From patchwork Fri Sep 18 16:46:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 11785453 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6218659D for ; Fri, 18 Sep 2020 16:48:50 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 33DA620872 for ; Fri, 18 Sep 2020 16:48:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="1ai0ob8M" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 33DA620872 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=yAp3GZo7NomzE6V1JoVDfZJvNspyahL87OAng8Xvkrc=; b=1ai0ob8M/2EHJoAOfqOY9DQiT HEaW90zVYxOeeHnLbaLk5MsnWMe1pwQ4hv1Yk2qbpQRg0+q6+lfzncgxeK3+nH2kjOOaFKbjWhUnK DgPs+4i03o9XWymI2ene9ang3jNG+WcYwn5s9SBiR3YXmFAtWbUJS1XshekIjFZHY5CLwVhtDn70q N4BSa6IuD6Sh2HCWIs0xA8pxkitGXYcOwOsRCOSNYjhNGjMP3A2skvAFoxsCmoMA9kwY2EjjETxgX 8y3iAtm72P5MRE3I9VVSj8AHorvHCwqPjH4I0wnHruBtdm2MPex78v5XYt755IlN0gQGNZoTlZiV/ rjmsW5pNA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJJXK-0006hg-GT; Fri, 18 Sep 2020 16:47:02 +0000 Received: from plasma31.jpberlin.de ([80.241.56.82]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJJXB-0006eU-Lm for linux-arm-kernel@lists.infradead.org; Fri, 18 Sep 2020 16:46:56 +0000 Received: from gerste.heinlein-support.de (unknown [80.241.56.124]) by plasma.jpberlin.de (Postfix) with ESMTP id 2C2E4100D7A; Fri, 18 Sep 2020 18:46:50 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from plasma.jpberlin.de ([80.241.56.76]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id YVw5KSDCwv_e; Fri, 18 Sep 2020 18:46:48 +0200 (CEST) Received: from webmail.opensynergy.com (unknown [217.66.60.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client CN "*.opensynergy.com", Issuer "Starfield Secure Certificate Authority - G2" (not verified)) (Authenticated sender: opensynergy@jpberlin.de) by plasma.jpberlin.de (Postfix) with ESMTPSA id 313B8100C91; Fri, 18 Sep 2020 18:46:48 +0200 (CEST) From: Peter Hilber To: , Subject: [RFC PATCH 1/7] firmware: arm_scmi, smccc, mailbox: Make shmem based transports optional Date: Fri, 18 Sep 2020 18:46:16 +0200 Message-ID: <20200918164617.256356-1-peter.hilber@opensynergy.com> In-Reply-To: <20200918162311.254564-1-peter.hilber@opensynergy.com> References: <20200918162311.254564-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-01.open-synergy.com (10.26.10.21) X-MBO-SPAM-Probability: * X-Rspamd-Score: 0.94 / 15.00 / 15.00 X-Rspamd-Queue-Id: 2C2E4100D7A X-Rspamd-UID: d174ef X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200918_124653_961866_26A9C4BA X-CRM114-Status: GOOD ( 18.66 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.82 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [80.241.56.82 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , jean-philippe@linaro.org, mikhail.golubev@opensynergy.com, Lorenzo Pieralisi , souvik.chakravarty@arm.com, igor.skalkin@opensynergy.com, Jassi Brar , linux-kernel@vger.kernel.org, Rob Herring , Peter Hilber , anton.yakovlev@opensynergy.com, sudeep.holla@arm.com, alex.bennee@linaro.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Igor Skalkin Upon adding the virtio transport in this patch series, SCMI will also work without shared memory based transports. Also, the mailbox transport may not be needed if the smc transport is used. - Compile shmem.c only if a shmem based transport is available. - Remove hard dependency of SCMI on mailbox. Co-developed-by: Peter Hilber Signed-off-by: Peter Hilber Signed-off-by: Igor Skalkin --- drivers/firmware/Kconfig | 9 ++++++++- drivers/firmware/arm_scmi/Makefile | 2 +- drivers/firmware/arm_scmi/common.h | 2 ++ drivers/firmware/arm_scmi/driver.c | 2 ++ drivers/firmware/smccc/Kconfig | 1 + drivers/mailbox/Kconfig | 1 + 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index afdbebba628a..bdde51adb267 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -9,7 +9,7 @@ menu "Firmware Drivers" config ARM_SCMI_PROTOCOL tristate "ARM System Control and Management Interface (SCMI) Message Protocol" depends on ARM || ARM64 || COMPILE_TEST - depends on MAILBOX + depends on ARM_SCMI_HAVE_SHMEM help ARM System Control and Management Interface (SCMI) protocol is a set of operating system-independent software interfaces that are @@ -27,6 +27,13 @@ config ARM_SCMI_PROTOCOL This protocol library provides interface for all the client drivers making use of the features offered by the SCMI. +config ARM_SCMI_HAVE_SHMEM + bool + default n + help + This declares whether a shared memory based transport for SCMI is + available. + config ARM_SCMI_POWER_DOMAIN tristate "SCMI power domain driver" depends on ARM_SCMI_PROTOCOL || (COMPILE_TEST && OF) diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile index bc0d54f8e861..3cc7fa40a464 100644 --- a/drivers/firmware/arm_scmi/Makefile +++ b/drivers/firmware/arm_scmi/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only scmi-bus-y = bus.o scmi-driver-y = driver.o notify.o -scmi-transport-y = shmem.o +scmi-transport-$(CONFIG_ARM_SCMI_HAVE_SHMEM) = shmem.o scmi-transport-$(CONFIG_MAILBOX) += mailbox.o scmi-transport-$(CONFIG_HAVE_ARM_SMCCC_DISCOVERY) += smc.o scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o system.o diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 37fb583f1bf5..36c38334a045 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -240,7 +240,9 @@ struct scmi_desc { int max_msg_size; }; +#ifdef CONFIG_MAILBOX extern const struct scmi_desc scmi_mailbox_desc; +#endif #ifdef CONFIG_HAVE_ARM_SMCCC extern const struct scmi_desc scmi_smc_desc; #endif diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index c5dea87edf8f..d070687cf2f6 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -910,7 +910,9 @@ ATTRIBUTE_GROUPS(versions); /* Each compatible listed below must have descriptor associated with it */ static const struct of_device_id scmi_of_match[] = { +#ifdef CONFIG_MAILBOX { .compatible = "arm,scmi", .data = &scmi_mailbox_desc }, +#endif #ifdef CONFIG_HAVE_ARM_SMCCC_DISCOVERY { .compatible = "arm,scmi-smc", .data = &scmi_smc_desc}, #endif diff --git a/drivers/firmware/smccc/Kconfig b/drivers/firmware/smccc/Kconfig index 15e7466179a6..69c4d6cabf62 100644 --- a/drivers/firmware/smccc/Kconfig +++ b/drivers/firmware/smccc/Kconfig @@ -9,6 +9,7 @@ config HAVE_ARM_SMCCC_DISCOVERY bool depends on ARM_PSCI_FW default y + select ARM_SCMI_HAVE_SHMEM help SMCCC v1.0 lacked discoverability and hence PSCI v1.0 was updated to add SMCCC discovery mechanism though the PSCI firmware diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig index 05b1009e2820..5ffe1ab0c869 100644 --- a/drivers/mailbox/Kconfig +++ b/drivers/mailbox/Kconfig @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only menuconfig MAILBOX bool "Mailbox Hardware Support" + select ARM_SCMI_HAVE_SHMEM help Mailbox is a framework to control hardware communication between on-chip processors through queued messages and interrupt driven From patchwork Fri Sep 18 16:52:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 11785583 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D086D6CB for ; Fri, 18 Sep 2020 18:02:45 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7E7D721734 for ; Fri, 18 Sep 2020 18:02:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="VW2ndJHV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7E7D721734 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=UhmerWEtbQ2ThTR1IyVpo4McylleNKXEq07Z+md70vQ=; b=VW2ndJHVmgnfFwB54eSurUi0g 6zkcrkeh0uLeuYE7dbPBIWp3nokAQYKWAU0V7Iv4/U9Q1nDbgV0rIDgBz9h/gy0oipqVO39RhBR9R HDo5yOfoNfOhRCINwuJedV+rc+doOr958lE5hcfZzXMl3crWfFcjBqUkTdSF/8LyvpGnXD8pdJl2j zdDqIo4pOJOOUTvwPASniAuc5v+EukpMqiaWINRvj+ba6suVoYU/VAW5aUnLn6WApYfDw8EfTCYVv 75CjM9EUReaWjAjY6IAQcvFduW3KEKR28Pa5/aHhrYnCS4sBCeKuz9OVQHeLkc7ZD63De7THj4arJ QGfdwB8+w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJKhK-0002oY-7t; Fri, 18 Sep 2020 18:01:26 +0000 Received: from plasma31.jpberlin.de ([80.241.56.82]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJJe0-0001jh-A6 for linux-arm-kernel@lists.infradead.org; Fri, 18 Sep 2020 16:53:59 +0000 Received: from spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) by plasma.jpberlin.de (Postfix) with ESMTP id 6AADA10155D; Fri, 18 Sep 2020 18:53:51 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from plasma.jpberlin.de ([80.241.56.76]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id q5yVNH_U4n5l; Fri, 18 Sep 2020 18:53:50 +0200 (CEST) Received: from webmail.opensynergy.com (unknown [217.66.60.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client CN "*.opensynergy.com", Issuer "Starfield Secure Certificate Authority - G2" (not verified)) (Authenticated sender: opensynergy@jpberlin.de) by plasma.jpberlin.de (Postfix) with ESMTPSA id 6ED8A100F02; Fri, 18 Sep 2020 18:53:50 +0200 (CEST) From: Peter Hilber To: , Subject: [RFC PATCH 2/7] firmware: arm_scmi: Document that max_msg is a per channel type limit Date: Fri, 18 Sep 2020 18:52:51 +0200 Message-ID: <20200918165251.256802-1-peter.hilber@opensynergy.com> In-Reply-To: <20200918162311.254564-1-peter.hilber@opensynergy.com> References: <20200918162311.254564-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-01.open-synergy.com (10.26.10.21) X-MBO-SPAM-Probability: X-Rspamd-Score: -1.83 / 15.00 / 15.00 X-Rspamd-Queue-Id: 6AADA10155D X-Rspamd-UID: 4de0b1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200918_125356_719105_9DA16875 X-CRM114-Status: GOOD ( 15.14 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.82 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [80.241.56.82 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jean-philippe@linaro.org, mikhail.golubev@opensynergy.com, souvik.chakravarty@arm.com, igor.skalkin@opensynergy.com, linux-kernel@vger.kernel.org, Rob Herring , Peter Hilber , anton.yakovlev@opensynergy.com, sudeep.holla@arm.com, alex.bennee@linaro.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Igor Skalkin struct scmi_desc.max_msg specifies a limit for the pending messages. This limit is a per SCMI channel type (tx, rx) limit. State that explicitly in the inline documentation. The following patch will add an op to override the limit per channel type. Co-developed-by: Peter Hilber Signed-off-by: Peter Hilber Signed-off-by: Igor Skalkin --- drivers/firmware/arm_scmi/common.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 36c38334a045..4cc78eb27f14 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -229,8 +229,8 @@ struct scmi_transport_ops { * * @ops: Pointer to the transport specific ops structure * @max_rx_timeout_ms: Timeout for communication with SoC (in Milliseconds) - * @max_msg: Maximum number of messages that can be pending - * simultaneously in the system + * @max_msg: Maximum number of messages for a channel type (tx or rx) that can + * be pending simultaneously in the system * @max_msg_size: Maximum size of data per message that can be handled. */ struct scmi_desc { From patchwork Fri Sep 18 16:53:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 11785519 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 157E0112E for ; Fri, 18 Sep 2020 16:59:25 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B52F0208DB for ; Fri, 18 Sep 2020 16:59:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GJIr+Jpn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B52F0208DB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Ofl3pN303Z8D539UnJSBO9Tuz9WPFFiXI9bMMPQUPrk=; b=GJIr+JpnCxJwnR1FIdtifpSsC se6zCHljfizeINOZ4nmS39rX4J13Du5v8RwUhh+y3xz0KHMLx6BDlDqdStqdOHxR7h+2O3ZlapV1T Np5MLGnGvZUz5VY6DyBwbjOpYW2aQExc9UsaB6EE8JbuG0lNlFwBNx3FVRj4PhAHHZTIFqB3eS+mc aFn3G4/JHw733rQ8Lpp3Wdc1+XPESHST9bHLgm2CLqLOko3V7MG5OA/ENMTG1JfcACjEaO31gGTZY E5uj5fismnyG60rlG+dA9HqZ0wM2dRA7uM5Q5LckLugSsyC5xiaFDXMphoSeTAnYg51q4VnZicmlH /prCFfwYw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJJgo-00036q-7V; Fri, 18 Sep 2020 16:56:50 +0000 Received: from plasma31.jpberlin.de ([80.241.56.82]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJJeo-0002BN-Lb for linux-arm-kernel@lists.infradead.org; Fri, 18 Sep 2020 16:54:49 +0000 Received: from spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) by plasma.jpberlin.de (Postfix) with ESMTP id CD9AE1018B5; Fri, 18 Sep 2020 18:54:42 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from plasma.jpberlin.de ([80.241.56.76]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id dKLDcAmeklFh; Fri, 18 Sep 2020 18:54:41 +0200 (CEST) Received: from webmail.opensynergy.com (unknown [217.66.60.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client CN "*.opensynergy.com", Issuer "Starfield Secure Certificate Authority - G2" (not verified)) (Authenticated sender: opensynergy@jpberlin.de) by plasma.jpberlin.de (Postfix) with ESMTPSA id 6BE50100E7E; Fri, 18 Sep 2020 18:54:41 +0200 (CEST) From: Peter Hilber To: , Subject: [RFC PATCH 3/7] firmware: arm_scmi: Add op to override max message # Date: Fri, 18 Sep 2020 18:53:50 +0200 Message-ID: <20200918165350.256878-1-peter.hilber@opensynergy.com> In-Reply-To: <20200918162311.254564-1-peter.hilber@opensynergy.com> References: <20200918162311.254564-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-01.open-synergy.com (10.26.10.21) X-MBO-SPAM-Probability: X-Rspamd-Score: -3.70 / 15.00 / 15.00 X-Rspamd-Queue-Id: CD9AE1018B5 X-Rspamd-UID: 9ad3d5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200918_125447_182289_5291C95B X-CRM114-Status: GOOD ( 22.49 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [80.241.56.82 listed in wl.mailspike.net] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.82 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jean-philippe@linaro.org, mikhail.golubev@opensynergy.com, souvik.chakravarty@arm.com, igor.skalkin@opensynergy.com, linux-kernel@vger.kernel.org, Rob Herring , Peter Hilber , anton.yakovlev@opensynergy.com, sudeep.holla@arm.com, alex.bennee@linaro.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Igor Skalkin The number of messages that the upcoming scmi-virtio transport can support depends on the virtio device (SCMI platform) and can differ for each channel. (The scmi-virtio transport does only have one tx and at most 1 rx channel.) Add an optional transport op so that scmi-virtio can report the actual max message # for each channel type. Respect these new limits. Co-developed-by: Peter Hilber Signed-off-by: Peter Hilber Signed-off-by: Igor Skalkin --- drivers/firmware/arm_scmi/common.h | 8 ++++- drivers/firmware/arm_scmi/driver.c | 49 ++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 4cc78eb27f14..0f1540cb2d84 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -201,6 +201,9 @@ struct scmi_chan_info { * @chan_available: Callback to check if channel is available or not * @chan_setup: Callback to allocate and setup a channel * @chan_free: Callback to free a channel + * @get_max_msg: Optional callback to provide max_msg dynamically + * @max_msg: Maximum number of messages for the channel type (tx or rx) + * that can be pending simultaneously in the system * @send_message: Callback to send a message * @mark_txdone: Callback to mark tx as done * @fetch_response: Callback to fetch response @@ -213,6 +216,8 @@ struct scmi_transport_ops { int (*chan_setup)(struct scmi_chan_info *cinfo, struct device *dev, bool tx); int (*chan_free)(int id, void *p, void *data); + int (*get_max_msg)(bool tx, struct scmi_chan_info *base_cinfo, + int *max_msg); int (*send_message)(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer); void (*mark_txdone)(struct scmi_chan_info *cinfo, int ret); @@ -230,7 +235,8 @@ struct scmi_transport_ops { * @ops: Pointer to the transport specific ops structure * @max_rx_timeout_ms: Timeout for communication with SoC (in Milliseconds) * @max_msg: Maximum number of messages for a channel type (tx or rx) that can - * be pending simultaneously in the system + * be pending simultaneously in the system. May be overridden by the + * get_max_msg op. * @max_msg_size: Maximum size of data per message that can be handled. */ struct scmi_desc { diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index d070687cf2f6..d66f19b27c44 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -61,11 +61,13 @@ static atomic_t transfer_last_id; * Index of this bitmap table is also used for message * sequence identifier. * @xfer_lock: Protection for message allocation + * @max_msg: Maximum number of messages that can be pending */ struct scmi_xfers_info { struct scmi_xfer *xfer_block; unsigned long *xfer_alloc_table; spinlock_t xfer_lock; + int max_msg; }; /** @@ -157,13 +159,11 @@ static struct scmi_xfer *scmi_xfer_get(const struct scmi_handle *handle, u16 xfer_id; struct scmi_xfer *xfer; unsigned long flags, bit_pos; - struct scmi_info *info = handle_to_scmi_info(handle); /* Keep the locked section as small as possible */ spin_lock_irqsave(&minfo->xfer_lock, flags); - bit_pos = find_first_zero_bit(minfo->xfer_alloc_table, - info->desc->max_msg); - if (bit_pos == info->desc->max_msg) { + bit_pos = find_first_zero_bit(minfo->xfer_alloc_table, minfo->max_msg); + if (bit_pos == minfo->max_msg) { spin_unlock_irqrestore(&minfo->xfer_lock, flags); return ERR_PTR(-ENOMEM); } @@ -594,32 +594,44 @@ int scmi_handle_put(const struct scmi_handle *handle) } static int __scmi_xfer_info_init(struct scmi_info *sinfo, - struct scmi_xfers_info *info) + struct scmi_xfers_info *info, + bool tx, + struct scmi_chan_info *base_cinfo) { int i; struct scmi_xfer *xfer; struct device *dev = sinfo->dev; const struct scmi_desc *desc = sinfo->desc; + info->max_msg = desc->max_msg; + + if (desc->ops->get_max_msg) { + int ret = + desc->ops->get_max_msg(tx, base_cinfo, &info->max_msg); + + if (ret) + return ret; + } + /* Pre-allocated messages, no more than what hdr.seq can support */ - if (WARN_ON(desc->max_msg >= MSG_TOKEN_MAX)) { + if (WARN_ON(info->max_msg >= MSG_TOKEN_MAX)) { dev_err(dev, "Maximum message of %d exceeds supported %ld\n", - desc->max_msg, MSG_TOKEN_MAX); + info->max_msg, MSG_TOKEN_MAX); return -EINVAL; } - info->xfer_block = devm_kcalloc(dev, desc->max_msg, + info->xfer_block = devm_kcalloc(dev, info->max_msg, sizeof(*info->xfer_block), GFP_KERNEL); if (!info->xfer_block) return -ENOMEM; - info->xfer_alloc_table = devm_kcalloc(dev, BITS_TO_LONGS(desc->max_msg), + info->xfer_alloc_table = devm_kcalloc(dev, BITS_TO_LONGS(info->max_msg), sizeof(long), GFP_KERNEL); if (!info->xfer_alloc_table) return -ENOMEM; /* Pre-initialize the buffer pointer to pre-allocated buffers */ - for (i = 0, xfer = info->xfer_block; i < desc->max_msg; i++, xfer++) { + for (i = 0, xfer = info->xfer_block; i < info->max_msg; i++, xfer++) { xfer->rx.buf = devm_kcalloc(dev, sizeof(u8), desc->max_msg_size, GFP_KERNEL); if (!xfer->rx.buf) @@ -636,10 +648,21 @@ static int __scmi_xfer_info_init(struct scmi_info *sinfo, static int scmi_xfer_info_init(struct scmi_info *sinfo) { - int ret = __scmi_xfer_info_init(sinfo, &sinfo->tx_minfo); + int ret; + struct scmi_chan_info *base_tx_cinfo; + struct scmi_chan_info *base_rx_cinfo; + + base_tx_cinfo = idr_find(&sinfo->tx_idr, SCMI_PROTOCOL_BASE); + if (unlikely(!base_tx_cinfo)) + return -EINVAL; + + ret = __scmi_xfer_info_init(sinfo, &sinfo->tx_minfo, true, + base_tx_cinfo); - if (!ret && idr_find(&sinfo->rx_idr, SCMI_PROTOCOL_BASE)) - ret = __scmi_xfer_info_init(sinfo, &sinfo->rx_minfo); + base_rx_cinfo = idr_find(&sinfo->rx_idr, SCMI_PROTOCOL_BASE); + if (!ret && base_rx_cinfo) + ret = __scmi_xfer_info_init(sinfo, &sinfo->rx_minfo, false, + base_rx_cinfo); return ret; } From patchwork Fri Sep 18 16:54:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 11785521 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ED54559D for ; Fri, 18 Sep 2020 16:59:45 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B6A5C20848 for ; Fri, 18 Sep 2020 16:59:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JUIgRzkp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B6A5C20848 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3wWCuYBdbyu+bwrctW5D9TpnfZHQlnr/xST4jUZ2lX0=; b=JUIgRzkppa19AsL4/6DrCzp22 Cf1kkSbWWg7DDsTSdlZ6rggU8q0V1Y+NS0PPyyGkggg5prHtRmptAEWjhw7a0N/MfGeE3QxPTbmku 8YuQEknx0SPprsiRJGODLTYhKJ9L/umRP1Jxyd26JMu5MQu6R1tmRLnNBREKxB7o/4R0luvNtaiZt Ulup0EYMYNPWRplHGicspGSCxJ6zarreMStVmH0+T6XWC7cHN3C4B4ARqRhGhzsppImVZOM+6IN/T epWt75UsvFFnzXHgOZgCQn8h78iwJmyHt29qvUlKi+zfZ8ppxMcpkYXe3DDkV+t0TdzpnSlQwko/9 K+Vgf7hcw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJJhJ-0003My-FF; Fri, 18 Sep 2020 16:57:21 +0000 Received: from plasma31.jpberlin.de ([80.241.56.82]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJJfb-0002Zp-UR for linux-arm-kernel@lists.infradead.org; Fri, 18 Sep 2020 16:55:37 +0000 Received: from spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) by plasma.jpberlin.de (Postfix) with ESMTP id 8BABF100E7E; Fri, 18 Sep 2020 18:55:31 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from plasma.jpberlin.de ([80.241.56.76]) by spamfilter04.heinlein-hosting.de (spamfilter04.heinlein-hosting.de [80.241.56.122]) (amavisd-new, port 10030) with ESMTP id CuQEcevHF-1V; Fri, 18 Sep 2020 18:55:30 +0200 (CEST) Received: from webmail.opensynergy.com (unknown [217.66.60.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client CN "*.opensynergy.com", Issuer "Starfield Secure Certificate Authority - G2" (not verified)) (Authenticated sender: opensynergy@jpberlin.de) by plasma.jpberlin.de (Postfix) with ESMTPSA id 287B31018B5; Fri, 18 Sep 2020 18:55:30 +0200 (CEST) From: Peter Hilber To: , Subject: [RFC PATCH 4/7] firmware: arm_scmi: Add per message transport data Date: Fri, 18 Sep 2020 18:54:41 +0200 Message-ID: <20200918165441.256940-1-peter.hilber@opensynergy.com> In-Reply-To: <20200918162311.254564-1-peter.hilber@opensynergy.com> References: <20200918162311.254564-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-01.open-synergy.com (10.26.10.21) X-MBO-SPAM-Probability: X-Rspamd-Score: -4.09 / 15.00 / 15.00 X-Rspamd-Queue-Id: 8BABF100E7E X-Rspamd-UID: 9ae508 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200918_125536_132032_A1190FFB X-CRM114-Status: GOOD ( 13.76 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.82 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [80.241.56.82 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jean-philippe@linaro.org, mikhail.golubev@opensynergy.com, souvik.chakravarty@arm.com, igor.skalkin@opensynergy.com, linux-kernel@vger.kernel.org, Rob Herring , Peter Hilber , anton.yakovlev@opensynergy.com, sudeep.holla@arm.com, alex.bennee@linaro.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Igor Skalkin The virtio transport in this patch series can be simplified by using the scmi_xfer tx/rx buffers for data exchange with the virtio device, and for saving the message state. But the virtio transport requires prepending a transport-specific header. Also, for data exchange using virtqueues, the tx and rx buffers should not overlap. The first step to solve the aforementioned issues is to add a transport-specific data pointer to scmi_xfer. Co-developed-by: Peter Hilber Signed-off-by: Peter Hilber Signed-off-by: Igor Skalkin --- drivers/firmware/arm_scmi/common.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 0f1540cb2d84..e3ccec954e93 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -131,6 +131,7 @@ struct scmi_msg { * buffer for the rx path as we use for the tx path. * @done: command message transmit completion event * @async_done: pointer to delayed response message received event completion + * @extra_data: Transport-specific private data pointer */ struct scmi_xfer { int transfer_id; @@ -139,6 +140,7 @@ struct scmi_xfer { struct scmi_msg rx; struct completion done; struct completion *async_done; + void *extra_data; }; void scmi_xfer_put(const struct scmi_handle *h, struct scmi_xfer *xfer); From patchwork Fri Sep 18 16:55:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 11785525 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C09176CA for ; Fri, 18 Sep 2020 17:00:33 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4066320848 for ; Fri, 18 Sep 2020 17:00:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GjYSD88z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4066320848 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6iyutxgLJ1gJtkD4FFTIWzxy3gN1fjzjMYzNmivVXew=; b=GjYSD88zQAQWEfxTmEPpMwTo9 /8YIHCaOiHKI0yWgPG0i3M55vs0bMQJhHhKmXDhiQFjXG28BzJj26rCegFaP22C5cfzIgR1wAFMiJ KKmAmXA6RPvFRhbYZal8fhKfkf2gaKuWfKaFRI05Ruh3InNW+zZ2lmVuYNaeP+eaWscRmKLESOs1F pqsWEAUSL89HzrYyMSpthYGWdYzLvP//tmhWtwoI6zBsetzDQy1bD//mg2kQdmgUnzs9rHTbt7nKk nSy41ELwoDg60P8bJzvwIc6N5v2+Q1ahivpdlNGVrXPS0qfNa/C4aTT74EN3uxApGooL6f+X6UzLG rK2NvDuQA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJJhv-0003ej-9n; Fri, 18 Sep 2020 16:57:59 +0000 Received: from plasma31.jpberlin.de ([80.241.56.82]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJJg4-0002nD-Cw for linux-arm-kernel@lists.infradead.org; Fri, 18 Sep 2020 16:56:17 +0000 Received: from spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) by plasma.jpberlin.de (Postfix) with ESMTP id 3C6B410268D; Fri, 18 Sep 2020 18:55:59 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from plasma.jpberlin.de ([80.241.56.76]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id 795MTA2s70oB; Fri, 18 Sep 2020 18:55:58 +0200 (CEST) Received: from webmail.opensynergy.com (unknown [217.66.60.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client CN "*.opensynergy.com", Issuer "Starfield Secure Certificate Authority - G2" (not verified)) (Authenticated sender: opensynergy@jpberlin.de) by plasma.jpberlin.de (Postfix) with ESMTPSA id 09297100D05; Fri, 18 Sep 2020 18:55:58 +0200 (CEST) From: Peter Hilber To: , Subject: [RFC PATCH 5/7] firmware: arm_scmi: Add xfer_init_buffers transport op Date: Fri, 18 Sep 2020 18:55:30 +0200 Message-ID: <20200918165530.257023-1-peter.hilber@opensynergy.com> In-Reply-To: <20200918162311.254564-1-peter.hilber@opensynergy.com> References: <20200918162311.254564-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-01.open-synergy.com (10.26.10.21) X-MBO-SPAM-Probability: X-Rspamd-Score: -4.07 / 15.00 / 15.00 X-Rspamd-Queue-Id: 3C6B410268D X-Rspamd-UID: 935e96 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200918_125605_177107_3FFC02B5 X-CRM114-Status: GOOD ( 19.22 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [80.241.56.82 listed in wl.mailspike.net] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.82 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jean-philippe@linaro.org, mikhail.golubev@opensynergy.com, souvik.chakravarty@arm.com, igor.skalkin@opensynergy.com, linux-kernel@vger.kernel.org, Rob Herring , Peter Hilber , anton.yakovlev@opensynergy.com, sudeep.holla@arm.com, alex.bennee@linaro.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Igor Skalkin The virtio transport in this patch series can be simplified by using the scmi_xfer tx/rx buffers for data exchange with the virtio device, and for saving the message state. But the virtio transport requires prepending a transport-specific header. Also, for data exchange using virtqueues, the tx and rx buffers should not overlap. After the previous patch, this is the second and final step to enable the virtio transport to use the scmi_xfer buffers for data exchange. Add an optional op through which the transport can allocate the tx/rx buffers along with room for the prepended transport-specific headers. Co-developed-by: Peter Hilber Signed-off-by: Peter Hilber Signed-off-by: Igor Skalkin --- drivers/firmware/arm_scmi/common.h | 3 +++ drivers/firmware/arm_scmi/driver.c | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index e3ccec954e93..c6071ffe4346 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -206,6 +206,7 @@ struct scmi_chan_info { * @get_max_msg: Optional callback to provide max_msg dynamically * @max_msg: Maximum number of messages for the channel type (tx or rx) * that can be pending simultaneously in the system + * @xfer_init_buffers: Callback to initialize buffers for scmi_xfer * @send_message: Callback to send a message * @mark_txdone: Callback to mark tx as done * @fetch_response: Callback to fetch response @@ -220,6 +221,8 @@ struct scmi_transport_ops { int (*chan_free)(int id, void *p, void *data); int (*get_max_msg)(bool tx, struct scmi_chan_info *base_cinfo, int *max_msg); + int (*xfer_init_buffers)(struct scmi_chan_info *cinfo, + struct scmi_xfer *xfer, int max_msg_size); int (*send_message)(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer); void (*mark_txdone)(struct scmi_chan_info *cinfo, int ret); diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index d66f19b27c44..2e25f6f068f5 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -632,12 +632,21 @@ static int __scmi_xfer_info_init(struct scmi_info *sinfo, /* Pre-initialize the buffer pointer to pre-allocated buffers */ for (i = 0, xfer = info->xfer_block; i < info->max_msg; i++, xfer++) { - xfer->rx.buf = devm_kcalloc(dev, sizeof(u8), desc->max_msg_size, - GFP_KERNEL); - if (!xfer->rx.buf) - return -ENOMEM; - - xfer->tx.buf = xfer->rx.buf; + if (desc->ops->xfer_init_buffers) { + int ret = desc->ops->xfer_init_buffers( + base_cinfo, xfer, desc->max_msg_size); + + if (ret) + return ret; + } else { + xfer->rx.buf = devm_kcalloc(dev, sizeof(u8), + desc->max_msg_size, + GFP_KERNEL); + if (!xfer->rx.buf) + return -ENOMEM; + + xfer->tx.buf = xfer->rx.buf; + } init_completion(&xfer->done); } From patchwork Fri Sep 18 16:55:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 11785527 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E6CA6CA for ; Fri, 18 Sep 2020 17:00:58 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F138920848 for ; Fri, 18 Sep 2020 17:00:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="2+vXhhQz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F138920848 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SrV3HeM83BcNrYSL6YWjP4yEvvgeII4gaGutNKuEn7g=; b=2+vXhhQzM47fyFrvP0Wb5QhyP weZoS9BKhBmIRADpsLFOOrJoeaTx2T0UQMq169wUXRdQxxtxQdb6vR/uJcJe5myTXpTZOWBKKvTEw uJ0xdHOy0YUUKLiwsolQMOjLfyPMSyn8lQ0tATT+diJROrphtwxe0v0ly0EwrfqSn7VMfzUCM2GPG wrvc+Qlf6A8FcCnQs+2VVHU3IplBlnLco/o1Qw3bpgnd8pBMuwafLEIZTw5qTnXgu4NrxfPu9iA4y PaPlMAoUH58g2VA4BSQ7jMU/QeO0XCQbZjFYcMc/aoYIXLszqPOj+Q8qibcD4Ytjh/ROtsIcoY9gS 30H36Ch2w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJJiO-0003ro-BG; Fri, 18 Sep 2020 16:58:28 +0000 Received: from plasma31.jpberlin.de ([80.241.56.82]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJJge-00034k-B3 for linux-arm-kernel@lists.infradead.org; Fri, 18 Sep 2020 16:56:47 +0000 Received: from spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) by plasma.jpberlin.de (Postfix) with ESMTP id 3BC0010268D; Fri, 18 Sep 2020 18:56:35 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from plasma.jpberlin.de ([80.241.56.76]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id 1lhJ3zNlksY9; Fri, 18 Sep 2020 18:56:33 +0200 (CEST) Received: from webmail.opensynergy.com (unknown [217.66.60.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client CN "*.opensynergy.com", Issuer "Starfield Secure Certificate Authority - G2" (not verified)) (Authenticated sender: opensynergy@jpberlin.de) by plasma.jpberlin.de (Postfix) with ESMTPSA id 49CB1100D05; Fri, 18 Sep 2020 18:56:33 +0200 (CEST) From: Peter Hilber To: , , , Subject: [RFC PATCH 6/7] dt-bindings: arm: Add virtio transport for SCMI Date: Fri, 18 Sep 2020 18:55:58 +0200 Message-ID: <20200918165558.257086-1-peter.hilber@opensynergy.com> In-Reply-To: <20200918162311.254564-1-peter.hilber@opensynergy.com> References: <20200918162311.254564-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-01.open-synergy.com (10.26.10.21) X-MBO-SPAM-Probability: X-Rspamd-Score: -4.01 / 15.00 / 15.00 X-Rspamd-Queue-Id: 3BC0010268D X-Rspamd-UID: 776556 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200918_125640_994598_A1AB65E9 X-CRM114-Status: GOOD ( 16.91 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.82 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [80.241.56.82 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jean-philippe@linaro.org, mikhail.golubev@opensynergy.com, souvik.chakravarty@arm.com, igor.skalkin@opensynergy.com, "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, Rob Herring , Peter Hilber , anton.yakovlev@opensynergy.com, sudeep.holla@arm.com, alex.bennee@linaro.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Igor Skalkin Document the properties for arm,scmi-virtio compatible nodes. The backing virtio SCMI device is described in patch [1]. [1] https://lists.oasis-open.org/archives/virtio-comment/202005/msg00096.html Co-developed-by: Peter Hilber Signed-off-by: Peter Hilber Signed-off-by: Igor Skalkin --- .../devicetree/bindings/arm/arm,scmi.txt | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/arm/arm,scmi.txt b/Documentation/devicetree/bindings/arm/arm,scmi.txt index 55deb68230eb..844ff3c40a49 100644 --- a/Documentation/devicetree/bindings/arm/arm,scmi.txt +++ b/Documentation/devicetree/bindings/arm/arm,scmi.txt @@ -13,6 +13,9 @@ the device tree. Required properties: The scmi node with the following properties shall be under the /firmware/ node. +Some properties are specific to a transport type. + +shmem-based transports (mailbox, smc/hvc): - compatible : shall be "arm,scmi" or "arm,scmi-smc" for smc/hvc transports - mboxes: List of phandle and mailbox channel specifiers. It should contain @@ -21,6 +24,17 @@ The scmi node with the following properties shall be under the /firmware/ node. supported. - shmem : List of phandle pointing to the shared memory(SHM) area as per generic mailbox client binding. + +Virtio transport: + +- compatible : shall be "arm,scmi-virtio". +- virtio_transport : phandle of the virtio device. This device must support one + virtqueue for transmitting commands ("tx", cmdq), and, + optionally, one more virtqueue for receiving notifications + and delayed responses ("rx", eventq). + +Additional required properties: + - #address-cells : should be '1' if the device has sub-nodes, maps to protocol identifier for a given sub-node. - #size-cells : should be '0' as 'reg' property doesn't have any size @@ -42,7 +56,8 @@ Each protocol supported shall have a sub-node with corresponding compatible as described in the following sections. If the platform supports dedicated communication channel for a particular protocol, the 3 properties namely: mboxes, mbox-names and shmem shall be present in the sub-node corresponding -to that protocol. +to that protocol. The virtio transport does not support dedicated communication +channels. Clock/Performance bindings for the clocks/OPPs based on SCMI Message Protocol ------------------------------------------------------------ @@ -106,7 +121,8 @@ Required sub-node properties: [4] Documentation/devicetree/bindings/sram/sram.yaml [5] Documentation/devicetree/bindings/reset/reset.txt -Example: +Example (mailbox transport): +---------------------------- sram@50000000 { compatible = "mmio-sram"; @@ -195,3 +211,21 @@ thermal-zones { ... }; }; + +Example (virtio transport): +--------------------------- + +virtio_mmio_scmi: virtio_mmio@4b001000 { + compatible = "virtio,mmio"; + ... +}; + +firmware { + ... + scmi { + compatible = "arm,scmi-virtio"; + virtio_transport = <&virtio_mmio_scmi>; + ... + +The rest is similar to the mailbox transport example, when omitting the +mailbox/shmem-specific properties. From patchwork Fri Sep 18 16:56:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 11785523 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5C9E59D for ; Fri, 18 Sep 2020 16:59:50 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3EB7420848 for ; Fri, 18 Sep 2020 16:59:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BGPbAkK+"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="LjhG8a3f" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EB7420848 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2B0MJiej1pgUCQeGdGrnGgqQqq8UpJMrj9LHye3skbQ=; b=BGPbAkK+Ti4cXOPI5gO46/TTb WyAOji/c3NqhVkSpyHCBrInvZ3paVkcEF/QwWEThMbo6PXWTA3YP8gIF70DrOiEw9gfuZBZYY4dis kS8UKU/IOpKb2mmNfjPwkolM3jhCik+rroyCIHNXukapQamhEypMwuu9fLldDEeTv1cpsAqJJ3Nw9 PWSWYQ5soYxUp/DZYIyqObwAKwnKZzT8fkitNYDbZopg70+j2eDPXkV2GQs5hpT1N93Dq+/wRidje v0E3aBRmOdnOYw2Dq74aaUa9W9vpvt2M7e/SjDRqw8CBh+9+dpXArDWq3fiYvVCadfIMaz5mFrUCp sNTExKyDQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJJjB-0004D4-3h; Fri, 18 Sep 2020 16:59:17 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJJhO-0003SU-2X for linux-arm-kernel@merlin.infradead.org; Fri, 18 Sep 2020 16:57:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender :Reply-To:Content-ID:Content-Description; bh=G+r4mq7eTEhRfjZ7nYcL6YTGQzqulTUwn1PfgCoo6gE=; b=LjhG8a3fHa1qqYcrtaCDhA0cFC DyVF4pPWtlqKa/uWh7zMZcrxR2oCVrWjxjZvRS+Tu78xujxCzE1G5+RzF30TkN2zp1eLR5AilZziQ NESa4vGsmJxCQlR/kIY/Vc8hzQSnSfrBPA8bx4mhb33Lf15YMDSrBQVNOAw4cb8IcUQfNMgpoQqWR 694egcbV0OrPVaa+oKqxoth3hKwtJuHXCsR5Q3kQ9GsspppQS2pane21kPCjqkl5nLTlwPmf6lDVo imoKjP8lpb7w+tnRyGbHqxsr09ToKyiqEXhELBGKHY/zqGEhUFbJDIGwrWKp7+cRlBeG+YqnBb4he MD6E+gEA==; Received: from plasma31.jpberlin.de ([80.241.56.82]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kJJhH-0008IV-H7 for linux-arm-kernel@lists.infradead.org; Fri, 18 Sep 2020 16:57:24 +0000 Received: from spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) by plasma.jpberlin.de (Postfix) with ESMTP id 7AEC31025D1; Fri, 18 Sep 2020 18:57:15 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from plasma.jpberlin.de ([80.241.56.76]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id z8cxieOR8uCZ; Fri, 18 Sep 2020 18:57:11 +0200 (CEST) Received: from webmail.opensynergy.com (unknown [217.66.60.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (Client CN "*.opensynergy.com", Issuer "Starfield Secure Certificate Authority - G2" (not verified)) (Authenticated sender: opensynergy@jpberlin.de) by plasma.jpberlin.de (Postfix) with ESMTPSA id A6BCD10271A; Fri, 18 Sep 2020 18:57:11 +0200 (CEST) From: Peter Hilber To: , , , Subject: [RFC PATCH 7/7] firmware: arm_scmi: Add virtio transport Date: Fri, 18 Sep 2020 18:56:33 +0200 Message-ID: <20200918165634.257150-1-peter.hilber@opensynergy.com> In-Reply-To: <20200918162311.254564-1-peter.hilber@opensynergy.com> References: <20200918162311.254564-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-01.open-synergy.com (10.26.10.21) X-MBO-SPAM-Probability: X-Rspamd-Score: -4.66 / 15.00 / 15.00 X-Rspamd-Queue-Id: 7AEC31025D1 X-Rspamd-UID: 0e90cb X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200918_175719_718327_607A1FF2 X-CRM114-Status: GOOD ( 33.42 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.4 on casper.infradead.org summary: Content analysis details: (-2.6 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [80.241.56.82 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [80.241.56.82 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jean-philippe@linaro.org, mikhail.golubev@opensynergy.com, souvik.chakravarty@arm.com, igor.skalkin@opensynergy.com, "Michael S. Tsirkin" , Jason Wang , linux-kernel@vger.kernel.org, Rob Herring , Peter Hilber , anton.yakovlev@opensynergy.com, sudeep.holla@arm.com, alex.bennee@linaro.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Igor Skalkin This transport enables accessing an SCMI platform as a virtio device. Implement an SCMI virtio driver according to the virtio SCMI device spec patch v5 [1]. Virtio device id 32 has been reserved for the SCMI device [2]. The virtio transport has one tx channel (virtio cmdq, A2P channel) and at most one rx channel (virtio eventq, P2A channel). The following feature bit defined in [1] is not implemented: VIRTIO_SCMI_F_SHARED_MEMORY. After the preparatory patches, implement the virtio transport as paraphrased: Call scmi-virtio init from arm-scmi to probe for the virtio device before arm-scmi will call any transport ops. Use the scmi_xfer tx/rx buffers for data exchange with the virtio device in order to avoid redundant maintenance of additional buffers. Allocate the buffers in the SCMI transport, and prepend room for a small header used by the virtio transport to the tx/rx buffers. For simplicity, restrict the number of messages which can be pending simultaneously according to the virtqueue capacity. (The virtqueue sizes are negotiated with the virtio device.) As soon as rx channel message buffers are allocated or have been read out by the arm-scmi driver, feed them to the virtio device. Since some virtio devices may not have the short response time exhibited by SCMI platforms using other transports, set a generous response timeout. Limitations: Do not adjust the other SCMI timeouts for delayed response and polling for now, since these timeouts are only relevant in special cases which are not yet deemed relevant for this transport. To do (as discussed in the cover letter): - Avoid re-use of buffers still being used by the virtio device on timeouts. - Avoid race conditions on receiving messages during/after channel free on driver probe failure or remove. [1] https://lists.oasis-open.org/archives/virtio-comment/202005/msg00096.html [2] https://www.oasis-open.org/committees/ballot.php?id=3496 Co-developed-by: Peter Hilber Signed-off-by: Peter Hilber Signed-off-by: Igor Skalkin --- MAINTAINERS | 1 + drivers/firmware/Kconfig | 12 +- drivers/firmware/arm_scmi/Makefile | 1 + drivers/firmware/arm_scmi/common.h | 14 + drivers/firmware/arm_scmi/driver.c | 11 + drivers/firmware/arm_scmi/virtio.c | 470 +++++++++++++++++++++++++++++ include/uapi/linux/virtio_ids.h | 1 + include/uapi/linux/virtio_scmi.h | 41 +++ 8 files changed, 550 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/arm_scmi/virtio.c create mode 100644 include/uapi/linux/virtio_scmi.h diff --git a/MAINTAINERS b/MAINTAINERS index deaafb617361..8df73d6ddfc1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -16772,6 +16772,7 @@ F: drivers/firmware/arm_scpi.c F: drivers/reset/reset-scmi.c F: include/linux/sc[mp]i_protocol.h F: include/trace/events/scmi.h +F: include/uapi/linux/virtio_scmi.h SYSTEM RESET/SHUTDOWN DRIVERS M: Sebastian Reichel diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index bdde51adb267..c4bdd84f7405 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -9,7 +9,7 @@ menu "Firmware Drivers" config ARM_SCMI_PROTOCOL tristate "ARM System Control and Management Interface (SCMI) Message Protocol" depends on ARM || ARM64 || COMPILE_TEST - depends on ARM_SCMI_HAVE_SHMEM + depends on ARM_SCMI_HAVE_SHMEM || VIRTIO_SCMI help ARM System Control and Management Interface (SCMI) protocol is a set of operating system-independent software interfaces that are @@ -34,6 +34,16 @@ config ARM_SCMI_HAVE_SHMEM This declares whether a shared memory based transport for SCMI is available. +config VIRTIO_SCMI + bool "Virtio transport for SCMI" + default n + depends on VIRTIO + help + This enables the virtio based transport for SCMI. + + If you want to use the ARM SCMI protocol between the virtio guest and + a host providing a virtio SCMI device, answer Y. + config ARM_SCMI_POWER_DOMAIN tristate "SCMI power domain driver" depends on ARM_SCMI_PROTOCOL || (COMPILE_TEST && OF) diff --git a/drivers/firmware/arm_scmi/Makefile b/drivers/firmware/arm_scmi/Makefile index 3cc7fa40a464..25caea5e1969 100644 --- a/drivers/firmware/arm_scmi/Makefile +++ b/drivers/firmware/arm_scmi/Makefile @@ -4,6 +4,7 @@ scmi-driver-y = driver.o notify.o scmi-transport-$(CONFIG_ARM_SCMI_HAVE_SHMEM) = shmem.o scmi-transport-$(CONFIG_MAILBOX) += mailbox.o scmi-transport-$(CONFIG_HAVE_ARM_SMCCC_DISCOVERY) += smc.o +scmi-transport-$(CONFIG_VIRTIO_SCMI) += virtio.o scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o system.o scmi-module-objs := $(scmi-bus-y) $(scmi-driver-y) $(scmi-protocols-y) \ $(scmi-transport-y) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index c6071ffe4346..865364dea9ea 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -161,6 +161,17 @@ int scmi_base_protocol_init(struct scmi_handle *h); int __init scmi_bus_init(void); void __exit scmi_bus_exit(void); +#ifdef CONFIG_VIRTIO_SCMI +int __init virtio_scmi_init(void); +void __exit virtio_scmi_exit(void); +#else +static inline int __init virtio_scmi_init(void) +{ + return 0; +} +#define virtio_scmi_exit() do { } while (0) +#endif + #define DECLARE_SCMI_REGISTER_UNREGISTER(func) \ int __init scmi_##func##_register(void); \ void __exit scmi_##func##_unregister(void) @@ -257,6 +268,9 @@ extern const struct scmi_desc scmi_mailbox_desc; #ifdef CONFIG_HAVE_ARM_SMCCC extern const struct scmi_desc scmi_smc_desc; #endif +#ifdef CONFIG_VIRTIO_SCMI +extern const struct scmi_desc scmi_virtio_desc; +#endif void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr); void scmi_free_channel(struct scmi_chan_info *cinfo, struct idr *idr, int id); diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 2e25f6f068f5..326f69f2a45a 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -947,6 +947,9 @@ static const struct of_device_id scmi_of_match[] = { #endif #ifdef CONFIG_HAVE_ARM_SMCCC_DISCOVERY { .compatible = "arm,scmi-smc", .data = &scmi_smc_desc}, +#endif +#ifdef CONFIG_VIRTIO_SCMI + { .compatible = "arm,scmi-virtio", .data = &scmi_virtio_desc}, #endif { /* Sentinel */ }, }; @@ -965,8 +968,14 @@ static struct platform_driver scmi_driver = { static int __init scmi_driver_init(void) { + int ret; + scmi_bus_init(); + ret = virtio_scmi_init(); + if (ret) + return ret; + scmi_clock_register(); scmi_perf_register(); scmi_power_register(); @@ -989,6 +998,8 @@ static void __exit scmi_driver_exit(void) scmi_sensors_unregister(); scmi_system_unregister(); + virtio_scmi_exit(); + platform_driver_unregister(&scmi_driver); } module_exit(scmi_driver_exit); diff --git a/drivers/firmware/arm_scmi/virtio.c b/drivers/firmware/arm_scmi/virtio.c new file mode 100644 index 000000000000..126c964d9f49 --- /dev/null +++ b/drivers/firmware/arm_scmi/virtio.c @@ -0,0 +1,470 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Virtio Transport driver for Arm System Control and Management Interface + * (SCMI). + * + * Copyright (C) 2020 OpenSynergy. + */ + +/** + * DOC: Theory of Operation + * + * The scmi-virtio transport implements a driver for the virtio SCMI device + * proposed in virtio spec patch v5[1]. + * + * There is one tx channel (virtio cmdq, A2P channel) and at most one rx + * channel (virtio eventq, P2A channel). Each channel is implemented through a + * virtqueue. Access to each virtqueue is protected by a spinlock. + * + * This SCMI transport uses the scmi_xfer tx/rx buffers for data exchange with + * the virtio device to avoid maintenance of additional buffers. + * + * [1] https://lists.oasis-open.org/archives/virtio-comment/202005/msg00096.html + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" + +#define VIRTIO_SCMI_MAX_MSG_SIZE 128 /* Value may be increased. */ +#define DESCR_PER_TX_MSG 2 + +struct scmi_vio_channel { + spinlock_t lock; + struct virtqueue *vqueue; + struct scmi_chan_info *cinfo; + u8 is_rx; +}; + +union virtio_scmi_input { + __virtio32 hdr; + struct virtio_scmi_response response; + struct virtio_scmi_notification notification; +}; + +struct scmi_vio_msg { + struct virtio_scmi_request *request; + union virtio_scmi_input *input; + u8 completed; +}; + +static int scmi_vio_populate_vq_rx(struct scmi_vio_channel *vioch, + struct scmi_xfer *xfer) +{ + struct scatterlist sg_in; + struct scmi_vio_msg *msg = xfer->extra_data; + int rc; + + msg->completed = false; + + sg_init_one(&sg_in, msg->input, + sizeof(*msg->input) + VIRTIO_SCMI_MAX_MSG_SIZE); + + rc = virtqueue_add_inbuf(vioch->vqueue, &sg_in, 1, xfer, GFP_ATOMIC); + if (rc) + dev_err(vioch->cinfo->dev, "%s() rc=%d\n", __func__, rc); + else + virtqueue_kick(vioch->vqueue); + + return rc; +} + +static void scmi_vio_complete_cb(struct virtqueue *vqueue) +{ + struct scmi_vio_channel *vioch = vqueue->priv; + unsigned long iflags; + unsigned int length; + + spin_lock_irqsave(&vioch->lock, iflags); + + do { + struct scmi_xfer *xfer; + + virtqueue_disable_cb(vqueue); + + while ((xfer = virtqueue_get_buf(vqueue, &length))) { + struct scmi_vio_msg *msg = xfer->extra_data; + u32 msg_hdr = + virtio32_to_cpu(vqueue->vdev, msg->input->hdr); + u8 msg_type = MSG_XTRACT_TYPE(msg_hdr); + + if (!vioch->is_rx) { /* tx queue response */ + msg->completed = true; + xfer->rx.len = + length - sizeof(msg->input->response); + if (!xfer->hdr.poll_completion) + scmi_rx_callback(vioch->cinfo, msg_hdr); + continue; + } + + /* rx queue - notification or delayed response */ + switch (msg_type) { + case MSG_TYPE_NOTIFICATION: + xfer->rx.len = length - + sizeof(msg->input->notification); + xfer->rx.buf = msg->input->notification.data; + break; + case MSG_TYPE_DELAYED_RESP: + xfer->rx.len = + length - sizeof(msg->input->response); + xfer->rx.buf = msg->input->response.data; + break; + default: + dev_warn_once(vioch->cinfo->dev, + "rx: unknown message_type %d\n", + msg_type); + scmi_vio_populate_vq_rx(vioch, xfer); + continue; + } + + scmi_rx_callback(vioch->cinfo, msg_hdr); + scmi_vio_populate_vq_rx(vioch, xfer); + } + + if (unlikely(virtqueue_is_broken(vqueue))) + break; + } while (!virtqueue_enable_cb(vqueue)); + + spin_unlock_irqrestore(&vioch->lock, iflags); +} + +static const char *const scmi_vio_vqueue_names[] = { "tx", "rx" }; + +static vq_callback_t *scmi_vio_complete_callbacks[] = { + scmi_vio_complete_cb, + scmi_vio_complete_cb +}; + +static bool virtio_chan_available(struct device *dev, int idx) +{ + struct platform_device *pdev; + struct virtio_device *vdev; + struct device_node *vioch_node; + struct scmi_vio_channel **vioch; + + vioch_node = of_parse_phandle(dev->of_node, "virtio_transport", 0); + if (!vioch_node) + return false; + + pdev = of_find_device_by_node(vioch_node); + of_node_put(vioch_node); + if (!pdev) + return false; + + vdev = (struct virtio_device *)pdev->dev.driver_data; + if (!vdev) + return false; + + vioch = vdev->priv; + if (!vioch) + return false; + + return vioch[idx] && vioch[idx]->vqueue; +} + +static int virtio_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, + bool tx) +{ + struct platform_device *pdev; + struct virtio_device *vdev; + struct device_node *vioch_node; + struct scmi_vio_channel **vioch; + int vioch_index = tx ? VIRTIO_SCMI_VQ_TX : VIRTIO_SCMI_VQ_RX; + + vioch_node = + of_parse_phandle(cinfo->dev->of_node, "virtio_transport", 0); + + pdev = of_find_device_by_node(vioch_node); + of_node_put(vioch_node); + if (!pdev) { + dev_err(dev, "virtio_transport device not found\n"); + return -1; + } + + vdev = (struct virtio_device *)pdev->dev.driver_data; + if (!vdev) + return -1; + + vioch = (struct scmi_vio_channel **)vdev->priv; + if (!vioch) { + dev_err(dev, "Data from scmi-virtio probe not found\n"); + return -1; + } + cinfo->transport_info = vioch[vioch_index]; + vioch[vioch_index]->cinfo = cinfo; + + return 0; +} + +static int virtio_chan_free(int id, void *p, void *data) +{ + struct scmi_chan_info *cinfo = p; + struct scmi_vio_channel *vioch = cinfo->transport_info; + + if (vioch) { + cinfo->transport_info = NULL; + kfree(vioch); + } + + scmi_free_channel(cinfo, data, id); + return 0; +} + +static int virtio_get_max_msg(bool tx, struct scmi_chan_info *base_cinfo, + int *max_msg) +{ + struct scmi_vio_channel *vioch = base_cinfo->transport_info; + + *max_msg = virtqueue_get_vring_size(vioch->vqueue); + + /* Tx messages need multiple descriptors. */ + if (tx) + *max_msg /= DESCR_PER_TX_MSG; + + if (*max_msg > MSG_TOKEN_MAX) { + dev_notice( + base_cinfo->dev, + "Only %ld messages can be pending simultaneously, while the virtqueue could hold %d\n", + MSG_TOKEN_MAX, *max_msg); + *max_msg = MSG_TOKEN_MAX; + } + + return 0; +} + +static int virtio_xfer_init_buffers(struct scmi_chan_info *cinfo, + struct scmi_xfer *xfer, int max_msg_size) +{ + struct scmi_vio_channel *vioch = cinfo->transport_info; + struct scmi_vio_msg *msg; + + msg = devm_kzalloc(cinfo->dev, sizeof(*msg), GFP_KERNEL); + if (!msg) + return -ENOMEM; + + xfer->extra_data = msg; + + if (vioch->is_rx) { + int rc; + unsigned long iflags; + + msg->input = devm_kzalloc(cinfo->dev, + sizeof(*msg->input) + max_msg_size, + GFP_KERNEL); + if (!msg->input) + return -ENOMEM; + + /* + * xfer->rx.buf will be set to notification or delayed response + * specific values in the receive callback, according to the + * type of the received message. + */ + + spin_lock_irqsave(&vioch->lock, iflags); + rc = scmi_vio_populate_vq_rx(vioch, xfer); + spin_unlock_irqrestore(&vioch->lock, iflags); + if (rc) + return rc; + } else { + msg->request = + devm_kzalloc(cinfo->dev, + sizeof(*msg->request) + max_msg_size, + GFP_KERNEL); + if (!msg->request) + return -ENOMEM; + + xfer->tx.buf = msg->request->data; + + msg->input = devm_kzalloc( + cinfo->dev, sizeof(msg->input->response) + max_msg_size, + GFP_KERNEL); + if (!msg->input) + return -ENOMEM; + + xfer->rx.buf = msg->input->response.data; + } + + return 0; +} + +static int scmi_vio_send(struct scmi_vio_channel *vioch, struct scmi_xfer *xfer) +{ + struct scatterlist sg_out; + struct scatterlist sg_in; + struct scatterlist *sgs[DESCR_PER_TX_MSG] = { &sg_out, &sg_in }; + struct scmi_vio_msg *msg = xfer->extra_data; + unsigned long iflags; + int rc; + + msg->completed = false; + + sg_init_one(&sg_out, msg->request, + sizeof(*msg->request) + xfer->tx.len); + sg_init_one(&sg_in, &msg->input->response, + sizeof(msg->input->response) + xfer->rx.len); + + spin_lock_irqsave(&vioch->lock, iflags); + rc = virtqueue_add_sgs(vioch->vqueue, sgs, 1, 1, xfer, GFP_ATOMIC); + if (rc) + dev_err(vioch->cinfo->dev, "%s() rc=%d\n", __func__, rc); + else + virtqueue_kick(vioch->vqueue); + spin_unlock_irqrestore(&vioch->lock, iflags); + + return rc; +} + +static int virtio_send_message(struct scmi_chan_info *cinfo, + struct scmi_xfer *xfer) +{ + uint32_t hdr; + struct scmi_vio_channel *vioch = cinfo->transport_info; + struct virtio_device *vdev = vioch->vqueue->vdev; + struct scmi_vio_msg *msg = xfer->extra_data; + + hdr = pack_scmi_header(&xfer->hdr); + + msg->request->hdr = cpu_to_virtio32(vdev, hdr); + + return scmi_vio_send(vioch, xfer); +} + +static void virtio_fetch_response(struct scmi_chan_info *cinfo, + struct scmi_xfer *xfer) +{ + struct scmi_vio_channel *vioch = cinfo->transport_info; + struct scmi_vio_msg *msg = xfer->extra_data; + + xfer->hdr.status = virtio32_to_cpu(vioch->vqueue->vdev, + msg->input->response.status); +} + +static void dummy_fetch_notification(struct scmi_chan_info *cinfo, + size_t max_len, struct scmi_xfer *xfer) +{ + (void)cinfo; + (void)max_len; + (void)xfer; +} + +static void dummy_clear_channel(struct scmi_chan_info *cinfo) +{ + (void)cinfo; +} + +static bool virtio_poll_done(struct scmi_chan_info *cinfo, + struct scmi_xfer *xfer) +{ + struct scmi_vio_channel *vioch = cinfo->transport_info; + struct scmi_vio_msg *msg = xfer->extra_data; + unsigned long iflags; + bool completed; + + spin_lock_irqsave(&vioch->lock, iflags); + completed = msg->completed; + spin_unlock_irqrestore(&vioch->lock, iflags); + + return completed; +} + +static const struct scmi_transport_ops scmi_virtio_ops = { + .chan_available = virtio_chan_available, + .chan_setup = virtio_chan_setup, + .chan_free = virtio_chan_free, + .get_max_msg = virtio_get_max_msg, + .send_message = virtio_send_message, + .fetch_response = virtio_fetch_response, + .fetch_notification = dummy_fetch_notification, + .clear_channel = dummy_clear_channel, + .poll_done = virtio_poll_done, + .xfer_init_buffers = virtio_xfer_init_buffers, +}; + +const struct scmi_desc scmi_virtio_desc = { + .ops = &scmi_virtio_ops, + .max_rx_timeout_ms = 60000, /* for non-realtime virtio devices */ + .max_msg = 0, /* overridden by virtio_get_max_msg() */ + .max_msg_size = VIRTIO_SCMI_MAX_MSG_SIZE, +}; + +static int scmi_vio_probe(struct virtio_device *vdev) +{ + struct device *dev = &vdev->dev; + struct scmi_vio_channel **vioch; + bool have_vq_rx; + int vq_cnt; + int i; + struct virtqueue *vqs[VIRTIO_SCMI_VQ_MAX_CNT]; + + vioch = devm_kcalloc(dev, VIRTIO_SCMI_VQ_MAX_CNT, sizeof(*vioch), + GFP_KERNEL); + if (!vioch) + return -ENOMEM; + + have_vq_rx = virtio_has_feature(vdev, VIRTIO_SCMI_F_P2A_CHANNELS); + vq_cnt = have_vq_rx ? VIRTIO_SCMI_VQ_MAX_CNT : 1; + + for (i = 0; i < vq_cnt; i++) { + vioch[i] = devm_kzalloc(dev, sizeof(**vioch), GFP_KERNEL); + if (!vioch[i]) + return -ENOMEM; + } + + if (have_vq_rx) + vioch[VIRTIO_SCMI_VQ_RX]->is_rx = true; + + if (virtio_find_vqs(vdev, vq_cnt, vqs, scmi_vio_complete_callbacks, + scmi_vio_vqueue_names, NULL)) { + dev_err(dev, "Failed to get %d virtqueue(s)\n", vq_cnt); + return -1; + } + dev_info(dev, "Found %d virtqueue(s)\n", vq_cnt); + + for (i = 0; i < vq_cnt; i++) { + spin_lock_init(&vioch[i]->lock); + vioch[i]->vqueue = vqs[i]; + vioch[i]->vqueue->priv = vioch[i]; + } + + vdev->priv = vioch; + + virtio_device_ready(vdev); + + return 0; +} + +static unsigned int features[] = { + VIRTIO_SCMI_F_P2A_CHANNELS, +}; + +static const struct virtio_device_id id_table[] = { + { VIRTIO_ID_SCMI, VIRTIO_DEV_ANY_ID }, + { 0 } +}; + +static struct virtio_driver virtio_scmi_driver = { + .driver.name = "scmi-virtio", + .driver.owner = THIS_MODULE, + .feature_table = features, + .feature_table_size = ARRAY_SIZE(features), + .id_table = id_table, + .probe = scmi_vio_probe, +}; + +int __init virtio_scmi_init(void) +{ + return register_virtio_driver(&virtio_scmi_driver); +} + +void __exit virtio_scmi_exit(void) +{ + unregister_virtio_driver(&virtio_scmi_driver); +} diff --git a/include/uapi/linux/virtio_ids.h b/include/uapi/linux/virtio_ids.h index b052355ac7a3..57d233c02720 100644 --- a/include/uapi/linux/virtio_ids.h +++ b/include/uapi/linux/virtio_ids.h @@ -48,5 +48,6 @@ #define VIRTIO_ID_FS 26 /* virtio filesystem */ #define VIRTIO_ID_PMEM 27 /* virtio pmem */ #define VIRTIO_ID_MAC80211_HWSIM 29 /* virtio mac80211-hwsim */ +#define VIRTIO_ID_SCMI 32 /* virtio SCMI */ #endif /* _LINUX_VIRTIO_IDS_H */ diff --git a/include/uapi/linux/virtio_scmi.h b/include/uapi/linux/virtio_scmi.h new file mode 100644 index 000000000000..9f21b3dbbfe2 --- /dev/null +++ b/include/uapi/linux/virtio_scmi.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* + * Copyright (C) 2020 OpenSynergy GmbH + */ + +#ifndef _UAPI_LINUX_VIRTIO_SCMI_H +#define _UAPI_LINUX_VIRTIO_SCMI_H + +#include + +/* Feature bits */ + +/* Device implements some SCMI notifications, or delayed responses. */ +#define VIRTIO_SCMI_F_P2A_CHANNELS 0 + +/* Device implements any SCMI statistics shared memory region */ +#define VIRTIO_SCMI_F_SHARED_MEMORY 1 + +/* Virtqueues */ + +#define VIRTIO_SCMI_VQ_TX 0 /* cmdq */ +#define VIRTIO_SCMI_VQ_RX 1 /* eventq */ +#define VIRTIO_SCMI_VQ_MAX_CNT 2 + +struct virtio_scmi_request { + __virtio32 hdr; + __u8 data[]; +}; + +struct virtio_scmi_response { + __virtio32 hdr; + __virtio32 status; + __u8 data[]; +}; + +struct virtio_scmi_notification { + __virtio32 hdr; + __u8 data[]; +}; + +#endif /* _UAPI_LINUX_VIRTIO_SCMI_H */