From patchwork Mon Nov 6 11:03:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 741386 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp1039368wrr; Mon, 6 Nov 2023 03:50:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IHff0j4DartVWXAEyrqt6DZTQc8gTLuQVs5RbzQ+osTb8Q/mrfR3o3VzC7bWnU9p8QQ029X X-Received: by 2002:ac8:4e96:0:b0:41e:2b64:11f5 with SMTP id 22-20020ac84e96000000b0041e2b6411f5mr34912749qtp.68.1699271459384; Mon, 06 Nov 2023 03:50:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699271459; cv=none; d=google.com; s=arc-20160816; b=B0VkXNmHQH7b5/eTvUdOTbs7Qz4ioCVRBrsRftcR9aYDdnOev6JjfseatXkiwl/buh Era9JadXlHf/rT+XLwRzxJ1bJDquXYCEMqxnfFiSoeXFIPJKm0A57EXPhyB+XEv2kXs0 k8z0ZGXSvcRqt5kMQinda6gK3Dcppl3JN4O+UGF1uL2Kbhzf2GowaUFIwcOj7ARI9OAK Aun3XkKnbHaK7F1b+3+2lzLI+syqVUhq4lFyzW8H2zSpSYom2Qottjfcg3OykHT0rK7u YwQB0dR9r3tk9OLhb7PYcB0i0WXHuRh5ZInWURp/F7U2kb7rrfTD/bXpH0DPGLP0WZbD zM5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gh2da5PI+FWVTGRmyCu8rnn16q3Vdl/J/DOzB/U83Dc=; fh=c1Hsd908U9PKLwue3PgIR6OEtkIdu11a71wsyXYOJoE=; b=cI1hQCjl4kKouOr9FzJIPT6nZri6B3RnVkygKt+z+oEfhvfx0qT5dNckuIzY8g77gf czmXyzlUsFnuEAhgTu2rtKNEmAw2MuYZVcZMjVfynk4zG73jie25Ecdii70p5qoWynv6 TxIqN+q6XI8XLBM3YvOEfUHMrDETfOt8vbeYumEZPFT0h7dmvYEnSfpSHU4rIr7xb9Hi pYnWQxkUnr8KCCzBWTOcXZaP4Q5FX//ZJdNo905gHdaCLvpBL8hPtEZfELOKrHKPFDEE Ax6rU4TbQu9o0JJrKSn/rIMucRI4pgv67gQavhCtC5OfnIqBdT5qVhZ63clCHbpDeWWm Wxpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HIimFuQv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t2-20020a05622a180200b004181b434f3esi5596931qtc.147.2023.11.06.03.50.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Nov 2023 03:50:59 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HIimFuQv; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qzxTv-0008W0-Ce; Mon, 06 Nov 2023 06:09:23 -0500 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 1qzxTt-0008JW-KL for qemu-devel@nongnu.org; Mon, 06 Nov 2023 06:09:21 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qzxTn-0005OF-4G for qemu-devel@nongnu.org; Mon, 06 Nov 2023 06:09:21 -0500 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-32fdc5be26dso58881f8f.2 for ; Mon, 06 Nov 2023 03:09:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699268953; x=1699873753; 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=gh2da5PI+FWVTGRmyCu8rnn16q3Vdl/J/DOzB/U83Dc=; b=HIimFuQvk6iTv5qCGB/EnbHhUITjNTjDzAej5T/jYn84/Z60WETbG882sWWeeCuAjp DuJgYu7oFhySdxMvbMzRVMD0+Ac2oO46E1aX3nvJcQWAYGJzha2TMR5tPZX7HgbPc3K6 zkkcm3/ULvpovhbJ5SgyXehOOoh2ODv4QYtyyXDim6MPTv1DfsQ3vCn2M1xnz1pdYDlr NeAgcqb63KmB9tbAI+gHh5gnGpApa8cEj2MyupVqgWo107l/6i/XwVB8NNpNYDcxDq3j GBv91S/KgCAJUXrM7G7WWuu7S/kVp3Y+OTimqlXhK6wYS6eJC6tGwVksLUCghw8ZF/LB 5a9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699268953; x=1699873753; 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=gh2da5PI+FWVTGRmyCu8rnn16q3Vdl/J/DOzB/U83Dc=; b=olp8YmyLjy2Ep6+IPbpIIBtJ1kRvEOkr28AAzU88UTtMNlUyy3t6UhivXUUFyPG5LB iAQlt1ChFOydzvM9w/ofl5ceCLh3o7eM1t4ehbR/NcQuqWTEosEDZbpj6qaC7paTaphu E1630AQvTyDXqVtAwoftxfrHTrM4uNpl1tAUBq5Ka6V/k2UtNilnmwOnhRDrlnnK/jHD zsVP/5kNVmRdcYrYx/OXIZ2vdnUuGKubENaHYjbYRlxH62ECqr8wD0kx1BP1CSSFI77t yukLIE6ihQfpyyVcP+pCqvq1u6PMddCXOE9hLla4pWSD5gZOcctqYYwE0BgjO+ofvExM sxqg== X-Gm-Message-State: AOJu0YyDjB6T3cn3oJLvCV//yKRv3WV3d9xQ/ZAKnyqi1SiUMnSKmgxw YGYBFaq7tLE6HbOa1SqfJW8rZ7XUQdbhkv8+szc= X-Received: by 2002:a5d:5a06:0:b0:32d:a101:689d with SMTP id bq6-20020a5d5a06000000b0032da101689dmr35272735wrb.56.1699268953327; Mon, 06 Nov 2023 03:09:13 -0800 (PST) Received: from m1x-phil.lan (176-131-220-199.abo.bbox.fr. [176.131.220.199]) by smtp.gmail.com with ESMTPSA id j17-20020a056000125100b0032db4e660d9sm9181558wrx.56.2023.11.06.03.09.11 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 06 Nov 2023 03:09:12 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, qemu-s390x@nongnu.org, qemu-block@nongnu.org, qemu-riscv@nongnu.org, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, Titus Rwantare , Hao Wu , Corey Minyard , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 49/60] hw/i2c: pmbus add support for block receive Date: Mon, 6 Nov 2023 12:03:21 +0100 Message-ID: <20231106110336.358-50-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231106110336.358-1-philmd@linaro.org> References: <20231106110336.358-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=philmd@linaro.org; helo=mail-wr1-x433.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Titus Rwantare PMBus devices can send and receive variable length data using the block read and write format, with the first byte in the payload denoting the length. This is mostly used for strings and on-device logs. Devices can respond to a block read with an empty string. Reviewed-by: Hao Wu Acked-by: Corey Minyard Signed-off-by: Titus Rwantare Message-ID: <20231023-staging-pmbus-v3-v4-1-07a8cb7cd20a@google.com> Signed-off-by: Philippe Mathieu-Daudé --- include/hw/i2c/pmbus_device.h | 7 +++++++ hw/i2c/pmbus_device.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/hw/i2c/pmbus_device.h b/include/hw/i2c/pmbus_device.h index 93f5d57c9d..7dc00cc4d9 100644 --- a/include/hw/i2c/pmbus_device.h +++ b/include/hw/i2c/pmbus_device.h @@ -501,6 +501,13 @@ void pmbus_send64(PMBusDevice *state, uint64_t data); */ void pmbus_send_string(PMBusDevice *state, const char *data); +/** + * @brief Receive data sent with Block Write. + * @param dest - memory with enough capacity to receive the write + * @param len - the capacity of dest + */ +uint8_t pmbus_receive_block(PMBusDevice *pmdev, uint8_t *dest, size_t len); + /** * @brief Receive data over PMBus * These methods help track how much data is being received over PMBus diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index cef51663d0..ea15490720 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -102,7 +102,6 @@ void pmbus_send_string(PMBusDevice *pmdev, const char *data) } size_t len = strlen(data); - g_assert(len > 0); g_assert(len + pmdev->out_buf_len < SMBUS_DATA_MAX_LEN); pmdev->out_buf[len + pmdev->out_buf_len] = len; @@ -112,6 +111,35 @@ void pmbus_send_string(PMBusDevice *pmdev, const char *data) pmdev->out_buf_len += len + 1; } +uint8_t pmbus_receive_block(PMBusDevice *pmdev, uint8_t *dest, size_t len) +{ + /* dest may contain data from previous writes */ + memset(dest, 0, len); + + /* Exclude command code from return value */ + pmdev->in_buf++; + pmdev->in_buf_len--; + + /* The byte after the command code denotes the length */ + uint8_t sent_len = pmdev->in_buf[0]; + + if (sent_len != pmdev->in_buf_len - 1) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: length mismatch. Expected %d bytes, got %d bytes\n", + __func__, sent_len, pmdev->in_buf_len - 1); + } + + /* exclude length byte */ + pmdev->in_buf++; + pmdev->in_buf_len--; + + if (pmdev->in_buf_len < len) { + len = pmdev->in_buf_len; + } + memcpy(dest, pmdev->in_buf, len); + return len; +} + static uint64_t pmbus_receive_uint(PMBusDevice *pmdev) {