From patchwork Fri Oct 28 22:58:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 9402793 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E3DFA6022E for ; Fri, 28 Oct 2016 22:47:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D376C2A8D3 for ; Fri, 28 Oct 2016 22:47:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C82F02A8D9; Fri, 28 Oct 2016 22:47:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDAF92A8D3 for ; Fri, 28 Oct 2016 22:47:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756070AbcJ1Wri (ORCPT ); Fri, 28 Oct 2016 18:47:38 -0400 Received: from mga01.intel.com ([192.55.52.88]:46396 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754380AbcJ1Wrh (ORCPT ); Fri, 28 Oct 2016 18:47:37 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP; 28 Oct 2016 15:47:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,560,1473145200"; d="scan'208";a="185150148" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.96]) by fmsmga004.fm.intel.com with ESMTP; 28 Oct 2016 15:47:36 -0700 From: Keith Busch To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: Lukas Wunner , Wei Zhang , Keith Busch Subject: [PATCHv4 next 1/3] pci: Add is_removed state Date: Fri, 28 Oct 2016 18:58:15 -0400 Message-Id: <1477695497-6207-2-git-send-email-keith.busch@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1477695497-6207-1-git-send-email-keith.busch@intel.com> References: <1477695497-6207-1-git-send-email-keith.busch@intel.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This adds a new state for devices that were once in the system, but unexpectedly removed. This is so device tear down functions can observe the device is not accessible so it may skip attempting to initialize the hardware. The pciehp and pcie-dpc drivers are aware of when the link is down, so these explicitly set this flag when its handlers detect the device is gone. Signed-off-by: Keith Busch Cc: Lukas Wunner Reviewed-by: Lukas Wunner --- drivers/pci/hotplug/pciehp_pci.c | 5 +++++ drivers/pci/pcie/pcie-dpc.c | 4 ++++ include/linux/pci.h | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c index 9e69403..7560961 100644 --- a/drivers/pci/hotplug/pciehp_pci.c +++ b/drivers/pci/hotplug/pciehp_pci.c @@ -109,6 +109,11 @@ int pciehp_unconfigure_device(struct slot *p_slot) break; } } + if (!presence) { + pci_set_removed(dev, NULL); + if (pci_has_subordinate(dev)) + pci_walk_bus(dev->subordinate, pci_set_removed, NULL); + } pci_stop_and_remove_bus_device(dev); /* * Ensure that no new Requests will be generated from diff --git a/drivers/pci/pcie/pcie-dpc.c b/drivers/pci/pcie/pcie-dpc.c index 9811b14..7818c88 100644 --- a/drivers/pci/pcie/pcie-dpc.c +++ b/drivers/pci/pcie/pcie-dpc.c @@ -14,6 +14,7 @@ #include #include #include +#include "../pci.h" struct dpc_dev { struct pcie_device *dev; @@ -46,6 +47,9 @@ static void interrupt_event_handler(struct work_struct *work) list_for_each_entry_safe_reverse(dev, temp, &parent->devices, bus_list) { pci_dev_get(dev); + pci_set_removed(dev, NULL); + if (pci_has_subordinate(dev)) + pci_walk_bus(dev->subordinate, pci_set_removed, NULL); pci_stop_and_remove_bus_device(dev); pci_dev_put(dev); } diff --git a/include/linux/pci.h b/include/linux/pci.h index 0e49f70..2115d19 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -341,6 +341,7 @@ struct pci_dev { unsigned int multifunction:1;/* Part of multi-function device */ /* keep track of device state */ unsigned int is_added:1; + unsigned int is_removed:1; /* device was surprise removed */ unsigned int is_busmaster:1; /* device is busmaster */ unsigned int no_msi:1; /* device may not use msi */ unsigned int no_64bit_msi:1; /* device may only use 32-bit MSIs */ @@ -417,6 +418,12 @@ static inline int pci_channel_offline(struct pci_dev *pdev) return (pdev->error_state != pci_channel_io_normal); } +static inline int pci_set_removed(struct pci_dev *pdev, void *unused) +{ + pdev->is_removed = 1; + return 0; +} + struct pci_host_bridge { struct device dev; struct pci_bus *bus; /* root bus */