Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3107980pxv; Mon, 12 Jul 2021 09:27:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAosX3FNNdc423r4tRlonmzcf734j0tpwnbAOzIIOSL4wu/7sM2YFdKdD7TJIAb7YrOoC9 X-Received: by 2002:a6b:b5c7:: with SMTP id e190mr40915341iof.31.1626107258805; Mon, 12 Jul 2021 09:27:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626107258; cv=none; d=google.com; s=arc-20160816; b=b2PIaX82DLmJtIh7747xAvVDqdg/tbrMNfP03vaY3EFGL1cmfIESFwTIqpYXxXtGUw wlQvpwRM7IuXifGE0QYJQNgWT1KhV0QPP4PzYLXJzDsbdVHp1roe8qyhTWkp1jcxQwXP KIGNYvgIAY03mnVuf0MbJime5WmlVPwaPYaa9y7QcLD0fha4JDWDesVRH5qfDZuw5RNP e/2/eAVh9mOyPnytaolSfSgzMvcwzwqkR730YuMHGk+MwXKPfwnncINPfK1YN3Va4C9O wF6604444QloVJCBNE4M2crBiTtGb8w0O6hOBLF/d3/tSmNrIvmabEUC1XEa82NpmW6d 3YiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=ZA4Ev6HVeDzA4sUfBzSxocrRClCTCLse2pqSYsc3ohc=; b=I2RNqcwL2IL2BRT5uzh4Pdr7wVFeV9TQQ2Kok5jdU21HuLbUTivLXrxdh7vClXwtDt kXSOV4TYY7p9d8+tBwYPt63TDXLkgSBVwRrPdg1rGfG0b2l8WHL5xbqIsgJFxgs7ioBc qiaG3PpfUVr5blGPUR4IFDd91mYlGKGlOZEJSFi7IGWOGTQ/JhGeupe/y+pOH2nXbVdn m2PDUYIqDu5upuMZLveFthcaE40O2IV7D4ZK5+6DOu95FZe3ijHwbV2K7jW90gXhoxcx Z0pPR2I6yTxSWp4Qw1poezSGdN7Rd/oQ9GK/plVCKRjU82NdsD98wAPNHxm6JVQJlQPD 5azg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a13si9528427ion.67.2021.07.12.09.27.26; Mon, 12 Jul 2021 09:27:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233856AbhGLQ3h (ORCPT + 99 others); Mon, 12 Jul 2021 12:29:37 -0400 Received: from foss.arm.com ([217.140.110.172]:57940 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232122AbhGLQ3h (ORCPT ); Mon, 12 Jul 2021 12:29:37 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7C3A831B; Mon, 12 Jul 2021 09:26:48 -0700 (PDT) Received: from e120937-lin.home (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C99CC3F774; Mon, 12 Jul 2021 09:26:46 -0700 (PDT) From: Cristian Marussi To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: sudeep.holla@arm.com, james.quinlan@broadcom.com, Jonathan.Cameron@Huawei.com, f.fainelli@gmail.com, etienne.carriere@linaro.org, vincent.guittot@linaro.org, souvik.chakravarty@arm.com, cristian.marussi@arm.com Subject: [PATCH v3 1/8] firmware: arm_scmi: Add configurable polling mode for transports Date: Mon, 12 Jul 2021 17:26:18 +0100 Message-Id: <20210712162626.34705-2-cristian.marussi@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210712162626.34705-1-cristian.marussi@arm.com> References: <20210712162626.34705-1-cristian.marussi@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org SCMI communications along TX channels can optionally be provided of a completion interrupt; when such interrupt is not available, command transactions should rely on polling, where the SCMI core takes care to repeatedly evaluates the transport-specific .poll_done() function to determine if a request was completed or timed out. Such mechanism is already present and working on a single transfer base: SCMI protocols can indeed enable hdr.poll_completion on specific commands ahead of each transfer and cause that transaction to be handled with polling. Introduce a couple of flags to be able to enforce such polling behaviour globally at will: - scmi_desc.force_polling: to statically switch the whole transport to polling mode. - scmi_chan_info.needs_polling: to switch a single channel dynamically to polling mode if at runtime is determined that no completion interrupt was available for such channel. Signed-off-by: Cristian Marussi --- drivers/firmware/arm_scmi/common.h | 10 ++++++++++ drivers/firmware/arm_scmi/driver.c | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 877236b99602..2b5fa351d89f 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -320,11 +320,18 @@ void scmi_protocol_release(const struct scmi_handle *handle, u8 protocol_id); * @dev: Reference to device in the SCMI hierarchy corresponding to this * channel * @handle: Pointer to SCMI entity handle + * @needs_polling: Flag to indicate that this channel has no completion + * interrupt mechanism, so it needs SCMI core to poll, using + * .poll_done(), to determine when a command has completed. + * This can be dynamically set by transports at run-time inside + * their provided .chan_setup() when they determine no + * completion interrupt is available. * @transport_info: Transport layer related information */ struct scmi_chan_info { struct device *dev; struct scmi_handle *handle; + bool needs_polling; void *transport_info; }; @@ -383,6 +390,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. + * @force_polling: Flag to force this whole transport to use SCMI core polling + * mechanism instead of completion interrupts even if available. */ struct scmi_desc { int (*init)(void); @@ -391,6 +400,7 @@ struct scmi_desc { int max_rx_timeout_ms; int max_msg; int max_msg_size; + bool force_polling; }; #ifdef CONFIG_ARM_SCMI_TRANSPORT_MAILBOX diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 650da2ef59bf..36cb7a12d72f 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -651,6 +651,15 @@ static void scmi_handle_response(struct scmi_chan_info *cinfo, scmi_xfer_state_update(xfer); + /* Discard unexpected messages when polling is active. */ + if (xfer->hdr.type != MSG_TYPE_DELAYED_RESP && + xfer->hdr.poll_completion) { + WARN_ON_ONCE(1); + dev_dbg(cinfo->dev, + "Completion IRQ received but using polling. Ignore.\n"); + return; + } + /* rx.len could be shrunk in the sync do_xfer, so reset to maxsz */ if (xfer->hdr.type == MSG_TYPE_DELAYED_RESP) xfer->rx.len = info->desc->max_msg_size; @@ -767,6 +776,9 @@ static int do_xfer(const struct scmi_protocol_handle *ph, if (unlikely(!cinfo)) return -EINVAL; + if (info->desc->force_polling || cinfo->needs_polling) + xfer->hdr.poll_completion = true; + trace_scmi_xfer_begin(xfer->transfer_id, xfer->hdr.id, xfer->hdr.protocol_id, xfer->hdr.seq, xfer->hdr.poll_completion); @@ -1490,6 +1502,11 @@ static int scmi_chan_setup(struct scmi_info *info, struct device *dev, if (ret) return ret; + if (tx && (cinfo->needs_polling || info->desc->force_polling)) + dev_info(dev, + "Enabled polling mode for TX channel - prot_id:%d\n", + prot_id); + idr_alloc: ret = idr_alloc(idr, cinfo, prot_id, prot_id + 1, GFP_KERNEL); if (ret != prot_id) { -- 2.17.1