From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 447AB7260 for ; Tue, 16 Jan 2018 21:20:07 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2018 12:20:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,369,1511856000"; d="scan'208";a="19909740" Received: from fyigit-mobl1.ger.corp.intel.com (HELO [10.237.220.48]) ([10.237.220.48]) by orsmga003.jf.intel.com with ESMTP; 16 Jan 2018 12:20:04 -0800 To: Yuanhan Liu , dev@dpdk.org Cc: Thomas Monjalon , Adrien Mazarguil , Ciara Loftus , Kevin Traynor References: <1512027330-30030-1-git-send-email-yliu@fridaylinux.org> From: Ferruh Yigit Message-ID: Date: Tue, 16 Jan 2018 20:20:03 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <1512027330-30030-1-git-send-email-yliu@fridaylinux.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: Re: [dpdk-dev] [PATCH] [RFC] ether: standardize getting the port by name X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Jan 2018 20:20:07 -0000 On 11/30/2017 7:35 AM, Yuanhan Liu wrote: > The ethdev name is taken from the "name" parameter from the helper > function rte_eth_dev_allocate(name). The name is given by the caller, > thus, there is no way to guarantee all the callers will follow the > same syntax, leaving us the port name is not standardized. > > For example, for all ports probed by the generic pci probe function, > the name is set to the PCI id. For all others, it's set by the caller, > aka, the PMD driver. Taking mlx PMD driver as the example, it's set > to something like "mlx5_0 port 0". > > Unfortunately, ovs-dpdk uses such name for referencing a specific port. > Since there is no standard, user has to figure out what is the right > name for the nic he is using. That adds extra (unnecessary) obstruction > to users. Can you please give more details about the ovs-dpdk usage? I assume ovs-dpdk creates some virtual/physical devices while started, and during switch configuration it need to access those devices and this is done by getting device by name. That is why need to know the device name. If above assumption correct, can supporting a generic id=x devargs help? Ethdev can guarantie that unique ids provided are unique and provides API to get device by id. And in ovs-dpdk can use those ids directly, can this work? > > Thus, the name should be standardized. We should give user a consistent > interface for finding a specific port. > > What this patch proposes is to use "name[,mac]" syntax. "name" is the > PCI id for pci device. For vdev, it's the vdev name given by user. The > reason "mac" is needed is for some devices (say ConnectX-3), 2 ports > (in a single NIC) have the same PCI id. > > There are 2 reasons I didn't make "mac" mandatory: > - it keeps the compatibility > - in most cases, the pci id is good enough to identify a port > > However, while writing this commit log, I think it might be better to > use something like UUID for standardizing the port name. This way, we > will always have a very consistent naming, no matter whether it's PCI > device or vdev device and whether a PCI devices has 2 ports share the > same PIC id, or something we have considered so far (say, few ports > sharing same PCI and mac address :/). > > It's also simpler and cleaner. The only drawback is such ID is meaningless > to human. > > Please also note that this patch just comes up with an API to query > a port from standard name suggested above. The ethdev name isn't really > standardized here. This patch is asking for comments after all. > > Thoughts? > > Cc: Thomas Monjalon > Cc: Adrien Mazarguil > Cc: Ciara Loftus > Cc: Kevin Traynor > Signed-off-by: Yuanhan Liu > --- > lib/librte_ether/rte_ethdev.c | 61 +++++++++++++++++++++++++++++++++++++++++++ > lib/librte_ether/rte_ethdev.h | 28 ++++++++++++++++++++ > 2 files changed, 89 insertions(+) > > diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c > index 318af28..acf29e7 100644 > --- a/lib/librte_ether/rte_ethdev.c > +++ b/lib/librte_ether/rte_ethdev.c > @@ -362,6 +362,67 @@ rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id) > return -ENODEV; > } > > +static int > +str_to_ether(const char *mac, struct ether_addr *ea) > +{ > + unsigned int bytes[6]; > + int i; > + > + if (sscanf(mac, "%x:%x:%x:%x:%x:%x", > + &bytes[0], &bytes[1], &bytes[2], > + &bytes[3], &bytes[4], &bytes[5]) != 6) { > + return -1; > + } > + > + for (i = 0; i < 6; i++) > + ea->addr_bytes[i] = bytes[i]; > + > + return 0; > +} > + > +int > +rte_eth_dev_get_port(const char *devarg, uint16_t *port_id) > +{ > + int i; > + char *name; > + char *mac; > + struct ether_addr ea; > + int nr_match = 0; > + > + if (devarg == NULL) > + return -EINVAL; > + > + name = strdup(devarg); > + mac = strchr(name, ','); > + if (mac) { > + *mac++ = '\0'; > + if (str_to_ether(mac, &ea) < 0) > + return -EINVAL; > + } > + > + RTE_ETH_FOREACH_DEV(i) { > + if (strncmp(name, rte_eth_dev_data[i].name, strlen(name)) == 0) { > + *port_id = i; > + > + /* if mac is given, mac has to be matched also */ > + if (mac && !is_same_ether_addr(&ea, > + &rte_eth_dev_data[i].mac_addrs[0])) > + continue; > + > + *port_id = i; > + nr_match += 1; > + } > + } > + > + if (nr_match > 1) { > + RTE_LOG(ERR, EAL, "%d ports found with devarg: %s\n", > + nr_match, devarg); > + return -EINVAL; > + } > + > + return -ENODEV; > +} > + > /* attach the new device, then store port_id of the device */ > int > rte_eth_dev_attach(const char *devargs, uint16_t *port_id) > diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h > index 341c2d6..3e131b6 100644 > --- a/lib/librte_ether/rte_ethdev.h > +++ b/lib/librte_ether/rte_ethdev.h > @@ -4555,6 +4555,34 @@ int > rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id); > > /** > +* Get the port id from the devarg > +* > +* The standard syntax for the devarg is "name[,mac]". > +* > +* For PCI device, "name" is the PCI id, for example, "0000:2:00.0". > +* For vdev, it's the vdev name, for example, "net_pcap0". > +* > +* The "mac" is optional, as in most cases, the name (say, the PCI > +* id) is good enough to identify a specific port. However, there > +* are cases that multiple ports share a single PCI id. In such case, > +* mac is needed to identify the specific port. > +* > +* If more than one port is found by the given devarg, -EINVAL will > +* be returned. An error message will also be dumped. > +* > +* @param devarg > +* a standard devarg string > +* @param port_id > +* pointer to port identifier of the device > +* @return > +* - 0 if successful and port_id is filled. > +* - -ENODEV if no port found > +* - -EINVAL for invalid devarg > +*/ > +int > +rte_eth_dev_get_port(const char *devarg, uint16_t *port_id); > + > +/** > * Get the device name from port id > * > * @param port_id >