Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018-2021 HiSilicon Limited.
3 : : */
4 : :
5 : : #include <bus_pci_driver.h>
6 : : #include <rte_common.h>
7 : : #include <rte_cycles.h>
8 : : #include <rte_geneve.h>
9 : : #include <rte_vxlan.h>
10 : : #include <ethdev_driver.h>
11 : : #include <rte_io.h>
12 : : #include <rte_net.h>
13 : : #include <rte_malloc.h>
14 : : #include <rte_net_crc.h>
15 : : #if defined(RTE_ARCH_ARM64)
16 : : #include <rte_cpuflags.h>
17 : : #include <rte_vect.h>
18 : : #endif
19 : :
20 : : #include "hns3_common.h"
21 : : #include "hns3_regs.h"
22 : : #include "hns3_logs.h"
23 : : #include "hns3_mp.h"
24 : : #include "hns3_rxtx.h"
25 : :
26 : : #define HNS3_CFG_DESC_NUM(num) ((num) / 8 - 1)
27 : : #define HNS3_RX_RING_PREFETCTH_MASK 3
28 : :
29 : : static void
30 : 0 : hns3_rx_queue_release_mbufs(struct hns3_rx_queue *rxq)
31 : : {
32 : : uint16_t i;
33 : :
34 : : /* Note: Fake rx queue will not enter here */
35 [ # # ]: 0 : if (rxq->sw_ring == NULL)
36 : : return;
37 : :
38 [ # # ]: 0 : if (rxq->rx_rearm_nb == 0) {
39 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
40 [ # # ]: 0 : if (rxq->sw_ring[i].mbuf != NULL) {
41 : : rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
42 : 0 : rxq->sw_ring[i].mbuf = NULL;
43 : : }
44 : : }
45 : : } else {
46 : 0 : for (i = rxq->next_to_use;
47 [ # # ]: 0 : i != rxq->rx_rearm_start;
48 : 0 : i = (i + 1) % rxq->nb_rx_desc) {
49 [ # # ]: 0 : if (rxq->sw_ring[i].mbuf != NULL) {
50 : : rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
51 : 0 : rxq->sw_ring[i].mbuf = NULL;
52 : : }
53 : : }
54 [ # # ]: 0 : for (i = 0; i < rxq->rx_rearm_nb; i++)
55 : 0 : rxq->sw_ring[(rxq->rx_rearm_start + i) % rxq->nb_rx_desc].mbuf = NULL;
56 : : }
57 : :
58 [ # # ]: 0 : for (i = 0; i < rxq->bulk_mbuf_num; i++)
59 : 0 : rte_pktmbuf_free_seg(rxq->bulk_mbuf[i]);
60 : 0 : rxq->bulk_mbuf_num = 0;
61 : :
62 [ # # ]: 0 : if (rxq->pkt_first_seg) {
63 : 0 : rte_pktmbuf_free(rxq->pkt_first_seg);
64 : 0 : rxq->pkt_first_seg = NULL;
65 : : }
66 : : }
67 : :
68 : : static void
69 : 0 : hns3_tx_queue_release_mbufs(struct hns3_tx_queue *txq)
70 : : {
71 : : uint16_t i;
72 : :
73 : : /* Note: Fake tx queue will not enter here */
74 [ # # ]: 0 : if (txq->sw_ring) {
75 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
76 [ # # ]: 0 : if (txq->sw_ring[i].mbuf) {
77 : : rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
78 : 0 : txq->sw_ring[i].mbuf = NULL;
79 : : }
80 : : }
81 : : }
82 : 0 : }
83 : :
84 : : static void
85 : 0 : hns3_rx_queue_release(void *queue)
86 : : {
87 : : struct hns3_rx_queue *rxq = queue;
88 [ # # ]: 0 : if (rxq) {
89 : 0 : hns3_rx_queue_release_mbufs(rxq);
90 [ # # ]: 0 : if (rxq->mz) {
91 : 0 : rte_memzone_free(rxq->mz);
92 : 0 : rxq->mz = NULL;
93 : : }
94 [ # # ]: 0 : if (rxq->sw_ring) {
95 : 0 : rte_free(rxq->sw_ring);
96 : 0 : rxq->sw_ring = NULL;
97 : : }
98 [ # # ]: 0 : if (rxq->crc_ctx) {
99 : 0 : rte_net_crc_free(rxq->crc_ctx);
100 : 0 : rxq->crc_ctx = NULL;
101 : : }
102 : 0 : rte_free(rxq);
103 : : }
104 : 0 : }
105 : :
106 : : static void
107 : 0 : hns3_tx_queue_release(void *queue)
108 : : {
109 : : struct hns3_tx_queue *txq = queue;
110 [ # # ]: 0 : if (txq) {
111 : 0 : hns3_tx_queue_release_mbufs(txq);
112 [ # # ]: 0 : if (txq->mz) {
113 : 0 : rte_memzone_free(txq->mz);
114 : 0 : txq->mz = NULL;
115 : : }
116 [ # # ]: 0 : if (txq->sw_ring) {
117 : 0 : rte_free(txq->sw_ring);
118 : 0 : txq->sw_ring = NULL;
119 : : }
120 [ # # ]: 0 : if (txq->free) {
121 : 0 : rte_free(txq->free);
122 : 0 : txq->free = NULL;
123 : : }
124 : 0 : rte_free(txq);
125 : : }
126 : 0 : }
127 : :
128 : : static void
129 : 0 : hns3_rx_queue_release_lock(void *queue)
130 : : {
131 : : struct hns3_rx_queue *rxq = queue;
132 : : struct hns3_adapter *hns;
133 : :
134 [ # # ]: 0 : if (rxq == NULL)
135 : : return;
136 : :
137 : 0 : hns = rxq->hns;
138 : 0 : rte_spinlock_lock(&hns->hw.lock);
139 : 0 : hns3_rx_queue_release(queue);
140 : : rte_spinlock_unlock(&hns->hw.lock);
141 : : }
142 : :
143 : : void
144 : 0 : hns3_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t queue_id)
145 : : {
146 : 0 : hns3_rx_queue_release_lock(dev->data->rx_queues[queue_id]);
147 : 0 : }
148 : :
149 : : static void
150 : 0 : hns3_tx_queue_release_lock(void *queue)
151 : : {
152 : : struct hns3_tx_queue *txq = queue;
153 : : struct hns3_adapter *hns;
154 : :
155 [ # # ]: 0 : if (txq == NULL)
156 : : return;
157 : :
158 : 0 : hns = txq->hns;
159 : 0 : rte_spinlock_lock(&hns->hw.lock);
160 : 0 : hns3_tx_queue_release(queue);
161 : : rte_spinlock_unlock(&hns->hw.lock);
162 : : }
163 : :
164 : : void
165 : 0 : hns3_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t queue_id)
166 : : {
167 : 0 : hns3_tx_queue_release_lock(dev->data->tx_queues[queue_id]);
168 : 0 : }
169 : :
170 : : static void
171 : 0 : hns3_fake_rx_queue_release(struct hns3_rx_queue *queue)
172 : : {
173 : : struct hns3_rx_queue *rxq = queue;
174 : : struct hns3_adapter *hns;
175 : : struct hns3_hw *hw;
176 : : uint16_t idx;
177 : :
178 [ # # ]: 0 : if (rxq == NULL)
179 : : return;
180 : :
181 : 0 : hns = rxq->hns;
182 : : hw = &hns->hw;
183 : 0 : idx = rxq->queue_id;
184 [ # # ]: 0 : if (hw->fkq_data.rx_queues[idx]) {
185 : 0 : hns3_rx_queue_release(hw->fkq_data.rx_queues[idx]);
186 : 0 : hw->fkq_data.rx_queues[idx] = NULL;
187 : : }
188 : :
189 : : /* free fake rx queue arrays */
190 [ # # ]: 0 : if (idx == hw->fkq_data.nb_fake_rx_queues - 1) {
191 : 0 : hw->fkq_data.nb_fake_rx_queues = 0;
192 : 0 : rte_free(hw->fkq_data.rx_queues);
193 : 0 : hw->fkq_data.rx_queues = NULL;
194 : : }
195 : : }
196 : :
197 : : static void
198 : 0 : hns3_fake_tx_queue_release(struct hns3_tx_queue *queue)
199 : : {
200 : : struct hns3_tx_queue *txq = queue;
201 : : struct hns3_adapter *hns;
202 : : struct hns3_hw *hw;
203 : : uint16_t idx;
204 : :
205 [ # # ]: 0 : if (txq == NULL)
206 : : return;
207 : :
208 : 0 : hns = txq->hns;
209 : : hw = &hns->hw;
210 : 0 : idx = txq->queue_id;
211 [ # # ]: 0 : if (hw->fkq_data.tx_queues[idx]) {
212 : 0 : hns3_tx_queue_release(hw->fkq_data.tx_queues[idx]);
213 : 0 : hw->fkq_data.tx_queues[idx] = NULL;
214 : : }
215 : :
216 : : /* free fake tx queue arrays */
217 [ # # ]: 0 : if (idx == hw->fkq_data.nb_fake_tx_queues - 1) {
218 : 0 : hw->fkq_data.nb_fake_tx_queues = 0;
219 : 0 : rte_free(hw->fkq_data.tx_queues);
220 : 0 : hw->fkq_data.tx_queues = NULL;
221 : : }
222 : : }
223 : :
224 : : static void
225 : 0 : hns3_free_rx_queues(struct rte_eth_dev *dev)
226 : : {
227 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
228 : : struct hns3_fake_queue_data *fkq_data;
229 : : struct hns3_hw *hw = &hns->hw;
230 : : uint16_t nb_rx_q;
231 : : uint16_t i;
232 : :
233 : 0 : nb_rx_q = hw->data->nb_rx_queues;
234 [ # # ]: 0 : for (i = 0; i < nb_rx_q; i++) {
235 [ # # ]: 0 : if (dev->data->rx_queues[i]) {
236 : 0 : hns3_rx_queue_release(dev->data->rx_queues[i]);
237 : 0 : dev->data->rx_queues[i] = NULL;
238 : : }
239 : : }
240 : :
241 : : /* Free fake Rx queues */
242 : : fkq_data = &hw->fkq_data;
243 [ # # ]: 0 : for (i = 0; i < fkq_data->nb_fake_rx_queues; i++) {
244 [ # # ]: 0 : if (fkq_data->rx_queues[i])
245 : 0 : hns3_fake_rx_queue_release(fkq_data->rx_queues[i]);
246 : : }
247 : 0 : }
248 : :
249 : : static void
250 : 0 : hns3_free_tx_queues(struct rte_eth_dev *dev)
251 : : {
252 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
253 : : struct hns3_fake_queue_data *fkq_data;
254 : : struct hns3_hw *hw = &hns->hw;
255 : : uint16_t nb_tx_q;
256 : : uint16_t i;
257 : :
258 : 0 : nb_tx_q = hw->data->nb_tx_queues;
259 [ # # ]: 0 : for (i = 0; i < nb_tx_q; i++) {
260 [ # # ]: 0 : if (dev->data->tx_queues[i]) {
261 : 0 : hns3_tx_queue_release(dev->data->tx_queues[i]);
262 : 0 : dev->data->tx_queues[i] = NULL;
263 : : }
264 : : }
265 : :
266 : : /* Free fake Tx queues */
267 : : fkq_data = &hw->fkq_data;
268 [ # # ]: 0 : for (i = 0; i < fkq_data->nb_fake_tx_queues; i++) {
269 [ # # ]: 0 : if (fkq_data->tx_queues[i])
270 : 0 : hns3_fake_tx_queue_release(fkq_data->tx_queues[i]);
271 : : }
272 : 0 : }
273 : :
274 : : void
275 : 0 : hns3_free_all_queues(struct rte_eth_dev *dev)
276 : : {
277 : 0 : hns3_free_rx_queues(dev);
278 : 0 : hns3_free_tx_queues(dev);
279 : 0 : }
280 : :
281 : : static int
282 : 0 : hns3_check_rx_dma_addr(struct hns3_hw *hw, uint64_t dma_addr)
283 : : {
284 : 0 : uint64_t rx_offload = hw->data->dev_conf.rxmode.offloads;
285 : : uint64_t rem;
286 : :
287 : 0 : rem = dma_addr & (hw->rx_dma_addr_align - 1);
288 [ # # ]: 0 : if (rem > 0) {
289 : 0 : hns3_err(hw,
290 : : "mbuf DMA address must be %u-byte aligned",
291 : : hw->rx_dma_addr_align);
292 : 0 : return -EINVAL;
293 : : }
294 : :
295 : : /*
296 : : * This check is for HIP08 network engine. The GRO function
297 : : * requires that mbuf DMA address is 64-byte aligned.
298 : : */
299 : 0 : rem = dma_addr & (HNS3_RX_DMA_ADDR_ALIGN_128 - 1);
300 [ # # # # ]: 0 : if ((rx_offload & RTE_ETH_RX_OFFLOAD_TCP_LRO) && rem > 0) {
301 : 0 : hns3_err(hw,
302 : : "GRO requires that mbuf DMA address be 64-byte aligned");
303 : 0 : return -EINVAL;
304 : : }
305 : : return 0;
306 : : }
307 : :
308 : : static int
309 : 0 : hns3_alloc_rx_queue_mbufs(struct hns3_hw *hw, struct hns3_rx_queue *rxq)
310 : : {
311 : : struct rte_mbuf *mbuf;
312 : : uint64_t dma_addr;
313 : : uint16_t i;
314 : : int ret;
315 : :
316 [ # # ]: 0 : for (i = 0; i < rxq->nb_rx_desc; i++) {
317 : 0 : mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
318 [ # # ]: 0 : if (unlikely(mbuf == NULL)) {
319 : 0 : hns3_err(hw, "Failed to allocate RXD[%u] for rx queue!",
320 : : i);
321 : 0 : hns3_rx_queue_release_mbufs(rxq);
322 : 0 : return -ENOMEM;
323 : : }
324 : :
325 : : rte_mbuf_refcnt_set(mbuf, 1);
326 : 0 : mbuf->next = NULL;
327 : 0 : mbuf->data_off = RTE_PKTMBUF_HEADROOM;
328 : 0 : mbuf->nb_segs = 1;
329 : 0 : mbuf->port = rxq->port_id;
330 : :
331 : 0 : rxq->sw_ring[i].mbuf = mbuf;
332 : : dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
333 : 0 : rxq->rx_ring[i].addr = dma_addr;
334 : 0 : rxq->rx_ring[i].rx.bd_base_info = 0;
335 : :
336 : 0 : ret = hns3_check_rx_dma_addr(hw, dma_addr);
337 [ # # ]: 0 : if (ret != 0) {
338 : 0 : hns3_rx_queue_release_mbufs(rxq);
339 : 0 : return ret;
340 : : }
341 : : }
342 : :
343 : : return 0;
344 : : }
345 : :
346 : : static int
347 : : hns3_buf_size2type(uint32_t buf_size)
348 : : {
349 : : int bd_size_type;
350 : :
351 [ # # # # ]: 0 : switch (buf_size) {
352 : : case 512:
353 : : bd_size_type = HNS3_BD_SIZE_512_TYPE;
354 : : break;
355 : 0 : case 1024:
356 : : bd_size_type = HNS3_BD_SIZE_1024_TYPE;
357 : 0 : break;
358 : 0 : case 4096:
359 : : bd_size_type = HNS3_BD_SIZE_4096_TYPE;
360 : 0 : break;
361 : 0 : default:
362 : : bd_size_type = HNS3_BD_SIZE_2048_TYPE;
363 : : }
364 : :
365 : : return bd_size_type;
366 : : }
367 : :
368 : : static void
369 : 0 : hns3_init_rx_queue_hw(struct hns3_rx_queue *rxq)
370 : : {
371 : 0 : uint32_t rx_buf_len = rxq->rx_buf_len;
372 : 0 : uint64_t dma_addr = rxq->rx_ring_phys_addr;
373 : :
374 : 0 : hns3_write_dev(rxq, HNS3_RING_RX_BASEADDR_L_REG, (uint32_t)dma_addr);
375 : 0 : hns3_write_dev(rxq, HNS3_RING_RX_BASEADDR_H_REG,
376 : : (uint32_t)(dma_addr >> 32));
377 : :
378 : 0 : hns3_write_dev(rxq, HNS3_RING_RX_BD_LEN_REG,
379 : : hns3_buf_size2type(rx_buf_len));
380 : 0 : hns3_write_dev(rxq, HNS3_RING_RX_BD_NUM_REG,
381 : : HNS3_CFG_DESC_NUM(rxq->nb_rx_desc));
382 : 0 : }
383 : :
384 : : static void
385 : : hns3_init_tx_queue_hw(struct hns3_tx_queue *txq)
386 : : {
387 : 0 : uint64_t dma_addr = txq->tx_ring_phys_addr;
388 : :
389 : 0 : hns3_write_dev(txq, HNS3_RING_TX_BASEADDR_L_REG, (uint32_t)dma_addr);
390 : 0 : hns3_write_dev(txq, HNS3_RING_TX_BASEADDR_H_REG,
391 : : (uint32_t)(dma_addr >> 32));
392 : :
393 : 0 : hns3_write_dev(txq, HNS3_RING_TX_BD_NUM_REG,
394 : : HNS3_CFG_DESC_NUM(txq->nb_tx_desc));
395 : : }
396 : :
397 : : void
398 : 0 : hns3_update_all_queues_pvid_proc_en(struct hns3_hw *hw)
399 : : {
400 : 0 : uint16_t nb_rx_q = hw->data->nb_rx_queues;
401 : 0 : uint16_t nb_tx_q = hw->data->nb_tx_queues;
402 : : struct hns3_rx_queue *rxq;
403 : : struct hns3_tx_queue *txq;
404 : : bool pvid_en;
405 : : int i;
406 : :
407 : 0 : pvid_en = hw->port_base_vlan_cfg.state == HNS3_PORT_BASE_VLAN_ENABLE;
408 [ # # ]: 0 : for (i = 0; i < hw->cfg_max_queues; i++) {
409 [ # # ]: 0 : if (i < nb_rx_q) {
410 : 0 : rxq = hw->data->rx_queues[i];
411 [ # # ]: 0 : if (rxq != NULL)
412 : 0 : rxq->pvid_sw_discard_en = pvid_en;
413 : : }
414 [ # # ]: 0 : if (i < nb_tx_q) {
415 : 0 : txq = hw->data->tx_queues[i];
416 [ # # ]: 0 : if (txq != NULL)
417 : 0 : txq->pvid_sw_shift_en = pvid_en;
418 : : }
419 : : }
420 : 0 : }
421 : :
422 : : static void
423 : : hns3_stop_unused_queue(void *tqp_base, enum hns3_ring_type queue_type)
424 : : {
425 : : uint32_t reg_offset;
426 : : uint32_t reg;
427 : :
428 : : reg_offset = queue_type == HNS3_RING_TYPE_TX ?
429 : : HNS3_RING_TX_EN_REG : HNS3_RING_RX_EN_REG;
430 : : reg = hns3_read_reg(tqp_base, reg_offset);
431 : 0 : reg &= ~BIT(HNS3_RING_EN_B);
432 : : hns3_write_reg(tqp_base, reg_offset, reg);
433 : 0 : }
434 : :
435 : : void
436 : 0 : hns3_enable_all_queues(struct hns3_hw *hw, bool en)
437 : : {
438 : 0 : uint16_t nb_rx_q = hw->data->nb_rx_queues;
439 : 0 : uint16_t nb_tx_q = hw->data->nb_tx_queues;
440 : : struct hns3_rx_queue *rxq;
441 : : struct hns3_tx_queue *txq;
442 : : uint32_t rcb_reg;
443 : : void *tqp_base;
444 : : uint16_t i;
445 : :
446 [ # # ]: 0 : for (i = 0; i < hw->cfg_max_queues; i++) {
447 [ # # ]: 0 : if (hns3_dev_get_support(hw, INDEP_TXRX)) {
448 [ # # ]: 0 : rxq = i < nb_rx_q ? hw->data->rx_queues[i] : NULL;
449 [ # # ]: 0 : txq = i < nb_tx_q ? hw->data->tx_queues[i] : NULL;
450 : :
451 : 0 : tqp_base = (void *)((char *)hw->io_base +
452 : 0 : hns3_get_tqp_reg_offset(i));
453 : : /*
454 : : * If queue struct is not initialized, it means the
455 : : * related HW ring has not been initialized yet.
456 : : * So, these queues should be disabled before enable
457 : : * the tqps to avoid a HW exception since the queues
458 : : * are enabled by default.
459 : : */
460 [ # # ]: 0 : if (rxq == NULL)
461 : : hns3_stop_unused_queue(tqp_base,
462 : : HNS3_RING_TYPE_RX);
463 [ # # ]: 0 : if (txq == NULL)
464 : : hns3_stop_unused_queue(tqp_base,
465 : : HNS3_RING_TYPE_TX);
466 : : } else {
467 [ # # ]: 0 : rxq = i < nb_rx_q ? hw->data->rx_queues[i] :
468 : 0 : hw->fkq_data.rx_queues[i - nb_rx_q];
469 : :
470 : 0 : tqp_base = rxq->io_base;
471 : : }
472 : : /*
473 : : * This is the master switch that used to control the enabling
474 : : * of a pair of Tx and Rx queues. Both the Rx and Tx point to
475 : : * the same register
476 : : */
477 : : rcb_reg = hns3_read_reg(tqp_base, HNS3_RING_EN_REG);
478 [ # # ]: 0 : if (en)
479 : 0 : rcb_reg |= BIT(HNS3_RING_EN_B);
480 : : else
481 : 0 : rcb_reg &= ~BIT(HNS3_RING_EN_B);
482 : : hns3_write_reg(tqp_base, HNS3_RING_EN_REG, rcb_reg);
483 : : }
484 : 0 : }
485 : :
486 : : static void
487 : : hns3_enable_txq(struct hns3_tx_queue *txq, bool en)
488 : : {
489 : 0 : struct hns3_hw *hw = &txq->hns->hw;
490 : : uint32_t reg;
491 : :
492 [ # # # # : 0 : if (hns3_dev_get_support(hw, INDEP_TXRX)) {
# # # # #
# ]
493 : 0 : reg = hns3_read_dev(txq, HNS3_RING_TX_EN_REG);
494 [ # # ]: 0 : if (en)
495 : 0 : reg |= BIT(HNS3_RING_EN_B);
496 : : else
497 : 0 : reg &= ~BIT(HNS3_RING_EN_B);
498 : 0 : hns3_write_dev(txq, HNS3_RING_TX_EN_REG, reg);
499 : : }
500 : 0 : txq->enabled = en;
501 : 0 : }
502 : :
503 : : static void
504 : : hns3_enable_rxq(struct hns3_rx_queue *rxq, bool en)
505 : : {
506 : 0 : struct hns3_hw *hw = &rxq->hns->hw;
507 : : uint32_t reg;
508 : :
509 [ # # # # : 0 : if (hns3_dev_get_support(hw, INDEP_TXRX)) {
# # # # ]
510 : 0 : reg = hns3_read_dev(rxq, HNS3_RING_RX_EN_REG);
511 [ # # ]: 0 : if (en)
512 : 0 : reg |= BIT(HNS3_RING_EN_B);
513 : : else
514 : 0 : reg &= ~BIT(HNS3_RING_EN_B);
515 : 0 : hns3_write_dev(rxq, HNS3_RING_RX_EN_REG, reg);
516 : : }
517 : 0 : rxq->enabled = en;
518 : 0 : }
519 : :
520 : : int
521 : 0 : hns3_start_all_txqs(struct rte_eth_dev *dev)
522 : : {
523 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
524 : : struct hns3_tx_queue *txq;
525 : : uint16_t i, j;
526 : :
527 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
528 : 0 : txq = hw->data->tx_queues[i];
529 [ # # ]: 0 : if (!txq) {
530 : 0 : hns3_err(hw, "Tx queue %u not available or setup.", i);
531 : 0 : goto start_txqs_fail;
532 : : }
533 : : /*
534 : : * Tx queue is enabled by default. Therefore, the Tx queues
535 : : * needs to be disabled when deferred_start is set. There is
536 : : * another master switch used to control the enabling of a pair
537 : : * of Tx and Rx queues. And the master switch is disabled by
538 : : * default.
539 : : */
540 [ # # ]: 0 : if (txq->tx_deferred_start)
541 : : hns3_enable_txq(txq, false);
542 : : else
543 : : hns3_enable_txq(txq, true);
544 : : }
545 : : return 0;
546 : :
547 : : start_txqs_fail:
548 [ # # ]: 0 : for (j = 0; j < i; j++) {
549 [ # # ]: 0 : txq = hw->data->tx_queues[j];
550 : : hns3_enable_txq(txq, false);
551 : : }
552 : : return -EINVAL;
553 : : }
554 : :
555 : : int
556 : 0 : hns3_start_all_rxqs(struct rte_eth_dev *dev)
557 : : {
558 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
559 : : struct hns3_rx_queue *rxq;
560 : : uint16_t i, j;
561 : :
562 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
563 : 0 : rxq = hw->data->rx_queues[i];
564 [ # # ]: 0 : if (!rxq) {
565 : 0 : hns3_err(hw, "Rx queue %u not available or setup.", i);
566 : 0 : goto start_rxqs_fail;
567 : : }
568 : : /*
569 : : * Rx queue is enabled by default. Therefore, the Rx queues
570 : : * needs to be disabled when deferred_start is set. There is
571 : : * another master switch used to control the enabling of a pair
572 : : * of Tx and Rx queues. And the master switch is disabled by
573 : : * default.
574 : : */
575 [ # # ]: 0 : if (rxq->rx_deferred_start)
576 : : hns3_enable_rxq(rxq, false);
577 : : else
578 : : hns3_enable_rxq(rxq, true);
579 : : }
580 : : return 0;
581 : :
582 : : start_rxqs_fail:
583 [ # # ]: 0 : for (j = 0; j < i; j++) {
584 [ # # ]: 0 : rxq = hw->data->rx_queues[j];
585 : : hns3_enable_rxq(rxq, false);
586 : : }
587 : : return -EINVAL;
588 : : }
589 : :
590 : : void
591 : 0 : hns3_restore_tqp_enable_state(struct hns3_hw *hw)
592 : : {
593 : : struct hns3_rx_queue *rxq;
594 : : struct hns3_tx_queue *txq;
595 : : uint16_t i;
596 : :
597 [ # # ]: 0 : for (i = 0; i < hw->data->nb_rx_queues; i++) {
598 : 0 : rxq = hw->data->rx_queues[i];
599 [ # # ]: 0 : if (rxq != NULL)
600 [ # # ]: 0 : hns3_enable_rxq(rxq, rxq->enabled);
601 : : }
602 : :
603 [ # # ]: 0 : for (i = 0; i < hw->data->nb_tx_queues; i++) {
604 : 0 : txq = hw->data->tx_queues[i];
605 [ # # ]: 0 : if (txq != NULL)
606 [ # # ]: 0 : hns3_enable_txq(txq, txq->enabled);
607 : : }
608 : 0 : }
609 : :
610 : : void
611 : 0 : hns3_stop_all_txqs(struct rte_eth_dev *dev)
612 : : {
613 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
614 : : struct hns3_tx_queue *txq;
615 : : uint16_t i;
616 : :
617 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
618 : 0 : txq = hw->data->tx_queues[i];
619 [ # # ]: 0 : if (!txq)
620 : 0 : continue;
621 : : hns3_enable_txq(txq, false);
622 : : }
623 : 0 : }
624 : :
625 : : static int
626 : 0 : hns3_tqp_enable(struct hns3_hw *hw, uint16_t queue_id, bool enable)
627 : : {
628 : : struct hns3_cfg_com_tqp_queue_cmd *req;
629 : : struct hns3_cmd_desc desc;
630 : : int ret;
631 : :
632 : : req = (struct hns3_cfg_com_tqp_queue_cmd *)desc.data;
633 : :
634 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_COM_TQP_QUEUE, false);
635 : 0 : req->tqp_id = rte_cpu_to_le_16(queue_id);
636 : 0 : req->stream_id = 0;
637 : 0 : hns3_set_bit(req->enable, HNS3_TQP_ENABLE_B, enable ? 1 : 0);
638 : :
639 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
640 [ # # ]: 0 : if (ret)
641 [ # # ]: 0 : hns3_err(hw, "TQP %s fail, ret = %d", enable ? "enable" : "disable", ret);
642 : :
643 : 0 : return ret;
644 : : }
645 : :
646 : : static int
647 : 0 : hns3_send_reset_tqp_cmd(struct hns3_hw *hw, uint16_t queue_id, bool enable)
648 : : {
649 : : struct hns3_reset_tqp_queue_cmd *req;
650 : : struct hns3_cmd_desc desc;
651 : : int ret;
652 : :
653 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RESET_TQP_QUEUE, false);
654 : :
655 : : req = (struct hns3_reset_tqp_queue_cmd *)desc.data;
656 : 0 : req->tqp_id = rte_cpu_to_le_16(queue_id);
657 : 0 : hns3_set_bit(req->reset_req, HNS3_TQP_RESET_B, enable ? 1 : 0);
658 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
659 [ # # ]: 0 : if (ret)
660 : 0 : hns3_err(hw, "send tqp reset cmd error, queue_id = %u, ret = %d",
661 : : queue_id, ret);
662 : :
663 : 0 : return ret;
664 : : }
665 : :
666 : : static int
667 : 0 : hns3_get_tqp_reset_status(struct hns3_hw *hw, uint16_t queue_id,
668 : : uint8_t *reset_status)
669 : : {
670 : : struct hns3_reset_tqp_queue_cmd *req;
671 : : struct hns3_cmd_desc desc;
672 : : int ret;
673 : :
674 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RESET_TQP_QUEUE, true);
675 : :
676 : : req = (struct hns3_reset_tqp_queue_cmd *)desc.data;
677 : 0 : req->tqp_id = rte_cpu_to_le_16(queue_id);
678 : :
679 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
680 [ # # ]: 0 : if (ret) {
681 : 0 : hns3_err(hw, "get tqp reset status error, queue_id = %u, ret = %d.",
682 : : queue_id, ret);
683 : 0 : return ret;
684 : : }
685 : 0 : *reset_status = hns3_get_bit(req->ready_to_reset, HNS3_TQP_RESET_B);
686 : 0 : return ret;
687 : : }
688 : :
689 : : static int
690 : 0 : hns3pf_reset_tqp(struct hns3_hw *hw, uint16_t queue_id)
691 : : {
692 : : #define HNS3_TQP_RESET_TRY_MS 200
693 : : uint16_t wait_time = 0;
694 : : uint8_t reset_status;
695 : : int ret;
696 : :
697 : : /*
698 : : * In current version VF is not supported when PF is driven by DPDK
699 : : * driver, all task queue pairs are mapped to PF function, so PF's queue
700 : : * id is equals to the global queue id in PF range.
701 : : */
702 : 0 : ret = hns3_send_reset_tqp_cmd(hw, queue_id, true);
703 [ # # ]: 0 : if (ret) {
704 : 0 : hns3_err(hw, "Send reset tqp cmd fail, ret = %d", ret);
705 : 0 : return ret;
706 : : }
707 : :
708 : : do {
709 : : /* Wait for tqp hw reset */
710 : : rte_delay_ms(HNS3_POLL_RESPONE_MS);
711 : 0 : wait_time += HNS3_POLL_RESPONE_MS;
712 : 0 : ret = hns3_get_tqp_reset_status(hw, queue_id, &reset_status);
713 [ # # ]: 0 : if (ret)
714 : 0 : goto tqp_reset_fail;
715 : :
716 [ # # ]: 0 : if (reset_status)
717 : : break;
718 [ # # ]: 0 : } while (wait_time < HNS3_TQP_RESET_TRY_MS);
719 : :
720 [ # # ]: 0 : if (!reset_status) {
721 : : ret = -ETIMEDOUT;
722 : 0 : hns3_err(hw, "reset tqp timeout, queue_id = %u, ret = %d",
723 : : queue_id, ret);
724 : 0 : goto tqp_reset_fail;
725 : : }
726 : :
727 : 0 : ret = hns3_send_reset_tqp_cmd(hw, queue_id, false);
728 [ # # ]: 0 : if (ret)
729 : 0 : hns3_err(hw, "Deassert the soft reset fail, ret = %d", ret);
730 : :
731 : : return ret;
732 : :
733 : 0 : tqp_reset_fail:
734 : 0 : hns3_send_reset_tqp_cmd(hw, queue_id, false);
735 : 0 : return ret;
736 : : }
737 : :
738 : : static int
739 : 0 : hns3vf_reset_tqp(struct hns3_hw *hw, uint16_t queue_id)
740 : : {
741 : : struct hns3_vf_to_pf_msg req;
742 : : int ret;
743 : :
744 : 0 : hns3vf_mbx_setup(&req, HNS3_MBX_QUEUE_RESET, 0);
745 : : memcpy(req.data, &queue_id, sizeof(uint16_t));
746 : 0 : ret = hns3vf_mbx_send(hw, &req, true, NULL, 0);
747 [ # # ]: 0 : if (ret)
748 : 0 : hns3_err(hw, "fail to reset tqp, queue_id = %u, ret = %d.",
749 : : queue_id, ret);
750 : 0 : return ret;
751 : : }
752 : :
753 : : static int
754 : 0 : hns3_reset_rcb_cmd(struct hns3_hw *hw, uint8_t *reset_status)
755 : : {
756 : : struct hns3_reset_cmd *req;
757 : : struct hns3_cmd_desc desc;
758 : : int ret;
759 : :
760 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_CFG_RST_TRIGGER, false);
761 : : req = (struct hns3_reset_cmd *)desc.data;
762 : 0 : hns3_set_bit(req->fun_reset_rcb, HNS3_CFG_RESET_RCB_B, 1);
763 : :
764 : : /*
765 : : * The start qid should be the global qid of the first tqp of the
766 : : * function which should be reset in this port. Since our PF not
767 : : * support take over of VFs, so we only need to reset function 0,
768 : : * and its start qid is always 0.
769 : : */
770 : 0 : req->fun_reset_rcb_vqid_start = rte_cpu_to_le_16(0);
771 : 0 : req->fun_reset_rcb_vqid_num = rte_cpu_to_le_16(hw->cfg_max_queues);
772 : :
773 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
774 [ # # ]: 0 : if (ret) {
775 : 0 : hns3_err(hw, "fail to send rcb reset cmd, ret = %d.", ret);
776 : 0 : return ret;
777 : : }
778 : :
779 : 0 : *reset_status = req->fun_reset_rcb_return_status;
780 : 0 : return 0;
781 : : }
782 : :
783 : : static int
784 : 0 : hns3pf_reset_all_tqps(struct hns3_hw *hw)
785 : : {
786 : : #define HNS3_RESET_RCB_NOT_SUPPORT 0U
787 : : #define HNS3_RESET_ALL_TQP_SUCCESS 1U
788 : : uint8_t reset_status;
789 : : uint16_t i;
790 : : int ret;
791 : :
792 : 0 : ret = hns3_reset_rcb_cmd(hw, &reset_status);
793 [ # # ]: 0 : if (ret)
794 : : return ret;
795 : :
796 : : /*
797 : : * If the firmware version is low, it may not support the rcb reset
798 : : * which means reset all the tqps at a time. In this case, we should
799 : : * reset tqps one by one.
800 : : */
801 [ # # ]: 0 : if (reset_status == HNS3_RESET_RCB_NOT_SUPPORT) {
802 [ # # ]: 0 : for (i = 0; i < hw->cfg_max_queues; i++) {
803 : 0 : ret = hns3pf_reset_tqp(hw, i);
804 [ # # ]: 0 : if (ret) {
805 : 0 : hns3_err(hw, "fail to reset tqp, queue_id = %u, ret = %d.",
806 : : i, ret);
807 : 0 : return ret;
808 : : }
809 : : }
810 [ # # ]: 0 : } else if (reset_status != HNS3_RESET_ALL_TQP_SUCCESS) {
811 : 0 : hns3_err(hw, "fail to reset all tqps, reset_status = %u.",
812 : : reset_status);
813 : 0 : return -EIO;
814 : : }
815 : :
816 : : return 0;
817 : : }
818 : :
819 : : static int
820 : 0 : hns3vf_reset_all_tqps(struct hns3_hw *hw)
821 : : {
822 : : #define HNS3VF_RESET_ALL_TQP_DONE 1U
823 : : struct hns3_vf_to_pf_msg req;
824 : : uint8_t reset_status;
825 : : int ret;
826 : : uint16_t i;
827 : :
828 : 0 : hns3vf_mbx_setup(&req, HNS3_MBX_QUEUE_RESET, 0);
829 : 0 : ret = hns3vf_mbx_send(hw, &req, true,
830 : : &reset_status, sizeof(reset_status));
831 [ # # ]: 0 : if (ret) {
832 : 0 : hns3_err(hw, "fail to send rcb reset mbx, ret = %d.", ret);
833 : 0 : return ret;
834 : : }
835 : :
836 [ # # ]: 0 : if (reset_status == HNS3VF_RESET_ALL_TQP_DONE)
837 : : return 0;
838 : :
839 : : /*
840 : : * If the firmware version or kernel PF version is low, it may not
841 : : * support the rcb reset which means reset all the tqps at a time.
842 : : * In this case, we should reset tqps one by one.
843 : : */
844 [ # # ]: 0 : for (i = 1; i < hw->cfg_max_queues; i++) {
845 : 0 : ret = hns3vf_reset_tqp(hw, i);
846 [ # # ]: 0 : if (ret)
847 : 0 : return ret;
848 : : }
849 : :
850 : : return 0;
851 : : }
852 : :
853 : : int
854 : 0 : hns3_reset_all_tqps(struct hns3_adapter *hns)
855 : : {
856 : 0 : struct hns3_hw *hw = &hns->hw;
857 : : uint16_t i;
858 : : int ret;
859 : :
860 : : /* Disable all queues before reset all queues */
861 [ # # ]: 0 : for (i = 0; i < hw->cfg_max_queues; i++) {
862 : 0 : ret = hns3_tqp_enable(hw, i, false);
863 [ # # ]: 0 : if (ret) {
864 : 0 : hns3_err(hw, "fail to disable tqps before tqps reset, ret = %d.",
865 : : ret);
866 : 0 : return ret;
867 : : }
868 : : }
869 : :
870 [ # # ]: 0 : if (hns->is_vf)
871 : 0 : return hns3vf_reset_all_tqps(hw);
872 : : else
873 : 0 : return hns3pf_reset_all_tqps(hw);
874 : : }
875 : :
876 : : static int
877 : 0 : hns3_send_reset_queue_cmd(struct hns3_hw *hw, uint16_t queue_id,
878 : : enum hns3_ring_type queue_type, bool enable)
879 : : {
880 : : struct hns3_reset_tqp_queue_cmd *req;
881 : : struct hns3_cmd_desc desc;
882 : : int ret;
883 : :
884 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RESET_TQP_QUEUE_INDEP, false);
885 : :
886 : : req = (struct hns3_reset_tqp_queue_cmd *)desc.data;
887 : 0 : req->tqp_id = rte_cpu_to_le_16(queue_id);
888 : 0 : req->queue_direction = queue_type == HNS3_RING_TYPE_TX ? 0 : 1;
889 : 0 : hns3_set_bit(req->reset_req, HNS3_TQP_RESET_B, enable ? 1 : 0);
890 : :
891 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
892 [ # # ]: 0 : if (ret)
893 [ # # ]: 0 : hns3_err(hw, "send queue reset cmd error, queue_id = %u, "
894 : : "queue_type = %s, ret = %d.", queue_id,
895 : : queue_type == HNS3_RING_TYPE_TX ? "Tx" : "Rx", ret);
896 : 0 : return ret;
897 : : }
898 : :
899 : : static int
900 : 0 : hns3_get_queue_reset_status(struct hns3_hw *hw, uint16_t queue_id,
901 : : enum hns3_ring_type queue_type,
902 : : uint8_t *reset_status)
903 : : {
904 : : struct hns3_reset_tqp_queue_cmd *req;
905 : : struct hns3_cmd_desc desc;
906 : : int ret;
907 : :
908 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_RESET_TQP_QUEUE_INDEP, true);
909 : :
910 : : req = (struct hns3_reset_tqp_queue_cmd *)desc.data;
911 : 0 : req->tqp_id = rte_cpu_to_le_16(queue_id);
912 : 0 : req->queue_direction = queue_type == HNS3_RING_TYPE_TX ? 0 : 1;
913 : :
914 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
915 [ # # ]: 0 : if (ret) {
916 [ # # ]: 0 : hns3_err(hw, "get queue reset status error, queue_id = %u "
917 : : "queue_type = %s, ret = %d.", queue_id,
918 : : queue_type == HNS3_RING_TYPE_TX ? "Tx" : "Rx", ret);
919 : 0 : return ret;
920 : : }
921 : :
922 : 0 : *reset_status = hns3_get_bit(req->ready_to_reset, HNS3_TQP_RESET_B);
923 : 0 : return ret;
924 : : }
925 : :
926 : : static int
927 : 0 : hns3_reset_queue(struct hns3_hw *hw, uint16_t queue_id,
928 : : enum hns3_ring_type queue_type)
929 : : {
930 : : #define HNS3_QUEUE_RESET_TRY_MS 200
931 : : struct hns3_tx_queue *txq;
932 : : struct hns3_rx_queue *rxq;
933 : : uint32_t reset_wait_times;
934 : : uint32_t max_wait_times;
935 : : uint8_t reset_status;
936 : : int ret;
937 : :
938 [ # # ]: 0 : if (queue_type == HNS3_RING_TYPE_TX) {
939 [ # # ]: 0 : txq = hw->data->tx_queues[queue_id];
940 : : hns3_enable_txq(txq, false);
941 : : } else {
942 [ # # ]: 0 : rxq = hw->data->rx_queues[queue_id];
943 : : hns3_enable_rxq(rxq, false);
944 : : }
945 : :
946 : 0 : ret = hns3_send_reset_queue_cmd(hw, queue_id, queue_type, true);
947 [ # # ]: 0 : if (ret) {
948 : 0 : hns3_err(hw, "send reset queue cmd fail, ret = %d.", ret);
949 : 0 : return ret;
950 : : }
951 : :
952 : : reset_wait_times = 0;
953 : : max_wait_times = HNS3_QUEUE_RESET_TRY_MS / HNS3_POLL_RESPONE_MS;
954 [ # # ]: 0 : while (reset_wait_times < max_wait_times) {
955 : : /* Wait for queue hw reset */
956 : : rte_delay_ms(HNS3_POLL_RESPONE_MS);
957 : 0 : ret = hns3_get_queue_reset_status(hw, queue_id,
958 : : queue_type, &reset_status);
959 [ # # ]: 0 : if (ret)
960 : 0 : goto queue_reset_fail;
961 : :
962 [ # # ]: 0 : if (reset_status)
963 : : break;
964 : 0 : reset_wait_times++;
965 : : }
966 : :
967 [ # # ]: 0 : if (!reset_status) {
968 [ # # ]: 0 : hns3_err(hw, "reset queue timeout, queue_id = %u, queue_type = %s",
969 : : queue_id,
970 : : queue_type == HNS3_RING_TYPE_TX ? "Tx" : "Rx");
971 : : ret = -ETIMEDOUT;
972 : 0 : goto queue_reset_fail;
973 : : }
974 : :
975 : 0 : ret = hns3_send_reset_queue_cmd(hw, queue_id, queue_type, false);
976 [ # # ]: 0 : if (ret)
977 : 0 : hns3_err(hw, "deassert queue reset fail, ret = %d.", ret);
978 : :
979 : : return ret;
980 : :
981 : 0 : queue_reset_fail:
982 : 0 : hns3_send_reset_queue_cmd(hw, queue_id, queue_type, false);
983 : 0 : return ret;
984 : : }
985 : :
986 : : uint32_t
987 : 0 : hns3_get_tqp_intr_reg_offset(uint16_t tqp_intr_id)
988 : : {
989 : : uint32_t reg_offset;
990 : :
991 : : /* Need an extend offset to config queues > 64 */
992 [ # # ]: 0 : if (tqp_intr_id < HNS3_MIN_EXT_TQP_INTR_ID)
993 : 0 : reg_offset = HNS3_TQP_INTR_REG_BASE +
994 : : tqp_intr_id * HNS3_TQP_INTR_LOW_ORDER_OFFSET;
995 : : else
996 : 0 : reg_offset = HNS3_TQP_INTR_EXT_REG_BASE +
997 : 0 : tqp_intr_id / HNS3_MIN_EXT_TQP_INTR_ID *
998 : 0 : HNS3_TQP_INTR_HIGH_ORDER_OFFSET +
999 : 0 : tqp_intr_id % HNS3_MIN_EXT_TQP_INTR_ID *
1000 : : HNS3_TQP_INTR_LOW_ORDER_OFFSET;
1001 : :
1002 : 0 : return reg_offset;
1003 : : }
1004 : :
1005 : : void
1006 : 0 : hns3_set_queue_intr_gl(struct hns3_hw *hw, uint16_t queue_id,
1007 : : uint8_t gl_idx, uint16_t gl_value)
1008 : : {
1009 : 0 : uint32_t offset[] = {HNS3_TQP_INTR_GL0_REG,
1010 : : HNS3_TQP_INTR_GL1_REG,
1011 : : HNS3_TQP_INTR_GL2_REG};
1012 : : uint32_t addr, value;
1013 : :
1014 [ # # ]: 0 : if (gl_idx >= RTE_DIM(offset) || gl_value > HNS3_TQP_INTR_GL_MAX)
1015 : 0 : return;
1016 : :
1017 : 0 : addr = offset[gl_idx] + hns3_get_tqp_intr_reg_offset(queue_id);
1018 [ # # ]: 0 : if (hw->intr.gl_unit == HNS3_INTR_COALESCE_GL_UINT_1US)
1019 : 0 : value = gl_value | HNS3_TQP_INTR_GL_UNIT_1US;
1020 : : else
1021 : 0 : value = HNS3_GL_USEC_TO_REG(gl_value);
1022 : :
1023 : 0 : hns3_write_dev(hw, addr, value);
1024 : : }
1025 : :
1026 : : void
1027 : 0 : hns3_set_queue_intr_rl(struct hns3_hw *hw, uint16_t queue_id, uint16_t rl_value)
1028 : : {
1029 : : uint32_t addr, value;
1030 : :
1031 [ # # ]: 0 : if (rl_value > HNS3_TQP_INTR_RL_MAX)
1032 : : return;
1033 : :
1034 : 0 : addr = HNS3_TQP_INTR_RL_REG + hns3_get_tqp_intr_reg_offset(queue_id);
1035 : 0 : value = HNS3_RL_USEC_TO_REG(rl_value);
1036 [ # # ]: 0 : if (value > 0)
1037 : 0 : value |= HNS3_TQP_INTR_RL_ENABLE_MASK;
1038 : :
1039 : 0 : hns3_write_dev(hw, addr, value);
1040 : : }
1041 : :
1042 : : void
1043 : 0 : hns3_set_queue_intr_ql(struct hns3_hw *hw, uint16_t queue_id, uint16_t ql_value)
1044 : : {
1045 : : uint32_t addr;
1046 : :
1047 : : /*
1048 : : * int_ql_max == 0 means the hardware does not support QL,
1049 : : * QL regs config is not permitted if QL is not supported,
1050 : : * here just return.
1051 : : */
1052 [ # # ]: 0 : if (hw->intr.int_ql_max == HNS3_INTR_QL_NONE)
1053 : : return;
1054 : :
1055 : 0 : addr = HNS3_TQP_INTR_TX_QL_REG + hns3_get_tqp_intr_reg_offset(queue_id);
1056 : 0 : hns3_write_dev(hw, addr, ql_value);
1057 : :
1058 : 0 : addr = HNS3_TQP_INTR_RX_QL_REG + hns3_get_tqp_intr_reg_offset(queue_id);
1059 : 0 : hns3_write_dev(hw, addr, ql_value);
1060 : : }
1061 : :
1062 : : static void
1063 : : hns3_queue_intr_enable(struct hns3_hw *hw, uint16_t queue_id, bool en)
1064 : : {
1065 : : uint32_t addr, value;
1066 : :
1067 : 0 : addr = HNS3_TQP_INTR_CTRL_REG + hns3_get_tqp_intr_reg_offset(queue_id);
1068 : 0 : value = en ? 1 : 0;
1069 : :
1070 : 0 : hns3_write_dev(hw, addr, value);
1071 : : }
1072 : :
1073 : : /*
1074 : : * Enable all rx queue interrupt when in interrupt rx mode.
1075 : : * This api was called before enable queue rx&tx (in normal start or reset
1076 : : * recover scenes), used to fix hardware rx queue interrupt enable was clear
1077 : : * when FLR.
1078 : : */
1079 : : void
1080 : 0 : hns3_dev_all_rx_queue_intr_enable(struct hns3_hw *hw, bool en)
1081 : : {
1082 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[hw->data->port_id];
1083 : 0 : uint16_t nb_rx_q = hw->data->nb_rx_queues;
1084 : : uint16_t i;
1085 : :
1086 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq == 0)
1087 : : return;
1088 : :
1089 [ # # ]: 0 : for (i = 0; i < nb_rx_q; i++)
1090 : 0 : hns3_queue_intr_enable(hw, i, en);
1091 : : }
1092 : :
1093 : : int
1094 : 0 : hns3_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1095 : : {
1096 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1097 : 0 : struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
1098 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1099 : :
1100 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq == 0)
1101 : : return -ENOTSUP;
1102 : :
1103 : 0 : hns3_queue_intr_enable(hw, queue_id, true);
1104 : :
1105 : 0 : return rte_intr_ack(intr_handle);
1106 : : }
1107 : :
1108 : : int
1109 : 0 : hns3_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1110 : : {
1111 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1112 : :
1113 [ # # ]: 0 : if (dev->data->dev_conf.intr_conf.rxq == 0)
1114 : : return -ENOTSUP;
1115 : :
1116 : 0 : hns3_queue_intr_enable(hw, queue_id, false);
1117 : :
1118 : 0 : return 0;
1119 : : }
1120 : :
1121 : : static int
1122 : 0 : hns3_init_rxq(struct hns3_adapter *hns, uint16_t idx)
1123 : : {
1124 : 0 : struct hns3_hw *hw = &hns->hw;
1125 : : struct hns3_rx_queue *rxq;
1126 : : int ret;
1127 : :
1128 : 0 : PMD_INIT_FUNC_TRACE();
1129 : :
1130 : 0 : rxq = (struct hns3_rx_queue *)hw->data->rx_queues[idx];
1131 : 0 : ret = hns3_alloc_rx_queue_mbufs(hw, rxq);
1132 [ # # ]: 0 : if (ret) {
1133 : 0 : hns3_err(hw, "fail to alloc mbuf for Rx queue %u, ret = %d.",
1134 : : idx, ret);
1135 : 0 : return ret;
1136 : : }
1137 : :
1138 : 0 : rxq->next_to_use = 0;
1139 : 0 : rxq->rx_rearm_start = 0;
1140 : 0 : rxq->rx_free_hold = 0;
1141 : 0 : rxq->rx_rearm_nb = 0;
1142 : 0 : rxq->pkt_first_seg = NULL;
1143 : 0 : rxq->pkt_last_seg = NULL;
1144 : 0 : hns3_init_rx_queue_hw(rxq);
1145 : 0 : hns3_rxq_vec_setup(rxq);
1146 : :
1147 : 0 : return 0;
1148 : : }
1149 : :
1150 : : static void
1151 : : hns3_init_fake_rxq(struct hns3_adapter *hns, uint16_t idx)
1152 : : {
1153 : : struct hns3_hw *hw = &hns->hw;
1154 : : struct hns3_rx_queue *rxq;
1155 : :
1156 : 0 : rxq = (struct hns3_rx_queue *)hw->fkq_data.rx_queues[idx];
1157 : 0 : rxq->next_to_use = 0;
1158 : 0 : rxq->rx_free_hold = 0;
1159 : 0 : rxq->rx_rearm_start = 0;
1160 : 0 : rxq->rx_rearm_nb = 0;
1161 : 0 : hns3_init_rx_queue_hw(rxq);
1162 : : }
1163 : :
1164 : : static void
1165 : 0 : hns3_init_txq(struct hns3_tx_queue *txq)
1166 : : {
1167 : : struct hns3_desc *desc;
1168 : : uint16_t i;
1169 : :
1170 : : /* Clear tx bd */
1171 : 0 : desc = txq->tx_ring;
1172 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
1173 : 0 : desc->tx.tp_fe_sc_vld_ra_ri = 0;
1174 : 0 : desc++;
1175 : : }
1176 : :
1177 : 0 : txq->next_to_use = 0;
1178 : 0 : txq->next_to_clean = 0;
1179 : 0 : txq->tx_bd_ready = txq->nb_tx_desc - 1;
1180 : : hns3_init_tx_queue_hw(txq);
1181 : 0 : }
1182 : :
1183 : : static int
1184 : 0 : hns3_init_tx_ring_tc(struct hns3_adapter *hns)
1185 : : {
1186 : : struct hns3_cmd_desc desc;
1187 : : struct hns3vf_tx_ring_tc_cmd *req = (struct hns3vf_tx_ring_tc_cmd *)desc.data;
1188 : 0 : struct hns3_hw *hw = &hns->hw;
1189 : : struct hns3_tx_queue *txq;
1190 : : int i, num, ret;
1191 : :
1192 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
1193 : : struct hns3_tc_queue_info *tc_queue = &hw->tc_queue[i];
1194 : : uint16_t j;
1195 : :
1196 [ # # ]: 0 : if (!tc_queue->enable)
1197 : 0 : continue;
1198 : :
1199 [ # # ]: 0 : for (j = 0; j < tc_queue->tqp_count; j++) {
1200 : 0 : num = tc_queue->tqp_offset + j;
1201 : 0 : txq = (struct hns3_tx_queue *)hw->data->tx_queues[num];
1202 [ # # ]: 0 : if (txq == NULL)
1203 : 0 : continue;
1204 : :
1205 [ # # ]: 0 : if (!hns->is_vf) {
1206 : 0 : hns3_write_dev(txq, HNS3_RING_TX_TC_REG, tc_queue->tc);
1207 : 0 : continue;
1208 : : }
1209 : :
1210 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_TQP_TX_QUEUE_TC, false);
1211 : 0 : req->tqp_id = rte_cpu_to_le_16(num);
1212 : 0 : req->tc_id = tc_queue->tc;
1213 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
1214 [ # # ]: 0 : if (ret != 0) {
1215 : 0 : hns3_err(hw, "config Tx queue (%u)'s TC failed! ret = %d.",
1216 : : num, ret);
1217 : 0 : return ret;
1218 : : }
1219 : : }
1220 : : }
1221 : :
1222 : : return 0;
1223 : : }
1224 : :
1225 : : static int
1226 : 0 : hns3_init_rx_queues(struct hns3_adapter *hns)
1227 : : {
1228 : : struct hns3_hw *hw = &hns->hw;
1229 : : struct hns3_rx_queue *rxq;
1230 : : uint16_t i, j;
1231 : : int ret;
1232 : :
1233 : : /* Initialize RSS for queues */
1234 : 0 : ret = hns3_config_rss(hns);
1235 [ # # ]: 0 : if (ret) {
1236 : 0 : hns3_err(hw, "failed to configure rss, ret = %d.", ret);
1237 : 0 : return ret;
1238 : : }
1239 : :
1240 [ # # ]: 0 : for (i = 0; i < hw->data->nb_rx_queues; i++) {
1241 : 0 : rxq = (struct hns3_rx_queue *)hw->data->rx_queues[i];
1242 [ # # ]: 0 : if (!rxq) {
1243 : 0 : hns3_err(hw, "Rx queue %u not available or setup.", i);
1244 : 0 : goto out;
1245 : : }
1246 : :
1247 [ # # ]: 0 : if (rxq->rx_deferred_start)
1248 : 0 : continue;
1249 : :
1250 : 0 : ret = hns3_init_rxq(hns, i);
1251 [ # # ]: 0 : if (ret) {
1252 : 0 : hns3_err(hw, "failed to init Rx queue %u, ret = %d.", i,
1253 : : ret);
1254 : 0 : goto out;
1255 : : }
1256 : : }
1257 : :
1258 [ # # ]: 0 : for (i = 0; i < hw->fkq_data.nb_fake_rx_queues; i++)
1259 : : hns3_init_fake_rxq(hns, i);
1260 : :
1261 : : return 0;
1262 : :
1263 : 0 : out:
1264 [ # # ]: 0 : for (j = 0; j < i; j++) {
1265 : 0 : rxq = (struct hns3_rx_queue *)hw->data->rx_queues[j];
1266 [ # # ]: 0 : if (rxq->rx_deferred_start)
1267 : 0 : continue;
1268 : :
1269 : 0 : hns3_rx_queue_release_mbufs(rxq);
1270 : : }
1271 : :
1272 : : return ret;
1273 : : }
1274 : :
1275 : : static int
1276 : 0 : hns3_init_tx_queues(struct hns3_adapter *hns)
1277 : : {
1278 : : struct hns3_hw *hw = &hns->hw;
1279 : : struct hns3_tx_queue *txq;
1280 : : uint16_t i;
1281 : :
1282 [ # # ]: 0 : for (i = 0; i < hw->data->nb_tx_queues; i++) {
1283 : 0 : txq = (struct hns3_tx_queue *)hw->data->tx_queues[i];
1284 [ # # ]: 0 : if (!txq) {
1285 : 0 : hns3_err(hw, "Tx queue %u not available or setup.", i);
1286 : 0 : return -EINVAL;
1287 : : }
1288 : :
1289 [ # # ]: 0 : if (txq->tx_deferred_start)
1290 : 0 : continue;
1291 : 0 : hns3_init_txq(txq);
1292 : : }
1293 : :
1294 [ # # ]: 0 : for (i = 0; i < hw->fkq_data.nb_fake_tx_queues; i++) {
1295 : 0 : txq = (struct hns3_tx_queue *)hw->fkq_data.tx_queues[i];
1296 : 0 : hns3_init_txq(txq);
1297 : : }
1298 : :
1299 : 0 : return hns3_init_tx_ring_tc(hns);
1300 : : }
1301 : :
1302 : : /*
1303 : : * Init all queues.
1304 : : * Note: just init and setup queues, and don't enable tqps.
1305 : : */
1306 : : int
1307 : 0 : hns3_init_queues(struct hns3_adapter *hns, bool reset_queue)
1308 : : {
1309 : : struct hns3_hw *hw = &hns->hw;
1310 : : int ret;
1311 : :
1312 [ # # ]: 0 : if (reset_queue) {
1313 : 0 : ret = hns3_reset_all_tqps(hns);
1314 [ # # ]: 0 : if (ret) {
1315 : 0 : hns3_err(hw, "failed to reset all queues, ret = %d.",
1316 : : ret);
1317 : 0 : return ret;
1318 : : }
1319 : : }
1320 : :
1321 : 0 : ret = hns3_init_rx_queues(hns);
1322 [ # # ]: 0 : if (ret) {
1323 : 0 : hns3_err(hw, "failed to init rx queues, ret = %d.", ret);
1324 : 0 : return ret;
1325 : : }
1326 : :
1327 : 0 : ret = hns3_init_tx_queues(hns);
1328 [ # # ]: 0 : if (ret) {
1329 : 0 : hns3_dev_release_mbufs(hns);
1330 : 0 : hns3_err(hw, "failed to init tx queues, ret = %d.", ret);
1331 : : }
1332 : :
1333 : : return ret;
1334 : : }
1335 : :
1336 : : void
1337 : 0 : hns3_start_tqps(struct hns3_hw *hw)
1338 : : {
1339 : : struct hns3_tx_queue *txq;
1340 : : struct hns3_rx_queue *rxq;
1341 : : uint16_t i;
1342 : :
1343 : 0 : hns3_enable_all_queues(hw, true);
1344 : :
1345 [ # # ]: 0 : for (i = 0; i < hw->data->nb_tx_queues; i++) {
1346 [ # # ]: 0 : __rte_assume(i < RTE_MAX_QUEUES_PER_PORT);
1347 : 0 : txq = hw->data->tx_queues[i];
1348 [ # # ]: 0 : if (txq->enabled)
1349 : 0 : hw->data->tx_queue_state[i] =
1350 : : RTE_ETH_QUEUE_STATE_STARTED;
1351 : : }
1352 : :
1353 [ # # ]: 0 : for (i = 0; i < hw->data->nb_rx_queues; i++) {
1354 [ # # ]: 0 : __rte_assume(i < RTE_MAX_QUEUES_PER_PORT);
1355 : 0 : rxq = hw->data->rx_queues[i];
1356 [ # # ]: 0 : if (rxq->enabled)
1357 : 0 : hw->data->rx_queue_state[i] =
1358 : : RTE_ETH_QUEUE_STATE_STARTED;
1359 : : }
1360 : 0 : }
1361 : :
1362 : : void
1363 : 0 : hns3_stop_tqps(struct hns3_hw *hw)
1364 : : {
1365 : : uint16_t i;
1366 : :
1367 : 0 : hns3_enable_all_queues(hw, false);
1368 : :
1369 [ # # ]: 0 : for (i = 0; i < hw->data->nb_tx_queues; i++)
1370 : 0 : hw->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1371 : :
1372 [ # # ]: 0 : for (i = 0; i < hw->data->nb_rx_queues; i++)
1373 : 0 : hw->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1374 : 0 : }
1375 : :
1376 : : /*
1377 : : * Iterate over all Rx Queue, and call the callback() function for each Rx
1378 : : * queue.
1379 : : *
1380 : : * @param[in] dev
1381 : : * The target eth dev.
1382 : : * @param[in] callback
1383 : : * The function to call for each queue.
1384 : : * if callback function return nonzero will stop iterate and return it's value
1385 : : * @param[in] arg
1386 : : * The arguments to provide the callback function with.
1387 : : *
1388 : : * @return
1389 : : * 0 on success, otherwise with errno set.
1390 : : */
1391 : : int
1392 : 0 : hns3_rxq_iterate(struct rte_eth_dev *dev,
1393 : : int (*callback)(struct hns3_rx_queue *, void *), void *arg)
1394 : : {
1395 : : uint32_t i;
1396 : : int ret;
1397 : :
1398 [ # # ]: 0 : if (dev->data->rx_queues == NULL)
1399 : : return -EINVAL;
1400 : :
1401 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1402 : 0 : ret = callback(dev->data->rx_queues[i], arg);
1403 [ # # ]: 0 : if (ret != 0)
1404 : 0 : return ret;
1405 : : }
1406 : :
1407 : : return 0;
1408 : : }
1409 : :
1410 : : static void*
1411 : 0 : hns3_alloc_rxq_and_dma_zone(struct rte_eth_dev *dev,
1412 : : struct hns3_queue_info *q_info)
1413 : : {
1414 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1415 : : const struct rte_memzone *rx_mz;
1416 : : struct hns3_rx_queue *rxq;
1417 : : unsigned int rx_desc;
1418 : :
1419 : 0 : rxq = rte_zmalloc_socket(q_info->type, sizeof(struct hns3_rx_queue),
1420 : 0 : RTE_CACHE_LINE_SIZE, q_info->socket_id);
1421 [ # # ]: 0 : if (rxq == NULL) {
1422 : 0 : hns3_err(hw, "Failed to allocate memory for No.%u rx ring!",
1423 : : q_info->idx);
1424 : 0 : return NULL;
1425 : : }
1426 : :
1427 : : /* Allocate rx ring hardware descriptors. */
1428 : 0 : rxq->queue_id = q_info->idx;
1429 : 0 : rxq->nb_rx_desc = q_info->nb_desc;
1430 : :
1431 : : /*
1432 : : * Allocate a litter more memory because rx vector functions
1433 : : * don't check boundaries each time.
1434 : : */
1435 : 0 : rx_desc = (rxq->nb_rx_desc + HNS3_DEFAULT_RX_BURST) *
1436 : : sizeof(struct hns3_desc);
1437 : 0 : rx_mz = rte_eth_dma_zone_reserve(dev, q_info->ring_name, q_info->idx,
1438 : : rx_desc, HNS3_RING_BASE_ALIGN,
1439 : 0 : q_info->socket_id);
1440 [ # # ]: 0 : if (rx_mz == NULL) {
1441 : 0 : hns3_err(hw, "Failed to reserve DMA memory for No.%u rx ring!",
1442 : : q_info->idx);
1443 : 0 : hns3_rx_queue_release(rxq);
1444 : 0 : return NULL;
1445 : : }
1446 : 0 : rxq->mz = rx_mz;
1447 : 0 : rxq->rx_ring = (struct hns3_desc *)rx_mz->addr;
1448 : 0 : rxq->rx_ring_phys_addr = rx_mz->iova;
1449 : :
1450 : 0 : return rxq;
1451 : : }
1452 : :
1453 : : static int
1454 : 0 : hns3_fake_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
1455 : : uint16_t nb_desc, unsigned int socket_id)
1456 : : {
1457 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
1458 : : struct hns3_hw *hw = &hns->hw;
1459 : : struct hns3_queue_info q_info;
1460 : : struct hns3_rx_queue *rxq;
1461 : : uint16_t nb_rx_q;
1462 : :
1463 [ # # ]: 0 : if (hw->fkq_data.rx_queues[idx]) {
1464 : 0 : hns3_rx_queue_release(hw->fkq_data.rx_queues[idx]);
1465 : 0 : hw->fkq_data.rx_queues[idx] = NULL;
1466 : : }
1467 : :
1468 : 0 : q_info.idx = idx;
1469 : 0 : q_info.socket_id = socket_id;
1470 : 0 : q_info.nb_desc = nb_desc;
1471 : 0 : q_info.type = "hns3 fake RX queue";
1472 : 0 : q_info.ring_name = "rx_fake_ring";
1473 : 0 : rxq = hns3_alloc_rxq_and_dma_zone(dev, &q_info);
1474 [ # # ]: 0 : if (rxq == NULL) {
1475 : 0 : hns3_err(hw, "Failed to setup No.%u fake rx ring.", idx);
1476 : 0 : return -ENOMEM;
1477 : : }
1478 : :
1479 : : /* Don't need alloc sw_ring, because upper applications don't use it */
1480 : 0 : rxq->sw_ring = NULL;
1481 : :
1482 : 0 : rxq->hns = hns;
1483 : 0 : rxq->rx_deferred_start = false;
1484 : 0 : rxq->port_id = dev->data->port_id;
1485 : 0 : rxq->configured = true;
1486 : 0 : nb_rx_q = dev->data->nb_rx_queues;
1487 : 0 : rxq->io_base = (void *)((char *)hw->io_base + HNS3_TQP_REG_OFFSET +
1488 : 0 : (nb_rx_q + idx) * HNS3_TQP_REG_SIZE);
1489 : 0 : rxq->rx_buf_len = HNS3_MIN_BD_BUF_SIZE;
1490 : :
1491 : 0 : rte_spinlock_lock(&hw->lock);
1492 : 0 : hw->fkq_data.rx_queues[idx] = rxq;
1493 : : rte_spinlock_unlock(&hw->lock);
1494 : :
1495 : 0 : return 0;
1496 : : }
1497 : :
1498 : : static void*
1499 : 0 : hns3_alloc_txq_and_dma_zone(struct rte_eth_dev *dev,
1500 : : struct hns3_queue_info *q_info)
1501 : : {
1502 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1503 : : const struct rte_memzone *tx_mz;
1504 : : struct hns3_tx_queue *txq;
1505 : : struct hns3_desc *desc;
1506 : : unsigned int tx_desc;
1507 : : uint16_t i;
1508 : :
1509 : 0 : txq = rte_zmalloc_socket(q_info->type, sizeof(struct hns3_tx_queue),
1510 : 0 : RTE_CACHE_LINE_SIZE, q_info->socket_id);
1511 [ # # ]: 0 : if (txq == NULL) {
1512 : 0 : hns3_err(hw, "Failed to allocate memory for No.%u tx ring!",
1513 : : q_info->idx);
1514 : 0 : return NULL;
1515 : : }
1516 : :
1517 : : /* Allocate tx ring hardware descriptors. */
1518 : 0 : txq->queue_id = q_info->idx;
1519 : 0 : txq->nb_tx_desc = q_info->nb_desc;
1520 : 0 : tx_desc = txq->nb_tx_desc * sizeof(struct hns3_desc);
1521 : 0 : tx_mz = rte_eth_dma_zone_reserve(dev, q_info->ring_name, q_info->idx,
1522 : : tx_desc, HNS3_RING_BASE_ALIGN,
1523 : 0 : q_info->socket_id);
1524 [ # # ]: 0 : if (tx_mz == NULL) {
1525 : 0 : hns3_err(hw, "Failed to reserve DMA memory for No.%u tx ring!",
1526 : : q_info->idx);
1527 : 0 : hns3_tx_queue_release(txq);
1528 : 0 : return NULL;
1529 : : }
1530 : 0 : txq->mz = tx_mz;
1531 : 0 : txq->tx_ring = (struct hns3_desc *)tx_mz->addr;
1532 : 0 : txq->tx_ring_phys_addr = tx_mz->iova;
1533 : :
1534 : : /* Clear tx bd */
1535 : : desc = txq->tx_ring;
1536 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
1537 : 0 : desc->tx.tp_fe_sc_vld_ra_ri = 0;
1538 : 0 : desc++;
1539 : : }
1540 : :
1541 : : return txq;
1542 : : }
1543 : :
1544 : : static int
1545 : 0 : hns3_fake_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
1546 : : uint16_t nb_desc, unsigned int socket_id)
1547 : : {
1548 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
1549 : : struct hns3_hw *hw = &hns->hw;
1550 : : struct hns3_queue_info q_info;
1551 : : struct hns3_tx_queue *txq;
1552 : : uint16_t nb_tx_q;
1553 : :
1554 [ # # ]: 0 : if (hw->fkq_data.tx_queues[idx] != NULL) {
1555 : 0 : hns3_tx_queue_release(hw->fkq_data.tx_queues[idx]);
1556 : 0 : hw->fkq_data.tx_queues[idx] = NULL;
1557 : : }
1558 : :
1559 : 0 : q_info.idx = idx;
1560 : 0 : q_info.socket_id = socket_id;
1561 : 0 : q_info.nb_desc = nb_desc;
1562 : 0 : q_info.type = "hns3 fake TX queue";
1563 : 0 : q_info.ring_name = "tx_fake_ring";
1564 : 0 : txq = hns3_alloc_txq_and_dma_zone(dev, &q_info);
1565 [ # # ]: 0 : if (txq == NULL) {
1566 : 0 : hns3_err(hw, "Failed to setup No.%u fake tx ring.", idx);
1567 : 0 : return -ENOMEM;
1568 : : }
1569 : :
1570 : : /* Don't need alloc sw_ring, because upper applications don't use it */
1571 : 0 : txq->sw_ring = NULL;
1572 : 0 : txq->free = NULL;
1573 : :
1574 : 0 : txq->hns = hns;
1575 : 0 : txq->tx_deferred_start = false;
1576 : 0 : txq->port_id = dev->data->port_id;
1577 : 0 : txq->configured = true;
1578 : 0 : nb_tx_q = dev->data->nb_tx_queues;
1579 : 0 : txq->io_base = (void *)((char *)hw->io_base + HNS3_TQP_REG_OFFSET +
1580 : 0 : (nb_tx_q + idx) * HNS3_TQP_REG_SIZE);
1581 : :
1582 : 0 : rte_spinlock_lock(&hw->lock);
1583 : 0 : hw->fkq_data.tx_queues[idx] = txq;
1584 : : rte_spinlock_unlock(&hw->lock);
1585 : :
1586 : 0 : return 0;
1587 : : }
1588 : :
1589 : : static int
1590 : 0 : hns3_fake_rx_queue_config(struct hns3_hw *hw, uint16_t nb_queues)
1591 : : {
1592 : 0 : uint16_t old_nb_queues = hw->fkq_data.nb_fake_rx_queues;
1593 : : void **rxq;
1594 : : uint16_t i;
1595 : :
1596 [ # # # # ]: 0 : if (hw->fkq_data.rx_queues == NULL && nb_queues != 0) {
1597 : : /* first time configuration */
1598 : : uint32_t size;
1599 : 0 : size = sizeof(hw->fkq_data.rx_queues[0]) * nb_queues;
1600 : 0 : hw->fkq_data.rx_queues = rte_zmalloc("fake_rx_queues", size,
1601 : : RTE_CACHE_LINE_SIZE);
1602 [ # # ]: 0 : if (hw->fkq_data.rx_queues == NULL) {
1603 : 0 : hw->fkq_data.nb_fake_rx_queues = 0;
1604 : 0 : return -ENOMEM;
1605 : : }
1606 [ # # # # ]: 0 : } else if (hw->fkq_data.rx_queues != NULL && nb_queues != 0) {
1607 : : /* re-configure */
1608 : : rxq = hw->fkq_data.rx_queues;
1609 [ # # ]: 0 : for (i = nb_queues; i < old_nb_queues; i++)
1610 : 0 : hns3_rx_queue_release_lock(rxq[i]);
1611 : :
1612 : 0 : rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
1613 : : RTE_CACHE_LINE_SIZE);
1614 [ # # ]: 0 : if (rxq == NULL)
1615 : : return -ENOMEM;
1616 [ # # ]: 0 : if (nb_queues > old_nb_queues) {
1617 : 0 : uint16_t new_qs = nb_queues - old_nb_queues;
1618 : 0 : memset(rxq + old_nb_queues, 0, sizeof(rxq[0]) * new_qs);
1619 : : }
1620 : :
1621 : 0 : hw->fkq_data.rx_queues = rxq;
1622 [ # # # # ]: 0 : } else if (hw->fkq_data.rx_queues != NULL && nb_queues == 0) {
1623 : : rxq = hw->fkq_data.rx_queues;
1624 [ # # ]: 0 : for (i = nb_queues; i < old_nb_queues; i++)
1625 : 0 : hns3_rx_queue_release_lock(rxq[i]);
1626 : :
1627 : 0 : rte_free(hw->fkq_data.rx_queues);
1628 : 0 : hw->fkq_data.rx_queues = NULL;
1629 : : }
1630 : :
1631 : 0 : hw->fkq_data.nb_fake_rx_queues = nb_queues;
1632 : :
1633 : 0 : return 0;
1634 : : }
1635 : :
1636 : : static int
1637 : 0 : hns3_fake_tx_queue_config(struct hns3_hw *hw, uint16_t nb_queues)
1638 : : {
1639 : 0 : uint16_t old_nb_queues = hw->fkq_data.nb_fake_tx_queues;
1640 : : void **txq;
1641 : : uint16_t i;
1642 : :
1643 [ # # # # ]: 0 : if (hw->fkq_data.tx_queues == NULL && nb_queues != 0) {
1644 : : /* first time configuration */
1645 : : uint32_t size;
1646 : 0 : size = sizeof(hw->fkq_data.tx_queues[0]) * nb_queues;
1647 : 0 : hw->fkq_data.tx_queues = rte_zmalloc("fake_tx_queues", size,
1648 : : RTE_CACHE_LINE_SIZE);
1649 [ # # ]: 0 : if (hw->fkq_data.tx_queues == NULL) {
1650 : 0 : hw->fkq_data.nb_fake_tx_queues = 0;
1651 : 0 : return -ENOMEM;
1652 : : }
1653 [ # # # # ]: 0 : } else if (hw->fkq_data.tx_queues != NULL && nb_queues != 0) {
1654 : : /* re-configure */
1655 : : txq = hw->fkq_data.tx_queues;
1656 [ # # ]: 0 : for (i = nb_queues; i < old_nb_queues; i++)
1657 : 0 : hns3_tx_queue_release_lock(txq[i]);
1658 : 0 : txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
1659 : : RTE_CACHE_LINE_SIZE);
1660 [ # # ]: 0 : if (txq == NULL)
1661 : : return -ENOMEM;
1662 [ # # ]: 0 : if (nb_queues > old_nb_queues) {
1663 : 0 : uint16_t new_qs = nb_queues - old_nb_queues;
1664 : 0 : memset(txq + old_nb_queues, 0, sizeof(txq[0]) * new_qs);
1665 : : }
1666 : :
1667 : 0 : hw->fkq_data.tx_queues = txq;
1668 [ # # # # ]: 0 : } else if (hw->fkq_data.tx_queues != NULL && nb_queues == 0) {
1669 : : txq = hw->fkq_data.tx_queues;
1670 [ # # ]: 0 : for (i = nb_queues; i < old_nb_queues; i++)
1671 : 0 : hns3_tx_queue_release_lock(txq[i]);
1672 : :
1673 : 0 : rte_free(hw->fkq_data.tx_queues);
1674 : 0 : hw->fkq_data.tx_queues = NULL;
1675 : : }
1676 : 0 : hw->fkq_data.nb_fake_tx_queues = nb_queues;
1677 : :
1678 : 0 : return 0;
1679 : : }
1680 : :
1681 : : int
1682 : 0 : hns3_set_fake_rx_or_tx_queues(struct rte_eth_dev *dev, uint16_t nb_rx_q,
1683 : : uint16_t nb_tx_q)
1684 : : {
1685 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1686 : : uint16_t rx_need_add_nb_q;
1687 : : uint16_t tx_need_add_nb_q;
1688 : : uint16_t port_id;
1689 : : uint16_t q;
1690 : : int ret;
1691 : :
1692 [ # # ]: 0 : if (hns3_dev_get_support(hw, INDEP_TXRX))
1693 : : return 0;
1694 : :
1695 : : /* Setup new number of fake RX/TX queues and reconfigure device. */
1696 : 0 : rx_need_add_nb_q = hw->cfg_max_queues - nb_rx_q;
1697 : 0 : tx_need_add_nb_q = hw->cfg_max_queues - nb_tx_q;
1698 : 0 : ret = hns3_fake_rx_queue_config(hw, rx_need_add_nb_q);
1699 [ # # ]: 0 : if (ret) {
1700 : 0 : hns3_err(hw, "Fail to configure fake rx queues: %d", ret);
1701 : 0 : return ret;
1702 : : }
1703 : :
1704 : 0 : ret = hns3_fake_tx_queue_config(hw, tx_need_add_nb_q);
1705 [ # # ]: 0 : if (ret) {
1706 : 0 : hns3_err(hw, "Fail to configure fake tx queues: %d", ret);
1707 : 0 : goto cfg_fake_tx_q_fail;
1708 : : }
1709 : :
1710 : : /* Allocate and set up fake RX queue per Ethernet port. */
1711 : 0 : port_id = hw->data->port_id;
1712 [ # # ]: 0 : for (q = 0; q < rx_need_add_nb_q; q++) {
1713 : 0 : ret = hns3_fake_rx_queue_setup(dev, q, HNS3_MIN_RING_DESC,
1714 : 0 : rte_eth_dev_socket_id(port_id));
1715 [ # # ]: 0 : if (ret)
1716 : 0 : goto setup_fake_rx_q_fail;
1717 : : }
1718 : :
1719 : : /* Allocate and set up fake TX queue per Ethernet port. */
1720 [ # # ]: 0 : for (q = 0; q < tx_need_add_nb_q; q++) {
1721 : 0 : ret = hns3_fake_tx_queue_setup(dev, q, HNS3_MIN_RING_DESC,
1722 : 0 : rte_eth_dev_socket_id(port_id));
1723 [ # # ]: 0 : if (ret)
1724 : 0 : goto setup_fake_tx_q_fail;
1725 : : }
1726 : :
1727 : : return 0;
1728 : :
1729 : : setup_fake_tx_q_fail:
1730 : 0 : setup_fake_rx_q_fail:
1731 : 0 : (void)hns3_fake_tx_queue_config(hw, 0);
1732 : 0 : cfg_fake_tx_q_fail:
1733 : 0 : (void)hns3_fake_rx_queue_config(hw, 0);
1734 : :
1735 : 0 : return ret;
1736 : : }
1737 : :
1738 : : void
1739 : 0 : hns3_dev_release_mbufs(struct hns3_adapter *hns)
1740 : : {
1741 : 0 : struct rte_eth_dev_data *dev_data = hns->hw.data;
1742 : : struct hns3_rx_queue *rxq;
1743 : : struct hns3_tx_queue *txq;
1744 : : uint16_t i;
1745 : :
1746 [ # # ]: 0 : if (dev_data->rx_queues)
1747 [ # # ]: 0 : for (i = 0; i < dev_data->nb_rx_queues; i++) {
1748 : 0 : rxq = dev_data->rx_queues[i];
1749 [ # # ]: 0 : if (rxq == NULL)
1750 : 0 : continue;
1751 : 0 : hns3_rx_queue_release_mbufs(rxq);
1752 : : }
1753 : :
1754 [ # # ]: 0 : if (dev_data->tx_queues)
1755 [ # # ]: 0 : for (i = 0; i < dev_data->nb_tx_queues; i++) {
1756 : 0 : txq = dev_data->tx_queues[i];
1757 [ # # ]: 0 : if (txq == NULL)
1758 : 0 : continue;
1759 : 0 : hns3_tx_queue_release_mbufs(txq);
1760 : : }
1761 : 0 : }
1762 : :
1763 : : static int
1764 : : hns3_rx_buf_len_calc(struct rte_mempool *mp, uint16_t *rx_buf_len)
1765 : : {
1766 : : uint16_t vld_buf_size;
1767 : : uint16_t num_hw_specs;
1768 : : uint16_t i;
1769 : :
1770 : : /*
1771 : : * hns3 network engine only support to set 4 typical specification, and
1772 : : * different buffer size will affect the max packet_len and the max
1773 : : * number of segmentation when hw gro is turned on in receive side. The
1774 : : * relationship between them is as follows:
1775 : : * rx_buf_size | max_gro_pkt_len | max_gro_nb_seg
1776 : : * ---------------------|-------------------|----------------
1777 : : * HNS3_4K_BD_BUF_SIZE | 60KB | 15
1778 : : * HNS3_2K_BD_BUF_SIZE | 62KB | 31
1779 : : * HNS3_1K_BD_BUF_SIZE | 63KB | 63
1780 : : * HNS3_512_BD_BUF_SIZE | 31.5KB | 63
1781 : : */
1782 : : static const uint16_t hw_rx_buf_size[] = {
1783 : : HNS3_4K_BD_BUF_SIZE,
1784 : : HNS3_2K_BD_BUF_SIZE,
1785 : : HNS3_1K_BD_BUF_SIZE,
1786 : : HNS3_512_BD_BUF_SIZE
1787 : : };
1788 : :
1789 : 0 : vld_buf_size = (uint16_t)(rte_pktmbuf_data_room_size(mp) -
1790 : : RTE_PKTMBUF_HEADROOM);
1791 [ # # ]: 0 : if (vld_buf_size < HNS3_MIN_BD_BUF_SIZE)
1792 : : return -EINVAL;
1793 : :
1794 : : num_hw_specs = RTE_DIM(hw_rx_buf_size);
1795 [ # # ]: 0 : for (i = 0; i < num_hw_specs; i++) {
1796 [ # # ]: 0 : if (vld_buf_size >= hw_rx_buf_size[i]) {
1797 : 0 : *rx_buf_len = hw_rx_buf_size[i];
1798 : : break;
1799 : : }
1800 : : }
1801 : : return 0;
1802 : : }
1803 : :
1804 : : static int
1805 : 0 : hns3_rxq_conf_runtime_check(struct hns3_hw *hw,
1806 : : const struct rte_eth_rxconf *conf,
1807 : : uint16_t buf_size, uint16_t nb_desc)
1808 : : {
1809 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[hw->data->port_id];
1810 : 0 : eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
1811 : 0 : uint32_t frame_size = dev->data->mtu + HNS3_ETH_OVERHEAD;
1812 : : uint16_t min_vec_bds;
1813 : :
1814 : : /*
1815 : : * HNS3 hardware network engine set scattered as default. If the driver
1816 : : * is not work in scattered mode and the pkts greater than buf_size
1817 : : * but smaller than frame size will be distributed to multiple BDs.
1818 : : * Driver cannot handle this situation.
1819 : : */
1820 [ # # # # ]: 0 : if (!hw->data->scattered_rx && frame_size > buf_size) {
1821 : 0 : hns3_err(hw, "frame size is not allowed to be set greater "
1822 : : "than rx_buf_len if scattered is off.");
1823 : 0 : return -EINVAL;
1824 : : }
1825 : :
1826 [ # # # # ]: 0 : if (pkt_burst == hns3_recv_pkts_vec ||
1827 : : pkt_burst == hns3_recv_pkts_vec_sve) {
1828 : : min_vec_bds = HNS3_DEFAULT_RXQ_REARM_THRESH +
1829 : : HNS3_DEFAULT_RX_BURST;
1830 [ # # # # ]: 0 : if (nb_desc < min_vec_bds ||
1831 : : nb_desc % HNS3_DEFAULT_RXQ_REARM_THRESH) {
1832 : 0 : hns3_err(hw, "if Rx burst mode is vector, "
1833 : : "number of descriptor is required to be "
1834 : : "bigger than min vector bds:%u, and could be "
1835 : : "divided by rxq rearm thresh:%u.",
1836 : : min_vec_bds, HNS3_DEFAULT_RXQ_REARM_THRESH);
1837 : 0 : return -EINVAL;
1838 : : }
1839 : : }
1840 : :
1841 [ # # # # ]: 0 : if ((conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) &&
1842 [ # # ]: 0 : pkt_burst != hns3_recv_pkts_simple &&
1843 : : pkt_burst != hns3_recv_scattered_pkts) {
1844 : 0 : hns3_err(hw, "KEEP_CRC offload is not supported with the current Rx function.");
1845 : 0 : return -EINVAL;
1846 : : }
1847 : :
1848 : : return 0;
1849 : : }
1850 : :
1851 : : static int
1852 : 0 : hns3_rx_queue_conf_check(struct hns3_hw *hw, const struct rte_eth_rxconf *conf,
1853 : : struct rte_mempool *mp, uint16_t nb_desc,
1854 : : uint16_t *buf_size)
1855 : : {
1856 : : int ret;
1857 : :
1858 [ # # # # ]: 0 : if (nb_desc > HNS3_MAX_RING_DESC || nb_desc < HNS3_MIN_RING_DESC ||
1859 : : nb_desc % HNS3_ALIGN_RING_DESC) {
1860 : 0 : hns3_err(hw, "Number (%u) of rx descriptors is invalid",
1861 : : nb_desc);
1862 : 0 : return -EINVAL;
1863 : : }
1864 : :
1865 [ # # ]: 0 : if (conf->rx_free_thresh >= nb_desc) {
1866 : 0 : hns3_err(hw, "rx_free_thresh (%u) must be less than %u",
1867 : : conf->rx_free_thresh, nb_desc);
1868 : 0 : return -EINVAL;
1869 : : }
1870 : :
1871 [ # # ]: 0 : if (conf->rx_drop_en == 0)
1872 : 0 : hns3_warn(hw, "if no descriptors available, packets are always "
1873 : : "dropped and rx_drop_en (1) is fixed on");
1874 : :
1875 : : if (hns3_rx_buf_len_calc(mp, buf_size)) {
1876 : 0 : hns3_err(hw, "rxq mbufs' data room size (%u) is not enough! "
1877 : : "minimal data room size (%u).",
1878 : : rte_pktmbuf_data_room_size(mp),
1879 : : HNS3_MIN_BD_BUF_SIZE + RTE_PKTMBUF_HEADROOM);
1880 : 0 : return -EINVAL;
1881 : : }
1882 : :
1883 [ # # ]: 0 : if (hw->data->dev_started) {
1884 : 0 : ret = hns3_rxq_conf_runtime_check(hw, conf, *buf_size, nb_desc);
1885 [ # # ]: 0 : if (ret) {
1886 : 0 : hns3_err(hw, "Rx queue runtime setup fail.");
1887 : 0 : return ret;
1888 : : }
1889 : : }
1890 : :
1891 : : return 0;
1892 : : }
1893 : :
1894 : : uint32_t
1895 : 0 : hns3_get_tqp_reg_offset(uint16_t queue_id)
1896 : : {
1897 : : uint32_t reg_offset;
1898 : :
1899 : : /* Need an extend offset to config queue > 1024 */
1900 [ # # ]: 0 : if (queue_id < HNS3_MIN_EXTEND_QUEUE_ID)
1901 : 0 : reg_offset = HNS3_TQP_REG_OFFSET + queue_id * HNS3_TQP_REG_SIZE;
1902 : : else
1903 : 0 : reg_offset = HNS3_TQP_REG_OFFSET + HNS3_TQP_EXT_REG_OFFSET +
1904 : 0 : (queue_id - HNS3_MIN_EXTEND_QUEUE_ID) *
1905 : : HNS3_TQP_REG_SIZE;
1906 : :
1907 : 0 : return reg_offset;
1908 : : }
1909 : :
1910 : : int
1911 : 0 : hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
1912 : : unsigned int socket_id, const struct rte_eth_rxconf *conf,
1913 : : struct rte_mempool *mp)
1914 : : {
1915 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
1916 : 0 : struct hns3_hw *hw = &hns->hw;
1917 : : struct hns3_queue_info q_info;
1918 : : struct hns3_rx_queue *rxq;
1919 : : uint16_t rx_buf_size;
1920 : : int rx_entry_len;
1921 : : int ret;
1922 : :
1923 : 0 : ret = hns3_rx_queue_conf_check(hw, conf, mp, nb_desc, &rx_buf_size);
1924 [ # # ]: 0 : if (ret)
1925 : : return ret;
1926 : :
1927 [ # # ]: 0 : if (dev->data->rx_queues[idx]) {
1928 : 0 : hns3_rx_queue_release(dev->data->rx_queues[idx]);
1929 : 0 : dev->data->rx_queues[idx] = NULL;
1930 : : }
1931 : :
1932 : 0 : q_info.idx = idx;
1933 : 0 : q_info.socket_id = socket_id;
1934 : 0 : q_info.nb_desc = nb_desc;
1935 : 0 : q_info.type = "hns3 RX queue";
1936 : 0 : q_info.ring_name = "rx_ring";
1937 : :
1938 : 0 : rxq = hns3_alloc_rxq_and_dma_zone(dev, &q_info);
1939 [ # # ]: 0 : if (rxq == NULL) {
1940 : 0 : hns3_err(hw,
1941 : : "Failed to alloc mem and reserve DMA mem for rx ring!");
1942 : 0 : return -ENOMEM;
1943 : : }
1944 : :
1945 : 0 : rxq->hns = hns;
1946 : 0 : rxq->ptype_tbl = &hns->ptype_tbl;
1947 : 0 : rxq->mb_pool = mp;
1948 [ # # ]: 0 : rxq->rx_free_thresh = (conf->rx_free_thresh > 0) ?
1949 : : conf->rx_free_thresh : HNS3_DEFAULT_RX_FREE_THRESH;
1950 : :
1951 : 0 : rxq->rx_deferred_start = conf->rx_deferred_start;
1952 [ # # # # ]: 0 : if (rxq->rx_deferred_start && !hns3_dev_get_support(hw, INDEP_TXRX)) {
1953 : 0 : hns3_warn(hw, "deferred start is not supported.");
1954 : 0 : rxq->rx_deferred_start = false;
1955 : : }
1956 : :
1957 : 0 : rx_entry_len = (rxq->nb_rx_desc + HNS3_DEFAULT_RX_BURST) *
1958 : : sizeof(struct hns3_entry);
1959 : 0 : rxq->sw_ring = rte_zmalloc_socket("hns3 RX sw ring", rx_entry_len,
1960 : : RTE_CACHE_LINE_SIZE, socket_id);
1961 [ # # ]: 0 : if (rxq->sw_ring == NULL) {
1962 : 0 : hns3_err(hw, "Failed to allocate memory for rx sw ring!");
1963 : 0 : hns3_rx_queue_release(rxq);
1964 : 0 : return -ENOMEM;
1965 : : }
1966 : :
1967 : 0 : rxq->next_to_use = 0;
1968 : 0 : rxq->rx_free_hold = 0;
1969 : 0 : rxq->rx_rearm_start = 0;
1970 : 0 : rxq->rx_rearm_nb = 0;
1971 : 0 : rxq->pkt_first_seg = NULL;
1972 : 0 : rxq->pkt_last_seg = NULL;
1973 : 0 : rxq->port_id = dev->data->port_id;
1974 : : /*
1975 : : * For hns3 PF device, if the VLAN mode is HW_SHIFT_AND_DISCARD_MODE,
1976 : : * the pvid_sw_discard_en in the queue struct should not be changed,
1977 : : * because PVID-related operations do not need to be processed by PMD.
1978 : : * For hns3 VF device, whether it needs to process PVID depends
1979 : : * on the configuration of PF kernel mode netdevice driver. And the
1980 : : * related PF configuration is delivered through the mailbox and finally
1981 : : * reflected in port_base_vlan_cfg.
1982 : : */
1983 [ # # # # ]: 0 : if (hns->is_vf || hw->vlan_mode == HNS3_SW_SHIFT_AND_DISCARD_MODE)
1984 : 0 : rxq->pvid_sw_discard_en = hw->port_base_vlan_cfg.state ==
1985 : : HNS3_PORT_BASE_VLAN_ENABLE;
1986 : : else
1987 : 0 : rxq->pvid_sw_discard_en = false;
1988 : 0 : rxq->ptype_en = hns3_dev_get_support(hw, RXD_ADV_LAYOUT) ? true : false;
1989 : 0 : rxq->configured = true;
1990 : 0 : rxq->io_base = (void *)((char *)hw->io_base +
1991 : 0 : hns3_get_tqp_reg_offset(idx));
1992 : 0 : rxq->io_head_reg = (volatile void *)((char *)rxq->io_base +
1993 : : HNS3_RING_RX_HEAD_REG);
1994 : 0 : rxq->rx_buf_len = rx_buf_size;
1995 [ # # ]: 0 : memset(&rxq->basic_stats, 0, sizeof(struct hns3_rx_basic_stats));
1996 : 0 : memset(&rxq->err_stats, 0, sizeof(struct hns3_rx_bd_errors_stats));
1997 : 0 : memset(&rxq->dfx_stats, 0, sizeof(struct hns3_rx_dfx_stats));
1998 : :
1999 : : /* CRC len set here is used for amending packet length */
2000 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
2001 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
2002 : : else
2003 : 0 : rxq->crc_len = 0;
2004 : :
2005 : 0 : rxq->keep_crc_fail_ptype = hw->strip_crc_ptype;
2006 : :
2007 : 0 : rxq->crc_ctx = rte_net_crc_set_alg(RTE_NET_CRC_SCALAR, RTE_NET_CRC32_ETH);
2008 [ # # ]: 0 : if (rxq->crc_ctx == NULL) {
2009 : 0 : hns3_err(hw, "Failed to allocate the CRC context.");
2010 : 0 : hns3_rx_queue_release(rxq);
2011 : 0 : return -ENOMEM;
2012 : : }
2013 : :
2014 : 0 : rxq->bulk_mbuf_num = 0;
2015 : :
2016 : 0 : rte_spinlock_lock(&hw->lock);
2017 : 0 : dev->data->rx_queues[idx] = rxq;
2018 : : rte_spinlock_unlock(&hw->lock);
2019 : :
2020 : 0 : return 0;
2021 : : }
2022 : :
2023 : : void
2024 : 0 : hns3_rx_scattered_reset(struct rte_eth_dev *dev)
2025 : : {
2026 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
2027 : : struct hns3_hw *hw = &hns->hw;
2028 : :
2029 : 0 : hw->rx_buf_len = 0;
2030 : 0 : dev->data->scattered_rx = false;
2031 : 0 : }
2032 : :
2033 : : void
2034 : 0 : hns3_rx_scattered_calc(struct rte_eth_dev *dev)
2035 : : {
2036 : 0 : struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
2037 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
2038 : : struct hns3_hw *hw = &hns->hw;
2039 : : struct hns3_rx_queue *rxq;
2040 : : uint32_t queue_id;
2041 : :
2042 [ # # ]: 0 : if (dev->data->rx_queues == NULL)
2043 : : return;
2044 : :
2045 [ # # ]: 0 : for (queue_id = 0; queue_id < dev->data->nb_rx_queues; queue_id++) {
2046 : 0 : rxq = dev->data->rx_queues[queue_id];
2047 [ # # ]: 0 : if (hw->rx_buf_len == 0)
2048 : 0 : hw->rx_buf_len = rxq->rx_buf_len;
2049 : : else
2050 : 0 : hw->rx_buf_len = RTE_MIN(hw->rx_buf_len,
2051 : : rxq->rx_buf_len);
2052 : : }
2053 : :
2054 [ # # ]: 0 : if (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER ||
2055 [ # # ]: 0 : dev->data->mtu + HNS3_ETH_OVERHEAD > hw->rx_buf_len)
2056 : 0 : dev->data->scattered_rx = true;
2057 : : }
2058 : :
2059 : : const uint32_t *
2060 : 0 : hns3_dev_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
2061 : : {
2062 : : static const uint32_t ptypes[] = {
2063 : : RTE_PTYPE_L2_ETHER,
2064 : : RTE_PTYPE_L2_ETHER_LLDP,
2065 : : RTE_PTYPE_L2_ETHER_ARP,
2066 : : RTE_PTYPE_L3_IPV4,
2067 : : RTE_PTYPE_L3_IPV4_EXT,
2068 : : RTE_PTYPE_L3_IPV6,
2069 : : RTE_PTYPE_L3_IPV6_EXT,
2070 : : RTE_PTYPE_L4_IGMP,
2071 : : RTE_PTYPE_L4_ICMP,
2072 : : RTE_PTYPE_L4_SCTP,
2073 : : RTE_PTYPE_L4_TCP,
2074 : : RTE_PTYPE_L4_UDP,
2075 : : RTE_PTYPE_TUNNEL_GRE,
2076 : : RTE_PTYPE_INNER_L2_ETHER,
2077 : : RTE_PTYPE_INNER_L3_IPV4,
2078 : : RTE_PTYPE_INNER_L3_IPV6,
2079 : : RTE_PTYPE_INNER_L3_IPV4_EXT,
2080 : : RTE_PTYPE_INNER_L3_IPV6_EXT,
2081 : : RTE_PTYPE_INNER_L4_UDP,
2082 : : RTE_PTYPE_INNER_L4_TCP,
2083 : : RTE_PTYPE_INNER_L4_SCTP,
2084 : : RTE_PTYPE_INNER_L4_ICMP,
2085 : : RTE_PTYPE_TUNNEL_GRENAT,
2086 : : RTE_PTYPE_TUNNEL_NVGRE,
2087 : : };
2088 : : static const uint32_t adv_layout_ptypes[] = {
2089 : : RTE_PTYPE_L2_ETHER,
2090 : : RTE_PTYPE_L2_ETHER_TIMESYNC,
2091 : : RTE_PTYPE_L2_ETHER_LLDP,
2092 : : RTE_PTYPE_L2_ETHER_ARP,
2093 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
2094 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
2095 : : RTE_PTYPE_L4_FRAG,
2096 : : RTE_PTYPE_L4_NONFRAG,
2097 : : RTE_PTYPE_L4_UDP,
2098 : : RTE_PTYPE_L4_TCP,
2099 : : RTE_PTYPE_L4_SCTP,
2100 : : RTE_PTYPE_L4_IGMP,
2101 : : RTE_PTYPE_L4_ICMP,
2102 : : RTE_PTYPE_TUNNEL_GRE,
2103 : : RTE_PTYPE_TUNNEL_GRENAT,
2104 : : RTE_PTYPE_INNER_L2_ETHER,
2105 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
2106 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
2107 : : RTE_PTYPE_INNER_L4_FRAG,
2108 : : RTE_PTYPE_INNER_L4_ICMP,
2109 : : RTE_PTYPE_INNER_L4_NONFRAG,
2110 : : RTE_PTYPE_INNER_L4_UDP,
2111 : : RTE_PTYPE_INNER_L4_TCP,
2112 : : RTE_PTYPE_INNER_L4_SCTP,
2113 : : RTE_PTYPE_INNER_L4_ICMP,
2114 : : };
2115 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2116 : :
2117 [ # # # # ]: 0 : if (dev->rx_pkt_burst == hns3_recv_pkts_simple ||
2118 [ # # ]: 0 : dev->rx_pkt_burst == hns3_recv_scattered_pkts ||
2119 [ # # ]: 0 : dev->rx_pkt_burst == hns3_recv_pkts_vec ||
2120 : : dev->rx_pkt_burst == hns3_recv_pkts_vec_sve) {
2121 [ # # ]: 0 : if (hns3_dev_get_support(hw, RXD_ADV_LAYOUT)) {
2122 : 0 : *no_of_elements = RTE_DIM(adv_layout_ptypes);
2123 : 0 : return adv_layout_ptypes;
2124 : : } else {
2125 : 0 : *no_of_elements = RTE_DIM(ptypes);
2126 : 0 : return ptypes;
2127 : : }
2128 : : }
2129 : :
2130 : : return NULL;
2131 : : }
2132 : :
2133 : : static void
2134 : : hns3_init_non_tunnel_ptype_tbl(struct hns3_ptype_table *tbl)
2135 : : {
2136 : 0 : tbl->l3table[0] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4;
2137 : 0 : tbl->l3table[1] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6;
2138 : 0 : tbl->l3table[2] = RTE_PTYPE_L2_ETHER_ARP;
2139 : 0 : tbl->l3table[4] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT;
2140 : 0 : tbl->l3table[5] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT;
2141 : 0 : tbl->l3table[6] = RTE_PTYPE_L2_ETHER_LLDP;
2142 : :
2143 : 0 : tbl->l4table[0] = RTE_PTYPE_L4_UDP;
2144 : 0 : tbl->l4table[1] = RTE_PTYPE_L4_TCP;
2145 : 0 : tbl->l4table[2] = RTE_PTYPE_TUNNEL_GRE;
2146 : 0 : tbl->l4table[3] = RTE_PTYPE_L4_SCTP;
2147 : 0 : tbl->l4table[4] = RTE_PTYPE_L4_IGMP;
2148 : 0 : tbl->l4table[5] = RTE_PTYPE_L4_ICMP;
2149 : : }
2150 : :
2151 : : static void
2152 : : hns3_init_tunnel_ptype_tbl(struct hns3_ptype_table *tbl)
2153 : : {
2154 : 0 : tbl->inner_l3table[0] = RTE_PTYPE_INNER_L2_ETHER |
2155 : : RTE_PTYPE_INNER_L3_IPV4;
2156 : 0 : tbl->inner_l3table[1] = RTE_PTYPE_INNER_L2_ETHER |
2157 : : RTE_PTYPE_INNER_L3_IPV6;
2158 : : /* There is not a ptype for inner ARP/RARP */
2159 : 0 : tbl->inner_l3table[2] = RTE_PTYPE_UNKNOWN;
2160 : 0 : tbl->inner_l3table[3] = RTE_PTYPE_UNKNOWN;
2161 : 0 : tbl->inner_l3table[4] = RTE_PTYPE_INNER_L2_ETHER |
2162 : : RTE_PTYPE_INNER_L3_IPV4_EXT;
2163 : 0 : tbl->inner_l3table[5] = RTE_PTYPE_INNER_L2_ETHER |
2164 : : RTE_PTYPE_INNER_L3_IPV6_EXT;
2165 : :
2166 : 0 : tbl->inner_l4table[0] = RTE_PTYPE_INNER_L4_UDP;
2167 : 0 : tbl->inner_l4table[1] = RTE_PTYPE_INNER_L4_TCP;
2168 : : /* There is not a ptype for inner GRE */
2169 : 0 : tbl->inner_l4table[2] = RTE_PTYPE_UNKNOWN;
2170 : 0 : tbl->inner_l4table[3] = RTE_PTYPE_INNER_L4_SCTP;
2171 : : /* There is not a ptype for inner IGMP */
2172 : 0 : tbl->inner_l4table[4] = RTE_PTYPE_UNKNOWN;
2173 : 0 : tbl->inner_l4table[5] = RTE_PTYPE_INNER_L4_ICMP;
2174 : :
2175 : 0 : tbl->ol3table[0] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4;
2176 : 0 : tbl->ol3table[1] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6;
2177 : 0 : tbl->ol3table[2] = RTE_PTYPE_UNKNOWN;
2178 : 0 : tbl->ol3table[3] = RTE_PTYPE_UNKNOWN;
2179 : 0 : tbl->ol3table[4] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT;
2180 : 0 : tbl->ol3table[5] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT;
2181 : :
2182 : 0 : tbl->ol4table[0] = RTE_PTYPE_UNKNOWN;
2183 : 0 : tbl->ol4table[1] = RTE_PTYPE_L4_UDP | RTE_PTYPE_TUNNEL_GRENAT;
2184 : 0 : tbl->ol4table[2] = RTE_PTYPE_TUNNEL_NVGRE;
2185 : : }
2186 : :
2187 : : static void
2188 : 0 : hns3_init_adv_layout_ptype(struct hns3_ptype_table *tbl)
2189 : : {
2190 : : uint32_t *ptype = tbl->ptype;
2191 : :
2192 : : /* Non-tunnel L2 */
2193 : 0 : ptype[1] = RTE_PTYPE_L2_ETHER_ARP;
2194 : 0 : ptype[3] = RTE_PTYPE_L2_ETHER_LLDP;
2195 : 0 : ptype[8] = RTE_PTYPE_L2_ETHER_TIMESYNC;
2196 : :
2197 : : /* Non-tunnel IPv4 */
2198 : 0 : ptype[17] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2199 : : RTE_PTYPE_L4_FRAG;
2200 : 0 : ptype[18] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2201 : : RTE_PTYPE_L4_NONFRAG;
2202 : 0 : ptype[19] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2203 : : RTE_PTYPE_L4_UDP;
2204 : 0 : ptype[20] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2205 : : RTE_PTYPE_L4_TCP;
2206 : 0 : ptype[21] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2207 : : RTE_PTYPE_TUNNEL_GRE;
2208 : 0 : ptype[22] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2209 : : RTE_PTYPE_L4_SCTP;
2210 : 0 : ptype[23] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2211 : : RTE_PTYPE_L4_IGMP;
2212 : 0 : ptype[24] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2213 : : RTE_PTYPE_L4_ICMP;
2214 : : /* The next ptype is PTP over IPv4 + UDP */
2215 : 0 : ptype[25] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2216 : : RTE_PTYPE_L4_UDP;
2217 : :
2218 : : /* IPv4 --> GRE/Teredo/VXLAN */
2219 : 0 : ptype[29] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2220 : : RTE_PTYPE_TUNNEL_GRENAT;
2221 : : /* IPv4 --> GRE/Teredo/VXLAN --> MAC */
2222 : 0 : ptype[30] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2223 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER;
2224 : :
2225 : : /* IPv4 --> GRE/Teredo/VXLAN --> MAC --> IPv4 */
2226 : 0 : ptype[31] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2227 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2228 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2229 : : RTE_PTYPE_INNER_L4_FRAG;
2230 : 0 : ptype[32] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2231 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2232 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2233 : : RTE_PTYPE_INNER_L4_NONFRAG;
2234 : 0 : ptype[33] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2235 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2236 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2237 : : RTE_PTYPE_INNER_L4_UDP;
2238 : 0 : ptype[34] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2239 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2240 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2241 : : RTE_PTYPE_INNER_L4_TCP;
2242 : 0 : ptype[35] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2243 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2244 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2245 : : RTE_PTYPE_INNER_L4_SCTP;
2246 : : /* The next ptype's inner L4 is IGMP */
2247 : 0 : ptype[36] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2248 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2249 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
2250 : 0 : ptype[37] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2251 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2252 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2253 : : RTE_PTYPE_INNER_L4_ICMP;
2254 : :
2255 : : /* IPv4 --> GRE/Teredo/VXLAN --> MAC --> IPv6 */
2256 : 0 : ptype[39] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2257 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2258 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2259 : : RTE_PTYPE_INNER_L4_FRAG;
2260 : 0 : ptype[40] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2261 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2262 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2263 : : RTE_PTYPE_INNER_L4_NONFRAG;
2264 : 0 : ptype[41] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2265 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2266 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2267 : : RTE_PTYPE_INNER_L4_UDP;
2268 : 0 : ptype[42] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2269 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2270 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2271 : : RTE_PTYPE_INNER_L4_TCP;
2272 : 0 : ptype[43] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2273 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2274 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2275 : : RTE_PTYPE_INNER_L4_SCTP;
2276 : : /* The next ptype's inner L4 is IGMP */
2277 : 0 : ptype[44] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2278 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2279 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
2280 : 0 : ptype[45] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2281 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2282 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2283 : : RTE_PTYPE_INNER_L4_ICMP;
2284 : :
2285 : : /* Non-tunnel IPv6 */
2286 : 0 : ptype[111] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2287 : : RTE_PTYPE_L4_FRAG;
2288 : 0 : ptype[112] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2289 : : RTE_PTYPE_L4_NONFRAG;
2290 : 0 : ptype[113] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2291 : : RTE_PTYPE_L4_UDP;
2292 : 0 : ptype[114] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2293 : : RTE_PTYPE_L4_TCP;
2294 : 0 : ptype[115] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2295 : : RTE_PTYPE_TUNNEL_GRE;
2296 : 0 : ptype[116] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2297 : : RTE_PTYPE_L4_SCTP;
2298 : 0 : ptype[117] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2299 : : RTE_PTYPE_L4_IGMP;
2300 : 0 : ptype[118] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2301 : : RTE_PTYPE_L4_ICMP;
2302 : : /* Special for PTP over IPv6 + UDP */
2303 : 0 : ptype[119] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2304 : : RTE_PTYPE_L4_UDP;
2305 : :
2306 : : /* IPv6 --> GRE/Teredo/VXLAN */
2307 : 0 : ptype[123] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2308 : : RTE_PTYPE_TUNNEL_GRENAT;
2309 : : /* IPv6 --> GRE/Teredo/VXLAN --> MAC */
2310 : 0 : ptype[124] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2311 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER;
2312 : :
2313 : : /* IPv6 --> GRE/Teredo/VXLAN --> MAC --> IPv4 */
2314 : 0 : ptype[125] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2315 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2316 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2317 : : RTE_PTYPE_INNER_L4_FRAG;
2318 : 0 : ptype[126] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2319 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2320 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2321 : : RTE_PTYPE_INNER_L4_NONFRAG;
2322 : 0 : ptype[127] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2323 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2324 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2325 : : RTE_PTYPE_INNER_L4_UDP;
2326 : 0 : ptype[128] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2327 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2328 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2329 : : RTE_PTYPE_INNER_L4_TCP;
2330 : 0 : ptype[129] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2331 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2332 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2333 : : RTE_PTYPE_INNER_L4_SCTP;
2334 : : /* The next ptype's inner L4 is IGMP */
2335 : 0 : ptype[130] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2336 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2337 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
2338 : 0 : ptype[131] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2339 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2340 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2341 : : RTE_PTYPE_INNER_L4_ICMP;
2342 : :
2343 : : /* IPv6 --> GRE/Teredo/VXLAN --> MAC --> IPv6 */
2344 : 0 : ptype[133] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2345 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2346 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2347 : : RTE_PTYPE_INNER_L4_FRAG;
2348 : 0 : ptype[134] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2349 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2350 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2351 : : RTE_PTYPE_INNER_L4_NONFRAG;
2352 : 0 : ptype[135] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2353 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2354 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2355 : : RTE_PTYPE_INNER_L4_UDP;
2356 : 0 : ptype[136] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2357 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2358 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2359 : : RTE_PTYPE_INNER_L4_TCP;
2360 : 0 : ptype[137] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2361 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2362 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2363 : : RTE_PTYPE_INNER_L4_SCTP;
2364 : : /* The next ptype's inner L4 is IGMP */
2365 : 0 : ptype[138] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2366 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2367 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
2368 : 0 : ptype[139] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2369 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2370 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2371 : : RTE_PTYPE_INNER_L4_ICMP;
2372 : 0 : }
2373 : :
2374 : : void
2375 : 0 : hns3_init_rx_ptype_tble(struct rte_eth_dev *dev)
2376 : : {
2377 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
2378 : 0 : struct hns3_ptype_table *tbl = &hns->ptype_tbl;
2379 : :
2380 : : memset(tbl, 0, sizeof(*tbl));
2381 : :
2382 : : hns3_init_non_tunnel_ptype_tbl(tbl);
2383 : : hns3_init_tunnel_ptype_tbl(tbl);
2384 : 0 : hns3_init_adv_layout_ptype(tbl);
2385 : 0 : }
2386 : :
2387 : : static inline void
2388 : 0 : hns3_rxd_to_vlan_tci(struct hns3_rx_queue *rxq, struct rte_mbuf *mb,
2389 : : uint32_t l234_info, const struct hns3_desc *rxd)
2390 : : {
2391 : : #define HNS3_STRP_STATUS_NUM 0x4
2392 : :
2393 : : #define HNS3_NO_STRP_VLAN_VLD 0x0
2394 : : #define HNS3_INNER_STRP_VLAN_VLD 0x1
2395 : : #define HNS3_OUTER_STRP_VLAN_VLD 0x2
2396 : : uint32_t strip_status;
2397 : : uint32_t report_mode;
2398 : :
2399 : : /*
2400 : : * Since HW limitation, the vlan tag will always be inserted into RX
2401 : : * descriptor when strip the tag from packet, driver needs to determine
2402 : : * reporting which tag to mbuf according to the PVID configuration
2403 : : * and vlan striped status.
2404 : : */
2405 : : static const uint32_t report_type[][HNS3_STRP_STATUS_NUM] = {
2406 : : {
2407 : : HNS3_NO_STRP_VLAN_VLD,
2408 : : HNS3_OUTER_STRP_VLAN_VLD,
2409 : : HNS3_INNER_STRP_VLAN_VLD,
2410 : : HNS3_OUTER_STRP_VLAN_VLD
2411 : : },
2412 : : {
2413 : : HNS3_NO_STRP_VLAN_VLD,
2414 : : HNS3_NO_STRP_VLAN_VLD,
2415 : : HNS3_NO_STRP_VLAN_VLD,
2416 : : HNS3_INNER_STRP_VLAN_VLD
2417 : : }
2418 : : };
2419 : 0 : strip_status = hns3_get_field(l234_info, HNS3_RXD_STRP_TAGP_M,
2420 : : HNS3_RXD_STRP_TAGP_S);
2421 : 0 : report_mode = report_type[rxq->pvid_sw_discard_en][strip_status];
2422 [ # # # # ]: 0 : switch (report_mode) {
2423 : 0 : case HNS3_NO_STRP_VLAN_VLD:
2424 : 0 : mb->vlan_tci = 0;
2425 : 0 : return;
2426 : 0 : case HNS3_INNER_STRP_VLAN_VLD:
2427 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
2428 : 0 : mb->vlan_tci = rte_le_to_cpu_16(rxd->rx.vlan_tag);
2429 : 0 : return;
2430 : 0 : case HNS3_OUTER_STRP_VLAN_VLD:
2431 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
2432 : 0 : mb->vlan_tci = rte_le_to_cpu_16(rxd->rx.ot_vlan_tag);
2433 : 0 : return;
2434 : 0 : default:
2435 : 0 : mb->vlan_tci = 0;
2436 : 0 : return;
2437 : : }
2438 : : }
2439 : :
2440 : : static inline void
2441 : : recalculate_data_len(struct rte_mbuf *last_seg, struct rte_mbuf *rxm,
2442 : : struct hns3_rx_queue *rxq)
2443 : : {
2444 : 0 : uint16_t data_len = rxm->data_len;
2445 : : uint8_t crc_len = rxq->crc_len;
2446 : :
2447 : 0 : if (data_len <= crc_len) {
2448 : 0 : rxm->data_len = 0;
2449 : 0 : last_seg->data_len = (uint16_t)(last_seg->data_len -
2450 : : (crc_len - data_len));
2451 : : } else
2452 : 0 : rxm->data_len = (uint16_t)(data_len - crc_len);
2453 : : }
2454 : :
2455 : : static inline struct rte_mbuf *
2456 : 0 : hns3_rx_alloc_buffer(struct hns3_rx_queue *rxq)
2457 : : {
2458 : : int ret;
2459 : :
2460 [ # # ]: 0 : if (likely(rxq->bulk_mbuf_num > 0))
2461 : 0 : return rxq->bulk_mbuf[--rxq->bulk_mbuf_num];
2462 : :
2463 [ # # ]: 0 : ret = rte_mempool_get_bulk(rxq->mb_pool, (void **)rxq->bulk_mbuf,
2464 : : HNS3_BULK_ALLOC_MBUF_NUM);
2465 [ # # ]: 0 : if (likely(ret == 0)) {
2466 : : rxq->bulk_mbuf_num = HNS3_BULK_ALLOC_MBUF_NUM;
2467 : 0 : return rxq->bulk_mbuf[--rxq->bulk_mbuf_num];
2468 : : } else
2469 : 0 : return rte_mbuf_raw_alloc(rxq->mb_pool);
2470 : : }
2471 : :
2472 : : static void
2473 : : hns3_rx_ptp_timestamp_handle(struct hns3_rx_queue *rxq, struct rte_mbuf *mbuf,
2474 : : uint64_t timestamp)
2475 : : {
2476 : 0 : struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(rxq->hns);
2477 : :
2478 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_IEEE1588_TMST;
2479 [ # # ]: 0 : if (hns3_timestamp_rx_dynflag > 0) {
2480 : 0 : *RTE_MBUF_DYNFIELD(mbuf, hns3_timestamp_dynfield_offset,
2481 : 0 : rte_mbuf_timestamp_t *) = timestamp;
2482 : 0 : mbuf->ol_flags |= hns3_timestamp_rx_dynflag;
2483 : : }
2484 : :
2485 : 0 : pf->rx_timestamp = timestamp;
2486 : 0 : }
2487 : :
2488 : : static inline bool
2489 : : hns3_need_recalculate_crc(struct hns3_rx_queue *rxq, struct rte_mbuf *m)
2490 : : {
2491 : : uint32_t ptype = m->packet_type;
2492 : :
2493 [ # # # # ]: 0 : if (rxq->keep_crc_fail_ptype == HNS3_STRIP_CRC_PTYPE_NONE)
2494 : : return false;
2495 : :
2496 [ # # # # ]: 0 : if (m->pkt_len > HNS3_KEEP_CRC_OK_MIN_PKT_LEN)
2497 : : return false;
2498 : :
2499 [ # # # # ]: 0 : if (!(RTE_ETH_IS_IPV4_HDR(ptype) || RTE_ETH_IS_IPV6_HDR(ptype)))
2500 : : return false;
2501 : :
2502 [ # # # # ]: 0 : if (rxq->keep_crc_fail_ptype == HNS3_STRIP_CRC_PTYPE_TCP)
2503 : 0 : return (ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP;
2504 : :
2505 : : return true;
2506 : : }
2507 : :
2508 : : /*
2509 : : * The hns3 driver requires that mbuf size must be at least 512B.
2510 : : * When CRC is stripped by hardware, the pkt_len must be less than
2511 : : * or equal to 60B. Therefore, the space of the mbuf is enough
2512 : : * to insert the CRC.
2513 : : */
2514 : : static_assert(HNS3_KEEP_CRC_OK_MIN_PKT_LEN < HNS3_MIN_BD_BUF_SIZE,
2515 : : "buffer size too small to insert CRC");
2516 : :
2517 : : static inline void
2518 : 0 : hns3_recalculate_crc(struct hns3_rx_queue *rxq, struct rte_mbuf *m)
2519 : : {
2520 : : char *append_data;
2521 : : uint32_t crc;
2522 : :
2523 : 0 : crc = rte_net_crc_calc(rxq->crc_ctx, rte_pktmbuf_mtod(m, void *), m->data_len);
2524 : :
2525 : : /*
2526 : : * After CRC is stripped by hardware, pkt_len and data_len do not
2527 : : * contain the CRC length. Therefore, after CRC data is appended
2528 : : * by PMD again.
2529 : : */
2530 : : append_data = rte_pktmbuf_append(m, RTE_ETHER_CRC_LEN);
2531 : :
2532 : : /* CRC data is binary data and does not care about the byte order. */
2533 : : memcpy(append_data, &crc, RTE_ETHER_CRC_LEN);
2534 : 0 : }
2535 : :
2536 : : uint16_t
2537 : 0 : hns3_recv_pkts_simple(void *rx_queue,
2538 : : struct rte_mbuf **rx_pkts,
2539 : : uint16_t nb_pkts)
2540 : 0 : {
2541 : : volatile struct hns3_desc *rx_ring; /* RX ring (desc) */
2542 : : volatile struct hns3_desc *rxdp; /* pointer of the current desc */
2543 : : struct hns3_rx_queue *rxq; /* RX queue */
2544 : : struct hns3_entry *sw_ring;
2545 : : struct hns3_entry *rxe;
2546 : : struct hns3_desc rxd;
2547 : : struct rte_mbuf *nmb; /* pointer of the new mbuf */
2548 : : struct rte_mbuf *rxm;
2549 : : uint32_t bd_base_info;
2550 : : uint32_t l234_info;
2551 : : uint32_t ol_info;
2552 : : uint64_t dma_addr;
2553 : : uint16_t nb_rx_bd;
2554 : : uint16_t nb_rx;
2555 : : uint16_t rx_id;
2556 : : int ret;
2557 : :
2558 : : nb_rx = 0;
2559 : : nb_rx_bd = 0;
2560 : : rxq = rx_queue;
2561 : 0 : rx_ring = rxq->rx_ring;
2562 : 0 : sw_ring = rxq->sw_ring;
2563 : 0 : rx_id = rxq->next_to_use;
2564 : :
2565 [ # # ]: 0 : while (nb_rx < nb_pkts) {
2566 : 0 : rxdp = &rx_ring[rx_id];
2567 : 0 : bd_base_info = rte_le_to_cpu_32(rxdp->rx.bd_base_info);
2568 [ # # ]: 0 : if (unlikely(!(bd_base_info & BIT(HNS3_RXD_VLD_B))))
2569 : : break;
2570 : :
2571 : 0 : rxd = rxdp[(bd_base_info & (1u << HNS3_RXD_VLD_B)) -
2572 : : (1u << HNS3_RXD_VLD_B)];
2573 : :
2574 : 0 : nmb = hns3_rx_alloc_buffer(rxq);
2575 [ # # ]: 0 : if (unlikely(nmb == NULL)) {
2576 : 0 : rte_eth_devices[rxq->port_id].data->
2577 : 0 : rx_mbuf_alloc_failed++;
2578 : 0 : break;
2579 : : }
2580 : :
2581 : 0 : nb_rx_bd++;
2582 : 0 : rxe = &sw_ring[rx_id];
2583 : 0 : rx_id++;
2584 [ # # ]: 0 : if (unlikely(rx_id == rxq->nb_rx_desc))
2585 : : rx_id = 0;
2586 : :
2587 : 0 : rte_prefetch0(sw_ring[rx_id].mbuf);
2588 [ # # ]: 0 : if ((rx_id & HNS3_RX_RING_PREFETCTH_MASK) == 0) {
2589 : 0 : rte_prefetch0(&rx_ring[rx_id]);
2590 : : rte_prefetch0(&sw_ring[rx_id]);
2591 : : }
2592 : :
2593 : 0 : rxm = rxe->mbuf;
2594 : 0 : rxm->ol_flags = 0;
2595 : 0 : rxe->mbuf = nmb;
2596 : :
2597 [ # # ]: 0 : if (unlikely(bd_base_info & BIT(HNS3_RXD_TS_VLD_B)))
2598 : : hns3_rx_ptp_timestamp_handle(rxq, rxm,
2599 [ # # ]: 0 : rte_le_to_cpu_64(rxdp->timestamp));
2600 : :
2601 : : dma_addr = rte_mbuf_data_iova_default(nmb);
2602 : 0 : rxdp->addr = rte_cpu_to_le_64(dma_addr);
2603 : 0 : rxdp->rx.bd_base_info = 0;
2604 : :
2605 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
2606 : 0 : rxm->pkt_len = (uint16_t)(rte_le_to_cpu_16(rxd.rx.pkt_len));
2607 : 0 : rxm->data_len = rxm->pkt_len;
2608 : 0 : rxm->port = rxq->port_id;
2609 : 0 : rxm->hash.rss = rte_le_to_cpu_32(rxd.rx.rss_hash);
2610 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
2611 [ # # ]: 0 : if (unlikely(bd_base_info & BIT(HNS3_RXD_LUM_B))) {
2612 : 0 : rxm->hash.fdir.hi =
2613 : 0 : rte_le_to_cpu_16(rxd.rx.fd_id);
2614 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
2615 : : }
2616 : 0 : rxm->nb_segs = 1;
2617 : 0 : rxm->next = NULL;
2618 : :
2619 : : /* Load remained descriptor data and extract necessary fields */
2620 : 0 : l234_info = rte_le_to_cpu_32(rxd.rx.l234_info);
2621 : 0 : ol_info = rte_le_to_cpu_32(rxd.rx.ol_info);
2622 : 0 : ret = hns3_handle_bdinfo(rxq, rxm, bd_base_info, l234_info);
2623 [ # # ]: 0 : if (unlikely(ret))
2624 : 0 : goto pkt_err;
2625 : :
2626 : 0 : rxm->packet_type = hns3_rx_calc_ptype(rxq, l234_info, ol_info);
2627 : :
2628 [ # # ]: 0 : if (rxm->packet_type == RTE_PTYPE_L2_ETHER_TIMESYNC)
2629 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_IEEE1588_PTP;
2630 : :
2631 [ # # # # ]: 0 : if (unlikely(rxq->crc_len > 0) &&
2632 : : hns3_need_recalculate_crc(rxq, rxm))
2633 : 0 : hns3_recalculate_crc(rxq, rxm);
2634 : 0 : rxm->pkt_len -= rxq->crc_len;
2635 : 0 : rxm->data_len -= rxq->crc_len;
2636 : :
2637 : 0 : hns3_rxd_to_vlan_tci(rxq, rxm, l234_info, &rxd);
2638 : :
2639 : : /* Increment bytes counter */
2640 : 0 : rxq->basic_stats.bytes += rxm->pkt_len;
2641 : :
2642 : 0 : rx_pkts[nb_rx++] = rxm;
2643 : 0 : continue;
2644 : : pkt_err:
2645 : 0 : rte_pktmbuf_free(rxm);
2646 : : }
2647 : :
2648 : 0 : rxq->next_to_use = rx_id;
2649 : 0 : rxq->rx_free_hold += nb_rx_bd;
2650 [ # # ]: 0 : if (rxq->rx_free_hold > rxq->rx_free_thresh) {
2651 : 0 : hns3_write_reg_opt(rxq->io_head_reg, rxq->rx_free_hold);
2652 : 0 : rxq->rx_free_hold = 0;
2653 : : }
2654 : :
2655 : 0 : return nb_rx;
2656 : : }
2657 : :
2658 : : uint16_t
2659 : 0 : hns3_recv_scattered_pkts(void *rx_queue,
2660 : : struct rte_mbuf **rx_pkts,
2661 : : uint16_t nb_pkts)
2662 : 0 : {
2663 : : volatile struct hns3_desc *rx_ring; /* RX ring (desc) */
2664 : : volatile struct hns3_desc *rxdp; /* pointer of the current desc */
2665 : : struct hns3_rx_queue *rxq; /* RX queue */
2666 : : struct hns3_entry *sw_ring;
2667 : : struct hns3_entry *rxe;
2668 : : struct rte_mbuf *first_seg;
2669 : : struct rte_mbuf *last_seg;
2670 : : struct hns3_desc rxd;
2671 : : struct rte_mbuf *nmb; /* pointer of the new mbuf */
2672 : : struct rte_mbuf *rxm;
2673 : : struct rte_eth_dev *dev;
2674 : : uint32_t bd_base_info;
2675 : : uint64_t timestamp;
2676 : : uint32_t l234_info;
2677 : : uint32_t gro_size;
2678 : : uint32_t ol_info;
2679 : : uint64_t dma_addr;
2680 : : uint16_t nb_rx_bd;
2681 : : uint16_t nb_rx;
2682 : : uint16_t rx_id;
2683 : : int ret;
2684 : :
2685 : : nb_rx = 0;
2686 : : nb_rx_bd = 0;
2687 : : rxq = rx_queue;
2688 : :
2689 : 0 : rx_id = rxq->next_to_use;
2690 : 0 : rx_ring = rxq->rx_ring;
2691 : 0 : sw_ring = rxq->sw_ring;
2692 : 0 : first_seg = rxq->pkt_first_seg;
2693 : 0 : last_seg = rxq->pkt_last_seg;
2694 : :
2695 [ # # ]: 0 : while (nb_rx < nb_pkts) {
2696 : 0 : rxdp = &rx_ring[rx_id];
2697 : 0 : bd_base_info = rte_le_to_cpu_32(rxdp->rx.bd_base_info);
2698 [ # # ]: 0 : if (unlikely(!(bd_base_info & BIT(HNS3_RXD_VLD_B))))
2699 : : break;
2700 : :
2701 : : /*
2702 : : * The interactive process between software and hardware of
2703 : : * receiving a new packet in hns3 network engine:
2704 : : * 1. Hardware network engine firstly writes the packet content
2705 : : * to the memory pointed by the 'addr' field of the Rx Buffer
2706 : : * Descriptor, secondly fills the result of parsing the
2707 : : * packet include the valid field into the Rx Buffer
2708 : : * Descriptor in one write operation.
2709 : : * 2. Driver reads the Rx BD's valid field in the loop to check
2710 : : * whether it's valid, if valid then assign a new address to
2711 : : * the addr field, clear the valid field, get the other
2712 : : * information of the packet by parsing Rx BD's other fields,
2713 : : * finally write back the number of Rx BDs processed by the
2714 : : * driver to the HNS3_RING_RX_HEAD_REG register to inform
2715 : : * hardware.
2716 : : * In the above process, the ordering is very important. We must
2717 : : * make sure that CPU read Rx BD's other fields only after the
2718 : : * Rx BD is valid.
2719 : : *
2720 : : * There are two type of re-ordering: compiler re-ordering and
2721 : : * CPU re-ordering under the ARMv8 architecture.
2722 : : * 1. we use volatile to deal with compiler re-ordering, so you
2723 : : * can see that rx_ring/rxdp defined with volatile.
2724 : : * 2. we commonly use memory barrier to deal with CPU
2725 : : * re-ordering, but the cost is high.
2726 : : *
2727 : : * In order to solve the high cost of using memory barrier, we
2728 : : * use the data dependency order under the ARMv8 architecture,
2729 : : * for example:
2730 : : * instr01: load A
2731 : : * instr02: load B <- A
2732 : : * the instr02 will always execute after instr01.
2733 : : *
2734 : : * To construct the data dependency ordering, we use the
2735 : : * following assignment:
2736 : : * rxd = rxdp[(bd_base_info & (1u << HNS3_RXD_VLD_B)) -
2737 : : * (1u<<HNS3_RXD_VLD_B)]
2738 : : * Using gcc compiler under the ARMv8 architecture, the related
2739 : : * assembly code example as follows:
2740 : : * note: (1u << HNS3_RXD_VLD_B) equal 0x10
2741 : : * instr01: ldr w26, [x22, #28] --read bd_base_info
2742 : : * instr02: and w0, w26, #0x10 --calc bd_base_info & 0x10
2743 : : * instr03: sub w0, w0, #0x10 --calc (bd_base_info &
2744 : : * 0x10) - 0x10
2745 : : * instr04: add x0, x22, x0, lsl #5 --calc copy source addr
2746 : : * instr05: ldp x2, x3, [x0]
2747 : : * instr06: stp x2, x3, [x29, #256] --copy BD's [0 ~ 15]B
2748 : : * instr07: ldp x4, x5, [x0, #16]
2749 : : * instr08: stp x4, x5, [x29, #272] --copy BD's [16 ~ 31]B
2750 : : * the instr05~08 depend on x0's value, x0 depent on w26's
2751 : : * value, the w26 is the bd_base_info, this form the data
2752 : : * dependency ordering.
2753 : : * note: if BD is valid, (bd_base_info & (1u<<HNS3_RXD_VLD_B)) -
2754 : : * (1u<<HNS3_RXD_VLD_B) will always zero, so the
2755 : : * assignment is correct.
2756 : : *
2757 : : * So we use the data dependency ordering instead of memory
2758 : : * barrier to improve receive performance.
2759 : : */
2760 : 0 : rxd = rxdp[(bd_base_info & (1u << HNS3_RXD_VLD_B)) -
2761 : : (1u << HNS3_RXD_VLD_B)];
2762 : : RX_BD_LOG(&rxq->hns->hw, DEBUG, &rxd);
2763 : :
2764 : 0 : nmb = hns3_rx_alloc_buffer(rxq);
2765 [ # # ]: 0 : if (unlikely(nmb == NULL)) {
2766 : 0 : dev = &rte_eth_devices[rxq->port_id];
2767 : 0 : dev->data->rx_mbuf_alloc_failed++;
2768 : 0 : break;
2769 : : }
2770 : :
2771 : 0 : nb_rx_bd++;
2772 : 0 : rxe = &sw_ring[rx_id];
2773 : 0 : rx_id++;
2774 [ # # ]: 0 : if (unlikely(rx_id == rxq->nb_rx_desc))
2775 : : rx_id = 0;
2776 : :
2777 : 0 : rte_prefetch0(sw_ring[rx_id].mbuf);
2778 [ # # ]: 0 : if ((rx_id & HNS3_RX_RING_PREFETCTH_MASK) == 0) {
2779 : 0 : rte_prefetch0(&rx_ring[rx_id]);
2780 : : rte_prefetch0(&sw_ring[rx_id]);
2781 : : }
2782 : :
2783 : 0 : rxm = rxe->mbuf;
2784 : 0 : rxe->mbuf = nmb;
2785 : :
2786 [ # # ]: 0 : if (unlikely(bd_base_info & BIT(HNS3_RXD_TS_VLD_B)))
2787 : 0 : timestamp = rte_le_to_cpu_64(rxdp->timestamp);
2788 : :
2789 : : dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
2790 : 0 : rxdp->rx.bd_base_info = 0;
2791 : 0 : rxdp->addr = dma_addr;
2792 : :
2793 [ # # ]: 0 : if (first_seg == NULL) {
2794 : : first_seg = rxm;
2795 : 0 : first_seg->nb_segs = 1;
2796 : : } else {
2797 : 0 : first_seg->nb_segs++;
2798 : 0 : last_seg->next = rxm;
2799 : : }
2800 : :
2801 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
2802 : 0 : rxm->data_len = rte_le_to_cpu_16(rxd.rx.size);
2803 : 0 : rxm->next = NULL;
2804 : :
2805 [ # # ]: 0 : if (!(bd_base_info & BIT(HNS3_RXD_FE_B))) {
2806 : : last_seg = rxm;
2807 : 0 : continue;
2808 : : }
2809 : :
2810 : 0 : first_seg->ol_flags = 0;
2811 [ # # ]: 0 : if (unlikely(bd_base_info & BIT(HNS3_RXD_TS_VLD_B)))
2812 : : hns3_rx_ptp_timestamp_handle(rxq, first_seg, timestamp);
2813 : :
2814 : : /*
2815 : : * The last buffer of the received packet. packet len from
2816 : : * buffer description may contains CRC len, packet len should
2817 : : * subtract it, same as data len.
2818 : : */
2819 : 0 : first_seg->pkt_len = rte_le_to_cpu_16(rxd.rx.pkt_len);
2820 : :
2821 : 0 : first_seg->port = rxq->port_id;
2822 : 0 : first_seg->hash.rss = rte_le_to_cpu_32(rxd.rx.rss_hash);
2823 : 0 : first_seg->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
2824 [ # # ]: 0 : if (unlikely(bd_base_info & BIT(HNS3_RXD_LUM_B))) {
2825 : 0 : first_seg->hash.fdir.hi =
2826 : 0 : rte_le_to_cpu_16(rxd.rx.fd_id);
2827 : 0 : first_seg->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
2828 : : }
2829 : :
2830 : 0 : gro_size = hns3_get_field(bd_base_info, HNS3_RXD_GRO_SIZE_M,
2831 : : HNS3_RXD_GRO_SIZE_S);
2832 [ # # ]: 0 : if (gro_size != 0) {
2833 : 0 : first_seg->ol_flags |= RTE_MBUF_F_RX_LRO;
2834 : 0 : first_seg->tso_segsz = gro_size;
2835 : : }
2836 : :
2837 : 0 : l234_info = rte_le_to_cpu_32(rxd.rx.l234_info);
2838 : 0 : ol_info = rte_le_to_cpu_32(rxd.rx.ol_info);
2839 : 0 : ret = hns3_handle_bdinfo(rxq, first_seg, bd_base_info,
2840 : : l234_info);
2841 [ # # ]: 0 : if (unlikely(ret))
2842 : 0 : goto pkt_err;
2843 : :
2844 : 0 : first_seg->packet_type = hns3_rx_calc_ptype(rxq,
2845 : : l234_info, ol_info);
2846 : :
2847 [ # # ]: 0 : if (first_seg->packet_type == RTE_PTYPE_L2_ETHER_TIMESYNC)
2848 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_IEEE1588_PTP;
2849 : : /*
2850 : : * This is the last buffer of the received packet. If the CRC
2851 : : * is not stripped by the hardware:
2852 : : * - Subtract the CRC length from the total packet length.
2853 : : * - If the last buffer only contains the whole CRC or a part
2854 : : * of it, free the mbuf associated to the last buffer. If part
2855 : : * of the CRC is also contained in the previous mbuf, subtract
2856 : : * the length of that CRC part from the data length of the
2857 : : * previous mbuf.
2858 : : *
2859 : : * In addition, the CRC is still stripped for a kind of packets
2860 : : * in hns3 NIC:
2861 : : * 1. All IP-TCP packet whose the length is less than and equal
2862 : : * to 60 Byte (no CRC) on HIP08 network engine.
2863 : : * 2. All IP packet whose the length is less than and equal to
2864 : : * 60 Byte (no CRC) on HIP09 network engine.
2865 : : * In this case, the PMD calculates the CRC and appends it to
2866 : : * mbuf.
2867 : : */
2868 [ # # ]: 0 : if (unlikely(rxq->crc_len > 0)) {
2869 [ # # ]: 0 : if (hns3_need_recalculate_crc(rxq, first_seg))
2870 : 0 : hns3_recalculate_crc(rxq, first_seg);
2871 [ # # ]: 0 : first_seg->pkt_len -= rxq->crc_len;
2872 : : recalculate_data_len(last_seg, rxm, rxq);
2873 : : }
2874 : :
2875 : 0 : hns3_rxd_to_vlan_tci(rxq, first_seg, l234_info, &rxd);
2876 : :
2877 : : /* Increment bytes counter */
2878 : 0 : rxq->basic_stats.bytes += first_seg->pkt_len;
2879 : :
2880 : 0 : rx_pkts[nb_rx++] = first_seg;
2881 : : first_seg = NULL;
2882 : 0 : continue;
2883 : : pkt_err:
2884 : 0 : rte_pktmbuf_free(first_seg);
2885 : : first_seg = NULL;
2886 : : }
2887 : :
2888 : 0 : rxq->next_to_use = rx_id;
2889 : 0 : rxq->pkt_first_seg = first_seg;
2890 : 0 : rxq->pkt_last_seg = last_seg;
2891 : :
2892 : 0 : rxq->rx_free_hold += nb_rx_bd;
2893 [ # # ]: 0 : if (rxq->rx_free_hold > rxq->rx_free_thresh) {
2894 : 0 : hns3_write_reg_opt(rxq->io_head_reg, rxq->rx_free_hold);
2895 : 0 : rxq->rx_free_hold = 0;
2896 : : }
2897 : :
2898 : 0 : return nb_rx;
2899 : : }
2900 : :
2901 : : #ifndef RTE_ARCH_ARM64
2902 : : void
2903 : 0 : hns3_rxq_vec_setup(__rte_unused struct hns3_rx_queue *rxq)
2904 : : {
2905 : 0 : }
2906 : :
2907 : : int
2908 : 0 : hns3_rx_check_vec_support(__rte_unused struct rte_eth_dev *dev)
2909 : : {
2910 : 0 : return -ENOTSUP;
2911 : : }
2912 : :
2913 : : uint16_t
2914 : 0 : hns3_recv_pkts_vec(__rte_unused void *rx_queue,
2915 : : __rte_unused struct rte_mbuf **rx_pkts,
2916 : : __rte_unused uint16_t nb_pkts)
2917 : : {
2918 : 0 : return 0;
2919 : : }
2920 : : #endif /* RTE_ARCH_ARM64 */
2921 : :
2922 : : #ifndef RTE_HAS_SVE_ACLE
2923 : : uint16_t
2924 : 0 : hns3_recv_pkts_vec_sve(__rte_unused void *rx_queue,
2925 : : __rte_unused struct rte_mbuf **rx_pkts,
2926 : : __rte_unused uint16_t nb_pkts)
2927 : : {
2928 : 0 : return 0;
2929 : : }
2930 : : #endif /* RTE_HAS_SVE_ACLE */
2931 : :
2932 : : int
2933 : 0 : hns3_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
2934 : : struct rte_eth_burst_mode *mode)
2935 : : {
2936 : : static const struct {
2937 : : eth_rx_burst_t pkt_burst;
2938 : : const char *info;
2939 : : } burst_infos[] = {
2940 : : { hns3_recv_pkts_simple, "Scalar Simple" },
2941 : : { hns3_recv_scattered_pkts, "Scalar Scattered" },
2942 : : { hns3_recv_pkts_vec, "Vector Neon" },
2943 : : { hns3_recv_pkts_vec_sve, "Vector Sve" },
2944 : : { rte_eth_pkt_burst_dummy, "Dummy" },
2945 : : };
2946 : :
2947 : 0 : eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
2948 : : int ret = -EINVAL;
2949 : : unsigned int i;
2950 : :
2951 [ # # ]: 0 : for (i = 0; i < RTE_DIM(burst_infos); i++) {
2952 [ # # ]: 0 : if (pkt_burst == burst_infos[i].pkt_burst) {
2953 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
2954 : 0 : burst_infos[i].info);
2955 : : ret = 0;
2956 : 0 : break;
2957 : : }
2958 : : }
2959 : :
2960 : 0 : return ret;
2961 : : }
2962 : :
2963 : : static bool
2964 : : hns3_get_default_vec_support(void)
2965 : : {
2966 : : #if defined(RTE_ARCH_ARM64)
2967 : : if (rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128)
2968 : : return false;
2969 : : if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_NEON))
2970 : : return true;
2971 : : #endif
2972 : : return false;
2973 : : }
2974 : :
2975 : : static bool
2976 : : hns3_get_sve_support(void)
2977 : : {
2978 : : #if defined(RTE_HAS_SVE_ACLE)
2979 : : if (rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_256)
2980 : : return false;
2981 : : if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_SVE))
2982 : : return true;
2983 : : #endif
2984 : : return false;
2985 : : }
2986 : :
2987 : : static eth_rx_burst_t
2988 : 0 : hns3_get_rx_function(struct rte_eth_dev *dev)
2989 : : {
2990 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
2991 : 0 : uint64_t offloads = dev->data->dev_conf.rxmode.offloads;
2992 : : bool vec_allowed, sve_allowed, simple_allowed;
2993 : : bool vec_support;
2994 : :
2995 : 0 : vec_support = hns3_rx_check_vec_support(dev) == 0;
2996 : : vec_allowed = vec_support && hns3_get_default_vec_support();
2997 : : sve_allowed = vec_support && hns3_get_sve_support();
2998 [ # # ]: 0 : simple_allowed = !dev->data->scattered_rx &&
2999 [ # # ]: 0 : (offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) == 0;
3000 : :
3001 : 0 : if (hns->rx_func_hint == HNS3_IO_FUNC_HINT_VEC && vec_allowed)
3002 : : return hns3_recv_pkts_vec;
3003 : : if (hns->rx_func_hint == HNS3_IO_FUNC_HINT_SVE && sve_allowed)
3004 : : return hns3_recv_pkts_vec_sve;
3005 [ # # # # ]: 0 : if (hns->rx_func_hint == HNS3_IO_FUNC_HINT_SIMPLE && simple_allowed)
3006 : : return hns3_recv_pkts_simple;
3007 [ # # ]: 0 : if (hns->rx_func_hint == HNS3_IO_FUNC_HINT_COMMON)
3008 : : return hns3_recv_scattered_pkts;
3009 : :
3010 : : if (vec_allowed)
3011 : : return hns3_recv_pkts_vec;
3012 [ # # ]: 0 : if (simple_allowed)
3013 : 0 : return hns3_recv_pkts_simple;
3014 : :
3015 : : return hns3_recv_scattered_pkts;
3016 : : }
3017 : :
3018 : : static int
3019 : 0 : hns3_tx_queue_conf_check(struct hns3_hw *hw, const struct rte_eth_txconf *conf,
3020 : : uint16_t nb_desc, uint16_t *tx_rs_thresh,
3021 : : uint16_t *tx_free_thresh, uint16_t idx)
3022 : : {
3023 : : #define HNS3_TX_RS_FREE_THRESH_GAP 8
3024 : : uint16_t rs_thresh, free_thresh, fast_free_thresh;
3025 : :
3026 [ # # # # ]: 0 : if (nb_desc > HNS3_MAX_RING_DESC || nb_desc < HNS3_MIN_RING_DESC ||
3027 : : nb_desc % HNS3_ALIGN_RING_DESC) {
3028 : 0 : hns3_err(hw, "number (%u) of tx descriptors is invalid",
3029 : : nb_desc);
3030 : 0 : return -EINVAL;
3031 : : }
3032 : :
3033 [ # # ]: 0 : rs_thresh = (conf->tx_rs_thresh > 0) ?
3034 : : conf->tx_rs_thresh : HNS3_DEFAULT_TX_RS_THRESH;
3035 [ # # ]: 0 : free_thresh = (conf->tx_free_thresh > 0) ?
3036 : : conf->tx_free_thresh : HNS3_DEFAULT_TX_FREE_THRESH;
3037 [ # # # # ]: 0 : if (rs_thresh + free_thresh > nb_desc || nb_desc % rs_thresh ||
3038 [ # # # # ]: 0 : rs_thresh >= nb_desc - HNS3_TX_RS_FREE_THRESH_GAP ||
3039 : : free_thresh >= nb_desc - HNS3_TX_RS_FREE_THRESH_GAP) {
3040 : 0 : hns3_err(hw, "tx_rs_thresh (%u) tx_free_thresh (%u) nb_desc "
3041 : : "(%u) of tx descriptors for port=%u queue=%u check "
3042 : : "fail!",
3043 : : rs_thresh, free_thresh, nb_desc, hw->data->port_id,
3044 : : idx);
3045 : 0 : return -EINVAL;
3046 : : }
3047 : :
3048 [ # # ]: 0 : if (conf->tx_free_thresh == 0) {
3049 : : /* Fast free Tx memory buffer to improve cache hit rate */
3050 : 0 : fast_free_thresh = nb_desc - rs_thresh;
3051 [ # # ]: 0 : if (fast_free_thresh >=
3052 : : HNS3_TX_FAST_FREE_AHEAD + HNS3_DEFAULT_TX_FREE_THRESH)
3053 : 0 : free_thresh = fast_free_thresh -
3054 : : HNS3_TX_FAST_FREE_AHEAD;
3055 : : }
3056 : :
3057 : 0 : *tx_rs_thresh = rs_thresh;
3058 : 0 : *tx_free_thresh = free_thresh;
3059 : 0 : return 0;
3060 : : }
3061 : :
3062 : : static void *
3063 : : hns3_tx_push_get_queue_tail_reg(struct rte_eth_dev *dev, uint16_t queue_id)
3064 : : {
3065 : : #define HNS3_TX_PUSH_TQP_REGION_SIZE 0x10000
3066 : : #define HNS3_TX_PUSH_QUICK_DOORBELL_OFFSET 64
3067 : : #define HNS3_TX_PUSH_PCI_BAR_INDEX 4
3068 : :
3069 : 0 : struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
3070 : : uint8_t bar_id = HNS3_TX_PUSH_PCI_BAR_INDEX;
3071 : :
3072 : : /*
3073 : : * If device support Tx push then its PCIe bar45 must exist, and DPDK
3074 : : * framework will mmap the bar45 default in PCI probe stage.
3075 : : *
3076 : : * In the bar45, the first half is for RoCE (RDMA over Converged
3077 : : * Ethernet), and the second half is for NIC, every TQP occupy 64KB.
3078 : : *
3079 : : * The quick doorbell located at 64B offset in the TQP region.
3080 : : */
3081 : 0 : return (char *)pci_dev->mem_resource[bar_id].addr +
3082 : 0 : (pci_dev->mem_resource[bar_id].len >> 1) +
3083 : 0 : HNS3_TX_PUSH_TQP_REGION_SIZE * queue_id +
3084 : : HNS3_TX_PUSH_QUICK_DOORBELL_OFFSET;
3085 : : }
3086 : :
3087 : : void
3088 : 0 : hns3_tx_push_init(struct rte_eth_dev *dev)
3089 : : {
3090 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3091 : : volatile uint32_t *reg;
3092 : : uint32_t val;
3093 : :
3094 [ # # ]: 0 : if (!hns3_dev_get_support(hw, TX_PUSH))
3095 : : return;
3096 : :
3097 : : reg = (volatile uint32_t *)hns3_tx_push_get_queue_tail_reg(dev, 0);
3098 : : /*
3099 : : * Because the size of bar45 is about 8GB size, it may take a long time
3100 : : * to do the page fault in Tx process when work with vfio-pci, so use
3101 : : * one read operation to make kernel setup page table mapping for bar45
3102 : : * in the init stage.
3103 : : * Note: the bar45 is readable but the result is all 1.
3104 : : */
3105 : 0 : val = *reg;
3106 : : RTE_SET_USED(val);
3107 : : }
3108 : :
3109 : : static void
3110 : : hns3_tx_push_queue_init(struct rte_eth_dev *dev,
3111 : : uint16_t queue_id,
3112 : : struct hns3_tx_queue *txq)
3113 : : {
3114 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3115 : 0 : if (!hns3_dev_get_support(hw, TX_PUSH)) {
3116 : 0 : txq->tx_push_enable = false;
3117 : 0 : return;
3118 : : }
3119 : :
3120 : 0 : txq->io_tail_reg = (volatile void *)hns3_tx_push_get_queue_tail_reg(dev,
3121 : : queue_id);
3122 : 0 : txq->tx_push_enable = true;
3123 : : }
3124 : :
3125 : : int
3126 : 0 : hns3_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
3127 : : unsigned int socket_id, const struct rte_eth_txconf *conf)
3128 : : {
3129 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
3130 : : uint16_t tx_rs_thresh, tx_free_thresh;
3131 : 0 : struct hns3_hw *hw = &hns->hw;
3132 : : struct hns3_queue_info q_info;
3133 : : struct hns3_tx_queue *txq;
3134 : : int tx_entry_len;
3135 : : int ret;
3136 : :
3137 : 0 : ret = hns3_tx_queue_conf_check(hw, conf, nb_desc,
3138 : : &tx_rs_thresh, &tx_free_thresh, idx);
3139 [ # # ]: 0 : if (ret)
3140 : : return ret;
3141 : :
3142 [ # # ]: 0 : if (dev->data->tx_queues[idx] != NULL) {
3143 : 0 : hns3_tx_queue_release(dev->data->tx_queues[idx]);
3144 : 0 : dev->data->tx_queues[idx] = NULL;
3145 : : }
3146 : :
3147 : 0 : q_info.idx = idx;
3148 : 0 : q_info.socket_id = socket_id;
3149 : 0 : q_info.nb_desc = nb_desc;
3150 : 0 : q_info.type = "hns3 TX queue";
3151 : 0 : q_info.ring_name = "tx_ring";
3152 : 0 : txq = hns3_alloc_txq_and_dma_zone(dev, &q_info);
3153 [ # # ]: 0 : if (txq == NULL) {
3154 : 0 : hns3_err(hw,
3155 : : "Failed to alloc mem and reserve DMA mem for tx ring!");
3156 : 0 : return -ENOMEM;
3157 : : }
3158 : :
3159 : 0 : txq->tx_deferred_start = conf->tx_deferred_start;
3160 [ # # # # ]: 0 : if (txq->tx_deferred_start && !hns3_dev_get_support(hw, INDEP_TXRX)) {
3161 : 0 : hns3_warn(hw, "deferred start is not supported.");
3162 : 0 : txq->tx_deferred_start = false;
3163 : : }
3164 : :
3165 : 0 : tx_entry_len = sizeof(struct hns3_entry) * txq->nb_tx_desc;
3166 : 0 : txq->sw_ring = rte_zmalloc_socket("hns3 TX sw ring", tx_entry_len,
3167 : : RTE_CACHE_LINE_SIZE, socket_id);
3168 [ # # ]: 0 : if (txq->sw_ring == NULL) {
3169 : 0 : hns3_err(hw, "Failed to allocate memory for tx sw ring!");
3170 : 0 : hns3_tx_queue_release(txq);
3171 : 0 : return -ENOMEM;
3172 : : }
3173 : :
3174 : 0 : txq->hns = hns;
3175 : 0 : txq->next_to_use = 0;
3176 : 0 : txq->next_to_clean = 0;
3177 : 0 : txq->tx_bd_ready = txq->nb_tx_desc - 1;
3178 : 0 : txq->tx_free_thresh = tx_free_thresh;
3179 : 0 : txq->tx_rs_thresh = tx_rs_thresh;
3180 : 0 : txq->free = rte_zmalloc_socket("hns3 TX mbuf free array",
3181 : 0 : sizeof(struct rte_mbuf *) * txq->tx_rs_thresh,
3182 : : RTE_CACHE_LINE_SIZE, socket_id);
3183 [ # # ]: 0 : if (!txq->free) {
3184 : 0 : hns3_err(hw, "failed to allocate tx mbuf free array!");
3185 : 0 : hns3_tx_queue_release(txq);
3186 : 0 : return -ENOMEM;
3187 : : }
3188 : :
3189 : 0 : txq->port_id = dev->data->port_id;
3190 : : /*
3191 : : * For hns3 PF device, if the VLAN mode is HW_SHIFT_AND_DISCARD_MODE,
3192 : : * the pvid_sw_shift_en in the queue struct should not be changed,
3193 : : * because PVID-related operations do not need to be processed by PMD.
3194 : : * For hns3 VF device, whether it needs to process PVID depends
3195 : : * on the configuration of PF kernel mode netdev driver. And the
3196 : : * related PF configuration is delivered through the mailbox and finally
3197 : : * reflected in port_base_vlan_cfg.
3198 : : */
3199 [ # # # # ]: 0 : if (hns->is_vf || hw->vlan_mode == HNS3_SW_SHIFT_AND_DISCARD_MODE)
3200 : 0 : txq->pvid_sw_shift_en = hw->port_base_vlan_cfg.state ==
3201 : : HNS3_PORT_BASE_VLAN_ENABLE;
3202 : : else
3203 : 0 : txq->pvid_sw_shift_en = false;
3204 : :
3205 [ # # ]: 0 : if (hns3_dev_get_support(hw, SIMPLE_BD))
3206 : 0 : txq->simple_bd_enable = true;
3207 : :
3208 : 0 : txq->max_non_tso_bd_num = hw->max_non_tso_bd_num;
3209 : 0 : txq->configured = true;
3210 : 0 : txq->io_base = (void *)((char *)hw->io_base +
3211 : 0 : hns3_get_tqp_reg_offset(idx));
3212 : 0 : txq->io_tail_reg = (volatile void *)((char *)txq->io_base +
3213 : : HNS3_RING_TX_TAIL_REG);
3214 : 0 : txq->min_tx_pkt_len = hw->min_tx_pkt_len;
3215 : 0 : txq->tso_mode = hw->tso_mode;
3216 : 0 : txq->udp_cksum_mode = hw->udp_cksum_mode;
3217 : 0 : txq->mbuf_fast_free_en = !!(dev->data->dev_conf.txmode.offloads &
3218 : : RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE);
3219 [ # # ]: 0 : memset(&txq->basic_stats, 0, sizeof(struct hns3_tx_basic_stats));
3220 [ # # ]: 0 : memset(&txq->dfx_stats, 0, sizeof(struct hns3_tx_dfx_stats));
3221 : :
3222 : : /*
3223 : : * Call hns3_tx_push_queue_init after assigned io_tail_reg field because
3224 : : * it may overwrite the io_tail_reg field.
3225 : : */
3226 : : hns3_tx_push_queue_init(dev, idx, txq);
3227 : :
3228 : 0 : rte_spinlock_lock(&hw->lock);
3229 : 0 : dev->data->tx_queues[idx] = txq;
3230 : : rte_spinlock_unlock(&hw->lock);
3231 : :
3232 : 0 : return 0;
3233 : : }
3234 : :
3235 : : static void
3236 : 0 : hns3_tx_free_useless_buffer(struct hns3_tx_queue *txq)
3237 : : {
3238 : 0 : uint16_t tx_next_clean = txq->next_to_clean;
3239 : 0 : uint16_t tx_next_use = txq->next_to_use;
3240 : 0 : uint16_t tx_bd_ready = txq->tx_bd_ready;
3241 : 0 : uint16_t tx_bd_max = txq->nb_tx_desc;
3242 : 0 : struct hns3_entry *tx_bak_pkt = &txq->sw_ring[tx_next_clean];
3243 : 0 : struct hns3_desc *desc = &txq->tx_ring[tx_next_clean];
3244 : : struct rte_mbuf *mbuf;
3245 : :
3246 : 0 : while ((!(desc->tx.tp_fe_sc_vld_ra_ri &
3247 [ # # # # ]: 0 : rte_cpu_to_le_16(BIT(HNS3_TXD_VLD_B)))) &&
3248 : : tx_next_use != tx_next_clean) {
3249 : 0 : mbuf = tx_bak_pkt->mbuf;
3250 [ # # ]: 0 : if (mbuf) {
3251 : : rte_pktmbuf_free_seg(mbuf);
3252 : 0 : tx_bak_pkt->mbuf = NULL;
3253 : : }
3254 : :
3255 : 0 : desc++;
3256 : 0 : tx_bak_pkt++;
3257 : 0 : tx_next_clean++;
3258 : 0 : tx_bd_ready++;
3259 : :
3260 [ # # ]: 0 : if (tx_next_clean >= tx_bd_max) {
3261 : : tx_next_clean = 0;
3262 : 0 : desc = txq->tx_ring;
3263 : 0 : tx_bak_pkt = txq->sw_ring;
3264 : : }
3265 : : }
3266 : :
3267 : 0 : txq->next_to_clean = tx_next_clean;
3268 : 0 : txq->tx_bd_ready = tx_bd_ready;
3269 : 0 : }
3270 : :
3271 : : int
3272 : 0 : hns3_config_gro(struct hns3_hw *hw, bool en)
3273 : : {
3274 : : struct hns3_cfg_gro_status_cmd *req;
3275 : : struct hns3_cmd_desc desc;
3276 : : int ret;
3277 : :
3278 [ # # ]: 0 : if (!hns3_dev_get_support(hw, GRO))
3279 : : return 0;
3280 : :
3281 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_GRO_GENERIC_CONFIG, false);
3282 : : req = (struct hns3_cfg_gro_status_cmd *)desc.data;
3283 : :
3284 : 0 : req->gro_en = rte_cpu_to_le_16(en ? 1 : 0);
3285 : :
3286 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
3287 [ # # ]: 0 : if (ret)
3288 [ # # ]: 0 : hns3_err(hw, "%s hardware GRO failed, ret = %d",
3289 : : en ? "enable" : "disable", ret);
3290 : :
3291 : : return ret;
3292 : : }
3293 : :
3294 : : int
3295 : 0 : hns3_restore_gro_conf(struct hns3_hw *hw)
3296 : : {
3297 : : uint64_t offloads;
3298 : : bool gro_en;
3299 : : int ret;
3300 : :
3301 : 0 : offloads = hw->data->dev_conf.rxmode.offloads;
3302 : 0 : gro_en = offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO ? true : false;
3303 : 0 : ret = hns3_config_gro(hw, gro_en);
3304 [ # # ]: 0 : if (ret)
3305 [ # # ]: 0 : hns3_err(hw, "restore hardware GRO to %s failed, ret = %d",
3306 : : gro_en ? "enabled" : "disabled", ret);
3307 : :
3308 : 0 : return ret;
3309 : : }
3310 : :
3311 : : static inline bool
3312 : : hns3_pkt_is_tso(struct rte_mbuf *m)
3313 : : {
3314 [ # # # # : 0 : return (m->tso_segsz != 0 && m->ol_flags & RTE_MBUF_F_TX_TCP_SEG);
# # ]
3315 : : }
3316 : :
3317 : : static void
3318 : : hns3_set_tso(struct hns3_desc *desc, uint32_t paylen, struct rte_mbuf *rxm)
3319 : : {
3320 [ # # ]: 0 : if (!hns3_pkt_is_tso(rxm))
3321 : : return;
3322 : :
3323 [ # # ]: 0 : if (paylen <= rxm->tso_segsz)
3324 : : return;
3325 : :
3326 : 0 : desc->tx.type_cs_vlan_tso_len |= rte_cpu_to_le_32(BIT(HNS3_TXD_TSO_B));
3327 : 0 : desc->tx.ckst_mss |= rte_cpu_to_le_16(rxm->tso_segsz);
3328 : : }
3329 : :
3330 : : static inline void
3331 : : hns3_fill_per_desc(struct hns3_desc *desc, struct rte_mbuf *rxm)
3332 : : {
3333 : 0 : desc->addr = rte_mbuf_data_iova(rxm);
3334 : 0 : desc->tx.send_size = rte_cpu_to_le_16(rte_pktmbuf_data_len(rxm));
3335 : 0 : desc->tx.tp_fe_sc_vld_ra_ri |= rte_cpu_to_le_16(BIT(HNS3_TXD_VLD_B));
3336 : : }
3337 : :
3338 : : static void
3339 : 0 : hns3_fill_first_desc(struct hns3_tx_queue *txq, struct hns3_desc *desc,
3340 : : struct rte_mbuf *rxm)
3341 : : {
3342 : 0 : uint64_t ol_flags = rxm->ol_flags;
3343 : : uint32_t hdr_len;
3344 : : uint32_t paylen;
3345 : :
3346 : 0 : hdr_len = rxm->l2_len + rxm->l3_len + rxm->l4_len;
3347 : 0 : hdr_len += (ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) ?
3348 [ # # ]: 0 : rxm->outer_l2_len + rxm->outer_l3_len : 0;
3349 : 0 : paylen = rxm->pkt_len - hdr_len;
3350 [ # # ]: 0 : desc->tx.paylen_fd_dop_ol4cs |= rte_cpu_to_le_32(paylen);
3351 : : hns3_set_tso(desc, paylen, rxm);
3352 : :
3353 : : /*
3354 : : * Currently, hardware doesn't support more than two layers VLAN offload
3355 : : * in Tx direction based on hns3 network engine. So when the number of
3356 : : * VLANs in the packets represented by rxm plus the number of VLAN
3357 : : * offload by hardware such as PVID etc, exceeds two, the packets will
3358 : : * be discarded or the original VLAN of the packets will be overwritten
3359 : : * by hardware. When the PF PVID is enabled by calling the API function
3360 : : * named rte_eth_dev_set_vlan_pvid or the VF PVID is enabled by the hns3
3361 : : * PF kernel ether driver, the outer VLAN tag will always be the PVID.
3362 : : * To avoid the VLAN of Tx descriptor is overwritten by PVID, it should
3363 : : * be added to the position close to the IP header when PVID is enabled.
3364 : : */
3365 [ # # ]: 0 : if (!txq->pvid_sw_shift_en &&
3366 [ # # ]: 0 : ol_flags & (RTE_MBUF_F_TX_VLAN | RTE_MBUF_F_TX_QINQ)) {
3367 : 0 : desc->tx.ol_type_vlan_len_msec |=
3368 : : rte_cpu_to_le_32(BIT(HNS3_TXD_OVLAN_B));
3369 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_QINQ)
3370 : 0 : desc->tx.outer_vlan_tag =
3371 : 0 : rte_cpu_to_le_16(rxm->vlan_tci_outer);
3372 : : else
3373 : 0 : desc->tx.outer_vlan_tag =
3374 : 0 : rte_cpu_to_le_16(rxm->vlan_tci);
3375 : : }
3376 : :
3377 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_QINQ ||
3378 [ # # # # ]: 0 : ((ol_flags & RTE_MBUF_F_TX_VLAN) && txq->pvid_sw_shift_en)) {
3379 : 0 : desc->tx.type_cs_vlan_tso_len |=
3380 : : rte_cpu_to_le_32(BIT(HNS3_TXD_VLAN_B));
3381 : 0 : desc->tx.vlan_tag = rte_cpu_to_le_16(rxm->vlan_tci);
3382 : : }
3383 : :
3384 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
3385 : 0 : desc->tx.tp_fe_sc_vld_ra_ri |=
3386 : : rte_cpu_to_le_16(BIT(HNS3_TXD_TSYN_B));
3387 : 0 : }
3388 : :
3389 : : static inline int
3390 : 0 : hns3_tx_alloc_mbufs(struct rte_mempool *mb_pool, uint16_t nb_new_buf,
3391 : : struct rte_mbuf **alloc_mbuf)
3392 : : {
3393 : : #define MAX_NON_TSO_BD_PER_PKT 18
3394 : : struct rte_mbuf *pkt_segs[MAX_NON_TSO_BD_PER_PKT];
3395 : : uint16_t i;
3396 : :
3397 : : /* Allocate enough mbufs */
3398 [ # # # # ]: 0 : if (rte_mempool_get_bulk(mb_pool, (void **)pkt_segs, nb_new_buf))
3399 : : return -ENOMEM;
3400 : :
3401 [ # # ]: 0 : for (i = 0; i < nb_new_buf - 1; i++)
3402 : 0 : pkt_segs[i]->next = pkt_segs[i + 1];
3403 : :
3404 : 0 : pkt_segs[nb_new_buf - 1]->next = NULL;
3405 : 0 : pkt_segs[0]->nb_segs = nb_new_buf;
3406 : 0 : *alloc_mbuf = pkt_segs[0];
3407 : :
3408 : 0 : return 0;
3409 : : }
3410 : :
3411 : : static inline void
3412 : : hns3_pktmbuf_copy_hdr(struct rte_mbuf *new_pkt, struct rte_mbuf *old_pkt)
3413 : : {
3414 : 0 : new_pkt->ol_flags = old_pkt->ol_flags;
3415 : 0 : new_pkt->pkt_len = rte_pktmbuf_pkt_len(old_pkt);
3416 : 0 : new_pkt->outer_l2_len = old_pkt->outer_l2_len;
3417 : 0 : new_pkt->outer_l3_len = old_pkt->outer_l3_len;
3418 : 0 : new_pkt->l2_len = old_pkt->l2_len;
3419 : 0 : new_pkt->l3_len = old_pkt->l3_len;
3420 : 0 : new_pkt->l4_len = old_pkt->l4_len;
3421 : 0 : new_pkt->vlan_tci_outer = old_pkt->vlan_tci_outer;
3422 : 0 : new_pkt->vlan_tci = old_pkt->vlan_tci;
3423 : : }
3424 : :
3425 : : static int
3426 : 0 : hns3_reassemble_tx_pkts(struct rte_mbuf *tx_pkt, struct rte_mbuf **new_pkt,
3427 : : uint8_t max_non_tso_bd_num)
3428 : : {
3429 : : struct rte_mempool *mb_pool;
3430 : : struct rte_mbuf *new_mbuf;
3431 : : struct rte_mbuf *temp_new;
3432 : : struct rte_mbuf *temp;
3433 : : uint16_t last_buf_len;
3434 : : uint16_t nb_new_buf;
3435 : : uint16_t buf_size;
3436 : : uint16_t buf_len;
3437 : : uint16_t len_s;
3438 : : uint16_t len_d;
3439 : : uint16_t len;
3440 : : int ret;
3441 : : char *s;
3442 : : char *d;
3443 : :
3444 : 0 : mb_pool = tx_pkt->pool;
3445 : 0 : buf_size = tx_pkt->buf_len - RTE_PKTMBUF_HEADROOM;
3446 : 0 : nb_new_buf = (rte_pktmbuf_pkt_len(tx_pkt) - 1) / buf_size + 1;
3447 [ # # ]: 0 : if (nb_new_buf > max_non_tso_bd_num)
3448 : : return -EINVAL;
3449 : :
3450 : 0 : last_buf_len = rte_pktmbuf_pkt_len(tx_pkt) % buf_size;
3451 [ # # ]: 0 : if (last_buf_len == 0)
3452 : : last_buf_len = buf_size;
3453 : :
3454 : : /* Allocate enough mbufs */
3455 : 0 : ret = hns3_tx_alloc_mbufs(mb_pool, nb_new_buf, &new_mbuf);
3456 [ # # ]: 0 : if (ret)
3457 : : return ret;
3458 : :
3459 : : /* Copy the original packet content to the new mbufs */
3460 : : temp = tx_pkt;
3461 : 0 : s = rte_pktmbuf_mtod(temp, char *);
3462 : 0 : len_s = rte_pktmbuf_data_len(temp);
3463 : 0 : temp_new = new_mbuf;
3464 [ # # ]: 0 : while (temp != NULL && temp_new != NULL) {
3465 : 0 : d = rte_pktmbuf_mtod(temp_new, char *);
3466 [ # # ]: 0 : buf_len = temp_new->next == NULL ? last_buf_len : buf_size;
3467 : : len_d = buf_len;
3468 : :
3469 [ # # ]: 0 : while (len_d) {
3470 : 0 : len = RTE_MIN(len_s, len_d);
3471 [ # # ]: 0 : memcpy(d, s, len);
3472 : 0 : s = s + len;
3473 : 0 : d = d + len;
3474 : 0 : len_d = len_d - len;
3475 : 0 : len_s = len_s - len;
3476 : :
3477 [ # # ]: 0 : if (len_s == 0) {
3478 : 0 : temp = temp->next;
3479 [ # # ]: 0 : if (temp == NULL)
3480 : : break;
3481 : 0 : s = rte_pktmbuf_mtod(temp, char *);
3482 : 0 : len_s = rte_pktmbuf_data_len(temp);
3483 : : }
3484 : : }
3485 : :
3486 : 0 : temp_new->data_len = buf_len;
3487 : 0 : temp_new = temp_new->next;
3488 : : }
3489 : : hns3_pktmbuf_copy_hdr(new_mbuf, tx_pkt);
3490 : :
3491 : : /* free original mbufs */
3492 : 0 : rte_pktmbuf_free(tx_pkt);
3493 : :
3494 : 0 : *new_pkt = new_mbuf;
3495 : :
3496 : 0 : return 0;
3497 : : }
3498 : :
3499 : : static void
3500 : : hns3_parse_outer_params(struct rte_mbuf *m, uint32_t *ol_type_vlan_len_msec)
3501 : : {
3502 : : uint32_t tmp = *ol_type_vlan_len_msec;
3503 : 0 : uint64_t ol_flags = m->ol_flags;
3504 : :
3505 : : /* (outer) IP header type */
3506 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_OUTER_IPV4) {
3507 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM)
3508 : : tmp |= hns3_gen_field_val(HNS3_TXD_OL3T_M,
3509 : : HNS3_TXD_OL3T_S, HNS3_OL3T_IPV4_CSUM);
3510 : : else
3511 : : tmp |= hns3_gen_field_val(HNS3_TXD_OL3T_M,
3512 : : HNS3_TXD_OL3T_S, HNS3_OL3T_IPV4_NO_CSUM);
3513 [ # # ]: 0 : } else if (ol_flags & RTE_MBUF_F_TX_OUTER_IPV6) {
3514 : : tmp |= hns3_gen_field_val(HNS3_TXD_OL3T_M, HNS3_TXD_OL3T_S,
3515 : : HNS3_OL3T_IPV6);
3516 : : }
3517 : : /* OL3 header size, defined in 4 bytes */
3518 : 0 : tmp |= hns3_gen_field_val(HNS3_TXD_L3LEN_M, HNS3_TXD_L3LEN_S,
3519 : : m->outer_l3_len >> HNS3_L3_LEN_UNIT);
3520 : 0 : *ol_type_vlan_len_msec = tmp;
3521 : : }
3522 : :
3523 : : static int
3524 : 0 : hns3_parse_inner_params(struct rte_mbuf *m, uint32_t *ol_type_vlan_len_msec,
3525 : : uint32_t *type_cs_vlan_tso_len)
3526 : : {
3527 : : #define HNS3_NVGRE_HLEN 8
3528 : 0 : uint32_t tmp_outer = *ol_type_vlan_len_msec;
3529 : 0 : uint32_t tmp_inner = *type_cs_vlan_tso_len;
3530 : 0 : uint64_t ol_flags = m->ol_flags;
3531 : : uint16_t inner_l2_len;
3532 : :
3533 [ # # # ]: 0 : switch (ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) {
3534 : 0 : case RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE:
3535 : : case RTE_MBUF_F_TX_TUNNEL_GENEVE:
3536 : : case RTE_MBUF_F_TX_TUNNEL_VXLAN:
3537 : : /* MAC in UDP tunnelling packet, include VxLAN and GENEVE */
3538 : : tmp_outer |= hns3_gen_field_val(HNS3_TXD_TUNTYPE_M,
3539 : : HNS3_TXD_TUNTYPE_S, HNS3_TUN_MAC_IN_UDP);
3540 : : /*
3541 : : * The inner l2 length of mbuf is the sum of outer l4 length,
3542 : : * tunneling header length and inner l2 length for a tunnel
3543 : : * packet. But in hns3 tx descriptor, the tunneling header
3544 : : * length is contained in the field of outer L4 length.
3545 : : * Therefore, driver need to calculate the outer L4 length and
3546 : : * inner L2 length.
3547 : : */
3548 : 0 : tmp_outer |= hns3_gen_field_val(HNS3_TXD_L4LEN_M,
3549 : : HNS3_TXD_L4LEN_S,
3550 : : (uint8_t)RTE_ETHER_VXLAN_HLEN >>
3551 : : HNS3_L4_LEN_UNIT);
3552 : :
3553 : 0 : inner_l2_len = m->l2_len - RTE_ETHER_VXLAN_HLEN;
3554 : 0 : break;
3555 : 0 : case RTE_MBUF_F_TX_TUNNEL_GRE:
3556 : : tmp_outer |= hns3_gen_field_val(HNS3_TXD_TUNTYPE_M,
3557 : : HNS3_TXD_TUNTYPE_S, HNS3_TUN_NVGRE);
3558 : : /*
3559 : : * For NVGRE tunnel packet, the outer L4 is empty. So only
3560 : : * fill the NVGRE header length to the outer L4 field.
3561 : : */
3562 : 0 : tmp_outer |= hns3_gen_field_val(HNS3_TXD_L4LEN_M,
3563 : : HNS3_TXD_L4LEN_S,
3564 : : (uint8_t)HNS3_NVGRE_HLEN >> HNS3_L4_LEN_UNIT);
3565 : :
3566 : 0 : inner_l2_len = m->l2_len - HNS3_NVGRE_HLEN;
3567 : 0 : break;
3568 : : default:
3569 : : /* For non UDP / GRE tunneling, drop the tunnel packet */
3570 : : return -EINVAL;
3571 : : }
3572 : :
3573 : 0 : tmp_inner |= hns3_gen_field_val(HNS3_TXD_L2LEN_M, HNS3_TXD_L2LEN_S,
3574 : : inner_l2_len >> HNS3_L2_LEN_UNIT);
3575 : : /* OL2 header size, defined in 2 bytes */
3576 : 0 : tmp_outer |= hns3_gen_field_val(HNS3_TXD_L2LEN_M, HNS3_TXD_L2LEN_S,
3577 : : m->outer_l2_len >> HNS3_L2_LEN_UNIT);
3578 : :
3579 : 0 : *type_cs_vlan_tso_len = tmp_inner;
3580 : 0 : *ol_type_vlan_len_msec = tmp_outer;
3581 : :
3582 : 0 : return 0;
3583 : : }
3584 : :
3585 : : static int
3586 : 0 : hns3_parse_tunneling_params(struct hns3_tx_queue *txq, struct rte_mbuf *m,
3587 : : uint16_t tx_desc_id)
3588 : : {
3589 : 0 : struct hns3_desc *tx_ring = txq->tx_ring;
3590 : 0 : struct hns3_desc *desc = &tx_ring[tx_desc_id];
3591 : 0 : uint64_t ol_flags = m->ol_flags;
3592 : 0 : uint32_t tmp_outer = 0;
3593 : 0 : uint32_t tmp_inner = 0;
3594 : : uint32_t tmp_ol4cs;
3595 : : int ret;
3596 : :
3597 : : /*
3598 : : * The tunnel header is contained in the inner L2 header field of the
3599 : : * mbuf, but for hns3 descriptor, it is contained in the outer L4. So,
3600 : : * there is a need that switching between them. To avoid multiple
3601 : : * calculations, the length of the L2 header include the outer and
3602 : : * inner, will be filled during the parsing of tunnel packets.
3603 : : */
3604 [ # # ]: 0 : if (!(ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK)) {
3605 : : /*
3606 : : * For non tunnel type the tunnel type id is 0, so no need to
3607 : : * assign a value to it. Only the inner(normal) L2 header length
3608 : : * is assigned.
3609 : : */
3610 : 0 : tmp_inner |= hns3_gen_field_val(HNS3_TXD_L2LEN_M,
3611 : : HNS3_TXD_L2LEN_S, m->l2_len >> HNS3_L2_LEN_UNIT);
3612 : : } else {
3613 : : /*
3614 : : * If outer csum is not offload, the outer length may be filled
3615 : : * with 0. And the length of the outer header is added to the
3616 : : * inner l2_len. It would lead a cksum error. So driver has to
3617 : : * calculate the header length.
3618 : : */
3619 [ # # # # ]: 0 : if (unlikely(!(ol_flags &
3620 : : (RTE_MBUF_F_TX_OUTER_IP_CKSUM | RTE_MBUF_F_TX_OUTER_UDP_CKSUM)) &&
3621 : : m->outer_l2_len == 0)) {
3622 : : struct rte_net_hdr_lens hdr_len;
3623 : 0 : (void)rte_net_get_ptype(m, &hdr_len,
3624 : : RTE_PTYPE_L2_MASK | RTE_PTYPE_L3_MASK);
3625 : 0 : m->outer_l3_len = hdr_len.l3_len;
3626 : 0 : m->outer_l2_len = hdr_len.l2_len;
3627 : 0 : m->l2_len = m->l2_len - hdr_len.l2_len - hdr_len.l3_len;
3628 : : }
3629 : : hns3_parse_outer_params(m, &tmp_outer);
3630 : 0 : ret = hns3_parse_inner_params(m, &tmp_outer, &tmp_inner);
3631 [ # # ]: 0 : if (ret)
3632 : : return -EINVAL;
3633 : : }
3634 : :
3635 : 0 : desc->tx.ol_type_vlan_len_msec = rte_cpu_to_le_32(tmp_outer);
3636 : 0 : desc->tx.type_cs_vlan_tso_len = rte_cpu_to_le_32(tmp_inner);
3637 : 0 : tmp_ol4cs = ol_flags & RTE_MBUF_F_TX_OUTER_UDP_CKSUM ?
3638 : 0 : BIT(HNS3_TXD_OL4CS_B) : 0;
3639 : 0 : desc->tx.paylen_fd_dop_ol4cs = rte_cpu_to_le_32(tmp_ol4cs);
3640 : :
3641 : 0 : return 0;
3642 : : }
3643 : :
3644 : : static void
3645 : : hns3_parse_l3_cksum_params(struct rte_mbuf *m, uint32_t *type_cs_vlan_tso_len)
3646 : : {
3647 : 0 : uint64_t ol_flags = m->ol_flags;
3648 : : uint32_t l3_type;
3649 : : uint32_t tmp;
3650 : :
3651 : : tmp = *type_cs_vlan_tso_len;
3652 : 0 : if (ol_flags & RTE_MBUF_F_TX_IPV4)
3653 : : l3_type = HNS3_L3T_IPV4;
3654 [ # # ]: 0 : else if (ol_flags & RTE_MBUF_F_TX_IPV6)
3655 : : l3_type = HNS3_L3T_IPV6;
3656 : : else
3657 : : l3_type = HNS3_L3T_NONE;
3658 : :
3659 : : /* inner(/normal) L3 header size, defined in 4 bytes */
3660 : 0 : tmp |= hns3_gen_field_val(HNS3_TXD_L3LEN_M, HNS3_TXD_L3LEN_S,
3661 : : m->l3_len >> HNS3_L3_LEN_UNIT);
3662 : :
3663 : 0 : tmp |= hns3_gen_field_val(HNS3_TXD_L3T_M, HNS3_TXD_L3T_S, l3_type);
3664 : :
3665 : : /* Enable L3 checksum offloads */
3666 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
3667 : 0 : tmp |= BIT(HNS3_TXD_L3CS_B);
3668 : 0 : *type_cs_vlan_tso_len = tmp;
3669 : : }
3670 : :
3671 : : static void
3672 : 0 : hns3_parse_l4_cksum_params(struct rte_mbuf *m, uint32_t *type_cs_vlan_tso_len)
3673 : : {
3674 : 0 : uint64_t ol_flags = m->ol_flags;
3675 : : uint32_t tmp;
3676 : : /* Enable L4 checksum offloads */
3677 [ # # # # ]: 0 : switch (ol_flags & (RTE_MBUF_F_TX_L4_MASK | RTE_MBUF_F_TX_TCP_SEG)) {
3678 : 0 : case RTE_MBUF_F_TX_TCP_CKSUM | RTE_MBUF_F_TX_TCP_SEG:
3679 : : case RTE_MBUF_F_TX_TCP_CKSUM:
3680 : : case RTE_MBUF_F_TX_TCP_SEG:
3681 : 0 : tmp = *type_cs_vlan_tso_len;
3682 : 0 : tmp |= hns3_gen_field_val(HNS3_TXD_L4T_M, HNS3_TXD_L4T_S,
3683 : : HNS3_L4T_TCP);
3684 : 0 : break;
3685 : 0 : case RTE_MBUF_F_TX_UDP_CKSUM:
3686 : 0 : tmp = *type_cs_vlan_tso_len;
3687 : 0 : tmp |= hns3_gen_field_val(HNS3_TXD_L4T_M, HNS3_TXD_L4T_S,
3688 : : HNS3_L4T_UDP);
3689 : 0 : break;
3690 : 0 : case RTE_MBUF_F_TX_SCTP_CKSUM:
3691 : 0 : tmp = *type_cs_vlan_tso_len;
3692 : 0 : tmp |= hns3_gen_field_val(HNS3_TXD_L4T_M, HNS3_TXD_L4T_S,
3693 : : HNS3_L4T_SCTP);
3694 : 0 : break;
3695 : : default:
3696 : : return;
3697 : : }
3698 : 0 : tmp |= BIT(HNS3_TXD_L4CS_B);
3699 : 0 : tmp |= hns3_gen_field_val(HNS3_TXD_L4LEN_M, HNS3_TXD_L4LEN_S,
3700 : : m->l4_len >> HNS3_L4_LEN_UNIT);
3701 : 0 : *type_cs_vlan_tso_len = tmp;
3702 : : }
3703 : :
3704 : : static void
3705 : 0 : hns3_txd_enable_checksum(struct hns3_tx_queue *txq, struct rte_mbuf *m,
3706 : : uint16_t tx_desc_id)
3707 : : {
3708 : 0 : struct hns3_desc *tx_ring = txq->tx_ring;
3709 [ # # ]: 0 : struct hns3_desc *desc = &tx_ring[tx_desc_id];
3710 : : uint32_t value = 0;
3711 : :
3712 : : hns3_parse_l3_cksum_params(m, &value);
3713 : 0 : hns3_parse_l4_cksum_params(m, &value);
3714 : :
3715 : 0 : desc->tx.type_cs_vlan_tso_len |= rte_cpu_to_le_32(value);
3716 : 0 : }
3717 : :
3718 : : static bool
3719 : 0 : hns3_pkt_need_linearized(struct rte_mbuf *tx_pkts, uint32_t bd_num,
3720 : : uint32_t max_non_tso_bd_num)
3721 : : {
3722 : : struct rte_mbuf *m_first = tx_pkts;
3723 : : struct rte_mbuf *m_last = tx_pkts;
3724 : : uint32_t tot_len = 0;
3725 : : uint32_t hdr_len;
3726 : : uint32_t i;
3727 : :
3728 : : /*
3729 : : * Hardware requires that the sum of the data length of every 8
3730 : : * consecutive buffers is greater than MSS in hns3 network engine.
3731 : : * We simplify it by ensuring pkt_headlen + the first 8 consecutive
3732 : : * frags greater than gso header len + mss, and the remaining 7
3733 : : * consecutive frags greater than MSS except the last 7 frags.
3734 : : */
3735 [ # # ]: 0 : if (bd_num <= max_non_tso_bd_num)
3736 : : return false;
3737 : :
3738 [ # # # # ]: 0 : for (i = 0; m_last && i < max_non_tso_bd_num - 1;
3739 : 0 : i++, m_last = m_last->next)
3740 : 0 : tot_len += m_last->data_len;
3741 : :
3742 [ # # ]: 0 : if (!m_last)
3743 : : return true;
3744 : :
3745 : : /* ensure the first 8 frags is greater than mss + header */
3746 : 0 : hdr_len = tx_pkts->l2_len + tx_pkts->l3_len + tx_pkts->l4_len;
3747 : 0 : hdr_len += (tx_pkts->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) ?
3748 [ # # ]: 0 : tx_pkts->outer_l2_len + tx_pkts->outer_l3_len : 0;
3749 [ # # ]: 0 : if (tot_len + m_last->data_len < tx_pkts->tso_segsz + hdr_len)
3750 : : return true;
3751 : :
3752 : : /*
3753 : : * ensure the sum of the data length of every 7 consecutive buffer
3754 : : * is greater than mss except the last one.
3755 : : */
3756 [ # # # # ]: 0 : for (i = 0; m_last && i < bd_num - max_non_tso_bd_num; i++) {
3757 : 0 : tot_len -= m_first->data_len;
3758 : 0 : tot_len += m_last->data_len;
3759 : :
3760 [ # # ]: 0 : if (tot_len < tx_pkts->tso_segsz)
3761 : : return true;
3762 : :
3763 : 0 : m_first = m_first->next;
3764 : 0 : m_last = m_last->next;
3765 : : }
3766 : :
3767 : : return false;
3768 : : }
3769 : :
3770 : : static int
3771 : 0 : hns3_check_tso_pkt_valid(struct rte_mbuf *m)
3772 : : {
3773 : : uint32_t tmp_data_len_sum = 0;
3774 : 0 : uint16_t nb_buf = m->nb_segs;
3775 : : uint32_t paylen, hdr_len;
3776 : : struct rte_mbuf *m_seg;
3777 : : int i;
3778 : :
3779 [ # # ]: 0 : if (nb_buf > HNS3_MAX_TSO_BD_PER_PKT)
3780 : : return -EINVAL;
3781 : :
3782 : 0 : hdr_len = m->l2_len + m->l3_len + m->l4_len;
3783 : 0 : hdr_len += (m->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) ?
3784 [ # # ]: 0 : m->outer_l2_len + m->outer_l3_len : 0;
3785 [ # # ]: 0 : if (hdr_len > HNS3_MAX_TSO_HDR_SIZE)
3786 : : return -EINVAL;
3787 : :
3788 : 0 : paylen = m->pkt_len - hdr_len;
3789 [ # # ]: 0 : if (paylen > HNS3_MAX_BD_PAYLEN)
3790 : : return -EINVAL;
3791 : :
3792 : : /*
3793 : : * The TSO header (include outer and inner L2, L3 and L4 header)
3794 : : * should be provided by three descriptors in maximum in hns3 network
3795 : : * engine.
3796 : : */
3797 : : m_seg = m;
3798 [ # # # # ]: 0 : for (i = 0; m_seg != NULL && i < HNS3_MAX_TSO_HDR_BD_NUM && i < nb_buf;
3799 : 0 : i++, m_seg = m_seg->next) {
3800 : 0 : tmp_data_len_sum += m_seg->data_len;
3801 : : }
3802 : :
3803 [ # # ]: 0 : if (hdr_len > tmp_data_len_sum)
3804 : 0 : return -EINVAL;
3805 : :
3806 : : return 0;
3807 : : }
3808 : :
3809 : : #ifdef RTE_LIBRTE_ETHDEV_DEBUG
3810 : : static inline int
3811 : : hns3_vld_vlan_chk(struct hns3_tx_queue *txq, struct rte_mbuf *m)
3812 : : {
3813 : : struct rte_ether_hdr *eh;
3814 : : struct rte_vlan_hdr *vh;
3815 : :
3816 : : if (!txq->pvid_sw_shift_en)
3817 : : return 0;
3818 : :
3819 : : /*
3820 : : * Due to hardware limitations, we only support two-layer VLAN hardware
3821 : : * offload in Tx direction based on hns3 network engine, so when PVID is
3822 : : * enabled, QinQ insert is no longer supported.
3823 : : * And when PVID is enabled, in the following two cases:
3824 : : * i) packets with more than two VLAN tags.
3825 : : * ii) packets with one VLAN tag while the hardware VLAN insert is
3826 : : * enabled.
3827 : : * The packets will be regarded as abnormal packets and discarded by
3828 : : * hardware in Tx direction. For debugging purposes, a validation check
3829 : : * for these types of packets is added to the '.tx_pkt_prepare' ops
3830 : : * implementation function named hns3_prep_pkts to inform users that
3831 : : * these packets will be discarded.
3832 : : */
3833 : : if (m->ol_flags & RTE_MBUF_F_TX_QINQ)
3834 : : return -EINVAL;
3835 : :
3836 : : eh = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
3837 : : if (eh->ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN)) {
3838 : : if (m->ol_flags & RTE_MBUF_F_TX_VLAN)
3839 : : return -EINVAL;
3840 : :
3841 : : /* Ensure the incoming packet is not a QinQ packet */
3842 : : vh = (struct rte_vlan_hdr *)(eh + 1);
3843 : : if (vh->eth_proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN))
3844 : : return -EINVAL;
3845 : : }
3846 : :
3847 : : return 0;
3848 : : }
3849 : : #endif
3850 : :
3851 : : static uint16_t
3852 : 0 : hns3_udp_cksum_help(struct rte_mbuf *m)
3853 : : {
3854 : 0 : uint64_t ol_flags = m->ol_flags;
3855 : 0 : uint16_t cksum = 0;
3856 : : uint32_t l4_len;
3857 : :
3858 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IPV4) {
3859 : 0 : struct rte_ipv4_hdr *ipv4_hdr = rte_pktmbuf_mtod_offset(m,
3860 : : struct rte_ipv4_hdr *, m->l2_len);
3861 [ # # ]: 0 : l4_len = rte_be_to_cpu_16(ipv4_hdr->total_length) - m->l3_len;
3862 : : } else {
3863 : 0 : struct rte_ipv6_hdr *ipv6_hdr = rte_pktmbuf_mtod_offset(m,
3864 : : struct rte_ipv6_hdr *, m->l2_len);
3865 [ # # ]: 0 : l4_len = rte_be_to_cpu_16(ipv6_hdr->payload_len);
3866 : : }
3867 : :
3868 : 0 : rte_raw_cksum_mbuf(m, m->l2_len + m->l3_len, l4_len, &cksum);
3869 : :
3870 : 0 : cksum = ~cksum;
3871 : : /*
3872 : : * RFC 768:If the computed checksum is zero for UDP, it is transmitted
3873 : : * as all ones
3874 : : */
3875 [ # # ]: 0 : if (cksum == 0)
3876 : 0 : cksum = 0xffff;
3877 : :
3878 : 0 : return (uint16_t)cksum;
3879 : : }
3880 : :
3881 : : static bool
3882 : 0 : hns3_validate_tunnel_cksum(struct hns3_tx_queue *tx_queue, struct rte_mbuf *m)
3883 : : {
3884 : 0 : uint64_t ol_flags = m->ol_flags;
3885 : : struct rte_udp_hdr *udp_hdr;
3886 : : uint16_t dst_port;
3887 : :
3888 [ # # ]: 0 : if (tx_queue->udp_cksum_mode == HNS3_SPECIAL_PORT_HW_CKSUM_MODE ||
3889 [ # # ]: 0 : ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK ||
3890 : : (ol_flags & RTE_MBUF_F_TX_L4_MASK) != RTE_MBUF_F_TX_UDP_CKSUM)
3891 : : return true;
3892 : : /*
3893 : : * A UDP packet with the same dst_port as VXLAN\VXLAN_GPE\GENEVE will
3894 : : * be recognized as a tunnel packet in HW. In this case, if UDP CKSUM
3895 : : * offload is set and the tunnel mask has not been set, the CKSUM will
3896 : : * be wrong since the header length is wrong and driver should complete
3897 : : * the CKSUM to avoid CKSUM error.
3898 : : */
3899 : 0 : udp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_udp_hdr *,
3900 : : m->l2_len + m->l3_len);
3901 [ # # ]: 0 : dst_port = rte_be_to_cpu_16(udp_hdr->dst_port);
3902 [ # # ]: 0 : switch (dst_port) {
3903 : 0 : case RTE_VXLAN_DEFAULT_PORT:
3904 : : case RTE_VXLAN_GPE_DEFAULT_PORT:
3905 : : case RTE_GENEVE_DEFAULT_PORT:
3906 : 0 : udp_hdr->dgram_cksum = hns3_udp_cksum_help(m);
3907 : 0 : m->ol_flags = ol_flags & ~RTE_MBUF_F_TX_L4_MASK;
3908 : 0 : return false;
3909 : : default:
3910 : : return true;
3911 : : }
3912 : : }
3913 : :
3914 : : static int
3915 [ # # ]: 0 : hns3_prep_pkt_proc(struct hns3_tx_queue *tx_queue, struct rte_mbuf *m)
3916 : : {
3917 : : int ret;
3918 : :
3919 : : #ifdef RTE_LIBRTE_ETHDEV_DEBUG
3920 : : ret = rte_validate_tx_offload(m);
3921 : : if (ret != 0) {
3922 : : rte_errno = -ret;
3923 : : return ret;
3924 : : }
3925 : :
3926 : : ret = hns3_vld_vlan_chk(tx_queue, m);
3927 : : if (ret != 0) {
3928 : : rte_errno = EINVAL;
3929 : : return ret;
3930 : : }
3931 : : #endif
3932 [ # # ]: 0 : if (hns3_pkt_is_tso(m)) {
3933 : 0 : if (hns3_pkt_need_linearized(m, m->nb_segs,
3934 [ # # ]: 0 : tx_queue->max_non_tso_bd_num) ||
3935 [ # # ]: 0 : hns3_check_tso_pkt_valid(m)) {
3936 : 0 : rte_errno = EINVAL;
3937 : 0 : return -EINVAL;
3938 : : }
3939 : :
3940 [ # # ]: 0 : if (tx_queue->tso_mode != HNS3_TSO_SW_CAL_PSEUDO_H_CSUM) {
3941 : : /*
3942 : : * (tso mode != HNS3_TSO_SW_CAL_PSEUDO_H_CSUM) means
3943 : : * hardware support recalculate the TCP pseudo header
3944 : : * checksum of packets that need TSO, so network driver
3945 : : * software not need to recalculate it.
3946 : : */
3947 : : return 0;
3948 : : }
3949 : : }
3950 : :
3951 : : ret = rte_net_intel_cksum_prepare(m);
3952 [ # # ]: 0 : if (ret != 0) {
3953 : 0 : rte_errno = -ret;
3954 : 0 : return ret;
3955 : : }
3956 : :
3957 : 0 : if (!hns3_validate_tunnel_cksum(tx_queue, m))
3958 : : return 0;
3959 : :
3960 : : return 0;
3961 : : }
3962 : :
3963 : : uint16_t
3964 : 0 : hns3_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
3965 : : uint16_t nb_pkts)
3966 : : {
3967 : : struct rte_mbuf *m;
3968 : : uint16_t i;
3969 : :
3970 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
3971 : 0 : m = tx_pkts[i];
3972 [ # # ]: 0 : if (hns3_prep_pkt_proc(tx_queue, m))
3973 : 0 : return i;
3974 : : }
3975 : :
3976 : : return i;
3977 : : }
3978 : :
3979 : : static inline int
3980 : 0 : hns3_handle_simple_bd(struct hns3_tx_queue *txq, struct hns3_desc *desc,
3981 : : struct rte_mbuf *m)
3982 : : {
3983 : : #define HNS3_TCP_CSUM_OFFSET 16
3984 : : #define HNS3_UDP_CSUM_OFFSET 6
3985 : :
3986 : : /*
3987 : : * In HIP09, NIC HW support Tx simple BD mode that the HW will
3988 : : * calculate the checksum from the start position of checksum and fill
3989 : : * the checksum result to the offset position without packet type and
3990 : : * header length of L3/L4.
3991 : : * For non-tunneling packet:
3992 : : * - Tx simple BD support for TCP and UDP checksum.
3993 : : * For tunneling packet:
3994 : : * - Tx simple BD support for inner L4 checksum(except sctp checksum).
3995 : : * - Tx simple BD not support the outer checksum and the inner L3
3996 : : * checksum.
3997 : : * - Besides, Tx simple BD is not support for TSO.
3998 : : */
3999 [ # # ]: 0 : if (txq->simple_bd_enable && !(m->ol_flags & RTE_MBUF_F_TX_IP_CKSUM) &&
4000 [ # # ]: 0 : !(m->ol_flags & RTE_MBUF_F_TX_TCP_SEG) &&
4001 : 0 : !(m->ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) &&
4002 [ # # ]: 0 : ((m->ol_flags & RTE_MBUF_F_TX_L4_MASK) == RTE_MBUF_F_TX_TCP_CKSUM ||
4003 : : (m->ol_flags & RTE_MBUF_F_TX_L4_MASK) == RTE_MBUF_F_TX_UDP_CKSUM)) {
4004 : : /* set checksum start and offset, defined in 2 Bytes */
4005 : 0 : hns3_set_field(desc->tx.type_cs_vlan_tso_len,
4006 : : HNS3_TXD_L4_START_M, HNS3_TXD_L4_START_S,
4007 : : (m->l2_len + m->l3_len) >> HNS3_SIMPLE_BD_UNIT);
4008 [ # # ]: 0 : hns3_set_field(desc->tx.ol_type_vlan_len_msec,
4009 : : HNS3_TXD_L4_CKS_OFFSET_M, HNS3_TXD_L4_CKS_OFFSET_S,
4010 : : (m->ol_flags & RTE_MBUF_F_TX_L4_MASK) ==
4011 : : RTE_MBUF_F_TX_TCP_CKSUM ?
4012 : : HNS3_TCP_CSUM_OFFSET >> HNS3_SIMPLE_BD_UNIT :
4013 : : HNS3_UDP_CSUM_OFFSET >> HNS3_SIMPLE_BD_UNIT);
4014 : :
4015 : 0 : hns3_set_bit(desc->tx.ckst_mss, HNS3_TXD_CKST_B, 1);
4016 : :
4017 : 0 : return 0;
4018 : : }
4019 : :
4020 : : return -ENOTSUP;
4021 : : }
4022 : :
4023 : : static int
4024 : 0 : hns3_parse_cksum(struct hns3_tx_queue *txq, uint16_t tx_desc_id,
4025 : : struct rte_mbuf *m)
4026 : : {
4027 : 0 : struct hns3_desc *tx_ring = txq->tx_ring;
4028 : 0 : struct hns3_desc *desc = &tx_ring[tx_desc_id];
4029 : :
4030 : : /* Enable checksum offloading */
4031 [ # # ]: 0 : if (m->ol_flags & HNS3_TX_CKSUM_OFFLOAD_MASK) {
4032 [ # # ]: 0 : if (hns3_handle_simple_bd(txq, desc, m) == 0)
4033 : : return 0;
4034 : : /* Fill in tunneling parameters if necessary */
4035 [ # # ]: 0 : if (hns3_parse_tunneling_params(txq, m, tx_desc_id)) {
4036 : 0 : txq->dfx_stats.unsupported_tunnel_pkt_cnt++;
4037 : 0 : return -EINVAL;
4038 : : }
4039 : :
4040 : 0 : hns3_txd_enable_checksum(txq, m, tx_desc_id);
4041 : : } else {
4042 : : /* clear the control bit */
4043 : 0 : desc->tx.type_cs_vlan_tso_len = 0;
4044 : 0 : desc->tx.ol_type_vlan_len_msec = 0;
4045 : : }
4046 : :
4047 : : return 0;
4048 : : }
4049 : :
4050 : : static int
4051 : 0 : hns3_check_non_tso_pkt(uint16_t nb_buf, struct rte_mbuf **m_seg,
4052 : : struct rte_mbuf *tx_pkt, struct hns3_tx_queue *txq)
4053 : : {
4054 : : uint8_t max_non_tso_bd_num;
4055 : : struct rte_mbuf *new_pkt;
4056 : : int ret;
4057 : :
4058 [ # # # # ]: 0 : if (hns3_pkt_is_tso(*m_seg))
4059 : : return 0;
4060 : :
4061 : : /*
4062 : : * If packet length is greater than HNS3_MAX_FRAME_LEN
4063 : : * driver support, the packet will be ignored.
4064 : : */
4065 [ # # ]: 0 : if (unlikely(rte_pktmbuf_pkt_len(tx_pkt) > HNS3_MAX_FRAME_LEN)) {
4066 : 0 : txq->dfx_stats.over_length_pkt_cnt++;
4067 : 0 : return -EINVAL;
4068 : : }
4069 : :
4070 : 0 : max_non_tso_bd_num = txq->max_non_tso_bd_num;
4071 [ # # ]: 0 : if (unlikely(nb_buf > max_non_tso_bd_num)) {
4072 : 0 : txq->dfx_stats.exceed_limit_bd_pkt_cnt++;
4073 : 0 : ret = hns3_reassemble_tx_pkts(tx_pkt, &new_pkt,
4074 : : max_non_tso_bd_num);
4075 [ # # ]: 0 : if (ret) {
4076 : 0 : txq->dfx_stats.exceed_limit_bd_reassem_fail++;
4077 : 0 : return ret;
4078 : : }
4079 : 0 : *m_seg = new_pkt;
4080 : : }
4081 : :
4082 : : return 0;
4083 : : }
4084 : :
4085 : : static inline void
4086 : 0 : hns3_tx_free_buffer_simple(struct hns3_tx_queue *txq)
4087 : : {
4088 : : struct hns3_entry *tx_entry;
4089 : : struct hns3_desc *desc;
4090 : : uint16_t tx_next_clean;
4091 : : uint16_t i;
4092 : :
4093 : : while (1) {
4094 [ # # ]: 0 : if (HNS3_GET_TX_QUEUE_PEND_BD_NUM(txq) < txq->tx_rs_thresh)
4095 : : break;
4096 : :
4097 : : /*
4098 : : * All mbufs can be released only when the VLD bits of all
4099 : : * descriptors in a batch are cleared.
4100 : : */
4101 : 0 : tx_next_clean = (txq->next_to_clean + txq->tx_rs_thresh - 1) %
4102 : : txq->nb_tx_desc;
4103 : 0 : desc = &txq->tx_ring[tx_next_clean];
4104 [ # # ]: 0 : for (i = 0; i < txq->tx_rs_thresh; i++) {
4105 [ # # ]: 0 : if (rte_le_to_cpu_16(desc->tx.tp_fe_sc_vld_ra_ri) &
4106 : : BIT(HNS3_TXD_VLD_B))
4107 : : return;
4108 : 0 : desc--;
4109 : : }
4110 : :
4111 : 0 : tx_entry = &txq->sw_ring[txq->next_to_clean];
4112 : :
4113 [ # # ]: 0 : if (txq->mbuf_fast_free_en) {
4114 [ # # ]: 0 : rte_mempool_put_bulk(tx_entry->mbuf->pool,
4115 : : (void **)tx_entry, txq->tx_rs_thresh);
4116 [ # # ]: 0 : for (i = 0; i < txq->tx_rs_thresh; i++)
4117 : 0 : tx_entry[i].mbuf = NULL;
4118 : 0 : goto update_field;
4119 : : }
4120 : :
4121 [ # # ]: 0 : for (i = 0; i < txq->tx_rs_thresh; i++)
4122 : 0 : rte_prefetch0((tx_entry + i)->mbuf);
4123 [ # # ]: 0 : for (i = 0; i < txq->tx_rs_thresh; i++, tx_entry++) {
4124 : 0 : rte_pktmbuf_free_seg(tx_entry->mbuf);
4125 : 0 : tx_entry->mbuf = NULL;
4126 : : }
4127 : :
4128 : 0 : update_field:
4129 : 0 : txq->next_to_clean = (tx_next_clean + 1) % txq->nb_tx_desc;
4130 : 0 : txq->tx_bd_ready += txq->tx_rs_thresh;
4131 : : }
4132 : : }
4133 : :
4134 : : static inline void
4135 : : hns3_tx_backup_1mbuf(struct hns3_entry *tx_entry, struct rte_mbuf **pkts)
4136 : : {
4137 : 0 : tx_entry->mbuf = pkts[0];
4138 : : }
4139 : :
4140 : : static inline void
4141 : : hns3_tx_backup_4mbuf(struct hns3_entry *tx_entry, struct rte_mbuf **pkts)
4142 : : {
4143 : : hns3_tx_backup_1mbuf(&tx_entry[0], &pkts[0]);
4144 : : hns3_tx_backup_1mbuf(&tx_entry[1], &pkts[1]);
4145 : : hns3_tx_backup_1mbuf(&tx_entry[2], &pkts[2]);
4146 : : hns3_tx_backup_1mbuf(&tx_entry[3], &pkts[3]);
4147 : : }
4148 : :
4149 : : static inline void
4150 : 0 : hns3_tx_setup_4bd(struct hns3_desc *txdp, struct rte_mbuf **pkts)
4151 : : {
4152 : : #define PER_LOOP_NUM 4
4153 : : uint16_t bd_flag = BIT(HNS3_TXD_VLD_B) | BIT(HNS3_TXD_FE_B);
4154 : : uint64_t dma_addr;
4155 : : uint32_t i;
4156 : :
4157 [ # # ]: 0 : for (i = 0; i < PER_LOOP_NUM; i++, txdp++, pkts++) {
4158 [ # # ]: 0 : dma_addr = rte_mbuf_data_iova(*pkts);
4159 : 0 : txdp->addr = rte_cpu_to_le_64(dma_addr);
4160 : 0 : txdp->tx.send_size = rte_cpu_to_le_16((*pkts)->data_len);
4161 : 0 : txdp->tx.paylen_fd_dop_ol4cs = 0;
4162 : 0 : txdp->tx.type_cs_vlan_tso_len = 0;
4163 : 0 : txdp->tx.ol_type_vlan_len_msec = 0;
4164 [ # # ]: 0 : if (unlikely((*pkts)->ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST))
4165 : : bd_flag |= BIT(HNS3_TXD_TSYN_B);
4166 : 0 : txdp->tx.tp_fe_sc_vld_ra_ri = rte_cpu_to_le_16(bd_flag);
4167 : : }
4168 : 0 : }
4169 : :
4170 : : static inline void
4171 : : hns3_tx_setup_1bd(struct hns3_desc *txdp, struct rte_mbuf **pkts)
4172 : : {
4173 : : uint16_t bd_flag = BIT(HNS3_TXD_VLD_B) | BIT(HNS3_TXD_FE_B);
4174 : : uint64_t dma_addr;
4175 : :
4176 : : dma_addr = rte_mbuf_data_iova(*pkts);
4177 : 0 : txdp->addr = rte_cpu_to_le_64(dma_addr);
4178 : 0 : txdp->tx.send_size = rte_cpu_to_le_16((*pkts)->data_len);
4179 : 0 : txdp->tx.paylen_fd_dop_ol4cs = 0;
4180 : 0 : txdp->tx.type_cs_vlan_tso_len = 0;
4181 : 0 : txdp->tx.ol_type_vlan_len_msec = 0;
4182 [ # # ]: 0 : if (unlikely((*pkts)->ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST))
4183 : : bd_flag |= BIT(HNS3_TXD_TSYN_B);
4184 : 0 : txdp->tx.tp_fe_sc_vld_ra_ri = rte_cpu_to_le_16(bd_flag);
4185 : : }
4186 : :
4187 : : static inline void
4188 : 0 : hns3_tx_fill_hw_ring(struct hns3_tx_queue *txq,
4189 : : struct rte_mbuf **pkts,
4190 : : uint16_t nb_pkts)
4191 : : {
4192 : : #define PER_LOOP_NUM 4
4193 : : #define PER_LOOP_MASK (PER_LOOP_NUM - 1)
4194 : 0 : struct hns3_desc *txdp = &txq->tx_ring[txq->next_to_use];
4195 : 0 : struct hns3_entry *tx_entry = &txq->sw_ring[txq->next_to_use];
4196 : 0 : const uint32_t mainpart = (nb_pkts & ((uint32_t)~PER_LOOP_MASK));
4197 : 0 : const uint32_t leftover = (nb_pkts & ((uint32_t)PER_LOOP_MASK));
4198 : : uint32_t i;
4199 : :
4200 [ # # ]: 0 : for (i = 0; i < mainpart; i += PER_LOOP_NUM) {
4201 : 0 : hns3_tx_backup_4mbuf(tx_entry + i, pkts + i);
4202 : 0 : hns3_tx_setup_4bd(txdp + i, pkts + i);
4203 : :
4204 : : /* Increment bytes counter */
4205 : : uint32_t j;
4206 [ # # ]: 0 : for (j = 0; j < PER_LOOP_NUM; j++)
4207 : 0 : txq->basic_stats.bytes += pkts[i + j]->pkt_len;
4208 : : }
4209 [ # # ]: 0 : if (unlikely(leftover > 0)) {
4210 [ # # ]: 0 : for (i = 0; i < leftover; i++) {
4211 : 0 : hns3_tx_backup_1mbuf(tx_entry + mainpart + i,
4212 : 0 : pkts + mainpart + i);
4213 [ # # ]: 0 : hns3_tx_setup_1bd(txdp + mainpart + i,
4214 : : pkts + mainpart + i);
4215 : :
4216 : : /* Increment bytes counter */
4217 : 0 : txq->basic_stats.bytes += pkts[mainpart + i]->pkt_len;
4218 : : }
4219 : : }
4220 : 0 : }
4221 : :
4222 : : uint16_t
4223 : 0 : hns3_xmit_pkts_simple(void *tx_queue,
4224 : : struct rte_mbuf **tx_pkts,
4225 : : uint16_t nb_pkts)
4226 : : {
4227 : : struct hns3_tx_queue *txq = tx_queue;
4228 : : uint16_t nb_tx = 0;
4229 : :
4230 : 0 : hns3_tx_free_buffer_simple(txq);
4231 : :
4232 : 0 : nb_pkts = RTE_MIN(txq->tx_bd_ready, nb_pkts);
4233 [ # # ]: 0 : if (unlikely(nb_pkts == 0)) {
4234 [ # # ]: 0 : if (txq->tx_bd_ready == 0)
4235 : 0 : txq->dfx_stats.queue_full_cnt++;
4236 : 0 : return 0;
4237 : : }
4238 : :
4239 : 0 : txq->tx_bd_ready -= nb_pkts;
4240 [ # # ]: 0 : if (txq->next_to_use + nb_pkts >= txq->nb_tx_desc) {
4241 : 0 : nb_tx = txq->nb_tx_desc - txq->next_to_use;
4242 : 0 : hns3_tx_fill_hw_ring(txq, tx_pkts, nb_tx);
4243 : 0 : txq->next_to_use = 0;
4244 : : }
4245 : :
4246 [ # # ]: 0 : if (nb_pkts > nb_tx) {
4247 : 0 : hns3_tx_fill_hw_ring(txq, tx_pkts + nb_tx, nb_pkts - nb_tx);
4248 : 0 : txq->next_to_use += nb_pkts - nb_tx;
4249 : : }
4250 : :
4251 : 0 : hns3_write_txq_tail_reg(txq, nb_pkts);
4252 : :
4253 : : return nb_pkts;
4254 : : }
4255 : :
4256 : : uint16_t
4257 : 0 : hns3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
4258 : : {
4259 : : struct hns3_tx_queue *txq = tx_queue;
4260 : : struct hns3_entry *tx_bak_pkt;
4261 : : struct hns3_desc *tx_ring;
4262 : : struct rte_mbuf *tx_pkt;
4263 : : struct rte_mbuf *m_seg;
4264 : : struct hns3_desc *desc;
4265 : : uint32_t nb_hold = 0;
4266 : : uint16_t tx_next_use;
4267 : : uint16_t tx_pkt_num;
4268 : : uint16_t tx_bd_max;
4269 : : uint16_t nb_buf;
4270 : : uint16_t nb_tx;
4271 : : uint16_t i;
4272 : :
4273 : 0 : hns3_tx_free_useless_buffer(txq);
4274 : :
4275 : 0 : tx_next_use = txq->next_to_use;
4276 : 0 : tx_bd_max = txq->nb_tx_desc;
4277 : : tx_pkt_num = nb_pkts;
4278 : 0 : tx_ring = txq->tx_ring;
4279 : :
4280 : : /* send packets */
4281 : 0 : tx_bak_pkt = &txq->sw_ring[tx_next_use];
4282 [ # # ]: 0 : for (nb_tx = 0; nb_tx < tx_pkt_num; nb_tx++) {
4283 : 0 : tx_pkt = *tx_pkts++;
4284 : :
4285 : 0 : nb_buf = tx_pkt->nb_segs;
4286 : :
4287 [ # # ]: 0 : if (nb_buf > txq->tx_bd_ready) {
4288 : 0 : txq->dfx_stats.queue_full_cnt++;
4289 [ # # ]: 0 : if (nb_tx == 0)
4290 : : return 0;
4291 : 0 : goto end_of_tx;
4292 : : }
4293 : :
4294 : : /*
4295 : : * If packet length is less than minimum packet length supported
4296 : : * by hardware in Tx direction, driver need to pad it to avoid
4297 : : * error.
4298 : : */
4299 [ # # ]: 0 : if (unlikely(rte_pktmbuf_pkt_len(tx_pkt) <
4300 : : txq->min_tx_pkt_len)) {
4301 : : uint16_t add_len;
4302 : : char *appended;
4303 : :
4304 : 0 : add_len = txq->min_tx_pkt_len -
4305 : : rte_pktmbuf_pkt_len(tx_pkt);
4306 : : appended = rte_pktmbuf_append(tx_pkt, add_len);
4307 [ # # ]: 0 : if (appended == NULL) {
4308 : 0 : txq->dfx_stats.pkt_padding_fail_cnt++;
4309 : 0 : break;
4310 : : }
4311 : :
4312 : 0 : memset(appended, 0, add_len);
4313 : : }
4314 : :
4315 : 0 : m_seg = tx_pkt;
4316 : :
4317 [ # # ]: 0 : if (hns3_check_non_tso_pkt(nb_buf, &m_seg, tx_pkt, txq))
4318 : 0 : goto end_of_tx;
4319 : :
4320 [ # # ]: 0 : if (hns3_parse_cksum(txq, tx_next_use, m_seg))
4321 : 0 : goto end_of_tx;
4322 : :
4323 : : i = 0;
4324 : 0 : desc = &tx_ring[tx_next_use];
4325 : :
4326 : : /*
4327 : : * If the packet is divided into multiple Tx Buffer Descriptors,
4328 : : * only need to fill vlan, paylen and tso into the first Tx
4329 : : * Buffer Descriptor.
4330 : : */
4331 : 0 : hns3_fill_first_desc(txq, desc, m_seg);
4332 : :
4333 : : do {
4334 : 0 : desc = &tx_ring[tx_next_use];
4335 : : /*
4336 : : * Fill valid bits, DMA address and data length for each
4337 : : * Tx Buffer Descriptor.
4338 : : */
4339 [ # # ]: 0 : hns3_fill_per_desc(desc, m_seg);
4340 : 0 : tx_bak_pkt->mbuf = m_seg;
4341 : 0 : m_seg = m_seg->next;
4342 : 0 : tx_next_use++;
4343 : 0 : tx_bak_pkt++;
4344 [ # # ]: 0 : if (tx_next_use >= tx_bd_max) {
4345 : : tx_next_use = 0;
4346 : 0 : tx_bak_pkt = txq->sw_ring;
4347 : : }
4348 : : if (m_seg != NULL)
4349 : : TX_BD_LOG(&txq->hns->hw, DEBUG, desc);
4350 : :
4351 : 0 : i++;
4352 [ # # ]: 0 : } while (m_seg != NULL);
4353 : :
4354 : : /* Add end flag for the last Tx Buffer Descriptor */
4355 : 0 : desc->tx.tp_fe_sc_vld_ra_ri |=
4356 : : rte_cpu_to_le_16(BIT(HNS3_TXD_FE_B));
4357 : : TX_BD_LOG(&txq->hns->hw, DEBUG, desc);
4358 : :
4359 : : /* Increment bytes counter */
4360 : 0 : txq->basic_stats.bytes += tx_pkt->pkt_len;
4361 : 0 : nb_hold += i;
4362 : 0 : txq->next_to_use = tx_next_use;
4363 : 0 : txq->tx_bd_ready -= i;
4364 : : }
4365 : :
4366 : 0 : end_of_tx:
4367 : :
4368 [ # # ]: 0 : if (likely(nb_tx))
4369 : : hns3_write_txq_tail_reg(txq, nb_hold);
4370 : :
4371 : : return nb_tx;
4372 : : }
4373 : :
4374 : : #ifndef RTE_ARCH_ARM64
4375 : : int
4376 : 0 : hns3_tx_check_vec_support(__rte_unused struct rte_eth_dev *dev)
4377 : : {
4378 : 0 : return -ENOTSUP;
4379 : : }
4380 : :
4381 : : uint16_t
4382 : 0 : hns3_xmit_pkts_vec(__rte_unused void *tx_queue,
4383 : : __rte_unused struct rte_mbuf **tx_pkts,
4384 : : __rte_unused uint16_t nb_pkts)
4385 : : {
4386 : 0 : return 0;
4387 : : }
4388 : : #endif /* RTE_ARCH_ARM64 */
4389 : :
4390 : : #ifndef RTE_HAS_SVE_ACLE
4391 : : uint16_t
4392 : 0 : hns3_xmit_pkts_vec_sve(void __rte_unused * tx_queue,
4393 : : struct rte_mbuf __rte_unused **tx_pkts,
4394 : : uint16_t __rte_unused nb_pkts)
4395 : : {
4396 : 0 : return 0;
4397 : : }
4398 : : #endif /* RTE_HAS_SVE_ACLE */
4399 : :
4400 : : int
4401 : 0 : hns3_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
4402 : : struct rte_eth_burst_mode *mode)
4403 : : {
4404 : : static const struct {
4405 : : eth_tx_burst_t pkt_burst;
4406 : : const char *info;
4407 : : } burst_infos[] = {
4408 : : { hns3_xmit_pkts_simple, "Scalar Simple" },
4409 : : { hns3_xmit_pkts, "Scalar" },
4410 : : { hns3_xmit_pkts_vec, "Vector Neon" },
4411 : : { hns3_xmit_pkts_vec_sve, "Vector Sve" },
4412 : : { rte_eth_pkt_burst_dummy, "Dummy" },
4413 : : };
4414 : :
4415 : 0 : eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
4416 : : int ret = -EINVAL;
4417 : : unsigned int i;
4418 : :
4419 [ # # ]: 0 : for (i = 0; i < RTE_DIM(burst_infos); i++) {
4420 [ # # ]: 0 : if (pkt_burst == burst_infos[i].pkt_burst) {
4421 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
4422 : 0 : burst_infos[i].info);
4423 : : ret = 0;
4424 : 0 : break;
4425 : : }
4426 : : }
4427 : :
4428 : 0 : return ret;
4429 : : }
4430 : :
4431 : : static bool
4432 : : hns3_tx_check_simple_support(struct rte_eth_dev *dev)
4433 : : {
4434 : 0 : uint64_t offloads = dev->data->dev_conf.txmode.offloads;
4435 : :
4436 : 0 : return (offloads == (offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE));
4437 : : }
4438 : :
4439 : : static bool
4440 : : hns3_get_tx_prep_needed(struct rte_eth_dev *dev)
4441 : : {
4442 : : #define HNS3_DEV_TX_CSKUM_TSO_OFFLOAD_MASK (\
4443 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | \
4444 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM | \
4445 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM | \
4446 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM | \
4447 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM | \
4448 : : RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM | \
4449 : : RTE_ETH_TX_OFFLOAD_TCP_TSO | \
4450 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO | \
4451 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO | \
4452 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO)
4453 : :
4454 : 0 : uint64_t tx_offload = dev->data->dev_conf.txmode.offloads;
4455 : :
4456 : 0 : if (tx_offload & HNS3_DEV_TX_CSKUM_TSO_OFFLOAD_MASK)
4457 : : return true;
4458 : :
4459 : : return false;
4460 : : }
4461 : :
4462 : : static eth_tx_prep_t
4463 : : hns3_get_tx_prepare(struct rte_eth_dev *dev)
4464 : : {
4465 : : return hns3_get_tx_prep_needed(dev) ? hns3_prep_pkts : NULL;
4466 : : }
4467 : :
4468 : : static eth_tx_burst_t
4469 : 0 : hns3_get_tx_function(struct rte_eth_dev *dev)
4470 : : {
4471 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
4472 : : bool vec_allowed, sve_allowed, simple_allowed;
4473 : : bool vec_support;
4474 : :
4475 : 0 : vec_support = hns3_tx_check_vec_support(dev) == 0;
4476 : : vec_allowed = vec_support && hns3_get_default_vec_support();
4477 : : sve_allowed = vec_support && hns3_get_sve_support();
4478 : : simple_allowed = hns3_tx_check_simple_support(dev);
4479 : :
4480 : 0 : if (hns->tx_func_hint == HNS3_IO_FUNC_HINT_VEC && vec_allowed)
4481 : : return hns3_xmit_pkts_vec;
4482 : : if (hns->tx_func_hint == HNS3_IO_FUNC_HINT_SVE && sve_allowed)
4483 : : return hns3_xmit_pkts_vec_sve;
4484 [ # # # # ]: 0 : if (hns->tx_func_hint == HNS3_IO_FUNC_HINT_SIMPLE && simple_allowed)
4485 : : return hns3_xmit_pkts_simple;
4486 [ # # ]: 0 : if (hns->tx_func_hint == HNS3_IO_FUNC_HINT_COMMON)
4487 : : return hns3_xmit_pkts;
4488 : :
4489 : : if (vec_allowed)
4490 : : return hns3_xmit_pkts_vec;
4491 [ # # ]: 0 : if (simple_allowed)
4492 : 0 : return hns3_xmit_pkts_simple;
4493 : :
4494 : : return hns3_xmit_pkts;
4495 : : }
4496 : :
4497 : : static void
4498 : 0 : hns3_trace_rxtx_function(struct rte_eth_dev *dev)
4499 : : {
4500 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4501 : : struct rte_eth_burst_mode rx_mode;
4502 : : struct rte_eth_burst_mode tx_mode;
4503 : :
4504 : : memset(&rx_mode, 0, sizeof(rx_mode));
4505 : : memset(&tx_mode, 0, sizeof(tx_mode));
4506 : 0 : (void)hns3_rx_burst_mode_get(dev, 0, &rx_mode);
4507 : 0 : (void)hns3_tx_burst_mode_get(dev, 0, &tx_mode);
4508 : :
4509 : 0 : hns3_dbg(hw, "using rx_pkt_burst: %s, tx_pkt_burst: %s.",
4510 : : rx_mode.info, tx_mode.info);
4511 : 0 : }
4512 : :
4513 : : static void
4514 : : hns3_eth_dev_fp_ops_config(const struct rte_eth_dev *dev)
4515 : : {
4516 : : struct rte_eth_fp_ops *fpo = rte_eth_fp_ops;
4517 : 0 : uint16_t port_id = dev->data->port_id;
4518 : :
4519 : 0 : fpo[port_id].rx_pkt_burst = dev->rx_pkt_burst;
4520 : 0 : fpo[port_id].tx_pkt_burst = dev->tx_pkt_burst;
4521 : 0 : fpo[port_id].tx_pkt_prepare = dev->tx_pkt_prepare;
4522 : 0 : fpo[port_id].rx_descriptor_status = dev->rx_descriptor_status;
4523 : 0 : fpo[port_id].tx_descriptor_status = dev->tx_descriptor_status;
4524 : 0 : fpo[port_id].rxq.data = dev->data->rx_queues;
4525 : 0 : fpo[port_id].txq.data = dev->data->tx_queues;
4526 : : }
4527 : :
4528 : : void
4529 : 0 : hns3_set_rxtx_function(struct rte_eth_dev *eth_dev)
4530 : : {
4531 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
4532 : : struct hns3_adapter *hns = eth_dev->data->dev_private;
4533 : :
4534 [ # # ]: 0 : if (hns->hw.adapter_state == HNS3_NIC_STARTED &&
4535 [ # # ]: 0 : rte_atomic_load_explicit(&hns->hw.reset.resetting, rte_memory_order_relaxed) == 0) {
4536 : 0 : eth_dev->rx_pkt_burst = hns3_get_rx_function(eth_dev);
4537 : 0 : eth_dev->rx_descriptor_status = hns3_dev_rx_descriptor_status;
4538 [ # # ]: 0 : eth_dev->tx_pkt_burst = hw->set_link_down ?
4539 [ # # ]: 0 : rte_eth_pkt_burst_dummy :
4540 : 0 : hns3_get_tx_function(eth_dev);
4541 : 0 : eth_dev->tx_pkt_prepare = hns3_get_tx_prepare(eth_dev);
4542 : 0 : eth_dev->tx_descriptor_status = hns3_dev_tx_descriptor_status;
4543 : : } else {
4544 : 0 : eth_dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
4545 : 0 : eth_dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
4546 : 0 : eth_dev->tx_pkt_prepare = NULL;
4547 : : }
4548 : :
4549 : 0 : hns3_trace_rxtx_function(eth_dev);
4550 : : hns3_eth_dev_fp_ops_config(eth_dev);
4551 : 0 : }
4552 : :
4553 : : void
4554 : 0 : hns3_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
4555 : : struct rte_eth_rxq_info *qinfo)
4556 : : {
4557 : 0 : struct hns3_rx_queue *rxq = dev->data->rx_queues[queue_id];
4558 : :
4559 : 0 : qinfo->mp = rxq->mb_pool;
4560 : 0 : qinfo->nb_desc = rxq->nb_rx_desc;
4561 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
4562 : : /* Report the HW Rx buffer length to user */
4563 : 0 : qinfo->rx_buf_size = rxq->rx_buf_len;
4564 : :
4565 : : /*
4566 : : * If there are no available Rx buffer descriptors, incoming packets
4567 : : * are always dropped by hardware based on hns3 network engine.
4568 : : */
4569 : 0 : qinfo->conf.rx_drop_en = 1;
4570 : 0 : qinfo->conf.offloads = dev->data->dev_conf.rxmode.offloads;
4571 : 0 : qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
4572 : 0 : qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
4573 : 0 : }
4574 : :
4575 : : void
4576 : 0 : hns3_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
4577 : : struct rte_eth_txq_info *qinfo)
4578 : : {
4579 : 0 : struct hns3_tx_queue *txq = dev->data->tx_queues[queue_id];
4580 : :
4581 : 0 : qinfo->nb_desc = txq->nb_tx_desc;
4582 : 0 : qinfo->conf.offloads = dev->data->dev_conf.txmode.offloads;
4583 : 0 : qinfo->conf.tx_rs_thresh = txq->tx_rs_thresh;
4584 : 0 : qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
4585 : 0 : qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
4586 : 0 : }
4587 : :
4588 : : int
4589 : 0 : hns3_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
4590 : : {
4591 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4592 : 0 : struct hns3_rx_queue *rxq = dev->data->rx_queues[rx_queue_id];
4593 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
4594 : : int ret;
4595 : :
4596 [ # # ]: 0 : if (!hns3_dev_get_support(hw, INDEP_TXRX))
4597 : : return -ENOTSUP;
4598 : :
4599 : 0 : rte_spinlock_lock(&hw->lock);
4600 : :
4601 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.resetting, rte_memory_order_relaxed)) {
4602 : 0 : hns3_err(hw, "fail to start Rx queue during resetting.");
4603 : : rte_spinlock_unlock(&hw->lock);
4604 : 0 : return -EIO;
4605 : : }
4606 : :
4607 : 0 : ret = hns3_reset_queue(hw, rx_queue_id, HNS3_RING_TYPE_RX);
4608 [ # # ]: 0 : if (ret) {
4609 : 0 : hns3_err(hw, "fail to reset Rx queue %u, ret = %d.",
4610 : : rx_queue_id, ret);
4611 : : rte_spinlock_unlock(&hw->lock);
4612 : 0 : return ret;
4613 : : }
4614 : :
4615 [ # # ]: 0 : if (rxq->sw_ring[0].mbuf != NULL)
4616 : 0 : hns3_rx_queue_release_mbufs(rxq);
4617 : :
4618 : 0 : ret = hns3_init_rxq(hns, rx_queue_id);
4619 [ # # ]: 0 : if (ret) {
4620 : 0 : hns3_err(hw, "fail to init Rx queue %u, ret = %d.",
4621 : : rx_queue_id, ret);
4622 : : rte_spinlock_unlock(&hw->lock);
4623 : 0 : return ret;
4624 : : }
4625 : :
4626 : : hns3_enable_rxq(rxq, true);
4627 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
4628 : : rte_spinlock_unlock(&hw->lock);
4629 : :
4630 : 0 : return ret;
4631 : : }
4632 : :
4633 : : static void
4634 : 0 : hns3_reset_sw_rxq(struct hns3_rx_queue *rxq)
4635 : : {
4636 : 0 : rxq->next_to_use = 0;
4637 : 0 : rxq->rx_rearm_start = 0;
4638 : 0 : rxq->rx_free_hold = 0;
4639 : 0 : rxq->rx_rearm_nb = 0;
4640 : 0 : rxq->pkt_first_seg = NULL;
4641 : 0 : rxq->pkt_last_seg = NULL;
4642 : 0 : memset(&rxq->rx_ring[0], 0, rxq->nb_rx_desc * sizeof(struct hns3_desc));
4643 : 0 : hns3_rxq_vec_setup(rxq);
4644 : 0 : }
4645 : :
4646 : : int
4647 : 0 : hns3_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
4648 : : {
4649 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4650 : 0 : struct hns3_rx_queue *rxq = dev->data->rx_queues[rx_queue_id];
4651 : :
4652 [ # # ]: 0 : if (!hns3_dev_get_support(hw, INDEP_TXRX))
4653 : : return -ENOTSUP;
4654 : :
4655 : 0 : rte_spinlock_lock(&hw->lock);
4656 : :
4657 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.resetting, rte_memory_order_relaxed)) {
4658 : 0 : hns3_err(hw, "fail to stop Rx queue during resetting.");
4659 : : rte_spinlock_unlock(&hw->lock);
4660 : 0 : return -EIO;
4661 : : }
4662 : :
4663 : : hns3_enable_rxq(rxq, false);
4664 : :
4665 : 0 : hns3_rx_queue_release_mbufs(rxq);
4666 : :
4667 : 0 : hns3_reset_sw_rxq(rxq);
4668 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
4669 : : rte_spinlock_unlock(&hw->lock);
4670 : :
4671 : 0 : return 0;
4672 : : }
4673 : :
4674 : : int
4675 : 0 : hns3_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
4676 : : {
4677 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4678 : 0 : struct hns3_tx_queue *txq = dev->data->tx_queues[tx_queue_id];
4679 : : int ret;
4680 : :
4681 [ # # ]: 0 : if (!hns3_dev_get_support(hw, INDEP_TXRX))
4682 : : return -ENOTSUP;
4683 : :
4684 : 0 : rte_spinlock_lock(&hw->lock);
4685 : :
4686 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.resetting, rte_memory_order_relaxed)) {
4687 : 0 : hns3_err(hw, "fail to start Tx queue during resetting.");
4688 : : rte_spinlock_unlock(&hw->lock);
4689 : 0 : return -EIO;
4690 : : }
4691 : :
4692 : 0 : ret = hns3_reset_queue(hw, tx_queue_id, HNS3_RING_TYPE_TX);
4693 [ # # ]: 0 : if (ret) {
4694 : 0 : hns3_err(hw, "fail to reset Tx queue %u, ret = %d.",
4695 : : tx_queue_id, ret);
4696 : : rte_spinlock_unlock(&hw->lock);
4697 : 0 : return ret;
4698 : : }
4699 : :
4700 : 0 : hns3_init_txq(txq);
4701 : : hns3_enable_txq(txq, true);
4702 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
4703 : : rte_spinlock_unlock(&hw->lock);
4704 : :
4705 : 0 : return ret;
4706 : : }
4707 : :
4708 : : int
4709 : 0 : hns3_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
4710 : : {
4711 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4712 : 0 : struct hns3_tx_queue *txq = dev->data->tx_queues[tx_queue_id];
4713 : :
4714 [ # # ]: 0 : if (!hns3_dev_get_support(hw, INDEP_TXRX))
4715 : : return -ENOTSUP;
4716 : :
4717 : 0 : rte_spinlock_lock(&hw->lock);
4718 : :
4719 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.resetting, rte_memory_order_relaxed)) {
4720 : 0 : hns3_err(hw, "fail to stop Tx queue during resetting.");
4721 : : rte_spinlock_unlock(&hw->lock);
4722 : 0 : return -EIO;
4723 : : }
4724 : :
4725 : : hns3_enable_txq(txq, false);
4726 : 0 : hns3_tx_queue_release_mbufs(txq);
4727 : : /*
4728 : : * All the mbufs in sw_ring are released and all the pointers in sw_ring
4729 : : * are set to NULL. If this queue is still called by upper layer,
4730 : : * residual SW status of this txq may cause these pointers in sw_ring
4731 : : * which have been set to NULL to be released again. To avoid it,
4732 : : * reinit the txq.
4733 : : */
4734 : 0 : hns3_init_txq(txq);
4735 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
4736 : : rte_spinlock_unlock(&hw->lock);
4737 : :
4738 : 0 : return 0;
4739 : : }
4740 : :
4741 : : static int
4742 : 0 : hns3_tx_done_cleanup_full(struct hns3_tx_queue *txq, uint32_t free_cnt)
4743 : : {
4744 : 0 : uint16_t next_to_clean = txq->next_to_clean;
4745 : 0 : uint16_t next_to_use = txq->next_to_use;
4746 : 0 : uint16_t tx_bd_ready = txq->tx_bd_ready;
4747 : 0 : struct hns3_entry *tx_pkt = &txq->sw_ring[next_to_clean];
4748 : 0 : struct hns3_desc *desc = &txq->tx_ring[next_to_clean];
4749 : : uint32_t idx;
4750 : :
4751 [ # # # # ]: 0 : if (free_cnt == 0 || free_cnt > txq->nb_tx_desc)
4752 : 0 : free_cnt = txq->nb_tx_desc;
4753 : :
4754 [ # # ]: 0 : for (idx = 0; idx < free_cnt; idx++) {
4755 [ # # ]: 0 : if (next_to_clean == next_to_use)
4756 : : break;
4757 [ # # ]: 0 : if (desc->tx.tp_fe_sc_vld_ra_ri &
4758 : : rte_cpu_to_le_16(BIT(HNS3_TXD_VLD_B)))
4759 : : break;
4760 [ # # ]: 0 : if (tx_pkt->mbuf != NULL) {
4761 : : rte_pktmbuf_free_seg(tx_pkt->mbuf);
4762 : 0 : tx_pkt->mbuf = NULL;
4763 : : }
4764 : 0 : next_to_clean++;
4765 : 0 : tx_bd_ready++;
4766 : 0 : tx_pkt++;
4767 : 0 : desc++;
4768 [ # # ]: 0 : if (next_to_clean == txq->nb_tx_desc) {
4769 : 0 : tx_pkt = txq->sw_ring;
4770 : 0 : desc = txq->tx_ring;
4771 : : next_to_clean = 0;
4772 : : }
4773 : : }
4774 : :
4775 [ # # ]: 0 : if (idx > 0) {
4776 : 0 : txq->next_to_clean = next_to_clean;
4777 : 0 : txq->tx_bd_ready = tx_bd_ready;
4778 : : }
4779 : :
4780 : 0 : return (int)idx;
4781 : : }
4782 : :
4783 : : int
4784 : 0 : hns3_tx_done_cleanup(void *txq, uint32_t free_cnt)
4785 : : {
4786 : : struct hns3_tx_queue *q = (struct hns3_tx_queue *)txq;
4787 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[q->port_id];
4788 : :
4789 [ # # ]: 0 : if (dev->tx_pkt_burst == hns3_xmit_pkts)
4790 : 0 : return hns3_tx_done_cleanup_full(q, free_cnt);
4791 [ # # ]: 0 : else if (dev->tx_pkt_burst == rte_eth_pkt_burst_dummy)
4792 : : return 0;
4793 : : else
4794 : 0 : return -ENOTSUP;
4795 : : }
4796 : :
4797 : : int
4798 : 0 : hns3_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
4799 : : {
4800 : : volatile struct hns3_desc *rxdp;
4801 : : struct hns3_rx_queue *rxq;
4802 : : struct rte_eth_dev *dev;
4803 : : uint32_t bd_base_info;
4804 : : uint16_t desc_id;
4805 : :
4806 : : rxq = (struct hns3_rx_queue *)rx_queue;
4807 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc)
4808 : : return -EINVAL;
4809 : :
4810 : 0 : desc_id = (rxq->next_to_use + offset) % rxq->nb_rx_desc;
4811 : 0 : rxdp = &rxq->rx_ring[desc_id];
4812 : 0 : bd_base_info = rte_le_to_cpu_32(rxdp->rx.bd_base_info);
4813 : 0 : dev = &rte_eth_devices[rxq->port_id];
4814 [ # # # # ]: 0 : if (dev->rx_pkt_burst == hns3_recv_pkts_simple ||
4815 : : dev->rx_pkt_burst == hns3_recv_scattered_pkts) {
4816 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - rxq->rx_free_hold)
4817 : : return RTE_ETH_RX_DESC_UNAVAIL;
4818 [ # # # # ]: 0 : } else if (dev->rx_pkt_burst == hns3_recv_pkts_vec ||
4819 : : dev->rx_pkt_burst == hns3_recv_pkts_vec_sve) {
4820 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - rxq->rx_rearm_nb)
4821 : : return RTE_ETH_RX_DESC_UNAVAIL;
4822 : : } else {
4823 : : return RTE_ETH_RX_DESC_UNAVAIL;
4824 : : }
4825 : :
4826 [ # # ]: 0 : if (!(bd_base_info & BIT(HNS3_RXD_VLD_B)))
4827 : : return RTE_ETH_RX_DESC_AVAIL;
4828 : : else
4829 : 0 : return RTE_ETH_RX_DESC_DONE;
4830 : : }
4831 : :
4832 : : int
4833 : 0 : hns3_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
4834 : : {
4835 : : volatile struct hns3_desc *txdp;
4836 : : struct hns3_tx_queue *txq;
4837 : : struct rte_eth_dev *dev;
4838 : : uint16_t desc_id;
4839 : :
4840 : : txq = (struct hns3_tx_queue *)tx_queue;
4841 [ # # ]: 0 : if (offset >= txq->nb_tx_desc)
4842 : : return -EINVAL;
4843 : :
4844 : 0 : dev = &rte_eth_devices[txq->port_id];
4845 [ # # # # ]: 0 : if (dev->tx_pkt_burst != hns3_xmit_pkts_simple &&
4846 [ # # ]: 0 : dev->tx_pkt_burst != hns3_xmit_pkts &&
4847 [ # # ]: 0 : dev->tx_pkt_burst != hns3_xmit_pkts_vec_sve &&
4848 : : dev->tx_pkt_burst != hns3_xmit_pkts_vec)
4849 : : return RTE_ETH_TX_DESC_UNAVAIL;
4850 : :
4851 : 0 : desc_id = (txq->next_to_use + offset) % txq->nb_tx_desc;
4852 : 0 : txdp = &txq->tx_ring[desc_id];
4853 [ # # ]: 0 : if (txdp->tx.tp_fe_sc_vld_ra_ri & rte_cpu_to_le_16(BIT(HNS3_TXD_VLD_B)))
4854 : : return RTE_ETH_TX_DESC_FULL;
4855 : : else
4856 : 0 : return RTE_ETH_TX_DESC_DONE;
4857 : : }
4858 : :
4859 : : uint32_t
4860 : 0 : hns3_rx_queue_count(void *rx_queue)
4861 : : {
4862 : : /*
4863 : : * Number of BDs that have been processed by the driver
4864 : : * but have not been notified to the hardware.
4865 : : */
4866 : : uint32_t driver_hold_bd_num;
4867 : : struct hns3_rx_queue *rxq;
4868 : : const struct rte_eth_dev *dev;
4869 : : uint32_t fbd_num;
4870 : :
4871 : : rxq = rx_queue;
4872 : 0 : dev = &rte_eth_devices[rxq->port_id];
4873 : :
4874 : 0 : fbd_num = hns3_read_dev(rxq, HNS3_RING_RX_FBDNUM_REG);
4875 [ # # # # ]: 0 : if (dev->rx_pkt_burst == hns3_recv_pkts_vec ||
4876 : : dev->rx_pkt_burst == hns3_recv_pkts_vec_sve)
4877 : 0 : driver_hold_bd_num = rxq->rx_rearm_nb;
4878 : : else
4879 : 0 : driver_hold_bd_num = rxq->rx_free_hold;
4880 : :
4881 [ # # ]: 0 : if (fbd_num <= driver_hold_bd_num)
4882 : : return 0;
4883 : : else
4884 : 0 : return fbd_num - driver_hold_bd_num;
4885 : : }
4886 : :
4887 : : void
4888 : 0 : hns3_enable_rxd_adv_layout(struct hns3_hw *hw)
4889 : : {
4890 : : /*
4891 : : * If the hardware support rxd advanced layout, then driver enable it
4892 : : * default.
4893 : : */
4894 [ # # ]: 0 : if (hns3_dev_get_support(hw, RXD_ADV_LAYOUT))
4895 : 0 : hns3_write_dev(hw, HNS3_RXD_ADV_LAYOUT_EN_REG, 1);
4896 : 0 : }
4897 : :
4898 : : void
4899 : 0 : hns3_stop_tx_datapath(struct rte_eth_dev *dev)
4900 : : {
4901 : 0 : dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
4902 : 0 : dev->tx_pkt_prepare = NULL;
4903 : : hns3_eth_dev_fp_ops_config(dev);
4904 : :
4905 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY)
4906 : : return;
4907 : :
4908 : : rte_wmb();
4909 : : /* Disable tx datapath on secondary process. */
4910 : 0 : hns3_mp_req_stop_tx(dev);
4911 : : /* Prevent crashes when queues are still in use. */
4912 : 0 : rte_delay_ms(dev->data->nb_tx_queues);
4913 : : }
4914 : :
4915 : : void
4916 : 0 : hns3_start_tx_datapath(struct rte_eth_dev *dev)
4917 : : {
4918 [ # # ]: 0 : dev->tx_pkt_burst = hns3_get_tx_function(dev);
4919 : 0 : dev->tx_pkt_prepare = hns3_get_tx_prepare(dev);
4920 : : hns3_eth_dev_fp_ops_config(dev);
4921 : :
4922 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY)
4923 : : return;
4924 : :
4925 : 0 : hns3_mp_req_start_tx(dev);
4926 : : }
4927 : :
4928 : : void
4929 : 0 : hns3_stop_rxtx_datapath(struct rte_eth_dev *dev)
4930 : : {
4931 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4932 : :
4933 : 0 : hns3_set_rxtx_function(dev);
4934 : :
4935 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY)
4936 : : return;
4937 : :
4938 : : rte_wmb();
4939 : : /* Disable datapath on secondary process. */
4940 : 0 : hns3_mp_req_stop_rxtx(dev);
4941 : : /* Prevent crashes when queues are still in use. */
4942 : 0 : rte_delay_ms(hw->cfg_max_queues);
4943 : : }
4944 : :
4945 : : void
4946 : 0 : hns3_start_rxtx_datapath(struct rte_eth_dev *dev)
4947 : : {
4948 : 0 : hns3_set_rxtx_function(dev);
4949 : :
4950 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY)
4951 : : return;
4952 : :
4953 : 0 : hns3_mp_req_start_rxtx(dev);
4954 : : }
4955 : :
4956 : : static int
4957 : 0 : hns3_monitor_callback(const uint64_t value,
4958 : : const uint64_t arg[RTE_POWER_MONITOR_OPAQUE_SZ] __rte_unused)
4959 : : {
4960 : : const uint64_t vld = rte_le_to_cpu_32(BIT(HNS3_RXD_VLD_B));
4961 [ # # ]: 0 : return (value & vld) == vld ? -1 : 0;
4962 : : }
4963 : :
4964 : : int
4965 : 0 : hns3_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc)
4966 : : {
4967 : : struct hns3_rx_queue *rxq = rx_queue;
4968 : 0 : struct hns3_desc *rxdp = &rxq->rx_ring[rxq->next_to_use];
4969 : :
4970 : 0 : pmc->addr = &rxdp->rx.bd_base_info;
4971 : 0 : pmc->fn = hns3_monitor_callback;
4972 : 0 : pmc->size = sizeof(uint32_t);
4973 : :
4974 : 0 : return 0;
4975 : : }
|