From patchwork Thu Sep 28 13:11:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 114439 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp730786qgf; Thu, 28 Sep 2017 06:17:14 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCanx2/efJk9oFz25hfl2Vi2czHuknamk4WyX9Awh/7lqZh8Cndi/merS2GNtu4qtXDmXlx X-Received: by 10.84.129.7 with SMTP id 7mr4067608plb.40.1506604634453; Thu, 28 Sep 2017 06:17:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506604634; cv=none; d=google.com; s=arc-20160816; b=kLglezW1nN7IzKeG7V8A6lsx1oSjsoUZll1xCCUG5psSoDCM2NHn3kZWDUIWaV5eGH QR3cBlV1Nii33csPV7VV6IhU/JmkppL7OF2xkqr+g4M13AlnVwf/vnwYvqOk32x9xXwZ F68I/oMd+eQdiM708kxOHsSDSEOWwFRBzzVWZPDSpviHEW2O5Re3OboOH8frOZHR7Cb/ 349wA8OyQFezuWf7biHsz1o2Ii6fT3RDpk+m99iNhnUd9k2QA38KKsWW16W7pIalDsFZ WcYo9/EAEFCHexAWlXtrwffSjCGu/cT/7PgfeQH6Gc1IP58ccoBVnUbD04I4lTtaP/RO 7Sjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=8k8iF9KxfWijeqBVif7EuyRbINu0wtsPqQsBo9DeXS0=; b=Ptx5xuCL9/CT0cw8uU2TqpW9kI1ENHJ5etinAUVuLM+brPntqs6NfqLBKUqlSk1xpF pcOymPlLkMbdySizyRxzj56eRdULNCy4teQoIZ6eB1pA4Ftgz+G1gSeEZ0uxeT771mgl utIE746UjhuQeUjrJFYvCWMOcjYvu/0wJOni9aqZSyKIMB5tl4CGaRgc7BN3gnTlS0kY pqug26QrYj/3OJtCjzAUBO34MU4XNW1FHGz6cRkFmh3JP6NBUBbQRD92gApqvmIR1fEG E9IfZ/5lX1LUrJ/I2prMpqjfY6cud+Nosslt6hw3xqUgaYX46Rr6iZUABW8nKmKMMD2g aZsA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x124si1373170pfx.227.2017.09.28.06.17.14; Thu, 28 Sep 2017 06:17:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753461AbdI1NRL (ORCPT + 26 others); Thu, 28 Sep 2017 09:17:11 -0400 Received: from foss.arm.com ([217.140.101.70]:57092 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752438AbdI1NOb (ORCPT ); Thu, 28 Sep 2017 09:14:31 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8F74A15BF; Thu, 28 Sep 2017 06:14:30 -0700 (PDT) Received: from e107155-lin.cambridge.arm.com (unknown [10.1.210.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7CAD03F483; Thu, 28 Sep 2017 06:14:28 -0700 (PDT) From: Sudeep Holla To: ALKML , LKML , DTML Cc: Sudeep Holla , Roy Franz , Harb Abdulhamid , Nishanth Menon , Arnd Bergmann , Loc Ho , Alexey Klimov , Ryan Harkin , Jassi Brar Subject: [PATCH v3 11/22] firmware: arm_scmi: add support for polling based SCMI transfers Date: Thu, 28 Sep 2017 14:11:35 +0100 Message-Id: <1506604306-20739-12-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506604306-20739-1-git-send-email-sudeep.holla@arm.com> References: <1506604306-20739-1-git-send-email-sudeep.holla@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It would be useful to have options to perform some SCMI transfers atomically by polling for the completion flag instead of interrupt driven. The SCMI specification has option to disable the interrupt and poll for the completion flag in the shared memory. This patch adds support for polling based SCMI transfers using that option. This might be used for uninterrupted/atomic DVFS operations from the scheduler context. Cc: Arnd Bergmann Signed-off-by: Sudeep Holla --- drivers/firmware/arm_scmi/driver.c | 41 ++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) -- 2.7.4 diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index a1abcf2049ca..e1abedf15cb0 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -26,6 +26,7 @@ */ #include +#include #include #include #include @@ -369,6 +370,20 @@ void scmi_one_xfer_put(const struct scmi_handle *handle, struct scmi_xfer *xfer) up(&minfo->sem_xfer_count); } +static bool +scmi_xfer_poll_done(const struct scmi_info *info, struct scmi_xfer *xfer) +{ + struct scmi_shared_mem *mem = info->tx_payload; + u16 xfer_id = MSG_XTRACT_TOKEN(le32_to_cpu(mem->msg_header)); + + if (xfer->hdr.seq != xfer_id) + return false; + + return le32_to_cpu(mem->channel_status) & + (SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR | + SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE); +} + /** * scmi_do_xfer() - Do one transfer * @@ -395,14 +410,24 @@ int scmi_do_xfer(const struct scmi_handle *handle, struct scmi_xfer *xfer) /* mbox_send_message returns non-negative value on success, so reset */ ret = 0; - /* And we wait for the response. */ - timeout = msecs_to_jiffies(info->desc->max_rx_timeout_ms); - if (!wait_for_completion_timeout(&xfer->done, timeout)) { - dev_err(dev, "mbox timed out in resp(caller: %pF)\n", - (void *)_RET_IP_); - ret = -ETIMEDOUT; - } else if (xfer->hdr.status) { - ret = scmi_to_linux_errno(xfer->hdr.status); + if (xfer->hdr.poll_completion) { + timeout = info->desc->max_rx_timeout_ms * 100; + while (!scmi_xfer_poll_done(info, xfer) && timeout--) + udelay(10); + if (timeout) + scmi_fetch_response(xfer, info->tx_payload); + else + ret = -ETIMEDOUT; + } 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)) { + dev_err(dev, "mbox timed out in resp(caller: %pF)\n", + (void *)_RET_IP_); + ret = -ETIMEDOUT; + } else if (xfer->hdr.status) { + ret = scmi_to_linux_errno(xfer->hdr.status); + } } /* * NOTE: we might prefer not to need the mailbox ticker to manage the