From patchwork Tue Jun 20 09:49:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 1797140 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4QlhkR4s2qz20WT for ; Tue, 20 Jun 2023 19:52:15 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232536AbjFTJwN (ORCPT ); Tue, 20 Jun 2023 05:52:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232008AbjFTJvm (ORCPT ); Tue, 20 Jun 2023 05:51:42 -0400 Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 23446173C; Tue, 20 Jun 2023 02:49:36 -0700 (PDT) Received: by angie.orcam.me.uk (Postfix, from userid 500) id B820492009D; Tue, 20 Jun 2023 11:49:14 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id B145092009B; Tue, 20 Jun 2023 10:49:14 +0100 (BST) Date: Tue, 20 Jun 2023 10:49:14 +0100 (BST) From: "Maciej W. Rozycki" To: Bjorn Helgaas , Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky cc: linux-pci@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] PCI: Export pci_parent_bus_reset() for drivers to use In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Export pci_parent_bus_reset() so that drivers do not duplicate it. Document the interface. Signed-off-by: Maciej W. Rozycki --- drivers/pci/pci.c | 15 ++++++++++++++- include/linux/pci.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) linux-pci-parent-bus-reset-export.diff Index: linux-macro/drivers/pci/pci.c =================================================================== --- linux-macro.orig/drivers/pci/pci.c +++ linux-macro/drivers/pci/pci.c @@ -5149,7 +5149,19 @@ int pci_bridge_secondary_bus_reset(struc } EXPORT_SYMBOL_GPL(pci_bridge_secondary_bus_reset); -static int pci_parent_bus_reset(struct pci_dev *dev, bool probe) +/** + * pci_parent_bus_reset - Reset a device via its upstream PCI bridge + * @dev: Device to reset. + * @probe: Only check if reset is possible if TRUE, actually reset if FALSE. + * + * Perform a device reset by requesting a secondary bus reset via the + * device's immediate upstream PCI bridge. Return 0 if successful or + * -ENOTTY if the reset failed or it could not have been issued in the + * first place because the device is not on a secondary bus of any PCI + * bridge or it wouldn't be the only device reset. If probing, then + * only verify whether it would be possible to issue a reset. + */ +int pci_parent_bus_reset(struct pci_dev *dev, bool probe) { struct pci_dev *pdev; @@ -5166,6 +5178,7 @@ static int pci_parent_bus_reset(struct p return pci_bridge_secondary_bus_reset(dev->bus->self); } +EXPORT_SYMBOL_GPL(pci_parent_bus_reset); static int pci_reset_hotplug_slot(struct hotplug_slot *hotplug, bool probe) { Index: linux-macro/include/linux/pci.h =================================================================== --- linux-macro.orig/include/linux/pci.h +++ linux-macro/include/linux/pci.h @@ -1447,6 +1447,7 @@ int devm_request_pci_bus_resources(struc /* Temporary until new and working PCI SBR API in place */ int pci_bridge_secondary_bus_reset(struct pci_dev *dev); +int pci_parent_bus_reset(struct pci_dev *dev, bool probe); #define __pci_bus_for_each_res0(bus, res, ...) \ for (unsigned int __b = 0; \ From patchwork Tue Jun 20 09:49:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 1797141 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Qlhkd4zgGz20WT for ; Tue, 20 Jun 2023 19:52:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232550AbjFTJwW (ORCPT ); Tue, 20 Jun 2023 05:52:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232481AbjFTJvs (ORCPT ); Tue, 20 Jun 2023 05:51:48 -0400 Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2C16B198C; Tue, 20 Jun 2023 02:49:41 -0700 (PDT) Received: by angie.orcam.me.uk (Postfix, from userid 500) id 1C5FB92009E; Tue, 20 Jun 2023 11:49:20 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 166A192009B; Tue, 20 Jun 2023 10:49:20 +0100 (BST) Date: Tue, 20 Jun 2023 10:49:20 +0100 (BST) From: "Maciej W. Rozycki" To: Bjorn Helgaas , Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky cc: linux-pci@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] IB/hfi1: Remove pci_parent_bus_reset() duplication In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Call pci_parent_bus_reset() rather than duplicating it in trigger_sbr(). There are extra preparatory checks made by the former function, but they are supposed to be neutral to the HFI1 device. Signed-off-by: Maciej W. Rozycki Reviewed-by: Ilpo Järvinen --- drivers/infiniband/hw/hfi1/pcie.c | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) linux-ib-hfi1-pcie-sbr-parent-bus-reset.diff Index: linux-macro/drivers/infiniband/hw/hfi1/pcie.c =================================================================== --- linux-macro.orig/drivers/infiniband/hw/hfi1/pcie.c +++ linux-macro/drivers/infiniband/hw/hfi1/pcie.c @@ -796,35 +796,13 @@ static void pcie_post_steps(struct hfi1_ /* * Trigger a secondary bus reset (SBR) on ourselves using our parent. * - * Based on pci_parent_bus_reset() which is not exported by the - * kernel core. + * This is an end around to do an SBR during probe time. A new API + * needs to be implemented to have cleaner interface but this fixes + * the current brokenness. */ static int trigger_sbr(struct hfi1_devdata *dd) { - struct pci_dev *dev = dd->pcidev; - struct pci_dev *pdev; - - /* need a parent */ - if (!dev->bus->self) { - dd_dev_err(dd, "%s: no parent device\n", __func__); - return -ENOTTY; - } - - /* should not be anyone else on the bus */ - list_for_each_entry(pdev, &dev->bus->devices, bus_list) - if (pdev != dev) { - dd_dev_err(dd, - "%s: another device is on the same bus\n", - __func__); - return -ENOTTY; - } - - /* - * This is an end around to do an SBR during probe time. A new API needs - * to be implemented to have cleaner interface but this fixes the - * current brokenness - */ - return pci_bridge_secondary_bus_reset(dev->bus->self); + return pci_parent_bus_reset(dd->pcidev, PCI_RESET_DO_RESET); } /*