From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 89CF537AF for ; Tue, 3 Feb 2015 03:37:28 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP; 02 Feb 2015 18:33:58 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,510,1418112000"; d="scan'208";a="671814367" Received: from pgsmsx103.gar.corp.intel.com ([10.221.44.82]) by fmsmga002.fm.intel.com with ESMTP; 02 Feb 2015 18:37:24 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by PGSMSX103.gar.corp.intel.com (10.221.44.82) with Microsoft SMTP Server (TLS) id 14.3.195.1; Tue, 3 Feb 2015 10:37:23 +0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.253]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.168]) with mapi id 14.03.0195.001; Tue, 3 Feb 2015 10:37:23 +0800 From: "Qiu, Michael" To: Tetsuya Mukawa , "dev@dpdk.org" Thread-Topic: [PATCH v6 07/13] ethdev: Add functions that will be used by port hotplug functions Thread-Index: AQHQPdP0fuVrmZhgX06gX2OWSzwBOA== Date: Tue, 3 Feb 2015 02:37:22 +0000 Message-ID: <533710CFB86FA344BFBF2D6802E60286CD3AFD@SHSMSX101.ccr.corp.intel.com> References: <1421664027-17971-9-git-send-email-mukawa@igel.co.jp> <1422763322-13742-1-git-send-email-mukawa@igel.co.jp> <1422763322-13742-8-git-send-email-mukawa@igel.co.jp> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v6 07/13] 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: Tue, 03 Feb 2015 02:37:29 -0000 On 2/1/2015 12:02 PM, Tetsuya Mukawa wrote:=0A= > The patch adds following functions.=0A= >=0A= > - rte_eth_dev_save()=0A= > The function is used for saving current rte_eth_dev structures.=0A= > - rte_eth_dev_get_changed_port()=0A= > The function receives the rte_eth_dev structures, then compare=0A= > these with current values to know which port is actually=0A= > attached or detached.=0A= > - rte_eth_dev_get_addr_by_port()=0A= > The function returns a pci address of a ethdev specified by port=0A= > identifier.=0A= > - rte_eth_dev_get_port_by_addr()=0A= > The function returns a port identifier of a ethdev specified by=0A= > pci address.=0A= > - rte_eth_dev_get_name_by_port()=0A= > The function returns a unique identifier name of a ethdev=0A= > specified by port identifier.=0A= > - Add rte_eth_dev_check_detachable()=0A= > The function returns whether a PMD supports detach function.=0A= >=0A= > Also the patch changes scope of rte_eth_dev_allocated() to global.=0A= > This function will be called by virtual PMDs to support port hotplug.=0A= > So change scope of the function to global.=0A= >=0A= > v5:=0A= > - Fix return value of below functions.=0A= > rte_eth_dev_get_changed_port().=0A= > rte_eth_dev_get_port_by_addr().=0A= > v4:=0A= > - Add paramerter checking.=0A= > v3:=0A= > - Fix if-condition bug while comparing pci addresses.=0A= > - Add error checking codes.=0A= > Reported-by: Mark Enright =0A= >=0A= > Signed-off-by: Tetsuya Mukawa =0A= > ---=0A= > lib/librte_ether/rte_ethdev.c | 98 +++++++++++++++++++++++++++++++++++++= +++++-=0A= > lib/librte_ether/rte_ethdev.h | 80 +++++++++++++++++++++++++++++++++++= =0A= > 2 files changed, 177 insertions(+), 1 deletion(-)=0A= >=0A= > diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.= c=0A= > index 7bed901..5aded10 100644=0A= > --- a/lib/librte_ether/rte_ethdev.c=0A= > +++ b/lib/librte_ether/rte_ethdev.c=0A= > @@ -206,7 +206,7 @@ rte_eth_dev_data_alloc(void)=0A= > RTE_MAX_ETHPORTS * sizeof(*rte_eth_dev_data));=0A= > }=0A= > =0A= > -static struct rte_eth_dev *=0A= > +struct rte_eth_dev *=0A= > rte_eth_dev_allocated(const char *name)=0A= > {=0A= > unsigned i;=0A= > @@ -426,6 +426,102 @@ rte_eth_dev_count(void)=0A= > return (nb_ports);=0A= > }=0A= > =0A= > +void=0A= > +rte_eth_dev_save(struct rte_eth_dev *devs)=0A= > +{=0A= > + if (devs =3D=3D NULL)=0A= > + return;=0A= > +=0A= > + /* save current rte_eth_devices */=0A= > + memcpy(devs, rte_eth_devices,=0A= > + sizeof(struct rte_eth_dev) * RTE_MAX_ETHPORTS);=0A= > +}=0A= > +=0A= > +int=0A= > +rte_eth_dev_get_changed_port(struct rte_eth_dev *devs, uint8_t *port_id)= =0A= > +{=0A= > + if ((devs =3D=3D NULL) || (port_id =3D=3D NULL))=0A= > + return -EINVAL;=0A= > +=0A= > + /* check which port was attached or detached */=0A= > + for (*port_id =3D 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++, devs++)= {=0A= > + if (rte_eth_devices[*port_id].attached ^ devs->attached)=0A= > + return 0;=0A= > + }=0A= > + return -ENODEV;=0A= > +}=0A= > +=0A= > +int=0A= > +rte_eth_dev_get_addr_by_port(uint8_t port_id, struct rte_pci_addr *addr)= =0A= > +{=0A= > + if (rte_eth_dev_validate_port(port_id, TRACE) =3D=3D DEV_INVALID)=0A= > + return -EINVAL;=0A= > +=0A= > + if (addr =3D=3D NULL) {=0A= > + PMD_DEBUG_TRACE("Null pointer is specified\n");=0A= > + return -EINVAL;=0A= > + }=0A= > +=0A= > + *addr =3D rte_eth_devices[port_id].pci_dev->addr;=0A= > + return 0;=0A= > +}=0A= > +=0A= > +int=0A= > +rte_eth_dev_get_port_by_addr(struct rte_pci_addr *addr, uint8_t *port_id= )=0A= > +{=0A= > + struct rte_pci_addr *tmp;=0A= > +=0A= > + if ((addr =3D=3D NULL) || (port_id =3D=3D NULL)) {=0A= > + PMD_DEBUG_TRACE("Null pointer is specified\n");=0A= > + return -EINVAL;=0A= > + }=0A= > +=0A= > + for (*port_id =3D 0; *port_id < RTE_MAX_ETHPORTS; (*port_id)++) {=0A= > + if (!rte_eth_devices[*port_id].attached)=0A= > + continue;=0A= > + if (!rte_eth_devices[*port_id].pci_dev)=0A= > + continue;=0A= > + tmp =3D &rte_eth_devices[*port_id].pci_dev->addr;=0A= > + if (eal_compare_pci_addr(tmp, addr) =3D=3D 0)=0A= > + return 0;=0A= > + }=0A= > + return -ENODEV;=0A= > +}=0A= > +=0A= > +int=0A= > +rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)=0A= > +{=0A= > + char *tmp;=0A= > +=0A= > + if (rte_eth_dev_validate_port(port_id, TRACE) =3D=3D DEV_INVALID)=0A= > + return -EINVAL;=0A= > +=0A= > + if (name =3D=3D NULL) {=0A= > + PMD_DEBUG_TRACE("Null pointer is specified\n");=0A= > + return -EINVAL;=0A= > + }=0A= > +=0A= > + /* shouldn't check 'rte_eth_devices[i].data',=0A= > + * because it might be overwritten by VDEV PMD */=0A= > + tmp =3D rte_eth_dev_data[port_id].name;=0A= > + strncpy(name, tmp, strlen(tmp) + 1);=0A= > + return 0;=0A= > +}=0A= > +=0A= > +int=0A= > +rte_eth_dev_check_detachable(uint8_t port_id)=0A= > +{=0A= > + uint32_t drv_flags;=0A= > +=0A= > + if (port_id >=3D RTE_MAX_ETHPORTS) {=0A= > + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id);=0A= > + return -EINVAL;=0A= > + }=0A= > +=0A= > + drv_flags =3D rte_eth_devices[port_id].driver->pci_drv.drv_flags;=0A= =0A= Here should be better to add pt_driver for pci_dev type port.=0A= =0A= Thanks,=0A= Michael=0A= > + return !(drv_flags & RTE_PCI_DRV_DETACHABLE);=0A= > +}=0A= > +=0A= > static int=0A= > rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues)= =0A= > {=0A= > diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.= h=0A= > index 91d9e86..9919968 100644=0A= > --- a/lib/librte_ether/rte_ethdev.h=0A= > +++ b/lib/librte_ether/rte_ethdev.h=0A= > @@ -1616,6 +1616,86 @@ extern struct rte_eth_dev rte_eth_devices[];=0A= > extern uint8_t rte_eth_dev_count(void);=0A= > =0A= > /**=0A= > + * Function for internal use by port hotplug functions.=0A= > + * Copies current ethdev structures to the specified pointer.=0A= > + *=0A= > + * @param devs The pointer to the ethdev structures=0A= > + */=0A= > +extern void rte_eth_dev_save(struct rte_eth_dev *devs);=0A= > +=0A= > +/**=0A= > + * Function for internal use by port hotplug functions.=0A= > + * Compare the specified ethdev structures with currents. Then=0A= > + * if there is a port which status is changed, fill the specified pointe= r=0A= > + * with the port id of that port.=0A= > + * @param devs The pointer to the ethdev structures=0A= > + * @param port_id The pointer to the port id=0A= > + * @return=0A= > + * - 0 on success, negative on error=0A= > + */=0A= > +extern int rte_eth_dev_get_changed_port(=0A= > + struct rte_eth_dev *devs, uint8_t *port_id);=0A= > +=0A= > +/**=0A= > + * Function for internal use by port hotplug functions.=0A= > + * Returns a pci address of a ethdev specified by port identifier.=0A= > + * @param port_id=0A= > + * The port identifier of the Ethernet device=0A= > + * @param addr=0A= > + * The pointer to the pci address=0A= > + * @return=0A= > + * - 0 on success, negative on error=0A= > + */=0A= > +extern int rte_eth_dev_get_addr_by_port(=0A= > + uint8_t port_id, struct rte_pci_addr *addr);=0A= > +=0A= > +/**=0A= > + * Function for internal use by port hotplug functions.=0A= > + * Returns a port identifier of a ethdev specified by pci address.=0A= > + * @param addr=0A= > + * The pointer to the pci address of the Ethernet device.=0A= > + * @param port_id=0A= > + * The pointer to the port identifier=0A= > + * @return=0A= > + * - 0 on success, negative on error=0A= > + */=0A= > +extern int rte_eth_dev_get_port_by_addr(=0A= > + struct rte_pci_addr *addr, uint8_t *port_id);=0A= > +=0A= > +/**=0A= > + * Function for internal use by port hotplug functions.=0A= > + * Returns a unique identifier name of a ethdev specified by port identi= fier.=0A= > + * @param port_id=0A= > + * The port identifier.=0A= > + * @param name=0A= > + * The pointer to the Unique identifier name for each Ethernet device= =0A= > + * @return=0A= > + * - 0 on success, negative on error=0A= > + */=0A= > +extern int rte_eth_dev_get_name_by_port(uint8_t port_id, char *name);=0A= > +=0A= > +/**=0A= > + * Function for internal use by port hotplug functions.=0A= > + * Check whether or not, a PMD that is handling the ethdev specified by = port=0A= > + * identifier can support detach function.=0A= > + * @param port_id=0A= > + * The port identifier=0A= > + * @return=0A= > + * - 0 on supporting detach function, negative on not supporting=0A= > + */=0A= > +extern int rte_eth_dev_check_detachable(uint8_t port_id);=0A= > +=0A= > +/**=0A= > + * Function for internal use by port hotplug functions.=0A= > + * Returns a ethdev slot specified by the unique identifier name.=0A= > + * @param name=0A= > + * The pointer to the Unique identifier name for each Ethernet device= =0A= > + * @return=0A= > + * - The pointer to the ethdev slot, on success. NULL on error=0A= > + */=0A= > +extern struct rte_eth_dev *rte_eth_dev_allocated(const char *name);=0A= > +=0A= > +/**=0A= > * Function for internal use by dummy drivers primarily, e.g. ring-based= =0A= > * driver.=0A= > * Allocates a new ethdev slot for an ethernet device and returns the po= inter=0A= =0A=