From patchwork Fri Nov 1 09:17:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13858962 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 AFE90CEB2DF for ; Fri, 1 Nov 2024 09:18:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F51E6B0095; Fri, 1 Nov 2024 05:18:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 350786B0096; Fri, 1 Nov 2024 05:18:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CB826B0098; Fri, 1 Nov 2024 05:18:11 -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 EE1A16B0095 for ; Fri, 1 Nov 2024 05:18:10 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6E180141A01 for ; Fri, 1 Nov 2024 09:18:10 +0000 (UTC) X-FDA: 82736974152.16.7B40016 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf22.hostedemail.com (Postfix) with ESMTP id C30F9C0003 for ; Fri, 1 Nov 2024 09:17:33 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.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=1730452528; 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=4RSBRIfhzmkRjmTComztAIOpv8cIji8WwvjBHHp8wyc=; b=WWsGc9+GCHZYHEG0+6GkbrIFCf74o1OrKU+jkAhWdeQP4HaYWM9+fFl+FFBqyuOF6CUibd DPFtjaehjgMD+09VjZW6n0XTrunN+m2jrsYjuMyzfO8sNyI8Ge9Mmlau7Xyz5qU1PY8HR/ EOvXuWMvsFxe5XXktKuPJL0b+X59e+o= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.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=1730452528; a=rsa-sha256; cv=none; b=ISENaLaJXrmznlqCKQV/yoGdtzoLLEZ/ktmQ5SrSOpJG/+sov+S/FCZOFoJFMi0NIBhykH Z9FQp5qtSe1GNvKVj8b545V+D7FECDtNdGAxPy2YuMW1uyy2Tq6JwL9B4MVgKU1ETILkhE SNj5g+Trk5kbVhqx9mH/vcjS58doSiE= Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XfwFM6rzFz6K6Qm; Fri, 1 Nov 2024 17:15:35 +0800 (CST) Received: from frapeml500007.china.huawei.com (unknown [7.182.85.172]) by mail.maildlp.com (Postfix) with ESMTPS id D2066140A36; Fri, 1 Nov 2024 17:18:06 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.126.171.129) 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; Fri, 1 Nov 2024 10:18:04 +0100 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v15 06/15] cxl/mbox: Add SET_FEATURE mailbox command Date: Fri, 1 Nov 2024 09:17:24 +0000 Message-ID: <20241101091735.1465-7-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20241101091735.1465-1-shiju.jose@huawei.com> References: <20241101091735.1465-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.126.171.129] X-ClientProxiedBy: lhrpeml500004.china.huawei.com (7.191.163.9) To frapeml500007.china.huawei.com (7.182.85.172) X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: C30F9C0003 X-Stat-Signature: emzcnf7k39xzqid3cxnthwes74aqzxwq X-Rspam-User: X-HE-Tag: 1730452653-91288 X-HE-Meta: U2FsdGVkX1/GRjnNvMjMGHZS4kx3yXrPZxfwI9ihOA+HqR2ig8sh7UGPhoFgRX8NTdQplsutxZ/K5QBo/4hpkXQOnewEJs83bjrTYhpF43cEVI4zZn7+mxGZsFFhaeU7dGvqyCW2iRI40n5G8Iz0Hf7I5BNUw5YQ8Kv+J6HvxQ+1hudaAc/CuX+i8B0gVuThDRDfasq0Q0hB5e+y1tRN0GMMPBbPND+UBo3/OC+52P8B4YByVaf40t/0WfslrGWi+oJG4g13OTP1+FldwQeZRI3wOGm3Qbfx+9XcbkcinqAfnamYm9uA9yEyXB2heH2x6TdKJyhlAo1OCWZuJyrlgc32J0AfzOqT9YZcK4XMrQ71PORUW7GNkqjJIJ+l2+mw1neFU13f+w8HDiXcGItHhB8l7HHMiCRhEujacP3tAZMB6POV9IJVnVeBFogiKIq63n97OrYU5xJLKztunBBoyrhVQwCVHQF1WQxYP8EVnVUXRcLn3hdaZbnqdp3la7PeWV/nO99mEMPTz6jJyemy5x8+DzCrcC188NMqR5/0NwOx5FgYljQz7U5V3LdCEhfLPBgtptkvZm/2EwZqR+PFsv/hkpdCSinUgdLnyGcYg7PvV6jAYKX3o+q1lV/ZJFPPnMXEQHOdqWqhIJfp0923bJfHUmfWyUkfrRbfK5YX4/WWpTR/54rdjGzpqOh2QTBHI6yhlqyBs1CP3SQ6+ucV6n0Dbae/y/z+MVuxf+o6tyRLRw3Ve4Gnczs68UsbZWbHw22LIWspR+txDkrhdsIgHirUwb9KmN1Ha5dJYPxYnwZ30HBYavLkX6lgzJZV5z+SmY/uUnGjZLfC8M2i5G9o+VPwcsyQlV2zabBoU/a9EvB6QmyLzaW94Dtws42oU/6ZBizYJhhPLWbJO6wAe1vz09qtPOkYqdS7+p4krK9MJ0rWtQ8twKJuULw+dsuKY6fI7ci6ExVTXSJYjJB2/A5 u1d1T4sa 2VqZH9Qhw2in6yP2sckbiUvh2o4uSoplXuxwnV3HQUhdZl0tvd7MlK0KA648yElA8H71Wb/GEE6oLC6vR4rDGcn+Bn49iGnEZhhdKYmSZigRRgI38XUjidRgTA1ASNl0WaQBR+Hod7Bkd4UlOi7sdNah5e2a6Glrb/7IpfAEqZJtAXx/w5ABsglQyW7ZPm275x1lBHzht7dgFQPuBdEjQ+jJ06SwKEeyh8MCSZ9e2TPvsnmDvOJ6ejmti0IkjePqB/7ZCqvmVu/aj+6enUkWO8bQxZKBjhX/Bqzok 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 support 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. Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang 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 3cd4bce2872d..4b9e62de164b 100644 --- a/drivers/cxl/core/mbox.c +++ b/drivers/cxl/core/mbox.c @@ -1011,6 +1011,79 @@ size_t cxl_get_feature(struct cxl_memdev_state *mds, 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_memdev_state *mds, + const uuid_t feat_uuid, u8 feat_version, + void *feat_data, size_t feat_data_size, + u8 feat_flag) +{ + struct cxl_mailbox *cxl_mbox = &mds->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 0c152719669a..fb356be8b426 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, @@ -879,6 +880,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); @@ -945,4 +975,8 @@ int cxl_get_supported_feature_entry(struct cxl_memdev_state *mds, const uuid_t * 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); #endif /* __CXL_MEM_H__ */