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 *grps_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 rte_memcpy(dws->grps_base, grps_base,
102 sizeof(uintptr_t) * CNXK_SSO_MAX_HWGRP);
103 dws->fc_mem = dev->fc_mem;
104 dws->xaq_lmt = dev->xaq_lmt;
106 plt_write64(val, dws->base[0] + SSOW_LF_GWS_NW_TIM);
107 plt_write64(val, dws->base[1] + SSOW_LF_GWS_NW_TIM);
110 rte_memcpy(ws->grps_base, grps_base,
111 sizeof(uintptr_t) * CNXK_SSO_MAX_HWGRP);
112 ws->fc_mem = dev->fc_mem;
113 ws->xaq_lmt = dev->xaq_lmt;
115 plt_write64(val, ws->base + SSOW_LF_GWS_NW_TIM);
120 cn9k_sso_hws_release(void *arg, void *hws)
122 struct cnxk_sso_evdev *dev = arg;
123 struct cn9k_sso_hws_dual *dws;
124 struct cn9k_sso_hws *ws;
129 for (i = 0; i < dev->nb_event_queues; i++) {
130 roc_sso_hws_unlink(&dev->sso,
131 CN9K_DUAL_WS_PAIR_ID(dws->hws_id, 0),
133 roc_sso_hws_unlink(&dev->sso,
134 CN9K_DUAL_WS_PAIR_ID(dws->hws_id, 1),
137 memset(dws, 0, sizeof(*dws));
140 for (i = 0; i < dev->nb_event_queues; i++)
141 roc_sso_hws_unlink(&dev->sso, ws->hws_id,
143 memset(ws, 0, sizeof(*ws));
148 cn9k_sso_hws_flush_events(void *hws, uint8_t queue_id, uintptr_t base,
149 cnxk_handle_event_t fn, void *arg)
151 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(arg);
152 struct cn9k_sso_hws_dual *dws;
153 struct cn9k_sso_hws_state *st;
154 struct cn9k_sso_hws *ws;
155 uint64_t cq_ds_cnt = 1;
162 plt_write64(0, base + SSO_LF_GGRP_QCTL);
164 req = queue_id; /* GGRP ID */
165 req |= BIT_ULL(18); /* Grouped */
166 req |= BIT_ULL(16); /* WAIT */
168 aq_cnt = plt_read64(base + SSO_LF_GGRP_AQ_CNT);
169 ds_cnt = plt_read64(base + SSO_LF_GGRP_MISC_CNT);
170 cq_ds_cnt = plt_read64(base + SSO_LF_GGRP_INT_CNT);
171 cq_ds_cnt &= 0x3FFF3FFF0000;
175 st = &dws->ws_state[0];
176 ws_base = dws->base[0];
179 st = (struct cn9k_sso_hws_state *)ws;
183 while (aq_cnt || cq_ds_cnt || ds_cnt) {
184 plt_write64(req, st->getwrk_op);
185 cn9k_sso_hws_get_work_empty(st, &ev);
186 if (fn != NULL && ev.u64 != 0)
188 if (ev.sched_type != SSO_TT_EMPTY)
189 cnxk_sso_hws_swtag_flush(st->tag_op,
192 val = plt_read64(ws_base + SSOW_LF_GWS_PENDSTATE);
193 } while (val & BIT_ULL(56));
194 aq_cnt = plt_read64(base + SSO_LF_GGRP_AQ_CNT);
195 ds_cnt = plt_read64(base + SSO_LF_GGRP_MISC_CNT);
196 cq_ds_cnt = plt_read64(base + SSO_LF_GGRP_INT_CNT);
197 /* Extract cq and ds count */
198 cq_ds_cnt &= 0x3FFF3FFF0000;
201 plt_write64(0, ws_base + SSOW_LF_GWS_OP_GWC_INVAL);
205 cn9k_sso_hws_reset(void *arg, void *hws)
207 struct cnxk_sso_evdev *dev = arg;
208 struct cn9k_sso_hws_dual *dws;
209 struct cn9k_sso_hws *ws;
218 for (i = 0; i < (dev->dual_ws ? CN9K_DUAL_WS_NB_WS : 1); i++) {
219 base = dev->dual_ws ? dws->base[i] : ws->base;
220 /* Wait till getwork/swtp/waitw/desched completes. */
222 pend_state = plt_read64(base + SSOW_LF_GWS_PENDSTATE);
223 } while (pend_state & (BIT_ULL(63) | BIT_ULL(62) | BIT_ULL(58) |
226 tag = plt_read64(base + SSOW_LF_GWS_TAG);
227 pend_tt = (tag >> 32) & 0x3;
228 if (pend_tt != SSO_TT_EMPTY) { /* Work was pending */
229 if (pend_tt == SSO_TT_ATOMIC ||
230 pend_tt == SSO_TT_ORDERED)
231 cnxk_sso_hws_swtag_untag(
232 base + SSOW_LF_GWS_OP_SWTAG_UNTAG);
233 plt_write64(0, base + SSOW_LF_GWS_OP_DESCHED);
236 /* Wait for desched to complete. */
238 pend_state = plt_read64(base + SSOW_LF_GWS_PENDSTATE);
239 } while (pend_state & BIT_ULL(58));
244 cn9k_sso_set_rsrc(void *arg)
246 struct cnxk_sso_evdev *dev = arg;
249 dev->max_event_ports = dev->sso.max_hws / CN9K_DUAL_WS_NB_WS;
251 dev->max_event_ports = dev->sso.max_hws;
252 dev->max_event_queues =
253 dev->sso.max_hwgrp > RTE_EVENT_MAX_QUEUES_PER_DEV ?
254 RTE_EVENT_MAX_QUEUES_PER_DEV :
259 cn9k_sso_rsrc_init(void *arg, uint8_t hws, uint8_t hwgrp)
261 struct cnxk_sso_evdev *dev = arg;
264 hws = hws * CN9K_DUAL_WS_NB_WS;
266 return roc_sso_rsrc_init(&dev->sso, hws, hwgrp);
270 cn9k_sso_updt_tx_adptr_data(const struct rte_eventdev *event_dev)
272 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
275 if (dev->tx_adptr_data == NULL)
278 for (i = 0; i < dev->nb_event_ports; i++) {
280 struct cn9k_sso_hws_dual *dws =
281 event_dev->data->ports[i];
284 ws_cookie = cnxk_sso_hws_get_cookie(dws);
285 ws_cookie = rte_realloc_socket(
287 sizeof(struct cnxk_sso_hws_cookie) +
288 sizeof(struct cn9k_sso_hws_dual) +
290 (dev->max_port_id + 1) *
291 RTE_MAX_QUEUES_PER_PORT),
292 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
293 if (ws_cookie == NULL)
295 dws = RTE_PTR_ADD(ws_cookie,
296 sizeof(struct cnxk_sso_hws_cookie));
297 memcpy(&dws->tx_adptr_data, dev->tx_adptr_data,
298 sizeof(uint64_t) * (dev->max_port_id + 1) *
299 RTE_MAX_QUEUES_PER_PORT);
300 event_dev->data->ports[i] = dws;
302 struct cn9k_sso_hws *ws = event_dev->data->ports[i];
305 ws_cookie = cnxk_sso_hws_get_cookie(ws);
306 ws_cookie = rte_realloc_socket(
308 sizeof(struct cnxk_sso_hws_cookie) +
309 sizeof(struct cn9k_sso_hws_dual) +
311 (dev->max_port_id + 1) *
312 RTE_MAX_QUEUES_PER_PORT),
313 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
314 if (ws_cookie == NULL)
316 ws = RTE_PTR_ADD(ws_cookie,
317 sizeof(struct cnxk_sso_hws_cookie));
318 memcpy(&ws->tx_adptr_data, dev->tx_adptr_data,
319 sizeof(uint64_t) * (dev->max_port_id + 1) *
320 RTE_MAX_QUEUES_PER_PORT);
321 event_dev->data->ports[i] = ws;
330 cn9k_sso_fp_fns_set(struct rte_eventdev *event_dev)
332 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
333 /* Single WS modes */
334 const event_dequeue_t sso_hws_deq[2][2][2][2][2][2][2] = {
335 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
336 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_##name,
337 NIX_RX_FASTPATH_MODES
341 const event_dequeue_burst_t sso_hws_deq_burst[2][2][2][2][2][2][2] = {
342 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
343 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_burst_##name,
344 NIX_RX_FASTPATH_MODES
348 const event_dequeue_t sso_hws_deq_tmo[2][2][2][2][2][2][2] = {
349 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
350 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_tmo_##name,
351 NIX_RX_FASTPATH_MODES
355 const event_dequeue_burst_t
356 sso_hws_deq_tmo_burst[2][2][2][2][2][2][2] = {
357 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
358 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_tmo_burst_##name,
359 NIX_RX_FASTPATH_MODES
363 const event_dequeue_t sso_hws_deq_ca[2][2][2][2][2][2][2] = {
364 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
365 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_ca_##name,
366 NIX_RX_FASTPATH_MODES
370 const event_dequeue_burst_t
371 sso_hws_deq_ca_burst[2][2][2][2][2][2][2] = {
372 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
373 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_ca_burst_##name,
374 NIX_RX_FASTPATH_MODES
378 const event_dequeue_t sso_hws_deq_seg[2][2][2][2][2][2][2] = {
379 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
380 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_seg_##name,
381 NIX_RX_FASTPATH_MODES
385 const event_dequeue_burst_t
386 sso_hws_deq_seg_burst[2][2][2][2][2][2][2] = {
387 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
388 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_seg_burst_##name,
389 NIX_RX_FASTPATH_MODES
393 const event_dequeue_t sso_hws_deq_tmo_seg[2][2][2][2][2][2][2] = {
394 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
395 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_tmo_seg_##name,
396 NIX_RX_FASTPATH_MODES
400 const event_dequeue_burst_t
401 sso_hws_deq_tmo_seg_burst[2][2][2][2][2][2][2] = {
402 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
403 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_tmo_seg_burst_##name,
404 NIX_RX_FASTPATH_MODES
408 const event_dequeue_t sso_hws_deq_ca_seg[2][2][2][2][2][2][2] = {
409 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
410 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_ca_seg_##name,
411 NIX_RX_FASTPATH_MODES
415 const event_dequeue_burst_t
416 sso_hws_deq_ca_seg_burst[2][2][2][2][2][2][2] = {
417 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
418 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_deq_ca_seg_burst_##name,
419 NIX_RX_FASTPATH_MODES
424 const event_dequeue_t sso_hws_dual_deq[2][2][2][2][2][2][2] = {
425 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
426 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_##name,
427 NIX_RX_FASTPATH_MODES
431 const event_dequeue_burst_t
432 sso_hws_dual_deq_burst[2][2][2][2][2][2][2] = {
433 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
434 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_burst_##name,
435 NIX_RX_FASTPATH_MODES
439 const event_dequeue_t sso_hws_dual_deq_tmo[2][2][2][2][2][2][2] = {
440 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
441 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_tmo_##name,
442 NIX_RX_FASTPATH_MODES
446 const event_dequeue_burst_t
447 sso_hws_dual_deq_tmo_burst[2][2][2][2][2][2][2] = {
448 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
449 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_tmo_burst_##name,
450 NIX_RX_FASTPATH_MODES
454 const event_dequeue_t sso_hws_dual_deq_ca[2][2][2][2][2][2][2] = {
455 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
456 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_ca_##name,
457 NIX_RX_FASTPATH_MODES
461 const event_dequeue_burst_t
462 sso_hws_dual_deq_ca_burst[2][2][2][2][2][2][2] = {
463 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
464 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_ca_burst_##name,
465 NIX_RX_FASTPATH_MODES
469 const event_dequeue_t sso_hws_dual_deq_seg[2][2][2][2][2][2][2] = {
470 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
471 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_seg_##name,
472 NIX_RX_FASTPATH_MODES
476 const event_dequeue_burst_t
477 sso_hws_dual_deq_seg_burst[2][2][2][2][2][2][2] = {
478 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
479 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_seg_burst_##name,
480 NIX_RX_FASTPATH_MODES
484 const event_dequeue_t sso_hws_dual_deq_tmo_seg[2][2][2][2][2][2][2] = {
485 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
486 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_tmo_seg_##name,
487 NIX_RX_FASTPATH_MODES
491 const event_dequeue_burst_t
492 sso_hws_dual_deq_tmo_seg_burst[2][2][2][2][2][2][2] = {
493 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
494 [f6][f5][f4][f3][f2][f1][f0] = \
495 cn9k_sso_hws_dual_deq_tmo_seg_burst_##name,
496 NIX_RX_FASTPATH_MODES
500 const event_dequeue_t sso_hws_dual_deq_ca_seg[2][2][2][2][2][2][2] = {
501 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
502 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_deq_ca_seg_##name,
503 NIX_RX_FASTPATH_MODES
507 const event_dequeue_burst_t
508 sso_hws_dual_deq_ca_seg_burst[2][2][2][2][2][2][2] = {
509 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
510 [f6][f5][f4][f3][f2][f1][f0] = \
511 cn9k_sso_hws_dual_deq_ca_seg_burst_##name,
512 NIX_RX_FASTPATH_MODES
517 const event_tx_adapter_enqueue
518 sso_hws_tx_adptr_enq[2][2][2][2][2][2][2] = {
519 #define T(name, f6, f5, f4, f3, f2, f1, f0, sz, flags) \
520 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_tx_adptr_enq_##name,
521 NIX_TX_FASTPATH_MODES
525 const event_tx_adapter_enqueue
526 sso_hws_tx_adptr_enq_seg[2][2][2][2][2][2][2] = {
527 #define T(name, f6, f5, f4, f3, f2, f1, f0, sz, flags) \
528 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_tx_adptr_enq_seg_##name,
529 NIX_TX_FASTPATH_MODES
533 const event_tx_adapter_enqueue
534 sso_hws_dual_tx_adptr_enq[2][2][2][2][2][2][2] = {
535 #define T(name, f6, f5, f4, f3, f2, f1, f0, sz, flags) \
536 [f6][f5][f4][f3][f2][f1][f0] = cn9k_sso_hws_dual_tx_adptr_enq_##name,
537 NIX_TX_FASTPATH_MODES
541 const event_tx_adapter_enqueue
542 sso_hws_dual_tx_adptr_enq_seg[2][2][2][2][2][2][2] = {
543 #define T(name, f6, f5, f4, f3, f2, f1, f0, sz, flags) \
544 [f6][f5][f4][f3][f2][f1][f0] = \
545 cn9k_sso_hws_dual_tx_adptr_enq_seg_##name,
546 NIX_TX_FASTPATH_MODES
550 event_dev->enqueue = cn9k_sso_hws_enq;
551 event_dev->enqueue_burst = cn9k_sso_hws_enq_burst;
552 event_dev->enqueue_new_burst = cn9k_sso_hws_enq_new_burst;
553 event_dev->enqueue_forward_burst = cn9k_sso_hws_enq_fwd_burst;
554 if (dev->rx_offloads & NIX_RX_MULTI_SEG_F) {
555 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue, sso_hws_deq_seg);
556 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
557 sso_hws_deq_seg_burst);
558 if (dev->is_timeout_deq) {
559 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
560 sso_hws_deq_tmo_seg);
561 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
562 sso_hws_deq_tmo_seg_burst);
564 if (dev->is_ca_internal_port) {
565 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
567 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
568 sso_hws_deq_ca_seg_burst);
571 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue, sso_hws_deq);
572 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
574 if (dev->is_timeout_deq) {
575 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
577 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
578 sso_hws_deq_tmo_burst);
580 if (dev->is_ca_internal_port) {
581 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
583 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
584 sso_hws_deq_ca_burst);
587 event_dev->ca_enqueue = cn9k_sso_hws_ca_enq;
589 if (dev->tx_offloads & NIX_TX_MULTI_SEG_F)
590 CN9K_SET_EVDEV_ENQ_OP(dev, event_dev->txa_enqueue,
591 sso_hws_tx_adptr_enq_seg);
593 CN9K_SET_EVDEV_ENQ_OP(dev, event_dev->txa_enqueue,
594 sso_hws_tx_adptr_enq);
597 event_dev->enqueue = cn9k_sso_hws_dual_enq;
598 event_dev->enqueue_burst = cn9k_sso_hws_dual_enq_burst;
599 event_dev->enqueue_new_burst = cn9k_sso_hws_dual_enq_new_burst;
600 event_dev->enqueue_forward_burst =
601 cn9k_sso_hws_dual_enq_fwd_burst;
602 event_dev->ca_enqueue = cn9k_sso_hws_dual_ca_enq;
604 if (dev->rx_offloads & NIX_RX_MULTI_SEG_F) {
605 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
606 sso_hws_dual_deq_seg);
607 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
608 sso_hws_dual_deq_seg_burst);
609 if (dev->is_timeout_deq) {
610 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
611 sso_hws_dual_deq_tmo_seg);
612 CN9K_SET_EVDEV_DEQ_OP(
613 dev, event_dev->dequeue_burst,
614 sso_hws_dual_deq_tmo_seg_burst);
616 if (dev->is_ca_internal_port) {
617 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
618 sso_hws_dual_deq_ca_seg);
619 CN9K_SET_EVDEV_DEQ_OP(
620 dev, event_dev->dequeue_burst,
621 sso_hws_dual_deq_ca_seg_burst);
624 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
626 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue_burst,
627 sso_hws_dual_deq_burst);
628 if (dev->is_timeout_deq) {
629 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
630 sso_hws_dual_deq_tmo);
631 CN9K_SET_EVDEV_DEQ_OP(
632 dev, event_dev->dequeue_burst,
633 sso_hws_dual_deq_tmo_burst);
635 if (dev->is_ca_internal_port) {
636 CN9K_SET_EVDEV_DEQ_OP(dev, event_dev->dequeue,
637 sso_hws_dual_deq_ca);
638 CN9K_SET_EVDEV_DEQ_OP(
639 dev, event_dev->dequeue_burst,
640 sso_hws_dual_deq_ca_burst);
644 if (dev->tx_offloads & NIX_TX_MULTI_SEG_F)
645 CN9K_SET_EVDEV_ENQ_OP(dev, event_dev->txa_enqueue,
646 sso_hws_dual_tx_adptr_enq_seg);
648 CN9K_SET_EVDEV_ENQ_OP(dev, event_dev->txa_enqueue,
649 sso_hws_dual_tx_adptr_enq);
652 event_dev->txa_enqueue_same_dest = event_dev->txa_enqueue;
657 cn9k_sso_init_hws_mem(void *arg, uint8_t port_id)
659 struct cnxk_sso_evdev *dev = arg;
660 struct cn9k_sso_hws_dual *dws;
661 struct cn9k_sso_hws *ws;
665 dws = rte_zmalloc("cn9k_dual_ws",
666 sizeof(struct cn9k_sso_hws_dual) +
668 RTE_CACHE_LINE_SIZE);
670 plt_err("Failed to alloc memory for port=%d", port_id);
674 dws = RTE_PTR_ADD(dws, sizeof(struct cnxk_sso_hws_cookie));
675 dws->base[0] = roc_sso_hws_base_get(
676 &dev->sso, CN9K_DUAL_WS_PAIR_ID(port_id, 0));
677 dws->base[1] = roc_sso_hws_base_get(
678 &dev->sso, CN9K_DUAL_WS_PAIR_ID(port_id, 1));
679 cn9k_init_hws_ops(&dws->ws_state[0], dws->base[0]);
680 cn9k_init_hws_ops(&dws->ws_state[1], dws->base[1]);
681 dws->hws_id = port_id;
687 /* Allocate event port memory */
688 ws = rte_zmalloc("cn9k_ws",
689 sizeof(struct cn9k_sso_hws) +
691 RTE_CACHE_LINE_SIZE);
693 plt_err("Failed to alloc memory for port=%d", port_id);
697 /* First cache line is reserved for cookie */
698 ws = RTE_PTR_ADD(ws, sizeof(struct cnxk_sso_hws_cookie));
699 ws->base = roc_sso_hws_base_get(&dev->sso, port_id);
700 cn9k_init_hws_ops((struct cn9k_sso_hws_state *)ws, ws->base);
701 ws->hws_id = port_id;
711 cn9k_sso_info_get(struct rte_eventdev *event_dev,
712 struct rte_event_dev_info *dev_info)
714 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
716 dev_info->driver_name = RTE_STR(EVENTDEV_NAME_CN9K_PMD);
717 cnxk_sso_info_get(dev, dev_info);
721 cn9k_sso_dev_configure(const struct rte_eventdev *event_dev)
723 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
726 rc = cnxk_sso_dev_validate(event_dev);
728 plt_err("Invalid event device configuration");
732 roc_sso_rsrc_fini(&dev->sso);
734 rc = cn9k_sso_rsrc_init(dev, dev->nb_event_ports, dev->nb_event_queues);
736 plt_err("Failed to initialize SSO resources");
740 rc = cnxk_sso_xaq_allocate(dev);
744 rc = cnxk_setup_event_ports(event_dev, cn9k_sso_init_hws_mem,
749 /* Restore any prior port-queue mapping. */
750 cnxk_sso_restore_links(event_dev, cn9k_sso_hws_link);
757 roc_sso_rsrc_fini(&dev->sso);
758 dev->nb_event_ports = 0;
763 cn9k_sso_port_setup(struct rte_eventdev *event_dev, uint8_t port_id,
764 const struct rte_event_port_conf *port_conf)
767 RTE_SET_USED(port_conf);
768 return cnxk_sso_port_setup(event_dev, port_id, cn9k_sso_hws_setup);
772 cn9k_sso_port_release(void *port)
774 struct cnxk_sso_hws_cookie *gws_cookie = cnxk_sso_hws_get_cookie(port);
775 struct cnxk_sso_evdev *dev;
780 dev = cnxk_sso_pmd_priv(gws_cookie->event_dev);
781 if (!gws_cookie->configured)
784 cn9k_sso_hws_release(dev, port);
785 memset(gws_cookie, 0, sizeof(*gws_cookie));
787 rte_free(gws_cookie);
791 cn9k_sso_port_link(struct rte_eventdev *event_dev, void *port,
792 const uint8_t queues[], const uint8_t priorities[],
795 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
796 uint16_t hwgrp_ids[nb_links];
799 RTE_SET_USED(priorities);
800 for (link = 0; link < nb_links; link++)
801 hwgrp_ids[link] = queues[link];
802 nb_links = cn9k_sso_hws_link(dev, port, hwgrp_ids, nb_links);
804 return (int)nb_links;
808 cn9k_sso_port_unlink(struct rte_eventdev *event_dev, void *port,
809 uint8_t queues[], uint16_t nb_unlinks)
811 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
812 uint16_t hwgrp_ids[nb_unlinks];
815 for (unlink = 0; unlink < nb_unlinks; unlink++)
816 hwgrp_ids[unlink] = queues[unlink];
817 nb_unlinks = cn9k_sso_hws_unlink(dev, port, hwgrp_ids, nb_unlinks);
819 return (int)nb_unlinks;
823 cn9k_sso_start(struct rte_eventdev *event_dev)
827 rc = cn9k_sso_updt_tx_adptr_data(event_dev);
831 rc = cnxk_sso_start(event_dev, cn9k_sso_hws_reset,
832 cn9k_sso_hws_flush_events);
836 cn9k_sso_fp_fns_set(event_dev);
842 cn9k_sso_stop(struct rte_eventdev *event_dev)
844 cnxk_sso_stop(event_dev, cn9k_sso_hws_reset, cn9k_sso_hws_flush_events);
848 cn9k_sso_close(struct rte_eventdev *event_dev)
850 return cnxk_sso_close(event_dev, cn9k_sso_hws_unlink);
854 cn9k_sso_selftest(void)
856 return cnxk_sso_selftest(RTE_STR(event_cn9k));
860 cn9k_sso_rx_adapter_caps_get(const struct rte_eventdev *event_dev,
861 const struct rte_eth_dev *eth_dev, uint32_t *caps)
865 RTE_SET_USED(event_dev);
866 rc = strncmp(eth_dev->device->driver->name, "net_cn9k", 9);
868 *caps = RTE_EVENT_ETH_RX_ADAPTER_SW_CAP;
870 *caps = RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT |
871 RTE_EVENT_ETH_RX_ADAPTER_CAP_MULTI_EVENTQ |
872 RTE_EVENT_ETH_RX_ADAPTER_CAP_OVERRIDE_FLOW_ID;
878 cn9k_sso_set_priv_mem(const struct rte_eventdev *event_dev, void *lookup_mem,
881 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
884 for (i = 0; i < dev->nb_event_ports; i++) {
886 struct cn9k_sso_hws_dual *dws =
887 event_dev->data->ports[i];
888 dws->lookup_mem = lookup_mem;
889 dws->tstamp = tstmp_info;
891 struct cn9k_sso_hws *ws = event_dev->data->ports[i];
892 ws->lookup_mem = lookup_mem;
893 ws->tstamp = tstmp_info;
899 cn9k_sso_rx_adapter_queue_add(
900 const struct rte_eventdev *event_dev, const struct rte_eth_dev *eth_dev,
902 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
904 struct cn9k_eth_rxq *rxq;
909 rc = strncmp(eth_dev->device->driver->name, "net_cn9k", 8);
913 rc = cnxk_sso_rx_adapter_queue_add(event_dev, eth_dev, rx_queue_id,
918 rxq = eth_dev->data->rx_queues[0];
919 lookup_mem = rxq->lookup_mem;
920 tstmp_info = rxq->tstamp;
921 cn9k_sso_set_priv_mem(event_dev, lookup_mem, tstmp_info);
922 cn9k_sso_fp_fns_set((struct rte_eventdev *)(uintptr_t)event_dev);
928 cn9k_sso_rx_adapter_queue_del(const struct rte_eventdev *event_dev,
929 const struct rte_eth_dev *eth_dev,
934 rc = strncmp(eth_dev->device->driver->name, "net_cn9k", 8);
938 return cnxk_sso_rx_adapter_queue_del(event_dev, eth_dev, rx_queue_id);
942 cn9k_sso_tx_adapter_caps_get(const struct rte_eventdev *dev,
943 const struct rte_eth_dev *eth_dev, uint32_t *caps)
948 ret = strncmp(eth_dev->device->driver->name, "net_cn9k", 8);
952 *caps = RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT;
958 cn9k_sso_txq_fc_update(const struct rte_eth_dev *eth_dev, int32_t tx_queue_id,
961 struct cnxk_eth_dev *cnxk_eth_dev = eth_dev->data->dev_private;
962 struct cn9k_eth_txq *txq;
963 struct roc_nix_sq *sq;
966 if (tx_queue_id < 0) {
967 for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
968 cn9k_sso_txq_fc_update(eth_dev, i, ena);
972 sq = &cnxk_eth_dev->sqs[tx_queue_id];
973 txq = eth_dev->data->tx_queues[tx_queue_id];
975 ena ? RTE_MIN(CNXK_SSO_SQB_LIMIT, sq->aura_sqb_bufs) :
977 txq->nb_sqb_bufs_adj =
979 RTE_ALIGN_MUL_CEIL(sq_limit,
980 (1ULL << txq->sqes_per_sqb_log2)) /
981 (1ULL << txq->sqes_per_sqb_log2);
982 txq->nb_sqb_bufs_adj = (70 * txq->nb_sqb_bufs_adj) / 100;
987 cn9k_sso_tx_adapter_queue_add(uint8_t id, const struct rte_eventdev *event_dev,
988 const struct rte_eth_dev *eth_dev,
994 rc = cnxk_sso_tx_adapter_queue_add(event_dev, eth_dev, tx_queue_id);
997 cn9k_sso_txq_fc_update(eth_dev, tx_queue_id, true);
998 rc = cn9k_sso_updt_tx_adptr_data(event_dev);
1001 cn9k_sso_fp_fns_set((struct rte_eventdev *)(uintptr_t)event_dev);
1007 cn9k_sso_tx_adapter_queue_del(uint8_t id, const struct rte_eventdev *event_dev,
1008 const struct rte_eth_dev *eth_dev,
1009 int32_t tx_queue_id)
1014 rc = cnxk_sso_tx_adapter_queue_del(event_dev, eth_dev, tx_queue_id);
1017 cn9k_sso_txq_fc_update(eth_dev, tx_queue_id, false);
1018 return cn9k_sso_updt_tx_adptr_data(event_dev);
1022 cn9k_crypto_adapter_caps_get(const struct rte_eventdev *event_dev,
1023 const struct rte_cryptodev *cdev, uint32_t *caps)
1025 CNXK_VALID_DEV_OR_ERR_RET(event_dev->dev, "event_cn9k");
1026 CNXK_VALID_DEV_OR_ERR_RET(cdev->device, "crypto_cn9k");
1028 *caps = RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD |
1029 RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA;
1035 cn9k_crypto_adapter_qp_add(const struct rte_eventdev *event_dev,
1036 const struct rte_cryptodev *cdev,
1037 int32_t queue_pair_id, const struct rte_event *event)
1039 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
1041 RTE_SET_USED(event);
1043 CNXK_VALID_DEV_OR_ERR_RET(event_dev->dev, "event_cn9k");
1044 CNXK_VALID_DEV_OR_ERR_RET(cdev->device, "crypto_cn9k");
1046 dev->is_ca_internal_port = 1;
1047 cn9k_sso_fp_fns_set((struct rte_eventdev *)(uintptr_t)event_dev);
1049 return cnxk_crypto_adapter_qp_add(event_dev, cdev, queue_pair_id);
1053 cn9k_crypto_adapter_qp_del(const struct rte_eventdev *event_dev,
1054 const struct rte_cryptodev *cdev,
1055 int32_t queue_pair_id)
1057 CNXK_VALID_DEV_OR_ERR_RET(event_dev->dev, "event_cn9k");
1058 CNXK_VALID_DEV_OR_ERR_RET(cdev->device, "crypto_cn9k");
1060 return cnxk_crypto_adapter_qp_del(cdev, queue_pair_id);
1063 static struct rte_eventdev_ops cn9k_sso_dev_ops = {
1064 .dev_infos_get = cn9k_sso_info_get,
1065 .dev_configure = cn9k_sso_dev_configure,
1066 .queue_def_conf = cnxk_sso_queue_def_conf,
1067 .queue_setup = cnxk_sso_queue_setup,
1068 .queue_release = cnxk_sso_queue_release,
1069 .port_def_conf = cnxk_sso_port_def_conf,
1070 .port_setup = cn9k_sso_port_setup,
1071 .port_release = cn9k_sso_port_release,
1072 .port_link = cn9k_sso_port_link,
1073 .port_unlink = cn9k_sso_port_unlink,
1074 .timeout_ticks = cnxk_sso_timeout_ticks,
1076 .eth_rx_adapter_caps_get = cn9k_sso_rx_adapter_caps_get,
1077 .eth_rx_adapter_queue_add = cn9k_sso_rx_adapter_queue_add,
1078 .eth_rx_adapter_queue_del = cn9k_sso_rx_adapter_queue_del,
1079 .eth_rx_adapter_start = cnxk_sso_rx_adapter_start,
1080 .eth_rx_adapter_stop = cnxk_sso_rx_adapter_stop,
1082 .eth_tx_adapter_caps_get = cn9k_sso_tx_adapter_caps_get,
1083 .eth_tx_adapter_queue_add = cn9k_sso_tx_adapter_queue_add,
1084 .eth_tx_adapter_queue_del = cn9k_sso_tx_adapter_queue_del,
1086 .timer_adapter_caps_get = cnxk_tim_caps_get,
1088 .crypto_adapter_caps_get = cn9k_crypto_adapter_caps_get,
1089 .crypto_adapter_queue_pair_add = cn9k_crypto_adapter_qp_add,
1090 .crypto_adapter_queue_pair_del = cn9k_crypto_adapter_qp_del,
1092 .dump = cnxk_sso_dump,
1093 .dev_start = cn9k_sso_start,
1094 .dev_stop = cn9k_sso_stop,
1095 .dev_close = cn9k_sso_close,
1096 .dev_selftest = cn9k_sso_selftest,
1100 cn9k_sso_init(struct rte_eventdev *event_dev)
1102 struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
1105 if (RTE_CACHE_LINE_SIZE != 128) {
1106 plt_err("Driver not compiled for CN9K");
1110 rc = roc_plt_init();
1112 plt_err("Failed to initialize platform model");
1116 event_dev->dev_ops = &cn9k_sso_dev_ops;
1117 /* For secondary processes, the primary has done all the work */
1118 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1119 cn9k_sso_fp_fns_set(event_dev);
1123 rc = cnxk_sso_init(event_dev);
1127 cn9k_sso_set_rsrc(cnxk_sso_pmd_priv(event_dev));
1128 if (!dev->max_event_ports || !dev->max_event_queues) {
1129 plt_err("Not enough eventdev resource queues=%d ports=%d",
1130 dev->max_event_queues, dev->max_event_ports);
1131 cnxk_sso_fini(event_dev);
1135 plt_sso_dbg("Initializing %s max_queues=%d max_ports=%d",
1136 event_dev->data->name, dev->max_event_queues,
1137 dev->max_event_ports);
1143 cn9k_sso_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
1145 return rte_event_pmd_pci_probe(
1146 pci_drv, pci_dev, sizeof(struct cnxk_sso_evdev), cn9k_sso_init);
1149 static const struct rte_pci_id cn9k_pci_sso_map[] = {
1155 static struct rte_pci_driver cn9k_pci_sso = {
1156 .id_table = cn9k_pci_sso_map,
1157 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA,
1158 .probe = cn9k_sso_probe,
1159 .remove = cnxk_sso_remove,
1162 RTE_PMD_REGISTER_PCI(event_cn9k, cn9k_pci_sso);
1163 RTE_PMD_REGISTER_PCI_TABLE(event_cn9k, cn9k_pci_sso_map);
1164 RTE_PMD_REGISTER_KMOD_DEP(event_cn9k, "vfio-pci");
1165 RTE_PMD_REGISTER_PARAM_STRING(event_cn9k, CNXK_SSO_XAE_CNT "=<int>"
1166 CNXK_SSO_GGRP_QOS "=<string>"
1167 CNXK_SSO_FORCE_BP "=1"
1168 CN9K_SSO_SINGLE_WS "=1"
1169 CNXK_TIM_DISABLE_NPA "=1"
1170 CNXK_TIM_CHNK_SLOTS "=<int>"
1171 CNXK_TIM_RINGS_LMT "=<int>"
1172 CNXK_TIM_STATS_ENA "=1");