From patchwork Thu Feb 13 09:15:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vinayak Holikatti X-Patchwork-Id: 13974720 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DEE6221DAD for ; Fri, 14 Feb 2025 10:23:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739528604; cv=none; b=e90i+x3VEzg16mY0MUP2/bklnizdURKi018RWnOq2AmDUZYin0NwQJ5ge32258PyfOhc0QnVAHQ0dzbx8k4T7a0EReJ1BkCwtnFqsoAI0+Nrh7NeGldu3SiLDjlMCuDj73sGLzeUDlYaNi7WRuZcKkm/HlUJwrpyKH7OwyXH6d4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739528604; c=relaxed/simple; bh=rvKM9PWc4R8j2H0bUbv18YspzAOl/dm683Y7SuuN7jI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=ifUWEWs5SQPFB+M9vwSrYyd6XtRXu5g9WrxupH9RyJZLPSA/Qphrb4umpF2NfzRUtYqaNX3CLBzVHMC3pbxPCYwL0ThxL+9puQ81qraURCSPU9AcTOz2DDuOQBJQSNhzoWX4Ne3KJGNUDDXT17pjlr9df0psSZi0hCvL3CgKPDg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=o0fY1m5N; arc=none smtp.client-ip=203.254.224.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="o0fY1m5N" Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20250214102319epoutp0327b35c7ec622efb3a5c2930b1b6f2e6c~kDAtoTuGJ1559215592epoutp03Y for ; Fri, 14 Feb 2025 10:23:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20250214102319epoutp0327b35c7ec622efb3a5c2930b1b6f2e6c~kDAtoTuGJ1559215592epoutp03Y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1739528599; bh=Y+YmI6Fv+4dx1jCNiVWWElBmtPS0hoZA2vg6Skzhh8I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o0fY1m5N2lpQ6hO/7ao1jN3kIbbD1i2Vrs/3N4wj1wkeUpp0Yy9ePaR56toLzIs3T D1+t5+1uFzTvNWbcSfShRaek0XKeNlw03Ix7SNX/sjeg9q2qHqO+nWN8zUULGIcS9g 5mtFuNDpeIGr/GmcBC100XQiGimWD0F94MdoYIcM= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20250214102318epcas5p1ae926a25ac7b6b81a517169295d58415~kDAtBYSiH0495704957epcas5p1j; Fri, 14 Feb 2025 10:23:18 +0000 (GMT) Received: from epsmges5p2new.samsung.com (unknown [182.195.38.178]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4YvSn03PSxz4x9Pt; Fri, 14 Feb 2025 10:23:16 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p2new.samsung.com (Symantec Messaging Gateway) with SMTP id 9B.B5.19933.4991FA76; Fri, 14 Feb 2025 19:23:16 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20250213091631epcas5p12bc4ff8f6f3498f400cf5f2cb1a42e96~judGrUT3r1560415604epcas5p11; Thu, 13 Feb 2025 09:16:31 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20250213091631epsmtrp1cf59accc57012985e3c9bcadf7285db1~judGqhZpE2265622656epsmtrp1f; Thu, 13 Feb 2025 09:16:31 +0000 (GMT) X-AuditID: b6c32a4a-b87c770000004ddd-f4-67af199452a3 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id 44.94.33707.F68BDA76; Thu, 13 Feb 2025 18:16:31 +0900 (KST) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20250213091629epsmtip1e54855622dae06f776471d16077ffced~judFQq1Cr2264222642epsmtip1r; Thu, 13 Feb 2025 09:16:29 +0000 (GMT) From: Vinayak Holikatti To: qemu-devel@nongnu.org Cc: gost.dev@samsung.com, linux-cxl@vger.kernel.org, nifan.cxl@gmail.com, dave@stgolabs.net, vishak.g@samsung.com, krish.reddy@samsung.com, a.manzanares@samsung.com, alok.rathore@samsung.com, Vinayak Holikatti Subject: [PATCH v2 2/3] hw/cxl: factor out calculation of sanitize duration from cmd_santize_overwrite Date: Thu, 13 Feb 2025 14:45:57 +0530 Message-Id: <20250213091558.2294806-3-vinayak.kh@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250213091558.2294806-1-vinayak.kh@samsung.com> Precedence: bulk X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprNJsWRmVeSWpSXmKPExsWy7bCmpu4UyfXpBi/f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ta9ZHFwIs/aOexsu8KT5HdqTeqP cbz6T4mlOCPRUIu5qDgRAKNOHPn3AgAA X-CMS-MailID: 20250213091631epcas5p12bc4ff8f6f3498f400cf5f2cb1a42e96 X-Msg-Generator: CA X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250213091631epcas5p12bc4ff8f6f3498f400cf5f2cb1a42e96 References: <20250213091558.2294806-1-vinayak.kh@samsung.com> Move the code of calculation of sanitize duration into function for usability by other sanitize routines Estimate times based on: https://pmem.io/documents/NVDIMM_DSM_Interface-V1.8.pdf Signed-off-by: Davidlohr Bueso Signed-off-by: Vinayak Holikatti --- hw/cxl/cxl-mailbox-utils.c | 61 ++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index fa38ecf507..d58c20842f 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -1656,34 +1656,10 @@ static void __do_sanitization(CXLType3Dev *ct3d) cxl_discard_all_event_records(&ct3d->cxl_dstate); } -/* - * CXL r3.1 Section 8.2.9.9.5.1: Sanitize (Opcode 4400h) - * - * Once the Sanitize command has started successfully, the device shall be - * placed in the media disabled state. If the command fails or is interrupted - * by a reset or power failure, it shall remain in the media disabled state - * until a successful Sanitize command has been completed. During this state: - * - * 1. Memory writes to the device will have no effect, and all memory reads - * will return random values (no user data returned, even for locations that - * the failed Sanitize operation didn’t sanitize yet). - * - * 2. Mailbox commands shall still be processed in the disabled state, except - * that commands that access Sanitized areas shall fail with the Media Disabled - * error code. - */ -static CXLRetCode cmd_sanitize_overwrite(const struct cxl_cmd *cmd, - uint8_t *payload_in, - size_t len_in, - uint8_t *payload_out, - size_t *len_out, - CXLCCI *cci) +static int get_sanitize_duration(uint64_t total_mem) { - CXLType3Dev *ct3d = CXL_TYPE3(cci->d); - uint64_t total_mem; /* in Mb */ - int secs; + int secs = 0; - total_mem = (ct3d->cxl_dstate.vmem_size + ct3d->cxl_dstate.pmem_size) >> 20; if (total_mem <= 512) { secs = 4; } else if (total_mem <= 1024) { @@ -1712,6 +1688,39 @@ static CXLRetCode cmd_sanitize_overwrite(const struct cxl_cmd *cmd, secs = 240 * 60; /* max 4 hrs */ } + return secs; +} + +/* + * CXL r3.1 Section 8.2.9.9.5.1: Sanitize (Opcode 4400h) + * + * Once the Sanitize command has started successfully, the device shall be + * placed in the media disabled state. If the command fails or is interrupted + * by a reset or power failure, it shall remain in the media disabled state + * until a successful Sanitize command has been completed. During this state: + * + * 1. Memory writes to the device will have no effect, and all memory reads + * will return random values (no user data returned, even for locations that + * the failed Sanitize operation didn’t sanitize yet). + * + * 2. Mailbox commands shall still be processed in the disabled state, except + * that commands that access Sanitized areas shall fail with the Media Disabled + * error code. + */ +static CXLRetCode cmd_sanitize_overwrite(const struct cxl_cmd *cmd, + uint8_t *payload_in, + size_t len_in, + uint8_t *payload_out, + size_t *len_out, + CXLCCI *cci) +{ + CXLType3Dev *ct3d = CXL_TYPE3(cci->d); + uint64_t total_mem; /* in Mb */ + int secs; + + total_mem = (ct3d->cxl_dstate.vmem_size + ct3d->cxl_dstate.pmem_size) >> 20; + secs = get_sanitize_duration(total_mem); + /* EBUSY other bg cmds as of now */ cci->bg.runtime = secs * 1000UL; *len_out = 0;