Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3912873rdh; Fri, 29 Sep 2023 06:12:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8uQvNg/ijk1Z03KrAr/Gcx9+zDJ9QuH/EKSpljbL8SN6fbQ98u/2p3L5VMd7msjRB1P+H X-Received: by 2002:a05:6a00:2d13:b0:68a:5773:6319 with SMTP id fa19-20020a056a002d1300b0068a57736319mr4533679pfb.11.1695993170985; Fri, 29 Sep 2023 06:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695993170; cv=none; d=google.com; s=arc-20160816; b=A0YozBTP7p15ELtEPLfWPhT+yOtM6dYKQSi0D6iww4cZDQ1U+GOAsMIWyepNo/I/yd r2bVSl5eDU1eXkesB3+B0KIf4ZxOZNM370NADcyDWKaIodBZvhiMQKqndAI8+KXbOYSV gZZjsQVspwWtksMG5Gpi9CaZHcBr7OVBXlMKRCldIrfWqFIjfiKqaNci40NEAOIUaCuK eYQJGAoYslbdGHwlg1dcNMmXrj63URGjGfiXxPHuH1wAgtba1XTQKt2Vd4xw5IobjSVM qJOlQcODHjVx7tufFd2smdKaeqt6KBZmNrZDdVv8+PWEQEb6PYZdNrlwY//sTMzIKhgj Lkow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YnYbGtxlEyv5gg06gqhhjGtZbz2oF6HoowlGwJBpkrA=; fh=fw9CINBXChmOzbpG8z130R6wLR+N0uJHzfDIs0RDLlQ=; b=st+qH6SPmMRNlihs1veF/zuUChgOKXmV3qu+TMWDC8qqGU0pkYUmJGPjkIQLl5Zgwb cfggU2uZt/zGvqejsDBnuwwOMINH0nkMDVdhwaCb/ZW6uvFx4B79vEp7CL7T08tKAeL/ cJPtYNhLONLg04vG/GdW3LJuJr9M8kYrCQQEn0xgWxZoJIfk4SiFPY3sgPsXu9yCvbKd Am+Y3+jt2rnv6tvJbjf3IyDv+nRkCLN2kMPlsMc4sAxQfkiIt2BWpo1K/T3vMnFdF7cd i30Ru+NfinsHu222LleSdSDqBQwW64v/eCAR67CDHJmAWz8RiauIGCiU7pmEhvVqLUHx 8LaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KtarcQXN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id z21-20020aa79495000000b00690d8405fe2si5418957pfk.60.2023.09.29.06.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 06:12:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KtarcQXN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 04CD0838190B; Fri, 29 Sep 2023 04:59:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233104AbjI2L7K (ORCPT + 99 others); Fri, 29 Sep 2023 07:59:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233214AbjI2L7G (ORCPT ); Fri, 29 Sep 2023 07:59:06 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 726CF1B0; Fri, 29 Sep 2023 04:59:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695988743; x=1727524743; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5GI9De0NedLS8Fb+1iCt8QAfte6ia8Vm/9fJLfKqyBE=; b=KtarcQXNP/o65oNQiIK/akayDJM7rPqashxAuwRz1JWkR2MqiisLCzQ1 MKxFkVV+bzsSeqZgMrF1nYS7QJqVy0m01v+UPZ3eDFzI239PYue681jTM zTsHMcLPiLFZsKfxoDkROuE3Arkzi/VBJwVyrFE5slkSNOX2Ra3+0Jnb+ uVu8o7oa8tUB31Py7t9OaLavF1rcBBfXjg+qVVHiM1svY4z3nB9YDtpeh ejDapAvBN6fw0YJbMOW8vRP9KYYjd0oXlk3rGFgKs537MfiMWLEJNAmJj CRt30mLtqa95Q3Y4jpnvLd80Qgga+Y0lWn4bPof3syC9kPEvp+fUNk1cI g==; X-IronPort-AV: E=McAfee;i="6600,9927,10847"; a="362528079" X-IronPort-AV: E=Sophos;i="6.03,187,1694761200"; d="scan'208";a="362528079" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2023 04:59:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10847"; a="815581136" X-IronPort-AV: E=Sophos;i="6.03,187,1694761200"; d="scan'208";a="815581136" Received: from valeks2x-mobl.ger.corp.intel.com (HELO localhost) ([10.252.53.242]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2023 04:58:54 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Lukas Wunner , Alexandru Gagniuc , Krishna chaitanya chundru , Srinivas Pandruvada , "Rafael J . Wysocki" , linux-pm@vger.kernel.org, Bjorn Helgaas , linux-kernel@vger.kernel.org Cc: Alex Deucher , Daniel Lezcano , Amit Kucheria , Zhang Rui , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Subject: [PATCH v3 06/10] PCI: Cache PCIe device's Supported Speed Vector Date: Fri, 29 Sep 2023 14:57:19 +0300 Message-Id: <20230929115723.7864-7-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230929115723.7864-1-ilpo.jarvinen@linux.intel.com> References: <20230929115723.7864-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 29 Sep 2023 04:59:23 -0700 (PDT) The Supported Link Speeds Vector in the Link Capabilities Register 2 corresponds to the bus below on Root Ports and Downstream Ports, whereas it corresponds to the bus above on Upstream Ports and Endpoints. Only the former is currently cached in pcie_bus_speeds in the struct pci_bus. The link speeds that are supported is the intersection of these two. Store the device's Supported Link Speeds Vector into the struct pci_bus when the Function 0 is enumerated (the Multi-Function Devices must have same speeds the same for all Functions) to be easily able to calculate the intersection of Supported Link Speeds. Suggested-by: Lukas Wunner Signed-off-by: Ilpo Järvinen --- drivers/pci/probe.c | 10 ++++++++++ drivers/pci/remove.c | 2 ++ include/linux/pci.h | 1 + 3 files changed, 13 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index ca1d797a30cb..a9408f2420e5 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -2564,6 +2564,7 @@ static void pci_set_msi_domain(struct pci_dev *dev) void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) { + u8 dev_speeds = 0; int ret; pci_configure_device(dev); @@ -2590,11 +2591,20 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) pci_init_capabilities(dev); + if (pci_is_pcie(dev) && PCI_FUNC(dev->devfn) == 0) { + u32 linkcap, linkcap2; + + pcie_capability_read_dword(dev, PCI_EXP_LNKCAP, &linkcap); + pcie_capability_read_dword(dev, PCI_EXP_LNKCAP2, &linkcap2); + dev_speeds = pcie_get_supported_speeds(linkcap, linkcap2); + } /* * Add the device to our list of discovered devices * and the bus list for fixup functions, etc. */ down_write(&pci_bus_sem); + if (dev_speeds) + bus->pcie_dev_speeds = dev_speeds; list_add_tail(&dev->bus_list, &bus->devices); up_write(&pci_bus_sem); diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index d749ea8250d6..656784cfb291 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -36,6 +36,8 @@ static void pci_destroy_dev(struct pci_dev *dev) device_del(&dev->dev); down_write(&pci_bus_sem); + if (pci_is_pcie(dev) && PCI_FUNC(dev->devfn) == 0) + dev->bus->pcie_dev_speeds = 0; list_del(&dev->bus_list); up_write(&pci_bus_sem); diff --git a/include/linux/pci.h b/include/linux/pci.h index cb03f3ff9d23..b8bd3dc92032 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -665,6 +665,7 @@ struct pci_bus { unsigned char max_bus_speed; /* enum pci_bus_speed */ unsigned char cur_bus_speed; /* enum pci_bus_speed */ u8 pcie_bus_speeds;/* Supported Link Speeds Vector (+ reserved 0 at LSB) */ + u8 pcie_dev_speeds;/* Device's Supported Link Speeds Vector (+ 0 at LSB) */ #ifdef CONFIG_PCI_DOMAINS_GENERIC int domain_nr; #endif -- 2.30.2