From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32461C636D6 for ; Mon, 6 Feb 2023 22:27:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229663AbjBFW12 (ORCPT ); Mon, 6 Feb 2023 17:27:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbjBFW11 (ORCPT ); Mon, 6 Feb 2023 17:27:27 -0500 Received: from bmailout1.hostsharing.net (bmailout1.hostsharing.net [IPv6:2a01:37:1000::53df:5f64:0]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECEF313500; Mon, 6 Feb 2023 14:27:26 -0800 (PST) Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "*.hostsharing.net", Issuer "RapidSSL Global TLS RSA4096 SHA256 2022 CA1" (verified OK)) by bmailout1.hostsharing.net (Postfix) with ESMTPS id 7D50630000CE2; Mon, 6 Feb 2023 23:27:22 +0100 (CET) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 64FF12F90FD; Mon, 6 Feb 2023 23:27:22 +0100 (CET) Date: Mon, 6 Feb 2023 23:27:22 +0100 From: Lukas Wunner To: Dave Jiang Cc: linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org, dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, bhelgaas@google.com, robert.moore@intel.com Subject: Re: [PATCH 10/18] PCI: Export pcie_get_speed() using the code from sysfs PCI link speed show function Message-ID: <20230206222722.GC21823@wunner.de> References: <167571650007.587790.10040913293130712882.stgit@djiang5-mobl3.local> <167571665075.587790.11513782507200128278.stgit@djiang5-mobl3.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <167571665075.587790.11513782507200128278.stgit@djiang5-mobl3.local> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org On Mon, Feb 06, 2023 at 01:50:52PM -0700, Dave Jiang wrote: > Move the logic in current_link_speed_show() to a common function and export > that functiuon as pcie_get_speed() to allow other drivers to to retrieve > the current negotiated link speed. [...] > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -6215,6 +6215,26 @@ enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev) > } > EXPORT_SYMBOL(pcie_get_width_cap); > > +/** > + * pcie_get_speed - query for the PCI device's current link speed > + * @dev: PCI device to query > + * > + * Query the PCI device current link speed. > + */ > +enum pci_bus_speed pcie_get_speed(struct pci_dev *dev) > +{ > + u16 linkstat, cls; > + int err; > + > + err = pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &linkstat); > + if (err) > + return PCI_SPEED_UNKNOWN; > + > + cls = FIELD_GET(PCI_EXP_LNKSTA_CLS, linkstat); > + return pcie_link_speed[cls]; > +} > +EXPORT_SYMBOL(pcie_get_speed); It seems we're already caching the current speed in dev->bus->cur_bus_speed. Is that not sufficient? If it isn't, that should be explained in the commit message. Thanks, Lukas