9054fb90e182cc856b0f27546b57ccb6035bda3f
[dpdk.git] / drivers / net / sfc / sfc_ef10_rx_ev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright (c) 2018 Solarflare Communications Inc.
4  * All rights reserved.
5  *
6  * This software was jointly developed between OKTET Labs (under contract
7  * for Solarflare) and Solarflare Communications, Inc.
8  */
9
10 #ifndef _SFC_EF10_RX_EV_H
11 #define _SFC_EF10_RX_EV_H
12
13 #include <rte_mbuf.h>
14
15 #include "efx_types.h"
16 #include "efx_regs.h"
17 #include "efx_regs_ef10.h"
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 static inline void
24 sfc_ef10_rx_ev_to_offloads(const efx_qword_t rx_ev, struct rte_mbuf *m,
25                            uint64_t ol_mask)
26 {
27         uint32_t tun_ptype = 0;
28         /* Which event bit is mapped to PKT_RX_IP_CKSUM_* */
29         int8_t ip_csum_err_bit;
30         /* Which event bit is mapped to PKT_RX_L4_CKSUM_* */
31         int8_t l4_csum_err_bit;
32         uint32_t l2_ptype = 0;
33         uint32_t l3_ptype = 0;
34         uint32_t l4_ptype = 0;
35         uint64_t ol_flags = 0;
36
37         if (unlikely(EFX_TEST_QWORD_BIT(rx_ev, ESF_DZ_RX_PARSE_INCOMPLETE_LBN)))
38                 goto done;
39
40 #if SFC_EF10_RX_EV_ENCAP_SUPPORT
41         switch (EFX_QWORD_FIELD(rx_ev, ESF_EZ_RX_ENCAP_HDR)) {
42         default:
43                 /* Unexpected encapsulation tag class */
44                 SFC_ASSERT(false);
45                 /* FALLTHROUGH */
46         case ESE_EZ_ENCAP_HDR_NONE:
47                 break;
48         case ESE_EZ_ENCAP_HDR_VXLAN:
49                 /*
50                  * It is definitely UDP, but we have no information
51                  * about IPv4 vs IPv6 and VLAN tagging.
52                  */
53                 tun_ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP;
54                 break;
55         case ESE_EZ_ENCAP_HDR_GRE:
56                 /*
57                  * We have no information about IPv4 vs IPv6 and VLAN tagging.
58                  */
59                 tun_ptype = RTE_PTYPE_TUNNEL_NVGRE;
60                 break;
61         }
62 #endif
63
64         if (tun_ptype == 0) {
65                 ip_csum_err_bit = ESF_DZ_RX_IPCKSUM_ERR_LBN;
66                 l4_csum_err_bit = ESF_DZ_RX_TCPUDP_CKSUM_ERR_LBN;
67         } else {
68                 ip_csum_err_bit = ESF_EZ_RX_IP_INNER_CHKSUM_ERR_LBN;
69                 l4_csum_err_bit = ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR_LBN;
70                 if (unlikely(EFX_TEST_QWORD_BIT(rx_ev,
71                                                 ESF_DZ_RX_IPCKSUM_ERR_LBN)))
72                         ol_flags |= PKT_RX_EIP_CKSUM_BAD;
73         }
74
75         switch (EFX_QWORD_FIELD(rx_ev, ESF_DZ_RX_ETH_TAG_CLASS)) {
76         case ESE_DZ_ETH_TAG_CLASS_NONE:
77                 l2_ptype = (tun_ptype == 0) ? RTE_PTYPE_L2_ETHER :
78                         RTE_PTYPE_INNER_L2_ETHER;
79                 break;
80         case ESE_DZ_ETH_TAG_CLASS_VLAN1:
81                 l2_ptype = (tun_ptype == 0) ? RTE_PTYPE_L2_ETHER_VLAN :
82                         RTE_PTYPE_INNER_L2_ETHER_VLAN;
83                 break;
84         case ESE_DZ_ETH_TAG_CLASS_VLAN2:
85                 l2_ptype = (tun_ptype == 0) ? RTE_PTYPE_L2_ETHER_QINQ :
86                         RTE_PTYPE_INNER_L2_ETHER_QINQ;
87                 break;
88         default:
89                 /* Unexpected Eth tag class */
90                 SFC_ASSERT(false);
91         }
92
93         switch (EFX_QWORD_FIELD(rx_ev, ESF_DZ_RX_L3_CLASS)) {
94         case ESE_DZ_L3_CLASS_IP4_FRAG:
95                 l4_ptype = (tun_ptype == 0) ? RTE_PTYPE_L4_FRAG :
96                         RTE_PTYPE_INNER_L4_FRAG;
97                 /* FALLTHROUGH */
98         case ESE_DZ_L3_CLASS_IP4:
99                 l3_ptype = (tun_ptype == 0) ? RTE_PTYPE_L3_IPV4_EXT_UNKNOWN :
100                         RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
101                 ol_flags |= PKT_RX_RSS_HASH |
102                         ((EFX_TEST_QWORD_BIT(rx_ev, ip_csum_err_bit)) ?
103                          PKT_RX_IP_CKSUM_BAD : PKT_RX_IP_CKSUM_GOOD);
104                 break;
105         case ESE_DZ_L3_CLASS_IP6_FRAG:
106                 l4_ptype = (tun_ptype == 0) ? RTE_PTYPE_L4_FRAG :
107                         RTE_PTYPE_INNER_L4_FRAG;
108                 /* FALLTHROUGH */
109         case ESE_DZ_L3_CLASS_IP6:
110                 l3_ptype = (tun_ptype == 0) ? RTE_PTYPE_L3_IPV6_EXT_UNKNOWN :
111                         RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
112                 ol_flags |= PKT_RX_RSS_HASH;
113                 break;
114         case ESE_DZ_L3_CLASS_ARP:
115                 /* Override Layer 2 packet type */
116                 /* There is no ARP classification for inner packets */
117                 if (tun_ptype == 0)
118                         l2_ptype = RTE_PTYPE_L2_ETHER_ARP;
119                 break;
120         default:
121                 /* Unexpected Layer 3 class */
122                 SFC_ASSERT(false);
123         }
124
125         /*
126          * RX_L4_CLASS is 3 bits wide on Huntington and Medford, but is only
127          * 2 bits wide on Medford2. Check it is safe to use the Medford2 field
128          * and values for all EF10 controllers.
129          */
130         RTE_BUILD_BUG_ON(ESF_FZ_RX_L4_CLASS_LBN != ESF_DE_RX_L4_CLASS_LBN);
131         switch (EFX_QWORD_FIELD(rx_ev, ESF_FZ_RX_L4_CLASS)) {
132         case ESE_FZ_L4_CLASS_TCP:
133                  RTE_BUILD_BUG_ON(ESE_FZ_L4_CLASS_TCP != ESE_DE_L4_CLASS_TCP);
134                 l4_ptype = (tun_ptype == 0) ? RTE_PTYPE_L4_TCP :
135                         RTE_PTYPE_INNER_L4_TCP;
136                 ol_flags |=
137                         (EFX_TEST_QWORD_BIT(rx_ev, l4_csum_err_bit)) ?
138                         PKT_RX_L4_CKSUM_BAD : PKT_RX_L4_CKSUM_GOOD;
139                 break;
140         case ESE_FZ_L4_CLASS_UDP:
141                  RTE_BUILD_BUG_ON(ESE_FZ_L4_CLASS_UDP != ESE_DE_L4_CLASS_UDP);
142                 l4_ptype = (tun_ptype == 0) ? RTE_PTYPE_L4_UDP :
143                         RTE_PTYPE_INNER_L4_UDP;
144                 ol_flags |=
145                         (EFX_TEST_QWORD_BIT(rx_ev, l4_csum_err_bit)) ?
146                         PKT_RX_L4_CKSUM_BAD : PKT_RX_L4_CKSUM_GOOD;
147                 break;
148         case ESE_FZ_L4_CLASS_UNKNOWN:
149                  RTE_BUILD_BUG_ON(ESE_FZ_L4_CLASS_UNKNOWN !=
150                                   ESE_DE_L4_CLASS_UNKNOWN);
151                 break;
152         default:
153                 /* Unexpected Layer 4 class */
154                 SFC_ASSERT(false);
155         }
156
157 done:
158         m->ol_flags = ol_flags & ol_mask;
159         m->packet_type = tun_ptype | l2_ptype | l3_ptype | l4_ptype;
160 }
161
162
163 #ifdef __cplusplus
164 }
165 #endif
166 #endif /* _SFC_EF10_RX_EV_H */