fec_mpc52xx: write in C...
[safe/jmp/linux-2.6] / drivers / net / wireless / netwave_cs.c
index 2a68886..d2fa079 100644 (file)
@@ -4,18 +4,18 @@
  * Version:       0.4.1
  * Description:   Netwave AirSurfer Wireless LAN PC Card driver
  * Status:        Experimental.
- * Authors:       John Markus Bjørndalen <johnm@cs.uit.no>
+ * Authors:       John Markus Bjørndalen <johnm@cs.uit.no>
  *                Dag Brattli <dagb@cs.uit.no>
  *                David Hinds <dahinds@users.sourceforge.net>
  * Created at:    A long time ago!
  * Modified at:   Mon Nov 10 11:54:37 1997
  * Modified by:   Dag Brattli <dagb@cs.uit.no>
  * 
- *     Copyright (c) 1997 University of Tromsø, Norway
+ *     Copyright (c) 1997 University of Tromsø, Norway
  *
  * Revision History:
  *
- *   08-Nov-97 15:14:47   John Markus Bjørndalen <johnm@cs.uit.no>
+ *   08-Nov-97 15:14:47   John Markus Bjørndalen <johnm@cs.uit.no>
  *    - Fixed some bugs in netwave_rx and cleaned it up a bit. 
  *      (One of the bugs would have destroyed packets when receiving
  *      multiple packets per interrupt). 
@@ -37,7 +37,6 @@
 /* To have statistics (just packets sent) define this */
 #undef NETWAVE_STATS
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
@@ -159,7 +158,7 @@ static int pc_debug = PCMCIA_DEBUG;
 module_param(pc_debug, int, 0);
 #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
 static char *version =
-"netwave_cs.c 0.3.0 Thu Jul 17 14:36:02 1997 (John Markus Bjørndalen)\n";
+"netwave_cs.c 0.3.0 Thu Jul 17 14:36:02 1997 (John Markus Bjørndalen)\n";
 #else
 #define DEBUG(n, args...)
 #endif
@@ -191,7 +190,7 @@ module_param(mem_speed, int, 0);
 
 /* PCMCIA (Card Services) related functions */
 static void netwave_release(struct pcmcia_device *link);     /* Card removal */
-static void netwave_pcmcia_config(struct pcmcia_device *arg); /* Runs after card
+static int netwave_pcmcia_config(struct pcmcia_device *arg); /* Runs after card
                                                                                                           insertion */
 static void netwave_detach(struct pcmcia_device *p_dev);    /* Destroy instance */
 
@@ -208,7 +207,7 @@ static int netwave_start_xmit( struct sk_buff *skb, struct net_device *dev);
 static int netwave_rx( struct net_device *dev);
 
 /* Interrupt routines */
-static irqreturn_t netwave_interrupt(int irq, void *dev_id, struct pt_regs *regs);
+static irqreturn_t netwave_interrupt(int irq, void *dev_id);
 static void netwave_watchdog(struct net_device *);
 
 /* Statistics */
@@ -376,7 +375,7 @@ static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
  *     configure the card at this point -- we wait until we receive a
  *     card insertion event.
  */
