clinuxnetwork-programmingdpdkmellanox

Can DPDK selectively init NIC ports


I'm using an dual-port NIC, Mellanox ConnectX-5, and the DPDK version is dpdk-stable-19.11.3. After configuration, the call of rte_eth_dev_count_avail() returns 2. But only one port of my ConnectX-5 NIC is connected to the other machine. All I can find is to init all available ports like this.

RTE_ETH_FOREACH_DEV(portid)
    if (port_init(portid, mbuf_pool) != 0)
        rte_exit(EXIT_FAILURE, "Cannot init port %u\n", portid);

Can dpdk selectively init ports? Or is there any way to make rte_eth_dev_count_avail() returning 1?


Solution

  • Yes one can selectively init ports by passing the right PCIe Bus:Device:Function address as a whitelist. Hence only desired ports will pop up in the application.

    How to do it:

    1. create a dummy application to take in all DPDK port.
    2. Initialize and start the dpdk ports. Check for link-state and create port-mask (global variable) which filters in application logic.
    3. Invoke rte_eth_dev_stop & rte_eth_dev_close for link down ports.
    4. Invoke rte_eal_cleanup.
    5. Use the port-mask, as an argument for execv to invoke your desired DPDK application.

    this way you can run your application with valid ports to it.

    But relying on rte_eth_link_get is tricky because

    Hence safest and recommended way to use is identify the NIC PCIe B:D:F in Linux driver and then whitelist the ports by using option -w for the desired port under igb_uio/virtio-pci. This can be done by bind all NIC back in linux by

    1. lshw -c network -businfo will list NIC and PCIe Bus:Device:Function with kerel device name and driver.
    2. use ethtool [eth device name] | grep Link to identify the link is connected.

    for reference, you can use https://github.com/vipinpv85/DPDK-APP_SAMPLES/blob/master/auto-baseaddr-selector.c as template for dummy applciation.