net: add rte prefix to ether structures
[dpdk.git] / lib / librte_ethdev / rte_ethdev.c
index 8b25c2a..b868535 100644 (file)
@@ -330,8 +330,7 @@ uint16_t
 rte_eth_find_next(uint16_t port_id)
 {
        while (port_id < RTE_MAX_ETHPORTS &&
-              rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
-              rte_eth_devices[port_id].state != RTE_ETH_DEV_REMOVED)
+                       rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED)
                port_id++;
 
        if (port_id >= RTE_MAX_ETHPORTS)
@@ -340,6 +339,34 @@ rte_eth_find_next(uint16_t port_id)
        return port_id;
 }
 
+/*
+ * Macro to iterate over all valid ports for internal usage.
+ * Note: RTE_ETH_FOREACH_DEV is different because filtering owned ports.
+ */
+#define RTE_ETH_FOREACH_VALID_DEV(port_id) \
+       for (port_id = rte_eth_find_next(0); \
+            port_id < RTE_MAX_ETHPORTS; \
+            port_id = rte_eth_find_next(port_id + 1))
+
+uint16_t
+rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent)
+{
+       port_id = rte_eth_find_next(port_id);
+       while (port_id < RTE_MAX_ETHPORTS &&
+                       rte_eth_devices[port_id].device != parent)
+               port_id = rte_eth_find_next(port_id + 1);
+
+       return port_id;
+}
+
+uint16_t
+rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref_port_id)
+{
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(ref_port_id, RTE_MAX_ETHPORTS);
+       return rte_eth_find_next_of(port_id,
+                       rte_eth_devices[ref_port_id].device);
+}
+
 static void
 rte_eth_dev_shared_data_prepare(void)
 {
@@ -566,14 +593,10 @@ rte_eth_is_valid_owner_id(uint64_t owner_id)
 uint64_t
 rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id)
 {
+       port_id = rte_eth_find_next(port_id);
        while (port_id < RTE_MAX_ETHPORTS &&
-              ((rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED &&
-              rte_eth_devices[port_id].state != RTE_ETH_DEV_REMOVED) ||
-              rte_eth_devices[port_id].data->owner.id != owner_id))
-               port_id++;
-
-       if (port_id >= RTE_MAX_ETHPORTS)
-               return RTE_MAX_ETHPORTS;
+                       rte_eth_devices[port_id].data->owner.id != owner_id)
+               port_id = rte_eth_find_next(port_id + 1);
 
        return port_id;
 }
@@ -746,14 +769,13 @@ rte_eth_dev_count_avail(void)
        return count;
 }
 
-uint16_t __rte_experimental
+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++;
+       RTE_ETH_FOREACH_VALID_DEV(port)
+               count++;
 
        return count;
 }
@@ -787,13 +809,11 @@ rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
                return -EINVAL;
        }
 
-       for (pid = 0; pid < RTE_MAX_ETHPORTS; pid++) {
-               if (rte_eth_devices[pid].state != RTE_ETH_DEV_UNUSED &&
-                   !strcmp(name, rte_eth_dev_shared_data->data[pid].name)) {
+       RTE_ETH_FOREACH_VALID_DEV(pid)
+               if (!strcmp(name, rte_eth_dev_shared_data->data[pid].name)) {
                        *port_id = pid;
                        return 0;
                }
-       }
 
        return -ENODEV;
 }
@@ -1326,7 +1346,7 @@ static void
 rte_eth_dev_mac_restore(struct rte_eth_dev *dev,
                        struct rte_eth_dev_info *dev_info)
 {
-       struct ether_addr *addr;
+       struct rte_ether_addr *addr;
        uint16_t i;
        uint32_t pool = 0;
        uint64_t pool_mask;
@@ -1651,7 +1671,7 @@ rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
             local_conf.offloads) {
                RTE_ETHDEV_LOG(ERR,
                        "Ethdev port_id=%d rx_queue_id=%d, new added offloads 0x%"PRIx64" must be "
-                       "within pre-queue offload capabilities 0x%"PRIx64" in %s()\n",
+                       "within per-queue offload capabilities 0x%"PRIx64" in %s()\n",
                        port_id, rx_queue_id, local_conf.offloads,
                        dev_info.rx_queue_offload_capa,
                        __func__);
@@ -1755,7 +1775,7 @@ rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
             local_conf.offloads) {
                RTE_ETHDEV_LOG(ERR,
                        "Ethdev port_id=%d tx_queue_id=%d, new added offloads 0x%"PRIx64" must be "
-                       "within pre-queue offload capabilities 0x%"PRIx64" in %s()\n",
+                       "within per-queue offload capabilities 0x%"PRIx64" in %s()\n",
                        port_id, tx_queue_id, local_conf.offloads,
                        dev_info.tx_queue_offload_capa,
                        __func__);
@@ -2571,7 +2591,7 @@ rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
 }
 
 void
-rte_eth_macaddr_get(uint16_t port_id, struct ether_addr *mac_addr)
+rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr)
 {
        struct rte_eth_dev *dev;
 
@@ -3058,7 +3078,7 @@ rte_eth_led_off(uint16_t port_id)
  * an empty spot.
  */
 static int
-get_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
+get_mac_addr_index(uint16_t port_id, const struct rte_ether_addr *addr)
 {
        struct rte_eth_dev_info dev_info;
        struct rte_eth_dev *dev = &rte_eth_devices[port_id];
@@ -3074,10 +3094,10 @@ get_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
        return -1;
 }
 
-static const struct ether_addr null_mac_addr;
+static const struct rte_ether_addr null_mac_addr;
 
 int
-rte_eth_dev_mac_addr_add(uint16_t port_id, struct ether_addr *addr,
+rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
                        uint32_t pool)
 {
        struct rte_eth_dev *dev;
@@ -3130,7 +3150,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct ether_addr *addr,
 }
 
 int
-rte_eth_dev_mac_addr_remove(uint16_t port_id, struct ether_addr *addr)
+rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)
 {
        struct rte_eth_dev *dev;
        int index;
@@ -3161,7 +3181,7 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct ether_addr *addr)
 }
 
 int
-rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct ether_addr *addr)
+rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)
 {
        struct rte_eth_dev *dev;
        int ret;
@@ -3190,7 +3210,7 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct ether_addr *addr)
  * an empty spot.
  */
 static int
-get_hash_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
+get_hash_mac_addr_index(uint16_t port_id, const struct rte_ether_addr *addr)
 {
        struct rte_eth_dev_info dev_info;
        struct rte_eth_dev *dev = &rte_eth_devices[port_id];
@@ -3209,7 +3229,7 @@ get_hash_mac_addr_index(uint16_t port_id, const struct ether_addr *addr)
 }
 
 int
-rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct ether_addr *addr,
+rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct rte_ether_addr *addr,
                                uint8_t on)
 {
        int index;
@@ -4046,7 +4066,7 @@ rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
 
 int
 rte_eth_dev_set_mc_addr_list(uint16_t port_id,
-                            struct ether_addr *mc_addr_set,
+                            struct rte_ether_addr *mc_addr_set,
                             uint32_t nb_mc_addr)
 {
        struct rte_eth_dev *dev;