From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-gw2-out.broadcom.com (mail-gw2-out.broadcom.com [216.31.210.63]) by dpdk.org (Postfix) with ESMTP id 2CAE89AE5 for ; Sat, 14 May 2016 00:50:37 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.24,615,1455004800"; d="scan'208";a="95337933" Received: from mail-irv-18.broadcom.com ([10.15.198.37]) by mail-gw2-out.broadcom.com with ESMTP; 13 May 2016 16:05:53 -0700 Received: from mail-irva-12.broadcom.com (mail-irva-12.broadcom.com [10.11.16.101]) by mail-irv-18.broadcom.com (Postfix) with ESMTP id B41ED82023 for ; Fri, 13 May 2016 15:50:36 -0700 (PDT) Received: from DPDK-C1.broadcom.com (dhcp-10-13-115-104.irv.broadcom.com [10.13.115.104]) by mail-irva-12.broadcom.com (Postfix) with ESMTP id 905D513DAC5 for ; Fri, 13 May 2016 15:47:05 -0700 (PDT) From: Stephen Hurd To: dev@dpdk.org Date: Fri, 13 May 2016 15:46:04 -0700 Message-Id: <1463179589-82681-15-git-send-email-stephen.hurd@broadcom.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1463179589-82681-1-git-send-email-stephen.hurd@broadcom.com> References: <1463179589-82681-1-git-send-email-stephen.hurd@broadcom.com> Subject: [dpdk-dev] [PATCH v2 15/40] bnxt: alloc/free ring information X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 May 2016 22:50:38 -0000 Perform allocation and free()ing of ring information structures for TX, RX, and completion rings. Signed-off-by: Stephen Hurd Reviewed-by: Ajit Kumar Khaparde --- drivers/net/bnxt/bnxt_cpr.c | 28 +++++++++++++++++++++++----- drivers/net/bnxt/bnxt_cpr.h | 2 +- drivers/net/bnxt/bnxt_rxq.c | 17 ++++++++++++----- drivers/net/bnxt/bnxt_rxr.c | 42 ++++++++++++++++++++++++++++++++++-------- drivers/net/bnxt/bnxt_rxr.h | 2 +- drivers/net/bnxt/bnxt_txq.c | 23 ++++++++++++++++------- drivers/net/bnxt/bnxt_txr.c | 43 ++++++++++++++++++++++++++++++++++--------- drivers/net/bnxt/bnxt_txr.h | 2 +- 8 files changed, 122 insertions(+), 37 deletions(-) diff --git a/drivers/net/bnxt/bnxt_cpr.c b/drivers/net/bnxt/bnxt_cpr.c index 34e45ef..27c557f 100644 --- a/drivers/net/bnxt/bnxt_cpr.c +++ b/drivers/net/bnxt/bnxt_cpr.c @@ -31,6 +31,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include + #include "bnxt.h" #include "bnxt_cpr.h" #include "bnxt_hwrm.h" @@ -120,21 +122,37 @@ reject: void bnxt_free_def_cp_ring(struct bnxt *bp) { struct bnxt_cp_ring_info *cpr = bp->def_cp_ring; - struct bnxt_ring_struct *ring = cpr->cp_ring_struct; - bnxt_free_ring(ring); + bnxt_free_ring(cpr->cp_ring_struct); + rte_free(cpr->cp_ring_struct); + rte_free(cpr); } /* For the default completion ring only */ -void bnxt_init_def_ring_struct(struct bnxt *bp) +int bnxt_init_def_ring_struct(struct bnxt *bp, unsigned int socket_id) { - struct bnxt_cp_ring_info *cpr = bp->def_cp_ring; - struct bnxt_ring_struct *ring = cpr->cp_ring_struct; + struct bnxt_cp_ring_info *cpr; + struct bnxt_ring_struct *ring; + cpr = rte_zmalloc_socket("bnxt_cp_ring", + sizeof(struct bnxt_cp_ring_info), + RTE_CACHE_LINE_SIZE, socket_id); + if (!cpr) + return -ENOMEM; + bp->def_cp_ring = cpr; + + ring = rte_zmalloc_socket("bnxt_cp_ring_struct", + sizeof(struct bnxt_ring_struct), + RTE_CACHE_LINE_SIZE, socket_id); + if (!ring) + return -ENOMEM; + cpr->cp_ring_struct = ring; ring->bd = (void *)cpr->cp_desc_ring; ring->bd_dma = cpr->cp_desc_mapping; ring->ring_size = rte_align32pow2(DEFAULT_CP_RING_SIZE); ring->ring_mask = ring->ring_size - 1; ring->vmem_size = 0; ring->vmem = NULL; + + return 0; } diff --git a/drivers/net/bnxt/bnxt_cpr.h b/drivers/net/bnxt/bnxt_cpr.h index f104281..3e25a75 100644 --- a/drivers/net/bnxt/bnxt_cpr.h +++ b/drivers/net/bnxt/bnxt_cpr.h @@ -79,7 +79,7 @@ struct bnxt_cp_ring_info { struct bnxt; void bnxt_free_def_cp_ring(struct bnxt *bp); -void bnxt_init_def_ring_struct(struct bnxt *bp); +int bnxt_init_def_ring_struct(struct bnxt *bp, unsigned int socket_id); void bnxt_handle_async_event(struct bnxt *bp, struct cmpl_base *cmp); void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmp); diff --git a/drivers/net/bnxt/bnxt_rxq.c b/drivers/net/bnxt/bnxt_rxq.c index 90a116b..2fe4de8 100644 --- a/drivers/net/bnxt/bnxt_rxq.c +++ b/drivers/net/bnxt/bnxt_rxq.c @@ -271,10 +271,12 @@ int bnxt_rx_queue_setup_op(struct rte_eth_dev *eth_dev, { struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private; struct bnxt_rx_queue *rxq; + int rc = 0; if (!nb_desc || nb_desc > MAX_RX_DESC_CNT) { RTE_LOG(ERR, PMD, "nb_desc %d is invalid", nb_desc); - return -EINVAL; + rc = -EINVAL; + goto out; } if (eth_dev->data->rx_queues) { @@ -286,14 +288,17 @@ int bnxt_rx_queue_setup_op(struct rte_eth_dev *eth_dev, RTE_CACHE_LINE_SIZE, socket_id); if (!rxq) { RTE_LOG(ERR, PMD, "bnxt_rx_queue allocation failed!"); - return -ENOMEM; + rc = -ENOMEM; + goto out; } rxq->bp = bp; rxq->mb_pool = mp; rxq->nb_rx_desc = nb_desc; rxq->rx_free_thresh = rx_conf->rx_free_thresh; - bnxt_init_rx_ring_struct(rxq); + rc = bnxt_init_rx_ring_struct(rxq, socket_id); + if (rc) + goto out; rxq->queue_id = queue_idx; rxq->port_id = eth_dev->data->port_id; @@ -306,8 +311,10 @@ int bnxt_rx_queue_setup_op(struct rte_eth_dev *eth_dev, "bnxt_rx_ring")) { RTE_LOG(ERR, PMD, "ring_dma_zone_reserve for rx_ring failed!"); bnxt_rx_queue_release_op(rxq); - return -ENOMEM; + rc = -ENOMEM; + goto out; } - return 0; +out: + return rc; } diff --git a/drivers/net/bnxt/bnxt_rxr.c b/drivers/net/bnxt/bnxt_rxr.c index eed88c6..5a6f2fe 100644 --- a/drivers/net/bnxt/bnxt_rxr.c +++ b/drivers/net/bnxt/bnxt_rxr.c @@ -252,17 +252,20 @@ void bnxt_free_rx_rings(struct bnxt *bp) if (!rxq) continue; - /* TODO: free() rxq->rx_ring and rxq->rx_ring->rx_ring_struct */ bnxt_free_ring(rxq->rx_ring->rx_ring_struct); - /* TODO: free() rxq->cp_ring and rxq->cp_ring->cp_ring_struct */ + rte_free(rxq->rx_ring->rx_ring_struct); + rte_free(rxq->rx_ring); + bnxt_free_ring(rxq->cp_ring->cp_ring_struct); + rte_free(rxq->cp_ring->cp_ring_struct); + rte_free(rxq->cp_ring); rte_free(rxq); bp->rx_queues[i] = NULL; } } -void bnxt_init_rx_ring_struct(struct bnxt_rx_queue *rxq) +int bnxt_init_rx_ring_struct(struct bnxt_rx_queue *rxq, unsigned int socket_id) { struct bnxt *bp = rxq->bp; struct bnxt_cp_ring_info *cpr; @@ -274,8 +277,19 @@ void bnxt_init_rx_ring_struct(struct bnxt_rx_queue *rxq) (2 * VLAN_TAG_SIZE); rxq->rx_buf_size = rxq->rx_buf_use_size + sizeof(struct rte_mbuf); - rxr = rxq->rx_ring; - ring = rxr->rx_ring_struct; + rxr = rte_zmalloc_socket("bnxt_rx_ring", + sizeof(struct bnxt_rx_ring_info), + RTE_CACHE_LINE_SIZE, socket_id); + if (!rxr) + return -ENOMEM; + rxq->rx_ring = rxr; + + ring = rte_zmalloc_socket("bnxt_rx_ring_struct", + sizeof(struct bnxt_ring_struct), + RTE_CACHE_LINE_SIZE, socket_id); + if (!ring) + return -ENOMEM; + rxr->rx_ring_struct = ring; ring->ring_size = rte_align32pow2(rxq->nb_rx_desc); ring->ring_mask = ring->ring_size - 1; ring->bd = (void *)rxr->rx_desc_ring; @@ -283,14 +297,27 @@ void bnxt_init_rx_ring_struct(struct bnxt_rx_queue *rxq) ring->vmem_size = ring->ring_size * sizeof(struct bnxt_sw_rx_bd); ring->vmem = (void **)&rxr->rx_buf_ring; - cpr = rxq->cp_ring; - ring = cpr->cp_ring_struct; + cpr = rte_zmalloc_socket("bnxt_rx_ring", + sizeof(struct bnxt_cp_ring_info), + RTE_CACHE_LINE_SIZE, socket_id); + if (!cpr) + return -ENOMEM; + rxq->cp_ring = cpr; + + ring = rte_zmalloc_socket("bnxt_rx_ring_struct", + sizeof(struct bnxt_ring_struct), + RTE_CACHE_LINE_SIZE, socket_id); + if (!ring) + return -ENOMEM; + cpr->cp_ring_struct = ring; ring->ring_size = rxr->rx_ring_struct->ring_size * 2; ring->ring_mask = ring->ring_size - 1; ring->bd = (void *)cpr->cp_desc_ring; ring->bd_dma = cpr->cp_desc_mapping; ring->vmem_size = 0; ring->vmem = NULL; + + return 0; } static void bnxt_init_rxbds(struct bnxt_ring_struct *ring, uint32_t type, @@ -317,7 +344,6 @@ int bnxt_init_one_rx_ring(struct bnxt_rx_queue *rxq) type = RX_PROD_PKT_BD_TYPE_RX_PROD_PKT | RX_PROD_PKT_BD_FLAGS_EOP_PAD; - /* TODO: These need to be allocated */ rxr = rxq->rx_ring; ring = rxr->rx_ring_struct; bnxt_init_rxbds(ring, type, rxq->rx_buf_use_size); diff --git a/drivers/net/bnxt/bnxt_rxr.h b/drivers/net/bnxt/bnxt_rxr.h index e9bae3f..7ba8f7b 100644 --- a/drivers/net/bnxt/bnxt_rxr.h +++ b/drivers/net/bnxt/bnxt_rxr.h @@ -56,7 +56,7 @@ struct bnxt_rx_ring_info { uint16_t bnxt_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts); void bnxt_free_rx_rings(struct bnxt *bp); -void bnxt_init_rx_ring_struct(struct bnxt_rx_queue *rxq); +int bnxt_init_rx_ring_struct(struct bnxt_rx_queue *rxq, unsigned int socket_id); int bnxt_init_one_rx_ring(struct bnxt_rx_queue *rxq); #endif diff --git a/drivers/net/bnxt/bnxt_txq.c b/drivers/net/bnxt/bnxt_txq.c index 7aba199..beda5fe 100644 --- a/drivers/net/bnxt/bnxt_txq.c +++ b/drivers/net/bnxt/bnxt_txq.c @@ -109,10 +109,12 @@ int bnxt_tx_queue_setup_op(struct rte_eth_dev *eth_dev, { struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private; struct bnxt_tx_queue *txq; + int rc = 0; if (!nb_desc || nb_desc > MAX_TX_DESC_CNT) { RTE_LOG(ERR, PMD, "nb_desc %d is invalid", nb_desc); - return -EINVAL; + rc = -EINVAL; + goto out; } if (eth_dev->data->tx_queues) { @@ -124,15 +126,18 @@ int bnxt_tx_queue_setup_op(struct rte_eth_dev *eth_dev, } txq = rte_zmalloc_socket("bnxt_tx_queue", sizeof(struct bnxt_tx_queue), RTE_CACHE_LINE_SIZE, socket_id); - if (txq == NULL) { + if (!txq) { RTE_LOG(ERR, PMD, "bnxt_tx_queue allocation failed!"); - return -ENOMEM; + rc = -ENOMEM; + goto out; } txq->bp = bp; txq->nb_tx_desc = nb_desc; txq->tx_free_thresh = tx_conf->tx_free_thresh; - bnxt_init_tx_ring_struct(txq); + rc = bnxt_init_tx_ring_struct(txq, socket_id); + if (rc) + goto out; txq->queue_id = queue_idx; txq->port_id = eth_dev->data->port_id; @@ -142,15 +147,19 @@ int bnxt_tx_queue_setup_op(struct rte_eth_dev *eth_dev, "bnxt_tx_ring")) { RTE_LOG(ERR, PMD, "ring_dma_zone_reserve for tx_ring failed!"); bnxt_tx_queue_release_op(txq); - return -ENOMEM; + rc = -ENOMEM; + goto out; } if (bnxt_init_one_tx_ring(txq)) { RTE_LOG(ERR, PMD, "bnxt_init_one_tx_ring failed!"); bnxt_tx_queue_release_op(txq); - return -ENOMEM; + rc = -ENOMEM; + goto out; } eth_dev->data->tx_queues[queue_idx] = txq; - return 0; + +out: + return rc; } diff --git a/drivers/net/bnxt/bnxt_txr.c b/drivers/net/bnxt/bnxt_txr.c index 2314410..218b945 100644 --- a/drivers/net/bnxt/bnxt_txr.c +++ b/drivers/net/bnxt/bnxt_txr.c @@ -59,9 +59,12 @@ void bnxt_free_tx_rings(struct bnxt *bp) continue; bnxt_free_ring(txq->tx_ring->tx_ring_struct); - /* TODO: free() txq->tx_ring and txq->tx_ring->tx_ring_struct */ + rte_free(txq->tx_ring->tx_ring_struct); + rte_free(txq->tx_ring); + bnxt_free_ring(txq->cp_ring->cp_ring_struct); - /* TODO: free() txq->cp_ring and txq->cp_ring->cp_ring_struct */ + rte_free(txq->cp_ring->cp_ring_struct); + rte_free(txq->cp_ring); rte_free(txq); bp->tx_queues[i] = NULL; @@ -79,15 +82,25 @@ int bnxt_init_one_tx_ring(struct bnxt_tx_queue *txq) return 0; } -void bnxt_init_tx_ring_struct(struct bnxt_tx_queue *txq) +int bnxt_init_tx_ring_struct(struct bnxt_tx_queue *txq, unsigned int socket_id) { struct bnxt_cp_ring_info *cpr; struct bnxt_tx_ring_info *txr; struct bnxt_ring_struct *ring; - /* TODO: These need to be allocated */ - txr = txq->tx_ring; - ring = txr->tx_ring_struct; + txr = rte_zmalloc_socket("bnxt_tx_ring", + sizeof(struct bnxt_tx_ring_info), + RTE_CACHE_LINE_SIZE, socket_id); + if (!txr) + return -ENOMEM; + txq->tx_ring = txr; + + ring = rte_zmalloc_socket("bnxt_tx_ring_struct", + sizeof(struct bnxt_ring_struct), + RTE_CACHE_LINE_SIZE, socket_id); + if (!ring) + return -ENOMEM; + txr->tx_ring_struct = ring; ring->ring_size = rte_align32pow2(txq->nb_tx_desc + 1); ring->ring_mask = ring->ring_size - 1; ring->bd = (void *)txr->tx_desc_ring; @@ -95,15 +108,27 @@ void bnxt_init_tx_ring_struct(struct bnxt_tx_queue *txq) ring->vmem_size = ring->ring_size * sizeof(struct bnxt_sw_tx_bd); ring->vmem = (void **)&txr->tx_buf_ring; - /* TODO: These need to be allocated */ - cpr = txq->cp_ring; - ring = cpr->cp_ring_struct; + cpr = rte_zmalloc_socket("bnxt_tx_ring", + sizeof(struct bnxt_cp_ring_info), + RTE_CACHE_LINE_SIZE, socket_id); + if (!cpr) + return -ENOMEM; + txq->cp_ring = cpr; + + ring = rte_zmalloc_socket("bnxt_tx_ring_struct", + sizeof(struct bnxt_ring_struct), + RTE_CACHE_LINE_SIZE, socket_id); + if (!ring) + return -ENOMEM; + cpr->cp_ring_struct = ring; ring->ring_size = txr->tx_ring_struct->ring_size; ring->ring_mask = ring->ring_size - 1; ring->bd = (void *)cpr->cp_desc_ring; ring->bd_dma = cpr->cp_desc_mapping; ring->vmem_size = 0; ring->vmem = NULL; + + return 0; } static inline uint32_t bnxt_tx_avail(struct bnxt_tx_ring_info *txr) diff --git a/drivers/net/bnxt/bnxt_txr.h b/drivers/net/bnxt/bnxt_txr.h index 1797a3d..56d0b08 100644 --- a/drivers/net/bnxt/bnxt_txr.h +++ b/drivers/net/bnxt/bnxt_txr.h @@ -64,7 +64,7 @@ struct bnxt_sw_tx_bd { void bnxt_free_tx_rings(struct bnxt *bp); int bnxt_init_one_tx_ring(struct bnxt_tx_queue *txq); -void bnxt_init_tx_ring_struct(struct bnxt_tx_queue *txq); +int bnxt_init_tx_ring_struct(struct bnxt_tx_queue *txq, unsigned int socket_id); uint16_t bnxt_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts); -- 1.9.1