From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 2002:a05:7022:70f:b0:65:5a5e:914a with SMTP id 15csp2482686dlh; Wed, 31 May 2023 08:04:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4aSNbI2xwrnJgATNmwgx1duCp/fXdecYfLCs27mVLwQVebJlGZADo45+A4sTemcKa21dhK X-Received: by 2002:a05:6214:cc4:b0:626:290f:3e80 with SMTP id 4-20020a0562140cc400b00626290f3e80mr8173228qvx.50.1685545477777; Wed, 31 May 2023 08:04:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685545477; cv=none; d=google.com; s=arc-20160816; b=f/UD+K/+kOtpC9jnJHcnNhG7jNFTbDZHVWZs4o8lzb6IEpeMe4bAP+8ZhZjp846ojD s34sCj6LOl62+oohalfY1Q9ZtPmMz0m/q7a7rP4RZjd/kyLV898JpfGv2guU6Mb/aI+0 BjaqsNbMboq8QQi1Gh4gFlmJGp2LdqYqL9HrZOBNWBgNh7ficdDAxiXMmoPf+KmtBz/L l7wmQj7OyWXqCjRUbihUllR8kFGqf2zR+AY4UmyLR2OZRg7rSkbZT4yyZyh3SSE8luOj trl9PQaLD8w81zXO8t1hQFWHoErwrAscZGCX+0H7xfMSdG2KQZG9NtVP1vKlZm2oiOgU bdJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:from:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:date; bh=1DJ9OLcc2+/6W4TIjCC0nOMrLw2zjTL+jdA6OWvfxow=; b=n9LBDCUSmoBp/Sb+dcfWBCCMvypoWWFk2JrFuAG1b9WVTxYIWCBgFdK3Vql8KtlI/r UHiNCPkSR7ZB+K92utM7vZzFolWpNeaPI8oXiz3HNZmfkQl0nVFJfDzTTSvh2Yp1gWAp PnBdafwnP71lfs1R+VQquJYs+vlhrUMcuNSGAJ5luTjWZDX9Dckn19aI4D6hq3LiEhDO 1m7RDu3qSmk4ErFKAqu9E1h6RETpH+u/ZgWca+Ek/ffUAI4MkTckxAoJzi5u5gHE7tji Tb8gescj1NzbfSGyh7xYMURQb9GTJwNWXZr1Yhx9M/OGebkEv/13nCnD7u6/EKAy2XDN rBfA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d14-20020a05621421ce00b006257724fdfcsi8353484qvh.303.2023.05.31.08.04.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 31 May 2023 08:04:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nongnu.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4NNI-0005l7-RU; Wed, 31 May 2023 11:04:33 -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 1q4NN8-0005eA-Cj; Wed, 31 May 2023 11:04:24 -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 1q4NN4-0002ss-Mc; Wed, 31 May 2023 11:04:20 -0400 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4QWXYd6LQhz67fDB; Wed, 31 May 2023 23:02:29 +0800 (CST) Received: from localhost (10.202.227.76) 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; Wed, 31 May 2023 16:04:11 +0100 Date: Wed, 31 May 2023 16:04:10 +0100 To: Klaus Jensen CC: , Corey Minyard , "Keith Busch" , Jason Wang , Lior Weintraub , Paolo Bonzini , Jeremy Kerr , , Matt Johnston , Peter Delevoryas , , =?ISO-8859-1?Q?C=E9dric?= Le Goater , Klaus Jensen , Peter Maydell , Subject: Re: [PATCH v3 2/3] hw/i2c: add mctp core Message-ID: <20230531160410.0000305b@Huawei.com> In-Reply-To: <20230531155944.00006309@Huawei.com> References: <20230531114744.9946-1-its@irrelevant.dk> <20230531114744.9946-3-its@irrelevant.dk> <20230531155944.00006309@Huawei.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.227.76] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected 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-arm@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-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: ZccyuaTb44fG On Wed, 31 May 2023 15:59:44 +0100 Jonathan Cameron wrote: > On Wed, 31 May 2023 13:47:43 +0200 > Klaus Jensen wrote: > > > From: Klaus Jensen > > > > Add an abstract MCTP over I2C endpoint model. This implements MCTP > > control message handling as well as handling the actual I2C transport > > (packetization). > > > > Devices are intended to derive from this and implement the class > > methods. > > > > Parts of this implementation is inspired by code[1] previously posted by > > Jonathan Cameron. > > > > Squashed a fix[2] from Matt Johnston. > > > > [1]: https://lore.kernel.org/qemu-devel/20220520170128.4436-1-Jonathan.Cameron@huawei.com/ > > [2]: https://lore.kernel.org/qemu-devel/20221121080445.GA29062@codeconstruct.com.au/ > > > > Signed-off-by: Klaus Jensen > Hi Klaus, > > A few minor comments inline. > > With those tidied up feel free to add > Reviewed-by: Jonathan Cameron > > > > > + > > + if (pkt->mctp.hdr.flags & MCTP_H_FLAGS_SOM) { > > + mctp->tx.is_control = false; > > + > > + if (mctp->state == I2C_MCTP_STATE_RX) { > > + mc->reset(mctp); > > + } > > + > > + mctp->state = I2C_MCTP_STATE_RX; > > + > > + mctp->tx.addr = pkt->i2c.source; > > + mctp->tx.eid = pkt->mctp.hdr.eid.source; > > + mctp->tx.flags = pkt->mctp.hdr.flags & 0x7; > > Maybe worth either defining that mask, or adding a comment that this > is copying the msg tag. Or rename flags... > > > > + mctp->tx.pktseq = (pkt->mctp.hdr.flags >> 4) & 0x3; > > + > > + if ((pkt->mctp.payload[0] & 0x7f) == MCTP_MESSAGE_TYPE_CONTROL) { > > + mctp->tx.is_control = true; > > + > > + i2c_mctp_handle_control(mctp); > > + > > + return 0; > > + } > > + } else if (mctp->state == I2C_MCTP_STATE_RX_STARTED) { > > + trace_i2c_mctp_drop_expected_som(); > > + goto drop; > > + } else if (((pkt->mctp.hdr.flags >> 4) & 0x3) != (++mctp->tx.pktseq & 0x3)) { > > + trace_i2c_mctp_drop_invalid_pktseq((pkt->mctp.hdr.flags >> 4) & 0x3, > > + mctp->tx.pktseq & 0x3); > > + goto drop; > > + } > > + > > + mc->put_buf(mctp, i2c_mctp_payload(mctp->buffer), payload_len); > > + > > + if (pkt->mctp.hdr.flags & MCTP_H_FLAGS_EOM) { > > + mc->handle(mctp); > > + mctp->state = I2C_MCTP_STATE_WAIT_TX; > > + } > > + > > + return 0; > > + > > + default: > > + return -1; > > + } > > + > > +drop: > > + mc->reset(mctp); > > + > > + mctp->state = I2C_MCTP_STATE_IDLE; > > + > > + return 0; > > +} > > > > diff --git a/include/hw/i2c/mctp.h b/include/hw/i2c/mctp.h > > new file mode 100644 > > index 000000000000..ea97792e8d43 > > --- /dev/null > > +++ b/include/hw/i2c/mctp.h > > ... > > +struct MCTPI2CEndpointClass { > > + I2CSlaveClass parent_class; > > + > > + /** > > + * > > + * put_buf() - receive incoming message fragment > > + * > > + * Must returns 0 for succes or -1 for error. > > + */ > > + int (*put_buf)(MCTPI2CEndpoint *mctp, uint8_t *buf, size_t len); > > + > > + /** > > + * get_buf() - provide pointer to message fragment > > + * > > + * Called by the mctp subsystem to request a pointer to the next message > > + * fragment. The implementation must advance its internal position such > > + * that successive calls returns the next fragments. > > + * > > + * Must return the number of bytes available. > > + */ > > + size_t (*get_buf)(MCTPI2CEndpoint *mctp, const uint8_t **buf, > > + size_t maxlen, uint8_t *mctp_flags); > > + > > + /** > > + * handle() - handle an MCTP message > > + * > > + * Called by the mctp subsystem when a full message has been delivered and > > + * may be parsed and processed. > > + */ > > + void (*handle)(MCTPI2CEndpoint *mctp); > > + > > + /** > > + * reset() - reset internal state > > + * > > + * Called by the mctp subsystem in the event of some transport error. > > + * Implementation must reset its internal state and drop any fragments > > + * previously receieved. > > + */ > > + void (*reset)(MCTPI2CEndpoint *mctp); > > + > > + /** > > + * get_types() - provide supported mctp message types > > + * > > + * Must provide a buffer with a full MCTP supported message types payload > > + * (i.e. `0x0(SUCCESS),0x1(ONE),0x4(NMI)`). > > ONE? Looks to be PLDM > Good to reference DSP0239 Management Component Transport Protocol (MCTP) IDs and Codes > which has the list. Ah. 0x1 is the length. Call it "type count" instead of ONE and make it obvious. > > > + * > > + * Returns the size of the response. > > + */ > > + size_t (*get_types)(MCTPI2CEndpoint *mctp, const uint8_t **data); > > +}; > > > diff --git a/include/net/mctp.h b/include/net/mctp.h > > new file mode 100644 > > index 000000000000..70b49235ddb2 > > --- /dev/null > > +++ b/include/net/mctp.h > > @@ -0,0 +1,28 @@ > > +#ifndef QEMU_MCTP_H > > +#define QEMU_MCTP_H > > + > > +#define MCTP_BASELINE_MTU 64 > > Ideally add a reference for this as well. > > 8.3.1 Baseline transmission unit in DSP0236 1.3.0 > > + > > +enum { > > + MCTP_H_FLAGS_EOM = 1 << 6, > > + MCTP_H_FLAGS_SOM = 1 << 7, > > Trivial: I'm not really seeing the enum here as useful vs > a pair of defines. > > > +}; > > + > > +#define MCTP_MESSAGE_IC (1 << 7) > > + > > 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 DC114C77B73 for ; Wed, 31 May 2023 15:04:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q4NNK-0005qs-R1; Wed, 31 May 2023 11:04:34 -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 1q4NN8-0005eA-Cj; Wed, 31 May 2023 11:04:24 -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 1q4NN4-0002ss-Mc; Wed, 31 May 2023 11:04:20 -0400 Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4QWXYd6LQhz67fDB; Wed, 31 May 2023 23:02:29 +0800 (CST) Received: from localhost (10.202.227.76) 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; Wed, 31 May 2023 16:04:11 +0100 Date: Wed, 31 May 2023 16:04:10 +0100 To: Klaus Jensen CC: , Corey Minyard , "Keith Busch" , Jason Wang , Lior Weintraub , Paolo Bonzini , Jeremy Kerr , , Matt Johnston , Peter Delevoryas , , =?ISO-8859-1?Q?C=E9dric?= Le Goater , Klaus Jensen , Peter Maydell , Subject: Re: [PATCH v3 2/3] hw/i2c: add mctp core Message-ID: <20230531160410.0000305b@Huawei.com> In-Reply-To: <20230531155944.00006309@Huawei.com> References: <20230531114744.9946-1-its@irrelevant.dk> <20230531114744.9946-3-its@irrelevant.dk> <20230531155944.00006309@Huawei.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.227.76] X-ClientProxiedBy: lhrpeml500005.china.huawei.com (7.191.163.240) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On Wed, 31 May 2023 15:59:44 +0100 Jonathan Cameron wrote: > On Wed, 31 May 2023 13:47:43 +0200 > Klaus Jensen wrote: > > > From: Klaus Jensen > > > > Add an abstract MCTP over I2C endpoint model. This implements MCTP > > control message handling as well as handling the actual I2C transport > > (packetization). > > > > Devices are intended to derive from this and implement the class > > methods. > > > > Parts of this implementation is inspired by code[1] previously posted by > > Jonathan Cameron. > > > > Squashed a fix[2] from Matt Johnston. > > > > [1]: https://lore.kernel.org/qemu-devel/20220520170128.4436-1-Jonathan.Cameron@huawei.com/ > > [2]: https://lore.kernel.org/qemu-devel/20221121080445.GA29062@codeconstruct.com.au/ > > > > Signed-off-by: Klaus Jensen > Hi Klaus, > > A few minor comments inline. > > With those tidied up feel free to add > Reviewed-by: Jonathan Cameron > > > > > + > > + if (pkt->mctp.hdr.flags & MCTP_H_FLAGS_SOM) { > > + mctp->tx.is_control = false; > > + > > + if (mctp->state == I2C_MCTP_STATE_RX) { > > + mc->reset(mctp); > > + } > > + > > + mctp->state = I2C_MCTP_STATE_RX; > > + > > + mctp->tx.addr = pkt->i2c.source; > > + mctp->tx.eid = pkt->mctp.hdr.eid.source; > > + mctp->tx.flags = pkt->mctp.hdr.flags & 0x7; > > Maybe worth either defining that mask, or adding a comment that this > is copying the msg tag. Or rename flags... > > > > + mctp->tx.pktseq = (pkt->mctp.hdr.flags >> 4) & 0x3; > > + > > + if ((pkt->mctp.payload[0] & 0x7f) == MCTP_MESSAGE_TYPE_CONTROL) { > > + mctp->tx.is_control = true; > > + > > + i2c_mctp_handle_control(mctp); > > + > > + return 0; > > + } > > + } else if (mctp->state == I2C_MCTP_STATE_RX_STARTED) { > > + trace_i2c_mctp_drop_expected_som(); > > + goto drop; > > + } else if (((pkt->mctp.hdr.flags >> 4) & 0x3) != (++mctp->tx.pktseq & 0x3)) { > > + trace_i2c_mctp_drop_invalid_pktseq((pkt->mctp.hdr.flags >> 4) & 0x3, > > + mctp->tx.pktseq & 0x3); > > + goto drop; > > + } > > + > > + mc->put_buf(mctp, i2c_mctp_payload(mctp->buffer), payload_len); > > + > > + if (pkt->mctp.hdr.flags & MCTP_H_FLAGS_EOM) { > > + mc->handle(mctp); > > + mctp->state = I2C_MCTP_STATE_WAIT_TX; > > + } > > + > > + return 0; > > + > > + default: > > + return -1; > > + } > > + > > +drop: > > + mc->reset(mctp); > > + > > + mctp->state = I2C_MCTP_STATE_IDLE; > > + > > + return 0; > > +} > > > > diff --git a/include/hw/i2c/mctp.h b/include/hw/i2c/mctp.h > > new file mode 100644 > > index 000000000000..ea97792e8d43 > > --- /dev/null > > +++ b/include/hw/i2c/mctp.h > > ... > > +struct MCTPI2CEndpointClass { > > + I2CSlaveClass parent_class; > > + > > + /** > > + * > > + * put_buf() - receive incoming message fragment > > + * > > + * Must returns 0 for succes or -1 for error. > > + */ > > + int (*put_buf)(MCTPI2CEndpoint *mctp, uint8_t *buf, size_t len); > > + > > + /** > > + * get_buf() - provide pointer to message fragment > > + * > > + * Called by the mctp subsystem to request a pointer to the next message > > + * fragment. The implementation must advance its internal position such > > + * that successive calls returns the next fragments. > > + * > > + * Must return the number of bytes available. > > + */ > > + size_t (*get_buf)(MCTPI2CEndpoint *mctp, const uint8_t **buf, > > + size_t maxlen, uint8_t *mctp_flags); > > + > > + /** > > + * handle() - handle an MCTP message > > + * > > + * Called by the mctp subsystem when a full message has been delivered and > > + * may be parsed and processed. > > + */ > > + void (*handle)(MCTPI2CEndpoint *mctp); > > + > > + /** > > + * reset() - reset internal state > > + * > > + * Called by the mctp subsystem in the event of some transport error. > > + * Implementation must reset its internal state and drop any fragments > > + * previously receieved. > > + */ > > + void (*reset)(MCTPI2CEndpoint *mctp); > > + > > + /** > > + * get_types() - provide supported mctp message types > > + * > > + * Must provide a buffer with a full MCTP supported message types payload > > + * (i.e. `0x0(SUCCESS),0x1(ONE),0x4(NMI)`). > > ONE? Looks to be PLDM > Good to reference DSP0239 Management Component Transport Protocol (MCTP) IDs and Codes > which has the list. Ah. 0x1 is the length. Call it "type count" instead of ONE and make it obvious. > > > + * > > + * Returns the size of the response. > > + */ > > + size_t (*get_types)(MCTPI2CEndpoint *mctp, const uint8_t **data); > > +}; > > > diff --git a/include/net/mctp.h b/include/net/mctp.h > > new file mode 100644 > > index 000000000000..70b49235ddb2 > > --- /dev/null > > +++ b/include/net/mctp.h > > @@ -0,0 +1,28 @@ > > +#ifndef QEMU_MCTP_H > > +#define QEMU_MCTP_H > > + > > +#define MCTP_BASELINE_MTU 64 > > Ideally add a reference for this as well. > > 8.3.1 Baseline transmission unit in DSP0236 1.3.0 > > + > > +enum { > > + MCTP_H_FLAGS_EOM = 1 << 6, > > + MCTP_H_FLAGS_SOM = 1 << 7, > > Trivial: I'm not really seeing the enum here as useful vs > a pair of defines. > > > +}; > > + > > +#define MCTP_MESSAGE_IC (1 << 7) > > + > >