app/testpmd: fix hotplug removal
[dpdk.git] / app / test-pmd / testpmd.c
index 37aba40..6cbe9ba 100644 (file)
@@ -857,16 +857,23 @@ dma_unmap_cb(struct rte_mempool *mp __rte_unused, void *opaque __rte_unused,
        int ret;
 
        RTE_ETH_FOREACH_DEV(pid) {
-               struct rte_eth_dev *dev =
-                       &rte_eth_devices[pid];
+               struct rte_eth_dev_info dev_info;
 
-               ret = rte_dev_dma_unmap(dev->device, memhdr->addr, 0,
-                                       memhdr->len);
+               ret = eth_dev_info_get_print_err(pid, &dev_info);
+               if (ret != 0) {
+                       TESTPMD_LOG(DEBUG,
+                                   "unable to get device info for port %d on addr 0x%p,"
+                                   "mempool unmapping will not be performed\n",
+                                   pid, memhdr->addr);
+                       continue;
+               }
+
+               ret = rte_dev_dma_unmap(dev_info.device, memhdr->addr, 0, memhdr->len);
                if (ret) {
                        TESTPMD_LOG(DEBUG,
                                    "unable to DMA unmap addr 0x%p "
                                    "for device %s\n",
-                                   memhdr->addr, dev->data->name);
+                                   memhdr->addr, dev_info.device->name);
                }
        }
        ret = rte_extmem_unregister(memhdr->addr, memhdr->len);
@@ -892,16 +899,22 @@ dma_map_cb(struct rte_mempool *mp __rte_unused, void *opaque __rte_unused,
                return;
        }
        RTE_ETH_FOREACH_DEV(pid) {
-               struct rte_eth_dev *dev =
-                       &rte_eth_devices[pid];
+               struct rte_eth_dev_info dev_info;
 
-               ret = rte_dev_dma_map(dev->device, memhdr->addr, 0,
-                                     memhdr->len);
+               ret = eth_dev_info_get_print_err(pid, &dev_info);
+               if (ret != 0) {
+                       TESTPMD_LOG(DEBUG,
+                                   "unable to get device info for port %d on addr 0x%p,"
+                                   "mempool mapping will not be performed\n",
+                                   pid, memhdr->addr);
+                       continue;
+               }
+               ret = rte_dev_dma_map(dev_info.device, memhdr->addr, 0, memhdr->len);
                if (ret) {
                        TESTPMD_LOG(DEBUG,
                                    "unable to DMA map addr 0x%p "
                                    "for device %s\n",
-                                   memhdr->addr, dev->data->name);
+                                   memhdr->addr, dev_info.device->name);
                }
        }
 }
@@ -1089,10 +1102,8 @@ check_socket_id(const unsigned int socket_id)
 
        if (new_socket_id(socket_id)) {
                if (!warning_once && numa_support)
-                       printf("Warning: NUMA should be configured manually by"
-                              " using --port-numa-config and"
-                              " --ring-numa-config parameters along with"
-                              " --numa.\n");
+                       fprintf(stderr,
+                               "Warning: NUMA should be configured manually by using --port-numa-config and --ring-numa-config parameters along with --numa.\n");
                warning_once = 1;
                return -1;
        }
@@ -1139,11 +1150,9 @@ check_nb_rxq(queueid_t rxq)
 
        allowed_max_rxq = get_allowed_max_nb_rxq(&pid);
        if (rxq > allowed_max_rxq) {
-               printf("Fail: input rxq (%u) can't be greater "
-                      "than max_rx_queues (%u) of port %u\n",
-                      rxq,
-                      allowed_max_rxq,
-                      pid);
+               fprintf(stderr,
+                       "Fail: input rxq (%u) can't be greater than max_rx_queues (%u) of port %u\n",
+                       rxq, allowed_max_rxq, pid);
                return -1;
        }
        return 0;
@@ -1189,11 +1198,9 @@ check_nb_txq(queueid_t txq)
 
        allowed_max_txq = get_allowed_max_nb_txq(&pid);
        if (txq > allowed_max_txq) {
-               printf("Fail: input txq (%u) can't be greater "
-                      "than max_tx_queues (%u) of port %u\n",
-                      txq,
-                      allowed_max_txq,
-                      pid);
+               fprintf(stderr,
+                       "Fail: input txq (%u) can't be greater than max_tx_queues (%u) of port %u\n",
+                       txq, allowed_max_txq, pid);
                return -1;
        }
        return 0;
