4 * Copyright(c) Broadcom Limited.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Broadcom Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <rte_bitmap.h>
38 #include <rte_byteorder.h>
39 #include <rte_malloc.h>
40 #include <rte_memory.h>
44 #include "bnxt_ring.h"
47 #include "hsi_struct_def_dpdk.h"
53 static inline struct rte_mbuf *__bnxt_alloc_rx_data(struct rte_mempool *mb)
55 struct rte_mbuf *data;
57 data = rte_mbuf_raw_alloc(mb);
62 static inline int bnxt_alloc_rx_data(struct bnxt_rx_queue *rxq,
63 struct bnxt_rx_ring_info *rxr,
66 struct rx_prod_pkt_bd *rxbd = &rxr->rx_desc_ring[prod];
67 struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[prod];
68 struct rte_mbuf *data;
70 data = __bnxt_alloc_rx_data(rxq->mb_pool);
72 rte_atomic64_inc(&rxq->bp->rx_mbuf_alloc_fail);
78 rxbd->addr = rte_cpu_to_le_64(RTE_MBUF_DATA_DMA_ADDR(rx_buf->mbuf));
83 static inline int bnxt_alloc_ag_data(struct bnxt_rx_queue *rxq,
84 struct bnxt_rx_ring_info *rxr,
87 struct rx_prod_pkt_bd *rxbd = &rxr->ag_desc_ring[prod];
88 struct bnxt_sw_rx_bd *rx_buf = &rxr->ag_buf_ring[prod];
89 struct rte_mbuf *data;
91 data = __bnxt_alloc_rx_data(rxq->mb_pool);
93 rte_atomic64_inc(&rxq->bp->rx_mbuf_alloc_fail);
98 RTE_LOG(ERR, PMD, "Jumbo Frame. rxbd is NULL\n");
100 RTE_LOG(ERR, PMD, "Jumbo Frame. rx_buf is NULL\n");
105 rxbd->addr = rte_cpu_to_le_64(RTE_MBUF_DATA_DMA_ADDR(rx_buf->mbuf));
110 static inline void bnxt_reuse_rx_mbuf(struct bnxt_rx_ring_info *rxr,
111 struct rte_mbuf *mbuf)
113 uint16_t prod = RING_NEXT(rxr->rx_ring_struct, rxr->rx_prod);
114 struct bnxt_sw_rx_bd *prod_rx_buf;
115 struct rx_prod_pkt_bd *prod_bd;
117 prod_rx_buf = &rxr->rx_buf_ring[prod];
119 RTE_ASSERT(prod_rx_buf->mbuf == NULL);
120 RTE_ASSERT(mbuf != NULL);
122 prod_rx_buf->mbuf = mbuf;
124 prod_bd = &rxr->rx_desc_ring[prod];
126 prod_bd->addr = rte_cpu_to_le_64(RTE_MBUF_DATA_DMA_ADDR(mbuf));
132 static void bnxt_reuse_ag_mbuf(struct bnxt_rx_ring_info *rxr, uint16_t cons,
133 struct rte_mbuf *mbuf)
135 uint16_t prod = rxr->ag_prod;
136 struct bnxt_sw_rx_bd *prod_rx_buf;
137 struct rx_prod_pkt_bd *prod_bd, *cons_bd;
139 prod_rx_buf = &rxr->ag_buf_ring[prod];
141 prod_rx_buf->mbuf = mbuf;
143 prod_bd = &rxr->ag_desc_ring[prod];
144 cons_bd = &rxr->ag_desc_ring[cons];
146 prod_bd->addr = cons_bd->addr;
151 struct rte_mbuf *bnxt_consume_rx_buf(struct bnxt_rx_ring_info *rxr,
154 struct bnxt_sw_rx_bd *cons_rx_buf;
155 struct rte_mbuf *mbuf;
157 cons_rx_buf = &rxr->rx_buf_ring[cons];
158 RTE_ASSERT(cons_rx_buf->mbuf != NULL);
159 mbuf = cons_rx_buf->mbuf;
160 cons_rx_buf->mbuf = NULL;
164 static void bnxt_tpa_start(struct bnxt_rx_queue *rxq,
165 struct rx_tpa_start_cmpl *tpa_start,
166 struct rx_tpa_start_cmpl_hi *tpa_start1)
168 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
169 uint8_t agg_id = rte_le_to_cpu_32(tpa_start->agg_id &
170 RX_TPA_START_CMPL_AGG_ID_MASK) >> RX_TPA_START_CMPL_AGG_ID_SFT;
172 struct bnxt_tpa_info *tpa_info;
173 struct rte_mbuf *mbuf;
175 data_cons = tpa_start->opaque;
176 tpa_info = &rxr->tpa_info[agg_id];
178 mbuf = bnxt_consume_rx_buf(rxr, data_cons);
180 bnxt_reuse_rx_mbuf(rxr, tpa_info->mbuf);
182 tpa_info->mbuf = mbuf;
183 tpa_info->len = rte_le_to_cpu_32(tpa_start->len);
187 mbuf->pkt_len = rte_le_to_cpu_32(tpa_start->len);
188 mbuf->data_len = mbuf->pkt_len;
189 mbuf->port = rxq->port_id;
190 mbuf->ol_flags = PKT_RX_LRO;
191 if (likely(tpa_start->flags_type &
192 rte_cpu_to_le_32(RX_TPA_START_CMPL_FLAGS_RSS_VALID))) {
193 mbuf->hash.rss = rte_le_to_cpu_32(tpa_start->rss_hash);
194 mbuf->ol_flags |= PKT_RX_RSS_HASH;
196 mbuf->hash.fdir.id = rte_le_to_cpu_16(tpa_start1->cfa_code);
197 mbuf->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
199 if (tpa_start1->flags2 &
200 rte_cpu_to_le_32(RX_TPA_START_CMPL_FLAGS2_META_FORMAT_VLAN)) {
201 mbuf->vlan_tci = rte_le_to_cpu_32(tpa_start1->metadata);
202 mbuf->ol_flags |= PKT_RX_VLAN_PKT;
204 if (likely(tpa_start1->flags2 &
205 rte_cpu_to_le_32(RX_TPA_START_CMPL_FLAGS2_L4_CS_CALC)))
206 mbuf->ol_flags |= PKT_RX_L4_CKSUM_GOOD;
208 /* recycle next mbuf */
209 data_cons = RING_NEXT(rxr->rx_ring_struct, data_cons);
210 bnxt_reuse_rx_mbuf(rxr, bnxt_consume_rx_buf(rxr, data_cons));
213 static int bnxt_agg_bufs_valid(struct bnxt_cp_ring_info *cpr,
214 uint8_t agg_bufs, uint32_t raw_cp_cons)
216 uint16_t last_cp_cons;
217 struct rx_pkt_cmpl *agg_cmpl;
219 raw_cp_cons = ADV_RAW_CMP(raw_cp_cons, agg_bufs);
220 last_cp_cons = RING_CMP(cpr->cp_ring_struct, raw_cp_cons);
221 agg_cmpl = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[last_cp_cons];
222 cpr->valid = FLIP_VALID(raw_cp_cons,
223 cpr->cp_ring_struct->ring_mask,
225 return CMP_VALID(agg_cmpl, raw_cp_cons, cpr->cp_ring_struct);
228 /* TPA consume agg buffer out of order, allocate connected data only */
229 static int bnxt_prod_ag_mbuf(struct bnxt_rx_queue *rxq)
231 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
232 uint16_t next = RING_NEXT(rxr->ag_ring_struct, rxr->ag_prod);
234 /* TODO batch allocation for better performance */
235 while (rte_bitmap_get(rxr->ag_bitmap, next)) {
236 if (unlikely(bnxt_alloc_ag_data(rxq, rxr, next))) {
238 "agg mbuf alloc failed: prod=0x%x\n", next);
241 rte_bitmap_clear(rxr->ag_bitmap, next);
243 next = RING_NEXT(rxr->ag_ring_struct, next);
249 static int bnxt_rx_pages(struct bnxt_rx_queue *rxq,
250 struct rte_mbuf *mbuf, uint32_t *tmp_raw_cons,
253 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
254 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
256 uint16_t cp_cons, ag_cons;
257 struct rx_pkt_cmpl *rxcmp;
258 struct rte_mbuf *last = mbuf;
260 for (i = 0; i < agg_buf; i++) {
261 struct bnxt_sw_rx_bd *ag_buf;
262 struct rte_mbuf *ag_mbuf;
263 *tmp_raw_cons = NEXT_RAW_CMP(*tmp_raw_cons);
264 cp_cons = RING_CMP(cpr->cp_ring_struct, *tmp_raw_cons);
265 rxcmp = (struct rx_pkt_cmpl *)
266 &cpr->cp_desc_ring[cp_cons];
269 bnxt_dump_cmpl(cp_cons, rxcmp);
272 ag_cons = rxcmp->opaque;
273 RTE_ASSERT(ag_cons <= rxr->ag_ring_struct->ring_mask);
274 ag_buf = &rxr->ag_buf_ring[ag_cons];
275 ag_mbuf = ag_buf->mbuf;
276 RTE_ASSERT(ag_mbuf != NULL);
278 ag_mbuf->data_len = rte_le_to_cpu_16(rxcmp->len);
281 mbuf->pkt_len += ag_mbuf->data_len;
283 last->next = ag_mbuf;
289 * As aggregation buffer consumed out of order in TPA module,
290 * use bitmap to track freed slots to be allocated and notified
293 rte_bitmap_set(rxr->ag_bitmap, ag_cons);
295 bnxt_prod_ag_mbuf(rxq);
299 static inline struct rte_mbuf *bnxt_tpa_end(
300 struct bnxt_rx_queue *rxq,
301 uint32_t *raw_cp_cons,
302 struct rx_tpa_end_cmpl *tpa_end,
303 struct rx_tpa_end_cmpl_hi *tpa_end1 __rte_unused)
305 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
306 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
307 uint8_t agg_id = (tpa_end->agg_id & RX_TPA_END_CMPL_AGG_ID_MASK)
308 >> RX_TPA_END_CMPL_AGG_ID_SFT;
309 struct rte_mbuf *mbuf;
311 struct bnxt_tpa_info *tpa_info;
313 tpa_info = &rxr->tpa_info[agg_id];
314 mbuf = tpa_info->mbuf;
315 RTE_ASSERT(mbuf != NULL);
318 agg_bufs = (rte_le_to_cpu_32(tpa_end->agg_bufs_v1) &
319 RX_TPA_END_CMPL_AGG_BUFS_MASK) >> RX_TPA_END_CMPL_AGG_BUFS_SFT;
321 if (!bnxt_agg_bufs_valid(cpr, agg_bufs, *raw_cp_cons))
323 bnxt_rx_pages(rxq, mbuf, raw_cp_cons, agg_bufs);
325 mbuf->l4_len = tpa_end->payload_offset;
327 struct rte_mbuf *new_data = __bnxt_alloc_rx_data(rxq->mb_pool);
328 RTE_ASSERT(new_data != NULL);
330 rte_atomic64_inc(&rxq->bp->rx_mbuf_alloc_fail);
333 tpa_info->mbuf = new_data;
339 bnxt_parse_pkt_type(struct rx_pkt_cmpl *rxcmp, struct rx_pkt_cmpl_hi *rxcmp1)
341 uint32_t pkt_type = 0;
342 uint32_t t_ipcs = 0, ip = 0, ip6 = 0;
343 uint32_t tcp = 0, udp = 0, icmp = 0;
346 vlan = !!(rxcmp1->flags2 &
347 rte_cpu_to_le_32(RX_PKT_CMPL_FLAGS2_META_FORMAT_VLAN));
348 t_ipcs = !!(rxcmp1->flags2 &
349 rte_cpu_to_le_32(RX_PKT_CMPL_FLAGS2_T_IP_CS_CALC));
350 ip6 = !!(rxcmp1->flags2 &
351 rte_cpu_to_le_32(RX_PKT_CMPL_FLAGS2_IP_TYPE));
352 icmp = !!(rxcmp->flags_type &
353 rte_cpu_to_le_16(RX_PKT_CMPL_FLAGS_ITYPE_ICMP));
354 tcp = !!(rxcmp->flags_type &
355 rte_cpu_to_le_16(RX_PKT_CMPL_FLAGS_ITYPE_TCP));
356 udp = !!(rxcmp->flags_type &
357 rte_cpu_to_le_16(RX_PKT_CMPL_FLAGS_ITYPE_UDP));
358 ip = !!(rxcmp->flags_type &
359 rte_cpu_to_le_16(RX_PKT_CMPL_FLAGS_ITYPE_IP));
361 pkt_type |= ((ip || tcp || udp || icmp) && !t_ipcs && !ip6) ?
362 RTE_PTYPE_L3_IPV4_EXT_UNKNOWN : 0;
363 pkt_type |= ((ip || tcp || udp || icmp) && !t_ipcs && ip6) ?
364 RTE_PTYPE_L3_IPV6_EXT_UNKNOWN : 0;
365 pkt_type |= (!t_ipcs && icmp) ? RTE_PTYPE_L4_ICMP : 0;
366 pkt_type |= (!t_ipcs && udp) ? RTE_PTYPE_L4_UDP : 0;
367 pkt_type |= (!t_ipcs && tcp) ? RTE_PTYPE_L4_TCP : 0;
368 pkt_type |= ((ip || tcp || udp || icmp) && t_ipcs && !ip6) ?
369 RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN : 0;
370 pkt_type |= ((ip || tcp || udp || icmp) && t_ipcs && ip6) ?
371 RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN : 0;
372 pkt_type |= (t_ipcs && icmp) ? RTE_PTYPE_INNER_L4_ICMP : 0;
373 pkt_type |= (t_ipcs && udp) ? RTE_PTYPE_INNER_L4_UDP : 0;
374 pkt_type |= (t_ipcs && tcp) ? RTE_PTYPE_INNER_L4_TCP : 0;
375 pkt_type |= vlan ? RTE_PTYPE_L2_ETHER_VLAN : 0;
380 static int bnxt_rx_pkt(struct rte_mbuf **rx_pkt,
381 struct bnxt_rx_queue *rxq, uint32_t *raw_cons)
383 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
384 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
385 struct rx_pkt_cmpl *rxcmp;
386 struct rx_pkt_cmpl_hi *rxcmp1;
387 uint32_t tmp_raw_cons = *raw_cons;
388 uint16_t cons, prod, cp_cons =
389 RING_CMP(cpr->cp_ring_struct, tmp_raw_cons);
393 struct rte_mbuf *mbuf;
398 rxcmp = (struct rx_pkt_cmpl *)
399 &cpr->cp_desc_ring[cp_cons];
401 tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons);
402 cp_cons = RING_CMP(cpr->cp_ring_struct, tmp_raw_cons);
403 rxcmp1 = (struct rx_pkt_cmpl_hi *)&cpr->cp_desc_ring[cp_cons];
405 if (!CMP_VALID(rxcmp1, tmp_raw_cons, cpr->cp_ring_struct))
408 cpr->valid = FLIP_VALID(cp_cons,
409 cpr->cp_ring_struct->ring_mask,
412 cmp_type = CMP_TYPE(rxcmp);
413 if (cmp_type == RX_PKT_CMPL_TYPE_RX_L2_TPA_START) {
414 bnxt_tpa_start(rxq, (struct rx_tpa_start_cmpl *)rxcmp,
415 (struct rx_tpa_start_cmpl_hi *)rxcmp1);
416 rc = -EINVAL; /* Continue w/o new mbuf */
418 } else if (cmp_type == RX_PKT_CMPL_TYPE_RX_L2_TPA_END) {
419 mbuf = bnxt_tpa_end(rxq, &tmp_raw_cons,
420 (struct rx_tpa_end_cmpl *)rxcmp,
421 (struct rx_tpa_end_cmpl_hi *)rxcmp1);
426 } else if (cmp_type != 0x11) {
431 agg_buf = (rxcmp->agg_bufs_v1 & RX_PKT_CMPL_AGG_BUFS_MASK)
432 >> RX_PKT_CMPL_AGG_BUFS_SFT;
433 if (agg_buf && !bnxt_agg_bufs_valid(cpr, agg_buf, tmp_raw_cons))
438 cons = rxcmp->opaque;
439 mbuf = bnxt_consume_rx_buf(rxr, cons);
447 mbuf->pkt_len = rxcmp->len;
448 mbuf->data_len = mbuf->pkt_len;
449 mbuf->port = rxq->port_id;
451 if (rxcmp->flags_type & RX_PKT_CMPL_FLAGS_RSS_VALID) {
452 mbuf->hash.rss = rxcmp->rss_hash;
453 mbuf->ol_flags |= PKT_RX_RSS_HASH;
455 mbuf->hash.fdir.id = rxcmp1->cfa_code;
456 mbuf->ol_flags |= PKT_RX_FDIR | PKT_RX_FDIR_ID;
460 bnxt_rx_pages(rxq, mbuf, &tmp_raw_cons, agg_buf);
462 if (rxcmp1->flags2 & RX_PKT_CMPL_FLAGS2_META_FORMAT_VLAN) {
463 mbuf->vlan_tci = rxcmp1->metadata &
464 (RX_PKT_CMPL_METADATA_VID_MASK |
465 RX_PKT_CMPL_METADATA_DE |
466 RX_PKT_CMPL_METADATA_PRI_MASK);
467 mbuf->ol_flags |= PKT_RX_VLAN_PKT;
470 if (likely(RX_CMP_IP_CS_OK(rxcmp1)))
471 mbuf->ol_flags |= PKT_RX_IP_CKSUM_GOOD;
473 mbuf->ol_flags |= PKT_RX_IP_CKSUM_NONE;
475 if (likely(RX_CMP_L4_CS_OK(rxcmp1)))
476 mbuf->ol_flags |= PKT_RX_L4_CKSUM_GOOD;
478 mbuf->ol_flags |= PKT_RX_L4_CKSUM_NONE;
480 mbuf->packet_type = bnxt_parse_pkt_type(rxcmp, rxcmp1);
483 if (rxcmp1->errors_v2 & RX_CMP_L2_ERRORS) {
484 /* Re-install the mbuf back to the rx ring */
485 bnxt_reuse_rx_mbuf(rxr, cons, mbuf);
487 bnxt_reuse_ag_mbuf(rxr, ag_cons, mbuf);
494 * TODO: Redesign this....
495 * If the allocation fails, the packet does not get received.
496 * Simply returning this will result in slowly falling behind
497 * on the producer ring buffers.
498 * Instead, "filling up" the producer just before ringing the
499 * doorbell could be a better solution since it will let the
500 * producer ring starve until memory is available again pushing
501 * the drops into hardware and getting them out of the driver
502 * allowing recovery to a full producer ring.
504 * This could also help with cache usage by preventing per-packet
505 * calls in favour of a tight loop with the same function being called
508 prod = RING_NEXT(rxr->rx_ring_struct, prod);
509 if (bnxt_alloc_rx_data(rxq, rxr, prod)) {
510 RTE_LOG(ERR, PMD, "mbuf alloc failed with prod=0x%x\n", prod);
516 * All MBUFs are allocated with the same size under DPDK,
517 * no optimization for rx_copy_thresh
524 *raw_cons = tmp_raw_cons;
529 uint16_t bnxt_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
532 struct bnxt_rx_queue *rxq = rx_queue;
533 struct bnxt_cp_ring_info *cpr = rxq->cp_ring;
534 struct bnxt_rx_ring_info *rxr = rxq->rx_ring;
535 uint32_t raw_cons = cpr->cp_raw_cons;
538 struct rx_pkt_cmpl *rxcmp;
539 uint16_t prod = rxr->rx_prod;
540 uint16_t ag_prod = rxr->ag_prod;
543 /* Handle RX burst request */
545 cons = RING_CMP(cpr->cp_ring_struct, raw_cons);
546 rte_prefetch0(&cpr->cp_desc_ring[cons]);
547 rxcmp = (struct rx_pkt_cmpl *)&cpr->cp_desc_ring[cons];
549 if (!CMP_VALID(rxcmp, raw_cons, cpr->cp_ring_struct))
551 cpr->valid = FLIP_VALID(cons,
552 cpr->cp_ring_struct->ring_mask,
555 /* TODO: Avoid magic numbers... */
556 if ((CMP_TYPE(rxcmp) & 0x30) == 0x10) {
557 rc = bnxt_rx_pkt(&rx_pkts[nb_rx_pkts], rxq, &raw_cons);
558 if (likely(!rc) || rc == -ENOMEM)
560 if (rc == -EBUSY) /* partial completion */
563 raw_cons = NEXT_RAW_CMP(raw_cons);
564 if (nb_rx_pkts == nb_pkts)
568 cpr->cp_raw_cons = raw_cons;
569 if (prod == rxr->rx_prod && ag_prod == rxr->ag_prod) {
571 * For PMD, there is no need to keep on pushing to REARM
572 * the doorbell if there are no new completions
577 B_CP_DIS_DB(cpr, cpr->cp_raw_cons);
578 B_RX_DB(rxr->rx_doorbell, rxr->rx_prod);
579 /* Ring the AGG ring DB */
580 B_RX_DB(rxr->ag_doorbell, rxr->ag_prod);
582 /* Attempt to alloc Rx buf in case of a previous allocation failure. */
586 for (i = prod; i <= nb_rx_pkts;
587 i = RING_NEXT(rxr->rx_ring_struct, i)) {
588 struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[i];
590 /* Buffer already allocated for this index. */
591 if (rx_buf->mbuf != NULL)
594 /* This slot is empty. Alloc buffer for Rx */
595 if (!bnxt_alloc_rx_data(rxq, rxr, i)) {
597 B_RX_DB(rxr->rx_doorbell, rxr->rx_prod);
599 RTE_LOG(ERR, PMD, "Alloc mbuf failed\n");
608 void bnxt_free_rx_rings(struct bnxt *bp)
612 for (i = 0; i < (int)bp->rx_nr_rings; i++) {
613 struct bnxt_rx_queue *rxq = bp->rx_queues[i];
618 bnxt_free_ring(rxq->rx_ring->rx_ring_struct);
619 rte_free(rxq->rx_ring->rx_ring_struct);
621 /* Free the Aggregator ring */
622 bnxt_free_ring(rxq->rx_ring->ag_ring_struct);
623 rte_free(rxq->rx_ring->ag_ring_struct);
624 rxq->rx_ring->ag_ring_struct = NULL;
626 rte_free(rxq->rx_ring);
628 bnxt_free_ring(rxq->cp_ring->cp_ring_struct);
629 rte_free(rxq->cp_ring->cp_ring_struct);
630 rte_free(rxq->cp_ring);
633 bp->rx_queues[i] = NULL;
637 int bnxt_init_rx_ring_struct(struct bnxt_rx_queue *rxq, unsigned int socket_id)
639 struct bnxt_cp_ring_info *cpr;
640 struct bnxt_rx_ring_info *rxr;
641 struct bnxt_ring *ring;
643 rxq->rx_buf_use_size = BNXT_MAX_MTU + ETHER_HDR_LEN + ETHER_CRC_LEN +
645 rxq->rx_buf_size = rxq->rx_buf_use_size + sizeof(struct rte_mbuf);
647 rxr = rte_zmalloc_socket("bnxt_rx_ring",
648 sizeof(struct bnxt_rx_ring_info),
649 RTE_CACHE_LINE_SIZE, socket_id);
654 ring = rte_zmalloc_socket("bnxt_rx_ring_struct",
655 sizeof(struct bnxt_ring),
656 RTE_CACHE_LINE_SIZE, socket_id);
659 rxr->rx_ring_struct = ring;
660 ring->ring_size = rte_align32pow2(rxq->nb_rx_desc);
661 ring->ring_mask = ring->ring_size - 1;
662 ring->bd = (void *)rxr->rx_desc_ring;
663 ring->bd_dma = rxr->rx_desc_mapping;
664 ring->vmem_size = ring->ring_size * sizeof(struct bnxt_sw_rx_bd);
665 ring->vmem = (void **)&rxr->rx_buf_ring;
667 cpr = rte_zmalloc_socket("bnxt_rx_ring",
668 sizeof(struct bnxt_cp_ring_info),
669 RTE_CACHE_LINE_SIZE, socket_id);
674 ring = rte_zmalloc_socket("bnxt_rx_ring_struct",
675 sizeof(struct bnxt_ring),
676 RTE_CACHE_LINE_SIZE, socket_id);
679 cpr->cp_ring_struct = ring;
680 ring->ring_size = rte_align32pow2(rxr->rx_ring_struct->ring_size *
681 (2 + AGG_RING_SIZE_FACTOR));
682 ring->ring_mask = ring->ring_size - 1;
683 ring->bd = (void *)cpr->cp_desc_ring;
684 ring->bd_dma = cpr->cp_desc_mapping;
688 /* Allocate Aggregator rings */
689 ring = rte_zmalloc_socket("bnxt_rx_ring_struct",
690 sizeof(struct bnxt_ring),
691 RTE_CACHE_LINE_SIZE, socket_id);
694 rxr->ag_ring_struct = ring;
695 ring->ring_size = rte_align32pow2(rxq->nb_rx_desc *
696 AGG_RING_SIZE_FACTOR);
697 ring->ring_mask = ring->ring_size - 1;
698 ring->bd = (void *)rxr->ag_desc_ring;
699 ring->bd_dma = rxr->ag_desc_mapping;
700 ring->vmem_size = ring->ring_size * sizeof(struct bnxt_sw_rx_bd);
701 ring->vmem = (void **)&rxr->ag_buf_ring;
706 static void bnxt_init_rxbds(struct bnxt_ring *ring, uint32_t type,
710 struct rx_prod_pkt_bd *rx_bd_ring = (struct rx_prod_pkt_bd *)ring->bd;
714 for (j = 0; j < ring->ring_size; j++) {
715 rx_bd_ring[j].flags_type = rte_cpu_to_le_16(type);
716 rx_bd_ring[j].len = rte_cpu_to_le_16(len);
717 rx_bd_ring[j].opaque = j;
721 int bnxt_init_one_rx_ring(struct bnxt_rx_queue *rxq)
723 struct bnxt_rx_ring_info *rxr;
724 struct bnxt_ring *ring;
729 size = rte_pktmbuf_data_room_size(rxq->mb_pool) - RTE_PKTMBUF_HEADROOM;
730 if (rxq->rx_buf_use_size <= size)
731 size = rxq->rx_buf_use_size;
733 type = RX_PROD_PKT_BD_TYPE_RX_PROD_PKT;
736 ring = rxr->rx_ring_struct;
737 bnxt_init_rxbds(ring, type, size);
740 for (i = 0; i < ring->ring_size; i++) {
741 if (bnxt_alloc_rx_data(rxq, rxr, prod) != 0) {
742 RTE_LOG(WARNING, PMD,
743 "init'ed rx ring %d with %d/%d mbufs only\n",
744 rxq->queue_id, i, ring->ring_size);
748 prod = RING_NEXT(rxr->rx_ring_struct, prod);
750 RTE_LOG(DEBUG, PMD, "%s\n", __func__);
752 ring = rxr->ag_ring_struct;
753 type = RX_PROD_AGG_BD_TYPE_RX_PROD_AGG;
754 bnxt_init_rxbds(ring, type, size);
757 for (i = 0; i < ring->ring_size; i++) {
758 if (bnxt_alloc_ag_data(rxq, rxr, prod) != 0) {
759 RTE_LOG(WARNING, PMD,
760 "init'ed AG ring %d with %d/%d mbufs only\n",
761 rxq->queue_id, i, ring->ring_size);
765 prod = RING_NEXT(rxr->ag_ring_struct, prod);
767 RTE_LOG(DEBUG, PMD, "%s AGG Done!\n", __func__);
770 for (i = 0; i < BNXT_TPA_MAX; i++) {
771 rxr->tpa_info[i].mbuf =
772 __bnxt_alloc_rx_data(rxq->mb_pool);
773 if (!rxr->tpa_info[i].mbuf) {
774 rte_atomic64_inc(&rxq->bp->rx_mbuf_alloc_fail);
779 RTE_LOG(DEBUG, PMD, "%s TPA alloc Done!\n", __func__);