From patchwork Wed Sep 11 09:04:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13800004 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 7924FEE021F for ; Wed, 11 Sep 2024 09:07:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC128940019; Wed, 11 Sep 2024 05:07:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E4792940015; Wed, 11 Sep 2024 05:07:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C9C4B940019; Wed, 11 Sep 2024 05:07:31 -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 A23A9940015 for ; Wed, 11 Sep 2024 05:07:31 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5AB78AA36A for ; Wed, 11 Sep 2024 09:07:31 +0000 (UTC) X-FDA: 82551879102.24.B023B82 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf17.hostedemail.com (Postfix) with ESMTP id 615524000B for ; Wed, 11 Sep 2024 09:07:29 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; 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; 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=1726045545; 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=5OX63fkb6UuI3R2/OylsB/7hR7bnhw9TCW8RtsIrcok=; b=RUMluk/ONPCFp0VsM6oX7Ir2AWY6wsWa/b/EoTK/6kOIH6esTtOGWQwak29e7IsLLsorSc xHgC2yiuAQ4lHwc2QgxbcQknUAiR0crz34KTYvx59VLCzhCcR8wJfiGQRto1JRmfT1K8xF 62Y4VwU0B3fRagnxXzSz65uQK5rtW+A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726045545; a=rsa-sha256; cv=none; b=YS/DQfY2+GCBvBUWMmbRHqa7VdiB44r5Fm+Em1i7Aqw0xsaf8dGK18po7mfOagiF19bxfY lzsgHXhyIIBwZ8KBXg330uc4xD7BQ56I/aUnEeZMOSGCmbZoTLNwf9EP5Fw96eH72h1KPN M8TYpuRk/gQxKYKJ+qJ2agORTxMsBOk= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; 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; 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 4X3ZN05MVXz6K6Fr; Wed, 11 Sep 2024 17:02:40 +0800 (CST) Received: from frapeml500007.china.huawei.com (unknown [7.182.85.172]) by mail.maildlp.com (Postfix) with ESMTPS id A843F140B38; Wed, 11 Sep 2024 17:07:27 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.195.245.151) 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; Wed, 11 Sep 2024 11:07:25 +0200 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v12 09/17] cxl/mbox: Add SET_FEATURE mailbox command Date: Wed, 11 Sep 2024 10:04:38 +0100 Message-ID: <20240911090447.751-10-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20240911090447.751-1-shiju.jose@huawei.com> References: <20240911090447.751-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.195.245.151] X-ClientProxiedBy: lhrpeml500003.china.huawei.com (7.191.162.67) To frapeml500007.china.huawei.com (7.182.85.172) X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 615524000B X-Stat-Signature: 33fxntqxtpjpzfx876chsf14ugb4unw7 X-HE-Tag: 1726045649-706603 X-HE-Meta: U2FsdGVkX18XZ4YckL4X2o4KQ+X2SK4/tt6rUDeuvKK4fkwkzLL3Tf5cQkVjk7OJJJM+LxOHemA9A8j2bWQgrsMQXO/chd9JU7nd1nuA+wGJqPIQ88uSZ5Z+URj52asnjdmEgAUGlGRI4JDVxdnuRXmM11pIEN/1v0W6pR2xjZyEmjRe07PyRY5e964m/HjHJH903w1pwVv7PepV1XghJnGnNgHSqmAQh6GuhOuN6chgMUPoeWbhz7lrQ6dSIkWxmTDsODLeLirZo7NcZaG0tb9Ik5uAvoASJk4SQcO0GDClbHBpQiToO6O0g5kmJiG2wWkTLHfn0WyWMif03WpMutdx8DZPFH8qp2HsIZy7uc2FbV5cyo9A4zu/dgOaDk2c3JZkAwVzaxJgb0XrHv/7+Ol/iodA0nnp/r/UwIW+Lvb+sItukrUXgqsO4bAc5xqIHzW0yEjyqo+Z1hN6kgiV368KRfkeno57d/KgDbI97nqb9W8w4cNA3Xiqt1/m/f9lgJXFy/FRufDCG8/rVJvfg02QorPzyoZM2dNp786ESXqiqmnKjFyEE1KEcdaTCSNoFxjjBvX8p1jCx2E6Sg12iubN41BqqBOgw8skmLr3JLLxiQ3xWyK1Hin3+IatySM3rE6wo7Z2JnNrKoztN7vRzbsgHwJyhgJp4tfj2g62DzInmHCcIRpaK2YRyhud2DIQLEp7EKPip6z77xzNu1GVr0tLI/p76Utx54W4sHtToNN+Gm1cHGb6S3sDyx8T963WWqbpsMIDl0xKuqPIscQok2dbRV1NFz9ISASOa2NPekWqF/ASNLGK3SvSTtLML58iyu/4sL8gf8jolTp5U4Cs/8sWCuMJvPGyHeMX49tKTZTl0BnIgcuidNWmfK3zCgN6h/bPdfLq2enWivEy/rJ7oFR6Yy7GttxAQ4TDToFzqo2qiPSr746QMUSrimkzaxsJmlriuA/Az6b7DO1f+Sx A8vvuV9U veAvFeNGhzyNxpCRBZyEyne4NNvGPNeIRk1pElYW0oErMpsKficNPuMjpgGP7uIhoFZzG5mFldy1a51eX9+4o4qIas6aEZXHhcwpc6HtIzTeQfs0NzaYHOKxOXVqDBG5Nk7A8gcvPE7scyzYqEkCc1O3FjNEjitF3Gk+zfjHlMlGEF+Sa65qb+IZ7ubjE+wnNP/4QmBd/2byQqSqrnYpz2+JPJYewS3RuDIizCkrZMRSbviZQf5+baYOECDHs3daeKWLHIKQcKnLIdTmKMe35geLmmQigqPOJVzFHxU0z/Y7+Jvg= 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 | 73 +++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 34 +++++++++++++++++++ 2 files changed, 107 insertions(+) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index 3dfe411c6556..806b1c8087b0 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1006,6 +1006,79 @@ size_t cxl_get_feature(struct cxl_dev_state *cxlds, const uuid_t feat_uuid, } 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_dev_state *cxlds, + const uuid_t feat_uuid, u8 feat_version, + void *feat_data, size_t feat_data_size, + u8 feat_flag) +{ + struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox; + 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(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(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) + return rc; + + data_sent_size += data_in_size; + if (data_sent_size >= feat_data_size) + 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); + /** * cxl_enumerate_cmds() - Enumerate commands for a device. * @mds: The driver data for the operation diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 57c9294bb7f3..b565a061a4e3 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -488,6 +488,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, @@ -835,6 +836,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; + int cxl_internal_send_cmd(struct cxl_mailbox *cxl_mbox, struct cxl_mbox_cmd *cmd); int cxl_dev_state_identify(struct cxl_memdev_state *mds); @@ -901,4 +931,8 @@ int cxl_get_supported_feature_entry(struct cxl_dev_state *cxlds, const uuid_t *f size_t cxl_get_feature(struct cxl_dev_state *cxlds, 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_dev_state *cxlds, + const uuid_t feat_uuid, u8 feat_version, + void *feat_data, size_t feat_data_size, + u8 feat_flag); #endif /* __CXL_MEM_H__ */