]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] orinoco driver update
authorDavid Gibson <david@gibson.dropbear.id.au>
Tue, 30 Apr 2002 07:42:48 +0000 (00:42 -0700)
committerLinus Torvalds <torvalds@penguin.transmeta.com>
Tue, 30 Apr 2002 07:42:48 +0000 (00:42 -0700)
The following patch against 2.5.11 updates the orinoco driver.  As well
as miscellaneous updates to the driver core it adds a new module
supporting Prism 2.5 based PCI wireless cards, and adds a MAINTAINERS
entry for the driver.

14 files changed:
MAINTAINERS
drivers/net/wireless/Config.help
drivers/net/wireless/Config.in
drivers/net/wireless/Makefile
drivers/net/wireless/airport.c
drivers/net/wireless/hermes.c
drivers/net/wireless/hermes.h
drivers/net/wireless/hermes_rid.h [new file with mode: 0644]
drivers/net/wireless/ieee802_11.h [new file with mode: 0644]
drivers/net/wireless/orinoco.c
drivers/net/wireless/orinoco.h
drivers/net/wireless/orinoco_cs.c
drivers/net/wireless/orinoco_pci.c [new file with mode: 0644]
drivers/net/wireless/orinoco_plx.c

index 29af3924e048a839ca83463415d2d31d4139db1d..11a48068e3d9423b8f1382d9d2bd524e2d3525d3 100644 (file)
@@ -1180,6 +1180,12 @@ M:       zwane@commfireservices.com
 L:     linux-sound@vger.kernel.org
 S:     Maintained
 
+ORINOCO DRIVER
+P:     David Gibson
+M:     hermes@gibson.dropbear.id.au
+W:     http://www.ozlabs.org/people/dgibson/dldwd
+S:     Maintained
+
 PARALLEL PORT SUPPORT
 P:     Phil Blundell
 M:     Philip.Blundell@pobox.com
index a3a0f66758451dd495e68e3f4c2829e78c4a0106..c9a70e228782ad41b2c9952739cb90f6de62681d 100644 (file)
@@ -55,6 +55,14 @@ CONFIG_PLX_HERMES
   Support for these adaptors is so far still incomplete and buggy.
   You have been warned.
 
+Prism 2.5 PCI 802.11b adaptor support
+CONFIG_PCI_HERMES
+  Enable support for PCI and mini-PCI 802.11b wireless NICs based on
+  the Prism 2.5 chipset.  These are true PCI cards, not the 802.11b
+  PCMCIA cards bundled with PCI<->PCMCIA adaptors which are also
+  common.  Some of the built-in wireless adaptors in laptops are of
+  this variety.
+
 CONFIG_PCMCIA_HERMES
   A driver for "Hermes" chipset based PCMCIA wireless adaptors, such
   as the Lucent WavelanIEEE/Orinoco cards and their OEM (Cabletron/
index f4fabcff0806e170c3062c2a80a133c20ea77e44..15ec65f86935103fc0686770c94387cacbcc6ab7 100644 (file)
@@ -20,6 +20,7 @@ fi
 
 if [ "$CONFIG_PCI" = "y" ]; then
    dep_tristate '    Hermes in PLX9052 based PCI adaptor support (Netgear MA301 etc.)' CONFIG_PLX_HERMES $CONFIG_HERMES $CONFIG_EXPERIMENTAL
+   dep_tristate '    Prism 2.5 PCI 802.11b adaptor support' CONFIG_PCI_HERMES $CONFIG_HERMES $CONFIG_EXPERIMENTAL
 fi
 
 # If Pcmcia is compiled in, offer Pcmcia cards...
index b3b8df628b5a6388b5265b0946469672b3ecb311..0b9a00f68654942154807bf3cf6bd9253a665548 100644 (file)
@@ -23,6 +23,7 @@ obj-$(CONFIG_HERMES)          += orinoco.o hermes.o
 obj-$(CONFIG_PCMCIA_HERMES)    += orinoco_cs.o
 obj-$(CONFIG_APPLE_AIRPORT)    += airport.o
 obj-$(CONFIG_PLX_HERMES)       += orinoco_plx.o
+obj-$(CONFIG_PCI_HERMES)       += orinoco_pci.o
 
 obj-$(CONFIG_AIRO)             += airo.o
 obj-$(CONFIG_AIRO_CS)          += airo_cs.o airo.o
index 9e0d1a6cd8d332db5d948ea06379d50a04b5f8f1..5a1ab243b5b4bea11afaf3665f868d0c4623373d 100644 (file)
@@ -1,4 +1,4 @@
-/* airport.c 0.06f
+/* airport.c 0.11a
  *
  * A driver for "Hermes" chipset based Apple Airport wireless
  * card.
@@ -11,6 +11,8 @@
  *  0.06 : fix possible hang on powerup, add sleep support
  */
 
+#include <linux/config.h>
+
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/pmu.h>
 
 #include <asm/prom.h>
-#include <asm/feature.h>
+#include <asm/machdep.h>
+#include <asm/pmac_feature.h>
 #include <asm/irq.h>
 
 #include "hermes.h"
 #include "orinoco.h"
 
-static char version[] __initdata = "airport.c 0.06f (Benjamin Herrenschmidt <benh@kernel.crashing.org>)";
+static char version[] __initdata = "airport.c 0.11a (Benjamin Herrenschmidt <benh@kernel.crashing.org>)";
 MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
 MODULE_DESCRIPTION("Driver for the Apple Airport wireless card.");
 MODULE_LICENSE("Dual MPL/GPL");
 EXPORT_NO_SYMBOLS;
 
-typedef struct dldwd_card {
+#define AIRPORT_IO_LEN (0x1000)        /* one page */
+
+struct airport {
        struct device_node* node;
+       void *vaddr;
        int irq_requested;
        int ndev_registered;
        int open;
-       /* Common structure (fully included), see orinoco.h */
-       struct dldwd_priv priv;
-} dldwd_card_t;
+};
 
 #ifdef CONFIG_PMAC_PBOOK
 static int airport_sleep_notify(struct pmu_sleep_notifier *self, int when);
@@ -65,9 +69,8 @@ static struct pmu_sleep_notifier airport_sleep_notifier = {
  * Function prototypes
  */
 
-static dldwd_priv_t* airport_attach(struct device_node *of_node);
-static void airport_detach(dldwd_priv_t* priv);
-static int airport_init(struct net_device *dev);
+static struct net_device *airport_attach(struct device_node *of_node);
+static void airport_detach(struct net_device *dev);
 static int airport_open(struct net_device *dev);
 static int airport_stop(struct net_device *dev);
 
@@ -81,44 +84,28 @@ static int airport_stop(struct net_device *dev);
    device numbers are used to derive the corresponding array index.
 */
 
-static dldwd_priv_t *airport_dev;
-
-static int airport_init(struct net_device *dev)
-{
-       dldwd_priv_t *priv = dev->priv;
-       int rc;
-       
-       TRACE_ENTER(priv->ndev.name);
-
-       MOD_INC_USE_COUNT;
-
-       rc = dldwd_init(dev);
-       if (!rc)
-               priv->hw_ready = 1;
-
-       MOD_DEC_USE_COUNT;
-
-       return rc;
-}
+static struct net_device *airport_dev;
 
 static int
 airport_open(struct net_device *dev)
 {
-       dldwd_priv_t *priv = dev->priv;
-       dldwd_card_t* card = (dldwd_card_t *)priv->card;
+       struct orinoco_private *priv = dev->priv;
+       struct airport* card = (struct airport *)priv->card;
        int rc;
 
-       TRACE_ENTER(priv->ndev.name);
+       TRACE_ENTER(dev->name);
 
-       rc = dldwd_reset(priv);
+       netif_device_attach(dev);
+
+       rc = orinoco_reset(priv);
        if (rc)
                airport_stop(dev);
        else {
                card->open = 1;
-               netif_device_attach(dev);
+               netif_start_queue(dev);
        }
 
-//     TRACE_EXIT(priv->ndev.name);
+       TRACE_EXIT(dev->name);
 
        return rc;
 }
@@ -126,16 +113,16 @@ airport_open(struct net_device *dev)
 static int
 airport_stop(struct net_device *dev)
 {
-       dldwd_priv_t *priv = dev->priv;
-       dldwd_card_t* card = (dldwd_card_t *)priv->card;
+       struct orinoco_private *priv = dev->priv;
+       struct airport* card = (struct airport *)priv->card;
 
-       TRACE_ENTER(priv->ndev.name);
+       TRACE_ENTER(dev->name);
 
        netif_stop_queue(dev);
-       dldwd_shutdown(priv);
+       orinoco_shutdown(priv);
        card->open = 0;
 
-       TRACE_EXIT(priv->ndev.name);
+       TRACE_EXIT(dev->name);
 
        return 0;
 }
@@ -144,16 +131,14 @@ airport_stop(struct net_device *dev)
 static int
 airport_sleep_notify(struct pmu_sleep_notifier *self, int when)
 {
-       dldwd_priv_t *priv;
-       struct net_device *ndev;
-       dldwd_card_t* card;
+       struct net_device *dev = airport_dev;
+       struct orinoco_private *priv = (struct orinoco_private *)dev->priv;
+       struct hermes *hw = &priv->hw;
+       struct airport* card = (struct airport *)priv->card;
        int rc;
        
-       if (!airport_dev)
+       if (! airport_dev)
                return PBOOK_SLEEP_OK;
-       priv = airport_dev;
-       ndev = &priv->ndev;
-       card = (dldwd_card_t *)priv->card;
 
        switch (when) {
        case PBOOK_SLEEP_REQUEST:
@@ -161,41 +146,42 @@ airport_sleep_notify(struct pmu_sleep_notifier *self, int when)
        case PBOOK_SLEEP_REJECT:
                break;
        case PBOOK_SLEEP_NOW:
-               printk(KERN_INFO "%s: Airport entering sleep mode\n", ndev->name);
-               netif_device_detach(ndev);
-               if (card->open)
-                       dldwd_shutdown(priv);
-               disable_irq(ndev->irq);
-               feature_set_airport_power(card->node, 0);
-               priv->hw_ready = 0;
+               printk(KERN_INFO "%s: Airport entering sleep mode\n", dev->name);
+               if (card->open) {
+                       netif_stop_queue(dev);
+                       orinoco_shutdown(priv);
+                       netif_device_detach(dev);
+               }
+               disable_irq(dev->irq);
+               pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, card->node, 0, 0);
                break;
        case PBOOK_WAKE:
-               printk(KERN_INFO "%s: Airport waking up\n", ndev->name);
-               feature_set_airport_power(card->node, 1);
+               printk(KERN_INFO "%s: Airport waking up\n", dev->name);
+               pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, card->node, 0, 1);
                mdelay(200);
-               hermes_reset(&priv->hw);
-               priv->hw_ready = 1;             
-               rc = dldwd_reset(priv);
+               hermes_reset(hw);
+               rc = orinoco_reset(priv);
                if (rc)
                        printk(KERN_ERR "airport: Error %d re-initing card !\n", rc);
                else if (card->open)
-                       netif_device_attach(ndev);
-               enable_irq(ndev->irq);
+                       netif_device_attach(dev);
+               enable_irq(dev->irq);
                break;
        }
        return PBOOK_SLEEP_OK;
 }
 #endif /* CONFIG_PMAC_PBOOK */
 
-static dldwd_priv_t*
+static struct net_device *
 airport_attach(struct device_node* of_node)
 {
-       dldwd_priv_t *priv;
-       struct net_device *ndev;
-       dldwd_card_t* card;
+       struct orinoco_private *priv;
+       struct net_device *dev;
+       struct airport *card;
+       unsigned long phys_addr;
        hermes_t *hw;
 
-       TRACE_ENTER("dldwd");
+       TRACE_ENTER("orinoco");
 
        if (of_node->n_addrs < 1 || of_node->n_intrs < 1) {
                printk(KERN_ERR "airport: wrong interrupt/addresses in OF tree\n");
@@ -203,74 +189,77 @@ airport_attach(struct device_node* of_node)
        }
 
        /* Allocate space for private device-specific data */
-       card = kmalloc(sizeof(*card), GFP_KERNEL);
-       if (!card) {
+       dev = alloc_orinocodev(sizeof(*card));
+       if (! dev) {
                printk(KERN_ERR "airport: can't allocate device datas\n");
                return NULL;
        }
-       memset(card, 0, sizeof(*card));
+       priv = dev->priv;
+       card = priv->card;
 
-       priv = &(card->priv);
-       priv->card = card;
-       ndev = &priv->ndev;
        hw = &priv->hw;
        card->node = of_node;
 
-       /* Setup the common part */
-       if (dldwd_setup(priv) < 0) {
-               kfree(card);
+       if (! request_OF_resource(of_node, 0, " (airport)")) {
+               printk(KERN_ERR "airport: can't request IO resource !\n");
+               kfree(dev);
                return NULL;
        }
+       
+       dev->name[0] = '\0';    /* register_netdev will give us an ethX name */
+       SET_MODULE_OWNER(dev);
 
        /* Overrides */
-       ndev->init = airport_init;
-       ndev->open = airport_open;
-       ndev->stop = airport_stop;
+       dev->open = airport_open;
+       dev->stop = airport_stop;
 
        /* Setup interrupts & base address */
-       ndev->irq = of_node->intrs[0].line;
-       ndev->base_addr = (unsigned long)ioremap(of_node->addrs[0].address, 0x1000) - _IO_BASE;
+       dev->irq = of_node->intrs[0].line;
+       phys_addr = of_node->addrs[0].address; /* Physical address */
+       dev->base_addr = phys_addr;
+       card->vaddr = ioremap(phys_addr, AIRPORT_IO_LEN);
+       if (! card->vaddr) {
+               printk("airport: ioremap() failed\n");
+               goto failed;
+       }
 
-       hermes_struct_init(hw, ndev->base_addr);
+       hermes_struct_init(hw, (ulong)card->vaddr,
+                       HERMES_MEM, HERMES_16BIT_REGSPACING);
                
        /* Power up card */
-       feature_set_airport_power(card->node, 1);
+       pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, card->node, 0, 1);
        current->state = TASK_UNINTERRUPTIBLE;
        schedule_timeout(HZ);
 
        /* Reset it before we get the interrupt */
        hermes_reset(hw);
 
-       if (request_irq(ndev->irq, dldwd_interrupt, 0, "Airport", (void *)priv)) {
-               printk(KERN_ERR "airport: Couldn't get IRQ %d\n", ndev->irq);
+       if (request_irq(dev->irq, orinoco_interrupt, 0, "Airport", (void *)priv)) {
+               printk(KERN_ERR "airport: Couldn't get IRQ %d\n", dev->irq);
                goto failed;
        }
        card->irq_requested = 1;
        
-       /* register_netdev will give us an ethX name */
-       ndev->name[0] = '\0';
        /* Tell the stack we exist */
-       if (register_netdev(ndev) != 0) {
+       if (register_netdev(dev) != 0) {
                printk(KERN_ERR "airport: register_netdev() failed\n");
                goto failed;
        }
-       printk(KERN_DEBUG "airport: card registered for interface %s\n", ndev->name);
+       printk(KERN_DEBUG "airport: card registered for interface %s\n", dev->name);
        card->ndev_registered = 1;
 
-       SET_MODULE_OWNER(ndev);
-
        /* And give us the proc nodes for debugging */
-       if (dldwd_proc_dev_init(priv) != 0)
+       if (orinoco_proc_dev_init(priv) != 0)
                printk(KERN_ERR "airport: Failed to create /proc node for %s\n",
-                      ndev->name);
+                      dev->name);
 
 #ifdef CONFIG_PMAC_PBOOK
        pmu_register_sleep_notifier(&airport_sleep_notifier);
 #endif
-       return priv;
+       return dev;
        
 failed:
-       airport_detach(priv);
+       airport_detach(dev);
        return NULL;
 }                              /* airport_attach */
 
@@ -279,32 +268,34 @@ failed:
   ======================================================================*/
 
 static void
-airport_detach(dldwd_priv_t *priv)
+airport_detach(struct net_device *dev)
 {
-       dldwd_card_t* card = (dldwd_card_t *)priv->card;
+       struct orinoco_private *priv = (struct orinoco_private *)dev->priv;
+       struct airport *card = (struct airport *)priv->card;
 
-       priv->hw_ready = 0;
-       
        /* Unregister proc entry */
-       dldwd_proc_dev_cleanup(priv);
+       orinoco_proc_dev_cleanup(priv);
 
 #ifdef CONFIG_PMAC_PBOOK
        pmu_unregister_sleep_notifier(&airport_sleep_notifier);
 #endif
        if (card->ndev_registered)
-               unregister_netdev(&priv->ndev);
+               unregister_netdev(dev);
        card->ndev_registered = 0;
        
        if (card->irq_requested)
-               free_irq(priv->ndev.irq, priv);
+               free_irq(dev->irq, priv);
        card->irq_requested = 0;
 
-// FIXME
-//     if (ndev->base_addr)
-//             iounmap(ndev->base_addr + _IO_BASE);
-//     ndev->base_addr = 0;
+       if (card->vaddr)
+               iounmap(card->vaddr);
+       card->vaddr = 0;
+       
+       dev->base_addr = 0;
+
+       release_OF_resource(card->node, 0);
        
-       feature_set_airport_power(card->node, 0);
+       pmac_call_feature(PMAC_FTR_AIRPORT_ENABLE, card->node, 0, 0);
        current->state = TASK_UNINTERRUPTIBLE;
        schedule_timeout(HZ);
        
index 536ffa9524f5dc8cd1b4da1b0f796ff0a2bd359d..e691667c3e03649e59b8336ae891723b2fb93d8f 100644 (file)
 
 #include "hermes.h"
 
-static char version[] __initdata = "hermes.c: 3 Oct 2001 David Gibson <hermes@gibson.dropbear.id.au>";
+static char version[] __initdata = "hermes.c: 5 Apr 2002 David Gibson <hermes@gibson.dropbear.id.au>";
 MODULE_DESCRIPTION("Low-level driver helper for Lucent Hermes chipset and Prism II HFA384x wireless MAC controller");
 MODULE_AUTHOR("David Gibson <hermes@gibson.dropbear.id.au>");
+#ifdef MODULE_LICENSE
 MODULE_LICENSE("Dual MPL/GPL");
+#endif
 
 /* These are maximum timeouts. Most often, card wil react much faster */
 #define CMD_BUSY_TIMEOUT (100) /* In iterations of ~1us */
 #define CMD_INIT_TIMEOUT (50000) /* in iterations of ~10us */
 #define CMD_COMPL_TIMEOUT (20000) /* in iterations of ~10us */
 #define ALLOC_COMPL_TIMEOUT (1000) /* in iterations of ~10us */
-#define BAP_BUSY_TIMEOUT (500) /* In iterations of ~1us */
 
 /*
  * Debugging helpers
@@ -75,9 +76,9 @@ MODULE_LICENSE("Dual MPL/GPL");
 #include <stdarg.h>
 
 #define DMSG(stuff...) do {printk(KERN_DEBUG "hermes @ 0x%x: " , hw->iobase); \
-                       printk(#stuff);} while (0)
+                       printk(stuff);} while (0)
 
-#define DEBUG(lvl, stuff...) if ( (lvl) <= HERMES_DEBUG) DMSG(#stuff)
+#define DEBUG(lvl, stuff...) if ( (lvl) <= HERMES_DEBUG) DMSG(stuff)
 
 #else /* ! HERMES_DEBUG */
 
@@ -85,6 +86,8 @@ MODULE_LICENSE("Dual MPL/GPL");
 
 #endif /* ! HERMES_DEBUG */
 
+#define IO_TYPE(hw)    ((hw)->io_space ? "IO " : "MEM ")
+
 /*
  * Internal functions
  */
@@ -98,10 +101,17 @@ MODULE_LICENSE("Dual MPL/GPL");
 */
 static int hermes_issue_cmd(hermes_t *hw, u16 cmd, u16 param0)
 {
+       int k = CMD_BUSY_TIMEOUT;
        u16 reg;
 
-       /* First check that the command register is not busy */
+       /* First wait for the command register to unbusy */
        reg = hermes_read_regn(hw, CMD);
+       while ( (reg & HERMES_CMD_BUSY) && k ) {
+               k--;
+               udelay(1);
+               reg = hermes_read_regn(hw, CMD);
+       }
+       DEBUG(3, "hermes_issue_cmd: did %d retries.\n", CMD_BUSY_TIMEOUT-k);
        if (reg & HERMES_CMD_BUSY) {
                return -EBUSY;
        }
@@ -118,10 +128,19 @@ static int hermes_issue_cmd(hermes_t *hw, u16 cmd, u16 param0)
  * Function definitions
  */
 
-void hermes_struct_init(hermes_t *hw, uint io)
+void hermes_struct_init(hermes_t *hw, ulong address,
+                       int io_space, int reg_spacing)
 {
-       hw->iobase = io;
+       hw->iobase = address;
+       hw->io_space = io_space;
+       hw->reg_spacing = reg_spacing;
        hw->inten = 0x0;
+
+#ifdef HERMES_DEBUG_BUFFER
+       hw->dbufp = 0;
+       memset(&hw->dbuf, 0xff, sizeof(hw->dbuf));
+       memset(&hw->profile, 0, sizeof(hw->profile));
+#endif
 }
 
 int hermes_reset(hermes_t *hw)
@@ -188,8 +207,9 @@ int hermes_reset(hermes_t *hw)
        }
                
        if (! (reg & HERMES_EV_CMD)) {
-               printk(KERN_ERR "hermes @ 0x%x: Timeout waiting for card to reset (reg=0x%04x)!\n",
-                      hw->iobase, reg);
+               printk(KERN_ERR "hermes @ %s0x%lx: " 
+                      "Timeout waiting for card to reset (reg=0x%04x)!\n",
+                      IO_TYPE(hw), hw->iobase, reg);
                err = -ETIMEDOUT;
                goto out;
        }
@@ -198,7 +218,8 @@ int hermes_reset(hermes_t *hw)
 
        hermes_write_regn(hw, EVACK, HERMES_EV_CMD);
 
-       err = status & HERMES_STATUS_RESULT;
+       if (status & HERMES_STATUS_RESULT)
+               err = -EIO;
 
  out:
        return err;
@@ -215,16 +236,18 @@ int hermes_docmd_wait(hermes_t *hw, u16 cmd, u16 parm0, hermes_response_t *resp)
        int err;
        int k;
        u16 reg;
+       u16 status;
 
        err = hermes_issue_cmd(hw, cmd, parm0);
        if (err) {
                if (! hermes_present(hw)) {
-                       printk(KERN_WARNING "hermes @ 0x%x: Card removed while issuing command.\n",
-                              hw->iobase);
+                       printk(KERN_WARNING "hermes @ %s0x%lx: "
+                              "Card removed while issuing command.\n",
+                              IO_TYPE(hw), hw->iobase);
                        err = -ENODEV;
                } else 
-                       printk(KERN_ERR "hermes @ 0x%x: CMD register busy in hermes_issue_command().\n",
-                              hw->iobase);
+                       printk(KERN_ERR "hermes @ %s0x%lx: Error %d issuing command.\n",
+                              IO_TYPE(hw), hw->iobase, err);
                goto out;
        }
 
@@ -237,27 +260,33 @@ int hermes_docmd_wait(hermes_t *hw, u16 cmd, u16 parm0, hermes_response_t *resp)
        }
 
        if (! hermes_present(hw)) {
-               printk(KERN_WARNING "hermes @ 0x%x: Card removed while waiting for command completion.\n",
-                      hw->iobase);
+               printk(KERN_WARNING "hermes @ %s0x%lx: "
+                      "Card removed while waiting for command completion.\n",
+                      IO_TYPE(hw), hw->iobase);
                err = -ENODEV;
                goto out;
        }
                
        if (! (reg & HERMES_EV_CMD)) {
-               printk(KERN_ERR "hermes @ 0x%x: Timeout waiting for command completion.\n",
-                      hw->iobase);
+               printk(KERN_ERR "hermes @ %s0x%lx: "
+                      "Timeout waiting for command completion.\n",
+                      IO_TYPE(hw), hw->iobase);
                err = -ETIMEDOUT;
                goto out;
        }
 
-       resp->status = hermes_read_regn(hw, STATUS);
-       resp->resp0 = hermes_read_regn(hw, RESP0);
-       resp->resp1 = hermes_read_regn(hw, RESP1);
-       resp->resp2 = hermes_read_regn(hw, RESP2);
+       status = hermes_read_regn(hw, STATUS);
+       if (resp) {
+               resp->status = status;
+               resp->resp0 = hermes_read_regn(hw, RESP0);
+               resp->resp1 = hermes_read_regn(hw, RESP1);
+               resp->resp2 = hermes_read_regn(hw, RESP2);
+       }
 
        hermes_write_regn(hw, EVACK, HERMES_EV_CMD);
 
-       err = resp->status & HERMES_STATUS_RESULT;
+       if (status & HERMES_STATUS_RESULT)
+               err = -EIO;
 
  out:
        return err;
@@ -266,17 +295,17 @@ int hermes_docmd_wait(hermes_t *hw, u16 cmd, u16 parm0, hermes_response_t *resp)
 int hermes_allocate(hermes_t *hw, u16 size, u16 *fid)
 {
        int err = 0;
-       hermes_response_t resp;
        int k;
        u16 reg;
        
        if ( (size < HERMES_ALLOC_LEN_MIN) || (size > HERMES_ALLOC_LEN_MAX) )
                return -EINVAL;
 
-       err = hermes_docmd_wait(hw, HERMES_CMD_ALLOC, size, &resp);
+       err = hermes_docmd_wait(hw, HERMES_CMD_ALLOC, size, NULL);
        if (err) {
-               printk(KERN_WARNING "hermes @ 0x%x: Frame allocation command failed (0x%X).\n",
-                      hw->iobase, err);
+               printk(KERN_WARNING "hermes @ %s0x%lx: "
+                      "Frame allocation command failed (0x%X).\n",
+                      IO_TYPE(hw), hw->iobase, err);
                return err;
        }
 
@@ -289,14 +318,16 @@ int hermes_allocate(hermes_t *hw, u16 size, u16 *fid)
        }
        
        if (! hermes_present(hw)) {
-               printk(KERN_WARNING "hermes @ 0x%x: Card removed waiting for frame allocation.\n",
-                      hw->iobase);
+               printk(KERN_WARNING "hermes @ %s0x%lx: "
+                      "Card removed waiting for frame allocation.\n",
+                      IO_TYPE(hw), hw->iobase);
                return -ENODEV;
        }
                
        if (! (reg & HERMES_EV_ALLOC)) {
-               printk(KERN_ERR "hermes @ 0x%x: Timeout waiting for frame allocation\n",
-                      hw->iobase);
+               printk(KERN_ERR "hermes @ %s0x%lx: "
+                      "Timeout waiting for frame allocation\n",
+                      IO_TYPE(hw), hw->iobase);
                return -ETIMEDOUT;
        }
 
@@ -306,13 +337,14 @@ int hermes_allocate(hermes_t *hw, u16 size, u16 *fid)
        return 0;
 }
 
+
 /* Set up a BAP to read a particular chunk of data from card's internal buffer.
  *
  * Returns: < 0 on internal failure (errno), 0 on success, >0 on error
  * from firmware
  *
  * Callable from any context */
-int hermes_bap_seek(hermes_t *hw, int bap, u16 id, u16 offset)
+static int hermes_bap_seek(hermes_t *hw, int bap, u16 id, u16 offset)
 {
        int sreg = bap ? HERMES_SELECT1 : HERMES_SELECT0;
        int oreg = bap ? HERMES_OFFSET1 : HERMES_OFFSET0;
@@ -323,14 +355,27 @@ int hermes_bap_seek(hermes_t *hw, int bap, u16 id, u16 offset)
        if ( (offset > HERMES_BAP_OFFSET_MAX) || (offset % 2) )
                return -EINVAL;
 
-       k = BAP_BUSY_TIMEOUT;
+       k = HERMES_BAP_BUSY_TIMEOUT;
        reg = hermes_read_reg(hw, oreg);
-       while ((reg & HERMES_OFFSET_BUSY) & k) {
+       while ((reg & HERMES_OFFSET_BUSY) && k) {
                k--;
                udelay(1);
                reg = hermes_read_reg(hw, oreg);
        }
 
+#ifdef HERMES_DEBUG_BUFFER
+       hw->profile[HERMES_BAP_BUSY_TIMEOUT - k]++;
+
+       if (k < HERMES_BAP_BUSY_TIMEOUT) {
+               struct hermes_debug_entry *e = 
+                       &hw->dbuf[(hw->dbufp++) % HERMES_DEBUG_BUFSIZE];
+               e->bap = bap;
+               e->id = id;
+               e->offset = offset;
+               e->cycles = HERMES_BAP_BUSY_TIMEOUT - k;
+       }
+#endif
+
        if (reg & HERMES_OFFSET_BUSY)
                return -ETIMEDOUT;
 
@@ -339,7 +384,7 @@ int hermes_bap_seek(hermes_t *hw, int bap, u16 id, u16 offset)
        hermes_write_reg(hw, oreg, offset);
 
        /* Wait for the BAP to be ready */
-       k = BAP_BUSY_TIMEOUT;
+       k = HERMES_BAP_BUSY_TIMEOUT;
        reg = hermes_read_reg(hw, oreg);
        while ( (reg & (HERMES_OFFSET_BUSY | HERMES_OFFSET_ERR)) && k) {
                k--;
@@ -373,7 +418,7 @@ int hermes_bap_pread(hermes_t *hw, int bap, void *buf, int len,
        int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
        int err = 0;
 
-       if (len % 2)
+       if ( (len < 0) || (len % 2) )
                return -EINVAL;
 
        err = hermes_bap_seek(hw, bap, id, offset);
@@ -399,7 +444,7 @@ int hermes_bap_pwrite(hermes_t *hw, int bap, const void *buf, int len,
        int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
        int err = 0;
 
-       if (len % 2)
+       if ( (len < 0) || (len % 2) )
                return -EINVAL;
 
        err = hermes_bap_seek(hw, bap, id, offset);
@@ -427,12 +472,11 @@ int hermes_read_ltv(hermes_t *hw, int bap, u16 rid, int bufsize,
        int err = 0;
        int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
        u16 rlength, rtype;
-       hermes_response_t resp;
 
-       if (bufsize % 2)
+       if ( (bufsize < 0) || (bufsize % 2) )
                return -EINVAL;
 
-       err = hermes_docmd_wait(hw, HERMES_CMD_ACCESS, rid, &resp);
+       err = hermes_docmd_wait(hw, HERMES_CMD_ACCESS, rid, NULL);
        if (err)
                goto out;
 
@@ -447,11 +491,14 @@ int hermes_read_ltv(hermes_t *hw, int bap, u16 rid, int bufsize,
                *length = rlength;
 
        if (rtype != rid)
-               printk(KERN_WARNING "hermes_read_ltv(): rid  (0x%04x) does "
-                      "not match type (0x%04x)\n", rid, rtype);
+               printk(KERN_WARNING "hermes @ %s0x%lx: "
+                      "hermes_read_ltv(): rid  (0x%04x) does not match type (0x%04x)\n",
+                      IO_TYPE(hw), hw->iobase, rid, rtype);
        if (HERMES_RECLEN_TO_BYTES(rlength) > bufsize)
-               printk(KERN_WARNING "hermes @ 0x%x: Truncating LTV record from %d to %d bytes. "
-                      "(rid=0x%04x, len=0x%04x)\n", hw->iobase,
+               printk(KERN_WARNING "hermes @ %s0x%lx: "
+                      "Truncating LTV record from %d to %d bytes. "
+                      "(rid=0x%04x, len=0x%04x)\n",
+                      IO_TYPE(hw), hw->iobase,
                       HERMES_RECLEN_TO_BYTES(rlength), bufsize, rid, rlength);
        
        /* FIXME: we should read the min of the requested length and
@@ -467,7 +514,6 @@ int hermes_write_ltv(hermes_t *hw, int bap, u16 rid,
 {
        int dreg = bap ? HERMES_DATA1 : HERMES_DATA0;
        int err = 0;
-       hermes_response_t resp;
        int count;
        
        DEBUG(3, "write_ltv(): bap=%d rid=0x%04x length=%d (value=0x%04x)\n",
@@ -485,7 +531,7 @@ int hermes_write_ltv(hermes_t *hw, int bap, u16 rid,
        hermes_write_words(hw, dreg, value, count);
 
        err = hermes_docmd_wait(hw, HERMES_CMD_ACCESS | HERMES_CMD_WRITE, 
-                               rid, &resp);
+                               rid, NULL);
 
  out:
        return err;
index 9786b0a152970dbd8b442b56f75f7a9cce006d6a..fed0f2d137e541dfec8ff0c86a6e30653bffffe6 100644 (file)
@@ -48,7 +48,6 @@
 #define                HERMES_PDA_LEN_MAX              (1024)  /* in bytes, from EK */
 #define                HERMES_SCANRESULT_MAX           (35)
 #define                HERMES_CHINFORESULT_MAX         (8)
-#define                HERMES_FRAME_LEN_MAX            (2304)
 #define                HERMES_MAX_MULTICAST            (16)
 #define                HERMES_MAGIC                    (0x7d1f)
 
 
 /*--- Regulate Commands --------------------------*/
 #define                HERMES_CMD_NOTIFY               (0x0010)
-#define                HERMES_CMD_INQ                  (0x0011)
+#define                HERMES_CMD_INQUIRE              (0x0011)
 
 /*--- Configure Commands --------------------------*/
 #define                HERMES_CMD_ACCESS               (0x0021)
 #define                HERMES_MONITOR_ENABLE           (0x000b)
 #define                HERMES_MONITOR_DISABLE          (0x000f)
 
-/*
- * Configuration RIDs
- */
-
-#define                HERMES_RID_CNF_PORTTYPE         (0xfc00)
-#define                HERMES_RID_CNF_MACADDR          (0xfc01)
-#define                HERMES_RID_CNF_DESIRED_SSID     (0xfc02)
-#define                HERMES_RID_CNF_CHANNEL          (0xfc03)
-#define                HERMES_RID_CNF_OWN_SSID         (0xfc04)
-#define                HERMES_RID_CNF_SYSTEM_SCALE     (0xfc06)
-#define                HERMES_RID_CNF_MAX_DATA_LEN     (0xfc07)
-#define                HERMES_RID_CNF_PM_ENABLE        (0xfc09)
-#define                HERMES_RID_CNF_PM_MCAST_RX      (0xfc0b)
-#define                HERMES_RID_CNF_PM_PERIOD        (0xfc0c)
-#define                HERMES_RID_CNF_PM_HOLDOVER      (0xfc0d)
-#define                HERMES_RID_CNF_NICKNAME         (0xfc0e)
-#define                HERMES_RID_CNF_WEP_ON           (0xfc20)
-#define                HERMES_RID_CNF_MWO_ROBUST       (0xfc25)
-#define                HERMES_RID_CNF_MULTICAST_LIST   (0xfc80)
-#define                HERMES_RID_CNF_CREATEIBSS       (0xfc81)
-#define                HERMES_RID_CNF_FRAG_THRESH      (0xfc82)
-#define                HERMES_RID_CNF_RTS_THRESH       (0xfc83)
-#define                HERMES_RID_CNF_TX_RATE_CTRL     (0xfc84)
-#define                HERMES_RID_CNF_PROMISCUOUS      (0xfc85)
-#define                HERMES_RID_CNF_KEYS             (0xfcb0)
-#define                HERMES_RID_CNF_TX_KEY           (0xfcb1)
-#define                HERMES_RID_CNF_TICKTIME         (0xfce0)
-
-#define                HERMES_RID_CNF_INTERSIL_WEP_ON  (0xfc28)
-#define                HERMES_RID_CNF_INTERSIL_TX_KEY  (0xfc23)
-#define                HERMES_RID_CNF_INTERSIL_KEY0    (0xfc24)
-#define                HERMES_RID_CNF_INTERSIL_KEY1    (0xfc25)
-#define                HERMES_RID_CNF_INTERSIL_KEY2    (0xfc26)
-#define                HERMES_RID_CNF_INTERSIL_KEY3    (0xfc27)
-#define                HERMES_RID_CNF_SYMBOL_MANDATORY_BSSID   (0xfc21)
-#define                HERMES_RID_CNF_SYMBOL_AUTH_TYPE         (0xfc2A)
-#define                HERMES_RID_CNF_SYMBOL_BASIC_RATES       (0xfc8A)
-#define                HERMES_RID_CNF_SYMBOL_PREAMBLE          (0xfc8C)
-
-/*
- * Information RIDs
- */
-#define                HERMES_RID_CHANNEL_LIST         (0xfd10)
-#define                HERMES_RID_STAIDENTITY          (0xfd20)
-#define                HERMES_RID_CURRENT_SSID         (0xfd41)
-#define                HERMES_RID_CURRENT_BSSID        (0xfd42)
-#define                HERMES_RID_COMMSQUALITY         (0xfd43)
-#define        HERMES_RID_CURRENT_TX_RATE      (0xfd44)
-#define        HERMES_RID_SHORT_RETRY_LIMIT    (0xfd48)
-#define        HERMES_RID_LONG_RETRY_LIMIT     (0xfd49)
-#define        HERMES_RID_MAX_TX_LIFETIME      (0xfd4A)
-#define                HERMES_RID_WEP_AVAIL            (0xfd4f)
-#define                HERMES_RID_CURRENT_CHANNEL      (0xfdc1)
-#define                HERMES_RID_DATARATES            (0xfdc6)
-#define                HERMES_RID_SYMBOL_SECONDARY_VER (0xfd24)
-#define                HERMES_RID_SYMBOL_KEY_LENGTH    (0xfc2B)
-
 /*
  * Frame structures and constants
  */
 
-typedef struct hermes_frame_desc {
-       /* Hermes - i.e. little-endian byte-order */
+#define HERMES_DESCRIPTOR_OFFSET       0
+#define HERMES_802_11_OFFSET           (14)
+#define HERMES_802_3_OFFSET            (14+32)
+#define HERMES_802_2_OFFSET            (14+32+14)
+
+struct hermes_rx_descriptor {
+       u16 status;
+       u32 time;
+       u8 silence;
+       u8 signal;
+       u8 rate;
+       u8 rxflow;
+       u32 reserved;
+} __attribute__ ((packed));
+
+#define HERMES_RXSTAT_ERR              (0x0003)
+#define        HERMES_RXSTAT_BADCRC            (0x0001)
+#define        HERMES_RXSTAT_UNDECRYPTABLE     (0x0002)
+#define        HERMES_RXSTAT_MACPORT           (0x0700)
+#define        HERMES_RXSTAT_MSGTYPE           (0xE000)
+#define        HERMES_RXSTAT_1042              (0x2000)        /* RFC-1042 frame */
+#define        HERMES_RXSTAT_TUNNEL            (0x4000)        /* bridge-tunnel encoded frame */
+#define        HERMES_RXSTAT_WMP               (0x6000)        /* Wavelan-II Management Protocol frame */
+
+struct hermes_tx_descriptor {
        u16 status;
-       u16 res1, res2;
-       u16 q_info;
-       u16 res3, res4;
-       u16 tx_ctl;
-} __attribute__ ((packed)) hermes_frame_desc_t;
-
-#define                HERMES_RXSTAT_ERR               (0x0003)
-#define                HERMES_RXSTAT_MACPORT           (0x0700)
-#define                HERMES_RXSTAT_MSGTYPE           (0xE000)
-
-#define                HERMES_RXSTAT_BADCRC            (0x0001)
-#define                HERMES_RXSTAT_UNDECRYPTABLE     (0x0002)
-
-/* RFC-1042 encoded frame */
-#define                HERMES_RXSTAT_1042              (0x2000)
-/* Bridge-tunnel encoded frame */
-#define                HERMES_RXSTAT_TUNNEL            (0x4000)
-/* Wavelan-II Management Protocol frame */
-#define                HERMES_RXSTAT_WMP               (0x6000)
+       u16 reserved1;
+       u16 reserved2;
+       u32 sw_support;
+       u8 retry_count;
+       u8 tx_rate;
+       u16 tx_control; 
+} __attribute__ ((packed));
+
+#define HERMES_TXSTAT_RETRYERR         (0x0001)
+#define HERMES_TXSTAT_AGEDERR          (0x0002)
+#define HERMES_TXSTAT_DISCON           (0x0004)
+#define HERMES_TXSTAT_FORMERR          (0x0008)
+
+#define HERMES_TXCTRL_TX_OK            (0x0002)        /* ?? interrupt on Tx complete */
+#define HERMES_TXCTRL_TX_EX            (0x0004)        /* ?? interrupt on Tx exception */
+#define HERMES_TXCTRL_802_11           (0x0008)        /* We supply 802.11 header */
+#define HERMES_TXCTRL_ALT_RTRY         (0x0020)
+
+/* Inquiry constants and data types */
+
+#define HERMES_INQ_TALLIES             (0xF100)
+#define HERMES_INQ_SCAN                        (0xF101)
+#define HERMES_INQ_LINKSTATUS          (0xF200)
+
+struct hermes_tallies_frame {
+       u16 TxUnicastFrames;
+       u16 TxMulticastFrames;
+       u16 TxFragments;
+       u16 TxUnicastOctets;
+       u16 TxMulticastOctets;
+       u16 TxDeferredTransmissions;
+       u16 TxSingleRetryFrames;
+       u16 TxMultipleRetryFrames;
+       u16 TxRetryLimitExceeded;
+       u16 TxDiscards;
+       u16 RxUnicastFrames;
+       u16 RxMulticastFrames;
+       u16 RxFragments;
+       u16 RxUnicastOctets;
+       u16 RxMulticastOctets;
+       u16 RxFCSErrors;
+       u16 RxDiscards_NoBuffer;
+       u16 TxDiscardsWrongSA;
+       u16 RxWEPUndecryptable;
+       u16 RxMsgInMsgFragments;
+       u16 RxMsgInBadMsgFragments;
+       /* Those last are probably not available in very old firmwares */
+       u16 RxDiscards_WEPICVError;
+       u16 RxDiscards_WEPExcluded;
+} __attribute__ ((packed));
+
+/* Grabbed from wlan-ng - Thanks Mark... - Jean II
+ * This is the result of a scan inquiry command */
+/* Structure describing info about an Access Point */
+struct hermes_scan_apinfo {
+       u16 channel;            /* Channel where the AP sits */
+       u16 noise;              /* Noise level */
+       u16 level;              /* Signal level */
+       u8 bssid[ETH_ALEN];     /* MAC address of the Access Point */
+       u16 beacon_interv;      /* Beacon interval ? */
+       u16 capabilities;       /* Capabilities ? */
+       u8 essid[32];           /* ESSID of the network */
+       u8 rates[10];           /* Bit rate supported */
+       u16 proberesp_rate;     /* ???? */
+} __attribute__ ((packed));
+/* Container */
+struct hermes_scan_frame {
+       u16 rsvd;                   /* ??? */
+       u16 scanreason;             /* ??? */
+       struct hermes_scan_apinfo aps[35];        /* Scan result */
+} __attribute__ ((packed));
+
+// #define HERMES_DEBUG_BUFFER 1
+#define HERMES_DEBUG_BUFSIZE 4096
+struct hermes_debug_entry {
+       int bap;
+       u16 id, offset;
+       int cycles;
+};
 
 #ifdef __KERNEL__
 
+/* Timeouts */
+#define HERMES_BAP_BUSY_TIMEOUT (500) /* In iterations of ~1us */
+
 /* Basic control structure */
 typedef struct hermes {
-       uint iobase;
+       ulong iobase;
+       int io_space; /* 1 if we IO-mapped IO, 0 for memory-mapped IO? */
+#define HERMES_IO      1
+#define HERMES_MEM     0
+       int reg_spacing;
+#define HERMES_16BIT_REGSPACING        0
+#define HERMES_32BIT_REGSPACING        1
 
        u16 inten; /* Which interrupts should be enabled? */
+
+#ifdef HERMES_DEBUG_BUFFER
+       struct hermes_debug_entry dbuf[HERMES_DEBUG_BUFSIZE];
+       unsigned long dbufp;
+       unsigned long profile[HERMES_BAP_BUSY_TIMEOUT+1];
+#endif
 } hermes_t;
 
 typedef struct hermes_response {
        u16 status, resp0, resp1, resp2;
 } hermes_response_t;
 
-/* "ID" structure - used for ESSID and station nickname */
-typedef struct hermes_id {
-       u16 len;
-       u16 val[16];
-} __attribute__ ((packed)) hermes_id_t;
-
-typedef struct hermes_multicast {
-       u8 addr[HERMES_MAX_MULTICAST][ETH_ALEN];
-} __attribute__ ((packed)) hermes_multicast_t;
-
 /* Register access convenience macros */
-#define hermes_read_reg(hw, off) (inw((hw)->iobase + (off)))
-#define hermes_write_reg(hw, off, val) (outw_p((val), (hw)->iobase + (off)))
+#define hermes_read_reg(hw, off) ((hw)->io_space ? \
+       inw((hw)->iobase + ( (off) << (hw)->reg_spacing )) : \
+       readw((hw)->iobase + ( (off) << (hw)->reg_spacing )))
+#define hermes_write_reg(hw, off, val) ((hw)->io_space ? \
+       outw_p((val), (hw)->iobase + ( (off) << (hw)->reg_spacing )) : \
+       writew((val), (hw)->iobase + ( (off) << (hw)->reg_spacing )))
 
 #define hermes_read_regn(hw, name) (hermes_read_reg((hw), HERMES_##name))
 #define hermes_write_regn(hw, name, val) (hermes_write_reg((hw), HERMES_##name, (val)))
 
 /* Function prototypes */
-void hermes_struct_init(hermes_t *hw, uint io);
+void hermes_struct_init(hermes_t *hw, ulong address, int io_space, int reg_spacing);
 int hermes_reset(hermes_t *hw);
 int hermes_docmd_wait(hermes_t *hw, u16 cmd, u16 parm0, hermes_response_t *resp);
 int hermes_allocate(hermes_t *hw, u16 size, u16 *fid);
 
-int hermes_bap_seek(hermes_t *hw, int bap, u16 id, u16 offset);
 int hermes_bap_pread(hermes_t *hw, int bap, void *buf, int len,
                       u16 id, u16 offset);
 int hermes_bap_pwrite(hermes_t *hw, int bap, const void *buf, int len,
@@ -300,26 +333,62 @@ static inline void hermes_set_irqmask(hermes_t *hw, u16 events)
 
 static inline int hermes_enable_port(hermes_t *hw, int port)
 {
-       hermes_response_t resp;
-
        return hermes_docmd_wait(hw, HERMES_CMD_ENABLE | (port << 8),
-                                0, &resp);
+                                0, NULL);
 }
 
 static inline int hermes_disable_port(hermes_t *hw, int port)
 {
-       hermes_response_t resp;
+       return hermes_docmd_wait(hw, HERMES_CMD_DISABLE | (port << 8), 
+                                0, NULL);
+}
 
-       return hermes_docmd_wait(hw, HERMES_CMD_ENABLE | (port << 8), 
-                                0, &resp);
+/* Initiate an INQUIRE command (tallies or scan).  The result will come as an
+ * information frame in __orinoco_ev_info() */
+static inline int hermes_inquire(hermes_t *hw, u16 rid)
+{
+       return hermes_docmd_wait(hw, HERMES_CMD_INQUIRE, rid, NULL);
 }
 
 #define HERMES_BYTES_TO_RECLEN(n) ( ((n) % 2) ? (((n)+1)/2)+1 : ((n)/2)+1 )
 #define HERMES_RECLEN_TO_BYTES(n) ( ((n)-1) * 2 )
 
 /* Note that for the next two, the count is in 16-bit words, not bytes */
-#define hermes_read_words(hw, off, buf, count) (insw((hw)->iobase + (off), (buf), (count)))
-#define hermes_write_words(hw, off, buf, count) (outsw((hw)->iobase + (off), (buf), (count)))
+static inline void hermes_read_words(struct hermes *hw, int off, void *buf, int count)
+{
+       off = off << hw->reg_spacing;;
+
+       if (hw->io_space) {
+               insw(hw->iobase + off, buf, count);
+       } else {
+               int i;
+               u16 *p;
+
+               /* This need to *not* byteswap (like insw()) but
+                * readw() does byteswap hence the conversion */
+               for (i = 0, p = buf; i < count; i++) {
+                       *p++ = cpu_to_le16(readw(hw->iobase + off));
+               }
+       }
+}
+
+static inline void hermes_write_words(struct hermes *hw, int off, const void *buf, int count)
+{
+       off = off << hw->reg_spacing;;
+
+       if (hw->io_space) {
+               outsw(hw->iobase + off, buf, count);
+       } else {
+               int i;
+               const u16 *p;
+
+               /* This need to *not* byteswap (like outsw()) but
+                * writew() does byteswap hence the conversion */
+               for (i = 0, p = buf; i < count; i++) {
+                       writew(le16_to_cpu(*p++), hw->iobase + off);
+               }
+       }
+}
 
 #define HERMES_READ_RECORD(hw, bap, rid, buf) \
        (hermes_read_ltv((hw),(bap),(rid), sizeof(*buf), NULL, (buf)))
diff --git a/drivers/net/wireless/hermes_rid.h b/drivers/net/wireless/hermes_rid.h
new file mode 100644 (file)
index 0000000..761c542
--- /dev/null
@@ -0,0 +1,153 @@
+#ifndef _HERMES_RID_H
+#define _HERMES_RID_H
+
+/*
+ * Configuration RIDs
+ */
+#define HERMES_RID_CNFPORTTYPE                 0xFC00  /* used */
+#define HERMES_RID_CNFOWNMACADDR               0xFC01  /* used */
+#define HERMES_RID_CNFDESIREDSSID              0xFC02  /* used */
+#define HERMES_RID_CNFOWNCHANNEL               0xFC03  /* used */
+#define HERMES_RID_CNFOWNSSID                  0xFC04  /* used */
+#define HERMES_RID_CNFOWNATIMWINDOW            0xFC05
+#define HERMES_RID_CNFSYSTEMSCALE              0xFC06  /* used */
+#define HERMES_RID_CNFMAXDATALEN               0xFC07
+#define HERMES_RID_CNFWDSADDRESS               0xFC08
+#define HERMES_RID_CNFPMENABLED                        0xFC09  /* used */
+#define HERMES_RID_CNFPMEPS                    0xFC0A
+#define HERMES_RID_CNFMULTICASTRECEIVE         0xFC0B  /* used */
+#define HERMES_RID_CNFMAXSLEEPDURATION         0xFC0C  /* used */
+#define HERMES_RID_CNFPMHOLDOVERDURATION       0xFC0D  /* used */
+#define HERMES_RID_CNFOWNNAME                  0xFC0E  /* used */
+#define HERMES_RID_CNFOWNDTIMPERIOD            0xFC10
+#define HERMES_RID_CNFWDSADDRESS1              0xFC11
+#define HERMES_RID_CNFWDSADDRESS2              0xFC12
+#define HERMES_RID_CNFWDSADDRESS3              0xFC13
+#define HERMES_RID_CNFWDSADDRESS4              0xFC14
+#define HERMES_RID_CNFWDSADDRESS5              0xFC15
+#define HERMES_RID_CNFWDSADDRESS6              0xFC16
+#define HERMES_RID_CNFMULTICASTPMBUFFERING     0xFC17
+#define HERMES_RID_CNFWEPENABLED_AGERE         0xFC20  /* used */
+#define HERMES_RID_CNFMANDATORYBSSID_SYMBOL    0xFC21
+#define HERMES_RID_CNFWEPDEFAULTKEYID          0xFC23  /* used */
+#define HERMES_RID_CNFDEFAULTKEY0              0xFC24  /* used */
+#define HERMES_RID_CNFDEFAULTKEY1              0xFC25  /* used */
+#define HERMES_RID_CNFMWOROBUST_AGERE          0xFC25  /* used */
+#define HERMES_RID_CNFDEFAULTKEY2              0xFC26  /* used */
+#define HERMES_RID_CNFDEFAULTKEY3              0xFC27  /* used */
+#define HERMES_RID_CNFWEPFLAGS_INTERSIL                0xFC28  /* used */
+#define HERMES_RID_CNFWEPKEYMAPPINGTABLE       0xFC29
+#define HERMES_RID_CNFAUTHENTICATION           0xFC2A  /* used */
+#define HERMES_RID_CNFMAXASSOCSTA              0xFC2B
+#define        HERMES_RID_CNFKEYLENGTH_SYMBOL          0xFC2B
+#define HERMES_RID_CNFTXCONTROL                        0xFC2C
+#define HERMES_RID_CNFROAMINGMODE              0xFC2D
+#define HERMES_RID_CNFHOSTAUTHENTICATION       0xFC2E
+#define HERMES_RID_CNFRCVCRCERROR              0xFC30
+#define HERMES_RID_CNFMMLIFE                   0xFC31
+#define HERMES_RID_CNFALTRETRYCOUNT            0xFC32
+#define HERMES_RID_CNFBEACONINT                        0xFC33
+#define HERMES_RID_CNFAPPCFINFO                        0xFC34
+#define HERMES_RID_CNFSTAPCFINFO               0xFC35
+#define HERMES_RID_CNFPRIORITYQUSAGE           0xFC37
+#define HERMES_RID_CNFTIMCTRL                  0xFC40
+#define HERMES_RID_CNFTHIRTY2TALLY             0xFC42
+#define HERMES_RID_CNFENHSECURITY              0xFC43
+#define HERMES_RID_CNFGROUPADDRESSES           0xFC80  /* used */
+#define HERMES_RID_CNFCREATEIBSS               0xFC81  /* used */
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD   0xFC82  /* used */
+#define HERMES_RID_CNFRTSTHRESHOLD             0xFC83  /* used */
+#define HERMES_RID_CNFTXRATECONTROL            0xFC84  /* used */
+#define HERMES_RID_CNFPROMISCUOUSMODE          0xFC85  /* used */
+#define HERMES_RID_CNFBASICRATES_SYMBOL                0xFC8A
+#define HERMES_RID_CNFPREAMBLE_SYMBOL          0xFC8C  /* used */
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD0  0xFC90
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD1  0xFC91
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD2  0xFC92
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD3  0xFC93
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD4  0xFC94
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD5  0xFC95
+#define HERMES_RID_CNFFRAGMENTATIONTHRESHOLD6  0xFC96
+#define HERMES_RID_CNFRTSTHRESHOLD0            0xFC97
+#define HERMES_RID_CNFRTSTHRESHOLD1            0xFC98
+#define HERMES_RID_CNFRTSTHRESHOLD2            0xFC99
+#define HERMES_RID_CNFRTSTHRESHOLD3            0xFC9A
+#define HERMES_RID_CNFRTSTHRESHOLD4            0xFC9B
+#define HERMES_RID_CNFRTSTHRESHOLD5            0xFC9C
+#define HERMES_RID_CNFRTSTHRESHOLD6            0xFC9D
+#define HERMES_RID_CNFSHORTPREAMBLE            0xFCB0
+#define HERMES_RID_CNFWEPKEYS_AGERE            0xFCB0  /* used */
+#define HERMES_RID_CNFEXCLUDELONGPREAMBLE      0xFCB1
+#define HERMES_RID_CNFTXKEY_AGERE              0xFCB1  /* used */
+#define HERMES_RID_CNFAUTHENTICATIONRSPTO      0xFCB2
+#define HERMES_RID_CNFBASICRATES               0xFCB3
+#define HERMES_RID_CNFSUPPORTEDRATES           0xFCB4
+#define HERMES_RID_CNFTICKTIME                 0xFCE0  /* used */
+#define HERMES_RID_CNFSCANREQUEST              0xFCE1
+#define HERMES_RID_CNFJOINREQUEST              0xFCE2
+#define HERMES_RID_CNFAUTHENTICATESTATION      0xFCE3
+#define HERMES_RID_CNFCHANNELINFOREQUEST       0xFCE4
+
+/*
+ * Information RIDs
+ */
+#define HERMES_RID_MAXLOADTIME                 0xFD00
+#define HERMES_RID_DOWNLOADBUFFER              0xFD01
+#define HERMES_RID_PRIID                       0xFD02
+#define HERMES_RID_PRISUPRANGE                 0xFD03
+#define HERMES_RID_CFIACTRANGES                        0xFD04
+#define HERMES_RID_NICSERNUM                   0xFD0A
+#define HERMES_RID_NICID                       0xFD0B
+#define HERMES_RID_MFISUPRANGE                 0xFD0C
+#define HERMES_RID_CFISUPRANGE                 0xFD0D
+#define HERMES_RID_CHANNELLIST                 0xFD10  /* used */
+#define HERMES_RID_REGULATORYDOMAINS           0xFD11
+#define HERMES_RID_TEMPTYPE                    0xFD12
+#define HERMES_RID_CIS                         0xFD13
+#define HERMES_RID_STAID                       0xFD20  /* used */
+#define HERMES_RID_STASUPRANGE                 0xFD21
+#define HERMES_RID_MFIACTRANGES                        0xFD22
+#define HERMES_RID_CFIACTRANGES2               0xFD23
+#define HERMES_RID_SECONDARYVERSION_SYMBOL     0xFD24  /* used */
+#define HERMES_RID_PORTSTATUS                  0xFD40
+#define HERMES_RID_CURRENTSSID                 0xFD41  /* used */
+#define HERMES_RID_CURRENTBSSID                        0xFD42  /* used */
+#define HERMES_RID_COMMSQUALITY                        0xFD43  /* used */
+#define HERMES_RID_CURRENTTXRATE               0xFD44  /* used */
+#define HERMES_RID_CURRENTBEACONINTERVAL       0xFD45
+#define HERMES_RID_CURRENTSCALETHRESHOLDS      0xFD46
+#define HERMES_RID_PROTOCOLRSPTIME             0xFD47
+#define HERMES_RID_SHORTRETRYLIMIT             0xFD48  /* used */
+#define HERMES_RID_LONGRETRYLIMIT              0xFD49  /* used */
+#define HERMES_RID_MAXTRANSMITLIFETIME         0xFD4A  /* used */
+#define HERMES_RID_MAXRECEIVELIFETIME          0xFD4B
+#define HERMES_RID_CFPOLLABLE                  0xFD4C
+#define HERMES_RID_AUTHENTICATIONALGORITHMS    0xFD4D
+#define HERMES_RID_PRIVACYOPTIONIMPLEMENTED    0xFD4F
+#define HERMES_RID_CURRENTTXRATE1              0xFD80
+#define HERMES_RID_CURRENTTXRATE2              0xFD81
+#define HERMES_RID_CURRENTTXRATE3              0xFD82
+#define HERMES_RID_CURRENTTXRATE4              0xFD83
+#define HERMES_RID_CURRENTTXRATE5              0xFD84
+#define HERMES_RID_CURRENTTXRATE6              0xFD85
+#define HERMES_RID_OWNMACADDR                  0xFD86
+#define HERMES_RID_SCANRESULTSTABLE            0xFD88
+#define HERMES_RID_PHYTYPE                     0xFDC0
+#define HERMES_RID_CURRENTCHANNEL              0xFDC1  /* used */
+#define HERMES_RID_CURRENTPOWERSTATE           0xFDC2
+#define HERMES_RID_CCAMODE                     0xFDC3
+#define HERMES_RID_SUPPORTEDDATARATES          0xFDC6  /* used */
+#define HERMES_RID_BUILDSEQ                    0xFFFE
+#define HERMES_RID_FWID                                0xFFFF
+
+/* "ID" structure - used for ESSID and station nickname */
+struct hermes_idstring {
+       u16 len;
+       u16 val[16];
+} __attribute__ ((packed));
+
+typedef struct hermes_multicast {
+       u8 addr[HERMES_MAX_MULTICAST][ETH_ALEN];
+} __attribute__ ((packed)) hermes_multicast_t;
+
+#endif
diff --git a/drivers/net/wireless/ieee802_11.h b/drivers/net/wireless/ieee802_11.h
new file mode 100644 (file)
index 0000000..e399f13
--- /dev/null
@@ -0,0 +1,73 @@
+#ifndef _IEEE802_11_H
+#define _IEEE802_11_H
+
+#define IEEE802_11_DATA_LEN            2304
+/* Actually, the standard seems to be inconsistent about what the
+   maximum frame size really is.  S6.2.1.1.2 says 2304 octets, but the
+   figure in section 7.1.2 says 2312 octects. */
+#define IEEE802_11_HLEN                        30
+#define IEEE802_11_FRAME_LEN           (IEEE802_11_DATA_LEN + IEEE802_11_HLEN)
+
+struct ieee802_11_hdr {
+       u16 frame_ctl;
+       u16 duration_id;
+       u8 addr1[ETH_ALEN];
+       u8 addr2[ETH_ALEN];
+       u8 addr3[ETH_ALEN];
+       u16 seq_ctl;
+       u8 addr4[ETH_ALEN];
+} __attribute__ ((packed));
+
+/* Frame control field constants */
+#define IEEE802_11_FCTL_VERS           0x0002
+#define IEEE802_11_FCTL_FTYPE          0x000c
+#define IEEE802_11_FCTL_STYPE          0x00f0
+#define IEEE802_11_FCTL_TODS           0x0100
+#define IEEE802_11_FCTL_FROMDS         0x0200
+#define IEEE802_11_FCTL_MOREFRAGS      0x0400
+#define IEEE802_11_FCTL_RETRY          0x0800
+#define IEEE802_11_FCTL_PM             0x1000
+#define IEEE802_11_FCTL_MOREDATA       0x2000
+#define IEEE802_11_FCTL_WEP            0x4000
+#define IEEE802_11_FCTL_ORDER          0x8000
+
+#define IEEE802_11_FTYPE_MGMT          0x0000
+#define IEEE802_11_FTYPE_CTL           0x0004
+#define IEEE802_11_FTYPE_DATA          0x0008
+
+/* management */
+#define IEEE802_11_STYPE_ASSOC_REQ     0x0000
+#define IEEE802_11_STYPE_ASSOC_RESP    0x0010
+#define IEEE802_11_STYPE_REASSOC_REQ   0x0020
+#define IEEE802_11_STYPE_REASSOC_RESP  0x0030
+#define IEEE802_11_STYPE_PROBE_REQ     0x0040
+#define IEEE802_11_STYPE_PROBE_RESP    0x0050
+#define IEEE802_11_STYPE_BEACON                0x0080
+#define IEEE802_11_STYPE_ATIM          0x0090
+#define IEEE802_11_STYPE_DISASSOC      0x00A0
+#define IEEE802_11_STYPE_AUTH          0x00B0
+#define IEEE802_11_STYPE_DEAUTH                0x00C0
+
+/* control */
+#define IEEE802_11_STYPE_PSPOLL                0x00A0
+#define IEEE802_11_STYPE_RTS           0x00B0
+#define IEEE802_11_STYPE_CTS           0x00C0
+#define IEEE802_11_STYPE_ACK           0x00D0
+#define IEEE802_11_STYPE_CFEND         0x00E0
+#define IEEE802_11_STYPE_CFENDACK      0x00F0
+
+/* data */
+#define IEEE802_11_STYPE_DATA          0x0000
+#define IEEE802_11_STYPE_DATA_CFACK    0x0010
+#define IEEE802_11_STYPE_DATA_CFPOLL   0x0020
+#define IEEE802_11_STYPE_DATA_CFACKPOLL        0x0030
+#define IEEE802_11_STYPE_NULLFUNC      0x0040
+#define IEEE802_11_STYPE_CFACK         0x0050
+#define IEEE802_11_STYPE_CFPOLL                0x0060
+#define IEEE802_11_STYPE_CFACKPOLL     0x0070
+
+#define IEEE802_11_SCTL_FRAG           0x000F
+#define IEEE802_11_SCTL_SEQ            0xFFF0
+
+#endif /* _IEEE802_11_H */
+
index 36c151148d41cd515224319fd2d70cfb0d7a951f..7f029196a28e92b6c292d04ffe9d6d4c862dc2b1 100644 (file)
@@ -1,11 +1,7 @@
-/* orinoco.c 0.08a     - (formerly known as dldwd_cs.c and orinoco_cs.c)
+/* orinoco.c 0.11a     - (formerly known as dldwd_cs.c and orinoco_cs.c)
  *
- * A driver for "Hermes" chipset based PCMCIA wireless adaptors, such
- * as the Lucent WavelanIEEE/Orinoco cards and their OEM (Cabletron/
- * EnteraSys RoamAbout 802.11, ELSA Airlancer, Melco Buffalo and others).
- * It should also be usable on various Prism II based cards such as the
- * Linksys, D-Link and Farallon Skyline. It should also work on Symbol
- * cards such as the 3Com AirConnect and Ericsson WLAN.
+ * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
+ * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
  *
  * Copyright (C) 2000 David Gibson, Linuxcare Australia <hermes@gibson.dropbear.id.au>
  *     With some help from :
  * deleting the provisions above and replace them with the notice and
  * other provisions required by the GPL.  If you do not delete the
  * provisions above, a recipient may use your version of this file
- * under either the MPL or the GPL.
- */
+ * under either the MPL or the GPL.  */
 
 /*
- * Tentative changelog...
- *
  * v0.01 -> v0.02 - 21/3/2001 - Jean II
  *     o Allow to use regular ethX device name instead of dldwdX
  *     o Warning on IBSS with ESSID=any for firmware 6.06
  *     o Fixed bad bug in WEP key handling on Intersil and Symbol firmware,
  *       which led to an instant crash on big-endian machines.
  *
- * TODO - Jean II
- *     o inline functions (lots of candidate, need to reorder code)
- *     o Test PrismII/Symbol cards & firmware versions
- *     o Mini-PCI support (some people have reported success - JII)
- *     o Find and kill remaining Tx timeout problems
- */
+ * v0.08a -> v0.08b - 20/11/2001 - David Gibson
+ *     o Lots of cleanup and bugfixes in orinoco_plx.c
+ *     o Cleanup to handling of Tx rate setting.
+ *     o Removed support for old encapsulation method.
+ *     o Removed old "dldwd" names.
+ *     o Split RID constants into a new file hermes_rid.h
+ *     o Renamed RID constants to match linux-wlan-ng and prism2.o
+ *     o Bugfixes in hermes.c
+ *     o Poke the PLX's INTCSR register, so it actually starts
+ *       generating interrupts.  These cards might actually work now.
+ *     o Update to wireless extensions v12 (Jean II)
+ *     o Support for tallies and inquire command (Jean II)
+ *     o Airport updates for newer PPC kernels (BenH)
+ *
+ * v0.08b -> v0.09 - 21/12/2001 - David Gibson
+ *     o Some new PCI IDs for PLX cards.
+ *     o Removed broken attempt to do ALLMULTI reception.  Just use
+ *       promiscuous mode instead
+ *     o Preliminary work for list-AP (Jean II)
+ *     o Airport updates from (BenH)
+ *     o Eliminated racy hw_ready stuff
+ *     o Fixed generation of fake events in irq handler.  This should
+ *       finally kill the EIO problems (Jean II & dgibson)
+ *     o Fixed breakage of bitrate set/get on Agere firmware (Jean II)
+ *
+ * v0.09 -> v0.09a - 2/1/2002 - David Gibson
+ *     o Fixed stupid mistake in multicast list handling, triggering
+ *       a BUG()
+ *
+ * v0.09a -> v0.09b - 16/1/2002 - David Gibson
+ *     o Fixed even stupider mistake in new interrupt handling, which
+ *       seriously broke things on big-endian machines.
+ *     o Removed a bunch of redundant includes and exports.
+ *     o Removed a redundant MOD_{INC,DEC}_USE_COUNT pair in airport.c
+ *     o Don't attempt to do hardware level multicast reception on
+ *       Intersil firmware, just go promisc instead.
+ *     o Typo fixed in hermes_issue_cmd()
+ *     o Eliminated WIRELESS_SPY #ifdefs
+ *     o Status code reported on Tx exceptions
+ *     o Moved netif_wake_queue() from ALLOC interrupts to TX and TXEXC
+ *       interrupts, which should fix the timeouts we're seeing.
+ *
+ * v0.09b -> v0.10 - 25 Feb 2002 - David Gibson
+ *     o Removed nested structures used for header parsing, so the
+ *       driver should now work without hackery on ARM
+ *     o Fix for WEP handling on Intersil (Hawk Newton)
+ *     o Eliminated the /proc/hermes/ethXX/regs debugging file.  It
+ *       was never very useful.
+ *     o Make Rx errors less noisy.
+ *
+ * v0.10 -> v0.11 - 5 Apr Mar 2002 - David Gibson
+ *     o Laid the groundwork in hermes.[ch] for devices which map
+ *       into PCI memory space rather than IO space.
+ *     o Fixed bug in multicast handling (cleared multicast list when
+ *       leaving promiscuous mode).
+ *     o Relegated Tx error messages to debug.
+ *     o Cleaned up / corrected handling of allocation lengths.
+ *     o Set OWNSSID in IBSS mode for WinXP interoperability (jimc).
+ *     o Change to using alloc_etherdev() for structure allocations. 
+ *     o Check for and drop undersized packets.
+ *     o Fixed a race in stopping/waking the queue.  This should fix
+ *       the timeout problems (Pavel Roskin)
+ *     o Reverted to netif_wake_queue() on the ALLOC event.
+ *     o Fixes for recent Symbol firmwares which lack AP density
+ *       (Pavel Roskin).
+ *
+ * v0.11 -> v0.11a - 29 Apr 2002 - David Gibson
+ *     o Handle different register spacing, necessary for Prism 2.5
+ *       PCI adaptors (Steve Hill).
+ *     o Cleaned up initialization of card structures in orinoco_cs
+ *       and airport.  Removed card->priv field.
+ *     o Make response structure optional for hermes_docmd_wait()
+ *       Pavel Roskin)
+ *     o Added PCI id for Nortel emobility to orinoco_plx.c.
+ *     o Cleanup to handling of Symbol's allocation bug. (Pavel Roskin)
+ *     o Cleanups to firmware capability detection.
+ *     o Arrange for orinoco_pci.c to override firmware detection.
+ *       We should be able to support the PCI Intersil cards now.
+ *     o Cleanup handling of reset_cor and hard_reset (Pavel Roskin).
+ *     o Remove erroneous use of USER_BAP in the TxExc handler (Jouni
+ *       Malinen).
+ *     o Makefile changes for better integration into David Hinds
+ *       pcmcia-cs package.
+ *
+ * TODO
+ *     o Re-assess our encapsulation detection strategy
+ *     o Handle de-encapsulation within network layer, provide 802.11
+ *       headers
+ *     o Fix possible races in SPY handling.
+ *     o Disconnect wireless extensions from fundamental configuration.
+ *
+ *     o Convert /proc debugging stuff to seqfile
+ *     o Use multiple Tx buffers */
 /* Notes on locking:
  *
  * The basic principle of operation is that everything except the
  * interrupt handler is serialized through a single spinlock in the
- * dldwd_priv_t structure, using dldwd_lock() and
- * dldwd_unlock() (which in turn use spin_lock_bh() and spin_unlock_bh()).
+ * struct orinoco_private structure, using orinoco_lock() and
+ * orinoco_unlock() (which in turn use spin_lock_bh() and
+ * spin_unlock_bh()).
  *
  * The kernel's IRQ handling stuff ensures that the interrupt handler
  * does not re-enter itself. The interrupt handler is written such
  * that the Rx path uses one of the Hermes chipset's BAPs while
  * everything else uses the other.
  *
- * Actually, the current updating of the statistics from the interrupt
- * handler is unsafe.  However all it can do is perturb the
- * packet/byte counts slightly, so we just put up with it.  We could
- * fix this to use atomic types, but it's probably not worth it.
+ * Actually, strictly speaking, the updating of the statistics from
+ * the interrupt handler isn't safe without a lock.  However the worst
+ * that can happen is that we perturb the packet/byte counts slightly.
+ * We could fix this to use atomic types, but it's probably not worth
+ * it.
  *
  * The big exception is that that we don't want the irq handler
  * running when we actually reset or shut down the card, because
  * strange things might happen (probably the worst would be one packet
  * of garbage, but you can't be too careful). For this we use
- * __dldwd_stop_irqs() which will set a flag to disable the interrupt
+ * __orinoco_stop_irqs() which will set a flag to disable the interrupt
  * handler, and wait for any outstanding instances of the handler to
  * complete. THIS WILL LOSE INTERRUPTS! so it shouldn't be used except
  * for resets, where losing a few interrupts is acceptable. */
 #include <asm/io.h>
 #include <asm/system.h>
 #include <linux/proc_fs.h>
+#include <linux/seq_file.h>
 #include <linux/netdevice.h>
 #include <linux/if_arp.h>
 #include <linux/etherdevice.h>
 #include <linux/wireless.h>
 #include <linux/list.h>
 
-#include <pcmcia/version.h>
-#include <pcmcia/cs_types.h>
-#include <pcmcia/cs.h>
-#include <pcmcia/cistpl.h>
-#include <pcmcia/cisreg.h>
-#include <pcmcia/ds.h>
-#include <pcmcia/bus_ops.h>
-
 #include "hermes.h"
+#include "hermes_rid.h"
 #include "orinoco.h"
+#include "ieee802_11.h"
+
+/* Wireless extensions backwards compatibility */
+#ifndef SIOCIWFIRSTPRIV
+#define SIOCIWFIRSTPRIV                SIOCDEVPRIVATE
+#endif /* SIOCIWFIRSTPRIV */
+
+/* We do this this way to avoid ifdefs in the actual code */
+#ifdef WIRELESS_SPY
+#define SPY_NUMBER(priv)       (priv->spy_number)
+#else
+#define SPY_NUMBER(priv)       0
+#endif /* WIRELESS_SPY */
 
-static char version[] __initdata = "orinoco.c 0.08a (David Gibson <hermes@gibson.dropbear.id.au> and others)";
+static char version[] __initdata = "orinoco.c 0.11a (David Gibson <hermes@gibson.dropbear.id.au> and others)";
 MODULE_AUTHOR("David Gibson <hermes@gibson.dropbear.id.au>");
 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
+#ifdef MODULE_LICENSE
 MODULE_LICENSE("Dual MPL/GPL");
+#endif
 
 /* Level of debugging. Used in the macros in orinoco.h */
 #ifdef ORINOCO_DEBUG
-int dldwd_debug = ORINOCO_DEBUG;
-MODULE_PARM(dldwd_debug, "i");
+int orinoco_debug = ORINOCO_DEBUG;
+MODULE_PARM(orinoco_debug, "i");
+EXPORT_SYMBOL(orinoco_debug);
 #endif
 
-int use_old_encaps = 0;
-MODULE_PARM(use_old_encaps, "i");
+#define ORINOCO_MIN_MTU                256
+#define ORINOCO_MAX_MTU                (IEEE802_11_DATA_LEN - ENCAPS_OVERHEAD)
 
 #define SYMBOL_MAX_VER_LEN     (14)
-
+#define USER_BAP               0
+#define IRQ_BAP                        1
+#define MAX_IRQLOOPS_PER_IRQ   10
+#define MAX_IRQLOOPS_PER_JIFFY (20000/HZ)      /* Based on a guestimate of how many events the
+                                                  device can legitimately generate */
+#define SMALL_KEY_SIZE         5
+#define LARGE_KEY_SIZE         13
+#define TX_NICBUF_SIZE_BUG     1585            /* Bug in Symbol firmware */
+
+#define DUMMY_FID              0xFFFF
+
+/*#define MAX_MULTICAST(priv)  (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
+  HERMES_MAX_MULTICAST : 0)*/
+#define MAX_MULTICAST(priv)    (HERMES_MAX_MULTICAST)
+
+/********************************************************************/
+/* Data tables                                                      */
+/********************************************************************/
+
+/* The frequency of each channel in MHz */
 const long channel_frequency[] = {
        2412, 2417, 2422, 2427, 2432, 2437, 2442,
        2447, 2452, 2457, 2462, 2467, 2472, 2484
 };
-
 #define NUM_CHANNELS ( sizeof(channel_frequency) / sizeof(channel_frequency[0]) )
 
-/* This tables gives the actual meanings of the bitrate IDs returned by the firmware.
-   It gives the rate in halfMb/s, negative indicates auto mode */
-const int rate_list[] = { 0, 2, 4, -22, 11, 22, -4, -11, 0, 0, 0, 0};
-
-#define NUM_RATES (sizeof(rate_list) / sizeof(rate_list[0]))
-
-struct p80211_hdr {
-       u16 frame_ctl;
-       u16 duration_id;
-       u8 addr1[ETH_ALEN];
-       u8 addr2[ETH_ALEN];
-       u8 addr3[ETH_ALEN];
-       u16 seq_ctl;
-       u8 addr4[ETH_ALEN];
-       u16 data_len;
-} __attribute__ ((packed));
-
-/* Frame control field constants */
-#define DLDWD_FCTL_VERS                        0x0002
-#define DLDWD_FCTL_FTYPE               0x000c
-#define DLDWD_FCTL_STYPE               0x00f0
-#define DLDWD_FCTL_TODS                        0x0100
-#define DLDWD_FCTL_FROMDS              0x0200
-#define DLDWD_FCTL_MOREFRAGS           0x0400
-#define DLDWD_FCTL_RETRY               0x0800
-#define DLDWD_FCTL_PM                  0x1000
-#define DLDWD_FCTL_MOREDATA            0x2000
-#define DLDWD_FCTL_WEP                 0x4000
-#define DLDWD_FCTL_ORDER               0x8000
-
-#define DLDWD_FTYPE_MGMT               0x0000
-#define DLDWD_FTYPE_CTL                        0x0004
-#define DLDWD_FTYPE_DATA               0x0008
-
-struct p8022_hdr {
+/* This tables gives the actual meanings of the bitrate IDs returned by the firmware. */
+struct {
+       int bitrate; /* in 100s of kilbits */
+       int automatic;
+       u16 agere_txratectrl;
+       u16 intersil_txratectrl;
+} bitrate_table[] = {
+       {110, 1,  3, 15}, /* Entry 0 is the default */
+       {10,  0,  1,  1},
+       {10,  1,  1,  1},
+       {20,  0,  2,  2},
+       {20,  1,  6,  3},
+       {55, 0,  4,  4},
+       {55, 1,  7,  7},
+       {110, 0,  5,  8},
+};
+#define BITRATE_TABLE_SIZE (sizeof(bitrate_table) / sizeof(bitrate_table[0]))
+
+struct header_struct {
+       /* 802.3 */
+       u8 dest[ETH_ALEN];
+       u8 src[ETH_ALEN];
+       u16 len;
+       /* 802.2 */
        u8 dsap;
        u8 ssap;
        u8 ctrl;
+       /* SNAP */
        u8 oui[3];
-} __attribute__ ((packed));
-
-struct dldwd_frame_hdr {
-       hermes_frame_desc_t desc;
-       struct p80211_hdr p80211;
-       struct ethhdr p8023;
-       struct p8022_hdr p8022;
        u16 ethertype;
 } __attribute__ ((packed));
 
-#define P8023_OFFSET           (sizeof(hermes_frame_desc_t) + \
-                               sizeof(struct p80211_hdr))
-#define ENCAPS_OVERHEAD                (sizeof(struct p8022_hdr) + 2)
-
-/* 802.2 LLL header SNAP used for SNAP encapsulation over 802.11 */
-struct p8022_hdr encaps_hdr = {
-       0xaa, 0xaa, 0x03, {0x00, 0x00, 0x00}
-};
-
-struct p8022_hdr old_encaps_hdr = {
-       0xaa, 0xaa, 0x03, {0x00, 0x00, 0xf8}
-};
-
-/* How many times to retry if we get an EIO reading the BAP in the Rx path */
-#define RX_EIO_RETRY           10
+/* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
+u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
 
-typedef struct dldwd_commsqual {
-       u16 qual, signal, noise;
-} __attribute__ ((packed)) dldwd_commsqual_t;
+#define ENCAPS_OVERHEAD                (sizeof(encaps_hdr) + 2)
 
 /*
  * Function prototypes
  */
 
-static void dldwd_stat_gather(struct net_device *dev,
+static void orinoco_stat_gather(struct net_device *dev,
                              struct sk_buff *skb,
-                             struct dldwd_frame_hdr *hdr);
+                             struct hermes_rx_descriptor *desc);
 
-static struct net_device_stats *dldwd_get_stats(struct net_device *dev);
-static struct iw_statistics *dldwd_get_wireless_stats(struct net_device *dev);
+static struct net_device_stats *orinoco_get_stats(struct net_device *dev);
+static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev);
 
 /* Hardware control routines */
 
-static int __dldwd_hw_reset(dldwd_priv_t *priv);
-static int __dldwd_hw_setup_wep(dldwd_priv_t *priv);
-static int dldwd_hw_get_bssid(dldwd_priv_t *priv, char buf[ETH_ALEN]);
-static int dldwd_hw_get_essid(dldwd_priv_t *priv, int *active, char buf[IW_ESSID_MAX_SIZE+1]);
-static long dldwd_hw_get_freq(dldwd_priv_t *priv);
-static int dldwd_hw_get_bitratelist(dldwd_priv_t *priv, int *numrates,
+static int __orinoco_hw_set_bitrate(struct orinoco_private *priv);
+static int __orinoco_hw_setup_wep(struct orinoco_private *priv);
+static int orinoco_hw_get_bssid(struct orinoco_private *priv, char buf[ETH_ALEN]);
+static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
+                             char buf[IW_ESSID_MAX_SIZE+1]);
+static long orinoco_hw_get_freq(struct orinoco_private *priv);
+static int orinoco_hw_get_bitratelist(struct orinoco_private *priv, int *numrates,
                                    s32 *rates, int max);
+static void __orinoco_set_multicast_list(struct net_device *dev);
 
 /* Interrupt handling routines */
-static void __dldwd_ev_tick(dldwd_priv_t *priv, hermes_t *hw);
-static void __dldwd_ev_wterr(dldwd_priv_t *priv, hermes_t *hw);
-static void __dldwd_ev_infdrop(dldwd_priv_t *priv, hermes_t *hw);
-static void __dldwd_ev_info(dldwd_priv_t *priv, hermes_t *hw);
-static void __dldwd_ev_rx(dldwd_priv_t *priv, hermes_t *hw);
-static void __dldwd_ev_txexc(dldwd_priv_t *priv, hermes_t *hw);
-static void __dldwd_ev_tx(dldwd_priv_t *priv, hermes_t *hw);
-static void __dldwd_ev_alloc(dldwd_priv_t *priv, hermes_t *hw);
-
-static int dldwd_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq);
-static int dldwd_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq);
-static int dldwd_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq);
-static int dldwd_ioctl_setessid(struct net_device *dev, struct iw_point *erq);
-static int dldwd_ioctl_getessid(struct net_device *dev, struct iw_point *erq);
-static int dldwd_ioctl_setnick(struct net_device *dev, struct iw_point *nrq);
-static int dldwd_ioctl_getnick(struct net_device *dev, struct iw_point *nrq);
-static int dldwd_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq);
-static int dldwd_ioctl_getsens(struct net_device *dev, struct iw_param *srq);
-static int dldwd_ioctl_setsens(struct net_device *dev, struct iw_param *srq);
-static int dldwd_ioctl_setrts(struct net_device *dev, struct iw_param *rrq);
-static int dldwd_ioctl_setfrag(struct net_device *dev, struct iw_param *frq);
-static int dldwd_ioctl_getfrag(struct net_device *dev, struct iw_param *frq);
-static int dldwd_ioctl_setrate(struct net_device *dev, struct iw_param *frq);
-static int dldwd_ioctl_getrate(struct net_device *dev, struct iw_param *frq);
-static int dldwd_ioctl_setpower(struct net_device *dev, struct iw_param *prq);
-static int dldwd_ioctl_getpower(struct net_device *dev, struct iw_param *prq);
-static int dldwd_ioctl_setport3(struct net_device *dev, struct iwreq *wrq);
-static int dldwd_ioctl_getport3(struct net_device *dev, struct iwreq *wrq);
-static void __dldwd_set_multicast_list(struct net_device *dev);
+static void __orinoco_ev_tick(struct orinoco_private *priv, hermes_t *hw);
+static void __orinoco_ev_wterr(struct orinoco_private *priv, hermes_t *hw);
+static void __orinoco_ev_infdrop(struct orinoco_private *priv, hermes_t *hw);
+static void __orinoco_ev_info(struct orinoco_private *priv, hermes_t *hw);
+static void __orinoco_ev_rx(struct orinoco_private *priv, hermes_t *hw);
+static void __orinoco_ev_txexc(struct orinoco_private *priv, hermes_t *hw);
+static void __orinoco_ev_tx(struct orinoco_private *priv, hermes_t *hw);
+static void __orinoco_ev_alloc(struct orinoco_private *priv, hermes_t *hw);
+
+static int orinoco_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq);
+static int orinoco_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq);
+static int orinoco_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq);
+static int orinoco_ioctl_setessid(struct net_device *dev, struct iw_point *erq);
+static int orinoco_ioctl_getessid(struct net_device *dev, struct iw_point *erq);
+static int orinoco_ioctl_setnick(struct net_device *dev, struct iw_point *nrq);
+static int orinoco_ioctl_getnick(struct net_device *dev, struct iw_point *nrq);
+static int orinoco_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq);
+static int orinoco_ioctl_getsens(struct net_device *dev, struct iw_param *srq);
+static int orinoco_ioctl_setsens(struct net_device *dev, struct iw_param *srq);
+static int orinoco_ioctl_setrts(struct net_device *dev, struct iw_param *rrq);
+static int orinoco_ioctl_setfrag(struct net_device *dev, struct iw_param *frq);
+static int orinoco_ioctl_getfrag(struct net_device *dev, struct iw_param *frq);
+static int orinoco_ioctl_setrate(struct net_device *dev, struct iw_param *frq);
+static int orinoco_ioctl_getrate(struct net_device *dev, struct iw_param *frq);
+static int orinoco_ioctl_setpower(struct net_device *dev, struct iw_param *prq);
+static int orinoco_ioctl_getpower(struct net_device *dev, struct iw_param *prq);
+static int orinoco_ioctl_setport3(struct net_device *dev, struct iwreq *wrq);
+static int orinoco_ioctl_getport3(struct net_device *dev, struct iwreq *wrq);
 
 /* /proc debugging stuff */
-static int dldwd_proc_init(void);
-static void dldwd_proc_cleanup(void);
+static int orinoco_proc_init(void);
+static void orinoco_proc_cleanup(void);
 
 /*
  * Inline functions
  */
 static inline void
-dldwd_lock(dldwd_priv_t *priv)
+orinoco_lock(struct orinoco_private *priv)
 {
        spin_lock_bh(&priv->lock);
 }
 
 static inline void
-dldwd_unlock(dldwd_priv_t *priv)
+orinoco_unlock(struct orinoco_private *priv)
 {
        spin_unlock_bh(&priv->lock);
 }
 
 static inline int
-dldwd_irqs_allowed(dldwd_priv_t *priv)
+orinoco_irqs_allowed(struct orinoco_private *priv)
 {
-       return test_bit(DLDWD_STATE_DOIRQ, &priv->state);
+       return test_bit(ORINOCO_STATE_DOIRQ, &priv->state);
 }
 
 static inline void
-__dldwd_stop_irqs(dldwd_priv_t *priv)
+__orinoco_stop_irqs(struct orinoco_private *priv)
 {
        hermes_t *hw = &priv->hw;
 
        hermes_set_irqmask(hw, 0);
-       clear_bit(DLDWD_STATE_DOIRQ, &priv->state);
-       while (test_bit(DLDWD_STATE_INIRQ, &priv->state))
+       clear_bit(ORINOCO_STATE_DOIRQ, &priv->state);
+       while (test_bit(ORINOCO_STATE_INIRQ, &priv->state))
                ;
 }
 
 static inline void
-__dldwd_start_irqs(dldwd_priv_t *priv, u16 irqmask)
+__orinoco_start_irqs(struct orinoco_private *priv, u16 irqmask)
 {
        hermes_t *hw = &priv->hw;
 
-       TRACE_ENTER(priv->ndev.name);
+       TRACE_ENTER(priv->ndev->name);
 
-       __cli();
-       set_bit(DLDWD_STATE_DOIRQ, &priv->state);
+       __cli(); /* FIXME: is this necessary? */
+       set_bit(ORINOCO_STATE_DOIRQ, &priv->state);
        hermes_set_irqmask(hw, irqmask);
        __sti();
 
-       TRACE_EXIT(priv->ndev.name);
+       TRACE_EXIT(priv->ndev->name);
 }
 
 static inline void
-set_port_type(dldwd_priv_t *priv)
+set_port_type(struct orinoco_private *priv)
 {
        switch (priv->iw_mode) {
        case IW_MODE_INFRA:
@@ -476,103 +555,90 @@ set_port_type(dldwd_priv_t *priv)
                break;
        default:
                printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
-                      priv->ndev.name);
+                      priv->ndev->name);
        }
 }
 
-extern void
-dldwd_set_multicast_list(struct net_device *dev)
+static inline int
+is_snap(struct header_struct *hdr)
+{
+       return (hdr->dsap == 0xAA) && (hdr->ssap == 0xAA) && (hdr->ctrl == 0x3);
+}
+
+static void
+orinoco_set_multicast_list(struct net_device *dev)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
 
-       dldwd_lock(priv);
-       __dldwd_set_multicast_list(dev);
-       dldwd_unlock(priv);
+       orinoco_lock(priv);
+       __orinoco_set_multicast_list(dev);
+       orinoco_unlock(priv);
 }
 
 /*
  * Hardware control routines
  */
 
-static int
-__dldwd_hw_reset(dldwd_priv_t *priv)
-{
-       hermes_t *hw = &priv->hw;
-       int err;
-
-       if (! priv->broken_reset)
-               return hermes_reset(hw);
-       else {
-               hw->inten = 0;
-               hermes_write_regn(hw, INTEN, 0);
-               err = hermes_disable_port(hw, 0);
-               hermes_write_regn(hw, EVACK, 0xffff);
-               return err;
-       }
-}
-
 void
-dldwd_shutdown(dldwd_priv_t *priv)
+orinoco_shutdown(struct orinoco_private *priv)
 {
-/*     hermes_t *hw = &priv->hw; */
        int err = 0;
 
-       TRACE_ENTER(priv->ndev.name);
+       TRACE_ENTER(priv->ndev->name);
 
-       dldwd_lock(priv);
-       __dldwd_stop_irqs(priv);
+       orinoco_lock(priv);
+       __orinoco_stop_irqs(priv);
 
-       err = __dldwd_hw_reset(priv);
+       err = hermes_reset(&priv->hw);
        if (err && err != -ENODEV) /* If the card is gone, we don't care about shutting it down */
-               printk(KERN_ERR "%s: Error %d shutting down Hermes chipset\n", priv->ndev.name, err);
+               printk(KERN_ERR "%s: Error %d shutting down Hermes chipset\n", priv->ndev->name, err);
 
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
-       TRACE_EXIT(priv->ndev.name);
+       TRACE_EXIT(priv->ndev->name);
 }
 
 int
-dldwd_reset(dldwd_priv_t *priv)
+orinoco_reset(struct orinoco_private *priv)
 {
-       struct net_device *dev = &priv->ndev;
+       struct net_device *dev = priv->ndev;
        hermes_t *hw = &priv->hw;
        int err = 0;
-       hermes_id_t idbuf;
-       int frame_size;
+       struct hermes_idstring idbuf;
 
-       TRACE_ENTER(priv->ndev.name);
+       TRACE_ENTER(priv->ndev->name);
 
        /* Stop other people bothering us */
-       dldwd_lock(priv);
-       __dldwd_stop_irqs(priv);
+       orinoco_lock(priv);
+       __orinoco_stop_irqs(priv);
 
        /* Check if we need a card reset */
-       if((priv->need_card_reset) && (priv->card_reset_handler != NULL))
-               priv->card_reset_handler(priv);
+       if (priv->hard_reset)
+               priv->hard_reset(priv);
 
        /* Do standard firmware reset if we can */
-       err = __dldwd_hw_reset(priv);
+       err = hermes_reset(hw);
        if (err)
                goto out;
 
-       frame_size = TX_NICBUF_SIZE;
-       /* This stupid bug is present in Intel firmware 1.10, and
-        * may be fixed in later firmwares - Jean II */
-       if(priv->broken_allocate)
-               frame_size = TX_NICBUF_SIZE_BUG;
-       err = hermes_allocate(hw, frame_size, &priv->txfid);
-       if (err)
-               goto out;
+       err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
+       if (err == -EIO) {
+               /* Try workaround for old Symbol firmware bug */
+               priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
+               err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
+               if (err)
+                       goto out;
+       }
 
        /* Now set up all the parameters on the card */
        
        /* Set up the link mode */
        
-       err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_PORTTYPE, priv->port_type);
+       err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE, priv->port_type);
        if (err)
                goto out;
        if (priv->has_ibss) {
-               err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_CREATEIBSS,
+               err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFCREATEIBSS,
                                           priv->allow_ibss);
                if (err)
                        goto out;
@@ -586,21 +652,16 @@ ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
                }
        }
 
-       /* Set up encryption */
-       if (priv->has_wep) {
-               err = __dldwd_hw_setup_wep(priv);
-               if (err) {
-                       printk(KERN_ERR "%s: Error %d activating WEP.\n",
-                              dev->name, err);
-                       goto out;
-               }
-       }
-
        /* Set the desired ESSID */
        idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
        memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
-       err = hermes_write_ltv(hw, USER_BAP, (priv->port_type == 3) ?
-                              HERMES_RID_CNF_OWN_SSID : HERMES_RID_CNF_DESIRED_SSID,
+       /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
+       err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
+                              HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
+                              &idbuf);
+       if (err)
+               goto out;
+       err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
                               HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
                               &idbuf);
        if (err)
@@ -609,58 +670,65 @@ ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
        /* Set the station name */
        idbuf.len = cpu_to_le16(strlen(priv->nick));
        memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
-       err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNF_NICKNAME,
+       err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
                               HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
                               &idbuf);
        if (err)
                goto out;
 
        /* Set the channel/frequency */
-       err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_CHANNEL, priv->channel);
+       err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFOWNCHANNEL, priv->channel);
        if (err)
                goto out;
 
        /* Set AP density */
-       err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_SYSTEM_SCALE, priv->ap_density);
-       if (err)
-               goto out;
+       if (priv->has_sensitivity) {
+               err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
+                                          priv->ap_density);
+               if (err)
+                       priv->has_sensitivity = 0;
+       }
 
        /* Set RTS threshold */
-       err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_RTS_THRESH, priv->rts_thresh);
+       err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD, priv->rts_thresh);
        if (err)
                goto out;
 
        /* Set fragmentation threshold or MWO robustness */
        if (priv->has_mwo)
                err = hermes_write_wordrec(hw, USER_BAP,
-                                          HERMES_RID_CNF_MWO_ROBUST, priv->mwo_robust);
+                                          HERMES_RID_CNFMWOROBUST_AGERE,
+                                          priv->mwo_robust);
        else
                err = hermes_write_wordrec(hw, USER_BAP,
-                                          HERMES_RID_CNF_FRAG_THRESH, priv->frag_thresh);
+                                          HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
+                                          priv->frag_thresh);
        if (err)
                goto out;
 
        /* Set bitrate */
-       err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_TX_RATE_CTRL,
-                                  priv->tx_rate_ctrl);
+       err = __orinoco_hw_set_bitrate(priv);
        if (err)
                goto out;
 
        /* Set power management */
        if (priv->has_pm) {
-               err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_ENABLE,
+               err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED,
                                           priv->pm_on);
                if (err)
                        goto out;
-               err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_MCAST_RX,
+               err = hermes_write_wordrec(hw, USER_BAP,
+                                          HERMES_RID_CNFMULTICASTRECEIVE,
                                           priv->pm_mcast);
                if (err)
                        goto out;
-               err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_PERIOD,
+               err = hermes_write_wordrec(hw, USER_BAP,
+                                          HERMES_RID_CNFMAXSLEEPDURATION,
                                           priv->pm_period);
                if (err)
                        goto out;
-               err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_HOLDOVER,
+               err = hermes_write_wordrec(hw, USER_BAP,
+                                          HERMES_RID_CNFPMHOLDOVERDURATION,
                                           priv->pm_timeout);
                if (err)
                        goto out;
@@ -668,7 +736,8 @@ ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
 
        /* Set preamble - only for Symbol so far... */
        if (priv->has_preamble) {
-               err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_SYMBOL_PREAMBLE,
+               err = hermes_write_wordrec(hw, USER_BAP,
+                                          HERMES_RID_CNFPREAMBLE_SYMBOL,
                                           priv->preamble);
                if (err) {
                        printk(KERN_WARNING "%s: Can't set preamble!\n", dev->name);
@@ -676,50 +745,100 @@ ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
                }
        }
 
+       /* Set up encryption */
+       if (priv->has_wep) {
+               err = __orinoco_hw_setup_wep(priv);
+               if (err) {
+                       printk(KERN_ERR "%s: Error %d activating WEP.\n",
+                              dev->name, err);
+                       goto out;
+               }
+       }
+
        /* Set promiscuity / multicast*/
        priv->promiscuous = 0;
-       priv->allmulti = 0;
        priv->mc_count = 0;
-       __dldwd_set_multicast_list(dev);
-       
-       err = hermes_enable_port(hw, DLDWD_MACPORT);
-       if (err)
-               goto out;
+       __orinoco_set_multicast_list(dev);
        
-       __dldwd_start_irqs(priv, HERMES_EV_RX | HERMES_EV_ALLOC |
+       __orinoco_start_irqs(priv, HERMES_EV_RX | HERMES_EV_ALLOC |
                           HERMES_EV_TX | HERMES_EV_TXEXC |
                           HERMES_EV_WTERR | HERMES_EV_INFO |
                           HERMES_EV_INFDROP);
 
+       err = hermes_enable_port(hw, 0);
+       if (err)
+               goto out;
+
  out:
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
+
+       TRACE_EXIT(priv->ndev->name);
+
+       return err;
+}
+
+static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
+{
+       hermes_t *hw = &priv->hw;
+       int err = 0;
+
+       TRACE_ENTER(priv->ndev->name);
+
+       if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
+               printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
+                      priv->ndev->name, priv->bitratemode);
+               return -EINVAL;
+       }
 
-       TRACE_EXIT(priv->ndev.name);
+       switch (priv->firmware_type) {
+       case FIRMWARE_TYPE_AGERE:
+               err = hermes_write_wordrec(hw, USER_BAP,
+                                          HERMES_RID_CNFTXRATECONTROL,
+                                          bitrate_table[priv->bitratemode].agere_txratectrl);
+               break;
+       case FIRMWARE_TYPE_INTERSIL:
+       case FIRMWARE_TYPE_SYMBOL:
+               err = hermes_write_wordrec(hw, USER_BAP,
+                                          HERMES_RID_CNFTXRATECONTROL,
+                                          bitrate_table[priv->bitratemode].intersil_txratectrl);
+               break;
+       default:
+               BUG();
+       }
+
+       TRACE_EXIT(priv->ndev->name);
 
        return err;
 }
 
-static int __dldwd_hw_setup_wep(dldwd_priv_t *priv)
+
+static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
 {
        hermes_t *hw = &priv->hw;
        int err = 0;
        int     master_wep_flag;
        int     auth_flag;
 
-       TRACE_ENTER(priv->ndev.name);
+       TRACE_ENTER(priv->ndev->name);
 
        switch (priv->firmware_type) {
-       case FIRMWARE_TYPE_LUCENT: /* Lucent style WEP */
+       case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
                if (priv->wep_on) {
-                       err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_TX_KEY, priv->tx_key);
+                       err = hermes_write_wordrec(hw, USER_BAP,
+                                                  HERMES_RID_CNFTXKEY_AGERE,
+                                                  priv->tx_key);
                        if (err)
                                return err;
                        
-                       err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNF_KEYS, &priv->keys);
+                       err = HERMES_WRITE_RECORD(hw, USER_BAP,
+                                                 HERMES_RID_CNFWEPKEYS_AGERE,
+                                                 &priv->keys);
                        if (err)
                                return err;
                }
-               err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_WEP_ON, priv->wep_on);
+               err = hermes_write_wordrec(hw, USER_BAP,
+                                          HERMES_RID_CNFWEPENABLED_AGERE,
+                                          priv->wep_on);
                if (err)
                        return err;
                break;
@@ -728,26 +847,24 @@ static int __dldwd_hw_setup_wep(dldwd_priv_t *priv)
        case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
                master_wep_flag = 0;            /* Off */
                if (priv->wep_on) {
-/*                     int keylen; */
+                       int keylen;
                        int i;
 
                        /* Fudge around firmware weirdness */
-/*                     keylen = priv->keys[priv->tx_key].len; */
-
+                       keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
+                       
                        /* Write all 4 keys */
-                       for(i = 0; i < MAX_KEYS; i++) {
-                               int keylen = le16_to_cpu(priv->keys[i].len);
-
+                       for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
+/*                             int keylen = le16_to_cpu(priv->keys[i].len); */
+                               
                                if (keylen > LARGE_KEY_SIZE) {
                                        printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
-                                              priv->ndev.name, i, keylen);
+                                              priv->ndev->name, i, keylen);
                                        return -E2BIG;
                                }
 
-                               printk("About to write key %d, keylen=%d\n",
-                                      i, keylen);                                   
                                err = hermes_write_ltv(hw, USER_BAP,
-                                                      HERMES_RID_CNF_INTERSIL_KEY0 + i,
+                                                      HERMES_RID_CNFDEFAULTKEY0 + i,
                                                       HERMES_BYTES_TO_RECLEN(keylen),
                                                       priv->keys[i].data);
                                if (err)
@@ -755,39 +872,35 @@ static int __dldwd_hw_setup_wep(dldwd_priv_t *priv)
                        }
 
                        /* Write the index of the key used in transmission */
-                       err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_INTERSIL_TX_KEY,
+                       err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFWEPDEFAULTKEYID,
                                                   priv->tx_key);
                        if (err)
                                return err;
-
-                       /* Authentication is where Intersil and Symbol
-                        * firmware differ... */
-                       if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL) {
-                               /* Symbol cards : set the authentication :
-                                * 0 -> no encryption, 1 -> open,
-                                * 2 -> shared key
-                                * 3 -> shared key 128 -> AP only */
-                               if(priv->wep_restrict)
-                                       auth_flag = 2;
-                               else
-                                       auth_flag = 1;
-                               err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_SYMBOL_AUTH_TYPE, auth_flag);
-                               if (err)
-                                       return err;
-                               /* Master WEP setting is always 3 */
+                       
+                       if (priv->wep_restrict) {
+                               auth_flag = 2;
                                master_wep_flag = 3;
                        } else {
-                               /* Prism2 card : we need to modify master
-                                * WEP setting */
-                               if(priv->wep_restrict)
-                                       master_wep_flag = 3;
-                               else
-                                       master_wep_flag = 1;
+                               /* Authentication is where Intersil and Symbol
+                                * firmware differ... */
+                               auth_flag = 1;
+                               if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
+                                       master_wep_flag = 3; /* Symbol */ 
+                               else 
+                                       master_wep_flag = 1; /* Intersil */
                        }
+
+
+                       err = hermes_write_wordrec(hw, USER_BAP,
+                                                  HERMES_RID_CNFAUTHENTICATION, auth_flag);
+                       if (err)
+                               return err;
                }
                
                /* Master WEP setting : on/off */
-               err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_INTERSIL_WEP_ON, master_wep_flag);
+               err = hermes_write_wordrec(hw, USER_BAP,
+                                          HERMES_RID_CNFWEPFLAGS_INTERSIL,
+                                          master_wep_flag);
                if (err)
                        return err;     
 
@@ -796,58 +909,58 @@ static int __dldwd_hw_setup_wep(dldwd_priv_t *priv)
        default:
                if (priv->wep_on) {
                        printk(KERN_ERR "%s: WEP enabled, although not supported!\n",
-                              priv->ndev.name);
+                              priv->ndev->name);
                        return -EINVAL;
                }
        }
 
-       TRACE_EXIT(priv->ndev.name);
+       TRACE_EXIT(priv->ndev->name);
 
        return 0;
 }
 
-static int dldwd_hw_get_bssid(dldwd_priv_t *priv, char buf[ETH_ALEN])
+static int orinoco_hw_get_bssid(struct orinoco_private *priv, char buf[ETH_ALEN])
 {
        hermes_t *hw = &priv->hw;
        int err = 0;
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
 
-       err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_BSSID,
+       err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
                              ETH_ALEN, NULL, buf);
 
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        return err;
 }
 
-static int dldwd_hw_get_essid(dldwd_priv_t *priv, int *active,
+static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
                              char buf[IW_ESSID_MAX_SIZE+1])
 {
        hermes_t *hw = &priv->hw;
        int err = 0;
-       hermes_id_t essidbuf;
+       struct hermes_idstring essidbuf;
        char *p = (char *)(&essidbuf.val);
        int len;
 
-       TRACE_ENTER(priv->ndev.name);
+       TRACE_ENTER(priv->ndev->name);
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
 
        if (strlen(priv->desired_essid) > 0) {
                /* We read the desired SSID from the hardware rather
                   than from priv->desired_essid, just in case the
                   firmware is allowed to change it on us. I'm not
                   sure about this */
-               /* My guess is that the OWN_SSID should always be whatever
+               /* My guess is that the OWNSSID should always be whatever
                 * we set to the card, whereas CURRENT_SSID is the one that
                 * may change... - Jean II */
                u16 rid;
 
                *active = 1;
 
-               rid = (priv->port_type == 3) ? HERMES_RID_CNF_OWN_SSID :
-                       HERMES_RID_CNF_DESIRED_SSID;
+               rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
+                       HERMES_RID_CNFDESIREDSSID;
                
                err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
                                      NULL, &essidbuf);
@@ -856,7 +969,7 @@ static int dldwd_hw_get_essid(dldwd_priv_t *priv, int *active,
        } else {
                *active = 0;
 
-               err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_SSID,
+               err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
                                      sizeof(essidbuf), NULL, &essidbuf);
                if (err)
                        goto fail_unlock;
@@ -864,19 +977,19 @@ static int dldwd_hw_get_essid(dldwd_priv_t *priv, int *active,
 
        len = le16_to_cpu(essidbuf.len);
 
-       memset(buf, 0, sizeof(buf));
+       memset(buf, 0, IW_ESSID_MAX_SIZE+1);
        memcpy(buf, p, len);
        buf[len] = '\0';
 
  fail_unlock:
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
-       TRACE_EXIT(priv->ndev.name);
+       TRACE_EXIT(priv->ndev->name);
 
        return err;       
 }
 
-static long dldwd_hw_get_freq(dldwd_priv_t *priv)
+static long orinoco_hw_get_freq(struct orinoco_private *priv)
 {
        
        hermes_t *hw = &priv->hw;
@@ -884,14 +997,14 @@ static long dldwd_hw_get_freq(dldwd_priv_t *priv)
        u16 channel;
        long freq = 0;
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
        
-       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENT_CHANNEL, &channel);
+       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
        if (err)
                goto out;
 
        if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
-               struct net_device *dev = &priv->ndev;
+               struct net_device *dev = priv->ndev;
 
                printk(KERN_WARNING "%s: Channel out of range (%d)!\n", dev->name, channel);
                err = -EBUSY;
@@ -901,27 +1014,27 @@ static long dldwd_hw_get_freq(dldwd_priv_t *priv)
        freq = channel_frequency[channel-1] * 100000;
 
  out:
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        if (err > 0)
                err = -EBUSY;
        return err ? err : freq;
 }
 
-static int dldwd_hw_get_bitratelist(dldwd_priv_t *priv, int *numrates,
+static int orinoco_hw_get_bitratelist(struct orinoco_private *priv, int *numrates,
                                    s32 *rates, int max)
 {
        hermes_t *hw = &priv->hw;
-       hermes_id_t list;
+       struct hermes_idstring list;
        unsigned char *p = (unsigned char *)&list.val;
        int err = 0;
        int num;
        int i;
 
-       dldwd_lock(priv);
-       err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_DATARATES, sizeof(list),
-                             NULL, &list);
-       dldwd_unlock(priv);
+       orinoco_lock(priv);
+       err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
+                             sizeof(list), NULL, &list);
+       orinoco_unlock(priv);
 
        if (err)
                return err;
@@ -937,19 +1050,20 @@ static int dldwd_hw_get_bitratelist(dldwd_priv_t *priv, int *numrates,
        return 0;
 }
 
+#if 0
 #ifndef ORINOCO_DEBUG
-static inline void show_rx_frame(struct dldwd_frame_hdr *frame) {}
+static inline void show_rx_frame(struct orinoco_rxframe_hdr *frame) {}
 #else
-static void show_rx_frame(struct dldwd_frame_hdr *frame)
+static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
 {
        printk(KERN_DEBUG "RX descriptor:\n");
        printk(KERN_DEBUG "  status      = 0x%04x\n", frame->desc.status);
-       printk(KERN_DEBUG "  res1        = 0x%04x\n", frame->desc.res1);
-       printk(KERN_DEBUG "  res2        = 0x%04x\n", frame->desc.res2);
-       printk(KERN_DEBUG "  q_info      = 0x%04x\n", frame->desc.q_info);
-       printk(KERN_DEBUG "  res3        = 0x%04x\n", frame->desc.res3);
-       printk(KERN_DEBUG "  res4        = 0x%04x\n", frame->desc.res4);
-       printk(KERN_DEBUG "  tx_ctl      = 0x%04x\n", frame->desc.tx_ctl);
+       printk(KERN_DEBUG "  time        = 0x%08x\n", frame->desc.time);
+       printk(KERN_DEBUG "  silence     = 0x%02x\n", frame->desc.silence);
+       printk(KERN_DEBUG "  signal      = 0x%02x\n", frame->desc.signal);
+       printk(KERN_DEBUG "  rate        = 0x%02x\n", frame->desc.rate);
+       printk(KERN_DEBUG "  rxflow      = 0x%02x\n", frame->desc.rxflow);
+       printk(KERN_DEBUG "  reserved    = 0x%08x\n", frame->desc.reserved);
 
        printk(KERN_DEBUG "IEEE 802.11 header:\n");
        printk(KERN_DEBUG "  frame_ctl   = 0x%04x\n",
@@ -997,182 +1111,246 @@ static void show_rx_frame(struct dldwd_frame_hdr *frame)
        printk(KERN_DEBUG "  ethertype  = 0x%04x\n", frame->ethertype);
 }
 #endif
+#endif
 
 /*
  * Interrupt handler
  */
-void dldwd_interrupt(int irq, void * dev_id, struct pt_regs *regs)
+void orinoco_interrupt(int irq, void * dev_id, struct pt_regs *regs)
 {
-       dldwd_priv_t *priv = (dldwd_priv_t *) dev_id;
+       struct orinoco_private *priv = (struct orinoco_private *) dev_id;
        hermes_t *hw = &priv->hw;
-       struct net_device *dev = &priv->ndev;
-       int count = IRQ_LOOP_MAX;
+       struct net_device *dev = priv->ndev;
+       int count = MAX_IRQLOOPS_PER_IRQ;
        u16 evstat, events;
-       static int old_time = 0, timecount = 0; /* Eugh, revolting hack for now */
+       /* These are used to detect a runaway interrupt situation */
+       /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
+        * we panic and shut down the hardware */
+       static int last_irq_jiffy = 0; /* jiffies value the last time we were called */
+       static int loops_this_jiffy = 0;
 
-       if (test_and_set_bit(DLDWD_STATE_INIRQ, &priv->state))
+       if (test_and_set_bit(ORINOCO_STATE_INIRQ, &priv->state))
                BUG();
 
-       if (! dldwd_irqs_allowed(priv)) {
-               clear_bit(DLDWD_STATE_INIRQ, &priv->state);
+       if (! orinoco_irqs_allowed(priv)) {
+               clear_bit(ORINOCO_STATE_INIRQ, &priv->state);
                return;
        }
 
-       DEBUG(3, "%s: dldwd_interrupt()\n", priv->ndev.name);
+       DEBUG(3, "%s: orinoco_interrupt()\n", priv->ndev->name);
 
-       while (1) {
-               if (jiffies != old_time)
-                       timecount = 0;
-               if ( (++timecount > 50) || (! count--) ) {
+       evstat = hermes_read_regn(hw, EVSTAT);
+       events = evstat & hw->inten;
+       
+/*     if (! events) { */
+/*             printk(KERN_WARNING "%s: Null event\n", dev->name); */
+/*     } */
+
+       if (jiffies != last_irq_jiffy)
+               loops_this_jiffy = 0;
+       last_irq_jiffy = jiffies;
+
+       while (events && count--) {
+               DEBUG(3, "__orinoco_interrupt(): count=%d EVSTAT=0x%04x\n",
+                     count, evstat);
+               
+               if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
                        printk(KERN_CRIT "%s: IRQ handler is looping too \
 much! Shutting down.\n",
                               dev->name);
                        /* Perform an emergency shutdown */
-                       clear_bit(DLDWD_STATE_DOIRQ, &priv->state);
+                       clear_bit(ORINOCO_STATE_DOIRQ, &priv->state);
                        hermes_set_irqmask(hw, 0);
                        break;
                }
 
-               evstat = hermes_read_regn(hw, EVSTAT);
-               DEBUG(3, "__dldwd_interrupt(): count=%d EVSTAT=0x%04x inten=0x%04x\n",
-                     count, evstat, hw->inten);
-
-               events = evstat & hw->inten;
-
-               if (! events) {
-                       if (netif_queue_stopped(dev)) {
-                               /* There seems to be a firmware bug which
-                                  sometimes causes the card to give an
-                                  interrupt with no event set, when there
-                                  sould be a Tx completed event. */
-                               DEBUG(3, "%s: Interrupt with no event (ALLOCFID=0x%04x)\n",
-                                     dev->name, (int)hermes_read_regn(hw, ALLOCFID));
-                               events = HERMES_EV_TX | HERMES_EV_ALLOC;
-                       } else /* Nothing's happening, we're done */
-                               break;
-               }
-
                /* Check the card hasn't been removed */
                if (! hermes_present(hw)) {
-                       DEBUG(0, "dldwd_interrupt(): card removed\n");
+                       DEBUG(0, "orinoco_interrupt(): card removed\n");
                        break;
                }
 
                if (events & HERMES_EV_TICK)
-                       __dldwd_ev_tick(priv, hw);
+                       __orinoco_ev_tick(priv, hw);
                if (events & HERMES_EV_WTERR)
-                       __dldwd_ev_wterr(priv, hw);
+                       __orinoco_ev_wterr(priv, hw);
                if (events & HERMES_EV_INFDROP)
-                       __dldwd_ev_infdrop(priv, hw);
+                       __orinoco_ev_infdrop(priv, hw);
                if (events & HERMES_EV_INFO)
-                       __dldwd_ev_info(priv, hw);
+                       __orinoco_ev_info(priv, hw);
                if (events & HERMES_EV_RX)
-                       __dldwd_ev_rx(priv, hw);
+                       __orinoco_ev_rx(priv, hw);
                if (events & HERMES_EV_TXEXC)
-                       __dldwd_ev_txexc(priv, hw);
+                       __orinoco_ev_txexc(priv, hw);
                if (events & HERMES_EV_TX)
-                       __dldwd_ev_tx(priv, hw);
+                       __orinoco_ev_tx(priv, hw);
                if (events & HERMES_EV_ALLOC)
-                       __dldwd_ev_alloc(priv, hw);
+                       __orinoco_ev_alloc(priv, hw);
                
                hermes_write_regn(hw, EVACK, events);
-       }
 
-       clear_bit(DLDWD_STATE_INIRQ, &priv->state);
+               evstat = hermes_read_regn(hw, EVSTAT);
+               events = evstat & hw->inten;
+       };
+
+       clear_bit(ORINOCO_STATE_INIRQ, &priv->state);
 }
 
-static void __dldwd_ev_tick(dldwd_priv_t *priv, hermes_t *hw)
+static void __orinoco_ev_tick(struct orinoco_private *priv, hermes_t *hw)
 {
-       printk(KERN_DEBUG "%s: TICK\n", priv->ndev.name);
+       printk(KERN_DEBUG "%s: TICK\n", priv->ndev->name);
 }
 
-static void __dldwd_ev_wterr(dldwd_priv_t *priv, hermes_t *hw)
+static void __orinoco_ev_wterr(struct orinoco_private *priv, hermes_t *hw)
 {
        /* This seems to happen a fair bit under load, but ignoring it
           seems to work fine...*/
        DEBUG(1, "%s: MAC controller error (WTERR). Ignoring.\n",
-             priv->ndev.name);
+             priv->ndev->name);
 }
 
-static void __dldwd_ev_infdrop(dldwd_priv_t *priv, hermes_t *hw)
+static void __orinoco_ev_infdrop(struct orinoco_private *priv, hermes_t *hw)
 {
-       printk(KERN_WARNING "%s: Information frame lost.\n", priv->ndev.name);
+       printk(KERN_WARNING "%s: Information frame lost.\n", priv->ndev->name);
 }
 
-static void __dldwd_ev_info(dldwd_priv_t *priv, hermes_t *hw)
+static void __orinoco_ev_info(struct orinoco_private *priv, hermes_t *hw)
 {
-       DEBUG(3, "%s: Information frame received.\n", priv->ndev.name);
-       /* We don't actually do anything about it - we assume the MAC
-          controller can deal with it */
+       struct net_device *dev = priv->ndev;
+       u16 infofid;
+       struct {
+               u16 len;
+               u16 type;
+       } __attribute__ ((packed)) info;
+       int err;
+
+       /* This is an answer to an INQUIRE command that we did earlier,
+        * or an information "event" generated by the card
+        * The controller return to us a pseudo frame containing
+        * the information in question - Jean II */
+       infofid = hermes_read_regn(hw, INFOFID);
+       DEBUG(3, "%s: __orinoco_ev_info(): INFOFID=0x%04x\n", dev->name,
+             infofid);
+
+       /* Read the info frame header - don't try too hard */
+       err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
+                              infofid, 0);
+       if (err) {
+               printk(KERN_ERR "%s: error %d reading info frame. "
+                      "Frame dropped.\n", dev->name, err);
+               return;
+       }
+       
+       switch (le16_to_cpu(info.type)) {
+       case HERMES_INQ_TALLIES: {
+               struct hermes_tallies_frame tallies;
+               struct iw_statistics *wstats = &priv->wstats;
+               int len = le16_to_cpu(info.len) - 1;
+               
+               if (len > (sizeof(tallies) / 2)) {
+                       DEBUG(1, "%s: tallies frame too long.\n", dev->name);
+                       len = sizeof(tallies) / 2;
+               }
+               
+               /* Read directly the data (no seek) */
+               hermes_read_words(hw, HERMES_DATA1, (void *) &tallies, len);
+               
+               /* Increment our various counters */
+               /* wstats->discard.nwid - no wrong BSSID stuff */
+               wstats->discard.code +=
+                       le16_to_cpu(tallies.RxWEPUndecryptable);
+               if (len == (sizeof(tallies) / 2))  
+                       wstats->discard.code +=
+                               le16_to_cpu(tallies.RxDiscards_WEPICVError) +
+                               le16_to_cpu(tallies.RxDiscards_WEPExcluded);
+               wstats->discard.misc +=
+                       le16_to_cpu(tallies.TxDiscardsWrongSA);
+#if WIRELESS_EXT > 11
+               wstats->discard.fragment +=
+                       le16_to_cpu(tallies.RxMsgInBadMsgFragments);
+               wstats->discard.retries +=
+                       le16_to_cpu(tallies.TxRetryLimitExceeded);
+               /* wstats->miss.beacon - no match */
+#if ORINOCO_DEBUG > 3
+               /* Hack for debugging - should not be taken as an example */
+               wstats->discard.nwid += le16_to_cpu(tallies.TxUnicastFrames);
+               wstats->miss.beacon += le16_to_cpu(tallies.RxUnicastFrames);
+#endif
+#endif /* WIRELESS_EXT > 11 */
+       }
+       break;
+       default:
+               DEBUG(1, "%s: Unknown information frame received (type %04x).\n",
+                     priv->ndev->name, le16_to_cpu(info.type));
+               /* We don't actually do anything about it */
+               break;
+       }
 }
 
-static void __dldwd_ev_rx(dldwd_priv_t *priv, hermes_t *hw)
+static void __orinoco_ev_rx(struct orinoco_private *priv, hermes_t *hw)
 {
-       struct net_device *dev = &priv->ndev;
+       struct net_device *dev = priv->ndev;
        struct net_device_stats *stats = &priv->stats;
        struct iw_statistics *wstats = &priv->wstats;
        struct sk_buff *skb = NULL;
-       int l = RX_EIO_RETRY;
        u16 rxfid, status;
        int length, data_len, data_off;
        char *p;
-       struct dldwd_frame_hdr hdr;
+       struct hermes_rx_descriptor desc;
+       struct header_struct hdr;
        struct ethhdr *eh;
        int err;
 
        rxfid = hermes_read_regn(hw, RXFID);
-       DEBUG(3, "__dldwd_ev_rx(): RXFID=0x%04x\n", rxfid);
-
-       /* We read in the entire frame header here. This isn't really
-          necessary, since we ignore most of it, but it's
-          conceptually simpler. We can tune this later if
-          necessary. */
-       do {
-               err = hermes_bap_pread(hw, IRQ_BAP, &hdr, sizeof(hdr),
-                                      rxfid, 0);
-       } while ( (err == -EIO) && (--l) );
+       DEBUG(3, "__orinoco_ev_rx(): RXFID=0x%04x\n", rxfid);
+
+       err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
+                              rxfid, 0);
        if (err) {
-               if (err == -EIO)
-                       DEBUG(1, "%s: EIO reading frame header.\n", dev->name);
-               else
-                       printk(KERN_ERR "%s: error %d reading frame header. "
-                              "Frame dropped.\n", dev->name, err);
+               printk(KERN_ERR "%s: error %d reading Rx descriptor. "
+                      "Frame dropped.\n", dev->name, err);
                stats->rx_errors++;
                goto drop;
        }
-       DEBUG(2, "%s: BAP read suceeded: l=%d\n", dev->name, l);
 
-       status = le16_to_cpu(hdr.desc.status);
+       status = le16_to_cpu(desc.status);
        
        if (status & HERMES_RXSTAT_ERR) {
-               if ((status & HERMES_RXSTAT_ERR) == HERMES_RXSTAT_BADCRC) {
-                       stats->rx_crc_errors++;
-                       DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n", dev->name);
-                       show_rx_frame(&hdr);
-               } else if ((status & HERMES_RXSTAT_ERR)
-                          == HERMES_RXSTAT_UNDECRYPTABLE) {
+               if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
                        wstats->discard.code++;
-                       printk(KERN_WARNING "%s: Undecryptable frame on Rx. Frame dropped.\n",
+                       DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
                               dev->name);
                } else {
-                       wstats->discard.misc++;
-                       printk("%s: Unknown Rx error (0x%x). Frame dropped.\n",
-                              dev->name, status & HERMES_RXSTAT_ERR);
+                       stats->rx_crc_errors++;
+                       DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n", dev->name);
                }
                stats->rx_errors++;
                goto drop;
        }
 
-       length = le16_to_cpu(hdr.p80211.data_len);
-       /* Yes, you heard right, that's le16. 802.2 and 802.3 are
-          big-endian, but 802.11 is little-endian believe it or
-          not. */
-       /* Correct. 802.3 is big-endian byte order and little endian bit
-        * order, whereas 802.11 is little endian for both byte and bit
-        * order. That's specified in the 802.11 spec. - Jean II */
+       /* For now we ignore the 802.11 header completely, assuming
+           that the card's firmware has handled anything vital */
+
+       err = hermes_bap_pread(hw, IRQ_BAP, &hdr, sizeof(hdr),
+                              rxfid, HERMES_802_3_OFFSET);
+       if (err) {
+               printk(KERN_ERR "%s: error %d reading frame header. "
+                      "Frame dropped.\n", dev->name, err);
+               stats->rx_errors++;
+               goto drop;
+       }
+
+       length = ntohs(hdr.len);
        
-       /* Sanity check */
-       if (length > MAX_FRAME_SIZE) {
+       /* Sanity checks */
+       if (length < sizeof(struct header_struct)) {
+               printk(KERN_WARNING "%s: Undersized frame received (%d bytes)\n",
+                      dev->name, length);
+               stats->rx_length_errors++;
+               stats->rx_errors++;
+               goto drop;
+       }
+       if (length > IEEE802_11_DATA_LEN) {
                printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
                       dev->name, length);
                stats->rx_length_errors++;
@@ -1203,45 +1381,38 @@ static void __dldwd_ev_rx(dldwd_priv_t *priv, hermes_t *hw)
         */
        if(((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
           ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
-          (!memcmp(&hdr.p8022, &encaps_hdr, 3))) {
+          is_snap(&hdr)) {
                /* These indicate a SNAP within 802.2 LLC within
                   802.11 frame which we'll need to de-encapsulate to
                   the original EthernetII frame. */
 
                /* Remove SNAP header, reconstruct EthernetII frame */
                data_len = length - ENCAPS_OVERHEAD;
-               data_off = sizeof(hdr);
+               data_off = HERMES_802_3_OFFSET + sizeof(hdr);
 
                eh = (struct ethhdr *)skb_put(skb, ETH_HLEN);
 
-               memcpy(eh, &hdr.p8023, sizeof(hdr.p8023));
+               memcpy(eh, &hdr, 2 * ETH_ALEN);
                eh->h_proto = hdr.ethertype;
        } else {
-               /* All other cases indicate a genuine 802.3 frame.
-                * No decapsulation needed */
-
-               /* Otherwise, we just throw the whole thing in,
-                * and hope the protocol layer can deal with it
-                * as 802.3 */
+               /* All other cases indicate a genuine 802.3 frame.  No
+                  decapsulation needed.  We just throw the whole
+                  thing in, and hope the protocol layer can deal with
+                  it as 802.3 */
                data_len = length;
-               data_off = P8023_OFFSET;
+               data_off = HERMES_802_3_OFFSET;
+               /* FIXME: we re-read from the card data we already read here */
        }
 
        p = skb_put(skb, data_len);
-       do {
-               err = hermes_bap_pread(hw, IRQ_BAP, p, RUP_EVEN(data_len),
-                                      rxfid, data_off);
-       } while ( (err == -EIO) && (--l) );
+       err = hermes_bap_pread(hw, IRQ_BAP, p, RUP_EVEN(data_len),
+                              rxfid, data_off);
        if (err) {
-               if (err == -EIO)
-                       DEBUG(1, "%s: EIO reading frame header.\n", dev->name);
-               else
-                       printk(KERN_ERR "%s: error %d reading frame header. "
-                              "Frame dropped.\n", dev->name, err);
+               printk(KERN_ERR "%s: error %d reading frame header. "
+                      "Frame dropped.\n", dev->name, err);
                stats->rx_errors++;
                goto drop;
        }
-       DEBUG(2, "%s: BAP read suceeded: l=%d\n", dev->name, l);
 
        dev->last_rx = jiffies;
        skb->dev = dev;
@@ -1249,11 +1420,10 @@ static void __dldwd_ev_rx(dldwd_priv_t *priv, hermes_t *hw)
        skb->ip_summed = CHECKSUM_NONE;
        
        /* Process the wireless stats if needed */
-       dldwd_stat_gather(dev, skb, &hdr);
+       orinoco_stat_gather(dev, skb, &desc);
 
        /* Pass the packet to the networking stack */
        netif_rx(skb);
-       dev->last_rx = jiffies;
        stats->rx_packets++;
        stats->rx_bytes += length;
 
@@ -1265,55 +1435,92 @@ static void __dldwd_ev_rx(dldwd_priv_t *priv, hermes_t *hw)
        return;
 }
 
-static void __dldwd_ev_txexc(dldwd_priv_t *priv, hermes_t *hw)
+static void __orinoco_ev_txexc(struct orinoco_private *priv, hermes_t *hw)
 {
-       struct net_device *dev = &priv->ndev;
+       struct net_device *dev = priv->ndev;
        struct net_device_stats *stats = &priv->stats;
+       u16 fid = hermes_read_regn(hw, TXCOMPLFID);
+       struct hermes_tx_descriptor desc;
+       int err = 0;
 
-       printk(KERN_WARNING "%s: Tx error!\n", dev->name);
+       if (fid == DUMMY_FID)
+               return; /* Nothing's really happened */
 
-       netif_wake_queue(dev);
+       err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc), fid, 0);
+       if (err) {
+               printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
+                      "(FID=%04X error %d)\n",
+                      dev->name, fid, err);
+       } else {
+               DEBUG(1, "%s: Tx error, status %d\n",
+                     dev->name, le16_to_cpu(desc.status));
+       }
+       
        stats->tx_errors++;
+
+       hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
 }
 
-static void __dldwd_ev_tx(dldwd_priv_t *priv, hermes_t *hw)
+static void __orinoco_ev_tx(struct orinoco_private *priv, hermes_t *hw)
 {
-       struct net_device *dev = &priv->ndev;
+/*     struct net_device *dev = priv->ndev; */
        struct net_device_stats *stats = &priv->stats;
+/*     u16 fid = hermes_read_regn(hw, TXCOMPLFID); */
 
-       DEBUG(3, "%s: Transmit completed\n", dev->name);
+/*     DEBUG(2, "%s: Transmit completed (FID=%04X)\n", priv->ndev->name, fid); */
 
        stats->tx_packets++;
-       netif_wake_queue(dev);
+
+       hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
 }
 
-static void __dldwd_ev_alloc(dldwd_priv_t *priv, hermes_t *hw)
+static void __orinoco_ev_alloc(struct orinoco_private *priv, hermes_t *hw)
 {
-       u16 allocfid;
+       struct net_device *dev = priv->ndev;
+       u16 fid = hermes_read_regn(hw, ALLOCFID);
+
+       DEBUG(3, "%s: Allocation complete FID=0x%04x\n", priv->ndev->name, fid);
+
+       if (fid != priv->txfid) {
+               if (fid != DUMMY_FID)
+                       printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
+                              dev->name, fid);
+               return;
+       } else {
+               netif_wake_queue(dev);
+       }
 
-       allocfid = hermes_read_regn(hw, ALLOCFID);
-       DEBUG(3, "%s: Allocation complete FID=0x%04x\n", priv->ndev.name, allocfid);
+       hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
+}
 
-       /* For some reason we don't seem to get transmit completed events properly */
-       if (allocfid == priv->txfid)
-               __dldwd_ev_tx(priv, hw);
+struct sta_id {
+       u16 id, vendor, major, minor;
+} __attribute__ ((packed));
 
-/*     hermes_write_regn(hw, ALLOCFID, 0); */
+static int determine_firmware_type(struct net_device *dev, struct sta_id *sta_id)
+{
+       u32 firmver = ((u32)sta_id->major << 16) | sta_id->minor;
+       
+       if (sta_id->vendor == 1)
+               return FIRMWARE_TYPE_AGERE;
+       else if ((sta_id->vendor == 2) &&
+                  ((firmver == 0x10001) || (firmver == 0x20001)))
+               return FIRMWARE_TYPE_SYMBOL;
+       else
+               return FIRMWARE_TYPE_INTERSIL;
 }
 
 static void determine_firmware(struct net_device *dev)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        hermes_t *hw = &priv->hw;
        int err;
-       struct sta_id {
-               u16 id, vendor, major, minor;
-       } __attribute__ ((packed)) sta_id;
+       struct sta_id sta_id;
        u32 firmver;
+       char tmp[SYMBOL_MAX_VER_LEN+1];
 
        /* Get the firmware version */
-       err = HERMES_READ_RECORD(hw, USER_BAP,
-                                HERMES_RID_STAIDENTITY, &sta_id);
+       err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
        if (err) {
                printk(KERN_WARNING "%s: Error %d reading firmware info. Wildly guessing capabilities...\n",
                       dev->name, err);
@@ -1330,21 +1537,29 @@ static void determine_firmware(struct net_device *dev)
               dev->name, sta_id.id, sta_id.vendor,
               sta_id.major, sta_id.minor);
 
-       /* Determine capabilities from the firmware version */
+       if (! priv->firmware_type)
+               priv->firmware_type = determine_firmware_type(dev, &sta_id);
 
-       if (sta_id.vendor == 1) {
+       /* Default capabilities */
+       priv->has_sensitivity = 1;
+       priv->has_mwo = 0;
+       priv->has_preamble = 0;
+       priv->has_port3 = 1;
+       priv->has_ibss = 1;
+       priv->has_ibss_any = 0;
+       priv->has_wep = 0;
+       priv->has_big_wep = 0;
+       priv->broken_cor_reset = 0;
+
+       /* Determine capabilities from the firmware version */
+       switch (priv->firmware_type) {
+       case FIRMWARE_TYPE_AGERE:
                /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
                   ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
                printk(KERN_DEBUG "%s: Looks like a Lucent/Agere firmware "
                       "version %d.%02d\n", dev->name,
                       sta_id.major, sta_id.minor);
 
-               priv->firmware_type = FIRMWARE_TYPE_LUCENT;
-               priv->tx_rate_ctrl = 0x3;       /* 11 Mb/s auto */
-               priv->need_card_reset = 0;
-               priv->broken_reset = 0;
-               priv->broken_allocate = 0;
-               priv->has_port3 = 1;            /* Still works in 7.28 */
                priv->has_ibss = (firmver >= 0x60006);
                priv->has_ibss_any = (firmver >= 0x60010);
                priv->has_wep = (firmver >= 0x40020);
@@ -1352,21 +1567,22 @@ static void determine_firmware(struct net_device *dev)
                                          Gold cards from the others? */
                priv->has_mwo = (firmver >= 0x60000);
                priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
-               priv->has_preamble = 0;
                priv->ibss_port = 1;
-               /* Tested with Lucent firmware :
+
+               /* FIXME: Which firmware really do have a broken reset */
+               priv->broken_cor_reset = (firmver < 0x60000);
+               /* Tested with Agere firmware :
                 *      1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
                 * Tested CableTron firmware : 4.32 => Anton */
-       } else if ((sta_id.vendor == 2) &&
-                  ((firmver == 0x10001) || (firmver == 0x20001))) {
+               break;
+       case FIRMWARE_TYPE_SYMBOL:
                /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
                /* Intel MAC : 00:02:B3:* */
                /* 3Com MAC : 00:50:DA:* */
-               char tmp[SYMBOL_MAX_VER_LEN+1];
-
                memset(tmp, 0, sizeof(tmp));
                /* Get the Symbol firmware version */
-               err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SYMBOL_SECONDARY_VER,
+               err = hermes_read_ltv(hw, USER_BAP,
+                                     HERMES_RID_SECONDARYVERSION_SYMBOL,
                                      SYMBOL_MAX_VER_LEN, NULL, &tmp);
                if (err) {
                        printk(KERN_WARNING
@@ -1390,22 +1606,16 @@ static void determine_firmware(struct net_device *dev)
                       "version [%s] (parsing to %X)\n", dev->name,
                       tmp, firmver);
 
-               priv->firmware_type = FIRMWARE_TYPE_SYMBOL;
-               priv->tx_rate_ctrl = 0xF;       /* 11 Mb/s auto */
-               priv->need_card_reset = 1;
-               priv->broken_reset = 0;
-               priv->broken_allocate = 1;
-               priv->has_port3 = 1;
                priv->has_ibss = (firmver >= 0x20000);
                priv->has_wep = (firmver >= 0x15012);
                priv->has_big_wep = (firmver >= 0x20000);
-               priv->has_mwo = 0;
                priv->has_pm = (firmver >= 0x20000) && (firmver < 0x22000);
                priv->has_preamble = (firmver >= 0x20000);
                priv->ibss_port = 4;
                /* Tested with Intel firmware : 0x20015 => Jean II */
                /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
-       } else {
+               break;
+       case FIRMWARE_TYPE_INTERSIL:
                /* D-Link, Linksys, Adtron, ZoomAir, and many others...
                 * Samsung, Compaq 100/200 and Proxim are slightly
                 * different and less well tested */
@@ -1415,27 +1625,21 @@ static void determine_firmware(struct net_device *dev)
                       "version %d.%02d\n", dev->name,
                       sta_id.major, sta_id.minor);
 
-               priv->firmware_type = FIRMWARE_TYPE_INTERSIL;
-               priv->tx_rate_ctrl = 0xF;       /* 11 Mb/s auto */
-               priv->need_card_reset = 0;
-               priv->broken_reset = 0;
-               priv->broken_allocate = 0;
-               priv->has_port3 = 1;
                priv->has_ibss = (firmver >= 0x00007); /* FIXME */
-               priv->has_wep = (firmver >= 0x00008);
-               priv->has_big_wep = priv->has_wep;
-               priv->has_mwo = 0;
+               priv->has_big_wep = priv->has_wep = (firmver >= 0x00008);
                priv->has_pm = (firmver >= 0x00007);
-               priv->has_preamble = 0;
 
                if (firmver >= 0x00008)
                        priv->ibss_port = 0;
                else {
                        printk(KERN_NOTICE "%s: Intersil firmware earlier "
-                              "than v0.08 - several features not supported.",
+                              "than v0.08 - several features not supported\n",
                               dev->name);
                        priv->ibss_port = 1;
                }
+               break;
+       default:
+               break;
        }
 }
 
@@ -1443,19 +1647,21 @@ static void determine_firmware(struct net_device *dev)
  * struct net_device methods
  */
 
-int
-dldwd_init(struct net_device *dev)
+static int
+orinoco_init(struct net_device *dev)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        hermes_t *hw = &priv->hw;
        int err = 0;
-       hermes_id_t nickbuf;
+       struct hermes_idstring nickbuf;
        u16 reclen;
        int len;
 
-       TRACE_ENTER("dldwd");
+       TRACE_ENTER("orinoco");
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
+
+       priv->nicbuf_size = IEEE802_11_FRAME_LEN + ETH_HLEN;
 
        /* Do standard firmware reset */
        err = hermes_reset(hw);
@@ -1468,20 +1674,20 @@ dldwd_init(struct net_device *dev)
        determine_firmware(dev);
 
        if (priv->has_port3)
-               printk(KERN_DEBUG "%s: Ad-hoc demo mode supported.\n", dev->name);
+               printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
        if (priv->has_ibss)
-               printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported.\n",
+               printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
                       dev->name);
        if (priv->has_wep) {
                printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
                if (priv->has_big_wep)
-                       printk("\"128\"-bit key.\n");
+                       printk("104-bit key\n");
                else
-                       printk("40-bit key.\n");
+                       printk("40-bit key\n");
        }
 
        /* Get the MAC address */
-       err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNF_MACADDR,
+       err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
                              ETH_ALEN, NULL, dev->dev_addr);
        if (err) {
                printk(KERN_WARNING "%s: failed to read MAC address!\n",
@@ -1495,15 +1701,15 @@ dldwd_init(struct net_device *dev)
               dev->dev_addr[5]);
 
        /* Get the station name */
-       err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNF_NICKNAME,
+       err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
                              sizeof(nickbuf), &reclen, &nickbuf);
        if (err) {
-               printk(KERN_ERR "%s: failed to read station name!n",
+               printk(KERN_ERR "%s: failed to read station name\n",
                       dev->name);
                goto out;
        }
        if (nickbuf.len)
-               len = min_t(u16, IW_ESSID_MAX_SIZE, le16_to_cpu(nickbuf.len));
+               len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
        else
                len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
        memcpy(priv->nick, &nickbuf.val, len);
@@ -1512,7 +1718,8 @@ dldwd_init(struct net_device *dev)
        printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
 
        /* Get allowed channels */
-       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNEL_LIST, &priv->channel_mask);
+       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
+                                 &priv->channel_mask);
        if (err) {
                printk(KERN_ERR "%s: failed to read channel list!\n",
                       dev->name);
@@ -1520,14 +1727,15 @@ dldwd_init(struct net_device *dev)
        }
 
        /* Get initial AP density */
-       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_SYSTEM_SCALE, &priv->ap_density);
-       if (err) {
-               printk(KERN_ERR "%s: failed to read AP density!\n", dev->name);
-               goto out;
+       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
+                                 &priv->ap_density);
+       if (err || priv->ap_density < 1 || priv->ap_density > 3) {
+               priv->has_sensitivity = 0;
        }
 
        /* Get initial RTS threshold */
-       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_RTS_THRESH, &priv->rts_thresh);
+       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
+                                 &priv->rts_thresh);
        if (err) {
                printk(KERN_ERR "%s: failed to read RTS threshold!\n", dev->name);
                goto out;
@@ -1535,10 +1743,11 @@ dldwd_init(struct net_device *dev)
 
        /* Get initial fragmentation settings */
        if (priv->has_mwo)
-               err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_MWO_ROBUST,
+               err = hermes_read_wordrec(hw, USER_BAP,
+                                         HERMES_RID_CNFMWOROBUST_AGERE,
                                          &priv->mwo_robust);
        else
-               err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_FRAG_THRESH,
+               err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
                                          &priv->frag_thresh);
        if (err) {
                printk(KERN_ERR "%s: failed to read fragmentation settings!\n", dev->name);
@@ -1549,14 +1758,16 @@ dldwd_init(struct net_device *dev)
        if (priv->has_pm) {
                priv->pm_on = 0;
                priv->pm_mcast = 1;
-               err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_PERIOD,
+               err = hermes_read_wordrec(hw, USER_BAP,
+                                         HERMES_RID_CNFMAXSLEEPDURATION,
                                          &priv->pm_period);
                if (err) {
                        printk(KERN_ERR "%s: failed to read power management period!\n",
                               dev->name);
                        goto out;
                }
-               err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_HOLDOVER,
+               err = hermes_read_wordrec(hw, USER_BAP,
+                                         HERMES_RID_CNFPMHOLDOVERDURATION,
                                          &priv->pm_timeout);
                if (err) {
                        printk(KERN_ERR "%s: failed to read power management timeout!\n",
@@ -1567,7 +1778,8 @@ dldwd_init(struct net_device *dev)
 
        /* Preamble setup */
        if (priv->has_preamble) {
-               err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_SYMBOL_PREAMBLE, &priv->preamble);
+               err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPREAMBLE_SYMBOL,
+                                         &priv->preamble);
                if (err)
                        goto out;
        }
@@ -1577,57 +1789,57 @@ dldwd_init(struct net_device *dev)
        /* By default use IEEE/IBSS ad-hoc mode if we have it */
        priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
        set_port_type(priv);
+       priv->channel = 10; /* default channel, more-or-less arbitrary */
 
        priv->promiscuous = 0;
-       priv->allmulti = 0;
        priv->wep_on = 0;
        priv->tx_key = 0;
 
        printk(KERN_DEBUG "%s: ready\n", dev->name);
 
  out:
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
-       TRACE_EXIT("dldwd");
+       TRACE_EXIT("orinoco");
 
        return err;
 }
 
 struct net_device_stats *
-dldwd_get_stats(struct net_device *dev)
+orinoco_get_stats(struct net_device *dev)
 {
-       dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
+       struct orinoco_private *priv = (struct orinoco_private *)dev->priv;
        
        return &priv->stats;
 }
 
 struct iw_statistics *
-dldwd_get_wireless_stats(struct net_device *dev)
+orinoco_get_wireless_stats(struct net_device *dev)
 {
-       dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
+       struct orinoco_private *priv = (struct orinoco_private *)dev->priv;
        hermes_t *hw = &priv->hw;
        struct iw_statistics *wstats = &priv->wstats;
        int err = 0;
 
-       if (!priv->hw_ready)
-               return NULL;
+       if (! netif_device_present(dev))
+               return NULL; /* FIXME: We may be able to do better than this */
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
 
        if (priv->iw_mode == IW_MODE_ADHOC) {
                memset(&wstats->qual, 0, sizeof(wstats->qual));
-#ifdef WIRELESS_SPY
                /* If a spy address is defined, we report stats of the
                 * first spy address - Jean II */
-               if (priv->spy_number > 0) {
+               if (SPY_NUMBER(priv)) {
                        wstats->qual.qual = priv->spy_stat[0].qual;
                        wstats->qual.level = priv->spy_stat[0].level;
                        wstats->qual.noise = priv->spy_stat[0].noise;
                        wstats->qual.updated = priv->spy_stat[0].updated;
                }
-#endif /* WIRELESS_SPY */
        } else {
-               dldwd_commsqual_t cq;
+               struct {
+                       u16 qual, signal, noise;
+               } __attribute__ ((packed)) cq;
 
                err = HERMES_READ_RECORD(hw, USER_BAP,
                                         HERMES_RID_COMMSQUALITY, &cq);
@@ -1641,7 +1853,14 @@ dldwd_get_wireless_stats(struct net_device *dev)
                wstats->qual.updated = 7;
        }
 
-       dldwd_unlock(priv);
+       /* We can't really wait for the tallies inquiry command to
+        * complete, so we just use the previous results and trigger
+        * a new tallies inquiry command for next time - Jean II */
+       /* FIXME: Hmm.. seems a bit ugly, I wonder if there's a way to
+          do better - dgibson */
+       err = hermes_inquire(hw, HERMES_INQ_TALLIES);
+               
+       orinoco_unlock(priv);
 
        if (err)
                return NULL;
@@ -1649,11 +1868,10 @@ dldwd_get_wireless_stats(struct net_device *dev)
        return wstats;
 }
 
-#ifdef WIRELESS_SPY
-static inline void dldwd_spy_gather(struct net_device *dev, u_char *mac,
+static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
                                    int level, int noise)
 {
-       dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
+       struct orinoco_private *priv = (struct orinoco_private *)dev->priv;
        int i;
 
        /* Gather wireless spy statistics: for each packet, compare the
@@ -1662,18 +1880,17 @@ static inline void dldwd_spy_gather(struct net_device *dev, u_char *mac,
                if (!memcmp(mac, priv->spy_address[i], ETH_ALEN)) {
                        priv->spy_stat[i].level = level - 0x95;
                        priv->spy_stat[i].noise = noise - 0x95;
-                       priv->spy_stat[i].qual = level - noise;
+                       priv->spy_stat[i].qual = (level > noise) ? (level - noise) : 0;
                        priv->spy_stat[i].updated = 7;
                }
 }
-#endif /* WIRELESS_SPY */
 
 void
-dldwd_stat_gather( struct net_device *dev,
-                  struct sk_buff *skb,
-                  struct dldwd_frame_hdr *hdr)
+orinoco_stat_gather(struct net_device *dev,
+                   struct sk_buff *skb,
+                   struct hermes_rx_descriptor *desc)
 {
-       dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
+       struct orinoco_private *priv = (struct orinoco_private *)dev->priv;
 
        /* Using spy support with lots of Rx packets, like in an
         * infrastructure (AP), will really slow down everything, because
@@ -1683,24 +1900,18 @@ dldwd_stat_gather( struct net_device *dev,
         * Note that to get here, you need both WIRELESS_SPY
         * compiled in AND some addresses in the list !!!
         */
-#ifdef WIRELESS_SPY
        /* Note : gcc will optimise the whole section away if
         * WIRELESS_SPY is not defined... - Jean II */
-       if (priv->spy_number > 0) {
-               u8 *stats = (u8 *) &(hdr->desc.q_info);
-               /* This code may look strange. Everywhere we are using 16 bit
-                * ints except here. I've verified that these are are the
-                * correct values. Please check on PPC - Jean II */
-
-               dldwd_spy_gather(dev, skb->mac.raw + ETH_ALEN, (int)stats[1], (int)stats[0]);
+       if (SPY_NUMBER(priv)) {
+               orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
+                                  desc->signal, desc->silence);
        }
-#endif /* WIRELESS_SPY */
 }
 
-int
-dldwd_xmit(struct sk_buff *skb, struct net_device *dev)
+static int
+orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
 {
-       dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
+       struct orinoco_private *priv = (struct orinoco_private *)dev->priv;
        struct net_device_stats *stats = &priv->stats;
        hermes_t *hw = &priv->hw;
        int err = 0;
@@ -1708,8 +1919,7 @@ dldwd_xmit(struct sk_buff *skb, struct net_device *dev)
        char *p;
        struct ethhdr *eh;
        int len, data_len, data_off;
-       struct dldwd_frame_hdr hdr;
-       hermes_response_t resp;
+       struct hermes_tx_descriptor desc;
 
        if (! netif_running(dev)) {
                printk(KERN_ERR "%s: Tx on stopped device!\n",
@@ -1724,90 +1934,69 @@ dldwd_xmit(struct sk_buff *skb, struct net_device *dev)
                return 1;
        }
        
-       dldwd_lock(priv);
+       orinoco_lock(priv);
 
        /* Length of the packet body */
+       /* FIXME: what if the skb is smaller than this? */
        len = max_t(int,skb->len - ETH_HLEN, ETH_ZLEN);
 
        eh = (struct ethhdr *)skb->data;
 
-       /* Build the IEEE 802.11 header */
-       memset(&hdr, 0, sizeof(hdr));
-       memcpy(hdr.p80211.addr1, eh->h_dest, ETH_ALEN);
-       memcpy(hdr.p80211.addr2, eh->h_source, ETH_ALEN);
-       hdr.p80211.frame_ctl = DLDWD_FTYPE_DATA;
+       memset(&desc, 0, sizeof(desc));
+       desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
+       err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
+       if (err) {
+               printk(KERN_ERR "%s: Error %d writing Tx descriptor to BAP\n",
+                      dev->name, err);
+               stats->tx_errors++;
+               goto fail;
+       }
 
        /* Encapsulate Ethernet-II frames */
        if (ntohs(eh->h_proto) > 1500) { /* Ethernet-II frame */
+               struct header_struct hdr;
                data_len = len;
-               data_off = sizeof(hdr);
+               data_off = HERMES_802_3_OFFSET + sizeof(hdr);
                p = skb->data + ETH_HLEN;
 
-               /* 802.11 header */
-               hdr.p80211.data_len = cpu_to_le16(data_len + ENCAPS_OVERHEAD);
-
                /* 802.3 header */
-               memcpy(hdr.p8023.h_dest, eh->h_dest, ETH_ALEN);
-               memcpy(hdr.p8023.h_source, eh->h_source, ETH_ALEN);
-               hdr.p8023.h_proto = htons(data_len + ENCAPS_OVERHEAD);
+               memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
+               memcpy(hdr.src, eh->h_source, ETH_ALEN);
+               hdr.len = htons(data_len + ENCAPS_OVERHEAD);
                
                /* 802.2 header */
-               if (! use_old_encaps) 
-                       memcpy(&hdr.p8022, &encaps_hdr,
-                              sizeof(encaps_hdr));
-               else
-                       memcpy(&hdr.p8022, &encaps_hdr,
-                              sizeof(old_encaps_hdr));
+               memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
                        
                hdr.ethertype = eh->h_proto;
                err  = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
-                                        txfid, 0);
+                                        txfid, HERMES_802_3_OFFSET);
                if (err) {
-                       if (err == -EIO)
-                               /* We get these errors reported by the
-                                  firmware every so often apparently at
-                                  random.  Let the upper layers
-                                  handle the retry */
-                               DEBUG(1, "%s: DEBUG: EIO writing packet header to BAP\n", dev->name);
-                       else
-                               printk(KERN_ERR "%s: Error %d writing packet header to BAP\n",
-                                      dev->name, err);
+                       printk(KERN_ERR "%s: Error %d writing packet header to BAP\n",
+                              dev->name, err);
                        stats->tx_errors++;
                        goto fail;
                }
        } else { /* IEEE 802.3 frame */
                data_len = len + ETH_HLEN;
-               data_off = P8023_OFFSET;
+               data_off = HERMES_802_3_OFFSET;
                p = skb->data;
-               
-               /* 802.11 header */
-               hdr.p80211.data_len = cpu_to_le16(len);
-               err = hermes_bap_pwrite(hw, USER_BAP, &hdr, P8023_OFFSET,
-                                       txfid, 0);
-               if (err) {
-                       printk(KERN_ERR
-                              "%s: Error %d writing packet header to BAP\n",
-                              dev->name, err);
-                       stats->tx_errors++;
-                       goto fail;
-               }
        }
 
        /* Round up for odd length packets */
        err = hermes_bap_pwrite(hw, USER_BAP, p, RUP_EVEN(data_len), txfid, data_off);
        if (err) {
-               if (err == -EIO)
-                       DEBUG(1, "%s: DEBUG: EIO writing packet header to BAP\n", dev->name);
-               else
-                       printk(KERN_ERR "%s: Error %d writing packet header to BAP",
-                              dev->name, err);
+               printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
+                      dev->name, err);
                stats->tx_errors++;
                goto fail;
        }
 
        /* Finally, we actually initiate the send */
-       err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL, txfid, &resp);
+       netif_stop_queue(dev);
+
+       err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL, txfid, NULL);
        if (err) {
+               netif_start_queue(dev);
                printk(KERN_ERR "%s: Error %d transmitting packet\n", dev->name, err);
                stats->tx_errors++;
                goto fail;
@@ -1816,31 +2005,30 @@ dldwd_xmit(struct sk_buff *skb, struct net_device *dev)
        dev->trans_start = jiffies;
        stats->tx_bytes += data_off + data_len;
 
-       netif_stop_queue(dev);
-
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        dev_kfree_skb(skb);
 
        return 0;
  fail:
 
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
        return err;
 }
 
