ethdev: use device name from device structure

Device name resides in two different locations, in rte_device->name and
in ethernet device private data.

For now, the copy in the ethernet device private data is required for
multi process support, the name is the how secondary process finds about
primary process device.

But in the ethdev library some eth_dev->data->name usage can be
converted to rte_device->name.

This patch updates ethdev to use rte_device->name when possible.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
This commit is contained in:
Ferruh Yigit 2017-06-09 19:36:06 +01:00 committed by Thomas Monjalon
parent 4be4659a93
commit a1e7c17555

View File

@ -179,10 +179,12 @@ rte_eth_dev_allocated(const char *name)
unsigned i; unsigned i;
for (i = 0; i < RTE_MAX_ETHPORTS; i++) { for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
if ((rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED) && if (rte_eth_devices[i].state == RTE_ETH_DEV_ATTACHED &&
strcmp(rte_eth_devices[i].data->name, name) == 0) rte_eth_devices[i].device) {
if (!strcmp(rte_eth_devices[i].device->name, name))
return &rte_eth_devices[i]; return &rte_eth_devices[i];
} }
}
return NULL; return NULL;
} }
@ -311,7 +313,7 @@ rte_eth_dev_count(void)
int int
rte_eth_dev_get_name_by_port(uint8_t port_id, char *name) rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
{ {
char *tmp; const char *tmp;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
@ -322,7 +324,7 @@ rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
/* shouldn't check 'rte_eth_devices[i].data', /* shouldn't check 'rte_eth_devices[i].data',
* because it might be overwritten by VDEV PMD */ * because it might be overwritten by VDEV PMD */
tmp = rte_eth_dev_data[port_id].name; tmp = rte_eth_devices[port_id].device->name;
strcpy(name, tmp); strcpy(name, tmp);
return 0; return 0;
} }
@ -330,6 +332,7 @@ rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)
int int
rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id) rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
{ {
int ret;
int i; int i;
if (name == NULL) { if (name == NULL) {
@ -341,11 +344,13 @@ rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)
return -ENODEV; return -ENODEV;
RTE_ETH_FOREACH_DEV(i) { RTE_ETH_FOREACH_DEV(i) {
if (!strncmp(name, if (!rte_eth_devices[i].device)
rte_eth_dev_data[i].name, strlen(name))) { continue;
ret = strncmp(name, rte_eth_devices[i].device->name,
strlen(name));
if (ret == 0) {
*port_id = i; *port_id = i;
return 0; return 0;
} }
} }
@ -438,8 +443,8 @@ rte_eth_dev_detach(uint8_t port_id, char *name)
if (rte_eth_dev_is_detachable(port_id)) if (rte_eth_dev_is_detachable(port_id))
goto err; goto err;
snprintf(name, sizeof(rte_eth_devices[port_id].data->name), snprintf(name, sizeof(rte_eth_devices[port_id].device->name),
"%s", rte_eth_devices[port_id].data->name); "%s", rte_eth_devices[port_id].device->name);
ret = rte_eal_dev_detach(rte_eth_devices[port_id].device); ret = rte_eal_dev_detach(rte_eth_devices[port_id].device);
if (ret < 0) if (ret < 0)