[dpdk-dev,v9,12/14] ethdev: Add one dev_type parameter to rte_eth_dev_allocate
Commit Message
This new parameter is needed to keep device type like PCI or virtual.
Port detaching processes are different between PCI device and virtual
device.
RTE_ETH_DEV_PCI indicates device type is PCI. RTE_ETH_DEV_VIRTUAL
indicates device is virtual.
v9:
- Fix commit log.
- RTE_ETH_DEV_PHYSICAL is replaced by RTE_ETH_DEV_PCI.
(Thanks to Thomas Monjalon)
v8:
- NONE_TRACE is replaced by NO_TRACE.
- Add missing symbol in version map.
(Thanks to Qiu, Michael and Iremonger, Bernard)
v4:
- Fix comments of rte_eth_dev_type.
Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
app/test/virtual_pmd.c | 2 +-
lib/librte_ether/rte_ethdev.c | 25 +++++++++++++++++++++++--
lib/librte_ether/rte_ethdev.h | 25 ++++++++++++++++++++++++-
lib/librte_ether/rte_ether_version.map | 1 +
lib/librte_pmd_af_packet/rte_eth_af_packet.c | 2 +-
lib/librte_pmd_bond/rte_eth_bond_api.c | 2 +-
lib/librte_pmd_pcap/rte_eth_pcap.c | 2 +-
lib/librte_pmd_ring/rte_eth_ring.c | 2 +-
lib/librte_pmd_xenvirt/rte_eth_xenvirt.c | 2 +-
9 files changed, 54 insertions(+), 9 deletions(-)
Comments
> -----Original Message-----
> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
> Sent: Thursday, February 19, 2015 2:50 AM
> To: dev@dpdk.org
> Cc: Qiu, Michael; Iremonger, Bernard; thomas.monjalon@6wind.com; Tetsuya Mukawa
> Subject: [PATCH v9 12/14] ethdev: Add one dev_type parameter to rte_eth_dev_allocate
>
> This new parameter is needed to keep device type like PCI or virtual.
> Port detaching processes are different between PCI device and virtual device.
> RTE_ETH_DEV_PCI indicates device type is PCI. RTE_ETH_DEV_VIRTUAL indicates device is virtual.
>
> v9:
> - Fix commit log.
> - RTE_ETH_DEV_PHYSICAL is replaced by RTE_ETH_DEV_PCI.
> (Thanks to Thomas Monjalon)
> v8:
> - NONE_TRACE is replaced by NO_TRACE.
> - Add missing symbol in version map.
> (Thanks to Qiu, Michael and Iremonger, Bernard)
> v4:
> - Fix comments of rte_eth_dev_type.
>
> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
> ---
> app/test/virtual_pmd.c | 2 +-
> lib/librte_ether/rte_ethdev.c | 25 +++++++++++++++++++++++--
> lib/librte_ether/rte_ethdev.h | 25 ++++++++++++++++++++++++-
> lib/librte_ether/rte_ether_version.map | 1 +
> lib/librte_pmd_af_packet/rte_eth_af_packet.c | 2 +-
> lib/librte_pmd_bond/rte_eth_bond_api.c | 2 +-
> lib/librte_pmd_pcap/rte_eth_pcap.c | 2 +-
> lib/librte_pmd_ring/rte_eth_ring.c | 2 +-
> lib/librte_pmd_xenvirt/rte_eth_xenvirt.c | 2 +-
> 9 files changed, 54 insertions(+), 9 deletions(-)
>
> diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c index 9fac95d..c02644a 100644
> --- a/app/test/virtual_pmd.c
> +++ b/app/test/virtual_pmd.c
> @@ -556,7 +556,7 @@ virtual_ethdev_create(const char *name, struct ether_addr *mac_addr,
> goto err;
>
> /* reserve an ethdev entry */
> - eth_dev = rte_eth_dev_allocate(name);
> + eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_PCI);
> if (eth_dev == NULL)
> goto err;
>
> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 3b64f3a..201c04a
> 100644
> --- a/lib/librte_ether/rte_ethdev.c
> +++ b/lib/librte_ether/rte_ethdev.c
> @@ -227,7 +227,7 @@ rte_eth_dev_find_free_port(void) }
>
> struct rte_eth_dev *
> -rte_eth_dev_allocate(const char *name)
> +rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
> {
> uint8_t port_id;
> struct rte_eth_dev *eth_dev;
> @@ -251,6 +251,7 @@ rte_eth_dev_allocate(const char *name)
> snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
> eth_dev->data->port_id = port_id;
> eth_dev->attached = DEV_ATTACHED;
> + eth_dev->dev_type = type;
> nb_ports++;
> return eth_dev;
> }
> @@ -262,6 +263,7 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
> return -EINVAL;
>
> eth_dev->attached = 0;
> + eth_dev->dev_type = RTE_ETH_DEV_UNKNOWN;
> nb_ports--;
> return 0;
> }
> @@ -299,7 +301,7 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv,
> /* Create unique Ethernet device name using PCI address */
> rte_eth_dev_create_unique_device_name(ethdev_name, pci_dev);
>
> - eth_dev = rte_eth_dev_allocate(ethdev_name);
> + eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
> if (eth_dev == NULL)
> return -ENOMEM;
>
> @@ -424,6 +426,14 @@ rte_eth_dev_count(void)
> return (nb_ports);
> }
>
> +enum rte_eth_dev_type
> +rte_eth_dev_get_device_type(uint8_t port_id) {
> + if (!rte_eth_dev_is_valid_port(port_id))
> + return -1;
> + return rte_eth_devices[port_id].dev_type;
> +}
> +
> int
> rte_eth_dev_save(struct rte_eth_dev *devs, size_t size) { @@ -521,6 +531,17 @@
> rte_eth_dev_is_detachable(uint8_t port_id)
> return -EINVAL;
> }
>
> + if (rte_eth_devices[port_id].dev_type == RTE_ETH_DEV_PCI) {
> + switch (rte_eth_devices[port_id].pci_dev->pt_driver) {
> + case RTE_PT_IGB_UIO:
> + case RTE_PT_UIO_GENERIC:
> + break;
> + case RTE_PT_VFIO:
> + default:
> + return -ENOTSUP;
> + }
> + }
> +
> drv_flags = rte_eth_devices[port_id].driver->pci_drv.drv_flags;
> return !(drv_flags & RTE_PCI_DRV_DETACHABLE); } diff --git a/lib/librte_ether/rte_ethdev.h
> b/lib/librte_ether/rte_ethdev.h index 90b7f25..4f66bb6 100644
> --- a/lib/librte_ether/rte_ethdev.h
> +++ b/lib/librte_ether/rte_ethdev.h
> @@ -1523,6 +1523,17 @@ struct eth_dev_ops { };
>
> /**
> + * The eth device type
> + */
> +enum rte_eth_dev_type {
> + RTE_ETH_DEV_UNKNOWN, /**< unknown device type */
> + RTE_ETH_DEV_PCI,
> + /**< Physical function and Virtual function of PCI devices */
> + RTE_ETH_DEV_VIRTUAL, /**< non hardware device */
> + RTE_ETH_DEV_MAX /**< max value of this enum */
> +};
> +
> +/**
> * @internal
> * The generic data structure associated with each ethernet device.
> *
> @@ -1541,6 +1552,7 @@ struct rte_eth_dev {
> struct rte_pci_device *pci_dev; /**< PCI info. supplied by probing */
> struct rte_eth_dev_cb_list callbacks; /**< User application callbacks */
> uint8_t attached; /**< Flag indicating the port is attached */
> + enum rte_eth_dev_type dev_type; /**< Flag indicating the device type
> +*/
> };
>
> struct rte_eth_dev_sriov {
> @@ -1618,6 +1630,15 @@ extern uint8_t rte_eth_dev_count(void);
>
> /**
> * Function for internal use by port hotplug functions.
> + * Get the device type to know whether the device is physical or virtual.
> + * @param port_id The pointer to the port id
Hi Tetsuya,
" The pointer to the port id" should be removed.
Regards,
Bernard.
> + * @return
> + * - Device type.
> + */
> +extern enum rte_eth_dev_type rte_eth_dev_get_device_type(uint8_t
> +port_id);
> +
> +/**
> + * Function for internal use by port hotplug functions.
> * Copies current ethdev structures to the specified pointer.
> *
> * @param devs The pointer to the ethdev structures
> @@ -1706,10 +1727,12 @@ extern struct rte_eth_dev *rte_eth_dev_allocated(const char *name);
> * to that slot for the driver to use.
> *
> * @param name Unique identifier name for each Ethernet device
> + * @param type Device type of this Ethernet device
> * @return
> * - Slot in the rte_dev_devices array for a new device;
> */
> -struct rte_eth_dev *rte_eth_dev_allocate(const char *name);
> +struct rte_eth_dev *rte_eth_dev_allocate(const char *name,
> + enum rte_eth_dev_type type);
>
> /**
> * Function for internal use by dummy drivers primarily, e.g. ring-based diff --git
> a/lib/librte_ether/rte_ether_version.map b/lib/librte_ether/rte_ether_version.map
> index 1d039ed..b78f5e3 100644
> --- a/lib/librte_ether/rte_ether_version.map
> +++ b/lib/librte_ether/rte_ether_version.map
> @@ -116,6 +116,7 @@ DPDK_2.0 {
> rte_eth_dev_get_port_by_addr;
> rte_eth_dev_get_changed_port;
> rte_eth_dev_save;
> + rte_eth_dev_get_device_type;
>
> local: *;
> };
> diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c
> b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
> index 1ffe1cd..80e9bdf 100644
> --- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c
> +++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
> @@ -649,7 +649,7 @@ rte_pmd_init_internals(const char *name,
> }
>
> /* reserve an ethdev entry */
> - *eth_dev = rte_eth_dev_allocate(name);
> + *eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
> if (*eth_dev == NULL)
> goto error;
>
> diff --git a/lib/librte_pmd_bond/rte_eth_bond_api.c b/lib/librte_pmd_bond/rte_eth_bond_api.c
> index 4ab3267..7a6a5f7 100644
> --- a/lib/librte_pmd_bond/rte_eth_bond_api.c
> +++ b/lib/librte_pmd_bond/rte_eth_bond_api.c
> @@ -235,7 +235,7 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
> }
>
> /* reserve an ethdev entry */
> - eth_dev = rte_eth_dev_allocate(name);
> + eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
> if (eth_dev == NULL) {
> RTE_BOND_LOG(ERR, "Unable to allocate rte_eth_dev");
> goto err;
> diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_eth_pcap.c
> index d299288..af7fae8 100644
> --- a/lib/librte_pmd_pcap/rte_eth_pcap.c
> +++ b/lib/librte_pmd_pcap/rte_eth_pcap.c
> @@ -709,7 +709,7 @@ rte_pmd_init_internals(const char *name, const unsigned nb_rx_queues,
> goto error;
>
> /* reserve an ethdev entry */
> - *eth_dev = rte_eth_dev_allocate(name);
> + *eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
> if (*eth_dev == NULL)
> goto error;
>
> diff --git a/lib/librte_pmd_ring/rte_eth_ring.c b/lib/librte_pmd_ring/rte_eth_ring.c
> index d5b1686..c837fcd 100644
> --- a/lib/librte_pmd_ring/rte_eth_ring.c
> +++ b/lib/librte_pmd_ring/rte_eth_ring.c
> @@ -255,7 +255,7 @@ rte_eth_from_rings(const char *name, struct rte_ring *const rx_queues[],
> goto error;
>
> /* reserve an ethdev entry */
> - eth_dev = rte_eth_dev_allocate(name);
> + eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
> if (eth_dev == NULL)
> goto error;
>
> diff --git a/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c b/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c
> index 04e30c9..bc403d6 100644
> --- a/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c
> +++ b/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c
> @@ -648,7 +648,7 @@ eth_dev_xenvirt_create(const char *name, const char *params,
> goto err;
>
> /* reserve an ethdev entry */
> - eth_dev = rte_eth_dev_allocate(name);
> + eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
> if (eth_dev == NULL)
> goto err;
>
> --
> 1.9.1
On 2015/02/19 23:51, Iremonger, Bernard wrote:
>
>> -----Original Message-----
>> From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp]
>> Sent: Thursday, February 19, 2015 2:50 AM
>> To: dev@dpdk.org
>> Cc: Qiu, Michael; Iremonger, Bernard; thomas.monjalon@6wind.com; Tetsuya Mukawa
>> Subject: [PATCH v9 12/14] ethdev: Add one dev_type parameter to rte_eth_dev_allocate
>>
>> This new parameter is needed to keep device type like PCI or virtual.
>> Port detaching processes are different between PCI device and virtual device.
>> RTE_ETH_DEV_PCI indicates device type is PCI. RTE_ETH_DEV_VIRTUAL indicates device is virtual.
>>
>> v9:
>> - Fix commit log.
>> - RTE_ETH_DEV_PHYSICAL is replaced by RTE_ETH_DEV_PCI.
>> (Thanks to Thomas Monjalon)
>> v8:
>> - NONE_TRACE is replaced by NO_TRACE.
>> - Add missing symbol in version map.
>> (Thanks to Qiu, Michael and Iremonger, Bernard)
>> v4:
>> - Fix comments of rte_eth_dev_type.
>>
>> Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
>> ---
>> app/test/virtual_pmd.c | 2 +-
>> lib/librte_ether/rte_ethdev.c | 25 +++++++++++++++++++++++--
>> lib/librte_ether/rte_ethdev.h | 25 ++++++++++++++++++++++++-
>> lib/librte_ether/rte_ether_version.map | 1 +
>> lib/librte_pmd_af_packet/rte_eth_af_packet.c | 2 +-
>> lib/librte_pmd_bond/rte_eth_bond_api.c | 2 +-
>> lib/librte_pmd_pcap/rte_eth_pcap.c | 2 +-
>> lib/librte_pmd_ring/rte_eth_ring.c | 2 +-
>> lib/librte_pmd_xenvirt/rte_eth_xenvirt.c | 2 +-
>> 9 files changed, 54 insertions(+), 9 deletions(-)
>>
>> diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c index 9fac95d..c02644a 100644
>> --- a/app/test/virtual_pmd.c
>> +++ b/app/test/virtual_pmd.c
>> @@ -556,7 +556,7 @@ virtual_ethdev_create(const char *name, struct ether_addr *mac_addr,
>> goto err;
>>
>> /* reserve an ethdev entry */
>> - eth_dev = rte_eth_dev_allocate(name);
>> + eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_PCI);
>> if (eth_dev == NULL)
>> goto err;
>>
>> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 3b64f3a..201c04a
>> 100644
>> --- a/lib/librte_ether/rte_ethdev.c
>> +++ b/lib/librte_ether/rte_ethdev.c
>> @@ -227,7 +227,7 @@ rte_eth_dev_find_free_port(void) }
>>
>> struct rte_eth_dev *
>> -rte_eth_dev_allocate(const char *name)
>> +rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
>> {
>> uint8_t port_id;
>> struct rte_eth_dev *eth_dev;
>> @@ -251,6 +251,7 @@ rte_eth_dev_allocate(const char *name)
>> snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
>> eth_dev->data->port_id = port_id;
>> eth_dev->attached = DEV_ATTACHED;
>> + eth_dev->dev_type = type;
>> nb_ports++;
>> return eth_dev;
>> }
>> @@ -262,6 +263,7 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
>> return -EINVAL;
>>
>> eth_dev->attached = 0;
>> + eth_dev->dev_type = RTE_ETH_DEV_UNKNOWN;
>> nb_ports--;
>> return 0;
>> }
>> @@ -299,7 +301,7 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv,
>> /* Create unique Ethernet device name using PCI address */
>> rte_eth_dev_create_unique_device_name(ethdev_name, pci_dev);
>>
>> - eth_dev = rte_eth_dev_allocate(ethdev_name);
>> + eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
>> if (eth_dev == NULL)
>> return -ENOMEM;
>>
>> @@ -424,6 +426,14 @@ rte_eth_dev_count(void)
>> return (nb_ports);
>> }
>>
>> +enum rte_eth_dev_type
>> +rte_eth_dev_get_device_type(uint8_t port_id) {
>> + if (!rte_eth_dev_is_valid_port(port_id))
>> + return -1;
>> + return rte_eth_devices[port_id].dev_type;
>> +}
>> +
>> int
>> rte_eth_dev_save(struct rte_eth_dev *devs, size_t size) { @@ -521,6 +531,17 @@
>> rte_eth_dev_is_detachable(uint8_t port_id)
>> return -EINVAL;
>> }
>>
>> + if (rte_eth_devices[port_id].dev_type == RTE_ETH_DEV_PCI) {
>> + switch (rte_eth_devices[port_id].pci_dev->pt_driver) {
>> + case RTE_PT_IGB_UIO:
>> + case RTE_PT_UIO_GENERIC:
>> + break;
>> + case RTE_PT_VFIO:
>> + default:
>> + return -ENOTSUP;
>> + }
>> + }
>> +
>> drv_flags = rte_eth_devices[port_id].driver->pci_drv.drv_flags;
>> return !(drv_flags & RTE_PCI_DRV_DETACHABLE); } diff --git a/lib/librte_ether/rte_ethdev.h
>> b/lib/librte_ether/rte_ethdev.h index 90b7f25..4f66bb6 100644
>> --- a/lib/librte_ether/rte_ethdev.h
>> +++ b/lib/librte_ether/rte_ethdev.h
>> @@ -1523,6 +1523,17 @@ struct eth_dev_ops { };
>>
>> /**
>> + * The eth device type
>> + */
>> +enum rte_eth_dev_type {
>> + RTE_ETH_DEV_UNKNOWN, /**< unknown device type */
>> + RTE_ETH_DEV_PCI,
>> + /**< Physical function and Virtual function of PCI devices */
>> + RTE_ETH_DEV_VIRTUAL, /**< non hardware device */
>> + RTE_ETH_DEV_MAX /**< max value of this enum */
>> +};
>> +
>> +/**
>> * @internal
>> * The generic data structure associated with each ethernet device.
>> *
>> @@ -1541,6 +1552,7 @@ struct rte_eth_dev {
>> struct rte_pci_device *pci_dev; /**< PCI info. supplied by probing */
>> struct rte_eth_dev_cb_list callbacks; /**< User application callbacks */
>> uint8_t attached; /**< Flag indicating the port is attached */
>> + enum rte_eth_dev_type dev_type; /**< Flag indicating the device type
>> +*/
>> };
>>
>> struct rte_eth_dev_sriov {
>> @@ -1618,6 +1630,15 @@ extern uint8_t rte_eth_dev_count(void);
>>
>> /**
>> * Function for internal use by port hotplug functions.
>> + * Get the device type to know whether the device is physical or virtual.
>> + * @param port_id The pointer to the port id
> Hi Tetsuya,
>
> " The pointer to the port id" should be removed.
I will fix it in next patch.
Tetsuya
> Regards,
>
> Bernard.
>
>
>> + * @return
>> + * - Device type.
>> + */
>> +extern enum rte_eth_dev_type rte_eth_dev_get_device_type(uint8_t
>> +port_id);
>> +
>> +/**
>> + * Function for internal use by port hotplug functions.
>> * Copies current ethdev structures to the specified pointer.
>> *
>> * @param devs The pointer to the ethdev structures
>> @@ -1706,10 +1727,12 @@ extern struct rte_eth_dev *rte_eth_dev_allocated(const char *name);
>> * to that slot for the driver to use.
>> *
>> * @param name Unique identifier name for each Ethernet device
>> + * @param type Device type of this Ethernet device
>> * @return
>> * - Slot in the rte_dev_devices array for a new device;
>> */
>> -struct rte_eth_dev *rte_eth_dev_allocate(const char *name);
>> +struct rte_eth_dev *rte_eth_dev_allocate(const char *name,
>> + enum rte_eth_dev_type type);
>>
>> /**
>> * Function for internal use by dummy drivers primarily, e.g. ring-based diff --git
>> a/lib/librte_ether/rte_ether_version.map b/lib/librte_ether/rte_ether_version.map
>> index 1d039ed..b78f5e3 100644
>> --- a/lib/librte_ether/rte_ether_version.map
>> +++ b/lib/librte_ether/rte_ether_version.map
>> @@ -116,6 +116,7 @@ DPDK_2.0 {
>> rte_eth_dev_get_port_by_addr;
>> rte_eth_dev_get_changed_port;
>> rte_eth_dev_save;
>> + rte_eth_dev_get_device_type;
>>
>> local: *;
>> };
>> diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c
>> b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
>> index 1ffe1cd..80e9bdf 100644
>> --- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c
>> +++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c
>> @@ -649,7 +649,7 @@ rte_pmd_init_internals(const char *name,
>> }
>>
>> /* reserve an ethdev entry */
>> - *eth_dev = rte_eth_dev_allocate(name);
>> + *eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
>> if (*eth_dev == NULL)
>> goto error;
>>
>> diff --git a/lib/librte_pmd_bond/rte_eth_bond_api.c b/lib/librte_pmd_bond/rte_eth_bond_api.c
>> index 4ab3267..7a6a5f7 100644
>> --- a/lib/librte_pmd_bond/rte_eth_bond_api.c
>> +++ b/lib/librte_pmd_bond/rte_eth_bond_api.c
>> @@ -235,7 +235,7 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
>> }
>>
>> /* reserve an ethdev entry */
>> - eth_dev = rte_eth_dev_allocate(name);
>> + eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
>> if (eth_dev == NULL) {
>> RTE_BOND_LOG(ERR, "Unable to allocate rte_eth_dev");
>> goto err;
>> diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_eth_pcap.c
>> index d299288..af7fae8 100644
>> --- a/lib/librte_pmd_pcap/rte_eth_pcap.c
>> +++ b/lib/librte_pmd_pcap/rte_eth_pcap.c
>> @@ -709,7 +709,7 @@ rte_pmd_init_internals(const char *name, const unsigned nb_rx_queues,
>> goto error;
>>
>> /* reserve an ethdev entry */
>> - *eth_dev = rte_eth_dev_allocate(name);
>> + *eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
>> if (*eth_dev == NULL)
>> goto error;
>>
>> diff --git a/lib/librte_pmd_ring/rte_eth_ring.c b/lib/librte_pmd_ring/rte_eth_ring.c
>> index d5b1686..c837fcd 100644
>> --- a/lib/librte_pmd_ring/rte_eth_ring.c
>> +++ b/lib/librte_pmd_ring/rte_eth_ring.c
>> @@ -255,7 +255,7 @@ rte_eth_from_rings(const char *name, struct rte_ring *const rx_queues[],
>> goto error;
>>
>> /* reserve an ethdev entry */
>> - eth_dev = rte_eth_dev_allocate(name);
>> + eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
>> if (eth_dev == NULL)
>> goto error;
>>
>> diff --git a/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c b/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c
>> index 04e30c9..bc403d6 100644
>> --- a/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c
>> +++ b/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c
>> @@ -648,7 +648,7 @@ eth_dev_xenvirt_create(const char *name, const char *params,
>> goto err;
>>
>> /* reserve an ethdev entry */
>> - eth_dev = rte_eth_dev_allocate(name);
>> + eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
>> if (eth_dev == NULL)
>> goto err;
>>
>> --
>> 1.9.1
@@ -556,7 +556,7 @@ virtual_ethdev_create(const char *name, struct ether_addr *mac_addr,
goto err;
/* reserve an ethdev entry */
- eth_dev = rte_eth_dev_allocate(name);
+ eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_PCI);
if (eth_dev == NULL)
goto err;
@@ -227,7 +227,7 @@ rte_eth_dev_find_free_port(void)
}
struct rte_eth_dev *
-rte_eth_dev_allocate(const char *name)
+rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)
{
uint8_t port_id;
struct rte_eth_dev *eth_dev;
@@ -251,6 +251,7 @@ rte_eth_dev_allocate(const char *name)
snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
eth_dev->data->port_id = port_id;
eth_dev->attached = DEV_ATTACHED;
+ eth_dev->dev_type = type;
nb_ports++;
return eth_dev;
}
@@ -262,6 +263,7 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev)
return -EINVAL;
eth_dev->attached = 0;
+ eth_dev->dev_type = RTE_ETH_DEV_UNKNOWN;
nb_ports--;
return 0;
}
@@ -299,7 +301,7 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv,
/* Create unique Ethernet device name using PCI address */
rte_eth_dev_create_unique_device_name(ethdev_name, pci_dev);
- eth_dev = rte_eth_dev_allocate(ethdev_name);
+ eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PCI);
if (eth_dev == NULL)
return -ENOMEM;
@@ -424,6 +426,14 @@ rte_eth_dev_count(void)
return (nb_ports);
}
+enum rte_eth_dev_type
+rte_eth_dev_get_device_type(uint8_t port_id)
+{
+ if (!rte_eth_dev_is_valid_port(port_id))
+ return -1;
+ return rte_eth_devices[port_id].dev_type;
+}
+
int
rte_eth_dev_save(struct rte_eth_dev *devs, size_t size)
{
@@ -521,6 +531,17 @@ rte_eth_dev_is_detachable(uint8_t port_id)
return -EINVAL;
}
+ if (rte_eth_devices[port_id].dev_type == RTE_ETH_DEV_PCI) {
+ switch (rte_eth_devices[port_id].pci_dev->pt_driver) {
+ case RTE_PT_IGB_UIO:
+ case RTE_PT_UIO_GENERIC:
+ break;
+ case RTE_PT_VFIO:
+ default:
+ return -ENOTSUP;
+ }
+ }
+
drv_flags = rte_eth_devices[port_id].driver->pci_drv.drv_flags;
return !(drv_flags & RTE_PCI_DRV_DETACHABLE);
}
@@ -1523,6 +1523,17 @@ struct eth_dev_ops {
};
/**
+ * The eth device type
+ */
+enum rte_eth_dev_type {
+ RTE_ETH_DEV_UNKNOWN, /**< unknown device type */
+ RTE_ETH_DEV_PCI,
+ /**< Physical function and Virtual function of PCI devices */
+ RTE_ETH_DEV_VIRTUAL, /**< non hardware device */
+ RTE_ETH_DEV_MAX /**< max value of this enum */
+};
+
+/**
* @internal
* The generic data structure associated with each ethernet device.
*
@@ -1541,6 +1552,7 @@ struct rte_eth_dev {
struct rte_pci_device *pci_dev; /**< PCI info. supplied by probing */
struct rte_eth_dev_cb_list callbacks; /**< User application callbacks */
uint8_t attached; /**< Flag indicating the port is attached */
+ enum rte_eth_dev_type dev_type; /**< Flag indicating the device type */
};
struct rte_eth_dev_sriov {
@@ -1618,6 +1630,15 @@ extern uint8_t rte_eth_dev_count(void);
/**
* Function for internal use by port hotplug functions.
+ * Get the device type to know whether the device is physical or virtual.
+ * @param port_id The pointer to the port id
+ * @return
+ * - Device type.
+ */
+extern enum rte_eth_dev_type rte_eth_dev_get_device_type(uint8_t port_id);
+
+/**
+ * Function for internal use by port hotplug functions.
* Copies current ethdev structures to the specified pointer.
*
* @param devs The pointer to the ethdev structures
@@ -1706,10 +1727,12 @@ extern struct rte_eth_dev *rte_eth_dev_allocated(const char *name);
* to that slot for the driver to use.
*
* @param name Unique identifier name for each Ethernet device
+ * @param type Device type of this Ethernet device
* @return
* - Slot in the rte_dev_devices array for a new device;
*/
-struct rte_eth_dev *rte_eth_dev_allocate(const char *name);
+struct rte_eth_dev *rte_eth_dev_allocate(const char *name,
+ enum rte_eth_dev_type type);
/**
* Function for internal use by dummy drivers primarily, e.g. ring-based
@@ -116,6 +116,7 @@ DPDK_2.0 {
rte_eth_dev_get_port_by_addr;
rte_eth_dev_get_changed_port;
rte_eth_dev_save;
+ rte_eth_dev_get_device_type;
local: *;
};
@@ -649,7 +649,7 @@ rte_pmd_init_internals(const char *name,
}
/* reserve an ethdev entry */
- *eth_dev = rte_eth_dev_allocate(name);
+ *eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
if (*eth_dev == NULL)
goto error;
@@ -235,7 +235,7 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
}
/* reserve an ethdev entry */
- eth_dev = rte_eth_dev_allocate(name);
+ eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
if (eth_dev == NULL) {
RTE_BOND_LOG(ERR, "Unable to allocate rte_eth_dev");
goto err;
@@ -709,7 +709,7 @@ rte_pmd_init_internals(const char *name, const unsigned nb_rx_queues,
goto error;
/* reserve an ethdev entry */
- *eth_dev = rte_eth_dev_allocate(name);
+ *eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
if (*eth_dev == NULL)
goto error;
@@ -255,7 +255,7 @@ rte_eth_from_rings(const char *name, struct rte_ring *const rx_queues[],
goto error;
/* reserve an ethdev entry */
- eth_dev = rte_eth_dev_allocate(name);
+ eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
if (eth_dev == NULL)
goto error;
@@ -648,7 +648,7 @@ eth_dev_xenvirt_create(const char *name, const char *params,
goto err;
/* reserve an ethdev entry */
- eth_dev = rte_eth_dev_allocate(name);
+ eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL);
if (eth_dev == NULL)
goto err;