Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / net / wireless / wl3501_cs.c
index 1433e5a..e52a650 100644 (file)
@@ -49,7 +49,6 @@
 
 #include <net/iw_handler.h>
 
-#include <pcmcia/version.h>
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
 #include <pcmcia/cistpl.h>
@@ -104,9 +103,8 @@ module_param(pc_debug, int, 0);
  * release a socket, in response to card insertion and ejection events.  They
  * are invoked from the wl24 event handler.
  */
-static void wl3501_config(dev_link_t *link);
-static void wl3501_release(dev_link_t *link);
-static int wl3501_event(event_t event, int pri, event_callback_args_t *args);
+static int wl3501_config(struct pcmcia_device *link);
+static void wl3501_release(struct pcmcia_device *link);
 
 /*
  * The dev_info variable is the "key" that is used to match up this
@@ -228,17 +226,6 @@ static void iw_copy_mgmt_info_element(struct iw_mgmt_info_element *to,
        iw_set_mgmt_info_element(from->id, to, from->data, from->len);
 }
 
-/*
- * A linked list of "instances" of the wl24 device.  Each actual PCMCIA card
- * corresponds to one device instance, and is described by one dev_link_t
- * structure (defined in ds.h).
- *
- * You may not want to use a linked list for this -- for example, the memory
- * card driver uses an array of dev_link_t pointers, where minor device numbers
- * are used to derive the corresponding array index.
- */
-static dev_link_t *wl3501_dev_list;
-
 static inline void wl3501_switch_page(struct wl3501_card *this, u8 page)
 {
        wl3501_outb(page, this->base_addr + WL3501_NIC_BSS);
@@ -297,7 +284,8 @@ static int wl3501_get_flash_mac_addr(struct wl3501_card *this)
  *
  * Move 'size' bytes from PC to card. (Shouldn't be interrupted)
  */
-void wl3501_set_to_wla(struct wl3501_card *this, u16 dest, void *src, int size)
+static void wl3501_set_to_wla(struct wl3501_card *this, u16 dest, void *src,
+                             int size)
 {
        /* switch to SRAM Page 0 */
        wl3501_switch_page(this, (dest & 0x8000) ? WL3501_BSS_SPAGE1 :
@@ -318,8 +306,8 @@ void wl3501_set_to_wla(struct wl3501_card *this, u16 dest, void *src, int size)
  *
  * Move 'size' bytes from card to PC. (Shouldn't be interrupted)
  */
-void wl3501_get_from_wla(struct wl3501_card *this, u16 src, void *dest,
-                        int size)
+static void wl3501_get_from_wla(struct wl3501_card *this, u16 src, void *dest,
+                               int size)
 {
        /* switch to SRAM Page 0 */
        wl3501_switch_page(this, (src & 0x8000) ? WL3501_BSS_SPAGE1 :
@@ -1282,15 +1270,10 @@ static int wl3501_close(struct net_device *dev)
        struct wl3501_card *this = dev->priv;
        int rc = -ENODEV;
        unsigned long flags;
-       dev_link_t *link;
+       struct pcmcia_device *link;
+       link = this->p_dev;
 
        spin_lock_irqsave(&this->lock, flags);
-       /* Check if the device is in wl3501_dev_list */
-       for (link = wl3501_dev_list; link; link = link->next)
-               if (link->priv == dev)
-                       break;
-       if (!link)
-               goto out;
        link->open--;
 
        /* Stop wl3501_hard_start_xmit() from now on */
@@ -1302,7 +1285,6 @@ static int wl3501_close(struct net_device *dev)
 
        rc = 0;
        printk(KERN_INFO "%s: WL3501 closed\n", dev->name);
-out:
        spin_unlock_irqrestore(&this->lock, flags);
        return rc;
 }
@@ -1401,14 +1383,11 @@ static int wl3501_open(struct net_device *dev)
        int rc = -ENODEV;
        struct wl3501_card *this = dev->priv;
        unsigned long flags;
-       dev_link_t *link;
+       struct pcmcia_device *link;
+       link = this->p_dev;
 
        spin_lock_irqsave(&this->lock, flags);
-       /* Check if the device is in wl3501_dev_list */
-       for (link = wl3501_dev_list; link; link = link->next)
-               if (link->priv == dev)
-                       break;
-       if (!DEV_OK(link))
+       if (!pcmcia_dev_present(link))
                goto out;
        netif_device_attach(dev);
        link->open++;
@@ -1439,14 +1418,14 @@ fail:
        goto out;
 }
 
-struct net_device_stats *wl3501_get_stats(struct net_device *dev)
+static struct net_device_stats *wl3501_get_stats(struct net_device *dev)
 {
        struct wl3501_card *this = dev->priv;
 
        return &this->stats;
 }
 
-struct iw_statistics *wl3501_get_wireless_stats(struct net_device *dev)
+static struct iw_statistics *wl3501_get_wireless_stats(struct net_device *dev)
 {
        struct wl3501_card *this = dev->priv;
        struct iw_statistics *wstats = &this->wstats;
@@ -1498,40 +1477,23 @@ static struct ethtool_ops ops = {
  * Services. If it has been released, all local data structures are freed.
  * Otherwise, the structures will be freed when the device is released.
  */
-static void wl3501_detach(dev_link_t *link)
+static void wl3501_detach(struct pcmcia_device *link)
 {
-       dev_link_t **linkp;
-
-       /* Locate device structure */
-       for (linkp = &wl3501_dev_list; *linkp; linkp = &(*linkp)->next)
-               if (*linkp == link)
-                       break;
-       if (!*linkp)
-               goto out;
+       struct net_device *dev = link->priv;
 
        /* If the device is currently configured and active, we won't actually
         * delete it yet.  Instead, it is marked so that when the release()
         * function is called, that will trigger a proper detach(). */
 
-       if (link->state & DEV_CONFIG) {
-#ifdef PCMCIA_DEBUG
-               printk(KERN_DEBUG "wl3501_cs: detach postponed, '%s' "
-                      "still locked\n", link->dev->dev_name);
-#endif
-               goto out;
-       }
-
-       /* Break the link with Card Services */
-       if (link->handle)
-               pcmcia_deregister_client(link->handle);
+       while (link->open > 0)
+               wl3501_close(dev);
 
-       /* Unlink device structure, free pieces */
-       *linkp = link->next;
+       netif_device_detach(dev);
+       wl3501_release(link);
 
        if (link->priv)
                free_netdev(link->priv);
-       kfree(link);
-out:
+
        return;
 }
 
@@ -1944,7 +1906,7 @@ static const iw_handler   wl3501_handler[] = {
 static const struct iw_handler_def wl3501_handler_def = {
        .num_standard   = sizeof(wl3501_handler) / sizeof(iw_handler),
        .standard       = (iw_handler *)wl3501_handler,
-       .spy_offset     = offsetof(struct wl3501_card, spy_data),
+       .get_wireless_stats = wl3501_get_wireless_stats,
 };
 
 /**
@@ -1956,35 +1918,26 @@ static const struct iw_handler_def wl3501_handler_def = {
  * The dev_link structure is initialized, but we don't actually configure the
  * card at this point -- we wait until we receive a card insertion event.
  */
-static dev_link_t *wl3501_attach(void)
+static int wl3501_probe(struct pcmcia_device *p_dev)
 {
-       client_reg_t client_reg;
-       dev_link_t *link;
        struct net_device *dev;
-       int ret;
-
-       /* Initialize the dev_link_t structure */
-       link = kmalloc(sizeof(*link), GFP_KERNEL);
-       if (!link)
-               goto out;
-       memset(link, 0, sizeof(struct dev_link_t));
+       struct wl3501_card *this;
 
        /* The io structure describes IO port mapping */
-       link->io.NumPorts1      = 16;
-       link->io.Attributes1    = IO_DATA_PATH_WIDTH_8;
-       link->io.IOAddrLines    = 5;
+       p_dev->io.NumPorts1     = 16;
+       p_dev->io.Attributes1   = IO_DATA_PATH_WIDTH_8;
+       p_dev->io.IOAddrLines   = 5;
 
        /* Interrupt setup */
-       link->irq.Attributes    = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
-       link->irq.IRQInfo1      = IRQ_LEVEL_ID;
-       link->irq.Handler = wl3501_interrupt;
+       p_dev->irq.Attributes   = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
+       p_dev->irq.IRQInfo1     = IRQ_LEVEL_ID;
+       p_dev->irq.Handler = wl3501_interrupt;
 
        /* General socket configuration */
-       link->conf.Attributes   = CONF_ENABLE_IRQ;
-       link->conf.Vcc          = 50;
-       link->conf.IntType      = INT_MEMORY_AND_IO;
-       link->conf.ConfigIndex  = 1;
-       link->conf.Present      = PRESENT_OPTION;
+       p_dev->conf.Attributes  = CONF_ENABLE_IRQ;
+       p_dev->conf.IntType     = INT_MEMORY_AND_IO;
+       p_dev->conf.ConfigIndex = 1;
+       p_dev->conf.Present     = PRESENT_OPTION;
 
        dev = alloc_etherdev(sizeof(struct wl3501_card));
        if (!dev)
@@ -1995,37 +1948,18 @@ static dev_link_t *wl3501_attach(void)
        dev->tx_timeout         = wl3501_tx_timeout;
        dev->watchdog_timeo     = 5 * HZ;
        dev->get_stats          = wl3501_get_stats;
-       dev->get_wireless_stats = wl3501_get_wireless_stats;
+       this = dev->priv;
+       this->wireless_data.spy_data = &this->spy_data;
+       this->p_dev = p_dev;
+       dev->wireless_data      = &this->wireless_data;
        dev->wireless_handlers  = (struct iw_handler_def *)&wl3501_handler_def;
        SET_ETHTOOL_OPS(dev, &ops);
        netif_stop_queue(dev);
-       link->priv = link->irq.Instance = dev;
-
-       /* Register with Card Services */
-       link->next               = wl3501_dev_list;
-       wl3501_dev_list          = link;
-       client_reg.dev_info      = &wl3501_dev_info;
-       client_reg.EventMask     = CS_EVENT_CARD_INSERTION |
-                                  CS_EVENT_RESET_PHYSICAL |
-                                  CS_EVENT_CARD_RESET |
-                                  CS_EVENT_CARD_REMOVAL |
-                                  CS_EVENT_PM_SUSPEND |
-                                  CS_EVENT_PM_RESUME;
-       client_reg.event_handler = wl3501_event;
-       client_reg.Version       = 0x0210;
-       client_reg.event_callback_args.client_data = link;
-       ret = pcmcia_register_client(&link->handle, &client_reg);
-       if (ret) {
-               cs_error(link->handle, RegisterClient, ret);
-               wl3501_detach(link);
-               link = NULL;
-       }
-out:
-       return link;
+       p_dev->priv = p_dev->irq.Instance = dev;
+
+       return wl3501_config(p_dev);
 out_link:
-       kfree(link);
-       link = NULL;
-       goto out;
+       return -ENOMEM;
 }
 
 #define CS_CHECK(fn, ret) \
@@ -2039,11 +1973,10 @@ do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  * received, to configure the PCMCIA socket, and to make the ethernet device
  * available to the system.
  */
-static void wl3501_config(dev_link_t *link)
+static int wl3501_config(struct pcmcia_device *link)
 {
        tuple_t tuple;
        cisparse_t parse;
-       client_handle_t handle = link->handle;
        struct net_device *dev = link->priv;
        int i = 0, j, last_fn, last_ret;
        unsigned char bf[64];
@@ -2052,18 +1985,15 @@ static void wl3501_config(dev_link_t *link)
        /* This reads the card's CONFIG tuple to find its config registers. */
        tuple.Attributes        = 0;
        tuple.DesiredTuple      = CISTPL_CONFIG;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
+       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
        tuple.TupleData         = bf;
        tuple.TupleDataMax      = sizeof(bf);
        tuple.TupleOffset       = 0;
-       CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
-       CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
+       CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
+       CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
        link->conf.ConfigBase   = parse.config.base;
        link->conf.Present      = parse.config.rmask[0];
 
-       /* Configure card */
-       link->state |= DEV_CONFIG;
-
        /* Try allocating IO ports.  This tries a few fixed addresses.  If you
         * want, you can also read the card's config table to pick addresses --
         * see the serial driver for an example. */
@@ -2073,28 +2003,28 @@ static void wl3501_config(dev_link_t *link)
                 * 0x200-0x2ff, and so on, because this seems safer */
                link->io.BasePort1 = j;
                link->io.BasePort2 = link->io.BasePort1 + 0x10;
-               i = pcmcia_request_io(link->handle, &link->io);
+               i = pcmcia_request_io(link, &link->io);
                if (i == CS_SUCCESS)
                        break;
        }
        if (i != CS_SUCCESS) {
-               cs_error(link->handle, RequestIO, i);
+               cs_error(link, RequestIO, i);
                goto failed;
        }
 
        /* Now allocate an interrupt line. Note that this does not actually
         * assign a handler to the interrupt. */
 
-       CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
+       CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
 
        /* This actually configures the PCMCIA socket -- setting up the I/O
         * windows and the interrupt mapping.  */
 
-       CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link->handle, &link->conf));
+       CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
 
        dev->irq = link->irq.AssignedIRQ;
        dev->base_addr = link->io.BasePort1;
-       SET_NETDEV_DEV(dev, &handle_to_dev(handle));
+       SET_NETDEV_DEV(dev, &handle_to_dev(link));
        if (register_netdev(dev)) {
                printk(KERN_NOTICE "wl3501_cs: register_netdev() failed\n");
                goto failed;
@@ -2105,10 +2035,9 @@ static void wl3501_config(dev_link_t *link)
        this = dev->priv;
        /*
         * At this point, the dev_node_t structure(s) should be initialized and
-        * arranged in a linked list at link->dev.
+        * arranged in a linked list at link->dev_node.
         */
-       link->dev = &this->node;
-       link->state &= ~DEV_CONFIG_PENDING;
+       link->dev_node = &this->node;
 
        this->base_addr = dev->base_addr;
 
@@ -2144,13 +2073,13 @@ static void wl3501_config(dev_link_t *link)
        spin_lock_init(&this->lock);
        init_waitqueue_head(&this->wait);
        netif_start_queue(dev);
-       goto out;
+       return 0;
+
 cs_failed:
-       cs_error(link->handle, last_fn, last_ret);
+       cs_error(link, last_fn, last_ret);
 failed:
        wl3501_release(link);
-out:
-       return;
+       return -ENODEV;
 }
 
 /**
@@ -2161,91 +2090,58 @@ out:
  * and release the PCMCIA configuration.  If the device is still open, this
  * will be postponed until it is closed.
  */
-static void wl3501_release(dev_link_t *link)
+static void wl3501_release(struct pcmcia_device *link)
 {
        struct net_device *dev = link->priv;
 
        /* Unlink the device chain */
-       if (link->dev) {
+       if (link->dev_node)
                unregister_netdev(dev);
-               link->dev = NULL;
-       }
 
-       /* Don't bother checking to see if these succeed or not */
-       pcmcia_release_configuration(link->handle);
-       pcmcia_release_io(link->handle, &link->io);
-       pcmcia_release_irq(link->handle, &link->irq);
-       link->state &= ~DEV_CONFIG;
+       pcmcia_disable_device(link);
 }
 
-/**
- * wl3501_event - The card status event handler
- * @event - event
- * @pri - priority
- * @args - arguments for this event
- *
- * The card status event handler. Mostly, this schedules other stuff to run
- * after an event is received. A CARD_REMOVAL event also sets some flags to
- * discourage the net drivers from trying to talk to the card any more.
- *
- * When a CARD_REMOVAL event is received, we immediately set a flag to block
- * future accesses to this device. All the functions that actually access the
- * device should check this flag to make sure the card is still present.
- */
-static int wl3501_event(event_t event, int pri, event_callback_args_t *args)
+static int wl3501_suspend(struct pcmcia_device *link)
 {
-       dev_link_t *link = args->client_data;
        struct net_device *dev = link->priv;
 
-       switch (event) {
-       case CS_EVENT_CARD_REMOVAL:
-               link->state &= ~DEV_PRESENT;
-               if (link->state & DEV_CONFIG) {
-                       while (link->open > 0)
-                               wl3501_close(dev);
-                       netif_device_detach(dev);
-                       wl3501_release(link);
-               }
-               break;
-       case CS_EVENT_CARD_INSERTION:
-               link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
-               wl3501_config(link);
-               break;
-       case CS_EVENT_PM_SUSPEND:
-               link->state |= DEV_SUSPEND;
-               wl3501_pwr_mgmt(dev->priv, WL3501_SUSPEND);
-               /* Fall through... */
-       case CS_EVENT_RESET_PHYSICAL:
-               if (link->state & DEV_CONFIG) {
-                       if (link->open)
-                               netif_device_detach(dev);
-                       pcmcia_release_configuration(link->handle);
-               }
-               break;
-       case CS_EVENT_PM_RESUME:
-               link->state &= ~DEV_SUSPEND;
-               wl3501_pwr_mgmt(dev->priv, WL3501_RESUME);
-               /* Fall through... */
-       case CS_EVENT_CARD_RESET:
-               if (link->state & DEV_CONFIG) {
-                       pcmcia_request_configuration(link->handle, &link->conf);
-                       if (link->open) {
-                               wl3501_reset(dev);
-                               netif_device_attach(dev);
-                       }
-               }
-               break;
+       wl3501_pwr_mgmt(dev->priv, WL3501_SUSPEND);
+       if (link->open)
+               netif_device_detach(dev);
+
+       return 0;
+}
+
+static int wl3501_resume(struct pcmcia_device *link)
+{
+       struct net_device *dev = link->priv;
+
+       wl3501_pwr_mgmt(dev->priv, WL3501_RESUME);
+       if (link->open) {
+               wl3501_reset(dev);
+               netif_device_attach(dev);
        }
+
        return 0;
 }
 
+
+static struct pcmcia_device_id wl3501_ids[] = {
+       PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0001),
+       PCMCIA_DEVICE_NULL
+};
+MODULE_DEVICE_TABLE(pcmcia, wl3501_ids);
+
 static struct pcmcia_driver wl3501_driver = {
-       .owner          = THIS_MODULE,
-       .drv            = {
-               .name   = "wl3501_cs",
+       .owner          = THIS_MODULE,
+       .drv            = {
+               .name   = "wl3501_cs",
        },
-       .attach         = wl3501_attach,
-       .detach         = wl3501_detach,
+       .probe          = wl3501_probe,
+       .remove         = wl3501_detach,
+       .id_table       = wl3501_ids,
+       .suspend        = wl3501_suspend,
+       .resume         = wl3501_resume,
 };
 
 static int __init wl3501_init_module(void)
@@ -2255,9 +2151,7 @@ static int __init wl3501_init_module(void)
 
 static void __exit wl3501_exit_module(void)
 {
-       dprintk(0, ": unloading");
        pcmcia_unregister_driver(&wl3501_driver);
-       BUG_ON(wl3501_dev_list != NULL);
 }
 
 module_init(wl3501_init_module);