From patchwork Mon Dec 9 09:21:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kishon Vijay Abraham I X-Patchwork-Id: 180993 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp4097901ile; Mon, 9 Dec 2019 01:21:08 -0800 (PST) X-Google-Smtp-Source: APXvYqxXFo0ZruUeBlOcJjVO6bnp+jz+VBG3KoxXGnK7XEwA5PO78hZus/+BBTRflxdbOt0027uA X-Received: by 2002:aca:6186:: with SMTP id v128mr24181908oib.17.1575883268393; Mon, 09 Dec 2019 01:21:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575883268; cv=none; d=google.com; s=arc-20160816; b=EC034Ovhe7ppanx5x4Tm0XhEKZTzLD4WiP9jgiXAc1uyO8jYzWF0CZSgljrxjtXIkG zaVjSU+82BwkxQ8EG6qZ8nwmZC1BG9SmMWIEMzVUJl3f2/5k4PGmFx0jXJc/5iKR15vZ oapk5l+kKF+b34CX6EcBIgx+HCDzAHNlJvzRnC4Zl5clrYMzVc3YeudCMBovYBzDzA3v 18+FyTecWXLuIWytQA+qoGl9WdwsusqZpL76qVjk0L3FGf29EB61PJSs32kKap9o2Zxu a24adf0so9R+bf/CMkX5zWfW3SKHjOHxGV8ueKzfPdr+fcKzJs9OvhYk1c5lNB8uBY/w C/9A== 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=OzxHiwIOPUOFBA7qrD6Vb+QLFWB9Mt5CRNKBBT7ftNQ=; b=QFCgBIgkv4zbJMVxNUPdw9cylf5iVfOVMaRNwdT1sRhbw2jRoJGla0oEpAG57GsVFJ bVwzPrbnw3A3XkVjpRnNeAQ9YoHOw3mT9yQga+O6BDJ8IrQ/0zt8dZrupr4Fi+QSZNUI amKChng/n/NEHkiy/Oon1xGYb26Q5iK153O8n8phdEVLzJPFMT62uLKI6ducSlthBKf6 2uTBC/ATNsMqYgft737Llu/wE050lKr7lGtwgZGgFy89imHKP11PlFlFMHRXSPUgBsV/ KAYjULZOngXAXORZ7991on+43YCcFUaPqeqz4nIeQFt53tlkDlk92dBnYeG+8OSGGtFL m36g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=zMp0dskh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id f4si11432613oto.169.2019.12.09.01.21.08; Mon, 09 Dec 2019 01:21:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=zMp0dskh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727605AbfLIJVH (ORCPT + 27 others); Mon, 9 Dec 2019 04:21:07 -0500 Received: from lelv0142.ext.ti.com ([198.47.23.249]:59874 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727579AbfLIJVE (ORCPT ); Mon, 9 Dec 2019 04:21:04 -0500 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id xB99KuVN045988; Mon, 9 Dec 2019 03:20:56 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1575883256; bh=OzxHiwIOPUOFBA7qrD6Vb+QLFWB9Mt5CRNKBBT7ftNQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=zMp0dskhFl7i6gKryWLdosqPB/ECwjUPm/lXAmyQ7JJb5FWW8Fe5fubmhJlEE3wwd gt0uezj7i0l19EVK6rx56mmikUauYQcdDWiNrgzoWd5yLECaWE2Ugj6S7WeyWp+K+F GRTsJs0Fc12wo6xh1WLi4RYFdk+cQhjGB1xTmf+Y= Received: from DFLE101.ent.ti.com (dfle101.ent.ti.com [10.64.6.22]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id xB99KutT063290 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 9 Dec 2019 03:20:56 -0600 Received: from DFLE100.ent.ti.com (10.64.6.21) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1847.3; Mon, 9 Dec 2019 03:20:55 -0600 Received: from lelv0327.itg.ti.com (10.180.67.183) by DFLE100.ent.ti.com (10.64.6.21) 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; Mon, 9 Dec 2019 03:20:55 -0600 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id xB99Kcd2087697; Mon, 9 Dec 2019 03:20:52 -0600 From: Kishon Vijay Abraham I To: Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , Arnd Bergmann , Andrew Murray CC: , , , , Kishon Vijay Abraham I Subject: [PATCH 04/13] PCI: cadence: Add support to start link and verify link status Date: Mon, 9 Dec 2019 14:51:38 +0530 Message-ID: <20191209092147.22901-5-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191209092147.22901-1-kishon@ti.com> References: <20191209092147.22901-1-kishon@ti.com> MIME-Version: 1.0 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 | 23 +++++++++++++++ 3 files changed, 59 insertions(+) -- 2.17.1 diff --git a/drivers/pci/controller/cadence/pcie-cadence-ep.c b/drivers/pci/controller/cadence/pcie-cadence-ep.c index 560f22b4d165..088394b6be04 100644 --- a/drivers/pci/controller/cadence/pcie-cadence-ep.c +++ b/drivers/pci/controller/cadence/pcie-cadence-ep.c @@ -355,8 +355,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 @@ -367,6 +369,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, true); + 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 ccf55e143e1d..0929554f5a81 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 @@ -201,6 +202,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_is_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; @@ -254,6 +272,16 @@ int cdns_pcie_host_setup(struct cdns_pcie_rc *rc) pcie->mem_res = res; + ret = cdns_pcie_start_link(pcie, true); + 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) goto err_init; diff --git a/drivers/pci/controller/cadence/pcie-cadence.h b/drivers/pci/controller/cadence/pcie-cadence.h index d0d91c69fa1d..f0395eaf9df5 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,8 @@ 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, bool start); + bool (*is_link_up)(struct cdns_pcie *pcie); }; /** @@ -447,6 +454,22 @@ 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, bool start) +{ + if (pcie->ops->start_link) + return pcie->ops->start_link(pcie, start); + + return 0; +} + +static inline bool cdns_pcie_is_link_up(struct cdns_pcie *pcie) +{ + if (pcie->ops->is_link_up) + return pcie->ops->is_link_up(pcie); + + return true; +} + #ifdef CONFIG_PCIE_CADENCE_HOST int cdns_pcie_host_setup(struct cdns_pcie_rc *rc); #else