1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
5 #ifndef __OTX2_EVDEV_H__
6 #define __OTX2_EVDEV_H__
8 #include <rte_eventdev.h>
9 #include <eventdev_pmd.h>
10 #include <rte_event_eth_rx_adapter.h>
11 #include <rte_event_eth_tx_adapter.h>
13 #include "otx2_common.h"
15 #include "otx2_ethdev.h"
16 #include "otx2_mempool.h"
17 #include "otx2_tim_evdev.h"
19 #define EVENTDEV_NAME_OCTEONTX2_PMD event_octeontx2
21 #define sso_func_trace otx2_sso_dbg
23 #define OTX2_SSO_MAX_VHGRP RTE_EVENT_MAX_QUEUES_PER_DEV
24 #define OTX2_SSO_MAX_VHWS (UINT8_MAX)
25 #define OTX2_SSO_FC_NAME "otx2_evdev_xaq_fc"
26 #define OTX2_SSO_SQB_LIMIT (0x180)
27 #define OTX2_SSO_XAQ_SLACK (8)
28 #define OTX2_SSO_XAQ_CACHE_CNT (0x7)
29 #define OTX2_SSO_WQE_SG_PTR (9)
31 /* SSO LF register offsets (BAR2) */
32 #define SSO_LF_GGRP_OP_ADD_WORK0 (0x0ull)
33 #define SSO_LF_GGRP_OP_ADD_WORK1 (0x8ull)
35 #define SSO_LF_GGRP_QCTL (0x20ull)
36 #define SSO_LF_GGRP_EXE_DIS (0x80ull)
37 #define SSO_LF_GGRP_INT (0x100ull)
38 #define SSO_LF_GGRP_INT_W1S (0x108ull)
39 #define SSO_LF_GGRP_INT_ENA_W1S (0x110ull)
40 #define SSO_LF_GGRP_INT_ENA_W1C (0x118ull)
41 #define SSO_LF_GGRP_INT_THR (0x140ull)
42 #define SSO_LF_GGRP_INT_CNT (0x180ull)
43 #define SSO_LF_GGRP_XAQ_CNT (0x1b0ull)
44 #define SSO_LF_GGRP_AQ_CNT (0x1c0ull)
45 #define SSO_LF_GGRP_AQ_THR (0x1e0ull)
46 #define SSO_LF_GGRP_MISC_CNT (0x200ull)
48 /* SSOW LF register offsets (BAR2) */
49 #define SSOW_LF_GWS_LINKS (0x10ull)
50 #define SSOW_LF_GWS_PENDWQP (0x40ull)
51 #define SSOW_LF_GWS_PENDSTATE (0x50ull)
52 #define SSOW_LF_GWS_NW_TIM (0x70ull)
53 #define SSOW_LF_GWS_GRPMSK_CHG (0x80ull)
54 #define SSOW_LF_GWS_INT (0x100ull)
55 #define SSOW_LF_GWS_INT_W1S (0x108ull)
56 #define SSOW_LF_GWS_INT_ENA_W1S (0x110ull)
57 #define SSOW_LF_GWS_INT_ENA_W1C (0x118ull)
58 #define SSOW_LF_GWS_TAG (0x200ull)
59 #define SSOW_LF_GWS_WQP (0x210ull)
60 #define SSOW_LF_GWS_SWTP (0x220ull)
61 #define SSOW_LF_GWS_PENDTAG (0x230ull)
62 #define SSOW_LF_GWS_OP_ALLOC_WE (0x400ull)
63 #define SSOW_LF_GWS_OP_GET_WORK (0x600ull)
64 #define SSOW_LF_GWS_OP_SWTAG_FLUSH (0x800ull)
65 #define SSOW_LF_GWS_OP_SWTAG_UNTAG (0x810ull)
66 #define SSOW_LF_GWS_OP_SWTP_CLR (0x820ull)
67 #define SSOW_LF_GWS_OP_UPD_WQP_GRP0 (0x830ull)
68 #define SSOW_LF_GWS_OP_UPD_WQP_GRP1 (0x838ull)
69 #define SSOW_LF_GWS_OP_DESCHED (0x880ull)
70 #define SSOW_LF_GWS_OP_DESCHED_NOSCH (0x8c0ull)
71 #define SSOW_LF_GWS_OP_SWTAG_DESCHED (0x980ull)
72 #define SSOW_LF_GWS_OP_SWTAG_NOSCHED (0x9c0ull)
73 #define SSOW_LF_GWS_OP_CLR_NSCHED0 (0xa00ull)
74 #define SSOW_LF_GWS_OP_CLR_NSCHED1 (0xa08ull)
75 #define SSOW_LF_GWS_OP_SWTP_SET (0xc00ull)
76 #define SSOW_LF_GWS_OP_SWTAG_NORM (0xc10ull)
77 #define SSOW_LF_GWS_OP_SWTAG_FULL0 (0xc20ull)
78 #define SSOW_LF_GWS_OP_SWTAG_FULL1 (0xc28ull)
79 #define SSOW_LF_GWS_OP_GWC_INVAL (0xe00ull)
81 #define OTX2_SSOW_GET_BASE_ADDR(_GW) ((_GW) - SSOW_LF_GWS_OP_GET_WORK)
82 #define OTX2_SSOW_TT_FROM_TAG(x) (((x) >> 32) & SSO_TT_EMPTY)
83 #define OTX2_SSOW_GRP_FROM_TAG(x) (((x) >> 36) & 0x3ff)
85 #define NSEC2USEC(__ns) ((__ns) / 1E3)
86 #define USEC2NSEC(__us) ((__us) * 1E3)
87 #define NSEC2TICK(__ns, __freq) (((__ns) * (__freq)) / 1E9)
88 #define TICK2NSEC(__tck, __freq) (((__tck) * 1E9) / (__freq))
90 enum otx2_sso_lf_type {
95 union otx2_sso_event {
99 uint32_t sub_event_type:8;
100 uint32_t event_type:4;
103 uint8_t sched_type:2;
117 struct otx2_sso_qos {
124 struct otx2_sso_evdev {
125 OTX2_DEV; /* Base class */
126 uint8_t max_event_queues;
127 uint8_t max_event_ports;
128 uint8_t is_timeout_deq;
129 uint8_t nb_event_queues;
130 uint8_t nb_event_ports;
133 uint32_t min_dequeue_timeout_ns;
134 uint32_t max_dequeue_timeout_ns;
135 int32_t max_num_events;
140 struct rte_mempool *xaq_pool;
141 uint64_t rx_offloads;
142 uint64_t tx_offloads;
143 uint64_t adptr_xae_cnt;
144 uint16_t rx_adptr_pool_cnt;
145 uint64_t *rx_adptr_pools;
146 uint16_t max_port_id;
147 uint16_t tim_adptr_ring_cnt;
148 uint16_t *timer_adptr_rings;
149 uint64_t *timer_adptr_sz;
153 uint8_t qos_queue_cnt;
154 struct otx2_sso_qos *qos_parse_data;
157 uint32_t xaq_buf_size;
160 uint16_t sso_msixoff[OTX2_SSO_MAX_VHGRP];
161 uint16_t ssow_msixoff[OTX2_SSO_MAX_VHWS];
163 struct otx2_timesync_info *tstamp;
164 } __rte_cache_aligned;
166 #define OTX2_SSOGWS_OPS \
168 uintptr_t getwrk_op; \
171 uintptr_t swtag_flush_op; \
172 uintptr_t swtag_norm_op; \
173 uintptr_t swtag_desched_op;
175 /* Event port aka GWS */
177 /* Get Work Fastpath data */
180 struct otx2_timesync_info *tstamp;
184 /* Add Work Fastpath data */
185 uint64_t xaq_lmt __rte_cache_aligned;
187 uintptr_t grps_base[OTX2_SSO_MAX_VHGRP];
188 /* Tx Fastpath data */
189 uint64_t base __rte_cache_aligned;
190 uint8_t tx_adptr_data[];
191 } __rte_cache_aligned;
193 struct otx2_ssogws_state {
197 struct otx2_ssogws_dual {
198 /* Get Work Fastpath data */
199 struct otx2_ssogws_state ws_state[2]; /* Ping and Pong */
201 struct otx2_timesync_info *tstamp;
204 uint8_t vws; /* Ping pong bit */
206 /* Add Work Fastpath data */
207 uint64_t xaq_lmt __rte_cache_aligned;
209 uintptr_t grps_base[OTX2_SSO_MAX_VHGRP];
210 /* Tx Fastpath data */
211 uint64_t base[2] __rte_cache_aligned;
212 uint8_t tx_adptr_data[];
213 } __rte_cache_aligned;
215 static inline struct otx2_sso_evdev *
216 sso_pmd_priv(const struct rte_eventdev *event_dev)
218 return event_dev->data->dev_private;
221 struct otx2_ssogws_cookie {
222 const struct rte_eventdev *event_dev;
226 static inline struct otx2_ssogws_cookie *
227 ssogws_get_cookie(void *ws)
229 return (struct otx2_ssogws_cookie *)
230 ((uint8_t *)ws - RTE_CACHE_LINE_SIZE);
233 static const union mbuf_initializer mbuf_init = {
235 .data_off = RTE_PKTMBUF_HEADROOM,
242 static __rte_always_inline void
243 otx2_wqe_to_mbuf(uint64_t get_work1, const uint64_t mbuf, uint8_t port_id,
244 const uint32_t tag, const uint32_t flags,
245 const void * const lookup_mem)
247 struct nix_wqe_hdr_s *wqe = (struct nix_wqe_hdr_s *)get_work1;
248 uint64_t val = mbuf_init.value | (uint64_t)port_id << 48;
250 if (flags & NIX_RX_OFFLOAD_TSTAMP_F)
251 val |= NIX_TIMESYNC_RX_OFFSET;
253 otx2_nix_cqe_to_mbuf((struct nix_cqe_hdr_s *)wqe, tag,
254 (struct rte_mbuf *)mbuf, lookup_mem,
260 parse_kvargs_flag(const char *key, const char *value, void *opaque)
264 *(uint8_t *)opaque = !!atoi(value);
269 parse_kvargs_value(const char *key, const char *value, void *opaque)
273 *(uint32_t *)opaque = (uint32_t)atoi(value);
277 #define SSO_RX_ADPTR_ENQ_FASTPATH_FUNC NIX_RX_FASTPATH_MODES
278 #define SSO_TX_ADPTR_ENQ_FASTPATH_FUNC NIX_TX_FASTPATH_MODES
280 /* Single WS API's */
281 uint16_t otx2_ssogws_enq(void *port, const struct rte_event *ev);
282 uint16_t otx2_ssogws_enq_burst(void *port, const struct rte_event ev[],
284 uint16_t otx2_ssogws_enq_new_burst(void *port, const struct rte_event ev[],
286 uint16_t otx2_ssogws_enq_fwd_burst(void *port, const struct rte_event ev[],
290 uint16_t otx2_ssogws_dual_enq(void *port, const struct rte_event *ev);
291 uint16_t otx2_ssogws_dual_enq_burst(void *port, const struct rte_event ev[],
293 uint16_t otx2_ssogws_dual_enq_new_burst(void *port, const struct rte_event ev[],
295 uint16_t otx2_ssogws_dual_enq_fwd_burst(void *port, const struct rte_event ev[],
298 /* Auto generated API's */
299 #define R(name, f6, f5, f4, f3, f2, f1, f0, flags) \
300 uint16_t otx2_ssogws_deq_ ##name(void *port, struct rte_event *ev, \
301 uint64_t timeout_ticks); \
302 uint16_t otx2_ssogws_deq_burst_ ##name(void *port, struct rte_event ev[], \
303 uint16_t nb_events, \
304 uint64_t timeout_ticks); \
305 uint16_t otx2_ssogws_deq_timeout_ ##name(void *port, \
306 struct rte_event *ev, \
307 uint64_t timeout_ticks); \
308 uint16_t otx2_ssogws_deq_timeout_burst_ ##name(void *port, \
309 struct rte_event ev[], \
310 uint16_t nb_events, \
311 uint64_t timeout_ticks); \
312 uint16_t otx2_ssogws_deq_seg_ ##name(void *port, struct rte_event *ev, \
313 uint64_t timeout_ticks); \
314 uint16_t otx2_ssogws_deq_seg_burst_ ##name(void *port, \
315 struct rte_event ev[], \
316 uint16_t nb_events, \
317 uint64_t timeout_ticks); \
318 uint16_t otx2_ssogws_deq_seg_timeout_ ##name(void *port, \
319 struct rte_event *ev, \
320 uint64_t timeout_ticks); \
321 uint16_t otx2_ssogws_deq_seg_timeout_burst_ ##name(void *port, \
322 struct rte_event ev[], \
323 uint16_t nb_events, \
324 uint64_t timeout_ticks); \
326 uint16_t otx2_ssogws_dual_deq_ ##name(void *port, struct rte_event *ev, \
327 uint64_t timeout_ticks); \
328 uint16_t otx2_ssogws_dual_deq_burst_ ##name(void *port, \
329 struct rte_event ev[], \
330 uint16_t nb_events, \
331 uint64_t timeout_ticks); \
332 uint16_t otx2_ssogws_dual_deq_timeout_ ##name(void *port, \
333 struct rte_event *ev, \
334 uint64_t timeout_ticks); \
335 uint16_t otx2_ssogws_dual_deq_timeout_burst_ ##name(void *port, \
336 struct rte_event ev[], \
337 uint16_t nb_events, \
338 uint64_t timeout_ticks); \
339 uint16_t otx2_ssogws_dual_deq_seg_ ##name(void *port, struct rte_event *ev, \
340 uint64_t timeout_ticks); \
341 uint16_t otx2_ssogws_dual_deq_seg_burst_ ##name(void *port, \
342 struct rte_event ev[], \
343 uint16_t nb_events, \
344 uint64_t timeout_ticks); \
345 uint16_t otx2_ssogws_dual_deq_seg_timeout_ ##name(void *port, \
346 struct rte_event *ev, \
347 uint64_t timeout_ticks); \
348 uint16_t otx2_ssogws_dual_deq_seg_timeout_burst_ ##name(void *port, \
349 struct rte_event ev[], \
350 uint16_t nb_events, \
351 uint64_t timeout_ticks);\
353 SSO_RX_ADPTR_ENQ_FASTPATH_FUNC
356 #define T(name, f6, f5, f4, f3, f2, f1, f0, sz, flags) \
357 uint16_t otx2_ssogws_tx_adptr_enq_ ## name(void *port, struct rte_event ev[],\
358 uint16_t nb_events); \
359 uint16_t otx2_ssogws_tx_adptr_enq_seg_ ## name(void *port, \
360 struct rte_event ev[], \
361 uint16_t nb_events); \
362 uint16_t otx2_ssogws_dual_tx_adptr_enq_ ## name(void *port, \
363 struct rte_event ev[], \
364 uint16_t nb_events); \
365 uint16_t otx2_ssogws_dual_tx_adptr_enq_seg_ ## name(void *port, \
366 struct rte_event ev[], \
367 uint16_t nb_events); \
369 SSO_TX_ADPTR_ENQ_FASTPATH_FUNC
372 void sso_updt_xae_cnt(struct otx2_sso_evdev *dev, void *data,
373 uint32_t event_type);
374 int sso_xae_reconfigure(struct rte_eventdev *event_dev);
375 void sso_fastpath_fns_set(struct rte_eventdev *event_dev);
377 int otx2_sso_rx_adapter_caps_get(const struct rte_eventdev *event_dev,
378 const struct rte_eth_dev *eth_dev,
380 int otx2_sso_rx_adapter_queue_add(const struct rte_eventdev *event_dev,
381 const struct rte_eth_dev *eth_dev,
383 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf);
384 int otx2_sso_rx_adapter_queue_del(const struct rte_eventdev *event_dev,
385 const struct rte_eth_dev *eth_dev,
386 int32_t rx_queue_id);
387 int otx2_sso_rx_adapter_start(const struct rte_eventdev *event_dev,
388 const struct rte_eth_dev *eth_dev);
389 int otx2_sso_rx_adapter_stop(const struct rte_eventdev *event_dev,
390 const struct rte_eth_dev *eth_dev);
391 int otx2_sso_tx_adapter_caps_get(const struct rte_eventdev *dev,
392 const struct rte_eth_dev *eth_dev,
394 int otx2_sso_tx_adapter_queue_add(uint8_t id,
395 const struct rte_eventdev *event_dev,
396 const struct rte_eth_dev *eth_dev,
397 int32_t tx_queue_id);
399 int otx2_sso_tx_adapter_queue_del(uint8_t id,
400 const struct rte_eventdev *event_dev,
401 const struct rte_eth_dev *eth_dev,
402 int32_t tx_queue_id);
404 /* Event crypto adapter API's */
405 int otx2_ca_caps_get(const struct rte_eventdev *dev,
406 const struct rte_cryptodev *cdev, uint32_t *caps);
408 int otx2_ca_qp_add(const struct rte_eventdev *dev,
409 const struct rte_cryptodev *cdev, int32_t queue_pair_id,
410 const struct rte_event *event);
412 int otx2_ca_qp_del(const struct rte_eventdev *dev,
413 const struct rte_cryptodev *cdev, int32_t queue_pair_id);
416 typedef void (*otx2_handle_event_t)(void *arg, struct rte_event ev);
417 void ssogws_flush_events(struct otx2_ssogws *ws, uint8_t queue_id,
418 uintptr_t base, otx2_handle_event_t fn, void *arg);
419 void ssogws_reset(struct otx2_ssogws *ws);
421 int otx2_sso_selftest(void);
422 /* Init and Fini API's */
423 int otx2_sso_init(struct rte_eventdev *event_dev);
424 int otx2_sso_fini(struct rte_eventdev *event_dev);
426 int sso_register_irqs(const struct rte_eventdev *event_dev);
427 void sso_unregister_irqs(const struct rte_eventdev *event_dev);
429 #endif /* __OTX2_EVDEV_H__ */