From patchwork Tue May 11 00:20:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 12250371 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D0CCC433B4 for ; Tue, 11 May 2021 10:00:27 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 A9EE661621 for ; Tue, 11 May 2021 10:00:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A9EE661621 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6QRCx3n8/w6kqK/8g+W1DXfgkKOZD9a7mqXIEZhVp+w=; b=dyMq/WsHSm+AOjaUxa/bgb4F5 KPOmPvrQpmmSQkF/OpzA8O/JDOFgLHUvq7L6JguzMj/xDhII0GeoH/DFROyveHXDxbBf1TF78lpnL P4GLE2o7MfAA7vVV8LJRf8WNsQnvPpQh/k/KZRS1HOrUpqjXoO+19KlBO4P3Z1UX9BSAJegjtUhod YEUiiuHiMES0xyfF32uifsImqsRF1vWml4jiiggdzVBzGvqoPfZWoedyxWUTPst6G0OIV+ShCJd8S cO2UejrX6Cvb8zA35doOXR278NyhUiBrJXsJvbqcjoD/C4pTakeQ3oSprZ5A9vhVhiA7NSd7MrZNi n1jRKxEpQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgPAI-00GnZI-6R; Tue, 11 May 2021 09:58:58 +0000 Received: from [2607:7c80:54:e::133] (helo=bombadil.infradead.org) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGoL-00G0ny-T0 for linux-arm-kernel@desiato.infradead.org; Tue, 11 May 2021 01:03:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=ZmQx0CHn1ZF5cPFnLZkXuV6S6R2qGPhY3pMc8jECLR4=; b=Kisfm76RRPX8ZbtGntXUymGQaW 7HclyDYjDt0Mru62quQWLT65q6abdlMUEvlf6M1AZVUb5PN4KYX6H+uNkTz8qJUAHBQa+CAPWu+IL L8sXoExklzPQ1wfvKKazR35JkxdhIkxfrZsBApWdWU12nK88cU1CF8EqKY9DQYaJkYkc8Ck4byZkM hgd+871kLwtD2hzHPEfc3ZvrAJkxLUW367x+7GJfMis4oU8ZxWxzl4WQ7AWoWzj3Vlb6cC2+taZdP A5xRtgIkpQpmUYGclXMVZnwIynl6cZp25EECi/hnHSwOAmdnfAhx0jf/l523DoDTW5Ew6FDk2zhkM dnEsQA2Q==; Received: from mx1.opensynergy.com ([217.66.60.4]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGGQ-009DPt-Hn for linux-arm-kernel@lists.infradead.org; Tue, 11 May 2021 00:28:45 +0000 Received: from SR-MAILGATE-02.opensynergy.com (localhost.localdomain [127.0.0.1]) by mx1.opensynergy.com (Proxmox) with ESMTP id 962D8A1987; Tue, 11 May 2021 02:22:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=opensynergy.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=srmailgate02; bh=ZmQx0CHn1ZF5 cPFnLZkXuV6S6R2qGPhY3pMc8jECLR4=; b=il1zd/GZusW0+LGf64dGfIzZfK2X 6rtXy4NzRDPp/xJ/H9LD/u3lb+mEbrDfkrq0otBFs0FmD7doJa6WYAI8zvzKLuI6 TzSblCZ08WtYp1Yo8aI/8YXf84U0Ocepsutiw2ruyb7cGCENsKkQc9wVGLr5OA1+ ygcmRTnfhRIjeRYjGVwoHlKKx3e7W/2qiyQpDfMhXvGq2mkREcmQ9FJNu74y3DED bGSdsGny+e/xIUR5Rh1dopIcNptVkHBpsVFOrkJ57mhvGdg2c4j/Y8W/YHsajAm3 6xbtDEwy46drTlR/JpejC4fPb2HuaBZyFZDnAlBkyykGJq8BOjZ7xSJyTw== From: Peter Hilber To: , CC: Igor Skalkin , Peter Hilber , Rob Herring , , , , , , , , Vasyl Vavrychuk , Andriy Tryshnivskyy , Cristian Marussi , Mark Rutland , Lorenzo Pieralisi , Jassi Brar Subject: [RFC PATCH v3 01/12] firmware: arm_scmi, smccc, mailbox: Make shmem based transports optional Date: Tue, 11 May 2021 02:20:29 +0200 Message-ID: <20210511002040.802226-2-peter.hilber@opensynergy.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210511002040.802226-1-peter.hilber@opensynergy.com> References: <20210511002040.802226-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-02.open-synergy.com (10.26.10.22) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172842_808378_2E28202B X-CRM114-Status: GOOD ( 15.22 ) /bin/ln: failed to access 'reaver_cache/texts/20210510_172842_808378_2E28202B': No such file or directory X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172842_808378_2E28202B X-CRM114-Status: GOOD ( 12.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.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. Signed-off-by: Igor Skalkin [ Peter: Adapted patch for submission to upstream. ] Co-developed-by: Peter Hilber Signed-off-by: Peter Hilber --- drivers/firmware/Kconfig | 8 +++++++- 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, 14 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index db0ea2d2d75a..80ff49dadf35 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,12 @@ 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 + 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 6a2ef63306d6..5a2d4c32e0ae 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 voltage.o diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 228bf4a71d23..94dcfb8c0176 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -330,7 +330,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 66eb3f0e5daf..41d80bbaa9a2 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -1567,7 +1567,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 68de2c6af727..fc02c38c0739 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 Tue May 11 00:20:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 12250381 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E856C433ED for ; Tue, 11 May 2021 10:02:00 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 E308761352 for ; Tue, 11 May 2021 10:01:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E308761352 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YJt/SWQqIRwuFXG5qPy8ZHwtf4V4OLKsHeoJYfXYGuo=; b=qzH8y2WnCGFHeHr5oEAI78eVS T/Anm64CtH/bG9m72nFU+ybhxk2QSZ4/jUpCmTFCzERP6uiC6w7huL7CcFfudNozD8omSLeR3NR83 Jsvqy7RW3oYtvMqibKAcj7zujnxH9fUK/iIHxtW3zPBk20RbmePhygz00AjT/O5hHUFMOkuQqFKLP 71h4FM92tHG0QecZPvHZh4BKOGSSvX6mcQ9Hs/Sv5VPGNjzYHYCKQLikeQASWsLodv9YT1dSHNBYq sMQIUzqFUHm1OWMm4JMze/1wIv4Gfl7E0ZONFkxQYHoGc7tt73nn3yMuc0Nd6rdPu3H5cS7GWfZfV XdyRxGspg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgPBk-00Gnzg-RO; Tue, 11 May 2021 10:00:30 +0000 Received: from [2607:7c80:54:e::133] (helo=bombadil.infradead.org) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGof-00G0q2-Iq for linux-arm-kernel@desiato.infradead.org; Tue, 11 May 2021 01:04:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=OU+HtaTs8FvoJVnDadVJ79nNHdyp+spOITIiOi6q/EY=; b=usW0A9SUfFwj43BWyX/d/kPlmU cRmJwQC04uRpxZM3/4I7ustj2q9NSZyo8hHKtKmDKyknS4V8MOIzdUiA6RE1bZVEn0a4NIsBhYWzm 142niFnLrvZWJONSY6QC5kxq38pg9/s05uc54OqDmeBaQumnRxqewDIOtSQNhonAhMF4NJ8CbSeXU dmW1weAc1UOF9rmGl9PIR8QwWcL0rdF7thI1HQcuMGIrgqxQ3RS+zHxpj/iM5taGvVjskaf8/gx2W WbIkbrQhQ0L4rikgUowNxYQimrxLVdV4Qqq39Rw7mLNCfEGedW/ebLaLItGIE1giqZBwdAzgzPgm6 3fWEVcEw==; Received: from mx1.opensynergy.com ([217.66.60.4]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGGO-009DOz-LJ for linux-arm-kernel@lists.infradead.org; Tue, 11 May 2021 00:28:42 +0000 Received: from SR-MAILGATE-02.opensynergy.com (localhost.localdomain [127.0.0.1]) by mx1.opensynergy.com (Proxmox) with ESMTP id 4B3C3A1A12; Tue, 11 May 2021 02:22:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=opensynergy.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=srmailgate02; bh=OU+HtaTs8Fvo JVnDadVJ79nNHdyp+spOITIiOi6q/EY=; b=Q6e3d650yUpUKNqe1tItVEO+y1Of mkEptEEXBi3JmUTqq0hYd9Wl/L8iwt4cWn09CUoEQhd9oo//HYwNbmw8wDZFEP+F PST0J/epi8V0j545ALWeXD4UMPHnErPKW4cgYxlER8yYLbR1ZVaX+O75va+OWujO HvdNHIkHezDdZ7cFH8xzpJdbbcHclCVZPXvC1R79MKd7B31huAGQ2hMCQHFGOk7f 3vEGl260cGGfZnKFMgNdQw3YcPLnmZ66VgpHESL7Am/MgLPaiwFIJhvAL7BY2EKc SKchiSGSYuMTzfrDbeBJIJoE1CkZkjxbpl9+gW6M0yp6ypxKDh1iMvHJ2A== From: Peter Hilber To: , CC: Cristian Marussi , Peter Hilber , Rob Herring , , , , , , , , , Vasyl Vavrychuk , Andriy Tryshnivskyy Subject: [RFC PATCH v3 02/12] firmware: arm_scmi: Add transport init/deinit Date: Tue, 11 May 2021 02:20:30 +0200 Message-ID: <20210511002040.802226-3-peter.hilber@opensynergy.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210511002040.802226-1-peter.hilber@opensynergy.com> References: <20210511002040.802226-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-02.open-synergy.com (10.26.10.22) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172840_901724_E2E21B74 X-CRM114-Status: GOOD ( 12.80 ) /bin/ln: failed to access 'reaver_cache/texts/20210510_172840_901724_E2E21B74': No such file or directory X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172840_901724_E2E21B74 X-CRM114-Status: GOOD ( 10.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Cristian Marussi Signed-off-by: Cristian Marussi [ Peter: Adapted RFC patch by Cristian for submission to upstream. ] Signed-off-by: Peter Hilber --- drivers/firmware/arm_scmi/common.h | 2 ++ drivers/firmware/arm_scmi/driver.c | 45 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 94dcfb8c0176..961a3c63cc42 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -324,6 +324,8 @@ struct scmi_device *scmi_child_dev_find(struct device *parent, * @max_msg_size: Maximum size of data per message that can be handled. */ struct scmi_desc { + int (*init)(void); + void (*exit)(void); const struct scmi_transport_ops *ops; int max_rx_timeout_ms; int max_msg; diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 41d80bbaa9a2..471c5de827c1 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -1588,10 +1588,53 @@ static struct platform_driver scmi_driver = { .remove = scmi_remove, }; +static inline int __scmi_transports_setup(bool init) +{ + int ret = 0; + const struct of_device_id *trans; + + for (trans = scmi_of_match; trans->data; trans++) { + const struct scmi_desc *tdesc = trans->data; + + if ((init && !tdesc->init) || !tdesc->exit) + continue; + pr_info("SCMI %sInitializing %s transport\n", init ? "" : "De-", + trans->compatible); + if (init) + ret = tdesc->init(); + else + tdesc->exit(); + + if (ret) { + pr_err("SCMI transport %s FAILED initialization!\n", + trans->compatible); + break; + } + } + + return ret; +} + +static int __init scmi_transports_init(void) +{ + return __scmi_transports_setup(true); +} + +static void __exit scmi_transports_exit(void) +{ + __scmi_transports_setup(false); +} + static int __init scmi_driver_init(void) { + int ret; + scmi_bus_init(); + ret = scmi_transports_init(); + if (ret) + return ret; + scmi_base_register(); scmi_clock_register(); @@ -1618,6 +1661,8 @@ static void __exit scmi_driver_exit(void) scmi_voltage_unregister(); scmi_system_unregister(); + scmi_transports_exit(); + scmi_bus_exit(); platform_driver_unregister(&scmi_driver); From patchwork Tue May 11 00:20:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 12250351 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3211AC433B4 for ; Tue, 11 May 2021 09:55:13 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 875CD6192C for ; Tue, 11 May 2021 09:55:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 875CD6192C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=g8RZA8ZY1cQskUXEoHWlAwL7dUm+SyygSGgmjSKRpfw=; b=BXQeYJ5P1yt1H3I7WtOcixfnP eTW/NQHvEOnmqc2iohUM6ohnZzt3auvMHhBL18wLZitmQFUACFEfS7rLDGfDpeKNmJS4RPv99NqBr NkFs2c88EVPMtPxaKS0b7Yko0ehwzVfOke4IYtv8zSPGCSvXGNIbNVpIbsKkG8fK68w0tlKKdQJAn xZu75Oq/6o/6nzCnj3D710p31y6SsTPU2zmZmd1EsHCdI3uqEua2n8IP3bbDXruxUtqyGHl/g10zM Rf26sw3N0eiW9Q1DMIY6HydKLG6N8t19vCfqk9F9FSDAvfZghlDrwloTx4+Id71/damkGsicXZ/zu weQUKx5Rw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgP5W-00GmCC-9c; Tue, 11 May 2021 09:54:02 +0000 Received: from [2607:7c80:54:e::133] (helo=bombadil.infradead.org) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGQA-00FzTz-J6 for linux-arm-kernel@desiato.infradead.org; Tue, 11 May 2021 00:38:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=wYfvrsc5PO1aVt2cRGcaZm71OUBsPX7ZwvdHqdDVxsM=; b=2bqEI9y553YbwwbVK8ID4WSJ9V GIL+eJPI9u3el3WgQbgDJEUQ47bbP1Dg+WcqMxBpkoDMLQYfcy5z08NOTIYMyDRKouZqFr00gJBd8 7jLU/hMqdgBylw3tqsqBqQCuFyZYl5cvzXqmQJpMKBeCnVd16JvUqDwEjdPL/Dhw3c/rahP3ZHTIZ Y66RqK6TuonQNO9XbXkfUlVOR+pnC3k34ISOlLgaARLoheipypEP91cn/ijFDc9wwn2tDxUbu0bRS 5kV3sKAUws9TU7JQ44GgsK+W96DZSrVaSbIH3Wb3R0mvFt8INYg4yaT/4C7nXh4ec3ehH3Gx/8Uv9 acf8DhVw==; Received: from mx1.opensynergy.com ([217.66.60.4]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGQ2-009Dn3-TV for linux-arm-kernel@lists.infradead.org; Tue, 11 May 2021 00:38:41 +0000 Received: from SR-MAILGATE-02.opensynergy.com (localhost.localdomain [127.0.0.1]) by mx1.opensynergy.com (Proxmox) with ESMTP id 4A792A1A25; Tue, 11 May 2021 02:22:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=opensynergy.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=srmailgate02; bh=wYfvrsc5PO1a Vt2cRGcaZm71OUBsPX7ZwvdHqdDVxsM=; b=FmCILYo4aAtl/aI2pFU9aDzCGjS+ JgqG/bWbOXlh5DxrXKObppb8B1s0xBLKkF/3+GJlRGor8+WO74yoomdWJqjpLQT4 7SrlbkmPxwqKrmsJxhoYaEXnDVji0wPiEjW2qUYLHYG17j1wd8z9UivmZpAdI7ql VW6XvOuNtJMKyVU7IlWJZUOkWzP04QlSui3JPt95scIkywZht8MungUQzVbJwoXr eyNiCM0WnLHW6Kn7h9aCwhuHxv8v28JRFAqjNqIctM8kqBWn3/eobc3UzSWnd+4/ ZF/k5Wz+I3LRtvmKcpwzuLmpZgKZMTvVoa3Goda7lY/LW2kuB12NF7fcpQ== From: Peter Hilber To: , CC: Igor Skalkin , Peter Hilber , Rob Herring , , , , , , , , Vasyl Vavrychuk , Andriy Tryshnivskyy , Cristian Marussi Subject: [RFC PATCH v3 03/12] firmware: arm_scmi: Add op to override max message # Date: Tue, 11 May 2021 02:20:31 +0200 Message-ID: <20210511002040.802226-4-peter.hilber@opensynergy.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210511002040.802226-1-peter.hilber@opensynergy.com> References: <20210511002040.802226-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-02.open-synergy.com (10.26.10.22) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_173839_143579_AD4E9097 X-CRM114-Status: GOOD ( 21.27 ) /bin/ln: failed to access 'reaver_cache/texts/20210510_173839_143579_AD4E9097': No such file or directory X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_173839_143579_AD4E9097 X-CRM114-Status: GOOD ( 18.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Igor Skalkin The number of simultaneously pending 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. Reflect that the limit in struct scmi_desc is now only a default any more. Signed-off-by: Igor Skalkin [ Peter: Adapted patch for submission to upstream. ] Co-developed-by: Peter Hilber Signed-off-by: Peter Hilber --- drivers/firmware/arm_scmi/common.h | 9 ++++-- drivers/firmware/arm_scmi/driver.c | 44 +++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 961a3c63cc42..13be8dedcd6b 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -286,6 +286,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 + * @return: 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 @@ -298,6 +301,7 @@ 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); + unsigned int (*get_max_msg)(bool tx, struct scmi_chan_info *base_cinfo); int (*send_message)(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer); void (*mark_txdone)(struct scmi_chan_info *cinfo, int ret); @@ -319,8 +323,9 @@ struct scmi_device *scmi_child_dev_find(struct device *parent, * * @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. 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 471c5de827c1..b7271f8fd1c7 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -73,11 +73,13 @@ struct scmi_requested_dev { * 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; }; /** @@ -224,13 +226,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); } @@ -1013,32 +1013,39 @@ 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) + info->max_msg = desc->ops->get_max_msg(tx, base_cinfo); + /* 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) @@ -1055,10 +1062,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 Tue May 11 00:20:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 12250353 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85175C433ED for ; Tue, 11 May 2021 09:55:23 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 E29496186A for ; Tue, 11 May 2021 09:55:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E29496186A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=szK2lDEZGz0TZEOq5l15xpTcWjjbTfH11adtx01XLxY=; b=LdPatBriRY0nCV5MdG0d6a8a1 av8s5eMQQNxjIpoOGKg9KGy60zmDU6qw5rymmEfZCFFruPbUK+rznTc8Haj6U6MQEJZVYh9uIAnFb w5Z2KIA6RMqlQ+dpg/Sklt6x+5+HlD+PIXm2j5AaRW7Q7/P4pPwBBsrc1TWm3xDBK5fcHDS1SHLwu bM7ipamN8jSStoVndkG8EVHF7r6YoH4iZEJwfPUbUqacj+eqHtjPttnQsxJOM7ulo+gaFoJ4TLuXJ Pi/eeEXos6Ug5a6EsjpPr9ibfFFeeZ90e5cHvEAUis5Ygeb9P9jCJMT+eF8B+KLNOCWAZSRNi83vW EId9TrmkQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgP5h-00GmDL-91; Tue, 11 May 2021 09:54:13 +0000 Received: from [198.137.202.133] (helo=bombadil.infradead.org) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGQC-00FzUN-2D for linux-arm-kernel@desiato.infradead.org; Tue, 11 May 2021 00:38:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=u2R/F8gzBLp/QsX1CQem5LuI8ZQQb+bW1B2JAci57oY=; b=hd3IDp8wYC+MVHdXZVtRfDT5WO klXGNopANhOzSWSc3P5IdSNizWG7N0zSnVCbcSyJJiBY71Qw1HF1gXEPAh4939tWP9JqtIgZa/UvF te4l32wuadL0bZBXN+NWHouUGnYIlxevzMu8Rr918PMsxWX2SoH2yJEwksFfHM94+l0Y6gUcErcNO JJd3U0NrBu0kJuWgtmg1SW2L3RXleeRI1AkRjARMUiNYTAfhzrekEAnm9//4Ij1PPXdDaiT2wpd9z cC6Z5zhbHYoVv9HWqFLvr3ckFJPSWn9wQ8CviLJeX/HCR4QJ4jajkPKe0igf0yxtZ4V+LY0cu0QNd p1dohOPw==; Received: from mx1.opensynergy.com ([217.66.60.4]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGQ2-009Dn5-TV for linux-arm-kernel@lists.infradead.org; Tue, 11 May 2021 00:38:40 +0000 Received: from SR-MAILGATE-02.opensynergy.com (localhost.localdomain [127.0.0.1]) by mx1.opensynergy.com (Proxmox) with ESMTP id C6EF7A1A28; Tue, 11 May 2021 02:22:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=opensynergy.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=srmailgate02; bh=u2R/F8gzBLp/ QsX1CQem5LuI8ZQQb+bW1B2JAci57oY=; b=nhH8Ojjk7BDWo/aNGYA5vxOI3ePd gKDHty8/N/wAP6zmG8gU7lFLot0XE6PvT+kDl+/3+fcPqjRzcxpvYutlafycI7Qm afj4d017ZmK6IZrIYEaPdn6QQlsfJBv+rfImvs6ZrgfRzKhSULAU0GNpU5rr1zSu LDULKHxiZh+G6txpVg2MQ2m72Noygpwg2jE4hTJMRy2o6zVMai7FJBXdaCtGOsli ttWSLGJI39K2EFzRGSDCrvD8CWaEt4V9RHxhIu/cSn0NhEPlQHp9JO+fEGry8gXh /CMGKcLRwX7xFUL8wpdPugZUN8+pcfqrpoJw0OdZndxCAdnW8hpDKxOJzQ== From: Peter Hilber To: , CC: Peter Hilber , Rob Herring , , , , , , , , , Vasyl Vavrychuk , Andriy Tryshnivskyy , Cristian Marussi Subject: [RFC PATCH v3 04/12] firmware: arm_scmi: Add optional link_supplier() transport op Date: Tue, 11 May 2021 02:20:32 +0200 Message-ID: <20210511002040.802226-5-peter.hilber@opensynergy.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210511002040.802226-1-peter.hilber@opensynergy.com> References: <20210511002040.802226-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-02.open-synergy.com (10.26.10.22) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_173839_136199_D7E4C154 X-CRM114-Status: GOOD ( 11.91 ) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_173839_136199_D7E4C154 X-CRM114-Status: UNSURE ( 9.73 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For the scmi-virtio transport, it might not be possible to refer to the proper virtio device at device tree build time. Therefore, add an op which will allow scmi-virtio to dynamically link to the proper virtio device during probe. Signed-off-by: Peter Hilber --- drivers/firmware/arm_scmi/common.h | 2 ++ drivers/firmware/arm_scmi/driver.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 13be8dedcd6b..d60e3c26821d 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -283,6 +283,7 @@ struct scmi_chan_info { /** * struct scmi_transport_ops - Structure representing a SCMI transport ops * + * @link_supplier: Optional callback to add link to a supplier device * @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 @@ -297,6 +298,7 @@ struct scmi_chan_info { * @poll_done: Callback to poll transfer status */ struct scmi_transport_ops { + int (*link_supplier)(struct device *dev); bool (*chan_available)(struct device *dev, int idx); int (*chan_setup)(struct scmi_chan_info *cinfo, struct device *dev, bool tx); diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index b7271f8fd1c7..df526ff37c6d 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -1434,6 +1434,12 @@ static int scmi_probe(struct platform_device *pdev) handle->devm_protocol_get = scmi_devm_protocol_get; handle->devm_protocol_put = scmi_devm_protocol_put; + if (desc->ops->link_supplier) { + ret = desc->ops->link_supplier(dev); + if (ret) + return ret; + } + ret = scmi_txrx_setup(info, dev, SCMI_PROTOCOL_BASE); if (ret) return ret; From patchwork Tue May 11 00:20:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 12250369 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A6EEC433B4 for ; Tue, 11 May 2021 10:00:06 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 96B0D61363 for ; Tue, 11 May 2021 10:00:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 96B0D61363 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8Kv0xTyKVVGfeaiH72FK+KCutQ+oATdrMFzD88E15VE=; b=CzQ6kMamzjAFiespVjXQaJu/K OBG2TCLfEysKxRkF2ZxPd/azEKca6b06ZzRd8Nt+tecyJha+26jfgylK9u6GIajurcFFVnySDmETJ 4PU1WfvYu4cZM/+xXlOnCAjJxC28Pi1S3TYYI6tDeqZ6DTaKMP1o/VZnnYtFag2seK9fjxHPiLCQ1 n43/mT8uxAPzADw6skHZtDLnl7TMChp/OiDyxTOGC/C4lAwiozISlgygoLYZCuLPsc1mZQU0lV9Jp 9RKWXUOgH09Y3qGvbr82sj7rbN+dpVFyw/MMzTj/ppG1p+EzDTX0TtE/D/Z0YjDLoGGhH9vezqkCx q2UcnRA1g==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgPA6-00GnWo-CR; Tue, 11 May 2021 09:58:46 +0000 Received: from [2607:7c80:54:e::133] (helo=bombadil.infradead.org) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGoH-00G0nV-Em for linux-arm-kernel@desiato.infradead.org; Tue, 11 May 2021 01:03:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=6+VlSkKWGdjkDM6nZTn7Ha5NxKkKwBbIL6DCLdewkbA=; b=db74ybAu+kb8esNlF/I0CQmO5x +OmDh/NVf7Duj7zAcgEEba0XR0R/cLb+wcOJ5S23L1SEWQeL0Yx/eCdMo2BKqAYTuYbDnhsNdf8Ba FNtcXtjBvxJ0jQC2buV/A4nlKytLb/WSAxPpXHjRp7I+SEwC8I4zXgAs4yOnjRafqZG/5sdA9MbIU 6F7FNfRXqMk5neuOaDv5DeDCG7L6x2ElS+wrINOs7Gk6gMrcVQsUVBIEA1nvSbXJ1L6WegBHYch83 Z/yl1ilQdhD6yvWzSTcxoRri7GMyOlKvrLXJNgnQbtEiMl/s8A60ORkQ97pwbAsv1Vw14801uBc4N mRoJ4z3A==; Received: from mx1.opensynergy.com ([217.66.60.4]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGGQ-009DPu-IO for linux-arm-kernel@lists.infradead.org; Tue, 11 May 2021 00:28:45 +0000 Received: from SR-MAILGATE-02.opensynergy.com (localhost.localdomain [127.0.0.1]) by mx1.opensynergy.com (Proxmox) with ESMTP id 7D13CA1A2E; Tue, 11 May 2021 02:22:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=opensynergy.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=srmailgate02; bh=6+VlSkKWGdjk DM6nZTn7Ha5NxKkKwBbIL6DCLdewkbA=; b=CGnQklXHC54GKgHiTz1MnYznchZN K0SvNZczQ/nM6pQopfMiFXgQ1Y5Bz0F1Piarn8SQ6qSXSHWJmqATT06yIQSNRLC3 Mlc8FLjDLl4uToDbeqbSQ3fIF/2RE8zT93ferkKSKP3awqndteNHn+UFhwjhoTJX 73x+yhxH6cgqmgusSRcdlaJL+SdKItlvIMmT54dtJedOH/zwenv8eZnjAESqXSlL FVsCR4Kh4hF8OtbqXUYIVm0+PCrYcyZx0ka8A7wxFGNsYVadRiObSsYAPJEzc3aV 81lzp8hXK0xYmnRCEDkg6ktg0+mcbIJIbnv+jUPn0y5CEyhCq/aBmVlLig== From: Peter Hilber To: , CC: Peter Hilber , Rob Herring , , , , , , , , , Vasyl Vavrychuk , Andriy Tryshnivskyy , Cristian Marussi Subject: [RFC PATCH v3 05/12] firmware: arm_scmi: Add per-device transport private info Date: Tue, 11 May 2021 02:20:33 +0200 Message-ID: <20210511002040.802226-6-peter.hilber@opensynergy.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210511002040.802226-1-peter.hilber@opensynergy.com> References: <20210511002040.802226-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-02.open-synergy.com (10.26.10.22) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172842_824504_9EB0FD2C X-CRM114-Status: GOOD ( 10.79 ) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172842_824504_9EB0FD2C X-CRM114-Status: UNSURE ( 8.60 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The scmi-virtio transport will link a supplier device to the arm-scmi device in the link_supplier() op. The transport should then save a pointer to the linked device. To enable this, add a transport private info to the scmi_info. (The scmi_info is already reachable through the arm-scmi device driver_data.) Signed-off-by: Peter Hilber --- drivers/firmware/arm_scmi/common.h | 2 ++ drivers/firmware/arm_scmi/driver.c | 35 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index d60e3c26821d..61b22cdeaeeb 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -346,6 +346,8 @@ extern const struct scmi_desc scmi_mailbox_desc; extern const struct scmi_desc scmi_smc_desc; #endif +int scmi_set_transport_info(struct device *dev, void *transport_info); +void *scmi_get_transport_info(struct device *dev); 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 df526ff37c6d..581b6c9b3781 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -127,6 +127,7 @@ struct scmi_protocol_instance { * @active_protocols: IDR storing device_nodes for protocols actually defined * in the DT and confirmed as implemented by fw. * @notify_priv: Pointer to private data structure specific to notifications. + * @transport_info: Transport private info * @node: List head * @users: Number of users of this instance */ @@ -145,6 +146,7 @@ struct scmi_info { u8 *protocols_imp; struct idr active_protocols; void *notify_priv; + void *transport_info; struct list_head node; int users; }; @@ -382,6 +384,39 @@ void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr) } } +/** + * scmi_set_transport_info() - Set transport private info + * + * @dev: SCMI instance device + * @transport_info: transport private info + * + * Return: 0 on success, otherwise error. + */ +int scmi_set_transport_info(struct device *dev, void *transport_info) +{ + struct scmi_info *info = dev_get_drvdata(dev); + + if (!info) + return -EBADR; + + info->transport_info = transport_info; + return 0; +} + +/** + * scmi_get_transport_info() - Get transport private info + * + * @dev: SCMI instance device + * + * Return: transport private info on success, otherwise NULL. + */ +void *scmi_get_transport_info(struct device *dev) +{ + struct scmi_info *info = dev_get_drvdata(dev); + + return info ? info->transport_info : NULL; +} + /** * xfer_put() - Release a transmit message * From patchwork Tue May 11 00:20:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 12250375 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FD8AC433ED for ; Tue, 11 May 2021 10:00:44 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 F187161621 for ; Tue, 11 May 2021 10:00:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F187161621 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Gx+8Ir1TQHq0OosiQW7TEmAKs1IFXYgupVi9nKp8FIc=; b=kUaxaNebdrFipw074SsyLhUFs wl/b+5WULe1Pj4xke6M6fiF9ZXoYaun73v+oaffpTcKNSZ/aB7ogwgWquOeenYwt2+3l+muKgoqDK JzF/oi5LHxmXcEd+sdXg6HbCOEJ0vDvSxeNLS26tSOYCytggIXnav7wiEqMhK3K5LgXjI/3zK5RO7 ZpZIQbCrTCFykaHCl9BEz26V7S/NGJJXfCoCQDUJM6PrYR1U4txADlk+fBmQjMLlvAes8J7FQtA7w xyyP5dD9snq9xyB6J+7f0j3/SvCGqZrWJoOZFzehIa3g7excYmGwQyOxzqjSEgJJyPAiTwDsqBpdw sFPLOuZaQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgPAm-00Gnfj-FM; Tue, 11 May 2021 09:59:28 +0000 Received: from [2607:7c80:54:e::133] (helo=bombadil.infradead.org) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGoU-00G0on-2N for linux-arm-kernel@desiato.infradead.org; Tue, 11 May 2021 01:03:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=uVXQj8vtCYsoWfIdT2YmI6MruqMQhZ51sMrsMngt+4c=; b=OtxF7l393eI95Mx6Cy2YjRFZpl ZQ66GT7VkRPZcRQmcL4QiTtZfnAzlo+F8iad6OsQlbO8Wm+ShD3nQh9nJHmYgxKLewnCng5i//hEG fdE5mOyTEYRM6DJdKvIY3YHo7tiUeaGJqMQwVbJw9z9FGmJ6u509jlbMKcfi8DvKhEK/xMNRO8UOu H+NS+WJyfp1JvzWUNWNgH7UEC7Ff6grRcyXa+OZhMtJlaWR5ea59TdRzmLGyoENytR0Xd99x0N1Tr 5CDZPmJWRDpa7XQqxqwZjtuVB8n8VzGef3YxXTp7KJ1u1cjv3TCvpaDxpdTHwd5raqzRfkpA1Vcmk OLjUTWKA==; Received: from mx1.opensynergy.com ([217.66.60.4]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGGQ-009DPp-H6 for linux-arm-kernel@lists.infradead.org; Tue, 11 May 2021 00:28:44 +0000 Received: from SR-MAILGATE-02.opensynergy.com (localhost.localdomain [127.0.0.1]) by mx1.opensynergy.com (Proxmox) with ESMTP id 1B765A1A30; Tue, 11 May 2021 02:22:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=opensynergy.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=srmailgate02; bh=uVXQj8vtCYso WfIdT2YmI6MruqMQhZ51sMrsMngt+4c=; b=bub2NUPQ/1YkHW/fBbb4rG6AQdkz 53zguMOjN7F+aEjMXK1IfPIpCrOOb0eNS5MMVhePifFi074BXvPPYN/sAWXRvrmX TdwmYlCc9MAPpVMEB15jf6tLCejtiebPengFdBWMFH0RDhUIiBRM45bOTU7bnupZ z6Slz8DMjiJ1/7jmL7EzPoZtR7vEDYjhQnVY3+7j/yekK7HDF5wXZMGQ718WK9Pb lRTLW3ZWqKv7QkP7ZK0+Up369Rrm3ZV8bZ9CKbe3VcbPy0lGlQrYkzrlppef/5fA SHAOMj5sSelTbNboJRAcJbQIWyHjSDPupXKXtlortgkHOaIVnQWRoQYnXA== From: Peter Hilber To: , CC: Peter Hilber , Rob Herring , , , , , , , , , Vasyl Vavrychuk , Andriy Tryshnivskyy , Cristian Marussi Subject: [RFC PATCH v3 06/12] firmware: arm_scmi: Add is_scmi_protocol_device() Date: Tue, 11 May 2021 02:20:34 +0200 Message-ID: <20210511002040.802226-7-peter.hilber@opensynergy.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210511002040.802226-1-peter.hilber@opensynergy.com> References: <20210511002040.802226-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-02.open-synergy.com (10.26.10.22) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172842_752888_37A3AC22 X-CRM114-Status: UNSURE ( 9.64 ) X-CRM114-Notice: Please train this message. X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172842_752888_37A3AC22 X-CRM114-Status: UNSURE ( 7.33 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The scmi-virtio transport driver will need to distinguish SCMI protocol devices from the SCMI instance device in the chan_setup() and chan_free() ops. Add this internal helper to be able to distinguish the two. Signed-off-by: Peter Hilber --- drivers/firmware/arm_scmi/bus.c | 5 +++++ drivers/firmware/arm_scmi/common.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c index 784cf0027da3..06148e972d1a 100644 --- a/drivers/firmware/arm_scmi/bus.c +++ b/drivers/firmware/arm_scmi/bus.c @@ -134,6 +134,11 @@ static struct bus_type scmi_bus_type = { .remove = scmi_dev_remove, }; +bool is_scmi_protocol_device(struct device *dev) +{ + return dev->bus == &scmi_bus_type; +} + int scmi_driver_register(struct scmi_driver *driver, struct module *owner, const char *mod_name) { diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 61b22cdeaeeb..9488c682a51d 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -231,6 +231,8 @@ struct scmi_protocol { const struct scmi_protocol_events *events; }; +bool is_scmi_protocol_device(struct device *dev); + int __init scmi_bus_init(void); void __exit scmi_bus_exit(void); From patchwork Tue May 11 00:20:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 12250349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C244DC433B4 for ; Tue, 11 May 2021 09:54:57 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 28EDD61363 for ; Tue, 11 May 2021 09:54:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 28EDD61363 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=L8sSuEr4Id6gOjLWgklxDi3qpmHV/9TB4owVZAkq/SY=; b=kny9y6D1fpdGi3zI6J47HPvkI gRFRnQA0DoZj/hCbl/5RdimdRdYR4ynV0H9Uk+NOKTnieP2NZ1xpw2thiWzDGanC4t+ZwjWwBJgnG kjGQXmR9wSyUaaZAQcqkupZd8QmlpVY6zJploOWSynnLpaJXSs/4pvUcB7XmHcyzCEB6Pt7EBVTo8 6HZJ4AHS4cO9GmIbx1myhsp4rB7dL5U0TiQoD3esocaG70mMEhW+J2dq5VgdVpqpPcLCjZ4taGVav Gh69G7jq9PLGt+BlRPd0nfEm5O4JejWDLonwiIPTSMdj/Xp6GWprfKiG7aqJ0JBGqIuAE2MCDwTw5 W/XebAv5A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgP5J-00GmAx-UH; Tue, 11 May 2021 09:53:50 +0000 Received: from [2607:7c80:54:e::133] (helo=bombadil.infradead.org) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGQA-00FzTy-Jo for linux-arm-kernel@desiato.infradead.org; Tue, 11 May 2021 00:38:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=/5Dxcbib2uhul8GgPx/VJRtYLOF11009NaDVvtRbKkg=; b=p6YaEjiYLeLDElib6gatlBFd/M hEIgzXWY176z7NRFRb9HVIU4lPWmYUpyl1lH8ndL19FjX+ylirMXf9JNr1RVBGMKDb+d5k8Iwi+Mt AdGjYyPxd4Fm+RRavzJo1Y+ZJX/gkZhYl6XX08b/iSKFeV0YIyOj4x4P9SmkHKOH9h8orY3qWtw9U ZsjoNh8Dp2b9i0Vfw8i+baeX90pIgpJNOismdKVPvcrkzhuICjM2HqMwjOuu8UzUABTWJQ4UxJ53U RQkHyFB3/00MtKI9lB8qYa9oiU3SBf/oQMcGHpfE/om74XT0xDg76RIh6CqKx3f9qcCxk0Y/0a04r vcgbLDDQ==; Received: from mx1.opensynergy.com ([217.66.60.4]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGQ2-009Dn4-TU for linux-arm-kernel@lists.infradead.org; Tue, 11 May 2021 00:38:41 +0000 Received: from SR-MAILGATE-02.opensynergy.com (localhost.localdomain [127.0.0.1]) by mx1.opensynergy.com (Proxmox) with ESMTP id 3D911A1A32; Tue, 11 May 2021 02:22:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=opensynergy.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=srmailgate02; bh=/5Dxcbib2uhu l8GgPx/VJRtYLOF11009NaDVvtRbKkg=; b=ZeN6OTiYGFHRcbQZmlEyWwXZybUo J3X0++xambBLe+GJ+VSQ8qmpUE7x97am3+9Gh3bHPPHXpJPVWpB7Rl9EEuGnchcY MLPHkrdVnCNDoP55fS2pZw9BT0sDMglxLPjgZNu+tI0svX9bOxyG/p2bprfHjTV/ Xr5phJJhWRymwbiT23Fai5395Px8DRZRP0YrjxNIw70q0kag6zYZIPrmDHJc339s 4u1xpa73CjqfFF15zz4rr0SKh77wKXhZp2S3TuNUw5mHf7Qf86IiQULED0kpDHwW KNH6O05SlpEyCy7d+MEk24pIOPPSepzdF3cC1tTRJC+ZmtrjL20SJFylAg== From: Peter Hilber To: , CC: Peter Hilber , Rob Herring , , , , , , , , , Vasyl Vavrychuk , Andriy Tryshnivskyy , Cristian Marussi Subject: [RFC PATCH v3 07/12] firmware: arm_scmi: Add msg_handle to some transport ops Date: Tue, 11 May 2021 02:20:35 +0200 Message-ID: <20210511002040.802226-8-peter.hilber@opensynergy.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210511002040.802226-1-peter.hilber@opensynergy.com> References: <20210511002040.802226-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-02.open-synergy.com (10.26.10.22) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_173839_139794_263CD38E X-CRM114-Status: GOOD ( 14.56 ) /bin/ln: failed to access 'reaver_cache/texts/20210510_173839_139794_263CD38E': No such file or directory X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_173839_139794_263CD38E X-CRM114-Status: GOOD ( 12.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The upcoming virtio transport may xfer several SCMI messages in parallel on a channel. But the transport ops which fetch messages lack information through which a transport can determine which of several messages the core intends to address. The virtio transport should not rely on the current implementation details of the core to deduce the message. Disambiguate this by having the transport pass an opaque message handle to scmi_rx_callback(), which the transport will then use in the message fetching transport ops to identify which message to address. Do not address how to handle the polling mechanism for now. The existing transports can just ignore the message handle. Signed-off-by: Peter Hilber --- drivers/firmware/arm_scmi/common.h | 8 ++++---- drivers/firmware/arm_scmi/driver.c | 20 +++++++++++--------- drivers/firmware/arm_scmi/mailbox.c | 7 ++++--- drivers/firmware/arm_scmi/smc.c | 5 +++-- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 9488c682a51d..5ab2ea0f7db2 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -310,9 +310,9 @@ struct scmi_transport_ops { struct scmi_xfer *xfer); void (*mark_txdone)(struct scmi_chan_info *cinfo, int ret); void (*fetch_response)(struct scmi_chan_info *cinfo, - struct scmi_xfer *xfer); - void (*fetch_notification)(struct scmi_chan_info *cinfo, - size_t max_len, struct scmi_xfer *xfer); + struct scmi_xfer *xfer, void *msg_handle); + void (*fetch_notification)(struct scmi_chan_info *cinfo, size_t max_len, + struct scmi_xfer *xfer, void *msg_handle); void (*clear_channel)(struct scmi_chan_info *cinfo); bool (*poll_done)(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer); }; @@ -350,7 +350,7 @@ extern const struct scmi_desc scmi_smc_desc; int scmi_set_transport_info(struct device *dev, void *transport_info); void *scmi_get_transport_info(struct device *dev); -void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr); +void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr, void *msg_handle); void scmi_free_channel(struct scmi_chan_info *cinfo, struct idr *idr, int id); /* shmem related declarations */ diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 581b6c9b3781..cc27978b4bea 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -272,7 +272,8 @@ __scmi_xfer_put(struct scmi_xfers_info *minfo, struct scmi_xfer *xfer) spin_unlock_irqrestore(&minfo->xfer_lock, flags); } -static void scmi_handle_notification(struct scmi_chan_info *cinfo, u32 msg_hdr) +static void scmi_handle_notification(struct scmi_chan_info *cinfo, u32 msg_hdr, + void *msg_handle) { struct scmi_xfer *xfer; struct device *dev = cinfo->dev; @@ -292,7 +293,7 @@ static void scmi_handle_notification(struct scmi_chan_info *cinfo, u32 msg_hdr) unpack_scmi_header(msg_hdr, &xfer->hdr); scmi_dump_header_dbg(dev, &xfer->hdr); info->desc->ops->fetch_notification(cinfo, info->desc->max_msg_size, - xfer); + xfer, msg_handle); scmi_notify(cinfo->handle, xfer->hdr.protocol_id, xfer->hdr.id, xfer->rx.buf, xfer->rx.len, ts); @@ -305,8 +306,8 @@ static void scmi_handle_notification(struct scmi_chan_info *cinfo, u32 msg_hdr) info->desc->ops->clear_channel(cinfo); } -static void scmi_handle_response(struct scmi_chan_info *cinfo, - u16 xfer_id, u8 msg_type) +static void scmi_handle_response(struct scmi_chan_info *cinfo, u16 xfer_id, + u8 msg_type, void *msg_handle) { struct scmi_xfer *xfer; struct device *dev = cinfo->dev; @@ -339,7 +340,7 @@ static void scmi_handle_response(struct scmi_chan_info *cinfo, scmi_dump_header_dbg(dev, &xfer->hdr); - info->desc->ops->fetch_response(cinfo, xfer); + info->desc->ops->fetch_response(cinfo, xfer, msg_handle); trace_scmi_rx_done(xfer->transfer_id, xfer->hdr.id, xfer->hdr.protocol_id, xfer->hdr.seq, @@ -365,18 +366,19 @@ static void scmi_handle_response(struct scmi_chan_info *cinfo, * NOTE: This function will be invoked in IRQ context, hence should be * as optimal as possible. */ -void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr) +void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr, + void *msg_handle) { u16 xfer_id = MSG_XTRACT_TOKEN(msg_hdr); u8 msg_type = MSG_XTRACT_TYPE(msg_hdr); switch (msg_type) { case MSG_TYPE_NOTIFICATION: - scmi_handle_notification(cinfo, msg_hdr); + scmi_handle_notification(cinfo, msg_hdr, msg_handle); break; case MSG_TYPE_COMMAND: case MSG_TYPE_DELAYED_RESP: - scmi_handle_response(cinfo, xfer_id, msg_type); + scmi_handle_response(cinfo, xfer_id, msg_type, msg_handle); break; default: WARN_ONCE(1, "received unknown msg_type:%d\n", msg_type); @@ -490,7 +492,7 @@ static int do_xfer(const struct scmi_protocol_handle *ph, spin_until_cond(scmi_xfer_done_no_timeout(cinfo, xfer, stop)); if (ktime_before(ktime_get(), stop)) - info->desc->ops->fetch_response(cinfo, xfer); + info->desc->ops->fetch_response(cinfo, xfer, NULL); else ret = -ETIMEDOUT; } else { diff --git a/drivers/firmware/arm_scmi/mailbox.c b/drivers/firmware/arm_scmi/mailbox.c index 4626404be541..584d7dcde2eb 100644 --- a/drivers/firmware/arm_scmi/mailbox.c +++ b/drivers/firmware/arm_scmi/mailbox.c @@ -43,7 +43,7 @@ static void rx_callback(struct mbox_client *cl, void *m) { struct scmi_mailbox *smbox = client_to_scmi_mailbox(cl); - scmi_rx_callback(smbox->cinfo, shmem_read_header(smbox->shmem)); + scmi_rx_callback(smbox->cinfo, shmem_read_header(smbox->shmem), NULL); } static bool mailbox_chan_available(struct device *dev, int idx) @@ -151,7 +151,7 @@ static void mailbox_mark_txdone(struct scmi_chan_info *cinfo, int ret) } static void mailbox_fetch_response(struct scmi_chan_info *cinfo, - struct scmi_xfer *xfer) + struct scmi_xfer *xfer, void *msg_handle) { struct scmi_mailbox *smbox = cinfo->transport_info; @@ -159,7 +159,8 @@ static void mailbox_fetch_response(struct scmi_chan_info *cinfo, } static void mailbox_fetch_notification(struct scmi_chan_info *cinfo, - size_t max_len, struct scmi_xfer *xfer) + size_t max_len, struct scmi_xfer *xfer, + void *msg_handle) { struct scmi_mailbox *smbox = cinfo->transport_info; diff --git a/drivers/firmware/arm_scmi/smc.c b/drivers/firmware/arm_scmi/smc.c index fcbe2677f84b..507107d1a4ad 100644 --- a/drivers/firmware/arm_scmi/smc.c +++ b/drivers/firmware/arm_scmi/smc.c @@ -151,7 +151,8 @@ static int smc_send_message(struct scmi_chan_info *cinfo, if (scmi_info->irq) wait_for_completion(&scmi_info->tx_complete); - scmi_rx_callback(scmi_info->cinfo, shmem_read_header(scmi_info->shmem)); + scmi_rx_callback(scmi_info->cinfo, shmem_read_header(scmi_info->shmem), + NULL); mutex_unlock(&scmi_info->shmem_lock); @@ -162,7 +163,7 @@ static int smc_send_message(struct scmi_chan_info *cinfo, } static void smc_fetch_response(struct scmi_chan_info *cinfo, - struct scmi_xfer *xfer) + struct scmi_xfer *xfer, void *msg_handle) { struct scmi_smc *scmi_info = cinfo->transport_info; From patchwork Tue May 11 00:20:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 12250367 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FCBFC433B4 for ; Tue, 11 May 2021 09:59:52 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 B524161621 for ; Tue, 11 May 2021 09:59:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B524161621 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=3h4PUO4xruvJIp7e7NNb5HaniVm0f8UM8R1dYzHaWp4=; b=ArMIIog6iyO8dQ0ANudzmeXY2 CPPY2PHWcqzX+7JowE8NCj4j6ukHfVI0mHcOvDi/2J9wckE3ikwnbnaif9Hq7Ako4/jvpcopByGj8 8U4Q0TjgvG9s9u7Z3bM/ci/4sLXnLddiTf1mxNHY2Qr5W9iHNoQ9XIjlBSq+LdrF78Hvsd8X1yg0K 50dNI0ZA4nmsU7KnqcFkErm7GtIDKpy+mzoK9qmat1sMvQ50DGZPrYr1WRX/vKeaUnlr6soYQ/U6+ s8qnLIgv99nebLguUzAl4i66UiBlTyRoSsV1D4aiWPuNnNEJ5tGi1BOMuuOzaAY5a7TaJ/0Z7Ceuw cYK8k6I9A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgP9r-00GnUm-R8; Tue, 11 May 2021 09:58:31 +0000 Received: from [2607:7c80:54:e::133] (helo=bombadil.infradead.org) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGoD-00G0n7-Vc for linux-arm-kernel@desiato.infradead.org; Tue, 11 May 2021 01:03:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=qDRth01lvccacQ4leScF8MqXeu+HXFiuV4vdo43NTWA=; b=iYbxqecEBbLAVUwrkvDKRXhSla NUgOwDLgfZ0g7zjEFV8FiPOakw8DA2tqEYDVZNO9+BU5Lj5mBWWIymlUCHz+YWwZaknk1TvbAwqFG 2LhDzNWqQQjrkGDcwauqHD9nuxh4BgJhXfxlZWj4G7Pzc/8vJjZE9x/jTTlBLxxYDd6WIa4EcGLqW XrZ0YvVuTfPxGM8/GSWysmyUE/+enz7DJOuJ0iENV+h8P7EThTsABKRwpjF+4iHx/4ryfQbRFX9PQ 52s+ELYqv5chVhu8ivdPvZNM8Ak6/WttTv+RQVYyvqnRcFVgTd61/PePZ7eh8+yM95hw7ipeeVfuI DDu+F7Xw==; Received: from mx1.opensynergy.com ([217.66.60.4]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGGQ-009DPs-Hx for linux-arm-kernel@lists.infradead.org; Tue, 11 May 2021 00:28:45 +0000 Received: from SR-MAILGATE-02.opensynergy.com (localhost.localdomain [127.0.0.1]) by mx1.opensynergy.com (Proxmox) with ESMTP id B9B33A1A33; Tue, 11 May 2021 02:22:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=opensynergy.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=srmailgate02; bh=qDRth01lvcca cQ4leScF8MqXeu+HXFiuV4vdo43NTWA=; b=l3D6+Lg0/yxa6+4wfSVlzgOUMBM9 Uje/YGgCyD2sbYNUoQDHiiONNgRYhTvEjPbww51bPTUtCaB2BWoua+kMDYe4OYXl 53v6nOvJME8MkmDRT6WVFTaB5iQ7EJOawBGWlt1TyMqCZO1kswGgHfTuQFB7gJLX 2SujQGhBfQ8ydb7sMw3TL5MqvwkjCHh/gNxJdMRa59FzXC3IhIxEscOzr0sktI6X zKsbGLqad8WkmcwGJc1Ic2TGHDs3sZpdoN6/3FmTMAjSu6PF2SeZ2yl/Q3d/z2qW FGwdu8263qq+Yjr/Kh/B1hm0jMIhP9XNEf6K6DEhiATlyogF+Gi3rJxvdw== From: Peter Hilber To: , CC: Peter Hilber , Rob Herring , , , , , , , , , Vasyl Vavrychuk , Andriy Tryshnivskyy , Cristian Marussi Subject: [RFC PATCH v3 08/12] firmware: arm_scmi: Add optional drop_message() transport op Date: Tue, 11 May 2021 02:20:36 +0200 Message-ID: <20210511002040.802226-9-peter.hilber@opensynergy.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210511002040.802226-1-peter.hilber@opensynergy.com> References: <20210511002040.802226-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-02.open-synergy.com (10.26.10.22) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172842_791985_4D49BACB X-CRM114-Status: GOOD ( 10.78 ) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172842_791985_4D49BACB X-CRM114-Status: UNSURE ( 8.59 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The virtio transport will need to know when the core has finished using a message. Add a transport op that indicates this to scmi_rx_callback(). Do not address the polling case for now. Signed-off-by: Peter Hilber --- drivers/firmware/arm_scmi/common.h | 2 ++ drivers/firmware/arm_scmi/driver.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 5ab2ea0f7db2..51ee08bdcb0c 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -298,6 +298,7 @@ struct scmi_chan_info { * @fetch_notification: Callback to fetch notification * @clear_channel: Callback to clear a channel * @poll_done: Callback to poll transfer status + * @drop_message: Optional callback when finished using msg_handle */ struct scmi_transport_ops { int (*link_supplier)(struct device *dev); @@ -315,6 +316,7 @@ struct scmi_transport_ops { struct scmi_xfer *xfer, void *msg_handle); void (*clear_channel)(struct scmi_chan_info *cinfo); bool (*poll_done)(struct scmi_chan_info *cinfo, struct scmi_xfer *xfer); + void (*drop_message)(struct scmi_chan_info *cinfo, void *msg_handle); }; int scmi_protocol_device_request(const struct scmi_device_id *id_table); diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index cc27978b4bea..e04e7c8e6928 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -371,6 +371,7 @@ void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr, { u16 xfer_id = MSG_XTRACT_TOKEN(msg_hdr); u8 msg_type = MSG_XTRACT_TYPE(msg_hdr); + struct scmi_info *info = handle_to_scmi_info(cinfo->handle); switch (msg_type) { case MSG_TYPE_NOTIFICATION: @@ -384,6 +385,9 @@ void scmi_rx_callback(struct scmi_chan_info *cinfo, u32 msg_hdr, WARN_ONCE(1, "received unknown msg_type:%d\n", msg_type); break; } + + if (info->desc->ops->drop_message) + info->desc->ops->drop_message(cinfo, msg_handle); } /** From patchwork Tue May 11 00:20:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 12250355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DE10C433ED for ; Tue, 11 May 2021 09:55:34 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 7A0C961932 for ; Tue, 11 May 2021 09:55:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7A0C961932 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=D6CC7/pl2h6Ey0KP3yI9VTzWTdnbAFX3htqCbpyCiqQ=; b=Axm413hcFS+OpI5rHA+prer3i cWL2GFTLn9JO93webq1sRq4NXMu4rdwxcPS+apqvxu2dNIvrsFrwUCyyGXc6OiDOEELxUQINnVKjF kY/J5PTHyirUwyXeL+F8C30zqszP4ZLcNvXXx2prHK/D+2Y3JnCiPxk+wcy7E2tyUQV4iGRGJrArB Djlxn85lWXBTJQR5v2BiM05d4Zsbgo0BLs11n+yM/Aj4bgFcARNxrFK2Df2B4MTqEH6M6zENokE5o 9tHPKcKIIUky2g5RL9dsOISJANQcKMCFL3gJa6zXIzhRy3OOST0EBK2w97AFjWpdPB+66oGxVod3W lAwRmxY4A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgP5t-00GmF6-2Y; Tue, 11 May 2021 09:54:25 +0000 Received: from [198.137.202.133] (helo=bombadil.infradead.org) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGQC-00FzUP-2N for linux-arm-kernel@desiato.infradead.org; Tue, 11 May 2021 00:38:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=P6aDOohx/CnLNSOtZzTr/KKqECyrpqq0nGc8kYRUUw8=; b=4pXJPtxNmLKmRWyXnQCKpMfjS5 ixxwc0UOJPVly97VN85SCZns7k2ZoSU0mTlJgL6O061zy5ZOVcQclGy/xzAX2L/1GjZYEIM2k0ZXW QCLhLdfrtq94ysQppf/artuit2kByLFd2a0lfPuMUMJRGQqhaVDke0z+zcYfVGiewAH1KAsbxqKct WvrTu+8bt0rVRyj3zLlUj0wbw51R4nCCZfT43rjX9HFTfBlRgAQ2/bQ6jdU+r7u86nPvBmZMKv3sp /td2nu9HS3oD+JZXLb6htoGnHwgS6B+jv94ELUHvtb9vkeDQy4+tnquyS4BkOiuoWd3WExodwUyWA POfiTwMQ==; Received: from mx1.opensynergy.com ([217.66.60.4]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGQ2-009Dn6-TT for linux-arm-kernel@lists.infradead.org; Tue, 11 May 2021 00:38:40 +0000 Received: from SR-MAILGATE-02.opensynergy.com (localhost.localdomain [127.0.0.1]) by mx1.opensynergy.com (Proxmox) with ESMTP id C2CE4A1A34; Tue, 11 May 2021 02:22:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=opensynergy.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=srmailgate02; bh=P6aDOohx/CnL NSOtZzTr/KKqECyrpqq0nGc8kYRUUw8=; b=lfOULUUkRdEbM33ODp84rarqB3eL oRp6r512RnPzAuj6sib4ZfsuUKhBSbNM4O9gevs1DpvGU6G1ZmpbjchQRlYTdSjl UJtVwKI9VQgGKGQecHOO2fQ/1xgc4X6iAT2iCDTgppVYbATBFkiJDdaiJXf7enbd kXTPMkLqm82/ZJqxi7yx+nMu11n7tEc26mltk9gQqnUDkfhU8S5Q21i0SOu6poek DJ7ewQhsH9Q5WEmPmbtkkSvd35Z3nvAdkHbetfj90mLhO0bT1w7iolmmePpirYuc iqkBKchUsC6UM5jQzuvNZFRuaQkxPQLOwT3ikbXIqJUB3JlJFPmhlWgw2A== From: Peter Hilber To: , CC: Peter Hilber , Rob Herring , , , , , , , , , Vasyl Vavrychuk , Andriy Tryshnivskyy , Cristian Marussi Subject: [RFC PATCH v3 09/12] firmware: arm_scmi: Add message passing abstractions for transports Date: Tue, 11 May 2021 02:20:37 +0200 Message-ID: <20210511002040.802226-10-peter.hilber@opensynergy.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210511002040.802226-1-peter.hilber@opensynergy.com> References: <20210511002040.802226-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-02.open-synergy.com (10.26.10.22) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_173839_139805_B817972B X-CRM114-Status: GOOD ( 16.94 ) /bin/ln: failed to access 'reaver_cache/texts/20210510_173839_139805_B817972B': No such file or directory X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_173839_139805_B817972B X-CRM114-Status: GOOD ( 14.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add abstractions for future transports using message passing, such as virtio. Derive the abstractions from the shared memory abstractions. Abstract the transport SDU through the opaque struct scmi_msg_payld. Also enable the transport to determine all other required information about the transport SDU. Signed-off-by: Peter Hilber --- drivers/firmware/Kconfig | 8 +- drivers/firmware/arm_scmi/Makefile | 1 + drivers/firmware/arm_scmi/common.h | 15 ++++ drivers/firmware/arm_scmi/msg.c | 113 +++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/arm_scmi/msg.c diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index 80ff49dadf35..e8377b12e4d0 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 || ARM_SCMI_HAVE_MSG help ARM System Control and Management Interface (SCMI) protocol is a set of operating system-independent software interfaces that are @@ -33,6 +33,12 @@ config ARM_SCMI_HAVE_SHMEM This declares whether a shared memory based transport for SCMI is available. +config ARM_SCMI_HAVE_MSG + bool + help + This declares whether a message passing 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 5a2d4c32e0ae..f6b4acb8abdb 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_ARM_SCMI_HAVE_MSG) += msg.o scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o system.o voltage.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 51ee08bdcb0c..4cb6571c7aaf 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -369,6 +369,21 @@ void shmem_clear_channel(struct scmi_shared_mem __iomem *shmem); bool shmem_poll_done(struct scmi_shared_mem __iomem *shmem, struct scmi_xfer *xfer); +/* declarations for message passing transports */ +struct scmi_msg_payld; + +/** Maximum overhead of message w.r.t. struct scmi_desc.max_msg_size */ +#define SCMI_MSG_MAX_PROT_OVERHEAD (2 * sizeof(__le32)) + +size_t msg_response_size(struct scmi_xfer *xfer); +size_t msg_command_size(struct scmi_xfer *xfer); +void msg_tx_prepare(struct scmi_msg_payld *msg, struct scmi_xfer *xfer); +u32 msg_read_header(struct scmi_msg_payld *msg); +void msg_fetch_response(struct scmi_msg_payld *msg, size_t len, + struct scmi_xfer *xfer); +void msg_fetch_notification(struct scmi_msg_payld *msg, size_t len, + size_t max_len, struct scmi_xfer *xfer); + void scmi_notification_instance_data_set(const struct scmi_handle *handle, void *priv); void *scmi_notification_instance_data_get(const struct scmi_handle *handle); diff --git a/drivers/firmware/arm_scmi/msg.c b/drivers/firmware/arm_scmi/msg.c new file mode 100644 index 000000000000..8a2d3303d281 --- /dev/null +++ b/drivers/firmware/arm_scmi/msg.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * For transports using message passing. + * + * Derived from shm.c. + * + * Copyright (C) 2019 ARM Ltd. + * Copyright (C) 2020 OpenSynergy GmbH + */ + +#include +#include +#include + +#include "common.h" + +/* + * struct scmi_msg_payld - Transport SDU layout + * + * The SCMI specification requires all parameters, message headers, return + * arguments or any protocol data to be expressed in little endian format only. + */ +struct scmi_msg_payld { + __le32 msg_header; + __le32 msg_payload[]; +}; + +/** + * msg_command_size() - Actual size of transport SDU for command. + * + * @xfer: message which core has prepared for sending + * + * Return: transport SDU size. + */ +size_t msg_command_size(struct scmi_xfer *xfer) +{ + return sizeof(struct scmi_msg_payld) + xfer->tx.len; +} + +/** + * msg_response_size() - Maximum size of transport SDU for response. + * + * @xfer: message which core has prepared for sending + * + * Return: transport SDU size. + */ +size_t msg_response_size(struct scmi_xfer *xfer) +{ + return sizeof(struct scmi_msg_payld) + sizeof(__le32) + xfer->rx.len; +} + +/** + * msg_tx_prepare() - Set up transport SDU for command. + * + * @msg: transport SDU for command + * @xfer: message which is being sent + */ +void msg_tx_prepare(struct scmi_msg_payld *msg, struct scmi_xfer *xfer) +{ + msg->msg_header = cpu_to_le32(pack_scmi_header(&xfer->hdr)); + if (xfer->tx.buf) + memcpy(msg->msg_payload, xfer->tx.buf, xfer->tx.len); +} + +/** + * msg_read_header() - Read SCMI header from transport SDU. + * + * @msg: transport SDU + * + * Return: SCMI header + */ +u32 msg_read_header(struct scmi_msg_payld *msg) +{ + return le32_to_cpu(msg->msg_header); +} + +/** + * msg_fetch_response() - Fetch response SCMI payload from transport SDU. + * + * @msg: transport SDU with response + * @len: transport SDU size + * @xfer: message being responded to + */ +void msg_fetch_response(struct scmi_msg_payld *msg, size_t len, + struct scmi_xfer *xfer) +{ + size_t prefix_len = sizeof(*msg) + sizeof(msg->msg_payload[0]); + + xfer->hdr.status = le32_to_cpu(msg->msg_payload[0]); + xfer->rx.len = min_t(size_t, xfer->rx.len, + len >= prefix_len ? len - prefix_len : 0); + + /* Take a copy to the rx buffer.. */ + memcpy(xfer->rx.buf, &msg->msg_payload[1], xfer->rx.len); +} + +/** + * msg_fetch_notification() - Fetch notification payload from transport SDU. + * + * @msg: transport SDU with notification + * @len: transport SDU size + * @max_len: maximum SCMI payload size to fetch + * @xfer: notification message + */ +void msg_fetch_notification(struct scmi_msg_payld *msg, size_t len, + size_t max_len, struct scmi_xfer *xfer) +{ + xfer->rx.len = min_t(size_t, max_len, + len >= sizeof(*msg) ? len - sizeof(*msg) : 0); + + /* Take a copy to the rx buffer.. */ + memcpy(xfer->rx.buf, msg->msg_payload, xfer->rx.len); +} From patchwork Tue May 11 00:20:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 12250377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BDD9C433ED for ; Tue, 11 May 2021 10:01:03 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 9643861621 for ; Tue, 11 May 2021 10:01:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9643861621 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=eMqJf3GvnESqi9uIL/O0//yE+v6pzjU96eZ3xNFrBKU=; b=KdUCSyJhJFZgpEo8TH0C1S0Ae 15L5s50yPJByBCh54Rdlm7ee30XjczznZbsAAaKuUjH3iuifD5VQxD5Im2kALW81E7DkJuaHBcZzA VWOZ3s8vwGbSIslx45Ouu3qshNFS71gpmS0cJPyKeUX5wOCHjR+D/D2yfTLPubw5exOCK23/BY7Mq T7LCQ3n1hq3288/bq0b9gWv12KF/Ns182e5K9srCvEc4/b/EK9khsjdKox5ODZHrOCqpGPtqrfVey eaxb0reGQhXQkcXslzHXwNXqK1aoBwJK4aQqkLR1NPrMUmSZ5QrMhEYXsNA2DL2JhwPvKe2dS/T3O TIVvD+CKw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgPB4-00Gnky-RO; Tue, 11 May 2021 09:59:47 +0000 Received: from [2607:7c80:54:e::133] (helo=bombadil.infradead.org) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGoX-00G0pG-W1 for linux-arm-kernel@desiato.infradead.org; Tue, 11 May 2021 01:04:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=cmoyI+jbzFuHzPs836GwRHzqAHaRxQ0315002Fo94F8=; b=yV/mdAep8oKQPWgZwjbqEBDzAE vpQ0hVoVHSQmfwCG55QueqS2eF/S7Jlqm3zwMzvIm0OEMWlhkZMrIOJ4XGnDniZciObKkBsqkWsrv uwlBnwQBTIjLv4bVJ9hxCaqk1xEmT47pct0HY5LvC1YT0H/tRYsGT9k4otXqEn7gZrL3iDopyew/X dH8n0XnlqDZn1FFUqFytCN3g0lQ4cvKewLna3MwJFYo0jHoXQrOlUbGpWz4SVzvtdIghkafIHFnoD 9WKCiGM/DejagTrM1wPZm8fX2gCuwPTzL/n8Fb3ZgFeJQ2R9by6HJK/ZNnXsQGHgm6w/Ajy8hwJ9P QH/LJ2Rg==; Received: from mx1.opensynergy.com ([217.66.60.4]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGGQ-009DPv-IP for linux-arm-kernel@lists.infradead.org; Tue, 11 May 2021 00:28:45 +0000 Received: from SR-MAILGATE-02.opensynergy.com (localhost.localdomain [127.0.0.1]) by mx1.opensynergy.com (Proxmox) with ESMTP id A8397A1A35; Tue, 11 May 2021 02:22:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=opensynergy.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=srmailgate02; bh=cmoyI+jbzFuH zPs836GwRHzqAHaRxQ0315002Fo94F8=; b=oaeVrtyElQDSd7Y5fDQV9QkAHjE5 RxDo5U3vQ0FHhgk3TBIDiR6iJ9FJAYAlOlRp9zOtISbitCeOkqi6SjF49mIrABcd L99Fj6YBx19pHUGR+dQoicUwo+ADIWRs+mz1aTVtx27sB0BCVV1tGY2ENzp36hIN P7WTwWuHSvMVIdRBHR19sTV2CNq2YNzrtJ1LoI9PjBQ2nBLI45tVRnSR2IvC/70Q 5quP1qI0fmHiILFHkWuEImcWLpU90Cw/wGXti61OrrdDJxE9QioTFbvr82Hyfhg4 WFtn6o+P0YUIY9J1PrPOgKZ21VXtIxwRzJq9agh8KAS4o4fiBmnnqpfhhw== From: Peter Hilber To: , , , CC: Igor Skalkin , Peter Hilber , Rob Herring , , , , , , , , Vasyl Vavrychuk , Andriy Tryshnivskyy , Cristian Marussi Subject: [RFC PATCH v3 10/12] dt-bindings: arm: Add virtio transport for SCMI Date: Tue, 11 May 2021 02:20:38 +0200 Message-ID: <20210511002040.802226-11-peter.hilber@opensynergy.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210511002040.802226-1-peter.hilber@opensynergy.com> References: <20210511002040.802226-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-02.open-synergy.com (10.26.10.22) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172842_834222_DF7789ED X-CRM114-Status: GOOD ( 12.14 ) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172842_834222_DF7789ED X-CRM114-Status: UNSURE ( 9.91 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.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 Signed-off-by: Igor Skalkin [ Peter: Adapted patch for submission to upstream. ] Co-developed-by: Peter Hilber Signed-off-by: Peter Hilber --- .../devicetree/bindings/arm/arm,scmi.txt | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/arm/arm,scmi.txt b/Documentation/devicetree/bindings/arm/arm,scmi.txt index 667d58e0a659..5d209ba666f6 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,15 @@ 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". + +The virtio transport only supports a single device. + +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 @@ -50,7 +62,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 ------------------------------------------------------------ @@ -129,7 +142,8 @@ Required sub-node properties: [5] Documentation/devicetree/bindings/reset/reset.txt [6] Documentation/devicetree/bindings/regulator/regulator.yaml -Example: +Example (mailbox transport): +---------------------------- sram@50000000 { compatible = "mmio-sram"; @@ -237,3 +251,20 @@ thermal-zones { ... }; }; + +Example (virtio transport): +--------------------------- + +virtio_mmio@4b001000 { + compatible = "virtio,mmio"; + ... +}; + +firmware { + ... + scmi { + compatible = "arm,scmi-virtio"; + ... + +The rest is similar to the mailbox transport example, when omitting the +mailbox/shmem-specific properties. From patchwork Tue May 11 00:20:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 12250365 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-22.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DA44C433B4 for ; Tue, 11 May 2021 09:59:46 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 8E1B861621 for ; Tue, 11 May 2021 09:59:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E1B861621 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=B2/jLcMywnLHzPCwuSFIq5nsKoBgq8g+HbGHnb5W3Cs=; b=Vnys/EIUjrmiOY7+KFqAXS4ju JQ3EgyI0KqywXqIhDBA85r8JnHI00mHZ4S+mww07ZQrQtTR/0w3BsdlkdLPPKCGx56u1eu9ioe0GG nznshgrJrs/E4scsES0ICB5+7zNHWlH0jjeNz5TReyNXAKzUZwjTlIH8bm4tKQsxm0ijgISzflxIF cgCMVa0+U75tFotMNc4M8chLTS2h6PpAj8hHHjvb5DFHtGHEiJg1Q/8hW9DZCySCs7Xe9AcCkYGaD y2rI9RTrPK3Kf19eBOPG8MV8ioCWzepQT6n6fR6khK1I9ktrJZaRf8mBssHAHV8MsBxPC/E9YFn8N VGw55Ktpg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgP9h-00GnTP-1t; Tue, 11 May 2021 09:58:21 +0000 Received: from [2607:7c80:54:e::133] (helo=bombadil.infradead.org) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGo7-00G0me-Su for linux-arm-kernel@desiato.infradead.org; Tue, 11 May 2021 01:03:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=J1JljJaWo9pg/nozizxGasLsEbgHLupBpRtoFNc0PB8=; b=XKoqdplRfcSBbyP+xArGptMtC6 +Ek1dlyJRTldwme8Bhaqmi4NGealjdpA2rZQiM3eReTauJeXXAzfEl2xytz2Vh6Cft7ToVyNCkCBK gd4MAZS6zz+Xeq0WMDzer6bFAx9+XLf1cxeYloiVeIeJeouwZcIeY9UUTTJFsTuDkS2Eu7+97P8wz qo7usGjJLYtsAK2TNoytTRSLKkXaCaYilimsiJLYxeYI/QpnJ6uThJf4zQcg75dD72HsPvyD5+YCE Q5H+PwXXuh7HmG8GRvBIrmn00H7NoFy4Lbqn4+8uv8pfrcXk9kAxOXkVxdZoFibm8vuXbv1Sb9YQF gHtI0thA==; Received: from mx1.opensynergy.com ([217.66.60.4]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGGQ-009DPq-HO for linux-arm-kernel@lists.infradead.org; Tue, 11 May 2021 00:28:48 +0000 Received: from SR-MAILGATE-02.opensynergy.com (localhost.localdomain [127.0.0.1]) by mx1.opensynergy.com (Proxmox) with ESMTP id C7CEBA1A38; Tue, 11 May 2021 02:22:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=opensynergy.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=srmailgate02; bh=J1JljJaWo9pg /nozizxGasLsEbgHLupBpRtoFNc0PB8=; b=DjM2RbqAfuCwQd0HA6E1c/ixXcwH dqwhkVJURbCvYtur7qiUJX15KphwjHAd8mEoQlZL1iEAnSBDzH1rukmCxo9zwj77 xoaPRR9vZUbpNu/ixJtNlIql/J0qzj35NKvBLggZe1StKDgsw9ahPnvgsoLBwD8m 5MSwOOT5oXtBRryoiIqUd5ijOwe4FXsueaTmHI+ExJNW1NIWR6/k/0e0Tr2z2VT/ gXGOVaMmTOpYpS0If9MjRYkyu1aCCn7VE9GCKqwwUAfh3DXwH5/2yO5YSH01Pwrs S7X6jyhzln+RM8raoxQhA5gRIfqxb8H77DTmhGwLvhjh2iK3SbME9wExSQ== From: Peter Hilber To: , , , CC: Igor Skalkin , Peter Hilber , Rob Herring , , , , , , , , Vasyl Vavrychuk , Andriy Tryshnivskyy , Cristian Marussi , "Michael S. Tsirkin" , Jason Wang , Viresh Kumar Subject: [RFC PATCH v3 11/12] firmware: arm_scmi: Add virtio transport Date: Tue, 11 May 2021 02:20:39 +0200 Message-ID: <20210511002040.802226-12-peter.hilber@opensynergy.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210511002040.802226-1-peter.hilber@opensynergy.com> References: <20210511002040.802226-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-02.open-synergy.com (10.26.10.22) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172842_980221_971437CB X-CRM114-Status: GOOD ( 33.29 ) /bin/ln: failed to access 'reaver_cache/texts/20210510_172842_980221_971437CB': No such file or directory X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172842_980221_971437CB X-CRM114-Status: GOOD ( 28.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.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 [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, this implements the virtio transport as paraphrased: Only support a single arm-scmi device (which is consistent with the SCMI spec). scmi-virtio init is called from arm-scmi module init. During the arm-scmi probing, link to the first probed scmi-virtio device. Defer arm-scmi probing if no scmi-virtio device is bound yet. 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: - Polling is not supported. - The timeout for delayed responses has not been adjusted. [1] https://github.com/oasis-tcs/virtio-spec/blob/master/virtio-scmi.tex [2] https://www.oasis-open.org/committees/ballot.php?id=3496 Signed-off-by: Igor Skalkin [ Peter: Adapted patch for submission to upstream. ] Co-developed-by: Peter Hilber Signed-off-by: Peter Hilber --- MAINTAINERS | 1 + drivers/firmware/Kconfig | 12 + drivers/firmware/arm_scmi/Makefile | 1 + drivers/firmware/arm_scmi/common.h | 3 + drivers/firmware/arm_scmi/driver.c | 3 + drivers/firmware/arm_scmi/virtio.c | 523 +++++++++++++++++++++++++++++ include/uapi/linux/virtio_ids.h | 1 + include/uapi/linux/virtio_scmi.h | 25 ++ 8 files changed, 569 insertions(+) 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 bd7aff0c120f..449c336872f3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17705,6 +17705,7 @@ F: drivers/regulator/scmi-regulator.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 e8377b12e4d0..7e9eafdd9b63 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -39,6 +39,18 @@ config ARM_SCMI_HAVE_MSG This declares whether a message passing based transport for SCMI is available. +# This config option includes the dependencies of ARM_SCMI_PROTOCOL so that +# this config doesn't show up when SCMI wouldn't be available. +config VIRTIO_SCMI + bool "Virtio transport for SCMI" + select ARM_SCMI_HAVE_MSG + depends on VIRTIO && (ARM || ARM64 || COMPILE_TEST) + 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 f6b4acb8abdb..db1787606fb2 100644 --- a/drivers/firmware/arm_scmi/Makefile +++ b/drivers/firmware/arm_scmi/Makefile @@ -5,6 +5,7 @@ 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_ARM_SCMI_HAVE_MSG) += msg.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 voltage.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 4cb6571c7aaf..bada06cfd33d 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -349,6 +349,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 int scmi_set_transport_info(struct device *dev, void *transport_info); void *scmi_get_transport_info(struct device *dev); diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index e04e7c8e6928..a31187385470 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -1637,6 +1637,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 */ }, }; diff --git a/drivers/firmware/arm_scmi/virtio.c b/drivers/firmware/arm_scmi/virtio.c new file mode 100644 index 000000000000..20972adf6dc7 --- /dev/null +++ b/drivers/firmware/arm_scmi/virtio.c @@ -0,0 +1,523 @@ +// 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. + * + * 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 spinlocks. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" + +#define VIRTIO_SCMI_MAX_MSG_SIZE 128 /* Value may be increased. */ +#define VIRTIO_SCMI_MAX_PDU_SIZE \ + (VIRTIO_SCMI_MAX_MSG_SIZE + SCMI_MSG_MAX_PROT_OVERHEAD) +#define DESCRIPTORS_PER_TX_MSG 2 + +/** + * struct scmi_vio_channel - Transport channel information + * + * @lock: Protects access to all members except ready. + * @ready_lock: Protects access to ready. If required, it must be taken before + * lock. + * @vqueue: Associated virtqueue + * @cinfo: SCMI Tx or Rx channel + * @free_list: List of unused scmi_vio_msg, maintained for Tx channels only + * @is_rx: Whether channel is an Rx channel + * @ready: Whether transport user is ready to hear about channel + */ +struct scmi_vio_channel { + spinlock_t lock; + spinlock_t ready_lock; + struct virtqueue *vqueue; + struct scmi_chan_info *cinfo; + struct list_head free_list; + u8 is_rx; + u8 ready; +}; + +/** + * struct scmi_vio_msg - Transport PDU information + * + * @request: SDU used for commands + * @input: SDU used for (delayed) responses and notifications + * @list: List which scmi_vio_msg may be part of + * @rx_len: Input SDU size in bytes, once input has been received + */ +struct scmi_vio_msg { + struct scmi_msg_payld *request; + struct scmi_msg_payld *input; + struct list_head list; + unsigned int rx_len; +}; + +static bool scmi_vio_have_vq_rx(struct virtio_device *vdev) +{ + return virtio_has_feature(vdev, VIRTIO_SCMI_F_P2A_CHANNELS); +} + +static int scmi_vio_feed_vq_rx(struct scmi_vio_channel *vioch, + struct scmi_vio_msg *msg) +{ + struct scatterlist sg_in; + int rc; + unsigned long flags; + + sg_init_one(&sg_in, msg->input, VIRTIO_SCMI_MAX_PDU_SIZE); + + spin_lock_irqsave(&vioch->lock, flags); + + rc = virtqueue_add_inbuf(vioch->vqueue, &sg_in, 1, msg, GFP_ATOMIC); + if (rc) + dev_err_once(vioch->cinfo->dev, + "%s() failed to add to virtqueue (%d)\n", __func__, + rc); + else + virtqueue_kick(vioch->vqueue); + + spin_unlock_irqrestore(&vioch->lock, flags); + + return rc; +} + +static void scmi_vio_complete_cb(struct virtqueue *vqueue) +{ + unsigned long ready_flags; + unsigned long flags; + unsigned int length; + struct scmi_vio_channel *vioch; + struct scmi_vio_msg *msg; + bool cb_enabled = true; + + if (WARN_ON_ONCE(!vqueue->vdev->priv)) + return; + vioch = &((struct scmi_vio_channel *)vqueue->vdev->priv)[vqueue->index]; + + for (;;) { + spin_lock_irqsave(&vioch->ready_lock, ready_flags); + + if (!vioch->ready) { + if (!cb_enabled) + (void)virtqueue_enable_cb(vqueue); + goto unlock_ready_out; + } + + spin_lock_irqsave(&vioch->lock, flags); + if (cb_enabled) { + virtqueue_disable_cb(vqueue); + cb_enabled = false; + } + msg = virtqueue_get_buf(vqueue, &length); + if (!msg) { + if (virtqueue_enable_cb(vqueue)) + goto unlock_out; + else + cb_enabled = true; + } + spin_unlock_irqrestore(&vioch->lock, flags); + + if (msg) { + msg->rx_len = length; + + /* + * Hold the ready_lock during the callback to avoid + * races when the arm-scmi driver is unbinding while + * the virtio device is not quiesced yet. + */ + scmi_rx_callback(vioch->cinfo, + msg_read_header(msg->input), msg); + } + spin_unlock_irqrestore(&vioch->ready_lock, ready_flags); + } + +unlock_out: + spin_unlock_irqrestore(&vioch->lock, flags); +unlock_ready_out: + spin_unlock_irqrestore(&vioch->ready_lock, ready_flags); +} + +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 unsigned int virtio_get_max_msg(bool tx, + struct scmi_chan_info *base_cinfo) +{ + struct scmi_vio_channel *vioch = base_cinfo->transport_info; + unsigned int ret; + + ret = virtqueue_get_vring_size(vioch->vqueue); + + /* Tx messages need multiple descriptors. */ + if (tx) + ret /= DESCRIPTORS_PER_TX_MSG; + + if (ret > MSG_TOKEN_MAX) { + dev_info_once( + base_cinfo->dev, + "Only %ld messages can be pending simultaneously, while the %s virtqueue could hold %d\n", + MSG_TOKEN_MAX, tx ? "tx" : "rx", ret); + ret = MSG_TOKEN_MAX; + } + + return ret; +} + +static int scmi_vio_match_any_dev(struct device *dev, const void *data) +{ + return 1; +} + +static struct virtio_driver virtio_scmi_driver; /* Forward declaration */ + +static int virtio_link_supplier(struct device *dev) +{ + struct device *vdev = driver_find_device( + &virtio_scmi_driver.driver, NULL, NULL, scmi_vio_match_any_dev); + + if (!vdev) { + dev_notice_once( + dev, + "Deferring probe after not finding a bound scmi-virtio device\n"); + return -EPROBE_DEFER; + } + + /* Add device link for remove order and sysfs link. */ + if (!device_link_add(dev, vdev, DL_FLAG_AUTOREMOVE_CONSUMER)) { + put_device(vdev); + dev_err(dev, "Adding link to supplier virtio device failed\n"); + return -ECANCELED; + } + + put_device(vdev); + return scmi_set_transport_info(dev, dev_to_virtio(vdev)); +} + +static bool virtio_chan_available(struct device *dev, int idx) +{ + struct virtio_device *vdev; + + /* scmi-virtio doesn't support per-protocol channels */ + if (is_scmi_protocol_device(dev)) + return false; + + vdev = scmi_get_transport_info(dev); + if (!vdev) + return false; + + switch (idx) { + case VIRTIO_SCMI_VQ_TX: + return true; + case VIRTIO_SCMI_VQ_RX: + return scmi_vio_have_vq_rx(vdev); + default: + return false; + } +} + +static int virtio_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, + bool tx) +{ + unsigned long flags; + struct virtio_device *vdev; + struct scmi_vio_channel *vioch; + int index = tx ? VIRTIO_SCMI_VQ_TX : VIRTIO_SCMI_VQ_RX; + int max_msg; + int i; + + if (!virtio_chan_available(dev, index)) + return -ENODEV; + + vdev = scmi_get_transport_info(dev); + vioch = &((struct scmi_vio_channel *)vdev->priv)[index]; + + spin_lock_irqsave(&vioch->lock, flags); + cinfo->transport_info = vioch; + vioch->cinfo = cinfo; + spin_unlock_irqrestore(&vioch->lock, flags); + + max_msg = virtio_get_max_msg(tx, cinfo); + + for (i = 0; i < max_msg; i++) { + struct scmi_vio_msg *msg; + + msg = devm_kzalloc(cinfo->dev, sizeof(*msg), GFP_KERNEL); + if (!msg) + return -ENOMEM; + + if (tx) { + msg->request = devm_kzalloc(cinfo->dev, + VIRTIO_SCMI_MAX_PDU_SIZE, + GFP_KERNEL); + if (!msg->request) + return -ENOMEM; + } + + msg->input = devm_kzalloc(cinfo->dev, VIRTIO_SCMI_MAX_PDU_SIZE, + GFP_KERNEL); + if (!msg->input) + return -ENOMEM; + + if (tx) { + spin_lock_irqsave(&vioch->lock, flags); + list_add_tail(&msg->list, &vioch->free_list); + spin_unlock_irqrestore(&vioch->lock, flags); + } else { + scmi_vio_feed_vq_rx(vioch, msg); + } + } + + spin_lock_irqsave(&vioch->ready_lock, flags); + vioch->ready = true; + spin_unlock_irqrestore(&vioch->ready_lock, flags); + + return 0; +} + +static int virtio_chan_free(int id, void *p, void *data) +{ + unsigned long flags; + struct scmi_chan_info *cinfo = p; + struct scmi_vio_channel *vioch = cinfo->transport_info; + + spin_lock_irqsave(&vioch->ready_lock, flags); + vioch->ready = false; + spin_unlock_irqrestore(&vioch->ready_lock, flags); + + scmi_free_channel(cinfo, data, id); + return 0; +} + +static int virtio_send_message(struct scmi_chan_info *cinfo, + struct scmi_xfer *xfer) +{ + struct scmi_vio_channel *vioch = cinfo->transport_info; + struct scatterlist sg_out; + struct scatterlist sg_in; + struct scatterlist *sgs[DESCRIPTORS_PER_TX_MSG] = { &sg_out, &sg_in }; + unsigned long flags; + int rc; + struct scmi_vio_msg *msg; + + /* + * TODO: For now, we don't support polling. But it should not be + * difficult to add support. + */ + if (xfer->hdr.poll_completion) + return -EINVAL; + + spin_lock_irqsave(&vioch->lock, flags); + + if (list_empty(&vioch->free_list)) { + spin_unlock_irqrestore(&vioch->lock, flags); + return -EBUSY; + } + + msg = list_first_entry(&vioch->free_list, typeof(*msg), list); + list_del(&msg->list); + + msg_tx_prepare(msg->request, xfer); + + sg_init_one(&sg_out, msg->request, msg_command_size(xfer)); + sg_init_one(&sg_in, msg->input, msg_response_size(xfer)); + + rc = virtqueue_add_sgs(vioch->vqueue, sgs, 1, 1, msg, GFP_ATOMIC); + if (rc) { + list_add(&msg->list, &vioch->free_list); + dev_err_once(vioch->cinfo->dev, + "%s() failed to add to virtqueue (%d)\n", __func__, + rc); + } else { + virtqueue_kick(vioch->vqueue); + } + + spin_unlock_irqrestore(&vioch->lock, flags); + + return rc; +} + +static void virtio_fetch_response(struct scmi_chan_info *cinfo, + struct scmi_xfer *xfer, void *msg_handle) +{ + struct scmi_vio_msg *msg = msg_handle; + struct scmi_vio_channel *vioch = cinfo->transport_info; + + if (!msg) { + dev_dbg_once(&vioch->vqueue->vdev->dev, + "Ignoring %s() call with NULL msg_handle\n", + __func__); + return; + } + + msg_fetch_response(msg->input, msg->rx_len, xfer); +} + +static void virtio_fetch_notification(struct scmi_chan_info *cinfo, + size_t max_len, struct scmi_xfer *xfer, + void *msg_handle) +{ + struct scmi_vio_msg *msg = msg_handle; + struct scmi_vio_channel *vioch = cinfo->transport_info; + + if (!msg) { + dev_dbg_once(&vioch->vqueue->vdev->dev, + "Ignoring %s() call with NULL msg_handle\n", + __func__); + return; + } + + msg_fetch_notification(msg->input, msg->rx_len, max_len, xfer); +} + +static void dummy_clear_channel(struct scmi_chan_info *cinfo) +{ +} + +static bool dummy_poll_done(struct scmi_chan_info *cinfo, + struct scmi_xfer *xfer) +{ + return false; +} + +static void virtio_drop_message(struct scmi_chan_info *cinfo, void *msg_handle) +{ + unsigned long flags; + struct scmi_vio_channel *vioch = cinfo->transport_info; + struct scmi_vio_msg *msg = msg_handle; + + if (!msg) { + dev_dbg_once(&vioch->vqueue->vdev->dev, + "Ignoring %s() call with NULL msg_handle\n", + __func__); + return; + } + + if (vioch->is_rx) { + scmi_vio_feed_vq_rx(vioch, msg); + } else { + spin_lock_irqsave(&vioch->lock, flags); + list_add(&msg->list, &vioch->free_list); + spin_unlock_irqrestore(&vioch->lock, flags); + } +} + +static const struct scmi_transport_ops scmi_virtio_ops = { + .link_supplier = virtio_link_supplier, + .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 = virtio_fetch_notification, + .clear_channel = dummy_clear_channel, + .poll_done = dummy_poll_done, + .drop_message = virtio_drop_message, +}; + +static int scmi_vio_probe(struct virtio_device *vdev) +{ + struct device *dev = &vdev->dev; + struct scmi_vio_channel *channels; + bool have_vq_rx; + int vq_cnt; + int i; + int ret; + struct virtqueue *vqs[VIRTIO_SCMI_VQ_MAX_CNT]; + + have_vq_rx = scmi_vio_have_vq_rx(vdev); + vq_cnt = have_vq_rx ? VIRTIO_SCMI_VQ_MAX_CNT : 1; + + channels = devm_kcalloc(dev, vq_cnt, sizeof(*channels), GFP_KERNEL); + if (!channels) + return -ENOMEM; + + if (have_vq_rx) + channels[VIRTIO_SCMI_VQ_RX].is_rx = true; + + ret = virtio_find_vqs(vdev, vq_cnt, vqs, scmi_vio_complete_callbacks, + scmi_vio_vqueue_names, NULL); + if (ret) { + dev_err(dev, "Failed to get %d virtqueue(s)\n", vq_cnt); + return ret; + } + dev_info(dev, "Found %d virtqueue(s)\n", vq_cnt); + + for (i = 0; i < vq_cnt; i++) { + spin_lock_init(&channels[i].lock); + spin_lock_init(&channels[i].ready_lock); + INIT_LIST_HEAD(&channels[i].free_list); + channels[i].vqueue = vqs[i]; + } + + vdev->priv = channels; + + return 0; +} + +static void scmi_vio_remove(struct virtio_device *vdev) +{ + vdev->config->reset(vdev); + vdev->config->del_vqs(vdev); +} + +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, + .remove = scmi_vio_remove, +}; + +static int __init virtio_scmi_init(void) +{ + return register_virtio_driver(&virtio_scmi_driver); +} + +static void __exit virtio_scmi_exit(void) +{ + unregister_virtio_driver(&virtio_scmi_driver); +} + +const struct scmi_desc scmi_virtio_desc = { + .init = virtio_scmi_init, + .exit = virtio_scmi_exit, + .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, +}; diff --git a/include/uapi/linux/virtio_ids.h b/include/uapi/linux/virtio_ids.h index f0c35ce8628c..c146fe30e589 100644 --- a/include/uapi/linux/virtio_ids.h +++ b/include/uapi/linux/virtio_ids.h @@ -56,5 +56,6 @@ #define VIRTIO_ID_PMEM 27 /* virtio pmem */ #define VIRTIO_ID_BT 28 /* virtio bluetooth */ #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..732b01504c35 --- /dev/null +++ b/include/uapi/linux/virtio_scmi.h @@ -0,0 +1,25 @@ +/* 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 + +#endif /* _UAPI_LINUX_VIRTIO_SCMI_H */ From patchwork Tue May 11 00:20:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hilber X-Patchwork-Id: 12250373 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20A2FC433B4 for ; Tue, 11 May 2021 10:00:35 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 582B561363 for ; Tue, 11 May 2021 10:00:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 582B561363 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=opensynergy.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=BzIMOvSo3APPhgD+LJ+EF6U2FtC8MglgLqdql6tdbak=; b=i7M0fBMRuopVpEVlAED9cm0iZ vRayK+rtBtKnQHVe258aJtzAby9lSFLw3k3YvGblRWGSRzyRiCg4FEgzRJ+Qc53cz2jX+hztwezTi fGg4tdo8flM1htBkDhtC06dk8n8IHNOHd1pq62/PIMwWNHD3wqJa/MRbWMORPdMLsnEBONOcauPnx +SM6eJ4AMjElUCR/oKjrYpOgnDzECPjmzpA14BBqltBM9nf3R3nwHfnvmqj7mPGTC539/IEgigHSs i9SSiD12okIVh5d9/CIi92XHK6FL+bRZHHXfVWxLXlR/IxMTw8Cl4CgMn5/0l8f2rKr0oJXOPtwoi N0UyYS/iA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgPAX-00GncG-AX; Tue, 11 May 2021 09:59:13 +0000 Received: from [2607:7c80:54:e::133] (helo=bombadil.infradead.org) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGoP-00G0oS-KY for linux-arm-kernel@desiato.infradead.org; Tue, 11 May 2021 01:03:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=7Jt8AOTWNRzk362lP6M1btJnyfFLS/lTS2EN5YBOQTs=; b=MhRCzpo5aRqMNqrfVsIySR3FN1 IsgKadrFWNRfPIVtxfVRkTs5i5l8U1kq9stSfPyJTJKQHJfCS1A+QaTnBmL8gYxbbX2zE7BEQ8UAK nA27WFLVvBjVyXbdPfxfx60f7DL5EHqEq+CRpp3u5dT5jHFN+puIjlCUR2jDUIeh52/f1xxYxlkVP pM9T0KgWqKJDGAK5sZcucsQdbbyyfYtl586CmqB2cDJmAcrXGD7Dxt0Id5u61igfwZm7za4jk9605 3gNQtavQfMv7NCcGyoR9y9HNKlO69uGEkF9WRX0HGzUEqg3Fh1OmHRbFERX5W734lKWD9vA5K93S6 yfxZJ+9Q==; Received: from mx1.opensynergy.com ([217.66.60.4]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgGGQ-009DPr-Hl for linux-arm-kernel@lists.infradead.org; Tue, 11 May 2021 00:28:46 +0000 Received: from SR-MAILGATE-02.opensynergy.com (localhost.localdomain [127.0.0.1]) by mx1.opensynergy.com (Proxmox) with ESMTP id 2F58BA1A3A; Tue, 11 May 2021 02:22:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=opensynergy.com; h=cc:cc:content-transfer-encoding:content-type:content-type :date:from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=srmailgate02; bh=7Jt8AOTWNRzk 362lP6M1btJnyfFLS/lTS2EN5YBOQTs=; b=lSFeSHdYmpAVbER7oNQMYUeE14KA rsQLvVY9E7eq5p3r6/duMDKZyuZI1TIa0hTrACrswWOTV54CVqtqpYKr6045I8IA Apxj1P+GUIvdsZFJuW21Tp7kj1X14n38kMRRGCWPCNU1NiUfMGzCJ5MW2JpjHWiJ S7sZFj09Qs1Qpkc6tD6a2AZq3TD8SQ1UMD/Kkvoi9HEHhDMqASuvXrLWzzFD1mgv fXaqC1ttp0Xw+M43g6pmvuYzVkIaihkhY2AawTeY/DrqKtOssisCBYY8KRkFSWZW vA8Nkq3nenR3kfGPb1uR552aGoGcqjGCqP14Nwu3M7L3tq5gv1iWMbipKA== From: Peter Hilber To: , CC: Peter Hilber , Rob Herring , , , , , , , , , Vasyl Vavrychuk , Andriy Tryshnivskyy , Cristian Marussi Subject: [RFC PATCH v3 12/12] firmware: arm_scmi: Handle races between core and transport Date: Tue, 11 May 2021 02:20:40 +0200 Message-ID: <20210511002040.802226-13-peter.hilber@opensynergy.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210511002040.802226-1-peter.hilber@opensynergy.com> References: <20210511002040.802226-1-peter.hilber@opensynergy.com> MIME-Version: 1.0 X-ClientProxiedBy: SR-MAIL-01.open-synergy.com (10.26.10.21) To SR-MAIL-02.open-synergy.com (10.26.10.22) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172842_995971_B17C316E X-CRM114-Status: GOOD ( 32.69 ) /bin/ln: failed to access 'reaver_cache/texts/20210510_172842_995971_B17C316E': No such file or directory X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_172842_995971_B17C316E X-CRM114-Status: GOOD ( 28.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Introduce additional state and locks to handle race conditions in the core-transport interaction. These race conditions become more relevant with the new virtio transport, which may time out more often, especially in the case of misconfigurations. The races involve the transport calling scmi_rx_callback() and a second function. The following race conditions are addressed: - concurrent not delayed and delayed response (or inverted order) - belated response to timed out message corrupts new message - mixing up of responses if the same command is repeated after timeout The implementation is not yet complete, as when the wait_after_timeout transport option is set and a not delayed response returns an error after timeout, the core would wait endlessly for any corresponding delayed response (marked with TODO in the code). Signed-off-by: Peter Hilber --- drivers/firmware/arm_scmi/common.h | 34 ++++++- drivers/firmware/arm_scmi/driver.c | 153 ++++++++++++++++++++++------- drivers/firmware/arm_scmi/virtio.c | 1 + 3 files changed, 150 insertions(+), 38 deletions(-) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index bada06cfd33d..bdb9796ea1a3 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -123,6 +123,29 @@ struct scmi_msg { size_t len; }; +/** + * struct scmi_xfer_state - Message flow state + * + * @done: command message transmit completion event + * @async_done: pointer to delayed response message received event completion + * @wait_response: Waiting for the (not delayed) response. + * @wait_delayed: Waiting for the delayed response. + * @wait_after_timeout: Message timed out for core, but transport will + * eventually submit the response. Cannot reuse the + * scmi_xfer as long as this is set. + * @put_wait: wait_after_timeout was set when we were trying to put the + * message, so we wait for the transport to present the response + * before actually releasing the message. + */ +struct scmi_xfer_state { + struct completion done; + struct completion *async_done; + u8 wait_response; + u8 wait_delayed; + u8 wait_after_timeout; + u8 put_wait; +}; + /** * struct scmi_xfer - Structure representing a message flow * @@ -132,16 +155,16 @@ struct scmi_msg { * @rx: Receive message, the buffer should be pre-allocated to store * message. If request-ACK protocol is used, we can reuse the same * 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 + * @state: Message flow state + * @lock: Protects access to message while transport may access it */ struct scmi_xfer { int transfer_id; struct scmi_msg_hdr hdr; struct scmi_msg tx; struct scmi_msg rx; - struct completion done; - struct completion *async_done; + struct scmi_xfer_state state; + spinlock_t lock; }; struct scmi_xfer_ops; @@ -333,6 +356,8 @@ struct scmi_device *scmi_child_dev_find(struct device *parent, * 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. + * @wait_after_timeout: On response timeout, don't reuse scmi_xfer until + * transport eventually returns response. */ struct scmi_desc { int (*init)(void); @@ -341,6 +366,7 @@ struct scmi_desc { int max_rx_timeout_ms; int max_msg; int max_msg_size; + u8 wait_after_timeout; }; #ifdef CONFIG_MAILBOX diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index a31187385470..51f6799cc8ab 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -72,13 +72,13 @@ struct scmi_requested_dev { * @xfer_alloc_table: Bitmap table for allocated messages. * Index of this bitmap table is also used for message * sequence identifier. - * @xfer_lock: Protection for message allocation + * @alloc_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; + spinlock_t alloc_lock; int max_msg; }; @@ -230,20 +230,20 @@ static struct scmi_xfer *scmi_xfer_get(const struct scmi_handle *handle, unsigned long flags, bit_pos; /* Keep the locked section as small as possible */ - spin_lock_irqsave(&minfo->xfer_lock, flags); + spin_lock_irqsave(&minfo->alloc_lock, flags); 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); + spin_unlock_irqrestore(&minfo->alloc_lock, flags); return ERR_PTR(-ENOMEM); } set_bit(bit_pos, minfo->xfer_alloc_table); - spin_unlock_irqrestore(&minfo->xfer_lock, flags); + spin_unlock_irqrestore(&minfo->alloc_lock, flags); xfer_id = bit_pos; xfer = &minfo->xfer_block[xfer_id]; xfer->hdr.seq = xfer_id; - reinit_completion(&xfer->done); + reinit_completion(&xfer->state.done); xfer->transfer_id = atomic_inc_return(&transfer_last_id); return xfer; @@ -255,21 +255,27 @@ static struct scmi_xfer *scmi_xfer_get(const struct scmi_handle *handle, * @minfo: Pointer to Tx/Rx Message management info based on channel type * @xfer: message that was reserved by scmi_xfer_get * - * This holds a spinlock to maintain integrity of internal data structures. + * For the Tx channel, call this with the xfer lock held. + * This uses the xfer table spinlock to maintain integrity of internal data + * structures. */ static void __scmi_xfer_put(struct scmi_xfers_info *minfo, struct scmi_xfer *xfer) { unsigned long flags; - /* - * Keep the locked section as small as possible - * NOTE: we might escape with smp_mb and no lock here.. - * but just be conservative and symmetric. - */ - spin_lock_irqsave(&minfo->xfer_lock, flags); - clear_bit(xfer->hdr.seq, minfo->xfer_alloc_table); - spin_unlock_irqrestore(&minfo->xfer_lock, flags); + if (xfer->state.wait_after_timeout) { + xfer->state.put_wait = true; + } else { + /* + * Keep the locked section as small as possible + * NOTE: we might escape with smp_mb and no lock here.. + * but just be conservative and symmetric. + */ + spin_lock_irqsave(&minfo->alloc_lock, flags); + clear_bit(xfer->hdr.seq, minfo->xfer_alloc_table); + spin_unlock_irqrestore(&minfo->alloc_lock, flags); + } } static void scmi_handle_notification(struct scmi_chan_info *cinfo, u32 msg_hdr, @@ -313,6 +319,7 @@ static void scmi_handle_response(struct scmi_chan_info *cinfo, u16 xfer_id, struct device *dev = cinfo->dev; struct scmi_info *info = handle_to_scmi_info(cinfo->handle); struct scmi_xfers_info *minfo = &info->tx_minfo; + unsigned long flags; /* Are we even expecting this? */ if (!test_bit(xfer_id, minfo->xfer_alloc_table)) { @@ -322,25 +329,65 @@ static void scmi_handle_response(struct scmi_chan_info *cinfo, u16 xfer_id, } xfer = &minfo->xfer_block[xfer_id]; + + spin_lock_irqsave(&xfer->lock, flags); + /* * Even if a response was indeed expected on this slot at this point, * a buggy platform could wrongly reply feeding us an unexpected - * delayed response we're not prepared to handle: bail-out safely + * response we're not prepared to handle: bail-out safely * blaming firmware. */ - if (unlikely(msg_type == MSG_TYPE_DELAYED_RESP && !xfer->async_done)) { - dev_err(dev, - "Delayed Response for %d not expected! Buggy F/W ?\n", - xfer_id); - info->desc->ops->clear_channel(cinfo); - /* It was unexpected, so nobody will clear the xfer if not us */ - __scmi_xfer_put(minfo, xfer); - return; + if (msg_type == MSG_TYPE_COMMAND) { + if (xfer->state.wait_response) { + xfer->state.wait_response = false; + /* + * TODO: In case of an error response, we should ensure + * that we cancel waiting for the delayed response. + */ + } else { + spin_unlock_irqrestore(&xfer->lock, flags); + dev_err(dev, + "Response for %d not expected! Buggy F/W?\n", + xfer_id); + return; + } + } else /* msg_type == MSG_TYPE_DELAYED_RESP */ { + if (xfer->state.wait_delayed) { + xfer->state.wait_delayed = false; + } else { + dev_err(dev, + "Delayed Response for %d not expected! Buggy F/W?\n", + xfer_id); + info->desc->ops->clear_channel(cinfo); + + /* It was unexpected, so nobody will clear the xfer if not us */ + __scmi_xfer_put(minfo, xfer); + spin_unlock_irqrestore(&xfer->lock, flags); + return; + } } scmi_dump_header_dbg(dev, &xfer->hdr); - info->desc->ops->fetch_response(cinfo, xfer, msg_handle); + if (xfer->state.wait_after_timeout && !xfer->state.wait_response && + !xfer->state.wait_delayed) { + xfer->state.wait_after_timeout = false; + if (xfer->state.put_wait) { + __scmi_xfer_put(minfo, xfer); + spin_unlock_irqrestore(&xfer->lock, flags); + return; + } + } + + if (xfer->state.async_done && msg_type == MSG_TYPE_COMMAND && + !xfer->state.wait_delayed) { + dev_dbg(dev, + "Ignoring not delayed response for %d, which was received after delayed response\n", + xfer_id); + } else { + info->desc->ops->fetch_response(cinfo, xfer, msg_handle); + } trace_scmi_rx_done(xfer->transfer_id, xfer->hdr.id, xfer->hdr.protocol_id, xfer->hdr.seq, @@ -348,10 +395,12 @@ static void scmi_handle_response(struct scmi_chan_info *cinfo, u16 xfer_id, if (msg_type == MSG_TYPE_DELAYED_RESP) { info->desc->ops->clear_channel(cinfo); - complete(xfer->async_done); + complete(xfer->state.async_done); } else { - complete(&xfer->done); + complete(&xfer->state.done); } + + spin_unlock_irqrestore(&xfer->lock, flags); } /** @@ -434,8 +483,11 @@ static void xfer_put(const struct scmi_protocol_handle *ph, { const struct scmi_protocol_instance *pi = ph_to_pi(ph); struct scmi_info *info = handle_to_scmi_info(pi->handle); + unsigned long flags; + spin_lock_irqsave(&xfer->lock, flags); __scmi_xfer_put(&info->tx_minfo, xfer); + spin_unlock_irqrestore(&xfer->lock, flags); } #define SCMI_MAX_POLL_TO_NS (100 * NSEC_PER_USEC) @@ -468,6 +520,7 @@ static int do_xfer(const struct scmi_protocol_handle *ph, struct scmi_info *info = handle_to_scmi_info(pi->handle); struct device *dev = info->dev; struct scmi_chan_info *cinfo; + unsigned long flags; /* * Re-instate protocol id here from protocol handle so that cannot be @@ -480,6 +533,16 @@ static int do_xfer(const struct scmi_protocol_handle *ph, if (unlikely(!cinfo)) return -EINVAL; + spin_lock_irqsave(&xfer->lock, flags); + if (xfer->state.wait_after_timeout) { + spin_unlock_irqrestore(&xfer->lock, flags); + return -EBUSY; + } + + xfer->state.wait_response = true; + xfer->state.wait_delayed = !!xfer->state.async_done; + spin_unlock_irqrestore(&xfer->lock, flags); + trace_scmi_xfer_begin(xfer->transfer_id, xfer->hdr.id, xfer->hdr.protocol_id, xfer->hdr.seq, xfer->hdr.poll_completion); @@ -502,7 +565,14 @@ static int do_xfer(const struct scmi_protocol_handle *ph, } else { /* And we wait for the response. */ timeout = msecs_to_jiffies(info->desc->max_rx_timeout_ms); - if (!wait_for_completion_timeout(&xfer->done, timeout)) { + if (!wait_for_completion_timeout(&xfer->state.done, timeout)) { + if (info->desc->wait_after_timeout) { + spin_lock_irqsave(&xfer->lock, flags); + if (xfer->state.wait_response || + xfer->state.wait_delayed) + xfer->state.wait_after_timeout = true; + spin_unlock_irqrestore(&xfer->lock, flags); + } dev_err(dev, "timed out in resp(caller: %pS)\n", (void *)_RET_IP_); ret = -ETIMEDOUT; @@ -547,17 +617,27 @@ static int do_xfer_with_response(const struct scmi_protocol_handle *ph, { int ret, timeout = msecs_to_jiffies(SCMI_MAX_RESPONSE_TIMEOUT); const struct scmi_protocol_instance *pi = ph_to_pi(ph); + const struct scmi_info *info = handle_to_scmi_info(pi->handle); DECLARE_COMPLETION_ONSTACK(async_response); + unsigned long flags; xfer->hdr.protocol_id = pi->proto->id; - xfer->async_done = &async_response; + xfer->state.async_done = &async_response; ret = do_xfer(ph, xfer); - if (!ret && !wait_for_completion_timeout(xfer->async_done, timeout)) + if (!ret && + !wait_for_completion_timeout(xfer->state.async_done, timeout)) { + if (info->desc->wait_after_timeout) { + spin_lock_irqsave(&xfer->lock, flags); + if (xfer->state.wait_delayed) + xfer->state.wait_after_timeout = true; + spin_unlock_irqrestore(&xfer->lock, flags); + } ret = -ETIMEDOUT; + } - xfer->async_done = NULL; + xfer->state.async_done = NULL; return ret; } @@ -604,6 +684,10 @@ static int xfer_get_init(const struct scmi_protocol_handle *ph, xfer->hdr.id = msg_id; xfer->hdr.protocol_id = pi->proto->id; xfer->hdr.poll_completion = false; + xfer->state.wait_response = false; + xfer->state.wait_delayed = false; + xfer->state.wait_after_timeout = false; + xfer->state.put_wait = false; *p = xfer; @@ -1085,7 +1169,7 @@ static int __scmi_xfer_info_init(struct scmi_info *sinfo, if (!info->xfer_alloc_table) return -ENOMEM; - /* Pre-initialize the buffer pointer to pre-allocated buffers */ + /* Pre-initialize the buffer pointer to pre-allocated buffers etc. */ 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); @@ -1093,10 +1177,11 @@ static int __scmi_xfer_info_init(struct scmi_info *sinfo, return -ENOMEM; xfer->tx.buf = xfer->rx.buf; - init_completion(&xfer->done); + init_completion(&xfer->state.done); + spin_lock_init(&xfer->lock); } - spin_lock_init(&info->xfer_lock); + spin_lock_init(&info->alloc_lock); return 0; } diff --git a/drivers/firmware/arm_scmi/virtio.c b/drivers/firmware/arm_scmi/virtio.c index 20972adf6dc7..3db3c629778c 100644 --- a/drivers/firmware/arm_scmi/virtio.c +++ b/drivers/firmware/arm_scmi/virtio.c @@ -520,4 +520,5 @@ const struct scmi_desc scmi_virtio_desc = { .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, + .wait_after_timeout = true, };