1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
3 */
4
5 #ifndef _RTE_PMD_ICE_H_
6 #define _RTE_PMD_ICE_H_
7
8 /**
9 * @file rte_pmd_ice.h
10 *
11 * ice PMD specific functions.
12 *
13 * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
14 *
15 */
16
17 #include <stdio.h>
18 #include <rte_mbuf.h>
19 #include <rte_mbuf_dyn.h>
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 /**
26 * The supported network protocol extraction metadata format.
27 */
28 union rte_net_ice_proto_xtr_metadata {
29 uint32_t metadata;
30
31 struct {
32 uint16_t data0;
33 uint16_t data1;
34 } raw;
35
36 struct {
37 uint16_t stag_vid:12,
38 stag_dei:1,
39 stag_pcp:3;
40 uint16_t ctag_vid:12,
41 ctag_dei:1,
42 ctag_pcp:3;
43 } vlan;
44
45 struct {
46 uint16_t protocol:8,
47 ttl:8;
48 uint16_t tos:8,
49 ihl:4,
50 version:4;
51 } ipv4;
52
53 struct {
54 uint16_t hoplimit:8,
55 nexthdr:8;
56 uint16_t flowhi4:4,
57 tc:8,
58 version:4;
59 } ipv6;
60
61 struct {
62 uint16_t flowlo16;
63 uint16_t flowhi4:4,
64 tc:8,
65 version:4;
66 } ipv6_flow;
67
68 struct {
69 uint16_t fin:1,
70 syn:1,
71 rst:1,
72 psh:1,
73 ack:1,
74 urg:1,
75 ece:1,
76 cwr:1,
77 res1:4,
78 doff:4;
79 uint16_t rsvd;
80 } tcp;
81
82 uint32_t ip_ofs;
83 };
84
85 /* Offset of mbuf dynamic field for protocol extraction data */
86 extern int rte_net_ice_dynfield_proto_xtr_metadata_offs;
87
88 /* Mask of mbuf dynamic flags for protocol extraction type */
89 extern uint64_t rte_net_ice_dynflag_proto_xtr_vlan_mask;
90 extern uint64_t rte_net_ice_dynflag_proto_xtr_ipv4_mask;
91 extern uint64_t rte_net_ice_dynflag_proto_xtr_ipv6_mask;
92 extern uint64_t rte_net_ice_dynflag_proto_xtr_ipv6_flow_mask;
93 extern uint64_t rte_net_ice_dynflag_proto_xtr_tcp_mask;
94 extern uint64_t rte_net_ice_dynflag_proto_xtr_ip_offset_mask;
95
96 /**
97 * The mbuf dynamic field pointer for protocol extraction metadata.
98 */
99 #define RTE_NET_ICE_DYNF_PROTO_XTR_METADATA(m) \
100 RTE_MBUF_DYNFIELD((m), \
101 rte_net_ice_dynfield_proto_xtr_metadata_offs, \
102 uint32_t *)
103
104 /**
105 * The mbuf dynamic flag for VLAN protocol extraction metadata, it is valid
106 * when dev_args 'proto_xtr' has 'vlan' specified.
107 */
108 #define RTE_PKT_RX_DYNF_PROTO_XTR_VLAN \
109 (rte_net_ice_dynflag_proto_xtr_vlan_mask)
110
111 /**
112 * The mbuf dynamic flag for IPv4 protocol extraction metadata, it is valid
113 * when dev_args 'proto_xtr' has 'ipv4' specified.
114 */
115 #define RTE_PKT_RX_DYNF_PROTO_XTR_IPV4 \
116 (rte_net_ice_dynflag_proto_xtr_ipv4_mask)
117
118 /**
119 * The mbuf dynamic flag for IPv6 protocol extraction metadata, it is valid
120 * when dev_args 'proto_xtr' has 'ipv6' specified.
121 */
122 #define RTE_PKT_RX_DYNF_PROTO_XTR_IPV6 \
123 (rte_net_ice_dynflag_proto_xtr_ipv6_mask)
124
125 /**
126 * The mbuf dynamic flag for IPv6 with flow protocol extraction metadata, it is
127 * valid when dev_args 'proto_xtr' has 'ipv6_flow' specified.
128 */
129 #define RTE_PKT_RX_DYNF_PROTO_XTR_IPV6_FLOW \
130 (rte_net_ice_dynflag_proto_xtr_ipv6_flow_mask)
131
132 /**
133 * The mbuf dynamic flag for TCP protocol extraction metadata, it is valid
134 * when dev_args 'proto_xtr' has 'tcp' specified.
135 */
136 #define RTE_PKT_RX_DYNF_PROTO_XTR_TCP \
137 (rte_net_ice_dynflag_proto_xtr_tcp_mask)
138
139 /**
140 * The mbuf dynamic flag for IP_OFFSET extraction metadata, it is valid
141 * when dev_args 'proto_xtr' has 'ip_offset' specified.
142 */
143 #define RTE_PKT_RX_DYNF_PROTO_XTR_IP_OFFSET \
144 (rte_net_ice_dynflag_proto_xtr_ip_offset_mask)
145
146 /**
147 * Check if mbuf dynamic field for protocol extraction metadata is registered.
148 *
149 * @return
150 * True if registered, false otherwise.
151 */
152 __rte_experimental
153 static __rte_always_inline int
rte_net_ice_dynf_proto_xtr_metadata_avail(void)154 rte_net_ice_dynf_proto_xtr_metadata_avail(void)
155 {
156 return rte_net_ice_dynfield_proto_xtr_metadata_offs != -1;
157 }
158
159 /**
160 * Get the mbuf dynamic field for protocol extraction metadata.
161 *
162 * @param m
163 * The pointer to the mbuf.
164 * @return
165 * The saved protocol extraction metadata.
166 */
167 __rte_experimental
168 static __rte_always_inline uint32_t
rte_net_ice_dynf_proto_xtr_metadata_get(struct rte_mbuf * m)169 rte_net_ice_dynf_proto_xtr_metadata_get(struct rte_mbuf *m)
170 {
171 return *RTE_NET_ICE_DYNF_PROTO_XTR_METADATA(m);
172 }
173
174 /**
175 * Dump the mbuf dynamic field for protocol extraction metadata.
176 *
177 * @param m
178 * The pointer to the mbuf.
179 */
180 __rte_experimental
181 static inline void
rte_net_ice_dump_proto_xtr_metadata(struct rte_mbuf * m)182 rte_net_ice_dump_proto_xtr_metadata(struct rte_mbuf *m)
183 {
184 union rte_net_ice_proto_xtr_metadata data;
185
186 if (!rte_net_ice_dynf_proto_xtr_metadata_avail())
187 return;
188
189 data.metadata = rte_net_ice_dynf_proto_xtr_metadata_get(m);
190
191 if (m->ol_flags & RTE_PKT_RX_DYNF_PROTO_XTR_VLAN)
192 printf(" - Protocol Extraction:[0x%04x:0x%04x],vlan,stag=%u:%u:%u,ctag=%u:%u:%u",
193 data.raw.data0, data.raw.data1,
194 data.vlan.stag_pcp,
195 data.vlan.stag_dei,
196 data.vlan.stag_vid,
197 data.vlan.ctag_pcp,
198 data.vlan.ctag_dei,
199 data.vlan.ctag_vid);
200 else if (m->ol_flags & RTE_PKT_RX_DYNF_PROTO_XTR_IPV4)
201 printf(" - Protocol Extraction:[0x%04x:0x%04x],ipv4,ver=%u,hdrlen=%u,tos=%u,ttl=%u,proto=%u",
202 data.raw.data0, data.raw.data1,
203 data.ipv4.version,
204 data.ipv4.ihl,
205 data.ipv4.tos,
206 data.ipv4.ttl,
207 data.ipv4.protocol);
208 else if (m->ol_flags & RTE_PKT_RX_DYNF_PROTO_XTR_IPV6)
209 printf(" - Protocol Extraction:[0x%04x:0x%04x],ipv6,ver=%u,tc=%u,flow_hi4=0x%x,nexthdr=%u,hoplimit=%u",
210 data.raw.data0, data.raw.data1,
211 data.ipv6.version,
212 data.ipv6.tc,
213 data.ipv6.flowhi4,
214 data.ipv6.nexthdr,
215 data.ipv6.hoplimit);
216 else if (m->ol_flags & RTE_PKT_RX_DYNF_PROTO_XTR_IPV6_FLOW)
217 printf(" - Protocol Extraction:[0x%04x:0x%04x],ipv6_flow,ver=%u,tc=%u,flow=0x%x%04x",
218 data.raw.data0, data.raw.data1,
219 data.ipv6_flow.version,
220 data.ipv6_flow.tc,
221 data.ipv6_flow.flowhi4,
222 data.ipv6_flow.flowlo16);
223 else if (m->ol_flags & RTE_PKT_RX_DYNF_PROTO_XTR_TCP)
224 printf(" - Protocol Extraction:[0x%04x:0x%04x],tcp,doff=%u,flags=%s%s%s%s%s%s%s%s",
225 data.raw.data0, data.raw.data1,
226 data.tcp.doff,
227 data.tcp.cwr ? "C" : "",
228 data.tcp.ece ? "E" : "",
229 data.tcp.urg ? "U" : "",
230 data.tcp.ack ? "A" : "",
231 data.tcp.psh ? "P" : "",
232 data.tcp.rst ? "R" : "",
233 data.tcp.syn ? "S" : "",
234 data.tcp.fin ? "F" : "");
235 else if (m->ol_flags & RTE_PKT_RX_DYNF_PROTO_XTR_IP_OFFSET)
236 printf(" - Protocol Offset:ip_offset=%u",
237 data.ip_ofs);
238 }
239
240 #ifdef __cplusplus
241 }
242 #endif
243
244 #endif /* _RTE_PMD_ICE_H_ */
245