xref: /dpdk/drivers/event/octeontx/ssovf_evdev.c (revision 12a33b67dd814ab1f497e51bf3069d0482b8e069)
1 /*
2  *   BSD LICENSE
3  *
4  *   Copyright (C) Cavium, Inc. 2017.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Cavium, Inc nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <inttypes.h>
34 
35 #include <rte_common.h>
36 #include <rte_debug.h>
37 #include <rte_dev.h>
38 #include <rte_eal.h>
39 #include <rte_ethdev.h>
40 #include <rte_event_eth_rx_adapter.h>
41 #include <rte_lcore.h>
42 #include <rte_log.h>
43 #include <rte_malloc.h>
44 #include <rte_memory.h>
45 #include <rte_memzone.h>
46 #include <rte_vdev.h>
47 
48 #include "ssovf_evdev.h"
49 
50 /* SSOPF Mailbox messages */
51 
52 struct ssovf_mbox_dev_info {
53 	uint64_t min_deq_timeout_ns;
54 	uint64_t max_deq_timeout_ns;
55 	uint32_t max_num_events;
56 };
57 
58 static int
59 ssovf_mbox_dev_info(struct ssovf_mbox_dev_info *info)
60 {
61 	struct octeontx_mbox_hdr hdr = {0};
62 	uint16_t len = sizeof(struct ssovf_mbox_dev_info);
63 
64 	hdr.coproc = SSO_COPROC;
65 	hdr.msg = SSO_GET_DEV_INFO;
66 	hdr.vfid = 0;
67 
68 	memset(info, 0, len);
69 	return octeontx_ssovf_mbox_send(&hdr, NULL, 0, info, len);
70 }
71 
72 struct ssovf_mbox_getwork_wait {
73 	uint64_t wait_ns;
74 };
75 
76 static int
77 ssovf_mbox_getwork_tmo_set(uint32_t timeout_ns)
78 {
79 	struct octeontx_mbox_hdr hdr = {0};
80 	struct ssovf_mbox_getwork_wait tmo_set;
81 	uint16_t len = sizeof(struct ssovf_mbox_getwork_wait);
82 	int ret;
83 
84 	hdr.coproc = SSO_COPROC;
85 	hdr.msg = SSO_SET_GETWORK_WAIT;
86 	hdr.vfid = 0;
87 
88 	tmo_set.wait_ns = timeout_ns;
89 	ret = octeontx_ssovf_mbox_send(&hdr, &tmo_set, len, NULL, 0);
90 	if (ret)
91 		ssovf_log_err("Failed to set getwork timeout(%d)", ret);
92 
93 	return ret;
94 }
95 
96 struct ssovf_mbox_grp_pri {
97 	uint8_t wgt_left; /* Read only */
98 	uint8_t weight;
99 	uint8_t affinity;
100 	uint8_t priority;
101 };
102 
103 static int
104 ssovf_mbox_priority_set(uint8_t queue, uint8_t prio)
105 {
106 	struct octeontx_mbox_hdr hdr = {0};
107 	struct ssovf_mbox_grp_pri grp;
108 	uint16_t len = sizeof(struct ssovf_mbox_grp_pri);
109 	int ret;
110 
111 	hdr.coproc = SSO_COPROC;
112 	hdr.msg = SSO_GRP_SET_PRIORITY;
113 	hdr.vfid = queue;
114 
115 	grp.weight = 0xff;
116 	grp.affinity = 0xff;
117 	grp.priority = prio / 32; /* Normalize to 0 to 7 */
118 
119 	ret = octeontx_ssovf_mbox_send(&hdr, &grp, len, NULL, 0);
120 	if (ret)
121 		ssovf_log_err("Failed to set grp=%d prio=%d", queue, prio);
122 
123 	return ret;
124 }
125 
126 struct ssovf_mbox_convert_ns_getworks_iter {
127 	uint64_t wait_ns;
128 	uint32_t getwork_iter;/* Get_work iterations for the given wait_ns */
129 };
130 
131 static int
132 ssovf_mbox_timeout_ticks(uint64_t ns, uint64_t *tmo_ticks)
133 {
134 	struct octeontx_mbox_hdr hdr = {0};
135 	struct ssovf_mbox_convert_ns_getworks_iter ns2iter;
136 	uint16_t len = sizeof(ns2iter);
137 	int ret;
138 
139 	hdr.coproc = SSO_COPROC;
140 	hdr.msg = SSO_CONVERT_NS_GETWORK_ITER;
141 	hdr.vfid = 0;
142 
143 	memset(&ns2iter, 0, len);
144 	ns2iter.wait_ns = ns;
145 	ret = octeontx_ssovf_mbox_send(&hdr, &ns2iter, len, &ns2iter, len);
146 	if (ret < 0 || (ret != len)) {
147 		ssovf_log_err("Failed to get tmo ticks ns=%"PRId64"", ns);
148 		return -EIO;
149 	}
150 
151 	*tmo_ticks = ns2iter.getwork_iter;
152 	return 0;
153 }
154 
155 static void
156 ssovf_fastpath_fns_set(struct rte_eventdev *dev)
157 {
158 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
159 
160 	dev->enqueue       = ssows_enq;
161 	dev->enqueue_burst = ssows_enq_burst;
162 	dev->enqueue_new_burst = ssows_enq_new_burst;
163 	dev->enqueue_forward_burst = ssows_enq_fwd_burst;
164 	dev->dequeue       = ssows_deq;
165 	dev->dequeue_burst = ssows_deq_burst;
166 
167 	if (edev->is_timeout_deq) {
168 		dev->dequeue       = ssows_deq_timeout;
169 		dev->dequeue_burst = ssows_deq_timeout_burst;
170 	}
171 }
172 
173 static void
174 ssovf_info_get(struct rte_eventdev *dev, struct rte_event_dev_info *dev_info)
175 {
176 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
177 
178 	dev_info->driver_name = RTE_STR(EVENTDEV_NAME_OCTEONTX_PMD);
179 	dev_info->min_dequeue_timeout_ns = edev->min_deq_timeout_ns;
180 	dev_info->max_dequeue_timeout_ns = edev->max_deq_timeout_ns;
181 	dev_info->max_event_queues = edev->max_event_queues;
182 	dev_info->max_event_queue_flows = (1ULL << 20);
183 	dev_info->max_event_queue_priority_levels = 8;
184 	dev_info->max_event_priority_levels = 1;
185 	dev_info->max_event_ports = edev->max_event_ports;
186 	dev_info->max_event_port_dequeue_depth = 1;
187 	dev_info->max_event_port_enqueue_depth = 1;
188 	dev_info->max_num_events =  edev->max_num_events;
189 	dev_info->event_dev_cap = RTE_EVENT_DEV_CAP_QUEUE_QOS |
190 					RTE_EVENT_DEV_CAP_DISTRIBUTED_SCHED |
191 					RTE_EVENT_DEV_CAP_QUEUE_ALL_TYPES;
192 }
193 
194 static int
195 ssovf_configure(const struct rte_eventdev *dev)
196 {
197 	struct rte_event_dev_config *conf = &dev->data->dev_conf;
198 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
199 	uint64_t deq_tmo_ns;
200 
201 	ssovf_func_trace();
202 	deq_tmo_ns = conf->dequeue_timeout_ns;
203 	if (deq_tmo_ns == 0)
204 		deq_tmo_ns = edev->min_deq_timeout_ns;
205 
206 	if (conf->event_dev_cfg & RTE_EVENT_DEV_CFG_PER_DEQUEUE_TIMEOUT) {
207 		edev->is_timeout_deq = 1;
208 		deq_tmo_ns = edev->min_deq_timeout_ns;
209 	}
210 	edev->nb_event_queues = conf->nb_event_queues;
211 	edev->nb_event_ports = conf->nb_event_ports;
212 
213 	return ssovf_mbox_getwork_tmo_set(deq_tmo_ns);
214 }
215 
216 static void
217 ssovf_queue_def_conf(struct rte_eventdev *dev, uint8_t queue_id,
218 				 struct rte_event_queue_conf *queue_conf)
219 {
220 	RTE_SET_USED(dev);
221 	RTE_SET_USED(queue_id);
222 
223 	queue_conf->nb_atomic_flows = (1ULL << 20);
224 	queue_conf->nb_atomic_order_sequences = (1ULL << 20);
225 	queue_conf->event_queue_cfg = RTE_EVENT_QUEUE_CFG_ALL_TYPES;
226 	queue_conf->priority = RTE_EVENT_DEV_PRIORITY_NORMAL;
227 }
228 
229 static void
230 ssovf_queue_release(struct rte_eventdev *dev, uint8_t queue_id)
231 {
232 	RTE_SET_USED(dev);
233 	RTE_SET_USED(queue_id);
234 }
235 
236 static int
237 ssovf_queue_setup(struct rte_eventdev *dev, uint8_t queue_id,
238 			      const struct rte_event_queue_conf *queue_conf)
239 {
240 	RTE_SET_USED(dev);
241 	ssovf_func_trace("queue=%d prio=%d", queue_id, queue_conf->priority);
242 
243 	return ssovf_mbox_priority_set(queue_id, queue_conf->priority);
244 }
245 
246 static void
247 ssovf_port_def_conf(struct rte_eventdev *dev, uint8_t port_id,
248 				 struct rte_event_port_conf *port_conf)
249 {
250 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
251 
252 	RTE_SET_USED(port_id);
253 	port_conf->new_event_threshold = edev->max_num_events;
254 	port_conf->dequeue_depth = 1;
255 	port_conf->enqueue_depth = 1;
256 }
257 
258 static void
259 ssovf_port_release(void *port)
260 {
261 	rte_free(port);
262 }
263 
264 static int
265 ssovf_port_setup(struct rte_eventdev *dev, uint8_t port_id,
266 				const struct rte_event_port_conf *port_conf)
267 {
268 	struct ssows *ws;
269 	uint32_t reg_off;
270 	uint8_t q;
271 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
272 
273 	ssovf_func_trace("port=%d", port_id);
274 	RTE_SET_USED(port_conf);
275 
276 	/* Free memory prior to re-allocation if needed */
277 	if (dev->data->ports[port_id] != NULL) {
278 		ssovf_port_release(dev->data->ports[port_id]);
279 		dev->data->ports[port_id] = NULL;
280 	}
281 
282 	/* Allocate event port memory */
283 	ws = rte_zmalloc_socket("eventdev ssows",
284 			sizeof(struct ssows), RTE_CACHE_LINE_SIZE,
285 			dev->data->socket_id);
286 	if (ws == NULL) {
287 		ssovf_log_err("Failed to alloc memory for port=%d", port_id);
288 		return -ENOMEM;
289 	}
290 
291 	ws->base = octeontx_ssovf_bar(OCTEONTX_SSO_HWS, port_id, 0);
292 	if (ws->base == NULL) {
293 		rte_free(ws);
294 		ssovf_log_err("Failed to get hws base addr port=%d", port_id);
295 		return -EINVAL;
296 	}
297 
298 	reg_off = SSOW_VHWS_OP_GET_WORK0;
299 	reg_off |= 1 << 4; /* Index_ggrp_mask (Use maskset zero) */
300 	reg_off |= 1 << 16; /* Wait */
301 	ws->getwork = ws->base + reg_off;
302 	ws->port = port_id;
303 
304 	for (q = 0; q < edev->nb_event_queues; q++) {
305 		ws->grps[q] = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, q, 2);
306 		if (ws->grps[q] == NULL) {
307 			rte_free(ws);
308 			ssovf_log_err("Failed to get grp%d base addr", q);
309 			return -EINVAL;
310 		}
311 	}
312 
313 	dev->data->ports[port_id] = ws;
314 	ssovf_log_dbg("port=%d ws=%p", port_id, ws);
315 	return 0;
316 }
317 
318 static int
319 ssovf_port_link(struct rte_eventdev *dev, void *port, const uint8_t queues[],
320 		const uint8_t priorities[], uint16_t nb_links)
321 {
322 	uint16_t link;
323 	uint64_t val;
324 	struct ssows *ws = port;
325 
326 	ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_links);
327 	RTE_SET_USED(dev);
328 	RTE_SET_USED(priorities);
329 
330 	for (link = 0; link < nb_links; link++) {
331 		val = queues[link];
332 		val |= (1ULL << 24); /* Set membership */
333 		ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0));
334 	}
335 	return (int)nb_links;
336 }
337 
338 static int
339 ssovf_port_unlink(struct rte_eventdev *dev, void *port, uint8_t queues[],
340 			uint16_t nb_unlinks)
341 {
342 	uint16_t unlink;
343 	uint64_t val;
344 	struct ssows *ws = port;
345 
346 	ssovf_func_trace("port=%d nb_links=%d", ws->port, nb_unlinks);
347 	RTE_SET_USED(dev);
348 
349 	for (unlink = 0; unlink < nb_unlinks; unlink++) {
350 		val = queues[unlink];
351 		val &= ~(1ULL << 24); /* Clear membership */
352 		ssovf_write64(val, ws->base + SSOW_VHWS_GRPMSK_CHGX(0));
353 	}
354 	return (int)nb_unlinks;
355 }
356 
357 static int
358 ssovf_timeout_ticks(struct rte_eventdev *dev, uint64_t ns, uint64_t *tmo_ticks)
359 {
360 	RTE_SET_USED(dev);
361 
362 	return ssovf_mbox_timeout_ticks(ns, tmo_ticks);
363 }
364 
365 static void
366 ssows_dump(struct ssows *ws, FILE *f)
367 {
368 	uint8_t *base = ws->base;
369 	uint64_t val;
370 
371 	fprintf(f, "\t---------------port%d---------------\n", ws->port);
372 	val = ssovf_read64(base + SSOW_VHWS_TAG);
373 	fprintf(f, "\ttag=0x%x tt=%d head=%d tail=%d grp=%d index=%d tail=%d\n",
374 		(uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3,
375 		(int)(val >> 34) & 0x1, (int)(val >> 35) & 0x1,
376 		(int)(val >> 36) & 0x3ff, (int)(val >> 48) & 0x3ff,
377 		(int)(val >> 63) & 0x1);
378 
379 	val = ssovf_read64(base + SSOW_VHWS_WQP);
380 	fprintf(f, "\twqp=0x%"PRIx64"\n", val);
381 
382 	val = ssovf_read64(base + SSOW_VHWS_LINKS);
383 	fprintf(f, "\tindex=%d valid=%d revlink=%d tail=%d head=%d grp=%d\n",
384 		(int)(val & 0x3ff), (int)(val >> 10) & 0x1,
385 		(int)(val >> 11) & 0x3ff, (int)(val >> 26) & 0x1,
386 		(int)(val >> 27) & 0x1, (int)(val >> 28) & 0x3ff);
387 
388 	val = ssovf_read64(base + SSOW_VHWS_PENDTAG);
389 	fprintf(f, "\tptag=0x%x ptt=%d pgwi=%d pdesc=%d pgw=%d pgww=%d ps=%d\n",
390 		(uint32_t)(val & 0xffffffff), (int)(val >> 32) & 0x3,
391 		(int)(val >> 56) & 0x1, (int)(val >> 58) & 0x1,
392 		(int)(val >> 61) & 0x1, (int)(val >> 62) & 0x1,
393 		(int)(val >> 63) & 0x1);
394 
395 	val = ssovf_read64(base + SSOW_VHWS_PENDWQP);
396 	fprintf(f, "\tpwqp=0x%"PRIx64"\n", val);
397 }
398 
399 static int
400 ssovf_eth_rx_adapter_caps_get(const struct rte_eventdev *dev,
401 		const struct rte_eth_dev *eth_dev, uint32_t *caps)
402 {
403 	int ret;
404 	RTE_SET_USED(dev);
405 
406 	ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
407 	if (ret)
408 		*caps = RTE_EVENT_ETH_RX_ADAPTER_SW_CAP;
409 	else
410 		*caps = RTE_EVENT_ETH_RX_ADAPTER_CAP_INTERNAL_PORT;
411 
412 	return 0;
413 }
414 
415 static int
416 ssovf_eth_rx_adapter_queue_add(const struct rte_eventdev *dev,
417 		const struct rte_eth_dev *eth_dev, int32_t rx_queue_id,
418 		const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
419 {
420 	int ret = 0;
421 	const struct octeontx_nic *nic = eth_dev->data->dev_private;
422 	pki_mod_qos_t pki_qos;
423 	RTE_SET_USED(dev);
424 
425 	ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
426 	if (ret)
427 		return -EINVAL;
428 
429 	if (rx_queue_id >= 0)
430 		return -EINVAL;
431 
432 	if (queue_conf->ev.sched_type == RTE_SCHED_TYPE_PARALLEL)
433 		return -ENOTSUP;
434 
435 	memset(&pki_qos, 0, sizeof(pki_mod_qos_t));
436 
437 	pki_qos.port_type = 0;
438 	pki_qos.index = 0;
439 	pki_qos.mmask.f_tag_type = 1;
440 	pki_qos.mmask.f_port_add = 1;
441 	pki_qos.mmask.f_grp_ok = 1;
442 	pki_qos.mmask.f_grp_bad = 1;
443 	pki_qos.mmask.f_grptag_ok = 1;
444 	pki_qos.mmask.f_grptag_bad = 1;
445 
446 	pki_qos.tag_type = queue_conf->ev.sched_type;
447 	pki_qos.qos_entry.port_add = 0;
448 	pki_qos.qos_entry.ggrp_ok = queue_conf->ev.queue_id;
449 	pki_qos.qos_entry.ggrp_bad = queue_conf->ev.queue_id;
450 	pki_qos.qos_entry.grptag_bad = 0;
451 	pki_qos.qos_entry.grptag_ok = 0;
452 
453 	ret = octeontx_pki_port_modify_qos(nic->port_id, &pki_qos);
454 	if (ret < 0)
455 		ssovf_log_err("failed to modify QOS, port=%d, q=%d",
456 				nic->port_id, queue_conf->ev.queue_id);
457 
458 	return ret;
459 }
460 
461 static int
462 ssovf_eth_rx_adapter_queue_del(const struct rte_eventdev *dev,
463 		const struct rte_eth_dev *eth_dev, int32_t rx_queue_id)
464 {
465 	int ret = 0;
466 	const struct octeontx_nic *nic = eth_dev->data->dev_private;
467 	pki_del_qos_t pki_qos;
468 	RTE_SET_USED(dev);
469 	RTE_SET_USED(rx_queue_id);
470 
471 	ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
472 	if (ret)
473 		return -EINVAL;
474 
475 	pki_qos.port_type = 0;
476 	pki_qos.index = 0;
477 	memset(&pki_qos, 0, sizeof(pki_del_qos_t));
478 	ret = octeontx_pki_port_delete_qos(nic->port_id, &pki_qos);
479 	if (ret < 0)
480 		ssovf_log_err("Failed to delete QOS port=%d, q=%d",
481 				nic->port_id, queue_conf->ev.queue_id);
482 	return ret;
483 }
484 
485 static int
486 ssovf_eth_rx_adapter_start(const struct rte_eventdev *dev,
487 					const struct rte_eth_dev *eth_dev)
488 {
489 	int ret;
490 	const struct octeontx_nic *nic = eth_dev->data->dev_private;
491 	RTE_SET_USED(dev);
492 
493 	ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
494 	if (ret)
495 		return 0;
496 	octeontx_pki_port_start(nic->port_id);
497 	return 0;
498 }
499 
500 
501 static int
502 ssovf_eth_rx_adapter_stop(const struct rte_eventdev *dev,
503 		const struct rte_eth_dev *eth_dev)
504 {
505 	int ret;
506 	const struct octeontx_nic *nic = eth_dev->data->dev_private;
507 	RTE_SET_USED(dev);
508 
509 	ret = strncmp(eth_dev->data->name, "eth_octeontx", 12);
510 	if (ret)
511 		return 0;
512 	octeontx_pki_port_stop(nic->port_id);
513 	return 0;
514 }
515 
516 static void
517 ssovf_dump(struct rte_eventdev *dev, FILE *f)
518 {
519 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
520 	uint8_t port;
521 
522 	/* Dump SSOWVF debug registers */
523 	for (port = 0; port < edev->nb_event_ports; port++)
524 		ssows_dump(dev->data->ports[port], f);
525 }
526 
527 static int
528 ssovf_start(struct rte_eventdev *dev)
529 {
530 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
531 	struct ssows *ws;
532 	uint8_t *base;
533 	uint8_t i;
534 
535 	ssovf_func_trace();
536 	for (i = 0; i < edev->nb_event_ports; i++) {
537 		ws = dev->data->ports[i];
538 		ssows_reset(ws);
539 		ws->swtag_req = 0;
540 	}
541 
542 	for (i = 0; i < edev->nb_event_queues; i++) {
543 		/* Consume all the events through HWS0 */
544 		ssows_flush_events(dev->data->ports[0], i);
545 
546 		base = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, i, 0);
547 		base += SSO_VHGRP_QCTL;
548 		ssovf_write64(1, base); /* Enable SSO group */
549 	}
550 
551 	ssovf_fastpath_fns_set(dev);
552 	return 0;
553 }
554 
555 static void
556 ssovf_stop(struct rte_eventdev *dev)
557 {
558 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
559 	struct ssows *ws;
560 	uint8_t *base;
561 	uint8_t i;
562 
563 	ssovf_func_trace();
564 	for (i = 0; i < edev->nb_event_ports; i++) {
565 		ws = dev->data->ports[i];
566 		ssows_reset(ws);
567 		ws->swtag_req = 0;
568 	}
569 
570 	for (i = 0; i < edev->nb_event_queues; i++) {
571 		/* Consume all the events through HWS0 */
572 		ssows_flush_events(dev->data->ports[0], i);
573 
574 		base = octeontx_ssovf_bar(OCTEONTX_SSO_GROUP, i, 0);
575 		base += SSO_VHGRP_QCTL;
576 		ssovf_write64(0, base); /* Disable SSO group */
577 	}
578 }
579 
580 static int
581 ssovf_close(struct rte_eventdev *dev)
582 {
583 	struct ssovf_evdev *edev = ssovf_pmd_priv(dev);
584 	uint8_t all_queues[RTE_EVENT_MAX_QUEUES_PER_DEV];
585 	uint8_t i;
586 
587 	for (i = 0; i < edev->nb_event_queues; i++)
588 		all_queues[i] = i;
589 
590 	for (i = 0; i < edev->nb_event_ports; i++)
591 		ssovf_port_unlink(dev, dev->data->ports[i], all_queues,
592 			edev->nb_event_queues);
593 	return 0;
594 }
595 
596 /* Initialize and register event driver with DPDK Application */
597 static const struct rte_eventdev_ops ssovf_ops = {
598 	.dev_infos_get    = ssovf_info_get,
599 	.dev_configure    = ssovf_configure,
600 	.queue_def_conf   = ssovf_queue_def_conf,
601 	.queue_setup      = ssovf_queue_setup,
602 	.queue_release    = ssovf_queue_release,
603 	.port_def_conf    = ssovf_port_def_conf,
604 	.port_setup       = ssovf_port_setup,
605 	.port_release     = ssovf_port_release,
606 	.port_link        = ssovf_port_link,
607 	.port_unlink      = ssovf_port_unlink,
608 	.timeout_ticks    = ssovf_timeout_ticks,
609 
610 	.eth_rx_adapter_caps_get  = ssovf_eth_rx_adapter_caps_get,
611 	.eth_rx_adapter_queue_add = ssovf_eth_rx_adapter_queue_add,
612 	.eth_rx_adapter_queue_del = ssovf_eth_rx_adapter_queue_del,
613 	.eth_rx_adapter_start = ssovf_eth_rx_adapter_start,
614 	.eth_rx_adapter_stop = ssovf_eth_rx_adapter_stop,
615 
616 	.dump             = ssovf_dump,
617 	.dev_start        = ssovf_start,
618 	.dev_stop         = ssovf_stop,
619 	.dev_close        = ssovf_close
620 };
621 
622 static int
623 ssovf_vdev_probe(struct rte_vdev_device *vdev)
624 {
625 	struct octeontx_ssovf_info oinfo;
626 	struct ssovf_mbox_dev_info info;
627 	struct ssovf_evdev *edev;
628 	struct rte_eventdev *eventdev;
629 	static int ssovf_init_once;
630 	const char *name;
631 	int ret;
632 
633 	name = rte_vdev_device_name(vdev);
634 	/* More than one instance is not supported */
635 	if (ssovf_init_once) {
636 		ssovf_log_err("Request to create >1 %s instance", name);
637 		return -EINVAL;
638 	}
639 
640 	eventdev = rte_event_pmd_vdev_init(name, sizeof(struct ssovf_evdev),
641 				rte_socket_id());
642 	if (eventdev == NULL) {
643 		ssovf_log_err("Failed to create eventdev vdev %s", name);
644 		return -ENOMEM;
645 	}
646 	eventdev->dev_ops = &ssovf_ops;
647 
648 	/* For secondary processes, the primary has done all the work */
649 	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
650 		ssovf_fastpath_fns_set(eventdev);
651 		return 0;
652 	}
653 
654 	ret = octeontx_ssovf_info(&oinfo);
655 	if (ret) {
656 		ssovf_log_err("Failed to probe and validate ssovfs %d", ret);
657 		goto error;
658 	}
659 
660 	edev = ssovf_pmd_priv(eventdev);
661 	edev->max_event_ports = oinfo.total_ssowvfs;
662 	edev->max_event_queues = oinfo.total_ssovfs;
663 	edev->is_timeout_deq = 0;
664 
665 	ret = ssovf_mbox_dev_info(&info);
666 	if (ret < 0 || ret != sizeof(struct ssovf_mbox_dev_info)) {
667 		ssovf_log_err("Failed to get mbox devinfo %d", ret);
668 		goto error;
669 	}
670 
671 	edev->min_deq_timeout_ns = info.min_deq_timeout_ns;
672 	edev->max_deq_timeout_ns = info.max_deq_timeout_ns;
673 	edev->max_num_events =  info.max_num_events;
674 	ssovf_log_dbg("min_deq_tmo=%"PRId64" max_deq_tmo=%"PRId64" max_evts=%d",
675 			info.min_deq_timeout_ns, info.max_deq_timeout_ns,
676 			info.max_num_events);
677 
678 	if (!edev->max_event_ports || !edev->max_event_queues) {
679 		ssovf_log_err("Not enough eventdev resource queues=%d ports=%d",
680 			edev->max_event_queues, edev->max_event_ports);
681 		ret = -ENODEV;
682 		goto error;
683 	}
684 
685 	ssovf_log_info("Initializing %s domain=%d max_queues=%d max_ports=%d",
686 			name, oinfo.domain, edev->max_event_queues,
687 			edev->max_event_ports);
688 
689 	ssovf_init_once = 1;
690 	return 0;
691 
692 error:
693 	rte_event_pmd_vdev_uninit(name);
694 	return ret;
695 }
696 
697 static int
698 ssovf_vdev_remove(struct rte_vdev_device *vdev)
699 {
700 	const char *name;
701 
702 	name = rte_vdev_device_name(vdev);
703 	ssovf_log_info("Closing %s", name);
704 	return rte_event_pmd_vdev_uninit(name);
705 }
706 
707 static struct rte_vdev_driver vdev_ssovf_pmd = {
708 	.probe = ssovf_vdev_probe,
709 	.remove = ssovf_vdev_remove
710 };
711 
712 RTE_PMD_REGISTER_VDEV(EVENTDEV_NAME_OCTEONTX_PMD, vdev_ssovf_pmd);
713