Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp763515rdh; Wed, 14 Feb 2024 10:32:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWpPtG8Q/uF4lREgjM66G3nRrcA8YlrsKL51iCmhmYB8h07KJGcak16HHZGMGuCq6Nd7upPl1d1bgVnJaDaB7Q91xH0HFE0cNowz9C0rg== X-Google-Smtp-Source: AGHT+IEZTKxb1Nm8n88YaBzgvVPoyiqscmg51FkREsKPD7ATHNFZtyeemESXmdFELfq4ATBVB3H5 X-Received: by 2002:a05:620a:559a:b0:785:96a6:f6ce with SMTP id vq26-20020a05620a559a00b0078596a6f6cemr3707100qkn.43.1707935569125; Wed, 14 Feb 2024 10:32:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707935569; cv=pass; d=google.com; s=arc-20160816; b=Y2rv/kXKWerjd5/aUE+VAHe5/Bxx5q8TPlmL/vp6UyT/y0+sNKR6fngL0p8be3oLdc cZ7ClbCtFICdaGs7OBxFyLQzpLwuKx5MJH5oZdt6yDaqf2Y4gFxPIRrqrFw6jqSeMhGZ wyn+H3PGncCNGhbVJe8J3lzEC2+lf2zlQlWArTKoS5SkYZff+MAjEJ3fvcsgPzbVLklV l5LZlvQCWOZxUeP/KjffdyhJBwf5wFFNgv63DJO44QOHMteORFv7zgwozkL6TqEzDAgY InkD+EHPqJsxJVkhliKhonPKcc/VE4Efxa82X5G6H1Q3UHkr1YJtDqQYY1yCiTiH+qjW 1uCw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=o14Bb/oC0Qo9Jp9ofAndjhxNDXONL9Kdjgv1ch1gFb8=; fh=NCOHr0qLyV9WXjodN5dKE0TRMqlehklxW1EnBHx7DDM=; b=FEpqemiEjtzQmc708xPasJW90SV92SDjBIdM/Pp8HsnmAnPlZhS29BZo9RL8X805Kz wwlUVNG95nOtvnPe2VkRqjINGu523s/gcAB9fI0VYiOMNhmHkVkuQPvUbJ6SPBOIKW34 CsGZo2b2TL8xXov1Yg9DQLzPQbsbVNVgh1/rmKQdR2xsuMTHmx/TH5fBujOLNOPxGJyk i/MPvhMmazmQtzuow3Otsc7DCixKLaHsKEcj81wgpJI4A9ZcS8kJFZDPM01xgFfRqbvT 4Ud+t5AgY1Sedn/Z0G2dc9QrJ2ptXnylN6MjjTVdpkotUQ3yVMmXjt8ZP8AwNoJcx6cv Q/Fg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-65806-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65806-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVrcWloYjpOHP9PT76ONmVM5Kq+xickDaDyNl7v1KCmCHaH5w2DkBPVCGYojfKpj26Z0GMY24fgjfMCODKBest8sYOV+WEokJstsYjPrQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u10-20020a05620a084a00b007871aa88a2csi4519938qku.585.2024.02.14.10.32.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 10:32:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65806-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-65806-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65806-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 90C3B1C294FB for ; Wed, 14 Feb 2024 18:30:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D0F5612C815; Wed, 14 Feb 2024 18:30:37 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3FC1612BF1C for ; Wed, 14 Feb 2024 18:30:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935437; cv=none; b=HmageslhNHufQEYklkOly2FwqQPsoEymNTgyF/A0T0wXolX0WfZBTOncn3NZg4cuHSdfdcSJKZZDzXVM/2TLF6UzNL/fTwhXKkKeBQnnrxoe7MSe4QdWGaEb9lr+Bm3KA30koC4HdfC1SzR3jQFeknsU2cRdf/zFhu9e+s8sfrc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707935437; c=relaxed/simple; bh=aLQIYcBnbK+esT1CQfwNNNQB4YwDBeNIL7pYpzFWpYU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ivQzZYg3ShBEs1x34ivgVP0H+TDV5O43nQDbySxMrYts2ilFGWkAoyA3kZNQ4blHEKDxKEXdmLMgMIGbCC2pp4esMyokH80iJ7DU+nIE/pONMt9f8KAZT7Ye/qH9HmLcP0GXye/1sbBxG9ICXdFrsJspBI94k5OSAUEsEsQFnZM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B94A1476; Wed, 14 Feb 2024 10:31:15 -0800 (PST) Received: from pluto.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DC2173F7B4; Wed, 14 Feb 2024 10:30:32 -0800 (PST) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, f.fainelli@gmail.com, vincent.guittot@linaro.org, peng.fan@oss.nxp.com, michal.simek@amd.com, quic_sibis@quicinc.com, quic_nkela@quicinc.com, souvik.chakravarty@arm.com, Cristian Marussi Subject: [PATCH 2/7] firmware: arm_scmi: Add support for v3.2 NEGOTIATE_PROTOCOL_VERSION Date: Wed, 14 Feb 2024 18:30:01 +0000 Message-ID: <20240214183006.3403207-3-cristian.marussi@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240214183006.3403207-1-cristian.marussi@arm.com> References: <20240214183006.3403207-1-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Freshly introduced NEGOTIATE_PROTOCOL_VERSION allows the agent to ascertain upfront if a specific, usually older, protocol version is supported by the platform. It is used by the agent in case the platform has advertised the support of a newer protocol version than the latest version supported by the agent, since backward compatibility cannot be automatically assumed. Emit a warning about possible incompatibility when negotiation was not possible or just print the successfully negotiated protocol. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/driver.c | 65 ++++++++++++++++++++++++--- drivers/firmware/arm_scmi/protocols.h | 1 + 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 4a64ad5c21ee..34d77802c990 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -86,6 +86,12 @@ struct scmi_xfers_info { * @users: A refcount to track effective users of this protocol. * @priv: Reference for optional protocol private data. * @version: Protocol version supported by the platform as detected at runtime. + * @negotiated_version: When the platform supports a newer protocol version, + * the agent will try to negotiate with the platform the + * usage of the newest version known to it, since + * backward compatibility is NOT automatically assured. + * This field is NON-zero when a successful negotiation + * has completed. * @ph: An embedded protocol handle that will be passed down to protocol * initialization code to identify this instance. * @@ -99,6 +105,7 @@ struct scmi_protocol_instance { refcount_t users; void *priv; unsigned int version; + unsigned int negotiated_version; struct scmi_protocol_handle ph; }; @@ -1815,6 +1822,44 @@ scmi_revision_area_get(const struct scmi_protocol_handle *ph) return pi->handle->version; } +/** + * scmi_protocol_version_negotiate - Negotiate protocol version + * + * @ph: A reference to the protocol handle. + * + * An helper to negotiate a protocol version different from the latest + * advertised as supported from the platform: on Success backward + * compatibility is assured by the platform. + * + * Return: 0 on Success + */ +static int scmi_protocol_version_negotiate(struct scmi_protocol_handle *ph) +{ + int ret; + struct scmi_xfer *t; + struct scmi_protocol_instance *pi = ph_to_pi(ph); + + /* At first check if NEGOTIATE_PROTOCOL_VERSION is supported ... */ + ret = scmi_protocol_msg_check(ph, NEGOTIATE_PROTOCOL_VERSION, NULL); + if (ret) + return ret; + + /* ... then attempt protocol version negotiation */ + ret = xfer_get_init(ph, NEGOTIATE_PROTOCOL_VERSION, + sizeof(__le32), 0, &t); + if (ret) + return ret; + + put_unaligned_le32(pi->proto->supported_version, t->tx.buf); + ret = do_xfer(ph, t); + if (!ret) + pi->negotiated_version = pi->proto->supported_version; + + xfer_put(ph, t); + + return ret; +} + /** * scmi_alloc_init_protocol_instance - Allocate and initialize a protocol * instance descriptor. @@ -1887,11 +1932,21 @@ scmi_alloc_init_protocol_instance(struct scmi_info *info, devres_close_group(handle->dev, pi->gid); dev_dbg(handle->dev, "Initialized protocol: 0x%X\n", pi->proto->id); - if (pi->version > proto->supported_version) - dev_warn(handle->dev, - "Detected UNSUPPORTED higher version 0x%X for protocol 0x%X." - "Backward compatibility is NOT assured.\n", - pi->version, pi->proto->id); + if (pi->version > proto->supported_version) { + ret = scmi_protocol_version_negotiate(&pi->ph); + if (!ret) { + dev_info(handle->dev, + "Protocol 0x%X successfully negotiated version 0x%X\n", + proto->id, pi->negotiated_version); + } else { + dev_warn(handle->dev, + "Detected UNSUPPORTED higher version 0x%X for protocol 0x%X.\n", + pi->version, pi->proto->id); + dev_warn(handle->dev, + "Trying version 0x%X. Backward compatibility is NOT assured.\n", + pi->proto->supported_version); + } + } return pi; diff --git a/drivers/firmware/arm_scmi/protocols.h b/drivers/firmware/arm_scmi/protocols.h index 26a3edd49fea..693019fff0f6 100644 --- a/drivers/firmware/arm_scmi/protocols.h +++ b/drivers/firmware/arm_scmi/protocols.h @@ -33,6 +33,7 @@ enum scmi_common_cmd { PROTOCOL_VERSION = 0x0, PROTOCOL_ATTRIBUTES = 0x1, PROTOCOL_MESSAGE_ATTRIBUTES = 0x2, + NEGOTIATE_PROTOCOL_VERSION = 0x10, }; /** -- 2.43.0