net: congestion notifications are not dropped packets
[safe/jmp/linux-2.6] / drivers / net / fealnx.c
index e935307..15f4f8d 100644 (file)
@@ -74,7 +74,6 @@ static int full_duplex[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, -1 };
 #include <linux/timer.h>
 #include <linux/errno.h>
 #include <linux/ioport.h>
-#include <linux/slab.h>
 #include <linux/interrupt.h>
 #include <linux/pci.h>
 #include <linux/netdevice.h>
@@ -90,10 +89,11 @@ static int full_duplex[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, -1 };
 #include <asm/processor.h>     /* Processor type for cache alignment. */
 #include <asm/io.h>
 #include <asm/uaccess.h>
+#include <asm/byteorder.h>
 
 /* These identify the driver base version and may not be removed. */
-static char version[] =
-KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE "\n";
+static const char version[] __devinitconst =
+       KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE "\n";
 
 
 /* This driver was written to use PCI memory space, however some x86 systems
@@ -111,7 +111,6 @@ MODULE_AUTHOR("Myson or whoever");
 MODULE_DESCRIPTION("Myson MTD-8xx 100/10M Ethernet PCI Adapter Driver");
 MODULE_LICENSE("GPL");
 module_param(max_interrupt_work, int, 0);
-//MODULE_PARM(min_pci_latency, "i");
 module_param(debug, int, 0);
 module_param(rx_copybreak, int, 0);
 module_param(multicast_filter_limit, int, 0);
@@ -431,9 +430,9 @@ static void getlinktype(struct net_device *dev);
 static void getlinkstatus(struct net_device *dev);
 static void netdev_timer(unsigned long data);
 static void reset_timer(unsigned long data);
-static void tx_timeout(struct net_device *dev);
+static void fealnx_tx_timeout(struct net_device *dev);
 static void init_ring(struct net_device *dev);
-static int start_tx(struct sk_buff *skb, struct net_device *dev);
+static netdev_tx_t start_tx(struct sk_buff *skb, struct net_device *dev);
 static irqreturn_t intr_handler(int irq, void *dev_instance);
 static int netdev_rx(struct net_device *dev);
 static void set_rx_mode(struct net_device *dev);
@@ -467,6 +466,18 @@ static void stop_nic_rxtx(void __iomem *ioaddr, long crvalue)
        }
 }
 
+static const struct net_device_ops netdev_ops = {
+       .ndo_open               = netdev_open,
+       .ndo_stop               = netdev_close,
+       .ndo_start_xmit         = start_tx,
+       .ndo_get_stats          = get_stats,
+       .ndo_set_multicast_list = set_rx_mode,
+       .ndo_do_ioctl           = mii_ioctl,
+       .ndo_tx_timeout         = fealnx_tx_timeout,
+       .ndo_change_mtu         = eth_change_mtu,
+       .ndo_set_mac_address    = eth_mac_addr,
+       .ndo_validate_addr      = eth_validate_addr,
+};
 
 static int __devinit fealnx_init_one(struct pci_dev *pdev,
                                     const struct pci_device_id *ent)
@@ -572,7 +583,8 @@ static int __devinit fealnx_init_one(struct pci_dev *pdev,
        if (np->flags == HAS_MII_XCVR) {
                int phy, phy_idx = 0;
 
-               for (phy = 1; phy < 32 && phy_idx < 4; phy++) {
+               for (phy = 1; phy < 32 && phy_idx < ARRAY_SIZE(np->phys);
+                              phy++) {
                        int mii_status = mdio_read(dev, phy, 1);
 
                        if (mii_status != 0xffff && mii_status != 0x0000) {
@@ -649,26 +661,17 @@ static int __devinit fealnx_init_one(struct pci_dev *pdev,
                np->mii.force_media = 1;
        }
 
-       /* The chip-specific entries in the device structure. */
-       dev->open = &netdev_open;
-       dev->hard_start_xmit = &start_tx;
-       dev->stop = &netdev_close;
-       dev->get_stats = &get_stats;
-       dev->set_multicast_list = &set_rx_mode;
-       dev->do_ioctl = &mii_ioctl;
+       dev->netdev_ops = &netdev_ops;
        dev->ethtool_ops = &netdev_ethtool_ops;
-       dev->tx_timeout = &tx_timeout;
        dev->watchdog_timeo = TX_TIMEOUT;
 
        err = register_netdev(dev);
        if (err)
                goto err_out_free_tx;
 
-       printk(KERN_INFO "%s: %s at %p, ",
-              dev->name, skel_netdrv_tbl[chip_id].chip_name, ioaddr);
-       for (i = 0; i < 5; i++)
-               printk("%2.2x:", dev->dev_addr[i]);
-       printk("%2.2x, IRQ %d.\n", dev->dev_addr[i], irq);
+       printk(KERN_INFO "%s: %s at %p, %pM, IRQ %d.\n",
+              dev->name, skel_netdrv_tbl[chip_id].chip_name, ioaddr,
+              dev->dev_addr, irq);
 
        return 0;
 
