From patchwork Thu Nov 26 15:29:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 333030 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp1402527ilb; Thu, 26 Nov 2020 07:22:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJxY2fuNJra+lglvbu3CGJmN7evR/9g1mgAf7k+cz8Xi/jANBw3hCqqPQw5iIbuuITBcaB5O X-Received: by 2002:a17:906:6d8e:: with SMTP id h14mr3238229ejt.522.1606404176127; Thu, 26 Nov 2020 07:22:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606404176; cv=none; d=google.com; s=arc-20160816; b=RuN/FtN4uf3VgnWF2ZG06Ktn9OP5LtVRgzuVodxh5QR8b8NuH8dPrKd3q/iHzfLYeA UkgI2FQbGBKMMncub4+qYhsak766An4m2Lz/5TImbmrzjTZ1B6Rdymxgj9wlOaUGhEb0 7hkAz60IYTHWLuHA1QQ5do32Kv6j4ylNapPlHhlTENd7r7f4jFP7FqcNWhXwwrUjaXZO ULdWqYTUjt7+NGut5lPd9Dqavb6gbNtYm8XJnrHN6xCOVNiKUk/946gpUTb8xz9Rm42x 0H14bUcRr4qxFncAHlqCXlRTGOeQ0894IoR5m+sOwVNDzxnpq3XKJ/U0hLzNVnl7fwaK llCQ== 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=phsWo5rhJkqxVPJl/pJrjqtmY1DQTnnTQTDcXmRwkgA=; b=rRdVHxUph+4mXksZehD/45W7gStw1/TV6aDEdQJ2rTjM27sLtmXhemix5u1Pa8fkz5 y6VATnXHs7WGi+FVJ3Rgcy8Du0m3nhUByxHza6gpeUQ4T7PuqbYhKfZydGvVs43CkxV5 D9AHU6s5DB+EmCjWpYoYvsZ1JXZ5UWlqSF0tkaKGXEV1dcrX/j3GAkbl0w3FF0lsVoSx i/BHVC5YLxWLf/M156gzK21YofNAftKnbXKyQ+x29sEIOlWz8Yarj6oELCOyti9wILBL dRELRqjpFcqKgdnIeMpEGikkQrFnmon1bwuQIVw5yd7K7jdU59tnk7ScJrfKSAao0GPx Wu5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XsqiME4s; 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.55; Thu, 26 Nov 2020 07:22:56 -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=XsqiME4s; 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 S2391296AbgKZPWX (ORCPT + 15 others); Thu, 26 Nov 2020 10:22:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391314AbgKZPWX (ORCPT ); Thu, 26 Nov 2020 10:22:23 -0500 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDE6FC061A04 for ; Thu, 26 Nov 2020 07:22:22 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id p22so2475182wmg.3 for ; Thu, 26 Nov 2020 07:22:22 -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=phsWo5rhJkqxVPJl/pJrjqtmY1DQTnnTQTDcXmRwkgA=; b=XsqiME4sq+d22N78uMt0i1Oq5ZWB1i3SPR62fXxjci/K9nTiYU9NDjY57J+IPCc+3U EvVLS/cjHajhgD9navBNBS8bLr39tzyJVs8CxbXLnfz4slr4eN9x5oi2f8z/F59Y2/8O rpBbNQpuxF+Lyd3y4eKWWblYaNeg36gc6c+Bmp7AUDHmAZAqzk5ZeY4olz5Td+fcvIjz 92auzppgTd5D5GlwX1Cku024hLGljgUKFaGA6gFDyel1urE8I7jhzzp2GP8jyhGZBltH dGII85vVfxoE3YQR8iBdD8dwWoEfHgy2PFaeQoZaMnqZbhh+7esG1uX8vYRbmFfnns+y I9Eg== 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=phsWo5rhJkqxVPJl/pJrjqtmY1DQTnnTQTDcXmRwkgA=; b=EOswnpUTJPE4YH3D+uTHLDeplnQgr0HGKnq8nMpGFGvQQcB8CZrOff/ZutMHkFz7Mt WpyIDcyWFzK9JiuuxnGM2aAP6UctNm57mafKXdCsmgqrWiTEJBdfPDxOPGDP/tWJkqAd yARGFDYijqTvjcvUfiOVofz+7XGtfOwc09SlJghIJhiz3CwD9EdDwyzgTUpo0y2Xz5fK ZFQhabzHKRZEm8jXaAZDL8f6SFFJmB1qUCWXO6EZlHVZXqZE53Rim2E7fTb4gYmu9Ruq Q0PJWpxmsxXAw+iN9ceqwIo4lC13xF1Bry47EeW5XFnds8NLdtoJBiIvsv8a7jYjaRxW +hwA== X-Gm-Message-State: AOAM532j1CI799JIWijg50nywthiJijsTpCG7kpasMiQOIZ5dwJNRJKp bKICYstd5mNP5s1s0VVzpRvlsw== X-Received: by 2002:a7b:cbd1:: with SMTP id n17mr3906056wmi.186.1606404141563; Thu, 26 Nov 2020 07:22:21 -0800 (PST) Received: from localhost.localdomain ([88.122.66.28]) by smtp.gmail.com with ESMTPSA id l10sm2756144wme.42.2020.11.26.07.22.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Nov 2020 07:22:20 -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 7/9] mhi: pci_generic: Add PCI error handlers Date: Thu, 26 Nov 2020 16:29:05 +0100 Message-Id: <1606404547-10737-8-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 In AER capable root complex, errors are reported to the host which can then act accordingly and perform PCI recovering procedure. This patch enables error reporting and implements error_detected, slot_reset and resume callbacks. Signed-off-by: Loic Poulain --- drivers/bus/mhi/pci_generic.c | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) -- 2.7.4 diff --git a/drivers/bus/mhi/pci_generic.c b/drivers/bus/mhi/pci_generic.c index 9919ad6..3ac5cd2 100644 --- a/drivers/bus/mhi/pci_generic.c +++ b/drivers/bus/mhi/pci_generic.c @@ -8,6 +8,7 @@ * Copyright (C) 2020 Linaro Ltd */ +#include #include #include #include @@ -409,6 +410,8 @@ static int mhi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) pci_save_state(pdev); mhi_pdev->pci_state = pci_store_saved_state(pdev); + pci_enable_pcie_error_reporting(pdev); + err = mhi_register_controller(mhi_cntrl, mhi_cntrl_config); if (err) return err; @@ -508,7 +511,54 @@ void mhi_pci_reset_done(struct pci_dev *pdev) set_bit(MHI_PCI_DEV_STARTED, &mhi_pdev->status); } +static pci_ers_result_t mhi_pci_error_detected(struct pci_dev *pdev, + pci_channel_state_t state) +{ + struct mhi_pci_device *mhi_pdev = pci_get_drvdata(pdev); + struct mhi_controller *mhi_cntrl = &mhi_pdev->mhi_cntrl; + + dev_err(&pdev->dev, "PCI error detected, state = %u\n", state); + + if (state == pci_channel_io_perm_failure) + return PCI_ERS_RESULT_DISCONNECT; + + /* Clean up MHI state */ + if (test_and_clear_bit(MHI_PCI_DEV_STARTED, &mhi_pdev->status)) { + mhi_power_down(mhi_cntrl, false); + mhi_unprepare_after_power_down(mhi_cntrl); + } else { + /* Nothing to do */ + return PCI_ERS_RESULT_RECOVERED; + } + + pci_disable_device(pdev); + + return PCI_ERS_RESULT_NEED_RESET; +} + +static pci_ers_result_t mhi_pci_slot_reset(struct pci_dev *pdev) +{ + if (pci_enable_device(pdev)) { + dev_err(&pdev->dev, "Cannot re-enable PCI device after reset.\n"); + return PCI_ERS_RESULT_DISCONNECT; + } + + return PCI_ERS_RESULT_RECOVERED; +} + +static void mhi_pci_io_resume(struct pci_dev *pdev) +{ + struct mhi_pci_device *mhi_pdev = pci_get_drvdata(pdev); + + dev_err(&pdev->dev, "PCI slot reset done\n"); + + queue_work(system_long_wq, &mhi_pdev->recovery_work); +} + static const struct pci_error_handlers mhi_pci_err_handler = { + .error_detected = mhi_pci_error_detected, + .slot_reset = mhi_pci_slot_reset, + .resume = mhi_pci_io_resume, .reset_prepare = mhi_pci_reset_prepare, .reset_done = mhi_pci_reset_done, };