From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0084.outbound.protection.outlook.com [104.47.0.84]) by dpdk.org (Postfix) with ESMTP id 4D5A32BD2 for ; Thu, 29 Mar 2018 08:13:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=5YE7j7spAPN11XoFWlK+kUUR/xl14wHee/QPj27BjS4=; b=ngn+OcRI5EBS7iFDguvLsPWVCS9G7qqaJGwkH6ZyNv64j0SCrVuVNs+dRpL/QINlH46zgf7+WXoJ57WyJ59b3fS/tefm7Mjw8mVi5tVBl/PW321mKSWFGXOZoeeg0bnDODokjIICFSb3cBj8mN7QIMwExz8kd6WDGbPJbga0PWU= Received: from DB7PR05MB4426.eurprd05.prod.outlook.com (52.134.109.15) by DB7PR05MB4137.eurprd05.prod.outlook.com (52.134.107.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.631.10; Thu, 29 Mar 2018 06:13:55 +0000 Received: from DB7PR05MB4426.eurprd05.prod.outlook.com ([fe80::808d:386e:26f3:859f]) by DB7PR05MB4426.eurprd05.prod.outlook.com ([fe80::808d:386e:26f3:859f%13]) with mapi id 15.20.0609.012; Thu, 29 Mar 2018 06:13:55 +0000 From: Shahaf Shuler To: Declan Doherty , "dev@dpdk.org" CC: Alex Rosenbaum , Ferruh Yigit , Thomas Monjalon , Qi Zhang , Alejandro Lucero , Andrew Rybchenko , Mohammad Abdul Awal , Remy Horton , "John McNamara" , Rony Efraim , Wu , Jingjing , Lu , Wenzhuo , Vincent JArdin , Yuanhan Liu , Richardson , Bruce , Ananyev , Konstantin , Wang , Zhihong Thread-Topic: [dpdk-dev][PATCH v6 3/8] ethdev: add generic create/destroy ethdev APIs Thread-Index: AQHTxp166Ef79YEEA0e0IAopLST1eaPmt3Cg Date: Thu, 29 Mar 2018 06:13:55 +0000 Message-ID: References: <20180328135433.20203-1-declan.doherty@intel.com> <20180328135433.20203-4-declan.doherty@intel.com> In-Reply-To: <20180328135433.20203-4-declan.doherty@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=shahafs@mellanox.com; x-originating-ip: [31.154.10.107] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB7PR05MB4137; 7:+1oDu8LOBGJijhdNcaDoOmHy2iQHY/f91fALpCL7YeFHDVRIOKvEZ6xF4CMVMDJNIN4Q1XECYpxeirt36THgVBL0bhRXhgpvFHWkp9rhKElzFp2zhhq7iCNSkmqNBon6NXVo9gGwlx9FmxweUTx+d/I1qExlZUYto6KMFSreepQhTNr+Eg/lsDa0OdX1OawlxFp7Qbv4u5BDyc2mm+KtwFX/4Gs/Ibag6gAv2kJXYXJmlvqIbzwKzTpWsKvegpz5 x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: abfb8229-dcde-4415-4446-08d5953c405d x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:DB7PR05MB4137; x-ms-traffictypediagnostic: DB7PR05MB4137: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(60795455431006)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(93006095)(93001095)(10201501046)(3231221)(944501327)(52105095)(6055026)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:DB7PR05MB4137; BCL:0; PCL:0; RULEID:; SRVR:DB7PR05MB4137; x-forefront-prvs: 0626C21B10 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(39860400002)(396003)(39380400002)(376002)(346002)(199004)(189003)(2900100001)(6506007)(3846002)(7696005)(5890100001)(7416002)(229853002)(2501003)(6116002)(26005)(33656002)(102836004)(81166006)(5660300001)(81156014)(186003)(106356001)(105586002)(316002)(76176011)(7736002)(54906003)(8936002)(8676002)(110136005)(5250100002)(59450400001)(53936002)(305945005)(6246003)(55016002)(486005)(476003)(86362001)(446003)(486005)(9686003)(2906002)(11346002)(6436002)(97736004)(25786009)(478600001)(66066001)(68736007)(4326008)(3660700001)(99286004)(39060400002)(74316002)(14454004)(3280700002)(41533002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR05MB4137; H:DB7PR05MB4426.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: tQQ8tQi4SEPWobYx5gn/an7OGl+i6Y/RzzrVfRbX5RtWaHXRnRarYXcwQurZZVjirw6jZcxLfbpPT+FJqQibc96SqLetUWaZzok1X8CpqZEx/075sYMHMGsjSyU/1F5PUH3aaa9n3C2WgO5R9C3pQXMGTM4AKB5WWMFejcX2N081K3NFCYteFfBmLXEi+fEf8PjHR6BJtCQUICgNmuh/Fj1sypBMdRXbqRDXuveQnKAS8BFPpm1NZc8WMsY/ShecdPyFcsDkxu8GPPXk1kQtklgxhaP4FOHNC4DXJ6dNIPAjtjQFx74yRM54ld0SNGsEBCcdw0/GjkTdlDupNRVjhg== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: abfb8229-dcde-4415-4446-08d5953c405d X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Mar 2018 06:13:55.1348 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR05MB4137 Subject: Re: [dpdk-dev] [PATCH v6 3/8] ethdev: add generic create/destroy ethdev APIs 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, 29 Mar 2018 06:13:58 -0000 Wednesday, March 28, 2018 4:54 PM, Declan Doherty: > Subject: [dpdk-dev][PATCH v6 3/8] ethdev: add generic create/destroy > ethdev APIs >=20 > Add new bus generic ethdev create/destroy APIs which are bus independent > and provide hooks for bus specific initialisation. >=20 > Signed-off-by: Declan Doherty > --- > lib/librte_ether/Makefile | 1 + > lib/librte_ether/meson.build | 1 + > lib/librte_ether/rte_ethdev.c | 96 > ++++++++++++++++++++++++++++++- > lib/librte_ether/rte_ethdev_driver.h | 57 ++++++++++++++++++ > lib/librte_ether/rte_ethdev_pci.h | 12 ++++ > lib/librte_ether/rte_ethdev_representor.h | 28 +++++++++ > lib/librte_ether/rte_ethdev_version.map | 8 +++ > 7 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 > lib/librte_ether/rte_ethdev_representor.h >=20 > diff --git a/lib/librte_ether/Makefile b/lib/librte_ether/Makefile index > 3ca5782bb..5698cd47b 100644 > --- a/lib/librte_ether/Makefile > +++ b/lib/librte_ether/Makefile > @@ -32,6 +32,7 @@ SYMLINK-y-include +=3D rte_ethdev_driver.h SYMLINK-y- > include +=3D rte_ethdev_core.h SYMLINK-y-include +=3D rte_ethdev_pci.h > SYMLINK-y-include +=3D rte_ethdev_vdev.h > +SYMLINK-y-include +=3D rte_ethdev_representor.h > SYMLINK-y-include +=3D rte_eth_ctrl.h > SYMLINK-y-include +=3D rte_dev_info.h > SYMLINK-y-include +=3D rte_flow.h > diff --git a/lib/librte_ether/meson.build b/lib/librte_ether/meson.build > index 7fed86056..163891556 100644 > --- a/lib/librte_ether/meson.build > +++ b/lib/librte_ether/meson.build > @@ -15,6 +15,7 @@ headers =3D files('rte_ethdev.h', > 'rte_ethdev_core.h', > 'rte_ethdev_pci.h', > 'rte_ethdev_vdev.h', > + 'rte_ethdev_representor.h', > 'rte_eth_ctrl.h', > 'rte_dev_info.h', > 'rte_flow.h', > diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.= c > index f32d18cad..c719f84a3 100644 > --- a/lib/librte_ether/rte_ethdev.c > +++ b/lib/librte_ether/rte_ethdev.c > @@ -345,7 +345,8 @@ rte_eth_dev_release_port(struct rte_eth_dev > *eth_dev) > rte_eth_dev_shared_data_prepare(); >=20 > rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock); > - > + eth_dev->device =3D NULL; > + eth_dev->intr_handle =3D NULL; > eth_dev->state =3D RTE_ETH_DEV_UNUSED; >=20 > memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data)); @@ - > 3403,6 +3404,99 @@ rte_eth_dma_zone_reserve(const struct rte_eth_dev > *dev, const char *ring_name, > return rte_memzone_reserve_aligned(z_name, size, socket_id, 0, > align); } >=20 > +int __rte_experimental > +rte_eth_dev_create(struct rte_device *device, const char *name, > + size_t priv_data_size, > + ethdev_bus_specific_init ethdev_bus_specific_init, > + void *bus_init_params, > + ethdev_init_t ethdev_init, void *init_params) { > + struct rte_eth_dev *ethdev; > + int retval; > + > + if (rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY) { > + ethdev =3D rte_eth_dev_allocate(name); > + if (!ethdev) { > + retval =3D -ENODEV; > + goto probe_failed; > + } > + > + if (priv_data_size) { > + ethdev->data->dev_private =3D rte_zmalloc_socket( > + name, priv_data_size, > RTE_CACHE_LINE_SIZE, > + device->numa_node); > + > + if (!ethdev->data->dev_private) { > + RTE_LOG(ERR, EAL, "failed to allocate private > data"); > + retval =3D -ENOMEM; > + goto probe_failed; > + } > + } > + } else { > + ethdev =3D rte_eth_dev_attach_secondary(name); > + if (!ethdev) { > + RTE_LOG(ERR, EAL, "secondary process attach failed, > " > + "ethdev doesn't exist"); > + retval =3D -ENODEV; > + goto probe_failed; > + } > + } > + > + ethdev->device =3D device; > + > + if (ethdev_bus_specific_init) { > + retval =3D ethdev_bus_specific_init(ethdev, bus_init_params); > + if (retval) { > + RTE_LOG(ERR, EAL, > + "ethdev bus specific initialisation failed"); > + goto probe_failed; > + } > + } > + > + RTE_FUNC_PTR_OR_ERR_RET(*ethdev_init, -EINVAL); > + retval =3D ethdev_init(ethdev, init_params); > + if (retval) { > + RTE_LOG(ERR, EAL, "ethdev initialisation failed"); > + goto probe_failed; > + } > + > + return retval; > +probe_failed: > + /* free ports private data if primary process */ > + if (rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY) > + rte_free(ethdev->data->dev_private); > + > + rte_eth_dev_release_port(ethdev); > + > + return retval; > +} > + > +int __rte_experimental > +rte_eth_dev_destroy(struct rte_eth_dev *ethdev, > + ethdev_uninit_t ethdev_uninit) > +{ > + int ret; > + > + ethdev =3D rte_eth_dev_allocated(ethdev->data->name); > + if (!ethdev) > + return -ENODEV; > + > + RTE_FUNC_PTR_OR_ERR_RET(*ethdev_uninit, -EINVAL); > + if (ethdev_uninit) { > + ret =3D ethdev_uninit(ethdev); > + if (ret) > + return ret; > + } > + > + if (rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY) > + rte_free(ethdev->data->dev_private); > + > + ethdev->data->dev_private =3D NULL; > + > + return rte_eth_dev_release_port(ethdev); } > + > + > int > rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id, > int epfd, int op, void *data) > diff --git a/lib/librte_ether/rte_ethdev_driver.h > b/lib/librte_ether/rte_ethdev_driver.h > index 45f08c65e..4896cea93 100644 > --- a/lib/librte_ether/rte_ethdev_driver.h > +++ b/lib/librte_ether/rte_ethdev_driver.h > @@ -125,6 +125,63 @@ rte_eth_dma_zone_reserve(const struct > rte_eth_dev *eth_dev, const char *name, > uint16_t queue_id, size_t size, > unsigned align, int socket_id); >=20 > + > +typedef int (*ethdev_init_t)(struct rte_eth_dev *ethdev, void > +*init_params); typedef int (*ethdev_bus_specific_init)(struct rte_eth_de= v > *ethdev, > + void *bus_specific_init_params); > + > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice. > + * > + * PMD helper function for the creation of a new ethdev ports. > + * > + * @param device > + * rte_device handle. > + * @param name > + * port name. > + * @param priv_data_size > + * size of private data required for port. > + * @param bus_specific_init > + * port bus specific initialisation callback function > + * @param bus_init_params > + * port bus specific initialisation parameters > + * @param ethdev_init > + * device specific port initialization callback function > + * @param init_params > + * port initialisation parameters > + * > + * @return > + * Negative errno value on error, 0 on success. > + */ > +int __rte_experimental > +rte_eth_dev_create(struct rte_device *device, const char *name, > + size_t priv_data_size, > + ethdev_bus_specific_init bus_specific_init, void *bus_init_params, > + ethdev_init_t ethdev_init, void *init_params); > + > + > +typedef int (*ethdev_uninit_t)(struct rte_eth_dev *ethdev); > + > +/** > + * @warning > + * @b EXPERIMENTAL: this API may change without prior notice. > + * > + * PMD helper function for cleaing up the resources of a ethdev port on > +it's > + * destruction. > + * > + * @param ethdev > + * ethdev handle of port. > + * @param ethdev > + * device specific port un-initialise callback function > + * > + * @return > + * Negative errno value on error, 0 on success. > + */ > +int __rte_experimental > +rte_eth_dev_destroy(struct rte_eth_dev *ethdev, > + ethdev_uninit_t ethdev_uninit); > + > #ifdef __cplusplus > } > #endif > diff --git a/lib/librte_ether/rte_ethdev_pci.h > b/lib/librte_ether/rte_ethdev_pci.h > index 897ce5b41..8604a0474 100644 > --- a/lib/librte_ether/rte_ethdev_pci.h > +++ b/lib/librte_ether/rte_ethdev_pci.h > @@ -70,6 +70,18 @@ rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, > eth_dev->data->numa_node =3D pci_dev->device.numa_node; } >=20 > +static inline int > +eth_dev_pci_specific_init(struct rte_eth_dev *eth_dev, void *bus_device) > { > + struct rte_pci_device *pci_dev =3D bus_device; > + > + if (!pci_dev) > + return -ENODEV; > + > + rte_eth_copy_pci_info(eth_dev, pci_dev); > + > + return 0; > +} > + > /** > * @internal > * Allocates a new ethdev slot for an ethernet device and returns the po= inter > diff --git a/lib/librte_ether/rte_ethdev_representor.h > b/lib/librte_ether/rte_ethdev_representor.h > new file mode 100644 > index 000000000..cbc1f2855 > --- /dev/null > +++ b/lib/librte_ether/rte_ethdev_representor.h > @@ -0,0 +1,28 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright(c) 2018 Intel Corporation. > + */ > + > + > +#ifndef _RTE_ETHDEV_REPRESENTOR_H_ > +#define _RTE_ETHDEV_REPRESENTOR_H_ > + > +#include > + > +static int > +eth_dev_representor_port_init(struct rte_eth_dev *ethdev, void > +*init_params) { > + struct rte_eth_dev *base_ethdev =3D init_params; > + > + if (!ethdev || !base_ethdev) > + return -ENODEV; > + > + /** representor shares same driver as it's base device */ > + ethdev->device->driver =3D base_ethdev->device->driver; > + > + /** representor inherits the switch id of it's base device */ > + ethdev->data->switch_id =3D base_ethdev->data->switch_id; Why not let the PMD to set it?=20 The PMD knows the specific port is a represntor port and to which switch it= belongs.=20 Doing it on ethdev layer will block us in the future from having more compl= ex model were, for example, there are multiple switch domain for a set of P= F + representors.=20 > + > + return 0; > +} > + > +#endif /* _RTE_ETHDEV_REPRESENTOR_H_ */ > diff --git a/lib/librte_ether/rte_ethdev_version.map > b/lib/librte_ether/rte_ethdev_version.map > index 87f02fb74..48b08bc36 100644 > --- a/lib/librte_ether/rte_ethdev_version.map > +++ b/lib/librte_ether/rte_ethdev_version.map > @@ -230,3 +230,11 @@ EXPERIMENTAL { > rte_mtr_stats_update; >=20 > } DPDK_17.11; > + > +EXPERIMENTAL { > + global: > + > + rte_eth_dev_create; > + rte_eth_dev_destroy; > + > +} DPDK_18.05; > -- > 2.14.3