-void
-dldwd_tx_timeout(struct net_device *dev)
+static void
+orinoco_tx_timeout(struct net_device *dev)
 {
-       dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
+       struct orinoco_private *priv = (struct orinoco_private *)dev->priv;
        struct net_device_stats *stats = &priv->stats;
+       struct hermes *hw = &priv->hw;
        int err = 0;
 
-       printk(KERN_WARNING "%s: Tx timeout! Resetting card.\n", dev->name);
+       printk(KERN_WARNING "%s: Tx timeout! Resetting card. ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n", dev->name, hermes_read_regn(hw, ALLOCFID), hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
 
        stats->tx_errors++;
 
-       err = dldwd_reset(priv);
+       err = orinoco_reset(priv);
        if (err)
                printk(KERN_ERR "%s: Error %d resetting card on Tx timeout!\n",
                       dev->name, err);
@@ -1850,9 +2038,113 @@ dldwd_tx_timeout(struct net_device *dev)
        }
 }
 
-static int dldwd_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq)
+static int
+orinoco_change_mtu(struct net_device *dev, int new_mtu)
+{
+       struct orinoco_private *priv = dev->priv;
+       TRACE_ENTER(dev->name);
+
+       if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
+               return -EINVAL;
+
+       if ( (new_mtu + ENCAPS_OVERHEAD + IEEE802_11_HLEN) >
+            (priv->nicbuf_size - ETH_HLEN) )
+               return -EINVAL;
+
+       dev->mtu = new_mtu;
+
+       TRACE_EXIT(dev->name);
+
+       return 0;
+}
+
+static void
+__orinoco_set_multicast_list(struct net_device *dev)
+{
+       struct orinoco_private *priv = dev->priv;
+       hermes_t *hw = &priv->hw;
+       int err = 0;
+       int promisc, mc_count;
+
+       /* We'll wait until it's ready. Anyway, the network doesn't call us
+        * here until we are open - Jean II */
+       /* FIXME: do we need this test at all? */
+       if (! netif_device_present(dev)) {
+               printk(KERN_WARNING "%s: __orinoco_set_multicast_list() called while device "
+                      "not present.\n", dev->name);
+               return;
+       }
+
+       TRACE_ENTER(dev->name);
+
+       /* The Hermes doesn't seem to have an allmulti mode, so we go
+        * into promiscuous mode and let the upper levels deal. */
+       if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
+            (dev->mc_count > MAX_MULTICAST(priv)) ) {
+               promisc = 1;
+               mc_count = 0;
+       } else {
+               promisc = 0;
+               mc_count = dev->mc_count;
+       }
+
+       if (promisc != priv->promiscuous) {
+               err = hermes_write_wordrec(hw, USER_BAP,
+                                          HERMES_RID_CNFPROMISCUOUSMODE,
+                                          promisc);
+               if (err) {
+                       printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
+                              dev->name, err);
+               } else 
+                       priv->promiscuous = promisc;
+       }
+
+       if (! promisc && (mc_count || priv->mc_count) ) {
+               struct dev_mc_list *p = dev->mc_list;
+               hermes_multicast_t mclist;
+               int i;
+
+               for (i = 0; i < mc_count; i++) {
+                       /* Paranoia: */
+                       if (! p)
+                               BUG(); /* Multicast list shorter than mc_count */
+                       if (p->dmi_addrlen != ETH_ALEN)
+                               BUG(); /* Bad address size in multicast list */
+                       
+                       memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
+                       p = p->next;
+               }
+               
+               if (p)
+                       printk(KERN_WARNING "Multicast list is longer than mc_count\n");
+
+               err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
+                                      HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
+                                      &mclist);
+               if (err)
+                       printk(KERN_ERR "%s: Error %d setting multicast list.\n",
+                              dev->name, err);
+               else
+                       priv->mc_count = mc_count;
+       }
+
+       /* Since we can set the promiscuous flag when it wasn't asked
+          for, make sure the net_device knows about it. */
+       if (priv->promiscuous)
+               dev->flags |= IFF_PROMISC;
+       else
+               dev->flags &= ~IFF_PROMISC;
+
+       TRACE_EXIT(dev->name);
+}
+
+/********************************************************************/
+/* Wireless extensions support                                      */
+/********************************************************************/
+
+static int orinoco_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        int err = 0;
        int mode;
        struct iw_range range;
@@ -1867,9 +2159,9 @@ static int dldwd_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq)
 
        rrq->length = sizeof(range);
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
        mode = priv->iw_mode;
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        memset(&range, 0, sizeof(range));
 
@@ -1905,13 +2197,25 @@ static int dldwd_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq)
                range.max_qual.qual = 0;
                range.max_qual.level = 0;
                range.max_qual.noise = 0;
+#if WIRELESS_EXT > 11
+               range.avg_qual.qual = 0;
+               range.avg_qual.level = 0;
+               range.avg_qual.noise = 0;
+#endif /* WIRELESS_EXT > 11 */
+
        } else {
                range.max_qual.qual = 0x8b - 0x2f;
                range.max_qual.level = 0x2f - 0x95 - 1;
                range.max_qual.noise = 0x2f - 0x95 - 1;
+#if WIRELESS_EXT > 11
+               /* Need to get better values */
+               range.avg_qual.qual = 0x24;
+               range.avg_qual.level = 0xC2;
+               range.avg_qual.noise = 0x9E;
+#endif /* WIRELESS_EXT > 11 */
        }
 
-       err = dldwd_hw_get_bitratelist(priv, &numrates,
+       err = orinoco_hw_get_bitratelist(priv, &numrates,
                                       range.bitrate, IW_MAX_BITRATES);
        if (err)
                return err;
@@ -1930,9 +2234,9 @@ static int dldwd_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq)
        range.min_frag = 256;
        range.max_frag = 2346;
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
        if (priv->has_wep) {
-               range.max_encoding_tokens = MAX_KEYS;
+               range.max_encoding_tokens = ORINOCO_MAX_KEYS;
 
                range.encoding_size[0] = SMALL_KEY_SIZE;
                range.num_encoding_sizes = 1;
@@ -1945,7 +2249,7 @@ static int dldwd_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq)
                range.num_encoding_sizes = 0;
                range.max_encoding_tokens = 0;
        }
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
                
        range.min_pmp = 0;
        range.max_pmp = 65535000;
@@ -1977,30 +2281,30 @@ static int dldwd_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq)
        return 0;
 }
 
-static int dldwd_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq)
+static int orinoco_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        int index = (erq->flags & IW_ENCODE_INDEX) - 1;
        int setindex = priv->tx_key;
        int enable = priv->wep_on;
        int restricted = priv->wep_restrict;
        u16 xlen = 0;
        int err = 0;
-       char keybuf[MAX_KEY_SIZE];
+       char keybuf[ORINOCO_MAX_KEY_SIZE];
        
        if (erq->pointer) {
                /* We actually have a key to set */
-               if ( (erq->length < SMALL_KEY_SIZE) || (erq->length > MAX_KEY_SIZE) )
+               if ( (erq->length < SMALL_KEY_SIZE) || (erq->length > ORINOCO_MAX_KEY_SIZE) )
                        return -EINVAL;
                
                if (copy_from_user(keybuf, erq->pointer, erq->length))
                        return -EFAULT;
        }
        
-       dldwd_lock(priv);
+       orinoco_lock(priv);
        
        if (erq->pointer) {
-               if (erq->length > MAX_KEY_SIZE) {
+               if (erq->length > ORINOCO_MAX_KEY_SIZE) {
                        err = -E2BIG;
                        goto out;
                }
@@ -2011,7 +2315,7 @@ static int dldwd_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq)
                        goto out;
                }
                
-               if ((index < 0) || (index >= MAX_KEYS))
+               if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
                        index = priv->tx_key;
                
                if (erq->length > SMALL_KEY_SIZE) {
@@ -2030,7 +2334,7 @@ static int dldwd_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq)
                /* Important note : if the user do "iwconfig eth0 enc off",
                 * we will arrive there with an index of -1. This is valid
                 * but need to be taken care off... Jean II */
-               if ((index < 0) || (index >= MAX_KEYS)) {
+               if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
                        if((index != -1) || (erq->flags == 0)) {
                                err = -EINVAL;
                                goto out;
@@ -2063,22 +2367,22 @@ static int dldwd_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq)
        priv->wep_restrict = restricted;
        
  out:
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
-       return 0;
+       return err;
 }
 
-static int dldwd_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq)
+static int orinoco_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        int index = (erq->flags & IW_ENCODE_INDEX) - 1;
        u16 xlen = 0;
-       char keybuf[MAX_KEY_SIZE];
+       char keybuf[ORINOCO_MAX_KEY_SIZE];
 
        
-       dldwd_lock(priv);
+       orinoco_lock(priv);
 
-       if ((index < 0) || (index >= MAX_KEYS))
+       if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
                index = priv->tx_key;
 
        erq->flags = 0;
@@ -2087,7 +2391,7 @@ static int dldwd_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq)
        erq->flags |= index + 1;
        
        /* Only for symbol cards - Jean II */
-       if (priv->firmware_type != FIRMWARE_TYPE_LUCENT) {
+       if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
                if(priv->wep_restrict)
                        erq->flags |= IW_ENCODE_RESTRICTED;
                else
@@ -2099,10 +2403,10 @@ static int dldwd_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq)
        erq->length = xlen;
 
        if (erq->pointer) {
-               memcpy(keybuf, priv->keys[index].data, MAX_KEY_SIZE);
+               memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
        }
        
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        if (erq->pointer) {
                if (copy_to_user(erq->pointer, keybuf, xlen))
@@ -2112,9 +2416,9 @@ static int dldwd_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq)
        return 0;
 }
 
-static int dldwd_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
+static int orinoco_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        char essidbuf[IW_ESSID_MAX_SIZE+1];
 
        /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
@@ -2132,27 +2436,33 @@ static int dldwd_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
                essidbuf[erq->length] = '\0';
        }
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
 
        memcpy(priv->desired_essid, essidbuf, sizeof(priv->desired_essid));
 
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        return 0;
 }
 
-static int dldwd_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
+static int orinoco_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        char essidbuf[IW_ESSID_MAX_SIZE+1];
        int active;
        int err = 0;
 
        TRACE_ENTER(dev->name);
 
-       err = dldwd_hw_get_essid(priv, &active, essidbuf);
-       if (err)
-               return err;
+       if (netif_running(dev)) {
+               err = orinoco_hw_get_essid(priv, &active, essidbuf);
+               if (err)
+                       return err;
+       } else {
+               orinoco_lock(priv);
+               memcpy(essidbuf, priv->desired_essid, sizeof(essidbuf));
+               orinoco_unlock(priv);
+       }
 
        erq->flags = 1;
        erq->length = strlen(essidbuf) + 1;
@@ -2165,9 +2475,9 @@ static int dldwd_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
        return 0;
 }
 
-static int dldwd_ioctl_setnick(struct net_device *dev, struct iw_point *nrq)
+static int orinoco_ioctl_setnick(struct net_device *dev, struct iw_point *nrq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        char nickbuf[IW_ESSID_MAX_SIZE+1];
 
        if (nrq->length > IW_ESSID_MAX_SIZE)
@@ -2180,23 +2490,23 @@ static int dldwd_ioctl_setnick(struct net_device *dev, struct iw_point *nrq)
 
        nickbuf[nrq->length] = '\0';
        
-       dldwd_lock(priv);
+       orinoco_lock(priv);
 
        memcpy(priv->nick, nickbuf, sizeof(priv->nick));
 
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        return 0;
 }
 
-static int dldwd_ioctl_getnick(struct net_device *dev, struct iw_point *nrq)
+static int orinoco_ioctl_getnick(struct net_device *dev, struct iw_point *nrq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        char nickbuf[IW_ESSID_MAX_SIZE+1];
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
        memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        nrq->length = strlen(nickbuf)+1;
 
@@ -2206,9 +2516,9 @@ static int dldwd_ioctl_getnick(struct net_device *dev, struct iw_point *nrq)
        return 0;
 }
 
-static int dldwd_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq)
+static int orinoco_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        int chan = -1;
 
        /* We can only use this in Ad-Hoc demo mode to set the operating
@@ -2237,23 +2547,26 @@ static int dldwd_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq)
             ! (priv->channel_mask & (1 << (chan-1)) ) )
                return -EINVAL;
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
        priv->channel = chan;
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        return 0;
 }
 
-static int dldwd_ioctl_getsens(struct net_device *dev, struct iw_param *srq)
+static int orinoco_ioctl_getsens(struct net_device *dev, struct iw_param *srq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        hermes_t *hw = &priv->hw;
        u16 val;
        int err;
 
-       dldwd_lock(priv);
-       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_SYSTEM_SCALE, &val);
-       dldwd_unlock(priv);
+       if (!priv->has_sensitivity)
+               return -EOPNOTSUPP;
+
+       orinoco_lock(priv);
+       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE, &val);
+       orinoco_unlock(priv);
 
        if (err)
                return err;
@@ -2264,24 +2577,27 @@ static int dldwd_ioctl_getsens(struct net_device *dev, struct iw_param *srq)
        return 0;
 }
 
-static int dldwd_ioctl_setsens(struct net_device *dev, struct iw_param *srq)
+static int orinoco_ioctl_setsens(struct net_device *dev, struct iw_param *srq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        int val = srq->value;
 
+       if (!priv->has_sensitivity)
+               return -EOPNOTSUPP;
+
        if ((val < 1) || (val > 3))
                return -EINVAL;
        
-       dldwd_lock(priv);
+       orinoco_lock(priv);
        priv->ap_density = val;
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        return 0;
 }
 
-static int dldwd_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
+static int orinoco_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        int val = rrq->value;
 
        if (rrq->disabled)
@@ -2290,19 +2606,19 @@ static int dldwd_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
        if ( (val < 0) || (val > 2347) )
                return -EINVAL;
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
        priv->rts_thresh = val;
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        return 0;
 }
 
-static int dldwd_ioctl_setfrag(struct net_device *dev, struct iw_param *frq)
+static int orinoco_ioctl_setfrag(struct net_device *dev, struct iw_param *frq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        int err = 0;
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
 
        if (priv->has_mwo) {
                if (frq->disabled)
@@ -2324,22 +2640,24 @@ supported on this firmware. Using MWO robust instead.\n", dev->name);
                }
        }
 
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        return err;
 }
 
-static int dldwd_ioctl_getfrag(struct net_device *dev, struct iw_param *frq)
+static int orinoco_ioctl_getfrag(struct net_device *dev, struct iw_param *frq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        hermes_t *hw = &priv->hw;
        int err = 0;
        u16 val;
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
        
        if (priv->has_mwo) {
-               err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_MWO_ROBUST, &val);
+               err = hermes_read_wordrec(hw, USER_BAP,
+                                         HERMES_RID_CNFMWOROBUST_AGERE,
+                                         &val);
                if (err)
                        val = 0;
 
@@ -2347,7 +2665,8 @@ static int dldwd_ioctl_getfrag(struct net_device *dev, struct iw_param *frq)
                frq->disabled = ! val;
                frq->fixed = 0;
        } else {
-               err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_FRAG_THRESH, &val);
+               err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
+                                         &val);
                if (err)
                        val = 0;
 
@@ -2356,158 +2675,122 @@ static int dldwd_ioctl_getfrag(struct net_device *dev, struct iw_param *frq)
                frq->fixed = 1;
        }
 
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
        
        return err;
 }
 
-static int dldwd_ioctl_setrate(struct net_device *dev, struct iw_param *rrq)
+static int orinoco_ioctl_setrate(struct net_device *dev, struct iw_param *rrq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        int err = 0;
-       int rate_ctrl = -1;
-       int fixed, upto;
-       int brate;
+       int ratemode = -1;
+       int bitrate; /* 100s of kilobits */
        int i;
+       
+       /* As the user space doesn't know our highest rate, it uses -1
+        * to ask us to set the highest rate.  Test it using "iwconfig
+        * ethX rate auto" - Jean II */
+       if (rrq->value == -1)
+               bitrate = 110;
+       else {
+               if (rrq->value % 100000)
+                       return -EINVAL;
+               bitrate = rrq->value / 100000;
+       }
 
-       dldwd_lock(priv);
-
-       /* Normalise value */
-       brate = rrq->value / 500000;
+       if ( (bitrate != 10) && (bitrate != 20) &&
+            (bitrate != 55) && (bitrate != 110) )
+               return -EINVAL;
 
-       switch (priv->firmware_type) {
-       case FIRMWARE_TYPE_LUCENT: /* Lucent style rate */
-               if (! rrq->fixed) {
-                       if (brate > 0)
-                               brate = -brate;
-                       else
-                               brate = -22;
-               }
-       
-               for (i = 0; i < NUM_RATES; i++)
-                       if (rate_list[i] == brate) {
-                               rate_ctrl = i;
-                               break;
-                       }
-       
-               if ( (rate_ctrl < 1) || (rate_ctrl >= NUM_RATES) )
-                       err = -EINVAL;
-               else
-                       priv->tx_rate_ctrl = rate_ctrl;
-               break;
-       case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
-       case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
-               switch(brate) {
-               case 0:
-                       fixed = 0x0;
-                       upto = 0xF;
-                       break;
-               case 2:
-                       fixed = 0x1;
-                       upto = 0x1;
-                       break;
-               case 4:
-                       fixed = 0x2;
-                       upto = 0x3;
+       for (i = 0; i < BITRATE_TABLE_SIZE; i++)
+               if ( (bitrate_table[i].bitrate == bitrate) &&
+                    (bitrate_table[i].automatic == ! rrq->fixed) ) {
+                       ratemode = i;
                        break;
-               case 11:
-                       fixed = 0x4;
-                       upto = 0x7;
-                       break;
-               case 22:
-                       fixed = 0x8;
-                       upto = 0xF;
-                       break;
-               default:
-                       fixed = 0x0;
-                       upto = 0x0;
                }
-               if (rrq->fixed)
-                       rate_ctrl = fixed;
-               else
-                       rate_ctrl = upto;
-               if (rate_ctrl == 0)
-                       err = -EINVAL;
-               else
-                       priv->tx_rate_ctrl = rate_ctrl;
-               break;
-       }
+       
+       if (ratemode == -1)
+               return -EINVAL;
 
-       dldwd_unlock(priv);
+       orinoco_lock(priv);
+       priv->bitratemode = ratemode;
+       orinoco_unlock(priv);
 
        return err;
 }
 
-static int dldwd_ioctl_getrate(struct net_device *dev, struct iw_param *rrq)
+static int orinoco_ioctl_getrate(struct net_device *dev, struct iw_param *rrq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        hermes_t *hw = &priv->hw;
        int err = 0;
+       int ratemode;
+       int i;
        u16 val;
-       int brate = 0;
 
-       dldwd_lock(priv);
-       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_TX_RATE_CTRL, &val);
-       if (err)
-               goto out;
-       
-       switch (priv->firmware_type) {
-       case FIRMWARE_TYPE_LUCENT: /* Lucent style rate */
-               brate = rate_list[val];
-       
-               if (brate < 0) {
-                       rrq->fixed = 0;
+       orinoco_lock(priv);
 
-                       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENT_TX_RATE, &val);
-                       if (err)
-                               goto out;
+       ratemode = priv->bitratemode;
+
+       if ( (ratemode < 0) || (ratemode > BITRATE_TABLE_SIZE) )
+               BUG();
 
+       rrq->value = bitrate_table[ratemode].bitrate * 100000;
+       rrq->fixed = ! bitrate_table[ratemode].automatic;
+       rrq->disabled = 0;
+
+       /* If the interface is running we try to find more about the
+          current mode */
+       if (netif_running(dev)) {
+               err = hermes_read_wordrec(hw, USER_BAP,
+                                         HERMES_RID_CURRENTTXRATE, &val);
+               if (err)
+                       goto out;
+               
+               switch (priv->firmware_type) {
+               case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
+                       /* Note : in Lucent firmware, the return value of
+                        * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
+                        * and therefore is totally different from the
+                        * encoding of HERMES_RID_CNFTXRATECONTROL.
+                        * Don't forget that 6Mb/s is really 5.5Mb/s */
                        if (val == 6)
-                               brate = 11;
+                               rrq->value = 5500000;
                        else
-                               brate = 2*val;
-               } else
-                       rrq->fixed = 1;
-               break;
-       case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
-       case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
-               /* Check if auto or fixed (crude approximation) */
-               if((val & 0x1) && (val > 1)) {
-                       rrq->fixed = 0;
+                               rrq->value = val * 1000000;
+                        break;
+               case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
+               case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
+                       for (i = 0; i < BITRATE_TABLE_SIZE; i++)
+                               if (bitrate_table[i].intersil_txratectrl == val) {
+                                       ratemode = i;
+                                       break;
+                               }
+                       if (i >= BITRATE_TABLE_SIZE)
+                               printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
+                                      dev->name, val);
 
-                       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENT_TX_RATE, &val);
-                       if (err)
-                               goto out;
-               } else
-                       rrq->fixed = 1;
-
-               if(val >= 8)
-                       brate = 22;
-               else if(val >= 4)
-                       brate = 11;
-               else if(val >= 2)
-                       brate = 4;
-               else
-                       brate = 2;
-               break;
+                       rrq->value = bitrate_table[ratemode].bitrate * 100000;
+                       break;
+               default:
+                       BUG();
+               }
        }
 
-       rrq->value = brate * 500000;
-       rrq->disabled = 0;
-
  out:
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        return err;
 }
 
-static int dldwd_ioctl_setpower(struct net_device *dev, struct iw_param *prq)
+static int orinoco_ioctl_setpower(struct net_device *dev, struct iw_param *prq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        int err = 0;
 
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
 
        if (prq->disabled) {
                priv->pm_on = 0;
@@ -2547,33 +2830,34 @@ static int dldwd_ioctl_setpower(struct net_device *dev, struct iw_param *prq)
        }
 
  out:
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        return err;
 }
 
-static int dldwd_ioctl_getpower(struct net_device *dev, struct iw_param *prq)
+static int orinoco_ioctl_getpower(struct net_device *dev, struct iw_param *prq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        hermes_t *hw = &priv->hw;
        int err = 0;
        u16 enable, period, timeout, mcast;
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
        
-       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_ENABLE, &enable);
+       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
        if (err)
                goto out;
 
-       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_PERIOD, &period);
+       err = hermes_read_wordrec(hw, USER_BAP,
+                                 HERMES_RID_CNFMAXSLEEPDURATION, &period);
        if (err)
                goto out;
 
-       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_HOLDOVER, &timeout);
+       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
        if (err)
                goto out;
 
-       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNF_PM_MCAST_RX, &mcast);
+       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
        if (err)
                goto out;
 
@@ -2592,30 +2876,33 @@ static int dldwd_ioctl_getpower(struct net_device *dev, struct iw_param *prq)
                prq->flags |= IW_POWER_UNICAST_R;
 
  out:
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        return err;
 }
 
 #if WIRELESS_EXT > 10
-static int dldwd_ioctl_getretry(struct net_device *dev, struct iw_param *rrq)
+static int orinoco_ioctl_getretry(struct net_device *dev, struct iw_param *rrq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        hermes_t *hw = &priv->hw;
        int err = 0;
        u16 short_limit, long_limit, lifetime;
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
        
-       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORT_RETRY_LIMIT, &short_limit);
+       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
+                                 &short_limit);
        if (err)
                goto out;
 
-       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONG_RETRY_LIMIT, &long_limit);
+       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
+                                 &long_limit);
        if (err)
                goto out;
 
-       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAX_TX_LIFETIME, &lifetime);
+       err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
+                                 &lifetime);
        if (err)
                goto out;
 
@@ -2639,46 +2926,46 @@ static int dldwd_ioctl_getretry(struct net_device *dev, struct iw_param *rrq)
        }
 
  out:
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        return err;
 }
 #endif /* WIRELESS_EXT > 10 */
 
-static int dldwd_ioctl_setibssport(struct net_device *dev, struct iwreq *wrq)
+static int orinoco_ioctl_setibssport(struct net_device *dev, struct iwreq *wrq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        int val = *( (int *) wrq->u.name );
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
        priv->ibss_port = val ;
 
        /* Actually update the mode we are using */
        set_port_type(priv);
 
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
        return 0;
 }
 
-static int dldwd_ioctl_getibssport(struct net_device *dev, struct iwreq *wrq)
+static int orinoco_ioctl_getibssport(struct net_device *dev, struct iwreq *wrq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        int *val = (int *)wrq->u.name;
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
        *val = priv->ibss_port;
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        return 0;
 }
 
-static int dldwd_ioctl_setport3(struct net_device *dev, struct iwreq *wrq)
+static int orinoco_ioctl_setport3(struct net_device *dev, struct iwreq *wrq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        int val = *( (int *) wrq->u.name );
        int err = 0;
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
        switch (val) {
        case 0: /* Try to do IEEE ad-hoc mode */
                if (! priv->has_ibss) {
@@ -2707,28 +2994,28 @@ static int dldwd_ioctl_setport3(struct net_device *dev, struct iwreq *wrq)
                /* Actually update the mode we are using */
                set_port_type(priv);
 
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        return err;
 }
 
-static int dldwd_ioctl_getport3(struct net_device *dev, struct iwreq *wrq)
+static int orinoco_ioctl_getport3(struct net_device *dev, struct iwreq *wrq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        int *val = (int *)wrq->u.name;
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
        *val = priv->prefer_port3;
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        return 0;
 }
 
 /* Spy is used for link quality/strength measurements in Ad-Hoc mode
  * Jean II */
-static int dldwd_ioctl_setspy(struct net_device *dev, struct iw_point *srq)
+static int orinoco_ioctl_setspy(struct net_device *dev, struct iw_point *srq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        struct sockaddr address[IW_MAX_SPY];
        int number = srq->length;
        int i;
@@ -2746,9 +3033,9 @@ static int dldwd_ioctl_setspy(struct net_device *dev, struct iw_point *srq)
        }
 
        /* Make sure nobody mess with the structure while we do */
-       dldwd_lock(priv);
+       orinoco_lock(priv);
 
-       /* dldwd_lock() doesn't disable interrupts, so make sure the
+       /* orinoco_lock() doesn't disable interrupts, so make sure the
         * interrupt rx path don't get confused while we copy */
        priv->spy_number = 0;
 
@@ -2775,20 +3062,20 @@ static int dldwd_ioctl_setspy(struct net_device *dev, struct iw_point *srq)
        }
 
        /* Now, let the others play */
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        return err;
 }
 
-static int dldwd_ioctl_getspy(struct net_device *dev, struct iw_point *srq)
+static int orinoco_ioctl_getspy(struct net_device *dev, struct iw_point *srq)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        struct sockaddr address[IW_MAX_SPY];
        struct iw_quality spy_stat[IW_MAX_SPY];
        int number;
        int i;
 
-       dldwd_lock(priv);
+       orinoco_lock(priv);
 
        number = priv->spy_number;
        if ((number > 0) && (srq->pointer)) {
@@ -2808,7 +3095,7 @@ static int dldwd_ioctl_getspy(struct net_device *dev, struct iw_point *srq)
                        priv->spy_stat[i].updated = 0;
        }
 
-       dldwd_unlock(priv);
+       orinoco_unlock(priv);
 
        /* Push stuff to user space */
        srq->length = number;
@@ -2822,23 +3109,23 @@ static int dldwd_ioctl_getspy(struct net_device *dev, struct iw_point *srq)
        return 0;
 }
 
-int
-dldwd_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
+static int
+orinoco_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 {
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = dev->priv;
        struct iwreq *wrq = (struct iwreq *)rq;
        int err = 0;
        int changed = 0;
 
        TRACE_ENTER(dev->name);
 
-       /* In theory, we could allow most of the the SET stuff to be done
-        * In practice, the laps of time at startup when the card is not
-        * ready is very short, so why bother...
-        * Note that hw_ready is different from up/down (ifconfig), when
-        * the device is not yet up, it is usually already ready...
-        * Jean II */
-       if (!priv->hw_ready)
+       /* In theory, we could allow most of the the SET stuff to be
+        * done In practice, the laps of time at startup when the card
+        * is not ready is very short, so why bother...  Note that
+        * netif_device_present is different from up/down (ifconfig),
+        * when the device is not yet up, it is usually already
+        * ready...  Jean II */
+       if (! netif_device_present(dev))
                return -ENODEV;
 
        switch (cmd) {
@@ -2850,17 +3137,17 @@ dldwd_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        case SIOCGIWAP:
                DEBUG(1, "%s: SIOCGIWAP\n", dev->name);
                wrq->u.ap_addr.sa_family = ARPHRD_ETHER;
-               err = dldwd_hw_get_bssid(priv, wrq->u.ap_addr.sa_data);
+               err = orinoco_hw_get_bssid(priv, wrq->u.ap_addr.sa_data);
                break;
 
        case SIOCGIWRANGE:
                DEBUG(1, "%s: SIOCGIWRANGE\n", dev->name);
-               err = dldwd_ioctl_getiwrange(dev, &wrq->u.data);
+               err = orinoco_ioctl_getiwrange(dev, &wrq->u.data);
                break;
 
        case SIOCSIWMODE:
                DEBUG(1, "%s: SIOCSIWMODE\n", dev->name);
-               dldwd_lock(priv);
+               orinoco_lock(priv);
                switch (wrq->u.mode) {
                case IW_MODE_ADHOC:
                        if (! (priv->has_ibss || priv->has_port3) )
@@ -2881,14 +3168,14 @@ dldwd_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
                        break;
                }
                set_port_type(priv);
-               dldwd_unlock(priv);
+               orinoco_unlock(priv);
                break;
 
        case SIOCGIWMODE:
                DEBUG(1, "%s: SIOCGIWMODE\n", dev->name);
-               dldwd_lock(priv);
+               orinoco_lock(priv);
                wrq->u.mode = priv->iw_mode;
-               dldwd_unlock(priv);
+               orinoco_unlock(priv);
                break;
 
        case SIOCSIWENCODE:
@@ -2898,7 +3185,7 @@ dldwd_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
                        break;
                }
 
-               err = dldwd_ioctl_setiwencode(dev, &wrq->u.encoding);
+               err = orinoco_ioctl_setiwencode(dev, &wrq->u.encoding);
                if (! err)
                        changed = 1;
                break;
@@ -2915,54 +3202,54 @@ dldwd_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
                        break;
                }
 
-               err = dldwd_ioctl_getiwencode(dev, &wrq->u.encoding);
+               err = orinoco_ioctl_getiwencode(dev, &wrq->u.encoding);
                break;
 
        case SIOCSIWESSID:
                DEBUG(1, "%s: SIOCSIWESSID\n", dev->name);
-               err = dldwd_ioctl_setessid(dev, &wrq->u.essid);
+               err = orinoco_ioctl_setessid(dev, &wrq->u.essid);
                if (! err)
                        changed = 1;
                break;
 
        case SIOCGIWESSID:
                DEBUG(1, "%s: SIOCGIWESSID\n", dev->name);
