1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Cesnet
3 * Copyright(c) 2019 Netcope Technologies, a.s. <[email protected]>
4 * All rights reserved.
5 */
6
7 #include <rte_kvargs.h>
8
9 #include "nfb_rx.h"
10 #include "nfb.h"
11
12 uint64_t nfb_timestamp_rx_dynflag;
13 int nfb_timestamp_dynfield_offset = -1;
14
15 int
nfb_eth_rx_queue_start(struct rte_eth_dev * dev,uint16_t rxq_id)16 nfb_eth_rx_queue_start(struct rte_eth_dev *dev, uint16_t rxq_id)
17 {
18 struct ndp_rx_queue *rxq = dev->data->rx_queues[rxq_id];
19 int ret;
20
21 if (rxq->queue == NULL) {
22 RTE_LOG(ERR, PMD, "RX NDP queue is NULL!\n");
23 return -EINVAL;
24 }
25
26 ret = ndp_queue_start(rxq->queue);
27 if (ret != 0)
28 goto err;
29 dev->data->rx_queue_state[rxq_id] = RTE_ETH_QUEUE_STATE_STARTED;
30 return 0;
31
32 err:
33 return -EINVAL;
34 }
35
36 int
nfb_eth_rx_queue_stop(struct rte_eth_dev * dev,uint16_t rxq_id)37 nfb_eth_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rxq_id)
38 {
39 struct ndp_rx_queue *rxq = dev->data->rx_queues[rxq_id];
40 int ret;
41
42 if (rxq->queue == NULL) {
43 RTE_LOG(ERR, PMD, "RX NDP queue is NULL!\n");
44 return -EINVAL;
45 }
46
47 ret = ndp_queue_stop(rxq->queue);
48 if (ret != 0)
49 return -EINVAL;
50
51 dev->data->rx_queue_state[rxq_id] = RTE_ETH_QUEUE_STATE_STOPPED;
52 return 0;
53 }
54
55 int
nfb_eth_rx_queue_setup(struct rte_eth_dev * dev,uint16_t rx_queue_id,uint16_t nb_rx_desc __rte_unused,unsigned int socket_id,const struct rte_eth_rxconf * rx_conf __rte_unused,struct rte_mempool * mb_pool)56 nfb_eth_rx_queue_setup(struct rte_eth_dev *dev,
57 uint16_t rx_queue_id,
58 uint16_t nb_rx_desc __rte_unused,
59 unsigned int socket_id,
60 const struct rte_eth_rxconf *rx_conf __rte_unused,
61 struct rte_mempool *mb_pool)
62 {
63 struct pmd_internals *internals = dev->data->dev_private;
64
65 struct ndp_rx_queue *rxq;
66 int ret;
67
68 rxq = rte_zmalloc_socket("ndp rx queue",
69 sizeof(struct ndp_rx_queue),
70 RTE_CACHE_LINE_SIZE, socket_id);
71
72 if (rxq == NULL) {
73 RTE_LOG(ERR, PMD, "rte_zmalloc_socket() failed for rx queue id "
74 "%" PRIu16 "!\n", rx_queue_id);
75 return -ENOMEM;
76 }
77
78 rxq->flags = 0;
79
80 ret = nfb_eth_rx_queue_init(internals->nfb,
81 rx_queue_id,
82 dev->data->port_id,
83 mb_pool,
84 rxq);
85
86 if (ret == 0)
87 dev->data->rx_queues[rx_queue_id] = rxq;
88 else
89 rte_free(rxq);
90
91 return ret;
92 }
93
94 int
nfb_eth_rx_queue_init(struct nfb_device * nfb,uint16_t rx_queue_id,uint16_t port_id,struct rte_mempool * mb_pool,struct ndp_rx_queue * rxq)95 nfb_eth_rx_queue_init(struct nfb_device *nfb,
96 uint16_t rx_queue_id,
97 uint16_t port_id,
98 struct rte_mempool *mb_pool,
99 struct ndp_rx_queue *rxq)
100 {
101 const struct rte_pktmbuf_pool_private *mbp_priv =
102 rte_mempool_get_priv(mb_pool);
103
104 if (nfb == NULL)
105 return -EINVAL;
106
107 rxq->queue = ndp_open_rx_queue(nfb, rx_queue_id);
108 if (rxq->queue == NULL)
109 return -EINVAL;
110
111 rxq->nfb = nfb;
112 rxq->rx_queue_id = rx_queue_id;
113 rxq->in_port = port_id;
114 rxq->mb_pool = mb_pool;
115 rxq->buf_size = (uint16_t)(mbp_priv->mbuf_data_room_size -
116 RTE_PKTMBUF_HEADROOM);
117
118 rxq->rx_pkts = 0;
119 rxq->rx_bytes = 0;
120 rxq->err_pkts = 0;
121
122 return 0;
123 }
124
125 void
nfb_eth_rx_queue_release(struct rte_eth_dev * dev,uint16_t qid)126 nfb_eth_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
127 {
128 struct ndp_rx_queue *rxq = dev->data->rx_queues[qid];
129
130 if (rxq->queue != NULL) {
131 ndp_close_rx_queue(rxq->queue);
132 rte_free(rxq);
133 rxq->queue = NULL;
134 }
135 }
136