From nobody Tue Dec 16 03:21:26 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1744086780; cv=none; d=zohomail.com; s=zohoarc; b=FXcTppf9qkjNXpDTaTlImMWIgf3WcQPWC8tXqicQ0bN6Ahx8NcUYT+yWF76KfVvSbT/Lig0/P/QUqlIjTxnwkHyUauY6faGs9oNfRmoL4wrN8CCbanufStZX0IcOZPBSPAK8ggMwehKA+bfi7WMhTs19+weJQO7lyacY+usDlkI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1744086780; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tFsyiFKRhSvGR0pMC95Wd+px084AVEIKUIaNuSDojhQ=; b=J4xeyPdN0LVhjYuNAYTh4UHUSRnY33bLPOVnCtbuUl+f+V/P5zHHk+iTPKMfwzp0CcNF577efcEQGj0DczSh/p4qUdMKzomPuqElkWp4nwoFqLYPxOD09agwfHXfExqQrYJIEDJntIvj5khz/AbMSEr7oKb2Xe81GhPdi1AI97o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1744086780158146.01471403431526; Mon, 7 Apr 2025 21:33:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u20d4-0006Tp-Tr; Tue, 08 Apr 2025 00:32:06 -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 1u20d2-0006TN-MW for qemu-devel@nongnu.org; Tue, 08 Apr 2025 00:32:04 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u20d0-0005cS-Rs for qemu-devel@nongnu.org; Tue, 08 Apr 2025 00:32:04 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-224341bbc1dso44682755ad.3 for ; Mon, 07 Apr 2025 21:32:02 -0700 (PDT) Received: from localhost.localdomain ([2601:646:8f03:9fee:5e33:e006:dcd5:852d]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2297865e0a9sm90055385ad.149.2025.04.07.21.31.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Apr 2025 21:32:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744086721; x=1744691521; 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=tFsyiFKRhSvGR0pMC95Wd+px084AVEIKUIaNuSDojhQ=; b=GBZBmQTDksfXRNESG07zJDqNmXMCTU0ZIl7Kedkh+IsgIe62sOFELZBByRZegg2zHX ftCUGXoNRPsekAvsUO/Dk9sld8jamo1LW7CygW6KBj0RspkAOEYfKN9tVzvWOAMMCoF6 nvNQJv/N6WicpulyIOCHgIQclIU+bDXu9IbS/yOl2q0dfCxIwyIh5lzoIVp8C3vR0XpE AaNbqpyhaKWX2eLZatCGQqhVyzcJQM8ScGas0zcrOlty81zut3mLcKt3PAtO+hAicUXS 4RuVYVn95bMJTvNzAeKkr0X+YauzEb/R/re34muFBoxY6aDWJtIWvdzxHoDruMlGSklz nubg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744086721; x=1744691521; 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=tFsyiFKRhSvGR0pMC95Wd+px084AVEIKUIaNuSDojhQ=; b=QnnOLpyx3dp2xhZ6whBhtoZXhq/LQH9YK6JGhQ+IwfqY9ZxCsmhkWZsFEq1ChjdgoK oVK6k2Hu2wz7T80qHpniQH1jUTJ3HkbIZOH9nYK9QnSOm55NXTc2/iK3ZDvsDwGdtfNw RWpZWJbytaEQgicGxflu/ZKl7IZwj9CPTHtx2thBKQ0inWvERjPi8lU6itQWBu6cZbqR 9ruLHdg7ri5ETYZ199fYl0KtDnIc+kI1NlYkP3CuZ76CBDa21D9rAyswAu620t1TQIxj KmoveUmIDe/59hsJRvWEy2rA1dDgdVVE9mE9fjUeRslnqrEOehFrtkWvpCXFNR4pcT7Z nz3Q== X-Forwarded-Encrypted: i=1; AJvYcCW9vVqqcpLpbiGXSZeGjC+L6tLdFi7Ot+t8Uv7cW01PAUdaEL4FO2sONeSyBCmlh4Uvhq4l56VYZ16J@nongnu.org X-Gm-Message-State: AOJu0YytBzfviKc8sFEKaJ5f/0xptL4KHzeBV7n+UWGK7HtKXsFObV52 2lDLmTZYdDmQ1m1rZE3Y1LmdBhPbtBaGNkQ/icTiur/+wKtrvFxm X-Gm-Gg: ASbGncsc5YjDjVG97fSC9pES3pZHs2LNUn4T0M/28+7/z6J+aBZCUkmGMubOmyarlUd hHHVlgoHHuHisyuwyiSWMdZZLg3K1RtmlQJlK/5oybBk6s6HQhp6KpMOqmR7vqlE6JlmijHTKDG Kyi8uLinB2zdlDfk0hDLgETX6Hb0/PWm4h0vsu1PGyOhjx/9n3bAl/iyz/Wz1c0eldSuWRTmZ71 O9w2NK/fXWLSVT93pOAmBfDXOkiOv8o9qrJb1967kYduiJxk0I5yxaFZ4vgDFPVuZIrSC0zsDcR jmMBzlHPbnJJ1EvdLGxGS+8b4QilXEloQG3vry/tLrgrT7g+PEkT+cjI400uVQ== X-Google-Smtp-Source: AGHT+IGGOYorAenJf9WDhLYuxrPuFrkDogX1/FSN2ZuwsnOPs6m3hMh2XFNgWY70xxDdmBZ82edybw== X-Received: by 2002:a17:902:f610:b0:223:3396:15e8 with SMTP id d9443c01a7336-22a9552b6damr173880685ad.22.1744086720905; Mon, 07 Apr 2025 21:32:00 -0700 (PDT) From: nifan.cxl@gmail.com To: jonathan.cameron@huawei.com, qemu-devel@nongnu.org Cc: linux-cxl@vger.kernel.org, a.manzanares@samsung.com, dave@stgolabs.net, nmtadam.samsung@gmail.com, nifan.cxl@gmail.com, anisa.su887@gmail.com, gourry@gourry.net, Fan Ni Subject: [RFC 1/3] cxl_type3: Preparing information sharing between VMs Date: Mon, 7 Apr 2025 21:20:28 -0700 Message-ID: <20250408043051.430340-2-nifan.cxl@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250408043051.430340-1-nifan.cxl@gmail.com> References: <20250408043051.430340-1-nifan.cxl@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=nifan.cxl@gmail.com; helo=mail-pl1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1744086787076019000 Content-Type: text/plain; charset="utf-8" From: Fan Ni Add two data structures for sharing information between multiple VMs. The global cci_map_buf is used to provide mappings between cci name and cci pointer. Each VM has its own cci_map_buf. However, since we expect the two VMs share the same configuration, the same CCI name should points to its own CCI. On the FM, we need to use the cci pointer to find the cci name. While on the test VM, we use the name to find cci pointer for MCTP message process. The mctp_shared_buffer is used to pass MCTP command information between FM and test VM for QMP command process. Signed-off-by: Fan Ni --- hw/mem/cxl_type3.c | 125 +++++++++++++++++++++++++++++- include/hw/cxl/cxl_device.h | 6 ++ include/hw/cxl/cxl_mctp_message.h | 40 ++++++++++ 3 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 include/hw/cxl/cxl_mctp_message.h diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 11c38a9292..7f85616ca1 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -29,6 +29,9 @@ #include "system/numa.h" #include "hw/cxl/cxl.h" #include "hw/pci/msix.h" +#include "hw/cxl/cxl_mctp_message.h" + +struct CXLCCINamePtrMaps *cci_map_buf; =20 /* type3 device private */ enum CXL_T3_MSIX_VECTOR { @@ -998,6 +1001,97 @@ static void init_alert_config(CXLType3Dev *ct3d) }; } =20 +static int ct3_mctp_buf_open(const char *filename, int flags) +{ + char name[128]; + snprintf(name, sizeof(name), "/%s", filename); + return shm_open(name, flags, 0666); +} + +static int ct3_mctp_buf_unlink(const char *filename) +{ + char name[128]; + snprintf(name, sizeof(name), "/%s", filename); + return shm_unlink(name); +} + +static struct CXLMCTPSharedBuf *ct3_mctp_buf_map(int fd, int size) +{ + void *map; + + if (fd < 0) { + return NULL; + } + + map =3D mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (map =3D=3D MAP_FAILED) { + return NULL; + } + + return (CXLMCTPSharedBuf *)map; +} + + +static int ct3_mctp_buf_create(const char *filename, size_t size) +{ + int fd, rc; + + fd =3D ct3_mctp_buf_open(filename, O_RDWR | O_CREAT); + if (fd =3D=3D -1) { + return -1; + } + + rc =3D ftruncate(fd, size); + + if (rc) { + close(fd); + return -1; + } + + return fd; +} + +static int ct3_setup_mctp_command_share_buffer(CXLType3Dev *ct3d, bool cre= ate) +{ + int fd; + int size =3D sizeof(*ct3d->mctp_shared_buffer); + sprintf(ct3d->mctp_buf_name, MCTP_MESSAGE_BUF_NAME); + + if (create) { + fd =3D ct3_mctp_buf_create(ct3d->mctp_buf_name, size); + } else { + fd =3D ct3_mctp_buf_open(ct3d->mctp_buf_name, O_RDWR | O_CREAT); + } + + if (fd =3D=3D -1) { + return fd; + } + ct3d->mctp_buf_fd =3D fd; + ct3d->mctp_shared_buffer =3D ct3_mctp_buf_map(ct3d->mctp_buf_fd, size); + if (ct3d->mctp_shared_buffer) { + return 0; + } + return -1; +} + +static int init_cci_name_ptr_mapping(void) +{ + if (!cci_map_buf) { + cci_map_buf =3D g_malloc(sizeof(*cci_map_buf)); + } + return 0; +} + +static void add_cci_name_ptr_mapping(const char *name, void *p) +{ + int n =3D cci_map_buf->num_mappings; + struct CXLCCINamePtrMap *map =3D &cci_map_buf->maps[n]; + + strcpy(map->cci_name, name); + map->cci_pointer =3D p; + cci_map_buf->num_mappings++; +} + void ct3_realize(PCIDevice *pci_dev, Error **errp) { ERRP_GUARD(); @@ -1108,6 +1202,14 @@ void ct3_realize(PCIDevice *pci_dev, Error **errp) ct3d->ecs_attrs.fru_attrs[count].ecs_flags =3D 0; } =20 + if (ct3d->allow_fm_attach) { + init_cci_name_ptr_mapping(); + if (ct3d->mctp_buf_init) { + ct3_setup_mctp_command_share_buffer(ct3d, true); + } else { + ct3_setup_mctp_command_share_buffer(ct3d, false); + } + } return; =20 err_release_cdat: @@ -1150,6 +1252,15 @@ void ct3_exit(PCIDevice *pci_dev) if (ct3d->hostvmem) { address_space_destroy(&ct3d->hostvmem_as); } + + if (ct3d->mctp_shared_buffer) { + munmap(ct3d->mctp_shared_buffer, sizeof(*ct3d->mctp_shared_buffer)= ); + close(ct3d->mctp_buf_fd); + ct3_mctp_buf_unlink(ct3d->mctp_buf_name); + ct3d->mctp_shared_buffer =3D NULL; + } + g_free(cci_map_buf); + cci_map_buf =3D NULL; } =20 /* @@ -1352,6 +1463,16 @@ void ct3d_reset(DeviceState *dev) } cxl_initialize_t3_ld_cci(&ct3d->ld0_cci, DEVICE(ct3d), DEVICE(ct3d), 512); /* Max payload made up */ + if (ct3d->allow_fm_attach) { + char name[64]; + + memset(name, 0, 64); + sprintf(name, "%lu:%s", ct3d->sn, "oob_mctp_cci"); + add_cci_name_ptr_mapping(name, &ct3d->oob_mctp_cci); + cxl_initialize_t3_fm_owned_ld_mctpcci(&ct3d->oob_mctp_cci, + DEVICE(ct3d), DEVICE(ct3d), + MCTP_CXL_MAILBOX_BYTES); + } } =20 static const Property ct3_props[] =3D { @@ -1372,7 +1493,9 @@ static const Property ct3_props[] =3D { speed, PCIE_LINK_SPEED_32), DEFINE_PROP_PCIE_LINK_WIDTH("x-width", CXLType3Dev, width, PCIE_LINK_WIDTH_16), - DEFINE_PROP_UINT16("chmu-port", CXLType3Dev, cxl_dstate.chmu[0].port, = 0),=20 + DEFINE_PROP_UINT16("chmu-port", CXLType3Dev, cxl_dstate.chmu[0].port, = 0), + DEFINE_PROP_BOOL("allow-fm-attach", CXLType3Dev, allow_fm_attach, fals= e), + DEFINE_PROP_BOOL("mctp-buf-init", CXLType3Dev, mctp_buf_init, false), }; =20 static uint64_t get_lsa_size(CXLType3Dev *ct3d) diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index ca515cab13..9a00ef7a1e 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -707,6 +707,12 @@ struct CXLType3Dev { } dc; =20 struct CXLSanitizeInfo *media_op_sanitize; + + bool allow_fm_attach; + bool mctp_buf_init; + struct CXLMCTPSharedBuf *mctp_shared_buffer; + char mctp_buf_name[64]; + int mctp_buf_fd; }; =20 #define TYPE_CXL_TYPE3 "cxl-type3" diff --git a/include/hw/cxl/cxl_mctp_message.h b/include/hw/cxl/cxl_mctp_me= ssage.h new file mode 100644 index 0000000000..85b3664cf7 --- /dev/null +++ b/include/hw/cxl/cxl_mctp_message.h @@ -0,0 +1,40 @@ +#ifndef CXL_MCTP_MESSAGE_H_H +#define CXL_MCTP_MESSAGE_H_H +#include + +#define MCTP_CXL_MAILBOX_BYTES 512 +#define MCTP_MESSAGE_BUF_NAME "mctp-message-buf" + +struct CXLMCTPCommandBuf { + /* uint8_t cci_name[64]; */ + uint8_t command_set; + uint8_t command; + size_t len_in; + size_t len_out; + uint8_t payload[MCTP_CXL_MAILBOX_BYTES]; + uint8_t payload_out[MCTP_CXL_MAILBOX_BYTES]; + bool bg_started; + int ret_val; +}; + +typedef struct CXLMCTPCommandBuf CXLMCTPCommandBuf; + +struct CXLCCINamePtrMap { + char cci_name[64]; + void *cci_pointer; /* This should be filled by the target VM */ +}; + +struct CXLCCINamePtrMaps { + int num_mappings; + struct CXLCCINamePtrMap maps[32]; +}; + +struct CXLMCTPSharedBuf { + /* set to 1 when sent to target VM and wait for 0 as it completes */ + int status; + CXLMCTPCommandBuf command_buf; +}; + +typedef struct CXLMCTPSharedBuf CXLMCTPSharedBuf; +extern struct CXLCCINamePtrMaps *cci_map_buf; +#endif --=20 2.47.2 From nobody Tue Dec 16 03:21:26 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1744086770; cv=none; d=zohomail.com; s=zohoarc; b=JxLzoJCk9ZGJY2jnJUzyCBi2ZmFIJoAh322Rb5riTaOTVL3UIy6cZvXablt5Ishv8qjs6PmjR+BwASrFkl14M02DuIAGL9PgnWToabfVN+K4CfS0UDQ3bhT0tY/e/bCqfN7zcJbA39GZzVOz2StvtqvZiZPXFlKHQrtsJf/AWNc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1744086770; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OIf6KRZsta6SFyUZqr4u0W6SgvBvMAQeL+UZ3/HECqo=; b=EqB1QGdS509FSwAxrc0GY8t9D/LHBLAOSPUAZ+9H3NAT0u70OKZ7fO3oN1cScvrIpblO1AVCDMEGM9lp5ehwcht/P3XWgOF65VbWc9XKjuxqM0bu5B0F4Lz/PaGMcrIHMw/+USnNEsMHq+yvqxJL9+dMJBQaePiKPbRoS585BO8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174408677086391.2873997243662; Mon, 7 Apr 2025 21:32:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u20d8-0006Uf-IA; Tue, 08 Apr 2025 00:32:10 -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 1u20d6-0006U2-EU for qemu-devel@nongnu.org; Tue, 08 Apr 2025 00:32:08 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u20d4-0005d8-FT for qemu-devel@nongnu.org; Tue, 08 Apr 2025 00:32:07 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-225477548e1so47446615ad.0 for ; Mon, 07 Apr 2025 21:32:06 -0700 (PDT) Received: from localhost.localdomain ([2601:646:8f03:9fee:5e33:e006:dcd5:852d]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2297865e0a9sm90055385ad.149.2025.04.07.21.32.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Apr 2025 21:32:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744086725; x=1744691525; 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=OIf6KRZsta6SFyUZqr4u0W6SgvBvMAQeL+UZ3/HECqo=; b=Wl4U1MHQ9zCb1mmtkkQhRXT8TZQN0wv6U4LI2MZAmz4rsp8EQCX82rCPh27p/xSQ9a a14HwvvZ0REnQezAHXV1TylGTZZEBTtPL3RWWazY6Dx+Tp6VEeuvb7ttobZJjgWLdnRl 2A/Aj726MmoWaVZdYCYrtmtSaJPew+5P0JqgcxLnQkqc4LLB1vme+4xa4NlGGYh6jtWe Vntcr4txdGGhRxxV9COPuf0ZMViKmqBX146NgLlNUdm5KYzRQhSQ2hQb7svlQzzMMUso SK8zOnNp5aYm2DMVplqJrpteP+9ZgZ+ml/Gv3t/8YLgsXDHu+nlnlGyWNZDg0xxIjxnd PFoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744086725; x=1744691525; 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=OIf6KRZsta6SFyUZqr4u0W6SgvBvMAQeL+UZ3/HECqo=; b=uInxg8UQn+RqmNxVO9wZROgUC4Kc/d20q2SDB9CmFOnITfC2APkTrmyKt6hfWiO0qp 9N3UikNhn1KSKyTX5PyOoB+nwwEwzGRZ56h9tonBrpFlLuVD4KJm68Fp8J9NpXQ6JutH pwQAaa/KG+uYgCD1JTHhK8osfBP+JYNWhKzeb3jp3GFGdIpzDEBwH/1BjqTGyqNbqapc Al0OzRL/3DAlneYz/7GOxrU8qmC+ZJxyPOn/7xr7tXnwwfLOIY73qMZ9qr9N/FoiCmd6 7ulkwe3cro1lX9qZDRJ2X8VjL8YRt1ZeGMKCQl4WckQRAkutLQ6kPy8mYlMXEfPw/jn9 nMrw== X-Forwarded-Encrypted: i=1; AJvYcCWXhOKOmpD7VJGkkjzSYnTJGVG/hXMGJR7Q50AO3/L20Gy1WdjV2N3ZrLhbnZll3uXBOAjGH0XTQMDa@nongnu.org X-Gm-Message-State: AOJu0Yx1L076c1Uo/cTMHSvWxvaI8WyyKdZQiBjXtCRiHXmnKu9ElgDB k0rSywkIP13h8MZvAd3EvrHKDwLvQ1tPVwIKJQAPvgkOQy/iddp6 X-Gm-Gg: ASbGncttHSwwevfov6lmw14LOHZaZiz1zCmMR8DhcuHcfXTejOrtZjJ9Ud8k5pHxtw6 nMH3LDGbzowij+YGnVt+IOK3rBCWU+hMiNI9BMhjlm6LLGcgDDD/VWeW5El/Q38/QlwSoTcBuOQ ol5xrjEMutCZyQZBWdElIYS52Xiw2RnBIIN24dsZCD4EktQ6+ketPuPQd71ZNuWQpVpKJ5cnSfC BpBXQsGAghlUYZ/lIQh8VmXwaF3TdFaJwCYPS0a/sVtHaTQDItgZ3+ZVShwS3JFsPZ37ZWOVqRv TS5oBMGp46dmtOU7RNaNXWK9VBzSLqSx/m0TI9HfDLChdK5GwBFZqk+qykB7zgY976CpIBeg X-Google-Smtp-Source: AGHT+IG95Srqv4+u+FHkRMxez0pgopseFoWm6fSASwQ6yjOyz+N/XBQF4kWBCIkYShUTM1WzudKcbQ== X-Received: by 2002:a17:903:2352:b0:224:c46:d162 with SMTP id d9443c01a7336-22a8a865a9cmr187371765ad.20.1744086725038; Mon, 07 Apr 2025 21:32:05 -0700 (PDT) From: nifan.cxl@gmail.com To: jonathan.cameron@huawei.com, qemu-devel@nongnu.org Cc: linux-cxl@vger.kernel.org, a.manzanares@samsung.com, dave@stgolabs.net, nmtadam.samsung@gmail.com, nifan.cxl@gmail.com, anisa.su887@gmail.com, gourry@gourry.net, Fan Ni Subject: [RFC 2/3] cxl_type3: Add qmp_cxl_process_mctp_message qmp interface Date: Mon, 7 Apr 2025 21:20:29 -0700 Message-ID: <20250408043051.430340-3-nifan.cxl@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250408043051.430340-1-nifan.cxl@gmail.com> References: <20250408043051.430340-1-nifan.cxl@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=nifan.cxl@gmail.com; helo=mail-pl1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1744086774700019100 Content-Type: text/plain; charset="utf-8" From: Fan Ni Add a new QAPI "qmp-cxl-process-mctp-message" to process the MCTP request cached in the shared buffer from FM VM. Signed-off-by: Fan Ni --- hw/mem/cxl_type3.c | 41 ++++++++++++++++++++++++++++++++++++++++ hw/mem/cxl_type3_stubs.c | 5 +++++ qapi/cxl.json | 18 ++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index 7f85616ca1..f7ac8e8da7 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -1614,6 +1614,47 @@ void cxl_clear_poison_list_overflowed(CXLType3Dev *c= t3d) ct3d->poison_list_overflow_ts =3D 0; } =20 +void qmp_cxl_process_mctp_message(const char *cci_name, Error **errp) +{ + int i; + struct CXLCCINamePtrMap *map; + struct CXLMCTPCommandBuf *buf; + CXLCCI *cci =3D NULL; + CXLType3Dev *ct3d; + + if (!cci_map_buf) { + error_setg(errp, "CCI name mapping buffer not setup"); + return; + } + + for (i =3D 0; i < cci_map_buf->num_mappings; i++) { + map =3D &cci_map_buf->maps[i]; + if (!strcmp(map->cci_name, cci_name)) { + cci =3D (CXLCCI *) map->cci_pointer; + break; + } + } + if (!cci) { + error_setg(errp, "CCI instance is not found with name: %s", cci_na= me); + return; + } + ct3d =3D CXL_TYPE3(OBJECT(cci->d)); + if (!ct3d) { + error_setg(errp, "No Type3 device associated with the cci"); + return; + } + if (ct3d->mctp_shared_buffer->status !=3D 1) { + error_setg(errp, "MCTP buffer status is not set to 1, skip"); + return; + } + buf =3D &ct3d->mctp_shared_buffer->command_buf; + buf->ret_val =3D cxl_process_cci_message(cci, buf->command_set, buf->c= ommand, + buf->len_in, buf->payload, + &buf->len_out, buf->payload_out, + &buf->bg_started); + ct3d->mctp_shared_buffer->status =3D 0; +} + void qmp_cxl_inject_poison(const char *path, uint64_t start, uint64_t leng= th, Error **errp) { diff --git a/hw/mem/cxl_type3_stubs.c b/hw/mem/cxl_type3_stubs.c index c1a5e4a7c1..dbf18f2af2 100644 --- a/hw/mem/cxl_type3_stubs.c +++ b/hw/mem/cxl_type3_stubs.c @@ -92,3 +92,8 @@ void qmp_cxl_release_dynamic_capacity(const char *path, u= int16_t host_id, { error_setg(errp, "CXL Type 3 support is not compiled in"); } + +void qmp_cxl_process_mctp_message(const char *cci_name, Error **errp) +{ + error_setg(errp, "CXL Type 3 support is not compiled in"); +} diff --git a/qapi/cxl.json b/qapi/cxl.json index dd947d3bbc..fcb1e0b3fd 100644 --- a/qapi/cxl.json +++ b/qapi/cxl.json @@ -553,3 +553,21 @@ }, 'features': [ 'unstable' ] } + +## +# @cxl-process-mctp-message: +# +# Command to process a MCTP command sent from another VM. +# +# @cci-name: name of the CCI to process the command; +# +# Features: +# +# @unstable: For now this command is subject to change. +# +# Since: 9.1 +## +{'command': 'cxl-process-mctp-message', + 'data': {'cci-name': 'str'}, + 'features': [ 'unstable' ] + } --=20 2.47.2 From nobody Tue Dec 16 03:21:26 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1744086785; cv=none; d=zohomail.com; s=zohoarc; b=BCWFounueyiIMZ7OsAV3zUnqAMezr4/6BsXrPWGkN0O4LiV48VM3iqVr25Vxh1jgrIz0z9L3O/22fsm3zikV5yNv54ya6XQ8N0cayg3qt0CQvctuAaGPbUUP7FdCWCEM3c0lP0AVPEwjJgE+1W3uZE/TZD6XaM0RgBTMIm5el44= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1744086785; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zSwDEvS3Dbs2+SGvBtHxNnFhnzrC6dneDlWiT9TyqTk=; b=YWH5R/3MYEumF7zqyVmpwjU5/z+r9xkDgomNH2SilQC0FAQEiTPJVK1vAArYGlHlPiTmr7H0YkHeXnXhMQL06uI0QPLU+h0cz4bMe05qzaWfkvtmw+mJwfPQivz5uP0CAfUSGWJQM0IBTCnsUF68/diDxTLcHL1O4gi42eK/7wk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1744086785199817.0867732250224; Mon, 7 Apr 2025 21:33:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u20dA-0006Ut-IQ; Tue, 08 Apr 2025 00:32:12 -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 1u20d9-0006Ug-9L for qemu-devel@nongnu.org; Tue, 08 Apr 2025 00:32:11 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u20d7-0005dU-5r for qemu-devel@nongnu.org; Tue, 08 Apr 2025 00:32:11 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-224191d92e4so47203545ad.3 for ; Mon, 07 Apr 2025 21:32:08 -0700 (PDT) Received: from localhost.localdomain ([2601:646:8f03:9fee:5e33:e006:dcd5:852d]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2297865e0a9sm90055385ad.149.2025.04.07.21.32.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Apr 2025 21:32:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744086727; x=1744691527; 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=zSwDEvS3Dbs2+SGvBtHxNnFhnzrC6dneDlWiT9TyqTk=; b=OX8Dl7W4fVdp6yX7fnsGlUqFbCzWzBnfoAXo4jip4gY2CFMu4fD0BHsXBlEEcxNCsT zEx5Apa98Qg1wRPHKerk7wdfqKgq/qek/3EP0zz20OQk7kzpLAGqAhjsgwW0d86Aax+N PftNHErAetppNQnUi4pwrU5Tdc9gVqj8ywho5saNxzazsfMJHodq/xyOR4AVDHtj+lqb cXCuSvUjFBRXIBgPgL5iN6SOJo10jeflMPw1VOXRvH5ZnB7IqhTkwRifgVlPLJIDK8rc fnW4BZWFE5QgN6rAFImNMXgR4s+SywtuzTo9zm7c4pDiJBjTVqZzjcRPJjHO0IYti21C XG9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744086727; x=1744691527; 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=zSwDEvS3Dbs2+SGvBtHxNnFhnzrC6dneDlWiT9TyqTk=; b=h1Q3dDFSSkaNJKOcRX9vKlLQWTRjXaFD5+IrHZ6hbHAvw1GOJ+SDhNoK+oIXAlfLSD jh3laub37wjJiXbCpp1Yz5Z8WnQB8be05BfGaWug7Mx+x4DlJjKhx2LQleLRDzqpfify ekBxu/DFfFWd+Adbp+TEy1REJauggLLUbDLMaPpggk4iSkRcGHRvQ9dkwNAUwg9THiIs 7LzAPHK4dpKP5Q6jZFsimnVaIGyMk1HOWWRLIY8vGt6RLosemPj5W6kq8KaizFH3tZB9 8rH28VAOyUujDf1H6EUhWZQ2V/kfLewDSUcYSLQy/jlJCXWlpvmnV9rPkTL8eIUD2PlQ PsZg== X-Forwarded-Encrypted: i=1; AJvYcCUAJaY5o/JRIpRriSkK5CeEPbZQywTM5SVIZeftz7L5InMiH58Qw9tw7bP85Zn/LJO08i/MqtV1XTEq@nongnu.org X-Gm-Message-State: AOJu0YwgmHSsmj+zJ81epUSd4k5FsH91ltTAS+/icjZbc59bm6F4+1Sv nMzxHrk509c8VkSHJZVikgc9HCuPMH2TZp0km1E7/B5Jbk9jz4sK X-Gm-Gg: ASbGncvyEwcoUXmot3etaninZ15LtpM3ToRPMzeEWlNVZbRd+wTY+Xe7zKwxoZtXOwl LCG7WVdWzBOIe1+xMPoVfckk6WNqx/f5R3KzN/rKifUNOsqm70rYkL0R8gvlRU5fxZ70d/tR8eL oAdcQ3V2xq0Df2MVeMaq5iaz2bPe1gubHNKLdKj4k2NSbUAzlskiF3tNisNqfym5Fi+rLYf+hIh eT6euMNG1T1pCLv5Mz51TmXZUtMH8ARHaTLQ9Ou3Hmljz+2lx5L57rWuKNQL/ckxMk6sq5n1oAs rfvCvU+JEUKgeiGzSUkKQi6Z8J6c/NuG9mMXj4Bs2QXpsc3u08+vLIiuzopm+Q== X-Google-Smtp-Source: AGHT+IHTrhx2ufYDrPtqjHltrCsDJfR6eJB3pAwZNwVKO9HzcZM80ak/RiIojJdvYuZp7wsaTHC+3Q== X-Received: by 2002:a17:902:da85:b0:224:f12:3735 with SMTP id d9443c01a7336-22a8a06b38dmr161533425ad.31.1744086727355; Mon, 07 Apr 2025 21:32:07 -0700 (PDT) From: nifan.cxl@gmail.com To: jonathan.cameron@huawei.com, qemu-devel@nongnu.org Cc: linux-cxl@vger.kernel.org, a.manzanares@samsung.com, dave@stgolabs.net, nmtadam.samsung@gmail.com, nifan.cxl@gmail.com, anisa.su887@gmail.com, gourry@gourry.net, Fan Ni Subject: [RFC 3/3] cxl/i2c_mctp_cxl: Add support to process MCTP command remotely Date: Mon, 7 Apr 2025 21:20:30 -0700 Message-ID: <20250408043051.430340-4-nifan.cxl@gmail.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250408043051.430340-1-nifan.cxl@gmail.com> References: <20250408043051.430340-1-nifan.cxl@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=nifan.cxl@gmail.com; helo=mail-pl1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1744086787463019000 Content-Type: text/plain; charset="utf-8" From: Fan Ni With the change, if "mctp-msg-forward" property is turned on for i2c_mctp_cxl device, we setup a QMP connection to the other VM identified by the "qmp" property, and forward the MCTP requests to the VM for processi= ng. Note: 1. The VM with "mctp-msg-forward=3Don" acts as a FM VM. 2. Before the FM VM is started, the target VM to connect to must be on and ready to connect. 3. For the FM VM instance, it needs to share the same CXL topology with the VM we want to connect to, and the cxl device to connect needs to have "allow-fm-attach=3Don". Signed-off-by: Fan Ni --- hw/cxl/cxl-mctp-qmp.c | 85 +++++++++++++++++++++++++++++++ hw/cxl/i2c_mctp_cxl.c | 68 ++++++++++++++++++++++--- hw/cxl/meson.build | 2 +- hw/mem/cxl_type3.c | 4 +- include/hw/cxl/cxl_device.h | 2 + include/hw/cxl/cxl_mctp_message.h | 3 ++ 6 files changed, 155 insertions(+), 9 deletions(-) create mode 100644 hw/cxl/cxl-mctp-qmp.c diff --git a/hw/cxl/cxl-mctp-qmp.c b/hw/cxl/cxl-mctp-qmp.c new file mode 100644 index 0000000000..f0ea5e2cc0 --- /dev/null +++ b/hw/cxl/cxl-mctp-qmp.c @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "hw/cxl/cxl_mctp_message.h" + +#define BUFFER_SIZE 4096 + +void read_qmp_response(int sockfd) +{ + char buffer[BUFFER_SIZE]; + memset(buffer, 0, BUFFER_SIZE); + int len =3D read(sockfd, buffer, BUFFER_SIZE - 1); + if (len > 0) { + printf("QMP Response:\n%s\n", buffer); + } +} + +static void send_qmp_command(int sockfd, const char *cmd) +{ + send(sockfd, cmd, strlen(cmd), 0); +} + +static void send_qmp_cap_command(int sockfd) +{ + const char *cap_cmd =3D "{ \"execute\": \"qmp_capabilities\" }\n"; + send_qmp_command(sockfd, cap_cmd); + read_qmp_response(sockfd); +} + +static int connect_to_qmp(const char *server, uint16_t port) +{ + int sockfd; + struct sockaddr_in serv_addr; + + sockfd =3D socket(AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) { + return -1; + } + + serv_addr.sin_family =3D AF_INET; + serv_addr.sin_port =3D htons(port); + + if (inet_pton(AF_INET, server, &serv_addr.sin_addr) <=3D 0) { + return -1; + } + + if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) = < 0) { + return -1; + } + + send_qmp_cap_command(sockfd); + + return sockfd; +} + +int setup_mctp_qmp_connection(const char *qmp_str) +{ + char host[256]; + uint16_t port; + + memset(host, 0, 256); + if (sscanf(qmp_str, "%255[^:]:%hu", host, &port) !=3D 2) { + return -1; + } + + return connect_to_qmp(host, port); +} + +void qmp_cxl_mctp_process_cci_message(const int sockfd, const char *cci_na= me) +{ + char command[256]; + + memset(command, 0, 256); + sprintf(command, "{ \"execute\": \"cxl-process-mctp-message\", \ + \"arguments\": { \ + \"cci-name\": \"%s\" \ +}}\n", cci_name); + send_qmp_command(sockfd, command); + read_qmp_response(sockfd); +} diff --git a/hw/cxl/i2c_mctp_cxl.c b/hw/cxl/i2c_mctp_cxl.c index 7d2cbc3b75..e146fa2039 100644 --- a/hw/cxl/i2c_mctp_cxl.c +++ b/hw/cxl/i2c_mctp_cxl.c @@ -29,6 +29,7 @@ #include "hw/pci/pcie_port.h" #include "hw/qdev-properties.h" #include "hw/registerfields.h" +#include "hw/cxl/cxl_mctp_message.h" =20 #define TYPE_I2C_MCTP_CXL "i2c_mctp_cxl" =20 @@ -83,6 +84,10 @@ struct I2C_MCTP_CXL_State { int64_t pos; uint8_t buffer[MCTP_CXL_MAX_MSG_LEN]; uint8_t scratch[MCTP_CXL_MAX_MSG_LEN]; + char *qmp_str; + int qmp_fd; + + bool mctp_msg_forward; }; =20 OBJECT_DECLARE_SIMPLE_TYPE(I2C_MCTP_CXL_State, I2C_MCTP_CXL) @@ -90,6 +95,9 @@ OBJECT_DECLARE_SIMPLE_TYPE(I2C_MCTP_CXL_State, I2C_MCTP_C= XL) static const Property i2c_mctp_cxl_props[] =3D { DEFINE_PROP_LINK("target", I2C_MCTP_CXL_State, target, TYPE_PCI_DEVICE, PCIDevice *), + DEFINE_PROP_STRING("qmp", I2C_MCTP_CXL_State, qmp_str), + DEFINE_PROP_BOOL("mctp-msg-forward", I2C_MCTP_CXL_State, + mctp_msg_forward, false), }; =20 static size_t i2c_mctp_cxl_get_buf(MCTPI2CEndpoint *mctp, @@ -211,12 +219,46 @@ static void i2c_mctp_cxl_handle_message(MCTPI2CEndpoi= nt *mctp) =20 len_in =3D msg->pl_length[2] << 16 | msg->pl_length[1] << 8 | msg->pl_length[0]; - - rc =3D cxl_process_cci_message(s->cci, msg->command_set, msg->comm= and, - len_in, msg->payload, - &len_out, - s->scratch + sizeof(CXLMCTPMessage), - &bg_started); + if (s->mctp_msg_forward) { + CXLType3Dev *ct3d =3D CXL_TYPE3(s->target); + CXLMCTPCommandBuf *mctp_buf; + int i; + char *cci_name =3D NULL; + + g_assert(cci_map_buf); + g_assert(ct3d->mctp_shared_buffer); + + for (i =3D 0; i < cci_map_buf->num_mappings; i++) { + if (cci_map_buf->maps[i].cci_pointer =3D=3D s->cci) { + break; + } + } + + g_assert(i < cci_map_buf->num_mappings); + cci_name =3D cci_map_buf->maps[i].cci_name; + + mctp_buf =3D &ct3d->mctp_shared_buffer->command_buf; + g_assert(mctp_buf); + + mctp_buf->command_set =3D msg->command_set; + mctp_buf->command =3D msg->command; + mctp_buf->len_in =3D len_in; + memcpy(mctp_buf->payload, msg->payload, len_in); + ct3d->mctp_shared_buffer->status =3D 1; + qmp_cxl_mctp_process_cci_message(s->qmp_fd, cci_name); + if (mctp_buf->len_out) { + memcpy(s->scratch + sizeof(CXLMCTPMessage), + mctp_buf->payload_out, mctp_buf->len_out); + } + rc =3D mctp_buf->ret_val; + len_out =3D mctp_buf->len_out; + } else { + rc =3D cxl_process_cci_message(s->cci, msg->command_set, msg->= command, + len_in, msg->payload, + &len_out, + s->scratch + sizeof(CXLMCTPMessag= e), + &bg_started); + } buf->rc =3D rc; s->pos +=3D len_out; s->len =3D s->pos; @@ -253,6 +295,20 @@ static void i2c_mctp_cxl_realize(DeviceState *d, Error= **errp) =20 cxl_initialize_t3_fm_owned_ld_mctpcci(s->cci, DEVICE(s->target), d, MCTP_CXL_MAILBOX_BYTES); + if (s->mctp_msg_forward) { + g_assert(s->qmp_str); + s->qmp_fd =3D setup_mctp_qmp_connection(s->qmp_str); + if (s->qmp_fd < 0) { + error_setg(errp, "setup connection to qmp server failed"); + } else { + read_qmp_response(s->qmp_fd); + } + + init_cci_name_ptr_mapping(); + ct3_setup_mctp_command_share_buffer(ct3d, false); + } else { + s->qmp_fd =3D -1; + } return; } =20 diff --git a/hw/cxl/meson.build b/hw/cxl/meson.build index e780344d85..d0a8f78462 100644 --- a/hw/cxl/meson.build +++ b/hw/cxl/meson.build @@ -13,7 +13,7 @@ system_ss.add(when: 'CONFIG_CXL', if_false: files( 'cxl-host-stubs.c', )) -system_ss.add(when: 'CONFIG_I2C_MCTP_CXL', if_true: files('i2c_mctp_cxl.c'= )) +system_ss.add(when: 'CONFIG_I2C_MCTP_CXL', if_true: files('i2c_mctp_cxl.c'= , 'cxl-mctp-qmp.c')) =20 system_ss.add(when: 'CONFIG_ALL', if_true: files('cxl-host-stubs.c')) =20 diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c index f7ac8e8da7..d44b1b6dc6 100644 --- a/hw/mem/cxl_type3.c +++ b/hw/mem/cxl_type3.c @@ -1051,7 +1051,7 @@ static int ct3_mctp_buf_create(const char *filename, = size_t size) return fd; } =20 -static int ct3_setup_mctp_command_share_buffer(CXLType3Dev *ct3d, bool cre= ate) +int ct3_setup_mctp_command_share_buffer(CXLType3Dev *ct3d, bool create) { int fd; int size =3D sizeof(*ct3d->mctp_shared_buffer); @@ -1074,7 +1074,7 @@ static int ct3_setup_mctp_command_share_buffer(CXLTyp= e3Dev *ct3d, bool create) return -1; } =20 -static int init_cci_name_ptr_mapping(void) +int init_cci_name_ptr_mapping(void) { if (!cci_map_buf) { cci_map_buf =3D g_malloc(sizeof(*cci_map_buf)); diff --git a/include/hw/cxl/cxl_device.h b/include/hw/cxl/cxl_device.h index 9a00ef7a1e..5c8813af20 100644 --- a/include/hw/cxl/cxl_device.h +++ b/include/hw/cxl/cxl_device.h @@ -810,4 +810,6 @@ void ct3_clear_region_block_backed(CXLType3Dev *ct3d, u= int64_t dpa, uint64_t len); bool ct3_test_region_block_backed(CXLType3Dev *ct3d, uint64_t dpa, uint64_t len); +int ct3_setup_mctp_command_share_buffer(CXLType3Dev *ct3d, bool create); +int init_cci_name_ptr_mapping(void); #endif diff --git a/include/hw/cxl/cxl_mctp_message.h b/include/hw/cxl/cxl_mctp_me= ssage.h index 85b3664cf7..718dc8c0a2 100644 --- a/include/hw/cxl/cxl_mctp_message.h +++ b/include/hw/cxl/cxl_mctp_message.h @@ -37,4 +37,7 @@ struct CXLMCTPSharedBuf { =20 typedef struct CXLMCTPSharedBuf CXLMCTPSharedBuf; extern struct CXLCCINamePtrMaps *cci_map_buf; +int setup_mctp_qmp_connection(const char *qmp_str); +void read_qmp_response(int sockfd); +void qmp_cxl_mctp_process_cci_message(const int sockfd, const char *cci_na= me); #endif --=20 2.47.2