@@ -835,7 +838,7 @@ static int netdev_open(struct net_device *dev)
 
        iowrite32(0x00000001, ioaddr + BCR);    /* Reset */
 
-       if (request_irq(dev->irq, &intr_handler, IRQF_SHARED, dev->name, dev))
+       if (request_irq(dev->irq, intr_handler, IRQF_SHARED, dev->name, dev))
                return -EAGAIN;
 
        for (i = 0; i < 3; i++)
@@ -863,40 +866,20 @@ static int netdev_open(struct net_device *dev)
           Wait the specified 50 PCI cycles after a reset by initializing
           Tx and Rx queues and the address filter list.
           FIXME (Ueimor): optimistic for alpha + posted writes ? */
-#if defined(__powerpc__) || defined(__sparc__)
-// 89/9/1 modify,
-//   np->bcrvalue=0x04 | 0x0x38;  /* big-endian, 256 burst length */
-       np->bcrvalue = 0x04 | 0x10;     /* big-endian, tx 8 burst length */
-       np->crvalue = 0xe00;    /* rx 128 burst length */
-#elif defined(__alpha__) || defined(__x86_64__)
-// 89/9/1 modify,
-//   np->bcrvalue=0x38;           /* little-endian, 256 burst length */
-       np->bcrvalue = 0x10;    /* little-endian, 8 burst length */
-       np->crvalue = 0xe00;    /* rx 128 burst length */
-#elif defined(__i386__)
-#if defined(MODULE)
-// 89/9/1 modify,
-//   np->bcrvalue=0x38;           /* little-endian, 256 burst length */
+
        np->bcrvalue = 0x10;    /* little-endian, 8 burst length */
-       np->crvalue = 0xe00;    /* rx 128 burst length */
-#else
-       /* When not a module we can work around broken '486 PCI boards. */
-#define x86 boot_cpu_data.x86
-// 89/9/1 modify,
-//   np->bcrvalue=(x86 <= 4 ? 0x10 : 0x38);
-       np->bcrvalue = 0x10;
-       np->crvalue = (x86 <= 4 ? 0xa00 : 0xe00);
-       if (x86 <= 4)
-               printk(KERN_INFO "%s: This is a 386/486 PCI system, setting burst "
-                      "length to %x.\n", dev->name, (x86 <= 4 ? 0x10 : 0x38));
+#ifdef __BIG_ENDIAN
+       np->bcrvalue |= 0x04;   /* big-endian */
 #endif
-#else
-// 89/9/1 modify,
-//   np->bcrvalue=0x38;
-       np->bcrvalue = 0x10;
-       np->crvalue = 0xe00;    /* rx 128 burst length */
-#warning Processor architecture undefined!
+
+#if defined(__i386__) && !defined(MODULE)
+       if (boot_cpu_data.x86 <= 4)
+               np->crvalue = 0xa00;
+       else
 #endif
+               np->crvalue = 0xe00;    /* rx 128 burst length */
+
+
 // 89/12/29 add,
 // 90/1/16 modify,
 //   np->imrvalue=FBE|TUNF|CNTOVF|RBU|TI|RI;
@@ -1219,24 +1202,27 @@ static void reset_timer(unsigned long data)
 }
 
 
-static void tx_timeout(struct net_device *dev)
+static void fealnx_tx_timeout(struct net_device *dev)
 {
        struct netdev_private *np = netdev_priv(dev);
        void __iomem *ioaddr = np->mem;
        unsigned long flags;
        int i;
 
-       printk(KERN_WARNING "%s: Transmit timed out, status %8.8x,"
-              " resetting...\n", dev->name, ioread32(ioaddr + ISR));
+       printk(KERN_WARNING
+              "%s: Transmit timed out, status %8.8x, resetting...\n",
+              dev->name, ioread32(ioaddr + ISR));
 
        {
                printk(KERN_DEBUG "  Rx ring %p: ", np->rx_ring);
                for (i = 0; i < RX_RING_SIZE; i++)
-                       printk(" %8.8x", (unsigned int) np->rx_ring[i].status);
-               printk("\n" KERN_DEBUG "  Tx ring %p: ", np->tx_ring);
+                       printk(KERN_CONT " %8.8x",
+                              (unsigned int) np->rx_ring[i].status);
+               printk(KERN_CONT "\n");
+               printk(KERN_DEBUG "  Tx ring %p: ", np->tx_ring);
                for (i = 0; i < TX_RING_SIZE; i++)
-                       printk(" %4.4x", np->tx_ring[i].status);
-               printk("\n");
+                       printk(KERN_CONT " %4.4x", np->tx_ring[i].status);
+               printk(KERN_CONT "\n");
        }
 
        spin_lock_irqsave(&np->lock, flags);
@@ -1247,7 +1233,7 @@ static void tx_timeout(struct net_device *dev)
 
        spin_unlock_irqrestore(&np->lock, flags);
 
-       dev->trans_start = jiffies;
+       dev->trans_start = jiffies; /* prevent tx timeout */
        np->stats.tx_errors++;
        netif_wake_queue(dev); /* or .._start_.. ?? */
 }
