Merge ../linux-2.6-watchdog-mm
[pandora-kernel.git] / drivers / net / bnx2.c
index baad015..ee7b75b 100644 (file)
 
 #include "bnx2.h"
 #include "bnx2_fw.h"
+#include "bnx2_fw2.h"
 
 #define DRV_MODULE_NAME                "bnx2"
 #define PFX DRV_MODULE_NAME    ": "
-#define DRV_MODULE_VERSION     "1.4.45"
-#define DRV_MODULE_RELDATE     "September 29, 2006"
+#define DRV_MODULE_VERSION     "1.5.5"
+#define DRV_MODULE_RELDATE     "February 1, 2007"
 
 #define RUN_AT(x) (jiffies + (x))
 
@@ -85,6 +86,7 @@ typedef enum {
        NC370F,
        BCM5708,
        BCM5708S,
+       BCM5709,
 } board_t;
 
 /* indexed by board_t, above */
@@ -98,6 +100,7 @@ static const struct {
        { "HP NC370F Multifunction Gigabit Server Adapter" },
        { "Broadcom NetXtreme II BCM5708 1000Base-T" },
        { "Broadcom NetXtreme II BCM5708 1000Base-SX" },
+       { "Broadcom NetXtreme II BCM5709 1000Base-T" },
        };
 
 static struct pci_device_id bnx2_pci_tbl[] = {
@@ -115,6 +118,8 @@ static struct pci_device_id bnx2_pci_tbl[] = {
          PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706S },
        { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5708S,
          PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5708S },
+       { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5709,
+         PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5709 },
        { 0, }
 };
 
@@ -212,9 +217,16 @@ static inline u32 bnx2_tx_avail(struct bnx2 *bp)
        u32 diff;
 
        smp_mb();
-       diff = TX_RING_IDX(bp->tx_prod) - TX_RING_IDX(bp->tx_cons);
-       if (diff > MAX_TX_DESC_CNT)
-               diff = (diff & MAX_TX_DESC_CNT) - 1;
+
+       /* The ring uses 256 indices for 255 entries, one of them
+        * needs to be skipped.
+        */
+       diff = bp->tx_prod - bp->tx_cons;
+       if (unlikely(diff >= TX_DESC_CNT)) {
+               diff &= 0xffff;
+               if (diff == TX_DESC_CNT)
+                       diff = MAX_TX_DESC_CNT;
+       }
        return (bp->tx_ring_size - diff);
 }
 
