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 * Packet type bitfield.
286 * Pointer to the neta_ouq_l3_type structure.
288 * Pointer to the neta_outq_l4_type structure.
289 * @param gen_l3_cksum
290 * Will be set to 1 in case l3 checksum is computed.
292 * Will be set to 1 in case l4 checksum is computed.
295 * 0 on success, negative error value otherwise.
298 mvneta_prepare_proto_info(uint64_t ol_flags, uint32_t packet_type,
299 enum neta_outq_l3_type *l3_type,
300 enum neta_outq_l4_type *l4_type,
305 * Based on ol_flags prepare information
306 * for neta_ppio_outq_desc_set_proto_info() which setups descriptor
309 if (ol_flags & PKT_TX_IPV4) {
310 *l3_type = NETA_OUTQ_L3_TYPE_IPV4;
311 *gen_l3_cksum = ol_flags & PKT_TX_IP_CKSUM ? 1 : 0;
312 } else if (ol_flags & PKT_TX_IPV6) {
313 *l3_type = NETA_OUTQ_L3_TYPE_IPV6;
314 /* no checksum for ipv6 header */
317 /* if something different then stop processing */
321 ol_flags &= PKT_TX_L4_MASK;
322 if ((packet_type & RTE_PTYPE_L4_TCP) &&
323 ol_flags == PKT_TX_TCP_CKSUM) {
324 *l4_type = NETA_OUTQ_L4_TYPE_TCP;
326 } else if ((packet_type & RTE_PTYPE_L4_UDP) &&
327 ol_flags == PKT_TX_UDP_CKSUM) {
328 *l4_type = NETA_OUTQ_L4_TYPE_UDP;
331 *l4_type = NETA_OUTQ_L4_TYPE_OTHER;
332 /* no checksum for other type */
340 * Get offload information from the received packet descriptor.
343 * Pointer to the received packet descriptor.
346 * Mbuf offload flags.
348 static inline uint64_t
349 mvneta_desc_to_ol_flags(struct neta_ppio_desc *desc)
352 enum neta_inq_desc_status status;
354 status = neta_ppio_inq_desc_get_l3_pkt_error(desc);
355 if (unlikely(status != NETA_DESC_ERR_OK))
356 flags = PKT_RX_IP_CKSUM_BAD;
358 flags = PKT_RX_IP_CKSUM_GOOD;
360 status = neta_ppio_inq_desc_get_l4_pkt_error(desc);
361 if (unlikely(status != NETA_DESC_ERR_OK))
362 flags |= PKT_RX_L4_CKSUM_BAD;
364 flags |= PKT_RX_L4_CKSUM_GOOD;
370 * DPDK callback for transmit.
373 * Generic pointer transmit queue.
375 * Packets to transmit.
377 * Number of packets in array.
380 * Number of packets successfully transmitted.
383 mvneta_tx_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
385 struct mvneta_txq *q = txq;
386 struct mvneta_shadow_txq *sq;
387 struct neta_ppio_desc descs[nb_pkts];
389 int i, ret, bytes_sent = 0;
390 uint16_t num, sq_free_size;
394 if (unlikely(!nb_pkts || !q->priv->ppio))
398 mvneta_sent_buffers_free(q->priv->ppio,
401 sq_free_size = MRVL_NETA_TX_SHADOWQ_SIZE - sq->size - 1;
402 if (unlikely(nb_pkts > sq_free_size)) {
404 "No room in shadow queue for %d packets! %d packets will be sent.",
405 nb_pkts, sq_free_size);
406 nb_pkts = sq_free_size;
410 for (i = 0; i < nb_pkts; i++) {
411 struct rte_mbuf *mbuf = tx_pkts[i];
412 int gen_l3_cksum, gen_l4_cksum;
413 enum neta_outq_l3_type l3_type;
414 enum neta_outq_l4_type l4_type;
416 /* Fill first mbuf info in shadow queue */
417 mvneta_fill_shadowq(sq, mbuf);
418 mvneta_fill_desc(&descs[i], mbuf);
420 bytes_sent += rte_pktmbuf_pkt_len(mbuf);
422 ret = mvneta_prepare_proto_info(mbuf->ol_flags,
430 neta_ppio_outq_desc_set_proto_info(&descs[i], l3_type, l4_type,
432 mbuf->l2_len + mbuf->l3_len,
433 gen_l3_cksum, gen_l4_cksum);
436 neta_ppio_send(q->priv->ppio, q->queue_id, descs, &nb_pkts);
439 /* number of packets that were not sent */
440 if (unlikely(num > nb_pkts)) {
441 for (i = nb_pkts; i < num; i++) {
442 sq->head = (MRVL_NETA_TX_SHADOWQ_SIZE + sq->head - 1) &
443 MRVL_NETA_TX_SHADOWQ_MASK;
444 addr = cookie_addr_high | sq->ent[sq->head].cookie;
446 rte_pktmbuf_pkt_len((struct rte_mbuf *)addr);
448 sq->size -= num - nb_pkts;
451 q->bytes_sent += bytes_sent;
456 /** DPDK callback for S/G transmit.
459 * Generic pointer transmit queue.
461 * Packets to transmit.
463 * Number of packets in array.
466 * Number of packets successfully transmitted.
469 mvneta_tx_sg_pkt_burst(void *txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
471 struct mvneta_txq *q = txq;
472 struct mvneta_shadow_txq *sq;
473 struct neta_ppio_desc descs[nb_pkts * NETA_PPIO_DESC_NUM_FRAGS];
474 struct neta_ppio_sg_pkts pkts;
475 uint8_t frags[nb_pkts];
476 int i, j, ret, bytes_sent = 0;
477 int tail, tail_first;
478 uint16_t num, sq_free_size;
479 uint16_t nb_segs, total_descs = 0;
486 if (unlikely(!q->priv->ppio))
490 mvneta_sent_buffers_free(q->priv->ppio,
492 /* Save shadow queue free size */
493 sq_free_size = MRVL_NETA_TX_SHADOWQ_SIZE - sq->size - 1;
496 for (i = 0; i < nb_pkts; i++) {
497 struct rte_mbuf *mbuf = tx_pkts[i];
498 struct rte_mbuf *seg = NULL;
499 int gen_l3_cksum, gen_l4_cksum;
500 enum neta_outq_l3_type l3_type;
501 enum neta_outq_l4_type l4_type;
503 nb_segs = mbuf->nb_segs;
504 total_descs += nb_segs;
507 * Check if total_descs does not exceed
508 * shadow queue free size
510 if (unlikely(total_descs > sq_free_size)) {
511 total_descs -= nb_segs;
513 "No room in shadow queue for %d packets! "
514 "%d packets will be sent.",
520 /* Check if nb_segs does not exceed the max nb of desc per
523 if (unlikely(nb_segs > NETA_PPIO_DESC_NUM_FRAGS)) {
524 total_descs -= nb_segs;
526 "Too many segments. Packet won't be sent.");
530 pkts.frags[pkts.num] = nb_segs;
535 for (j = 0; j < nb_segs - 1; j++) {
536 /* For the subsequent segments, set shadow queue
539 mvneta_fill_shadowq(sq, NULL);
540 mvneta_fill_desc(&descs[tail], seg);
545 /* Put first mbuf info in last shadow queue entry */
546 mvneta_fill_shadowq(sq, mbuf);
547 /* Update descriptor with last segment */
548 mvneta_fill_desc(&descs[tail++], seg);
550 bytes_sent += rte_pktmbuf_pkt_len(mbuf);
552 ret = mvneta_prepare_proto_info(mbuf->ol_flags,
560 neta_ppio_outq_desc_set_proto_info(&descs[tail_first],
563 mbuf->l2_len + mbuf->l3_len,
564 gen_l3_cksum, gen_l4_cksum);
567 neta_ppio_send_sg(q->priv->ppio, q->queue_id, descs, &total_descs,
570 /* number of packets that were not sent */
571 if (unlikely(num > total_descs)) {
572 for (i = total_descs; i < num; i++) {
573 sq->head = (MRVL_NETA_TX_SHADOWQ_SIZE +
575 MRVL_NETA_TX_SHADOWQ_MASK;
576 addr = sq->ent[sq->head].cookie;
578 struct rte_mbuf *mbuf;
580 mbuf = (struct rte_mbuf *)
581 (cookie_addr_high | addr);
582 bytes_sent -= rte_pktmbuf_pkt_len(mbuf);
585 sq->size -= num - total_descs;
589 q->bytes_sent += bytes_sent;
595 * Set tx burst function according to offload flag
598 * Pointer to Ethernet device structure.
601 mvneta_set_tx_function(struct rte_eth_dev *dev)
603 struct mvneta_priv *priv = dev->data->dev_private;
605 /* Use a simple Tx queue (no offloads, no multi segs) if possible */
606 if (priv->multiseg) {
607 MVNETA_LOG(INFO, "Using multi-segment tx callback");
608 dev->tx_pkt_burst = mvneta_tx_sg_pkt_burst;
610 MVNETA_LOG(INFO, "Using single-segment tx callback");
611 dev->tx_pkt_burst = mvneta_tx_pkt_burst;
616 * DPDK callback for receive.
619 * Generic pointer to the receive queue.
621 * Array to store received packets.
623 * Maximum number of packets in array.
626 * Number of packets successfully received.
629 mvneta_rx_pkt_burst(void *rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
631 struct mvneta_rxq *q = rxq;
632 struct neta_ppio_desc descs[nb_pkts];
633 int i, ret, rx_done = 0, rx_dropped = 0;
635 if (unlikely(!q || !q->priv->ppio))
638 ret = neta_ppio_recv(q->priv->ppio, q->queue_id,
641 if (unlikely(ret < 0)) {
642 MVNETA_LOG(ERR, "Failed to receive packets");
646 for (i = 0; i < nb_pkts; i++) {
647 struct rte_mbuf *mbuf;
648 uint8_t l3_offset, l4_offset;
649 enum neta_inq_desc_status status;
652 addr = cookie_addr_high |
653 neta_ppio_inq_desc_get_cookie(&descs[i]);
654 mbuf = (struct rte_mbuf *)addr;
656 rte_pktmbuf_reset(mbuf);
658 /* drop packet in case of mac, overrun or resource error */
659 status = neta_ppio_inq_desc_get_l2_pkt_error(&descs[i]);
660 if (unlikely(status != NETA_DESC_ERR_OK)) {
661 /* Release the mbuf to the mempool since
662 * it won't be transferred to tx path
664 rte_pktmbuf_free(mbuf);
670 mbuf->data_off += MVNETA_PKT_EFFEC_OFFS;
671 mbuf->pkt_len = neta_ppio_inq_desc_get_pkt_len(&descs[i]);
672 mbuf->data_len = mbuf->pkt_len;
673 mbuf->port = q->port_id;
675 mvneta_desc_to_packet_type_and_offset(&descs[i],
678 mbuf->l2_len = l3_offset;
679 mbuf->l3_len = l4_offset - l3_offset;
681 if (likely(q->cksum_enabled))
682 mbuf->ol_flags = mvneta_desc_to_ol_flags(&descs[i]);
684 rx_pkts[rx_done++] = mbuf;
685 q->bytes_recv += mbuf->pkt_len;
687 q->pkts_processed += rx_done + rx_dropped;
689 if (q->pkts_processed > rx_desc_free_thresh) {
690 int buf_to_refill = rx_desc_free_thresh;
692 ret = mvneta_buffs_alloc(q->priv, q, &buf_to_refill);
694 MVNETA_LOG(ERR, "Refill failed");
695 q->pkts_processed -= buf_to_refill;
702 * DPDK callback to configure the receive queue.
705 * Pointer to Ethernet device structure.
709 * Number of descriptors to configure in queue.
711 * NUMA socket on which memory must be allocated.
713 * Thresholds parameters (unused_).
715 * Memory pool for buffer allocations.
718 * 0 on success, negative error value otherwise.
721 mvneta_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
723 const struct rte_eth_rxconf *conf __rte_unused,
724 struct rte_mempool *mp)
726 struct mvneta_priv *priv = dev->data->dev_private;
727 struct mvneta_rxq *rxq;
728 uint32_t frame_size, buf_size = rte_pktmbuf_data_room_size(mp);
729 uint32_t max_rx_pkt_len = dev->data->dev_conf.rxmode.max_rx_pkt_len;
731 frame_size = buf_size - RTE_PKTMBUF_HEADROOM - MVNETA_PKT_EFFEC_OFFS;
733 if (frame_size < max_rx_pkt_len) {
735 "Mbuf size must be increased to %u bytes to hold up "
736 "to %u bytes of data.",
737 buf_size + max_rx_pkt_len - frame_size,
739 dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
740 MVNETA_LOG(INFO, "Setting max rx pkt len to %u",
741 dev->data->dev_conf.rxmode.max_rx_pkt_len);
744 if (dev->data->rx_queues[idx]) {
745 rte_free(dev->data->rx_queues[idx]);
746 dev->data->rx_queues[idx] = NULL;
749 rxq = rte_zmalloc_socket("rxq", sizeof(*rxq), 0, socket);
755 rxq->cksum_enabled = dev->data->dev_conf.rxmode.offloads &
756 DEV_RX_OFFLOAD_IPV4_CKSUM;
758 rxq->port_id = dev->data->port_id;
760 rx_desc_free_thresh = RTE_MIN(rx_desc_free_thresh, (desc / 2));
761 priv->ppio_params.inqs_params.tcs_params[MRVL_NETA_DEFAULT_TC].size =
764 dev->data->rx_queues[idx] = rxq;
770 * DPDK callback to configure the transmit queue.
773 * Pointer to Ethernet device structure.
775 * Transmit queue index.
777 * Number of descriptors to configure in the queue.
779 * NUMA socket on which memory must be allocated.
781 * Tx queue configuration parameters.
784 * 0 on success, negative error value otherwise.
787 mvneta_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
788 unsigned int socket, const struct rte_eth_txconf *conf)
790 struct mvneta_priv *priv = dev->data->dev_private;
791 struct mvneta_txq *txq;
793 if (dev->data->tx_queues[idx]) {
794 rte_free(dev->data->tx_queues[idx]);
795 dev->data->tx_queues[idx] = NULL;
798 txq = rte_zmalloc_socket("txq", sizeof(*txq), 0, socket);
804 txq->port_id = dev->data->port_id;
805 txq->tx_deferred_start = conf->tx_deferred_start;
806 dev->data->tx_queues[idx] = txq;
808 priv->ppio_params.outqs_params.outqs_params[idx].size = desc;
809 priv->ppio_params.outqs_params.outqs_params[idx].weight = 1;
815 * DPDK callback to release the transmit queue.
818 * Generic transmit queue pointer.
821 mvneta_tx_queue_release(void *txq)
823 struct mvneta_txq *q = txq;
832 * Return mbufs to mempool.
835 * Pointer to rx queue structure
837 * Array of rx descriptors
840 mvneta_recv_buffs_free(struct neta_ppio_desc *desc, uint16_t num)
845 for (i = 0; i < num; i++) {
847 addr = cookie_addr_high |
848 neta_ppio_inq_desc_get_cookie(desc);
850 rte_pktmbuf_free((struct rte_mbuf *)addr);
857 mvneta_alloc_rx_bufs(struct rte_eth_dev *dev)
859 struct mvneta_priv *priv = dev->data->dev_private;
862 for (i = 0; i < dev->data->nb_rx_queues; i++) {
863 struct mvneta_rxq *rxq = dev->data->rx_queues[i];
866 ret = mvneta_buffs_alloc(priv, rxq, &num);
867 if (ret || num != rxq->size) {
877 * Flush single receive queue.
880 * Pointer to rx queue structure.
882 * Array of rx descriptors
885 mvneta_rx_queue_flush(struct mvneta_rxq *rxq)
887 struct neta_ppio_desc *descs;
888 struct neta_buff_inf *bufs;
892 descs = rte_malloc("rxdesc", MRVL_NETA_RXD_MAX * sizeof(*descs), 0);
893 bufs = rte_malloc("buffs", MRVL_NETA_RXD_MAX * sizeof(*bufs), 0);
896 num = MRVL_NETA_RXD_MAX;
897 ret = neta_ppio_recv(rxq->priv->ppio,
900 mvneta_recv_buffs_free(descs, num);
901 } while (ret == 0 && num);
903 rxq->pkts_processed = 0;
905 num = MRVL_NETA_RXD_MAX;
907 neta_ppio_inq_get_all_buffs(rxq->priv->ppio, rxq->queue_id, bufs, &num);
908 MVNETA_LOG(INFO, "freeing %u unused bufs.", num);
910 for (i = 0; i < num; i++) {
912 if (bufs[i].cookie) {
913 addr = cookie_addr_high | bufs[i].cookie;
914 rte_pktmbuf_free((struct rte_mbuf *)addr);
923 * Flush single transmit queue.
926 * Pointer to tx queue structure
929 mvneta_tx_queue_flush(struct mvneta_txq *txq)
931 struct mvneta_shadow_txq *sq = &txq->shadow_txq;
934 mvneta_sent_buffers_free(txq->priv->ppio, sq,
937 /* free the rest of them */
938 while (sq->tail != sq->head) {
939 uint64_t addr = cookie_addr_high |
940 sq->ent[sq->tail].cookie;
941 rte_pktmbuf_free((struct rte_mbuf *)addr);
942 sq->tail = (sq->tail + 1) & MRVL_NETA_TX_SHADOWQ_MASK;
944 memset(sq, 0, sizeof(*sq));
948 mvneta_flush_queues(struct rte_eth_dev *dev)
952 MVNETA_LOG(INFO, "Flushing rx queues");
953 for (i = 0; i < dev->data->nb_rx_queues; i++) {
954 struct mvneta_rxq *rxq = dev->data->rx_queues[i];
956 mvneta_rx_queue_flush(rxq);
959 MVNETA_LOG(INFO, "Flushing tx queues");
960 for (i = 0; i < dev->data->nb_tx_queues; i++) {
961 struct mvneta_txq *txq = dev->data->tx_queues[i];
963 mvneta_tx_queue_flush(txq);
968 * DPDK callback to release the receive queue.
971 * Generic receive queue pointer.
974 mvneta_rx_queue_release(void *rxq)
976 struct mvneta_rxq *q = rxq;
981 /* If dev_stop was called already, mbufs are already
982 * returned to mempool and ppio is deinitialized.
987 mvneta_rx_queue_flush(q);
993 * DPDK callback to get information about specific receive queue.
996 * Pointer to Ethernet device structure.
998 * Receive queue index.
1000 * Receive queue information structure.
1003 mvneta_rxq_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
1004 struct rte_eth_rxq_info *qinfo)
1006 struct mvneta_rxq *q = dev->data->rx_queues[rx_queue_id];
1009 qinfo->nb_desc = q->size;
1013 * DPDK callback to get information about specific transmit queue.
1016 * Pointer to Ethernet device structure.
1017 * @param tx_queue_id
1018 * Transmit queue index.
1020 * Transmit queue information structure.
1023 mvneta_txq_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
1024 struct rte_eth_txq_info *qinfo)
1026 struct mvneta_priv *priv = dev->data->dev_private;
1029 priv->ppio_params.outqs_params.outqs_params[tx_queue_id].size;