xref: /dpdk/drivers/event/octeontx/ssovf_evdev.c (revision 60531a2c53f4d2b4b96ebb10ca813f62d0a5508d)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Cavium, Inc
3  */
4 
5 #include <inttypes.h>
6 #include <stdlib.h>
7 
8 #include <rte_common.h>
9 #include <cryptodev_pmd.h>
10 #include <rte_debug.h>
11 #include <dev_driver.h>
12 #include <rte_eal.h>
13 #include <ethdev_driver.h>
14 #include <rte_event_eth_rx_adapter.h>
15 #include <rte_kvargs.h>
16 #include <rte_lcore.h>
17 #include <rte_log.h>
18 #include <rte_malloc.h>
19 #include <rte_memory.h>
20 #include <bus_vdev_driver.h>
21 
22 #include "ssovf_evdev.h"
23 #include "timvf_evdev.h"
24 #include "otx_cryptodev_hw_access.h"
25 
26 static uint8_t timvf_enable_stats;
27 
28 RTE_LOG_REGISTER_DEFAULT(otx_logtype_ssovf, NOTICE);
29 
30 /* SSOPF Mailbox messages */
31 
32 struct ssovf_mbox_dev_info {
33 	uint64_t min_deq_timeout_ns;
34 	uint64_t max_deq_timeout_ns;
35 	uint32_t max_num_events;
36 };
37 
38 static int
39 ssovf_mbox_dev_info(struct ssovf_mbox_dev_info *info)
40 {
41 	struct octeontx_mbox_hdr hdr = {0};
42 	uint16_t len = sizeof(struct ssovf_mbox_dev_info);
43 
44 	hdr.coproc = SSO_COPROC;
45 	hdr.msg = SSO_GET_DEV_INFO;
46 	hdr.vfid = 0;
47 
48 	memset(info, 0, len);
49 	return octeontx_mbox_send(&hdr, NULL, 0, info, len);
50 }
51 
52 struct ssovf_mbox_getwork_wait {
53 	uint64_t wait_ns;
54 };
55 
56 static int
57 ssovf_mbox_getwork_tmo_set(uint32_t timeout_ns)
58 {
59 	struct octeontx_mbox_hdr hdr = {0};
60 	struct ssovf_mbox_getwork_wait tmo_set;
61 	uint16_t len = sizeof(struct ssovf_mbox_getwork_wait);
62 	int ret;
63 
64 	hdr.coproc = SSO_COPROC;
65 	hdr.msg = SSO_SET_GETWORK_WAIT;
66 	hdr.vfid = 0;
67 
68 	tmo_set.wait_ns = timeout_ns;
69 	ret = octeontx_mbox_send(&hdr, &tmo_set, len, NULL, 0);
70 	if (ret)
71 		ssovf_log_err("Failed to set getwork timeout(%d)", ret);
72 
73 	return ret;
74 }
75 
76 struct ssovf_mbox_grp_pri {
77 	uint8_t vhgrp_id;
78 	uint8_t wgt_left; /* Read only */
79 	uint8_t weight;
80 	uint8_t affinity;
81 	uint8_t priority;
82 };
83 
84 static int
85 ssovf_mbox_priority_set(uint8_t queue, uint8_t prio)
86 {
87 	struct octeontx_mbox_hdr hdr = {0};
88 	struct ssovf_mbox_grp_pri grp;
89 	uint16_t len = sizeof(struct ssovf_mbox_grp_pri);
90 	int ret;
91 
92 	hdr.coproc = SSO_COPROC;
93 	hdr.msg = SSO_GRP_SET_PRIORITY;
94 	hdr.vfid = queue;
95 
96 	grp.vhgrp_id = queue;
97 	grp.weight = 0xff;
98 	grp.affinity = 0xff;
99 	grp.priority = prio / 32; /* Normalize to 0 to 7 */
100 
101 	ret = octeontx_mbox_send(&hdr, &grp, len, NULL, 0);
102 	if (ret)
103 		ssovf_log_err("Failed to set grp=%d prio=%d", queue, prio);
104 
105 	return ret;
106 }
107 
108 struct ssovf_mbox_convert_ns_getworks_iter {
109 	uint64_t wait_ns;
110 	uint32_t getwork_iter;/* Get_work iterations for the given wait_ns */
111 };
112 
113 static int
114 ssovf_mbox_timeout_ticks(uint64_t ns, uint64_t *tmo_ticks)
115 {
116 	struct octeontx_mbox_hdr hdr = {0};
117 	struct ssovf_mbox_convert_ns_getworks_iter ns2iter;
118 	uint16_t len = sizeof(ns2iter);
119 	int ret;
120 
121 	hdr.coproc = SSO_COPROC;
122 	hdr.msg = SSO_CONVERT_NS_GETWORK_ITER;
123 	hdr.vfid = 0;
124 
125 	memset(&ns2iter, 0, len);
126 	ns2iter.wait_ns = ns;
127 	ret = octeontx_mbox_send(&hdr, &ns2iter, len, &ns2iter, len);
128 	if (ret < 0 || (ret != len)) {
129 		ssovf_log_err("Failed to get tmo ticks ns=%"PRId64"", ns);
130 		return -EIO;
131 	}
132 
133 	*tmo_ticks = ns2iter.getwork_iter;
134 	return 0;
135 }
136 
137 static void
138 ssovf_info_get(struct rte_eventdev *dev, struct rte_event_dev_info *dev_info)
139 {
140 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
141 
142 	dev_info->driver_name = RTE_STR(EVENTDEV_NAME_OCTEONTX_PMD);
143 	dev_info->min_dequeue_timeout_ns = edev->min_deq_timeout_ns;
144 	dev_info->max_dequeue_timeout_ns = edev->max_deq_timeout_ns;
145 	dev_info->max_event_queues = edev->max_event_queues;
146 	dev_info->max_event_queue_flows = (1ULL << 20);
147 	dev_info->max_event_queue_priority_levels = 8;
148 	dev_info->max_event_priority_levels = 1;
149 	dev_info->max_event_ports = edev->max_event_ports;
150 	dev_info->max_event_port_dequeue_depth = 1;
151 	dev_info->max_event_port_enqueue_depth = 1;
152 	dev_info->max_num_events =  edev->max_num_events;
153 	dev_info->event_dev_cap = RTE_EVENT_DEV_CAP_QUEUE_QOS |
154 					RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED |
155 					RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES|
156 					RTE_EVENT_DEV_CAP_RUNTIME_PORT_LINK |
157 					RTE_EVENT_DEV_CAP_MULTIPLE_QUEUE_PORT |
158 					RTE_EVENT_DEV_CAP_NONSEQ_MODE |
159 					RTE_EVENT_DEV_CAP_CARRY_FLOW_ID |
160 					RTE_EVENT_DEV_CAP_MAINTENANCE_FREE;
161 	dev_info->max_profiles_per_port = 1;
162 }
163 
164 static int
165 ssovf_configure(const struct rte_eventdev *dev)
166 {
167 	struct rte_event_dev_config *conf = &dev->data->dev_conf;
168 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
169 	uint64_t deq_tmo_ns;
170 
171 	ssovf_func_trace();
172 	deq_tmo_ns = conf->dequeue_timeout_ns;
173 	if (deq_tmo_ns == 0)
174 		deq_tmo_ns = edev->min_deq_timeout_ns;
175 
176 	if (conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT) {
177 		edev->is_timeout_deq = 1;
178 		deq_tmo_ns = edev->min_deq_timeout_ns;
179 	}
180 	edev->nb_event_queues = conf->nb_event_queues;
181 	edev->nb_event_ports = conf->nb_event_ports;
182 
183 	return ssovf_mbox_getwork_tmo_set(deq_tmo_ns);
184 }
185 
186 static void
187 ssovf_queue_def_conf(struct rte_eventdev *dev, uint8_t queue_id,
188 				 struct rte_event_queue_conf *queue_conf)
189 {
190 	RTE_SET_USED(dev);
191 	RTE_SET_USED(queue_id);
192 
193 	queue_conf->nb_atomic_flows = (1ULL << 20);
194 	queue_conf->nb_atomic_order_sequences = (1ULL << 20);
195 	queue_conf->event_queue_cfg = RTE_EVENT_QUEUE_CFG_ALL_TYPES;
196 	queue_conf->priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
197 }
198 
199 static void
200 ssovf_queue_release(struct rte_eventdev *dev, uint8_t queue_id)
201 {
202 	RTE_SET_USED(dev);
203 	RTE_SET_USED(queue_id);
204 }
205 
206 static int
207 ssovf_queue_setup(struct rte_eventdev *dev, uint8_t queue_id,
208 			      const struct rte_event_queue_conf *queue_conf)
209 {
210 	RTE_SET_USED(dev);
211 	ssovf_func_trace("queue=%d prio=%d", queue_id, queue_conf->priority);
212 
213 	return ssovf_mbox_priority_set(queue_id, queue_conf->priority);
214 }
215 
216 static void
217 ssovf_port_def_conf(struct rte_eventdev *dev, uint8_t port_id,
218 				 struct rte_event_port_conf *port_conf)
219 {
220 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
221 
222 	RTE_SET_USED(port_id);
223 	port_conf->new_event_threshold = edev->max_num_events;
224 	port_conf->dequeue_depth = 1;
225 	port_conf->enqueue_depth = 1;
226 	port_conf->event_port_cfg = 0;
227 }
228 
229 static void
230 ssovf_port_release(void *port)
231 {
232 	rte_free(port);
233 }
234 
235 static int
236 ssovf_port_setup(struct rte_eventdev *dev, uint8_t port_id,
237 				const struct rte_event_port_conf *port_conf)
238 {
239 	struct ssows *ws;
240 	uint32_t reg_off;
241 	uint8_t q;
242 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
243 
244 	ssovf_func_trace("port=%d", port_id);
245 	RTE_SET_USED(port_conf);
246 
247 	/* Free memory prior to re-allocation if needed */
248 	if (dev->data->ports[port_id] != NULL) {
249 		ssovf_port_release(dev->data->ports[port_id]);
250 		dev->data->ports[port_id] = NULL;
251 	}
252 
253 	/* Allocate event port memory */
254 	ws = rte_zmalloc_socket("eventdev ssows",
255 			sizeof(struct ssows), RTE_CACHE_LINE_SIZE,
256 			dev->data->socket_id);
257 	if (ws == NULL) {
258 		ssovf_log_err("Failed to alloc memory for port=%d", port_id);
259 		return -ENOMEM;
260 	}
261 
262 	ws->base = ssovf_bar(OCTEONTX_SSO_HWS, port_id, 0);
263 	if (ws->base == NULL) {
264 		rte_free(ws);
265 		ssovf_log_err("Failed to get hws base addr port=%d", port_id);
266 		return -EINVAL;
267 	}
268 
269 	reg_off = SSOW_VHWS_OP_GET_WORK0;
270 	reg_off |= 1 << 4; /* Index_ggrp_mask (Use maskset zero) */
271 	reg_off |= 1 << 16; /* Wait */
272 	ws->getwork = ws->base + reg_off;
273 	ws->port = port_id;
274 	ws->lookup_mem = octeontx_fastpath_lookup_mem_get();
275 
276 	for (q = 0; q < edev->nb_event_queues; q++) {
277 		ws->grps[q] = ssovf_bar(OCTEONTX_SSO_GROUP, q, 2);
278 		if (ws->grps[q] == NULL) {
279 			rte_free(ws);
280 			ssovf_log_err("Failed to get grp%d base addr", q);
281 			return -EINVAL;
282 		}
283 	}
284 
285 	dev->data->ports[port_id] = ws;
286 	ssovf_log_dbg("port=%d ws=%p", port_id, ws);
287 	return 0;
288 }
289 
290 static int
291 ssovf_port_link(struct rte_eventdev *dev, void *port, const uint8_t queues[],
292 		const uint8_t priorities[], uint16_t nb_links)
293 {
294 	uint16_t link;
295 	uint64_t val;
296 	struct ssows *ws = port;
297 
298 	ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_links);
299 	RTE_SET_USED(dev);
300 	RTE_SET_USED(priorities);
301 
302 	for (link = 0; link < nb_links; link++) {
303 		val = queues[link];
304 		val |= (1ULL << 24); /* Set membership */
305 		ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0));
306 	}
307 	return (int)nb_links;
308 }
309 
310 static int
311 ssovf_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
312 			uint16_t nb_unlinks)
313 {
314 	uint16_t unlink;
315 	uint64_t val;
316 	struct ssows *ws = port;
317 
318 	ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_unlinks);
319 	RTE_SET_USED(dev);
320 
321 	for (unlink = 0; unlink < nb_unlinks; unlink++) {
322 		val = queues[unlink];
323 		val &= ~(1ULL << 24); /* Clear membership */
324 		ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0));
325 	}
326 	return (int)nb_unlinks;
327 }
328 
329 static int
330 ssovf_timeout_ticks(struct rte_eventdev *dev, uint64_t ns, uint64_t *tmo_ticks)
331 {
332 	RTE_SET_USED(dev);
333 
334 	return ssovf_mbox_timeout_ticks(ns, tmo_ticks);
335 }
336 
337 static void
338 ssows_dump(struct ssows *ws, FILE *f)
339 {
340 	uint8_t *base = ws->base;
341 	uint64_t val;
342 
343 	fprintf(f, "\t---------------port%d---------------\n", ws->port);
344 	val = ssovf_read64(base + SSOW_VHWS_TAG);
345 	fprintf(f, "\ttag=0x%x tt=%d head=%d tail=%d grp=%d index=%d tail=%d\n",
346 		(uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3,
347 		(int)(val >> 34) & 0x1, (int)(val >> 35) & 0x1,
348 		(int)(val >> 36) & 0x3ff, (int)(val >> 48) & 0x3ff,
349 		(int)(val >> 63) & 0x1);
350 
351 	val = ssovf_read64(base + SSOW_VHWS_WQP);
352 	fprintf(f, "\twqp=0x%"PRIx64"\n", val);
353 
354 	val = ssovf_read64(base + SSOW_VHWS_LINKS);
355 	fprintf(f, "\tindex=%d valid=%d revlink=%d tail=%d head=%d grp=%d\n",
356 		(int)(val & 0x3ff), (int)(val >> 10) & 0x1,
357 		(int)(val >> 11) & 0x3ff, (int)(val >> 26) & 0x1,
358 		(int)(val >> 27) & 0x1, (int)(val >> 28) & 0x3ff);
359 
360 	val = ssovf_read64(base + SSOW_VHWS_PENDTAG);
361 	fprintf(f, "\tptag=0x%x ptt=%d pgwi=%d pdesc=%d pgw=%d pgww=%d ps=%d\n",
362 		(uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3,
363 		(int)(val >> 56) & 0x1, (int)(val >> 58) & 0x1,
364 		(int)(val >> 61) & 0x1, (int)(val >> 62) & 0x1,
365 		(int)(val >> 63) & 0x1);
366 
367 	val = ssovf_read64(base + SSOW_VHWS_PENDWQP);
368 	fprintf(f, "\tpwqp=0x%"PRIx64"\n", val);
369 }
370 
371 static int
372 ssovf_eth_rx_adapter_caps_get(const struct rte_eventdev *dev,
373 		const struct rte_eth_dev *eth_dev, uint32_t *caps)
374 {
375 	int ret;
376 	RTE_SET_USED(dev);
377 
378 	ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
379 	if (ret)
380 		*caps = RTE_EVENT_ETH_RX_ADAPTER_SW_CAP;
381 	else
382 		*caps = RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT;
383 
384 	return 0;
385 }
386 
387 static int
388 ssovf_eth_rx_adapter_queue_add(const struct rte_eventdev *dev,
389 		const struct rte_eth_dev *eth_dev, int32_t rx_queue_id,
390 		const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
391 {
392 	const struct octeontx_nic *nic = eth_dev->data->dev_private;
393 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
394 	uint16_t free_idx = UINT16_MAX;
395 	struct octeontx_rxq *rxq;
396 	pki_mod_qos_t pki_qos;
397 	uint8_t found = false;
398 	int i, ret = 0;
399 	void *old_ptr;
400 
401 	ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
402 	if (ret)
403 		return -EINVAL;
404 
405 	if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
406 		return -ENOTSUP;
407 
408 	/* eth_octeontx only supports one rq. */
409 	rx_queue_id = rx_queue_id == -1 ? 0 : rx_queue_id;
410 	rxq = eth_dev->data->rx_queues[rx_queue_id];
411 	/* Add rxq pool to list of used pools and reduce available events. */
412 	for (i = 0; i < edev->rxq_pools; i++) {
413 		if (edev->rxq_pool_array[i] == (uintptr_t)rxq->pool) {
414 			edev->rxq_pool_rcnt[i]++;
415 			found = true;
416 			break;
417 		} else if (free_idx == UINT16_MAX &&
418 			   edev->rxq_pool_array[i] == 0) {
419 			free_idx = i;
420 		}
421 	}
422 
423 	if (!found) {
424 		uint16_t idx;
425 
426 		if (edev->available_events < rxq->pool->size) {
427 			ssovf_log_err(
428 				"Max available events %"PRIu32" requested events in rxq pool %"PRIu32"",
429 				edev->available_events, rxq->pool->size);
430 			return -ENOMEM;
431 		}
432 
433 		if (free_idx != UINT16_MAX) {
434 			idx = free_idx;
435 		} else {
436 			old_ptr = edev->rxq_pool_array;
437 			edev->rxq_pools++;
438 			edev->rxq_pool_array = rte_realloc(
439 				edev->rxq_pool_array,
440 				sizeof(uint64_t) * edev->rxq_pools, 0);
441 			if (edev->rxq_pool_array == NULL) {
442 				edev->rxq_pools--;
443 				edev->rxq_pool_array = old_ptr;
444 				return -ENOMEM;
445 			}
446 
447 			old_ptr = edev->rxq_pool_rcnt;
448 			edev->rxq_pool_rcnt = rte_realloc(
449 				edev->rxq_pool_rcnt,
450 				sizeof(uint8_t) * edev->rxq_pools, 0);
451 			if (edev->rxq_pool_rcnt == NULL) {
452 				edev->rxq_pools--;
453 				edev->rxq_pool_rcnt = old_ptr;
454 				return -ENOMEM;
455 			}
456 			idx = edev->rxq_pools - 1;
457 		}
458 
459 		edev->rxq_pool_array[idx] = (uintptr_t)rxq->pool;
460 		edev->rxq_pool_rcnt[idx] = 1;
461 		edev->available_events -= rxq->pool->size;
462 	}
463 
464 	memset(&pki_qos, 0, sizeof(pki_mod_qos_t));
465 
466 	pki_qos.port_type = 0;
467 	pki_qos.index = 0;
468 	pki_qos.mmask.f_tag_type = 1;
469 	pki_qos.mmask.f_port_add = 1;
470 	pki_qos.mmask.f_grp_ok = 1;
471 	pki_qos.mmask.f_grp_bad = 1;
472 	pki_qos.mmask.f_grptag_ok = 1;
473 	pki_qos.mmask.f_grptag_bad = 1;
474 
475 	pki_qos.qos_entry.tag_type = queue_conf->ev.sched_type;
476 	pki_qos.qos_entry.port_add = 0;
477 	pki_qos.qos_entry.ggrp_ok = queue_conf->ev.queue_id;
478 	pki_qos.qos_entry.ggrp_bad = queue_conf->ev.queue_id;
479 	pki_qos.qos_entry.grptag_bad = 0;
480 	pki_qos.qos_entry.grptag_ok = 0;
481 
482 	ret = octeontx_pki_port_modify_qos(nic->port_id, &pki_qos);
483 	if (ret < 0)
484 		ssovf_log_err("failed to modify QOS, port=%d, q=%d",
485 				nic->port_id, queue_conf->ev.queue_id);
486 
487 	edev->rx_offload_flags = nic->rx_offload_flags;
488 	edev->tx_offload_flags = nic->tx_offload_flags;
489 	return ret;
490 }
491 
492 static int
493 ssovf_eth_rx_adapter_queue_del(const struct rte_eventdev *dev,
494 		const struct rte_eth_dev *eth_dev, int32_t rx_queue_id)
495 {
496 	const struct octeontx_nic *nic = eth_dev->data->dev_private;
497 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
498 	struct octeontx_rxq *rxq;
499 	pki_del_qos_t pki_qos;
500 	uint8_t found = false;
501 	int i, ret = 0;
502 
503 	rx_queue_id = rx_queue_id == -1 ? 0 : rx_queue_id;
504 	rxq = eth_dev->data->rx_queues[rx_queue_id];
505 	for (i = 0; i < edev->rxq_pools; i++) {
506 		if (edev->rxq_pool_array[i] == (uintptr_t)rxq->pool) {
507 			found = true;
508 			break;
509 		}
510 	}
511 
512 	if (found) {
513 		edev->rxq_pool_rcnt[i]--;
514 		if (edev->rxq_pool_rcnt[i] == 0)
515 			edev->rxq_pool_array[i] = 0;
516 		edev->available_events += rxq->pool->size;
517 	}
518 
519 	ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
520 	if (ret)
521 		return -EINVAL;
522 
523 	pki_qos.port_type = 0;
524 	pki_qos.index = 0;
525 	memset(&pki_qos, 0, sizeof(pki_del_qos_t));
526 	ret = octeontx_pki_port_delete_qos(nic->port_id, &pki_qos);
527 	if (ret < 0)
528 		ssovf_log_err("Failed to delete QOS port=%d, q=%d",
529 				nic->port_id, rx_queue_id);
530 	return ret;
531 }
532 
533 static int
534 ssovf_eth_rx_adapter_start(const struct rte_eventdev *dev,
535 					const struct rte_eth_dev *eth_dev)
536 {
537 	RTE_SET_USED(dev);
538 	RTE_SET_USED(eth_dev);
539 
540 	return 0;
541 }
542 
543 
544 static int
545 ssovf_eth_rx_adapter_stop(const struct rte_eventdev *dev,
546 		const struct rte_eth_dev *eth_dev)
547 {
548 	RTE_SET_USED(dev);
549 	RTE_SET_USED(eth_dev);
550 
551 	return 0;
552 }
553 
554 static int
555 ssovf_eth_tx_adapter_caps_get(const struct rte_eventdev *dev,
556 		const struct rte_eth_dev *eth_dev, uint32_t *caps)
557 {
558 	int ret;
559 	RTE_SET_USED(dev);
560 
561 	ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
562 	if (ret)
563 		*caps = 0;
564 	else
565 		*caps = RTE_EVENT_ETH_TX_ADAPTER_CAP_INTERNAL_PORT;
566 
567 	return 0;
568 }
569 
570 static int
571 ssovf_eth_tx_adapter_create(uint8_t id, const struct rte_eventdev *dev)
572 {
573 	RTE_SET_USED(id);
574 	RTE_SET_USED(dev);
575 	return 0;
576 }
577 
578 static int
579 ssovf_eth_tx_adapter_free(uint8_t id, const struct rte_eventdev *dev)
580 {
581 	RTE_SET_USED(id);
582 	RTE_SET_USED(dev);
583 	return 0;
584 }
585 
586 static int
587 ssovf_eth_tx_adapter_queue_add(uint8_t id, const struct rte_eventdev *dev,
588 		const struct rte_eth_dev *eth_dev, int32_t tx_queue_id)
589 {
590 	RTE_SET_USED(id);
591 	RTE_SET_USED(dev);
592 	RTE_SET_USED(eth_dev);
593 	RTE_SET_USED(tx_queue_id);
594 	return 0;
595 }
596 
597 static int
598 ssovf_eth_tx_adapter_queue_del(uint8_t id, const struct rte_eventdev *dev,
599 		const struct rte_eth_dev *eth_dev, int32_t tx_queue_id)
600 {
601 	RTE_SET_USED(id);
602 	RTE_SET_USED(dev);
603 	RTE_SET_USED(eth_dev);
604 	RTE_SET_USED(tx_queue_id);
605 	return 0;
606 }
607 
608 static int
609 ssovf_eth_tx_adapter_start(uint8_t id, const struct rte_eventdev *dev)
610 {
611 	RTE_SET_USED(id);
612 	RTE_SET_USED(dev);
613 	return 0;
614 }
615 
616 static int
617 ssovf_eth_tx_adapter_stop(uint8_t id, const struct rte_eventdev *dev)
618 {
619 	RTE_SET_USED(id);
620 	RTE_SET_USED(dev);
621 	return 0;
622 }
623 
624 
625 static void
626 ssovf_dump(struct rte_eventdev *dev, FILE *f)
627 {
628 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
629 	uint8_t port;
630 
631 	/* Dump SSOWVF debug registers */
632 	for (port = 0; port < edev->nb_event_ports; port++)
633 		ssows_dump(dev->data->ports[port], f);
634 }
635 
636 static int
637 ssovf_start(struct rte_eventdev *dev)
638 {
639 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
640 	struct ssows *ws;
641 	uint8_t *base;
642 	uint8_t i;
643 
644 	ssovf_func_trace();
645 	for (i = 0; i < edev->nb_event_ports; i++) {
646 		ws = dev->data->ports[i];
647 		ssows_reset(ws);
648 		ws->swtag_req = 0;
649 	}
650 
651 	for (i = 0; i < edev->nb_event_queues; i++) {
652 		/* Consume all the events through HWS0 */
653 		ssows_flush_events(dev->data->ports[0], i, NULL, NULL);
654 
655 		base = ssovf_bar(OCTEONTX_SSO_GROUP, i, 0);
656 		base += SSO_VHGRP_QCTL;
657 		ssovf_write64(1, base); /* Enable SSO group */
658 	}
659 
660 	ssovf_fastpath_fns_set(dev);
661 	return 0;
662 }
663 
664 static void
665 ssows_handle_event(void *arg, struct rte_event event)
666 {
667 	struct rte_eventdev *dev = arg;
668 
669 	if (dev->dev_ops->dev_stop_flush != NULL)
670 		dev->dev_ops->dev_stop_flush(dev->data->dev_id, event,
671 					dev->data->dev_stop_flush_arg);
672 }
673 
674 static void
675 ssovf_stop(struct rte_eventdev *dev)
676 {
677 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
678 	struct ssows *ws;
679 	uint8_t *base;
680 	uint8_t i;
681 
682 	ssovf_func_trace();
683 	for (i = 0; i < edev->nb_event_ports; i++) {
684 		ws = dev->data->ports[i];
685 		ssows_reset(ws);
686 		ws->swtag_req = 0;
687 	}
688 
689 	for (i = 0; i < edev->nb_event_queues; i++) {
690 		/* Consume all the events through HWS0 */
691 		ssows_flush_events(dev->data->ports[0], i,
692 				ssows_handle_event, dev);
693 
694 		base = ssovf_bar(OCTEONTX_SSO_GROUP, i, 0);
695 		base += SSO_VHGRP_QCTL;
696 		ssovf_write64(0, base); /* Disable SSO group */
697 	}
698 }
699 
700 static int
701 ssovf_close(struct rte_eventdev *dev)
702 {
703 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
704 	uint8_t all_queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
705 	uint8_t i;
706 
707 	for (i = 0; i < edev->nb_event_queues; i++)
708 		all_queues[i] = i;
709 
710 	for (i = 0; i < edev->nb_event_ports; i++)
711 		ssovf_port_unlink(dev, dev->data->ports[i], all_queues,
712 			edev->nb_event_queues);
713 	return 0;
714 }
715 
716 static int
717 ssovf_parsekv(const char *key __rte_unused, const char *value, void *opaque)
718 {
719 	int *flag = opaque;
720 	*flag = !!atoi(value);
721 	return 0;
722 }
723 
724 static int
725 ssovf_timvf_caps_get(const struct rte_eventdev *dev, uint64_t flags,
726 		     uint32_t *caps, const struct event_timer_adapter_ops **ops)
727 {
728 	return timvf_timer_adapter_caps_get(dev, flags, caps, ops,
729 			timvf_enable_stats);
730 }
731 
732 static int
733 ssovf_crypto_adapter_caps_get(const struct rte_eventdev *dev,
734 			      const struct rte_cryptodev *cdev, uint32_t *caps)
735 {
736 	RTE_SET_USED(dev);
737 	RTE_SET_USED(cdev);
738 
739 	*caps = RTE_EVENT_CRYPTO_ADAPTER_CAP_INTERNAL_PORT_OP_FWD |
740 		RTE_EVENT_CRYPTO_ADAPTER_CAP_SESSION_PRIVATE_DATA;
741 
742 	return 0;
743 }
744 
745 static int
746 ssovf_crypto_adapter_qp_add(const struct rte_eventdev *dev,
747 			    const struct rte_cryptodev *cdev,
748 			    int32_t queue_pair_id,
749 			    const struct rte_event_crypto_adapter_queue_conf *conf)
750 {
751 	struct cpt_instance *qp;
752 	uint8_t qp_id;
753 
754 	RTE_SET_USED(conf);
755 
756 	if (queue_pair_id == -1) {
757 		for (qp_id = 0; qp_id < cdev->data->nb_queue_pairs; qp_id++) {
758 			qp = cdev->data->queue_pairs[qp_id];
759 			qp->ca_enabled = 1;
760 		}
761 	} else {
762 		qp = cdev->data->queue_pairs[queue_pair_id];
763 		qp->ca_enabled = 1;
764 	}
765 
766 	ssovf_fastpath_fns_set((struct rte_eventdev *)(uintptr_t)dev);
767 
768 	return 0;
769 }
770 
771 static int
772 ssovf_crypto_adapter_qp_del(const struct rte_eventdev *dev,
773 			    const struct rte_cryptodev *cdev,
774 			    int32_t queue_pair_id)
775 {
776 	struct cpt_instance *qp;
777 	uint8_t qp_id;
778 
779 	RTE_SET_USED(dev);
780 
781 	if (queue_pair_id == -1) {
782 		for (qp_id = 0; qp_id < cdev->data->nb_queue_pairs; qp_id++) {
783 			qp = cdev->data->queue_pairs[qp_id];
784 			qp->ca_enabled = 0;
785 		}
786 	} else {
787 		qp = cdev->data->queue_pairs[queue_pair_id];
788 		qp->ca_enabled = 0;
789 	}
790 
791 	return 0;
792 }
793 
794 /* Initialize and register event driver with DPDK Application */
795 static struct eventdev_ops ssovf_ops = {
796 	.dev_infos_get    = ssovf_info_get,
797 	.dev_configure    = ssovf_configure,
798 	.queue_def_conf   = ssovf_queue_def_conf,
799 	.queue_setup      = ssovf_queue_setup,
800 	.queue_release    = ssovf_queue_release,
801 	.port_def_conf    = ssovf_port_def_conf,
802 	.port_setup       = ssovf_port_setup,
803 	.port_release     = ssovf_port_release,
804 	.port_link        = ssovf_port_link,
805 	.port_unlink      = ssovf_port_unlink,
806 	.timeout_ticks    = ssovf_timeout_ticks,
807 
808 	.eth_rx_adapter_caps_get  = ssovf_eth_rx_adapter_caps_get,
809 	.eth_rx_adapter_queue_add = ssovf_eth_rx_adapter_queue_add,
810 	.eth_rx_adapter_queue_del = ssovf_eth_rx_adapter_queue_del,
811 	.eth_rx_adapter_start = ssovf_eth_rx_adapter_start,
812 	.eth_rx_adapter_stop = ssovf_eth_rx_adapter_stop,
813 
814 	.eth_tx_adapter_caps_get = ssovf_eth_tx_adapter_caps_get,
815 	.eth_tx_adapter_create = ssovf_eth_tx_adapter_create,
816 	.eth_tx_adapter_free = ssovf_eth_tx_adapter_free,
817 	.eth_tx_adapter_queue_add = ssovf_eth_tx_adapter_queue_add,
818 	.eth_tx_adapter_queue_del = ssovf_eth_tx_adapter_queue_del,
819 	.eth_tx_adapter_start = ssovf_eth_tx_adapter_start,
820 	.eth_tx_adapter_stop = ssovf_eth_tx_adapter_stop,
821 
822 	.timer_adapter_caps_get = ssovf_timvf_caps_get,
823 
824 	.crypto_adapter_caps_get = ssovf_crypto_adapter_caps_get,
825 	.crypto_adapter_queue_pair_add = ssovf_crypto_adapter_qp_add,
826 	.crypto_adapter_queue_pair_del = ssovf_crypto_adapter_qp_del,
827 
828 	.dev_selftest = test_eventdev_octeontx,
829 
830 	.dump             = ssovf_dump,
831 	.dev_start        = ssovf_start,
832 	.dev_stop         = ssovf_stop,
833 	.dev_close        = ssovf_close
834 };
835 
836 static int
837 ssovf_vdev_probe(struct rte_vdev_device *vdev)
838 {
839 	struct ssovf_info oinfo;
840 	struct ssovf_mbox_dev_info info;
841 	struct ssovf_evdev *edev;
842 	struct rte_eventdev *eventdev;
843 	static int ssovf_init_once;
844 	const char *name;
845 	const char *params;
846 	int ret;
847 
848 	static const char *const args[] = {
849 		TIMVF_ENABLE_STATS_ARG,
850 		NULL
851 	};
852 
853 	name = rte_vdev_device_name(vdev);
854 	/* More than one instance is not supported */
855 	if (ssovf_init_once) {
856 		ssovf_log_err("Request to create >1 %s instance", name);
857 		return -EINVAL;
858 	}
859 
860 	params = rte_vdev_device_args(vdev);
861 	if (params != NULL && params[0] != '\0') {
862 		struct rte_kvargs *kvlist = rte_kvargs_parse(params, args);
863 
864 		if (!kvlist) {
865 			ssovf_log_info(
866 				"Ignoring unsupported params supplied '%s'",
867 				name);
868 		} else {
869 			ret = rte_kvargs_process(kvlist, TIMVF_ENABLE_STATS_ARG,
870 						 ssovf_parsekv,
871 						 &timvf_enable_stats);
872 			if (ret != 0) {
873 				ssovf_log_err("%s: Error in timvf stats", name);
874 				rte_kvargs_free(kvlist);
875 				return ret;
876 			}
877 		}
878 
879 		rte_kvargs_free(kvlist);
880 	}
881 
882 	eventdev = rte_event_pmd_vdev_init(name, sizeof(struct ssovf_evdev),
883 				rte_socket_id(), vdev);
884 	if (eventdev == NULL) {
885 		ssovf_log_err("Failed to create eventdev vdev %s", name);
886 		return -ENOMEM;
887 	}
888 	eventdev->dev_ops = &ssovf_ops;
889 
890 	timvf_set_eventdevice(eventdev);
891 
892 	/* For secondary processes, the primary has done all the work */
893 	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
894 		ssovf_fastpath_fns_set(eventdev);
895 		return 0;
896 	}
897 
898 	octeontx_mbox_init();
899 	ret = ssovf_info(&oinfo);
900 	if (ret) {
901 		ssovf_log_err("Failed to probe and validate ssovfs %d", ret);
902 		goto error;
903 	}
904 
905 	edev = ssovf_pmd_priv(eventdev);
906 	edev->max_event_ports = oinfo.total_ssowvfs;
907 	edev->max_event_queues = oinfo.total_ssovfs;
908 	edev->is_timeout_deq = 0;
909 
910 	ret = ssovf_mbox_dev_info(&info);
911 	if (ret < 0 || ret != sizeof(struct ssovf_mbox_dev_info)) {
912 		ssovf_log_err("Failed to get mbox devinfo %d", ret);
913 		goto error;
914 	}
915 
916 	edev->min_deq_timeout_ns = info.min_deq_timeout_ns;
917 	edev->max_deq_timeout_ns = info.max_deq_timeout_ns;
918 	edev->max_num_events =  info.max_num_events;
919 	edev->available_events = info.max_num_events;
920 
921 	ssovf_log_dbg("min_deq_tmo=%" PRId64 " max_deq_tmo=%" PRId64
922 		      " max_evts=%d",
923 		      info.min_deq_timeout_ns, info.max_deq_timeout_ns,
924 		      info.max_num_events);
925 
926 	if (!edev->max_event_ports || !edev->max_event_queues) {
927 		ssovf_log_err("Not enough eventdev resource queues=%d ports=%d",
928 			edev->max_event_queues, edev->max_event_ports);
929 		ret = -ENODEV;
930 		goto error;
931 	}
932 
933 	ssovf_log_info("Initializing %s domain=%d max_queues=%d max_ports=%d",
934 			name, oinfo.domain, edev->max_event_queues,
935 			edev->max_event_ports);
936 
937 	ssovf_init_once = 1;
938 	event_dev_probing_finish(eventdev);
939 	return 0;
940 
941 error:
942 	rte_event_pmd_vdev_uninit(name);
943 	return ret;
944 }
945 
946 static int
947 ssovf_vdev_remove(struct rte_vdev_device *vdev)
948 {
949 	const char *name;
950 
951 	name = rte_vdev_device_name(vdev);
952 	ssovf_log_info("Closing %s", name);
953 	return rte_event_pmd_vdev_uninit(name);
954 }
955 
956 static struct rte_vdev_driver vdev_ssovf_pmd = {
957 	.probe = ssovf_vdev_probe,
958 	.remove = ssovf_vdev_remove
959 };
960 
961 RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_OCTEONTX_PMD, vdev_ssovf_pmd);
962