From patchwork Fri Apr 19 15:22:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alex G." X-Patchwork-Id: 10909153 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-2.web.codeaurora.org (Postfix) with ESMTP id 524D1922 for ; Fri, 19 Apr 2019 18:19:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46BD128D3F for ; Fri, 19 Apr 2019 18:19:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B35A28D95; Fri, 19 Apr 2019 18:19:42 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,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 C945328D3F for ; Fri, 19 Apr 2019 18:19:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726358AbfDSSSL (ORCPT ); Fri, 19 Apr 2019 14:18:11 -0400 Received: from mail-oi1-f193.google.com ([209.85.167.193]:42107 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726134AbfDSSSK (ORCPT ); Fri, 19 Apr 2019 14:18:10 -0400 Received: by mail-oi1-f193.google.com with SMTP id w139so4520017oie.9; Fri, 19 Apr 2019 11:18:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vd6QC5/kh1+k2njWGbBmVOB+Wb//gDgVPntsiNP/wHU=; b=uxLxSIUPcUT7maJmNU2OlubOxwiXC5vvjb9k7HjpgLBBDVNMC/gk/AM7EdHkcwKYP0 5qDRvrxhT9+hniMPoHB0e4eZc5dR4WgqrlQ9cHpYy3kmEWuMFX96EBYg1cxFbw/Vnk57 YOVnEHlPxpVIM675XegQGNqqEHYywW4wCQa3oFieuyci43T+4IFzgQ5Kgo2LVqmlcQNU hZ7610Jfx9G9q9sQ8bjMSSKr/r3juCsv97mkpwsAFln/hmdlgV2MW04t7b9LtbALPZ4h z/nniWYxSUhgwNKiauMjPaUzXjmHrj8wRjLJhUBLX3K0W6v5vNg73T4d7ICsZ25zAm5t E2mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vd6QC5/kh1+k2njWGbBmVOB+Wb//gDgVPntsiNP/wHU=; b=HfHRDo4KnNzZKQTDkKW31X1EkPmQMmY5ld+g9LFxb3qa409XpxE7hAYi0p0fPOCpLx 2/UguFyBF6xfBsQ0TZdHfKCSG0DuDBiN/tAdnH7uMo+uVrtkO5lTn/u2Lbefp8haoukI JHlY0iWaj1HP5A5KxicVSQFL9CIDKwHDs+3I0Om8xr68Lh/IzybEj0HxtK29tVmLMPXW HNQ0hLJP1DMdhd0CFxkOzr2dgkv4E+WQo6y/AwQ84nSUhl0ofzn7JyOh0y5pABlv9kNn RXE3flCtP9LL5zz6XlN7oh/q/QhiP0MV5d3xIHDeE/cMeVLVDDXPudSuLWvjaL9kCEG+ IBlA== X-Gm-Message-State: APjAAAXsOU3ogixbQlLc0nXuKQAQ8+gf0p8MG+cM+al0iJamCuwzB7yj rB3PPGDOq2woCMEpmAKMlDdIvNWYn9M= X-Google-Smtp-Source: APXvYqxTs9S6QFx3ORJhQTczfnDLFv3JUp9cYjVp9VXMwTBYVCvlsOuNE8ewMSpDQBEMfbtIGmsk3g== X-Received: by 2002:aca:d595:: with SMTP id m143mr2139444oig.31.1555687380781; Fri, 19 Apr 2019 08:23:00 -0700 (PDT) Received: from nuclearis2-1.lan (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id y9sm1981723otk.20.2019.04.19.08.22.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Apr 2019 08:23:00 -0700 (PDT) From: Alexandru Gagniuc To: bhelgaas@google.com Cc: austin_bolen@dell.com, alex_gagniuc@dellteam.com, keith.busch@intel.com, Shyam_Iyer@Dell.com, lukas@wunner.de, Alexandru Gagniuc , "Rafael J. Wysocki" , Mika Westerberg , Andy Shevchenko , "Gustavo A. R. Silva" , Sinan Kaya , Oza Pawandeep , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] PCI: hotplug: Add support for disabling in-band presence Date: Fri, 19 Apr 2019 10:22:23 -0500 Message-Id: <20190419152238.12251-2-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190419152238.12251-1-mr.nuke.me@gmail.com> References: <20190419000148.GI126710@google.com> <20190419152238.12251-1-mr.nuke.me@gmail.com> MIME-Version: 1.0 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 The presence detect state (PDS) is normally a logical or of in-band and out-of-band presence. In PCIe 4.0, there is the option to disable in-band presence so that the PDS bit always reflects the state of the out-of-band presence. The recommendation of the PCIe spec is to disable in-band presence whenever supported. Signed-off-by: Alexandru Gagniuc --- drivers/pci/hotplug/pciehp.h | 1 + drivers/pci/hotplug/pciehp_hpc.c | 9 ++++++++- include/uapi/linux/pci_regs.h | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h index 506e1d923a1f..6f729ce4a7b9 100644 --- a/drivers/pci/hotplug/pciehp.h +++ b/drivers/pci/hotplug/pciehp.h @@ -98,6 +98,7 @@ struct controller { struct pcie_device *pcie; u32 slot_cap; /* capabilities and quirks */ + unsigned int inband_presence_disabled:1; u16 slot_ctrl; /* control register access */ struct mutex ctrl_lock; diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 6a2365cd794e..078d78a7437d 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -837,7 +837,7 @@ static inline void dbg_ctrl(struct controller *ctrl) struct controller *pcie_init(struct pcie_device *dev) { struct controller *ctrl; - u32 slot_cap, link_cap; + u32 slot_cap, slot_cap2, link_cap; u8 poweron; struct pci_dev *pdev = dev->port; struct pci_bus *subordinate = pdev->subordinate; @@ -895,6 +895,13 @@ struct controller *pcie_init(struct pcie_device *dev) FLAG(link_cap, PCI_EXP_LNKCAP_DLLLARC), pdev->broken_cmd_compl ? " (with Cmd Compl erratum)" : ""); + pcie_capability_read_dword(pdev, PCI_EXP_SLTCAP2, &slot_cap2); + if (slot_cap2 & PCI_EXP_SLTCAP2_IBPD) { + pcie_write_cmd_nowait(ctrl, PCI_EXP_SLTCTL_IBPD_DISABLE, + PCI_EXP_SLTCTL_IBPD_DISABLE); + ctrl->inband_presence_disabled = 1; + } + /* * If empty slot's power status is on, turn power off. The IRQ isn't * requested yet, so avoid triggering a notification with this command. diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h index 5c98133f2c94..c7afdc4c098c 100644 --- a/include/uapi/linux/pci_regs.h +++ b/include/uapi/linux/pci_regs.h @@ -597,6 +597,7 @@ #define PCI_EXP_SLTCTL_PWR_OFF 0x0400 /* Power Off */ #define PCI_EXP_SLTCTL_EIC 0x0800 /* Electromechanical Interlock Control */ #define PCI_EXP_SLTCTL_DLLSCE 0x1000 /* Data Link Layer State Changed Enable */ +#define PCI_EXP_SLTCTL_IBPD_DISABLE 0x4000 /* In-band PD disable */ #define PCI_EXP_SLTSTA 26 /* Slot Status */ #define PCI_EXP_SLTSTA_ABP 0x0001 /* Attention Button Pressed */ #define PCI_EXP_SLTSTA_PFD 0x0002 /* Power Fault Detected */ @@ -667,6 +668,7 @@ #define PCI_EXP_LNKSTA2 50 /* Link Status 2 */ #define PCI_CAP_EXP_ENDPOINT_SIZEOF_V2 52 /* v2 endpoints with link end here */ #define PCI_EXP_SLTCAP2 52 /* Slot Capabilities 2 */ +#define PCI_EXP_SLTCAP2_IBPD 0x0001 /* In-band PD Disable Supported */ #define PCI_EXP_SLTCTL2 56 /* Slot Control 2 */ #define PCI_EXP_SLTSTA2 58 /* Slot Status 2 */ From patchwork Fri Apr 19 15:22:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alex G." X-Patchwork-Id: 10909135 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-2.web.codeaurora.org (Postfix) with ESMTP id F3A2D17EE for ; Fri, 19 Apr 2019 18:19:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E977928D98 for ; Fri, 19 Apr 2019 18:19:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD3B728D95; Fri, 19 Apr 2019 18:19:09 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,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 7964328D95 for ; Fri, 19 Apr 2019 18:19:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727582AbfDSSS4 (ORCPT ); Fri, 19 Apr 2019 14:18:56 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:45618 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727592AbfDSSSx (ORCPT ); Fri, 19 Apr 2019 14:18:53 -0400 Received: by mail-oi1-f196.google.com with SMTP id y84so4512842oia.12; Fri, 19 Apr 2019 11:18:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X/hLQpHGE1nTb+M+K/IecZnZNDziSOQqF73l6PGV8NA=; b=eb3TGYRVeXXq45nTJxEIkXv84cFepFfM6I8aTkKCCJiEw4XIPcVRBIvZlUaTor9TFr fbtxcIEgMAbsR2DLuSnu89mzpL7DBo1NjVKAnJW9EjKLrnVHoNwwzAEpft1UwVTvFnNF wnwvqzN7EtjpKDkYqQB/2sJwPLhNtxMFRejD/NVbUpsiBf8o00+C85mv58iD6jdYctWw T5MKgHrP2691rDocufwPvdr7hpe6xscjURezVg8PE/6ACVdAkro7kilyEeuXltWsndiB Fu1wOUJo1n+IWO5+u5AVeOo0t/cz3hTP/XWN+N1udv7058TESP7CcYpFUPh9YuIqUiuM FIYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X/hLQpHGE1nTb+M+K/IecZnZNDziSOQqF73l6PGV8NA=; b=gbJGwHi5IWqJ5R3QtXs8IlV1gKtq0ab1sMsVgrfHwTX8E2KSXlxJ0T17AK7A6PnAKw S3ZBYg5UX9GN2YEkUQ/6muy3/CdNqev0A6Y21E3L6iaVaI2/V7ublbR3zmy4QJ2Xmpf7 QgfoATCsbvRSF8hlNCCqjYya5vk0ALYO9NuCMSD34H+CHgJkdErjwSPxIgBhNigscH5F 8czYSKu3EeZtBynj72JGDkCoc0tbEWnStzbDFAqUMlyrlh9C7cFs/yt2vQQUb/PWVhIb hNpWLlJkaB6sJ4Z683x2zL3t7jAYGoS3gFNbLFuAtpGmLQvaarSKZ2DStpKPeidZJ26w 1jRg== X-Gm-Message-State: APjAAAUadPCMYijE/BgbCn0GpqfHk0En1u79RNYzlMkWwoPo3f9fHpPj fOIggfXcLaixWg2SirYwgaOMSDZPdT4= X-Google-Smtp-Source: APXvYqyAvazz134UGdE3uY6fi6/ztybt+Do5+lqi/oxed7ssxuRXOJT3VwfxLlX0raAZgoCyHXZvHw== X-Received: by 2002:aca:bf83:: with SMTP id p125mr2171074oif.47.1555687391478; Fri, 19 Apr 2019 08:23:11 -0700 (PDT) Received: from nuclearis2-1.lan (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id y9sm1981723otk.20.2019.04.19.08.23.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Apr 2019 08:23:11 -0700 (PDT) From: Alexandru Gagniuc To: bhelgaas@google.com Cc: austin_bolen@dell.com, alex_gagniuc@dellteam.com, keith.busch@intel.com, Shyam_Iyer@Dell.com, lukas@wunner.de, Alexandru Gagniuc , "Rafael J. Wysocki" , Andy Shevchenko , Mika Westerberg , "Gustavo A. R. Silva" , Sinan Kaya , Oza Pawandeep , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/4] PCI: pciehp: Do not turn off slot if presence comes up after link Date: Fri, 19 Apr 2019 10:22:24 -0500 Message-Id: <20190419152238.12251-3-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190419152238.12251-1-mr.nuke.me@gmail.com> References: <20190419000148.GI126710@google.com> <20190419152238.12251-1-mr.nuke.me@gmail.com> MIME-Version: 1.0 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 According to PCIe 3.0, the presence detect state is a logical OR of in-band and out-of-band presence. With this, we'd expect the presence state to always be asserted when the link comes up. Not all hardware follows this, and it is possible for the presence to come up after the link. In this case, the PCIe device would be erroneously disabled and re-probed. It is possible to distinguish between a delayed presence and a card swap by looking at the DLL state changed bit -- The link has to come down if the card is removed. Thus, for a device that is probed, present and has its link active, a lack of a link state change event guarantees we have the same device, and shutdown is not needed. Signed-off-by: Alexandru Gagniuc --- drivers/pci/hotplug/pciehp_ctrl.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c index 905282a8ddaa..d46724f0b4ce 100644 --- a/drivers/pci/hotplug/pciehp_ctrl.c +++ b/drivers/pci/hotplug/pciehp_ctrl.c @@ -217,6 +217,22 @@ void pciehp_handle_disable_request(struct controller *ctrl) ctrl->request_result = pciehp_disable_slot(ctrl, SAFE_REMOVAL); } +static bool is_delayed_presence_up_event(struct controller *ctrl, u32 events) +{ + bool present, link_active; + + if (!ctrl->inband_presence_disabled) + return false; + + present = pciehp_card_present(ctrl); + link_active = pciehp_check_link_active(ctrl); + + if (!present || !link_active || events & PCI_EXP_SLTSTA_DLLSC) + return false; + + return true; +} + void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) { bool present, link_active; @@ -224,6 +240,9 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) /* * If the slot is on and presence or link has changed, turn it off. * Even if it's occupied again, we cannot assume the card is the same. + * + * An exception is a delayed "Card present" after a "Link Up". This can + * happen on controllers with in-band presence disabled. */ mutex_lock(&ctrl->state_lock); switch (ctrl->state) { @@ -231,6 +250,11 @@ void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events) cancel_delayed_work(&ctrl->button_work); /* fall through */ case ON_STATE: + if (is_delayed_presence_up_event(ctrl, events)) { + mutex_unlock(&ctrl->state_lock); + ctrl_dbg(ctrl, "Presence state came up after link"); + return; + } ctrl->state = POWEROFF_STATE; mutex_unlock(&ctrl->state_lock); if (events & PCI_EXP_SLTSTA_DLLSC) From patchwork Fri Apr 19 15:22:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alex G." X-Patchwork-Id: 10909613 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-2.web.codeaurora.org (Postfix) with ESMTP id 3D9FE14DB for ; Fri, 19 Apr 2019 19:11:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 302A428DFD for ; Fri, 19 Apr 2019 19:11:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2199928E02; Fri, 19 Apr 2019 19:11:29 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,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 BEA7A28DFD for ; Fri, 19 Apr 2019 19:11:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727719AbfDSTL1 (ORCPT ); Fri, 19 Apr 2019 15:11:27 -0400 Received: from mail-oi1-f196.google.com ([209.85.167.196]:37840 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727415AbfDSTL1 (ORCPT ); Fri, 19 Apr 2019 15:11:27 -0400 Received: by mail-oi1-f196.google.com with SMTP id v84so4621101oif.4; Fri, 19 Apr 2019 12:11:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+2drH5CEdV46g6LB3v7o+zWjzFiQ1J6IZVvI0w9yvfU=; b=ZHSxBoQYrfU2dxsZQQqGxEZIyuA/1ek2/MFLecIqgFx1YVTsIP1xTRAzqDe1FixNTk 6oOpOY0LOoSy01zsOWAnSZBy31/aVodErLKBfOW8kwt5sCTEotXvPDi8smtzRHNRBccz xdBrXE9d2jALCY2HN+7VLz57ASGGC29AjNO01j8W8Gz8r1qeGhzfVhiCmDUO+DD752cW oANhKwSxUnFgV1OXppWWyIXFI4GsMGRqV57HXkB4YVFyrCNIs5s4edPJm0hhECeUGtDe lYqYzXzXqeqE5z94/cNOL7boK3DrsSgypEHV7A6vs/G52lrrnZ1dPDw2JlIz031XSHsd 0Oyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+2drH5CEdV46g6LB3v7o+zWjzFiQ1J6IZVvI0w9yvfU=; b=sNv6uWkfwR+za4y5LIDaOW6tpiYwQF6rQLr1DUk5SBLUUFFsZoGkPuxhyNR/AfGSgs K3oKKLNRxVoBbCvIaDxJRqMYx1xdtyaRq76pZs01qhnRHl9Rw1D4XmiRhcbwZE00+SgX tZqw3ZJaesdWDwbosCvhvjuVfxZapEaYgpy4StzN24sWE9Q8LnuhKyZjAWhnmIUURg2v 9WaW99i2KOPLcjEmpzQUPn/dc38N1mJNzZiVvSJqDRHvYGxOvrbZmZLs1/6RrPWHV+/I ToOelK/Yyw2YDUPNriZZ9KRyx29/mV9cIo52X5bO95j9lfMrdFAdLRbqIqCRHDUnysz9 8WdA== X-Gm-Message-State: APjAAAWQ1BbrVNARgJwM1l7pQA1zBucXTTmv2jCrHIYND1Eb8A3YUWHb X0I1IG9Mpco/d5Zae9BAUNhYv1TNIUA= X-Google-Smtp-Source: APXvYqzZSMLoPPohOVoFI1SE6z3j9BzvEfCXlMxQrZidqZZZsN8fjNejYaNz3qfb1i3TGQiVl+C5dw== X-Received: by 2002:aca:fd93:: with SMTP id b141mr2017782oii.153.1555687402034; Fri, 19 Apr 2019 08:23:22 -0700 (PDT) Received: from nuclearis2-1.lan (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id y9sm1981723otk.20.2019.04.19.08.23.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Apr 2019 08:23:21 -0700 (PDT) From: Alexandru Gagniuc To: bhelgaas@google.com Cc: austin_bolen@dell.com, alex_gagniuc@dellteam.com, keith.busch@intel.com, Shyam_Iyer@Dell.com, lukas@wunner.de, Alexandru Gagniuc , "Rafael J. Wysocki" , Andy Shevchenko , Mika Westerberg , "Gustavo A. R. Silva" , Sinan Kaya , Oza Pawandeep , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/4] PCI: hotplug: Wait for PDS when in-band presence is disabled Date: Fri, 19 Apr 2019 10:22:25 -0500 Message-Id: <20190419152238.12251-4-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190419152238.12251-1-mr.nuke.me@gmail.com> References: <20190419000148.GI126710@google.com> <20190419152238.12251-1-mr.nuke.me@gmail.com> MIME-Version: 1.0 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 When inband presence is disabled, PDS may come up at any time, or not at all. PDS being low may indicate that the card is still mating, and we could expect contact bounce to bring down the link as well. It is reasonable to assume that most cards will mate in a hotplug slot in less than a second. Thus, when we know PDS only reflects out-of-band presence, it's worthwhile to wait the extra second and make sure the card is properly mated before loading the driver. Signed-off-by: Alexandru Gagniuc --- drivers/pci/hotplug/pciehp_hpc.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 078d78a7437d..6cd2c4fb4edb 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -240,6 +240,25 @@ static bool pci_bus_check_dev(struct pci_bus *bus, int devfn) return found; } +static void pcie_wait_for_presence(struct pci_dev *pdev) +{ + int timeout = 1000; + bool pds; + u16 slot_status; + + while(true) { + pcie_capability_read_word(pdev, PCI_EXP_SLTSTA, &slot_status); + pds = !!(slot_status & PCI_EXP_SLTSTA_PDS); + if (pds || timeout <= 0) + break; + msleep(10); + timeout -= 10; + } + + if (!pds) + pci_info(pdev, "Presence Detect state not set in 1000 msec\n"); +} + int pciehp_check_link_status(struct controller *ctrl) { struct pci_dev *pdev = ctrl_dev(ctrl); @@ -249,6 +268,9 @@ int pciehp_check_link_status(struct controller *ctrl) if (!pcie_wait_for_link(pdev, true)) return -1; + if (ctrl->inband_presence_disabled) + pcie_wait_for_presence(pdev); + found = pci_bus_check_dev(ctrl->pcie->port->subordinate, PCI_DEVFN(0, 0)); From patchwork Fri Apr 19 15:22:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alex G." X-Patchwork-Id: 10909387 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-2.web.codeaurora.org (Postfix) with ESMTP id 47EB7922 for ; Fri, 19 Apr 2019 18:31:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C8AA28C6D for ; Fri, 19 Apr 2019 18:31:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FF8428DB3; Fri, 19 Apr 2019 18:31:54 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,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 C420528C6D for ; Fri, 19 Apr 2019 18:31:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728167AbfDSSbs (ORCPT ); Fri, 19 Apr 2019 14:31:48 -0400 Received: from mail-oi1-f195.google.com ([209.85.167.195]:42887 "EHLO mail-oi1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727636AbfDSSbs (ORCPT ); Fri, 19 Apr 2019 14:31:48 -0400 Received: by mail-oi1-f195.google.com with SMTP id w139so4541803oie.9; Fri, 19 Apr 2019 11:31:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=c3d5eGGJw4R7UGVxkj3FtbNAvPKDTO3ueR90+T5iRs0=; b=rKL89JIglaL3N3+3WtwQBikjppTKoCm6pWZF9gcdn8r/7HI8bh2nxRjgTUsbCP465G ULsIXGPj4suAbAt7YGp5aSF1U2GAj9gyJrV4gSreRD/Nk8CXHwgb7uA0e9qBtG9X9u7l h4Qm/tdz961Gi/QiOqkoha/y7eRYXBZA7dMQGjEow/znK4REaZ5YJdkxhRcVR6Gk/5pD VcmPllvYoJWSVeq/0RDrkRa1xBy2R6dnwLwoqXWKHsUc3SurGJZqWcGa2Ghhj+UUr/Jx Np+mLq3Kf7QZbNRHVgBIUspN2d45OP3FiPEymaa3RGmUHbuy4cKxtVieHxpNhWBxswKs 9siw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=c3d5eGGJw4R7UGVxkj3FtbNAvPKDTO3ueR90+T5iRs0=; b=UuUXVnPwzBNMzs3LjKuwSE6Firlue0IaeWAcKLAileSKMDSTcr99WFAaWlu3X4aHQv GJZ9RPuVmcNQ+5sYK1YyAvvv3nYY9Zsrwf7cVtRpwVxnFwDX1drmrB6wm8MMZYvATIxx uRchRJ4ZkAB2PmCdcaRw2OyDW12Qy+6HeRBnI9IaLpwdppNOh1+GdMt8yWmSyKkFcyFU M+ayIqAnSahxRrYm2/SQuMU88EvP7BdlKQWLLYWYkYCfCCcXypVElIKlsiZ0ZGqVJJx0 utH04S0B/aCXaSkowkYJkNX88DWyjbAbNdBLt4JUm667RViezjFjW3r+E3qTdsFf9KD0 1pfg== X-Gm-Message-State: APjAAAUYr5TG91Yr9JDdqxn/uY8PXWX/3COFmGI5XInTvbglrMGhNtvX 2UH2Gpju6Npv5MPaM0JTT16GJn3Yv5M= X-Google-Smtp-Source: APXvYqxcZRdGYykEJapShXtif+/DvI+vwSpOeJfLFlYzqtajt3JHmKM8cVn1YTqHX4A07b7HAa7ZCA== X-Received: by 2002:aca:5904:: with SMTP id n4mr2086084oib.122.1555687412714; Fri, 19 Apr 2019 08:23:32 -0700 (PDT) Received: from nuclearis2-1.lan (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id y9sm1981723otk.20.2019.04.19.08.23.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Apr 2019 08:23:32 -0700 (PDT) From: Alexandru Gagniuc To: bhelgaas@google.com Cc: austin_bolen@dell.com, alex_gagniuc@dellteam.com, keith.busch@intel.com, Shyam_Iyer@Dell.com, lukas@wunner.de, Alexandru Gagniuc , "Rafael J. Wysocki" , Andy Shevchenko , Mika Westerberg , "Gustavo A. R. Silva" , Sinan Kaya , Oza Pawandeep , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/4] PCI: hotplug: Add quirk For Dell nvme pcie switches Date: Fri, 19 Apr 2019 10:22:26 -0500 Message-Id: <20190419152238.12251-5-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190419152238.12251-1-mr.nuke.me@gmail.com> References: <20190419000148.GI126710@google.com> <20190419152238.12251-1-mr.nuke.me@gmail.com> MIME-Version: 1.0 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 These switches are used to fornicate the motherboard's x16 PCIe ports into four x4 ports for NVMe drives. In conjunction with the storage backplane, the PDS bit reports only the out-of-band presence. The fact that inband presence is disabled is not reported in the slot capabilities 2 (SLTCAP2) register. Because this does not conform to the PCIe spec, add a quirk to let hotplug code know to expect and handle this. Signed-off-by: Alexandru Gagniuc --- drivers/pci/hotplug/pciehp_hpc.c | 21 +++++++++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 22 insertions(+) diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 6cd2c4fb4edb..681043f59fa5 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -881,6 +881,9 @@ struct controller *pcie_init(struct pcie_device *dev) if (pdev->is_thunderbolt) slot_cap |= PCI_EXP_SLTCAP_NCCS; + if (pdev->no_in_band_presence) + ctrl->inband_presence_disabled = 1; + ctrl->slot_cap = slot_cap; mutex_init(&ctrl->ctrl_lock); mutex_init(&ctrl->state_lock); @@ -964,3 +967,21 @@ DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_QCOM, 0x0401, PCI_CLASS_BRIDGE_PCI, 8, quirk_cmd_compl); DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_HXT, 0x0401, PCI_CLASS_BRIDGE_PCI, 8, quirk_cmd_compl); + +static void fixup_dell_nvme_backplane_switches(struct pci_dev *pdev) +{ + if (!pci_is_pcie(pdev)) + return; + + if (pci_pcie_type(pdev) != PCI_EXP_TYPE_DOWNSTREAM) + return; + + if (pdev->subsystem_vendor != PCI_VENDOR_ID_DELL || + pdev->subsystem_device != 0x1fc7) + return; + + pdev->no_in_band_presence = 1; +} +DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_PLX, 0x9733, + PCI_CLASS_BRIDGE_PCI, 8, + fixup_dell_nvme_backplane_switches); diff --git a/include/linux/pci.h b/include/linux/pci.h index 77448215ef5b..9594a313064d 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -416,6 +416,7 @@ struct pci_dev { unsigned int non_compliant_bars:1; /* Broken BARs; ignore them */ unsigned int is_probed:1; /* Device probing in progress */ unsigned int link_active_reporting:1;/* Device capable of reporting link active */ + unsigned int no_in_band_presence:1; /* Device does not report in-band presence */ unsigned int no_vf_scan:1; /* Don't scan for VFs after IOV enablement */ pci_dev_flags_t dev_flags; atomic_t enable_cnt; /* pci_enable_device has been called */