From patchwork Mon Feb 12 18:45:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 128151 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp3485419ljc; Mon, 12 Feb 2018 10:46:12 -0800 (PST) X-Google-Smtp-Source: AH8x226+a/zAU0VLNRxjcrar5m5C6dDUr3c9nQ/ap1+rGAfek/sI86G/Qd2wn06sTg7jw320EVQz X-Received: by 10.101.67.71 with SMTP id k7mr9881462pgq.136.1518461172369; Mon, 12 Feb 2018 10:46:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518461172; cv=none; d=google.com; s=arc-20160816; b=qPLvx+Qw+bai3bEV2tr/8m1QAcVTj4UVqDCuPfqcssM/l8h7C1mu8lrKXtsFo1scew 6J9Ron17ejF5qV81TJwds+Fg69Qwi830ixhSDD1srBbKxR1pmyGaeqrOIuyfZDitiuSk 55mj1NMeuNmb4ud9787sTcDGC0VRwXPI9NLhT+AJaknOR1b73LJ32B4sCXNcbwY2YbMS aRYV3D5Oom0PePW3zDE71L5VgPnEOyVsjDDkmREAQ1xBeqY5jXugviYMnkBVY2KllaTx VvUmuuSWQGKRrYTL93xp57NTuq9BJWlAqskwI/OQICWFc+833EB4MWW1zbWq5VLS+1Mq Gy7Q== 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=CsrEWVgEUhhJgU40rXv8P5u1lcGWdHKSRDHyrDyeuMg=; b=QzuG0CkrqzqAp8zNJ6/71Bs6YqZkeQDVUpSXWcBYV4X8f+2U0Pkxpy8FwzGQzF3u12 S/z2kQk0xiEKNQOuhPFpwAyIuee35JDuju0I9Q/aroya6SAEtgar96OT/1QQ7iASRZUT YncQ3QxgoP/g0m8mIrMWxXoYkzJxDs/1GIwnWVP2nD2O7zauKJ/cu64l+ylrsWXhanis vVfiHSJGchluTYOUk4GfbohnR0fNfTELQpFgJSNPP1iLpLU9x5I9l0+i7WZEqcKzDuG1 xb2xhtrycYPRuzhRzNNUp49p+8+gWfOzBVv/x4tzUy6VXZBVPI8xOka3YWoNJ8FGpG49 El1A== 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 z100-v6si837258plh.129.2018.02.12.10.46.11; Mon, 12 Feb 2018 10:46:12 -0800 (PST) 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 S1753311AbeBLSqG (ORCPT + 26 others); Mon, 12 Feb 2018 13:46:06 -0500 Received: from foss.arm.com ([217.140.101.70]:47224 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754052AbeBLSqA (ORCPT ); Mon, 12 Feb 2018 13:46:00 -0500 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 1FA0B165D; Mon, 12 Feb 2018 10:46:00 -0800 (PST) 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 BDF433F24D; Mon, 12 Feb 2018 10:45:58 -0800 (PST) From: Sudeep Holla To: ALKML , LKML , DTML Cc: Sudeep Holla , Greg Kroah-Hartman , Arnd Bergmann , Alexey Klimov Subject: [PATCH v5 11/20] firmware: arm_scmi: add support for polling based SCMI transfers Date: Mon, 12 Feb 2018 18:45:15 +0000 Message-Id: <1518461124-17371-12-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518461124-17371-1-git-send-email-sudeep.holla@arm.com> References: <1518461124-17371-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 Cc: Greg Kroah-Hartman 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 939ef626bfdd..0108bb39d0f6 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 @@ -346,6 +348,21 @@ void scmi_one_xfer_put(const struct scmi_handle *handle, struct scmi_xfer *xfer) spin_unlock_irqrestore(&minfo->xfer_lock, flags); } +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 * @@ -372,14 +389,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