From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E1341CD1292 for ; Mon, 1 Apr 2024 12:10:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=tKCS9QdnAwWbuZtYBI4sT1iLB4Tt93btjF36mrIzaXY=; b=IpNtCbFKFUv/X8rUmYTvaV8xtW SRKmHO1W4tb6J7oXP2okubqmjDFDFIXWROtJspdXwC5WMUE46g6vjGTi7ACPU8Uiw2bQbLaUOnxgQ TJ/tzF6VleEmNNjpDoK0wYHUR7+eU2cFUDWtY9yFb5Fjta9q3urm/nNhhDGIKX9q1KiwXG415q47H FRokcvdgU7st2qEHjLJ+QMMY3RRTbyaPdruIEhTy/wWUsrtqcHYcAx1MPBFQF1Iu28SQ/8epOLrrw Y8xEkT7IrghDPfYPW94eFVv59clyObmaOS9hRcyR4vIt/XtpJ1oiDGHYcIqzeTFJ5bq9LaJHT/EGf 8O9Ypb0Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrGUy-00000007de8-0TjE; Mon, 01 Apr 2024 12:10:48 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrFGy-00000007V3O-1MS2 for ath11k@lists.infradead.org; Mon, 01 Apr 2024 10:52:19 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1e0bec01232so29555785ad.3 for ; Mon, 01 Apr 2024 03:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711968553; x=1712573353; darn=lists.infradead.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=tKCS9QdnAwWbuZtYBI4sT1iLB4Tt93btjF36mrIzaXY=; b=JbqwI8vsjnwLRJ+XaNVrEHhDgWBVZDc6pr5g62GpM09IEsVK/JEByMopoD7WXckjdR ytXFlCHYX9kcosPn2SxGtXadE66q97cOm8kzya4db8XHtebmmR0J39wdRFEG9Sbz0IQD nPiIAYjt8g3z+bhgZPJV0N5zq0EOF4hoCQ+qdZitS2IhYzuJ3nbczcH2185+jVIBPvc8 H9Es9gGcXyg5G5BmMjFMYtql9NWOugYFDiY8XDmpYnzZSUlqwjaE1l1kcSt6/bexjPIN 1Eh7dkVF6oTnyH/EahtiF//n8OUq3kNepMDlmAaInO/dii6y0cFI1qwf2HC4Hh34ofnT f+QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711968553; x=1712573353; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tKCS9QdnAwWbuZtYBI4sT1iLB4Tt93btjF36mrIzaXY=; b=Y/6lkKutwGKyPrLvzYMvMUu48f59LTkq8L9a2sLCDWa7/Gf87kIEXYAkLnR9O09zeR aU4/Vmf1TOq8huBWOqnEtbhbE7iznrSKfAq3whpeViEZ/hx8fj1/V4mp3waDYJsRQLod ngwwIa3QjQ9Rg4uKKvUhH/QK5YpTJGA6RyqGyCLPmFLmHJKmiTlnAlxi1cOU4LnOEKji p56WJQpeL5HVdXnxxGtfbp13wYW1pFTkeHApMi5HsAu/r88RURSU8xnCLSlDhqsb/+E6 1CeXcJ5PNfoAzGdS5KuafzYi+6l0HNMRI00s0NtVEdoaJlY6G4HnfV+wvCR5pJbFgYPn g3dA== X-Gm-Message-State: AOJu0YzWH6htML/6ca8ad+K9Xzzjjtp0KiBI9TCsgDsV/4CDTUfPwTBa yGNdYnzhKHFq9MpoPEN0xHVLOcst91FrCGfsor2v+mu0utixuGqMPzoSle3JKw== X-Google-Smtp-Source: AGHT+IFF770fgs+yMHKwTIlLL3P039OFnIkWdfZJY4CvGxJUM7y7krgfn19E1tYKv8Gdk6uxTqFDKA== X-Received: by 2002:a17:902:e802:b0:1e0:b862:5330 with SMTP id u2-20020a170902e80200b001e0b8625330mr10121788plg.54.1711968553329; Mon, 01 Apr 2024 03:49:13 -0700 (PDT) Received: from thinkpad ([103.28.246.102]) by smtp.gmail.com with ESMTPSA id u1-20020a170902e5c100b001e0b5eee802sm8552693plf.123.2024.04.01.03.49.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 03:49:12 -0700 (PDT) Date: Mon, 1 Apr 2024 16:19:08 +0530 From: Manivannan Sadhasivam To: Baochen Qiang Cc: ath11k@lists.infradead.org, linux-wireless@vger.kernel.org, linux-arm-msm@vger.kernel.org, mhi@lists.linux.dev, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org Subject: Re: [PATCH v7 1/3] bus: mhi: host: add mhi_power_down_keep_dev() Message-ID: <20240401104908.GA234427@thinkpad> References: <20240305021320.3367-1-quic_bqiang@quicinc.com> <20240305021320.3367-2-quic_bqiang@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240305021320.3367-2-quic_bqiang@quicinc.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240401_035216_721006_A8767336 X-CRM114-Status: GOOD ( 36.63 ) X-BeenThere: ath11k@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "ath11k" Errors-To: ath11k-bounces+ath11k=archiver.kernel.org@lists.infradead.org On Tue, Mar 05, 2024 at 10:13:18AM +0800, Baochen Qiang wrote: > ath11k fails to resume: > > ath11k_pci 0000:06:00.0: timeout while waiting for restart complete > > This happens because when calling mhi_sync_power_up() the MHI subsystem > eventually calls device_add() from mhi_create_devices() but the device > creation is deferred: > > mhi mhi0_IPCR: Driver qcom_mhi_qrtr force probe deferral > > The reason for deferring device creation is explained in dpm_prepare(): > > /* > * It is unsafe if probing of devices will happen during suspend or > * hibernation and system behavior will be unpredictable in this case. > * So, let's prohibit device's probing here and defer their probes > * instead. The normal behavior will be restored in dpm_complete(). > */ > > Because the device probe is deferred, the qcom_mhi_qrtr_probe() is not > called and thus MHI channels are not prepared: > > So what this means that QRTR is not delivering messages and the QMI connection > is not working between ath11k and the firmware, resulting a failure in firmware > initialization. > > To fix this add new function mhi_power_down_keep_dev() which doesn't destroy > the devices for channels during power down. This way we avoid probe defer issue > and finally can get ath11k hibernation working with the following patches. > > Tested-on: WCN6855 hw2.0 PCI WLAN.HSP.1.1-03125-QCAHSPSWPL_V1_V2_SILICONZ_LITE-3.6510.30 > > Signed-off-by: Baochen Qiang Applied to mhi-next! Note that this patch is also available in mhi-immutable branch for ath11k maintainers to pull into their tree. https://git.kernel.org/pub/scm/linux/kernel/git/mani/mhi.git/log/?h=mhi-immutable - Mani > Reviewed-by: Manivannan Sadhasivam > Reviewed-by: Jeff Johnson > --- > drivers/bus/mhi/host/internal.h | 4 +++- > drivers/bus/mhi/host/pm.c | 42 ++++++++++++++++++++++++++++----- > include/linux/mhi.h | 18 +++++++++++++- > 3 files changed, 56 insertions(+), 8 deletions(-) > > diff --git a/drivers/bus/mhi/host/internal.h b/drivers/bus/mhi/host/internal.h > index 5fe49311b8eb..aaad40a07f69 100644 > --- a/drivers/bus/mhi/host/internal.h > +++ b/drivers/bus/mhi/host/internal.h > @@ -80,6 +80,7 @@ enum dev_st_transition { > DEV_ST_TRANSITION_FP, > DEV_ST_TRANSITION_SYS_ERR, > DEV_ST_TRANSITION_DISABLE, > + DEV_ST_TRANSITION_DISABLE_DESTROY_DEVICE, > DEV_ST_TRANSITION_MAX, > }; > > @@ -90,7 +91,8 @@ enum dev_st_transition { > dev_st_trans(MISSION_MODE, "MISSION MODE") \ > dev_st_trans(FP, "FLASH PROGRAMMER") \ > dev_st_trans(SYS_ERR, "SYS ERROR") \ > - dev_st_trans_end(DISABLE, "DISABLE") > + dev_st_trans(DISABLE, "DISABLE") \ > + dev_st_trans_end(DISABLE_DESTROY_DEVICE, "DISABLE (DESTROY DEVICE)") > > extern const char * const dev_state_tran_str[DEV_ST_TRANSITION_MAX]; > #define TO_DEV_STATE_TRANS_STR(state) (((state) >= DEV_ST_TRANSITION_MAX) ? \ > diff --git a/drivers/bus/mhi/host/pm.c b/drivers/bus/mhi/host/pm.c > index 8b40d3f01acc..11c0e751f223 100644 > --- a/drivers/bus/mhi/host/pm.c > +++ b/drivers/bus/mhi/host/pm.c > @@ -468,7 +468,8 @@ static int mhi_pm_mission_mode_transition(struct mhi_controller *mhi_cntrl) > } > > /* Handle shutdown transitions */ > -static void mhi_pm_disable_transition(struct mhi_controller *mhi_cntrl) > +static void mhi_pm_disable_transition(struct mhi_controller *mhi_cntrl, > + bool destroy_device) > { > enum mhi_pm_state cur_state; > struct mhi_event *mhi_event; > @@ -530,8 +531,16 @@ static void mhi_pm_disable_transition(struct mhi_controller *mhi_cntrl) > dev_dbg(dev, "Waiting for all pending threads to complete\n"); > wake_up_all(&mhi_cntrl->state_event); > > - dev_dbg(dev, "Reset all active channels and remove MHI devices\n"); > - device_for_each_child(&mhi_cntrl->mhi_dev->dev, NULL, mhi_destroy_device); > + /* > + * Only destroy the 'struct device' for channels if indicated by the > + * 'destroy_device' flag. Because, during system suspend or hibernation > + * state, there is no need to destroy the 'struct device' as the endpoint > + * device would still be physically attached to the machine. > + */ > + if (destroy_device) { > + dev_dbg(dev, "Reset all active channels and remove MHI devices\n"); > + device_for_each_child(&mhi_cntrl->mhi_dev->dev, NULL, mhi_destroy_device); > + } > > mutex_lock(&mhi_cntrl->pm_mutex); > > @@ -821,7 +830,10 @@ void mhi_pm_st_worker(struct work_struct *work) > mhi_pm_sys_error_transition(mhi_cntrl); > break; > case DEV_ST_TRANSITION_DISABLE: > - mhi_pm_disable_transition(mhi_cntrl); > + mhi_pm_disable_transition(mhi_cntrl, false); > + break; > + case DEV_ST_TRANSITION_DISABLE_DESTROY_DEVICE: > + mhi_pm_disable_transition(mhi_cntrl, true); > break; > default: > break; > @@ -1175,7 +1187,8 @@ int mhi_async_power_up(struct mhi_controller *mhi_cntrl) > } > EXPORT_SYMBOL_GPL(mhi_async_power_up); > > -void mhi_power_down(struct mhi_controller *mhi_cntrl, bool graceful) > +static void __mhi_power_down(struct mhi_controller *mhi_cntrl, bool graceful, > + bool destroy_device) > { > enum mhi_pm_state cur_state, transition_state; > struct device *dev = &mhi_cntrl->mhi_dev->dev; > @@ -1211,15 +1224,32 @@ void mhi_power_down(struct mhi_controller *mhi_cntrl, bool graceful) > write_unlock_irq(&mhi_cntrl->pm_lock); > mutex_unlock(&mhi_cntrl->pm_mutex); > > - mhi_queue_state_transition(mhi_cntrl, DEV_ST_TRANSITION_DISABLE); > + if (destroy_device) > + mhi_queue_state_transition(mhi_cntrl, > + DEV_ST_TRANSITION_DISABLE_DESTROY_DEVICE); > + else > + mhi_queue_state_transition(mhi_cntrl, > + DEV_ST_TRANSITION_DISABLE); > > /* Wait for shutdown to complete */ > flush_work(&mhi_cntrl->st_worker); > > disable_irq(mhi_cntrl->irq[0]); > } > + > +void mhi_power_down(struct mhi_controller *mhi_cntrl, bool graceful) > +{ > + __mhi_power_down(mhi_cntrl, graceful, true); > +} > EXPORT_SYMBOL_GPL(mhi_power_down); > > +void mhi_power_down_keep_dev(struct mhi_controller *mhi_cntrl, > + bool graceful) > +{ > + __mhi_power_down(mhi_cntrl, graceful, false); > +} > +EXPORT_SYMBOL_GPL(mhi_power_down_keep_dev); > + > int mhi_sync_power_up(struct mhi_controller *mhi_cntrl) > { > int ret = mhi_async_power_up(mhi_cntrl); > diff --git a/include/linux/mhi.h b/include/linux/mhi.h > index 77b8c0a26674..cde01e133a1b 100644 > --- a/include/linux/mhi.h > +++ b/include/linux/mhi.h > @@ -630,12 +630,28 @@ int mhi_async_power_up(struct mhi_controller *mhi_cntrl); > int mhi_sync_power_up(struct mhi_controller *mhi_cntrl); > > /** > - * mhi_power_down - Start MHI power down sequence > + * mhi_power_down - Power down the MHI device and also destroy the > + * 'struct device' for the channels associated with it. > + * See also mhi_power_down_keep_dev() which is a variant > + * of this API that keeps the 'struct device' for channels > + * (useful during suspend/hibernation). > * @mhi_cntrl: MHI controller > * @graceful: Link is still accessible, so do a graceful shutdown process > */ > void mhi_power_down(struct mhi_controller *mhi_cntrl, bool graceful); > > +/** > + * mhi_power_down_keep_dev - Power down the MHI device but keep the 'struct > + * device' for the channels associated with it. > + * This is a variant of 'mhi_power_down()' and > + * useful in scenarios such as suspend/hibernation > + * where destroying of the 'struct device' is not > + * needed. > + * @mhi_cntrl: MHI controller > + * @graceful: Link is still accessible, so do a graceful shutdown process > + */ > +void mhi_power_down_keep_dev(struct mhi_controller *mhi_cntrl, bool graceful); > + > /** > * mhi_unprepare_after_power_down - Free any allocated memory after power down > * @mhi_cntrl: MHI controller > -- > 2.25.1 > -- மணிவண்ணன் சதாசிவம்