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