gianfar: keep vlan related state when restart
[safe/jmp/linux-2.6] / drivers / net / macsonic.c
index a3d24a3..61eabca 100644 (file)
@@ -83,9 +83,6 @@ static unsigned int sonic_debug = 1;
 
 static int sonic_version_printed;
 
-extern int mac_onboard_sonic_probe(struct net_device* dev);
-extern int mac_nubus_sonic_probe(struct net_device* dev);
-
 /* For onboard SONIC */
 #define ONBOARD_SONIC_REGISTERS        0x50F0A000
 #define ONBOARD_SONIC_PROM_BASE        0x50f08000
@@ -130,7 +127,59 @@ static inline void bit_reverse_addr(unsigned char addr[6])
                addr[i] = bitrev8(addr[i]);
 }
 
-int __init macsonic_init(struct net_device* dev)
+static irqreturn_t macsonic_interrupt(int irq, void *dev_id)
+{
+       irqreturn_t result;
+       unsigned long flags;
+
+       local_irq_save(flags);
+       result = sonic_interrupt(irq, dev_id);
+       local_irq_restore(flags);
+       return result;
+}
+
+static int macsonic_open(struct net_device* dev)
+{
+       if (request_irq(dev->irq, &sonic_interrupt, IRQ_FLG_FAST, "sonic", dev)) {
+               printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq);
+               return -EAGAIN;
+       }
+       /* Under the A/UX interrupt scheme, the onboard SONIC interrupt comes
+        * in at priority level 3. However, we sometimes get the level 2 inter-
+        * rupt as well, which must prevent re-entrance of the sonic handler.
+        */
+       if (dev->irq == IRQ_AUTO_3)
+               if (request_irq(IRQ_NUBUS_9, &macsonic_interrupt, IRQ_FLG_FAST, "sonic", dev)) {
+                       printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, IRQ_NUBUS_9);
+                       free_irq(dev->irq, dev);
+                       return -EAGAIN;
+               }
+       return sonic_open(dev);
+}
+
+static int macsonic_close(struct net_device* dev)
+{
+       int err;
+       err = sonic_close(dev);
+       free_irq(dev->irq, dev);
+       if (dev->irq == IRQ_AUTO_3)
+               free_irq(IRQ_NUBUS_9, dev);
+       return err;
+}
+
+static const struct net_device_ops macsonic_netdev_ops = {
+       .ndo_open               = macsonic_open,
+       .ndo_stop               = macsonic_close,
+       .ndo_start_xmit         = sonic_send_packet,
+       .ndo_set_multicast_list = sonic_multicast_list,
+       .ndo_tx_timeout         = sonic_tx_timeout,
+       .ndo_get_stats          = sonic_get_stats,
+       .ndo_validate_addr      = eth_validate_addr,
+       .ndo_change_mtu         = eth_change_mtu,
+       .ndo_set_mac_address    = eth_mac_addr,
+};
+
+static int __devinit macsonic_init(struct net_device *dev)
 {
        struct sonic_local* lp = netdev_priv(dev);
 
@@ -139,7 +188,8 @@ int __init macsonic_init(struct net_device* dev)
        if ((lp->descriptors = dma_alloc_coherent(lp->device,
                    SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
                    &lp->descriptors_laddr, GFP_KERNEL)) == NULL) {
-               printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n", lp->device->bus_id);
+               printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n",
+                      dev_name(lp->device));
                return -ENOMEM;
        }
 
@@ -160,12 +210,7 @@ int __init macsonic_init(struct net_device* dev)
        lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
                             * SONIC_BUS_SCALE(lp->dma_bitmode));
 
-       dev->open = sonic_open;
-       dev->stop = sonic_close;
-       dev->hard_start_xmit = sonic_send_packet;
-       dev->get_stats = sonic_get_stats;
-       dev->set_multicast_list = &sonic_multicast_list;
-       dev->tx_timeout = sonic_tx_timeout;
+       dev->netdev_ops = &macsonic_netdev_ops;
        dev->watchdog_timeo = TX_TIMEOUT;
 
        /*
@@ -178,7 +223,7 @@ int __init macsonic_init(struct net_device* dev)
        return 0;
 }
 
-int __init mac_onboard_sonic_ethernet_addr(struct net_device* dev)
+static int __devinit mac_onboard_sonic_ethernet_addr(struct net_device *dev)
 {
        struct sonic_local *lp = netdev_priv(dev);
        const int prom_addr = ONBOARD_SONIC_PROM_BASE;
@@ -226,13 +271,8 @@ int __init mac_onboard_sonic_ethernet_addr(struct net_device* dev)
                dev->dev_addr[1] = val >> 8;
                dev->dev_addr[0] = val & 0xff;
 
-               printk(KERN_INFO "HW Address from CAM 15: ");
-               for (i = 0; i < 6; i++) {
-                       printk("%2.2x", dev->dev_addr[i]);
-                       if (i < 5)
-                               printk(":");
-               }
-               printk("\n");
+               printk(KERN_INFO "HW Address from CAM 15: %pM\n",
+                      dev->dev_addr);
        } else return 0;
 
        if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) &&
@@ -248,7 +288,7 @@ int __init mac_onboard_sonic_ethernet_addr(struct net_device* dev)
        } else return 0;
 }
 
-int __init mac_onboard_sonic_probe(struct net_device* dev)
+static int __devinit mac_onboard_sonic_probe(struct net_device *dev)
 {
        /* Bwahahaha */
        static int once_is_more_than_enough;
