/spare/repo/netdev-2.6 branch 'ieee80211'
[pandora-kernel.git] / drivers / net / wireless / hostap / hostap_cs.c
index e66c797..7024245 100644 (file)
@@ -1,7 +1,6 @@
 #define PRISM2_PCCARD
 
 #include <linux/config.h>
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/if.h>
@@ -13,7 +12,6 @@
 #include <linux/wireless.h>
 #include <net/iw_handler.h>
 
-#include <pcmcia/version.h>
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
 #include <pcmcia/cistpl.h>
@@ -34,19 +32,22 @@ 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 irq_mask = 0xdeb8;
-module_param(irq_mask, int, 0444);
-
-static int irq_list[4] = { -1 };
-module_param_array(irq_list, int, NULL, 0444);
-
 static int ignore_cis_vcc;
 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;
+       dev_link_t *link;
+       int sandisk_connectplus;
+};
+
+
 #ifdef PRISM2_IO_DEBUG
 
 static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
@@ -210,8 +211,9 @@ static int prism2_event(event_t event, int priority,
 
 static int prism2_pccard_card_present(local_info_t *local)
 {
-       if (local->link != NULL &&
-           ((local->link->state & (DEV_PRESENT | DEV_CONFIG)) ==
+       struct hostap_cs_priv *hw_priv = local->hw_priv;
+       if (hw_priv->link != NULL &&
+           ((hw_priv->link->state & (DEV_PRESENT | DEV_CONFIG)) ==
             (DEV_PRESENT | DEV_CONFIG)))
                return 1;
        return 0;
@@ -231,12 +233,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->handle,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -"
                       " res=%d\n", res);
@@ -246,8 +250,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->handle,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -"
                       " res=%d\n", res);
@@ -279,8 +284,9 @@ static int sandisk_enable_wireless(struct net_device *dev)
        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;
@@ -297,9 +303,9 @@ static int sandisk_enable_wireless(struct net_device *dev)
        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) ||
+       if (pcmcia_get_first_tuple(hw_priv->link->handle, &tuple) ||
+           pcmcia_get_tuple_data(hw_priv->link->handle, &tuple) ||
+           pcmcia_parse_tuple(hw_priv->link->handle, &tuple, parse) ||
            parse->manfid.manf != 0xd601 || parse->manfid.card != 0x0101) {
                /* No SanDisk manfid found */
                ret = -ENODEV;
@@ -307,9 +313,9 @@ static int sandisk_enable_wireless(struct net_device *dev)
        }
 
        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->handle, &tuple) ||
+           pcmcia_get_tuple_data(hw_priv->link->handle, &tuple) ||
+           pcmcia_parse_tuple(hw_priv->link->handle, &tuple, parse) ||
                parse->longlink_mfc.nfn < 2) {
                /* No multi-function links found */
                ret = -ENODEV;
@@ -318,13 +324,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->handle,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
                       dev->name, res);
@@ -340,7 +347,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->handle,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
                       dev->name, res);
@@ -365,6 +373,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;
@@ -373,7 +382,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->handle,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n",
                       res);
@@ -384,28 +394,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->handle,
+                                                  &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->handle,
+                                                  &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);
 }
 
@@ -415,11 +427,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;
        }
@@ -428,7 +441,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->handle,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 "
                       "(%d)\n", res);
@@ -440,7 +454,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->handle,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 "
                       "(%d)\n", res);
@@ -453,7 +468,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->handle,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 "
                       "(%d)\n", res);
@@ -464,7 +480,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->handle,
+                                                  &reg);
        if (res != CS_SUCCESS) {
                printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 "
                       "(%d)\n", res);
@@ -477,23 +494,29 @@ 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++;
+       struct hostap_cs_priv *hw_priv = local->hw_priv;
+       hw_priv->link->open++;
        return 0;
 }
 
 
 static int prism2_pccard_dev_close(local_info_t *local)
 {
-       if (local == NULL || local->link == NULL)
+       struct hostap_cs_priv *hw_priv;
+
+       if (local == NULL || local->hw_priv == NULL)
+               return 1;
+       hw_priv = local->hw_priv;
+       if (hw_priv->link == NULL)
                return 1;
 
-       if (!local->link->open) {
+       if (!hw_priv->link->open) {
                printk(KERN_WARNING "%s: prism2_pccard_dev_close(): "
                       "link not open?!\n", local->dev->name);
                return 1;
        }
 
-       local->link->open--;
+       hw_priv->link->open--;
 
        return 0;
 }
@@ -532,12 +555,6 @@ static dev_link_t *prism2_attach(void)
        link->next = dev_list;
        dev_list = link;
        client_reg.dev_info = &dev_info;
-       client_reg.Attributes = INFO_IO_CLIENT;
-       client_reg.EventMask = CS_EVENT_CARD_INSERTION |
-               CS_EVENT_CARD_REMOVAL |
-               CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
-               CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
-       client_reg.event_handler = &prism2_event;
        client_reg.Version = 0x0210;
        client_reg.event_callback_args.client_data = link;
        ret = pcmcia_register_client(&link->handle, &client_reg);
@@ -580,8 +597,13 @@ static void prism2_detach(dev_link_t *link)
        *linkp = link->next;
        /* release net devices */
        if (link->priv) {
-               prism2_free_local_data((struct net_device *) link->priv);
-
+               struct net_device *dev;
+               struct hostap_interface *iface;
+               dev = link->priv;
+               iface = netdev_priv(dev);
+               kfree(iface->local->hw_priv);
+               iface->local->hw_priv = NULL;
+               prism2_free_local_data(dev);
        }
        kfree(link);
 }
