hostap_cs: correct poor NULL checks in suspend/resume routines
[safe/jmp/linux-2.6] / drivers / net / wireless / hostap / hostap_cs.c
index a83ee5c..3b4e55c 100644 (file)
@@ -1,6 +1,5 @@
 #define PRISM2_PCCARD
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/if.h>
 #include "hostap_wlan.h"
 
 
-static char *version = PRISM2_VERSION " (Jouni Malinen <jkmaline@cc.hut.fi>)";
 static dev_info_t dev_info = "hostap_cs";
-static dev_link_t *dev_list = NULL;
 
 MODULE_AUTHOR("Jouni Malinen");
 MODULE_DESCRIPTION("Support for Intersil Prism2-based 802.11 wireless LAN "
                   "cards (PC Card).");
 MODULE_SUPPORTED_DEVICE("Intersil Prism2-based WLAN cards (PC Card)");
 MODULE_LICENSE("GPL");
-MODULE_VERSION(PRISM2_VERSION);
 
 
 static int ignore_cis_vcc;
@@ -40,6 +36,14 @@ module_param(ignore_cis_vcc, int, 0444);
 MODULE_PARM_DESC(ignore_cis_vcc, "Ignore broken CIS VCC entry");
 
 
+/* struct local_info::hw_priv */
+struct hostap_cs_priv {
+       dev_node_t node;
+       struct pcmcia_device *link;
+       int sandisk_connectplus;
+};
+
+
 #ifdef PRISM2_IO_DEBUG
 
 static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
@@ -195,17 +199,15 @@ static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
 
 
 
-static void prism2_detach(dev_link_t *link);
+static void prism2_detach(struct pcmcia_device *p_dev);
 static void prism2_release(u_long arg);
-static int prism2_event(event_t event, int priority,
-                       event_callback_args_t *args);
+static int prism2_config(struct pcmcia_device *link);
 
 
 static int prism2_pccard_card_present(local_info_t *local)
 {
-       if (local->link != NULL &&
-           ((local->link->state & (DEV_PRESENT | DEV_CONFIG)) ==
-            (DEV_PRESENT | DEV_CONFIG)))
+       struct hostap_cs_priv *hw_priv = local->hw_priv;
+       if (hw_priv != NULL && hw_priv->link != NULL && pcmcia_dev_present(hw_priv->link))
                return 1;
        return 0;
 }