@@ -305,7 +345,7 @@ int __init mac_onboard_sonic_probe(struct net_device* dev)
                sonic_version_printed = 1;
        }
        printk(KERN_INFO "%s: onboard / comm-slot SONIC at 0x%08lx\n",
-              lp->device->bus_id, dev->base_addr);
+              dev_name(lp->device), dev->base_addr);
 
        /* The PowerBook's SONIC is 16 bit always. */
        if (macintosh_config->ident == MAC_MODEL_PB520) {
@@ -338,10 +378,10 @@ int __init mac_onboard_sonic_probe(struct net_device* dev)
        }
        printk(KERN_INFO
               "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
-              lp->device->bus_id, sr, lp->dma_bitmode?32:16, lp->reg_offset);
+              dev_name(lp->device), sr, lp->dma_bitmode?32:16, lp->reg_offset);
 
 #if 0 /* This is sometimes useful to find out how MacOS configured the card. */
-       printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", lp->device->bus_id,
+       printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", dev_name(lp->device),
               SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff);
 #endif
 
@@ -369,9 +409,9 @@ int __init mac_onboard_sonic_probe(struct net_device* dev)
        return macsonic_init(dev);
 }
 
-int __init mac_nubus_sonic_ethernet_addr(struct net_device* dev,
-                                        unsigned long prom_addr,
-                                        int id)
+static int __devinit mac_nubus_sonic_ethernet_addr(struct net_device *dev,
+                                               unsigned long prom_addr,
+                                               int id)
 {
        int i;
        for(i = 0; i < 6; i++)
@@ -384,7 +424,7 @@ int __init mac_nubus_sonic_ethernet_addr(struct net_device* dev,
        return 0;
 }
 
-int __init macsonic_ident(struct nubus_dev* ndev)
+static int __devinit macsonic_ident(struct nubus_dev *ndev)
 {
        if (ndev->dr_hw == NUBUS_DRHW_ASANTE_LC &&
            ndev->dr_sw == NUBUS_DRSW_SONIC_LC)
@@ -409,7 +449,7 @@ int __init macsonic_ident(struct nubus_dev* ndev)
        return -1;
 }
 
-int __init mac_nubus_sonic_probe(struct net_device* dev)
+static int __devinit mac_nubus_sonic_probe(struct net_device *dev)
 {
        static int slots;
        struct nubus_dev* ndev = NULL;
@@ -493,12 +533,12 @@ int __init mac_nubus_sonic_probe(struct net_device* dev)
                sonic_version_printed = 1;
        }
        printk(KERN_INFO "%s: %s in slot %X\n",
-              lp->device->bus_id, ndev->board->name, ndev->board->slot);
+              dev_name(lp->device), ndev->board->name, ndev->board->slot);
        printk(KERN_INFO "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
-              lp->device->bus_id, SONIC_READ(SONIC_SR), dma_bitmode?32:16, reg_offset);
+              dev_name(lp->device), SONIC_READ(SONIC_SR), dma_bitmode?32:16, reg_offset);
 
 #if 0 /* This is sometimes useful to find out how MacOS configured the card. */
-       printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", lp->device->bus_id,
+       printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", dev_name(lp->device),
               SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff);
 #endif
 
@@ -522,21 +562,20 @@ int __init mac_nubus_sonic_probe(struct net_device* dev)
        return macsonic_init(dev);
 }
 
-static int __init mac_sonic_probe(struct platform_device *device)
+static int __devinit mac_sonic_probe(struct platform_device *pdev)
 {
        struct net_device *dev;
        struct sonic_local *lp;
        int err;
-       int i;
 
        dev = alloc_etherdev(sizeof(struct sonic_local));
        if (!dev)
                return -ENOMEM;
 
        lp = netdev_priv(dev);
-       lp->device = &device->dev;
-       SET_NETDEV_DEV(dev, &device->dev);
-       SET_MODULE_OWNER(dev);
+       lp->device = &pdev->dev;
+       SET_NETDEV_DEV(dev, &pdev->dev);
+       platform_set_drvdata(pdev, dev);
 
        /* This will catch fatal stuff like -ENOMEM as well as success */
        err = mac_onboard_sonic_probe(dev);
@@ -552,13 +591,7 @@ found:
        if (err)
                goto out;
 
-       printk("%s: MAC ", dev->name);
-       for (i = 0; i < 6; i++) {
-               printk("%2.2x", dev->dev_addr[i]);
-               if (i < 5)
-                       printk(":");
-       }
-       printk(" IRQ %d\n", dev->irq);
+       printk("%s: MAC %pM IRQ %d\n", dev->name, dev->dev_addr, dev->irq);
 
        return 0;
 
@@ -572,19 +605,17 @@ MODULE_DESCRIPTION("Macintosh SONIC ethernet driver");
 module_param(sonic_debug, int, 0);
 MODULE_PARM_DESC(sonic_debug, "macsonic debug level (1-4)");
 
-#define SONIC_IRQ_FLAG IRQ_FLG_FAST
-
 #include "sonic.c"
 
-static int __devexit mac_sonic_device_remove (struct platform_device *device)
+static int __devexit mac_sonic_device_remove (struct platform_device *pdev)
 {
-       struct net_device *dev = platform_get_drvdata(device);
+       struct net_device *dev = platform_get_drvdata(pdev);
        struct sonic_local* lp = netdev_priv(dev);
 
-       unregister_netdev (dev);
+       unregister_netdev(dev);
        dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
                          lp->descriptors, lp->descriptors_laddr);
-       free_netdev (dev);
+       free_netdev(dev);
 
        return 0;
 }
@@ -607,9 +638,8 @@ static int __init mac_sonic_init_module(void)
        }
 
        mac_sonic_device = platform_device_alloc(mac_sonic_string, 0);
-       if (!mac_sonic_device) {
+       if (!mac_sonic_device)
                goto out_unregister;
-       }
 
        if (platform_device_add(mac_sonic_device)) {
                platform_device_put(mac_sonic_device);