]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/net/ethernet/broadcom/bnxt/bnxt.c
bnxt_en: Optimize ring alloc and ring free functions.
[karo-tx-linux.git] / drivers / net / ethernet / broadcom / bnxt / bnxt.c
index bdf094fb6ef92062d62d428109e277ba9e9d15f5..e340fb31ed78667f45b8b33069936053ddab8d0a 100644 (file)
@@ -1969,11 +1969,12 @@ static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr)
        rxr->rx_prod = prod;
        ring->fw_ring_id = INVALID_HW_RING_ID;
 
+       ring = &rxr->rx_agg_ring_struct;
+       ring->fw_ring_id = INVALID_HW_RING_ID;
+
        if (!(bp->flags & BNXT_FLAG_AGG_RINGS))
                return 0;
 
-       ring = &rxr->rx_agg_ring_struct;
-
        type = ((u32)PAGE_SIZE << RX_BD_LEN_SHIFT) |
                RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP;
 
@@ -1989,7 +1990,6 @@ static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr)
                prod = NEXT_RX_AGG(prod);
        }
        rxr->rx_agg_prod = prod;
-       ring->fw_ring_id = INVALID_HW_RING_ID;
 
        if (bp->flags & BNXT_FLAG_TPA) {
                if (rxr->rx_tpa) {
@@ -2693,17 +2693,16 @@ static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp)
        req.ver_upd = DRV_VER_UPD;
 
        if (BNXT_PF(bp)) {
-               unsigned long vf_req_snif_bmap[4];
+               DECLARE_BITMAP(vf_req_snif_bmap, 256);
                u32 *data = (u32 *)vf_req_snif_bmap;
 
-               memset(vf_req_snif_bmap, 0, 32);
+               memset(vf_req_snif_bmap, 0, sizeof(vf_req_snif_bmap));
                for (i = 0; i < ARRAY_SIZE(bnxt_vf_req_snif); i++)
                        __set_bit(bnxt_vf_req_snif[i], vf_req_snif_bmap);
 
-               for (i = 0; i < 8; i++) {
-                       req.vf_req_fwd[i] = cpu_to_le32(*data);
-                       data++;
-               }
+               for (i = 0; i < 8; i++)
+                       req.vf_req_fwd[i] = cpu_to_le32(data[i]);
+
                req.enables |=
                        cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD);
        }
@@ -2711,6 +2710,14 @@ static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp)
        return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
 }
 
