ethdev: expose device states
authorGaetan Rivet <gaetan.rivet@6wind.com>
Fri, 31 Mar 2017 12:04:37 +0000 (14:04 +0200)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 5 Apr 2017 20:47:57 +0000 (22:47 +0200)
The hotplug API introduced multiple states for a device with possible
values defined internally, while the related field in struct rte_eth_dev
was made public.

Exposing those states improves consistency because applications have to
deal with the device list directly.

"DEV_DETACHED" is renamed "RTE_ETH_DEV_UNUSED" to better reflect that
the emptiness of a slot is not necessarily the result of detaching a
device.

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
lib/librte_ether/rte_ethdev.c
lib/librte_ether/rte_ethdev.h

index f90f102..d737ca6 100644 (file)
@@ -138,11 +138,6 @@ enum {
        STAT_QMAP_RX
 };
 
-enum {
-       DEV_DETACHED = 0,
-       DEV_ATTACHED
-};
-
 static void
 rte_eth_dev_data_alloc(void)
 {
@@ -170,7 +165,7 @@ rte_eth_dev_allocated(const char *name)
        unsigned i;
 
        for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-               if ((rte_eth_devices[i].attached == DEV_ATTACHED) &&
+               if ((rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED) &&
                    strcmp(rte_eth_devices[i].data->name, name) == 0)
                        return &rte_eth_devices[i];
        }
@@ -183,7 +178,7 @@ rte_eth_dev_find_free_port(void)
        unsigned i;
 
        for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
-               if (rte_eth_devices[i].attached == DEV_DETACHED)
+               if (rte_eth_devices[i].state == RTE_ETH_DEV_UNUSED)
                        return i;
        }
        return RTE_MAX_ETHPORTS;
@@ -195,7 +190,7 @@ eth_dev_get(uint8_t port_id)
        struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
 
        eth_dev->data = &rte_eth_dev_data[port_id];
-       eth_dev->attached = DEV_ATTACHED;
+       eth_dev->state = RTE_ETH_DEV_ATTACHED;
        TAILQ_INIT(&(eth_dev->link_intr_cbs));
 
        eth_dev_last_created_port = port_id;
@@ -271,7 +266,7 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
        if (eth_dev == NULL)
                return -EINVAL;
 
-       eth_dev->attached = DEV_DETACHED;
+       eth_dev->state = RTE_ETH_DEV_UNUSED;
        nb_ports--;
        return 0;
 }
@@ -377,7 +372,7 @@ int
 rte_eth_dev_is_valid_port(uint8_t port_id)
 {
        if (port_id >= RTE_MAX_ETHPORTS ||
-           rte_eth_devices[port_id].attached != DEV_ATTACHED)
+           rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED)
                return 0;
        else
                return 1;
index 71a35f2..266434e 100644 (file)
@@ -1628,6 +1628,14 @@ struct rte_eth_rxtx_callback {
        void *param;
 };
 
+/**
+ * A set of values to describe the possible states of an eth device.
+ */
+enum rte_eth_dev_state {
+       RTE_ETH_DEV_UNUSED = 0,
+       RTE_ETH_DEV_ATTACHED,
+};
+
 /**
  * @internal
  * The generic data structure associated with each ethernet device.
@@ -1659,7 +1667,7 @@ struct rte_eth_dev {
         * received packets before passing them to the driver for transmission.
         */
        struct rte_eth_rxtx_callback *pre_tx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];
-       uint8_t attached; /**< Flag indicating the port is attached */
+       enum rte_eth_dev_state state:8; /**< Flag indicating the port state */
 } __rte_cache_aligned;
 
 struct rte_eth_dev_sriov {