Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1431581rwb; Mon, 7 Nov 2022 01:20:38 -0800 (PST) X-Google-Smtp-Source: AMsMyM5Fv6+R4utycU+9U/KHcK4vuCycwgrHvlYKUP6fO2ijGp7FPRqvFEwtVb7MK6kinHNkalL3 X-Received: by 2002:a05:6402:516e:b0:461:ebe2:f17d with SMTP id d14-20020a056402516e00b00461ebe2f17dmr49769517ede.181.1667812837771; Mon, 07 Nov 2022 01:20:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667812837; cv=none; d=google.com; s=arc-20160816; b=E3FbyXRCFw0uOinFLuuzpW2MC62+SzrfgvTBSj2n/EBE2O7BLf2UXmtmJ0bSOeTemh UZW8T3zA6GaUHk4o5JEZWFC+v4ZxhyPYvCkkUa7QqPE5bvLf9klsr62C8J/5zCDsCU2v bQzpjH/uVPACMUZzdES3YlEZCi0qWuHfxHnm91jDitaV5HrqKd6yeZjK47MRhmPkng+P hafGZefGIIGMpU/Z+r/50RXc2XsMX87q9maKMYyKVEz5GzevXa4Q+hPmTHFEraV77ZYl NKOKJN/SCiJYReAZ5FYt2dB8OttoCck6iY1/pajH/frcl2teCazzW0NC45T24PpFJVI4 2Ntw== 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 :dkim-signature; bh=GMdkKK1kJMZ9FOws/TUTxiXvJe5vbpiXLddg4aAob20=; b=lqDLwEzi53TgvBooOnAfISyN4ZVUi0TgMT2dHPAVfeVTUENTcAymQNNFRpnEPIxhBi bnivRKOTZqb8/FRKF/jJaYsPWehMWXK5Jr+ohvrPsEZiLBmj5KCh4S9b2lJ/zXU2j4OY 3GYKA8a0wh70H+IcSLbY1eqICnqn06J7RoFHF1HRQlAVinOTEW5XrehB7yt9kiFhhrd7 NRyy/hd34IjvrDY0j7brhjUeZsaHpbux0Mz187KaA4ir7TGFfHwOO/obTKzBPtJeo44B jvKZ0HebP/HjCxLyX3cs4miUQTtmvFMKC5YgpkGFzvX/fhfARFrQdORBTAHujbzPQNPI 1rkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="MhgD1Pf/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cy1-20020a0564021c8100b00459060fcde3si7828743edb.202.2022.11.07.01.20.14; Mon, 07 Nov 2022 01:20:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="MhgD1Pf/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230504AbiKGIn7 (ORCPT + 95 others); Mon, 7 Nov 2022 03:43:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231436AbiKGIny (ORCPT ); Mon, 7 Nov 2022 03:43:54 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 463BC2626; Mon, 7 Nov 2022 00:43:52 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 885D5B80B8D; Mon, 7 Nov 2022 08:43:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C78A9C433D6; Mon, 7 Nov 2022 08:43:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667810630; bh=s4O1eWmHOa86wpGByLAydZl7UeUpyu0CzKU4kzn7HJA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MhgD1Pf/z4Zk/gdeXMJs9kUIANWO+7c+0fmALFzCB9LukvqLiTjzOSmgRrhynTJZc RUZgdQr7bkstW75ta9UD5I3kWWlDhXX75e12JHmjjjDgVl/2Hqx+8xZLntzFr0iU+o WXJr2KfNVz/5fI9xzxfXNlp4WZwYJQ+VM5ZWxZDgYopfm28mrbQFRWOEnwILXM8YVh GHqJzJY1XKp+DwD4Xws+0TBmD19aE6Gq3sqxl3fVVxOeaGj/Pa7dj9G9Rabm4Tel4O TVsROk5+fwJyVe3lipwoT1L9zsYpCt/9N3lEsVy9jGKydUKig19xJN7P2UfdQqyskZ 1sGeWlfHwTtRA== Received: by pali.im (Postfix) id EE84489B; Mon, 7 Nov 2022 09:43:46 +0100 (CET) Date: Mon, 7 Nov 2022 09:43:46 +0100 From: Pali =?utf-8?B?Um9ow6Fy?= To: Nathan Rossi Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Nathan Rossi , Thomas Petazzoni , Lorenzo Pieralisi , Bjorn Helgaas Subject: Re: [PATCH] PCI: mvebu: Set Target Link Speed for 2.5GT downstream devices Message-ID: <20221107084346.ksdhcxk7bppvpmqc@pali> References: <20221107081327.336239-1-nathan@nathanrossi.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221107081327.336239-1-nathan@nathanrossi.com> User-Agent: NeoMutt/20180716 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Monday 07 November 2022 08:13:27 Nathan Rossi wrote: > From: Nathan Rossi > > There is a known issue with the mvebu PCIe controller when triggering > retraining of the link (via Link Control) where the link is dropped > completely causing significant delay in the renegotiation of the link. > This occurs only when the downstream device is 2.5GT and the upstream > port is configured to support both 2.5GT and 5GT. > > It is possible to prevent this link dropping by setting the associated > link speed in Target Link Speed of the Link Control 2 register. This > only needs to be done when the downstream is specifically 2.5GT. > > This change applies the required Target Link Speed value during > mvebu_pcie_setup_hw conditionally depending on the current link speed > from the Link Status register, only applying the change when the link > is configured to 2.5GT already. > > Signed-off-by: Nathan Rossi > --- > drivers/pci/controller/pci-mvebu.c | 18 +++++++++++++++++- > 1 file changed, 17 insertions(+), 1 deletion(-) > > diff --git a/drivers/pci/controller/pci-mvebu.c b/drivers/pci/controller/pci-mvebu.c > index 1ced73726a..6a869a33ba 100644 > --- a/drivers/pci/controller/pci-mvebu.c > +++ b/drivers/pci/controller/pci-mvebu.c > @@ -248,7 +248,7 @@ static void mvebu_pcie_setup_wins(struct mvebu_pcie_port *port) > > static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port) > { > - u32 ctrl, lnkcap, cmd, dev_rev, unmask, sspl; > + u32 ctrl, lnkcap, cmd, dev_rev, unmask, sspl, lnksta, lnkctl2; > > /* Setup PCIe controller to Root Complex mode. */ > ctrl = mvebu_readl(port, PCIE_CTRL_OFF); > @@ -339,6 +339,22 @@ static void mvebu_pcie_setup_hw(struct mvebu_pcie_port *port) > unmask |= PCIE_INT_INTX(0) | PCIE_INT_INTX(1) | > PCIE_INT_INTX(2) | PCIE_INT_INTX(3); > mvebu_writel(port, unmask, PCIE_INT_UNMASK_OFF); > + > + /* > + * Set Target Link Speed within the Link Control 2 register when the > + * linked downstream device is connected at 2.5GT. This is configured > + * in order to avoid issues with the controller when the upstream port > + * is configured to support 2.5GT and 5GT and the downstream device is > + * linked at 2.5GT, retraining the link in this case causes the link to > + * drop taking significant time to retrain. > + */ > + lnksta = mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_LNKCTL) >> 16; > + if ((lnksta & PCI_EXP_LNKSTA_CLS) == PCI_EXP_LNKSTA_CLS_2_5GB) { This code does not work because at this stage endpoint device does not have to be ready and therefore link is not established yet. Also this code is not running when kernel issue PCIe Hot Reset via PCI Secondary Bus Reset bit. And it does not handle possible hot-plug situation. That check that code below has to be done _after_ kernel enumerate device. PCI core code has already logic to handle delays for "slow" devices. And reverse operation (setting lnkctl2 target speed to original value) has to be called after unplugging device - when link goes down. If you want to work on this stuff, I can try to find my notes which I done during investigation of this issue... where is probably the best place in kernel pci core code for handling this issue. > + lnkctl2 = mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_LNKCTL2); > + lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS; > + lnkctl2 |= PCI_EXP_LNKCTL2_TLS_2_5GT; > + mvebu_writel(port, lnkctl2, PCIE_CAP_PCIEXP + PCI_EXP_LNKCTL2); > + } > } > > static struct mvebu_pcie_port *mvebu_pcie_find_port(struct mvebu_pcie *pcie, > --- > 2.37.2