From patchwork Fri Feb 23 16:23:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 129437 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp789346lja; Fri, 23 Feb 2018 08:24:30 -0800 (PST) X-Google-Smtp-Source: AH8x226VJPexB85EfYYyVK7QU/L+GShWqFZCI3zj/UU4RURsNVY8wOIb/9kvqOsqDOvW6OqMXl8U X-Received: by 2002:a17:902:aa83:: with SMTP id d3-v6mr2208256plr.36.1519403070043; Fri, 23 Feb 2018 08:24:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519403070; cv=none; d=google.com; s=arc-20160816; b=Uo8Ux8FCEDUu9XPWz9YPkfuLldUJbEbxxALp0fmokOci8xOMo0SOSVe2YCmJlLFPyl 2V3hTCyBkIX4MUn0iXMJw/TW2Jd1GFjJt0fyajPWPVdpPtKfpfj+xn3wsO2Xa9xakRRf qPBPh0LxJD/Vl4OTiIDiVG5T+GaOnC339Dnrbya0/L5+Ey69hht8OJyVwZR1HmtLYWTP vg4vvTDqVysiFOYVkhJfBdTqjEcfsyyn3Jed1SHCxY/MyTEt9tJMwpPuZI+yKMMoul9e y0OHnguphwNtccOBIYyCO5utmAnglltVsw6G6RooSKGEFBF/gwZ9t0W3F8ODVygKy5rA zwTg== 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=kSf5TsnBVkUyX8P1X1Vz0sWsof1us3ocZzmJZtkSWac=; b=cYuXRzYRatKoJOfWGX2EhZzch8jBRXFiNZYxCyCzOvlfCPPMB99+QOIl/K3Tfu0qav WpC4RhCV6sZPkBHnlOsd9hb2QVzNB4EU0rHKcaUUGVUAAj5smXS+BD4uEp34knBTYyeO lOg/FR8WZ+6/4Vm/pMph/n74W/rHJTavunKfdjSIqUWwGvbmMNFVpap0Pj/XIPEOfEJA 8BvUESbbBnbU0rigIF2Yx14mArRVykXWHy3Fuuolw4uWvdA0JDwverv0MIuo3gfIgFk/ EvJnulxuU9vRvZ9WTliVjY5/uAMRRmwp8JKbJuT0MxYkf+ULcIpr3kMFaFkyFqykb3xO KY2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 g9-v6si1970983plp.423.2018.02.23.08.24.29; Fri, 23 Feb 2018 08:24:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-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 devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751920AbeBWQY2 (ORCPT + 6 others); Fri, 23 Feb 2018 11:24:28 -0500 Received: from foss.arm.com ([217.140.101.70]:57330 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751841AbeBWQY0 (ORCPT ); Fri, 23 Feb 2018 11:24:26 -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 D2DB51610; Fri, 23 Feb 2018 08:24:25 -0800 (PST) Received: from e107155-lin.cambridge.arm.com (unknown [10.1.210.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7D6F73F25C; Fri, 23 Feb 2018 08:24:24 -0800 (PST) From: Sudeep Holla To: ALKML , LKML , DTML Cc: Sudeep Holla , Alexey Klimov , Arnd Bergmann , Greg Kroah-Hartman Subject: [PATCH v6 11/20] firmware: arm_scmi: add support for polling based SCMI transfers Date: Fri, 23 Feb 2018 16:23:41 +0000 Message-Id: <1519403030-21189-12-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519403030-21189-1-git-send-email-sudeep.holla@arm.com> References: <1519403030-21189-1-git-send-email-sudeep.holla@arm.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@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 | 55 ++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 8 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 970c3a8c6e96..e6698629e15a 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -29,10 +29,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -346,6 +348,30 @@ 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_POLL_TO_NS (100 * NSEC_PER_USEC) + +static bool scmi_xfer_done_no_timeout(const struct scmi_info *info, + struct scmi_xfer *xfer, ktime_t stop) +{ + ktime_t __cur = ktime_get(); + + return scmi_xfer_poll_done(info, xfer) || ktime_after(__cur, stop); +} + /** * scmi_do_xfer() - Do one transfer * @@ -372,15 +398,28 @@ 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: %pS)\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 = ktime_add_ns(ktime_get(), SCMI_MAX_POLL_TO_NS); + + spin_until_cond(scmi_xfer_done_no_timeout(info, xfer, stop)); + + if (ktime_before(ktime_get(), 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: %pS)\n", + (void *)_RET_IP_); + ret = -ETIMEDOUT; + } } + + if (!ret && xfer->hdr.status) + ret = scmi_to_linux_errno(xfer->hdr.status); + /* * NOTE: we might prefer not to need the mailbox ticker to manage the * transfer queueing since the protocol layer queues things by itself.