fix ethdev ports enumeration
[dpdk.git] / examples / packet_ordering / main.c
index 97a58dd..964e23c 100644 (file)
@@ -211,11 +211,10 @@ flush_tx_error_callback(struct rte_mbuf **unsent, uint16_t count,
 
 static inline int
 free_tx_buffers(struct rte_eth_dev_tx_buffer *tx_buffer[]) {
-       const uint8_t nb_ports = rte_eth_dev_count();
-       unsigned port_id;
+       uint16_t port_id;
 
        /* initialize buffers for all ports */
-       for (port_id = 0; port_id < nb_ports; port_id++) {
+       RTE_ETH_FOREACH_DEV(port_id) {
                /* skip ports that are not enabled */
                if ((portmask & (1 << port_id)) == 0)
                        continue;
@@ -228,12 +227,11 @@ free_tx_buffers(struct rte_eth_dev_tx_buffer *tx_buffer[]) {
 static inline int
 configure_tx_buffers(struct rte_eth_dev_tx_buffer *tx_buffer[])
 {
-       const uint8_t nb_ports = rte_eth_dev_count();
-       unsigned port_id;
+       uint16_t port_id;
        int ret;
 
        /* initialize buffers for all ports */
-       for (port_id = 0; port_id < nb_ports; port_id++) {
+       RTE_ETH_FOREACH_DEV(port_id) {
                /* skip ports that are not enabled */
                if ((portmask & (1 << port_id)) == 0)
                        continue;
@@ -325,8 +323,7 @@ configure_eth_port(uint16_t port_id)
 static void
 print_stats(void)
 {
-       const uint8_t nb_ports = rte_eth_dev_count();
-       unsigned i;
+       uint16_t i;
        struct rte_eth_stats eth_stats;
 
        printf("\nRX thread stats:\n");
@@ -355,7 +352,7 @@ print_stats(void)
        printf(" - Pkts tx failed w/o reorder:          %"PRIu64"\n",
                                                app_stats.tx.early_pkts_tx_failed_woro);
 
-       for (i = 0; i < nb_ports; i++) {
+       RTE_ETH_FOREACH_DEV(i) {
                rte_eth_stats_get(i, &eth_stats);
                printf("\nPort %u stats:\n", i);
                printf(" - Pkts in:   %"PRIu64"\n", eth_stats.ipackets);
@@ -383,7 +380,6 @@ int_handler(int sig_num)
 static int
 rx_thread(struct rte_ring *ring_out)
 {
-       const uint8_t nb_ports = rte_eth_dev_count();
        uint32_t seqn = 0;
        uint16_t i, ret = 0;
        uint16_t nb_rx_pkts;
@@ -395,7 +391,7 @@ rx_thread(struct rte_ring *ring_out)
 
        while (!quit_signal) {
 
-               for (port_id = 0; port_id < nb_ports; port_id++) {
+               RTE_ETH_FOREACH_DEV(port_id) {
                        if ((portmask & (1 << port_id)) != 0) {
 
                                /* receive packets */
@@ -665,7 +661,7 @@ main(int argc, char **argv)
        nb_ports_available = nb_ports;
 
        /* initialize all ports */
-       for (port_id = 0; port_id < nb_ports; port_id++) {
+       RTE_ETH_FOREACH_DEV(port_id) {
                /* skip ports that are not enabled */
                if ((portmask & (1 << port_id)) == 0) {
                        printf("\nSkipping disabled port %d\n", port_id);