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 : : 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 : : 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 : : 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 : : 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 idpf_complq *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 : : bool is_splitq;
417 : : int ret;
418 : :
419 : 0 : offloads = tx_conf->offloads | dev->data->dev_conf.txmode.offloads;
420 : :
421 [ # # ]: 0 : tx_rs_thresh = (uint16_t)((tx_conf->tx_rs_thresh > 0) ?
422 : : tx_conf->tx_rs_thresh : IDPF_DEFAULT_TX_RS_THRESH);
423 [ # # ]: 0 : tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh > 0) ?
424 : : tx_conf->tx_free_thresh : IDPF_DEFAULT_TX_FREE_THRESH);
425 [ # # ]: 0 : if (idpf_qc_tx_thresh_check(nb_desc, tx_rs_thresh, tx_free_thresh) != 0)
426 : : return -EINVAL;
427 : :
428 : : /* Free memory if needed. */
429 [ # # ]: 0 : if (dev->data->tx_queues[queue_idx] != NULL) {
430 : 0 : idpf_qc_tx_queue_release(dev->data->tx_queues[queue_idx]);
431 : 0 : dev->data->tx_queues[queue_idx] = NULL;
432 : : }
433 : :
434 : : /* Allocate the TX queue data structure. */
435 : 0 : txq = rte_zmalloc_socket("idpf txq",
436 : : sizeof(struct ci_tx_queue),
437 : : RTE_CACHE_LINE_SIZE,
438 : : socket_id);
439 [ # # ]: 0 : if (txq == NULL) {
440 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for tx queue structure");
441 : : ret = -ENOMEM;
442 : 0 : goto err_txq_alloc;
443 : : }
444 : :
445 : 0 : is_splitq = !!(vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SPLIT);
446 : :
447 : 0 : txq->nb_tx_desc = nb_desc;
448 : 0 : txq->tx_rs_thresh = tx_rs_thresh;
449 [ # # ]: 0 : txq->log2_rs_thresh = rte_log2_u32(tx_rs_thresh);
450 : 0 : txq->tx_free_thresh = tx_free_thresh;
451 : 0 : txq->queue_id = vport->chunks_info.tx_start_qid + queue_idx;
452 : 0 : txq->port_id = dev->data->port_id;
453 : 0 : txq->fast_free_mp = offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE ?
454 [ # # ]: 0 : (void *)UINTPTR_MAX : NULL;
455 : 0 : txq->offloads = idpf_tx_offload_convert(offloads);
456 : 0 : txq->tx_deferred_start = tx_conf->tx_deferred_start;
457 : :
458 : 0 : txq->sw_nb_desc = nb_desc;
459 : :
460 : : /* Allocate TX hardware ring descriptors. */
461 : 0 : mz = idpf_dma_zone_reserve(dev, queue_idx, nb_desc, VIRTCHNL2_QUEUE_TYPE_TX,
462 : : socket_id, is_splitq);
463 [ # # ]: 0 : if (mz == NULL) {
464 : : ret = -ENOMEM;
465 : 0 : goto err_mz_reserve;
466 : : }
467 : 0 : txq->tx_ring_dma = mz->iova;
468 : 0 : txq->mz = mz;
469 : :
470 [ # # ]: 0 : if (!is_splitq) {
471 : 0 : txq->sw_ring = rte_zmalloc_socket("idpf tx sw ring",
472 : : sizeof(struct ci_tx_entry) * nb_desc,
473 : : RTE_CACHE_LINE_SIZE, socket_id);
474 [ # # ]: 0 : if (txq->sw_ring == NULL) {
475 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for SW TX ring");
476 : : ret = -ENOMEM;
477 : 0 : goto err_sw_ring_alloc;
478 : : }
479 : :
480 : 0 : txq->rs_last_id = rte_zmalloc_socket("idpf tx rs_last_id",
481 : 0 : sizeof(txq->rs_last_id[0]) * (nb_desc >> txq->log2_rs_thresh),
482 : : RTE_CACHE_LINE_SIZE, socket_id);
483 [ # # ]: 0 : if (txq->rs_last_id == NULL) {
484 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate memory for TX RS tracking");
485 : : ret = -ENOMEM;
486 : 0 : goto err_rs_last_id_alloc;
487 : : }
488 : :
489 : 0 : txq->ci_tx_ring = mz->addr;
490 : 0 : idpf_qc_single_tx_queue_reset(txq);
491 : : } else {
492 : 0 : txq->desc_ring = mz->addr;
493 : 0 : ret = idpf_qc_split_tx_pending_alloc(txq, socket_id);
494 [ # # ]: 0 : if (ret != 0)
495 : 0 : goto err_sw_ring_alloc;
496 : 0 : idpf_qc_split_tx_descq_reset(txq);
497 : :
498 : : /* Setup tx completion queue if split model */
499 : 0 : ret = idpf_tx_complq_setup(dev, txq, queue_idx,
500 : : 2 * nb_desc, socket_id);
501 [ # # ]: 0 : if (ret != 0)
502 : 0 : goto err_complq_setup;
503 : : }
504 : :
505 : 0 : txq->qtx_tail = hw->hw_addr + (vport->chunks_info.tx_qtail_start +
506 : 0 : queue_idx * vport->chunks_info.tx_qtail_spacing);
507 : 0 : txq->q_set = true;
508 : 0 : dev->data->tx_queues[queue_idx] = txq;
509 : :
510 : 0 : return 0;
511 : :
512 : : err_complq_setup:
513 : 0 : rte_free(txq->rs_last_id);
514 : 0 : err_rs_last_id_alloc:
515 : 0 : rte_free(txq->sw_ring);
516 : 0 : err_sw_ring_alloc:
517 : : idpf_dma_zone_release(mz);
518 : 0 : err_mz_reserve:
519 : 0 : rte_free(txq);
520 : : err_txq_alloc:
521 : : return ret;
522 : : }
523 : :
524 : : int
525 : 0 : idpf_rx_queue_init(struct rte_eth_dev *dev, uint16_t rx_queue_id)
526 : : {
527 : : struct idpf_rx_queue *rxq;
528 : : uint16_t max_pkt_len;
529 : : uint32_t frame_size;
530 : : int err;
531 : :
532 [ # # ]: 0 : if (rx_queue_id >= dev->data->nb_rx_queues)
533 : : return -EINVAL;
534 : :
535 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
536 : :
537 [ # # # # ]: 0 : if (rxq == NULL || !rxq->q_set) {
538 : 0 : PMD_DRV_LOG(ERR, "RX queue %u not available or setup",
539 : : rx_queue_id);
540 : 0 : return -EINVAL;
541 : : }
542 : :
543 : 0 : frame_size = dev->data->mtu + IDPF_ETH_OVERHEAD;
544 : :
545 : 0 : max_pkt_len =
546 : 0 : RTE_MIN((uint32_t)IDPF_SUPPORT_CHAIN_NUM * rxq->rx_buf_len,
547 : : frame_size);
548 : :
549 : 0 : rxq->max_pkt_len = max_pkt_len;
550 [ # # # # ]: 0 : if ((dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER) ||
551 : : frame_size > rxq->rx_buf_len)
552 : 0 : dev->data->scattered_rx = 1;
553 : :
554 : 0 : err = idpf_qc_ts_mbuf_register(rxq);
555 [ # # ]: 0 : if (err != 0) {
556 : 0 : PMD_DRV_LOG(ERR, "fail to residter timestamp mbuf %u",
557 : : rx_queue_id);
558 : 0 : return -EIO;
559 : : }
560 : :
561 [ # # ]: 0 : if (rxq->adapter->is_rx_singleq) {
562 : : /* Single queue */
563 : 0 : err = idpf_qc_single_rxq_mbufs_alloc(rxq);
564 [ # # ]: 0 : if (err != 0) {
565 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate RX queue mbuf");
566 : 0 : return err;
567 : : }
568 : :
569 : : rte_wmb();
570 : :
571 : : /* Init the RX tail register. */
572 : 0 : IDPF_PCI_REG_WRITE(rxq->qrx_tail, rxq->nb_rx_desc - 1);
573 : : } else {
574 : : /* Split queue */
575 : 0 : err = idpf_qc_split_rxq_mbufs_alloc(rxq->bufq1);
576 [ # # ]: 0 : if (err != 0) {
577 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate RX buffer queue mbuf");
578 : 0 : return err;
579 : : }
580 : 0 : err = idpf_qc_split_rxq_mbufs_alloc(rxq->bufq2);
581 [ # # ]: 0 : if (err != 0) {
582 : 0 : PMD_DRV_LOG(ERR, "Failed to allocate RX buffer queue mbuf");
583 : 0 : return err;
584 : : }
585 : :
586 : : rte_wmb();
587 : :
588 : : /* Init the RX tail register. */
589 : 0 : IDPF_PCI_REG_WRITE(rxq->bufq1->qrx_tail, rxq->bufq1->rx_tail);
590 : 0 : IDPF_PCI_REG_WRITE(rxq->bufq2->qrx_tail, rxq->bufq2->rx_tail);
591 : : }
592 : :
593 : : return err;
594 : : }
595 : :
596 : : int
597 : 0 : idpf_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
598 : : {
599 : 0 : struct idpf_vport *vport = dev->data->dev_private;
600 : 0 : struct idpf_rx_queue *rxq =
601 : 0 : dev->data->rx_queues[rx_queue_id];
602 : : int err = 0;
603 : :
604 : 0 : err = idpf_vc_rxq_config(vport, rxq);
605 [ # # ]: 0 : if (err != 0) {
606 : 0 : PMD_DRV_LOG(ERR, "Fail to configure Rx queue %u", rx_queue_id);
607 : 0 : return err;
608 : : }
609 : :
610 : 0 : err = idpf_rx_queue_init(dev, rx_queue_id);
611 [ # # ]: 0 : if (err != 0) {
612 : 0 : PMD_DRV_LOG(ERR, "Failed to init RX queue %u",
613 : : rx_queue_id);
614 : 0 : return err;
615 : : }
616 : :
617 : : /* Ready to switch the queue on */
618 : 0 : err = idpf_vc_queue_switch(vport, rx_queue_id, true, true,
619 : : VIRTCHNL2_QUEUE_TYPE_RX);
620 [ # # ]: 0 : if (err != 0) {
621 : 0 : PMD_DRV_LOG(ERR, "Failed to switch RX queue %u on",
622 : : rx_queue_id);
623 : : } else {
624 : 0 : rxq->q_started = true;
625 : 0 : dev->data->rx_queue_state[rx_queue_id] =
626 : : RTE_ETH_QUEUE_STATE_STARTED;
627 : : }
628 : :
629 : : return err;
630 : : }
631 : :
632 : : int
633 : 0 : idpf_tx_queue_init(struct rte_eth_dev *dev, uint16_t tx_queue_id)
634 : : {
635 : : struct ci_tx_queue *txq;
636 : :
637 [ # # ]: 0 : if (tx_queue_id >= dev->data->nb_tx_queues)
638 : : return -EINVAL;
639 : :
640 : 0 : txq = dev->data->tx_queues[tx_queue_id];
641 : :
642 : : /* Init the RX tail register. */
643 : 0 : IDPF_PCI_REG_WRITE(txq->qtx_tail, 0);
644 : :
645 : 0 : return 0;
646 : : }
647 : :
648 : : int
649 : 0 : idpf_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
650 : : {
651 : 0 : struct idpf_vport *vport = dev->data->dev_private;
652 : 0 : struct ci_tx_queue *txq = dev->data->tx_queues[tx_queue_id];
653 : : int err = 0;
654 : :
655 : 0 : err = idpf_vc_txq_config(vport, txq);
656 [ # # ]: 0 : if (err != 0) {
657 : 0 : PMD_DRV_LOG(ERR, "Fail to configure Tx queue %u", tx_queue_id);
658 : 0 : return err;
659 : : }
660 : :
661 : 0 : err = idpf_tx_queue_init(dev, tx_queue_id);
662 [ # # ]: 0 : if (err != 0) {
663 : 0 : PMD_DRV_LOG(ERR, "Failed to init TX queue %u",
664 : : tx_queue_id);
665 : 0 : return err;
666 : : }
667 : :
668 : : /* Ready to switch the queue on */
669 : 0 : err = idpf_vc_queue_switch(vport, tx_queue_id, false, true,
670 : : VIRTCHNL2_QUEUE_TYPE_TX);
671 [ # # ]: 0 : if (err != 0) {
672 : 0 : PMD_DRV_LOG(ERR, "Failed to switch TX queue %u on",
673 : : tx_queue_id);
674 : : } else {
675 : 0 : dev->data->tx_queue_state[tx_queue_id] =
676 : : RTE_ETH_QUEUE_STATE_STARTED;
677 : : }
678 : :
679 : : return err;
680 : : }
681 : :
682 : : int
683 : 0 : idpf_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
684 : : {
685 : 0 : struct idpf_vport *vport = dev->data->dev_private;
686 : : struct idpf_rx_queue *rxq;
687 : : int err;
688 : :
689 [ # # ]: 0 : if (rx_queue_id >= dev->data->nb_rx_queues)
690 : : return -EINVAL;
691 : :
692 : 0 : err = idpf_vc_queue_switch(vport, rx_queue_id, true, false,
693 : : VIRTCHNL2_QUEUE_TYPE_RX);
694 [ # # ]: 0 : if (err != 0) {
695 : 0 : PMD_DRV_LOG(ERR, "Failed to switch RX queue %u off",
696 : : rx_queue_id);
697 : 0 : return err;
698 : : }
699 : :
700 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
701 : 0 : rxq->q_started = false;
702 [ # # ]: 0 : if (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE) {
703 : 0 : rxq->idpf_ops->release_mbufs(rxq);
704 : 0 : idpf_qc_single_rx_queue_reset(rxq);
705 : : } else {
706 : 0 : rxq->bufq1->idpf_ops->release_mbufs(rxq->bufq1);
707 : 0 : rxq->bufq2->idpf_ops->release_mbufs(rxq->bufq2);
708 : 0 : idpf_qc_split_rx_queue_reset(rxq);
709 : : }
710 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
711 : :
712 : 0 : return 0;
713 : : }
714 : :
715 : : int
716 : 0 : idpf_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
717 : : {
718 : 0 : struct idpf_vport *vport = dev->data->dev_private;
719 : : struct ci_tx_queue *txq;
720 : : int err;
721 : :
722 [ # # ]: 0 : if (tx_queue_id >= dev->data->nb_tx_queues)
723 : : return -EINVAL;
724 : :
725 : 0 : err = idpf_vc_queue_switch(vport, tx_queue_id, false, false,
726 : : VIRTCHNL2_QUEUE_TYPE_TX);
727 [ # # ]: 0 : if (err != 0) {
728 : 0 : PMD_DRV_LOG(ERR, "Failed to switch TX queue %u off",
729 : : tx_queue_id);
730 : 0 : return err;
731 : : }
732 : :
733 : 0 : txq = dev->data->tx_queues[tx_queue_id];
734 [ # # ]: 0 : if (vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE) {
735 : 0 : ci_txq_release_all_mbufs(txq, false);
736 : 0 : idpf_qc_single_tx_queue_reset(txq);
737 : : } else {
738 : 0 : idpf_qc_split_tx_descq_reset(txq);
739 : 0 : idpf_qc_split_tx_complq_reset(txq->complq);
740 : : }
741 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
742 : :
743 : 0 : return 0;
744 : : }
745 : :
746 : : void
747 : 0 : idpf_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
748 : : {
749 : 0 : idpf_qc_rx_queue_release(dev->data->rx_queues[qid]);
750 : 0 : }
751 : :
752 : : void
753 : 0 : idpf_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
754 : : {
755 : 0 : idpf_qc_tx_queue_release(dev->data->tx_queues[qid]);
756 : 0 : }
757 : :
758 : : void
759 : 0 : idpf_stop_queues(struct rte_eth_dev *dev)
760 : : {
761 : : struct idpf_rx_queue *rxq;
762 : : struct ci_tx_queue *txq;
763 : : int i;
764 : :
765 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
766 : 0 : rxq = dev->data->rx_queues[i];
767 [ # # ]: 0 : if (rxq == NULL)
768 : 0 : continue;
769 : :
770 [ # # ]: 0 : if (idpf_rx_queue_stop(dev, i) != 0)
771 : 0 : PMD_DRV_LOG(WARNING, "Fail to stop Rx queue %d", i);
772 : : }
773 : :
774 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
775 : 0 : txq = dev->data->tx_queues[i];
776 [ # # ]: 0 : if (txq == NULL)
777 : 0 : continue;
778 : :
779 [ # # ]: 0 : if (idpf_tx_queue_stop(dev, i) != 0)
780 : 0 : PMD_DRV_LOG(WARNING, "Fail to stop Tx queue %d", i);
781 : : }
782 : 0 : }
783 : :
784 : : void
785 : 0 : idpf_set_rx_function(struct rte_eth_dev *dev)
786 : : {
787 : 0 : struct idpf_vport *vport = dev->data->dev_private;
788 : 0 : struct idpf_adapter *ad = vport->adapter;
789 : 0 : struct ci_rx_path_features req_features = {
790 : 0 : .rx_offloads = dev->data->dev_conf.rxmode.offloads,
791 : : .simd_width = RTE_VECT_SIMD_DISABLED,
792 : : };
793 : : #ifdef RTE_ARCH_X86
794 : : struct idpf_rx_queue *rxq;
795 : : int i;
796 : : #endif
797 : :
798 : : /* If the device has started the function has already been selected. */
799 [ # # ]: 0 : if (dev->data->dev_started)
800 : 0 : goto out;
801 : :
802 : : #ifdef RTE_ARCH_X86
803 [ # # # # ]: 0 : if (idpf_rx_vec_dev_check_default(dev) == IDPF_VECTOR_PATH &&
804 : 0 : rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256)
805 : 0 : req_features.simd_width = idpf_get_max_simd_bitwidth();
806 : : #endif
807 : :
808 : 0 : req_features.single_queue = (vport->rxq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE);
809 : 0 : req_features.scattered = dev->data->scattered_rx;
810 : :
811 : 0 : ad->rx_func_type = ci_rx_path_select(&req_features,
812 : : &idpf_rx_path_infos[0],
813 : : IDPF_RX_MAX,
814 : : IDPF_RX_DEFAULT);
815 : :
816 : : #ifdef RTE_ARCH_X86
817 [ # # ]: 0 : if (idpf_rx_path_infos[ad->rx_func_type].features.simd_width >= RTE_VECT_SIMD_256) {
818 : : /* Vector function selected. Prepare the rxq accordingly. */
819 [ # # ]: 0 : if (idpf_rx_path_infos[ad->rx_func_type].features.single_queue) {
820 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
821 : 0 : rxq = dev->data->rx_queues[i];
822 : 0 : (void)idpf_qc_singleq_rx_vec_setup(rxq);
823 : : }
824 : : } else {
825 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
826 : 0 : rxq = dev->data->rx_queues[i];
827 : 0 : (void)idpf_qc_splitq_rx_vec_setup(rxq);
828 : : }
829 : : }
830 : :
831 : : }
832 : : #endif
833 : :
834 : 0 : out:
835 : 0 : dev->rx_pkt_burst = idpf_rx_path_infos[ad->rx_func_type].pkt_burst;
836 : 0 : PMD_DRV_LOG(DEBUG, "Using %s Rx (port %d).",
837 : : idpf_rx_path_infos[ad->rx_func_type].info, dev->data->port_id);
838 : :
839 : 0 : }
840 : :
841 : : static bool
842 : 0 : idpf_tx_simple_allowed(struct rte_eth_dev *dev)
843 : : {
844 : 0 : struct idpf_vport *vport = dev->data->dev_private;
845 : : struct ci_tx_queue *txq;
846 : :
847 [ # # ]: 0 : if (vport->txq_model != VIRTCHNL2_QUEUE_MODEL_SINGLE)
848 : : return false;
849 : :
850 [ # # ]: 0 : for (int i = 0; i < dev->data->nb_tx_queues; i++) {
851 : 0 : txq = dev->data->tx_queues[i];
852 [ # # ]: 0 : if (txq == NULL)
853 : 0 : continue;
854 [ # # ]: 0 : if (txq->offloads != (txq->offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE) ||
855 [ # # ]: 0 : txq->tx_rs_thresh < IDPF_VPMD_TX_MAX_BURST)
856 : : return false;
857 : : }
858 : : return true;
859 : : }
860 : :
861 : : void
862 : 0 : idpf_set_tx_function(struct rte_eth_dev *dev)
863 : : {
864 : 0 : struct idpf_vport *vport = dev->data->dev_private;
865 : : struct ci_tx_queue *txq;
866 : : int i;
867 : 0 : struct idpf_adapter *ad = vport->adapter;
868 : 0 : bool simple_allowed = idpf_tx_simple_allowed(dev);
869 : 0 : struct ci_tx_path_features req_features = {
870 : 0 : .tx_offloads = dev->data->dev_conf.txmode.offloads,
871 : : .simd_width = RTE_VECT_SIMD_DISABLED,
872 : 0 : .single_queue = (vport->txq_model == VIRTCHNL2_QUEUE_MODEL_SINGLE),
873 : : .simple_tx = simple_allowed
874 : : };
875 : :
876 : : /* If the device has started the function has already been selected. */
877 [ # # ]: 0 : if (dev->data->dev_started)
878 : 0 : goto out;
879 : :
880 : : #ifdef RTE_ARCH_X86
881 [ # # ]: 0 : if (idpf_tx_vec_dev_check_default(dev) == IDPF_VECTOR_PATH)
882 : 0 : req_features.simd_width = idpf_get_max_simd_bitwidth();
883 : : #endif
884 : :
885 : 0 : ad->tx_func_type = ci_tx_path_select(&req_features,
886 : : &idpf_tx_path_infos[0],
887 : : IDPF_TX_MAX,
888 : : IDPF_TX_DEFAULT,
889 : : false);
890 : :
891 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
892 : 0 : txq = dev->data->tx_queues[i];
893 [ # # ]: 0 : if (txq == NULL)
894 : 0 : continue;
895 : 0 : txq->use_vec_entry = (ad->tx_func_type != IDPF_TX_SINGLEQ &&
896 : : ad->tx_func_type != IDPF_TX_DEFAULT);
897 : : }
898 : :
899 : 0 : out:
900 : 0 : dev->tx_pkt_burst = idpf_tx_path_infos[ad->tx_func_type].pkt_burst;
901 : 0 : dev->tx_pkt_prepare = idpf_dp_prep_pkts;
902 : 0 : PMD_DRV_LOG(DEBUG, "Using %s Tx (port %d).",
903 : : idpf_tx_path_infos[ad->tx_func_type].info, dev->data->port_id);
904 : 0 : }
|