bnx2: Refine VPD logic.
[safe/jmp/linux-2.6] / drivers / net / at1700.c
index 8620a5b..b14f479 100644 (file)
@@ -109,7 +109,6 @@ typedef unsigned char uchar;
 
 /* Information that need to be kept for each board. */
 struct net_local {
-       struct net_device_stats stats;
        spinlock_t lock;
        unsigned char mc_filter[8];
        uint jumpered:1;                        /* Set iff the board has jumper config. */
@@ -160,11 +159,11 @@ struct net_local {
 static int at1700_probe1(struct net_device *dev, int ioaddr);
 static int read_eeprom(long ioaddr, int location);
 static int net_open(struct net_device *dev);
-static int     net_send_packet(struct sk_buff *skb, struct net_device *dev);
+static netdev_tx_t net_send_packet(struct sk_buff *skb,
+                                  struct net_device *dev);
 static irqreturn_t net_interrupt(int irq, void *dev_id);
 static void net_rx(struct net_device *dev);
 static int net_close(struct net_device *dev);
-static struct net_device_stats *net_get_stats(struct net_device *dev);
 static void set_rx_mode(struct net_device *dev);
 static void net_tx_timeout (struct net_device *dev);
 
@@ -225,8 +224,6 @@ struct net_device * __init at1700_probe(int unit)
                dev->irq = irq;
        }
 
-       SET_MODULE_OWNER(dev);
-
        if (io > 0x1ff) {       /* Check a single specified location. */
                err = at1700_probe1(dev, io);
        } else if (io != 0) {   /* Don't probe at all. */
@@ -253,6 +250,17 @@ out:
        return ERR_PTR(err);
 }
 
+static const struct net_device_ops at1700_netdev_ops = {
+       .ndo_open               = net_open,
+       .ndo_stop               = net_close,
+       .ndo_start_xmit         = net_send_packet,
+       .ndo_set_multicast_list = set_rx_mode,
+       .ndo_tx_timeout         = net_tx_timeout,
+       .ndo_change_mtu         = eth_change_mtu,
+       .ndo_set_mac_address    = eth_mac_addr,
+       .ndo_validate_addr      = eth_validate_addr,
+};
+
 /* The Fujitsu datasheet suggests that the NIC be probed for by checking its
    "signature", the default bit pattern after a reset.  This *doesn't* work --
    there is no way to reset the bus interface without a complete power-cycle!
@@ -311,7 +319,7 @@ static int __init at1700_probe1(struct net_device *dev, int ioaddr)
                                pos3 = mca_read_stored_pos( slot, 3 );
                                pos4 = mca_read_stored_pos( slot, 4 );
 
-                               for (l_i = 0; l_i < 0x09; l_i++)
+                               for (l_i = 0; l_i < 8; l_i++)
                                        if (( pos3 & 0x07) == at1700_ioaddr_pattern[l_i])
                                                break;
                                ioaddr = at1700_mca_probe_list[l_i];
@@ -342,13 +350,13 @@ static int __init at1700_probe1(struct net_device *dev, int ioaddr)
        slot = -1;
        /* We must check for the EEPROM-config boards first, else accessing
           IOCONFIG0 will move the board! */
-       if (at1700_probe_list[inb(ioaddr + IOCONFIG1) & 0x07] == ioaddr
-               && read_eeprom(ioaddr, 4) == 0x0000
-               && (read_eeprom(ioaddr, 5) & 0xff00) == 0xF400)
+       if (at1700_probe_list[inb(ioaddr + IOCONFIG1) & 0x07] == ioaddr &&
+           read_eeprom(ioaddr, 4) == 0x0000 &&
+           (read_eeprom(ioaddr, 5) & 0xff00) == 0xF400)
                is_at1700 = 1;
-       else if (inb(ioaddr   + SAPROM    ) == 0x00
-               && inb(ioaddr + SAPROM + 1) == 0x00
-               && inb(ioaddr + SAPROM + 2) == 0x0e)
+       else if (inb(ioaddr + SAPROM    ) == 0x00 &&
+                inb(ioaddr + SAPROM + 1) == 0x00 &&
+                inb(ioaddr + SAPROM + 2) == 0x0e)
                is_fmv18x = 1;
        else {
                goto err_out;
@@ -392,16 +400,15 @@ found:
        if (is_at1700) {
                for(i = 0; i < 3; i++) {
                        unsigned short eeprom_val = read_eeprom(ioaddr, 4+i);
-                       printk("%04x", eeprom_val);
                        ((unsigned short *)dev->dev_addr)[i] = ntohs(eeprom_val);
                }
        } else {
                for(i = 0; i < 6; i++) {
                        unsigned char val = inb(ioaddr + SAPROM + i);
-                       printk("%02x", val);
                        dev->dev_addr[i] = val;
                }
        }
+       printk("%pM", dev->dev_addr);
 
        /* The EEPROM word 12 bit 0x0400 means use regular 100 ohm 10baseT signals,
           rather than 150 ohm shielded twisted pair compensation.
@@ -453,14 +460,7 @@ found:
        if (net_debug)
                printk(version);
 
-       memset(lp, 0, sizeof(struct net_local));
-
-       dev->open               = net_open;
-       dev->stop               = net_close;
-       dev->hard_start_xmit = net_send_packet;
-       dev->get_stats  = net_get_stats;
-       dev->set_multicast_list = &set_rx_mode;
-       dev->tx_timeout = net_tx_timeout;
+       dev->netdev_ops = &at1700_netdev_ops;
        dev->watchdog_timeo = TX_TIMEOUT;
 
        spin_lock_init(&lp->lock);
@@ -468,10 +468,11 @@ found:
        lp->jumpered = is_fmv18x;
        lp->mca_slot = slot;
        /* Snarf the interrupt vector now. */
-       ret = request_irq(irq, &net_interrupt, 0, DRV_NAME, dev);
+       ret = request_irq(irq, net_interrupt, 0, DRV_NAME, dev);
        if (ret) {
-               printk ("  AT1700 at %#3x is unusable due to a conflict on"
-                               "IRQ %d.\n", ioaddr, irq);
+               printk(KERN_ERR "AT1700 at %#3x is unusable due to a "
+                      "conflict on IRQ %d.\n",
+                      ioaddr, irq);
                goto err_mca;
        }
 
@@ -573,7 +574,7 @@ static void net_tx_timeout (struct net_device *dev)
         dev->name, inw(ioaddr + TX_STATUS), inw(ioaddr + TX_INTR), inw(ioaddr + TX_MODE),
                inw(ioaddr + CONFIG_0), inw(ioaddr + DATAPORT), inw(ioaddr + TX_START),
                inw(ioaddr + MODE13 - 1), inw(ioaddr + RX_CTRL));
-       lp->stats.tx_errors++;
+       dev->stats.tx_errors++;
        /* ToDo: We should try to restart the adaptor... */
        outw(0xffff, ioaddr + MODE24);
        outw (0xffff, ioaddr + TX_STATUS);
@@ -595,7 +596,8 @@ static void net_tx_timeout (struct net_device *dev)
 }
 
 
