Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp798465pxb; Thu, 19 Nov 2020 14:11:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlPrCTYSeZolDEmYQ8l7af4Ct6IpTw+1a1UOLwGJeQDE2PbpXRY/y0CJR9rkEc9+XS/iDv X-Received: by 2002:a17:906:7043:: with SMTP id r3mr29337646ejj.287.1605823904211; Thu, 19 Nov 2020 14:11:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605823904; cv=none; d=google.com; s=arc-20160816; b=BYy1M0OuR8a4mf9EEsyclToSp8JjXDurn8wwEcqvYwONlvADmDCmv0AWhj7qGbYHAo XDdQU5XxeRqqg/VUQmNSSGBStpXrz/Es00Ow12LRyBC8m0c1t2fhA+L1qfW54p31dX+G R1Km8eoSD8YPJpHwtbD4IieV4Y7kpVrncwMJFNNQv+3C4stYPURNPM/ufnF2VQ0dz2bx n+Mg4U0cMq3IY6G9dHEzPHT2XhJAwmBw/Y4yCKKy8QiwfSNuQ2cq234Ps5kV3Ds1cAqe HqslkbnfD+ILIiH95P5+tKgYm/2yH38aHlVpfltmNvml4CfypNHUuRTp2oEaM18dtV+B xjIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=Rye2n88CR2osPpQZOIww1HU7LK3GMoiSuQ5zm5jNDLc=; b=y/gmaRrU7zZcNEnM7n3eebxyxcT36MyCkSA66280uIpyMv2To8rygCYZqbRh94XAUe hRxEQzxVmYCdBFzcspSxQ2sUZyf1AKJStriJz9WRlCt9g2SKy9OaFXejTkq6RScjM30t oXFzU+PjoI2OPrhxk97nr1az2CTCN+UF1Qk/CuVTDI7fmM0lyBNMj9jpsSDEIEkGLKsE Kk3+WlYkd4a4ELiDIVgS+E+8ilvf2rQhUUEpaTgFqqBfza39bC3HEmX8o56PpHkiFmxm cPwlwMqKQJZzbOuE8C0JDdIogr8hZKK0w0+roFWIp9jJ37ytopDsiGdJOWIMtdnfyxqh DgKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cf25si742718ejb.435.2020.11.19.14.11.19; Thu, 19 Nov 2020 14:11:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726799AbgKSWIJ (ORCPT + 99 others); Thu, 19 Nov 2020 17:08:09 -0500 Received: from mga14.intel.com ([192.55.52.115]:11216 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726474AbgKSWIJ (ORCPT ); Thu, 19 Nov 2020 17:08:09 -0500 IronPort-SDR: IPMIicnUVjrpYpewlbPSHMay3Oc85cUhK4OvM6zihdH24UYoaesOgJIlFuXxrYFCKjmht4sN2F xdzh6teFTt5g== X-IronPort-AV: E=McAfee;i="6000,8403,9810"; a="170592550" X-IronPort-AV: E=Sophos;i="5.78,354,1599548400"; d="scan'208";a="170592550" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Nov 2020 14:08:09 -0800 IronPort-SDR: j6vcc1RP9WQOlPo7lSgSezcUlpAkgQtucdHVTA5GVwQ18vpSEUAXlsVlVbgZ5NGsS6h5WMc0g3 F/2j6SOcXW0A== X-IronPort-AV: E=Sophos;i="5.78,354,1599548400"; d="scan'208";a="341842084" Received: from otc-nc-03.jf.intel.com (HELO otc-nc-03) ([10.54.39.36]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Nov 2020 14:08:08 -0800 Date: Thu, 19 Nov 2020 14:08:07 -0800 From: "Raj, Ashok" To: Lukas Wunner Cc: linux-pci@vger.kernel.org, Bjorn Helgaas , Sathyanarayanan Kuppuswamy , linux-kernel@vger.kernel.org, Ashok Raj Subject: Re: [PATCH 1/1] pci: pciehp: Handle MRL interrupts to enable slot for hotplug. Message-ID: <20201119220807.GB102444@otc-nc-03> References: <20200925230138.29011-1-ashok.raj@intel.com> <20201119075120.GA542@wunner.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201119075120.GA542@wunner.de> User-Agent: Mutt/1.5.24 (2015-08-30) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 19, 2020 at 08:51:20AM +0100, Lukas Wunner wrote: > Hi Ashok, > > my sincere apologies for the delay. No worries.. > > On Fri, Sep 25, 2020 at 04:01:38PM -0700, Ashok Raj wrote: > > When Mechanical Retention Lock (MRL) is present, Linux doesn't process > > those change events. > > > > The following changes need to be enabled when MRL is present. > > > > 1. Subscribe to MRL change events in SlotControl. > > 2. When MRL is closed, > > - If there is no ATTN button, then POWER on the slot. > > - If there is ATTN button, and an MRL event pending, ignore > > Presence Detect. Since we want ATTN button to drive the > > hotplug event. > > So I understand you have a hardware platform which has both MRL and > Attention Button on its hotplug slots? It may be useful to name the > hardware platform in the commit message. I should, let me find out the exact intercept and include it next. > > If an Attention Button is present, the current behavior is to bring up > the hotplug slot as soon as presence or link is detected. We don't wait > for a button press. This is intended as a convience feature to bring up > slots as quickly as possible, but the behavior can be changed if the > button press and 5 second delay is preferred. No personal preference, I thought that is how the code in Linux was earlier. Looks like we still don't subscribe to PDC if ATTN is present? So you don't get an event until someone presses the button to process hotplug right? pciehp_hpc.c:pcie_enable_notification() { .... * Always enable link events: thus link-up and link-down shall * always be treated as hotplug and unplug respectively. Enable * presence detect only if Attention Button is not present. */ cmd = PCI_EXP_SLTCTL_DLLSCE; if (ATTN_BUTTN(ctrl)) cmd |= PCI_EXP_SLTCTL_ABPE; else cmd |= PCI_EXP_SLTCTL_PDCE; .... } Looks like we still wait for button press to process. When you don't have a power control yes the DLLSC would kick in and we would process them. but if you have power control, you won't turn on until the button press? > > In any case the behavior in response to an Attention Button press should > be the same regardless whether an MRL is present or not. (The spec > doesn't seem to say otherwise.) True, Looks like that is a Linux behavior, certainly not a spec recommendation. Our validation teams tell Windows also behaves such. i.e when ATTN exists button press drivers the hot-add. Linux doesn't need to follow suite though. In that case do we need to subscribe to PDC even when ATTN is present? > > > > + if (MRL_SENS(ctrl)) { > > + pciehp_get_latch_status(ctrl, &getstatus); > > + /* > > + * If slot is closed && ATTN button exists > > + * don't continue, let the ATTN button > > + * drive the hot-plug > > + */ > > + if (!getstatus && ATTN_BUTTN(ctrl)) > > + return; > > + } > > For the sake of readability I'd suggest adding a pciehp_latch_closed() > helper similar to pciehp_card_present_or_link_active() which returns > true if no MRL is present (i.e. !MRL_SENS(ctrl)), otherwise retrieves > and returns the status with pciehp_get_latch_status(). Makes sense.. I can add that. > > > > +void pciehp_handle_mrl_change(struct controller *ctrl) > > +{ > > + u8 getstatus = 0; > > + int present, link_active; > > + > > + pciehp_get_latch_status(ctrl, &getstatus); > > + > > + present = pciehp_card_present(ctrl); > > + link_active = pciehp_check_link_active(ctrl); > > + > > + ctrl_info(ctrl, "Slot(%s): Card %spresent\n", > > + slot_name(ctrl), present ? "" : "not "); > > + > > + ctrl_info(ctrl, "Slot(%s): Link %s\n", > > + slot_name(ctrl), link_active ? "Up" : "Down"); > > This duplicates a lot of code from pciehp_handle_presence_or_link_change(), > which I think suggests handling MRL events in that function. After all, > an MRL event may lead to bringup or bringdown of a slot similar to > a link or presence event. > > Basically pciehp_handle_presence_or_link_change() just needs to be > amended to bring down the slot if an MRL event occurred, and > afterwards only bring up the slot if MRL is closed. Like this: > > - if (present <= 0 && link_active <= 0) { > + if ((present <= 0 && link_active <= 0) || !latch_closed) { Certainly looks like good simplication. I'll change and have a test run. > mutex_unlock(&ctrl->state_lock); > return; > } > > > > + /* > > + * Need to handle only MRL Open. When MRL is closed with > > + * a Card Present, either the ATTN button, or the PDC indication > > + * should power the slot and add the card in the slot > > + */ > > I agree with the second sentence. You may want to refer to PCIe Base Spec > r4.0, section 6.7.1.3 either in the commit message or a code comment, > which says: > > "If an MRL Sensor is implemented without a corresponding MRL Sensor input > on the Hot-Plug Controller, it is recommended that the MRL Sensor be > routed to power fault input of the Hot-Plug Controller. > This allows an active adapter to be powered off when the MRL is opened." > > This seems to suggest that the slot should be brought down as soon as MRL > is opened. Good for commit log. I'll add a pointer in code comments too. Rarely people go to commit log :-) > > > > + /* > > + * If MRL is triggered, if ATTN button exists, ignore the event. > > + */ > > + if (ATTN_BUTTN(ctrl) && (events & PCI_EXP_SLTSTA_MRLSC)) > > + events &= ~PCI_EXP_SLTSTA_PDC; > > Hm, the spec doesn't seem to imply a connection between presence of > an MRL and presence of an Attention Button, so I find this confusing. This isn't spec required. But to enforce the earlier behavior that only ATTN drives the hot-add event. Sometimes you close the MRL, even if you didn't subscribe for notification of PDC, the bit is set and un-intentionally acted upon. If the event wasn't subscribed for to start with PDC getting pulled in is a side effect of the MRL. Validation folks look for consistency :-).. so this was mostly to enforce that. > > > > + /* > > + * If ATTN is present and MRL is triggered > > + * ignore the Presence Change Event. > > + */ > > + if (ATTN_BUTTN(ctrl) && (events & PCI_EXP_SLTSTA_MRLSC)) > > + events &= ~PCI_EXP_SLTSTA_PDC; > > An Attention Button press results in a synthesized PDC event after > 5 seconds, which may get lost due to the above if-statement. When its synthesized you don't get the MRLSC? So we won't nuke the PDC then correct? Cheers, Ashok