From patchwork Fri Jul 16 15:19:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 12382475 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 266D4C07E95 for ; Fri, 16 Jul 2021 15:24:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 038E261409 for ; Fri, 16 Jul 2021 15:24:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240773AbhGPP1Z (ORCPT ); Fri, 16 Jul 2021 11:27:25 -0400 Received: from mail-bn8nam08on2086.outbound.protection.outlook.com ([40.107.100.86]:5408 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240765AbhGPP1Y (ORCPT ); Fri, 16 Jul 2021 11:27:24 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CnfgvhtkzNCzQLZQXZG+veqIuz0jIKI0X66ZUf8CEhckwrrr4X2m6MnbNWo4NyaPoN1wDU31EA3HWFBXOQysTI21M4vj/R6eGIS6X0/xxm237priD9auW/jtvGSS6SdrrHTb7iYFOEyL8vTnLWPEQLmu/omeGCD1T6r/O3M/J+cGytaaenOqNJZ3Yth4pEiTk7f7iNV7Dv7zsvqHGiT/74MTWTUIEMSDFsMCzYm5kUz4SBHGgvvgeUPqpTnVfd3i8CN6n0UuAAnDkqfyYkAkDnFdE0DemyeOqHbmeMlQJAoWYYomh9h82R1zbXodlAJes4x/miZByNklmR6Z2ZtGxQ== 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-SenderADCheck; bh=TNGEdyd2PXOAXWZpuACvKtbKoIiSd/mnufsXFJddCvc=; b=BovVt5TbsQAzb2YRaTjTzIQ9CiB0YBxMfi0HBvjONHMOo80W/DDY5ReVNG9Ie/e/TUiKtdYcdnH+zKcNu0idwje4mi1iJyks2NRhaflr0CnYVQTGy3LcO8QQEaOlzx1VF47IltakKvlHsXRBSggmPFHWw6YxTM9GvRoHyQXyrBEvfpOkmxebOf0KSlrjeltOmUWYCiZxVEZhHQUbm8I4YYwGqRp5kIqLnsYejwCVQk7Q1SNfeEwIWVwB0MTCuMgK16vdhPuOjzBBvZzIF6SiAvThb8BQ9qaFZxJdFsvoigARLs0KrI9t7LfwGMP/YXFpqsSWvwRD7pg3QvEn7/qb5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=rjwysocki.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TNGEdyd2PXOAXWZpuACvKtbKoIiSd/mnufsXFJddCvc=; b=Dfp6sJPdAlh9PKPNhaOBDd1dRAflFcYSTlsLkibDvhLe9mGt1mvzSeHvN5LHQqDD1ymh/fBr6Ygr/jd8qXZmW857mDoNEsC8Nf8PYhWiRVqs1zjOqs1A1y4Kdrch+l8KczFdHI0M+DzabkPB7X22uhKenvlzJtUGZhVkVee6bQuiHvkMq+MCuVEaJiqkhLQSRjCU8ZCEXKCfYGHEiBGAGAb9N9wSoptzWKDD5hOQYJjTuWfyj9n26Sby3RkVQQAMD7pVPmPaZAPHYtQ2oaok31oIB2frDywcOavvyZiMkjr2SYAVt6keZoZI1MuHVB4Y8l/LgzvwDVOd18kNVpq1wA== Received: from BN6PR17CA0032.namprd17.prod.outlook.com (2603:10b6:405:75::21) by DM5PR12MB1754.namprd12.prod.outlook.com (2603:10b6:3:10f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.23; Fri, 16 Jul 2021 15:24:28 +0000 Received: from BN8NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:405:75:cafe::a5) by BN6PR17CA0032.outlook.office365.com (2603:10b6:405:75::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.22 via Frontend Transport; Fri, 16 Jul 2021 15:24:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; rjwysocki.net; dkim=none (message not signed) header.d=none;rjwysocki.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT008.mail.protection.outlook.com (10.13.177.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4331.21 via Frontend Transport; Fri, 16 Jul 2021 15:24:27 +0000 Received: from SDONTHINENI-DESKTOP.nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 16 Jul 2021 15:24:25 +0000 From: Shanker Donthineni To: Bjorn Helgaas CC: Alex Williamson , , , , Len Brown , "Rafael J . Wysocki" , Sinan Kaya , "Amey Narkhede" , Shanker Donthineni Subject: [PATCH v12 1/8] PCI: Add pcie_reset_flr to follow calling convention of other reset methods Date: Fri, 16 Jul 2021 10:19:39 -0500 Message-ID: <20210716151946.690-2-sdonthineni@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210716151946.690-1-sdonthineni@nvidia.com> References: <20210716151946.690-1-sdonthineni@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 865eb03a-5836-4379-7440-08d9486dcd0a X-MS-TrafficTypeDiagnostic: DM5PR12MB1754: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zJCDgyd9feG6NfklPjRuX9g0NOSpO/lORo0VQUm84UQxNmyCStyQkwTPxgw8zqa28EdsT1dsSB2kcoAIX23rBt9OQ72XIF9PxMoylPbfqKk38PnhnxnOjZnQklJ27k4Dhe2zn2zOWH5Qjj3ZVfy2/BiGSscasSYMDMj6UflkGKDZMkBufrVQeYuY/kEXS05cNr5/nYACSxZxoq5wX8lUbj6crPkPYyqhIIVetWZD5SPl702pOBBebL/Iyy86yMoItoS6uB8tUoPbe+N5+LAk0Ma6qFR0ASYfo45za22mVbF12WRkwFyY9+8vPivOp43LUivpALlWdHYtMbxSS+vYjbrGnA9gk4EbZ3kJxugvBxk9BF5O7JDEIZA7QF+ksU5jcwXbapWsWYNkaIc4ZDD7Ei3Oj68I11Wim+33UdF/u3OcWRY2aKN/nWlYvQs95XzHUC2XzAOfUdAuG+6Y8nc+i6ax7qnBtKDp3wy/zkjk40pu52d4ODMjm4VMCUB36+cjuGovA9Ctl/PoLxkgnc9pRIROaPXqkc80bukGEbyuWCwsln42aAySkPenrjCO7hAkDfhPxZXZA6CV6etu6cAl4ISQ81PfP+uzHGmYEZAJwgcwhNy69IXcAwSs6clva99XtBK+2EmDTilTlknL/R9TwljjIpVZ44D8rzOSc3GVi55G1PuOXQSlQkV7Ho6fZEA4GZtg/Ag6rOKVua6qre9ZeBd7c8TzlJqCqlmu0vPkXQs= X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(396003)(39860400002)(346002)(376002)(136003)(46966006)(36840700001)(82740400003)(186003)(426003)(2616005)(7636003)(82310400003)(16526019)(26005)(7696005)(34020700004)(356005)(6666004)(2906002)(5660300002)(8676002)(36756003)(47076005)(336012)(1076003)(478600001)(316002)(8936002)(83380400001)(36860700001)(70586007)(36906005)(4326008)(54906003)(86362001)(107886003)(70206006)(6916009);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2021 15:24:27.6686 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 865eb03a-5836-4379-7440-08d9486dcd0a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1754 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Amey Narkhede Add has_pcie_flr bitfield in struct pci_dev to indicate support for PCIe FLR to avoid reading PCI_EXP_DEVCAP multiple times. Currently there is separate function pcie_has_flr() to probe if PCIe FLR is supported by the device which does not match the calling convention followed by reset methods which use second function argument to decide whether to probe or not. Add new function pcie_reset_flr() that follows the calling convention of reset methods. Signed-off-by: Amey Narkhede Reviewed-by: Alex Williamson --- drivers/crypto/cavium/nitrox/nitrox_main.c | 4 +- drivers/pci/pci.c | 59 +++++++++++----------- drivers/pci/pcie/aer.c | 12 ++--- drivers/pci/probe.c | 6 ++- drivers/pci/quirks.c | 9 ++-- include/linux/pci.h | 3 +- 6 files changed, 45 insertions(+), 48 deletions(-) diff --git a/drivers/crypto/cavium/nitrox/nitrox_main.c b/drivers/crypto/cavium/nitrox/nitrox_main.c index 96bc7b5c6532d..2db3fd5815c82 100644 --- a/drivers/crypto/cavium/nitrox/nitrox_main.c +++ b/drivers/crypto/cavium/nitrox/nitrox_main.c @@ -306,9 +306,7 @@ static int nitrox_device_flr(struct pci_dev *pdev) return -ENOMEM; } - /* check flr support */ - if (pcie_has_flr(pdev)) - pcie_flr(pdev); + pcie_reset_flr(pdev, 0); pci_restore_state(pdev); diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index aacf575c15cff..16870e4d7863a 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4621,32 +4621,12 @@ int pci_wait_for_pending_transaction(struct pci_dev *dev) } EXPORT_SYMBOL(pci_wait_for_pending_transaction); -/** - * pcie_has_flr - check if a device supports function level resets - * @dev: device to check - * - * Returns true if the device advertises support for PCIe function level - * resets. - */ -bool pcie_has_flr(struct pci_dev *dev) -{ - u32 cap; - - if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET) - return false; - - pcie_capability_read_dword(dev, PCI_EXP_DEVCAP, &cap); - return cap & PCI_EXP_DEVCAP_FLR; -} -EXPORT_SYMBOL_GPL(pcie_has_flr); - /** * pcie_flr - initiate a PCIe function level reset * @dev: device to reset * - * Initiate a function level reset on @dev. The caller should ensure the - * device supports FLR before calling this function, e.g. by using the - * pcie_has_flr() helper. + * Initiate a function level reset unconditionally on @dev without + * checking any flags and DEVCAP */ int pcie_flr(struct pci_dev *dev) { @@ -4669,6 +4649,28 @@ int pcie_flr(struct pci_dev *dev) } EXPORT_SYMBOL_GPL(pcie_flr); +/** + * pcie_reset_flr - initiate a PCIe function level reset + * @dev: device to reset + * @probe: If set, only check if the device can be reset this way. + * + * Initiate a function level reset on @dev. + */ +int pcie_reset_flr(struct pci_dev *dev, int probe) +{ + if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET) + return -ENOTTY; + + if (!dev->has_pcie_flr) + return -ENOTTY; + + if (probe) + return 0; + + return pcie_flr(dev); +} +EXPORT_SYMBOL_GPL(pcie_reset_flr); + static int pci_af_flr(struct pci_dev *dev, int probe) { int pos; @@ -5151,11 +5153,9 @@ int __pci_reset_function_locked(struct pci_dev *dev) rc = pci_dev_specific_reset(dev, 0); if (rc != -ENOTTY) return rc; - if (pcie_has_flr(dev)) { - rc = pcie_flr(dev); - if (rc != -ENOTTY) - return rc; - } + rc = pcie_reset_flr(dev, 0); + if (rc != -ENOTTY) + return rc; rc = pci_af_flr(dev, 0); if (rc != -ENOTTY) return rc; @@ -5186,8 +5186,9 @@ int pci_probe_reset_function(struct pci_dev *dev) rc = pci_dev_specific_reset(dev, 1); if (rc != -ENOTTY) return rc; - if (pcie_has_flr(dev)) - return 0; + rc = pcie_reset_flr(dev, 1); + if (rc != -ENOTTY) + return rc; rc = pci_af_flr(dev, 1); if (rc != -ENOTTY) return rc; diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index df4ba9b384c24..031379deb1304 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -1407,13 +1407,11 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev) } if (type == PCI_EXP_TYPE_RC_EC || type == PCI_EXP_TYPE_RC_END) { - if (pcie_has_flr(dev)) { - rc = pcie_flr(dev); - pci_info(dev, "has been reset (%d)\n", rc); - } else { - pci_info(dev, "not reset (no FLR support)\n"); - rc = -ENOTTY; - } + rc = pcie_reset_flr(dev, 0); + if (!rc) + pci_info(dev, "has been reset\n"); + else + pci_info(dev, "not reset (no FLR support: %d)\n", rc); } else { rc = pci_bus_error_reset(dev); pci_info(dev, "%s Port link has been reset (%d)\n", diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 79177ac37880f..d99ef232169e2 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1488,6 +1488,7 @@ void set_pcie_port_type(struct pci_dev *pdev) { int pos; u16 reg16; + u32 reg32; int type; struct pci_dev *parent; @@ -1498,8 +1499,9 @@ void set_pcie_port_type(struct pci_dev *pdev) pdev->pcie_cap = pos; pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, ®16); pdev->pcie_flags_reg = reg16; - pci_read_config_word(pdev, pos + PCI_EXP_DEVCAP, ®16); - pdev->pcie_mpss = reg16 & PCI_EXP_DEVCAP_PAYLOAD; + pci_read_config_dword(pdev, pos + PCI_EXP_DEVCAP, ®32); + pdev->pcie_mpss = reg32 & PCI_EXP_DEVCAP_PAYLOAD; + pdev->has_pcie_flr = !!(reg32 & PCI_EXP_DEVCAP_FLR); parent = pci_upstream_bridge(pdev); if (!parent) diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 6d74386eadc2c..90144fbc4f4ea 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -3852,7 +3852,7 @@ static int nvme_disable_and_flr(struct pci_dev *dev, int probe) u32 cfg; if (dev->class != PCI_CLASS_STORAGE_EXPRESS || - !pcie_has_flr(dev) || !pci_resource_start(dev, 0)) + pcie_reset_flr(dev, 1) || !pci_resource_start(dev, 0)) return -ENOTTY; if (probe) @@ -3921,13 +3921,10 @@ static int nvme_disable_and_flr(struct pci_dev *dev, int probe) */ static int delay_250ms_after_flr(struct pci_dev *dev, int probe) { - if (!pcie_has_flr(dev)) - return -ENOTTY; + int ret = pcie_reset_flr(dev, probe); if (probe) - return 0; - - pcie_flr(dev); + return ret; msleep(250); diff --git a/include/linux/pci.h b/include/linux/pci.h index 540b377ca8f61..5652214fe3a58 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -337,6 +337,7 @@ struct pci_dev { u8 msi_cap; /* MSI capability offset */ u8 msix_cap; /* MSI-X capability offset */ u8 pcie_mpss:3; /* PCIe Max Payload Size Supported */ + u8 has_pcie_flr:1; /* PCIe FLR supported */ u8 rom_base_reg; /* Config register controlling ROM */ u8 pin; /* Interrupt pin this device uses */ u16 pcie_flags_reg; /* Cached PCIe Capabilities Register */ @@ -1228,7 +1229,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev, enum pci_bus_speed *speed, enum pcie_link_width *width); void pcie_print_link_status(struct pci_dev *dev); -bool pcie_has_flr(struct pci_dev *dev); +int pcie_reset_flr(struct pci_dev *dev, int probe); int pcie_flr(struct pci_dev *dev); int __pci_reset_function_locked(struct pci_dev *dev); int pci_reset_function(struct pci_dev *dev); From patchwork Fri Jul 16 15:19:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 12382477 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56CC3C12002 for ; Fri, 16 Jul 2021 15:24:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3E5F1601FC for ; Fri, 16 Jul 2021 15:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240889AbhGPP10 (ORCPT ); Fri, 16 Jul 2021 11:27:26 -0400 Received: from mail-dm6nam10on2054.outbound.protection.outlook.com ([40.107.93.54]:3809 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240855AbhGPP10 (ORCPT ); Fri, 16 Jul 2021 11:27:26 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RqgPt0WEf1tjO3sz1PjeAwNtvO5umgzuyyR1/YTsFkj03I248LIIEqwyOu2ZPYsj3DtRctxI0BS7R9J+MeSrotUhkZc9UPNNIUcpLYSUGyGShfNiw9kHBTo5XzTOcYFCRm24q5Mnup9inhJxkQIfheVdFGUic/wZR9Cm1lrMLNySCL/Jdjelo1oBWxEDidaVkrTwc65fIHUSh+YivSlwkDJTh3kI7OG7QgilYUApQObGs4fJsADH4/RmvBBsto45+Md8iK0jWFbsCtVpEQdTHmY0x9XrjHupou3srCeXOoDmglDSZor3ItLa8NSsL8GspnmUKFZyB12QLRSIa76UWQ== 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-SenderADCheck; bh=cziv2NW0lWnsmfgx12k0Ck9NVtSNjKT67wiQkKh+vzw=; b=U/CkEYYzr3kEwU7mWV1e69obyxxkJValos1XIsF/32mrh3g68lte4itS7lnIdP5gJWgnGko9teX1Ou4AiVW63lt0Bg5omx1oDMUC5iENkAT9ZvQ4IZOEeyIZWTAJG17st9uFu4+kN+Az3Ci1zMxLFoyeNJTXjrVP6C0t+JnY9LxZKLajG1stPKl/ru0nOFS75px6jeLwOQ848MR3XEpHl5gZjY67h8tzt193OfkSSOaW0VbumZvgyjFibONUIzuf7ftVVx1I5QfJg/E0+dkaKwMqaq8CflcCD1BPtOGnID3eAV56MkY/kMgHciw1RSy8M/5suVR76mSjBmenWqCXWg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=rjwysocki.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cziv2NW0lWnsmfgx12k0Ck9NVtSNjKT67wiQkKh+vzw=; b=aqGTa+lQUlVby+KnXI/C7ZpnoirsEuZSdvlDceLV6G4QbTZsy90i04I5IfASfIMGuj961PaxkodnIS/WUO3NVAvzdg0r+jKwSWQYrm3LxoUFciMOU7sqkv2uE0oM7OUmgKmPNGUlhvCSvoTzzbhbTFr53XrMqDS+2qa/pV08+/BXGD/wO8Sz8psh2dK18AUgEop9CxldEYzT2g20KYD5HVRIX/HbMLgNlqlQ/gCBekEdX+KLmbBUtLve05q5kRdq9LIBIdJZBCYEg2rBrtHmPYxOKaIWUH8dV4SEZjijDboH1k2TPZtAfagQMxa+Mvrv0GJZP0C0aiSkzCdP3ktiow== Received: from BN0PR03CA0027.namprd03.prod.outlook.com (2603:10b6:408:e6::32) by DM6PR12MB2713.namprd12.prod.outlook.com (2603:10b6:5:4c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.25; Fri, 16 Jul 2021 15:24:29 +0000 Received: from BN8NAM11FT007.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e6:cafe::d0) by BN0PR03CA0027.outlook.office365.com (2603:10b6:408:e6::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Fri, 16 Jul 2021 15:24:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; rjwysocki.net; dkim=none (message not signed) header.d=none;rjwysocki.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT007.mail.protection.outlook.com (10.13.177.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4331.21 via Frontend Transport; Fri, 16 Jul 2021 15:24:29 +0000 Received: from SDONTHINENI-DESKTOP.nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 16 Jul 2021 15:24:27 +0000 From: Shanker Donthineni To: Bjorn Helgaas CC: Alex Williamson , , , , Len Brown , "Rafael J . Wysocki" , Sinan Kaya , "Amey Narkhede" , Shanker Donthineni Subject: [PATCH v12 2/8] PCI: Add new array for keeping track of ordering of reset methods Date: Fri, 16 Jul 2021 10:19:40 -0500 Message-ID: <20210716151946.690-3-sdonthineni@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210716151946.690-1-sdonthineni@nvidia.com> References: <20210716151946.690-1-sdonthineni@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 14fbe6c9-17d4-4f9c-5b67-08d9486dce0f X-MS-TrafficTypeDiagnostic: DM6PR12MB2713: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YtlYHXxSu5n1Fovx2biZ5YlKnCPb0ilYcQSGHdV2YrdcuqDmnPF+Lf+WvoWsTP7e6KKYa/Nt+UPftJqpJ94wj01eguqaWom1IUGsAwH8wn1UeSNaVcnFQeUpZswXTrM8erAnhJddXw59x3bdagXpiM6tcQODFe06eOIYo5ccIYAsAaicCijM5bw4+A2FRM258afFUyHFuKw4n9Ul25sV9+lTW878kQqeKpg81c/krbvJctK9IMi+0QwW150YTDewGhVEVmkBB23qEmZdPJS8JAasZ6aSsLTlk6pgC3XRrzdGCoyWuPk2S8WQGsGl+fPXGmpsNyPvCxtqpeMtjv+4SjlyzIyB9UC297NsAF9/SUgXM64H51pQIBpkMIESgTrj6Ff74YRENivN9ahfaxmR4a6S/y2fd4ShxWLwpgkm98JSOjsKQKnbg7HWEcEi0lOno/84LUJwDO56zKwvIapHzNOKYWgai3gcEOI8kPghrDXgjqhmJjueJInXDtB34n+W3MB/PrnOk4YNX+C+xhjQclC5fQmGPa6K+/Pl8nMAaLY7Xl+/yEfcsRQZpQcSQeIBupRoBlFau5ewVW+4b6x9Mis7HbKUft5dxmNhTGJ7iR/BZA5Wctj6v74BIJULcvJlf10gbYrWN2GynC/t2TmAJj3gsxXrqkSAbC6HLBgF3OZQ+MxBCCY134vCyJf8D1AmJGSK6zTWeamgR96oouLXXVP3Lr+OB1zk6oUJWosLJDw= X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(346002)(136003)(376002)(39860400002)(396003)(46966006)(36840700001)(1076003)(36906005)(186003)(54906003)(4326008)(83380400001)(5660300002)(356005)(2616005)(7696005)(16526019)(36860700001)(6666004)(2906002)(6916009)(82740400003)(336012)(82310400003)(86362001)(107886003)(8676002)(47076005)(34020700004)(316002)(26005)(426003)(8936002)(478600001)(7636003)(70206006)(36756003)(70586007);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2021 15:24:29.3674 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 14fbe6c9-17d4-4f9c-5b67-08d9486dce0f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT007.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2713 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Amey Narkhede Introduce a new array reset_methods in struct pci_dev to keep track of reset mechanisms supported by the device and their ordering. Also refactor probing and reset functions to take advantage of calling convention of reset functions. Co-developed-by: Alex Williamson Signed-off-by: Alex Williamson Signed-off-by: Amey Narkhede --- drivers/pci/pci.c | 92 ++++++++++++++++++++++++++------------------- drivers/pci/pci.h | 9 ++++- drivers/pci/probe.c | 5 +-- include/linux/pci.h | 7 ++++ 4 files changed, 70 insertions(+), 43 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 16870e4d7863a..4d5618b232363 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -72,6 +72,14 @@ static void pci_dev_d3_sleep(struct pci_dev *dev) msleep(delay); } +int pci_reset_supported(struct pci_dev *dev) +{ + u8 null_reset_methods[PCI_NUM_RESET_METHODS] = { 0 }; + + return memcmp(null_reset_methods, + dev->reset_methods, sizeof(null_reset_methods)); +} + #ifdef CONFIG_PCI_DOMAINS int pci_domains_supported = 1; #endif @@ -5116,6 +5124,15 @@ static void pci_dev_restore(struct pci_dev *dev) err_handler->reset_done(dev); } +const struct pci_reset_fn_method pci_reset_fn_methods[] = { + { }, + { &pci_dev_specific_reset, .name = "device_specific" }, + { &pcie_reset_flr, .name = "flr" }, + { &pci_af_flr, .name = "af_flr" }, + { &pci_pm_reset, .name = "pm" }, + { &pci_reset_bus_function, .name = "bus" }, +}; + /** * __pci_reset_function_locked - reset a PCI device function while holding * the @dev mutex lock. @@ -5138,65 +5155,62 @@ static void pci_dev_restore(struct pci_dev *dev) */ int __pci_reset_function_locked(struct pci_dev *dev) { - int rc; + int i, m, rc = -ENOTTY; might_sleep(); /* - * A reset method returns -ENOTTY if it doesn't support this device - * and we should try the next method. + * A reset method returns -ENOTTY if it doesn't support this device and + * we should try the next method. * - * If it returns 0 (success), we're finished. If it returns any - * other error, we're also finished: this indicates that further - * reset mechanisms might be broken on the device. + * If it returns 0 (success), we're finished. If it returns any other + * error, we're also finished: this indicates that further reset + * mechanisms might be broken on the device. */ - rc = pci_dev_specific_reset(dev, 0); - if (rc != -ENOTTY) - return rc; - rc = pcie_reset_flr(dev, 0); - if (rc != -ENOTTY) - return rc; - rc = pci_af_flr(dev, 0); - if (rc != -ENOTTY) - return rc; - rc = pci_pm_reset(dev, 0); - if (rc != -ENOTTY) - return rc; - return pci_reset_bus_function(dev, 0); + for (i = 0; i < PCI_NUM_RESET_METHODS && (m = dev->reset_methods[i]); i++) { + rc = pci_reset_fn_methods[m].reset_fn(dev, 0); + if (!rc) + return 0; + if (rc != -ENOTTY) + return rc; + } + + return -ENOTTY; } EXPORT_SYMBOL_GPL(__pci_reset_function_locked); /** - * pci_probe_reset_function - check whether the device can be safely reset - * @dev: PCI device to reset + * pci_init_reset_methods - check whether device can be safely reset + * and store supported reset mechanisms. + * @dev: PCI device to check for reset mechanisms * * Some devices allow an individual function to be reset without affecting * other functions in the same device. The PCI device must be responsive - * to PCI config space in order to use this function. + * to reads and writes to its PCI config space in order to use this function. * - * Returns 0 if the device function can be reset or negative if the - * device doesn't support resetting a single function. + * Stores reset mechanisms supported by device in reset_methods byte array + * which is a member of struct pci_dev. */ -int pci_probe_reset_function(struct pci_dev *dev) +void pci_init_reset_methods(struct pci_dev *dev) { - int rc; + int i, n, rc; + u8 reset_methods[PCI_NUM_RESET_METHODS] = { 0 }; + + n = 0; + + BUILD_BUG_ON(ARRAY_SIZE(pci_reset_fn_methods) != PCI_NUM_RESET_METHODS); might_sleep(); - rc = pci_dev_specific_reset(dev, 1); - if (rc != -ENOTTY) - return rc; - rc = pcie_reset_flr(dev, 1); - if (rc != -ENOTTY) - return rc; - rc = pci_af_flr(dev, 1); - if (rc != -ENOTTY) - return rc; - rc = pci_pm_reset(dev, 1); - if (rc != -ENOTTY) - return rc; + for (i = 1; i < PCI_NUM_RESET_METHODS; i++) { + rc = pci_reset_fn_methods[i].reset_fn(dev, 1); + if (!rc) + reset_methods[n++] = i; + else if (rc != -ENOTTY) + break; + } - return pci_reset_bus_function(dev, 1); + memcpy(dev->reset_methods, reset_methods, sizeof(reset_methods)); } /** diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 93dcdd4310726..482d26cff7912 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -33,7 +33,8 @@ enum pci_mmap_api { int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai, enum pci_mmap_api mmap_api); -int pci_probe_reset_function(struct pci_dev *dev); +int pci_reset_supported(struct pci_dev *dev); +void pci_init_reset_methods(struct pci_dev *dev); int pci_bridge_secondary_bus_reset(struct pci_dev *dev); int pci_bus_error_reset(struct pci_dev *dev); @@ -610,6 +611,12 @@ struct pci_dev_reset_methods { int (*reset)(struct pci_dev *dev, int probe); }; +struct pci_reset_fn_method { + int (*reset_fn)(struct pci_dev *pdev, int probe); + char *name; +}; + +extern const struct pci_reset_fn_method pci_reset_fn_methods[]; #ifdef CONFIG_PCI_QUIRKS int pci_dev_specific_reset(struct pci_dev *dev, int probe); #else diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index d99ef232169e2..4ce7979d703eb 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2430,9 +2430,8 @@ static void pci_init_capabilities(struct pci_dev *dev) pci_rcec_init(dev); /* Root Complex Event Collector */ pcie_report_downtraining(dev); - - if (pci_probe_reset_function(dev) == 0) - dev->reset_fn = 1; + pci_init_reset_methods(dev); + dev->reset_fn = pci_reset_supported(dev); } /* diff --git a/include/linux/pci.h b/include/linux/pci.h index 5652214fe3a58..8c2d3a357eedb 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -49,6 +49,9 @@ PCI_STATUS_SIG_TARGET_ABORT | \ PCI_STATUS_PARITY) +/* Number of reset methods used in pci_reset_fn_methods array in pci.c */ +#define PCI_NUM_RESET_METHODS 6 + /* * The PCI interface treats multi-function devices as independent * devices. The slot/function address of each device is encoded @@ -506,6 +509,10 @@ struct pci_dev { char *driver_override; /* Driver name to force a match */ unsigned long priv_flags; /* Private flags for the PCI driver */ + /* + * See pci_reset_fn_methods array in pci.c for ordering. + */ + u8 reset_methods[PCI_NUM_RESET_METHODS]; /* Reset methods ordered by priority */ }; static inline struct pci_dev *pci_physfn(struct pci_dev *dev) From patchwork Fri Jul 16 15:19:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 12382479 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF90FC636CA for ; Fri, 16 Jul 2021 15:24:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3915613F8 for ; Fri, 16 Jul 2021 15:24:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240863AbhGPP1d (ORCPT ); Fri, 16 Jul 2021 11:27:33 -0400 Received: from mail-dm6nam11on2084.outbound.protection.outlook.com ([40.107.223.84]:52672 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240892AbhGPP12 (ORCPT ); Fri, 16 Jul 2021 11:27:28 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T63tSswUejcoMz0rU0esspATMwyo46SSUdUBT9oJkFl5ETbgOes3OBh65BpZO2hhvPafzaPDj5K2gzSnvtpyX7pxoyDuB79mrYx3ItXrrCdMrpgI//i+WZUBrG2MYitpLUW7PG3CKLYJpDFd8J0WP+IeUQ1lNJtQtXpWHcmipAwPXrBZfn2HEpsv3MYuntvzt4oWc97zetpHBWqyKujdVGZCBAajSklMZwRtswM6b3LWjN+rolTAGpu/tcQgbvFBm/w+3R5N8bhfPl1zoOO5ZhPIargYAALc5oLYUKnWx2uJP5fjHM8htuQ0nzUGGksgfkD5o9vt6cqqbEeRXzOblw== 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-SenderADCheck; bh=Pl+5ztjPoWm2qZQ0S94/WMf9XlisuAxbrMhd3ecEYH8=; b=FVJckbIjE348BksNZf+hmwRVDA/bF/xpIK3vbZbC3CvQNKwUKCwneyt1NROWa59yHtZuYT28X1x/wDq3Wiiu8jHhRtFY8eFCSbbDk83ksQKx3oaMfvCjDbRCSWPJ+EMc/ZQPpleRp0zv4aJFMDX9UMAJ7xoSDcSgyIagVIqDHJcy3xopiXxSF4hZZfXQQTtNGZgNGY2ByBIpS/3fDFd2ObfBWhpjETpHVtVtykEW9p2wR/qWDOaSOPTO8K3DZPZDuMcmuPhZvZyRiQnm/d4+xqPJhU7agXTNDE4rwfJhEFXroDcUWRX2Q6d5WEnUq+sYLpVT76r2e8cWUFG3kQdTvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=rjwysocki.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Pl+5ztjPoWm2qZQ0S94/WMf9XlisuAxbrMhd3ecEYH8=; b=gTWJtcaSEhroZCKD76Vu06QD3HKuBeMAUcE2ZuQt1XoegseCyN6IR+Ry7e6fdxz5IzrGvMfxhM9+riMIu3Vbjlo/j+w6mNmh7b3M7mvlBjrh+ETTJbzRW2Z4Jn4/YeYYr9rtxHeb0DYnmCLJZ0fZud1i5TXAegm6A5N8nJ6l2rEJ++Wb2qRsWGpDbx4MNS5vysXsciz/y3vUcp6fFMmon2j+dc3XfFS9Jf1zZ/J1Sswa33j0ce4AFEWBPHOCgWdtW3Oeq/bc5IcMo0hygUFnI6WUADoe1X0ycm5WAEaTrj7+/zTFW1c9yOUKjBB13Kp7pzSu8v/v7JoPSkq9rlHioA== Received: from BN6PR21CA0022.namprd21.prod.outlook.com (2603:10b6:404:8e::32) by BN8PR12MB3155.namprd12.prod.outlook.com (2603:10b6:408:97::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Fri, 16 Jul 2021 15:24:31 +0000 Received: from BN8NAM11FT044.eop-nam11.prod.protection.outlook.com (2603:10b6:404:8e:cafe::77) by BN6PR21CA0022.outlook.office365.com (2603:10b6:404:8e::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.2 via Frontend Transport; Fri, 16 Jul 2021 15:24:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; rjwysocki.net; dkim=none (message not signed) header.d=none;rjwysocki.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT044.mail.protection.outlook.com (10.13.177.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4331.21 via Frontend Transport; Fri, 16 Jul 2021 15:24:31 +0000 Received: from SDONTHINENI-DESKTOP.nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 16 Jul 2021 15:24:28 +0000 From: Shanker Donthineni To: Bjorn Helgaas CC: Alex Williamson , , , , Len Brown , "Rafael J . Wysocki" , Sinan Kaya , "Amey Narkhede" , Shanker Donthineni , Raphael Norwitz Subject: [PATCH v12 3/8] PCI: Remove reset_fn field from pci_dev Date: Fri, 16 Jul 2021 10:19:41 -0500 Message-ID: <20210716151946.690-4-sdonthineni@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210716151946.690-1-sdonthineni@nvidia.com> References: <20210716151946.690-1-sdonthineni@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 83cc6e2c-9db7-4354-a7be-08d9486dcf2e X-MS-TrafficTypeDiagnostic: BN8PR12MB3155: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3exZ0Of7SsVddA9bCKH0rNftnhelEvtu9witenCTYvQTEURQzrok4eY3bN2B7HqKtmoJlscxhNelDYhlBxBW+FtavwZxMmnpY74wEqrqR4y7P5Z2IWagwZlbCYWjFy7+eMfszKvx7hGtdKisE2OnjqCiXkS8flPH7gfAWul/aV5W8s0ES0gjgrP/sODGEDWFuR7l3A+3ihSlK7bXMdKUw+aBTeRi41SKxT8Vp5SG5SOwEGOtgv1purKwb+8+jACxJ2P2YqWfV8bVrc5MOttU9hcH+/HBmWDDS+JKt1Y6LLLseYzILut+a77fiB7c9M7vHpInI5rR04tcSnDvTWLl8KgOaMaX9Db6nizcVWcPdXHQ5/xd37zyhKNc3iqH+yzJG/2I0SGbOoX70VABgmIuB3qM93J5l38P1wLzhjM2n2rgXee00gSLLuMwXGjCyozR5cYdJ+CdGoEauaggqbFgrIXbE9UoxQ/5NFt+ciVdPM7DFmF2hUV/ROr63wgxfARbCpgmKbSg0hFXHLi9DFxx8v75lPxjqdNgdT1V6QqKoBoIs6axyfvpRrThO5Ld9ug+zHP7xun3e93auTEIACK26fRqZ06DGZ9Yw+uX2+4WpRr3HoMPFgJqC03kea25hCDZoj6nKZLhhvRKPjSGzyiU7enYfxhHSAkxc4/JoeWr4E5ATel5vPaLEQJVhb3HOxmlLYqAv9su4rYQDoASwy7gCbDgMy24ix06I/6O1eJajYA= X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(136003)(396003)(346002)(376002)(39860400002)(46966006)(36840700001)(8936002)(2616005)(2906002)(82310400003)(6666004)(70206006)(316002)(34020700004)(186003)(82740400003)(47076005)(5660300002)(426003)(16526019)(70586007)(478600001)(8676002)(26005)(6916009)(83380400001)(54906003)(36860700001)(336012)(36906005)(7696005)(7416002)(86362001)(36756003)(1076003)(7636003)(4326008)(356005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2021 15:24:31.2453 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 83cc6e2c-9db7-4354-a7be-08d9486dcf2e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT044.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3155 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Amey Narkhede reset_fn field is used to indicate whether the device supports any reset mechanism or not. Remove the use of reset_fn in favor of new reset_methods array which can be used to keep track of all supported reset mechanisms of a device and their ordering. The octeon driver is incorrectly using reset_fn field to detect if the device supports FLR or not. Use pcie_reset_flr() to probe whether it supports FLR or not. Reviewed-by: Alex Williamson Reviewed-by: Raphael Norwitz Co-developed-by: Alex Williamson Signed-off-by: Alex Williamson Signed-off-by: Amey Narkhede --- drivers/net/ethernet/cavium/liquidio/lio_vf_main.c | 2 +- drivers/pci/pci-sysfs.c | 2 +- drivers/pci/pci.c | 6 +++--- drivers/pci/probe.c | 1 - drivers/pci/quirks.c | 2 +- drivers/pci/remove.c | 1 - include/linux/pci.h | 1 - 7 files changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c index ffddb3126a323..d185df5acea69 100644 --- a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c +++ b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c @@ -526,7 +526,7 @@ static void octeon_destroy_resources(struct octeon_device *oct) oct->irq_name_storage = NULL; } /* Soft reset the octeon device before exiting */ - if (oct->pci_dev->reset_fn) + if (!pcie_reset_flr(oct->pci_dev, 1)) octeon_pci_flr(oct); else cn23xx_vf_ask_pf_to_do_flr(oct); diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 5d63df7c18206..a1d9b0e83615a 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1367,7 +1367,7 @@ static umode_t pci_dev_reset_attr_is_visible(struct kobject *kobj, { struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); - if (!pdev->reset_fn) + if (!pci_reset_supported(pdev)) return 0; return a->mode; diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 4d5618b232363..cc9f96effa546 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -5233,7 +5233,7 @@ int pci_reset_function(struct pci_dev *dev) { int rc; - if (!dev->reset_fn) + if (!pci_reset_supported(dev)) return -ENOTTY; pci_dev_lock(dev); @@ -5269,7 +5269,7 @@ int pci_reset_function_locked(struct pci_dev *dev) { int rc; - if (!dev->reset_fn) + if (!pci_reset_supported(dev)) return -ENOTTY; pci_dev_save_and_disable(dev); @@ -5292,7 +5292,7 @@ int pci_try_reset_function(struct pci_dev *dev) { int rc; - if (!dev->reset_fn) + if (!pci_reset_supported(dev)) return -ENOTTY; if (!pci_dev_trylock(dev)) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 4ce7979d703eb..66f052446de20 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2431,7 +2431,6 @@ static void pci_init_capabilities(struct pci_dev *dev) pcie_report_downtraining(dev); pci_init_reset_methods(dev); - dev->reset_fn = pci_reset_supported(dev); } /* diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index 90144fbc4f4ea..f43883a2e33df 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -5626,7 +5626,7 @@ static void quirk_reset_lenovo_thinkpad_p50_nvgpu(struct pci_dev *pdev) if (pdev->subsystem_vendor != PCI_VENDOR_ID_LENOVO || pdev->subsystem_device != 0x222e || - !pdev->reset_fn) + !pci_reset_supported(pdev)) return; if (pci_enable_device_mem(pdev)) diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index dd12c2fcc7dc1..4c54c75050dc1 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -19,7 +19,6 @@ static void pci_stop_dev(struct pci_dev *dev) pci_pme_active(dev, false); if (pci_dev_is_added(dev)) { - dev->reset_fn = 0; device_release_driver(&dev->dev); pci_proc_detach_device(dev); diff --git a/include/linux/pci.h b/include/linux/pci.h index 8c2d3a357eedb..58cc2e2b05051 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -431,7 +431,6 @@ struct pci_dev { unsigned int state_saved:1; unsigned int is_physfn:1; unsigned int is_virtfn:1; - unsigned int reset_fn:1; unsigned int is_hotplug_bridge:1; unsigned int shpc_managed:1; /* SHPC owned by shpchp */ unsigned int is_thunderbolt:1; /* Thunderbolt controller */ From patchwork Fri Jul 16 15:19:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 12382481 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0006C07E95 for ; Fri, 16 Jul 2021 15:24:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C991A613F5 for ; Fri, 16 Jul 2021 15:24:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240908AbhGPP1d (ORCPT ); Fri, 16 Jul 2021 11:27:33 -0400 Received: from mail-bn8nam11on2067.outbound.protection.outlook.com ([40.107.236.67]:35904 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240866AbhGPP1a (ORCPT ); Fri, 16 Jul 2021 11:27:30 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U37IcBeMST7N6a+dmaATLAd1u+2DY6XANUTy1IbdaV9A8JErVnR2DpPbZEmlgqCED75EzT7s3w9dJEHnmLSr8ySfc1L6IjH9k7cd3OAZ3Sr4HP05JMLJEL6NTijTaj76ke6Q4btLcNz65SEjrgNqOz/pApqzqKjFVkdbxP5+s48erosMg8rLIYCl0rjGX0AW5REtXhY/24GoNnDo+KrlcILEgP+TcATmbNz1LWQW+QfIVgqW9IDuLPcf9TPtBuwsyS9i/njppb/2Ewdx3dIQmOoIc3AQk/I62M9yF1xzth1j7o1fkT1f6RqYYoZ6+ZwtsLIx/g0YQUZ3K2QRiMS8YQ== 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-SenderADCheck; bh=MPy1cW+x+aIesqEakKo/iI1KkcGL54cHthCCKR1n5DA=; b=HFwRrgtHku6gxu8sbVpas3fiwaPeGMgn7JlKUwO5vrJA6CaAMfQXA5XCXeh5pUOnuvlEODsu9PuOZzm4JFGmSefHqzlZBDXPl2sd59Y8mXP2q2MVL68xQx6ppH8K6OyhyCd8ODnRDraZI8k/LpPaLiNexUj8AzvlQ+5J9dXtr5i87pSZuYg92lUP/vB9sXEKzZuXDCrl1Ve1ENn6oy/mMkoOXHm8BgffMe2Ejz72DeujO4qa1eDzCGl1Dg9d1S2bP9BeVNoKWPpRGaswCvc3UURUrW1BUaV5h6XWlMR9msyuN2xHFqYYNs3t56ChWgxXqlKE0eHK0f/KT9HGrexPRw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=rjwysocki.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MPy1cW+x+aIesqEakKo/iI1KkcGL54cHthCCKR1n5DA=; b=KIhZCbj3lrxrXaesU/BH/dZYdXxvWO2fM5q3gePScVZkHJ23hSRzK0Lwlc6CYqjr6A4H5JKK0oLak/ZqIExam954iKMD2TCh/rQ6Hpx/br/23ec0kDkN5PQWvAXYzIsz+7KZ0CHZbqmBlQdISHItNS2gUCD+FpFltZ4eI8OP5JpFNDfGtZzkOPoO6ZNDz6yM1x2bJ2SBoWe/5JEIs4c2xn9ACv22Baeewt4fVyNTx6nXB1OzNHREG/PMZ82xAlZqrW6Cwc44u8mkawZ0mzWICgLYunCK40kCk7XsqcWZK95y0Nhc8hBriblEm7wL3DeFuprcO0QalLZAUbrQnFSCeA== Received: from BN6PR13CA0027.namprd13.prod.outlook.com (2603:10b6:404:13e::13) by CO6PR12MB5474.namprd12.prod.outlook.com (2603:10b6:303:139::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.23; Fri, 16 Jul 2021 15:24:33 +0000 Received: from BN8NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:404:13e:cafe::19) by BN6PR13CA0027.outlook.office365.com (2603:10b6:404:13e::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.11 via Frontend Transport; Fri, 16 Jul 2021 15:24:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; rjwysocki.net; dkim=none (message not signed) header.d=none;rjwysocki.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT058.mail.protection.outlook.com (10.13.177.58) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4331.21 via Frontend Transport; Fri, 16 Jul 2021 15:24:33 +0000 Received: from SDONTHINENI-DESKTOP.nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 16 Jul 2021 15:24:30 +0000 From: Shanker Donthineni To: Bjorn Helgaas CC: Alex Williamson , , , , Len Brown , "Rafael J . Wysocki" , Sinan Kaya , "Amey Narkhede" , Shanker Donthineni , Leon Romanovsky Subject: [PATCH v12 4/8] PCI/sysfs: Allow userspace to query and set device reset mechanism Date: Fri, 16 Jul 2021 10:19:42 -0500 Message-ID: <20210716151946.690-5-sdonthineni@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210716151946.690-1-sdonthineni@nvidia.com> References: <20210716151946.690-1-sdonthineni@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cfa02b9c-fa86-4836-74c1-08d9486dd03c X-MS-TrafficTypeDiagnostic: CO6PR12MB5474: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1388; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NVR+1S6BwVRvANlBd//7v5GLGLEfziEf3WWpcvdlOTpylbE/SogmO/php8yN3YmMRIwFLwyRHE1wnmkY11YhwdcaugaRKxexnFDMmk117932UnNEV+NcHwemSeKaIiGHa/KlljWgftidCW5fays2syTFsEBjNRose+HS06olDQ53kK2NPeLKx4ApEziEhnpzMtB5uzdUiS9XD8SCBvb6uGMgZb6B2qacIkQGQ/wIbpOrrz+BFgQJID7xotiQVam3EY46/tCAW2FxhT1bR2HE+1sTIjAzV18CDlyHlFmhFo434p5x5Y66NuEeCYXdA0fkyKGAZdNkOBj0w88xL6QwQ2ueZyU9x73Bx7w/U4/iMRG2GrKiEzGxwhgAsPqgmfYOrWXowYZd0SLxl6nujZh23YJC50gDZcry2G/NwAoGAAL3m7jgK+qJN7CR8yhiXceh3KXzZtE67y86CP6q+CR+qaX/Lkk5vLpD9/8Vmo1bl692ZrUL+vb+s6K/tUHZXfaQxu86DXKliWH7aabSV1EwhVrizjF/fnNU6Sa564rfGWvwluR1t/nkDW2ExBsUbY3omt0rorbU/WJP5Sp8C9CU5qoyRD2DcxxlhRue5E+yhRtXHLgVUL2pGBOn2Nawem/OLyQqpVbTWWqIdXz3aIQeg22mdDLc2HGDfYMbW91LYGqSkU8sgO4KuU46pYOP+8ZuCWngsJ/kugkp0qhYksBtC+4coW4gARB3YWUrgCXBTHw= X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(396003)(346002)(376002)(39860400002)(136003)(46966006)(36840700001)(316002)(36906005)(70586007)(54906003)(8676002)(2616005)(6666004)(70206006)(8936002)(82310400003)(426003)(36860700001)(6916009)(36756003)(2906002)(5660300002)(4326008)(7636003)(82740400003)(47076005)(34020700004)(478600001)(83380400001)(107886003)(16526019)(186003)(356005)(336012)(26005)(86362001)(7696005)(1076003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2021 15:24:33.0204 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cfa02b9c-fa86-4836-74c1-08d9486dd03c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5474 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Amey Narkhede Add reset_method sysfs attribute to enable user to query and set user preferred device reset methods and their ordering. Co-developed-by: Alex Williamson Signed-off-by: Alex Williamson Signed-off-by: Amey Narkhede Reviewed-by: Leon Romanovsky --- Documentation/ABI/testing/sysfs-bus-pci | 19 +++++ drivers/pci/pci-sysfs.c | 103 ++++++++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci index 793cbb76cd250..beb94b9c18c78 100644 --- a/Documentation/ABI/testing/sysfs-bus-pci +++ b/Documentation/ABI/testing/sysfs-bus-pci @@ -121,6 +121,25 @@ Description: child buses, and re-discover devices removed earlier from this part of the device tree. +What: /sys/bus/pci/devices/.../reset_method +Date: March 2021 +Contact: Amey Narkhede +Description: + Some devices allow an individual function to be reset + without affecting other functions in the same slot. + + For devices that have this support, a file named + reset_method will be present in sysfs. Initially reading + this file will give names of the device supported reset + methods and their ordering. After write, this file will + give names and ordering of currently enabled reset methods. + Writing the name or comma separated list of names of any of + the device supported reset methods to this file will set + the reset methods and their ordering to be used when + resetting the device. Writing empty string to this file + will disable ability to reset the device and writing + "default" will return to the original value. + What: /sys/bus/pci/devices/.../reset Date: July 2009 Contact: Michael S. Tsirkin diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index a1d9b0e83615a..65791d8b07aa5 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1334,6 +1334,108 @@ static const struct attribute_group pci_dev_rom_attr_group = { .is_bin_visible = pci_dev_rom_attr_is_visible, }; +static ssize_t reset_method_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct pci_dev *pdev = to_pci_dev(dev); + ssize_t len = 0; + int i, idx; + + for (i = 0; i < PCI_NUM_RESET_METHODS; i++) { + idx = pdev->reset_methods[i]; + if (!idx) + break; + + len += sysfs_emit_at(buf, len, "%s%s", len ? "," : "", + pci_reset_fn_methods[idx].name); + } + + if (len) + len += sysfs_emit_at(buf, len, "\n"); + + return len; +} + +static ssize_t reset_method_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct pci_dev *pdev = to_pci_dev(dev); + int n = 0; + char *name, *options = NULL; + u8 reset_methods[PCI_NUM_RESET_METHODS] = { 0 }; + + if (count >= (PAGE_SIZE - 1)) + return -EINVAL; + + if (sysfs_streq(buf, "")) { + pci_warn(pdev, "All device reset methods disabled by user"); + goto set_reset_methods; + } + + if (sysfs_streq(buf, "default")) { + pci_init_reset_methods(pdev); + return count; + } + + options = kstrndup(buf, count, GFP_KERNEL); + if (!options) + return -ENOMEM; + + while ((name = strsep(&options, ",")) != NULL) { + int i; + + if (sysfs_streq(name, "")) + continue; + + name = strim(name); + + for (i = 1; i < PCI_NUM_RESET_METHODS; i++) { + if (sysfs_streq(name, pci_reset_fn_methods[i].name) && + !pci_reset_fn_methods[i].reset_fn(pdev, 1)) { + reset_methods[n++] = i; + break; + } + } + + if (i == PCI_NUM_RESET_METHODS) { + kfree(options); + return -EINVAL; + } + } + + if (!pci_reset_fn_methods[1].reset_fn(pdev, 1) && reset_methods[0] != 1) + pci_warn(pdev, "Device specific reset disabled/de-prioritized by user"); + +set_reset_methods: + memcpy(pdev->reset_methods, reset_methods, sizeof(reset_methods)); + kfree(options); + return count; +} +static DEVICE_ATTR_RW(reset_method); + +static struct attribute *pci_dev_reset_method_attrs[] = { + &dev_attr_reset_method.attr, + NULL, +}; + +static umode_t pci_dev_reset_method_attr_is_visible(struct kobject *kobj, + struct attribute *a, int n) +{ + struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj)); + + if (!pci_reset_supported(pdev)) + return 0; + + return a->mode; +} + +static const struct attribute_group pci_dev_reset_method_attr_group = { + .attrs = pci_dev_reset_method_attrs, + .is_visible = pci_dev_reset_method_attr_is_visible, +}; + static ssize_t reset_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -1491,6 +1593,7 @@ const struct attribute_group *pci_dev_groups[] = { &pci_dev_config_attr_group, &pci_dev_rom_attr_group, &pci_dev_reset_attr_group, + &pci_dev_reset_method_attr_group, &pci_dev_vpd_attr_group, #ifdef CONFIG_DMI &pci_dev_smbios_attr_group, From patchwork Fri Jul 16 15:19:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 12382485 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96509C12002 for ; Fri, 16 Jul 2021 15:24:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 837BC613F6 for ; Fri, 16 Jul 2021 15:24:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240945AbhGPP1i (ORCPT ); Fri, 16 Jul 2021 11:27:38 -0400 Received: from mail-dm6nam12on2055.outbound.protection.outlook.com ([40.107.243.55]:51520 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240765AbhGPP1c (ORCPT ); Fri, 16 Jul 2021 11:27:32 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TBCXfLpB6OhC33mIz1lje+kDWr2o9DmObgPO2GD/LixwX1JNjZg6GZXQx7lH/iv9KFaXvJI7g9GOlcxRkRE1yAupkRNHQbSPr+PWhxHcX1HozGSHwTDaMzvAUWBhvcPRyq43tLkRklXks5XqebOTuXzo9gDJGsmzTfCpTQi/wipx7vV8nGJ1bpV351YNmOh8/ZzOZCMEwK9rSlEpRN2sXTD3U9c2z/elD03tDUy3XuTixiOeAQHFo2DZXvSrNEDuypBNwzR/XAwDXDjqDl/BdZRsYPrbFnaVKWGSWqh5GWmsSIpRLCPmIVj9IzmXCVyQlykjLQNDy2OXrqOEHCTJaA== 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-SenderADCheck; bh=3ZGzr3fqG83VjVOwKMXfakYtivzpnToDyWUHo11oIx0=; b=cKEJGn1xyJifdsbxW7HC6PUo+lG51aXahZRCCoJ85B63fROBMDB6m9ZtCDlhBsUFWhQoYIuBrkcqPhQckWo7JzbxU0MVe0kl7Bzu+sGC6Vos51t3lTrpLVHrBDTiTtgfIX8Jj+4L+eCTc2gPEAZr3ipHotiN2fJSEJGfSNwtRNCfPt/VR4zYxGjV3XflZ83SRwBe2HGph8NWXum1IhNlhqZsk0qzgTQX0sC4zeSzhST/fIoo1Lu+czBsntOPXAAZT47vXbmmV+QRa2yQXI/9F24KNA06o9YHxr7PrqscHvU/61lDKXDhZRLUErsuLzGB2gx6H73syQ7ORyHQZzc2nQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=rjwysocki.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3ZGzr3fqG83VjVOwKMXfakYtivzpnToDyWUHo11oIx0=; b=mob0N+PL43djlHa4kY1N3Tu1x75ptj9Rv+YSkiAtnyQ2IneeAhJK06tNwKUAv0cVeVO4Yl39idWp/axtXC5xtY1vhYKbWiO7OQ+IyjjIZIU41hnh92GELtK4FR2+FQ9DWGwtSrET3MQbwmuHW8touS+BrzQ+2y06PiQmdT5SFTgBhdKSbG6cabN6ap7+aNL0vNY22i5znBGQmm3UJxFhiefPa/bIyVWk7cpCdoqelvm9JOsP+tGbgTANGr+0syI1Qy6NNl9TfOmIoWqQq9Hc5J/ybYWvq9cYyaZmMbNE4sRlQoSyL2S1FBmf4vI6mJ0UDlWPNpAz5H8w35nFnA+0UQ== Received: from BN9PR03CA0632.namprd03.prod.outlook.com (2603:10b6:408:13b::7) by BY5PR12MB3857.namprd12.prod.outlook.com (2603:10b6:a03:196::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.23; Fri, 16 Jul 2021 15:24:35 +0000 Received: from BN8NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13b:cafe::b0) by BN9PR03CA0632.outlook.office365.com (2603:10b6:408:13b::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.22 via Frontend Transport; Fri, 16 Jul 2021 15:24:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; rjwysocki.net; dkim=none (message not signed) header.d=none;rjwysocki.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT015.mail.protection.outlook.com (10.13.176.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4331.21 via Frontend Transport; Fri, 16 Jul 2021 15:24:34 +0000 Received: from SDONTHINENI-DESKTOP.nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 16 Jul 2021 15:24:32 +0000 From: Shanker Donthineni To: Bjorn Helgaas CC: Alex Williamson , , , , Len Brown , "Rafael J . Wysocki" , Sinan Kaya , "Amey Narkhede" , Shanker Donthineni Subject: [PATCH v12 5/8] PCI: Define a function to set ACPI_COMPANION in pci_dev Date: Fri, 16 Jul 2021 10:19:43 -0500 Message-ID: <20210716151946.690-6-sdonthineni@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210716151946.690-1-sdonthineni@nvidia.com> References: <20210716151946.690-1-sdonthineni@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 27357afa-ef47-4200-55cd-08d9486dd143 X-MS-TrafficTypeDiagnostic: BY5PR12MB3857: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2582; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8Sp9X3WWeC0EkLg+ApInu0Uj8Jur9PLPI2WQoPnS+6xki7mo3vMEycR8XUnRat91WpBlxttsSS/IRhtk/HVUc6lear4vLuszbaah+ois2zOogInlVJjpFc8ungwpjF2fiage4WHXaX7evaxHXMMoBqDPo51m8cL6kaGiU4vyaT1edAFDnEsKD4Coe4PX8JsPG1aciAACUGq1Sr7az7jNYroyy6piesTPM4/TGgxHCV4Gk9jxtK/kYWHS0hxJos//X3kT5ix4IIhDCfYLAoe52xhkVjLuqyeXGScCVaR24jMfzjaVewi5iXhjjgfxstU/oQAjN5lnc0LMbKGJjzU/SDJP75KSXuIDOXcG+f9RBwoTQziRttldl2RnTcgqbWINbJUpntBkvDyK+OxCGjS198NgVpESYmLhUogJ0qTKjIdf+Y7dpv9Lokzdqc0kGyC/QMqlRY8qfL2RgymIfeKVHAD9fcVik3KFQE8VtCN07vNjvTcpaSoX7NNzH9zmfFy6gmBjtGaTk6RsyaVC3w61EPcLV6fgzTi/X183H0RDrC8FuTzTJsoIr3yjl5tLyN5f2Vg5yX/pSgACayP92S+cBxjURWRbxHSLdvxjbHEU5jpiHsAdy+lh4Rz0ehXOEzRvxgzodQ085pbwndzaEP0P8APBNSCpSi40GXGl9I5g7HV4z5ANNnqQHWUxMGM1rFhv40gYJpxEnWVGTonFA5ypXVLG1vOfaC2KkDkej64V2Po= X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(376002)(346002)(136003)(396003)(39860400002)(36840700001)(46966006)(36906005)(7696005)(5660300002)(356005)(6666004)(2906002)(8936002)(7636003)(34020700004)(26005)(82310400003)(336012)(36860700001)(478600001)(86362001)(54906003)(186003)(316002)(6916009)(82740400003)(107886003)(70206006)(70586007)(83380400001)(426003)(16526019)(4326008)(2616005)(47076005)(1076003)(36756003)(8676002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2021 15:24:34.7362 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 27357afa-ef47-4200-55cd-08d9486dd143 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB3857 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Move the existing code logic from acpi_pci_bridge_d3() to a separate function pci_set_acpi_fwnode() to set the ACPI fwnode. No functional change with this patch. Signed-off-by: Shanker Donthineni Reviewed-by: Alex Williamson --- drivers/pci/pci-acpi.c | 12 ++++++++---- drivers/pci/pci.h | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index 36bc23e217592..eaddbf7017594 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -934,6 +934,13 @@ static pci_power_t acpi_pci_choose_state(struct pci_dev *pdev) static struct acpi_device *acpi_pci_find_companion(struct device *dev); +void pci_set_acpi_fwnode(struct pci_dev *dev) +{ + if (!ACPI_COMPANION(&dev->dev) && !pci_dev_is_added(dev)) + ACPI_COMPANION_SET(&dev->dev, + acpi_pci_find_companion(&dev->dev)); +} + static bool acpi_pci_bridge_d3(struct pci_dev *dev) { const struct fwnode_handle *fwnode; @@ -945,11 +952,8 @@ static bool acpi_pci_bridge_d3(struct pci_dev *dev) return false; /* Assume D3 support if the bridge is power-manageable by ACPI. */ + pci_set_acpi_fwnode(dev); adev = ACPI_COMPANION(&dev->dev); - if (!adev && !pci_dev_is_added(dev)) { - adev = acpi_pci_find_companion(&dev->dev); - ACPI_COMPANION_SET(&dev->dev, adev); - } if (adev && acpi_device_power_manageable(adev)) return true; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 482d26cff7912..37381734fcc78 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -708,7 +708,9 @@ static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL #ifdef CONFIG_ACPI int pci_acpi_program_hp_params(struct pci_dev *dev); extern const struct attribute_group pci_dev_acpi_attr_group; +void pci_set_acpi_fwnode(struct pci_dev *dev); #else +static inline void pci_set_acpi_fwnode(struct pci_dev *dev) {} static inline int pci_acpi_program_hp_params(struct pci_dev *dev) { return -ENODEV; From patchwork Fri Jul 16 15:19:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 12382483 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6902BC636CA for ; Fri, 16 Jul 2021 15:24:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4BFC8611F1 for ; Fri, 16 Jul 2021 15:24:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240955AbhGPP1h (ORCPT ); Fri, 16 Jul 2021 11:27:37 -0400 Received: from mail-bn8nam12on2086.outbound.protection.outlook.com ([40.107.237.86]:53856 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S237326AbhGPP1c (ORCPT ); Fri, 16 Jul 2021 11:27:32 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oLqg6u+srVNnQEoQ1QCHVEzNItL9Y1CqqlaloHKtK4V123Q8WRFZKH8my5Jp97fjKTdqwUJ91GZBxxMQANzvy1dLMN1Qo/kEnB8dZl52O1QZgMQjLjtiRqa7TTRDmCqwl8M2NjoivzWVH7JWQo8luIXHhcUsUcSr8b82SfzuOG7X2TZm+jDef0zgDgRDLU5Df4d7DAcD9piXhVBmozRz3IFhH2yzPe075vnAh9/vvHmlCRaNNNl8bhccf69nCRrj6heOJuJRp4wPfdBg5v0smLdfST0xSX8Mxp1Wm2sEzRizBZ2RImwFhqgs7XAl/hy2SonWYSYw2bwKsh9g32GKPw== 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-SenderADCheck; bh=j1smU2iB93tQPjFzQzhqdG79mTBolDEEd+p/AvMitkc=; b=hzmtPYlUCLMTkhNkYY+ogHx2ERNca/rPUFjSeRPQMAsv4+TS/NT0J7+knwVt8YDGcNW5+tl6FrePFXYnDn2ILKJNSXlB4aZuvJQxyst67wiOsqQTrOg5s8pVxyP+pP56hjEB9RgAIHbrEkAHMq06qCsvrr7bGpNvwKg7g6xAxVg4u2EnYUWzVkY6ele8NsI7m9Jx/pUEeMXwvgzVX2Fr/MLa9ThFbPmvIqGoofLCliwYS6aoopbRgxXHBKJp5tyaYiP3zBlx6Cxk/XYl+2FZEUM+M255+1vcB3XfQtNL2Go5A/7v5g6HAJr5iWON7vXYYoi22wyoQXooaLfPmrW8SA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=rjwysocki.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=j1smU2iB93tQPjFzQzhqdG79mTBolDEEd+p/AvMitkc=; b=BvKAmyy5SQjlxDZ73oUTkK1Eaf36XzsauOVmw2MnfB2QsOqEZ1MlwgaFe4TSBFy6KYSqwZfrE/Ltc45HneIMttdeW8T6/hAmQaHTGA/kxHzzsFAZUe2ampalQReNkS+smt+XH9t1ftK6kiaJoQ4K+ziKkE+lhvZy8NBCL1hBRbGw25o56W2SRYEqgD8fCipP08l+aEef5fJ8CbXSSyatjKPzXZS0XOidhq/dgsGm7loY8CygFuFyJcj6C6VixJ3PeziJqA3UqDfa4O6yCMmOLoa8llZm8ecI+/4mJDycoED5jfGSUKzNUODWRFzpyUtXHXBrRgc/+t7Bq7x8jLxKiQ== Received: from BN9PR03CA0633.namprd03.prod.outlook.com (2603:10b6:408:13b::8) by BN6PR12MB1426.namprd12.prod.outlook.com (2603:10b6:404:22::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.24; Fri, 16 Jul 2021 15:24:36 +0000 Received: from BN8NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13b:cafe::98) by BN9PR03CA0633.outlook.office365.com (2603:10b6:408:13b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Fri, 16 Jul 2021 15:24:36 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; rjwysocki.net; dkim=none (message not signed) header.d=none;rjwysocki.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT015.mail.protection.outlook.com (10.13.176.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4331.21 via Frontend Transport; Fri, 16 Jul 2021 15:24:36 +0000 Received: from SDONTHINENI-DESKTOP.nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 16 Jul 2021 15:24:34 +0000 From: Shanker Donthineni To: Bjorn Helgaas CC: Alex Williamson , , , , Len Brown , "Rafael J . Wysocki" , Sinan Kaya , "Amey Narkhede" , Shanker Donthineni Subject: [PATCH v12 6/8] PCI: Setup ACPI fwnode early and at the same time with OF Date: Fri, 16 Jul 2021 10:19:44 -0500 Message-ID: <20210716151946.690-7-sdonthineni@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210716151946.690-1-sdonthineni@nvidia.com> References: <20210716151946.690-1-sdonthineni@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8e425bfd-fc72-48c3-5d3b-08d9486dd24e X-MS-TrafficTypeDiagnostic: BN6PR12MB1426: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OUpYHXxwFLC1++aWTte3tLuVdO6uayT6Kqesr8l/0IejVs7GOcBfj0XV0fjyTQxEk0fVjfM33Fv1G7kwTcc/NXc2n4mz5ACtJUv3tbb8Z43XnHdT5VdNSkuX5BefkFJ+otms+s2/9rz76dWObkVX/RPb9MMGSaPSG+YIxje8rRS4EtA0wdgIkfFVipzN0njmE+e5h3tLD209TUYXYBoQqgijyTrhb/+F0A3IMLyvmkT0obn2hQUyhsc0THFBqO+fPhbjQfxD3DAnmbNlkWXDb0WocwBHLA2bIBiqu+YEsr5OUu5len3FaCZPiNhDew48JTPAkvAGtr/UNCYeGcEQoqup9sXbi219FwpRXfo08v9y/O6ZLOqI9R9qkOAN+LNlhotFJxtFqOQyZAr0uUVJIs27pLJ9ZhC3icBNlZR/gndc87JnXvuaZtFK4AdlNquOTYaF1q6jn6zbiqBnvizEkkC869QEjBGWCvVHWfz8KbcGCVcnh5s2pe6aKfC1+I6a/3kMyMYiGRmJt7760y5SskIt0RbnyyWBGr+cl6+A1O9y/0ZKE9vewJH4AfPqMBHTPN+DB+OOPGCzRc+pk1UH5WixtyVNjGo9Q815lFSZTtKwcLKaI4Z7PMJtTLe2u/tYJu3OeY36AtK60K+DdJndN238AM4RuRvhdFQAAhYCJdktneWYUe8lksXB3x1b0vKOnML96d45m9Ij47putmFEeUC0SUyJPbziGOFvVkYVyDRLR5B9jvkkkJK65WY5X6K8Ae+ohycu9IGqAdOtX9303A== X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(396003)(376002)(136003)(346002)(39860400002)(46966006)(36840700001)(70586007)(7696005)(316002)(107886003)(6916009)(6666004)(8936002)(2906002)(1076003)(4326008)(8676002)(16526019)(426003)(26005)(54906003)(336012)(186003)(478600001)(2616005)(36906005)(70206006)(82310400003)(5660300002)(82740400003)(36860700001)(356005)(86362001)(47076005)(36756003)(34020700004)(83380400001)(7636003)(21314003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2021 15:24:36.4753 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8e425bfd-fc72-48c3-5d3b-08d9486dd24e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1426 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The pci_dev objects are created through two mechanisms 1) during PCI bus scan and 2) from I/O Virtualization. The fwnode in pci_dev object is being set at different places depends on the type of firmware used, device creation mechanism, and acpi_pci_bridge_d3() WAR. The software features which have a dependency on ACPI fwnode properties and need to be handled before device_add() will not work. One use case, the software has to check the existence of _RST method to support ACPI based reset method. This patch does the two changes in order to provide fwnode consistently. - Set ACPI and OF fwnodes from pci_setup_device(). - Remove pci_set_acpi_fwnode() in acpi_pci_bridge_d3(). After this patch, ACPI/OF firmware properties are visible at the same time during the early stage of pci_dev setup. And also call sites should be able to use firmware agnostic functions device_property_xxx() for the early PCI quirks in the future. Signed-off-by: Shanker Donthineni Reviewed-by: Alex Williamson --- drivers/pci/pci-acpi.c | 1 - drivers/pci/probe.c | 7 ++++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index eaddbf7017594..dae021322b3fc 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -952,7 +952,6 @@ static bool acpi_pci_bridge_d3(struct pci_dev *dev) return false; /* Assume D3 support if the bridge is power-manageable by ACPI. */ - pci_set_acpi_fwnode(dev); adev = ACPI_COMPANION(&dev->dev); if (adev && acpi_device_power_manageable(adev)) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 66f052446de20..a0f20a6e3c04c 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1811,6 +1811,9 @@ int pci_setup_device(struct pci_dev *dev) dev->error_state = pci_channel_io_normal; set_pcie_port_type(dev); + pci_set_of_node(dev); + pci_set_acpi_fwnode(dev); + pci_dev_assign_slot(dev); /* @@ -1948,6 +1951,7 @@ int pci_setup_device(struct pci_dev *dev) default: /* unknown header */ pci_err(dev, "unknown header type %02x, ignoring device\n", dev->hdr_type); + pci_release_of_node(dev); return -EIO; bad: @@ -2376,10 +2380,7 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn) dev->vendor = l & 0xffff; dev->device = (l >> 16) & 0xffff; - pci_set_of_node(dev); - if (pci_setup_device(dev)) { - pci_release_of_node(dev); pci_bus_put(dev->bus); kfree(dev); return NULL; From patchwork Fri Jul 16 15:19:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 12382487 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E677C636CB for ; Fri, 16 Jul 2021 15:24:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6926E611F1 for ; Fri, 16 Jul 2021 15:24:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240965AbhGPP1j (ORCPT ); Fri, 16 Jul 2021 11:27:39 -0400 Received: from mail-mw2nam12on2053.outbound.protection.outlook.com ([40.107.244.53]:20289 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240913AbhGPP1e (ORCPT ); Fri, 16 Jul 2021 11:27:34 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hP1tH9CfPwTRZQYkhqa95uK6EgdViS3NeLidCdXyAxUWin+8WaA/TfTOw/WD8+1MNtQZUZ+ZsU6tP91LcR3o3KoGIzmCuI0HbJGEea4X8cuLyppiQVnWBsFd3nZ1VXSr6M6qkZEslOJaT8Jni8T3TvbYiDrgvIUQ0ecXGaXvf8AsIdYcxoas29g3OVaDhBfX60iaJOL9gzInxvzFavT+ZhgxDh+LDD6bJpbtBUMoEDOro9gaf7a8MUbmqcqem3uuT/BuskppWzYVXg6W1g5T+z+zK3onKosgCYqJq5LIEuBlv1LFN7KTntp94YpeGnEI7g2HLV2wNfA+qvl4gcgKew== 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-SenderADCheck; bh=ovzB+Qvsy37ejW46W9js0hCw+OSIiSu1ZGqRrn3/sv0=; b=GRkMAMYbwgiwPPavxumlueO7p0N+mzbCgy+MzQD3NLt7JrsBkgjlgOk11EOC0FRurLcOei2ZeXmUa70yLV/6/IM8oP+L4VPdLP/sQp9HI5UTczcbjEypOjRg8+7JADi6jL86+/MQG+EYTRpVptRSff1N9GUiHCoHbXKa7XEPDP1uEbc6zUwv0mhW0stIZ38fV44krXVrOaeJtxsAd2omT6tKvytlsKR2A00i4RXO+ly3VydX8T5QAyBpHObN/jHu2tf+YYbia+04is4V84MRhuDdQRpv55F2+uUofiXbXrt3r37g+mgy7pqNAtOOg9EsWQgGDMc1cIovIKuoc2ph0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=rjwysocki.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ovzB+Qvsy37ejW46W9js0hCw+OSIiSu1ZGqRrn3/sv0=; b=c6izm6JAKJEdCct8oS40OPIT1LYGPGABezo30kvgi+IFRcLY4//jL8kzAO5+dywyUVvFtS0VADvNWYcEyoMcFhKFFRttnoDvsNmvW37Y5Tb521P6cPpq2xcArxE7yH+v8sxzEghTGA6tOlQxmT67wBZTeldCMOZs8m8vEA+ljvMQz8kns1vvhdQrgxwChLOly3fkLYTQLz7xa9pc/X++ey/HXPgKuZ0Nfo1eZe2stuT8uPjXq25R1FNJUG7H39i+9KnYk3URGV/dYlgBWVxsgyoOMh1O4t2XcRWNczkUtmBivBql9DEFTmspLoFDagnlyD4cHtI0KQGD12L9ZoVtuw== Received: from BN9PR03CA0656.namprd03.prod.outlook.com (2603:10b6:408:13b::31) by MWHPR12MB1389.namprd12.prod.outlook.com (2603:10b6:300:13::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Fri, 16 Jul 2021 15:24:38 +0000 Received: from BN8NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13b:cafe::14) by BN9PR03CA0656.outlook.office365.com (2603:10b6:408:13b::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Fri, 16 Jul 2021 15:24:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; rjwysocki.net; dkim=none (message not signed) header.d=none;rjwysocki.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT015.mail.protection.outlook.com (10.13.176.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4331.21 via Frontend Transport; Fri, 16 Jul 2021 15:24:37 +0000 Received: from SDONTHINENI-DESKTOP.nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 16 Jul 2021 15:24:35 +0000 From: Shanker Donthineni To: Bjorn Helgaas CC: Alex Williamson , , , , Len Brown , "Rafael J . Wysocki" , Sinan Kaya , "Amey Narkhede" , Shanker Donthineni Subject: [PATCH v12 7/8] PCI: Add support for ACPI _RST reset method Date: Fri, 16 Jul 2021 10:19:45 -0500 Message-ID: <20210716151946.690-8-sdonthineni@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210716151946.690-1-sdonthineni@nvidia.com> References: <20210716151946.690-1-sdonthineni@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 25bd0648-dc28-4eab-d3eb-08d9486dd330 X-MS-TrafficTypeDiagnostic: MWHPR12MB1389: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YfCmMGBlr732wJkhI1KeYGlNtQLocENOggKw6hdG0JxCOcvdDZq/LS2H7raIlcobIMSZe8PUKh+YTaTeAoePZYBudnk728uDEGKPxfEe4DfRidr7QXmNbCf0s4gama9Zfo73NVvSuWb+yvhLMFuDJjG2Zjm+UdebB252SrfLX1O1cm7DC09mJugS08Mcl2MAX7UOS9Frjr3EuvpWp5XhcL8lH/nTLinJzkFVXoeHiTWXPIwpXFjKvG5wSiDbU9s4EPK7P5QiGY4PbCbuOIEeq9wuwURfBuEQU8vta7l9QBWVyMqmdteRpxWDthjzt1LB0WPw9u0g3+prXZ8jYo6DwzAIJQlEJcM0QmyBsY5GMUlYnBtvsUWrYs01FLHzA83TA0DgQKbMI5rRa35+HH/Sr95IfGc+O5Y4/yvDZRwHu+8ku02S7ChoxaIOiJb82CM2++f2ylpWO+oHpaLUVKRMkYEudhHkpFB/G4VnZfuPTsdJeu0nQjJD38oIHbvR7T6eTPtxjmO+sRr5hxW533bbNZTrHI53OepYEk90l5FDPsXYg2o8sJ8zA1NLwl3JDFH/ckgfew1ZIi+dVWXpBATrWgOgvojaR/nLjvyWss6IfbkNyC7e4ko16LewQ2EeCB1xtEErDeKsWxPWypN2SDmS00c6/UEL8/Tfj/q+uxmqa3nV5geJ2lRA3M80FE/WE7DbPCXnUFqFxSZvtjvtNagp9alTV6zpJs6u8l8sAB5n8jo= X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(356005)(4326008)(107886003)(83380400001)(26005)(36860700001)(1076003)(316002)(186003)(36756003)(54906003)(6916009)(5660300002)(36906005)(16526019)(47076005)(34020700004)(8936002)(2906002)(7636003)(426003)(6666004)(70586007)(2616005)(7696005)(86362001)(82310400003)(336012)(508600001)(8676002)(70206006);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2021 15:24:37.9534 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 25bd0648-dc28-4eab-d3eb-08d9486dd330 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1389 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org The _RST is a standard method specified in the ACPI specification. It provides a function level reset when it is described in the acpi_device context associated with PCI-device. Implement a new reset function pci_dev_acpi_reset() for probing RST method and execute if it is defined in the firmware. The default priority of the ACPI reset is set to below device-specific and above hardware resets. Signed-off-by: Shanker Donthineni Suggested-by: Alex Williamson Reviewed-by: Sinan Kaya Reviewed-by: Alex Williamson --- drivers/pci/pci-acpi.c | 23 +++++++++++++++++++++++ drivers/pci/pci.c | 1 + drivers/pci/pci.h | 6 ++++++ include/linux/pci.h | 2 +- 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index dae021322b3fc..31f76746741f5 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -941,6 +941,29 @@ void pci_set_acpi_fwnode(struct pci_dev *dev) acpi_pci_find_companion(&dev->dev)); } +/** + * pci_dev_acpi_reset - do a function level reset using _RST method + * @dev: device to reset + * @probe: check if _RST method is included in the acpi_device context. + */ +int pci_dev_acpi_reset(struct pci_dev *dev, int probe) +{ + acpi_handle handle = ACPI_HANDLE(&dev->dev); + + if (!handle || !acpi_has_method(handle, "_RST")) + return -ENOTTY; + + if (probe) + return 0; + + if (ACPI_FAILURE(acpi_evaluate_object(handle, "_RST", NULL, NULL))) { + pci_warn(dev, "ACPI _RST failed\n"); + return -ENOTTY; + } + + return 0; +} + static bool acpi_pci_bridge_d3(struct pci_dev *dev) { const struct fwnode_handle *fwnode; diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index cc9f96effa546..8aab4097f80bc 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -5127,6 +5127,7 @@ static void pci_dev_restore(struct pci_dev *dev) const struct pci_reset_fn_method pci_reset_fn_methods[] = { { }, { &pci_dev_specific_reset, .name = "device_specific" }, + { &pci_dev_acpi_reset, .name = "acpi" }, { &pcie_reset_flr, .name = "flr" }, { &pci_af_flr, .name = "af_flr" }, { &pci_pm_reset, .name = "pm" }, diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 37381734fcc78..699d14243867a 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -709,7 +709,13 @@ static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL int pci_acpi_program_hp_params(struct pci_dev *dev); extern const struct attribute_group pci_dev_acpi_attr_group; void pci_set_acpi_fwnode(struct pci_dev *dev); +int pci_dev_acpi_reset(struct pci_dev *dev, int probe); #else +static inline int pci_dev_acpi_reset(struct pci_dev *dev, int probe) +{ + return -ENOTTY; +} + static inline void pci_set_acpi_fwnode(struct pci_dev *dev) {} static inline int pci_acpi_program_hp_params(struct pci_dev *dev) { diff --git a/include/linux/pci.h b/include/linux/pci.h index 58cc2e2b05051..698a668828f66 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -50,7 +50,7 @@ PCI_STATUS_PARITY) /* Number of reset methods used in pci_reset_fn_methods array in pci.c */ -#define PCI_NUM_RESET_METHODS 6 +#define PCI_NUM_RESET_METHODS 7 /* * The PCI interface treats multi-function devices as independent From patchwork Fri Jul 16 15:19:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shanker Donthineni X-Patchwork-Id: 12382489 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47E5BC636CD for ; Fri, 16 Jul 2021 15:24:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 32C40613F5 for ; Fri, 16 Jul 2021 15:24:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240984AbhGPP1l (ORCPT ); Fri, 16 Jul 2021 11:27:41 -0400 Received: from mail-mw2nam12on2053.outbound.protection.outlook.com ([40.107.244.53]:11488 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240950AbhGPP1h (ORCPT ); Fri, 16 Jul 2021 11:27:37 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GqG8EthRYljiWL6tWFlrRC10Fm0nMpX93Pwxgv9yRo+6F4BU65O2MeQEVT3LYgf7dzJBNbf9Hl0Ue+rFnILz92EXcDTo8AAAW+Zys7KyZ/rB67bELtGiiXmIH0odw+5J05lR2rOIA4TbFkSBG0e3ewUt+qeb3TmrWWLhc8gsFxamx4GzCR13IZ2SmgfzDg0bIXTGz0ut18R9yay08lW9557o6c62assxJsJR54CiMdPHK3qnbxirD/IwJFE+g5NH5RQlso74qoCVR7uH2csLXkp6Tmc/av6kB3uVLmTpNggBMAtE7SMz4nWWWrfN/2EEMxB3gbFtIQxA/kr+vF3kdA== 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-SenderADCheck; bh=EgX8pxJBCFIwVSUfnLxjuJM10cAnpiQahGUcJ/gQyvg=; b=QCUenMsos9+02k8x+ZpRbgstQOpq3NVnTOTfbk2OptyytdkfbTbGXeVgqsY7oHJkVxJTKHBVLPKDSr3CwjcuYOspoAOePib/coXGzYK5Z8edSQjZ/+xFlazMT4Q9epN9sxS/SB7ajOsqbYQTwYHpEe+dP08GVBPoXUX2hkqZ8dIYY4zdZTBy6Tkb5icUlpuMeRWWWYNoAS+7Xy0tpozX0BsI9nS/74SvW0maZr6Wai+9ugdSetVzhRQlrnxSfUTPZuXf/Ckj4jU1CamGXQR7TlSM26qg+VOjDI0AHuvP7wk7ZVhFcRKU93gn442xntOKksmeGn8VlGAWqqXGy1ip8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=rjwysocki.net smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EgX8pxJBCFIwVSUfnLxjuJM10cAnpiQahGUcJ/gQyvg=; b=NJiSvVyYpSUrZmYcG+4zogSP8Q+0zYVX/0W9jS3qrknupM0SQNlla6/ggWET6/z5+WH4p9t1EzsB69rWl1ARoS5Mz9IYm1aPDfrai4u1neyHW3KZxVvd7qmlKpHRzVTgpsY6VR+BvnUWcQYwttW8tu70OCFOlvATlIUQZlyOPXWL8H1RIuVl9MA5yPAzAFOmJNRBPdWWbP4v3d8EN6y23kw3PI/TzG3HB5CnqGF9p5EwK00CYhxSdzdvNkRd/sFO1Vf41wuwy3doxVLMSoosZ9y2bKRf7wi7jIe+ZJVIEVRA4i0xH9IIBO9+fD8M6DB6PoCkOSvjWBso5ipUi2pLKw== Received: from BN9PR03CA0352.namprd03.prod.outlook.com (2603:10b6:408:f6::27) by DM5PR12MB1723.namprd12.prod.outlook.com (2603:10b6:3:111::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.22; Fri, 16 Jul 2021 15:24:40 +0000 Received: from BN8NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f6:cafe::c5) by BN9PR03CA0352.outlook.office365.com (2603:10b6:408:f6::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.23 via Frontend Transport; Fri, 16 Jul 2021 15:24:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; rjwysocki.net; dkim=none (message not signed) header.d=none;rjwysocki.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT034.mail.protection.outlook.com (10.13.176.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4331.21 via Frontend Transport; Fri, 16 Jul 2021 15:24:39 +0000 Received: from SDONTHINENI-DESKTOP.nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 16 Jul 2021 15:24:37 +0000 From: Shanker Donthineni To: Bjorn Helgaas CC: Alex Williamson , , , , Len Brown , "Rafael J . Wysocki" , Sinan Kaya , "Amey Narkhede" , Shanker Donthineni Subject: [PATCH v12 8/8] PCI: Change the type of probe argument in reset functions Date: Fri, 16 Jul 2021 10:19:46 -0500 Message-ID: <20210716151946.690-9-sdonthineni@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210716151946.690-1-sdonthineni@nvidia.com> References: <20210716151946.690-1-sdonthineni@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ac60ad82-e9e9-4423-517d-08d9486dd44c X-MS-TrafficTypeDiagnostic: DM5PR12MB1723: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4S/Mr7uMqBVYnQsaIRhgESvr0QRWiGqo2ExKQBWcUWBYRLGI/2x32zUgzI26SzCp1QfrRt74ve8bJ0JlQc7K9WOn88Escsw6mF7C4SVsvld+ipHxYREVu11eoCCtDyHTUZT0VQMzqKuy4js2cKav/5Rqb9BWKoUhHlXTWPq3QvbNHQiDAyhDBi1gmcz8qX+oIus01yoh1HDksoa1jetFhpS3WZfH9cU546PrVFAarvsJLRk4giZjqfmXNZG7IqCojRxTEf1/c9L6FDmeTskCXwy0gVMHNSwjF5Ihz+U+q+FkKAgqbRH/jQeibHACkytdJISlRl4BIlpSNMsIWf1aqQAn4Wleh7o8+DejenfkdFAkP5XeMGrQcsX801bg0fwDbkrAJxphoQ8F6pmIM+L4/9kHt3B0FRlP4gOdFC0+lXjElH/zWTAUjPjLyxbjkHRbfL9H2KB8a0akFyxpKFAlrJEyZOBYA4jTQjWpPyVbpXuGetfXWQcGGBD7DS0H9BpZDy/iPXlNigdWB9uPz2HQ3cD2HYoBqmJm3Mr6rRYHj/KgA28KGVZFvF2du53r8WjrKEhtSbsSK9wlZ5IJK6k8z4mniXkV55ExwPDnqFOXLuhV1YQjT6rFcQZi5Q6EZVePDsv3HHv3ng/bekkYlyfPTGOr6Q9vkS1V9l3ZLg7vyEbqNPDoxpmojzWqgYi/d8AV9uLFKkU9tskehav4tsaFxv9p0kJ15mMXEFjGqtB6wD29B3NM/nd5USehDT3JcwOro7L94DftFIJ161BlFwImV1T8B/5gwyJq7DGfAOdwm1H8edGiKY5cBS61v2jfJFb/ X-Forefront-Antispam-Report: CIP:216.228.112.34;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid03.nvidia.com;CAT:NONE;SFS:(4636009)(396003)(136003)(39860400002)(376002)(346002)(46966006)(36840700001)(47076005)(5660300002)(16526019)(8936002)(966005)(6666004)(2906002)(26005)(186003)(4326008)(478600001)(336012)(83380400001)(426003)(70586007)(7696005)(70206006)(6916009)(82740400003)(356005)(7636003)(34020700004)(66574015)(54906003)(107886003)(2616005)(8676002)(316002)(36756003)(36860700001)(1076003)(36906005)(82310400003)(86362001)(30864003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2021 15:24:39.7633 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ac60ad82-e9e9-4423-517d-08d9486dd44c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.34];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1723 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Amey Narkhede Introduce a new enum pci_reset_mode_t to make the context of probe argument in reset functions clear and the code easier to read. Change the type of probe argument in functions which implement reset methods from int to pci_reset_mode_t to make the intent clear. Add a new line in return statement of pci_reset_bus_function(). Suggested-by: Alex Williamson Suggested-by: Krzysztof WilczyƄski Signed-off-by: Amey Narkhede Reviewed-by: Alex Williamson --- drivers/crypto/cavium/nitrox/nitrox_main.c | 2 +- .../ethernet/cavium/liquidio/lio_vf_main.c | 2 +- drivers/pci/hotplug/pciehp.h | 2 +- drivers/pci/hotplug/pciehp_hpc.c | 4 +- drivers/pci/hotplug/pnv_php.c | 4 +- drivers/pci/pci-acpi.c | 10 ++- drivers/pci/pci-sysfs.c | 6 +- drivers/pci/pci.c | 85 ++++++++++++------- drivers/pci/pci.h | 12 +-- drivers/pci/pcie/aer.c | 2 +- drivers/pci/quirks.c | 37 ++++---- include/linux/pci.h | 8 +- include/linux/pci_hotplug.h | 2 +- 13 files changed, 107 insertions(+), 69 deletions(-) diff --git a/drivers/crypto/cavium/nitrox/nitrox_main.c b/drivers/crypto/cavium/nitrox/nitrox_main.c index 2db3fd5815c82..6c61817996a33 100644 --- a/drivers/crypto/cavium/nitrox/nitrox_main.c +++ b/drivers/crypto/cavium/nitrox/nitrox_main.c @@ -306,7 +306,7 @@ static int nitrox_device_flr(struct pci_dev *pdev) return -ENOMEM; } - pcie_reset_flr(pdev, 0); + pcie_reset_flr(pdev, PCI_RESET_DO_RESET); pci_restore_state(pdev); diff --git a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c index d185df5acea69..ac821c5532a4e 100644 --- a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c +++ b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c @@ -526,7 +526,7 @@ static void octeon_destroy_resources(struct octeon_device *oct) oct->irq_name_storage = NULL; } /* Soft reset the octeon device before exiting */ - if (!pcie_reset_flr(oct->pci_dev, 1)) + if (!pcie_reset_flr(oct->pci_dev, PCI_RESET_PROBE)) octeon_pci_flr(oct); else cn23xx_vf_ask_pf_to_do_flr(oct); diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h index d4a930881054d..6c5de749ece82 100644 --- a/drivers/pci/hotplug/pciehp.h +++ b/drivers/pci/hotplug/pciehp.h @@ -184,7 +184,7 @@ void pciehp_release_ctrl(struct controller *ctrl); int pciehp_sysfs_enable_slot(struct hotplug_slot *hotplug_slot); int pciehp_sysfs_disable_slot(struct hotplug_slot *hotplug_slot); -int pciehp_reset_slot(struct hotplug_slot *hotplug_slot, int probe); +int pciehp_reset_slot(struct hotplug_slot *hotplug_slot, pci_reset_mode_t mode); int pciehp_get_attention_status(struct hotplug_slot *hotplug_slot, u8 *status); int pciehp_set_raw_indicator_status(struct hotplug_slot *h_slot, u8 status); int pciehp_get_raw_indicator_status(struct hotplug_slot *h_slot, u8 *status); diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 9d06939736c0f..67fd7024a29aa 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -870,14 +870,14 @@ void pcie_disable_interrupt(struct controller *ctrl) * momentarily, if we see that they could interfere. Also, clear any spurious * events after. */ -int pciehp_reset_slot(struct hotplug_slot *hotplug_slot, int probe) +int pciehp_reset_slot(struct hotplug_slot *hotplug_slot, pci_reset_mode_t mode) { struct controller *ctrl = to_ctrl(hotplug_slot); struct pci_dev *pdev = ctrl_dev(ctrl); u16 stat_mask = 0, ctrl_mask = 0; int rc; - if (probe) + if (mode == PCI_RESET_PROBE) return 0; down_write(&ctrl->reset_lock); diff --git a/drivers/pci/hotplug/pnv_php.c b/drivers/pci/hotplug/pnv_php.c index 04565162a4495..77df598c8deaf 100644 --- a/drivers/pci/hotplug/pnv_php.c +++ b/drivers/pci/hotplug/pnv_php.c @@ -526,7 +526,7 @@ static int pnv_php_enable(struct pnv_php_slot *php_slot, bool rescan) return 0; } -static int pnv_php_reset_slot(struct hotplug_slot *slot, int probe) +static int pnv_php_reset_slot(struct hotplug_slot *slot, pci_reset_mode_t mode) { struct pnv_php_slot *php_slot = to_pnv_php_slot(slot); struct pci_dev *bridge = php_slot->pdev; @@ -537,7 +537,7 @@ static int pnv_php_reset_slot(struct hotplug_slot *slot, int probe) * which don't have a bridge. Only claim to support * reset_slot() if we have a bridge device (for now...) */ - if (probe) + if (mode == PCI_RESET_PROBE) return !bridge; /* mask our interrupt while resetting the bridge */ diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index 31f76746741f5..4cb84ce6829f7 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -944,16 +944,20 @@ void pci_set_acpi_fwnode(struct pci_dev *dev) /** * pci_dev_acpi_reset - do a function level reset using _RST method * @dev: device to reset - * @probe: check if _RST method is included in the acpi_device context. + * @probe: If PCI_RESET_PROBE, check whether _RST method is included + * in the acpi_device context. */ -int pci_dev_acpi_reset(struct pci_dev *dev, int probe) +int pci_dev_acpi_reset(struct pci_dev *dev, pci_reset_mode_t mode) { acpi_handle handle = ACPI_HANDLE(&dev->dev); + if (mode >= PCI_RESET_MODE_MAX) + return -EINVAL; + if (!handle || !acpi_has_method(handle, "_RST")) return -ENOTTY; - if (probe) + if (mode == PCI_RESET_PROBE) return 0; if (ACPI_FAILURE(acpi_evaluate_object(handle, "_RST", NULL, NULL))) { diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 65791d8b07aa5..87dbe33fb149e 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1393,7 +1393,8 @@ static ssize_t reset_method_store(struct device *dev, for (i = 1; i < PCI_NUM_RESET_METHODS; i++) { if (sysfs_streq(name, pci_reset_fn_methods[i].name) && - !pci_reset_fn_methods[i].reset_fn(pdev, 1)) { + !pci_reset_fn_methods[i].reset_fn(pdev, + PCI_RESET_PROBE)) { reset_methods[n++] = i; break; } @@ -1405,7 +1406,8 @@ static ssize_t reset_method_store(struct device *dev, } } - if (!pci_reset_fn_methods[1].reset_fn(pdev, 1) && reset_methods[0] != 1) + if (!pci_reset_fn_methods[1].reset_fn(pdev, PCI_RESET_PROBE) && + reset_methods[0] != 1) pci_warn(pdev, "Device specific reset disabled/de-prioritized by user"); set_reset_methods: diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 8aab4097f80bc..5a2452d0f1771 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4660,30 +4660,36 @@ EXPORT_SYMBOL_GPL(pcie_flr); /** * pcie_reset_flr - initiate a PCIe function level reset * @dev: device to reset - * @probe: If set, only check if the device can be reset this way. + * @mode: If PCI_RESET_PROBE, only check if the device can be reset this way. * * Initiate a function level reset on @dev. */ -int pcie_reset_flr(struct pci_dev *dev, int probe) +int pcie_reset_flr(struct pci_dev *dev, pci_reset_mode_t mode) { + if (mode >= PCI_RESET_MODE_MAX) + return -EINVAL; + if (dev->dev_flags & PCI_DEV_FLAGS_NO_FLR_RESET) return -ENOTTY; if (!dev->has_pcie_flr) return -ENOTTY; - if (probe) + if (mode == PCI_RESET_PROBE) return 0; return pcie_flr(dev); } EXPORT_SYMBOL_GPL(pcie_reset_flr); -static int pci_af_flr(struct pci_dev *dev, int probe) +static int pci_af_flr(struct pci_dev *dev, pci_reset_mode_t mode) { int pos; u8 cap; + if (mode >= PCI_RESET_MODE_MAX) + return -EINVAL; + pos = pci_find_capability(dev, PCI_CAP_ID_AF); if (!pos) return -ENOTTY; @@ -4695,7 +4701,7 @@ static int pci_af_flr(struct pci_dev *dev, int probe) if (!(cap & PCI_AF_CAP_TP) || !(cap & PCI_AF_CAP_FLR)) return -ENOTTY; - if (probe) + if (mode == PCI_RESET_PROBE) return 0; /* @@ -4726,7 +4732,7 @@ static int pci_af_flr(struct pci_dev *dev, int probe) /** * pci_pm_reset - Put device into PCI_D3 and back into PCI_D0. * @dev: Device to reset. - * @probe: If set, only check if the device can be reset this way. + * @mode: If PCI_RESET_PROBE, only check if the device can be reset this way. * * If @dev supports native PCI PM and its PCI_PM_CTRL_NO_SOFT_RESET flag is * unset, it will be reinitialized internally when going from PCI_D3hot to @@ -4738,10 +4744,13 @@ static int pci_af_flr(struct pci_dev *dev, int probe) * by default (i.e. unless the @dev's d3hot_delay field has a different value). * Moreover, only devices in D0 can be reset by this function. */ -static int pci_pm_reset(struct pci_dev *dev, int probe) +static int pci_pm_reset(struct pci_dev *dev, pci_reset_mode_t mode) { u16 csr; + if (mode >= PCI_RESET_MODE_MAX) + return -EINVAL; + if (!dev->pm_cap || dev->dev_flags & PCI_DEV_FLAGS_NO_PM_RESET) return -ENOTTY; @@ -4749,7 +4758,7 @@ static int pci_pm_reset(struct pci_dev *dev, int probe) if (csr & PCI_PM_CTRL_NO_SOFT_RESET) return -ENOTTY; - if (probe) + if (mode == PCI_RESET_PROBE) return 0; if (dev->current_state != PCI_D0) @@ -4998,10 +5007,13 @@ int pci_bridge_secondary_bus_reset(struct pci_dev *dev) } EXPORT_SYMBOL_GPL(pci_bridge_secondary_bus_reset); -static int pci_parent_bus_reset(struct pci_dev *dev, int probe) +static int pci_parent_bus_reset(struct pci_dev *dev, pci_reset_mode_t mode) { struct pci_dev *pdev; + if (mode >= PCI_RESET_MODE_MAX) + return -EINVAL; + if (pci_is_root_bus(dev->bus) || dev->subordinate || !dev->bus->self || dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET) return -ENOTTY; @@ -5010,44 +5022,47 @@ static int pci_parent_bus_reset(struct pci_dev *dev, int probe) if (pdev != dev) return -ENOTTY; - if (probe) + if (mode == PCI_RESET_PROBE) return 0; return pci_bridge_secondary_bus_reset(dev->bus->self); } -static int pci_reset_hotplug_slot(struct hotplug_slot *hotplug, int probe) +static int pci_reset_hotplug_slot(struct hotplug_slot *hotplug, pci_reset_mode_t mode) { int rc = -ENOTTY; + if (mode >= PCI_RESET_MODE_MAX) + return -EINVAL; + if (!hotplug || !try_module_get(hotplug->owner)) return rc; if (hotplug->ops->reset_slot) - rc = hotplug->ops->reset_slot(hotplug, probe); + rc = hotplug->ops->reset_slot(hotplug, mode); module_put(hotplug->owner); return rc; } -static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe) +static int pci_dev_reset_slot_function(struct pci_dev *dev, pci_reset_mode_t mode) { if (dev->multifunction || dev->subordinate || !dev->slot || dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET) return -ENOTTY; - return pci_reset_hotplug_slot(dev->slot->hotplug, probe); + return pci_reset_hotplug_slot(dev->slot->hotplug, mode); } -static int pci_reset_bus_function(struct pci_dev *dev, int probe) +static int pci_reset_bus_function(struct pci_dev *dev, pci_reset_mode_t mode) { int rc; - rc = pci_dev_reset_slot_function(dev, probe); + rc = pci_dev_reset_slot_function(dev, mode); if (rc != -ENOTTY) return rc; - return pci_parent_bus_reset(dev, probe); + return pci_parent_bus_reset(dev, mode); } static void pci_dev_lock(struct pci_dev *dev) @@ -5169,7 +5184,7 @@ int __pci_reset_function_locked(struct pci_dev *dev) * mechanisms might be broken on the device. */ for (i = 0; i < PCI_NUM_RESET_METHODS && (m = dev->reset_methods[i]); i++) { - rc = pci_reset_fn_methods[m].reset_fn(dev, 0); + rc = pci_reset_fn_methods[m].reset_fn(dev, PCI_RESET_DO_RESET); if (!rc) return 0; if (rc != -ENOTTY) @@ -5204,7 +5219,7 @@ void pci_init_reset_methods(struct pci_dev *dev) might_sleep(); for (i = 1; i < PCI_NUM_RESET_METHODS; i++) { - rc = pci_reset_fn_methods[i].reset_fn(dev, 1); + rc = pci_reset_fn_methods[i].reset_fn(dev, PCI_RESET_PROBE); if (!rc) reset_methods[n++] = i; else if (rc != -ENOTTY) @@ -5521,21 +5536,24 @@ static void pci_slot_restore_locked(struct pci_slot *slot) } } -static int pci_slot_reset(struct pci_slot *slot, int probe) +static int pci_slot_reset(struct pci_slot *slot, pci_reset_mode_t mode) { int rc; + if (mode >= PCI_RESET_MODE_MAX) + return -EINVAL; + if (!slot || !pci_slot_resetable(slot)) return -ENOTTY; - if (!probe) + if (mode != PCI_RESET_PROBE) pci_slot_lock(slot); might_sleep(); - rc = pci_reset_hotplug_slot(slot->hotplug, probe); + rc = pci_reset_hotplug_slot(slot->hotplug, mode); - if (!probe) + if (mode != PCI_RESET_PROBE) pci_slot_unlock(slot); return rc; @@ -5549,7 +5567,7 @@ static int pci_slot_reset(struct pci_slot *slot, int probe) */ int pci_probe_reset_slot(struct pci_slot *slot) { - return pci_slot_reset(slot, 1); + return pci_slot_reset(slot, PCI_RESET_PROBE); } EXPORT_SYMBOL_GPL(pci_probe_reset_slot); @@ -5572,14 +5590,14 @@ static int __pci_reset_slot(struct pci_slot *slot) { int rc; - rc = pci_slot_reset(slot, 1); + rc = pci_slot_reset(slot, PCI_RESET_PROBE); if (rc) return rc; if (pci_slot_trylock(slot)) { pci_slot_save_and_disable_locked(slot); might_sleep(); - rc = pci_reset_hotplug_slot(slot->hotplug, 0); + rc = pci_reset_hotplug_slot(slot->hotplug, PCI_RESET_DO_RESET); pci_slot_restore_locked(slot); pci_slot_unlock(slot); } else @@ -5588,14 +5606,17 @@ static int __pci_reset_slot(struct pci_slot *slot) return rc; } -static int pci_bus_reset(struct pci_bus *bus, int probe) +static int pci_bus_reset(struct pci_bus *bus, pci_reset_mode_t mode) { int ret; + if (mode >= PCI_RESET_MODE_MAX) + return -EINVAL; + if (!bus->self || !pci_bus_resetable(bus)) return -ENOTTY; - if (probe) + if (mode == PCI_RESET_PROBE) return 0; pci_bus_lock(bus); @@ -5634,14 +5655,14 @@ int pci_bus_error_reset(struct pci_dev *bridge) goto bus_reset; list_for_each_entry(slot, &bus->slots, list) - if (pci_slot_reset(slot, 0)) + if (pci_slot_reset(slot, PCI_RESET_DO_RESET)) goto bus_reset; mutex_unlock(&pci_slot_mutex); return 0; bus_reset: mutex_unlock(&pci_slot_mutex); - return pci_bus_reset(bridge->subordinate, 0); + return pci_bus_reset(bridge->subordinate, PCI_RESET_DO_RESET); } /** @@ -5652,7 +5673,7 @@ int pci_bus_error_reset(struct pci_dev *bridge) */ int pci_probe_reset_bus(struct pci_bus *bus) { - return pci_bus_reset(bus, 1); + return pci_bus_reset(bus, PCI_RESET_PROBE); } EXPORT_SYMBOL_GPL(pci_probe_reset_bus); @@ -5666,7 +5687,7 @@ static int __pci_reset_bus(struct pci_bus *bus) { int rc; - rc = pci_bus_reset(bus, 1); + rc = pci_bus_reset(bus, PCI_RESET_PROBE); if (rc) return rc; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 699d14243867a..cc480c238db9c 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -608,19 +608,19 @@ static inline int pci_enable_ptm(struct pci_dev *dev, u8 *granularity) struct pci_dev_reset_methods { u16 vendor; u16 device; - int (*reset)(struct pci_dev *dev, int probe); + int (*reset)(struct pci_dev *dev, pci_reset_mode_t mode); }; struct pci_reset_fn_method { - int (*reset_fn)(struct pci_dev *pdev, int probe); + int (*reset_fn)(struct pci_dev *pdev, pci_reset_mode_t mode); char *name; }; extern const struct pci_reset_fn_method pci_reset_fn_methods[]; #ifdef CONFIG_PCI_QUIRKS -int pci_dev_specific_reset(struct pci_dev *dev, int probe); +int pci_dev_specific_reset(struct pci_dev *dev, pci_reset_mode_t mode); #else -static inline int pci_dev_specific_reset(struct pci_dev *dev, int probe) +static inline int pci_dev_specific_reset(struct pci_dev *dev, pci_reset_mode_t mode) { return -ENOTTY; } @@ -709,9 +709,9 @@ static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL int pci_acpi_program_hp_params(struct pci_dev *dev); extern const struct attribute_group pci_dev_acpi_attr_group; void pci_set_acpi_fwnode(struct pci_dev *dev); -int pci_dev_acpi_reset(struct pci_dev *dev, int probe); +int pci_dev_acpi_reset(struct pci_dev *dev, pci_reset_mode_t mode); #else -static inline int pci_dev_acpi_reset(struct pci_dev *dev, int probe) +static inline int pci_dev_acpi_reset(struct pci_dev *dev, pci_reset_mode_t mode) { return -ENOTTY; } diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index 031379deb1304..9784fdcf30061 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -1407,7 +1407,7 @@ static pci_ers_result_t aer_root_reset(struct pci_dev *dev) } if (type == PCI_EXP_TYPE_RC_EC || type == PCI_EXP_TYPE_RC_END) { - rc = pcie_reset_flr(dev, 0); + rc = pcie_reset_flr(dev, PCI_RESET_DO_RESET); if (!rc) pci_info(dev, "has been reset\n"); else diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c index f43883a2e33df..b230bd07a0295 100644 --- a/drivers/pci/quirks.c +++ b/drivers/pci/quirks.c @@ -3702,7 +3702,7 @@ DECLARE_PCI_FIXUP_SUSPEND_LATE(PCI_VENDOR_ID_INTEL, * reset a single function if other methods (e.g. FLR, PM D0->D3) are * not available. */ -static int reset_intel_82599_sfp_virtfn(struct pci_dev *dev, int probe) +static int reset_intel_82599_sfp_virtfn(struct pci_dev *dev, pci_reset_mode_t mode) { /* * http://www.intel.com/content/dam/doc/datasheet/82599-10-gbe-controller-datasheet.pdf @@ -3712,7 +3712,7 @@ static int reset_intel_82599_sfp_virtfn(struct pci_dev *dev, int probe) * Thus we must call pcie_flr() directly without first checking if it is * supported. */ - if (!probe) + if (mode == PCI_RESET_DO_RESET) pcie_flr(dev); return 0; } @@ -3724,13 +3724,13 @@ static int reset_intel_82599_sfp_virtfn(struct pci_dev *dev, int probe) #define NSDE_PWR_STATE 0xd0100 #define IGD_OPERATION_TIMEOUT 10000 /* set timeout 10 seconds */ -static int reset_ivb_igd(struct pci_dev *dev, int probe) +static int reset_ivb_igd(struct pci_dev *dev, pci_reset_mode_t mode) { void __iomem *mmio_base; unsigned long timeout; u32 val; - if (probe) + if (mode == PCI_RESET_PROBE) return 0; mmio_base = pci_iomap(dev, 0, 0); @@ -3767,7 +3767,7 @@ static int reset_ivb_igd(struct pci_dev *dev, int probe) } /* Device-specific reset method for Chelsio T4-based adapters */ -static int reset_chelsio_generic_dev(struct pci_dev *dev, int probe) +static int reset_chelsio_generic_dev(struct pci_dev *dev, pci_reset_mode_t mode) { u16 old_command; u16 msix_flags; @@ -3783,7 +3783,7 @@ static int reset_chelsio_generic_dev(struct pci_dev *dev, int probe) * If this is the "probe" phase, return 0 indicating that we can * reset this device. */ - if (probe) + if (mode == PCI_RESET_PROBE) return 0; /* @@ -3845,17 +3845,17 @@ static int reset_chelsio_generic_dev(struct pci_dev *dev, int probe) * Chapter 3: NVMe control registers * Chapter 7.3: Reset behavior */ -static int nvme_disable_and_flr(struct pci_dev *dev, int probe) +static int nvme_disable_and_flr(struct pci_dev *dev, pci_reset_mode_t mode) { void __iomem *bar; u16 cmd; u32 cfg; if (dev->class != PCI_CLASS_STORAGE_EXPRESS || - pcie_reset_flr(dev, 1) || !pci_resource_start(dev, 0)) + pcie_reset_flr(dev, PCI_RESET_PROBE) || !pci_resource_start(dev, 0)) return -ENOTTY; - if (probe) + if (mode == PCI_RESET_PROBE) return 0; bar = pci_iomap(dev, 0, NVME_REG_CC + sizeof(cfg)); @@ -3919,11 +3919,13 @@ static int nvme_disable_and_flr(struct pci_dev *dev, int probe) * device too soon after FLR. A 250ms delay after FLR has heuristically * proven to produce reliably working results for device assignment cases. */ -static int delay_250ms_after_flr(struct pci_dev *dev, int probe) +static int delay_250ms_after_flr(struct pci_dev *dev, pci_reset_mode_t mode) { - int ret = pcie_reset_flr(dev, probe); + int ret; + + ret = pcie_reset_flr(dev, mode); - if (probe) + if (ret || mode == PCI_RESET_PROBE) return ret; msleep(250); @@ -3939,13 +3941,13 @@ static int delay_250ms_after_flr(struct pci_dev *dev, int probe) #define HINIC_OPERATION_TIMEOUT 15000 /* 15 seconds */ /* Device-specific reset method for Huawei Intelligent NIC virtual functions */ -static int reset_hinic_vf_dev(struct pci_dev *pdev, int probe) +static int reset_hinic_vf_dev(struct pci_dev *pdev, pci_reset_mode_t mode) { unsigned long timeout; void __iomem *bar; u32 val; - if (probe) + if (mode == PCI_RESET_PROBE) return 0; bar = pci_iomap(pdev, 0, 0); @@ -4016,16 +4018,19 @@ static const struct pci_dev_reset_methods pci_dev_reset_methods[] = { * because when a host assigns a device to a guest VM, the host may need * to reset the device but probably doesn't have a driver for it. */ -int pci_dev_specific_reset(struct pci_dev *dev, int probe) +int pci_dev_specific_reset(struct pci_dev *dev, pci_reset_mode_t mode) { const struct pci_dev_reset_methods *i; + if (mode >= PCI_RESET_MODE_MAX) + return -EINVAL; + for (i = pci_dev_reset_methods; i->reset; i++) { if ((i->vendor == dev->vendor || i->vendor == (u16)PCI_ANY_ID) && (i->device == dev->device || i->device == (u16)PCI_ANY_ID)) - return i->reset(dev, probe); + return i->reset(dev, mode); } return -ENOTTY; diff --git a/include/linux/pci.h b/include/linux/pci.h index 698a668828f66..e6f34fbd19332 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -52,6 +52,12 @@ /* Number of reset methods used in pci_reset_fn_methods array in pci.c */ #define PCI_NUM_RESET_METHODS 7 +typedef enum pci_reset_mode { + PCI_RESET_DO_RESET, + PCI_RESET_PROBE, + PCI_RESET_MODE_MAX, +} pci_reset_mode_t; + /* * The PCI interface treats multi-function devices as independent * devices. The slot/function address of each device is encoded @@ -1235,7 +1241,7 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev, enum pci_bus_speed *speed, enum pcie_link_width *width); void pcie_print_link_status(struct pci_dev *dev); -int pcie_reset_flr(struct pci_dev *dev, int probe); +int pcie_reset_flr(struct pci_dev *dev, pci_reset_mode_t mode); int pcie_flr(struct pci_dev *dev); int __pci_reset_function_locked(struct pci_dev *dev); int pci_reset_function(struct pci_dev *dev); diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h index 2dac431d94ac1..75e4e13887d0b 100644 --- a/include/linux/pci_hotplug.h +++ b/include/linux/pci_hotplug.h @@ -44,7 +44,7 @@ struct hotplug_slot_ops { int (*get_attention_status) (struct hotplug_slot *slot, u8 *value); int (*get_latch_status) (struct hotplug_slot *slot, u8 *value); int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value); - int (*reset_slot) (struct hotplug_slot *slot, int probe); + int (*reset_slot) (struct hotplug_slot *slot, pci_reset_mode_t mode); }; /**