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 /* NULL BBDev logging ID */
19 static int bbdev_null_logtype;
21 /* Helper macro for logging */
22 #define rte_bbdev_log(level, fmt, ...) \
23 rte_log(RTE_LOG_ ## level, bbdev_null_logtype, fmt "\n", ##__VA_ARGS__)
25 #define rte_bbdev_log_debug(fmt, ...) \
26 rte_bbdev_log(DEBUG, RTE_STR(__LINE__) ":%s() " fmt, __func__, \
29 /* Initialisation params structure that can be used by null BBDEV driver */
30 struct bbdev_null_params {
31 int socket_id; /*< Null BBDEV socket */
32 uint16_t queues_num; /*< Null BBDEV queues number */
35 /* Accecptable params for null BBDEV devices */
36 #define BBDEV_NULL_MAX_NB_QUEUES_ARG "max_nb_queues"
37 #define BBDEV_NULL_SOCKET_ID_ARG "socket_id"
39 static const char * const bbdev_null_valid_params[] = {
40 BBDEV_NULL_MAX_NB_QUEUES_ARG,
41 BBDEV_NULL_SOCKET_ID_ARG
44 /* private data structure */
45 struct bbdev_private {
46 unsigned int max_nb_queues; /**< Max number of queues */
51 struct rte_ring *processed_pkts; /* Ring for processed packets */
52 } __rte_cache_aligned;
56 info_get(struct rte_bbdev *dev, struct rte_bbdev_driver_info *dev_info)
58 struct bbdev_private *internals = dev->data->dev_private;
60 static const struct rte_bbdev_op_cap bbdev_capabilities[] = {
61 RTE_BBDEV_END_OF_CAPABILITIES_LIST(),
64 static struct rte_bbdev_queue_conf default_queue_conf = {
65 .queue_size = RTE_BBDEV_QUEUE_SIZE_LIMIT,
68 default_queue_conf.socket = dev->data->socket_id;
70 dev_info->driver_name = RTE_STR(DRIVER_NAME);
71 dev_info->max_num_queues = internals->max_nb_queues;
72 dev_info->queue_size_lim = RTE_BBDEV_QUEUE_SIZE_LIMIT;
73 dev_info->hardware_accelerated = false;
74 dev_info->max_dl_queue_priority = 0;
75 dev_info->max_ul_queue_priority = 0;
76 dev_info->default_queue_conf = default_queue_conf;
77 dev_info->capabilities = bbdev_capabilities;
78 dev_info->cpu_flag_reqs = NULL;
79 dev_info->min_alignment = 0;
81 rte_bbdev_log_debug("got device info from %u", dev->data->dev_id);
86 q_release(struct rte_bbdev *dev, uint16_t q_id)
88 struct bbdev_queue *q = dev->data->queues[q_id].queue_private;
91 rte_ring_free(q->processed_pkts);
93 dev->data->queues[q_id].queue_private = NULL;
96 rte_bbdev_log_debug("released device queue %u:%u",
97 dev->data->dev_id, q_id);
103 q_setup(struct rte_bbdev *dev, uint16_t q_id,
104 const struct rte_bbdev_queue_conf *queue_conf)
106 struct bbdev_queue *q;
107 char ring_name[RTE_RING_NAMESIZE];
108 snprintf(ring_name, RTE_RING_NAMESIZE, RTE_STR(DRIVER_NAME) "%u:%u",
109 dev->data->dev_id, q_id);
111 /* Allocate the queue data structure. */
112 q = rte_zmalloc_socket(RTE_STR(DRIVER_NAME), sizeof(*q),
113 RTE_CACHE_LINE_SIZE, queue_conf->socket);
115 rte_bbdev_log(ERR, "Failed to allocate queue memory");
119 q->processed_pkts = rte_ring_create(ring_name, queue_conf->queue_size,
120 queue_conf->socket, RING_F_SP_ENQ | RING_F_SC_DEQ);
121 if (q->processed_pkts == NULL) {
122 rte_bbdev_log(ERR, "Failed to create ring");
126 dev->data->queues[q_id].queue_private = q;
127 rte_bbdev_log_debug("setup device queue %s", ring_name);
135 static const struct rte_bbdev_ops pmd_ops = {
136 .info_get = info_get,
137 .queue_setup = q_setup,
138 .queue_release = q_release
141 /* Enqueue decode burst */
143 enqueue_dec_ops(struct rte_bbdev_queue_data *q_data,
144 struct rte_bbdev_dec_op **ops, uint16_t nb_ops)
146 struct bbdev_queue *q = q_data->queue_private;
147 uint16_t nb_enqueued = rte_ring_enqueue_burst(q->processed_pkts,
148 (void **)ops, nb_ops, NULL);
150 q_data->queue_stats.enqueue_err_count += nb_ops - nb_enqueued;
151 q_data->queue_stats.enqueued_count += nb_enqueued;
156 /* Enqueue encode burst */
158 enqueue_enc_ops(struct rte_bbdev_queue_data *q_data,
159 struct rte_bbdev_enc_op **ops, uint16_t nb_ops)
161 struct bbdev_queue *q = q_data->queue_private;
162 uint16_t nb_enqueued = rte_ring_enqueue_burst(q->processed_pkts,
163 (void **)ops, nb_ops, NULL);
165 q_data->queue_stats.enqueue_err_count += nb_ops - nb_enqueued;
166 q_data->queue_stats.enqueued_count += nb_enqueued;
171 /* Dequeue decode burst */
173 dequeue_dec_ops(struct rte_bbdev_queue_data *q_data,
174 struct rte_bbdev_dec_op **ops, uint16_t nb_ops)
176 struct bbdev_queue *q = q_data->queue_private;
177 uint16_t nb_dequeued = rte_ring_dequeue_burst(q->processed_pkts,
178 (void **)ops, nb_ops, NULL);
179 q_data->queue_stats.dequeued_count += nb_dequeued;
184 /* Dequeue encode burst */
186 dequeue_enc_ops(struct rte_bbdev_queue_data *q_data,
187 struct rte_bbdev_enc_op **ops, uint16_t nb_ops)
189 struct bbdev_queue *q = q_data->queue_private;
190 uint16_t nb_dequeued = rte_ring_dequeue_burst(q->processed_pkts,
191 (void **)ops, nb_ops, NULL);
192 q_data->queue_stats.dequeued_count += nb_dequeued;
197 /* Parse 16bit integer from string argument */
199 parse_u16_arg(const char *key, const char *value, void *extra_args)
201 uint16_t *u16 = extra_args;
202 unsigned int long result;
204 if ((value == NULL) || (extra_args == NULL))
207 result = strtoul(value, NULL, 0);
208 if ((result >= (1 << 16)) || (errno != 0)) {
209 rte_bbdev_log(ERR, "Invalid value %lu for %s", result, key);
212 *u16 = (uint16_t)result;
216 /* Parse parameters used to create device */
218 parse_bbdev_null_params(struct bbdev_null_params *params,
219 const char *input_args)
221 struct rte_kvargs *kvlist = NULL;
227 kvlist = rte_kvargs_parse(input_args, bbdev_null_valid_params);
231 ret = rte_kvargs_process(kvlist, bbdev_null_valid_params[0],
232 &parse_u16_arg, ¶ms->queues_num);
236 ret = rte_kvargs_process(kvlist, bbdev_null_valid_params[1],
237 &parse_u16_arg, ¶ms->socket_id);
241 if (params->socket_id >= RTE_MAX_NUMA_NODES) {
242 rte_bbdev_log(ERR, "Invalid socket, must be < %u",
250 rte_kvargs_free(kvlist);
256 null_bbdev_create(struct rte_vdev_device *vdev,
257 struct bbdev_null_params *init_params)
259 struct rte_bbdev *bbdev;
260 const char *name = rte_vdev_device_name(vdev);
262 bbdev = rte_bbdev_allocate(name);
266 bbdev->data->dev_private = rte_zmalloc_socket(name,
267 sizeof(struct bbdev_private), RTE_CACHE_LINE_SIZE,
268 init_params->socket_id);
269 if (bbdev->data->dev_private == NULL) {
270 rte_bbdev_release(bbdev);
274 bbdev->dev_ops = &pmd_ops;
275 bbdev->device = &vdev->device;
276 bbdev->data->socket_id = init_params->socket_id;
277 bbdev->intr_handle = NULL;
279 /* register rx/tx burst functions for data path */
280 bbdev->dequeue_enc_ops = dequeue_enc_ops;
281 bbdev->dequeue_dec_ops = dequeue_dec_ops;
282 bbdev->enqueue_enc_ops = enqueue_enc_ops;
283 bbdev->enqueue_dec_ops = enqueue_dec_ops;
284 ((struct bbdev_private *) bbdev->data->dev_private)->max_nb_queues =
285 init_params->queues_num;
290 /* Initialise device */
292 null_bbdev_probe(struct rte_vdev_device *vdev)
294 struct bbdev_null_params init_params = {
296 RTE_BBDEV_DEFAULT_MAX_NB_QUEUES
299 const char *input_args;
304 name = rte_vdev_device_name(vdev);
308 input_args = rte_vdev_device_args(vdev);
309 parse_bbdev_null_params(&init_params, input_args);
311 rte_bbdev_log_debug("Init %s on NUMA node %d with max queues: %d",
312 name, init_params.socket_id, init_params.queues_num);
314 return null_bbdev_create(vdev, &init_params);
317 /* Uninitialise device */
319 null_bbdev_remove(struct rte_vdev_device *vdev)
321 struct rte_bbdev *bbdev;
327 name = rte_vdev_device_name(vdev);
331 bbdev = rte_bbdev_get_named_dev(name);
335 rte_free(bbdev->data->dev_private);
337 return rte_bbdev_release(bbdev);
340 static struct rte_vdev_driver bbdev_null_pmd_drv = {
341 .probe = null_bbdev_probe,
342 .remove = null_bbdev_remove
345 RTE_PMD_REGISTER_VDEV(DRIVER_NAME, bbdev_null_pmd_drv);
346 RTE_PMD_REGISTER_PARAM_STRING(DRIVER_NAME,
347 BBDEV_NULL_MAX_NB_QUEUES_ARG"=<int> "
348 BBDEV_NULL_SOCKET_ID_ARG"=<int>");
349 RTE_PMD_REGISTER_ALIAS(DRIVER_NAME, bbdev_null);
351 RTE_INIT(null_bbdev_init_log)
353 bbdev_null_logtype = rte_log_register("pmd.bb.null");
354 if (bbdev_null_logtype >= 0)
355 rte_log_set_level(bbdev_null_logtype, RTE_LOG_NOTICE);