719487e1e61ecc391258d20e9ca4058c6f3920f7
[dpdk.git] / drivers / net / ice / rte_pmd_ice.h
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 #include <stdio.h>
9 #include <rte_mbuf.h>
10 #include <rte_ethdev.h>
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 enum proto_xtr_type {
17         PROTO_XTR_NONE,
18         PROTO_XTR_VLAN,
19         PROTO_XTR_IPV4,
20         PROTO_XTR_IPV6,
21         PROTO_XTR_IPV6_FLOW,
22         PROTO_XTR_TCP,
23 };
24
25 struct proto_xtr_flds {
26         union {
27                 struct {
28                         uint16_t data0;
29                         uint16_t data1;
30                 } raw;
31                 struct {
32                         uint16_t stag_vid:12,
33                                  stag_dei:1,
34                                  stag_pcp:3;
35                         uint16_t ctag_vid:12,
36                                  ctag_dei:1,
37                                  ctag_pcp:3;
38                 } vlan;
39                 struct {
40                         uint16_t protocol:8,
41                                  ttl:8;
42                         uint16_t tos:8,
43                                  ihl:4,
44                                  version:4;
45                 } ipv4;
46                 struct {
47                         uint16_t hoplimit:8,
48                                  nexthdr:8;
49                         uint16_t flowhi4:4,
50                                  tc:8,
51                                  version:4;
52                 } ipv6;
53                 struct {
54                         uint16_t flowlo16;
55                         uint16_t flowhi4:4,
56                                  tc:8,
57                                  version:4;
58                 } ipv6_flow;
59                 struct {
60                         uint16_t fin:1,
61                                  syn:1,
62                                  rst:1,
63                                  psh:1,
64                                  ack:1,
65                                  urg:1,
66                                  ece:1,
67                                  cwr:1,
68                                  res1:4,
69                                  doff:4;
70                         uint16_t rsvd;
71                 } tcp;
72         } u;
73
74         uint16_t rsvd;
75
76         uint8_t type;
77
78 #define PROTO_XTR_MAGIC_ID      0xCE
79         uint8_t magic;
80 };
81
82 static inline void
83 init_proto_xtr_flds(struct rte_mbuf *mb)
84 {
85         mb->udata64 = 0;
86 }
87
88 static inline struct proto_xtr_flds *
89 get_proto_xtr_flds(struct rte_mbuf *mb)
90 {
91         RTE_BUILD_BUG_ON(sizeof(struct proto_xtr_flds) > sizeof(mb->udata64));
92
93         return (struct proto_xtr_flds *)&mb->udata64;
94 }
95
96 static inline void
97 dump_proto_xtr_flds(struct rte_mbuf *mb)
98 {
99         struct proto_xtr_flds *xtr = get_proto_xtr_flds(mb);
100
101         if (xtr->magic != PROTO_XTR_MAGIC_ID || xtr->type == PROTO_XTR_NONE)
102                 return;
103
104         printf(" - Protocol Extraction:[0x%04x:0x%04x],",
105                xtr->u.raw.data0, xtr->u.raw.data1);
106
107         if (xtr->type == PROTO_XTR_VLAN)
108                 printf("vlan,stag=%u:%u:%u,ctag=%u:%u:%u ",
109                        xtr->u.vlan.stag_pcp,
110                        xtr->u.vlan.stag_dei,
111                        xtr->u.vlan.stag_vid,
112                        xtr->u.vlan.ctag_pcp,
113                        xtr->u.vlan.ctag_dei,
114                        xtr->u.vlan.ctag_vid);
115         else if (xtr->type == PROTO_XTR_IPV4)
116                 printf("ipv4,ver=%u,hdrlen=%u,tos=%u,ttl=%u,proto=%u ",
117                        xtr->u.ipv4.version,
118                        xtr->u.ipv4.ihl,
119                        xtr->u.ipv4.tos,
120                        xtr->u.ipv4.ttl,
121                        xtr->u.ipv4.protocol);
122         else if (xtr->type == PROTO_XTR_IPV6)
123                 printf("ipv6,ver=%u,tc=%u,flow_hi4=0x%x,nexthdr=%u,hoplimit=%u ",
124                        xtr->u.ipv6.version,
125                        xtr->u.ipv6.tc,
126                        xtr->u.ipv6.flowhi4,
127                        xtr->u.ipv6.nexthdr,
128                        xtr->u.ipv6.hoplimit);
129         else if (xtr->type == PROTO_XTR_IPV6_FLOW)
130                 printf("ipv6_flow,ver=%u,tc=%u,flow=0x%x%04x ",
131                        xtr->u.ipv6_flow.version,
132                        xtr->u.ipv6_flow.tc,
133                        xtr->u.ipv6_flow.flowhi4,
134                        xtr->u.ipv6_flow.flowlo16);
135         else if (xtr->type == PROTO_XTR_TCP)
136                 printf("tcp,doff=%u,flags=%s%s%s%s%s%s%s%s ",
137                        xtr->u.tcp.doff,
138                        xtr->u.tcp.cwr ? "C" : "",
139                        xtr->u.tcp.ece ? "E" : "",
140                        xtr->u.tcp.urg ? "U" : "",
141                        xtr->u.tcp.ack ? "A" : "",
142                        xtr->u.tcp.psh ? "P" : "",
143                        xtr->u.tcp.rst ? "R" : "",
144                        xtr->u.tcp.syn ? "S" : "",
145                        xtr->u.tcp.fin ? "F" : "");
146 }
147
148 #ifdef __cplusplus
149 }
150 #endif
151
152 #endif /* _RTE_PMD_ICE_H_ */