Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp546894ybz; Fri, 17 Apr 2020 06:00:15 -0700 (PDT) X-Google-Smtp-Source: APiQypIPr83d2RrGoLCFriDqS688XIN2sr5xrzmwyH3MezGoaLR6qazmtC1lYChdHbI4ClqmHQrS X-Received: by 2002:a17:906:b28f:: with SMTP id q15mr2755053ejz.188.1587128415114; Fri, 17 Apr 2020 06:00:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587128415; cv=none; d=google.com; s=arc-20160816; b=trFRgQJv06JS5onPdcUQX6iY/pZMyigW87XdFKouvsNF+mkrjEK8LdWiEiLixrkhml rpGZuHUuIJoqixoUfph4FytfuHA1ZcfbvVrdS1b4ZqSEYIefWN83JI60hyna5fbp6gGd +WEoyj7JbwRBPQnK6P6BDJXqpWYw8YbZ5WYci0O1/b78h2Q726tlcqdFFPw60fPRNb8F m60YFGMiI8+QtbRWTI6Q/kkT5t4bnAaH54IbXIDFq8AeOzuNEFK8PGuz+Y0uCVQihFal NcQsoHLqBO7J6dcQArmDLa4Sq2X6WfiKEgI2e6zD13yWeLuf/LBKIzrT6S85iUhLk4Ft /XtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=4Sxi02H9RpRJe5ickAsHEIaYUb+VzvWXaGZ7c+DHSbE=; b=B7/2GKeyapPxIEGz92QQsR987BVyk2JsOSQFGJbym3MK7eLPp1LNnC4Gz4KU1VAGDh dfAWooWEGL9sRuKIbD4yNNrkqYwlUmIkAXIxVZUjBSJC7ZdUuALOm18PKDZQQ/CnL5qd rSXyHLAjaidiT5EGK6yKTtPsVLBjML6qsE0C8ZEL3F9MMz9saWy0Z93sJw38uWIE8mG+ Dkwezks2VeJvcZN3sdYAXnS4DL3jNhqAHhHYoEgBbvyPD1kV4uS/Qh2klCyZen8FVBR7 Zb0AOlxJn/ezqnwqMRwP6XYPT190ikS8t7FNqt89hcnED2pKRGmBsYojO8C0/SJcK0XV C2OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=J+HpLR0X; 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 u16si7188419edd.86.2020.04.17.05.59.52; Fri, 17 Apr 2020 06:00:15 -0700 (PDT) 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=J+HpLR0X; 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 S1730139AbgDQM6j (ORCPT + 99 others); Fri, 17 Apr 2020 08:58:39 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:50198 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729034AbgDQM6j (ORCPT ); Fri, 17 Apr 2020 08:58:39 -0400 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 03HCwCGB058763; Fri, 17 Apr 2020 07:58:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1587128292; bh=4Sxi02H9RpRJe5ickAsHEIaYUb+VzvWXaGZ7c+DHSbE=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=J+HpLR0XDOm1WWxFLuTr5GsKuQ31E/771iwGAc1yLK9HtWUpsg5uIuL6ec0h23LPX ekjVw9zpEzigHpVmweJ2CUKbTxlg2Jq93PB+rZa+5so8XTHMJfv6H/sYOu2VFPVgzu DgTPiHxhNQWNpidwEFDrdScenSNVma9+b+aYeoRg= Received: from DLEE115.ent.ti.com (dlee115.ent.ti.com [157.170.170.26]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 03HCwCoM056923 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 17 Apr 2020 07:58:12 -0500 Received: from DLEE105.ent.ti.com (157.170.170.35) by DLEE115.ent.ti.com (157.170.170.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Fri, 17 Apr 2020 07:58:12 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3 via Frontend Transport; Fri, 17 Apr 2020 07:58:12 -0500 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 03HCvsD9031089; Fri, 17 Apr 2020 07:58:09 -0500 From: Kishon Vijay Abraham I To: Tom Joseph , Bjorn Helgaas , Rob Herring , Lorenzo Pieralisi , Andrew Murray CC: Arnd Bergmann , Greg Kroah-Hartman , , , , Subject: [PATCH v3 04/14] PCI: cadence: Add support to start link and verify link status Date: Fri, 17 Apr 2020 18:27:43 +0530 Message-ID: <20200417125753.13021-5-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200417125753.13021-1-kishon@ti.com> References: <20200417125753.13021-1-kishon@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add cdns_pcie_ops to start link and verify link status. The registers to start link and to check link status is in Platform specific PCIe wrapper. Add support for platform specific drivers to add callback functions for the PCIe Cadence core to start link and verify link status. Signed-off-by: Kishon Vijay Abraham I --- .../pci/controller/cadence/pcie-cadence-ep.c | 8 +++++ .../controller/cadence/pcie-cadence-host.c | 28 +++++++++++++++++ drivers/pci/controller/cadence/pcie-cadence.h | 30 +++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/drivers/pci/controller/cadence/pcie-cadence-ep.c b/drivers/pci/controller/cadence/pcie-cadence-ep.c index 1fdae37843ef..14021d760482 100644 --- a/drivers/pci/controller/cadence/pcie-cadence-ep.c +++ b/drivers/pci/controller/cadence/pcie-cadence-ep.c @@ -354,8 +354,10 @@ static int cdns_pcie_ep_start(struct pci_epc *epc) { struct cdns_pcie_ep *ep = epc_get_drvdata(epc); struct cdns_pcie *pcie = &ep->pcie; + struct device *dev = pcie->dev; struct pci_epf *epf; u32 cfg; + int ret; /* * BIT(0) is hardwired to 1, hence function 0 is always enabled @@ -366,6 +368,12 @@ static int cdns_pcie_ep_start(struct pci_epc *epc) cfg |= BIT(epf->func_no); cdns_pcie_writel(pcie, CDNS_PCIE_LM_EP_FUNC_CFG, cfg); + ret = cdns_pcie_start_link(pcie); + if (ret) { + dev_err(dev, "Failed to start link\n"); + return ret; + } + return 0; } diff --git a/drivers/pci/controller/cadence/pcie-cadence-host.c b/drivers/pci/controller/cadence/pcie-cadence-host.c index 465607202bb5..a60b9627cfbf 100644 --- a/drivers/pci/controller/cadence/pcie-cadence-host.c +++ b/drivers/pci/controller/cadence/pcie-cadence-host.c @@ -3,6 +3,7 @@ // Cadence PCIe host controller driver. // Author: Cyrille Pitchen +#include #include #include #include @@ -197,6 +198,23 @@ static int cdns_pcie_host_init(struct device *dev, return err; } +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; @@ -256,6 +274,16 @@ int cdns_pcie_host_setup(struct cdns_pcie_rc *rc) pcie->mem_res = res; + ret = cdns_pcie_start_link(pcie); + if (ret) { + dev_err(dev, "Failed to start link\n"); + return ret; + } + + ret = cdns_pcie_host_wait_for_link(pcie); + if (ret) + dev_dbg(dev, "PCIe link never came up\n"); + ret = cdns_pcie_host_init(dev, &resources, rc); if (ret) return ret; diff --git a/drivers/pci/controller/cadence/pcie-cadence.h b/drivers/pci/controller/cadence/pcie-cadence.h index 70b6b25153e8..a6c4816b68c0 100644 --- a/drivers/pci/controller/cadence/pcie-cadence.h +++ b/drivers/pci/controller/cadence/pcie-cadence.h @@ -10,6 +10,11 @@ #include #include +/* Parameters for the waiting for link up routine */ +#define LINK_WAIT_MAX_RETRIES 10 +#define LINK_WAIT_USLEEP_MIN 90000 +#define LINK_WAIT_USLEEP_MAX 100000 + /* * Local Management Registers */ @@ -226,6 +231,9 @@ enum cdns_pcie_msg_routing { struct cdns_pcie_ops { u32 (*read)(void __iomem *addr, int size); void (*write)(void __iomem *addr, int size, u32 value); + int (*start_link)(struct cdns_pcie *pcie); + void (*stop_link)(struct cdns_pcie *pcie); + bool (*link_up)(struct cdns_pcie *pcie); }; /** @@ -445,6 +453,28 @@ static inline u32 cdns_pcie_ep_fn_readl(struct cdns_pcie *pcie, u8 fn, u32 reg) return readl(addr); } +static inline int cdns_pcie_start_link(struct cdns_pcie *pcie) +{ + if (pcie->ops->start_link) + return pcie->ops->start_link(pcie); + + return 0; +} + +static inline void cdns_pcie_stop_link(struct cdns_pcie *pcie) +{ + if (pcie->ops->stop_link) + pcie->ops->stop_link(pcie); +} + +static inline bool cdns_pcie_link_up(struct cdns_pcie *pcie) +{ + if (pcie->ops->link_up) + return pcie->ops->link_up(pcie); + + return true; +} + #ifdef CONFIG_PCIE_CADENCE_HOST int cdns_pcie_host_setup(struct cdns_pcie_rc *rc); #else -- 2.17.1