net: align ethdev and eal driver names
[dpdk.git] / drivers / net / ring / rte_eth_ring.c
index c9ecb0e..6f9cc1a 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>
 
@@ -51,6 +51,11 @@ static const char *valid_arguments[] = {
        NULL
 };
 
+enum dev_action {
+       DEV_CREATE,
+       DEV_ATTACH
+};
+
 struct ring_queue {
        struct rte_ring *rng;
        rte_atomic64_t rx_pkts;
@@ -66,14 +71,15 @@ struct pmd_internals {
        struct ring_queue tx_ring_queues[RTE_PMD_RING_MAX_TX_RINGS];
 
        struct ether_addr address;
+       enum dev_action action;
 };
 
 
-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
@@ -113,27 +119,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;
 }
 
@@ -166,13 +172,11 @@ eth_dev_info(struct rte_eth_dev *dev,
                struct rte_eth_dev_info *dev_info)
 {
        struct pmd_internals *internals = dev->data->dev_private;
-       dev_info->driver_name = drivername;
        dev_info->max_mac_addrs = 1;
        dev_info->max_rx_pktlen = (uint32_t)-1;
        dev_info->max_rx_queues = (uint16_t)internals->max_rx_queues;
        dev_info->max_tx_queues = (uint16_t)internals->max_tx_queues;
        dev_info->min_rx_bufsize = 0;
-       dev_info->pci_dev = NULL;
 }
 
 static void
@@ -252,32 +256,19 @@ static const struct eth_dev_ops ops = {
        .mac_addr_add = eth_mac_addr_add,
 };
 
-int
-rte_eth_from_rings(const char *name, struct rte_ring *const rx_queues[],
-               const unsigned nb_rx_queues,
-               struct rte_ring *const tx_queues[],
-               const unsigned nb_tx_queues,
-               const unsigned numa_node)
+static struct rte_vdev_driver pmd_ring_drv;
+
+static int
+do_eth_dev_ring_create(const char *name,
+               struct rte_ring * const rx_queues[], const unsigned nb_rx_queues,
+               struct rte_ring *const tx_queues[], const unsigned nb_tx_queues,
+               const unsigned numa_node, enum dev_action action)
 {
        struct rte_eth_dev_data *data = NULL;
        struct pmd_internals *internals = NULL;
        struct rte_eth_dev *eth_dev = NULL;
        unsigned i;
 
-       /* do some parameter checking */
-       if (rx_queues == NULL && nb_rx_queues > 0) {
-               rte_errno = EINVAL;
-               goto error;
-       }
-       if (tx_queues == NULL && nb_tx_queues > 0) {
-               rte_errno = EINVAL;
-               goto error;
-       }
-       if (nb_rx_queues > RTE_PMD_RING_MAX_RX_RINGS) {
-               rte_errno = EINVAL;
-               goto error;
-       }
-
        RTE_LOG(INFO, PMD, "Creating rings-backed ethdev on numa socket %u\n",
                        numa_node);
 
@@ -311,7 +302,7 @@ rte_eth_from_rings(const char *name, struct rte_ring *const rx_queues[],
        }
 
        /* 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;
@@ -326,6 +317,7 @@ rte_eth_from_rings(const char *name, struct rte_ring *const rx_queues[],
        /* NOTE: we'll replace the data element, of originally allocated eth_dev
         * so the rings are local per-process */
 
+       internals->action = action;
        internals->max_rx_queues = nb_rx_queues;
        internals->max_tx_queues = nb_tx_queues;
        for (i = 0; i < nb_rx_queues; i++) {
@@ -350,11 +342,9 @@ rte_eth_from_rings(const char *name, struct rte_ring *const rx_queues[],
        eth_dev->dev_ops = &ops;
        data->dev_flags = RTE_ETH_DEV_DETACHABLE;
        data->kdrv = RTE_KDRV_NONE;
-       data->drv_name = drivername;
+       data->drv_name = pmd_ring_drv.driver.name;
        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;
@@ -372,6 +362,31 @@ error:
        return -1;
 }
 
+int
+rte_eth_from_rings(const char *name, struct rte_ring *const rx_queues[],
+               const unsigned nb_rx_queues,
+               struct rte_ring *const tx_queues[],
+               const unsigned nb_tx_queues,
+               const unsigned numa_node)
+{
+       /* do some parameter checking */
+       if (rx_queues == NULL && nb_rx_queues > 0) {
+               rte_errno = EINVAL;
+               return -1;
+       }
+       if (tx_queues == NULL && nb_tx_queues > 0) {
+               rte_errno = EINVAL;
+               return -1;
+       }
+       if (nb_rx_queues > RTE_PMD_RING_MAX_RX_RINGS) {
+               rte_errno = EINVAL;
+               return -1;
+       }
+
+       return do_eth_dev_ring_create(name, rx_queues, nb_rx_queues,
+                       tx_queues, nb_tx_queues, numa_node, DEV_ATTACH);
+}
+
 int
 rte_eth_from_ring(struct rte_ring *r)
 {
@@ -379,11 +394,6 @@ rte_eth_from_ring(struct rte_ring *r)
                        r->memzone ? r->memzone->socket_id : SOCKET_ID_ANY);
 }
 
-enum dev_action{
-       DEV_CREATE,
-       DEV_ATTACH
-};
-
 static int
 eth_dev_ring_create(const char *name, const unsigned numa_node,
                enum dev_action action)
@@ -407,7 +417,8 @@ eth_dev_ring_create(const char *name, const unsigned numa_node,
                        return -1;
        }
 
-       if (rte_eth_from_rings(name, rxtx, num_rings, rxtx, num_rings, numa_node) < 0)
+       if (do_eth_dev_ring_create(name, rxtx, num_rings, rxtx, num_rings,
+               numa_node, action) < 0)
                return -1;
 
        return 0;
@@ -491,7 +502,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;
@@ -543,7 +554,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) &&
@@ -566,9 +577,12 @@ 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;
+       struct ring_queue *r = NULL;
+       uint16_t i;
 
        RTE_LOG(INFO, PMD, "Un-Initializing pmd_ring for %s\n", name);
 
@@ -582,22 +596,34 @@ rte_pmd_ring_devuninit(const char *name)
 
        eth_dev_stop(eth_dev);
 
-       if (eth_dev->data) {
-               rte_free(eth_dev->data->rx_queues);
-               rte_free(eth_dev->data->tx_queues);
-               rte_free(eth_dev->data->dev_private);
+       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);
 
        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)");