From patchwork Fri Sep 15 04:54:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Nipun" X-Patchwork-Id: 140490 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a55:b0:13f:353d:d1ed with SMTP id 21csp376029rwb; Fri, 15 Sep 2023 08:02:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHSvJ0qZul8+t2DFpv0773s3nKU04dtfZ1oIEUKe7S63M8wJNph/eyg27Qxxo/iGBPd2y6N X-Received: by 2002:a05:6a20:f38a:b0:154:e7e6:85c8 with SMTP id qr10-20020a056a20f38a00b00154e7e685c8mr1748030pzb.31.1694790137868; Fri, 15 Sep 2023 08:02:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1694790137; cv=pass; d=google.com; s=arc-20160816; b=YrpU8S9FnwKnyyRI3CJYT8iCdlcgm3W/Sx1Jv2kowSKaV0vwbRmPw8CXhhOr4QgdOQ Of/hTeYLW6qigWUvEYti/q6BQer/prErKvmPk2f/aw1yCIDPf9erVLxH++TsAn6RI8N/ e72qk41pvN+o/CRzsySgVlu0ICqeMUCS5RnG117LQgSLfX2D0HhihvpRB3nddSxOA2pQ +QG8G1+8a2y81Vyv3obbkrnIRFrJ5lSwrkkizom9NaxAV8TIoeu2+xbf0zhJmdDddAoi QEkQALyNlgcGQVErXx8jIMSBI+DEvES51UnDKfXwTZHFMXoOFds0eF0Zekqj6HjxCesa zESA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=J4C3zuGu7WnGiG9ewbMqJ6VKoEBb/yM7nn43IAPMltg=; fh=fLjj5HR455sYz0uzTCxnf9BZdFLfS2gGmKsOPKFbVJU=; b=WrhEPGy4a7xqeyWKX3ApEsJDZyp6mxIysMAB6zq8MftSFo4qDtQQ+zzfHGIqsGqCnp ukVU+LbM9W2PlbYQ65MS+2QqtSnj5t/SPtaOsfpsl3ST31wJ++aertLGoyZouTAB3SYJ 84xu1yRN4zSaikRxj3fIrAyqs2kJ1MJ1rCCr3xDpntImoIdhl4ATVtxoEUWuzLfO0f+N kj5+6qPciX2RoftumltqAbGsP/k0XBagHUXt+Ae65OrCHbDNIv8o/CJqJtAq/xkhm9iy Lhr0uDXnpmJB6UPlgfQGUtdqHgcOaUvYU6mEoMMH+2V2sqVrRVl3LGOfHMGWEK5bPPHa cFAQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Mn58Kwov; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id v127-20020a632f85000000b0055c8d58cee9si3229339pgv.714.2023.09.15.08.02.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 08:02:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Mn58Kwov; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id EA9F781B5AA4; Thu, 14 Sep 2023 21:55:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231946AbjIOEzH (ORCPT + 33 others); Fri, 15 Sep 2023 00:55:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjIOEzG (ORCPT ); Fri, 15 Sep 2023 00:55:06 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2054.outbound.protection.outlook.com [40.107.220.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B493F2718 for ; Thu, 14 Sep 2023 21:55:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HPwJUAsEfVEApVmHHq/ye+P0iXBWqb5nX0cuG00BT4+5Kq5nMFVk1DHTfyKzy1YHvy0E1dIDZINyGkbjZPYAh0aF+Z+McBOXA/T7gE0CMru0aYxSNz0/N4nGEHgJ//z36u5FnhNdN2jd23x0kTfu/rQ5UPBxnhQGs+WfGCkrZ4MT6FE7pNQcfFINSKl5HWFa1cLjYYGIiNXpz+IoKcgRxB/jzY7TCRWhMqU9QtUQaW9zghXT1/FnFAZQCk/G2ktvC+Do5Q5bFdsonoqLwvnqPJxEo5nWjYK4ezOPao4Z1tC7vRxGDSO4CdQXr8WrWSa7TbPrBDKXRUHxvcoLGHjQYw== 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=J4C3zuGu7WnGiG9ewbMqJ6VKoEBb/yM7nn43IAPMltg=; b=LXPBzlWH90StYhZABfQ6IVBdvwiND9iaXVFuGUpAV8jLl3XHAzXFY0m0KUcb2x6XZnUDqxcZiiI3FZK/HHF0NHHgWwENKmWmd7luKQHlSzuwyXf13l+pjbGjkY76LEvggVKpIa2prrv/yR69oLhRZV8H7RETzjbpSCKTw1vqi307uqzRDTDgsCtHqw0KxHEnl2Fey98kA8S+IgwQ9Tjrqso6It+drg1DlVNeJK+T9VlR17SqHiUmP0AblW6sIGrVZq2R3gU6WnOHvQ7DWlHX8QXpw6TmgqLIZGylGQ5YmVjv9PyuW3anKtL52ekliapNQGloeNb9iZh7r0/s0fiLUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linuxfoundation.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=J4C3zuGu7WnGiG9ewbMqJ6VKoEBb/yM7nn43IAPMltg=; b=Mn58KwovqFtS0HOzydMMAh8YRlIGtHybrkAF1pEM5hJwsD3gqI6r6vL3SKeKsCpDAO87+FshbbAjR48T1eTRwR/Qq3IkRuO1by0RfvuM1rhe1ZMqWHC6DV3UzEAVgb2h3pbKdGA+/WMczLVeGsbUaNPgQ2X3AV56lJBEIDnBgDc= Received: from MW4PR02CA0001.namprd02.prod.outlook.com (2603:10b6:303:16d::21) by SA1PR12MB7317.namprd12.prod.outlook.com (2603:10b6:806:2ba::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.20; Fri, 15 Sep 2023 04:54:58 +0000 Received: from CO1PEPF000044FB.namprd21.prod.outlook.com (2603:10b6:303:16d:cafe::74) by MW4PR02CA0001.outlook.office365.com (2603:10b6:303:16d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.20 via Frontend Transport; Fri, 15 Sep 2023 04:54:58 +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 CO1PEPF000044FB.mail.protection.outlook.com (10.167.241.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.20 via Frontend Transport; Fri, 15 Sep 2023 04:54:57 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.2507.27; Thu, 14 Sep 2023 23:54:28 -0500 Received: from xhdipdslab41.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Thu, 14 Sep 2023 23:54:25 -0500 From: Nipun Gupta To: , , CC: , , , , , , Nipun Gupta Subject: [PATCH v8 1/3] cdx: add support for bus mastering Date: Fri, 15 Sep 2023 10:24:21 +0530 Message-ID: <20230915045423.31630-1-nipun.gupta@amd.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044FB:EE_|SA1PR12MB7317:EE_ X-MS-Office365-Filtering-Correlation-Id: 60f001d3-1ec7-470c-93c9-08dbb5a7e93b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CnIkAFhAC8xEAxsO3vo6F2BtuIPaR7iQBSTr844iGHpG7cvaqXHNCFkLTYJj78nov8to4BP26+WKSo7zyfi7u3cyLm/cze9oAv4K+TbvJ4vqFTcZeR2Jw5HcyPDWz/vY+/XtjoTiS/rvKsPqNqiT6FcLwKDBUSA4qBUgZlDOX76ZWKOU71z48SQIvQYlUS7IJVGp6hvtYDA5kD0OTZYFkSKiAULtoE2tx/zI+/l8FJMjV1r31Uk/SAhecv9sM5dLH5nRQNeZSdEGN8CXcskpq8py4Be6fmmI3YlsB1/zOGWTFRV4UAl+4ZwAmmkhQtv040CgrOsRB+SXMChe/O9k73O+zH3Xg+jzekREG6jCP5N0wmgLraEf9ECuIDE9Pb7+aayzQvooBVsDUG9kaH975k3ycAzSa8VsJWUUjg30ACtbRUyTu34GEsINY1rYUsULCqLVPsDeYL4kesAoo2Jmbl925vaLSgvpR4NJSlGG/Fes0AEXaG99xwaOTb4uXvi6vH6HhKDWnh+jVh4MRtVQmhBPq4CX6zjLYBawSCvl3mnZb3/oOQxlC0cFI7SHIUvaL4BA+/LXZDD0HS5qz1xNanJgi1+czGHlTfCj6D6tJ/VwBl6YIjckbJb/AwyfcL+4qlEMGu/EN0EjOQkMnagPfJKlBVha83wFGSj5e7j00de86lh2DID+anTsIvFbwukuWa5CGnkXXUcoG6Qh/Z1gE2Y/r63EjF+c6u5KetuReL+JEsgqAA+ATEJSPWyuWY9UUFjWLhRKUS6KrOVabDP4dA== 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:(13230031)(4636009)(39860400002)(376002)(346002)(136003)(396003)(1800799009)(451199024)(82310400011)(186009)(36840700001)(46966006)(40470700004)(2906002)(4326008)(8936002)(8676002)(44832011)(41300700001)(5660300002)(54906003)(70206006)(316002)(70586007)(110136005)(40460700003)(478600001)(6666004)(83380400001)(36756003)(2616005)(426003)(47076005)(1076003)(336012)(81166007)(26005)(40480700001)(36860700001)(356005)(82740400003)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2023 04:54:57.8812 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 60f001d3-1ec7-470c-93c9-08dbb5a7e93b 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: CO1PEPF000044FB.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7317 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 14 Sep 2023 21:55:09 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777116263550682012 X-GMAIL-MSGID: 1777116263550682012 Introduce cdx_set_master() and cdx_clear_master() APIs to support enable and disable of bus mastering. Drivers need to use these APIs to enable/disable DMAs from the CDX devices. Signed-off-by: Nipun Gupta Reviewed-by: Pieter Jansen van Vuuren --- Changes v7->v8: - Fix a comment in cdx_mcdi_ctrl_flag_set() Changes v6->v7: - None Changes v5->v6: - change cdx_clear_master() to int return type Changes v4->v5: - No change in this patch, patch 2/3 and patch 3/3 are updated Changes v3->v4: - Added user of the Bus master enable and disable APIs in patch 2/2. There is no change in this patch. Changes v2->v3: - Changed return value from EOPNOTSUPP to -EOPNOTSUPP in cdx_set_master() Changes v1->v2: - Replace bme with bus_master_enable - Added check for dev_configure API callback - remove un-necessary error prints - changed conditional to if-else - updated commit message to use 72 columns drivers/cdx/cdx.c | 32 ++++++++++++++ drivers/cdx/controller/cdx_controller.c | 4 ++ drivers/cdx/controller/mcdi_functions.c | 58 +++++++++++++++++++++++++ drivers/cdx/controller/mcdi_functions.h | 13 ++++++ include/linux/cdx/cdx_bus.h | 18 ++++++++ 5 files changed, 125 insertions(+) diff --git a/drivers/cdx/cdx.c b/drivers/cdx/cdx.c index d2cad4c670a0..9efb7584f952 100644 --- a/drivers/cdx/cdx.c +++ b/drivers/cdx/cdx.c @@ -182,6 +182,38 @@ cdx_match_id(const struct cdx_device_id *ids, struct cdx_device *dev) return NULL; } +int cdx_set_master(struct cdx_device *cdx_dev) +{ + struct cdx_controller *cdx = cdx_dev->cdx; + struct cdx_device_config dev_config; + int ret = -EOPNOTSUPP; + + dev_config.type = CDX_DEV_BUS_MASTER_CONF; + dev_config.bus_master_enable = true; + if (cdx->ops->dev_configure) + ret = cdx->ops->dev_configure(cdx, cdx_dev->bus_num, + cdx_dev->dev_num, &dev_config); + + return ret; +} +EXPORT_SYMBOL_GPL(cdx_set_master); + +int cdx_clear_master(struct cdx_device *cdx_dev) +{ + struct cdx_controller *cdx = cdx_dev->cdx; + struct cdx_device_config dev_config; + int ret = -EOPNOTSUPP; + + dev_config.type = CDX_DEV_BUS_MASTER_CONF; + dev_config.bus_master_enable = false; + if (cdx->ops->dev_configure) + ret = cdx->ops->dev_configure(cdx, cdx_dev->bus_num, + cdx_dev->dev_num, &dev_config); + + return ret; +} +EXPORT_SYMBOL_GPL(cdx_clear_master); + /** * cdx_bus_match - device to driver matching callback * @dev: the cdx device to match against diff --git a/drivers/cdx/controller/cdx_controller.c b/drivers/cdx/controller/cdx_controller.c index dc52f95f8978..39aa569d8e07 100644 --- a/drivers/cdx/controller/cdx_controller.c +++ b/drivers/cdx/controller/cdx_controller.c @@ -55,6 +55,10 @@ static int cdx_configure_device(struct cdx_controller *cdx, case CDX_DEV_RESET_CONF: ret = cdx_mcdi_reset_device(cdx->priv, bus_num, dev_num); break; + case CDX_DEV_BUS_MASTER_CONF: + ret = cdx_mcdi_bus_master_enable(cdx->priv, bus_num, dev_num, + dev_config->bus_master_enable); + break; default: ret = -EINVAL; } diff --git a/drivers/cdx/controller/mcdi_functions.c b/drivers/cdx/controller/mcdi_functions.c index 0158f26533dd..6acd8fea4586 100644 --- a/drivers/cdx/controller/mcdi_functions.c +++ b/drivers/cdx/controller/mcdi_functions.c @@ -137,3 +137,61 @@ int cdx_mcdi_reset_device(struct cdx_mcdi *cdx, u8 bus_num, u8 dev_num) return ret; } + +static int cdx_mcdi_ctrl_flag_get(struct cdx_mcdi *cdx, u8 bus_num, + u8 dev_num, u32 *flags) +{ + MCDI_DECLARE_BUF(inbuf, MC_CMD_CDX_DEVICE_CONTROL_GET_IN_LEN); + MCDI_DECLARE_BUF(outbuf, MC_CMD_CDX_DEVICE_CONTROL_GET_OUT_LEN); + size_t outlen; + int ret; + + MCDI_SET_DWORD(inbuf, CDX_DEVICE_CONTROL_GET_IN_BUS, bus_num); + MCDI_SET_DWORD(inbuf, CDX_DEVICE_CONTROL_GET_IN_DEVICE, dev_num); + ret = cdx_mcdi_rpc(cdx, MC_CMD_CDX_DEVICE_CONTROL_GET, inbuf, + sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); + if (ret) + return ret; + + if (outlen != MC_CMD_CDX_DEVICE_CONTROL_GET_OUT_LEN) + return -EIO; + + *flags = MCDI_DWORD(outbuf, CDX_DEVICE_CONTROL_GET_OUT_FLAGS); + + return 0; +} + +static int cdx_mcdi_ctrl_flag_set(struct cdx_mcdi *cdx, u8 bus_num, + u8 dev_num, bool enable, int bit_pos) +{ + MCDI_DECLARE_BUF(inbuf, MC_CMD_CDX_DEVICE_CONTROL_SET_IN_LEN); + u32 flags; + int ret; + + /* + * Get flags and then set/reset bit at bit_pos according to + * the input params. + */ + ret = cdx_mcdi_ctrl_flag_get(cdx, bus_num, dev_num, &flags); + if (ret) + return ret; + + flags = flags & (u32)(~(BIT(bit_pos))); + if (enable) + flags |= (1 << bit_pos); + + MCDI_SET_DWORD(inbuf, CDX_DEVICE_CONTROL_SET_IN_BUS, bus_num); + MCDI_SET_DWORD(inbuf, CDX_DEVICE_CONTROL_SET_IN_DEVICE, dev_num); + MCDI_SET_DWORD(inbuf, CDX_DEVICE_CONTROL_SET_IN_FLAGS, flags); + ret = cdx_mcdi_rpc(cdx, MC_CMD_CDX_DEVICE_CONTROL_SET, inbuf, + sizeof(inbuf), NULL, 0, NULL); + + return ret; +} + +int cdx_mcdi_bus_master_enable(struct cdx_mcdi *cdx, u8 bus_num, + u8 dev_num, bool enable) +{ + return cdx_mcdi_ctrl_flag_set(cdx, bus_num, dev_num, enable, + MC_CMD_CDX_DEVICE_CONTROL_SET_IN_BUS_MASTER_ENABLE_LBN); +} diff --git a/drivers/cdx/controller/mcdi_functions.h b/drivers/cdx/controller/mcdi_functions.h index 7440ace5539a..a448d6581eb4 100644 --- a/drivers/cdx/controller/mcdi_functions.h +++ b/drivers/cdx/controller/mcdi_functions.h @@ -58,4 +58,17 @@ int cdx_mcdi_get_dev_config(struct cdx_mcdi *cdx, int cdx_mcdi_reset_device(struct cdx_mcdi *cdx, u8 bus_num, u8 dev_num); +/** + * cdx_mcdi_bus_master_enable - Set/Reset bus mastering for cdx device + * represented by bus_num:dev_num + * @cdx: pointer to MCDI interface. + * @bus_num: Bus number. + * @dev_num: Device number. + * @enable: Enable bus mastering if set, disable otherwise. + * + * Return: 0 on success, <0 on failure + */ +int cdx_mcdi_bus_master_enable(struct cdx_mcdi *cdx, u8 bus_num, + u8 dev_num, bool enable); + #endif /* CDX_MCDI_FUNCTIONS_H */ diff --git a/include/linux/cdx/cdx_bus.h b/include/linux/cdx/cdx_bus.h index bead71b7bc73..8320ec3b9e37 100644 --- a/include/linux/cdx/cdx_bus.h +++ b/include/linux/cdx/cdx_bus.h @@ -21,11 +21,13 @@ struct cdx_controller; enum { + CDX_DEV_BUS_MASTER_CONF, CDX_DEV_RESET_CONF, }; struct cdx_device_config { u8 type; + bool bus_master_enable; }; typedef int (*cdx_scan_cb)(struct cdx_controller *cdx); @@ -170,4 +172,20 @@ extern struct bus_type cdx_bus_type; */ int cdx_dev_reset(struct device *dev); +/** + * cdx_set_master - enables bus-mastering for CDX device + * @cdx_dev: the CDX device to enable + * + * Return: 0 for success, -errno on failure + */ +int cdx_set_master(struct cdx_device *cdx_dev); + +/** + * cdx_clear_master - disables bus-mastering for CDX device + * @cdx_dev: the CDX device to disable + * + * Return: 0 for success, -errno on failure + */ +int cdx_clear_master(struct cdx_device *cdx_dev); + #endif /* _CDX_BUS_H_ */ From patchwork Fri Sep 15 04:54:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Nipun" X-Patchwork-Id: 140370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp969446vqi; Fri, 15 Sep 2023 04:25:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMGMR2dPh7/lziWBHafWl0kY2FdMC84QnBAsaM8RKcEOY85M3kimOw1i/Q6T2qowZxOPvI X-Received: by 2002:a05:6870:610c:b0:1ba:bb13:d007 with SMTP id s12-20020a056870610c00b001babb13d007mr1406013oae.5.1694777116284; Fri, 15 Sep 2023 04:25:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1694777116; cv=pass; d=google.com; s=arc-20160816; b=QBEeZMn8gxh3p8kIwjEcgRhYUsFYDtzpQgoUMjl97hocqKoLfMBkv5PcwPUgaLlnKI TGaB8BDdXGrQAwXYAYnqflBNBL9qspbVma45x0lpSsWFGKSFX5zcvn189YcIdC0AeRLA NsdnqZoTyJsUWOk+5tyliNgnLttOPE0q/z8BxcqKpRKNlYxB6oD83vG/hkCkPJpWgjSz mRtTYTG4ywJDqFm2yXKHnnNPXKr4OHYOgsUH5xsRtHq18RT4NOpcWVg4qdVWw6TsJEFa 7qk55G/xqhpTc6abded9p3/Zf1b093x1Q+X8jaDBUsxWbcBqxoDxCACp8waZ7Ofqa4uF 0VTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qqyDlYkLguiypuhViCXOm5TpvHK3PjOwSh0lLfq6OJU=; fh=u0RzIGyOF4RNUxxiywAXX9SKZez48D6UhwtRfYwn0/A=; b=Jwsgrxs8VxU6SkM/4pT+YZ154IEvaC6z4Di+KS3pZUSlUJpf91bkMgGzXlvMd9IF+V ZWDX+NqINUE+TPGsSZ/O4AZdCkBWVXKj/Bt91LYcb8h3xM5XIXOMhYENCZq+NATE32k+ sbBCOXC7Uhsj+RCvbXUf9SMd/LWFVjeLJFLGyZoRmHDWRaB3CggKUcX7UmAAhQiN+U93 MW71FEsEhKO4pgaHdDmFkPeBrOI83WsKhiXJxywmw1unsIXeICV1VbKTqCi/v/A+K36z cnqzFXFTHzBJchuM5saANGBztcmE+E5yl+lbizIA7Z71kG6IGz216maXr46m3K7OcI4B lGaw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=NjW5vCAs; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id o25-20020a635a19000000b005652a295669si3104865pgb.490.2023.09.15.04.25.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 04:25:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=NjW5vCAs; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 301F0837EA4A; Thu, 14 Sep 2023 21:55:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229593AbjIOEzY (ORCPT + 33 others); Fri, 15 Sep 2023 00:55:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjIOEzV (ORCPT ); Fri, 15 Sep 2023 00:55:21 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2067.outbound.protection.outlook.com [40.107.223.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB4812710 for ; Thu, 14 Sep 2023 21:55:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K5W3yDl6tqEnOj68EpaVfuj1vyKc75xxGOe2Ov7HBsYmuCl8UTkTmbFS65Yd90s/Gmq5C4BhnYlGmmvivwVIjJ+kUOCi0sEN9gRktO1j13KehkbZnuzpsWfQx/f58r160UuFFRQOEJRw1uFahT/ObNy0nTI0rzUqzo5d7bAY+CUS4mg4rdxnN30K4TrPQBiSGWgTMidH2cid5N2EgnOLsvOsEgXb0NBRIBve6mr3BE/69iPQ5MmXtCoeXnpZa2U1Kr6ZSA9crM5+4RFy4JWKtp2uHFen/tS4Ghl8bidvevmWn/gIU3a04kPiygjRR4y5lyOUhyDeXtuWLNQAwS/PxQ== 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=qqyDlYkLguiypuhViCXOm5TpvHK3PjOwSh0lLfq6OJU=; b=Z8TuXzbr+pSob2lpzL1va/zKw9c3LiVHEm4Kq9RzLU2mg74057MUkF5CzcE2iGwHoi3s9FNXTAd5jDtlZMUdT8abLHqGSUDVLMihK4rBAjSdtiBNTuX6AkXKHPOf79b1fkNOVjxN1ER8+xUQHUz1z2h0005fxGnrQGsX1MYYeiwU0Iafp9EMCVV9oo3ZB2w/7pVAKZGjE9USV0Zc9o2+LCexXCdEWx0d/zGE7ppS7Kt8EMsdXaU1bU7w30y4sUTiIEs69e/V48eh2AepNlTIPnpvYZL6JLWnxiBqY+YyEKLskHmiQMDCfQzs/0EJQ+SjssGOOxTrDXm6JDr5t0J6/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linuxfoundation.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=qqyDlYkLguiypuhViCXOm5TpvHK3PjOwSh0lLfq6OJU=; b=NjW5vCAsCsSLnwkyIzJD3VVdcVRlxSHYIEZowspZ+j9Qj6JfPfEGUH0hroARFtIKRRjBwAtwirpiTzawl13Yc5U7DulYk3uuIa+Ugcc9YybicWynzlhvqeHiOTdYPaQL1TV+HzThwV4JHG68odGlrSPhqyp6Tf70j1yEI/mmHN8= Received: from MW4PR03CA0118.namprd03.prod.outlook.com (2603:10b6:303:b7::33) by SA3PR12MB8761.namprd12.prod.outlook.com (2603:10b6:806:312::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.30; Fri, 15 Sep 2023 04:55:07 +0000 Received: from CO1PEPF000044F7.namprd21.prod.outlook.com (2603:10b6:303:b7:cafe::a6) by MW4PR03CA0118.outlook.office365.com (2603:10b6:303:b7::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.21 via Frontend Transport; Fri, 15 Sep 2023 04:55:06 +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 CO1PEPF000044F7.mail.protection.outlook.com (10.167.241.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.20 via Frontend Transport; Fri, 15 Sep 2023 04:55:06 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) 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.2507.27; Thu, 14 Sep 2023 23:55:02 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 14 Sep 2023 21:55:02 -0700 Received: from xhdipdslab41.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Thu, 14 Sep 2023 23:54:59 -0500 From: Nipun Gupta To: , , CC: , , , , , , Nipun Gupta , Shubham Rohila Subject: [PATCH v8 2/3] vfio: add bus master feature to device feature ioctl Date: Fri, 15 Sep 2023 10:24:22 +0530 Message-ID: <20230915045423.31630-2-nipun.gupta@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230915045423.31630-1-nipun.gupta@amd.com> References: <20230915045423.31630-1-nipun.gupta@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F7:EE_|SA3PR12MB8761:EE_ X-MS-Office365-Filtering-Correlation-Id: f44eed17-aad6-48b7-91e7-08dbb5a7ee57 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LehUsQFVC1wXdi59RhpAHo7AykBsRcvh5DLvB/fk3SbYaR6ydZjozV44Y7IrgyEfqEMRH3vKp9yDktUgEQi5bIdGoVLKKGOQhox7MUox3CRZ6RIytv6olTraY99KB8i04Sd6bzpR0QtH6n7GhnNJCur7Xsclo1Q7Xy1jjUY+bH5vLJx/vqRyOQJGDgRG7vCnZHLlzquOr0epBtEJfKd++M30mdVwUeaxMuV1/hIShbumhL06YUSC9BiIchiDWSawQsrc9BOiyQ2s8+4ZjhUjyqS6wRnskL9BQrEuOhcgZo8311ebBcUTfuADBJMYEZGUX93UywxONmdWAcCJalVwileq5vV+zt/FI1ZRDs/eLlKWkSV2I0Ul5jiNNOSD+ODfyyzBkYGzvWXK8m2ZygEUWdfhaneFPonsyyqXQm0/r/E7akJ7wabUho7bFj/J87ikyqyAsCmKWtIXgPO1sRdn2Jc4KsPJ3PtkjlOCV0dgx5+miUSla5VG1Vxb59tJ6G5+8svc8fappMj71fFvZ+JBoCokATfDJ3N9g5ZvVRGpv6m2H/ENcys2OJZQyG2/aI/ldyvjEDvGRgW6TyIST29ojEmQlhGlMCzCmPNm602TsgdrIYsytM+GHgcd+ZHtKXLZvNISz0ba9KbDsbun6tge42s6t3BaPsjh2PD+UvxPhzsM1xNMeYEQqcETW7jvaME+BRq3QPpWhLPKdlqwu2dWYTaxON2F7hIWWdFAQqpAkAfRGc/PBwKnXh03dv6B0JJ3yd+/uSr8kNEVmxwZwAYWAA== 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:(13230031)(4636009)(39860400002)(346002)(396003)(136003)(376002)(186009)(1800799009)(451199024)(82310400011)(40470700004)(46966006)(36840700001)(82740400003)(5660300002)(70206006)(81166007)(356005)(6666004)(70586007)(36860700001)(86362001)(40460700003)(47076005)(40480700001)(478600001)(426003)(26005)(44832011)(41300700001)(1076003)(83380400001)(8936002)(36756003)(4326008)(2616005)(8676002)(54906003)(110136005)(316002)(2906002)(336012)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2023 04:55:06.4220 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f44eed17-aad6-48b7-91e7-08dbb5a7ee57 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: CO1PEPF000044F7.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB8761 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 14 Sep 2023 21:55:30 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777102609524487439 X-GMAIL-MSGID: 1777102609524487439 add bus mastering control to VFIO_DEVICE_FEATURE IOCTL. The VFIO user can use this feature to enable or disable the Bus Mastering of a device bound to VFIO. Co-developed-by: Shubham Rohila Signed-off-by: Shubham Rohila Signed-off-by: Nipun Gupta --- Changes v7->v8: - None Changes v6->v7: - None Changes v5->v6: - Updated description of VFIO_DEVICE_FEATURE_BUS_MASTER IOCTL - Used 0 for clear and 1 for set bus master operation Changes in v5: - This patch is newly added which proposes a new flag VFIO_DEVICE_FEATURE_BUS_MASTER in VFIO_DEVICE_FEATURE IOCTL. include/uapi/linux/vfio.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 20c804bdc09c..6858cd80d597 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -1287,6 +1287,27 @@ struct vfio_device_feature_mig_data_size { #define VFIO_DEVICE_FEATURE_MIG_DATA_SIZE 9 +/** + * Upon VFIO_DEVICE_FEATURE_SET, set or clear the BUS mastering for the device + * based on the operation specified in op flag. + * + * The functionality is incorporated for devices that needs bus master control, + * but the in-band device interface lacks the support. Consequently, it is not + * applicable to PCI devices, as bus master control for PCI devices is managed + * in-band through the configuration space. At present, this feature is supported + * only for CDX devices. + * When the device's BUS MASTER setting is configured as CLEAR, it will result in + * blocking all incoming DMA requests from the device. On the other hand, configuring + * the device's BUS MASTER setting as SET (enable) will grant the device the + * capability to perform DMA to the host memory. + */ +struct vfio_device_feature_bus_master { + __u32 op; +#define VFIO_DEVICE_FEATURE_CLEAR_MASTER 0 /* Clear Bus Master */ +#define VFIO_DEVICE_FEATURE_SET_MASTER 1 /* Set Bus Master */ +}; +#define VFIO_DEVICE_FEATURE_BUS_MASTER 10 + /* -------- API for Type1 VFIO IOMMU -------- */ /** From patchwork Fri Sep 15 04:54:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Nipun" X-Patchwork-Id: 140143 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp811571vqi; Thu, 14 Sep 2023 22:05:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENKUzsbDiHQhdDdfwGqxdm1ty44fnHwvbPbjr+tgvfKmfUHZVtK9uapsgoUZpg82szc8rN X-Received: by 2002:a05:6a00:9a3:b0:68f:d036:9bc5 with SMTP id u35-20020a056a0009a300b0068fd0369bc5mr694535pfg.2.1694754346286; Thu, 14 Sep 2023 22:05:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1694754346; cv=pass; d=google.com; s=arc-20160816; b=mpw8dHJ+9YqNFFPTKhruvyna72fwUcU+151R2TEZ9oKwzfohKGXKIP/HKpM96DmZhH q0Y+SWvFZVnC5G9CsOfEy7zm+Hh2iTfGXAkgcY692VpfQA07Y52i17AwJ2ruY3mlhH23 3GMXJ93fxoHdoYm/Ev0GEMkEsLgtymT/ARSug/8Ei8kviR9ums0H4rnKMiw8fZjLuTsW QFsTaH11NhqDsY9lh3v93rgSjtQqR5jWK3gcXZtk6p37wVlVUweHBmdhvMjzXsMtC7tu zXxXoEFOGl6gmIy3U0Dvg5U8bckJ7bo2B6twTwZAq8HwgzZ2ehNZgHHi8EBWxce1xHY+ /oBA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nebA7Ev9hlCgPI8GGx1l9HRcwFl+MEMWgnueVmIvbOU=; fh=u0RzIGyOF4RNUxxiywAXX9SKZez48D6UhwtRfYwn0/A=; b=FEQ9IrJQ5JtubyAsG0lqP63uhQwdvudVm0I8I0x2P7TpHzbAdNLvmtAdUvVLA695Zn 7UFbk65jYaPHxxwyuZ1MwrtfxWsY7hgwLBi/2XrJki2ZadhRNAxDFxjXAi7ugJNYnVRl pj5YkFp5b6Puo3UDA1spIGWd0HJTRvV0K4K8h8swmFji8qmDrsy5N61b6ZCcPQHXaCQ2 VlCcGANfsE2EJTLcSn52scmXl36SGrQerEF+HT3de/9ic3EPPPxUMHL6Aib1Y7XE38dl PJyBWKH/79ruxA0fje/fgt2+bCksR2tAQ+VYHPgQWVK0Un34Xiy6CDUvOAqB2AeWrHCL GIZg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=tpghMAso; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id s72-20020a632c4b000000b00577475ee5f6si2634912pgs.618.2023.09.14.22.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 22:05:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=tpghMAso; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 0E06E8377BB0; Thu, 14 Sep 2023 21:55:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231978AbjIOEz0 (ORCPT + 33 others); Fri, 15 Sep 2023 00:55:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231177AbjIOEzW (ORCPT ); Fri, 15 Sep 2023 00:55:22 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2072.outbound.protection.outlook.com [40.107.244.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 432AD2723 for ; Thu, 14 Sep 2023 21:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RwXrJdhOkIkqVmXFyxCiVwcoE8ZAWDiH1bkF/FLl8YebQq3qostvzshxag8MADxNlYuvWU2UfHbPJRKFullYvllPFQTwS7c/oU/OYhOCa4Q+4LKSInUPoGyLMvh5MjdWJ++9e8dJP07TsiTPbd2oA+Sla89zNQkqkZCZJebb8il1zvek3yOVPlvJfaoLMVghsp8Q2jVEzahOqlSLX7mYONBHg3NrK8hH85Res6myNXDcj4sgU9WMMf0g6PtIP1ULRtRdbyc+bWdgWx76m2KAcKrCbt+oAeB6kIHjWsfN1g6ulgSWn+JKjrGrn59HlGUO8bVrOcIfBZzcJSpsmDpkJA== 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=nebA7Ev9hlCgPI8GGx1l9HRcwFl+MEMWgnueVmIvbOU=; b=j05/XSZJmqcGH4EiT+4WfVkAnQCdcTFmYLEUUCTJdcI7VJoVMSEkFhEWx8YxgozvmChAhudskuwe/UhMndayKLPiCWCUxKEDEka3OhzP1S1LBx9KaAbXqnMmfPAxMQYEvTOkOuKCTwQWA6TZql2XLNFqjzpwD+HWpLD83TgN0FgLoHhG38bm1Bw2EIPUOOqFm0555bObiJjpHN24xgRV/o1bKpgZGonSyYnOK4Zc3Sty92CZ4pcxu9XdhYUFmCu7jO03+2LWNtTGyuue/3rxsU/AJcm1pVKGyOI3Ltjw/nbAocY/r4mLu4MFMOApsuf8vMhOStpF2aawfvFAWVTF/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=linuxfoundation.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=nebA7Ev9hlCgPI8GGx1l9HRcwFl+MEMWgnueVmIvbOU=; b=tpghMAsoDSKHusRqA2nbgggztDbJ1I/VRPn2GintkCLA+ifWNVHDSUi1B7qWHzbqjdHQPm9NFdWRwuoILMMGMdtXoHUqmtDXO7NulIsPBNCOuMVuU8nw450F5rIsY6TNkybE3t5E7O31C9JqHxSNUjqfpE/gPBOQHtK/Kvuvacg= Received: from MW4PR04CA0374.namprd04.prod.outlook.com (2603:10b6:303:81::19) by CYXPR12MB9385.namprd12.prod.outlook.com (2603:10b6:930:e2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.34; Fri, 15 Sep 2023 04:55:08 +0000 Received: from MWH0EPF000971E7.namprd02.prod.outlook.com (2603:10b6:303:81:cafe::a7) by MW4PR04CA0374.outlook.office365.com (2603:10b6:303:81::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.20 via Frontend Transport; Fri, 15 Sep 2023 04:55:08 +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 MWH0EPF000971E7.mail.protection.outlook.com (10.167.243.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6792.19 via Frontend Transport; Fri, 15 Sep 2023 04:55:08 +0000 Received: from SATLEXMB08.amd.com (10.181.40.132) 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; Thu, 14 Sep 2023 23:55:07 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) by SATLEXMB08.amd.com (10.181.40.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 14 Sep 2023 21:55:06 -0700 Received: from xhdipdslab41.xilinx.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Thu, 14 Sep 2023 23:55:04 -0500 From: Nipun Gupta To: , , CC: , , , , , , Nipun Gupta , Shubham Rohila Subject: [PATCH v8 3/3] vfio-cdx: add bus mastering device feature support Date: Fri, 15 Sep 2023 10:24:23 +0530 Message-ID: <20230915045423.31630-3-nipun.gupta@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230915045423.31630-1-nipun.gupta@amd.com> References: <20230915045423.31630-1-nipun.gupta@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000971E7:EE_|CYXPR12MB9385:EE_ X-MS-Office365-Filtering-Correlation-Id: 8ebdf625-b511-4747-8fed-08dbb5a7ef59 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9wWXg4nLMf0rnkQdq2b1IFWTcN2eOMtoaCv88138VS2zFrBJ8B0eFZWD5ye2k9Q1/njBcBTXfOKJKWjDFF7ADLlsALHWfUgvnZSnfuNo2mLRKYinRdPvBau77JgKfSDD0SHr8xLDiws0zHfWiuCnDOhAeqBO/fIfPX0f2+2IxTEq4qkTXremyB3KCoVTGyra0uK2EyF5XUb/OhsFUQoCgWCEldaBTwobiW7a/6yPt2qZL0LyW28ZDA4rHtDMQlmuyedInBgvG6HTE68JD0THZv3z3+d4w1h+OWD5A971G6KePlDUGjmPhRwvHTBDXdUWrIfu5kEP7qH9JD34Gk2/LSdfNTFyMcYs1LTMkStAU7JPQX9uolm4Zhcl/gYTbZB5tgqg5u3y/Kwq0PuIrb7k60Y9kHPC3PRAP42+9v99HDahT1LUZ57C34iLYd2V4n95GoXitCMStFgOgbVCbqxUTT3Qc1eZMzjpjZuqNV6FKlcj1IbF7rTBL8D5NSwEzwBEzKGn06jGH2U1uVxy0IKp8f8+L1ToMKeOTUoxl4folmoZH2a1qk6tuWZF3BMowm5ASwoN6E2NzCRBKvT3cD6Njc/d2kdkhCS2I9Piy1rBXCQKGutHJocYLxpD5BFehpO/oNq0TaDLKXYl8IMYM5ldpqmFmnpmGMYvvRXBGpWnzo3DjLFQDqycOYGjMUqRVsw9h3ElyaDJxWjWQYFTBs1UKmmM5m3U8GQMH2Q84g9mtZ+BKBSeRCRfyBaRKTrAIc5OhaLrrQBuM/7iw5IdAKMufQ== 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:(13230031)(4636009)(136003)(396003)(346002)(376002)(39860400002)(1800799009)(82310400011)(451199024)(186009)(36840700001)(40470700004)(46966006)(110136005)(356005)(36756003)(6666004)(26005)(478600001)(83380400001)(2906002)(336012)(426003)(70586007)(1076003)(44832011)(70206006)(41300700001)(8676002)(2616005)(316002)(4326008)(40460700003)(5660300002)(8936002)(54906003)(36860700001)(86362001)(40480700001)(47076005)(82740400003)(81166007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2023 04:55:08.1128 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8ebdf625-b511-4747-8fed-08dbb5a7ef59 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: MWH0EPF000971E7.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYXPR12MB9385 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 14 Sep 2023 21:55:35 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777078733120997635 X-GMAIL-MSGID: 1777078733120997635 Support Bus master enable and disable on VFIO-CDX devices using VFIO_DEVICE_FEATURE_BUS_MASTER flag over VFIO_DEVICE_FEATURE IOCTL. Co-developed-by: Shubham Rohila Signed-off-by: Shubham Rohila Signed-off-by: Nipun Gupta --- Changes v7->v8: - None Changes v6->v7: - Add check for BME in open, thus resulting in correct response in feature probe. - Set vdev_regions to NULL in case of error in vfio device open. Changes v5->v6: - Called CDX device reset at cdx_open_device() Changes v4->v5: - Use device feature IOCTL instead of adding a new VFIO IOCTL for bus master feature. Changes in v4: - This patch is newly added which uses cdx_set_master() and cdx_clear_master() APIs. drivers/vfio/cdx/main.c | 57 +++++++++++++++++++++++++++++++++++++- drivers/vfio/cdx/private.h | 2 ++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/cdx/main.c b/drivers/vfio/cdx/main.c index c376a69d2db2..53ed8e6c499f 100644 --- a/drivers/vfio/cdx/main.c +++ b/drivers/vfio/cdx/main.c @@ -14,7 +14,7 @@ static int vfio_cdx_open_device(struct vfio_device *core_vdev) container_of(core_vdev, struct vfio_cdx_device, vdev); struct cdx_device *cdx_dev = to_cdx_device(core_vdev->dev); int count = cdx_dev->res_count; - int i; + int i, ret; vdev->regions = kcalloc(count, sizeof(struct vfio_cdx_region), GFP_KERNEL_ACCOUNT); @@ -39,6 +39,17 @@ static int vfio_cdx_open_device(struct vfio_device *core_vdev) if (!(cdx_dev->res[i].flags & IORESOURCE_READONLY)) vdev->regions[i].flags |= VFIO_REGION_INFO_FLAG_WRITE; } + ret = cdx_dev_reset(core_vdev->dev); + if (ret) { + kfree(vdev->regions); + vdev->regions = NULL; + return ret; + } + ret = cdx_clear_master(cdx_dev); + if (ret) + vdev->flags &= ~BME_SUPPORT; + else + vdev->flags |= BME_SUPPORT; return 0; } @@ -52,6 +63,49 @@ static void vfio_cdx_close_device(struct vfio_device *core_vdev) cdx_dev_reset(core_vdev->dev); } +static int vfio_cdx_bm_ctrl(struct vfio_device *core_vdev, u32 flags, + void __user *arg, size_t argsz) +{ + size_t minsz = + offsetofend(struct vfio_device_feature_bus_master, op); + struct vfio_cdx_device *vdev = + container_of(core_vdev, struct vfio_cdx_device, vdev); + struct cdx_device *cdx_dev = to_cdx_device(core_vdev->dev); + struct vfio_device_feature_bus_master ops; + int ret; + + if (!vdev->flags & BME_SUPPORT) + return -ENOTTY; + + ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_SET, + sizeof(ops)); + if (ret != 1) + return ret; + + if (copy_from_user(&ops, arg, minsz)) + return -EFAULT; + + switch (ops.op) { + case VFIO_DEVICE_FEATURE_CLEAR_MASTER: + return cdx_clear_master(cdx_dev); + case VFIO_DEVICE_FEATURE_SET_MASTER: + return cdx_set_master(cdx_dev); + default: + return -EINVAL; + } +} + +static int vfio_cdx_ioctl_feature(struct vfio_device *device, u32 flags, + void __user *arg, size_t argsz) +{ + switch (flags & VFIO_DEVICE_FEATURE_MASK) { + case VFIO_DEVICE_FEATURE_BUS_MASTER: + return vfio_cdx_bm_ctrl(device, flags, arg, argsz); + default: + return -ENOTTY; + } +} + static int vfio_cdx_ioctl_get_info(struct vfio_cdx_device *vdev, struct vfio_device_info __user *arg) { @@ -169,6 +223,7 @@ static const struct vfio_device_ops vfio_cdx_ops = { .open_device = vfio_cdx_open_device, .close_device = vfio_cdx_close_device, .ioctl = vfio_cdx_ioctl, + .device_feature = vfio_cdx_ioctl_feature, .mmap = vfio_cdx_mmap, .bind_iommufd = vfio_iommufd_physical_bind, .unbind_iommufd = vfio_iommufd_physical_unbind, diff --git a/drivers/vfio/cdx/private.h b/drivers/vfio/cdx/private.h index 8bdc117ea88e..8e9d25913728 100644 --- a/drivers/vfio/cdx/private.h +++ b/drivers/vfio/cdx/private.h @@ -23,6 +23,8 @@ struct vfio_cdx_region { struct vfio_cdx_device { struct vfio_device vdev; struct vfio_cdx_region *regions; + u32 flags; +#define BME_SUPPORT BIT(0) }; #endif /* VFIO_CDX_PRIVATE_H */