Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2021 Marvell.
3 : : */
4 : :
5 : : #include <eal_export.h>
6 : : #include <rte_pmd_cnxk.h>
7 : :
8 : : #include <cnxk_ethdev.h>
9 : : #include <cnxk_mempool.h>
10 : :
11 : : #define CNXK_NIX_INL_META_POOL_NAME "NIX_INL_META_POOL"
12 : : #define CN10K_HW_POOL_OPS_NAME "cn10k_hwpool_ops"
13 : :
14 : : #define CNXK_NIX_INL_SELFTEST "selftest"
15 : : #define CNXK_NIX_INL_IPSEC_IN_MIN_SPI "ipsec_in_min_spi"
16 : : #define CNXK_NIX_INL_IPSEC_IN_MAX_SPI "ipsec_in_max_spi"
17 : : #define CNXK_INL_CPT_CHANNEL "inl_cpt_channel"
18 : : #define CNXK_NIX_INL_NB_META_BUFS "nb_meta_bufs"
19 : : #define CNXK_NIX_INL_META_BUF_SZ "meta_buf_sz"
20 : : #define CNXK_NIX_SOFT_EXP_POLL_FREQ "soft_exp_poll_freq"
21 : : #define CNXK_MAX_IPSEC_RULES "max_ipsec_rules"
22 : : #define CNXK_NIX_INL_RX_INJ_ENABLE "rx_inj_ena"
23 : : #define CNXK_NIX_CUSTOM_INB_SA "custom_inb_sa"
24 : : #define CNXK_NIX_NB_INL_INB_QS "nb_inl_inb_qs"
25 : : #define CNXK_NIX_INL_CPT_CQ_ENABLE "cpt_cq_enable"
26 : :
27 : : /* Default soft expiry poll freq in usec */
28 : : #define CNXK_NIX_SOFT_EXP_POLL_FREQ_DFLT 100
29 : :
30 : : struct inl_cpt_channel {
31 : : bool is_multi_channel;
32 : : uint16_t channel;
33 : : uint16_t mask;
34 : : };
35 : :
36 : : #define CNXK_NIX_INL_DEV_NAME RTE_STR(cnxk_nix_inl_dev_)
37 : : #define CNXK_NIX_INL_DEV_NAME_LEN \
38 : : (sizeof(CNXK_NIX_INL_DEV_NAME) + PCI_PRI_STR_SIZE)
39 : :
40 : : struct cnxk_ethdev_pmd_ops cnxk_pmd_ops;
41 : :
42 : : static inline int
43 : : bitmap_ctzll(uint64_t slab)
44 : : {
45 : 0 : if (slab == 0)
46 : : return 0;
47 : :
48 : 0 : return rte_ctz64(slab);
49 : : }
50 : :
51 : : int
52 : 0 : cnxk_nix_inl_meta_pool_cb(uint64_t *aura_handle, uintptr_t *mpool, uint32_t buf_sz,
53 : : uint32_t nb_bufs, bool destroy, const char *mempool_name)
54 : : {
55 : : const char *mp_name = NULL;
56 : : struct rte_pktmbuf_pool_private mbp_priv;
57 : : struct rte_mempool *mp;
58 : : uint16_t first_skip;
59 : : int rc;
60 : :
61 : : /* Null Mempool name indicates to allocate Zero aura. */
62 [ # # ]: 0 : if (!mempool_name)
63 : : mp_name = CNXK_NIX_INL_META_POOL_NAME;
64 : : else
65 : : mp_name = mempool_name;
66 : :
67 : : /* Destroy the mempool if requested */
68 [ # # ]: 0 : if (destroy) {
69 : 0 : mp = rte_mempool_lookup(mp_name);
70 [ # # ]: 0 : if (!mp)
71 : : return -ENOENT;
72 : :
73 [ # # ]: 0 : if (mp->pool_id != *aura_handle) {
74 : 0 : plt_err("Meta pool aura mismatch");
75 : 0 : return -EINVAL;
76 : : }
77 : :
78 : 0 : rte_mempool_free(mp);
79 : :
80 : 0 : *aura_handle = 0;
81 : 0 : *mpool = 0;
82 : 0 : return 0;
83 : : }
84 : :
85 : : /* Need to make it similar to rte_pktmbuf_pool() for sake of OOP
86 : : * support.
87 : : */
88 : 0 : mp = rte_mempool_create_empty(mp_name, nb_bufs, buf_sz, 0,
89 : : sizeof(struct rte_pktmbuf_pool_private),
90 : : SOCKET_ID_ANY, 0);
91 [ # # ]: 0 : if (!mp) {
92 : 0 : plt_err("Failed to create inline meta pool");
93 : 0 : return -EIO;
94 : : }
95 : :
96 [ # # ]: 0 : rc = rte_mempool_set_ops_byname(mp, rte_mbuf_platform_mempool_ops(),
97 : : mempool_name ?
98 : : NULL : PLT_PTR_CAST(CNXK_MEMPOOL_F_ZERO_AURA));
99 [ # # ]: 0 : if (rc) {
100 : 0 : plt_err("Failed to setup mempool ops for meta, rc=%d", rc);
101 : 0 : goto free_mp;
102 : : }
103 : :
104 : : /* Init mempool private area */
105 : : first_skip = sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM;
106 : : memset(&mbp_priv, 0, sizeof(mbp_priv));
107 : 0 : mbp_priv.mbuf_data_room_size = (buf_sz - first_skip +
108 : : RTE_PKTMBUF_HEADROOM);
109 : 0 : rte_pktmbuf_pool_init(mp, &mbp_priv);
110 : :
111 : : /* Populate buffer */
112 : 0 : rc = rte_mempool_populate_default(mp);
113 [ # # ]: 0 : if (rc < 0) {
114 : 0 : plt_err("Failed to create inline meta pool, rc=%d", rc);
115 : 0 : goto free_mp;
116 : : }
117 : :
118 : 0 : rte_mempool_obj_iter(mp, rte_pktmbuf_init, NULL);
119 : 0 : *aura_handle = mp->pool_id;
120 : 0 : *mpool = (uintptr_t)mp;
121 : 0 : return 0;
122 : 0 : free_mp:
123 : 0 : rte_mempool_free(mp);
124 : 0 : return rc;
125 : : }
126 : :
127 : : /* Create Aura and link with Global mempool for 1:N Pool:Aura case */
128 : : int
129 : 0 : cnxk_nix_inl_custom_meta_pool_cb(uintptr_t pmpool, uintptr_t *mpool, const char *mempool_name,
130 : : uint64_t *aura_handle, uint32_t buf_sz, uint32_t nb_bufs,
131 : : bool destroy)
132 : : {
133 : : struct rte_mempool *hp;
134 : : int rc;
135 : :
136 : : /* Destroy the mempool if requested */
137 [ # # ]: 0 : if (destroy) {
138 : 0 : hp = rte_mempool_lookup(mempool_name);
139 [ # # ]: 0 : if (!hp)
140 : : return -ENOENT;
141 : :
142 [ # # ]: 0 : if (hp->pool_id != *aura_handle) {
143 : 0 : plt_err("Meta pool aura mismatch");
144 : 0 : return -EINVAL;
145 : : }
146 : :
147 : 0 : plt_free(hp->pool_config);
148 : 0 : rte_mempool_free(hp);
149 : :
150 : 0 : *aura_handle = 0;
151 : 0 : *mpool = 0;
152 : 0 : return 0;
153 : : }
154 : :
155 : : /* Need to make it similar to rte_pktmbuf_pool() for sake of OOP
156 : : * support.
157 : : */
158 : 0 : hp = rte_mempool_create_empty(mempool_name, nb_bufs, buf_sz, 0,
159 : : sizeof(struct rte_pktmbuf_pool_private),
160 : : SOCKET_ID_ANY, 0);
161 [ # # ]: 0 : if (!hp) {
162 : 0 : plt_err("Failed to create inline meta pool");
163 : 0 : return -EIO;
164 : : }
165 : :
166 : 0 : rc = rte_mempool_set_ops_byname(hp, CN10K_HW_POOL_OPS_NAME, (void *)pmpool);
167 : :
168 [ # # ]: 0 : if (rc) {
169 : 0 : plt_err("Failed to setup ops, rc=%d", rc);
170 : 0 : goto free_hp;
171 : : }
172 : :
173 : : /* Populate buffer */
174 : 0 : rc = rte_mempool_populate_default(hp);
175 [ # # ]: 0 : if (rc < 0) {
176 : 0 : plt_err("Failed to populate pool, rc=%d", rc);
177 : 0 : goto free_hp;
178 : : }
179 : :
180 : 0 : *aura_handle = hp->pool_id;
181 : 0 : *mpool = (uintptr_t)hp;
182 : 0 : return 0;
183 : 0 : free_hp:
184 : 0 : rte_mempool_free(hp);
185 : 0 : return rc;
186 : : }
187 : :
188 : : static int
189 : 0 : parse_max_ipsec_rules(const char *key, const char *value, void *extra_args)
190 : : {
191 : : RTE_SET_USED(key);
192 : : uint32_t val;
193 : :
194 : 0 : val = atoi(value);
195 : :
196 [ # # ]: 0 : if (val < 1 || val > 4095)
197 : : return -EINVAL;
198 : :
199 : 0 : *(uint32_t *)extra_args = val;
200 : :
201 : 0 : return 0;
202 : : }
203 : :
204 : : static int
205 : 0 : parse_val_u8(const char *key, const char *value, void *extra_args)
206 : : {
207 : : RTE_SET_USED(key);
208 : : uint32_t val;
209 : :
210 : 0 : val = atoi(value);
211 : :
212 : 0 : *(uint8_t *)extra_args = !!(val == 1);
213 : :
214 : 0 : return 0;
215 : : }
216 : :
217 : : int
218 : 0 : cnxk_eth_outb_sa_idx_get(struct cnxk_eth_dev *dev, uint32_t *idx_p,
219 : : uint32_t spi)
220 : : {
221 : : uint32_t pos, idx;
222 : : uint64_t slab;
223 : : int rc;
224 : :
225 [ # # ]: 0 : if (!dev->outb.sa_bmap)
226 : : return -ENOTSUP;
227 : :
228 : 0 : pos = 0;
229 [ # # ]: 0 : slab = 0;
230 : : /* Scan from the beginning */
231 : : plt_bitmap_scan_init(dev->outb.sa_bmap);
232 : :
233 [ # # ]: 0 : if (dev->nix.custom_sa_action) {
234 [ # # ]: 0 : if (spi > dev->outb.max_sa)
235 : : return -ENOTSUP;
236 : : idx = spi;
237 [ # # ]: 0 : if (!plt_bitmap_get(dev->outb.sa_bmap, idx)) {
238 : 0 : plt_err("Outbound SA index %u already in use", idx);
239 : 0 : return -EEXIST;
240 : : }
241 : : } else {
242 : : /* Scan bitmap to get the free sa index */
243 : 0 : rc = plt_bitmap_scan(dev->outb.sa_bmap, &pos, &slab);
244 : : /* Empty bitmap */
245 [ # # ]: 0 : if (rc == 0) {
246 : 0 : plt_err("Outbound SA' exhausted, use 'ipsec_out_max_sa' "
247 : : "devargs to increase");
248 : 0 : return -ERANGE;
249 : : }
250 : :
251 : : /* Get free SA index */
252 [ # # ]: 0 : idx = pos + bitmap_ctzll(slab);
253 : : }
254 : 0 : plt_bitmap_clear(dev->outb.sa_bmap, idx);
255 : 0 : *idx_p = idx;
256 : 0 : return 0;
257 : : }
258 : :
259 : : int
260 : 0 : cnxk_eth_outb_sa_idx_put(struct cnxk_eth_dev *dev, uint32_t idx)
261 : : {
262 [ # # ]: 0 : if (idx >= dev->outb.max_sa)
263 : : return -EINVAL;
264 : :
265 : : /* Check if it is already free */
266 [ # # ]: 0 : if (plt_bitmap_get(dev->outb.sa_bmap, idx))
267 : : return -EINVAL;
268 : :
269 : : /* Mark index as free */
270 : 0 : plt_bitmap_set(dev->outb.sa_bmap, idx);
271 : 0 : return 0;
272 : : }
273 : :
274 : : struct cnxk_eth_sec_sess *
275 : 0 : cnxk_eth_sec_sess_get_by_sa_idx(struct cnxk_eth_dev *dev, uint32_t sa_idx, bool inb)
276 : : {
277 : : struct cnxk_eth_sec_sess_list *list;
278 : : struct cnxk_eth_sec_sess *eth_sec;
279 : :
280 [ # # ]: 0 : list = inb ? &dev->inb.list : &dev->outb.list;
281 [ # # ]: 0 : TAILQ_FOREACH(eth_sec, list, entry) {
282 [ # # ]: 0 : if (eth_sec->sa_idx == sa_idx)
283 : 0 : return eth_sec;
284 : : }
285 : :
286 : : return NULL;
287 : : }
288 : :
289 : : struct cnxk_eth_sec_sess *
290 : 0 : cnxk_eth_sec_sess_get_by_sess(struct cnxk_eth_dev *dev, const struct rte_security_session *sess)
291 : : {
292 : : struct cnxk_eth_sec_sess *eth_sec = NULL;
293 : :
294 : : /* Search in inbound list */
295 [ # # ]: 0 : TAILQ_FOREACH(eth_sec, &dev->inb.list, entry) {
296 [ # # ]: 0 : if (eth_sec->sess == sess)
297 : 0 : return eth_sec;
298 : : }
299 : :
300 : : /* Search in outbound list */
301 [ # # ]: 0 : TAILQ_FOREACH(eth_sec, &dev->outb.list, entry) {
302 [ # # ]: 0 : if (eth_sec->sess == sess)
303 : 0 : return eth_sec;
304 : : }
305 : :
306 : : return NULL;
307 : : }
308 : :
309 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_inl_dev_submit, 23.11)
310 : : uint16_t
311 : 0 : rte_pmd_cnxk_inl_dev_submit(struct rte_pmd_cnxk_inl_dev_q *qptr, void *inst, uint16_t nb_inst)
312 : : {
313 : 0 : return cnxk_pmd_ops.inl_dev_submit((struct roc_nix_inl_dev_q *)qptr, inst, nb_inst);
314 : : }
315 : :
316 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_inl_dev_qptr_get, 23.11)
317 : : struct rte_pmd_cnxk_inl_dev_q *
318 : 0 : rte_pmd_cnxk_inl_dev_qptr_get(void)
319 : : {
320 : 0 : return roc_nix_inl_dev_qptr_get(0);
321 : : }
322 : :
323 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_cpt_q_stats_get, 23.11)
324 : : int
325 : 0 : rte_pmd_cnxk_cpt_q_stats_get(uint16_t portid, enum rte_pmd_cnxk_cpt_q_stats_type type,
326 : : struct rte_pmd_cnxk_cpt_q_stats *stats, uint16_t idx)
327 : : {
328 : 0 : struct rte_eth_dev *eth_dev = &rte_eth_devices[portid];
329 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
330 : :
331 : 0 : return roc_nix_inl_cpt_lf_stats_get(&dev->nix, (enum roc_nix_cpt_lf_stats_type)type,
332 : : (struct roc_nix_cpt_lf_stats *)stats, idx);
333 : : }
334 : :
335 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_hw_session_base_get, 23.11)
336 : : union rte_pmd_cnxk_ipsec_hw_sa *
337 : 0 : rte_pmd_cnxk_hw_session_base_get(uint16_t portid, bool inb)
338 : : {
339 [ # # ]: 0 : struct rte_eth_dev *eth_dev = &rte_eth_devices[portid];
340 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
341 : : uintptr_t sa_base;
342 : :
343 [ # # ]: 0 : if (inb)
344 : 0 : sa_base = roc_nix_inl_inb_sa_base_get(&dev->nix, dev->inb.inl_dev);
345 : : else
346 : 0 : sa_base = roc_nix_inl_outb_sa_base_get(&dev->nix);
347 : :
348 : 0 : return (union rte_pmd_cnxk_ipsec_hw_sa *)sa_base;
349 : : }
350 : :
351 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_inl_inb_prof_sa_base_get, 25.11)
352 : : union rte_pmd_cnxk_ipsec_hw_sa *
353 : 0 : rte_pmd_cnxk_inl_inb_prof_sa_base_get(uint16_t portid, uint16_t profile_id)
354 : : {
355 : : struct rte_eth_dev *eth_dev;
356 : : struct cnxk_eth_dev *dev;
357 : : uintptr_t sa_base;
358 : :
359 [ # # ]: 0 : if (!rte_eth_dev_is_valid_port(portid))
360 : : return NULL;
361 : :
362 : : eth_dev = &rte_eth_devices[portid];
363 : : dev = cnxk_eth_pmd_priv(eth_dev);
364 : :
365 : : /* Return IPsec sa base if profile_id is UINT16_MAX, else return the sa base
366 : : * for the given profile_id.
367 : : */
368 [ # # ]: 0 : if (profile_id == UINT16_MAX)
369 : 0 : sa_base = roc_nix_inl_inb_sa_base_get(&dev->nix, dev->inb.inl_dev);
370 : : else
371 : 0 : sa_base = roc_nix_inl_inb_prof_sa_base_get(&dev->nix, !dev->inb.no_inl_dev,
372 : 0 : profile_id);
373 : :
374 [ # # ]: 0 : if (!sa_base)
375 : : return NULL;
376 : :
377 : 0 : return (union rte_pmd_cnxk_ipsec_hw_sa *)sa_base;
378 : : }
379 : :
380 : : static uint64_t
381 : 0 : cnxk_rx_def_inl_cfg_pack(const struct rte_pmd_cnxk_rx_def_inl_cfg *cfg)
382 : : {
383 : : uint64_t val = 0;
384 : :
385 : 0 : val |= PACK(cfg->ltype_mask, NIX_LTYPE_MASK_SHIFT, 4);
386 : 0 : val |= PACK(cfg->ltype_match, NIX_LTYPE_MATCH_SHIFT, 4);
387 : 0 : val |= PACK(cfg->lid, NIX_LID_SHIFT, 3);
388 : 0 : val |= PACK(cfg->gen_offset_ng, NIX_GEN_OFFSET_NG_SHIFT, 1);
389 : 0 : val |= PACK(cfg->gen_offset, NIX_GEN_OFFSET_SHIFT, 4);
390 : 0 : val |= PACK(cfg->gen_nz, NIX_GEN_NZ_SHIFT, 1);
391 : 0 : val |= PACK(cfg->cpt_l3_lid, NIX_CPT_L3_LID_SHIFT, 3);
392 : 0 : val |= PACK(cfg->flags_mask, NIX_FLAGS_MASK_SHIFT, 4);
393 : 0 : val |= PACK(cfg->flags_match, NIX_FLAGS_MATCH_SHIFT, 4);
394 : 0 : val |= PACK(cfg->match_oipv4, NIX_MATCH_OIPV4_SHIFT, 1);
395 : 0 : val |= PACK(cfg->match_oipv6, NIX_MATCH_OIPV6_SHIFT, 1);
396 : 0 : val |= PACK(cfg->oiplen_ena, NIX_OIPLEN_ENA_SHIFT, 1);
397 : 0 : val |= PACK(cfg->inline_shift, NIX_INLINE_SHIFT_SHIFT, 2);
398 : :
399 : 0 : return val;
400 : : }
401 : :
402 : : static uint64_t
403 : : cnxk_rx_gen_inl_cfg_pack(const struct rte_pmd_cnxk_rx_gen_inl_cfg *cfg)
404 : : {
405 : : uint64_t val = 0;
406 : :
407 : : /* CPT instruction fields */
408 : 0 : val |= PACK(cfg->param2, NIX_PARAM2_SHIFT, 16);
409 : 0 : val |= PACK(cfg->param1, NIX_PARAM1_SHIFT, 16);
410 : 0 : val |= PACK(cfg->opcode, NIX_OPCODE_SHIFT, 16);
411 : 0 : val |= PACK(cfg->egrp, NIX_EGRP_SHIFT, 3);
412 : 0 : val |= PACK(cfg->ctx_val, NIX_CTX_VAL_SHIFT, 1);
413 : :
414 : : return val;
415 : : }
416 : :
417 : : static uint64_t
418 : 0 : cnxk_rx_extract_inl_cfg_pack(const struct rte_pmd_cnxk_rx_extract_inl_cfg *cfg)
419 : : {
420 : : uint64_t val = 0;
421 : :
422 : 0 : val |= PACK(cfg->len_l, NIX_LEN_L_SHIFT, 6);
423 : 0 : val |= PACK(cfg->bitpos_l, NIX_BITPOS_L_SHIFT, 6);
424 : 0 : val |= PACK(cfg->len_m, NIX_LEN_M_SHIFT, 6);
425 : 0 : val |= PACK(cfg->bitpos_m, NIX_BITPOS_M_SHIFT, 6);
426 : 0 : val |= PACK(cfg->len_h, NIX_LEN_H_SHIFT, 6);
427 : 0 : val |= PACK(cfg->bitpos_h, NIX_BITPOS_H_SHIFT, 6);
428 : :
429 : 0 : return val;
430 : : }
431 : :
432 : : static uint64_t
433 : : cnxk_rx_prot_field_inline_cfg_pack(const struct rte_pmd_cnxk_rx_prot_field_inl_cfg *cfg)
434 : : {
435 : : uint64_t val = 0;
436 : :
437 : 0 : val |= PACK(cfg->valid, NIX_VALID_SHIFT, 1);
438 : 0 : val |= PACK(cfg->offset, NIX_OFFSET_SHIFT, 6);
439 : 0 : val |= PACK(cfg->sizem1, NIX_SIZEM1_SHIFT, 4);
440 : 0 : val |= PACK(cfg->logmult, NIX_LOGMULT_SHIFT, 2);
441 : :
442 : : return val;
443 : : }
444 : :
445 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_nix_inl_custom_profile_setup, 25.11)
446 : : int
447 : 0 : rte_pmd_cnxk_nix_inl_custom_profile_setup(uint16_t portid,
448 : : const struct rte_pmd_cnxk_profile_cfg_params *cfg,
449 : : uint16_t *profile_id)
450 : : {
451 : 0 : uint64_t prot_field_cfg_val[RTE_PMD_CNXK_MAX_PROT_FIELDS] = {0};
452 : : struct rte_eth_dev *eth_dev;
453 : : struct cnxk_eth_dev *dev;
454 : : uint64_t extract_cfg_val = 0;
455 : : uint64_t def_cfg_val = 0;
456 : : uint64_t gen_cfg_val = 0;
457 : : uint32_t sa_size = 0;
458 : : uint32_t max_sa = 0;
459 [ # # ]: 0 : uint16_t prof_id = 0;
460 : : int rc = 0;
461 : : int i;
462 : :
463 [ # # ]: 0 : if (!roc_feature_nix_has_inl_profile())
464 : : return -ENOTSUP;
465 : :
466 [ # # ]: 0 : if (!rte_eth_dev_is_valid_port(portid))
467 : : return -EINVAL;
468 : :
469 [ # # ]: 0 : if (!cfg || !profile_id)
470 : : return -EINVAL;
471 : :
472 : : eth_dev = &rte_eth_devices[portid];
473 : : dev = cnxk_eth_pmd_priv(eth_dev);
474 : :
475 : : /* Pack default inline configuration */
476 : 0 : def_cfg_val = cnxk_rx_def_inl_cfg_pack(&cfg->def_cfg);
477 : :
478 : : /* Pack generic inline configuration */
479 : : gen_cfg_val = cnxk_rx_gen_inl_cfg_pack(&cfg->gen_cfg);
480 : :
481 : : /* Pack extract inline configuration */
482 : 0 : extract_cfg_val = cnxk_rx_extract_inl_cfg_pack(&cfg->extract_cfg);
483 : :
484 : : /* Pack protocol field inline configurations */
485 [ # # ]: 0 : for (i = 0; i < RTE_PMD_CNXK_MAX_PROT_FIELDS; i++)
486 : 0 : prot_field_cfg_val[i] = cnxk_rx_prot_field_inline_cfg_pack(&cfg->prot_field_cfg[i]);
487 : :
488 : : /* Get SA size and max SA count */
489 : 0 : sa_size = cfg->sa_size;
490 : 0 : max_sa = cfg->max_sa;
491 : :
492 : : /* Call ROC API to configure the custom profile */
493 : 0 : rc = roc_nix_inl_custom_profile_setup(&dev->nix, def_cfg_val, gen_cfg_val, extract_cfg_val,
494 : : prot_field_cfg_val, sa_size, max_sa,
495 : 0 : !dev->inb.no_inl_dev, &prof_id);
496 [ # # ]: 0 : if (rc) {
497 : 0 : plt_err("Failed to setup custom profile: rc=%d", rc);
498 : 0 : return rc;
499 : : }
500 : :
501 : 0 : *profile_id = prof_id;
502 : :
503 : 0 : plt_nix_dbg("Custom profile setup: port=%u, sa_size=%u, max_sa=%u, profile_id=%u", portid,
504 : : sa_size, max_sa, *profile_id);
505 : :
506 : 0 : return 0;
507 : : }
508 : :
509 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_nix_inl_custom_profile_release, 25.11)
510 : : int
511 : 0 : rte_pmd_cnxk_nix_inl_custom_profile_release(uint16_t portid, uint16_t profile_id)
512 : : {
513 : : struct rte_eth_dev *eth_dev;
514 : : struct cnxk_eth_dev *dev;
515 : : int rc;
516 : :
517 [ # # ]: 0 : if (!rte_eth_dev_is_valid_port(portid))
518 : : return -EINVAL;
519 : :
520 : : eth_dev = &rte_eth_devices[portid];
521 : : dev = cnxk_eth_pmd_priv(eth_dev);
522 : :
523 : : /* Call ROC API to release the custom profile */
524 : 0 : rc = roc_nix_inl_custom_profile_release(&dev->nix, profile_id, !dev->inb.no_inl_dev);
525 [ # # ]: 0 : if (rc) {
526 : 0 : plt_err("Failed to release custom profile %u: rc=%d", profile_id, rc);
527 : 0 : return rc;
528 : : }
529 : :
530 : : return 0;
531 : : }
532 : :
533 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_sa_flush, 23.11)
534 : : int
535 : 0 : rte_pmd_cnxk_sa_flush(uint16_t portid, union rte_pmd_cnxk_ipsec_hw_sa *sess, bool inb)
536 : : {
537 [ # # ]: 0 : struct rte_eth_dev *eth_dev = &rte_eth_devices[portid];
538 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
539 : : rte_spinlock_t *lock;
540 : : bool inl_dev;
541 : : int rc;
542 : :
543 : 0 : inl_dev = !!dev->inb.inl_dev;
544 [ # # ]: 0 : lock = inb ? &dev->inb.lock : &dev->outb.lock;
545 : : rte_spinlock_lock(lock);
546 : :
547 : : /* Acquire lock on inline dev for inbound */
548 [ # # ]: 0 : if (inb && inl_dev)
549 : 0 : roc_nix_inl_dev_lock();
550 : :
551 : 0 : rc = roc_nix_inl_sa_sync(&dev->nix, sess, inb, ROC_NIX_INL_SA_OP_FLUSH);
552 : :
553 [ # # ]: 0 : if (inb && inl_dev)
554 : 0 : roc_nix_inl_dev_unlock();
555 : : rte_spinlock_unlock(lock);
556 : :
557 : 0 : return rc;
558 : : }
559 : :
560 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_hw_sa_read, 22.07)
561 : : int
562 : 0 : rte_pmd_cnxk_hw_sa_read(uint16_t portid, void *sess, union rte_pmd_cnxk_ipsec_hw_sa *data,
563 : : uint32_t len, bool inb)
564 : : {
565 : 0 : struct rte_eth_dev *eth_dev = &rte_eth_devices[portid];
566 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
567 : : struct cnxk_eth_sec_sess *eth_sec;
568 : : rte_spinlock_t *lock;
569 : : bool inl_dev;
570 : : void *sa;
571 : : int rc;
572 : :
573 : 0 : eth_sec = cnxk_eth_sec_sess_get_by_sess(dev, sess);
574 [ # # ]: 0 : if (eth_sec)
575 : 0 : sa = eth_sec->sa;
576 : : else
577 : : sa = sess;
578 : :
579 : 0 : inl_dev = !!dev->inb.inl_dev;
580 [ # # ]: 0 : lock = inb ? &dev->inb.lock : &dev->outb.lock;
581 : : rte_spinlock_lock(lock);
582 : :
583 : : /* Acquire lock on inline dev for inbound */
584 [ # # ]: 0 : if (inb && inl_dev)
585 : 0 : roc_nix_inl_dev_lock();
586 : :
587 : 0 : rc = roc_nix_inl_sa_sync(&dev->nix, sa, inb, ROC_NIX_INL_SA_OP_FLUSH);
588 [ # # ]: 0 : if (rc)
589 : 0 : goto err;
590 : :
591 [ # # ]: 0 : if (inb && inl_dev)
592 : 0 : roc_nix_inl_dev_unlock();
593 : : rte_spinlock_unlock(lock);
594 : :
595 : 0 : memcpy(data, sa, len);
596 : :
597 : 0 : return 0;
598 : : err:
599 [ # # ]: 0 : if (inb && inl_dev)
600 : 0 : roc_nix_inl_dev_unlock();
601 : : rte_spinlock_unlock(lock);
602 : :
603 : 0 : return rc;
604 : : }
605 : :
606 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_hw_sa_write, 22.07)
607 : : int
608 : 0 : rte_pmd_cnxk_hw_sa_write(uint16_t portid, void *sess, union rte_pmd_cnxk_ipsec_hw_sa *data,
609 : : uint32_t len, bool inb)
610 : : {
611 : 0 : struct rte_eth_dev *eth_dev = &rte_eth_devices[portid];
612 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
613 : : struct cnxk_eth_sec_sess *eth_sec;
614 : : struct roc_nix_inl_dev_q *q;
615 : : rte_spinlock_t *lock;
616 : : bool inl_dev;
617 : : void *sa;
618 : : int rc;
619 : :
620 : 0 : eth_sec = cnxk_eth_sec_sess_get_by_sess(dev, sess);
621 [ # # ]: 0 : if (eth_sec)
622 : 0 : sa = eth_sec->sa;
623 : : else
624 : : sa = sess;
625 : :
626 : 0 : q = dev->inb.inl_dev_q;
627 [ # # # # ]: 0 : if (q && cnxk_nix_inl_fc_check(q->fc_addr, &q->fc_addr_sw, q->nb_desc, 1))
628 : : return -EAGAIN;
629 : :
630 : 0 : inl_dev = !!dev->inb.inl_dev;
631 [ # # ]: 0 : lock = inb ? &dev->inb.lock : &dev->outb.lock;
632 : : rte_spinlock_lock(lock);
633 : :
634 : : /* Acquire lock on inline dev for inbound */
635 [ # # ]: 0 : if (inb && inl_dev)
636 : 0 : roc_nix_inl_dev_lock();
637 : :
638 : 0 : rc = roc_nix_inl_ctx_write(&dev->nix, data, sa, inb, len);
639 : :
640 [ # # ]: 0 : if (inb && inl_dev)
641 : 0 : roc_nix_inl_dev_unlock();
642 : : rte_spinlock_unlock(lock);
643 : :
644 : 0 : return rc;
645 : : }
646 : :
647 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_inl_ipsec_res, 23.11)
648 : : union rte_pmd_cnxk_cpt_res_s *
649 : 0 : rte_pmd_cnxk_inl_ipsec_res(struct rte_mbuf *mbuf)
650 : : {
651 : : const union nix_rx_parse_u *rx;
652 : : uint16_t desc_size;
653 : : uintptr_t wqe;
654 : :
655 [ # # # # ]: 0 : if (!mbuf || !(mbuf->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD))
656 : : return NULL;
657 : :
658 : 0 : wqe = (uintptr_t)(mbuf + 1);
659 : 0 : rx = (const union nix_rx_parse_u *)(wqe + 8);
660 : 0 : desc_size = (rx->desc_sizem1 + 1) * 16;
661 : :
662 : : /* rte_pmd_cnxk_cpt_res_s sits after SG list at 16B aligned address */
663 : 0 : return (void *)(wqe + 64 + desc_size);
664 : : }
665 : :
666 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_pmd_cnxk_hw_inline_inb_cfg_set, 23.11)
667 : : void
668 : 0 : rte_pmd_cnxk_hw_inline_inb_cfg_set(uint16_t portid, struct rte_pmd_cnxk_ipsec_inb_cfg *cfg)
669 : : {
670 : 0 : struct rte_eth_dev *eth_dev = &rte_eth_devices[portid];
671 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
672 : :
673 : 0 : dev->nix.inb_cfg_param1 = cfg->param1;
674 : 0 : dev->nix.inb_cfg_param2 = cfg->param2;
675 : 0 : }
676 : :
677 : : static unsigned int
678 : 0 : cnxk_eth_sec_session_get_size(void *device __rte_unused)
679 : : {
680 : 0 : return RTE_MAX(sizeof(struct cnxk_macsec_sess), sizeof(struct cnxk_eth_sec_sess));
681 : : }
682 : :
683 : : struct rte_security_ops cnxk_eth_sec_ops = {
684 : : .session_get_size = cnxk_eth_sec_session_get_size
685 : : };
686 : :
687 : : static int
688 : 0 : parse_val_u32(const char *key, const char *value, void *extra_args)
689 : : {
690 : : RTE_SET_USED(key);
691 : : uint32_t val;
692 : :
693 : 0 : errno = 0;
694 : 0 : val = strtoul(value, NULL, 0);
695 [ # # ]: 0 : if (errno)
696 : : val = 0;
697 : :
698 : 0 : *(uint32_t *)extra_args = val;
699 : :
700 : 0 : return 0;
701 : : }
702 : :
703 : : static int
704 : 0 : parse_selftest(const char *key, const char *value, void *extra_args)
705 : : {
706 : : RTE_SET_USED(key);
707 : : uint32_t val;
708 : :
709 : 0 : val = atoi(value);
710 : :
711 : 0 : *(uint8_t *)extra_args = !!(val == 1);
712 : 0 : return 0;
713 : : }
714 : :
715 : : static int
716 : 0 : parse_inl_cpt_channel(const char *key, const char *value, void *extra_args)
717 : : {
718 : : RTE_SET_USED(key);
719 : : uint16_t chan = 0, mask = 0;
720 : 0 : char *next = 0;
721 : :
722 : : /* next will point to the separator '/' */
723 : 0 : chan = strtol(value, &next, 16);
724 : 0 : mask = strtol(++next, 0, 16);
725 : :
726 [ # # ]: 0 : if (chan > GENMASK(12, 0) || mask > GENMASK(12, 0))
727 : : return -EINVAL;
728 : :
729 : 0 : ((struct inl_cpt_channel *)extra_args)->channel = chan;
730 : 0 : ((struct inl_cpt_channel *)extra_args)->mask = mask;
731 : 0 : ((struct inl_cpt_channel *)extra_args)->is_multi_channel = true;
732 : :
733 : 0 : return 0;
734 : : }
735 : :
736 : : static int
737 : 0 : nix_inl_parse_devargs(struct rte_devargs *devargs,
738 : : struct roc_nix_inl_dev *inl_dev)
739 : : {
740 : 0 : uint32_t soft_exp_poll_freq = CNXK_NIX_SOFT_EXP_POLL_FREQ_DFLT;
741 : 0 : uint32_t ipsec_in_max_spi = BIT(8) - 1;
742 : 0 : uint32_t ipsec_in_min_spi = 0;
743 : : struct inl_cpt_channel cpt_channel;
744 : 0 : uint32_t max_ipsec_rules = 0;
745 : : struct rte_kvargs *kvlist;
746 : 0 : uint8_t custom_inb_sa = 0;
747 : 0 : uint8_t nb_inl_inb_qs = 1;
748 : 0 : uint32_t nb_meta_bufs = 0;
749 : 0 : uint32_t meta_buf_sz = 0;
750 : 0 : uint8_t rx_inj_ena = 0;
751 [ # # ]: 0 : uint8_t selftest = 0;
752 [ # # ]: 0 : uint8_t cpt_cq_enable = roc_feature_nix_has_cpt_cq_support() ? 1 : 0;
753 : :
754 : : memset(&cpt_channel, 0, sizeof(cpt_channel));
755 : :
756 [ # # ]: 0 : if (devargs == NULL)
757 : 0 : goto null_devargs;
758 : :
759 : 0 : kvlist = rte_kvargs_parse(devargs->args, NULL);
760 [ # # ]: 0 : if (kvlist == NULL)
761 : 0 : goto exit;
762 : :
763 : 0 : rte_kvargs_process(kvlist, CNXK_NIX_INL_SELFTEST, &parse_selftest,
764 : : &selftest);
765 : 0 : rte_kvargs_process(kvlist, CNXK_NIX_INL_IPSEC_IN_MIN_SPI,
766 : : &parse_val_u32, &ipsec_in_min_spi);
767 : 0 : rte_kvargs_process(kvlist, CNXK_NIX_INL_IPSEC_IN_MAX_SPI,
768 : : &parse_val_u32, &ipsec_in_max_spi);
769 : 0 : rte_kvargs_process(kvlist, CNXK_INL_CPT_CHANNEL, &parse_inl_cpt_channel,
770 : : &cpt_channel);
771 : 0 : rte_kvargs_process(kvlist, CNXK_NIX_INL_NB_META_BUFS, &parse_val_u32,
772 : : &nb_meta_bufs);
773 : 0 : rte_kvargs_process(kvlist, CNXK_NIX_INL_META_BUF_SZ, &parse_val_u32,
774 : : &meta_buf_sz);
775 : 0 : rte_kvargs_process(kvlist, CNXK_NIX_SOFT_EXP_POLL_FREQ,
776 : : &parse_val_u32, &soft_exp_poll_freq);
777 : 0 : rte_kvargs_process(kvlist, CNXK_MAX_IPSEC_RULES, &parse_max_ipsec_rules, &max_ipsec_rules);
778 : 0 : rte_kvargs_process(kvlist, CNXK_NIX_INL_RX_INJ_ENABLE, &parse_val_u8, &rx_inj_ena);
779 : 0 : rte_kvargs_process(kvlist, CNXK_NIX_CUSTOM_INB_SA, &parse_val_u8, &custom_inb_sa);
780 : 0 : rte_kvargs_process(kvlist, CNXK_NIX_NB_INL_INB_QS, &parse_val_u8, &nb_inl_inb_qs);
781 : 0 : rte_kvargs_process(kvlist, CNXK_NIX_INL_CPT_CQ_ENABLE, &parse_val_u8, &cpt_cq_enable);
782 : 0 : rte_kvargs_free(kvlist);
783 : :
784 : 0 : null_devargs:
785 : 0 : inl_dev->ipsec_in_min_spi = ipsec_in_min_spi;
786 : 0 : inl_dev->ipsec_in_max_spi = ipsec_in_max_spi;
787 : 0 : inl_dev->selftest = selftest;
788 : 0 : inl_dev->channel = cpt_channel.channel;
789 : 0 : inl_dev->chan_mask = cpt_channel.mask;
790 : 0 : inl_dev->is_multi_channel = cpt_channel.is_multi_channel;
791 : 0 : inl_dev->nb_meta_bufs = nb_meta_bufs;
792 : 0 : inl_dev->meta_buf_sz = meta_buf_sz;
793 : 0 : inl_dev->soft_exp_poll_freq = soft_exp_poll_freq;
794 : 0 : inl_dev->cpt_cq_enable = cpt_cq_enable;
795 [ # # ]: 0 : inl_dev->max_ipsec_rules = max_ipsec_rules;
796 [ # # ]: 0 : if (roc_feature_nix_has_rx_inject())
797 : 0 : inl_dev->rx_inj_ena = rx_inj_ena;
798 [ # # ]: 0 : if (roc_feature_nix_has_inl_multi_queue())
799 : 0 : inl_dev->nb_inb_cptlfs = nb_inl_inb_qs;
800 : 0 : inl_dev->custom_inb_sa = custom_inb_sa;
801 : 0 : return 0;
802 : : exit:
803 : 0 : return -EINVAL;
804 : : }
805 : :
806 : : static inline char *
807 : 0 : nix_inl_dev_to_name(struct rte_pci_device *pci_dev, char *name)
808 : : {
809 : 0 : snprintf(name, CNXK_NIX_INL_DEV_NAME_LEN,
810 : : CNXK_NIX_INL_DEV_NAME PCI_PRI_FMT, pci_dev->addr.domain,
811 : 0 : pci_dev->addr.bus, pci_dev->addr.devid,
812 : 0 : pci_dev->addr.function);
813 : :
814 : 0 : return name;
815 : : }
816 : :
817 : : static int
818 : 0 : cnxk_nix_inl_dev_remove(struct rte_pci_device *pci_dev)
819 : : {
820 : : char name[CNXK_NIX_INL_DEV_NAME_LEN];
821 : : const struct rte_memzone *mz;
822 : : struct roc_nix_inl_dev *dev;
823 : : int rc;
824 : :
825 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
826 : : return 0;
827 : :
828 : 0 : mz = rte_memzone_lookup(nix_inl_dev_to_name(pci_dev, name));
829 [ # # ]: 0 : if (!mz)
830 : : return 0;
831 : :
832 : 0 : dev = mz->addr;
833 : :
834 : : /* Cleanup inline dev */
835 : 0 : rc = roc_nix_inl_dev_fini(dev);
836 [ # # ]: 0 : if (rc) {
837 : 0 : plt_err("Failed to cleanup inl dev, rc=%d(%s)", rc,
838 : : roc_error_msg_get(rc));
839 : 0 : return rc;
840 : : }
841 : :
842 : 0 : rte_memzone_free(mz);
843 : 0 : return 0;
844 : : }
845 : :
846 : : static int
847 : 0 : cnxk_nix_inl_dev_probe(struct rte_pci_driver *pci_drv,
848 : : struct rte_pci_device *pci_dev)
849 : : {
850 : : char name[CNXK_NIX_INL_DEV_NAME_LEN];
851 : : struct roc_nix_inl_dev *inl_dev;
852 : : const struct rte_memzone *mz;
853 : : uint16_t wqe_skip;
854 : : int rc = -ENOMEM;
855 : :
856 : : RTE_SET_USED(pci_drv);
857 : :
858 : 0 : rc = roc_plt_init();
859 [ # # ]: 0 : if (rc) {
860 : 0 : plt_err("Failed to initialize platform model, rc=%d", rc);
861 : 0 : return rc;
862 : : }
863 : :
864 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
865 : : return 0;
866 : :
867 : 0 : mz = rte_memzone_reserve_aligned(nix_inl_dev_to_name(pci_dev, name),
868 : : sizeof(*inl_dev), SOCKET_ID_ANY, 0,
869 : : RTE_CACHE_LINE_SIZE);
870 [ # # ]: 0 : if (mz == NULL)
871 : : return rc;
872 : :
873 : 0 : inl_dev = mz->addr;
874 : 0 : inl_dev->pci_dev = pci_dev;
875 : :
876 : : /* Parse devargs string */
877 : 0 : rc = nix_inl_parse_devargs(pci_dev->device.devargs, inl_dev);
878 [ # # ]: 0 : if (rc) {
879 : 0 : plt_err("Failed to parse devargs rc=%d", rc);
880 : 0 : goto free_mem;
881 : : }
882 : :
883 : : /* WQE skip is one for DPDK */
884 : : wqe_skip = RTE_ALIGN_CEIL(sizeof(struct rte_mbuf), ROC_CACHE_LINE_SZ);
885 : : wqe_skip = wqe_skip / ROC_CACHE_LINE_SZ;
886 : 0 : inl_dev->wqe_skip = wqe_skip;
887 : 0 : rc = roc_nix_inl_dev_init(inl_dev);
888 [ # # ]: 0 : if (rc) {
889 : 0 : plt_err("Failed to init nix inl device, rc=%d(%s)", rc,
890 : : roc_error_msg_get(rc));
891 : 0 : goto free_mem;
892 : : }
893 : :
894 : : return 0;
895 : 0 : free_mem:
896 : 0 : rte_memzone_free(mz);
897 : 0 : return rc;
898 : : }
899 : :
900 : : static const struct rte_pci_id cnxk_nix_inl_pci_map[] = {
901 : : {RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_CNXK_RVU_NIX_INL_PF)},
902 : : {RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_CNXK_RVU_NIX_INL_VF)},
903 : : {
904 : : .vendor_id = 0,
905 : : },
906 : : };
907 : :
908 : : static struct rte_pci_driver cnxk_nix_inl_pci = {
909 : : .id_table = cnxk_nix_inl_pci_map,
910 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA,
911 : : .probe = cnxk_nix_inl_dev_probe,
912 : : .remove = cnxk_nix_inl_dev_remove,
913 : : };
914 : :
915 : 305 : RTE_PMD_REGISTER_PCI(cnxk_nix_inl, cnxk_nix_inl_pci);
916 : : RTE_PMD_REGISTER_PCI_TABLE(cnxk_nix_inl, cnxk_nix_inl_pci_map);
917 : : RTE_PMD_REGISTER_KMOD_DEP(cnxk_nix_inl, "vfio-pci");
918 : :
919 : : RTE_PMD_REGISTER_PARAM_STRING(cnxk_nix_inl,
920 : : CNXK_NIX_INL_SELFTEST "=1"
921 : : CNXK_NIX_INL_IPSEC_IN_MIN_SPI "=<1-U32_MAX>"
922 : : CNXK_NIX_INL_IPSEC_IN_MAX_SPI "=<1-U32_MAX>"
923 : : CNXK_INL_CPT_CHANNEL "=<1-4095>/<1-4095>"
924 : : CNXK_NIX_INL_NB_META_BUFS "=<1-U32_MAX>"
925 : : CNXK_NIX_INL_META_BUF_SZ "=<1-U32_MAX>"
926 : : CNXK_NIX_SOFT_EXP_POLL_FREQ "=<0-U32_MAX>"
927 : : CNXK_MAX_IPSEC_RULES "=<1-4095>"
928 : : CNXK_NIX_INL_RX_INJ_ENABLE "=1"
929 : : CNXK_NIX_CUSTOM_INB_SA "=1"
930 : : CNXK_NIX_NB_INL_INB_QS "=[0-16]");
|