From patchwork Fri Nov 13 15:00:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 324332 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp1262450ils; Fri, 13 Nov 2020 06:54:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDktPUZmuQ5Sf4QLwEbE5nnHKJGLKbCQ0r//4Le5D+jUEXA6XlTwNMWSW8VDzLirC//yfr X-Received: by 2002:a17:906:6949:: with SMTP id c9mr2223745ejs.482.1605279240434; Fri, 13 Nov 2020 06:54:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605279240; cv=none; d=google.com; s=arc-20160816; b=MsrlMBFYgeMRKjjZClXpLFIAucoGYd+ehEFV81J3Rj5xb+84AkommRXquuH/pQsF4d ZdrGa/+0cVR+QMwHc43K0rAFC3R2FLGxh32vDpD/4PYO8wC771rZPL8XlTGp30NAmp1y 0KE8hAkRT2qQsPea1TfByvvdtqPB1mfW/mByNKDxk4H6o3bD8KCH6zf7umeiIneVpR7J 6bEY2lW8X/c6EHRDdTFtCtJ24ka41FqpmpBxzWplrCO3bvucJhpT+A62ZVu+ouXSVQ/Z PHsraB1KcEFF+fnFi/S8UUyMPlS1wN3f2vBPpSRaPuqn4wv91rVZxJm0JkYkPR1R93WA xAjQ== 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=bm260PJoO5H8NK8G6hExam2xqasQcYPyaEgFTuITWiM=; b=xzdn6TcQNKDhYjpxADzDXeAzeFfXbfSeX5aJvcubDrirgNw2Zh060QKt0liwtg8ioY yoDzOATq1UI9jGxwjivK2apMBv8kG6nFvtf6OmG/vRm5edEEupZxkpnFaLB/IMVjZg8w QJmo7aDUzAWceqJtSFOU//dQkTqUihUrM3d/cC5v8q7urNrp1A1T0FQdEqWF20vCVpGf kMx6VxzVL+4f/lRXMz1Z8GB1pDobpJqCCI2Wq3HtnxknnF4ImFmXo3egZggkZiLeaykm reV2fm1W9nbYbglWGhi3jJaDY0U6rrGc+Q9v5+yJFatOEx4VgIcgljtF0PpyhzsI6X3p IqZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eG3fS+qa; 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 y7si5841525ejd.450.2020.11.13.06.54.00; Fri, 13 Nov 2020 06:54:00 -0800 (PST) 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=eG3fS+qa; 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 S1726731AbgKMOxy (ORCPT + 15 others); 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-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(+) -- 2.7.4 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: