drivers/video/msm: update to new kernel
[safe/jmp/linux-2.6] / drivers / net / macsonic.c
index a55a839..b3d7d8d 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
@@ -170,7 +167,19 @@ static int macsonic_close(struct net_device* dev)
        return err;
 }
 
-int __init macsonic_init(struct net_device* dev)
+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);
 
@@ -179,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;
        }
 
@@ -200,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 = 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;
-       dev->tx_timeout = sonic_tx_timeout;
+       dev->netdev_ops = &macsonic_netdev_ops;
        dev->watchdog_timeo = TX_TIMEOUT;
 
        /*
@@ -218,77 +223,76 @@ int __init macsonic_init(struct net_device* dev)
        return 0;
 }
 
-int __init mac_onboard_sonic_ethernet_addr(struct net_device* dev)
+#define INVALID_MAC(mac) (memcmp(mac, "\x08\x00\x07", 3) && \
+                          memcmp(mac, "\x00\xA0\x40", 3) && \
+                          memcmp(mac, "\x00\x80\x19", 3) && \
+                          memcmp(mac, "\x00\x05\x02", 3))
+
+static void __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;
-       int i;
+       unsigned short val;
 
-       /* On NuBus boards we can sometimes look in the ROM resources.
-          No such luck for comm-slot/onboard. */
-       for(i = 0; i < 6; i++)
-               dev->dev_addr[i] = SONIC_READ_PROM(i);
+       /*
+        * On NuBus boards we can sometimes look in the ROM resources.
+        * No such luck for comm-slot/onboard.
+        * On the PowerBook 520, the PROM base address is a mystery.
+        */
+       if (hwreg_present((void *)prom_addr)) {
+               int i;
 
-       /* Most of the time, the address is bit-reversed.  The NetBSD
-          source has a rather long and detailed historical account of
-          why this is so. */
-       if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) &&
-           memcmp(dev->dev_addr, "\x00\xA0\x40", 3) &&
-           memcmp(dev->dev_addr, "\x00\x80\x19", 3) &&
-           memcmp(dev->dev_addr, "\x00\x05\x02", 3))
+               for (i = 0; i < 6; i++)
+                       dev->dev_addr[i] = SONIC_READ_PROM(i);
+               if (!INVALID_MAC(dev->dev_addr))
+                       return;
+
+               /*
+                * Most of the time, the address is bit-reversed. The NetBSD
+                * source has a rather long and detailed historical account of
+                * why this is so.
+                */
                bit_reverse_addr(dev->dev_addr);
-       else
-               return 0;
-
-       /* If we still have what seems to be a bogus address, we'll
-           look in the CAM.  The top entry should be ours. */
-       /* Danger! This only works if MacOS has already initialized
-           the card... */
-       if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) &&
-           memcmp(dev->dev_addr, "\x00\xA0\x40", 3) &&
-           memcmp(dev->dev_addr, "\x00\x80\x19", 3) &&
-           memcmp(dev->dev_addr, "\x00\x05\x02", 3))
-       {
-               unsigned short val;
-
-               printk(KERN_INFO "macsonic: PROM seems to be wrong, trying CAM entry 15\n");
-
-               SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
-               SONIC_WRITE(SONIC_CEP, 15);
-
-               val = SONIC_READ(SONIC_CAP2);
-               dev->dev_addr[5] = val >> 8;
-               dev->dev_addr[4] = val & 0xff;
-               val = SONIC_READ(SONIC_CAP1);
-               dev->dev_addr[3] = val >> 8;
-               dev->dev_addr[2] = val & 0xff;
-               val = SONIC_READ(SONIC_CAP0);
-               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");
-       } else return 0;
+               if (!INVALID_MAC(dev->dev_addr))
+                       return;
 
-       if (memcmp(dev->dev_addr, "\x08\x00\x07", 3) &&
-           memcmp(dev->dev_addr, "\x00\xA0\x40", 3) &&
-           memcmp(dev->dev_addr, "\x00\x80\x19", 3) &&
-           memcmp(dev->dev_addr, "\x00\x05\x02", 3))
-       {
                /*
-                * Still nonsense ... messed up someplace!
+                * If we still have what seems to be a bogus address, we'll
+                * look in the CAM. The top entry should be ours.
                 */
-               printk(KERN_ERR "macsonic: ERROR (INVALID MAC)\n");
-               return -EIO;
-       } else return 0;
+               printk(KERN_WARNING "macsonic: MAC address in PROM seems "
+                                   "to be invalid, trying CAM\n");
+       } else {
+               printk(KERN_WARNING "macsonic: cannot read MAC address from "
+                                   "PROM, trying CAM\n");
+       }
+
+       /* This only works if MacOS has already initialized the card. */
+
+       SONIC_WRITE(SONIC_CMD, SONIC_CR_RST);
+       SONIC_WRITE(SONIC_CEP, 15);
+
+       val = SONIC_READ(SONIC_CAP2);
+       dev->dev_addr[5] = val >> 8;
+       dev->dev_addr[4] = val & 0xff;
+       val = SONIC_READ(SONIC_CAP1);
+       dev->dev_addr[3] = val >> 8;
+       dev->dev_addr[2] = val & 0xff;
+       val = SONIC_READ(SONIC_CAP0);
+       dev->dev_addr[1] = val >> 8;
+       dev->dev_addr[0] = val & 0xff;
+
+       if (!INVALID_MAC(dev->dev_addr))
+               return;
+
+       /* Still nonsense ... messed up someplace! */
+
+       printk(KERN_WARNING "macsonic: MAC address in CAM entry 15 "
+                           "seems invalid, will use a random MAC\n");
+       random_ether_addr(dev->dev_addr);
 }
 
-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;
@@ -345,7 +349,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) {
@@ -378,10 +382,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
 
@@ -402,16 +406,15 @@ int __init mac_onboard_sonic_probe(struct net_device* dev)
        SONIC_WRITE(SONIC_ISR, 0x7fff);
 
        /* Now look for the MAC address. */
-       if (mac_onboard_sonic_ethernet_addr(dev) != 0)
-               return -ENODEV;
+       mac_onboard_sonic_ethernet_addr(dev);
 
        /* Shared init code */
        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++)
@@ -424,7 +427,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)
@@ -449,7 +452,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;
@@ -533,12 +536,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
 
@@ -562,12 +565,11 @@ int __init mac_nubus_sonic_probe(struct net_device* dev)
        return macsonic_init(dev);
 }
 
-static int __init mac_sonic_probe(struct platform_device *pdev)
+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)
@@ -576,6 +578,7 @@ static int __init mac_sonic_probe(struct platform_device *pdev)
        lp = netdev_priv(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);
@@ -591,13 +594,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;