1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
5 #include "cn9k_worker.h"
6 #include "cnxk_eventdev.h"
7 #include "cnxk_worker.h"
9 #define CN9K_DUAL_WS_NB_WS 2
10 #define CN9K_DUAL_WS_PAIR_ID(x, id) (((x)*CN9K_DUAL_WS_NB_WS) + id)
12 #define CN9K_SET_EVDEV_DEQ_OP(dev, deq_op, deq_ops) \
13 (deq_op = deq_ops[!!(dev->rx_offloads & NIX_RX_OFFLOAD_SECURITY_F)] \
14 [!!(dev->rx_offloads & NIX_RX_OFFLOAD_VLAN_STRIP_F)] \
15 [!!(dev->rx_offloads & NIX_RX_OFFLOAD_TSTAMP_F)] \
16 [!!(dev->rx_offloads & NIX_RX_OFFLOAD_MARK_UPDATE_F)] \
17 [!!(dev->rx_offloads & NIX_RX_OFFLOAD_CHECKSUM_F)] \
18 [!!(dev->rx_offloads & NIX_RX_OFFLOAD_PTYPE_F)] \
19 [!!(dev->rx_offloads & NIX_RX_OFFLOAD_RSS_F)])
21 #define CN9K_SET_EVDEV_ENQ_OP(dev, enq_op, enq_ops) \
22 (enq_op = enq_ops[!!(dev->tx_offloads & NIX_TX_OFFLOAD_SECURITY_F)] \
23 [!!(dev->tx_offloads & NIX_TX_OFFLOAD_TSTAMP_F)] \
24 [!!(dev->tx_offloads & NIX_TX_OFFLOAD_TSO_F)] \
25 [!!(dev->tx_offloads & NIX_TX_OFFLOAD_MBUF_NOFF_F)] \
26 [!!(dev->tx_offloads & NIX_TX_OFFLOAD_VLAN_QINQ_F)] \
27 [!!(dev->tx_offloads & NIX_TX_OFFLOAD_OL3_OL4_CSUM_F)] \
28 [!!(dev->tx_offloads & NIX_TX_OFFLOAD_L3_L4_CSUM_F)])
31 cn9k_init_hws_ops(struct cn9k_sso_hws_state *ws, uintptr_t base)
33 ws->tag_op = base + SSOW_LF_GWS_TAG;
34 ws->wqp_op = base + SSOW_LF_GWS_WQP;
35 ws->getwrk_op = base + SSOW_LF_GWS_OP_GET_WORK0;
36 ws->swtag_flush_op = base + SSOW_LF_GWS_OP_SWTAG_FLUSH;
37 ws->swtag_norm_op = base + SSOW_LF_GWS_OP_SWTAG_NORM;
38 ws->swtag_desched_op = base + SSOW_LF_GWS_OP_SWTAG_DESCHED;
42 cn9k_sso_hws_link(void *arg, void *port, uint16_t *map, uint16_t nb_link)
44 struct cnxk_sso_evdev *dev = arg;
45 struct cn9k_sso_hws_dual *dws;
46 struct cn9k_sso_hws *ws;
51 rc = roc_sso_hws_link(&dev->sso,
52 CN9K_DUAL_WS_PAIR_ID(dws->hws_id, 0), map,
54 rc |= roc_sso_hws_link(&dev->sso,
55 CN9K_DUAL_WS_PAIR_ID(dws->hws_id, 1),
59 rc = roc_sso_hws_link(&dev->sso, ws->hws_id, map, nb_link);
66 cn9k_sso_hws_unlink(void *arg, void *port, uint16_t *map, uint16_t nb_link)
68 struct cnxk_sso_evdev *dev = arg;
69 struct cn9k_sso_hws_dual *dws;
70 struct cn9k_sso_hws *ws;
75 rc = roc_sso_hws_unlink(&dev->sso,
76 CN9K_DUAL_WS_PAIR_ID(dws->hws_id, 0),
78 rc |= roc_sso_hws_unlink(&dev->sso,
79 CN9K_DUAL_WS_PAIR_ID(dws->hws_id, 1),
83 rc = roc_sso_hws_unlink(&dev->sso, ws->hws_id, map, nb_link);
90 cn9k_sso_hws_setup(void *arg, void *hws, uintptr_t grp_base)
92 struct cnxk_sso_evdev *dev = arg;
93 struct cn9k_sso_hws_dual *dws;
94 struct cn9k_sso_hws *ws;
97 /* Set get_work tmo for HWS */
98 val = NSEC2USEC(dev->deq_tmo_ns) - 1;
101 dws->grp_base = grp_base;
102 dws->fc_mem = (uint64_t *)dev->fc_iova;
103 dws->xaq_lmt = dev->xaq_lmt;
105 plt_write64(val, dws->base[0] + SSOW_LF_GWS_NW_TIM);
106 plt_write64(val, dws->base[1] + SSOW_LF_GWS_NW_TIM);
109 ws->grp_base = grp_base;
110 ws->fc_mem = (uint64_t *)dev->fc_iova;
111 ws->xaq_lmt = dev->xaq_lmt;
113 plt_write64(val, ws->base + SSOW_LF_GWS_NW_TIM);
118 cn9k_sso_hws_release(void *arg, void *hws)
120 struct cnxk_sso_evdev *dev = arg;
121 struct cn9k_sso_hws_dual *dws;
122 struct cn9k_sso_hws *ws;
127 for (i = 0; i < dev->nb_event_queues; i++) {
128 roc_sso_hws_unlink(&dev->sso,
129 CN9K_DUAL_WS_PAIR_ID(dws->hws_id, 0),
131 roc_sso_hws_unlink(&dev->sso,
132 CN9K_DUAL_WS_PAIR_ID(dws->hws_id, 1),
135 memset(dws, 0, sizeof(*dws));
138 for (i = 0; i < dev->nb_event_queues; i++)
139 roc_sso_hws_unlink(&dev->sso, ws->hws_id,
141 memset(ws, 0, sizeof(*ws));
146 cn9k_sso_hws_flush_events(void *hws, uint8_t queue_id, uintptr_t base,
147 cnxk_handle_event_t fn, void *arg)
149 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(arg);
150 struct cn9k_sso_hws_dual *dws;
151 struct cn9k_sso_hws_state *st;
152 struct cn9k_sso_hws *ws;
153 uint64_t cq_ds_cnt = 1;
160 plt_write64(0, base + SSO_LF_GGRP_QCTL);
162 req = queue_id; /* GGRP ID */
163 req |= BIT_ULL(18); /* Grouped */
164 req |= BIT_ULL(16); /* WAIT */
166 aq_cnt = plt_read64(base + SSO_LF_GGRP_AQ_CNT);
167 ds_cnt = plt_read64(base + SSO_LF_GGRP_MISC_CNT);
168 cq_ds_cnt = plt_read64(base + SSO_LF_GGRP_INT_CNT);
169 cq_ds_cnt &= 0x3FFF3FFF0000;
173 st = &dws->ws_state[0];
174 ws_base = dws->base[0];
177 st = (struct cn9k_sso_hws_state *)ws;
181 while (aq_cnt || cq_ds_cnt || ds_cnt) {
182 plt_write64(req, st->getwrk_op);
183 cn9k_sso_hws_get_work_empty(st, &ev);
184 if (fn != NULL && ev.u64 != 0)
186 if (ev.sched_type != SSO_TT_EMPTY)
187 cnxk_sso_hws_swtag_flush(st->tag_op,
190 val = plt_read64(ws_base + SSOW_LF_GWS_PENDSTATE);
191 } while (val & BIT_ULL(56));
192 aq_cnt = plt_read64(base + SSO_LF_GGRP_AQ_CNT);
193 ds_cnt = plt_read64(base + SSO_LF_GGRP_MISC_CNT);
194 cq_ds_cnt = plt_read64(base + SSO_LF_GGRP_INT_CNT);
195 /* Extract cq and ds count */
196 cq_ds_cnt &= 0x3FFF3FFF0000;
199 plt_write64(0, ws_base + SSOW_LF_GWS_OP_GWC_INVAL);
203 cn9k_sso_hws_reset(void *arg, void *hws)
205 struct cnxk_sso_evdev *dev = arg;
206 struct cn9k_sso_hws_dual *dws;
207 struct cn9k_sso_hws *ws;
216 for (i = 0; i < (dev->dual_ws ? CN9K_DUAL_WS_NB_WS : 1); i++) {
217 base = dev->dual_ws ? dws->base[i] : ws->base;
218 /* Wait till getwork/swtp/waitw/desched completes. */
220 pend_state = plt_read64(base + SSOW_LF_GWS_PENDSTATE);
221 } while (pend_state & (BIT_ULL(63) | BIT_ULL(62) | BIT_ULL(58) |
224 tag = plt_read64(base + SSOW_LF_GWS_TAG);
225 pend_tt = (tag >> 32) & 0x3;
226 if (pend_tt != SSO_TT_EMPTY) { /* Work was pending */
227 if (pend_tt == SSO_TT_ATOMIC ||
228 pend_tt == SSO_TT_ORDERED)
229 cnxk_sso_hws_swtag_untag(
230 base + SSOW_LF_GWS_OP_SWTAG_UNTAG);
231 plt_write64(0, base + SSOW_LF_GWS_OP_DESCHED);
234 /* Wait for desched to complete. */
236 pend_state = plt_read64(base + SSOW_LF_GWS_PENDSTATE);
237 } while (pend_state & BIT_ULL(58));
242 cn9k_sso_set_rsrc(void *arg)
244 struct cnxk_sso_evdev *dev = arg;
247 dev->max_event_ports = dev->sso.max_hws / CN9K_DUAL_WS_NB_WS;
249 dev->max_event_ports = dev->sso.max_hws;
250 dev->max_event_queues =
251 dev->sso.max_hwgrp > RTE_EVENT_MAX_QUEUES_PER_DEV ?
252 RTE_EVENT_MAX_QUEUES_PER_DEV :
257 cn9k_sso_rsrc_init(void *arg, uint8_t hws, uint8_t hwgrp)
259 struct cnxk_sso_evdev *dev = arg;
262 hws = hws * CN9K_DUAL_WS_NB_WS;
264 return roc_sso_rsrc_init(&dev->sso, hws, hwgrp);
268 cn9k_sso_updt_tx_adptr_data(const struct rte_eventdev *event_dev)
270 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
273 if (dev->tx_adptr_data == NULL)
276 for (i = 0; i < dev->nb_event_ports; i++) {
278 struct cn9k_sso_hws_dual *dws =
279 event_dev->data->ports[i];
282 ws_cookie = cnxk_sso_hws_get_cookie(dws);
283 ws_cookie = rte_realloc_socket(
285 sizeof(struct cnxk_sso_hws_cookie) +
286 sizeof(struct cn9k_sso_hws_dual) +
288 (dev->max_port_id + 1) *
289 RTE_MAX_QUEUES_PER_PORT),
290 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
291 if (ws_cookie == NULL)
293 dws = RTE_PTR_ADD(ws_cookie,
294 sizeof(struct cnxk_sso_hws_cookie));
295 memcpy(&dws->tx_adptr_data, dev->tx_adptr_data,
296 sizeof(uint64_t) * (dev->max_port_id + 1) *
297 RTE_MAX_QUEUES_PER_PORT);
298 event_dev->data->ports[i] = dws;
300 struct cn9k_sso_hws *ws = event_dev->data->ports[i];
303 ws_cookie = cnxk_sso_hws_get_cookie(ws);
304 ws_cookie = rte_realloc_socket(
306 sizeof(struct cnxk_sso_hws_cookie) +
307 sizeof(struct cn9k_sso_hws_dual) +
309 (dev->max_port_id + 1) *
310 RTE_MAX_QUEUES_PER_PORT),
311 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
312 if (ws_cookie == NULL)
314 ws = RTE_PTR_ADD(ws_cookie,
315 sizeof(struct cnxk_sso_hws_cookie));
316 memcpy(&ws->tx_adptr_data, dev->tx_adptr_data,
317 sizeof(uint64_t) * (dev->max_port_id + 1) *
318 RTE_MAX_QUEUES_PER_PORT);
319 event_dev->data->ports[i] = ws;
328 cn9k_sso_fp_fns_set(struct rte_eventdev *event_dev)
330 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
331 /* Single WS modes */
332 const event_dequeue_t sso_hws_deq[2][2][2][2][2][2][2] = {
333 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
334 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_##name,
335 NIX_RX_FASTPATH_MODES
339 const event_dequeue_burst_t sso_hws_deq_burst[2][2][2][2][2][2][2] = {
340 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
341 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_burst_##name,
342 NIX_RX_FASTPATH_MODES
346 const event_dequeue_t sso_hws_deq_tmo[2][2][2][2][2][2][2] = {
347 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
348 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_tmo_##name,
349 NIX_RX_FASTPATH_MODES
353 const event_dequeue_burst_t
354 sso_hws_deq_tmo_burst[2][2][2][2][2][2][2] = {
355 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
356 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_tmo_burst_##name,
357 NIX_RX_FASTPATH_MODES
361 const event_dequeue_t sso_hws_deq_ca[2][2][2][2][2][2][2] = {
362 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
363 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_ca_##name,
364 NIX_RX_FASTPATH_MODES
368 const event_dequeue_burst_t
369 sso_hws_deq_ca_burst[2][2][2][2][2][2][2] = {
370 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
371 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_ca_burst_##name,
372 NIX_RX_FASTPATH_MODES
376 const event_dequeue_t sso_hws_deq_seg[2][2][2][2][2][2][2] = {
377 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
378 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_seg_##name,
379 NIX_RX_FASTPATH_MODES
383 const event_dequeue_burst_t
384 sso_hws_deq_seg_burst[2][2][2][2][2][2][2] = {
385 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
386 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_seg_burst_##name,
387 NIX_RX_FASTPATH_MODES
391 const event_dequeue_t sso_hws_deq_tmo_seg[2][2][2][2][2][2][2] = {
392 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
393 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_tmo_seg_##name,
394 NIX_RX_FASTPATH_MODES
398 const event_dequeue_burst_t
399 sso_hws_deq_tmo_seg_burst[2][2][2][2][2][2][2] = {
400 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
401 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_tmo_seg_burst_##name,
402 NIX_RX_FASTPATH_MODES
406 const event_dequeue_t sso_hws_deq_ca_seg[2][2][2][2][2][2][2] = {
407 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
408 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_ca_seg_##name,
409 NIX_RX_FASTPATH_MODES
413 const event_dequeue_burst_t
414 sso_hws_deq_ca_seg_burst[2][2][2][2][2][2][2] = {
415 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
416 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_ca_seg_burst_##name,
417 NIX_RX_FASTPATH_MODES
422 const event_dequeue_t sso_hws_dual_deq[2][2][2][2][2][2][2] = {
423 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
424 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_##name,
425 NIX_RX_FASTPATH_MODES
429 const event_dequeue_burst_t
430 sso_hws_dual_deq_burst[2][2][2][2][2][2][2] = {
431 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
432 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_burst_##name,
433 NIX_RX_FASTPATH_MODES
437 const event_dequeue_t sso_hws_dual_deq_tmo[2][2][2][2][2][2][2] = {
438 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
439 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_tmo_##name,
440 NIX_RX_FASTPATH_MODES
444 const event_dequeue_burst_t
445 sso_hws_dual_deq_tmo_burst[2][2][2][2][2][2][2] = {
446 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
447 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_tmo_burst_##name,
448 NIX_RX_FASTPATH_MODES
452 const event_dequeue_t sso_hws_dual_deq_ca[2][2][2][2][2][2][2] = {
453 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
454 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_ca_##name,
455 NIX_RX_FASTPATH_MODES
459 const event_dequeue_burst_t
460 sso_hws_dual_deq_ca_burst[2][2][2][2][2][2][2] = {
461 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
462 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_ca_burst_##name,
463 NIX_RX_FASTPATH_MODES
467 const event_dequeue_t sso_hws_dual_deq_seg[2][2][2][2][2][2][2] = {
468 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
469 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_seg_##name,
470 NIX_RX_FASTPATH_MODES
474 const event_dequeue_burst_t
475 sso_hws_dual_deq_seg_burst[2][2][2][2][2][2][2] = {
476 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
477 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_seg_burst_##name,
478 NIX_RX_FASTPATH_MODES
482 const event_dequeue_t sso_hws_dual_deq_tmo_seg[2][2][2][2][2][2][2] = {
483 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
484 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_tmo_seg_##name,
485 NIX_RX_FASTPATH_MODES
489 const event_dequeue_burst_t
490 sso_hws_dual_deq_tmo_seg_burst[2][2][2][2][2][2][2] = {
491 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
492 [f6][f5][f4][f3][f2][f1][f0] = \
493 cn9k_sso_hws_dual_deq_tmo_seg_burst_##name,
494 NIX_RX_FASTPATH_MODES
498 const event_dequeue_t sso_hws_dual_deq_ca_seg[2][2][2][2][2][2][2] = {
499 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
500 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_ca_seg_##name,
501 NIX_RX_FASTPATH_MODES
505 const event_dequeue_burst_t
506 sso_hws_dual_deq_ca_seg_burst[2][2][2][2][2][2][2] = {
507 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
508 [f6][f5][f4][f3][f2][f1][f0] = \
509 cn9k_sso_hws_dual_deq_ca_seg_burst_##name,
510 NIX_RX_FASTPATH_MODES
515 const event_tx_adapter_enqueue_t
516 sso_hws_tx_adptr_enq[2][2][2][2][2][2][2] = {
517 #define T(name, f6, f5, f4, f3, f2, f1, f0, sz, flags) \
518 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_tx_adptr_enq_##name,
519 NIX_TX_FASTPATH_MODES
523 const event_tx_adapter_enqueue_t
524 sso_hws_tx_adptr_enq_seg[2][2][2][2][2][2][2] = {
525 #define T(name, f6, f5, f4, f3, f2, f1, f0, sz, flags) \
526 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_tx_adptr_enq_seg_##name,
527 NIX_TX_FASTPATH_MODES
531 const event_tx_adapter_enqueue_t
532 sso_hws_dual_tx_adptr_enq[2][2][2][2][2][2][2] = {
533 #define T(name, f6, f5, f4, f3, f2, f1, f0, sz, flags) \
534 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_tx_adptr_enq_##name,
535 NIX_TX_FASTPATH_MODES
539 const event_tx_adapter_enqueue_t
540 sso_hws_dual_tx_adptr_enq_seg[2][2][2][2][2][2][2] = {
541 #define T(name, f6, f5, f4, f3, f2, f1, f0, sz, flags) \
542 [f6][f5][f4][f3][f2][f1][f0] = \
543 cn9k_sso_hws_dual_tx_adptr_enq_seg_##name,
544 NIX_TX_FASTPATH_MODES
548 event_dev->enqueue = cn9k_sso_hws_enq;
549 event_dev->enqueue_burst = cn9k_sso_hws_enq_burst;
550 event_dev->enqueue_new_burst = cn9k_sso_hws_enq_new_burst;
551 event_dev->enqueue_forward_burst = cn9k_sso_hws_enq_fwd_burst;
552 if (dev->rx_offloads & NIX_RX_MULTI_SEG_F) {
553 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue, sso_hws_deq_seg);
554 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
555 sso_hws_deq_seg_burst);
556 if (dev->is_timeout_deq) {
557 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
558 sso_hws_deq_tmo_seg);
559 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
560 sso_hws_deq_tmo_seg_burst);
562 if (dev->is_ca_internal_port) {
563 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
565 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
566 sso_hws_deq_ca_seg_burst);
569 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue, sso_hws_deq);
570 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
572 if (dev->is_timeout_deq) {
573 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
575 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
576 sso_hws_deq_tmo_burst);
578 if (dev->is_ca_internal_port) {
579 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
581 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
582 sso_hws_deq_ca_burst);
585 event_dev->ca_enqueue = cn9k_sso_hws_ca_enq;
587 if (dev->tx_offloads & NIX_TX_MULTI_SEG_F)
588 CN9K_SET_EVDEV_ENQ_OP(dev, event_dev->txa_enqueue,
589 sso_hws_tx_adptr_enq_seg);
591 CN9K_SET_EVDEV_ENQ_OP(dev, event_dev->txa_enqueue,
592 sso_hws_tx_adptr_enq);
595 event_dev->enqueue = cn9k_sso_hws_dual_enq;
596 event_dev->enqueue_burst = cn9k_sso_hws_dual_enq_burst;
597 event_dev->enqueue_new_burst = cn9k_sso_hws_dual_enq_new_burst;
598 event_dev->enqueue_forward_burst =
599 cn9k_sso_hws_dual_enq_fwd_burst;
600 event_dev->ca_enqueue = cn9k_sso_hws_dual_ca_enq;
602 if (dev->rx_offloads & NIX_RX_MULTI_SEG_F) {
603 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
604 sso_hws_dual_deq_seg);
605 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
606 sso_hws_dual_deq_seg_burst);
607 if (dev->is_timeout_deq) {
608 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
609 sso_hws_dual_deq_tmo_seg);
610 CN9K_SET_EVDEV_DEQ_OP(
611 dev, event_dev->dequeue_burst,
612 sso_hws_dual_deq_tmo_seg_burst);
614 if (dev->is_ca_internal_port) {
615 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
616 sso_hws_dual_deq_ca_seg);
617 CN9K_SET_EVDEV_DEQ_OP(
618 dev, event_dev->dequeue_burst,
619 sso_hws_dual_deq_ca_seg_burst);
622 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
624 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
625 sso_hws_dual_deq_burst);
626 if (dev->is_timeout_deq) {
627 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
628 sso_hws_dual_deq_tmo);
629 CN9K_SET_EVDEV_DEQ_OP(
630 dev, event_dev->dequeue_burst,
631 sso_hws_dual_deq_tmo_burst);
633 if (dev->is_ca_internal_port) {
634 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
635 sso_hws_dual_deq_ca);
636 CN9K_SET_EVDEV_DEQ_OP(
637 dev, event_dev->dequeue_burst,
638 sso_hws_dual_deq_ca_burst);
642 if (dev->tx_offloads & NIX_TX_MULTI_SEG_F)
643 CN9K_SET_EVDEV_ENQ_OP(dev, event_dev->txa_enqueue,
644 sso_hws_dual_tx_adptr_enq_seg);
646 CN9K_SET_EVDEV_ENQ_OP(dev, event_dev->txa_enqueue,
647 sso_hws_dual_tx_adptr_enq);
650 event_dev->txa_enqueue_same_dest = event_dev->txa_enqueue;
655 cn9k_sso_init_hws_mem(void *arg, uint8_t port_id)
657 struct cnxk_sso_evdev *dev = arg;
658 struct cn9k_sso_hws_dual *dws;
659 struct cn9k_sso_hws *ws;
663 dws = rte_zmalloc("cn9k_dual_ws",
664 sizeof(struct cn9k_sso_hws_dual) +
666 RTE_CACHE_LINE_SIZE);
668 plt_err("Failed to alloc memory for port=%d", port_id);
672 dws = RTE_PTR_ADD(dws, sizeof(struct cnxk_sso_hws_cookie));
673 dws->base[0] = roc_sso_hws_base_get(
674 &dev->sso, CN9K_DUAL_WS_PAIR_ID(port_id, 0));
675 dws->base[1] = roc_sso_hws_base_get(
676 &dev->sso, CN9K_DUAL_WS_PAIR_ID(port_id, 1));
677 cn9k_init_hws_ops(&dws->ws_state[0], dws->base[0]);
678 cn9k_init_hws_ops(&dws->ws_state[1], dws->base[1]);
679 dws->hws_id = port_id;
685 /* Allocate event port memory */
686 ws = rte_zmalloc("cn9k_ws",
687 sizeof(struct cn9k_sso_hws) +
689 RTE_CACHE_LINE_SIZE);
691 plt_err("Failed to alloc memory for port=%d", port_id);
695 /* First cache line is reserved for cookie */
696 ws = RTE_PTR_ADD(ws, sizeof(struct cnxk_sso_hws_cookie));
697 ws->base = roc_sso_hws_base_get(&dev->sso, port_id);
698 cn9k_init_hws_ops((struct cn9k_sso_hws_state *)ws, ws->base);
699 ws->hws_id = port_id;
709 cn9k_sso_info_get(struct rte_eventdev *event_dev,
710 struct rte_event_dev_info *dev_info)
712 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
714 dev_info->driver_name = RTE_STR(EVENTDEV_NAME_CN9K_PMD);
715 cnxk_sso_info_get(dev, dev_info);
719 cn9k_sso_dev_configure(const struct rte_eventdev *event_dev)
721 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
724 rc = cnxk_sso_dev_validate(event_dev);
726 plt_err("Invalid event device configuration");
730 rc = cn9k_sso_rsrc_init(dev, dev->nb_event_ports, dev->nb_event_queues);
732 plt_err("Failed to initialize SSO resources");
736 rc = cnxk_sso_xaq_allocate(dev);
740 rc = cnxk_setup_event_ports(event_dev, cn9k_sso_init_hws_mem,
745 /* Restore any prior port-queue mapping. */
746 cnxk_sso_restore_links(event_dev, cn9k_sso_hws_link);
753 roc_sso_rsrc_fini(&dev->sso);
754 dev->nb_event_ports = 0;
759 cn9k_sso_port_setup(struct rte_eventdev *event_dev, uint8_t port_id,
760 const struct rte_event_port_conf *port_conf)
763 RTE_SET_USED(port_conf);
764 return cnxk_sso_port_setup(event_dev, port_id, cn9k_sso_hws_setup);
768 cn9k_sso_port_release(void *port)
770 struct cnxk_sso_hws_cookie *gws_cookie = cnxk_sso_hws_get_cookie(port);
771 struct cnxk_sso_evdev *dev;
776 dev = cnxk_sso_pmd_priv(gws_cookie->event_dev);
777 if (!gws_cookie->configured)
780 cn9k_sso_hws_release(dev, port);
781 memset(gws_cookie, 0, sizeof(*gws_cookie));
783 rte_free(gws_cookie);
787 cn9k_sso_port_link(struct rte_eventdev *event_dev, void *port,
788 const uint8_t queues[], const uint8_t priorities[],
791 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
792 uint16_t hwgrp_ids[nb_links];
795 RTE_SET_USED(priorities);
796 for (link = 0; link < nb_links; link++)
797 hwgrp_ids[link] = queues[link];
798 nb_links = cn9k_sso_hws_link(dev, port, hwgrp_ids, nb_links);
800 return (int)nb_links;
804 cn9k_sso_port_unlink(struct rte_eventdev *event_dev, void *port,
805 uint8_t queues[], uint16_t nb_unlinks)
807 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
808 uint16_t hwgrp_ids[nb_unlinks];
811 for (unlink = 0; unlink < nb_unlinks; unlink++)
812 hwgrp_ids[unlink] = queues[unlink];
813 nb_unlinks = cn9k_sso_hws_unlink(dev, port, hwgrp_ids, nb_unlinks);
815 return (int)nb_unlinks;
819 cn9k_sso_start(struct rte_eventdev *event_dev)
823 rc = cn9k_sso_updt_tx_adptr_data(event_dev);
827 rc = cnxk_sso_start(event_dev, cn9k_sso_hws_reset,
828 cn9k_sso_hws_flush_events);
832 cn9k_sso_fp_fns_set(event_dev);
838 cn9k_sso_stop(struct rte_eventdev *event_dev)
840 cnxk_sso_stop(event_dev, cn9k_sso_hws_reset, cn9k_sso_hws_flush_events);
844 cn9k_sso_close(struct rte_eventdev *event_dev)
846 return cnxk_sso_close(event_dev, cn9k_sso_hws_unlink);
850 cn9k_sso_selftest(void)
852 return cnxk_sso_selftest(RTE_STR(event_cn9k));
856 cn9k_sso_rx_adapter_caps_get(const struct rte_eventdev *event_dev,
857 const struct rte_eth_dev *eth_dev, uint32_t *caps)
861 RTE_SET_USED(event_dev);
862 rc = strncmp(eth_dev->device->driver->name, "net_cn9k", 9);
864 *caps = RTE_EVENT_ETH_RX_ADAPTER_SW_CAP;
866 *caps = RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT |
867 RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ |
868 RTE_EVENT_ETH_RX_ADAPTER_CAP_OVERRIDE_FLOW_ID;
874 cn9k_sso_set_priv_mem(const struct rte_eventdev *event_dev, void *lookup_mem,
877 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
880 for (i = 0; i < dev->nb_event_ports; i++) {
882 struct cn9k_sso_hws_dual *dws =
883 event_dev->data->ports[i];
884 dws->lookup_mem = lookup_mem;
885 dws->tstamp = tstmp_info;
887 struct cn9k_sso_hws *ws = event_dev->data->ports[i];
888 ws->lookup_mem = lookup_mem;
889 ws->tstamp = tstmp_info;
895 cn9k_sso_rx_adapter_queue_add(
896 const struct rte_eventdev *event_dev, const struct rte_eth_dev *eth_dev,
898 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
900 struct cn9k_eth_rxq *rxq;
905 rc = strncmp(eth_dev->device->driver->name, "net_cn9k", 8);
909 rc = cnxk_sso_rx_adapter_queue_add(event_dev, eth_dev, rx_queue_id,
914 rxq = eth_dev->data->rx_queues[0];
915 lookup_mem = rxq->lookup_mem;
916 tstmp_info = rxq->tstamp;
917 cn9k_sso_set_priv_mem(event_dev, lookup_mem, tstmp_info);
918 cn9k_sso_fp_fns_set((struct rte_eventdev *)(uintptr_t)event_dev);
924 cn9k_sso_rx_adapter_queue_del(const struct rte_eventdev *event_dev,
925 const struct rte_eth_dev *eth_dev,
930 rc = strncmp(eth_dev->device->driver->name, "net_cn9k", 8);
934 return cnxk_sso_rx_adapter_queue_del(event_dev, eth_dev, rx_queue_id);
938 cn9k_sso_tx_adapter_caps_get(const struct rte_eventdev *dev,
939 const struct rte_eth_dev *eth_dev, uint32_t *caps)
944 ret = strncmp(eth_dev->device->driver->name, "net_cn9k", 8);
948 *caps = RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT;
954 cn9k_sso_txq_fc_update(const struct rte_eth_dev *eth_dev, int32_t tx_queue_id,
957 struct cnxk_eth_dev *cnxk_eth_dev = eth_dev->data->dev_private;
958 struct cn9k_eth_txq *txq;
959 struct roc_nix_sq *sq;
962 if (tx_queue_id < 0) {
963 for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
964 cn9k_sso_txq_fc_update(eth_dev, i, ena);
968 sq = &cnxk_eth_dev->sqs[tx_queue_id];
969 txq = eth_dev->data->tx_queues[tx_queue_id];
971 ena ? RTE_MIN(CNXK_SSO_SQB_LIMIT, sq->aura_sqb_bufs) :
973 txq->nb_sqb_bufs_adj =
975 RTE_ALIGN_MUL_CEIL(sq_limit,
976 (1ULL << txq->sqes_per_sqb_log2)) /
977 (1ULL << txq->sqes_per_sqb_log2);
978 txq->nb_sqb_bufs_adj = (70 * txq->nb_sqb_bufs_adj) / 100;
983 cn9k_sso_tx_adapter_queue_add(uint8_t id, const struct rte_eventdev *event_dev,
984 const struct rte_eth_dev *eth_dev,
990 rc = cnxk_sso_tx_adapter_queue_add(event_dev, eth_dev, tx_queue_id);
993 cn9k_sso_txq_fc_update(eth_dev, tx_queue_id, true);
994 rc = cn9k_sso_updt_tx_adptr_data(event_dev);
997 cn9k_sso_fp_fns_set((struct rte_eventdev *)(uintptr_t)event_dev);
1003 cn9k_sso_tx_adapter_queue_del(uint8_t id, const struct rte_eventdev *event_dev,
1004 const struct rte_eth_dev *eth_dev,
1005 int32_t tx_queue_id)
1010 rc = cnxk_sso_tx_adapter_queue_del(event_dev, eth_dev, tx_queue_id);
1013 cn9k_sso_txq_fc_update(eth_dev, tx_queue_id, false);
1014 return cn9k_sso_updt_tx_adptr_data(event_dev);
1018 cn9k_crypto_adapter_caps_get(const struct rte_eventdev *event_dev,
1019 const struct rte_cryptodev *cdev, uint32_t *caps)
1021 CNXK_VALID_DEV_OR_ERR_RET(event_dev->dev, "event_cn9k");
1022 CNXK_VALID_DEV_OR_ERR_RET(cdev->device, "crypto_cn9k");
1024 *caps = RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD |
1025 RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA;
1031 cn9k_crypto_adapter_qp_add(const struct rte_eventdev *event_dev,
1032 const struct rte_cryptodev *cdev,
1033 int32_t queue_pair_id, const struct rte_event *event)
1035 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
1037 RTE_SET_USED(event);
1039 CNXK_VALID_DEV_OR_ERR_RET(event_dev->dev, "event_cn9k");
1040 CNXK_VALID_DEV_OR_ERR_RET(cdev->device, "crypto_cn9k");
1042 dev->is_ca_internal_port = 1;
1043 cn9k_sso_fp_fns_set((struct rte_eventdev *)(uintptr_t)event_dev);
1045 return cnxk_crypto_adapter_qp_add(event_dev, cdev, queue_pair_id);
1049 cn9k_crypto_adapter_qp_del(const struct rte_eventdev *event_dev,
1050 const struct rte_cryptodev *cdev,
1051 int32_t queue_pair_id)
1053 CNXK_VALID_DEV_OR_ERR_RET(event_dev->dev, "event_cn9k");
1054 CNXK_VALID_DEV_OR_ERR_RET(cdev->device, "crypto_cn9k");
1056 return cnxk_crypto_adapter_qp_del(cdev, queue_pair_id);
1059 static struct eventdev_ops cn9k_sso_dev_ops = {
1060 .dev_infos_get = cn9k_sso_info_get,
1061 .dev_configure = cn9k_sso_dev_configure,
1062 .queue_def_conf = cnxk_sso_queue_def_conf,
1063 .queue_setup = cnxk_sso_queue_setup,
1064 .queue_release = cnxk_sso_queue_release,
1065 .port_def_conf = cnxk_sso_port_def_conf,
1066 .port_setup = cn9k_sso_port_setup,
1067 .port_release = cn9k_sso_port_release,
1068 .port_link = cn9k_sso_port_link,
1069 .port_unlink = cn9k_sso_port_unlink,
1070 .timeout_ticks = cnxk_sso_timeout_ticks,
1072 .eth_rx_adapter_caps_get = cn9k_sso_rx_adapter_caps_get,
1073 .eth_rx_adapter_queue_add = cn9k_sso_rx_adapter_queue_add,
1074 .eth_rx_adapter_queue_del = cn9k_sso_rx_adapter_queue_del,
1075 .eth_rx_adapter_start = cnxk_sso_rx_adapter_start,
1076 .eth_rx_adapter_stop = cnxk_sso_rx_adapter_stop,
1078 .eth_tx_adapter_caps_get = cn9k_sso_tx_adapter_caps_get,
1079 .eth_tx_adapter_queue_add = cn9k_sso_tx_adapter_queue_add,
1080 .eth_tx_adapter_queue_del = cn9k_sso_tx_adapter_queue_del,
1082 .timer_adapter_caps_get = cnxk_tim_caps_get,
1084 .crypto_adapter_caps_get = cn9k_crypto_adapter_caps_get,
1085 .crypto_adapter_queue_pair_add = cn9k_crypto_adapter_qp_add,
1086 .crypto_adapter_queue_pair_del = cn9k_crypto_adapter_qp_del,
1088 .dump = cnxk_sso_dump,
1089 .dev_start = cn9k_sso_start,
1090 .dev_stop = cn9k_sso_stop,
1091 .dev_close = cn9k_sso_close,
1092 .dev_selftest = cn9k_sso_selftest,
1096 cn9k_sso_init(struct rte_eventdev *event_dev)
1098 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
1101 if (RTE_CACHE_LINE_SIZE != 128) {
1102 plt_err("Driver not compiled for CN9K");
1106 rc = roc_plt_init();
1108 plt_err("Failed to initialize platform model");
1112 event_dev->dev_ops = &cn9k_sso_dev_ops;
1113 /* For secondary processes, the primary has done all the work */
1114 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1115 cn9k_sso_fp_fns_set(event_dev);
1119 rc = cnxk_sso_init(event_dev);
1123 cn9k_sso_set_rsrc(cnxk_sso_pmd_priv(event_dev));
1124 if (!dev->max_event_ports || !dev->max_event_queues) {
1125 plt_err("Not enough eventdev resource queues=%d ports=%d",
1126 dev->max_event_queues, dev->max_event_ports);
1127 cnxk_sso_fini(event_dev);
1131 plt_sso_dbg("Initializing %s max_queues=%d max_ports=%d",
1132 event_dev->data->name, dev->max_event_queues,
1133 dev->max_event_ports);
1139 cn9k_sso_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
1141 return rte_event_pmd_pci_probe(
1142 pci_drv, pci_dev, sizeof(struct cnxk_sso_evdev), cn9k_sso_init);
1145 static const struct rte_pci_id cn9k_pci_sso_map[] = {
1151 static struct rte_pci_driver cn9k_pci_sso = {
1152 .id_table = cn9k_pci_sso_map,
1153 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA,
1154 .probe = cn9k_sso_probe,
1155 .remove = cnxk_sso_remove,
1158 RTE_PMD_REGISTER_PCI(event_cn9k, cn9k_pci_sso);
1159 RTE_PMD_REGISTER_PCI_TABLE(event_cn9k, cn9k_pci_sso_map);
1160 RTE_PMD_REGISTER_KMOD_DEP(event_cn9k, "vfio-pci");
1161 RTE_PMD_REGISTER_PARAM_STRING(event_cn9k, CNXK_SSO_XAE_CNT "=<int>"
1162 CNXK_SSO_GGRP_QOS "=<string>"
1163 CNXK_SSO_FORCE_BP "=1"
1164 CN9K_SSO_SINGLE_WS "=1"
1165 CNXK_TIM_DISABLE_NPA "=1"
1166 CNXK_TIM_CHNK_SLOTS "=<int>"
1167 CNXK_TIM_RINGS_LMT "=<int>"
1168 CNXK_TIM_STATS_ENA "=1");