From patchwork Mon Jan 4 16:14:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 356398 Delivered-To: patch@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp15089549jai; Mon, 4 Jan 2021 08:10:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJy592/pdH8szj5IjD5hIhyk1pYVwF8ykXpmGTVKYroBKl3iTQnXSWcE0xzgTNF51uU9DOr7 X-Received: by 2002:a05:6402:1ac4:: with SMTP id ba4mr17452516edb.383.1609776629569; Mon, 04 Jan 2021 08:10:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609776629; cv=none; d=google.com; s=arc-20160816; b=Dx/u9uCTEG0uieWGE8V+jx81MnRvfjOMs22PtfryuirSfBT/LdAvlXFQH2UdlKlxcd RWUaOo6KfaS8LxGgWR/XAHbMF6LeQFur7p7AibXkv1yRwN5xHSDacjaiAdiiBtUfF0wX bVX2AI50atKz10dgjKe4vfy4T8H/+9xZxN1MJqA/AxYk0IWC8DOlzLz2YNryn2Bb+nnH nd48wJFwZH5rbfAkd3Vn5uBoq9VXvTwpALqy/4WD9+6kCPWMH+kWmlXuogwqXMDTTR6x BFoyqiEaVv6KkajKNkgVt6jn/j0teK1yl2fYuhh+vkE69e3oKyAKSTIU4en2T7X5+GHp T5kg== 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=34XOBF83gNVVKnvz/aUxsZHTWtTtAZLPpXEIjEVGhRo=; b=ctq1vnV6oyBOUkFQnjjqjzM7Y0TnvF1BRozDQ8LVrn9fS165yem9Tu2KWofSg3kdhh NCot6snJ87csjvxeO+pObL519K03teyuZ/8/soigzJ9LusQz73e2jAXC38INJu6DlIaI mJwYZbYgTT9ETW8eEumfDp+W17UneF2MEirHhP18E7IdG9rO21IWi8xLjpAMx2PrjOi/ m5+qFaIyZ/TavseG1MH9xfaB7wXDTVtZgObVTgQAe6QfbxBNfHYIOd2Y4Lt5MV8rBSWu hnbjvMawm1t8iV9SnqCuEN5cAlrY6XYSn4Rmjb0CfqJkA0GllIzdoCJ1HPlLTWmuS+fm bRyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LpJWeo4s; 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 61si31780067edk.598.2021.01.04.08.10.29; Mon, 04 Jan 2021 08:10:29 -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=LpJWeo4s; 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 S1728674AbhADQJE (ORCPT + 15 others); Mon, 4 Jan 2021 11:09:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729613AbhADQIv (ORCPT ); Mon, 4 Jan 2021 11:08:51 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46FE4C06179A for ; Mon, 4 Jan 2021 08:07:34 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id y23so19838431wmi.1 for ; Mon, 04 Jan 2021 08:07:34 -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=34XOBF83gNVVKnvz/aUxsZHTWtTtAZLPpXEIjEVGhRo=; b=LpJWeo4szLK1Xt/vGxUx89bMndVwpBNdUQoN64QbsBMIOosnHL6XEYXs1qaUsW1TIm 8clWaKJufZesuv0mQ+ydtaZC/96VNBrQxSL2qsPUg0nCIepliNS7pwXG9bAo11mr0ouN onY8J5tilmPzDdrTUi6G4xNZaveZDtqknAq74DPG7OBvMuCTLE9owkrhAsMxnHv3MpEM sTGdXEPF5a0gN/LoI4Hg/ZL6XZ0yOK/N8FTLEA207ZDPlVT6W8J9cZKEOHbkpkKpsOpn n/Bp9xdDUMUMJSS++j9jVarrzSg3WhR1YBaXO6xK+Vtj3BD7cYUOwcWhQrl/T8n83N+K 75IA== 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=34XOBF83gNVVKnvz/aUxsZHTWtTtAZLPpXEIjEVGhRo=; b=G/aLOnLH65Xt7mHvdHPpv7RDXGgClWzoic/9VOqSPzqpTYue+8a5gbpkWb4b0aWSlB uGTapTjVFRG1+prl4ot1Yli0N7aJ64mEAELaedk9hzu7t48pH6u3Cu2buPr68ofODg6B 2LGsoX1D0znrsaevVeKOBfD4Ft5azijQ3xzNrCWJ7l7PUd8TT1oGkARUyYOMnfargelT 8m/qQh+mMzuXHMgwNLbwjhwMO1j3bCtdy2bc9+9P16qvNEku/0PAnZgoNjI5Gao8PX1+ jgQlT3vcGw26hynzu325WVnrJkv+CiQ+3btVCjYMeSvAkPXmQ0/noD8+ZXCj+fr5jIWi h7/w== X-Gm-Message-State: AOAM531KngqRB8ET5xh7unECdermmhseefsepsRuSYyzJO4pgzOgWxqd MwFviBZYYfz1N2KBbUMBkY36ig== X-Received: by 2002:a1c:7d88:: with SMTP id y130mr26906465wmc.158.1609776453013; Mon, 04 Jan 2021 08:07:33 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:490:8730:41b:e085:fa9a:9c53]) by smtp.gmail.com with ESMTPSA id h9sm89278049wre.24.2021.01.04.08.07.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jan 2021 08:07:32 -0800 (PST) From: Loic Poulain To: manivannan.sadhasivam@linaro.org Cc: linux-arm-msm@vger.kernel.org, bbhatt@codeaurora.org, hemantk@codeaurora.org, Loic Poulain Subject: [PATCH v8 06/10] mhi: pci_generic: Add PCI error handlers Date: Mon, 4 Jan 2021 17:14:55 +0100 Message-Id: <1609776899-30664-7-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1609776899-30664-1-git-send-email-loic.poulain@linaro.org> References: <1609776899-30664-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 Reviewed-by Hemant Kumar Reviewed-by: Manivannan Sadhasivam --- 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 2552c2e..2cc4410 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 @@ -405,6 +406,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; @@ -501,7 +504,54 @@ static 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, };