R&D/DPDK

port hotplug

sunshout 2017. 4. 14. 10:30

void

attach_port(char *identifier)

{

        portid_t pi = 0;

        unsigned int socket_id;


        printf("Attaching a new port...\n");


        if (identifier == NULL) {

                printf("Invalid parameters are specified\n");

                return;

        }


        if (rte_eth_dev_attach(identifier, &pi))

                return;


        ports[pi].enabled = 1;

        socket_id = (unsigned)rte_eth_dev_socket_id(pi);

        /* if socket_id is invalid, set to 0 */

        if (check_socket_id(socket_id) < 0)

                socket_id = 0;

        reconfig(pi, socket_id);

        rte_eth_promiscuous_enable(pi);


        nb_ports = rte_eth_dev_count();


        ports[pi].port_status = RTE_PORT_STOPPED;


        printf("Port %d is attached. Now total ports is %d\n", pi, nb_ports);

        printf("Done\n");

}


http://dpdk.org/doc/guides/prog_guide/port_hotplug_framework.html


To attach new physical device ports, the device will be recognized by userspace driver I/O framework in kernel at first. Then DPDK applications can call the Port Hotplug functions to attach the ports. For detaching, steps are vice versa.



typedef uint8_t  portid_t;


int rte_eth_dev_attach(const char * devargs,
uint8_t * port_id 
)

Attach a new Ethernet device specified by aruguments.

Parameters
devargsA pointer to a strings array describing the new device to be attached. The strings should be a pci address like '0000:01:00.0' or virtual device name like 'net_pcap0'.
port_idA pointer to a port identifier actually attached.
Returns
0 on success and port_id is filled, negative on error



int rte_eth_dev_detach(uint8_t port_id,
char * devname 
)

Detach a Ethernet device specified by port identifier. This function must be called when the device is in the closed state.

Parameters
port_idThe port identifier of the device to detach.
devnameA pointer to a device name actually detached.
Returns
0 on success and devname is filled, negative on error


plugins/dpdk/device/init.c