linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / net / wireless / orinoco_cs.c
index bc14689..ec6f2a4 100644 (file)
@@ -13,6 +13,7 @@
 #define DRIVER_NAME "orinoco_cs"
 #define PFX DRIVER_NAME ": "
 
+#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
@@ -48,7 +49,7 @@ MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket
 /* PCMCIA specific device information (goes in the card field of
  * struct orinoco_private */
 struct orinoco_pccard {
-       struct pcmcia_device    *p_dev;
+       dev_link_t link;
        dev_node_t node;
 
        /* Used to handle hard reset */
@@ -62,8 +63,8 @@ struct orinoco_pccard {
 /* Function prototypes                                             */
 /********************************************************************/
 
-static int orinoco_cs_config(struct pcmcia_device *link);
-static void orinoco_cs_release(struct pcmcia_device *link);
+static void orinoco_cs_config(dev_link_t *link);
+static void orinoco_cs_release(dev_link_t *link);
 static void orinoco_cs_detach(struct pcmcia_device *p_dev);
 
 /********************************************************************/
@@ -74,13 +75,13 @@ static int
 orinoco_cs_hard_reset(struct orinoco_private *priv)
 {
        struct orinoco_pccard *card = priv->card;
-       struct pcmcia_device *link = card->p_dev;
+       dev_link_t *link = &card->link;
        int err;
 
        /* We need atomic ops here, because we're not holding the lock */
        set_bit(0, &card->hard_reset_in_progress);
 
-       err = pcmcia_reset_card(link, NULL);
+       err = pcmcia_reset_card(link->handle, NULL);
        if (err)
                return err;
 
@@ -103,11 +104,12 @@ orinoco_cs_hard_reset(struct orinoco_private *priv)
  * configure the card at this point -- we wait until we receive a card
  * insertion event.  */
 static int
-orinoco_cs_probe(struct pcmcia_device *link)
+orinoco_cs_attach(struct pcmcia_device *p_dev)
 {
        struct net_device *dev;
        struct orinoco_private *priv;
        struct orinoco_pccard *card;
+       dev_link_t *link;
 
        dev = alloc_orinocodev(sizeof(*card), orinoco_cs_hard_reset);
        if (! dev)
@@ -116,7 +118,7 @@ orinoco_cs_probe(struct pcmcia_device *link)
        card = priv->card;
 
        /* Link both structures together */
-       card->p_dev = link;
+       link = &card->link;
        link->priv = dev;
 
        /* Interrupt setup */
@@ -133,7 +135,16 @@ orinoco_cs_probe(struct pcmcia_device *link)
        link->conf.Attributes = 0;
        link->conf.IntType = INT_MEMORY_AND_IO;
 
-       return orinoco_cs_config(link);
+       /* Register with Card Services */
+       link->next = NULL;
+
+       link->handle = p_dev;
+       p_dev->instance = link;
+
+       link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
+       orinoco_cs_config(link);
+
+       return 0;
 }                              /* orinoco_cs_attach */
 
 /*
@@ -142,15 +153,20 @@ orinoco_cs_probe(struct pcmcia_device *link)
  * are freed.  Otherwise, the structures will be freed when the device
  * is released.
  */
-static void orinoco_cs_detach(struct pcmcia_device *link)
+static void orinoco_cs_detach(struct pcmcia_device *p_dev)
 {
+       dev_link_t *link = dev_to_instance(p_dev);
        struct net_device *dev = link->priv;
 
-       if (link->dev_node)
-               unregister_netdev(dev);
-
-       orinoco_cs_release(link);
+       if (link->state & DEV_CONFIG)
+               orinoco_cs_release(link);
 
+       DEBUG(0, PFX "detach: link=%p link->dev=%p\n", link, link->dev);
+       if (link->dev) {
+               DEBUG(0, PFX "About to unregister net device %p\n",
+                     dev);
+               unregister_netdev(dev);
+       }
        free_orinocodev(dev);
 }                              /* orinoco_cs_detach */
 
@@ -164,20 +180,24 @@ static void orinoco_cs_detach(struct pcmcia_device *link)
                last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; \
        } while (0)
 
-static int
-orinoco_cs_config(struct pcmcia_device *link)
+static void
+orinoco_cs_config(dev_link_t *link)
 {
        struct net_device *dev = link->priv;
+       client_handle_t handle = link->handle;
        struct orinoco_private *priv = netdev_priv(dev);
        struct orinoco_pccard *card = priv->card;
        hermes_t *hw = &priv->hw;
        int last_fn, last_ret;
        u_char buf[64];
        config_info_t conf;
+       cisinfo_t info;
        tuple_t tuple;
        cisparse_t parse;
        void __iomem *mem;
 
+       CS_CHECK(ValidateCIS, pcmcia_validate_cis(handle, &info));
+
        /*
         * This reads the card's CONFIG tuple to find its
         * configuration registers.
@@ -187,15 +207,19 @@ orinoco_cs_config(struct pcmcia_device *link)
        tuple.TupleData = buf;
        tuple.TupleDataMax = sizeof(buf);
        tuple.TupleOffset = 0;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
-       CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
+       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
+       CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
+       CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
        link->conf.ConfigBase = parse.config.base;
        link->conf.Present = parse.config.rmask[0];
 
+       /* Configure card */
+       link->state |= DEV_CONFIG;
+
        /* Look up the current Vcc */
        CS_CHECK(GetConfigurationInfo,
-                pcmcia_get_configuration_info(link, &conf));
+                pcmcia_get_configuration_info(handle, &conf));
+       link->conf.Vcc = conf.Vcc;
 
        /*
         * In this loop, we scan the CIS for configuration table
@@ -212,13 +236,13 @@ orinoco_cs_config(struct pcmcia_device *link)
         * implementation-defined details.
         */
        tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
+       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
        while (1) {
                cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
                cistpl_cftable_entry_t dflt = { .index = 0 };
 
-               if ( (pcmcia_get_tuple_data(link, &tuple) != 0)
-                   || (pcmcia_parse_tuple(link, &tuple, &parse) != 0))
+               if ( (pcmcia_get_tuple_data(handle, &tuple) != 0)
+                   || (pcmcia_parse_tuple(handle, &tuple, &parse) != 0))
                        goto next_entry;
 
                if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
@@ -227,6 +251,12 @@ orinoco_cs_config(struct pcmcia_device *link)
                        goto next_entry;
                link->conf.ConfigIndex = cfg->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)) {
@@ -244,10 +274,10 @@ orinoco_cs_config(struct pcmcia_device *link)
                }
 
                if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
+                       link->conf.Vpp1 = link->conf.Vpp2 =
                            cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
                else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
+                       link->conf.Vpp1 = link->conf.Vpp2 =
                            dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
                
                /* Do we need to allocate an interrupt? */
@@ -277,7 +307,7 @@ orinoco_cs_config(struct pcmcia_device *link)
                        }
 
                        /* This reserves IO space but doesn't actually enable it */
