[ovs-dev] [ovs-dev, v2] netdev-dpdk: fix port addition for ports sharing same PCI id

Yuanhan Liu yliu at fridaylinux.org
Tue Jan 9 12:50:34 UTC 2018


On Tue, Jan 09, 2018 at 02:14:22PM +0300, Ilya Maximets wrote:
> > +static dpdk_port_t
> > +netdev_dpdk_get_port_by_mac(const char *mac_str)
> > +{
> > +    int i;
> > +    struct ether_addr mac;
> > +    struct ether_addr port_mac;
> > +
> > +    if (netdev_dpdk_str_to_ether(mac_str, &mac) != 0) {
> > +        return DPDK_ETH_PORT_ID_INVALID;
> > +    }
> > +
> > +    for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
> > +        if (!rte_eth_dev_is_valid_port(i)) {
> > +            continue;
> > +        }
> > +
> > +        rte_eth_macaddr_get(i, &port_mac);
> > +        if (is_same_ether_addr(&mac, &port_mac)) {
> > +            return i;
> > +        }
> > +    }
> > +
> > +    return DPDK_ETH_PORT_ID_INVALID;
> > +}
> 
> How about reusing of existing OVS functions and RTE_ETH_FOREACH_DEV
> for iteration ? Like this (not even compile tested):
> 
> static dpdk_port_t                                                                                                                   
> netdev_dpdk_get_port_by_mac(const char *mac_str)                                     
> {                                                                                    
>     dpdk_port_t pid;
>     struct eth_addr mac, port_mac;
>     struct ether_addr dpdk_port_mac;
> 
>     if (!eth_addr_from_string(mac_str, &mac)) {

Good tip. I wasn't aware of the existence of this helper function.

>         return DPDK_ETH_PORT_ID_INVALID;
>     }
> 
>     RTE_ETH_FOREACH_DEV (pid) {
>         rte_eth_macaddr_get(pid, &dpdk_port_mac);
>         memcpy(port_mac.ea, dpdk_port_mac.addr_bytes, ETH_ADDR_LEN);
> 
>         if (!eth_addr_equals(mac, port_mac)) {
>             return pid;
>         }
>     }
> 
>     return DPDK_ETH_PORT_ID_INVALID;
> }

Yep, it looks cleaner. I will fix them in v3. But I'd postpone it a
bit, for getting more comments (if any) and not flooding this list.

Thanks.

	--yliu


More information about the dev mailing list