back ported version 3.66f tg3 driver
[linux-2.6.git] / drivers / net / tg3.c
index eafabb2..1aeb2ff 100644 (file)
  *     notice is accompanying it.
  */
 
+#include <linux/config.h>
+#include <linux/version.h>
 
+#if (LINUX_VERSION_CODE < 0x020500)
+#if defined(CONFIG_MODVERSIONS) && defined(MODULE) && ! defined(MODVERSIONS)
+#define MODVERSIONS
+#include <linux/modversions.h>
+#endif
+#endif
 #include <linux/module.h>
+#if (LINUX_VERSION_CODE >= 0x20600)
 #include <linux/moduleparam.h>
+#endif
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/compiler.h>
 #include <linux/if_vlan.h>
 #include <linux/ip.h>
 #include <linux/tcp.h>
+#if (LINUX_VERSION_CODE >= 0x20600)
 #include <linux/workqueue.h>
+#endif
 #include <linux/prefetch.h>
+#if (LINUX_VERSION_CODE >= 0x020600)
 #include <linux/dma-mapping.h>
+#endif
+#include <linux/bitops.h>
 
 #include <net/checksum.h>
 
@@ -68,8 +83,8 @@
 
 #define DRV_MODULE_NAME                "tg3"
 #define PFX DRV_MODULE_NAME    ": "
-#define DRV_MODULE_VERSION     "3.65"
-#define DRV_MODULE_RELDATE     "August 07, 2006"
+#define DRV_MODULE_VERSION     "3.66f"
+#define DRV_MODULE_RELDATE     "September 1, 2006"
 
 #define TG3_DEF_MAC_MODE       0
 #define TG3_DEF_RX_MODE                0
@@ -145,8 +160,10 @@ MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_MODULE_VERSION);
 
 static int tg3_debug = -1;     /* -1 == use TG3_DEF_MSG_ENABLE as value */
+#if (LINUX_VERSION_CODE >= 0x20600)
 module_param(tg3_debug, int, 0);
 MODULE_PARM_DESC(tg3_debug, "Tigon3 bitmapped debugging message enable value");
+#endif
 
 static struct pci_device_id tg3_pci_tbl[] = {
        { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_TIGON3_5700,
@@ -544,6 +561,9 @@ static inline void tg3_cond_int(struct tg3 *tp)
        if (!(tp->tg3_flags & TG3_FLAG_TAGGED_STATUS) &&
            (tp->hw_status->status & SD_STATUS_UPDATED))
                tw32(GRC_LOCAL_CTRL, tp->grc_local_ctrl | GRC_LCLCTRL_SETINT);
+       else
+               tw32(HOSTCC_MODE, tp->coalesce_mode |
+                    (HOSTCC_MODE_ENABLE | HOSTCC_MODE_NOW));
 }
 
 static void tg3_enable_ints(struct tg3 *tp)
@@ -1172,6 +1192,12 @@ static void tg3_nvram_unlock(struct tg3 *);
 
 static void tg3_power_down_phy(struct tg3 *tp)
 {
+       if (tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)
+               return;
+
+       tg3_writephy(tp, MII_TG3_EXT_CTRL, MII_TG3_EXT_CTRL_FORCE_LED_OFF);
+       tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
+
        /* The PHY should not be powered down on some chips because
         * of bugs.
         */
@@ -1262,7 +1288,12 @@ static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
                        tg3_read_mem(tp, NIC_SRAM_FW_ASF_STATUS_MBOX, &val);
                        if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
                                break;
+#if (LINUX_VERSION_CODE < 0x20607)
+                       set_current_state(TASK_UNINTERRUPTIBLE);
+                       schedule_timeout(HZ / 1000);
+#else
                        msleep(1);
+#endif
                }
        }
        tg3_write_mem(tp, NIC_SRAM_WOL_MBOX, WOL_SIGNATURE |
@@ -1278,7 +1309,10 @@ static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
                        tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x5a);
                        udelay(40);
 
-                       mac_mode = MAC_MODE_PORT_MODE_MII;
+                       if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES)
+                               mac_mode = MAC_MODE_PORT_MODE_GMII;
+                       else
+                               mac_mode = MAC_MODE_PORT_MODE_MII;
 
                        if (GET_ASIC_REV(tp->pci_chip_rev_id) != ASIC_REV_5700 ||
                            !(tp->tg3_flags & TG3_FLAG_WOL_SPEED_100MB))
@@ -1356,15 +1390,9 @@ static int tg3_set_power_state(struct tg3 *tp, pci_power_t state)
        }
 
        if (!(tp->tg3_flags & TG3_FLAG_WOL_ENABLE) &&
-           !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF)) {
+           !(tp->tg3_flags & TG3_FLAG_ENABLE_ASF))
                /* Turn off the PHY */
