]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/macsonic.c
net drivers: fix platform driver hotplug/coldplug
[linux-2.6-omap-h63xx.git] / drivers / net / macsonic.c
index 8ca57a0a4c11acb47ece31b99bac91e8887d4066..b267161418ea3680e6bb522ba5d8afd5fbcbedc0 100644 (file)
@@ -130,6 +130,46 @@ static inline void bit_reverse_addr(unsigned char addr[6])
                addr[i] = bitrev8(addr[i]);
 }
 
+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;
+}
+
 int __init macsonic_init(struct net_device* dev)
 {
        struct sonic_local* lp = netdev_priv(dev);
@@ -160,8 +200,8 @@ 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->open = macsonic_open;
+       dev->stop = macsonic_close;
        dev->hard_start_xmit = sonic_send_packet;
        dev->get_stats = sonic_get_stats;
        dev->set_multicast_list = &sonic_multicast_list;
@@ -183,6 +223,7 @@ int __init mac_onboard_sonic_ethernet_addr(struct net_device* dev)
        struct sonic_local *lp = netdev_priv(dev);
        const int prom_addr = ONBOARD_SONIC_PROM_BASE;
        int i;
+       DECLARE_MAC_BUF(mac);
 
        /* On NuBus boards we can sometimes look in the ROM resources.
           No such luck for comm-slot/onboard. */
@@ -226,13 +267,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: %s\n",
+                      print_mac(mac, dev->dev_addr));
        } else return 0;
 
        if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) &&
@@ -402,7 +438,7 @@ int __init macsonic_ident(struct nubus_dev* ndev)
            ndev->dr_sw == NUBUS_DRSW_DAYNA)
                return MACSONIC_DAYNA;
 
-       if (ndev->dr_hw == NUBUS_DRHW_SONIC_LC &&
+       if (ndev->dr_hw == NUBUS_DRHW_APPLE_SONIC_LC &&
            ndev->dr_sw == 0) { /* huh? */
                return MACSONIC_APPLE16;
        }
@@ -522,21 +558,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 __init mac_sonic_probe(struct platform_device *pdev)
 {
        struct net_device *dev;
        struct sonic_local *lp;
        int err;
-       int i;
+       DECLARE_MAC_BUF(mac);
 
        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);
 
        /* This will catch fatal stuff like -ENOMEM as well as success */
        err = mac_onboard_sonic_probe(dev);
@@ -552,13 +587,8 @@ 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 %s IRQ %d\n",
+              dev->name, print_mac(mac, dev->dev_addr), dev->irq);
 
        return 0;
 
@@ -572,19 +602,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 +635,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);