-               err = dldwd_ioctl_getessid(dev, &wrq->u.essid);
+               err = orinoco_ioctl_getessid(dev, &wrq->u.essid);
                break;
 
        case SIOCSIWNICKN:
                DEBUG(1, "%s: SIOCSIWNICKN\n", dev->name);
-               err = dldwd_ioctl_setnick(dev, &wrq->u.data);
+               err = orinoco_ioctl_setnick(dev, &wrq->u.data);
                if (! err)
                        changed = 1;
                break;
 
        case SIOCGIWNICKN:
                DEBUG(1, "%s: SIOCGIWNICKN\n", dev->name);
-               err = dldwd_ioctl_getnick(dev, &wrq->u.data);
+               err = orinoco_ioctl_getnick(dev, &wrq->u.data);
                break;
 
        case SIOCGIWFREQ:
                DEBUG(1, "%s: SIOCGIWFREQ\n", dev->name);
-               wrq->u.freq.m = dldwd_hw_get_freq(priv);
+               wrq->u.freq.m = orinoco_hw_get_freq(priv);
                wrq->u.freq.e = 1;
                break;
 
        case SIOCSIWFREQ:
                DEBUG(1, "%s: SIOCSIWFREQ\n", dev->name);
-               err = dldwd_ioctl_setfreq(dev, &wrq->u.freq);
+               err = orinoco_ioctl_setfreq(dev, &wrq->u.freq);
                if (! err)
                        changed = 1;
                break;
 
        case SIOCGIWSENS:
                DEBUG(1, "%s: SIOCGIWSENS\n", dev->name);
-               err = dldwd_ioctl_getsens(dev, &wrq->u.sens);
+               err = orinoco_ioctl_getsens(dev, &wrq->u.sens);
                break;
 
        case SIOCSIWSENS:
                DEBUG(1, "%s: SIOCSIWSENS\n", dev->name);
-               err = dldwd_ioctl_setsens(dev, &wrq->u.sens);
+               err = orinoco_ioctl_setsens(dev, &wrq->u.sens);
                if (! err)
                        changed = 1;
                break;
@@ -2976,45 +3263,45 @@ dldwd_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 
        case SIOCSIWRTS:
                DEBUG(1, "%s: SIOCSIWRTS\n", dev->name);
-               err = dldwd_ioctl_setrts(dev, &wrq->u.rts);
+               err = orinoco_ioctl_setrts(dev, &wrq->u.rts);
                if (! err)
                        changed = 1;
                break;
 
        case SIOCSIWFRAG:
                DEBUG(1, "%s: SIOCSIWFRAG\n", dev->name);
-               err = dldwd_ioctl_setfrag(dev, &wrq->u.frag);
+               err = orinoco_ioctl_setfrag(dev, &wrq->u.frag);
                if (! err)
                        changed = 1;
                break;
 
        case SIOCGIWFRAG:
                DEBUG(1, "%s: SIOCGIWFRAG\n", dev->name);
-               err = dldwd_ioctl_getfrag(dev, &wrq->u.frag);
+               err = orinoco_ioctl_getfrag(dev, &wrq->u.frag);
                break;
 
        case SIOCSIWRATE:
                DEBUG(1, "%s: SIOCSIWRATE\n", dev->name);
-               err = dldwd_ioctl_setrate(dev, &wrq->u.bitrate);
+               err = orinoco_ioctl_setrate(dev, &wrq->u.bitrate);
                if (! err)
                        changed = 1;
                break;
 
        case SIOCGIWRATE:
                DEBUG(1, "%s: SIOCGIWRATE\n", dev->name);
-               err = dldwd_ioctl_getrate(dev, &wrq->u.bitrate);
+               err = orinoco_ioctl_getrate(dev, &wrq->u.bitrate);
                break;
 
        case SIOCSIWPOWER:
                DEBUG(1, "%s: SIOCSIWPOWER\n", dev->name);
-               err = dldwd_ioctl_setpower(dev, &wrq->u.power);
+               err = orinoco_ioctl_setpower(dev, &wrq->u.power);
                if (! err)
                        changed = 1;
                break;
 
        case SIOCGIWPOWER:
                DEBUG(1, "%s: SIOCGIWPOWER\n", dev->name);
-               err = dldwd_ioctl_getpower(dev, &wrq->u.power);
+               err = orinoco_ioctl_getpower(dev, &wrq->u.power);
                break;
 
        case SIOCGIWTXPOW:
@@ -3034,44 +3321,44 @@ dldwd_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 
        case SIOCGIWRETRY:
                DEBUG(1, "%s: SIOCGIWRETRY\n", dev->name);
-               err = dldwd_ioctl_getretry(dev, &wrq->u.retry);
+               err = orinoco_ioctl_getretry(dev, &wrq->u.retry);
                break;
 #endif /* WIRELESS_EXT > 10 */
 
        case SIOCSIWSPY:
                DEBUG(1, "%s: SIOCSIWSPY\n", dev->name);
 
-               err = dldwd_ioctl_setspy(dev, &wrq->u.data);
+               err = orinoco_ioctl_setspy(dev, &wrq->u.data);
                break;
 
        case SIOCGIWSPY:
                DEBUG(1, "%s: SIOCGIWSPY\n", dev->name);
 
