From patchwork Mon Jan 6 12:10:09 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13927262 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 803E7E77199 for ; Mon, 6 Jan 2025 12:12:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 497406B00B7; Mon, 6 Jan 2025 07:12:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 41ED66B00B8; Mon, 6 Jan 2025 07:12:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24C406B00B9; Mon, 6 Jan 2025 07:12:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DFFB46B00B7 for ; Mon, 6 Jan 2025 07:12:02 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id ABBDF457BA for ; Mon, 6 Jan 2025 12:12:02 +0000 (UTC) X-FDA: 82976913684.17.01CE6E8 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf17.hostedemail.com (Postfix) with ESMTP id B58CB4001C for ; Mon, 6 Jan 2025 12:12:00 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736165521; 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=w/ebybN/aPEZ/V23Av1JvMe03wNX+18cdCme2bl3bMA=; b=TavVDPk/PnbqcL63n7PUKi3qoaeMluLSlmGbG1yPeNSpfyDa7Dqba/6TCTX3rIHXglL02z hx3vkxO6Gn+iHBRDhu8oysH27OcFkNs/Wem4CMpd+2oxxsQRgQk6zxCrujykQ2Wkcsq4G8 1sNnkFv7o4Gbdv0Iu8CqT3/GK47K+Hs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736165521; a=rsa-sha256; cv=none; b=dFJ+rpEht4B03CAxKWLEs6BKuMepWGruF716kY8//gbBP4hYCTXeXjSGH/Ef8Q670QMTkn Urj01ocurz0nwJGVByKKH3IUWh0ATM76D6oXrMJt3vxA+kK0MztRxnux0EsK2id1mc8NTn yS2/bSlUUP9gN/8H7FhmxLpFZZyWppU= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4YRY0g25tcz6LD7d; Mon, 6 Jan 2025 20:10:27 +0800 (CST) Received: from frapeml500007.china.huawei.com (unknown [7.182.85.172]) by mail.maildlp.com (Postfix) with ESMTPS id 07761140A08; Mon, 6 Jan 2025 20:11:59 +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:56 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v18 13/19] cxl/mbox: Add SET_FEATURE mailbox command Date: Mon, 6 Jan 2025 12:10:09 +0000 Message-ID: <20250106121017.1620-14-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-Stat-Signature: ux96ggms4g7b8e145ocaipcfkxceaw8j X-Rspamd-Queue-Id: B58CB4001C X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1736165520-206931 X-HE-Meta: U2FsdGVkX18Sl2yrNTToyw84HzOQhbNmZi8nVV0fQDFe5yi8Vp2T6vLoLY1XEFk3/VuLAIJDzk2rTYrqVz6muHHmbsXarBc0/jPa7B/zbDOABWik012LVrZJLz61wG1KTC/H3dkO6QxrZXzJKCPAhj+GvlCca2kTOFZicCXB8kziqSp2gpeDwS9RDltr+toyG3KzanlNWyD7lzuF/Ntg2zeoQYJ1FT/xS000xCv2kS5qR6sJlkwqwf80i7Zo8lHgDOziaWTMHd/kF+Ct3LZ2qyGbIo1sx42ax5ImNbA3gZ+qUhJVTTl7aGX6LbwqTd2FPgwBpJRe3637Dy9s62alPcg0l4xVSJ+tgdWwjbIyxyReQv7y5Ew2lInK8gBR+CWCDSSRO14g4AwxDsee43pGOxsPjAiBmhsgmRsBxq4ST/VJgNdv+DklIoYAviUclxryI6Eyd2eAqHMndwsMFrgxCKhdYJd66pUZLNEj48IuUsK3Xpl35xO4utMiiUVF0euQrmlq9Gs89HkG39/Q23e2M/1/ufwWyixC5vbI6wYQJMX0YASJi6IxOLL9BtJXihZcPa47xc7Dp7lYsvJP+UZjh3cB6whbgR1TDvkbSGJUPx50CGD89769FrVRkoXI74G9/YO/6UnnmnxgG/VsKzjdTwFg7gahjnVW14hXKYt4c9XVotgLdDqE58tDWdHvyjoP4layazLjqShXqrmW53TSkFSiD8Tk/Nww1Ifn/6qNqZsX5vylWtdVbsLDyIkRfuF9f48fxQNwilk3edMVX+HsQqjU0dil5HfmmUcrDF6NhlP2u9p+32yzPmTEFZGkekM/SdWjRwW+9XYhHA0LUzjjnjlArI6fFdkrQBdOViiffb1i+HWACNxaEjnrp2u10L6SbPHWscjLPKltCvDAtL42VcE4w74O1DHvuaiB3W6Gcl11yCVsyDArl+CgEZcIh77xrP+epYJ9z7Q6ByREIHq MKMfLE05 Alcag78LI4MmG/psQu2MChq5QyWDQ5nb+Js82op9OzwFJ7+LrmhFGEGdMzerEiAk6nAuX+PdSEcndyiAo6eSq2LEaRCxKASBIzcpXlSOE4lU/Ir4tSNb1ZKRmHEL4ptf3jOu+fHgXtbNknk2zbEn3noWjp42+IxjgVoowRqtLpVxCRTvzbbDfWFhNJL+qKTFOLGC2XQXzKbtlLAx3ajBhIFzUwwUzGJEJdnvaEWbiMaMWynS+ZmDT2JXIEx9MGGxK0vQFRcNGPvXxMdMvPC3DY0aFPDMkJYVWGg6g 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 SET_FEATURE mailbox command. CXL spec 3.1 section 8.2.9.6 describes optional device specific features. CXL devices supports features with changeable attributes. The settings of a feature can be optionally modified using Set Feature command. CXL spec 3.1 section 8.2.9.6.3 describes Set Feature command. Signed-off-by: Shiju Jose Signed-off-by: Dave Jiang --- drivers/cxl/core/features.c | 92 +++++++++++++++++++++++++++++++++++++ include/cxl/features.h | 32 +++++++++++++ 2 files changed, 124 insertions(+) diff --git a/drivers/cxl/core/features.c b/drivers/cxl/core/features.c index ab9386b53a95..932e82b52f90 100644 --- a/drivers/cxl/core/features.c +++ b/drivers/cxl/core/features.c @@ -171,3 +171,95 @@ size_t cxl_get_feature(struct cxl_features *features, const uuid_t feat_uuid, return data_rcvd_size; } EXPORT_SYMBOL_NS_GPL(cxl_get_feature, "CXL"); + +/* + * FEAT_DATA_MIN_PAYLOAD_SIZE - min extra number of bytes should be + * available in the mailbox for storing the actual feature data so that + * the feature data transfer would work as expected. + */ +#define FEAT_DATA_MIN_PAYLOAD_SIZE 10 +int cxl_set_feature(struct cxl_features *features, + const uuid_t feat_uuid, u8 feat_version, + void *feat_data, size_t feat_data_size, + u32 feat_flag, u16 offset, u16 *return_code) +{ + struct cxl_memdev_set_feat_pi { + struct cxl_mbox_set_feat_hdr hdr; + u8 feat_data[]; + } __packed; + size_t data_in_size, data_sent_size = 0; + struct cxl_features_state *cfs; + struct cxl_mbox_cmd mbox_cmd; + struct cxl_mailbox *cxl_mbox; + size_t hdr_size; + int rc = 0; + + if (return_code) + *return_code = CXL_MBOX_CMD_RC_INPUT; + + cfs = dev_get_drvdata(&features->dev); + if (!cfs) + return -EOPNOTSUPP; + + if (!cxl_feature_enabled(cfs, CXL_MBOX_OP_SET_FEATURE)) + return -EOPNOTSUPP; + + cxl_mbox = features->cxl_mbox; + + struct cxl_memdev_set_feat_pi *pi __free(kfree) = + kmalloc(cxl_mbox->payload_size, GFP_KERNEL); + pi->hdr.uuid = feat_uuid; + pi->hdr.version = feat_version; + feat_flag &= ~CXL_SET_FEAT_FLAG_DATA_TRANSFER_MASK; + feat_flag |= CXL_SET_FEAT_FLAG_DATA_SAVED_ACROSS_RESET; + hdr_size = sizeof(pi->hdr); + /* + * Check minimum mbox payload size is available for + * the feature data transfer. + */ + if (hdr_size + FEAT_DATA_MIN_PAYLOAD_SIZE > cxl_mbox->payload_size) + return -ENOMEM; + + if ((hdr_size + feat_data_size) <= cxl_mbox->payload_size) { + pi->hdr.flags = cpu_to_le32(feat_flag | + CXL_SET_FEAT_FLAG_FULL_DATA_TRANSFER); + data_in_size = feat_data_size; + } else { + pi->hdr.flags = cpu_to_le32(feat_flag | + CXL_SET_FEAT_FLAG_INITIATE_DATA_TRANSFER); + data_in_size = cxl_mbox->payload_size - hdr_size; + } + + do { + pi->hdr.offset = cpu_to_le16(offset + data_sent_size); + memcpy(pi->feat_data, feat_data + data_sent_size, data_in_size); + mbox_cmd = (struct cxl_mbox_cmd) { + .opcode = CXL_MBOX_OP_SET_FEATURE, + .size_in = hdr_size + data_in_size, + .payload_in = pi, + }; + rc = cxl_internal_send_cmd(cxl_mbox, &mbox_cmd); + if (rc < 0) { + if (return_code) + *return_code = mbox_cmd.return_code; + return rc; + } + + data_sent_size += data_in_size; + if (data_sent_size >= feat_data_size) { + if (return_code) + *return_code = CXL_MBOX_CMD_RC_SUCCESS; + return 0; + } + + if ((feat_data_size - data_sent_size) <= (cxl_mbox->payload_size - hdr_size)) { + data_in_size = feat_data_size - data_sent_size; + pi->hdr.flags = cpu_to_le32(feat_flag | + CXL_SET_FEAT_FLAG_FINISH_DATA_TRANSFER); + } else { + pi->hdr.flags = cpu_to_le32(feat_flag | + CXL_SET_FEAT_FLAG_CONTINUE_DATA_TRANSFER); + } + } while (true); +} +EXPORT_SYMBOL_NS_GPL(cxl_set_feature, "CXL"); diff --git a/include/cxl/features.h b/include/cxl/features.h index 582fb85da5b9..41d3602b186c 100644 --- a/include/cxl/features.h +++ b/include/cxl/features.h @@ -75,6 +75,35 @@ struct cxl_mbox_get_feat_in { u8 selection; } __packed; +/* + * Set Feature CXL 3.1 Spec 8.2.9.6.3 + */ + +/* + * Set Feature input payload + * CXL rev 3.1 section 8.2.9.6.3 Table 8-101 + */ +/* Set Feature : Payload in flags */ +#define CXL_SET_FEAT_FLAG_DATA_TRANSFER_MASK GENMASK(2, 0) +enum cxl_set_feat_flag_data_transfer { + CXL_SET_FEAT_FLAG_FULL_DATA_TRANSFER, + CXL_SET_FEAT_FLAG_INITIATE_DATA_TRANSFER, + CXL_SET_FEAT_FLAG_CONTINUE_DATA_TRANSFER, + CXL_SET_FEAT_FLAG_FINISH_DATA_TRANSFER, + CXL_SET_FEAT_FLAG_ABORT_DATA_TRANSFER, + CXL_SET_FEAT_FLAG_DATA_TRANSFER_MAX +}; + +#define CXL_SET_FEAT_FLAG_DATA_SAVED_ACROSS_RESET BIT(3) + +struct cxl_mbox_set_feat_hdr { + uuid_t uuid; + __le32 flags; + __le16 offset; + u8 version; + u8 rsvd[9]; +} __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); @@ -85,5 +114,8 @@ 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); +int cxl_set_feature(struct cxl_features *features, const uuid_t feat_uuid, + u8 feat_version, void *feat_data, size_t feat_data_size, + u32 feat_flag, u16 offset, u16 *return_code); #endif