[PATCH] AX.25: Delete debug printk from mkiss driver
[safe/jmp/linux-2.6] / drivers / net / ixgb / ixgb_main.c
index da6b9d6..176680c 100644 (file)
 #include "ixgb.h"
 
 /* Change Log
+ * 1.0.96 04/19/05
+ * - Make needlessly global code static -- bunk@stusta.de
+ * - ethtool cleanup -- shemminger@osdl.org
+ * - Support for MODULE_VERSION -- linville@tuxdriver.com
+ * - add skb_header_cloned check to the tso path -- herbert@apana.org.au
  * 1.0.88 01/05/05
  * - include fix to the condition that determines when to quit NAPI - Robert Olsson
  * - use netif_poll_{disable/enable} to synchronize between NAPI and i/f up/down
@@ -47,8 +52,9 @@ char ixgb_driver_string[] = "Intel(R) PRO/10GbE Network Driver";
 #else
 #define DRIVERNAPI "-NAPI"
 #endif
-char ixgb_driver_version[] = "1.0.90-k2"DRIVERNAPI;
-char ixgb_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
+#define DRV_VERSION            "1.0.100-k2"DRIVERNAPI
+char ixgb_driver_version[] = DRV_VERSION;
+static char ixgb_copyright[] = "Copyright (c) 1999-2005 Intel Corporation.";
 
 /* ixgb_pci_tbl - PCI Device ID Table
  *
@@ -103,6 +109,7 @@ static int ixgb_change_mtu(struct net_device *netdev, int new_mtu);
 static int ixgb_set_mac(struct net_device *netdev, void *p);
 static irqreturn_t ixgb_intr(int irq, void *data, struct pt_regs *regs);
 static boolean_t ixgb_clean_tx_irq(struct ixgb_adapter *adapter);
+
 #ifdef CONFIG_IXGB_NAPI
 static int ixgb_clean(struct net_device *netdev, int *budget);
 static boolean_t ixgb_clean_rx_irq(struct ixgb_adapter *adapter,
@@ -120,44 +127,34 @@ static void ixgb_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid);
 static void ixgb_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid);
 static void ixgb_restore_vlan(struct ixgb_adapter *adapter);
 
-static int ixgb_notify_reboot(struct notifier_block *, unsigned long event,
-                             void *ptr);
-static int ixgb_suspend(struct pci_dev *pdev, uint32_t state);
-
 #ifdef CONFIG_NET_POLL_CONTROLLER
 /* for netdump / net console */
 static void ixgb_netpoll(struct net_device *dev);
 #endif
 
-struct notifier_block ixgb_notifier_reboot = {
-       .notifier_call = ixgb_notify_reboot,
-       .next = NULL,
-       .priority = 0
-};
-
 /* Exported from other modules */
 
 extern void ixgb_check_options(struct ixgb_adapter *adapter);
 
 static struct pci_driver ixgb_driver = {
-       .name = ixgb_driver_name,
+       .name     = ixgb_driver_name,
        .id_table = ixgb_pci_tbl,
-       .probe = ixgb_probe,
-       .remove = __devexit_p(ixgb_remove),
-       /* Power Managment Hooks */
-       .suspend = NULL,
-       .resume = NULL
+       .probe    = ixgb_probe,
+       .remove   = __devexit_p(ixgb_remove),
 };
 
 MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
 MODULE_DESCRIPTION("Intel(R) PRO/10GbE Network Driver");
 MODULE_LICENSE("GPL");
+MODULE_VERSION(DRV_VERSION);
 
 /* some defines for controlling descriptor fetches in h/w */
-#define RXDCTL_PTHRESH_DEFAULT 128     /* chip considers prefech below this */
-#define RXDCTL_HTHRESH_DEFAULT 16      /* chip will only prefetch if tail is 
-                                          pushed this many descriptors from head */
 #define RXDCTL_WTHRESH_DEFAULT 16      /* chip writes back at this many or RXT0 */