@@ -1264,21 +1271,17 @@ check_nb_rxd(queueid_t rxd)
 
        allowed_max_rxd = get_allowed_max_nb_rxd(&pid);
        if (rxd > allowed_max_rxd) {
-               printf("Fail: input rxd (%u) can't be greater "
-                      "than max_rxds (%u) of port %u\n",
-                      rxd,
-                      allowed_max_rxd,
-                      pid);
+               fprintf(stderr,
+                       "Fail: input rxd (%u) can't be greater than max_rxds (%u) of port %u\n",
+                       rxd, allowed_max_rxd, pid);
                return -1;
        }
 
        allowed_min_rxd = get_allowed_min_nb_rxd(&pid);
        if (rxd < allowed_min_rxd) {
-               printf("Fail: input rxd (%u) can't be less "
-                      "than min_rxds (%u) of port %u\n",
-                      rxd,
-                      allowed_min_rxd,
-                      pid);
+               fprintf(stderr,
+                       "Fail: input rxd (%u) can't be less than min_rxds (%u) of port %u\n",
+                       rxd, allowed_min_rxd, pid);
                return -1;
        }
 
@@ -1349,21 +1352,17 @@ check_nb_txd(queueid_t txd)
 
        allowed_max_txd = get_allowed_max_nb_txd(&pid);
        if (txd > allowed_max_txd) {
-               printf("Fail: input txd (%u) can't be greater "
-                      "than max_txds (%u) of port %u\n",
-                      txd,
-                      allowed_max_txd,
-                      pid);
+               fprintf(stderr,
+                       "Fail: input txd (%u) can't be greater than max_txds (%u) of port %u\n",
+                       txd, allowed_max_txd, pid);
                return -1;
        }
 
        allowed_min_txd = get_allowed_min_nb_txd(&pid);
        if (txd < allowed_min_txd) {
-               printf("Fail: input txd (%u) can't be less "
-                      "than min_txds (%u) of port %u\n",
-                      txd,
-                      allowed_min_txd,
-                      pid);
+               fprintf(stderr,
+                       "Fail: input txd (%u) can't be less than min_txds (%u) of port %u\n",
+                       txd, allowed_min_txd, pid);
                return -1;
        }
        return 0;
@@ -1409,9 +1408,9 @@ check_nb_hairpinq(queueid_t hairpinq)
 
        allowed_max_hairpinq = get_allowed_max_nb_hairpinq(&pid);
        if (hairpinq > allowed_max_hairpinq) {
-               printf("Fail: input hairpin (%u) can't be greater "
-                      "than max_hairpin_queues (%u) of port %u\n",
-                      hairpinq, allowed_max_hairpinq, pid);
+               fprintf(stderr,
+                       "Fail: input hairpin (%u) can't be greater than max_hairpin_queues (%u) of port %u\n",
+                       hairpinq, allowed_max_hairpinq, pid);
                return -1;
        }
        return 0;
@@ -1434,7 +1433,8 @@ init_config_port_offloads(portid_t pid, uint32_t socket_id)
 
        ret = update_jumbo_frame_offload(pid);
        if (ret != 0)
-               printf("Updating jumbo frame offload failed for port %u\n",
+               fprintf(stderr,
+                       "Updating jumbo frame offload failed for port %u\n",
                        pid);
 
        if (!(port->dev_info.tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE))
@@ -1626,15 +1626,15 @@ init_fwd_streams(void)
        RTE_ETH_FOREACH_DEV(pid) {
                port = &ports[pid];
                if (nb_rxq > port->dev_info.max_rx_queues) {
-                       printf("Fail: nb_rxq(%d) is greater than "
-                               "max_rx_queues(%d)\n", nb_rxq,
-                               port->dev_info.max_rx_queues);
+                       fprintf(stderr,
+                               "Fail: nb_rxq(%d) is greater than max_rx_queues(%d)\n",
+                               nb_rxq, port->dev_info.max_rx_queues);
                        return -1;
                }
                if (nb_txq > port->dev_info.max_tx_queues) {
-                       printf("Fail: nb_txq(%d) is greater than "
-                               "max_tx_queues(%d)\n", nb_txq,
-                               port->dev_info.max_tx_queues);
+                       fprintf(stderr,
+                               "Fail: nb_txq(%d) is greater than max_tx_queues(%d)\n",
+                               nb_txq, port->dev_info.max_tx_queues);
                        return -1;
                }
                if (numa_support) {
@@ -1661,7 +1661,8 @@ init_fwd_streams(void)
 
        q = RTE_MAX(nb_rxq, nb_txq);
        if (q == 0) {
-               printf("Fail: Cannot allocate fwd streams as number of queues is 0\n");
+               fprintf(stderr,
+                       "Fail: Cannot allocate fwd streams as number of queues is 0\n");
                return -1;
        }
        nb_fwd_streams_new = (streamid_t)(nb_ports * q);
@@ -2118,8 +2119,9 @@ launch_packet_forwarding(lcore_function_t *pkt_fwd_on_lcore)
                        diag = rte_eal_remote_launch(pkt_fwd_on_lcore,
                                                     fwd_lcores[i], lc_id);
                        if (diag != 0)
-                               printf("launch lcore %u failed - diag=%d\n",
-                                      lc_id, diag);
+                               fprintf(stderr,
+                                       "launch lcore %u failed - diag=%d\n",
+                                       lc_id, diag);
                }
        }
 }