@@ -224,12 +226,14 @@ static void sandisk_set_iobase(local_info_t *local)
 {
        int res;
        conf_reg_t reg;
+       struct hostap_cs_priv *hw_priv = local->hw_priv;
 
        reg.Function = 0;
        reg.Action = CS_WRITE;
        reg.Offset = 0x10; /* 0x3f0 IO base 1 */
-       reg.Value = local->link->io.BasePort1 & 0x00ff;
-       res = pcmcia_access_configuration_register(local->link->handle, &reg);
+       reg.Value = hw_priv->link->io.BasePort1 & 0x00ff;
+       res = pcmcia_access_configuration_register(hw_priv->link,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -"
                       " res=%d\n", res);
@@ -239,8 +243,9 @@ static void sandisk_set_iobase(local_info_t *local)
        reg.Function = 0;
        reg.Action = CS_WRITE;
        reg.Offset = 0x12; /* 0x3f2 IO base 2 */
-       reg.Value = (local->link->io.BasePort1 & 0xff00) >> 8;
-       res = pcmcia_access_configuration_register(local->link->handle, &reg);
+       reg.Value = (hw_priv->link->io.BasePort1 & 0xff00) >> 8;
+       res = pcmcia_access_configuration_register(hw_priv->link,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -"
                       " res=%d\n", res);
@@ -267,13 +272,14 @@ static int sandisk_enable_wireless(struct net_device *dev)
 {
        int res, ret = 0;
        conf_reg_t reg;
-       struct hostap_interface *iface = dev->priv;
+       struct hostap_interface *iface = netdev_priv(dev);
        local_info_t *local = iface->local;
        tuple_t tuple;
        cisparse_t *parse = NULL;
        u_char buf[64];
+       struct hostap_cs_priv *hw_priv = local->hw_priv;
 
-       if (local->link->io.NumPorts1 < 0x42) {
+       if (hw_priv->link->io.NumPorts1 < 0x42) {
                /* Not enough ports to be SanDisk multi-function card */
                ret = -ENODEV;
                goto done;
@@ -285,24 +291,21 @@ static int sandisk_enable_wireless(struct net_device *dev)
                goto done;
        }
 
-       tuple.DesiredTuple = CISTPL_MANFID;
        tuple.Attributes = TUPLE_RETURN_COMMON;
        tuple.TupleData = buf;
        tuple.TupleDataMax = sizeof(buf);
        tuple.TupleOffset = 0;
-       if (pcmcia_get_first_tuple(local->link->handle, &tuple) ||
-           pcmcia_get_tuple_data(local->link->handle, &tuple) ||
-           pcmcia_parse_tuple(local->link->handle, &tuple, parse) ||
-           parse->manfid.manf != 0xd601 || parse->manfid.card != 0x0101) {
+
+       if (hw_priv->link->manf_id != 0xd601 || hw_priv->link->card_id != 0x0101) {
                /* No SanDisk manfid found */
                ret = -ENODEV;
                goto done;
        }
 
        tuple.DesiredTuple = CISTPL_LONGLINK_MFC;
-       if (pcmcia_get_first_tuple(local->link->handle, &tuple) ||
-           pcmcia_get_tuple_data(local->link->handle, &tuple) ||
-           pcmcia_parse_tuple(local->link->handle, &tuple, parse) ||
+       if (pcmcia_get_first_tuple(hw_priv->link, &tuple) ||
+           pcmcia_get_tuple_data(hw_priv->link, &tuple) ||
+           pcmcia_parse_tuple(hw_priv->link, &tuple, parse) ||
                parse->longlink_mfc.nfn < 2) {
                /* No multi-function links found */
                ret = -ENODEV;
@@ -311,13 +314,14 @@ static int sandisk_enable_wireless(struct net_device *dev)
 
        printk(KERN_DEBUG "%s: Multi-function SanDisk ConnectPlus detected"
               " - using vendor-specific initialization\n", dev->name);
-       local->sandisk_connectplus = 1;
+       hw_priv->sandisk_connectplus = 1;
 
        reg.Function = 0;
        reg.Action = CS_WRITE;
        reg.Offset = CISREG_COR;
        reg.Value = COR_SOFT_RESET;
-       res = pcmcia_access_configuration_register(local->link->handle, &reg);
+       res = pcmcia_access_configuration_register(hw_priv->link,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
                       dev->name, res);
@@ -333,7 +337,8 @@ static int sandisk_enable_wireless(struct net_device *dev)
         * will be enabled during the first cor_sreset call.
         */
        reg.Value = COR_LEVEL_REQ | 0x8 | COR_ADDR_DECODE | COR_FUNC_ENA;
-       res = pcmcia_access_configuration_register(local->link->handle, &reg);
+       res = pcmcia_access_configuration_register(hw_priv->link,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
                       dev->name, res);
@@ -358,6 +363,7 @@ static void prism2_pccard_cor_sreset(local_info_t *local)
 {
        int res;
        conf_reg_t reg;
+       struct hostap_cs_priv *hw_priv = local->hw_priv;
 
        if (!prism2_pccard_card_present(local))
               return;
@@ -366,7 +372,8 @@ static void prism2_pccard_cor_sreset(local_info_t *local)
        reg.Action = CS_READ;
        reg.Offset = CISREG_COR;
        reg.Value = 0;
-       res = pcmcia_access_configuration_register(local->link->handle, &reg);
+       res = pcmcia_access_configuration_register(hw_priv->link,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n",
                       res);
@@ -377,28 +384,30 @@ static void prism2_pccard_cor_sreset(local_info_t *local)
 
        reg.Action = CS_WRITE;
        reg.Value |= COR_SOFT_RESET;
-       res = pcmcia_access_configuration_register(local->link->handle, &reg);
+       res = pcmcia_access_configuration_register(hw_priv->link,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n",
                       res);
                return;
        }
 
-       mdelay(local->sandisk_connectplus ? 5 : 2);
+       mdelay(hw_priv->sandisk_connectplus ? 5 : 2);
 
        reg.Value &= ~COR_SOFT_RESET;
-       if (local->sandisk_connectplus)
+       if (hw_priv->sandisk_connectplus)
                reg.Value |= COR_IREQ_ENA;
-       res = pcmcia_access_configuration_register(local->link->handle, &reg);
+       res = pcmcia_access_configuration_register(hw_priv->link,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n",
                       res);
                return;
        }
 
-       mdelay(local->sandisk_connectplus ? 5 : 2);
+       mdelay(hw_priv->sandisk_connectplus ? 5 : 2);
 
-       if (local->sandisk_connectplus)
+       if (hw_priv->sandisk_connectplus)
                sandisk_set_iobase(local);
 }
 
@@ -408,11 +417,12 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
        int res;
        conf_reg_t reg;
        int old_cor;
+       struct hostap_cs_priv *hw_priv = local->hw_priv;
 
        if (!prism2_pccard_card_present(local))
               return;
 
-       if (local->sandisk_connectplus) {
+       if (hw_priv->sandisk_connectplus) {
                sandisk_write_hcr(local, hcr);
                return;
        }
@@ -421,7 +431,8 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
        reg.Action = CS_READ;
        reg.Offset = CISREG_COR;
        reg.Value = 0;
-       res = pcmcia_access_configuration_register(local->link->handle, &reg);
+       res = pcmcia_access_configuration_register(hw_priv->link,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 "
                       "(%d)\n", res);
@@ -433,7 +444,8 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
 
        reg.Action = CS_WRITE;
        reg.Value |= COR_SOFT_RESET;
-       res = pcmcia_access_configuration_register(local->link->handle, &reg);
+       res = pcmcia_access_configuration_register(hw_priv->link,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 "
                       "(%d)\n", res);
@@ -446,7 +458,8 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
        reg.Action = CS_WRITE;
        reg.Value = hcr;
        reg.Offset = CISREG_CCSR;
-       res = pcmcia_access_configuration_register(local->link->handle, &reg);
+       res = pcmcia_access_configuration_register(hw_priv->link,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 "
                       "(%d)\n", res);
@@ -457,7 +470,8 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
        reg.Action = CS_WRITE;
        reg.Offset = CISREG_COR;
        reg.Value = old_cor & ~COR_SOFT_RESET;
-       res = pcmcia_access_configuration_register(local->link->handle, &reg);
+       res = pcmcia_access_configuration_register(hw_priv->link,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 "
                       "(%d)\n", res);
@@ -468,36 +482,10 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
 }
 
 
-static int prism2_pccard_dev_open(local_info_t *local)
-{
-       local->link->open++;
-       return 0;
-}
-
-
-static int prism2_pccard_dev_close(local_info_t *local)
-{
-       if (local == NULL || local->link == NULL)
-               return 1;
-
-       if (!local->link->open) {
-               printk(KERN_WARNING "%s: prism2_pccard_dev_close(): "
-                      "link not open?!\n", local->dev->name);
-               return 1;
-       }
-
-       local->link->open--;
-
-       return 0;
-}
-
-
 static struct prism2_helper_functions prism2_pccard_funcs =
 {
        .card_present   = prism2_pccard_card_present,
        .cor_sreset     = prism2_pccard_cor_sreset,
-       .dev_open       = prism2_pccard_dev_open,
-       .dev_close      = prism2_pccard_dev_close,
        .genesis_reset  = prism2_pccard_genesis_reset,
        .hw_type        = HOSTAP_HW_PCCARD,
 };
@@ -505,72 +493,39 @@ static struct prism2_helper_functions prism2_pccard_funcs =
 
 /* allocate local data and register with CardServices
  * initialize dev_link structure, but do not configure the card yet */
-static dev_link_t *prism2_attach(void)
+static int hostap_cs_probe(struct pcmcia_device *p_dev)
 {
-       dev_link_t *link;
-       client_reg_t client_reg;
        int ret;
 
-       link = kmalloc(sizeof(dev_link_t), GFP_KERNEL);
-       if (link == NULL)
-               return NULL;
-
-       memset(link, 0, sizeof(dev_link_t));
-
        PDEBUG(DEBUG_HW, "%s: setting Vcc=33 (constant)\n", dev_info);
-       link->conf.Vcc = 33;
-       link->conf.IntType = INT_MEMORY_AND_IO;
-
-       /* register with CardServices */
-       link->next = dev_list;
-       dev_list = link;
-       client_reg.dev_info = &dev_info;
-       client_reg.Version = 0x0210;
-       client_reg.event_callback_args.client_data = link;
-       ret = pcmcia_register_client(&link->handle, &client_reg);
-       if (ret != CS_SUCCESS) {
-               cs_error(link->handle, RegisterClient, ret);
-               prism2_detach(link);
-               return NULL;
+       p_dev->conf.IntType = INT_MEMORY_AND_IO;
+
+       ret = prism2_config(p_dev);
+       if (ret) {
+               PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n");
        }
-       return link;
+
+       return ret;
 }
 
 
-static void prism2_detach(dev_link_t *link)
+static void prism2_detach(struct pcmcia_device *link)
 {
-       dev_link_t **linkp;
-
        PDEBUG(DEBUG_FLOW, "prism2_detach\n");
 
-       for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
-               if (*linkp == link)
-                       break;
-       if (*linkp == NULL) {
-               printk(KERN_WARNING "%s: Attempt to detach non-existing "
-                      "PCMCIA client\n", dev_info);
-               return;
-       }
-
-       if (link->state & DEV_CONFIG) {
-               prism2_release((u_long)link);
-       }
-
-       if (link->handle) {
-               int res = pcmcia_deregister_client(link->handle);
-               if (res) {
-                       printk("CardService(DeregisterClient) => %d\n", res);
-                       cs_error(link->handle, DeregisterClient, res);
-               }
-       }
+       prism2_release((u_long)link);
 
-       *linkp = link->next;
        /* release net devices */
        if (link->priv) {
-               prism2_free_local_data((struct net_device *) link->priv);
-
+               struct hostap_cs_priv *hw_priv;
+               struct net_device *dev;
+               struct hostap_interface *iface;
+               dev = link->priv;
+               iface = netdev_priv(dev);
+               hw_priv = iface->local->hw_priv;
+               prism2_free_local_data(dev);
+               kfree(hw_priv);
        }
-       kfree(link);
 }
 
 
@@ -578,10 +533,10 @@ static void prism2_detach(dev_link_t *link)
 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
 #define CFG_CHECK2(fn, retf) \
-do { int ret = (retf); \
-if (ret != 0) { \
-       PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", ret); \
-       cs_error(link->handle, fn, ret); \
+do { int _ret = (retf); \
+if (_ret != 0) { \
+       PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", _ret); \
+       cs_error(link, fn, _ret); \
        goto next_entry; \
 } \
 } while (0)
@@ -589,7 +544,7 @@ if (ret != 0) { \
 
 /* run after a CARD_INSERTION event is received to configure the PCMCIA
  * socket and make the device available to the system */
-static int prism2_config(dev_link_t *link)
+static int prism2_config(struct pcmcia_device *link)
 {
        struct net_device *dev;
        struct hostap_interface *iface;
@@ -601,41 +556,34 @@ static int prism2_config(dev_link_t *link)
        u_char buf[64];
        config_info_t conf;
        cistpl_cftable_entry_t dflt = { 0 };
+       struct hostap_cs_priv *hw_priv;
 
        PDEBUG(DEBUG_FLOW, "prism2_config()\n");
 
        parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL);
-       if (parse == NULL) {
+       hw_priv = kzalloc(sizeof(*hw_priv), GFP_KERNEL);
+       if (parse == NULL || hw_priv == NULL) {
                ret = -ENOMEM;
                goto failed;
        }
 
-       tuple.DesiredTuple = CISTPL_CONFIG;
        tuple.Attributes = 0;
        tuple.TupleData = buf;
        tuple.TupleDataMax = sizeof(buf);
        tuple.TupleOffset = 0;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple));
-       CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link->handle, &tuple));
-       CS_CHECK(ParseTuple, pcmcia_parse_tuple(link->handle, &tuple, parse));
-       link->conf.ConfigBase = parse->config.base;
-       link->conf.Present = parse->config.rmask[0];
 
        CS_CHECK(GetConfigurationInfo,
-                pcmcia_get_configuration_info(link->handle, &conf));
-       PDEBUG(DEBUG_HW, "%s: %s Vcc=%d (from config)\n", dev_info,
-              ignore_cis_vcc ? "ignoring" : "setting", conf.Vcc);
-       link->conf.Vcc = conf.Vcc;
+                pcmcia_get_configuration_info(link, &conf));
 
        /* Look for an appropriate configuration table entry in the CIS */
        tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple));