@@ -1333,8 +1345,6 @@ bnx2_init_copper_phy(struct bnx2 *bp)
 {
        u32 val;
 
-       bp->phy_flags |= PHY_CRC_FIX_FLAG;
-
        if (bp->phy_flags & PHY_CRC_FIX_FLAG) {
                bnx2_write_phy(bp, 0x18, 0x0c00);
                bnx2_write_phy(bp, 0x17, 0x000a);
@@ -1346,6 +1356,14 @@ bnx2_init_copper_phy(struct bnx2 *bp)
                bnx2_write_phy(bp, 0x18, 0x0400);
        }
 
+       if (bp->phy_flags & PHY_DIS_EARLY_DAC_FLAG) {
+               bnx2_write_phy(bp, MII_BNX2_DSP_ADDRESS,
+                              MII_BNX2_DSP_EXPAND_REG | 0x8);
+               bnx2_read_phy(bp, MII_BNX2_DSP_RW_PORT, &val);
+               val &= ~(1 << 8);
+               bnx2_write_phy(bp, MII_BNX2_DSP_RW_PORT, val);
+       }
+
        if (bp->dev->mtu > 1500) {
                /* Set extended packet length bit */
                bnx2_write_phy(bp, 0x18, 0x7);
@@ -2410,7 +2428,10 @@ bnx2_init_cpus(struct bnx2 *bp)
        cpu_reg.spad_base = BNX2_RXP_SCRATCH;
        cpu_reg.mips_view_base = 0x8000000;
 
-       fw = &bnx2_rxp_fw_06;
+       if (CHIP_NUM(bp) == CHIP_NUM_5709)
+               fw = &bnx2_rxp_fw_09;
+       else
+               fw = &bnx2_rxp_fw_06;
 
        rc = load_cpu_fw(bp, &cpu_reg, fw);
        if (rc)
@@ -2430,7 +2451,10 @@ bnx2_init_cpus(struct bnx2 *bp)
        cpu_reg.spad_base = BNX2_TXP_SCRATCH;
        cpu_reg.mips_view_base = 0x8000000;
 
-       fw = &bnx2_txp_fw_06;
+       if (CHIP_NUM(bp) == CHIP_NUM_5709)
+               fw = &bnx2_txp_fw_09;
+       else
+               fw = &bnx2_txp_fw_06;
 
        rc = load_cpu_fw(bp, &cpu_reg, fw);
        if (rc)
@@ -2450,7 +2474,10 @@ bnx2_init_cpus(struct bnx2 *bp)
        cpu_reg.spad_base = BNX2_TPAT_SCRATCH;
        cpu_reg.mips_view_base = 0x8000000;
 
-       fw = &bnx2_tpat_fw_06;
+       if (CHIP_NUM(bp) == CHIP_NUM_5709)
+               fw = &bnx2_tpat_fw_09;
+       else
+               fw = &bnx2_tpat_fw_06;
 
        rc = load_cpu_fw(bp, &cpu_reg, fw);
        if (rc)
@@ -2470,12 +2497,36 @@ bnx2_init_cpus(struct bnx2 *bp)
        cpu_reg.spad_base = BNX2_COM_SCRATCH;
        cpu_reg.mips_view_base = 0x8000000;
 
-       fw = &bnx2_com_fw_06;
+       if (CHIP_NUM(bp) == CHIP_NUM_5709)
+               fw = &bnx2_com_fw_09;
+       else
+               fw = &bnx2_com_fw_06;
 
        rc = load_cpu_fw(bp, &cpu_reg, fw);
        if (rc)
                goto init_cpu_err;
 
+       /* Initialize the Command Processor. */
+       cpu_reg.mode = BNX2_CP_CPU_MODE;
+       cpu_reg.mode_value_halt = BNX2_CP_CPU_MODE_SOFT_HALT;
+       cpu_reg.mode_value_sstep = BNX2_CP_CPU_MODE_STEP_ENA;
+       cpu_reg.state = BNX2_CP_CPU_STATE;
+       cpu_reg.state_value_clear = 0xffffff;
+       cpu_reg.gpr0 = BNX2_CP_CPU_REG_FILE;
+       cpu_reg.evmask = BNX2_CP_CPU_EVENT_MASK;
+       cpu_reg.pc = BNX2_CP_CPU_PROGRAM_COUNTER;
+       cpu_reg.inst = BNX2_CP_CPU_INSTRUCTION;
+       cpu_reg.bp = BNX2_CP_CPU_HW_BREAKPOINT;
+       cpu_reg.spad_base = BNX2_CP_SCRATCH;
+       cpu_reg.mips_view_base = 0x8000000;
+
+       if (CHIP_NUM(bp) == CHIP_NUM_5709) {
+               fw = &bnx2_cp_fw_09;
+
+               rc = load_cpu_fw(bp, &cpu_reg, fw);
+               if (rc)
+                       goto init_cpu_err;
+       }
 init_cpu_err:
        bnx2_gunzip_end(bp);
        return rc;
@@ -3040,7 +3091,7 @@ bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
                int buf_size)
 {
        u32 written, offset32, len32;
-       u8 *buf, start[4], end[4], *flash_buffer = NULL;
+       u8 *buf, start[4], end[4], *align_buf = NULL, *flash_buffer = NULL;
        int rc = 0;
        int align_start, align_end;
 
@@ -3051,7 +3102,7 @@ bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
 
        if ((align_start = (offset32 & 3))) {
                offset32 &= ~3;
-               len32 += align_start;
+               len32 += (4 - align_start);
                if ((rc = bnx2_nvram_read(bp, offset32, start, 4)))
                        return rc;
        }
@@ -3068,16 +3119,17 @@ bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
        }
 
        if (align_start || align_end) {
-               buf = kmalloc(len32, GFP_KERNEL);
-               if (buf == 0)
+               align_buf = kmalloc(len32, GFP_KERNEL);
+               if (align_buf == NULL)
                        return -ENOMEM;
                if (align_start) {
-                       memcpy(buf, start, 4);
+                       memcpy(align_buf, start, 4);
                }
                if (align_end) {
-                       memcpy(buf + len32 - 4, end, 4);
+                       memcpy(align_buf + len32 - 4, end, 4);
                }
-               memcpy(buf + align_start, data_buf, buf_size);
+               memcpy(align_buf + align_start, data_buf, buf_size);
+               buf = align_buf;
        }
 
        if (bp->flash_info->buffered == 0) {
@@ -3211,11 +3263,8 @@ bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
        }
 
 nvram_write_end:
-       if (bp->flash_info->buffered == 0)
-               kfree(flash_buffer);
-
-       if (align_start || align_end)
-               kfree(buf);
+       kfree(flash_buffer);
+       kfree(align_buf);
        return rc;
 }
 
