baseband/la12xx: add devargs option for max queues
[dpdk.git] / drivers / baseband / la12xx / bbdev_la12xx.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2020-2021 NXP
3  */
4
5 #include <string.h>
6
7 #include <rte_common.h>
8 #include <rte_bus_vdev.h>
9 #include <rte_malloc.h>
10 #include <rte_ring.h>
11 #include <rte_kvargs.h>
12
13 #include <rte_bbdev.h>
14 #include <rte_bbdev_pmd.h>
15
16 #include <bbdev_la12xx_pmd_logs.h>
17
18 #define DRIVER_NAME baseband_la12xx
19
20 /*  Initialisation params structure that can be used by LA12xx BBDEV driver */
21 struct bbdev_la12xx_params {
22         uint8_t queues_num; /*< LA12xx BBDEV queues number */
23 };
24
25 #define LA12XX_MAX_NB_QUEUES_ARG        "max_nb_queues"
26
27 static const char * const bbdev_la12xx_valid_params[] = {
28         LA12XX_MAX_NB_QUEUES_ARG,
29 };
30
31 /* private data structure */
32 struct bbdev_la12xx_private {
33         unsigned int max_nb_queues;  /**< Max number of queues */
34 };
35 static inline int
36 parse_u16_arg(const char *key, const char *value, void *extra_args)
37 {
38         uint16_t *u16 = extra_args;
39
40         uint64_t result;
41         if ((value == NULL) || (extra_args == NULL))
42                 return -EINVAL;
43         errno = 0;
44         result = strtoul(value, NULL, 0);
45         if ((result >= (1 << 16)) || (errno != 0)) {
46                 rte_bbdev_log(ERR, "Invalid value %" PRIu64 " for %s",
47                               result, key);
48                 return -ERANGE;
49         }
50         *u16 = (uint16_t)result;
51         return 0;
52 }
53
54 /* Parse parameters used to create device */
55 static int
56 parse_bbdev_la12xx_params(struct bbdev_la12xx_params *params,
57                 const char *input_args)
58 {
59         struct rte_kvargs *kvlist = NULL;
60         int ret = 0;
61
62         if (params == NULL)
63                 return -EINVAL;
64         if (input_args) {
65                 kvlist = rte_kvargs_parse(input_args,
66                                 bbdev_la12xx_valid_params);
67                 if (kvlist == NULL)
68                         return -EFAULT;
69
70                 ret = rte_kvargs_process(kvlist, bbdev_la12xx_valid_params[0],
71                                         &parse_u16_arg, &params->queues_num);
72                 if (ret < 0)
73                         goto exit;
74
75         }
76
77 exit:
78         if (kvlist)
79                 rte_kvargs_free(kvlist);
80         return ret;
81 }
82
83 /* Create device */
84 static int
85 la12xx_bbdev_create(struct rte_vdev_device *vdev,
86                 struct bbdev_la12xx_params *init_params __rte_unused)
87 {
88         struct rte_bbdev *bbdev;
89         const char *name = rte_vdev_device_name(vdev);
90
91         PMD_INIT_FUNC_TRACE();
92
93         bbdev = rte_bbdev_allocate(name);
94         if (bbdev == NULL)
95                 return -ENODEV;
96
97         bbdev->data->dev_private = rte_zmalloc(name,
98                         sizeof(struct bbdev_la12xx_private),
99                         RTE_CACHE_LINE_SIZE);
100         if (bbdev->data->dev_private == NULL) {
101                 rte_bbdev_release(bbdev);
102                 return -ENOMEM;
103         }
104
105         bbdev->dev_ops = NULL;
106         bbdev->device = &vdev->device;
107         bbdev->data->socket_id = 0;
108         bbdev->intr_handle = NULL;
109
110         /* register rx/tx burst functions for data path */
111         bbdev->dequeue_enc_ops = NULL;
112         bbdev->dequeue_dec_ops = NULL;
113         bbdev->enqueue_enc_ops = NULL;
114         bbdev->enqueue_dec_ops = NULL;
115
116         return 0;
117 }
118
119 /* Initialise device */
120 static int
121 la12xx_bbdev_probe(struct rte_vdev_device *vdev)
122 {
123         struct bbdev_la12xx_params init_params = {
124                 8
125         };
126         const char *name;
127         const char *input_args;
128
129         PMD_INIT_FUNC_TRACE();
130
131         if (vdev == NULL)
132                 return -EINVAL;
133
134         name = rte_vdev_device_name(vdev);
135         if (name == NULL)
136                 return -EINVAL;
137
138         input_args = rte_vdev_device_args(vdev);
139         parse_bbdev_la12xx_params(&init_params, input_args);
140
141         return la12xx_bbdev_create(vdev, &init_params);
142 }
143
144 /* Uninitialise device */
145 static int
146 la12xx_bbdev_remove(struct rte_vdev_device *vdev)
147 {
148         struct rte_bbdev *bbdev;
149         const char *name;
150
151         PMD_INIT_FUNC_TRACE();
152
153         if (vdev == NULL)
154                 return -EINVAL;
155
156         name = rte_vdev_device_name(vdev);
157         if (name == NULL)
158                 return -EINVAL;
159
160         bbdev = rte_bbdev_get_named_dev(name);
161         if (bbdev == NULL)
162                 return -EINVAL;
163
164         rte_free(bbdev->data->dev_private);
165
166         return rte_bbdev_release(bbdev);
167 }
168
169 static struct rte_vdev_driver bbdev_la12xx_pmd_drv = {
170         .probe = la12xx_bbdev_probe,
171         .remove = la12xx_bbdev_remove
172 };
173
174 RTE_PMD_REGISTER_VDEV(DRIVER_NAME, bbdev_la12xx_pmd_drv);
175 RTE_PMD_REGISTER_PARAM_STRING(DRIVER_NAME,
176         LA12XX_MAX_NB_QUEUES_ARG"=<int>");
177 RTE_LOG_REGISTER_DEFAULT(bbdev_la12xx_logtype, NOTICE);