@@ -2148,11 +2150,11 @@ start_packet_forwarding(int with_tx_first)
                        cur_fwd_eng->fwd_mode_name);
 
        if (all_ports_started() == 0) {
-               printf("Not all ports were started\n");
+               fprintf(stderr, "Not all ports were started\n");
                return;
        }
        if (test_done == 0) {
-               printf("Packet forwarding already started\n");
+               fprintf(stderr, "Packet forwarding already started\n");
                return;
        }
        test_done = 0;
@@ -2195,7 +2197,7 @@ stop_packet_forwarding(void)
        int i;
 
        if (test_done) {
-               printf("Packet forwarding not started\n");
+               fprintf(stderr, "Packet forwarding not started\n");
                return;
        }
        printf("Telling cores to stop...");
@@ -2221,14 +2223,14 @@ void
 dev_set_link_up(portid_t pid)
 {
        if (rte_eth_dev_set_link_up(pid) < 0)
-               printf("\nSet link up fail.\n");
+               fprintf(stderr, "\nSet link up fail.\n");
 }
 
 void
 dev_set_link_down(portid_t pid)
 {
        if (rte_eth_dev_set_link_down(pid) < 0)
-               printf("\nSet link down fail.\n");
+               fprintf(stderr, "\nSet link down fail.\n");
 }
 
 static int
@@ -2349,10 +2351,10 @@ setup_hairpin_queues(portid_t pi, portid_t p_pi, uint16_t cnt_pi)
                if (rte_atomic16_cmpset(&(port->port_status),
                                        RTE_PORT_HANDLING,
                                        RTE_PORT_STOPPED) == 0)
-                       printf("Port %d can not be set back "
-                                       "to stopped\n", pi);
-               printf("Fail to configure port %d hairpin "
-                               "queues\n", pi);
+                       fprintf(stderr,
+                               "Port %d can not be set back to stopped\n", pi);
+               fprintf(stderr, "Fail to configure port %d hairpin queues\n",
+                       pi);
                /* try to reconfigure queues next time */
                port->need_reconfig_queues = 1;
                return -1;
@@ -2372,10 +2374,10 @@ setup_hairpin_queues(portid_t pi, portid_t p_pi, uint16_t cnt_pi)
                if (rte_atomic16_cmpset(&(port->port_status),
                                        RTE_PORT_HANDLING,
                                        RTE_PORT_STOPPED) == 0)
-                       printf("Port %d can not be set back "
-                                       "to stopped\n", pi);
-               printf("Fail to configure port %d hairpin "
-                               "queues\n", pi);
+                       fprintf(stderr,
+                               "Port %d can not be set back to stopped\n", pi);
+               fprintf(stderr, "Fail to configure port %d hairpin queues\n",
+                       pi);
                /* try to reconfigure queues next time */
                port->need_reconfig_queues = 1;
                return -1;
@@ -2454,7 +2456,7 @@ start_port(portid_t pid)
                port = &ports[pi];
                if (rte_atomic16_cmpset(&(port->port_status), RTE_PORT_STOPPED,
                                                 RTE_PORT_HANDLING) == 0) {
-                       printf("Port %d is now not stopped\n", pi);
+                       fprintf(stderr, "Port %d is now not stopped\n", pi);
                        continue;
                }
 
@@ -2464,8 +2466,9 @@ start_port(portid_t pid)
                        if (flow_isolate_all) {
                                int ret = port_flow_isolate(pi, 1);
                                if (ret) {
-                                       printf("Failed to apply isolated"
-                                              " mode on port %d\n", pi);
+                                       fprintf(stderr,
+                                               "Failed to apply isolated mode on port %d\n",
+                                               pi);
                                        return -1;
                                }
                        }