-               if (!(tp->tg3_flags2 & TG3_FLG2_PHY_SERDES)) {
-                       tg3_writephy(tp, MII_TG3_EXT_CTRL,
-                                    MII_TG3_EXT_CTRL_FORCE_LED_OFF);
-                       tg3_writephy(tp, MII_TG3_AUX_CTRL, 0x01b2);
-                       tg3_power_down_phy(tp);
-               }
-       }
+               tg3_power_down_phy(tp);
 
        tg3_frob_aux_power(tp);
 
@@ -2461,6 +2489,7 @@ static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
        expected_sg_dig_ctrl |= (1 << 12);
 
        if (sg_dig_ctrl != expected_sg_dig_ctrl) {
+restart_autoneg:
                if (workaround)
                        tw32_f(MAC_SERDES_CFG, serdes_cfg | 0xc011000);
                tw32_f(SG_DIG_CTRL, expected_sg_dig_ctrl | (1 << 30));
@@ -2521,7 +2550,8 @@ static int tg3_setup_fiber_hw_autoneg(struct tg3 *tp, u32 mac_status)
                                    !(mac_status & MAC_STATUS_RCVD_CFG)) {
                                        tg3_setup_flow_control(tp, 0, 0);
                                        current_link_up = 1;
-                               }
+                               } else
+                                       goto restart_autoneg;
                        }
                }
        }
@@ -3343,6 +3373,9 @@ next_pkt_nopost:
        tp->rx_rcb_ptr = sw_idx;
        tw32_rx_mbox(MAILBOX_RCVRET_CON_IDX_0 + TG3_64BIT_REG_LOW, sw_idx);
 
+       /* Some platforms need to sync memory here */
+       wmb();
+
        /* Refill RX ring(s). */
        if (work_mask & RXD_OPAQUE_RING_STD) {
                sw_idx = tp->rx_std_ptr % TG3_RX_RING_SIZE;
@@ -3428,7 +3461,11 @@ static void tg3_irq_quiesce(struct tg3 *tp)
        tp->irq_sync = 1;
        smp_mb();
 
+#if (LINUX_VERSION_CODE >= 0x2051c)
        synchronize_irq(tp->pdev->irq);
+#else
+       synchronize_irq();
+#endif
 }
 
 static inline int tg3_irq_sync(struct tg3 *tp)
@@ -3622,11 +3659,22 @@ static int tg3_restart_hw(struct tg3 *tp, int reset_phy)
        return err;
 }
 
-#ifdef CONFIG_NET_POLL_CONTROLLER
+#if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
 static void tg3_poll_controller(struct net_device *dev)
 {
        struct tg3 *tp = netdev_priv(dev);
 
+#if defined(RED_HAT_LINUX_KERNEL) && (LINUX_VERSION_CODE < 0x20600)
+       if (netdump_mode) {
+               tg3_interrupt(tp->pdev->irq, dev, NULL);
+               if (dev->poll_list.prev) {
+                       int budget = 64;
+
+                       tg3_poll(dev, &budget);
+               }
+       }
+       else
+#endif
        tg3_interrupt(tp->pdev->irq, dev, NULL);
 }
 #endif
@@ -3832,9 +3880,12 @@ static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
                        goto out_unlock;
                }
 
+#ifdef NETIF_F_GSO
                if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
                        mss |= (skb_headlen(skb) - ETH_HLEN) << 9;
-               else {
+               else
+#endif
+               {
                        tcp_opt_len = ((skb->h.th->doff - 5) * 4);
                        ip_tcp_len = (skb->nh.iph->ihl * 4) +
                                     sizeof(struct tcphdr);
@@ -3899,6 +3950,9 @@ static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
                }
        }
 
+       /* Some platforms need to sync memory here */
+       wmb();
+
        /* Packets are ready, update Tx producer idx local and on card. */
        tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
 
@@ -3909,7 +3963,9 @@ static int tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
                        netif_wake_queue(tp->dev);
        }
 
+#if TG3_TSO_SUPPORT != 0
 out_unlock:
+#endif
        mmiowb();
 
        dev->trans_start = jiffies;
@@ -3917,7 +3973,9 @@ out_unlock:
        return NETDEV_TX_OK;
 }
 
+
 #if TG3_TSO_SUPPORT != 0
+#ifdef NETIF_F_GSO
 static int tg3_start_xmit_dma_bug(struct sk_buff *, struct net_device *);
 
 /* Use GSO to workaround a rare TSO bug that may be triggered when the
@@ -3950,6 +4008,7 @@ tg3_tso_bug_end:
        return NETDEV_TX_OK;
 }
 #endif
+#endif
 
 /* hard_start_xmit for devices that have the 4G bug and/or 40-bit bug and
  * support TG3_FLG2_HW_TSO_1 or firmware TSO only.
@@ -3999,9 +4058,11 @@ static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
                ip_tcp_len = (skb->nh.iph->ihl * 4) + sizeof(struct tcphdr);
 
                hdr_len = ip_tcp_len + tcp_opt_len;
+#ifdef NETIF_F_GSO
                if (unlikely((ETH_HLEN + hdr_len) > 80) &&
                             (tp->tg3_flags2 & TG3_FLG2_HW_TSO_1_BUG))
                        return (tg3_tso_bug(tp, skb));
+#endif
 
                base_flags |= (TXD_FLAG_CPU_PRE_DMA |
                               TXD_FLAG_CPU_POST_DMA);
@@ -4114,6 +4175,9 @@ static int tg3_start_xmit_dma_bug(struct sk_buff *skb, struct net_device *dev)
                entry = start;
        }
 
+       /* Some platforms need to sync memory here */
+       wmb();
+
        /* Packets are ready, update Tx producer idx local and on card. */
        tw32_tx_mbox((MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW), entry);
 