+static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp)
+{
+       struct hwrm_func_drv_unrgtr_input req = {0};
+
+       bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_UNRGTR, -1, -1);
+       return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT);
+}
+
 static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, u8 tunnel_type)
 {
        u32 rc = 0;
@@ -3294,54 +3301,45 @@ static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
 {
        int i, rc = 0;
 
-       if (bp->cp_nr_rings) {
-               for (i = 0; i < bp->cp_nr_rings; i++) {
-                       struct bnxt_napi *bnapi = bp->bnapi[i];
-                       struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
-                       struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
+       for (i = 0; i < bp->cp_nr_rings; i++) {
+               struct bnxt_napi *bnapi = bp->bnapi[i];
+               struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
+               struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
 
-                       rc = hwrm_ring_alloc_send_msg(bp, ring,
-                                                     HWRM_RING_ALLOC_CMPL, i,
-                                                     INVALID_STATS_CTX_ID);
-                       if (rc)
-                               goto err_out;
-                       cpr->cp_doorbell = bp->bar1 + i * 0x80;
-                       BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
-                       bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id;
-               }
+               rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL, i,
+                                             INVALID_STATS_CTX_ID);
+               if (rc)
+                       goto err_out;
+               cpr->cp_doorbell = bp->bar1 + i * 0x80;
+               BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons);
+               bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id;
        }
 
-       if (bp->tx_nr_rings) {
-               for (i = 0; i < bp->tx_nr_rings; i++) {
-                       struct bnxt_napi *bnapi = bp->bnapi[i];
-                       struct bnxt_tx_ring_info *txr = &bnapi->tx_ring;
-                       struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
-                       u16 fw_stats_ctx = bp->grp_info[i].fw_stats_ctx;
+       for (i = 0; i < bp->tx_nr_rings; i++) {
+               struct bnxt_napi *bnapi = bp->bnapi[i];
+               struct bnxt_tx_ring_info *txr = &bnapi->tx_ring;
+               struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
+               u16 fw_stats_ctx = bp->grp_info[i].fw_stats_ctx;
 
-                       rc = hwrm_ring_alloc_send_msg(bp, ring,
-                                                     HWRM_RING_ALLOC_TX, i,
-                                                     fw_stats_ctx);
-                       if (rc)
-                               goto err_out;
-                       txr->tx_doorbell = bp->bar1 + i * 0x80;
-               }
+               rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX, i,
+                                             fw_stats_ctx);
+               if (rc)
+                       goto err_out;
+               txr->tx_doorbell = bp->bar1 + i * 0x80;
        }
 
-       if (bp->rx_nr_rings) {
-               for (i = 0; i < bp->rx_nr_rings; i++) {
-                       struct bnxt_napi *bnapi = bp->bnapi[i];
-                       struct bnxt_rx_ring_info *rxr = &bnapi->rx_ring;
-                       struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
+       for (i = 0; i < bp->rx_nr_rings; i++) {
+               struct bnxt_napi *bnapi = bp->bnapi[i];
+               struct bnxt_rx_ring_info *rxr = &bnapi->rx_ring;
+               struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
 
-                       rc = hwrm_ring_alloc_send_msg(bp, ring,
-                                                     HWRM_RING_ALLOC_RX, i,
-                                                     INVALID_STATS_CTX_ID);
-                       if (rc)
-                               goto err_out;
-                       rxr->rx_doorbell = bp->bar1 + i * 0x80;
-                       writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
-                       bp->grp_info[i].rx_fw_ring_id = ring->fw_ring_id;
-               }
+               rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX, i,
+                                             INVALID_STATS_CTX_ID);
+               if (rc)
+                       goto err_out;
+               rxr->rx_doorbell = bp->bar1 + i * 0x80;
+               writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell);
+               bp->grp_info[i].rx_fw_ring_id = ring->fw_ring_id;
        }
 
        if (bp->flags & BNXT_FLAG_AGG_RINGS) {
@@ -3409,91 +3407,73 @@ static int hwrm_ring_free_send_msg(struct bnxt *bp,
        return 0;
 }
 
-static int bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
+static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path)
 {
-       int i, rc = 0;
+       int i;
 
        if (!bp->bnapi)
-               return 0;
+               return;
 
-       if (bp->tx_nr_rings) {
-               for (i = 0; i < bp->tx_nr_rings; i++) {
-                       struct bnxt_napi *bnapi = bp->bnapi[i];
-                       struct bnxt_tx_ring_info *txr = &bnapi->tx_ring;
-                       struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
-                       u32 cmpl_ring_id = bp->grp_info[i].cp_fw_ring_id;
-
-                       if (ring->fw_ring_id != INVALID_HW_RING_ID) {
-                               hwrm_ring_free_send_msg(
-                                       bp, ring,
-                                       RING_FREE_REQ_RING_TYPE_TX,
-                                       close_path ? cmpl_ring_id :
-                                       INVALID_HW_RING_ID);
-                               ring->fw_ring_id = INVALID_HW_RING_ID;
-                       }
+       for (i = 0; i < bp->tx_nr_rings; i++) {
+               struct bnxt_napi *bnapi = bp->bnapi[i];
+               struct bnxt_tx_ring_info *txr = &bnapi->tx_ring;
+               struct bnxt_ring_struct *ring = &txr->tx_ring_struct;
+               u32 cmpl_ring_id = bp->grp_info[i].cp_fw_ring_id;
+
+               if (ring->fw_ring_id != INVALID_HW_RING_ID) {
+                       hwrm_ring_free_send_msg(bp, ring,
+                                               RING_FREE_REQ_RING_TYPE_TX,
+                                               close_path ? cmpl_ring_id :
+                                               INVALID_HW_RING_ID);
+                       ring->fw_ring_id = INVALID_HW_RING_ID;
                }
        }
 
-       if (bp->rx_nr_rings) {
-               for (i = 0; i < bp->rx_nr_rings; i++) {
-                       struct bnxt_napi *bnapi = bp->bnapi[i];
-                       struct bnxt_rx_ring_info *rxr = &bnapi->rx_ring;
-                       struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
-                       u32 cmpl_ring_id = bp->grp_info[i].cp_fw_ring_id;
-
-                       if (ring->fw_ring_id != INVALID_HW_RING_ID) {
-                               hwrm_ring_free_send_msg(
-                                       bp, ring,
-                                       RING_FREE_REQ_RING_TYPE_RX,
-                                       close_path ? cmpl_ring_id :
-                                       INVALID_HW_RING_ID);
-                               ring->fw_ring_id = INVALID_HW_RING_ID;
-                               bp->grp_info[i].rx_fw_ring_id =
-                                       INVALID_HW_RING_ID;
-                       }
+       for (i = 0; i < bp->rx_nr_rings; i++) {
+               struct bnxt_napi *bnapi = bp->bnapi[i];
+               struct bnxt_rx_ring_info *rxr = &bnapi->rx_ring;
+               struct bnxt_ring_struct *ring = &rxr->rx_ring_struct;
+               u32 cmpl_ring_id = bp->grp_info[i].cp_fw_ring_id;
+
+               if (ring->fw_ring_id != INVALID_HW_RING_ID) {
+                       hwrm_ring_free_send_msg(bp, ring,
+                                               RING_FREE_REQ_RING_TYPE_RX,
+                                               close_path ? cmpl_ring_id :
+                                               INVALID_HW_RING_ID);
+                       ring->fw_ring_id = INVALID_HW_RING_ID;
+                       bp->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID;
                }
        }
 
-       if (bp->rx_agg_nr_pages) {
-               for (i = 0; i < bp->rx_nr_rings; i++) {
-                       struct bnxt_napi *bnapi = bp->bnapi[i];
-                       struct bnxt_rx_ring_info *rxr = &bnapi->rx_ring;
-                       struct bnxt_ring_struct *ring =
-                                               &rxr->rx_agg_ring_struct;
-                       u32 cmpl_ring_id = bp->grp_info[i].cp_fw_ring_id;
-
-                       if (ring->fw_ring_id != INVALID_HW_RING_ID) {
-                               hwrm_ring_free_send_msg(
-                                       bp, ring,
-                                       RING_FREE_REQ_RING_TYPE_RX,
-                                       close_path ? cmpl_ring_id :
-                                       INVALID_HW_RING_ID);
-                               ring->fw_ring_id = INVALID_HW_RING_ID;
-                               bp->grp_info[i].agg_fw_ring_id =
-                                       INVALID_HW_RING_ID;
-                       }
+       for (i = 0; i < bp->rx_nr_rings; i++) {
+               struct bnxt_napi *bnapi = bp->bnapi[i];
+               struct bnxt_rx_ring_info *rxr = &bnapi->rx_ring;
+               struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct;
+               u32 cmpl_ring_id = bp->grp_info[i].cp_fw_ring_id;
+
+               if (ring->fw_ring_id != INVALID_HW_RING_ID) {
+                       hwrm_ring_free_send_msg(bp, ring,
+                                               RING_FREE_REQ_RING_TYPE_RX,
+                                               close_path ? cmpl_ring_id :
+                                               INVALID_HW_RING_ID);
+                       ring->fw_ring_id = INVALID_HW_RING_ID;
+                       bp->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID;
                }
        }
 
-       if (bp->cp_nr_rings) {
-               for (i = 0; i < bp->cp_nr_rings; i++) {
-                       struct bnxt_napi *bnapi = bp->bnapi[i];
-                       struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
-                       struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
-
-                       if (ring->fw_ring_id != INVALID_HW_RING_ID) {
-                               hwrm_ring_free_send_msg(
-                                       bp, ring,
-                                       RING_FREE_REQ_RING_TYPE_CMPL,
-                                       INVALID_HW_RING_ID);
-                               ring->fw_ring_id = INVALID_HW_RING_ID;
-                               bp->grp_info[i].cp_fw_ring_id =
-                                                       INVALID_HW_RING_ID;
-                       }
+       for (i = 0; i < bp->cp_nr_rings; i++) {
+               struct bnxt_napi *bnapi = bp->bnapi[i];
+               struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
+               struct bnxt_ring_struct *ring = &cpr->cp_ring_struct;
+
+               if (ring->fw_ring_id != INVALID_HW_RING_ID) {
+                       hwrm_ring_free_send_msg(bp, ring,
+                                               RING_FREE_REQ_RING_TYPE_CMPL,
+                                               INVALID_HW_RING_ID);
+                       ring->fw_ring_id = INVALID_HW_RING_ID;
+                       bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID;
                }
        }
-
-       return rc;
 }
 
 int bnxt_hwrm_set_coal(struct bnxt *bp)
@@ -4231,12 +4211,10 @@ static void bnxt_init_napi(struct bnxt *bp)
                        bnapi = bp->bnapi[i];
                        netif_napi_add(bp->dev, &bnapi->napi,
                                       bnxt_poll, 64);
-                       napi_hash_add(&bnapi->napi);
                }
        } else {
                bnapi = bp->bnapi[0];
                netif_napi_add(bp->dev, &bnapi->napi, bnxt_poll, 64);
-               napi_hash_add(&bnapi->napi);
        }
 }
 
@@ -4603,7 +4581,7 @@ static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
                        bp->nge_port_cnt = 1;
        }
 
-       bp->state = BNXT_STATE_OPEN;
+       set_bit(BNXT_STATE_OPEN, &bp->state);
        bnxt_enable_int(bp);
        /* Enable TX queues */
        bnxt_tx_enable(bp);
@@ -4679,8 +4657,10 @@ int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init)
        /* Change device state to avoid TX queue wake up's */
        bnxt_tx_disable(bp);
 
-       bp->state = BNXT_STATE_CLOSED;
-       cancel_work_sync(&bp->sp_task);
+       clear_bit(BNXT_STATE_OPEN, &bp->state);
+       smp_mb__after_atomic();
+       while (test_bit(BNXT_STATE_IN_SP_TASK, &bp->state))
+               msleep(20);
 
        /* Flush rings before disabling interrupts */
        bnxt_shutdown_nic(bp, irq_re_init);
@@ -5030,8 +5010,10 @@ static void bnxt_dbg_dump_states(struct bnxt *bp)
 static void bnxt_reset_task(struct bnxt *bp)
 {
        bnxt_dbg_dump_states(bp);
-       if (netif_running(bp->dev))
-               bnxt_tx_disable(bp); /* prevent tx timout again */
+       if (netif_running(bp->dev)) {
+               bnxt_close_nic(bp, false, false);
+               bnxt_open_nic(bp, false, false);
+       }
 }
 
 static void bnxt_tx_timeout(struct net_device *dev)
@@ -5081,8 +5063,12 @@ static void bnxt_sp_task(struct work_struct *work)
        struct bnxt *bp = container_of(work, struct bnxt, sp_task);
        int rc;
 
-       if (bp->state != BNXT_STATE_OPEN)
+       set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
+       smp_mb__after_atomic();
+       if (!test_bit(BNXT_STATE_OPEN, &bp->state)) {
+               clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
                return;
+       }
 
        if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event))
                bnxt_cfg_rx_mode(bp);
@@ -5106,8 +5092,19 @@ static void bnxt_sp_task(struct work_struct *work)
                bnxt_hwrm_tunnel_dst_port_free(
                        bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN);
        }
-       if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event))
+       if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event)) {
+               /* bnxt_reset_task() calls bnxt_close_nic() which waits
+                * for BNXT_STATE_IN_SP_TASK to clear.
+                */
+               clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
+               rtnl_lock();
                bnxt_reset_task(bp);
+               set_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
+               rtnl_unlock();
+       }
+
+       smp_mb__before_atomic();
+       clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state);
 }
 
 static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
@@ -5186,7 +5183,7 @@ static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev)
        bp->timer.function = bnxt_timer;
        bp->current_interval = BNXT_TIMER_INTERVAL;
 
-       bp->state = BNXT_STATE_CLOSED;
+       clear_bit(BNXT_STATE_OPEN, &bp->state);
 
        return 0;
 
@@ -5533,6 +5530,7 @@ static void bnxt_remove_one(struct pci_dev *pdev)
        cancel_work_sync(&bp->sp_task);
        bp->sp_event = 0;
 
+       bnxt_hwrm_func_drv_unrgtr(bp);
        bnxt_free_hwrm_resources(bp);
        pci_iounmap(pdev, bp->bar2);
        pci_iounmap(pdev, bp->bar1);