From patchwork Fri Nov 3 14:47:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 117927 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp3403673edm; Fri, 3 Nov 2017 07:51:23 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QOBG//INaL6FLjtgD3dw6dXTwC8gJX1iz166rPHRngozwtWqeKkS0rfiJftgkyduG8FmDp X-Received: by 10.101.64.9 with SMTP id f9mr7549240pgp.114.1509720683184; Fri, 03 Nov 2017 07:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509720683; cv=none; d=google.com; s=arc-20160816; b=cf5CNuXt8D2RSmIEq36FvYCcTMKvm6K1vQunUutdBievIPMNylkDpjE70a9uaxMA2J pAw0dd7q8Sabk2UzWG1wiGtrICD2JmP8JuNET/xmVKS7qFbHTXfB15Uh12Lne7MH94/c yrG9GPvLtU0swzLgkiInixOKwmW4snRGhG1vvemSsFgU3r7aVW/a+zQuHLNdF+iIN6yN aurrEqVF5jIgRoHo5lAkgTyXD+RTWAtVGFxT56d6a8/+QIlRA/9RdD5lO1L1nz53BEXj 58kVzTQSxNWzLcKljp8huMd9yzVpTKvOX0tZf9oHds09PKSL2Tsld/dhyVqFQR80sueR TsjQ== 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=8pHL7Asy7Btif+4vz6+WyQccvaTJBNiOJwUmKaQBziM=; b=lfXdSVdgF9o7KiGFnp5o1tUzLuqvRkSFQSPh64Hpd2UTEBcJ4p5rMRJgCxuowzak4Z ebvkJB1tk/XLlgJQzcTY638PFEOnsvjJFcZISaF20pVqFKEohvT+VH1xO3wd2SQXtUQV tpXPFAeohOuY3DeOWIwRN+JJ6FlC97oUxGL56HxZWl18jcdCJAxyTRrFaBi4ihl9ikmD ykg+RCZ7Q2NQQzHCH7okXsHMwRrHRR/MhlaFREmTUUuSYy0lMdAyGbyFZIBXYzLRttTa XO2QJJHWy5pT3eAXAjp+HLfgO7IojGiJsBOCHkSy5RsGOTXweT9tEO8wu5mwKvwYoIRC BVhw== 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 k16si6393320pff.411.2017.11.03.07.51.22; Fri, 03 Nov 2017 07:51:23 -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 S933925AbdKCOvV (ORCPT + 26 others); Fri, 3 Nov 2017 10:51:21 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:44396 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755320AbdKCOtP (ORCPT ); Fri, 3 Nov 2017 10:49:15 -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 AA2C01529; Fri, 3 Nov 2017 07:49:14 -0700 (PDT) Received: from e107155-lin.cambridge.arm.com (e107155-lin.cambridge.arm.com [10.1.210.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BB4253F3DF; Fri, 3 Nov 2017 07:49:12 -0700 (PDT) From: Sudeep Holla To: ALKML , LKML , DTML Cc: Sudeep Holla , Roy Franz , Harb Abdulhamid , Nishanth Menon , Arnd Bergmann , Loc Ho , Ryan Harkin , Jassi Brar Subject: [PATCH v4 11/20] firmware: arm_scmi: add support for polling based SCMI transfers Date: Fri, 3 Nov 2017 14:47:48 +0000 Message-Id: <1509720477-18936-12-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509720477-18936-1-git-send-email-sudeep.holla@arm.com> References: <1509720477-18936-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 | 49 +++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 8 deletions(-) -- 2.7.4 diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 11c18ac9816f..0c9dda72f10c 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -26,9 +26,11 @@ */ #include +#include #include #include #include +#include #include #include #include @@ -363,6 +365,21 @@ 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); +} + +#define SCMI_MAX_POLLING_TIMEOUT_NS (100 * NSEC_PER_USEC) /** * scmi_do_xfer() - Do one transfer * @@ -389,14 +406,30 @@ 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) { + ktime_t stop, cur; + + stop = ktime_add_ns(ktime_get(), SCMI_MAX_POLLING_TIMEOUT_NS); + do { + udelay(5); + cur = ktime_get(); + } while (!scmi_xfer_poll_done(info, xfer) && + ktime_before(cur, stop)); + + if (ktime_before(cur, stop)) + 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