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