From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5A50C2F2 for ; Sat, 1 Feb 2025 00:45:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738370706; cv=none; b=btevfYUSysH9QmMghLKqi1qyMoFi8XAiTIPrciazs4fHHdl6iZD/Iagn4QFGGEkmsDr5y3dmpJixZ7f3VR27XC6X3tPd39jIYqM9RDV8iBw4cd2LmTje0Zc9jaIMO763w5JhDuPeYp7y/OO8tL/BBk8ulwAH8cetyckLf0En4P4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738370706; c=relaxed/simple; bh=O+sjJoiUJIEpzHXs3kCrM//uBAa9UmLXJiW3qHimMcU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ij0ZxtwBrPl3V9KQOjdTyvW/hj1IlY044RSUsq/FX3c2qcBGpMqYfDvnhbtaR1U7U3DbpiBwrj6E7BoX9Vn+l5+nlP+LmnwZS5hZ7eHzQtNZvqy1binMWPZ0WvsS8rwvXfpgXRPcz9nPZCc3Ab48I3plwKHKaGwSlWlhaOuMwKQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06471C4CED1; Sat, 1 Feb 2025 00:45:04 +0000 (UTC) From: Dave Jiang To: linux-cxl@vger.kernel.org Cc: dan.j.williams@intel.com, ira.weiny@intel.com, vishal.l.verma@intel.com, alison.schofield@intel.com, Jonathan.Cameron@huawei.com, dave@stgolabs.net, jgg@nvidia.com, shiju.jose@huawei.com Subject: [PATCH v2 02/16] cxl: Enumerate feature commands Date: Fri, 31 Jan 2025 17:41:55 -0700 Message-ID: <20250201004459.466499-3-dave.jiang@intel.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250201004459.466499-1-dave.jiang@intel.com> References: <20250201004459.466499-1-dave.jiang@intel.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add feature commands enumeration code in order to detect and enumerate the 3 feature related commands "get supported features", "get feature", and "set feature". The enumeration will help determine whether the driver can issue any of the 3 commands to the device. Signed-off-by: Dave Jiang --- v2: - Setup allocation of cxlfs and move enumeration of commands to the setup function. - Introduce features_capability enum. (Dan) - Name the setup function devm_cxl_add_features(). (Dan) - Drop 'cxl_mem_command' support. (Dan) - Move feature support to mem probe. (Dan) - Remove comma at last entry of data structs. (Jonathan) --- drivers/cxl/Makefile | 2 +- drivers/cxl/core/mbox.c | 30 ++++++++++++++++++++++ drivers/cxl/cxl.h | 2 ++ drivers/cxl/cxlmem.h | 5 ++++ drivers/cxl/features.c | 55 ++++++++++++++++++++++++++++++++++++++++ drivers/cxl/features.h | 8 ++++++ drivers/cxl/mem.c | 5 ++++ include/cxl/features.h | 35 +++++++++++++++++++++++++ include/cxl/mailbox.h | 2 ++ tools/testing/cxl/Kbuild | 2 +- 10 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 drivers/cxl/features.c create mode 100644 drivers/cxl/features.h create mode 100644 include/cxl/features.h diff --git a/drivers/cxl/Makefile b/drivers/cxl/Makefile index 2caa90fa4bf2..12fbc35081bb 100644 --- a/drivers/cxl/Makefile +++ b/drivers/cxl/Makefile @@ -17,5 +17,5 @@ obj-$(CONFIG_CXL_PCI) += cxl_pci.o cxl_port-y := port.o cxl_acpi-y := acpi.o cxl_pmem-y := pmem.o security.o -cxl_mem-y := mem.o +cxl_mem-y := mem.o features.o cxl_pci-y := pci.o diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index bdb8f060f2c1..25fb7bd770b3 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -69,6 +69,29 @@ static struct cxl_mem_command cxl_mem_commands[CXL_MEM_COMMAND_ID_MAX] = { CXL_CMD(GET_TIMESTAMP, 0, 0x8, 0), }; +static u16 cxl_feature_commands[] = { + CXL_MBOX_OP_GET_SUPPORTED_FEATURES, + CXL_MBOX_OP_GET_FEATURE, + CXL_MBOX_OP_SET_FEATURE +}; + +/** + * cxl_get_feature_command_id() - Get the index id for a feature command + * @opcode: The device opcode for the feature command + * + * Return the index id on success or -errno on failure + */ +int cxl_get_feature_command_id(u16 opcode) +{ + for (int i = 0; i < ARRAY_SIZE(cxl_feature_commands); i++) { + if (cxl_feature_commands[i] == opcode) + return i; + } + + return -ENOENT; +} +EXPORT_SYMBOL_NS_GPL(cxl_get_feature_command_id, "CXL"); + /* * Commands that RAW doesn't permit. The rationale for each: * @@ -734,6 +757,13 @@ static void cxl_walk_cel(struct cxl_memdev_state *mds, size_t size, u8 *cel) if (cmd) { set_bit(cmd->info.id, cxl_mbox->enabled_cmds); enabled++; + } else { + int fid = cxl_get_feature_command_id(opcode); + + if (fid >= 0) { + set_bit(fid, cxl_mbox->feature_cmds); + enabled++; + } } if (cxl_is_poison_command(opcode)) { diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index f6015f24ad38..2d6f7c87e5e8 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -911,6 +911,8 @@ void cxl_coordinates_combine(struct access_coordinate *out, bool cxl_endpoint_decoder_reset_detected(struct cxl_port *port); +int cxl_get_feature_command_id(u16 opcode); + /* * Unit test builds overrides this to __weak, find the 'strong' version * of these symbols in tools/testing/cxl/. diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index a0a49809cd76..4a42cdb64b5c 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -39,6 +39,7 @@ * @dev: driver core device object * @cdev: char dev core object for ioctl operations * @cxlds: The device state backing this device + * @cxlfs: The features state for the device * @detach_work: active memdev lost a port in its ancestry * @cxl_nvb: coordinate removal of @cxl_nvd if present * @cxl_nvd: optional bridge to an nvdimm if the device supports pmem @@ -50,6 +51,7 @@ struct cxl_memdev { struct device dev; struct cdev cdev; struct cxl_dev_state *cxlds; + struct cxl_features_state *cxlfs; struct work_struct detach_work; struct cxl_nvdimm_bridge *cxl_nvb; struct cxl_nvdimm *cxl_nvd; @@ -490,6 +492,9 @@ enum cxl_opcode { CXL_MBOX_OP_GET_LOG_CAPS = 0x0402, CXL_MBOX_OP_CLEAR_LOG = 0x0403, CXL_MBOX_OP_GET_SUP_LOG_SUBLIST = 0x0405, + CXL_MBOX_OP_GET_SUPPORTED_FEATURES = 0x0500, + CXL_MBOX_OP_GET_FEATURE = 0x0501, + CXL_MBOX_OP_SET_FEATURE = 0x0502, CXL_MBOX_OP_IDENTIFY = 0x4000, CXL_MBOX_OP_GET_PARTITION_INFO = 0x4100, CXL_MBOX_OP_SET_PARTITION_INFO = 0x4101, diff --git a/drivers/cxl/features.c b/drivers/cxl/features.c new file mode 100644 index 000000000000..13b0b29ee102 --- /dev/null +++ b/drivers/cxl/features.c @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2024-2025 Intel Corporation. All rights reserved. */ +#include +#include +#include +#include "cxl.h" +#include "cxlmem.h" +#include "features.h" + +static void enumerate_feature_cmds(struct cxl_memdev *cxlmd) +{ + struct cxl_dev_state *cxlds = cxlmd->cxlds; + struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox; + struct cxl_features_state *cxlfs = cxlds->cxlmd->cxlfs; + int fid; + + fid = cxl_get_feature_command_id(CXL_MBOX_OP_GET_SUPPORTED_FEATURES); + if (!test_bit(fid, cxl_mbox->feature_cmds)) + return; + + fid = cxl_get_feature_command_id(CXL_MBOX_OP_GET_FEATURE); + if (!test_bit(fid, cxl_mbox->feature_cmds)) + return; + + cxlfs->cap = CXL_FEATURES_RO; + + fid = cxl_get_feature_command_id(CXL_MBOX_OP_SET_FEATURE); + if (!test_bit(fid, cxl_mbox->feature_cmds)) + return; + + cxlfs->cap = CXL_FEATURES_RW; +} + +/** + * devm_cxl_add_features() - Allocate and initialize features context + * @cxlmd: CXL memory device + * + * Return 0 on success or -errno on failure. + */ +int devm_cxl_add_features(struct cxl_memdev *cxlmd) +{ + struct cxl_features_state *cxlfs; + struct device *dev = &cxlmd->dev; + + cxlfs = devm_kzalloc(dev, sizeof(*cxlfs), GFP_KERNEL); + if (!cxlfs) + return -ENOMEM; + + cxlmd->cxlfs = cxlfs; + cxlfs->cxlmd = cxlmd; + enumerate_feature_cmds(cxlmd); + + return 0; +} +EXPORT_SYMBOL_NS_GPL(devm_cxl_add_features, "CXL"); diff --git a/drivers/cxl/features.h b/drivers/cxl/features.h new file mode 100644 index 000000000000..0cc6d9e6c441 --- /dev/null +++ b/drivers/cxl/features.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2025 Intel Corporation. */ +#ifndef __CXL_FEATURES_LOCAL__ +#define __CXL_FEATURES_LOCAL__ + +int devm_cxl_add_features(struct cxl_memdev *cxlmd); + +#endif diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c index 2f03a4d5606e..47348a52bc05 100644 --- a/drivers/cxl/mem.c +++ b/drivers/cxl/mem.c @@ -7,6 +7,7 @@ #include "cxlmem.h" #include "cxlpci.h" +#include "features.h" /** * DOC: cxl mem @@ -180,6 +181,10 @@ static int cxl_mem_probe(struct device *dev) return rc; } + rc = devm_cxl_add_features(cxlmd); + if (rc) + dev_dbg(dev, "No CXL Features enumerated.\n"); + /* * The kernel may be operating out of CXL memory on this device, * there is no spec defined way to determine whether this device diff --git a/include/cxl/features.h b/include/cxl/features.h new file mode 100644 index 000000000000..eadf0d56553f --- /dev/null +++ b/include/cxl/features.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2024-2025 Intel Corporation. */ +#ifndef __CXL_FEATURES_H__ +#define __CXL_FEATURES_H__ + +struct cxl_mailbox; + +/* Index IDs for CXL mailbox Feature commands */ +enum feature_cmds { + CXL_FEATURE_ID_GET_SUPPORTED_FEATURES = 0, + CXL_FEATURE_ID_GET_FEATURE, + CXL_FEATURE_ID_SET_FEATURE, + CXL_FEATURE_ID_MAX +}; + +/* Feature commands capability supported by a device */ +enum cxl_features_capability { + CXL_FEATURES_NONE = 0, + CXL_FEATURES_RO, + CXL_FEATURES_RW +}; + +/** + * struct cxl_features_state - The Features state for the device + * @cxlmd: Pointer to cxl mem device + * @cap: Feature commands capability + * @num_features: total Features supported by the device + */ +struct cxl_features_state { + struct cxl_memdev *cxlmd; + enum cxl_features_capability cap; + int num_features; +}; + +#endif diff --git a/include/cxl/mailbox.h b/include/cxl/mailbox.h index cc894f07a435..99d3bbe1ba2a 100644 --- a/include/cxl/mailbox.h +++ b/include/cxl/mailbox.h @@ -3,6 +3,7 @@ #ifndef __CXL_MBOX_H__ #define __CXL_MBOX_H__ #include +#include #include /** @@ -56,6 +57,7 @@ struct cxl_mailbox { struct device *host; DECLARE_BITMAP(enabled_cmds, CXL_MEM_COMMAND_ID_MAX); DECLARE_BITMAP(exclusive_cmds, CXL_MEM_COMMAND_ID_MAX); + DECLARE_BITMAP(feature_cmds, CXL_FEATURE_ID_MAX); size_t payload_size; struct mutex mbox_mutex; /* lock to protect mailbox context */ struct rcuwait mbox_wait; diff --git a/tools/testing/cxl/Kbuild b/tools/testing/cxl/Kbuild index b1256fee3567..47be82a2dd5b 100644 --- a/tools/testing/cxl/Kbuild +++ b/tools/testing/cxl/Kbuild @@ -46,7 +46,7 @@ cxl_port-y += cxl_port_test.o obj-m += cxl_mem.o -cxl_mem-y := $(CXL_SRC)/mem.o +cxl_mem-y := $(CXL_SRC)/mem.o $(CXL_SRC)/features.o cxl_mem-y += config_check.o cxl_mem-y += cxl_mem_test.o -- 2.48.1