Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1491528rwb; Mon, 7 Nov 2022 02:11:42 -0800 (PST) X-Google-Smtp-Source: AMsMyM7TWamgyO4haMRyaCHCBhrrTUum6c3Vem5IQjlyissMIZvWpMwBA8xcJykiFYX3nnU3O9vS X-Received: by 2002:a17:906:6d19:b0:7ae:3a0d:a10c with SMTP id m25-20020a1709066d1900b007ae3a0da10cmr15070447ejr.152.1667815902358; Mon, 07 Nov 2022 02:11:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667815902; cv=none; d=google.com; s=arc-20160816; b=s8jPRP+ARLBzXieTkbVIgt8DMq2XUv/XyvZrV+UIfTNsCQxehWNQeCMH4CX673d2lt auy5nNo/QQj/50Deh5vXrAvkAJzOZaSVrZhZUA/Hb3KTYJgQB/e/Zs/pjW0Wltmo+7eh J8APOcQhfkSsCBAh8ik4Nx/WQxemXullcEdVx7gLVvjp2uWAL/H0itRWszm6quKyfUso hRMTRydaKiN0zN7JvO1/YrT1IiigtGqQNt18dMPpDsxP3T1vhEc+e55MKVW4gbslxkM4 qqBB/LafFf8zTG7XViA+hZS21O9cfbEoc5mHIhXkWKTRJ8MgSzpVpHlHdQrZaSUVyf+1 5b5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Rq7f5awERCBOzRjQecmifE8ARalisdBJSDWTzIB4PxQ=; b=W1Sc/dIjcsteSGJBojj4W6IIXzsLVRAcCknkGshjwbuFXZVfHj/kAcHC08CxuyCiYY IXAiIor/bqK5yL6Qhd574I4KIlhoWyOawkwLOkARaCbQsHUXmeCDiRGD6DK4+8Cj5yfA 1K0rUMZRM3GuzGJh3ta+C1nWCOO45mXTUM6ZrFCO/bBnhWXqcndzGbu2XxFqoTxxWB+V STqlV1M8744dHTImZbdYJdOCkh6QI+LVMWO3IgYhi8fgwAbngcVyIRPk8tHbN73DMz8Q 6Z0Bxfmb067Dc7cQ06qiVRvuPxoHxsaS/QPyjvWit1Wri6VUVv2OmGRBsA2+/9M66QIu C4tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nathanrossi.com header.s=google header.b=ZUFFDsZK; 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=nathanrossi.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g22-20020a1709065d1600b007ae664aa7dbsi5404380ejt.877.2022.11.07.02.11.19; Mon, 07 Nov 2022 02:11:42 -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=@nathanrossi.com header.s=google header.b=ZUFFDsZK; 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=nathanrossi.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231594AbiKGJKV (ORCPT + 95 others); Mon, 7 Nov 2022 04:10:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230515AbiKGJKQ (ORCPT ); Mon, 7 Nov 2022 04:10:16 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F445167F3 for ; Mon, 7 Nov 2022 01:10:15 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id bj12so28171580ejb.13 for ; Mon, 07 Nov 2022 01:10:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nathanrossi.com; s=google; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Rq7f5awERCBOzRjQecmifE8ARalisdBJSDWTzIB4PxQ=; b=ZUFFDsZKDnQfoyM9/MObxP3JEorLMtGF2pXlhdoE9hwl9N54nPUCE7s97sAz+L/81q dqtkmW5Ag6NAZOXcJrAREmLpl45C0hJTaXbScoVWHwA/UOaU9Ljcygb3jiGoI49/Fd77 EnwWz/xPj/uXTlTH4u70IqttOvNaZM4wOzKUmn+A78fd3LokucErLFJj5CrY7E/wN/QI 18HVOkrowHVA2wmI+Dv8+8mVZrC9l75Rf+//aRQEv9Kc2D4I92+nfdbCybYqvTXov8G5 S4J9UHnxdoGdeXuMJBjNgIazvz94uulPoLoWYfetKrFDOUL6BviWgw2iZxTK7+0D2BdX 4sbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rq7f5awERCBOzRjQecmifE8ARalisdBJSDWTzIB4PxQ=; b=nVjL4B1hz4oBghYMj0gzm4nMZ3BCiXlr3druoyBfznv3EaoY4mU9Y1BRZdRwq1xDbj crN99VHXZ18lu91+LVyV7Z+NYCSURdcXWUmFPavT1voY0tOOjXcjzZBfvEyrqbOHljfw hoxKmf7qJx2PYf3X0SsjniqfXAndXgIw/fg7ViZQB4RfVamCrTDLtX6sxhjKGP+sUaWQ xBq4Mw5JQA+vQQtvsDDXOICFSPWrWlbh600Fj4zNJmCmIK8QXK1N7OapNk86lSL2Litx 5qNQ6w0qeAboTHVesu5oRejVX6C8aDqZfvc5QVlpW9hXVMK5701/fQoAw1mabqrjjHJ+ zLHw== X-Gm-Message-State: ACrzQf3kvuO0PhO/HxAwy/YiMpQTp+c7Xjt9d5Xl38HMmkSIq5oshW8a RPd7KaVrdqV8vkkI2e0iywHbYqc43Hvrx5PD48v0Qg== X-Received: by 2002:a17:906:371a:b0:7ad:c01c:6fa0 with SMTP id d26-20020a170906371a00b007adc01c6fa0mr42731140ejc.267.1667812213764; Mon, 07 Nov 2022 01:10:13 -0800 (PST) MIME-Version: 1.0 References: <20221107081327.336239-1-nathan@nathanrossi.com> <20221107084346.ksdhcxk7bppvpmqc@pali> In-Reply-To: <20221107084346.ksdhcxk7bppvpmqc@pali> From: Nathan Rossi Date: Mon, 7 Nov 2022 19:10:02 +1000 Message-ID: Subject: Re: [PATCH] PCI: mvebu: Set Target Link Speed for 2.5GT downstream devices To: =?UTF-8?Q?Pali_Roh=C3=A1r?= 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 Mon, 7 Nov 2022 at 18:43, Pali Roh=C3=A1r wrote: > > 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/controlle= r/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 =3D mvebu_readl(port, PCIE_CTRL_OFF); > > @@ -339,6 +339,22 @@ static void mvebu_pcie_setup_hw(struct mvebu_pcie_= port *port) > > unmask |=3D 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 config= ured > > + * in order to avoid issues with the controller when the upstream= port > > + * is configured to support 2.5GT and 5GT and the downstream devi= ce is > > + * linked at 2.5GT, retraining the link in this case causes the l= ink to > > + * drop taking significant time to retrain. > > + */ > > + lnksta =3D mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_LNKCTL) >>= 16; > > + if ((lnksta & PCI_EXP_LNKSTA_CLS) =3D=3D 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. Some notes/direction for implementation would be very appreciated. I am not particularly familiar with the pci core code, so I don't have a good idea on how to best implement this workaround. Thanks, Nathan > > > + lnkctl2 =3D mvebu_readl(port, PCIE_CAP_PCIEXP + PCI_EXP_L= NKCTL2); > > + lnkctl2 &=3D ~PCI_EXP_LNKCTL2_TLS; > > + lnkctl2 |=3D PCI_EXP_LNKCTL2_TLS_2_5GT; > > + mvebu_writel(port, lnkctl2, PCIE_CAP_PCIEXP + PCI_EXP_LNK= CTL2); > > + } > > } > > > > static struct mvebu_pcie_port *mvebu_pcie_find_port(struct mvebu_pcie = *pcie, > > --- > > 2.37.2