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