+#define RXDCTL_PTHRESH_DEFAULT 0               /* chip considers prefech below
+                                                * this */
+#define RXDCTL_HTHRESH_DEFAULT 0               /* chip will only prefetch if tail
+                                                * is pushed this many descriptors
+                                                * from head */
 
 /**
  * ixgb_init_module - Driver Registration Routine
@@ -169,17 +166,12 @@ MODULE_LICENSE("GPL");
 static int __init
 ixgb_init_module(void)
 {
-       int ret;
        printk(KERN_INFO "%s - version %s\n",
               ixgb_driver_string, ixgb_driver_version);
 
        printk(KERN_INFO "%s\n", ixgb_copyright);
 
-       ret = pci_module_init(&ixgb_driver);
-       if(ret >= 0) {
-               register_reboot_notifier(&ixgb_notifier_reboot);
-       }
-       return ret;
+       return pci_module_init(&ixgb_driver);
 }
 
 module_init(ixgb_init_module);
@@ -194,7 +186,6 @@ module_init(ixgb_init_module);
 static void __exit
 ixgb_exit_module(void)
 {
-       unregister_reboot_notifier(&ixgb_notifier_reboot);
        pci_unregister_driver(&ixgb_driver);
 }
 
@@ -391,7 +382,7 @@ ixgb_probe(struct pci_dev *pdev,
        SET_NETDEV_DEV(netdev, &pdev->dev);
 
        pci_set_drvdata(pdev, netdev);
-       adapter = netdev->priv;
+       adapter = netdev_priv(netdev);
        adapter->netdev = netdev;
        adapter->pdev = pdev;
        adapter->hw.back = adapter;
@@ -469,8 +460,9 @@ ixgb_probe(struct pci_dev *pdev,
        }
 
        ixgb_get_ee_mac_addr(&adapter->hw, netdev->dev_addr);
+       memcpy(netdev->perm_addr, netdev->dev_addr, netdev->addr_len);
 
-       if(!is_valid_ether_addr(netdev->dev_addr)) {
+       if(!is_valid_ether_addr(netdev->perm_addr)) {
                err = -EIO;
                goto err_eeprom;
        }
@@ -527,7 +519,7 @@ static void __devexit
 ixgb_remove(struct pci_dev *pdev)
 {
        struct net_device *netdev = pci_get_drvdata(pdev);
-       struct ixgb_adapter *adapter = netdev->priv;
+       struct ixgb_adapter *adapter = netdev_priv(netdev);
 
        unregister_netdev(netdev);
 
@@ -598,7 +590,7 @@ ixgb_sw_init(struct ixgb_adapter *adapter)
 static int
 ixgb_open(struct net_device *netdev)
 {
-       struct ixgb_adapter *adapter = netdev->priv;
+       struct ixgb_adapter *adapter = netdev_priv(netdev);
        int err;
 
        /* allocate transmit descriptors */
