From patchwork Mon Nov 23 14:11:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 330675 Delivered-To: patch@linaro.org Received: by 2002:a92:ae0b:0:0:0:0:0 with SMTP id s11csp2026553ilh; Mon, 23 Nov 2020 06:05:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGRp0/p/MmmqWZMIMKSDGgbz6euSMwq2J2uk9MBPAz7prqkCWDeNyVbdHT9REI19oQIvRL X-Received: by 2002:a17:906:d96e:: with SMTP id rp14mr23696288ejb.214.1606140304834; Mon, 23 Nov 2020 06:05:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606140304; cv=none; d=google.com; s=arc-20160816; b=dTjonAUzkDenqkDlKWrGZNi9Kzltl5U6Yo63kTabKiyP89GYROdlDuPJAxkLwgtpvB rWNbQYgSD6h2B3VQySMT8swxctYCKFDJMNBZFl4DTYzzzvWlkmUPp+kdPS1KzDlRoLL7 FFQpYvMc0kFkEoNIWlqvIx+PwOMav4kVkDmeBC1djk5psXvEx0lbSCp+pjgfX3WD2gnx qfrFLofiU6HAqDbivU/jOCU0dBR95TcXQMrjXoFbOCBIpuM+GmgfneW3DyIxrLu4is1g pF0swizM/iDizSijPFpRk76zULYlPndKR2brC4jsi6B6BI7TO+1+WKN1Wn/Ea811hwH+ iSzg== 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=aJwDuVuDFzYWlPenmYT+5y0gUc768gX0/h1SRlfw534=; b=OdatYsQ/KrRHs1KnkdQ2qsyapWgDvdw+A9AYzjyiwctfZoaJAKaj3E6/Dl4UbYLvVw ltNv5dIIsA3JtfMPem0utqrbP+dxl8UIiWzugBw5a+6Xs4JKhpO5CCa0IEiGq9uXzJQ5 2LvGtz4DHGtshGNX5xjJMm8zD87SXJP7SkuRDfdMaAwXoUMf5sJnEzeAkSDjE8tZ1n6t OGuzqMKycUQf6H8cV0Fpx3TI7zlYY4DvNn9BDwGPF3j9rEp0r3UbdDOot9z686dG/6lA f6VL4QgsH1Zfhwbyts/5RnWZ08ndLjR2yhBnTkdI9/59UzVkHpmUWboMUAk6ZJdrBGxs cLvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="PIA6xLj/"; 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 r18si6917042edm.82.2020.11.23.06.05.04; Mon, 23 Nov 2020 06:05:04 -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="PIA6xLj/"; 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 S1730130AbgKWOEt (ORCPT + 15 others); Mon, 23 Nov 2020 09:04:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729293AbgKWOEt (ORCPT ); Mon, 23 Nov 2020 09:04:49 -0500 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F33ABC0613CF for ; Mon, 23 Nov 2020 06:04:48 -0800 (PST) Received: by mail-wm1-x344.google.com with SMTP id x13so7768690wmj.1 for ; Mon, 23 Nov 2020 06:04:48 -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=aJwDuVuDFzYWlPenmYT+5y0gUc768gX0/h1SRlfw534=; b=PIA6xLj/8vNx/bL0HZ4na6bXLvf+MZ4FMhXEzk/7lqgCB26v1M+tLqyC6a9ctOrBEf bvRPNLGHwZEWFtjlQLuang9avRIb/jUcncHRLy+t4lMNBnIxP8ZAF29PrqHpVS5svg3Q pPe+tlavqfbkIY339v3ksNlqfc3OBDmruEQlrpaGbkUUDcZXQl078dvDo1xw+hJrkMtI AWHT5nLWDYHItHegMjeR5Np+KM7A4UgrMXOFEqQ6Iy5n89QEqXfGFuj+xy7YRmPH2oGG zbzF/bb11PgxTTOh6S6oVLiqdx2aj7z/tiJOYOJ/AUtaiNRkW/Gxo9jWm/I12rMJEktW oiQQ== 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=aJwDuVuDFzYWlPenmYT+5y0gUc768gX0/h1SRlfw534=; b=Uos9r+tU+aLedBwBVC1FJm+3jL4KnLOF5PcpHaVEkMXFvBrbnFSrD+oiWfb5pdjl/Q IldqaKrbUQd9TJfzNCwxhVjXPaZRCe6ltSR5wjmW8vkOSCIoK4/Xq7O5NcjqR8lDaX7D 4++z78rTM8ayJPRBIYPYerJTpP9fTJT9qhn21mk9HRGZdcdUALKtV06B5yULc0a9QNrb JGqLSHWXMcHHXPV8zKRyRXurfRhwR0KHuFXIKxqpYOSEojB0wBQGECq1kYGypTvdIg5L i0dmojeoz5kjOmK7M0g9GucccqefHM/7WFdb6cmQpkR1WPJNZQyEXtljSuRyJbykHCZK LCmQ== X-Gm-Message-State: AOAM531fH+jpyxx/cxt//aikXuI80Vgc02AHWXae8AGDsGujvoDEWnDp H0lNtOGWY1yp7SMqyg+/Za5kBw== X-Received: by 2002:a1c:61c2:: with SMTP id v185mr23735520wmb.152.1606140287652; Mon, 23 Nov 2020 06:04:47 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:490:8730:f5cd:e791:e88b:e3b7]) by smtp.gmail.com with ESMTPSA id m9sm7102727wrx.59.2020.11.23.06.04.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Nov 2020 06:04:44 -0800 (PST) From: Loic Poulain To: manivannan.sadhasivam@linaro.org, hemantk@codeaurora.org Cc: linux-arm-msm@vger.kernel.org, Loic Poulain Subject: [PATCH v2 6/8] mhi: pci_generic: Add PCI error handlers Date: Mon, 23 Nov 2020 15:11:04 +0100 Message-Id: <1606140666-4986-7-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1606140666-4986-1-git-send-email-loic.poulain@linaro.org> References: <1606140666-4986-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 3eefef3..b01b279 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 @@ -407,6 +408,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; @@ -506,7 +509,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, };