Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2153342ybm; Thu, 23 May 2019 12:14:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqymRHzKujgG+tm4vAfPLdmZorJa/otCgLo7d4VdlWtK3LNyPWrQfMHTcB60EWldcM3YlKNf X-Received: by 2002:a63:e953:: with SMTP id q19mr6490433pgj.313.1558638857799; Thu, 23 May 2019 12:14:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558638857; cv=none; d=google.com; s=arc-20160816; b=BOjZRssUNgCxX55XX4XgFoNTqsprbg19g5V2f5jAC+Y543KKs2QM2tatCG769nIktG ebcw5VUjEESFyngBHLwKXqdYwaAwoI/J2TUs/pPcCjgXFrowb1Zs3/wCvzl4rUif4qJ7 6FqojXavTElpFUBabiGnCMw01flLG37VQOvmES37AMHChO8wDeNHsD2F7E01lQ4dP0XX 5EkFVWQztM609uEg6WKc8y8ljfA3UwP/NY7jt0wWG6Vg889WQTOVcMwcKbvQRAjJIzKl GDN+UXRKUkcNLZip1TvKo/g9zTiAK2s+Yd7ojnYVaCrvZhH1IAqt/4YI55D/kBTDAktg 1frQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xiUPSEvQH4dl+nxg69M92erRGlYzqwdOOvIeLYRDhos=; b=qigF7YmmyBNjIA5xQapeqPWpxWbm7j1M8WuXzYasK5hGWwbXoqSV4ZszsUn0ntv4OZ GjYVPkPus4z7nlfSRrWCGmWRL+0Vw3ikUdJbBTuZF8UTZ2YrKOMWbuRVID+ivI0Rxco6 xutLHcV0CS7Nf+En7qEuTQfV/GXbG03vxjh6Z8rEqV9QTtuPeyLk/xyoAn+T6e7jqys2 2ey3fy/iWP3ZqcjzvKF0w7qoCcXZhEq4haY5uJSJE7oG9JnQKSuUyUUd+7dT8HOMNVJo tYEi/WWhbVt6avn3Gli2gZUpTksQ6paI8WkiOhTGqIBZEEuwORG4744geGGZvhSOHJWI Ltow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=joXQg4E2; 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 a66si363098pje.2.2019.05.23.12.14.02; Thu, 23 May 2019 12:14:17 -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; dkim=pass header.i=@kernel.org header.s=default header.b=joXQg4E2; 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 S1731670AbfEWTMe (ORCPT + 99 others); Thu, 23 May 2019 15:12:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:46282 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731525AbfEWTMb (ORCPT ); Thu, 23 May 2019 15:12:31 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9915A2133D; Thu, 23 May 2019 19:12:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558638751; bh=ftD4znQOaJSO3UarcPtZDSeOe3CXrXbU6sFqUYdLwsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=joXQg4E2nzCHu7r7ozgq93+Lq+5E015njaYjvZwj4wvEYpGXo5BEa7SseLuR+k2c6 VafD/ajTUcXHrBu0noKWoEufhWJwC052nwXZ5yh7jSoPAPnpCIV6nNDbJA/TFgG3kq 1gS9XxjptYHK8ouqAANLnRIkZWbOJh35/anKh5io= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Stefan=20M=C3=A4tje?= , Bjorn Helgaas , Andy Shevchenko Subject: [PATCH 4.14 51/77] PCI: Factor out pcie_retrain_link() function Date: Thu, 23 May 2019 21:06:09 +0200 Message-Id: <20190523181727.076690788@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181719.982121681@linuxfoundation.org> References: <20190523181719.982121681@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stefan Mätje commit 86fa6a344209d9414ea962b1f1ac6ade9dd7563a upstream. Factor out pcie_retrain_link() to use for Pericom Retrain Link quirk. No functional change intended. Signed-off-by: Stefan Mätje Signed-off-by: Bjorn Helgaas Reviewed-by: Andy Shevchenko CC: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/pci/pcie/aspm.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -211,6 +211,29 @@ static void pcie_clkpm_cap_init(struct p link->clkpm_capable = (blacklist) ? 0 : capable; } +static bool pcie_retrain_link(struct pcie_link_state *link) +{ + struct pci_dev *parent = link->pdev; + unsigned long start_jiffies; + u16 reg16; + + pcie_capability_read_word(parent, PCI_EXP_LNKCTL, ®16); + reg16 |= PCI_EXP_LNKCTL_RL; + pcie_capability_write_word(parent, PCI_EXP_LNKCTL, reg16); + + /* Wait for link training end. Break out after waiting for timeout */ + start_jiffies = jiffies; + for (;;) { + pcie_capability_read_word(parent, PCI_EXP_LNKSTA, ®16); + if (!(reg16 & PCI_EXP_LNKSTA_LT)) + break; + if (time_after(jiffies, start_jiffies + LINK_RETRAIN_TIMEOUT)) + break; + msleep(1); + } + return !(reg16 & PCI_EXP_LNKSTA_LT); +} + /* * pcie_aspm_configure_common_clock: check if the 2 ends of a link * could use common clock. If they are, configure them to use the @@ -220,7 +243,6 @@ static void pcie_aspm_configure_common_c { int same_clock = 1; u16 reg16, parent_reg, child_reg[8]; - unsigned long start_jiffies; struct pci_dev *child, *parent = link->pdev; struct pci_bus *linkbus = parent->subordinate; /* @@ -260,21 +282,7 @@ static void pcie_aspm_configure_common_c reg16 &= ~PCI_EXP_LNKCTL_CCC; pcie_capability_write_word(parent, PCI_EXP_LNKCTL, reg16); - /* Retrain link */ - reg16 |= PCI_EXP_LNKCTL_RL; - pcie_capability_write_word(parent, PCI_EXP_LNKCTL, reg16); - - /* Wait for link training end. Break out after waiting for timeout */ - start_jiffies = jiffies; - for (;;) { - pcie_capability_read_word(parent, PCI_EXP_LNKSTA, ®16); - if (!(reg16 & PCI_EXP_LNKSTA_LT)) - break; - if (time_after(jiffies, start_jiffies + LINK_RETRAIN_TIMEOUT)) - break; - msleep(1); - } - if (!(reg16 & PCI_EXP_LNKSTA_LT)) + if (pcie_retrain_link(link)) return; /* Training failed. Restore common clock configurations */