@@ -4140,7 +4204,9 @@ static inline void tg3_set_mtu(struct net_device *dev, struct tg3 *tp,
        if (new_mtu > ETH_DATA_LEN) {
                if (tp->tg3_flags2 & TG3_FLG2_5780_CLASS) {
                        tp->tg3_flags2 &= ~TG3_FLG2_TSO_CAPABLE;
+#if TG3_TSO_SUPPORT != 0
                        ethtool_op_set_tso(dev, 0);
+#endif
                }
                else
                        tp->tg3_flags |= TG3_FLAG_JUMBO_RING_ENABLE;
@@ -4699,6 +4765,35 @@ static void tg3_write_sig_legacy(struct tg3 *tp, int kind)
        }
 }
 
+static int tg3_poll_fw(struct tg3 *tp)
+{
+       int i;
+       u32 val;
+
+       /* Wait for firmware initialization to complete. */
+       for (i = 0; i < 100000; i++) {
+               tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
+               if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
+                       break;
+               udelay(10);
+       }
+
+       /* Chip might not be fitted with firmare.  Some Sun onboard
+        * parts are configured like that.  So don't signal the timeout
+        * of the above loop as an error, but do report the lack of
+        * running firmware once.
+        */
+       if (i >= 100000 &&
+           !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) {
+               tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED;
+
+               printk(KERN_INFO PFX "%s: No firmware running.\n",
+                      tp->dev->name);
+       }
+
+       return 0;
+}
+
 static void tg3_stop_fw(struct tg3 *);
 
 /* tp->lock is held. */
@@ -4706,7 +4801,7 @@ static int tg3_chip_reset(struct tg3 *tp)
 {
        u32 val;
        void (*write_op)(struct tg3 *, u32, u32);
-       int i;
+       int err;
 
        tg3_nvram_lock(tp);
 
@@ -4803,7 +4898,11 @@ static int tg3_chip_reset(struct tg3 *tp)
                val |= PCISTATE_RETRY_SAME_DMA;
        pci_write_config_dword(tp->pdev, TG3PCI_PCISTATE, val);
 
+#if (LINUX_VERSION_CODE < 0x2060a)
+       pci_restore_state(tp->pdev, tp->pci_cfg_state);
+#else
        pci_restore_state(tp->pdev);
+#endif
 
        /* Make sure PCI-X relaxed ordering bit is clear. */
        pci_read_config_dword(tp->pdev, TG3PCI_X_CAPS, &val);
@@ -4866,26 +4965,9 @@ static int tg3_chip_reset(struct tg3 *tp)
                tw32_f(MAC_MODE, 0);
        udelay(40);
 
-       /* Wait for firmware initialization to complete. */
-       for (i = 0; i < 100000; i++) {
-               tg3_read_mem(tp, NIC_SRAM_FIRMWARE_MBOX, &val);
-               if (val == ~NIC_SRAM_FIRMWARE_MBOX_MAGIC1)
-                       break;
-               udelay(10);
-       }
-
-       /* Chip might not be fitted with firmare.  Some Sun onboard
-        * parts are configured like that.  So don't signal the timeout
-        * of the above loop as an error, but do report the lack of
-        * running firmware once.
-        */
-       if (i >= 100000 &&
-           !(tp->tg3_flags2 & TG3_FLG2_NO_FWARE_REPORTED)) {
-               tp->tg3_flags2 |= TG3_FLG2_NO_FWARE_REPORTED;
-
-               printk(KERN_INFO PFX "%s: No firmware running.\n",
-                      tp->dev->name);
-       }
+       err = tg3_poll_fw(tp);
+       if (err)
+               return err;
 
        if ((tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS) &&
            tp->pci_chip_rev_id != CHIPREV_ID_5750_A0) {
@@ -6735,7 +6817,7 @@ static void tg3_timer(unsigned long __opaque)
                        u32 val;
 
                        tg3_write_mem(tp, NIC_SRAM_FW_CMD_MBOX,
-                                     FWCMD_NICDRV_ALIVE2);
+                                     FWCMD_NICDRV_ALIVE_DETECT);
                        tg3_write_mem(tp, NIC_SRAM_FW_CMD_LEN_MBOX, 4);
                        /* 5 seconds timeout */
                        tg3_write_mem(tp, NIC_SRAM_FW_CMD_DATA_MBOX, 5);
@@ -6802,7 +6884,13 @@ static int tg3_test_interrupt(struct tg3 *tp)
                                        TG3_64BIT_REG_LOW);
                if (int_mbox != 0)
                        break;
