Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[safe/jmp/linux-2.6] / drivers / net / bnx2x_main.c
index 82deea0..49f8e78 100644 (file)
@@ -59,8 +59,8 @@
 #include "bnx2x.h"
 #include "bnx2x_init.h"
 
-#define DRV_MODULE_VERSION     "1.45.20"
-#define DRV_MODULE_RELDATE     "2008/08/25"
+#define DRV_MODULE_VERSION     "1.45.23"
+#define DRV_MODULE_RELDATE     "2008/11/03"
 #define BNX2X_BC_VER           0x040200
 
 /* Time in jiffies before concluding the transmitter is hung */
@@ -649,15 +649,16 @@ static void bnx2x_int_disable(struct bnx2x *bp)
                BNX2X_ERR("BUG! proper val not read from IGU!\n");
 }
 
-static void bnx2x_int_disable_sync(struct bnx2x *bp)
+static void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
 {
        int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
        int i;
 
        /* disable interrupt handling */
        atomic_inc(&bp->intr_sem);
-       /* prevent the HW from sending interrupts */
-       bnx2x_int_disable(bp);
+       if (disable_hw)
+               /* prevent the HW from sending interrupts */
+               bnx2x_int_disable(bp);
 
        /* make sure all ISRs are done */
        if (msix) {
@@ -1027,7 +1028,7 @@ static inline int bnx2x_alloc_rx_skb(struct bnx2x *bp,
        if (unlikely(skb == NULL))
                return -ENOMEM;
 
-       mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_use_size,
+       mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_size,
                                 PCI_DMA_FROMDEVICE);
        if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
                dev_kfree_skb(skb);
@@ -1169,7 +1170,7 @@ static void bnx2x_tpa_start(struct bnx2x_fastpath *fp, u16 queue,
        /* move empty skb from pool to prod and map it */
        prod_rx_buf->skb = fp->tpa_pool[queue].skb;
        mapping = pci_map_single(bp->pdev, fp->tpa_pool[queue].skb->data,
-                                bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
+                                bp->rx_buf_size, PCI_DMA_FROMDEVICE);
        pci_unmap_addr_set(prod_rx_buf, mapping, mapping);
 
        /* move partial skb from cons to pool (don't unmap yet) */
@@ -1276,7 +1277,7 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
           pool entry status to BNX2X_TPA_STOP even if new skb allocation
           fails. */
        pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping),
-                        bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
+                        bp->rx_buf_size, PCI_DMA_FROMDEVICE);
 
        if (likely(new_skb)) {
                /* fix ip xsum and give it to the stack */
@@ -1327,7 +1328,6 @@ static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
                        dev_kfree_skb(skb);
                }
 
-               bp->dev->last_rx = jiffies;
 
                /* put new skb in bin */
                fp->tpa_pool[queue].skb = new_skb;
@@ -1520,7 +1520,7 @@ static int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget)
                        } else if (bnx2x_alloc_rx_skb(bp, fp, bd_prod) == 0) {
                                pci_unmap_single(bp->pdev,
                                        pci_unmap_addr(rx_buf, mapping),
-                                                bp->rx_buf_use_size,
+                                                bp->rx_buf_size,
                                                 PCI_DMA_FROMDEVICE);
                                skb_reserve(skb, pad);
                                skb_put(skb, len);
@@ -1556,7 +1556,6 @@ reuse_rx:
 #endif
                        netif_receive_skb(skb);
 
-               bp->dev->last_rx = jiffies;
 
 next_rx:
                rx_buf->skb = NULL;
@@ -4229,7 +4228,7 @@ static inline void bnx2x_free_tpa_pool(struct bnx2x *bp,
                if (fp->tpa_state[i] == BNX2X_TPA_START)
                        pci_unmap_single(bp->pdev,
                                         pci_unmap_addr(rx_buf, mapping),
-                                        bp->rx_buf_use_size,
+                                        bp->rx_buf_size,
                                         PCI_DMA_FROMDEVICE);
 
                dev_kfree_skb(skb);
@@ -4245,15 +4244,14 @@ static void bnx2x_init_rx_rings(struct bnx2x *bp)
        u16 ring_prod, cqe_ring_prod;
        int i, j;
 
-       bp->rx_buf_use_size = bp->dev->mtu;
-       bp->rx_buf_use_size += bp->rx_offset + ETH_OVREHEAD;
-       bp->rx_buf_size = bp->rx_buf_use_size + 64;
+       bp->rx_buf_size = bp->dev->mtu;
+       bp->rx_buf_size += bp->rx_offset + ETH_OVREHEAD +
+               BCM_RX_ETH_PAYLOAD_ALIGN;
 
        if (bp->flags & TPA_ENABLE_FLAG) {
                DP(NETIF_MSG_IFUP,
-                  "rx_buf_use_size %d  rx_buf_size %d  effective_mtu %d\n",
-                  bp->rx_buf_use_size, bp->rx_buf_size,
-                  bp->dev->mtu + ETH_OVREHEAD);
+                  "rx_buf_size %d  effective_mtu %d\n",
+                  bp->rx_buf_size, bp->dev->mtu + ETH_OVREHEAD);
 
                for_each_queue(bp, j) {
                        struct bnx2x_fastpath *fp = &bp->fp[j];
@@ -4462,9 +4460,10 @@ static void bnx2x_init_context(struct bnx2x *bp)
                context->ustorm_st_context.common.status_block_id = sb_id;
                context->ustorm_st_context.common.flags =
                        USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_MC_ALIGNMENT;
-               context->ustorm_st_context.common.mc_alignment_size = 64;
+               context->ustorm_st_context.common.mc_alignment_size =
+                       BCM_RX_ETH_PAYLOAD_ALIGN;
                context->ustorm_st_context.common.bd_buff_size =
-                                               bp->rx_buf_use_size;
+                                               bp->rx_buf_size;
                context->ustorm_st_context.common.bd_page_base_hi =
                                                U64_HI(fp->rx_desc_mapping);
                context->ustorm_st_context.common.bd_page_base_lo =
@@ -4717,7 +4716,7 @@ static void bnx2x_init_internal_func(struct bnx2x *bp)
        }
 
        /* Init CQ ring mapping and aggregation size */
-       max_agg_size = min((u32)(bp->rx_buf_use_size +
+       max_agg_size = min((u32)(bp->rx_buf_size +
                                 8*BCM_PAGE_SIZE*PAGES_PER_SGE),
                           (u32)0xffff);
        for_each_queue(bp, i) {
@@ -5940,7 +5939,7 @@ static void bnx2x_free_rx_skbs(struct bnx2x *bp)
 
                        pci_unmap_single(bp->pdev,
                                         pci_unmap_addr(rx_buf, mapping),
-                                        bp->rx_buf_use_size,
+                                        bp->rx_buf_size,
                                         PCI_DMA_FROMDEVICE);
 
                        rx_buf->skb = NULL;
@@ -6086,9 +6085,9 @@ static void bnx2x_netif_start(struct bnx2x *bp)
        }
 }
 
-static void bnx2x_netif_stop(struct bnx2x *bp)
+static void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw)
 {
-       bnx2x_int_disable_sync(bp);
+       bnx2x_int_disable_sync(bp, disable_hw);
        if (netif_running(bp->dev)) {
                bnx2x_napi_disable(bp);
                netif_tx_disable(bp->dev);
@@ -6475,11 +6474,12 @@ load_rings_free:
        for_each_queue(bp, i)
                bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
 load_int_disable:
-       bnx2x_int_disable_sync(bp);
+       bnx2x_int_disable_sync(bp, 1);
        /* Release IRQs */
        bnx2x_free_irq(bp);
 load_error:
        bnx2x_free_mem(bp);
+       bp->port.pmf = 0;
 
        /* TBD we really need to reset the chip
           if we want to recover from this */
@@ -6650,7 +6650,7 @@ static int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode)
        bp->rx_mode = BNX2X_RX_MODE_NONE;
        bnx2x_set_storm_rx_mode(bp);
 
-       bnx2x_netif_stop(bp);
+       bnx2x_netif_stop(bp, 1);
        if (!netif_running(bp->dev))
                bnx2x_napi_disable(bp);
        del_timer_sync(&bp->timer);
@@ -6790,6 +6790,7 @@ unload_error:
        /* Report UNLOAD_DONE to MCP */
        if (!BP_NOMCP(bp))
                bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
+       bp->port.pmf = 0;
 
        /* Free SKBs, SGEs, TPA pool and driver internals */
        bnx2x_free_skbs(bp);
@@ -8766,7 +8767,6 @@ static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode, u8 link_up)
        rc = 0;
 
 test_loopback_rx_exit:
-       bp->dev->last_rx = jiffies;
 
        fp->rx_bd_cons = NEXT_RX_IDX(fp->rx_bd_cons);
        fp->rx_bd_prod = NEXT_RX_IDX(fp->rx_bd_prod);
@@ -8791,7 +8791,7 @@ static int bnx2x_test_loopback(struct bnx2x *bp, u8 link_up)
        if (!netif_running(bp->dev))
                return BNX2X_LOOPBACK_FAILED;
 
-       bnx2x_netif_stop(bp);
+       bnx2x_netif_stop(bp, 1);
 
        if (bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK, link_up)) {
                DP(NETIF_MSG_PROBE, "MAC loopback failed\n");
@@ -9850,11 +9850,8 @@ static void bnx2x_set_rx_mode(struct net_device *dev)
                             mclist && (i < dev->mc_count);
                             i++, mclist = mclist->next) {
 
-                               DP(NETIF_MSG_IFUP, "Adding mcast MAC: "
-                                  "%02x:%02x:%02x:%02x:%02x:%02x\n",
-                                  mclist->dmi_addr[0], mclist->dmi_addr[1],
-                                  mclist->dmi_addr[2], mclist->dmi_addr[3],
-                                  mclist->dmi_addr[4], mclist->dmi_addr[5]);
+                               DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
+                                  mclist->dmi_addr);
 
                                crc = crc32c_le(0, mclist->dmi_addr, ETH_ALEN);
                                bit = (crc >> 24) & 0xff;
@@ -10089,8 +10086,7 @@ static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
 
        dev->irq = pdev->irq;
 
-       bp->regview = ioremap_nocache(dev->base_addr,
-                                     pci_resource_len(pdev, 0));
+       bp->regview = pci_ioremap_bar(pdev, 0);
        if (!bp->regview) {
                printk(KERN_ERR PFX "Cannot map register space, aborting\n");
                rc = -ENOMEM;
@@ -10191,7 +10187,6 @@ static int __devinit bnx2x_init_one(struct pci_dev *pdev,
        struct net_device *dev = NULL;
        struct bnx2x *bp;
        int rc;
-       DECLARE_MAC_BUF(mac);
 
        if (version_printed++ == 0)
                printk(KERN_INFO "%s", version);
@@ -10203,8 +10198,6 @@ static int __devinit bnx2x_init_one(struct pci_dev *pdev,
                return -ENOMEM;
        }
 
-       netif_carrier_off(dev);
-
        bp = netdev_priv(dev);
        bp->msglevel = debug;
 
@@ -10228,6 +10221,8 @@ static int __devinit bnx2x_init_one(struct pci_dev *pdev,
                goto init_one_exit;
        }
 
+       netif_carrier_off(dev);
+
        bp->common.name = board_info[ent->driver_data].name;
        printk(KERN_INFO "%s: %s (%c%d) PCI-E x%d %s found at mem %lx,"
               " IRQ %d, ", dev->name, bp->common.name,
@@ -10235,7 +10230,7 @@ static int __devinit bnx2x_init_one(struct pci_dev *pdev,
               bnx2x_get_pcie_width(bp),
               (bnx2x_get_pcie_speed(bp) == 2) ? "5GHz (Gen2)" : "2.5GHz",
               dev->base_addr, bp->pdev->irq);
-       printk(KERN_CONT "node addr %s\n", print_mac(mac, dev->dev_addr));
+       printk(KERN_CONT "node addr %pM\n", dev->dev_addr);
        return 0;
 
 init_one_exit:
@@ -10346,6 +10341,74 @@ static int bnx2x_resume(struct pci_dev *pdev)
        return rc;
 }
 
+static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
+{
+       int i;
+
+       bp->state = BNX2X_STATE_ERROR;
+
+       bp->rx_mode = BNX2X_RX_MODE_NONE;
+
+       bnx2x_netif_stop(bp, 0);
+
+       del_timer_sync(&bp->timer);
+       bp->stats_state = STATS_STATE_DISABLED;
+       DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
+
+       /* Release IRQs */
+       bnx2x_free_irq(bp);
+
+       if (CHIP_IS_E1(bp)) {
+               struct mac_configuration_cmd *config =
+                                               bnx2x_sp(bp, mcast_config);
+
+               for (i = 0; i < config->hdr.length_6b; i++)
+                       CAM_INVALIDATE(config->config_table[i]);
+       }
+
+       /* Free SKBs, SGEs, TPA pool and driver internals */
+       bnx2x_free_skbs(bp);
+       for_each_queue(bp, i)
+               bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
+       bnx2x_free_mem(bp);
+
+       bp->state = BNX2X_STATE_CLOSED;
+
+       netif_carrier_off(bp->dev);
+
+       return 0;
+}
+
+static void bnx2x_eeh_recover(struct bnx2x *bp)
+{
+       u32 val;
+
+       mutex_init(&bp->port.phy_mutex);
+
+       bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
+       bp->link_params.shmem_base = bp->common.shmem_base;
+       BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
+
+       if (!bp->common.shmem_base ||
+           (bp->common.shmem_base < 0xA0000) ||
+           (bp->common.shmem_base >= 0xC0000)) {
+               BNX2X_DEV_INFO("MCP not active\n");
+               bp->flags |= NO_MCP_FLAG;
+               return;
+       }
+
+       val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
+       if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
+               != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
+               BNX2X_ERR("BAD MCP validity signature\n");
+
+       if (!BP_NOMCP(bp)) {
+               bp->fw_seq = (SHMEM_RD(bp, func_mb[BP_FUNC(bp)].drv_mb_header)
+                             & DRV_MSG_SEQ_NUMBER_MASK);
+               BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
+       }
+}
+
 /**
  * bnx2x_io_error_detected - called when PCI error is detected
  * @pdev: Pointer to PCI device
@@ -10365,7 +10428,7 @@ static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
        netif_device_detach(dev);
 
        if (netif_running(dev))
-               bnx2x_nic_unload(bp, UNLOAD_CLOSE);
+               bnx2x_eeh_nic_unload(bp);
 
        pci_disable_device(pdev);
 
@@ -10420,8 +10483,10 @@ static void bnx2x_io_resume(struct pci_dev *pdev)
 
        rtnl_lock();
 
+       bnx2x_eeh_recover(bp);
+
        if (netif_running(dev))
-               bnx2x_nic_load(bp, LOAD_OPEN);
+               bnx2x_nic_load(bp, LOAD_NORMAL);
 
        netif_device_attach(dev);