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,
56 if ((flag & NIX_RX_OFFLOAD_TSTAMP_F) &&
57 (mbuf->data_off == RTE_PKTMBUF_HEADROOM +
58 NIX_TIMESYNC_RX_OFFSET)) {
60 /* Reading the rx timestamp inserted by CGX, viz at
61 * starting of the packet data.
63 mbuf->timestamp = rte_be_to_cpu_64(*tstamp_ptr);
64 /* PKT_RX_IEEE1588_TMST flag needs to be set only in case
65 * PTP packets are received.
67 if (mbuf->packet_type == RTE_PTYPE_L2_ETHER_TIMESYNC) {
68 tstamp->rx_tstamp = mbuf->timestamp;
70 mbuf->ol_flags |= PKT_RX_IEEE1588_PTP |
71 PKT_RX_IEEE1588_TMST | PKT_RX_TIMESTAMP;
76 static __rte_always_inline uint64_t
77 nix_clear_data_off(uint64_t oldval)
79 union mbuf_initializer mbuf_init = { .value = oldval };
81 mbuf_init.fields.data_off = 0;
82 return mbuf_init.value;
85 static __rte_always_inline struct rte_mbuf *
86 nix_get_mbuf_from_cqe(void *cq, const uint64_t data_off)
90 /* Skip CQE, NIX_RX_PARSE_S and SG HDR(9 DWORDs) and peek buff addr */
91 buff = *((rte_iova_t *)((uint64_t *)cq + 9));
92 return (struct rte_mbuf *)(buff - data_off);
96 static __rte_always_inline uint32_t
97 nix_ptype_get(const void * const lookup_mem, const uint64_t in)
99 const uint16_t * const ptype = lookup_mem;
100 const uint16_t lg_lf_le = (in & 0xFFF000000000000) >> 48;
101 const uint16_t tu_l2 = ptype[(in & 0x000FFF000000000) >> 36];
102 const uint16_t il4_tu = ptype[PTYPE_NON_TUNNEL_ARRAY_SZ + lg_lf_le];
104 return (il4_tu << PTYPE_WIDTH) | tu_l2;
107 static __rte_always_inline uint32_t
108 nix_rx_olflags_get(const void * const lookup_mem, const uint64_t in)
110 const uint32_t * const ol_flags = (const uint32_t *)
111 ((const uint8_t *)lookup_mem + PTYPE_ARRAY_SZ);
113 return ol_flags[(in & 0xfff00000) >> 20];
116 static inline uint64_t
117 nix_update_match_id(const uint16_t match_id, uint64_t ol_flags,
118 struct rte_mbuf *mbuf)
120 /* There is no separate bit to check match_id
121 * is valid or not? and no flag to identify it is an
122 * RTE_FLOW_ACTION_TYPE_FLAG vs RTE_FLOW_ACTION_TYPE_MARK
123 * action. The former case addressed through 0 being invalid
124 * value and inc/dec match_id pair when MARK is activated.
125 * The later case addressed through defining
126 * OTX2_FLOW_MARK_DEFAULT as value for
127 * RTE_FLOW_ACTION_TYPE_MARK.
128 * This would translate to not use
129 * OTX2_FLOW_ACTION_FLAG_DEFAULT - 1 and
130 * OTX2_FLOW_ACTION_FLAG_DEFAULT for match_id.
131 * i.e valid mark_id's are from
132 * 0 to OTX2_FLOW_ACTION_FLAG_DEFAULT - 2
134 if (likely(match_id)) {
135 ol_flags |= PKT_RX_FDIR;
136 if (match_id != OTX2_FLOW_ACTION_FLAG_DEFAULT) {
137 ol_flags |= PKT_RX_FDIR_ID;
138 mbuf->hash.fdir.hi = match_id - 1;
145 static __rte_always_inline void
146 nix_cqe_xtract_mseg(const struct nix_rx_parse_s *rx,
147 struct rte_mbuf *mbuf, uint64_t rearm)
149 const rte_iova_t *iova_list;
150 struct rte_mbuf *head;
151 const rte_iova_t *eol;
155 sg = *(const uint64_t *)(rx + 1);
156 nb_segs = (sg >> 48) & 0x3;
157 mbuf->nb_segs = nb_segs;
158 mbuf->data_len = sg & 0xFFFF;
161 eol = ((const rte_iova_t *)(rx + 1) + ((rx->desc_sizem1 + 1) << 1));
162 /* Skip SG_S and first IOVA*/
163 iova_list = ((const rte_iova_t *)(rx + 1)) + 2;
166 rearm = rearm & ~0xFFFF;
170 mbuf->next = ((struct rte_mbuf *)*iova_list) - 1;
173 __mempool_check_cookies(mbuf->pool, (void **)&mbuf, 1, 1);
175 mbuf->data_len = sg & 0xFFFF;
177 *(uint64_t *)(&mbuf->rearm_data) = rearm;
181 if (!nb_segs && (iova_list + 1 < eol)) {
182 sg = *(const uint64_t *)(iova_list);
183 nb_segs = (sg >> 48) & 0x3;
184 head->nb_segs += nb_segs;
185 iova_list = (const rte_iova_t *)(iova_list + 1);
190 static __rte_always_inline void
191 otx2_nix_cqe_to_mbuf(const struct nix_cqe_hdr_s *cq, const uint32_t tag,
192 struct rte_mbuf *mbuf, const void *lookup_mem,
193 const uint64_t val, const uint16_t flag)
195 const struct nix_rx_parse_s *rx =
196 (const struct nix_rx_parse_s *)((const uint64_t *)cq + 1);
197 const uint64_t w1 = *(const uint64_t *)rx;
198 const uint16_t len = rx->pkt_lenm1 + 1;
199 uint64_t ol_flags = 0;
201 /* Mark mempool obj as "get" as it is alloc'ed by NIX */
202 __mempool_check_cookies(mbuf->pool, (void **)&mbuf, 1, 1);
204 if (flag & NIX_RX_OFFLOAD_PTYPE_F)
205 mbuf->packet_type = nix_ptype_get(lookup_mem, w1);
207 mbuf->packet_type = 0;
209 if (flag & NIX_RX_OFFLOAD_RSS_F) {
210 mbuf->hash.rss = tag;
211 ol_flags |= PKT_RX_RSS_HASH;
214 if (flag & NIX_RX_OFFLOAD_CHECKSUM_F)
215 ol_flags |= nix_rx_olflags_get(lookup_mem, w1);
217 if (flag & NIX_RX_OFFLOAD_VLAN_STRIP_F) {
218 if (rx->vtag0_gone) {
219 ol_flags |= PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED;
220 mbuf->vlan_tci = rx->vtag0_tci;
222 if (rx->vtag1_gone) {
223 ol_flags |= PKT_RX_QINQ | PKT_RX_QINQ_STRIPPED;
224 mbuf->vlan_tci_outer = rx->vtag1_tci;
228 if (flag & NIX_RX_OFFLOAD_MARK_UPDATE_F)
229 ol_flags = nix_update_match_id(rx->match_id, ol_flags, mbuf);
231 mbuf->ol_flags = ol_flags;
232 *(uint64_t *)(&mbuf->rearm_data) = val;
235 if (flag & NIX_RX_MULTI_SEG_F)
236 nix_cqe_xtract_mseg(rx, mbuf, val);
238 mbuf->data_len = len;
241 #define CKSUM_F NIX_RX_OFFLOAD_CHECKSUM_F
242 #define PTYPE_F NIX_RX_OFFLOAD_PTYPE_F
243 #define RSS_F NIX_RX_OFFLOAD_RSS_F
244 #define RX_VLAN_F NIX_RX_OFFLOAD_VLAN_STRIP_F
245 #define MARK_F NIX_RX_OFFLOAD_MARK_UPDATE_F
246 #define TS_F NIX_RX_OFFLOAD_TSTAMP_F
248 /* [TSMP] [MARK] [VLAN] [CKSUM] [PTYPE] [RSS] */
249 #define NIX_RX_FASTPATH_MODES \
250 R(no_offload, 0, 0, 0, 0, 0, 0, NIX_RX_OFFLOAD_NONE) \
251 R(rss, 0, 0, 0, 0, 0, 1, RSS_F) \
252 R(ptype, 0, 0, 0, 0, 1, 0, PTYPE_F) \
253 R(ptype_rss, 0, 0, 0, 0, 1, 1, PTYPE_F | RSS_F) \
254 R(cksum, 0, 0, 0, 1, 0, 0, CKSUM_F) \
255 R(cksum_rss, 0, 0, 0, 1, 0, 1, CKSUM_F | RSS_F) \
256 R(cksum_ptype, 0, 0, 0, 1, 1, 0, CKSUM_F | PTYPE_F) \
257 R(cksum_ptype_rss, 0, 0, 0, 1, 1, 1, CKSUM_F | PTYPE_F | RSS_F)\
258 R(vlan, 0, 0, 1, 0, 0, 0, RX_VLAN_F) \
259 R(vlan_rss, 0, 0, 1, 0, 0, 1, RX_VLAN_F | RSS_F) \
260 R(vlan_ptype, 0, 0, 1, 0, 1, 0, RX_VLAN_F | PTYPE_F) \
261 R(vlan_ptype_rss, 0, 0, 1, 0, 1, 1, RX_VLAN_F | PTYPE_F | RSS_F)\
262 R(vlan_cksum, 0, 0, 1, 1, 0, 0, RX_VLAN_F | CKSUM_F) \
263 R(vlan_cksum_rss, 0, 0, 1, 1, 0, 1, RX_VLAN_F | CKSUM_F | RSS_F)\
264 R(vlan_cksum_ptype, 0, 0, 1, 1, 1, 0, \
265 RX_VLAN_F | CKSUM_F | PTYPE_F) \
266 R(vlan_cksum_ptype_rss, 0, 0, 1, 1, 1, 1, \
267 RX_VLAN_F | CKSUM_F | PTYPE_F | RSS_F) \
268 R(mark, 0, 1, 0, 0, 0, 0, MARK_F) \
269 R(mark_rss, 0, 1, 0, 0, 0, 1, MARK_F | RSS_F) \
270 R(mark_ptype, 0, 1, 0, 0, 1, 0, MARK_F | PTYPE_F) \
271 R(mark_ptype_rss, 0, 1, 0, 0, 1, 1, MARK_F | PTYPE_F | RSS_F)\
272 R(mark_cksum, 0, 1, 0, 1, 0, 0, MARK_F | CKSUM_F) \
273 R(mark_cksum_rss, 0, 1, 0, 1, 0, 1, MARK_F | CKSUM_F | RSS_F)\
274 R(mark_cksum_ptype, 0, 1, 0, 1, 1, 0, MARK_F | CKSUM_F | PTYPE_F)\
275 R(mark_cksum_ptype_rss, 0, 1, 0, 1, 1, 1, \
276 MARK_F | CKSUM_F | PTYPE_F | RSS_F) \
277 R(mark_vlan, 0, 1, 1, 0, 0, 0, MARK_F | RX_VLAN_F) \
278 R(mark_vlan_rss, 0, 1, 1, 0, 0, 1, MARK_F | RX_VLAN_F | RSS_F)\
279 R(mark_vlan_ptype, 0, 1, 1, 0, 1, 0, \
280 MARK_F | RX_VLAN_F | PTYPE_F) \
281 R(mark_vlan_ptype_rss, 0, 1, 1, 0, 1, 1, \
282 MARK_F | RX_VLAN_F | PTYPE_F | RSS_F) \
283 R(mark_vlan_cksum, 0, 1, 1, 1, 0, 0, \
284 MARK_F | RX_VLAN_F | CKSUM_F) \
285 R(mark_vlan_cksum_rss, 0, 1, 1, 1, 0, 1, \
286 MARK_F | RX_VLAN_F | CKSUM_F | RSS_F) \
287 R(mark_vlan_cksum_ptype, 0, 1, 1, 1, 1, 0, \
288 MARK_F | RX_VLAN_F | CKSUM_F | PTYPE_F) \
289 R(mark_vlan_cksum_ptype_rss, 0, 1, 1, 1, 1, 1, \
290 MARK_F | RX_VLAN_F | CKSUM_F | PTYPE_F | RSS_F) \
291 R(ts, 1, 0, 0, 0, 0, 0, TS_F) \
292 R(ts_rss, 1, 0, 0, 0, 0, 1, TS_F | RSS_F) \
293 R(ts_ptype, 1, 0, 0, 0, 1, 0, TS_F | PTYPE_F) \
294 R(ts_ptype_rss, 1, 0, 0, 0, 1, 1, TS_F | PTYPE_F | RSS_F)\
295 R(ts_cksum, 1, 0, 0, 1, 0, 0, TS_F | CKSUM_F) \
296 R(ts_cksum_rss, 1, 0, 0, 1, 0, 1, TS_F | CKSUM_F | RSS_F)\
297 R(ts_cksum_ptype, 1, 0, 0, 1, 1, 0, TS_F | CKSUM_F | PTYPE_F)\
298 R(ts_cksum_ptype_rss, 1, 0, 0, 1, 1, 1, \
299 TS_F | CKSUM_F | PTYPE_F | RSS_F) \
300 R(ts_vlan, 1, 0, 1, 0, 0, 0, TS_F | RX_VLAN_F) \
301 R(ts_vlan_rss, 1, 0, 1, 0, 0, 1, TS_F | RX_VLAN_F | RSS_F)\
302 R(ts_vlan_ptype, 1, 0, 1, 0, 1, 0, TS_F | RX_VLAN_F | PTYPE_F)\
303 R(ts_vlan_ptype_rss, 1, 0, 1, 0, 1, 1, \
304 TS_F | RX_VLAN_F | PTYPE_F | RSS_F) \
305 R(ts_vlan_cksum, 1, 0, 1, 1, 0, 0, \
306 TS_F | RX_VLAN_F | CKSUM_F) \
307 R(ts_vlan_cksum_rss, 1, 0, 1, 1, 0, 1, \
308 MARK_F | RX_VLAN_F | CKSUM_F | RSS_F) \
309 R(ts_vlan_cksum_ptype, 1, 0, 1, 1, 1, 0, \
310 TS_F | RX_VLAN_F | CKSUM_F | PTYPE_F) \
311 R(ts_vlan_cksum_ptype_rss, 1, 0, 1, 1, 1, 1, \
312 TS_F | RX_VLAN_F | CKSUM_F | PTYPE_F | RSS_F) \
313 R(ts_mark, 1, 1, 0, 0, 0, 0, TS_F | MARK_F) \
314 R(ts_mark_rss, 1, 1, 0, 0, 0, 1, TS_F | MARK_F | RSS_F)\
315 R(ts_mark_ptype, 1, 1, 0, 0, 1, 0, TS_F | MARK_F | PTYPE_F)\
316 R(ts_mark_ptype_rss, 1, 1, 0, 0, 1, 1, \
317 TS_F | MARK_F | PTYPE_F | RSS_F) \
318 R(ts_mark_cksum, 1, 1, 0, 1, 0, 0, TS_F | MARK_F | CKSUM_F)\
319 R(ts_mark_cksum_rss, 1, 1, 0, 1, 0, 1, \
320 TS_F | MARK_F | CKSUM_F | RSS_F)\
321 R(ts_mark_cksum_ptype, 1, 1, 0, 1, 1, 0, \
322 TS_F | MARK_F | CKSUM_F | PTYPE_F) \
323 R(ts_mark_cksum_ptype_rss, 1, 1, 0, 1, 1, 1, \
324 TS_F | MARK_F | CKSUM_F | PTYPE_F | RSS_F) \
325 R(ts_mark_vlan, 1, 1, 1, 0, 0, 0, TS_F | MARK_F | RX_VLAN_F)\
326 R(ts_mark_vlan_rss, 1, 1, 1, 0, 0, 1, \
327 TS_F | MARK_F | RX_VLAN_F | RSS_F)\
328 R(ts_mark_vlan_ptype, 1, 1, 1, 0, 1, 0, \
329 TS_F | MARK_F | RX_VLAN_F | PTYPE_F) \
330 R(ts_mark_vlan_ptype_rss, 1, 1, 1, 0, 1, 1, \
331 TS_F | MARK_F | RX_VLAN_F | PTYPE_F | RSS_F) \
332 R(ts_mark_vlan_cksum_ptype, 1, 1, 1, 1, 1, 0, \
333 TS_F | MARK_F | RX_VLAN_F | CKSUM_F | PTYPE_F) \
334 R(ts_mark_vlan_cksum_ptype_rss, 1, 1, 1, 1, 1, 1, \
335 TS_F | MARK_F | RX_VLAN_F | CKSUM_F | PTYPE_F | RSS_F)
337 #endif /* __OTX2_RX_H__ */