+
+#if (LINUX_VERSION_CODE < 0x20607)
+               set_current_state(TASK_UNINTERRUPTIBLE);
+               schedule_timeout(10);
+#else
                msleep(10);
+#endif
        }
 
        tg3_disable_ints(tp);
@@ -6857,7 +6945,9 @@ static int tg3_test_msi(struct tg3 *tp)
                       tp->dev->name);
 
        free_irq(tp->pdev->irq, dev);
+#ifdef CONFIG_PCI_MSI
        pci_disable_msi(tp->pdev);
+#endif
 
        tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
 
@@ -6904,6 +6994,7 @@ static int tg3_open(struct net_device *dev)
        if (err)
                return err;
 
+#ifdef CONFIG_PCI_MSI
        if ((tp->tg3_flags2 & TG3_FLG2_5750_PLUS) &&
            (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_AX) &&
            (GET_CHIP_REV(tp->pci_chip_rev_id) != CHIPREV_5750_BX) &&
@@ -6923,11 +7014,14 @@ static int tg3_open(struct net_device *dev)
                        tp->tg3_flags2 |= TG3_FLG2_USING_MSI;
                }
        }
+#endif
        err = tg3_request_irq(tp);
 
        if (err) {
                if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
+#ifdef CONFIG_PCI_MSI
                        pci_disable_msi(tp->pdev);
+#endif
                        tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
                }
                tg3_free_consistent(tp);
@@ -6963,7 +7057,9 @@ static int tg3_open(struct net_device *dev)
        if (err) {
                free_irq(tp->pdev->irq, dev);
                if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
+#ifdef CONFIG_PCI_MSI
                        pci_disable_msi(tp->pdev);
+#endif
                        tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
                }
                tg3_free_consistent(tp);
@@ -6977,7 +7073,9 @@ static int tg3_open(struct net_device *dev)
                        tg3_full_lock(tp, 0);
 
                        if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
+#ifdef CONFIG_PCI_MSI
                                pci_disable_msi(tp->pdev);
+#endif
                                tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
                        }
                        tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
@@ -7250,8 +7348,14 @@ static int tg3_close(struct net_device *dev)
         * linkwatch_event() may be on the workqueue and it will try to get
         * the rtnl_lock which we are holding.
         */
-       while (tp->tg3_flags & TG3_FLAG_IN_RESET_TASK)
+       while (tp->tg3_flags & TG3_FLAG_IN_RESET_TASK) {
+#if (LINUX_VERSION_CODE < 0x20607)
+               set_current_state(TASK_UNINTERRUPTIBLE);
+               schedule_timeout(1);
+#else
                msleep(1);
+#endif
+       }
 
        netif_stop_queue(dev);
 
@@ -7274,7 +7378,9 @@ static int tg3_close(struct net_device *dev)
 
        free_irq(tp->pdev->irq, dev);
        if (tp->tg3_flags2 & TG3_FLG2_USING_MSI) {
+#ifdef CONFIG_PCI_MSI
                pci_disable_msi(tp->pdev);
+#endif
                tp->tg3_flags2 &= ~TG3_FLG2_USING_MSI;
        }
 
@@ -7671,16 +7777,19 @@ do {    p = (u32 *)(orig_p + (reg));            \
        tg3_full_unlock(tp);
 }
 
+#if (LINUX_VERSION_CODE >= 0x20418)
 static int tg3_get_eeprom_len(struct net_device *dev)
 {
        struct tg3 *tp = netdev_priv(dev);
 
        return tp->nvram_size;
 }
+#endif
 
 static int tg3_nvram_read(struct tg3 *tp, u32 offset, u32 *val);
 static int tg3_nvram_read_swab(struct tg3 *tp, u32 offset, u32 *val);
 
+#ifdef ETHTOOL_GEEPROM
 static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
 {
        struct tg3 *tp = netdev_priv(dev);
@@ -7742,9 +7851,11 @@ static int tg3_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
        }
        return 0;
 }
+#endif
 
 static int tg3_nvram_write_block(struct tg3 *tp, u32 offset, u32 len, u8 *buf); 
 
+#ifdef ETHTOOL_SEEPROM
 static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data)
 {
        struct tg3 *tp = netdev_priv(dev);
@@ -7803,6 +7914,7 @@ static int tg3_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
 
        return ret;
 }
+#endif
 
 static int tg3_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
@@ -7912,7 +8024,7 @@ static int tg3_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
        if (wol->wolopts & ~WAKE_MAGIC)
                return -EINVAL;
        if ((wol->wolopts & WAKE_MAGIC) &&
-           tp->tg3_flags2 & TG3_FLG2_PHY_SERDES &&
+           tp->tg3_flags2 & TG3_FLG2_ANY_SERDES &&
            !(tp->tg3_flags & TG3_FLAG_SERDES_WOL_CAP))
                return -EINVAL;
   
