net/softnic: fix memory leak in arguments parsing
[dpdk.git] / drivers / net / softnic / rte_eth_softnic.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #include <stdint.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 #include <ethdev_driver.h>
10 #include <ethdev_vdev.h>
11 #include <rte_malloc.h>
12 #include <rte_bus_vdev.h>
13 #include <rte_kvargs.h>
14 #include <rte_errno.h>
15 #include <rte_ring.h>
16 #include <rte_tm_driver.h>
17 #include <rte_mtr_driver.h>
18
19 #include "rte_eth_softnic.h"
20 #include "rte_eth_softnic_internals.h"
21
22 #define PMD_PARAM_FIRMWARE                                 "firmware"
23 #define PMD_PARAM_CONN_PORT                                "conn_port"
24 #define PMD_PARAM_CPU_ID                                   "cpu_id"
25 #define PMD_PARAM_SC                                       "sc"
26 #define PMD_PARAM_TM_N_QUEUES                              "tm_n_queues"
27 #define PMD_PARAM_TM_QSIZE0                                "tm_qsize0"
28 #define PMD_PARAM_TM_QSIZE1                                "tm_qsize1"
29 #define PMD_PARAM_TM_QSIZE2                                "tm_qsize2"
30 #define PMD_PARAM_TM_QSIZE3                                "tm_qsize3"
31 #define PMD_PARAM_TM_QSIZE4                                "tm_qsize4"
32 #define PMD_PARAM_TM_QSIZE5                                "tm_qsize5"
33 #define PMD_PARAM_TM_QSIZE6                                "tm_qsize6"
34 #define PMD_PARAM_TM_QSIZE7                                "tm_qsize7"
35 #define PMD_PARAM_TM_QSIZE8                                "tm_qsize8"
36 #define PMD_PARAM_TM_QSIZE9                                "tm_qsize9"
37 #define PMD_PARAM_TM_QSIZE10                               "tm_qsize10"
38 #define PMD_PARAM_TM_QSIZE11                               "tm_qsize11"
39 #define PMD_PARAM_TM_QSIZE12                               "tm_qsize12"
40
41
42 static const char * const pmd_valid_args[] = {
43         PMD_PARAM_FIRMWARE,
44         PMD_PARAM_CONN_PORT,
45         PMD_PARAM_CPU_ID,
46         PMD_PARAM_SC,
47         PMD_PARAM_TM_N_QUEUES,
48         PMD_PARAM_TM_QSIZE0,
49         PMD_PARAM_TM_QSIZE1,
50         PMD_PARAM_TM_QSIZE2,
51         PMD_PARAM_TM_QSIZE3,
52         PMD_PARAM_TM_QSIZE4,
53         PMD_PARAM_TM_QSIZE5,
54         PMD_PARAM_TM_QSIZE6,
55         PMD_PARAM_TM_QSIZE7,
56         PMD_PARAM_TM_QSIZE8,
57         PMD_PARAM_TM_QSIZE9,
58         PMD_PARAM_TM_QSIZE10,
59         PMD_PARAM_TM_QSIZE11,
60         PMD_PARAM_TM_QSIZE12,
61         NULL
62 };
63
64 static const char welcome[] =
65         "\n"
66         "Welcome to Soft NIC!\n"
67         "\n";
68
69 static const char prompt[] = "softnic> ";
70
71 static const struct softnic_conn_params conn_params_default = {
72         .welcome = welcome,
73         .prompt = prompt,
74         .addr = "0.0.0.0",
75         .port = 0,
76         .buf_size = 1024 * 1024,
77         .msg_in_len_max = 1024,
78         .msg_out_len_max = 1024 * 1024,
79         .msg_handle = softnic_cli_process,
80         .msg_handle_arg = NULL,
81 };
82
83 RTE_LOG_REGISTER_DEFAULT(pmd_softnic_logtype, NOTICE);
84
85 #define PMD_LOG(level, fmt, args...) \
86         rte_log(RTE_LOG_ ## level, pmd_softnic_logtype, \
87                 "%s(): " fmt "\n", __func__, ##args)
88
89 static int
90 pmd_dev_infos_get(struct rte_eth_dev *dev __rte_unused,
91         struct rte_eth_dev_info *dev_info)
92 {
93         dev_info->max_rx_pktlen = UINT32_MAX;
94         dev_info->max_rx_queues = UINT16_MAX;
95         dev_info->max_tx_queues = UINT16_MAX;
96
97         return 0;
98 }
99
100 static int
101 pmd_dev_configure(struct rte_eth_dev *dev __rte_unused)
102 {
103         return 0;
104 }
105
106 static int
107 pmd_rx_queue_setup(struct rte_eth_dev *dev,
108         uint16_t rx_queue_id,
109         uint16_t nb_rx_desc,
110         unsigned int socket_id __rte_unused,
111         const struct rte_eth_rxconf *rx_conf __rte_unused,
112         struct rte_mempool *mb_pool __rte_unused)
113 {
114         char name[NAME_SIZE];
115         struct pmd_internals *p = dev->data->dev_private;
116         struct softnic_swq *swq;
117
118         struct softnic_swq_params params = {
119                 .size = nb_rx_desc,
120         };
121
122         snprintf(name, sizeof(name), "RXQ%u", rx_queue_id);
123
124         swq = softnic_swq_create(p,
125                 name,
126                 &params);
127         if (swq == NULL)
128                 return -1;
129
130         dev->data->rx_queues[rx_queue_id] = swq->r;
131         return 0;
132 }
133
134 static int
135 pmd_tx_queue_setup(struct rte_eth_dev *dev,
136         uint16_t tx_queue_id,
137         uint16_t nb_tx_desc,
138         unsigned int socket_id __rte_unused,
139         const struct rte_eth_txconf *tx_conf __rte_unused)
140 {
141         char name[NAME_SIZE];
142         struct pmd_internals *p = dev->data->dev_private;
143         struct softnic_swq *swq;
144
145         struct softnic_swq_params params = {
146                 .size = nb_tx_desc,
147         };
148
149         snprintf(name, sizeof(name), "TXQ%u", tx_queue_id);
150
151         swq = softnic_swq_create(p,
152                 name,
153                 &params);
154         if (swq == NULL)
155                 return -1;
156
157         dev->data->tx_queues[tx_queue_id] = swq->r;
158         return 0;
159 }
160
161 static int
162 pmd_dev_start(struct rte_eth_dev *dev)
163 {
164         struct pmd_internals *p = dev->data->dev_private;
165         int status;
166
167         /* Firmware */
168         status = softnic_cli_script_process(p,
169                 p->params.firmware,
170                 conn_params_default.msg_in_len_max,
171                 conn_params_default.msg_out_len_max);
172         if (status)
173                 return status;
174
175         /* Link UP */
176         dev->data->dev_link.link_status = ETH_LINK_UP;
177
178         return 0;
179 }
180
181 static int
182 pmd_dev_stop(struct rte_eth_dev *dev)
183 {
184         struct pmd_internals *p = dev->data->dev_private;
185
186         /* Link DOWN */
187         dev->data->dev_link.link_status = ETH_LINK_DOWN;
188
189         /* Firmware */
190         softnic_pipeline_disable_all(p);
191         softnic_pipeline_free(p);
192         softnic_table_action_profile_free(p);
193         softnic_port_in_action_profile_free(p);
194         softnic_tap_free(p);
195         softnic_tmgr_free(p);
196         softnic_link_free(p);
197         softnic_softnic_swq_free_keep_rxq_txq(p);
198         softnic_mempool_free(p);
199
200         tm_hierarchy_free(p);
201         softnic_mtr_free(p);
202
203         return 0;
204 }
205
206 static void
207 pmd_free(struct pmd_internals *p)
208 {
209         if (p == NULL)
210                 return;
211
212         if (p->params.conn_port)
213                 softnic_conn_free(p->conn);
214
215         softnic_thread_free(p);
216         softnic_pipeline_free(p);
217         softnic_table_action_profile_free(p);
218         softnic_port_in_action_profile_free(p);
219         softnic_tap_free(p);
220         softnic_tmgr_free(p);
221         softnic_link_free(p);
222         softnic_swq_free(p);
223         softnic_mempool_free(p);
224
225         tm_hierarchy_free(p);
226         softnic_mtr_free(p);
227
228         rte_free(p);
229 }
230
231 static int
232 pmd_dev_close(struct rte_eth_dev *dev)
233 {
234         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
235                 return 0;
236
237         pmd_free(dev->data->dev_private);
238         dev->data->dev_private = NULL; /* already freed */
239         dev->data->mac_addrs = NULL; /* statically allocated */
240         return 0;
241 }
242
243 static int
244 pmd_link_update(struct rte_eth_dev *dev __rte_unused,
245         int wait_to_complete __rte_unused)
246 {
247         return 0;
248 }
249
250 static int
251 pmd_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
252                  const struct rte_flow_ops **ops)
253 {
254         *ops = &pmd_flow_ops;
255         return 0;
256 }
257
258 static int
259 pmd_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg)
260 {
261         *(const struct rte_tm_ops **)arg = &pmd_tm_ops;
262
263         return 0;
264 }
265
266 static int
267 pmd_mtr_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg)
268 {
269         *(const struct rte_mtr_ops **)arg = &pmd_mtr_ops;
270
271         return 0;
272 }
273
274 static const struct eth_dev_ops pmd_ops = {
275         .dev_configure = pmd_dev_configure,
276         .dev_start = pmd_dev_start,
277         .dev_stop = pmd_dev_stop,
278         .dev_close = pmd_dev_close,
279         .link_update = pmd_link_update,
280         .dev_infos_get = pmd_dev_infos_get,
281         .rx_queue_setup = pmd_rx_queue_setup,
282         .tx_queue_setup = pmd_tx_queue_setup,
283         .flow_ops_get = pmd_flow_ops_get,
284         .tm_ops_get = pmd_tm_ops_get,
285         .mtr_ops_get = pmd_mtr_ops_get,
286 };
287
288 static uint16_t
289 pmd_rx_pkt_burst(void *rxq,
290         struct rte_mbuf **rx_pkts,
291         uint16_t nb_pkts)
292 {
293         return (uint16_t)rte_ring_sc_dequeue_burst(rxq,
294                 (void **)rx_pkts,
295                 nb_pkts,
296                 NULL);
297 }
298
299 static uint16_t
300 pmd_tx_pkt_burst(void *txq,
301         struct rte_mbuf **tx_pkts,
302         uint16_t nb_pkts)
303 {
304         return (uint16_t)rte_ring_sp_enqueue_burst(txq,
305                 (void **)tx_pkts,
306                 nb_pkts,
307                 NULL);
308 }
309
310 static void *
311 pmd_init(struct pmd_params *params)
312 {
313         struct pmd_internals *p;
314         int status;
315
316         p = rte_zmalloc_socket(params->name,
317                 sizeof(struct pmd_internals),
318                 0,
319                 params->cpu_id);
320         if (p == NULL)
321                 return NULL;
322
323         /* Params */
324         memcpy(&p->params, params, sizeof(p->params));
325
326         /* Resources */
327         tm_hierarchy_init(p);
328         softnic_mtr_init(p);
329
330         softnic_mempool_init(p);
331         softnic_swq_init(p);
332         softnic_link_init(p);
333         softnic_tmgr_init(p);
334         softnic_tap_init(p);
335         softnic_cryptodev_init(p);
336         softnic_port_in_action_profile_init(p);
337         softnic_table_action_profile_init(p);
338         softnic_pipeline_init(p);
339
340         status = softnic_thread_init(p);
341         if (status) {
342                 rte_free(p);
343                 return NULL;
344         }
345
346         if (params->conn_port) {
347                 struct softnic_conn_params conn_params;
348
349                 memcpy(&conn_params, &conn_params_default, sizeof(conn_params));
350                 conn_params.port = p->params.conn_port;
351                 conn_params.msg_handle_arg = p;
352
353                 p->conn = softnic_conn_init(&conn_params);
354                 if (p->conn == NULL) {
355                         softnic_thread_free(p);
356                         rte_free(p);
357                         return NULL;
358                 }
359         }
360
361         return p;
362 }
363
364 static struct rte_ether_addr eth_addr = {
365         .addr_bytes = {0},
366 };
367
368 static int
369 pmd_ethdev_register(struct rte_vdev_device *vdev,
370         struct pmd_params *params,
371         void *dev_private)
372 {
373         struct rte_eth_dev *dev;
374
375         /* Ethdev entry allocation */
376         dev = rte_eth_dev_allocate(params->name);
377         if (!dev)
378                 return -ENOMEM;
379
380         /* dev */
381         dev->rx_pkt_burst = pmd_rx_pkt_burst;
382         dev->tx_pkt_burst = pmd_tx_pkt_burst;
383         dev->tx_pkt_prepare = NULL;
384         dev->dev_ops = &pmd_ops;
385         dev->device = &vdev->device;
386
387         /* dev->data */
388         dev->data->dev_private = dev_private;
389         dev->data->dev_link.link_speed = ETH_SPEED_NUM_100G;
390         dev->data->dev_link.link_duplex = ETH_LINK_FULL_DUPLEX;
391         dev->data->dev_link.link_autoneg = ETH_LINK_FIXED;
392         dev->data->dev_link.link_status = ETH_LINK_DOWN;
393         dev->data->mac_addrs = &eth_addr;
394         dev->data->promiscuous = 1;
395         dev->data->numa_node = params->cpu_id;
396
397         rte_eth_dev_probing_finish(dev);
398
399         return 0;
400 }
401
402 static int
403 get_string(const char *key __rte_unused, const char *value, void *extra_args)
404 {
405         if (!value || !extra_args)
406                 return -EINVAL;
407
408         *(char **)extra_args = strdup(value);
409
410         if (!*(char **)extra_args)
411                 return -ENOMEM;
412
413         return 0;
414 }
415
416 static int
417 get_uint32(const char *key __rte_unused, const char *value, void *extra_args)
418 {
419         if (!value || !extra_args)
420                 return -EINVAL;
421
422         *(uint32_t *)extra_args = strtoull(value, NULL, 0);
423
424         return 0;
425 }
426
427 static int
428 get_uint16(const char *key __rte_unused, const char *value, void *extra_args)
429 {
430         if (!value || !extra_args)
431                 return -EINVAL;
432
433         *(uint16_t *)extra_args = strtoull(value, NULL, 0);
434
435         return 0;
436 }
437
438 static int
439 pmd_parse_args(struct pmd_params *p, const char *params)
440 {
441         struct rte_kvargs *kvlist;
442         int ret = 0;
443         char *firmware = NULL;
444
445         kvlist = rte_kvargs_parse(params, pmd_valid_args);
446         if (kvlist == NULL)
447                 return -EINVAL;
448
449         /* Set default values */
450         memset(p, 0, sizeof(*p));
451         if (rte_strscpy(p->firmware, SOFTNIC_FIRMWARE,
452                         sizeof(p->firmware)) < 0) {
453                 PMD_LOG(WARNING,
454                         "\"%s\": firmware path should be shorter than %zu",
455                         SOFTNIC_FIRMWARE, sizeof(p->firmware));
456                 ret = -EINVAL;
457                 goto out_free;
458         }
459         p->cpu_id = SOFTNIC_CPU_ID;
460         p->sc = SOFTNIC_SC;
461         p->tm.n_queues = SOFTNIC_TM_N_QUEUES;
462         p->tm.qsize[0] = SOFTNIC_TM_QUEUE_SIZE;
463         p->tm.qsize[1] = SOFTNIC_TM_QUEUE_SIZE;
464         p->tm.qsize[2] = SOFTNIC_TM_QUEUE_SIZE;
465         p->tm.qsize[3] = SOFTNIC_TM_QUEUE_SIZE;
466         p->tm.qsize[4] = SOFTNIC_TM_QUEUE_SIZE;
467         p->tm.qsize[5] = SOFTNIC_TM_QUEUE_SIZE;
468         p->tm.qsize[6] = SOFTNIC_TM_QUEUE_SIZE;
469         p->tm.qsize[7] = SOFTNIC_TM_QUEUE_SIZE;
470         p->tm.qsize[8] = SOFTNIC_TM_QUEUE_SIZE;
471         p->tm.qsize[9] = SOFTNIC_TM_QUEUE_SIZE;
472         p->tm.qsize[10] = SOFTNIC_TM_QUEUE_SIZE;
473         p->tm.qsize[11] = SOFTNIC_TM_QUEUE_SIZE;
474         p->tm.qsize[12] = SOFTNIC_TM_QUEUE_SIZE;
475
476         /* Firmware script (optional) */
477         if (rte_kvargs_count(kvlist, PMD_PARAM_FIRMWARE) == 1) {
478                 ret = rte_kvargs_process(kvlist, PMD_PARAM_FIRMWARE,
479                         &get_string, &firmware);
480                 if (ret < 0)
481                         goto out_free;
482         }
483         if (rte_strscpy(p->firmware, firmware,
484                         sizeof(p->firmware)) < 0) {
485                 PMD_LOG(WARNING,
486                         "\"%s\": firmware path should be shorter than %zu",
487                         firmware, sizeof(p->firmware));
488                 free(firmware);
489                 ret = -EINVAL;
490                 goto out_free;
491         }
492         free(firmware);
493         /* Connection listening port (optional) */
494         if (rte_kvargs_count(kvlist, PMD_PARAM_CONN_PORT) == 1) {
495                 ret = rte_kvargs_process(kvlist, PMD_PARAM_CONN_PORT,
496                         &get_uint16, &p->conn_port);
497                 if (ret < 0)
498                         goto out_free;
499         }
500
501         /* CPU ID (optional) */
502         if (rte_kvargs_count(kvlist, PMD_PARAM_CPU_ID) == 1) {
503                 ret = rte_kvargs_process(kvlist, PMD_PARAM_CPU_ID,
504                         &get_uint32, &p->cpu_id);
505                 if (ret < 0)
506                         goto out_free;
507         }
508
509         /* Service cores (optional) */
510         if (rte_kvargs_count(kvlist, PMD_PARAM_SC) == 1) {
511                 ret = rte_kvargs_process(kvlist, PMD_PARAM_SC,
512                         &get_uint32, &p->sc);
513                 if (ret < 0)
514                         goto out_free;
515         }
516
517         /* TM number of queues (optional) */
518         if (rte_kvargs_count(kvlist, PMD_PARAM_TM_N_QUEUES) == 1) {
519                 ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_N_QUEUES,
520                         &get_uint32, &p->tm.n_queues);
521                 if (ret < 0)
522                         goto out_free;
523         }
524
525         /* TM queue size 0 .. 3 (optional) */
526         if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE0) == 1) {
527                 ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE0,
528                         &get_uint32, &p->tm.qsize[0]);
529                 if (ret < 0)
530                         goto out_free;
531         }
532
533         if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE1) == 1) {
534                 ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE1,
535                         &get_uint32, &p->tm.qsize[1]);
536                 if (ret < 0)
537                         goto out_free;
538         }
539
540         if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE2) == 1) {
541                 ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE2,
542                         &get_uint32, &p->tm.qsize[2]);
543                 if (ret < 0)
544                         goto out_free;
545         }
546
547         if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE3) == 1) {
548                 ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE3,
549                         &get_uint32, &p->tm.qsize[3]);
550                 if (ret < 0)
551                         goto out_free;
552         }
553
554         if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE4) == 1) {
555                 ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE4,
556                         &get_uint32, &p->tm.qsize[4]);
557                 if (ret < 0)
558                         goto out_free;
559         }
560
561         if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE5) == 1) {
562                 ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE5,
563                         &get_uint32, &p->tm.qsize[5]);
564                 if (ret < 0)
565                         goto out_free;
566         }
567
568         if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE6) == 1) {
569                 ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE6,
570                         &get_uint32, &p->tm.qsize[6]);
571                 if (ret < 0)
572                         goto out_free;
573         }
574
575         if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE7) == 1) {
576                 ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE7,
577                         &get_uint32, &p->tm.qsize[7]);
578                 if (ret < 0)
579                         goto out_free;
580         }
581         if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE8) == 1) {
582                 ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE8,
583                         &get_uint32, &p->tm.qsize[8]);
584                 if (ret < 0)
585                         goto out_free;
586         }
587         if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE9) == 1) {
588                 ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE9,
589                         &get_uint32, &p->tm.qsize[9]);
590                 if (ret < 0)
591                         goto out_free;
592         }
593
594         if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE10) == 1) {
595                 ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE10,
596                         &get_uint32, &p->tm.qsize[10]);
597                 if (ret < 0)
598                         goto out_free;
599         }
600
601         if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE11) == 1) {
602                 ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE11,
603                         &get_uint32, &p->tm.qsize[11]);
604                 if (ret < 0)
605                         goto out_free;
606         }
607
608         if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE12) == 1) {
609                 ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE12,
610                         &get_uint32, &p->tm.qsize[12]);
611                 if (ret < 0)
612                         goto out_free;
613         }
614
615 out_free:
616         rte_kvargs_free(kvlist);
617         return ret;
618 }
619
620 static int
621 pmd_probe(struct rte_vdev_device *vdev)
622 {
623         struct pmd_params p;
624         const char *params;
625         int status = 0;
626
627         void *dev_private;
628         const char *name = rte_vdev_device_name(vdev);
629
630         PMD_LOG(INFO, "Probing device \"%s\"", name);
631
632         /* Parse input arguments */
633         params = rte_vdev_device_args(vdev);
634         if (!params)
635                 return -EINVAL;
636
637         status = pmd_parse_args(&p, params);
638         if (status)
639                 return status;
640
641         if (rte_strscpy(p.name, name, sizeof(p.name)) < 0) {
642                 PMD_LOG(WARNING,
643                         "\"%s\": device name should be shorter than %zu",
644                         name, sizeof(p.name));
645                 return -EINVAL;
646         }
647
648         /* Allocate and initialize soft ethdev private data */
649         dev_private = pmd_init(&p);
650         if (dev_private == NULL)
651                 return -ENOMEM;
652
653         /* Register soft ethdev */
654         PMD_LOG(INFO, "Creating soft ethdev \"%s\"", p.name);
655
656         status = pmd_ethdev_register(vdev, &p, dev_private);
657         if (status) {
658                 pmd_free(dev_private);
659                 return status;
660         }
661
662         return 0;
663 }
664
665 static int
666 pmd_remove(struct rte_vdev_device *vdev)
667 {
668         struct rte_eth_dev *dev = NULL;
669
670         if (!vdev)
671                 return -EINVAL;
672
673         PMD_LOG(INFO, "Removing device \"%s\"", rte_vdev_device_name(vdev));
674
675         /* Find the ethdev entry */
676         dev = rte_eth_dev_allocated(rte_vdev_device_name(vdev));
677         if (dev == NULL)
678                 return 0; /* port already released */
679
680         pmd_dev_close(dev);
681         rte_eth_dev_release_port(dev);
682
683         return 0;
684 }
685
686 static struct rte_vdev_driver pmd_softnic_drv = {
687         .probe = pmd_probe,
688         .remove = pmd_remove,
689 };
690
691 RTE_PMD_REGISTER_VDEV(net_softnic, pmd_softnic_drv);
692 RTE_PMD_REGISTER_PARAM_STRING(net_softnic,
693         PMD_PARAM_FIRMWARE "=<string> "
694         PMD_PARAM_CONN_PORT "=<uint16> "
695         PMD_PARAM_CPU_ID "=<uint32> "
696         PMD_PARAM_TM_N_QUEUES "=<uint32> "
697         PMD_PARAM_TM_QSIZE0 "=<uint32> "
698         PMD_PARAM_TM_QSIZE1 "=<uint32> "
699         PMD_PARAM_TM_QSIZE2 "=<uint32> "
700         PMD_PARAM_TM_QSIZE3 "=<uint32>"
701         PMD_PARAM_TM_QSIZE4 "=<uint32> "
702         PMD_PARAM_TM_QSIZE5 "=<uint32> "
703         PMD_PARAM_TM_QSIZE6 "=<uint32> "
704         PMD_PARAM_TM_QSIZE7 "=<uint32> "
705         PMD_PARAM_TM_QSIZE8 "=<uint32> "
706         PMD_PARAM_TM_QSIZE9 "=<uint32> "
707         PMD_PARAM_TM_QSIZE10 "=<uint32> "
708         PMD_PARAM_TM_QSIZE11 "=<uint32>"
709         PMD_PARAM_TM_QSIZE12 "=<uint32>"
710 );
711
712 int
713 rte_pmd_softnic_manage(uint16_t port_id)
714 {
715         struct rte_eth_dev *dev = &rte_eth_devices[port_id];
716         struct pmd_internals *softnic;
717
718 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
719         RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
720 #endif
721
722         softnic = dev->data->dev_private;
723
724         softnic_conn_poll_for_conn(softnic->conn);
725
726         softnic_conn_poll_for_msg(softnic->conn);
727
728         return 0;
729 }