Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp947721ybm; Wed, 22 May 2019 14:28:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzdslX2tdWpmU1lVb/4IysPE9DDc3Sz5aZBYQSMARPH/DiEKBMw/psejISWfR5AHBB16VA X-Received: by 2002:a62:1a51:: with SMTP id a78mr97317290pfa.133.1558560506768; Wed, 22 May 2019 14:28:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558560506; cv=none; d=google.com; s=arc-20160816; b=zte6x3QTr0CzXoVCphHUrOo2tOlTR84BK9Gak7++vlSZi0ZvB0Ebt48sDymkzGolZa ++6fS54A8tD0dJF+Ls0WGWDQp2FK6075f4kFCcXKQtqnZKTcVf+jhusFWylnWWjoWJ6m 9KTN9oYUulLzgFFhRYLlDA0s4AHisUPUu6dNjhgaZqPZkQOJEm8TuPBXDwYBNDlrvZw2 BcWEf69mRz2pu+DWe64xzL+RfaWdUvxPwP/jHn0mNPorjEi0XDLDgU1FdegV6dChlcqy 9XeWdo/O8NaOp3Zm7ohT09IUHn7zsEO0gctaaQvv/rE0ozuY+jnpKY9hUnETi49FwpOO /RRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=IQNgU8Ncijni4iKKQIfX8iD9WTOdi5imPd28f7HuUok=; b=veBCCYrWYdgZDTmhQVrF75uytLY0nY77l3Ryzdugf6wCCZHXHKP2wMLLRz2xA9QV0w oKqydyyP5Dgkd0kkPO00g9+PPiAyHQ0lOcAqgEe18Jy9xFt7mgrROnuBKY8aF4u0Rq7f UZLQemA2cdilhunbQTD09BMaLtofNg7fMA6iih/je1koRObyD0ReK0bT1w/xg59VE4BB s8U4y3wZ1h3HMjwEMM9gl1ELBUVrGvcGGwZOtosj+xFBgWl3K19le1RyfERg0ZTYpFMQ OI3uV5LMa0+PxXXe9SqPSqvYKeV7c71dxGYnk6UNxsEwaV7BfgukKlS5fPqSAuSEal2b y4Hw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a27si29663815pfr.186.2019.05.22.14.28.11; Wed, 22 May 2019 14:28:26 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730020AbfEVV0i (ORCPT + 99 others); Wed, 22 May 2019 17:26:38 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:57285 "EHLO relay7-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728761AbfEVV0i (ORCPT ); Wed, 22 May 2019 17:26:38 -0400 X-Originating-IP: 88.190.179.123 Received: from localhost (unknown [88.190.179.123]) (Authenticated sender: repk@triplefau.lt) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id D473020004; Wed, 22 May 2019 21:26:29 +0000 (UTC) From: Remi Pommarel To: Thomas Petazzoni , Lorenzo Pieralisi , Bjorn Helgaas Cc: Ellie Reeves , linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Remi Pommarel Subject: [PATCH v3] PCI: aardvark: Use LTSSM state to build link training flag Date: Wed, 22 May 2019 23:33:51 +0200 Message-Id: <20190522213351.21366-3-repk@triplefau.lt> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Aardvark's PCI_EXP_LNKSTA_LT flag in its link status register is not implemented and does not reflect the actual link training state (the flag is always set to 0). In order to support link re-training feature this flag has to be emulated. The Link Training and Status State Machine (LTSSM) flag in Aardvark LMI config register could be used as a link training indicator. Indeed if the LTSSM is in L0 or upper state then link training has completed (see [1]). Unfortunately because after asking a link retraining it takes a while for the LTSSM state to become less than 0x10 (due to L0s to recovery state transition delays), LTSSM can still be in L0 while link training has not finished yet. So this waits for link to be in recovery or lesser state before returning after asking for a link retrain. [1] "PCI Express Base Specification", REV. 4.0 PCI Express, February 19 2014, Table 4-14 Signed-off-by: Remi Pommarel --- Changes since v1: - Rename retraining flag field - Fix DEVCTL register writing Changes since v2: - Rewrite patch logic so it is more legible Please note that I will unlikely be able to answer any comments from May 24th to June 10th. --- drivers/pci/controller/pci-aardvark.c | 29 ++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/pci/controller/pci-aardvark.c b/drivers/pci/controller/pci-aardvark.c index 134e0306ff00..8803083b2174 100644 --- a/drivers/pci/controller/pci-aardvark.c +++ b/drivers/pci/controller/pci-aardvark.c @@ -180,6 +180,8 @@ #define LINK_WAIT_MAX_RETRIES 10 #define LINK_WAIT_USLEEP_MIN 90000 #define LINK_WAIT_USLEEP_MAX 100000 +#define RETRAIN_WAIT_MAX_RETRIES 10 +#define RETRAIN_WAIT_USLEEP_US 2000 #define MSI_IRQ_NUM 32 @@ -239,6 +241,17 @@ static int advk_pcie_wait_for_link(struct advk_pcie *pcie) return -ETIMEDOUT; } +static void advk_pcie_wait_for_retrain(struct advk_pcie *pcie) +{ + size_t retries; + + for (retries = 0; retries < RETRAIN_WAIT_MAX_RETRIES; ++retries) { + if (!advk_pcie_link_up(pcie)) + break; + udelay(RETRAIN_WAIT_USLEEP_US); + } +} + static void advk_pcie_setup_hw(struct advk_pcie *pcie) { u32 reg; @@ -426,11 +439,20 @@ advk_pci_bridge_emul_pcie_conf_read(struct pci_bridge_emul *bridge, return PCI_BRIDGE_EMUL_HANDLED; } + case PCI_EXP_LNKCTL: { + /* u32 contains both PCI_EXP_LNKCTL and PCI_EXP_LNKSTA */ + u32 val = advk_readl(pcie, PCIE_CORE_PCIEXP_CAP + reg) & + ~(PCI_EXP_LNKSTA_LT << 16); + if (!advk_pcie_link_up(pcie)) + val |= (PCI_EXP_LNKSTA_LT << 16); + *value = val; + return PCI_BRIDGE_EMUL_HANDLED; + } + case PCI_CAP_LIST_ID: case PCI_EXP_DEVCAP: case PCI_EXP_DEVCTL: case PCI_EXP_LNKCAP: - case PCI_EXP_LNKCTL: *value = advk_readl(pcie, PCIE_CORE_PCIEXP_CAP + reg); return PCI_BRIDGE_EMUL_HANDLED; default: @@ -447,8 +469,13 @@ advk_pci_bridge_emul_pcie_conf_write(struct pci_bridge_emul *bridge, switch (reg) { case PCI_EXP_DEVCTL: + advk_writel(pcie, new, PCIE_CORE_PCIEXP_CAP + reg); + break; + case PCI_EXP_LNKCTL: advk_writel(pcie, new, PCIE_CORE_PCIEXP_CAP + reg); + if (new & PCI_EXP_LNKCTL_RL) + advk_pcie_wait_for_retrain(pcie); break; case PCI_EXP_RTCTL: -- 2.20.1