1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
8 /* Default mark value used when none is provided. */
9 #define OTX2_FLOW_ACTION_FLAG_DEFAULT 0xffff
11 #define PTYPE_WIDTH 12
12 #define PTYPE_NON_TUNNEL_ARRAY_SZ BIT(PTYPE_WIDTH)
13 #define PTYPE_TUNNEL_ARRAY_SZ BIT(PTYPE_WIDTH)
14 #define PTYPE_ARRAY_SZ ((PTYPE_NON_TUNNEL_ARRAY_SZ +\
15 PTYPE_TUNNEL_ARRAY_SZ) *\
18 #define NIX_RX_OFFLOAD_NONE (0)
19 #define NIX_RX_OFFLOAD_RSS_F BIT(0)
20 #define NIX_RX_OFFLOAD_PTYPE_F BIT(1)
21 #define NIX_RX_OFFLOAD_CHECKSUM_F BIT(2)
22 #define NIX_RX_OFFLOAD_VLAN_STRIP_F BIT(3)
23 #define NIX_RX_OFFLOAD_MARK_UPDATE_F BIT(4)
24 #define NIX_RX_OFFLOAD_TSTAMP_F BIT(5)
26 /* Flags to control cqe_to_mbuf conversion function.
27 * Defining it from backwards to denote its been
28 * not used as offload flags to pick function
30 #define NIX_RX_MULTI_SEG_F BIT(15)
31 #define NIX_TIMESYNC_RX_OFFSET 8
33 struct otx2_timesync_info {
35 rte_iova_t tx_tstamp_iova;
39 } __rte_cache_aligned;
41 union mbuf_initializer {
51 static __rte_always_inline void
52 otx2_nix_mbuf_to_tstamp(struct rte_mbuf *mbuf,
53 struct otx2_timesync_info *tstamp, const uint16_t flag)
55 if ((flag & NIX_RX_OFFLOAD_TSTAMP_F) &&
56 mbuf->packet_type == RTE_PTYPE_L2_ETHER_TIMESYNC &&
57 (mbuf->data_off == RTE_PKTMBUF_HEADROOM +
58 NIX_TIMESYNC_RX_OFFSET)) {
61 /* Deal with rx timestamp */
62 tstamp_ptr = rte_pktmbuf_mtod_offset(mbuf, uint64_t *,
63 -NIX_TIMESYNC_RX_OFFSET);
64 mbuf->timestamp = rte_be_to_cpu_64(*tstamp_ptr);
65 tstamp->rx_tstamp = mbuf->timestamp;
67 mbuf->ol_flags |= PKT_RX_IEEE1588_PTP | PKT_RX_IEEE1588_TMST
72 static __rte_always_inline uint64_t
73 nix_clear_data_off(uint64_t oldval)
75 union mbuf_initializer mbuf_init = { .value = oldval };
77 mbuf_init.fields.data_off = 0;
78 return mbuf_init.value;
81 static __rte_always_inline struct rte_mbuf *
82 nix_get_mbuf_from_cqe(void *cq, const uint64_t data_off)
86 /* Skip CQE, NIX_RX_PARSE_S and SG HDR(9 DWORDs) and peek buff addr */
87 buff = *((rte_iova_t *)((uint64_t *)cq + 9));
88 return (struct rte_mbuf *)(buff - data_off);
92 static __rte_always_inline uint32_t
93 nix_ptype_get(const void * const lookup_mem, const uint64_t in)
95 const uint16_t * const ptype = lookup_mem;
96 const uint16_t lg_lf_le = (in & 0xFFF000000000000) >> 48;
97 const uint16_t tu_l2 = ptype[(in & 0x000FFF000000000) >> 36];
98 const uint16_t il4_tu = ptype[PTYPE_NON_TUNNEL_ARRAY_SZ + lg_lf_le];
100 return (il4_tu << PTYPE_WIDTH) | tu_l2;
103 static __rte_always_inline uint32_t
104 nix_rx_olflags_get(const void * const lookup_mem, const uint64_t in)
106 const uint32_t * const ol_flags = (const uint32_t *)
107 ((const uint8_t *)lookup_mem + PTYPE_ARRAY_SZ);
109 return ol_flags[(in & 0xfff00000) >> 20];
112 static inline uint64_t
113 nix_update_match_id(const uint16_t match_id, uint64_t ol_flags,
114 struct rte_mbuf *mbuf)
116 /* There is no separate bit to check match_id
117 * is valid or not? and no flag to identify it is an
118 * RTE_FLOW_ACTION_TYPE_FLAG vs RTE_FLOW_ACTION_TYPE_MARK
119 * action. The former case addressed through 0 being invalid
120 * value and inc/dec match_id pair when MARK is activated.
121 * The later case addressed through defining
122 * OTX2_FLOW_MARK_DEFAULT as value for
123 * RTE_FLOW_ACTION_TYPE_MARK.
124 * This would translate to not use
125 * OTX2_FLOW_ACTION_FLAG_DEFAULT - 1 and
126 * OTX2_FLOW_ACTION_FLAG_DEFAULT for match_id.
127 * i.e valid mark_id's are from
128 * 0 to OTX2_FLOW_ACTION_FLAG_DEFAULT - 2
130 if (likely(match_id)) {
131 ol_flags |= PKT_RX_FDIR;
132 if (match_id != OTX2_FLOW_ACTION_FLAG_DEFAULT) {
133 ol_flags |= PKT_RX_FDIR_ID;
134 mbuf->hash.fdir.hi = match_id - 1;
141 static __rte_always_inline void
142 nix_cqe_xtract_mseg(const struct nix_rx_parse_s *rx,
143 struct rte_mbuf *mbuf, uint64_t rearm)
145 const rte_iova_t *iova_list;
146 struct rte_mbuf *head;
147 const rte_iova_t *eol;
151 sg = *(const uint64_t *)(rx + 1);
152 nb_segs = (sg >> 48) & 0x3;
153 mbuf->nb_segs = nb_segs;
154 mbuf->data_len = sg & 0xFFFF;
157 eol = ((const rte_iova_t *)(rx + 1) + ((rx->desc_sizem1 + 1) << 1));
158 /* Skip SG_S and first IOVA*/
159 iova_list = ((const rte_iova_t *)(rx + 1)) + 2;
162 rearm = rearm & ~0xFFFF;
166 mbuf->next = ((struct rte_mbuf *)*iova_list) - 1;
169 __mempool_check_cookies(mbuf->pool, (void **)&mbuf, 1, 1);
171 mbuf->data_len = sg & 0xFFFF;
173 *(uint64_t *)(&mbuf->rearm_data) = rearm;
177 if (!nb_segs && (iova_list + 1 < eol)) {
178 sg = *(const uint64_t *)(iova_list);
179 nb_segs = (sg >> 48) & 0x3;
180 head->nb_segs += nb_segs;
181 iova_list = (const rte_iova_t *)(iova_list + 1);
186 static __rte_always_inline void
187 otx2_nix_cqe_to_mbuf(const struct nix_cqe_hdr_s *cq, const uint32_t tag,
188 struct rte_mbuf *mbuf, const void *lookup_mem,
189 const uint64_t val, const uint16_t flag)
191 const struct nix_rx_parse_s *rx =
192 (const struct nix_rx_parse_s *)((const uint64_t *)cq + 1);
193 const uint64_t w1 = *(const uint64_t *)rx;
194 const uint16_t len = rx->pkt_lenm1 + 1;
195 uint64_t ol_flags = 0;
197 /* Mark mempool obj as "get" as it is alloc'ed by NIX */
198 __mempool_check_cookies(mbuf->pool, (void **)&mbuf, 1, 1);
200 if (flag & NIX_RX_OFFLOAD_PTYPE_F)
201 mbuf->packet_type = nix_ptype_get(lookup_mem, w1);
203 mbuf->packet_type = 0;
205 if (flag & NIX_RX_OFFLOAD_RSS_F) {
206 mbuf->hash.rss = tag;
207 ol_flags |= PKT_RX_RSS_HASH;
210 if (flag & NIX_RX_OFFLOAD_CHECKSUM_F)
211 ol_flags |= nix_rx_olflags_get(lookup_mem, w1);
213 if (flag & NIX_RX_OFFLOAD_VLAN_STRIP_F) {
214 if (rx->vtag0_gone) {
215 ol_flags |= PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED;
216 mbuf->vlan_tci = rx->vtag0_tci;
218 if (rx->vtag1_gone) {
219 ol_flags |= PKT_RX_QINQ | PKT_RX_QINQ_STRIPPED;
220 mbuf->vlan_tci_outer = rx->vtag1_tci;
224 if (flag & NIX_RX_OFFLOAD_MARK_UPDATE_F)
225 ol_flags = nix_update_match_id(rx->match_id, ol_flags, mbuf);
227 mbuf->ol_flags = ol_flags;
228 *(uint64_t *)(&mbuf->rearm_data) = val;
231 if (flag & NIX_RX_MULTI_SEG_F)
232 nix_cqe_xtract_mseg(rx, mbuf, val);
234 mbuf->data_len = len;
237 #define CKSUM_F NIX_RX_OFFLOAD_CHECKSUM_F
238 #define PTYPE_F NIX_RX_OFFLOAD_PTYPE_F
239 #define RSS_F NIX_RX_OFFLOAD_RSS_F
240 #define RX_VLAN_F NIX_RX_OFFLOAD_VLAN_STRIP_F
241 #define MARK_F NIX_RX_OFFLOAD_MARK_UPDATE_F
242 #define TS_F NIX_RX_OFFLOAD_TSTAMP_F
244 /* [TSMP] [MARK] [VLAN] [CKSUM] [PTYPE] [RSS] */
245 #define NIX_RX_FASTPATH_MODES \
246 R(no_offload, 0, 0, 0, 0, 0, 0, NIX_RX_OFFLOAD_NONE) \
247 R(rss, 0, 0, 0, 0, 0, 1, RSS_F) \
248 R(ptype, 0, 0, 0, 0, 1, 0, PTYPE_F) \
249 R(ptype_rss, 0, 0, 0, 0, 1, 1, PTYPE_F | RSS_F) \
250 R(cksum, 0, 0, 0, 1, 0, 0, CKSUM_F) \
251 R(cksum_rss, 0, 0, 0, 1, 0, 1, CKSUM_F | RSS_F) \
252 R(cksum_ptype, 0, 0, 0, 1, 1, 0, CKSUM_F | PTYPE_F) \
253 R(cksum_ptype_rss, 0, 0, 0, 1, 1, 1, CKSUM_F | PTYPE_F | RSS_F)\
254 R(vlan, 0, 0, 1, 0, 0, 0, RX_VLAN_F) \
255 R(vlan_rss, 0, 0, 1, 0, 0, 1, RX_VLAN_F | RSS_F) \
256 R(vlan_ptype, 0, 0, 1, 0, 1, 0, RX_VLAN_F | PTYPE_F) \
257 R(vlan_ptype_rss, 0, 0, 1, 0, 1, 1, RX_VLAN_F | PTYPE_F | RSS_F)\
258 R(vlan_cksum, 0, 0, 1, 1, 0, 0, RX_VLAN_F | CKSUM_F) \
259 R(vlan_cksum_rss, 0, 0, 1, 1, 0, 1, RX_VLAN_F | CKSUM_F | RSS_F)\
260 R(vlan_cksum_ptype, 0, 0, 1, 1, 1, 0, \
261 RX_VLAN_F | CKSUM_F | PTYPE_F) \
262 R(vlan_cksum_ptype_rss, 0, 0, 1, 1, 1, 1, \
263 RX_VLAN_F | CKSUM_F | PTYPE_F | RSS_F) \
264 R(mark, 0, 1, 0, 0, 0, 0, MARK_F) \
265 R(mark_rss, 0, 1, 0, 0, 0, 1, MARK_F | RSS_F) \
266 R(mark_ptype, 0, 1, 0, 0, 1, 0, MARK_F | PTYPE_F) \
267 R(mark_ptype_rss, 0, 1, 0, 0, 1, 1, MARK_F | PTYPE_F | RSS_F)\
268 R(mark_cksum, 0, 1, 0, 1, 0, 0, MARK_F | CKSUM_F) \
269 R(mark_cksum_rss, 0, 1, 0, 1, 0, 1, MARK_F | CKSUM_F | RSS_F)\
270 R(mark_cksum_ptype, 0, 1, 0, 1, 1, 0, MARK_F | CKSUM_F | PTYPE_F)\
271 R(mark_cksum_ptype_rss, 0, 1, 0, 1, 1, 1, \
272 MARK_F | CKSUM_F | PTYPE_F | RSS_F) \
273 R(mark_vlan, 0, 1, 1, 0, 0, 0, MARK_F | RX_VLAN_F) \
274 R(mark_vlan_rss, 0, 1, 1, 0, 0, 1, MARK_F | RX_VLAN_F | RSS_F)\
275 R(mark_vlan_ptype, 0, 1, 1, 0, 1, 0, \
276 MARK_F | RX_VLAN_F | PTYPE_F) \
277 R(mark_vlan_ptype_rss, 0, 1, 1, 0, 1, 1, \
278 MARK_F | RX_VLAN_F | PTYPE_F | RSS_F) \
279 R(mark_vlan_cksum, 0, 1, 1, 1, 0, 0, \
280 MARK_F | RX_VLAN_F | CKSUM_F) \
281 R(mark_vlan_cksum_rss, 0, 1, 1, 1, 0, 1, \
282 MARK_F | RX_VLAN_F | CKSUM_F | RSS_F) \
283 R(mark_vlan_cksum_ptype, 0, 1, 1, 1, 1, 0, \
284 MARK_F | RX_VLAN_F | CKSUM_F | PTYPE_F) \
285 R(mark_vlan_cksum_ptype_rss, 0, 1, 1, 1, 1, 1, \
286 MARK_F | RX_VLAN_F | CKSUM_F | PTYPE_F | RSS_F) \
287 R(ts, 1, 0, 0, 0, 0, 0, TS_F) \
288 R(ts_rss, 1, 0, 0, 0, 0, 1, TS_F | RSS_F) \
289 R(ts_ptype, 1, 0, 0, 0, 1, 0, TS_F | PTYPE_F) \
290 R(ts_ptype_rss, 1, 0, 0, 0, 1, 1, TS_F | PTYPE_F | RSS_F)\
291 R(ts_cksum, 1, 0, 0, 1, 0, 0, TS_F | CKSUM_F) \
292 R(ts_cksum_rss, 1, 0, 0, 1, 0, 1, TS_F | CKSUM_F | RSS_F)\
293 R(ts_cksum_ptype, 1, 0, 0, 1, 1, 0, TS_F | CKSUM_F | PTYPE_F)\
294 R(ts_cksum_ptype_rss, 1, 0, 0, 1, 1, 1, \
295 TS_F | CKSUM_F | PTYPE_F | RSS_F) \
296 R(ts_vlan, 1, 0, 1, 0, 0, 0, TS_F | RX_VLAN_F) \
297 R(ts_vlan_rss, 1, 0, 1, 0, 0, 1, TS_F | RX_VLAN_F | RSS_F)\
298 R(ts_vlan_ptype, 1, 0, 1, 0, 1, 0, TS_F | RX_VLAN_F | PTYPE_F)\
299 R(ts_vlan_ptype_rss, 1, 0, 1, 0, 1, 1, \
300 TS_F | RX_VLAN_F | PTYPE_F | RSS_F) \
301 R(ts_vlan_cksum, 1, 0, 1, 1, 0, 0, \
302 TS_F | RX_VLAN_F | CKSUM_F) \
303 R(ts_vlan_cksum_rss, 1, 0, 1, 1, 0, 1, \
304 MARK_F | RX_VLAN_F | CKSUM_F | RSS_F) \
305 R(ts_vlan_cksum_ptype, 1, 0, 1, 1, 1, 0, \
306 TS_F | RX_VLAN_F | CKSUM_F | PTYPE_F) \
307 R(ts_vlan_cksum_ptype_rss, 1, 0, 1, 1, 1, 1, \
308 TS_F | RX_VLAN_F | CKSUM_F | PTYPE_F | RSS_F) \
309 R(ts_mark, 1, 1, 0, 0, 0, 0, TS_F | MARK_F) \
310 R(ts_mark_rss, 1, 1, 0, 0, 0, 1, TS_F | MARK_F | RSS_F)\
311 R(ts_mark_ptype, 1, 1, 0, 0, 1, 0, TS_F | MARK_F | PTYPE_F)\
312 R(ts_mark_ptype_rss, 1, 1, 0, 0, 1, 1, \
313 TS_F | MARK_F | PTYPE_F | RSS_F) \
314 R(ts_mark_cksum, 1, 1, 0, 1, 0, 0, TS_F | MARK_F | CKSUM_F)\
315 R(ts_mark_cksum_rss, 1, 1, 0, 1, 0, 1, \
316 TS_F | MARK_F | CKSUM_F | RSS_F)\
317 R(ts_mark_cksum_ptype, 1, 1, 0, 1, 1, 0, \
318 TS_F | MARK_F | CKSUM_F | PTYPE_F) \
319 R(ts_mark_cksum_ptype_rss, 1, 1, 0, 1, 1, 1, \
320 TS_F | MARK_F | CKSUM_F | PTYPE_F | RSS_F) \
321 R(ts_mark_vlan, 1, 1, 1, 0, 0, 0, TS_F | MARK_F | RX_VLAN_F)\
322 R(ts_mark_vlan_rss, 1, 1, 1, 0, 0, 1, \
323 TS_F | MARK_F | RX_VLAN_F | RSS_F)\
324 R(ts_mark_vlan_ptype, 1, 1, 1, 0, 1, 0, \
325 TS_F | MARK_F | RX_VLAN_F | PTYPE_F) \
326 R(ts_mark_vlan_ptype_rss, 1, 1, 1, 0, 1, 1, \
327 TS_F | MARK_F | RX_VLAN_F | PTYPE_F | RSS_F) \
328 R(ts_mark_vlan_cksum_ptype, 1, 1, 1, 1, 1, 0, \
329 TS_F | MARK_F | RX_VLAN_F | CKSUM_F | PTYPE_F) \
330 R(ts_mark_vlan_cksum_ptype_rss, 1, 1, 1, 1, 1, 1, \
331 TS_F | MARK_F | RX_VLAN_F | CKSUM_F | PTYPE_F | RSS_F)
333 #endif /* __OTX2_RX_H__ */