1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2014-2018 Broadcom
9 #include <rte_bitmap.h>
10 #include <rte_byteorder.h>
11 #include <rte_malloc.h>
12 #include <rte_memory.h>
16 #include "bnxt_ring.h"
19 #include "hsi_struct_def_dpdk.h"
25 static inline struct rte_mbuf *__bnxt_alloc_rx_data(struct rte_mempool *mb)
27 struct rte_mbuf *data;
29 data = rte_mbuf_raw_alloc(mb);
34 static inline int bnxt_alloc_rx_data(struct bnxt_rx_queue *rxq,
35 struct bnxt_rx_ring_info *rxr,
38 struct rx_prod_pkt_bd *rxbd = &rxr->rx_desc_ring[prod];
39 struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[prod];
40 struct rte_mbuf *mbuf;
42 mbuf = __bnxt_alloc_rx_data(rxq->mb_pool);
44 rte_atomic64_inc(&rxq->bp->rx_mbuf_alloc_fail);
50 rxbd->addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
55 static inline int bnxt_alloc_ag_data(struct bnxt_rx_queue *rxq,
56 struct bnxt_rx_ring_info *rxr,
59 struct rx_prod_pkt_bd *rxbd = &rxr->ag_desc_ring[prod];
60 struct bnxt_sw_rx_bd *rx_buf = &rxr->ag_buf_ring[prod];
61 struct rte_mbuf *mbuf;
63 mbuf = __bnxt_alloc_rx_data(rxq->mb_pool);
65 rte_atomic64_inc(&rxq->bp->rx_mbuf_alloc_fail);
70 PMD_DRV_LOG(ERR, "Jumbo Frame. rxbd is NULL\n");
72 PMD_DRV_LOG(ERR, "Jumbo Frame. rx_buf is NULL\n");
77 rxbd->addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
82 static inline void bnxt_reuse_rx_mbuf(struct bnxt_rx_ring_info *rxr,
83 struct rte_mbuf *mbuf)
85 uint16_t prod = RING_NEXT(rxr->rx_ring_struct, rxr->rx_prod);
86 struct bnxt_sw_rx_bd *prod_rx_buf;
87 struct rx_prod_pkt_bd *prod_bd;
89 prod_rx_buf = &rxr->rx_buf_ring[prod];
91 RTE_ASSERT(prod_rx_buf->mbuf == NULL);
92 RTE_ASSERT(mbuf != NULL);
94 prod_rx_buf->mbuf = mbuf;
96 prod_bd = &rxr->rx_desc_ring[prod];
98 prod_bd->addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
104 static void bnxt_reuse_ag_mbuf(struct bnxt_rx_ring_info *rxr, uint16_t cons,
105 struct rte_mbuf *mbuf)
107 uint16_t prod = rxr->ag_prod;
108 struct bnxt_sw_rx_bd *prod_rx_buf;
109 struct rx_prod_pkt_bd *prod_bd, *cons_bd;
111 prod_rx_buf = &rxr->ag_buf_ring[prod];
113 prod_rx_buf->mbuf = mbuf;
115 prod_bd = &rxr->ag_desc_ring[prod];
116 cons_bd = &rxr->ag_desc_ring[cons];
118 prod_bd->addr = cons_bd->addr;
123 struct rte_mbuf *bnxt_consume_rx_buf(struct bnxt_rx_ring_info *rxr,
126 struct bnxt_sw_rx_bd *cons_rx_buf;
127 struct rte_mbuf *mbuf;
129 cons_rx_buf = &rxr->rx_buf_ring[cons];
130 RTE_ASSERT(cons_rx_buf->mbuf != NULL);
131 mbuf = cons_rx_buf->mbuf;
132 cons_rx_buf->mbuf = NULL;
136 static void bnxt_tpa_start(struct bnxt_rx_queue *rxq,
137 struct rx_tpa_start_cmpl *tpa_start,
138 struct rx_tpa_start_cmpl_hi *tpa_start1)
140 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
141 uint8_t agg_id = rte_le_to_cpu_32(tpa_start->agg_id &
142 RX_TPA_START_CMPL_AGG_ID_MASK) >> RX_TPA_START_CMPL_AGG_ID_SFT;
144 struct bnxt_tpa_info *tpa_info;
145 struct rte_mbuf *mbuf;
147 data_cons = tpa_start->opaque;
148 tpa_info = &rxr->tpa_info[agg_id];
150 mbuf = bnxt_consume_rx_buf(rxr, data_cons);
152 bnxt_reuse_rx_mbuf(rxr, tpa_info->mbuf);
154 tpa_info->mbuf = mbuf;
155 tpa_info->len = rte_le_to_cpu_32(tpa_start->len);
159 mbuf->pkt_len = rte_le_to_cpu_32(tpa_start->len);
160 mbuf->data_len = mbuf->pkt_len;
161 mbuf->port = rxq->port_id;
162 mbuf->ol_flags = PKT_RX_LRO;
163 if (likely(tpa_start->flags_type &
164 rte_cpu_to_le_32(RX_TPA_START_CMPL_FLAGS_RSS_VALID))) {
165 mbuf->hash.rss = rte_le_to_cpu_32(tpa_start->rss_hash);
166 mbuf->ol_flags |= PKT_RX_RSS_HASH;
168 mbuf->hash.fdir.id = rte_le_to_cpu_16(tpa_start1->cfa_code);
169 mbuf->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
171 if (tpa_start1->flags2 &
172 rte_cpu_to_le_32(RX_TPA_START_CMPL_FLAGS2_META_FORMAT_VLAN)) {
173 mbuf->vlan_tci = rte_le_to_cpu_32(tpa_start1->metadata);
174 mbuf->ol_flags |= PKT_RX_VLAN;
176 if (likely(tpa_start1->flags2 &
177 rte_cpu_to_le_32(RX_TPA_START_CMPL_FLAGS2_L4_CS_CALC)))
178 mbuf->ol_flags |= PKT_RX_L4_CKSUM_GOOD;
180 /* recycle next mbuf */
181 data_cons = RING_NEXT(rxr->rx_ring_struct, data_cons);
182 bnxt_reuse_rx_mbuf(rxr, bnxt_consume_rx_buf(rxr, data_cons));
185 static int bnxt_agg_bufs_valid(struct bnxt_cp_ring_info *cpr,
186 uint8_t agg_bufs, uint32_t raw_cp_cons)
188 uint16_t last_cp_cons;
189 struct rx_pkt_cmpl *agg_cmpl;
191 raw_cp_cons = ADV_RAW_CMP(raw_cp_cons, agg_bufs);
192 last_cp_cons = RING_CMP(cpr->cp_ring_struct, raw_cp_cons);
193 agg_cmpl = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[last_cp_cons];
194 cpr->valid = FLIP_VALID(raw_cp_cons,
195 cpr->cp_ring_struct->ring_mask,
197 return CMP_VALID(agg_cmpl, raw_cp_cons, cpr->cp_ring_struct);
200 /* TPA consume agg buffer out of order, allocate connected data only */
201 static int bnxt_prod_ag_mbuf(struct bnxt_rx_queue *rxq)
203 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
204 uint16_t next = RING_NEXT(rxr->ag_ring_struct, rxr->ag_prod);
206 /* TODO batch allocation for better performance */
207 while (rte_bitmap_get(rxr->ag_bitmap, next)) {
208 if (unlikely(bnxt_alloc_ag_data(rxq, rxr, next))) {
210 "agg mbuf alloc failed: prod=0x%x\n", next);
213 rte_bitmap_clear(rxr->ag_bitmap, next);
215 next = RING_NEXT(rxr->ag_ring_struct, next);
221 static int bnxt_rx_pages(struct bnxt_rx_queue *rxq,
222 struct rte_mbuf *mbuf, uint32_t *tmp_raw_cons,
225 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
226 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
228 uint16_t cp_cons, ag_cons;
229 struct rx_pkt_cmpl *rxcmp;
230 struct rte_mbuf *last = mbuf;
232 for (i = 0; i < agg_buf; i++) {
233 struct bnxt_sw_rx_bd *ag_buf;
234 struct rte_mbuf *ag_mbuf;
235 *tmp_raw_cons = NEXT_RAW_CMP(*tmp_raw_cons);
236 cp_cons = RING_CMP(cpr->cp_ring_struct, *tmp_raw_cons);
237 rxcmp = (struct rx_pkt_cmpl *)
238 &cpr->cp_desc_ring[cp_cons];
241 bnxt_dump_cmpl(cp_cons, rxcmp);
244 ag_cons = rxcmp->opaque;
245 RTE_ASSERT(ag_cons <= rxr->ag_ring_struct->ring_mask);
246 ag_buf = &rxr->ag_buf_ring[ag_cons];
247 ag_mbuf = ag_buf->mbuf;
248 RTE_ASSERT(ag_mbuf != NULL);
250 ag_mbuf->data_len = rte_le_to_cpu_16(rxcmp->len);
253 mbuf->pkt_len += ag_mbuf->data_len;
255 last->next = ag_mbuf;
261 * As aggregation buffer consumed out of order in TPA module,
262 * use bitmap to track freed slots to be allocated and notified
265 rte_bitmap_set(rxr->ag_bitmap, ag_cons);
267 bnxt_prod_ag_mbuf(rxq);
271 static inline struct rte_mbuf *bnxt_tpa_end(
272 struct bnxt_rx_queue *rxq,
273 uint32_t *raw_cp_cons,
274 struct rx_tpa_end_cmpl *tpa_end,
275 struct rx_tpa_end_cmpl_hi *tpa_end1 __rte_unused)
277 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
278 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
279 uint8_t agg_id = (tpa_end->agg_id & RX_TPA_END_CMPL_AGG_ID_MASK)
280 >> RX_TPA_END_CMPL_AGG_ID_SFT;
281 struct rte_mbuf *mbuf;
283 struct bnxt_tpa_info *tpa_info;
285 tpa_info = &rxr->tpa_info[agg_id];
286 mbuf = tpa_info->mbuf;
287 RTE_ASSERT(mbuf != NULL);
290 agg_bufs = (rte_le_to_cpu_32(tpa_end->agg_bufs_v1) &
291 RX_TPA_END_CMPL_AGG_BUFS_MASK) >> RX_TPA_END_CMPL_AGG_BUFS_SFT;
293 if (!bnxt_agg_bufs_valid(cpr, agg_bufs, *raw_cp_cons))
295 bnxt_rx_pages(rxq, mbuf, raw_cp_cons, agg_bufs);
297 mbuf->l4_len = tpa_end->payload_offset;
299 struct rte_mbuf *new_data = __bnxt_alloc_rx_data(rxq->mb_pool);
300 RTE_ASSERT(new_data != NULL);
302 rte_atomic64_inc(&rxq->bp->rx_mbuf_alloc_fail);
305 tpa_info->mbuf = new_data;
311 bnxt_parse_pkt_type(struct rx_pkt_cmpl *rxcmp, struct rx_pkt_cmpl_hi *rxcmp1)
313 uint32_t l3, pkt_type = 0;
314 uint32_t t_ipcs = 0, ip6 = 0, vlan = 0;
317 vlan = !!(rxcmp1->flags2 &
318 rte_cpu_to_le_32(RX_PKT_CMPL_FLAGS2_META_FORMAT_VLAN));
319 pkt_type |= vlan ? RTE_PTYPE_L2_ETHER_VLAN : RTE_PTYPE_L2_ETHER;
321 t_ipcs = !!(rxcmp1->flags2 &
322 rte_cpu_to_le_32(RX_PKT_CMPL_FLAGS2_T_IP_CS_CALC));
323 ip6 = !!(rxcmp1->flags2 &
324 rte_cpu_to_le_32(RX_PKT_CMPL_FLAGS2_IP_TYPE));
326 flags_type = rxcmp->flags_type &
327 rte_cpu_to_le_32(RX_PKT_CMPL_FLAGS_ITYPE_MASK);
330 l3 = RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
331 else if (!t_ipcs && ip6)
332 l3 = RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
333 else if (t_ipcs && !ip6)
334 l3 = RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
336 l3 = RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
338 switch (flags_type) {
339 case RTE_LE32(RX_PKT_CMPL_FLAGS_ITYPE_ICMP):
341 pkt_type |= l3 | RTE_PTYPE_L4_ICMP;
343 pkt_type |= l3 | RTE_PTYPE_INNER_L4_ICMP;
346 case RTE_LE32(RX_PKT_CMPL_FLAGS_ITYPE_TCP):
348 pkt_type |= l3 | RTE_PTYPE_L4_TCP;
350 pkt_type |= l3 | RTE_PTYPE_INNER_L4_TCP;
353 case RTE_LE32(RX_PKT_CMPL_FLAGS_ITYPE_UDP):
355 pkt_type |= l3 | RTE_PTYPE_L4_UDP;
357 pkt_type |= l3 | RTE_PTYPE_INNER_L4_UDP;
360 case RTE_LE32(RX_PKT_CMPL_FLAGS_ITYPE_IP):
368 static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt,
369 struct bnxt_rx_queue *rxq, uint32_t *raw_cons)
371 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
372 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
373 struct rx_pkt_cmpl *rxcmp;
374 struct rx_pkt_cmpl_hi *rxcmp1;
375 uint32_t tmp_raw_cons = *raw_cons;
376 uint16_t cons, prod, cp_cons =
377 RING_CMP(cpr->cp_ring_struct, tmp_raw_cons);
381 struct rte_mbuf *mbuf;
386 rxcmp = (struct rx_pkt_cmpl *)
387 &cpr->cp_desc_ring[cp_cons];
389 tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons);
390 cp_cons = RING_CMP(cpr->cp_ring_struct, tmp_raw_cons);
391 rxcmp1 = (struct rx_pkt_cmpl_hi *)&cpr->cp_desc_ring[cp_cons];
393 if (!CMP_VALID(rxcmp1, tmp_raw_cons, cpr->cp_ring_struct))
396 cpr->valid = FLIP_VALID(cp_cons,
397 cpr->cp_ring_struct->ring_mask,
400 cmp_type = CMP_TYPE(rxcmp);
401 if (cmp_type == RX_TPA_START_CMPL_TYPE_RX_TPA_START) {
402 bnxt_tpa_start(rxq, (struct rx_tpa_start_cmpl *)rxcmp,
403 (struct rx_tpa_start_cmpl_hi *)rxcmp1);
404 rc = -EINVAL; /* Continue w/o new mbuf */
406 } else if (cmp_type == RX_TPA_END_CMPL_TYPE_RX_TPA_END) {
407 mbuf = bnxt_tpa_end(rxq, &tmp_raw_cons,
408 (struct rx_tpa_end_cmpl *)rxcmp,
409 (struct rx_tpa_end_cmpl_hi *)rxcmp1);
414 } else if (cmp_type != 0x11) {
419 agg_buf = (rxcmp->agg_bufs_v1 & RX_PKT_CMPL_AGG_BUFS_MASK)
420 >> RX_PKT_CMPL_AGG_BUFS_SFT;
421 if (agg_buf && !bnxt_agg_bufs_valid(cpr, agg_buf, tmp_raw_cons))
426 cons = rxcmp->opaque;
427 mbuf = bnxt_consume_rx_buf(rxr, cons);
433 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
436 mbuf->pkt_len = rxcmp->len;
437 mbuf->data_len = mbuf->pkt_len;
438 mbuf->port = rxq->port_id;
440 if (rxcmp->flags_type & RX_PKT_CMPL_FLAGS_RSS_VALID) {
441 mbuf->hash.rss = rxcmp->rss_hash;
442 mbuf->ol_flags |= PKT_RX_RSS_HASH;
444 mbuf->hash.fdir.id = rxcmp1->cfa_code;
445 mbuf->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
448 if ((rxcmp->flags_type & rte_cpu_to_le_16(RX_PKT_CMPL_FLAGS_MASK)) ==
449 RX_PKT_CMPL_FLAGS_ITYPE_PTP_W_TIMESTAMP)
450 mbuf->ol_flags |= PKT_RX_IEEE1588_PTP | PKT_RX_IEEE1588_TMST;
453 bnxt_rx_pages(rxq, mbuf, &tmp_raw_cons, agg_buf);
455 if (rxcmp1->flags2 & RX_PKT_CMPL_FLAGS2_META_FORMAT_VLAN) {
456 mbuf->vlan_tci = rxcmp1->metadata &
457 (RX_PKT_CMPL_METADATA_VID_MASK |
458 RX_PKT_CMPL_METADATA_DE |
459 RX_PKT_CMPL_METADATA_PRI_MASK);
460 mbuf->ol_flags |= PKT_RX_VLAN;
463 if (likely(RX_CMP_IP_CS_OK(rxcmp1)))
464 mbuf->ol_flags |= PKT_RX_IP_CKSUM_GOOD;
466 mbuf->ol_flags |= PKT_RX_IP_CKSUM_BAD;
468 if (likely(RX_CMP_L4_CS_OK(rxcmp1)))
469 mbuf->ol_flags |= PKT_RX_L4_CKSUM_GOOD;
471 mbuf->ol_flags |= PKT_RX_L4_CKSUM_BAD;
473 mbuf->packet_type = bnxt_parse_pkt_type(rxcmp, rxcmp1);
476 if (rxcmp1->errors_v2 & RX_CMP_L2_ERRORS) {
477 /* Re-install the mbuf back to the rx ring */
478 bnxt_reuse_rx_mbuf(rxr, cons, mbuf);
480 bnxt_reuse_ag_mbuf(rxr, ag_cons, mbuf);
487 * TODO: Redesign this....
488 * If the allocation fails, the packet does not get received.
489 * Simply returning this will result in slowly falling behind
490 * on the producer ring buffers.
491 * Instead, "filling up" the producer just before ringing the
492 * doorbell could be a better solution since it will let the
493 * producer ring starve until memory is available again pushing
494 * the drops into hardware and getting them out of the driver
495 * allowing recovery to a full producer ring.
497 * This could also help with cache usage by preventing per-packet
498 * calls in favour of a tight loop with the same function being called
501 prod = RING_NEXT(rxr->rx_ring_struct, prod);
502 if (bnxt_alloc_rx_data(rxq, rxr, prod)) {
503 PMD_DRV_LOG(ERR, "mbuf alloc failed with prod=0x%x\n", prod);
509 * All MBUFs are allocated with the same size under DPDK,
510 * no optimization for rx_copy_thresh
517 *raw_cons = tmp_raw_cons;
522 uint16_t bnxt_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
525 struct bnxt_rx_queue *rxq = rx_queue;
526 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
527 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
528 uint32_t raw_cons = cpr->cp_raw_cons;
531 struct rx_pkt_cmpl *rxcmp;
532 uint16_t prod = rxr->rx_prod;
533 uint16_t ag_prod = rxr->ag_prod;
536 /* If Rx Q was stopped return */
537 if (rxq->rx_deferred_start)
540 /* Handle RX burst request */
542 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
543 rte_prefetch0(&cpr->cp_desc_ring[cons]);
544 rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
546 if (!CMP_VALID(rxcmp, raw_cons, cpr->cp_ring_struct))
548 cpr->valid = FLIP_VALID(cons,
549 cpr->cp_ring_struct->ring_mask,
552 /* TODO: Avoid magic numbers... */
553 if ((CMP_TYPE(rxcmp) & 0x30) == 0x10) {
554 rc = bnxt_rx_pkt(&rx_pkts[nb_rx_pkts], rxq, &raw_cons);
555 if (likely(!rc) || rc == -ENOMEM)
557 if (rc == -EBUSY) /* partial completion */
560 raw_cons = NEXT_RAW_CMP(raw_cons);
561 if (nb_rx_pkts == nb_pkts)
565 cpr->cp_raw_cons = raw_cons;
566 if (prod == rxr->rx_prod && ag_prod == rxr->ag_prod) {
568 * For PMD, there is no need to keep on pushing to REARM
569 * the doorbell if there are no new completions
574 B_CP_DIS_DB(cpr, cpr->cp_raw_cons);
575 B_RX_DB(rxr->rx_doorbell, rxr->rx_prod);
576 /* Ring the AGG ring DB */
577 B_RX_DB(rxr->ag_doorbell, rxr->ag_prod);
579 /* Attempt to alloc Rx buf in case of a previous allocation failure. */
583 for (i = prod; i <= nb_rx_pkts;
584 i = RING_NEXT(rxr->rx_ring_struct, i)) {
585 struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[i];
587 /* Buffer already allocated for this index. */
588 if (rx_buf->mbuf != NULL)
591 /* This slot is empty. Alloc buffer for Rx */
592 if (!bnxt_alloc_rx_data(rxq, rxr, i)) {
594 B_RX_DB(rxr->rx_doorbell, rxr->rx_prod);
596 PMD_DRV_LOG(ERR, "Alloc mbuf failed\n");
605 void bnxt_free_rx_rings(struct bnxt *bp)
609 for (i = 0; i < (int)bp->rx_nr_rings; i++) {
610 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
615 bnxt_free_ring(rxq->rx_ring->rx_ring_struct);
616 rte_free(rxq->rx_ring->rx_ring_struct);
618 /* Free the Aggregator ring */
619 bnxt_free_ring(rxq->rx_ring->ag_ring_struct);
620 rte_free(rxq->rx_ring->ag_ring_struct);
621 rxq->rx_ring->ag_ring_struct = NULL;
623 rte_free(rxq->rx_ring);
625 bnxt_free_ring(rxq->cp_ring->cp_ring_struct);
626 rte_free(rxq->cp_ring->cp_ring_struct);
627 rte_free(rxq->cp_ring);
630 bp->rx_queues[i] = NULL;
634 int bnxt_init_rx_ring_struct(struct bnxt_rx_queue *rxq, unsigned int socket_id)
636 struct bnxt_cp_ring_info *cpr;
637 struct bnxt_rx_ring_info *rxr;
638 struct bnxt_ring *ring;
640 rxq->rx_buf_use_size = BNXT_MAX_MTU + ETHER_HDR_LEN + ETHER_CRC_LEN +
642 rxq->rx_buf_size = rxq->rx_buf_use_size + sizeof(struct rte_mbuf);
644 rxr = rte_zmalloc_socket("bnxt_rx_ring",
645 sizeof(struct bnxt_rx_ring_info),
646 RTE_CACHE_LINE_SIZE, socket_id);
651 ring = rte_zmalloc_socket("bnxt_rx_ring_struct",
652 sizeof(struct bnxt_ring),
653 RTE_CACHE_LINE_SIZE, socket_id);
656 rxr->rx_ring_struct = ring;
657 ring->ring_size = rte_align32pow2(rxq->nb_rx_desc);
658 ring->ring_mask = ring->ring_size - 1;
659 ring->bd = (void *)rxr->rx_desc_ring;
660 ring->bd_dma = rxr->rx_desc_mapping;
661 ring->vmem_size = ring->ring_size * sizeof(struct bnxt_sw_rx_bd);
662 ring->vmem = (void **)&rxr->rx_buf_ring;
664 cpr = rte_zmalloc_socket("bnxt_rx_ring",
665 sizeof(struct bnxt_cp_ring_info),
666 RTE_CACHE_LINE_SIZE, socket_id);
671 ring = rte_zmalloc_socket("bnxt_rx_ring_struct",
672 sizeof(struct bnxt_ring),
673 RTE_CACHE_LINE_SIZE, socket_id);
676 cpr->cp_ring_struct = ring;
677 ring->ring_size = rte_align32pow2(rxr->rx_ring_struct->ring_size *
678 (2 + AGG_RING_SIZE_FACTOR));
679 ring->ring_mask = ring->ring_size - 1;
680 ring->bd = (void *)cpr->cp_desc_ring;
681 ring->bd_dma = cpr->cp_desc_mapping;
685 /* Allocate Aggregator rings */
686 ring = rte_zmalloc_socket("bnxt_rx_ring_struct",
687 sizeof(struct bnxt_ring),
688 RTE_CACHE_LINE_SIZE, socket_id);
691 rxr->ag_ring_struct = ring;
692 ring->ring_size = rte_align32pow2(rxq->nb_rx_desc *
693 AGG_RING_SIZE_FACTOR);
694 ring->ring_mask = ring->ring_size - 1;
695 ring->bd = (void *)rxr->ag_desc_ring;
696 ring->bd_dma = rxr->ag_desc_mapping;
697 ring->vmem_size = ring->ring_size * sizeof(struct bnxt_sw_rx_bd);
698 ring->vmem = (void **)&rxr->ag_buf_ring;
703 static void bnxt_init_rxbds(struct bnxt_ring *ring, uint32_t type,
707 struct rx_prod_pkt_bd *rx_bd_ring = (struct rx_prod_pkt_bd *)ring->bd;
711 for (j = 0; j < ring->ring_size; j++) {
712 rx_bd_ring[j].flags_type = rte_cpu_to_le_16(type);
713 rx_bd_ring[j].len = rte_cpu_to_le_16(len);
714 rx_bd_ring[j].opaque = j;
718 int bnxt_init_one_rx_ring(struct bnxt_rx_queue *rxq)
720 struct bnxt_rx_ring_info *rxr;
721 struct bnxt_ring *ring;
726 size = rte_pktmbuf_data_room_size(rxq->mb_pool) - RTE_PKTMBUF_HEADROOM;
727 if (rxq->rx_buf_use_size <= size)
728 size = rxq->rx_buf_use_size;
730 type = RX_PROD_PKT_BD_TYPE_RX_PROD_PKT;
733 ring = rxr->rx_ring_struct;
734 bnxt_init_rxbds(ring, type, size);
737 for (i = 0; i < ring->ring_size; i++) {
738 if (bnxt_alloc_rx_data(rxq, rxr, prod) != 0) {
740 "init'ed rx ring %d with %d/%d mbufs only\n",
741 rxq->queue_id, i, ring->ring_size);
745 prod = RING_NEXT(rxr->rx_ring_struct, prod);
748 ring = rxr->ag_ring_struct;
749 type = RX_PROD_AGG_BD_TYPE_RX_PROD_AGG;
750 bnxt_init_rxbds(ring, type, size);
753 for (i = 0; i < ring->ring_size; i++) {
754 if (bnxt_alloc_ag_data(rxq, rxr, prod) != 0) {
756 "init'ed AG ring %d with %d/%d mbufs only\n",
757 rxq->queue_id, i, ring->ring_size);
761 prod = RING_NEXT(rxr->ag_ring_struct, prod);
763 PMD_DRV_LOG(DEBUG, "AGG Done!\n");
766 for (i = 0; i < BNXT_TPA_MAX; i++) {
767 rxr->tpa_info[i].mbuf =
768 __bnxt_alloc_rx_data(rxq->mb_pool);
769 if (!rxr->tpa_info[i].mbuf) {
770 rte_atomic64_inc(&rxq->bp->rx_mbuf_alloc_fail);
775 PMD_DRV_LOG(DEBUG, "TPA alloc Done!\n");