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