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 2285142C3E; Tue, 6 Jun 2023 12:03:43 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1500F42D35; Tue, 6 Jun 2023 12:03:31 +0200 (CEST) Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2066.outbound.protection.outlook.com [40.107.212.66]) by mails.dpdk.org (Postfix) with ESMTP id 3763642D31 for ; Tue, 6 Jun 2023 12:03:29 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O4yc3fJHdrcYWwApzDsjs6oGP1LjWU8GnxXNw3BnTGNeKiltyVUka1+AdrN8/SenjakiqMNBf0rNs5uD/AuIpklt9EOjmsKP+u3w3h0bVFJ0RzUIg0CQw87ARWiQbllx67jesQUD+1AKnQtZ+qM2HUXlLZH2Ey9zcC0hxIgysW7iNTKEHZvvWlMawbF2/6mgx2bvk6uuUtybG5xdJWMrnAcXjepQ0tMHtjorG4D4c/8Pon2o+XHlGsdGqZcaOQ12U+Mh+PlImtxCHs0bGoemVEARTgKxEfBTCcsOTjRlOKslSVmTOlQK+SibTzyCERqatn2XLqPEjTjpyas4F4Qgrw== 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=XnyCN+WUseRdtROemicjyCKHzNj6FRLtKtPcgGJPLiU=; b=DTTS4mKuluUy/DioPyHPbFTkuuIuJWPZo0ItkB3Zqfsj6hPdZa07wcMvztE5fXaBilaGJS/zjGImJL6u1QR67wLg9BP/+LY8ojGrg6J+zfxokIRuhIWQoSbSK/jz+yEHVtD1z44fOyOMCLcCNDxApJfgCY9Kgn09HOWMLVJZT6ISlmNgjtp4dkAXr6qc2ikxX27c0U4J+dVJvkCJA3bF5s+qPnVazOT/fG1p54HBslWrWvwt7R50d+N4MJ2FgfCchdZV/n7OpCSlW3UaWVyb5ViDLYgxR3xyWiJGOx69XlZkYbjWgJpT4mGlqv2QAfeeKv9mTjfd39Y98+8NJ2u+Ig== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=dpdk.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=XnyCN+WUseRdtROemicjyCKHzNj6FRLtKtPcgGJPLiU=; b=V04q7R5HNdXqOi6N9zw9GyfNW79YG8fNk5oi85UqsrR7askmhIQR17kcJ5pvKJPyPrQDwbyCGUvImHVZCcfA1iRYPU2CUP3BCfYkMt5DOTZ8Epb2KanypTfQewS6RTnb4douxaJRiH4FhIHG3reqldrmH586mfSqAgmD6gZm1y8= Received: from MW2PR16CA0072.namprd16.prod.outlook.com (2603:10b6:907:1::49) by DM6PR12MB4530.namprd12.prod.outlook.com (2603:10b6:5:2aa::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33; Tue, 6 Jun 2023 10:03:27 +0000 Received: from CO1NAM11FT085.eop-nam11.prod.protection.outlook.com (2603:10b6:907:1:cafe::b3) by MW2PR16CA0072.outlook.office365.com (2603:10b6:907:1::49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.33 via Frontend Transport; Tue, 6 Jun 2023 10:03:26 +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 CO1NAM11FT085.mail.protection.outlook.com (10.13.174.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6455.33 via Frontend Transport; Tue, 6 Jun 2023 10:03:26 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) 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.2375.34; Tue, 6 Jun 2023 05:03:26 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB07.amd.com (10.181.41.45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 6 Jun 2023 03:03:25 -0700 Received: from xhdipdslab41.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2375.34 via Frontend Transport; Tue, 6 Jun 2023 05:03:22 -0500 From: Nipun Gupta To: , , , , , CC: , , , Nipun Gupta Subject: [PATCH v7 4/4] bus/cdx: support plug unplug and dev iterator Date: Tue, 6 Jun 2023 15:32:58 +0530 Message-ID: <20230606100258.26532-5-nipun.gupta@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230606100258.26532-1-nipun.gupta@amd.com> References: <20230124140746.594066-1-nipun.gupta@amd.com> <20230606100258.26532-1-nipun.gupta@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT085:EE_|DM6PR12MB4530:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f2078fb-fb71-4faa-cd86-08db667545ac X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YmubWqNJsnt+B9tSfgxU3p8qSwVniVBtj8oP1+lGfnPDns0aYV11gAinWuEXzSgp+R2uoFUTDexjAVavaO7LcCpXe+FL7z2GerE+vfP76jjCwde0/37nBVMLKy14v1w1zi/t0VMD72p8fDfvQ9gvvi7Cp07Z5MZ7kKfKDIVUNf/ADPZ5ZoMD7w03KO3G+1fMFgDe+OgIUU4KAzrW8z/kIUtRuUeEt6yVmGVWtb8rNlTDEazpne6wSwNfqQriTHxPx+dAlCFvcmbZRQqLpSnnZSFRdW9Q9396qM0XpqJJ0J60DlW+dUfR45F1YAsgj7dhvu1aJNQBhdGvCPDjrlDgkryjn8J5elo5lmdItueaPMcjgWU0i9Ka0KQpdLlvWkd2W3DfoWCdycVishkCq/5ur2rp0c+4kTD+EsC7Z6RS6SNsOGGbhBuQHauCkT+6m8U3oA2EymCVj7xGG5emV6npPt0jyw0l45yo6Xeot4V7BAcHos0nK7G39D4DwGi8nlkFui9m74WAzZ0c6wpvFFH4LFo87RY9li/DsrXAogQcrW49W783DJwhlc576VOwtilaxUS9J1xB5swLBP3+Kq0gOfKFc6RMW0EjKGCn+YbBnZ5dwDPXk/7pM0PkBVUNh4af/NCN46au31aPsq3HrIGUeFYNOeUv/BSUm5Uq5tsuRDcNVn/TzNWjkB88f+VmIazJB8jlh3f1cKETnKoPf4UGJYk3FgFofYpvpiOwpG7fpxGjiziUakmfm2G5cTTkvx37DRSJfmBhB0urK2MAw8sSUA== 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)(396003)(376002)(346002)(39860400002)(136003)(451199021)(40470700004)(36840700001)(46966006)(26005)(110136005)(40480700001)(1076003)(70206006)(82740400003)(70586007)(4326008)(81166007)(356005)(82310400005)(36860700001)(336012)(426003)(47076005)(478600001)(2616005)(36756003)(2906002)(40460700003)(41300700001)(316002)(44832011)(8676002)(54906003)(8936002)(186003)(5660300002)(86362001)(6666004)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2023 10:03:26.7810 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9f2078fb-fb71-4faa-cd86-08db667545ac 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: CO1NAM11FT085.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4530 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This change adds support for plugging and unplugging CDX devices on AMD CDX bus. Also, CDX dev iterator support has been added for the CDX bus. Signed-off-by: Nipun Gupta Acked-by: Ferruh Yigit --- drivers/bus/cdx/bus_cdx_driver.h | 1 + drivers/bus/cdx/cdx.c | 122 +++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) diff --git a/drivers/bus/cdx/bus_cdx_driver.h b/drivers/bus/cdx/bus_cdx_driver.h index cb99c13636..04ccdf7c53 100644 --- a/drivers/bus/cdx/bus_cdx_driver.h +++ b/drivers/bus/cdx/bus_cdx_driver.h @@ -52,6 +52,7 @@ struct rte_cdx_id { struct rte_cdx_device { RTE_TAILQ_ENTRY(rte_cdx_device) next; /**< Next probed CDX device. */ struct rte_device device; /**< Inherit core device */ + struct rte_cdx_driver *driver; /**< CDX driver used in probing */ char name[RTE_DEV_NAME_MAX_LEN]; /**< Device name */ struct rte_cdx_id id; /**< CDX ID. */ struct rte_mem_resource mem_resource[CDX_MAX_RESOURCE]; diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c index e5e6a665c3..2165486bc3 100644 --- a/drivers/bus/cdx/cdx.c +++ b/drivers/bus/cdx/cdx.c @@ -71,6 +71,7 @@ #include #include #include +#include #include #include @@ -92,6 +93,15 @@ struct rte_cdx_bus rte_cdx_bus; +enum cdx_params { + RTE_CDX_PARAM_NAME, +}; + +static const char * const cdx_params_keys[] = { + [RTE_CDX_PARAM_NAME] = "name", + NULL, +}; + /* Add a device to CDX bus */ static void cdx_add_device(struct rte_cdx_device *cdx_dev) @@ -385,6 +395,7 @@ cdx_probe_one_driver(struct rte_cdx_driver *dr, } else { dev->device.driver = &dr->driver; } + dev->driver = dr; return ret; @@ -499,6 +510,71 @@ cdx_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, return NULL; } +/* Remove a device from CDX bus */ +static void +cdx_remove_device(struct rte_cdx_device *cdx_dev) +{ + TAILQ_REMOVE(&rte_cdx_bus.device_list, cdx_dev, next); +} + +/* + * If vendor/device ID match, call the remove() function of the + * driver. + */ +static int +cdx_detach_dev(struct rte_cdx_device *dev) +{ + struct rte_cdx_driver *dr; + int ret = 0; + + if (dev == NULL) + return -EINVAL; + + dr = dev->driver; + + CDX_BUS_DEBUG("detach device %s using driver: %s", + dev->device.name, dr->driver.name); + + if (dr->remove) { + ret = dr->remove(dev); + if (ret < 0) + return ret; + } + + /* clear driver structure */ + dev->driver = NULL; + dev->device.driver = NULL; + + rte_cdx_unmap_device(dev); + + rte_intr_instance_free(dev->intr_handle); + dev->intr_handle = NULL; + + return 0; +} + +static int +cdx_plug(struct rte_device *dev) +{ + return cdx_probe_all_drivers(RTE_DEV_TO_CDX_DEV(dev)); +} + +static int +cdx_unplug(struct rte_device *dev) +{ + struct rte_cdx_device *cdx_dev; + int ret; + + cdx_dev = RTE_DEV_TO_CDX_DEV(dev); + ret = cdx_detach_dev(cdx_dev); + if (ret == 0) { + cdx_remove_device(cdx_dev); + rte_devargs_remove(dev->devargs); + free(cdx_dev); + } + return ret; +} + static int cdx_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len) { @@ -526,15 +602,61 @@ cdx_get_iommu_class(void) return RTE_IOVA_VA; } +static int +cdx_dev_match(const struct rte_device *dev, + const void *_kvlist) +{ + const struct rte_kvargs *kvlist = _kvlist; + const char *key = cdx_params_keys[RTE_CDX_PARAM_NAME]; + const char *name; + + /* no kvlist arg, all devices match */ + if (kvlist == NULL) + return 0; + + /* if key is present in kvlist and does not match, filter device */ + name = rte_kvargs_get(kvlist, key); + if (name != NULL && strcmp(name, dev->name)) + return -1; + + return 0; +} + +static void * +cdx_dev_iterate(const void *start, + const char *str, + const struct rte_dev_iterator *it __rte_unused) +{ + rte_bus_find_device_t find_device; + struct rte_kvargs *kvargs = NULL; + struct rte_device *dev; + + if (str != NULL) { + kvargs = rte_kvargs_parse(str, cdx_params_keys); + if (kvargs == NULL) { + CDX_BUS_ERR("cannot parse argument list %s", str); + rte_errno = EINVAL; + return NULL; + } + } + find_device = rte_cdx_bus.bus.find_device; + dev = find_device(start, cdx_dev_match, kvargs); + rte_kvargs_free(kvargs); + return dev; +} + struct rte_cdx_bus rte_cdx_bus = { .bus = { .scan = cdx_scan, .probe = cdx_probe, .find_device = cdx_find_device, + .plug = cdx_plug, + .unplug = cdx_unplug, .parse = cdx_parse, .dma_map = cdx_dma_map, .dma_unmap = cdx_dma_unmap, .get_iommu_class = cdx_get_iommu_class, + .dev_iterate = cdx_dev_iterate, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_cdx_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_cdx_bus.driver_list), -- 2.17.1