1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
7 #include <rte_common.h>
8 #include <rte_bus_vdev.h>
9 #include <rte_malloc.h>
11 #include <rte_kvargs.h>
13 #include <rte_bbdev.h>
14 #include <rte_bbdev_pmd.h>
16 #define DRIVER_NAME baseband_null
18 RTE_LOG_REGISTER_DEFAULT(bbdev_null_logtype, NOTICE);
20 /* Helper macro for logging */
21 #define rte_bbdev_log(level, fmt, ...) \
22 rte_log(RTE_LOG_ ## level, bbdev_null_logtype, fmt "\n", ##__VA_ARGS__)
24 #define rte_bbdev_log_debug(fmt, ...) \
25 rte_bbdev_log(DEBUG, RTE_STR(__LINE__) ":%s() " fmt, __func__, \
28 /* Initialisation params structure that can be used by null BBDEV driver */
29 struct bbdev_null_params {
30 int socket_id; /*< Null BBDEV socket */
31 uint16_t queues_num; /*< Null BBDEV queues number */
34 /* Acceptable params for null BBDEV devices */
35 #define BBDEV_NULL_MAX_NB_QUEUES_ARG "max_nb_queues"
36 #define BBDEV_NULL_SOCKET_ID_ARG "socket_id"
38 static const char * const bbdev_null_valid_params[] = {
39 BBDEV_NULL_MAX_NB_QUEUES_ARG,
40 BBDEV_NULL_SOCKET_ID_ARG
43 /* private data structure */
44 struct bbdev_private {
45 unsigned int max_nb_queues; /**< Max number of queues */
50 struct rte_ring *processed_pkts; /* Ring for processed packets */
51 } __rte_cache_aligned;
55 info_get(struct rte_bbdev *dev, struct rte_bbdev_driver_info *dev_info)
57 struct bbdev_private *internals = dev->data->dev_private;
59 static const struct rte_bbdev_op_cap bbdev_capabilities[] = {
60 RTE_BBDEV_END_OF_CAPABILITIES_LIST(),
63 static struct rte_bbdev_queue_conf default_queue_conf = {
64 .queue_size = RTE_BBDEV_QUEUE_SIZE_LIMIT,
67 default_queue_conf.socket = dev->data->socket_id;
69 dev_info->driver_name = RTE_STR(DRIVER_NAME);
70 dev_info->max_num_queues = internals->max_nb_queues;
71 dev_info->queue_size_lim = RTE_BBDEV_QUEUE_SIZE_LIMIT;
72 dev_info->hardware_accelerated = false;
73 dev_info->max_dl_queue_priority = 0;
74 dev_info->max_ul_queue_priority = 0;
75 dev_info->default_queue_conf = default_queue_conf;
76 dev_info->capabilities = bbdev_capabilities;
77 dev_info->cpu_flag_reqs = NULL;
78 dev_info->min_alignment = 0;
80 /* BBDEV null device does not process the data, so
81 * endianness setting is not relevant, but setting it
82 * here for code completeness.
84 dev_info->data_endianness = RTE_LITTLE_ENDIAN;
86 rte_bbdev_log_debug("got device info from %u", dev->data->dev_id);
91 q_release(struct rte_bbdev *dev, uint16_t q_id)
93 struct bbdev_queue *q = dev->data->queues[q_id].queue_private;
96 rte_ring_free(q->processed_pkts);
98 dev->data->queues[q_id].queue_private = NULL;
101 rte_bbdev_log_debug("released device queue %u:%u",
102 dev->data->dev_id, q_id);
108 q_setup(struct rte_bbdev *dev, uint16_t q_id,
109 const struct rte_bbdev_queue_conf *queue_conf)
111 struct bbdev_queue *q;
112 char ring_name[RTE_RING_NAMESIZE];
113 snprintf(ring_name, RTE_RING_NAMESIZE, RTE_STR(DRIVER_NAME) "%u:%u",
114 dev->data->dev_id, q_id);
116 /* Allocate the queue data structure. */
117 q = rte_zmalloc_socket(RTE_STR(DRIVER_NAME), sizeof(*q),
118 RTE_CACHE_LINE_SIZE, queue_conf->socket);
120 rte_bbdev_log(ERR, "Failed to allocate queue memory");
124 q->processed_pkts = rte_ring_create(ring_name, queue_conf->queue_size,
125 queue_conf->socket, RING_F_SP_ENQ | RING_F_SC_DEQ);
126 if (q->processed_pkts == NULL) {
127 rte_bbdev_log(ERR, "Failed to create ring");
131 dev->data->queues[q_id].queue_private = q;
132 rte_bbdev_log_debug("setup device queue %s", ring_name);
140 static const struct rte_bbdev_ops pmd_ops = {
141 .info_get = info_get,
142 .queue_setup = q_setup,
143 .queue_release = q_release
146 /* Enqueue decode burst */
148 enqueue_dec_ops(struct rte_bbdev_queue_data *q_data,
149 struct rte_bbdev_dec_op **ops, uint16_t nb_ops)
151 struct bbdev_queue *q = q_data->queue_private;
152 uint16_t nb_enqueued = rte_ring_enqueue_burst(q->processed_pkts,
153 (void **)ops, nb_ops, NULL);
155 q_data->queue_stats.enqueue_err_count += nb_ops - nb_enqueued;
156 q_data->queue_stats.enqueued_count += nb_enqueued;
161 /* Enqueue encode burst */
163 enqueue_enc_ops(struct rte_bbdev_queue_data *q_data,
164 struct rte_bbdev_enc_op **ops, uint16_t nb_ops)
166 struct bbdev_queue *q = q_data->queue_private;
167 uint16_t nb_enqueued = rte_ring_enqueue_burst(q->processed_pkts,
168 (void **)ops, nb_ops, NULL);
170 q_data->queue_stats.enqueue_err_count += nb_ops - nb_enqueued;
171 q_data->queue_stats.enqueued_count += nb_enqueued;
176 /* Dequeue decode burst */
178 dequeue_dec_ops(struct rte_bbdev_queue_data *q_data,
179 struct rte_bbdev_dec_op **ops, uint16_t nb_ops)
181 struct bbdev_queue *q = q_data->queue_private;
182 uint16_t nb_dequeued = rte_ring_dequeue_burst(q->processed_pkts,
183 (void **)ops, nb_ops, NULL);
184 q_data->queue_stats.dequeued_count += nb_dequeued;
189 /* Dequeue encode burst */
191 dequeue_enc_ops(struct rte_bbdev_queue_data *q_data,
192 struct rte_bbdev_enc_op **ops, uint16_t nb_ops)
194 struct bbdev_queue *q = q_data->queue_private;
195 uint16_t nb_dequeued = rte_ring_dequeue_burst(q->processed_pkts,
196 (void **)ops, nb_ops, NULL);
197 q_data->queue_stats.dequeued_count += nb_dequeued;
202 /* Parse 16bit integer from string argument */
204 parse_u16_arg(const char *key, const char *value, void *extra_args)
206 uint16_t *u16 = extra_args;
207 unsigned int long result;
209 if ((value == NULL) || (extra_args == NULL))
212 result = strtoul(value, NULL, 0);
213 if ((result >= (1 << 16)) || (errno != 0)) {
214 rte_bbdev_log(ERR, "Invalid value %lu for %s", result, key);
217 *u16 = (uint16_t)result;
221 /* Parse parameters used to create device */
223 parse_bbdev_null_params(struct bbdev_null_params *params,
224 const char *input_args)
226 struct rte_kvargs *kvlist = NULL;
232 kvlist = rte_kvargs_parse(input_args, bbdev_null_valid_params);
236 ret = rte_kvargs_process(kvlist, bbdev_null_valid_params[0],
237 &parse_u16_arg, ¶ms->queues_num);
241 ret = rte_kvargs_process(kvlist, bbdev_null_valid_params[1],
242 &parse_u16_arg, ¶ms->socket_id);
246 if (params->socket_id >= RTE_MAX_NUMA_NODES) {
247 rte_bbdev_log(ERR, "Invalid socket, must be < %u",
255 rte_kvargs_free(kvlist);
261 null_bbdev_create(struct rte_vdev_device *vdev,
262 struct bbdev_null_params *init_params)
264 struct rte_bbdev *bbdev;
265 const char *name = rte_vdev_device_name(vdev);
267 bbdev = rte_bbdev_allocate(name);
271 bbdev->data->dev_private = rte_zmalloc_socket(name,
272 sizeof(struct bbdev_private), RTE_CACHE_LINE_SIZE,
273 init_params->socket_id);
274 if (bbdev->data->dev_private == NULL) {
275 rte_bbdev_release(bbdev);
279 bbdev->dev_ops = &pmd_ops;
280 bbdev->device = &vdev->device;
281 bbdev->data->socket_id = init_params->socket_id;
282 bbdev->intr_handle = NULL;
284 /* register rx/tx burst functions for data path */
285 bbdev->dequeue_enc_ops = dequeue_enc_ops;
286 bbdev->dequeue_dec_ops = dequeue_dec_ops;
287 bbdev->enqueue_enc_ops = enqueue_enc_ops;
288 bbdev->enqueue_dec_ops = enqueue_dec_ops;
289 ((struct bbdev_private *) bbdev->data->dev_private)->max_nb_queues =
290 init_params->queues_num;
295 /* Initialise device */
297 null_bbdev_probe(struct rte_vdev_device *vdev)
299 struct bbdev_null_params init_params = {
301 RTE_BBDEV_DEFAULT_MAX_NB_QUEUES
304 const char *input_args;
309 name = rte_vdev_device_name(vdev);
313 input_args = rte_vdev_device_args(vdev);
314 parse_bbdev_null_params(&init_params, input_args);
316 rte_bbdev_log_debug("Init %s on NUMA node %d with max queues: %d",
317 name, init_params.socket_id, init_params.queues_num);
319 return null_bbdev_create(vdev, &init_params);
322 /* Uninitialise device */
324 null_bbdev_remove(struct rte_vdev_device *vdev)
326 struct rte_bbdev *bbdev;
332 name = rte_vdev_device_name(vdev);
336 bbdev = rte_bbdev_get_named_dev(name);
340 rte_free(bbdev->data->dev_private);
342 return rte_bbdev_release(bbdev);
345 static struct rte_vdev_driver bbdev_null_pmd_drv = {
346 .probe = null_bbdev_probe,
347 .remove = null_bbdev_remove
350 RTE_PMD_REGISTER_VDEV(DRIVER_NAME, bbdev_null_pmd_drv);
351 RTE_PMD_REGISTER_PARAM_STRING(DRIVER_NAME,
352 BBDEV_NULL_MAX_NB_QUEUES_ARG"=<int> "
353 BBDEV_NULL_SOCKET_ID_ARG"=<int>");
354 RTE_PMD_REGISTER_ALIAS(DRIVER_NAME, bbdev_null);