Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp31627pxu; Sat, 21 Nov 2020 21:44:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxxMLuKYJ83fmQjk0myhz7KuPjO1qV1YmBAIlzF9RQJeLq71T8Tijl9YoSDMaMmkte4Mhnl X-Received: by 2002:a50:d5c4:: with SMTP id g4mr18200707edj.334.1606023861981; Sat, 21 Nov 2020 21:44:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606023861; cv=none; d=google.com; s=arc-20160816; b=JivLMKv1DXijR5b9hziHMG/CGOflyaRWxXw7E2oq53+7f83E00d1KKOBnB09K5u2vr QgT0WcOZx7lzKLPvNmjed8wRkqSao42n6tSwGmw7Hq3N6P+EZkPEDGI0UUZuaTbYSNQB mc4Dukb/0cHWBV/uwiYgU0WYc4XXJx83o3hklcV2MBsq2ZfJH3mRxyEzYTv2IE+WTnDk U9EqrzvCrpGa5p3E1rXseXT9/8pMOqg+FWhWDC0R9hKMA9FO+qqINhmgzk96I7ms9JVj IonN3+ehwavprNeziyIeVgmZXkd+et6WkFsbs2K2gqtOcNABZbNl2Jnh+qbKLgDKcMew 1YTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uxioNJ9Dz5N1bJTcNGO+4WH6L1qpmuMjGSsoszz+ZaE=; b=cgRLgkijd50CG2gurW/ri6lNTE/jq9PWEZD6ja5duS3BKuRJIT6yuf+SsvML9gwEzs ru+xKyVEadYH+qDcvnuEocZjQc2AcFhs+A9XYTny3faiO4gxar1zMY6igZNRkWmm8Dgi Yn/1xdOPCaufMHZcQK1/TpCn8vlnWRKa/Kfzqm23ZcrfnqLosOsXFl9s2S77jgPz37H6 DiSd9sXJj51ZxKvtm3ISy7TDbYsQQ1i1UByaOqhVZtSGvp2YhSP0p8IdbRqCEI0belMu MxAVLiRQyf6Rv5eXFPpjT4AmOk0gIesWeAodp09irCjPgIbZlmBFWM5rwHnQD9QZAiT2 ihxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PFkpkKce; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e21si4848918edr.26.2020.11.21.21.43.59; Sat, 21 Nov 2020 21:44:21 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=PFkpkKce; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727374AbgKVFli (ORCPT + 99 others); Sun, 22 Nov 2020 00:41:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727365AbgKVFlh (ORCPT ); Sun, 22 Nov 2020 00:41:37 -0500 Received: from mail-oi1-x243.google.com (mail-oi1-x243.google.com [IPv6:2607:f8b0:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3B12C061A4B for ; Sat, 21 Nov 2020 21:41:35 -0800 (PST) Received: by mail-oi1-x243.google.com with SMTP id d9so15853200oib.3 for ; Sat, 21 Nov 2020 21:41:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uxioNJ9Dz5N1bJTcNGO+4WH6L1qpmuMjGSsoszz+ZaE=; b=PFkpkKceOBIr0TBYveSoUMOMFU0eH5GW8YBPjYyEx3gpqllx11EdVxW27KUkjiFMVM EE/udUMkOdtkA0+87g46i5h3nTvjN0eIimbNeSVXsGxgkkH8KGpURKUHjTe4SBfGGNi6 stdy4uEnadrfOydlixpckPziky/+4nncYvw9hUj6XRSDTJTYqb2e7u9gYrsOBtVWLYCM CfWiFv7omroy036DN6JdUSABtssXcvtJph0jVGDFU1STigZ+ApZOGUBamUBlXKHxJba8 4cfHUuLwMT1xm+cTWBbUFcw32IgsqSQf+INZ1X3YEOhNnu0aVnSLOVngnqZUC3g36TPc pN/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uxioNJ9Dz5N1bJTcNGO+4WH6L1qpmuMjGSsoszz+ZaE=; b=UAewfQElSZ20hMiVfnE008AGR+4gmHN7lKqkaC8KdPIg7Q2+gZpPmdxDpVH9nPCMDc eT1LR5KFy8kcIUfh3fBBbblVXrLW2OHcbqgE7Bk15EsXKYUaLzfdr1MHFsKU8o/UHlFs VPptYNYBFOw8Po6qHuoD2XG/c7A+/JURpl1ObdoJVnVJCkTTzLL4W9mbRuc13tLWRwRO w1isNLExy6VP7qpqepz7txv5azM2UlJRn7IrYYnJq0miUd9W6H1k5bRM0LcfjSqnggy6 NGHfbd8pQM4CT/hQSLhwQK7RfBtLROMVMSEnEK3OQ1BXJWW+a2sAAShcPqEUna4jgKUJ TjFg== X-Gm-Message-State: AOAM5305bomtl1dZg0e/XuVgvAjGaLyE9CcSepb3rsqtMHz+1iZdskct FjG0Rlde8hjB4x0sxHQ/j/JVw8ElQRQrKg== X-Received: by 2002:a05:6808:14e:: with SMTP id h14mr11814504oie.126.1606023695179; Sat, 21 Nov 2020 21:41:35 -0800 (PST) Received: from localhost.localdomain (104-57-184-186.lightspeed.austtx.sbcglobal.net. [104.57.184.186]) by smtp.gmail.com with ESMTPSA id s28sm4303132otr.4.2020.11.21.21.41.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 21:41:34 -0800 (PST) From: Bjorn Andersson To: Andy Gross , Bjorn Andersson , Ohad Ben-Cohen , Siddharth Gupta Cc: Mathieu Poirier , linux-arm-msm@vger.kernel.org, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, Steev Klimaszewski , Rishabh Bhatnagar Subject: [PATCH v3 2/4] remoteproc: sysmon: Expose the shutdown result Date: Sat, 21 Nov 2020 21:41:33 -0800 Message-Id: <20201122054135.802935-3-bjorn.andersson@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201122054135.802935-1-bjorn.andersson@linaro.org> References: <20201122054135.802935-1-bjorn.andersson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A graceful shutdown of the Qualcomm remote processors where traditionally performed by invoking a shared memory state signal and waiting for the associated ack. This was later superseded by the "sysmon" mechanism, where some form of shared memory bus is used to send a "graceful shutdown request" message and one of more signals comes back to indicate its success. But when this newer mechanism is in effect the firmware is shut down by the time the older mechanism, implemented in the remoteproc drivers, attempts to perform a graceful shutdown - and as such it will never receive an ack back. This patch therefor track the success of the latest shutdown attempt in sysmon and exposes a new function in the API that the remoteproc driver can use to query the success and the necessity of invoking the older mechanism. Tested-by: Steev Klimaszewski Reviewed-by: Rishabh Bhatnagar Signed-off-by: Bjorn Andersson --- Change since v2: - None drivers/remoteproc/qcom_common.h | 6 +++ drivers/remoteproc/qcom_sysmon.c | 82 ++++++++++++++++++++++++-------- 2 files changed, 69 insertions(+), 19 deletions(-) diff --git a/drivers/remoteproc/qcom_common.h b/drivers/remoteproc/qcom_common.h index dfc641c3a98b..8ba9052955bd 100644 --- a/drivers/remoteproc/qcom_common.h +++ b/drivers/remoteproc/qcom_common.h @@ -51,6 +51,7 @@ struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc, const char *name, int ssctl_instance); void qcom_remove_sysmon_subdev(struct qcom_sysmon *sysmon); +bool qcom_sysmon_shutdown_acked(struct qcom_sysmon *sysmon); #else static inline struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc, const char *name, @@ -62,6 +63,11 @@ static inline struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc, static inline void qcom_remove_sysmon_subdev(struct qcom_sysmon *sysmon) { } + +static inline bool qcom_sysmon_shutdown_acked(struct qcom_sysmon *sysmon) +{ + return false; +} #endif #endif diff --git a/drivers/remoteproc/qcom_sysmon.c b/drivers/remoteproc/qcom_sysmon.c index b37b111b15b3..a428b707a6de 100644 --- a/drivers/remoteproc/qcom_sysmon.c +++ b/drivers/remoteproc/qcom_sysmon.c @@ -44,6 +44,7 @@ struct qcom_sysmon { struct mutex lock; bool ssr_ack; + bool shutdown_acked; struct qmi_handle qmi; struct sockaddr_qrtr ssctl; @@ -115,10 +116,13 @@ static void sysmon_send_event(struct qcom_sysmon *sysmon, /** * sysmon_request_shutdown() - request graceful shutdown of remote * @sysmon: sysmon context + * + * Return: boolean indicator of the remote processor acking the request */ -static void sysmon_request_shutdown(struct qcom_sysmon *sysmon) +static bool sysmon_request_shutdown(struct qcom_sysmon *sysmon) { char *req = "ssr:shutdown"; + bool acked = false; int ret; mutex_lock(&sysmon->lock); @@ -141,9 +145,13 @@ static void sysmon_request_shutdown(struct qcom_sysmon *sysmon) if (!sysmon->ssr_ack) dev_err(sysmon->dev, "unexpected response to sysmon shutdown request\n"); + else + acked = true; out_unlock: mutex_unlock(&sysmon->lock); + + return acked; } static int sysmon_callback(struct rpmsg_device *rpdev, void *data, int count, @@ -297,14 +305,33 @@ static struct qmi_msg_handler qmi_indication_handler[] = { {} }; +static bool ssctl_request_shutdown_wait(struct qcom_sysmon *sysmon) +{ + int ret; + + ret = wait_for_completion_timeout(&sysmon->shutdown_comp, 10 * HZ); + if (ret) + return true; + + ret = try_wait_for_completion(&sysmon->ind_comp); + if (ret) + return true; + + dev_err(sysmon->dev, "timeout waiting for shutdown ack\n"); + return false; +} + /** * ssctl_request_shutdown() - request shutdown via SSCTL QMI service * @sysmon: sysmon context + * + * Return: boolean indicator of the remote processor acking the request */ -static void ssctl_request_shutdown(struct qcom_sysmon *sysmon) +static bool ssctl_request_shutdown(struct qcom_sysmon *sysmon) { struct ssctl_shutdown_resp resp; struct qmi_txn txn; + bool acked = false; int ret; reinit_completion(&sysmon->ind_comp); @@ -312,7 +339,7 @@ static void ssctl_request_shutdown(struct qcom_sysmon *sysmon) ret = qmi_txn_init(&sysmon->qmi, &txn, ssctl_shutdown_resp_ei, &resp); if (ret < 0) { dev_err(sysmon->dev, "failed to allocate QMI txn\n"); - return; + return false; } ret = qmi_send_request(&sysmon->qmi, &sysmon->ssctl, &txn, @@ -320,27 +347,23 @@ static void ssctl_request_shutdown(struct qcom_sysmon *sysmon) if (ret < 0) { dev_err(sysmon->dev, "failed to send shutdown request\n"); qmi_txn_cancel(&txn); - return; + return false; } ret = qmi_txn_wait(&txn, 5 * HZ); - if (ret < 0) + if (ret < 0) { dev_err(sysmon->dev, "failed receiving QMI response\n"); - else if (resp.resp.result) + } else if (resp.resp.result) { dev_err(sysmon->dev, "shutdown request failed\n"); - else + } else { dev_dbg(sysmon->dev, "shutdown request completed\n"); - - if (sysmon->shutdown_irq > 0) { - ret = wait_for_completion_timeout(&sysmon->shutdown_comp, - 10 * HZ); - if (!ret) { - ret = try_wait_for_completion(&sysmon->ind_comp); - if (!ret) - dev_err(sysmon->dev, - "timeout waiting for shutdown ack\n"); - } + acked = true; } + + if (sysmon->shutdown_irq > 0) + return ssctl_request_shutdown_wait(sysmon); + + return acked; } /** @@ -510,6 +533,9 @@ static void sysmon_stop(struct rproc_subdev *subdev, bool crashed) .subsys_name = sysmon->name, .ssr_event = SSCTL_SSR_EVENT_BEFORE_SHUTDOWN }; + bool acked; + + sysmon->shutdown_acked = false; mutex_lock(&sysmon->state_lock); sysmon->state = SSCTL_SSR_EVENT_BEFORE_SHUTDOWN; @@ -521,9 +547,11 @@ static void sysmon_stop(struct rproc_subdev *subdev, bool crashed) return; if (sysmon->ssctl_version) - ssctl_request_shutdown(sysmon); + acked = ssctl_request_shutdown(sysmon); else if (sysmon->ept) - sysmon_request_shutdown(sysmon); + acked = sysmon_request_shutdown(sysmon); + + sysmon->shutdown_acked = acked; } static void sysmon_unprepare(struct rproc_subdev *subdev) @@ -681,6 +709,22 @@ void qcom_remove_sysmon_subdev(struct qcom_sysmon *sysmon) } EXPORT_SYMBOL_GPL(qcom_remove_sysmon_subdev); +/** + * qcom_sysmon_shutdown_acked() - query the success of the last shutdown + * @sysmon: sysmon context + * + * When sysmon is used to request a graceful shutdown of the remote processor + * this can be used by the remoteproc driver to query the success, in order to + * know if it should fall back to other means of requesting a shutdown. + * + * Return: boolean indicator of the success of the last shutdown request + */ +bool qcom_sysmon_shutdown_acked(struct qcom_sysmon *sysmon) +{ + return sysmon && sysmon->shutdown_acked; +} +EXPORT_SYMBOL_GPL(qcom_sysmon_shutdown_acked); + /** * sysmon_probe() - probe sys_mon channel * @rpdev: rpmsg device handle -- 2.28.0