Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/cpufreq
[sfrench/cifs-2.6.git] / drivers / net / bnx2.c
index c571da60241d599da18e0aa05586a2b0d65dca9a..02e994b1b028f1d1f6c23cbde2538ae253091092 100644 (file)
@@ -40,7 +40,6 @@
 #define BCM_VLAN 1
 #endif
 #include <net/ip.h>
-#include <net/tcp.h>
 #include <net/checksum.h>
 #include <linux/workqueue.h>
 #include <linux/crc32.h>
@@ -54,8 +53,8 @@
 
 #define DRV_MODULE_NAME                "bnx2"
 #define PFX DRV_MODULE_NAME    ": "
-#define DRV_MODULE_VERSION     "1.5.11"
-#define DRV_MODULE_RELDATE     "June 4, 2007"
+#define DRV_MODULE_VERSION     "1.6.2"
+#define DRV_MODULE_RELDATE     "July 6, 2007"
 
 #define RUN_AT(x) (jiffies + (x))
 
@@ -604,12 +603,21 @@ bnx2_report_fw_link(struct bnx2 *bp)
        REG_WR_IND(bp, bp->shmem_base + BNX2_LINK_STATUS, fw_link_status);
 }
 
+static char *
+bnx2_xceiver_str(struct bnx2 *bp)
+{
+       return ((bp->phy_port == PORT_FIBRE) ? "SerDes" :
+               ((bp->phy_flags & PHY_SERDES_FLAG) ? "Remote Copper" :
+                "Copper"));
+}
+
 static void
 bnx2_report_link(struct bnx2 *bp)
 {
        if (bp->link_up) {
                netif_carrier_on(bp->dev);
-               printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name);
+               printk(KERN_INFO PFX "%s NIC %s Link is Up, ", bp->dev->name,
+                      bnx2_xceiver_str(bp));
 
                printk("%d Mbps ", bp->line_speed);
 
@@ -633,7 +641,8 @@ bnx2_report_link(struct bnx2 *bp)
        }
        else {
                netif_carrier_off(bp->dev);
-               printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name);
+               printk(KERN_ERR PFX "%s NIC %s Link is Down\n", bp->dev->name,
+                      bnx2_xceiver_str(bp));
        }
 
        bnx2_report_fw_link(bp);
@@ -1476,6 +1485,20 @@ bnx2_set_default_link(struct bnx2 *bp)
                bp->advertising = ETHTOOL_ALL_COPPER_SPEED | ADVERTISED_Autoneg;
 }
 
+static void
+bnx2_send_heart_beat(struct bnx2 *bp)
+{
+       u32 msg;
+       u32 addr;
+
+       spin_lock(&bp->indirect_lock);
+       msg = (u32) (++bp->fw_drv_pulse_wr_seq & BNX2_DRV_PULSE_SEQ_MASK);
+       addr = bp->shmem_base + BNX2_DRV_PULSE_MB;
+       REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, addr);
+       REG_WR(bp, BNX2_PCICFG_REG_WINDOW, msg);
+       spin_unlock(&bp->indirect_lock);
+}
+
 static void
 bnx2_remote_phy_event(struct bnx2 *bp)
 {
@@ -1485,6 +1508,11 @@ bnx2_remote_phy_event(struct bnx2 *bp)
 
        msg = REG_RD_IND(bp, bp->shmem_base + BNX2_LINK_STATUS);
 
+       if (msg & BNX2_LINK_STATUS_HEART_BEAT_EXPIRED)
+               bnx2_send_heart_beat(bp);
+
+       msg &= ~BNX2_LINK_STATUS_HEART_BEAT_EXPIRED;
+
        if ((msg & BNX2_LINK_STATUS_LINK_UP) == BNX2_LINK_STATUS_LINK_DOWN)
                bp->link_up = 0;
        else {
@@ -1562,6 +1590,7 @@ bnx2_set_remote_link(struct bnx2 *bp)
                        break;
                case BNX2_FW_EVT_CODE_SW_TIMER_EXPIRATION_EVENT:
                default:
+                       bnx2_send_heart_beat(bp);
                        break;
        }
        return 0;
@@ -2537,6 +2566,7 @@ bnx2_interrupt(int irq, void *dev_instance)
 {
        struct net_device *dev = dev_instance;
        struct bnx2 *bp = netdev_priv(dev);
+       struct status_block *sblk = bp->status_blk;
 
        /* When using INTx, it is possible for the interrupt to arrive
         * at the CPU before the status block posted prior to the
@@ -2544,7 +2574,7 @@ bnx2_interrupt(int irq, void *dev_instance)
         * When using MSI, the MSI message will always complete after
         * the status block write.
         */
-       if ((bp->status_blk->status_idx == bp->last_status_idx) &&
+       if ((sblk->status_idx == bp->last_status_idx) &&
            (REG_RD(bp, BNX2_PCICFG_MISC_STATUS) &
             BNX2_PCICFG_MISC_STATUS_INTA_VALUE))
                return IRQ_NONE;
@@ -2553,11 +2583,19 @@ bnx2_interrupt(int irq, void *dev_instance)
                BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
                BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
 
+       /* Read back to deassert IRQ immediately to avoid too many
+        * spurious interrupts.
+        */
+       REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD);
+
        /* Return here if interrupt is shared and is disabled. */
        if (unlikely(atomic_read(&bp->intr_sem) != 0))
                return IRQ_HANDLED;
 
-       netif_rx_schedule(dev);
+       if (netif_rx_schedule_prep(dev)) {
+               bp->last_status_idx = sblk->status_idx;
+               __netif_rx_schedule(dev);
+       }
 
        return IRQ_HANDLED;
 }
@@ -4103,7 +4141,7 @@ bnx2_init_chip(struct bnx2 *bp)
        rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT2 | BNX2_DRV_MSG_CODE_RESET,
                          0);
 
