From patchwork Thu Aug 10 08:44:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Nipun" X-Patchwork-Id: 133778 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp286214vqi; Thu, 10 Aug 2023 02:10:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqwdVbHRsbhlDo+qyj8OmyXPZRYVI+q5ib3TNTy6Qj7Oyv3Owrmkq7s1Qj2qM8R/UXqlTv X-Received: by 2002:a05:6358:5916:b0:139:d6cf:c430 with SMTP id g22-20020a056358591600b00139d6cfc430mr2218790rwf.6.1691658647868; Thu, 10 Aug 2023 02:10:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1691658647; cv=pass; d=google.com; s=arc-20160816; b=Y6ysqeWHJzc8TxQPS7J677zAULOhC/a9meWQcffoAH4uP3faTSpMxMc4oOot1yHM/t PDg6QpFNe7JZWBCSPEcbrYEFxz8tTrRU9buWsMBEkFGcr2k+S6nvGjRE2AKib1csx+nY nY9scsc6FOa+ZWOqy07IAd/NsSfE8OvyNLO1jjslt6dq+wP1OIjQn86lRClHjrMPQ+1k yUlTID4Qc6RZPHN89vnPoD9EWAqwqFOCXTiK15nDzuRtjDm15UeYRa9vH7u6erXVr3oD 2EQrtJ1Lm1YZYrOsnrVNBNdXvLspA6n/L3QhhG3DuXX4eIORL5RqBYjLaBXuZ7WPqXyD FE3A== 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=E0ITBgDcsUS7C9+Fo7odr0gcHBZsJ4138cB+awwnaX4=; fh=Ni1nsrg1oOMllulTte61KVXg/7l8962UlCxeEssxYck=; b=V76TN90pKVUCpdlV8O66jOgLZcAaqLUguswD/2uBsH9TiC620+wGxAfI+nUEvZqjIW meFtZsT6o6fTSwpQFIzkGZZoGSBqoJoyzwJOD4zQxtzlX9vpmSiWQyOrCk6vrqPkul7U Gd+3M9IhqamtdyW28an/XTH5HaRd0JkvHB+nVCoLk5aKdOQOr0/iu1/AhCtUpc2Fb9Iv FRE8zXnd3/2vNXjKE6QN+m268FsGzAl/8B6xMoOFJd0JZuaZYjYPdlt4wSlrl6nF56LO tZ22d8QJzs9QEirJEEz1XMWlhVPHedk44C0ejUSDoWqXsWjlXJd2QDze6y+UE+0CXbXV lhyg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=zTM0DLwp; 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 t186-20020a6381c3000000b0055beccf9921si1160256pgd.212.2023.08.10.02.10.34; Thu, 10 Aug 2023 02:10:47 -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=zTM0DLwp; 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 S234291AbjHJIo0 (ORCPT + 99 others); Thu, 10 Aug 2023 04:44:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234206AbjHJIoZ (ORCPT ); Thu, 10 Aug 2023 04:44:25 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2044.outbound.protection.outlook.com [40.107.220.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7572E1BFA for ; Thu, 10 Aug 2023 01:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O3t9IDiLLjbBpBYgySpX0PmXlLjolLGUtuiotK4VcVKIQksiz79HHwvT9DKxzaHoPPkhrTsgHixnd7mF9PxQH05Oz6t1E22WRslplVUxP7b8/vD3a5kfNsOyZjUrxbcI3TPtQEN9MhLU1e/gEWW4biJoMM/CTt3O+5rwBlFuNvpmgBDME4wR+E66zjc0UIvOWoCpL54G6mewIAC8oeUjN/y3/za+vQrEVnvvxAeRf3euBhpcBNXcSuMTsBVphJL648dcXRe4KCW2FxS/xeOBsBUWOgdbdkL9fS2xbPEu7QBGLxzAMqPofwN2O7DN9VgPEUqWub5K3tSYUdjG52FBqw== 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=E0ITBgDcsUS7C9+Fo7odr0gcHBZsJ4138cB+awwnaX4=; b=MTJnNdiYBIKz7yhX7rwTgkpNWUe8iZd188YgENek0KK1HzB+pr8kNJzuPQlHsxc0/6AaHt6WrHvzRmPwVLvJMrnbTRAP85xaXJuLSruqO8vOjG/cNePYfXSbLE/gAAEu9b/N7eCwNWtwZfy0El9CtxW0B36eHxvszNyyLwQJupa41DduK6n5YTW3Ce7nd3QXd5Z+Fz7n9hGFx/iFeWk+lLL4iQvTOHT3WIV3k0Hu69ekRvF00yGqP5yII72rrhU2cVl66lQr5ThSx6U0qFfhZrHAaIthaVXfCDpHCcnZThjS1wUZUECCga3c5asctJz0BQaYM315q9R5qCjMhg+h7g== 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=E0ITBgDcsUS7C9+Fo7odr0gcHBZsJ4138cB+awwnaX4=; b=zTM0DLwpr+j7Jj2CgwIR9BB5Qjp41O5xo44LCWN9MDaAlwei0Yv8TlEGZF5OatIJf1c9PEal65owSpsGw1BmRZP5yV9vvZ6ZzIMiCtneWsFzfzHZoMlwncrOF4UMHNWxHH9IO7BP43DM0HpuQOrLezNxCXGMOznBrCvT13sI51I= Received: from DS7PR03CA0127.namprd03.prod.outlook.com (2603:10b6:5:3b4::12) by MW6PR12MB8734.namprd12.prod.outlook.com (2603:10b6:303:249::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30; Thu, 10 Aug 2023 08:44:21 +0000 Received: from CY4PEPF0000EE33.namprd05.prod.outlook.com (2603:10b6:5:3b4:cafe::4e) by DS7PR03CA0127.outlook.office365.com (2603:10b6:5:3b4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30 via Frontend Transport; Thu, 10 Aug 2023 08:44:21 +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 CY4PEPF0000EE33.mail.protection.outlook.com (10.167.242.39) 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, 10 Aug 2023 08:44:20 +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, 10 Aug 2023 03:44:19 -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, 10 Aug 2023 03:44:17 -0500 From: Nipun Gupta To: , , CC: , , , , , Nipun Gupta Subject: [PATCH v6 1/3] cdx: add support for bus mastering Date: Thu, 10 Aug 2023 14:14:07 +0530 Message-ID: <20230810084409.4922-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: CY4PEPF0000EE33:EE_|MW6PR12MB8734:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ac0bfd2-e0ca-4bc2-aaa8-08db997dfdae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 14ci+eXjvU7xhCD6vSmdZD6etQwmMQC5OyQVxBzsS7qVD52JxCXXIJeYj6YE7uyAe4bXPSmpcFknwvuc+x+t/DD7SzIQ3hskcw4pxMpccDV5K4uWNg6whkjE0yps50Xy4sB7Yb9wMd4XpNSbs+ngNXKg4uLrOqsG+fvNHmwsXDvmFPxWGygliUqqyAuCbb2L1m0rqRDpYqp9CeC7RizxLe4+Ua3p5AqYfjdF6HyBhRSwTd7DuBh9Ia6t8bRFWvW7GgQk+fH0wk9UUjEqK01Yrnfe56YZ+ndNmakKrzD4tSlLd/Dpn3gwaa1RidnOFIM1SFHjuZDkf/h0syPzaFi52Elg4fHSI8sTyrZ8H26h3Zg915hOyaCUAjDkUBdgWYicAFX7thR5U615iwsJHiewr4+ewRxAj2m0LX96FIQ96u/B6SkTbTbE3Wd71tRbLNgC1Og7ILG4Hu6kDzkfDcuq8ljlH6SSfldwlWGvknBewweYam8HJEawDu5y8MwdEkmAR3XhDOmMZx0sb5r96phb5CJtpzRaDsrazjTqEL0SymDIJX7IE1ognsEQ3KVoee2bGrLlFwbObbM95ajlTMqO3a4+5U+1ausfoNSQiYggosnn1m1rlGX0yCz/NrMj7MIik1XKezi/yJCo3UzUq3HSeojSQFN87M5+RCJvEcigJYU0+6mtPWl8SiLItU6s9B6rekNl2zIDzCOFQC8YZKeHjIDBp+ke1bRHEd9n6YapMSA1e4w10OYawqP89REXSyBDg5fLlb2kRfy0pn2YMaKEgA== 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)(136003)(346002)(376002)(82310400008)(1800799006)(186006)(451199021)(46966006)(40470700004)(36840700001)(110136005)(54906003)(356005)(44832011)(478600001)(8676002)(8936002)(40460700003)(5660300002)(82740400003)(1076003)(336012)(26005)(81166007)(40480700001)(6666004)(86362001)(2906002)(70206006)(70586007)(36756003)(36860700001)(83380400001)(47076005)(2616005)(426003)(316002)(4326008)(41300700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2023 08:44:20.7852 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3ac0bfd2-e0ca-4bc2-aaa8-08db997dfdae 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: CY4PEPF0000EE33.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8734 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 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: 1773832658033295256 X-GMAIL-MSGID: 1773832658033295256 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 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 | 31 +++++++++++++ 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, 124 insertions(+) diff --git a/drivers/cdx/cdx.c b/drivers/cdx/cdx.c index d2cad4c670a0..363951b50034 100644 --- a/drivers/cdx/cdx.c +++ b/drivers/cdx/cdx.c @@ -182,6 +182,37 @@ 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 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..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 Thu Aug 10 08:44:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Nipun" X-Patchwork-Id: 133837 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp309812vqi; Thu, 10 Aug 2023 03:07:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFTF8gvWgplpgkiVxja+KTCgJW5cIO0RFErhZg3PqsKPYGZjuODb2JbWHIMUgfZboWvADXq X-Received: by 2002:a05:6512:32d1:b0:4fb:7c40:9f95 with SMTP id f17-20020a05651232d100b004fb7c409f95mr1576722lfg.47.1691662054330; Thu, 10 Aug 2023 03:07:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1691662054; cv=pass; d=google.com; s=arc-20160816; b=B7o/I3yuvz0IjbUN3XfFLgVHc1CUAYdoV33heZ1O2XMGwdwCbf65gxVNiGle9zujtF r2YMQUxrbZqb88NII6Ck78o1f+1+CV+5wNOm0aPupoXAWFFA8htfTYtIg0cnnLM+TQVD HAT4lt7shwe7tlzRo77IiUobE1SMiZmc9SMklEblqk51n+5AlEP6ybSqQ4peFhjqPBYW eRq0FcqvztdPLZu6mHBI9NFvO16piwsbamnem0YD3/DbH0k9RWFTGMA7V4Dyx+Op6uZY GH9AaAuNVwLl+RlFtqseLrKK/X+0UAdsGZt3ZaJ+I2SZQL+VyRULtQGAz5LDJOwGwK1w L9bw== 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=J3Lm3jSVWPw1SSL1NJQVfGdGRuXjzMkMUjbcJwk7O5U=; fh=tJDGlZlaSCi+XrMbzD8P6ISxXPUqdHJUGabWidOy+gE=; b=q5IvIwPEP2u904+aAAKafEDrjvCeZqxwrBdCqotmHQDqddO7ub9uMw5x2JmwT5XO1b U+9FXI5el5n/zJBOYFZIrN/CTPwqqSUwM+HpcqLGMTfsjXq0FLIk0kkhnJuxhscKKqXI ce+8juEUjLdqGcHov9xopNuER5pbm54T5c3DcXgetE/z5DiQDlU/u1Lxxde0h6Rqzn31 edEmnANwIPwHehsbylRpqHPAA0THyWqX0G/fAShglwVDM1VY7RVOY8pFNhW2cNnkrc7T cjRkRLiyAN/uotmNzkL+oTfy21DeFufLZXE6dL/m26AidIWvKFt03Cbr3EgBmAs8R0Z1 eL1Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=xjtPrkh1; 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 y16-20020a056402135000b005233f0f1a49si1132060edw.49.2023.08.10.03.07.00; Thu, 10 Aug 2023 03:07:34 -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=xjtPrkh1; 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 S234307AbjHJIod (ORCPT + 99 others); Thu, 10 Aug 2023 04:44:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234302AbjHJIob (ORCPT ); Thu, 10 Aug 2023 04:44:31 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2061b.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e88::61b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ACB110DC for ; Thu, 10 Aug 2023 01:44:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=blCZMNksac5n7FKaK4w1BgZcSI9PReUPXZXDb2eVOjChBLNOQJD4GhA4qb9ati/slmDWEJougCQPR5pQaRGxLmoYSaeB3VPaHhnl+jWzWFdZ+IvkynCzkgz3WkcYVAOYLGKCUuTqY5FcB+pphYv+hc+lraWQCRPgtOlJkKDDGFbAhkqfJ1WFQ2n2jKQGFsNfOr7Ll4xhoq8DQlreSSltOZCwD7uO07k1S4OzebV3sedYlDi5w91zAscHEQ/u72graWGRIGpji5NITLioTnjKHD9VluFQM4P7xmixJ+7vepotEmWj4TnjHWNRBWepfz4XV92GA6RHa6AO/XBxBXICfg== 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=J3Lm3jSVWPw1SSL1NJQVfGdGRuXjzMkMUjbcJwk7O5U=; b=N/O6fbFMdTkQsZXr1q2dltf4wtRbr1zy/R4AYYCoDvtWlW8T5TxVC4F+x39xlHTe2AChh6nobYebPYPQ6285RjYMRcngQ7J+X345jIZFylWXmvj3oOXY0EreNadOIiA74p2x6TwnR+CGoqmQ/5xNG2e5dSoN6W/NTcoznpYozHai4k/nX8W8wcIMp4tgaJqxuDBNvdccANCbNQMd2gNm3nBjorSMy/PcFGOspOK4JOFTr/19itqCkj65UCz3vzF0VEIqEfN+p7yEAYShziscFoMNRHN6E3PrTXijKbUGnvOyHSrsEapXaLwPE6K6Lka1jq2DcecJTfVJx8cL9LRtGw== 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=J3Lm3jSVWPw1SSL1NJQVfGdGRuXjzMkMUjbcJwk7O5U=; b=xjtPrkh1zgJyveTebwU7VCzin/xZixg8FaM5mQ33PBkvnSWMkiGA1B6GvgdJjvymSrWLWVR0Q3XD/x76ZPHsWMUcXaJZl03WCc5qOael+x1287uvgbBnzFLCL4ItmuWN+bqCrchDvfgBik+UaMJ9LRDx2pxTJach5YcP1gqay0Q= Received: from DM6PR11CA0033.namprd11.prod.outlook.com (2603:10b6:5:190::46) by BL0PR12MB4900.namprd12.prod.outlook.com (2603:10b6:208:1c1::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30; Thu, 10 Aug 2023 08:44:27 +0000 Received: from CY4PEPF0000EE35.namprd05.prod.outlook.com (2603:10b6:5:190:cafe::eb) by DM6PR11CA0033.outlook.office365.com (2603:10b6:5:190::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30 via Frontend Transport; Thu, 10 Aug 2023 08:44:27 +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 CY4PEPF0000EE35.mail.protection.outlook.com (10.167.242.41) 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, 10 Aug 2023 08:44:27 +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, 10 Aug 2023 03:44:27 -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, 10 Aug 2023 01:44:26 -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, 10 Aug 2023 03:44:23 -0500 From: Nipun Gupta To: , , CC: , , , , , Nipun Gupta , Shubham Rohila Subject: [PATCH v6 2/3] vfio: add bus master feature to device feature ioctl Date: Thu, 10 Aug 2023 14:14:08 +0530 Message-ID: <20230810084409.4922-2-nipun.gupta@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230810084409.4922-1-nipun.gupta@amd.com> References: <20230810084409.4922-1-nipun.gupta@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE35:EE_|BL0PR12MB4900:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ab3052a-a057-4142-361c-08db997e01a4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KXDimDa1kS9jgilNoXh878J9TrJfR9CS526M3D3ZHaefVAPhnypDZGJkg4UetISIhyUMohiL319FSKneXRGnjZbiDuGBmQzuVG6mlQuf+OSdCBBu/5lZqT8Qszcmdea2KVNdl8+mosTKyiYs/EWm/7Z2+55tyW6RK9uxQQqbVkKcwO29B66APC3S05fTiPgOGUpch6eZ+gVWtu73pYulfvsq5cdvC6l+mTWA+QYCt9BkuYl2bYqtXc7zfXpq7xKeJQEnx9LgqXhUa1xSxwkt5ubfUrvOHSKIPktMEySb9bC7XFTiLZyzGqoivVaOVqCQ+Dad2hCMEk0qAGiJl0HNgEtfA8N7hY47JohndppytHdTqT1qYkKIqyoQJe0pexUZZ5UwYTZ6fj10Hi8QCGg4zA9GWHUHtX6YZKhc/4pNHwAM+OvNR+rdywf9/2jEZX9qd3YYg2b3IBveRLkI0GIolqfoBPlCfWbzv5Zfqq1xDlh/AdJLTfTp5U0B1e4y/X9AAqgGL2C+VXAv9xZcxh+AFoKEI0kUvHPqoy90/0i2KTo4oK7D3eIrmwHlVORnK8IYAR/9NUQMukPuwi/bXSqjNyInuY4+ktpzNamOmt+7kj8ebSnNen2EQqrJPmgE8vfUTTi1cqg4AviUb6POAXKaS8lJ9AJieoqCe6ten6WJ7dNsJzXQZVzUnXLmsLTIsc5/HPRKP3fiPDit3I0EWBu6ObFJOwNocKpR5bIJZBSLIH9V5jgCJWqpMnA3NSkrUnPAWUuPfitoEh5OEl55715LFA== 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)(396003)(136003)(39860400002)(376002)(451199021)(186006)(82310400008)(1800799006)(36840700001)(40470700004)(46966006)(336012)(44832011)(82740400003)(5660300002)(40460700003)(356005)(81166007)(426003)(83380400001)(2616005)(47076005)(2906002)(26005)(1076003)(36860700001)(41300700001)(8676002)(8936002)(6666004)(40480700001)(36756003)(86362001)(70586007)(70206006)(316002)(4326008)(110136005)(478600001)(54906003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2023 08:44:27.4432 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9ab3052a-a057-4142-361c-08db997e01a4 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: CY4PEPF0000EE35.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4900 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_PASS,SPF_NONE 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: 1773836229920945767 X-GMAIL-MSGID: 1773836229920945767 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 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 Thu Aug 10 08:44:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gupta, Nipun" X-Patchwork-Id: 133814 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp300501vqi; Thu, 10 Aug 2023 02:46:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7XlEdXZi0yHxKmUN2tsTFh4dba3OmnMY0q35W9Zl58xFPm6KjPQbK6G3+G1aDDsZoUoIK X-Received: by 2002:a05:6a21:47cb:b0:140:ed6d:9251 with SMTP id as11-20020a056a2147cb00b00140ed6d9251mr1726348pzc.27.1691660772001; Thu, 10 Aug 2023 02:46:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1691660771; cv=pass; d=google.com; s=arc-20160816; b=Fr2RGiRYR4OeKbMXLBz1v6qDqQma51J182XhV2gXmGAJjNYWSAemfDdZLpKqCiFG37 UgWvQQvmCe04WqR3x4OY4nLefh4l1imw9qlun7Hy5jtRPHpL8ybkhj1P0KzOeDJ/8Dwt ipK7EkZC/LazED4lfNJ+OxVGuYl7UqXvIrVGZaZbUNlgtJMEIXon0F7nz8+LAu2l6RxG zuUiMiU/w791jkPY/sswY6ZlCAlytxCVCFLa29kYQcN92EQILsXJuP2UazZ2OyFWdvr8 1kK2pwV1rbS6xihM20w0HkahNIj9Sln9ZcbM4ydJI0Q9nDUHN1P05B0rbn0sKKRfsHF8 1Nyg== 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=G6j0r28OrlYdRKB6FnC5jMv+78o0wx6zAN2aCzzaGa4=; fh=tJDGlZlaSCi+XrMbzD8P6ISxXPUqdHJUGabWidOy+gE=; b=L0JpSFBm2GoDEhG2rDUGuOD/PxaTiipllvVha4dW5qlHcphA7TuRkm5sFvV9Z6O8yx xrDAoBtyw8JWmKZcpp3RpeLt66zFlFYxk4TaGApr7/NvDuc5KIKZOmnJXQQUVx61/Vu9 DXBqypEM/QCpwlBgEiiBoFg3cSV7SrWRuwu3qyS/LoH68kvrZ96JcUKzKwP9ozcpOQJ6 q9Lje+eg+NkHIsfxUiJc/c0MMpJ9FZiBERn7iFasAJSSkvbj750172snfmS+IBGguKBn ByHHtHC7Vv0G4hvVXLKAvWv7UIZv0SxzmHbe4q545oVCsAehFNl6S4mIkXeG0wKwvO8P jsJw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=K8TQqKlG; 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 t30-20020a63955e000000b0053fbb36fc65si1321616pgn.382.2023.08.10.02.45.50; Thu, 10 Aug 2023 02:46:11 -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=K8TQqKlG; 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 S234322AbjHJIoh (ORCPT + 99 others); Thu, 10 Aug 2023 04:44:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233231AbjHJIog (ORCPT ); Thu, 10 Aug 2023 04:44:36 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2044.outbound.protection.outlook.com [40.107.223.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED117211D for ; Thu, 10 Aug 2023 01:44:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FdfC8LJ8IBmR4HoTbIYyJWSppiqq6Fsh0mHGnQ6ceQSUhLNaVuducxozy1CCUUMImy0bh2HNHEezJUBGEgmaxc2GqZpUx2ly/1AbEboXerZ8xRR/VZrIcr25lJxCTOdywWa4+Ai5poUs4JkpO0CexbnEjQjl7BVRlaFUAz9+1DQ5DwgpfHADO8XSv0fcCzfpPs3Xco4yq30dIkY8vTsy1eeVX/akenn8DUwNSMH0+vqCcYfjbhEjaHZmHbIMznhf+tkTVYsAlUZWkXm0KmXdrQ97a/I6SOtR2Tka6EsaaDvaBGNN47+Qt/WG/AjcHXbVDFarMLRjhnfALu2PJA+W+w== 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=G6j0r28OrlYdRKB6FnC5jMv+78o0wx6zAN2aCzzaGa4=; b=GTFWSeTD8x9ASKcLMyz0f4evbs2/XNRVOiN/LabPdElCeU/wZTzOPfLmEvqLa6DBwdyCo/qO3wWkQs8BIpRYO4twlzKpU59I1VOSIR6zmHW9H9R9EDi2I9Lv47tJNRgN2Tb8uKWZNwhCsCVkJVTDT+zA25jORjO2A3HnAFhrWcsdLD83XgxXNC9zl/d+Tkm8pC2N530WkedkQMZQj5+kQw2yDjCY7fkGe/Wp6csv/fh0/VrooEVA7TVDe9+J6kN2uaqaOgU/ids4PE1u84jlDcxVKedzoEe4SYI2GFK8VCozcAh7H292ShnTqPpz2yXs7Ms8BikBAyRCrCZs9/6ohw== 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=G6j0r28OrlYdRKB6FnC5jMv+78o0wx6zAN2aCzzaGa4=; b=K8TQqKlGkht7PmUlaLfIMVYEPxuQnQsIZK4iUUo0JAHIxhTiUFVGoef1qJZyUoY6fza0ax3fZiH+yK2keT11LCPuRKhfKtqRL4iXi8U+xK/pi/v2SfKa5eTSBKFUCOZEaP732dkm1dRmK6gciMxhyoH5sUTkcJQHlh1BNMIxb/Q= Received: from DS7PR07CA0024.namprd07.prod.outlook.com (2603:10b6:5:3af::6) by DS0PR12MB9037.namprd12.prod.outlook.com (2603:10b6:8:f1::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30; Thu, 10 Aug 2023 08:44:32 +0000 Received: from CY4PEPF0000EE34.namprd05.prod.outlook.com (2603:10b6:5:3af:cafe::69) by DS7PR07CA0024.outlook.office365.com (2603:10b6:5:3af::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30 via Frontend Transport; Thu, 10 Aug 2023 08:44:32 +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 CY4PEPF0000EE34.mail.protection.outlook.com (10.167.242.40) 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, 10 Aug 2023 08:44:32 +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, 10 Aug 2023 03:44:31 -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, 10 Aug 2023 01:44:30 -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, 10 Aug 2023 03:44:28 -0500 From: Nipun Gupta To: , , CC: , , , , , Nipun Gupta , Shubham Rohila Subject: [PATCH v6 3/3] vfio-cdx: add bus mastering device feature support Date: Thu, 10 Aug 2023 14:14:09 +0530 Message-ID: <20230810084409.4922-3-nipun.gupta@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230810084409.4922-1-nipun.gupta@amd.com> References: <20230810084409.4922-1-nipun.gupta@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE34:EE_|DS0PR12MB9037:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a611710-a5e1-4943-72ad-08db997e04b5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qVlkOfYCWKiIpAAi/lcp4yKMcohVXiIkhyymwhmir9nJrAVw8bHYXGhibX9cBB6RQ2+uVTuTsFUo5gR5M9zA5rD+u0RHrC+soGhto23bR4Uq1FmMCwT/9EwGJNwWntliKy8aH5X1rJbRv/JCKIMk5J7UMSS9sqsy45k/Q9JuCsS3yKYcAeGavQn9PiGd/FZj5GfN0CAT6Ifi2fq/wAXUPa8CHy9V1+5CWos5tNE22cedg89+KlwwBxchB6KholjToz3704nguVXLqjVd44nW7u8ExmDN2WUZBEj+/JAVP590ps9yFlWDTEX5inbcCD5TlWWVX98TcyjXvGwUJfmTdgUfNO0EuuaMnB952ErHeR6nzgCij2DUNGto6lyTCd/7qZGM7D161VQFggI5AYRE1uInQnZ1NbElB2Ecj2Jzxd6cBLF0IWxLNUYEUAAdZHORTb7scAWorWSEnjjyM7t/xNnl+fAtWoHn8RYFHbtNhbsch+xw2GxgKYXrbT+DIvdg73gr0+kgxMgYdRQPsQ4Wp0DeQUCamHYAxRE275O7CLDxpi2yPsf52CmU7hOlXUh/nMEtd/Md/IwmmjV+WYqvU4oarP6mmT5NzVmKFBtNPJS9oLKO/RLNMSyhRmFxiAE24T1uAO7AyaDJhdPxwIql6XCU4E5lvV0DsjnvChdOjxrBdrKzXP57EjmJ60Y6NEEKX6h+3oxEzx3tDjJTAaDdr+sYu4c+ncJtselCGVTmVUkaPoYgVPwWup9tu0kslf3xhmrJsVlp0iPve5wWZ0/SWQ== 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)(136003)(396003)(346002)(376002)(82310400008)(1800799006)(451199021)(186006)(46966006)(36840700001)(40470700004)(2616005)(478600001)(44832011)(426003)(86362001)(40480700001)(6666004)(2906002)(36756003)(1076003)(336012)(40460700003)(26005)(83380400001)(356005)(54906003)(316002)(81166007)(70206006)(70586007)(4326008)(41300700001)(47076005)(5660300002)(110136005)(8936002)(8676002)(36860700001)(82740400003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2023 08:44:32.5892 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8a611710-a5e1-4943-72ad-08db997e04b5 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: CY4PEPF0000EE34.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB9037 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 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: 1773834885942761302 X-GMAIL-MSGID: 1773834885942761302 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 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 | 46 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/drivers/vfio/cdx/main.c b/drivers/vfio/cdx/main.c index c376a69d2db2..bf0e1f56e0f9 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,8 +39,11 @@ 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); - return 0; + return ret; } static void vfio_cdx_close_device(struct vfio_device *core_vdev) @@ -52,6 +55,44 @@ 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: + 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 +210,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,