Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp26755imp; Tue, 19 Feb 2019 17:21:36 -0800 (PST) X-Google-Smtp-Source: AHgI3IaWyRtctApq2EaIgOeJd1il0yibWMNCBEmqyaNHSoyI9/MYxhWykeMtj4ngxnCvvoMeLR9R X-Received: by 2002:a63:e051:: with SMTP id n17mr26664400pgj.258.1550625696839; Tue, 19 Feb 2019 17:21:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550625696; cv=none; d=google.com; s=arc-20160816; b=J+WLIgWbuOU221TV2VQpAYkrdvDiiZ7HBNn0i1rXgk0gc+wSrvy8f4WxTUsqWporP4 8Mebr7eE6CGJCHYpgwdSxmGrfke9ky642VnrxHMMuc5BoFPebI4LduipglJmGtej3Cag dhSie/8NZ5vSRJsNNHuOXEvrUhZRw6imFPVSnV+wNp1nIIVhGIY4XkzBsBMGEvfQz++t MYysLPP8iECP0PLuIBpu+v3zBVNrC4TAygzD0kIicDfS2sXHCLC/sXRtSxtyU/MW2l+0 WtnNmm17HfW09vYnFfJIW1U+f/MXAt5vseZzhc8qt3lDhhww/k2G+lM4uIUxYmTcxRmt Ya4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cqGwsJuXZUfRqc7YK5FaZmF1KQuNiz1aXzMjLa/CYEk=; b=InrQbC/2kPpLf+ss1fwuDj5WXlk0bEUsrF9p/DmG+dgaNG2uxpxmyOE4SSG+MxYsbA bczPlJcmMfoZshgZfSIy8/7eycqpd1VwKwTQMc9LgKzLONjzacTguijXyRctLXmDPq2q f0J2zh510jeTQnP7m57DUbSTrx9EyazTIYoas3lHG/xQpz0ChSZQBWv0TwPRizPmcrTZ AdmL41BqQqWvU645twDNBRbOeStsh17exHsi0tdhaFar+rIjIIgJk+JHOLBiboguFdoY eezF9OT9qalteO14FuB+xc7NfRldD5KxW9S1L4n077sMFAGA93HjyMd0+GGd6wwtoKlx kqNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Qx+JsQtm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31si18289768plj.244.2019.02.19.17.21.22; Tue, 19 Feb 2019 17:21:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Qx+JsQtm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730211AbfBTBU5 (ORCPT + 99 others); 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-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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- 2.19.2