ethdev: remove forcing stopped state upon close
[dpdk.git] / drivers / net / ring / rte_eth_ring.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2015 Intel Corporation
3  */
4
5 #include "rte_eth_ring.h"
6 #include <rte_mbuf.h>
7 #include <rte_ethdev_driver.h>
8 #include <rte_malloc.h>
9 #include <rte_memcpy.h>
10 #include <rte_string_fns.h>
11 #include <rte_bus_vdev.h>
12 #include <rte_kvargs.h>
13 #include <rte_errno.h>
14
15 #define ETH_RING_NUMA_NODE_ACTION_ARG   "nodeaction"
16 #define ETH_RING_ACTION_CREATE          "CREATE"
17 #define ETH_RING_ACTION_ATTACH          "ATTACH"
18 #define ETH_RING_INTERNAL_ARG           "internal"
19 #define ETH_RING_INTERNAL_ARG_MAX_LEN   19 /* "0x..16chars..\0" */
20
21 static const char *valid_arguments[] = {
22         ETH_RING_NUMA_NODE_ACTION_ARG,
23         ETH_RING_INTERNAL_ARG,
24         NULL
25 };
26
27 struct ring_internal_args {
28         struct rte_ring * const *rx_queues;
29         const unsigned int nb_rx_queues;
30         struct rte_ring * const *tx_queues;
31         const unsigned int nb_tx_queues;
32         const unsigned int numa_node;
33         void *addr; /* self addr for sanity check */
34 };
35
36 enum dev_action {
37         DEV_CREATE,
38         DEV_ATTACH
39 };
40
41 struct ring_queue {
42         struct rte_ring *rng;
43         rte_atomic64_t rx_pkts;
44         rte_atomic64_t tx_pkts;
45 };
46
47 struct pmd_internals {
48         unsigned int max_rx_queues;
49         unsigned int max_tx_queues;
50
51         struct ring_queue rx_ring_queues[RTE_PMD_RING_MAX_RX_RINGS];
52         struct ring_queue tx_ring_queues[RTE_PMD_RING_MAX_TX_RINGS];
53
54         struct rte_ether_addr address;
55         enum dev_action action;
56 };
57
58 static struct rte_eth_link pmd_link = {
59         .link_speed = ETH_SPEED_NUM_10G,
60         .link_duplex = ETH_LINK_FULL_DUPLEX,
61         .link_status = ETH_LINK_DOWN,
62         .link_autoneg = ETH_LINK_FIXED,
63 };
64
65 RTE_LOG_REGISTER(eth_ring_logtype, pmd.net.ring, NOTICE);
66
67 #define PMD_LOG(level, fmt, args...) \
68         rte_log(RTE_LOG_ ## level, eth_ring_logtype, \
69                 "%s(): " fmt "\n", __func__, ##args)
70
71 static uint16_t
72 eth_ring_rx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
73 {
74         void **ptrs = (void *)&bufs[0];
75         struct ring_queue *r = q;
76         const uint16_t nb_rx = (uint16_t)rte_ring_dequeue_burst(r->rng,
77                         ptrs, nb_bufs, NULL);
78         if (r->rng->flags & RING_F_SC_DEQ)
79                 r->rx_pkts.cnt += nb_rx;
80         else
81                 rte_atomic64_add(&(r->rx_pkts), nb_rx);
82         return nb_rx;
83 }
84
85 static uint16_t
86 eth_ring_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs)
87 {
88         void **ptrs = (void *)&bufs[0];
89         struct ring_queue *r = q;
90         const uint16_t nb_tx = (uint16_t)rte_ring_enqueue_burst(r->rng,
91                         ptrs, nb_bufs, NULL);
92         if (r->rng->flags & RING_F_SP_ENQ)
93                 r->tx_pkts.cnt += nb_tx;
94         else
95                 rte_atomic64_add(&(r->tx_pkts), nb_tx);
96         return nb_tx;
97 }
98
99 static int
100 eth_dev_configure(struct rte_eth_dev *dev __rte_unused) { return 0; }
101
102 static int
103 eth_dev_start(struct rte_eth_dev *dev)
104 {
105         dev->data->dev_link.link_status = ETH_LINK_UP;
106         return 0;
107 }
108
109 static void
110 eth_dev_stop(struct rte_eth_dev *dev)
111 {
112         dev->data->dev_started = 0;
113         dev->data->dev_link.link_status = ETH_LINK_DOWN;
114 }
115
116 static int
117 eth_dev_set_link_down(struct rte_eth_dev *dev)
118 {
119         dev->data->dev_link.link_status = ETH_LINK_DOWN;
120         return 0;
121 }
122
123 static int
124 eth_dev_set_link_up(struct rte_eth_dev *dev)
125 {
126         dev->data->dev_link.link_status = ETH_LINK_UP;
127         return 0;
128 }
129
130 static int
131 eth_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
132                                     uint16_t nb_rx_desc __rte_unused,
133                                     unsigned int socket_id __rte_unused,
134                                     const struct rte_eth_rxconf *rx_conf __rte_unused,
135                                     struct rte_mempool *mb_pool __rte_unused)
136 {
137         struct pmd_internals *internals = dev->data->dev_private;
138
139         dev->data->rx_queues[rx_queue_id] = &internals->rx_ring_queues[rx_queue_id];
140         return 0;
141 }
142
143 static int
144 eth_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
145                                     uint16_t nb_tx_desc __rte_unused,
146                                     unsigned int socket_id __rte_unused,
147                                     const struct rte_eth_txconf *tx_conf __rte_unused)
148 {
149         struct pmd_internals *internals = dev->data->dev_private;
150
151         dev->data->tx_queues[tx_queue_id] = &internals->tx_ring_queues[tx_queue_id];
152         return 0;
153 }
154
155
156 static int
157 eth_dev_info(struct rte_eth_dev *dev,
158              struct rte_eth_dev_info *dev_info)
159 {
160         struct pmd_internals *internals = dev->data->dev_private;
161
162         dev_info->max_mac_addrs = 1;
163         dev_info->max_rx_pktlen = (uint32_t)-1;
164         dev_info->max_rx_queues = (uint16_t)internals->max_rx_queues;
165         dev_info->rx_offload_capa = DEV_RX_OFFLOAD_SCATTER;
166         dev_info->tx_offload_capa = DEV_TX_OFFLOAD_MULTI_SEGS;
167         dev_info->max_tx_queues = (uint16_t)internals->max_tx_queues;
168         dev_info->min_rx_bufsize = 0;
169
170         return 0;
171 }
172
173 static int
174 eth_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
175 {
176         unsigned int i;
177         unsigned long rx_total = 0, tx_total = 0;
178         const struct pmd_internals *internal = dev->data->dev_private;
179
180         for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS &&
181                         i < dev->data->nb_rx_queues; i++) {
182                 stats->q_ipackets[i] = internal->rx_ring_queues[i].rx_pkts.cnt;
183                 rx_total += stats->q_ipackets[i];
184         }
185
186         for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS &&
187                         i < dev->data->nb_tx_queues; i++) {
188                 stats->q_opackets[i] = internal->tx_ring_queues[i].tx_pkts.cnt;
189                 tx_total += stats->q_opackets[i];
190         }
191
192         stats->ipackets = rx_total;
193         stats->opackets = tx_total;
194
195         return 0;
196 }
197
198 static int
199 eth_stats_reset(struct rte_eth_dev *dev)
200 {
201         unsigned int i;
202         struct pmd_internals *internal = dev->data->dev_private;
203
204         for (i = 0; i < dev->data->nb_rx_queues; i++)
205                 internal->rx_ring_queues[i].rx_pkts.cnt = 0;
206         for (i = 0; i < dev->data->nb_tx_queues; i++)
207                 internal->tx_ring_queues[i].tx_pkts.cnt = 0;
208
209         return 0;
210 }
211
212 static void
213 eth_mac_addr_remove(struct rte_eth_dev *dev __rte_unused,
214         uint32_t index __rte_unused)
215 {
216 }
217
218 static int
219 eth_mac_addr_add(struct rte_eth_dev *dev __rte_unused,
220         struct rte_ether_addr *mac_addr __rte_unused,
221         uint32_t index __rte_unused,
222         uint32_t vmdq __rte_unused)
223 {
224         return 0;
225 }
226
227 static void
228 eth_queue_release(void *q __rte_unused) { ; }
229 static int
230 eth_link_update(struct rte_eth_dev *dev __rte_unused,
231                 int wait_to_complete __rte_unused) { return 0; }
232
233 static int
234 eth_dev_close(struct rte_eth_dev *dev)
235 {
236         struct pmd_internals *internals = NULL;
237         struct ring_queue *r = NULL;
238         uint16_t i;
239
240         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
241                 return 0;
242
243         eth_dev_stop(dev);
244
245         internals = dev->data->dev_private;
246         if (internals->action == DEV_CREATE) {
247                 /*
248                  * it is only necessary to delete the rings in rx_queues because
249                  * they are the same used in tx_queues
250                  */
251                 for (i = 0; i < dev->data->nb_rx_queues; i++) {
252                         r = dev->data->rx_queues[i];
253                         rte_ring_free(r->rng);
254                 }
255         }
256
257         /* mac_addrs must not be freed alone because part of dev_private */
258         dev->data->mac_addrs = NULL;
259
260         return 0;
261 }
262
263 static const struct eth_dev_ops ops = {
264         .dev_close = eth_dev_close,
265         .dev_start = eth_dev_start,
266         .dev_stop = eth_dev_stop,
267         .dev_set_link_up = eth_dev_set_link_up,
268         .dev_set_link_down = eth_dev_set_link_down,
269         .dev_configure = eth_dev_configure,
270         .dev_infos_get = eth_dev_info,
271         .rx_queue_setup = eth_rx_queue_setup,
272         .tx_queue_setup = eth_tx_queue_setup,
273         .rx_queue_release = eth_queue_release,
274         .tx_queue_release = eth_queue_release,
275         .link_update = eth_link_update,
276         .stats_get = eth_stats_get,
277         .stats_reset = eth_stats_reset,
278         .mac_addr_remove = eth_mac_addr_remove,
279         .mac_addr_add = eth_mac_addr_add,
280 };
281
282 static int
283 do_eth_dev_ring_create(const char *name,
284                 struct rte_vdev_device *vdev,
285                 struct rte_ring * const rx_queues[],
286                 const unsigned int nb_rx_queues,
287                 struct rte_ring *const tx_queues[],
288                 const unsigned int nb_tx_queues,
289                 const unsigned int numa_node, enum dev_action action,
290                 struct rte_eth_dev **eth_dev_p)
291 {
292         struct rte_eth_dev_data *data = NULL;
293         struct pmd_internals *internals = NULL;
294         struct rte_eth_dev *eth_dev = NULL;
295         void **rx_queues_local = NULL;
296         void **tx_queues_local = NULL;
297         unsigned int i;
298
299         PMD_LOG(INFO, "Creating rings-backed ethdev on numa socket %u",
300                         numa_node);
301
302         rx_queues_local = rte_calloc_socket(name, nb_rx_queues,
303                                             sizeof(void *), 0, numa_node);
304         if (rx_queues_local == NULL) {
305                 rte_errno = ENOMEM;
306                 goto error;
307         }
308
309         tx_queues_local = rte_calloc_socket(name, nb_tx_queues,
310                                             sizeof(void *), 0, numa_node);
311         if (tx_queues_local == NULL) {
312                 rte_errno = ENOMEM;
313                 goto error;
314         }
315
316         internals = rte_zmalloc_socket(name, sizeof(*internals), 0, numa_node);
317         if (internals == NULL) {
318                 rte_errno = ENOMEM;
319                 goto error;
320         }
321
322         /* reserve an ethdev entry */
323         eth_dev = rte_eth_dev_allocate(name);
324         if (eth_dev == NULL) {
325                 rte_errno = ENOSPC;
326                 goto error;
327         }
328
329         /* now put it all together
330          * - store EAL device in eth_dev,
331          * - store queue data in internals,
332          * - store numa_node info in eth_dev_data
333          * - point eth_dev_data to internals
334          * - and point eth_dev structure to new eth_dev_data structure
335          */
336
337         eth_dev->device = &vdev->device;
338
339         data = eth_dev->data;
340         data->rx_queues = rx_queues_local;
341         data->tx_queues = tx_queues_local;
342
343         internals->action = action;
344         internals->max_rx_queues = nb_rx_queues;
345         internals->max_tx_queues = nb_tx_queues;
346         for (i = 0; i < nb_rx_queues; i++) {
347                 internals->rx_ring_queues[i].rng = rx_queues[i];
348                 data->rx_queues[i] = &internals->rx_ring_queues[i];
349         }
350         for (i = 0; i < nb_tx_queues; i++) {
351                 internals->tx_ring_queues[i].rng = tx_queues[i];
352                 data->tx_queues[i] = &internals->tx_ring_queues[i];
353         }
354
355         data->dev_private = internals;
356         data->nb_rx_queues = (uint16_t)nb_rx_queues;
357         data->nb_tx_queues = (uint16_t)nb_tx_queues;
358         data->dev_link = pmd_link;
359         data->mac_addrs = &internals->address;
360         data->promiscuous = 1;
361         data->all_multicast = 1;
362
363         eth_dev->dev_ops = &ops;
364         data->numa_node = numa_node;
365
366         /* finally assign rx and tx ops */
367         eth_dev->rx_pkt_burst = eth_ring_rx;
368         eth_dev->tx_pkt_burst = eth_ring_tx;
369
370         rte_eth_dev_probing_finish(eth_dev);
371         *eth_dev_p = eth_dev;
372
373         return data->port_id;
374
375 error:
376         rte_free(rx_queues_local);
377         rte_free(tx_queues_local);
378         rte_free(internals);
379
380         return -1;
381 }
382
383 int
384 rte_eth_from_rings(const char *name, struct rte_ring *const rx_queues[],
385                 const unsigned int nb_rx_queues,
386                 struct rte_ring *const tx_queues[],
387                 const unsigned int nb_tx_queues,
388                 const unsigned int numa_node)
389 {
390         struct ring_internal_args args = {
391                 .rx_queues = rx_queues,
392                 .nb_rx_queues = nb_rx_queues,
393                 .tx_queues = tx_queues,
394                 .nb_tx_queues = nb_tx_queues,
395                 .numa_node = numa_node,
396                 .addr = &args,
397         };
398         char args_str[32];
399         char ring_name[RTE_RING_NAMESIZE];
400         uint16_t port_id = RTE_MAX_ETHPORTS;
401         int ret;
402
403         /* do some parameter checking */
404         if (rx_queues == NULL && nb_rx_queues > 0) {
405                 rte_errno = EINVAL;
406                 return -1;
407         }
408         if (tx_queues == NULL && nb_tx_queues > 0) {
409                 rte_errno = EINVAL;
410                 return -1;
411         }
412         if (nb_rx_queues > RTE_PMD_RING_MAX_RX_RINGS) {
413                 rte_errno = EINVAL;
414                 return -1;
415         }
416
417         snprintf(args_str, sizeof(args_str), "%s=%p",
418                  ETH_RING_INTERNAL_ARG, &args);
419
420         ret = snprintf(ring_name, sizeof(ring_name), "net_ring_%s", name);
421         if (ret >= (int)sizeof(ring_name)) {
422                 rte_errno = ENAMETOOLONG;
423                 return -1;
424         }
425
426         ret = rte_vdev_init(ring_name, args_str);
427         if (ret) {
428                 rte_errno = EINVAL;
429                 return -1;
430         }
431
432         ret = rte_eth_dev_get_port_by_name(ring_name, &port_id);
433         if (ret) {
434                 rte_errno = ENODEV;
435                 return -1;
436         }
437
438         return port_id;
439 }
440
441 int
442 rte_eth_from_ring(struct rte_ring *r)
443 {
444         return rte_eth_from_rings(r->name, &r, 1, &r, 1,
445                         r->memzone ? r->memzone->socket_id : SOCKET_ID_ANY);
446 }
447
448 static int
449 eth_dev_ring_create(const char *name,
450                 struct rte_vdev_device *vdev,
451                 const unsigned int numa_node,
452                 enum dev_action action, struct rte_eth_dev **eth_dev)
453 {
454         /* rx and tx are so-called from point of view of first port.
455          * They are inverted from the point of view of second port
456          */
457         struct rte_ring *rxtx[RTE_PMD_RING_MAX_RX_RINGS];
458         unsigned int i;
459         char rng_name[RTE_RING_NAMESIZE];
460         unsigned int num_rings = RTE_MIN(RTE_PMD_RING_MAX_RX_RINGS,
461                         RTE_PMD_RING_MAX_TX_RINGS);
462
463         for (i = 0; i < num_rings; i++) {
464                 int cc;
465
466                 cc = snprintf(rng_name, sizeof(rng_name),
467                               "ETH_RXTX%u_%s", i, name);
468                 if (cc >= (int)sizeof(rng_name)) {
469                         rte_errno = ENAMETOOLONG;
470                         return -1;
471                 }
472
473                 rxtx[i] = (action == DEV_CREATE) ?
474                                 rte_ring_create(rng_name, 1024, numa_node,
475                                                 RING_F_SP_ENQ|RING_F_SC_DEQ) :
476                                 rte_ring_lookup(rng_name);
477                 if (rxtx[i] == NULL)
478                         return -1;
479         }
480
481         if (do_eth_dev_ring_create(name, vdev, rxtx, num_rings, rxtx, num_rings,
482                 numa_node, action, eth_dev) < 0)
483                 return -1;
484
485         return 0;
486 }
487
488 struct node_action_pair {
489         char name[PATH_MAX];
490         unsigned int node;
491         enum dev_action action;
492 };
493
494 struct node_action_list {
495         unsigned int total;
496         unsigned int count;
497         struct node_action_pair *list;
498 };
499
500 static int parse_kvlist(const char *key __rte_unused,
501                         const char *value, void *data)
502 {
503         struct node_action_list *info = data;
504         int ret;
505         char *name;
506         char *action;
507         char *node;
508         char *end;
509
510         name = strdup(value);
511
512         ret = -EINVAL;
513
514         if (!name) {
515                 PMD_LOG(WARNING, "command line parameter is empty for ring pmd!");
516                 goto out;
517         }
518
519         node = strchr(name, ':');
520         if (!node) {
521                 PMD_LOG(WARNING, "could not parse node value from %s",
522                         name);
523                 goto out;
524         }
525
526         *node = '\0';
527         node++;
528
529         action = strchr(node, ':');
530         if (!action) {
531                 PMD_LOG(WARNING, "could not parse action value from %s",
532                         node);
533                 goto out;
534         }
535
536         *action = '\0';
537         action++;
538
539         /*
540          * Need to do some sanity checking here
541          */
542
543         if (strcmp(action, ETH_RING_ACTION_ATTACH) == 0)
544                 info->list[info->count].action = DEV_ATTACH;
545         else if (strcmp(action, ETH_RING_ACTION_CREATE) == 0)
546                 info->list[info->count].action = DEV_CREATE;
547         else
548                 goto out;
549
550         errno = 0;
551         info->list[info->count].node = strtol(node, &end, 10);
552
553         if ((errno != 0) || (*end != '\0')) {
554                 PMD_LOG(WARNING,
555                         "node value %s is unparseable as a number", node);
556                 goto out;
557         }
558
559         strlcpy(info->list[info->count].name, name,
560                 sizeof(info->list[info->count].name));
561
562         info->count++;
563
564         ret = 0;
565 out:
566         free(name);
567         return ret;
568 }
569
570 static int
571 parse_internal_args(const char *key __rte_unused, const char *value,
572                 void *data)
573 {
574         struct ring_internal_args **internal_args = data;
575         void *args;
576         int ret, n;
577
578         /* make sure 'value' is valid pointer length */
579         if (strnlen(value, ETH_RING_INTERNAL_ARG_MAX_LEN) >=
580                         ETH_RING_INTERNAL_ARG_MAX_LEN) {
581                 PMD_LOG(ERR, "Error parsing internal args, argument is too long");
582                 return -1;
583         }
584
585         ret = sscanf(value, "%p%n", &args, &n);
586         if (ret == 0 || (size_t)n != strlen(value)) {
587                 PMD_LOG(ERR, "Error parsing internal args");
588
589                 return -1;
590         }
591
592         *internal_args = args;
593
594         if ((*internal_args)->addr != args)
595                 return -1;
596
597         return 0;
598 }
599
600 static int
601 rte_pmd_ring_probe(struct rte_vdev_device *dev)
602 {
603         const char *name, *params;
604         struct rte_kvargs *kvlist = NULL;
605         int ret = 0;
606         struct node_action_list *info = NULL;
607         struct rte_eth_dev *eth_dev = NULL;
608         struct ring_internal_args *internal_args;
609
610         name = rte_vdev_device_name(dev);
611         params = rte_vdev_device_args(dev);
612
613         PMD_LOG(INFO, "Initializing pmd_ring for %s", name);
614
615         if (params == NULL || params[0] == '\0') {
616                 ret = eth_dev_ring_create(name, dev, rte_socket_id(), DEV_CREATE,
617                                 &eth_dev);
618                 if (ret == -1) {
619                         PMD_LOG(INFO,
620                                 "Attach to pmd_ring for %s", name);
621                         ret = eth_dev_ring_create(name, dev, rte_socket_id(),
622                                                   DEV_ATTACH, &eth_dev);
623                 }
624         } else {
625                 kvlist = rte_kvargs_parse(params, valid_arguments);
626
627                 if (!kvlist) {
628                         PMD_LOG(INFO,
629                                 "Ignoring unsupported parameters when creatingrings-backed ethernet device");
630                         ret = eth_dev_ring_create(name, dev, rte_socket_id(),
631                                                   DEV_CREATE, &eth_dev);
632                         if (ret == -1) {
633                                 PMD_LOG(INFO,
634                                         "Attach to pmd_ring for %s",
635                                         name);
636                                 ret = eth_dev_ring_create(name, dev, rte_socket_id(),
637                                                           DEV_ATTACH, &eth_dev);
638                         }
639
640                         return ret;
641                 }
642
643                 if (rte_kvargs_count(kvlist, ETH_RING_INTERNAL_ARG) == 1) {
644                         ret = rte_kvargs_process(kvlist, ETH_RING_INTERNAL_ARG,
645                                                  parse_internal_args,
646                                                  &internal_args);
647                         if (ret < 0)
648                                 goto out_free;
649
650                         ret = do_eth_dev_ring_create(name, dev,
651                                 internal_args->rx_queues,
652                                 internal_args->nb_rx_queues,
653                                 internal_args->tx_queues,
654                                 internal_args->nb_tx_queues,
655                                 internal_args->numa_node,
656                                 DEV_ATTACH,
657                                 &eth_dev);
658                         if (ret >= 0)
659                                 ret = 0;
660                 } else {
661                         ret = rte_kvargs_count(kvlist, ETH_RING_NUMA_NODE_ACTION_ARG);
662                         info = rte_zmalloc("struct node_action_list",
663                                            sizeof(struct node_action_list) +
664                                            (sizeof(struct node_action_pair) * ret),
665                                            0);
666                         if (!info)
667                                 goto out_free;
668
669                         info->total = ret;
670                         info->list = (struct node_action_pair *)(info + 1);
671
672                         ret = rte_kvargs_process(kvlist, ETH_RING_NUMA_NODE_ACTION_ARG,
673                                                  parse_kvlist, info);
674
675                         if (ret < 0)
676                                 goto out_free;
677
678                         for (info->count = 0; info->count < info->total; info->count++) {
679                                 ret = eth_dev_ring_create(info->list[info->count].name,
680                                                           dev,
681                                                           info->list[info->count].node,
682                                                           info->list[info->count].action,
683                                                           &eth_dev);
684                                 if ((ret == -1) &&
685                                     (info->list[info->count].action == DEV_CREATE)) {
686                                         PMD_LOG(INFO,
687                                                 "Attach to pmd_ring for %s",
688                                                 name);
689                                         ret = eth_dev_ring_create(name, dev,
690                                                         info->list[info->count].node,
691                                                         DEV_ATTACH,
692                                                         &eth_dev);
693                                 }
694                         }
695                 }
696         }
697
698 out_free:
699         rte_kvargs_free(kvlist);
700         rte_free(info);
701         return ret;
702 }
703
704 static int
705 rte_pmd_ring_remove(struct rte_vdev_device *dev)
706 {
707         const char *name = rte_vdev_device_name(dev);
708         struct rte_eth_dev *eth_dev = NULL;
709
710         PMD_LOG(INFO, "Un-Initializing pmd_ring for %s", name);
711
712         if (name == NULL)
713                 return -EINVAL;
714
715         /* find an ethdev entry */
716         eth_dev = rte_eth_dev_allocated(name);
717         if (eth_dev == NULL)
718                 return 0; /* port already released */
719
720         eth_dev_close(eth_dev);
721         rte_eth_dev_release_port(eth_dev);
722         return 0;
723 }
724
725 static struct rte_vdev_driver pmd_ring_drv = {
726         .probe = rte_pmd_ring_probe,
727         .remove = rte_pmd_ring_remove,
728 };
729
730 RTE_PMD_REGISTER_VDEV(net_ring, pmd_ring_drv);
731 RTE_PMD_REGISTER_ALIAS(net_ring, eth_ring);
732 RTE_PMD_REGISTER_PARAM_STRING(net_ring,
733         ETH_RING_NUMA_NODE_ACTION_ARG "=name:node:action(ATTACH|CREATE)");