+       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
        for (;;) {
                cistpl_cftable_entry_t *cfg = &(parse->cftable_entry);
                CFG_CHECK2(GetTupleData,
-                          pcmcia_get_tuple_data(link->handle, &tuple));
+                          pcmcia_get_tuple_data(link, &tuple));
                CFG_CHECK2(ParseTuple,
-                          pcmcia_parse_tuple(link->handle, &tuple, parse));
+                          pcmcia_parse_tuple(link, &tuple, parse));
 
                if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
                        dflt = *cfg;
@@ -670,10 +618,10 @@ static int prism2_config(dev_link_t *link)
                }
 
                if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
-                       link->conf.Vpp1 = link->conf.Vpp2 =
+                       link->conf.Vpp =
                                cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
                else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
-                       link->conf.Vpp1 = link->conf.Vpp2 =
+                       link->conf.Vpp =
                                dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
 
                /* Do we need to allocate an interrupt? */
@@ -715,23 +663,30 @@ static int prism2_config(dev_link_t *link)
 
                /* This reserves IO space but doesn't actually enable it */
                CFG_CHECK2(RequestIO,
-                          pcmcia_request_io(link->handle, &link->io));
+                          pcmcia_request_io(link, &link->io));
 
                /* This configuration table entry is OK */
                break;
 
        next_entry:
                CS_CHECK(GetNextTuple,
-                        pcmcia_get_next_tuple(link->handle, &tuple));
+                        pcmcia_get_next_tuple(link, &tuple));
        }
 
        /* Need to allocate net_device before requesting IRQ handler */
        dev = prism2_init_local_data(&prism2_pccard_funcs, 0,
-                                    &handle_to_dev(link->handle));
+                                    &handle_to_dev(link));
        if (dev == NULL)
                goto failed;
        link->priv = dev;
 
