From patchwork Tue Sep 27 20:23:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 675810 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3skBpR466lz9sXR for ; Wed, 28 Sep 2016 06:12:47 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934732AbcI0UMq (ORCPT ); Tue, 27 Sep 2016 16:12:46 -0400 Received: from mga09.intel.com ([134.134.136.24]:1675 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932573AbcI0UMp (ORCPT ); Tue, 27 Sep 2016 16:12:45 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 27 Sep 2016 13:12:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,406,1470726000"; d="scan'208";a="884426504" Received: from unknown (HELO localhost.lm.intel.com) ([10.232.112.65]) by orsmga003.jf.intel.com with ESMTP; 27 Sep 2016 13:12:43 -0700 From: Keith Busch To: linux-pci@vger.kernel.org, Bjorn Helgaas Cc: Ralf Baechle , Lukas Wunner , Wei Zhang , Keith Busch Subject: [PATCHv3 2/5] pci: Add is_removed state Date: Tue, 27 Sep 2016 16:23:32 -0400 Message-Id: <1475007815-28354-3-git-send-email-keith.busch@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1475007815-28354-1-git-send-email-keith.busch@intel.com> References: <1475007815-28354-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 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 --- drivers/pci/hotplug/pciehp_pci.c | 2 ++ drivers/pci/pcie/pcie-dpc.c | 1 + include/linux/pci.h | 1 + 3 files changed, 4 insertions(+) diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c index 9e69403..299ea5e 100644 --- a/drivers/pci/hotplug/pciehp_pci.c +++ b/drivers/pci/hotplug/pciehp_pci.c @@ -109,6 +109,8 @@ int pciehp_unconfigure_device(struct slot *p_slot) break; } } + if (!presence) + dev->is_removed = 1; 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 250f878..756eae4 100644 --- a/drivers/pci/pcie/pcie-dpc.c +++ b/drivers/pci/pcie/pcie-dpc.c @@ -44,6 +44,7 @@ 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); + dev->is_removed = 1; pci_stop_and_remove_bus_device(dev); pci_dev_put(dev); } diff --git a/include/linux/pci.h b/include/linux/pci.h index c81fbf7..36b759c 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -337,6 +337,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 */