From patchwork Thu Nov 26 15:29:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 333032 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp1402542ilb; Thu, 26 Nov 2020 07:22:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJyViP2Ud4rXKDCG4mCN5pph6UtpDj2otkVjm/L33RBfjAx3Pcop20+Yhex+AwvnMqiUV+lR X-Received: by 2002:a17:906:af0a:: with SMTP id lx10mr3139968ejb.75.1606404177031; Thu, 26 Nov 2020 07:22:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606404177; cv=none; d=google.com; s=arc-20160816; b=qKQVbI2rg2v7txiLtG7Wng2Kh3Bn7iUrCFSqd9pIJpXt2udEtv4GCiFKGIV6O5NAOW 1JtFJJ7KyY9gXRT2xMTTdJuF/XqqIwM1NCTqDq4Ep+zi0QpzcqoKygDv8ky/nLYkVrkU vJtCMZuBf7KKxsF6CLCC172Jgyv8W0U29TlMzPoswXN9k6SvZGYnnloXfI9V8Y7aIYBN j8Wm3KvjTEdb9NaTy+FpwqodCmlr8oRDPrV5PRxH2T7dbckDaEp/qY3GArpwA+kr1Xom hm4+x76gJ4YjE/wqgn5Q1B+BdPNAEhVBBz5Pwm+OqvqVw++KJ19G5oqANoeoRZPycS77 dc0Q== 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=T9NdeCY8lnXyB3TYArwpP2Vm2Myt8lw3Dn2sdkapntA=; b=Ha93qutqaslWs1S+69+Py0Muwe+3AduFVwDCn+Qtwl/VNJclzQfn3JUFAHm4yFubX4 yZyAabE4cC4zWXBYe803glAikXVSMhzXmaPgRIRbleW60fI4oq7N08G+56SPzlJbGG6h prM2jM7Nbg/NuFqa6rSFlAopABrgENqwUBsc3iHK0iLeAZ64Tb4gR9V5O6h7nUUUD0BX F8LdvZvU9XEg2/0TP+VTDAab4C1p8Zxv4bVetKLNRbC/u3sGlk/Riu56/9rdOTC6uAUz IbCjald6szpEWHP0ZyIA2MMc1rcBB49pr2pKHuRrA/yeB1T8hHt5qWYn+fP/1JgSfMvu xaug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a5rhygAQ; 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 w10si3453177edx.350.2020.11.26.07.22.56; Thu, 26 Nov 2020 07:22:57 -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=a5rhygAQ; 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 S2391261AbgKZPW0 (ORCPT + 15 others); Thu, 26 Nov 2020 10:22:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391314AbgKZPWZ (ORCPT ); Thu, 26 Nov 2020 10:22:25 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E512C0613D4 for ; Thu, 26 Nov 2020 07:22:24 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id g14so2495286wrm.13 for ; Thu, 26 Nov 2020 07:22:23 -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=T9NdeCY8lnXyB3TYArwpP2Vm2Myt8lw3Dn2sdkapntA=; b=a5rhygAQ31gr+pcb9zgfWoQQfi6406vqyZKupj4U2kYr7ELRyjqTbg4wL0gb8fwl9C FlWQVTlXWEfM7mQwV9Qsm8qOpJBARWG5H07FUm6QLw7pJ2I64jvpgfWhqQ/Yo96GqJhR IXjRU157qlTHwyH5ZViBGNTCxgq3nHPh0cErqjmRiGgvoY0eUQkGM+qeKxh2WwuBLyyZ M6gTnX//vJcv8Ngzm95GisKW1aUch+21jWnIOCAZMuVwEjLLchJzySZqDNACSdnlGHh2 TFsIDdIlxz9VoNz+gEKKTVy0bM5ZrJZQjsys7j+562ndjc3I12tBVouHFnmyqryf1S2Z EuZQ== 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=T9NdeCY8lnXyB3TYArwpP2Vm2Myt8lw3Dn2sdkapntA=; b=DgbTGBZcdlRJjwUKXqdLDIOGdIt10IbpV5RYekbwYQZe0ClnSBa21cV9ItH6uKT2Ao cUrmdxh6Up3FvX80g0HWo9K7yCIZryd8TLjjifFcS2dUfWYxzD8Us7WRmhGraLEYGAUh cCexkgK/JKg6lkZYfRXlX3+3XFIM0AIUwdypPjE8+8IMqKOKrA6KUHAPSsPnRH29kxip TzndIpi8dI/0ZbCNE/UtU6Afgh5+bSZxhWdIuY/tGiUavV7/NttW5gkWLemY7FcuvLQ9 w+/uYhf8rwuBZk6wHsuXa2ww+GfZdhbgdey08mbFGrVbArYVnNbbZeVHijnpo14fZ6iN PwcA== X-Gm-Message-State: AOAM532z23yC5eW1lHHHxnNPqugOFUKaFGrVaz2GJUK+rSrn1ttRZEzV kVlceGu3miMhZBNjzJPj2eh+bA== X-Received: by 2002:adf:9144:: with SMTP id j62mr4422501wrj.419.1606404142755; Thu, 26 Nov 2020 07:22:22 -0800 (PST) Received: from localhost.localdomain ([88.122.66.28]) by smtp.gmail.com with ESMTPSA id l10sm2756144wme.42.2020.11.26.07.22.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Nov 2020 07:22:22 -0800 (PST) From: Loic Poulain To: manivannan.sadhasivam@linaro.org, hemantk@codeaurora.org Cc: linux-arm-msm@vger.kernel.org, bbhatt@codeaurora.org, Loic Poulain Subject: [PATCH v3 8/9] mhi: pci_generic: Add health-check Date: Thu, 26 Nov 2020 16:29:06 +0100 Message-Id: <1606404547-10737-9-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1606404547-10737-1-git-send-email-loic.poulain@linaro.org> References: <1606404547-10737-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 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) -- 2.7.4 Reviewed-by: Manivannan Sadhasivam Reviewed-by: Hemant Kumar 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 #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; @@ -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: