Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3148772pxu; Mon, 14 Dec 2020 23:04:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyVXGuT1GNWazwtnstDK+quF0emsUYhPB22SgVHTKZxMTHtPDJM1dYl0uXtxhsJyymxqZ9H X-Received: by 2002:a17:906:524a:: with SMTP id y10mr25958294ejm.97.1608015896189; Mon, 14 Dec 2020 23:04:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608015896; cv=none; d=google.com; s=arc-20160816; b=EVTXh/K/F0tix1krJCDg7kRKxutZvUqSJXqCzv3K5WAp1sqJkEcTYeJmmPI3zzGMZn 4WJL/GQOTFEDYhyWPuQHcchKus/zTG6MzxfUjePgua6mQPnMm37HWcey4TV1sijR9VbX vIplNGtZbzsqBXTqek1Kr2GPNGNtdN87MMrJxWvX9w2iGfOCRZi3NfHtsyv+rVWWueKp rKYk1xaJp9fL6/nJ7B21H9/zJN9tUnY2nZjt8K8bBrOWNqk9igNpL9zuav9x6kNHP9WE FtiFQzdKT1/O+X8WF8eXngsvF7zMPwJ/V6twvxTua0NZTjWRXLj0j29I4RGZ662e6M20 rWgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=iWkY+8bX1O7V/L8hXMtJVE3oSow43PDbAsF0LzeIDlA=; b=vBMrpO6h5hRTFX7vYK8lVHLkaVjZYRyQnoowdqMi/q40VyOQhl2U5RywVOgyZNim0M ycVzj46CE81zOTjB1GIjzY8JZXkPm2TMRgQnY7TNAif62shMuZTiOV2ZNKtyzHMu8H6Q AQHyLKxbCt5HyQCDRTEKjbG+Mjf9gqcSrygAqxlzo1cKPLWniwMChxXy6wC16N2L9gVa hytowbmTXD27bdq5HwrlrBaLORkI4BQkO4DJ2MyPMkbrbHgxrB0WRdHXoEA3ugGDn9Pc jfhVyqU8o1HXq59yflKHJkXz/toyj9xyW87Ds81qw1EwKtLrF7CLHL+G5Lfdlv6/drtk wzVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=ccZASm4o; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j23si430478ejy.309.2020.12.14.23.04.32; Mon, 14 Dec 2020 23:04:56 -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; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=ccZASm4o; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726697AbgLOHCS (ORCPT + 99 others); Tue, 15 Dec 2020 02:02:18 -0500 Received: from fllv0015.ext.ti.com ([198.47.19.141]:44902 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726377AbgLOHCM (ORCPT ); Tue, 15 Dec 2020 02:02:12 -0500 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 0BF70GdC061345; Tue, 15 Dec 2020 01:00:16 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1608015616; bh=iWkY+8bX1O7V/L8hXMtJVE3oSow43PDbAsF0LzeIDlA=; h=From:To:CC:Subject:Date; b=ccZASm4oaGgrAkN2rJJc1NnTkTek3wlBr+GPNIDAB5//stLxKoibo6aRWrMrcS4cE EGNM7cZEbQ3vLk/qVtEqEeu0WfVBIw8YwahGIJ6rFx7/QT48DDoP5HzpTdsKxQOzem F+N08xUEUp5JuUinP2XedUCOkS8JwtM5mLrzpbt0= Received: from DLEE107.ent.ti.com (dlee107.ent.ti.com [157.170.170.37]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 0BF70G7w051335 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 15 Dec 2020 01:00:16 -0600 Received: from DLEE106.ent.ti.com (157.170.170.36) by DLEE107.ent.ti.com (157.170.170.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Tue, 15 Dec 2020 01:00:16 -0600 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Tue, 15 Dec 2020 01:00:16 -0600 Received: from a0393678-ssd.dal.design.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 0BF70BdN130944; Tue, 15 Dec 2020 01:00:12 -0600 From: Kishon Vijay Abraham I To: Kishon Vijay Abraham I , Tom Joseph , Rob Herring , Bjorn Helgaas , Nadeem Athani CC: , , , , , , Subject: [PATCH v5] PCI: cadence: Retrain Link to work around Gen2 training defect. Date: Tue, 15 Dec 2020 12:30:09 +0530 Message-ID: <20201215070009.27937-1-kishon@ti.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nadeem Athani Cadence controller will not initiate autonomous speed change if strapped as Gen2. The Retrain Link bit is set as quirk to enable this speed change. Signed-off-by: Nadeem Athani [kishon@ti.com: Enable the workaround for TI's J721E SoC] Signed-off-by: Kishon Vijay Abraham I --- Hi Lorenzo, The previous version of the patch can be found at [1]. I slightly re-worked the patch from Nadeem *) Removed additional Link Up Check *) Removed quirk from pcie-cadence-plat.c *) Also removed additional compatible "cdns,cdns-pcie-host-quirk-retrain" added in that series *) Enabled the quirk for J721E [1] -> http://lore.kernel.org/r/20201211144236.3825-1-nadeem@cadence.com drivers/pci/controller/cadence/pci-j721e.c | 3 + .../controller/cadence/pcie-cadence-host.c | 67 ++++++++++++++----- drivers/pci/controller/cadence/pcie-cadence.h | 11 ++- 3 files changed, 62 insertions(+), 19 deletions(-) diff --git a/drivers/pci/controller/cadence/pci-j721e.c b/drivers/pci/controller/cadence/pci-j721e.c index dac1ac8a7615..baf729850cb1 100644 --- a/drivers/pci/controller/cadence/pci-j721e.c +++ b/drivers/pci/controller/cadence/pci-j721e.c @@ -64,6 +64,7 @@ enum j721e_pcie_mode { struct j721e_pcie_data { enum j721e_pcie_mode mode; + bool quirk_retrain_flag; }; static inline u32 j721e_pcie_user_readl(struct j721e_pcie *pcie, u32 offset) @@ -280,6 +281,7 @@ static struct pci_ops cdns_ti_pcie_host_ops = { static const struct j721e_pcie_data j721e_pcie_rc_data = { .mode = PCI_MODE_RC, + .quirk_retrain_flag = true, }; static const struct j721e_pcie_data j721e_pcie_ep_data = { @@ -388,6 +390,7 @@ static int j721e_pcie_probe(struct platform_device *pdev) bridge->ops = &cdns_ti_pcie_host_ops; rc = pci_host_bridge_priv(bridge); + rc->quirk_retrain_flag = data->quirk_retrain_flag; cdns_pcie = &rc->pcie; cdns_pcie->dev = dev; diff --git a/drivers/pci/controller/cadence/pcie-cadence-host.c b/drivers/pci/controller/cadence/pcie-cadence-host.c index 811c1cb2e8de..773c0d1137ed 100644 --- a/drivers/pci/controller/cadence/pcie-cadence-host.c +++ b/drivers/pci/controller/cadence/pcie-cadence-host.c @@ -77,6 +77,50 @@ static struct pci_ops cdns_pcie_host_ops = { .write = pci_generic_config_write, }; +static int cdns_pcie_host_wait_for_link(struct cdns_pcie *pcie) +{ + struct device *dev = pcie->dev; + int retries; + + /* Check if the link is up or not */ + for (retries = 0; retries < LINK_WAIT_MAX_RETRIES; retries++) { + if (cdns_pcie_link_up(pcie)) { + dev_info(dev, "Link up\n"); + return 0; + } + usleep_range(LINK_WAIT_USLEEP_MIN, LINK_WAIT_USLEEP_MAX); + } + + return -ETIMEDOUT; +} + +static void cdns_pcie_retrain(struct cdns_pcie *pcie) +{ + u32 lnk_cap_sls, pcie_cap_off = CDNS_PCIE_RP_CAP_OFFSET; + u16 lnk_stat, lnk_ctl; + + /* + * Set retrain bit if current speed is 2.5 GB/s, + * but the PCIe root port support is > 2.5 GB/s. + */ + + lnk_cap_sls = cdns_pcie_readl(pcie, (CDNS_PCIE_RP_BASE + pcie_cap_off + + PCI_EXP_LNKCAP)); + if ((lnk_cap_sls & PCI_EXP_LNKCAP_SLS) <= PCI_EXP_LNKCAP_SLS_2_5GB) + return; + + lnk_stat = cdns_pcie_rp_readw(pcie, pcie_cap_off + PCI_EXP_LNKSTA); + if ((lnk_stat & PCI_EXP_LNKSTA_CLS) == PCI_EXP_LNKSTA_CLS_2_5GB) { + lnk_ctl = cdns_pcie_rp_readw(pcie, + pcie_cap_off + PCI_EXP_LNKCTL); + lnk_ctl |= PCI_EXP_LNKCTL_RL; + cdns_pcie_rp_writew(pcie, pcie_cap_off + PCI_EXP_LNKCTL, + lnk_ctl); + + if (cdns_pcie_host_wait_for_link(pcie)) + return; + } +} static int cdns_pcie_host_init_root_port(struct cdns_pcie_rc *rc) { @@ -398,23 +442,6 @@ static int cdns_pcie_host_init(struct device *dev, return cdns_pcie_host_init_address_translation(rc); } -static int cdns_pcie_host_wait_for_link(struct cdns_pcie *pcie) -{ - struct device *dev = pcie->dev; - int retries; - - /* Check if the link is up or not */ - for (retries = 0; retries < LINK_WAIT_MAX_RETRIES; retries++) { - if (cdns_pcie_link_up(pcie)) { - dev_info(dev, "Link up\n"); - return 0; - } - usleep_range(LINK_WAIT_USLEEP_MIN, LINK_WAIT_USLEEP_MAX); - } - - return -ETIMEDOUT; -} - int cdns_pcie_host_setup(struct cdns_pcie_rc *rc) { struct device *dev = rc->pcie.dev; @@ -458,8 +485,12 @@ int cdns_pcie_host_setup(struct cdns_pcie_rc *rc) } ret = cdns_pcie_host_wait_for_link(pcie); - if (ret) + if (ret) { dev_dbg(dev, "PCIe link never came up\n"); + } else { + if (rc->quirk_retrain_flag) + cdns_pcie_retrain(pcie); + } for (bar = RP_BAR0; bar <= RP_NO_BAR; bar++) rc->avail_ib_bar[bar] = true; diff --git a/drivers/pci/controller/cadence/pcie-cadence.h b/drivers/pci/controller/cadence/pcie-cadence.h index 30eba6cafe2c..0f29128a5d0a 100644 --- a/drivers/pci/controller/cadence/pcie-cadence.h +++ b/drivers/pci/controller/cadence/pcie-cadence.h @@ -119,7 +119,7 @@ * Root Port Registers (PCI configuration space for the root port function) */ #define CDNS_PCIE_RP_BASE 0x00200000 - +#define CDNS_PCIE_RP_CAP_OFFSET 0xc0 /* * Address Translation Registers @@ -291,6 +291,7 @@ struct cdns_pcie { * @device_id: PCI device ID * @avail_ib_bar: Satus of RP_BAR0, RP_BAR1 and RP_NO_BAR if it's free or * available + * @quirk_retrain_flag: Retrain link as quirk for PCIe Gen2 */ struct cdns_pcie_rc { struct cdns_pcie pcie; @@ -299,6 +300,7 @@ struct cdns_pcie_rc { u32 vendor_id; u32 device_id; bool avail_ib_bar[CDNS_PCIE_RP_MAX_IB]; + bool quirk_retrain_flag; }; /** @@ -414,6 +416,13 @@ static inline void cdns_pcie_rp_writew(struct cdns_pcie *pcie, cdns_pcie_write_sz(addr, 0x2, value); } +static inline u16 cdns_pcie_rp_readw(struct cdns_pcie *pcie, u32 reg) +{ + void __iomem *addr = pcie->reg_base + CDNS_PCIE_RP_BASE + reg; + + return cdns_pcie_read_sz(addr, 0x2); +} + /* Endpoint Function register access */ static inline void cdns_pcie_ep_fn_writeb(struct cdns_pcie *pcie, u8 fn, u32 reg, u8 value) -- 2.17.1