From patchwork Mon Mar 27 21:44:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667488 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 4D911C76195 for ; Mon, 27 Mar 2023 21:44:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229501AbjC0VoK (ORCPT ); Mon, 27 Mar 2023 17:44:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230105AbjC0VoJ (ORCPT ); Mon, 27 Mar 2023 17:44:09 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F3851FF2; Mon, 27 Mar 2023 14:44:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953449; x=1711489449; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WQYg204qkmnNNnhYQSQcABDM0C9ntwqAzA/kRY5xJBI=; b=ceYZlc1+yjQVbsnXUJ1A5+WlLDHlbYTfbVrCCguhicqhpbPEOjMYWT7R 1xHdncIDXpUdOZOSog4jp9Hl8bF35QzssI0s+0SuFa12AyX8bcInknK7O iGvu84Inp6eDwKoMjTqxDZEQALwxduNdHKn+qrw+XZhkm2kAQZwhXqrir YVw7IvavLE0/YAW+ao1gi+laKaiBjeONNmgsrRUvDaluzyughE+l9/aIy qieJRLPF8gsgJq984mowOESoG+9BxjvUn64zzLr62nUgG07v1I6ag+a0B f8SlBv/mpxxrBs+pzwpfu5tNm1xd3j6qBHw7Bs3vGPhGXN1ezS8SUbwnW w==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="339120545" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="339120545" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="772883205" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="772883205" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:08 -0700 Subject: [PATCH v2 01/21] cxl: Export QTG ids from CFMWS to sysfs From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:44:08 -0700 Message-ID: <167995344806.2857312.16258432683708945736.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Export the QoS Throttling Group ID from the CXL Fixed Memory Window Structure (CFMWS) under the root decoder sysfs attributes. CXL rev3.0 9.17.1.3 CXL Fixed Memory Window Structure (CFMWS) cxl cli will use this QTG ID to match with the _DSM retrieved QTG ID for a hot-plugged CXL memory device DPA memory range to make sure that the DPA range is under the right CFMWS window. Signed-off-by: Dave Jiang Reviewed-by: Ira Weiny --- v2: - Add explanation commit header (Jonathan) --- Documentation/ABI/testing/sysfs-bus-cxl | 9 +++++++++ drivers/cxl/acpi.c | 3 +++ drivers/cxl/core/port.c | 14 ++++++++++++++ drivers/cxl/cxl.h | 3 +++ 4 files changed, 29 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl index 3acf2f17a73f..471ac9a37078 100644 --- a/Documentation/ABI/testing/sysfs-bus-cxl +++ b/Documentation/ABI/testing/sysfs-bus-cxl @@ -309,6 +309,15 @@ Description: (WO) Write a string in the form 'regionZ' to delete that region, provided it is currently idle / not bound to a driver. +What: /sys/bus/cxl/devices/decoderX.Y/qtg_id +Date: Jan, 2023 +KernelVersion: v6.4 +Contact: linux-cxl@vger.kernel.org +Description: + (RO) Shows the QoS Throttling Group ID. The QTG ID for a root + decoder comes from the CFMWS structure of the CEDT. A value of + -1 indicates that no QTG ID was retrieved. The QTG ID is used as + guidance to match against the QTG ID of a hot-plugged device. What: /sys/bus/cxl/devices/regionZ/uuid Date: May, 2022 diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c index 7e1765b09e04..abc24137c291 100644 --- a/drivers/cxl/acpi.c +++ b/drivers/cxl/acpi.c @@ -289,6 +289,9 @@ static int cxl_parse_cfmws(union acpi_subtable_headers *header, void *arg, } } } + + cxld->qtg_id = cfmws->qtg_id; + rc = cxl_decoder_add(cxld, target_map); err_xormap: if (rc) diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index 8ee6b6e2e2a4..5ec48dddb2f9 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -276,6 +276,16 @@ static ssize_t interleave_ways_show(struct device *dev, static DEVICE_ATTR_RO(interleave_ways); +static ssize_t qtg_id_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct cxl_decoder *cxld = to_cxl_decoder(dev); + + return sysfs_emit(buf, "%d\n", cxld->qtg_id); +} + +static DEVICE_ATTR_RO(qtg_id); + static struct attribute *cxl_decoder_base_attrs[] = { &dev_attr_start.attr, &dev_attr_size.attr, @@ -295,6 +305,7 @@ static struct attribute *cxl_decoder_root_attrs[] = { &dev_attr_cap_type2.attr, &dev_attr_cap_type3.attr, &dev_attr_target_list.attr, + &dev_attr_qtg_id.attr, SET_CXL_REGION_ATTR(create_pmem_region) SET_CXL_REGION_ATTR(create_ram_region) SET_CXL_REGION_ATTR(delete_region) @@ -1649,6 +1660,7 @@ struct cxl_root_decoder *cxl_root_decoder_alloc(struct cxl_port *port, } atomic_set(&cxlrd->region_id, rc); + cxld->qtg_id = CXL_QTG_ID_INVALID; return cxlrd; } EXPORT_SYMBOL_NS_GPL(cxl_root_decoder_alloc, CXL); @@ -1686,6 +1698,7 @@ struct cxl_switch_decoder *cxl_switch_decoder_alloc(struct cxl_port *port, cxld = &cxlsd->cxld; cxld->dev.type = &cxl_decoder_switch_type; + cxld->qtg_id = CXL_QTG_ID_INVALID; return cxlsd; } EXPORT_SYMBOL_NS_GPL(cxl_switch_decoder_alloc, CXL); @@ -1718,6 +1731,7 @@ struct cxl_endpoint_decoder *cxl_endpoint_decoder_alloc(struct cxl_port *port) } cxld->dev.type = &cxl_decoder_endpoint_type; + cxld->qtg_id = CXL_QTG_ID_INVALID; return cxled; } EXPORT_SYMBOL_NS_GPL(cxl_endpoint_decoder_alloc, CXL); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index f2b0962a552d..cc3309794b45 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -300,6 +300,7 @@ enum cxl_decoder_type { */ #define CXL_DECODER_MAX_INTERLEAVE 16 +#define CXL_QTG_ID_INVALID -1 /** * struct cxl_decoder - Common CXL HDM Decoder Attributes @@ -311,6 +312,7 @@ enum cxl_decoder_type { * @target_type: accelerator vs expander (type2 vs type3) selector * @region: currently assigned region for this decoder * @flags: memory type capabilities and locking + * @qtg_id: QoS Throttling Group ID * @commit: device/decoder-type specific callback to commit settings to hw * @reset: device/decoder-type specific callback to reset hw settings */ @@ -323,6 +325,7 @@ struct cxl_decoder { enum cxl_decoder_type target_type; struct cxl_region *region; unsigned long flags; + int qtg_id; int (*commit)(struct cxl_decoder *cxld); int (*reset)(struct cxl_decoder *cxld); }; From patchwork Mon Mar 27 21:44:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667942 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 1012FC76195 for ; Mon, 27 Mar 2023 21:44:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230361AbjC0VoR (ORCPT ); Mon, 27 Mar 2023 17:44:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230105AbjC0VoQ (ORCPT ); Mon, 27 Mar 2023 17:44:16 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5D281FF2; Mon, 27 Mar 2023 14:44:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953455; x=1711489455; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pFqON91iYbteazF95zQ7LMgoJ45bF8CJY0dtaCEPOTc=; b=TAP0RRP/5E4i4SYqfbYkACMF13GBuuxNeFllc4OlEqcu4Z4Ugsbz73Er 2hVQ1gvS3NvhBKA+Ced2GhiAswp0G4tbtkN/OgxL51Xqvs7tyNZsp3p4D ePTKmAzMg4xZdCRBAStzzXP/QYjVm5V3V1HRwxGhjY16KQfnlsPqQrsfJ dZeywbRfcSIynxNLFKk+QkjfPpsyurDHrHFUOw099KcBHTEz9App/pU7h kaBazK0wHKr4fdZ0NUGeyoDex63JBbdYDh2EGPUv1kNZraYQQKGSFSw4S cIWxDUE7aNH0NCizuoZb97GcHDtJ80BmeQQPW9m43Mf0jLIvgciR39E2X g==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="320798895" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="320798895" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="857803675" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="857803675" Received: from spal2-desk3.gar.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:14 -0700 Subject: [PATCH v2 02/21] cxl: Add checksum verification to CDAT from CXL From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:44:13 -0700 Message-ID: <167995345388.2857312.2421270054519644444.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org A CDAT table is available from a CXL device. The table is read by the driver and cached in software. With the CXL subsystem needing to parse the CDAT table, the checksum should be verified. Add checksum verification after the CDAT table is read from device. Signed-off-by: Dave Jiang Reviewed-by: Ira Weiny --- v2: - Drop ACPI checksum export and just use local verification. (Dan) --- drivers/cxl/core/pci.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c index 25b7e8125d5d..e0d5e6525c0d 100644 --- a/drivers/cxl/core/pci.c +++ b/drivers/cxl/core/pci.c @@ -528,6 +528,16 @@ static int cxl_cdat_read_table(struct device *dev, return 0; } +static unsigned char cdat_checksum(void *buf, size_t size) +{ + unsigned char sum, *data = buf; + size_t i; + + for (sum = 0, i = 0; i < size; i++) + sum += data[i]; + return 0 - sum; +} + /** * read_cdat_data - Read the CDAT data on this port * @port: Port to read data from @@ -573,6 +583,12 @@ void read_cdat_data(struct cxl_port *port) } port->cdat.table = cdat_table + sizeof(__le32); + if (cdat_checksum(port->cdat.table, cdat_length)) { + /* Don't leave table data allocated on error */ + devm_kfree(dev, cdat_table); + dev_err(dev, "CDAT data checksum error\n"); + } + port->cdat.length = cdat_length; } EXPORT_SYMBOL_NS_GPL(read_cdat_data, CXL); From patchwork Mon Mar 27 21:44:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667487 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 27269C6FD1D for ; Mon, 27 Mar 2023 21:44:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230105AbjC0VoX (ORCPT ); Mon, 27 Mar 2023 17:44:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229912AbjC0VoW (ORCPT ); Mon, 27 Mar 2023 17:44:22 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DF3B1FF2; Mon, 27 Mar 2023 14:44:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953461; x=1711489461; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qMX+9/E8E3AG4Wg+IkDmtuH/c52x1b9v4GhmwnO7wpE=; b=BllbbbYdGkWKIByqMvOfKCtcw9WjKw3Jm6ytJ3lk6DOFUot0sb/QmGTi 66BGN1QYRcihcg12eLNLNmjeNTkNCU2ZxLleefrCb7JzyfxzOc99QYUnq Ltk9voXciasuMetcyMqoAGqvjfqfDLTuZ3xbpytvEPR3E9hkVBwoWQbCy D2HGkovHcNYwyGmdBWT0AMkWpX9hSMRRR7dCs6y8jRu418fgrMAPCm9bP 5XJ/dOGLlvuldkWiPpJsRi18FAnw7822rrP4Y9jFeQzigkOmpIAmkAvBm 8fRkl0abr+S+rzC64ZNbycUiR0AyBxMbCFwwto5EVlNLt6869XvKDqzxS Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="320798906" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="320798906" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="857803689" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="857803689" Received: from spal2-desk3.gar.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:20 -0700 Subject: [PATCH v2 03/21] cxl: Add support for reading CXL switch CDAT table From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:44:20 -0700 Message-ID: <167995346010.2857312.16383291901753972325.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Move read_cdat_data() from endpoint probe to general port probe to allow reading of CDAT data for CXL switches as well as CXL device. Add wrapper support for cxl_test to bypass the cdat reading. Signed-off-by: Dave Jiang Reviewed-by: Ira Weiny --- drivers/cxl/core/pci.c | 20 +++++++++++++++----- drivers/cxl/port.c | 6 +++--- tools/testing/cxl/Kbuild | 1 + tools/testing/cxl/test/mock.c | 5 +++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c index e0d5e6525c0d..4241c7b8d5c2 100644 --- a/drivers/cxl/core/pci.c +++ b/drivers/cxl/core/pci.c @@ -546,16 +546,26 @@ static unsigned char cdat_checksum(void *buf, size_t size) */ void read_cdat_data(struct cxl_port *port) { - struct pci_doe_mb *cdat_doe; - struct device *dev = &port->dev; struct device *uport = port->uport; - struct cxl_memdev *cxlmd = to_cxl_memdev(uport); - struct cxl_dev_state *cxlds = cxlmd->cxlds; - struct pci_dev *pdev = to_pci_dev(cxlds->dev); + struct device *dev = &port->dev; + struct cxl_dev_state *cxlds; + struct pci_doe_mb *cdat_doe; + struct cxl_memdev *cxlmd; + struct pci_dev *pdev; size_t cdat_length; void *cdat_table; int rc; + if (is_cxl_memdev(uport)) { + cxlmd = to_cxl_memdev(uport); + cxlds = cxlmd->cxlds; + pdev = to_pci_dev(cxlds->dev); + } else if (dev_is_pci(uport)) { + pdev = to_pci_dev(uport); + } else { + return; + } + cdat_doe = pci_find_doe_mailbox(pdev, PCI_DVSEC_VENDOR_ID_CXL, CXL_DOE_PROTOCOL_TABLE_ACCESS); if (!cdat_doe) { diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c index 1049bb5ea496..60a865680e22 100644 --- a/drivers/cxl/port.c +++ b/drivers/cxl/port.c @@ -93,9 +93,6 @@ static int cxl_endpoint_port_probe(struct cxl_port *port) if (IS_ERR(cxlhdm)) return PTR_ERR(cxlhdm); - /* Cache the data early to ensure is_visible() works */ - read_cdat_data(port); - get_device(&cxlmd->dev); rc = devm_add_action_or_reset(&port->dev, schedule_detach, cxlmd); if (rc) @@ -135,6 +132,9 @@ static int cxl_port_probe(struct device *dev) { struct cxl_port *port = to_cxl_port(dev); + /* Cache the data early to ensure is_visible() works */ + read_cdat_data(port); + if (is_cxl_endpoint(port)) return cxl_endpoint_port_probe(port); return cxl_switch_port_probe(port); diff --git a/tools/testing/cxl/Kbuild b/tools/testing/cxl/Kbuild index fba7bec96acd..2637c71f3378 100644 --- a/tools/testing/cxl/Kbuild +++ b/tools/testing/cxl/Kbuild @@ -12,6 +12,7 @@ ldflags-y += --wrap=cxl_await_media_ready ldflags-y += --wrap=cxl_hdm_decode_init ldflags-y += --wrap=cxl_dvsec_rr_decode ldflags-y += --wrap=cxl_rcrb_to_component +ldflags-y += --wrap=read_cdat_data DRIVERS := ../../../drivers CXL_SRC := $(DRIVERS)/cxl diff --git a/tools/testing/cxl/test/mock.c b/tools/testing/cxl/test/mock.c index c4e53f22e421..3a75909b2aae 100644 --- a/tools/testing/cxl/test/mock.c +++ b/tools/testing/cxl/test/mock.c @@ -263,6 +263,11 @@ resource_size_t __wrap_cxl_rcrb_to_component(struct device *dev, } EXPORT_SYMBOL_NS_GPL(__wrap_cxl_rcrb_to_component, CXL); +void __wrap_read_cdat_data(struct cxl_port *port) +{ +} +EXPORT_SYMBOL_NS_GPL(__wrap_read_cdat_data, CXL); + MODULE_LICENSE("GPL v2"); MODULE_IMPORT_NS(ACPI); MODULE_IMPORT_NS(CXL); From patchwork Mon Mar 27 21:44:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667941 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 DAFBBC76195 for ; Mon, 27 Mar 2023 21:44:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230432AbjC0Vob (ORCPT ); Mon, 27 Mar 2023 17:44:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229663AbjC0Voa (ORCPT ); Mon, 27 Mar 2023 17:44:30 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9D0C26B3; Mon, 27 Mar 2023 14:44:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953468; x=1711489468; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=B9VBVgS4nybtHfZE9p+drAXT3PxU7FrJ0X5i9nulIVQ=; b=Uo4NKqKD218sBnw9z8y1cP3HwTEo/v0fjAkrsnFj4O4SqIzniFvDrCW2 sCg7yPsoGl4OHoHAS8rh3rDrG5HL5Exk3vog080PMPzW9nc8vwYYa3LM7 OEcocw3HyzQVk94MfBdDxMg419C+2EO6fQVF5wZv96QE1ZpDfl26QkFW4 rncQQYzwME44R2LIx7deaVP1ExeLnsyc2XIiyq1qq4Ekd2v75QpKAntMO 2XD7BFrN5ScBCjdg8lWDHzNW52w5YpZp3TjcKlDb7kEBePpg1+qYkiYkC ZWd7RGUDmBG/QPAFRwHc8sxrR/1b2Vlg+Os+QylibEFfhZTvIM3LiBksu Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="320798929" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="320798929" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="857803703" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="857803703" Received: from spal2-desk3.gar.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:26 -0700 Subject: [PATCH v2 04/21] cxl: Add common helpers for cdat parsing From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:44:26 -0700 Message-ID: <167995346626.2857312.13797065956132374426.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add helper functions to parse the CDAT table and provide a callback to parse the sub-table. Helpers are provided for DSMAS and DSLBIS sub-table parsing. The code is patterned after the ACPI table parsing helpers. Signed-off-by: Dave Jiang --- v2: - Use local headers to handle LE instead of ACPI header - Reduce complexity of parser function. (Jonathan) - Directly access header type. (Jonathan) - Simplify header ptr math. (Jonathan) - Move parsed counter to the correct location. (Jonathan) - Add LE to host conversion for entry length --- drivers/cxl/core/Makefile | 1 drivers/cxl/core/cdat.c | 100 +++++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlpci.h | 29 +++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 drivers/cxl/core/cdat.c diff --git a/drivers/cxl/core/Makefile b/drivers/cxl/core/Makefile index ca4ae31d8f57..867a8014b462 100644 --- a/drivers/cxl/core/Makefile +++ b/drivers/cxl/core/Makefile @@ -12,5 +12,6 @@ cxl_core-y += memdev.o cxl_core-y += mbox.o cxl_core-y += pci.o cxl_core-y += hdm.o +cxl_core-y += cdat.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o diff --git a/drivers/cxl/core/cdat.c b/drivers/cxl/core/cdat.c new file mode 100644 index 000000000000..210f4499bddb --- /dev/null +++ b/drivers/cxl/core/cdat.c @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2023 Intel Corporation. All rights reserved. */ +#include "cxlpci.h" +#include "cxl.h" + +static bool has_handler(struct cdat_subtable_proc *proc) +{ + return proc->handler; +} + +static int call_handler(struct cdat_subtable_proc *proc, + struct cdat_subtable_entry *ent) +{ + if (has_handler(proc)) + return proc->handler(ent->hdr, proc->arg); + return -EINVAL; +} + +static bool cdat_is_subtable_match(struct cdat_subtable_entry *ent) +{ + return ent->hdr->type == ent->type; +} + +static int cdat_table_parse_entries(enum cdat_type type, + struct cdat_header *table_header, + struct cdat_subtable_proc *proc) +{ + unsigned long table_end, entry_len; + struct cdat_subtable_entry entry; + int count = 0; + int rc; + + if (!has_handler(proc)) + return -EINVAL; + + table_end = (unsigned long)table_header + table_header->length; + + if (type >= CDAT_TYPE_RESERVED) + return -EINVAL; + + entry.type = type; + entry.hdr = (struct cdat_entry_header *)(table_header + 1); + + while ((unsigned long)entry.hdr < table_end) { + entry_len = le16_to_cpu(entry.hdr->length); + + if ((unsigned long)entry.hdr + entry_len > table_end) + return -EINVAL; + + if (entry_len == 0) + return -EINVAL; + + if (cdat_is_subtable_match(&entry)) { + rc = call_handler(proc, &entry); + if (rc) + return rc; + count++; + } + + entry.hdr = (struct cdat_entry_header *)((unsigned long)entry.hdr + entry_len); + } + + return count; +} + +int cdat_table_parse_dsmas(struct cdat_header *table, + cdat_tbl_entry_handler handler, void *arg) +{ + struct cdat_subtable_proc proc = { + .handler = handler, + .arg = arg, + }; + + return cdat_table_parse_entries(CDAT_TYPE_DSMAS, table, &proc); +} +EXPORT_SYMBOL_NS_GPL(cdat_table_parse_dsmas, CXL); + +int cdat_table_parse_dslbis(struct cdat_header *table, + cdat_tbl_entry_handler handler, void *arg) +{ + struct cdat_subtable_proc proc = { + .handler = handler, + .arg = arg, + }; + + return cdat_table_parse_entries(CDAT_TYPE_DSLBIS, table, &proc); +} +EXPORT_SYMBOL_NS_GPL(cdat_table_parse_dslbis, CXL); + +int cdat_table_parse_sslbis(struct cdat_header *table, + cdat_tbl_entry_handler handler, void *arg) +{ + struct cdat_subtable_proc proc = { + .handler = handler, + .arg = arg, + }; + + return cdat_table_parse_entries(CDAT_TYPE_SSLBIS, table, &proc); +} +EXPORT_SYMBOL_NS_GPL(cdat_table_parse_sslbis, CXL); diff --git a/drivers/cxl/cxlpci.h b/drivers/cxl/cxlpci.h index 0465ef963cd6..45e2f2bf5ef8 100644 --- a/drivers/cxl/cxlpci.h +++ b/drivers/cxl/cxlpci.h @@ -76,12 +76,34 @@ struct cdat_header { __le32 sequence; } __packed; +enum cdat_type { + CDAT_TYPE_DSMAS = 0, + CDAT_TYPE_DSLBIS, + CDAT_TYPE_DSMSCIS, + CDAT_TYPE_DSIS, + CDAT_TYPE_DSEMTS, + CDAT_TYPE_SSLBIS, + CDAT_TYPE_RESERVED +}; + struct cdat_entry_header { u8 type; u8 reserved; __le16 length; } __packed; +typedef int (*cdat_tbl_entry_handler)(struct cdat_entry_header *header, void *arg); + +struct cdat_subtable_proc { + cdat_tbl_entry_handler handler; + void *arg; +}; + +struct cdat_subtable_entry { + struct cdat_entry_header *hdr; + enum cdat_type type; +}; + int devm_cxl_port_enumerate_dports(struct cxl_port *port); struct cxl_dev_state; int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm, @@ -90,4 +112,11 @@ void read_cdat_data(struct cxl_port *port); void cxl_cor_error_detected(struct pci_dev *pdev); pci_ers_result_t cxl_error_detected(struct pci_dev *pdev, pci_channel_state_t state); + +#define cdat_table_parse(x) \ +int cdat_table_parse_##x(struct cdat_header *table, \ + cdat_tbl_entry_handler handler, void *arg) +cdat_table_parse(dsmas); +cdat_table_parse(dslbis); +cdat_table_parse(sslbis); #endif /* __CXL_PCI_H__ */ From patchwork Mon Mar 27 21:44:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667486 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 360C0C6FD1D for ; Mon, 27 Mar 2023 21:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229663AbjC0Vo4 (ORCPT ); Mon, 27 Mar 2023 17:44:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230347AbjC0Vog (ORCPT ); Mon, 27 Mar 2023 17:44:36 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19E812696; Mon, 27 Mar 2023 14:44:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953475; x=1711489475; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eKZ1lT0Wp+RGk86M0TTpu5dLEU7Fb2kX1PZ2dmEqmtc=; b=jJurMHRnnyAcghAlCTDPbOuPfuh/mEQvc5JOFg7FMgkmy/6xHAMYMQpc aqrK9BJ5x86IkXfjev+mrsvN5VfAo+tHgJjCvbn9omy/zj/wPCMNWTIY/ +JehB+GAy5FYWhigXaEJY5jzmbNM923VATo6P2iu3XW7Vw25wrp9wT0q6 5j2dJMHH1Y2cmkxZpTQin9lVuSdST1mYPUCS28vDMRCSQL0FTmts/65Ke +BsSj330K3h7OOBc8CJF6WKNz7cNgtdxKlEYr69sSVZ6aqiaCYdTPP8LU kUuccR6xSPQ5mAQHcc12YrJjnYIZq3J+RP4Zz9gqL0uF4zA7Te85xKwBz Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="320798947" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="320798947" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="857803728" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="857803728" Received: from spal2-desk3.gar.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:33 -0700 Subject: [PATCH v2 05/21] cxl: Add callback to parse the DSMAS subtables from CDAT From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:44:32 -0700 Message-ID: <167995347254.2857312.246180486952683569.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Provide a callback function to the CDAT parser in order to parse the Device Scoped Memory Affinity Structure (DSMAS). Each DSMAS structure contains the DPA range and its associated attributes in each entry. See the CDAT specification for details. Signed-off-by: Dave Jiang --- v2: - Add DSMAS table size check. (Lukas) - Use local DSMAS header for LE handling. - Remove dsmas lock. (Jonathan) - Fix handle size (Jonathan) - Add LE to host conversion for DSMAS address and length. - Make dsmas_list local --- drivers/cxl/core/cdat.c | 26 ++++++++++++++++++++++++++ drivers/cxl/cxl.h | 1 + drivers/cxl/cxlpci.h | 18 ++++++++++++++++++ drivers/cxl/port.c | 24 ++++++++++++++++++++++++ 4 files changed, 69 insertions(+) diff --git a/drivers/cxl/core/cdat.c b/drivers/cxl/core/cdat.c index 210f4499bddb..d068609fb6f9 100644 --- a/drivers/cxl/core/cdat.c +++ b/drivers/cxl/core/cdat.c @@ -98,3 +98,29 @@ int cdat_table_parse_sslbis(struct cdat_header *table, return cdat_table_parse_entries(CDAT_TYPE_SSLBIS, table, &proc); } EXPORT_SYMBOL_NS_GPL(cdat_table_parse_sslbis, CXL); + +int cxl_dsmas_parse_entry(struct cdat_entry_header *header, void *arg) +{ + struct cdat_dsmas *dsmas = (struct cdat_dsmas *)(header); + struct list_head *dsmas_list = (struct list_head *)arg; + struct dsmas_entry *dent; + + if (dsmas->hdr.length != sizeof(*dsmas)) { + pr_warn("Malformed DSMAS table length: (%lu:%u)\n", + (unsigned long)sizeof(*dsmas), dsmas->hdr.length); + return -EINVAL; + } + + dent = kzalloc(sizeof(*dent), GFP_KERNEL); + if (!dent) + return -ENOMEM; + + dent->handle = dsmas->dsmad_handle; + dent->dpa_range.start = le64_to_cpu(dsmas->dpa_base_address); + dent->dpa_range.end = le64_to_cpu(dsmas->dpa_base_address) + + le64_to_cpu(dsmas->dpa_length) - 1; + list_add_tail(&dent->list, dsmas_list); + + return 0; +} +EXPORT_SYMBOL_NS_GPL(cxl_dsmas_parse_entry, CXL); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index cc3309794b45..9d0e22fe72c0 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -8,6 +8,7 @@ #include #include #include +#include #include /** diff --git a/drivers/cxl/cxlpci.h b/drivers/cxl/cxlpci.h index 45e2f2bf5ef8..9a2468a93d83 100644 --- a/drivers/cxl/cxlpci.h +++ b/drivers/cxl/cxlpci.h @@ -104,6 +104,22 @@ struct cdat_subtable_entry { enum cdat_type type; }; +struct dsmas_entry { + struct list_head list; + struct range dpa_range; + u8 handle; +}; + +/* Sub-table 0: Device Scoped Memory Affinity Structure (DSMAS) */ +struct cdat_dsmas { + struct cdat_entry_header hdr; + u8 dsmad_handle; + u8 flags; + __u16 reserved; + __le64 dpa_base_address; + __le64 dpa_length; +} __packed; + int devm_cxl_port_enumerate_dports(struct cxl_port *port); struct cxl_dev_state; int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm, @@ -119,4 +135,6 @@ int cdat_table_parse_##x(struct cdat_header *table, \ cdat_table_parse(dsmas); cdat_table_parse(dslbis); cdat_table_parse(sslbis); + +int cxl_dsmas_parse_entry(struct cdat_entry_header *header, void *arg); #endif /* __CXL_PCI_H__ */ diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c index 60a865680e22..c8136797d528 100644 --- a/drivers/cxl/port.c +++ b/drivers/cxl/port.c @@ -57,6 +57,16 @@ static int discover_region(struct device *dev, void *root) return 0; } +static void dsmas_list_destroy(struct list_head *dsmas_list) +{ + struct dsmas_entry *dentry, *n; + + list_for_each_entry_safe(dentry, n, dsmas_list, list) { + list_del(&dentry->list); + kfree(dentry); + } +} + static int cxl_switch_port_probe(struct cxl_port *port) { struct cxl_hdm *cxlhdm; @@ -131,9 +141,23 @@ static int cxl_endpoint_port_probe(struct cxl_port *port) static int cxl_port_probe(struct device *dev) { struct cxl_port *port = to_cxl_port(dev); + int rc; /* Cache the data early to ensure is_visible() works */ read_cdat_data(port); + if (port->cdat.table) { + if (is_cxl_endpoint(port)) { + LIST_HEAD(dsmas_list); + + rc = cdat_table_parse_dsmas(port->cdat.table, + cxl_dsmas_parse_entry, + (void *)&dsmas_list); + if (rc < 0) + dev_warn(dev, "Failed to parse DSMAS: %d\n", rc); + + dsmas_list_destroy(&dsmas_list); + } + } if (is_cxl_endpoint(port)) return cxl_endpoint_port_probe(port); From patchwork Mon Mar 27 21:44:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667940 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 AF1AFC761A6 for ; Mon, 27 Mar 2023 21:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229767AbjC0Vo4 (ORCPT ); Mon, 27 Mar 2023 17:44:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231493AbjC0Vom (ORCPT ); Mon, 27 Mar 2023 17:44:42 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5193E1FF2; Mon, 27 Mar 2023 14:44:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953481; x=1711489481; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ujdW4aVFzAQRcZBKJuVkW18/txhJnPiHwlRF2FWgRq4=; b=D+ELJchGXt9UgTxRsWu7sBaSAIJzIbS3wyk59Qlqt0SWmazNVdGnRJ6Y BVJC6k0Pm8K25Vd9+xQFQjmjLZ3G3riYEY1TRJJUdE7F+Bpo9QE1SHMXX gNjRfLtVtDHDEER8mYVZtfYlXnhBx40bB1+9/1lKNxCaJWjQEtVwCcspf RuHHzU62/D6rw3G7mFZXcNWpikKgBY2qRLtdPZD6/G9hcAV5MKQEqWNTK D/F908H/GHKh9HJB4hFAzp4u+zl8uYyXYcDDK+cJA+wNVIEoOJdgEzJLu nswvNY12KCzNJ8yIgP5UE0orQoNuCTkvjv3rUfqgZUXMSSoeZZVnG4fUA Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="320798971" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="320798971" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="857803739" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="857803739" Received: from spal2-desk3.gar.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:40 -0700 Subject: [PATCH v2 06/21] cxl: Add callback to parse the DSLBIS subtable from CDAT From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:44:39 -0700 Message-ID: <167995347963.2857312.11781710463537827645.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Provide a callback to parse the Device Scoped Latency and Bandwidth Information Structure (DSLBIS) in the CDAT structures. The DSLBIS contains the bandwidth and latency information that's tied to a DSMAS handle. The driver will retrieve the read and write latency and bandwidth associated with the DSMAS which is tied to a DPA range. Signed-off-by: Dave Jiang --- v2: - Add size check to DSLIBIS table. (Lukas) - Remove unnecessary entry type check. (Jonathan) - Move data_type check to after match. (Jonathan) - Skip unknown data type. (Jonathan) - Add overflow check for unit multiply. (Jonathan) - Use dev_warn() when entries parsing fail. (Jonathan) --- drivers/cxl/core/cdat.c | 41 +++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlpci.h | 34 +++++++++++++++++++++++++++++++++- drivers/cxl/port.c | 9 ++++++++- 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/drivers/cxl/core/cdat.c b/drivers/cxl/core/cdat.c index d068609fb6f9..0e88973e9f38 100644 --- a/drivers/cxl/core/cdat.c +++ b/drivers/cxl/core/cdat.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright(c) 2023 Intel Corporation. All rights reserved. */ +#include #include "cxlpci.h" #include "cxl.h" @@ -124,3 +125,43 @@ int cxl_dsmas_parse_entry(struct cdat_entry_header *header, void *arg) return 0; } EXPORT_SYMBOL_NS_GPL(cxl_dsmas_parse_entry, CXL); + +int cxl_dslbis_parse_entry(struct cdat_entry_header *header, void *arg) +{ + struct cdat_dslbis *dslbis = (struct cdat_dslbis *)header; + struct list_head *dsmas_list = (struct list_head *)arg; + struct dsmas_entry *dent; + + if (dslbis->hdr.length != sizeof(*dslbis)) { + pr_warn("Malformed DSLBIS table length: (%lu:%u)\n", + (unsigned long)sizeof(*dslbis), dslbis->hdr.length); + return -EINVAL; + } + + /* Unrecognized data type, we can skip */ + if (dslbis->data_type >= HMAT_SLLBIS_DATA_TYPE_MAX) + return 0; + + list_for_each_entry(dent, dsmas_list, list) { + u64 val; + int rc; + + if (dslbis->handle != dent->handle) + continue; + + /* Not a memory type, skip */ + if ((dslbis->flags & DSLBIS_MEM_MASK) != DSLBIS_MEM_MEMORY) + return 0; + + rc = check_mul_overflow(le64_to_cpu(dslbis->entry_base_unit), + le16_to_cpu(dslbis->entry[0]), &val); + if (unlikely(rc)) + pr_warn("DSLBIS value overflowed!\n"); + + dent->qos[dslbis->data_type] = val; + break; + } + + return 0; +} +EXPORT_SYMBOL_NS_GPL(cxl_dslbis_parse_entry, CXL); diff --git a/drivers/cxl/cxlpci.h b/drivers/cxl/cxlpci.h index 9a2468a93d83..1429de49e0c4 100644 --- a/drivers/cxl/cxlpci.h +++ b/drivers/cxl/cxlpci.h @@ -104,10 +104,21 @@ struct cdat_subtable_entry { enum cdat_type type; }; +enum { + HMAT_SLLBIS_ACCESS_LATENCY = 0, + HMAT_SLLBIS_READ_LATENCY, + HMAT_SLLBIS_WRITE_LATENCY, + HMAT_SLLBIS_ACCESS_BANDWIDTH, + HMAT_SLLBIS_READ_BANDWIDTH, + HMAT_SLLBIS_WRITE_BANDWIDTH, + HMAT_SLLBIS_DATA_TYPE_MAX +}; + struct dsmas_entry { struct list_head list; struct range dpa_range; u8 handle; + u64 qos[HMAT_SLLBIS_DATA_TYPE_MAX]; }; /* Sub-table 0: Device Scoped Memory Affinity Structure (DSMAS) */ @@ -120,6 +131,23 @@ struct cdat_dsmas { __le64 dpa_length; } __packed; +/* Sub-table 1: Device Scoped Latency and Bandwidth Information Structure (DSLBIS) */ +struct cdat_dslbis { + struct cdat_entry_header hdr; + u8 handle; + u8 flags; + u8 data_type; + u8 reserved; + __le64 entry_base_unit; + __le16 entry[3]; + __le16 reserved2; +} __packed; + +/* Flags for subtable above */ + +#define DSLBIS_MEM_MASK GENMASK(3, 0) +#define DSLBIS_MEM_MEMORY 0 + int devm_cxl_port_enumerate_dports(struct cxl_port *port); struct cxl_dev_state; int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm, @@ -136,5 +164,9 @@ cdat_table_parse(dsmas); cdat_table_parse(dslbis); cdat_table_parse(sslbis); -int cxl_dsmas_parse_entry(struct cdat_entry_header *header, void *arg); +#define cxl_parse_entry(x) \ +int cxl_##x##_parse_entry(struct cdat_entry_header *header, void *arg) + +cxl_parse_entry(dsmas); +cxl_parse_entry(dslbis); #endif /* __CXL_PCI_H__ */ diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c index c8136797d528..6f2b327f7128 100644 --- a/drivers/cxl/port.c +++ b/drivers/cxl/port.c @@ -152,8 +152,15 @@ static int cxl_port_probe(struct device *dev) rc = cdat_table_parse_dsmas(port->cdat.table, cxl_dsmas_parse_entry, (void *)&dsmas_list); - if (rc < 0) + if (rc > 0) { + rc = cdat_table_parse_dslbis(port->cdat.table, + cxl_dslbis_parse_entry, + (void *)&dsmas_list); + if (rc <= 0) + dev_warn(dev, "Failed to parse DSLBIS: %d\n", rc); + } else { dev_warn(dev, "Failed to parse DSMAS: %d\n", rc); + } dsmas_list_destroy(&dsmas_list); } From patchwork Mon Mar 27 21:44:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667485 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 26B42C77B6C for ; Mon, 27 Mar 2023 21:44:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230201AbjC0Vo5 (ORCPT ); Mon, 27 Mar 2023 17:44:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232318AbjC0Vos (ORCPT ); Mon, 27 Mar 2023 17:44:48 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 080D81FF2; Mon, 27 Mar 2023 14:44:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953488; x=1711489488; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Yww4IVyJADF6fVSvA6jcZGyhvDlSeOXKLJGlMtUZj2Y=; b=cHF38lUs5+Hsq894G26/MeIp0E+Ab+cu5y6Bt2eYI9hRME2uCKCXuTl1 uxRmFN7whQltrj/b9h90GR6xNzhAQbnHWKuAnBlGu9y2Y9jiDTIE4jyD5 vhNqpE2ivwviFcYTNzhwVibzDnuZbkSP45QacIK/5NrTGyGfYGrHAlixk 2Hf3R56LnVv/CHoQCYxBuaDAFCDP58emvK8TY1sfwKi117QEBpX7Q7ExF Gb1rXaecBNZpmROrJ+XlJ0L3e+WGPdx++w/uDVhDNABTMFbYK9OL9baoN ILBZvP5vpyhzMXuFE8N2k6MBCV7Lx2pkJrUvVLnNKmmJgEe0XJwQyVzx9 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="339120650" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="339120650" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="677116237" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="677116237" Received: from spal2-desk3.gar.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:46 -0700 Subject: [PATCH v2 07/21] cxl: Add callback to parse the SSLBIS subtable from CDAT From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:44:45 -0700 Message-ID: <167995348596.2857312.14405653084102194066.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Provide a callback to parse the Switched Scoped Latency and Bandwidth Information Structure (DSLBIS) in the CDAT structures. The SSLBIS contains the bandwidth and latency information that's tied to the CLX switch that the data table has been read from. The extracted values are indexed by the downstream port id. It is possible the downstream port id is 0xffff which is a wildcard value for any port id. Signed-off-by: Dave Jiang --- drivers/cxl/core/cdat.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/port.c | 5 +++ drivers/cxl/cxl.h | 1 + drivers/cxl/cxlpci.h | 24 +++++++++++++++ drivers/cxl/port.c | 6 ++++ 5 files changed, 112 insertions(+) diff --git a/drivers/cxl/core/cdat.c b/drivers/cxl/core/cdat.c index 0e88973e9f38..0e7a4f74fcf8 100644 --- a/drivers/cxl/core/cdat.c +++ b/drivers/cxl/core/cdat.c @@ -165,3 +165,79 @@ int cxl_dslbis_parse_entry(struct cdat_entry_header *header, void *arg) return 0; } EXPORT_SYMBOL_NS_GPL(cxl_dslbis_parse_entry, CXL); + +int cxl_sslbis_parse_entry(struct cdat_entry_header *header, void *arg) +{ + struct cdat_sslbis *sslbis = (struct cdat_sslbis *)header; + struct xarray *sslbis_xa = (struct xarray *)arg; + int remain, entries, i; + + remain = sslbis->hdr.length - sizeof(*sslbis); + if (!remain || remain % sizeof(struct sslbis_sslbe)) { + pr_warn("Malformed SSLBIS table length: (%u)\n", + sslbis->hdr.length); + return -EINVAL; + } + + /* Unrecognized data type, we can skip */ + if (sslbis->data_type >= HMAT_SLLBIS_DATA_TYPE_MAX) + return 0; + + entries = remain / sizeof(*sslbis); + + for (i = 0; i < entries; i++) { + struct sslbis_sslbe *sslbe = &sslbis->sslbe[i]; + u16 x = le16_to_cpu(sslbe->port_x_id); + u16 y = le16_to_cpu(sslbe->port_y_id); + struct sslbis_entry *sentry; + u16 dsp_id; + u64 val; + int rc; + + switch (x) { + case SSLBIS_US_PORT: + dsp_id = y; + break; + case SSLBIS_ANY_PORT: + switch (y) { + case SSLBIS_US_PORT: + dsp_id = x; + break; + case SSLBIS_ANY_PORT: + dsp_id = SSLBIS_ANY_PORT; + break; + default: + dsp_id = y; + break; + } + break; + default: + dsp_id = x; + break; + } + + sentry = xa_load(sslbis_xa, dsp_id); + if (xa_is_err(sentry)) + return xa_err(sentry); + if (!sentry) { + sentry = kzalloc(sizeof(*sentry), GFP_KERNEL); + if (!sentry) + return -ENOMEM; + } + + rc = check_mul_overflow(le64_to_cpu(sslbis->entry_base_unit), + le16_to_cpu(sslbe->value), &val); + if (unlikely(rc)) + pr_warn("SSLBIS value overflowed!\n"); + + sentry->qos[sslbis->data_type] = val; + rc = xa_insert(sslbis_xa, dsp_id, sentry, GFP_KERNEL); + if (rc < 0 && rc != -EBUSY) { + kfree(sentry); + return rc; + } + } + + return 0; +} +EXPORT_SYMBOL_NS_GPL(cxl_sslbis_parse_entry, CXL); diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index 5ec48dddb2f9..a61f9395a209 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -518,6 +518,7 @@ static void cxl_ep_remove(struct cxl_port *port, struct cxl_ep *ep) static void cxl_port_release(struct device *dev) { struct cxl_port *port = to_cxl_port(dev); + struct sslbis_entry *sentry; unsigned long index; struct cxl_ep *ep; @@ -526,6 +527,9 @@ static void cxl_port_release(struct device *dev) xa_destroy(&port->endpoints); xa_destroy(&port->dports); xa_destroy(&port->regions); + xa_for_each(&port->cdat.sslbis_xa, index, sentry) + kfree(sentry); + xa_destroy(&port->cdat.sslbis_xa); ida_free(&cxl_port_ida, port->id); kfree(port); } @@ -684,6 +688,7 @@ static struct cxl_port *cxl_port_alloc(struct device *uport, xa_init(&port->dports); xa_init(&port->endpoints); xa_init(&port->regions); + xa_init(&port->cdat.sslbis_xa); device_initialize(dev); lockdep_set_class_and_subclass(&dev->mutex, &cxl_port_key, port->depth); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 9d0e22fe72c0..50ac74f66cbd 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -581,6 +581,7 @@ struct cxl_port { struct cxl_cdat { void *table; size_t length; + struct xarray sslbis_xa; } cdat; bool cdat_available; }; diff --git a/drivers/cxl/cxlpci.h b/drivers/cxl/cxlpci.h index 1429de49e0c4..1c9e8b078369 100644 --- a/drivers/cxl/cxlpci.h +++ b/drivers/cxl/cxlpci.h @@ -121,6 +121,10 @@ struct dsmas_entry { u64 qos[HMAT_SLLBIS_DATA_TYPE_MAX]; }; +struct sslbis_entry { + u64 qos[HMAT_SLLBIS_DATA_TYPE_MAX]; +}; + /* Sub-table 0: Device Scoped Memory Affinity Structure (DSMAS) */ struct cdat_dsmas { struct cdat_entry_header hdr; @@ -148,6 +152,25 @@ struct cdat_dslbis { #define DSLBIS_MEM_MASK GENMASK(3, 0) #define DSLBIS_MEM_MEMORY 0 +struct sslbis_sslbe { + __le16 port_x_id; + __le16 port_y_id; + __le16 value; /* latency or bandwidth */ + __le16 reserved; +} __packed; + +/* Sub-table 5: Switch Scoped Latency and Bandwidth Information Structure (SSLBIS) */ +struct cdat_sslbis { + struct cdat_entry_header hdr; + u8 data_type; + u8 reserved[3]; + __le64 entry_base_unit; + struct sslbis_sslbe sslbe[]; +} __packed; + +#define SSLBIS_US_PORT 0x0100 +#define SSLBIS_ANY_PORT 0xffff + int devm_cxl_port_enumerate_dports(struct cxl_port *port); struct cxl_dev_state; int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm, @@ -169,4 +192,5 @@ int cxl_##x##_parse_entry(struct cdat_entry_header *header, void *arg) cxl_parse_entry(dsmas); cxl_parse_entry(dslbis); +cxl_parse_entry(sslbis); #endif /* __CXL_PCI_H__ */ diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c index 6f2b327f7128..7839e0244d0d 100644 --- a/drivers/cxl/port.c +++ b/drivers/cxl/port.c @@ -163,6 +163,12 @@ static int cxl_port_probe(struct device *dev) } dsmas_list_destroy(&dsmas_list); + } else { + rc = cdat_table_parse_sslbis(port->cdat.table, + cxl_sslbis_parse_entry, + (void *)&port->cdat.sslbis_xa); + if (rc <= 0) + dev_warn(dev, "Failed to parse SSLBIS: %d\n", rc); } } From patchwork Mon Mar 27 21:44:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667939 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 90D10C77B6E for ; Mon, 27 Mar 2023 21:44:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231244AbjC0Vo6 (ORCPT ); Mon, 27 Mar 2023 17:44:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229471AbjC0Vo4 (ORCPT ); Mon, 27 Mar 2023 17:44:56 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29A1C1FF2; Mon, 27 Mar 2023 14:44:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953495; x=1711489495; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=H7zfqOcVJ02CJZ2p/NGllYcgfY1NukX2REpKJgA7P1A=; b=nAL2/jUAb52rk5Pn4e6927Gae8ARLQgUT2aqyufPkVwDli0qxEQGRLHD 3t35yEg/4klJ20f1tBaZTuv6650da6yWYAzESQuWeK4vPL55XFgH/X9O7 nwZlwwwtAAkjHQDvAZppZ0PiaHYhOIQRHjitN5oNlRZEPX+18WhG6jjyN xoptCVqzgZWu3zcFzM7isRsZLLM3/bDJQSDOaxcXV8KFeHW1MI5lhdD0x f5wnV7Uge+/DRFBlwVafCv94K2X33rctcl5mMdVY/CQ9jrw/mXHqsdiAw oPOOgjpnql/11jyexQk/2twBA4zfAwa259Q5qa/fMfzuFrkVvBReMXRWR w==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="339120675" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="339120675" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="677116252" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="677116252" Received: from spal2-desk3.gar.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:53 -0700 Subject: [PATCH v2 08/21] cxl: Add support for _DSM Function for retrieving QTG ID From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:44:52 -0700 Message-ID: <167995349254.2857312.13398539042888653099.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org CXL spec v3.0 9.17.3 CXL Root Device Specific Methods (_DSM) Add support to retrieve QTG ID via ACPI _DSM call. The _DSM call requires an input of an ACPI package with 4 dwords (read latency, write latency, read bandwidth, write bandwidth). The call returns a package with 1 WORD that provides the max supported QTG ID and a package that may contain 0 or more WORDs as the recommended QTG IDs in the recommended order. Signed-off-by: Dave Jiang --- v2: - Reorder var declaration and use C99 style. (Jonathan) - Allow >2 ACPI objects in package for future expansion. (Jonathan) - Check QTG IDs against MAX QTG ID provided by output package. (Jonathan) --- drivers/cxl/core/Makefile | 1 drivers/cxl/core/acpi.c | 116 +++++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 16 ++++++ 3 files changed, 133 insertions(+) create mode 100644 drivers/cxl/core/acpi.c diff --git a/drivers/cxl/core/Makefile b/drivers/cxl/core/Makefile index 867a8014b462..30d61c8cae22 100644 --- a/drivers/cxl/core/Makefile +++ b/drivers/cxl/core/Makefile @@ -13,5 +13,6 @@ cxl_core-y += mbox.o cxl_core-y += pci.o cxl_core-y += hdm.o cxl_core-y += cdat.o +cxl_core-y += acpi.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o diff --git a/drivers/cxl/core/acpi.c b/drivers/cxl/core/acpi.c new file mode 100644 index 000000000000..6eda5cad8d59 --- /dev/null +++ b/drivers/cxl/core/acpi.c @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2022 Intel Corporation. All rights reserved. */ +#include +#include +#include +#include +#include +#include +#include "cxlpci.h" +#include "cxl.h" + +const guid_t acpi_cxl_qtg_id_guid = + GUID_INIT(0xF365F9A6, 0xA7DE, 0x4071, + 0xA6, 0x6A, 0xB4, 0x0C, 0x0B, 0x4F, 0x8E, 0x52); + +/** + * cxl_acpi_evaluate_qtg_dsm - Retrieve QTG ids via ACPI _DSM + * @handle: ACPI handle + * @input: bandwidth and latency data + * + * Issue QTG _DSM with accompanied bandwidth and latency data in order to get + * the QTG IDs that falls within the performance data. + */ +struct qtg_dsm_output *cxl_acpi_evaluate_qtg_dsm(acpi_handle handle, + struct qtg_dsm_input *input) +{ + union acpi_object *out_obj, *out_buf, *pkg; + union acpi_object in_buf = { + .buffer = { + .type = ACPI_TYPE_BUFFER, + .pointer = (u8 *)input, + .length = sizeof(u32) * 4, + }, + }; + union acpi_object in_obj = { + .package = { + .type = ACPI_TYPE_PACKAGE, + .count = 1, + .elements = &in_buf + }, + }; + struct qtg_dsm_output *output = NULL; + int len, rc, i; + u16 *max_qtg; + + out_obj = acpi_evaluate_dsm(handle, &acpi_cxl_qtg_id_guid, 1, 1, &in_obj); + if (!out_obj) + return ERR_PTR(-ENXIO); + + if (out_obj->type != ACPI_TYPE_PACKAGE) { + rc = -ENXIO; + goto err; + } + + /* Check Max QTG ID */ + pkg = &out_obj->package.elements[0]; + if (pkg->type != ACPI_TYPE_BUFFER) { + rc = -ENXIO; + goto err; + } + + if (pkg->buffer.length != sizeof(u16)) { + rc = -ENXIO; + goto err; + } + max_qtg = (u16 *)pkg->buffer.pointer; + + /* Retrieve QTG IDs package */ + pkg = &out_obj->package.elements[1]; + if (pkg->type != ACPI_TYPE_PACKAGE) { + rc = -ENXIO; + goto err; + } + + out_buf = &pkg->package.elements[0]; + if (out_buf->type != ACPI_TYPE_BUFFER) { + rc = -ENXIO; + goto err; + } + + len = out_buf->buffer.length; + + /* It's legal to have 0 QTG entries */ + if (len == 0) + goto out; + + /* Malformed package, not multiple of WORD size */ + if (len % sizeof(u16)) { + rc = -ENXIO; + goto out; + } + + output = kmalloc(len + sizeof(*output), GFP_KERNEL); + if (!output) { + rc = -ENOMEM; + goto err; + } + + output->nr = len / sizeof(u16); + memcpy(output->qtg_ids, out_buf->buffer.pointer, len); + + for (i = 0; i < output->nr; i++) { + if (output->qtg_ids[i] > *max_qtg) + pr_warn("QTG ID %u greater than MAX %u\n", + output->qtg_ids[i], *max_qtg); + } + +out: + ACPI_FREE(out_obj); + return output; + +err: + ACPI_FREE(out_obj); + return ERR_PTR(rc); +} +EXPORT_SYMBOL_NS_GPL(cxl_acpi_evaluate_qtg_dsm, CXL); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 50ac74f66cbd..04b8a032bd14 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -791,6 +792,21 @@ static inline struct cxl_dax_region *to_cxl_dax_region(struct device *dev) } #endif +struct qtg_dsm_input { + u32 rd_lat; + u32 wr_lat; + u32 rd_bw; + u32 wr_bw; +}; + +struct qtg_dsm_output { + int nr; + u16 qtg_ids[]; +}; + +struct qtg_dsm_output *cxl_acpi_evaluate_qtg_dsm(acpi_handle handle, + struct qtg_dsm_input *input); + /* * Unit test builds overrides this to __weak, find the 'strong' version * of these symbols in tools/testing/cxl/. From patchwork Mon Mar 27 21:44:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667484 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 C1CABC77B60 for ; Mon, 27 Mar 2023 21:45:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229547AbjC0Vp2 (ORCPT ); Mon, 27 Mar 2023 17:45:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229464AbjC0VpA (ORCPT ); Mon, 27 Mar 2023 17:45:00 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 415FF26AA; Mon, 27 Mar 2023 14:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953500; x=1711489500; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8t2nGx+s7JFBFfgM6MI1h6lYgxIWg/nxB+bI0TPO3rg=; b=dd9j2oCV42Vd50XRQbLlPSqyOT00MErH2ujqV3nCC9/Ng6uepjWB3+uF tAqvABXgh51BqDrtTjrP0Gcy001ptocu8Ldg+ettrLxipPCJF3BPhH3/W FadYBJpaa1iwq0biuB5zsAlb9LbhAqDRy4hNpKjc5PjguMZkEIIBJFP9i l0VQWx3vIPNzlyUZiE/0YIh/JRJ/FppxcP+/3vU9m+kMKieAT4i01AtO0 gf3eS8Vp8Oz46PzmA5INhqoDL8HGnA+5YtYSF1bc028YRl1BSE7qQi9XA b4CpIpLAe9qWLPAyjqLpCht+Fq6xpS7E4Yybz3JJuEn91d0aK/oE+c/tJ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="337899921" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="337899921" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="686114689" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="686114689" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:44:59 -0700 Subject: [PATCH v2 09/21] cxl: Add helper function to retrieve ACPI handle of CXL root device From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:44:59 -0700 Message-ID: <167995349900.2857312.16120678350775837497.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Provide a helper to find the ACPI0017 device in order to issue the _DSM. The helper will take the 'struct device' from a cxl_port and iterate until the root device is reached. The ACPI handle will be returned from the root device. Signed-off-by: Dave Jiang --- v2: - Fix commenting style. (Jonathan) - Fix var declaration aligning. (Jonathan) --- drivers/cxl/core/acpi.c | 34 ++++++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 1 + 2 files changed, 35 insertions(+) diff --git a/drivers/cxl/core/acpi.c b/drivers/cxl/core/acpi.c index 6eda5cad8d59..191644d0ca6d 100644 --- a/drivers/cxl/core/acpi.c +++ b/drivers/cxl/core/acpi.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "cxlpci.h" #include "cxl.h" @@ -13,6 +14,39 @@ const guid_t acpi_cxl_qtg_id_guid = GUID_INIT(0xF365F9A6, 0xA7DE, 0x4071, 0xA6, 0x6A, 0xB4, 0x0C, 0x0B, 0x4F, 0x8E, 0x52); +/** + * cxl_acpi_get_rootdev_handle - get the ACPI handle of the CXL root device + * @dev: 'struct device' to start searching from. Should be from cxl_port->dev. + * + * Return: acpi_handle on success, errptr of errno on error. + * + * Looks for the ACPI0017 device and return the ACPI handle + **/ +acpi_handle cxl_acpi_get_rootdev_handle(struct device *dev) +{ + struct device *itr = dev; + struct device *root_dev; + acpi_handle handle; + + if (!dev) + return ERR_PTR(-EINVAL); + + while (itr->parent) { + root_dev = itr; + itr = itr->parent; + } + + if (!dev_is_platform(root_dev)) + return ERR_PTR(-ENODEV); + + handle = ACPI_HANDLE(root_dev); + if (!handle) + return ERR_PTR(-ENODEV); + + return handle; +} +EXPORT_SYMBOL_NS_GPL(cxl_acpi_get_rootdev_handle, CXL); + /** * cxl_acpi_evaluate_qtg_dsm - Retrieve QTG ids via ACPI _DSM * @handle: ACPI handle diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 04b8a032bd14..dc6da641ced0 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -806,6 +806,7 @@ struct qtg_dsm_output { struct qtg_dsm_output *cxl_acpi_evaluate_qtg_dsm(acpi_handle handle, struct qtg_dsm_input *input); +acpi_handle cxl_acpi_get_rootdev_handle(struct device *dev); /* * Unit test builds overrides this to __weak, find the 'strong' version From patchwork Mon Mar 27 21:45:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667938 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 23B59C77B6C for ; Mon, 27 Mar 2023 21:45:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231493AbjC0Vp3 (ORCPT ); Mon, 27 Mar 2023 17:45:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231717AbjC0VpK (ORCPT ); Mon, 27 Mar 2023 17:45:10 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 221EF2D4E; Mon, 27 Mar 2023 14:45:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953506; x=1711489506; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mp1icMQq4gU4CT+5IYE6g3GosicnEOy9n3GobjODQgY=; b=N+VsijBfIG97kXEkyOiC0nVT7DxNKFfcHfedF05tj8n43qn72Ijld33u Lwvk2/ora8EKX/IxGf5V4p1Xcw6tYt8s6EG2vAOuMJrnzk7e4h0AwKI12 iN97hKYacAiI2iyRjjOsxA+mtnGytBEP5xsbE9203FLhmMVULFsG20QZ4 b/rCEJXmCvXCeBIgzsJ7f1VhaDAi3R2x7hoQonq0iBCS85gDih2amKqhF kiiQCdnFqVilqQW0HnzRebmgMoEwraGF05pMQ9PeCkS/qPAzds9foDuaG MDc9pBqdZG79UhAe07sD1vSUPyHmTpLhesrBikBcjfTECyJbzKYwOHL3p A==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="337899951" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="337899951" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="686114734" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="686114734" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:05 -0700 Subject: [PATCH v2 10/21] cxl: Add helpers to calculate pci latency for the CXL device From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:45:05 -0700 Message-ID: <167995350504.2857312.2081220855575036506.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The latency is calculated by dividing the flit size over the bandwidth. Add support to retrieve the flit size for the CXL device and calculate the latency of the downstream link. Signed-off-by: Dave Jiang --- v2: - Fix commit log issues. (Jonathan) - Fix var declaration issues. (Jonathan) --- drivers/cxl/core/pci.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlpci.h | 15 +++++++++++ drivers/cxl/pci.c | 13 --------- 3 files changed, 83 insertions(+), 13 deletions(-) diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c index 4241c7b8d5c2..2f58cc54e108 100644 --- a/drivers/cxl/core/pci.c +++ b/drivers/cxl/core/pci.c @@ -712,3 +712,71 @@ pci_ers_result_t cxl_error_detected(struct pci_dev *pdev, return PCI_ERS_RESULT_NEED_RESET; } EXPORT_SYMBOL_NS_GPL(cxl_error_detected, CXL); + +static int pcie_speed_to_mbps(enum pci_bus_speed speed) +{ + switch (speed) { + case PCIE_SPEED_2_5GT: + return 2500; + case PCIE_SPEED_5_0GT: + return 5000; + case PCIE_SPEED_8_0GT: + return 8000; + case PCIE_SPEED_16_0GT: + return 16000; + case PCIE_SPEED_32_0GT: + return 32000; + case PCIE_SPEED_64_0GT: + return 64000; + default: + break; + } + + return -EINVAL; +} + +static int cxl_pci_mbits_to_mbytes(struct pci_dev *pdev) +{ + int mbits; + + mbits = pcie_speed_to_mbps(pdev->bus->cur_bus_speed); + if (mbits < 0) + return mbits; + + return mbits >> 3; +} + +static int cxl_flit_size(struct pci_dev *pdev) +{ + if (cxl_pci_flit_256(pdev)) + return 256; + + return 68; +} + +/** + * cxl_pci_get_latency - calculate the link latency for the PCIe link + * @pdev - PCI device + * + * return: calculated latency or -errno + * + * CXL Memory Device SW Guide v1.0 2.11.4 Link latency calculation + * Link latency = LinkPropagationLatency + FlitLatency + RetimerLatency + * LinkProgationLatency is negligible, so 0 will be used + * RetimerLatency is assumed to be negligible and 0 will be used + * FlitLatency = FlitSize / LinkBandwidth + * FlitSize is defined by spec. CXL rev3.0 4.2.1. + * 68B flit is used up to 32GT/s. >32GT/s, 256B flit size is used. + * The FlitLatency is converted to picoseconds. + */ +long cxl_pci_get_latency(struct pci_dev *pdev) +{ + long bw; + + bw = cxl_pci_mbits_to_mbytes(pdev); + if (bw < 0) + return bw; + + return cxl_flit_size(pdev) * 1000000L / bw; +} +EXPORT_SYMBOL_NS_GPL(cxl_pci_get_latency, CXL); diff --git a/drivers/cxl/cxlpci.h b/drivers/cxl/cxlpci.h index 1c9e8b078369..815bf843018e 100644 --- a/drivers/cxl/cxlpci.h +++ b/drivers/cxl/cxlpci.h @@ -171,6 +171,19 @@ struct cdat_sslbis { #define SSLBIS_US_PORT 0x0100 #define SSLBIS_ANY_PORT 0xffff +/* + * CXL v3.0 6.2.3 Table 6-4 + * The table indicates that if PCIe Flit Mode is set, then CXL is in 256B flits + * mode, otherwise it's 68B flits mode. + */ +static inline bool cxl_pci_flit_256(struct pci_dev *pdev) +{ + u16 lnksta2; + + pcie_capability_read_word(pdev, PCI_EXP_LNKSTA2, &lnksta2); + return lnksta2 & PCI_EXP_LNKSTA2_FLIT; +} + int devm_cxl_port_enumerate_dports(struct cxl_port *port); struct cxl_dev_state; int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm, @@ -193,4 +206,6 @@ int cxl_##x##_parse_entry(struct cdat_entry_header *header, void *arg) cxl_parse_entry(dsmas); cxl_parse_entry(dslbis); cxl_parse_entry(sslbis); + +long cxl_pci_get_latency(struct pci_dev *pdev); #endif /* __CXL_PCI_H__ */ diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index ea38bd49b0cf..ed39d133b70d 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -365,19 +365,6 @@ static bool is_cxl_restricted(struct pci_dev *pdev) return pci_pcie_type(pdev) == PCI_EXP_TYPE_RC_END; } -/* - * CXL v3.0 6.2.3 Table 6-4 - * The table indicates that if PCIe Flit Mode is set, then CXL is in 256B flits - * mode, otherwise it's 68B flits mode. - */ -static bool cxl_pci_flit_256(struct pci_dev *pdev) -{ - u16 lnksta2; - - pcie_capability_read_word(pdev, PCI_EXP_LNKSTA2, &lnksta2); - return lnksta2 & PCI_EXP_LNKSTA2_FLIT; -} - static int cxl_pci_ras_unmask(struct pci_dev *pdev) { struct pci_host_bridge *host_bridge = pci_find_host_bridge(pdev->bus); From patchwork Mon Mar 27 21:45:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667483 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 AC367C77B6F for ; Mon, 27 Mar 2023 21:45:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231359AbjC0Vp3 (ORCPT ); Mon, 27 Mar 2023 17:45:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232075AbjC0VpM (ORCPT ); Mon, 27 Mar 2023 17:45:12 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8F6C2696; Mon, 27 Mar 2023 14:45:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953511; x=1711489511; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QgESBbS9QqBtr+VC0tuT/jXrT/nLMzpw2FMu9iOcnoI=; b=aRPHY/kJ6OX40VKNr9emd/qe3PIgnVTgdsNF2iZ2Z74p9nRA5pK3dXoB rRmk6m8ZQOIGW+5Ao9q9Ta48GPRWW3NenO16FxIR8MtPbD//hLNZPaq7F O5xRJ4w61LocQgomv4f5V6dMtx7wX8hBXVivV3McQzwugOMOd7tJGWo+A Z7vQI3pgOB+WWaqR0Fk2lr1sUayNNBtE8tNmduIXqrdwJNfynjByP8u8a gEjU+u7ceYXwv6z0wiefJXUY6GATc7LcGyGqzykCCw6/Rt7D9YsQgK83N w7cG1opMWekXyQNQl5BgIR+GrKuhBr+GChqnIAMp2dgWnT8OwAKJdHIwG A==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="337899975" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="337899975" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="686114752" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="686114752" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:11 -0700 Subject: [PATCH v2 11/21] cxl: Add helper function that calculates QoS values for switches From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:45:10 -0700 Message-ID: <167995351086.2857312.5620998796872386187.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The CDAT information from the switch, Switch Scoped Latency and Bandwidth Information Strucutre (SSLBIS), is parsed and stored in an xarray under the cxl_port. The QoS data are indexed by the downstream port id. Walk the CXL ports from endpoint to root and retrieve the relevant QoS information (bandwidth and latency) that are from the switch CDAT. If read or write QoS values are not available, then use the access QoS value. Signed-off-by: Dave Jiang --- drivers/cxl/core/port.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 2 + 2 files changed, 91 insertions(+) diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index a61f9395a209..6e2f8e40757e 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -1945,6 +1945,95 @@ bool schedule_cxl_memdev_detach(struct cxl_memdev *cxlmd) } EXPORT_SYMBOL_NS_GPL(schedule_cxl_memdev_detach, CXL); +/** + * cxl_port_get_switch_qos - retrieve QoS data for CXL switches + * @port: endpoint cxl_port + * @rd_bw: writeback value for min read bandwidth + * @rd_lat: writeback value for total read latency + * @wr_bw: writeback value for min write bandwidth + * @wr_lat: writeback value for total write latency + * + * Return: Errno on failure, 0 on success. -ENOENT if no switch device + */ +int cxl_port_get_switch_qos(struct cxl_port *port, u64 *rd_bw, u64 *rd_lat, + u64 *wr_bw, u64 *wr_lat) +{ + u64 min_rd_bw = ULONG_MAX; + u64 min_wr_bw = ULONG_MAX; + struct cxl_dport *dport; + struct cxl_port *nport; + u64 total_rd_lat = 0; + u64 total_wr_lat = 0; + struct device *next; + int switches = 0; + int rc = 0; + + if (!is_cxl_endpoint(port)) + return -EINVAL; + + /* Skip the endpoint */ + next = port->dev.parent; + nport = to_cxl_port(next); + dport = port->parent_dport; + + do { + struct sslbis_entry *sentry; + u64 lat, bw; + + if (!nport->cdat.table) + break; + + if (!dev_is_pci(dport->dport)) + break; + + sentry = xa_load(&nport->cdat.sslbis_xa, dport->port_id); + if (xa_is_err(sentry)) + return xa_err(sentry); + + if (!sentry) { + sentry = xa_load(&nport->cdat.sslbis_xa, SSLBIS_ANY_PORT); + if (xa_is_err(sentry)) + return xa_err(sentry); + if (!sentry) + return -ENXIO; + } + + bw = sentry->qos[HMAT_SLLBIS_WRITE_BANDWIDTH]; + if (!bw) + bw = sentry->qos[HMAT_SLLBIS_ACCESS_BANDWIDTH]; + lat = sentry->qos[HMAT_SLLBIS_WRITE_LATENCY]; + if (!lat) + lat = sentry->qos[HMAT_SLLBIS_ACCESS_LATENCY]; + min_wr_bw = min_t(u64, min_wr_bw, bw); + total_wr_lat += lat; + + bw = sentry->qos[HMAT_SLLBIS_READ_BANDWIDTH]; + if (!bw) + bw = sentry->qos[HMAT_SLLBIS_ACCESS_BANDWIDTH]; + lat = sentry->qos[HMAT_SLLBIS_READ_LATENCY]; + if (!lat) + lat = sentry->qos[HMAT_SLLBIS_ACCESS_LATENCY]; + min_rd_bw = min_t(u64, min_rd_bw, bw); + total_rd_lat += lat; + + dport = nport->parent_dport; + next = next->parent; + nport = to_cxl_port(next); + switches++; + } while (next); + + *wr_bw = min_wr_bw; + *wr_lat = total_wr_lat; + *rd_bw = min_rd_bw; + *rd_lat = total_rd_lat; + + if (!switches) + return -ENOENT; + + return rc; +} +EXPORT_SYMBOL_NS_GPL(cxl_port_get_switch_qos, CXL); + /* for user tooling to ensure port disable work has completed */ static ssize_t flush_store(struct bus_type *bus, const char *buf, size_t count) { diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index dc6da641ced0..21e7c1f78f1f 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -807,6 +807,8 @@ struct qtg_dsm_output { struct qtg_dsm_output *cxl_acpi_evaluate_qtg_dsm(acpi_handle handle, struct qtg_dsm_input *input); acpi_handle cxl_acpi_get_rootdev_handle(struct device *dev); +int cxl_port_get_switch_qos(struct cxl_port *port, u64 *rd_bw, u64 *rd_lat, + u64 *wr_bw, u64 *wr_lat); /* * Unit test builds overrides this to __weak, find the 'strong' version From patchwork Mon Mar 27 21:45:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667937 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 4D665C77B70 for ; Mon, 27 Mar 2023 21:45:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231820AbjC0Vpa (ORCPT ); Mon, 27 Mar 2023 17:45:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230206AbjC0VpS (ORCPT ); Mon, 27 Mar 2023 17:45:18 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A08971FF2; Mon, 27 Mar 2023 14:45:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953517; x=1711489517; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6CBLF1DD1zQ6yDOItBTKoL6bG2Pv03DELrI8RTxx4VY=; b=Irnj+oqy1cm7I0IX4L7lGhgwPpwIEHoN3mHMgQEaN954sz0yP2AvVkRg xDN0MMvMmgrG8cZNuPNo5cR09v81xRqjJAdX1/b1P7d7RxeQFxCeBY5GT MgOwER7C/FlnR+zRGMhw0F4jSKucO6luDOA0eUqZc2xM3gpFFU0aEompZ Ejy2UQTuWMAzraYSnmwSZ5iPUklbt3jgPVAe/MnOi/hPjB0NGYCgOTy7h L+WUrDGlo1erdJx1aAPw8pC5r37SPcCIgS3Y3/aY+ATpWrIFPa8Uw2pif mUBqfVJ5U7aLuu/j7fZOr7fT1UOKptuktLX9F6pXDworneUf5o6p+eha7 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="337899994" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="337899994" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="686114760" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="686114760" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:17 -0700 Subject: [PATCH v2 12/21] cxl: Add helper function that calculate QoS values for PCI path From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:45:16 -0700 Message-ID: <167995351670.2857312.8039697517683275636.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Calculate the link bandwidth and latency for the PCIe path from the device to the CXL Host Bridge. This does not include the CDAT data from the device or the switch(es) in the path. Signed-off-by: Dave Jiang --- drivers/cxl/core/port.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 2 ++ 2 files changed, 63 insertions(+) diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index 6e2f8e40757e..f78559edd239 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -2034,6 +2034,67 @@ int cxl_port_get_switch_qos(struct cxl_port *port, u64 *rd_bw, u64 *rd_lat, } EXPORT_SYMBOL_NS_GPL(cxl_port_get_switch_qos, CXL); +/** + * cxl_port_get_downstream_qos - retrieve QoS data for PCIE downstream path + * @port: endpoint cxl_port + * @bandwidth: writeback value for min bandwidth + * @latency: writeback value for total latency + * + * Return: Errno on failure, 0 on success. + */ +int cxl_port_get_downstream_qos(struct cxl_port *port, u64 *bandwidth, + u64 *latency) +{ + u64 min_bw = ULONG_MAX; + struct pci_dev *pdev; + struct cxl_port *p; + struct device *dev; + u64 total_lat = 0; + int devices = 0; + u64 lat; + + /* Grab the device that is the PCI device for CXL memdev */ + dev = port->uport->parent; + /* Skip if it's not PCI, most likely a cxl_test device */ + if (!dev_is_pci(dev)) + return 0; + + pdev = to_pci_dev(dev); + min_bw = pcie_bandwidth_available(pdev, NULL, NULL, NULL); + if (min_bw == 0) + return -ENXIO; + + /* convert to MB/s from Mb/s */ + min_bw >>= 3; + + p = port; + do { + struct cxl_dport *dport; + + lat = cxl_pci_get_latency(pdev); + if (lat < 0) + return lat; + + total_lat += lat; + devices++; + + dport = p->parent_dport; + if (!dport) + break; + + p = dport->port; + dev = p->uport; + if (!dev_is_pci(dev)) + break; + pdev = to_pci_dev(dev); + } while (1); + + *bandwidth = min_bw; + *latency = total_lat; + return 0; +} +EXPORT_SYMBOL_NS_GPL(cxl_port_get_downstream_qos, CXL); + /* for user tooling to ensure port disable work has completed */ static ssize_t flush_store(struct bus_type *bus, const char *buf, size_t count) { diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 21e7c1f78f1f..67e844645ef6 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -809,6 +809,8 @@ struct qtg_dsm_output *cxl_acpi_evaluate_qtg_dsm(acpi_handle handle, acpi_handle cxl_acpi_get_rootdev_handle(struct device *dev); int cxl_port_get_switch_qos(struct cxl_port *port, u64 *rd_bw, u64 *rd_lat, u64 *wr_bw, u64 *wr_lat); +int cxl_port_get_downstream_qos(struct cxl_port *port, u64 *bandwidth, + u64 *latency); /* * Unit test builds overrides this to __weak, find the 'strong' version From patchwork Mon Mar 27 21:45:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667482 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 94AF3C77B74 for ; Mon, 27 Mar 2023 21:45:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230386AbjC0Vpb (ORCPT ); Mon, 27 Mar 2023 17:45:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229492AbjC0VpZ (ORCPT ); Mon, 27 Mar 2023 17:45:25 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46BC32696; Mon, 27 Mar 2023 14:45:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953524; x=1711489524; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AVA14HQNfCIA/61q7aYrlg12qAV568Fd3pbtDzEXaKQ=; b=NslgtMU9tc6s7h33YOsvO+9nF7HwJW9vhc9C36/6irjyR0t5T/yO7CQF PtE7wQ2DkqYHcKhz+3JBp0nGYI9rhZ7uSCpBDVchQ1Xa/n+GEKDzd7evN Dt6j0UWUcJ5ku15PwC5lHh+majWTiiGnDETRH9bHWVUi2faMv6q6bRj3C QPrIyIsZpAyBwLb8SGUTWbk7fhttZpTkuYUfnasozet0RiIKbfagz6k89 lVzsSgJRpBL4eA5wQPx5mvvUQvs5gkxGhz8U8W4yBlhXMc2aXU+omFwUq 7hdrPPaaqKJFVZHzYR+bxvcGCNKZsZ3pUc0GaC6Jyi6aEw0S5gyle2pue A==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="320799066" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="320799066" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="660958485" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="660958485" Received: from spal2-desk3.gar.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:23 -0700 Subject: [PATCH v2 13/21] ACPI: NUMA: Add genport target allocation to the HMAT parsing From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:45:22 -0700 Message-ID: <167995352251.2857312.3324792978023135511.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add SRAT parsing for the HMAT init in order to collect the device handle from the Generic Port Affinity Structure. The devie handle will serve as the key to search for target data. Signed-off-by: Dave Jiang --- drivers/acpi/numa/hmat.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ include/acpi/actbl3.h | 2 ++ 2 files changed, 53 insertions(+) diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c index bba268ecd802..8879c4576cf5 100644 --- a/drivers/acpi/numa/hmat.c +++ b/drivers/acpi/numa/hmat.c @@ -65,6 +65,7 @@ struct memory_target { struct node_hmem_attrs hmem_attrs[2]; struct list_head caches; struct node_cache_attrs cache_attrs; + u8 device_handle[ACPI_SRAT_DEVICE_HANDLE_SIZE]; bool registered; }; @@ -151,6 +152,33 @@ static __init void alloc_memory_target(unsigned int mem_pxm, start, start + len, mem_pxm); } +static __init void alloc_genport_target(unsigned int mem_pxm, u8 *handle) +{ + struct memory_target *target; + + target = find_mem_target(mem_pxm); + if (!target) { + target = kzalloc(sizeof(*target), GFP_KERNEL); + if (!target) + return; + target->memory_pxm = mem_pxm; + target->processor_pxm = PXM_INVAL; + target->memregions = (struct resource) { + .name = "ACPI genport", + .start = 0, + .end = -1, + .flags = IORESOURCE_MEM, + }; + memcpy(target->device_handle, handle, + ACPI_SRAT_DEVICE_HANDLE_SIZE); + list_add_tail(&target->node, &targets); + INIT_LIST_HEAD(&target->caches); + } else { + memcpy(target->device_handle, handle, + ACPI_SRAT_DEVICE_HANDLE_SIZE); + } +} + static __init const char *hmat_data_type(u8 type) { switch (type) { @@ -490,6 +518,22 @@ static __init int srat_parse_mem_affinity(union acpi_subtable_headers *header, return 0; } +static __init int srat_parse_genport_affinity(union acpi_subtable_headers *header, + const unsigned long end) +{ + struct acpi_srat_generic_affinity *ga = (void *)header; + + if (!ga) + return -EINVAL; + + if (!(ga->flags & ACPI_SRAT_GENERIC_AFFINITY_ENABLED)) + return 0; + + alloc_genport_target(ga->proximity_domain, (u8 *)ga->device_handle); + + return 0; +} + static u32 hmat_initiator_perf(struct memory_target *target, struct memory_initiator *initiator, struct acpi_hmat_locality *hmat_loc) @@ -835,6 +879,13 @@ static __init int hmat_init(void) ACPI_SRAT_TYPE_MEMORY_AFFINITY, srat_parse_mem_affinity, 0) < 0) goto out_put; + + if (acpi_table_parse_entries(ACPI_SIG_SRAT, + sizeof(struct acpi_table_srat), + ACPI_SRAT_TYPE_GENERIC_PORT_AFFINITY, + srat_parse_genport_affinity, 0) < 0) + goto out_put; + acpi_put_table(tbl); status = acpi_get_table(ACPI_SIG_HMAT, 0, &tbl); diff --git a/include/acpi/actbl3.h b/include/acpi/actbl3.h index 832c6464f063..0daf5a94f08a 100644 --- a/include/acpi/actbl3.h +++ b/include/acpi/actbl3.h @@ -289,6 +289,8 @@ struct acpi_srat_generic_affinity { u32 reserved1; }; +#define ACPI_SRAT_DEVICE_HANDLE_SIZE 16 + /* Flags for struct acpi_srat_generic_affinity */ #define ACPI_SRAT_GENERIC_AFFINITY_ENABLED (1) /* 00: Use affinity structure */ From patchwork Mon Mar 27 21:45:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667936 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 E532BC761A6 for ; Mon, 27 Mar 2023 21:46:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232531AbjC0VqA (ORCPT ); Mon, 27 Mar 2023 17:46:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232075AbjC0Vpb (ORCPT ); Mon, 27 Mar 2023 17:45:31 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2E2F2703; Mon, 27 Mar 2023 14:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953530; x=1711489530; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zh8urJq+jR9Vil1i9aljmOMFom/6ygKszDzVGbSr91A=; b=MzdzO/u6mOZBVwbDEAkTaPF9DpC384zW7TzhfzHp+0IOUYOFDdWYgk4g /gga98epimt8kzWP6DQJ9bEJORyttr88MyiWivku7FZM+LAM4zhcEIcnT i9vORRyx//2CWEQTepaIiEXoW7awttJAdmzutHMcAvE+69akaKdrzAIGG MYu1qk0ww3wR12y/eX3ZDV325Tl5H54gnH/i+gba87J8gg9fdtW3OcBN6 ZX+xHpWzToVzvtdCVaPxj8dyE/pmj86WOe0FD32bPJIWG+f5QQC7jIus2 IisRybRF896wH6GtpOieBlKG+mxfwbv2CJf6SXH5x5RhwIHvvE7Eie57Z A==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="320799102" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="320799102" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="660958509" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="660958509" Received: from spal2-desk3.gar.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:29 -0700 Subject: [PATCH v2 14/21] ACPI: NUMA: Add helper function to retrieve the performance attributes From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:45:28 -0700 Message-ID: <167995352876.2857312.5148434994393894318.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add helper to retrieve the performance attributes based on the device handle. The helper function is exported so the CXL driver can use that to acquire the performance data between the CPU and the CXL host bridge. Signed-off-by: Dave Jiang --- drivers/acpi/numa/hmat.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/acpi.h | 6 ++++++ 2 files changed, 50 insertions(+) diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c index 8879c4576cf5..9952a9bafe70 100644 --- a/drivers/acpi/numa/hmat.c +++ b/drivers/acpi/numa/hmat.c @@ -100,6 +100,50 @@ static struct memory_target *find_mem_target(unsigned int mem_pxm) return NULL; } +static struct memory_target *acpi_find_genport_target(u8 *device_handle) +{ + struct memory_target *target; + + list_for_each_entry(target, &targets, node) { + if (!strncmp(target->device_handle, device_handle, + ACPI_SRAT_DEVICE_HANDLE_SIZE)) + return target; + } + + return NULL; +} + +int acpi_get_genport_attrs(u8 *device_handle, u64 *val, int type) +{ + struct memory_target *target; + + target = acpi_find_genport_target(device_handle); + if (!target) + return -ENOENT; + + switch (type) { + case ACPI_HMAT_ACCESS_LATENCY: + case ACPI_HMAT_READ_LATENCY: + *val = target->hmem_attrs[0].read_latency; + break; + case ACPI_HMAT_WRITE_LATENCY: + *val = target->hmem_attrs[0].write_latency; + break; + case ACPI_HMAT_ACCESS_BANDWIDTH: + case ACPI_HMAT_READ_BANDWIDTH: + *val = target->hmem_attrs[0].read_bandwidth; + break; + case ACPI_HMAT_WRITE_BANDWIDTH: + *val = target->hmem_attrs[0].write_bandwidth; + break; + default: + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL_GPL(acpi_get_genport_attrs); + static __init void alloc_memory_initiator(unsigned int cpu_pxm) { struct memory_initiator *initiator; diff --git a/include/linux/acpi.h b/include/linux/acpi.h index efff750f326d..1a727053fabb 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -451,6 +451,7 @@ extern bool acpi_osi_is_win8(void); #ifdef CONFIG_ACPI_NUMA int acpi_map_pxm_to_node(int pxm); int acpi_get_node(acpi_handle handle); +int acpi_get_genport_attrs(u8 *device_handle, u64 *val, int type); /** * pxm_to_online_node - Map proximity ID to online node @@ -485,6 +486,11 @@ static inline int acpi_get_node(acpi_handle handle) { return 0; } + +static inline int acpi_get_genport_attrs(u8 *device_handle, u64 *val, int type); +{ + return -EOPNOTSUPP; +} #endif extern int acpi_paddr_to_node(u64 start_addr, u64 size); From patchwork Mon Mar 27 21:45:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667481 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 A9665C6FD1D for ; Mon, 27 Mar 2023 21:46:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229967AbjC0VqB (ORCPT ); Mon, 27 Mar 2023 17:46:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231694AbjC0Vpw (ORCPT ); Mon, 27 Mar 2023 17:45:52 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CF7C2D63; Mon, 27 Mar 2023 14:45:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953537; x=1711489537; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3D19eVA6StizRDQ3Hc2AQXS3EISK8uXQhS4ITUho+hg=; b=l4w31YNRE/cXhbYCdh7MWXIry/7wpTK9Z+1CdU/1DHqNDNeb5edSUx9K 5PGAQDiEeZl+nd/rHif4v64yiEmPCgcD8dHn/r5FaH87QgQ9HMsHkFhDP +nPOWLvb8dAtTU4EzW1lcU21V0uGotPXJvt1C1xnNMKYdXDAMw/E21d5z KJKgnifKlcYijfiFmQ+LmiJ4q4f25oNJ81QKLBXk0LcCCZW/WqByDbtlB L4q3oS7dtfm5Yo1pW44jocMsrAwgqNvY44CijX7PNBoGFXWDtmD2heZQK 90+WobnW7cbDz5i6r/vS/1THPDvWkk9Ru+qKEkf2/NpK5BnPFkC6E75q9 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="320799140" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="320799140" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="660958536" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="660958536" Received: from spal2-desk3.gar.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:35 -0700 Subject: [PATCH v2 15/21] cxl: Add helper function to retrieve generic port QoS From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:45:35 -0700 Message-ID: <167995353515.2857312.6918225718341979725.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add CXL helper function that retrieves the bandwidth and latency data of a generic port by calling acpi_get_genport_attrs() function. A device handle is passed in constructed from the ACPI HID and UID of the CXL host bridge (ACPI0016) device. Signed-off-by: Dave Jiang --- drivers/cxl/core/acpi.c | 30 ++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 1 + 2 files changed, 31 insertions(+) diff --git a/drivers/cxl/core/acpi.c b/drivers/cxl/core/acpi.c index 191644d0ca6d..41eeaa8c272e 100644 --- a/drivers/cxl/core/acpi.c +++ b/drivers/cxl/core/acpi.c @@ -148,3 +148,33 @@ struct qtg_dsm_output *cxl_acpi_evaluate_qtg_dsm(acpi_handle handle, return ERR_PTR(rc); } EXPORT_SYMBOL_NS_GPL(cxl_acpi_evaluate_qtg_dsm, CXL); + +/** + * cxl_acpi_get_hb_qos - retrieve QoS data for generic port + * @host: 'struct device' of the CXL host bridge + * @latency: genport latency data + * @bandwidth: genport bandwidth data + * + * Return: Errno on failure, 0 on success. + */ +int cxl_acpi_get_hb_qos(struct device *host, u64 *latency, u64 *bandwidth) +{ + u8 handle[ACPI_SRAT_DEVICE_HANDLE_SIZE] = { 0 }; + struct acpi_device *adev = ACPI_COMPANION(host); + int rc; + + /* ACPI spec 6.5 Table 5.65 */ + memcpy(handle, acpi_device_hid(adev), 8); + memcpy(&handle[8], acpi_device_uid(adev), 4); + + rc = acpi_get_genport_attrs(handle, latency, ACPI_HMAT_ACCESS_LATENCY); + if (rc) + return rc; + + rc = acpi_get_genport_attrs(handle, bandwidth, ACPI_HMAT_ACCESS_BANDWIDTH); + if (rc) + return rc; + + return 0; +} +EXPORT_SYMBOL_NS_GPL(cxl_acpi_get_hb_qos, CXL); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 67e844645ef6..56bcf144eede 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -811,6 +811,7 @@ int cxl_port_get_switch_qos(struct cxl_port *port, u64 *rd_bw, u64 *rd_lat, u64 *wr_bw, u64 *wr_lat); int cxl_port_get_downstream_qos(struct cxl_port *port, u64 *bandwidth, u64 *latency); +int cxl_acpi_get_hb_qos(struct device *host, u64 *latency, u64 *bandwidth); /* * Unit test builds overrides this to __weak, find the 'strong' version From patchwork Mon Mar 27 21:45:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667935 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 37E48C6FD1D for ; Mon, 27 Mar 2023 21:46:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229492AbjC0Vqc (ORCPT ); Mon, 27 Mar 2023 17:46:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232508AbjC0Vp5 (ORCPT ); Mon, 27 Mar 2023 17:45:57 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7DDE30E8; Mon, 27 Mar 2023 14:45:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953550; x=1711489550; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bYRH6N4zfhx3kZr9t6XKOJzTYs9F5EponBN8NC06Fzk=; b=lADN/S20AiXX/3me4VJsHWvEbWnyOrMkyBh55ygWEtwmzLPiXefonIcY eKrEkWhK7XlHXFw8+q7r3KqUyCOcsQB92RfRD3GNp6vtdxHFS37Q+PAHj K8X/+uikjqR92xcmg/g+lUqBBHm6WYM8klQX4GLBKkjFhzsbFoSJaKzyX d5isfQtr/T1C2BxGE9e6l33hQNebo7K0+ZANdBnoqJajPxWhLNWn50r3J wBf3cd/iJsbcaslh+cOhFyZzVXKr+WycecQT+6eZ8Wqjp3nIyUxBLxQXy B71kxMWnfEL5+K4lLvyN4qd97U9mmf8bOC6vXKlZz1bA6z94qV6xLvORu Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="320799240" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="320799240" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="660958585" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="660958585" Received: from spal2-desk3.gar.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:41 -0700 Subject: [PATCH v2 16/21] cxl: Add latency and bandwidth calculations for the CXL path From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:45:41 -0700 Message-ID: <167995354137.2857312.1894822835758834110.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org CXL Memory Device SW Guide rev1.0 2.11.2 provides instruction on how to caluclate latency and bandwidth for CXL memory device. Calculate minimum bandwidth and total latency for the path from the CXL device to the root port. The retrieved QTG ID is stored to the cxl_port of the CXL device. For example for a device that is directly attached to a host bus: Total Latency = Device Latency (from CDAT) + Dev to Host Bus (HB) Link Latency + Generic Port Latency Min Bandwidth = Min bandwidth for link bandwidth between HB and CXL device, device CDAT bandwidth, and Generic Port Bandwidth For a device that has a switch in between host bus and CXL device: Total Latency = Device (CDAT) Latency + Dev to Switch Link Latency + Switch (CDAT) Latency + Switch to HB Link Latency + Generic Port Latency Min Bandwidth = Min bandwidth for link bandwidth between CXL device to CXL switch, CXL device CDAT bandwidth, CXL switch CDAT bandwidth, CXL switch to HB bandwidth, and Generic Port Bandwidth. Signed-off-by: Dave Jiang --- drivers/cxl/cxlpci.h | 1 + drivers/cxl/port.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/drivers/cxl/cxlpci.h b/drivers/cxl/cxlpci.h index 815bf843018e..8ed8dd6903e9 100644 --- a/drivers/cxl/cxlpci.h +++ b/drivers/cxl/cxlpci.h @@ -119,6 +119,7 @@ struct dsmas_entry { struct range dpa_range; u8 handle; u64 qos[HMAT_SLLBIS_DATA_TYPE_MAX]; + u16 qtg_id; }; struct sslbis_entry { diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c index 7839e0244d0d..55517f6f5b84 100644 --- a/drivers/cxl/port.c +++ b/drivers/cxl/port.c @@ -67,6 +67,63 @@ static void dsmas_list_destroy(struct list_head *dsmas_list) } } +static int cxl_port_qos_calculate(struct cxl_port *port, + struct list_head *dsmas_list) +{ + u64 sw_wr_bw, sw_wr_lat, sw_rd_bw, sw_rd_lat; + u64 min_rd_bw, total_rd_lat, min_wr_bw, total_wr_lat; + struct qtg_dsm_output *output; + struct qtg_dsm_input input; + struct dsmas_entry *dent; + acpi_handle handle; + u64 gp_bw, gp_lat; + u64 ds_bw, ds_lat; + int rc; + + rc = cxl_port_get_downstream_qos(port, &ds_bw, &ds_lat); + if (rc) + return rc; + + rc = cxl_port_get_switch_qos(port, &sw_rd_bw, &sw_rd_lat, + &sw_wr_bw, &sw_wr_lat); + if (rc && rc != -ENOENT) + return rc; + + rc = cxl_acpi_get_hb_qos(port->host_bridge, &gp_lat, &gp_bw); + if (rc) + return rc; + + min_rd_bw = min_t(u64, ds_bw, sw_rd_bw); + min_rd_bw = min_t(u64, gp_bw, min_rd_bw); + total_rd_lat = ds_lat + gp_lat + sw_rd_lat; + + min_wr_bw = min_t(u64, ds_bw, sw_wr_bw); + min_wr_bw = min_t(u64, gp_bw, min_wr_bw); + total_wr_lat = ds_lat + gp_lat + sw_wr_lat; + + handle = cxl_acpi_get_rootdev_handle(&port->dev); + if (IS_ERR(handle)) + return PTR_ERR(handle); + + list_for_each_entry(dent, dsmas_list, list) { + input.rd_lat = dent->qos[ACPI_HMAT_READ_LATENCY] + total_rd_lat; + input.wr_lat = dent->qos[ACPI_HMAT_WRITE_LATENCY] + total_wr_lat; + input.rd_bw = min_t(int, min_rd_bw, + dent->qos[ACPI_HMAT_READ_BANDWIDTH]); + input.wr_bw = min_t(int, min_wr_bw, + dent->qos[ACPI_HMAT_WRITE_BANDWIDTH]); + + output = cxl_acpi_evaluate_qtg_dsm(handle, &input); + if (IS_ERR(output)) + continue; + + dent->qtg_id = output->qtg_ids[0]; + kfree(output); + } + + return 0; +} + static int cxl_switch_port_probe(struct cxl_port *port) { struct cxl_hdm *cxlhdm; @@ -162,6 +219,9 @@ static int cxl_port_probe(struct device *dev) dev_warn(dev, "Failed to parse DSMAS: %d\n", rc); } + rc = cxl_port_qos_calculate(port, &dsmas_list); + if (rc) + dev_dbg(dev, "Failed to do QoS calculations\n"); dsmas_list_destroy(&dsmas_list); } else { rc = cdat_table_parse_sslbis(port->cdat.table, From patchwork Mon Mar 27 21:45:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667480 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 29951C6FD1D for ; Mon, 27 Mar 2023 21:47:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229815AbjC0Vqc (ORCPT ); Mon, 27 Mar 2023 17:46:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232336AbjC0VqI (ORCPT ); Mon, 27 Mar 2023 17:46:08 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12A562D6A; Mon, 27 Mar 2023 14:46:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953564; x=1711489564; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zjASrLO9JAbHSbBHk6kX11fYZgCw5TbnWsK7mdF23JY=; b=AkhyFCT5ozUw7NIA2IrCOj2ypk5vvbTjEQcScsXagNiRbJWznVBzLXfw an+wnjsfpomjfSq48o89hNMwckcjfghM4crNnbzOF5kcGT3QtmxT2wgOY +O+XsdCIIq422q3/ZGPAj5wcobSfCHbwL8y6sWZdB5orioP0JrwQ4fuim 57Ps9eFkqqcdsXSvbnaZIBzCbudjGhEg81Q5POiB4m++OoooJBBmU0Qqt h/GqQUc4KLlnYz4TRXwDSvLGqM7kYr2/Uwyk2xYmbFpNRl+LdDaHG4uPu WJpng7gquPG7YSeNJQNXlaMbum8HHHuQIQpALFeKyk3vk9P/NL+pAaNF1 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="320799345" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="320799345" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="660958638" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="660958638" Received: from spal2-desk3.gar.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:48 -0700 Subject: [PATCH v2 17/21] cxl: Wait Memory_Info_Valid before access memory related info From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:45:47 -0700 Message-ID: <167995354763.2857312.3427869236165015969.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org CXL rev3.0 8.1.3.8.2 Memory_Info_valid field The Memory_Info_Valid bit indicates that the CXL Range Size High and Size Low registers are valid. The bit must be set within 1 second of reset deassertion to the device. Check valid bit before we check the Memory_Active bit when waiting for cxl_await_media_ready() to ensure that the memory info is valid for consumption. Fixes: 2e4ba0ec9783 ("cxl/pci: Move cxl_await_media_ready() to the core") Signed-off-by: Dave Jiang --- v2: - Check both ranges. (Jonathan) --- drivers/cxl/core/pci.c | 83 +++++++++++++++++++++++++++++++++++++++++++----- drivers/cxl/cxlpci.h | 2 + 2 files changed, 77 insertions(+), 8 deletions(-) diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c index 2f58cc54e108..268694d33a34 100644 --- a/drivers/cxl/core/pci.c +++ b/drivers/cxl/core/pci.c @@ -101,21 +101,55 @@ int devm_cxl_port_enumerate_dports(struct cxl_port *port) } EXPORT_SYMBOL_NS_GPL(devm_cxl_port_enumerate_dports, CXL); -/* - * Wait up to @media_ready_timeout for the device to report memory - * active. - */ -int cxl_await_media_ready(struct cxl_dev_state *cxlds) +static int cxl_dvsec_mem_range_valid(struct cxl_dev_state *cxlds, int id) +{ + struct pci_dev *pdev = to_pci_dev(cxlds->dev); + int d = cxlds->cxl_dvsec; + bool valid = false; + int rc, i; + u32 temp; + + if (id > CXL_DVSEC_RANGE_MAX) + return -EINVAL; + + /* Check MEM INFO VALID bit first, give up after 1s */ + i = 1; + do { + rc = pci_read_config_dword(pdev, + d + CXL_DVSEC_RANGE_SIZE_LOW(id), + &temp); + if (rc) + return rc; + + valid = FIELD_GET(CXL_DVSEC_MEM_INFO_VALID, temp); + if (valid) + break; + msleep(1000); + } while (i--); + + if (!valid) { + dev_err(&pdev->dev, + "Timeout awaiting memory range %d valid after 1s.\n", + id); + return -ETIMEDOUT; + } + + return 0; +} + +static int cxl_dvsec_mem_range_active(struct cxl_dev_state *cxlds, int id) { struct pci_dev *pdev = to_pci_dev(cxlds->dev); int d = cxlds->cxl_dvsec; bool active = false; - u64 md_status; int rc, i; + u32 temp; - for (i = media_ready_timeout; i; i--) { - u32 temp; + if (id > CXL_DVSEC_RANGE_MAX) + return -EINVAL; + /* Check MEM ACTIVE bit, up to 60s timeout by default */ + for (i = media_ready_timeout; i; i--) { rc = pci_read_config_dword( pdev, d + CXL_DVSEC_RANGE_SIZE_LOW(0), &temp); if (rc) @@ -134,6 +168,39 @@ int cxl_await_media_ready(struct cxl_dev_state *cxlds) return -ETIMEDOUT; } + return 0; +} + +/* + * Wait up to @media_ready_timeout for the device to report memory + * active. + */ +int cxl_await_media_ready(struct cxl_dev_state *cxlds) +{ + struct pci_dev *pdev = to_pci_dev(cxlds->dev); + int d = cxlds->cxl_dvsec; + int rc, i, hdm_count; + u64 md_status; + u16 cap; + + rc = pci_read_config_word(pdev, + d + CXL_DVSEC_CAP_OFFSET, &cap); + if (rc) + return rc; + + hdm_count = FIELD_GET(CXL_DVSEC_HDM_COUNT_MASK, cap); + for (i = 0; i < hdm_count; i++) { + rc = cxl_dvsec_mem_range_valid(cxlds, i); + if (rc) + return rc; + } + + for (i = 0; i < hdm_count; i++) { + rc = cxl_dvsec_mem_range_active(cxlds, i); + if (rc) + return rc; + } + md_status = readq(cxlds->regs.memdev + CXLMDEV_STATUS_OFFSET); if (!CXLMDEV_READY(md_status)) return -EIO; diff --git a/drivers/cxl/cxlpci.h b/drivers/cxl/cxlpci.h index 8ed8dd6903e9..754bfeab2921 100644 --- a/drivers/cxl/cxlpci.h +++ b/drivers/cxl/cxlpci.h @@ -31,6 +31,8 @@ #define CXL_DVSEC_RANGE_BASE_LOW(i) (0x24 + (i * 0x10)) #define CXL_DVSEC_MEM_BASE_LOW_MASK GENMASK(31, 28) +#define CXL_DVSEC_RANGE_MAX 2 + /* CXL 2.0 8.1.4: Non-CXL Function Map DVSEC */ #define CXL_DVSEC_FUNCTION_MAP 2 From patchwork Mon Mar 27 21:45:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667479 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 CE88FC77B6D for ; Mon, 27 Mar 2023 21:47:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231694AbjC0Vqd (ORCPT ); Mon, 27 Mar 2023 17:46:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232443AbjC0VqP (ORCPT ); Mon, 27 Mar 2023 17:46:15 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94B323A82; Mon, 27 Mar 2023 14:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953572; x=1711489572; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R2JHEP2NGtTg4XZMCESgs9TXf6rrTFuo735DGLV/EUQ=; b=P+1DaS07glEVvnWmLHpapXtIm9yX50t657m1GLy8NsyvDgRbFQLDwo8w S7mKQOjQrA3NKXUDO7fZtTIb3B0biWLNaOTe9snmarOM7CwNo77kz3UEr h2NaCdsM+Mxxx0299dxXVoapf5kiHV7O8Rhu2wZG+7A0gdn/zxAqjlHnE nMeiQ8px0u4NRSpfDqhS052tfHnprIrS6map9uFTDceioPoVIOBdPcwPL 3SGrEva/aoeUaau4YG8/T0K453B4vg7cw9VNvabQlmuQyGHw2NlELgHtu wOmk0A4k+Y9QEd3KMEqElC+3VJ16AmT2YLKbdLndZtbWb6iMuvVscBRvw g==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="337900352" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="337900352" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="686114796" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="686114796" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:45:54 -0700 Subject: [PATCH v2 18/21] cxl: Move identify and partition query from pci probe to port probe From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:45:54 -0700 Message-ID: <167995355442.2857312.7640440102093572590.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Move the enumeration of device capacity to cxl_port_probe() from cxl_pci_probe(). The size and capacity information should be read after cxl_await_media_ready() so the data is valid. Fixes: 5e2411ae8071 ("cxl/memdev: Change cxl_mem to a more descriptive name") Signed-off-by: Dave Jiang --- drivers/cxl/pci.c | 8 -------- drivers/cxl/port.c | 8 ++++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index ed39d133b70d..06324266eae8 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -707,14 +707,6 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (rc) return rc; - rc = cxl_dev_state_identify(cxlds); - if (rc) - return rc; - - rc = cxl_mem_create_range_info(cxlds); - if (rc) - return rc; - rc = cxl_alloc_irq_vectors(pdev); if (rc) return rc; diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c index 55517f6f5b84..f6646d91ae26 100644 --- a/drivers/cxl/port.c +++ b/drivers/cxl/port.c @@ -175,6 +175,14 @@ static int cxl_endpoint_port_probe(struct cxl_port *port) return rc; } + rc = cxl_dev_state_identify(cxlds); + if (rc) + return rc; + + rc = cxl_mem_create_range_info(cxlds); + if (rc) + return rc; + rc = devm_cxl_enumerate_decoders(cxlhdm, &info); if (rc) return rc; From patchwork Mon Mar 27 21:46:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667934 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 BE15DC77B61 for ; Mon, 27 Mar 2023 21:47:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231779AbjC0Vqd (ORCPT ); Mon, 27 Mar 2023 17:46:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232464AbjC0VqQ (ORCPT ); Mon, 27 Mar 2023 17:46:16 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C1303590; Mon, 27 Mar 2023 14:46:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953576; x=1711489576; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VNlMZOdJht7Zy6pmLtxW1M0jPur17UAJ1WBP+aKH9eE=; b=G3BjD5syB3n3eCtAZ++BUPW82/tWKq5mOAb0l9Do3uBH/YOIVWRkzLa/ BbjdqW+HvNpEIc7TF7FEE2+8K1gv9hO4nvs3Uxp58845eQG9eRxZnzh9H Fdfplag/kUReSoXdLLXXjy6XawN7RaJSoHI7w6/48aDR15xEAuQ6UjZp3 YOiOyadb/CHrqd9A5YH7/5nK+tFTa5lfJf9XPN0A+7lBLJLhKZ4/ZVIUm HYuKmMG7Yz5OYd5xuPEorn6/Hyl/j3aVPnDhvBzJXBBE07/joZU1/R12q k18js7V1NkxwT2YKaECIbRcucxix1Dgh5Yif1gjnwtznelSJz6PaCbLgn g==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="337900377" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="337900377" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:46:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="686114802" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="686114802" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:46:00 -0700 Subject: [PATCH v2 19/21] cxl: Store QTG IDs and related info to the CXL memory device context From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:46:00 -0700 Message-ID: <167995356029.2857312.4374564094571467987.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Once the QTG ID _DSM is executed successfully, the QTG ID is retrieved from the return package. Create a list of entries in the cxl_memdev context and store the QTG ID and the associated DPA range. This information can be exposed to user space via sysfs in order to help region setup for hot-plugged CXL memory devices. Signed-off-by: Dave Jiang --- drivers/cxl/core/memdev.c | 1 + drivers/cxl/cxlmem.h | 14 ++++++++++++++ drivers/cxl/port.c | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index 28a05f2fe32d..d2605fc39240 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -346,6 +346,7 @@ struct cxl_memdev *devm_cxl_add_memdev(struct cxl_dev_state *cxlds) */ cxlmd->cxlds = cxlds; cxlds->cxlmd = cxlmd; + INIT_LIST_HEAD(&cxlmd->qos_list); cdev = &cxlmd->cdev; rc = cdev_device_add(cdev, dev); diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 001dabf0231b..c8b8d4865e49 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -40,6 +40,7 @@ * @cxl_nvd: optional bridge to an nvdimm if the device supports pmem * @id: id number of this memdev instance. * @depth: endpoint port depth + * @qos_list: QTG ID related list of entries */ struct cxl_memdev { struct device dev; @@ -50,6 +51,7 @@ struct cxl_memdev { struct cxl_nvdimm *cxl_nvd; int id; int depth; + struct list_head qos_list; }; static inline struct cxl_memdev *to_cxl_memdev(struct device *dev) @@ -215,6 +217,18 @@ struct cxl_event_state { struct mutex log_lock; }; +/** + * struct qos_prop - QoS property entry + * @list - list entry + * @dpa_range - range for DPA address + * @qtg_id - QoS Throttling Group ID + */ +struct qos_prop_entry { + struct list_head list; + struct range dpa_range; + u16 qtg_id; +}; + /** * struct cxl_dev_state - The driver device state * diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c index f6646d91ae26..4e7e22c13790 100644 --- a/drivers/cxl/port.c +++ b/drivers/cxl/port.c @@ -124,6 +124,22 @@ static int cxl_port_qos_calculate(struct cxl_port *port, return 0; } +static void cxl_memdev_set_qtg(struct cxl_memdev *cxlmd, struct list_head *dsmas_list) +{ + struct dsmas_entry *dent; + struct qos_prop_entry *qos; + + list_for_each_entry(dent, dsmas_list, list) { + qos = devm_kzalloc(&cxlmd->dev, sizeof(*qos), GFP_KERNEL); + if (!qos) + return; + + qos->dpa_range = dent->dpa_range; + qos->qtg_id = dent->qtg_id; + list_add_tail(&qos->list, &cxlmd->qos_list); + } +} + static int cxl_switch_port_probe(struct cxl_port *port) { struct cxl_hdm *cxlhdm; @@ -212,6 +228,7 @@ static int cxl_port_probe(struct device *dev) read_cdat_data(port); if (port->cdat.table) { if (is_cxl_endpoint(port)) { + struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport); LIST_HEAD(dsmas_list); rc = cdat_table_parse_dsmas(port->cdat.table, @@ -230,6 +247,8 @@ static int cxl_port_probe(struct device *dev) rc = cxl_port_qos_calculate(port, &dsmas_list); if (rc) dev_dbg(dev, "Failed to do QoS calculations\n"); + + cxl_memdev_set_qtg(cxlmd, &dsmas_list); dsmas_list_destroy(&dsmas_list); } else { rc = cdat_table_parse_sslbis(port->cdat.table, From patchwork Mon Mar 27 21:46:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667478 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 1383EC77B6E for ; Mon, 27 Mar 2023 21:47:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232251AbjC0Vqf (ORCPT ); Mon, 27 Mar 2023 17:46:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232477AbjC0VqS (ORCPT ); Mon, 27 Mar 2023 17:46:18 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49B9A2D67; Mon, 27 Mar 2023 14:46:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953577; x=1711489577; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0UAeaeee3yTvKLvqJ/XX58s7B1Cuu8AmvKhY4rlK+DI=; b=eQ5IHQzoTyBDsrhA2KTR22sGcVUpUcCLomh5njS2dhJQPlykXfX3wRC/ DJp13usJrobPq+5Rlja1H/6B4WGQNYbXTTTh4kZjSDB8eARlcTzc9E2Iw L8zXESTDeDlkLuvo92hCPlpuIp8z+nNtE+lzPVui9JSvsUQgpKQCQ1Jjt 5tQJatoqwj8zDYENvuR1hUNpxpILcY8rJjL9RP9+KIqRwsRkdcxlwGPAI AQAdxAMSRCydlzL5QsRIiS7rsJHho8YLK3C5jLdb9W6b9xbybRL6EDepE jvB4+wJ09Bw9Bs+zxNUF4VyzqVW4Bd/q3ibivAYJyXiWVgUobnOcPuoy4 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="337900401" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="337900401" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:46:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="686114808" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="686114808" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:46:06 -0700 Subject: [PATCH v2 20/21] cxl: Export sysfs attributes for memory device QTG ID From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: Dan Williams , dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:46:06 -0700 Message-ID: <167995356611.2857312.4634198260468536572.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Export qtg_id sysfs attributes for the CXL memory device. The QTG ID should show up as /sys/bus/cxl/devices/memX/qtg_id. The QTG ID is retrieved via _DSM after supplying the caluclated bandwidth and latency for the entire CXL path from device to the CPU. This ID is used to match up to the root decoder QTG ID to determine which CFMWS the memory range of a hotplugged CXL mem device should be assigned under. While there may be multiple DSMAS exported by the device CDAT, the driver will only expose the first QTG ID in sysfs for now. In the future when multiple QTG IDs are necessary, they can be exposed. [1] [1]: https://lore.kernel.org/linux-cxl/167571650007.587790.10040913293130712882.stgit@djiang5-mobl3.local/T/#md2a47b1ead3e1ba08f50eab29a4af1aed1d215ab Suggested-by: Dan Williams Signed-off-by: Dave Jiang --- Documentation/ABI/testing/sysfs-bus-cxl | 11 +++++++++++ drivers/cxl/core/memdev.c | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl index 471ac9a37078..a018f0a21aca 100644 --- a/Documentation/ABI/testing/sysfs-bus-cxl +++ b/Documentation/ABI/testing/sysfs-bus-cxl @@ -58,6 +58,17 @@ Description: affinity for this device. +What: /sys/bus/cxl/devices/memX/qtg_id +Date: March, 2024 +KernelVersion: v6.4 +Contact: linux-cxl@vger.kernel.org +Description: + (RO) Show the first QoS Throttling Group ID for the device. + The ID is used to match against the CFMWS (root decoder) + QTG ID so that the memory range under a hot-plugged device + is assigned under the appropriate CFMWS. + + What: /sys/bus/cxl/devices/*/devtype Date: June, 2021 KernelVersion: v5.14 diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c index d2605fc39240..974eff833edd 100644 --- a/drivers/cxl/core/memdev.c +++ b/drivers/cxl/core/memdev.c @@ -106,12 +106,27 @@ static ssize_t numa_node_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(numa_node); +static ssize_t qtg_id_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct cxl_memdev *cxlmd = to_cxl_memdev(dev); + struct qos_prop_entry *qos; + + if (list_empty(&cxlmd->qos_list)) + return 0; + + qos = list_first_entry(&cxlmd->qos_list, struct qos_prop_entry, list); + return sysfs_emit(buf, "%u\n", qos->qtg_id); +} +static DEVICE_ATTR_RO(qtg_id); + static struct attribute *cxl_memdev_attributes[] = { &dev_attr_serial.attr, &dev_attr_firmware_version.attr, &dev_attr_payload_max.attr, &dev_attr_label_storage_size.attr, &dev_attr_numa_node.attr, + &dev_attr_qtg_id.attr, NULL, }; From patchwork Mon Mar 27 21:46:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Jiang X-Patchwork-Id: 667933 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 E05FFC77B6C for ; Mon, 27 Mar 2023 21:47:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232153AbjC0Vqe (ORCPT ); Mon, 27 Mar 2023 17:46:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232479AbjC0VqS (ORCPT ); Mon, 27 Mar 2023 17:46:18 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 131AA2D51; Mon, 27 Mar 2023 14:46:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679953578; x=1711489578; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qMzu4nCtJ++Zi0nLNXxEMdOYChBih0KqyaTouorlZiU=; b=WSdtDeuF/f6eXksYRMQJTDHfr7KdS6077czsaJqcCy2pNLRiwn8rQpM8 KtWPTcOABmWGeQplqchM/DMs1Fpr41JSlkaoQDY/TLF1kOUSDSo6llRAu RgfABcqZiMUILtbWuxWRPlhpeLHLVhwfea0Ur2PWZhBBEd9U9f7aL3xcz IjzhdDaiRvbXsTuLmBZ0nnb8buRHw12TBxxW0NMqJUnG/1GrbfFso1OXF sBCq3VzUKYTc1aaSTNPakkEk88HfRG0vLD6jn3Y82St+hCSM1LQHF74EW ANoeRurcp8Zjd38qHFYIn51Hr82kzdCBno8kcq+KygkHV95BXz2u1w9dc A==; X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="337900415" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="337900415" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:46:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10662"; a="686114814" X-IronPort-AV: E=Sophos;i="5.98,295,1673942400"; d="scan'208";a="686114814" Received: from djiang5-mobl3.amr.corp.intel.com (HELO [192.168.1.177]) ([10.212.91.66]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Mar 2023 14:46:12 -0700 Subject: [PATCH v2 21/21] cxl/mem: Add debugfs output for QTG related data From: Dave Jiang To: linux-cxl@vger.kernel.org, linux-acpi@vger.kernel.org Cc: Dan Williams , dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, rafael@kernel.org, lukas@wunner.de Date: Mon, 27 Mar 2023 14:46:11 -0700 Message-ID: <167995357195.2857312.5279274659737251140.stgit@djiang5-mobl3> In-Reply-To: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> References: <167995336797.2857312.539473939839316778.stgit@djiang5-mobl3> User-Agent: StGit/1.5 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add debugfs output to /sys/kernel/debug/cxl/memX/qtgmap The debugfs attribute will dump out all the DSMAS ranges and the associated QTG ID exported by the CXL device CDAT. Suggested-by: Dan Williams Signed-off-by: Dave Jiang --- drivers/cxl/mem.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c index 39c4b54f0715..bf2cb5a54a7f 100644 --- a/drivers/cxl/mem.c +++ b/drivers/cxl/mem.c @@ -45,6 +45,21 @@ static int cxl_mem_dpa_show(struct seq_file *file, void *data) return 0; } +static int cxl_mem_qtg_show(struct seq_file *file, void *data) +{ + struct device *dev = file->private; + struct cxl_memdev *cxlmd = to_cxl_memdev(dev); + struct qos_prop_entry *qos; + + list_for_each_entry(qos, &cxlmd->qos_list, list) { + seq_printf(file, "%08llx-%08llx : QTG ID %u\n", + qos->dpa_range.start, qos->dpa_range.end, + qos->qtg_id); + } + + return 0; +} + static int devm_cxl_add_endpoint(struct device *host, struct cxl_memdev *cxlmd, struct cxl_dport *parent_dport) { @@ -117,6 +132,7 @@ static int cxl_mem_probe(struct device *dev) dentry = cxl_debugfs_create_dir(dev_name(dev)); debugfs_create_devm_seqfile(dev, "dpamem", dentry, cxl_mem_dpa_show); + debugfs_create_devm_seqfile(dev, "qtgmap", dentry, cxl_mem_qtg_show); rc = devm_add_action_or_reset(dev, remove_debugfs, dentry); if (rc) return rc;