From patchwork Thu Jan 27 21:29:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 12727431 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 64B7CC433F5 for ; Thu, 27 Jan 2022 21:29:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230317AbiA0V3g (ORCPT ); Thu, 27 Jan 2022 16:29:36 -0500 Received: from mga03.intel.com ([134.134.136.65]:30536 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbiA0V3g (ORCPT ); Thu, 27 Jan 2022 16:29:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643318976; x=1674854976; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gQO89et669dzx6ow2bGppQogeEOsPa/FRO7ZoBM0oT4=; b=Wt7qivZIL0RZrGtT28zq1I3LsyZ822Y9uv6/MFORpBrhrR6AHf3DNzqE zg02RffYttELEW2EW6ZcfOjNPiq4ZwxKndf6OC06bTlpFNfHTyD97JBnB I4MMDA9jjxo5m6OD4Dt7jsW2rB+d8w1SLwe0AEX+6l/X838xxIxMdKrZM hp8ULzb0d5Ica8zPaJARxNM7MeoZylD3IbvD25COOSJIaY6y/jjm6ph2Q FL8hPNJ1QiSJ/AvuMr1g4I6VV4h21FAVZ19zcdyVRHSzZsV0adSgLE5Ql DLu2azI4APXZQkTzKxsKGqAVCIej4cte8PWZWI3vXbar8jF6LO4hjEQWK w==; X-IronPort-AV: E=McAfee;i="6200,9189,10239"; a="246914534" X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="246914534" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 13:29:33 -0800 X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="521402187" Received: from vrao2-mobl1.gar.corp.intel.com (HELO localhost.localdomain) ([10.252.129.6]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 13:29:32 -0800 From: Ben Widawsky To: linux-cxl@vger.kernel.org Cc: patches@lists.linux.dev, Ben Widawsky , Alison Schofield , Dan Williams , Ira Weiny , Jonathan Cameron , Vishal Verma Subject: [PATCH 1/4] cxl/acpi: Store interleave granularity absolutely Date: Thu, 27 Jan 2022 13:29:08 -0800 Message-Id: <20220127212911.127741-2-ben.widawsky@intel.com> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20220127212911.127741-1-ben.widawsky@intel.com> References: <20220127212911.127741-1-ben.widawsky@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org This matches the usages everywhere else in the driver and matches the existing kernel documentation defined for CXL decoders. Signed-off-by: Ben Widawsky --- drivers/cxl/acpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c index f64d98bfcb3b..f99cad8350fd 100644 --- a/drivers/cxl/acpi.c +++ b/drivers/cxl/acpi.c @@ -11,7 +11,7 @@ /* Encode defined in CXL 2.0 8.2.5.12.7 HDM Decoder Control Register */ #define CFMWS_INTERLEAVE_WAYS(x) (1 << (x)->interleave_ways) -#define CFMWS_INTERLEAVE_GRANULARITY(x) ((x)->granularity + 8) +#define CFMWS_INTERLEAVE_GRANULARITY(x) (1 << ((x)->granularity + 8)) static unsigned long cfmws_to_decoder_flags(int restrictions) { From patchwork Thu Jan 27 21:29:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 12727428 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 A6E12C433FE for ; Thu, 27 Jan 2022 21:29:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230374AbiA0V3g (ORCPT ); Thu, 27 Jan 2022 16:29:36 -0500 Received: from mga03.intel.com ([134.134.136.65]:30536 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbiA0V3g (ORCPT ); Thu, 27 Jan 2022 16:29:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643318976; x=1674854976; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=t4zZwTnokNlqXGMfgu29KqGrhR4jjOjQZrlpar9zdDQ=; b=mBLhF2zvUSyXyKg5heW27kElKahjapiOTT2jdIyqqfG40Ain+t7x6wG4 f0dFuxkVjY6rHn8uSfH+eoYEaZdbUgCq9q5966IscqGQT1MLNz6cRhJDr 3x4ypflqjZ44Nt0VflJTZVDAkue+MeKhvVAoJ/DV+DdTQJxfRHHe2MusO FxWy3PPucGUf28dF5YlHfKMf+6xCXrwxcaWML7SbwgEKLHPlex07SraSe 6iKDnEe3Ep6UfW0zRyoACrzP5CPUIoriqR71JYpEYoapf0gfOc6A9xie9 kmWOylLtR+ZdvrqwdBNFJ3AVtbQKBjWm1WY6JomjkFWj0VLnTaClUw/XB g==; X-IronPort-AV: E=McAfee;i="6200,9189,10239"; a="246914535" X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="246914535" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 13:29:33 -0800 X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="521402190" Received: from vrao2-mobl1.gar.corp.intel.com (HELO localhost.localdomain) ([10.252.129.6]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 13:29:32 -0800 From: Ben Widawsky To: linux-cxl@vger.kernel.org Cc: patches@lists.linux.dev, Ben Widawsky , Alison Schofield , Dan Williams , Ira Weiny , Jonathan Cameron , Vishal Verma Subject: [PATCH 2/4] cxl/core: Add more decoder attributes to sysfs Date: Thu, 27 Jan 2022 13:29:09 -0800 Message-Id: <20220127212911.127741-3-ben.widawsky@intel.com> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20220127212911.127741-1-ben.widawsky@intel.com> References: <20220127212911.127741-1-ben.widawsky@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org The decoder attributes are consumed by userspace in order to program and verify the CXL topology. An example of the new attributes is with x1 and 8192 granularity: archlinux ~ # cat /sys/bus/cxl/devices/decoder0.0/interleave_{ways,granularity} 1 8192 Signed-off-by: Ben Widawsky --- drivers/cxl/core/port.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index f49783d8c845..631dec0fa79e 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -99,6 +99,25 @@ static ssize_t size_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(size); +static ssize_t interleave_ways_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->interleave_ways); +} +static DEVICE_ATTR_RO(interleave_ways); + +static ssize_t interleave_granularity_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->interleave_granularity); +} +static DEVICE_ATTR_RO(interleave_granularity); + #define CXL_DECODER_FLAG_ATTR(name, flag) \ static ssize_t name##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \ @@ -186,6 +205,8 @@ static struct attribute *cxl_decoder_base_attrs[] = { &dev_attr_start.attr, &dev_attr_size.attr, &dev_attr_locked.attr, + &dev_attr_interleave_ways.attr, + &dev_attr_interleave_granularity.attr, NULL, }; From patchwork Thu Jan 27 21:29:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 12727430 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 A144CC43217 for ; Thu, 27 Jan 2022 21:29:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229610AbiA0V3h (ORCPT ); Thu, 27 Jan 2022 16:29:37 -0500 Received: from mga03.intel.com ([134.134.136.65]:30536 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235091AbiA0V3g (ORCPT ); Thu, 27 Jan 2022 16:29:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643318976; x=1674854976; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hnTws23roenYnf9FuTxI5kIVmD5micpi0QGZFv8KyLc=; b=jY3YUb/YbFcQ9QxD4MuSJ9tHoz3ZkNNh/5sP53k6gNxpKBUYP5E/WFMk atQq//X5IjVhEbSBDYolY7HMdiFNSzMBKKJaRR+AIDhARVE6CUA/V7zMt I3sOWWio/2rgGg6s8HcMwjVouTezLVnFbXUDID9zc0Hrxh3yn6gV9sgoD DTyyNe7H8anbIXtZQIy1jZcbgzRo58B4suC/VvwCLm8F0AjcBN4XaaUj7 NwS4WK/t+jPf9NoE5dxhfx9qWHSDVAfDRGZ4iWj9FkInCgpaNH5cl9aEu 3ZvesGhaAIXh2CQZ8yLKwG6FDn9OjcIT4X/q5+gJaYbF+mMmTvBwSNuUU A==; X-IronPort-AV: E=McAfee;i="6200,9189,10239"; a="246914536" X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="246914536" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 13:29:33 -0800 X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="521402193" Received: from vrao2-mobl1.gar.corp.intel.com (HELO localhost.localdomain) ([10.252.129.6]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 13:29:32 -0800 From: Ben Widawsky To: linux-cxl@vger.kernel.org Cc: patches@lists.linux.dev, Ben Widawsky , Alison Schofield , Dan Williams , Ira Weiny , Jonathan Cameron , Vishal Verma Subject: [PATCH 3/4] cxl/core: Extract IW/IG decoding Date: Thu, 27 Jan 2022 13:29:10 -0800 Message-Id: <20220127212911.127741-4-ben.widawsky@intel.com> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20220127212911.127741-1-ben.widawsky@intel.com> References: <20220127212911.127741-1-ben.widawsky@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Interleave granularity and ways have specification defined encodings. Extracting this functionality into the common header file allows other consumers to make use of it. Signed-off-by: Ben Widawsky --- I'm in favor of making these helps part of UABI. Having userspace and kernel disagree (because of differing spec versions for example) would be difficult to manage. Thoughts? --- drivers/cxl/core/hdm.c | 11 ++--------- drivers/cxl/cxl.h | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c index 4955ba16c9c8..a28369f264da 100644 --- a/drivers/cxl/core/hdm.c +++ b/drivers/cxl/core/hdm.c @@ -133,21 +133,14 @@ static int to_interleave_granularity(u32 ctrl) { int val = FIELD_GET(CXL_HDM_DECODER0_CTRL_IG_MASK, ctrl); - return 256 << val; + return cxl_to_interleave_granularity(val); } static int to_interleave_ways(u32 ctrl) { int val = FIELD_GET(CXL_HDM_DECODER0_CTRL_IW_MASK, ctrl); - switch (val) { - case 0 ... 4: - return 1 << val; - case 8 ... 10: - return 3 << (val - 8); - default: - return 0; - } + return cxl_to_interleave_ways(val); } static int init_hdm_decoder(struct cxl_port *port, struct cxl_decoder *cxld, diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 962629c5775f..13fb06849199 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -64,6 +64,23 @@ static inline int cxl_hdm_decoder_count(u32 cap_hdr) return val ? val * 2 : 1; } +static inline int cxl_to_interleave_granularity(u16 ig) +{ + return 256 << ig; +} + +static inline int cxl_to_interleave_ways(u8 eniw) +{ + switch (eniw) { + case 0 ... 4: + return 1 << eniw; + case 8 ... 10: + return 3 << (eniw - 8); + default: + return 0; + } +} + /* CXL 2.0 8.2.8.1 Device Capabilities Array Register */ #define CXLDEV_CAP_ARRAY_OFFSET 0x0 #define CXLDEV_CAP_ARRAY_CAP_ID 0 From patchwork Thu Jan 27 21:29:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 12727427 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 8AFA9C433F5 for ; Thu, 27 Jan 2022 21:29:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230365AbiA0V3e (ORCPT ); Thu, 27 Jan 2022 16:29:34 -0500 Received: from mga18.intel.com ([134.134.136.126]:50502 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230317AbiA0V3d (ORCPT ); Thu, 27 Jan 2022 16:29:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643318973; x=1674854973; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c1aM+hrXlpfMyS4zpoHXcSqxmp0h+TQpG3apP92+EwM=; b=Ypo4wPoTLQXlVdRw/Cvq/RJqI5HMUo9XaXeSLZd1sBp5SsI2TiWo80/8 bd1mMtXnU9nRjQHYGUFYSGR8G9inz3LjV5mg6hOAA7WoLBEmeTbfF32ra L7X1uon0Y+IYzx8EC0cy3me42JpYjnFQVgxqq0kouNAuaKNHyf+Uy92uy geVCdk7SYlubXwWc9Uvr3wcl7NbHhXU5mBszvVUZ+dmJyPdAtyabaK1Yp km8NvbsCoA2Cw1vN+a62grnbxGlf0gK4PlRJ8t5g6ZEvqa7elpCKprU4m CopYS92ZNDo/6lffjf6O63gi0+ZE+4iyvvKLcmaaxx5SdIw8SZ1SWwMT3 w==; X-IronPort-AV: E=McAfee;i="6200,9189,10239"; a="230546182" X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="230546182" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 13:29:33 -0800 X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="521402198" Received: from vrao2-mobl1.gar.corp.intel.com (HELO localhost.localdomain) ([10.252.129.6]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 13:29:33 -0800 From: Ben Widawsky To: linux-cxl@vger.kernel.org Cc: patches@lists.linux.dev, Ben Widawsky , Alison Schofield , Dan Williams , Ira Weiny , Jonathan Cameron , Vishal Verma Subject: [PATCH 4/4] cxl/acpi: Use common IW/IG decoding Date: Thu, 27 Jan 2022 13:29:11 -0800 Message-Id: <20220127212911.127741-5-ben.widawsky@intel.com> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20220127212911.127741-1-ben.widawsky@intel.com> References: <20220127212911.127741-1-ben.widawsky@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Now that functionality to decode interleave ways and granularity is in a common place, use that functionality in the cxl_acpi driver. Signed-off-by: Ben Widawsky --- drivers/cxl/acpi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c index f99cad8350fd..d6dcb2b6af48 100644 --- a/drivers/cxl/acpi.c +++ b/drivers/cxl/acpi.c @@ -10,8 +10,8 @@ #include "cxl.h" /* Encode defined in CXL 2.0 8.2.5.12.7 HDM Decoder Control Register */ -#define CFMWS_INTERLEAVE_WAYS(x) (1 << (x)->interleave_ways) -#define CFMWS_INTERLEAVE_GRANULARITY(x) (1 << ((x)->granularity + 8)) +#define CFMWS_INTERLEAVE_WAYS(x) (cxl_to_interleave_ways((x)->interleave_ways)) +#define CFMWS_INTERLEAVE_GRANULARITY(x) (cxl_to_interleave_granularity((x)->granularity)) static unsigned long cfmws_to_decoder_flags(int restrictions) {