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 8774642C46; Wed, 7 Jun 2023 06:25:09 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 61F1F42D35; Wed, 7 Jun 2023 06:25:05 +0200 (CEST) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2076.outbound.protection.outlook.com [40.107.92.76]) by mails.dpdk.org (Postfix) with ESMTP id B391142D35 for ; Wed, 7 Jun 2023 06:25:03 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xav19O5cpAqsQbjld5eo2A7JzJv9jkcHPGsHI3OdtPOd9ktUfVWKy3eG5ufFfQzC46yJIN4h4xlK6lrRL5ODVe366dZyTAqln01SAEJZpB6coXZs8lcM6Gci9HWVh8tAfe79dxe7Lhlt/PCMkXT1b9o6v00EQxZx/aLmpYYLkmtNVcJornVLTRZFCfj71NJ9w+WGfBOOX9CmA2UWumrPYyRsHHbeDY2X8U6qu7CNMv1IbmgyVwN0d0agnHK3ZKgQ6vBmZ2SlAPQe4xneT6zNyfLKxXKtEi5dmxbYtpA9Ypd/IZOt1CvYtfIl3AW7dScQe7bf4RQ/16N7ji5scizMXQ== 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=mXnTV8xwi+SuTvBFmXodYcInIgl27fzkwB1Py/HrfmA=; b=FDrF3nLWx7f5x7SLoExhJc58X19dq/rw89YNPFU3bQhRnDwkueB36cFc+5D2FjNaGPLdo63jCgHAJ6DxNz2ptbjipJR0inho/9JFFRyHppjyOucBvYlGEWrPNgqXNc5CeMx8NMMDc3Pr6Dptk9nMNMIfW9JdPo+J4+3SBud1a4/B6I8jqB4HdOBYiUzGMNlatQ3cf4L8bzUNpsUv8/fvgnQ72PAsEOv6W4bJcSQVaiQ5OGJT8Oyel84Z0NrzAddCW/hHmJbOlZL0wubOl2Phz0fAkWPGuvzuKHAakfScdIVC4ZhxUOx6qMMStLFZqJd+P8PuxQ+etkGDBXqhmbX9EQ== 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=mXnTV8xwi+SuTvBFmXodYcInIgl27fzkwB1Py/HrfmA=; b=Ua5VBBViA4Jexxr5WSWxARJyE+1+xXHYvCb1GXjJohk9M3s/dteHG+gGYyNaRpFQXg6y9KCn8JnIMY+2YOukBJvaVPbe+gTL6F2gRd6LQU1ISPPW6rUdCwjr+KN32CvNamypSGB8K1p6OJGkkK4yFaJbfkJKcX5lF2KR/Qot9s8= Received: from DM5PR07CA0084.namprd07.prod.outlook.com (2603:10b6:4:ad::49) by BY5PR12MB4856.namprd12.prod.outlook.com (2603:10b6:a03:1d5::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.19; Wed, 7 Jun 2023 04:24:58 +0000 Received: from CY4PEPF0000EE3B.namprd03.prod.outlook.com (2603:10b6:4:ad:cafe::bb) by DM5PR07CA0084.outlook.office365.com (2603:10b6:4:ad::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; Wed, 7 Jun 2023 04:24:57 +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=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by CY4PEPF0000EE3B.mail.protection.outlook.com (10.167.242.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6477.13 via Frontend Transport; Wed, 7 Jun 2023 04:24:57 +0000 Received: from SATLEXMB06.amd.com (10.181.40.147) by SATLEXMB03.amd.com (10.181.40.144) 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 23:24:57 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB06.amd.com (10.181.40.147) 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 23:24:56 -0500 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 23:24:54 -0500 From: Nipun Gupta To: , , , , , CC: , , , Nipun Gupta Subject: [PATCH v8 4/4] bus/cdx: support plug unplug and dev iterator Date: Wed, 7 Jun 2023 09:54:25 +0530 Message-ID: <20230607042425.30714-5-nipun.gupta@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230607042425.30714-1-nipun.gupta@amd.com> References: <20230124140746.594066-1-nipun.gupta@amd.com> <20230607042425.30714-1-nipun.gupta@amd.com> MIME-Version: 1.0 Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3B:EE_|BY5PR12MB4856:EE_ X-MS-Office365-Filtering-Correlation-Id: 76f50a24-886c-48e5-73b2-08db670f26ed X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c4lB4doJTptRnvkInxb6XADO+qBMJwuVk3uIa0AKfOHtjNPYMqbNh3QQCus3NONxAjwlJze1A6ZVrPs+6RT85i5ztXug1bGGTv0cyoJi8J8AH7+4a6ZcAJCUezeR5RHxPsF4Iltu2m6OOM3uq6Eb7vs6Py0NvHZJjHcRwPMN3R2XiUCmtSomKZRzuJQVJ2vi3SXB3/EBDBfl/MGxANjb51u4RnldKhf5WconzGJGePAL6KBaikKOJn6zkteI5Z94N4kLYs8JrCv+Sc8tESlv52agnRI8OSKkO306MGvvEc1FUF+S7C8yF2rcRQGrpL4NuufZb3a109QJ6YaBdf+/Sh3iiauY4Ko11mFL88jdcU2mReZNCkmvHcFHqgoNXN2X9OTLBOjlh6ussbAQnZltlnPuZvz/21FZyTxNaFP6ZIN9gI7SljXX9W5l29CKuTEqDmSCGyeEFjhofDcvqZXobWJXz/YLF7xuVFIR1rS6jhxsFcQf3KLg2tQimOfeb/rQPM5/iVnoVOCdGPOlf73klEhvApcaIZBvdXOCR56gGeDA5DnVh/L+askRoP8Xu/EJIz1zmoo5AHA5Dh8LrHcLHNLZwxoVKmqGDMAgRkn37l/332df//zTevfnwW2fLSN0sdh1XL1UoK9bH5HyQ9s2zTEuyaoy6URbjhyBNEAU9AJP7oWWxhYvpnRlMlKzF4Y4vwizKdPL5ORjE1a7KD6y92336eNiv2F5hgYz7XdQKlFRZUUAzIbdVYCdK90LfgH1ign/585fg6t8CHRBpxcMSQ== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB03.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230028)(4636009)(39860400002)(376002)(136003)(346002)(396003)(451199021)(40470700004)(46966006)(36840700001)(86362001)(40460700003)(2906002)(110136005)(54906003)(41300700001)(8936002)(82310400005)(8676002)(5660300002)(82740400003)(356005)(36756003)(44832011)(316002)(4326008)(81166007)(70206006)(70586007)(40480700001)(6666004)(478600001)(36860700001)(186003)(47076005)(336012)(2616005)(426003)(26005)(1076003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2023 04:24:57.7385 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 76f50a24-886c-48e5-73b2-08db670f26ed 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE3B.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4856 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 95c266bccb..fcacdb5896 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[RTE_CDX_MAX_RESOURCE]; diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c index 88505cfbfb..9607096d18 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