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)
50 #define CNXK_TAG_IS_HEAD(x) (BIT_ULL(35) & x)
52 #define CN9K_SSOW_GET_BASE_ADDR(_GW) ((_GW)-SSOW_LF_GWS_OP_GET_WORK0)
54 #define CN10K_GW_MODE_NONE 0
55 #define CN10K_GW_MODE_PREF 1
56 #define CN10K_GW_MODE_PREF_WFE 2
58 #define CNXK_VALID_DEV_OR_ERR_RET(dev, drv_name) \
60 if (strncmp(dev->driver->name, drv_name, strlen(drv_name))) \
64 typedef void *(*cnxk_sso_init_hws_mem_t)(void *dev, uint8_t port_id);
65 typedef void (*cnxk_sso_hws_setup_t)(void *dev, void *ws, uintptr_t grp_base);
66 typedef void (*cnxk_sso_hws_release_t)(void *dev, void *ws);
67 typedef int (*cnxk_sso_link_t)(void *dev, void *ws, uint16_t *map,
69 typedef int (*cnxk_sso_unlink_t)(void *dev, void *ws, uint16_t *map,
71 typedef void (*cnxk_handle_event_t)(void *arg, struct rte_event ev);
72 typedef void (*cnxk_sso_hws_reset_t)(void *arg, void *ws);
73 typedef void (*cnxk_sso_hws_flush_t)(void *ws, uint8_t queue_id, uintptr_t base,
74 cnxk_handle_event_t fn, void *arg);
83 struct cnxk_sso_evdev {
85 uint8_t max_event_queues;
86 uint8_t max_event_ports;
87 uint8_t is_timeout_deq;
88 uint8_t nb_event_queues;
89 uint8_t nb_event_ports;
92 uint32_t min_dequeue_timeout_ns;
93 uint32_t max_dequeue_timeout_ns;
94 int32_t max_num_events;
99 uint64_t adptr_xae_cnt;
100 uint16_t rx_adptr_pool_cnt;
101 uint64_t *rx_adptr_pools;
102 uint64_t *tx_adptr_data;
103 size_t tx_adptr_data_sz;
104 uint16_t max_port_id;
105 uint16_t max_queue_id[RTE_MAX_ETHPORTS];
106 uint8_t tx_adptr_configured;
107 uint16_t tim_adptr_ring_cnt;
108 uint16_t *timer_adptr_rings;
109 uint64_t *timer_adptr_sz;
110 uint16_t vec_pool_cnt;
114 uint8_t qos_queue_cnt;
115 struct cnxk_sso_qos *qos_parse_data;
116 uint8_t force_ena_bp;
122 uint8_t is_ca_internal_port;
123 } __rte_cache_aligned;
125 struct cn10k_sso_hws {
129 struct cnxk_timesync_info *tstamp;
134 /* Add Work Fastpath data */
135 uint64_t xaq_lmt __rte_cache_aligned;
138 /* Tx Fastpath data */
139 uintptr_t lmt_base __rte_cache_aligned;
140 uint64_t lso_tun_fmt;
141 uint8_t tx_adptr_data[];
142 } __rte_cache_aligned;
144 /* Event port a.k.a GWS */
145 struct cn9k_sso_hws {
149 struct cnxk_timesync_info *tstamp;
153 /* Add Work Fastpath data */
154 uint64_t xaq_lmt __rte_cache_aligned;
157 /* Tx Fastpath data */
158 uint64_t lso_tun_fmt __rte_cache_aligned;
159 uint8_t tx_adptr_data[];
160 } __rte_cache_aligned;
162 struct cn9k_sso_hws_dual {
163 uint64_t base[2]; /* Ping and Pong */
166 struct cnxk_timesync_info *tstamp;
169 uint8_t vws; /* Ping pong bit */
171 /* Add Work Fastpath data */
172 uint64_t xaq_lmt __rte_cache_aligned;
175 /* Tx Fastpath data */
176 uint64_t lso_tun_fmt __rte_cache_aligned;
177 uint8_t tx_adptr_data[];
178 } __rte_cache_aligned;
180 struct cnxk_sso_hws_cookie {
181 const struct rte_eventdev *event_dev;
183 } __rte_cache_aligned;
186 parse_kvargs_flag(const char *key, const char *value, void *opaque)
190 *(uint8_t *)opaque = !!atoi(value);
195 parse_kvargs_value(const char *key, const char *value, void *opaque)
199 *(uint32_t *)opaque = (uint32_t)atoi(value);
203 static inline struct cnxk_sso_evdev *
204 cnxk_sso_pmd_priv(const struct rte_eventdev *event_dev)
206 return event_dev->data->dev_private;
209 static inline struct cnxk_sso_hws_cookie *
210 cnxk_sso_hws_get_cookie(void *ws)
212 return RTE_PTR_SUB(ws, sizeof(struct cnxk_sso_hws_cookie));
215 /* Configuration functions */
216 int cnxk_sso_xae_reconfigure(struct rte_eventdev *event_dev);
217 int cnxk_sso_xaq_allocate(struct cnxk_sso_evdev *dev);
218 void cnxk_sso_updt_xae_cnt(struct cnxk_sso_evdev *dev, void *data,
219 uint32_t event_type);
221 /* Common ops API. */
222 int cnxk_sso_init(struct rte_eventdev *event_dev);
223 int cnxk_sso_fini(struct rte_eventdev *event_dev);
224 int cnxk_sso_remove(struct rte_pci_device *pci_dev);
225 void cnxk_sso_info_get(struct cnxk_sso_evdev *dev,
226 struct rte_event_dev_info *dev_info);
227 int cnxk_sso_dev_validate(const struct rte_eventdev *event_dev);
228 int cnxk_setup_event_ports(const struct rte_eventdev *event_dev,
229 cnxk_sso_init_hws_mem_t init_hws_mem,
230 cnxk_sso_hws_setup_t hws_setup);
231 void cnxk_sso_restore_links(const struct rte_eventdev *event_dev,
232 cnxk_sso_link_t link_fn);
233 void cnxk_sso_queue_def_conf(struct rte_eventdev *event_dev, uint8_t queue_id,
234 struct rte_event_queue_conf *queue_conf);
235 int cnxk_sso_queue_setup(struct rte_eventdev *event_dev, uint8_t queue_id,
236 const struct rte_event_queue_conf *queue_conf);
237 void cnxk_sso_queue_release(struct rte_eventdev *event_dev, uint8_t queue_id);
238 void cnxk_sso_port_def_conf(struct rte_eventdev *event_dev, uint8_t port_id,
239 struct rte_event_port_conf *port_conf);
240 int cnxk_sso_port_setup(struct rte_eventdev *event_dev, uint8_t port_id,
241 cnxk_sso_hws_setup_t hws_setup_fn);
242 int cnxk_sso_timeout_ticks(struct rte_eventdev *event_dev, uint64_t ns,
243 uint64_t *tmo_ticks);
244 int cnxk_sso_start(struct rte_eventdev *event_dev,
245 cnxk_sso_hws_reset_t reset_fn,
246 cnxk_sso_hws_flush_t flush_fn);
247 void cnxk_sso_stop(struct rte_eventdev *event_dev,
248 cnxk_sso_hws_reset_t reset_fn,
249 cnxk_sso_hws_flush_t flush_fn);
250 int cnxk_sso_close(struct rte_eventdev *event_dev, cnxk_sso_unlink_t unlink_fn);
251 int cnxk_sso_selftest(const char *dev_name);
252 void cnxk_sso_dump(struct rte_eventdev *event_dev, FILE *f);
255 int cnxk_sso_xstats_get_names(const struct rte_eventdev *event_dev,
256 enum rte_event_dev_xstats_mode mode,
257 uint8_t queue_port_id,
258 struct rte_event_dev_xstats_name *xstats_names,
259 unsigned int *ids, unsigned int size);
260 int cnxk_sso_xstats_get(const struct rte_eventdev *event_dev,
261 enum rte_event_dev_xstats_mode mode,
262 uint8_t queue_port_id, const unsigned int ids[],
263 uint64_t values[], unsigned int n);
264 int cnxk_sso_xstats_reset(struct rte_eventdev *event_dev,
265 enum rte_event_dev_xstats_mode mode,
266 int16_t queue_port_id, const uint32_t ids[],
269 /* Crypto adapter APIs. */
270 int cnxk_crypto_adapter_qp_add(const struct rte_eventdev *event_dev,
271 const struct rte_cryptodev *cdev,
272 int32_t queue_pair_id);
273 int cnxk_crypto_adapter_qp_del(const struct rte_cryptodev *cdev,
274 int32_t queue_pair_id);
277 void cn9k_sso_set_rsrc(void *arg);
279 /* Common adapter ops */
280 int cnxk_sso_rx_adapter_queue_add(
281 const struct rte_eventdev *event_dev, const struct rte_eth_dev *eth_dev,
283 const struct rte_event_eth_rx_adapter_queue_conf *queue_conf);
284 int cnxk_sso_rx_adapter_queue_del(const struct rte_eventdev *event_dev,
285 const struct rte_eth_dev *eth_dev,
286 int32_t rx_queue_id);
287 int cnxk_sso_rx_adapter_start(const struct rte_eventdev *event_dev,
288 const struct rte_eth_dev *eth_dev);
289 int cnxk_sso_rx_adapter_stop(const struct rte_eventdev *event_dev,
290 const struct rte_eth_dev *eth_dev);
291 int cnxk_sso_tx_adapter_queue_add(const struct rte_eventdev *event_dev,
292 const struct rte_eth_dev *eth_dev,
293 int32_t tx_queue_id);
294 int cnxk_sso_tx_adapter_queue_del(const struct rte_eventdev *event_dev,
295 const struct rte_eth_dev *eth_dev,
296 int32_t tx_queue_id);
298 #endif /* __CNXK_EVENTDEV_H__ */