@@ -3247,31 +3296,44 @@ bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
         * before we issue a reset. */
        val = REG_RD(bp, BNX2_MISC_ID);
 
-       val = BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
-             BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
-             BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
+       if (CHIP_NUM(bp) == CHIP_NUM_5709) {
+               REG_WR(bp, BNX2_MISC_COMMAND, BNX2_MISC_COMMAND_SW_RESET);
+               REG_RD(bp, BNX2_MISC_COMMAND);
+               udelay(5);
 
-       /* Chip reset. */
-       REG_WR(bp, BNX2_PCICFG_MISC_CONFIG, val);
+               val = BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
+                     BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
 
-       if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
-           (CHIP_ID(bp) == CHIP_ID_5706_A1))
-               msleep(15);
+               pci_write_config_dword(bp->pdev, BNX2_PCICFG_MISC_CONFIG, val);
 
-       /* Reset takes approximate 30 usec */
-       for (i = 0; i < 10; i++) {
-               val = REG_RD(bp, BNX2_PCICFG_MISC_CONFIG);
-               if ((val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
-                           BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0) {
-                       break;
+       } else {
+               val = BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
+                     BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
+                     BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
+
+               /* Chip reset. */
+               REG_WR(bp, BNX2_PCICFG_MISC_CONFIG, val);
+
+               if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
+                   (CHIP_ID(bp) == CHIP_ID_5706_A1)) {
+                       current->state = TASK_UNINTERRUPTIBLE;
+                       schedule_timeout(HZ / 50);
                }
-               udelay(10);
-       }
 
-       if (val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
-                  BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
-               printk(KERN_ERR PFX "Chip reset did not complete\n");
-               return -EBUSY;
+               /* Reset takes approximate 30 usec */
+               for (i = 0; i < 10; i++) {
+                       val = REG_RD(bp, BNX2_PCICFG_MISC_CONFIG);
+                       if ((val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
+                                   BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0)
+                               break;
+                       udelay(10);
+               }
+
+               if (val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
+                          BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
+                       printk(KERN_ERR PFX "Chip reset did not complete\n");
+                       return -EBUSY;
+               }
        }
 
        /* Make sure byte swapping is properly configured. */
@@ -3947,7 +4009,7 @@ bnx2_run_loopback(struct bnx2 *bp, int loopback_mode)
        if (!skb)
                return -ENOMEM;
        packet = skb_put(skb, pkt_size);
-       memcpy(packet, bp->mac_addr, 6);
+       memcpy(packet, bp->dev->dev_addr, 6);
        memset(packet + 6, 0x0, 8);
        for (i = 14; i < pkt_size; i++)
                packet[i] = (unsigned char) (i & 0xff);
@@ -3976,8 +4038,8 @@ bnx2_run_loopback(struct bnx2 *bp, int loopback_mode)
        bp->tx_prod = NEXT_TX_BD(bp->tx_prod);
        bp->tx_prod_bseq += pkt_size;
 
-       REG_WR16(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BIDX, bp->tx_prod);
-       REG_WR(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BSEQ, bp->tx_prod_bseq);
+       REG_WR16(bp, bp->tx_bidx_addr, bp->tx_prod);
+       REG_WR(bp, bp->tx_bseq_addr, bp->tx_prod_bseq);
 
        udelay(100);
 
@@ -4360,9 +4422,9 @@ bnx2_open(struct net_device *dev)
 }
 
 static void
-bnx2_reset_task(void *data)
+bnx2_reset_task(struct work_struct *work)
 {
-       struct bnx2 *bp = data;
+       struct bnx2 *bp = container_of(work, struct bnx2, reset_task);
 
        if (!netif_running(bp->dev))
                return;
@@ -4529,8 +4591,8 @@ bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev)
        prod = NEXT_TX_BD(prod);
        bp->tx_prod_bseq += skb->len;
 
-       REG_WR16(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BIDX, prod);
-       REG_WR(bp, MB_TX_CID_ADDR + BNX2_L2CTX_TX_HOST_BSEQ, bp->tx_prod_bseq);
+       REG_WR16(bp, bp->tx_bidx_addr, prod);
+       REG_WR(bp, bp->tx_bseq_addr, bp->tx_prod_bseq);
 
        mmiowb();
 
@@ -5587,6 +5649,44 @@ poll_bnx2(struct net_device *dev)
 }
 #endif
 