@@ -1318,7 +1304,7 @@ static void init_ring(struct net_device *dev)
 }
 
 
-static int start_tx(struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t start_tx(struct sk_buff *skb, struct net_device *dev)
 {
        struct netdev_private *np = netdev_priv(dev);
        unsigned long flags;
@@ -1388,10 +1374,9 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
                netif_stop_queue(dev);
        ++np->really_tx_count;
        iowrite32(0, np->mem + TXPDR);
-       dev->trans_start = jiffies;
 
        spin_unlock_irqrestore(&np->lock, flags);
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 
@@ -1642,8 +1627,8 @@ static int netdev_rx(struct net_device *dev)
                if (debug)
                        printk(KERN_DEBUG "  netdev_rx() status was %8.8x.\n", rx_status);
 
-               if ((!((rx_status & RXFSD) && (rx_status & RXLSD)))
-                   || (rx_status & ErrorSummary)) {
+               if ((!((rx_status & RXFSD) && (rx_status & RXLSD))) ||
+                   (rx_status & ErrorSummary)) {
                        if (rx_status & ErrorSummary) { /* there was a fatal error */
                                if (debug)
                                        printk(KERN_DEBUG
@@ -1668,8 +1653,8 @@ static int netdev_rx(struct net_device *dev)
                                        cur = np->cur_rx;
                                        while (desno <= np->really_rx_count) {
                                                ++desno;
-                                               if ((!(cur->status & RXOWN))
-                                                   && (cur->status & RXLSD))
+                                               if ((!(cur->status & RXOWN)) &&
+                                                   (cur->status & RXLSD))
                                                        break;
                                                /* goto next rx descriptor */
                                                cur = cur->next_desc_logical;
@@ -1748,7 +1733,6 @@ static int netdev_rx(struct net_device *dev)
                        }
                        skb->protocol = eth_type_trans(skb, dev);
                        netif_rx(skb);
-                       dev->last_rx = jiffies;
                        np->stats.rx_packets++;
                        np->stats.rx_bytes += pkt_len;
                }
@@ -1800,20 +1784,18 @@ static void __set_rx_mode(struct net_device *dev)
        if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
                memset(mc_filter, 0xff, sizeof(mc_filter));
                rx_mode = CR_W_PROM | CR_W_AB | CR_W_AM;
-       } else if ((dev->mc_count > multicast_filter_limit)
-                  || (dev->flags & IFF_ALLMULTI)) {
+       } else if ((netdev_mc_count(dev) > multicast_filter_limit) ||
+                  (dev->flags & IFF_ALLMULTI)) {
                /* Too many to match, or accept all multicasts. */
                memset(mc_filter, 0xff, sizeof(mc_filter));
                rx_mode = CR_W_AB | CR_W_AM;
        } else {
-               struct dev_mc_list *mclist;
-               int i;
+               struct netdev_hw_addr *ha;
 
                memset(mc_filter, 0, sizeof(mc_filter));
-               for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
-                    i++, mclist = mclist->next) {
+               netdev_for_each_mc_addr(ha, dev) {
                        unsigned int bit;
-                       bit = (ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26) ^ 0x3F;
+                       bit = (ether_crc(ETH_ALEN, ha->addr) >> 26) ^ 0x3F;
                        mc_filter[bit >> 5] |= (1 << bit);
                }
                rx_mode = CR_W_AB | CR_W_AM;
@@ -1891,8 +1873,6 @@ static const struct ethtool_ops netdev_ethtool_ops = {
        .get_link               = netdev_get_link,
        .get_msglevel           = netdev_get_msglevel,
        .set_msglevel           = netdev_set_msglevel,
-       .get_sg                 = ethtool_op_get_sg,
-       .get_tx_csum            = ethtool_op_get_tx_csum,
 };
 
 static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
@@ -1957,7 +1937,7 @@ static int netdev_close(struct net_device *dev)
        return 0;
 }
 
-static struct pci_device_id fealnx_pci_tbl[] = {
+static DEFINE_PCI_DEVICE_TABLE(fealnx_pci_tbl) = {
        {0x1516, 0x0800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
        {0x1516, 0x0803, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
        {0x1516, 0x0891, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},