bus: mhi: core: Add support for forced PM resume

For whatever reason, some devices like QCA6390, WCN6855 using ath11k
are not in M3 state during PM resume, but still functional. The
mhi_pm_resume should then not fail in those cases, and let the higher
level device specific stack continue resuming process.

Add an API mhi_pm_resume_force(), to force resuming irrespective of the
current MHI state. This fixes a regression with non functional ath11k WiFi
after suspend/resume cycle on some machines.

Bug report: https://bugzilla.kernel.org/show_bug.cgi?id=214179

Link: https://lore.kernel.org/regressions/871r5p0x2u.fsf@codeaurora.org/
Fixes: 020d3b26c07a ("bus: mhi: Early MHI resume failure in non M3 state")
Cc: stable@vger.kernel.org #5.13
Reported-by: Kalle Valo <kvalo@codeaurora.org>
Reported-by: Pengyu Ma <mapengyu@gmail.com>
Tested-by: Kalle Valo <kvalo@kernel.org>
Acked-by: Kalle Valo <kvalo@kernel.org>
Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
[mani: Switched to API, added bug report, reported-by tags and CCed stable]
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Link: https://lore.kernel.org/r/20211209131633.4168-1-manivannan.sadhasivam@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by Loic Poulain and committed by Greg Kroah-Hartman cab2d3fd 7c602f5d

Changed files
+36 -4
drivers
bus
mhi
core
net
wireless
ath
ath11k
include
linux
+18 -3
drivers/bus/mhi/core/pm.c
··· 881 881 } 882 882 EXPORT_SYMBOL_GPL(mhi_pm_suspend); 883 883 884 - int mhi_pm_resume(struct mhi_controller *mhi_cntrl) 884 + static int __mhi_pm_resume(struct mhi_controller *mhi_cntrl, bool force) 885 885 { 886 886 struct mhi_chan *itr, *tmp; 887 887 struct device *dev = &mhi_cntrl->mhi_dev->dev; ··· 898 898 if (MHI_PM_IN_ERROR_STATE(mhi_cntrl->pm_state)) 899 899 return -EIO; 900 900 901 - if (mhi_get_mhi_state(mhi_cntrl) != MHI_STATE_M3) 902 - return -EINVAL; 901 + if (mhi_get_mhi_state(mhi_cntrl) != MHI_STATE_M3) { 902 + dev_warn(dev, "Resuming from non M3 state (%s)\n", 903 + TO_MHI_STATE_STR(mhi_get_mhi_state(mhi_cntrl))); 904 + if (!force) 905 + return -EINVAL; 906 + } 903 907 904 908 /* Notify clients about exiting LPM */ 905 909 list_for_each_entry_safe(itr, tmp, &mhi_cntrl->lpm_chans, node) { ··· 944 940 945 941 return 0; 946 942 } 943 + 944 + int mhi_pm_resume(struct mhi_controller *mhi_cntrl) 945 + { 946 + return __mhi_pm_resume(mhi_cntrl, false); 947 + } 947 948 EXPORT_SYMBOL_GPL(mhi_pm_resume); 949 + 950 + int mhi_pm_resume_force(struct mhi_controller *mhi_cntrl) 951 + { 952 + return __mhi_pm_resume(mhi_cntrl, true); 953 + } 954 + EXPORT_SYMBOL_GPL(mhi_pm_resume_force); 948 955 949 956 int __mhi_device_get_sync(struct mhi_controller *mhi_cntrl) 950 957 {
+5 -1
drivers/net/wireless/ath/ath11k/mhi.c
··· 533 533 ret = mhi_pm_suspend(ab_pci->mhi_ctrl); 534 534 break; 535 535 case ATH11K_MHI_RESUME: 536 - ret = mhi_pm_resume(ab_pci->mhi_ctrl); 536 + /* Do force MHI resume as some devices like QCA6390, WCN6855 537 + * are not in M3 state but they are functional. So just ignore 538 + * the MHI state while resuming. 539 + */ 540 + ret = mhi_pm_resume_force(ab_pci->mhi_ctrl); 537 541 break; 538 542 case ATH11K_MHI_TRIGGER_RDDM: 539 543 ret = mhi_force_rddm_mode(ab_pci->mhi_ctrl);
+13
include/linux/mhi.h
··· 664 664 int mhi_pm_resume(struct mhi_controller *mhi_cntrl); 665 665 666 666 /** 667 + * mhi_pm_resume_force - Force resume MHI from suspended state 668 + * @mhi_cntrl: MHI controller 669 + * 670 + * Resume the device irrespective of its MHI state. As per the MHI spec, devices 671 + * has to be in M3 state during resume. But some devices seem to be in a 672 + * different MHI state other than M3 but they continue working fine if allowed. 673 + * This API is intented to be used for such devices. 674 + * 675 + * Return: 0 if the resume succeeds, a negative error code otherwise 676 + */ 677 + int mhi_pm_resume_force(struct mhi_controller *mhi_cntrl); 678 + 679 + /** 667 680 * mhi_download_rddm_image - Download ramdump image from device for 668 681 * debugging purpose. 669 682 * @mhi_cntrl: MHI controller