@@ -8117,6 +8229,7 @@ static int tg3_set_rx_csum(struct net_device *dev, u32 data)
        return 0;
 }
   
+#if (LINUX_VERSION_CODE >= 0x20418)
 static int tg3_set_tx_csum(struct net_device *dev, u32 data)
 {
        struct tg3 *tp = netdev_priv(dev);
@@ -8129,12 +8242,17 @@ static int tg3_set_tx_csum(struct net_device *dev, u32 data)
   
        if (GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5755 ||
            GET_ASIC_REV(tp->pci_chip_rev_id) == ASIC_REV_5787)
+#if (LINUX_VERSION_CODE >= 0x20418) && (LINUX_VERSION_CODE < 0x2060c)
+               tg3_set_tx_hw_csum(dev, data);
+#else
                ethtool_op_set_tx_hw_csum(dev, data);
+#endif
        else
                ethtool_op_set_tx_csum(dev, data);
 
        return 0;
 }
+#endif
 
 static int tg3_get_stats_count (struct net_device *dev)
 {
@@ -8185,8 +8303,12 @@ static int tg3_phys_id(struct net_device *dev, u32 data)
                else
                        tw32(MAC_LED_CTRL, LED_CTRL_LNKLED_OVERRIDE |
                                           LED_CTRL_TRAFFIC_OVERRIDE);
-
+#if (LINUX_VERSION_CODE < 0x20609)
+               set_current_state(TASK_INTERRUPTIBLE);
+               if (schedule_timeout(HZ / 2))
+#else
                if (msleep_interruptible(500))
+#endif
                        break;
        }
        tw32(MAC_LED_CTRL, tp->led_ctrl);
@@ -8237,7 +8359,7 @@ static int tg3_test_nvram(struct tg3 *tp)
                goto out;
 
        /* Selfboot format */
