Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018-2021 HiSilicon Limited.
3 : : */
4 : :
5 : : #ifndef HNS3_RXTX_H
6 : : #define HNS3_RXTX_H
7 : :
8 : : #include <stdint.h>
9 : :
10 : : #include <ethdev_driver.h>
11 : : #include <rte_mbuf_core.h>
12 : : #include <rte_ethdev.h>
13 : : #include <rte_ethdev_core.h>
14 : : #include <rte_io.h>
15 : : #include <rte_mempool.h>
16 : : #include <rte_memzone.h>
17 : :
18 : : #include "hns3_ethdev.h"
19 : :
20 : : #define HNS3_MIN_RING_DESC 64
21 : : #define HNS3_MAX_RING_DESC 32768
22 : : #define HNS3_DEFAULT_RING_DESC 1024
23 : : #define HNS3_ALIGN_RING_DESC 32
24 : : #define HNS3_RING_BASE_ALIGN 128
25 : : #define HNS3_BULK_ALLOC_MBUF_NUM 32
26 : :
27 : : #define HNS3_DEFAULT_RX_FREE_THRESH 32
28 : : #define HNS3_DEFAULT_TX_FREE_THRESH 32
29 : : #define HNS3_DEFAULT_TX_RS_THRESH 32
30 : : #define HNS3_TX_FAST_FREE_AHEAD 64
31 : :
32 : : #define HNS3_DEFAULT_RX_BURST 64
33 : : #if (HNS3_DEFAULT_RX_BURST > 64)
34 : : #error "PMD HNS3: HNS3_DEFAULT_RX_BURST must <= 64\n"
35 : : #endif
36 : : #define HNS3_DEFAULT_DESCS_PER_LOOP 4
37 : : #define HNS3_SVE_DEFAULT_DESCS_PER_LOOP 8
38 : : #if (HNS3_DEFAULT_DESCS_PER_LOOP > HNS3_SVE_DEFAULT_DESCS_PER_LOOP)
39 : : #define HNS3_VECTOR_RX_OFFSET_TABLE_LEN HNS3_DEFAULT_DESCS_PER_LOOP
40 : : #else
41 : : #define HNS3_VECTOR_RX_OFFSET_TABLE_LEN HNS3_SVE_DEFAULT_DESCS_PER_LOOP
42 : : #endif
43 : : #define HNS3_DEFAULT_RXQ_REARM_THRESH 64
44 : : #define HNS3_UINT8_BIT 8
45 : : #define HNS3_UINT16_BIT 16
46 : : #define HNS3_UINT32_BIT 32
47 : :
48 : : #define HNS3_512_BD_BUF_SIZE 512
49 : : #define HNS3_1K_BD_BUF_SIZE 1024
50 : : #define HNS3_2K_BD_BUF_SIZE 2048
51 : : #define HNS3_4K_BD_BUF_SIZE 4096
52 : :
53 : : #define HNS3_MIN_BD_BUF_SIZE HNS3_512_BD_BUF_SIZE
54 : : #define HNS3_MAX_BD_BUF_SIZE HNS3_4K_BD_BUF_SIZE
55 : :
56 : : #define HNS3_BD_SIZE_512_TYPE 0
57 : : #define HNS3_BD_SIZE_1024_TYPE 1
58 : : #define HNS3_BD_SIZE_2048_TYPE 2
59 : : #define HNS3_BD_SIZE_4096_TYPE 3
60 : :
61 : : #define HNS3_RX_FLAG_VLAN_PRESENT 0x1
62 : : #define HNS3_RX_FLAG_L3ID_IPV4 0x0
63 : : #define HNS3_RX_FLAG_L3ID_IPV6 0x1
64 : : #define HNS3_RX_FLAG_L4ID_UDP 0x0
65 : : #define HNS3_RX_FLAG_L4ID_TCP 0x1
66 : :
67 : : #define HNS3_RXD_DMAC_S 0
68 : : #define HNS3_RXD_DMAC_M (0x3 << HNS3_RXD_DMAC_S)
69 : : #define HNS3_RXD_VLAN_S 2
70 : : #define HNS3_RXD_VLAN_M (0x3 << HNS3_RXD_VLAN_S)
71 : : #define HNS3_RXD_L3ID_S 4
72 : : #define HNS3_RXD_L3ID_M (0xf << HNS3_RXD_L3ID_S)
73 : : #define HNS3_RXD_L4ID_S 8
74 : : #define HNS3_RXD_L4ID_M (0xf << HNS3_RXD_L4ID_S)
75 : : #define HNS3_RXD_FRAG_B 12
76 : : #define HNS3_RXD_STRP_TAGP_S 13
77 : : #define HNS3_RXD_STRP_TAGP_M (0x3 << HNS3_RXD_STRP_TAGP_S)
78 : :
79 : : #define HNS3_RXD_L2E_B 16
80 : : #define HNS3_RXD_L3E_B 17
81 : : #define HNS3_RXD_L4E_B 18
82 : : #define HNS3_RXD_TRUNCATE_B 19
83 : : #define HNS3_RXD_HOI_B 20
84 : : #define HNS3_RXD_DOI_B 21
85 : : #define HNS3_RXD_OL3E_B 22
86 : : #define HNS3_RXD_OL4E_B 23
87 : : #define HNS3_RXD_GRO_COUNT_S 24
88 : : #define HNS3_RXD_GRO_COUNT_M (0x3f << HNS3_RXD_GRO_COUNT_S)
89 : : #define HNS3_RXD_GRO_FIXID_B 30
90 : : #define HNS3_RXD_GRO_ECN_B 31
91 : :
92 : : #define HNS3_RXD_ODMAC_S 0
93 : : #define HNS3_RXD_ODMAC_M (0x3 << HNS3_RXD_ODMAC_S)
94 : : #define HNS3_RXD_OVLAN_S 2
95 : : #define HNS3_RXD_OVLAN_M (0x3 << HNS3_RXD_OVLAN_S)
96 : : #define HNS3_RXD_OL3ID_S 4
97 : : #define HNS3_RXD_OL3ID_M (0xf << HNS3_RXD_OL3ID_S)
98 : : #define HNS3_RXD_OL4ID_S 8
99 : : #define HNS3_RXD_OL4ID_M (0xf << HNS3_RXD_OL4ID_S)
100 : : #define HNS3_RXD_PTYPE_S 4
101 : : #define HNS3_RXD_PTYPE_M (0xff << HNS3_RXD_PTYPE_S)
102 : : #define HNS3_RXD_FBHI_S 12
103 : : #define HNS3_RXD_FBHI_M (0x3 << HNS3_RXD_FBHI_S)
104 : : #define HNS3_RXD_FBLI_S 14
105 : : #define HNS3_RXD_FBLI_M (0x3 << HNS3_RXD_FBLI_S)
106 : :
107 : : #define HNS3_RXD_BDTYPE_S 0
108 : : #define HNS3_RXD_BDTYPE_M (0xf << HNS3_RXD_BDTYPE_S)
109 : : #define HNS3_RXD_VLD_B 4
110 : : #define HNS3_RXD_UDP0_B 5
111 : : #define HNS3_RXD_EXTEND_B 7
112 : : #define HNS3_RXD_FE_B 8
113 : : #define HNS3_RXD_LUM_B 9
114 : : #define HNS3_RXD_CRCP_B 10
115 : : #define HNS3_RXD_L3L4P_B 11
116 : :
117 : : #define HNS3_RXD_TS_VLD_B 14
118 : : #define HNS3_RXD_GRO_SIZE_S 16
119 : : #define HNS3_RXD_GRO_SIZE_M (0x3fff << HNS3_RXD_GRO_SIZE_S)
120 : :
121 : : #define HNS3_TXD_L3T_S 0
122 : : #define HNS3_TXD_L3T_M (0x3 << HNS3_TXD_L3T_S)
123 : : #define HNS3_TXD_L4T_S 2
124 : : #define HNS3_TXD_L4T_M (0x3 << HNS3_TXD_L4T_S)
125 : : #define HNS3_TXD_L3CS_B 4
126 : : #define HNS3_TXD_L4CS_B 5
127 : : #define HNS3_TXD_VLAN_B 6
128 : : #define HNS3_TXD_TSO_B 7
129 : :
130 : : #define HNS3_TXD_L2LEN_S 8
131 : : #define HNS3_TXD_L2LEN_M (0xff << HNS3_TXD_L2LEN_S)
132 : : #define HNS3_TXD_L3LEN_S 16
133 : : #define HNS3_TXD_L3LEN_M (0xff << HNS3_TXD_L3LEN_S)
134 : : #define HNS3_TXD_L4LEN_S 24
135 : : #define HNS3_TXD_L4LEN_M (0xffUL << HNS3_TXD_L4LEN_S)
136 : :
137 : : #define HNS3_TXD_L4_START_S 8
138 : : #define HNS3_TXD_L4_START_M (0xffff << HNS3_TXD_L4_START_S)
139 : :
140 : : #define HNS3_TXD_OL3T_S 0
141 : : #define HNS3_TXD_OL3T_M (0x3 << HNS3_TXD_OL3T_S)
142 : : #define HNS3_TXD_OVLAN_B 2
143 : : #define HNS3_TXD_MACSEC_B 3
144 : : #define HNS3_TXD_TUNTYPE_S 4
145 : : #define HNS3_TXD_TUNTYPE_M (0xf << HNS3_TXD_TUNTYPE_S)
146 : :
147 : : #define HNS3_TXD_L4_CKS_OFFSET_S 8
148 : : #define HNS3_TXD_L4_CKS_OFFSET_M (0xffff << HNS3_TXD_L4_CKS_OFFSET_S)
149 : :
150 : : #define HNS3_TXD_BDTYPE_S 0
151 : : #define HNS3_TXD_BDTYPE_M (0xf << HNS3_TXD_BDTYPE_S)
152 : : #define HNS3_TXD_FE_B 4
153 : : #define HNS3_TXD_SC_S 5
154 : : #define HNS3_TXD_SC_M (0x3 << HNS3_TXD_SC_S)
155 : : #define HNS3_TXD_EXTEND_B 7
156 : : #define HNS3_TXD_VLD_B 8
157 : : #define HNS3_TXD_RI_B 9
158 : : #define HNS3_TXD_RA_B 10
159 : : #define HNS3_TXD_TSYN_B 11
160 : : #define HNS3_TXD_DECTTL_S 12
161 : : #define HNS3_TXD_DECTTL_M (0xf << HNS3_TXD_DECTTL_S)
162 : :
163 : : #define HNS3_TXD_MSS_S 0
164 : : #define HNS3_TXD_MSS_M (0x3fff << HNS3_TXD_MSS_S)
165 : :
166 : : #define HNS3_TXD_CKST_B 14
167 : :
168 : : #define HNS3_TXD_OL4CS_B 22
169 : : #define HNS3_L2_LEN_UNIT 1UL
170 : : #define HNS3_L3_LEN_UNIT 2UL
171 : : #define HNS3_L4_LEN_UNIT 2UL
172 : : #define HNS3_SIMPLE_BD_UNIT 1UL
173 : :
174 : : #define HNS3_TXD_DEFAULT_BDTYPE 0
175 : : #define HNS3_TXD_VLD_CMD (0x1 << HNS3_TXD_VLD_B)
176 : : #define HNS3_TXD_FE_CMD (0x1 << HNS3_TXD_FE_B)
177 : : #define HNS3_TXD_DEFAULT_VLD_FE_BDTYPE \
178 : : (HNS3_TXD_VLD_CMD | HNS3_TXD_FE_CMD | HNS3_TXD_DEFAULT_BDTYPE)
179 : : #define HNS3_TXD_SEND_SIZE_SHIFT 16
180 : :
181 : : enum hns3_pkt_l2t_type {
182 : : HNS3_L2_TYPE_UNICAST,
183 : : HNS3_L2_TYPE_MULTICAST,
184 : : HNS3_L2_TYPE_BROADCAST,
185 : : HNS3_L2_TYPE_INVALID,
186 : : };
187 : :
188 : : enum hns3_pkt_l3t_type {
189 : : HNS3_L3T_NONE,
190 : : HNS3_L3T_IPV6,
191 : : HNS3_L3T_IPV4,
192 : : HNS3_L3T_RESERVED
193 : : };
194 : :
195 : : enum hns3_pkt_l4t_type {
196 : : HNS3_L4T_UNKNOWN,
197 : : HNS3_L4T_TCP,
198 : : HNS3_L4T_UDP,
199 : : HNS3_L4T_SCTP
200 : : };
201 : :
202 : : enum hns3_pkt_ol3t_type {
203 : : HNS3_OL3T_NONE,
204 : : HNS3_OL3T_IPV6,
205 : : HNS3_OL3T_IPV4_NO_CSUM,
206 : : HNS3_OL3T_IPV4_CSUM
207 : : };
208 : :
209 : : enum hns3_pkt_tun_type {
210 : : HNS3_TUN_NONE,
211 : : HNS3_TUN_MAC_IN_UDP,
212 : : HNS3_TUN_NVGRE,
213 : : HNS3_TUN_OTHER
214 : : };
215 : :
216 : : /* hardware spec ring buffer format */
217 : : struct hns3_desc {
218 : : union {
219 : : uint64_t addr;
220 : : uint64_t timestamp;
221 : :
222 : : struct {
223 : : uint32_t addr0;
224 : : uint32_t addr1;
225 : : };
226 : : };
227 : : union {
228 : : struct {
229 : : uint16_t vlan_tag;
230 : : uint16_t send_size;
231 : : union {
232 : : /*
233 : : * L3T | L4T | L3CS | L4CS | VLAN | TSO |
234 : : * L2_LEN
235 : : */
236 : : uint32_t type_cs_vlan_tso_len;
237 : : struct {
238 : : uint8_t type_cs_vlan_tso;
239 : : uint8_t l2_len;
240 : : uint8_t l3_len;
241 : : uint8_t l4_len;
242 : : };
243 : : };
244 : : uint16_t outer_vlan_tag;
245 : : uint16_t tv;
246 : : union {
247 : : /* OL3T | OVALAN | MACSEC */
248 : : uint32_t ol_type_vlan_len_msec;
249 : : struct {
250 : : uint8_t ol_type_vlan_msec;
251 : : uint8_t ol2_len;
252 : : uint8_t ol3_len;
253 : : uint8_t ol4_len;
254 : : };
255 : : };
256 : :
257 : : uint32_t paylen_fd_dop_ol4cs;
258 : : uint16_t tp_fe_sc_vld_ra_ri;
259 : : uint16_t ckst_mss;
260 : : } tx;
261 : :
262 : : struct {
263 : : uint32_t l234_info;
264 : : uint16_t pkt_len;
265 : : uint16_t size;
266 : : uint32_t rss_hash;
267 : : uint16_t fd_id;
268 : : uint16_t vlan_tag;
269 : : union {
270 : : uint32_t ol_info;
271 : : struct {
272 : : uint16_t o_dm_vlan_id_fb;
273 : : uint16_t ot_vlan_tag;
274 : : };
275 : : };
276 : : union {
277 : : uint32_t bd_base_info;
278 : : struct {
279 : : uint16_t bdtype_vld_udp0;
280 : : uint16_t fe_lum_crcp_l3l4p;
281 : : };
282 : : };
283 : : } rx;
284 : : };
285 : : } __rte_packed;
286 : :
287 : : struct hns3_entry {
288 : : struct rte_mbuf *mbuf;
289 : : };
290 : :
291 : : struct hns3_rx_basic_stats {
292 : : uint64_t packets;
293 : : uint64_t bytes;
294 : : uint64_t errors;
295 : : };
296 : :
297 : : struct hns3_rx_dfx_stats {
298 : : uint64_t l3_csum_errors;
299 : : uint64_t l4_csum_errors;
300 : : uint64_t ol3_csum_errors;
301 : : uint64_t ol4_csum_errors;
302 : : };
303 : :
304 : : struct hns3_rx_bd_errors_stats {
305 : : uint64_t l2_errors;
306 : : uint64_t pkt_len_errors;
307 : : };
308 : :
309 : : struct hns3_rx_queue {
310 : : volatile void *io_head_reg;
311 : : struct hns3_ptype_table *ptype_tbl;
312 : : struct rte_mempool *mb_pool;
313 : : struct hns3_desc *rx_ring;
314 : : struct hns3_entry *sw_ring;
315 : :
316 : : uint16_t port_id;
317 : : uint16_t nb_rx_desc;
318 : : /*
319 : : * threshold for the number of BDs waited to passed to hardware. If the
320 : : * number exceeds the threshold, driver will pass these BDs to hardware.
321 : : */
322 : : uint16_t rx_free_thresh;
323 : : uint16_t next_to_use; /* index of next BD to be polled */
324 : : uint16_t rx_free_hold; /* num of BDs waited to passed to hardware */
325 : : uint16_t rx_rearm_start; /* index of BD that driver re-arming from */
326 : : uint16_t rx_rearm_nb; /* number of remaining BDs to be re-armed */
327 : :
328 : : /* 4 if RTE_ETH_RX_OFFLOAD_KEEP_CRC offload set, 0 otherwise */
329 : : uint8_t crc_len;
330 : :
331 : : /*
332 : : * Indicate whether ignore the outer VLAN field in the Rx BD reported
333 : : * by the Hardware. Because the outer VLAN is the PVID if the PVID is
334 : : * set for some version of hardware network engine whose vlan mode is
335 : : * HNS3_SW_SHIFT_AND_DISCARD_MODE, such as kunpeng 920. And this VLAN
336 : : * should not be transitted to the upper-layer application. For hardware
337 : : * network engine whose vlan mode is HNS3_HW_SHIFT_AND_DISCARD_MODE,
338 : : * such as kunpeng 930, PVID will not be reported to the BDs. So, PMD
339 : : * does not need to perform PVID-related operation in Rx. At this
340 : : * point, the pvid_sw_discard_en will be false.
341 : : */
342 : : uint8_t pvid_sw_discard_en:1;
343 : : uint8_t ptype_en:1; /* indicate if the ptype field enabled */
344 : :
345 : : uint64_t mbuf_initializer; /* value to init mbufs used with vector rx */
346 : : /* offset_table: used for vector, to solve execute re-order problem */
347 : : uint8_t offset_table[HNS3_VECTOR_RX_OFFSET_TABLE_LEN + 1];
348 : :
349 : : uint16_t bulk_mbuf_num; /* indicate bulk_mbuf valid nums */
350 : :
351 : : struct hns3_rx_basic_stats basic_stats;
352 : :
353 : : struct rte_mbuf *pkt_first_seg;
354 : : struct rte_mbuf *pkt_last_seg;
355 : :
356 : : struct rte_mbuf *bulk_mbuf[HNS3_BULK_ALLOC_MBUF_NUM];
357 : :
358 : : /* DFX statistics that driver does not need to discard packets */
359 : : struct hns3_rx_dfx_stats dfx_stats;
360 : : /* Error statistics that driver needs to discard packets */
361 : : struct hns3_rx_bd_errors_stats err_stats;
362 : :
363 : : struct rte_mbuf fake_mbuf; /* fake mbuf used with vector rx */
364 : :
365 : : /*
366 : : * The following fields are not accessed in the I/O path, so they are
367 : : * placed at the end.
368 : : */
369 : : alignas(RTE_CACHE_LINE_SIZE) void *io_base;
370 : : struct hns3_adapter *hns;
371 : : uint64_t rx_ring_phys_addr; /* RX ring DMA address */
372 : : const struct rte_memzone *mz;
373 : :
374 : : uint16_t queue_id;
375 : : uint16_t rx_buf_len;
376 : :
377 : : bool configured; /* indicate if rx queue has been configured */
378 : : bool rx_deferred_start; /* don't start this queue in dev start */
379 : : bool enabled; /* indicate if Rx queue has been enabled */
380 : : };
381 : :
382 : : struct hns3_tx_basic_stats {
383 : : uint64_t packets;
384 : : uint64_t bytes;
385 : : };
386 : :
387 : : /*
388 : : * The following items are used for the abnormal errors statistics in
389 : : * the Tx datapath. When upper level application calls the
390 : : * rte_eth_tx_burst API function to send multiple packets at a time with
391 : : * burst mode based on hns3 network engine, there are some abnormal
392 : : * conditions that cause the driver to fail to operate the hardware to
393 : : * send packets correctly.
394 : : * Note: When using burst mode to call the rte_eth_tx_burst API function
395 : : * to send multiple packets at a time. When the first abnormal error is
396 : : * detected, add one to the relevant error statistics item, and then
397 : : * exit the loop of sending multiple packets of the function. That is to
398 : : * say, even if there are multiple packets in which abnormal errors may
399 : : * be detected in the burst, the relevant error statistics in the driver
400 : : * will only be increased by one.
401 : : * The detail description of the Tx abnormal errors statistic items as
402 : : * below:
403 : : * - over_length_pkt_cnt
404 : : * Total number of greater than HNS3_MAX_FRAME_LEN the driver
405 : : * supported.
406 : : *
407 : : * - exceed_limit_bd_pkt_cnt
408 : : * Total number of exceeding the hardware limited bd which process
409 : : * a packet needed bd numbers.
410 : : *
411 : : * - exceed_limit_bd_reassem_fail
412 : : * Total number of exceeding the hardware limited bd fail which
413 : : * process a packet needed bd numbers and reassemble fail.
414 : : *
415 : : * - unsupported_tunnel_pkt_cnt
416 : : * Total number of unsupported tunnel packet. The unsupported tunnel
417 : : * type: vxlan_gpe, gtp, ipip and MPLSINUDP, MPLSINUDP is a packet
418 : : * with MPLS-in-UDP RFC 7510 header.
419 : : *
420 : : * - queue_full_cnt
421 : : * Total count which the available bd numbers in current bd queue is
422 : : * less than the bd numbers with the pkt process needed.
423 : : *
424 : : * - pkt_padding_fail_cnt
425 : : * Total count which the packet length is less than minimum packet
426 : : * length(struct hns3_tx_queue::min_tx_pkt_len) supported by
427 : : * hardware in Tx direction and fail to be appended with 0.
428 : : */
429 : : struct hns3_tx_dfx_stats {
430 : : uint64_t over_length_pkt_cnt;
431 : : uint64_t exceed_limit_bd_pkt_cnt;
432 : : uint64_t exceed_limit_bd_reassem_fail;
433 : : uint64_t unsupported_tunnel_pkt_cnt;
434 : : uint64_t queue_full_cnt;
435 : : uint64_t pkt_padding_fail_cnt;
436 : : };
437 : :
438 : : struct hns3_tx_queue {
439 : : /* The io_tail_reg is write-only if working in tx push mode */
440 : : volatile void *io_tail_reg;
441 : : struct hns3_desc *tx_ring;
442 : : struct hns3_entry *sw_ring;
443 : :
444 : : uint16_t nb_tx_desc;
445 : : /*
446 : : * index of next BD whose corresponding rte_mbuf can be released by
447 : : * driver.
448 : : */
449 : : uint16_t next_to_clean;
450 : : /* index of next BD to be filled by driver to send packet */
451 : : uint16_t next_to_use;
452 : : /* num of remaining BDs ready to be filled by driver to send packet */
453 : : uint16_t tx_bd_ready;
454 : :
455 : : /* threshold for free tx buffer if available BDs less than this value */
456 : : uint16_t tx_free_thresh;
457 : :
458 : : /*
459 : : * The minimum length of the packet supported by hardware in the Tx
460 : : * direction.
461 : : */
462 : : uint8_t min_tx_pkt_len;
463 : :
464 : : uint8_t max_non_tso_bd_num; /* max BD number of one non-TSO packet */
465 : :
466 : : /*
467 : : * tso mode.
468 : : * value range:
469 : : * HNS3_TSO_SW_CAL_PSEUDO_H_CSUM/HNS3_TSO_HW_CAL_PSEUDO_H_CSUM
470 : : *
471 : : * - HNS3_TSO_SW_CAL_PSEUDO_H_CSUM
472 : : * In this mode, because of the hardware constraint, network driver
473 : : * software need erase the L4 len value of the TCP pseudo header
474 : : * and recalculate the TCP pseudo header checksum of packets that
475 : : * need TSO.
476 : : *
477 : : * - HNS3_TSO_HW_CAL_PSEUDO_H_CSUM
478 : : * In this mode, hardware support recalculate the TCP pseudo header
479 : : * checksum of packets that need TSO, so network driver software
480 : : * not need to recalculate it.
481 : : */
482 : : uint16_t tso_mode:1;
483 : : /*
484 : : * udp checksum mode.
485 : : * value range:
486 : : * HNS3_SPECIAL_PORT_HW_CKSUM_MODE/HNS3_SPECIAL_PORT_SW_CKSUM_MODE
487 : : *
488 : : * - HNS3_SPECIAL_PORT_SW_CKSUM_MODE
489 : : * In this mode, HW can not do checksum for special UDP port like
490 : : * 4789, 4790, 6081 for non-tunnel UDP packets and UDP tunnel
491 : : * packets without the RTE_MBUF_F_TX_TUNEL_MASK in the mbuf. So, PMD need
492 : : * do the checksum for these packets to avoid a checksum error.
493 : : *
494 : : * - HNS3_SPECIAL_PORT_HW_CKSUM_MODE
495 : : * In this mode, HW does not have the preceding problems and can
496 : : * directly calculate the checksum of these UDP packets.
497 : : */
498 : : uint16_t udp_cksum_mode:1;
499 : :
500 : : /* check whether the simple BD mode is supported */
501 : : uint16_t simple_bd_enable:1;
502 : : uint16_t tx_push_enable:1; /* check whether the tx push is enabled */
503 : : /*
504 : : * Indicate whether add the vlan_tci of the mbuf to the inner VLAN field
505 : : * of Tx BD. Because the outer VLAN will always be the PVID when the
506 : : * PVID is set and for some version of hardware network engine whose
507 : : * vlan mode is HNS3_SW_SHIFT_AND_DISCARD_MODE, such as kunpeng 920, the
508 : : * PVID will overwrite the outer VLAN field of Tx BD. For the hardware
509 : : * network engine whose vlan mode is HNS3_HW_SHIFT_AND_DISCARD_MODE,
510 : : * such as kunpeng 930, if the PVID is set, the hardware will shift the
511 : : * VLAN field automatically. So, PMD does not need to do
512 : : * PVID-related operations in Tx. And pvid_sw_shift_en will be false at
513 : : * this point.
514 : : */
515 : : uint16_t pvid_sw_shift_en:1;
516 : : /* check whether the mbuf fast free offload is enabled */
517 : : uint16_t mbuf_fast_free_en:1;
518 : :
519 : : /*
520 : : * For better performance in tx datapath, releasing mbuf in batches is
521 : : * required.
522 : : * Only checking the VLD bit of the last descriptor in a batch of the
523 : : * thresh descriptors does not mean that these descriptors are all sent
524 : : * by hardware successfully. So we need to check that the VLD bits of
525 : : * all descriptors are cleared. and then free all mbufs in the batch.
526 : : * - tx_rs_thresh
527 : : * Number of mbufs released at a time.
528 : : *
529 : : * - free
530 : : * Tx mbuf free array used for preserving temporarily address of mbuf
531 : : * released back to mempool, when releasing mbuf in batches.
532 : : */
533 : : uint16_t tx_rs_thresh;
534 : : struct rte_mbuf **free;
535 : :
536 : : struct hns3_tx_basic_stats basic_stats;
537 : : struct hns3_tx_dfx_stats dfx_stats;
538 : :
539 : : /*
540 : : * The following fields are not accessed in the I/O path, so they are
541 : : * placed at the end.
542 : : */
543 : : alignas(RTE_CACHE_LINE_SIZE) void *io_base;
544 : : struct hns3_adapter *hns;
545 : : uint64_t tx_ring_phys_addr; /* TX ring DMA address */
546 : : const struct rte_memzone *mz;
547 : :
548 : : uint16_t port_id;
549 : : uint16_t queue_id;
550 : :
551 : : bool configured; /* indicate if tx queue has been configured */
552 : : bool tx_deferred_start; /* don't start this queue in dev start */
553 : : bool enabled; /* indicate if Tx queue has been enabled */
554 : : };
555 : :
556 : : #define RX_BD_LOG(hw, level, rxdp) \
557 : : PMD_RX_LOG(hw, level, "Rx descriptor: " \
558 : : "l234_info=%#x pkt_len=%u size=%u rss_hash=%#x fd_id=%u vlan_tag=%u " \
559 : : "o_dm_vlan_id_fb=%#x ot_vlan_tag=%u bd_base_info=%#x", \
560 : : rte_le_to_cpu_32((rxdp)->rx.l234_info), \
561 : : rte_le_to_cpu_16((rxdp)->rx.pkt_len), \
562 : : rte_le_to_cpu_16((rxdp)->rx.size), \
563 : : rte_le_to_cpu_32((rxdp)->rx.rss_hash), \
564 : : rte_le_to_cpu_16((rxdp)->rx.fd_id), \
565 : : rte_le_to_cpu_16((rxdp)->rx.vlan_tag), \
566 : : rte_le_to_cpu_16((rxdp)->rx.o_dm_vlan_id_fb), \
567 : : rte_le_to_cpu_16((rxdp)->rx.ot_vlan_tag), \
568 : : rte_le_to_cpu_32((rxdp)->rx.bd_base_info))
569 : :
570 : : #define TX_BD_LOG(hw, level, txdp) \
571 : : PMD_TX_LOG(hw, level, "Tx descriptor: " \
572 : : "vlan_tag=%u send_size=%u type_cs_vlan_tso_len=%#x outer_vlan_tag=%u " \
573 : : "tv=%#x ol_type_vlan_len_msec=%#x paylen_fd_dop_ol4cs=%#x " \
574 : : "tp_fe_sc_vld_ra_ri=%#x ckst_mss=%u", \
575 : : rte_le_to_cpu_16((txdp)->tx.vlan_tag), \
576 : : rte_le_to_cpu_16((txdp)->tx.send_size), \
577 : : rte_le_to_cpu_32((txdp)->tx.type_cs_vlan_tso_len), \
578 : : rte_le_to_cpu_16((txdp)->tx.outer_vlan_tag), \
579 : : rte_le_to_cpu_16((txdp)->tx.tv), \
580 : : rte_le_to_cpu_32((txdp)->tx.ol_type_vlan_len_msec), \
581 : : rte_le_to_cpu_32((txdp)->tx.paylen_fd_dop_ol4cs), \
582 : : rte_le_to_cpu_16((txdp)->tx.tp_fe_sc_vld_ra_ri), \
583 : : rte_le_to_cpu_16((txdp)->tx.ckst_mss))
584 : :
585 : : #define HNS3_GET_TX_QUEUE_PEND_BD_NUM(txq) \
586 : : ((txq)->nb_tx_desc - 1 - (txq)->tx_bd_ready)
587 : :
588 : : struct hns3_queue_info {
589 : : const char *type; /* point to queue memory name */
590 : : const char *ring_name; /* point to hardware ring name */
591 : : uint16_t idx;
592 : : uint16_t nb_desc;
593 : : unsigned int socket_id;
594 : : };
595 : :
596 : : #define HNS3_TX_CKSUM_OFFLOAD_MASK (RTE_MBUF_F_TX_OUTER_UDP_CKSUM | \
597 : : RTE_MBUF_F_TX_OUTER_IP_CKSUM | \
598 : : RTE_MBUF_F_TX_IP_CKSUM | \
599 : : RTE_MBUF_F_TX_TCP_SEG | \
600 : : RTE_MBUF_F_TX_L4_MASK)
601 : :
602 : : enum hns3_cksum_status {
603 : : HNS3_CKSUM_NONE = 0,
604 : : HNS3_L3_CKSUM_ERR = 1,
605 : : HNS3_L4_CKSUM_ERR = 2,
606 : : HNS3_OUTER_L3_CKSUM_ERR = 4,
607 : : HNS3_OUTER_L4_CKSUM_ERR = 8
608 : : };
609 : :
610 : : extern uint64_t hns3_timestamp_rx_dynflag;
611 : : extern int hns3_timestamp_dynfield_offset;
612 : :
613 : : static inline void
614 : 0 : hns3_rx_set_cksum_flag(struct hns3_rx_queue *rxq,
615 : : struct rte_mbuf *rxm,
616 : : uint32_t l234_info)
617 : : {
618 : : #define HNS3_RXD_CKSUM_ERR_MASK (BIT(HNS3_RXD_L3E_B) | \
619 : : BIT(HNS3_RXD_L4E_B) | \
620 : : BIT(HNS3_RXD_OL3E_B) | \
621 : : BIT(HNS3_RXD_OL4E_B))
622 : :
623 [ # # ]: 0 : if (likely((l234_info & HNS3_RXD_CKSUM_ERR_MASK) == 0)) {
624 : 0 : rxm->ol_flags |= (RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_GOOD);
625 : 0 : return;
626 : : }
627 : :
628 [ # # ]: 0 : if (unlikely(l234_info & BIT(HNS3_RXD_L3E_B))) {
629 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
630 : 0 : rxq->dfx_stats.l3_csum_errors++;
631 : : } else {
632 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
633 : : }
634 : :
635 [ # # ]: 0 : if (unlikely(l234_info & BIT(HNS3_RXD_L4E_B))) {
636 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD;
637 : 0 : rxq->dfx_stats.l4_csum_errors++;
638 : : } else {
639 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
640 : : }
641 : :
642 [ # # ]: 0 : if (unlikely(l234_info & BIT(HNS3_RXD_OL3E_B)))
643 : 0 : rxq->dfx_stats.ol3_csum_errors++;
644 : :
645 [ # # ]: 0 : if (unlikely(l234_info & BIT(HNS3_RXD_OL4E_B))) {
646 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_OUTER_L4_CKSUM_BAD;
647 : 0 : rxq->dfx_stats.ol4_csum_errors++;
648 : : }
649 : : }
650 : :
651 : : static inline int
652 : 0 : hns3_handle_bdinfo(struct hns3_rx_queue *rxq, struct rte_mbuf *rxm,
653 : : uint32_t bd_base_info, uint32_t l234_info)
654 : : {
655 : : #define L2E_TRUNC_ERR_FLAG (BIT(HNS3_RXD_L2E_B) | \
656 : : BIT(HNS3_RXD_TRUNCATE_B))
657 : :
658 : : /*
659 : : * If packet len bigger than mtu when recv with no-scattered algorithm,
660 : : * the first n bd will without FE bit, we need process this situation.
661 : : * Note: we don't need add statistic counter because latest BD which
662 : : * with FE bit will mark HNS3_RXD_L2E_B bit.
663 : : */
664 [ # # ]: 0 : if (unlikely((bd_base_info & BIT(HNS3_RXD_FE_B)) == 0))
665 : : return -EINVAL;
666 : :
667 [ # # # # ]: 0 : if (unlikely((l234_info & L2E_TRUNC_ERR_FLAG) || rxm->pkt_len == 0)) {
668 [ # # ]: 0 : if (l234_info & BIT(HNS3_RXD_L2E_B))
669 : 0 : rxq->err_stats.l2_errors++;
670 : : else
671 : 0 : rxq->err_stats.pkt_len_errors++;
672 : 0 : return -EINVAL;
673 : : }
674 : :
675 [ # # ]: 0 : if (bd_base_info & BIT(HNS3_RXD_L3L4P_B))
676 : 0 : hns3_rx_set_cksum_flag(rxq, rxm, l234_info);
677 : :
678 : : return 0;
679 : : }
680 : :
681 : : static inline uint32_t
682 : 0 : hns3_rx_calc_ptype(struct hns3_rx_queue *rxq, const uint32_t l234_info,
683 : : const uint32_t ol_info)
684 : : {
685 : 0 : const struct hns3_ptype_table * const ptype_tbl = rxq->ptype_tbl;
686 : : uint32_t ol3id, ol4id;
687 : : uint32_t l3id, l4id;
688 : : uint32_t ptype;
689 : :
690 [ # # ]: 0 : if (rxq->ptype_en) {
691 : 0 : ptype = hns3_get_field(ol_info, HNS3_RXD_PTYPE_M,
692 : : HNS3_RXD_PTYPE_S);
693 : 0 : return ptype_tbl->ptype[ptype];
694 : : }
695 : :
696 : 0 : ol4id = hns3_get_field(ol_info, HNS3_RXD_OL4ID_M, HNS3_RXD_OL4ID_S);
697 : 0 : ol3id = hns3_get_field(ol_info, HNS3_RXD_OL3ID_M, HNS3_RXD_OL3ID_S);
698 : 0 : l3id = hns3_get_field(l234_info, HNS3_RXD_L3ID_M, HNS3_RXD_L3ID_S);
699 : 0 : l4id = hns3_get_field(l234_info, HNS3_RXD_L4ID_M, HNS3_RXD_L4ID_S);
700 : :
701 [ # # ]: 0 : if (unlikely(ptype_tbl->ol4table[ol4id]))
702 : 0 : return ptype_tbl->inner_l3table[l3id] |
703 : 0 : ptype_tbl->inner_l4table[l4id] |
704 : 0 : ptype_tbl->ol3table[ol3id] |
705 : : ptype_tbl->ol4table[ol4id];
706 : : else
707 : 0 : return ptype_tbl->l3table[l3id] | ptype_tbl->l4table[l4id];
708 : : }
709 : :
710 : : /*
711 : : * If enable using Tx push feature and also device support it, then use quick
712 : : * doorbell (bar45) to inform the hardware.
713 : : *
714 : : * The other cases (such as: device don't support or user don't enable using)
715 : : * then use normal doorbell (bar23) to inform the hardware.
716 : : */
717 : : static inline void
718 : : hns3_write_txq_tail_reg(struct hns3_tx_queue *txq, uint32_t value)
719 : : {
720 : 0 : rte_io_wmb();
721 [ # # # # ]: 0 : if (txq->tx_push_enable)
722 : 0 : rte_write64_relaxed(rte_cpu_to_le_32(value), txq->io_tail_reg);
723 : : else
724 : 0 : rte_write32_relaxed(rte_cpu_to_le_32(value), txq->io_tail_reg);
725 : : }
726 : :
727 : : void hns3_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t queue_id);
728 : : void hns3_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t queue_id);
729 : : void hns3_free_all_queues(struct rte_eth_dev *dev);
730 : : int hns3_reset_all_tqps(struct hns3_adapter *hns);
731 : : void hns3_dev_all_rx_queue_intr_enable(struct hns3_hw *hw, bool en);
732 : : int hns3_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id);
733 : : int hns3_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id);
734 : : void hns3_enable_all_queues(struct hns3_hw *hw, bool en);
735 : : int hns3_init_queues(struct hns3_adapter *hns, bool reset_queue);
736 : : void hns3_start_tqps(struct hns3_hw *hw);
737 : : void hns3_stop_tqps(struct hns3_hw *hw);
738 : : int hns3_rxq_iterate(struct rte_eth_dev *dev,
739 : : int (*callback)(struct hns3_rx_queue *, void *), void *arg);
740 : : void hns3_dev_release_mbufs(struct hns3_adapter *hns);
741 : : int hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
742 : : unsigned int socket_id,
743 : : const struct rte_eth_rxconf *conf,
744 : : struct rte_mempool *mp);
745 : : int hns3_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
746 : : unsigned int socket_id,
747 : : const struct rte_eth_txconf *conf);
748 : : uint32_t hns3_rx_queue_count(void *rx_queue);
749 : : int hns3_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
750 : : int hns3_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
751 : : int hns3_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
752 : : int hns3_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
753 : : uint16_t hns3_recv_pkts_simple(void *rx_queue, struct rte_mbuf **rx_pkts,
754 : : uint16_t nb_pkts);
755 : : uint16_t hns3_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
756 : : uint16_t nb_pkts);
757 : : uint16_t hns3_recv_pkts_vec(void *__restrict rx_queue,
758 : : struct rte_mbuf **__restrict rx_pkts,
759 : : uint16_t nb_pkts);
760 : : uint16_t hns3_recv_pkts_vec_sve(void *__restrict rx_queue,
761 : : struct rte_mbuf **__restrict rx_pkts,
762 : : uint16_t nb_pkts);
763 : : int hns3_rx_burst_mode_get(struct rte_eth_dev *dev,
764 : : __rte_unused uint16_t queue_id,
765 : : struct rte_eth_burst_mode *mode);
766 : : uint16_t hns3_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
767 : : uint16_t nb_pkts);
768 : : uint16_t hns3_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
769 : : uint16_t nb_pkts);
770 : : uint16_t hns3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
771 : : uint16_t nb_pkts);
772 : : uint16_t hns3_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
773 : : uint16_t nb_pkts);
774 : : uint16_t hns3_xmit_pkts_vec_sve(void *tx_queue, struct rte_mbuf **tx_pkts,
775 : : uint16_t nb_pkts);
776 : : int hns3_tx_burst_mode_get(struct rte_eth_dev *dev,
777 : : __rte_unused uint16_t queue_id,
778 : : struct rte_eth_burst_mode *mode);
779 : : const uint32_t *hns3_dev_supported_ptypes_get(struct rte_eth_dev *dev,
780 : : size_t *no_of_elements);
781 : : void hns3_init_rx_ptype_tble(struct rte_eth_dev *dev);
782 : : void hns3_set_rxtx_function(struct rte_eth_dev *eth_dev);
783 : : uint32_t hns3_get_tqp_intr_reg_offset(uint16_t tqp_intr_id);
784 : : void hns3_set_queue_intr_gl(struct hns3_hw *hw, uint16_t queue_id,
785 : : uint8_t gl_idx, uint16_t gl_value);
786 : : void hns3_set_queue_intr_rl(struct hns3_hw *hw, uint16_t queue_id,
787 : : uint16_t rl_value);
788 : : void hns3_set_queue_intr_ql(struct hns3_hw *hw, uint16_t queue_id,
789 : : uint16_t ql_value);
790 : : int hns3_set_fake_rx_or_tx_queues(struct rte_eth_dev *dev, uint16_t nb_rx_q,
791 : : uint16_t nb_tx_q);
792 : : int hns3_config_gro(struct hns3_hw *hw, bool en);
793 : : int hns3_restore_gro_conf(struct hns3_hw *hw);
794 : : void hns3_update_all_queues_pvid_proc_en(struct hns3_hw *hw);
795 : : void hns3_rx_scattered_reset(struct rte_eth_dev *dev);
796 : : void hns3_rx_scattered_calc(struct rte_eth_dev *dev);
797 : : int hns3_rx_check_vec_support(struct rte_eth_dev *dev);
798 : : int hns3_tx_check_vec_support(struct rte_eth_dev *dev);
799 : : void hns3_rxq_vec_setup(struct hns3_rx_queue *rxq);
800 : : void hns3_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
801 : : struct rte_eth_rxq_info *qinfo);
802 : : void hns3_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
803 : : struct rte_eth_txq_info *qinfo);
804 : : uint32_t hns3_get_tqp_reg_offset(uint16_t queue_id);
805 : : int hns3_start_all_txqs(struct rte_eth_dev *dev);
806 : : int hns3_start_all_rxqs(struct rte_eth_dev *dev);
807 : : void hns3_stop_all_txqs(struct rte_eth_dev *dev);
808 : : void hns3_restore_tqp_enable_state(struct hns3_hw *hw);
809 : : int hns3_tx_done_cleanup(void *txq, uint32_t free_cnt);
810 : : void hns3_enable_rxd_adv_layout(struct hns3_hw *hw);
811 : : int hns3_dev_rx_descriptor_status(void *rx_queue, uint16_t offset);
812 : : int hns3_dev_tx_descriptor_status(void *tx_queue, uint16_t offset);
813 : : void hns3_tx_push_init(struct rte_eth_dev *dev);
814 : : void hns3_stop_tx_datapath(struct rte_eth_dev *dev);
815 : : void hns3_start_tx_datapath(struct rte_eth_dev *dev);
816 : : void hns3_stop_rxtx_datapath(struct rte_eth_dev *dev);
817 : : void hns3_start_rxtx_datapath(struct rte_eth_dev *dev);
818 : : int hns3_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc);
819 : :
820 : : #endif /* HNS3_RXTX_H */
|