From patchwork Fri Apr 19 16:47:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13636608 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 383CFC04FF6 for ; Fri, 19 Apr 2024 16:48:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF8A86B009E; Fri, 19 Apr 2024 12:47:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D5AFE6B009F; Fri, 19 Apr 2024 12:47:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A75F76B00A0; Fri, 19 Apr 2024 12:47:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 740AB6B009F for ; Fri, 19 Apr 2024 12:47:53 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2010DA25E2 for ; Fri, 19 Apr 2024 16:47:53 +0000 (UTC) X-FDA: 82026863226.29.95FDF7E Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf16.hostedemail.com (Postfix) with ESMTP id 2392918000C for ; Fri, 19 Apr 2024 16:47:50 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; spf=pass (imf16.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=1713545271; 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=VC7rMdELh0pbhpVZri3WsWx/6r+VY4Nx2RgkTHWAzqo=; b=7juOznTL9S9JfJnm5LL8a0D17NrTgMTfWL3QeaNNqA+EyTP2nRRjDKMSd/UFeMbdFTvxGH TIjbfBZPbMIcELop6XC5ZjDWu30XxDYRL2ytCu/4NfFRhp4FMXEfTkNs5/XjY3qMj7anjH Jazp2l7+hPpV9vjncQsNxU4+DBxDhDY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713545271; a=rsa-sha256; cv=none; b=CMXuyT6GI/KTwxubiedITOv6HNzLj1KEhNKcZWJBv/1ghl2rqcj83dUvnnhCYiJHH8ZZG3 q45/ecBqqPmzAlG88S12bg1osZER4YWurD657vd/bKCEnA/F/4sz9+fLPYayFk+gHUyRS9 fvaejk+OQnoh7ABCU4n2Mu4093T0nTA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; spf=pass (imf16.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 Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4VLgW90KVRz6K62N; Sat, 20 Apr 2024 00:45:41 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id DAB6A140B55; Sat, 20 Apr 2024 00:47:47 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) 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.35; Fri, 19 Apr 2024 17:47:44 +0100 From: To: , , , , , , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH v8 04/10] cxl/mbox: Add SET_FEATURE mailbox command Date: Sat, 20 Apr 2024 00:47:13 +0800 Message-ID: <20240419164720.1765-5-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20240419164720.1765-1-shiju.jose@huawei.com> References: <20240419164720.1765-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml500006.china.huawei.com (7.191.161.198) To lhrpeml500006.china.huawei.com (7.191.161.198) X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 2392918000C X-Stat-Signature: 7tmjf7ikkxzwy3gk79ch5iuo3eg1kg5a X-HE-Tag: 1713545270-988737 X-HE-Meta: U2FsdGVkX198H2zbU3DhqyZYFePhaatTVyZiHQr7pRBsn7ZN2Rc6JXBNpqBcpXl1yPiE2o4C1KeRK18FzlooXazFfhnr9KPOp1x5YhDpc7gu1kk8e2+NsNnZWtIs7WfKqw+Ja4MNQoYJaIUO1aBPsA8z5lj9yHimyV4OVENM7eCIUdkU6IVP6tD3bPqjmgq1Rax9NtbMUc3EE0JJ4tE3EaazW3QDhK+gvzkYy4YrfUQ20eTo79jVZykVnjX7WnoERvOWdRKZORhSaZbrjMixMzU0cmXq1dop7p50Qr9IkuDAJhcPiljEGIqp+dnazDOsMFuI9E94e1KFScg4Nu1tQEy9+u5DbJ5wDwmCWk+fYOyTHF4CTttVtXcvTAj6bi4fXiItAxzZJhNVDjgPodVCTxN3vNPNLGFeD+7Jo2ZBjQFCamiWehecL/pSl4quzdC7guQ5SBxGdJoU61Evwv3m16LLWtdCdX9550CsNUO+L1bNf66Hasj5vfNXinZ9tckx2fxN+g4Ng3IiTl5UIncYv8lsbMwpDpPXmZddQKuFtfCGFooOqMcspiqRIA/yAVezHTSeWE1o/XRe953KEVA8ALV6HSkQF8a5futwzftb6h3qlS6h6T1/TjshBrbocTnfi2CzA/PnihqNemqUEO7mmsfJVQGAWgLDSX6O7VI3i8qKhCtxFRTPdYnqn8KNcYSwR1z1rsVPFdRPFHV99NGfwZ1mVbUUgpG/eq/+9HnjfWJDRrS7itrBWlXW1zlRJTw9CH1dEeol8tlMP1XWHxrCeeC3HKY+B9dTX1qP1/g0lXmfurXT4/KWo/w9WXV+oHCpmlHWK41/0Ib7f23V0s4BlQtqQ6WV503C2FQPJIFMIsA+G7Qi1wQgu9b1QUPZ7RKcQOLPz7/ihrvN24EoZnBIb9nTzZaStjLePCI4orgBCSFJgyAS4U0uVtadvQxYfI2j6kmNPoFRTCPsR72hSk8 OGj3hUb2 9TvsHmbC0vbOLLTTI4evsXfAWNhsQQ7hFWlRb99GVQYv/tH4FkB7TQJ/N77gqegg9rCks2qGC3HBO86e8g51n6YJehsksrhUdHdVExRaTwk1aA+1EVCS81KYWNHr0E9He8tHrp95Ahn0JwB14mHyHNYY/JJbXEJ6R7avNFVgtSRXHIx3h75JVGdZXWrVvQICaFOSoq/l81TDAnSj3fEXbxczsZLY+k5GfJWpH9vdAPOR8eYzggv1IsB1ase28DmClCgsOZZAX5nra0qtkn70RntWi315kEbvA7lkV3wJeYOxuRVI= 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 | 73 +++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 33 +++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index 999965871048..4ca1238e8fec 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1371,6 +1371,79 @@ 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); + + return rc; +} +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 c822eb30e6d1..1c50a3e2eced 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -529,6 +529,7 @@ enum cxl_opcode { CXL_MBOX_OP_GET_LOG = 0x0401, 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, @@ -777,6 +778,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; @@ -916,6 +945,10 @@ size_t cxl_get_feature(struct cxl_memdev_state *mds, size_t feat_out_size, size_t feat_out_min_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);