+       iface = netdev_priv(dev);
+       local = iface->local;
+       local->hw_priv = hw_priv;
+       hw_priv->link = link;
+       strcpy(hw_priv->node.dev_name, dev->name);
+       link->dev_node = &hw_priv->node;
+
        /*
         * Allocate an interrupt line.  Note that this does not assign a
         * handler to the interrupt, unless the 'Handler' member of the
@@ -743,7 +698,7 @@ static int prism2_config(dev_link_t *link)
                link->irq.Handler = prism2_interrupt;
                link->irq.Instance = dev;
                CS_CHECK(RequestIRQ,
-                        pcmcia_request_irq(link->handle, &link->irq));
+                        pcmcia_request_irq(link, &link->irq));
        }
 
        /*
@@ -752,18 +707,17 @@ static int prism2_config(dev_link_t *link)
         * card and host interface into "Memory and IO" mode.
         */
        CS_CHECK(RequestConfiguration,
-                pcmcia_request_configuration(link->handle, &link->conf));
+                pcmcia_request_configuration(link, &link->conf));
 
        dev->irq = link->irq.AssignedIRQ;
        dev->base_addr = link->io.BasePort1;
 
        /* Finally, report what we've done */
-       printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d",
-              dev_info, link->conf.ConfigIndex,
-              link->conf.Vcc / 10, link->conf.Vcc % 10);
-       if (link->conf.Vpp1)
-               printk(", Vpp %d.%d", link->conf.Vpp1 / 10,
-                      link->conf.Vpp1 % 10);
+       printk(KERN_INFO "%s: index 0x%02x: ",
+              dev_info, link->conf.ConfigIndex);
+       if (link->conf.Vpp)
+               printk(", Vpp %d.%d", link->conf.Vpp / 10,
+                      link->conf.Vpp % 10);
        if (link->conf.Attributes & CONF_ENABLE_IRQ)
                printk(", irq %d", link->irq.AssignedIRQ);
        if (link->io.NumPorts1)
