From patchwork Wed Oct 9 12:41:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13828310 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 C77EBCEDD8F for ; Wed, 9 Oct 2024 12:43:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 183FB6B00E0; Wed, 9 Oct 2024 08:43:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 134996B00E1; Wed, 9 Oct 2024 08:43:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0D236B00E2; Wed, 9 Oct 2024 08:43:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 995496B00E0 for ; Wed, 9 Oct 2024 08:43:29 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5309F813FD for ; Wed, 9 Oct 2024 12:43:27 +0000 (UTC) X-FDA: 82654029738.25.1A716B2 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf24.hostedemail.com (Postfix) with ESMTP id 508FC180014 for ; Wed, 9 Oct 2024 12:43:27 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.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=1728477763; 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=ss4ZPbnHnoWtGtVFDDacAveL2wOTnVrUSvXa7143Wt0=; b=U6AfOitNEZoHreC5NWKkqe52/5mCkOD6PJDHVNmm6wE00aoKZtunmFbPclK23OCsI6eNYi ysL/Zj0ELERp+xEGMA3WX94VTds/01Y6vHiRJ279EfEfghDIiTg9+JYDoTZoC1O6fFW0US oogLw6qHG/NQW6NRnT4+/hRVA2pym+8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.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=1728477764; a=rsa-sha256; cv=none; b=AFkMETnPYCzlbSr7OmTQQsDo2btJa3pN0f/DIieZixOXhYHcgBWxuKL1Izlpd2x+4wGgpS ggkGiLKyOU495hRCkkR0nQbWotnuZATC+MvTxTid4OF3wF6LA3j5y+fZpF69rCPO3XAxxp WxDnOP6ezZWeZ7aYOBvbS0AFww+ghfA= Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XNsrp2Svdz6GFK0; Wed, 9 Oct 2024 20:39:06 +0800 (CST) Received: from frapeml500007.china.huawei.com (unknown [7.182.85.172]) by mail.maildlp.com (Postfix) with ESMTPS id 8769C140133; Wed, 9 Oct 2024 20:43:25 +0800 (CST) Received: from P_UKIT01-A7bmah.china.huawei.com (10.48.152.209) 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, 9 Oct 2024 14:43:23 +0200 From: To: , , , , CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v13 09/18] cxl/mbox: Add SET_FEATURE mailbox command Date: Wed, 9 Oct 2024 13:41:10 +0100 Message-ID: <20241009124120.1124-10-shiju.jose@huawei.com> X-Mailer: git-send-email 2.43.0.windows.1 In-Reply-To: <20241009124120.1124-1-shiju.jose@huawei.com> References: <20241009124120.1124-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.48.152.209] 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: 6xkggj1453rgoda1oor87firiyph5qgm X-Rspamd-Queue-Id: 508FC180014 X-Rspamd-Server: rspam11 X-HE-Tag: 1728477807-706685 X-HE-Meta: U2FsdGVkX1/G9WOmXxTVTsEd+WUkuAGUXVYEgbsDEkKmsYObIUAaYI28KmOo5rwz/sBgVVUGAvBI2/ooR5ghEnnMnPNimS0/YxmdokLE8ewcWh/0tqaAjlwuJ8xdlfZCD8UvRVWxfb+d95JOlKJ6zlRHk6rkeG2BuQ40sXEwvIq0xDNPZ82FoPEjNzv+4xje0WmDlYdHP4M0VXJLxW0BmysraqDQqqTdJcawqKM7zwJuCBZqNqIOwAGpVslVqOA53z1xmQJZSoWUIIfJCcFxBKdrCaWwkXeCbKrKUIaW0ap0n2Wnj5529n0rE5mVY8VAPaoydcoy1MuYfvBXKsylWR5FrzbH41OJe/aQLU6SxmfNccBgBGICChMBQbua86xaKVhg3WxWYLlBFBo57LR0ozvNT7LAXE4twhmJZddSV8sVB4t8UwuMvtVoRdWieLZTj2vLvbv8AqXw1RcMvpx9vNXqb5CQtz0jNuqCibi7PeA/Y3loOf2bZjyZi7EXLLU9cBbNNidD9GSwiFi4vr3Wl0OMNycOf+ty/MZqq3oWqAYuxgroqaoDKFkgkQ3c2omF1pqf8WUwiWCEE156G+AGlumC+4V0V9+YK19ZRDWsjq8feXnHk/LK0b5zCqUY5w9bBM9/qpSfvjC8PWP9F2IL6KorwHo3++nU6OgAu4E7FqM8BZ47CeNT52n5b2UaZqFO5XgNZ1bMVJYJ9UKBsGOwcXw+QjElWsVxtZiiRxxrWqdhHhQOVSE8mjb4ZmApjPIUBqktT6jDXtt0891iunRGZ0nJ/ICnd9IgTapwfFAaKOkWD7JubRy+CJFIh6Is2FFORLRpKArcq3Z298lYhuuOndhVz4XFnSSBZrY3oppoWN4tQEw7Dn8FNYbbK3qjFAAxV/BPayjVe5vNCe26kkXUzANNnUSJoJnqBbGaV0MWFpunbyL8sQyzOxnHEchDicwEiWGH73IfD+PYbTSXRfS 2YsLuaKO 0wm+GYqqW/mDisNkcLGdalubVIc04IehBa4kfvq9VaUmaNa6o8MJ7UfisUa3YbIdzCBJ3Oe1KOrTRdQmDMd31XBQRUgsYRNrzzKCQdjHYHfHqC0UUu0f4uLX+LA/v/MYk040LAlEvxzAD0vgkOvs65DgRQaYEL7k1tu5l4renn0c03cdK/t+cOt3OaZxRCAxWYevQ7x+pHLvXDcUVo4OFuMHyRYB80nao9U52ZfKBgW/2zpDNnWrIn9gU8qktC1W9aKzjxkrs7+xNIRBfin4AWFieDDNyE64xOdAdU1uu6PrNp4g= 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. Signed-off-by: Shiju Jose Reviewed-by: Jonathan Cameron --- 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 eae374a90a9f..30c44ab11347 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 c7ad63597709..b778eef99ce0 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -530,6 +530,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, @@ -877,6 +878,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); @@ -943,4 +973,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__ */