Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2569426imw; Wed, 6 Jul 2022 08:09:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uHGop5zpD6JpeBPL1GWuu6y9J5BNO2wh94Q494eggg0toDAnTBYtiT32ZtuYmM4oNNpmL0 X-Received: by 2002:a05:6402:510a:b0:43a:91ff:3f4b with SMTP id m10-20020a056402510a00b0043a91ff3f4bmr1053963edd.187.1657120178212; Wed, 06 Jul 2022 08:09:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657120178; cv=none; d=google.com; s=arc-20160816; b=jTrMIB9hR+FD3yqhGElz08uI2CJ1OCM1Onc4RQqvhlBcygGKrUZVcYXfaglHyTPQJr MxT+NYir0nVLQemaaMFG9/H9mcb+KYkJ3X7w+RUokY57h9X9JWP+5nlmUhPbpALkJDkV 8PqapN7QK56H88uPnTrXXMp/3nOKMfldxiF9YlqgRzK5u0JV52tx9zu+q9C9w+H6H+Ky w9NYGX7dbpHsk8ru+SmXCCPLYYROSvEnMJkfGyyaRaTSqIDt3caNP5ANPMKY0ycRV+GF pwHUTfjnVHGyUrvrx8epkyPMwG4HCzVduzIdnFY0xDFJhjvv9FLVIwU3silGHG2wk+++ hLgQ== 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=Hr9yV/i11+naZBUagnWE5HaqO+SDNFfP01uIpud54bQ=; b=G8RrEWslzXmCFg2kIz4U1x+iHhvCiCRJ9UxTUod9ZSi4n/2bmKlV6I8EMrMNhCzNFP y4VVHPsqHIIPFxTWX8M2VRA3bOVxMyR70ZWavTKhhRxAwTb4eWe20l1cGBkqHkEpvfIh vztimFElMvGL0aMdEKQzLKjLuva/0jzw22RePgrUUe7ryi88SHH9nFVhko9pOF842ylR wO5W9NvzB4GQQW4+7f6Zg2B/1iIMz0Pd+rLHg6z3mTworVMc99yUM4i5NRMDfL4Po0LY zHGtoAW7D2Ll4usC22v4m0bhH++Hhqz3R0NPrZzmvP6ZTU0nRZsTyCGk8ZlNeyo2ZaIE ovRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=QeontSuI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs8-20020a1709072d0800b00718d2cbefd9si50671380ejc.807.2022.07.06.08.09.11; Wed, 06 Jul 2022 08:09:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=QeontSuI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233460AbiGFOlh (ORCPT + 99 others); Wed, 6 Jul 2022 10:41:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233413AbiGFOlg (ORCPT ); Wed, 6 Jul 2022 10:41:36 -0400 Received: from alexa-out.qualcomm.com (alexa-out.qualcomm.com [129.46.98.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D705237D3; Wed, 6 Jul 2022 07:41:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1657118495; x=1688654495; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Hr9yV/i11+naZBUagnWE5HaqO+SDNFfP01uIpud54bQ=; b=QeontSuISPdiGgRlQ57Pj+KlhZvaz4o+qoWNYD+a6cT8rixGBIAUtvGS DCJqteOCeKTGQGPb1+jRHCI+m6yZ4M9zK1chjQ71J93SAi3gHoMdDK3tP tcRQsuE+PCm//HzVgGvYw9S1mrfI2taetk/hT4iY/q4QxQxpWR3q+pfwB 8=; Received: from ironmsg09-lv.qualcomm.com ([10.47.202.153]) by alexa-out.qualcomm.com with ESMTP; 06 Jul 2022 07:41:35 -0700 X-QCInternal: smtphost Received: from ironmsg02-blr.qualcomm.com ([10.86.208.131]) by ironmsg09-lv.qualcomm.com with ESMTP/TLS/AES256-SHA; 06 Jul 2022 07:40:49 -0700 X-QCInternal: smtphost Received: from hu-krichai-hyd.qualcomm.com (HELO hu-sgudaval-hyd.qualcomm.com) ([10.213.110.37]) by ironmsg02-blr.qualcomm.com with ESMTP; 06 Jul 2022 20:10:27 +0530 Received: by hu-sgudaval-hyd.qualcomm.com (Postfix, from userid 4058933) id D6C9642A4; Wed, 6 Jul 2022 20:10:26 +0530 (+0530) From: Krishna chaitanya chundru To: helgaas@kernel.org Cc: linux-pci@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, mka@chromium.org, quic_vbadigan@quicinc.com, quic_hemantk@quicinc.com, quic_nitegupt@quicinc.com, quic_skananth@quicinc.com, quic_ramkri@quicinc.com, manivannan.sadhasivam@linaro.org, swboyd@chromium.org, dmitry.baryshkov@linaro.org, Krishna chaitanya chundru , Jingoo Han , Gustavo Pimentel , Lorenzo Pieralisi , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Bjorn Helgaas , Stanimir Varbanov , Andy Gross , Bjorn Andersson Subject: [PATCH v4 2/2] PCI: qcom: Restrict pci transactions after pci suspend Date: Wed, 6 Jul 2022 20:10:25 +0530 Message-Id: <1657118425-10304-3-git-send-email-quic_krichai@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1657118425-10304-1-git-send-email-quic_krichai@quicinc.com> References: <1656684800-31278-1-git-send-email-quic_krichai@quicinc.com> <1657118425-10304-1-git-send-email-quic_krichai@quicinc.com> X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the endpoint device state is D0 and irq's are not freed, then kernel try to mask interrupts in system suspend path by writing in to the vector table (for MSIX interrupts) and config space (for MSI's). These transactions are initiated in the pm suspend after pcie clocks got disabled as part of platform driver pm suspend call. Due to it, these transactions are resulting in un-clocked access and eventually to crashes. So added a logic in qcom driver to restrict these unclocked access. And updated the logic to check the link state before masking or unmasking the interrupts. Signed-off-by: Krishna chaitanya chundru --- drivers/pci/controller/dwc/pcie-designware-host.c | 14 +++++++-- drivers/pci/controller/dwc/pcie-qcom.c | 36 +++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c index 2fa86f3..2a46b40 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -29,13 +29,23 @@ static void dw_msi_ack_irq(struct irq_data *d) static void dw_msi_mask_irq(struct irq_data *d) { - pci_msi_mask_irq(d); + struct pcie_port *pp = irq_data_get_irq_chip_data(d->parent_data); + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); + + if (dw_pcie_link_up(pci)) + pci_msi_mask_irq(d); + irq_chip_mask_parent(d); } static void dw_msi_unmask_irq(struct irq_data *d) { - pci_msi_unmask_irq(d); + struct pcie_port *pp = irq_data_get_irq_chip_data(d->parent_data); + struct dw_pcie *pci = to_dw_pcie_from_pp(pp); + + if (dw_pcie_link_up(pci)) + pci_msi_unmask_irq(d); + irq_chip_unmask_parent(d); } diff --git a/drivers/pci/controller/dwc/pcie-qcom.c b/drivers/pci/controller/dwc/pcie-qcom.c index 0a9d1ee..78bc463 100644 --- a/drivers/pci/controller/dwc/pcie-qcom.c +++ b/drivers/pci/controller/dwc/pcie-qcom.c @@ -1342,11 +1342,41 @@ static int qcom_pcie_suspend_2_7_0(struct qcom_pcie *pcie) return 0; } +static u32 qcom_pcie_read_dbi(struct dw_pcie *pci, void __iomem *base, + u32 reg, size_t size) +{ + struct qcom_pcie *pcie = to_qcom_pcie(pci); + u32 val; + + if (pcie->is_suspended) + return PCIBIOS_BAD_REGISTER_NUMBER; + + dw_pcie_read(base + reg, size, &val); + return val; +} + +static void qcom_pcie_write_dbi(struct dw_pcie *pci, void __iomem *base, + u32 reg, size_t size, u32 val) +{ + struct qcom_pcie *pcie = to_qcom_pcie(pci); + + if (pcie->is_suspended) + return; + + dw_pcie_write(base + reg, size, val); +} + static int qcom_pcie_link_up(struct dw_pcie *pci) { - u16 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); - u16 val = readw(pci->dbi_base + offset + PCI_EXP_LNKSTA); + struct qcom_pcie *pcie = to_qcom_pcie(pci); + u16 offset; + u16 val; + + if (pcie->is_suspended) + return false; + offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP); + val = readw(pci->dbi_base + offset + PCI_EXP_LNKSTA); return !!(val & PCI_EXP_LNKSTA_DLLLA); } @@ -1590,6 +1620,8 @@ static const struct qcom_pcie_cfg sc7280_cfg = { static const struct dw_pcie_ops dw_pcie_ops = { .link_up = qcom_pcie_link_up, .start_link = qcom_pcie_start_link, + .read_dbi = qcom_pcie_read_dbi, + .write_dbi = qcom_pcie_write_dbi, }; static int qcom_pcie_probe(struct platform_device *pdev) -- 2.7.4