From mboxrd@z Thu Jan 1 00:00:00 1970 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 436DEC3ABBF for ; Thu, 8 May 2025 00:20:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uCoyZ-000607-0L; Wed, 07 May 2025 20:18:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uCoyW-0005zj-Sy for qemu-devel@nongnu.org; Wed, 07 May 2025 20:18:56 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uCoyU-0006ve-Uh for qemu-devel@nongnu.org; Wed, 07 May 2025 20:18:56 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-72d3b48d2ffso577154b3a.2 for ; Wed, 07 May 2025 17:18:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1746663533; x=1747268333; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z6cBqkRIN/p93Mp6T+47qwI49pgayI1pu+8Iku9SCaA=; b=l+1KCMsV573RAAnY0N2XRD4kPOgHDAg0r3ct9EYCFDx1la41jO1sMqAQyhje4t2x3P hzSZotbER5xHLKxoE/0EixyEzqwj32D5iFndO47n/ZQBeLULRZP7A7pGB3D//ujQujap YkLV1AOUlRzY5gJRXdE9y6WQLLPK8ySClZOb2zEEfsCscq48/68xH1AXywom7XdHi11B S3eR0pCsl+GQ+8lvqqZCC4rZA6rZIwe58NMpBxDVuMWPDaIH0ExuVtxP7ZDXbxQz7R2q f1e2R3rGDlYbbMlueqpxxTY6TesolQ6ZZY7eDkoWm/8RFyn+N91krZxx+zvh0891BI8C PRrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1746663533; x=1747268333; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z6cBqkRIN/p93Mp6T+47qwI49pgayI1pu+8Iku9SCaA=; b=B7sDJkVlIhxSbTyJvj4viMNnJxBGTdtarTdUg0uZ0u8TKOoM0JQKsV8FPF8qns39Wj dp/SDUEsmedShHo7XLMLATLpjp4F/uEt8xzCLeHSjWokq/k0kbfJLoWjdSjrJrhpKiCU 19HcPPWiRb4Ru8cSf7BXKp+9DkpQOnACk5To2b5r8nECL7sbv0fdGMDOjRZGnENQP5Bx QpH9i3iyDNlY31LP6Opx/q1+jYWGlsRMGJuX6a0PVUMGRhA43Imwbcb2yqohRsff50GS 4jyUhh2ab7gRwJ5fsOTf57Ze7xcSm3kdS2anihWci57W6oXzJd3yMxmY//NbtudNQ0XE Bbng== X-Gm-Message-State: AOJu0Yw7DvCsuY0tuNvEuqYyFnKNAWqki4l3XrvPUJNEw5qqC7bnbWcv 7pHBCIviFTYC6sg08EdSRZF03IlYNgeXN6/o/xmqlWDeUjN/4rqbyWkCNw== X-Gm-Gg: ASbGncsacN7HnI/OqRDhv/FpCp4fPuSNrpsTZOQ0iKxOUc9O9rziYVJ/Jkm8N+Bg7YX 5RiJP0/oFYiGk2Wj6+AkcPLtovAfSx+I8K0aHdY8aacHn/DnynWkYENpAsJIOpNKZ4DqbArD0WE 7oGxUSovbmedMiAAzdWiiXMQ96m6AYPt+L3Wv1xxv9Rsunb8iYlKeh5pHPZVjLZgFa0Ja3SEriO CpdBVAPmBmjgcnq0IuItQRfWgHzp2MsX8gDJJ4JVWyJLS+imAoFY93EgryGuTElIQhdv8c2A0x6 zppWiJKe8gRivG+gEY8OlSjGiQCfv+zMPlLBuiuKYkYysv26v19zNpaYr6NZLA== X-Google-Smtp-Source: AGHT+IFtkrcVBX6ObZonU424FPrWqjFZpGx77nj+3pAk9SRgQxByIsqorta/xrxBeb2ObdUJyUJqsA== X-Received: by 2002:a05:6a00:2e0e:b0:740:9d6f:a73b with SMTP id d2e1a72fcca58-7409d6fa83bmr6306683b3a.17.1746663533512; Wed, 07 May 2025 17:18:53 -0700 (PDT) Received: from deb-101020-bm01.dtc.local ([149.97.161.244]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7405902167csm12378724b3a.98.2025.05.07.17.18.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 May 2025 17:18:53 -0700 (PDT) From: anisa.su887@gmail.com To: qemu-devel@nongnu.org Cc: Jonathan.Cameron@huawei.com, nifan.cxl@gmail.com, dave@stgolabs.net, linux-cxl@vger.kernel.org, Anisa Su Subject: [PATCH v2 07/10] cxl-mailbox-utils: 0x5602 - FMAPI Set DC Region Config Date: Thu, 8 May 2025 00:01:03 +0000 Message-ID: <20250508001754.122180-8-anisa.su887@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250508001754.122180-1-anisa.su887@gmail.com> References: <20250508001754.122180-1-anisa.su887@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=anisa.su887@gmail.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Anisa Su FM DCD Management command 0x5602 implemented per CXL r3.2 Spec Section 7.6.7.6.3 Signed-off-by: Anisa Su --- hw/cxl/cxl-mailbox-utils.c | 97 ++++++++++++++++++++++++++++++++++++ hw/mem/cxl_type3.c | 2 +- include/hw/cxl/cxl_device.h | 3 ++ include/hw/cxl/cxl_mailbox.h | 6 +++ include/hw/cxl/cxl_opcodes.h | 1 + 5 files changed, 108 insertions(+), 1 deletion(-) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index 6afc45833d..fe38a13f71 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -3426,6 +3426,96 @@ static CXLRetCode cmd_fm_get_host_dc_region_config(const struct cxl_cmd *cmd, return CXL_MBOX_SUCCESS; } +static void cxl_mbox_dc_event_create_record_hdr(CXLType3Dev *ct3d, + CXLEventRecordHdr *hdr) +{ + /* + * CXL r3.1 section 8.2.9.2.1.6: Dynamic Capacity Event Record + * + * All Dynamic Capacity event records shall set the Event Record Severity + * field in the Common Event Record Format to Informational Event. All + * Dynamic Capacity related events shall be logged in the Dynamic Capacity + * Event Log. + */ + uint8_t flags = 1 << CXL_EVENT_TYPE_INFO; + + st24_le_p(&hdr->flags, flags); + hdr->length = sizeof(struct CXLEventDynamicCapacity); + memcpy(&hdr->id, &dynamic_capacity_uuid, sizeof(hdr->id)); + stq_le_p(&hdr->timestamp, cxl_device_get_timestamp(&ct3d->cxl_dstate)); +} + +/* CXL r3.2 section 7.6.7.6.3: Set Host DC Region Configuration (Opcode 5602) */ +static CXLRetCode cmd_fm_set_dc_region_config(const struct cxl_cmd *cmd, + uint8_t *payload_in, + size_t len_in, + uint8_t *payload_out, + size_t *len_out, + CXLCCI *cci) +{ + struct { + uint8_t reg_id; + uint8_t rsvd[3]; + uint64_t block_sz; + uint8_t flags; + uint8_t rsvd2[3]; + } QEMU_PACKED *in = (void *)payload_in; + CXLType3Dev *ct3d = CXL_TYPE3(cci->d); + CXLEventDynamicCapacity dcEvent = {}; + CXLDCRegion *region; + + region = &ct3d->dc.regions[in->reg_id]; + + /* + * CXL r3.2 7.6.7.6.3: Set DC Region Configuration + * This command shall fail with Unsupported when the Sanitize on Release + * field does not match the region’s configuration... and the device + * does not support reconfiguration of the Sanitize on Release setting. + * + * Currently not reconfigurable, so always fail if sanitize bit + * doesn't match. + */ + if ((in->flags & 0x1) != (region->flags & 0x1)) { + return CXL_MBOX_UNSUPPORTED; + } + + if (in->reg_id >= DCD_MAX_NUM_REGION) { + return CXL_MBOX_UNSUPPORTED; + } + + /* Check that no extents are in the region being reconfigured */ + if (!bitmap_empty(region->blk_bitmap, region->len / region->block_size)) { + return CXL_MBOX_UNSUPPORTED; + } + + /* Check that new block size is supported */ + if (!test_bit(BIT((int) log2(in->block_sz)), + ®ion->supported_blk_size_bitmask)) { + return CXL_MBOX_INVALID_INPUT; + } + + /* Free bitmap and create new one for new block size. */ + qemu_mutex_lock(®ion->bitmap_lock); + g_free(region->blk_bitmap); + region->blk_bitmap = bitmap_new(region->len / in->block_sz); + qemu_mutex_unlock(®ion->bitmap_lock); + region->block_size = in->block_sz; + + /* Create event record and insert into event log */ + cxl_mbox_dc_event_create_record_hdr(ct3d, &dcEvent.hdr); + dcEvent.type = DC_EVENT_REGION_CONFIG_UPDATED; + dcEvent.validity_flags = 1; + dcEvent.host_id = 0; + dcEvent.updated_region_id = in->reg_id; + + if (cxl_event_insert(&ct3d->cxl_dstate, + CXL_EVENT_TYPE_DYNAMIC_CAP, + (CXLEventRecordRaw *)&dcEvent)) { + cxl_event_irq_assert(ct3d); + } + return CXL_MBOX_SUCCESS; +} + static const struct cxl_cmd cxl_cmd_set[256][256] = { [INFOSTAT][BACKGROUND_OPERATION_ABORT] = { "BACKGROUND_OPERATION_ABORT", cmd_infostat_bg_op_abort, 0, 0 }, @@ -3552,6 +3642,13 @@ static const struct cxl_cmd cxl_cmd_set_fm_dcd[256][256] = { cmd_fm_get_dcd_info, 0, 0 }, [FMAPI_DCD_MGMT][GET_HOST_DC_REGION_CONFIG] = { "GET_HOST_DC_REGION_CONFIG", cmd_fm_get_host_dc_region_config, 4, 0 }, + [FMAPI_DCD_MGMT][SET_DC_REGION_CONFIG] = { "SET_DC_REGION_CONFIG", + cmd_fm_set_dc_region_config, 16, + (CXL_MBOX_CONFIG_CHANGE_COLD_RESET | + CXL_MBOX_CONFIG_CHANGE_CONV_RESET | + CXL_MBOX_CONFIG_CHANGE_CXL_RESET | + CXL_MBOX_IMMEDIATE_CONFIG_CHANGE | + CXL_MBOX_IMMEDIATE_DATA_CHANGE) }, }; /* diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index b5b3df5edf..edc29f1ccb 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -1695,7 +1695,7 @@ void qmp_cxl_inject_correctable_error(const char *path, CxlCorErrorType type, pcie_aer_inject_error(PCI_DEVICE(obj), &err); } -static void cxl_assign_event_header(CXLEventRecordHdr *hdr, +void cxl_assign_event_header(CXLEventRecordHdr *hdr, const QemuUUID *uuid, uint32_t flags, uint8_t length, uint64_t timestamp) { diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index 9cfd9c5a9f..22823e2054 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -821,4 +821,7 @@ void ct3_clear_region_block_backed(CXLType3Dev *ct3d, uint64_t dpa, uint64_t len); bool ct3_test_region_block_backed(CXLType3Dev *ct3d, uint64_t dpa, uint64_t len); +void cxl_assign_event_header(CXLEventRecordHdr *hdr, + const QemuUUID *uuid, uint32_t flags, + uint8_t length, uint64_t timestamp); #endif diff --git a/include/hw/cxl/cxl_mailbox.h b/include/hw/cxl/cxl_mailbox.h index 8e1c7c5f15..820c411cbb 100644 --- a/include/hw/cxl/cxl_mailbox.h +++ b/include/hw/cxl/cxl_mailbox.h @@ -8,6 +8,7 @@ #ifndef CXL_MAILBOX_H #define CXL_MAILBOX_H +#define CXL_MBOX_CONFIG_CHANGE_COLD_RESET (1) #define CXL_MBOX_IMMEDIATE_CONFIG_CHANGE (1 << 1) #define CXL_MBOX_IMMEDIATE_DATA_CHANGE (1 << 2) #define CXL_MBOX_IMMEDIATE_POLICY_CHANGE (1 << 3) @@ -15,6 +16,11 @@ #define CXL_MBOX_SECURITY_STATE_CHANGE (1 << 5) #define CXL_MBOX_BACKGROUND_OPERATION (1 << 6) #define CXL_MBOX_BACKGROUND_OPERATION_ABORT (1 << 7) +#define CXL_MBOX_SECONDARY_MBOX_SUPPORTED (1 << 8) +#define CXL_MBOX_REQUEST_ABORT_BACKGROUND_OP_SUPPORTED (1 << 9) +#define CXL_MBOX_CEL_10_TO_11_VALID (1 << 10) +#define CXL_MBOX_CONFIG_CHANGE_CONV_RESET (1 << 11) +#define CXL_MBOX_CONFIG_CHANGE_CXL_RESET (1 << 12) #define CXL_LOG_CAP_CLEAR_SUPPORTED (1 << 0) #define CXL_LOG_CAP_POPULATE_SUPPORTED (1 << 1) diff --git a/include/hw/cxl/cxl_opcodes.h b/include/hw/cxl/cxl_opcodes.h index 68ad68291c..ed4be23b75 100644 --- a/include/hw/cxl/cxl_opcodes.h +++ b/include/hw/cxl/cxl_opcodes.h @@ -64,5 +64,6 @@ enum { FMAPI_DCD_MGMT = 0x56, #define GET_DCD_INFO 0x0 #define GET_HOST_DC_REGION_CONFIG 0x1 + #define SET_DC_REGION_CONFIG 0x2 GLOBAL_MEMORY_ACCESS_EP_MGMT = 0X59 }; -- 2.47.2