From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pd0-f178.google.com (mail-pd0-f178.google.com [209.85.192.178]) by dpdk.org (Postfix) with ESMTP id 8D18E5A1F for ; Wed, 21 Jan 2015 10:03:02 +0100 (CET) Received: by mail-pd0-f178.google.com with SMTP id y10so9046206pdj.9 for ; Wed, 21 Jan 2015 01:03:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=I2YgmDodfvCQNIgYmx6i7QpnGMCqjBIt2unVpMm0MmI=; b=IjisM/7OrxHmokW4hIArUaPI2RWNKLa3wZRhRJ9RRvhwWFSdjR+ms44a5gBlSX/2mj KIkgSOcTMwi8xIPoWGqzSikaj6PAh053ZLpMR14AgDcLGLxQFLwsv1taTa6cKKmzgbyt qKUfcfVrIGh0GsFVGNNNPGB3+9Pl2vQSuyvuRzL5DcrwaUsFP1QGi+sPsTCYtx+G/b43 gokx2/C/6s4y2SO7KGA+jOLBW3cNyefak4OySxDQfbkFW3ZqSCfTG0brw73CZVmrwH94 FmQG8Q2j8Hj7n20v0Uil4AAMM9wnpHEmRgSAo9l1+W9xwFxVxY28fed8c+uDg6JKPVEd BbsQ== X-Gm-Message-State: ALoCoQkjiiHtbKwAzPxpiLBzOKdCoewM4Flcvy+O9eNHYymXl8dSswt87SdKcMQLa4n/P56RSMdv X-Received: by 10.70.135.9 with SMTP id po9mr13012565pdb.47.1421830981750; Wed, 21 Jan 2015 01:03:01 -0800 (PST) Received: from [10.16.129.101] (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id qb10sm5274515pbb.9.2015.01.21.01.03.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Jan 2015 01:03:01 -0800 (PST) Message-ID: <54BF6B43.1080401@igel.co.jp> Date: Wed, 21 Jan 2015 18:02:59 +0900 From: Tetsuya Mukawa User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: "Qiu, Michael" References: <1418106629-22227-2-git-send-email-mukawa@igel.co.j> <1421664027-17971-1-git-send-email-mukawa@igel.co.jp> <1421664027-17971-6-git-send-email-mukawa@igel.co.jp> <533710CFB86FA344BFBF2D6802E60286CB7F5F@SHSMSX101.ccr.corp.intel.com> In-Reply-To: <533710CFB86FA344BFBF2D6802E60286CB7F5F@SHSMSX101.ccr.corp.intel.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] [PATCH v4 05/11] ethdev: Add functions that will be used by port hotplug functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jan 2015 09:03:03 -0000 Hi Michael, On 2015/01/21 11:40, Qiu, Michael wrote: > On 1/19/2015 6:42 PM, Tetsuya Mukawa wrote: >> The patch adds following functions. >> >> - rte_eth_dev_save() >> The function is used for saving current rte_eth_dev structures. >> - rte_eth_dev_get_changed_port() >> The function receives the rte_eth_dev structures, then compare >> these with current values to know which port is actually >> attached or detached. >> - rte_eth_dev_get_addr_by_port() >> The function returns a pci address of a ethdev specified by port >> identifier. >> - rte_eth_dev_get_port_by_addr() >> The function returns a port identifier of a ethdev specified by >> pci address. >> - rte_eth_dev_get_name_by_port() >> The function returns a unique identifier name of a ethdev >> specified by port identifier. >> - Add rte_eth_dev_check_detachable() >> The function returns whether a PMD supports detach function. >> >> Also the patch changes scope of rte_eth_dev_allocated() to global. >> This function will be called by virtual PMDs to support port hotplug. >> So change scope of the function to global. >> >> v4: >> - Add paramerter checking. >> v3: >> - Fix if-condition bug while comparing pci addresses. >> - Add error checking codes. >> Reported-by: Mark Enright >> >> Signed-off-by: Tetsuya Mukawa >> --- >> lib/librte_ether/rte_ethdev.c | 102 +++++++++++++++++++++++++++++++++++++++++- >> lib/librte_ether/rte_ethdev.h | 80 +++++++++++++++++++++++++++++++++ >> 2 files changed, 181 insertions(+), 1 deletion(-) >> >> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c >> index e5145b7..e572ef4 100644 >> --- a/lib/librte_ether/rte_ethdev.c >> +++ b/lib/librte_ether/rte_ethdev.c >> @@ -206,7 +206,7 @@ rte_eth_dev_data_alloc(void) >> RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data)); >> } >> >> -static struct rte_eth_dev * >> +struct rte_eth_dev * >> rte_eth_dev_allocated(const char *name) >> { >> unsigned i; >> @@ -422,6 +422,106 @@ rte_eth_dev_count(void) >> return (nb_ports); >> } >> >> +void >> +rte_eth_dev_save(struct rte_eth_dev *devs) >> +{ >> + if (devs == NULL) >> + return; >> + >> + /* save current rte_eth_devices */ >> + memcpy(devs, rte_eth_devices, >> + sizeof(struct rte_eth_dev) * RTE_MAX_ETHPORTS); >> +} >> + >> +int >> +rte_eth_dev_get_changed_port(struct rte_eth_dev *devs, uint8_t *port_id) >> +{ >> + if ((devs == NULL) || (port_id == NULL)) >> + return -1; >> + >> + /* check which port was attached or detached */ >> + for (*port_id = 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++, devs++) { >> + if (rte_eth_devices[*port_id].attached ^ devs->attached) >> + return 0; >> + } >> + return 1; >> +} >> + >> +int >> +rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr) >> +{ >> + if (rte_eth_dev_validate_port(port_id) == DEV_INVALID) { >> + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); >> + return -EINVAL; >> + } >> + >> + if (addr == NULL) { >> + PMD_DEBUG_TRACE("Null pointer is specified\n"); >> + return -EINVAL; >> + } >> + >> + *addr = rte_eth_devices[port_id].pci_dev->addr; >> + return 0; >> +} >> + >> +int >> +rte_eth_dev_get_port_by_addr(struct rte_pci_addr *addr, uint8_t *port_id) >> +{ >> + struct rte_pci_addr *tmp; >> + >> + if ((addr == NULL) || (port_id == NULL)) { >> + PMD_DEBUG_TRACE("Null pointer is specified\n"); >> + return -1; > Is it better to replace "-1" to "-EINVAL" ? Thanks. I will do like above. Regards, Tetsuya > >> + } >> + >> + for (*port_id = 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++) { >> + if (!rte_eth_devices[*port_id].attached) >> + continue; >> + if (!rte_eth_devices[*port_id].pci_dev) >> + continue; >> + tmp = &rte_eth_devices[*port_id].pci_dev->addr; >> + if (eal_compare_pci_addr(tmp, addr) == 0) >> + return 0; >> + } >> + return -1; >> +} >> + >> +int >> +rte_eth_dev_get_name_by_port(uint8_t port_id, char *name) >> +{ >> + char *tmp; >> + >> + if (rte_eth_dev_validate_port(port_id) == DEV_INVALID) { >> + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); >> + return -EINVAL; >> + } >> + >> + if (name == NULL) { >> + PMD_DEBUG_TRACE("Null pointer is specified\n"); >> + return -EINVAL; >> + } >> + >> + /* shouldn't check 'rte_eth_devices[i].data', >> + * because it might be overwritten by VDEV PMD */ >> + tmp = rte_eth_dev_data[port_id].name; >> + strncpy(name, tmp, strlen(tmp) + 1); >> + return 0; >> +} >> + >> +int >> +rte_eth_dev_check_detachable(uint8_t port_id) >> +{ >> + uint32_t drv_flags; >> + >> + if (port_id >= RTE_MAX_ETHPORTS) { >> + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); >> + return -EINVAL; >> + } >> + >> + drv_flags = rte_eth_devices[port_id].driver->pci_drv.drv_flags; >> + return !(drv_flags & RTE_PCI_DRV_DETACHABLE); >> +} >> + >> static int >> rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) >> { >> diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h >> index 2a8ff26..c0b98dc 100644 >> --- a/lib/librte_ether/rte_ethdev.h >> +++ b/lib/librte_ether/rte_ethdev.h >> @@ -1642,6 +1642,86 @@ extern struct rte_eth_dev rte_eth_devices[]; >> extern uint8_t rte_eth_dev_count(void); >> >> /** >> + * Function for internal use by port hotplug functions. >> + * Copies current ethdev structures to the specified pointer. >> + * >> + * @param devs The pointer to the ethdev structures >> + */ >> +extern void rte_eth_dev_save(struct rte_eth_dev *devs); >> + >> +/** >> + * Function for internal use by port hotplug functions. >> + * Compare the specified ethdev structures with currents. Then >> + * if there is a port which status is changed, fill the specified pointer >> + * with the port id of that port. >> + * @param devs The pointer to the ethdev structures >> + * @param port_id The pointer to the port id >> + * @return >> + * - 0 on success, negative on error >> + */ >> +extern int rte_eth_dev_get_changed_port( >> + struct rte_eth_dev *devs, uint8_t *port_id); >> + >> +/** >> + * Function for internal use by port hotplug functions. >> + * Returns a pci address of a ethdev specified by port identifier. >> + * @param port_id >> + * The port identifier of the Ethernet device >> + * @param addr >> + * The pointer to the pci address >> + * @return >> + * - 0 on success, negative on error >> + */ >> +extern int rte_eth_dev_get_addr_by_port( >> + uint8_t port_id, struct rte_pci_addr *addr); >> + >> +/** >> + * Function for internal use by port hotplug functions. >> + * Returns a port identifier of a ethdev specified by pci address. >> + * @param addr >> + * The pointer to the pci address of the Ethernet device. >> + * @param port_id >> + * The pointer to the port identifier >> + * @return >> + * - 0 on success, negative on error >> + */ >> +extern int rte_eth_dev_get_port_by_addr( >> + struct rte_pci_addr *addr, uint8_t *port_id); >> + >> +/** >> + * Function for internal use by port hotplug functions. >> + * Returns a unique identifier name of a ethdev specified by port identifier. >> + * @param port_id >> + * The port identifier. >> + * @param name >> + * The pointer to the Unique identifier name for each Ethernet device >> + * @return >> + * - 0 on success, negative on error >> + */ >> +extern int rte_eth_dev_get_name_by_port(uint8_t port_id, char *name); >> + >> +/** >> + * Function for internal use by port hotplug functions. >> + * Check whether or not, a PMD that is handling the ethdev specified by port >> + * identifier can support detach function. >> + * @param port_id >> + * The port identifier >> + * @return >> + * - 0 on supporting detach function, negative on not supporting >> + */ >> +extern int rte_eth_dev_check_detachable(uint8_t port_id); >> + >> +/** >> + * Function for internal use by port hotplug functions. >> + * Returns a ethdev slot specified by the unique identifier name. >> + * @param name >> + * The pointer to the Unique identifier name for each Ethernet device >> + * @return >> + * - The pointer to the ethdev slot, on success. NULL on error >> + */ >> +extern struct rte_eth_dev *rte_eth_dev_allocated(const char *name); >> + >> +/** >> * Function for internal use by dummy drivers primarily, e.g. ring-based >> * driver. >> * Allocates a new ethdev slot for an ethernet device and returns the pointer