]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/bnx2.c
[BNX2]: Update version to 1.6.6.
[linux-2.6-omap-h63xx.git] / drivers / net / bnx2.c
index a729da061bbb649ab51ee0d53775f2a536f049fc..0e4928c751ff024af696a3c202d2706a6bbd940f 100644 (file)
 #include "bnx2_fw.h"
 #include "bnx2_fw2.h"
 
+#define FW_BUF_SIZE            0x8000
+
 #define DRV_MODULE_NAME                "bnx2"
 #define PFX DRV_MODULE_NAME    ": "
-#define DRV_MODULE_VERSION     "1.6.3"
-#define DRV_MODULE_RELDATE     "July 16, 2007"
+#define DRV_MODULE_VERSION     "1.6.6"
+#define DRV_MODULE_RELDATE     "October 2, 2007"
 
 #define RUN_AT(x) (jiffies + (x))
 
@@ -428,7 +430,7 @@ bnx2_netif_stop(struct bnx2 *bp)
 {
        bnx2_disable_int_sync(bp);
        if (netif_running(bp->dev)) {
-               netif_poll_disable(bp->dev);
+               napi_disable(&bp->napi);
                netif_tx_disable(bp->dev);
                bp->dev->trans_start = jiffies; /* prevent tx timeout */
        }
@@ -440,7 +442,7 @@ bnx2_netif_start(struct bnx2 *bp)
        if (atomic_dec_and_test(&bp->intr_sem)) {
                if (netif_running(bp->dev)) {
                        netif_wake_queue(bp->dev);
-                       netif_poll_enable(bp->dev);
+                       napi_enable(&bp->napi);
                        bnx2_enable_int(bp);
                }
        }
@@ -2551,7 +2553,7 @@ bnx2_msi(int irq, void *dev_instance)
        if (unlikely(atomic_read(&bp->intr_sem) != 0))
                return IRQ_HANDLED;
 
-       netif_rx_schedule(dev);
+       netif_rx_schedule(dev, &bp->napi);
 
        return IRQ_HANDLED;
 }
@@ -2568,7 +2570,7 @@ bnx2_msi_1shot(int irq, void *dev_instance)
        if (unlikely(atomic_read(&bp->intr_sem) != 0))
                return IRQ_HANDLED;
 
-       netif_rx_schedule(dev);
+       netif_rx_schedule(dev, &bp->napi);
 
        return IRQ_HANDLED;
 }
@@ -2604,9 +2606,9 @@ bnx2_interrupt(int irq, void *dev_instance)
        if (unlikely(atomic_read(&bp->intr_sem) != 0))
                return IRQ_HANDLED;
 
-       if (netif_rx_schedule_prep(dev)) {
+       if (netif_rx_schedule_prep(dev, &bp->napi)) {
                bp->last_status_idx = sblk->status_idx;
-               __netif_rx_schedule(dev);
+               __netif_rx_schedule(dev, &bp->napi);
        }
 
        return IRQ_HANDLED;
@@ -2632,12 +2634,14 @@ bnx2_has_work(struct bnx2 *bp)
 }
 
 static int
