From patchwork Wed Sep 11 09:04:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13800008 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 3F18BEE021F for ; Wed, 11 Sep 2024 09:08:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E032094001A; Wed, 11 Sep 2024 05:07:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CEBCE94001E; Wed, 11 Sep 2024 05:07:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8557994001A; Wed, 11 Sep 2024 05:07:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5948894001C for ; Wed, 11 Sep 2024 05:07:56 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E07CC140764 for ; Wed, 11 Sep 2024 09:07:55 +0000 (UTC) X-FDA: 82551880110.12.B0F65A8 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf19.hostedemail.com (Postfix) with ESMTP id E9DA71A0011 for ; Wed, 11 Sep 2024 09:07:53 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.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=1726045669; a=rsa-sha256; cv=none; b=aouK2EtW0bG/0bULQLsEn/1L2EBN/wPoohxqCN5b9FnlI5dyM5HwnUwwqr9zwX//3MaoUw RbEV4KllCxgk2Vm909S8x6pEt98bqD/IEJi+MeOLDxOG+BtoNKhW5tIeEKEWCuYIuSz3aV XPfSdxS33cgit5N21pmGLEECagj7Ajo= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.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=1726045669; 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=y91z5OfE2jY0SF7uaVxgC87Os5sSYEq9HTrkj7VDjQY=; b=gy5Hh/UEaH2G8m3nOvyxcTV67Bbxj9LIgsUt0+cLVAgYQBpsa8dhRp6It1UzUruuQ3AP/r 8sGKLrgB6KESq1K2xYaRuasyopV2VTZP2LPjNi8Jb9syLCyl7HUPN6cgfBgKpL0Qpe+wzA WlLJI40ybtkvHpCB7BWfk4ehdz+hVfM= Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4X3ZPP73vZz6K5wh; Wed, 11 Sep 2024 17:03:53 +0800 (CST) Received: from frapeml500007.china.huawei.com (unknown [7.182.85.172]) by mail.maildlp.com (Postfix) with ESMTPS id D7E6B140A77; Wed, 11 Sep 2024 17:07:51 +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:49 +0200 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v12 16/17] cxl/mbox: Add support for PERFORM_MAINTENANCE mailbox command Date: Wed, 11 Sep 2024 10:04:45 +0100 Message-ID: <20240911090447.751-17-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-Stat-Signature: 5a8g63cxeaose5weigjdgqz4reb9qt6i X-Rspamd-Queue-Id: E9DA71A0011 X-Rspamd-Server: rspam02 X-HE-Tag: 1726045673-764405 X-HE-Meta: U2FsdGVkX1/tZYqJfkvkL4DXGxHZn7kc5bVEK3ZWxAfoohPLCBDXDXCwDG4Mr8BymhHgxDJC2yEfOCow8MpqU/gtv7YxLScLapK7UnP6Sv6Hr2cg7E9sEJxzWLplr6WkZSQVtcdNg/V+tnFtzMXtuEtGkqVBzlt0V2ckyPZ7uW/dqd+imjN3feaJvpViIfDtXmJsSIdx6pdYyqET7wvWKQ4spU3B/YLHTYGqaWGxr8SV/HsYMGpRvaf6bOQAI8IlSRfkLzR/yShA/xjH5F2DXUa+l83i35MklRNVjVJjaVj8o9mgYn/5JTVckMt3jLpq8VFdbDc0T7xVZjD2FwWjgUvaEqpcj9hf6bVw5MZgwQQrFvi1iSSJYSAu7DYAipbSI92scUmUH6ElQILmHAsfWEDzSv7lCumqxA0vcl2Ro/RzMl0uSrTEM1Q421TGD1vQhLNeXSDPMDJc/IKlrz+I7uu6BU9tpVgxALPWNRJ9pWK5+Q7CJ/1PMIXaNkWaznuvcvGtQr0zvAbB3T7I6CK2IVK0x3YTBUUPSJ5gXEovzDr/bKntipwFacqisDcucNQSS93+Z2f5vp3dyM6r4PhuHD6ZwMbONqboJIBqqlK2KpAlsMAFN+D1+cKFvEGSdVqekgsejYbZRZWF1QJOzxH9eIPSFNSXVNoBW+2spljsEjZCG2SbD/a1GIMDRO2vHNgcjyPJoT+iZ90HWEEexg2YpJqh7B5BSC+vtqCaBLQfu8b2QG6Yxb5ZTfX+5p0yZWrcGBlirK34UflB9QS+36tsgc1XUEgd4g0f0LwbSVuOIxdEMPiCXXEk8q/K/xyGP6kpFvxpf0bbMyb3w9i6OSvEceWF2j4KZ9/JSAjT1q5sdSrZT+YjH7hWePeGtdIXzfT5iYcPaLW45nyoNkuY4QRnHeTGmw0Gey+Q0l1U0pQkK/B73jYPYOAqpuxAEIXqlpmYdGSxxZIfHsasNGLvhuG TjNvvzut DE+u6zZBQ2QQo3Q1CGLdIAHpmMlJOZUc4OY/oRJo+L1jwPHkSqro+Ds40D/X6FQpypnYwwei8JsBRtn7H36FFNMrW1NZL+hRjXsa4vJSgwt7edX0z0ORara8PBKukY7h3AWbPX42sBSynzKaPIheV8YvM7ItMW4ZUpSkYEUvS+P6cGP/pknbNIti8r216iC1e6yZlRIsRehXwgrSb7Qnx6jQvOrNbtNL5Jwvwhnu2IhfemISU/6BatQIRzaNW2T+WRqj0wc9wyjRh1ds= 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 PERFORM_MAINTENANCE mailbox command. CXL spec 3.1 section 8.2.9.7.1 describes the Perform Maintenance command. This command requests the device to execute the maintenance operation specified by the maintenance operation class and the maintenance operation subclass. Signed-off-by: Shiju Jose --- drivers/cxl/core/mbox.c | 40 ++++++++++++++++++++++++++++++++++++++++ drivers/cxl/cxlmem.h | 17 +++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c index 806b1c8087b0..6c91f5f5be48 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1079,6 +1079,46 @@ int cxl_set_feature(struct cxl_dev_state *cxlds, } EXPORT_SYMBOL_NS_GPL(cxl_set_feature, CXL); +int cxl_do_maintenance(struct cxl_dev_state *cxlds, + u8 class, u8 subclass, + void *data_in, size_t data_in_size) +{ + struct cxl_mailbox *cxl_mbox = &cxlds->cxl_mbox; + struct cxl_memdev_maintenance_pi { + struct cxl_mbox_do_maintenance_hdr hdr; + u8 data[]; + } __packed; + struct cxl_mbox_cmd mbox_cmd; + size_t hdr_size; + int rc = 0; + + struct cxl_memdev_maintenance_pi *pi __free(kfree) = + kmalloc(cxl_mbox->payload_size, GFP_KERNEL); + pi->hdr.op_class = class; + pi->hdr.op_subclass = subclass; + hdr_size = sizeof(pi->hdr); + /* + * Check minimum mbox payload size is available for + * the maintenance data transfer. + */ + if (hdr_size + data_in_size > cxl_mbox->payload_size) + return -ENOMEM; + + memcpy(pi->data, data_in, data_in_size); + mbox_cmd = (struct cxl_mbox_cmd) { + .opcode = CXL_MBOX_OP_DO_MAINTENANCE, + .size_in = hdr_size + data_in_size, + .payload_in = pi, + }; + + rc = cxl_internal_send_cmd(cxl_mbox, &mbox_cmd); + if (rc < 0) + return rc; + + return 0; +} +EXPORT_SYMBOL_NS_GPL(cxl_do_maintenance, 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 2187c3378eaa..ba454a2315ee 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -489,6 +489,7 @@ enum cxl_opcode { CXL_MBOX_OP_GET_SUPPORTED_FEATURES = 0x0500, CXL_MBOX_OP_GET_FEATURE = 0x0501, CXL_MBOX_OP_SET_FEATURE = 0x0502, + CXL_MBOX_OP_DO_MAINTENANCE = 0x0600, CXL_MBOX_OP_IDENTIFY = 0x4000, CXL_MBOX_OP_GET_PARTITION_INFO = 0x4100, CXL_MBOX_OP_SET_PARTITION_INFO = 0x4101, @@ -865,6 +866,19 @@ struct cxl_mbox_set_feat_hdr { u8 rsvd[9]; } __packed; +/* + * Perform Maintenance CXL 3.1 Spec 8.2.9.7.1 + */ + +/* + * Perform Maintenance input payload + * CXL rev 3.1 section 8.2.9.7.1 Table 8-102 + */ +struct cxl_mbox_do_maintenance_hdr { + u8 op_class; + u8 op_subclass; +} __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); @@ -942,4 +956,7 @@ 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); +int cxl_do_maintenance(struct cxl_dev_state *cxlds, + u8 class, u8 subclass, + void *data_in, size_t data_in_size); #endif /* __CXL_MEM_H__ */