-                       if (pcmcia_request_io(link, &link->io) != 0)
+                       if (pcmcia_request_io(link->handle, &link->io) != 0)
                                goto next_entry;
                }
 
@@ -287,8 +317,9 @@ orinoco_cs_config(struct pcmcia_device *link)
                break;
                
        next_entry:
-               pcmcia_disable_device(link);
-               last_ret = pcmcia_get_next_tuple(link, &tuple);
+               if (link->io.NumPorts1)
+                       pcmcia_release_io(link->handle, &link->io);
+               last_ret = pcmcia_get_next_tuple(handle, &tuple);
                if (last_ret  == CS_NO_MORE_ITEMS) {
                        printk(KERN_ERR PFX "GetNextTuple(): No matching "
                               "CIS configuration.  Maybe you need the "
@@ -302,7 +333,7 @@ orinoco_cs_config(struct pcmcia_device *link)
         * a handler to the interrupt, unless the 'Handler' member of
         * the irq structure is initialized.
         */
-       CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
+       CS_CHECK(RequestIRQ, pcmcia_request_irq(link->handle, &link->irq));
 
        /* We initialize the hermes structure before completing PCMCIA
         * configuration just in case the interrupt handler gets
@@ -319,7 +350,7 @@ orinoco_cs_config(struct pcmcia_device *link)
         * card and host interface into "Memory and IO" mode.
         */
        CS_CHECK(RequestConfiguration,
-                pcmcia_request_configuration(link, &link->conf));
+                pcmcia_request_configuration(link->handle, &link->conf));
 
        /* Ok, we have the configuration, prepare to register the netdev */
        dev->base_addr = link->io.BasePort1;
@@ -327,7 +358,7 @@ orinoco_cs_config(struct pcmcia_device *link)
        SET_MODULE_OWNER(dev);
        card->node.major = card->node.minor = 0;
 
-       SET_NETDEV_DEV(dev, &handle_to_dev(link));
+       SET_NETDEV_DEV(dev, &handle_to_dev(handle));
        /* Tell the stack we exist */
        if (register_netdev(dev) != 0) {
                printk(KERN_ERR PFX "register_netdev() failed\n");
@@ -335,26 +366,36 @@ orinoco_cs_config(struct pcmcia_device *link)
        }
 
        /* At this point, the dev_node_t structure(s) needs to be
-        * initialized and arranged in a linked list at link->dev_node. */
+        * initialized and arranged in a linked list at link->dev. */
        strcpy(card->node.dev_name, dev->name);
-       link->dev_node = &card->node; /* link->dev_node being non-NULL is also
+       link->dev = &card->node; /* link->dev being non-NULL is also
                                     used to indicate that the
                                     net_device has been registered */
+       link->state &= ~DEV_CONFIG_PENDING;
 
        /* Finally, report what we've done */
-       printk(KERN_DEBUG "%s: " DRIVER_NAME " at %s, irq %d, io "
-              "0x%04x-0x%04x\n", dev->name, dev->class_dev.dev->bus_id,
-              link->irq.AssignedIRQ, link->io.BasePort1,
-              link->io.BasePort1 + link->io.NumPorts1 - 1);
-
-       return 0;
+       printk(KERN_DEBUG "%s: index 0x%02x: Vcc %d.%d",
+              dev->name, 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(", irq %d", link->irq.AssignedIRQ);
+       if (link->io.NumPorts1)
+               printk(", io 0x%04x-0x%04x", link->io.BasePort1,
+                      link->io.BasePort1 + link->io.NumPorts1 - 1);
+       if (link->io.NumPorts2)
+               printk(" & 0x%04x-0x%04x", link->io.BasePort2,
+                      link->io.BasePort2 + link->io.NumPorts2 - 1);
+       printk("\n");
+
+       return;
 
  cs_failed:
-       cs_error(link, last_fn, last_ret);
+       cs_error(link->handle, last_fn, last_ret);
 
  failed:
        orinoco_cs_release(link);
-       return -ENODEV;
 }                              /* orinoco_cs_config */
 
 /*
@@ -363,7 +404,7 @@ orinoco_cs_config(struct pcmcia_device *link)
  * still open, this will be postponed until it is closed.
  */
 static void
-orinoco_cs_release(struct pcmcia_device *link)
+orinoco_cs_release(dev_link_t *link)
 {
        struct net_device *dev = link->priv;
        struct orinoco_private *priv = netdev_priv(dev);
@@ -375,70 +416,91 @@ orinoco_cs_release(struct pcmcia_device *link)
        priv->hw_unavailable++;
        spin_unlock_irqrestore(&priv->lock, flags);
 
-       pcmcia_disable_device(link);
+       /* Don't bother checking to see if these succeed or not */
+       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;
        if (priv->hw.iobase)
                ioport_unmap(priv->hw.iobase);
 }                              /* orinoco_cs_release */
 
-static int orinoco_cs_suspend(struct pcmcia_device *link)
+static int orinoco_cs_suspend(struct pcmcia_device *p_dev)
 {
+       dev_link_t *link = dev_to_instance(p_dev);
        struct net_device *dev = link->priv;
        struct orinoco_private *priv = netdev_priv(dev);
        struct orinoco_pccard *card = priv->card;
        int err = 0;
        unsigned long flags;
 
-       /* This is probably racy, but I can't think of
-          a better way, short of rewriting the PCMCIA
-          layer to not suck :-( */
-       if (! test_bit(0, &card->hard_reset_in_progress)) {
-               spin_lock_irqsave(&priv->lock, flags);
+       link->state |= DEV_SUSPEND;
+       if (link->state & DEV_CONFIG) {
+               /* This is probably racy, but I can't think of
+                  a better way, short of rewriting the PCMCIA
+                  layer to not suck :-( */
+               if (! test_bit(0, &card->hard_reset_in_progress)) {
+                       spin_lock_irqsave(&priv->lock, flags);
+
+                       err = __orinoco_down(dev);
+                       if (err)
+                               printk(KERN_WARNING "%s: Error %d downing interface\n",
+                                      dev->name, err);
 
-               err = __orinoco_down(dev);
-               if (err)
-                       printk(KERN_WARNING "%s: Error %d downing interface\n",
-                              dev->name, err);
+                       netif_device_detach(dev);
+                       priv->hw_unavailable++;
 
-               netif_device_detach(dev);
-               priv->hw_unavailable++;
+                       spin_unlock_irqrestore(&priv->lock, flags);
+               }
 
-               spin_unlock_irqrestore(&priv->lock, flags);
+               pcmcia_release_configuration(link->handle);
        }
 
        return 0;
 }
 
-static int orinoco_cs_resume(struct pcmcia_device *link)
+static int orinoco_cs_resume(struct pcmcia_device *p_dev)
 {
+       dev_link_t *link = dev_to_instance(p_dev);
        struct net_device *dev = link->priv;
        struct orinoco_private *priv = netdev_priv(dev);
        struct orinoco_pccard *card = priv->card;
        int err = 0;
+       unsigned long flags;
 
-       if (! test_bit(0, &card->hard_reset_in_progress)) {
-               err = orinoco_reinit_firmware(dev);
-               if (err) {
-                       printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
-                              dev->name, err);
-                       return -EIO;
-               }
+       link->state &= ~DEV_SUSPEND;
+       if (link->state & DEV_CONFIG) {
+               /* FIXME: should we double check that this is
+                * the same card as we had before */
+               pcmcia_request_configuration(link->handle, &link->conf);
+
+               if (! test_bit(0, &card->hard_reset_in_progress)) {
+                       err = orinoco_reinit_firmware(dev);
+                       if (err) {
+                               printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
+                                      dev->name, err);
+                               return -EIO;
+                       }
 
-               spin_lock(&priv->lock);
+                       spin_lock_irqsave(&priv->lock, flags);
 
-               netif_device_attach(dev);
-               priv->hw_unavailable--;
+                       netif_device_attach(dev);
+                       priv->hw_unavailable--;
 
-               if (priv->open && ! priv->hw_unavailable) {
-                       err = __orinoco_up(dev);
-                       if (err)
-                               printk(KERN_ERR "%s: Error %d restarting card\n",
-                                      dev->name, err);
-               }
+                       if (priv->open && ! priv->hw_unavailable) {
+                               err = __orinoco_up(dev);
+                               if (err)
+                                       printk(KERN_ERR "%s: Error %d restarting card\n",
+                                              dev->name, err);
+                       }
 
-               spin_unlock(&priv->lock);
+                       spin_unlock_irqrestore(&priv->lock, flags);
+               }
        }
 
-       return err;
+       return 0;
 }
 
 
@@ -542,7 +604,7 @@ static struct pcmcia_driver orinoco_driver = {
        .drv            = {
                .name   = DRIVER_NAME,
        },
-       .probe          = orinoco_cs_probe,
+       .probe          = orinoco_cs_attach,
        .remove         = orinoco_cs_detach,
        .id_table       = orinoco_cs_ids,
        .suspend        = orinoco_cs_suspend,