From patchwork Tue Jul 25 21:40:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brett Creeley X-Patchwork-Id: 13327080 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52613275DB for ; Tue, 25 Jul 2023 21:41:25 +0000 (UTC) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2063.outbound.protection.outlook.com [40.107.223.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B95391FDD; Tue, 25 Jul 2023 14:41:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MbZmnEFyZmX0wFUhVVvf5ZInuFMBm3JbbADOnmH2hUaD+ToyeS8p8xrEv74eeJHhxEVLwLaDSgyw+qQCL4zRQ9nDfvEkw+pIAnmCn2HflQmJqk4p0B9klfMy22TlwzDBYokwQuW+CHXckGxiq2iXJHV/p6bm2u88rnlqy1laYEgqJSzxvtTRR2GRuT/rAPPFUu6S+e3YoQyQo0yaf9j2a/SkKiUxxp74st0u5GItCvSU3l3g91Q+tc7cSVKzTBSZCJeLkevgUyOdGscaWqEpGj3UHDgH9IHDtfZGP0nbDMhL1HPqVCRG4fj+j2p2pMQ/AIVDkhprtzZY80WBqLg0EA== 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=AJXJRJK4Zxisb4vrqw7qX8Nd9M6nxWLi3p7PVi2oaeQ=; b=kDzeKM+eWYwjouDYaTFio5CrAXaS1Q9KczgUjU0mCZgppBKd7ijxigTCQ3jqOoKRMaGz9zCNMRsOERqTxc24DHGloBGLvrJx4py108impcmcbsipJr68AGylfd1cc4gxJAi2/9sv5QhQoD+P1TNDevQmGmIwD8Pvu5iGl/oh+DojHakmVPIFOQcDLDNg06iAFr/Lbex6M0VQXBJ8ocTqBpZH/hr6UDpbAINeAvUN0LPO8f5GEW4+anFGdgfjjlkuOm30kVQjMzYC8WdYMjnDoC9lXLl8uLaYvHZY19qqbxDucsz7n3pOTAEepzzj1yRTYFeF7CJhJrjEg2ZUg6i4Mg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AJXJRJK4Zxisb4vrqw7qX8Nd9M6nxWLi3p7PVi2oaeQ=; b=v8TYC0nxMmfUz5XavL9lTNifvii70b6vRFTG4UqieuR+NX8CEmmJN+gSFKpLRH5hA5EUYYPlsJ0hN0jM4wXI/e81ETijjP1KyQxe8K7zTB7H1F4qADKxEu5VhBsudByaYvurZJgJ4oDta9Hf1ynnYu3j5vaVYRw1cbyVVKr2ZiI= Received: from BN9PR03CA0800.namprd03.prod.outlook.com (2603:10b6:408:13f::25) by IA1PR12MB8540.namprd12.prod.outlook.com (2603:10b6:208:454::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Tue, 25 Jul 2023 21:41:21 +0000 Received: from BN8NAM11FT046.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13f:cafe::7b) by BN9PR03CA0800.outlook.office365.com (2603:10b6:408:13f::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33 via Frontend Transport; Tue, 25 Jul 2023 21:41:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT046.mail.protection.outlook.com (10.13.177.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6631.22 via Frontend Transport; Tue, 25 Jul 2023 21:41:21 +0000 Received: from driver-dev1.pensando.io (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 25 Jul 2023 16:40:40 -0500 From: Brett Creeley To: , , , , , , CC: , , Subject: [PATCH v13 vfio 2/7] vfio/pds: Initial support for pds VFIO driver Date: Tue, 25 Jul 2023 14:40:20 -0700 Message-ID: <20230725214025.9288-3-brett.creeley@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230725214025.9288-1-brett.creeley@amd.com> References: <20230725214025.9288-1-brett.creeley@amd.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT046:EE_|IA1PR12MB8540:EE_ X-MS-Office365-Filtering-Correlation-Id: 24e35d6c-c39b-433f-5c97-08db8d57e32b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: E3JqKkaIQDoogtJHyrpDGtboKqXnb2GFKOqe8SsejjGc7zst849+l1tRViSWyStjsdAKpyHlahGRoz9e0fIn8FC/K0O6Ruwy54E/9i6M0JcJe3kI0gsTGz2fBlP8srpVwnBVnx180/AcHzAXb1xFqj5H4s+58Ve4uVlp8PIEp09WD7+Wl+yv5WZkiAY4/nrM+wgiaHc7Ns7aFJwEov1xyWWiA33D6tjivRO8lTqemB2+UMVeUZH55ccDh8UvgjPcHH4f0ODf4Hjy/q/Riv2D7fUw/JMd4CJAGePHKnz78zMF7aY4Nm106XQZSf6S9NcSPYDD522Q0WBhoBaIEOd6GqORxbWvIjPlImNf963P7DLPjq5SUu3tS0+tHfnsXEJXIeRZgKJySqKOtZ+oIUpj1a/y91jFzGR9WytdpFFcdjLzEM5cJY6WsvfcrxHbjGgwejLNrI9Fs1HEQzhFUTbX450h2VWeu+14kFhl4mWwzZAEsgBqvrUGcTzcT8NWFgbAtDgzDSlxF+SOnpcnuro+EVts0xPdrponp6dtFyCQRCuGLdIWNjWM1ANuPy8UeZ9mpkKAwFuK5uzL+B8ZL6X+CNCKII8Z1+ZE5TNsIRMKYl5Q9USgSUKfgnBwER7IdvxxIxZySbO9dks7RzsFHX7cQ+Mu0nXzUNHEenp6LSyNnMTXsiNcYgy1Ye27HLgCJ3nWA+0T5MTJdIr+p9ywOU1mpv+JptQxMK7yl2FUIvb9xBG/INK2NuTKLW8JSydeQJvx64s457SIH2BKMQPG6lE/HQ== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(376002)(136003)(346002)(396003)(39860400002)(451199021)(82310400008)(36840700001)(40470700004)(46966006)(40460700003)(6666004)(4326008)(316002)(70206006)(110136005)(478600001)(81166007)(356005)(82740400003)(70586007)(83380400001)(426003)(36860700001)(54906003)(16526019)(186003)(26005)(1076003)(336012)(2616005)(47076005)(36756003)(40480700001)(2906002)(8676002)(41300700001)(8936002)(44832011)(5660300002)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Jul 2023 21:41:21.5529 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 24e35d6c-c39b-433f-5c97-08db8d57e32b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT046.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8540 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net This is the initial framework for the new pds-vfio-pci device driver. This does the very basics of registering the PDS PCI device and configuring it as a VFIO PCI device. With this change, the VF device can be bound to the pds-vfio-pci driver on the host and presented to the VM as an ethernet VF. Signed-off-by: Brett Creeley Signed-off-by: Shannon Nelson --- drivers/vfio/pci/Makefile | 2 + drivers/vfio/pci/pds/Makefile | 8 ++++ drivers/vfio/pci/pds/pci_drv.c | 68 ++++++++++++++++++++++++++++++ drivers/vfio/pci/pds/vfio_dev.c | 75 +++++++++++++++++++++++++++++++++ drivers/vfio/pci/pds/vfio_dev.h | 19 +++++++++ 5 files changed, 172 insertions(+) create mode 100644 drivers/vfio/pci/pds/Makefile create mode 100644 drivers/vfio/pci/pds/pci_drv.c create mode 100644 drivers/vfio/pci/pds/vfio_dev.c create mode 100644 drivers/vfio/pci/pds/vfio_dev.h diff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile index 24c524224da5..45167be462d8 100644 --- a/drivers/vfio/pci/Makefile +++ b/drivers/vfio/pci/Makefile @@ -11,3 +11,5 @@ obj-$(CONFIG_VFIO_PCI) += vfio-pci.o obj-$(CONFIG_MLX5_VFIO_PCI) += mlx5/ obj-$(CONFIG_HISI_ACC_VFIO_PCI) += hisilicon/ + +obj-$(CONFIG_PDS_VFIO_PCI) += pds/ diff --git a/drivers/vfio/pci/pds/Makefile b/drivers/vfio/pci/pds/Makefile new file mode 100644 index 000000000000..e5e53a6d86d1 --- /dev/null +++ b/drivers/vfio/pci/pds/Makefile @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2023 Advanced Micro Devices, Inc. + +obj-$(CONFIG_PDS_VFIO_PCI) += pds-vfio-pci.o + +pds-vfio-pci-y := \ + pci_drv.o \ + vfio_dev.o diff --git a/drivers/vfio/pci/pds/pci_drv.c b/drivers/vfio/pci/pds/pci_drv.c new file mode 100644 index 000000000000..4670ddda603a --- /dev/null +++ b/drivers/vfio/pci/pds/pci_drv.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2023 Advanced Micro Devices, Inc. */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include + +#include + +#include "vfio_dev.h" + +#define PDS_VFIO_DRV_DESCRIPTION "AMD/Pensando VFIO Device Driver" +#define PCI_VENDOR_ID_PENSANDO 0x1dd8 + +static int pds_vfio_pci_probe(struct pci_dev *pdev, + const struct pci_device_id *id) +{ + struct pds_vfio_pci_device *pds_vfio; + int err; + + pds_vfio = vfio_alloc_device(pds_vfio_pci_device, vfio_coredev.vdev, + &pdev->dev, pds_vfio_ops_info()); + if (IS_ERR(pds_vfio)) + return PTR_ERR(pds_vfio); + + dev_set_drvdata(&pdev->dev, &pds_vfio->vfio_coredev); + + err = vfio_pci_core_register_device(&pds_vfio->vfio_coredev); + if (err) + goto out_put_vdev; + + return 0; + +out_put_vdev: + vfio_put_device(&pds_vfio->vfio_coredev.vdev); + return err; +} + +static void pds_vfio_pci_remove(struct pci_dev *pdev) +{ + struct pds_vfio_pci_device *pds_vfio = pds_vfio_pci_drvdata(pdev); + + vfio_pci_core_unregister_device(&pds_vfio->vfio_coredev); + vfio_put_device(&pds_vfio->vfio_coredev.vdev); +} + +static const struct pci_device_id pds_vfio_pci_table[] = { + { PCI_DRIVER_OVERRIDE_DEVICE_VFIO(PCI_VENDOR_ID_PENSANDO, 0x1003) }, /* Ethernet VF */ + { 0, } +}; +MODULE_DEVICE_TABLE(pci, pds_vfio_pci_table); + +static struct pci_driver pds_vfio_pci_driver = { + .name = KBUILD_MODNAME, + .id_table = pds_vfio_pci_table, + .probe = pds_vfio_pci_probe, + .remove = pds_vfio_pci_remove, + .driver_managed_dma = true, +}; + +module_pci_driver(pds_vfio_pci_driver); + +MODULE_DESCRIPTION(PDS_VFIO_DRV_DESCRIPTION); +MODULE_AUTHOR("Brett Creeley "); +MODULE_LICENSE("GPL"); diff --git a/drivers/vfio/pci/pds/vfio_dev.c b/drivers/vfio/pci/pds/vfio_dev.c new file mode 100644 index 000000000000..6d7ff1e07373 --- /dev/null +++ b/drivers/vfio/pci/pds/vfio_dev.c @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright(c) 2023 Advanced Micro Devices, Inc. */ + +#include +#include + +#include "vfio_dev.h" + +struct pds_vfio_pci_device *pds_vfio_pci_drvdata(struct pci_dev *pdev) +{ + struct vfio_pci_core_device *core_device = dev_get_drvdata(&pdev->dev); + + return container_of(core_device, struct pds_vfio_pci_device, + vfio_coredev); +} + +static int pds_vfio_init_device(struct vfio_device *vdev) +{ + struct pds_vfio_pci_device *pds_vfio = + container_of(vdev, struct pds_vfio_pci_device, + vfio_coredev.vdev); + struct pci_dev *pdev = to_pci_dev(vdev->dev); + int err, vf_id; + + vf_id = pci_iov_vf_id(pdev); + if (vf_id < 0) + return vf_id; + + err = vfio_pci_core_init_dev(vdev); + if (err) + return err; + + pds_vfio->vf_id = vf_id; + + return 0; +} + +static int pds_vfio_open_device(struct vfio_device *vdev) +{ + struct pds_vfio_pci_device *pds_vfio = + container_of(vdev, struct pds_vfio_pci_device, + vfio_coredev.vdev); + int err; + + err = vfio_pci_core_enable(&pds_vfio->vfio_coredev); + if (err) + return err; + + vfio_pci_core_finish_enable(&pds_vfio->vfio_coredev); + + return 0; +} + +static const struct vfio_device_ops pds_vfio_ops = { + .name = "pds-vfio", + .init = pds_vfio_init_device, + .release = vfio_pci_core_release_dev, + .open_device = pds_vfio_open_device, + .close_device = vfio_pci_core_close_device, + .ioctl = vfio_pci_core_ioctl, + .device_feature = vfio_pci_core_ioctl_feature, + .read = vfio_pci_core_read, + .write = vfio_pci_core_write, + .mmap = vfio_pci_core_mmap, + .request = vfio_pci_core_request, + .match = vfio_pci_core_match, + .bind_iommufd = vfio_iommufd_physical_bind, + .unbind_iommufd = vfio_iommufd_physical_unbind, + .attach_ioas = vfio_iommufd_physical_attach_ioas, +}; + +const struct vfio_device_ops *pds_vfio_ops_info(void) +{ + return &pds_vfio_ops; +} diff --git a/drivers/vfio/pci/pds/vfio_dev.h b/drivers/vfio/pci/pds/vfio_dev.h new file mode 100644 index 000000000000..a4d4b65778d1 --- /dev/null +++ b/drivers/vfio/pci/pds/vfio_dev.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright(c) 2023 Advanced Micro Devices, Inc. */ + +#ifndef _VFIO_DEV_H_ +#define _VFIO_DEV_H_ + +#include +#include + +struct pds_vfio_pci_device { + struct vfio_pci_core_device vfio_coredev; + + int vf_id; +}; + +const struct vfio_device_ops *pds_vfio_ops_info(void); +struct pds_vfio_pci_device *pds_vfio_pci_drvdata(struct pci_dev *pdev); + +#endif /* _VFIO_DEV_H_ */