[dpdk-dev] [PATCH v2 15/40] bnxt: alloc/free ring information

2016-05-26 Thread Bruce Richardson
On Fri, May 13, 2016 at 03:46:04PM -0700, Stephen Hurd wrote:
> Perform allocation and free()ing of ring information structures for
> TX, RX, and completion rings.
> 

A bit more detail would be useful here. What are the information structures and
how are they used? We've already had two previous patches each for RX and TX,
which add structures and allocs/frees, so how is this different from them.
Would it make sense to merge in this allocation with other allocation patches?
[Not saying it would, just asking :-)]

/Bruce



[dpdk-dev] [PATCH v2 15/40] bnxt: alloc/free ring information

2016-05-13 Thread Stephen Hurd
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