Q:

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? 

A:

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:

create a dummy application to take in all DPDK port. 
Initialize and start the dpdk ports.  Check for link-state and create port-mask (global variable) which filters in application logic. 
Invoke rte_eth_dev_stop & rte_eth_dev_close for link down ports. 
Invoke rte_eal_cleanup. 
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

if the other end is connected to dpdk-pktgen, first your DPDK application has to init the NIC locally. 
if connected to linux box, the nic has to be bought up first with ifconfig [other nic] up
at times one needs to check link.link_speed if its valid. 
certain PMD needs write to PCIe mapped register, hence has to dev_configure and port_init to get a reliable reading for link status. 

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

lshw -c network -businfo will list NIC and PCIe Bus:Device:Function with kerel device name and driver. 
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.