net/bnx2x: fix fastpath SB allocation for SRIOV
[dpdk.git] / drivers / net / bnx2x / bnx2x.c
index f32db6d..1a08826 100644 (file)
@@ -2015,6 +2015,8 @@ bnx2x_nic_unload(struct bnx2x_softc *sc, uint32_t unload_mode, uint8_t keep_link
        uint8_t global = FALSE;
        uint32_t val;
 
+       PMD_INIT_FUNC_TRACE(sc);
+
        PMD_DRV_LOG(DEBUG, sc, "Starting NIC unload...");
 
        /* mark driver as unloaded in shmem2 */
@@ -2118,6 +2120,9 @@ bnx2x_nic_unload(struct bnx2x_softc *sc, uint32_t unload_mode, uint8_t keep_link
                bnx2x_free_mem(sc);
        }
 
+       /* free the host hardware/software hsi structures */
+       bnx2x_free_hsi_mem(sc);
+
        bnx2x_free_fw_stats_mem(sc);
 
        sc->state = BNX2X_STATE_CLOSED;
@@ -2197,8 +2202,8 @@ int bnx2x_tx_encap(struct bnx2x_tx_queue *txq, struct rte_mbuf *m0)
                        tx_start_bd->vlan_or_ethertype =
                            rte_cpu_to_le_16(pkt_prod);
                else {
-                       struct ether_hdr *eh =
-                           rte_pktmbuf_mtod(m0, struct ether_hdr *);
+                       struct rte_ether_hdr *eh =
+                           rte_pktmbuf_mtod(m0, struct rte_ether_hdr *);
 
                        tx_start_bd->vlan_or_ethertype =
                            rte_cpu_to_le_16(rte_be_to_cpu_16(eh->ether_type));
@@ -2208,14 +2213,14 @@ int bnx2x_tx_encap(struct bnx2x_tx_queue *txq, struct rte_mbuf *m0)
        bd_prod = NEXT_TX_BD(bd_prod);
        if (IS_VF(sc)) {
                struct eth_tx_parse_bd_e2 *tx_parse_bd;
-               const struct ether_hdr *eh =
-                   rte_pktmbuf_mtod(m0, struct ether_hdr *);
+               const struct rte_ether_hdr *eh =
+                   rte_pktmbuf_mtod(m0, struct rte_ether_hdr *);
                uint8_t mac_type = UNICAST_ADDRESS;
 
                tx_parse_bd =
                    &txq->tx_ring[TX_BD(bd_prod, txq)].parse_bd_e2;
-               if (is_multicast_ether_addr(&eh->d_addr)) {
-                       if (is_broadcast_ether_addr(&eh->d_addr))
+               if (rte_is_multicast_ether_addr(&eh->d_addr)) {
+                       if (rte_is_broadcast_ether_addr(&eh->d_addr))
                                mac_type = BROADCAST_ADDRESS;
                        else
                                mac_type = MULTICAST_ADDRESS;
@@ -4572,6 +4577,8 @@ static void bnx2x_handle_fp_tq(struct bnx2x_fastpath *fp)
                }
        }
 
+       /* Assuming we have completed slow path completion, clear the flag */
+       rte_atomic32_set(&sc->scan_fp, 0);
        bnx2x_ack_sb(sc, fp->igu_sb_id, USTORM_ID,
                   le16toh(fp->fp_hc_idx), IGU_INT_ENABLE, 1);
 }
@@ -7228,6 +7235,14 @@ int bnx2x_nic_load(struct bnx2x_softc *sc)
                }
        }
 
+       /* allocate the host hardware/software hsi structures */
+       if (bnx2x_alloc_hsi_mem(sc) != 0) {
+               PMD_DRV_LOG(ERR, sc, "bnx2x_alloc_hsi_mem was failed");
+               sc->state = BNX2X_STATE_CLOSED;
+               rc = -ENOMEM;
+               goto bnx2x_nic_load_error0;
+       }
+
        if (bnx2x_alloc_fw_stats_mem(sc) != 0) {
                sc->state = BNX2X_STATE_CLOSED;
                rc = -ENOMEM;
@@ -7443,6 +7458,7 @@ bnx2x_nic_load_error1:
 bnx2x_nic_load_error0:
 
        bnx2x_free_fw_stats_mem(sc);
+       bnx2x_free_hsi_mem(sc);
        bnx2x_free_mem(sc);
 
        return rc;
@@ -8103,6 +8119,27 @@ static int bnx2x_get_shmem_info(struct bnx2x_softc *sc)
                    ~ELINK_FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
        }
 
