Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/bnx2-2.6
[sfrench/cifs-2.6.git] / drivers / net / bnx2.c
index 7d824cf8ee2d3e6893b00c70aad0d71a61e4ca3c..ee7b75b976b5c60a41dc0ba3e76651cba42b113c 100644 (file)
@@ -57,8 +57,8 @@
 
 #define DRV_MODULE_NAME                "bnx2"
 #define PFX DRV_MODULE_NAME    ": "
-#define DRV_MODULE_VERSION     "1.5.1"
-#define DRV_MODULE_RELDATE     "November 15, 2006"
+#define DRV_MODULE_VERSION     "1.5.5"
+#define DRV_MODULE_RELDATE     "February 1, 2007"
 
 #define RUN_AT(x) (jiffies + (x))
 
@@ -217,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);
 }
 
@@ -1338,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);
@@ -1351,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);
@@ -3078,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;
 
@@ -3089,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;
        }
@@ -3106,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) {
@@ -3249,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;
 }
 
@@ -3998,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);
@@ -5638,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)
 {
@@ -5804,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
@@ -5858,10 +5909,9 @@ 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_NUM(bp) == CHIP_NUM_5709) {
-               if (CHIP_BOND_ID(bp) != BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_C)
-                       bp->phy_flags |= PHY_SERDES_FLAG;
-       } else 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) {
@@ -5873,7 +5923,11 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
                        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) ||