-bnx2_poll(struct net_device *dev, int *budget)
+bnx2_poll(struct napi_struct *napi, int budget)
 {
-       struct bnx2 *bp = netdev_priv(dev);
+       struct bnx2 *bp = container_of(napi, struct bnx2, napi);
+       struct net_device *dev = bp->dev;
        struct status_block *sblk = bp->status_blk;
        u32 status_attn_bits = sblk->status_attn_bits;
        u32 status_attn_bits_ack = sblk->status_attn_bits_ack;
+       int work_done = 0;
 
        if ((status_attn_bits & STATUS_ATTN_EVENTS) !=
            (status_attn_bits_ack & STATUS_ATTN_EVENTS)) {
@@ -2655,23 +2659,14 @@ bnx2_poll(struct net_device *dev, int *budget)
        if (bp->status_blk->status_tx_quick_consumer_index0 != bp->hw_tx_cons)
                bnx2_tx_int(bp);
 
-       if (bp->status_blk->status_rx_quick_consumer_index0 != bp->hw_rx_cons) {
-               int orig_budget = *budget;
-               int work_done;
-
-               if (orig_budget > dev->quota)
-                       orig_budget = dev->quota;
-
-               work_done = bnx2_rx_int(bp, orig_budget);
-               *budget -= work_done;
-               dev->quota -= work_done;
-       }
+       if (bp->status_blk->status_rx_quick_consumer_index0 != bp->hw_rx_cons)
+               work_done = bnx2_rx_int(bp, budget);
 
        bp->last_status_idx = bp->status_blk->status_idx;
        rmb();
 
        if (!bnx2_has_work(bp)) {
-               netif_rx_complete(dev);
+               netif_rx_complete(dev, napi);
                if (likely(bp->flags & USING_MSI_FLAG)) {
                        REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
                               BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
@@ -2686,10 +2681,9 @@ bnx2_poll(struct net_device *dev, int *budget)
                REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
                       BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
                       bp->last_status_idx);
-               return 0;
        }
 
-       return 1;
+       return work_done;
 }
 
 /* Called with rtnl_lock from vlan functions and also netif_tx_lock
@@ -2767,92 +2761,6 @@ bnx2_set_rx_mode(struct net_device *dev)
        spin_unlock_bh(&bp->phy_lock);
 }
 
-#define FW_BUF_SIZE    0x8000
-
-static int
-bnx2_gunzip_init(struct bnx2 *bp)
-{
-       if ((bp->gunzip_buf = vmalloc(FW_BUF_SIZE)) == NULL)
-               goto gunzip_nomem1;
-
-       if ((bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL)) == NULL)
-               goto gunzip_nomem2;
-
-       bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
-       if (bp->strm->workspace == NULL)
-               goto gunzip_nomem3;
-
-       return 0;
-
-gunzip_nomem3:
-       kfree(bp->strm);
-       bp->strm = NULL;
-
-gunzip_nomem2:
-       vfree(bp->gunzip_buf);
-       bp->gunzip_buf = NULL;
-
-gunzip_nomem1:
-       printk(KERN_ERR PFX "%s: Cannot allocate firmware buffer for "
-                           "uncompression.\n", bp->dev->name);
-       return -ENOMEM;
-}
-
-static void
-bnx2_gunzip_end(struct bnx2 *bp)
-{
-       kfree(bp->strm->workspace);
-
-       kfree(bp->strm);
-       bp->strm = NULL;
-
-       if (bp->gunzip_buf) {
-               vfree(bp->gunzip_buf);
-               bp->gunzip_buf = NULL;
-       }
-}
-
-static int
-bnx2_gunzip(struct bnx2 *bp, u8 *zbuf, int len, void **outbuf, int *outlen)
-{
-       int n, rc;
-
-       /* check gzip header */
-       if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED))
-               return -EINVAL;
-
-       n = 10;
-
-#define FNAME  0x8
-       if (zbuf[3] & FNAME)
-               while ((zbuf[n++] != 0) && (n < len));
-
-       bp->strm->next_in = zbuf + n;
-       bp->strm->avail_in = len - n;
-       bp->strm->next_out = bp->gunzip_buf;
-       bp->strm->avail_out = FW_BUF_SIZE;
-
-       rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
-       if (rc != Z_OK)
-               return rc;
-
-       rc = zlib_inflate(bp->strm, Z_FINISH);
-
-       *outlen = FW_BUF_SIZE - bp->strm->avail_out;
-       *outbuf = bp->gunzip_buf;
-
-       if ((rc != Z_OK) && (rc != Z_STREAM_END))
-               printk(KERN_ERR PFX "%s: Firmware decompression error: %s\n",
-                      bp->dev->name, bp->strm->msg);
-
-       zlib_inflateEnd(bp->strm);
-
-       if (rc == Z_STREAM_END)
-               return 0;
-
-       return rc;
-}
-
 static void
 load_rv2p_fw(struct bnx2 *bp, u32 *rv2p_code, u32 rv2p_code_len,
        u32 rv2p_proc)