+static void __devinit
+bnx2_get_5709_media(struct bnx2 *bp)
+{
+       u32 val = REG_RD(bp, BNX2_MISC_DUAL_MEDIA_CTRL);
+       u32 bond_id = val & BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID;
+       u32 strap;
+
+       if (bond_id == BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_C)
+               return;
+       else if (bond_id == BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
+               bp->phy_flags |= PHY_SERDES_FLAG;
+               return;
+       }
+
+       if (val & BNX2_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE)
+               strap = (val & BNX2_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
+       else
+               strap = (val & BNX2_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP) >> 8;
+
+       if (PCI_FUNC(bp->pdev->devfn) == 0) {
+               switch (strap) {
+               case 0x4:
+               case 0x5:
+               case 0x6:
+                       bp->phy_flags |= PHY_SERDES_FLAG;
+                       return;
+               }
+       } else {
+               switch (strap) {
+               case 0x1:
+               case 0x2:
+               case 0x4:
+                       bp->phy_flags |= PHY_SERDES_FLAG;
+                       return;
+               }
+       }
+}
+
 static int __devinit
 bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
 {
@@ -5651,7 +5751,7 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
        bp->pdev = pdev;
 
        spin_lock_init(&bp->phy_lock);
-       INIT_WORK(&bp->reset_task, bnx2_reset_task, bp);
+       INIT_WORK(&bp->reset_task, bnx2_reset_task);
 
        dev->base_addr = dev->mem_start = pci_resource_start(pdev, 0);
        mem_len = MB_GET_CID_ADDR(TX_TSS_CID + 1);
@@ -5753,9 +5853,11 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
        reg = REG_RD_IND(bp, BNX2_SHM_HDR_SIGNATURE);
 
        if ((reg & BNX2_SHM_HDR_SIGNATURE_SIG_MASK) ==
-           BNX2_SHM_HDR_SIGNATURE_SIG)
-               bp->shmem_base = REG_RD_IND(bp, BNX2_SHM_HDR_ADDR_0);
-       else
+           BNX2_SHM_HDR_SIGNATURE_SIG) {
+               u32 off = PCI_FUNC(pdev->devfn) << 2;
+
+               bp->shmem_base = REG_RD_IND(bp, BNX2_SHM_HDR_ADDR_0 + off);
+       } else
                bp->shmem_base = HOST_VIEW_SHMEM_BASE;
 
        /* Get the permanent MAC address.  First we need to make sure the
@@ -5807,17 +5909,25 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
        bp->phy_addr = 1;
 
        /* Disable WOL support if we are running on a SERDES chip. */
-       if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT) {
+       if (CHIP_NUM(bp) == CHIP_NUM_5709)
+               bnx2_get_5709_media(bp);
+       else if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT)
                bp->phy_flags |= PHY_SERDES_FLAG;
+
+       if (bp->phy_flags & PHY_SERDES_FLAG) {
                bp->flags |= NO_WOL_FLAG;
-               if (CHIP_NUM(bp) == CHIP_NUM_5708) {
+               if (CHIP_NUM(bp) != CHIP_NUM_5706) {
                        bp->phy_addr = 2;
                        reg = REG_RD_IND(bp, bp->shmem_base +
                                         BNX2_SHARED_HW_CFG_CONFIG);
                        if (reg & BNX2_SHARED_HW_CFG_PHY_2_5G)
                                bp->phy_flags |= PHY_2_5G_CAPABLE_FLAG;
                }
-       }
+       } else if (CHIP_NUM(bp) == CHIP_NUM_5706 ||
+                  CHIP_NUM(bp) == CHIP_NUM_5708)
+               bp->phy_flags |= PHY_CRC_FIX_FLAG;
+       else if (CHIP_ID(bp) == CHIP_ID_5709_A0)
+               bp->phy_flags |= PHY_DIS_EARLY_DAC_FLAG;
 
        if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
            (CHIP_ID(bp) == CHIP_ID_5708_B0) ||