Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8125966imu; Tue, 4 Dec 2018 03:27:11 -0800 (PST) X-Google-Smtp-Source: AFSGD/XMUi6UxZsz0UFtGOmKTfwbms5knExU58h0VRd1nCoQ2FfK5svSBKRe4NGXwsTIRac3y5or X-Received: by 2002:a17:902:209:: with SMTP id 9mr19987179plc.288.1543922831837; Tue, 04 Dec 2018 03:27:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543922831; cv=none; d=google.com; s=arc-20160816; b=POyJBbrKk/ApTI9lJ34QOdUsJ7gHtCqn1rq3tOVVYZd3SoJF3/Wl1coFJHYGB9s9Ol P+mzLAQifEvoF6HL41W9jjyC4B7PVeELpiVWGBACYbjG05PYu9YsuxxBDmr6owOoHN0k FQTZBSBRTDWhSJNv2/Q378fDCPeDXGU4dfFoH8uVQEj+zh+BipQ9foOUireU4zaP5QqR iqLT1BeSaK0lUDMne1V+EMx4pCN3EwoG/jWJfyH3jfXqxipTvHTSS/3e1JlN8n52TQmN 187MKU5DW3pTomCBl/s+fc4z0F5GTeQktCwGQPPL2DXRmvMJCfRgSv6l0UmhKkD1UX4a 0+8A== 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=/Z6tQ8whmjri+EpRKLpct1arr7ikw4jQD6oFRGwxqt4=; b=s8MJtW5OLr3f5fnjC2lCcZBqc+CH2+x9FlTeG7F5bSHuqz1EY6nHGl8r3lxuwW8JGQ CzHeKg7B+e5xYkrrxuP4N2/Rk8gb8yHesf3unhdJM+5f3kiDNePkRnT3zhf6qcg6J7zH /9UADVaj0y1olW9nFVJbwk+ajQjF6OQHgKgFKs8U/5ErvOd9KuXmQH6HLuM9RhsJpc79 4cXb/vf3JRJQddxGmni/9OUP8QkVKQ1pAUq7QfCvngNnDAWIgAfLiGg3fOB1DmKbz++m E4QXB+O+Lmi54HM8o6uI5uYcV3N20m2MQQn8QV1zS4rOOGj8YPAbhNFoe9EA978Z9gRh 6Tlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=i9FMSr94; 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 b8si15372404pge.384.2018.12.04.03.26.56; Tue, 04 Dec 2018 03:27:11 -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=@kernel.org header.s=default header.b=i9FMSr94; 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 S1727210AbeLDK7z (ORCPT + 99 others); Tue, 4 Dec 2018 05:59:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:44924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726541AbeLDK7x (ORCPT ); Tue, 4 Dec 2018 05:59:53 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 DA9032087F; Tue, 4 Dec 2018 10:59:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921192; bh=M8ml5plknAYioYz8msCT+UHTjsHKjb63T+K/NfJ9mwk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i9FMSr94MsWjevQ0GJR7gmy+wtqPtfPvS9Wc9oGy8CISl2ZEj6ItcwqnmZCo/3pIG qNptSbzbdPt0GqFvXX3v3C/lFKxLZayXwhP/dIb8wuZmqQbaN195yaYdw8ZbfXeBtG AGwZWJoYszSX3akby34XlhlwWgFJWVFujmSMmQQI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Bjorn Helgaas , Alex Deucher Subject: [PATCH 4.19 081/139] PCI: Fix incorrect value returned from pcie_get_speed_cap() Date: Tue, 4 Dec 2018 11:49:22 +0100 Message-Id: <20181204103653.510773818@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204103649.950154335@linuxfoundation.org> References: <20181204103649.950154335@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mikulas Patocka commit f1f90e254e46e0a14220e4090041f68256fbe297 upstream. The macros PCI_EXP_LNKCAP_SLS_*GB are values, not bit masks. We must mask the register and compare it against them. This fixes errors like this: amdgpu: [powerplay] failed to send message 261 ret is 0 when a PCIe-v3 card is plugged into a PCIe-v1 slot, because the slot is being incorrectly reported as PCIe-v3 capable. 6cf57be0f78e, which appeared in v4.17, added pcie_get_speed_cap() with the incorrect test of PCI_EXP_LNKCAP_SLS as a bitmask. 5d9a63304032, which appeared in v4.19, changed amdgpu to use pcie_get_speed_cap(), so the amdgpu bug reports below are regressions in v4.19. Fixes: 6cf57be0f78e ("PCI: Add pcie_get_speed_cap() to find max supported link speed") Fixes: 5d9a63304032 ("drm/amdgpu: use pcie functions for link width and speed") Link: https://bugs.freedesktop.org/show_bug.cgi?id=108704 Link: https://bugs.freedesktop.org/show_bug.cgi?id=108778 Signed-off-by: Mikulas Patocka [bhelgaas: update comment, remove use of PCI_EXP_LNKCAP_SLS_8_0GB and PCI_EXP_LNKCAP_SLS_16_0GB since those should be covered by PCI_EXP_LNKCAP2, remove test of PCI_EXP_LNKCAP for zero, since that register is required] Signed-off-by: Bjorn Helgaas Acked-by: Alex Deucher Cc: stable@vger.kernel.org # v4.17+ Signed-off-by: Greg Kroah-Hartman --- drivers/pci/pci.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -5473,9 +5473,13 @@ enum pci_bus_speed pcie_get_speed_cap(st u32 lnkcap2, lnkcap; /* - * PCIe r4.0 sec 7.5.3.18 recommends using the Supported Link - * Speeds Vector in Link Capabilities 2 when supported, falling - * back to Max Link Speed in Link Capabilities otherwise. + * Link Capabilities 2 was added in PCIe r3.0, sec 7.8.18. The + * implementation note there recommends using the Supported Link + * Speeds Vector in Link Capabilities 2 when supported. + * + * Without Link Capabilities 2, i.e., prior to PCIe r3.0, software + * should use the Supported Link Speeds field in Link Capabilities, + * where only 2.5 GT/s and 5.0 GT/s speeds were defined. */ pcie_capability_read_dword(dev, PCI_EXP_LNKCAP2, &lnkcap2); if (lnkcap2) { /* PCIe r3.0-compliant */ @@ -5491,16 +5495,10 @@ enum pci_bus_speed pcie_get_speed_cap(st } pcie_capability_read_dword(dev, PCI_EXP_LNKCAP, &lnkcap); - if (lnkcap) { - if (lnkcap & PCI_EXP_LNKCAP_SLS_16_0GB) - return PCIE_SPEED_16_0GT; - else if (lnkcap & PCI_EXP_LNKCAP_SLS_8_0GB) - return PCIE_SPEED_8_0GT; - else if (lnkcap & PCI_EXP_LNKCAP_SLS_5_0GB) - return PCIE_SPEED_5_0GT; - else if (lnkcap & PCI_EXP_LNKCAP_SLS_2_5GB) - return PCIE_SPEED_2_5GT; - } + if ((lnkcap & PCI_EXP_LNKCAP_SLS) == PCI_EXP_LNKCAP_SLS_5_0GB) + return PCIE_SPEED_5_0GT; + else if ((lnkcap & PCI_EXP_LNKCAP_SLS) == PCI_EXP_LNKCAP_SLS_2_5GB) + return PCIE_SPEED_2_5GT; return PCI_SPEED_UNKNOWN; }