From patchwork Mon Jan 6 12:10:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13927261 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE4BCE77198 for ; Mon, 6 Jan 2025 12:12:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 495046B00B4; Mon, 6 Jan 2025 07:12:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F7796B00B3; Mon, 6 Jan 2025 07:12:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D4836B00B4; Mon, 6 Jan 2025 07:12:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id ECE6E6B00B2 for ; Mon, 6 Jan 2025 07:11:59 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A73F41211BB for ; Mon, 6 Jan 2025 12:11:59 +0000 (UTC) X-FDA: 82976913558.02.2D6EE83 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf14.hostedemail.com (Postfix) with ESMTP id B5FA6100005 for ; Mon, 6 Jan 2025 12:11:57 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736165518; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bRt/4O1dt4aRr92KBUh2/YI4zKqd4cT1qDk/y89qkZs=; b=3aUSS8QQBPOe6Qo1s14RmkR61KSliNG7Ldn++CNSWsPjNDYST+XFnFAIk+YJ5/tNs7lmhN d5Vfj5/d1Li5tQaqp6q2tPvQzNP3bGi9YznJTp6LBGNJKouvACiwxeyYbDtMGZWcLJqClC AxDekaJMFnsVjuwkGue0k8e+FrQ5pqk= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736165518; a=rsa-sha256; cv=none; b=ku9IipWqW4j7QL0GFXZuH4AJN8eQC9jSaNRuA5R0P81mi3ILVZ5uMWz2VaBln6wWjKJ1dC DOlnVhxwptkBviSBX7jVERWp5Jdqz6kp1np9wAf8cjK++6fW4pKAjemvCUC/C9FciOLI2H VHBjpqeMDFDzKeW5/aLfa1V8VJcusWA= Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4YRXxB43NLz6K8qh; Mon, 6 Jan 2025 20:07:26 +0800 (CST) Received: from frapeml500007.china.huawei.com (unknown [7.182.85.172]) by mail.maildlp.com (Postfix) with ESMTPS id 26439140A08; Mon, 6 Jan 2025 20:11:56 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.126.170.95) by frapeml500007.china.huawei.com (7.182.85.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 6 Jan 2025 13:11:54 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v18 12/19] cxl/mbox: Add GET_FEATURE mailbox command Date: Mon, 6 Jan 2025 12:10:08 +0000 Message-ID: <20250106121017.1620-13-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20250106121017.1620-1-shiju.jose@huawei.com> References: <20250106121017.1620-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.126.170.95] X-ClientProxiedBy: lhrpeml100011.china.huawei.com (7.191.174.247) To frapeml500007.china.huawei.com (7.182.85.172) X-Rspamd-Server: rspam05 X-Stat-Signature: ihbczbd7xrir3uqg1n9nocupd77mrc9z X-Rspamd-Queue-Id: B5FA6100005 X-Rspam-User: X-HE-Tag: 1736165517-682305 X-HE-Meta: U2FsdGVkX1+pemM6+4E+AeSzUctZU/EDdW1T9Jo/tqT6sFaM8lfbvnyQlGolxgxYRGSdAFcZJdz/AdndjcpguhaAPOAsuO8CPqo6HcnIBCagcJ8aF+xvY+HfQqnQoSHTa4a6KjWOs4HcENJaqPNreeRNdQmfSnYhgqhLgGSDU+2FJkHoqf/BMU3Zf4WK18eJx+IMEkXBq+61biuqi1qFDBFm8Ro6Gjc47PFUyW8oplMYb8Ehl9hmvGEHJz87PVjuYGi63kD+EVHnQGRIjDb4Oh5kzu+WqaADKJ0euvliCqgKTGyexT7+KkorDMkrlVi/FrkefqVswWLOsXdDdGyz52+7Sw4TcYZvkPNWcMs+UlqpZOjJV7b/sxg+ZtppGoGzyIxjyAEwx5X638mNfsBkXZ1IbRNBwi3Yepn6kcmngDcXUpl3Dd0vJShFJrSGySvr8RWKT81ziGX3zg50nP+AwjrR7IQcFz590RhUDQDG2VeUh9FFTMPtnXjANRd6MsNlGBq1XH3pherQQgDtlthSoLxDhD+zTTLQc6/8lCfOGcvroVnM4EfnmFDp4lxSdyppkAo7bPZd2Wu07SgWVkWIX2ANYqnbp70fCpThZwOUCrHTW3lPraoTTKcNWriwubuxZUOXS3Q/g3pyY21S4q/dWbhCA3BZ3uFHnj18MJHuwRod6H+LOflfn9mO6Yb26aGJamGxwB2We0Elj4ULW0/JXDmSnYZe1rDJsPODCPfoK+lmBnf8lwHqc/DqR3wh4aFmSl3PAuugOtrhkjh/K/2L/dPf1dK44PrKt8ZgTocXPDeOGx72qqnu3G8DPzUZZ86wAgM03eEgN7ujY/HqM3jVinznBohd81sBrXXbCt4Op9XaqarVrEDlVl5twjPgOCDCBq6MUbJL4Pl9+RkH/Ahzu4lvIjqASrFN37Bs5VpKodBw/3YGIVv5vN2ROjQskJnUenO1kdubm9SNi661Ehk 6FPRVEuD WberU2ZvsVOGUcQvT9JdXNHqLdNbCn2trdnFg+mYUYgyLh2xg95q0pp1TJBAgCGMUR5BmlTbRudWPkBm6ilFYqXeWp6/02i/EdaEfn3ez8+oX1i38m52pn/zvf6ivhjoMCwesIv3NtH+3guTwdxYfwH9Plygebz5v7b8guMN9VlWtWg8Th5nYfgr4H0X6JOUW9XYl4DdYSUzCIYu8M01+tpqzf/hesVwjQGFP94kIIRYr1V0m1mJG5Wx9tsax2qTdmQ1t49/oYqbqCbgHFSjfsV+f+31pG31661E8 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Shiju Jose Add support for GET_FEATURE mailbox command. CXL spec 3.1 section 8.2.9.6 describes optional device specific features. The settings of a feature can be retrieved using Get Feature command. CXL spec 3.1 section 8.2.9.6.2 describes Get Feature command. Signed-off-by: Shiju Jose Signed-off-by: Dave Jiang --- drivers/cxl/core/features.c | 74 +++++++++++++++++++++++++++++++++++++ drivers/cxl/features.c | 6 +-- include/cxl/features.h | 27 ++++++++++++++ 3 files changed, 102 insertions(+), 5 deletions(-) diff --git a/drivers/cxl/core/features.c b/drivers/cxl/core/features.c index 66a4b82910e6..ab9386b53a95 100644 --- a/drivers/cxl/core/features.c +++ b/drivers/cxl/core/features.c @@ -4,6 +4,7 @@ #include #include "cxl.h" #include "core.h" +#include "cxlmem.h" #define CXL_FEATURE_MAX_DEVS 65536 static DEFINE_IDA(cxl_features_ida); @@ -97,3 +98,76 @@ cxl_get_supported_feature_entry(struct cxl_features *features, return ERR_PTR(-ENOENT); } EXPORT_SYMBOL_NS_GPL(cxl_get_supported_feature_entry, "CXL"); + +bool cxl_feature_enabled(struct cxl_features_state *cfs, u16 opcode) +{ + struct cxl_mailbox *cxl_mbox = cfs->features->cxl_mbox; + struct cxl_mem_command *cmd; + + cmd = cxl_find_feature_command(opcode); + if (!cmd) + return false; + + return test_bit(cmd->info.id, cxl_mbox->feature_cmds); +} +EXPORT_SYMBOL_NS_GPL(cxl_feature_enabled, "CXL"); + +size_t cxl_get_feature(struct cxl_features *features, const uuid_t feat_uuid, + enum cxl_get_feat_selection selection, + void *feat_out, size_t feat_out_size, u16 offset, + u16 *return_code) +{ + size_t data_to_rd_size, size_out; + struct cxl_features_state *cfs; + struct cxl_mbox_get_feat_in pi; + struct cxl_mailbox *cxl_mbox; + struct cxl_mbox_cmd mbox_cmd; + size_t data_rcvd_size = 0; + int rc; + + if (return_code) + *return_code = CXL_MBOX_CMD_RC_INPUT; + + cfs = dev_get_drvdata(&features->dev); + if (!cfs) + return 0; + + if (!cxl_feature_enabled(cfs, CXL_MBOX_OP_GET_FEATURE)) + return 0; + + if (!feat_out || !feat_out_size) + return 0; + + cxl_mbox = features->cxl_mbox; + size_out = min(feat_out_size, cxl_mbox->payload_size); + pi.uuid = feat_uuid; + pi.selection = selection; + do { + data_to_rd_size = min(feat_out_size - data_rcvd_size, + cxl_mbox->payload_size); + pi.offset = cpu_to_le16(offset + data_rcvd_size); + pi.count = cpu_to_le16(data_to_rd_size); + + mbox_cmd = (struct cxl_mbox_cmd) { + .opcode = CXL_MBOX_OP_GET_FEATURE, + .size_in = sizeof(pi), + .payload_in = &pi, + .size_out = size_out, + .payload_out = feat_out + data_rcvd_size, + .min_out = data_to_rd_size, + }; + rc = cxl_internal_send_cmd(cxl_mbox, &mbox_cmd); + if (rc < 0 || !mbox_cmd.size_out) { + if (return_code) + *return_code = mbox_cmd.return_code; + return 0; + } + data_rcvd_size += mbox_cmd.size_out; + } while (data_rcvd_size < feat_out_size); + + if (return_code) + *return_code = CXL_MBOX_CMD_RC_SUCCESS; + + return data_rcvd_size; +} +EXPORT_SYMBOL_NS_GPL(cxl_get_feature, "CXL"); diff --git a/drivers/cxl/features.c b/drivers/cxl/features.c index 2f0fb072921e..2faa9e03a840 100644 --- a/drivers/cxl/features.c +++ b/drivers/cxl/features.c @@ -47,14 +47,10 @@ static int cxl_get_supported_features(struct cxl_features_state *cfs) struct cxl_mbox_get_sup_feats_in mbox_in; struct cxl_feat_entry *entry; struct cxl_mbox_cmd mbox_cmd; - struct cxl_mem_command *cmd; int count; /* Get supported features is optional, need to check */ - cmd = cxl_find_feature_command(CXL_MBOX_OP_GET_SUPPORTED_FEATURES); - if (!cmd) - return -EOPNOTSUPP; - if (!test_bit(cmd->info.id, cxl_mbox->feature_cmds)) + if (!cxl_feature_enabled(cfs, CXL_MBOX_OP_GET_SUPPORTED_FEATURES)) return -EOPNOTSUPP; count = cxl_get_supported_features_count(cxl_mbox); diff --git a/include/cxl/features.h b/include/cxl/features.h index 429b9782667c..582fb85da5b9 100644 --- a/include/cxl/features.h +++ b/include/cxl/features.h @@ -53,10 +53,37 @@ struct cxl_features_state { struct cxl_feat_entry *entries; }; +/* + * Get Feature CXL 3.1 Spec 8.2.9.6.2 + */ + +/* + * Get Feature input payload + * CXL rev 3.1 section 8.2.9.6.2 Table 8-99 + */ +enum cxl_get_feat_selection { + CXL_GET_FEAT_SEL_CURRENT_VALUE, + CXL_GET_FEAT_SEL_DEFAULT_VALUE, + CXL_GET_FEAT_SEL_SAVED_VALUE, + CXL_GET_FEAT_SEL_MAX +}; + +struct cxl_mbox_get_feat_in { + uuid_t uuid; + __le16 offset; + __le16 count; + u8 selection; +} __packed; + +bool cxl_feature_enabled(struct cxl_features_state *cfs, u16 opcode); struct cxl_features *cxl_features_alloc(struct cxl_mailbox *cxl_mbox, struct device *parent); struct cxl_feat_entry * cxl_get_supported_feature_entry(struct cxl_features *features, const uuid_t *feat_uuid); +size_t cxl_get_feature(struct cxl_features *features, const uuid_t feat_uuid, + enum cxl_get_feat_selection selection, + void *feat_out, size_t feat_out_size, u16 offset, + u16 *return_code); #endif