-static int net_send_packet (struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t net_send_packet (struct sk_buff *skb,
+                                   struct net_device *dev)
 {
        struct net_local *lp = netdev_priv(dev);
        int ioaddr = dev->base_addr;
@@ -643,7 +645,7 @@ static int net_send_packet (struct sk_buff *skb, struct net_device *dev)
                netif_start_queue (dev);
        dev_kfree_skb (skb);
 
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 /* The typical workload of the driver:
@@ -693,10 +695,10 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
                                printk("%s: 16 Collision occur during Txing.\n", dev->name);
                        /* Cancel sending a packet. */
                        outb(0x03, ioaddr + COL16CNTL);
-                       lp->stats.collisions++;
+                       dev->stats.collisions++;
                }
                if (status & 0x82) {
-                       lp->stats.tx_packets++;
+                       dev->stats.tx_packets++;
                        /* The Tx queue has any packets and is not being
                           transferred a packet from the host, start
                           transmitting. */
@@ -721,7 +723,6 @@ static irqreturn_t net_interrupt(int irq, void *dev_id)
 static void
 net_rx(struct net_device *dev)
 {
-       struct net_local *lp = netdev_priv(dev);
        int ioaddr = dev->base_addr;
        int boguscount = 5;
 
@@ -740,11 +741,11 @@ net_rx(struct net_device *dev)
 #endif
 
                if ((status & 0xF0) != 0x20) {  /* There was an error. */
-                       lp->stats.rx_errors++;
-                       if (status & 0x08) lp->stats.rx_length_errors++;
-                       if (status & 0x04) lp->stats.rx_frame_errors++;
-                       if (status & 0x02) lp->stats.rx_crc_errors++;
-                       if (status & 0x01) lp->stats.rx_over_errors++;
+                       dev->stats.rx_errors++;
+                       if (status & 0x08) dev->stats.rx_length_errors++;
+                       if (status & 0x04) dev->stats.rx_frame_errors++;
+                       if (status & 0x02) dev->stats.rx_crc_errors++;
+                       if (status & 0x01) dev->stats.rx_over_errors++;
                } else {
                        /* Malloc up new buffer. */
                        struct sk_buff *skb;
@@ -755,7 +756,7 @@ net_rx(struct net_device *dev)
                                /* Prime the FIFO and then flush the packet. */
                                inw(ioaddr + DATAPORT); inw(ioaddr + DATAPORT);
                                outb(0x05, ioaddr + RX_CTRL);
-                               lp->stats.rx_errors++;
+                               dev->stats.rx_errors++;
                                break;
                        }
                        skb = dev_alloc_skb(pkt_len+3);
@@ -765,18 +766,16 @@ net_rx(struct net_device *dev)
                                /* Prime the FIFO and then flush the packet. */
                                inw(ioaddr + DATAPORT); inw(ioaddr + DATAPORT);
                                outb(0x05, ioaddr + RX_CTRL);
-                               lp->stats.rx_dropped++;
+                               dev->stats.rx_dropped++;
                                break;
                        }
-                       skb->dev = dev;
                        skb_reserve(skb,2);
 
                        insw(ioaddr + DATAPORT, skb_put(skb,pkt_len), (pkt_len + 1) >> 1);
                        skb->protocol=eth_type_trans(skb, dev);
                        netif_rx(skb);
-                       dev->last_rx = jiffies;
-                       lp->stats.rx_packets++;
-                       lp->stats.rx_bytes += pkt_len;
+                       dev->stats.rx_packets++;
+                       dev->stats.rx_bytes += pkt_len;
                }
                if (--boguscount <= 0)
                        break;
@@ -825,17 +824,6 @@ static int net_close(struct net_device *dev)
        return 0;
 }
 
