@@ -109,7 +109,6 @@
static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data";
struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
static struct rte_eth_dev_data *rte_eth_dev_data = NULL;
-static uint8_t nb_ports = 0;
/* spinlock for eth device callbacks */
static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
@@ -201,19 +200,33 @@ rte_eth_dev_allocated(const char *name)
{
unsigned i;
- for (i = 0; i < nb_ports; i++) {
- if (strcmp(rte_eth_devices[i].data->name, name) == 0)
+ for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+ if (rte_eth_devices[i].attached && strcmp(
+ rte_eth_dev_data[i].name, name) == 0)
return &rte_eth_devices[i];
- }
+
return NULL;
}
+static uint8_t
+rte_eth_dev_allocate_new_port(void)
+{
+ unsigned i;
+
+ for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+ if (!rte_eth_devices[i].attached)
+ return i;
+ return RTE_MAX_ETHPORTS;
+}
+
struct rte_eth_dev *
rte_eth_dev_allocate(const char *name)
{
+ uint8_t port_id;
struct rte_eth_dev *eth_dev;
- if (nb_ports == RTE_MAX_ETHPORTS) {
+ port_id = rte_eth_dev_allocate_new_port();
+ if (port_id >= RTE_MAX_ETHPORTS) {
PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n");
return NULL;
}
@@ -226,10 +239,11 @@ rte_eth_dev_allocate(const char *name)
return NULL;
}
- eth_dev = &rte_eth_devices[nb_ports];
- eth_dev->data = &rte_eth_dev_data[nb_ports];
+ eth_dev = &rte_eth_devices[port_id];
+ eth_dev->data = &rte_eth_dev_data[port_id];
snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
- eth_dev->data->port_id = nb_ports++;
+ eth_dev->data->port_id = port_id;
+ eth_dev->attached = 1;
return eth_dev;
}
@@ -283,7 +297,7 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv,
(unsigned) pci_dev->id.device_id);
if (rte_eal_process_type() == RTE_PROC_PRIMARY)
rte_free(eth_dev->data->dev_private);
- nb_ports--;
+ eth_dev->attached = 0;
return diag;
}
@@ -308,10 +322,19 @@ rte_eth_driver_register(struct eth_driver *eth_drv)
rte_eal_pci_register(ð_drv->pci_drv);
}
+static int
+rte_eth_dev_validate_port(uint8_t port_id)
+{
+ if (port_id >= RTE_MAX_ETHPORTS)
+ return 1;
+
+ return !rte_eth_devices[port_id].attached;
+}
+
int
rte_eth_dev_socket_id(uint8_t port_id)
{
- if (port_id >= nb_ports)
+ if (rte_eth_dev_validate_port(port_id))
return -1;
return rte_eth_devices[port_id].pci_dev->numa_node;
}
@@ -319,7 +342,13 @@ rte_eth_dev_socket_id(uint8_t port_id)
uint8_t
rte_eth_dev_count(void)
{
- return (nb_ports);
+ unsigned i;
+ uint8_t nb_ports = 0;
+
+ for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+ if (rte_eth_devices[i].attached)
+ nb_ports++;
+ return nb_ports;
}
static int
@@ -369,7 +398,7 @@ rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id)
* in a multi-process setup*/
PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -EINVAL;
}
@@ -395,7 +424,7 @@ rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id)
* in a multi-process setup*/
PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -EINVAL;
}
@@ -421,7 +450,7 @@ rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id)
* in a multi-process setup*/
PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -EINVAL;
}
@@ -447,7 +476,7 @@ rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id)
* in a multi-process setup*/
PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -EINVAL;
}
@@ -662,7 +691,7 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
* in a multi-process setup*/
PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
- if (port_id >= nb_ports || port_id >= RTE_MAX_ETHPORTS) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-EINVAL);
}
@@ -846,7 +875,7 @@ rte_eth_dev_start(uint8_t port_id)
* in a multi-process setup*/
PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id);
return (-EINVAL);
}
@@ -881,7 +910,7 @@ rte_eth_dev_stop(uint8_t port_id)
* in a multi-process setup*/
PROC_PRIMARY_OR_RET();
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id);
return;
}
@@ -909,7 +938,7 @@ rte_eth_dev_set_link_up(uint8_t port_id)
* in a multi-process setup*/
PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -EINVAL;
}
@@ -928,7 +957,7 @@ rte_eth_dev_set_link_down(uint8_t port_id)
* in a multi-process setup*/
PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -EINVAL;
}
@@ -947,7 +976,7 @@ rte_eth_dev_close(uint8_t port_id)
* in a multi-process setup*/
PROC_PRIMARY_OR_RET();
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return;
}
@@ -975,7 +1004,7 @@ rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id,
* in a multi-process setup*/
PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-EINVAL);
}
@@ -1048,7 +1077,7 @@ rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id,
* in a multi-process setup*/
PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY);
- if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-EINVAL);
}
@@ -1081,7 +1110,7 @@ rte_eth_promiscuous_enable(uint8_t port_id)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return;
}
@@ -1097,7 +1126,7 @@ rte_eth_promiscuous_disable(uint8_t port_id)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return;
}
@@ -1113,7 +1142,7 @@ rte_eth_promiscuous_get(uint8_t port_id)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -1;
}
@@ -1127,7 +1156,7 @@ rte_eth_allmulticast_enable(uint8_t port_id)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return;
}
@@ -1143,7 +1172,7 @@ rte_eth_allmulticast_disable(uint8_t port_id)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return;
}
@@ -1159,7 +1188,7 @@ rte_eth_allmulticast_get(uint8_t port_id)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -1;
}
@@ -1187,7 +1216,7 @@ rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return;
}
@@ -1207,7 +1236,7 @@ rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return;
}
@@ -1227,7 +1256,7 @@ rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return;
}
@@ -1244,7 +1273,7 @@ rte_eth_stats_reset(uint8_t port_id)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return;
}
@@ -1265,7 +1294,7 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
uint64_t val;
char *stats_ptr;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -1;
}
@@ -1334,7 +1363,7 @@ rte_eth_xstats_reset(uint8_t port_id)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return;
}
@@ -1356,7 +1385,7 @@ set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -1391,7 +1420,7 @@ rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return;
}
@@ -1411,7 +1440,7 @@ rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return;
}
@@ -1425,7 +1454,7 @@ rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1441,7 +1470,7 @@ rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu)
int ret;
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1461,7 +1490,7 @@ rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1486,7 +1515,7 @@ rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int o
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1508,7 +1537,7 @@ rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1528,7 +1557,7 @@ rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask)
int mask = 0;
int cur, org = 0;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1573,7 +1602,7 @@ rte_eth_dev_get_vlan_offload(uint8_t port_id)
struct rte_eth_dev *dev;
int ret = 0;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1597,7 +1626,7 @@ rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1615,7 +1644,7 @@ rte_eth_dev_fdir_add_signature_filter(uint8_t port_id,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1649,7 +1678,7 @@ rte_eth_dev_fdir_update_signature_filter(uint8_t port_id,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1683,7 +1712,7 @@ rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1714,7 +1743,7 @@ rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1739,7 +1768,7 @@ rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1779,7 +1808,7 @@ rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1817,7 +1846,7 @@ rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1853,7 +1882,7 @@ rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1873,7 +1902,7 @@ rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1889,7 +1918,7 @@ rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1909,7 +1938,7 @@ rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1933,7 +1962,7 @@ rte_eth_dev_rss_reta_update(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
uint16_t max_rxq;
uint8_t i,j;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -1985,7 +2014,7 @@ rte_eth_dev_rss_reta_query(uint8_t port_id, struct rte_eth_rss_reta *reta_conf)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2006,7 +2035,7 @@ rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf)
struct rte_eth_dev *dev;
uint16_t rss_hash_protos;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2028,7 +2057,7 @@ rte_eth_dev_rss_hash_conf_get(uint8_t port_id,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2043,7 +2072,7 @@ rte_eth_dev_udp_tunnel_add(uint8_t port_id,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -2069,7 +2098,7 @@ rte_eth_dev_udp_tunnel_delete(uint8_t port_id,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -2094,7 +2123,7 @@ rte_eth_led_on(uint8_t port_id)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2109,7 +2138,7 @@ rte_eth_led_off(uint8_t port_id)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2149,7 +2178,7 @@ rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr,
int index;
uint64_t pool_mask;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2200,7 +2229,7 @@ rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr)
struct rte_eth_dev *dev;
int index;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2231,7 +2260,7 @@ rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf,
struct rte_eth_dev *dev;
struct rte_eth_dev_info dev_info;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n",
port_id);
return (-ENODEV);
@@ -2286,7 +2315,7 @@ rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr,
int ret;
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
port_id);
return (-ENODEV);
@@ -2339,7 +2368,7 @@ rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n",
port_id);
return (-ENODEV);
@@ -2358,7 +2387,7 @@ rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on)
struct rte_eth_dev *dev;
struct rte_eth_dev_info dev_info;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2384,7 +2413,7 @@ rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on)
struct rte_eth_dev *dev;
struct rte_eth_dev_info dev_info;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2409,7 +2438,7 @@ rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n",
port_id);
return (-ENODEV);
@@ -2440,7 +2469,7 @@ int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx,
struct rte_eth_dev_info dev_info;
struct rte_eth_link link;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("set queue rate limit:invalid port id=%d\n",
port_id);
return -ENODEV;
@@ -2477,7 +2506,7 @@ int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate,
if (q_msk == 0)
return 0;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n",
port_id);
return -ENODEV;
@@ -2511,7 +2540,7 @@ rte_eth_mirror_rule_set(uint8_t port_id,
{
struct rte_eth_dev *dev = &rte_eth_devices[port_id];
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2552,7 +2581,7 @@ rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id)
{
struct rte_eth_dev *dev = &rte_eth_devices[port_id];
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2577,7 +2606,7 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return 0;
}
@@ -2597,7 +2626,7 @@ rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return 0;
}
@@ -2617,7 +2646,7 @@ rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return 0;
}
@@ -2631,7 +2660,7 @@ rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2652,7 +2681,7 @@ rte_eth_dev_callback_register(uint8_t port_id,
if (!cb_fn)
return (-EINVAL);
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-EINVAL);
}
@@ -2692,7 +2721,7 @@ rte_eth_dev_callback_unregister(uint8_t port_id,
if (!cb_fn)
return (-EINVAL);
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-EINVAL);
}
@@ -2752,7 +2781,7 @@ int rte_eth_dev_bypass_init(uint8_t port_id)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2772,7 +2801,7 @@ rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2791,7 +2820,7 @@ rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2811,7 +2840,7 @@ rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2831,7 +2860,7 @@ rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2851,7 +2880,7 @@ rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2871,7 +2900,7 @@ rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2891,7 +2920,7 @@ rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2911,7 +2940,7 @@ rte_eth_dev_bypass_wd_reset(uint8_t port_id)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return (-ENODEV);
}
@@ -2933,7 +2962,7 @@ rte_eth_dev_add_syn_filter(uint8_t port_id,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -2948,7 +2977,7 @@ rte_eth_dev_remove_syn_filter(uint8_t port_id)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -2967,7 +2996,7 @@ rte_eth_dev_get_syn_filter(uint8_t port_id,
if (filter == NULL || rx_queue == NULL)
return -EINVAL;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -2983,7 +3012,7 @@ rte_eth_dev_add_ethertype_filter(uint8_t port_id, uint16_t index,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -3004,7 +3033,7 @@ rte_eth_dev_remove_ethertype_filter(uint8_t port_id, uint16_t index)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -3023,7 +3052,7 @@ rte_eth_dev_get_ethertype_filter(uint8_t port_id, uint16_t index,
if (filter == NULL || rx_queue == NULL)
return -EINVAL;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -3040,7 +3069,7 @@ rte_eth_dev_add_2tuple_filter(uint8_t port_id, uint16_t index,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -3062,7 +3091,7 @@ rte_eth_dev_remove_2tuple_filter(uint8_t port_id, uint16_t index)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -3081,7 +3110,7 @@ rte_eth_dev_get_2tuple_filter(uint8_t port_id, uint16_t index,
if (filter == NULL || rx_queue == NULL)
return -EINVAL;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -3097,7 +3126,7 @@ rte_eth_dev_add_5tuple_filter(uint8_t port_id, uint16_t index,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -3120,7 +3149,7 @@ rte_eth_dev_remove_5tuple_filter(uint8_t port_id, uint16_t index)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -3139,7 +3168,7 @@ rte_eth_dev_get_5tuple_filter(uint8_t port_id, uint16_t index,
if (filter == NULL || rx_queue == NULL)
return -EINVAL;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -3156,7 +3185,7 @@ rte_eth_dev_add_flex_filter(uint8_t port_id, uint16_t index,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -3171,7 +3200,7 @@ rte_eth_dev_remove_flex_filter(uint8_t port_id, uint16_t index)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -3190,7 +3219,7 @@ rte_eth_dev_get_flex_filter(uint8_t port_id, uint16_t index,
if (filter == NULL || rx_queue == NULL)
return -EINVAL;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -3206,7 +3235,7 @@ rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type)
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -3223,7 +3252,7 @@ rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type,
{
struct rte_eth_dev *dev;
- if (port_id >= nb_ports) {
+ if (rte_eth_dev_validate_port(port_id)) {
PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id);
return -ENODEV;
}
@@ -1534,6 +1534,7 @@ struct eth_dev_ops {
* process, while the actual configuration data for the device is shared.
*/
struct rte_eth_dev {
+ uint8_t attached; /**< Flag indicating the port is attached */
eth_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */
eth_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function. */
struct rte_eth_dev_data *data; /**< Pointer to device data */
@@ -1606,6 +1607,10 @@ extern struct rte_eth_dev rte_eth_devices[];
* initialized by the [matching] Ethernet driver during the PCI probing phase.
* All devices whose port identifier is in the range
* [0, rte_eth_dev_count() - 1] can be operated on by network applications.
+ * immediately after invoking rte_eal_init().
+ * If the application unplugs a port using hotplug function, The enabled port
+ * numbers may be noncontiguous. In the case, the applications need to manage
+ * enabled port by themselves.
*
* @return
* - The total number of usable Ethernet devices.