net/i40e: fix Rx packet statistics
[dpdk.git] / drivers / net / iavf / rte_pmd_iavf.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Intel Corporation
3  */
4
5 #ifndef _RTE_PMD_IAVF_H_
6 #define _RTE_PMD_IAVF_H_
7
8 /**
9  * @file rte_pmd_iavf.h
10  *
11  * iavf PMD specific functions.
12  *
13  * @b EXPERIMENTAL: this API may change, or be removed, without prior notiavf
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 flexible descriptor's extraction metadata format.
27  */
28 union rte_pmd_ifd_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 flexible descriptor's extraction data */
86 extern int rte_pmd_ifd_dynfield_proto_xtr_metadata_offs;
87
88 /* Mask of mbuf dynamic flags for flexible descriptor's extraction type */
89 extern uint64_t rte_pmd_ifd_dynflag_proto_xtr_vlan_mask;
90 extern uint64_t rte_pmd_ifd_dynflag_proto_xtr_ipv4_mask;
91 extern uint64_t rte_pmd_ifd_dynflag_proto_xtr_ipv6_mask;
92 extern uint64_t rte_pmd_ifd_dynflag_proto_xtr_ipv6_flow_mask;
93 extern uint64_t rte_pmd_ifd_dynflag_proto_xtr_tcp_mask;
94 extern uint64_t rte_pmd_ifd_dynflag_proto_xtr_ip_offset_mask;
95
96 /**
97  * The mbuf dynamic field pointer for flexible descriptor's extraction metadata.
98  */
99 #define RTE_PMD_IFD_DYNF_PROTO_XTR_METADATA(m) \
100         RTE_MBUF_DYNFIELD((m), \
101                           rte_pmd_ifd_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_IAVF_PKT_RX_DYNF_PROTO_XTR_VLAN \
109         (rte_pmd_ifd_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_IAVF_PKT_RX_DYNF_PROTO_XTR_IPV4 \
116         (rte_pmd_ifd_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_IAVF_PKT_RX_DYNF_PROTO_XTR_IPV6 \
123         (rte_pmd_ifd_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_IAVF_PKT_RX_DYNF_PROTO_XTR_IPV6_FLOW \
130         (rte_pmd_ifd_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_IAVF_PKT_RX_DYNF_PROTO_XTR_TCP \
137         (rte_pmd_ifd_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_IAVF_PKT_RX_DYNF_PROTO_XTR_IP_OFFSET \
144         (rte_pmd_ifd_dynflag_proto_xtr_ip_offset_mask)
145
146 /**
147  * Check if mbuf dynamic field for flexible descriptor's extraction metadata
148  * is registered.
149  *
150  * @return
151  *   True if registered, false otherwise.
152  */
153 __rte_experimental
154 static __rte_always_inline int
155 rte_pmd_ifd_dynf_proto_xtr_metadata_avail(void)
156 {
157         return rte_pmd_ifd_dynfield_proto_xtr_metadata_offs != -1;
158 }
159
160 /**
161  * Get the mbuf dynamic field for flexible descriptor's extraction metadata.
162  *
163  * @param m
164  *    The pointer to the mbuf.
165  * @return
166  *   The saved protocol extraction metadata.
167  */
168 __rte_experimental
169 static __rte_always_inline uint32_t
170 rte_pmd_ifd_dynf_proto_xtr_metadata_get(struct rte_mbuf *m)
171 {
172         return *RTE_PMD_IFD_DYNF_PROTO_XTR_METADATA(m);
173 }
174
175 /**
176  * Dump the mbuf dynamic field for flexible descriptor's extraction metadata.
177  *
178  * @param m
179  *    The pointer to the mbuf.
180  */
181 __rte_experimental
182 static inline void
183 rte_pmd_ifd_dump_proto_xtr_metadata(struct rte_mbuf *m)
184 {
185         union rte_pmd_ifd_proto_xtr_metadata data;
186
187         if (!rte_pmd_ifd_dynf_proto_xtr_metadata_avail())
188                 return;
189
190         data.metadata = rte_pmd_ifd_dynf_proto_xtr_metadata_get(m);
191
192         if (m->ol_flags & RTE_IAVF_PKT_RX_DYNF_PROTO_XTR_VLAN)
193                 printf(" - Flexible descriptor's Metadata: [0x%04x:0x%04x],"
194                        "vlan,stag=%u:%u:%u,ctag=%u:%u:%u",
195                        data.raw.data0, data.raw.data1,
196                        data.vlan.stag_pcp,
197                        data.vlan.stag_dei,
198                        data.vlan.stag_vid,
199                        data.vlan.ctag_pcp,
200                        data.vlan.ctag_dei,
201                        data.vlan.ctag_vid);
202         else if (m->ol_flags & RTE_IAVF_PKT_RX_DYNF_PROTO_XTR_IPV4)
203                 printf(" - Flexible descriptor's Metadata: [0x%04x:0x%04x],"
204                        "ipv4,ver=%u,hdrlen=%u,tos=%u,ttl=%u,proto=%u",
205                        data.raw.data0, data.raw.data1,
206                        data.ipv4.version,
207                        data.ipv4.ihl,
208                        data.ipv4.tos,
209                        data.ipv4.ttl,
210                        data.ipv4.protocol);
211         else if (m->ol_flags & RTE_IAVF_PKT_RX_DYNF_PROTO_XTR_IPV6)
212                 printf(" - Flexible descriptor's Metadata: [0x%04x:0x%04x],"
213                        "ipv6,ver=%u,tc=%u,flow_hi4=0x%x,nexthdr=%u,hoplimit=%u",
214                        data.raw.data0, data.raw.data1,
215                        data.ipv6.version,
216                        data.ipv6.tc,
217                        data.ipv6.flowhi4,
218                        data.ipv6.nexthdr,
219                        data.ipv6.hoplimit);
220         else if (m->ol_flags & RTE_IAVF_PKT_RX_DYNF_PROTO_XTR_IPV6_FLOW)
221                 printf(" - Flexible descriptor's Metadata: [0x%04x:0x%04x],"
222                        "ipv6_flow,ver=%u,tc=%u,flow=0x%x%04x",
223                        data.raw.data0, data.raw.data1,
224                        data.ipv6_flow.version,
225                        data.ipv6_flow.tc,
226                        data.ipv6_flow.flowhi4,
227                        data.ipv6_flow.flowlo16);
228         else if (m->ol_flags & RTE_IAVF_PKT_RX_DYNF_PROTO_XTR_TCP)
229                 printf(" - Flexible descriptor's Metadata: [0x%04x:0x%04x],"
230                        "tcp,doff=%u,flags=%s%s%s%s%s%s%s%s",
231                        data.raw.data0, data.raw.data1,
232                        data.tcp.doff,
233                        data.tcp.cwr ? "C" : "",
234                        data.tcp.ece ? "E" : "",
235                        data.tcp.urg ? "U" : "",
236                        data.tcp.ack ? "A" : "",
237                        data.tcp.psh ? "P" : "",
238                        data.tcp.rst ? "R" : "",
239                        data.tcp.syn ? "S" : "",
240                        data.tcp.fin ? "F" : "");
241         else if (m->ol_flags & RTE_IAVF_PKT_RX_DYNF_PROTO_XTR_IP_OFFSET)
242                 printf(" - Flexible descriptor's Extraction: ip_offset=%u",
243                        data.ip_ofs);
244 }
245
246 #ifdef __cplusplus
247 }
248 #endif
249
250 #endif /* _RTE_PMD_IAVF_H_ */