From: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
To: Loic Poulain <loic.poulain@linaro.org>
Cc: hemantk@codeaurora.org, linux-arm-msm@vger.kernel.org,
bbhatt@codeaurora.org
Subject: Re: [PATCH v3 8/9] mhi: pci_generic: Add health-check
Date: Sat, 28 Nov 2020 11:29:36 +0530 [thread overview]
Message-ID: <20201128055936.GF3077@thinkpad> (raw)
In-Reply-To: <1606404547-10737-9-git-send-email-loic.poulain@linaro.org>
On Thu, Nov 26, 2020 at 04:29:06PM +0100, Loic Poulain wrote:
> If the modem crashes for any reason, we may not be able to detect
> it at MHI level (MHI registers not reachable anymore).
>
> This patch implements a health-check mechanism to check regularly
> that device is alive (MHI layer can communicate with). If device
> is not alive (because a crash or unexpected reset), the recovery
> procedure is triggered.
>
> Tested successfully with Telit FN980m module.
>
> Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Bhaumik, Hemant, does this looks reasonable to you? Or we can do a
better job in the MHI stack. To me this is not a specific usecase for
Telit.
If you guys plan to implement it later, I can just apply this patch in
the meantime as it looks good to me.
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Thanks,
Mani
> ---
> drivers/bus/mhi/pci_generic.c | 34 ++++++++++++++++++++++++++++++++++
> 1 file changed, 34 insertions(+)
>
> diff --git a/drivers/bus/mhi/pci_generic.c b/drivers/bus/mhi/pci_generic.c
> index 3ac5cd2..26c2dfa 100644
> --- a/drivers/bus/mhi/pci_generic.c
> +++ b/drivers/bus/mhi/pci_generic.c
> @@ -14,12 +14,15 @@
> #include <linux/mhi.h>
> #include <linux/module.h>
> #include <linux/pci.h>
> +#include <linux/timer.h>
> #include <linux/workqueue.h>
>
> #define MHI_PCI_DEFAULT_BAR_NUM 0
>
> #define DEV_RESET_REG (0xB0)
>
> +#define HEALTH_CHECK_PERIOD (HZ * 5)
> +
> /**
> * struct mhi_pci_dev_info - MHI PCI device specific information
> * @config: MHI controller configuration
> @@ -190,6 +193,7 @@ struct mhi_pci_device {
> struct mhi_controller mhi_cntrl;
> struct pci_saved_state *pci_state;
> struct work_struct recovery_work;
> + struct timer_list health_check_timer;
> unsigned long status;
> };
>
> @@ -332,6 +336,8 @@ static void mhi_pci_recovery_work(struct work_struct *work)
>
> dev_warn(&pdev->dev, "device recovery started\n");
>
> + del_timer(&mhi_pdev->health_check_timer);
> +
> /* Clean up MHI state */
> if (test_and_clear_bit(MHI_PCI_DEV_STARTED, &mhi_pdev->status)) {
> mhi_power_down(mhi_cntrl, false);
> @@ -355,6 +361,7 @@ static void mhi_pci_recovery_work(struct work_struct *work)
> goto err_unprepare;
>
> set_bit(MHI_PCI_DEV_STARTED, &mhi_pdev->status);
> + mod_timer(&mhi_pdev->health_check_timer, jiffies + HEALTH_CHECK_PERIOD);
> return;
>
> err_unprepare:
> @@ -364,6 +371,21 @@ static void mhi_pci_recovery_work(struct work_struct *work)
> dev_err(&pdev->dev, "Recovery failed\n");
> }
>
> +static void health_check(struct timer_list *t)
> +{
> + struct mhi_pci_device *mhi_pdev = from_timer(mhi_pdev, t, health_check_timer);
> + struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl;
> +
> + if (!mhi_pci_is_alive(mhi_cntrl)) {
> + dev_err(mhi_cntrl->cntrl_dev, "Device died\n");
> + queue_work(system_long_wq, &mhi_pdev->recovery_work);
> + return;
> + }
> +
> + /* reschedule in two seconds */
> + mod_timer(&mhi_pdev->health_check_timer, jiffies + HEALTH_CHECK_PERIOD);
> +}
> +
> static int mhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> {
> const struct mhi_pci_dev_info *info = (struct mhi_pci_dev_info *) id->driver_data;
> @@ -379,6 +401,7 @@ static int mhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> return -ENOMEM;
>
> INIT_WORK(&mhi_pdev->recovery_work, mhi_pci_recovery_work);
> + timer_setup(&mhi_pdev->health_check_timer, health_check, 0);
>
> mhi_cntrl_config = info->config;
> mhi_cntrl = &mhi_pdev->mhi_cntrl;
> @@ -431,6 +454,9 @@ static int mhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>
> set_bit(MHI_PCI_DEV_STARTED, &mhi_pdev->status);
>
> + /* start health check */
> + mod_timer(&mhi_pdev->health_check_timer, jiffies + HEALTH_CHECK_PERIOD);
> +
> return 0;
>
> err_unprepare:
> @@ -446,6 +472,7 @@ static void mhi_pci_remove(struct pci_dev *pdev)
> struct mhi_pci_device *mhi_pdev = pci_get_drvdata(pdev);
> struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl;
>
> + del_timer(&mhi_pdev->health_check_timer);
> cancel_work_sync(&mhi_pdev->recovery_work);
>
> if (test_and_clear_bit(MHI_PCI_DEV_STARTED, &mhi_pdev->status)) {
> @@ -466,6 +493,8 @@ void mhi_pci_reset_prepare(struct pci_dev *pdev)
>
> dev_info(&pdev->dev, "reset\n");
>
> + del_timer(&mhi_pdev->health_check_timer);
> +
> /* Clean up MHI state */
> if (test_and_clear_bit(MHI_PCI_DEV_STARTED, &mhi_pdev->status)) {
> mhi_power_down(mhi_cntrl, false);
> @@ -509,6 +538,7 @@ void mhi_pci_reset_done(struct pci_dev *pdev)
> }
>
> set_bit(MHI_PCI_DEV_STARTED, &mhi_pdev->status);
> + mod_timer(&mhi_pdev->health_check_timer, jiffies + HEALTH_CHECK_PERIOD);
> }
>
> static pci_ers_result_t mhi_pci_error_detected(struct pci_dev *pdev,
> @@ -569,6 +599,7 @@ int __maybe_unused mhi_pci_suspend(struct device *dev)
> struct mhi_pci_device *mhi_pdev = dev_get_drvdata(dev);
> struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl;
>
> + del_timer(&mhi_pdev->health_check_timer);
> cancel_work_sync(&mhi_pdev->recovery_work);
>
> /* Transition to M3 state */
> @@ -604,6 +635,9 @@ static int __maybe_unused mhi_pci_resume(struct device *dev)
> goto err_recovery;
> }
>
> + /* Resume health check */
> + mod_timer(&mhi_pdev->health_check_timer, jiffies + HEALTH_CHECK_PERIOD);
> +
> return 0;
>
> err_recovery:
> --
> 2.7.4
>
next prev parent reply other threads:[~2020-11-28 22:14 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-26 15:28 [PATCH v3 0/9] mhi: pci_generic: Misc improvements Loic Poulain
2020-11-26 15:28 ` [PATCH v3 1/9] mhi: Add mhi_controller_initialize helper Loic Poulain
2020-11-28 5:42 ` Manivannan Sadhasivam
2020-12-02 1:41 ` Bhaumik Bhatt
2020-11-26 15:29 ` [PATCH v3 2/9] mhi: pci-generic: Increase number of hardware events Loic Poulain
2020-11-28 5:44 ` Manivannan Sadhasivam
2020-11-26 15:29 ` [PATCH v3 3/9] mhi: pci-generic: Perform hard reset on remove Loic Poulain
2020-11-27 17:34 ` Jeffrey Hugo
2020-11-27 17:40 ` Jeffrey Hugo
2020-11-26 15:29 ` [PATCH v3 4/9] mhi: pci_generic: Enable burst mode for hardware channels Loic Poulain
2020-11-28 5:45 ` Manivannan Sadhasivam
2020-11-26 15:29 ` [PATCH v3 5/9] mhi: pci_generic: Add support for reset Loic Poulain
2020-11-28 5:49 ` Manivannan Sadhasivam
2020-11-30 9:08 ` Loic Poulain
2020-12-02 1:24 ` Bhaumik Bhatt
2020-12-07 14:05 ` Loic Poulain
2020-11-26 15:29 ` [PATCH v3 6/9] mhi: pci_generic: Add suspend/resume/recovery procedure Loic Poulain
2020-11-26 15:29 ` [PATCH v3 7/9] mhi: pci_generic: Add PCI error handlers Loic Poulain
2020-11-26 15:29 ` [PATCH v3 8/9] mhi: pci_generic: Add health-check Loic Poulain
2020-11-28 5:59 ` Manivannan Sadhasivam [this message]
2020-12-01 0:59 ` Hemant Kumar
2020-12-01 1:02 ` Hemant Kumar
2020-11-26 15:29 ` [PATCH v3 9/9] mhi: pci_generic: Increase controller timeout value Loic Poulain
2020-11-28 5:51 ` Manivannan Sadhasivam
2020-11-28 6:00 ` [PATCH v3 0/9] mhi: pci_generic: Misc improvements Manivannan Sadhasivam
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201128055936.GF3077@thinkpad \
--to=manivannan.sadhasivam@linaro.org \
--cc=bbhatt@codeaurora.org \
--cc=hemantk@codeaurora.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=loic.poulain@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).