From patchwork Wed Feb 20 01:20:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alex G." X-Patchwork-Id: 10820989 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 38B496CB for ; Wed, 20 Feb 2019 01:20:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20C902CFCD for ; Wed, 20 Feb 2019 01:20:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 143D82C165; Wed, 20 Feb 2019 01:20:53 +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 902F42C165 for ; Wed, 20 Feb 2019 01:20:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726286AbfBTBUw (ORCPT ); Tue, 19 Feb 2019 20:20:52 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:33156 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726214AbfBTBUv (ORCPT ); Tue, 19 Feb 2019 20:20:51 -0500 Received: by mail-ot1-f66.google.com with SMTP id i20so37573890otl.0; Tue, 19 Feb 2019 17:20:51 -0800 (PST) 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=0csvRJO9q2/FaX/o0eEuWXuIPQ1fh/fIC0tbNVmVNFY=; b=vX4S0FZEiZ6zhRlOjEZNXfZ7KpkNT2TAXtdAYVwhS5CLiFK0gDnMguL6fT6pkt+EeW +VqkzSm1taxY8ev+qPvjrFH6yf6xSnRYjrBwpvif3wz+GTHqyfA99hD1AQAri6vTqdEX AqEYUaaSgdTk9rtbLz4kgIIULSEBrrKmwZEYP7b6nBxsA72DtW26qArpLeLgoHlr6qIO syU/uaYmXEIpH2XAuJ946sE4e8yZsl6c/GrvF4wz/Ka1OD59qlRLh75n+qyFX9r0X6vF yII5QXryk3F2xREfz2136R34wuR4Ko7/OuYNNExMMCO0qTjB2Z3vbEOl99RPO6crsvVF Ohsg== 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=0csvRJO9q2/FaX/o0eEuWXuIPQ1fh/fIC0tbNVmVNFY=; b=RzOQgIDNSdeTTctD0VUVbr51PJAT3IAC2nBG8WPCwJ8Mm27mAxgfnZloz9JEoYAjb5 9H9CRB7PrOab+tsf/da6b8Ll6/EeikfexVuIrs1pcDUoYPWBK/ZuWG1FQ/Wy5dp79fbE 56F5JRG7lETcdmQ7NKsBQHOQLEtm70BXlEzKDULM8W4hX27S1UVgoZs59HoZzeX3WCmc bJXUbQmYMz+TKxTkiekYmV6cl+LMXdg0PRXYIUgoK2+lCMP+IpPirJnGoFhIovdy9eEc 7rAJD4zaRHqs69VNw8EsnmkAG80g6wzQsAhHllMsKKKlZsFtSDIPLjxzeIvcRu/nfo9u odlA== X-Gm-Message-State: AHQUAuYOkiFRQXHDOYD7R/xrXstVZAkN6uSLnRkAVup4gvsqCEnx6E2q Td/B6HjMnUVbpqxNH7X42W0= X-Google-Smtp-Source: AHgI3IZU08WTMWIwwZlfeWAm3wMV40RmxOr3ER9crN5MJvmKZ+s34D9tS5Vz86uJJ3Dy2lOYqodjLg== X-Received: by 2002:aca:4d3:: with SMTP id 202mr4217306oie.31.1550625650495; Tue, 19 Feb 2019 17:20:50 -0800 (PST) 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 d67sm8000424oig.36.2019.02.19.17.20.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Feb 2019 17:20:50 -0800 (PST) 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, okaya@kernel.org, linux-pci@vger.kernel.org, Alexandru Gagniuc , "Rafael J. Wysocki" , Andy Shevchenko , Mika Westerberg , Oza Pawandeep , linux-kernel@vger.kernel.org Subject: [PATCH RFC v2 1/4] PCI: hotplug: Add support for disabling in-band presence Date: Tue, 19 Feb 2019 19:20:27 -0600 Message-Id: <20190220012031.10741-2-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190220012031.10741-1-mr.nuke.me@gmail.com> References: <20190220012031.10741-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 | 12 +++++++++++- include/linux/pci.h | 1 + include/uapi/linux/pci_regs.h | 2 ++ 4 files changed, 15 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 7dd443aea5a5..f77dc7c38f9a 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -824,7 +824,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; @@ -846,6 +846,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); @@ -882,6 +885,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/linux/pci.h b/include/linux/pci.h index 65f1d8c2f082..9d08cdbca459 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -413,6 +413,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 */ diff --git a/include/uapi/linux/pci_regs.h b/include/uapi/linux/pci_regs.h index e1e9888c85e6..5423dc476c77 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 Wed Feb 20 01:20:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alex G." X-Patchwork-Id: 10820991 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 D03B06CB for ; Wed, 20 Feb 2019 01:20:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA9022C165 for ; Wed, 20 Feb 2019 01:20:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEA2E2CFDB; Wed, 20 Feb 2019 01:20:58 +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 20B092CFCE for ; Wed, 20 Feb 2019 01:20:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730165AbfBTBU5 (ORCPT ); Tue, 19 Feb 2019 20:20:57 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:40348 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726214AbfBTBU4 (ORCPT ); Tue, 19 Feb 2019 20:20:56 -0500 Received: by mail-ot1-f65.google.com with SMTP id v20so5519205otk.7; Tue, 19 Feb 2019 17:20:56 -0800 (PST) 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=cqGwsJuXZUfRqc7YK5FaZmF1KQuNiz1aXzMjLa/CYEk=; b=Qx+JsQtmwUB6aqqH8XS09WIpZeGseOj/YWe0q/1CwIF+OaFhOFECYZ82n5VICZwdoh yYQt0BgQeArGGAsnevX2tAC180A1INMInrg0qx4S3EWNgS5GcTRj1eCjuF42ODa1Jnc8 bEGI+RWwQAGXcMXGxrbSO+zr27cffqXVIXy2R+/10YM4bb8ex8ubmHHWJacTCfIYjBIg yOUd5LNqtAGBrofjEVm7+uQvPPCa930vOWwUkoHU95h1OnvNB2RYJm3uwVKU5LKKHju7 HVa+KsBYK4SGI/XNCohTFhl3vEkOP2yjoUNLanFZdVbcVZyPtocpSoRTXbM+ejlshK/N wYxQ== 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=cqGwsJuXZUfRqc7YK5FaZmF1KQuNiz1aXzMjLa/CYEk=; b=H0Uo25iwOtTkjL/MXQiTRW0yxYBPP1tyvQbrNnJcKGfmKn5IcqHt+wiM2xGG3EEEJT jDs6ZiC5tIu7ViemPOTNqs1y05BsM543kcjP0KafDHOOEEzzDqs+l9U4IznmVoBcGqMT BWNOG64MU99M+IAbstRnjDIFn04nAQ2SetNulTUy5k9w9I9agprEBuST5K1sUnmq82Lm jy67a4ZIaGLJXyUJlfAm9tJJpdQWKYAaPnx4qjt587GNqa8oGb35E2jhrz/kRUhOXyIS zaXYLlcUuHPQDLrfnkkEe6XHmpWHr01IMu6BpQcpm7Ei4GG6bJzczDLwVRnmiqEVp5Hy AIVQ== X-Gm-Message-State: AHQUAuZ8c0KLdmdjUnAzhtXHlyGr3buZk8rWn2lmNy+Csmbpi2NnE46Z 9OxpSMBIl3uikkJ1slGq3R4= X-Google-Smtp-Source: AHgI3Ia4802Wa4Yq6LCQYYuE7ZZzi5mcB+1nDYYc/GdK9mVacMj4V9/mpUoBx5Cmcta3Nh/xmYsM1Q== X-Received: by 2002:a9d:7544:: with SMTP id b4mr19045866otl.326.1550625655787; Tue, 19 Feb 2019 17:20:55 -0800 (PST) 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 d67sm8000424oig.36.2019.02.19.17.20.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Feb 2019 17:20:55 -0800 (PST) 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, okaya@kernel.org, linux-pci@vger.kernel.org, Alexandru Gagniuc , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org Subject: [PATCH RFC v2 2/4] PCI: pciehp: Do not turn off slot if presence comes up after link Date: Tue, 19 Feb 2019 19:20:28 -0600 Message-Id: <20190220012031.10741-3-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190220012031.10741-1-mr.nuke.me@gmail.com> References: <20190220012031.10741-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 3f3df4c29f6e..28965995ebb9 100644 --- a/drivers/pci/hotplug/pciehp_ctrl.c +++ b/drivers/pci/hotplug/pciehp_ctrl.c @@ -213,6 +213,21 @@ 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; @@ -220,13 +235,22 @@ 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. + * When the card is swapped, we also expect a change in link state, + * without which, it's likely presence became high after link-active. */ mutex_lock(&ctrl->state_lock); + present = pciehp_card_present(ctrl); + link_active = pciehp_check_link_active(ctrl); switch (ctrl->state) { case BLINKINGOFF_STATE: 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 Wed Feb 20 01:20:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alex G." X-Patchwork-Id: 10820993 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 9B1EE6CB for ; Wed, 20 Feb 2019 01:21:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 835C22C165 for ; Wed, 20 Feb 2019 01:21:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 77A692CFCE; Wed, 20 Feb 2019 01:21:03 +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 21BEC2C165 for ; Wed, 20 Feb 2019 01:21:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730233AbfBTBVC (ORCPT ); Tue, 19 Feb 2019 20:21:02 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:43987 "EHLO mail-ot1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726214AbfBTBVB (ORCPT ); Tue, 19 Feb 2019 20:21:01 -0500 Received: by mail-ot1-f65.google.com with SMTP id n71so37447274ota.10; Tue, 19 Feb 2019 17:21:01 -0800 (PST) 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=dKu71cm1Y17WsZMdlE2Br7miRSMDbxv4AD05UHP7QGA=; b=SWsVpPyV2G/om9p5ChNFXDezwdMjPSMfFX/CMteAfiXL0N+dfIzos5M4QgCMrDo3Wy saFHTUS1Y6OHE0Z1kaN4wus9TkT306jnZr39x/2LI6w57/mK16OeUk3wiuwEsL9CstRO +bbaa0a5CftUc78ezzIBXpKmTTrvWsb5vcbIuHIj24/a966S9NSa/YUzX1ycaF9VbWYR d05SqYnNNf4jvHImu+0s9nqEqQqCvcKvdoxQheO3MFpW7Duf+0RZEikN5vkf/RRZUTAj Ywj0wWrhQ1KkUxnd0AHxs6/U7UPU37rMUYOFZ/bz2mwMFf0KLpfm15kXx6ioW3t4loPW X9gg== 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=dKu71cm1Y17WsZMdlE2Br7miRSMDbxv4AD05UHP7QGA=; b=HeYyIA1etVniEic8tTGeSNsbh0xQW3lsllyDKjvJWkcTUwMx0/v1eOqPp11LlFrZ0n 8A3DvoM6LXFfzU39SYGX6NrG88etk8Hj3ean5hWynqyknf/saN3FXphT1uXjz+BBDtlK tKTnnR4HSZ0qhGzK5dffqHUcYE02oYwJm2elX9NMLESd4pYqBIvjTqM9TEP2mQQFydM3 G6Ze9QHidoFcvXkXQRRya7AftqYDCl/nTY2rQqF5J9KrR/+Bjk13deMqEjqGVzKkf+GS uPG5xFHHr6/PM1nIvFsNnUCox1pEWIQngrDg25CC4x+OsurZC2LD0U+dAt/ZWlN1aatj +7+A== X-Gm-Message-State: AHQUAubRZjMMPKNJdoBTjrlKXliMlNZOSz6Nfh7ydHWPR7pwLIc08DHm 6HdFWu6B37U/ZULTpCSfmsk= X-Google-Smtp-Source: AHgI3Ib8TYhT4kDvqGiXYkae5uLT9thhu++fxPJ+kkOi6owIkDb0qSu7hJE5pyonacf5RtQRABNbVQ== X-Received: by 2002:a05:6830:1493:: with SMTP id s19mr20260660otq.117.1550625660833; Tue, 19 Feb 2019 17:21:00 -0800 (PST) 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 d67sm8000424oig.36.2019.02.19.17.20.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Feb 2019 17:21:00 -0800 (PST) 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, okaya@kernel.org, linux-pci@vger.kernel.org, Alexandru Gagniuc , Mika Westerberg , Sinan Kaya , "Rafael J. Wysocki" , Oza Pawandeep , linux-kernel@vger.kernel.org Subject: [PATCH RFC v2 3/4] PCI: hotplug: Wait for PDS when in-band presence is disabled Date: Tue, 19 Feb 2019 19:20:29 -0600 Message-Id: <20190220012031.10741-4-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190220012031.10741-1-mr.nuke.me@gmail.com> References: <20190220012031.10741-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 f77dc7c38f9a..9bcadb5d3561 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(20); + timeout -= 20; + } + + 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 Wed Feb 20 01:20:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Alex G." X-Patchwork-Id: 10820995 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 3AFCC1575 for ; Wed, 20 Feb 2019 01:21:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 249E72C165 for ; Wed, 20 Feb 2019 01:21:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1748C2CFCE; Wed, 20 Feb 2019 01:21:14 +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 B803D2C165 for ; Wed, 20 Feb 2019 01:21:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730263AbfBTBVI (ORCPT ); Tue, 19 Feb 2019 20:21:08 -0500 Received: from mail-ot1-f68.google.com ([209.85.210.68]:33200 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726214AbfBTBVH (ORCPT ); Tue, 19 Feb 2019 20:21:07 -0500 Received: by mail-ot1-f68.google.com with SMTP id i20so37574757otl.0; Tue, 19 Feb 2019 17:21:07 -0800 (PST) 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=icSMYWZ1TCBph2yK3xUDD7lbSKqUZW49ipCB4B2lztg=; b=Dz7KGAxdD8LlyCChAE9NNDESeqrpxN+Hwwj/rCZ4/qp5y1IvN1ZRitfyT86HSJhCH8 +/PmeI0tmxcz0AGFyEUYD1FinVcQTmN30VhY7eAsLNolBbfkfP9700WFltQVmTGNRDqt QOVsrflazXIpj4DhWQngSigF1bXJERIHOZJ+mRlfAWqIEt1LfTOEFPdkfpEuCc5GQ89U JRDTbP6mLrA7FSpgEwqfpFZIuolL6JwoikurvmvhLm11rKDdvBxz2sNUVpPBO8uPoYBx YmfzdizOTvCHu8LkX8y20P7GNCVoXr7U19TbjNf4NhP+SY7bzqdrD+Gp6sAMw4lpF3VH t95Q== 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=icSMYWZ1TCBph2yK3xUDD7lbSKqUZW49ipCB4B2lztg=; b=VAJcHRTlaJcJy9RpA77p2KqxH5/FmbnmfRkDJm8P6A+vQhEkVfoqY6DwERhpooFvlG uHtw80T98DP6di/MVGgzPfm8m3N2UBssOND/YVNiIiBW+OF1gk2GvF7UBxbXaIXYuu9F XJy7gQzEDNiXio9/3z0qk5Paa9QOVaPJylATC7I39Ajk/wYRkVnj+R8F6P6DohDGqnXb hkdlromoztKIAh4pOue7WHSwxi0Kb9HI8Oec4B2vDUfMIYhrKmUHV905mT6lOYAac0G2 yo8VjB7lohad8vShvFz2vn6cpLLGncRT39PCb9K4dy1MxVXiF0HxPMzkLirP5tdJksjh Umfg== X-Gm-Message-State: AHQUAubGZ4/8OureyIrPULpsXE5MJJglE112NLEUoNc/XBpPUPuDIYmN zusUKbCGDMj+7A3sLAsFMg4= X-Google-Smtp-Source: AHgI3IY6M895F7dzLE9D3NjCgb8tt1X0wIv3/YKD52ruvWoSR9Qfc0XEeVBYszqOvpD78wbaA8yKaQ== X-Received: by 2002:aca:4205:: with SMTP id p5mr4510977oia.15.1550625666880; Tue, 19 Feb 2019 17:21:06 -0800 (PST) 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 d67sm8000424oig.36.2019.02.19.17.21.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Feb 2019 17:21:06 -0800 (PST) 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, okaya@kernel.org, linux-pci@vger.kernel.org, Alexandru Gagniuc , Mika Westerberg , Sinan Kaya , Oza Pawandeep , linux-kernel@vger.kernel.org Subject: [PATCH RFC v2 4/4] PCI: hotplug: Add quirk For Dell nvme pcie switches Date: Tue, 19 Feb 2019 19:20:30 -0600 Message-Id: <20190220012031.10741-5-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20190220012031.10741-1-mr.nuke.me@gmail.com> References: <20190220012031.10741-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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c index 9bcadb5d3561..853fb4ab53de 100644 --- a/drivers/pci/hotplug/pciehp_hpc.c +++ b/drivers/pci/hotplug/pciehp_hpc.c @@ -952,3 +952,23 @@ DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_QCOM, 0x0400, PCI_CLASS_BRIDGE_PCI, 8, quirk_cmd_compl); DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_QCOM, 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);