From: Lance Richardson Date: Sun, 2 Jun 2019 17:42:42 +0000 (-0400) Subject: net/bnxt: refactor doorbell handling X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=bb0546edfa6776b93b3011618dfc4f2af6a51f76;p=dpdk.git net/bnxt: refactor doorbell handling Reduce code duplication and prepare for newer controllers that use different doorbell protocols by refactoring doorbell handling code. Signed-off-by: Lance Richardson Reviewed-by: Ajit Khaparde --- diff --git a/drivers/net/bnxt/bnxt_cpr.h b/drivers/net/bnxt/bnxt_cpr.h index ee5ca820e6..77a22d2418 100644 --- a/drivers/net/bnxt/bnxt_cpr.h +++ b/drivers/net/bnxt/bnxt_cpr.h @@ -9,6 +9,8 @@ #include +struct bnxt_db_info; + #define CMP_VALID(cmp, raw_cons, ring) \ (!!(rte_le_to_cpu_32(((struct cmpl_base *)(cmp))->info3_v) & \ CMPL_BASE_V) == !((raw_cons) & ((ring)->ring_size))) @@ -40,37 +42,44 @@ #define B_CP_DB_REARM(cpr, raw_cons) \ rte_write32((DB_CP_REARM_FLAGS | \ RING_CMP(((cpr)->cp_ring_struct), raw_cons)), \ - ((cpr)->cp_doorbell)) + ((cpr)->cp_db.doorbell)) + +#define B_CP_DB_ARM(cpr) rte_write32((DB_KEY_CP), \ + ((cpr)->cp_db.doorbell)) -#define B_CP_DB_ARM(cpr) rte_write32((DB_KEY_CP), ((cpr)->cp_doorbell)) -#define B_CP_DB_DISARM(cpr) (*(uint32_t *)((cpr)->cp_doorbell) = \ +#define B_CP_DB_DISARM(cpr) (*(uint32_t *)((cpr)->cp_db.doorbell) = \ DB_KEY_CP | DB_IRQ_DIS) #define B_CP_DB_IDX_ARM(cpr, cons) \ - (*(uint32_t *)((cpr)->cp_doorbell) = (DB_CP_REARM_FLAGS | \ + (*(uint32_t *)((cpr)->cp_db.doorbell) = (DB_CP_REARM_FLAGS | \ (cons))) #define B_CP_DB_IDX_DISARM(cpr, cons) do { \ rte_smp_wmb(); \ - (*(uint32_t *)((cpr)->cp_doorbell) = (DB_CP_FLAGS | \ + (*(uint32_t *)((cpr)->cp_db.doorbell) = (DB_CP_FLAGS | \ (cons)); \ } while (0) #define B_CP_DIS_DB(cpr, raw_cons) \ rte_write32((DB_CP_FLAGS | \ RING_CMP(((cpr)->cp_ring_struct), raw_cons)), \ - ((cpr)->cp_doorbell)) + ((cpr)->cp_db.doorbell)) + #define B_CP_DB(cpr, raw_cons, ring_mask) \ rte_write32((DB_CP_FLAGS | \ RING_CMPL((ring_mask), raw_cons)), \ - ((cpr)->cp_doorbell)) + ((cpr)->cp_db.doorbell)) + +struct bnxt_db_info { + void *doorbell; + uint32_t db_key32; +}; struct bnxt_ring; struct bnxt_cp_ring_info { uint32_t cp_raw_cons; - void *cp_doorbell; struct cmpl_base *cp_desc_ring; - + struct bnxt_db_info cp_db; rte_iova_t cp_desc_mapping; struct ctx_hw_stats *hw_stats; diff --git a/drivers/net/bnxt/bnxt_irq.c b/drivers/net/bnxt/bnxt_irq.c index e03766b41f..918f3dcf48 100644 --- a/drivers/net/bnxt/bnxt_irq.c +++ b/drivers/net/bnxt/bnxt_irq.c @@ -71,7 +71,7 @@ void bnxt_disable_int(struct bnxt *bp) struct bnxt_cp_ring_info *cpr = bp->def_cp_ring; /* Only the default completion ring */ - if (cpr != NULL && cpr->cp_doorbell != NULL) + if (cpr != NULL && cpr->cp_db.doorbell != NULL) B_CP_DB_DISARM(cpr); } @@ -80,7 +80,7 @@ void bnxt_enable_int(struct bnxt *bp) struct bnxt_cp_ring_info *cpr = bp->def_cp_ring; /* Only the default completion ring */ - if (cpr != NULL && cpr->cp_doorbell != NULL) + if (cpr != NULL && cpr->cp_db.doorbell != NULL) B_CP_DB_ARM(cpr); } diff --git a/drivers/net/bnxt/bnxt_ring.c b/drivers/net/bnxt/bnxt_ring.c index 51fe35f3e5..15d4189778 100644 --- a/drivers/net/bnxt/bnxt_ring.c +++ b/drivers/net/bnxt/bnxt_ring.c @@ -276,31 +276,48 @@ static void bnxt_init_dflt_coal(struct bnxt_coal *coal) coal->cmpl_aggr_dma_tmr_during_int = BNXT_CMPL_AGGR_DMA_TMR_DURING_INT; } +static void bnxt_set_db(struct bnxt *bp, + struct bnxt_db_info *db, + uint32_t ring_type, + uint32_t map_idx) +{ + db->doorbell = (char *)bp->doorbell_base + map_idx * 0x80; + switch (ring_type) { + case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX: + db->db_key32 = DB_KEY_TX; + break; + case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX: + db->db_key32 = DB_KEY_RX; + break; + case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL: + db->db_key32 = DB_KEY_CP; + break; + } +} + int bnxt_alloc_hwrm_rx_ring(struct bnxt *bp, int queue_index) { - struct rte_pci_device *pci_dev = bp->pdev; struct bnxt_rx_queue *rxq = bp->rx_queues[queue_index]; struct bnxt_cp_ring_info *cpr = rxq->cp_ring; struct bnxt_ring *cp_ring = cpr->cp_ring_struct; struct bnxt_rx_ring_info *rxr = rxq->rx_ring; struct bnxt_ring *ring = rxr->rx_ring_struct; unsigned int map_idx = queue_index + bp->rx_cp_nr_rings; + uint8_t ring_type; int rc = 0; bp->grp_info[queue_index].fw_stats_ctx = cpr->hw_stats_ctx_id; /* Rx cmpl */ - rc = bnxt_hwrm_ring_alloc(bp, cp_ring, - HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL, - queue_index, HWRM_NA_SIGNATURE, - HWRM_NA_SIGNATURE); + ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL; + rc = bnxt_hwrm_ring_alloc(bp, cp_ring, ring_type, queue_index, + HWRM_NA_SIGNATURE, HWRM_NA_SIGNATURE); if (rc) goto err_out; - cpr->cp_doorbell = (char *)pci_dev->mem_resource[2].addr + - queue_index * BNXT_DB_SIZE; bp->grp_info[queue_index].cp_fw_ring_id = cp_ring->fw_ring_id; - B_CP_DIS_DB(cpr, cpr->cp_raw_cons); + bnxt_set_db(bp, &cpr->cp_db, ring_type, queue_index); + bnxt_db_cq(cpr); if (!queue_index) { /* @@ -314,35 +331,33 @@ int bnxt_alloc_hwrm_rx_ring(struct bnxt *bp, int queue_index) goto err_out; } /* Rx ring */ - rc = bnxt_hwrm_ring_alloc(bp, ring, HWRM_RING_ALLOC_INPUT_RING_TYPE_RX, - queue_index, cpr->hw_stats_ctx_id, - cp_ring->fw_ring_id); + ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX; + rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, queue_index, + cpr->hw_stats_ctx_id, cp_ring->fw_ring_id); if (rc) goto err_out; rxr->rx_prod = 0; - rxr->rx_doorbell = (char *)pci_dev->mem_resource[2].addr + - queue_index * BNXT_DB_SIZE; bp->grp_info[queue_index].rx_fw_ring_id = ring->fw_ring_id; - B_RX_DB(rxr->rx_doorbell, rxr->rx_prod); + bnxt_set_db(bp, &rxr->rx_db, ring_type, queue_index); + bnxt_db_write(&rxr->rx_db, rxr->rx_prod); - ring = rxr->ag_ring_struct; /* Agg ring */ + ring = rxr->ag_ring_struct; if (!ring) PMD_DRV_LOG(ERR, "Alloc AGG Ring is NULL!\n"); - rc = bnxt_hwrm_ring_alloc(bp, ring, HWRM_RING_ALLOC_INPUT_RING_TYPE_RX, - map_idx, HWRM_NA_SIGNATURE, - cp_ring->fw_ring_id); + ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX; + rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, map_idx, + HWRM_NA_SIGNATURE, cp_ring->fw_ring_id); if (rc) goto err_out; PMD_DRV_LOG(DEBUG, "Alloc AGG Done!\n"); rxr->ag_prod = 0; - rxr->ag_doorbell = (char *)pci_dev->mem_resource[2].addr + - map_idx * BNXT_DB_SIZE; bp->grp_info[queue_index].ag_fw_ring_id = ring->fw_ring_id; - B_RX_DB(rxr->ag_doorbell, rxr->ag_prod); + bnxt_set_db(bp, &rxr->ag_db, ring_type, map_idx); + bnxt_db_write(&rxr->ag_db, rxr->ag_prod); rxq->rx_buf_use_size = BNXT_MAX_MTU + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + (2 * VLAN_TAG_SIZE); @@ -356,8 +371,8 @@ int bnxt_alloc_hwrm_rx_ring(struct bnxt *bp, int queue_index) rc = -ENOMEM; goto err_out; } - B_RX_DB(rxr->rx_doorbell, rxr->rx_prod); - B_RX_DB(rxr->ag_doorbell, rxr->ag_prod); + bnxt_db_write(&rxr->rx_db, rxr->rx_prod); + bnxt_db_write(&rxr->ag_db, rxr->ag_prod); } rxq->index = queue_index; PMD_DRV_LOG(INFO, @@ -368,6 +383,7 @@ int bnxt_alloc_hwrm_rx_ring(struct bnxt *bp, int queue_index) err_out: return rc; } + /* ring_grp usage: * [0] = default completion ring * [1 -> +rx_cp_nr_rings] = rx_cp, rx rings @@ -377,6 +393,7 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp) { struct bnxt_coal coal; unsigned int i; + uint8_t ring_type; int rc = 0; bnxt_init_dflt_coal(&coal); @@ -392,18 +409,16 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp) bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id; /* Rx cmpl */ - rc = bnxt_hwrm_ring_alloc - (bp, - cp_ring, - HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL, - i, - HWRM_NA_SIGNATURE, - HWRM_NA_SIGNATURE); + ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL; + rc = bnxt_hwrm_ring_alloc(bp, cp_ring, ring_type, i, + HWRM_NA_SIGNATURE, + HWRM_NA_SIGNATURE); if (rc) goto err_out; - cpr->cp_doorbell = (char *)bp->doorbell_base + i * 0x80; bp->grp_info[i].cp_fw_ring_id = cp_ring->fw_ring_id; - B_CP_DIS_DB(cpr, cpr->cp_raw_cons); + bnxt_set_db(bp, &cpr->cp_db, ring_type, i); + bnxt_db_cq(cpr); + bnxt_hwrm_set_ring_coal(bp, &coal, cp_ring->fw_ring_id); if (!i) { @@ -420,37 +435,36 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp) } /* Rx ring */ - rc = bnxt_hwrm_ring_alloc(bp, - ring, - HWRM_RING_ALLOC_INPUT_RING_TYPE_RX, - i, + ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX; + rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, i, cpr->hw_stats_ctx_id, cp_ring->fw_ring_id); if (rc) goto err_out; rxr->rx_prod = 0; - rxr->rx_doorbell = (char *)bp->doorbell_base + i * 0x80; bp->grp_info[i].rx_fw_ring_id = ring->fw_ring_id; - B_RX_DB(rxr->rx_doorbell, rxr->rx_prod); + bnxt_set_db(bp, &rxr->rx_db, ring_type, i); + bnxt_db_write(&rxr->rx_db, rxr->rx_prod); - ring = rxr->ag_ring_struct; /* Agg ring */ + ring = rxr->ag_ring_struct; + if (ring == NULL) { PMD_DRV_LOG(ERR, "Alloc AGG Ring is NULL!\n"); goto err_out; } - rc = bnxt_hwrm_ring_alloc(bp, ring, - HWRM_RING_ALLOC_INPUT_RING_TYPE_RX, - map_idx, HWRM_NA_SIGNATURE, - cp_ring->fw_ring_id); + ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_RX; + rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, map_idx, + HWRM_NA_SIGNATURE, + cp_ring->fw_ring_id); if (rc) goto err_out; - PMD_DRV_LOG(DEBUG, "Alloc AGG Done!\n"); + rxr->ag_prod = 0; - rxr->ag_doorbell = (char *)bp->doorbell_base + map_idx * 0x80; bp->grp_info[i].ag_fw_ring_id = ring->fw_ring_id; - B_RX_DB(rxr->ag_doorbell, rxr->ag_prod); + bnxt_set_db(bp, &rxr->ag_db, ring_type, map_idx); + bnxt_db_write(&rxr->ag_db, rxr->ag_prod); rxq->rx_buf_use_size = BNXT_MAX_MTU + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + (2 * VLAN_TAG_SIZE); @@ -459,8 +473,8 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp) bnxt_rx_queue_release_op(rxq); return -ENOMEM; } - B_RX_DB(rxr->rx_doorbell, rxr->rx_prod); - B_RX_DB(rxr->ag_doorbell, rxr->ag_prod); + bnxt_db_write(&rxr->rx_db, rxr->rx_prod); + bnxt_db_write(&rxr->ag_db, rxr->ag_prod); rxq->index = i; } @@ -473,25 +487,25 @@ int bnxt_alloc_hwrm_rings(struct bnxt *bp) unsigned int idx = i + bp->rx_cp_nr_rings; /* Tx cmpl */ - rc = bnxt_hwrm_ring_alloc(bp, cp_ring, - HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL, - idx, HWRM_NA_SIGNATURE, - HWRM_NA_SIGNATURE); + ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL; + rc = bnxt_hwrm_ring_alloc(bp, cp_ring, ring_type, idx, + HWRM_NA_SIGNATURE, + HWRM_NA_SIGNATURE); if (rc) goto err_out; - cpr->cp_doorbell = (char *)bp->doorbell_base + idx * 0x80; - B_CP_DIS_DB(cpr, cpr->cp_raw_cons); + bnxt_set_db(bp, &cpr->cp_db, ring_type, idx); + bnxt_db_cq(cpr); /* Tx ring */ - rc = bnxt_hwrm_ring_alloc(bp, ring, - HWRM_RING_ALLOC_INPUT_RING_TYPE_TX, - idx, cpr->hw_stats_ctx_id, - cp_ring->fw_ring_id); + ring_type = HWRM_RING_ALLOC_INPUT_RING_TYPE_TX; + rc = bnxt_hwrm_ring_alloc(bp, ring, ring_type, idx, + cpr->hw_stats_ctx_id, + cp_ring->fw_ring_id); if (rc) goto err_out; - txr->tx_doorbell = (char *)bp->doorbell_base + idx * 0x80; + bnxt_set_db(bp, &txr->tx_db, ring_type, idx); txq->index = idx; bnxt_hwrm_set_ring_coal(bp, &coal, cp_ring->fw_ring_id); } diff --git a/drivers/net/bnxt/bnxt_ring.h b/drivers/net/bnxt/bnxt_ring.h index fd3d0bd73f..8cb0e8eb01 100644 --- a/drivers/net/bnxt/bnxt_ring.h +++ b/drivers/net/bnxt/bnxt_ring.h @@ -74,4 +74,15 @@ int bnxt_alloc_rings(struct bnxt *bp, uint16_t qidx, int bnxt_alloc_hwrm_rx_ring(struct bnxt *bp, int queue_index); int bnxt_alloc_hwrm_rings(struct bnxt *bp); +static inline void bnxt_db_write(struct bnxt_db_info *db, uint32_t idx) +{ + rte_write32(db->db_key32 | idx, db->doorbell); +} + +static inline void bnxt_db_cq(struct bnxt_cp_ring_info *cpr) +{ + rte_smp_wmb(); + B_CP_DIS_DB(cpr, cpr->cp_raw_cons); +} + #endif diff --git a/drivers/net/bnxt/bnxt_rxr.c b/drivers/net/bnxt/bnxt_rxr.c index 303549b5dc..75d2c76a51 100644 --- a/drivers/net/bnxt/bnxt_rxr.c +++ b/drivers/net/bnxt/bnxt_rxr.c @@ -552,7 +552,7 @@ uint16_t bnxt_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, break; /* Post some Rx buf early in case of larger burst processing */ if (nb_rx_pkts == BNXT_RX_POST_THRESH) - B_RX_DB(rxr->rx_doorbell, rxr->rx_prod); + bnxt_db_write(&rxr->rx_db, rxr->rx_prod); } cpr->cp_raw_cons = raw_cons; @@ -565,13 +565,13 @@ uint16_t bnxt_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, } if (prod != rxr->rx_prod) - B_RX_DB(rxr->rx_doorbell, rxr->rx_prod); + bnxt_db_write(&rxr->rx_db, rxr->rx_prod); /* Ring the AGG ring DB */ if (ag_prod != rxr->ag_prod) - B_RX_DB(rxr->ag_doorbell, rxr->ag_prod); + bnxt_db_write(&rxr->ag_db, rxr->ag_prod); - B_CP_DIS_DB(cpr, cpr->cp_raw_cons); + bnxt_db_cq(cpr); /* Attempt to alloc Rx buf in case of a previous allocation failure. */ if (rc == -ENOMEM) { @@ -588,7 +588,7 @@ uint16_t bnxt_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, /* This slot is empty. Alloc buffer for Rx */ if (!bnxt_alloc_rx_data(rxq, rxr, i)) { rxr->rx_prod = i; - B_RX_DB(rxr->rx_doorbell, rxr->rx_prod); + bnxt_db_write(&rxr->rx_db, rxr->rx_prod); } else { PMD_DRV_LOG(ERR, "Alloc mbuf failed\n"); break; diff --git a/drivers/net/bnxt/bnxt_rxr.h b/drivers/net/bnxt/bnxt_rxr.h index d10cefb938..6523b94c61 100644 --- a/drivers/net/bnxt/bnxt_rxr.h +++ b/drivers/net/bnxt/bnxt_rxr.h @@ -81,8 +81,8 @@ struct bnxt_sw_rx_bd { struct bnxt_rx_ring_info { uint16_t rx_prod; uint16_t ag_prod; - void *rx_doorbell; - void *ag_doorbell; + struct bnxt_db_info rx_db; + struct bnxt_db_info ag_db; struct rx_prod_pkt_bd *rx_desc_ring; struct rx_prod_pkt_bd *ag_desc_ring; diff --git a/drivers/net/bnxt/bnxt_rxtx_vec_sse.c b/drivers/net/bnxt/bnxt_rxtx_vec_sse.c index 1c32c986ce..c358506f82 100644 --- a/drivers/net/bnxt/bnxt_rxtx_vec_sse.c +++ b/drivers/net/bnxt/bnxt_rxtx_vec_sse.c @@ -92,7 +92,7 @@ bnxt_rxq_rearm(struct bnxt_rx_queue *rxq, struct bnxt_rx_ring_info *rxr) } rxq->rxrearm_start += RTE_BNXT_RXQ_REARM_THRESH; - B_RX_DB(rxr->rx_doorbell, rxq->rxrearm_start - 1); + bnxt_db_write(&rxr->rx_db, rxq->rxrearm_start - 1); if (rxq->rxrearm_start >= rxq->nb_rx_desc) rxq->rxrearm_start = 0; @@ -272,7 +272,7 @@ bnxt_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts, rxq->rxrearm_nb += nb_rx_pkts; cpr->cp_raw_cons = raw_cons; if (nb_rx_pkts || evt) - B_CP_DIS_DB(cpr, cpr->cp_raw_cons); + bnxt_db_cq(cpr); return nb_rx_pkts; } @@ -349,7 +349,7 @@ bnxt_handle_tx_cp_vec(struct bnxt_tx_queue *txq) if (nb_tx_pkts) { bnxt_tx_cmp_vec(txq, nb_tx_pkts); cpr->cp_raw_cons = raw_cons; - B_CP_DB(cpr, raw_cons, ring_mask); + bnxt_db_cq(cpr); } } @@ -420,7 +420,7 @@ bnxt_xmit_fixed_burst_vec(void *tx_queue, struct rte_mbuf **tx_pkts, } rte_compiler_barrier(); - B_TX_DB(txr->tx_doorbell, prod); + bnxt_db_write(&txr->tx_db, prod); txr->tx_prod = prod; diff --git a/drivers/net/bnxt/bnxt_txr.c b/drivers/net/bnxt/bnxt_txr.c index 5018c299a1..4bb177f7e0 100644 --- a/drivers/net/bnxt/bnxt_txr.c +++ b/drivers/net/bnxt/bnxt_txr.c @@ -415,7 +415,7 @@ static int bnxt_handle_tx_cp(struct bnxt_tx_queue *txq) if (nb_tx_pkts) { bnxt_tx_cmp(txq, nb_tx_pkts); cpr->cp_raw_cons = raw_cons; - B_CP_DB(cpr, cpr->cp_raw_cons, ring_mask); + bnxt_db_cq(cpr); } return nb_tx_pkts; @@ -452,7 +452,7 @@ uint16_t bnxt_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, if (likely(nb_tx_pkts)) { /* Request a completion on the last packet */ last_txbd->flags_type &= ~TX_BD_LONG_FLAGS_NO_CMPL; - B_TX_DB(txq->tx_ring->tx_doorbell, txq->tx_ring->tx_prod); + bnxt_db_write(&txq->tx_ring->tx_db, txq->tx_ring->tx_prod); } return nb_tx_pkts; diff --git a/drivers/net/bnxt/bnxt_txr.h b/drivers/net/bnxt/bnxt_txr.h index 58678a1c83..08fd2e0142 100644 --- a/drivers/net/bnxt/bnxt_txr.h +++ b/drivers/net/bnxt/bnxt_txr.h @@ -18,7 +18,7 @@ struct bnxt_tx_ring_info { uint16_t tx_prod; uint16_t tx_cons; - void *tx_doorbell; + struct bnxt_db_info tx_db; struct tx_bd_long *tx_desc_ring; struct bnxt_sw_tx_bd *tx_buf_ring;