@@ -2474,8 +2477,9 @@ start_port(portid_t pid)
                                        port->socket_id);
                        if (nb_hairpinq > 0 &&
                            rte_eth_dev_hairpin_capability_get(pi, &cap)) {
-                               printf("Port %d doesn't support hairpin "
-                                      "queues\n", pi);
+                               fprintf(stderr,
+                                       "Port %d doesn't support hairpin queues\n",
+                                       pi);
                                return -1;
                        }
                        /* configure port */
@@ -2485,9 +2489,11 @@ start_port(portid_t pid)
                        if (diag != 0) {
                                if (rte_atomic16_cmpset(&(port->port_status),
                                RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
-                                       printf("Port %d can not be set back "
-                                                       "to stopped\n", pi);
-                               printf("Fail to configure port %d\n", pi);
+                                       fprintf(stderr,
+                                               "Port %d can not be set back to stopped\n",
+                                               pi);
+                               fprintf(stderr, "Fail to configure port %d\n",
+                                       pi);
                                /* try to reconfigure port next time */
                                port->need_reconfig = 1;
                                return -1;
@@ -2516,10 +2522,12 @@ start_port(portid_t pid)
                                if (rte_atomic16_cmpset(&(port->port_status),
                                                        RTE_PORT_HANDLING,
                                                        RTE_PORT_STOPPED) == 0)
-                                       printf("Port %d can not be set back "
-                                                       "to stopped\n", pi);
-                               printf("Fail to configure port %d tx queues\n",
-                                      pi);
+                                       fprintf(stderr,
+                                               "Port %d can not be set back to stopped\n",
+                                               pi);
+                               fprintf(stderr,
+                                       "Fail to configure port %d tx queues\n",
+                                       pi);
                                /* try to reconfigure queues next time */
                                port->need_reconfig_queues = 1;
                                return -1;
@@ -2532,9 +2540,8 @@ start_port(portid_t pid)
                                                mbuf_pool_find
                                                        (rxring_numa[pi], 0);
                                        if (mp == NULL) {
-                                               printf("Failed to setup RX queue:"
-                                                       "No mempool allocation"
-                                                       " on the socket %d\n",
+                                               fprintf(stderr,
+                                                       "Failed to setup RX queue: No mempool allocation on the socket %d\n",
                                                        rxring_numa[pi]);
                                                return -1;
                                        }
@@ -2549,9 +2556,8 @@ start_port(portid_t pid)
                                                mbuf_pool_find
                                                        (port->socket_id, 0);
                                        if (mp == NULL) {
-                                               printf("Failed to setup RX queue:"
-                                                       "No mempool allocation"
-                                                       " on the socket %d\n",
+                                               fprintf(stderr,
+                                                       "Failed to setup RX queue: No mempool allocation on the socket %d\n",
                                                        port->socket_id);
                                                return -1;
                                        }
@@ -2568,10 +2574,12 @@ start_port(portid_t pid)
                                if (rte_atomic16_cmpset(&(port->port_status),
                                                        RTE_PORT_HANDLING,
                                                        RTE_PORT_STOPPED) == 0)
-                                       printf("Port %d can not be set back "
-                                                       "to stopped\n", pi);
-                               printf("Fail to configure port %d rx queues\n",
-                                      pi);
+                                       fprintf(stderr,
+                                               "Port %d can not be set back to stopped\n",
+                                               pi);
+                               fprintf(stderr,
+                                       "Fail to configure port %d rx queues\n",
+                                       pi);
                                /* try to reconfigure queues next time */
                                port->need_reconfig_queues = 1;
                                return -1;
@@ -2585,9 +2593,9 @@ start_port(portid_t pid)
                        diag = rte_eth_dev_set_ptypes(pi, RTE_PTYPE_UNKNOWN,
                                        NULL, 0);
                        if (diag < 0)
-                               printf(
-                               "Port %d: Failed to disable Ptype parsing\n",
-                               pi);
+                               fprintf(stderr,
+                                       "Port %d: Failed to disable Ptype parsing\n",
+                                       pi);
                }
 
                p_pi = pi;
@@ -2596,20 +2604,22 @@ start_port(portid_t pid)
                /* start port */
                diag = rte_eth_dev_start(pi);
                if (diag < 0) {
-                       printf("Fail to start port %d: %s\n", pi,
-                              rte_strerror(-diag));
+                       fprintf(stderr, "Fail to start port %d: %s\n",
+                               pi, rte_strerror(-diag));
 
                        /* Fail to setup rx queue, return */
                        if (rte_atomic16_cmpset(&(port->port_status),
                                RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
-                               printf("Port %d can not be set back to "
-                                                       "stopped\n", pi);
+                               fprintf(stderr,
+                                       "Port %d can not be set back to stopped\n",
+                                       pi);
                        continue;
                }
 
                if (rte_atomic16_cmpset(&(port->port_status),
                        RTE_PORT_HANDLING, RTE_PORT_STARTED) == 0)
-                       printf("Port %d can not be set into started\n", pi);
+                       fprintf(stderr, "Port %d can not be set into started\n",
+                               pi);
 
                if (eth_macaddr_get_print_err(pi, &port->eth_addr) == 0)
                        printf("Port %d: %02X:%02X:%02X:%02X:%02X:%02X\n", pi,
@@ -2629,7 +2639,7 @@ start_port(portid_t pid)
        if (need_check_link_status == 1 && !no_link_check)
                check_all_ports_link_status(RTE_PORT_ALL);
        else if (need_check_link_status == 0)
-               printf("Please stop the ports first\n");
+               fprintf(stderr, "Please stop the ports first\n");
 
        if (hairpin_mode & 0xf) {
                uint16_t i;
@@ -2648,10 +2658,10 @@ start_port(portid_t pid)
                                        continue;
                                diag = rte_eth_hairpin_bind(pi, peer_pl[j]);
                                if (diag < 0) {
-                                       printf("Error during binding hairpin"
-                                              " Tx port %u to %u: %s\n",
-                                              pi, peer_pl[j],
-                                              rte_strerror(-diag));
+                                       fprintf(stderr,
+                                               "Error during binding hairpin Tx port %u to %u: %s\n",
+                                               pi, peer_pl[j],
+                                               rte_strerror(-diag));
                                        return -1;
                                }
                        }
@@ -2665,10 +2675,10 @@ start_port(portid_t pid)
                                        continue;
                                diag = rte_eth_hairpin_bind(peer_pl[j], pi);
                                if (diag < 0) {
-                                       printf("Error during binding hairpin"
-                                              " Tx port %u to %u: %s\n",
-                                              peer_pl[j], pi,
-                                              rte_strerror(-diag));
+                                       fprintf(stderr,
+                                               "Error during binding hairpin Tx port %u to %u: %s\n",
+                                               peer_pl[j], pi,
+                                               rte_strerror(-diag));
                                        return -1;
                                }
                        }
@@ -2698,12 +2708,16 @@ stop_port(portid_t pid)
                        continue;
 
                if (port_is_forwarding(pi) != 0 && test_done == 0) {
-                       printf("Please remove port %d from forwarding configuration.\n", pi);
+                       fprintf(stderr,
+                               "Please remove port %d from forwarding configuration.\n",
+                               pi);
                        continue;
                }
 
                if (port_is_bonding_slave(pi)) {
-                       printf("Please remove port %d from bonded device.\n", pi);
+                       fprintf(stderr,
+                               "Please remove port %d from bonded device.\n",
+                               pi);
                        continue;
                }
 
@@ -2737,7 +2751,8 @@ stop_port(portid_t pid)
 
                if (rte_atomic16_cmpset(&(port->port_status),
                        RTE_PORT_HANDLING, RTE_PORT_STOPPED) == 0)
-                       printf("Port %d can not be set into stopped\n", pi);
+                       fprintf(stderr, "Port %d can not be set into stopped\n",
+                               pi);
                need_check_link_status = 1;
        }
        if (need_check_link_status && !no_link_check)
@@ -2784,19 +2799,23 @@ close_port(portid_t pid)
                        continue;
 
                if (port_is_forwarding(pi) != 0 && test_done == 0) {
-                       printf("Please remove port %d from forwarding configuration.\n", pi);
+                       fprintf(stderr,
+                               "Please remove port %d from forwarding configuration.\n",
+                               pi);
                        continue;
                }
 
                if (port_is_bonding_slave(pi)) {
-                       printf("Please remove port %d from bonded device.\n", pi);
+                       fprintf(stderr,
+                               "Please remove port %d from bonded device.\n",
+                               pi);
                        continue;
                }
 
                port = &ports[pi];
                if (rte_atomic16_cmpset(&(port->port_status),
                        RTE_PORT_CLOSED, RTE_PORT_CLOSED) == 1) {
-                       printf("Port %d is already closed\n", pi);
+                       fprintf(stderr, "Port %d is already closed\n", pi);
                        continue;
                }
 
@@ -2820,7 +2839,8 @@ reset_port(portid_t pid)
 
        if ((pid == (portid_t)RTE_PORT_ALL && !all_ports_stopped()) ||
                (pid != (portid_t)RTE_PORT_ALL && !port_is_stopped(pid))) {
-               printf("Can not reset port(s), please stop port(s) first.\n");
+               fprintf(stderr,
+                       "Can not reset port(s), please stop port(s) first.\n");
                return;
        }
 
@@ -2831,14 +2851,16 @@ reset_port(portid_t pid)
                        continue;
 
                if (port_is_forwarding(pi) != 0 && test_done == 0) {
-                       printf("Please remove port %d from forwarding "
-                              "configuration.\n", pi);
+                       fprintf(stderr,
+                               "Please remove port %d from forwarding configuration.\n",
+                               pi);
                        continue;
                }
 
                if (port_is_bonding_slave(pi)) {
-                       printf("Please remove port %d from bonded device.\n",
-                              pi);
+                       fprintf(stderr,
+                               "Please remove port %d from bonded device.\n",
+                               pi);
                        continue;
                }
 
@@ -2848,7 +2870,8 @@ reset_port(portid_t pid)
                        port->need_reconfig = 1;
                        port->need_reconfig_queues = 1;
                } else {
-                       printf("Failed to reset port %d. diag=%d\n", pi, diag);
+                       fprintf(stderr, "Failed to reset port %d. diag=%d\n",
+                               pi, diag);
                }
        }
 
@@ -2864,7 +2887,7 @@ attach_port(char *identifier)
        printf("Attaching a new port...\n");
 
        if (identifier == NULL) {
-               printf("Invalid parameters are specified\n");
+               fprintf(stderr, "Invalid parameters are specified\n");
                return;
        }
 
@@ -2905,7 +2928,8 @@ setup_attached_port(portid_t pi)
        reconfig(pi, socket_id);
        ret = rte_eth_promiscuous_enable(pi);
        if (ret != 0)
-               printf("Error during enabling promiscuous mode for port %u: %s - ignore\n",
+               fprintf(stderr,
+                       "Error during enabling promiscuous mode for port %u: %s - ignore\n",
                        pi, rte_strerror(-ret));
 
        ports_ids[nb_ports++] = pi;
@@ -2924,7 +2948,7 @@ detach_device(struct rte_device *dev)
        portid_t sibling;
 
        if (dev == NULL) {
-               printf("Device already removed\n");
+               fprintf(stderr, "Device already removed\n");
                return;
        }
 
@@ -2933,7 +2957,8 @@ detach_device(struct rte_device *dev)
        RTE_ETH_FOREACH_DEV_OF(sibling, dev) {
                if (ports[sibling].port_status != RTE_PORT_CLOSED) {
                        if (ports[sibling].port_status != RTE_PORT_STOPPED) {
-                               printf("Port %u not stopped\n", sibling);
+                               fprintf(stderr, "Port %u not stopped\n",
+                                       sibling);
                                return;
                        }
                        port_flow_flush(sibling);
@@ -2955,18 +2980,28 @@ detach_device(struct rte_device *dev)
 void
 detach_port_device(portid_t port_id)
 {
+       int ret;
+       struct rte_eth_dev_info dev_info;
+
        if (port_id_is_invalid(port_id, ENABLED_WARN))
                return;
 
        if (ports[port_id].port_status != RTE_PORT_CLOSED) {
                if (ports[port_id].port_status != RTE_PORT_STOPPED) {
-                       printf("Port not stopped\n");
+                       fprintf(stderr, "Port not stopped\n");
                        return;
                }
-               printf("Port was not closed\n");
+               fprintf(stderr, "Port was not closed\n");
        }
 
-       detach_device(rte_eth_devices[port_id].device);
+       ret = eth_dev_info_get_print_err(port_id, &dev_info);
+       if (ret != 0) {
+               TESTPMD_LOG(ERR,
+                       "Failed to get device info for port %d, not detaching\n",
+                       port_id);
+               return;
+       }
+       detach_device(dev_info.device);
 }
 
 void
@@ -2980,14 +3015,15 @@ detach_devargs(char *identifier)
 
        memset(&da, 0, sizeof(da));
        if (rte_devargs_parsef(&da, "%s", identifier)) {
-               printf("cannot parse identifier\n");
+               fprintf(stderr, "cannot parse identifier\n");
                return;
        }
 
        RTE_ETH_FOREACH_MATCHING_DEV(port_id, identifier, &iterator) {
                if (ports[port_id].port_status != RTE_PORT_CLOSED) {
                        if (ports[port_id].port_status != RTE_PORT_STOPPED) {
-                               printf("Port %u not stopped\n", port_id);
+                               fprintf(stderr, "Port %u not stopped\n",
+                                       port_id);
                                rte_eth_iterator_cleanup(&iterator);
                                rte_devargs_reset(&da);
                                return;
@@ -3105,7 +3141,8 @@ check_all_ports_link_status(uint32_t port_mask)
                        if (ret < 0) {
                                all_ports_up = 0;
                                if (print_flag == 1)
-                                       printf("Port %u link get failed: %s\n",
+                                       fprintf(stderr,
+                                               "Port %u link get failed: %s\n",
                                                portid, rte_strerror(-ret));
                                continue;
                        }
@@ -3147,7 +3184,8 @@ rmv_port_callback(void *arg)
        int need_to_start = 0;
        int org_no_link_check = no_link_check;
        portid_t port_id = (intptr_t)arg;
-       struct rte_device *dev;
+       struct rte_eth_dev_info dev_info;
+       int ret;
 
        RTE_ETH_VALID_PORTID_OR_RET(port_id);
 
@@ -3159,11 +3197,16 @@ rmv_port_callback(void *arg)
        stop_port(port_id);
        no_link_check = org_no_link_check;
 
-       /* Save rte_device pointer before closing ethdev port */
-       dev = rte_eth_devices[port_id].device;
-       close_port(port_id);
-       detach_device(dev); /* might be already removed or have more ports */
-
+       ret = eth_dev_info_get_print_err(port_id, &dev_info);
+       if (ret != 0)
+               TESTPMD_LOG(ERR,
+                       "Failed to get device info for port %d, not detaching\n",
+                       port_id);
+       else {
+               struct rte_device *device = dev_info.device;
+               close_port(port_id);
+               detach_device(device); /* might be already removed or have more ports */
+       }
        if (need_to_start)
                start_packet_forwarding(0);
 }
@@ -3177,7 +3220,8 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
        RTE_SET_USED(ret_param);
 
        if (type >= RTE_ETH_EVENT_MAX) {
-               fprintf(stderr, "\nPort %" PRIu16 ": %s called upon invalid event %d\n",
+               fprintf(stderr,
+                       "\nPort %" PRIu16 ": %s called upon invalid event %d\n",
                        port_id, __func__, type);
                fflush(stderr);
        } else if (event_print_mask & (UINT32_C(1) << type)) {
@@ -3196,7 +3240,8 @@ eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param,
                        break;
                if (rte_eal_alarm_set(100000,
                                rmv_port_callback, (void *)(intptr_t)port_id))
-                       fprintf(stderr, "Could not set up deferred device removal\n");
+                       fprintf(stderr,
+                               "Could not set up deferred device removal\n");
                break;
        case RTE_ETH_EVENT_DESTROY:
                ports[port_id].port_status = RTE_PORT_CLOSED;
@@ -3373,7 +3418,8 @@ update_jumbo_frame_offload(portid_t portid)
                on = false;
        } else {
                if ((port->dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME) == 0) {
-                       printf("Frame size (%u) is not supported by port %u\n",
+                       fprintf(stderr,
+                               "Frame size (%u) is not supported by port %u\n",
                                port->dev_conf.rxmode.max_rx_pkt_len,
                                portid);
                        return -1;
@@ -3403,7 +3449,8 @@ update_jumbo_frame_offload(portid_t portid)
                ret = rte_eth_dev_set_mtu(portid,
                                port->dev_conf.rxmode.max_rx_pkt_len - eth_overhead);
                if (ret)
-                       printf("Failed to set MTU to %u for port %u\n",
+                       fprintf(stderr,
+                               "Failed to set MTU to %u for port %u\n",
                                port->dev_conf.rxmode.max_rx_pkt_len - eth_overhead,
                                portid);
        }
@@ -3454,13 +3501,9 @@ init_port_config(void)
                rte_pmd_ixgbe_bypass_init(pid);
 #endif
 
-               if (lsc_interrupt &&
-                   (rte_eth_devices[pid].data->dev_flags &
-                    RTE_ETH_DEV_INTR_LSC))
+               if (lsc_interrupt && (*port->dev_info.dev_flags & RTE_ETH_DEV_INTR_LSC))
                        port->dev_conf.intr_conf.lsc = 1;
-               if (rmv_interrupt &&
-                   (rte_eth_devices[pid].data->dev_flags &
-                    RTE_ETH_DEV_INTR_RMV))
+               if (rmv_interrupt && (*port->dev_info.dev_flags & RTE_ETH_DEV_INTR_RMV))
                        port->dev_conf.intr_conf.rmv = 1;
        }
 }
@@ -3484,10 +3527,19 @@ void clear_port_slave_flag(portid_t slave_pid)
 uint8_t port_is_bonding_slave(portid_t slave_pid)
 {
        struct rte_port *port;
+       struct rte_eth_dev_info dev_info;
+       int ret;
 
        port = &ports[slave_pid];
-       if ((rte_eth_devices[slave_pid].data->dev_flags &
-           RTE_ETH_DEV_BONDED_SLAVE) || (port->slave_flag == 1))
+       ret = eth_dev_info_get_print_err(slave_pid, &dev_info);
+       if (ret != 0) {
+               TESTPMD_LOG(ERR,
+                       "Failed to get device info for port id %d,"
+                       "cannot determine if the port is a bonded slave",
+                       slave_pid);
+               return 0;
+       }
+       if ((*dev_info.dev_flags & RTE_ETH_DEV_BONDED_SLAVE) || (port->slave_flag == 1))
                return 1;
        return 0;
 }
@@ -3617,8 +3669,9 @@ init_port_dcb_config(portid_t pid,
         */
        if (dcb_mode == DCB_VT_ENABLED &&
            rte_port->dev_info.vmdq_pool_base > 0) {
-               printf("VMDQ_DCB multi-queue mode is nonsensical"
-                       " for port %d.", pid);
+               fprintf(stderr,
+                       "VMDQ_DCB multi-queue mode is nonsensical for port %d.\n",
+                       pid);
                return -1;
        }
 
@@ -3716,8 +3769,8 @@ static void
 signal_handler(int signum)
 {
        if (signum == SIGINT || signum == SIGTERM) {
-               printf("\nSignal %d received, preparing to exit...\n",
-                               signum);
+               fprintf(stderr, "\nSignal %d received, preparing to exit...\n",
+                       signum);
 #ifdef RTE_LIB_PDUMP
                /* uninitialize packet capture framework */
                rte_pdump_uninit();
@@ -3820,18 +3873,19 @@ main(int argc, char** argv)
                                "interactive mode.\n");
 
        if (tx_first && lsc_interrupt) {
-               printf("Warning: lsc_interrupt needs to be off when "
-                               " using tx_first. Disabling.\n");
+               fprintf(stderr,
+                       "Warning: lsc_interrupt needs to be off when using tx_first. Disabling.\n");
                lsc_interrupt = 0;
        }
 
        if (!nb_rxq && !nb_txq)
-               printf("Warning: Either rx or tx queues should be non-zero\n");
+               fprintf(stderr,
+                       "Warning: Either rx or tx queues should be non-zero\n");
 
        if (nb_rxq > 1 && nb_rxq > nb_txq)
-               printf("Warning: nb_rxq=%d enables RSS configuration, "
-                      "but nb_txq=%d will prevent to fully test it.\n",
-                      nb_rxq, nb_txq);
+               fprintf(stderr,
+                       "Warning: nb_rxq=%d enables RSS configuration, but nb_txq=%d will prevent to fully test it.\n",
+                       nb_rxq, nb_txq);
 
        init_config();
 
@@ -3866,7 +3920,8 @@ main(int argc, char** argv)
        RTE_ETH_FOREACH_DEV(port_id) {
                ret = rte_eth_promiscuous_enable(port_id);
                if (ret != 0)
-                       printf("Error during enabling promiscuous mode for port %u: %s - ignore\n",
+                       fprintf(stderr,
+                               "Error during enabling promiscuous mode for port %u: %s - ignore\n",
                                port_id, rte_strerror(-ret));
        }
 
@@ -3877,9 +3932,10 @@ main(int argc, char** argv)
        if (latencystats_enabled != 0) {
                int ret = rte_latencystats_init(1, NULL);
                if (ret)
-                       printf("Warning: latencystats init()"
-                               " returned error %d\n", ret);
-               printf("Latencystats running on lcore %d\n",
+                       fprintf(stderr,
+                               "Warning: latencystats init() returned error %d\n",
+                               ret);
+               fprintf(stderr, "Latencystats running on lcore %d\n",
                        latencystats_lcore_id);
        }
 #endif