-static int netwave_attach(struct pcmcia_device *link)
+static int netwave_probe(struct pcmcia_device *link)
 {
     struct net_device *dev;
     netwave_private *priv;
@@ -407,14 +406,12 @@ static int netwave_attach(struct pcmcia_device *link)
     link->conf.Attributes = CONF_ENABLE_IRQ;
     link->conf.IntType = INT_MEMORY_AND_IO;
     link->conf.ConfigIndex = 1;
-    link->conf.Present = PRESENT_OPTION;
 
     /* Netwave private struct init. link/dev/node already taken care of,
      * other stuff zero'd - Jean II */
     spin_lock_init(&priv->spinlock);
 
     /* Netwave specific entries in the device structure */
-    SET_MODULE_OWNER(dev);
     dev->hard_start_xmit = &netwave_start_xmit;
     dev->get_stats  = &netwave_get_stats;
     dev->set_multicast_list = &set_multicast_list;
@@ -428,10 +425,7 @@ static int netwave_attach(struct pcmcia_device *link)
     dev->stop = &netwave_close;
     link->irq.Instance = dev;
 
-    link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
-    netwave_pcmcia_config( link);
-
-    return 0;
+    return netwave_pcmcia_config( link);
 } /* netwave_attach */
 
 /*
@@ -448,8 +442,7 @@ static void netwave_detach(struct pcmcia_device *link)
 
        DEBUG(0, "netwave_detach(0x%p)\n", link);
 
-       if (link->state & DEV_CONFIG)
-               netwave_release(link);
+       netwave_release(link);
 
        if (link->dev_node)
                unregister_netdev(dev);
@@ -716,9 +709,9 @@ static const iw_handler             netwave_private_handler[] =
 
 static const struct iw_handler_def     netwave_handler_def =
 {
-       .num_standard   = sizeof(netwave_handler)/sizeof(iw_handler),
-       .num_private    = sizeof(netwave_private_handler)/sizeof(iw_handler),
-       .num_private_args = sizeof(netwave_private_args)/sizeof(struct iw_priv_args),
+       .num_standard   = ARRAY_SIZE(netwave_handler),
+       .num_private    = ARRAY_SIZE(netwave_private_handler),
+       .num_private_args = ARRAY_SIZE(netwave_private_args),
        .standard       = (iw_handler *) netwave_handler,
        .private        = (iw_handler *) netwave_private_handler,
        .private_args   = (struct iw_priv_args *) netwave_private_args,
@@ -737,38 +730,18 @@ static const struct iw_handler_def        netwave_handler_def =
 #define CS_CHECK(fn, ret) \
 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
-static void netwave_pcmcia_config(struct pcmcia_device *link) {
+static int netwave_pcmcia_config(struct pcmcia_device *link) {
     struct net_device *dev = link->priv;
     netwave_private *priv = netdev_priv(dev);
-    tuple_t tuple;
-    cisparse_t parse;
     int i, j, last_ret, last_fn;
-    u_char buf[64];
     win_req_t req;
     memreq_t mem;
     u_char __iomem *ramBase = NULL;
+    DECLARE_MAC_BUF(mac);
 
     DEBUG(0, "netwave_pcmcia_config(0x%p)\n", link);
 
     /*
-      This reads the card's CONFIG tuple to find its configuration
-      registers.
-    */
-    tuple.Attributes = 0;
-    tuple.TupleData = (cisdata_t *) buf;
-    tuple.TupleDataMax = 64;
-    tuple.TupleOffset = 0;
-    tuple.DesiredTuple = CISTPL_CONFIG;
-    CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-    CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
-    CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
-    link->conf.ConfigBase = parse.config.base;
-    link->conf.Present = parse.config.rmask[0];
-
-    /* Configure card */
-    link->state |= DEV_CONFIG;
-
-    /*
      *  Try allocating IO ports.  This tries a few fixed addresses.
      *  If you want, you can also read the card's config table to
      *  pick addresses -- see the serial driver for an example.
@@ -825,7 +798,6 @@ static void netwave_pcmcia_config(struct pcmcia_device *link) {
 
     strcpy(priv->node.dev_name, dev->name);
     link->dev_node = &priv->node;
-    link->state &= ~DEV_CONFIG_PENDING;
 
     /* Reset card before reading physical address */
     netwave_doreset(dev->base_addr, ramBase);
