ethdev: add dev configured flag
[dpdk.git] / lib / ethdev / rte_ethdev.c
index c607eab..6ebf52b 100644 (file)
@@ -1356,6 +1356,13 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
                return -EBUSY;
        }
 
+       /*
+        * Ensure that "dev_configured" is always 0 each time prepare to do
+        * dev_configure() to avoid any non-anticipated behaviour.
+        * And set to 1 when dev_configure() is executed successfully.
+        */
+       dev->data->dev_configured = 0;
+
         /* Store original config, as rollback required on failure */
        memcpy(&orig_conf, &dev->data->dev_conf, sizeof(dev->data->dev_conf));
 
@@ -1605,6 +1612,7 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
                goto reset_queues;
        }
 
+       dev->data->dev_configured = 1;
        rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, 0);
        return 0;
 reset_queues:
@@ -1751,6 +1759,13 @@ rte_eth_dev_start(uint16_t port_id)
 
        RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP);
 
+       if (dev->data->dev_configured == 0) {
+               RTE_ETHDEV_LOG(INFO,
+                       "Device with port_id=%"PRIu16" is not configured.\n",
+                       port_id);
+               return -EINVAL;
+       }
+
        if (dev->data->dev_started != 0) {
                RTE_ETHDEV_LOG(INFO,
                        "Device with port_id=%"PRIu16" already started\n",