ethdev: initialize more fields on allocation
[dpdk.git] / drivers / net / ring / rte_eth_ring.c
index ba19cd7..c7726f4 100644 (file)
@@ -38,7 +38,7 @@
 #include <rte_memcpy.h>
 #include <rte_memzone.h>
 #include <rte_string_fns.h>
-#include <rte_dev.h>
+#include <rte_vdev.h>
 #include <rte_kvargs.h>
 #include <rte_errno.h>
 
@@ -77,9 +77,10 @@ struct pmd_internals {
 
 static const char *drivername = "Rings PMD";
 static struct rte_eth_link pmd_link = {
-               .link_speed = 10000,
+               .link_speed = ETH_SPEED_NUM_10G,
                .link_duplex = ETH_LINK_FULL_DUPLEX,
-               .link_status = 0
+               .link_status = ETH_LINK_DOWN,
+               .link_autoneg = ETH_LINK_SPEED_AUTONEG
 };
 
 static uint16_t
@@ -119,27 +120,27 @@ eth_dev_configure(struct rte_eth_dev *dev __rte_unused) { return 0; }
 static int
 eth_dev_start(struct rte_eth_dev *dev)
 {
-       dev->data->dev_link.link_status = 1;
+       dev->data->dev_link.link_status = ETH_LINK_UP;
        return 0;
 }
 
 static void
 eth_dev_stop(struct rte_eth_dev *dev)
 {
-       dev->data->dev_link.link_status = 0;
+       dev->data->dev_link.link_status = ETH_LINK_DOWN;
 }
 
 static int
 eth_dev_set_link_down(struct rte_eth_dev *dev)
 {
-       dev->data->dev_link.link_status = 0;
+       dev->data->dev_link.link_status = ETH_LINK_DOWN;
        return 0;
 }
 
 static int
 eth_dev_set_link_up(struct rte_eth_dev *dev)
 {
-       dev->data->dev_link.link_status = 1;
+       dev->data->dev_link.link_status = ETH_LINK_UP;
        return 0;
 }
 
@@ -302,7 +303,7 @@ do_eth_dev_ring_create(const char *name,
        }
 
        /* reserve an ethdev entry */
-       eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
+       eth_dev = rte_eth_dev_allocate(name);
        if (eth_dev == NULL) {
                rte_errno = ENOSPC;
                goto error;
@@ -345,8 +346,6 @@ do_eth_dev_ring_create(const char *name,
        data->drv_name = drivername;
        data->numa_node = numa_node;
 
-       TAILQ_INIT(&(eth_dev->link_intr_cbs));
-
        /* finally assign rx and tx ops */
        eth_dev->rx_pkt_burst = eth_ring_rx;
        eth_dev->tx_pkt_burst = eth_ring_tx;
@@ -504,7 +503,7 @@ out:
 }
 
 static int
-rte_pmd_ring_devinit(const char *name, const char *params)
+rte_pmd_ring_probe(const char *name, const char *params)
 {
        struct rte_kvargs *kvlist = NULL;
        int ret = 0;
@@ -556,7 +555,7 @@ rte_pmd_ring_devinit(const char *name, const char *params)
                                goto out_free;
 
                        for (info->count = 0; info->count < info->total; info->count++) {
-                               ret = eth_dev_ring_create(name,
+                               ret = eth_dev_ring_create(info->list[info->count].name,
                                                          info->list[info->count].node,
                                                          info->list[info->count].action);
                                if ((ret == -1) &&
@@ -579,7 +578,7 @@ out_free:
 }
 
 static int
-rte_pmd_ring_devuninit(const char *name)
+rte_pmd_ring_remove(const char *name)
 {
        struct rte_eth_dev *eth_dev = NULL;
        struct pmd_internals *internals = NULL;
@@ -598,35 +597,34 @@ rte_pmd_ring_devuninit(const char *name)
 
        eth_dev_stop(eth_dev);
 
-       if (eth_dev->data) {
-               internals = eth_dev->data->dev_private;
-               if (internals->action == DEV_CREATE) {
-                       /*
-                        * it is only necessary to delete the rings in rx_queues because
-                        * they are the same used in tx_queues
-                        */
-                       for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
-                               r = eth_dev->data->rx_queues[i];
-                               rte_ring_free(r->rng);
-                       }
+       internals = eth_dev->data->dev_private;
+       if (internals->action == DEV_CREATE) {
+               /*
+                * it is only necessary to delete the rings in rx_queues because
+                * they are the same used in tx_queues
+                */
+               for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
+                       r = eth_dev->data->rx_queues[i];
+                       rte_ring_free(r->rng);
                }
-
-               rte_free(eth_dev->data->rx_queues);
-               rte_free(eth_dev->data->tx_queues);
-               rte_free(eth_dev->data->dev_private);
        }
 
+       rte_free(eth_dev->data->rx_queues);
+       rte_free(eth_dev->data->tx_queues);
+       rte_free(eth_dev->data->dev_private);
+
        rte_free(eth_dev->data);
 
        rte_eth_dev_release_port(eth_dev);
        return 0;
 }
 
-static struct rte_driver pmd_ring_drv = {
-       .name = "eth_ring",
-       .type = PMD_VDEV,
-       .init = rte_pmd_ring_devinit,
-       .uninit = rte_pmd_ring_devuninit,
+static struct rte_vdev_driver pmd_ring_drv = {
+       .probe = rte_pmd_ring_probe,
+       .remove = rte_pmd_ring_remove,
 };
 
-PMD_REGISTER_DRIVER(pmd_ring_drv);
+RTE_PMD_REGISTER_VDEV(net_ring, pmd_ring_drv);
+RTE_PMD_REGISTER_ALIAS(net_ring, eth_ring);
+RTE_PMD_REGISTER_PARAM_STRING(net_ring,
+       ETH_RING_NUMA_NODE_ACTION_ARG "=name:node:action(ATTACH|CREATE)");