X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_ether%2Frte_ethdev.c;h=7821a88838ed730293dfaac01cf208168e8d61d4;hb=3c20cf98e2c99e6178585299056f3fb6d08467f3;hp=a364af3408ce232c2813ed7c406d7c276db8bcb8;hpb=cd8c7c7ce241d2ea7c059a9df07caa9411ef19ed;p=dpdk.git diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index a364af3408..7821a88838 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -534,6 +534,12 @@ rte_eth_dev_get_sec_ctx(uint16_t port_id) uint16_t rte_eth_dev_count(void) +{ + return rte_eth_dev_count_avail(); +} + +uint16_t +rte_eth_dev_count_avail(void) { uint16_t p; uint16_t count; @@ -546,6 +552,18 @@ rte_eth_dev_count(void) return count; } +uint16_t +rte_eth_dev_count_total(void) +{ + uint16_t port, count = 0; + + for (port = 0; port < RTE_MAX_ETHPORTS; port++) + if (rte_eth_devices[port].state != RTE_ETH_DEV_UNUSED) + count++; + + return count; +} + int rte_eth_dev_get_name_by_port(uint16_t port_id, char *name) { @@ -601,7 +619,7 @@ int rte_eth_dev_attach(const char *devargs, uint16_t *port_id) { int ret = -1; - int current = rte_eth_dev_count(); + int current = rte_eth_dev_count_total(); char *name = NULL; char *args = NULL; @@ -619,7 +637,7 @@ rte_eth_dev_attach(const char *devargs, uint16_t *port_id) goto err; /* no point looking at the port count if no port exists */ - if (!rte_eth_dev_count()) { + if (!rte_eth_dev_count_total()) { ethdev_log(ERR, "No port found for device (%s)", name); ret = -1; goto err; @@ -627,8 +645,9 @@ rte_eth_dev_attach(const char *devargs, uint16_t *port_id) /* if nothing happened, there is a bug here, since some driver told us * it did attach a device, but did not create a port. + * FIXME: race condition in case of plug-out of another device */ - if (current == rte_eth_dev_count()) { + if (current == rte_eth_dev_count_total()) { ret = -1; goto err; } @@ -1061,6 +1080,26 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q, RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); + dev = &rte_eth_devices[port_id]; + + RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP); + (*dev->dev_ops->dev_infos_get)(dev, &dev_info); + + /* If number of queues specified by application for both Rx and Tx is + * zero, use driver preferred values. This cannot be done individually + * as it is valid for either Tx or Rx (but not both) to be zero. + * If driver does not provide any preferred valued, fall back on + * EAL defaults. + */ + if (nb_rx_q == 0 && nb_tx_q == 0) { + nb_rx_q = dev_info.default_rxportconf.nb_queues; + if (nb_rx_q == 0) + nb_rx_q = RTE_ETH_DEV_FALLBACK_RX_NBQUEUES; + nb_tx_q = dev_info.default_txportconf.nb_queues; + if (nb_tx_q == 0) + nb_tx_q = RTE_ETH_DEV_FALLBACK_TX_NBQUEUES; + } + if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) { RTE_PMD_DEBUG_TRACE( "Number of RX queues requested (%u) is greater than max supported(%d)\n", @@ -1075,8 +1114,6 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q, return -EINVAL; } - dev = &rte_eth_devices[port_id]; - RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP); RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP); @@ -1106,13 +1143,6 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q, * than the maximum number of RX and TX queues supported by the * configured device. */ - (*dev->dev_ops->dev_infos_get)(dev, &dev_info); - - if (nb_rx_q == 0 && nb_tx_q == 0) { - RTE_PMD_DEBUG_TRACE("ethdev port_id=%d both rx and tx queue cannot be 0\n", port_id); - return -EINVAL; - } - if (nb_rx_q > dev_info.max_rx_queues) { RTE_PMD_DEBUG_TRACE("ethdev port_id=%d nb_rx_queues=%d > %d\n", port_id, nb_rx_q, dev_info.max_rx_queues); @@ -1477,6 +1507,14 @@ rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id, return -EINVAL; } + /* Use default specified by driver, if nb_rx_desc is zero */ + if (nb_rx_desc == 0) { + nb_rx_desc = dev_info.default_rxportconf.ring_size; + /* If driver default is also zero, fall back on EAL default */ + if (nb_rx_desc == 0) + nb_rx_desc = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE; + } + if (nb_rx_desc > dev_info.rx_desc_lim.nb_max || nb_rx_desc < dev_info.rx_desc_lim.nb_min || nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) { @@ -1600,6 +1638,13 @@ rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id, rte_eth_dev_info_get(port_id, &dev_info); + /* Use default specified by driver, if nb_tx_desc is zero */ + if (nb_tx_desc == 0) { + nb_tx_desc = dev_info.default_txportconf.ring_size; + /* If driver default is zero, fall back on EAL default */ + if (nb_tx_desc == 0) + nb_tx_desc = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE; + } if (nb_tx_desc > dev_info.tx_desc_lim.nb_max || nb_tx_desc < dev_info.tx_desc_lim.nb_min || nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) { @@ -1789,7 +1834,8 @@ rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link) RTE_ETH_VALID_PORTID_OR_RET(port_id); dev = &rte_eth_devices[port_id]; - if (dev->data->dev_conf.intr_conf.lsc) + if (dev->data->dev_conf.intr_conf.lsc && + dev->data->dev_started) rte_eth_linkstatus_get(dev, eth_link); else { RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update); @@ -1806,7 +1852,8 @@ rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link) RTE_ETH_VALID_PORTID_OR_RET(port_id); dev = &rte_eth_devices[port_id]; - if (dev->data->dev_conf.intr_conf.lsc) + if (dev->data->dev_conf.intr_conf.lsc && + dev->data->dev_started) rte_eth_linkstatus_get(dev, eth_link); else { RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update); @@ -3006,6 +3053,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct ether_addr *addr) { struct rte_eth_dev *dev; + int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); @@ -3015,11 +3063,13 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct ether_addr *addr) dev = &rte_eth_devices[port_id]; RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP); + ret = (*dev->dev_ops->mac_addr_set)(dev, addr); + if (ret < 0) + return ret; + /* Update default address in NIC data structure */ ether_addr_copy(addr, &dev->data->mac_addrs[0]); - (*dev->dev_ops->mac_addr_set)(dev, addr); - return 0; }