1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Marvell International Ltd.
3 * Copyright(c) 2018 Semihalf.
7 #include "mvneta_rxtx.h"
9 #define MVNETA_PKT_EFFEC_OFFS (MRVL_NETA_PKT_OFFS + MV_MH_SIZE)
11 #define MRVL_NETA_DEFAULT_TC 0
13 /** Maximum number of descriptors in shadow queue. Must be power of 2 */
14 #define MRVL_NETA_TX_SHADOWQ_SIZE MRVL_NETA_TXD_MAX
16 /** Shadow queue size mask (since shadow queue size is power of 2) */
17 #define MRVL_NETA_TX_SHADOWQ_MASK (MRVL_NETA_TX_SHADOWQ_SIZE - 1)
19 /** Minimum number of sent buffers to release from shadow queue to BM */
20 #define MRVL_NETA_BUF_RELEASE_BURST_SIZE_MIN 16
22 /** Maximum number of sent buffers to release from shadow queue to BM */
23 #define MRVL_NETA_BUF_RELEASE_BURST_SIZE_MAX 64
25 #define MVNETA_COOKIE_ADDR_INVALID ~0ULL
26 #define MVNETA_COOKIE_HIGH_ADDR_SHIFT (sizeof(neta_cookie_t) * 8)
27 #define MVNETA_COOKIE_HIGH_ADDR_MASK (~0ULL << MVNETA_COOKIE_HIGH_ADDR_SHIFT)
29 #define MVNETA_SET_COOKIE_HIGH_ADDR(addr) { \
30 if (unlikely(cookie_addr_high == MVNETA_COOKIE_ADDR_INVALID)) \
32 (uint64_t)(addr) & MVNETA_COOKIE_HIGH_ADDR_MASK;\
35 #define MVNETA_CHECK_COOKIE_HIGH_ADDR(addr) \
36 ((likely(cookie_addr_high == \
37 ((uint64_t)(addr) & MVNETA_COOKIE_HIGH_ADDR_MASK))) ? 1 : 0)
40 struct mvneta_priv *priv;
41 struct rte_mempool *mp;
48 uint64_t pkts_processed;
52 * To use buffer harvesting based on loopback port shadow queue structure
53 * was introduced for buffers information bookkeeping.
55 struct mvneta_shadow_txq {
56 int head; /* write index - used when sending buffers */
57 int tail; /* read index - used when releasing buffers */
58 u16 size; /* queue occupied size */
59 struct neta_buff_inf ent[MRVL_NETA_TX_SHADOWQ_SIZE]; /* q entries */
63 struct mvneta_priv *priv;
67 struct mvneta_shadow_txq shadow_txq;
68 int tx_deferred_start;
71 static uint64_t cookie_addr_high = MVNETA_COOKIE_ADDR_INVALID;
72 static uint16_t rx_desc_free_thresh = MRVL_NETA_BUF_RELEASE_BURST_SIZE_MIN;
75 mvneta_buffs_refill(struct mvneta_priv *priv, struct mvneta_rxq *rxq, u16 *num)
77 struct rte_mbuf *mbufs[MRVL_NETA_BUF_RELEASE_BURST_SIZE_MAX];
78 struct neta_buff_inf entries[MRVL_NETA_BUF_RELEASE_BURST_SIZE_MAX];
80 uint16_t nb_desc = *num;
82 ret = rte_pktmbuf_alloc_bulk(rxq->mp, mbufs, nb_desc);
84 MVNETA_LOG(ERR, "Failed to allocate %u mbufs.", nb_desc);
89 MVNETA_SET_COOKIE_HIGH_ADDR(mbufs[0]);
91 for (i = 0; i < nb_desc; i++) {
92 if (unlikely(!MVNETA_CHECK_COOKIE_HIGH_ADDR(mbufs[i]))) {
94 "mbuf virt high addr 0x%lx out of range 0x%lx",
95 (uint64_t)mbufs[i] >> 32,
96 cookie_addr_high >> 32);
100 entries[i].addr = rte_mbuf_data_iova_default(mbufs[i]);
101 entries[i].cookie = (neta_cookie_t)(uint64_t)mbufs[i];
103 neta_ppio_inq_put_buffs(priv->ppio, rxq->queue_id, entries, num);
106 for (i = *num; i < nb_desc; i++)
107 rte_pktmbuf_free(mbufs[i]);
113 * Allocate buffers from mempool
114 * and store addresses in rx descriptors.
117 * 0 on success, negative error value otherwise.
120 mvneta_buffs_alloc(struct mvneta_priv *priv, struct mvneta_rxq *rxq, int *num)
122 uint16_t nb_desc, nb_desc_burst, sent = 0;
129 (nb_desc < MRVL_NETA_BUF_RELEASE_BURST_SIZE_MAX) ?
130 nb_desc : MRVL_NETA_BUF_RELEASE_BURST_SIZE_MAX;
132 ret = mvneta_buffs_refill(priv, rxq, &nb_desc_burst);
133 if (unlikely(ret || !nb_desc_burst))
136 sent += nb_desc_burst;
137 nb_desc -= nb_desc_burst;
147 mvneta_fill_shadowq(struct mvneta_shadow_txq *sq, struct rte_mbuf *buf)
149 sq->ent[sq->head].cookie = (uint64_t)buf;
150 sq->ent[sq->head].addr = buf ?
151 rte_mbuf_data_iova_default(buf) : 0;
153 sq->head = (sq->head + 1) & MRVL_NETA_TX_SHADOWQ_MASK;
158 mvneta_fill_desc(struct neta_ppio_desc *desc, struct rte_mbuf *buf)
160 neta_ppio_outq_desc_reset(desc);
161 neta_ppio_outq_desc_set_phys_addr(desc, rte_pktmbuf_iova(buf));
162 neta_ppio_outq_desc_set_pkt_offset(desc, 0);
163 neta_ppio_outq_desc_set_pkt_len(desc, rte_pktmbuf_data_len(buf));
167 * Release already sent buffers to mempool.
170 * Pointer to the port structure.
172 * Pointer to the shadow queue.
176 * Force releasing packets.
179 mvneta_sent_buffers_free(struct neta_ppio *ppio,
180 struct mvneta_shadow_txq *sq, int qid)
182 struct neta_buff_inf *entry;
183 uint16_t nb_done = 0;
187 neta_ppio_get_num_outq_done(ppio, qid, &nb_done);
189 if (nb_done > sq->size) {
190 MVNETA_LOG(ERR, "nb_done: %d, sq->size %d",
195 for (i = 0; i < nb_done; i++) {
196 entry = &sq->ent[tail];
198 if (unlikely(!entry->addr)) {
200 "Shadow memory @%d: cookie(%lx), pa(%lx)!",
201 tail, (u64)entry->cookie,
203 tail = (tail + 1) & MRVL_NETA_TX_SHADOWQ_MASK;
207 struct rte_mbuf *mbuf;
209 mbuf = (struct rte_mbuf *)
210 (cookie_addr_high | entry->cookie);
211 rte_pktmbuf_free(mbuf);
212 tail = (tail + 1) & MRVL_NETA_TX_SHADOWQ_MASK;
220 * Return packet type information and l3/l4 offsets.
223 * Pointer to the received packet descriptor.
230 * Packet type information.
232 static inline uint64_t
233 mvneta_desc_to_packet_type_and_offset(struct neta_ppio_desc *desc,
234 uint8_t *l3_offset, uint8_t *l4_offset)
236 enum neta_inq_l3_type l3_type;
237 enum neta_inq_l4_type l4_type;
238 uint64_t packet_type;
240 neta_ppio_inq_desc_get_l3_info(desc, &l3_type, l3_offset);
241 neta_ppio_inq_desc_get_l4_info(desc, &l4_type, l4_offset);
243 packet_type = RTE_PTYPE_L2_ETHER;
245 if (NETA_RXD_GET_VLAN_INFO(desc))
246 packet_type |= RTE_PTYPE_L2_ETHER_VLAN;
249 case NETA_INQ_L3_TYPE_IPV4_BAD:
250 case NETA_INQ_L3_TYPE_IPV4_OK:
251 packet_type |= RTE_PTYPE_L3_IPV4;
253 case NETA_INQ_L3_TYPE_IPV6:
254 packet_type |= RTE_PTYPE_L3_IPV6;
257 packet_type |= RTE_PTYPE_UNKNOWN;
258 MVNETA_LOG(DEBUG, "Failed to recognize l3 packet type");
263 case NETA_INQ_L4_TYPE_TCP:
264 packet_type |= RTE_PTYPE_L4_TCP;
266 case NETA_INQ_L4_TYPE_UDP:
267 packet_type |= RTE_PTYPE_L4_UDP;
270 packet_type |= RTE_PTYPE_UNKNOWN;
271 MVNETA_LOG(DEBUG, "Failed to recognize l4 packet type");
279 * Prepare offload information.
284 * Pointer to the neta_ouq_l3_type structure.
286 * Pointer to the neta_outq_l4_type structure.
287 * @param gen_l3_cksum
288 * Will be set to 1 in case l3 checksum is computed.
290 * Will be set to 1 in case l4 checksum is computed.
293 mvneta_prepare_proto_info(uint64_t ol_flags,
294 enum neta_outq_l3_type *l3_type,
295 enum neta_outq_l4_type *l4_type,
300 * Based on ol_flags prepare information
301 * for neta_ppio_outq_desc_set_proto_info() which setups descriptor
303 * in most of the checksum cases ipv4 must be set, so this is the
306 *l3_type = NETA_OUTQ_L3_TYPE_IPV4;
307 *gen_l3_cksum = ol_flags & PKT_TX_IP_CKSUM ? 1 : 0;
309 if (ol_flags & PKT_TX_IPV6) {
310 *l3_type = NETA_OUTQ_L3_TYPE_IPV6;
311 /* no checksum for ipv6 header */
315 if (ol_flags & PKT_TX_TCP_CKSUM) {
316 *l4_type = NETA_OUTQ_L4_TYPE_TCP;
318 } else if (ol_flags & PKT_TX_UDP_CKSUM) {
319 *l4_type = NETA_OUTQ_L4_TYPE_UDP;
322 *l4_type = NETA_OUTQ_L4_TYPE_OTHER;
323 /* no checksum for other type */
329 * Get offload information from the received packet descriptor.
332 * Pointer to the received packet descriptor.
335 * Mbuf offload flags.
337 static inline uint64_t
338 mvneta_desc_to_ol_flags(struct neta_ppio_desc *desc)
341 enum neta_inq_desc_status status;
343 status = neta_ppio_inq_desc_get_l3_pkt_error(desc);
344 if (unlikely(status != NETA_DESC_ERR_OK))
345 flags = PKT_RX_IP_CKSUM_BAD;
347 flags = PKT_RX_IP_CKSUM_GOOD;
349 status = neta_ppio_inq_desc_get_l4_pkt_error(desc);
350 if (unlikely(status != NETA_DESC_ERR_OK))
351 flags |= PKT_RX_L4_CKSUM_BAD;
353 flags |= PKT_RX_L4_CKSUM_GOOD;
359 * DPDK callback for transmit.
362 * Generic pointer transmit queue.
364 * Packets to transmit.
366 * Number of packets in array.
369 * Number of packets successfully transmitted.
372 mvneta_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
374 struct mvneta_txq *q = txq;
375 struct mvneta_shadow_txq *sq;
376 struct neta_ppio_desc descs[nb_pkts];
377 int i, bytes_sent = 0;
378 uint16_t num, sq_free_size;
382 if (unlikely(!nb_pkts || !q->priv->ppio))
386 mvneta_sent_buffers_free(q->priv->ppio,
389 sq_free_size = MRVL_NETA_TX_SHADOWQ_SIZE - sq->size - 1;
390 if (unlikely(nb_pkts > sq_free_size)) {
392 "No room in shadow queue for %d packets! %d packets will be sent.",
393 nb_pkts, sq_free_size);
394 nb_pkts = sq_free_size;
398 for (i = 0; i < nb_pkts; i++) {
399 struct rte_mbuf *mbuf = tx_pkts[i];
400 int gen_l3_cksum, gen_l4_cksum;
401 enum neta_outq_l3_type l3_type;
402 enum neta_outq_l4_type l4_type;
404 /* Fill first mbuf info in shadow queue */
405 mvneta_fill_shadowq(sq, mbuf);
406 mvneta_fill_desc(&descs[i], mbuf);
408 bytes_sent += rte_pktmbuf_pkt_len(mbuf);
410 if (!(mbuf->ol_flags & MVNETA_TX_PKT_OFFLOADS))
412 mvneta_prepare_proto_info(mbuf->ol_flags, &l3_type, &l4_type,
413 &gen_l3_cksum, &gen_l4_cksum);
415 neta_ppio_outq_desc_set_proto_info(&descs[i], l3_type, l4_type,
417 mbuf->l2_len + mbuf->l3_len,
418 gen_l3_cksum, gen_l4_cksum);
421 neta_ppio_send(q->priv->ppio, q->queue_id, descs, &nb_pkts);
424 /* number of packets that were not sent */
425 if (unlikely(num > nb_pkts)) {
426 for (i = nb_pkts; i < num; i++) {
427 sq->head = (MRVL_NETA_TX_SHADOWQ_SIZE + sq->head - 1) &
428 MRVL_NETA_TX_SHADOWQ_MASK;
429 addr = cookie_addr_high | sq->ent[sq->head].cookie;
431 rte_pktmbuf_pkt_len((struct rte_mbuf *)addr);
433 sq->size -= num - nb_pkts;
436 q->bytes_sent += bytes_sent;
441 /** DPDK callback for S/G transmit.
444 * Generic pointer transmit queue.
446 * Packets to transmit.
448 * Number of packets in array.
451 * Number of packets successfully transmitted.
454 mvneta_tx_sg_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
456 struct mvneta_txq *q = txq;
457 struct mvneta_shadow_txq *sq;
458 struct neta_ppio_desc descs[nb_pkts * NETA_PPIO_DESC_NUM_FRAGS];
459 struct neta_ppio_sg_pkts pkts;
460 uint8_t frags[nb_pkts];
461 int i, j, bytes_sent = 0;
462 int tail, tail_first;
463 uint16_t num, sq_free_size;
464 uint16_t nb_segs, total_descs = 0;
471 if (unlikely(!q->priv->ppio))
475 mvneta_sent_buffers_free(q->priv->ppio,
477 /* Save shadow queue free size */
478 sq_free_size = MRVL_NETA_TX_SHADOWQ_SIZE - sq->size - 1;
481 for (i = 0; i < nb_pkts; i++) {
482 struct rte_mbuf *mbuf = tx_pkts[i];
483 struct rte_mbuf *seg = NULL;
484 int gen_l3_cksum, gen_l4_cksum;
485 enum neta_outq_l3_type l3_type;
486 enum neta_outq_l4_type l4_type;
488 nb_segs = mbuf->nb_segs;
489 total_descs += nb_segs;
492 * Check if total_descs does not exceed
493 * shadow queue free size
495 if (unlikely(total_descs > sq_free_size)) {
496 total_descs -= nb_segs;
498 "No room in shadow queue for %d packets! "
499 "%d packets will be sent.",
505 /* Check if nb_segs does not exceed the max nb of desc per
508 if (unlikely(nb_segs > NETA_PPIO_DESC_NUM_FRAGS)) {
509 total_descs -= nb_segs;
511 "Too many segments. Packet won't be sent.");
515 pkts.frags[pkts.num] = nb_segs;
520 for (j = 0; j < nb_segs - 1; j++) {
521 /* For the subsequent segments, set shadow queue
524 mvneta_fill_shadowq(sq, NULL);
525 mvneta_fill_desc(&descs[tail], seg);
530 /* Put first mbuf info in last shadow queue entry */
531 mvneta_fill_shadowq(sq, mbuf);
532 /* Update descriptor with last segment */
533 mvneta_fill_desc(&descs[tail++], seg);
535 bytes_sent += rte_pktmbuf_pkt_len(mbuf);
537 if (!(mbuf->ol_flags & MVNETA_TX_PKT_OFFLOADS))
539 mvneta_prepare_proto_info(mbuf->ol_flags, &l3_type, &l4_type,
540 &gen_l3_cksum, &gen_l4_cksum);
542 neta_ppio_outq_desc_set_proto_info(&descs[tail_first],
545 mbuf->l2_len + mbuf->l3_len,
546 gen_l3_cksum, gen_l4_cksum);
549 neta_ppio_send_sg(q->priv->ppio, q->queue_id, descs, &total_descs,
552 /* number of packets that were not sent */
553 if (unlikely(num > total_descs)) {
554 for (i = total_descs; i < num; i++) {
555 sq->head = (MRVL_NETA_TX_SHADOWQ_SIZE +
557 MRVL_NETA_TX_SHADOWQ_MASK;
558 addr = sq->ent[sq->head].cookie;
560 struct rte_mbuf *mbuf;
562 mbuf = (struct rte_mbuf *)
563 (cookie_addr_high | addr);
564 bytes_sent -= rte_pktmbuf_pkt_len(mbuf);
567 sq->size -= num - total_descs;
571 q->bytes_sent += bytes_sent;
577 * Set tx burst function according to offload flag
580 * Pointer to Ethernet device structure.
583 mvneta_set_tx_function(struct rte_eth_dev *dev)
585 struct mvneta_priv *priv = dev->data->dev_private;
587 /* Use a simple Tx queue (no offloads, no multi segs) if possible */
588 if (priv->multiseg) {
589 MVNETA_LOG(INFO, "Using multi-segment tx callback");
590 dev->tx_pkt_burst = mvneta_tx_sg_pkt_burst;
592 MVNETA_LOG(INFO, "Using single-segment tx callback");
593 dev->tx_pkt_burst = mvneta_tx_pkt_burst;
598 * DPDK callback for receive.
601 * Generic pointer to the receive queue.
603 * Array to store received packets.
605 * Maximum number of packets in array.
608 * Number of packets successfully received.
611 mvneta_rx_pkt_burst(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
613 struct mvneta_rxq *q = rxq;
614 struct neta_ppio_desc descs[nb_pkts];
615 int i, ret, rx_done = 0, rx_dropped = 0;
617 if (unlikely(!q || !q->priv->ppio))
620 ret = neta_ppio_recv(q->priv->ppio, q->queue_id,
623 if (unlikely(ret < 0)) {
624 MVNETA_LOG(ERR, "Failed to receive packets");
628 for (i = 0; i < nb_pkts; i++) {
629 struct rte_mbuf *mbuf;
630 uint8_t l3_offset, l4_offset;
631 enum neta_inq_desc_status status;
634 addr = cookie_addr_high |
635 neta_ppio_inq_desc_get_cookie(&descs[i]);
636 mbuf = (struct rte_mbuf *)addr;
638 rte_pktmbuf_reset(mbuf);
640 /* drop packet in case of mac, overrun or resource error */
641 status = neta_ppio_inq_desc_get_l2_pkt_error(&descs[i]);
642 if (unlikely(status != NETA_DESC_ERR_OK)) {
643 /* Release the mbuf to the mempool since
644 * it won't be transferred to tx path
646 rte_pktmbuf_free(mbuf);
652 mbuf->data_off += MVNETA_PKT_EFFEC_OFFS;
653 mbuf->pkt_len = neta_ppio_inq_desc_get_pkt_len(&descs[i]);
654 mbuf->data_len = mbuf->pkt_len;
655 mbuf->port = q->port_id;
657 mvneta_desc_to_packet_type_and_offset(&descs[i],
660 mbuf->l2_len = l3_offset;
661 mbuf->l3_len = l4_offset - l3_offset;
663 if (likely(q->cksum_enabled))
664 mbuf->ol_flags = mvneta_desc_to_ol_flags(&descs[i]);
666 rx_pkts[rx_done++] = mbuf;
667 q->bytes_recv += mbuf->pkt_len;
669 q->pkts_processed += rx_done + rx_dropped;
671 if (q->pkts_processed > rx_desc_free_thresh) {
672 int buf_to_refill = rx_desc_free_thresh;
674 ret = mvneta_buffs_alloc(q->priv, q, &buf_to_refill);
676 MVNETA_LOG(ERR, "Refill failed");
677 q->pkts_processed -= buf_to_refill;
684 * DPDK callback to configure the receive queue.
687 * Pointer to Ethernet device structure.
691 * Number of descriptors to configure in queue.
693 * NUMA socket on which memory must be allocated.
695 * Thresholds parameters (unused_).
697 * Memory pool for buffer allocations.
700 * 0 on success, negative error value otherwise.
703 mvneta_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
705 const struct rte_eth_rxconf *conf __rte_unused,
706 struct rte_mempool *mp)
708 struct mvneta_priv *priv = dev->data->dev_private;
709 struct mvneta_rxq *rxq;
710 uint32_t frame_size, buf_size = rte_pktmbuf_data_room_size(mp);
711 uint32_t max_rx_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
713 frame_size = buf_size - RTE_PKTMBUF_HEADROOM - MVNETA_PKT_EFFEC_OFFS;
715 if (frame_size < max_rx_pkt_len) {
717 "Mbuf size must be increased to %u bytes to hold up "
718 "to %u bytes of data.",
719 buf_size + max_rx_pkt_len - frame_size,
721 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
722 MVNETA_LOG(INFO, "Setting max rx pkt len to %u",
723 dev->data->dev_conf.rxmode.max_rx_pkt_len);
726 if (dev->data->rx_queues[idx]) {
727 rte_free(dev->data->rx_queues[idx]);
728 dev->data->rx_queues[idx] = NULL;
731 rxq = rte_zmalloc_socket("rxq", sizeof(*rxq), 0, socket);
737 rxq->cksum_enabled = dev->data->dev_conf.rxmode.offloads &
738 DEV_RX_OFFLOAD_IPV4_CKSUM;
740 rxq->port_id = dev->data->port_id;
742 rx_desc_free_thresh = RTE_MIN(rx_desc_free_thresh, (desc / 2));
743 priv->ppio_params.inqs_params.tcs_params[MRVL_NETA_DEFAULT_TC].size =
746 dev->data->rx_queues[idx] = rxq;
752 * DPDK callback to configure the transmit queue.
755 * Pointer to Ethernet device structure.
757 * Transmit queue index.
759 * Number of descriptors to configure in the queue.
761 * NUMA socket on which memory must be allocated.
763 * Tx queue configuration parameters.
766 * 0 on success, negative error value otherwise.
769 mvneta_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
770 unsigned int socket, const struct rte_eth_txconf *conf)
772 struct mvneta_priv *priv = dev->data->dev_private;
773 struct mvneta_txq *txq;
775 if (dev->data->tx_queues[idx]) {
776 rte_free(dev->data->tx_queues[idx]);
777 dev->data->tx_queues[idx] = NULL;
780 txq = rte_zmalloc_socket("txq", sizeof(*txq), 0, socket);
786 txq->port_id = dev->data->port_id;
787 txq->tx_deferred_start = conf->tx_deferred_start;
788 dev->data->tx_queues[idx] = txq;
790 priv->ppio_params.outqs_params.outqs_params[idx].size = desc;
791 priv->ppio_params.outqs_params.outqs_params[idx].weight = 1;
797 * DPDK callback to release the transmit queue.
800 * Pointer to Ethernet device structure.
802 * Transmit queue index.
805 mvneta_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
807 struct mvneta_txq *q = dev->data->tx_queues[qid];
816 * Return mbufs to mempool.
819 * Pointer to rx queue structure
821 * Array of rx descriptors
824 mvneta_recv_buffs_free(struct neta_ppio_desc *desc, uint16_t num)
829 for (i = 0; i < num; i++) {
831 addr = cookie_addr_high |
832 neta_ppio_inq_desc_get_cookie(desc);
834 rte_pktmbuf_free((struct rte_mbuf *)addr);
841 mvneta_alloc_rx_bufs(struct rte_eth_dev *dev)
843 struct mvneta_priv *priv = dev->data->dev_private;
846 for (i = 0; i < dev->data->nb_rx_queues; i++) {
847 struct mvneta_rxq *rxq = dev->data->rx_queues[i];
850 ret = mvneta_buffs_alloc(priv, rxq, &num);
851 if (ret || num != rxq->size) {
861 * Flush single receive queue.
864 * Pointer to rx queue structure.
866 * Array of rx descriptors
869 mvneta_rx_queue_flush(struct mvneta_rxq *rxq)
871 struct neta_ppio_desc *descs;
872 struct neta_buff_inf *bufs;
876 descs = rte_malloc("rxdesc", MRVL_NETA_RXD_MAX * sizeof(*descs), 0);
878 MVNETA_LOG(ERR, "Failed to allocate descs.");
882 bufs = rte_malloc("buffs", MRVL_NETA_RXD_MAX * sizeof(*bufs), 0);
884 MVNETA_LOG(ERR, "Failed to allocate bufs.");
890 num = MRVL_NETA_RXD_MAX;
891 ret = neta_ppio_recv(rxq->priv->ppio,
894 mvneta_recv_buffs_free(descs, num);
895 } while (ret == 0 && num);
897 rxq->pkts_processed = 0;
899 num = MRVL_NETA_RXD_MAX;
901 neta_ppio_inq_get_all_buffs(rxq->priv->ppio, rxq->queue_id, bufs, &num);
902 MVNETA_LOG(INFO, "freeing %u unused bufs.", num);
904 for (i = 0; i < num; i++) {
906 if (bufs[i].cookie) {
907 addr = cookie_addr_high | bufs[i].cookie;
908 rte_pktmbuf_free((struct rte_mbuf *)addr);
917 * Flush single transmit queue.
920 * Pointer to tx queue structure
923 mvneta_tx_queue_flush(struct mvneta_txq *txq)
925 struct mvneta_shadow_txq *sq = &txq->shadow_txq;
928 mvneta_sent_buffers_free(txq->priv->ppio, sq,
931 /* free the rest of them */
932 while (sq->tail != sq->head) {
933 uint64_t addr = cookie_addr_high |
934 sq->ent[sq->tail].cookie;
935 rte_pktmbuf_free((struct rte_mbuf *)addr);
936 sq->tail = (sq->tail + 1) & MRVL_NETA_TX_SHADOWQ_MASK;
938 memset(sq, 0, sizeof(*sq));
942 mvneta_flush_queues(struct rte_eth_dev *dev)
946 MVNETA_LOG(INFO, "Flushing rx queues");
947 for (i = 0; i < dev->data->nb_rx_queues; i++) {
948 struct mvneta_rxq *rxq = dev->data->rx_queues[i];
950 mvneta_rx_queue_flush(rxq);
953 MVNETA_LOG(INFO, "Flushing tx queues");
954 for (i = 0; i < dev->data->nb_tx_queues; i++) {
955 struct mvneta_txq *txq = dev->data->tx_queues[i];
957 mvneta_tx_queue_flush(txq);
962 * DPDK callback to release the receive queue.
965 * Pointer to Ethernet device structure.
967 * Receive queue index.
970 mvneta_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
972 struct mvneta_rxq *q = dev->data->rx_queues[qid];
977 /* If dev_stop was called already, mbufs are already
978 * returned to mempool and ppio is deinitialized.
983 mvneta_rx_queue_flush(q);
989 * DPDK callback to get information about specific receive queue.
992 * Pointer to Ethernet device structure.
994 * Receive queue index.
996 * Receive queue information structure.
999 mvneta_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
1000 struct rte_eth_rxq_info *qinfo)
1002 struct mvneta_rxq *q = dev->data->rx_queues[rx_queue_id];
1005 qinfo->nb_desc = q->size;
1009 * DPDK callback to get information about specific transmit queue.
1012 * Pointer to Ethernet device structure.
1013 * @param tx_queue_id
1014 * Transmit queue index.
1016 * Transmit queue information structure.
1019 mvneta_txq_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
1020 struct rte_eth_txq_info *qinfo)
1022 struct mvneta_priv *priv = dev->data->dev_private;
1025 priv->ppio_params.outqs_params.outqs_params[tx_queue_id].size;