net/sfc: discard packets with bad CRC on EF10 ESSB Rx
[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(rx_ev.eq_u64[0] &
38                 rte_cpu_to_le_64((1ull << ESF_DZ_RX_ECC_ERR_LBN) |
39                                  (1ull << ESF_DZ_RX_ECRC_ERR_LBN) |
40                                  (1ull << ESF_DZ_RX_PARSE_INCOMPLETE_LBN)))) {
41                 /* Zero packet type is used as a marker to dicard bad packets */
42                 goto done;
43         }
44
45 #if SFC_EF10_RX_EV_ENCAP_SUPPORT
46         switch (EFX_QWORD_FIELD(rx_ev, ESF_EZ_RX_ENCAP_HDR)) {
47         default:
48                 /* Unexpected encapsulation tag class */
49                 SFC_ASSERT(false);
50                 /* FALLTHROUGH */
51         case ESE_EZ_ENCAP_HDR_NONE:
52                 break;
53         case ESE_EZ_ENCAP_HDR_VXLAN:
54                 /*
55                  * It is definitely UDP, but we have no information
56                  * about IPv4 vs IPv6 and VLAN tagging.
57                  */
58                 tun_ptype = RTE_PTYPE_TUNNEL_VXLAN | RTE_PTYPE_L4_UDP;
59                 break;
60         case ESE_EZ_ENCAP_HDR_GRE:
61                 /*
62                  * We have no information about IPv4 vs IPv6 and VLAN tagging.
63                  */
64                 tun_ptype = RTE_PTYPE_TUNNEL_NVGRE;
65                 break;
66         }
67 #endif
68
69         if (tun_ptype == 0) {
70                 ip_csum_err_bit = ESF_DZ_RX_IPCKSUM_ERR_LBN;
71                 l4_csum_err_bit = ESF_DZ_RX_TCPUDP_CKSUM_ERR_LBN;
72         } else {
73                 ip_csum_err_bit = ESF_EZ_RX_IP_INNER_CHKSUM_ERR_LBN;
74                 l4_csum_err_bit = ESF_EZ_RX_TCP_UDP_INNER_CHKSUM_ERR_LBN;
75                 if (unlikely(EFX_TEST_QWORD_BIT(rx_ev,
76                                                 ESF_DZ_RX_IPCKSUM_ERR_LBN)))
77                         ol_flags |= PKT_RX_EIP_CKSUM_BAD;
78         }
79
80         switch (EFX_QWORD_FIELD(rx_ev, ESF_DZ_RX_ETH_TAG_CLASS)) {
81         case ESE_DZ_ETH_TAG_CLASS_NONE:
82                 l2_ptype = (tun_ptype == 0) ? RTE_PTYPE_L2_ETHER :
83                         RTE_PTYPE_INNER_L2_ETHER;
84                 break;
85         case ESE_DZ_ETH_TAG_CLASS_VLAN1:
86                 l2_ptype = (tun_ptype == 0) ? RTE_PTYPE_L2_ETHER_VLAN :
87                         RTE_PTYPE_INNER_L2_ETHER_VLAN;
88                 break;
89         case ESE_DZ_ETH_TAG_CLASS_VLAN2:
90                 l2_ptype = (tun_ptype == 0) ? RTE_PTYPE_L2_ETHER_QINQ :
91                         RTE_PTYPE_INNER_L2_ETHER_QINQ;
92                 break;
93         default:
94                 /* Unexpected Eth tag class */
95                 SFC_ASSERT(false);
96         }
97
98         switch (EFX_QWORD_FIELD(rx_ev, ESF_DZ_RX_L3_CLASS)) {
99         case ESE_DZ_L3_CLASS_IP4_FRAG:
100                 l4_ptype = (tun_ptype == 0) ? RTE_PTYPE_L4_FRAG :
101                         RTE_PTYPE_INNER_L4_FRAG;
102                 /* FALLTHROUGH */
103         case ESE_DZ_L3_CLASS_IP4:
104                 l3_ptype = (tun_ptype == 0) ? RTE_PTYPE_L3_IPV4_EXT_UNKNOWN :
105                         RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
106                 ol_flags |= PKT_RX_RSS_HASH |
107                         ((EFX_TEST_QWORD_BIT(rx_ev, ip_csum_err_bit)) ?
108                          PKT_RX_IP_CKSUM_BAD : PKT_RX_IP_CKSUM_GOOD);
109                 break;
110         case ESE_DZ_L3_CLASS_IP6_FRAG:
111                 l4_ptype = (tun_ptype == 0) ? RTE_PTYPE_L4_FRAG :
112                         RTE_PTYPE_INNER_L4_FRAG;
113                 /* FALLTHROUGH */
114         case ESE_DZ_L3_CLASS_IP6:
115                 l3_ptype = (tun_ptype == 0) ? RTE_PTYPE_L3_IPV6_EXT_UNKNOWN :
116                         RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
117                 ol_flags |= PKT_RX_RSS_HASH;
118                 break;
119         case ESE_DZ_L3_CLASS_ARP:
120                 /* Override Layer 2 packet type */
121                 /* There is no ARP classification for inner packets */
122                 if (tun_ptype == 0)
123                         l2_ptype = RTE_PTYPE_L2_ETHER_ARP;
124                 break;
125         default:
126                 /* Unexpected Layer 3 class */
127                 SFC_ASSERT(false);
128         }
129
130         /*
131          * RX_L4_CLASS is 3 bits wide on Huntington and Medford, but is only
132          * 2 bits wide on Medford2. Check it is safe to use the Medford2 field
133          * and values for all EF10 controllers.
134          */
135         RTE_BUILD_BUG_ON(ESF_FZ_RX_L4_CLASS_LBN != ESF_DE_RX_L4_CLASS_LBN);
136         switch (EFX_QWORD_FIELD(rx_ev, ESF_FZ_RX_L4_CLASS)) {
137         case ESE_FZ_L4_CLASS_TCP:
138                  RTE_BUILD_BUG_ON(ESE_FZ_L4_CLASS_TCP != ESE_DE_L4_CLASS_TCP);
139                 l4_ptype = (tun_ptype == 0) ? RTE_PTYPE_L4_TCP :
140                         RTE_PTYPE_INNER_L4_TCP;
141                 ol_flags |=
142                         (EFX_TEST_QWORD_BIT(rx_ev, l4_csum_err_bit)) ?
143                         PKT_RX_L4_CKSUM_BAD : PKT_RX_L4_CKSUM_GOOD;
144                 break;
145         case ESE_FZ_L4_CLASS_UDP:
146                  RTE_BUILD_BUG_ON(ESE_FZ_L4_CLASS_UDP != ESE_DE_L4_CLASS_UDP);
147                 l4_ptype = (tun_ptype == 0) ? RTE_PTYPE_L4_UDP :
148                         RTE_PTYPE_INNER_L4_UDP;
149                 ol_flags |=
150                         (EFX_TEST_QWORD_BIT(rx_ev, l4_csum_err_bit)) ?
151                         PKT_RX_L4_CKSUM_BAD : PKT_RX_L4_CKSUM_GOOD;
152                 break;
153         case ESE_FZ_L4_CLASS_UNKNOWN:
154                  RTE_BUILD_BUG_ON(ESE_FZ_L4_CLASS_UNKNOWN !=
155                                   ESE_DE_L4_CLASS_UNKNOWN);
156                 break;
157         default:
158                 /* Unexpected Layer 4 class */
159                 SFC_ASSERT(false);
160         }
161
162         SFC_ASSERT(l2_ptype != 0);
163
164 done:
165         m->ol_flags = ol_flags & ol_mask;
166         m->packet_type = tun_ptype | l2_ptype | l3_ptype | l4_ptype;
167 }
168
169
170 #ifdef __cplusplus
171 }
172 #endif
173 #endif /* _SFC_EF10_RX_EV_H */