@@ -2902,19 +2810,13 @@ load_cpu_fw(struct bnx2 *bp, struct cpu_reg *cpu_reg, struct fw_info *fw)
        /* Load the Text area. */
        offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
        if (fw->gz_text) {
-               u32 text_len;
-               void *text;
+               int j;
 
-               rc = bnx2_gunzip(bp, fw->gz_text, fw->gz_text_len, &text,
-                                &text_len);
-               if (rc)
+               rc = zlib_inflate_blob(fw->text, FW_BUF_SIZE, fw->gz_text,
+                                      fw->gz_text_len);
+               if (rc < 0)
                        return rc;
 
-               fw->text = text;
-       }
-       if (fw->gz_text) {
-               int j;
-
                for (j = 0; j < (fw->text_len / 4); j++, offset += 4) {
                        REG_WR_IND(bp, offset, cpu_to_le32(fw->text[j]));
                }
@@ -2932,21 +2834,21 @@ load_cpu_fw(struct bnx2 *bp, struct cpu_reg *cpu_reg, struct fw_info *fw)
 
        /* Load the SBSS area. */
        offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
-       if (fw->sbss) {
+       if (fw->sbss_len) {
                int j;
 
                for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4) {
-                       REG_WR_IND(bp, offset, fw->sbss[j]);
+                       REG_WR_IND(bp, offset, 0);
                }
        }
 
        /* Load the BSS area. */
        offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
-       if (fw->bss) {
+       if (fw->bss_len) {
                int j;
 
                for (j = 0; j < (fw->bss_len/4); j++, offset += 4) {
-                       REG_WR_IND(bp, offset, fw->bss[j]);
+                       REG_WR_IND(bp, offset, 0);
                }
        }
 
@@ -2979,27 +2881,24 @@ bnx2_init_cpus(struct bnx2 *bp)
 {
        struct cpu_reg cpu_reg;
        struct fw_info *fw;
-       int rc = 0;
+       int rc;
        void *text;
-       u32 text_len;
-
-       if ((rc = bnx2_gunzip_init(bp)) != 0)
-               return rc;
 
        /* Initialize the RV2P processor. */
-       rc = bnx2_gunzip(bp, bnx2_rv2p_proc1, sizeof(bnx2_rv2p_proc1), &text,
-                        &text_len);
-       if (rc)
+       text = vmalloc(FW_BUF_SIZE);
+       if (!text)
+               return -ENOMEM;
+       rc = zlib_inflate_blob(text, FW_BUF_SIZE, bnx2_rv2p_proc1, sizeof(bnx2_rv2p_proc1));
+       if (rc < 0)
                goto init_cpu_err;
 
-       load_rv2p_fw(bp, text, text_len, RV2P_PROC1);
+       load_rv2p_fw(bp, text, rc /* == len */, RV2P_PROC1);
 
-       rc = bnx2_gunzip(bp, bnx2_rv2p_proc2, sizeof(bnx2_rv2p_proc2), &text,
-                        &text_len);
-       if (rc)
+       rc = zlib_inflate_blob(text, FW_BUF_SIZE, bnx2_rv2p_proc2, sizeof(bnx2_rv2p_proc2));
+       if (rc < 0)
                goto init_cpu_err;
 
-       load_rv2p_fw(bp, text, text_len, RV2P_PROC2);
+       load_rv2p_fw(bp, text, rc /* == len */, RV2P_PROC2);
 
        /* Initialize the RX Processor. */
        cpu_reg.mode = BNX2_RXP_CPU_MODE;
@@ -3020,6 +2919,7 @@ bnx2_init_cpus(struct bnx2 *bp)
        else
                fw = &bnx2_rxp_fw_06;
 
+       fw->text = text;
        rc = load_cpu_fw(bp, &cpu_reg, fw);
        if (rc)
                goto init_cpu_err;
@@ -3043,6 +2943,7 @@ bnx2_init_cpus(struct bnx2 *bp)
        else
                fw = &bnx2_txp_fw_06;
 
+       fw->text = text;
        rc = load_cpu_fw(bp, &cpu_reg, fw);
        if (rc)
                goto init_cpu_err;
@@ -3066,6 +2967,7 @@ bnx2_init_cpus(struct bnx2 *bp)
        else
                fw = &bnx2_tpat_fw_06;
 
+       fw->text = text;
        rc = load_cpu_fw(bp, &cpu_reg, fw);
        if (rc)
                goto init_cpu_err;
@@ -3089,6 +2991,7 @@ bnx2_init_cpus(struct bnx2 *bp)
        else
                fw = &bnx2_com_fw_06;
 
+       fw->text = text;
        rc = load_cpu_fw(bp, &cpu_reg, fw);
        if (rc)
                goto init_cpu_err;
@@ -3110,12 +3013,13 @@ bnx2_init_cpus(struct bnx2 *bp)
        if (CHIP_NUM(bp) == CHIP_NUM_5709) {
                fw = &bnx2_cp_fw_09;
 
+               fw->text = text;
                rc = load_cpu_fw(bp, &cpu_reg, fw);
                if (rc)
                        goto init_cpu_err;
        }
 init_cpu_err:
-       bnx2_gunzip_end(bp);
+       vfree(text);
        return rc;
 }
 
@@ -3500,7 +3404,7 @@ bnx2_init_nvram(struct bnx2 *bp)
        /* Determine the selected interface. */
        val = REG_RD(bp, BNX2_NVM_CFG1);
 
-       entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
+       entry_count = ARRAY_SIZE(flash_table);
 
        if (val & 0x40000000) {
 
@@ -3934,11 +3838,13 @@ bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
                /* Chip reset. */
                REG_WR(bp, BNX2_PCICFG_MISC_CONFIG, val);
 
+               /* Reading back any register after chip reset will hang the
+                * bus on 5706 A0 and A1.  The msleep below provides plenty
+                * of margin for write posting.
+                */
                if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
-                   (CHIP_ID(bp) == CHIP_ID_5706_A1)) {
-                       current->state = TASK_UNINTERRUPTIBLE;
-                       schedule_timeout(HZ / 50);
-               }
+                   (CHIP_ID(bp) == CHIP_ID_5706_A1))
+                       msleep(20);
 
                /* Reset takes approximate 30 usec */
                for (i = 0; i < 10; i++) {
@@ -5037,6 +4943,8 @@ bnx2_open(struct net_device *dev)
        if (rc)
                return rc;
 
+       napi_enable(&bp->napi);
+
        if ((bp->flags & MSI_CAP_FLAG) && !disable_msi) {
                if (pci_enable_msi(bp->pdev) == 0) {
                        bp->flags |= USING_MSI_FLAG;
@@ -5047,6 +4955,7 @@ bnx2_open(struct net_device *dev)
        rc = bnx2_request_irq(bp);
 
        if (rc) {
+               napi_disable(&bp->napi);
                bnx2_free_mem(bp);
                return rc;
        }
@@ -5054,6 +4963,7 @@ bnx2_open(struct net_device *dev)
        rc = bnx2_init_nic(bp);
 
        if (rc) {
+               napi_disable(&bp->napi);
                bnx2_free_irq(bp);
                bnx2_free_skbs(bp);
                bnx2_free_mem(bp);
@@ -5086,6 +4996,7 @@ bnx2_open(struct net_device *dev)
                                rc = bnx2_request_irq(bp);
 
                        if (rc) {
+                               napi_disable(&bp->napi);
                                bnx2_free_skbs(bp);
                                bnx2_free_mem(bp);
                                del_timer_sync(&bp->timer);
@@ -5299,7 +5210,8 @@ bnx2_close(struct net_device *dev)
        while (bp->in_reset_task)
                msleep(1);
 
-       bnx2_netif_stop(bp);
+       bnx2_disable_int_sync(bp);
+       napi_disable(&bp->napi);
        del_timer_sync(&bp->timer);
        if (bp->flags & NO_WOL_FLAG)
                reset_code = BNX2_DRV_MSG_CODE_UNLOAD_LNK_DN;
@@ -6068,9 +5980,16 @@ static struct {
 };
 
 static int
-bnx2_self_test_count(struct net_device *dev)
+bnx2_get_sset_count(struct net_device *dev, int sset)
 {
-       return BNX2_NUM_TESTS;
+       switch (sset) {
+       case ETH_SS_TEST:
+               return BNX2_NUM_TESTS;
+       case ETH_SS_STATS:
+               return BNX2_NUM_STATS;
+       default:
+               return -EOPNOTSUPP;
+       }
 }
 
 static void
@@ -6144,12 +6063,6 @@ bnx2_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
        }
 }
 
-static int
-bnx2_get_stats_count(struct net_device *dev)
-{
-       return BNX2_NUM_STATS;
-}
-
 static void
 bnx2_get_ethtool_stats(struct net_device *dev,
                struct ethtool_stats *stats, u64 *buf)
@@ -6257,19 +6170,14 @@ static const struct ethtool_ops bnx2_ethtool_ops = {
        .set_pauseparam         = bnx2_set_pauseparam,
        .get_rx_csum            = bnx2_get_rx_csum,
        .set_rx_csum            = bnx2_set_rx_csum,
-       .get_tx_csum            = ethtool_op_get_tx_csum,
        .set_tx_csum            = bnx2_set_tx_csum,
-       .get_sg                 = ethtool_op_get_sg,
        .set_sg                 = ethtool_op_set_sg,
-       .get_tso                = ethtool_op_get_tso,
        .set_tso                = bnx2_set_tso,
-       .self_test_count        = bnx2_self_test_count,
        .self_test              = bnx2_self_test,
        .get_strings            = bnx2_get_strings,
        .phys_id                = bnx2_phys_id,
-       .get_stats_count        = bnx2_get_stats_count,
        .get_ethtool_stats      = bnx2_get_ethtool_stats,
-       .get_perm_addr          = ethtool_op_get_perm_addr,
+       .get_sset_count         = bnx2_get_sset_count,
 };
 
 /* Called with rtnl_lock */
@@ -6475,7 +6383,6 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
        u32 reg;
        u64 dma_mask, persist_dma_mask;
 
-       SET_MODULE_OWNER(dev);
        SET_NETDEV_DEV(dev, &pdev->dev);
        bp = netdev_priv(dev);
 
@@ -6726,7 +6633,8 @@ bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
        } 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)
+       else if (CHIP_ID(bp) == CHIP_ID_5709_A0 ||
+                CHIP_ID(bp) == CHIP_ID_5709_A1)
                bp->phy_flags |= PHY_DIS_EARLY_DAC_FLAG;
 
        if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
@@ -6825,8 +6733,9 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        static int version_printed = 0;
        struct net_device *dev = NULL;
        struct bnx2 *bp;
-       int rc, i;
+       int rc;
        char str[40];
+       DECLARE_MAC_BUF(mac);
 
        if (version_printed++ == 0)
                printk(KERN_INFO "%s", version);
@@ -6856,11 +6765,10 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 #ifdef BCM_VLAN
        dev->vlan_rx_register = bnx2_vlan_rx_register;
 #endif
-       dev->poll = bnx2_poll;
        dev->ethtool_ops = &bnx2_ethtool_ops;
-       dev->weight = 64;
 
        bp = netdev_priv(dev);
+       netif_napi_add(dev, &bp->napi, bnx2_poll, 64);
 
 #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
        dev->poll_controller = poll_bnx2;
@@ -6895,19 +6803,14 @@ bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        }
 
        printk(KERN_INFO "%s: %s (%c%d) %s found at mem %lx, "
-               "IRQ %d, ",
+               "IRQ %d, node addr %s\n",
                dev->name,
                bp->name,
                ((CHIP_ID(bp) & 0xf000) >> 12) + 'A',
                ((CHIP_ID(bp) & 0x0ff0) >> 4),
                bnx2_bus_string(bp, str),
                dev->base_addr,
-               bp->pdev->irq);
-
-       printk("node addr ");
-       for (i = 0; i < 6; i++)
-               printk("%2.2x", dev->dev_addr[i]);
-       printk("\n");
+               bp->pdev->irq, print_mac(mac, dev->dev_addr));
 
        return 0;
 }
