From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 64E5CB5DD for ; Thu, 19 Feb 2015 15:32:20 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP; 19 Feb 2015 06:26:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,608,1418112000"; d="scan'208";a="680362502" Received: from irsmsx101.ger.corp.intel.com ([163.33.3.153]) by fmsmga002.fm.intel.com with ESMTP; 19 Feb 2015 06:32:16 -0800 Received: from irsmsx108.ger.corp.intel.com ([169.254.11.218]) by IRSMSX101.ger.corp.intel.com ([163.33.3.153]) with mapi id 14.03.0195.001; Thu, 19 Feb 2015 14:31:48 +0000 From: "Iremonger, Bernard" To: Tetsuya Mukawa , "dev@dpdk.org" Thread-Topic: [PATCH v9 07/14] eal,ethdev: Add a function and function pointers to close ether device Thread-Index: AQHQS+76B87tkldb8kuV7moLT9yaYpz4B/wQ Date: Thu, 19 Feb 2015 14:31:48 +0000 Message-ID: <8CEF83825BEC744B83065625E567D7C2049EB1A3@IRSMSX108.ger.corp.intel.com> References: <1424060073-23484-12-git-send-email-mukawa@igel.co.jp> <1424314187-25177-1-git-send-email-mukawa@igel.co.jp> <1424314187-25177-8-git-send-email-mukawa@igel.co.jp> In-Reply-To: <1424314187-25177-8-git-send-email-mukawa@igel.co.jp> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v9 07/14] eal, ethdev: Add a function and function pointers to close ether device 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: Thu, 19 Feb 2015 14:32:20 -0000 > -----Original Message----- > From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp] > Sent: Thursday, February 19, 2015 2:50 AM > To: dev@dpdk.org > Cc: Qiu, Michael; Iremonger, Bernard; thomas.monjalon@6wind.com; Tetsuya = Mukawa > Subject: [PATCH v9 07/14] eal,ethdev: Add a function and function pointer= s to close ether device >=20 > The patch adds function pointer to rte_pci_driver and eth_driver structur= e. These function pointers > are used when ports are detached. > Also, the patch adds rte_eth_dev_uninit(). So far, it's not called by any= where, but it will be called > when port hotplug function is implemented. >=20 > v9: > - Change parameter of pci_devuninit_t and rte_eth_dev_uninit. > - Remove code that initiaize callback of ethdev from > rte_eth_dev_uninit(). > - Add a function to create a unique device name. > (Thanks to Thomas Monjalon) > v6: > - Fix rte_eth_dev_uninit() to handle a return value of uninit > function of PMD. > v4: > - Add parameter checking. > - Change function names. >=20 > Signed-off-by: Tetsuya Mukawa > --- > lib/librte_eal/common/include/rte_pci.h | 6 ++++ > lib/librte_ether/rte_ethdev.c | 62 +++++++++++++++++++++++++++= ++++-- > lib/librte_ether/rte_ethdev.h | 24 +++++++++++++ > 3 files changed, 90 insertions(+), 2 deletions(-) >=20 > diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/com= mon/include/rte_pci.h > index c609ef3..376f66a 100644 > --- a/lib/librte_eal/common/include/rte_pci.h > +++ b/lib/librte_eal/common/include/rte_pci.h > @@ -189,12 +189,18 @@ struct rte_pci_driver; typedef int (pci_devinit_t)= (struct rte_pci_driver *, > struct rte_pci_device *); >=20 > /** > + * Uninitialisation function for the driver called during hotplugging. > + */ > +typedef int (pci_devuninit_t)(struct rte_pci_device *); > + > +/** > * A structure describing a PCI driver. > */ > struct rte_pci_driver { > TAILQ_ENTRY(rte_pci_driver) next; /**< Next in list. */ > const char *name; /**< Driver name. */ > pci_devinit_t *devinit; /**< Device init. function. */ > + pci_devuninit_t *devuninit; /**< Device uninit function. */ > struct rte_pci_id *id_table; /**< ID table, NULL terminated.= */ > uint32_t drv_flags; /**< Flags contolling handling = of device. */ > }; > diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.= c index be5aa18..ef5d226 > 100644 > --- a/lib/librte_ether/rte_ethdev.c > +++ b/lib/librte_ether/rte_ethdev.c > @@ -266,6 +266,24 @@ rte_eth_dev_release_port(struct rte_eth_dev *eth_dev= ) > return 0; > } >=20 > +static inline int > +rte_eth_dev_create_unique_device_name(char *name, > + struct rte_pci_device *pci_dev) > +{ > + int ret; > + > + if ((name =3D=3D NULL) || (pci_dev =3D=3D NULL)) > + return -EINVAL; > + Hi Tetsuya, It would be safer to pass in the size of the name buffer and use it in the = snprintf() call . Regards, Bernard. > + ret =3D snprintf(name, RTE_ETH_NAME_MAX_LEN, "%d:%d.%d", > + pci_dev->addr.bus, pci_dev->addr.devid, > + pci_dev->addr.function); > + if (ret < 0) > + return ret; > + > + return 0; > +} > + > static int > rte_eth_dev_init(struct rte_pci_driver *pci_drv, > struct rte_pci_device *pci_dev) > @@ -279,8 +297,7 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv, > eth_drv =3D (struct eth_driver *)pci_drv; >=20 > /* Create unique Ethernet device name using PCI address */ > - snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "%d:%d.%d", > - pci_dev->addr.bus, pci_dev->addr.devid, pci_dev->addr.function); > + rte_eth_dev_create_unique_device_name(ethdev_name, pci_dev); >=20 > eth_dev =3D rte_eth_dev_allocate(ethdev_name); > if (eth_dev =3D=3D NULL) > @@ -321,6 +338,46 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv, > return diag; > } >=20 > +static int > +rte_eth_dev_uninit(struct rte_pci_device *pci_dev) { > + const struct eth_driver *eth_drv; > + struct rte_eth_dev *eth_dev; > + char ethdev_name[RTE_ETH_NAME_MAX_LEN]; > + int ret; > + > + if (pci_dev =3D=3D NULL) > + return -EINVAL; > + > + /* Create unique Ethernet device name using PCI address */ > + rte_eth_dev_create_unique_device_name(ethdev_name, pci_dev); > + > + eth_dev =3D rte_eth_dev_allocated(ethdev_name); > + if (eth_dev =3D=3D NULL) > + return -ENODEV; > + > + eth_drv =3D (const struct eth_driver *)pci_dev->driver; > + > + /* Invoke PMD device uninit function */ > + if (*eth_drv->eth_dev_uninit) { > + ret =3D (*eth_drv->eth_dev_uninit)(eth_drv, eth_dev); > + if (ret) > + return ret; > + } > + > + /* free ether device */ > + rte_eth_dev_release_port(eth_dev); > + > + if (rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY) > + rte_free(eth_dev->data->dev_private); > + > + eth_dev->pci_dev =3D NULL; > + eth_dev->driver =3D NULL; > + eth_dev->data =3D NULL; > + > + return 0; > +} > + > /** > * Register an Ethernet [Poll Mode] driver. > * > @@ -339,6 +396,7 @@ void > rte_eth_driver_register(struct eth_driver *eth_drv) { > eth_drv->pci_drv.devinit =3D rte_eth_dev_init; > + eth_drv->pci_drv.devuninit =3D rte_eth_dev_uninit; > rte_eal_pci_register(ð_drv->pci_drv); > } >=20 > diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.= h index 28ecafd..f403780 > 100644 > --- a/lib/librte_ether/rte_ethdev.h > +++ b/lib/librte_ether/rte_ethdev.h > @@ -1677,6 +1677,27 @@ typedef int (*eth_dev_init_t)(struct eth_driver *= eth_drv, >=20 > /** > * @internal > + * Finalization function of an Ethernet driver invoked for each > +matching > + * Ethernet PCI device detected during the PCI closing phase. > + * > + * @param eth_drv > + * The pointer to the [matching] Ethernet driver structure supplied by > + * the PMD when it registered itself. > + * @param eth_dev > + * The *eth_dev* pointer is the address of the *rte_eth_dev* structure > + * associated with the matching device and which have been [automatica= lly] > + * allocated in the *rte_eth_devices* array. > + * @return > + * - 0: Success, the device is properly finalized by the driver. > + * In particular, the driver MUST free the *dev_ops* pointer > + * of the *eth_dev* structure. > + * - <0: Error code of the device initialization failure. > + */ > +typedef int (*eth_dev_uninit_t)(const struct eth_driver *eth_drv, > + struct rte_eth_dev *eth_dev); > + > +/** > + * @internal > * The structure associated with a PMD Ethernet driver. > * > * Each Ethernet driver acts as a PCI driver and is represented by a gen= eric @@ -1686,11 +1707,14 @@ > typedef int (*eth_dev_init_t)(struct eth_driver *eth_drv, > * > * - The *eth_dev_init* function invoked for each matching PCI device. > * > + * - The *eth_dev_uninit* function invoked for each matching PCI device. > + * > * - The size of the private data to allocate for each matching device. > */ > struct eth_driver { > struct rte_pci_driver pci_drv; /**< The PMD is also a PCI driver. */ > eth_dev_init_t eth_dev_init; /**< Device init function. */ > + eth_dev_uninit_t eth_dev_uninit; /**< Device uninit function. */ > unsigned int dev_private_size; /**< Size of device private data. */ > }; >=20 > -- > 1.9.1