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