@@ -6938,6 +6841,11 @@ bnx2_suspend(struct pci_dev *pdev, pm_message_t state)
        struct bnx2 *bp = netdev_priv(dev);
        u32 reset_code;
 
+       /* PCI register 4 needs to be saved whether netif_running() or not.
+        * MSI address and data need to be saved if using MSI and
+        * netif_running().
+        */
+       pci_save_state(pdev);
        if (!netif_running(dev))
                return 0;
 
@@ -6953,7 +6861,6 @@ bnx2_suspend(struct pci_dev *pdev, pm_message_t state)
                reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
        bnx2_reset_chip(bp, reset_code);
        bnx2_free_skbs(bp);
-       pci_save_state(pdev);
        bnx2_set_power_state(bp, pci_choose_state(pdev, state));
        return 0;
 }
@@ -6964,10 +6871,10 @@ bnx2_resume(struct pci_dev *pdev)
        struct net_device *dev = pci_get_drvdata(pdev);
        struct bnx2 *bp = netdev_priv(dev);
 
+       pci_restore_state(pdev);
        if (!netif_running(dev))
                return 0;
 
-       pci_restore_state(pdev);
        bnx2_set_power_state(bp, PCI_D0);
        netif_device_attach(dev);
        bnx2_init_nic(bp);