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 void
1184 : 0 : hns3_init_tx_ring_tc(struct hns3_adapter *hns)
1185 : : {
1186 : : struct hns3_hw *hw = &hns->hw;
1187 : : struct hns3_tx_queue *txq;
1188 : : int i, num;
1189 : :
1190 [ # # ]: 0 : for (i = 0; i < HNS3_MAX_TC_NUM; i++) {
1191 : : struct hns3_tc_queue_info *tc_queue = &hw->tc_queue[i];
1192 : : uint16_t j;
1193 : :
1194 [ # # ]: 0 : if (!tc_queue->enable)
1195 : 0 : continue;
1196 : :
1197 [ # # ]: 0 : for (j = 0; j < tc_queue->tqp_count; j++) {
1198 : 0 : num = tc_queue->tqp_offset + j;
1199 : 0 : txq = (struct hns3_tx_queue *)hw->data->tx_queues[num];
1200 [ # # ]: 0 : if (txq == NULL)
1201 : 0 : continue;
1202 : :
1203 : 0 : hns3_write_dev(txq, HNS3_RING_TX_TC_REG, tc_queue->tc);
1204 : : }
1205 : : }
1206 : 0 : }
1207 : :
1208 : : static int
1209 : 0 : hns3_init_rx_queues(struct hns3_adapter *hns)
1210 : : {
1211 : : struct hns3_hw *hw = &hns->hw;
1212 : : struct hns3_rx_queue *rxq;
1213 : : uint16_t i, j;
1214 : : int ret;
1215 : :
1216 : : /* Initialize RSS for queues */
1217 : 0 : ret = hns3_config_rss(hns);
1218 [ # # ]: 0 : if (ret) {
1219 : 0 : hns3_err(hw, "failed to configure rss, ret = %d.", ret);
1220 : 0 : return ret;
1221 : : }
1222 : :
1223 [ # # ]: 0 : for (i = 0; i < hw->data->nb_rx_queues; i++) {
1224 : 0 : rxq = (struct hns3_rx_queue *)hw->data->rx_queues[i];
1225 [ # # ]: 0 : if (!rxq) {
1226 : 0 : hns3_err(hw, "Rx queue %u not available or setup.", i);
1227 : 0 : goto out;
1228 : : }
1229 : :
1230 [ # # ]: 0 : if (rxq->rx_deferred_start)
1231 : 0 : continue;
1232 : :
1233 : 0 : ret = hns3_init_rxq(hns, i);
1234 [ # # ]: 0 : if (ret) {
1235 : 0 : hns3_err(hw, "failed to init Rx queue %u, ret = %d.", i,
1236 : : ret);
1237 : 0 : goto out;
1238 : : }
1239 : : }
1240 : :
1241 [ # # ]: 0 : for (i = 0; i < hw->fkq_data.nb_fake_rx_queues; i++)
1242 : : hns3_init_fake_rxq(hns, i);
1243 : :
1244 : : return 0;
1245 : :
1246 : 0 : out:
1247 [ # # ]: 0 : for (j = 0; j < i; j++) {
1248 : 0 : rxq = (struct hns3_rx_queue *)hw->data->rx_queues[j];
1249 [ # # ]: 0 : if (rxq->rx_deferred_start)
1250 : 0 : continue;
1251 : :
1252 : 0 : hns3_rx_queue_release_mbufs(rxq);
1253 : : }
1254 : :
1255 : : return ret;
1256 : : }
1257 : :
1258 : : static int
1259 : 0 : hns3_init_tx_queues(struct hns3_adapter *hns)
1260 : : {
1261 : : struct hns3_hw *hw = &hns->hw;
1262 : : struct hns3_tx_queue *txq;
1263 : : uint16_t i;
1264 : :
1265 [ # # ]: 0 : for (i = 0; i < hw->data->nb_tx_queues; i++) {
1266 : 0 : txq = (struct hns3_tx_queue *)hw->data->tx_queues[i];
1267 [ # # ]: 0 : if (!txq) {
1268 : 0 : hns3_err(hw, "Tx queue %u not available or setup.", i);
1269 : 0 : return -EINVAL;
1270 : : }
1271 : :
1272 [ # # ]: 0 : if (txq->tx_deferred_start)
1273 : 0 : continue;
1274 : 0 : hns3_init_txq(txq);
1275 : : }
1276 : :
1277 [ # # ]: 0 : for (i = 0; i < hw->fkq_data.nb_fake_tx_queues; i++) {
1278 : 0 : txq = (struct hns3_tx_queue *)hw->fkq_data.tx_queues[i];
1279 : 0 : hns3_init_txq(txq);
1280 : : }
1281 : 0 : hns3_init_tx_ring_tc(hns);
1282 : :
1283 : 0 : return 0;
1284 : : }
1285 : :
1286 : : /*
1287 : : * Init all queues.
1288 : : * Note: just init and setup queues, and don't enable tqps.
1289 : : */
1290 : : int
1291 : 0 : hns3_init_queues(struct hns3_adapter *hns, bool reset_queue)
1292 : : {
1293 : : struct hns3_hw *hw = &hns->hw;
1294 : : int ret;
1295 : :
1296 [ # # ]: 0 : if (reset_queue) {
1297 : 0 : ret = hns3_reset_all_tqps(hns);
1298 [ # # ]: 0 : if (ret) {
1299 : 0 : hns3_err(hw, "failed to reset all queues, ret = %d.",
1300 : : ret);
1301 : 0 : return ret;
1302 : : }
1303 : : }
1304 : :
1305 : 0 : ret = hns3_init_rx_queues(hns);
1306 [ # # ]: 0 : if (ret) {
1307 : 0 : hns3_err(hw, "failed to init rx queues, ret = %d.", ret);
1308 : 0 : return ret;
1309 : : }
1310 : :
1311 : 0 : ret = hns3_init_tx_queues(hns);
1312 [ # # ]: 0 : if (ret) {
1313 : 0 : hns3_dev_release_mbufs(hns);
1314 : 0 : hns3_err(hw, "failed to init tx queues, ret = %d.", ret);
1315 : : }
1316 : :
1317 : : return ret;
1318 : : }
1319 : :
1320 : : void
1321 : 0 : hns3_start_tqps(struct hns3_hw *hw)
1322 : : {
1323 : : struct hns3_tx_queue *txq;
1324 : : struct hns3_rx_queue *rxq;
1325 : : uint16_t i;
1326 : :
1327 : 0 : hns3_enable_all_queues(hw, true);
1328 : :
1329 [ # # ]: 0 : for (i = 0; i < hw->data->nb_tx_queues; i++) {
1330 [ # # ]: 0 : __rte_assume(i < RTE_MAX_QUEUES_PER_PORT);
1331 : 0 : txq = hw->data->tx_queues[i];
1332 [ # # ]: 0 : if (txq->enabled)
1333 : 0 : hw->data->tx_queue_state[i] =
1334 : : RTE_ETH_QUEUE_STATE_STARTED;
1335 : : }
1336 : :
1337 [ # # ]: 0 : for (i = 0; i < hw->data->nb_rx_queues; i++) {
1338 [ # # ]: 0 : __rte_assume(i < RTE_MAX_QUEUES_PER_PORT);
1339 : 0 : rxq = hw->data->rx_queues[i];
1340 [ # # ]: 0 : if (rxq->enabled)
1341 : 0 : hw->data->rx_queue_state[i] =
1342 : : RTE_ETH_QUEUE_STATE_STARTED;
1343 : : }
1344 : 0 : }
1345 : :
1346 : : void
1347 : 0 : hns3_stop_tqps(struct hns3_hw *hw)
1348 : : {
1349 : : uint16_t i;
1350 : :
1351 : 0 : hns3_enable_all_queues(hw, false);
1352 : :
1353 [ # # ]: 0 : for (i = 0; i < hw->data->nb_tx_queues; i++)
1354 : 0 : hw->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1355 : :
1356 [ # # ]: 0 : for (i = 0; i < hw->data->nb_rx_queues; i++)
1357 : 0 : hw->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
1358 : 0 : }
1359 : :
1360 : : /*
1361 : : * Iterate over all Rx Queue, and call the callback() function for each Rx
1362 : : * queue.
1363 : : *
1364 : : * @param[in] dev
1365 : : * The target eth dev.
1366 : : * @param[in] callback
1367 : : * The function to call for each queue.
1368 : : * if callback function return nonzero will stop iterate and return it's value
1369 : : * @param[in] arg
1370 : : * The arguments to provide the callback function with.
1371 : : *
1372 : : * @return
1373 : : * 0 on success, otherwise with errno set.
1374 : : */
1375 : : int
1376 : 0 : hns3_rxq_iterate(struct rte_eth_dev *dev,
1377 : : int (*callback)(struct hns3_rx_queue *, void *), void *arg)
1378 : : {
1379 : : uint32_t i;
1380 : : int ret;
1381 : :
1382 [ # # ]: 0 : if (dev->data->rx_queues == NULL)
1383 : : return -EINVAL;
1384 : :
1385 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1386 : 0 : ret = callback(dev->data->rx_queues[i], arg);
1387 [ # # ]: 0 : if (ret != 0)
1388 : 0 : return ret;
1389 : : }
1390 : :
1391 : : return 0;
1392 : : }
1393 : :
1394 : : static void*
1395 : 0 : hns3_alloc_rxq_and_dma_zone(struct rte_eth_dev *dev,
1396 : : struct hns3_queue_info *q_info)
1397 : : {
1398 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1399 : : const struct rte_memzone *rx_mz;
1400 : : struct hns3_rx_queue *rxq;
1401 : : unsigned int rx_desc;
1402 : :
1403 : 0 : rxq = rte_zmalloc_socket(q_info->type, sizeof(struct hns3_rx_queue),
1404 : 0 : RTE_CACHE_LINE_SIZE, q_info->socket_id);
1405 [ # # ]: 0 : if (rxq == NULL) {
1406 : 0 : hns3_err(hw, "Failed to allocate memory for No.%u rx ring!",
1407 : : q_info->idx);
1408 : 0 : return NULL;
1409 : : }
1410 : :
1411 : : /* Allocate rx ring hardware descriptors. */
1412 : 0 : rxq->queue_id = q_info->idx;
1413 : 0 : rxq->nb_rx_desc = q_info->nb_desc;
1414 : :
1415 : : /*
1416 : : * Allocate a litter more memory because rx vector functions
1417 : : * don't check boundaries each time.
1418 : : */
1419 : 0 : rx_desc = (rxq->nb_rx_desc + HNS3_DEFAULT_RX_BURST) *
1420 : : sizeof(struct hns3_desc);
1421 : 0 : rx_mz = rte_eth_dma_zone_reserve(dev, q_info->ring_name, q_info->idx,
1422 : : rx_desc, HNS3_RING_BASE_ALIGN,
1423 : 0 : q_info->socket_id);
1424 [ # # ]: 0 : if (rx_mz == NULL) {
1425 : 0 : hns3_err(hw, "Failed to reserve DMA memory for No.%u rx ring!",
1426 : : q_info->idx);
1427 : 0 : hns3_rx_queue_release(rxq);
1428 : 0 : return NULL;
1429 : : }
1430 : 0 : rxq->mz = rx_mz;
1431 : 0 : rxq->rx_ring = (struct hns3_desc *)rx_mz->addr;
1432 : 0 : rxq->rx_ring_phys_addr = rx_mz->iova;
1433 : :
1434 : 0 : return rxq;
1435 : : }
1436 : :
1437 : : static int
1438 : 0 : hns3_fake_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
1439 : : uint16_t nb_desc, unsigned int socket_id)
1440 : : {
1441 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
1442 : : struct hns3_hw *hw = &hns->hw;
1443 : : struct hns3_queue_info q_info;
1444 : : struct hns3_rx_queue *rxq;
1445 : : uint16_t nb_rx_q;
1446 : :
1447 [ # # ]: 0 : if (hw->fkq_data.rx_queues[idx]) {
1448 : 0 : hns3_rx_queue_release(hw->fkq_data.rx_queues[idx]);
1449 : 0 : hw->fkq_data.rx_queues[idx] = NULL;
1450 : : }
1451 : :
1452 : 0 : q_info.idx = idx;
1453 : 0 : q_info.socket_id = socket_id;
1454 : 0 : q_info.nb_desc = nb_desc;
1455 : 0 : q_info.type = "hns3 fake RX queue";
1456 : 0 : q_info.ring_name = "rx_fake_ring";
1457 : 0 : rxq = hns3_alloc_rxq_and_dma_zone(dev, &q_info);
1458 [ # # ]: 0 : if (rxq == NULL) {
1459 : 0 : hns3_err(hw, "Failed to setup No.%u fake rx ring.", idx);
1460 : 0 : return -ENOMEM;
1461 : : }
1462 : :
1463 : : /* Don't need alloc sw_ring, because upper applications don't use it */
1464 : 0 : rxq->sw_ring = NULL;
1465 : :
1466 : 0 : rxq->hns = hns;
1467 : 0 : rxq->rx_deferred_start = false;
1468 : 0 : rxq->port_id = dev->data->port_id;
1469 : 0 : rxq->configured = true;
1470 : 0 : nb_rx_q = dev->data->nb_rx_queues;
1471 : 0 : rxq->io_base = (void *)((char *)hw->io_base + HNS3_TQP_REG_OFFSET +
1472 : 0 : (nb_rx_q + idx) * HNS3_TQP_REG_SIZE);
1473 : 0 : rxq->rx_buf_len = HNS3_MIN_BD_BUF_SIZE;
1474 : :
1475 : 0 : rte_spinlock_lock(&hw->lock);
1476 : 0 : hw->fkq_data.rx_queues[idx] = rxq;
1477 : : rte_spinlock_unlock(&hw->lock);
1478 : :
1479 : 0 : return 0;
1480 : : }
1481 : :
1482 : : static void*
1483 : 0 : hns3_alloc_txq_and_dma_zone(struct rte_eth_dev *dev,
1484 : : struct hns3_queue_info *q_info)
1485 : : {
1486 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1487 : : const struct rte_memzone *tx_mz;
1488 : : struct hns3_tx_queue *txq;
1489 : : struct hns3_desc *desc;
1490 : : unsigned int tx_desc;
1491 : : uint16_t i;
1492 : :
1493 : 0 : txq = rte_zmalloc_socket(q_info->type, sizeof(struct hns3_tx_queue),
1494 : 0 : RTE_CACHE_LINE_SIZE, q_info->socket_id);
1495 [ # # ]: 0 : if (txq == NULL) {
1496 : 0 : hns3_err(hw, "Failed to allocate memory for No.%u tx ring!",
1497 : : q_info->idx);
1498 : 0 : return NULL;
1499 : : }
1500 : :
1501 : : /* Allocate tx ring hardware descriptors. */
1502 : 0 : txq->queue_id = q_info->idx;
1503 : 0 : txq->nb_tx_desc = q_info->nb_desc;
1504 : 0 : tx_desc = txq->nb_tx_desc * sizeof(struct hns3_desc);
1505 : 0 : tx_mz = rte_eth_dma_zone_reserve(dev, q_info->ring_name, q_info->idx,
1506 : : tx_desc, HNS3_RING_BASE_ALIGN,
1507 : 0 : q_info->socket_id);
1508 [ # # ]: 0 : if (tx_mz == NULL) {
1509 : 0 : hns3_err(hw, "Failed to reserve DMA memory for No.%u tx ring!",
1510 : : q_info->idx);
1511 : 0 : hns3_tx_queue_release(txq);
1512 : 0 : return NULL;
1513 : : }
1514 : 0 : txq->mz = tx_mz;
1515 : 0 : txq->tx_ring = (struct hns3_desc *)tx_mz->addr;
1516 : 0 : txq->tx_ring_phys_addr = tx_mz->iova;
1517 : :
1518 : : /* Clear tx bd */
1519 : : desc = txq->tx_ring;
1520 [ # # ]: 0 : for (i = 0; i < txq->nb_tx_desc; i++) {
1521 : 0 : desc->tx.tp_fe_sc_vld_ra_ri = 0;
1522 : 0 : desc++;
1523 : : }
1524 : :
1525 : : return txq;
1526 : : }
1527 : :
1528 : : static int
1529 : 0 : hns3_fake_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx,
1530 : : uint16_t nb_desc, unsigned int socket_id)
1531 : : {
1532 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
1533 : : struct hns3_hw *hw = &hns->hw;
1534 : : struct hns3_queue_info q_info;
1535 : : struct hns3_tx_queue *txq;
1536 : : uint16_t nb_tx_q;
1537 : :
1538 [ # # ]: 0 : if (hw->fkq_data.tx_queues[idx] != NULL) {
1539 : 0 : hns3_tx_queue_release(hw->fkq_data.tx_queues[idx]);
1540 : 0 : hw->fkq_data.tx_queues[idx] = NULL;
1541 : : }
1542 : :
1543 : 0 : q_info.idx = idx;
1544 : 0 : q_info.socket_id = socket_id;
1545 : 0 : q_info.nb_desc = nb_desc;
1546 : 0 : q_info.type = "hns3 fake TX queue";
1547 : 0 : q_info.ring_name = "tx_fake_ring";
1548 : 0 : txq = hns3_alloc_txq_and_dma_zone(dev, &q_info);
1549 [ # # ]: 0 : if (txq == NULL) {
1550 : 0 : hns3_err(hw, "Failed to setup No.%u fake tx ring.", idx);
1551 : 0 : return -ENOMEM;
1552 : : }
1553 : :
1554 : : /* Don't need alloc sw_ring, because upper applications don't use it */
1555 : 0 : txq->sw_ring = NULL;
1556 : 0 : txq->free = NULL;
1557 : :
1558 : 0 : txq->hns = hns;
1559 : 0 : txq->tx_deferred_start = false;
1560 : 0 : txq->port_id = dev->data->port_id;
1561 : 0 : txq->configured = true;
1562 : 0 : nb_tx_q = dev->data->nb_tx_queues;
1563 : 0 : txq->io_base = (void *)((char *)hw->io_base + HNS3_TQP_REG_OFFSET +
1564 : 0 : (nb_tx_q + idx) * HNS3_TQP_REG_SIZE);
1565 : :
1566 : 0 : rte_spinlock_lock(&hw->lock);
1567 : 0 : hw->fkq_data.tx_queues[idx] = txq;
1568 : : rte_spinlock_unlock(&hw->lock);
1569 : :
1570 : 0 : return 0;
1571 : : }
1572 : :
1573 : : static int
1574 : 0 : hns3_fake_rx_queue_config(struct hns3_hw *hw, uint16_t nb_queues)
1575 : : {
1576 : 0 : uint16_t old_nb_queues = hw->fkq_data.nb_fake_rx_queues;
1577 : : void **rxq;
1578 : : uint16_t i;
1579 : :
1580 [ # # # # ]: 0 : if (hw->fkq_data.rx_queues == NULL && nb_queues != 0) {
1581 : : /* first time configuration */
1582 : : uint32_t size;
1583 : 0 : size = sizeof(hw->fkq_data.rx_queues[0]) * nb_queues;
1584 : 0 : hw->fkq_data.rx_queues = rte_zmalloc("fake_rx_queues", size,
1585 : : RTE_CACHE_LINE_SIZE);
1586 [ # # ]: 0 : if (hw->fkq_data.rx_queues == NULL) {
1587 : 0 : hw->fkq_data.nb_fake_rx_queues = 0;
1588 : 0 : return -ENOMEM;
1589 : : }
1590 [ # # # # ]: 0 : } else if (hw->fkq_data.rx_queues != NULL && nb_queues != 0) {
1591 : : /* re-configure */
1592 : : rxq = hw->fkq_data.rx_queues;
1593 [ # # ]: 0 : for (i = nb_queues; i < old_nb_queues; i++)
1594 : 0 : hns3_rx_queue_release_lock(rxq[i]);
1595 : :
1596 : 0 : rxq = rte_realloc(rxq, sizeof(rxq[0]) * nb_queues,
1597 : : RTE_CACHE_LINE_SIZE);
1598 [ # # ]: 0 : if (rxq == NULL)
1599 : : return -ENOMEM;
1600 [ # # ]: 0 : if (nb_queues > old_nb_queues) {
1601 : 0 : uint16_t new_qs = nb_queues - old_nb_queues;
1602 : 0 : memset(rxq + old_nb_queues, 0, sizeof(rxq[0]) * new_qs);
1603 : : }
1604 : :
1605 : 0 : hw->fkq_data.rx_queues = rxq;
1606 [ # # # # ]: 0 : } else if (hw->fkq_data.rx_queues != NULL && nb_queues == 0) {
1607 : : rxq = hw->fkq_data.rx_queues;
1608 [ # # ]: 0 : for (i = nb_queues; i < old_nb_queues; i++)
1609 : 0 : hns3_rx_queue_release_lock(rxq[i]);
1610 : :
1611 : 0 : rte_free(hw->fkq_data.rx_queues);
1612 : 0 : hw->fkq_data.rx_queues = NULL;
1613 : : }
1614 : :
1615 : 0 : hw->fkq_data.nb_fake_rx_queues = nb_queues;
1616 : :
1617 : 0 : return 0;
1618 : : }
1619 : :
1620 : : static int
1621 : 0 : hns3_fake_tx_queue_config(struct hns3_hw *hw, uint16_t nb_queues)
1622 : : {
1623 : 0 : uint16_t old_nb_queues = hw->fkq_data.nb_fake_tx_queues;
1624 : : void **txq;
1625 : : uint16_t i;
1626 : :
1627 [ # # # # ]: 0 : if (hw->fkq_data.tx_queues == NULL && nb_queues != 0) {
1628 : : /* first time configuration */
1629 : : uint32_t size;
1630 : 0 : size = sizeof(hw->fkq_data.tx_queues[0]) * nb_queues;
1631 : 0 : hw->fkq_data.tx_queues = rte_zmalloc("fake_tx_queues", size,
1632 : : RTE_CACHE_LINE_SIZE);
1633 [ # # ]: 0 : if (hw->fkq_data.tx_queues == NULL) {
1634 : 0 : hw->fkq_data.nb_fake_tx_queues = 0;
1635 : 0 : return -ENOMEM;
1636 : : }
1637 [ # # # # ]: 0 : } else if (hw->fkq_data.tx_queues != NULL && nb_queues != 0) {
1638 : : /* re-configure */
1639 : : txq = hw->fkq_data.tx_queues;
1640 [ # # ]: 0 : for (i = nb_queues; i < old_nb_queues; i++)
1641 : 0 : hns3_tx_queue_release_lock(txq[i]);
1642 : 0 : txq = rte_realloc(txq, sizeof(txq[0]) * nb_queues,
1643 : : RTE_CACHE_LINE_SIZE);
1644 [ # # ]: 0 : if (txq == NULL)
1645 : : return -ENOMEM;
1646 [ # # ]: 0 : if (nb_queues > old_nb_queues) {
1647 : 0 : uint16_t new_qs = nb_queues - old_nb_queues;
1648 : 0 : memset(txq + old_nb_queues, 0, sizeof(txq[0]) * new_qs);
1649 : : }
1650 : :
1651 : 0 : hw->fkq_data.tx_queues = txq;
1652 [ # # # # ]: 0 : } else if (hw->fkq_data.tx_queues != NULL && nb_queues == 0) {
1653 : : txq = hw->fkq_data.tx_queues;
1654 [ # # ]: 0 : for (i = nb_queues; i < old_nb_queues; i++)
1655 : 0 : hns3_tx_queue_release_lock(txq[i]);
1656 : :
1657 : 0 : rte_free(hw->fkq_data.tx_queues);
1658 : 0 : hw->fkq_data.tx_queues = NULL;
1659 : : }
1660 : 0 : hw->fkq_data.nb_fake_tx_queues = nb_queues;
1661 : :
1662 : 0 : return 0;
1663 : : }
1664 : :
1665 : : int
1666 : 0 : hns3_set_fake_rx_or_tx_queues(struct rte_eth_dev *dev, uint16_t nb_rx_q,
1667 : : uint16_t nb_tx_q)
1668 : : {
1669 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1670 : : uint16_t rx_need_add_nb_q;
1671 : : uint16_t tx_need_add_nb_q;
1672 : : uint16_t port_id;
1673 : : uint16_t q;
1674 : : int ret;
1675 : :
1676 [ # # ]: 0 : if (hns3_dev_get_support(hw, INDEP_TXRX))
1677 : : return 0;
1678 : :
1679 : : /* Setup new number of fake RX/TX queues and reconfigure device. */
1680 : 0 : rx_need_add_nb_q = hw->cfg_max_queues - nb_rx_q;
1681 : 0 : tx_need_add_nb_q = hw->cfg_max_queues - nb_tx_q;
1682 : 0 : ret = hns3_fake_rx_queue_config(hw, rx_need_add_nb_q);
1683 [ # # ]: 0 : if (ret) {
1684 : 0 : hns3_err(hw, "Fail to configure fake rx queues: %d", ret);
1685 : 0 : return ret;
1686 : : }
1687 : :
1688 : 0 : ret = hns3_fake_tx_queue_config(hw, tx_need_add_nb_q);
1689 [ # # ]: 0 : if (ret) {
1690 : 0 : hns3_err(hw, "Fail to configure fake tx queues: %d", ret);
1691 : 0 : goto cfg_fake_tx_q_fail;
1692 : : }
1693 : :
1694 : : /* Allocate and set up fake RX queue per Ethernet port. */
1695 : 0 : port_id = hw->data->port_id;
1696 [ # # ]: 0 : for (q = 0; q < rx_need_add_nb_q; q++) {
1697 : 0 : ret = hns3_fake_rx_queue_setup(dev, q, HNS3_MIN_RING_DESC,
1698 : 0 : rte_eth_dev_socket_id(port_id));
1699 [ # # ]: 0 : if (ret)
1700 : 0 : goto setup_fake_rx_q_fail;
1701 : : }
1702 : :
1703 : : /* Allocate and set up fake TX queue per Ethernet port. */
1704 [ # # ]: 0 : for (q = 0; q < tx_need_add_nb_q; q++) {
1705 : 0 : ret = hns3_fake_tx_queue_setup(dev, q, HNS3_MIN_RING_DESC,
1706 : 0 : rte_eth_dev_socket_id(port_id));
1707 [ # # ]: 0 : if (ret)
1708 : 0 : goto setup_fake_tx_q_fail;
1709 : : }
1710 : :
1711 : : return 0;
1712 : :
1713 : : setup_fake_tx_q_fail:
1714 : 0 : setup_fake_rx_q_fail:
1715 : 0 : (void)hns3_fake_tx_queue_config(hw, 0);
1716 : 0 : cfg_fake_tx_q_fail:
1717 : 0 : (void)hns3_fake_rx_queue_config(hw, 0);
1718 : :
1719 : 0 : return ret;
1720 : : }
1721 : :
1722 : : void
1723 : 0 : hns3_dev_release_mbufs(struct hns3_adapter *hns)
1724 : : {
1725 : 0 : struct rte_eth_dev_data *dev_data = hns->hw.data;
1726 : : struct hns3_rx_queue *rxq;
1727 : : struct hns3_tx_queue *txq;
1728 : : uint16_t i;
1729 : :
1730 [ # # ]: 0 : if (dev_data->rx_queues)
1731 [ # # ]: 0 : for (i = 0; i < dev_data->nb_rx_queues; i++) {
1732 : 0 : rxq = dev_data->rx_queues[i];
1733 [ # # ]: 0 : if (rxq == NULL)
1734 : 0 : continue;
1735 : 0 : hns3_rx_queue_release_mbufs(rxq);
1736 : : }
1737 : :
1738 [ # # ]: 0 : if (dev_data->tx_queues)
1739 [ # # ]: 0 : for (i = 0; i < dev_data->nb_tx_queues; i++) {
1740 : 0 : txq = dev_data->tx_queues[i];
1741 [ # # ]: 0 : if (txq == NULL)
1742 : 0 : continue;
1743 : 0 : hns3_tx_queue_release_mbufs(txq);
1744 : : }
1745 : 0 : }
1746 : :
1747 : : static int
1748 : : hns3_rx_buf_len_calc(struct rte_mempool *mp, uint16_t *rx_buf_len)
1749 : : {
1750 : : uint16_t vld_buf_size;
1751 : : uint16_t num_hw_specs;
1752 : : uint16_t i;
1753 : :
1754 : : /*
1755 : : * hns3 network engine only support to set 4 typical specification, and
1756 : : * different buffer size will affect the max packet_len and the max
1757 : : * number of segmentation when hw gro is turned on in receive side. The
1758 : : * relationship between them is as follows:
1759 : : * rx_buf_size | max_gro_pkt_len | max_gro_nb_seg
1760 : : * ---------------------|-------------------|----------------
1761 : : * HNS3_4K_BD_BUF_SIZE | 60KB | 15
1762 : : * HNS3_2K_BD_BUF_SIZE | 62KB | 31
1763 : : * HNS3_1K_BD_BUF_SIZE | 63KB | 63
1764 : : * HNS3_512_BD_BUF_SIZE | 31.5KB | 63
1765 : : */
1766 : : static const uint16_t hw_rx_buf_size[] = {
1767 : : HNS3_4K_BD_BUF_SIZE,
1768 : : HNS3_2K_BD_BUF_SIZE,
1769 : : HNS3_1K_BD_BUF_SIZE,
1770 : : HNS3_512_BD_BUF_SIZE
1771 : : };
1772 : :
1773 : 0 : vld_buf_size = (uint16_t)(rte_pktmbuf_data_room_size(mp) -
1774 : : RTE_PKTMBUF_HEADROOM);
1775 [ # # ]: 0 : if (vld_buf_size < HNS3_MIN_BD_BUF_SIZE)
1776 : : return -EINVAL;
1777 : :
1778 : : num_hw_specs = RTE_DIM(hw_rx_buf_size);
1779 [ # # ]: 0 : for (i = 0; i < num_hw_specs; i++) {
1780 [ # # ]: 0 : if (vld_buf_size >= hw_rx_buf_size[i]) {
1781 : 0 : *rx_buf_len = hw_rx_buf_size[i];
1782 : : break;
1783 : : }
1784 : : }
1785 : : return 0;
1786 : : }
1787 : :
1788 : : static int
1789 : 0 : hns3_rxq_conf_runtime_check(struct hns3_hw *hw,
1790 : : const struct rte_eth_rxconf *conf,
1791 : : uint16_t buf_size, uint16_t nb_desc)
1792 : : {
1793 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[hw->data->port_id];
1794 : 0 : eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
1795 : 0 : uint32_t frame_size = dev->data->mtu + HNS3_ETH_OVERHEAD;
1796 : : uint16_t min_vec_bds;
1797 : :
1798 : : /*
1799 : : * HNS3 hardware network engine set scattered as default. If the driver
1800 : : * is not work in scattered mode and the pkts greater than buf_size
1801 : : * but smaller than frame size will be distributed to multiple BDs.
1802 : : * Driver cannot handle this situation.
1803 : : */
1804 [ # # # # ]: 0 : if (!hw->data->scattered_rx && frame_size > buf_size) {
1805 : 0 : hns3_err(hw, "frame size is not allowed to be set greater "
1806 : : "than rx_buf_len if scattered is off.");
1807 : 0 : return -EINVAL;
1808 : : }
1809 : :
1810 [ # # # # ]: 0 : if (pkt_burst == hns3_recv_pkts_vec ||
1811 : : pkt_burst == hns3_recv_pkts_vec_sve) {
1812 : : min_vec_bds = HNS3_DEFAULT_RXQ_REARM_THRESH +
1813 : : HNS3_DEFAULT_RX_BURST;
1814 [ # # # # ]: 0 : if (nb_desc < min_vec_bds ||
1815 : : nb_desc % HNS3_DEFAULT_RXQ_REARM_THRESH) {
1816 : 0 : hns3_err(hw, "if Rx burst mode is vector, "
1817 : : "number of descriptor is required to be "
1818 : : "bigger than min vector bds:%u, and could be "
1819 : : "divided by rxq rearm thresh:%u.",
1820 : : min_vec_bds, HNS3_DEFAULT_RXQ_REARM_THRESH);
1821 : 0 : return -EINVAL;
1822 : : }
1823 : : }
1824 : :
1825 [ # # # # ]: 0 : if ((conf->offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC) &&
1826 [ # # ]: 0 : pkt_burst != hns3_recv_pkts_simple &&
1827 : : pkt_burst != hns3_recv_scattered_pkts) {
1828 : 0 : hns3_err(hw, "KEEP_CRC offload is not supported with the current Rx function.");
1829 : 0 : return -EINVAL;
1830 : : }
1831 : :
1832 : : return 0;
1833 : : }
1834 : :
1835 : : static int
1836 : 0 : hns3_rx_queue_conf_check(struct hns3_hw *hw, const struct rte_eth_rxconf *conf,
1837 : : struct rte_mempool *mp, uint16_t nb_desc,
1838 : : uint16_t *buf_size)
1839 : : {
1840 : : int ret;
1841 : :
1842 [ # # # # ]: 0 : if (nb_desc > HNS3_MAX_RING_DESC || nb_desc < HNS3_MIN_RING_DESC ||
1843 : : nb_desc % HNS3_ALIGN_RING_DESC) {
1844 : 0 : hns3_err(hw, "Number (%u) of rx descriptors is invalid",
1845 : : nb_desc);
1846 : 0 : return -EINVAL;
1847 : : }
1848 : :
1849 [ # # ]: 0 : if (conf->rx_free_thresh >= nb_desc) {
1850 : 0 : hns3_err(hw, "rx_free_thresh (%u) must be less than %u",
1851 : : conf->rx_free_thresh, nb_desc);
1852 : 0 : return -EINVAL;
1853 : : }
1854 : :
1855 [ # # ]: 0 : if (conf->rx_drop_en == 0)
1856 : 0 : hns3_warn(hw, "if no descriptors available, packets are always "
1857 : : "dropped and rx_drop_en (1) is fixed on");
1858 : :
1859 : : if (hns3_rx_buf_len_calc(mp, buf_size)) {
1860 : 0 : hns3_err(hw, "rxq mbufs' data room size (%u) is not enough! "
1861 : : "minimal data room size (%u).",
1862 : : rte_pktmbuf_data_room_size(mp),
1863 : : HNS3_MIN_BD_BUF_SIZE + RTE_PKTMBUF_HEADROOM);
1864 : 0 : return -EINVAL;
1865 : : }
1866 : :
1867 [ # # ]: 0 : if (hw->data->dev_started) {
1868 : 0 : ret = hns3_rxq_conf_runtime_check(hw, conf, *buf_size, nb_desc);
1869 [ # # ]: 0 : if (ret) {
1870 : 0 : hns3_err(hw, "Rx queue runtime setup fail.");
1871 : 0 : return ret;
1872 : : }
1873 : : }
1874 : :
1875 : : return 0;
1876 : : }
1877 : :
1878 : : uint32_t
1879 : 0 : hns3_get_tqp_reg_offset(uint16_t queue_id)
1880 : : {
1881 : : uint32_t reg_offset;
1882 : :
1883 : : /* Need an extend offset to config queue > 1024 */
1884 [ # # ]: 0 : if (queue_id < HNS3_MIN_EXTEND_QUEUE_ID)
1885 : 0 : reg_offset = HNS3_TQP_REG_OFFSET + queue_id * HNS3_TQP_REG_SIZE;
1886 : : else
1887 : 0 : reg_offset = HNS3_TQP_REG_OFFSET + HNS3_TQP_EXT_REG_OFFSET +
1888 : 0 : (queue_id - HNS3_MIN_EXTEND_QUEUE_ID) *
1889 : : HNS3_TQP_REG_SIZE;
1890 : :
1891 : 0 : return reg_offset;
1892 : : }
1893 : :
1894 : : int
1895 : 0 : hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
1896 : : unsigned int socket_id, const struct rte_eth_rxconf *conf,
1897 : : struct rte_mempool *mp)
1898 : : {
1899 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
1900 : 0 : struct hns3_hw *hw = &hns->hw;
1901 : : struct hns3_queue_info q_info;
1902 : : struct hns3_rx_queue *rxq;
1903 : : uint16_t rx_buf_size;
1904 : : int rx_entry_len;
1905 : : int ret;
1906 : :
1907 : 0 : ret = hns3_rx_queue_conf_check(hw, conf, mp, nb_desc, &rx_buf_size);
1908 [ # # ]: 0 : if (ret)
1909 : : return ret;
1910 : :
1911 [ # # ]: 0 : if (dev->data->rx_queues[idx]) {
1912 : 0 : hns3_rx_queue_release(dev->data->rx_queues[idx]);
1913 : 0 : dev->data->rx_queues[idx] = NULL;
1914 : : }
1915 : :
1916 : 0 : q_info.idx = idx;
1917 : 0 : q_info.socket_id = socket_id;
1918 : 0 : q_info.nb_desc = nb_desc;
1919 : 0 : q_info.type = "hns3 RX queue";
1920 : 0 : q_info.ring_name = "rx_ring";
1921 : :
1922 : 0 : rxq = hns3_alloc_rxq_and_dma_zone(dev, &q_info);
1923 [ # # ]: 0 : if (rxq == NULL) {
1924 : 0 : hns3_err(hw,
1925 : : "Failed to alloc mem and reserve DMA mem for rx ring!");
1926 : 0 : return -ENOMEM;
1927 : : }
1928 : :
1929 : 0 : rxq->hns = hns;
1930 : 0 : rxq->ptype_tbl = &hns->ptype_tbl;
1931 : 0 : rxq->mb_pool = mp;
1932 [ # # ]: 0 : rxq->rx_free_thresh = (conf->rx_free_thresh > 0) ?
1933 : : conf->rx_free_thresh : HNS3_DEFAULT_RX_FREE_THRESH;
1934 : :
1935 : 0 : rxq->rx_deferred_start = conf->rx_deferred_start;
1936 [ # # # # ]: 0 : if (rxq->rx_deferred_start && !hns3_dev_get_support(hw, INDEP_TXRX)) {
1937 : 0 : hns3_warn(hw, "deferred start is not supported.");
1938 : 0 : rxq->rx_deferred_start = false;
1939 : : }
1940 : :
1941 : 0 : rx_entry_len = (rxq->nb_rx_desc + HNS3_DEFAULT_RX_BURST) *
1942 : : sizeof(struct hns3_entry);
1943 : 0 : rxq->sw_ring = rte_zmalloc_socket("hns3 RX sw ring", rx_entry_len,
1944 : : RTE_CACHE_LINE_SIZE, socket_id);
1945 [ # # ]: 0 : if (rxq->sw_ring == NULL) {
1946 : 0 : hns3_err(hw, "Failed to allocate memory for rx sw ring!");
1947 : 0 : hns3_rx_queue_release(rxq);
1948 : 0 : return -ENOMEM;
1949 : : }
1950 : :
1951 : 0 : rxq->next_to_use = 0;
1952 : 0 : rxq->rx_free_hold = 0;
1953 : 0 : rxq->rx_rearm_start = 0;
1954 : 0 : rxq->rx_rearm_nb = 0;
1955 : 0 : rxq->pkt_first_seg = NULL;
1956 : 0 : rxq->pkt_last_seg = NULL;
1957 : 0 : rxq->port_id = dev->data->port_id;
1958 : : /*
1959 : : * For hns3 PF device, if the VLAN mode is HW_SHIFT_AND_DISCARD_MODE,
1960 : : * the pvid_sw_discard_en in the queue struct should not be changed,
1961 : : * because PVID-related operations do not need to be processed by PMD.
1962 : : * For hns3 VF device, whether it needs to process PVID depends
1963 : : * on the configuration of PF kernel mode netdevice driver. And the
1964 : : * related PF configuration is delivered through the mailbox and finally
1965 : : * reflected in port_base_vlan_cfg.
1966 : : */
1967 [ # # # # ]: 0 : if (hns->is_vf || hw->vlan_mode == HNS3_SW_SHIFT_AND_DISCARD_MODE)
1968 : 0 : rxq->pvid_sw_discard_en = hw->port_base_vlan_cfg.state ==
1969 : : HNS3_PORT_BASE_VLAN_ENABLE;
1970 : : else
1971 : 0 : rxq->pvid_sw_discard_en = false;
1972 : 0 : rxq->ptype_en = hns3_dev_get_support(hw, RXD_ADV_LAYOUT) ? true : false;
1973 : 0 : rxq->configured = true;
1974 : 0 : rxq->io_base = (void *)((char *)hw->io_base +
1975 : 0 : hns3_get_tqp_reg_offset(idx));
1976 : 0 : rxq->io_head_reg = (volatile void *)((char *)rxq->io_base +
1977 : : HNS3_RING_RX_HEAD_REG);
1978 : 0 : rxq->rx_buf_len = rx_buf_size;
1979 [ # # ]: 0 : memset(&rxq->basic_stats, 0, sizeof(struct hns3_rx_basic_stats));
1980 : 0 : memset(&rxq->err_stats, 0, sizeof(struct hns3_rx_bd_errors_stats));
1981 : 0 : memset(&rxq->dfx_stats, 0, sizeof(struct hns3_rx_dfx_stats));
1982 : :
1983 : : /* CRC len set here is used for amending packet length */
1984 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_KEEP_CRC)
1985 : 0 : rxq->crc_len = RTE_ETHER_CRC_LEN;
1986 : : else
1987 : 0 : rxq->crc_len = 0;
1988 : :
1989 : 0 : rxq->keep_crc_fail_ptype = hw->strip_crc_ptype;
1990 : :
1991 : 0 : rxq->crc_ctx = rte_net_crc_set_alg(RTE_NET_CRC_SCALAR, RTE_NET_CRC32_ETH);
1992 [ # # ]: 0 : if (rxq->crc_ctx == NULL) {
1993 : 0 : hns3_err(hw, "Failed to allocate the CRC context.");
1994 : 0 : hns3_rx_queue_release(rxq);
1995 : 0 : return -ENOMEM;
1996 : : }
1997 : :
1998 : 0 : rxq->bulk_mbuf_num = 0;
1999 : :
2000 : 0 : rte_spinlock_lock(&hw->lock);
2001 : 0 : dev->data->rx_queues[idx] = rxq;
2002 : : rte_spinlock_unlock(&hw->lock);
2003 : :
2004 : 0 : return 0;
2005 : : }
2006 : :
2007 : : void
2008 : 0 : hns3_rx_scattered_reset(struct rte_eth_dev *dev)
2009 : : {
2010 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
2011 : : struct hns3_hw *hw = &hns->hw;
2012 : :
2013 : 0 : hw->rx_buf_len = 0;
2014 : 0 : dev->data->scattered_rx = false;
2015 : 0 : }
2016 : :
2017 : : void
2018 : 0 : hns3_rx_scattered_calc(struct rte_eth_dev *dev)
2019 : : {
2020 : 0 : struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
2021 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
2022 : : struct hns3_hw *hw = &hns->hw;
2023 : : struct hns3_rx_queue *rxq;
2024 : : uint32_t queue_id;
2025 : :
2026 [ # # ]: 0 : if (dev->data->rx_queues == NULL)
2027 : : return;
2028 : :
2029 [ # # ]: 0 : for (queue_id = 0; queue_id < dev->data->nb_rx_queues; queue_id++) {
2030 : 0 : rxq = dev->data->rx_queues[queue_id];
2031 [ # # ]: 0 : if (hw->rx_buf_len == 0)
2032 : 0 : hw->rx_buf_len = rxq->rx_buf_len;
2033 : : else
2034 : 0 : hw->rx_buf_len = RTE_MIN(hw->rx_buf_len,
2035 : : rxq->rx_buf_len);
2036 : : }
2037 : :
2038 [ # # ]: 0 : if (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_SCATTER ||
2039 [ # # ]: 0 : dev->data->mtu + HNS3_ETH_OVERHEAD > hw->rx_buf_len)
2040 : 0 : dev->data->scattered_rx = true;
2041 : : }
2042 : :
2043 : : const uint32_t *
2044 : 0 : hns3_dev_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
2045 : : {
2046 : : static const uint32_t ptypes[] = {
2047 : : RTE_PTYPE_L2_ETHER,
2048 : : RTE_PTYPE_L2_ETHER_LLDP,
2049 : : RTE_PTYPE_L2_ETHER_ARP,
2050 : : RTE_PTYPE_L3_IPV4,
2051 : : RTE_PTYPE_L3_IPV4_EXT,
2052 : : RTE_PTYPE_L3_IPV6,
2053 : : RTE_PTYPE_L3_IPV6_EXT,
2054 : : RTE_PTYPE_L4_IGMP,
2055 : : RTE_PTYPE_L4_ICMP,
2056 : : RTE_PTYPE_L4_SCTP,
2057 : : RTE_PTYPE_L4_TCP,
2058 : : RTE_PTYPE_L4_UDP,
2059 : : RTE_PTYPE_TUNNEL_GRE,
2060 : : RTE_PTYPE_INNER_L2_ETHER,
2061 : : RTE_PTYPE_INNER_L3_IPV4,
2062 : : RTE_PTYPE_INNER_L3_IPV6,
2063 : : RTE_PTYPE_INNER_L3_IPV4_EXT,
2064 : : RTE_PTYPE_INNER_L3_IPV6_EXT,
2065 : : RTE_PTYPE_INNER_L4_UDP,
2066 : : RTE_PTYPE_INNER_L4_TCP,
2067 : : RTE_PTYPE_INNER_L4_SCTP,
2068 : : RTE_PTYPE_INNER_L4_ICMP,
2069 : : RTE_PTYPE_TUNNEL_GRENAT,
2070 : : RTE_PTYPE_TUNNEL_NVGRE,
2071 : : };
2072 : : static const uint32_t adv_layout_ptypes[] = {
2073 : : RTE_PTYPE_L2_ETHER,
2074 : : RTE_PTYPE_L2_ETHER_TIMESYNC,
2075 : : RTE_PTYPE_L2_ETHER_LLDP,
2076 : : RTE_PTYPE_L2_ETHER_ARP,
2077 : : RTE_PTYPE_L3_IPV4_EXT_UNKNOWN,
2078 : : RTE_PTYPE_L3_IPV6_EXT_UNKNOWN,
2079 : : RTE_PTYPE_L4_FRAG,
2080 : : RTE_PTYPE_L4_NONFRAG,
2081 : : RTE_PTYPE_L4_UDP,
2082 : : RTE_PTYPE_L4_TCP,
2083 : : RTE_PTYPE_L4_SCTP,
2084 : : RTE_PTYPE_L4_IGMP,
2085 : : RTE_PTYPE_L4_ICMP,
2086 : : RTE_PTYPE_TUNNEL_GRE,
2087 : : RTE_PTYPE_TUNNEL_GRENAT,
2088 : : RTE_PTYPE_INNER_L2_ETHER,
2089 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN,
2090 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN,
2091 : : RTE_PTYPE_INNER_L4_FRAG,
2092 : : RTE_PTYPE_INNER_L4_ICMP,
2093 : : RTE_PTYPE_INNER_L4_NONFRAG,
2094 : : RTE_PTYPE_INNER_L4_UDP,
2095 : : RTE_PTYPE_INNER_L4_TCP,
2096 : : RTE_PTYPE_INNER_L4_SCTP,
2097 : : RTE_PTYPE_INNER_L4_ICMP,
2098 : : };
2099 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2100 : :
2101 [ # # # # ]: 0 : if (dev->rx_pkt_burst == hns3_recv_pkts_simple ||
2102 [ # # ]: 0 : dev->rx_pkt_burst == hns3_recv_scattered_pkts ||
2103 [ # # ]: 0 : dev->rx_pkt_burst == hns3_recv_pkts_vec ||
2104 : : dev->rx_pkt_burst == hns3_recv_pkts_vec_sve) {
2105 [ # # ]: 0 : if (hns3_dev_get_support(hw, RXD_ADV_LAYOUT)) {
2106 : 0 : *no_of_elements = RTE_DIM(adv_layout_ptypes);
2107 : 0 : return adv_layout_ptypes;
2108 : : } else {
2109 : 0 : *no_of_elements = RTE_DIM(ptypes);
2110 : 0 : return ptypes;
2111 : : }
2112 : : }
2113 : :
2114 : : return NULL;
2115 : : }
2116 : :
2117 : : static void
2118 : : hns3_init_non_tunnel_ptype_tbl(struct hns3_ptype_table *tbl)
2119 : : {
2120 : 0 : tbl->l3table[0] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4;
2121 : 0 : tbl->l3table[1] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6;
2122 : 0 : tbl->l3table[2] = RTE_PTYPE_L2_ETHER_ARP;
2123 : 0 : tbl->l3table[4] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT;
2124 : 0 : tbl->l3table[5] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT;
2125 : 0 : tbl->l3table[6] = RTE_PTYPE_L2_ETHER_LLDP;
2126 : :
2127 : 0 : tbl->l4table[0] = RTE_PTYPE_L4_UDP;
2128 : 0 : tbl->l4table[1] = RTE_PTYPE_L4_TCP;
2129 : 0 : tbl->l4table[2] = RTE_PTYPE_TUNNEL_GRE;
2130 : 0 : tbl->l4table[3] = RTE_PTYPE_L4_SCTP;
2131 : 0 : tbl->l4table[4] = RTE_PTYPE_L4_IGMP;
2132 : 0 : tbl->l4table[5] = RTE_PTYPE_L4_ICMP;
2133 : : }
2134 : :
2135 : : static void
2136 : : hns3_init_tunnel_ptype_tbl(struct hns3_ptype_table *tbl)
2137 : : {
2138 : 0 : tbl->inner_l3table[0] = RTE_PTYPE_INNER_L2_ETHER |
2139 : : RTE_PTYPE_INNER_L3_IPV4;
2140 : 0 : tbl->inner_l3table[1] = RTE_PTYPE_INNER_L2_ETHER |
2141 : : RTE_PTYPE_INNER_L3_IPV6;
2142 : : /* There is not a ptype for inner ARP/RARP */
2143 : 0 : tbl->inner_l3table[2] = RTE_PTYPE_UNKNOWN;
2144 : 0 : tbl->inner_l3table[3] = RTE_PTYPE_UNKNOWN;
2145 : 0 : tbl->inner_l3table[4] = RTE_PTYPE_INNER_L2_ETHER |
2146 : : RTE_PTYPE_INNER_L3_IPV4_EXT;
2147 : 0 : tbl->inner_l3table[5] = RTE_PTYPE_INNER_L2_ETHER |
2148 : : RTE_PTYPE_INNER_L3_IPV6_EXT;
2149 : :
2150 : 0 : tbl->inner_l4table[0] = RTE_PTYPE_INNER_L4_UDP;
2151 : 0 : tbl->inner_l4table[1] = RTE_PTYPE_INNER_L4_TCP;
2152 : : /* There is not a ptype for inner GRE */
2153 : 0 : tbl->inner_l4table[2] = RTE_PTYPE_UNKNOWN;
2154 : 0 : tbl->inner_l4table[3] = RTE_PTYPE_INNER_L4_SCTP;
2155 : : /* There is not a ptype for inner IGMP */
2156 : 0 : tbl->inner_l4table[4] = RTE_PTYPE_UNKNOWN;
2157 : 0 : tbl->inner_l4table[5] = RTE_PTYPE_INNER_L4_ICMP;
2158 : :
2159 : 0 : tbl->ol3table[0] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4;
2160 : 0 : tbl->ol3table[1] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6;
2161 : 0 : tbl->ol3table[2] = RTE_PTYPE_UNKNOWN;
2162 : 0 : tbl->ol3table[3] = RTE_PTYPE_UNKNOWN;
2163 : 0 : tbl->ol3table[4] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT;
2164 : 0 : tbl->ol3table[5] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT;
2165 : :
2166 : 0 : tbl->ol4table[0] = RTE_PTYPE_UNKNOWN;
2167 : 0 : tbl->ol4table[1] = RTE_PTYPE_L4_UDP | RTE_PTYPE_TUNNEL_GRENAT;
2168 : 0 : tbl->ol4table[2] = RTE_PTYPE_TUNNEL_NVGRE;
2169 : : }
2170 : :
2171 : : static void
2172 : 0 : hns3_init_adv_layout_ptype(struct hns3_ptype_table *tbl)
2173 : : {
2174 : : uint32_t *ptype = tbl->ptype;
2175 : :
2176 : : /* Non-tunnel L2 */
2177 : 0 : ptype[1] = RTE_PTYPE_L2_ETHER_ARP;
2178 : 0 : ptype[3] = RTE_PTYPE_L2_ETHER_LLDP;
2179 : 0 : ptype[8] = RTE_PTYPE_L2_ETHER_TIMESYNC;
2180 : :
2181 : : /* Non-tunnel IPv4 */
2182 : 0 : ptype[17] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2183 : : RTE_PTYPE_L4_FRAG;
2184 : 0 : ptype[18] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2185 : : RTE_PTYPE_L4_NONFRAG;
2186 : 0 : ptype[19] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2187 : : RTE_PTYPE_L4_UDP;
2188 : 0 : ptype[20] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2189 : : RTE_PTYPE_L4_TCP;
2190 : 0 : ptype[21] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2191 : : RTE_PTYPE_TUNNEL_GRE;
2192 : 0 : ptype[22] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2193 : : RTE_PTYPE_L4_SCTP;
2194 : 0 : ptype[23] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2195 : : RTE_PTYPE_L4_IGMP;
2196 : 0 : ptype[24] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2197 : : RTE_PTYPE_L4_ICMP;
2198 : : /* The next ptype is PTP over IPv4 + UDP */
2199 : 0 : ptype[25] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2200 : : RTE_PTYPE_L4_UDP;
2201 : :
2202 : : /* IPv4 --> GRE/Teredo/VXLAN */
2203 : 0 : ptype[29] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2204 : : RTE_PTYPE_TUNNEL_GRENAT;
2205 : : /* IPv4 --> GRE/Teredo/VXLAN --> MAC */
2206 : 0 : ptype[30] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2207 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER;
2208 : :
2209 : : /* IPv4 --> GRE/Teredo/VXLAN --> MAC --> IPv4 */
2210 : 0 : ptype[31] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2211 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2212 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2213 : : RTE_PTYPE_INNER_L4_FRAG;
2214 : 0 : ptype[32] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2215 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2216 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2217 : : RTE_PTYPE_INNER_L4_NONFRAG;
2218 : 0 : ptype[33] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2219 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2220 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2221 : : RTE_PTYPE_INNER_L4_UDP;
2222 : 0 : ptype[34] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2223 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2224 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2225 : : RTE_PTYPE_INNER_L4_TCP;
2226 : 0 : ptype[35] = 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_SCTP;
2230 : : /* The next ptype's inner L4 is IGMP */
2231 : 0 : ptype[36] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2232 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2233 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
2234 : 0 : ptype[37] = 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_ICMP;
2238 : :
2239 : : /* IPv4 --> GRE/Teredo/VXLAN --> MAC --> IPv6 */
2240 : 0 : ptype[39] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2241 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2242 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2243 : : RTE_PTYPE_INNER_L4_FRAG;
2244 : 0 : ptype[40] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2245 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2246 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2247 : : RTE_PTYPE_INNER_L4_NONFRAG;
2248 : 0 : ptype[41] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2249 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2250 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2251 : : RTE_PTYPE_INNER_L4_UDP;
2252 : 0 : ptype[42] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2253 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2254 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2255 : : RTE_PTYPE_INNER_L4_TCP;
2256 : 0 : ptype[43] = 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_SCTP;
2260 : : /* The next ptype's inner L4 is IGMP */
2261 : 0 : ptype[44] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4_EXT_UNKNOWN |
2262 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2263 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
2264 : 0 : ptype[45] = 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_ICMP;
2268 : :
2269 : : /* Non-tunnel IPv6 */
2270 : 0 : ptype[111] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2271 : : RTE_PTYPE_L4_FRAG;
2272 : 0 : ptype[112] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2273 : : RTE_PTYPE_L4_NONFRAG;
2274 : 0 : ptype[113] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2275 : : RTE_PTYPE_L4_UDP;
2276 : 0 : ptype[114] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2277 : : RTE_PTYPE_L4_TCP;
2278 : 0 : ptype[115] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2279 : : RTE_PTYPE_TUNNEL_GRE;
2280 : 0 : ptype[116] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2281 : : RTE_PTYPE_L4_SCTP;
2282 : 0 : ptype[117] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2283 : : RTE_PTYPE_L4_IGMP;
2284 : 0 : ptype[118] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2285 : : RTE_PTYPE_L4_ICMP;
2286 : : /* Special for PTP over IPv6 + UDP */
2287 : 0 : ptype[119] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2288 : : RTE_PTYPE_L4_UDP;
2289 : :
2290 : : /* IPv6 --> GRE/Teredo/VXLAN */
2291 : 0 : ptype[123] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2292 : : RTE_PTYPE_TUNNEL_GRENAT;
2293 : : /* IPv6 --> GRE/Teredo/VXLAN --> MAC */
2294 : 0 : ptype[124] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2295 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER;
2296 : :
2297 : : /* IPv6 --> GRE/Teredo/VXLAN --> MAC --> IPv4 */
2298 : 0 : ptype[125] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2299 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2300 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2301 : : RTE_PTYPE_INNER_L4_FRAG;
2302 : 0 : ptype[126] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2303 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2304 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2305 : : RTE_PTYPE_INNER_L4_NONFRAG;
2306 : 0 : ptype[127] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2307 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2308 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2309 : : RTE_PTYPE_INNER_L4_UDP;
2310 : 0 : ptype[128] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2311 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2312 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN |
2313 : : RTE_PTYPE_INNER_L4_TCP;
2314 : 0 : ptype[129] = 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_SCTP;
2318 : : /* The next ptype's inner L4 is IGMP */
2319 : 0 : ptype[130] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2320 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2321 : : RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
2322 : 0 : ptype[131] = 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_ICMP;
2326 : :
2327 : : /* IPv6 --> GRE/Teredo/VXLAN --> MAC --> IPv6 */
2328 : 0 : ptype[133] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2329 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2330 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2331 : : RTE_PTYPE_INNER_L4_FRAG;
2332 : 0 : ptype[134] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2333 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2334 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2335 : : RTE_PTYPE_INNER_L4_NONFRAG;
2336 : 0 : ptype[135] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2337 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2338 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2339 : : RTE_PTYPE_INNER_L4_UDP;
2340 : 0 : ptype[136] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2341 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2342 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN |
2343 : : RTE_PTYPE_INNER_L4_TCP;
2344 : 0 : ptype[137] = 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_SCTP;
2348 : : /* The next ptype's inner L4 is IGMP */
2349 : 0 : ptype[138] = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV6_EXT_UNKNOWN |
2350 : : RTE_PTYPE_TUNNEL_GRENAT | RTE_PTYPE_INNER_L2_ETHER |
2351 : : RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
2352 : 0 : ptype[139] = 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_ICMP;
2356 : 0 : }
2357 : :
2358 : : void
2359 : 0 : hns3_init_rx_ptype_tble(struct rte_eth_dev *dev)
2360 : : {
2361 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
2362 : 0 : struct hns3_ptype_table *tbl = &hns->ptype_tbl;
2363 : :
2364 : : memset(tbl, 0, sizeof(*tbl));
2365 : :
2366 : : hns3_init_non_tunnel_ptype_tbl(tbl);
2367 : : hns3_init_tunnel_ptype_tbl(tbl);
2368 : 0 : hns3_init_adv_layout_ptype(tbl);
2369 : 0 : }
2370 : :
2371 : : static inline void
2372 : 0 : hns3_rxd_to_vlan_tci(struct hns3_rx_queue *rxq, struct rte_mbuf *mb,
2373 : : uint32_t l234_info, const struct hns3_desc *rxd)
2374 : : {
2375 : : #define HNS3_STRP_STATUS_NUM 0x4
2376 : :
2377 : : #define HNS3_NO_STRP_VLAN_VLD 0x0
2378 : : #define HNS3_INNER_STRP_VLAN_VLD 0x1
2379 : : #define HNS3_OUTER_STRP_VLAN_VLD 0x2
2380 : : uint32_t strip_status;
2381 : : uint32_t report_mode;
2382 : :
2383 : : /*
2384 : : * Since HW limitation, the vlan tag will always be inserted into RX
2385 : : * descriptor when strip the tag from packet, driver needs to determine
2386 : : * reporting which tag to mbuf according to the PVID configuration
2387 : : * and vlan striped status.
2388 : : */
2389 : : static const uint32_t report_type[][HNS3_STRP_STATUS_NUM] = {
2390 : : {
2391 : : HNS3_NO_STRP_VLAN_VLD,
2392 : : HNS3_OUTER_STRP_VLAN_VLD,
2393 : : HNS3_INNER_STRP_VLAN_VLD,
2394 : : HNS3_OUTER_STRP_VLAN_VLD
2395 : : },
2396 : : {
2397 : : HNS3_NO_STRP_VLAN_VLD,
2398 : : HNS3_NO_STRP_VLAN_VLD,
2399 : : HNS3_NO_STRP_VLAN_VLD,
2400 : : HNS3_INNER_STRP_VLAN_VLD
2401 : : }
2402 : : };
2403 : 0 : strip_status = hns3_get_field(l234_info, HNS3_RXD_STRP_TAGP_M,
2404 : : HNS3_RXD_STRP_TAGP_S);
2405 : 0 : report_mode = report_type[rxq->pvid_sw_discard_en][strip_status];
2406 [ # # # # ]: 0 : switch (report_mode) {
2407 : 0 : case HNS3_NO_STRP_VLAN_VLD:
2408 : 0 : mb->vlan_tci = 0;
2409 : 0 : return;
2410 : 0 : case HNS3_INNER_STRP_VLAN_VLD:
2411 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
2412 : 0 : mb->vlan_tci = rte_le_to_cpu_16(rxd->rx.vlan_tag);
2413 : 0 : return;
2414 : 0 : case HNS3_OUTER_STRP_VLAN_VLD:
2415 : 0 : mb->ol_flags |= RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED;
2416 : 0 : mb->vlan_tci = rte_le_to_cpu_16(rxd->rx.ot_vlan_tag);
2417 : 0 : return;
2418 : 0 : default:
2419 : 0 : mb->vlan_tci = 0;
2420 : 0 : return;
2421 : : }
2422 : : }
2423 : :
2424 : : static inline void
2425 : : recalculate_data_len(struct rte_mbuf *last_seg, struct rte_mbuf *rxm,
2426 : : struct hns3_rx_queue *rxq)
2427 : : {
2428 : 0 : uint16_t data_len = rxm->data_len;
2429 : : uint8_t crc_len = rxq->crc_len;
2430 : :
2431 : 0 : if (data_len <= crc_len) {
2432 : 0 : rxm->data_len = 0;
2433 : 0 : last_seg->data_len = (uint16_t)(last_seg->data_len -
2434 : : (crc_len - data_len));
2435 : : } else
2436 : 0 : rxm->data_len = (uint16_t)(data_len - crc_len);
2437 : : }
2438 : :
2439 : : static inline struct rte_mbuf *
2440 : 0 : hns3_rx_alloc_buffer(struct hns3_rx_queue *rxq)
2441 : : {
2442 : : int ret;
2443 : :
2444 [ # # ]: 0 : if (likely(rxq->bulk_mbuf_num > 0))
2445 : 0 : return rxq->bulk_mbuf[--rxq->bulk_mbuf_num];
2446 : :
2447 [ # # ]: 0 : ret = rte_mempool_get_bulk(rxq->mb_pool, (void **)rxq->bulk_mbuf,
2448 : : HNS3_BULK_ALLOC_MBUF_NUM);
2449 [ # # ]: 0 : if (likely(ret == 0)) {
2450 : : rxq->bulk_mbuf_num = HNS3_BULK_ALLOC_MBUF_NUM;
2451 : 0 : return rxq->bulk_mbuf[--rxq->bulk_mbuf_num];
2452 : : } else
2453 : 0 : return rte_mbuf_raw_alloc(rxq->mb_pool);
2454 : : }
2455 : :
2456 : : static void
2457 : : hns3_rx_ptp_timestamp_handle(struct hns3_rx_queue *rxq, struct rte_mbuf *mbuf,
2458 : : uint64_t timestamp)
2459 : : {
2460 : 0 : struct hns3_pf *pf = HNS3_DEV_PRIVATE_TO_PF(rxq->hns);
2461 : :
2462 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_IEEE1588_TMST;
2463 [ # # ]: 0 : if (hns3_timestamp_rx_dynflag > 0) {
2464 : 0 : *RTE_MBUF_DYNFIELD(mbuf, hns3_timestamp_dynfield_offset,
2465 : 0 : rte_mbuf_timestamp_t *) = timestamp;
2466 : 0 : mbuf->ol_flags |= hns3_timestamp_rx_dynflag;
2467 : : }
2468 : :
2469 : 0 : pf->rx_timestamp = timestamp;
2470 : 0 : }
2471 : :
2472 : : static inline bool
2473 : : hns3_need_recalculate_crc(struct hns3_rx_queue *rxq, struct rte_mbuf *m)
2474 : : {
2475 : : uint32_t ptype = m->packet_type;
2476 : :
2477 [ # # # # ]: 0 : if (rxq->keep_crc_fail_ptype == HNS3_STRIP_CRC_PTYPE_NONE)
2478 : : return false;
2479 : :
2480 [ # # # # ]: 0 : if (m->pkt_len > HNS3_KEEP_CRC_OK_MIN_PKT_LEN)
2481 : : return false;
2482 : :
2483 [ # # # # ]: 0 : if (!(RTE_ETH_IS_IPV4_HDR(ptype) || RTE_ETH_IS_IPV6_HDR(ptype)))
2484 : : return false;
2485 : :
2486 [ # # # # ]: 0 : if (rxq->keep_crc_fail_ptype == HNS3_STRIP_CRC_PTYPE_TCP)
2487 : 0 : return (ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP;
2488 : :
2489 : : return true;
2490 : : }
2491 : :
2492 : : /*
2493 : : * The hns3 driver requires that mbuf size must be at least 512B.
2494 : : * When CRC is stripped by hardware, the pkt_len must be less than
2495 : : * or equal to 60B. Therefore, the space of the mbuf is enough
2496 : : * to insert the CRC.
2497 : : */
2498 : : static_assert(HNS3_KEEP_CRC_OK_MIN_PKT_LEN < HNS3_MIN_BD_BUF_SIZE,
2499 : : "buffer size too small to insert CRC");
2500 : :
2501 : : static inline void
2502 : 0 : hns3_recalculate_crc(struct hns3_rx_queue *rxq, struct rte_mbuf *m)
2503 : : {
2504 : : char *append_data;
2505 : : uint32_t crc;
2506 : :
2507 : 0 : crc = rte_net_crc_calc(rxq->crc_ctx, rte_pktmbuf_mtod(m, void *), m->data_len);
2508 : :
2509 : : /*
2510 : : * After CRC is stripped by hardware, pkt_len and data_len do not
2511 : : * contain the CRC length. Therefore, after CRC data is appended
2512 : : * by PMD again.
2513 : : */
2514 : : append_data = rte_pktmbuf_append(m, RTE_ETHER_CRC_LEN);
2515 : :
2516 : : /* CRC data is binary data and does not care about the byte order. */
2517 : : memcpy(append_data, &crc, RTE_ETHER_CRC_LEN);
2518 : 0 : }
2519 : :
2520 : : uint16_t
2521 : 0 : hns3_recv_pkts_simple(void *rx_queue,
2522 : : struct rte_mbuf **rx_pkts,
2523 : : uint16_t nb_pkts)
2524 : 0 : {
2525 : : volatile struct hns3_desc *rx_ring; /* RX ring (desc) */
2526 : : volatile struct hns3_desc *rxdp; /* pointer of the current desc */
2527 : : struct hns3_rx_queue *rxq; /* RX queue */
2528 : : struct hns3_entry *sw_ring;
2529 : : struct hns3_entry *rxe;
2530 : : struct hns3_desc rxd;
2531 : : struct rte_mbuf *nmb; /* pointer of the new mbuf */
2532 : : struct rte_mbuf *rxm;
2533 : : uint32_t bd_base_info;
2534 : : uint32_t l234_info;
2535 : : uint32_t ol_info;
2536 : : uint64_t dma_addr;
2537 : : uint16_t nb_rx_bd;
2538 : : uint16_t nb_rx;
2539 : : uint16_t rx_id;
2540 : : int ret;
2541 : :
2542 : : nb_rx = 0;
2543 : : nb_rx_bd = 0;
2544 : : rxq = rx_queue;
2545 : 0 : rx_ring = rxq->rx_ring;
2546 : 0 : sw_ring = rxq->sw_ring;
2547 : 0 : rx_id = rxq->next_to_use;
2548 : :
2549 [ # # ]: 0 : while (nb_rx < nb_pkts) {
2550 : 0 : rxdp = &rx_ring[rx_id];
2551 : 0 : bd_base_info = rte_le_to_cpu_32(rxdp->rx.bd_base_info);
2552 [ # # ]: 0 : if (unlikely(!(bd_base_info & BIT(HNS3_RXD_VLD_B))))
2553 : : break;
2554 : :
2555 : 0 : rxd = rxdp[(bd_base_info & (1u << HNS3_RXD_VLD_B)) -
2556 : : (1u << HNS3_RXD_VLD_B)];
2557 : :
2558 : 0 : nmb = hns3_rx_alloc_buffer(rxq);
2559 [ # # ]: 0 : if (unlikely(nmb == NULL)) {
2560 : 0 : rte_eth_devices[rxq->port_id].data->
2561 : 0 : rx_mbuf_alloc_failed++;
2562 : 0 : break;
2563 : : }
2564 : :
2565 : 0 : nb_rx_bd++;
2566 : 0 : rxe = &sw_ring[rx_id];
2567 : 0 : rx_id++;
2568 [ # # ]: 0 : if (unlikely(rx_id == rxq->nb_rx_desc))
2569 : : rx_id = 0;
2570 : :
2571 : 0 : rte_prefetch0(sw_ring[rx_id].mbuf);
2572 [ # # ]: 0 : if ((rx_id & HNS3_RX_RING_PREFETCTH_MASK) == 0) {
2573 : 0 : rte_prefetch0(&rx_ring[rx_id]);
2574 : : rte_prefetch0(&sw_ring[rx_id]);
2575 : : }
2576 : :
2577 : 0 : rxm = rxe->mbuf;
2578 : 0 : rxm->ol_flags = 0;
2579 : 0 : rxe->mbuf = nmb;
2580 : :
2581 [ # # ]: 0 : if (unlikely(bd_base_info & BIT(HNS3_RXD_TS_VLD_B)))
2582 : : hns3_rx_ptp_timestamp_handle(rxq, rxm,
2583 [ # # ]: 0 : rte_le_to_cpu_64(rxdp->timestamp));
2584 : :
2585 : : dma_addr = rte_mbuf_data_iova_default(nmb);
2586 : 0 : rxdp->addr = rte_cpu_to_le_64(dma_addr);
2587 : 0 : rxdp->rx.bd_base_info = 0;
2588 : :
2589 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
2590 : 0 : rxm->pkt_len = (uint16_t)(rte_le_to_cpu_16(rxd.rx.pkt_len));
2591 : 0 : rxm->data_len = rxm->pkt_len;
2592 : 0 : rxm->port = rxq->port_id;
2593 : 0 : rxm->hash.rss = rte_le_to_cpu_32(rxd.rx.rss_hash);
2594 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
2595 [ # # ]: 0 : if (unlikely(bd_base_info & BIT(HNS3_RXD_LUM_B))) {
2596 : 0 : rxm->hash.fdir.hi =
2597 : 0 : rte_le_to_cpu_16(rxd.rx.fd_id);
2598 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
2599 : : }
2600 : 0 : rxm->nb_segs = 1;
2601 : 0 : rxm->next = NULL;
2602 : :
2603 : : /* Load remained descriptor data and extract necessary fields */
2604 : 0 : l234_info = rte_le_to_cpu_32(rxd.rx.l234_info);
2605 : 0 : ol_info = rte_le_to_cpu_32(rxd.rx.ol_info);
2606 : 0 : ret = hns3_handle_bdinfo(rxq, rxm, bd_base_info, l234_info);
2607 [ # # ]: 0 : if (unlikely(ret))
2608 : 0 : goto pkt_err;
2609 : :
2610 : 0 : rxm->packet_type = hns3_rx_calc_ptype(rxq, l234_info, ol_info);
2611 : :
2612 [ # # ]: 0 : if (rxm->packet_type == RTE_PTYPE_L2_ETHER_TIMESYNC)
2613 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_IEEE1588_PTP;
2614 : :
2615 [ # # # # ]: 0 : if (unlikely(rxq->crc_len > 0) &&
2616 : : hns3_need_recalculate_crc(rxq, rxm))
2617 : 0 : hns3_recalculate_crc(rxq, rxm);
2618 : 0 : rxm->pkt_len -= rxq->crc_len;
2619 : 0 : rxm->data_len -= rxq->crc_len;
2620 : :
2621 : 0 : hns3_rxd_to_vlan_tci(rxq, rxm, l234_info, &rxd);
2622 : :
2623 : : /* Increment bytes counter */
2624 : 0 : rxq->basic_stats.bytes += rxm->pkt_len;
2625 : :
2626 : 0 : rx_pkts[nb_rx++] = rxm;
2627 : 0 : continue;
2628 : : pkt_err:
2629 : 0 : rte_pktmbuf_free(rxm);
2630 : : }
2631 : :
2632 : 0 : rxq->next_to_use = rx_id;
2633 : 0 : rxq->rx_free_hold += nb_rx_bd;
2634 [ # # ]: 0 : if (rxq->rx_free_hold > rxq->rx_free_thresh) {
2635 : 0 : hns3_write_reg_opt(rxq->io_head_reg, rxq->rx_free_hold);
2636 : 0 : rxq->rx_free_hold = 0;
2637 : : }
2638 : :
2639 : 0 : return nb_rx;
2640 : : }
2641 : :
2642 : : uint16_t
2643 : 0 : hns3_recv_scattered_pkts(void *rx_queue,
2644 : : struct rte_mbuf **rx_pkts,
2645 : : uint16_t nb_pkts)
2646 : 0 : {
2647 : : volatile struct hns3_desc *rx_ring; /* RX ring (desc) */
2648 : : volatile struct hns3_desc *rxdp; /* pointer of the current desc */
2649 : : struct hns3_rx_queue *rxq; /* RX queue */
2650 : : struct hns3_entry *sw_ring;
2651 : : struct hns3_entry *rxe;
2652 : : struct rte_mbuf *first_seg;
2653 : : struct rte_mbuf *last_seg;
2654 : : struct hns3_desc rxd;
2655 : : struct rte_mbuf *nmb; /* pointer of the new mbuf */
2656 : : struct rte_mbuf *rxm;
2657 : : struct rte_eth_dev *dev;
2658 : : uint32_t bd_base_info;
2659 : : uint64_t timestamp;
2660 : : uint32_t l234_info;
2661 : : uint32_t gro_size;
2662 : : uint32_t ol_info;
2663 : : uint64_t dma_addr;
2664 : : uint16_t nb_rx_bd;
2665 : : uint16_t nb_rx;
2666 : : uint16_t rx_id;
2667 : : int ret;
2668 : :
2669 : : nb_rx = 0;
2670 : : nb_rx_bd = 0;
2671 : : rxq = rx_queue;
2672 : :
2673 : 0 : rx_id = rxq->next_to_use;
2674 : 0 : rx_ring = rxq->rx_ring;
2675 : 0 : sw_ring = rxq->sw_ring;
2676 : 0 : first_seg = rxq->pkt_first_seg;
2677 : 0 : last_seg = rxq->pkt_last_seg;
2678 : :
2679 [ # # ]: 0 : while (nb_rx < nb_pkts) {
2680 : 0 : rxdp = &rx_ring[rx_id];
2681 : 0 : bd_base_info = rte_le_to_cpu_32(rxdp->rx.bd_base_info);
2682 [ # # ]: 0 : if (unlikely(!(bd_base_info & BIT(HNS3_RXD_VLD_B))))
2683 : : break;
2684 : :
2685 : : /*
2686 : : * The interactive process between software and hardware of
2687 : : * receiving a new packet in hns3 network engine:
2688 : : * 1. Hardware network engine firstly writes the packet content
2689 : : * to the memory pointed by the 'addr' field of the Rx Buffer
2690 : : * Descriptor, secondly fills the result of parsing the
2691 : : * packet include the valid field into the Rx Buffer
2692 : : * Descriptor in one write operation.
2693 : : * 2. Driver reads the Rx BD's valid field in the loop to check
2694 : : * whether it's valid, if valid then assign a new address to
2695 : : * the addr field, clear the valid field, get the other
2696 : : * information of the packet by parsing Rx BD's other fields,
2697 : : * finally write back the number of Rx BDs processed by the
2698 : : * driver to the HNS3_RING_RX_HEAD_REG register to inform
2699 : : * hardware.
2700 : : * In the above process, the ordering is very important. We must
2701 : : * make sure that CPU read Rx BD's other fields only after the
2702 : : * Rx BD is valid.
2703 : : *
2704 : : * There are two type of re-ordering: compiler re-ordering and
2705 : : * CPU re-ordering under the ARMv8 architecture.
2706 : : * 1. we use volatile to deal with compiler re-ordering, so you
2707 : : * can see that rx_ring/rxdp defined with volatile.
2708 : : * 2. we commonly use memory barrier to deal with CPU
2709 : : * re-ordering, but the cost is high.
2710 : : *
2711 : : * In order to solve the high cost of using memory barrier, we
2712 : : * use the data dependency order under the ARMv8 architecture,
2713 : : * for example:
2714 : : * instr01: load A
2715 : : * instr02: load B <- A
2716 : : * the instr02 will always execute after instr01.
2717 : : *
2718 : : * To construct the data dependency ordering, we use the
2719 : : * following assignment:
2720 : : * rxd = rxdp[(bd_base_info & (1u << HNS3_RXD_VLD_B)) -
2721 : : * (1u<<HNS3_RXD_VLD_B)]
2722 : : * Using gcc compiler under the ARMv8 architecture, the related
2723 : : * assembly code example as follows:
2724 : : * note: (1u << HNS3_RXD_VLD_B) equal 0x10
2725 : : * instr01: ldr w26, [x22, #28] --read bd_base_info
2726 : : * instr02: and w0, w26, #0x10 --calc bd_base_info & 0x10
2727 : : * instr03: sub w0, w0, #0x10 --calc (bd_base_info &
2728 : : * 0x10) - 0x10
2729 : : * instr04: add x0, x22, x0, lsl #5 --calc copy source addr
2730 : : * instr05: ldp x2, x3, [x0]
2731 : : * instr06: stp x2, x3, [x29, #256] --copy BD's [0 ~ 15]B
2732 : : * instr07: ldp x4, x5, [x0, #16]
2733 : : * instr08: stp x4, x5, [x29, #272] --copy BD's [16 ~ 31]B
2734 : : * the instr05~08 depend on x0's value, x0 depent on w26's
2735 : : * value, the w26 is the bd_base_info, this form the data
2736 : : * dependency ordering.
2737 : : * note: if BD is valid, (bd_base_info & (1u<<HNS3_RXD_VLD_B)) -
2738 : : * (1u<<HNS3_RXD_VLD_B) will always zero, so the
2739 : : * assignment is correct.
2740 : : *
2741 : : * So we use the data dependency ordering instead of memory
2742 : : * barrier to improve receive performance.
2743 : : */
2744 : 0 : rxd = rxdp[(bd_base_info & (1u << HNS3_RXD_VLD_B)) -
2745 : : (1u << HNS3_RXD_VLD_B)];
2746 : : RX_BD_LOG(&rxq->hns->hw, DEBUG, &rxd);
2747 : :
2748 : 0 : nmb = hns3_rx_alloc_buffer(rxq);
2749 [ # # ]: 0 : if (unlikely(nmb == NULL)) {
2750 : 0 : dev = &rte_eth_devices[rxq->port_id];
2751 : 0 : dev->data->rx_mbuf_alloc_failed++;
2752 : 0 : break;
2753 : : }
2754 : :
2755 : 0 : nb_rx_bd++;
2756 : 0 : rxe = &sw_ring[rx_id];
2757 : 0 : rx_id++;
2758 [ # # ]: 0 : if (unlikely(rx_id == rxq->nb_rx_desc))
2759 : : rx_id = 0;
2760 : :
2761 : 0 : rte_prefetch0(sw_ring[rx_id].mbuf);
2762 [ # # ]: 0 : if ((rx_id & HNS3_RX_RING_PREFETCTH_MASK) == 0) {
2763 : 0 : rte_prefetch0(&rx_ring[rx_id]);
2764 : : rte_prefetch0(&sw_ring[rx_id]);
2765 : : }
2766 : :
2767 : 0 : rxm = rxe->mbuf;
2768 : 0 : rxe->mbuf = nmb;
2769 : :
2770 [ # # ]: 0 : if (unlikely(bd_base_info & BIT(HNS3_RXD_TS_VLD_B)))
2771 : 0 : timestamp = rte_le_to_cpu_64(rxdp->timestamp);
2772 : :
2773 : : dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(nmb));
2774 : 0 : rxdp->rx.bd_base_info = 0;
2775 : 0 : rxdp->addr = dma_addr;
2776 : :
2777 [ # # ]: 0 : if (first_seg == NULL) {
2778 : : first_seg = rxm;
2779 : 0 : first_seg->nb_segs = 1;
2780 : : } else {
2781 : 0 : first_seg->nb_segs++;
2782 : 0 : last_seg->next = rxm;
2783 : : }
2784 : :
2785 : 0 : rxm->data_off = RTE_PKTMBUF_HEADROOM;
2786 : 0 : rxm->data_len = rte_le_to_cpu_16(rxd.rx.size);
2787 : 0 : rxm->next = NULL;
2788 : :
2789 [ # # ]: 0 : if (!(bd_base_info & BIT(HNS3_RXD_FE_B))) {
2790 : : last_seg = rxm;
2791 : 0 : continue;
2792 : : }
2793 : :
2794 : 0 : first_seg->ol_flags = 0;
2795 [ # # ]: 0 : if (unlikely(bd_base_info & BIT(HNS3_RXD_TS_VLD_B)))
2796 : : hns3_rx_ptp_timestamp_handle(rxq, first_seg, timestamp);
2797 : :
2798 : : /*
2799 : : * The last buffer of the received packet. packet len from
2800 : : * buffer description may contains CRC len, packet len should
2801 : : * subtract it, same as data len.
2802 : : */
2803 : 0 : first_seg->pkt_len = rte_le_to_cpu_16(rxd.rx.pkt_len);
2804 : :
2805 : 0 : first_seg->port = rxq->port_id;
2806 : 0 : first_seg->hash.rss = rte_le_to_cpu_32(rxd.rx.rss_hash);
2807 : 0 : first_seg->ol_flags |= RTE_MBUF_F_RX_RSS_HASH;
2808 [ # # ]: 0 : if (unlikely(bd_base_info & BIT(HNS3_RXD_LUM_B))) {
2809 : 0 : first_seg->hash.fdir.hi =
2810 : 0 : rte_le_to_cpu_16(rxd.rx.fd_id);
2811 : 0 : first_seg->ol_flags |= RTE_MBUF_F_RX_FDIR | RTE_MBUF_F_RX_FDIR_ID;
2812 : : }
2813 : :
2814 : 0 : gro_size = hns3_get_field(bd_base_info, HNS3_RXD_GRO_SIZE_M,
2815 : : HNS3_RXD_GRO_SIZE_S);
2816 [ # # ]: 0 : if (gro_size != 0) {
2817 : 0 : first_seg->ol_flags |= RTE_MBUF_F_RX_LRO;
2818 : 0 : first_seg->tso_segsz = gro_size;
2819 : : }
2820 : :
2821 : 0 : l234_info = rte_le_to_cpu_32(rxd.rx.l234_info);
2822 : 0 : ol_info = rte_le_to_cpu_32(rxd.rx.ol_info);
2823 : 0 : ret = hns3_handle_bdinfo(rxq, first_seg, bd_base_info,
2824 : : l234_info);
2825 [ # # ]: 0 : if (unlikely(ret))
2826 : 0 : goto pkt_err;
2827 : :
2828 : 0 : first_seg->packet_type = hns3_rx_calc_ptype(rxq,
2829 : : l234_info, ol_info);
2830 : :
2831 [ # # ]: 0 : if (first_seg->packet_type == RTE_PTYPE_L2_ETHER_TIMESYNC)
2832 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_IEEE1588_PTP;
2833 : : /*
2834 : : * This is the last buffer of the received packet. If the CRC
2835 : : * is not stripped by the hardware:
2836 : : * - Subtract the CRC length from the total packet length.
2837 : : * - If the last buffer only contains the whole CRC or a part
2838 : : * of it, free the mbuf associated to the last buffer. If part
2839 : : * of the CRC is also contained in the previous mbuf, subtract
2840 : : * the length of that CRC part from the data length of the
2841 : : * previous mbuf.
2842 : : *
2843 : : * In addition, the CRC is still stripped for a kind of packets
2844 : : * in hns3 NIC:
2845 : : * 1. All IP-TCP packet whose the length is less than and equal
2846 : : * to 60 Byte (no CRC) on HIP08 network engine.
2847 : : * 2. All IP packet whose the length is less than and equal to
2848 : : * 60 Byte (no CRC) on HIP09 network engine.
2849 : : * In this case, the PMD calculates the CRC and appends it to
2850 : : * mbuf.
2851 : : */
2852 [ # # ]: 0 : if (unlikely(rxq->crc_len > 0)) {
2853 [ # # ]: 0 : if (hns3_need_recalculate_crc(rxq, first_seg))
2854 : 0 : hns3_recalculate_crc(rxq, first_seg);
2855 [ # # ]: 0 : first_seg->pkt_len -= rxq->crc_len;
2856 : : recalculate_data_len(last_seg, rxm, rxq);
2857 : : }
2858 : :
2859 : 0 : hns3_rxd_to_vlan_tci(rxq, first_seg, l234_info, &rxd);
2860 : :
2861 : : /* Increment bytes counter */
2862 : 0 : rxq->basic_stats.bytes += first_seg->pkt_len;
2863 : :
2864 : 0 : rx_pkts[nb_rx++] = first_seg;
2865 : : first_seg = NULL;
2866 : 0 : continue;
2867 : : pkt_err:
2868 : 0 : rte_pktmbuf_free(first_seg);
2869 : : first_seg = NULL;
2870 : : }
2871 : :
2872 : 0 : rxq->next_to_use = rx_id;
2873 : 0 : rxq->pkt_first_seg = first_seg;
2874 : 0 : rxq->pkt_last_seg = last_seg;
2875 : :
2876 : 0 : rxq->rx_free_hold += nb_rx_bd;
2877 [ # # ]: 0 : if (rxq->rx_free_hold > rxq->rx_free_thresh) {
2878 : 0 : hns3_write_reg_opt(rxq->io_head_reg, rxq->rx_free_hold);
2879 : 0 : rxq->rx_free_hold = 0;
2880 : : }
2881 : :
2882 : 0 : return nb_rx;
2883 : : }
2884 : :
2885 : : #ifndef RTE_ARCH_ARM64
2886 : : void
2887 : 0 : hns3_rxq_vec_setup(__rte_unused struct hns3_rx_queue *rxq)
2888 : : {
2889 : 0 : }
2890 : :
2891 : : int
2892 : 0 : hns3_rx_check_vec_support(__rte_unused struct rte_eth_dev *dev)
2893 : : {
2894 : 0 : return -ENOTSUP;
2895 : : }
2896 : :
2897 : : uint16_t
2898 : 0 : hns3_recv_pkts_vec(__rte_unused void *rx_queue,
2899 : : __rte_unused struct rte_mbuf **rx_pkts,
2900 : : __rte_unused uint16_t nb_pkts)
2901 : : {
2902 : 0 : return 0;
2903 : : }
2904 : : #endif /* RTE_ARCH_ARM64 */
2905 : :
2906 : : #ifndef RTE_HAS_SVE_ACLE
2907 : : uint16_t
2908 : 0 : hns3_recv_pkts_vec_sve(__rte_unused void *rx_queue,
2909 : : __rte_unused struct rte_mbuf **rx_pkts,
2910 : : __rte_unused uint16_t nb_pkts)
2911 : : {
2912 : 0 : return 0;
2913 : : }
2914 : : #endif /* RTE_HAS_SVE_ACLE */
2915 : :
2916 : : int
2917 : 0 : hns3_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
2918 : : struct rte_eth_burst_mode *mode)
2919 : : {
2920 : : static const struct {
2921 : : eth_rx_burst_t pkt_burst;
2922 : : const char *info;
2923 : : } burst_infos[] = {
2924 : : { hns3_recv_pkts_simple, "Scalar Simple" },
2925 : : { hns3_recv_scattered_pkts, "Scalar Scattered" },
2926 : : { hns3_recv_pkts_vec, "Vector Neon" },
2927 : : { hns3_recv_pkts_vec_sve, "Vector Sve" },
2928 : : { rte_eth_pkt_burst_dummy, "Dummy" },
2929 : : };
2930 : :
2931 : 0 : eth_rx_burst_t pkt_burst = dev->rx_pkt_burst;
2932 : : int ret = -EINVAL;
2933 : : unsigned int i;
2934 : :
2935 [ # # ]: 0 : for (i = 0; i < RTE_DIM(burst_infos); i++) {
2936 [ # # ]: 0 : if (pkt_burst == burst_infos[i].pkt_burst) {
2937 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
2938 : 0 : burst_infos[i].info);
2939 : : ret = 0;
2940 : 0 : break;
2941 : : }
2942 : : }
2943 : :
2944 : 0 : return ret;
2945 : : }
2946 : :
2947 : : static bool
2948 : : hns3_get_default_vec_support(void)
2949 : : {
2950 : : #if defined(RTE_ARCH_ARM64)
2951 : : if (rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128)
2952 : : return false;
2953 : : if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_NEON))
2954 : : return true;
2955 : : #endif
2956 : : return false;
2957 : : }
2958 : :
2959 : : static bool
2960 : : hns3_get_sve_support(void)
2961 : : {
2962 : : #if defined(RTE_HAS_SVE_ACLE)
2963 : : if (rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_256)
2964 : : return false;
2965 : : if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_SVE))
2966 : : return true;
2967 : : #endif
2968 : : return false;
2969 : : }
2970 : :
2971 : : static eth_rx_burst_t
2972 : 0 : hns3_get_rx_function(struct rte_eth_dev *dev)
2973 : : {
2974 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
2975 : 0 : uint64_t offloads = dev->data->dev_conf.rxmode.offloads;
2976 : : bool vec_allowed, sve_allowed, simple_allowed;
2977 : : bool vec_support;
2978 : :
2979 : 0 : vec_support = hns3_rx_check_vec_support(dev) == 0;
2980 : : vec_allowed = vec_support && hns3_get_default_vec_support();
2981 : : sve_allowed = vec_support && hns3_get_sve_support();
2982 [ # # ]: 0 : simple_allowed = !dev->data->scattered_rx &&
2983 [ # # ]: 0 : (offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) == 0;
2984 : :
2985 : 0 : if (hns->rx_func_hint == HNS3_IO_FUNC_HINT_VEC && vec_allowed)
2986 : : return hns3_recv_pkts_vec;
2987 : : if (hns->rx_func_hint == HNS3_IO_FUNC_HINT_SVE && sve_allowed)
2988 : : return hns3_recv_pkts_vec_sve;
2989 [ # # # # ]: 0 : if (hns->rx_func_hint == HNS3_IO_FUNC_HINT_SIMPLE && simple_allowed)
2990 : : return hns3_recv_pkts_simple;
2991 [ # # ]: 0 : if (hns->rx_func_hint == HNS3_IO_FUNC_HINT_COMMON)
2992 : : return hns3_recv_scattered_pkts;
2993 : :
2994 : : if (vec_allowed)
2995 : : return hns3_recv_pkts_vec;
2996 [ # # ]: 0 : if (simple_allowed)
2997 : 0 : return hns3_recv_pkts_simple;
2998 : :
2999 : : return hns3_recv_scattered_pkts;
3000 : : }
3001 : :
3002 : : static int
3003 : 0 : hns3_tx_queue_conf_check(struct hns3_hw *hw, const struct rte_eth_txconf *conf,
3004 : : uint16_t nb_desc, uint16_t *tx_rs_thresh,
3005 : : uint16_t *tx_free_thresh, uint16_t idx)
3006 : : {
3007 : : #define HNS3_TX_RS_FREE_THRESH_GAP 8
3008 : : uint16_t rs_thresh, free_thresh, fast_free_thresh;
3009 : :
3010 [ # # # # ]: 0 : if (nb_desc > HNS3_MAX_RING_DESC || nb_desc < HNS3_MIN_RING_DESC ||
3011 : : nb_desc % HNS3_ALIGN_RING_DESC) {
3012 : 0 : hns3_err(hw, "number (%u) of tx descriptors is invalid",
3013 : : nb_desc);
3014 : 0 : return -EINVAL;
3015 : : }
3016 : :
3017 [ # # ]: 0 : rs_thresh = (conf->tx_rs_thresh > 0) ?
3018 : : conf->tx_rs_thresh : HNS3_DEFAULT_TX_RS_THRESH;
3019 [ # # ]: 0 : free_thresh = (conf->tx_free_thresh > 0) ?
3020 : : conf->tx_free_thresh : HNS3_DEFAULT_TX_FREE_THRESH;
3021 [ # # # # ]: 0 : if (rs_thresh + free_thresh > nb_desc || nb_desc % rs_thresh ||
3022 [ # # # # ]: 0 : rs_thresh >= nb_desc - HNS3_TX_RS_FREE_THRESH_GAP ||
3023 : : free_thresh >= nb_desc - HNS3_TX_RS_FREE_THRESH_GAP) {
3024 : 0 : hns3_err(hw, "tx_rs_thresh (%u) tx_free_thresh (%u) nb_desc "
3025 : : "(%u) of tx descriptors for port=%u queue=%u check "
3026 : : "fail!",
3027 : : rs_thresh, free_thresh, nb_desc, hw->data->port_id,
3028 : : idx);
3029 : 0 : return -EINVAL;
3030 : : }
3031 : :
3032 [ # # ]: 0 : if (conf->tx_free_thresh == 0) {
3033 : : /* Fast free Tx memory buffer to improve cache hit rate */
3034 : 0 : fast_free_thresh = nb_desc - rs_thresh;
3035 [ # # ]: 0 : if (fast_free_thresh >=
3036 : : HNS3_TX_FAST_FREE_AHEAD + HNS3_DEFAULT_TX_FREE_THRESH)
3037 : 0 : free_thresh = fast_free_thresh -
3038 : : HNS3_TX_FAST_FREE_AHEAD;
3039 : : }
3040 : :
3041 : 0 : *tx_rs_thresh = rs_thresh;
3042 : 0 : *tx_free_thresh = free_thresh;
3043 : 0 : return 0;
3044 : : }
3045 : :
3046 : : static void *
3047 : : hns3_tx_push_get_queue_tail_reg(struct rte_eth_dev *dev, uint16_t queue_id)
3048 : : {
3049 : : #define HNS3_TX_PUSH_TQP_REGION_SIZE 0x10000
3050 : : #define HNS3_TX_PUSH_QUICK_DOORBELL_OFFSET 64
3051 : : #define HNS3_TX_PUSH_PCI_BAR_INDEX 4
3052 : :
3053 : 0 : struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
3054 : : uint8_t bar_id = HNS3_TX_PUSH_PCI_BAR_INDEX;
3055 : :
3056 : : /*
3057 : : * If device support Tx push then its PCIe bar45 must exist, and DPDK
3058 : : * framework will mmap the bar45 default in PCI probe stage.
3059 : : *
3060 : : * In the bar45, the first half is for RoCE (RDMA over Converged
3061 : : * Ethernet), and the second half is for NIC, every TQP occupy 64KB.
3062 : : *
3063 : : * The quick doorbell located at 64B offset in the TQP region.
3064 : : */
3065 : 0 : return (char *)pci_dev->mem_resource[bar_id].addr +
3066 : 0 : (pci_dev->mem_resource[bar_id].len >> 1) +
3067 : 0 : HNS3_TX_PUSH_TQP_REGION_SIZE * queue_id +
3068 : : HNS3_TX_PUSH_QUICK_DOORBELL_OFFSET;
3069 : : }
3070 : :
3071 : : void
3072 : 0 : hns3_tx_push_init(struct rte_eth_dev *dev)
3073 : : {
3074 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3075 : : volatile uint32_t *reg;
3076 : : uint32_t val;
3077 : :
3078 [ # # ]: 0 : if (!hns3_dev_get_support(hw, TX_PUSH))
3079 : : return;
3080 : :
3081 : : reg = (volatile uint32_t *)hns3_tx_push_get_queue_tail_reg(dev, 0);
3082 : : /*
3083 : : * Because the size of bar45 is about 8GB size, it may take a long time
3084 : : * to do the page fault in Tx process when work with vfio-pci, so use
3085 : : * one read operation to make kernel setup page table mapping for bar45
3086 : : * in the init stage.
3087 : : * Note: the bar45 is readable but the result is all 1.
3088 : : */
3089 : 0 : val = *reg;
3090 : : RTE_SET_USED(val);
3091 : : }
3092 : :
3093 : : static void
3094 : : hns3_tx_push_queue_init(struct rte_eth_dev *dev,
3095 : : uint16_t queue_id,
3096 : : struct hns3_tx_queue *txq)
3097 : : {
3098 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3099 : 0 : if (!hns3_dev_get_support(hw, TX_PUSH)) {
3100 : 0 : txq->tx_push_enable = false;
3101 : 0 : return;
3102 : : }
3103 : :
3104 : 0 : txq->io_tail_reg = (volatile void *)hns3_tx_push_get_queue_tail_reg(dev,
3105 : : queue_id);
3106 : 0 : txq->tx_push_enable = true;
3107 : : }
3108 : :
3109 : : int
3110 : 0 : hns3_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
3111 : : unsigned int socket_id, const struct rte_eth_txconf *conf)
3112 : : {
3113 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
3114 : : uint16_t tx_rs_thresh, tx_free_thresh;
3115 : 0 : struct hns3_hw *hw = &hns->hw;
3116 : : struct hns3_queue_info q_info;
3117 : : struct hns3_tx_queue *txq;
3118 : : int tx_entry_len;
3119 : : int ret;
3120 : :
3121 : 0 : ret = hns3_tx_queue_conf_check(hw, conf, nb_desc,
3122 : : &tx_rs_thresh, &tx_free_thresh, idx);
3123 [ # # ]: 0 : if (ret)
3124 : : return ret;
3125 : :
3126 [ # # ]: 0 : if (dev->data->tx_queues[idx] != NULL) {
3127 : 0 : hns3_tx_queue_release(dev->data->tx_queues[idx]);
3128 : 0 : dev->data->tx_queues[idx] = NULL;
3129 : : }
3130 : :
3131 : 0 : q_info.idx = idx;
3132 : 0 : q_info.socket_id = socket_id;
3133 : 0 : q_info.nb_desc = nb_desc;
3134 : 0 : q_info.type = "hns3 TX queue";
3135 : 0 : q_info.ring_name = "tx_ring";
3136 : 0 : txq = hns3_alloc_txq_and_dma_zone(dev, &q_info);
3137 [ # # ]: 0 : if (txq == NULL) {
3138 : 0 : hns3_err(hw,
3139 : : "Failed to alloc mem and reserve DMA mem for tx ring!");
3140 : 0 : return -ENOMEM;
3141 : : }
3142 : :
3143 : 0 : txq->tx_deferred_start = conf->tx_deferred_start;
3144 [ # # # # ]: 0 : if (txq->tx_deferred_start && !hns3_dev_get_support(hw, INDEP_TXRX)) {
3145 : 0 : hns3_warn(hw, "deferred start is not supported.");
3146 : 0 : txq->tx_deferred_start = false;
3147 : : }
3148 : :
3149 : 0 : tx_entry_len = sizeof(struct hns3_entry) * txq->nb_tx_desc;
3150 : 0 : txq->sw_ring = rte_zmalloc_socket("hns3 TX sw ring", tx_entry_len,
3151 : : RTE_CACHE_LINE_SIZE, socket_id);
3152 [ # # ]: 0 : if (txq->sw_ring == NULL) {
3153 : 0 : hns3_err(hw, "Failed to allocate memory for tx sw ring!");
3154 : 0 : hns3_tx_queue_release(txq);
3155 : 0 : return -ENOMEM;
3156 : : }
3157 : :
3158 : 0 : txq->hns = hns;
3159 : 0 : txq->next_to_use = 0;
3160 : 0 : txq->next_to_clean = 0;
3161 : 0 : txq->tx_bd_ready = txq->nb_tx_desc - 1;
3162 : 0 : txq->tx_free_thresh = tx_free_thresh;
3163 : 0 : txq->tx_rs_thresh = tx_rs_thresh;
3164 : 0 : txq->free = rte_zmalloc_socket("hns3 TX mbuf free array",
3165 : 0 : sizeof(struct rte_mbuf *) * txq->tx_rs_thresh,
3166 : : RTE_CACHE_LINE_SIZE, socket_id);
3167 [ # # ]: 0 : if (!txq->free) {
3168 : 0 : hns3_err(hw, "failed to allocate tx mbuf free array!");
3169 : 0 : hns3_tx_queue_release(txq);
3170 : 0 : return -ENOMEM;
3171 : : }
3172 : :
3173 : 0 : txq->port_id = dev->data->port_id;
3174 : : /*
3175 : : * For hns3 PF device, if the VLAN mode is HW_SHIFT_AND_DISCARD_MODE,
3176 : : * the pvid_sw_shift_en in the queue struct should not be changed,
3177 : : * because PVID-related operations do not need to be processed by PMD.
3178 : : * For hns3 VF device, whether it needs to process PVID depends
3179 : : * on the configuration of PF kernel mode netdev driver. And the
3180 : : * related PF configuration is delivered through the mailbox and finally
3181 : : * reflected in port_base_vlan_cfg.
3182 : : */
3183 [ # # # # ]: 0 : if (hns->is_vf || hw->vlan_mode == HNS3_SW_SHIFT_AND_DISCARD_MODE)
3184 : 0 : txq->pvid_sw_shift_en = hw->port_base_vlan_cfg.state ==
3185 : : HNS3_PORT_BASE_VLAN_ENABLE;
3186 : : else
3187 : 0 : txq->pvid_sw_shift_en = false;
3188 : :
3189 [ # # ]: 0 : if (hns3_dev_get_support(hw, SIMPLE_BD))
3190 : 0 : txq->simple_bd_enable = true;
3191 : :
3192 : 0 : txq->max_non_tso_bd_num = hw->max_non_tso_bd_num;
3193 : 0 : txq->configured = true;
3194 : 0 : txq->io_base = (void *)((char *)hw->io_base +
3195 : 0 : hns3_get_tqp_reg_offset(idx));
3196 : 0 : txq->io_tail_reg = (volatile void *)((char *)txq->io_base +
3197 : : HNS3_RING_TX_TAIL_REG);
3198 : 0 : txq->min_tx_pkt_len = hw->min_tx_pkt_len;
3199 : 0 : txq->tso_mode = hw->tso_mode;
3200 : 0 : txq->udp_cksum_mode = hw->udp_cksum_mode;
3201 : 0 : txq->mbuf_fast_free_en = !!(dev->data->dev_conf.txmode.offloads &
3202 : : RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE);
3203 [ # # ]: 0 : memset(&txq->basic_stats, 0, sizeof(struct hns3_tx_basic_stats));
3204 [ # # ]: 0 : memset(&txq->dfx_stats, 0, sizeof(struct hns3_tx_dfx_stats));
3205 : :
3206 : : /*
3207 : : * Call hns3_tx_push_queue_init after assigned io_tail_reg field because
3208 : : * it may overwrite the io_tail_reg field.
3209 : : */
3210 : : hns3_tx_push_queue_init(dev, idx, txq);
3211 : :
3212 : 0 : rte_spinlock_lock(&hw->lock);
3213 : 0 : dev->data->tx_queues[idx] = txq;
3214 : : rte_spinlock_unlock(&hw->lock);
3215 : :
3216 : 0 : return 0;
3217 : : }
3218 : :
3219 : : static void
3220 : 0 : hns3_tx_free_useless_buffer(struct hns3_tx_queue *txq)
3221 : : {
3222 : 0 : uint16_t tx_next_clean = txq->next_to_clean;
3223 : 0 : uint16_t tx_next_use = txq->next_to_use;
3224 : 0 : uint16_t tx_bd_ready = txq->tx_bd_ready;
3225 : 0 : uint16_t tx_bd_max = txq->nb_tx_desc;
3226 : 0 : struct hns3_entry *tx_bak_pkt = &txq->sw_ring[tx_next_clean];
3227 : 0 : struct hns3_desc *desc = &txq->tx_ring[tx_next_clean];
3228 : : struct rte_mbuf *mbuf;
3229 : :
3230 : 0 : while ((!(desc->tx.tp_fe_sc_vld_ra_ri &
3231 [ # # # # ]: 0 : rte_cpu_to_le_16(BIT(HNS3_TXD_VLD_B)))) &&
3232 : : tx_next_use != tx_next_clean) {
3233 : 0 : mbuf = tx_bak_pkt->mbuf;
3234 [ # # ]: 0 : if (mbuf) {
3235 : : rte_pktmbuf_free_seg(mbuf);
3236 : 0 : tx_bak_pkt->mbuf = NULL;
3237 : : }
3238 : :
3239 : 0 : desc++;
3240 : 0 : tx_bak_pkt++;
3241 : 0 : tx_next_clean++;
3242 : 0 : tx_bd_ready++;
3243 : :
3244 [ # # ]: 0 : if (tx_next_clean >= tx_bd_max) {
3245 : : tx_next_clean = 0;
3246 : 0 : desc = txq->tx_ring;
3247 : 0 : tx_bak_pkt = txq->sw_ring;
3248 : : }
3249 : : }
3250 : :
3251 : 0 : txq->next_to_clean = tx_next_clean;
3252 : 0 : txq->tx_bd_ready = tx_bd_ready;
3253 : 0 : }
3254 : :
3255 : : int
3256 : 0 : hns3_config_gro(struct hns3_hw *hw, bool en)
3257 : : {
3258 : : struct hns3_cfg_gro_status_cmd *req;
3259 : : struct hns3_cmd_desc desc;
3260 : : int ret;
3261 : :
3262 [ # # ]: 0 : if (!hns3_dev_get_support(hw, GRO))
3263 : : return 0;
3264 : :
3265 : 0 : hns3_cmd_setup_basic_desc(&desc, HNS3_OPC_GRO_GENERIC_CONFIG, false);
3266 : : req = (struct hns3_cfg_gro_status_cmd *)desc.data;
3267 : :
3268 : 0 : req->gro_en = rte_cpu_to_le_16(en ? 1 : 0);
3269 : :
3270 : 0 : ret = hns3_cmd_send(hw, &desc, 1);
3271 [ # # ]: 0 : if (ret)
3272 [ # # ]: 0 : hns3_err(hw, "%s hardware GRO failed, ret = %d",
3273 : : en ? "enable" : "disable", ret);
3274 : :
3275 : : return ret;
3276 : : }
3277 : :
3278 : : int
3279 : 0 : hns3_restore_gro_conf(struct hns3_hw *hw)
3280 : : {
3281 : : uint64_t offloads;
3282 : : bool gro_en;
3283 : : int ret;
3284 : :
3285 : 0 : offloads = hw->data->dev_conf.rxmode.offloads;
3286 : 0 : gro_en = offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO ? true : false;
3287 : 0 : ret = hns3_config_gro(hw, gro_en);
3288 [ # # ]: 0 : if (ret)
3289 [ # # ]: 0 : hns3_err(hw, "restore hardware GRO to %s failed, ret = %d",
3290 : : gro_en ? "enabled" : "disabled", ret);
3291 : :
3292 : 0 : return ret;
3293 : : }
3294 : :
3295 : : static inline bool
3296 : : hns3_pkt_is_tso(struct rte_mbuf *m)
3297 : : {
3298 [ # # # # : 0 : return (m->tso_segsz != 0 && m->ol_flags & RTE_MBUF_F_TX_TCP_SEG);
# # ]
3299 : : }
3300 : :
3301 : : static void
3302 : : hns3_set_tso(struct hns3_desc *desc, uint32_t paylen, struct rte_mbuf *rxm)
3303 : : {
3304 [ # # ]: 0 : if (!hns3_pkt_is_tso(rxm))
3305 : : return;
3306 : :
3307 [ # # ]: 0 : if (paylen <= rxm->tso_segsz)
3308 : : return;
3309 : :
3310 : 0 : desc->tx.type_cs_vlan_tso_len |= rte_cpu_to_le_32(BIT(HNS3_TXD_TSO_B));
3311 : 0 : desc->tx.ckst_mss |= rte_cpu_to_le_16(rxm->tso_segsz);
3312 : : }
3313 : :
3314 : : static inline void
3315 : : hns3_fill_per_desc(struct hns3_desc *desc, struct rte_mbuf *rxm)
3316 : : {
3317 : 0 : desc->addr = rte_mbuf_data_iova(rxm);
3318 : 0 : desc->tx.send_size = rte_cpu_to_le_16(rte_pktmbuf_data_len(rxm));
3319 : 0 : desc->tx.tp_fe_sc_vld_ra_ri |= rte_cpu_to_le_16(BIT(HNS3_TXD_VLD_B));
3320 : : }
3321 : :
3322 : : static void
3323 : 0 : hns3_fill_first_desc(struct hns3_tx_queue *txq, struct hns3_desc *desc,
3324 : : struct rte_mbuf *rxm)
3325 : : {
3326 : 0 : uint64_t ol_flags = rxm->ol_flags;
3327 : : uint32_t hdr_len;
3328 : : uint32_t paylen;
3329 : :
3330 : 0 : hdr_len = rxm->l2_len + rxm->l3_len + rxm->l4_len;
3331 : 0 : hdr_len += (ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) ?
3332 [ # # ]: 0 : rxm->outer_l2_len + rxm->outer_l3_len : 0;
3333 : 0 : paylen = rxm->pkt_len - hdr_len;
3334 [ # # ]: 0 : desc->tx.paylen_fd_dop_ol4cs |= rte_cpu_to_le_32(paylen);
3335 : : hns3_set_tso(desc, paylen, rxm);
3336 : :
3337 : : /*
3338 : : * Currently, hardware doesn't support more than two layers VLAN offload
3339 : : * in Tx direction based on hns3 network engine. So when the number of
3340 : : * VLANs in the packets represented by rxm plus the number of VLAN
3341 : : * offload by hardware such as PVID etc, exceeds two, the packets will
3342 : : * be discarded or the original VLAN of the packets will be overwritten
3343 : : * by hardware. When the PF PVID is enabled by calling the API function
3344 : : * named rte_eth_dev_set_vlan_pvid or the VF PVID is enabled by the hns3
3345 : : * PF kernel ether driver, the outer VLAN tag will always be the PVID.
3346 : : * To avoid the VLAN of Tx descriptor is overwritten by PVID, it should
3347 : : * be added to the position close to the IP header when PVID is enabled.
3348 : : */
3349 [ # # ]: 0 : if (!txq->pvid_sw_shift_en &&
3350 [ # # ]: 0 : ol_flags & (RTE_MBUF_F_TX_VLAN | RTE_MBUF_F_TX_QINQ)) {
3351 : 0 : desc->tx.ol_type_vlan_len_msec |=
3352 : : rte_cpu_to_le_32(BIT(HNS3_TXD_OVLAN_B));
3353 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_QINQ)
3354 : 0 : desc->tx.outer_vlan_tag =
3355 : 0 : rte_cpu_to_le_16(rxm->vlan_tci_outer);
3356 : : else
3357 : 0 : desc->tx.outer_vlan_tag =
3358 : 0 : rte_cpu_to_le_16(rxm->vlan_tci);
3359 : : }
3360 : :
3361 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_QINQ ||
3362 [ # # # # ]: 0 : ((ol_flags & RTE_MBUF_F_TX_VLAN) && txq->pvid_sw_shift_en)) {
3363 : 0 : desc->tx.type_cs_vlan_tso_len |=
3364 : : rte_cpu_to_le_32(BIT(HNS3_TXD_VLAN_B));
3365 : 0 : desc->tx.vlan_tag = rte_cpu_to_le_16(rxm->vlan_tci);
3366 : : }
3367 : :
3368 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST)
3369 : 0 : desc->tx.tp_fe_sc_vld_ra_ri |=
3370 : : rte_cpu_to_le_16(BIT(HNS3_TXD_TSYN_B));
3371 : 0 : }
3372 : :
3373 : : static inline int
3374 : 0 : hns3_tx_alloc_mbufs(struct rte_mempool *mb_pool, uint16_t nb_new_buf,
3375 : : struct rte_mbuf **alloc_mbuf)
3376 : : {
3377 : : #define MAX_NON_TSO_BD_PER_PKT 18
3378 : : struct rte_mbuf *pkt_segs[MAX_NON_TSO_BD_PER_PKT];
3379 : : uint16_t i;
3380 : :
3381 : : /* Allocate enough mbufs */
3382 [ # # # # ]: 0 : if (rte_mempool_get_bulk(mb_pool, (void **)pkt_segs, nb_new_buf))
3383 : : return -ENOMEM;
3384 : :
3385 [ # # ]: 0 : for (i = 0; i < nb_new_buf - 1; i++)
3386 : 0 : pkt_segs[i]->next = pkt_segs[i + 1];
3387 : :
3388 : 0 : pkt_segs[nb_new_buf - 1]->next = NULL;
3389 : 0 : pkt_segs[0]->nb_segs = nb_new_buf;
3390 : 0 : *alloc_mbuf = pkt_segs[0];
3391 : :
3392 : 0 : return 0;
3393 : : }
3394 : :
3395 : : static inline void
3396 : : hns3_pktmbuf_copy_hdr(struct rte_mbuf *new_pkt, struct rte_mbuf *old_pkt)
3397 : : {
3398 : 0 : new_pkt->ol_flags = old_pkt->ol_flags;
3399 : 0 : new_pkt->pkt_len = rte_pktmbuf_pkt_len(old_pkt);
3400 : 0 : new_pkt->outer_l2_len = old_pkt->outer_l2_len;
3401 : 0 : new_pkt->outer_l3_len = old_pkt->outer_l3_len;
3402 : 0 : new_pkt->l2_len = old_pkt->l2_len;
3403 : 0 : new_pkt->l3_len = old_pkt->l3_len;
3404 : 0 : new_pkt->l4_len = old_pkt->l4_len;
3405 : 0 : new_pkt->vlan_tci_outer = old_pkt->vlan_tci_outer;
3406 : 0 : new_pkt->vlan_tci = old_pkt->vlan_tci;
3407 : : }
3408 : :
3409 : : static int
3410 : 0 : hns3_reassemble_tx_pkts(struct rte_mbuf *tx_pkt, struct rte_mbuf **new_pkt,
3411 : : uint8_t max_non_tso_bd_num)
3412 : : {
3413 : : struct rte_mempool *mb_pool;
3414 : : struct rte_mbuf *new_mbuf;
3415 : : struct rte_mbuf *temp_new;
3416 : : struct rte_mbuf *temp;
3417 : : uint16_t last_buf_len;
3418 : : uint16_t nb_new_buf;
3419 : : uint16_t buf_size;
3420 : : uint16_t buf_len;
3421 : : uint16_t len_s;
3422 : : uint16_t len_d;
3423 : : uint16_t len;
3424 : : int ret;
3425 : : char *s;
3426 : : char *d;
3427 : :
3428 : 0 : mb_pool = tx_pkt->pool;
3429 : 0 : buf_size = tx_pkt->buf_len - RTE_PKTMBUF_HEADROOM;
3430 : 0 : nb_new_buf = (rte_pktmbuf_pkt_len(tx_pkt) - 1) / buf_size + 1;
3431 [ # # ]: 0 : if (nb_new_buf > max_non_tso_bd_num)
3432 : : return -EINVAL;
3433 : :
3434 : 0 : last_buf_len = rte_pktmbuf_pkt_len(tx_pkt) % buf_size;
3435 [ # # ]: 0 : if (last_buf_len == 0)
3436 : : last_buf_len = buf_size;
3437 : :
3438 : : /* Allocate enough mbufs */
3439 : 0 : ret = hns3_tx_alloc_mbufs(mb_pool, nb_new_buf, &new_mbuf);
3440 [ # # ]: 0 : if (ret)
3441 : : return ret;
3442 : :
3443 : : /* Copy the original packet content to the new mbufs */
3444 : : temp = tx_pkt;
3445 : 0 : s = rte_pktmbuf_mtod(temp, char *);
3446 : 0 : len_s = rte_pktmbuf_data_len(temp);
3447 : 0 : temp_new = new_mbuf;
3448 [ # # ]: 0 : while (temp != NULL && temp_new != NULL) {
3449 : 0 : d = rte_pktmbuf_mtod(temp_new, char *);
3450 [ # # ]: 0 : buf_len = temp_new->next == NULL ? last_buf_len : buf_size;
3451 : : len_d = buf_len;
3452 : :
3453 [ # # ]: 0 : while (len_d) {
3454 : 0 : len = RTE_MIN(len_s, len_d);
3455 [ # # ]: 0 : memcpy(d, s, len);
3456 : 0 : s = s + len;
3457 : 0 : d = d + len;
3458 : 0 : len_d = len_d - len;
3459 : 0 : len_s = len_s - len;
3460 : :
3461 [ # # ]: 0 : if (len_s == 0) {
3462 : 0 : temp = temp->next;
3463 [ # # ]: 0 : if (temp == NULL)
3464 : : break;
3465 : 0 : s = rte_pktmbuf_mtod(temp, char *);
3466 : 0 : len_s = rte_pktmbuf_data_len(temp);
3467 : : }
3468 : : }
3469 : :
3470 : 0 : temp_new->data_len = buf_len;
3471 : 0 : temp_new = temp_new->next;
3472 : : }
3473 : : hns3_pktmbuf_copy_hdr(new_mbuf, tx_pkt);
3474 : :
3475 : : /* free original mbufs */
3476 : 0 : rte_pktmbuf_free(tx_pkt);
3477 : :
3478 : 0 : *new_pkt = new_mbuf;
3479 : :
3480 : 0 : return 0;
3481 : : }
3482 : :
3483 : : static void
3484 : : hns3_parse_outer_params(struct rte_mbuf *m, uint32_t *ol_type_vlan_len_msec)
3485 : : {
3486 : : uint32_t tmp = *ol_type_vlan_len_msec;
3487 : 0 : uint64_t ol_flags = m->ol_flags;
3488 : :
3489 : : /* (outer) IP header type */
3490 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_OUTER_IPV4) {
3491 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM)
3492 : : tmp |= hns3_gen_field_val(HNS3_TXD_OL3T_M,
3493 : : HNS3_TXD_OL3T_S, HNS3_OL3T_IPV4_CSUM);
3494 : : else
3495 : : tmp |= hns3_gen_field_val(HNS3_TXD_OL3T_M,
3496 : : HNS3_TXD_OL3T_S, HNS3_OL3T_IPV4_NO_CSUM);
3497 [ # # ]: 0 : } else if (ol_flags & RTE_MBUF_F_TX_OUTER_IPV6) {
3498 : : tmp |= hns3_gen_field_val(HNS3_TXD_OL3T_M, HNS3_TXD_OL3T_S,
3499 : : HNS3_OL3T_IPV6);
3500 : : }
3501 : : /* OL3 header size, defined in 4 bytes */
3502 : 0 : tmp |= hns3_gen_field_val(HNS3_TXD_L3LEN_M, HNS3_TXD_L3LEN_S,
3503 : : m->outer_l3_len >> HNS3_L3_LEN_UNIT);
3504 : 0 : *ol_type_vlan_len_msec = tmp;
3505 : : }
3506 : :
3507 : : static int
3508 : 0 : hns3_parse_inner_params(struct rte_mbuf *m, uint32_t *ol_type_vlan_len_msec,
3509 : : uint32_t *type_cs_vlan_tso_len)
3510 : : {
3511 : : #define HNS3_NVGRE_HLEN 8
3512 : 0 : uint32_t tmp_outer = *ol_type_vlan_len_msec;
3513 : 0 : uint32_t tmp_inner = *type_cs_vlan_tso_len;
3514 : 0 : uint64_t ol_flags = m->ol_flags;
3515 : : uint16_t inner_l2_len;
3516 : :
3517 [ # # # ]: 0 : switch (ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) {
3518 : 0 : case RTE_MBUF_F_TX_TUNNEL_VXLAN_GPE:
3519 : : case RTE_MBUF_F_TX_TUNNEL_GENEVE:
3520 : : case RTE_MBUF_F_TX_TUNNEL_VXLAN:
3521 : : /* MAC in UDP tunnelling packet, include VxLAN and GENEVE */
3522 : : tmp_outer |= hns3_gen_field_val(HNS3_TXD_TUNTYPE_M,
3523 : : HNS3_TXD_TUNTYPE_S, HNS3_TUN_MAC_IN_UDP);
3524 : : /*
3525 : : * The inner l2 length of mbuf is the sum of outer l4 length,
3526 : : * tunneling header length and inner l2 length for a tunnel
3527 : : * packet. But in hns3 tx descriptor, the tunneling header
3528 : : * length is contained in the field of outer L4 length.
3529 : : * Therefore, driver need to calculate the outer L4 length and
3530 : : * inner L2 length.
3531 : : */
3532 : 0 : tmp_outer |= hns3_gen_field_val(HNS3_TXD_L4LEN_M,
3533 : : HNS3_TXD_L4LEN_S,
3534 : : (uint8_t)RTE_ETHER_VXLAN_HLEN >>
3535 : : HNS3_L4_LEN_UNIT);
3536 : :
3537 : 0 : inner_l2_len = m->l2_len - RTE_ETHER_VXLAN_HLEN;
3538 : 0 : break;
3539 : 0 : case RTE_MBUF_F_TX_TUNNEL_GRE:
3540 : : tmp_outer |= hns3_gen_field_val(HNS3_TXD_TUNTYPE_M,
3541 : : HNS3_TXD_TUNTYPE_S, HNS3_TUN_NVGRE);
3542 : : /*
3543 : : * For NVGRE tunnel packet, the outer L4 is empty. So only
3544 : : * fill the NVGRE header length to the outer L4 field.
3545 : : */
3546 : 0 : tmp_outer |= hns3_gen_field_val(HNS3_TXD_L4LEN_M,
3547 : : HNS3_TXD_L4LEN_S,
3548 : : (uint8_t)HNS3_NVGRE_HLEN >> HNS3_L4_LEN_UNIT);
3549 : :
3550 : 0 : inner_l2_len = m->l2_len - HNS3_NVGRE_HLEN;
3551 : 0 : break;
3552 : : default:
3553 : : /* For non UDP / GRE tunneling, drop the tunnel packet */
3554 : : return -EINVAL;
3555 : : }
3556 : :
3557 : 0 : tmp_inner |= hns3_gen_field_val(HNS3_TXD_L2LEN_M, HNS3_TXD_L2LEN_S,
3558 : : inner_l2_len >> HNS3_L2_LEN_UNIT);
3559 : : /* OL2 header size, defined in 2 bytes */
3560 : 0 : tmp_outer |= hns3_gen_field_val(HNS3_TXD_L2LEN_M, HNS3_TXD_L2LEN_S,
3561 : : m->outer_l2_len >> HNS3_L2_LEN_UNIT);
3562 : :
3563 : 0 : *type_cs_vlan_tso_len = tmp_inner;
3564 : 0 : *ol_type_vlan_len_msec = tmp_outer;
3565 : :
3566 : 0 : return 0;
3567 : : }
3568 : :
3569 : : static int
3570 : 0 : hns3_parse_tunneling_params(struct hns3_tx_queue *txq, struct rte_mbuf *m,
3571 : : uint16_t tx_desc_id)
3572 : : {
3573 : 0 : struct hns3_desc *tx_ring = txq->tx_ring;
3574 : 0 : struct hns3_desc *desc = &tx_ring[tx_desc_id];
3575 : 0 : uint64_t ol_flags = m->ol_flags;
3576 : 0 : uint32_t tmp_outer = 0;
3577 : 0 : uint32_t tmp_inner = 0;
3578 : : uint32_t tmp_ol4cs;
3579 : : int ret;
3580 : :
3581 : : /*
3582 : : * The tunnel header is contained in the inner L2 header field of the
3583 : : * mbuf, but for hns3 descriptor, it is contained in the outer L4. So,
3584 : : * there is a need that switching between them. To avoid multiple
3585 : : * calculations, the length of the L2 header include the outer and
3586 : : * inner, will be filled during the parsing of tunnel packets.
3587 : : */
3588 [ # # ]: 0 : if (!(ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK)) {
3589 : : /*
3590 : : * For non tunnel type the tunnel type id is 0, so no need to
3591 : : * assign a value to it. Only the inner(normal) L2 header length
3592 : : * is assigned.
3593 : : */
3594 : 0 : tmp_inner |= hns3_gen_field_val(HNS3_TXD_L2LEN_M,
3595 : : HNS3_TXD_L2LEN_S, m->l2_len >> HNS3_L2_LEN_UNIT);
3596 : : } else {
3597 : : /*
3598 : : * If outer csum is not offload, the outer length may be filled
3599 : : * with 0. And the length of the outer header is added to the
3600 : : * inner l2_len. It would lead a cksum error. So driver has to
3601 : : * calculate the header length.
3602 : : */
3603 [ # # # # ]: 0 : if (unlikely(!(ol_flags &
3604 : : (RTE_MBUF_F_TX_OUTER_IP_CKSUM | RTE_MBUF_F_TX_OUTER_UDP_CKSUM)) &&
3605 : : m->outer_l2_len == 0)) {
3606 : : struct rte_net_hdr_lens hdr_len;
3607 : 0 : (void)rte_net_get_ptype(m, &hdr_len,
3608 : : RTE_PTYPE_L2_MASK | RTE_PTYPE_L3_MASK);
3609 : 0 : m->outer_l3_len = hdr_len.l3_len;
3610 : 0 : m->outer_l2_len = hdr_len.l2_len;
3611 : 0 : m->l2_len = m->l2_len - hdr_len.l2_len - hdr_len.l3_len;
3612 : : }
3613 : : hns3_parse_outer_params(m, &tmp_outer);
3614 : 0 : ret = hns3_parse_inner_params(m, &tmp_outer, &tmp_inner);
3615 [ # # ]: 0 : if (ret)
3616 : : return -EINVAL;
3617 : : }
3618 : :
3619 : 0 : desc->tx.ol_type_vlan_len_msec = rte_cpu_to_le_32(tmp_outer);
3620 : 0 : desc->tx.type_cs_vlan_tso_len = rte_cpu_to_le_32(tmp_inner);
3621 : 0 : tmp_ol4cs = ol_flags & RTE_MBUF_F_TX_OUTER_UDP_CKSUM ?
3622 : 0 : BIT(HNS3_TXD_OL4CS_B) : 0;
3623 : 0 : desc->tx.paylen_fd_dop_ol4cs = rte_cpu_to_le_32(tmp_ol4cs);
3624 : :
3625 : 0 : return 0;
3626 : : }
3627 : :
3628 : : static void
3629 : : hns3_parse_l3_cksum_params(struct rte_mbuf *m, uint32_t *type_cs_vlan_tso_len)
3630 : : {
3631 : 0 : uint64_t ol_flags = m->ol_flags;
3632 : : uint32_t l3_type;
3633 : : uint32_t tmp;
3634 : :
3635 : : tmp = *type_cs_vlan_tso_len;
3636 : 0 : if (ol_flags & RTE_MBUF_F_TX_IPV4)
3637 : : l3_type = HNS3_L3T_IPV4;
3638 [ # # ]: 0 : else if (ol_flags & RTE_MBUF_F_TX_IPV6)
3639 : : l3_type = HNS3_L3T_IPV6;
3640 : : else
3641 : : l3_type = HNS3_L3T_NONE;
3642 : :
3643 : : /* inner(/normal) L3 header size, defined in 4 bytes */
3644 : 0 : tmp |= hns3_gen_field_val(HNS3_TXD_L3LEN_M, HNS3_TXD_L3LEN_S,
3645 : : m->l3_len >> HNS3_L3_LEN_UNIT);
3646 : :
3647 : 0 : tmp |= hns3_gen_field_val(HNS3_TXD_L3T_M, HNS3_TXD_L3T_S, l3_type);
3648 : :
3649 : : /* Enable L3 checksum offloads */
3650 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IP_CKSUM)
3651 : 0 : tmp |= BIT(HNS3_TXD_L3CS_B);
3652 : 0 : *type_cs_vlan_tso_len = tmp;
3653 : : }
3654 : :
3655 : : static void
3656 : 0 : hns3_parse_l4_cksum_params(struct rte_mbuf *m, uint32_t *type_cs_vlan_tso_len)
3657 : : {
3658 : 0 : uint64_t ol_flags = m->ol_flags;
3659 : : uint32_t tmp;
3660 : : /* Enable L4 checksum offloads */
3661 [ # # # # ]: 0 : switch (ol_flags & (RTE_MBUF_F_TX_L4_MASK | RTE_MBUF_F_TX_TCP_SEG)) {
3662 : 0 : case RTE_MBUF_F_TX_TCP_CKSUM | RTE_MBUF_F_TX_TCP_SEG:
3663 : : case RTE_MBUF_F_TX_TCP_CKSUM:
3664 : : case RTE_MBUF_F_TX_TCP_SEG:
3665 : 0 : tmp = *type_cs_vlan_tso_len;
3666 : 0 : tmp |= hns3_gen_field_val(HNS3_TXD_L4T_M, HNS3_TXD_L4T_S,
3667 : : HNS3_L4T_TCP);
3668 : 0 : break;
3669 : 0 : case RTE_MBUF_F_TX_UDP_CKSUM:
3670 : 0 : tmp = *type_cs_vlan_tso_len;
3671 : 0 : tmp |= hns3_gen_field_val(HNS3_TXD_L4T_M, HNS3_TXD_L4T_S,
3672 : : HNS3_L4T_UDP);
3673 : 0 : break;
3674 : 0 : case RTE_MBUF_F_TX_SCTP_CKSUM:
3675 : 0 : tmp = *type_cs_vlan_tso_len;
3676 : 0 : tmp |= hns3_gen_field_val(HNS3_TXD_L4T_M, HNS3_TXD_L4T_S,
3677 : : HNS3_L4T_SCTP);
3678 : 0 : break;
3679 : : default:
3680 : : return;
3681 : : }
3682 : 0 : tmp |= BIT(HNS3_TXD_L4CS_B);
3683 : 0 : tmp |= hns3_gen_field_val(HNS3_TXD_L4LEN_M, HNS3_TXD_L4LEN_S,
3684 : : m->l4_len >> HNS3_L4_LEN_UNIT);
3685 : 0 : *type_cs_vlan_tso_len = tmp;
3686 : : }
3687 : :
3688 : : static void
3689 : 0 : hns3_txd_enable_checksum(struct hns3_tx_queue *txq, struct rte_mbuf *m,
3690 : : uint16_t tx_desc_id)
3691 : : {
3692 : 0 : struct hns3_desc *tx_ring = txq->tx_ring;
3693 [ # # ]: 0 : struct hns3_desc *desc = &tx_ring[tx_desc_id];
3694 : : uint32_t value = 0;
3695 : :
3696 : : hns3_parse_l3_cksum_params(m, &value);
3697 : 0 : hns3_parse_l4_cksum_params(m, &value);
3698 : :
3699 : 0 : desc->tx.type_cs_vlan_tso_len |= rte_cpu_to_le_32(value);
3700 : 0 : }
3701 : :
3702 : : static bool
3703 : 0 : hns3_pkt_need_linearized(struct rte_mbuf *tx_pkts, uint32_t bd_num,
3704 : : uint32_t max_non_tso_bd_num)
3705 : : {
3706 : : struct rte_mbuf *m_first = tx_pkts;
3707 : : struct rte_mbuf *m_last = tx_pkts;
3708 : : uint32_t tot_len = 0;
3709 : : uint32_t hdr_len;
3710 : : uint32_t i;
3711 : :
3712 : : /*
3713 : : * Hardware requires that the sum of the data length of every 8
3714 : : * consecutive buffers is greater than MSS in hns3 network engine.
3715 : : * We simplify it by ensuring pkt_headlen + the first 8 consecutive
3716 : : * frags greater than gso header len + mss, and the remaining 7
3717 : : * consecutive frags greater than MSS except the last 7 frags.
3718 : : */
3719 [ # # ]: 0 : if (bd_num <= max_non_tso_bd_num)
3720 : : return false;
3721 : :
3722 [ # # # # ]: 0 : for (i = 0; m_last && i < max_non_tso_bd_num - 1;
3723 : 0 : i++, m_last = m_last->next)
3724 : 0 : tot_len += m_last->data_len;
3725 : :
3726 [ # # ]: 0 : if (!m_last)
3727 : : return true;
3728 : :
3729 : : /* ensure the first 8 frags is greater than mss + header */
3730 : 0 : hdr_len = tx_pkts->l2_len + tx_pkts->l3_len + tx_pkts->l4_len;
3731 : 0 : hdr_len += (tx_pkts->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) ?
3732 [ # # ]: 0 : tx_pkts->outer_l2_len + tx_pkts->outer_l3_len : 0;
3733 [ # # ]: 0 : if (tot_len + m_last->data_len < tx_pkts->tso_segsz + hdr_len)
3734 : : return true;
3735 : :
3736 : : /*
3737 : : * ensure the sum of the data length of every 7 consecutive buffer
3738 : : * is greater than mss except the last one.
3739 : : */
3740 [ # # # # ]: 0 : for (i = 0; m_last && i < bd_num - max_non_tso_bd_num; i++) {
3741 : 0 : tot_len -= m_first->data_len;
3742 : 0 : tot_len += m_last->data_len;
3743 : :
3744 [ # # ]: 0 : if (tot_len < tx_pkts->tso_segsz)
3745 : : return true;
3746 : :
3747 : 0 : m_first = m_first->next;
3748 : 0 : m_last = m_last->next;
3749 : : }
3750 : :
3751 : : return false;
3752 : : }
3753 : :
3754 : : static int
3755 : 0 : hns3_check_tso_pkt_valid(struct rte_mbuf *m)
3756 : : {
3757 : : uint32_t tmp_data_len_sum = 0;
3758 : 0 : uint16_t nb_buf = m->nb_segs;
3759 : : uint32_t paylen, hdr_len;
3760 : : struct rte_mbuf *m_seg;
3761 : : int i;
3762 : :
3763 [ # # ]: 0 : if (nb_buf > HNS3_MAX_TSO_BD_PER_PKT)
3764 : : return -EINVAL;
3765 : :
3766 : 0 : hdr_len = m->l2_len + m->l3_len + m->l4_len;
3767 : 0 : hdr_len += (m->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK) ?
3768 [ # # ]: 0 : m->outer_l2_len + m->outer_l3_len : 0;
3769 [ # # ]: 0 : if (hdr_len > HNS3_MAX_TSO_HDR_SIZE)
3770 : : return -EINVAL;
3771 : :
3772 : 0 : paylen = m->pkt_len - hdr_len;
3773 [ # # ]: 0 : if (paylen > HNS3_MAX_BD_PAYLEN)
3774 : : return -EINVAL;
3775 : :
3776 : : /*
3777 : : * The TSO header (include outer and inner L2, L3 and L4 header)
3778 : : * should be provided by three descriptors in maximum in hns3 network
3779 : : * engine.
3780 : : */
3781 : : m_seg = m;
3782 [ # # # # ]: 0 : for (i = 0; m_seg != NULL && i < HNS3_MAX_TSO_HDR_BD_NUM && i < nb_buf;
3783 : 0 : i++, m_seg = m_seg->next) {
3784 : 0 : tmp_data_len_sum += m_seg->data_len;
3785 : : }
3786 : :
3787 [ # # ]: 0 : if (hdr_len > tmp_data_len_sum)
3788 : 0 : return -EINVAL;
3789 : :
3790 : : return 0;
3791 : : }
3792 : :
3793 : : #ifdef RTE_LIBRTE_ETHDEV_DEBUG
3794 : : static inline int
3795 : : hns3_vld_vlan_chk(struct hns3_tx_queue *txq, struct rte_mbuf *m)
3796 : : {
3797 : : struct rte_ether_hdr *eh;
3798 : : struct rte_vlan_hdr *vh;
3799 : :
3800 : : if (!txq->pvid_sw_shift_en)
3801 : : return 0;
3802 : :
3803 : : /*
3804 : : * Due to hardware limitations, we only support two-layer VLAN hardware
3805 : : * offload in Tx direction based on hns3 network engine, so when PVID is
3806 : : * enabled, QinQ insert is no longer supported.
3807 : : * And when PVID is enabled, in the following two cases:
3808 : : * i) packets with more than two VLAN tags.
3809 : : * ii) packets with one VLAN tag while the hardware VLAN insert is
3810 : : * enabled.
3811 : : * The packets will be regarded as abnormal packets and discarded by
3812 : : * hardware in Tx direction. For debugging purposes, a validation check
3813 : : * for these types of packets is added to the '.tx_pkt_prepare' ops
3814 : : * implementation function named hns3_prep_pkts to inform users that
3815 : : * these packets will be discarded.
3816 : : */
3817 : : if (m->ol_flags & RTE_MBUF_F_TX_QINQ)
3818 : : return -EINVAL;
3819 : :
3820 : : eh = rte_pktmbuf_mtod(m, struct rte_ether_hdr *);
3821 : : if (eh->ether_type == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN)) {
3822 : : if (m->ol_flags & RTE_MBUF_F_TX_VLAN)
3823 : : return -EINVAL;
3824 : :
3825 : : /* Ensure the incoming packet is not a QinQ packet */
3826 : : vh = (struct rte_vlan_hdr *)(eh + 1);
3827 : : if (vh->eth_proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN))
3828 : : return -EINVAL;
3829 : : }
3830 : :
3831 : : return 0;
3832 : : }
3833 : : #endif
3834 : :
3835 : : static uint16_t
3836 : 0 : hns3_udp_cksum_help(struct rte_mbuf *m)
3837 : : {
3838 : 0 : uint64_t ol_flags = m->ol_flags;
3839 : 0 : uint16_t cksum = 0;
3840 : : uint32_t l4_len;
3841 : :
3842 [ # # ]: 0 : if (ol_flags & RTE_MBUF_F_TX_IPV4) {
3843 : 0 : struct rte_ipv4_hdr *ipv4_hdr = rte_pktmbuf_mtod_offset(m,
3844 : : struct rte_ipv4_hdr *, m->l2_len);
3845 [ # # ]: 0 : l4_len = rte_be_to_cpu_16(ipv4_hdr->total_length) - m->l3_len;
3846 : : } else {
3847 : 0 : struct rte_ipv6_hdr *ipv6_hdr = rte_pktmbuf_mtod_offset(m,
3848 : : struct rte_ipv6_hdr *, m->l2_len);
3849 [ # # ]: 0 : l4_len = rte_be_to_cpu_16(ipv6_hdr->payload_len);
3850 : : }
3851 : :
3852 : 0 : rte_raw_cksum_mbuf(m, m->l2_len + m->l3_len, l4_len, &cksum);
3853 : :
3854 : 0 : cksum = ~cksum;
3855 : : /*
3856 : : * RFC 768:If the computed checksum is zero for UDP, it is transmitted
3857 : : * as all ones
3858 : : */
3859 [ # # ]: 0 : if (cksum == 0)
3860 : 0 : cksum = 0xffff;
3861 : :
3862 : 0 : return (uint16_t)cksum;
3863 : : }
3864 : :
3865 : : static bool
3866 : 0 : hns3_validate_tunnel_cksum(struct hns3_tx_queue *tx_queue, struct rte_mbuf *m)
3867 : : {
3868 : 0 : uint64_t ol_flags = m->ol_flags;
3869 : : struct rte_udp_hdr *udp_hdr;
3870 : : uint16_t dst_port;
3871 : :
3872 [ # # ]: 0 : if (tx_queue->udp_cksum_mode == HNS3_SPECIAL_PORT_HW_CKSUM_MODE ||
3873 [ # # ]: 0 : ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK ||
3874 : : (ol_flags & RTE_MBUF_F_TX_L4_MASK) != RTE_MBUF_F_TX_UDP_CKSUM)
3875 : : return true;
3876 : : /*
3877 : : * A UDP packet with the same dst_port as VXLAN\VXLAN_GPE\GENEVE will
3878 : : * be recognized as a tunnel packet in HW. In this case, if UDP CKSUM
3879 : : * offload is set and the tunnel mask has not been set, the CKSUM will
3880 : : * be wrong since the header length is wrong and driver should complete
3881 : : * the CKSUM to avoid CKSUM error.
3882 : : */
3883 : 0 : udp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_udp_hdr *,
3884 : : m->l2_len + m->l3_len);
3885 [ # # ]: 0 : dst_port = rte_be_to_cpu_16(udp_hdr->dst_port);
3886 [ # # ]: 0 : switch (dst_port) {
3887 : 0 : case RTE_VXLAN_DEFAULT_PORT:
3888 : : case RTE_VXLAN_GPE_DEFAULT_PORT:
3889 : : case RTE_GENEVE_DEFAULT_PORT:
3890 : 0 : udp_hdr->dgram_cksum = hns3_udp_cksum_help(m);
3891 : 0 : m->ol_flags = ol_flags & ~RTE_MBUF_F_TX_L4_MASK;
3892 : 0 : return false;
3893 : : default:
3894 : : return true;
3895 : : }
3896 : : }
3897 : :
3898 : : static int
3899 [ # # ]: 0 : hns3_prep_pkt_proc(struct hns3_tx_queue *tx_queue, struct rte_mbuf *m)
3900 : : {
3901 : : int ret;
3902 : :
3903 : : #ifdef RTE_LIBRTE_ETHDEV_DEBUG
3904 : : ret = rte_validate_tx_offload(m);
3905 : : if (ret != 0) {
3906 : : rte_errno = -ret;
3907 : : return ret;
3908 : : }
3909 : :
3910 : : ret = hns3_vld_vlan_chk(tx_queue, m);
3911 : : if (ret != 0) {
3912 : : rte_errno = EINVAL;
3913 : : return ret;
3914 : : }
3915 : : #endif
3916 [ # # ]: 0 : if (hns3_pkt_is_tso(m)) {
3917 : 0 : if (hns3_pkt_need_linearized(m, m->nb_segs,
3918 [ # # ]: 0 : tx_queue->max_non_tso_bd_num) ||
3919 [ # # ]: 0 : hns3_check_tso_pkt_valid(m)) {
3920 : 0 : rte_errno = EINVAL;
3921 : 0 : return -EINVAL;
3922 : : }
3923 : :
3924 [ # # ]: 0 : if (tx_queue->tso_mode != HNS3_TSO_SW_CAL_PSEUDO_H_CSUM) {
3925 : : /*
3926 : : * (tso mode != HNS3_TSO_SW_CAL_PSEUDO_H_CSUM) means
3927 : : * hardware support recalculate the TCP pseudo header
3928 : : * checksum of packets that need TSO, so network driver
3929 : : * software not need to recalculate it.
3930 : : */
3931 : : return 0;
3932 : : }
3933 : : }
3934 : :
3935 : : ret = rte_net_intel_cksum_prepare(m);
3936 [ # # ]: 0 : if (ret != 0) {
3937 : 0 : rte_errno = -ret;
3938 : 0 : return ret;
3939 : : }
3940 : :
3941 : 0 : if (!hns3_validate_tunnel_cksum(tx_queue, m))
3942 : : return 0;
3943 : :
3944 : : return 0;
3945 : : }
3946 : :
3947 : : uint16_t
3948 : 0 : hns3_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
3949 : : uint16_t nb_pkts)
3950 : : {
3951 : : struct rte_mbuf *m;
3952 : : uint16_t i;
3953 : :
3954 [ # # ]: 0 : for (i = 0; i < nb_pkts; i++) {
3955 : 0 : m = tx_pkts[i];
3956 [ # # ]: 0 : if (hns3_prep_pkt_proc(tx_queue, m))
3957 : 0 : return i;
3958 : : }
3959 : :
3960 : : return i;
3961 : : }
3962 : :
3963 : : static inline int
3964 : 0 : hns3_handle_simple_bd(struct hns3_tx_queue *txq, struct hns3_desc *desc,
3965 : : struct rte_mbuf *m)
3966 : : {
3967 : : #define HNS3_TCP_CSUM_OFFSET 16
3968 : : #define HNS3_UDP_CSUM_OFFSET 6
3969 : :
3970 : : /*
3971 : : * In HIP09, NIC HW support Tx simple BD mode that the HW will
3972 : : * calculate the checksum from the start position of checksum and fill
3973 : : * the checksum result to the offset position without packet type and
3974 : : * header length of L3/L4.
3975 : : * For non-tunneling packet:
3976 : : * - Tx simple BD support for TCP and UDP checksum.
3977 : : * For tunneling packet:
3978 : : * - Tx simple BD support for inner L4 checksum(except sctp checksum).
3979 : : * - Tx simple BD not support the outer checksum and the inner L3
3980 : : * checksum.
3981 : : * - Besides, Tx simple BD is not support for TSO.
3982 : : */
3983 [ # # ]: 0 : if (txq->simple_bd_enable && !(m->ol_flags & RTE_MBUF_F_TX_IP_CKSUM) &&
3984 [ # # ]: 0 : !(m->ol_flags & RTE_MBUF_F_TX_TCP_SEG) &&
3985 : 0 : !(m->ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) &&
3986 [ # # ]: 0 : ((m->ol_flags & RTE_MBUF_F_TX_L4_MASK) == RTE_MBUF_F_TX_TCP_CKSUM ||
3987 : : (m->ol_flags & RTE_MBUF_F_TX_L4_MASK) == RTE_MBUF_F_TX_UDP_CKSUM)) {
3988 : : /* set checksum start and offset, defined in 2 Bytes */
3989 : 0 : hns3_set_field(desc->tx.type_cs_vlan_tso_len,
3990 : : HNS3_TXD_L4_START_M, HNS3_TXD_L4_START_S,
3991 : : (m->l2_len + m->l3_len) >> HNS3_SIMPLE_BD_UNIT);
3992 [ # # ]: 0 : hns3_set_field(desc->tx.ol_type_vlan_len_msec,
3993 : : HNS3_TXD_L4_CKS_OFFSET_M, HNS3_TXD_L4_CKS_OFFSET_S,
3994 : : (m->ol_flags & RTE_MBUF_F_TX_L4_MASK) ==
3995 : : RTE_MBUF_F_TX_TCP_CKSUM ?
3996 : : HNS3_TCP_CSUM_OFFSET >> HNS3_SIMPLE_BD_UNIT :
3997 : : HNS3_UDP_CSUM_OFFSET >> HNS3_SIMPLE_BD_UNIT);
3998 : :
3999 : 0 : hns3_set_bit(desc->tx.ckst_mss, HNS3_TXD_CKST_B, 1);
4000 : :
4001 : 0 : return 0;
4002 : : }
4003 : :
4004 : : return -ENOTSUP;
4005 : : }
4006 : :
4007 : : static int
4008 : 0 : hns3_parse_cksum(struct hns3_tx_queue *txq, uint16_t tx_desc_id,
4009 : : struct rte_mbuf *m)
4010 : : {
4011 : 0 : struct hns3_desc *tx_ring = txq->tx_ring;
4012 : 0 : struct hns3_desc *desc = &tx_ring[tx_desc_id];
4013 : :
4014 : : /* Enable checksum offloading */
4015 [ # # ]: 0 : if (m->ol_flags & HNS3_TX_CKSUM_OFFLOAD_MASK) {
4016 [ # # ]: 0 : if (hns3_handle_simple_bd(txq, desc, m) == 0)
4017 : : return 0;
4018 : : /* Fill in tunneling parameters if necessary */
4019 [ # # ]: 0 : if (hns3_parse_tunneling_params(txq, m, tx_desc_id)) {
4020 : 0 : txq->dfx_stats.unsupported_tunnel_pkt_cnt++;
4021 : 0 : return -EINVAL;
4022 : : }
4023 : :
4024 : 0 : hns3_txd_enable_checksum(txq, m, tx_desc_id);
4025 : : } else {
4026 : : /* clear the control bit */
4027 : 0 : desc->tx.type_cs_vlan_tso_len = 0;
4028 : 0 : desc->tx.ol_type_vlan_len_msec = 0;
4029 : : }
4030 : :
4031 : : return 0;
4032 : : }
4033 : :
4034 : : static int
4035 : 0 : hns3_check_non_tso_pkt(uint16_t nb_buf, struct rte_mbuf **m_seg,
4036 : : struct rte_mbuf *tx_pkt, struct hns3_tx_queue *txq)
4037 : : {
4038 : : uint8_t max_non_tso_bd_num;
4039 : : struct rte_mbuf *new_pkt;
4040 : : int ret;
4041 : :
4042 [ # # # # ]: 0 : if (hns3_pkt_is_tso(*m_seg))
4043 : : return 0;
4044 : :
4045 : : /*
4046 : : * If packet length is greater than HNS3_MAX_FRAME_LEN
4047 : : * driver support, the packet will be ignored.
4048 : : */
4049 [ # # ]: 0 : if (unlikely(rte_pktmbuf_pkt_len(tx_pkt) > HNS3_MAX_FRAME_LEN)) {
4050 : 0 : txq->dfx_stats.over_length_pkt_cnt++;
4051 : 0 : return -EINVAL;
4052 : : }
4053 : :
4054 : 0 : max_non_tso_bd_num = txq->max_non_tso_bd_num;
4055 [ # # ]: 0 : if (unlikely(nb_buf > max_non_tso_bd_num)) {
4056 : 0 : txq->dfx_stats.exceed_limit_bd_pkt_cnt++;
4057 : 0 : ret = hns3_reassemble_tx_pkts(tx_pkt, &new_pkt,
4058 : : max_non_tso_bd_num);
4059 [ # # ]: 0 : if (ret) {
4060 : 0 : txq->dfx_stats.exceed_limit_bd_reassem_fail++;
4061 : 0 : return ret;
4062 : : }
4063 : 0 : *m_seg = new_pkt;
4064 : : }
4065 : :
4066 : : return 0;
4067 : : }
4068 : :
4069 : : static inline void
4070 : 0 : hns3_tx_free_buffer_simple(struct hns3_tx_queue *txq)
4071 : : {
4072 : : struct hns3_entry *tx_entry;
4073 : : struct hns3_desc *desc;
4074 : : uint16_t tx_next_clean;
4075 : : uint16_t i;
4076 : :
4077 : : while (1) {
4078 [ # # ]: 0 : if (HNS3_GET_TX_QUEUE_PEND_BD_NUM(txq) < txq->tx_rs_thresh)
4079 : : break;
4080 : :
4081 : : /*
4082 : : * All mbufs can be released only when the VLD bits of all
4083 : : * descriptors in a batch are cleared.
4084 : : */
4085 : 0 : tx_next_clean = (txq->next_to_clean + txq->tx_rs_thresh - 1) %
4086 : : txq->nb_tx_desc;
4087 : 0 : desc = &txq->tx_ring[tx_next_clean];
4088 [ # # ]: 0 : for (i = 0; i < txq->tx_rs_thresh; i++) {
4089 [ # # ]: 0 : if (rte_le_to_cpu_16(desc->tx.tp_fe_sc_vld_ra_ri) &
4090 : : BIT(HNS3_TXD_VLD_B))
4091 : : return;
4092 : 0 : desc--;
4093 : : }
4094 : :
4095 : 0 : tx_entry = &txq->sw_ring[txq->next_to_clean];
4096 : :
4097 [ # # ]: 0 : if (txq->mbuf_fast_free_en) {
4098 [ # # ]: 0 : rte_mempool_put_bulk(tx_entry->mbuf->pool,
4099 : : (void **)tx_entry, txq->tx_rs_thresh);
4100 [ # # ]: 0 : for (i = 0; i < txq->tx_rs_thresh; i++)
4101 : 0 : tx_entry[i].mbuf = NULL;
4102 : 0 : goto update_field;
4103 : : }
4104 : :
4105 [ # # ]: 0 : for (i = 0; i < txq->tx_rs_thresh; i++)
4106 : 0 : rte_prefetch0((tx_entry + i)->mbuf);
4107 [ # # ]: 0 : for (i = 0; i < txq->tx_rs_thresh; i++, tx_entry++) {
4108 : 0 : rte_pktmbuf_free_seg(tx_entry->mbuf);
4109 : 0 : tx_entry->mbuf = NULL;
4110 : : }
4111 : :
4112 : 0 : update_field:
4113 : 0 : txq->next_to_clean = (tx_next_clean + 1) % txq->nb_tx_desc;
4114 : 0 : txq->tx_bd_ready += txq->tx_rs_thresh;
4115 : : }
4116 : : }
4117 : :
4118 : : static inline void
4119 : : hns3_tx_backup_1mbuf(struct hns3_entry *tx_entry, struct rte_mbuf **pkts)
4120 : : {
4121 : 0 : tx_entry->mbuf = pkts[0];
4122 : : }
4123 : :
4124 : : static inline void
4125 : : hns3_tx_backup_4mbuf(struct hns3_entry *tx_entry, struct rte_mbuf **pkts)
4126 : : {
4127 : : hns3_tx_backup_1mbuf(&tx_entry[0], &pkts[0]);
4128 : : hns3_tx_backup_1mbuf(&tx_entry[1], &pkts[1]);
4129 : : hns3_tx_backup_1mbuf(&tx_entry[2], &pkts[2]);
4130 : : hns3_tx_backup_1mbuf(&tx_entry[3], &pkts[3]);
4131 : : }
4132 : :
4133 : : static inline void
4134 : 0 : hns3_tx_setup_4bd(struct hns3_desc *txdp, struct rte_mbuf **pkts)
4135 : : {
4136 : : #define PER_LOOP_NUM 4
4137 : : uint16_t bd_flag = BIT(HNS3_TXD_VLD_B) | BIT(HNS3_TXD_FE_B);
4138 : : uint64_t dma_addr;
4139 : : uint32_t i;
4140 : :
4141 [ # # ]: 0 : for (i = 0; i < PER_LOOP_NUM; i++, txdp++, pkts++) {
4142 [ # # ]: 0 : dma_addr = rte_mbuf_data_iova(*pkts);
4143 : 0 : txdp->addr = rte_cpu_to_le_64(dma_addr);
4144 : 0 : txdp->tx.send_size = rte_cpu_to_le_16((*pkts)->data_len);
4145 : 0 : txdp->tx.paylen_fd_dop_ol4cs = 0;
4146 : 0 : txdp->tx.type_cs_vlan_tso_len = 0;
4147 : 0 : txdp->tx.ol_type_vlan_len_msec = 0;
4148 [ # # ]: 0 : if (unlikely((*pkts)->ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST))
4149 : : bd_flag |= BIT(HNS3_TXD_TSYN_B);
4150 : 0 : txdp->tx.tp_fe_sc_vld_ra_ri = rte_cpu_to_le_16(bd_flag);
4151 : : }
4152 : 0 : }
4153 : :
4154 : : static inline void
4155 : : hns3_tx_setup_1bd(struct hns3_desc *txdp, struct rte_mbuf **pkts)
4156 : : {
4157 : : uint16_t bd_flag = BIT(HNS3_TXD_VLD_B) | BIT(HNS3_TXD_FE_B);
4158 : : uint64_t dma_addr;
4159 : :
4160 : : dma_addr = rte_mbuf_data_iova(*pkts);
4161 : 0 : txdp->addr = rte_cpu_to_le_64(dma_addr);
4162 : 0 : txdp->tx.send_size = rte_cpu_to_le_16((*pkts)->data_len);
4163 : 0 : txdp->tx.paylen_fd_dop_ol4cs = 0;
4164 : 0 : txdp->tx.type_cs_vlan_tso_len = 0;
4165 : 0 : txdp->tx.ol_type_vlan_len_msec = 0;
4166 [ # # ]: 0 : if (unlikely((*pkts)->ol_flags & RTE_MBUF_F_TX_IEEE1588_TMST))
4167 : : bd_flag |= BIT(HNS3_TXD_TSYN_B);
4168 : 0 : txdp->tx.tp_fe_sc_vld_ra_ri = rte_cpu_to_le_16(bd_flag);
4169 : : }
4170 : :
4171 : : static inline void
4172 : 0 : hns3_tx_fill_hw_ring(struct hns3_tx_queue *txq,
4173 : : struct rte_mbuf **pkts,
4174 : : uint16_t nb_pkts)
4175 : : {
4176 : : #define PER_LOOP_NUM 4
4177 : : #define PER_LOOP_MASK (PER_LOOP_NUM - 1)
4178 : 0 : struct hns3_desc *txdp = &txq->tx_ring[txq->next_to_use];
4179 : 0 : struct hns3_entry *tx_entry = &txq->sw_ring[txq->next_to_use];
4180 : 0 : const uint32_t mainpart = (nb_pkts & ((uint32_t)~PER_LOOP_MASK));
4181 : 0 : const uint32_t leftover = (nb_pkts & ((uint32_t)PER_LOOP_MASK));
4182 : : uint32_t i;
4183 : :
4184 [ # # ]: 0 : for (i = 0; i < mainpart; i += PER_LOOP_NUM) {
4185 : 0 : hns3_tx_backup_4mbuf(tx_entry + i, pkts + i);
4186 : 0 : hns3_tx_setup_4bd(txdp + i, pkts + i);
4187 : :
4188 : : /* Increment bytes counter */
4189 : : uint32_t j;
4190 [ # # ]: 0 : for (j = 0; j < PER_LOOP_NUM; j++)
4191 : 0 : txq->basic_stats.bytes += pkts[i + j]->pkt_len;
4192 : : }
4193 [ # # ]: 0 : if (unlikely(leftover > 0)) {
4194 [ # # ]: 0 : for (i = 0; i < leftover; i++) {
4195 : 0 : hns3_tx_backup_1mbuf(tx_entry + mainpart + i,
4196 : 0 : pkts + mainpart + i);
4197 [ # # ]: 0 : hns3_tx_setup_1bd(txdp + mainpart + i,
4198 : : pkts + mainpart + i);
4199 : :
4200 : : /* Increment bytes counter */
4201 : 0 : txq->basic_stats.bytes += pkts[mainpart + i]->pkt_len;
4202 : : }
4203 : : }
4204 : 0 : }
4205 : :
4206 : : uint16_t
4207 : 0 : hns3_xmit_pkts_simple(void *tx_queue,
4208 : : struct rte_mbuf **tx_pkts,
4209 : : uint16_t nb_pkts)
4210 : : {
4211 : : struct hns3_tx_queue *txq = tx_queue;
4212 : : uint16_t nb_tx = 0;
4213 : :
4214 : 0 : hns3_tx_free_buffer_simple(txq);
4215 : :
4216 : 0 : nb_pkts = RTE_MIN(txq->tx_bd_ready, nb_pkts);
4217 [ # # ]: 0 : if (unlikely(nb_pkts == 0)) {
4218 [ # # ]: 0 : if (txq->tx_bd_ready == 0)
4219 : 0 : txq->dfx_stats.queue_full_cnt++;
4220 : 0 : return 0;
4221 : : }
4222 : :
4223 : 0 : txq->tx_bd_ready -= nb_pkts;
4224 [ # # ]: 0 : if (txq->next_to_use + nb_pkts >= txq->nb_tx_desc) {
4225 : 0 : nb_tx = txq->nb_tx_desc - txq->next_to_use;
4226 : 0 : hns3_tx_fill_hw_ring(txq, tx_pkts, nb_tx);
4227 : 0 : txq->next_to_use = 0;
4228 : : }
4229 : :
4230 [ # # ]: 0 : if (nb_pkts > nb_tx) {
4231 : 0 : hns3_tx_fill_hw_ring(txq, tx_pkts + nb_tx, nb_pkts - nb_tx);
4232 : 0 : txq->next_to_use += nb_pkts - nb_tx;
4233 : : }
4234 : :
4235 : 0 : hns3_write_txq_tail_reg(txq, nb_pkts);
4236 : :
4237 : : return nb_pkts;
4238 : : }
4239 : :
4240 : : uint16_t
4241 : 0 : hns3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
4242 : : {
4243 : : struct hns3_tx_queue *txq = tx_queue;
4244 : : struct hns3_entry *tx_bak_pkt;
4245 : : struct hns3_desc *tx_ring;
4246 : : struct rte_mbuf *tx_pkt;
4247 : : struct rte_mbuf *m_seg;
4248 : : struct hns3_desc *desc;
4249 : : uint32_t nb_hold = 0;
4250 : : uint16_t tx_next_use;
4251 : : uint16_t tx_pkt_num;
4252 : : uint16_t tx_bd_max;
4253 : : uint16_t nb_buf;
4254 : : uint16_t nb_tx;
4255 : : uint16_t i;
4256 : :
4257 : 0 : hns3_tx_free_useless_buffer(txq);
4258 : :
4259 : 0 : tx_next_use = txq->next_to_use;
4260 : 0 : tx_bd_max = txq->nb_tx_desc;
4261 : : tx_pkt_num = nb_pkts;
4262 : 0 : tx_ring = txq->tx_ring;
4263 : :
4264 : : /* send packets */
4265 : 0 : tx_bak_pkt = &txq->sw_ring[tx_next_use];
4266 [ # # ]: 0 : for (nb_tx = 0; nb_tx < tx_pkt_num; nb_tx++) {
4267 : 0 : tx_pkt = *tx_pkts++;
4268 : :
4269 : 0 : nb_buf = tx_pkt->nb_segs;
4270 : :
4271 [ # # ]: 0 : if (nb_buf > txq->tx_bd_ready) {
4272 : 0 : txq->dfx_stats.queue_full_cnt++;
4273 [ # # ]: 0 : if (nb_tx == 0)
4274 : : return 0;
4275 : 0 : goto end_of_tx;
4276 : : }
4277 : :
4278 : : /*
4279 : : * If packet length is less than minimum packet length supported
4280 : : * by hardware in Tx direction, driver need to pad it to avoid
4281 : : * error.
4282 : : */
4283 [ # # ]: 0 : if (unlikely(rte_pktmbuf_pkt_len(tx_pkt) <
4284 : : txq->min_tx_pkt_len)) {
4285 : : uint16_t add_len;
4286 : : char *appended;
4287 : :
4288 : 0 : add_len = txq->min_tx_pkt_len -
4289 : : rte_pktmbuf_pkt_len(tx_pkt);
4290 : : appended = rte_pktmbuf_append(tx_pkt, add_len);
4291 [ # # ]: 0 : if (appended == NULL) {
4292 : 0 : txq->dfx_stats.pkt_padding_fail_cnt++;
4293 : 0 : break;
4294 : : }
4295 : :
4296 : 0 : memset(appended, 0, add_len);
4297 : : }
4298 : :
4299 : 0 : m_seg = tx_pkt;
4300 : :
4301 [ # # ]: 0 : if (hns3_check_non_tso_pkt(nb_buf, &m_seg, tx_pkt, txq))
4302 : 0 : goto end_of_tx;
4303 : :
4304 [ # # ]: 0 : if (hns3_parse_cksum(txq, tx_next_use, m_seg))
4305 : 0 : goto end_of_tx;
4306 : :
4307 : : i = 0;
4308 : 0 : desc = &tx_ring[tx_next_use];
4309 : :
4310 : : /*
4311 : : * If the packet is divided into multiple Tx Buffer Descriptors,
4312 : : * only need to fill vlan, paylen and tso into the first Tx
4313 : : * Buffer Descriptor.
4314 : : */
4315 : 0 : hns3_fill_first_desc(txq, desc, m_seg);
4316 : :
4317 : : do {
4318 : 0 : desc = &tx_ring[tx_next_use];
4319 : : /*
4320 : : * Fill valid bits, DMA address and data length for each
4321 : : * Tx Buffer Descriptor.
4322 : : */
4323 [ # # ]: 0 : hns3_fill_per_desc(desc, m_seg);
4324 : 0 : tx_bak_pkt->mbuf = m_seg;
4325 : 0 : m_seg = m_seg->next;
4326 : 0 : tx_next_use++;
4327 : 0 : tx_bak_pkt++;
4328 [ # # ]: 0 : if (tx_next_use >= tx_bd_max) {
4329 : : tx_next_use = 0;
4330 : 0 : tx_bak_pkt = txq->sw_ring;
4331 : : }
4332 : : if (m_seg != NULL)
4333 : : TX_BD_LOG(&txq->hns->hw, DEBUG, desc);
4334 : :
4335 : 0 : i++;
4336 [ # # ]: 0 : } while (m_seg != NULL);
4337 : :
4338 : : /* Add end flag for the last Tx Buffer Descriptor */
4339 : 0 : desc->tx.tp_fe_sc_vld_ra_ri |=
4340 : : rte_cpu_to_le_16(BIT(HNS3_TXD_FE_B));
4341 : : TX_BD_LOG(&txq->hns->hw, DEBUG, desc);
4342 : :
4343 : : /* Increment bytes counter */
4344 : 0 : txq->basic_stats.bytes += tx_pkt->pkt_len;
4345 : 0 : nb_hold += i;
4346 : 0 : txq->next_to_use = tx_next_use;
4347 : 0 : txq->tx_bd_ready -= i;
4348 : : }
4349 : :
4350 : 0 : end_of_tx:
4351 : :
4352 [ # # ]: 0 : if (likely(nb_tx))
4353 : : hns3_write_txq_tail_reg(txq, nb_hold);
4354 : :
4355 : : return nb_tx;
4356 : : }
4357 : :
4358 : : #ifndef RTE_ARCH_ARM64
4359 : : int
4360 : 0 : hns3_tx_check_vec_support(__rte_unused struct rte_eth_dev *dev)
4361 : : {
4362 : 0 : return -ENOTSUP;
4363 : : }
4364 : :
4365 : : uint16_t
4366 : 0 : hns3_xmit_pkts_vec(__rte_unused void *tx_queue,
4367 : : __rte_unused struct rte_mbuf **tx_pkts,
4368 : : __rte_unused uint16_t nb_pkts)
4369 : : {
4370 : 0 : return 0;
4371 : : }
4372 : : #endif /* RTE_ARCH_ARM64 */
4373 : :
4374 : : #ifndef RTE_HAS_SVE_ACLE
4375 : : uint16_t
4376 : 0 : hns3_xmit_pkts_vec_sve(void __rte_unused * tx_queue,
4377 : : struct rte_mbuf __rte_unused **tx_pkts,
4378 : : uint16_t __rte_unused nb_pkts)
4379 : : {
4380 : 0 : return 0;
4381 : : }
4382 : : #endif /* RTE_HAS_SVE_ACLE */
4383 : :
4384 : : int
4385 : 0 : hns3_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
4386 : : struct rte_eth_burst_mode *mode)
4387 : : {
4388 : : static const struct {
4389 : : eth_tx_burst_t pkt_burst;
4390 : : const char *info;
4391 : : } burst_infos[] = {
4392 : : { hns3_xmit_pkts_simple, "Scalar Simple" },
4393 : : { hns3_xmit_pkts, "Scalar" },
4394 : : { hns3_xmit_pkts_vec, "Vector Neon" },
4395 : : { hns3_xmit_pkts_vec_sve, "Vector Sve" },
4396 : : { rte_eth_pkt_burst_dummy, "Dummy" },
4397 : : };
4398 : :
4399 : 0 : eth_tx_burst_t pkt_burst = dev->tx_pkt_burst;
4400 : : int ret = -EINVAL;
4401 : : unsigned int i;
4402 : :
4403 [ # # ]: 0 : for (i = 0; i < RTE_DIM(burst_infos); i++) {
4404 [ # # ]: 0 : if (pkt_burst == burst_infos[i].pkt_burst) {
4405 : 0 : snprintf(mode->info, sizeof(mode->info), "%s",
4406 : 0 : burst_infos[i].info);
4407 : : ret = 0;
4408 : 0 : break;
4409 : : }
4410 : : }
4411 : :
4412 : 0 : return ret;
4413 : : }
4414 : :
4415 : : static bool
4416 : : hns3_tx_check_simple_support(struct rte_eth_dev *dev)
4417 : : {
4418 : 0 : uint64_t offloads = dev->data->dev_conf.txmode.offloads;
4419 : :
4420 : 0 : return (offloads == (offloads & RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE));
4421 : : }
4422 : :
4423 : : static bool
4424 : : hns3_get_tx_prep_needed(struct rte_eth_dev *dev)
4425 : : {
4426 : : #define HNS3_DEV_TX_CSKUM_TSO_OFFLOAD_MASK (\
4427 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | \
4428 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM | \
4429 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM | \
4430 : : RTE_ETH_TX_OFFLOAD_SCTP_CKSUM | \
4431 : : RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM | \
4432 : : RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM | \
4433 : : RTE_ETH_TX_OFFLOAD_TCP_TSO | \
4434 : : RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO | \
4435 : : RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO | \
4436 : : RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO)
4437 : :
4438 : 0 : uint64_t tx_offload = dev->data->dev_conf.txmode.offloads;
4439 : :
4440 : 0 : if (tx_offload & HNS3_DEV_TX_CSKUM_TSO_OFFLOAD_MASK)
4441 : : return true;
4442 : :
4443 : : return false;
4444 : : }
4445 : :
4446 : : static eth_tx_prep_t
4447 : : hns3_get_tx_prepare(struct rte_eth_dev *dev)
4448 : : {
4449 : : return hns3_get_tx_prep_needed(dev) ? hns3_prep_pkts : NULL;
4450 : : }
4451 : :
4452 : : static eth_tx_burst_t
4453 : 0 : hns3_get_tx_function(struct rte_eth_dev *dev)
4454 : : {
4455 : 0 : struct hns3_adapter *hns = dev->data->dev_private;
4456 : : bool vec_allowed, sve_allowed, simple_allowed;
4457 : : bool vec_support;
4458 : :
4459 : 0 : vec_support = hns3_tx_check_vec_support(dev) == 0;
4460 : : vec_allowed = vec_support && hns3_get_default_vec_support();
4461 : : sve_allowed = vec_support && hns3_get_sve_support();
4462 : : simple_allowed = hns3_tx_check_simple_support(dev);
4463 : :
4464 : 0 : if (hns->tx_func_hint == HNS3_IO_FUNC_HINT_VEC && vec_allowed)
4465 : : return hns3_xmit_pkts_vec;
4466 : : if (hns->tx_func_hint == HNS3_IO_FUNC_HINT_SVE && sve_allowed)
4467 : : return hns3_xmit_pkts_vec_sve;
4468 [ # # # # ]: 0 : if (hns->tx_func_hint == HNS3_IO_FUNC_HINT_SIMPLE && simple_allowed)
4469 : : return hns3_xmit_pkts_simple;
4470 [ # # ]: 0 : if (hns->tx_func_hint == HNS3_IO_FUNC_HINT_COMMON)
4471 : : return hns3_xmit_pkts;
4472 : :
4473 : : if (vec_allowed)
4474 : : return hns3_xmit_pkts_vec;
4475 [ # # ]: 0 : if (simple_allowed)
4476 : 0 : return hns3_xmit_pkts_simple;
4477 : :
4478 : : return hns3_xmit_pkts;
4479 : : }
4480 : :
4481 : : static void
4482 : 0 : hns3_trace_rxtx_function(struct rte_eth_dev *dev)
4483 : : {
4484 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4485 : : struct rte_eth_burst_mode rx_mode;
4486 : : struct rte_eth_burst_mode tx_mode;
4487 : :
4488 : : memset(&rx_mode, 0, sizeof(rx_mode));
4489 : : memset(&tx_mode, 0, sizeof(tx_mode));
4490 : 0 : (void)hns3_rx_burst_mode_get(dev, 0, &rx_mode);
4491 : 0 : (void)hns3_tx_burst_mode_get(dev, 0, &tx_mode);
4492 : :
4493 : 0 : hns3_dbg(hw, "using rx_pkt_burst: %s, tx_pkt_burst: %s.",
4494 : : rx_mode.info, tx_mode.info);
4495 : 0 : }
4496 : :
4497 : : static void
4498 : : hns3_eth_dev_fp_ops_config(const struct rte_eth_dev *dev)
4499 : : {
4500 : : struct rte_eth_fp_ops *fpo = rte_eth_fp_ops;
4501 : 0 : uint16_t port_id = dev->data->port_id;
4502 : :
4503 : 0 : fpo[port_id].rx_pkt_burst = dev->rx_pkt_burst;
4504 : 0 : fpo[port_id].tx_pkt_burst = dev->tx_pkt_burst;
4505 : 0 : fpo[port_id].tx_pkt_prepare = dev->tx_pkt_prepare;
4506 : 0 : fpo[port_id].rx_descriptor_status = dev->rx_descriptor_status;
4507 : 0 : fpo[port_id].tx_descriptor_status = dev->tx_descriptor_status;
4508 : 0 : fpo[port_id].rxq.data = dev->data->rx_queues;
4509 : 0 : fpo[port_id].txq.data = dev->data->tx_queues;
4510 : : }
4511 : :
4512 : : void
4513 : 0 : hns3_set_rxtx_function(struct rte_eth_dev *eth_dev)
4514 : : {
4515 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
4516 : : struct hns3_adapter *hns = eth_dev->data->dev_private;
4517 : :
4518 [ # # ]: 0 : if (hns->hw.adapter_state == HNS3_NIC_STARTED &&
4519 [ # # ]: 0 : rte_atomic_load_explicit(&hns->hw.reset.resetting, rte_memory_order_relaxed) == 0) {
4520 : 0 : eth_dev->rx_pkt_burst = hns3_get_rx_function(eth_dev);
4521 : 0 : eth_dev->rx_descriptor_status = hns3_dev_rx_descriptor_status;
4522 [ # # ]: 0 : eth_dev->tx_pkt_burst = hw->set_link_down ?
4523 [ # # ]: 0 : rte_eth_pkt_burst_dummy :
4524 : 0 : hns3_get_tx_function(eth_dev);
4525 : 0 : eth_dev->tx_pkt_prepare = hns3_get_tx_prepare(eth_dev);
4526 : 0 : eth_dev->tx_descriptor_status = hns3_dev_tx_descriptor_status;
4527 : : } else {
4528 : 0 : eth_dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
4529 : 0 : eth_dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
4530 : 0 : eth_dev->tx_pkt_prepare = NULL;
4531 : : }
4532 : :
4533 : 0 : hns3_trace_rxtx_function(eth_dev);
4534 : : hns3_eth_dev_fp_ops_config(eth_dev);
4535 : 0 : }
4536 : :
4537 : : void
4538 : 0 : hns3_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
4539 : : struct rte_eth_rxq_info *qinfo)
4540 : : {
4541 : 0 : struct hns3_rx_queue *rxq = dev->data->rx_queues[queue_id];
4542 : :
4543 : 0 : qinfo->mp = rxq->mb_pool;
4544 : 0 : qinfo->nb_desc = rxq->nb_rx_desc;
4545 : 0 : qinfo->scattered_rx = dev->data->scattered_rx;
4546 : : /* Report the HW Rx buffer length to user */
4547 : 0 : qinfo->rx_buf_size = rxq->rx_buf_len;
4548 : :
4549 : : /*
4550 : : * If there are no available Rx buffer descriptors, incoming packets
4551 : : * are always dropped by hardware based on hns3 network engine.
4552 : : */
4553 : 0 : qinfo->conf.rx_drop_en = 1;
4554 : 0 : qinfo->conf.offloads = dev->data->dev_conf.rxmode.offloads;
4555 : 0 : qinfo->conf.rx_free_thresh = rxq->rx_free_thresh;
4556 : 0 : qinfo->conf.rx_deferred_start = rxq->rx_deferred_start;
4557 : 0 : }
4558 : :
4559 : : void
4560 : 0 : hns3_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
4561 : : struct rte_eth_txq_info *qinfo)
4562 : : {
4563 : 0 : struct hns3_tx_queue *txq = dev->data->tx_queues[queue_id];
4564 : :
4565 : 0 : qinfo->nb_desc = txq->nb_tx_desc;
4566 : 0 : qinfo->conf.offloads = dev->data->dev_conf.txmode.offloads;
4567 : 0 : qinfo->conf.tx_rs_thresh = txq->tx_rs_thresh;
4568 : 0 : qinfo->conf.tx_free_thresh = txq->tx_free_thresh;
4569 : 0 : qinfo->conf.tx_deferred_start = txq->tx_deferred_start;
4570 : 0 : }
4571 : :
4572 : : int
4573 : 0 : hns3_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
4574 : : {
4575 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4576 : 0 : struct hns3_rx_queue *rxq = dev->data->rx_queues[rx_queue_id];
4577 : : struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
4578 : : int ret;
4579 : :
4580 [ # # ]: 0 : if (!hns3_dev_get_support(hw, INDEP_TXRX))
4581 : : return -ENOTSUP;
4582 : :
4583 : 0 : rte_spinlock_lock(&hw->lock);
4584 : :
4585 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.resetting, rte_memory_order_relaxed)) {
4586 : 0 : hns3_err(hw, "fail to start Rx queue during resetting.");
4587 : : rte_spinlock_unlock(&hw->lock);
4588 : 0 : return -EIO;
4589 : : }
4590 : :
4591 : 0 : ret = hns3_reset_queue(hw, rx_queue_id, HNS3_RING_TYPE_RX);
4592 [ # # ]: 0 : if (ret) {
4593 : 0 : hns3_err(hw, "fail to reset Rx queue %u, ret = %d.",
4594 : : rx_queue_id, ret);
4595 : : rte_spinlock_unlock(&hw->lock);
4596 : 0 : return ret;
4597 : : }
4598 : :
4599 [ # # ]: 0 : if (rxq->sw_ring[0].mbuf != NULL)
4600 : 0 : hns3_rx_queue_release_mbufs(rxq);
4601 : :
4602 : 0 : ret = hns3_init_rxq(hns, rx_queue_id);
4603 [ # # ]: 0 : if (ret) {
4604 : 0 : hns3_err(hw, "fail to init Rx queue %u, ret = %d.",
4605 : : rx_queue_id, ret);
4606 : : rte_spinlock_unlock(&hw->lock);
4607 : 0 : return ret;
4608 : : }
4609 : :
4610 : : hns3_enable_rxq(rxq, true);
4611 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
4612 : : rte_spinlock_unlock(&hw->lock);
4613 : :
4614 : 0 : return ret;
4615 : : }
4616 : :
4617 : : static void
4618 : 0 : hns3_reset_sw_rxq(struct hns3_rx_queue *rxq)
4619 : : {
4620 : 0 : rxq->next_to_use = 0;
4621 : 0 : rxq->rx_rearm_start = 0;
4622 : 0 : rxq->rx_free_hold = 0;
4623 : 0 : rxq->rx_rearm_nb = 0;
4624 : 0 : rxq->pkt_first_seg = NULL;
4625 : 0 : rxq->pkt_last_seg = NULL;
4626 : 0 : memset(&rxq->rx_ring[0], 0, rxq->nb_rx_desc * sizeof(struct hns3_desc));
4627 : 0 : hns3_rxq_vec_setup(rxq);
4628 : 0 : }
4629 : :
4630 : : int
4631 : 0 : hns3_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
4632 : : {
4633 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4634 : 0 : struct hns3_rx_queue *rxq = dev->data->rx_queues[rx_queue_id];
4635 : :
4636 [ # # ]: 0 : if (!hns3_dev_get_support(hw, INDEP_TXRX))
4637 : : return -ENOTSUP;
4638 : :
4639 : 0 : rte_spinlock_lock(&hw->lock);
4640 : :
4641 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.resetting, rte_memory_order_relaxed)) {
4642 : 0 : hns3_err(hw, "fail to stop Rx queue during resetting.");
4643 : : rte_spinlock_unlock(&hw->lock);
4644 : 0 : return -EIO;
4645 : : }
4646 : :
4647 : : hns3_enable_rxq(rxq, false);
4648 : :
4649 : 0 : hns3_rx_queue_release_mbufs(rxq);
4650 : :
4651 : 0 : hns3_reset_sw_rxq(rxq);
4652 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
4653 : : rte_spinlock_unlock(&hw->lock);
4654 : :
4655 : 0 : return 0;
4656 : : }
4657 : :
4658 : : int
4659 : 0 : hns3_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
4660 : : {
4661 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4662 : 0 : struct hns3_tx_queue *txq = dev->data->tx_queues[tx_queue_id];
4663 : : int ret;
4664 : :
4665 [ # # ]: 0 : if (!hns3_dev_get_support(hw, INDEP_TXRX))
4666 : : return -ENOTSUP;
4667 : :
4668 : 0 : rte_spinlock_lock(&hw->lock);
4669 : :
4670 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.resetting, rte_memory_order_relaxed)) {
4671 : 0 : hns3_err(hw, "fail to start Tx queue during resetting.");
4672 : : rte_spinlock_unlock(&hw->lock);
4673 : 0 : return -EIO;
4674 : : }
4675 : :
4676 : 0 : ret = hns3_reset_queue(hw, tx_queue_id, HNS3_RING_TYPE_TX);
4677 [ # # ]: 0 : if (ret) {
4678 : 0 : hns3_err(hw, "fail to reset Tx queue %u, ret = %d.",
4679 : : tx_queue_id, ret);
4680 : : rte_spinlock_unlock(&hw->lock);
4681 : 0 : return ret;
4682 : : }
4683 : :
4684 : 0 : hns3_init_txq(txq);
4685 : : hns3_enable_txq(txq, true);
4686 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
4687 : : rte_spinlock_unlock(&hw->lock);
4688 : :
4689 : 0 : return ret;
4690 : : }
4691 : :
4692 : : int
4693 : 0 : hns3_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
4694 : : {
4695 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4696 : 0 : struct hns3_tx_queue *txq = dev->data->tx_queues[tx_queue_id];
4697 : :
4698 [ # # ]: 0 : if (!hns3_dev_get_support(hw, INDEP_TXRX))
4699 : : return -ENOTSUP;
4700 : :
4701 : 0 : rte_spinlock_lock(&hw->lock);
4702 : :
4703 [ # # ]: 0 : if (rte_atomic_load_explicit(&hw->reset.resetting, rte_memory_order_relaxed)) {
4704 : 0 : hns3_err(hw, "fail to stop Tx queue during resetting.");
4705 : : rte_spinlock_unlock(&hw->lock);
4706 : 0 : return -EIO;
4707 : : }
4708 : :
4709 : : hns3_enable_txq(txq, false);
4710 : 0 : hns3_tx_queue_release_mbufs(txq);
4711 : : /*
4712 : : * All the mbufs in sw_ring are released and all the pointers in sw_ring
4713 : : * are set to NULL. If this queue is still called by upper layer,
4714 : : * residual SW status of this txq may cause these pointers in sw_ring
4715 : : * which have been set to NULL to be released again. To avoid it,
4716 : : * reinit the txq.
4717 : : */
4718 : 0 : hns3_init_txq(txq);
4719 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
4720 : : rte_spinlock_unlock(&hw->lock);
4721 : :
4722 : 0 : return 0;
4723 : : }
4724 : :
4725 : : static int
4726 : 0 : hns3_tx_done_cleanup_full(struct hns3_tx_queue *txq, uint32_t free_cnt)
4727 : : {
4728 : 0 : uint16_t next_to_clean = txq->next_to_clean;
4729 : 0 : uint16_t next_to_use = txq->next_to_use;
4730 : 0 : uint16_t tx_bd_ready = txq->tx_bd_ready;
4731 : 0 : struct hns3_entry *tx_pkt = &txq->sw_ring[next_to_clean];
4732 : 0 : struct hns3_desc *desc = &txq->tx_ring[next_to_clean];
4733 : : uint32_t idx;
4734 : :
4735 [ # # # # ]: 0 : if (free_cnt == 0 || free_cnt > txq->nb_tx_desc)
4736 : 0 : free_cnt = txq->nb_tx_desc;
4737 : :
4738 [ # # ]: 0 : for (idx = 0; idx < free_cnt; idx++) {
4739 [ # # ]: 0 : if (next_to_clean == next_to_use)
4740 : : break;
4741 [ # # ]: 0 : if (desc->tx.tp_fe_sc_vld_ra_ri &
4742 : : rte_cpu_to_le_16(BIT(HNS3_TXD_VLD_B)))
4743 : : break;
4744 [ # # ]: 0 : if (tx_pkt->mbuf != NULL) {
4745 : : rte_pktmbuf_free_seg(tx_pkt->mbuf);
4746 : 0 : tx_pkt->mbuf = NULL;
4747 : : }
4748 : 0 : next_to_clean++;
4749 : 0 : tx_bd_ready++;
4750 : 0 : tx_pkt++;
4751 : 0 : desc++;
4752 [ # # ]: 0 : if (next_to_clean == txq->nb_tx_desc) {
4753 : 0 : tx_pkt = txq->sw_ring;
4754 : 0 : desc = txq->tx_ring;
4755 : : next_to_clean = 0;
4756 : : }
4757 : : }
4758 : :
4759 [ # # ]: 0 : if (idx > 0) {
4760 : 0 : txq->next_to_clean = next_to_clean;
4761 : 0 : txq->tx_bd_ready = tx_bd_ready;
4762 : : }
4763 : :
4764 : 0 : return (int)idx;
4765 : : }
4766 : :
4767 : : int
4768 : 0 : hns3_tx_done_cleanup(void *txq, uint32_t free_cnt)
4769 : : {
4770 : : struct hns3_tx_queue *q = (struct hns3_tx_queue *)txq;
4771 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[q->port_id];
4772 : :
4773 [ # # ]: 0 : if (dev->tx_pkt_burst == hns3_xmit_pkts)
4774 : 0 : return hns3_tx_done_cleanup_full(q, free_cnt);
4775 [ # # ]: 0 : else if (dev->tx_pkt_burst == rte_eth_pkt_burst_dummy)
4776 : : return 0;
4777 : : else
4778 : 0 : return -ENOTSUP;
4779 : : }
4780 : :
4781 : : int
4782 : 0 : hns3_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
4783 : : {
4784 : : volatile struct hns3_desc *rxdp;
4785 : : struct hns3_rx_queue *rxq;
4786 : : struct rte_eth_dev *dev;
4787 : : uint32_t bd_base_info;
4788 : : uint16_t desc_id;
4789 : :
4790 : : rxq = (struct hns3_rx_queue *)rx_queue;
4791 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc)
4792 : : return -EINVAL;
4793 : :
4794 : 0 : desc_id = (rxq->next_to_use + offset) % rxq->nb_rx_desc;
4795 : 0 : rxdp = &rxq->rx_ring[desc_id];
4796 : 0 : bd_base_info = rte_le_to_cpu_32(rxdp->rx.bd_base_info);
4797 : 0 : dev = &rte_eth_devices[rxq->port_id];
4798 [ # # # # ]: 0 : if (dev->rx_pkt_burst == hns3_recv_pkts_simple ||
4799 : : dev->rx_pkt_burst == hns3_recv_scattered_pkts) {
4800 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - rxq->rx_free_hold)
4801 : : return RTE_ETH_RX_DESC_UNAVAIL;
4802 [ # # # # ]: 0 : } else if (dev->rx_pkt_burst == hns3_recv_pkts_vec ||
4803 : : dev->rx_pkt_burst == hns3_recv_pkts_vec_sve) {
4804 [ # # ]: 0 : if (offset >= rxq->nb_rx_desc - rxq->rx_rearm_nb)
4805 : : return RTE_ETH_RX_DESC_UNAVAIL;
4806 : : } else {
4807 : : return RTE_ETH_RX_DESC_UNAVAIL;
4808 : : }
4809 : :
4810 [ # # ]: 0 : if (!(bd_base_info & BIT(HNS3_RXD_VLD_B)))
4811 : : return RTE_ETH_RX_DESC_AVAIL;
4812 : : else
4813 : 0 : return RTE_ETH_RX_DESC_DONE;
4814 : : }
4815 : :
4816 : : int
4817 : 0 : hns3_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
4818 : : {
4819 : : volatile struct hns3_desc *txdp;
4820 : : struct hns3_tx_queue *txq;
4821 : : struct rte_eth_dev *dev;
4822 : : uint16_t desc_id;
4823 : :
4824 : : txq = (struct hns3_tx_queue *)tx_queue;
4825 [ # # ]: 0 : if (offset >= txq->nb_tx_desc)
4826 : : return -EINVAL;
4827 : :
4828 : 0 : dev = &rte_eth_devices[txq->port_id];
4829 [ # # # # ]: 0 : if (dev->tx_pkt_burst != hns3_xmit_pkts_simple &&
4830 [ # # ]: 0 : dev->tx_pkt_burst != hns3_xmit_pkts &&
4831 [ # # ]: 0 : dev->tx_pkt_burst != hns3_xmit_pkts_vec_sve &&
4832 : : dev->tx_pkt_burst != hns3_xmit_pkts_vec)
4833 : : return RTE_ETH_TX_DESC_UNAVAIL;
4834 : :
4835 : 0 : desc_id = (txq->next_to_use + offset) % txq->nb_tx_desc;
4836 : 0 : txdp = &txq->tx_ring[desc_id];
4837 [ # # ]: 0 : if (txdp->tx.tp_fe_sc_vld_ra_ri & rte_cpu_to_le_16(BIT(HNS3_TXD_VLD_B)))
4838 : : return RTE_ETH_TX_DESC_FULL;
4839 : : else
4840 : 0 : return RTE_ETH_TX_DESC_DONE;
4841 : : }
4842 : :
4843 : : uint32_t
4844 : 0 : hns3_rx_queue_count(void *rx_queue)
4845 : : {
4846 : : /*
4847 : : * Number of BDs that have been processed by the driver
4848 : : * but have not been notified to the hardware.
4849 : : */
4850 : : uint32_t driver_hold_bd_num;
4851 : : struct hns3_rx_queue *rxq;
4852 : : const struct rte_eth_dev *dev;
4853 : : uint32_t fbd_num;
4854 : :
4855 : : rxq = rx_queue;
4856 : 0 : dev = &rte_eth_devices[rxq->port_id];
4857 : :
4858 : 0 : fbd_num = hns3_read_dev(rxq, HNS3_RING_RX_FBDNUM_REG);
4859 [ # # # # ]: 0 : if (dev->rx_pkt_burst == hns3_recv_pkts_vec ||
4860 : : dev->rx_pkt_burst == hns3_recv_pkts_vec_sve)
4861 : 0 : driver_hold_bd_num = rxq->rx_rearm_nb;
4862 : : else
4863 : 0 : driver_hold_bd_num = rxq->rx_free_hold;
4864 : :
4865 [ # # ]: 0 : if (fbd_num <= driver_hold_bd_num)
4866 : : return 0;
4867 : : else
4868 : 0 : return fbd_num - driver_hold_bd_num;
4869 : : }
4870 : :
4871 : : void
4872 : 0 : hns3_enable_rxd_adv_layout(struct hns3_hw *hw)
4873 : : {
4874 : : /*
4875 : : * If the hardware support rxd advanced layout, then driver enable it
4876 : : * default.
4877 : : */
4878 [ # # ]: 0 : if (hns3_dev_get_support(hw, RXD_ADV_LAYOUT))
4879 : 0 : hns3_write_dev(hw, HNS3_RXD_ADV_LAYOUT_EN_REG, 1);
4880 : 0 : }
4881 : :
4882 : : void
4883 : 0 : hns3_stop_tx_datapath(struct rte_eth_dev *dev)
4884 : : {
4885 : 0 : dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
4886 : 0 : dev->tx_pkt_prepare = NULL;
4887 : : hns3_eth_dev_fp_ops_config(dev);
4888 : :
4889 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY)
4890 : : return;
4891 : :
4892 : : rte_wmb();
4893 : : /* Disable tx datapath on secondary process. */
4894 : 0 : hns3_mp_req_stop_tx(dev);
4895 : : /* Prevent crashes when queues are still in use. */
4896 : 0 : rte_delay_ms(dev->data->nb_tx_queues);
4897 : : }
4898 : :
4899 : : void
4900 : 0 : hns3_start_tx_datapath(struct rte_eth_dev *dev)
4901 : : {
4902 [ # # ]: 0 : dev->tx_pkt_burst = hns3_get_tx_function(dev);
4903 : 0 : dev->tx_pkt_prepare = hns3_get_tx_prepare(dev);
4904 : : hns3_eth_dev_fp_ops_config(dev);
4905 : :
4906 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY)
4907 : : return;
4908 : :
4909 : 0 : hns3_mp_req_start_tx(dev);
4910 : : }
4911 : :
4912 : : void
4913 : 0 : hns3_stop_rxtx_datapath(struct rte_eth_dev *dev)
4914 : : {
4915 : 0 : struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
4916 : :
4917 : 0 : hns3_set_rxtx_function(dev);
4918 : :
4919 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY)
4920 : : return;
4921 : :
4922 : : rte_wmb();
4923 : : /* Disable datapath on secondary process. */
4924 : 0 : hns3_mp_req_stop_rxtx(dev);
4925 : : /* Prevent crashes when queues are still in use. */
4926 : 0 : rte_delay_ms(hw->cfg_max_queues);
4927 : : }
4928 : :
4929 : : void
4930 : 0 : hns3_start_rxtx_datapath(struct rte_eth_dev *dev)
4931 : : {
4932 : 0 : hns3_set_rxtx_function(dev);
4933 : :
4934 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY)
4935 : : return;
4936 : :
4937 : 0 : hns3_mp_req_start_rxtx(dev);
4938 : : }
4939 : :
4940 : : static int
4941 : 0 : hns3_monitor_callback(const uint64_t value,
4942 : : const uint64_t arg[RTE_POWER_MONITOR_OPAQUE_SZ] __rte_unused)
4943 : : {
4944 : : const uint64_t vld = rte_le_to_cpu_32(BIT(HNS3_RXD_VLD_B));
4945 [ # # ]: 0 : return (value & vld) == vld ? -1 : 0;
4946 : : }
4947 : :
4948 : : int
4949 : 0 : hns3_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc)
4950 : : {
4951 : : struct hns3_rx_queue *rxq = rx_queue;
4952 : 0 : struct hns3_desc *rxdp = &rxq->rx_ring[rxq->next_to_use];
4953 : :
4954 : 0 : pmc->addr = &rxdp->rx.bd_base_info;
4955 : 0 : pmc->fn = hns3_monitor_callback;
4956 : 0 : pmc->size = sizeof(uint32_t);
4957 : :
4958 : 0 : return 0;
4959 : : }
|