+       val = sc->devinfo.bc_ver >> 8;
+       if (val < BNX2X_BC_VER) {
+               /* for now only warn later we might need to enforce this */
+               PMD_DRV_LOG(NOTICE, sc, "This driver needs bc_ver %X but found %X, please upgrade BC\n",
+                           BNX2X_BC_VER, val);
+       }
+       sc->link_params.feature_config_flags |=
+                               (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
+                               ELINK_FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY :
+                               0;
+
+       sc->link_params.feature_config_flags |=
+               (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
+               ELINK_FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
+       sc->link_params.feature_config_flags |=
+               (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
+               ELINK_FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
+       sc->link_params.feature_config_flags |=
+               (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
+               ELINK_FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
+
        /* get the initial value of the link params */
        sc->link_params.multi_phy_config =
            SHMEM_RD(sc, dev_info.port_hw_config[port].multi_phy_config);
@@ -8867,9 +8904,9 @@ int bnx2x_alloc_hsi_mem(struct bnx2x_softc *sc)
        uint32_t i;
 
        if (IS_PF(sc)) {
-/************************/
-/* DEFAULT STATUS BLOCK */
-/************************/
+               /************************/
+               /* DEFAULT STATUS BLOCK */
+               /************************/
 
                if (bnx2x_dma_alloc(sc, sizeof(struct host_sp_status_block),
                                  &sc->def_sb_dma, "def_sb",
@@ -8879,9 +8916,9 @@ int bnx2x_alloc_hsi_mem(struct bnx2x_softc *sc)
 
                sc->def_sb =
                    (struct host_sp_status_block *)sc->def_sb_dma.vaddr;
-/***************/
-/* EVENT QUEUE */
-/***************/
+               /***************/
+               /* EVENT QUEUE */
+               /***************/
 
                if (bnx2x_dma_alloc(sc, BNX2X_PAGE_SIZE,
                                  &sc->eq_dma, "ev_queue",
@@ -8892,9 +8929,9 @@ int bnx2x_alloc_hsi_mem(struct bnx2x_softc *sc)
 
                sc->eq = (union event_ring_elem *)sc->eq_dma.vaddr;
 
-/*************/
-/* SLOW PATH */
-/*************/
+               /*************/
+               /* SLOW PATH */
+               /*************/
 
                if (bnx2x_dma_alloc(sc, sizeof(struct bnx2x_slowpath),
                                  &sc->sp_dma, "sp",
@@ -8906,9 +8943,9 @@ int bnx2x_alloc_hsi_mem(struct bnx2x_softc *sc)
 
                sc->sp = (struct bnx2x_slowpath *)sc->sp_dma.vaddr;
 
-/*******************/
-/* SLOW PATH QUEUE */
-/*******************/
+               /*******************/
+               /* SLOW PATH QUEUE */
+               /*******************/
 
                if (bnx2x_dma_alloc(sc, BNX2X_PAGE_SIZE,
                                  &sc->spq_dma, "sp_queue",
@@ -8921,9 +8958,9 @@ int bnx2x_alloc_hsi_mem(struct bnx2x_softc *sc)
 
                sc->spq = (struct eth_spe *)sc->spq_dma.vaddr;
 
-/***************************/
-/* FW DECOMPRESSION BUFFER */
-/***************************/
+               /***************************/
+               /* FW DECOMPRESSION BUFFER */
+               /***************************/
 
                if (bnx2x_dma_alloc(sc, FW_BUF_SIZE, &sc->gz_buf_dma,
                                  "fw_buf", RTE_CACHE_LINE_SIZE) != 0) {
@@ -8947,9 +8984,9 @@ int bnx2x_alloc_hsi_mem(struct bnx2x_softc *sc)
                fp->sc = sc;
                fp->index = i;
 
-/*******************/
-/* FP STATUS BLOCK */
-/*******************/
+               /*******************/
+               /* FP STATUS BLOCK */
+               /*******************/
 
                snprintf(buf, sizeof(buf), "fp_%d_sb", i);
                if (bnx2x_dma_alloc(sc, sizeof(union bnx2x_host_hc_status_block),
@@ -8980,43 +9017,50 @@ void bnx2x_free_hsi_mem(struct bnx2x_softc *sc)
        for (i = 0; i < sc->num_queues; i++) {
                fp = &sc->fp[i];
 
-/*******************/
-/* FP STATUS BLOCK */
-/*******************/
+               /*******************/
+               /* FP STATUS BLOCK */
+               /*******************/
 
                memset(&fp->status_block, 0, sizeof(fp->status_block));
+               bnx2x_dma_free(&fp->sb_dma);
        }
 
-       /***************************/
-       /* FW DECOMPRESSION BUFFER */
-       /***************************/
+       if (IS_PF(sc)) {
+               /***************************/
+               /* FW DECOMPRESSION BUFFER */
+               /***************************/
 
-       sc->gz_buf = NULL;
+               bnx2x_dma_free(&sc->gz_buf_dma);
+               sc->gz_buf = NULL;
 
-       /*******************/
-       /* SLOW PATH QUEUE */
-       /*******************/
+               /*******************/
+               /* SLOW PATH QUEUE */
+               /*******************/
 
-       sc->spq = NULL;
+               bnx2x_dma_free(&sc->spq_dma);
+               sc->spq = NULL;
 
-       /*************/
-       /* SLOW PATH */
-       /*************/
+               /*************/
+               /* SLOW PATH */
+               /*************/
 
-       sc->sp = NULL;
+               bnx2x_dma_free(&sc->sp_dma);
+               sc->sp = NULL;
 
-       /***************/
-       /* EVENT QUEUE */
-       /***************/
+               /***************/
+               /* EVENT QUEUE */
+               /***************/
 
-       sc->eq = NULL;
+               bnx2x_dma_free(&sc->eq_dma);
+               sc->eq = NULL;
 
-       /************************/
-       /* DEFAULT STATUS BLOCK */
-       /************************/
-
-       sc->def_sb = NULL;
+               /************************/
+               /* DEFAULT STATUS BLOCK */
+               /************************/
 
+               bnx2x_dma_free(&sc->def_sb_dma);
+               sc->def_sb = NULL;
+       }
 }
 
 /*
@@ -9766,13 +9810,13 @@ int bnx2x_attach(struct bnx2x_softc *sc)
                bnx2x_get_phy_info(sc);
        } else {
                /* Left mac of VF unfilled, PF should set it for VF */
-               memset(sc->link_params.mac_addr, 0, ETHER_ADDR_LEN);
+               memset(sc->link_params.mac_addr, 0, RTE_ETHER_ADDR_LEN);
        }
 
        sc->wol = 0;
 
        /* set the default MTU (changed via ifconfig) */
-       sc->mtu = ETHER_MTU;
+       sc->mtu = RTE_ETHER_MTU;
 
        bnx2x_set_modes_bitmap(sc);