From patchwork Wed Jul 26 11:02:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Nipun" X-Patchwork-Id: 126312 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp364704vqo; Wed, 26 Jul 2023 05:27:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlG9YvVf1WL1oGdkSyb6uFpOVeaGO0ej8Srdl8MOFCss4mMEPVUkYCVCKQb/tj0T5cfyY2Gu X-Received: by 2002:ac2:5f81:0:b0:4fb:85b2:cf78 with SMTP id r1-20020ac25f81000000b004fb85b2cf78mr1149868lfe.37.1690374423682; Wed, 26 Jul 2023 05:27:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690374423; cv=pass; d=google.com; s=arc-20160816; b=NLY72HJ4Av0tvVz4W55CGCa95SsFS/gg4ryZswBeYAFq/BE9ouM3O3dcr2YaFzpL7Y XlTEzCJML2ZMuzZdKlxg/b+Zc9ammeOh2hsoAliIf0kvnrkz4aOjeH42WDx1TEn06iXG QoXohn16BYmEKbRRp6b1jKdv7T6YpVaniVyFgVbvHIHqc4baxi9i6/iZx2aENMKNwiAM wesK0wnvbjJq+HCiuNX3zki6ddnIbjC+GSOLldQKMb0ALT9Ycv34p6h8b3CTUmMOiiGM cIinypg5xi0vWfd7uulvTateYPAkhTGfHJR3A7BdrtPQboPH67R32fJNWnWIpclZPYid 1thw== 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=SjVkBaURuq++rgBcyk7gBPfCsQ7UmQ+UrK8PCAQLaSw=; fh=Ni1nsrg1oOMllulTte61KVXg/7l8962UlCxeEssxYck=; b=FfFaCidQ1y56Ybbk1HE8OxP4LFrSc6WAoQd2WlDCui6e2kfpAqIqm6dvcQMMf6ggys y/08mYl9Xhf0at41/3F21v3tXZMGOZIdRR1pL04tb+Qu+Lf2ussLZ7OMEI3FYyttaaP9 ppSkeY/nKEBwKQlWb+qD7ns7BooD/IzT6J7az+jXFI3ntLPLxYGVSUGNwU6uuDgLHMbF d6EtTFsKTvcINnAUzNJqf2hoMrc2wPioYybZn93NOgCo6klnE19oeGfDEq5ZmAAsUuuM zBVz3KkBBEwO0ltoxQBVS/W4riGr2cjG7l4pYSPi4LfGZujlBXI8FYteSypsLmrh9EN5 jRHA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=YRRnvDN7; 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::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id md12-20020a170906ae8c00b0096fe1a56de3si8901638ejb.1048.2023.07.26.05.26.38; Wed, 26 Jul 2023 05:27:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=YRRnvDN7; 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::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232478AbjGZLCl (ORCPT + 99 others); Wed, 26 Jul 2023 07:02:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230398AbjGZLCk (ORCPT ); Wed, 26 Jul 2023 07:02:40 -0400 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5AB89B for ; Wed, 26 Jul 2023 04:02:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N2iUnd7giw4iJddWj/sU+hbcaujCyknjCL++ZSa+kVe9P31+t9UsAW69d6iRT4YEQ9FTY/HvkQGMDgUOn/Mp20qHodTgy8JJvAEptidI+/S0bUtjSiM1W1ypJJFX7ZV4AhA4QAXFdsJtiAGYmUW0jZMEFZ+KhseIHY4pE9/4CasL4VGOlj5HmQ7WA1OSrDjPqIqVQmmg/BV/6MgitDIWm9HKIjZlJiRH5awDdTL7neAUN70OtFlJ7N741TtT+PPp2KRyGMFp9yx0oNg4yvsXLxgtkG6Pm4WI5wtUeVQOOqe+n78gGW9HkPP1h2F2V4WQ1n43NBjeJkYKalGmgTwLrg== 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=SjVkBaURuq++rgBcyk7gBPfCsQ7UmQ+UrK8PCAQLaSw=; b=JmCY1IP2yi8Up8gxWGTcOMTDftSEHDQ5T/j1+XvqYvqtqq73IR6xNIDpSbfvzgXqDkSCODEmCzIperCPDwOLexfiHpO/oJRcXmEPVRCqJySHPB8klkWV5Up7ZySFIzY3yLOJqQumGzUwk7vs9FuzIkV8PjMgfmD8YGj55wYmDURvS5H78eIyGZThjpwQpi150DJX93Zv0PxqF9cEq0yttUXBNlB17qRBpvPiB7/fTr4rq2BI6sSqNwQEsN5CoF7t6Thx6M9IseXfjj4Z/zjuq/tmvZjeXsWj1mKvEU48RV4tz9MDRxDpU2CH4woaaxyzSmC8OpXKODgeyGT42igyig== 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=SjVkBaURuq++rgBcyk7gBPfCsQ7UmQ+UrK8PCAQLaSw=; b=YRRnvDN7lrBGDpAUnghutQ/R/zOJuogqr/3aurQufHE4G2h/WN7dJ4i2wg1etf1lSviGrT5ZThkaLQlsbX5ric7U0f69j/geLKHEF/gIRciZwkHp4PJOLIGuzsqsDL5KcJFoY0kjtzh88s1lycZ5ngmJufAMvdEzUh6STTO5TNI= Received: from MW3PR06CA0019.namprd06.prod.outlook.com (2603:10b6:303:2a::24) by CYXPR12MB9388.namprd12.prod.outlook.com (2603:10b6:930:e8::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.28; Wed, 26 Jul 2023 11:02:33 +0000 Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2a:cafe::70) by MW3PR06CA0019.outlook.office365.com (2603:10b6:303:2a::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33 via Frontend Transport; Wed, 26 Jul 2023 11:02:33 +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 CO1NAM11FT060.mail.protection.outlook.com (10.13.175.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6631.29 via Frontend Transport; Wed, 26 Jul 2023 11:02:33 +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.2507.27; Wed, 26 Jul 2023 06:02:31 -0500 Received: from SATLEXMB03.amd.com (10.181.40.144) 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.2507.27; Wed, 26 Jul 2023 06:02:30 -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; Wed, 26 Jul 2023 06:02:28 -0500 From: Nipun Gupta To: , , CC: , , , , , Nipun Gupta Subject: [PATCH 1/2 v4] cdx: add support for bus mastering Date: Wed, 26 Jul 2023 16:32:19 +0530 Message-ID: <20230726110220.26486-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: CO1NAM11FT060:EE_|CYXPR12MB9388:EE_ X-MS-Office365-Filtering-Correlation-Id: d2ed6e4f-2ca8-413a-de8f-08db8dc7d037 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VPmRTZTeQVO5CJ5FWVcdF4qlIJnLnM65eHPsvQgJj9+gmOQuEY9uXlciURhP9xKYWEsyq5/mcfurY2OPzxX3oOh31411QGnRJTg4QX1bTrFnFJPly0NoTYU5pfas1oWI2WlAwIAfMjPUjgQ71bJ00GMpfnkJwfi6TjbOlBZtc/gyI5vSLBGUJ1JB6uiynM/Xy18V74pqnVH/I5xji0LjEFGYUcjEnDgGdGM+jECxN0LCnCQ2AAgCuq56cCTtYjJv5ucgSG3MEmk+jUcUQoQudZZIauSWP+iaCuXl2de0uw8A13sndcbWILm84Xqch2I6BTfqmqFHqKXDncrKIg3v9Rp5/jZT5GA3DKBq89qivZmz7dV1rKjes9Vp7wp9J3/oP2hOIYksiwiQxELui3YWQoBiSDLVLl7aKOi3lXV5Pktv/c39sIHTn+B0R4UwBhFHtbEzs3lFjd41p/rQkRZgoEUrnYCEK37byrXz1bpsKObdzcWalWHL4zqFQ3OMkE9yHROhRjMA1W7kFs4uDqm1DWgcy1DgcX9KqAfm/HpaXbDc7EGtc3FJospZtbQhPJgf+6IRh2+TcW/wmY8mYFMpgh6wDaJKt+cW8xG+k0G7CXsAZDvIAhr3ugaeDWO1MjKin+EU78Wik1H/eEMWXPIF1q2qZC8BtrrA9Z8bKX3+22uPLgRpIsEWeUgsW8wVh8kAM3rVlLgH9lBglFiq+lXCPrMU/eE+NT4KoGVpYXysBXdi/WTHwhqf/kkWZJMmR/hOVKSzemh8YGjuKDb/HDfI7Q== 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)(346002)(39860400002)(376002)(396003)(136003)(82310400008)(451199021)(36840700001)(46966006)(40470700004)(81166007)(1076003)(47076005)(82740400003)(2906002)(36756003)(356005)(8676002)(426003)(186003)(2616005)(36860700001)(44832011)(26005)(40480700001)(5660300002)(8936002)(83380400001)(40460700003)(336012)(4326008)(478600001)(316002)(6666004)(86362001)(70206006)(54906003)(41300700001)(70586007)(110136005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jul 2023 11:02:33.2669 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d2ed6e4f-2ca8-413a-de8f-08db8dc7d037 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: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYXPR12MB9388 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_NONE,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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772486051748066358 X-GMAIL-MSGID: 1772486051748066358 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 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 | 29 +++++++++++++ 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 | 16 +++++++ 5 files changed, 120 insertions(+) diff --git a/drivers/cdx/cdx.c b/drivers/cdx/cdx.c index d2cad4c670a0..10c6281b59c3 100644 --- a/drivers/cdx/cdx.c +++ b/drivers/cdx/cdx.c @@ -182,6 +182,35 @@ 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); + +void cdx_clear_master(struct cdx_device *cdx_dev) +{ + struct cdx_controller *cdx = cdx_dev->cdx; + struct cdx_device_config dev_config; + + dev_config.type = CDX_DEV_BUS_MASTER_CONF; + dev_config.bus_master_enable = false; + if (cdx->ops->dev_configure) + cdx->ops->dev_configure(cdx, cdx_dev->bus_num, + cdx_dev->dev_num, &dev_config); +} +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 lbn) +{ + MCDI_DECLARE_BUF(inbuf, MC_CMD_CDX_DEVICE_CONTROL_SET_IN_LEN); + u32 flags; + int ret; + + /* + * Get flags and then set/reset BUS_MASTER_BIT 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(lbn))); + if (enable) + flags |= (1 << lbn); + + 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..1816c279879e 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,18 @@ 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 + */ +void cdx_clear_master(struct cdx_device *cdx_dev); + #endif /* _CDX_BUS_H_ */ From patchwork Wed Jul 26 11:02:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Nipun" X-Patchwork-Id: 126310 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp364379vqo; Wed, 26 Jul 2023 05:26:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlGEfYSRyLiYD5LhukgHd43zfaD7SQxpG0tvIpTmWJbaAZVK0OHtxVZjyQiylA5i6ahfQf6C X-Received: by 2002:aa7:c6d8:0:b0:522:37e3:74df with SMTP id b24-20020aa7c6d8000000b0052237e374dfmr1303793eds.28.1690374387167; Wed, 26 Jul 2023 05:26:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1690374387; cv=pass; d=google.com; s=arc-20160816; b=Fu+zVgATJvoPW1NbhJFdWc9v1LqnKnQsHSa1IQjvk+CwyQIzl724IJ2RfFZMjHUqIx Utq4A+dq3CqJYYFTllJQIeesthk6p9nAyVqnQNP8njvbEQZDo7sWzg2baKUEpMVN2cmd zVdjWUEIWYQtRplcZxVAFZP9IXFlJdFytLh/Rnnuk3t5U1MYwMFbjkTTfOlySE2l9O9X PZUE70op4TCVFXgrpfTqA5lsBEpp/vSs8oHvaodPCqf6NALBG3thVMoHZeE2xZSwB4K1 z+HEcOvhWwwo/OHycT7Ry1ZdDJS59j3bIVbqX5GmClpeDHkPNSbCDfTX8NO+Jxna8hp3 mF3Q== 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=DZIqtYtIIOO+rcD+PHQDo/jy9dGKQFJllHRCMeBjJwM=; fh=tJDGlZlaSCi+XrMbzD8P6ISxXPUqdHJUGabWidOy+gE=; b=TYQYIO29PMik1x5SKdiyodzJO3puiUXJioCtmi5BCWmHEucbHUyjSHCX6Qa4hlZash popkhxS3ziMFvG82qpFJH5/Eh6tBpzqhXwse2Wnaiqruzo6k08s9Frl4Gm2w2SrR8fS+ qqgnKhkE39nlxfzXaqgbXR8xna7mqkq3Pcj6hJ1hM8MHGikJBD+GIhr3m592PmQRSwEV trl7V8gKNxvN8+ji+HcyCESyR7Dpr8g6NKPhZlytsE/jAZkr3tEtxoax6woWB1jmlORb FkfGpxXUBvQZJ7BWXWX+RvzdPsSLPL6CguCyUgc2CgUkSgu6MhAoqWlSrSfM2y9XZcTm 4PQg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=v4Nv++cG; 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::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h16-20020a50ed90000000b005223cf54192si3184613edr.188.2023.07.26.05.26.02; Wed, 26 Jul 2023 05:26:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=v4Nv++cG; 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::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233856AbjGZLCw (ORCPT + 99 others); Wed, 26 Jul 2023 07:02:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232922AbjGZLCq (ORCPT ); Wed, 26 Jul 2023 07:02:46 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2050.outbound.protection.outlook.com [40.107.244.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C05A132 for ; Wed, 26 Jul 2023 04:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TGZ5YIlkVyGnGgk16NrjgRSQo4zu2XPhyadHXFouzk5jEGp+l4pGNmrXFfd09J5fUC8yCPvLGs9N6xaGZ5piqLea8o7zsTU47wG5Gesk0UnS4g33+c2ERJlkIZI7HlDyiJm7mmiax8QFvsjwzaOYecX0Nq1qkQAsmJA7+gwQXoKkEjqHlSy41fKzmVhx3Vsrxt2A6EuH0ZRHrGa1eJpr1IB5FfYMsYh0ZSx3gBZ0m55ODffJ3L87uazoNpMGh4BJ8XNvaBuZFaQQWhIPDkzcqZ3gaOCqKifEULwYNx/N8XDDu027aTk7RnllTnDJSCtoHiVv/zGKitU45bgjZRCQEQ== 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=DZIqtYtIIOO+rcD+PHQDo/jy9dGKQFJllHRCMeBjJwM=; b=Qv/HMY04FuXCZYC1rCvW839dw7BRtDUcDz8FuyIs6Hp81OcaqSc+t/pu8zXx6BuQ/tXYNRMaWRuTlpCU6H0XPuaK2b3UXsFanP2qwm/zWUsIRxXw0o6nEcJjm+hgtvPSNSFhkr5Fyachfqx3USwRtUdEG1aGFD1AwyY2oL/zGbPK6aZB+BwhGNub/HdQmpTT8bE5y1zxqD8AEwim0rWlj8El2vEgNxMzePAVuzO8K0GcNJhMwW8p6BiJf7aI0V0vHLtFoUudNaVenCj0wXtvjXVSVpFaWq+gu3TgH9+PfHIxUjtj8q58A8ZoHiEQ4MH/GZzGwnlE1/nP60nkF9UoPg== 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=DZIqtYtIIOO+rcD+PHQDo/jy9dGKQFJllHRCMeBjJwM=; b=v4Nv++cGCSqOnVJcbPtACwEVui8c4yI+A+eAzzDoqscDmRnjiB/1nm/Fvj6DqwO5KWG2YWBL0b9qeCX6sJf9K2jUGVn5LBanC/zJtLnUaawirHthd1SODmvYJ1SvB0W1s3osn4OYc0dQyEd5SgNjgF9fLqy0OvGwlVprt2ApVVw= Received: from MW4PR03CA0226.namprd03.prod.outlook.com (2603:10b6:303:b9::21) by MW4PR12MB5641.namprd12.prod.outlook.com (2603:10b6:303:186::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.33; Wed, 26 Jul 2023 11:02:41 +0000 Received: from CO1NAM11FT108.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b9:cafe::47) by MW4PR03CA0226.outlook.office365.com (2603:10b6:303:b9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.32 via Frontend Transport; Wed, 26 Jul 2023 11:02:41 +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 CO1NAM11FT108.mail.protection.outlook.com (10.13.175.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6631.29 via Frontend Transport; Wed, 26 Jul 2023 11:02:41 +0000 Received: from SATLEXMB03.amd.com (10.181.40.144) 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; Wed, 26 Jul 2023 06:02:34 -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; Wed, 26 Jul 2023 06:02:32 -0500 From: Nipun Gupta To: , , CC: , , , , , Nipun Gupta , Shubham Rohila Subject: [PATCH 2/2 v4] vfio-cdx: add ioctl support for bus master enable Date: Wed, 26 Jul 2023 16:32:20 +0530 Message-ID: <20230726110220.26486-2-nipun.gupta@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230726110220.26486-1-nipun.gupta@amd.com> References: <20230726110220.26486-1-nipun.gupta@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT108:EE_|MW4PR12MB5641:EE_ X-MS-Office365-Filtering-Correlation-Id: 38e985c0-61a1-4424-be15-08db8dc7d4ff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: p9FscsuZY2Od98uz2v2ocIprpjI6AMD3BZPMaRAGwHuckqzJb0PX7czUH5Igss/Zy2+WQsbhTpiUozFf/IpQ3U3F7WRJeKpJDu0pKARqieG9RFTk/SkUUibxzuC9gquGn30qt59QCxuXYFdSd7hz7en5I4su3LCc8dCXhunY2SSQSoi5CwJbeUg7xak3rCXMLqrJd3TcoL2RAopyWUuMNMR6gmqCVJFoWa97e31RnudKEE7aTkg4oK3549kz4tUtvIbbmBHxd7jr9ISrqUizdrIXZ+4EDT0Njd5RPOA16nLAF/BZksL0Wl6MxmzUOo1D2LknldlhgcM8oxYdPi8VdqgzylXA3R53g7cZ8ZSMLvRTH87zWLHnBo2rt/bNUnVjN9js0CjoVG89vikqI5J7kHilVw75XcGYXAjPS0NBc/c6/Sll5MwSmTUyXRConTMbXKIzTTcSn6Di68AndDM7KAT1J65V9YFZIQ1yj52Pykg1aDIieJbMniztRfB/Kfj42VjwBkRl3kplyZ3DGLsqU2CXsdF8qbZvGoFpp/gU5c1BeyYw417J+YiwVucuNqPpOPwT0Bxtw3Ch8N+BQQz2Q4DWMG3ZHcTAS9GIfYEDupmfUx3194zYlXIpbbZhg81BZsePBcku/NWPAqtj10BaCulifGGyQ3lmnuv+5BfubvCk54Uop48BeuSn01lnn8hJRi4oFYW2Ih2YdnLHS891/2G1DgDWibq1iURlsDmn4xtHSfS+/sDqxW6q1H2qyJXaU3UKxqoddr16Ij/r0nDyOQ== 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)(136003)(39860400002)(396003)(376002)(346002)(451199021)(82310400008)(36840700001)(46966006)(40470700004)(26005)(336012)(1076003)(2906002)(186003)(4326008)(81166007)(36860700001)(356005)(82740400003)(426003)(2616005)(40480700001)(47076005)(41300700001)(5660300002)(40460700003)(70586007)(70206006)(44832011)(316002)(36756003)(8676002)(8936002)(86362001)(6666004)(54906003)(110136005)(478600001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jul 2023 11:02:41.3033 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 38e985c0-61a1-4424-be15-08db8dc7d4ff 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: CO1NAM11FT108.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB5641 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_NONE,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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772486013330249986 X-GMAIL-MSGID: 1772486013330249986 add VFIO_DEVICE_CDX_CTRL IOCTL to expose control operations for CDX devices to VFIO users. Support Bus master enable and Bus master disable on CDX bus control. Signed-off-by: Shubham Rohila Signed-off-by: Nipun Gupta --- Changes in v4: - This patch is newly added which uses cdx_set_master() and cdx_clear_master() APIs. drivers/vfio/cdx/main.c | 26 ++++++++++++++++++++++++++ include/uapi/linux/vfio.h | 14 ++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/drivers/vfio/cdx/main.c b/drivers/vfio/cdx/main.c index c376a69d2db2..c39a965716f4 100644 --- a/drivers/vfio/cdx/main.c +++ b/drivers/vfio/cdx/main.c @@ -98,6 +98,30 @@ static int vfio_cdx_ioctl_get_region_info(struct vfio_cdx_device *vdev, return copy_to_user(arg, &info, minsz) ? -EFAULT : 0; } +static int vfio_cdx_ioctl_ctrl(struct vfio_cdx_device *vdev, + struct vfio_device_cdx_ctrl __user *arg) +{ + unsigned long minsz = offsetofend(struct vfio_device_cdx_ctrl, op); + struct cdx_device *cdx_dev = to_cdx_device(vdev->vdev.dev); + struct vfio_device_cdx_ctrl ops; + + if (copy_from_user(&ops, arg, minsz)) + return -EFAULT; + + if (ops.argsz < minsz) + return -EINVAL; + + switch (ops.op) { + case VFIO_CDX_CTRL_CLEAR_MASTER: + cdx_clear_master(cdx_dev); + return 0; + case VFIO_CDX_CTRL_SET_MASTER: + return cdx_set_master(cdx_dev); + default: + return -EINVAL; + } +} + static long vfio_cdx_ioctl(struct vfio_device *core_vdev, unsigned int cmd, unsigned long arg) { @@ -112,6 +136,8 @@ static long vfio_cdx_ioctl(struct vfio_device *core_vdev, return vfio_cdx_ioctl_get_region_info(vdev, uarg); case VFIO_DEVICE_RESET: return cdx_dev_reset(core_vdev->dev); + case VFIO_DEVICE_CDX_CTRL: + return vfio_cdx_ioctl_ctrl(vdev, uarg); default: return -ENOTTY; } diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 20c804bdc09c..5f6a58f9f8e2 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -1649,6 +1649,20 @@ struct vfio_iommu_spapr_tce_remove { }; #define VFIO_IOMMU_SPAPR_TCE_REMOVE _IO(VFIO_TYPE, VFIO_BASE + 20) +/** + * VFIO_DEVICE_CDX_CTRL - _IO(VFIO_TYPE, VFIO_BASE + 21) + * + * Control CDX device. + * Variable op is set as per the operation required + */ +struct vfio_device_cdx_ctrl { + __u32 argsz; + __u32 op; +#define VFIO_CDX_CTRL_SET_MASTER 0 /* Set Bus Master */ +#define VFIO_CDX_CTRL_CLEAR_MASTER 1 /* Clear Bus Master */ +}; +#define VFIO_DEVICE_CDX_CTRL _IO(VFIO_TYPE, VFIO_BASE + 21) + /* ***************************************************************** */ #endif /* _UAPIVFIO_H */