@@ -641,7 +633,7 @@ err_setup_tx:
 static int
 ixgb_close(struct net_device *netdev)
 {
-       struct ixgb_adapter *adapter = netdev->priv;
+       struct ixgb_adapter *adapter = netdev_priv(netdev);
 
        ixgb_down(adapter, TRUE);
 
@@ -1032,7 +1024,7 @@ ixgb_clean_rx_ring(struct ixgb_adapter *adapter)
 static int
 ixgb_set_mac(struct net_device *netdev, void *p)
 {
-       struct ixgb_adapter *adapter = netdev->priv;
+       struct ixgb_adapter *adapter = netdev_priv(netdev);
        struct sockaddr *addr = p;
 
        if(!is_valid_ether_addr(addr->sa_data))
@@ -1058,7 +1050,7 @@ ixgb_set_mac(struct net_device *netdev, void *p)
 static void
 ixgb_set_multi(struct net_device *netdev)
 {
-       struct ixgb_adapter *adapter = netdev->priv;
+       struct ixgb_adapter *adapter = netdev_priv(netdev);
        struct ixgb_hw *hw = &adapter->hw;
        struct dev_mc_list *mc_ptr;
        uint32_t rctl;
@@ -1272,6 +1264,7 @@ ixgb_tx_map(struct ixgb_adapter *adapter, struct sk_buff *skb,
 
        unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
        unsigned int f;
+
        len -= skb->data_len;
 
        i = tx_ring->next_to_use;
@@ -1385,7 +1378,7 @@ ixgb_tx_queue(struct ixgb_adapter *adapter, int count, int vlan_id,int tx_flags)
 static int
 ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
 {
-       struct ixgb_adapter *adapter = netdev->priv;
+       struct ixgb_adapter *adapter = netdev_priv(netdev);
        unsigned int first;
        unsigned int tx_flags = 0;
        unsigned long flags;
@@ -1439,7 +1432,7 @@ ixgb_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
 static void
 ixgb_tx_timeout(struct net_device *netdev)
 {
-       struct ixgb_adapter *adapter = netdev->priv;
+       struct ixgb_adapter *adapter = netdev_priv(netdev);
 
        /* Do the reset outside of interrupt context */
        schedule_work(&adapter->tx_timeout_task);
@@ -1448,7 +1441,7 @@ ixgb_tx_timeout(struct net_device *netdev)
 static void
 ixgb_tx_timeout_task(struct net_device *netdev)
 {
-       struct ixgb_adapter *adapter = netdev->priv;
+       struct ixgb_adapter *adapter = netdev_priv(netdev);
 
        ixgb_down(adapter, TRUE);
        ixgb_up(adapter);
@@ -1465,7 +1458,7 @@ ixgb_tx_timeout_task(struct net_device *netdev)
 static struct net_device_stats *
 ixgb_get_stats(struct net_device *netdev)
 {
-       struct ixgb_adapter *adapter = netdev->priv;
+       struct ixgb_adapter *adapter = netdev_priv(netdev);
 
        return &adapter->net_stats;
 }
@@ -1481,7 +1474,7 @@ ixgb_get_stats(struct net_device *netdev)
 static int
 ixgb_change_mtu(struct net_device *netdev, int new_mtu)
 {
-       struct ixgb_adapter *adapter = netdev->priv;
+       struct ixgb_adapter *adapter = netdev_priv(netdev);
        int max_frame = new_mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
        int old_max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
 
@@ -1536,7 +1529,8 @@ ixgb_update_stats(struct ixgb_adapter *adapter)
 
                multi |= ((u64)IXGB_READ_REG(&adapter->hw, MPRCH) << 32);
                /* fix up multicast stats by removing broadcasts */
-               multi -= bcast;
+               if(multi >= bcast)
+                       multi -= bcast;
                
                adapter->stats.mprcl += (multi & 0xFFFFFFFF);
                adapter->stats.mprch += (multi >> 32);
@@ -1623,8 +1617,6 @@ ixgb_update_stats(struct ixgb_adapter *adapter)
            adapter->stats.icbc +
            adapter->stats.ecbc + adapter->stats.mpc;
 
-       adapter->net_stats.rx_dropped = adapter->stats.mpc;
-
        /* see above
         * adapter->net_stats.rx_length_errors = adapter->stats.rlec;
         */
@@ -1655,7 +1647,7 @@ static irqreturn_t
 ixgb_intr(int irq, void *data, struct pt_regs *regs)
 {
        struct net_device *netdev = data;
-       struct ixgb_adapter *adapter = netdev->priv;
+       struct ixgb_adapter *adapter = netdev_priv(netdev);
        struct ixgb_hw *hw = &adapter->hw;
        uint32_t icr = IXGB_READ_REG(hw, ICR);
 #ifndef CONFIG_IXGB_NAPI
@@ -1702,7 +1694,7 @@ ixgb_intr(int irq, void *data, struct pt_regs *regs)
 static int
 ixgb_clean(struct net_device *netdev, int *budget)
 {
-       struct ixgb_adapter *adapter = netdev->priv;
+       struct ixgb_adapter *adapter = netdev_priv(netdev);
        int work_to_do = min(*budget, netdev->quota);
        int tx_cleaned;
        int work_done = 0;
@@ -1841,7 +1833,6 @@ ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
        struct pci_dev *pdev = adapter->pdev;
        struct ixgb_rx_desc *rx_desc, *next_rxd;
        struct ixgb_buffer *buffer_info, *next_buffer, *next2_buffer;
-       struct sk_buff *skb, *next_skb;
        uint32_t length;
        unsigned int i, j;
        boolean_t cleaned = FALSE;
@@ -1851,6 +1842,8 @@ ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
        buffer_info = &rx_ring->buffer_info[i];
 
        while(rx_desc->status & IXGB_RX_DESC_STATUS_DD) {
+               struct sk_buff *skb, *next_skb;
+               u8 status;
 
 #ifdef CONFIG_IXGB_NAPI
                if(*work_done >= work_to_do)
@@ -1858,7 +1851,9 @@ ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
 
                (*work_done)++;
 #endif
+               status = rx_desc->status;
                skb = buffer_info->skb;
+
                prefetch(skb->data);
 
                if(++i == rx_ring->count) i = 0;
@@ -1873,7 +1868,6 @@ ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
                next_skb = next_buffer->skb;
                prefetch(next_skb);
 
-
                cleaned = TRUE;
 
                pci_unmap_single(pdev,
@@ -1883,7 +1877,7 @@ ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
 
                length = le16_to_cpu(rx_desc->length);
 
-               if(unlikely(!(rx_desc->status & IXGB_RX_DESC_STATUS_EOP))) {
+               if(unlikely(!(status & IXGB_RX_DESC_STATUS_EOP))) {
 
                        /* All receives must fit into a single buffer */
 
@@ -1891,12 +1885,7 @@ ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
                                         "length<%x>\n", length);
 
                        dev_kfree_skb_irq(skb);
-                       rx_desc->status = 0;
-                       buffer_info->skb = NULL;
-
-                       rx_desc = next_rxd;
-                       buffer_info = next_buffer;
-                       continue;
+                       goto rxdesc_done;
                }
 
                if (unlikely(rx_desc->errors
@@ -1905,12 +1894,7 @@ ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
                                IXGB_RX_DESC_ERRORS_RXE))) {
 
                        dev_kfree_skb_irq(skb);
-                       rx_desc->status = 0;
-                       buffer_info->skb = NULL;
-
-                       rx_desc = next_rxd;
-                       buffer_info = next_buffer;
-                       continue;
+                       goto rxdesc_done;
                }
 
                /* Good Receive */
@@ -1921,7 +1905,7 @@ ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
 
                skb->protocol = eth_type_trans(skb, netdev);
 #ifdef CONFIG_IXGB_NAPI
-               if(adapter->vlgrp && (rx_desc->status & IXGB_RX_DESC_STATUS_VP)) {
+               if(adapter->vlgrp && (status & IXGB_RX_DESC_STATUS_VP)) {
                        vlan_hwaccel_receive_skb(skb, adapter->vlgrp,
                                le16_to_cpu(rx_desc->special) &
                                        IXGB_RX_DESC_SPECIAL_VLAN_MASK);
@@ -1929,7 +1913,7 @@ ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
                        netif_receive_skb(skb);
                }
 #else /* CONFIG_IXGB_NAPI */
-               if(adapter->vlgrp && (rx_desc->status & IXGB_RX_DESC_STATUS_VP)) {
+               if(adapter->vlgrp && (status & IXGB_RX_DESC_STATUS_VP)) {
                        vlan_hwaccel_rx(skb, adapter->vlgrp,
                                le16_to_cpu(rx_desc->special) &
                                        IXGB_RX_DESC_SPECIAL_VLAN_MASK);
@@ -1939,9 +1923,12 @@ ixgb_clean_rx_irq(struct ixgb_adapter *adapter)
 #endif /* CONFIG_IXGB_NAPI */
                netdev->last_rx = jiffies;
 
+rxdesc_done:
+               /* clean up descriptor, might be written over by hw */
                rx_desc->status = 0;
                buffer_info->skb = NULL;
 
+               /* use prefetched values */
                rx_desc = next_rxd;
                buffer_info = next_buffer;
        }
@@ -1977,8 +1964,8 @@ ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter)
 
        num_group_tail_writes = IXGB_RX_BUFFER_WRITE;
 
-       /* leave one descriptor unused */
-       while(--cleancount > 0) {
+       /* leave three descriptors unused */
+       while(--cleancount > 2) {
                rx_desc = IXGB_RX_DESC(*rx_ring, i);
 
                skb = dev_alloc_skb(adapter->rx_buffer_len + NET_IP_ALIGN);
@@ -2005,6 +1992,10 @@ ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter)
                                   PCI_DMA_FROMDEVICE);
 
                rx_desc->buff_addr = cpu_to_le64(buffer_info->dma);
+               /* guarantee DD bit not set now before h/w gets descriptor
+                * this is the rest of the workaround for h/w double 
+                * writeback. */
+               rx_desc->status = 0;
 
                if((i & ~(num_group_tail_writes- 1)) == i) {
                        /* Force memory writes to complete before letting h/w
@@ -2032,7 +2023,7 @@ ixgb_alloc_rx_buffers(struct ixgb_adapter *adapter)
 static void
 ixgb_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
 {
-       struct ixgb_adapter *adapter = netdev->priv;
+       struct ixgb_adapter *adapter = netdev_priv(netdev);
        uint32_t ctrl, rctl;
 
        ixgb_irq_disable(adapter);
@@ -2070,7 +2061,7 @@ ixgb_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
 static void
 ixgb_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
 {
-       struct ixgb_adapter *adapter = netdev->priv;
+       struct ixgb_adapter *adapter = netdev_priv(netdev);
        uint32_t vfta, index;
 
        /* add VID to filter table */
@@ -2084,7 +2075,7 @@ ixgb_vlan_rx_add_vid(struct net_device *netdev, uint16_t vid)
 static void
 ixgb_vlan_rx_kill_vid(struct net_device *netdev, uint16_t vid)
 {
-       struct ixgb_adapter *adapter = netdev->priv;
+       struct ixgb_adapter *adapter = netdev_priv(netdev);
        uint32_t vfta, index;
 
        ixgb_irq_disable(adapter);
@@ -2117,54 +2108,6 @@ ixgb_restore_vlan(struct ixgb_adapter *adapter)
        }
 }
 
-/**
- * ixgb_notify_reboot - handles OS notification of reboot event.
- * @param nb notifier block, unused
- * @param event Event being passed to driver to act upon
- * @param p A pointer to our net device
- **/
-static int
-ixgb_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
-{
-       struct pci_dev *pdev = NULL;
-
-       switch(event) {
-       case SYS_DOWN:
-       case SYS_HALT:
-       case SYS_POWER_OFF:
-               while ((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev))) {
-                       if (pci_dev_driver(pdev) == &ixgb_driver)
-                               ixgb_suspend(pdev, 3);
-               }
-       }
-       return NOTIFY_DONE;
-}
-
-/**
- * ixgb_suspend - driver suspend function called from notify.
- * @param pdev pci driver structure used for passing to
- * @param state power state to enter 
- **/
-static int
-ixgb_suspend(struct pci_dev *pdev, uint32_t state)
-{
-       struct net_device *netdev = pci_get_drvdata(pdev);
-       struct ixgb_adapter *adapter = netdev->priv;
-
-       netif_device_detach(netdev);
-
-       if(netif_running(netdev))
-               ixgb_down(adapter, TRUE);
-
-       pci_save_state(pdev);
-
-       state = (state > 0) ? 3 : 0;
-       pci_set_power_state(pdev, state);
-       msec_delay(200);
-
-       return 0;
-}
-
 #ifdef CONFIG_NET_POLL_CONTROLLER
 /*
  * Polling 'interrupt' - used by things like netconsole to send skbs
@@ -2175,6 +2118,7 @@ ixgb_suspend(struct pci_dev *pdev, uint32_t state)
 static void ixgb_netpoll(struct net_device *dev)
 {
        struct ixgb_adapter *adapter = dev->priv;
+
        disable_irq(adapter->pdev->irq);
        ixgb_intr(adapter->pdev->irq, dev, NULL);
        enable_irq(adapter->pdev->irq);