From nobody Fri Apr 19 18:10:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1685030962; cv=none; d=zohomail.com; s=zohoarc; b=Yh4wXDWA8+gZpPG97IaGQ/1UiyFe2KIZCLx/IRk+CRgC1P+bAirxuGpHTrDPq+j/klq31Yf7gs6XwTKp6azxLHJdVOq/PO7q8waVhNf7PJ3STmcKEbg5D1TGbOWTkAFNcl5+nHtmFjKu3yVdEY5ChQ9YgxvsEv+mE3YhwElUoec= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685030962; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=81awDB6YlRY3kALE8QwZnDWU+Ovk5J+EKifFi1VW8D8=; b=kCgYkxSZIqHJjuVsggkDXEK7It3cM2cFrwR2chRJ9bBAsiv6IBrYV9dWbBNVWyomNLuBgEAs4Bu6Z5EbDV+3cIar0aGDLdiCFcXJXyciR5nRRbH9aEe5hNhlakRN1+uJvJpVZT+Fx9EG6KW2o0pu46a2OzciyZ0OYM7giHH3/Dc= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 1685030962636804.1058258454464; Thu, 25 May 2023 09:09:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q2DWZ-0000KS-DR; Thu, 25 May 2023 12:09:11 -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 1q2DWX-0000GN-BQ for qemu-devel@nongnu.org; Thu, 25 May 2023 12:09:09 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q2DWS-0003Ks-EI for qemu-devel@nongnu.org; Thu, 25 May 2023 12:09:09 -0400 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4QRtHV1HrGz67RCM; Fri, 26 May 2023 00:07:34 +0800 (CST) Received: from SecurePC-101-06.china.huawei.com (10.122.247.231) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 25 May 2023 17:08:59 +0100 To: , Fan Ni CC: Niyas Sait , Klaus Jensen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Michael S . Tsirkin" , Jeremy Kerr , Matt Johnston , Shesha Bhushan Sreenivasamurthy , , , "Viacheslav A . Dubeyko" , Peter Maydell Subject: [RFC PATCH 0/6] hw/{cxl, i386, arm}: PoC: Emulated MCTP over I2C for CXL Fabric / Device management Date: Thu, 25 May 2023 17:08:53 +0100 Message-ID: <20230525160859.32517-1-Jonathan.Cameron@huawei.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.122.247.231] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected 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=185.176.79.56; envelope-from=jonathan.cameron@huawei.com; helo=frasgout.his.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Reply-to: Jonathan Cameron From: Jonathan Cameron via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1685030964781100001 Content-Type: text/plain; charset="utf-8" Not intended for merge in anything like current form! CC list is a bit random and I'll admit I added a few people just to make th= em groan. Depends on patches 1 and 2 from. [PATCH v2 0/3] hw/{i2c, nvme}: mctp endpoint, nvme management interface mod= el. Based-on: Message-ID: 20230425063540.46143-1-its@irrelevant.dk Arm parts also need the out of tree ARM64 cxl patches. Generally working with the kernel CXL stack requires event emulation. A git tree with this near the top and all prereqs is available at: http://gitlab.com/jic23/qemu cxl-2023-05-25 Just over a year ago (yikes) I posted [RFC PATCH 0/2] CXL FMAPI interface o= ver MCTP/I2C https://lore.kernel.org/linux-cxl/20220520170128.4436-1-Jonathan.Cameron@hu= awei.com/ Since that time I've had a number of questions about how to build on that PoC to enable control of actual CXL devices. The fundamental problem at that stage was the PoC only worked with device t= ree bindings and the rest of CXL software assumes ACPI (adding DT support for CXL in general is a long term project). So this series attempts to 'solve' that. Currently I'm only aware of one emulated I2C controller with the right characteristics to be able to support MCTP over I2C - aspeed-i2c. So lets add that to the main architectures we care about for CXL: - ARM64 (on top of my out of tree support github.com/jic23/qemu) - X86 - yup I just added an aspeed-i2c controller to pc :) The actual emulated device has been rebased on Klaus Jensen's work for the nvme-mi which massively reduces the amount of boilerplate / state machine handling that needs to be done in this emulation. (great work btw Klaius!) So how to use this: For ACPI you need the kernel patches from: https://lore.kernel.org/linux-cxl/20230525152203.32190-1-Jonathan.Cameron@h= uawei.com/T/#u To make the aspeed i2c controller play nicely with PRP0001 based ACPI descr= iption. Example qemu command line - stripped back to include only relevant bits qemu-system-x86_64 -M q35,cxl=3Don -m 4g,maxmem=3D8G,slots=3D8 -cpu max -sm= p 4 \ ... -object memory-backend-file,id=3Dcxl-mem1,share=3Don,mem-path=3D/tmp/cxlte= st.raw,size=3D256M,align=3D256M \ -object memory-backend-file,id=3Dcxl-mem2,share=3Don,mem-path=3D/tmp/cxlte= st2.raw,size=3D256M,align=3D256M \ -object memory-backend-file,id=3Dcxl-mem3,share=3Don,mem-path=3D/tmp/cxlte= st3.raw,size=3D256M,align=3D256M \ -object memory-backend-file,id=3Dcxl-lsa1,share=3Don,mem-path=3D/tmp/lsa.r= aw,size=3D1M,align=3D1M \ -object memory-backend-file,id=3Dcxl-lsa2,share=3Don,mem-path=3D/tmp/lsa2.= raw,size=3D1M,align=3D1M \ -object memory-backend-file,id=3Dcxl-lsa3,share=3Don,mem-path=3D/tmp/lsa3.= raw,size=3D1M,align=3D1M \ -object memory-backend-file,id=3Dcxl-mem5,share=3Don,mem-path=3D/tmp/cxlte= st5.raw,size=3D256M,align=3D256M \ -object memory-backend-file,id=3Dcxl-mem6,share=3Don,mem-path=3D/tmp/cxlte= st6.raw,size=3D256M,align=3D256M \ -object memory-backend-file,id=3Dcxl-mem7,share=3Don,mem-path=3D/tmp/cxlte= st7.raw,size=3D256M,align=3D256M \ -object memory-backend-file,id=3Dcxl-lsa5,share=3Don,mem-path=3D/tmp/lsa5.= raw,size=3D1M,align=3D1M \ -object memory-backend-file,id=3Dcxl-lsa6,share=3Don,mem-path=3D/tmp/lsa6.= raw,size=3D1M,align=3D1M \ -object memory-backend-file,id=3Dcxl-lsa7,share=3Don,mem-path=3D/tmp/lsa7.= raw,size=3D1M,align=3D1M \ -device pxb-cxl,bus_nr=3D12,bus=3Dpcie.0,id=3Dcxl.1 \ -device cxl-rp,port=3D0,bus=3Dcxl.1,id=3Droot_port0,chassis=3D0,slot=3D2 \ -device cxl-rp,port=3D1,bus=3Dcxl.1,id=3Droot_port2,chassis=3D0,slot=3D3 \ -device cxl-upstream,port=3D33,bus=3Droot_port0,id=3Dus0,multifunction=3Do= n,addr=3D0.0,sn=3D12345678 \ -device cxl-downstream,port=3D0,bus=3Dus0,id=3Dswport0,chassis=3D0,slot=3D= 4 \ -device cxl-downstream,port=3D1,bus=3Dus0,id=3Dswport1,chassis=3D0,slot=3D= 5 \ -device cxl-downstream,port=3D2,bus=3Dus0,id=3Dswport2,chassis=3D0,slot=3D= 6 \ -device cxl-type3,bus=3Dswport0,persistent-memdev=3Dcxl-mem1,id=3Dcxl-pmem= 0,lsa=3Dcxl-lsa1,sn=3D3 \ -device cxl-type3,bus=3Dswport1,persistent-memdev=3Dcxl-mem2,id=3Dcxl-pmem= 1,lsa=3Dcxl-lsa2,sn=3D4 \ -device cxl-type3,bus=3Dswport2,persistent-memdev=3Dcxl-mem3,id=3Dcxl-pmem= 2,lsa=3Dcxl-lsa3,sn=3D5 \ -machine cxl-fmw.0.targets.0=3Dcxl.1,cxl-fmw.0.size=3D4G,cxl-fmw.0.interle= ave-granularity=3D1k \ -device i2c_mctp_cxl,bus=3Daspeed.i2c.bus.0,address=3D4,target=3Dus0 \ -device i2c_mctp_cxl,bus=3Daspeed.i2c.bus.0,address=3D5,target=3Dcxl-pmem0= \ -device i2c_mctp_cxl,bus=3Daspeed.i2c.bus.0,address=3D6,target=3Dcxl-pmem1= \ -device i2c_mctp_cxl,bus=3Daspeed.i2c.bus.0,address=3D7,target=3Dcxl-pmem2= \ =20 Install the MCTP daemon from: https://github.com/CodeConstruct/mctp Bring up and enumerate the MCTP EPs: # Bring up the link mctp link set mctpi2c0 up # Assign an address to the aspeed-i2c controller mctp addr add 50 dev mctpi2c0 # Assign a neetwork ID to the link (11) mctp link set mctpi2c0 net 11 # Start the daemon that uses dbus for configuration. systemctl start mctpd.service # Assign EIDs to the EPs busctl call xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp au.com.CodeC= onstruct.MCTP AssignEndpoint say mctpi2c0 1 0x4 busctl call xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp au.com.CodeC= onstruct.MCTP AssignEndpoint say mctpi2c0 1 0x5 busctl call xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp au.com.CodeC= onstruct.MCTP AssignEndpoint say mctpi2c0 1 0x6 busctl call xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp au.com.CodeC= onstruct.MCTP AssignEndpoint say mctpi2c0 1 0x7 # Check it worked by dumping some state. busctl introspect xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp/11/8 x= yz.openbmc_project.MCTP.Endpoint busctl introspect xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp/11/9 x= yz.openbmc_project.MCTP.Endpoint busctl introspect xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp/11/10 = xyz.openbmc_project.MCTP.Endpoint busctl introspect xyz.openbmc_project.MCTP /xyz/openbmc_project/mctp/11/11 = xyz.openbmc_project.MCTP.Endpoint Use the following test program to poke them ./test 8 etc (address will be printed out during configuration above, but u= sually starts at 8) From 14ac4ad4eb97bd0536c332f08c639f980c280b93 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Thu, 25 May 2023 11:36:36 +0100 Subject: [PATCH] Trivial MCTP CXL CCI test prog Signed-off-by: Jonathan Cameron --- cxl_fmapi.h | 72 +++++++++++ mctp.h | 68 ++++++++++ test.c | 361 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 501 insertions(+) create mode 100644 cxl_fmapi.h create mode 100644 mctp.h create mode 100644 test.c diff --git a/cxl_fmapi.h b/cxl_fmapi.h new file mode 100644 index 0000000..6e861ed --- /dev/null +++ b/cxl_fmapi.h @@ -0,0 +1,72 @@ + +#include + +#define CXL_CCI_CMD_SET_INFO 0x0 +#define CXL_IDENTIFY 0x0 +#define CXL_FM_API_CMD_SET_PHYSICAL_SWITCH 0x51 +#define CXL_IDENTIFY_SWITCH_DEVICE 0x00 +#define CXL_GET_PHYSICAL_PORT_STATE 0x01 + +struct cxl_fmapi_header { + #define CXL_MCTP_CATEGORY_REQ 0 + #define CXL_MCTP_CATEGORY_RESP 1 + uint8_t category; + uint8_t tag; + uint8_t rsv1; + uint8_t command; + uint8_t command_set; + uint8_t pl_length[3]; /* 20 bit little endian, BO bit at bit 23 */ + uint16_t return_code; + uint16_t vendor_ext_status; +} __attribute__ ((packed)); + +struct cxl_cci_infostat_identify_resp_pl { + uint16_t vendor_id; + uint16_t device_id; + uint16_t subsys_vendor_id; + uint16_t subsys_id; + uint8_t serial_num[8]; + uint8_t max_msg; + uint8_t component_type; +} __attribute__((packed)); + +struct cxl_fmapi_ident_switch_dev_resp_pl { + uint8_t ingres_port_id; + uint8_t rsv1; + uint8_t num_physical_ports; + uint8_t num_vcs; + uint8_t active_port_bitmask[32]; + uint8_t active_vcs_bitmask[32]; + uint16_t num_total_vppb; + uint16_t num_active_vppb; +} __attribute__((packed)); + +struct cxl_fmapi_get_phys_port_state_req_pl { + uint8_t num_ports; /* CHECK. may get too large for MCTP message size */ + uint8_t ports[]; +} __attribute__((packed)); + +struct cxl_fmapi_port_state_info_block { + uint8_t port_id; + uint8_t config_state; + uint8_t connected_device_cxl_version; + uint8_t rsv1; + uint8_t connected_device_type; + uint8_t port_cxl_version_bitmask; + uint8_t max_link_width; + uint8_t negotiated_link_width; + uint8_t supported_link_speeds_vector; + uint8_t max_link_speed; + uint8_t current_link_speed; + uint8_t ltssm_state; + uint8_t first_lane_num; + uint16_t link_state; + uint8_t supported_ld_count; +} __attribute__((packed)); + +struct cxl_fmapi_get_phys_port_state_resp_pl { + uint8_t num_ports; + uint8_t rsv1[3]; + struct cxl_fmapi_port_state_info_block ports[]; +} __attribute__((packed)); + diff --git a/mctp.h b/mctp.h new file mode 100644 index 0000000..154ab56 --- /dev/null +++ b/mctp.h @@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Management Component Transport Protocol (MCTP) + * + * Copyright (c) 2021 Code Construct + * Copyright (c) 2021 Google + */ + +#ifndef __UAPI_MCTP_H +#define __UAPI_MCTP_H + +#include +#include +#include + +typedef __u8 mctp_eid_t; + +struct mctp_addr { + mctp_eid_t s_addr; +}; + +struct sockaddr_mctp { + __kernel_sa_family_t smctp_family; + __u16 __smctp_pad0; + unsigned int smctp_network; + struct mctp_addr smctp_addr; + __u8 smctp_type; + __u8 smctp_tag; + __u8 __smctp_pad1; +}; + +struct sockaddr_mctp_ext { + struct sockaddr_mctp smctp_base; + int smctp_ifindex; + __u8 smctp_halen; + __u8 __smctp_pad0[3]; + __u8 smctp_haddr[MAX_ADDR_LEN]; +}; + +#define MCTP_NET_ANY 0x0 + +#define MCTP_ADDR_NULL 0x00 +#define MCTP_ADDR_ANY 0xff + +#define MCTP_TAG_MASK 0x07 +#define MCTP_TAG_OWNER 0x08 +#define MCTP_TAG_PREALLOC 0x10 + +#define MCTP_OPT_ADDR_EXT 1 + +#define SIOCMCTPALLOCTAG (SIOCPROTOPRIVATE + 0) +#define SIOCMCTPDROPTAG (SIOCPROTOPRIVATE + 1) + +struct mctp_ioc_tag_ctl { + mctp_eid_t peer_addr; + + /* For SIOCMCTPALLOCTAG: must be passed as zero, kernel will + * populate with the allocated tag value. Returned tag value will + * always have TO and PREALLOC set. + * + * For SIOCMCTPDROPTAG: userspace provides tag value to drop, from + * a prior SIOCMCTPALLOCTAG call (and so must have TO and PREALLOC set). + */ + __u8 tag; + __u16 flags; +}; + +#endif /* __UAPI_MCTP_H */ diff --git a/test.c b/test.c new file mode 100644 index 0000000..20f1dbb --- /dev/null +++ b/test.c @@ -0,0 +1,361 @@ +/* + * Trivial example program to exercise QEMU FMAPI Emulation over MCTP over= I2C + */ +#include +#include +#include +#include +#include +#include "mctp.h" +#include "cxl_fmapi.h" + +enum cxl_type { + cxl_switch, + cxl_type3, +}; + +static int query_cci_identify(int sd, struct sockaddr_mctp *addr, int *tag= , enum cxl_type *type) +{ + struct cxl_cci_infostat_identify_resp_pl *pl; + uint8_t buf[1024]; + struct cxl_fmapi_header *rsp_head =3D buf; + + int rc; + ssize_t len; + struct sockaddr_mctp addrrx; + socklen_t addrlen =3D sizeof(addrrx); + struct cxl_fmapi_header req =3D { + .category =3D CXL_MCTP_CATEGORY_REQ, + .tag =3D *tag++, + .command =3D 1, + .command_set =3D 0, + .vendor_ext_status =3D 0xabcd, + }; + + printf("trying to identify\n"); + len =3D sendto(sd, &req, sizeof(req), 0, (struct sockaddr *)addr, sizeof(= *addr)); + if (len !=3D sizeof(req)) { + printf("Failed to send whole request for phys switch info %d %d\n", len,= sizeof(req)); + return -1; + } + + len =3D recvfrom(sd, buf, sizeof(buf), 0, (struct sockaddr *)&addrrx, &ad= drlen); + if (len < 0) { + printf("Failed to receive response\n"); + return -1; + } + printf("length %d\n", len); + pl =3D (void *)(rsp_head + 1); + printf("Vendor id : %04x\n", pl->vendor_id); + printf("Device id : %04x\n", pl->device_id); + printf("Subsys vid : %04x\n", pl->subsys_vendor_id); + printf("Subsys id : %04x\n", pl->subsys_id); + + switch (pl->component_type) { + case 0x00: + printf("Switch!\n"); + *type =3D cxl_switch; + break; + case 0x03: + printf("Type3!\n"); + *type =3D cxl_type3; + break; + } + + return 0; +} + +static int parse_physical_switch_identify_switch_device(void *buf, size_t = buf_len) +{ + struct cxl_fmapi_header *rsp_head =3D buf; + struct cxl_fmapi_ident_switch_dev_resp_pl *pl =3D (void *)(rsp_head + 1); + uint8_t *b; + if (rsp_head->return_code !=3D 0) { + printf("Error code in response %d\n", rsp_head->return_code); + return -1; + } + printf("Num total vppb %d\n", pl->num_total_vppb); + printf("Ports %d\n", pl->num_physical_ports); + b =3D pl->active_port_bitmask; + printf("ActivePortMask"); + for (int i =3D 0; i < 32; i++) + printf("%02x", b[i]); + printf("\n"); + return 0; +} + +int query_physical_switch_info(int sd, struct sockaddr_mctp *addr, int *ta= g) +{ + uint8_t buf[1024]; + int rc; + ssize_t len; + struct sockaddr_mctp addrrx; + socklen_t addrlen =3D sizeof(addrrx); + struct cxl_fmapi_header req =3D { + .category =3D CXL_MCTP_CATEGORY_REQ, + .tag =3D *tag++, + .command =3D CXL_IDENTIFY_SWITCH_DEVICE, + .command_set =3D CXL_FM_API_CMD_SET_PHYSICAL_SWITCH, + .vendor_ext_status =3D 0xabcd, + }; + + len =3D sendto(sd, &req, sizeof(req), 0, (struct sockaddr *)addr, sizeof(= *addr)); + if (len !=3D sizeof(req)) { + printf("Failed to send whole request for phys switch info %d %d\n", len,= sizeof(req)); + return -1; + } + + len =3D recvfrom(sd, buf, sizeof(buf), 0, (struct sockaddr *)&addrrx, &ad= drlen); + if (len < 0) { + printf("Failed to receive response\n"); + return -1; + } + printf("length %d\n", len); + rc =3D parse_physical_switch_identify_switch_device(buf, len); + if (rc) + return -1; + + return 0; +} + +static int parse_phys_port_state_rsp(void * buf, size_t buf_len, struct cx= l_fmapi_header *head) +{ + struct cxl_fmapi_header *rsp_head =3D buf; + struct cxl_fmapi_get_phys_port_state_resp_pl *pl =3D (void *)(rsp_head + = 1); + uint32_t pl_length =3D rsp_head->pl_length[0] | + (rsp_head->pl_length[1] << 8) | + ((rsp_head->pl_length[2] & 0xf) << 16); + + if (rsp_head->category !=3D CXL_MCTP_CATEGORY_RESP) { + printf("Message not a response\n"); + return -1; + } + if (rsp_head->tag !=3D head->tag) { + printf("Reply has wrong tag\n"); + return -1; + } + if ((rsp_head->command !=3D head->command) || + (rsp_head->command_set !=3D head->command_set)) { + printf("Response to wrong command\n"); + return -1; + } + + if (rsp_head->return_code !=3D 0) { + printf("Error code in response %d\n", rsp_head->return_code); + printf("%x %x %x %x %x %x %x %x %x %x %x %x\n", ((uint8_t *)rsp_head)[0]= ,((uint8_t *)rsp_head)[1], + ((uint8_t *)rsp_head)[2],((uint8_t *)rsp_head)[3], + ((uint8_t *)rsp_head)[4],((uint8_t *)rsp_head)[5],((uint8_t *)rsp_head)= [6], + ((uint8_t *)rsp_head)[7], ((uint8_t *)rsp_head)[8], ((uint8_t *)rsp_hea= d)[9], + ((uint8_t *)rsp_head)[10], ((uint8_t *)rsp_head)[11]); + return -1; + } + + if (pl_length < 4 || pl_length < (pl->num_ports * sizeof(pl->ports[0])))= { + printf("too short %d %d\n", pl->num_ports); + return -1; + } + + for (int i =3D 0; i < pl->num_ports; i++) { + struct cxl_fmapi_port_state_info_block *port =3D &pl->ports[i]; + const char *port_states[] =3D { + [0x0] =3D "Disabled", + [0x1] =3D "Bind in progress", + [0x2] =3D "Unbind in progress", + [0x3] =3D "DSP", + [0x4] =3D "USP", + [0x5] =3D "Reserved", + //other values not present. + [0xf] =3D "Invalid Port ID" + }; + const char *connected_device_modes[] =3D { + [0] =3D "Not CXL / connected", + [1] =3D "CXL 1.1", + [2] =3D "CXL 2.0", + }; + const char *connected_device_type[] =3D { + [0] =3D "No device detected", + [1] =3D "PCIe device", + [2] =3D "CXL type 1 device", + [3] =3D "CXL type 2 device", + [4] =3D "CXL type 3 device", + [5] =3D "CXL type 3 pooled device", + [6] =3D "Reserved", + }; + const char *ltssm_states[] =3D { + [0] =3D "Detect", + [1] =3D "Polling", + [2] =3D "Configuration", + [3] =3D "Recovery", + [4] =3D "L0", + [5] =3D "L0s", + [6] =3D "L1", + [7] =3D "L2", + [8] =3D "Disabled", + [9] =3D "Loop Back", + [10] =3D "Hot Reset", + }; + printf("Port%02d:\n ", port->port_id); + printf("\tPort state: "); + if (port_states[port->config_state & 0xf]) + printf("%s\n", port_states[port->config_state]); + else + printf("Unknown state\n"); + + if (port->config_state =3D=3D 3) { /* DSP so device could be there */ + printf("\tConnected Device CXL Version: "); + if (port->connected_device_cxl_version > 2) + printf("Unknown CXL Version\n"); + else + printf("%s\n", connected_device_modes[port->connected_device_cxl_versi= on]); + + printf("\tConnected Device Type: "); + if (port->connected_device_type > 7) + printf("Unknown\n"); + else + printf("%s\n", connected_device_type[port->connected_device_type]); + } + + printf("\tSupported CXL Modes:"); + if (port->port_cxl_version_bitmask & 0x1) + printf(" 1.1"); + if (port->port_cxl_version_bitmask & 0x2) + printf(" 2.0"); + printf("\n"); + + printf("\tMaximum Link Width: %d Negotiated Width %d\n", + port->max_link_width, + port->negotiated_link_width); + printf("\tSupported Speeds: "); + if (port->supported_link_speeds_vector & 0x1) + printf(" 2.5 GT/s"); + if (port->supported_link_speeds_vector & 0x2) + printf(" 5.0 GT/s"); + if (port->supported_link_speeds_vector & 0x4) + printf(" 8.0 GT/s"); + if (port->supported_link_speeds_vector & 0x8) + printf(" 16.0 GT/s"); + if (port->supported_link_speeds_vector & 0x10) + printf(" 32.0 GT/s"); + if (port->supported_link_speeds_vector & 0x20) + printf(" 64.0 GT/s"); + printf("\n"); + + printf("\tLTSSM: "); + if (port->ltssm_state >=3D sizeof(ltssm_states)) + printf("Unkown\n"); + else + printf("%s\n", ltssm_states[port->ltssm_state]); + } +} + +int query_ports(int sd, struct sockaddr_mctp *addr, int *tag) +{ + uint8_t buf[1024]; + ssize_t len; + int num_ports =3D 4; + int rc; + uint8_t port_list[4] =3D { 0, 3, 7, 4 }; + struct sockaddr_mctp addrrx; + socklen_t addrlen =3D sizeof(addrrx); + struct cxl_fmapi_header *head; + struct cxl_fmapi_get_phys_port_state_req_pl *reqpl; + size_t req_sz =3D sizeof(*reqpl) + num_ports + sizeof(*head) ; + + head =3D malloc(req_sz); + *head =3D (struct cxl_fmapi_header) { + .category =3D CXL_MCTP_CATEGORY_REQ, + .tag =3D *tag++, + .command =3D CXL_GET_PHYSICAL_PORT_STATE, + .command_set =3D CXL_FM_API_CMD_SET_PHYSICAL_SWITCH, + .pl_length =3D { + req_sz & 0xff, + (req_sz >> 8) & 0xff, + (req_sz >> 16) & 0xf }, + .vendor_ext_status =3D 0x1234, + }; + reqpl =3D (void *)(head + 1); + *reqpl =3D (struct cxl_fmapi_get_phys_port_state_req_pl) { + .num_ports =3D num_ports, + }; + for (int j =3D 0; j < num_ports; j++) + reqpl->ports[j] =3D port_list[j]; + + len =3D sendto(sd, head, req_sz, 0, + (struct sockaddr *)addr, sizeof(*addr)); + + len =3D recvfrom(sd, buf, sizeof(buf), 0, + (struct sockaddr *)&addrrx, &addrlen); + if (len < sizeof(struct cxl_fmapi_header)) { + printf("Too short for header\n"); + } + //TODO generic check of reply. + if (addrrx.smctp_type !=3D 0x7) { + printf("Reply does not match expected message type %x\n", addrrx.smctp_t= ype); + } + + rc =3D parse_phys_port_state_rsp(buf, len, head); + if (rc) + return rc; + + return 0; +} + +int main(int argv, char **argc) +{ + int rc, cci_sd, fmapi_sd; + int tag =3D 0; /* will increment on each use */ + ssize_t len; + if (argv < 2) { + printf("Give an address\n"); + return -1; + } + int dev_addr =3D atoi(argc[1]); + struct sockaddr_mctp cci_addr =3D { + .smctp_family =3D AF_MCTP, + .smctp_network =3D 11, + .smctp_addr.s_addr =3D dev_addr, + .smctp_type =3D 0x8, /* CXL CCI */ + .smctp_tag =3D MCTP_TAG_OWNER, + }; + struct sockaddr_mctp fmapi_addr =3D { + .smctp_family =3D AF_MCTP, + .smctp_network =3D 11, + .smctp_addr.s_addr =3D dev_addr, + .smctp_type =3D 0x7, /* CXL FMAPI */ + .smctp_tag =3D MCTP_TAG_OWNER, + }; + struct sockaddr_mctp addrrx; + socklen_t addrlen =3D sizeof(addrrx); + enum cxl_type type; + + cci_sd =3D socket(AF_MCTP, SOCK_DGRAM, 0); + rc =3D bind(cci_sd, (struct sockaddr *)&cci_addr, sizeof(cci_addr)); + if (rc) { + printf("Bind failed\n"); + return -1; + } + + rc =3D query_cci_identify(cci_sd, &cci_addr, &tag, &type); + if (rc) + return rc; + + if (type =3D=3D cxl_switch) { + fmapi_sd =3D socket(AF_MCTP, SOCK_DGRAM, 0); + rc =3D bind(fmapi_sd, (struct sockaddr *)&fmapi_addr, sizeof(fmapi_addr)= ); + if (rc) { + printf("Bind failed\n"); + return -1; + } + + rc =3D query_physical_switch_info(fmapi_sd, &fmapi_addr, &tag); + if (rc) + return rc; + + /* Next query some of the ports */ + rc =3D query_ports(fmapi_sd, &fmapi_addr, &tag); + if (rc) + return rc; + } + + return 0; +} --=20 2.39.2 Jonathan Cameron (6): hw/acpi/aml-build: add function for i2c slave device serial bus description HACK: arm/virt: Add aspeed-i2c controller and MCTP EP to enable MCTP testing HACK: hw/arm/virt: Add ACPI support for aspeed-i2c / mctp HACK: hw/i386/pc: Add Aspeed i2c controller + MCTP with ACPI tables misc/i2c_mctp_cxl: Initial device emulation docs: cxl: Add example commandline for MCTP CXL CCIs docs/system/devices/cxl.rst | 27 +++ include/hw/acpi/aml-build.h | 1 + include/hw/arm/virt.h | 2 + include/hw/cxl/cxl_fmapi.h | 102 ++++++++++ include/hw/i386/pc.h | 1 + hw/acpi/aml-build.c | 17 ++ hw/arm/virt-acpi-build.c | 60 ++++++ hw/arm/virt.c | 92 ++++++++- hw/cxl/i2c_mctp_cxl.c | 369 ++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 65 +++++++ hw/i386/pc.c | 20 +- hw/arm/Kconfig | 2 + hw/cxl/Kconfig | 3 + hw/cxl/meson.build | 1 + hw/i2c/meson.build | 2 +- hw/i386/Kconfig | 2 + hw/misc/meson.build | 1 + 17 files changed, 762 insertions(+), 5 deletions(-) create mode 100644 include/hw/cxl/cxl_fmapi.h create mode 100644 hw/cxl/i2c_mctp_cxl.c --=20 2.39.2