-       REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS, 0x5ffffff);
+       REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS, BNX2_MISC_ENABLE_DEFAULT);
        REG_RD(bp, BNX2_MISC_ENABLE_SET_BITS);
 
        udelay(20);
@@ -4911,7 +4949,6 @@ static void
 bnx2_timer(unsigned long data)
 {
        struct bnx2 *bp = (struct bnx2 *) data;
-       u32 msg;
 
        if (!netif_running(bp->dev))
                return;
@@ -4919,8 +4956,7 @@ bnx2_timer(unsigned long data)
        if (atomic_read(&bp->intr_sem) != 0)
                goto bnx2_restart_timer;
 
-       msg = (u32) ++bp->fw_drv_pulse_wr_seq;
-       REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_PULSE_MB, msg);
+       bnx2_send_heart_beat(bp);
 
        bp->stats_blk->stat_FwRxDrop = REG_RD_IND(bp, BNX2_FW_RX_DROP_COUNT);
 
@@ -5363,17 +5399,25 @@ static int
 bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
        struct bnx2 *bp = netdev_priv(dev);
+       int support_serdes = 0, support_copper = 0;
 
        cmd->supported = SUPPORTED_Autoneg;
-       if (bp->phy_flags & PHY_SERDES_FLAG) {
+       if (bp->phy_flags & REMOTE_PHY_CAP_FLAG) {
+               support_serdes = 1;
+               support_copper = 1;
+       } else if (bp->phy_port == PORT_FIBRE)
+               support_serdes = 1;
+       else
+               support_copper = 1;
+
+       if (support_serdes) {
                cmd->supported |= SUPPORTED_1000baseT_Full |
                        SUPPORTED_FIBRE;
                if (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG)
                        cmd->supported |= SUPPORTED_2500baseX_Full;
 
-               cmd->port = PORT_FIBRE;
        }
-       else {
+       if (support_copper) {
                cmd->supported |= SUPPORTED_10baseT_Half |
                        SUPPORTED_10baseT_Full |
                        SUPPORTED_100baseT_Half |
@@ -5381,9 +5425,10 @@ bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
                        SUPPORTED_1000baseT_Full |
                        SUPPORTED_TP;
 
-               cmd->port = PORT_TP;
        }
 
+       spin_lock_bh(&bp->phy_lock);
+       cmd->port = bp->phy_port;
        cmd->advertising = bp->advertising;
 
        if (bp->autoneg & AUTONEG_SPEED) {
@@ -5401,6 +5446,7 @@ bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
                cmd->speed = -1;
                cmd->duplex = -1;
        }
+       spin_unlock_bh(&bp->phy_lock);
 
        cmd->transceiver = XCVR_INTERNAL;
        cmd->phy_address = bp->phy_addr;
@@ -5416,6 +5462,15 @@ bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
        u8 req_duplex = bp->req_duplex;
        u16 req_line_speed = bp->req_line_speed;
        u32 advertising = bp->advertising;
+       int err = -EINVAL;
+
+       spin_lock_bh(&bp->phy_lock);
+
+       if (cmd->port != PORT_TP && cmd->port != PORT_FIBRE)
+               goto err_out_unlock;
+
+       if (cmd->port != bp->phy_port && !(bp->phy_flags & REMOTE_PHY_CAP_FLAG))
+               goto err_out_unlock;
 
        if (cmd->autoneg == AUTONEG_ENABLE) {
                autoneg |= AUTONEG_SPEED;
@@ -5428,44 +5483,41 @@ bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
                        (cmd->advertising == ADVERTISED_100baseT_Half) ||
                        (cmd->advertising == ADVERTISED_100baseT_Full)) {
 
-                       if (bp->phy_flags & PHY_SERDES_FLAG)
-                               return -EINVAL;
+                       if (cmd->port == PORT_FIBRE)
+                               goto err_out_unlock;
 
                        advertising = cmd->advertising;
 
                } else if (cmd->advertising == ADVERTISED_2500baseX_Full) {
-                       if (!(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
-                               return -EINVAL;
-               } else if (cmd->advertising == ADVERTISED_1000baseT_Full) {
+                       if (!(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) ||
+                           (cmd->port == PORT_TP))
+                               goto err_out_unlock;
+               } else if (cmd->advertising == ADVERTISED_1000baseT_Full)
                        advertising = cmd->advertising;
-               }
-               else if (cmd->advertising == ADVERTISED_1000baseT_Half) {
-                       return -EINVAL;
-               }
+               else if (cmd->advertising == ADVERTISED_1000baseT_Half)
+                       goto err_out_unlock;
                else {
-                       if (bp->phy_flags & PHY_SERDES_FLAG) {
+                       if (cmd->port == PORT_FIBRE)
                                advertising = ETHTOOL_ALL_FIBRE_SPEED;
-                       }
-                       else {
+                       else
                                advertising = ETHTOOL_ALL_COPPER_SPEED;
-                       }
                }
                advertising |= ADVERTISED_Autoneg;
        }
        else {
-               if (bp->phy_flags & PHY_SERDES_FLAG) {
+               if (cmd->port == PORT_FIBRE) {
                        if ((cmd->speed != SPEED_1000 &&
                             cmd->speed != SPEED_2500) ||
                            (cmd->duplex != DUPLEX_FULL))
-                               return -EINVAL;
+                               goto err_out_unlock;
 
                        if (cmd->speed == SPEED_2500 &&
                            !(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
-                               return -EINVAL;
-               }
-               else if (cmd->speed == SPEED_1000) {
-                       return -EINVAL;
+                               goto err_out_unlock;
                }
+               else if (cmd->speed == SPEED_1000 || cmd->speed == SPEED_2500)
+                       goto err_out_unlock;
+
                autoneg &= ~AUTONEG_SPEED;
                req_line_speed = cmd->speed;
                req_duplex = cmd->duplex;
@@ -5477,13 +5529,12 @@ bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
        bp->req_line_speed = req_line_speed;
        bp->req_duplex = req_duplex;
 
-       spin_lock_bh(&bp->phy_lock);
-
-       bnx2_setup_phy(bp, bp->phy_port);
+       err = bnx2_setup_phy(bp, cmd->port);
 
+err_out_unlock:
        spin_unlock_bh(&bp->phy_lock);
 
-       return 0;
+       return err;
 }
 
 static void
@@ -5494,11 +5545,7 @@ bnx2_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
        strcpy(info->driver, DRV_MODULE_NAME);
        strcpy(info->version, DRV_MODULE_VERSION);
        strcpy(info->bus_info, pci_name(bp->pdev));
-       info->fw_version[0] = ((bp->fw_ver & 0xff000000) >> 24) + '0';
-       info->fw_version[2] = ((bp->fw_ver & 0xff0000) >> 16) + '0';
-       info->fw_version[4] = ((bp->fw_ver & 0xff00) >> 8) + '0';
-       info->fw_version[1] = info->fw_version[3] = '.';
-       info->fw_version[5] = 0;
+       strcpy(info->fw_version, bp->fw_version);
 }
 
 #define BNX2_REGDUMP_LEN               (32 * 1024)
@@ -5610,6 +5657,14 @@ bnx2_nway_reset(struct net_device *dev)
 
        spin_lock_bh(&bp->phy_lock);
 
+       if (bp->phy_flags & REMOTE_PHY_CAP_FLAG) {
+               int rc;
+
+               rc = bnx2_setup_remote_phy(bp, bp->phy_port);
+               spin_unlock_bh(&bp->phy_lock);
+               return rc;
+       }
+
        /* Force a link down visible on the other side */
        if (bp->phy_flags & PHY_SERDES_FLAG) {
                bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK);
@@ -6219,6 +6274,9 @@ bnx2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
        case SIOCGMIIREG: {
                u32 mii_regval;
 
+               if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
+                       return -EOPNOTSUPP;
+
                if (!netif_running(dev))
                        return -EAGAIN;
 
@@ -6235,6 +6293,9 @@ bnx2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
                if (!capable(CAP_NET_ADMIN))
                        return -EPERM;
 
+               if (bp->phy_flags & REMOTE_PHY_CAP_FLAG)
+                       return -EOPNOTSUPP;
+
                if (!netif_running(dev))
                        return -EAGAIN;
 
@@ -6396,7 +6457,7 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
 {
        struct bnx2 *bp;
        unsigned long mem_len;
-       int rc;
+       int rc, i, j;
        u32 reg;
        u64 dma_mask, persist_dma_mask;
 
@@ -6553,7 +6614,35 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
                goto err_out_unmap;
        }
 
-       bp->fw_ver = REG_RD_IND(bp, bp->shmem_base + BNX2_DEV_INFO_BC_REV);
+       reg = REG_RD_IND(bp, bp->shmem_base + BNX2_DEV_INFO_BC_REV);
+       for (i = 0, j = 0; i < 3; i++) {
+               u8 num, k, skip0;
+
+               num = (u8) (reg >> (24 - (i * 8)));
+               for (k = 100, skip0 = 1; k >= 1; num %= k, k /= 10) {
+                       if (num >= k || !skip0 || k == 1) {
+                               bp->fw_version[j++] = (num / k) + '0';
+                               skip0 = 0;
+                       }
+               }
+               if (i != 2)
+                       bp->fw_version[j++] = '.';
+       }
+       reg = REG_RD_IND(bp, bp->shmem_base + BNX2_BC_STATE_CONDITION);
+       reg &= BNX2_CONDITION_MFW_RUN_MASK;
+       if (reg != BNX2_CONDITION_MFW_RUN_UNKNOWN &&
+           reg != BNX2_CONDITION_MFW_RUN_NONE) {
+               int i;
+               u32 addr = REG_RD_IND(bp, bp->shmem_base + BNX2_MFW_VER_PTR);
+
+               bp->fw_version[j++] = ' ';
+               for (i = 0; i < 3; i++) {
+                       reg = REG_RD_IND(bp, addr + i * 4);
+                       reg = swab32(reg);
+                       memcpy(&bp->fw_version[j], &reg, 4);
+                       j += 4;
+               }
+       }
 
        reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_MAC_UPPER);
        bp->mac_addr[0] = (u8) (reg >> 8);
@@ -6647,10 +6736,9 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
                while ((amd_8132 = pci_get_device(PCI_VENDOR_ID_AMD,
                                                  PCI_DEVICE_ID_AMD_8132_BRIDGE,
                                                  amd_8132))) {
-                       u8 rev;
 
-                       pci_read_config_byte(amd_8132, PCI_REVISION_ID, &rev);
-                       if (rev >= 0x10 && rev <= 0x13) {
+                       if (amd_8132->revision >= 0x10 &&
+                           amd_8132->revision <= 0x13) {
                                disable_msi = 1;
                                pci_dev_put(amd_8132);
                                break;