From patchwork Thu Aug 3 14:32:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Nipun" X-Patchwork-Id: 130740 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1280762vqx; Thu, 3 Aug 2023 09:59:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlF+nBO/FzlvhA4vXkuIVlFD5RHTzpuWd4pO7OtP6v+lVo+pTjRLU6Rf+8QmxmwzW1UTqbJL X-Received: by 2002:a17:90a:d48d:b0:267:fe4e:392f with SMTP id s13-20020a17090ad48d00b00267fe4e392fmr18695231pju.39.1691081946841; Thu, 03 Aug 2023 09:59:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1691081946; cv=pass; d=google.com; s=arc-20160816; b=xsApoubevjU52BMrM39oJ/QhZr/XuHJ1XwLaokHOJkvDl+7E4+JFKPZ+xjJpU/74QG uqrdwFPCLYCXS9mo5yyMKE8o8mZqIjjYdLRPmpO41XhAG5aaaG1soTQR+afzPMuhY+Nm XCGgrMVcaE5tYDcliOnoyItX0zDeKBWyB4+5pgCfsIu4VugZaMYTXP5Ey3tzIvOtlZJP pqTiwh2ZUf5RChzXvV8jy2l2Jc3X44v6SGEEhyDaz1tRgz1Xhx2lRzq7kWceanKxmZWR 5camKN+38c6ZFUoENqx/h3Dtq60z3WFbOQuQ2m2q/aLNaBhoKbzzbqo6rewubyrHfEp9 V/Lg== 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=prxRzKnebEJ1ovhNzL9vipTjlItl5tkrLLekj391SAY=; fh=Ni1nsrg1oOMllulTte61KVXg/7l8962UlCxeEssxYck=; b=FHm21AlqK5/db+UobqB1lMNJGpa6y4vZpZwoJC00dt5SGqJwWVBwnCFeGvUQBwel4A 2h+ieWrP//soV4Lx3In2euUPVFb4DkL5vg+c71KeeDEc3vFNLHNvbLb/QJ6y4t8amOqc yPeDORi2dKYHMN2wHKOzCJ9QvadHS6bfA8I+FtGf4Y1i3OlPV+trGEa52D0x5Kmog36x b9U6G2LYH+h1vLgp3CXw+9gJwNyQT9l9yIQlJcHi/Vo8JlMSKviiLT9OHXDvnzSMm3VN eecqb/1L37f22QOCuEhPHA/6SGnSNNzm9pSvVdK/5vQCAqXSpnwp5KxILowbQFFGYyxr uI9w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=C5+cNPzm; 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 k1-20020a17090a910100b00262c146b8cesi3486588pjo.158.2023.08.03.09.58.53; Thu, 03 Aug 2023 09:59:06 -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=C5+cNPzm; 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 S236682AbjHCOeF (ORCPT + 99 others); Thu, 3 Aug 2023 10:34:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236593AbjHCOdx (ORCPT ); Thu, 3 Aug 2023 10:33:53 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2081.outbound.protection.outlook.com [40.107.237.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CE0BF0 for ; Thu, 3 Aug 2023 07:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OuRznBx0D+3AYRHSbB8UpzqDF4f7tpRINqSchwUw+/rbOQF6ZY/a7ZJJs2W4BsbrCQgjYkYDNsPVK0Go21vlP9FQGGibK53ywuR5TB7cI7Sq78e6dqXkGt1T+3Kz2qgOiuKUPT+vgwpuyToDoKoftJAx3b07Ab0wiwIdW7MoQfulyNBvbhGG1Y6qq30PZlDhc6s25tN6In7wlMd6HD5NY3t+Z13UfUStXNIrWNbGIo9SDTCL6xjvf+bSf+6CAvOtUy8er56cx65vPdl9gpVxU49BmckxCh8UwxOleBfIRMdaq177cQcR8yeTjL1NZHkOLlk4bhCA+Yp1MBl7BBjYHg== 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=prxRzKnebEJ1ovhNzL9vipTjlItl5tkrLLekj391SAY=; b=OrlTB0BriWywpBlFG6tbIp3kTTHXK3XzVlVDlrzW/mJ6qwsYcn2wn1+FNdd3naK5gio2WQMlb8IBLoQgqL8X3mjh3hMlcLnShEbYvEQL4+u1G2bcHY0J678ON24UOoeKQA8/PC0DfmbFpyDbyTYMRqduX6YFbeI92N4ftOteXoPITXuK/f72GvVtBdCXMMp3TQa6ZR7eVfu3e1ondXf/1jWHtKmxRKXgWPfQ6HTeeNpqW6bUaJxEXe12F8+DX3kLiIKBfPOsT5d8eP4Sf6l2BQC8BcK/t54I5PfIcmC66FLKjsceQIUI2nDmzYedgDDZ/LAfMNHdWl+Lot0KnR5q/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=prxRzKnebEJ1ovhNzL9vipTjlItl5tkrLLekj391SAY=; b=C5+cNPzmO68fW6ZOV2kFs1JWDdqXJveUDcfqwv8WIafUQhZAS3k0FojzXIApKvhkEcsNE1LBr8xLLzjeK2nf/FRGD73OuognYNdGS1ktj9z9wO0L8Iq5mPJYZoMHvZAnCdDmGyDdWWjAdNCKKlwKQndDtNxYc+h4YWZPiCQjafk= Received: from CYZPR11CA0018.namprd11.prod.outlook.com (2603:10b6:930:8d::27) by IA1PR12MB8495.namprd12.prod.outlook.com (2603:10b6:208:44d::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.44; Thu, 3 Aug 2023 14:33:00 +0000 Received: from CY4PEPF0000EE3E.namprd03.prod.outlook.com (2603:10b6:930:8d:cafe::e2) by CYZPR11CA0018.outlook.office365.com (2603:10b6:930:8d::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.20 via Frontend Transport; Thu, 3 Aug 2023 14:33:00 +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 CY4PEPF0000EE3E.mail.protection.outlook.com (10.167.242.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6652.19 via Frontend Transport; Thu, 3 Aug 2023 14:33:00 +0000 Received: from SATLEXMB07.amd.com (10.181.41.45) 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, 3 Aug 2023 09:32:59 -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.2507.27; Thu, 3 Aug 2023 07:32:58 -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.2507.27 via Frontend Transport; Thu, 3 Aug 2023 09:32:56 -0500 From: Nipun Gupta To: , , CC: , , , , , Nipun Gupta Subject: [PATCH v5 1/3] cdx: add support for bus mastering Date: Thu, 3 Aug 2023 20:02:51 +0530 Message-ID: <20230803143253.7817-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: CY4PEPF0000EE3E:EE_|IA1PR12MB8495:EE_ X-MS-Office365-Filtering-Correlation-Id: b90a0ecf-bd2a-49ab-60fe-08db942e89aa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZK4YajgBI2zVgd3IL8O1Kgx7L4ra/K9OkB2Ve0NRlb8vrMYAhNQRbPk7pNBA/i9egziVfsmQM+vL+Q+i9qtxaV1qNBhd0a+aRcC8766tEs0YdMiUWSazmXfD35/KDxGVnPunxPc2sEJRlB7gMQ4i9nXzh9O/rrBzIV5Juw40tu6f4JiaeeRxrGA6KvGDUXWHFtBERh4D9jumFpOGKnzt5k8/gkZHtZ3k2DQk3qvgbZnw4X8mDb/6QcT+V/JTjWn9H9ObJoJ2gMgNggd1z88A8bIXtwZJM5KGawh8jxnAdDmTRf1ppHvQeeILWJELLlquYt4hFqcrKQOfub4KWcaFKXyghyojglB80Uu5dOTHspVgUhvifliQXfqGIFIlOCeNAFhNgdlMwSYbuId85xAM83SNeGc0rm6+qioqZHGb7MYOVEKzri7CaAP7IWQixuYNFtRCouXoGmsP9Pcy1cucsGhcKOvKUDN776alIFoqkhSh0eAr4D67Wzh975x+Js73xguNTRaz4GwHsuyfru7WFBX2XQYuauSD1xj+luvfTsI1vaBVKzK9k7ocxW7XU6bgMb+vFX/Gn3h65aTbl3tGwtCffSIBwW0n8Vh8L/93CkLAY7z0EqP1/CgSv3k8eZa4CmU4iYkUm1RsRlzvfLVYui1Lg0zDpH1hnWrM12KAwems5mqlWnX0kQdn7dqEBjcv/NSbejGnNoId65NRLVPczxGmwegeJX4iazq4Ms0hUb3j3z1p74Mz7pR+9segAZobJRHkYgB/pq+dJknkv6PmgA== 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)(396003)(346002)(376002)(136003)(451199021)(82310400008)(36840700001)(46966006)(40470700004)(54906003)(5660300002)(44832011)(478600001)(82740400003)(81166007)(110136005)(6666004)(356005)(40480700001)(8676002)(41300700001)(8936002)(1076003)(26005)(2906002)(4326008)(186003)(70206006)(316002)(70586007)(86362001)(336012)(2616005)(426003)(40460700003)(36860700001)(83380400001)(47076005)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 14:33:00.1014 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b90a0ecf-bd2a-49ab-60fe-08db942e89aa 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: CY4PEPF0000EE3E.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8495 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE 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: 1773227943439685331 X-GMAIL-MSGID: 1773227943439685331 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 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 | 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 Thu Aug 3 14:32:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Nipun" X-Patchwork-Id: 130742 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1281102vqx; Thu, 3 Aug 2023 09:59:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IESZRta3N/VgJDa9YYZuZ4P7rZJDiyBfl1HwKnW22yQIKkf8ezIPZVwkrx2idi0+u/c01Kz X-Received: by 2002:a54:4e94:0:b0:3a7:7366:7526 with SMTP id c20-20020a544e94000000b003a773667526mr865786oiy.53.1691081988818; Thu, 03 Aug 2023 09:59:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1691081988; cv=pass; d=google.com; s=arc-20160816; b=i1NTrX+vJ5rqE8QR9UZbaJt5M5mTUjKjtyjLLC841Sex5kSomXsPy4h3kiNbC/3JHx fVEkvqWrfJdEKI9iMj0sTG/NBLrrEYCMS2FZtJLAH/1EccBhHs4Iqp0zT5d8uvE+lbPX QyOjGp51z6jkpvQYiqscYuUilHVXUphmUaEYiOBWxFgzpBSSMBpA1eF32ZjOC5nzFQpY DGBXl1J12JGW60v6nbh+A3jqOr5mYBkSPiby42CDDs0+fvkW0zZ1OCcrNKBih51bsR5X gG1GssrXmeFkPtKNjidAmcLHRUI/UxuBdJuZ9UCZmBrk6d0ihQuQwlKw3wRUsGW+cff9 HdOg== 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=nidXFovMwXMY+ljbF75xsPQS2gch+qdQ7STt1gVt8oc=; fh=tJDGlZlaSCi+XrMbzD8P6ISxXPUqdHJUGabWidOy+gE=; b=mEPnti65oNchSmB/qRqg9TUr4md+pFuzPlRX+szh0TkoWCu/nYXWC5jMIwUOts+SnJ eV4KIvyI4mJcrFI7xNE6Xvpp+++3vlPDTFnhbayh2TgFR0s2Yc6m6H1gzRQfQ4uLXJ7k i7W+7Ib700JlQEhdlI0o1GGcHWF/nUxlCI/c+1WTph1c177lw7l1qdjUwzzNV7ntGWlt CMHwfssYvqde++MhyGepRt1PFUD/mrhqcyizEGswMQMZYP4409ghnqrR6Cyj0QGP0i4W LhUFte3+MK8g+b64+jFbzSy8j9aZwtUsSyksRbCgcOzShVviPkhIHew1D/9A2ATMIcAe L6Bg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=L37UKtaU; 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 r20-20020a6560d4000000b0054fe7b18671si147524pgv.809.2023.08.03.09.59.34; Thu, 03 Aug 2023 09:59:48 -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=L37UKtaU; 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 S236593AbjHCOeJ (ORCPT + 99 others); Thu, 3 Aug 2023 10:34:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236683AbjHCOdx (ORCPT ); Thu, 3 Aug 2023 10:33:53 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2072.outbound.protection.outlook.com [40.107.220.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E55402D65 for ; Thu, 3 Aug 2023 07:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J+dAAl7BqGyCHrgUvVciv+3PUwquG3Y9shzUbe0vZ4F4OLZB5ihl9R78FbIQPZzIK3+kN1t9SVmyg4MJL77syjFJnMnHV2DrhMBJq/iPwyVhOZ7ll9Vx+uhJA190n5EoQz/7tUP4mkWCIxwD5w7xBnb09dBYzEfkZhv4pJ1x0AZgZ/wJQ7TXKCinwXwDheSQgaQkZh62SL64lJdTuiAoPsNMFOyu9Ffw6Ftzn9Fx6OxUlNJWszWVBaYT24W6vjPZTuiAe/PcnMCE6sXa8S8lxTgRlIeDZrso93BxSSRhLtLBKvXrjOYnFZlcqSlTJwKDTddzvPki3qEdQ/Q/ftATyw== 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=nidXFovMwXMY+ljbF75xsPQS2gch+qdQ7STt1gVt8oc=; b=nTaBwSePPO6iKOrTosFiIa6FTktxs/oqIfSM1x6rMc7v3+efJ0GNSMyv9LTxbOPquTER0JZyx7DPCsi1ineVGjffg0qm4j1rRhXY3ETb75vmK4lnM0zLHakdf/j/kH1LxjZDGPp+3AzZLLuwewkvLqmZW3spMS8l2Whop0Oj8Sw5uLYLdqE/8MQdMTTKkttA2qK4TL1YiysMy18D1tlrH1rBfca05u1AreKzRq2eBoDLUxi6AEUPA/W9iEsV4sNQQ2kP+5Nl4lP68nLE8h/iyXmVrvec2PlV0bRkCoQyL/QntuReO0+eIbLyoR7ZdhOUL8j1jDQWsx1Nywc3S2CAkg== 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=nidXFovMwXMY+ljbF75xsPQS2gch+qdQ7STt1gVt8oc=; b=L37UKtaUXrKR+xazpA/7KLXp8J+Y14Ppcfo8L+Kv0QrztRbvaz6kjhPp5UTFE4l1LV5VBbwtdqgTxlLItt7AGnf+Sqtk9leNToXJSi68KsxeqRoraw4eOQ847uy/0/8whcUqRERdATS9KXm29KrJDHZbAa1ojLaBoFRjXMOgCpU= Received: from CY8PR11CA0015.namprd11.prod.outlook.com (2603:10b6:930:48::21) by BN9PR12MB5113.namprd12.prod.outlook.com (2603:10b6:408:136::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.20; Thu, 3 Aug 2023 14:33:06 +0000 Received: from CY4PEPF0000EE3F.namprd03.prod.outlook.com (2603:10b6:930:48:cafe::6c) by CY8PR11CA0015.outlook.office365.com (2603:10b6:930:48::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.20 via Frontend Transport; Thu, 3 Aug 2023 14:33: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 CY4PEPF0000EE3F.mail.protection.outlook.com (10.167.242.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6652.19 via Frontend Transport; Thu, 3 Aug 2023 14:33:05 +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, 3 Aug 2023 09:33:03 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) 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, 3 Aug 2023 07:33:03 -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.2507.27 via Frontend Transport; Thu, 3 Aug 2023 09:33:00 -0500 From: Nipun Gupta To: , , CC: , , , , , Nipun Gupta , Shubham Rohila Subject: [PATCH v5 2/3] vfio: add bus master feature to device feature ioctl Date: Thu, 3 Aug 2023 20:02:52 +0530 Message-ID: <20230803143253.7817-2-nipun.gupta@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230803143253.7817-1-nipun.gupta@amd.com> References: <20230803143253.7817-1-nipun.gupta@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE3F:EE_|BN9PR12MB5113:EE_ X-MS-Office365-Filtering-Correlation-Id: b9727572-906d-4348-91c7-08db942e8d2b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rYiQwqdv5IjdMzPCM78JvwTipCZIw9YRyhQ1Sh54UZR67Jhfocm2eYo7TmnAO4YtIm0U9Q0CPs137BRNNJKGtald/Rc2q8m27ddHz2JaklA/FXwoPa6sB2Kyyj378kn0Hm+xqLRNEU9HxXpe/Jtc0aTgpWQWKxvy2i/F2ijPhx8UQg0AWPWElqp6M26NXNGNFpiRpFej8QwgRA8RUIyHkYZKvFnm28nXLuigu7RCJZrDnSGrEh7a5vhisurMWD8FzxMRLLHo4tsYuZbkg0MyNsJswQCSqH4Bzt0QeI5yd91KNy8y7tD0lHuuAzqkjaStKO0QDkclJQoTfi3bVqrilMZSZ3a+OoewilvhkrNe+lrSi/1VULuVnqZfm499CYRtypR7d/0s5Avd3vzUV/h3TvfworZONTcQW0LXuZWtdi47nlTm+sB/6eJoiYFdH0iWnC3lxPL4v0lh3ipgToKx3NJV/URUk5lHCNPXoCnoo8tq6f+aErVzbysaDyz6Ys3Km1HI4O7sQHgcKmqCroKLcCAWbMMAI7Auyj223B/we8luZm+ElzYGfaXjTJ7YqaOCwDFJk9bGhGFP+pTG0/4nHO5oFBjXOg1gpa0uaGb9TMGaHQKTbSY8hBOjJMJQ33KU7/cMFJTigwIiycwBAMSI30Z9H7e3kX5ghYfHbue0RqcfjBoBQkwAGsP6cIPknCUVyc2t+C4ZnunG+JBFZLmXlS63AAb2DI7brkXX3PRaQjzd5B36grWW2rkiBQlOGnFYzXCl5lSxhwdWQltpzPJpaw== 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)(376002)(39860400002)(346002)(396003)(136003)(82310400008)(451199021)(36840700001)(46966006)(40470700004)(36756003)(86362001)(82740400003)(40460700003)(40480700001)(54906003)(478600001)(110136005)(356005)(81166007)(47076005)(1076003)(426003)(2616005)(83380400001)(336012)(186003)(26005)(8676002)(8936002)(44832011)(41300700001)(6666004)(36860700001)(316002)(5660300002)(2906002)(4326008)(70206006)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 14:33:05.9812 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b9727572-906d-4348-91c7-08db942e8d2b 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: CY4PEPF0000EE3F.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5113 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE 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: 1773227987502081238 X-GMAIL-MSGID: 1773227987502081238 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 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 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 20c804bdc09c..05350a2f1eab 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -1287,6 +1287,22 @@ struct vfio_device_feature_mig_data_size { #define VFIO_DEVICE_FEATURE_MIG_DATA_SIZE 9 +/** + * Upon VFIO_DEVICE_FEATURE_SET, allow the BUS mastering for the device to be + * set or clear based on the operation specified in op flag. + * + * If the BUS MASTER of the device is configured to CLEAR, + * all the incoming DMA from the device will be blocked. + * If the BUS MASTER of the device is configured to SET (enable), + * device would be able to do DMA to host memory. + */ +struct vfio_device_feature_bus_master { + __u32 op; +#define VFIO_DEVICE_FEATURE_SET_MASTER 0 /* Set Bus Master */ +#define VFIO_DEVICE_FEATURE_CLEAR_MASTER 1 /* Clear Bus Master */ +}; +#define VFIO_DEVICE_FEATURE_BUS_MASTER 9 + /* -------- API for Type1 VFIO IOMMU -------- */ /** From patchwork Thu Aug 3 14:32:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Nipun" X-Patchwork-Id: 130738 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1279017vqx; Thu, 3 Aug 2023 09:55:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlHbthxLASKfbP4dqDbyE8rwS8ByZwUt8asHIXk+LYvoC5111FjpHJ5GXT2dawEBYwqgpj5Q X-Received: by 2002:a05:6358:5918:b0:134:e777:c78b with SMTP id g24-20020a056358591800b00134e777c78bmr10193276rwf.5.1691081741476; Thu, 03 Aug 2023 09:55:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1691081741; cv=pass; d=google.com; s=arc-20160816; b=syn2KCIFnpxVSDZ/U4szW6gHUX1KgeZKmv7NQtjwDF4LTixTvqhM6DpklMkKwSRae8 9BwzBmKI71S0je1NUgWJy7k6W082jbANMaG17HqNAWmHFftTg6LDKogkglZY6zK0zpPh jfnpslWymaO4RqNy2M/LwDU6N3qNt7Ll3efpJddIZme6B1gT7uJK170mCxYdBjTjEgHn ZvgE4ggaXWPuZDiRvxzfCTeUAM5EYL4whcbTh1sjyHzICKUFOGwsLwetRwNDEVKCrj+h q9WGV20gECnFAPamRQmmK5p0SJucbbO1r7j9nzt8g16PYd4hy+TQMkr7XNHuqcFGFdeQ kAqw== 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=L4bwOTGjojPmDtBETmBHZsBQZ7TjvY8a1Tqeo5zAv8s=; fh=tJDGlZlaSCi+XrMbzD8P6ISxXPUqdHJUGabWidOy+gE=; b=xOoBXzWHzoGizH9xlNUcpRL+wWnRw2Kb6VXrwikR2rgf9sAFJndZxGBxJhtWfKwa/p Jfa/Ia2j14hXn+OxCNmAl1dgNwTxjwr99Y8k1wxW4ipCtnLj9tO7c1toRQM7IoW6LVSz hpgPRqq9XA8V/Pk6MS+B+kLlblDXwxAIdwXiw0l2usJf/qRo3VTXLGvCW2SMzQoSgkd0 VMIveVbsD4zCkroGLFkMXurk3OQXW4Z5J2HzLALeegc9CqhihqUZAMwMxENBshcXaB4g Ao6SX2erh5p/AQkU7z3wjoApoQkXSioykaQOkkAiOo2d8zSTLgMTGMQujYssWKtp99Pf fiqw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=TEK4A+bd; 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 x3-20020a636303000000b0055ace8caef7si155102pgb.610.2023.08.03.09.55.21; Thu, 03 Aug 2023 09:55:41 -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=TEK4A+bd; 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 S235359AbjHCOeL (ORCPT + 99 others); Thu, 3 Aug 2023 10:34:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236310AbjHCOdy (ORCPT ); Thu, 3 Aug 2023 10:33:54 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2060.outbound.protection.outlook.com [40.107.94.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A55C30C2 for ; Thu, 3 Aug 2023 07:33:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W/guKlrzTnkZuixQkpfcakmt0SnXCctfr8t2jKf8FamPpLl12IR/qkVsrPaMutF5TOEvwKMen2oLMIXyWoodfHMcxb1IuRWDxP1x3GmrxjzY/f7VtSoaJruSzJtRDnYmZfDpHbE33wX/bBBBkm5S9KxbcuaihblilB2svVce8g1F30So3vV/rYKc8TS42bnA0W4UVf0A4Ni5h4s54pdo8zriFWYpMvP1adUEpqVbKUIhUhzV3MKFLmYXOGDT48j2q+XKwq07tmPDzVUx4ZZEWSa0DVKV+uJy7syRvQA0JDMrWVVlxyAo5KCx1BAZZoNZ46xb0Odo9s6d+1pUuSbk2g== 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=L4bwOTGjojPmDtBETmBHZsBQZ7TjvY8a1Tqeo5zAv8s=; b=VVSwWwXNLtY+sTtCPdpPocNXPSArbTk6z7UDsZOCuEnJ+VFyZdLMB860rszs4H+hCbWYRtma/YKUYmvkiAar74K5RUoznllYmQX3jTpQseb0Sj4bUDjql3tjzeg8cS2CXcSRpUQIksKstbpBPDpWXM06Hc8SCUOJnyARgKP/mSw2EHqiOWRFtV/AY6QSeVnmpjly53IqFwcgO+D8ORV3RQhZh2DaJuq0nJmBs/c7grME+2rVA3Nu8X8Ajw6/RDWhn3NnpIGmCwtuSgFv4fLvDkAXJGdDE6ZqQ9jFpGVZCAF3BfHpMOQ0RGGv5i85ERRQqRzD2TVqvcnHrOjT6S13ew== 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=L4bwOTGjojPmDtBETmBHZsBQZ7TjvY8a1Tqeo5zAv8s=; b=TEK4A+bdRnTryfG+WeOU2H4UcjKnUHD4HuD++wW2nDjPViLFlzUTXjcbYZ5XYAtGo9GibxuQ271C/f+dC5Pee40Ka6z2XLE/mza+ziwYvY73ABHRpAfUrbzoSGKQ9svx8tGUL7OOoQ/mjCwiZW/EXOv1GHqP1iUvWtU0r4r34W4= Received: from MW2PR16CA0056.namprd16.prod.outlook.com (2603:10b6:907:1::33) by DS0PR12MB6464.namprd12.prod.outlook.com (2603:10b6:8:c4::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.20; Thu, 3 Aug 2023 14:33:08 +0000 Received: from CO1PEPF000042A9.namprd03.prod.outlook.com (2603:10b6:907:1:cafe::a2) by MW2PR16CA0056.outlook.office365.com (2603:10b6:907:1::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.20 via Frontend Transport; Thu, 3 Aug 2023 14:33: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 CO1PEPF000042A9.mail.protection.outlook.com (10.167.243.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6652.19 via Frontend Transport; Thu, 3 Aug 2023 14:33: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, 3 Aug 2023 09:33:07 -0500 Received: from SATLEXMB04.amd.com (10.181.40.145) 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, 3 Aug 2023 07:33:07 -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.2507.27 via Frontend Transport; Thu, 3 Aug 2023 09:33:04 -0500 From: Nipun Gupta To: , , CC: , , , , , Nipun Gupta , Shubham Rohila Subject: [PATCH v5 3/3] vfio-cdx: add bus mastering device feature support Date: Thu, 3 Aug 2023 20:02:53 +0530 Message-ID: <20230803143253.7817-3-nipun.gupta@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230803143253.7817-1-nipun.gupta@amd.com> References: <20230803143253.7817-1-nipun.gupta@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000042A9:EE_|DS0PR12MB6464:EE_ X-MS-Office365-Filtering-Correlation-Id: e5fd247d-6a4c-4d6e-5e43-08db942e8ea3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AootwSpsHvNz4dt6+OVpx5j4GTuhPzP6untd9Lzm6jdr7KxCstjZvEenYVCMi/xo+coqm7nJtUsbkSbm9q/uWuhnsIfDEkKwfl8Jtn5XZimcfBepFji4jZrO6G2uYnrzOgvnuQenuSWdTIJy2PoGhdh1bq2HR4/rsr8uJrYYG50FYyofk12K0SUyJTAZ2gVbu0FuS7jfqmDiGkVe9cVNX9l6miXdcYjAKYVcsH02tBWps9XL1DXdNWPeBy1mnck8D64YVIxgbK90XtD+ycuobjyXVBAocw7Uruw30c+ejSx8/yhHP6LiPW0aeXlhs2+km6LGlKcXAMU+ucOv+18xRpGvB2b2dazW/QY8Jc7KoJvUThfU6+jviw2jmWEmwXXdv1WFF8hRbFA/axINls8usElLCMXDJskVN1sXReRB62nii9wppufxsvA7lSCczgy+fx7Q6LWrJvFYpeZO0ZaDInuo3PeMIEmLa2993NFdBrJ143BUc3FDe4KIScmMmqWdcMFQgVRy5zIW/45uyFcYNO7KYnGfr03d2J8ONfUdbEZyKmNoMJG0OtBQAj94fCuRcZab+6tLOCmig2w7oKXHPImHvxr0nas10refydmRQQ9nBhMXY+gfBJRfuLtjqDEzfw2kkHA4KUqb08x79spwT1ezuYW+JHGtaZyT/qLAc4Q7wGpAPFdgEcfo22sgnHEaTK8FWHzqkghTtgOhGoordCfSyDTJo7F+6LmyOSg3jhuSiGNLrpYIM/awJpdInrbWLULhU1Y7ZjxUkZpB1tAcWg== 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)(136003)(346002)(39860400002)(376002)(451199021)(82310400008)(36840700001)(40470700004)(46966006)(86362001)(36756003)(82740400003)(40460700003)(40480700001)(54906003)(478600001)(110136005)(356005)(81166007)(47076005)(1076003)(426003)(2616005)(336012)(186003)(26005)(83380400001)(8676002)(8936002)(41300700001)(44832011)(6666004)(316002)(36860700001)(5660300002)(2906002)(4326008)(70206006)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 14:33:08.4128 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e5fd247d-6a4c-4d6e-5e43-08db942e8ea3 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: CO1PEPF000042A9.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6464 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE 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: 1773227728247034142 X-GMAIL-MSGID: 1773227728247034142 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 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 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/vfio/cdx/main.c b/drivers/vfio/cdx/main.c index c376a69d2db2..6420cf6eb2f9 100644 --- a/drivers/vfio/cdx/main.c +++ b/drivers/vfio/cdx/main.c @@ -52,6 +52,45 @@ 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 cdx_device *cdx_dev = to_cdx_device(core_vdev->dev); + struct vfio_device_feature_bus_master ops; + int ret; + + 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: + cdx_clear_master(cdx_dev); + return 0; + 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 +208,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,