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 : : #define HNS3_KEEP_CRC_OK_MIN_PKT_LEN 60
182 : :
183 : : enum hns3_pkt_l2t_type {
184 : : HNS3_L2_TYPE_UNICAST,
185 : : HNS3_L2_TYPE_MULTICAST,
186 : : HNS3_L2_TYPE_BROADCAST,
187 : : HNS3_L2_TYPE_INVALID,
188 : : };
189 : :
190 : : enum hns3_pkt_l3t_type {
191 : : HNS3_L3T_NONE,
192 : : HNS3_L3T_IPV6,
193 : : HNS3_L3T_IPV4,
194 : : HNS3_L3T_RESERVED
195 : : };
196 : :
197 : : enum hns3_pkt_l4t_type {
198 : : HNS3_L4T_UNKNOWN,
199 : : HNS3_L4T_TCP,
200 : : HNS3_L4T_UDP,
201 : : HNS3_L4T_SCTP
202 : : };
203 : :
204 : : enum hns3_pkt_ol3t_type {
205 : : HNS3_OL3T_NONE,
206 : : HNS3_OL3T_IPV6,
207 : : HNS3_OL3T_IPV4_NO_CSUM,
208 : : HNS3_OL3T_IPV4_CSUM
209 : : };
210 : :
211 : : enum hns3_pkt_tun_type {
212 : : HNS3_TUN_NONE,
213 : : HNS3_TUN_MAC_IN_UDP,
214 : : HNS3_TUN_NVGRE,
215 : : HNS3_TUN_OTHER
216 : : };
217 : :
218 : : /* hardware spec ring buffer format */
219 : : struct __rte_packed_begin hns3_desc {
220 : : union {
221 : : uint64_t addr;
222 : : uint64_t timestamp;
223 : :
224 : : struct {
225 : : uint32_t addr0;
226 : : uint32_t addr1;
227 : : };
228 : : };
229 : : union {
230 : : struct {
231 : : uint16_t vlan_tag;
232 : : uint16_t send_size;
233 : : union {
234 : : /*
235 : : * L3T | L4T | L3CS | L4CS | VLAN | TSO |
236 : : * L2_LEN
237 : : */
238 : : uint32_t type_cs_vlan_tso_len;
239 : : struct {
240 : : uint8_t type_cs_vlan_tso;
241 : : uint8_t l2_len;
242 : : uint8_t l3_len;
243 : : uint8_t l4_len;
244 : : };
245 : : };
246 : : uint16_t outer_vlan_tag;
247 : : uint16_t tv;
248 : : union {
249 : : /* OL3T | OVALAN | MACSEC */
250 : : uint32_t ol_type_vlan_len_msec;
251 : : struct {
252 : : uint8_t ol_type_vlan_msec;
253 : : uint8_t ol2_len;
254 : : uint8_t ol3_len;
255 : : uint8_t ol4_len;
256 : : };
257 : : };
258 : :
259 : : uint32_t paylen_fd_dop_ol4cs;
260 : : uint16_t tp_fe_sc_vld_ra_ri;
261 : : uint16_t ckst_mss;
262 : : } tx;
263 : :
264 : : struct {
265 : : uint32_t l234_info;
266 : : uint16_t pkt_len;
267 : : uint16_t size;
268 : : uint32_t rss_hash;
269 : : uint16_t fd_id;
270 : : uint16_t vlan_tag;
271 : : union {
272 : : uint32_t ol_info;
273 : : struct {
274 : : uint16_t o_dm_vlan_id_fb;
275 : : uint16_t ot_vlan_tag;
276 : : };
277 : : };
278 : : union {
279 : : uint32_t bd_base_info;
280 : : struct {
281 : : uint16_t bdtype_vld_udp0;
282 : : uint16_t fe_lum_crcp_l3l4p;
283 : : };
284 : : };
285 : : } rx;
286 : : };
287 : : } __rte_packed_end;
288 : :
289 : : struct hns3_entry {
290 : : struct rte_mbuf *mbuf;
291 : : };
292 : :
293 : : struct hns3_rx_basic_stats {
294 : : uint64_t packets;
295 : : uint64_t bytes;
296 : : uint64_t errors;
297 : : };
298 : :
299 : : struct hns3_rx_dfx_stats {
300 : : uint64_t l3_csum_errors;
301 : : uint64_t l4_csum_errors;
302 : : uint64_t ol3_csum_errors;
303 : : uint64_t ol4_csum_errors;
304 : : };
305 : :
306 : : struct hns3_rx_bd_errors_stats {
307 : : uint64_t l2_errors;
308 : : uint64_t pkt_len_errors;
309 : : };
310 : :
311 : : struct hns3_rx_queue {
312 : : volatile void *io_head_reg;
313 : : struct hns3_ptype_table *ptype_tbl;
314 : : struct rte_mempool *mb_pool;
315 : : struct hns3_desc *rx_ring;
316 : : struct hns3_entry *sw_ring;
317 : :
318 : : uint16_t port_id;
319 : : uint16_t nb_rx_desc;
320 : : /*
321 : : * threshold for the number of BDs waited to passed to hardware. If the
322 : : * number exceeds the threshold, driver will pass these BDs to hardware.
323 : : */
324 : : uint16_t rx_free_thresh;
325 : : uint16_t next_to_use; /* index of next BD to be polled */
326 : : uint16_t rx_free_hold; /* num of BDs waited to passed to hardware */
327 : : uint16_t rx_rearm_start; /* index of BD that driver re-arming from */
328 : : uint16_t rx_rearm_nb; /* number of remaining BDs to be re-armed */
329 : :
330 : : /* 4 if RTE_ETH_RX_OFFLOAD_KEEP_CRC offload set, 0 otherwise */
331 : : uint8_t crc_len;
332 : :
333 : : /*
334 : : * Indicate whether ignore the outer VLAN field in the Rx BD reported
335 : : * by the Hardware. Because the outer VLAN is the PVID if the PVID is
336 : : * set for some version of hardware network engine whose vlan mode is
337 : : * HNS3_SW_SHIFT_AND_DISCARD_MODE, such as kunpeng 920. And this VLAN
338 : : * should not be transitted to the upper-layer application. For hardware
339 : : * network engine whose vlan mode is HNS3_HW_SHIFT_AND_DISCARD_MODE,
340 : : * such as kunpeng 930, PVID will not be reported to the BDs. So, PMD
341 : : * does not need to perform PVID-related operation in Rx. At this
342 : : * point, the pvid_sw_discard_en will be false.
343 : : */
344 : : uint8_t pvid_sw_discard_en:1;
345 : : uint8_t ptype_en:1; /* indicate if the ptype field enabled */
346 : : uint8_t keep_crc_fail_ptype:2;
347 : :
348 : : uint64_t mbuf_initializer; /* value to init mbufs used with vector rx */
349 : : /* offset_table: used for vector, to solve execute re-order problem */
350 : : uint8_t offset_table[HNS3_VECTOR_RX_OFFSET_TABLE_LEN + 1];
351 : :
352 : : uint16_t bulk_mbuf_num; /* indicate bulk_mbuf valid nums */
353 : :
354 : : struct hns3_rx_basic_stats basic_stats;
355 : :
356 : : struct rte_mbuf *pkt_first_seg;
357 : : struct rte_mbuf *pkt_last_seg;
358 : :
359 : : struct rte_mbuf *bulk_mbuf[HNS3_BULK_ALLOC_MBUF_NUM];
360 : :
361 : : /* DFX statistics that driver does not need to discard packets */
362 : : struct hns3_rx_dfx_stats dfx_stats;
363 : : /* Error statistics that driver needs to discard packets */
364 : : struct hns3_rx_bd_errors_stats err_stats;
365 : :
366 : : struct rte_mbuf fake_mbuf; /* fake mbuf used with vector rx */
367 : :
368 : : /* The CRC context, which is used by software to calculate CRC data. */
369 : : struct rte_net_crc *crc_ctx;
370 : :
371 : : /*
372 : : * The following fields are not accessed in the I/O path, so they are
373 : : * placed at the end.
374 : : */
375 : : alignas(RTE_CACHE_LINE_SIZE) void *io_base;
376 : : struct hns3_adapter *hns;
377 : : uint64_t rx_ring_phys_addr; /* RX ring DMA address */
378 : : const struct rte_memzone *mz;
379 : :
380 : : uint16_t queue_id;
381 : : uint16_t rx_buf_len;
382 : :
383 : : bool configured; /* indicate if rx queue has been configured */
384 : : bool rx_deferred_start; /* don't start this queue in dev start */
385 : : bool enabled; /* indicate if Rx queue has been enabled */
386 : : };
387 : :
388 : : struct hns3_tx_basic_stats {
389 : : uint64_t packets;
390 : : uint64_t bytes;
391 : : };
392 : :
393 : : /*
394 : : * The following items are used for the abnormal errors statistics in
395 : : * the Tx datapath. When upper level application calls the
396 : : * rte_eth_tx_burst API function to send multiple packets at a time with
397 : : * burst mode based on hns3 network engine, there are some abnormal
398 : : * conditions that cause the driver to fail to operate the hardware to
399 : : * send packets correctly.
400 : : * Note: When using burst mode to call the rte_eth_tx_burst API function
401 : : * to send multiple packets at a time. When the first abnormal error is
402 : : * detected, add one to the relevant error statistics item, and then
403 : : * exit the loop of sending multiple packets of the function. That is to
404 : : * say, even if there are multiple packets in which abnormal errors may
405 : : * be detected in the burst, the relevant error statistics in the driver
406 : : * will only be increased by one.
407 : : * The detail description of the Tx abnormal errors statistic items as
408 : : * below:
409 : : * - over_length_pkt_cnt
410 : : * Total number of greater than HNS3_MAX_FRAME_LEN the driver
411 : : * supported.
412 : : *
413 : : * - exceed_limit_bd_pkt_cnt
414 : : * Total number of exceeding the hardware limited bd which process
415 : : * a packet needed bd numbers.
416 : : *
417 : : * - exceed_limit_bd_reassem_fail
418 : : * Total number of exceeding the hardware limited bd fail which
419 : : * process a packet needed bd numbers and reassemble fail.
420 : : *
421 : : * - unsupported_tunnel_pkt_cnt
422 : : * Total number of unsupported tunnel packet. The unsupported tunnel
423 : : * type: vxlan_gpe, gtp, ipip and MPLSINUDP, MPLSINUDP is a packet
424 : : * with MPLS-in-UDP RFC 7510 header.
425 : : *
426 : : * - queue_full_cnt
427 : : * Total count which the available bd numbers in current bd queue is
428 : : * less than the bd numbers with the pkt process needed.
429 : : *
430 : : * - pkt_padding_fail_cnt
431 : : * Total count which the packet length is less than minimum packet
432 : : * length(struct hns3_tx_queue::min_tx_pkt_len) supported by
433 : : * hardware in Tx direction and fail to be appended with 0.
434 : : */
435 : : struct hns3_tx_dfx_stats {
436 : : uint64_t over_length_pkt_cnt;
437 : : uint64_t exceed_limit_bd_pkt_cnt;
438 : : uint64_t exceed_limit_bd_reassem_fail;
439 : : uint64_t unsupported_tunnel_pkt_cnt;
440 : : uint64_t queue_full_cnt;
441 : : uint64_t pkt_padding_fail_cnt;
442 : : };
443 : :
444 : : struct hns3_tx_queue {
445 : : /* The io_tail_reg is write-only if working in tx push mode */
446 : : volatile void *io_tail_reg;
447 : : struct hns3_desc *tx_ring;
448 : : struct hns3_entry *sw_ring;
449 : :
450 : : uint16_t nb_tx_desc;
451 : : /*
452 : : * index of next BD whose corresponding rte_mbuf can be released by
453 : : * driver.
454 : : */
455 : : uint16_t next_to_clean;
456 : : /* index of next BD to be filled by driver to send packet */
457 : : uint16_t next_to_use;
458 : : /* num of remaining BDs ready to be filled by driver to send packet */
459 : : uint16_t tx_bd_ready;
460 : :
461 : : /* threshold for free tx buffer if available BDs less than this value */
462 : : uint16_t tx_free_thresh;
463 : :
464 : : /*
465 : : * The minimum length of the packet supported by hardware in the Tx
466 : : * direction.
467 : : */
468 : : uint8_t min_tx_pkt_len;
469 : :
470 : : uint8_t max_non_tso_bd_num; /* max BD number of one non-TSO packet */
471 : :
472 : : /*
473 : : * tso mode.
474 : : * value range:
475 : : * HNS3_TSO_SW_CAL_PSEUDO_H_CSUM/HNS3_TSO_HW_CAL_PSEUDO_H_CSUM
476 : : *
477 : : * - HNS3_TSO_SW_CAL_PSEUDO_H_CSUM
478 : : * In this mode, because of the hardware constraint, network driver
479 : : * software need erase the L4 len value of the TCP pseudo header
480 : : * and recalculate the TCP pseudo header checksum of packets that
481 : : * need TSO.
482 : : *
483 : : * - HNS3_TSO_HW_CAL_PSEUDO_H_CSUM
484 : : * In this mode, hardware support recalculate the TCP pseudo header
485 : : * checksum of packets that need TSO, so network driver software
486 : : * not need to recalculate it.
487 : : */
488 : : uint16_t tso_mode:1;
489 : : /*
490 : : * udp checksum mode.
491 : : * value range:
492 : : * HNS3_SPECIAL_PORT_HW_CKSUM_MODE/HNS3_SPECIAL_PORT_SW_CKSUM_MODE
493 : : *
494 : : * - HNS3_SPECIAL_PORT_SW_CKSUM_MODE
495 : : * In this mode, HW can not do checksum for special UDP port like
496 : : * 4789, 4790, 6081 for non-tunnel UDP packets and UDP tunnel
497 : : * packets without the RTE_MBUF_F_TX_TUNEL_MASK in the mbuf. So, PMD need
498 : : * do the checksum for these packets to avoid a checksum error.
499 : : *
500 : : * - HNS3_SPECIAL_PORT_HW_CKSUM_MODE
501 : : * In this mode, HW does not have the preceding problems and can
502 : : * directly calculate the checksum of these UDP packets.
503 : : */
504 : : uint16_t udp_cksum_mode:1;
505 : :
506 : : /* check whether the simple BD mode is supported */
507 : : uint16_t simple_bd_enable:1;
508 : : uint16_t tx_push_enable:1; /* check whether the tx push is enabled */
509 : : /*
510 : : * Indicate whether add the vlan_tci of the mbuf to the inner VLAN field
511 : : * of Tx BD. Because the outer VLAN will always be the PVID when the
512 : : * PVID is set and for some version of hardware network engine whose
513 : : * vlan mode is HNS3_SW_SHIFT_AND_DISCARD_MODE, such as kunpeng 920, the
514 : : * PVID will overwrite the outer VLAN field of Tx BD. For the hardware
515 : : * network engine whose vlan mode is HNS3_HW_SHIFT_AND_DISCARD_MODE,
516 : : * such as kunpeng 930, if the PVID is set, the hardware will shift the
517 : : * VLAN field automatically. So, PMD does not need to do
518 : : * PVID-related operations in Tx. And pvid_sw_shift_en will be false at
519 : : * this point.
520 : : */
521 : : uint16_t pvid_sw_shift_en:1;
522 : : /* check whether the mbuf fast free offload is enabled */
523 : : uint16_t mbuf_fast_free_en:1;
524 : :
525 : : /*
526 : : * For better performance in tx datapath, releasing mbuf in batches is
527 : : * required.
528 : : * Only checking the VLD bit of the last descriptor in a batch of the
529 : : * thresh descriptors does not mean that these descriptors are all sent
530 : : * by hardware successfully. So we need to check that the VLD bits of
531 : : * all descriptors are cleared. and then free all mbufs in the batch.
532 : : * - tx_rs_thresh
533 : : * Number of mbufs released at a time.
534 : : *
535 : : * - free
536 : : * Tx mbuf free array used for preserving temporarily address of mbuf
537 : : * released back to mempool, when releasing mbuf in batches.
538 : : */
539 : : uint16_t tx_rs_thresh;
540 : : struct rte_mbuf **free;
541 : :
542 : : struct hns3_tx_basic_stats basic_stats;
543 : : struct hns3_tx_dfx_stats dfx_stats;
544 : :
545 : : /*
546 : : * The following fields are not accessed in the I/O path, so they are
547 : : * placed at the end.
548 : : */
549 : : alignas(RTE_CACHE_LINE_SIZE) void *io_base;
550 : : struct hns3_adapter *hns;
551 : : uint64_t tx_ring_phys_addr; /* TX ring DMA address */
552 : : const struct rte_memzone *mz;
553 : :
554 : : uint16_t port_id;
555 : : uint16_t queue_id;
556 : :
557 : : bool configured; /* indicate if tx queue has been configured */
558 : : bool tx_deferred_start; /* don't start this queue in dev start */
559 : : bool enabled; /* indicate if Tx queue has been enabled */
560 : : };
561 : :
562 : : #define RX_BD_LOG(hw, level, rxdp) \
563 : : PMD_RX_LOG(hw, level, "Rx descriptor: " \
564 : : "l234_info=%#x pkt_len=%u size=%u rss_hash=%#x fd_id=%u vlan_tag=%u " \
565 : : "o_dm_vlan_id_fb=%#x ot_vlan_tag=%u bd_base_info=%#x", \
566 : : rte_le_to_cpu_32((rxdp)->rx.l234_info), \
567 : : rte_le_to_cpu_16((rxdp)->rx.pkt_len), \
568 : : rte_le_to_cpu_16((rxdp)->rx.size), \
569 : : rte_le_to_cpu_32((rxdp)->rx.rss_hash), \
570 : : rte_le_to_cpu_16((rxdp)->rx.fd_id), \
571 : : rte_le_to_cpu_16((rxdp)->rx.vlan_tag), \
572 : : rte_le_to_cpu_16((rxdp)->rx.o_dm_vlan_id_fb), \
573 : : rte_le_to_cpu_16((rxdp)->rx.ot_vlan_tag), \
574 : : rte_le_to_cpu_32((rxdp)->rx.bd_base_info))
575 : :
576 : : #define TX_BD_LOG(hw, level, txdp) \
577 : : PMD_TX_LOG(hw, level, "Tx descriptor: " \
578 : : "vlan_tag=%u send_size=%u type_cs_vlan_tso_len=%#x outer_vlan_tag=%u " \
579 : : "tv=%#x ol_type_vlan_len_msec=%#x paylen_fd_dop_ol4cs=%#x " \
580 : : "tp_fe_sc_vld_ra_ri=%#x ckst_mss=%u", \
581 : : rte_le_to_cpu_16((txdp)->tx.vlan_tag), \
582 : : rte_le_to_cpu_16((txdp)->tx.send_size), \
583 : : rte_le_to_cpu_32((txdp)->tx.type_cs_vlan_tso_len), \
584 : : rte_le_to_cpu_16((txdp)->tx.outer_vlan_tag), \
585 : : rte_le_to_cpu_16((txdp)->tx.tv), \
586 : : rte_le_to_cpu_32((txdp)->tx.ol_type_vlan_len_msec), \
587 : : rte_le_to_cpu_32((txdp)->tx.paylen_fd_dop_ol4cs), \
588 : : rte_le_to_cpu_16((txdp)->tx.tp_fe_sc_vld_ra_ri), \
589 : : rte_le_to_cpu_16((txdp)->tx.ckst_mss))
590 : :
591 : : #define HNS3_GET_TX_QUEUE_PEND_BD_NUM(txq) \
592 : : ((txq)->nb_tx_desc - 1 - (txq)->tx_bd_ready)
593 : :
594 : : struct hns3_queue_info {
595 : : const char *type; /* point to queue memory name */
596 : : const char *ring_name; /* point to hardware ring name */
597 : : uint16_t idx;
598 : : uint16_t nb_desc;
599 : : unsigned int socket_id;
600 : : };
601 : :
602 : : #define HNS3_TX_CKSUM_OFFLOAD_MASK (RTE_MBUF_F_TX_OUTER_UDP_CKSUM | \
603 : : RTE_MBUF_F_TX_OUTER_IP_CKSUM | \
604 : : RTE_MBUF_F_TX_IP_CKSUM | \
605 : : RTE_MBUF_F_TX_TCP_SEG | \
606 : : RTE_MBUF_F_TX_L4_MASK)
607 : :
608 : : enum hns3_cksum_status {
609 : : HNS3_CKSUM_NONE = 0,
610 : : HNS3_L3_CKSUM_ERR = 1,
611 : : HNS3_L4_CKSUM_ERR = 2,
612 : : HNS3_OUTER_L3_CKSUM_ERR = 4,
613 : : HNS3_OUTER_L4_CKSUM_ERR = 8
614 : : };
615 : :
616 : : extern uint64_t hns3_timestamp_rx_dynflag;
617 : : extern int hns3_timestamp_dynfield_offset;
618 : :
619 : : static inline void
620 : 0 : hns3_rx_set_cksum_flag(struct hns3_rx_queue *rxq,
621 : : struct rte_mbuf *rxm,
622 : : uint32_t l234_info)
623 : : {
624 : : #define HNS3_RXD_CKSUM_ERR_MASK (BIT(HNS3_RXD_L3E_B) | \
625 : : BIT(HNS3_RXD_L4E_B) | \
626 : : BIT(HNS3_RXD_OL3E_B) | \
627 : : BIT(HNS3_RXD_OL4E_B))
628 : :
629 [ # # ]: 0 : if (likely((l234_info & HNS3_RXD_CKSUM_ERR_MASK) == 0)) {
630 : 0 : rxm->ol_flags |= (RTE_MBUF_F_RX_IP_CKSUM_GOOD | RTE_MBUF_F_RX_L4_CKSUM_GOOD);
631 : 0 : return;
632 : : }
633 : :
634 [ # # ]: 0 : if (unlikely(l234_info & BIT(HNS3_RXD_L3E_B))) {
635 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
636 : 0 : rxq->dfx_stats.l3_csum_errors++;
637 : : } else {
638 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
639 : : }
640 : :
641 [ # # ]: 0 : if (unlikely(l234_info & BIT(HNS3_RXD_L4E_B))) {
642 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD;
643 : 0 : rxq->dfx_stats.l4_csum_errors++;
644 : : } else {
645 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
646 : : }
647 : :
648 [ # # ]: 0 : if (unlikely(l234_info & BIT(HNS3_RXD_OL3E_B)))
649 : 0 : rxq->dfx_stats.ol3_csum_errors++;
650 : :
651 [ # # ]: 0 : if (unlikely(l234_info & BIT(HNS3_RXD_OL4E_B))) {
652 : 0 : rxm->ol_flags |= RTE_MBUF_F_RX_OUTER_L4_CKSUM_BAD;
653 : 0 : rxq->dfx_stats.ol4_csum_errors++;
654 : : }
655 : : }
656 : :
657 : : static inline int
658 : 0 : hns3_handle_bdinfo(struct hns3_rx_queue *rxq, struct rte_mbuf *rxm,
659 : : uint32_t bd_base_info, uint32_t l234_info)
660 : : {
661 : : #define L2E_TRUNC_ERR_FLAG (BIT(HNS3_RXD_L2E_B) | \
662 : : BIT(HNS3_RXD_TRUNCATE_B))
663 : :
664 : : /*
665 : : * If packet len bigger than mtu when recv with no-scattered algorithm,
666 : : * the first n bd will without FE bit, we need process this situation.
667 : : * Note: we don't need add statistic counter because latest BD which
668 : : * with FE bit will mark HNS3_RXD_L2E_B bit.
669 : : */
670 [ # # ]: 0 : if (unlikely((bd_base_info & BIT(HNS3_RXD_FE_B)) == 0))
671 : : return -EINVAL;
672 : :
673 [ # # # # ]: 0 : if (unlikely((l234_info & L2E_TRUNC_ERR_FLAG) || rxm->pkt_len == 0)) {
674 [ # # ]: 0 : if (l234_info & BIT(HNS3_RXD_L2E_B))
675 : 0 : rxq->err_stats.l2_errors++;
676 : : else
677 : 0 : rxq->err_stats.pkt_len_errors++;
678 : 0 : return -EINVAL;
679 : : }
680 : :
681 [ # # ]: 0 : if (bd_base_info & BIT(HNS3_RXD_L3L4P_B))
682 : 0 : hns3_rx_set_cksum_flag(rxq, rxm, l234_info);
683 : :
684 : : return 0;
685 : : }
686 : :
687 : : static inline uint32_t
688 : 0 : hns3_rx_calc_ptype(struct hns3_rx_queue *rxq, const uint32_t l234_info,
689 : : const uint32_t ol_info)
690 : : {
691 : 0 : const struct hns3_ptype_table * const ptype_tbl = rxq->ptype_tbl;
692 : : uint32_t ol3id, ol4id;
693 : : uint32_t l3id, l4id;
694 : : uint32_t ptype;
695 : :
696 [ # # ]: 0 : if (rxq->ptype_en) {
697 : 0 : ptype = hns3_get_field(ol_info, HNS3_RXD_PTYPE_M,
698 : : HNS3_RXD_PTYPE_S);
699 : 0 : return ptype_tbl->ptype[ptype];
700 : : }
701 : :
702 : 0 : ol4id = hns3_get_field(ol_info, HNS3_RXD_OL4ID_M, HNS3_RXD_OL4ID_S);
703 : 0 : ol3id = hns3_get_field(ol_info, HNS3_RXD_OL3ID_M, HNS3_RXD_OL3ID_S);
704 : 0 : l3id = hns3_get_field(l234_info, HNS3_RXD_L3ID_M, HNS3_RXD_L3ID_S);
705 : 0 : l4id = hns3_get_field(l234_info, HNS3_RXD_L4ID_M, HNS3_RXD_L4ID_S);
706 : :
707 [ # # ]: 0 : if (unlikely(ptype_tbl->ol4table[ol4id]))
708 : 0 : return ptype_tbl->inner_l3table[l3id] |
709 : 0 : ptype_tbl->inner_l4table[l4id] |
710 : 0 : ptype_tbl->ol3table[ol3id] |
711 : : ptype_tbl->ol4table[ol4id];
712 : : else
713 : 0 : return ptype_tbl->l3table[l3id] | ptype_tbl->l4table[l4id];
714 : : }
715 : :
716 : : /*
717 : : * If enable using Tx push feature and also device support it, then use quick
718 : : * doorbell (bar45) to inform the hardware.
719 : : *
720 : : * The other cases (such as: device don't support or user don't enable using)
721 : : * then use normal doorbell (bar23) to inform the hardware.
722 : : */
723 : : static inline void
724 : : hns3_write_txq_tail_reg(struct hns3_tx_queue *txq, uint32_t value)
725 : : {
726 : 0 : rte_io_wmb();
727 [ # # # # ]: 0 : if (txq->tx_push_enable)
728 : 0 : rte_write64_relaxed(rte_cpu_to_le_32(value), txq->io_tail_reg);
729 : : else
730 : 0 : rte_write32_relaxed(rte_cpu_to_le_32(value), txq->io_tail_reg);
731 : : }
732 : :
733 : : void hns3_dev_rx_queue_release(struct rte_eth_dev *dev, uint16_t queue_id);
734 : : void hns3_dev_tx_queue_release(struct rte_eth_dev *dev, uint16_t queue_id);
735 : : void hns3_free_all_queues(struct rte_eth_dev *dev);
736 : : int hns3_reset_all_tqps(struct hns3_adapter *hns);
737 : : void hns3_dev_all_rx_queue_intr_enable(struct hns3_hw *hw, bool en);
738 : : int hns3_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id);
739 : : int hns3_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id);
740 : : void hns3_enable_all_queues(struct hns3_hw *hw, bool en);
741 : : int hns3_init_queues(struct hns3_adapter *hns, bool reset_queue);
742 : : void hns3_start_tqps(struct hns3_hw *hw);
743 : : void hns3_stop_tqps(struct hns3_hw *hw);
744 : : int hns3_rxq_iterate(struct rte_eth_dev *dev,
745 : : int (*callback)(struct hns3_rx_queue *, void *), void *arg);
746 : : void hns3_dev_release_mbufs(struct hns3_adapter *hns);
747 : : int hns3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
748 : : unsigned int socket_id,
749 : : const struct rte_eth_rxconf *conf,
750 : : struct rte_mempool *mp);
751 : : int hns3_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t nb_desc,
752 : : unsigned int socket_id,
753 : : const struct rte_eth_txconf *conf);
754 : : uint32_t hns3_rx_queue_count(void *rx_queue);
755 : : int hns3_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id);
756 : : int hns3_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id);
757 : : int hns3_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id);
758 : : int hns3_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id);
759 : : uint16_t hns3_recv_pkts_simple(void *rx_queue, struct rte_mbuf **rx_pkts,
760 : : uint16_t nb_pkts);
761 : : uint16_t hns3_recv_scattered_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
762 : : uint16_t nb_pkts);
763 : : uint16_t hns3_recv_pkts_vec(void *__restrict rx_queue,
764 : : struct rte_mbuf **__restrict rx_pkts,
765 : : uint16_t nb_pkts);
766 : : uint16_t hns3_recv_pkts_vec_sve(void *__restrict rx_queue,
767 : : struct rte_mbuf **__restrict rx_pkts,
768 : : uint16_t nb_pkts);
769 : : int hns3_rx_burst_mode_get(struct rte_eth_dev *dev,
770 : : __rte_unused uint16_t queue_id,
771 : : struct rte_eth_burst_mode *mode);
772 : : uint16_t hns3_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
773 : : uint16_t nb_pkts);
774 : : uint16_t hns3_xmit_pkts_simple(void *tx_queue, struct rte_mbuf **tx_pkts,
775 : : uint16_t nb_pkts);
776 : : uint16_t hns3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
777 : : uint16_t nb_pkts);
778 : : uint16_t hns3_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
779 : : uint16_t nb_pkts);
780 : : uint16_t hns3_xmit_pkts_vec_sve(void *tx_queue, struct rte_mbuf **tx_pkts,
781 : : uint16_t nb_pkts);
782 : : int hns3_tx_burst_mode_get(struct rte_eth_dev *dev,
783 : : __rte_unused uint16_t queue_id,
784 : : struct rte_eth_burst_mode *mode);
785 : : const uint32_t *hns3_dev_supported_ptypes_get(struct rte_eth_dev *dev,
786 : : size_t *no_of_elements);
787 : : void hns3_init_rx_ptype_tble(struct rte_eth_dev *dev);
788 : : void hns3_set_rxtx_function(struct rte_eth_dev *eth_dev);
789 : : uint32_t hns3_get_tqp_intr_reg_offset(uint16_t tqp_intr_id);
790 : : void hns3_set_queue_intr_gl(struct hns3_hw *hw, uint16_t queue_id,
791 : : uint8_t gl_idx, uint16_t gl_value);
792 : : void hns3_set_queue_intr_rl(struct hns3_hw *hw, uint16_t queue_id,
793 : : uint16_t rl_value);
794 : : void hns3_set_queue_intr_ql(struct hns3_hw *hw, uint16_t queue_id,
795 : : uint16_t ql_value);
796 : : int hns3_set_fake_rx_or_tx_queues(struct rte_eth_dev *dev, uint16_t nb_rx_q,
797 : : uint16_t nb_tx_q);
798 : : int hns3_config_gro(struct hns3_hw *hw, bool en);
799 : : int hns3_restore_gro_conf(struct hns3_hw *hw);
800 : : void hns3_update_all_queues_pvid_proc_en(struct hns3_hw *hw);
801 : : void hns3_rx_scattered_reset(struct rte_eth_dev *dev);
802 : : void hns3_rx_scattered_calc(struct rte_eth_dev *dev);
803 : : int hns3_rx_check_vec_support(struct rte_eth_dev *dev);
804 : : int hns3_tx_check_vec_support(struct rte_eth_dev *dev);
805 : : void hns3_rxq_vec_setup(struct hns3_rx_queue *rxq);
806 : : void hns3_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
807 : : struct rte_eth_rxq_info *qinfo);
808 : : void hns3_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
809 : : struct rte_eth_txq_info *qinfo);
810 : : uint32_t hns3_get_tqp_reg_offset(uint16_t queue_id);
811 : : int hns3_start_all_txqs(struct rte_eth_dev *dev);
812 : : int hns3_start_all_rxqs(struct rte_eth_dev *dev);
813 : : void hns3_stop_all_txqs(struct rte_eth_dev *dev);
814 : : void hns3_restore_tqp_enable_state(struct hns3_hw *hw);
815 : : int hns3_tx_done_cleanup(void *txq, uint32_t free_cnt);
816 : : void hns3_enable_rxd_adv_layout(struct hns3_hw *hw);
817 : : int hns3_dev_rx_descriptor_status(void *rx_queue, uint16_t offset);
818 : : int hns3_dev_tx_descriptor_status(void *tx_queue, uint16_t offset);
819 : : void hns3_tx_push_init(struct rte_eth_dev *dev);
820 : : void hns3_stop_tx_datapath(struct rte_eth_dev *dev);
821 : : void hns3_start_tx_datapath(struct rte_eth_dev *dev);
822 : : void hns3_stop_rxtx_datapath(struct rte_eth_dev *dev);
823 : : void hns3_start_rxtx_datapath(struct rte_eth_dev *dev);
824 : : int hns3_get_monitor_addr(void *rx_queue, struct rte_power_monitor_cond *pmc);
825 : :
826 : : #endif /* HNS3_RXTX_H */
|