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