@@ -774,15 +728,6 @@ static int prism2_config(dev_link_t *link)
                       link->io.BasePort2+link->io.NumPorts2-1);
        printk("\n");
 
-       link->state |= DEV_CONFIG;
-       link->state &= ~DEV_CONFIG_PENDING;
-
-       iface = netdev_priv(dev);
-       local = iface->local;
-       local->link = link;
-       strcpy(local->node.dev_name, dev->name);
-       link->dev = &local->node;
-
        local->shutdown = 0;
 
        sandisk_enable_wireless(dev);
@@ -791,16 +736,17 @@ static int prism2_config(dev_link_t *link)
        if (!ret) {
                ret = hostap_hw_ready(dev);
                if (ret == 0 && local->ddev)
-                       strcpy(local->node.dev_name, local->ddev->name);
+                       strcpy(hw_priv->node.dev_name, local->ddev->name);
        }
        kfree(parse);
        return ret;
 
  cs_failed:
-       cs_error(link->handle, last_fn, last_ret);
+       cs_error(link, last_fn, last_ret);
 
  failed:
        kfree(parse);
+       kfree(hw_priv);
        prism2_release((u_long)link);
        return ret;
 }
@@ -808,7 +754,7 @@ static int prism2_config(dev_link_t *link)
 
 static void prism2_release(u_long arg)
 {
-       dev_link_t *link = (dev_link_t *)arg;
+       struct pcmcia_device *link = (struct pcmcia_device *)arg;
 
        PDEBUG(DEBUG_FLOW, "prism2_release\n");
 
@@ -817,103 +763,72 @@ static void prism2_release(u_long arg)
                struct hostap_interface *iface;
 
                iface = netdev_priv(dev);
-               if (link->state & DEV_CONFIG)
-                       prism2_hw_shutdown(dev, 0);
+               prism2_hw_shutdown(dev, 0);
                iface->local->shutdown = 1;
        }
 