-/* Get the current statistics.
-   This may be called with the card open or closed.
-   There are no on-chip counters, so this function is trivial.
-*/
-static struct net_device_stats *
-net_get_stats(struct net_device *dev)
-{
-       struct net_local *lp = netdev_priv(dev);
-       return &lp->stats;
-}
-
 /*
   Set the multicast/promiscuous mode for this adaptor.
 */
@@ -847,13 +835,12 @@ set_rx_mode(struct net_device *dev)
        struct net_local *lp = netdev_priv(dev);
        unsigned char mc_filter[8];              /* Multicast hash filter */
        unsigned long flags;
-       int i;
 
        if (dev->flags & IFF_PROMISC) {
                memset(mc_filter, 0xff, sizeof(mc_filter));
                outb(3, ioaddr + RX_MODE);      /* Enable promiscuous mode */
-       } else if (dev->mc_count > MC_FILTERBREAK
-                          ||  (dev->flags & IFF_ALLMULTI)) {
+       } else if (dev->mc_count > MC_FILTERBREAK ||
+                          (dev->flags & IFF_ALLMULTI)) {
                /* Too many to filter perfectly -- accept all multicasts. */
                memset(mc_filter, 0xff, sizeof(mc_filter));
                outb(2, ioaddr + RX_MODE);      /* Use normal mode. */
@@ -876,6 +863,7 @@ set_rx_mode(struct net_device *dev)
 
        spin_lock_irqsave (&lp->lock, flags);
        if (memcmp(mc_filter, lp->mc_filter, sizeof(mc_filter))) {
+               int i;
                int saved_bank = inw(ioaddr + CONFIG_0);
                /* Switch to bank 1 and set the multicast table. */
                outw((saved_bank & ~0x0C00) | 0x0480, ioaddr + CONFIG_0);
@@ -898,7 +886,7 @@ MODULE_PARM_DESC(io, "AT1700/FMV18X I/O base address");
 MODULE_PARM_DESC(irq, "AT1700/FMV18X IRQ number");
 MODULE_PARM_DESC(net_debug, "AT1700/FMV18X debug level (0-6)");
 
-int __init init_module(void)
+static int __init at1700_module_init(void)
 {
        if (io == 0)
                printk("at1700: You should not use auto-probing with insmod!\n");
@@ -908,24 +896,13 @@ int __init init_module(void)
        return 0;
 }
 
-void
-cleanup_module(void)
+static void __exit at1700_module_exit(void)
 {
        unregister_netdev(dev_at1700);
        cleanup_card(dev_at1700);
        free_netdev(dev_at1700);
 }
+module_init(at1700_module_init);
+module_exit(at1700_module_exit);
 #endif /* MODULE */
 MODULE_LICENSE("GPL");
-
-
-/*
- * Local variables:
- *  compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c at1700.c"
- *  alt-compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c at1700.c"
- *  tab-width: 4
- *  c-basic-offset: 4
- *  c-indent-level: 4
- * End:
- */
-