From patchwork Tue Apr 6 09:11:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 415880 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp4381666jai; Tue, 6 Apr 2021 02:03:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKMmRz49jBYgnj4d2fC810+xstlgRZoAg2m9UJH8WhUFtrTcra7c5e8JqbiUk48PDyjvvC X-Received: by 2002:a05:6e02:1d8e:: with SMTP id h14mr22811868ila.301.1617699809078; Tue, 06 Apr 2021 02:03:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617699809; cv=none; d=google.com; s=arc-20160816; b=sFTX+7rFYfhNDCMV9UjPZm5BiMkGaVC6x+ACxOAguNRHszwqA479065JjX+lKrXd6Q vYdGbe0G+ucsatSbgeuvXM74EGEyX3ZdQ4NV2JWJACtTY7EAKC9atea/dG0481EodgWy v5jkRw1foafvjFxIRNFUiFPwxcmP1BIPU0GG9hq8wAQvy+Rfc+LPXkS77mOMaGjwx4Uh yds22ZPdRN/XIvMWTIESYfUtwnB8tA2B8Zf14KCdozha1+Irlh3I/dzH8ZexHyg087Uq Yd9MzjdOJa24KJ5rp3JR+jiteqAynPL29Y1iFIU2XahsLDhEFgmaUuTdnUY4gvwGxMMH dzMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=hhElSehBICCLixw2Sc8DnTZQKYNCSKGbuQyHX9s80TU=; b=aplfRHGWv/gcYbSO4yy88mRuy1pZ8w8uiB2ZEkUFqOtoHe5y/Ms83OjO1LLulEgO42 Gx3xlTiTVHM5Q4ebLooZuGOLEkDbDas6XZuHuGvcVJA+t17PxzLjBhI/vX1sc2kV95xh Hg5aI2gaGyC8G5RFJ0KR7JbmMREsW4EdsnSPJscB0wwkaaHzpsKM7Ys6SARd+a3LzT5H pHXIVMIqxHqM+QXlAk6zfFb67HGlCuF+riGWukmuZUnXx0nEOvuopl8KIQWcp3Sw4LQg Np3mlFchqwm13b9dyxY2SF9QGGUHLtV5GUOxmCYLXMo0EZ32B7gSP0QW0oOwER9mxSqA Yi3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i8y+U33j; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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 w9si18601743jad.47.2021.04.06.02.03.17; Tue, 06 Apr 2021 02:03:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-msm-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=i8y+U33j; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S240564AbhDFJDY (ORCPT + 17 others); Tue, 6 Apr 2021 05:03:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240559AbhDFJDX (ORCPT ); Tue, 6 Apr 2021 05:03:23 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03D27C06174A for ; Tue, 6 Apr 2021 02:03:15 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id o6so4021718wmq.3 for ; Tue, 06 Apr 2021 02:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=hhElSehBICCLixw2Sc8DnTZQKYNCSKGbuQyHX9s80TU=; b=i8y+U33jxfRDkGCdX5fOtdblKXSPK+nAVJ2wFSl4ZASvEvtjknOwKAmEI8mhjpDYMl fvcREKX6n8Ir/oNM0boKfhH6bvaDcQRNG/WtExT6KLZoR4zddKFXpFjO60N6ObDp2JIC H0pZKhQTS1aYfQzqOSuMDFRnkxnhWMnlQpXjTaUxSDMqBrEqlGRS+3dbWn6TmnceGsWa rDwgFW2YJBKCxthNKhV4iEpVHGq2B01tLi72k3/EM1aAVEi+2f00ImhYTygHWBWkROR8 tyRifP8KqN6BpQoFrjUv8fKVguEEGxzQyHt73ErRhZOkl9u39V99jQSRPx2Bd8uZkmB7 +jMw== 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; bh=hhElSehBICCLixw2Sc8DnTZQKYNCSKGbuQyHX9s80TU=; b=TgrqJQhgMYwUXsZ6H27t3/MfkLMC6duDC7HAh2ASJXhU2fMXja4DLKdkoUX95m0YMh kkNcRY/DXFuwS9tB5UqNjcOXdBlYt+9h1L0D8C9XIH5Ahocq8vsyAD1pxMCi2buM9A19 1eB0KHbiYzwOs0/NOvgcePejlHiBzcJAbXUMR1a8kDjVWyWthc+xVagQgAAZxEergpL9 iUo8LT89BYV4ABo73J1WmrsHKTKcR2HlbDfOAZV8Ts0u5i91nGqSBEyhDjlrikzoBK76 dXry5fGyvHMnSw6BP6KdmfyUTZquTzAf+KKEAV/+IeqcxBYzFuLckJLUMTaE5MUZrzuc UHiw== X-Gm-Message-State: AOAM532LbhAfF6vRB1E746Mpj5jxHFtWNNcaI72x4klbln1sdb2KHQRu GFQIiYqcviL17HHnmNpkHtSML+UMIrtTml1h X-Received: by 2002:a7b:cc84:: with SMTP id p4mr3149612wma.10.1617699793574; Tue, 06 Apr 2021 02:03:13 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:82c:5f0:49e5:d54d:f006:441f]) by smtp.gmail.com with ESMTPSA id r1sm38266233wrj.63.2021.04.06.02.03.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Apr 2021 02:03:13 -0700 (PDT) From: Loic Poulain To: manivannan.sadhasivam@linaro.org, hemantk@codeaurora.org Cc: bbhatt@codeaurora.org, linux-arm-msm@vger.kernel.org, Loic Poulain Subject: [PATCH v2 1/2] bus: mhi: core: Fix MHI runtime_pm behavior Date: Tue, 6 Apr 2021 11:11:54 +0200 Message-Id: <1617700315-12492-1-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org This change ensures that PM reference is always get during packet queueing and released either after queuing completion (RX) or once the buffer has been consumed (TX). This guarantees proper update for underlying MHI controller runtime status (e.g. last_busy timestamp) and prevents suspend to be triggered while TX packets are flying, or before we completed update of the RX ring. Signed-off-by: Loic Poulain --- v2: mhi_reset_data_chan: move put under existing DMA_TO_DEVICE if block drivers/bus/mhi/core/main.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) -- 2.7.4 Reviewed-by: Manivannan Sadhasivam diff --git a/drivers/bus/mhi/core/main.c b/drivers/bus/mhi/core/main.c index c780234..6e72239 100644 --- a/drivers/bus/mhi/core/main.c +++ b/drivers/bus/mhi/core/main.c @@ -584,8 +584,11 @@ static int parse_xfer_event(struct mhi_controller *mhi_cntrl, /* notify client */ mhi_chan->xfer_cb(mhi_chan->mhi_dev, &result); - if (mhi_chan->dir == DMA_TO_DEVICE) + if (mhi_chan->dir == DMA_TO_DEVICE) { atomic_dec(&mhi_cntrl->pending_pkts); + /* Release the reference got from mhi_queue() */ + mhi_cntrl->runtime_put(mhi_cntrl); + } /* * Recycle the buffer if buffer is pre-allocated, @@ -1021,9 +1024,11 @@ static int mhi_queue(struct mhi_device *mhi_dev, struct mhi_buf_info *buf_info, if (unlikely(ret)) goto exit_unlock; - /* trigger M3 exit if necessary */ - if (MHI_PM_IN_SUSPEND_STATE(mhi_cntrl->pm_state)) - mhi_trigger_resume(mhi_cntrl); + /* Packet is queued, take a usage ref to exit M3 if necessary + * for host->device buffer, balanced put is done on buffer completion + * for device->host buffer, balanced put is after ringing the DB + */ + mhi_cntrl->runtime_get(mhi_cntrl); /* Assert dev_wake (to exit/prevent M1/M2)*/ mhi_cntrl->wake_toggle(mhi_cntrl); @@ -1034,6 +1039,9 @@ static int mhi_queue(struct mhi_device *mhi_dev, struct mhi_buf_info *buf_info, if (likely(MHI_DB_ACCESS_VALID(mhi_cntrl))) mhi_ring_chan_db(mhi_cntrl, mhi_chan); + if (dir == DMA_FROM_DEVICE) + mhi_cntrl->runtime_put(mhi_cntrl); + exit_unlock: read_unlock_irqrestore(&mhi_cntrl->pm_lock, flags); @@ -1416,8 +1424,11 @@ static void mhi_reset_data_chan(struct mhi_controller *mhi_cntrl, while (tre_ring->rp != tre_ring->wp) { struct mhi_buf_info *buf_info = buf_ring->rp; - if (mhi_chan->dir == DMA_TO_DEVICE) + if (mhi_chan->dir == DMA_TO_DEVICE) { atomic_dec(&mhi_cntrl->pending_pkts); + /* Release the reference got from mhi_queue() */ + mhi_cntrl->runtime_put(mhi_cntrl); + } if (!buf_info->pre_mapped) mhi_cntrl->unmap_single(mhi_cntrl, buf_info); From patchwork Tue Apr 6 09:11:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 415881 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp4381733jai; Tue, 6 Apr 2021 02:03:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtx+RnSdH5dlg7Y0A+xSosAm6d6IXLpTINguyfmxJhxPJFWrAmhaX2W9N+LsgN6+dnQq9G X-Received: by 2002:a05:6638:dc3:: with SMTP id m3mr27966349jaj.130.1617699817430; Tue, 06 Apr 2021 02:03:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617699817; cv=none; d=google.com; s=arc-20160816; b=xx5giB8Dt2vn+sQb6IjyX5nyjR1E3cJxPV/LqljpuH+wTFTc+HdWPhWHIAzDL4zE52 8B8BRWWhB6d0Vuk5g4hDy8R1dLvY9xyrgkEAOMPMDFSp4xmJU2rcalv0Ysg5FYJcj5aF ymczPhXk5YWDWgDc51/JkSSjyK5lmPp6l+7BP+Iz4U11Y7Mo/CQnT6p1IKlf8Hpuhy8c vWOvDwDFAQf/qJc3BlWuJ7wN7N+cXme4GRdz+wWYbVQIJ1dTQMSGSi0yQfjjvqKBOBVA 04U0vHPch5FAL0AvwcTdZoLmV5sXvDQIoMMnIVLkkq1xTCIPJmIYMTe+hk3ES0kOh6WJ tEyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=2mu2HOwUtFaOtvfYjnCHwk+0pWgHjq01yFoIZqmWRuA=; b=xejNAyKZarFvCxZO8R1+1qQci5uZZ63M8BkbOceSTj+E/Jo+45nMLQPwTouwy5YTbD wXjuWGkpu+YhkKc8pg3zhNHu1Z1sFH4QOJXMRjlNIWoJBg0zt9E7XpaJ8VT8uumN2+tJ boogoBWNyQfG323o6V+tghc7S+qaLWeywFIz2NyZPUpTbP1P5rbvHkFymIAAkWPBYCc6 Kr6YPBo1sQXzJR7wlEfVOIRYGXD0VGlfEaOc78WTwN+uNp78LgpxqUoKjeD0bTUIogx3 wEbHpP6wlZUTFosJw1nmay9AU6oRfprZXbHL5btRnX6n3L6nNN8qqLgrqNWCefVVa28b JF9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CJEeSsz7; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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 w9si18601743jad.47.2021.04.06.02.03.29; Tue, 06 Apr 2021 02:03:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-msm-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=CJEeSsz7; spf=pass (google.com: domain of linux-arm-msm-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-arm-msm-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 S240584AbhDFJD0 (ORCPT + 17 others); Tue, 6 Apr 2021 05:03:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240559AbhDFJD0 (ORCPT ); Tue, 6 Apr 2021 05:03:26 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61AC5C06174A for ; Tue, 6 Apr 2021 02:03:17 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id o6so4021805wmq.3 for ; Tue, 06 Apr 2021 02:03:17 -0700 (PDT) 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; bh=2mu2HOwUtFaOtvfYjnCHwk+0pWgHjq01yFoIZqmWRuA=; b=CJEeSsz7VndEgvx76HxdN9wu727/9fWXtZhtE66+pS2uQ63QLfKQtZORbq6G74NDph w9xoqbGUlCPneWecBTjTDFwbHHkzD/Q21DnD8GYoFyGr5anmjKk99l6CQwTI2z1JNR0u yU3flZXYhlxmMzgSZpa+EOuD8mO7bGTHmtjJgrCnZZ7VuFzUmhLLYgm+5M9XMjW6z+Lf q1KwQPHSw6xW4+9T2/AP7cN45LfCzbJmV6//puQ0rxCM0tY6FFyTXw3n2kE1rJCe1tOb nHNOnebTuOYxlaj+lyopwZ+TerIgzj6WO/KoEIxGqLouqSb4aPmLCbT4Hvq8lc9FHO9T 23iQ== 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; bh=2mu2HOwUtFaOtvfYjnCHwk+0pWgHjq01yFoIZqmWRuA=; b=beoFYYrvsSCxoDuEEFCcWMZVFezkSmprxuxwHOfWM936zQCFl6yg8/xkhhEc8+5xl5 h3T+hTs14x3WoVHDXyNVwa7AopW4QpGEn8XfPMXCwphIhQXrNNB8qrTPBjM2QZStb+QT 0ySS17LTmasXFvsw3lkfxI8hIayj3Jg21IHsHZjbCQ38j4fGiYQjEFHZU+GtVLeQZP06 4gyPY+er7RluSfzHPe21xUJmFbhx9b90kwQ+XOvausglCMdtwN0g969upH3pXbAAYyix hgb71no7m1A/S5y1njqco3f/NAX3jA5HGZktlPiBlJ4xuBPfy9FEG7z7ql+cMjJ8sv6d UEPA== X-Gm-Message-State: AOAM532jXl8NgiKvs6mLlGv8kLrkqeAKIXI3+e7jUTzSoBfuEc1HswU6 gNHvEfCAQUWZrwV10bv7e+mANeY8meW7gEgt X-Received: by 2002:a05:600c:3594:: with SMTP id p20mr2977822wmq.173.1617699796083; Tue, 06 Apr 2021 02:03:16 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:82c:5f0:49e5:d54d:f006:441f]) by smtp.gmail.com with ESMTPSA id r1sm38266233wrj.63.2021.04.06.02.03.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Apr 2021 02:03:15 -0700 (PDT) From: Loic Poulain To: manivannan.sadhasivam@linaro.org, hemantk@codeaurora.org Cc: bbhatt@codeaurora.org, linux-arm-msm@vger.kernel.org, Loic Poulain Subject: [PATCH v2 2/2] bus: mhi: pm: reduce PM state change verbosity Date: Tue, 6 Apr 2021 11:11:55 +0200 Message-Id: <1617700315-12492-2-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1617700315-12492-1-git-send-email-loic.poulain@linaro.org> References: <1617700315-12492-1-git-send-email-loic.poulain@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Since M3 can be entered/exited quite a lot when used for runtime PM, keep the mhi suspend/resume transitions quiet. Signed-off-by: Loic Poulain Reviewed-by: Bhaumik Bhatt --- v2: Coding style, adjust alignment of dev_dbg params drivers/bus/mhi/core/pm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 2.7.4 Reviewed-by: Manivannan Sadhasivam diff --git a/drivers/bus/mhi/core/pm.c b/drivers/bus/mhi/core/pm.c index edd7794..6cbac21 100644 --- a/drivers/bus/mhi/core/pm.c +++ b/drivers/bus/mhi/core/pm.c @@ -858,7 +858,7 @@ int mhi_pm_suspend(struct mhi_controller *mhi_cntrl) return -EBUSY; } - dev_info(dev, "Allowing M3 transition\n"); + dev_dbg(dev, "Allowing M3 transition\n"); new_state = mhi_tryset_pm_state(mhi_cntrl, MHI_PM_M3_ENTER); if (new_state != MHI_PM_M3_ENTER) { write_unlock_irq(&mhi_cntrl->pm_lock); @@ -872,7 +872,7 @@ int mhi_pm_suspend(struct mhi_controller *mhi_cntrl) /* Set MHI to M3 and wait for completion */ mhi_set_mhi_state(mhi_cntrl, MHI_STATE_M3); write_unlock_irq(&mhi_cntrl->pm_lock); - dev_info(dev, "Wait for M3 completion\n"); + dev_dbg(dev, "Wait for M3 completion\n"); ret = wait_event_timeout(mhi_cntrl->state_event, mhi_cntrl->dev_state == MHI_STATE_M3 || @@ -906,9 +906,9 @@ int mhi_pm_resume(struct mhi_controller *mhi_cntrl) enum mhi_pm_state cur_state; int ret; - dev_info(dev, "Entered with PM state: %s, MHI state: %s\n", - to_mhi_pm_state_str(mhi_cntrl->pm_state), - TO_MHI_STATE_STR(mhi_cntrl->dev_state)); + dev_dbg(dev, "Entered with PM state: %s, MHI state: %s\n", + to_mhi_pm_state_str(mhi_cntrl->pm_state), + TO_MHI_STATE_STR(mhi_cntrl->dev_state)); if (mhi_cntrl->pm_state == MHI_PM_DISABLE) return 0;