-       if (link->win)
-               pcmcia_release_window(link->win);
-       pcmcia_release_configuration(link->handle);
-       if (link->io.NumPorts1)
-               pcmcia_release_io(link->handle, &link->io);
-       if (link->irq.AssignedIRQ)
-               pcmcia_release_irq(link->handle, &link->irq);
-
-       link->state &= ~DEV_CONFIG;
-
+       pcmcia_disable_device(link);
        PDEBUG(DEBUG_FLOW, "release - done\n");
 }
 
+static int hostap_cs_suspend(struct pcmcia_device *link)
+{
+       struct net_device *dev = (struct net_device *) link->priv;
+       int dev_open = 0;
+       struct hostap_interface *iface = NULL;
+
+       if (!dev)
+               return -ENODEV;
+
+       iface = netdev_priv(dev);
+
+       PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info);
+       if (iface && iface->local)
+               dev_open = iface->local->num_dev_open > 0;
+       if (dev_open) {
+               netif_stop_queue(dev);
+               netif_device_detach(dev);
+       }
+       prism2_suspend(dev);
+
+       return 0;
+}
 
-static int prism2_event(event_t event, int priority,
-                       event_callback_args_t *args)
+static int hostap_cs_resume(struct pcmcia_device *link)
 {
-       dev_link_t *link = args->client_data;
        struct net_device *dev = (struct net_device *) link->priv;
+       int dev_open = 0;
+       struct hostap_interface *iface = NULL;
 
-       switch (event) {
-       case CS_EVENT_CARD_INSERTION:
-               PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_INSERTION\n", dev_info);
-               link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
-               if (prism2_config(link)) {
-                       PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n");
-               }
-               break;
+       if (!dev)
+               return -ENODEV;
 
-       case CS_EVENT_CARD_REMOVAL:
-               PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_REMOVAL\n", dev_info);
-               link->state &= ~DEV_PRESENT;
-               if (link->state & DEV_CONFIG) {
-                       netif_stop_queue(dev);
-                       netif_device_detach(dev);
-                       prism2_release((u_long) link);
-               }
-               break;
+       iface = netdev_priv(dev);
 
-       case CS_EVENT_PM_SUSPEND:
-               PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info);
-               link->state |= DEV_SUSPEND;
-               /* fall through */
-
-       case CS_EVENT_RESET_PHYSICAL:
-               PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_RESET_PHYSICAL\n", dev_info);
-               if (link->state & DEV_CONFIG) {
-                       if (link->open) {
-                               netif_stop_queue(dev);
-                               netif_device_detach(dev);
-                       }
-                       prism2_suspend(dev);
-                       pcmcia_release_configuration(link->handle);
-               }
-               break;
+       PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info);
 
