Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp3545250ybk; Tue, 19 May 2020 07:16:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqgqmLNKOBLrT0JQryC1+JDrn8LMcxTK9t2M9/lk8o+UV+d3NQ4cjJePqcQMPCSeN4aYxu X-Received: by 2002:a17:906:41a:: with SMTP id d26mr18432171eja.217.1589897813121; Tue, 19 May 2020 07:16:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589897813; cv=none; d=google.com; s=arc-20160816; b=YjX57neQ0IWgvExIp+pd+eRBAUrp6Dym4Rj7ekyeAXg6zSIJYaLmwPOq2PC6pmIO6V Bcmo5Y0aTSQ4F1tZzX1V1NPBliLqSDCa6rS4LggXN6S8TF5lbpTnkSPO2yp+SoV7gCsU 6eHzVBZZ1C6GisWpSNxfcIjIFChrIechnyrQy+jVzcsIkoDEnfBAqrG1BUScHOpyJAGN 63isYiWu1ng/rAIR6NGZ8v6RmOeV1XDibTZVpNGo6f6rxPJZNqSkGqjHTW51atzSf5WF yTB6e4Xwn8aFb8li/uZKLZNHGyTkiTOEXRsZdJ5VFaLsT6j45PT+/ArcwcM6fpbj0snR ek4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature; bh=Vyp+hEO5hf8GYwz6X2L6iMDXElho5JZfbOncmp0Trv4=; b=lE+UcCNWjaqgg4aUmA2M/oF3NgmSG6sXE4dFVaTEFoEitAkhh9NqTuvs66qXDOC8yF 8GQdDRIOUKCcOg3an7a4BBCDmdfxKCeOQhhq36jw8CSEzjQExIWZJLzVcgUxJ8qYeT2X S4FZ7baaGgB5oRIpJobhW/QBkyEH8tGiNKtPb+v4futR5+yIh8xfkihSHU963Jht3YO8 Sv629GNoY9i65H0XWUA95g9UaQuX/6EzKWlRBGka/br6lp+WlC9Omr2T6lZQnfm5Fwxg tdf+v3+EaF+sluxTDKNwsRj0W9kMelEiGXYszR9jcJb8DnoLHixe5InlZ9nMhIZCQ4gj AUMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=w+TeR55T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a11si256545ejr.616.2020.05.19.07.16.29; Tue, 19 May 2020 07:16:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@mg.codeaurora.org header.s=smtp header.b=w+TeR55T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728940AbgESOOz (ORCPT + 99 others); Tue, 19 May 2020 10:14:55 -0400 Received: from mail26.static.mailgun.info ([104.130.122.26]:30285 "EHLO mail26.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729103AbgESOOt (ORCPT ); Tue, 19 May 2020 10:14:49 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1589897689; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=Vyp+hEO5hf8GYwz6X2L6iMDXElho5JZfbOncmp0Trv4=; b=w+TeR55T0+0GaN95i6EXAwAvQ7vsFGM+wqCjwGt/jcWbvvyE2Di6fw9X4EyiRYHUvBTwF+5o DDk8PbVnoJTR8XGwa/92jtMWc90ng7fTl1cjuuNQYs/MICn6gob0TNu2SiKrD8t87zaS4AI9 8aP3PTZKCQgvepSiIAZWg6vrDw8= X-Mailgun-Sending-Ip: 104.130.122.26 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5ec3e9c6.7f128b2c29d0-smtp-out-n05; Tue, 19 May 2020 14:14:30 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id A2F81C44795; Tue, 19 May 2020 14:14:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.0 Received: from jhugo-perf-lnx.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: jhugo) by smtp.codeaurora.org (Postfix) with ESMTPSA id 27ED0C43637; Tue, 19 May 2020 14:14:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 27ED0C43637 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=jhugo@codeaurora.org From: Jeffrey Hugo To: arnd@arndb.de, gregkh@linuxfoundation.org Cc: manivannan.sadhasivam@linaro.org, bjorn.andersson@linaro.org, wufan@codeaurora.org, pratanan@codeaurora.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Jeffrey Hugo Subject: [RFC v2 PATCH 6/8] qaic: Implement PCI link status error handlers Date: Tue, 19 May 2020 08:14:03 -0600 Message-Id: <1589897645-17088-7-git-send-email-jhugo@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1589897645-17088-1-git-send-email-jhugo@codeaurora.org> References: <1589897645-17088-1-git-send-email-jhugo@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Whenever the link goes down, the device loses all state. Therefore, we need to be aware of when the link goes down and comes back up so that our state is kept in sync with the device. Implement the PCI error handlers to be notified of links tate changes. Signed-off-by: Jeffrey Hugo --- drivers/misc/qaic/mhi_controller.c | 16 ++++++++++++++++ drivers/misc/qaic/mhi_controller.h | 4 ++++ drivers/misc/qaic/qaic_drv.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/drivers/misc/qaic/mhi_controller.c b/drivers/misc/qaic/mhi_controller.c index a667a2f..9ba74fc 100644 --- a/drivers/misc/qaic/mhi_controller.c +++ b/drivers/misc/qaic/mhi_controller.c @@ -495,3 +495,19 @@ void qaic_mhi_free_controller(struct mhi_controller *mhi_cntl, bool link_up) kfree(mhi_cntl->irq); kfree(mhi_cntl); } + +void qaic_mhi_link_down(struct mhi_controller *mhi_cntl) +{ + mhi_power_down(mhi_cntl, false); +} + +void qaic_mhi_link_up(struct mhi_controller *mhi_cntl) +{ + struct pci_dev *pci_dev = container_of(mhi_cntl->cntrl_dev, + struct pci_dev, dev); + int ret; + + ret = mhi_async_power_up(mhi_cntl); + if (ret) + pci_err(pci_dev, "mhi_async_power_up failed when link came back %d\n", ret); +} diff --git a/drivers/misc/qaic/mhi_controller.h b/drivers/misc/qaic/mhi_controller.h index f5197f1..6dca59d 100644 --- a/drivers/misc/qaic/mhi_controller.h +++ b/drivers/misc/qaic/mhi_controller.h @@ -11,4 +11,8 @@ struct mhi_controller *qaic_mhi_register_controller(struct pci_dev *pci_dev, int mhi_irq); void qaic_mhi_free_controller(struct mhi_controller *mhi_cntl, bool link_up); + +void qaic_mhi_link_down(struct mhi_controller *mhi_cntl); +void qaic_mhi_link_up(struct mhi_controller *mhi_cntl); + #endif /* MHICONTROLLERQAIC_H_ */ diff --git a/drivers/misc/qaic/qaic_drv.c b/drivers/misc/qaic/qaic_drv.c index e548881..ac4315a 100644 --- a/drivers/misc/qaic/qaic_drv.c +++ b/drivers/misc/qaic/qaic_drv.c @@ -484,6 +484,28 @@ static void qaic_pci_remove(struct pci_dev *pdev) kfree(qdev); } +static pci_ers_result_t qaic_pci_error_detected(struct pci_dev *pdev, + enum pci_channel_state error) +{ + return PCI_ERS_RESULT_NEED_RESET; +} + +static void qaic_pci_reset_prepare(struct pci_dev *pdev) +{ + struct qaic_device *qdev = pci_get_drvdata(pdev); + + qaic_dev_reset_clean_local_state(qdev); + qaic_mhi_link_down(qdev->mhi_cntl); +} + +static void qaic_pci_reset_done(struct pci_dev *pdev) +{ + struct qaic_device *qdev = pci_get_drvdata(pdev); + + qdev->in_reset = false; + qaic_mhi_link_up(qdev->mhi_cntl); +} + static const struct mhi_device_id qaic_mhi_match_table[] = { { .chan = "QAIC_CONTROL", }, {}, @@ -507,11 +529,18 @@ static const struct pci_device_id ids[] = { }; MODULE_DEVICE_TABLE(pci, ids); +static const struct pci_error_handlers qaic_pci_err_handler = { + .error_detected = qaic_pci_error_detected, + .reset_prepare = qaic_pci_reset_prepare, + .reset_done = qaic_pci_reset_done, +}; + static struct pci_driver qaic_pci_driver = { .name = KBUILD_MODNAME, .id_table = ids, .probe = qaic_pci_probe, .remove = qaic_pci_remove, + .err_handler = &qaic_pci_err_handler, }; static int __init qaic_init(void) -- Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.