-               err = dldwd_ioctl_getspy(dev, &wrq->u.data);
+               err = orinoco_ioctl_getspy(dev, &wrq->u.data);
                break;
 
        case SIOCGIWPRIV:
                DEBUG(1, "%s: SIOCGIWPRIV\n", dev->name);
                if (wrq->u.data.pointer) {
                        struct iw_priv_args privtab[] = {
-                               { SIOCDEVPRIVATE + 0x0, 0, 0, "force_reset" },
-                               { SIOCDEVPRIVATE + 0x1, 0, 0, "card_reset" },
-                               { SIOCDEVPRIVATE + 0x2,
+                               { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
+                               { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
+                               { SIOCIWFIRSTPRIV + 0x2,
                                  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
                                  0, "set_port3" },
-                               { SIOCDEVPRIVATE + 0x3, 0,
+                               { SIOCIWFIRSTPRIV + 0x3, 0,
                                  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
                                  "get_port3" },
-                               { SIOCDEVPRIVATE + 0x4,
+                               { SIOCIWFIRSTPRIV + 0x4,
                                  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
                                  0, "set_preamble" },
-                               { SIOCDEVPRIVATE + 0x5, 0,
+                               { SIOCIWFIRSTPRIV + 0x5, 0,
                                  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
                                  "get_preamble" },
-                               { SIOCDEVPRIVATE + 0x6,
+                               { SIOCIWFIRSTPRIV + 0x6,
                                  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
                                  0, "set_ibssport" },
-                               { SIOCDEVPRIVATE + 0x7, 0,
+                               { SIOCIWFIRSTPRIV + 0x7, 0,
                                  IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
                                  "get_ibssport" }
                        };
@@ -3086,8 +3373,9 @@ dldwd_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
                }
                break;
               
-       case SIOCDEVPRIVATE + 0x0: /* force_reset */
-               DEBUG(1, "%s: SIOCDEVPRIVATE + 0x0 (force_reset)\n",
+       case SIOCIWFIRSTPRIV + 0x0: /* force_reset */
+       case SIOCIWFIRSTPRIV + 0x1: /* card_reset */
+               DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x0 (force_reset)\n",
                      dev->name);
                if (! capable(CAP_NET_ADMIN)) {
                        err = -EPERM;
@@ -3095,44 +3383,35 @@ dldwd_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
                }
                
                printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
-               dldwd_reset(priv);
-               break;
 
-       case SIOCDEVPRIVATE + 0x1: /* card_reset */
-               DEBUG(1, "%s: SIOCDEVPRIVATE + 0x1 (card_reset)\n",
-                     dev->name);
-               if (! capable(CAP_NET_ADMIN)) {
-                       err = -EPERM;
-                       break;
-               }
-               
-               printk(KERN_DEBUG "%s: Forcing card reset!\n", dev->name);
-               if(priv->card_reset_handler != NULL)
-                       priv->card_reset_handler(priv);
-               dldwd_reset(priv);
+               /* We need the xmit lock because it protects the
+                  multicast list which orinoco_reset() reads */
+               spin_lock_bh(&dev->xmit_lock);
+               orinoco_reset(priv);
+               spin_unlock_bh(&dev->xmit_lock);
                break;
 
-       case SIOCDEVPRIVATE + 0x2: /* set_port3 */
-               DEBUG(1, "%s: SIOCDEVPRIVATE + 0x2 (set_port3)\n",
+       case SIOCIWFIRSTPRIV + 0x2: /* set_port3 */
+               DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x2 (set_port3)\n",
                      dev->name);
                if (! capable(CAP_NET_ADMIN)) {
                        err = -EPERM;
                        break;
                }
 
-               err = dldwd_ioctl_setport3(dev, wrq);
+               err = orinoco_ioctl_setport3(dev, wrq);
                if (! err)
                        changed = 1;
                break;
 
-       case SIOCDEVPRIVATE + 0x3: /* get_port3 */
-               DEBUG(1, "%s: SIOCDEVPRIVATE + 0x3 (get_port3)\n",
+       case SIOCIWFIRSTPRIV + 0x3: /* get_port3 */
+               DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x3 (get_port3)\n",
                      dev->name);
-               err = dldwd_ioctl_getport3(dev, wrq);
+               err = orinoco_ioctl_getport3(dev, wrq);
                break;
 
-       case SIOCDEVPRIVATE + 0x4: /* set_preamble */
-               DEBUG(1, "%s: SIOCDEVPRIVATE + 0x4 (set_preamble)\n",
+       case SIOCIWFIRSTPRIV + 0x4: /* set_preamble */
+               DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x4 (set_preamble)\n",
                      dev->name);
                if (! capable(CAP_NET_ADMIN)) {
                        err = -EPERM;
@@ -3147,46 +3426,46 @@ dldwd_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
                if(priv->has_preamble) {
                        int val = *( (int *) wrq->u.name );
 
-                       dldwd_lock(priv);
+                       orinoco_lock(priv);
                        if(val)
                                priv->preamble = 1;
                        else
                                priv->preamble = 0;
-                       dldwd_unlock(priv);
+                       orinoco_unlock(priv);
                        changed = 1;
                } else
                        err = -EOPNOTSUPP;
                break;
 
-       case SIOCDEVPRIVATE + 0x5: /* get_preamble */
-               DEBUG(1, "%s: SIOCDEVPRIVATE + 0x5 (get_preamble)\n",
+       case SIOCIWFIRSTPRIV + 0x5: /* get_preamble */
+               DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x5 (get_preamble)\n",
                      dev->name);
                if(priv->has_preamble) {
                        int *val = (int *)wrq->u.name;
 
-                       dldwd_lock(priv);
+                       orinoco_lock(priv);
                        *val = priv->preamble;
-                       dldwd_unlock(priv);
+                       orinoco_unlock(priv);
                } else
                        err = -EOPNOTSUPP;
                break;
-       case SIOCDEVPRIVATE + 0x6: /* set_ibssport */
-               DEBUG(1, "%s: SIOCDEVPRIVATE + 0x6 (set_ibssport)\n",
+       case SIOCIWFIRSTPRIV + 0x6: /* set_ibssport */
+               DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x6 (set_ibssport)\n",
                      dev->name);
                if (! capable(CAP_NET_ADMIN)) {
                        err = -EPERM;
                        break;
                }
 
-               err = dldwd_ioctl_setibssport(dev, wrq);
+               err = orinoco_ioctl_setibssport(dev, wrq);
                if (! err)
                        changed = 1;
                break;
 
-       case SIOCDEVPRIVATE + 0x7: /* get_ibssport */
-               DEBUG(1, "%s: SIOCDEVPRIVATE + 0x7 (get_ibssport)\n",
+       case SIOCIWFIRSTPRIV + 0x7: /* get_ibssport */
+               DEBUG(1, "%s: SIOCIWFIRSTPRIV + 0x7 (get_ibssport)\n",
                      dev->name);
-               err = dldwd_ioctl_getibssport(dev, wrq);
+               err = orinoco_ioctl_getibssport(dev, wrq);
                break;
 
 
@@ -3195,14 +3474,17 @@ dldwd_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        }
        
        if (! err && changed && netif_running(dev)) {
-               err = dldwd_reset(priv);
+               /* We need the xmit lock because it protects the
+                  multicast list which orinoco_reset() reads */
+               spin_lock_bh(&dev->xmit_lock);
+               err = orinoco_reset(priv);
+               spin_unlock_bh(&dev->xmit_lock);
                if (err) {
                        /* Ouch ! What are we supposed to do ? */
                        printk(KERN_ERR "orinoco_cs: Failed to set parameters on %s\n",
                               dev->name);
-                       netif_stop_queue(dev);
-                       dldwd_shutdown(priv);
-                       priv->hw_ready = 0;
+                       netif_device_detach(dev);
+                       orinoco_shutdown(priv);
                }
        }               
 
@@ -3211,147 +3493,14 @@ dldwd_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        return err;
 }
 
-int
-dldwd_change_mtu(struct net_device *dev, int new_mtu)
-{
-       TRACE_ENTER(dev->name);
-
-       if ( (new_mtu < DLDWD_MIN_MTU) || (new_mtu > DLDWD_MAX_MTU) )
-               return -EINVAL;
-
-       dev->mtu = new_mtu;
-
-       TRACE_EXIT(dev->name);
-
-       return 0;
-}
-
-static void
-__dldwd_set_multicast_list(struct net_device *dev)
-{
-       dldwd_priv_t *priv = dev->priv;
-       hermes_t *hw = &priv->hw;
-       int err = 0;
-       int promisc, allmulti, mc_count;
-
-       /* We'll wait until it's ready. Anyway, the network doesn't call us
-        * here until we are open - Jean II */
-       if (!priv->hw_ready)
-               return;
-
-
-       TRACE_ENTER(dev->name);
-
-       DEBUG(3, "dev->flags=0x%x, priv->promiscuous=%d, dev->mc_count=%d priv->mc_count=%d\n",
-             dev->flags, priv->promiscuous, dev->mc_count, priv->mc_count);
-
-       /* The Hermes doesn't seem to have an allmulti mode, so we go
-        * into promiscuous mode and let the upper levels deal. */
-       if ( (dev->flags & IFF_PROMISC) ) {
-               promisc = 1;
-               allmulti = 0;
-               mc_count = 0;
-       } else if ( (dev->flags & IFF_ALLMULTI) ||
-                   (dev->mc_count > HERMES_MAX_MULTICAST) ) {
-               promisc = 0;
-               allmulti = 1;
-               mc_count = HERMES_MAX_MULTICAST;
-       } else {
-               promisc = 0;
-               allmulti = 0;
-               mc_count = dev->mc_count;
-       }
-
-       DEBUG(3, "promisc=%d mc_count=%d\n",
-             promisc, mc_count);
-
-       if (promisc != priv->promiscuous) { /* Don't touch the hardware if we don't have to */
-               err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNF_PROMISCUOUS,
-                                          promisc);
-               if (err) {
-                       printk(KERN_ERR "%s: Error %d setting promiscuity to %d.\n",
-                              dev->name, err, promisc);
-               } else 
-                       priv->promiscuous = promisc;
-       }
-
-       if (allmulti) {
-               /* FIXME: This method of doing allmulticast reception
-                  comes from the NetBSD driver. Haven't actually
-                  tested whether it works or not. */
-               hermes_multicast_t mclist;
-
-               memset(&mclist, 0, sizeof(mclist));
-               err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNF_MULTICAST_LIST, &mclist);
-               if (err)
-                       printk(KERN_ERR "%s: Error %d setting multicast list.\n",
-                              dev->name, err);
-               else
-                       priv->allmulti = 1;
-                      
-       } else if (mc_count || (! mc_count && priv->mc_count) ) {
-               struct dev_mc_list *p = dev->mc_list;
-               hermes_multicast_t mclist;
-               int i;
-
-               for (i = 0; i < mc_count; i++) {
-                       /* First some paranoid checks */
-                       if (! p) {
-                               printk(KERN_ERR "%s: Multicast list shorter than mc_count.\n",
-                                      dev->name);
-                               break;
-                       }
-                       if (p->dmi_addrlen != ETH_ALEN) {
-
-                               printk(KERN_ERR "%s: Bad address size (%d) in multicast list.\n",
-                                      dev->name, p->dmi_addrlen);
-                               break;
-                       }
-
-                       memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
-                       p = p->next;
-               }
-
-               /* More paranoia */
-               if (p)
-                       printk(KERN_ERR "%s: Multicast list longer than mc_count.\n",
-                              dev->name);
-
-               priv->mc_count = i;                     
-
-               DEBUG(3, "priv->mc_count = %d\n", priv->mc_count);
-
-               err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNF_MULTICAST_LIST,
-                                      HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
-                                      &mclist);
-               if (err)
-                       printk(KERN_ERR "%s: Error %d setting multicast list.\n",
-                              dev->name, err);
-               else
-                       priv->allmulti = 0;
-       }
-
-       /* Since we can set the promiscuous flag when it wasn't asked
-          for, make sure the net_device knows about it. */
-       if (priv->promiscuous)
-               dev->flags |= IFF_PROMISC;
-       else
-               dev->flags &= ~IFF_PROMISC;
-
-       if (priv->allmulti)
-               dev->flags |= IFF_ALLMULTI;
-       else
-               dev->flags &= ~IFF_ALLMULTI;
-
-       TRACE_EXIT(dev->name);
-}
-
-/*
- * procfs stuff
- */
+/********************************************************************/
+/* procfs stuff                                                     */
+/********************************************************************/
 
 static struct proc_dir_entry *dir_base = NULL;
 
+#define PROC_LTV_SIZE          128
+
 /*
  * This function updates the total amount of data printed so far. It then
  * determines if the amount of data printed into a buffer  has reached the
@@ -3361,7 +3510,6 @@ static struct proc_dir_entry *dir_base = NULL;
  * function returns 1, otherwise 0.
  */
 static int 
-
 shift_buffer(char *buffer, int requested_offset, int requested_len,
             int *total, int *slop, char **buf)
 {
@@ -3420,153 +3568,161 @@ calc_start_len(char *buffer, char **start, int requested_offset,
        return return_len;
 }
 
-static int
-dldwd_proc_get_hermes_regs(char *page, char **start, off_t requested_offset,
-                          int requested_len, int *eof, void *data)
-{
-       dldwd_priv_t *dev = (dldwd_priv_t *)data;
-       hermes_t *hw = &dev->hw;
-       char *buf;
-       int total = 0, slop = 0;
-
-       /* Hum, in this case hardware register are probably not readable... */
-       if (!dev->hw_ready)
-               return -ENODEV;
-
-       buf = page;
-
-#define DHERMESREG(name) buf += sprintf(buf, "%-16s: %04x\n", #name, hermes_read_regn(hw, name))
-
-       DHERMESREG(CMD);
-       DHERMESREG(PARAM0);
-       DHERMESREG(PARAM1);
-       DHERMESREG(PARAM2);
-       DHERMESREG(STATUS);
-       DHERMESREG(RESP0);
-       DHERMESREG(RESP1);
-       DHERMESREG(RESP2);
-       DHERMESREG(INFOFID);
-       DHERMESREG(RXFID);
-       DHERMESREG(ALLOCFID);
-       DHERMESREG(TXCOMPLFID);
-       DHERMESREG(SELECT0);
-       DHERMESREG(OFFSET0);
-       DHERMESREG(SELECT1);
-       DHERMESREG(OFFSET1);
-       DHERMESREG(EVSTAT);
-       DHERMESREG(INTEN);
-       DHERMESREG(EVACK);
-       DHERMESREG(CONTROL);
-       DHERMESREG(SWSUPPORT0);
-       DHERMESREG(SWSUPPORT1);
-       DHERMESREG(SWSUPPORT2);
-       DHERMESREG(AUXPAGE);
-       DHERMESREG(AUXOFFSET);
-       DHERMESREG(AUXDATA);
-#undef DHERMESREG
-
-       shift_buffer(page, requested_offset, requested_len, &total,
-                    &slop, &buf);
-       return calc_start_len(page, start, requested_offset, requested_len,
-                             total, buf);
-}
-
 struct {
        u16 rid;
        char *name;
-       int minlen, maxlen;
        int displaytype;
 #define DISPLAY_WORDS  0
 #define DISPLAY_BYTES  1
 #define DISPLAY_STRING 2
+#define DISPLAY_XSTRING        3
 } record_table[] = {
-#define RTCNFENTRY(name, type) { HERMES_RID_CNF_##name, #name, 0, LTV_BUF_SIZE, type }
-       RTCNFENTRY(PORTTYPE, DISPLAY_WORDS),
-       RTCNFENTRY(MACADDR, DISPLAY_BYTES),
-       RTCNFENTRY(DESIRED_SSID, DISPLAY_STRING),
-       RTCNFENTRY(CHANNEL, DISPLAY_WORDS),
-       RTCNFENTRY(OWN_SSID, DISPLAY_STRING),
-       RTCNFENTRY(SYSTEM_SCALE, DISPLAY_WORDS),
-       RTCNFENTRY(MAX_DATA_LEN, DISPLAY_WORDS),
-       RTCNFENTRY(PM_ENABLE, DISPLAY_WORDS),
-       RTCNFENTRY(PM_MCAST_RX, DISPLAY_WORDS),
-       RTCNFENTRY(PM_PERIOD, DISPLAY_WORDS),
-       RTCNFENTRY(NICKNAME, DISPLAY_STRING),
-       RTCNFENTRY(WEP_ON, DISPLAY_WORDS),
-       RTCNFENTRY(MWO_ROBUST, DISPLAY_WORDS),
-       RTCNFENTRY(MULTICAST_LIST, DISPLAY_BYTES),
-       RTCNFENTRY(CREATEIBSS, DISPLAY_WORDS),
-       RTCNFENTRY(FRAG_THRESH, DISPLAY_WORDS),
-       RTCNFENTRY(RTS_THRESH, DISPLAY_WORDS),
-       RTCNFENTRY(TX_RATE_CTRL, DISPLAY_WORDS),
-       RTCNFENTRY(PROMISCUOUS, DISPLAY_WORDS),
-       RTCNFENTRY(KEYS, DISPLAY_BYTES),
-       RTCNFENTRY(TX_KEY, DISPLAY_WORDS),
-       RTCNFENTRY(TICKTIME, DISPLAY_WORDS),
-       RTCNFENTRY(INTERSIL_TX_KEY, DISPLAY_WORDS),
-       RTCNFENTRY(INTERSIL_KEY0, DISPLAY_BYTES),
-       RTCNFENTRY(INTERSIL_KEY1, DISPLAY_BYTES),
-       RTCNFENTRY(INTERSIL_KEY2, DISPLAY_BYTES),
-       RTCNFENTRY(INTERSIL_KEY3, DISPLAY_BYTES),
-       RTCNFENTRY(INTERSIL_WEP_ON, DISPLAY_WORDS),
-#undef RTCNFENTRY
-#define RTINFENTRY(name,type) { HERMES_RID_##name, #name, 0, LTV_BUF_SIZE, type }
-       RTINFENTRY(CHANNEL_LIST, DISPLAY_WORDS),
-       RTINFENTRY(STAIDENTITY, DISPLAY_WORDS),
-       RTINFENTRY(CURRENT_SSID, DISPLAY_STRING),
-       RTINFENTRY(CURRENT_BSSID, DISPLAY_BYTES),
-       RTINFENTRY(COMMSQUALITY, DISPLAY_WORDS),
-       RTINFENTRY(CURRENT_TX_RATE, DISPLAY_WORDS),
-       RTINFENTRY(WEP_AVAIL, DISPLAY_WORDS),
-       RTINFENTRY(CURRENT_CHANNEL, DISPLAY_WORDS),
-       RTINFENTRY(DATARATES, DISPLAY_BYTES),
-#undef RTINFENTRY
+#define PROC_REC(name,type) { HERMES_RID_##name, #name, DISPLAY_##type }
+       PROC_REC(CNFPORTTYPE,WORDS),
+       PROC_REC(CNFOWNMACADDR,BYTES),
+       PROC_REC(CNFDESIREDSSID,STRING),
+       PROC_REC(CNFOWNCHANNEL,WORDS),
+       PROC_REC(CNFOWNSSID,STRING),
+       PROC_REC(CNFOWNATIMWINDOW,WORDS),
+       PROC_REC(CNFSYSTEMSCALE,WORDS),
+       PROC_REC(CNFMAXDATALEN,WORDS),
+       PROC_REC(CNFPMENABLED,WORDS),
+       PROC_REC(CNFPMEPS,WORDS),
+       PROC_REC(CNFMULTICASTRECEIVE,WORDS),
+       PROC_REC(CNFMAXSLEEPDURATION,WORDS),
+       PROC_REC(CNFPMHOLDOVERDURATION,WORDS),
+       PROC_REC(CNFOWNNAME,STRING),
+       PROC_REC(CNFOWNDTIMPERIOD,WORDS),
+       PROC_REC(CNFMULTICASTPMBUFFERING,WORDS),
+       PROC_REC(CNFWEPENABLED_AGERE,WORDS),
+       PROC_REC(CNFMANDATORYBSSID_SYMBOL,WORDS),
+       PROC_REC(CNFWEPDEFAULTKEYID,WORDS),
+       PROC_REC(CNFDEFAULTKEY0,BYTES),
+       PROC_REC(CNFDEFAULTKEY1,BYTES),
+       PROC_REC(CNFMWOROBUST_AGERE,WORDS),
+       PROC_REC(CNFDEFAULTKEY2,BYTES),
+       PROC_REC(CNFDEFAULTKEY3,BYTES),
+       PROC_REC(CNFWEPFLAGS_INTERSIL,WORDS),
+       PROC_REC(CNFWEPKEYMAPPINGTABLE,WORDS),
+       PROC_REC(CNFAUTHENTICATION,WORDS),
+       PROC_REC(CNFMAXASSOCSTA,WORDS),
+       PROC_REC(CNFKEYLENGTH_SYMBOL,WORDS),
+       PROC_REC(CNFTXCONTROL,WORDS),
+       PROC_REC(CNFROAMINGMODE,WORDS),
+       PROC_REC(CNFHOSTAUTHENTICATION,WORDS),
+       PROC_REC(CNFRCVCRCERROR,WORDS),
+       PROC_REC(CNFMMLIFE,WORDS),
+       PROC_REC(CNFALTRETRYCOUNT,WORDS),
+       PROC_REC(CNFBEACONINT,WORDS),
+       PROC_REC(CNFAPPCFINFO,WORDS),
+       PROC_REC(CNFSTAPCFINFO,WORDS),
+       PROC_REC(CNFPRIORITYQUSAGE,WORDS),
+       PROC_REC(CNFTIMCTRL,WORDS),
+       PROC_REC(CNFTHIRTY2TALLY,WORDS),
+       PROC_REC(CNFENHSECURITY,WORDS),
+       PROC_REC(CNFGROUPADDRESSES,BYTES),
+       PROC_REC(CNFCREATEIBSS,WORDS),
+       PROC_REC(CNFFRAGMENTATIONTHRESHOLD,WORDS),
+       PROC_REC(CNFRTSTHRESHOLD,WORDS),
+       PROC_REC(CNFTXRATECONTROL,WORDS),
+       PROC_REC(CNFPROMISCUOUSMODE,WORDS),
+       PROC_REC(CNFBASICRATES_SYMBOL,WORDS),
+       PROC_REC(CNFPREAMBLE_SYMBOL,WORDS),
+       PROC_REC(CNFSHORTPREAMBLE,WORDS),
+       PROC_REC(CNFWEPKEYS_AGERE,BYTES),
+       PROC_REC(CNFEXCLUDELONGPREAMBLE,WORDS),
+       PROC_REC(CNFTXKEY_AGERE,WORDS),
+       PROC_REC(CNFAUTHENTICATIONRSPTO,WORDS),
+       PROC_REC(CNFBASICRATES,WORDS),
+       PROC_REC(CNFSUPPORTEDRATES,WORDS),
+       PROC_REC(CNFTICKTIME,WORDS),
+       PROC_REC(CNFSCANREQUEST,WORDS),
+       PROC_REC(CNFJOINREQUEST,WORDS),
+       PROC_REC(CNFAUTHENTICATESTATION,WORDS),
+       PROC_REC(CNFCHANNELINFOREQUEST,WORDS),
+       PROC_REC(MAXLOADTIME,WORDS),
+       PROC_REC(DOWNLOADBUFFER,WORDS),
+       PROC_REC(PRIID,WORDS),
+       PROC_REC(PRISUPRANGE,WORDS),
+       PROC_REC(CFIACTRANGES,WORDS),
+       PROC_REC(NICSERNUM,WORDS),
+       PROC_REC(NICID,WORDS),
+       PROC_REC(MFISUPRANGE,WORDS),
+       PROC_REC(CFISUPRANGE,WORDS),
+       PROC_REC(CHANNELLIST,WORDS),
+       PROC_REC(REGULATORYDOMAINS,WORDS),
+       PROC_REC(TEMPTYPE,WORDS),
+/*     PROC_REC(CIS,BYTES), */
+       PROC_REC(STAID,WORDS),
+       PROC_REC(CURRENTSSID,STRING),
+       PROC_REC(CURRENTBSSID,BYTES),
+       PROC_REC(COMMSQUALITY,WORDS),
+       PROC_REC(CURRENTTXRATE,WORDS),
+       PROC_REC(CURRENTBEACONINTERVAL,WORDS),
+       PROC_REC(CURRENTSCALETHRESHOLDS,WORDS),
+       PROC_REC(PROTOCOLRSPTIME,WORDS),
+       PROC_REC(SHORTRETRYLIMIT,WORDS),
+       PROC_REC(LONGRETRYLIMIT,WORDS),
+       PROC_REC(MAXTRANSMITLIFETIME,WORDS),
+       PROC_REC(MAXRECEIVELIFETIME,WORDS),
+       PROC_REC(CFPOLLABLE,WORDS),
+       PROC_REC(AUTHENTICATIONALGORITHMS,WORDS),
+       PROC_REC(PRIVACYOPTIONIMPLEMENTED,WORDS),
+       PROC_REC(OWNMACADDR,BYTES),
+       PROC_REC(SCANRESULTSTABLE,WORDS),
+       PROC_REC(PHYTYPE,WORDS),
+       PROC_REC(CURRENTCHANNEL,WORDS),
+       PROC_REC(CURRENTPOWERSTATE,WORDS),
+       PROC_REC(CCAMODE,WORDS),
+       PROC_REC(SUPPORTEDDATARATES,WORDS),
+       PROC_REC(BUILDSEQ,BYTES),
+       PROC_REC(FWID,XSTRING)
+#undef PROC_REC
 };
 #define NUM_RIDS ( sizeof(record_table) / sizeof(record_table[0]) )
 
 static int
-dldwd_proc_get_hermes_recs(char *page, char **start, off_t requested_offset,
+orinoco_proc_get_hermes_recs(char *page, char **start, off_t requested_offset,
                           int requested_len, int *eof, void *data)
 {
-       dldwd_priv_t *dev = (dldwd_priv_t *)data;
-       hermes_t *hw = &dev->hw;
-       char *buf;
+       struct orinoco_private *priv = (struct orinoco_private *)data;
+       struct net_device *dev = priv->ndev;
+       hermes_t *hw = &priv->hw;
+       char *buf = page;
        int total = 0, slop = 0;
-       int i;
+       u8 *val8;
+       u16 *val16;
+       int i,j;
        u16 length;
        int err;
 
-       /* Hum, in this case hardware register are probably not readable... */
-       if (!dev->hw_ready)
+       if (! netif_device_present(dev))
                return -ENODEV;
-               
-       buf = page;
 
-       /* print out all the config RIDs */
+       val8 = kmalloc(PROC_LTV_SIZE + 2, GFP_KERNEL);
+       if (! val8)
+               return -ENOMEM;
+       val16 = (u16 *)val8;
+
        for (i = 0; i < NUM_RIDS; i++) {
                u16 rid = record_table[i].rid;
-               int minlen = record_table[i].minlen;
-               int maxlen = record_table[i].maxlen;
                int len;
-               u8 *val8;
-               u16 *val16;
-               int j;
 
-               val8 = kmalloc(maxlen + 2, GFP_KERNEL);
-               if (! val8)
-                       return -ENOMEM;
+               memset(val8, 0, PROC_LTV_SIZE + 2);
 
-               err = hermes_read_ltv(hw, USER_BAP, rid, maxlen,
+               err = hermes_read_ltv(hw, USER_BAP, rid, PROC_LTV_SIZE,
                                      &length, val8);
                if (err) {
                        DEBUG(0, "Error %d reading RID 0x%04x\n", err, rid);
                        continue;
                }
                val16 = (u16 *)val8;
+               if (length == 0)
+                       continue;
 
                buf += sprintf(buf, "%-15s (0x%04x): length=%d (%d bytes)\tvalue=", record_table[i].name,
                               rid, length, (length-1)*2);
-               len = min( (int)max(minlen, ((int)length-1)*2), maxlen);
+               len = min(((int)length-1)*2, PROC_LTV_SIZE);
 
                switch (record_table[i].displaytype) {
                case DISPLAY_WORDS:
@@ -3589,11 +3745,67 @@ dldwd_proc_get_hermes_recs(char *page, char **start, off_t requested_offset,
                        val8[len] = '\0';
                        buf += sprintf(buf, "\"%s\"", (char *)&val16[1]);
                        break;
+
+               case DISPLAY_XSTRING:
+                       buf += sprintf(buf, "'%s'", (char *)val8);
                }
 
                buf += sprintf(buf, "\n");
 
-               kfree(val8);
+               if (shift_buffer(page, requested_offset, requested_len,
+                                &total, &slop, &buf))
+                       break;
+
+               if ( (buf - page) > PROC_SAFE_SIZE )
+                       break;
+       }
+
+       kfree(val8);
+
+       return calc_start_len(page, start, requested_offset, requested_len,
+                             total, buf);
+}
+
+#ifdef HERMES_DEBUG_BUFFER
+static int
+orinoco_proc_get_hermes_buf(char *page, char **start, off_t requested_offset,
+                           int requested_len, int *eof, void *data)
+{
+       struct orinoco_private *priv = (struct orinoco_private *)data;
+       hermes_t *hw = &priv->hw;
+       char *buf = page;
+       int total = 0, slop = 0;
+       int i;
+
+       for (i = 0; i < min_t(int,hw->dbufp, HERMES_DEBUG_BUFSIZE); i++) {
+               memcpy(buf, &hw->dbuf[i], sizeof(hw->dbuf[i]));
+               buf += sizeof(hw->dbuf[i]);
+
+               if (shift_buffer(page, requested_offset, requested_len,
+                                &total, &slop, &buf))
+                       break;
+
+               if ( (buf - page) > PROC_SAFE_SIZE )
+                       break;
+       }
+
+       return calc_start_len(page, start, requested_offset, requested_len,
+                             total, buf);
+}
+
+static int
+orinoco_proc_get_hermes_prof(char *page, char **start, off_t requested_offset,
+                           int requested_len, int *eof, void *data)
+{
+       struct orinoco_private *priv = (struct orinoco_private *)data;
+       hermes_t *hw = &priv->hw;
+       char *buf = page;
+       int total = 0, slop = 0;
+       int i;
+
+       for (i = 0; i < (HERMES_BAP_BUSY_TIMEOUT+1); i++) {
+               memcpy(buf, &hw->profile[i], sizeof(hw->profile[i]));
+               buf += sizeof(hw->profile[i]);
 
                if (shift_buffer(page, requested_offset, requested_len,
                                 &total, &slop, &buf))
@@ -3606,161 +3818,165 @@ dldwd_proc_get_hermes_recs(char *page, char **start, off_t requested_offset,
        return calc_start_len(page, start, requested_offset, requested_len,
                              total, buf);
 }
+#endif /* HERMES_DEBUG_BUFFER */
 
 /* initialise the /proc subsystem for the hermes driver, creating the
  * separate entries */
 static int
-dldwd_proc_init(void)
+orinoco_proc_init(void)
 {
        int err = 0;
 
-       TRACE_ENTER("dldwd");
+       TRACE_ENTER("orinoco");
 
        /* create the directory for it to sit in */
        dir_base = create_proc_entry("hermes", S_IFDIR, &proc_root);
        if (dir_base == NULL) {
                printk(KERN_ERR "Unable to initialise /proc/hermes.\n");
-               dldwd_proc_cleanup();
+               orinoco_proc_cleanup();
                err = -ENOMEM;
        }
 
-       TRACE_EXIT("dldwd");
+       TRACE_EXIT("orinoco");
 
        return err;
 }
 
 int
-dldwd_proc_dev_init(dldwd_priv_t *dev)
+orinoco_proc_dev_init(struct orinoco_private *priv)
 {
-       struct net_device *ndev = &dev->ndev;
+       struct net_device *dev = priv->ndev;
+       struct proc_dir_entry *e;
+
+       priv->dir_dev = NULL;
 
-       dev->dir_dev = NULL;
        /* create the directory for it to sit in */
-       dev->dir_dev = create_proc_entry(ndev->name, S_IFDIR | S_IRUGO | S_IXUGO,
-                                        dir_base);
-       if (dev->dir_dev == NULL) {
-               printk(KERN_ERR "Unable to initialise /proc/hermes/%s.\n",  ndev->name);
+       priv->dir_dev = create_proc_entry(dev->name, S_IFDIR | S_IRUGO | S_IXUGO,
+                                         dir_base);
+       if (! priv->dir_dev) {
+               printk(KERN_ERR "Unable to initialize /proc/hermes/%s\n",  dev->name);
+               goto fail;
+       }
+
+       e = create_proc_read_entry("recs", S_IFREG | S_IRUGO,
+                              priv->dir_dev, orinoco_proc_get_hermes_recs, priv);
+       if (! e) {
+               printk(KERN_ERR "Unable to initialize /proc/hermes/%s/recs\n",  dev->name);
                goto fail;
        }
 
-       dev->dir_regs = NULL;
-       dev->dir_regs = create_proc_read_entry("regs", S_IFREG | S_IRUGO,
-                                              dev->dir_dev, dldwd_proc_get_hermes_regs, dev);
-       if (dev->dir_regs == NULL) {
-               printk(KERN_ERR "Unable to initialise /proc/hermes/%s/regs.\n",  ndev->name);
+#ifdef HERMES_DEBUG_BUFFER
+       e = create_proc_read_entry("buf", S_IFREG | S_IRUGO,
+                                              priv->dir_dev, orinoco_proc_get_hermes_buf, priv);
+       if (! e) {
+               printk(KERN_ERR "Unable to intialize /proc/hermes/%s/buf\n", dev->name);
                goto fail;
        }
 
-       dev->dir_recs = NULL;
-       dev->dir_recs = create_proc_read_entry("recs", S_IFREG | S_IRUGO,
-                                              dev->dir_dev, dldwd_proc_get_hermes_recs, dev);
-       if (dev->dir_recs == NULL) {
-               printk(KERN_ERR "Unable to initialise /proc/hermes/%s/recs.\n",  ndev->name);
+       e = create_proc_read_entry("prof", S_IFREG | S_IRUGO,
+                                              priv->dir_dev, orinoco_proc_get_hermes_prof, priv);
+       if (! e) {
+               printk(KERN_ERR "Unable to intialize /proc/hermes/%s/prof\n", dev->name);
                goto fail;
        }
+#endif /* HERMES_DEBUG_BUFFER */
 
        return 0;
  fail:
-       dldwd_proc_dev_cleanup(dev);
+       orinoco_proc_dev_cleanup(priv);
        return -ENOMEM;
 }
 
 void
-dldwd_proc_dev_cleanup(dldwd_priv_t *priv)
+orinoco_proc_dev_cleanup(struct orinoco_private *priv)
 {
-       struct net_device *ndev = &priv->ndev;
+       struct net_device *dev = priv->ndev;
+
+       TRACE_ENTER(priv->ndev->name);
 
-       if (priv->dir_regs) {
-               remove_proc_entry("regs", priv->dir_dev);
-               priv->dir_regs = NULL;
-       }               
-       if (priv->dir_recs) {
-               remove_proc_entry("recs", priv->dir_dev);
-               priv->dir_recs = NULL;
-       }               
        if (priv->dir_dev) {
-               remove_proc_entry(ndev->name, dir_base);
+               remove_proc_entry("prof", priv->dir_dev);
+               remove_proc_entry("buf", priv->dir_dev);
+               remove_proc_entry("recs", priv->dir_dev);
+               remove_proc_entry(dev->name, dir_base);
                priv->dir_dev = NULL;
        }
+
+       TRACE_EXIT(priv->ndev->name);
 }
 
 static void
-dldwd_proc_cleanup(void)
+orinoco_proc_cleanup(void)
 {
-       TRACE_ENTER("dldwd");
+       TRACE_ENTER("orinoco");
 
        if (dir_base) {
                remove_proc_entry("hermes", &proc_root);
                dir_base = NULL;
        }
        
-       TRACE_EXIT("dldwd");
+       TRACE_EXIT("orinoco");
 }
 
-int
-dldwd_setup(dldwd_priv_t* priv)
+struct net_device *alloc_orinocodev(int sizeof_card)
 {
-       struct net_device *dev = &priv->ndev;;
-
-       spin_lock_init(&priv->lock);
-
-       /* Set up the net_device */
-       ether_setup(dev);
-       dev->priv = priv;
+       struct net_device *dev;
+       struct orinoco_private *priv;
 
-       /* Setup up default routines */
-       priv->card_reset_handler = NULL;        /* Caller may override */
-       dev->init = dldwd_init;
-       dev->open = NULL;               /* Caller *must* override */
+       TRACE_ENTER("orinoco");
+       dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
+       priv = (struct orinoco_private *)dev->priv;
+       priv->ndev = dev;
+       if (sizeof_card)
+               priv->card = (void *)((unsigned long)dev->priv + sizeof(struct orinoco_private));
+       else
+               priv->card = NULL;
+
+       /* Setup / override net_device fields */
+       dev->init = orinoco_init;
+       dev->hard_start_xmit = orinoco_xmit;
+       dev->tx_timeout = orinoco_tx_timeout;
+       dev->watchdog_timeo = HZ; /* 1 second timeout */
+       dev->get_stats = orinoco_get_stats;
+       dev->get_wireless_stats = orinoco_get_wireless_stats;
+       dev->do_ioctl = orinoco_ioctl;
+       dev->change_mtu = orinoco_change_mtu;
+       dev->set_multicast_list = orinoco_set_multicast_list;
+
+       dev->open = NULL;               /* Caller *must* override  these */
        dev->stop = NULL;
-       dev->hard_start_xmit = dldwd_xmit;
-       dev->tx_timeout = dldwd_tx_timeout;
-       dev->watchdog_timeo = HZ; /* 4 second timeout */
-
-       dev->get_stats = dldwd_get_stats;
-       dev->get_wireless_stats = dldwd_get_wireless_stats;
 
-       dev->do_ioctl = dldwd_ioctl;
+       /* Setup the private structure */
 
-       dev->change_mtu = dldwd_change_mtu;
-       dev->set_multicast_list = dldwd_set_multicast_list;
-
-       netif_stop_queue(dev);
+       spin_lock_init(&priv->lock);
+       priv->hard_reset = NULL;        /* Caller may override */
+       
+       TRACE_EXIT("orinoco");
+       return dev;
 
-       return 0;
 }
 
-#ifdef ORINOCO_DEBUG
-EXPORT_SYMBOL(dldwd_debug);
-#endif
-EXPORT_SYMBOL(dldwd_init);
-EXPORT_SYMBOL(dldwd_xmit);
-EXPORT_SYMBOL(dldwd_tx_timeout);
-EXPORT_SYMBOL(dldwd_ioctl);
-EXPORT_SYMBOL(dldwd_change_mtu);
-EXPORT_SYMBOL(dldwd_set_multicast_list);
-EXPORT_SYMBOL(dldwd_shutdown);
-EXPORT_SYMBOL(dldwd_reset);
-EXPORT_SYMBOL(dldwd_setup);
-EXPORT_SYMBOL(dldwd_proc_dev_init);
-EXPORT_SYMBOL(dldwd_proc_dev_cleanup);
-EXPORT_SYMBOL(dldwd_interrupt);
-
-static int __init init_dldwd(void)
-{
-       int err;
+/********************************************************************/
+/* module bookkeeping                                               */
+/********************************************************************/
 
-       err = dldwd_proc_init();
+EXPORT_SYMBOL(alloc_orinocodev);
+EXPORT_SYMBOL(orinoco_shutdown);
+EXPORT_SYMBOL(orinoco_reset);
+EXPORT_SYMBOL(orinoco_proc_dev_init);
+EXPORT_SYMBOL(orinoco_proc_dev_cleanup);
+EXPORT_SYMBOL(orinoco_interrupt);
 
+static int __init init_orinoco(void)
+{
        printk(KERN_DEBUG "%s\n", version);
-
-       return 0;
+       return orinoco_proc_init();
 }
 
-static void __exit exit_dldwd(void)
+static void __exit exit_orinoco(void)
 {
-       dldwd_proc_cleanup();
+       orinoco_proc_cleanup();
 }
 
-module_init(init_dldwd);
-module_exit(exit_dldwd);
+module_init(init_orinoco);
+module_exit(exit_orinoco);
index a231fb7064526185807acaafccba2e2920698e95..d9e857954e6cc62fbfc666a21bc674ace636f5dd 100644 (file)
 #define _ORINOCO_H
 
 /* To enable debug messages */
-/*  #define ORINOCO_DEBUG              3 */
+//#define ORINOCO_DEBUG                3
 
 #if (! defined (WIRELESS_EXT)) || (WIRELESS_EXT < 10)
-#error "orinoco_cs requires Wireless extensions v10 or later."
+#error "orinoco driver requires Wireless extensions v10 or later."
 #endif /* (! defined (WIRELESS_EXT)) || (WIRELESS_EXT < 10) */
 #define WIRELESS_SPY           // enable iwspy support
 
+#define ORINOCO_MAX_KEY_SIZE   14
+#define ORINOCO_MAX_KEYS       4
 
-#define DLDWD_MIN_MTU          256
-#define DLDWD_MAX_MTU          (HERMES_FRAME_LEN_MAX - ENCAPS_OVERHEAD)
+typedef struct orinoco_key {
+       u16 len;        /* always store little-endian */
+       char data[ORINOCO_MAX_KEY_SIZE];
+} __attribute__ ((packed)) orinoco_key_t;
 
-#define LTV_BUF_SIZE           128
-#define USER_BAP               0
-#define IRQ_BAP                        1
-#define DLDWD_MACPORT          0
-#define IRQ_LOOP_MAX           10
-#define TX_NICBUF_SIZE         2048
-#define TX_NICBUF_SIZE_BUG     1585            /* Bug in Symbol firmware */
-#define MAX_KEYS               4
-#define MAX_KEY_SIZE           14
-#define LARGE_KEY_SIZE         13
-#define SMALL_KEY_SIZE         5
-#define MAX_FRAME_SIZE         2304
-
-typedef struct dldwd_key {
-       uint16_t len;   /* always store little-endian */
-       char data[MAX_KEY_SIZE];
-} __attribute__ ((packed)) dldwd_key_t;
-
-typedef dldwd_key_t dldwd_keys_t[MAX_KEYS];
+typedef orinoco_key_t orinoco_keys_t[ORINOCO_MAX_KEYS];
 
 /*====================================================================*/
 
-
-typedef struct dldwd_priv {
-       void* card;     /* Pointer to card dependant structure */
+struct orinoco_private {
+       void *card;     /* Pointer to card dependant structure */
        /* card dependant extra reset code (i.e. bus/interface specific */
-       int (*card_reset_handler)(struct dldwd_priv *);
+       int (*hard_reset)(struct orinoco_private *);
 
        spinlock_t lock;
        long state;
-#define DLDWD_STATE_INIRQ 0
-#define DLDWD_STATE_DOIRQ 1
-       int hw_ready;   /* HW may be suspended by platform */
+#define ORINOCO_STATE_INIRQ 0
+#define ORINOCO_STATE_DOIRQ 1
 
        /* Net device stuff */
-       struct net_device ndev;
+       struct net_device *ndev;
        struct net_device_stats stats;
        struct iw_statistics wstats;
 
-
        /* Hardware control variables */
        hermes_t hw;
-       uint16_t txfid;
+       u16 txfid;
 
        /* Capabilities of the hardware/firmware */
        int firmware_type;
-#define FIRMWARE_TYPE_LUCENT 1
+#define FIRMWARE_TYPE_AGERE 1
 #define FIRMWARE_TYPE_INTERSIL 2
 #define FIRMWARE_TYPE_SYMBOL 3
-       int has_ibss, has_port3, prefer_port3, has_ibss_any, ibss_port;
+       int has_ibss, has_port3, has_ibss_any, ibss_port;
        int has_wep, has_big_wep;
        int has_mwo;
        int has_pm;
        int has_preamble;
-       int need_card_reset, broken_reset, broken_allocate;
-       uint16_t channel_mask;
-
-       /* Current configuration */
-       uint32_t iw_mode;
-       int port_type, allow_ibss;
-       uint16_t wep_on, wep_restrict, tx_key;
-       dldwd_keys_t keys;
+       int has_sensitivity;
+       int nicbuf_size;
+       int broken_cor_reset;
+       u16 channel_mask;
+
+       /* Configuration paramaters */
+       u32 iw_mode;
+       int prefer_port3;
+       u16 wep_on, wep_restrict, tx_key;
+       orinoco_keys_t keys;
+       int bitratemode;
        char nick[IW_ESSID_MAX_SIZE+1];
        char desired_essid[IW_ESSID_MAX_SIZE+1];
-       uint16_t frag_thresh, mwo_robust;
-       uint16_t channel;
-       uint16_t ap_density, rts_thresh;
-       uint16_t tx_rate_ctrl;
-       uint16_t pm_on, pm_mcast, pm_period, pm_timeout;
-       uint16_t preamble;
-
-       int promiscuous, allmulti, mc_count;
-
+       u16 frag_thresh, mwo_robust;
+       u16 channel;
+       u16 ap_density, rts_thresh;
+       u16 pm_on, pm_mcast, pm_period, pm_timeout;
+       u16 preamble;
 #ifdef WIRELESS_SPY
        int                     spy_number;
        u_char                  spy_address[IW_MAX_SPY][ETH_ALEN];
        struct iw_quality       spy_stat[IW_MAX_SPY];
 #endif
 
+       /* Configuration dependent variables */
+       int port_type, allow_ibss;
+       int promiscuous, mc_count;
+
+
        /* /proc based debugging stuff */
        struct proc_dir_entry *dir_dev;
-       struct proc_dir_entry *dir_regs;
-       struct proc_dir_entry *dir_recs;
-} dldwd_priv_t;
+};
 
 /*====================================================================*/
 
-extern struct list_head dldwd_instances;
+extern struct list_head orinoco_instances;
 
 #ifdef ORINOCO_DEBUG
-extern int dldwd_debug;
-#define DEBUG(n, args...) do { if (dldwd_debug>(n)) printk(KERN_DEBUG args); } while(0)
-#define DEBUGMORE(n, args...) do { if (dldwd_debug>(n)) printk(args); } while (0)
+extern int orinoco_debug;
+#define DEBUG(n, args...) do { if (orinoco_debug>(n)) printk(KERN_DEBUG args); } while(0)
+#define DEBUGMORE(n, args...) do { if (orinoco_debug>(n)) printk(args); } while (0)
 #else
 #define DEBUG(n, args...) do { } while (0)
 #define DEBUGMORE(n, args...) do { } while (0)
@@ -122,21 +107,12 @@ extern int dldwd_debug;
 
 #define RUP_EVEN(a) ( (a) % 2 ? (a) + 1 : (a) )
 
-/* struct net_device methods */
-extern int dldwd_init(struct net_device *dev);
-extern int dldwd_xmit(struct sk_buff *skb, struct net_device *dev);
-extern void dldwd_tx_timeout(struct net_device *dev);
-
-extern int dldwd_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
-extern int dldwd_change_mtu(struct net_device *dev, int new_mtu);
-extern void dldwd_set_multicast_list(struct net_device *dev);
-
 /* utility routines */
-extern void dldwd_shutdown(dldwd_priv_t *dev);
-extern int dldwd_reset(dldwd_priv_t *dev);
-extern int dldwd_setup(dldwd_priv_t* priv);
-extern int dldwd_proc_dev_init(dldwd_priv_t *dev);
-extern void dldwd_proc_dev_cleanup(dldwd_priv_t *priv);
-extern void dldwd_interrupt(int irq, void * dev_id, struct pt_regs *regs);
-
-#endif
+struct net_device *alloc_orinocodev(int sizeof_card);
+extern void orinoco_shutdown(struct orinoco_private *dev);
+extern int orinoco_reset(struct orinoco_private *dev);
+extern int orinoco_proc_dev_init(struct orinoco_private *dev);
+extern void orinoco_proc_dev_cleanup(struct orinoco_private *priv);
+extern void orinoco_interrupt(int irq, void * dev_id, struct pt_regs *regs);
+
+#endif /* _ORINOCO_H */
index de70ba44317c8f72d99ac1118995ed4229aeb74e..8515f37f167c0f63ce1669dfde2c8db3e9b952dc 100644 (file)
@@ -1,4 +1,4 @@
-/* orinoco_cs.c 0.08a  - (formerly known as dldwd_cs.c)
+/* orinoco_cs.c 0.11a  - (formerly known as dldwd_cs.c)
  *
  * A driver for "Hermes" chipset based PCMCIA wireless adaptors, such
  * as the Lucent WavelanIEEE/Orinoco cards and their OEM (Cabletron/
@@ -11,6 +11,9 @@
  */
 
 #include <linux/config.h>
+#ifdef  __IN_PCMCIA_PACKAGE__
+#include <pcmcia/k_compat.h>
+#endif /* __IN_PCMCIA_PACKAGE__ */
 
 #include <linux/module.h>
 #include <linux/kernel.h>
 
 /*====================================================================*/
 
-static char version[] __initdata = "orinoco_cs.c 0.08a (David Gibson <hermes@gibson.dropbear.id.au> and others)";
+static char version[] __initdata = "orinoco_cs.c 0.11a (David Gibson <hermes@gibson.dropbear.id.au> and others)";
 
 MODULE_AUTHOR("David Gibson <hermes@gibson.dropbear.id.au>");
 MODULE_DESCRIPTION("Driver for PCMCIA Lucent Orinoco, Prism II based and similar wireless cards");
+#ifdef MODULE_LICENSE
 MODULE_LICENSE("Dual MPL/GPL");
+#endif
 
 /* Parameters that can be set with 'insmod' */
 
@@ -58,7 +63,7 @@ static uint irq_mask = 0xdeb8;
 /* Newer, simpler way of listing specific interrupts */
 static int irq_list[4] = { -1 };
 /* Do a Pcmcia soft reset (may help some cards) */
-static int reset_cor = 0;
+static int reset_cor = -1;
 /* Some D-Link cards have buggy CIS. They do work at 5v properly, but
  * don't have any CIS entry for it. This workaround it... */
 static int ignore_cis_vcc; /* = 0 */
@@ -68,40 +73,34 @@ MODULE_PARM(irq_list, "1-4i");
 MODULE_PARM(reset_cor, "i");
 MODULE_PARM(ignore_cis_vcc, "i");
 
-
 /* Pcmcia specific structure */
-typedef struct dldwd_card {
+struct orinoco_pccard {
        dev_link_t link;
        dev_node_t node;
-       int instance;
-
-       /* Common structure (fully included), see orinoco.h */
-       struct dldwd_priv  priv;
-} dldwd_card_t;
+};
 
 /*
  * Function prototypes
  */
 
 /* struct net_device methods */
-static int dldwd_cs_open(struct net_device *dev);
-static int dldwd_cs_stop(struct net_device *dev);
+static int orinoco_cs_open(struct net_device *dev);
+static int orinoco_cs_stop(struct net_device *dev);
 
 /* PCMCIA gumpf */
-static void dldwd_cs_config(dev_link_t * link);
-static void dldwd_cs_release(u_long arg);
-static int dldwd_cs_event(event_t event, int priority,
+static void orinoco_cs_config(dev_link_t * link);
+static void orinoco_cs_release(u_long arg);
+static int orinoco_cs_event(event_t event, int priority,
                       event_callback_args_t * args);
 
-static dev_link_t *dldwd_cs_attach(void);
-static void dldwd_cs_detach(dev_link_t *);
+static dev_link_t *orinoco_cs_attach(void);
+static void orinoco_cs_detach(dev_link_t *);
 
 /*
    The dev_info variable is the "key" that is used to match up this
    device driver with appropriate cards, through the card configuration
    database.
 */
-
 static dev_info_t dev_info = "orinoco_cs";
 
 /*
@@ -115,7 +114,6 @@ static dev_info_t dev_info = "orinoco_cs";
 */
 
 static dev_link_t *dev_list; /* = NULL */
-static int num_instances; /* = 0 */
 
 /*====================================================================*/
 
@@ -127,48 +125,48 @@ cs_error(client_handle_t handle, int func, int ret)
 }
 
 static int
-dldwd_cs_open(struct net_device *dev)
+orinoco_cs_open(struct net_device *dev)
 {
-       dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
-       dldwd_card_t* card = (dldwd_card_t *)priv->card;
+       struct orinoco_private *priv = (struct orinoco_private *)dev->priv;
+       struct orinoco_pccard* card = (struct orinoco_pccard *)priv->card;
        dev_link_t *link = &card->link;
        int err;
        
-       TRACE_ENTER(priv->ndev.name);
+       TRACE_ENTER(dev->name);
 
        link->open++;
        netif_device_attach(dev);
        
-       err = dldwd_reset(priv);
+       err = orinoco_reset(priv);
        if (err)
-               dldwd_cs_stop(dev);
+               orinoco_cs_stop(dev);
        else
                netif_start_queue(dev);
 
-       TRACE_EXIT(priv->ndev.name);
+       TRACE_EXIT(dev->name);
 
        return err;
 }
 
 static int
-dldwd_cs_stop(struct net_device *dev)
+orinoco_cs_stop(struct net_device *dev)
 {
-       dldwd_priv_t *priv = (dldwd_priv_t *)dev->priv;
-       dldwd_card_t* card = (dldwd_card_t *)priv->card;
+       struct orinoco_private *priv = (struct orinoco_private *)dev->priv;
+       struct orinoco_pccard* card = (struct orinoco_pccard *)priv->card;
        dev_link_t *link = &card->link;
 
-       TRACE_ENTER(priv->ndev.name);
+       TRACE_ENTER(dev->name);
 
        netif_stop_queue(dev);
 
-       dldwd_shutdown(priv);
+       orinoco_shutdown(priv);
        
        link->open--;
 
        if (link->state & DEV_STALE_CONFIG)
                mod_timer(&link->release, jiffies + HZ/20);
        
-       TRACE_EXIT(priv->ndev.name);
+       TRACE_EXIT(dev->name);
        
        return 0;
 }
@@ -179,18 +177,18 @@ dldwd_cs_stop(struct net_device *dev)
  * In fact, this seem necessary for Spectrum cards...
  */
 static int
-dldwd_cs_cor_reset(dldwd_priv_t *priv)
+orinoco_cs_cor_reset(struct orinoco_private *priv)
 {
-       dldwd_card_t* card = (dldwd_card_t *)priv->card;
+       struct orinoco_pccard* card = (struct orinoco_pccard *)priv->card;
        dev_link_t *link = &card->link;
        conf_reg_t reg;
        u_int default_cor; 
 
-       TRACE_ENTER(priv->ndev.name);
+       TRACE_ENTER(priv->ndev->name);
 
        /* Doing it if hardware is gone is guaranteed crash */
-       if(!priv->hw_ready)
-               return(0);
+       if(! (link->state & DEV_CONFIG) )
+               return -ENODEV;
 
        /* Save original COR value */
        reg.Function = 0;
@@ -200,7 +198,7 @@ dldwd_cs_cor_reset(dldwd_priv_t *priv)
        CardServices(AccessConfigurationRegister, link->handle, &reg);
        default_cor = reg.Value;
 
-       DEBUG(2, "dldwd : dldwd_cs_cor_reset() : cor=0x%X\n", default_cor);
+       DEBUG(2, "orinoco : orinoco_cs_cor_reset() : cor=0x%X\n", default_cor);
 
        /* Soft-Reset card */
        reg.Action = CS_WRITE;
@@ -209,18 +207,57 @@ dldwd_cs_cor_reset(dldwd_priv_t *priv)
        CardServices(AccessConfigurationRegister, link->handle, &reg);
 
        /* Wait until the card has acknowledged our reset */
+       /* FIXME: mdelay() is deprecated -dgibson */
        mdelay(1);
 
+#if 0 /* This seems to help on Symbol cards, but we're not sure why,
+       and we don't know what it will do to other cards */
+       reg.Action = CS_READ;
+       reg.Offset = CISREG_CCSR;
+       CardServices(AccessConfigurationRegister, link->handle, &reg);
+
+       /* Write 7 (RUN) to CCSR, but preserve the original bit 4 */
+       reg.Action = CS_WRITE;
+       reg.Offset = CISREG_CCSR;
+       reg.Value = 7 | (reg.Value & 0x10);
+       CardServices(AccessConfigurationRegister, link->handle, &reg);
+       mdelay(1);
+#endif
+
        /* Restore original COR configuration index */
+       reg.Action = CS_WRITE;
+       reg.Offset = CISREG_COR;
        reg.Value = (default_cor & ~COR_SOFT_RESET);
        CardServices(AccessConfigurationRegister, link->handle, &reg);
 
        /* Wait until the card has finished restarting */
+       /* FIXME: mdelay() is deprecated -dgibson */
        mdelay(1);
 
-       TRACE_EXIT(priv->ndev.name);
+       TRACE_EXIT(priv->ndev->name);
 
-       return(0);
+       return 0;
+}
+
+static int
+orinoco_cs_hard_reset(struct orinoco_private *priv)
+{
+       if (! priv->broken_cor_reset)
+               return orinoco_cs_cor_reset(priv);
+       else
+               return 0;
+
+#if 0 /* We'd like to use ResetCard, but we can't for the moment - it sleeps */
+       /* Not sure what the second parameter is supposed to be - the 
+          PCMCIA code doesn't actually use it */
+       if (in_interrupt()) {
+               printk("Not resetting card, in_interrupt() is true\n");
+               return 0;
+       } else {
+               printk("Doing ResetCard\n");
+               return CardServices(ResetCard, link->handle, NULL);
+       }
+#endif
 }
 
 /* Remove zombie instances (card removed, detach pending) */
@@ -228,17 +265,17 @@ static void
 flush_stale_links(void)
 {
        dev_link_t *link, *next;
-       TRACE_ENTER("dldwd");
+       TRACE_ENTER("orinoco");
        for (link = dev_list; link; link = next) {
                next = link->next;
                if (link->state & DEV_STALE_LINK)
-                       dldwd_cs_detach(link);
+                       orinoco_cs_detach(link);
        }
-       TRACE_EXIT("dldwd");
+       TRACE_EXIT("orinoco");
 }
 
 /*======================================================================
-  dldwd_cs_attach() creates an "instance" of the driver, allocating
+  orinoco_cs_attach() creates an "instance" of the driver, allocating
   local data structures for one device.  The device is registered
   with Card Services.
   
@@ -248,37 +285,35 @@ flush_stale_links(void)
   ======================================================================*/
 
 static dev_link_t *
-dldwd_cs_attach(void)
+orinoco_cs_attach(void)
 {
-       dldwd_card_t *card;
-       dldwd_priv_t *priv;
+       struct net_device *dev;
+       struct orinoco_private *priv;
+       struct orinoco_pccard *card;
        dev_link_t *link;
-       struct net_device *ndev;
        client_reg_t client_reg;
        int ret, i;
 
-       TRACE_ENTER("dldwd");
+       TRACE_ENTER("orinoco");
        /* A bit of cleanup */
        flush_stale_links();
 
-       /* Allocate space for private device-specific data */
-       card = kmalloc(sizeof(*card), GFP_KERNEL);
-       if (! card) {
-               link = NULL;
-               goto out;
-       }
-       memset(card, 0, sizeof(*card));
+       dev = alloc_orinocodev(sizeof(*card));
+       if (! dev)
+               return NULL;
+       priv = dev->priv;
+       card = priv->card;
+       /* Overrides */
+       dev->open = orinoco_cs_open;
+       dev->stop = orinoco_cs_stop;
+       priv->hard_reset = orinoco_cs_hard_reset;
 
-       /* Link both structure together */
-       priv = &(card->priv);
-       priv->card = card;
-       card->instance = num_instances++; /* FIXME: Racy? */
+       /* Link both structures together */
        link = &card->link;
-       ndev = &priv->ndev;
        link->priv = priv;
 
        /* Initialize the dev_link_t structure */
-       link->release.function = &dldwd_cs_release;
+       link->release.function = &orinoco_cs_release;
        link->release.data = (u_long) link;
 
        /* Interrupt setup */
@@ -301,17 +336,6 @@ dldwd_cs_attach(void)
        link->conf.Attributes = 0;
        link->conf.IntType = INT_MEMORY_AND_IO;
 
-       /* Setup the common part */
-       if(dldwd_setup(priv) < 0) {
-               kfree(card);
-               return NULL;
-       }
-
-       /* Overrides */
-       ndev->open = dldwd_cs_open;
-       ndev->stop = dldwd_cs_stop;
-       priv->card_reset_handler = dldwd_cs_cor_reset;
-
        /* Register with Card Services */
        link->next = dev_list;
        dev_list = link;
@@ -321,21 +345,21 @@ dldwd_cs_attach(void)
            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 = &dldwd_cs_event;
+       client_reg.event_handler = &orinoco_cs_event;
        client_reg.Version = 0x0210;
        client_reg.event_callback_args.client_data = link;
        ret = CardServices(RegisterClient, &link->handle, &client_reg);
        if (ret != CS_SUCCESS) {
                cs_error(link->handle, RegisterClient, ret);
-               dldwd_cs_detach(link);
+               orinoco_cs_detach(link);
                link = NULL;
                goto out;
        }
 
  out:
-       TRACE_EXIT("dldwd");
+       TRACE_EXIT("orinoco");
        return link;
-}                              /* dldwd_cs_attach */
+}                              /* orinoco_cs_attach */
 
 /*======================================================================
   This deletes a driver "instance".  The device is de-registered
@@ -345,12 +369,12 @@ dldwd_cs_attach(void)
   ======================================================================*/
 
 static void
-dldwd_cs_detach(dev_link_t * link)
+orinoco_cs_detach(dev_link_t * link)
 {
        dev_link_t **linkp;
-       dldwd_priv_t *priv = link->priv;
+       struct orinoco_private *priv = link->priv;
 
-       TRACE_ENTER("dldwd");
+       TRACE_ENTER("orinoco");
 
        /* Locate device structure */
        for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
@@ -383,19 +407,17 @@ dldwd_cs_detach(dev_link_t * link)
        DEBUG(0, "orinoco_cs: detach: link=%p link->dev=%p\n", link, link->dev);
        if (link->dev) {
                DEBUG(0, "orinoco_cs: About to unregister net device %p\n",
-                     &priv->ndev);
-               unregister_netdev(&priv->ndev);
+                     priv->ndev);
+               unregister_netdev(priv->ndev);
        }
        kfree(priv->card);
 
-       num_instances--; /* FIXME: Racy? */
-
  out:
-       TRACE_EXIT("dldwd");
-}                              /* dldwd_cs_detach */
+       TRACE_EXIT("orinoco");
+}                              /* orinoco_cs_detach */
 
 /*======================================================================
-  dldwd_cs_config() is scheduled to run after a CARD_INSERTION event
+  orinoco_cs_config() is scheduled to run after a CARD_INSERTION event
   is received, to configure the PCMCIA socket, and to make the
   device available to the system.
   ======================================================================*/
@@ -407,13 +429,13 @@ while ((last_ret=CardServices(last_fn=(fn),args))!=0) goto cs_failed
 if (CardServices(fn, args) != 0) goto next_entry
 
 static void
-dldwd_cs_config(dev_link_t * link)
+orinoco_cs_config(dev_link_t * link)
 {
        client_handle_t handle = link->handle;
-       dldwd_priv_t *priv = link->priv;
-       dldwd_card_t *card = (dldwd_card_t *)priv->card;
+       struct orinoco_private *priv = link->priv;
+       struct orinoco_pccard *card = (struct orinoco_pccard *)priv->card;
        hermes_t *hw = &priv->hw;
-       struct net_device *ndev = &priv->ndev;
+       struct net_device *ndev = priv->ndev;
        tuple_t tuple;
        cisparse_t parse;
        int last_fn, last_ret;
@@ -422,7 +444,7 @@ dldwd_cs_config(dev_link_t * link)
        cistpl_cftable_entry_t dflt = { 0 };
        cisinfo_t info;
 
-       TRACE_ENTER("dldwd");
+       TRACE_ENTER("orinoco");
 
        CS_CHECK(ValidateCIS, handle, &info);
 
@@ -448,7 +470,7 @@ dldwd_cs_config(dev_link_t * link)
        CS_CHECK(GetConfigurationInfo, handle, &conf);
        link->conf.Vcc = conf.Vcc;
 
-       DEBUG(0, "dldwd_cs_config: ConfigBase = 0x%x link->conf.Vcc = %d\n", 
+       DEBUG(0, "orinoco_cs_config: ConfigBase = 0x%x link->conf.Vcc = %d\n", 
              link->conf.ConfigBase, link->conf.Vcc);
 
        /*
@@ -470,7 +492,7 @@ dldwd_cs_config(dev_link_t * link)
                CFG_CHECK(GetTupleData, handle, &tuple);
                CFG_CHECK(ParseTuple, handle, &tuple, &parse);
 
-               DEBUG(0, "dldwd_cs_config: index = 0x%x, flags = 0x%x\n",
+               DEBUG(0, "orinoco_cs_config: index = 0x%x, flags = 0x%x\n",
                      cfg->index, cfg->flags);
 
                if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
@@ -488,16 +510,14 @@ dldwd_cs_config(dev_link_t * link)
                /* 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)) {
-                       if (conf.Vcc !=
-                           cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
-                               DEBUG(2, "dldwd_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n",  conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
-                               if(!ignore_cis_vcc)
+                       if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
+                               DEBUG(2, "orinoco_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n",  conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
+                               if (!ignore_cis_vcc)
                                        goto next_entry;
                        }
                } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
-                       if (conf.Vcc !=
-                           dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) {
-                               DEBUG(2, "dldwd_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n",  conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000);
+                       if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) {
+                               DEBUG(2, "orinoco_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n",  conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000);
                                if(!ignore_cis_vcc)
                                        goto next_entry;
                        }
@@ -510,7 +530,7 @@ dldwd_cs_config(dev_link_t * link)
                        link->conf.Vpp1 = link->conf.Vpp2 =
                            dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
                
-               DEBUG(0, "dldwd_cs_config: We seem to have configured Vcc and Vpp\n");
+               DEBUG(0, "orinoco_cs_config: We seem to have configured Vcc and Vpp\n");
 
                /* Do we need to allocate an interrupt? */
                if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
@@ -551,7 +571,12 @@ dldwd_cs_config(dev_link_t * link)
        next_entry:
                if (link->io.NumPorts1)
                        CardServices(ReleaseIO, link->handle, &link->io);
-               CS_CHECK(GetNextTuple, handle, &tuple);
+               last_ret = CardServices(GetNextTuple, handle, &tuple);
+               if (last_ret  == CS_NO_MORE_ITEMS) {
+                       printk(KERN_ERR "GetNextTuple().  No matching CIS configuration, "
+                              "maybe you need the ignore_cis_vcc=1 parameter.\n");
+                       goto cs_failed;
+               }
        }
 
        /*
@@ -570,7 +595,7 @@ dldwd_cs_config(dev_link_t * link)
                        for (i=0; i<4; i++)
                                link->irq.IRQInfo2 |= 1 << irq_list[i];
                
-               link->irq.Handler = dldwd_interrupt; 
+               link->irq.Handler = orinoco_interrupt; 
                link->irq.Instance = priv; 
                
                CS_CHECK(RequestIRQ, link->handle, &link->irq);
@@ -579,7 +604,8 @@ dldwd_cs_config(dev_link_t * link)
        /* We initialize the hermes structure before completing PCMCIA
           configuration just in case the interrupt handler gets
           called. */
-       hermes_struct_init(hw, link->io.BasePort1);
+       hermes_struct_init(hw, link->io.BasePort1,
+                               HERMES_IO, HERMES_16BIT_REGSPACING);
 
        /*
           This actually configures the PCMCIA socket -- setting up
@@ -618,7 +644,7 @@ dldwd_cs_config(dev_link_t * link)
        printk("\n");
 
        /* And give us the proc nodes for debugging */
-       if (dldwd_proc_dev_init(priv) != 0) {
+       if (orinoco_proc_dev_init(priv) != 0) {
                printk(KERN_ERR "orinoco_cs: Failed to create /proc node for %s\n",
                       ndev->name);
                goto failed;
@@ -627,12 +653,9 @@ dldwd_cs_config(dev_link_t * link)
        /* Note to myself : this replace MOD_INC_USE_COUNT/MOD_DEC_USE_COUNT */
        SET_MODULE_OWNER(ndev);
        
-       /* Allow cor_reset, /proc & ioctls to act */
-       priv->hw_ready = 1;
-       
-       /* Do a Pcmcia soft reset of the card (optional) */
-       if(reset_cor)
-               dldwd_cs_cor_reset(priv);
+       /* Let reset_cor parameter override determine_firmware()'s guess */
+       if (reset_cor != -1)
+               priv->broken_cor_reset = ! reset_cor;
 
        /*
           At this point, the dev_node_t structure(s) need to be
@@ -642,29 +665,29 @@ dldwd_cs_config(dev_link_t * link)
        link->dev = &card->node;
        link->state &= ~DEV_CONFIG_PENDING;
 
-       TRACE_EXIT("dldwd");
+       TRACE_EXIT("orinoco");
 
        return;
 
  cs_failed:
        cs_error(link->handle, last_fn, last_ret);
  failed:
-       dldwd_cs_release((u_long) link);
+       orinoco_cs_release((u_long) link);
 
-       TRACE_EXIT("dldwd");
-}                              /* dldwd_cs_config */
+       TRACE_EXIT("orinoco");
+}                              /* orinoco_cs_config */
 
 /*======================================================================
-  After a card is removed, dldwd_cs_release() will unregister the
+  After a card is removed, orinoco_cs_release() will unregister the
   device, and release the PCMCIA configuration.  If the device is
   still open, this will be postponed until it is closed.
   ======================================================================*/
 
 static void
-dldwd_cs_release(u_long arg)
+orinoco_cs_release(u_long arg)
 {
        dev_link_t *link = (dev_link_t *) arg;
-       dldwd_priv_t *priv = link->priv;
+       struct orinoco_private *priv = link->priv;
 
        TRACE_ENTER(link->dev->dev_name);
 
@@ -681,7 +704,7 @@ dldwd_cs_release(u_long arg)
        }
 
        /* Unregister proc entry */
-       dldwd_proc_dev_cleanup(priv);
+       orinoco_proc_dev_cleanup(priv);
 
        /* Don't bother checking to see if these succeed or not */
        CardServices(ReleaseConfiguration, link->handle);
@@ -692,7 +715,7 @@ dldwd_cs_release(u_long arg)
        link->state &= ~DEV_CONFIG;
 
        TRACE_EXIT(link->dev->dev_name);
-}                              /* dldwd_cs_release */
+}                              /* orinoco_cs_release */
 
 /*======================================================================
   The card status event handler.  Mostly, this schedules other
@@ -705,39 +728,37 @@ dldwd_cs_release(u_long arg)
   ======================================================================*/
 
 static int
-dldwd_cs_event(event_t event, int priority,
+orinoco_cs_event(event_t event, int priority,
                       event_callback_args_t * args)
 {
        dev_link_t *link = args->client_data;
-       dldwd_priv_t *priv = (dldwd_priv_t *)link->priv;
-       struct net_device *dev = &priv->ndev;
+       struct orinoco_private *priv = (struct orinoco_private *)link->priv;
+       struct net_device *dev = priv->ndev;
 
-       TRACE_ENTER("dldwd");
+       TRACE_ENTER("orinoco");
 
        switch (event) {
        case CS_EVENT_CARD_REMOVAL:
-               /* FIXME: Erg.. this whole hw_ready thing looks racy
-                  to me.  this may not be fixable without changin the
-                  PCMCIA subsystem, though */
-               priv->hw_ready = 0;
-               dldwd_shutdown(priv);
                link->state &= ~DEV_PRESENT;
                if (link->state & DEV_CONFIG) {
                        netif_stop_queue(dev);
+               }
+               orinoco_shutdown(priv);
+               if (link->state & DEV_CONFIG) {
                        netif_device_detach(dev);
                        mod_timer(&link->release, jiffies + HZ / 20);
                }
                break;
        case CS_EVENT_CARD_INSERTION:
                link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
-               dldwd_cs_config(link);
+               orinoco_cs_config(link);
                break;
        case CS_EVENT_PM_SUSPEND:
 
                link->state |= DEV_SUSPEND;
                /* Fall through... */
        case CS_EVENT_RESET_PHYSICAL:
-               dldwd_shutdown(priv);
+               orinoco_shutdown(priv);
                /* Mark the device as stopped, to block IO until later */
 
                if (link->state & DEV_CONFIG) {
@@ -757,13 +778,13 @@ dldwd_cs_event(event_t event, int priority,
                                     &link->conf);
 
                        if (link->open) {
-                               if (dldwd_reset(priv) == 0) {
+                               if (orinoco_reset(priv) == 0) {
                                        netif_device_attach(dev);
                                        netif_start_queue(dev);
                                } else {
                                        printk(KERN_ERR "%s: Error resetting device on PCMCIA event\n",
                                               dev->name);
-                                       dldwd_cs_stop(dev);
+                                       orinoco_cs_stop(dev);
                                }
                        }
                }
@@ -774,17 +795,17 @@ dldwd_cs_event(event_t event, int priority,
                break;
        }
 
-       TRACE_EXIT("dldwd");
+       TRACE_EXIT("orinoco");
 
        return 0;
-}                              /* dldwd_cs_event */
+}                              /* orinoco_cs_event */
 
 static int __init
-init_dldwd_cs(void)
+init_orinoco_cs(void)
 {
        servinfo_t serv;
 
-       TRACE_ENTER("dldwd");
+       TRACE_ENTER("orinoco");
 
        printk(KERN_DEBUG "%s\n", version);
 
@@ -795,17 +816,17 @@ init_dldwd_cs(void)
                return -1;
        }
 
-       register_pccard_driver(&dev_info, &dldwd_cs_attach, &dldwd_cs_detach);
+       register_pccard_driver(&dev_info, &orinoco_cs_attach, &orinoco_cs_detach);
 
 
-       TRACE_EXIT("dldwd");
+       TRACE_EXIT("orinoco");
        return 0;
 }
 
 static void __exit
-exit_dldwd_cs(void)
+exit_orinoco_cs(void)
 {
-       TRACE_ENTER("dldwd");
+       TRACE_ENTER("orinoco");
 
        unregister_pccard_driver(&dev_info);
 
@@ -814,12 +835,12 @@ exit_dldwd_cs(void)
        while (dev_list != NULL) {
                del_timer(&dev_list->release);
                if (dev_list->state & DEV_CONFIG)
-                       dldwd_cs_release((u_long) dev_list);
-               dldwd_cs_detach(dev_list);
+                       orinoco_cs_release((u_long) dev_list);
+               orinoco_cs_detach(dev_list);
        }
 
-       TRACE_EXIT("dldwd");
+       TRACE_EXIT("orinoco");
 }
 
-module_init(init_dldwd_cs);
-module_exit(exit_dldwd_cs);
+module_init(init_orinoco_cs);
+module_exit(exit_orinoco_cs);
diff --git a/drivers/net/wireless/orinoco_pci.c b/drivers/net/wireless/orinoco_pci.c
new file mode 100644 (file)
index 0000000..c33f104
--- /dev/null
@@ -0,0 +1,391 @@
+/* orinoco_pci.c 0.01
+ * 
+ * Driver for Prism II devices that have a direct PCI interface
+ * (i.e., not in a Pcmcia or PLX bridge)
+ *
+ * Specifically here we're talking about the Linksys WMP11
+ *
+ * Some of this code is borrowed from orinoco_plx.c
+ *     Copyright (C) 2001 Daniel Barlow <dan@telent.net>
+ * Some of this code is "inspired" by linux-wlan-ng-0.1.10, but nothing
+ * has been copied from it. linux-wlan-ng-0.1.10 is originally :
+ *     Copyright (C) 1999 AbsoluteValue Systems, Inc.  All Rights Reserved.
+ * The rest is :
+ *     Copyright (C) 2001 Jean Tourrilhes <jt@hpl.hp.com>
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License
+ * at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * Alternatively, the contents of this file may be used under the
+ * terms of the GNU General Public License version 2 (the "GPL"), in
+ * which case the provisions of the GPL are applicable instead of the
+ * above.  If you wish to allow the use of your version of this file
+ * only under the terms of the GPL and not to allow others to use your
+ * version of this file under the MPL, indicate your decision by
+ * deleting the provisions above and replace them with the notice and
+ * other provisions required by the GPL.  If you do not delete the
+ * provisions above, a recipient may use your version of this file
+ * under either the MPL or the GPL.
+ */
+
+/*
+ * Theory of operation...
+ * -------------------
+ * Maybe you had a look in orinoco_plx. Well, this is totally different...
+ *
+ * The card contains only one PCI region, which contains all the usual
+ * hermes registers.
+ *
+ * The driver will memory map this region in normal memory. Because
+ * the hermes registers are mapped in normal memory and not in ISA I/O
+ * post space, we can't use the usual inw/outw macros and we need to
+ * use readw/writew.
+ * This slight difference force us to compile our own version of
+ * hermes.c with the register access macro changed. That's a bit
+ * hackish but works fine.
+ *
+ * Note that the PCI region is pretty big (4K). That's much more than
+ * the usual set of hermes register (0x0 -> 0x3E). I've got a strong
+ * suspicion that the whole memory space of the adapter is in fact in
+ * this region. Accessing directly the adapter memory instead of going
+ * through the usual register would speed up significantely the
+ * operations...
+ *
+ * Finally, the card looks like this :
+-----------------------
+  Bus  0, device  14, function  0:
+    Network controller: PCI device 1260:3873 (Harris Semiconductor) (rev 1).
+      IRQ 11.
+      Master Capable.  Latency=248.  
+      Prefetchable 32 bit memory at 0xffbcc000 [0xffbccfff].
+-----------------------
+00:0e.0 Network controller: Harris Semiconductor: Unknown device 3873 (rev 01)
+        Subsystem: Unknown device 1737:3874
+        Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
+        Status: Cap+ 66Mhz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
+        Latency: 248 set, cache line size 08
+        Interrupt: pin A routed to IRQ 11
+        Region 0: Memory at ffbcc000 (32-bit, prefetchable) [size=4K]
+        Capabilities: [dc] Power Management version 2
+                Flags: PMEClk- AuxPwr- DSI- D1+ D2+ PME+
+                Status: D0 PME-Enable- DSel=0 DScale=0 PME-
+-----------------------
+ *
+ * That's all..
+ *
+ * Jean II
+ */
+
+#include <linux/config.h>
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/ptrace.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/timer.h>
+#include <linux/ioport.h>
+#include <asm/uaccess.h>
+#include <asm/io.h>
+#include <asm/system.h>
+#include <linux/proc_fs.h>
+#include <linux/netdevice.h>
+#include <linux/if_arp.h>
+#include <linux/etherdevice.h>
+#include <linux/wireless.h>
+#include <linux/list.h>
+#include <linux/pci.h>
+#include <linux/wireless.h>
+#include <linux/fcntl.h>
+
+#include "hermes.h"
+#include "orinoco.h"
+
+/* All the magic there is from wlan-ng */
+/* Magic offset of the reset register of the PCI card */
+#define HERMES_PCI_COR         (0x26)
+/* Magic bitmask to reset the card */
+#define HERMES_PCI_COR_MASK    (0x0080)
+/* Magic timeouts for doing the reset.
+ * Those times are straight from wlan-ng, and it is claimed that they
+ * are necessary. Alan will kill me. Take your time and grab a coffee. */
+#define HERMES_PCI_COR_ONT     (250)           /* ms */
+#define HERMES_PCI_COR_OFFT    (500)           /* ms */
+#define HERMES_PCI_COR_BUSYT   (500)           /* ms */
+
+MODULE_AUTHOR("Jean Tourrilhes <jt@hpl.hp.com>");
+MODULE_DESCRIPTION("Driver for wireless LAN cards using direct PCI interface");
+MODULE_LICENSE("Dual MPL/GPL");
+
+static int orinoco_pci_open(struct net_device *dev)
+{
+       struct orinoco_private *priv = (struct orinoco_private *) dev->priv;
+       int err;
+
+       netif_device_attach(dev);
+
+       err = orinoco_reset(priv);
+       if (err)
+               printk(KERN_ERR "%s: orinoco_reset failed in orinoco_pci_open()",
+                      dev->name);
+       else
+               netif_start_queue(dev);
+
+       return err;
+}
+
+static int orinoco_pci_stop(struct net_device *dev)
+{
+       struct orinoco_private *priv = (struct orinoco_private *) dev->priv;
+       netif_stop_queue(dev);
+       orinoco_shutdown(priv);
+       return 0;
+}
+
+static void
+orinoco_pci_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+       orinoco_interrupt(irq, (struct orinoco_private *)dev_id, regs);
+}
+
+/*
+ * Do a soft reset of the PCI card using the Configuration Option Register
+ * We need this to get going...
+ * This is the part of the code that is strongly inspired from wlan-ng
+ *
+ * Note : This code is done with irq enabled. This mean that many
+ * interrupts will occur while we are there. This is why we use the
+ * jiffies to regulate time instead of a straight mdelay(). Usually we
+ * need only around 245 iteration of the loop to do 250 ms delay.
+ *
+ * Note bis : Don't try to access HERMES_CMD during the reset phase.
+ * It just won't work !
+ */
+static int
+orinoco_pci_cor_reset(struct orinoco_private *priv)
+{
+       hermes_t *hw = &priv->hw;
+       unsigned long   timeout;
+       u16     reg;
+
+       TRACE_ENTER(priv->ndev->name);
+
+
+       /* Assert the reset until the card notice */
+       hermes_write_regn(hw, PCI_COR, HERMES_PCI_COR_MASK);
+       printk(KERN_NOTICE "Reset done");
+       timeout = jiffies + (HERMES_PCI_COR_ONT * HZ / 1000);
+       while(time_before(jiffies, timeout)) {
+               printk(".");
+               mdelay(1);
+       }
+       printk(";\n");
+       //mdelay(HERMES_PCI_COR_ONT);
+
+       /* Give time for the card to recover from this hard effort */
+       hermes_write_regn(hw, PCI_COR, 0x0000);
+       printk(KERN_NOTICE "Clear Reset");
+       timeout = jiffies + (HERMES_PCI_COR_OFFT * HZ / 1000);
+       while(time_before(jiffies, timeout)) {
+               printk(".");
+               mdelay(1);
+       }
+       printk(";\n");
+       //mdelay(HERMES_PCI_COR_OFFT);
+
+       /* The card is ready when it's no longer busy */
+       timeout = jiffies + (HERMES_PCI_COR_BUSYT * HZ / 1000);
+       reg = hermes_read_regn(hw, CMD);
+       while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
+               mdelay(1);
+               reg = hermes_read_regn(hw, CMD);
+       }
+       /* Did we timeout ? */
+       if(time_after_eq(jiffies, timeout)) {
+               printk(KERN_ERR "orinoco_pci: Busy timeout\n");
+               return -ETIMEDOUT;
+       }
+       printk(KERN_NOTICE "pci_cor : reg = 0x%X - %lX - %lX\n", reg, timeout, jiffies);
+
+       TRACE_EXIT(priv->ndev->name);
+
+       return 0;
+}
+
+/*
+ * Initialise a card. Mostly similar to PLX code.
+ */
+static int orinoco_pci_init_one(struct pci_dev *pdev,
+                               const struct pci_device_id *ent)
+{
+       int err = 0;
+       unsigned long pci_iorange;
+       u16 *pci_ioaddr = NULL;
+       unsigned long pci_iolen;
+       struct orinoco_private *priv = NULL;
+       struct net_device *dev = NULL;
+       int netdev_registered = 0;
+
+       TRACE_ENTER("orinoco_pci");
+
+       err = pci_enable_device(pdev);
+       if (err)
+               return -EIO;
+
+       /* Resource 0 is mapped to the hermes registers */
+       pci_iorange = pci_resource_start(pdev, 0);
+       pci_iolen = pci_resource_len(pdev, 0);
+       pci_ioaddr = ioremap(pci_iorange, pci_iolen);
+       if (! pci_iorange)
+               goto fail;
+
+       /* Usual setup of structures */
+       dev = alloc_orinocodev(0);
+       if (! dev) {
+               err = -ENOMEM;
+               goto fail;
+       }
+       priv = dev->priv;
+
+       dev->base_addr = (int) pci_ioaddr;
+        dev->mem_start = (unsigned long) pci_iorange;
+        dev->mem_end = ((unsigned long) pci_iorange) + pci_iolen - 1;
+       dev->open = orinoco_pci_open;
+       dev->stop = orinoco_pci_stop;
+/*     priv->card_reset_handler = orinoco_pci_cor_reset; */
+
+       SET_MODULE_OWNER(dev);
+
+       printk(KERN_DEBUG
+              "Detected Orinoco/Prism2 PCI device at %s, mem:0x%lX to 0x%lX -> 0x%p, irq:%d\n",
+              pdev->slot_name, dev->mem_start, dev->mem_end, pci_ioaddr, pdev->irq);
+
+       hermes_struct_init(&(priv->hw), dev->base_addr, HERMES_MEM, HERMES_32BIT_REGSPACING);
+       pci_set_drvdata(pdev, priv);
+
+       err = request_irq(pdev->irq, orinoco_pci_interrupt, SA_SHIRQ, dev->name, priv);
+       if (err) {
+               printk(KERN_ERR "orinoco_pci: Error allocating IRQ %d.\n", pdev->irq);
+               err = -EBUSY;
+               goto fail;
+       }
+       dev->irq = pdev->irq;
+       /* Perform a COR reset to start the card */
+       if(orinoco_pci_cor_reset(priv) != 0) {
+               printk(KERN_ERR "%s: Failed to start the card\n", dev->name);
+               err = -ETIMEDOUT;
+               goto fail;
+       }
+
+       /* Override the normal firmware detection - the Prism 2.5 PCI
+        * cards look like Lucent firmware but are actually Intersil */
+       priv->firmware_type = FIRMWARE_TYPE_INTERSIL;
+
+       err = register_netdev(dev);
+       if (err)
+               goto fail;
+       netdev_registered = 1;
+
+       err = orinoco_proc_dev_init(priv);
+       if (err) {
+               printk(KERN_ERR "%s: Failed to create /proc node\n", dev->name);
+               err = -EIO;
+               goto fail;
+       }
+
+       TRACE_EXIT("orinoco_pci");
+
+        return 0;               /* succeeded */
+ fail:
+       printk(KERN_DEBUG "orinoco_pci: init_one(), FAIL!\n");
+
+       if (priv) {
+               orinoco_proc_dev_cleanup(priv);
+               if (netdev_registered)
+                       unregister_netdev(dev);
+
+               if (dev->irq)
+                       free_irq(dev->irq, priv);
+
+               kfree(priv);
+       }
+
+       if (pci_ioaddr)
+               iounmap(pci_ioaddr);
+
+       return err;
+}
+
+static void __devexit orinoco_pci_remove_one(struct pci_dev *pdev)
+{
+       struct orinoco_private *priv = pci_get_drvdata(pdev);
+       struct net_device *dev = priv->ndev;
+
+       TRACE_ENTER("orinoco_pci");
+
+       if (!priv)
+               BUG();
+
+       orinoco_proc_dev_cleanup(priv);
+
+       unregister_netdev(dev);
+
+        if (dev->irq)
+               free_irq(dev->irq, priv);
+
+       if (priv->hw.iobase)
+               iounmap((unsigned char *) priv->hw.iobase);
+
+       kfree(priv);
+
+       pci_disable_device(pdev);
+
+       TRACE_EXIT("orinoco_pci");
+}
+
+
+static struct pci_device_id orinoco_pci_pci_id_table[] __devinitdata = {
+       {0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID,},
+       {0,},
+};
+
+MODULE_DEVICE_TABLE(pci, orinoco_pci_pci_id_table);
+
+static struct pci_driver orinoco_pci_driver = {
+       name:"orinoco_pci",
+       id_table:orinoco_pci_pci_id_table,
+       probe:orinoco_pci_init_one,
+       remove:orinoco_pci_remove_one,
+       suspend:0,
+       resume:0
+};
+
+static int __init orinoco_pci_init(void)
+{
+       return pci_module_init(&orinoco_pci_driver);
+}
+
+extern void __exit orinoco_pci_exit(void)
+{
+       pci_unregister_driver(&orinoco_pci_driver);
+}
+
+module_init(orinoco_pci_init);
+module_exit(orinoco_pci_exit);
+
+/*
+ * Local variables:
+ *  c-indent-level: 8
+ *  c-basic-offset: 8
+ *  tab-width: 8
+ * End:
+ */
index 0bdd8a952cf7159b76d2ed14e8a8e1b6789266de..1e1d8bf0ef09d9597329d0cba998a1bef722ad9b 100644 (file)
@@ -1,16 +1,8 @@
-/* orinoco_plx.c 0.01
+/* orinoco_plx.c 0.11a
  * 
  * Driver for Prism II devices which would usually be driven by orinoco_cs,
  * but are connected to the PCI bus by a PLX9052. 
  *
- * Specifically here we're talking about the SMC2602W (EZConnect
- * Wireless PCI Adaptor)
- *
- * The actual driving is done by orinoco.c, this is just resource
- * allocation stuff.  The explanation below is courtesy of Ryan Niemi
- * on the linux-wlan-ng list at
- * http://archives.neohapsis.com/archives/dev/linux-wlan/2001-q1/0026.html
- *
  * Copyright (C) 2001 Daniel Barlow <dan@telent.net>
  *
  * The contents of this file are subject to the Mozilla Public License
  * provisions above, a recipient may use your version of this file
  * under either the MPL or the GPL.
 
+ * Caution: this is experimental and probably buggy.  For success and
+ * failure reports for different cards and adaptors, see
+ * orinoco_plx_pci_id_table near the end of the file.  If you have a
+ * card we don't have the PCI id for, and looks like it should work,
+ * drop me mail with the id and "it works"/"it doesn't work".
+ *
+ * Note: if everything gets detected fine but it doesn't actually send
+ * or receive packets, your first port of call should probably be to   
+ * try newer firmware in the card.  Especially if you're doing Ad-Hoc
+ * modes
+ *
+ * The actual driving is done by orinoco.c, this is just resource
+ * allocation stuff.  The explanation below is courtesy of Ryan Niemi
+ * on the linux-wlan-ng list at
+ * http://archives.neohapsis.com/archives/dev/linux-wlan/2001-q1/0026.html
+
 The PLX9052-based cards (WL11000 and several others) are a different
 beast than the usual PCMCIA-based PRISM2 configuration expected by
 wlan-ng. Here's the general details on how the WL11000 PCI adapter
@@ -95,14 +103,6 @@ to implement support myself yet, and with the way things are going, might
 not have time for a while..
 
 ---end of mail---
-
-  Bus  0, device   4, function  0:
-    Network controller: Unknown vendor Unknown device (rev 2).
-      Vendor id=1638. Device id=1100.
-      Medium devsel.  Fast back-to-back capable.  IRQ 10.  
-      I/O at 0x1000 [0x1001].
-      Non-prefetchable 32 bit memory at 0x40000000 [0x40000000].
-      I/O at 0x10c0 [0x10c1].
 */
 
 #include <linux/config.h>
@@ -129,36 +129,36 @@ not have time for a while..
 #include <linux/wireless.h>
 #include <linux/fcntl.h>
 
-#include <pcmcia/version.h>
-#include <pcmcia/cs_types.h>
-#include <pcmcia/cs.h>
-#include <pcmcia/cistpl.h>
 #include <pcmcia/cisreg.h>
-#include <pcmcia/ds.h>
-#include <pcmcia/bus_ops.h>
 
 #include "hermes.h"
 #include "orinoco.h"
 
+static char version[] __initdata = "orinoco_plx.c 0.11a (Daniel Barlow <dan@telent.net>)";
 MODULE_AUTHOR("Daniel Barlow <dan@telent.net>");
 MODULE_DESCRIPTION("Driver for wireless LAN cards using the PLX9052 PCI bridge");
+#ifdef MODULE_LICENSE
 MODULE_LICENSE("Dual MPL/GPL");
+#endif
 
-static dev_info_t dev_info = "orinoco_plx";
+static char dev_info[] = "orinoco_plx";
 
-#define COR_OFFSET    0x3e0    /* COR attribute offset of Prism2 PC card */
-#define COR_VALUE     0x41     /* Enable PC card with interrupt in level trigger */
+#define COR_OFFSET    (0x3e0 / 2)      /* COR attribute offset of Prism2 PC card */
+#define COR_VALUE     (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
+
+#define PLX_INTCSR       0x4c /* Interrupt Control and Status Register */
+#define PLX_INTCSR_INTEN (1<<6) /* Interrupt Enable bit */
 
 static int orinoco_plx_open(struct net_device *dev)
 {
-       dldwd_priv_t *priv = (dldwd_priv_t *) dev->priv;
+       struct orinoco_private *priv = (struct orinoco_private *) dev->priv;
        int err;
 
        netif_device_attach(dev);
 
-       err = dldwd_reset(priv);
+       err = orinoco_reset(priv);
        if (err)
-               printk(KERN_ERR "%s: dldwd_reset failed in orinoco_plx_open()",
+               printk(KERN_ERR "%s: orinoco_reset failed in orinoco_plx_open()",
                       dev->name);
        else
                netif_start_queue(dev);
@@ -168,110 +168,204 @@ static int orinoco_plx_open(struct net_device *dev)
 
 static int orinoco_plx_stop(struct net_device *dev)
 {
-       dldwd_priv_t *priv = (dldwd_priv_t *) dev->priv;
+       struct orinoco_private *priv = (struct orinoco_private *) dev->priv;
        netif_stop_queue(dev);
-       dldwd_shutdown(priv);
+       orinoco_shutdown(priv);
        return 0;
 }
 
 static void
 orinoco_plx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
-       dldwd_interrupt(irq, ((struct net_device *) dev_id)->priv, regs);
+       orinoco_interrupt(irq, (struct orinoco_private *)dev_id, regs);
 }
 
+static const u16 cis_magic[] = {
+       0x0001, 0x0003, 0x0000, 0x0000, 0x00ff, 0x0017, 0x0004, 0x0067
+};
+
 static int orinoco_plx_init_one(struct pci_dev *pdev,
                                const struct pci_device_id *ent)
 {
-       struct net_device *dev;
-       unsigned long pccard_ioaddr;
+       int err = 0;
+       u16 *attr_mem = NULL;
+       u32 reg, addr;
+       struct orinoco_private *priv = NULL;
+       unsigned long pccard_ioaddr = 0;
+       unsigned long pccard_iolen = 0;
+       struct net_device *dev = NULL;
+       int netdev_registered = 0;
        int i;
-       int reg;
-       unsigned char *attr_mem;
-       dldwd_priv_t *priv;
 
-       if ((i = pci_enable_device(pdev)))
+       TRACE_ENTER("orinoco_plx");
+
+       err = pci_enable_device(pdev);
+       if (err)
                return -EIO;
 
        /* Resource 2 is mapped to the PCMCIA space */
-       attr_mem = ioremap(pci_resource_start(pdev, 2), 0x1000);
-       /* and 3 to the PCMCIA slot I/O address space */
-       pccard_ioaddr = pci_resource_start(pdev, 3);
+       attr_mem = ioremap(pci_resource_start(pdev, 2), PAGE_SIZE);
+       if (! attr_mem)
+               goto fail;
+
+       printk(KERN_DEBUG "orinoco_plx: CIS: ");
+       for (i = 0; i < 16; i++) {
+               printk("%02X:", (int)attr_mem[i]);
+       }
+       printk("\n");
 
        /* Verify whether PC card is present */
-       if (attr_mem[0] != 0x01 || attr_mem[2] != 0x03 ||
-           attr_mem[4] != 0x00 || attr_mem[6] != 0x00 ||
-           attr_mem[8] != 0xFF || attr_mem[10] != 0x17 ||
-           attr_mem[12] != 0x04 || attr_mem[14] != 0x67) {
+       /* FIXME: we probably need to be smarted about this */
+       if (memcmp(attr_mem, cis_magic, sizeof(cis_magic)) != 0) {
                printk(KERN_ERR "orinoco_plx: The CIS value of Prism2 PC card is invalid.\n");
-               return -EIO;
+               err = -EIO;
+               goto fail;
        }
+
        /* PCMCIA COR is the first byte following CIS: this write should
         * enable I/O mode and select level-triggered interrupts */
        attr_mem[COR_OFFSET] = COR_VALUE;
+       mdelay(1);
        reg = attr_mem[COR_OFFSET];
-       /* assert(reg==COR_VALUE); doesn't work */
-       iounmap(attr_mem);      /* done with this now, it seems */
-       if (!request_region(pccard_ioaddr,
-                           pci_resource_len(pdev, 3), dev_info)) {
+       if (reg != COR_VALUE) {
+               printk(KERN_ERR "orinoco_plx: Error setting COR value (reg=%x)\n", reg);
+               goto fail;
+       }                       
+
+       iounmap(attr_mem);
+       attr_mem = NULL; /* done with this now, it seems */
+
+       /* bjoern: We need to tell the card to enable interrupts, in
+          case the serial eprom didn't do this already. See the
+          PLX9052 data book, p8-1 and 8-24 for reference. */
+       addr = pci_resource_start(pdev, 1);
+       reg = 0;
+       reg = inl(addr+PLX_INTCSR);
+       if(reg & PLX_INTCSR_INTEN)
+               printk(KERN_DEBUG "orinoco_plx: "
+                      "Local Interrupt already enabled\n");
+       else {
+               reg |= PLX_INTCSR_INTEN;
+               outl(reg, addr+PLX_INTCSR);
+               reg = inl(addr+PLX_INTCSR);
+               if(!(reg & PLX_INTCSR_INTEN)) {
+                       printk(KERN_ERR "orinoco_plx: "
+                              "Couldn't enable Local Interrupts\n");
+                       goto fail;
+               }
+       }
+
+       /* and 3 to the PCMCIA slot I/O address space */
+       pccard_ioaddr = pci_resource_start(pdev, 3);
+       pccard_iolen = pci_resource_len(pdev, 3);
+       if (! request_region(pccard_ioaddr, pccard_iolen, dev_info)) {
                printk(KERN_ERR "orinoco_plx: I/O resource 0x%lx @ 0x%lx busy\n",
-                      pci_resource_len(pdev, 3), pccard_ioaddr);
-               return -EBUSY;
+                      pccard_iolen, pccard_ioaddr);
+               pccard_ioaddr = 0;
+               err = -EBUSY;
+               goto fail;
        }
-       if (!(priv = kmalloc(sizeof(*priv), GFP_KERNEL)))
-               return -ENOMEM;
-       memset(priv, 0, sizeof(*priv));
-       dev = &priv->ndev;
 
-       dldwd_setup(priv);      /* XXX clean up if <0 */
-       dev->irq = pdev->irq;
+       dev = alloc_orinocodev(0);
+       if (! dev) {
+               err = -ENOMEM;
+               goto fail;
+       }
+
+       priv = dev->priv;
        dev->base_addr = pccard_ioaddr;
        dev->open = orinoco_plx_open;
        dev->stop = orinoco_plx_stop;
-       priv->card_reset_handler = NULL; /* We have no reset handler */
+       SET_MODULE_OWNER(dev);
 
        printk(KERN_DEBUG
-              "Detected Orinoco/Prism2 PCI device at %s, mem:0x%lx, irq:%d, io addr:0x%lx\n",
-              pdev->slot_name, (long) attr_mem, pdev->irq, pccard_ioaddr);
-
-       hermes_struct_init(&(priv->hw), dev->base_addr);        /* XXX */
-       dev->name[0] = '\0';    /* name defaults to ethX */
-       register_netdev(dev);
-       request_irq(pdev->irq, orinoco_plx_interrupt, SA_SHIRQ, dev->name,
-                   dev);
-       if (dldwd_proc_dev_init(priv) != 0) {
-               printk(KERN_ERR "%s: Failed to create /proc node\n", dev->name);
-               return -EIO;
+              "Detected Orinoco/Prism2 PLX device at %s irq:%d, io addr:0x%lx\n",
+              pdev->slot_name, pdev->irq, pccard_ioaddr);
+
+       hermes_struct_init(&(priv->hw), dev->base_addr,
+                       HERMES_IO, HERMES_16BIT_REGSPACING);
+       pci_set_drvdata(pdev, priv);
+
+       err = request_irq(pdev->irq, orinoco_plx_interrupt, SA_SHIRQ, dev->name, priv);
+       if (err) {
+               printk(KERN_ERR "orinoco_plx: Error allocating IRQ %d.\n", pdev->irq);
+               err = -EBUSY;
+               goto fail;
        }
+       dev->irq = pdev->irq;
 
-       SET_MODULE_OWNER(dev);
-       priv->hw_ready = 1;
+       err = register_netdev(dev);
+       if (err)
+               goto fail;
+       netdev_registered = 1;
+
+       err = orinoco_proc_dev_init(priv);
+       if (err)
+               goto fail;
+
+       TRACE_EXIT("orinoco_plx");
 
-       /* if(reset_cor) dldwd_cs_cor_reset(priv); */
        return 0;               /* succeeded */
+
+ fail: 
+       printk(KERN_DEBUG "orinoco_plx: init_one(), FAIL!\n");
+
+       if (priv) {
+               orinoco_proc_dev_cleanup(priv);
+
+               if (netdev_registered)
+                       unregister_netdev(dev);
+               
+               if (dev->irq)
+                       free_irq(dev->irq, priv);
+               
+               kfree(priv);
+       }
+
+       if (pccard_ioaddr)
+               release_region(pccard_ioaddr, pccard_iolen);
+
+       if (attr_mem)
+               iounmap(attr_mem);
+
+       pci_disable_device(pdev);
+
+       TRACE_EXIT("orinoco_plx");
+       
+       return err;
 }
 
 static void __devexit orinoco_plx_remove_one(struct pci_dev *pdev)
 {
-       struct net_device *dev = pci_get_drvdata(pdev);
-       dldwd_priv_t *priv = dev->priv;
+       struct orinoco_private *priv = pci_get_drvdata(pdev);
+       struct net_device *dev = priv->ndev;
+
+       TRACE_ENTER("orinoco_plx");
 
-       if (!dev)
+       if (!priv)
                BUG();
 
-       dldwd_proc_dev_cleanup(priv);
-       free_irq(dev->irq, dev);
+       orinoco_proc_dev_cleanup(priv);
+
        unregister_netdev(dev);
-       release_region(dev->base_addr, 0x40);
-       kfree(dev->priv);
-       pci_set_drvdata(pdev, NULL);
+               
+       if (dev->irq)
+               free_irq(dev->irq, priv);
+               
+       kfree(priv);
+
+       release_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3));
+
+       pci_disable_device(pdev);
+
+       TRACE_EXIT("orinoco_plx");
 }
 
+
 static struct pci_device_id orinoco_plx_pci_id_table[] __devinitdata = {
+       {0x111a, 0x1023, PCI_ANY_ID, PCI_ANY_ID,},      /* Siemens SpeedStream SS1023 */
        {0x1385, 0x4100, PCI_ANY_ID, PCI_ANY_ID,},      /* Netgear MA301 */
-#if 0
-       {0x15e8, 0x0130, PCI_ANY_ID, PCI_ANY_ID,},      /* Correga */
-#endif
+       {0x15e8, 0x0130, PCI_ANY_ID, PCI_ANY_ID,},      /* Correga  - does this work? */
        {0x1638, 0x1100, PCI_ANY_ID, PCI_ANY_ID,},      /* SMC EZConnect SMC2602W,
                                                           Eumitcom PCI WL11000,
                                                           Addtron AWA-100*/
@@ -279,26 +373,34 @@ static struct pci_device_id orinoco_plx_pci_id_table[] __devinitdata = {
        {0x16ab, 0x1101, PCI_ANY_ID, PCI_ANY_ID,},      /* Reported working, but unknown */
        {0x16ab, 0x1102, PCI_ANY_ID, PCI_ANY_ID,},      /* Linksys WDT11 */
        {0x16ec, 0x3685, PCI_ANY_ID, PCI_ANY_ID,},      /* USR 2415 */
-       {0xec80, 0xec00, PCI_ANY_ID, PCI_ANY_ID,},      /* Belkin F5D6000 */
+       {0xec80, 0xec00, PCI_ANY_ID, PCI_ANY_ID,},      /* Belkin F5D6000 tested by
+                                                          Brendan W. McAdams <rit@jacked-in.org> */
+       {0x126c, 0x8030, PCI_ANY_ID, PCI_ANY_ID,},      /* Nortel emobility */
        {0,},
 };
+
 MODULE_DEVICE_TABLE(pci, orinoco_plx_pci_id_table);
 
 static struct pci_driver orinoco_plx_driver = {
-       name:           "orinoco_plx",
-       id_table:       orinoco_plx_pci_id_table,
-       probe:          orinoco_plx_init_one,
-       remove:         __devexit_p(orinoco_plx_remove_one),
+       name:"orinoco_plx",
+       id_table:orinoco_plx_pci_id_table,
+       probe:orinoco_plx_init_one,
+       remove:orinoco_plx_remove_one,
+       suspend:0,
+       resume:0
 };
 
 static int __init orinoco_plx_init(void)
 {
+       printk(KERN_DEBUG "%s\n", version);
        return pci_module_init(&orinoco_plx_driver);
 }
 
 extern void __exit orinoco_plx_exit(void)
 {
        pci_unregister_driver(&orinoco_plx_driver);
+       current->state = TASK_UNINTERRUPTIBLE;
+       schedule_timeout(HZ);
 }
 
 module_init(orinoco_plx_init);