From patchwork Fri Aug 16 16:42:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13766599 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 A1DF5C3DA4A for ; Fri, 16 Aug 2024 16:43:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7244A6B0136; Fri, 16 Aug 2024 12:43:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6ABC48D007E; Fri, 16 Aug 2024 12:43:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4DA1C6B013C; Fri, 16 Aug 2024 12:43:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 281626B0136 for ; Fri, 16 Aug 2024 12:43:43 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B0375A0115 for ; Fri, 16 Aug 2024 16:43:42 +0000 (UTC) X-FDA: 82458679884.05.34A2BD1 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf05.hostedemail.com (Postfix) with ESMTP id A53F0100013 for ; Fri, 16 Aug 2024 16:43:40 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf05.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723826560; a=rsa-sha256; cv=none; b=g/FARmP9oniPvtMsT0Zws+6uSoOvGS+DhG6bHzEmcgCPJ9uPihCxzhSJKppYw0OKPPtFCU OFe+cleR27RoGnP+ytb458Jf/gBVA1WKrD6ZcIHwNQFfYxrSiRahXELUlczXpOrkttkGiT EsEgdMYCd13taQEX91YJGjtHt5erK9M= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf05.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=1723826560; 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=qF4jvI2IHufnbtyN/a7COQ8WfrsKyUWPT+X4Iru+o4M=; b=qKhE/KKqsitHYgIapA0QpleaIFceabPygOuK+QZgo7D1xFjHcukLnlwD3FdM3EQ7a/P1pU f/gh3FTIK11Ih43NlR2BJlsNh2m5dErlarsWh1SQj1rKiPXwtQ64lDxSzW6QQv8+hb7pPS vgIlLokqGV8dB6vMB+EiXY+Zlp6Z87g= Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4Wlnlz1ghTz6K5t4; Sat, 17 Aug 2024 00:40:15 +0800 (CST) Received: from lhrpeml500006.china.huawei.com (unknown [7.191.161.198]) by mail.maildlp.com (Postfix) with ESMTPS id 3AA0E140680; Sat, 17 Aug 2024 00:43:38 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.48.148.43) 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; Fri, 16 Aug 2024 17:43:36 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v11 06/14] cxl/mbox: Add SET_FEATURE mailbox command Date: Fri, 16 Aug 2024 17:42:29 +0100 Message-ID: <20240816164238.1902-7-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240816164238.1902-1-shiju.jose@huawei.com> References: <20240816164238.1902-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.48.148.43] X-ClientProxiedBy: lhrpeml100005.china.huawei.com (7.191.160.25) To lhrpeml500006.china.huawei.com (7.191.161.198) X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A53F0100013 X-Stat-Signature: b7fu13s1gzyde7ukgbku671gz8itofhu X-Rspam-User: X-HE-Tag: 1723826620-397201 X-HE-Meta: U2FsdGVkX1+vHKPzeUMhPMxdORHE1MRAzaWGRVtM4z8zNCMrNPXKm/fZqpgQALC9qx4Alh9hwlaqb1koav0w7U/EDnL42hjDgLOhvvkJU5oI0/a2BRMCayDqleVorCH2TI7ESDctQ6lqFHAvkZadsHdUTfvWydMxDTyPm/5/VND9fXeKOkD8aB3ll7uniQBOMvta1KUpN+uwvm6CUSpPoSkpKCxlWlU0IV75G267FINLj6TzvJikwdi7OHF+OSnGTWTwe5Qh991LKdqQuRwOx/WTjbDA5gP/9LhbDpmzP+LWY0WRbzy89haTYZissjFfdOdClfRcJ6kex35fZ5Kc4pSzkq6aX8OaMMs7bBZ2FiEm9IH/DkVgoWAgxEtWvXQa8a/WX+JROwu2pYVGrEXZBNomuAkBFDlLHCmHGpCq3emsKRKOkIkI4rNAWgxWCY0VB+lw+pE6/8XV5HvXOljVxdiuNqdghcdZ8AtKINndUDDyhT9sfQirrYdtszjR2HnECJXwF8dfRki9imAwj/GE4UixjWm65ouQiiE+8WkfHJAUbpyY6X1VSQ6LwrXZ+cm3o+QCDjFjmT8lcWM4LW8w2FSOjeBVHNsG3j/wO7uT8onsKvXpE+uzE3gb1bYz5T1L4pNhf/vJhNd1ARG0Ozt/OwYHxks8LFo23WRrhoJnG4Xob18SXFwHLiq+jElU5CBVgVLJE9c7R4O/IU/xjXJKxufnpwTjx5OzKf5fr5yyr0DTYml3XJbcMPDmXcO3eNwY4CaU9oLBSm4/pKrEpuuAbk8uLP9anO5/RFlpNBnO/JvkqbClCm0iIIpBhmtLjluaJniHYXOsOrNcu5Cj5c4/zNr0zblq6DgAgdSQVT+HBn1nuj1+QZzCFmzFXkQvpqT0BsoMGZYatUmyseOye+GJtnz8WD2HjfUvWO0vG3KMFGEhbfmYd5C0oGSSLhtMro75hbyMcvv++XnD3Ya92Bl icaBmD3P GqRsopRQn17lniP3ZYZNw7yaWxA+R7+rw+/UM55VoHruH/+mGIZ90Ul+wbWT2tSgxgqBBlJaTINuPz0ZNvcd2g5ltuQx4GzmX5oCwXI0Jj6XFc5eUSDJFDezWm5a96PrgFDLtb5fJuvDu3+sjEPKUxaRu8hhg4awBI24heSnjrPW6A/LvVD4O8UjbOBhFcozV0xTarNXulZU2QPC54777LGv5iYPIQOgA5nPs1dE9xu6eQXuN5qb5YMsSo6NOOBQJLa0cdXXPkPFL/jhYg+I2N79C77HRRPM+l0u8JwzdV+ktz3g= 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 --- drivers/cxl/core/mbox.c | 72 +++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 34 +++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index c283684e8e73..f79269add159 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1432,6 +1432,78 @@ 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; + 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 > 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 608e3ed845a7..a092a14361ec 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -533,6 +533,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, @@ -781,6 +782,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; + /* Get Poison List CXL 3.0 Spec 8.2.9.8.4.1 */ struct cxl_mbox_poison_in { __le64 offset; @@ -921,6 +951,10 @@ size_t cxl_get_feature(struct cxl_memdev_state *mds, const uuid_t feat_uuid, enum cxl_get_feat_selection selection, void *feat_out, size_t feat_out_size); +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);