-       case CS_EVENT_PM_RESUME:
-               PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info);
-               link->state &= ~DEV_SUSPEND;
-               /* fall through */
-
-       case CS_EVENT_CARD_RESET:
-               PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_RESET\n", dev_info);
-               if (link->state & DEV_CONFIG) {
-                       pcmcia_request_configuration(link->handle,
-                                                    &link->conf);
-                       prism2_hw_shutdown(dev, 1);
-                       prism2_hw_config(dev, link->open ? 0 : 1);
-                       if (link->open) {
-                               netif_device_attach(dev);
-                               netif_start_queue(dev);
-                       }
-               }
-               break;
+       if (iface && iface->local)
+               dev_open = iface->local->num_dev_open > 0;
 
-       default:
-               PDEBUG(DEBUG_EXTRA, "%s: prism2_event() - unknown event %d\n",
-                      dev_info, event);
-               break;
+       prism2_hw_shutdown(dev, 1);
+       prism2_hw_config(dev, dev_open ? 0 : 1);
+       if (dev_open) {
+               netif_device_attach(dev);
+               netif_start_queue(dev);
        }
+
        return 0;
 }
 
-
 static struct pcmcia_device_id hostap_cs_ids[] = {
        PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100),
        PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300),
        PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777),
        PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000),
        PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002),
-       PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002),
+       PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x3301),
        PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002),
+       PCMCIA_DEVICE_MANF_CARD(0x026f, 0x030b),
        PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612),
        PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613),
        PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002),
@@ -921,16 +836,27 @@ static struct pcmcia_device_id hostap_cs_ids[] = {
        PCMCIA_DEVICE_MANF_CARD(0x02d2, 0x0001),
        PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x0001),
        PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300),
-       PCMCIA_DEVICE_MANF_CARD(0xc00f, 0x0000),
+/*     PCMCIA_DEVICE_MANF_CARD(0xc00f, 0x0000),    conflict with pcnet_cs */
+       PCMCIA_DEVICE_MANF_CARD(0xc250, 0x0002),
        PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
        PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
        PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0010),
+       PCMCIA_DEVICE_MANF_CARD(0x0126, 0x0002),
+       PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0xd601, 0x0005, "ADLINK 345 CF",
+                                        0x2d858104),
+       PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0x0156, 0x0002, "INTERSIL",
+                                        0x74c5e40d),
+       PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0x0156, 0x0002, "Intersil",
+                                        0x4b801a17),
        PCMCIA_MFC_DEVICE_PROD_ID12(0, "SanDisk", "ConnectPlus",
                                    0x7a954bd9, 0x74be00c6),
