1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
5 #ifndef __CNXK_EVENTDEV_H__
6 #define __CNXK_EVENTDEV_H__
10 #include <cryptodev_pmd.h>
11 #include <rte_devargs.h>
12 #include <rte_ethdev.h>
13 #include <rte_event_eth_rx_adapter.h>
14 #include <rte_event_eth_tx_adapter.h>
15 #include <rte_kvargs.h>
16 #include <rte_mbuf_pool_ops.h>
19 #include <eventdev_pmd_pci.h>
23 #include "cnxk_tim_evdev.h"
25 #define CNXK_SSO_XAE_CNT "xae_cnt"
26 #define CNXK_SSO_GGRP_QOS "qos"
27 #define CNXK_SSO_FORCE_BP "force_rx_bp"
28 #define CN9K_SSO_SINGLE_WS "single_ws"
29 #define CN10K_SSO_GW_MODE "gw_mode"
31 #define NSEC2USEC(__ns) ((__ns) / 1E3)
32 #define USEC2NSEC(__us) ((__us)*1E3)
33 #define NSEC2TICK(__ns, __freq) (((__ns) * (__freq)) / 1E9)
35 #define CNXK_SSO_MAX_HWGRP (RTE_EVENT_MAX_QUEUES_PER_DEV + 1)
36 #define CNXK_SSO_FC_NAME "cnxk_evdev_xaq_fc"
37 #define CNXK_SSO_MZ_NAME "cnxk_evdev_mz"
38 #define CNXK_SSO_XAQ_CACHE_CNT (0x7)
39 #define CNXK_SSO_XAQ_SLACK (8)
40 #define CNXK_SSO_WQE_SG_PTR (9)
41 #define CNXK_SSO_SQB_LIMIT (0x180)
43 #define CNXK_TT_FROM_TAG(x) (((x) >> 32) & SSO_TT_EMPTY)
44 #define CNXK_TT_FROM_EVENT(x) (((x) >> 38) & SSO_TT_EMPTY)
45 #define CNXK_EVENT_TYPE_FROM_TAG(x) (((x) >> 28) & 0xf)
46 #define CNXK_SUB_EVENT_FROM_TAG(x) (((x) >> 20) & 0xff)
47 #define CNXK_CLR_SUB_EVENT(x) (~(0xffu << 20) & x)
48 #define CNXK_GRP_FROM_TAG(x) (((x) >> 36) & 0x3ff)
49 #define CNXK_SWTAG_PEND(x) (BIT_ULL(62) & x)
51 #define CN9K_SSOW_GET_BASE_ADDR(_GW) ((_GW)-SSOW_LF_GWS_OP_GET_WORK0)
53 #define CN10K_GW_MODE_NONE 0
54 #define CN10K_GW_MODE_PREF 1
55 #define CN10K_GW_MODE_PREF_WFE 2
57 #define CNXK_VALID_DEV_OR_ERR_RET(dev, drv_name) \
59 if (strncmp(dev->driver->name, drv_name, strlen(drv_name))) \
63 typedef void *(*cnxk_sso_init_hws_mem_t)(void *dev, uint8_t port_id);
64 typedef void (*cnxk_sso_hws_setup_t)(void *dev, void *ws, uintptr_t grp_base);
65 typedef void (*cnxk_sso_hws_release_t)(void *dev, void *ws);
66 typedef int (*cnxk_sso_link_t)(void *dev, void *ws, uint16_t *map,
68 typedef int (*cnxk_sso_unlink_t)(void *dev, void *ws, uint16_t *map,
70 typedef void (*cnxk_handle_event_t)(void *arg, struct rte_event ev);
71 typedef void (*cnxk_sso_hws_reset_t)(void *arg, void *ws);
72 typedef void (*cnxk_sso_hws_flush_t)(void *ws, uint8_t queue_id, uintptr_t base,
73 cnxk_handle_event_t fn, void *arg);
82 struct cnxk_sso_evdev {
84 uint8_t max_event_queues;
85 uint8_t max_event_ports;
86 uint8_t is_timeout_deq;
87 uint8_t nb_event_queues;
88 uint8_t nb_event_ports;
91 uint32_t min_dequeue_timeout_ns;
92 uint32_t max_dequeue_timeout_ns;
93 int32_t max_num_events;
98 uint64_t adptr_xae_cnt;
99 uint16_t rx_adptr_pool_cnt;
100 uint64_t *rx_adptr_pools;
101 uint64_t *tx_adptr_data;
102 size_t tx_adptr_data_sz;
103 uint16_t max_port_id;
104 uint16_t max_queue_id[RTE_MAX_ETHPORTS];
105 uint8_t tx_adptr_configured;
106 uint16_t tim_adptr_ring_cnt;
107 uint16_t *timer_adptr_rings;
108 uint64_t *timer_adptr_sz;
109 uint16_t vec_pool_cnt;
113 uint8_t qos_queue_cnt;
114 struct cnxk_sso_qos *qos_parse_data;
115 uint8_t force_ena_bp;
121 uint8_t is_ca_internal_port;
122 } __rte_cache_aligned;
124 struct cn10k_sso_hws {
127 struct cnxk_timesync_info *tstamp;
132 /* Add Work Fastpath data */
133 uint64_t xaq_lmt __rte_cache_aligned;
136 /* Tx Fastpath data */
137 uintptr_t lmt_base __rte_cache_aligned;
138 uint64_t lso_tun_fmt;
139 uint8_t tx_adptr_data[];
140 } __rte_cache_aligned;
142 /* Event port a.k.a GWS */
143 struct cn9k_sso_hws {
146 struct cnxk_timesync_info *tstamp;
150 /* Add Work Fastpath data */
151 uint64_t xaq_lmt __rte_cache_aligned;
154 /* Tx Fastpath data */
155 uint64_t lso_tun_fmt __rte_cache_aligned;
156 uint8_t tx_adptr_data[];
157 } __rte_cache_aligned;
159 struct cn9k_sso_hws_dual {
160 uint64_t base[2]; /* Ping and Pong */
162 struct cnxk_timesync_info *tstamp;
165 uint8_t vws; /* Ping pong bit */
167 /* Add Work Fastpath data */
168 uint64_t xaq_lmt __rte_cache_aligned;
171 /* Tx Fastpath data */
172 uint64_t lso_tun_fmt __rte_cache_aligned;
173 uint8_t tx_adptr_data[];
174 } __rte_cache_aligned;
176 struct cnxk_sso_hws_cookie {
177 const struct rte_eventdev *event_dev;
179 } __rte_cache_aligned;
182 parse_kvargs_flag(const char *key, const char *value, void *opaque)
186 *(uint8_t *)opaque = !!atoi(value);
191 parse_kvargs_value(const char *key, const char *value, void *opaque)
195 *(uint32_t *)opaque = (uint32_t)atoi(value);
199 static inline struct cnxk_sso_evdev *
200 cnxk_sso_pmd_priv(const struct rte_eventdev *event_dev)
202 return event_dev->data->dev_private;
205 static inline struct cnxk_sso_hws_cookie *
206 cnxk_sso_hws_get_cookie(void *ws)
208 return RTE_PTR_SUB(ws, sizeof(struct cnxk_sso_hws_cookie));
211 /* Configuration functions */
212 int cnxk_sso_xae_reconfigure(struct rte_eventdev *event_dev);
213 int cnxk_sso_xaq_allocate(struct cnxk_sso_evdev *dev);
214 void cnxk_sso_updt_xae_cnt(struct cnxk_sso_evdev *dev, void *data,
215 uint32_t event_type);
217 /* Common ops API. */
218 int cnxk_sso_init(struct rte_eventdev *event_dev);
219 int cnxk_sso_fini(struct rte_eventdev *event_dev);
220 int cnxk_sso_remove(struct rte_pci_device *pci_dev);
221 void cnxk_sso_info_get(struct cnxk_sso_evdev *dev,
222 struct rte_event_dev_info *dev_info);
223 int cnxk_sso_dev_validate(const struct rte_eventdev *event_dev);
224 int cnxk_setup_event_ports(const struct rte_eventdev *event_dev,
225 cnxk_sso_init_hws_mem_t init_hws_mem,
226 cnxk_sso_hws_setup_t hws_setup);
227 void cnxk_sso_restore_links(const struct rte_eventdev *event_dev,
228 cnxk_sso_link_t link_fn);
229 void cnxk_sso_queue_def_conf(struct rte_eventdev *event_dev, uint8_t queue_id,
230 struct rte_event_queue_conf *queue_conf);
231 int cnxk_sso_queue_setup(struct rte_eventdev *event_dev, uint8_t queue_id,
232 const struct rte_event_queue_conf *queue_conf);
233 void cnxk_sso_queue_release(struct rte_eventdev *event_dev, uint8_t queue_id);
234 void cnxk_sso_port_def_conf(struct rte_eventdev *event_dev, uint8_t port_id,
235 struct rte_event_port_conf *port_conf);
236 int cnxk_sso_port_setup(struct rte_eventdev *event_dev, uint8_t port_id,
237 cnxk_sso_hws_setup_t hws_setup_fn);
238 int cnxk_sso_timeout_ticks(struct rte_eventdev *event_dev, uint64_t ns,
239 uint64_t *tmo_ticks);
240 int cnxk_sso_start(struct rte_eventdev *event_dev,
241 cnxk_sso_hws_reset_t reset_fn,
242 cnxk_sso_hws_flush_t flush_fn);
243 void cnxk_sso_stop(struct rte_eventdev *event_dev,
244 cnxk_sso_hws_reset_t reset_fn,
245 cnxk_sso_hws_flush_t flush_fn);
246 int cnxk_sso_close(struct rte_eventdev *event_dev, cnxk_sso_unlink_t unlink_fn);
247 int cnxk_sso_selftest(const char *dev_name);
248 void cnxk_sso_dump(struct rte_eventdev *event_dev, FILE *f);
251 int cnxk_sso_xstats_get_names(const struct rte_eventdev *event_dev,
252 enum rte_event_dev_xstats_mode mode,
253 uint8_t queue_port_id,
254 struct rte_event_dev_xstats_name *xstats_names,
255 unsigned int *ids, unsigned int size);
256 int cnxk_sso_xstats_get(const struct rte_eventdev *event_dev,
257 enum rte_event_dev_xstats_mode mode,
258 uint8_t queue_port_id, const unsigned int ids[],
259 uint64_t values[], unsigned int n);
260 int cnxk_sso_xstats_reset(struct rte_eventdev *event_dev,
261 enum rte_event_dev_xstats_mode mode,
262 int16_t queue_port_id, const uint32_t ids[],
265 /* Crypto adapter APIs. */
266 int cnxk_crypto_adapter_qp_add(const struct rte_eventdev *event_dev,
267 const struct rte_cryptodev *cdev,
268 int32_t queue_pair_id);
269 int cnxk_crypto_adapter_qp_del(const struct rte_cryptodev *cdev,
270 int32_t queue_pair_id);
273 void cn9k_sso_set_rsrc(void *arg);
275 /* Common adapter ops */
276 int cnxk_sso_rx_adapter_queue_add(
277 const struct rte_eventdev *event_dev, const struct rte_eth_dev *eth_dev,
279 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf);
280 int cnxk_sso_rx_adapter_queue_del(const struct rte_eventdev *event_dev,
281 const struct rte_eth_dev *eth_dev,
282 int32_t rx_queue_id);
283 int cnxk_sso_rx_adapter_start(const struct rte_eventdev *event_dev,
284 const struct rte_eth_dev *eth_dev);
285 int cnxk_sso_rx_adapter_stop(const struct rte_eventdev *event_dev,
286 const struct rte_eth_dev *eth_dev);
287 int cnxk_sso_tx_adapter_queue_add(const struct rte_eventdev *event_dev,
288 const struct rte_eth_dev *eth_dev,
289 int32_t tx_queue_id);
290 int cnxk_sso_tx_adapter_queue_del(const struct rte_eventdev *event_dev,
291 const struct rte_eth_dev *eth_dev,
292 int32_t tx_queue_id);
294 #endif /* __CNXK_EVENTDEV_H__ */