xref: /dpdk/drivers/raw/skeleton/skeleton_rawdev.c (revision 365ec3c4fe599048c67cc79817ae9dfa090753cc)
1473c88f9SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2473c88f9SBruce Richardson  * Copyright 2017 NXP
3473c88f9SBruce Richardson  */
4473c88f9SBruce Richardson 
5473c88f9SBruce Richardson #include <assert.h>
6473c88f9SBruce Richardson #include <stdio.h>
7473c88f9SBruce Richardson #include <stdbool.h>
872b452c5SDmitry Kozlyuk #include <stdlib.h>
9473c88f9SBruce Richardson #include <errno.h>
10473c88f9SBruce Richardson #include <stdint.h>
11473c88f9SBruce Richardson #include <inttypes.h>
12473c88f9SBruce Richardson #include <string.h>
13473c88f9SBruce Richardson 
14473c88f9SBruce Richardson #include <rte_byteorder.h>
15473c88f9SBruce Richardson #include <rte_common.h>
16473c88f9SBruce Richardson #include <rte_debug.h>
171acb7f54SDavid Marchand #include <dev_driver.h>
18473c88f9SBruce Richardson #include <rte_eal.h>
19473c88f9SBruce Richardson #include <rte_kvargs.h>
20473c88f9SBruce Richardson #include <rte_log.h>
21473c88f9SBruce Richardson #include <rte_malloc.h>
22473c88f9SBruce Richardson #include <rte_memory.h>
23473c88f9SBruce Richardson #include <rte_memcpy.h>
24473c88f9SBruce Richardson #include <rte_lcore.h>
254851ef2bSDavid Marchand #include <bus_vdev_driver.h>
26473c88f9SBruce Richardson 
27473c88f9SBruce Richardson #include <rte_rawdev.h>
28473c88f9SBruce Richardson #include <rte_rawdev_pmd.h>
29473c88f9SBruce Richardson 
30473c88f9SBruce Richardson #include "skeleton_rawdev.h"
31473c88f9SBruce Richardson 
32473c88f9SBruce Richardson /* Count of instances */
33473c88f9SBruce Richardson static uint16_t skeldev_init_once;
34473c88f9SBruce Richardson 
35473c88f9SBruce Richardson /**< Rawdev Skeleton dummy driver name */
36473c88f9SBruce Richardson #define SKELETON_PMD_RAWDEV_NAME rawdev_skeleton
37473c88f9SBruce Richardson 
38473c88f9SBruce Richardson struct queue_buffers {
39473c88f9SBruce Richardson 	void *bufs[SKELETON_QUEUE_MAX_DEPTH];
40473c88f9SBruce Richardson };
41473c88f9SBruce Richardson 
42473c88f9SBruce Richardson static struct queue_buffers queue_buf[SKELETON_MAX_QUEUES] = {};
43473c88f9SBruce Richardson static void clear_queue_bufs(int queue_id);
44473c88f9SBruce Richardson 
skeleton_rawdev_info_get(struct rte_rawdev * dev,rte_rawdev_obj_t dev_info,size_t dev_info_size)45f150dd88SBruce Richardson static int skeleton_rawdev_info_get(struct rte_rawdev *dev,
4610b71caeSBruce Richardson 				     rte_rawdev_obj_t dev_info,
4710b71caeSBruce Richardson 				     size_t dev_info_size)
48473c88f9SBruce Richardson {
49473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
50473c88f9SBruce Richardson 	struct skeleton_rawdev_conf *skeldev_conf;
51473c88f9SBruce Richardson 
52473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
53473c88f9SBruce Richardson 
5410b71caeSBruce Richardson 	if (!dev_info || dev_info_size != sizeof(*skeldev_conf)) {
55473c88f9SBruce Richardson 		SKELETON_PMD_ERR("Invalid request");
56f150dd88SBruce Richardson 		return -EINVAL;
57473c88f9SBruce Richardson 	}
58473c88f9SBruce Richardson 
59473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(dev);
60473c88f9SBruce Richardson 
61473c88f9SBruce Richardson 	skeldev_conf = dev_info;
62473c88f9SBruce Richardson 
63473c88f9SBruce Richardson 	skeldev_conf->num_queues = skeldev->num_queues;
64473c88f9SBruce Richardson 	skeldev_conf->capabilities = skeldev->capabilities;
65473c88f9SBruce Richardson 	skeldev_conf->device_state = skeldev->device_state;
66473c88f9SBruce Richardson 	skeldev_conf->firmware_state = skeldev->fw.firmware_state;
67f150dd88SBruce Richardson 
68f150dd88SBruce Richardson 	return 0;
69473c88f9SBruce Richardson }
70473c88f9SBruce Richardson 
skeleton_rawdev_configure(const struct rte_rawdev * dev,rte_rawdev_obj_t config,size_t config_size)71473c88f9SBruce Richardson static int skeleton_rawdev_configure(const struct rte_rawdev *dev,
728db9dce7SBruce Richardson 				     rte_rawdev_obj_t config,
738db9dce7SBruce Richardson 				     size_t config_size)
74473c88f9SBruce Richardson {
75473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
76473c88f9SBruce Richardson 	struct skeleton_rawdev_conf *skeldev_conf;
77473c88f9SBruce Richardson 
78473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
79473c88f9SBruce Richardson 
808f1d23ecSDavid Marchand 	if (dev == NULL)
818f1d23ecSDavid Marchand 		return -EINVAL;
82473c88f9SBruce Richardson 
838db9dce7SBruce Richardson 	if (config == NULL || config_size != sizeof(*skeldev_conf)) {
84473c88f9SBruce Richardson 		SKELETON_PMD_ERR("Invalid configuration");
85473c88f9SBruce Richardson 		return -EINVAL;
86473c88f9SBruce Richardson 	}
87473c88f9SBruce Richardson 
88473c88f9SBruce Richardson 	skeldev_conf = config;
89473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(dev);
90473c88f9SBruce Richardson 
91473c88f9SBruce Richardson 	if (skeldev_conf->num_queues <= SKELETON_MAX_QUEUES)
92473c88f9SBruce Richardson 		skeldev->num_queues = skeldev_conf->num_queues;
93473c88f9SBruce Richardson 	else
94473c88f9SBruce Richardson 		return -EINVAL;
95473c88f9SBruce Richardson 
96473c88f9SBruce Richardson 	skeldev->capabilities = skeldev_conf->capabilities;
97473c88f9SBruce Richardson 	skeldev->num_queues = skeldev_conf->num_queues;
98473c88f9SBruce Richardson 
99473c88f9SBruce Richardson 	return 0;
100473c88f9SBruce Richardson }
101473c88f9SBruce Richardson 
skeleton_rawdev_start(struct rte_rawdev * dev)102473c88f9SBruce Richardson static int skeleton_rawdev_start(struct rte_rawdev *dev)
103473c88f9SBruce Richardson {
104473c88f9SBruce Richardson 	int ret = 0;
105473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
106473c88f9SBruce Richardson 	enum skeleton_firmware_state fw_state;
107473c88f9SBruce Richardson 	enum skeleton_device_state device_state;
108473c88f9SBruce Richardson 
109473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
110473c88f9SBruce Richardson 
1118f1d23ecSDavid Marchand 	if (dev == NULL)
1128f1d23ecSDavid Marchand 		return -EINVAL;
113473c88f9SBruce Richardson 
114473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(dev);
115473c88f9SBruce Richardson 
116473c88f9SBruce Richardson 	fw_state = skeldev->fw.firmware_state;
117473c88f9SBruce Richardson 	device_state = skeldev->device_state;
118473c88f9SBruce Richardson 
119473c88f9SBruce Richardson 	if (fw_state == SKELETON_FW_LOADED &&
120473c88f9SBruce Richardson 		device_state == SKELETON_DEV_STOPPED) {
121473c88f9SBruce Richardson 		skeldev->device_state = SKELETON_DEV_RUNNING;
122473c88f9SBruce Richardson 	} else {
123473c88f9SBruce Richardson 		SKELETON_PMD_ERR("Device not ready for starting");
124473c88f9SBruce Richardson 		ret = -EINVAL;
125473c88f9SBruce Richardson 	}
126473c88f9SBruce Richardson 
127473c88f9SBruce Richardson 	return ret;
128473c88f9SBruce Richardson }
129473c88f9SBruce Richardson 
skeleton_rawdev_stop(struct rte_rawdev * dev)130473c88f9SBruce Richardson static void skeleton_rawdev_stop(struct rte_rawdev *dev)
131473c88f9SBruce Richardson {
132473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
133473c88f9SBruce Richardson 
134473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
135473c88f9SBruce Richardson 
136473c88f9SBruce Richardson 	if (dev) {
137473c88f9SBruce Richardson 		skeldev = skeleton_rawdev_get_priv(dev);
138473c88f9SBruce Richardson 		skeldev->device_state = SKELETON_DEV_STOPPED;
139473c88f9SBruce Richardson 	}
140473c88f9SBruce Richardson }
141473c88f9SBruce Richardson 
142473c88f9SBruce Richardson static void
reset_queues(struct skeleton_rawdev * skeldev)143473c88f9SBruce Richardson reset_queues(struct skeleton_rawdev *skeldev)
144473c88f9SBruce Richardson {
145473c88f9SBruce Richardson 	int i;
146473c88f9SBruce Richardson 
147473c88f9SBruce Richardson 	for (i = 0; i < SKELETON_MAX_QUEUES; i++) {
148473c88f9SBruce Richardson 		skeldev->queues[i].depth = SKELETON_QUEUE_DEF_DEPTH;
149473c88f9SBruce Richardson 		skeldev->queues[i].state = SKELETON_QUEUE_DETACH;
150473c88f9SBruce Richardson 	}
151473c88f9SBruce Richardson }
152473c88f9SBruce Richardson 
153473c88f9SBruce Richardson static void
reset_attribute_table(struct skeleton_rawdev * skeldev)154473c88f9SBruce Richardson reset_attribute_table(struct skeleton_rawdev *skeldev)
155473c88f9SBruce Richardson {
156473c88f9SBruce Richardson 	int i;
157473c88f9SBruce Richardson 
158473c88f9SBruce Richardson 	for (i = 0; i < SKELETON_MAX_ATTRIBUTES; i++) {
159473c88f9SBruce Richardson 		if (skeldev->attr[i].name) {
160473c88f9SBruce Richardson 			free(skeldev->attr[i].name);
161473c88f9SBruce Richardson 			skeldev->attr[i].name = NULL;
162473c88f9SBruce Richardson 		}
163473c88f9SBruce Richardson 	}
164473c88f9SBruce Richardson }
165473c88f9SBruce Richardson 
skeleton_rawdev_close(struct rte_rawdev * dev)166473c88f9SBruce Richardson static int skeleton_rawdev_close(struct rte_rawdev *dev)
167473c88f9SBruce Richardson {
168473c88f9SBruce Richardson 	int ret = 0, i;
169473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
170473c88f9SBruce Richardson 	enum skeleton_firmware_state fw_state;
171473c88f9SBruce Richardson 	enum skeleton_device_state device_state;
172473c88f9SBruce Richardson 
173473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
174473c88f9SBruce Richardson 
1758f1d23ecSDavid Marchand 	if (dev == NULL)
1768f1d23ecSDavid Marchand 		return -EINVAL;
177473c88f9SBruce Richardson 
178473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(dev);
179473c88f9SBruce Richardson 
180473c88f9SBruce Richardson 	fw_state = skeldev->fw.firmware_state;
181473c88f9SBruce Richardson 	device_state = skeldev->device_state;
182473c88f9SBruce Richardson 
183473c88f9SBruce Richardson 	reset_queues(skeldev);
184473c88f9SBruce Richardson 	reset_attribute_table(skeldev);
185473c88f9SBruce Richardson 
186473c88f9SBruce Richardson 	switch (fw_state) {
187473c88f9SBruce Richardson 	case SKELETON_FW_LOADED:
188473c88f9SBruce Richardson 		if (device_state == SKELETON_DEV_RUNNING) {
189473c88f9SBruce Richardson 			SKELETON_PMD_ERR("Cannot close running device");
190473c88f9SBruce Richardson 			ret = -EINVAL;
191473c88f9SBruce Richardson 		} else {
192473c88f9SBruce Richardson 			/* Probably call fw reset here */
193473c88f9SBruce Richardson 			skeldev->fw.firmware_state = SKELETON_FW_READY;
194473c88f9SBruce Richardson 		}
195473c88f9SBruce Richardson 		break;
196473c88f9SBruce Richardson 	case SKELETON_FW_READY:
197e640362bSLukasz Wojciechowski 		SKELETON_PMD_DEBUG("Device already in stopped state");
198e640362bSLukasz Wojciechowski 		break;
199473c88f9SBruce Richardson 	case SKELETON_FW_ERROR:
200473c88f9SBruce Richardson 	default:
201e640362bSLukasz Wojciechowski 		SKELETON_PMD_DEBUG("Device in impossible state");
202473c88f9SBruce Richardson 		ret = -EINVAL;
203473c88f9SBruce Richardson 		break;
204473c88f9SBruce Richardson 	}
205473c88f9SBruce Richardson 
206473c88f9SBruce Richardson 	/* Clear all allocated queues */
207473c88f9SBruce Richardson 	for (i = 0; i < SKELETON_MAX_QUEUES; i++)
208473c88f9SBruce Richardson 		clear_queue_bufs(i);
209473c88f9SBruce Richardson 
210473c88f9SBruce Richardson 	return ret;
211473c88f9SBruce Richardson }
212473c88f9SBruce Richardson 
skeleton_rawdev_reset(struct rte_rawdev * dev)213473c88f9SBruce Richardson static int skeleton_rawdev_reset(struct rte_rawdev *dev)
214473c88f9SBruce Richardson {
215473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
216473c88f9SBruce Richardson 
217473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
218473c88f9SBruce Richardson 
2198f1d23ecSDavid Marchand 	if (dev == NULL)
2208f1d23ecSDavid Marchand 		return -EINVAL;
221473c88f9SBruce Richardson 
222473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(dev);
223473c88f9SBruce Richardson 
224473c88f9SBruce Richardson 	SKELETON_PMD_DEBUG("Resetting device");
225473c88f9SBruce Richardson 	skeldev->fw.firmware_state = SKELETON_FW_READY;
226473c88f9SBruce Richardson 
227473c88f9SBruce Richardson 	return 0;
228473c88f9SBruce Richardson }
229473c88f9SBruce Richardson 
skeleton_rawdev_queue_def_conf(struct rte_rawdev * dev,uint16_t queue_id,rte_rawdev_obj_t queue_conf,size_t conf_size)23013f8e4a2SBruce Richardson static int skeleton_rawdev_queue_def_conf(struct rte_rawdev *dev,
231473c88f9SBruce Richardson 					  uint16_t queue_id,
232f574ed81SBruce Richardson 					  rte_rawdev_obj_t queue_conf,
233f574ed81SBruce Richardson 					  size_t conf_size)
234473c88f9SBruce Richardson {
235473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
236473c88f9SBruce Richardson 	struct skeleton_rawdev_queue *skelq;
237473c88f9SBruce Richardson 
238473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
239473c88f9SBruce Richardson 
240f574ed81SBruce Richardson 	if (!dev || !queue_conf ||
241f574ed81SBruce Richardson 			conf_size != sizeof(struct skeleton_rawdev_queue))
24213f8e4a2SBruce Richardson 		return -EINVAL;
243473c88f9SBruce Richardson 
244473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(dev);
245473c88f9SBruce Richardson 	skelq = &skeldev->queues[queue_id];
246473c88f9SBruce Richardson 
247473c88f9SBruce Richardson 	if (queue_id < SKELETON_MAX_QUEUES)
248473c88f9SBruce Richardson 		rte_memcpy(queue_conf, skelq,
249473c88f9SBruce Richardson 			sizeof(struct skeleton_rawdev_queue));
25013f8e4a2SBruce Richardson 
25113f8e4a2SBruce Richardson 	return 0;
252473c88f9SBruce Richardson }
253473c88f9SBruce Richardson 
254473c88f9SBruce Richardson static void
clear_queue_bufs(int queue_id)255473c88f9SBruce Richardson clear_queue_bufs(int queue_id)
256473c88f9SBruce Richardson {
257473c88f9SBruce Richardson 	int i;
258473c88f9SBruce Richardson 
259473c88f9SBruce Richardson 	/* Clear buffers for queue_id */
260473c88f9SBruce Richardson 	for (i = 0; i < SKELETON_QUEUE_MAX_DEPTH; i++)
261473c88f9SBruce Richardson 		queue_buf[queue_id].bufs[i] = NULL;
262473c88f9SBruce Richardson }
263473c88f9SBruce Richardson 
skeleton_rawdev_queue_setup(struct rte_rawdev * dev,uint16_t queue_id,rte_rawdev_obj_t queue_conf,size_t conf_size)264473c88f9SBruce Richardson static int skeleton_rawdev_queue_setup(struct rte_rawdev *dev,
265473c88f9SBruce Richardson 				       uint16_t queue_id,
266f574ed81SBruce Richardson 				       rte_rawdev_obj_t queue_conf,
267f574ed81SBruce Richardson 				       size_t conf_size)
268473c88f9SBruce Richardson {
269473c88f9SBruce Richardson 	int ret = 0;
270473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
271473c88f9SBruce Richardson 	struct skeleton_rawdev_queue *q;
272473c88f9SBruce Richardson 
273473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
274473c88f9SBruce Richardson 
275f574ed81SBruce Richardson 	if (!dev || !queue_conf ||
276f574ed81SBruce Richardson 			conf_size != sizeof(struct skeleton_rawdev_queue))
277473c88f9SBruce Richardson 		return -EINVAL;
278473c88f9SBruce Richardson 
279473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(dev);
280473c88f9SBruce Richardson 	q = &skeldev->queues[queue_id];
281473c88f9SBruce Richardson 
282473c88f9SBruce Richardson 	if (skeldev->num_queues > queue_id &&
283473c88f9SBruce Richardson 	    q->depth < SKELETON_QUEUE_MAX_DEPTH) {
284473c88f9SBruce Richardson 		rte_memcpy(q, queue_conf,
285473c88f9SBruce Richardson 			   sizeof(struct skeleton_rawdev_queue));
286473c88f9SBruce Richardson 		clear_queue_bufs(queue_id);
287473c88f9SBruce Richardson 	} else {
288473c88f9SBruce Richardson 		SKELETON_PMD_ERR("Invalid queue configuration");
289473c88f9SBruce Richardson 		ret = -EINVAL;
290473c88f9SBruce Richardson 	}
291473c88f9SBruce Richardson 
292473c88f9SBruce Richardson 	return ret;
293473c88f9SBruce Richardson }
294473c88f9SBruce Richardson 
skeleton_rawdev_queue_release(struct rte_rawdev * dev,uint16_t queue_id)295473c88f9SBruce Richardson static int skeleton_rawdev_queue_release(struct rte_rawdev *dev,
296473c88f9SBruce Richardson 					 uint16_t queue_id)
297473c88f9SBruce Richardson {
298473c88f9SBruce Richardson 	int ret = 0;
299473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
300473c88f9SBruce Richardson 
301473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
302473c88f9SBruce Richardson 
3038f1d23ecSDavid Marchand 	if (dev == NULL)
3048f1d23ecSDavid Marchand 		return -EINVAL;
305473c88f9SBruce Richardson 
306473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(dev);
307473c88f9SBruce Richardson 
308473c88f9SBruce Richardson 	if (skeldev->num_queues > queue_id) {
309473c88f9SBruce Richardson 		skeldev->queues[queue_id].state = SKELETON_QUEUE_DETACH;
310473c88f9SBruce Richardson 		skeldev->queues[queue_id].depth = SKELETON_QUEUE_DEF_DEPTH;
311473c88f9SBruce Richardson 		clear_queue_bufs(queue_id);
312473c88f9SBruce Richardson 	} else {
313473c88f9SBruce Richardson 		SKELETON_PMD_ERR("Invalid queue configuration");
314473c88f9SBruce Richardson 		ret = -EINVAL;
315473c88f9SBruce Richardson 	}
316473c88f9SBruce Richardson 
317473c88f9SBruce Richardson 	return ret;
318473c88f9SBruce Richardson }
319473c88f9SBruce Richardson 
skeleton_rawdev_queue_count(struct rte_rawdev * dev)320473c88f9SBruce Richardson static uint16_t skeleton_rawdev_queue_count(struct rte_rawdev *dev)
321473c88f9SBruce Richardson {
322473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
323473c88f9SBruce Richardson 
324473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
325473c88f9SBruce Richardson 
3268f1d23ecSDavid Marchand 	if (dev == NULL)
3278f1d23ecSDavid Marchand 		return -EINVAL;
328473c88f9SBruce Richardson 
329473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(dev);
330473c88f9SBruce Richardson 	return skeldev->num_queues;
331473c88f9SBruce Richardson }
332473c88f9SBruce Richardson 
skeleton_rawdev_get_attr(struct rte_rawdev * dev,const char * attr_name,uint64_t * attr_value)333473c88f9SBruce Richardson static int skeleton_rawdev_get_attr(struct rte_rawdev *dev,
334473c88f9SBruce Richardson 				    const char *attr_name,
335473c88f9SBruce Richardson 				    uint64_t *attr_value)
336473c88f9SBruce Richardson {
337473c88f9SBruce Richardson 	int i;
338473c88f9SBruce Richardson 	uint8_t done = 0;
339473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
340473c88f9SBruce Richardson 
341473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
342473c88f9SBruce Richardson 
343473c88f9SBruce Richardson 	if (!dev || !attr_name || !attr_value) {
344473c88f9SBruce Richardson 		SKELETON_PMD_ERR("Invalid arguments for getting attributes");
345473c88f9SBruce Richardson 		return -EINVAL;
346473c88f9SBruce Richardson 	}
347473c88f9SBruce Richardson 
348473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(dev);
349473c88f9SBruce Richardson 
350473c88f9SBruce Richardson 	for (i = 0; i < SKELETON_MAX_ATTRIBUTES; i++) {
351473c88f9SBruce Richardson 		if (!skeldev->attr[i].name)
352473c88f9SBruce Richardson 			continue;
353473c88f9SBruce Richardson 
354473c88f9SBruce Richardson 		if (!strncmp(skeldev->attr[i].name, attr_name,
355473c88f9SBruce Richardson 			    SKELETON_ATTRIBUTE_NAME_MAX)) {
356473c88f9SBruce Richardson 			*attr_value = skeldev->attr[i].value;
357473c88f9SBruce Richardson 			done = 1;
358473c88f9SBruce Richardson 			SKELETON_PMD_DEBUG("Attribute (%s) Value (%" PRIu64 ")",
359473c88f9SBruce Richardson 					   attr_name, *attr_value);
360473c88f9SBruce Richardson 			break;
361473c88f9SBruce Richardson 		}
362473c88f9SBruce Richardson 	}
363473c88f9SBruce Richardson 
364473c88f9SBruce Richardson 	if (done)
365473c88f9SBruce Richardson 		return 0;
366473c88f9SBruce Richardson 
367473c88f9SBruce Richardson 	/* Attribute not found */
368473c88f9SBruce Richardson 	return -EINVAL;
369473c88f9SBruce Richardson }
370473c88f9SBruce Richardson 
skeleton_rawdev_set_attr(struct rte_rawdev * dev,const char * attr_name,const uint64_t attr_value)371473c88f9SBruce Richardson static int skeleton_rawdev_set_attr(struct rte_rawdev *dev,
372473c88f9SBruce Richardson 				     const char *attr_name,
373473c88f9SBruce Richardson 				     const uint64_t attr_value)
374473c88f9SBruce Richardson {
375473c88f9SBruce Richardson 	int i;
376473c88f9SBruce Richardson 	uint8_t done = 0;
377473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
378473c88f9SBruce Richardson 
379473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
380473c88f9SBruce Richardson 
381473c88f9SBruce Richardson 	if (!dev || !attr_name) {
382473c88f9SBruce Richardson 		SKELETON_PMD_ERR("Invalid arguments for setting attributes");
383473c88f9SBruce Richardson 		return -EINVAL;
384473c88f9SBruce Richardson 	}
385473c88f9SBruce Richardson 
386473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(dev);
387473c88f9SBruce Richardson 
388473c88f9SBruce Richardson 	/* Check if attribute already exists */
389473c88f9SBruce Richardson 	for (i = 0; i < SKELETON_MAX_ATTRIBUTES; i++) {
390473c88f9SBruce Richardson 		if (!skeldev->attr[i].name)
391473c88f9SBruce Richardson 			break;
392473c88f9SBruce Richardson 
393473c88f9SBruce Richardson 		if (!strncmp(skeldev->attr[i].name, attr_name,
394473c88f9SBruce Richardson 			     SKELETON_ATTRIBUTE_NAME_MAX)) {
395473c88f9SBruce Richardson 			/* Update value */
396473c88f9SBruce Richardson 			skeldev->attr[i].value = attr_value;
397473c88f9SBruce Richardson 			done = 1;
398473c88f9SBruce Richardson 			break;
399473c88f9SBruce Richardson 		}
400473c88f9SBruce Richardson 	}
401473c88f9SBruce Richardson 
402473c88f9SBruce Richardson 	if (!done) {
403473c88f9SBruce Richardson 		if (i < (SKELETON_MAX_ATTRIBUTES - 1)) {
404473c88f9SBruce Richardson 			/* There is still space to insert one more */
405473c88f9SBruce Richardson 			skeldev->attr[i].name = strdup(attr_name);
406473c88f9SBruce Richardson 			if (!skeldev->attr[i].name)
407473c88f9SBruce Richardson 				return -ENOMEM;
408473c88f9SBruce Richardson 
409473c88f9SBruce Richardson 			skeldev->attr[i].value = attr_value;
410473c88f9SBruce Richardson 			return 0;
411473c88f9SBruce Richardson 		}
412473c88f9SBruce Richardson 	}
413473c88f9SBruce Richardson 
414473c88f9SBruce Richardson 	return -EINVAL;
415473c88f9SBruce Richardson }
416473c88f9SBruce Richardson 
skeleton_rawdev_enqueue_bufs(struct rte_rawdev * dev,struct rte_rawdev_buf ** buffers,unsigned int count,rte_rawdev_obj_t context)417473c88f9SBruce Richardson static int skeleton_rawdev_enqueue_bufs(struct rte_rawdev *dev,
418473c88f9SBruce Richardson 					struct rte_rawdev_buf **buffers,
419473c88f9SBruce Richardson 					unsigned int count,
420473c88f9SBruce Richardson 					rte_rawdev_obj_t context)
421473c88f9SBruce Richardson {
422473c88f9SBruce Richardson 	unsigned int i;
423473c88f9SBruce Richardson 	uint16_t q_id;
424473c88f9SBruce Richardson 	RTE_SET_USED(dev);
425473c88f9SBruce Richardson 
426473c88f9SBruce Richardson 	/* context is essentially the queue_id which is
427473c88f9SBruce Richardson 	 * transferred as opaque object through the library layer. This can
428473c88f9SBruce Richardson 	 * help in complex implementation which require more information than
429473c88f9SBruce Richardson 	 * just an integer - for example, a queue-pair.
430473c88f9SBruce Richardson 	 */
431*365ec3c4SDavid Marchand 	q_id = *((uint16_t *)context);
432473c88f9SBruce Richardson 
433473c88f9SBruce Richardson 	for (i = 0; i < count; i++)
434473c88f9SBruce Richardson 		queue_buf[q_id].bufs[i] = buffers[i]->buf_addr;
435473c88f9SBruce Richardson 
436473c88f9SBruce Richardson 	return i;
437473c88f9SBruce Richardson }
438473c88f9SBruce Richardson 
skeleton_rawdev_dequeue_bufs(struct rte_rawdev * dev,struct rte_rawdev_buf ** buffers,unsigned int count,rte_rawdev_obj_t context)439473c88f9SBruce Richardson static int skeleton_rawdev_dequeue_bufs(struct rte_rawdev *dev,
440473c88f9SBruce Richardson 					struct rte_rawdev_buf **buffers,
441473c88f9SBruce Richardson 					unsigned int count,
442473c88f9SBruce Richardson 					rte_rawdev_obj_t context)
443473c88f9SBruce Richardson {
444473c88f9SBruce Richardson 	unsigned int i;
445473c88f9SBruce Richardson 	uint16_t q_id;
446473c88f9SBruce Richardson 	RTE_SET_USED(dev);
447473c88f9SBruce Richardson 
448473c88f9SBruce Richardson 	/* context is essentially the queue_id which is
449473c88f9SBruce Richardson 	 * transferred as opaque object through the library layer. This can
450473c88f9SBruce Richardson 	 * help in complex implementation which require more information than
451473c88f9SBruce Richardson 	 * just an integer - for example, a queue-pair.
452473c88f9SBruce Richardson 	 */
453*365ec3c4SDavid Marchand 	q_id = *((uint16_t *)context);
454473c88f9SBruce Richardson 
455473c88f9SBruce Richardson 	for (i = 0; i < count; i++)
456473c88f9SBruce Richardson 		buffers[i]->buf_addr = queue_buf[q_id].bufs[i];
457473c88f9SBruce Richardson 
458473c88f9SBruce Richardson 	return i;
459473c88f9SBruce Richardson }
460473c88f9SBruce Richardson 
skeleton_rawdev_dump(struct rte_rawdev * dev,FILE * f)461473c88f9SBruce Richardson static int skeleton_rawdev_dump(struct rte_rawdev *dev, FILE *f)
462473c88f9SBruce Richardson {
463473c88f9SBruce Richardson 	RTE_SET_USED(dev);
464473c88f9SBruce Richardson 	RTE_SET_USED(f);
465473c88f9SBruce Richardson 
466473c88f9SBruce Richardson 	return 0;
467473c88f9SBruce Richardson }
468473c88f9SBruce Richardson 
skeleton_rawdev_firmware_status_get(struct rte_rawdev * dev,rte_rawdev_obj_t status_info)469473c88f9SBruce Richardson static int skeleton_rawdev_firmware_status_get(struct rte_rawdev *dev,
470473c88f9SBruce Richardson 					       rte_rawdev_obj_t status_info)
471473c88f9SBruce Richardson {
472473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
473473c88f9SBruce Richardson 
474473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
475473c88f9SBruce Richardson 
476473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(dev);
477473c88f9SBruce Richardson 
478473c88f9SBruce Richardson 	if (status_info)
479473c88f9SBruce Richardson 		memcpy(status_info, &skeldev->fw.firmware_state,
480473c88f9SBruce Richardson 			sizeof(enum skeleton_firmware_state));
481473c88f9SBruce Richardson 
482473c88f9SBruce Richardson 	return 0;
483473c88f9SBruce Richardson }
484473c88f9SBruce Richardson 
485473c88f9SBruce Richardson 
skeleton_rawdev_firmware_version_get(struct rte_rawdev * dev,rte_rawdev_obj_t version_info)486473c88f9SBruce Richardson static int skeleton_rawdev_firmware_version_get(
487473c88f9SBruce Richardson 					struct rte_rawdev *dev,
488473c88f9SBruce Richardson 					rte_rawdev_obj_t version_info)
489473c88f9SBruce Richardson {
490473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
491473c88f9SBruce Richardson 	struct skeleton_firmware_version_info *vi;
492473c88f9SBruce Richardson 
493473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
494473c88f9SBruce Richardson 
495473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(dev);
496473c88f9SBruce Richardson 	vi = version_info;
497473c88f9SBruce Richardson 
498473c88f9SBruce Richardson 	vi->major = skeldev->fw.firmware_version.major;
499473c88f9SBruce Richardson 	vi->minor = skeldev->fw.firmware_version.minor;
500473c88f9SBruce Richardson 	vi->subrel = skeldev->fw.firmware_version.subrel;
501473c88f9SBruce Richardson 
502473c88f9SBruce Richardson 	return 0;
503473c88f9SBruce Richardson }
504473c88f9SBruce Richardson 
skeleton_rawdev_firmware_load(struct rte_rawdev * dev,rte_rawdev_obj_t firmware_buf)505473c88f9SBruce Richardson static int skeleton_rawdev_firmware_load(struct rte_rawdev *dev,
506473c88f9SBruce Richardson 					 rte_rawdev_obj_t firmware_buf)
507473c88f9SBruce Richardson {
508473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
509473c88f9SBruce Richardson 
510473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
511473c88f9SBruce Richardson 
512473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(dev);
513473c88f9SBruce Richardson 
514473c88f9SBruce Richardson 	/* firmware_buf is a mmaped, possibly DMA'able area, buffer. Being
515473c88f9SBruce Richardson 	 * dummy, all this does is check if firmware_buf is not NULL and
516473c88f9SBruce Richardson 	 * sets the state of the firmware.
517473c88f9SBruce Richardson 	 */
518473c88f9SBruce Richardson 	if (!firmware_buf)
519473c88f9SBruce Richardson 		return -EINVAL;
520473c88f9SBruce Richardson 
521473c88f9SBruce Richardson 	skeldev->fw.firmware_state = SKELETON_FW_LOADED;
522473c88f9SBruce Richardson 
523473c88f9SBruce Richardson 	return 0;
524473c88f9SBruce Richardson }
525473c88f9SBruce Richardson 
skeleton_rawdev_firmware_unload(struct rte_rawdev * dev)526473c88f9SBruce Richardson static int skeleton_rawdev_firmware_unload(struct rte_rawdev *dev)
527473c88f9SBruce Richardson {
528473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev;
529473c88f9SBruce Richardson 
530473c88f9SBruce Richardson 	SKELETON_PMD_FUNC_TRACE();
531473c88f9SBruce Richardson 
532473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(dev);
533473c88f9SBruce Richardson 
534473c88f9SBruce Richardson 	skeldev->fw.firmware_state = SKELETON_FW_READY;
535473c88f9SBruce Richardson 
536473c88f9SBruce Richardson 	return 0;
537473c88f9SBruce Richardson }
538473c88f9SBruce Richardson 
539473c88f9SBruce Richardson static const struct rte_rawdev_ops skeleton_rawdev_ops = {
540473c88f9SBruce Richardson 	.dev_info_get = skeleton_rawdev_info_get,
541473c88f9SBruce Richardson 	.dev_configure = skeleton_rawdev_configure,
542473c88f9SBruce Richardson 	.dev_start = skeleton_rawdev_start,
543473c88f9SBruce Richardson 	.dev_stop = skeleton_rawdev_stop,
544473c88f9SBruce Richardson 	.dev_close = skeleton_rawdev_close,
545473c88f9SBruce Richardson 	.dev_reset = skeleton_rawdev_reset,
546473c88f9SBruce Richardson 
547473c88f9SBruce Richardson 	.queue_def_conf = skeleton_rawdev_queue_def_conf,
548473c88f9SBruce Richardson 	.queue_setup = skeleton_rawdev_queue_setup,
549473c88f9SBruce Richardson 	.queue_release = skeleton_rawdev_queue_release,
550473c88f9SBruce Richardson 	.queue_count = skeleton_rawdev_queue_count,
551473c88f9SBruce Richardson 
552473c88f9SBruce Richardson 	.attr_get = skeleton_rawdev_get_attr,
553473c88f9SBruce Richardson 	.attr_set = skeleton_rawdev_set_attr,
554473c88f9SBruce Richardson 
555473c88f9SBruce Richardson 	.enqueue_bufs = skeleton_rawdev_enqueue_bufs,
556473c88f9SBruce Richardson 	.dequeue_bufs = skeleton_rawdev_dequeue_bufs,
557473c88f9SBruce Richardson 
558473c88f9SBruce Richardson 	.dump = skeleton_rawdev_dump,
559473c88f9SBruce Richardson 
560473c88f9SBruce Richardson 	.xstats_get = NULL,
561473c88f9SBruce Richardson 	.xstats_get_names = NULL,
562473c88f9SBruce Richardson 	.xstats_get_by_name = NULL,
563473c88f9SBruce Richardson 	.xstats_reset = NULL,
564473c88f9SBruce Richardson 
565473c88f9SBruce Richardson 	.firmware_status_get = skeleton_rawdev_firmware_status_get,
566473c88f9SBruce Richardson 	.firmware_version_get = skeleton_rawdev_firmware_version_get,
567473c88f9SBruce Richardson 	.firmware_load = skeleton_rawdev_firmware_load,
568473c88f9SBruce Richardson 	.firmware_unload = skeleton_rawdev_firmware_unload,
569473c88f9SBruce Richardson 
570473c88f9SBruce Richardson 	.dev_selftest = test_rawdev_skeldev,
571473c88f9SBruce Richardson };
572473c88f9SBruce Richardson 
573473c88f9SBruce Richardson static int
skeleton_rawdev_create(const char * name,struct rte_vdev_device * vdev,int socket_id)574473c88f9SBruce Richardson skeleton_rawdev_create(const char *name,
575473c88f9SBruce Richardson 		       struct rte_vdev_device *vdev,
576473c88f9SBruce Richardson 		       int socket_id)
577473c88f9SBruce Richardson {
578473c88f9SBruce Richardson 	int ret = 0, i;
579473c88f9SBruce Richardson 	struct rte_rawdev *rawdev = NULL;
580473c88f9SBruce Richardson 	struct skeleton_rawdev *skeldev = NULL;
581473c88f9SBruce Richardson 
582473c88f9SBruce Richardson 	if (!name) {
583473c88f9SBruce Richardson 		SKELETON_PMD_ERR("Invalid name of the device!");
584473c88f9SBruce Richardson 		ret = -EINVAL;
585473c88f9SBruce Richardson 		goto cleanup;
586473c88f9SBruce Richardson 	}
587473c88f9SBruce Richardson 
588473c88f9SBruce Richardson 	/* Allocate device structure */
589473c88f9SBruce Richardson 	rawdev = rte_rawdev_pmd_allocate(name, sizeof(struct skeleton_rawdev),
590473c88f9SBruce Richardson 					 socket_id);
591473c88f9SBruce Richardson 	if (rawdev == NULL) {
592473c88f9SBruce Richardson 		SKELETON_PMD_ERR("Unable to allocate rawdevice");
593473c88f9SBruce Richardson 		ret = -EINVAL;
594473c88f9SBruce Richardson 		goto cleanup;
595473c88f9SBruce Richardson 	}
596473c88f9SBruce Richardson 
597473c88f9SBruce Richardson 	ret = rawdev->dev_id; /* return the rawdev id of new device */
598473c88f9SBruce Richardson 
599473c88f9SBruce Richardson 	rawdev->dev_ops = &skeleton_rawdev_ops;
600473c88f9SBruce Richardson 	rawdev->device = &vdev->device;
601473c88f9SBruce Richardson 
602473c88f9SBruce Richardson 	skeldev = skeleton_rawdev_get_priv(rawdev);
603473c88f9SBruce Richardson 
604473c88f9SBruce Richardson 	skeldev->device_id = SKELETON_DEVICE_ID;
605473c88f9SBruce Richardson 	skeldev->vendor_id = SKELETON_VENDOR_ID;
606473c88f9SBruce Richardson 	skeldev->capabilities = SKELETON_DEFAULT_CAPA;
607473c88f9SBruce Richardson 
608473c88f9SBruce Richardson 	memset(&skeldev->fw, 0, sizeof(struct skeleton_firmware));
609473c88f9SBruce Richardson 
610473c88f9SBruce Richardson 	skeldev->fw.firmware_state = SKELETON_FW_READY;
611473c88f9SBruce Richardson 	skeldev->fw.firmware_version.major = SKELETON_MAJOR_VER;
612473c88f9SBruce Richardson 	skeldev->fw.firmware_version.minor = SKELETON_MINOR_VER;
613473c88f9SBruce Richardson 	skeldev->fw.firmware_version.subrel = SKELETON_SUB_VER;
614473c88f9SBruce Richardson 
615473c88f9SBruce Richardson 	skeldev->device_state = SKELETON_DEV_STOPPED;
616473c88f9SBruce Richardson 
617473c88f9SBruce Richardson 	/* Reset/set to default queue configuration for this device */
618473c88f9SBruce Richardson 	for (i = 0; i < SKELETON_MAX_QUEUES; i++) {
619473c88f9SBruce Richardson 		skeldev->queues[i].state = SKELETON_QUEUE_DETACH;
620473c88f9SBruce Richardson 		skeldev->queues[i].depth = SKELETON_QUEUE_DEF_DEPTH;
621473c88f9SBruce Richardson 	}
622473c88f9SBruce Richardson 
623473c88f9SBruce Richardson 	/* Clear all allocated queue buffers */
624473c88f9SBruce Richardson 	for (i = 0; i < SKELETON_MAX_QUEUES; i++)
625473c88f9SBruce Richardson 		clear_queue_bufs(i);
626473c88f9SBruce Richardson 
627473c88f9SBruce Richardson 	return ret;
628473c88f9SBruce Richardson 
629473c88f9SBruce Richardson cleanup:
630473c88f9SBruce Richardson 	if (rawdev)
631473c88f9SBruce Richardson 		rte_rawdev_pmd_release(rawdev);
632473c88f9SBruce Richardson 
633473c88f9SBruce Richardson 	return ret;
634473c88f9SBruce Richardson }
635473c88f9SBruce Richardson 
636473c88f9SBruce Richardson static int
skeleton_rawdev_destroy(const char * name)637473c88f9SBruce Richardson skeleton_rawdev_destroy(const char *name)
638473c88f9SBruce Richardson {
639473c88f9SBruce Richardson 	int ret;
640473c88f9SBruce Richardson 	struct rte_rawdev *rdev;
641473c88f9SBruce Richardson 
642473c88f9SBruce Richardson 	if (!name) {
643473c88f9SBruce Richardson 		SKELETON_PMD_ERR("Invalid device name");
644473c88f9SBruce Richardson 		return -EINVAL;
645473c88f9SBruce Richardson 	}
646473c88f9SBruce Richardson 
647473c88f9SBruce Richardson 	rdev = rte_rawdev_pmd_get_named_dev(name);
648473c88f9SBruce Richardson 	if (!rdev) {
649473c88f9SBruce Richardson 		SKELETON_PMD_ERR("Invalid device name (%s)", name);
650473c88f9SBruce Richardson 		return -EINVAL;
651473c88f9SBruce Richardson 	}
652473c88f9SBruce Richardson 
653473c88f9SBruce Richardson 	/* rte_rawdev_close is called by pmd_release */
654473c88f9SBruce Richardson 	ret = rte_rawdev_pmd_release(rdev);
655473c88f9SBruce Richardson 	if (ret)
656473c88f9SBruce Richardson 		SKELETON_PMD_DEBUG("Device cleanup failed");
657473c88f9SBruce Richardson 
658473c88f9SBruce Richardson 	return 0;
659473c88f9SBruce Richardson }
660473c88f9SBruce Richardson 
661473c88f9SBruce Richardson static int
skeldev_get_selftest(const char * key __rte_unused,const char * value,void * opaque)662473c88f9SBruce Richardson skeldev_get_selftest(const char *key __rte_unused,
663473c88f9SBruce Richardson 		     const char *value,
664473c88f9SBruce Richardson 		     void *opaque)
665473c88f9SBruce Richardson {
666473c88f9SBruce Richardson 	int *flag = opaque;
66711da6149SChengwen Feng 	if (value == NULL || opaque == NULL)
66811da6149SChengwen Feng 		return -EINVAL;
669473c88f9SBruce Richardson 	*flag = atoi(value);
670473c88f9SBruce Richardson 	return 0;
671473c88f9SBruce Richardson }
672473c88f9SBruce Richardson 
673473c88f9SBruce Richardson static int
skeldev_parse_vdev_args(struct rte_vdev_device * vdev)674473c88f9SBruce Richardson skeldev_parse_vdev_args(struct rte_vdev_device *vdev)
675473c88f9SBruce Richardson {
676473c88f9SBruce Richardson 	int selftest = 0;
677473c88f9SBruce Richardson 	const char *name;
678473c88f9SBruce Richardson 	const char *params;
679473c88f9SBruce Richardson 
680473c88f9SBruce Richardson 	static const char *const args[] = {
681473c88f9SBruce Richardson 		SKELETON_SELFTEST_ARG,
682473c88f9SBruce Richardson 		NULL
683473c88f9SBruce Richardson 	};
684473c88f9SBruce Richardson 
685473c88f9SBruce Richardson 	name = rte_vdev_device_name(vdev);
686473c88f9SBruce Richardson 
687473c88f9SBruce Richardson 	params = rte_vdev_device_args(vdev);
688473c88f9SBruce Richardson 	if (params != NULL && params[0] != '\0') {
689473c88f9SBruce Richardson 		struct rte_kvargs *kvlist = rte_kvargs_parse(params, args);
690473c88f9SBruce Richardson 
691473c88f9SBruce Richardson 		if (!kvlist) {
692473c88f9SBruce Richardson 			SKELETON_PMD_INFO(
693473c88f9SBruce Richardson 				"Ignoring unsupported params supplied '%s'",
694473c88f9SBruce Richardson 				name);
695473c88f9SBruce Richardson 		} else {
696473c88f9SBruce Richardson 			int ret = rte_kvargs_process(kvlist,
697473c88f9SBruce Richardson 					SKELETON_SELFTEST_ARG,
698473c88f9SBruce Richardson 					skeldev_get_selftest, &selftest);
699473c88f9SBruce Richardson 			if (ret != 0 || (selftest < 0 || selftest > 1)) {
700473c88f9SBruce Richardson 				SKELETON_PMD_ERR("%s: Error in parsing args",
701473c88f9SBruce Richardson 						 name);
702473c88f9SBruce Richardson 				rte_kvargs_free(kvlist);
703473c88f9SBruce Richardson 				ret = -1; /* enforce if selftest is invalid */
704473c88f9SBruce Richardson 				return ret;
705473c88f9SBruce Richardson 			}
706473c88f9SBruce Richardson 		}
707473c88f9SBruce Richardson 
708473c88f9SBruce Richardson 		rte_kvargs_free(kvlist);
709473c88f9SBruce Richardson 	}
710473c88f9SBruce Richardson 
711473c88f9SBruce Richardson 	return selftest;
712473c88f9SBruce Richardson }
713473c88f9SBruce Richardson 
714473c88f9SBruce Richardson static int
skeleton_rawdev_probe(struct rte_vdev_device * vdev)715473c88f9SBruce Richardson skeleton_rawdev_probe(struct rte_vdev_device *vdev)
716473c88f9SBruce Richardson {
717473c88f9SBruce Richardson 	const char *name;
718473c88f9SBruce Richardson 	int selftest = 0, ret = 0;
719473c88f9SBruce Richardson 
720473c88f9SBruce Richardson 
721473c88f9SBruce Richardson 	name = rte_vdev_device_name(vdev);
722473c88f9SBruce Richardson 	if (name == NULL)
723473c88f9SBruce Richardson 		return -EINVAL;
724473c88f9SBruce Richardson 
725473c88f9SBruce Richardson 	/* More than one instance is not supported */
726473c88f9SBruce Richardson 	if (skeldev_init_once) {
727473c88f9SBruce Richardson 		SKELETON_PMD_ERR("Multiple instance not supported for %s",
728473c88f9SBruce Richardson 				 name);
729473c88f9SBruce Richardson 		return -EINVAL;
730473c88f9SBruce Richardson 	}
731473c88f9SBruce Richardson 
732473c88f9SBruce Richardson 	SKELETON_PMD_INFO("Init %s on NUMA node %d", name, rte_socket_id());
733473c88f9SBruce Richardson 
734473c88f9SBruce Richardson 	selftest = skeldev_parse_vdev_args(vdev);
735473c88f9SBruce Richardson 	/* In case of invalid argument, selftest != 1; ignore other values */
736473c88f9SBruce Richardson 
737473c88f9SBruce Richardson 	ret = skeleton_rawdev_create(name, vdev, rte_socket_id());
738473c88f9SBruce Richardson 	if (ret >= 0) {
739473c88f9SBruce Richardson 		/* In case command line argument for 'selftest' was passed;
740473c88f9SBruce Richardson 		 * if invalid arguments were passed, execution continues but
741473c88f9SBruce Richardson 		 * without selftest.
742473c88f9SBruce Richardson 		 */
743473c88f9SBruce Richardson 		if (selftest == 1)
744473c88f9SBruce Richardson 			test_rawdev_skeldev(ret);
745473c88f9SBruce Richardson 	}
746473c88f9SBruce Richardson 
747473c88f9SBruce Richardson 	/* Device instance created; Second instance not possible */
748473c88f9SBruce Richardson 	skeldev_init_once = 1;
749473c88f9SBruce Richardson 
750473c88f9SBruce Richardson 	return ret < 0 ? ret : 0;
751473c88f9SBruce Richardson }
752473c88f9SBruce Richardson 
753473c88f9SBruce Richardson static int
skeleton_rawdev_remove(struct rte_vdev_device * vdev)754473c88f9SBruce Richardson skeleton_rawdev_remove(struct rte_vdev_device *vdev)
755473c88f9SBruce Richardson {
756473c88f9SBruce Richardson 	const char *name;
757473c88f9SBruce Richardson 	int ret;
758473c88f9SBruce Richardson 
759473c88f9SBruce Richardson 	name = rte_vdev_device_name(vdev);
760473c88f9SBruce Richardson 	if (name == NULL)
761473c88f9SBruce Richardson 		return -1;
762473c88f9SBruce Richardson 
763473c88f9SBruce Richardson 	SKELETON_PMD_INFO("Closing %s on NUMA node %d", name, rte_socket_id());
764473c88f9SBruce Richardson 
765473c88f9SBruce Richardson 	ret = skeleton_rawdev_destroy(name);
766473c88f9SBruce Richardson 	if (!ret)
767473c88f9SBruce Richardson 		skeldev_init_once = 0;
768473c88f9SBruce Richardson 
769473c88f9SBruce Richardson 	return ret;
770473c88f9SBruce Richardson }
771473c88f9SBruce Richardson 
772473c88f9SBruce Richardson static struct rte_vdev_driver skeleton_pmd_drv = {
773473c88f9SBruce Richardson 	.probe = skeleton_rawdev_probe,
774473c88f9SBruce Richardson 	.remove = skeleton_rawdev_remove
775473c88f9SBruce Richardson };
776473c88f9SBruce Richardson 
777473c88f9SBruce Richardson RTE_PMD_REGISTER_VDEV(SKELETON_PMD_RAWDEV_NAME, skeleton_pmd_drv);
778eeded204SDavid Marchand RTE_LOG_REGISTER_DEFAULT(skeleton_pmd_logtype, INFO);
779