From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by dpdk.org (Postfix) with ESMTP id 2C821107A for ; Thu, 30 Nov 2017 08:35:38 +0100 (CET) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 7FC9920A94; Thu, 30 Nov 2017 02:35:38 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute1.internal (MEProxy); Thu, 30 Nov 2017 02:35:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fridaylinux.org; h=cc:date:from:message-id:subject:to:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=JDt6CIFIplXAldsIHiKMWjgDjUqbEaAkCcHXCMHqm pY=; b=N68FF8KOfEgVTsmRhs9UEin3Uh5WoUiRqqtEL8H8hLlk9KG+mTpGIdNn6 CeB8QuiJpJC/sDPwNEwsEVuikXs9c7Shc5k2fN+OgJU1wPi8bF6Zaa78RUQWLSG8 yQpGvQgvvTGcTnJARZHrPVfM4O33PpFaW+H5+xFlki7NirlWpCrTwueghjsCSyGv 8e09RrpFBCdmPUmvJkT20IT7CF/gVAEE0Hoj8i2TGl0/8R7chmYX07frObVT0dSy k5tpFiJLi2lfbjrvjfjaMLWDOZRXoenud+hnHqkIie3oGKJ0J8H4/kEhJBHq/90W /411RfU4TdyPEJzyLaEXNLkl4CqYA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:message-id:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=JDt6CIFIplXAldsIH iKMWjgDjUqbEaAkCcHXCMHqmpY=; b=lYfyzBKAuPo/IiQtvm9AzMkZcfa+mWhtQ MvSlGyOaTSbw39x3jAW3KCnvk96ZIzrZ9P5IGNL/x/KpW3g07UGH0/+0BUzoaEfF zyUhjvwP1pryDufl4kZnU9cmigUR14nLYZeRYtxnR9VuI6a+xLp7+P9OQykRCI7X 0xrgvz2kYzYSPZUHz4NkpjXip2ntbySKe2LztEM1B2CHKGXVhOaFmPairnJG1DzZ sKzraWziznuHM288H/gUGDAU4fOSBuOGn3i9p5HyDc1SMWVbvmDClNdHbF+31UZK uUBgiqAgYHCnYcwvFDUwVd1B4OLlVT8irR1unPhzAIJT1G/4jzkMg== X-ME-Sender: Received: from yliu-dev.mtl.com (unknown [101.229.191.5]) by mail.messagingengine.com (Postfix) with ESMTPA id 0639E7F7F5; Thu, 30 Nov 2017 02:35:34 -0500 (EST) From: Yuanhan Liu To: dev@dpdk.org Cc: Yuanhan Liu , Thomas Monjalon , Adrien Mazarguil , Ciara Loftus , Kevin Traynor Date: Thu, 30 Nov 2017 15:35:30 +0800 Message-Id: <1512027330-30030-1-git-send-email-yliu@fridaylinux.org> X-Mailer: git-send-email 2.7.4 Subject: [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: Thu, 30 Nov 2017 07:35:39 -0000 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. 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 -- 2.7.4