Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2022 Intel Corporation
3 : : */
4 : :
5 : : #include <ethdev_driver.h>
6 : : #include <rte_net.h>
7 : : #include <rte_vect.h>
8 : :
9 : : #include "idpf_ethdev.h"
10 : : #include "idpf_rxtx.h"
11 : : #include "idpf_rxtx_vec_common.h"
12 : :
13 : : static uint64_t
14 : 0 : idpf_rx_offload_convert(uint64_t offload)
15 : : {
16 : : uint64_t ol = 0;
17 : :
18 [ # # ]: 0 : if ((offload & RTE_ETH_RX_OFFLOAD_IPV4_CKSUM) != 0)
19 : : ol |= IDPF_RX_OFFLOAD_IPV4_CKSUM;
20 [ # # ]: 0 : if ((offload & RTE_ETH_RX_OFFLOAD_UDP_CKSUM) != 0)
21 : 0 : ol |= IDPF_RX_OFFLOAD_UDP_CKSUM;
22 [ # # ]: 0 : if ((offload & RTE_ETH_RX_OFFLOAD_TCP_CKSUM) != 0)
23 : 0 : ol |= IDPF_RX_OFFLOAD_TCP_CKSUM;
24 [ # # ]: 0 : if ((offload & RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM) != 0)
25 : 0 : ol |= IDPF_RX_OFFLOAD_OUTER_IPV4_CKSUM;
26 [ # # ]: 0 : if ((offload & RTE_ETH_RX_OFFLOAD_TIMESTAMP) != 0)
27 : 0 : ol |= IDPF_RX_OFFLOAD_TIMESTAMP;
28 : :
29 : 0 : return ol;
30 : : }
31 : :
32 : : static uint64_t
33 : 0 : idpf_tx_offload_convert(uint64_t offload)
34 : : {
35 : : uint64_t ol = 0;
36 : :
37 [ # # ]: 0 : if ((offload & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) != 0)
38 : : ol |= IDPF_TX_OFFLOAD_IPV4_CKSUM;
39 [ # # ]: 0 : if ((offload & RTE_ETH_TX_OFFLOAD_UDP_CKSUM) != 0)
40 : 0 : ol |= IDPF_TX_OFFLOAD_UDP_CKSUM;
41 [ # # ]: 0 : if ((offload & RTE_ETH_TX_OFFLOAD_TCP_CKSUM) != 0)
42 : 0 : ol |= IDPF_TX_OFFLOAD_TCP_CKSUM;
43 [ # # ]: 0 : if ((offload & RTE_ETH_TX_OFFLOAD_SCTP_CKSUM) != 0)
44 : 0 : ol |= IDPF_TX_OFFLOAD_SCTP_CKSUM;
45 [ # # ]: 0 : if ((offload & RTE_ETH_TX_OFFLOAD_TCP_TSO) != 0)
46 : 0 : ol |= IDPF_TX_OFFLOAD_TCP_TSO;
47 [ # # ]: 0 : if ((offload & RTE_ETH_TX_OFFLOAD_MULTI_SEGS) != 0)
48 : 0 : ol |= IDPF_TX_OFFLOAD_MULTI_SEGS;
49 [ # # ]: 0 : if ((offload & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) != 0)
50 : 0 : ol |= IDPF_TX_OFFLOAD_MBUF_FAST_FREE;
51 : :
52 : 0 : return ol;
53 : : }
54 : :
55 : : static const struct idpf_rxq_ops def_rxq_ops = {
56 : : .release_mbufs = idpf_qc_rxq_mbufs_release,
57 : : };
58 : :
59 : : static const struct rte_memzone *
60 [ # # # # : 0 : idpf_dma_zone_reserve(struct rte_eth_dev *dev, uint16_t queue_idx,
# ]
61 : : uint16_t len, uint16_t queue_type,
62 : : unsigned int socket_id, bool splitq)
63 : : {
64 : : char ring_name[RTE_MEMZONE_NAMESIZE];
65 : : const struct rte_memzone *mz;
66 : : uint32_t ring_size;
67 : :
68 : : memset(ring_name, 0, RTE_MEMZONE_NAMESIZE);
69 [ # # # # : 0 : switch (queue_type) {
# ]
70 : 0 : case VIRTCHNL2_QUEUE_TYPE_TX:
71 [ # # ]: 0 : if (splitq)
72 : 0 : ring_size = RTE_ALIGN(len * sizeof(struct idpf_flex_tx_sched_desc),
73 : : IDPF_DMA_MEM_ALIGN);
74 : : else
75 : 0 : ring_size = RTE_ALIGN(len * sizeof(struct ci_tx_desc),
76 : : IDPF_DMA_MEM_ALIGN);
77 : : rte_memcpy(ring_name, "idpf Tx ring", sizeof("idpf Tx ring"));
78 : : break;
79 : 0 : case VIRTCHNL2_QUEUE_TYPE_RX:
80 [ # # ]: 0 : if (splitq)
81 : 0 : ring_size = RTE_ALIGN(len * sizeof(struct virtchnl2_rx_flex_desc_adv_nic_3),
82 : : IDPF_DMA_MEM_ALIGN);
83 : : else
84 : 0 : ring_size = RTE_ALIGN(len * sizeof(struct virtchnl2_singleq_rx_buf_desc),
85 : : IDPF_DMA_MEM_ALIGN);
86 : : rte_memcpy(ring_name, "idpf Rx ring", sizeof("idpf Rx ring"));
87 : : break;
88 : 0 : case VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION:
89 [ # # ]: 0 : ring_size = RTE_ALIGN(len * sizeof(struct idpf_splitq_tx_compl_desc),
90 : : IDPF_DMA_MEM_ALIGN);
91 : : rte_memcpy(ring_name, "idpf Tx compl ring", sizeof("idpf Tx compl ring"));
92 : : break;
93 : 0 : case VIRTCHNL2_QUEUE_TYPE_RX_BUFFER:
94 [ # # ]: 0 : ring_size = RTE_ALIGN(len * sizeof(struct virtchnl2_splitq_rx_buf_desc),
95 : : IDPF_DMA_MEM_ALIGN);
96 : : rte_memcpy(ring_name, "idpf Rx buf ring", sizeof("idpf Rx buf ring"));
97 : : break;
98 : 0 : default:
99 : 0 : PMD_INIT_LOG(ERR, "Invalid queue type");
100 : 0 : return NULL;
101 : : }
102 : :
103 : 0 : mz = rte_eth_dma_zone_reserve(dev, ring_name, queue_idx,
104 : : ring_size, IDPF_RING_BASE_ALIGN,
105 : : socket_id);
106 [ # # ]: 0 : if (mz == NULL) {
107 : 0 : PMD_INIT_LOG(ERR, "Failed to reserve DMA memory for ring");
108 : 0 : return NULL;
109 : : }
110 : :
111 : : /* Zero all the descriptors in the ring. */
112 : 0 : memset(mz->addr, 0, ring_size);
113 : :
114 : 0 : return mz;
115 : : }
116 : :
117 : : static void
118 : : idpf_dma_zone_release(const struct rte_memzone *mz)
119 : : {
120 : 0 : rte_memzone_free(mz);
121 : 0 : }
122 : :
123 : : static int
124 : 0 : idpf_rx_split_bufq_setup(struct rte_eth_dev *dev, struct idpf_rx_queue *rxq,
125 : : uint16_t queue_idx, uint16_t rx_free_thresh,
126 : : uint16_t nb_desc, unsigned int socket_id,
127 : : struct rte_mempool *mp, uint8_t bufq_id)
128 : : {
129 : 0 : struct idpf_vport *vport = dev->data->dev_private;
130 : 0 : struct idpf_adapter *adapter = vport->adapter;
131 : : struct idpf_hw *hw = &adapter->hw;
132 : : const struct rte_memzone *mz;
133 : : struct idpf_rx_queue *bufq;
134 : : uint16_t len;
135 : : int ret;
136 : :
137 : 0 : bufq = rte_zmalloc_socket("idpf bufq",
138 : : sizeof(struct idpf_rx_queue),
139 : : RTE_CACHE_LINE_SIZE,
140 : : socket_id);
141 [ # # ]: 0 : if (bufq == NULL) {
142 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for rx buffer queue.");
143 : : ret = -ENOMEM;
144 : 0 : goto err_bufq1_alloc;
145 : : }
146 : :
147 : 0 : bufq->mp = mp;
148 : 0 : bufq->nb_rx_desc = nb_desc;
149 : 0 : bufq->rx_free_thresh = rx_free_thresh;
150 : 0 : bufq->queue_id = vport->chunks_info.rx_buf_start_qid + queue_idx;
151 : 0 : bufq->port_id = dev->data->port_id;
152 : 0 : bufq->rx_hdr_len = 0;
153 [ # # ]: 0 : bufq->adapter = adapter;
154 : :
155 : 0 : len = rte_pktmbuf_data_room_size(bufq->mp) - RTE_PKTMBUF_HEADROOM;
156 : 0 : bufq->rx_buf_len = RTE_ALIGN_FLOOR(len, (1 << IDPF_RLAN_CTX_DBUF_S));
157 : 0 : bufq->rx_buf_len = RTE_MIN(bufq->rx_buf_len, IDPF_RX_MAX_DATA_BUF_SIZE);
158 : :
159 : : /* Allocate a little more to support bulk allocate. */
160 : 0 : len = nb_desc + IDPF_RX_MAX_BURST;
161 : :
162 : 0 : mz = idpf_dma_zone_reserve(dev, queue_idx, len,
163 : : VIRTCHNL2_QUEUE_TYPE_RX_BUFFER,
164 : : socket_id, true);
165 [ # # ]: 0 : if (mz == NULL) {
166 : : ret = -ENOMEM;
167 : 0 : goto err_mz_reserve;
168 : : }
169 : :
170 : 0 : bufq->rx_ring_phys_addr = mz->iova;
171 : 0 : bufq->rx_ring = mz->addr;
172 : 0 : bufq->mz = mz;
173 : :
174 : 0 : bufq->sw_ring =
175 : 0 : rte_zmalloc_socket("idpf rx bufq sw ring",
176 : : sizeof(struct rte_mbuf *) * len,
177 : : RTE_CACHE_LINE_SIZE,
178 : : socket_id);
179 [ # # ]: 0 : if (bufq->sw_ring == NULL) {
180 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for SW ring");
181 : : ret = -ENOMEM;
182 : 0 : goto err_sw_ring_alloc;
183 : : }
184 : :
185 : 0 : idpf_qc_split_rx_bufq_reset(bufq);
186 : 0 : bufq->qrx_tail = hw->hw_addr + (vport->chunks_info.rx_buf_qtail_start +
187 : 0 : queue_idx * vport->chunks_info.rx_buf_qtail_spacing);
188 : 0 : bufq->idpf_ops = &def_rxq_ops;
189 : 0 : bufq->q_set = true;
190 : :
191 [ # # ]: 0 : if (bufq_id == IDPF_RX_SPLIT_BUFQ1_ID) {
192 : 0 : rxq->bufq1 = bufq;
193 [ # # ]: 0 : } else if (bufq_id == IDPF_RX_SPLIT_BUFQ2_ID) {
194 : 0 : rxq->bufq2 = bufq;
195 : : } else {
196 : 0 : PMD_INIT_LOG(ERR, "Invalid buffer queue index.");
197 : : ret = -EINVAL;
198 : 0 : goto err_bufq_id;
199 : : }
200 : :
201 : : return 0;
202 : :
203 : : err_bufq_id:
204 : 0 : rte_free(bufq->sw_ring);
205 : 0 : err_sw_ring_alloc:
206 : : idpf_dma_zone_release(mz);
207 : 0 : err_mz_reserve:
208 : 0 : rte_free(bufq);
209 : : err_bufq1_alloc:
210 : : return ret;
211 : : }
212 : :
213 : : static void
214 : 0 : idpf_rx_split_bufq_release(struct idpf_rx_queue *bufq)
215 : : {
216 : 0 : rte_free(bufq->sw_ring);
217 : 0 : idpf_dma_zone_release(bufq->mz);
218 : 0 : rte_free(bufq);
219 : 0 : }
220 : :
221 : : int
222 : 0 : idpf_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
223 : : uint16_t nb_desc, unsigned int socket_id,
224 : : const struct rte_eth_rxconf *rx_conf,
225 : : struct rte_mempool *mp)
226 : : {
227 : 0 : struct idpf_vport *vport = dev->data->dev_private;
228 : 0 : struct idpf_adapter *adapter = vport->adapter;
229 : : struct idpf_hw *hw = &adapter->hw;
230 : : const struct rte_memzone *mz;
231 : : struct idpf_rx_queue *rxq;
232 : : uint16_t rx_free_thresh;
233 : : uint64_t offloads;
234 : : bool is_splitq;
235 : : uint16_t len;
236 : : int ret;
237 : :
238 : 0 : offloads = rx_conf->offloads | dev->data->dev_conf.rxmode.offloads;
239 : :
240 : : /* Check free threshold */
241 [ # # ]: 0 : rx_free_thresh = (rx_conf->rx_free_thresh == 0) ?
242 : : IDPF_DEFAULT_RX_FREE_THRESH :
243 : : rx_conf->rx_free_thresh;
244 [ # # ]: 0 : if (idpf_qc_rx_thresh_check(nb_desc, rx_free_thresh) != 0)
245 : : return -EINVAL;
246 : :
247 : : /* Check that ring size is > 2 * rx_free_thresh */
248 [ # # ]: 0 : if (nb_desc <= 2 * rx_free_thresh) {
249 : 0 : PMD_INIT_LOG(ERR, "rx ring size (%u) must be > 2 * rx_free_thresh (%u)",
250 : : nb_desc, rx_free_thresh);
251 [ # # ]: 0 : if (rx_free_thresh == IDPF_DEFAULT_RX_FREE_THRESH)
252 : 0 : PMD_INIT_LOG(ERR, "To use ring sizes of %u or smaller, reduce rx_free_thresh",
253 : : IDPF_DEFAULT_RX_FREE_THRESH * 2);
254 : 0 : return -EINVAL;
255 : : }
256 : :
257 : : /* Free memory if needed */
258 [ # # ]: 0 : if (dev->data->rx_queues[queue_idx] != NULL) {
259 : 0 : idpf_qc_rx_queue_release(dev->data->rx_queues[queue_idx]);
260 : 0 : dev->data->rx_queues[queue_idx] = NULL;
261 : : }
262 : :
263 : : /* Setup Rx queue */
264 : 0 : rxq = rte_zmalloc_socket("idpf rxq",
265 : : sizeof(struct idpf_rx_queue),
266 : : RTE_CACHE_LINE_SIZE,
267 : : socket_id);
268 [ # # ]: 0 : if (rxq == NULL) {
269 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for rx queue data structure");
270 : : ret = -ENOMEM;
271 : 0 : goto err_rxq_alloc;
272 : : }
273 : :
274 : 0 : is_splitq = !!(vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT);
275 : :
276 : 0 : rxq->mp = mp;
277 : 0 : rxq->nb_rx_desc = nb_desc;
278 : 0 : rxq->rx_free_thresh = rx_free_thresh;
279 : 0 : rxq->queue_id = vport->chunks_info.rx_start_qid + queue_idx;
280 : 0 : rxq->port_id = dev->data->port_id;
281 : 0 : rxq->rx_deferred_start = rx_conf->rx_deferred_start;
282 : 0 : rxq->rx_hdr_len = 0;
283 : 0 : rxq->adapter = adapter;
284 [ # # ]: 0 : rxq->offloads = idpf_rx_offload_convert(offloads);
285 : :
286 : 0 : len = rte_pktmbuf_data_room_size(rxq->mp) - RTE_PKTMBUF_HEADROOM;
287 : 0 : rxq->rx_buf_len = RTE_ALIGN_FLOOR(len, (1 << IDPF_RLAN_CTX_DBUF_S));
288 : 0 : rxq->rx_buf_len = RTE_MIN(rxq->rx_buf_len, IDPF_RX_MAX_DATA_BUF_SIZE);
289 : :
290 : : /* Allocate a little more to support bulk allocate. */
291 : 0 : len = nb_desc + IDPF_RX_MAX_BURST;
292 : 0 : mz = idpf_dma_zone_reserve(dev, queue_idx, len, VIRTCHNL2_QUEUE_TYPE_RX,
293 : : socket_id, is_splitq);
294 [ # # ]: 0 : if (mz == NULL) {
295 : : ret = -ENOMEM;
296 : 0 : goto err_mz_reserve;
297 : : }
298 : 0 : rxq->rx_ring_phys_addr = mz->iova;
299 : 0 : rxq->rx_ring = mz->addr;
300 : 0 : rxq->mz = mz;
301 : :
302 [ # # ]: 0 : if (!is_splitq) {
303 : 0 : rxq->sw_ring = rte_zmalloc_socket("idpf rxq sw ring",
304 : : sizeof(struct rte_mbuf *) * len,
305 : : RTE_CACHE_LINE_SIZE,
306 : : socket_id);
307 [ # # ]: 0 : if (rxq->sw_ring == NULL) {
308 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for SW ring");
309 : : ret = -ENOMEM;
310 : 0 : goto err_sw_ring_alloc;
311 : : }
312 : :
313 : 0 : idpf_qc_single_rx_queue_reset(rxq);
314 : 0 : rxq->qrx_tail = hw->hw_addr + (vport->chunks_info.rx_qtail_start +
315 : 0 : queue_idx * vport->chunks_info.rx_qtail_spacing);
316 : 0 : rxq->idpf_ops = &def_rxq_ops;
317 : : } else {
318 : 0 : idpf_qc_split_rx_descq_reset(rxq);
319 : :
320 : : /* Setup Rx buffer queues */
321 : 0 : ret = idpf_rx_split_bufq_setup(dev, rxq, 2 * queue_idx,
322 : : rx_free_thresh, nb_desc,
323 : : socket_id, mp, 1);
324 [ # # ]: 0 : if (ret != 0) {
325 : 0 : PMD_INIT_LOG(ERR, "Failed to setup buffer queue 1");
326 : : ret = -EINVAL;
327 : 0 : goto err_bufq1_setup;
328 : : }
329 : :
330 : 0 : ret = idpf_rx_split_bufq_setup(dev, rxq, 2 * queue_idx + 1,
331 : : rx_free_thresh, nb_desc,
332 : : socket_id, mp, 2);
333 [ # # ]: 0 : if (ret != 0) {
334 : 0 : PMD_INIT_LOG(ERR, "Failed to setup buffer queue 2");
335 : : ret = -EINVAL;
336 : 0 : goto err_bufq2_setup;
337 : : }
338 : : }
339 : :
340 : 0 : rxq->q_set = true;
341 : 0 : dev->data->rx_queues[queue_idx] = rxq;
342 : :
343 : 0 : return 0;
344 : :
345 : : err_bufq2_setup:
346 : 0 : idpf_rx_split_bufq_release(rxq->bufq1);
347 : 0 : err_bufq1_setup:
348 : 0 : err_sw_ring_alloc:
349 : : idpf_dma_zone_release(mz);
350 : 0 : err_mz_reserve:
351 : 0 : rte_free(rxq);
352 : : err_rxq_alloc:
353 : : return ret;
354 : : }
355 : :
356 : : static int
357 : 0 : idpf_tx_complq_setup(struct rte_eth_dev *dev, struct ci_tx_queue *txq,
358 : : uint16_t queue_idx, uint16_t nb_desc,
359 : : unsigned int socket_id)
360 : : {
361 : 0 : struct idpf_vport *vport = dev->data->dev_private;
362 : : const struct rte_memzone *mz;
363 : : struct ci_tx_queue *cq;
364 : : int ret;
365 : :
366 : 0 : cq = rte_zmalloc_socket("idpf splitq cq",
367 : : sizeof(*cq),
368 : : RTE_CACHE_LINE_SIZE,
369 : : socket_id);
370 [ # # ]: 0 : if (cq == NULL) {
371 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for Tx compl queue");
372 : : ret = -ENOMEM;
373 : 0 : goto err_cq_alloc;
374 : : }
375 : :
376 : 0 : cq->nb_tx_desc = nb_desc;
377 : 0 : cq->queue_id = vport->chunks_info.tx_compl_start_qid + queue_idx;
378 : 0 : cq->port_id = dev->data->port_id;
379 : 0 : cq->txqs = dev->data->tx_queues;
380 : 0 : cq->tx_start_qid = vport->chunks_info.tx_start_qid;
381 : :
382 : 0 : mz = idpf_dma_zone_reserve(dev, queue_idx, nb_desc,
383 : : VIRTCHNL2_QUEUE_TYPE_TX_COMPLETION,
384 : : socket_id, true);
385 [ # # ]: 0 : if (mz == NULL) {
386 : : ret = -ENOMEM;
387 : 0 : goto err_mz_reserve;
388 : : }
389 : 0 : cq->tx_ring_dma = mz->iova;
390 : 0 : cq->compl_ring = mz->addr;
391 : 0 : cq->mz = mz;
392 : 0 : idpf_qc_split_tx_complq_reset(cq);
393 : :
394 : 0 : txq->complq = cq;
395 : :
396 : 0 : return 0;
397 : :
398 : : err_mz_reserve:
399 : 0 : rte_free(cq);
400 : : err_cq_alloc:
401 : : return ret;
402 : : }
403 : :
404 : : int
405 : 0 : idpf_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
406 : : uint16_t nb_desc, unsigned int socket_id,
407 : : const struct rte_eth_txconf *tx_conf)
408 : : {
409 : 0 : struct idpf_vport *vport = dev->data->dev_private;
410 : 0 : struct idpf_adapter *adapter = vport->adapter;
411 : : uint16_t tx_rs_thresh, tx_free_thresh;
412 : : struct idpf_hw *hw = &adapter->hw;
413 : : const struct rte_memzone *mz;
414 : : struct ci_tx_queue *txq;
415 : : uint64_t offloads;
416 : : uint16_t len;
417 : : bool is_splitq;
418 : : int ret;
419 : :
420 : 0 : offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
421 : :
422 [ # # ]: 0 : tx_rs_thresh = (uint16_t)((tx_conf->tx_rs_thresh > 0) ?
423 : : tx_conf->tx_rs_thresh : IDPF_DEFAULT_TX_RS_THRESH);
424 [ # # ]: 0 : tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh > 0) ?
425 : : tx_conf->tx_free_thresh : IDPF_DEFAULT_TX_FREE_THRESH);
426 [ # # ]: 0 : if (idpf_qc_tx_thresh_check(nb_desc, tx_rs_thresh, tx_free_thresh) != 0)
427 : : return -EINVAL;
428 : :
429 : : /* Free memory if needed. */
430 [ # # ]: 0 : if (dev->data->tx_queues[queue_idx] != NULL) {
431 : 0 : idpf_qc_tx_queue_release(dev->data->tx_queues[queue_idx]);
432 : 0 : dev->data->tx_queues[queue_idx] = NULL;
433 : : }
434 : :
435 : : /* Allocate the TX queue data structure. */
436 : 0 : txq = rte_zmalloc_socket("idpf txq",
437 : : sizeof(struct ci_tx_queue),
438 : : RTE_CACHE_LINE_SIZE,
439 : : socket_id);
440 [ # # ]: 0 : if (txq == NULL) {
441 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for tx queue structure");
442 : : ret = -ENOMEM;
443 : 0 : goto err_txq_alloc;
444 : : }
445 : :
446 : 0 : is_splitq = !!(vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT);
447 : :
448 : 0 : txq->nb_tx_desc = nb_desc;
449 : 0 : txq->tx_rs_thresh = tx_rs_thresh;
450 [ # # ]: 0 : txq->log2_rs_thresh = rte_log2_u32(tx_rs_thresh);
451 : 0 : txq->tx_free_thresh = tx_free_thresh;
452 : 0 : txq->queue_id = vport->chunks_info.tx_start_qid + queue_idx;
453 : 0 : txq->port_id = dev->data->port_id;
454 : 0 : txq->fast_free_mp = offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ?
455 [ # # ]: 0 : (void *)UINTPTR_MAX : NULL;
456 : 0 : txq->offloads = idpf_tx_offload_convert(offloads);
457 : 0 : txq->tx_deferred_start = tx_conf->tx_deferred_start;
458 : :
459 [ # # ]: 0 : if (is_splitq)
460 : 0 : len = 2 * nb_desc;
461 : : else
462 : : len = nb_desc;
463 : 0 : txq->sw_nb_desc = len;
464 : :
465 : : /* Allocate TX hardware ring descriptors. */
466 : 0 : mz = idpf_dma_zone_reserve(dev, queue_idx, nb_desc, VIRTCHNL2_QUEUE_TYPE_TX,
467 : : socket_id, is_splitq);
468 [ # # ]: 0 : if (mz == NULL) {
469 : : ret = -ENOMEM;
470 : 0 : goto err_mz_reserve;
471 : : }
472 : 0 : txq->tx_ring_dma = mz->iova;
473 : 0 : txq->mz = mz;
474 : :
475 : 0 : txq->sw_ring = rte_zmalloc_socket("idpf tx sw ring",
476 : : sizeof(struct ci_tx_entry) * len,
477 : : RTE_CACHE_LINE_SIZE, socket_id);
478 [ # # ]: 0 : if (txq->sw_ring == NULL) {
479 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for SW TX ring");
480 : : ret = -ENOMEM;
481 : 0 : goto err_sw_ring_alloc;
482 : : }
483 : :
484 : 0 : txq->rs_last_id = rte_zmalloc_socket("idpf tx rs_last_id",
485 : 0 : sizeof(txq->rs_last_id[0]) * (nb_desc >> txq->log2_rs_thresh),
486 : : RTE_CACHE_LINE_SIZE, socket_id);
487 [ # # ]: 0 : if (txq->rs_last_id == NULL) {
488 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for TX RS tracking");
489 : : ret = -ENOMEM;
490 : 0 : goto err_rs_last_id_alloc;
491 : : }
492 : :
493 [ # # ]: 0 : if (!is_splitq) {
494 : 0 : txq->ci_tx_ring = mz->addr;
495 : 0 : idpf_qc_single_tx_queue_reset(txq);
496 : : } else {
497 : 0 : txq->desc_ring = mz->addr;
498 : 0 : idpf_qc_split_tx_descq_reset(txq);
499 : :
500 : : /* Setup tx completion queue if split model */
501 : 0 : ret = idpf_tx_complq_setup(dev, txq, queue_idx,
502 : : 2 * nb_desc, socket_id);
503 [ # # ]: 0 : if (ret != 0)
504 : 0 : goto err_complq_setup;
505 : : }
506 : :
507 : 0 : txq->qtx_tail = hw->hw_addr + (vport->chunks_info.tx_qtail_start +
508 : 0 : queue_idx * vport->chunks_info.tx_qtail_spacing);
509 : 0 : txq->q_set = true;
510 : 0 : dev->data->tx_queues[queue_idx] = txq;
511 : :
512 : 0 : return 0;
513 : :
514 : : err_complq_setup:
515 : 0 : rte_free(txq->rs_last_id);
516 : 0 : err_rs_last_id_alloc:
517 : 0 : rte_free(txq->sw_ring);
518 : 0 : err_sw_ring_alloc:
519 : : idpf_dma_zone_release(mz);
520 : 0 : err_mz_reserve:
521 : 0 : rte_free(txq);
522 : : err_txq_alloc:
523 : : return ret;
524 : : }
525 : :
526 : : int
527 : 0 : idpf_rx_queue_init(struct rte_eth_dev *dev, uint16_t rx_queue_id)
528 : : {
529 : : struct idpf_rx_queue *rxq;
530 : : uint16_t max_pkt_len;
531 : : uint32_t frame_size;
532 : : int err;
533 : :
534 [ # # ]: 0 : if (rx_queue_id >= dev->data->nb_rx_queues)
535 : : return -EINVAL;
536 : :
537 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
538 : :
539 [ # # # # ]: 0 : if (rxq == NULL || !rxq->q_set) {
540 : 0 : PMD_DRV_LOG(ERR, "RX queue %u not available or setup",
541 : : rx_queue_id);
542 : 0 : return -EINVAL;
543 : : }
544 : :
545 : 0 : frame_size = dev->data->mtu + IDPF_ETH_OVERHEAD;
546 : :
547 : 0 : max_pkt_len =
548 : 0 : RTE_MIN((uint32_t)IDPF_SUPPORT_CHAIN_NUM * rxq->rx_buf_len,
549 : : frame_size);
550 : :
551 : 0 : rxq->max_pkt_len = max_pkt_len;
552 [ # # # # ]: 0 : if ((dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) ||
553 : : frame_size > rxq->rx_buf_len)
554 : 0 : dev->data->scattered_rx = 1;
555 : :
556 : 0 : err = idpf_qc_ts_mbuf_register(rxq);
557 [ # # ]: 0 : if (err != 0) {
558 : 0 : PMD_DRV_LOG(ERR, "fail to residter timestamp mbuf %u",
559 : : rx_queue_id);
560 : 0 : return -EIO;
561 : : }
562 : :
563 [ # # ]: 0 : if (rxq->adapter->is_rx_singleq) {
564 : : /* Single queue */
565 : 0 : err = idpf_qc_single_rxq_mbufs_alloc(rxq);
566 [ # # ]: 0 : if (err != 0) {
567 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf");
568 : 0 : return err;
569 : : }
570 : :
571 : : rte_wmb();
572 : :
573 : : /* Init the RX tail register. */
574 : 0 : IDPF_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
575 : : } else {
576 : : /* Split queue */
577 : 0 : err = idpf_qc_split_rxq_mbufs_alloc(rxq->bufq1);
578 [ # # ]: 0 : if (err != 0) {
579 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate RX buffer queue mbuf");
580 : 0 : return err;
581 : : }
582 : 0 : err = idpf_qc_split_rxq_mbufs_alloc(rxq->bufq2);
583 [ # # ]: 0 : if (err != 0) {
584 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate RX buffer queue mbuf");
585 : 0 : return err;
586 : : }
587 : :
588 : : rte_wmb();
589 : :
590 : : /* Init the RX tail register. */
591 : 0 : IDPF_PCI_REG_WRITE(rxq->bufq1->qrx_tail, rxq->bufq1->rx_tail);
592 : 0 : IDPF_PCI_REG_WRITE(rxq->bufq2->qrx_tail, rxq->bufq2->rx_tail);
593 : : }
594 : :
595 : : return err;
596 : : }
597 : :
598 : : int
599 : 0 : idpf_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
600 : : {
601 : 0 : struct idpf_vport *vport = dev->data->dev_private;
602 : 0 : struct idpf_rx_queue *rxq =
603 : 0 : dev->data->rx_queues[rx_queue_id];
604 : : int err = 0;
605 : :
606 : 0 : err = idpf_vc_rxq_config(vport, rxq);
607 [ # # ]: 0 : if (err != 0) {
608 : 0 : PMD_DRV_LOG(ERR, "Fail to configure Rx queue %u", rx_queue_id);
609 : 0 : return err;
610 : : }
611 : :
612 : 0 : err = idpf_rx_queue_init(dev, rx_queue_id);
613 [ # # ]: 0 : if (err != 0) {
614 : 0 : PMD_DRV_LOG(ERR, "Failed to init RX queue %u",
615 : : rx_queue_id);
616 : 0 : return err;
617 : : }
618 : :
619 : : /* Ready to switch the queue on */
620 : 0 : err = idpf_vc_queue_switch(vport, rx_queue_id, true, true,
621 : : VIRTCHNL2_QUEUE_TYPE_RX);
622 [ # # ]: 0 : if (err != 0) {
623 : 0 : PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
624 : : rx_queue_id);
625 : : } else {
626 : 0 : rxq->q_started = true;
627 : 0 : dev->data->rx_queue_state[rx_queue_id] =
628 : : RTE_ETH_QUEUE_STATE_STARTED;
629 : : }
630 : :
631 : : return err;
632 : : }
633 : :
634 : : int
635 : 0 : idpf_tx_queue_init(struct rte_eth_dev *dev, uint16_t tx_queue_id)
636 : : {
637 : : struct ci_tx_queue *txq;
638 : :
639 [ # # ]: 0 : if (tx_queue_id >= dev->data->nb_tx_queues)
640 : : return -EINVAL;
641 : :
642 : 0 : txq = dev->data->tx_queues[tx_queue_id];
643 : :
644 : : /* Init the RX tail register. */
645 : 0 : IDPF_PCI_REG_WRITE(txq->qtx_tail, 0);
646 : :
647 : 0 : return 0;
648 : : }
649 : :
650 : : int
651 : 0 : idpf_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
652 : : {
653 : 0 : struct idpf_vport *vport = dev->data->dev_private;
654 : 0 : struct ci_tx_queue *txq = dev->data->tx_queues[tx_queue_id];
655 : : int err = 0;
656 : :
657 : 0 : err = idpf_vc_txq_config(vport, txq);
658 [ # # ]: 0 : if (err != 0) {
659 : 0 : PMD_DRV_LOG(ERR, "Fail to configure Tx queue %u", tx_queue_id);
660 : 0 : return err;
661 : : }
662 : :
663 : 0 : err = idpf_tx_queue_init(dev, tx_queue_id);
664 [ # # ]: 0 : if (err != 0) {
665 : 0 : PMD_DRV_LOG(ERR, "Failed to init TX queue %u",
666 : : tx_queue_id);
667 : 0 : return err;
668 : : }
669 : :
670 : : /* Ready to switch the queue on */
671 : 0 : err = idpf_vc_queue_switch(vport, tx_queue_id, false, true,
672 : : VIRTCHNL2_QUEUE_TYPE_TX);
673 [ # # ]: 0 : if (err != 0) {
674 : 0 : PMD_DRV_LOG(ERR, "Failed to switch TX queue %u on",
675 : : tx_queue_id);
676 : : } else {
677 : 0 : dev->data->tx_queue_state[tx_queue_id] =
678 : : RTE_ETH_QUEUE_STATE_STARTED;
679 : : }
680 : :
681 : : return err;
682 : : }
683 : :
684 : : int
685 : 0 : idpf_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
686 : : {
687 : 0 : struct idpf_vport *vport = dev->data->dev_private;
688 : : struct idpf_rx_queue *rxq;
689 : : int err;
690 : :
691 [ # # ]: 0 : if (rx_queue_id >= dev->data->nb_rx_queues)
692 : : return -EINVAL;
693 : :
694 : 0 : err = idpf_vc_queue_switch(vport, rx_queue_id, true, false,
695 : : VIRTCHNL2_QUEUE_TYPE_RX);
696 [ # # ]: 0 : if (err != 0) {
697 : 0 : PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off",
698 : : rx_queue_id);
699 : 0 : return err;
700 : : }
701 : :
702 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
703 : 0 : rxq->q_started = false;
704 [ # # ]: 0 : if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE) {
705 : 0 : rxq->idpf_ops->release_mbufs(rxq);
706 : 0 : idpf_qc_single_rx_queue_reset(rxq);
707 : : } else {
708 : 0 : rxq->bufq1->idpf_ops->release_mbufs(rxq->bufq1);
709 : 0 : rxq->bufq2->idpf_ops->release_mbufs(rxq->bufq2);
710 : 0 : idpf_qc_split_rx_queue_reset(rxq);
711 : : }
712 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
713 : :
714 : 0 : return 0;
715 : : }
716 : :
717 : : int
718 : 0 : idpf_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
719 : : {
720 : 0 : struct idpf_vport *vport = dev->data->dev_private;
721 : : struct ci_tx_queue *txq;
722 : : int err;
723 : :
724 [ # # ]: 0 : if (tx_queue_id >= dev->data->nb_tx_queues)
725 : : return -EINVAL;
726 : :
727 : 0 : err = idpf_vc_queue_switch(vport, tx_queue_id, false, false,
728 : : VIRTCHNL2_QUEUE_TYPE_TX);
729 [ # # ]: 0 : if (err != 0) {
730 : 0 : PMD_DRV_LOG(ERR, "Failed to switch TX queue %u off",
731 : : tx_queue_id);
732 : 0 : return err;
733 : : }
734 : :
735 : 0 : txq = dev->data->tx_queues[tx_queue_id];
736 : 0 : ci_txq_release_all_mbufs(txq, false);
737 [ # # ]: 0 : if (vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE) {
738 : 0 : idpf_qc_single_tx_queue_reset(txq);
739 : : } else {
740 : 0 : idpf_qc_split_tx_descq_reset(txq);
741 : 0 : idpf_qc_split_tx_complq_reset(txq->complq);
742 : : }
743 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
744 : :
745 : 0 : return 0;
746 : : }
747 : :
748 : : void
749 : 0 : idpf_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
750 : : {
751 : 0 : idpf_qc_rx_queue_release(dev->data->rx_queues[qid]);
752 : 0 : }
753 : :
754 : : void
755 : 0 : idpf_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
756 : : {
757 : 0 : idpf_qc_tx_queue_release(dev->data->tx_queues[qid]);
758 : 0 : }
759 : :
760 : : void
761 : 0 : idpf_stop_queues(struct rte_eth_dev *dev)
762 : : {
763 : : struct idpf_rx_queue *rxq;
764 : : struct ci_tx_queue *txq;
765 : : int i;
766 : :
767 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
768 : 0 : rxq = dev->data->rx_queues[i];
769 [ # # ]: 0 : if (rxq == NULL)
770 : 0 : continue;
771 : :
772 [ # # ]: 0 : if (idpf_rx_queue_stop(dev, i) != 0)
773 : 0 : PMD_DRV_LOG(WARNING, "Fail to stop Rx queue %d", i);
774 : : }
775 : :
776 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
777 : 0 : txq = dev->data->tx_queues[i];
778 [ # # ]: 0 : if (txq == NULL)
779 : 0 : continue;
780 : :
781 [ # # ]: 0 : if (idpf_tx_queue_stop(dev, i) != 0)
782 : 0 : PMD_DRV_LOG(WARNING, "Fail to stop Tx queue %d", i);
783 : : }
784 : 0 : }
785 : :
786 : : void
787 : 0 : idpf_set_rx_function(struct rte_eth_dev *dev)
788 : : {
789 : 0 : struct idpf_vport *vport = dev->data->dev_private;
790 : 0 : struct idpf_adapter *ad = vport->adapter;
791 : 0 : struct ci_rx_path_features req_features = {
792 : 0 : .rx_offloads = dev->data->dev_conf.rxmode.offloads,
793 : : .simd_width = RTE_VECT_SIMD_DISABLED,
794 : : };
795 : : #ifdef RTE_ARCH_X86
796 : : struct idpf_rx_queue *rxq;
797 : : int i;
798 : : #endif
799 : :
800 : : /* If the device has started the function has already been selected. */
801 [ # # ]: 0 : if (dev->data->dev_started)
802 : 0 : goto out;
803 : :
804 : : #ifdef RTE_ARCH_X86
805 [ # # # # ]: 0 : if (idpf_rx_vec_dev_check_default(dev) == IDPF_VECTOR_PATH &&
806 : 0 : rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256)
807 : 0 : req_features.simd_width = idpf_get_max_simd_bitwidth();
808 : : #endif
809 : :
810 : 0 : req_features.single_queue = (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE);
811 : 0 : req_features.scattered = dev->data->scattered_rx;
812 : :
813 : 0 : ad->rx_func_type = ci_rx_path_select(&req_features,
814 : : &idpf_rx_path_infos[0],
815 : : IDPF_RX_MAX,
816 : : IDPF_RX_DEFAULT);
817 : :
818 : : #ifdef RTE_ARCH_X86
819 [ # # ]: 0 : if (idpf_rx_path_infos[ad->rx_func_type].features.simd_width >= RTE_VECT_SIMD_256) {
820 : : /* Vector function selected. Prepare the rxq accordingly. */
821 [ # # ]: 0 : if (idpf_rx_path_infos[ad->rx_func_type].features.single_queue) {
822 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
823 : 0 : rxq = dev->data->rx_queues[i];
824 : 0 : (void)idpf_qc_singleq_rx_vec_setup(rxq);
825 : : }
826 : : } else {
827 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
828 : 0 : rxq = dev->data->rx_queues[i];
829 : 0 : (void)idpf_qc_splitq_rx_vec_setup(rxq);
830 : : }
831 : : }
832 : :
833 : : }
834 : : #endif
835 : :
836 : 0 : out:
837 : 0 : dev->rx_pkt_burst = idpf_rx_path_infos[ad->rx_func_type].pkt_burst;
838 : 0 : PMD_DRV_LOG(NOTICE, "Using %s Rx (port %d).",
839 : : idpf_rx_path_infos[ad->rx_func_type].info, dev->data->port_id);
840 : :
841 : 0 : }
842 : :
843 : : static bool
844 : 0 : idpf_tx_simple_allowed(struct rte_eth_dev *dev)
845 : : {
846 : 0 : struct idpf_vport *vport = dev->data->dev_private;
847 : : struct ci_tx_queue *txq;
848 : :
849 [ # # ]: 0 : if (vport->txq_model != VIRTCHNL2_QUEUE_MODEL_SINGLE)
850 : : return false;
851 : :
852 [ # # ]: 0 : for (int i = 0; i < dev->data->nb_tx_queues; i++) {
853 : 0 : txq = dev->data->tx_queues[i];
854 [ # # ]: 0 : if (txq == NULL)
855 : 0 : continue;
856 [ # # ]: 0 : if (txq->offloads != (txq->offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) ||
857 [ # # ]: 0 : txq->tx_rs_thresh < IDPF_VPMD_TX_MAX_BURST)
858 : : return false;
859 : : }
860 : : return true;
861 : : }
862 : :
863 : : void
864 : 0 : idpf_set_tx_function(struct rte_eth_dev *dev)
865 : : {
866 : 0 : struct idpf_vport *vport = dev->data->dev_private;
867 : : struct ci_tx_queue *txq;
868 : : int i;
869 : 0 : struct idpf_adapter *ad = vport->adapter;
870 : 0 : bool simple_allowed = idpf_tx_simple_allowed(dev);
871 : 0 : struct ci_tx_path_features req_features = {
872 : 0 : .tx_offloads = dev->data->dev_conf.txmode.offloads,
873 : : .simd_width = RTE_VECT_SIMD_DISABLED,
874 : 0 : .single_queue = (vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE),
875 : : .simple_tx = simple_allowed
876 : : };
877 : :
878 : : /* If the device has started the function has already been selected. */
879 [ # # ]: 0 : if (dev->data->dev_started)
880 : 0 : goto out;
881 : :
882 : : #ifdef RTE_ARCH_X86
883 [ # # ]: 0 : if (idpf_tx_vec_dev_check_default(dev) == IDPF_VECTOR_PATH)
884 : 0 : req_features.simd_width = idpf_get_max_simd_bitwidth();
885 : : #endif
886 : :
887 : 0 : ad->tx_func_type = ci_tx_path_select(&req_features,
888 : : &idpf_tx_path_infos[0],
889 : : IDPF_TX_MAX,
890 : : IDPF_TX_DEFAULT);
891 : :
892 : : /* Set use_vec_entry for single queue mode - only IDPF_TX_SINGLEQ uses regular entries */
893 [ # # ]: 0 : if (vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE) {
894 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
895 : 0 : txq = dev->data->tx_queues[i];
896 [ # # ]: 0 : if (txq == NULL)
897 : 0 : continue;
898 : 0 : txq->use_vec_entry = (ad->tx_func_type != IDPF_TX_SINGLEQ);
899 : : }
900 : : }
901 : :
902 : 0 : out:
903 : 0 : dev->tx_pkt_burst = idpf_tx_path_infos[ad->tx_func_type].pkt_burst;
904 : 0 : dev->tx_pkt_prepare = idpf_dp_prep_pkts;
905 : 0 : PMD_DRV_LOG(NOTICE, "Using %s Tx (port %d).",
906 : : idpf_tx_path_infos[ad->tx_func_type].info, dev->data->port_id);
907 : 0 : }
|