-       PCMCIA_DEVICE_PROD_ID1234(
+       PCMCIA_DEVICE_PROD_ID123(
                "Intersil", "PRISM 2_5 PCMCIA ADAPTER", "ISL37300P",
-               "Eval-RevA",
-               0x4b801a17, 0x6345a0bf, 0xc9049a39, 0xc23adc0e),
+               0x4b801a17, 0x6345a0bf, 0xc9049a39),
+       /* D-Link DWL-650 Rev. P1; manfid 0x000b, 0x7110 */
+       PCMCIA_DEVICE_PROD_ID123(
+               "D-Link", "DWL-650 Wireless PC Card RevP", "ISL37101P-10",
+               0x1a424a1c, 0x6ea57632, 0xdd97a26b),
        PCMCIA_DEVICE_PROD_ID123(
                "Addtron", "AWP-100 Wireless PCMCIA", "Version 01.02",
                0xe6ec52ce, 0x08649af2, 0x4b74baa0),
@@ -943,6 +869,8 @@ static struct pcmcia_device_id hostap_cs_ids[] = {
        PCMCIA_DEVICE_PROD_ID123(
                "SMC", "SMC2632W", "Version 01.02",
                0xc4f8b18b, 0x474a1f2a, 0x4b74baa0),
+       PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-CF-S11G", 
+                               0x2decece3, 0x82067c18),
        PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card",
                                0x54f7c49c, 0x15a75e5b),
        PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE",
@@ -952,6 +880,25 @@ static struct pcmcia_device_id hostap_cs_ids[] = {
        PCMCIA_DEVICE_PROD_ID12(
                "ZoomAir 11Mbps High", "Rate wireless Networking",
                0x273fe3db, 0x32a1eaee),
+       PCMCIA_DEVICE_PROD_ID123(
+               "Pretec", "CompactWLAN Card 802.11b", "2.5",
+               0x1cadd3e5, 0xe697636c, 0x7a5bfcf1),
+       PCMCIA_DEVICE_PROD_ID123(
+               "U.S. Robotics", "IEEE 802.11b PC-CARD", "Version 01.02",
+               0xc7b8df9d, 0x1700d087, 0x4b74baa0),
+       PCMCIA_DEVICE_PROD_ID123(
+               "Allied Telesyn", "AT-WCL452 Wireless PCMCIA Radio",
+               "Ver. 1.00",
+               0x5cd01705, 0x4271660f, 0x9d08ee12),
+       PCMCIA_DEVICE_PROD_ID123(
+               "corega", "WL PCCL-11", "ISL37300P",
+               0xa21501a, 0x59868926, 0xc9049a39),
+       PCMCIA_DEVICE_PROD_ID123(
+               "The Linksys Group, Inc.", "Wireless Network CF Card", "ISL37300P",
+               0xa5f472c2, 0x9c05598d, 0xc9049a39),
+       PCMCIA_DEVICE_PROD_ID123(
+               "Wireless LAN" , "11Mbps PC Card", "Version 01.02",
+               0x4b8870ff, 0x70e946d1, 0x4b74baa0),
        PCMCIA_DEVICE_NULL
 };
 MODULE_DEVICE_TABLE(pcmcia, hostap_cs_ids);
@@ -961,23 +908,22 @@ static struct pcmcia_driver hostap_driver = {
        .drv            = {
                .name   = "hostap_cs",
        },
-       .attach         = prism2_attach,
-       .detach         = prism2_detach,
+       .probe          = hostap_cs_probe,
+       .remove         = prism2_detach,
        .owner          = THIS_MODULE,
-       .event          = prism2_event,
        .id_table       = hostap_cs_ids,
+       .suspend        = hostap_cs_suspend,
+       .resume         = hostap_cs_resume,
 };
 
 static int __init init_prism2_pccard(void)
 {
-       printk(KERN_INFO "%s: %s\n", dev_info, version);
        return pcmcia_register_driver(&hostap_driver);
 }
 
 static void __exit exit_prism2_pccard(void)
 {
        pcmcia_unregister_driver(&hostap_driver);
-       printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
 }