-       if (cpu_to_be32(buf[0]) != TG3_EEPROM_MAGIC) {
+       if ((cpu_to_be32(buf[0]) & 0xff000000) == 0xa5000000) {
                u8 *buf8 = (u8 *) buf, csum8 = 0;
 
                for (i = 0; i < size; i++)
@@ -8270,7 +8392,7 @@ out:
 }
 
 #define TG3_SERDES_TIMEOUT_SEC 2
-#define TG3_COPPER_TIMEOUT_SEC 6
+#define TG3_COPPER_TIMEOUT_SEC 7
 
 static int tg3_test_link(struct tg3 *tp)
 {
@@ -8288,7 +8410,12 @@ static int tg3_test_link(struct tg3 *tp)
                if (netif_carrier_ok(tp->dev))
                        return 0;
 
+#if (LINUX_VERSION_CODE < 0x20609)
+               set_current_state(TASK_INTERRUPTIBLE);
+               if (schedule_timeout(HZ))
+#else
                if (msleep_interruptible(1000))
+#endif
                        break;
        }
 
@@ -8298,7 +8425,7 @@ static int tg3_test_link(struct tg3 *tp)
 /* Only test the commonly used registers */
 static int tg3_test_registers(struct tg3 *tp)
 {
-       int i, is_5705;
+       int i, is_5705, is_5750;
        u32 offset, read_mask, write_mask, val, save_val, read_val;
        static struct {
                u16 offset;
@@ -8306,6 +8433,7 @@ static int tg3_test_registers(struct tg3 *tp)
 #define TG3_FL_5705    0x1
 #define TG3_FL_NOT_5705        0x2
 #define TG3_FL_NOT_5788        0x4
+#define TG3_FL_NOT_5750        0x8
                u32 read_mask;
                u32 write_mask;
        } reg_tbl[] = {
@@ -8416,9 +8544,9 @@ static int tg3_test_registers(struct tg3 *tp)
                        0xffffffff, 0x00000000 },
 
                /* Buffer Manager Control Registers. */
-               { BUFMGR_MB_POOL_ADDR, 0x0000,
+               { BUFMGR_MB_POOL_ADDR, TG3_FL_NOT_5750,
                        0x00000000, 0x007fff80 },
-               { BUFMGR_MB_POOL_SIZE, 0x0000,
+               { BUFMGR_MB_POOL_SIZE, TG3_FL_NOT_5750,
                        0x00000000, 0x007fffff },
                { BUFMGR_MB_RDMA_LOW_WATER, 0x0000,
                        0x00000000, 0x0000003f },
@@ -8444,10 +8572,13 @@ static int tg3_test_registers(struct tg3 *tp)
                { 0xffff, 0x0000, 0x00000000, 0x00000000 },
        };
 
-       if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS)
+       is_5705 = 0;
+       is_5750 = 0;
+       if (tp->tg3_flags2 & TG3_FLG2_5705_PLUS) {
                is_5705 = 1;
-       else
-               is_5705 = 0;
+               if (tp->tg3_flags2 & TG3_FLG2_5750_PLUS)
+                       is_5750 = 1;
+       }
 
        for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
                if (is_5705 && (reg_tbl[i].flags & TG3_FL_NOT_5705))
@@ -8460,6 +8591,9 @@ static int tg3_test_registers(struct tg3 *tp)
                    (reg_tbl[i].flags & TG3_FL_NOT_5788))
                        continue;
 
+               if (is_5750 && (reg_tbl[i].flags & TG3_FL_NOT_5750))
+                       continue;
+
                offset = (u32) reg_tbl[i].offset;
                read_mask = reg_tbl[i].read_mask;
                write_mask = reg_tbl[i].write_mask;
@@ -8596,13 +8730,24 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
                        return 0;
 
                mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
-                          MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY |
-                          MAC_MODE_PORT_MODE_GMII;
+                          MAC_MODE_PORT_INT_LPBACK | MAC_MODE_LINK_POLARITY;
+               if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
+                       mac_mode |= MAC_MODE_PORT_MODE_MII;
+               else
+                       mac_mode |= MAC_MODE_PORT_MODE_GMII;
                tw32(MAC_MODE, mac_mode);
        } else if (loopback_mode == TG3_PHY_LOOPBACK) {
-               tg3_writephy(tp, MII_BMCR, BMCR_LOOPBACK | BMCR_FULLDPLX |
-                                          BMCR_SPEED1000);
+               u32 val;
+
+               val = BMCR_LOOPBACK | BMCR_FULLDPLX;
+               if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
+                       val |= BMCR_SPEED100;
+               else
+                       val |= BMCR_SPEED1000;
+
+               tg3_writephy(tp, MII_BMCR, val);
                udelay(40);
+
                /* reset to prevent losing 1st rx packet intermittently */
                if (tp->tg3_flags2 & TG3_FLG2_MII_SERDES) {
                        tw32_f(MAC_RX_MODE, RX_MODE_RESET);
@@ -8610,7 +8755,11 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
                        tw32_f(MAC_RX_MODE, tp->rx_mode);
                }
                mac_mode = (tp->mac_mode & ~MAC_MODE_PORT_MODE_MASK) |
-                          MAC_MODE_LINK_POLARITY | MAC_MODE_PORT_MODE_GMII;
+                          MAC_MODE_LINK_POLARITY;
+               if (tp->tg3_flags & TG3_FLAG_10_100_ONLY)
+                       mac_mode |= MAC_MODE_PORT_MODE_MII;
+               else
+                       mac_mode |= MAC_MODE_PORT_MODE_GMII;
                if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5401) {
                        mac_mode &= ~MAC_MODE_LINK_POLARITY;
                        tg3_writephy(tp, MII_TG3_EXT_CTRL,
@@ -8653,13 +8802,16 @@ static int tg3_run_loopback(struct tg3 *tp, int loopback_mode)
        tp->tx_prod++;
        num_pkts++;
 
+       /* Some platforms need to sync memory here */
+       wmb();
+
        tw32_tx_mbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW,
                     tp->tx_prod);
        tr32_mailbox(MAILBOX_SNDHOST_PROD_IDX_0 + TG3_64BIT_REG_LOW);
 
        udelay(10);
 
-       for (i = 0; i < 10; i++) {
+       for (i = 0; i < 50; i++) {
                tw32_f(HOSTCC_MODE, tp->coalesce_mode | HOSTCC_MODE_ENABLE |
                       HOSTCC_MODE_NOW);
 
@@ -8812,7 +8964,11 @@ static void tg3_self_test(struct net_device *dev, struct ethtool_test *etest,
 
 static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 {
+#if (LINUX_VERSION_CODE >= 0x020607)
        struct mii_ioctl_data *data = if_mii(ifr);
+#else
+       struct mii_ioctl_data *data = (struct mii_ioctl_data *) &ifr->ifr_ifru;
+#endif
        struct tg3 *tp = netdev_priv(dev);
        int err;
 
@@ -8974,9 +9130,15 @@ static struct ethtool_ops tg3_ethtool_ops = {
        .set_msglevel           = tg3_set_msglevel,
        .nway_reset             = tg3_nway_reset,
        .get_link               = ethtool_op_get_link,
+#if (LINUX_VERSION_CODE >= 0x20418)
        .get_eeprom_len         = tg3_get_eeprom_len,
+#endif
+#ifdef ETHTOOL_GEEPROM
        .get_eeprom             = tg3_get_eeprom,
+#endif
+#ifdef ETHTOOL_SEEPROM
        .set_eeprom             = tg3_set_eeprom,
+#endif
        .get_ringparam          = tg3_get_ringparam,
        .set_ringparam          = tg3_set_ringparam,
        .get_pauseparam         = tg3_get_pauseparam,
@@ -8984,7 +9146,9 @@ static struct ethtool_ops tg3_ethtool_ops = {
        .get_rx_csum            = tg3_get_rx_csum,
        .set_rx_csum            = tg3_set_rx_csum,
        .get_tx_csum            = ethtool_op_get_tx_csum,
+#if (LINUX_VERSION_CODE >= 0x20418)
        .set_tx_csum            = tg3_set_tx_csum,
+#endif
        .get_sg                 = ethtool_op_get_sg,
        .set_sg                 = ethtool_op_set_sg,
 #if TG3_TSO_SUPPORT != 0
@@ -8999,7 +9163,9 @@ static struct ethtool_ops tg3_ethtool_ops = {
        .get_ethtool_stats      = tg3_get_ethtool_stats,
        .get_coalesce           = tg3_get_coalesce,
        .set_coalesce           = tg3_set_coalesce,
+#ifdef ETHTOOL_GPERMADDR
        .get_perm_addr          = ethtool_op_get_perm_addr,
+#endif
 };
 
 static void __devinit tg3_get_eeprom_size(struct tg3 *tp)
@@ -9736,7 +9902,12 @@ static void __devinit tg3_get_eeprom_hw_cfg(struct tg3 *tp)
        pci_read_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, &pmcsr);
        pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
        pci_write_config_word(tp->pdev, tp->pm_cap + PCI_PM_CTRL, pmcsr);
+#if (LINUX_VERSION_CODE < 0x20607)
+       set_current_state(TASK_UNINTERRUPTIBLE);
+       schedule_timeout(HZ / 1000);
+#else
        msleep(1);
+#endif
 
        /* Make sure register accesses (indirect or otherwise)
         * will function correctly.
@@ -10036,7 +10207,12 @@ static void __devinit tg3_read_partno(struct tg3 *tp)
                                                     PCI_VPD_ADDR, &tmp16);
                                if (tmp16 & 0x8000)
                                        break;
+#if (LINUX_VERSION_CODE < 0x20607)
+                               set_current_state(TASK_UNINTERRUPTIBLE);
+                               schedule_timeout(1);
+#else
                                msleep(1);
+#endif
                        }
                        if (!(tmp16 & 0x8000))
                                goto out_not_found;
@@ -10134,6 +10310,7 @@ static void __devinit tg3_read_fw_ver(struct tg3 *tp)
 
 static int __devinit tg3_get_invariants(struct tg3 *tp)
 {
+#if (LINUX_VERSION_CODE >= 0x2060a)
        static struct pci_device_id write_reorder_chipsets[] = {
                { PCI_DEVICE(PCI_VENDOR_ID_AMD,
                             PCI_DEVICE_ID_AMD_FE_GATE_700C) },
@@ -10143,6 +10320,7 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
                             PCI_DEVICE_ID_VIA_8385_0) },
                { },
        };
+#endif
        u32 misc_ctrl_reg;
        u32 cacheline_sz_reg;
        u32 pci_state_reg, grc_misc_cfg;
@@ -10329,7 +10507,16 @@ static int __devinit tg3_get_invariants(struct tg3 *tp)
         * every mailbox register write to force the writes to be
         * posted to the chip in order.
         */
+#if (LINUX_VERSION_CODE < 0x2060a)
+       if ((pci_find_device(PCI_VENDOR_ID_AMD,
+                            PCI_DEVICE_ID_AMD_FE_GATE_700C, NULL) ||
+            pci_find_device(PCI_VENDOR_ID_AMD,
+                            PCI_DEVICE_ID_AMD_8131_BRIDGE, NULL) ||
+            pci_find_device(PCI_VENDOR_ID_VIA,
+                            PCI_DEVICE_ID_VIA_8385_0, NULL)) &&
+#else
        if (pci_dev_present(write_reorder_chipsets) &&
+#endif
            !(tp->tg3_flags2 & TG3_FLG2_PCI_EXPRESS))
                tp->tg3_flags |= TG3_FLAG_MBOX_WRITE_REORDER;
 
@@ -10801,7 +10988,9 @@ static int __devinit tg3_get_device_address(struct tg3 *tp)
 #endif
                return -EINVAL;
        }
+#ifdef ETHTOOL_GPERMADDR
        memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
+#endif
        return 0;
 }
 
@@ -11182,17 +11371,25 @@ static int __devinit tg3_test_dma(struct tg3 *tp)
        }
        if ((tp->dma_rwctrl & DMA_RWCTRL_WRITE_BNDRY_MASK) !=
            DMA_RWCTRL_WRITE_BNDRY_16) {
+#if (LINUX_VERSION_CODE >= 0x2060a)
                static struct pci_device_id dma_wait_state_chipsets[] = {
                        { PCI_DEVICE(PCI_VENDOR_ID_APPLE,
                                     PCI_DEVICE_ID_APPLE_UNI_N_PCI15) },
                        { },
                };
+#endif
 
                /* DMA test passed without adjusting DMA boundary,
                 * now look for chipsets that are known to expose the
                 * DMA bug without failing the test.
                 */
-               if (pci_dev_present(dma_wait_state_chipsets)) {
+#if (LINUX_VERSION_CODE < 0x2060a)
+               if (pci_find_device(PCI_VENDOR_ID_APPLE,
+                       PCI_DEVICE_ID_APPLE_UNI_N_PCI15, NULL))
+#else
+               if (pci_dev_present(dma_wait_state_chipsets))
+#endif
+               {
                        tp->dma_rwctrl &= ~DMA_RWCTRL_WRITE_BNDRY_MASK;
                        tp->dma_rwctrl |= DMA_RWCTRL_WRITE_BNDRY_16;
                }
@@ -11437,7 +11634,9 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
        }
 
        SET_MODULE_OWNER(dev);
+#if (LINUX_VERSION_CODE >= 0x20419)
        SET_NETDEV_DEV(dev, &pdev->dev);
+#endif
 
 #if TG3_VLAN_TAG_USED
        dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
@@ -11510,7 +11709,7 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
        dev->watchdog_timeo = TG3_TX_TIMEOUT;
        dev->change_mtu = tg3_change_mtu;
        dev->irq = pdev->irq;
-#ifdef CONFIG_NET_POLL_CONTROLLER
+#if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
        dev->poll_controller = tg3_poll_controller;
 #endif
 
@@ -11612,7 +11811,11 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
         */
        if ((tr32(HOSTCC_MODE) & HOSTCC_MODE_ENABLE) ||
            (tr32(WDMAC_MODE) & WDMAC_MODE_ENABLE)) {
+#if (LINUX_VERSION_CODE < 0x2060a)
+               pci_save_state(tp->pdev, tp->pci_cfg_state);
+#else
                pci_save_state(tp->pdev);
+#endif
                tw32(MEMARB_MODE, MEMARB_MODE_ENABLE);
                tg3_halt(tp, RESET_KIND_SHUTDOWN, 1);
        }
@@ -11646,7 +11849,11 @@ static int __devinit tg3_init_one(struct pci_dev *pdev,
         * of the PCI config space.  We need to restore this after
         * GRC_MISC_CFG core clock resets and some resume events.
         */
+#if (LINUX_VERSION_CODE < 0x2060a)
+       pci_save_state(tp->pdev, tp->pci_cfg_state);
+#else
        pci_save_state(tp->pdev);
+#endif
 
        err = register_netdev(dev);
        if (err) {
@@ -11696,7 +11903,11 @@ err_out_iounmap:
        }
 
 err_out_free_dev:
+#if (LINUX_VERSION_CODE >= 0x20418)
        free_netdev(dev);
+#else
+       kfree(dev);
+#endif
 
 err_out_free_res:
        pci_release_regions(pdev);
@@ -11714,20 +11925,30 @@ static void __devexit tg3_remove_one(struct pci_dev *pdev)
        if (dev) {
                struct tg3 *tp = netdev_priv(dev);
 
+#if (LINUX_VERSION_CODE >= 0x20600)
                flush_scheduled_work();
+#endif
                unregister_netdev(dev);
                if (tp->regs) {
                        iounmap(tp->regs);
                        tp->regs = NULL;
                }
+#if (LINUX_VERSION_CODE >= 0x20418)
                free_netdev(dev);
+#else
+               kfree(dev);
+#endif
                pci_release_regions(pdev);
                pci_disable_device(pdev);
                pci_set_drvdata(pdev, NULL);
        }
 }
 
+#if (LINUX_VERSION_CODE < 0x2060b)
+static int tg3_suspend(struct pci_dev *pdev, u32 state)
+#else
 static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
+#endif
 {
        struct net_device *dev = pci_get_drvdata(pdev);
        struct tg3 *tp = netdev_priv(dev);
@@ -11736,7 +11957,9 @@ static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
        if (!netif_running(dev))
                return 0;
 
+#if (LINUX_VERSION_CODE >= 0x20600)
        flush_scheduled_work();
+#endif
        tg3_netif_stop(tp);
 
        del_timer_sync(&tp->timer);
@@ -11752,7 +11975,11 @@ static int tg3_suspend(struct pci_dev *pdev, pm_message_t state)
        tp->tg3_flags &= ~TG3_FLAG_INIT_COMPLETE;
        tg3_full_unlock(tp);
 
+#if (LINUX_VERSION_CODE < 0x2060b)
+       err = tg3_set_power_state(tp, state);
+#else
        err = tg3_set_power_state(tp, pci_choose_state(pdev, state));
+#endif
        if (err) {
                tg3_full_lock(tp, 0);
 
@@ -11782,7 +12009,11 @@ static int tg3_resume(struct pci_dev *pdev)
        if (!netif_running(dev))
                return 0;
 
+#if (LINUX_VERSION_CODE < 0x2060a)
+       pci_restore_state(tp->pdev, tp->pci_cfg_state);
+#else
        pci_restore_state(tp->pdev);
+#endif
 
        err = tg3_set_power_state(tp, PCI_D0);
        if (err)