From patchwork Sun Nov 22 05:41:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 11923745 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53DDCC64E8A for ; Sun, 22 Nov 2020 05:41:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24B43208D5 for ; Sun, 22 Nov 2020 05:41:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="mJBunxM5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727267AbgKVFlq (ORCPT ); Sun, 22 Nov 2020 00:41:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727339AbgKVFlg (ORCPT ); Sun, 22 Nov 2020 00:41:36 -0500 Received: from mail-oi1-x241.google.com (mail-oi1-x241.google.com [IPv6:2607:f8b0:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF7E5C0613D2 for ; Sat, 21 Nov 2020 21:41:34 -0800 (PST) Received: by mail-oi1-x241.google.com with SMTP id k26so15870312oiw.0 for ; Sat, 21 Nov 2020 21:41:34 -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=yQvyFDM0JjV69fRQJvQbh4EUUpGYP88ib4fx5c7S58s=; b=mJBunxM5mgkzBeH2Zqtr83SqxLzRQSI7jClSU564b/d8b94UJKf0ItjyaU8DOysg9q c2qrBo8aHMdfR9hFXUBrTuIndVRUWnODvuOoejC55fXbmlNn/YwzSESZOD/40gvxinXC Wvd3n8E82XsOpQlCJclCsN+Tbf5AAzNUhsp9Qpc9dTYWz9oLvdK+BPp2+S8sI+8Fj4xT AkZJ/sAcKBw4adkSr0cQMyyDeMTuuwYzOes78AZLUJ9otLcg12Rx5f4U8Xs7wNSSENWN ppDjxUS4l2njr6Cm53FAz6F95SPpOhxtr95nOCHLdfngcggTtw3lm2iBNOTZmutjWhDE vTLQ== 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=yQvyFDM0JjV69fRQJvQbh4EUUpGYP88ib4fx5c7S58s=; b=SR9PdE8lsPk1pysrO6epgG+5Ww1R/EQdrmQNqvRItf58T3BeJNEBpWNUqucCeXeAkN 9ly5DwI+6682YrX9N8LfUj/fehAYUcRPMb8NQskXxel1YZXj8YpfdX7qmltvNhJwUsGE 054VogLOfKFZuwx8W+HcdZvq5WuCNVQMa2nSA2Ltt7WrcUQdtVZeFHvhGLttCw7hbm5+ 8s3yibGub4IYNyh+7qbBQt3wze8i/HsvncFmq22GFYv3OmQxfpKicRubdIHUjmyP/cjx ghyOXpUJAf+URKbLysWMxEy0Fe8Z5lkOl2y1b8FZomKz7iBJR8W/Mb95OAkb+SKAxITU ofEQ== X-Gm-Message-State: AOAM533Lb8NI9ToRvPH56mW3kc+eGatFRVa/iXpZDuexl+kKm+dEO4a3 PovODaQC6HKf0MVTLtgaQ2ErYnuuQgtvtQ== X-Google-Smtp-Source: ABdhPJyqx4jrmkRkFOuiZci8CzeEUgW29mdcrfQBlpoCszNp00F3WQtf7ygPl9u4zmcUvbfO92rU8g== X-Received: by 2002:a54:4608:: with SMTP id p8mr11536251oip.5.1606023694131; Sat, 21 Nov 2020 21:41:34 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 21:41:33 -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, stable@vger.kernel.org Subject: [PATCH v3 1/4] remoteproc: sysmon: Ensure remote notification ordering Date: Sat, 21 Nov 2020 21:41:32 -0800 Message-Id: <20201122054135.802935-2-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 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The reliance on the remoteproc's state for determining when to send sysmon notifications to a remote processor is racy with regard to concurrent remoteproc operations. Further more the advertisement of the state of other remote processor to a newly started remote processor might not only send the wrong state, but might result in a stream of state changes that are out of order. Address this by introducing state tracking within the sysmon instances themselves and extend the locking to ensure that the notifications are consistent with this state. Fixes: 1f36ab3f6e3b ("remoteproc: sysmon: Inform current rproc about all active rprocs") Fixes: 1877f54f75ad ("remoteproc: sysmon: Add notifications for events") Fixes: 1fb82ee806d1 ("remoteproc: qcom: Introduce sysmon") Cc: stable@vger.kernel.org Signed-off-by: Bjorn Andersson Reviewed-by: Rishabh Bhatnagar --- Changes since v2: - Hold sysmon_lock during traversal of sysmons in sysmon_start() drivers/remoteproc/qcom_sysmon.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/remoteproc/qcom_sysmon.c b/drivers/remoteproc/qcom_sysmon.c index 9eb2f6bccea6..b37b111b15b3 100644 --- a/drivers/remoteproc/qcom_sysmon.c +++ b/drivers/remoteproc/qcom_sysmon.c @@ -22,6 +22,9 @@ struct qcom_sysmon { struct rproc_subdev subdev; struct rproc *rproc; + int state; + struct mutex state_lock; + struct list_head node; const char *name; @@ -448,7 +451,10 @@ static int sysmon_prepare(struct rproc_subdev *subdev) .ssr_event = SSCTL_SSR_EVENT_BEFORE_POWERUP }; + mutex_lock(&sysmon->state_lock); + sysmon->state = SSCTL_SSR_EVENT_BEFORE_POWERUP; blocking_notifier_call_chain(&sysmon_notifiers, 0, (void *)&event); + mutex_unlock(&sysmon->state_lock); return 0; } @@ -472,20 +478,25 @@ static int sysmon_start(struct rproc_subdev *subdev) .ssr_event = SSCTL_SSR_EVENT_AFTER_POWERUP }; + mutex_lock(&sysmon->state_lock); + sysmon->state = SSCTL_SSR_EVENT_AFTER_POWERUP; blocking_notifier_call_chain(&sysmon_notifiers, 0, (void *)&event); + mutex_unlock(&sysmon->state_lock); mutex_lock(&sysmon_lock); list_for_each_entry(target, &sysmon_list, node) { - if (target == sysmon || - target->rproc->state != RPROC_RUNNING) + if (target == sysmon) continue; + mutex_lock(&target->state_lock); event.subsys_name = target->name; + event.ssr_event = target->state; if (sysmon->ssctl_version == 2) ssctl_send_event(sysmon, &event); else if (sysmon->ept) sysmon_send_event(sysmon, &event); + mutex_unlock(&target->state_lock); } mutex_unlock(&sysmon_lock); @@ -500,7 +511,10 @@ static void sysmon_stop(struct rproc_subdev *subdev, bool crashed) .ssr_event = SSCTL_SSR_EVENT_BEFORE_SHUTDOWN }; + mutex_lock(&sysmon->state_lock); + sysmon->state = SSCTL_SSR_EVENT_BEFORE_SHUTDOWN; blocking_notifier_call_chain(&sysmon_notifiers, 0, (void *)&event); + mutex_unlock(&sysmon->state_lock); /* Don't request graceful shutdown if we've crashed */ if (crashed) @@ -521,7 +535,10 @@ static void sysmon_unprepare(struct rproc_subdev *subdev) .ssr_event = SSCTL_SSR_EVENT_AFTER_SHUTDOWN }; + mutex_lock(&sysmon->state_lock); + sysmon->state = SSCTL_SSR_EVENT_AFTER_SHUTDOWN; blocking_notifier_call_chain(&sysmon_notifiers, 0, (void *)&event); + mutex_unlock(&sysmon->state_lock); } /** @@ -534,11 +551,10 @@ static int sysmon_notify(struct notifier_block *nb, unsigned long event, void *data) { struct qcom_sysmon *sysmon = container_of(nb, struct qcom_sysmon, nb); - struct rproc *rproc = sysmon->rproc; struct sysmon_event *sysmon_event = data; /* Skip non-running rprocs and the originating instance */ - if (rproc->state != RPROC_RUNNING || + if (sysmon->state != SSCTL_SSR_EVENT_AFTER_POWERUP || !strcmp(sysmon_event->subsys_name, sysmon->name)) { dev_dbg(sysmon->dev, "not notifying %s\n", sysmon->name); return NOTIFY_DONE; @@ -591,6 +607,7 @@ struct qcom_sysmon *qcom_add_sysmon_subdev(struct rproc *rproc, init_completion(&sysmon->ind_comp); init_completion(&sysmon->shutdown_comp); mutex_init(&sysmon->lock); + mutex_init(&sysmon->state_lock); sysmon->shutdown_irq = of_irq_get_byname(sysmon->dev->of_node, "shutdown-ack"); From patchwork Sun Nov 22 05:41:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 11923749 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A31DDC64EBC for ; Sun, 22 Nov 2020 05:41:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F3DC208D5 for ; Sun, 22 Nov 2020 05:41:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="PFkpkKce" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727339AbgKVFlr (ORCPT ); Sun, 22 Nov 2020 00:41:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727297AbgKVFlf (ORCPT ); Sun, 22 Nov 2020 00:41:35 -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 C3AB2C0613D3 for ; Sat, 21 Nov 2020 21:41:35 -0800 (PST) Received: by mail-oi1-x243.google.com with SMTP id o25so15850078oie.5 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=gH0DgL62/8q/qAv+c7hPMhwR7EBu+KJeQDia/ZFVB+wBQ2cVthpf8BWB0zIwR9hYSI 5gVEj5EepM5eca9G2Q0mLr3nufdQfOa/WZEPRzm36I+QZgpaQIZzka04yNtGfURR13ST Xd++mF/yYbizK+fipsLBZba3JmHsqAjj9hZzGIxmYW0NjXUif+rUWdG1u1BWgWGPoUsu h7IsareBILaTznLa54CTH6oQcsm7RS8wEOQrYyOhtb/xK8T6fO5EuukC2j4BiA4VBuhB hnTAfZNVyJvKv4n3gFP233chKdqSTrXUJuDfbxIp66hTR8Xvidp+R+Coy7WghBW/D2GP HLxA== X-Gm-Message-State: AOAM5336wdkLUuvCSf4oWf27I0lNzMQDhJJQTLShB6IehGqj3gmr67cb 4vNaNWYC2MUW3qzzx+zAqkEtTQ== X-Google-Smtp-Source: ABdhPJyyGT5KbeBIkpt56QyndMzf+OOeuNWg+/InHojhwHsTZ+799ij/wr9vqnnxWzu/2dBWpqCV+A== 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 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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 From patchwork Sun Nov 22 05:41:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 11923747 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35431C64E7D for ; Sun, 22 Nov 2020 05:41:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F38AB20789 for ; Sun, 22 Nov 2020 05:41:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Dw43r0cp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727329AbgKVFlq (ORCPT ); Sun, 22 Nov 2020 00:41:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727267AbgKVFlg (ORCPT ); Sun, 22 Nov 2020 00:41:36 -0500 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDB35C061A4A for ; Sat, 21 Nov 2020 21:41:36 -0800 (PST) Received: by mail-ot1-x343.google.com with SMTP id 79so12875940otc.7 for ; Sat, 21 Nov 2020 21:41:36 -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=8Mu+dWZCO3tL9VhrtmkYCgByiYUNNJtCg8o7EBl4LbY=; b=Dw43r0cpkVNP4J6hIFwMxTkUOA20gaysCq4H+9QCOnXZSbp7ee/b7HZ5k6XHdg6TL3 8j9tw8ef9qwdjWzsYYEpo6XRpa5cpL+ekwgtNWGdKEIjRt9vtlh7s7576moo5iDUwl8m st1XacbCo2mD9HTFL0bh8fW6TGVcAYuxCZGwjkVHDEx66cC4Gj9jJtyfCq+xU1bU6yh0 bAsqlGVsZC5MFcZV4zgzLhco2l9t/1kLOTRGHBxZMcgj3cGuoVJ52de1rYWxEChEMQyp iCuuuJ3A1JsHDhqJvu/JT1jl0WD4eYpAS8bEXHuAdD6gSvf3Z3zPnvqk4X+GVuPAcZOE GLcg== 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=8Mu+dWZCO3tL9VhrtmkYCgByiYUNNJtCg8o7EBl4LbY=; b=bWQWWMN+AsOyKoBDD1Iv9bSQQ+gigSm1PAQWJJt9iWkWoifSNXo5Hnv05NjeI7UAx1 iYp2mfqtyfLfmeOEIbcyFzLD0pyFlwzXaflM0ma6ffqFO/5Dfq8ClZmB7VVc3pZionU/ R1ScHH+WEPvlB0tVEI9MUwQLBv8nRWiuW/DRcAoVG4zt7AbikoGIHtfmPQaDxw6gj/Aq BJUKU9XUNMFN2dDYkbySylvq01NoF42oQYwuKpmPGfpPifkEmJVK0pf/rXSSjyteh17r phW/1gj6AVh8jN35exzyWbybLzdAksHeySisE9miJdnMNuqUha5X8taGAn9YBtmkuQqb vcsA== X-Gm-Message-State: AOAM5300qYY/tUPgjb5SBYxUhaubZTOpIhrocAFyyXjSx4BDgvbb60gh 4MWDTcUarqiy2A6gNQ5m0K1QzA8P1WvsKQ== X-Google-Smtp-Source: ABdhPJyjiYCewLDWj4DRROyBGjc0tJrW+kPIe/zJJooxQI8y/UHfKPGd0DcDhL5fZlmKKaeFuZNQ1g== X-Received: by 2002:a05:6830:12c2:: with SMTP id a2mr19346062otq.162.1606023696218; Sat, 21 Nov 2020 21:41:36 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 21:41:35 -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 3/4] remoteproc: qcom: q6v5: Query sysmon before graceful shutdown Date: Sat, 21 Nov 2020 21:41:34 -0800 Message-Id: <20201122054135.802935-4-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 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Requesting a graceful shutdown through the shared memory state signals will not be acked in the event that sysmon has already successfully shut down the remote firmware. So extend the stop request API to optionally take the remoteproc's sysmon instance and query if there's already been a successful shutdown attempt, before doing the signal dance. Tested-by: Steev Klimaszewski Reviewed-by: Rishabh Bhatnagar Signed-off-by: Bjorn Andersson --- Change since v2: - Fixed spelling of optionally in commit message drivers/remoteproc/qcom_q6v5.c | 8 +++++++- drivers/remoteproc/qcom_q6v5.h | 3 ++- drivers/remoteproc/qcom_q6v5_adsp.c | 2 +- drivers/remoteproc/qcom_q6v5_mss.c | 2 +- drivers/remoteproc/qcom_q6v5_pas.c | 2 +- drivers/remoteproc/qcom_q6v5_wcss.c | 2 +- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/remoteproc/qcom_q6v5.c b/drivers/remoteproc/qcom_q6v5.c index fd6fd36268d9..9627a950928e 100644 --- a/drivers/remoteproc/qcom_q6v5.c +++ b/drivers/remoteproc/qcom_q6v5.c @@ -13,6 +13,7 @@ #include #include #include +#include "qcom_common.h" #include "qcom_q6v5.h" #define Q6V5_PANIC_DELAY_MS 200 @@ -146,15 +147,20 @@ static irqreturn_t q6v5_stop_interrupt(int irq, void *data) /** * qcom_q6v5_request_stop() - request the remote processor to stop * @q6v5: reference to qcom_q6v5 context + * @sysmon: reference to the remote's sysmon instance, or NULL * * Return: 0 on success, negative errno on failure */ -int qcom_q6v5_request_stop(struct qcom_q6v5 *q6v5) +int qcom_q6v5_request_stop(struct qcom_q6v5 *q6v5, struct qcom_sysmon *sysmon) { int ret; q6v5->running = false; + /* Don't perform SMP2P dance if sysmon already shut down the remote */ + if (qcom_sysmon_shutdown_acked(sysmon)) + return 0; + qcom_smem_state_update_bits(q6v5->state, BIT(q6v5->stop_bit), BIT(q6v5->stop_bit)); diff --git a/drivers/remoteproc/qcom_q6v5.h b/drivers/remoteproc/qcom_q6v5.h index c4ed887c1499..1c212f670cbc 100644 --- a/drivers/remoteproc/qcom_q6v5.h +++ b/drivers/remoteproc/qcom_q6v5.h @@ -8,6 +8,7 @@ struct rproc; struct qcom_smem_state; +struct qcom_sysmon; struct qcom_q6v5 { struct device *dev; @@ -40,7 +41,7 @@ int qcom_q6v5_init(struct qcom_q6v5 *q6v5, struct platform_device *pdev, int qcom_q6v5_prepare(struct qcom_q6v5 *q6v5); int qcom_q6v5_unprepare(struct qcom_q6v5 *q6v5); -int qcom_q6v5_request_stop(struct qcom_q6v5 *q6v5); +int qcom_q6v5_request_stop(struct qcom_q6v5 *q6v5, struct qcom_sysmon *sysmon); int qcom_q6v5_wait_for_start(struct qcom_q6v5 *q6v5, int timeout); unsigned long qcom_q6v5_panic(struct qcom_q6v5 *q6v5); diff --git a/drivers/remoteproc/qcom_q6v5_adsp.c b/drivers/remoteproc/qcom_q6v5_adsp.c index f0b7363b5b26..2f8f38408eb7 100644 --- a/drivers/remoteproc/qcom_q6v5_adsp.c +++ b/drivers/remoteproc/qcom_q6v5_adsp.c @@ -266,7 +266,7 @@ static int adsp_stop(struct rproc *rproc) int handover; int ret; - ret = qcom_q6v5_request_stop(&adsp->q6v5); + ret = qcom_q6v5_request_stop(&adsp->q6v5, adsp->sysmon); if (ret == -ETIMEDOUT) dev_err(adsp->dev, "timed out on wait\n"); diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c index ac289e08062e..55f7c5740920 100644 --- a/drivers/remoteproc/qcom_q6v5_mss.c +++ b/drivers/remoteproc/qcom_q6v5_mss.c @@ -1373,7 +1373,7 @@ static int q6v5_stop(struct rproc *rproc) struct q6v5 *qproc = (struct q6v5 *)rproc->priv; int ret; - ret = qcom_q6v5_request_stop(&qproc->q6v5); + ret = qcom_q6v5_request_stop(&qproc->q6v5, qproc->sysmon); if (ret == -ETIMEDOUT) dev_err(qproc->dev, "timed out on wait\n"); diff --git a/drivers/remoteproc/qcom_q6v5_pas.c b/drivers/remoteproc/qcom_q6v5_pas.c index 0678b417707e..49ea0133ff04 100644 --- a/drivers/remoteproc/qcom_q6v5_pas.c +++ b/drivers/remoteproc/qcom_q6v5_pas.c @@ -217,7 +217,7 @@ static int adsp_stop(struct rproc *rproc) int handover; int ret; - ret = qcom_q6v5_request_stop(&adsp->q6v5); + ret = qcom_q6v5_request_stop(&adsp->q6v5, adsp->sysmon); if (ret == -ETIMEDOUT) dev_err(adsp->dev, "timed out on wait\n"); diff --git a/drivers/remoteproc/qcom_q6v5_wcss.c b/drivers/remoteproc/qcom_q6v5_wcss.c index 8846ef0b0f1a..d6639856069b 100644 --- a/drivers/remoteproc/qcom_q6v5_wcss.c +++ b/drivers/remoteproc/qcom_q6v5_wcss.c @@ -390,7 +390,7 @@ static int q6v5_wcss_stop(struct rproc *rproc) int ret; /* WCSS powerdown */ - ret = qcom_q6v5_request_stop(&wcss->q6v5); + ret = qcom_q6v5_request_stop(&wcss->q6v5, wcss->sysmon); if (ret == -ETIMEDOUT) { dev_err(wcss->dev, "timed out on wait\n"); return ret; From patchwork Sun Nov 22 05:41:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Andersson X-Patchwork-Id: 11923743 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C73EFC64E7B for ; Sun, 22 Nov 2020 05:41:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6FA9E208D5 for ; Sun, 22 Nov 2020 05:41:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="z0/F6IyZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727423AbgKVFlm (ORCPT ); Sun, 22 Nov 2020 00:41:42 -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 S1727387AbgKVFlj (ORCPT ); Sun, 22 Nov 2020 00:41:39 -0500 Received: from mail-oi1-x241.google.com (mail-oi1-x241.google.com [IPv6:2607:f8b0:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC54AC0613D3 for ; Sat, 21 Nov 2020 21:41:37 -0800 (PST) Received: by mail-oi1-x241.google.com with SMTP id v202so12677764oia.9 for ; Sat, 21 Nov 2020 21:41:37 -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=qvpm8U35Wi5xW8cDlkOEMWm9u3v4oYij+TGxaJn+sgw=; b=z0/F6IyZHUpoXEJ0ybXF0z+a2Xvsd86bf/HthIlSIfCqh4GOISDFivw9DlSAs43MUf KIiKAlMN1RyUIf05KNffeRroYx2MlnXI6wiQw8MoSLsIF4Vy4C8rBBmsZTyBTVpfIgrY 1Qfoko5q9gxGU0WllYgLcIiywlvSd6LHUBv2z8VfFd8NtnwI9V0ihBcRW6jSIlYsplMQ 8BHhmWltd/2s7hODDaApsQpF0l6uK4mKJKg7AY2COhy7o+orKDBnSoGDH/nlU1qMn3uT R5Xy6Ny3v4wBwutcyUM7HLDJCzXzVAni38fVw5XScvr1dca4ueAv2MG7Sz0ZxksNZZDD U9JQ== 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=qvpm8U35Wi5xW8cDlkOEMWm9u3v4oYij+TGxaJn+sgw=; b=O+HX4N3emdAScCuDiuP2zG8vYh21X/o1rK9rwX6w0+p7dNE+WrpOrFyWqwhD+AK594 dAf+2BrfWOWSgHmADblQJXZh70mmIVVk1z4Lll9c6XD06+AIaolUqt9Bq+g9oI0Z7jMi uJdtC6bD8gp6g+mFJ3HIvi2fA661p5rHQ7G7LCL5XvVPahK3eAaCCYuCXm2JhMQYK3Vj IiuT8gvd1YXThIHq/j/0/dWkIH+I7wHoL82Pnyjlzgk9noizbpFFCvhhNL26AN6dPrCG nv/GZxPPuiW7yjrmvNA41OVUela8KA7X20TXt1EWl7/bLvE6k5SdrqZmlVmKRSQOPNFN tmFA== X-Gm-Message-State: AOAM531p7uR5XZR2xhOuTUhuiJf/3TPG5ikFsj09inql4ok2IA38OpSa RMSmJt1LgatwbLT5GHpcWhj5ZA== X-Google-Smtp-Source: ABdhPJxRJ6Pq2gDVZXh9XuwLH1m35Yf7+sfqi3oaKpZi2VQkh8xbuUn+pF/Kl/gQRDFRthtP79fiQA== X-Received: by 2002:aca:a8c8:: with SMTP id r191mr11456932oie.138.1606023697312; Sat, 21 Nov 2020 21:41:37 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Nov 2020 21:41:36 -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 4/4] remoteproc: sysmon: Improve error messages Date: Sat, 21 Nov 2020 21:41:35 -0800 Message-Id: <20201122054135.802935-5-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 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Improve the style of a few of the error messages printed by the sysmon implementation and fix the copy-pasted shutdown error in the send-event function. Tested-by: Steev Klimaszewski Reviewed-by: Rishabh Bhatnagar Signed-off-by: Bjorn Andersson --- Change since v2: - None drivers/remoteproc/qcom_sysmon.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/remoteproc/qcom_sysmon.c b/drivers/remoteproc/qcom_sysmon.c index a428b707a6de..9fed11a2b4ba 100644 --- a/drivers/remoteproc/qcom_sysmon.c +++ b/drivers/remoteproc/qcom_sysmon.c @@ -352,9 +352,9 @@ static bool ssctl_request_shutdown(struct qcom_sysmon *sysmon) ret = qmi_txn_wait(&txn, 5 * HZ); if (ret < 0) { - dev_err(sysmon->dev, "failed receiving QMI response\n"); + dev_err(sysmon->dev, "timeout waiting for shutdown response\n"); } else if (resp.resp.result) { - dev_err(sysmon->dev, "shutdown request failed\n"); + dev_err(sysmon->dev, "shutdown request rejected\n"); } else { dev_dbg(sysmon->dev, "shutdown request completed\n"); acked = true; @@ -397,18 +397,18 @@ static void ssctl_send_event(struct qcom_sysmon *sysmon, SSCTL_SUBSYS_EVENT_REQ, 40, ssctl_subsys_event_req_ei, &req); if (ret < 0) { - dev_err(sysmon->dev, "failed to send shutdown request\n"); + dev_err(sysmon->dev, "failed to send subsystem event\n"); qmi_txn_cancel(&txn); return; } ret = qmi_txn_wait(&txn, 5 * HZ); if (ret < 0) - dev_err(sysmon->dev, "failed receiving QMI response\n"); + dev_err(sysmon->dev, "timeout waiting for subsystem event response\n"); else if (resp.resp.result) - dev_err(sysmon->dev, "ssr event send failed\n"); + dev_err(sysmon->dev, "subsystem event rejected\n"); else - dev_dbg(sysmon->dev, "ssr event send completed\n"); + dev_dbg(sysmon->dev, "subsystem event accepted\n"); } /**