From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 45B0BA054A for ; Wed, 15 Jun 2022 08:55:15 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3AF7941140; Wed, 15 Jun 2022 08:55:15 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mails.dpdk.org (Postfix) with ESMTP id 4490A40220; Wed, 15 Jun 2022 08:55:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655276112; x=1686812112; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=/1pzMVM8lWJVEdqeYOMd7GivL/mo/nBTbtj1rFnJchw=; b=IeR0eIS5ZmgtJDoSK08HCFJ2PIToB/ORitjFeRQpKH+WEuX+rMsfj82c D3YqEWrfLkqWMdy0iwwxQJDTZF3EGgHVoPR9DD1Rfj8zcO4xfmJt59Xml l1j808Yk67FKUxxMtzY5DcIulUPtsiOlz1nK/tnFaoe3bgYlw3HWKaEg9 EKGN4v4uSlW/7uDKdeWYtlHelhZwTpc+gQDoOwScnQ7DxOUAF1LQ6t63O xWDa+N3lkth+7h0cItRgBNi/BQVOaxP6phzUWlUEDq2h+U5nkT1dUMt4C s1duM5/W7IgBdlWGUBNsVLRPH23t2keziBeC8WQUVXFRzRcVzVEcdMhAi A==; X-IronPort-AV: E=McAfee;i="6400,9594,10378"; a="261888173" X-IronPort-AV: E=Sophos;i="5.91,300,1647327600"; d="scan'208";a="261888173" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2022 23:55:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,300,1647327600"; d="scan'208";a="618330780" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by orsmga001.jf.intel.com with ESMTP; 14 Jun 2022 23:55:10 -0700 Received: from fmsmsx601.amr.corp.intel.com (10.18.126.81) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Tue, 14 Jun 2022 23:55:10 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27 via Frontend Transport; Tue, 14 Jun 2022 23:55:10 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.105) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.27; Tue, 14 Jun 2022 23:55:10 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ehVIDncfk3akOH8EkZ+M3ZvIUDkU8jvljE1n9Pkrfu7HewY7rQXzgphM0ZyufAyWqpEm5opnsyxe045zhRRTx2t2hfL5bbPQ5tnZRWH+3jK65Gnw3SMHsy0e8KuDCW1KzO6pGme0FMZtjyLuS5IhWs6N5rLTlzhqOV+oqhAPvShBVV1Qc8xQfsWy++3FuJNLQp+3YUiv9n4PFzojhGw4bf2ImK00GUQdRdEsfMowliKcZG7qi8BYt7RiHOvWWXBWKu6vUGDrD7jbcpydTovddbxl8m+9js/iybk1yG3G7gToX3h//zR4qpkIaMkG8BPIc8EeaEC5Ga3Uvowgwe+wgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=L9QctcfuV50jJU0gCIXcn13unRiIkqLcrI96YRZ9OCw=; b=IYXitGeNWaL5h/eNrP91Tqqyr1ifhu92H2LiFleSH7YlTRem3DW1gLheyeSIggoqNhlzD1bFnRoBLemP9GqUK10nIJREaY8z0Py+NCsX4PeAa7KF4FnxnJ7ez6E9XFuUNJ1TGyoHpMAtlUDf8HlmTQVzPwehU8g3qceyFZtUCSCTwwtTkV84zV3sgl04ayKyeT0MQSZQqCU4AVhBNZK+FHdd7fH2bqbHqTqs3ktL1B4lDwhRR3As2EjfdtM6Z9dzStI7rQL9dBgnYMZqd8qnYE/IqvG+CL8casI+ol/E9T6m2KfPE1bgAG54bgI4u92NedZvZhBqZ9SQjIjAXEV12w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from DM6PR11MB4252.namprd11.prod.outlook.com (2603:10b6:5:201::26) by BY5PR11MB4273.namprd11.prod.outlook.com (2603:10b6:a03:1c9::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.14; Wed, 15 Jun 2022 06:55:02 +0000 Received: from DM6PR11MB4252.namprd11.prod.outlook.com ([fe80::b9d5:600c:9f13:bc96]) by DM6PR11MB4252.namprd11.prod.outlook.com ([fe80::b9d5:600c:9f13:bc96%7]) with mapi id 15.20.5332.023; Wed, 15 Jun 2022 06:55:02 +0000 From: "Xu, Rosen" To: "Huang, Wei" , "dev@dpdk.org" , "thomas@monjalon.net" , "nipun.gupta@nxp.com" , "hemant.agrawal@nxp.com" CC: "stable@dpdk.org" , "Zhang, Tianfei" , "Zhang, Qi Z" Subject: RE: [PATCH v7 1/5] raw/ifpga: introduce AFU driver framework Thread-Topic: [PATCH v7 1/5] raw/ifpga: introduce AFU driver framework Thread-Index: AQHYe9K7dl8L/fQjhEaNpgXkrMF1t61QEM5w Date: Wed, 15 Jun 2022 06:55:02 +0000 Message-ID: References: <1654742650-7214-1-git-send-email-wei.huang@intel.com> <1654760242-7832-1-git-send-email-wei.huang@intel.com> <1654760242-7832-2-git-send-email-wei.huang@intel.com> In-Reply-To: <1654760242-7832-2-git-send-email-wei.huang@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.6.500.17 dlp-reaction: no-action x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYmRjMDQ5ZDMtYTJiZC00OTM1LTk3MWEtMjYzMThhNjYyMmI0IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiMnRYXC9HU1wvUmgzMWdTakhWSGVyTGxpK1Jld0gwR2JLd3Z2QzdhM1FSWUVqQjdHRXdZRlNqcHd0RnBtMSsyN2QyIn0= x-ctpclassification: CTP_NT authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 56c227dd-7659-4ee8-5b05-08da4e9bf8d9 x-ms-traffictypediagnostic: BY5PR11MB4273:EE_ x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: u1yJT96xoQ18XMe4nCaAEk03vJtwBcc7r967hr6gz4q8NcF/a2c00miwBOcU55j5gxL7KyFjFXaVclyaQoFp57lsrySKGTxxVXax1kXhIzwauSJDK+bxVuvI5GrG/hSzdF1K0hI+TEbYoYMhBeQaPQpeb+z0nwTXu5od6L4IKx+glyxQVZPbhceP3jwZMwZmkgcu6+PPQ8FQdT3tWudoweINgIGf6kwiYNE+F9SPqkBkPdMFcR8w38TKMFIKGcmdVwBCYq7lHZMvAbuWAbB7YUcdjYobOuj9LTe+g+DSwPHUA5Zuhuj461z59RmJ4CcT1IESTqdqMGd0nCtfBTyes1VsVIGejl8l5MKbum0ChJnnD2exW6Jgp6sl6vFCsKBz7oqhEDYyuZorFMPc2Vm8BfJoGqlFmchEEbtisBUmO2wlsWskBjdEjhPLp6oK0Qql3PagJVtmVWoiJtAzVifapFbZ17gPUefMISfTLsl6NKUlTp3dddLGj3KwSMY7Dnjor2/B2CDaNpvkaGQ4/7YzxwPL+TI7gC6BfG+AraPX28oxxHMCgJvH9ieYF7/jaL6DshJmJKhxGzYkgiF7Np65PuIFi4FUU7+dNbatQU1RhFRe4uTpCKnus5rp2I2N4JJEvXCVlw+V+Vtlx42EfX5cBg346eJDEUr3SMXdtY26hjk2MUCh3f5qiAziuBl/nJ2iu7x+Zbtg9qS0jeTvFVOqyQ== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR11MB4252.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(366004)(122000001)(38070700005)(107886003)(186003)(82960400001)(83380400001)(38100700002)(2906002)(55016003)(33656002)(5660300002)(8936002)(52536014)(8676002)(4326008)(316002)(54906003)(66556008)(66946007)(64756008)(30864003)(26005)(53546011)(6506007)(66446008)(76116006)(7696005)(66476007)(71200400001)(9686003)(508600001)(86362001)(110136005); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?oeBOi9B3eyq64PMfm7mhmx/xgvS8dRG2V+MtoSfc4UKCxDvLXEGIxmSrBA8c?= =?us-ascii?Q?LiuxAJkbk/3lPTzS5hyB3RNuz3ZsnEl28qitx1u6iKDcQHBMdmobVGhxAAuG?= =?us-ascii?Q?ac+2FXZKfo4TtmpeESxKRqHGhc/HpOBFKNgeICL1t+wDrR/f1qC37aY7yaoY?= =?us-ascii?Q?d5ts8JlYeK21+zpTN3BPxEhvLwbsP5tCItUtGO6C5iClXkXri3iV3gTRr/lk?= =?us-ascii?Q?P4eU0/urc/th8rtjclZZ6W807rloyax3GPsQ/sRqSl0NUJ6vLiBEeDg+tGni?= =?us-ascii?Q?URx7NSJr210aFxXFMdSAPX9qjtz9c14WDOKlxUjTbD5KBXF0gZ5sR6VwGqSo?= =?us-ascii?Q?I0kcVYkVnunPMzMQok7FRlagDNKsxqBoTUUMqb3l2k1QQJ/LWRZA6GEB9I3/?= =?us-ascii?Q?kx8uu2qgVJkEesMe9poQ36guIb2g2lg7mWGbkOYG2GOIvE6/BHd5H6UrWfFZ?= =?us-ascii?Q?ZYvGD/E17e3S2tDRAMAV4JKy3Od6f7F5JI9NN6Q+TdM5IzuSx4rEh6D7GwdO?= =?us-ascii?Q?fwZsb9awCA4k2/nwCTcyDyqCEDgajL1RyX0PqAz6noL/lbrFClI9GAKlOXqn?= =?us-ascii?Q?ce3ctL/bh7bw/Bb+x9F3PsDSZvC1N0vX/bUwk6BvrieB6AoPuo54jdvmsDxw?= =?us-ascii?Q?v8D11IzQHxczIFipLnLUJ3/fdrQeTSaMAzpq/Quhqi3ul2Gdc9LyZ6ygmnik?= =?us-ascii?Q?GKMLnMl/m90zzJZa8ee8nQ7p0PPtein0tdpGShBiumgish+8KH0OGoIed8D+?= =?us-ascii?Q?9BmQ4f6gqcO2hSR126F6+w2Wa4+pPyo3hbAwvqZze7bkOoFXSZJcvnBxIt8y?= =?us-ascii?Q?gHHLXJW+1P9NPCj5d3Ut4JQZCZX5Fmudwocq0IdRIx2Ls5bKLFzpx/35ZaAw?= =?us-ascii?Q?llQrsaeIMv1KQqpn3J22hoKf+oRvxOQ0MnqIbw/Zn3NlfxUMB3eI3RMCFeg0?= =?us-ascii?Q?LHx25MS/Hgg8i7hLKSb80IBfEpvtbheGX0OlIuchaj4ErAaZcAIeqmnE7Bmp?= =?us-ascii?Q?d4eeTRygOxFazG/CFkqqiCYbMx3PCvYWELoM5h/0Fh7AInLIlUg8F0lPrvDa?= =?us-ascii?Q?ajHivX1YmHsHgiKIP6HcdbWKAMF6TjZlGFONnriXyl2ZxC8LzALiMajVdzmk?= =?us-ascii?Q?GsoOHHs9umETDB0F62WSGY85feW7uQcGDIxTW7Y/BdXguTftUt7Y1eqqqidP?= =?us-ascii?Q?muskHvbnMD9ryzVXjQC0fBHz8BjGAgPhmj4aBKIPW1n5c+Yv205kzcJX8GcI?= =?us-ascii?Q?wHsLQkurxrcRBzV5hbxnTH0OfbXG6aUYEczJb0P5+/3wUJKsG9BKMfTob/c1?= =?us-ascii?Q?SQ7JyO2JGjEFPtvxZt8nc4TAHLxpjE1X6CYsjqrnB7q6VEafE4yz0NSeQUFS?= =?us-ascii?Q?YeFoQlP7uZk5/9Ynw2jzuXNX20RJ9R31psDm1t9aTFl3e3oxcBnqNe2vvC3n?= =?us-ascii?Q?4SKXoisoabfFV2K2IU0oy5lye/82RucjWm5K1h9zeD/gaKQcKzV8xZoacl/1?= =?us-ascii?Q?LF6Zokck9aRMCvfTvP4DsBSy0yXe6AXNEiZ6TW+SqIZqpc/J3qzL7LmbsEyY?= =?us-ascii?Q?SejVonwyBzeFchq1Po8lWATWQR+q6iIgIpY/W1rmzE+B3B29y38GILv7NFcn?= =?us-ascii?Q?YOCe9Kf9PsuEHa2DxzNtXJNL03qi6Qjjn/HywoJ31PDsnBeU0CTbXrXe1lVC?= =?us-ascii?Q?wMiMkv7+vjI8pWVaBeSnSP3uGZB0eqBl1MLoEtgbPbVE8i/K448NJbDvRZ8t?= =?us-ascii?Q?mIFZR/8X0Q=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4252.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 56c227dd-7659-4ee8-5b05-08da4e9bf8d9 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Jun 2022 06:55:02.7769 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: nRNias3p7Nt2+7SQRjOkzst/apjIIOsgZ/TndFkfs77KaU3pmIElQhKm1HjY7uZAb0UKlxLlscXPcxhigz424g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR11MB4273 X-OriginatorOrg: intel.com X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi Wei, Some comments. Thanks, Rosen > -----Original Message----- > From: Huang, Wei > Sent: Thursday, June 09, 2022 15:37 > To: dev@dpdk.org; thomas@monjalon.net; nipun.gupta@nxp.com; > hemant.agrawal@nxp.com > Cc: stable@dpdk.org; Xu, Rosen ; Zhang, Tianfei > ; Zhang, Qi Z ; Huang, Wei > > Subject: [PATCH v7 1/5] raw/ifpga: introduce AFU driver framework >=20 > AFU (Acceleration Function Unit) is part of FPGA and enumerated by ifpga > driver. > This driver implements common AFU device interfaces and exposes them to > application as standard raw device APIs. > Normally application can operate specified AFU as below, 1. call > rte_rawdev_pmd_get_named_dev() to find AFU device. > 2. call rte_rawdev_configure() to initialize AFU device. > 3. call rte_rawdev_selftest() to test AFU device. >=20 > Signed-off-by: Wei Huang > --- > v2: fix typo > --- > v3: fix build error in FreeBSD13-64, UB2004-32 and UB2204-32 > --- > v4: fix coding style issue and build error in FreeBSD13-64 > --- > v5: split patch into several patches > --- > v6: move source files to ifpga and rename, use spinlock > --- > drivers/raw/ifpga/afu_pmd_core.c | 453 > +++++++++++++++++++++++++++++++++++++++ > drivers/raw/ifpga/afu_pmd_core.h | 76 +++++++ > drivers/raw/ifpga/meson.build | 2 +- > 3 files changed, 530 insertions(+), 1 deletion(-) create mode 100644 > drivers/raw/ifpga/afu_pmd_core.c create mode 100644 > drivers/raw/ifpga/afu_pmd_core.h >=20 > diff --git a/drivers/raw/ifpga/afu_pmd_core.c > b/drivers/raw/ifpga/afu_pmd_core.c > new file mode 100644 > index 0000000..a24b517 > --- /dev/null > +++ b/drivers/raw/ifpga/afu_pmd_core.c > @@ -0,0 +1,453 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright 2022 Intel Corporation > + * > + * AFU is Acceleration Function Unit in FPGA, it is enumerated by ifpga = pmd. > + * Suppose AFU is found in FPGA at PCI address 31:00.0, then you can > +create > + * and test a AFU device by following steps in application. > + * 1. rte_vdev_init("ifpga_rawdev_cfg0", "ifpga=3D31:00.0,port=3D0") > + * 2. rawdev =3D rte_rawdev_pmd_get_named_dev("afu_0|31:00.0") > + * 3. rte_rawdev_configure(rawdev->dev_id, &cfg, sizeof(cfg)) > + * 4. rte_rawdev_selftest(rawdev->dev_id) > + * 5. rte_vdev_uninit("ifpga_rawdev_cfg0") > + * > + * AFU device name format used in rte_rawdev_pmd_get_named_dev is > + * "afu_[port]|[BDF]". Please refer to OPAE documentation for the > +meaning of > + * port. Each AFU device has specific configuration data, they are > +defined > + * in rte_pmd_afu.h. > + * > + */ > + Could you split these notes? General speaking we just announce license in h= ead of source file. > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > + > +#include "afu_pmd_core.h" > + > +static struct rte_afu_uuid > afu_pmd_uuid_map[AFU_RAWDEV_MAX_DRVS+1]; > +TAILQ_HEAD(afu_drv_list, afu_rawdev_drv); static struct afu_drv_list > +afu_pmd_list =3D TAILQ_HEAD_INITIALIZER(afu_pmd_list); > + > +static inline int afu_rawdev_trylock(struct afu_rawdev *dev) { > + if (!dev || !dev->sd) > + return 0; > + > + return rte_spinlock_trylock(&dev->sd->lock); > +} > + > +static inline void afu_rawdev_unlock(struct afu_rawdev *dev) { > + if (!dev || !dev->sd) > + return; > + > + rte_spinlock_unlock(&dev->sd->lock); > +} > + > +static int afu_rawdev_configure(const struct rte_rawdev *rawdev, > + rte_rawdev_obj_t config, size_t config_size) { > + struct afu_rawdev *dev =3D NULL; > + int ret =3D 0; > + > + IFPGA_RAWDEV_PMD_FUNC_TRACE(); > + > + dev =3D afu_rawdev_get_priv(rawdev); > + if (!dev) > + return -ENODEV; > + > + if (dev->ops && dev->ops->config) > + ret =3D (*dev->ops->config)(dev, config, config_size); > + > + return ret; > +} > + > +static int afu_rawdev_start(struct rte_rawdev *rawdev) { > + struct afu_rawdev *dev =3D NULL; > + int ret =3D 0; > + > + IFPGA_RAWDEV_PMD_FUNC_TRACE(); > + > + dev =3D afu_rawdev_get_priv(rawdev); > + if (!dev) > + return -ENODEV; > + > + ret =3D afu_rawdev_trylock(dev); > + if (!ret) { > + IFPGA_RAWDEV_PMD_WARN("AFU is busy, please start it > later"); > + return ret; > + } > + > + if (dev->ops && dev->ops->start) > + ret =3D (*dev->ops->start)(dev); > + > + afu_rawdev_unlock(dev); > + > + return ret; > +} > + > +static void afu_rawdev_stop(struct rte_rawdev *rawdev) { > + struct afu_rawdev *dev =3D NULL; > + int ret =3D 0; > + > + IFPGA_RAWDEV_PMD_FUNC_TRACE(); > + > + dev =3D afu_rawdev_get_priv(rawdev); > + if (!dev) > + return; > + > + ret =3D afu_rawdev_trylock(dev); > + if (!ret) { > + IFPGA_RAWDEV_PMD_WARN("AFU is busy, please stop it > later"); > + return; > + } > + > + if (dev->ops && dev->ops->stop) > + ret =3D (*dev->ops->stop)(dev); > + > + afu_rawdev_unlock(dev); > +} > + > +static int afu_rawdev_close(struct rte_rawdev *rawdev) { > + struct afu_rawdev *dev =3D NULL; > + int ret =3D 0; > + > + IFPGA_RAWDEV_PMD_FUNC_TRACE(); > + > + dev =3D afu_rawdev_get_priv(rawdev); > + if (!dev) > + return -ENODEV; > + > + if (dev->ops && dev->ops->close) > + ret =3D (*dev->ops->close)(dev); > + > + return ret; > +} > + > +static int afu_rawdev_reset(struct rte_rawdev *rawdev) { > + struct afu_rawdev *dev =3D NULL; > + int ret =3D 0; > + > + IFPGA_RAWDEV_PMD_FUNC_TRACE(); > + > + dev =3D afu_rawdev_get_priv(rawdev); > + if (!dev) > + return -ENODEV; > + > + ret =3D afu_rawdev_trylock(dev); > + if (!ret) { > + IFPGA_RAWDEV_PMD_WARN("AFU is busy, please reset it > later"); > + return ret; > + } > + > + if (dev->ops && dev->ops->reset) > + ret =3D (*dev->ops->reset)(dev); > + > + afu_rawdev_unlock(dev); > + > + return ret; > +} > + > +static int afu_rawdev_selftest(uint16_t dev_id) { > + struct afu_rawdev *dev =3D NULL; > + int ret =3D 0; > + > + IFPGA_RAWDEV_PMD_FUNC_TRACE(); > + > + if (!rte_rawdev_pmd_is_valid_dev(dev_id)) > + return -ENODEV; > + > + dev =3D afu_rawdev_get_priv(&rte_rawdevs[dev_id]); > + if (!dev) > + return -ENOENT; > + > + ret =3D afu_rawdev_trylock(dev); > + if (!ret) { > + IFPGA_RAWDEV_PMD_WARN("AFU is busy, please test it > later"); > + return ret; > + } > + > + if (dev->ops && dev->ops->test) > + ret =3D (*dev->ops->test)(dev); > + > + afu_rawdev_unlock(dev); > + > + return ret; > +} > + > +static int afu_rawdev_dump(struct rte_rawdev *rawdev, FILE *f) { > + struct afu_rawdev *dev =3D NULL; > + int ret =3D 0; > + > + IFPGA_RAWDEV_PMD_FUNC_TRACE(); > + > + dev =3D afu_rawdev_get_priv(rawdev); > + if (!dev) > + return -ENODEV; > + > + if (dev->ops && dev->ops->dump) > + ret =3D (*dev->ops->dump)(dev, f); > + > + return ret; > +} > + > +static const struct rte_rawdev_ops afu_rawdev_ops =3D { > + .dev_info_get =3D NULL, > + .dev_configure =3D afu_rawdev_configure, > + .dev_start =3D afu_rawdev_start, > + .dev_stop =3D afu_rawdev_stop, > + .dev_close =3D afu_rawdev_close, > + .dev_reset =3D afu_rawdev_reset, > + > + .queue_def_conf =3D NULL, > + .queue_setup =3D NULL, > + .queue_release =3D NULL, > + .queue_count =3D NULL, > + > + .attr_get =3D NULL, > + .attr_set =3D NULL, > + > + .enqueue_bufs =3D NULL, > + .dequeue_bufs =3D NULL, > + > + .dump =3D afu_rawdev_dump, > + > + .xstats_get =3D NULL, > + .xstats_get_names =3D NULL, > + .xstats_get_by_name =3D NULL, > + .xstats_reset =3D NULL, > + > + .firmware_status_get =3D NULL, > + .firmware_version_get =3D NULL, > + .firmware_load =3D NULL, > + .firmware_unload =3D NULL, > + > + .dev_selftest =3D afu_rawdev_selftest, > +}; > + > +static int afu_shared_data_alloc(const char *name, > + struct afu_shared_data **data, int socket_id) { > + const struct rte_memzone *mz; > + char mz_name[RTE_MEMZONE_NAMESIZE]; > + struct afu_shared_data *sd =3D NULL; > + int init_mz =3D 0; > + > + if (!name || !data) > + return -EINVAL; > + > + /* name format is afu_?|??:??.? which is unique */ > + snprintf(mz_name, sizeof(mz_name), "%s", name); > + > + mz =3D rte_memzone_lookup(mz_name); > + if (!mz) { > + mz =3D rte_memzone_reserve(mz_name, sizeof(struct > afu_shared_data), > + socket_id, 0); > + init_mz =3D 1; > + } > + > + if (!mz) { > + IFPGA_RAWDEV_PMD_ERR("Allocate memory zone %s > failed!", > + mz_name); > + return -ENOMEM; > + } > + > + sd =3D (struct afu_shared_data *)mz->addr; > + > + if (init_mz) /* initialize memory zone on the first time */ > + rte_spinlock_init(&sd->lock); > + > + *data =3D sd; > + > + return 0; > +} > + > +static int afu_rawdev_name_get(struct rte_afu_device *afu_dev, char > *name, > + size_t size) > +{ > + int n =3D 0; > + > + if (!afu_dev || !name || !size) > + return -EINVAL; > + > + n =3D snprintf(name, size, "afu_%s", afu_dev->device.name); > + if (n >=3D (int)size) { > + IFPGA_RAWDEV_PMD_ERR("Name of AFU device is too > long!"); > + return -ENAMETOOLONG; > + } > + > + return 0; > +} > + > +static struct afu_ops *afu_ops_get(struct rte_afu_uuid *afu_id) { > + struct afu_rawdev_drv *drv =3D NULL; > + > + if (!afu_id) > + return NULL; > + > + TAILQ_FOREACH(drv, &afu_pmd_list, next) { > + if ((drv->uuid.uuid_low =3D=3D afu_id->uuid_low) && > + (drv->uuid.uuid_high =3D=3D afu_id->uuid_high)) > + break; > + } > + > + return drv ? drv->ops : NULL; > +} > + > +static int afu_rawdev_create(struct rte_afu_device *afu_dev, int > +socket_id) { > + struct rte_rawdev *rawdev =3D NULL; > + struct afu_rawdev *dev =3D NULL; > + char name[RTE_RAWDEV_NAME_MAX_LEN] =3D {0}; > + int ret =3D 0; > + > + if (!afu_dev) > + return -EINVAL; > + > + ret =3D afu_rawdev_name_get(afu_dev, name, sizeof(name)); > + if (ret) > + return ret; > + > + IFPGA_RAWDEV_PMD_INFO("Create raw device %s on NUMA > node %d", > + name, socket_id); > + > + /* Allocate device structure */ > + rawdev =3D rte_rawdev_pmd_allocate(name, sizeof(struct > afu_rawdev), > + socket_id); > + if (!rawdev) { > + IFPGA_RAWDEV_PMD_ERR("Unable to allocate raw device"); > + return -ENOMEM; > + } > + > + rawdev->dev_ops =3D &afu_rawdev_ops; > + rawdev->device =3D &afu_dev->device; > + rawdev->driver_name =3D afu_dev->driver->driver.name; > + > + dev =3D afu_rawdev_get_priv(rawdev); > + if (!dev) > + goto cleanup; > + > + dev->rawdev =3D rawdev; > + dev->port =3D afu_dev->id.port; > + dev->addr =3D afu_dev->mem_resource[0].addr; > + dev->ops =3D afu_ops_get(&afu_dev->id.uuid); > + if (dev->ops =3D=3D NULL) { > + IFPGA_RAWDEV_PMD_ERR("Unsupported AFU device"); > + goto cleanup; > + } > + > + if (dev->ops->init) { > + ret =3D (*dev->ops->init)(dev); > + if (ret) { > + IFPGA_RAWDEV_PMD_ERR("Failed to init %s", > name); > + goto cleanup; > + } > + } > + > + ret =3D afu_shared_data_alloc(name, &dev->sd, socket_id); > + if (ret) > + goto cleanup; > + > + return ret; > + > +cleanup: > + rte_rawdev_pmd_release(rawdev); > + return ret; > +} > + > +static int afu_rawdev_destroy(struct rte_afu_device *afu_dev) { > + struct rte_rawdev *rawdev =3D NULL; > + char name[RTE_RAWDEV_NAME_MAX_LEN] =3D {0}; > + int ret =3D 0; > + > + if (!afu_dev) > + return -EINVAL; > + > + ret =3D afu_rawdev_name_get(afu_dev, name, sizeof(name)); > + if (ret) > + return ret; > + > + IFPGA_RAWDEV_PMD_INFO("Destroy raw device %s", name); > + > + rawdev =3D rte_rawdev_pmd_get_named_dev(name); > + if (!rawdev) { > + IFPGA_RAWDEV_PMD_ERR("Raw device %s not found", > name); > + return -EINVAL; > + } > + > + /* rte_rawdev_close is called by pmd_release */ > + ret =3D rte_rawdev_pmd_release(rawdev); > + if (ret) > + IFPGA_RAWDEV_PMD_DEBUG("Device cleanup failed"); > + > + return 0; > +} > + > +static int afu_rawdev_probe(struct rte_afu_device *afu_dev) { > + IFPGA_RAWDEV_PMD_FUNC_TRACE(); > + return afu_rawdev_create(afu_dev, rte_socket_id()); } > + Function format issue. > +static int afu_rawdev_remove(struct rte_afu_device *afu_dev) { > + IFPGA_RAWDEV_PMD_FUNC_TRACE(); > + return afu_rawdev_destroy(afu_dev); > +} > + > +static struct rte_afu_driver afu_pmd =3D { > + .id_table =3D afu_pmd_uuid_map, > + .probe =3D afu_rawdev_probe, > + .remove =3D afu_rawdev_remove > +}; > + > +RTE_PMD_REGISTER_AFU(afu_rawdev_driver, afu_pmd); > + > +static void update_uuid_map(void) > +{ > + int i =3D 0; > + struct rte_afu_uuid *afu_id =3D afu_pmd_uuid_map; > + struct afu_rawdev_drv *drv; > + > + TAILQ_FOREACH(drv, &afu_pmd_list, next) { > + if (i++ < AFU_RAWDEV_MAX_DRVS) { > + afu_id->uuid_low =3D drv->uuid.uuid_low; > + afu_id->uuid_high =3D drv->uuid.uuid_high; > + afu_id++; > + } > + } > + if (i <=3D AFU_RAWDEV_MAX_DRVS) { > + afu_id->uuid_low =3D 0; > + afu_id->uuid_high =3D 0; > + } > +} > + > +void afu_pmd_register(struct afu_rawdev_drv *driver) { > + TAILQ_INSERT_TAIL(&afu_pmd_list, driver, next); > + update_uuid_map(); > +} > + > +void afu_pmd_unregister(struct afu_rawdev_drv *driver) { > + TAILQ_REMOVE(&afu_pmd_list, driver, next); > + update_uuid_map(); > +} > diff --git a/drivers/raw/ifpga/afu_pmd_core.h > b/drivers/raw/ifpga/afu_pmd_core.h > new file mode 100644 > index 0000000..4fad2c7 > --- /dev/null > +++ b/drivers/raw/ifpga/afu_pmd_core.h > @@ -0,0 +1,76 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright 2022 Intel Corporation > + */ > + > +#ifndef __AFU_PMD_CORE_H__ > +#define __AFU_PMD_CORE_H__ > + > +#ifdef __cplusplus > +extern "C" { > +#endif > + > +#include > +#include > +#include > + > +#include > +#include > +#include > + > +#include "ifpga_rawdev.h" > + > +#define AFU_RAWDEV_MAX_DRVS 32 > + > +struct afu_rawdev; > + > +struct afu_ops { > + int (*init)(struct afu_rawdev *dev); > + int (*config)(struct afu_rawdev *dev, void *config, > + size_t config_size); > + int (*start)(struct afu_rawdev *dev); > + int (*stop)(struct afu_rawdev *dev); > + int (*test)(struct afu_rawdev *dev); > + int (*close)(struct afu_rawdev *dev); > + int (*reset)(struct afu_rawdev *dev); > + int (*dump)(struct afu_rawdev *dev, FILE *f); }; > + > +struct afu_shared_data { > + rte_spinlock_t lock; /* lock for multi-process access */ }; > + > +struct afu_rawdev_drv { > + TAILQ_ENTRY(afu_rawdev_drv) next; > + struct rte_afu_uuid uuid; > + struct afu_ops *ops; > +}; > + > +struct afu_rawdev { > + struct rte_rawdev *rawdev; /* point to parent raw device */ > + struct afu_shared_data *sd; /* shared data for multi-process */ > + struct afu_ops *ops; /* device operation functions */ > + int port; /* index of port the AFU attached */ > + void *addr; /* base address of AFU registers */ > + void *priv; /* private driver data */ }; > + > +static inline struct afu_rawdev * > +afu_rawdev_get_priv(const struct rte_rawdev *rawdev) { > + return rawdev ? (struct afu_rawdev *)rawdev->dev_private : NULL; } > + > +void afu_pmd_register(struct afu_rawdev_drv *driver); void > +afu_pmd_unregister(struct afu_rawdev_drv *driver); > + > +#define AFU_PMD_REGISTER(drv)\ > +RTE_INIT(afupmdinitfunc_ ##drv)\ > +{\ > + afu_pmd_register(&drv);\ > +} > + > +#ifdef __cplusplus > +} > +#endif > + > +#endif /* __AFU_PMD_CORE_H__ */ > diff --git a/drivers/raw/ifpga/meson.build b/drivers/raw/ifpga/meson.buil= d > index aeccc17..d9a6f29 100644 > --- a/drivers/raw/ifpga/meson.build > +++ b/drivers/raw/ifpga/meson.build > @@ -13,7 +13,7 @@ objs =3D [base_objs] > deps +=3D ['ethdev', 'rawdev', 'pci', 'bus_pci', 'kvargs', > 'bus_vdev', 'bus_ifpga', 'net', 'net_i40e', 'net_ipn3ke'] >=20 > -sources =3D files('ifpga_rawdev.c', 'rte_pmd_ifpga.c') > +sources =3D files('ifpga_rawdev.c', 'rte_pmd_ifpga.c', 'afu_pmd_core.c') >=20 > includes +=3D include_directories('base') includes +=3D > include_directories('../../net/ipn3ke') > -- > 1.8.3.1 Reviewed-by: Rosen Xu