From patchwork Tue Jul 16 15:03:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13734594 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 7F17BC3DA49 for ; Tue, 16 Jul 2024 15:04:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 87E0A6B0093; Tue, 16 Jul 2024 11:04:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 807F66B0095; Tue, 16 Jul 2024 11:04:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 683136B0096; Tue, 16 Jul 2024 11:04:41 -0400 (EDT) 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 4760B6B0093 for ; Tue, 16 Jul 2024 11:04:41 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id ECF6B1212A3 for ; Tue, 16 Jul 2024 15:04:40 +0000 (UTC) X-FDA: 82345937520.22.037D5B2 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf10.hostedemail.com (Postfix) with ESMTP id E9EB1C0021 for ; Tue, 16 Jul 2024 15:04:38 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.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=1721142260; 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=YMIqX1krpZfca2bDoM0Co7MTbbiSb4dospFOevbcvPs=; b=2Qkfvz7Q+qiDyafYfN7h/UTpD2jHT5z0+AJsreuILWzIgJZ2a6W7tqikFNpS340hYCjOFK EcY7beUjY3NRG15F+wWRvcMgteYB2xXUkatB6wNEN2ChmMCv15IUE96PH5kK5T5NVlm8ya RQVSbb527APVnoEBwTZQzdGjOV86F0o= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.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=1721142260; a=rsa-sha256; cv=none; b=f/OYcsINx8Yg+74tMWoxA8yXOEzYeS68f+Lh7YRHWlgiYhiJPFzTU85E3a2O7rctnsd3U+ NaokLSSHGrXxsWUAptlo3epjEjusDs6amDdKUqDIzQqhjHnzQrjxQwStkSXGtrUyZuoEzU p7vuMpZvCm7J6woJmiiXAjL2hcKHRKM= Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WNj3N0F6Gz6K8wS; Tue, 16 Jul 2024 23:02:24 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id F038B1400CF; Tue, 16 Jul 2024 23:04:36 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.48.159.153) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 16 Jul 2024 16:04:35 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v9 06/11] cxl/mbox: Add SET_FEATURE mailbox command Date: Tue, 16 Jul 2024 16:03:30 +0100 Message-ID: <20240716150336.2042-7-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240716150336.2042-1-shiju.jose@huawei.com> References: <20240716150336.2042-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.48.159.153] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500006.china.huawei.com (7.191.161.198) X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: E9EB1C0021 X-Stat-Signature: bxh8179jyut56eyp6mr1zs8eiubuhya1 X-HE-Tag: 1721142278-863164 X-HE-Meta: U2FsdGVkX1+69lNUIJtE2f9YEiPPYvSGcDzyGCV8RgCTLtrxmOwPK8Ct7sZb1zD2aYIHq33W6DBrIFqODwImZH+cdiQCrPBYMR0SGg6j4VuQlAldAw5z57Q4crxF0taWsx6NPcSf+BIPRfUf3nrvPkfxEvOis5AnyZAQZgpEYsov9RbVyO6zXm1H4rNgv/zYg3OBJITwZHmd5RS5TiR2rIzeQngnunooFgyzNvcKqzN7PoZuARqS/t6l3KSQrusd4fH2Xd2FnWjNfXtJVkEkwWlJ6ACgQ7lLX2RnLZLwF2GxpdLyC0Qi1hWrc9MsjaUc8BU/4SLk1GcxQXysVEe8B6r19q8NtvsHqArQsncTrb4j8U+sDnIiQ5p6XMAJfu3pNBw3tJtmyB3XLM7LmAApiXZbNSJ6Te2JghybZ0wKyCY7YqWrloQWDGeeRhT+Fo8rhCQbW2zbzqlUUZbRHJX2LduPWh/21d/zyeJlLe93JuvXbZzps+8jJnoETSsrhsZg0OBl0pYfuQConFroQOLIJ71+ZPhXKW4rdbSl3fIVJSllmahpy09i9pb0AApwPyyAd2dkVpSK8lEeliO7cJBTbsSWO4+T6mqDRqyC/KBfWHT91741nreojwr0W/piXRfdb8NY+/DzWp4oAfddyeDpymR9qTWXFkrDNsskOB96niQdxlhXMYRqWWZxqRQemdiEDJIH/KuDo2fpVjaCc17qwAibEvufc3XGpfHEBnhoegtWhsXiQAS2m2N4J5MbbkBoN2NMIbdTxLCmHKbj1UBDUK8IDdS+kjhnPF5te49x6STepXdjOh28KZzJi6klf4Z/fkfUG20EC335H2dHyGCuA1w19LdzZq8apyWCeAPKOAjQb90s7L3OR3jfREQd62O9zJkbE/xCO0205msy9+TBULPkVDx4ddhfzzzvZVeGFgqyQX6lhor7rs0BUj4QVTvydYY/RVx4okJkchBZBo6 gyZIYhZ2 1P0G5dWDdthajC1UjXwBX12smQN63//M3Y9g4FLCV7pa1UJGjyJSpEJglTPUJPOHWS86jxZIuvBQKjl7njXpy1zgfueWHm/OEVo21rYAI3C8GHEK0Qd4PoWwCNFlPjFtzWbn1M4guMOOmvWi3QU/DQnKxkDGnuV+uMJ5HLYQpRkr12riZ5HTu9KWBTKFNXSFRK9mOhBLweSna8UYvSLEED56zg5S9rftH9tuwvpqotrStkb+Su5Hd9/ZRLW367IMqZVUneSoeLEWgnUJwnFFfCtgon/jXxTZ0cJ0BmCJPOV6Jnd8= 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. Signed-off-by: Shiju Jose --- drivers/cxl/core/mbox.c | 71 +++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 33 +++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index b1eeed508459..50ecd2bd7372 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1388,6 +1388,77 @@ size_t cxl_get_feature(struct cxl_memdev_state *mds, } 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_memdev_state *mds, + const uuid_t feat_uuid, u8 feat_version, + void *feat_data, size_t feat_data_size, + u8 feat_flag) +{ + 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_mbox_cmd mbox_cmd; + size_t hdr_size; + int rc = 0; + + struct cxl_memdev_set_feat_pi *pi __free(kfree) = + kmalloc(mds->payload_size, GFP_KERNEL); + pi->hdr.uuid = feat_uuid; + pi->hdr.version = feat_version; + feat_flag &= ~CXL_SET_FEAT_FLAG_DATA_TRANSFER_MASK; + 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 > mds->payload_size) + return -ENOMEM; + + if ((hdr_size + feat_data_size) <= mds->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 = mds->payload_size - hdr_size; + } + + do { + pi->hdr.offset = cpu_to_le16(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(mds, &mbox_cmd); + if (rc < 0) + return rc; + + data_sent_size += data_in_size; + if (data_sent_size >= feat_data_size) + return 0; + + if ((feat_data_size - data_sent_size) <= (mds->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); + int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, struct cxl_region *cxlr) { diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 25698a6fbe66..c3cb8e2736b5 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -532,6 +532,7 @@ enum cxl_opcode { 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, @@ -780,6 +781,34 @@ 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; + /* Get Poison List CXL 3.0 Spec 8.2.9.8.4.1 */ struct cxl_mbox_poison_in { __le64 offset; @@ -918,6 +947,10 @@ size_t cxl_get_feature(struct cxl_memdev_state *mds, const uuid_t feat_uuid, void *feat_out, size_t feat_out_size, enum cxl_get_feat_selection selection); +int cxl_set_feature(struct cxl_memdev_state *mds, + const uuid_t feat_uuid, u8 feat_version, + void *feat_data, size_t feat_data_size, + u8 feat_flag); int cxl_poison_state_init(struct cxl_memdev_state *mds); int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len, struct cxl_region *cxlr);