@@ -834,23 +806,25 @@ static void netwave_pcmcia_config(struct pcmcia_device *link) {
     for (i = 0; i < 6; i++) 
        dev->dev_addr[i] = readb(ramBase + NETWAVE_EREG_PA + i);
 
-    printk(KERN_INFO "%s: Netwave: port %#3lx, irq %d, mem %lx id "
-          "%c%c, hw_addr ", dev->name, dev->base_addr, dev->irq,
-          (u_long) ramBase, (int) readb(ramBase+NETWAVE_EREG_NI),
-          (int) readb(ramBase+NETWAVE_EREG_NI+1));
-    for (i = 0; i < 6; i++)
-       printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
+    printk(KERN_INFO "%s: Netwave: port %#3lx, irq %d, mem %lx, "
+          "id %c%c, hw_addr %s\n",
+          dev->name, dev->base_addr, dev->irq,
+          (u_long) ramBase,
+          (int) readb(ramBase+NETWAVE_EREG_NI),
+          (int) readb(ramBase+NETWAVE_EREG_NI+1),
+          print_mac(mac, dev->dev_addr));
 
     /* get revision words */
     printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n", 
           get_uint16(ramBase + NETWAVE_EREG_ARW),
           get_uint16(ramBase + NETWAVE_EREG_ARW+2));
-    return;
+    return 0;
 
 cs_failed:
     cs_error(link, last_fn, last_ret);
 failed:
     netwave_release(link);
+    return -ENODEV;
 } /* netwave_pcmcia_config */
 
 /*
@@ -876,7 +850,7 @@ static int netwave_suspend(struct pcmcia_device *link)
 {
        struct net_device *dev = link->priv;
 
-       if ((link->state & DEV_CONFIG) && (link->open))
+       if (link->open)
                netif_device_detach(dev);
 
        return 0;
@@ -886,7 +860,7 @@ static int netwave_resume(struct pcmcia_device *link)
 {
        struct net_device *dev = link->priv;
 
-       if ((link->state & DEV_CONFIG) && (link->open)) {
+       if (link->open) {
                netwave_reset(dev);
                netif_device_attach(dev);
        }
@@ -1080,7 +1054,7 @@ static int netwave_start_xmit(struct sk_buff *skb, struct net_device *dev) {
 } /* netwave_start_xmit */
 
 /*
- * Function netwave_interrupt (irq, dev_id, regs)
+ * Function netwave_interrupt (irq, dev_id)
  *
  *    This function is the interrupt handler for the Netwave card. This
  *    routine will be called whenever: 
@@ -1089,7 +1063,7 @@ static int netwave_start_xmit(struct sk_buff *skb, struct net_device *dev) {
  *          ready to transmit another packet.
  *       3. A command has completed execution.
  */
-static irqreturn_t netwave_interrupt(int irq, void* dev_id, struct pt_regs *regs)
+static irqreturn_t netwave_interrupt(int irq, void* dev_id)
 {
     kio_addr_t iobase;
     u_char __iomem *ramBase;
@@ -1114,7 +1088,7 @@ static irqreturn_t netwave_interrupt(int irq, void* dev_id, struct pt_regs *regs
        
         status = inb(iobase + NETWAVE_REG_ASR);
                
-       if (!DEV_OK(link)) {
+       if (!pcmcia_dev_present(link)) {
            DEBUG(1, "netwave_interrupt: Interrupt with status 0x%x "
                  "from removed or suspended card!\n", status);
            break;
@@ -1310,7 +1284,6 @@ static int netwave_rx(struct net_device *dev)
 
        skb_reserve( skb, 2);  /* Align IP on 16 byte */
        skb_put( skb, rcvLen);
-       skb->dev = dev;
 
        /* Copy packet fragments to the skb data area */
        ptr = (u_char*) skb->data;
@@ -1353,7 +1326,7 @@ static int netwave_open(struct net_device *dev) {
 
     DEBUG(1, "netwave_open: starting.\n");
     
-    if (!DEV_OK(link))
+    if (!pcmcia_dev_present(link))
        return -ENODEV;
 
     link->open++;
@@ -1387,7 +1360,7 @@ static struct pcmcia_driver netwave_driver = {
        .drv            = {
                .name   = "netwave_cs",
        },
-       .probe          = netwave_attach,
+       .probe          = netwave_probe,
        .remove         = netwave_detach,
        .id_table       = netwave_ids,
        .suspend        = netwave_suspend,