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 X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 BC714C388F7 for ; Fri, 13 Nov 2020 14:53:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8726E22240 for ; Fri, 13 Nov 2020 14:53:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="eG3fS+qa" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726731AbgKMOxy (ORCPT ); Fri, 13 Nov 2020 09:53:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726701AbgKMOxx (ORCPT ); Fri, 13 Nov 2020 09:53:53 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3538C0617A6 for ; Fri, 13 Nov 2020 06:53:37 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id c16so8728560wmd.2 for ; Fri, 13 Nov 2020 06:53: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; bh=bm260PJoO5H8NK8G6hExam2xqasQcYPyaEgFTuITWiM=; b=eG3fS+qaRoVWJxbodDX3niX7YM3b+pIOQtVgTFrIlPQ10eLeHxGlJE3IK2ptG1xnqD 4f8av3ru5BdWDV1lGhTRsSw8dJqcXzVn/zbo4J2NIWdYZlZVLvF9gvM2Ha1alXHjytCF WX1PFXHqaT7TKU4RWgtJ2sHlV9JV8l+RadVuXxolzzFq8Dr7xJLKjUmen18IF1nPA5B2 wtTFc+ylRfAP3UwOr/V1xYLRsnBekIbvr2kbyKypqVB5M+tbZ90yn5shQQa29ZhSRrSA oB3cBPS6uHpaRj8NtrjhYTnbd3aDW9AIMyLUsnrYEdRxwiniXTzODEbCPrPmt8rH+/6j wqVg== 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=bm260PJoO5H8NK8G6hExam2xqasQcYPyaEgFTuITWiM=; b=nUXV2JK8dHfy4gw4cHJ0t37KXU+gbdbQuifT/JB7vf1yUfNaL2z3aaymdUVxUIuPb/ qKc6pyOjmHzfwwQ5ixAZc8sxmNLkFV/j8lTuJVXQU2cCanGQD179uUpnbxiuDQUmUawW Z5kUXVdBxB7OpNdNiQlSaIK1B8Od+2v1bUB9DeD2fQfr6eAru5gDJLgHwsHsIqfEA4Z6 MsaLLHuVVinlJFSR6o4Bdt0iPAGgscOpXfwwWnv8QO3lTBzap+1ytIbaJ23USjY89IXq ++KHv9s96A4J4xbmiUciEKT14HkQSNYX94jFiVOvaZZXuFSRDVRLQgEO+IXx6/BmJxna S0Ww== X-Gm-Message-State: AOAM531QhIWwSEfmDZLAvDgIBtd0thbOkFJqI38QT8/fNVso4YPPj0cy lkuEoMWVF/83LEtor3ePKV/c2g== X-Google-Smtp-Source: ABdhPJxKabYpNvTIXHWF6IBMu6/Nm7qjt1OHT0ET72N8I0tpJiCoPC0dQKfWTJ2bv4G7vL+8JTCR8A== X-Received: by 2002:a1c:bcc1:: with SMTP id m184mr2861234wmf.132.1605279216356; Fri, 13 Nov 2020 06:53:36 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:490:8730:304f:e9d4:6385:8ac5]) by smtp.gmail.com with ESMTPSA id i6sm10729341wma.42.2020.11.13.06.53.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Nov 2020 06:53:35 -0800 (PST) From: Loic Poulain To: manivannan.sadhasivam@linaro.org, hemantk@codeaurora.org Cc: linux-arm-msm@vger.kernel.org, Loic Poulain Subject: [PATCH 7/8] mhi: pci_generic: Add health-check Date: Fri, 13 Nov 2020 16:00:01 +0100 Message-Id: <1605279602-18749-8-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1605279602-18749-1-git-send-email-loic.poulain@linaro.org> References: <1605279602-18749-1-git-send-email-loic.poulain@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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 --- drivers/bus/mhi/pci_generic.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/bus/mhi/pci_generic.c b/drivers/bus/mhi/pci_generic.c index a7fbba5..6cc7bb9 100644 --- a/drivers/bus/mhi/pci_generic.c +++ b/drivers/bus/mhi/pci_generic.c @@ -14,12 +14,15 @@ #include #include #include +#include #include #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; @@ -429,6 +452,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: @@ -444,6 +470,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)) { @@ -464,6 +491,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); @@ -507,6 +536,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, @@ -567,6 +597,9 @@ 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; + /* Suspend health check */ + del_timer(&mhi_pdev->health_check_timer); + /* Transition to M3 state */ mhi_pm_suspend(mhi_cntrl); @@ -600,6 +633,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