@@ -614,14 +636,19 @@ 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 = kmalloc(sizeof(*hw_priv), GFP_KERNEL);
+       if (parse == NULL || hw_priv == NULL) {
+               kfree(parse);
+               kfree(hw_priv);
                ret = -ENOMEM;
                goto failed;
        }
+       memset(hw_priv, 0, sizeof(*hw_priv));
 
        tuple.DesiredTuple = CISTPL_CONFIG;
        tuple.Attributes = 0;
@@ -657,13 +684,13 @@ static int prism2_config(dev_link_t *link)
                link->conf.ConfigIndex = cfg->index;
                PDEBUG(DEBUG_EXTRA, "Checking CFTABLE_ENTRY 0x%02X "
                       "(default 0x%02X)\n", cfg->index, dflt.index);
-       
+
                /* Does this card need audio output? */
                if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
                        link->conf.Attributes |= CONF_ENABLE_SPKR;
                        link->conf.Status = CCSR_AUDIO_ENA;
                }
-       
+
                /* Use power settings for Vcc and Vpp if present */
                /*  Note that the CIS values need to be rescaled */
                if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
@@ -739,7 +766,8 @@ static int prism2_config(dev_link_t *link)
        }
 
        /* Need to allocate net_device before requesting IRQ handler */
-       dev = prism2_init_local_data(&prism2_pccard_funcs, 0);
+       dev = prism2_init_local_data(&prism2_pccard_funcs, 0,
+                                    &handle_to_dev(link->handle));
        if (dev == NULL)
                goto failed;
        link->priv = dev;
@@ -750,14 +778,8 @@ static int prism2_config(dev_link_t *link)
         * irq structure is initialized.
         */
        if (link->conf.Attributes & CONF_ENABLE_IRQ) {
-               int i;
                link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
-               link->irq.IRQInfo1 = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
-               if (irq_list[0] == -1)
-                       link->irq.IRQInfo2 = irq_mask;
-               else
-                       for (i = 0; i < 4; i++)
-                               link->irq.IRQInfo2 |= 1 << irq_list[i];
+               link->irq.IRQInfo1 = IRQ_LEVEL_ID;
                link->irq.Handler = prism2_interrupt;
                link->irq.Instance = dev;
                CS_CHECK(RequestIRQ,
@@ -797,9 +819,10 @@ static int prism2_config(dev_link_t *link)
 
        iface = netdev_priv(dev);
        local = iface->local;
-       local->link = link;
-       strcpy(local->node.dev_name, dev->name);
-       link->dev = &local->node;
+       local->hw_priv = hw_priv;
+       hw_priv->link = link;
+       strcpy(hw_priv->node.dev_name, dev->name);
+       link->dev = &hw_priv->node;
 
        local->shutdown = 0;
 
@@ -809,7 +832,7 @@ 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;
@@ -819,6 +842,7 @@ static int prism2_config(dev_link_t *link)
 
  failed:
        kfree(parse);
+       kfree(hw_priv);
        prism2_release((u_long)link);
        return ret;
 }
@@ -924,6 +948,60 @@ static int prism2_event(event_t event, int priority,
 }
 
 
+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(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),
+       PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002),
+       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(0xd601, 0x0002),
+       PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
+       PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0010),
+       PCMCIA_MFC_DEVICE_PROD_ID12(0, "SanDisk", "ConnectPlus",
+                                   0x7a954bd9, 0x74be00c6),
+       PCMCIA_DEVICE_PROD_ID1234(
+               "Intersil", "PRISM 2_5 PCMCIA ADAPTER", "ISL37300P",
+               "Eval-RevA",
+               0x4b801a17, 0x6345a0bf, 0xc9049a39, 0xc23adc0e),
+       PCMCIA_DEVICE_PROD_ID123(
+               "Addtron", "AWP-100 Wireless PCMCIA", "Version 01.02",
+               0xe6ec52ce, 0x08649af2, 0x4b74baa0),
+       PCMCIA_DEVICE_PROD_ID123(
+               "D", "Link DWL-650 11Mbps WLAN Card", "Version 01.02",
+               0x71b18589, 0xb6f1b0ab, 0x4b74baa0),
+       PCMCIA_DEVICE_PROD_ID123(
+               "Instant Wireless ", " Network PC CARD", "Version 01.02",
+               0x11d901af, 0x6e9bd926, 0x4b74baa0),
+       PCMCIA_DEVICE_PROD_ID123(
+               "SMC", "SMC2632W", "Version 01.02",
+               0xc4f8b18b, 0x474a1f2a, 0x4b74baa0),
+       PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-CF-S11G", 
+                               0x1b01a57b, 0xefd5102a),
+       PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card",
+                               0x54f7c49c, 0x15a75e5b),
+       PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE",
+                               0x74c5e40d, 0xdb472a18),
+       PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card",
+                               0x0733cc81, 0x0c52f395),
+       PCMCIA_DEVICE_PROD_ID12(
+               "ZoomAir 11Mbps High", "Rate wireless Networking",
+               0x273fe3db, 0x32a1eaee),
+       PCMCIA_DEVICE_NULL
+};
+MODULE_DEVICE_TABLE(pcmcia, hostap_cs_ids);
+
+
 static struct pcmcia_driver hostap_driver = {
        .drv            = {
                .name   = "hostap_cs",
@@ -931,6 +1009,8 @@ static struct pcmcia_driver hostap_driver = {
        .attach         = prism2_attach,
        .detach         = prism2_detach,
        .owner          = THIS_MODULE,
+       .event          = prism2_event,
+       .id_table       = hostap_cs_ids,
 };
 
 static int __init init_prism2_pccard(void)