r8169: move PHY regs tables to .rodata
[safe/jmp/linux-2.6] / drivers / net / macsonic.c
index 205bb05..875d361 100644 (file)
@@ -140,7 +140,7 @@ static irqreturn_t macsonic_interrupt(int irq, void *dev_id)
 
 static int macsonic_open(struct net_device* dev)
 {
-       if (request_irq(dev->irq, &sonic_interrupt, IRQ_FLG_FAST, "sonic", 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;
        }
@@ -149,7 +149,7 @@ static int macsonic_open(struct net_device* dev)
         * 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)) {
+               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;
@@ -167,7 +167,19 @@ static int macsonic_close(struct net_device* dev)
        return err;
 }
 
-static 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);
 
@@ -176,7 +188,8 @@ static 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;
        }
 
@@ -197,12 +210,7 @@ static 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;
 
        /*
@@ -215,72 +223,76 @@ static int __init macsonic_init(struct net_device *dev)
        return 0;
 }
 
-static 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;
+
+               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. */
-       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))
+               /*
+                * 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: %pM\n",
-                      dev->dev_addr);
-       } else return 0;
-
-       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))
-       {
+               if (!INVALID_MAC(dev->dev_addr))
+                       return;
+
                /*
-                * 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);
 }
 
-static 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;
@@ -337,7 +349,7 @@ static 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) {
@@ -370,10 +382,10 @@ static 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
 
@@ -394,14 +406,13 @@ static 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);
 }
 
-static int __init mac_nubus_sonic_ethernet_addr(struct net_device *dev,
+static int __devinit mac_nubus_sonic_ethernet_addr(struct net_device *dev,
                                                unsigned long prom_addr,
                                                int id)
 {
@@ -416,7 +427,7 @@ static int __init mac_nubus_sonic_ethernet_addr(struct net_device *dev,
        return 0;
 }
 
-static 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)
@@ -441,7 +452,7 @@ static int __init macsonic_ident(struct nubus_dev *ndev)
        return -1;
 }
 
-static 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;
@@ -525,12 +536,12 @@ static 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
 
@@ -554,7 +565,7 @@ static 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;
@@ -567,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);