From patchwork Wed Sep 23 06:26:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 11794069 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E5C2792C for ; Wed, 23 Sep 2020 06:28:59 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B5EC821D43 for ; Wed, 23 Sep 2020 06:28:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ppv8eLNq"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=Synaptics.onmicrosoft.com header.i=@Synaptics.onmicrosoft.com header.b="i6Va3w+f" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B5EC821D43 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=synaptics.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=h4YNCY8w1+nn5Nc4qFINfAI8NmosCNkYyzrHBR/uY1o=; b=ppv8eLNqlj+nvQh5dB/TaM4MQS LE32bSm0UG23WQ+QYZCJQL1eXubZgQmbccuP9LnLaIEUcsTQEunUw+GnjJWsEqQC6cyra5ZK/drK+ rz8ovwNJvYsnlpMLWDKu0XwMwZBMpWKjlfLdJALk5r2ZrSeBh+fOks8W2AqqpEncJbU6yXcw661ZK 1GgUvXe0BaE7vmN0sCyVpCP7u/PvXHl0wA4P25PuGvIeyRWVXSUj6aPu/Kmhns4x4h2QlWxgQKB/y aNPKlOkQIE7qNOkLH1QJpBQzjKm7XBAwy2qRRYE7cgP8AErdWSRFkHmCw4JaHl/69tms6yfKwC5tW +T/IHDdQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKyFZ-00069k-Eb; Wed, 23 Sep 2020 06:27:33 +0000 Received: from mail-dm6nam10on2059.outbound.protection.outlook.com ([40.107.93.59] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKyFV-00068s-QW for linux-arm-kernel@lists.infradead.org; Wed, 23 Sep 2020 06:27:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A0kSs2FycmMcV13/lJYFSPFtny5FZ7lTB3miueAskn2Q2Hi8BEiZdUtGrxOEO2oCOZnhWo7S1W1J7u/UdfdGAO6wD73wLM5CH9pNPQBrTNq3T7rTzo/DbeeqTKTLbcnAQ3oY9Iyg9wSe+phQ4dWcV5nzaL9/o2BK9t7GLaEBIOFn11nHQgSJjXXf9+mj2YpmR8GK5nlxnTw88uFd6AHeZX3exQ/WnDm52woIkJztYulrtk3Ok10bG7KWyIpTmpmt1U1V3GgOud4bLgb/qcR2uNgJ8D9fkci/bkH76rRTGvbN/268Py244ZvsfVYbzPLJP5i+Ty11m4o96ey6/WXfwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6g2NAP3+8asfVz5TnwA65boSew3P9cr7EnSkkE+UHTY=; b=Q8MiRLM15YBQAeeLDE8DNTlyYt32kGwu9Bo2uLHK/t4IJb/fLVLhT7vMTUx+CnJMdgT4honpwMJnrPvlXzWlvysw/t8+l0VGAUoes6DI21qbxbqr/hdi9QekJU8Q+IqDqNRwXo1yyCVbIZLl4+eR5cVCgD/W9sbqa/t05BcYlisrIfLggIJLUBqZ/ZSLHYTnR1IQlHM1HETEgYwW1/rOEGD9lsCw3HWluKUU8a/NMIS3LEVNHHv9jaMP2q9U17FNj8CMrNnbDBWPTzPTODDVG+g2dOWQ2DExuazIQm/TQYIqJg7DHVLoOqxnG6yikAJbzueqztBl3QBFAHpkxU7/RQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=synaptics.com; dmarc=pass action=none header.from=synaptics.com; dkim=pass header.d=synaptics.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Synaptics.onmicrosoft.com; s=selector2-Synaptics-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6g2NAP3+8asfVz5TnwA65boSew3P9cr7EnSkkE+UHTY=; b=i6Va3w+flapu5hNu6aUt6zJx1WTkCg4ZrxmEiJr5tdKmVFl4OIBzKawLibp9GrBS/mdwC6qAqVUWuuVtSTUDBZfa0x+sWpP+e3cQ9UuV2hSabGJLEVZqfDTI5JehF2Mgx2VwIJM0L1YAhxvNrFDe0FCjxVkWSXS/CDaKDWbWwN0= Authentication-Results: ti.com; dkim=none (message not signed) header.d=none;ti.com; dmarc=none action=none header.from=synaptics.com; Received: from DM6PR03MB4555.namprd03.prod.outlook.com (2603:10b6:5:102::17) by DM6PR03MB5177.namprd03.prod.outlook.com (2603:10b6:5:22b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.21; Wed, 23 Sep 2020 06:27:26 +0000 Received: from DM6PR03MB4555.namprd03.prod.outlook.com ([fe80::e494:740f:155:4a38]) by DM6PR03MB4555.namprd03.prod.outlook.com ([fe80::e494:740f:155:4a38%7]) with mapi id 15.20.3391.027; Wed, 23 Sep 2020 06:27:26 +0000 Date: Wed, 23 Sep 2020 14:26:07 +0800 From: Jisheng Zhang To: Kishon Vijay Abraham I , Lorenzo Pieralisi , Rob Herring , Bjorn Helgaas , Jingoo Han , Gustavo Pimentel , Thierry Reding , Vidya Sagar Subject: [PATCH] PCI: dwc: Move allocate and map page for msi out of dw_pcie_msi_init() Message-ID: <20200923142607.10c89bd2@xhacker.debian> X-Mailer: Claws Mail 3.17.6 (GTK+ 2.24.32; x86_64-pc-linux-gnu) X-ClientProxiedBy: TY2PR02CA0002.apcprd02.prod.outlook.com (2603:1096:404:56::14) To DM6PR03MB4555.namprd03.prod.outlook.com (2603:10b6:5:102::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from xhacker.debian (124.74.246.114) by TY2PR02CA0002.apcprd02.prod.outlook.com (2603:1096:404:56::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.20 via Frontend Transport; Wed, 23 Sep 2020 06:27:22 +0000 X-Mailer: Claws Mail 3.17.6 (GTK+ 2.24.32; x86_64-pc-linux-gnu) X-Originating-IP: [124.74.246.114] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a3b13486-19b8-45ce-3ad9-08d85f89bd23 X-MS-TrafficTypeDiagnostic: DM6PR03MB5177: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PJbmB6CgJ+ZmxBmazII9ZcpYOh36Yr00ZKjRw3WDmc7FPk8P6B1V7+b+h2v3mk+20p11Z39i1yB0o8GHZ7pYtqfjBztv9nh5BUVd5cH56lkvHrXvFIVBuUiV5x8RMJFmLlRYDKzjA1ISZQ+BkljbM7qK4fqxUPyEBYV120PsUaJ/3eQKn6tcK01LHj92Rm5r2OW4Dy6Q2IWSFJN0bJ2jkmdw0kvB0VET/rVFff8/TZTc1fLOQbu6NOjkQl4UUskIkd5pWnKgza4MAzaHsNbXREau+7Q3URGgMmc92Y4uI2Uz5rvWzGm9hWWhscFvMe6MaM20g81T5PbHkzAXYk7Qeg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM6PR03MB4555.namprd03.prod.outlook.com; PTR:; CAT:NONE; SFS:(346002)(376002)(366004)(39850400004)(136003)(396003)(9686003)(66556008)(66946007)(8936002)(16526019)(186003)(86362001)(2906002)(55016002)(83380400001)(66476007)(5660300002)(110136005)(1076003)(7416002)(316002)(6666004)(8676002)(4326008)(956004)(26005)(52116002)(7696005)(6506007)(478600001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: WB4NM5eXdSP1/kgX5jflJXTPj67rRQjlpcXBQ9JaHxBW5u4siKIOqnDsJ9ZV3IZ9pw8ln7yW/dVOzVh00SV9Ofdj8wFLOa9bof2bnFBkBA5rpvd3XFB6JA73ZOh30LKjiW3swdO+5deeZmfG3N4wHGalLLcmFF+uz892+DJpz7XVKXvXl6kP12ZW1CiwIZeiIh+Qp/4oBzhIfCKvnQIEaZxpLd6EJR2u7S8U7ZBLGAnxyTc7T/TpoR/7o8jazMFUFzIhSk3vcKHpO2gLWiwobXdpbrx3s1Ecw9Tzz7x4v04cA4B0HAR3vo7yu6NnLH1NqI4LTmw93JlT/iN2GrWQuC3yHqeOAmbKGoHqDeakcgALinyH0xePX2r7GfpgQvDjx7rfu97llycojeamfXdA3ZIJ5GJby+PYcbsYqzP/J0hAbpcBoPMkrPxUBBf4+kE0xHPptYrmQRr9PXoFvaGZrbbhzX/OSqnyk639CEaUBPph4+vraWQvN6cWBjj5LNC73N45x6dnqm1ctrU0BDtw0qOShfV6aWWjQRB3fN7lkj4ip9MnlZh1jxXs7pMrFxRV8HWvJW6ItfqK9kfQLrbmbxK8gVQoWk2uxIXcOTXUKyXOn5ofgiL2a5OdNVyq6ENchJ2Y1lcRDv3eIfKRIjMLuA== X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-Network-Message-Id: a3b13486-19b8-45ce-3ad9-08d85f89bd23 X-MS-Exchange-CrossTenant-AuthSource: DM6PR03MB4555.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2020 06:27:26.5443 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cseE0HNz6h+rvsg8S4m060FhJPs7T5kj1vwhyt7o44AiPCUfxgpad2y/j+GA/buBT/8HC+Kcg4ERIU7OhqI+Zw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR03MB5177 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200923_022729_983816_ABB99B69 X-CRM114-Status: GOOD ( 15.73 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [40.107.93.59 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [40.107.93.59 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 MSGID_FROM_MTA_HEADER Message-Id was added by a relay X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-pci@vger.kernel.org, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Currently, dw_pcie_msi_init() allocates and maps page for msi, then program the PCIE_MSI_ADDR_LO and PCIE_MSI_ADDR_HI. The Root Complex may lose power during suspend-to-RAM, so when we resume, we want to redo the latter but not the former. If designware based driver (for example, pcie-tegra194.c) calls dw_pcie_msi_init() in resume path, the previous msi page will be leaked. Move the allocate and map msi page from dw_pcie_msi_init() to dw_pcie_host_init() to fix this problem. Fixes: 56e15a238d92 ("PCI: tegra: Add Tegra194 PCIe support") Signed-off-by: Jisheng Zhang --- drivers/pci/controller/dwc/pci-dra7xx.c | 18 ++++++++++++- .../pci/controller/dwc/pcie-designware-host.c | 27 +++++++++---------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-dra7xx.c b/drivers/pci/controller/dwc/pci-dra7xx.c index dc387724cf08..4301cf844a4c 100644 --- a/drivers/pci/controller/dwc/pci-dra7xx.c +++ b/drivers/pci/controller/dwc/pci-dra7xx.c @@ -490,7 +490,9 @@ static struct irq_chip dra7xx_pci_msi_bottom_irq_chip = { static int dra7xx_pcie_msi_host_init(struct pcie_port *pp) { struct dw_pcie *pci = to_dw_pcie_from_pp(pp); + struct device *dev = pci->dev; u32 ctrl, num_ctrls; + int ret; pp->msi_irq_chip = &dra7xx_pci_msi_bottom_irq_chip; @@ -506,7 +508,21 @@ static int dra7xx_pcie_msi_host_init(struct pcie_port *pp) ~0); } - return dw_pcie_allocate_domains(pp); + ret = dw_pcie_allocate_domains(pp); + if (ret) + return ret; + + pp->msi_page = alloc_page(GFP_KERNEL); + pp->msi_data = dma_map_page(dev, pp->msi_page, 0, PAGE_SIZE, + DMA_FROM_DEVICE); + ret = dma_mapping_error(dev, pp->msi_data); + if (ret) { + dev_err(dev, "Failed to map MSI data\n"); + __free_page(pp->msi_page); + pp->msi_page = NULL; + dw_pcie_free_msi(pp); + } + return ret; } static const struct dw_pcie_host_ops dra7xx_pcie_host_ops = { diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c index 9dafecba347f..c23ba64f64fe 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -294,20 +294,7 @@ void dw_pcie_free_msi(struct pcie_port *pp) void dw_pcie_msi_init(struct pcie_port *pp) { - struct dw_pcie *pci = to_dw_pcie_from_pp(pp); - struct device *dev = pci->dev; - u64 msi_target; - - pp->msi_page = alloc_page(GFP_KERNEL); - pp->msi_data = dma_map_page(dev, pp->msi_page, 0, PAGE_SIZE, - DMA_FROM_DEVICE); - if (dma_mapping_error(dev, pp->msi_data)) { - dev_err(dev, "Failed to map MSI data\n"); - __free_page(pp->msi_page); - pp->msi_page = NULL; - return; - } - msi_target = (u64)pp->msi_data; + u64 msi_target = (u64)pp->msi_data; /* Program the msi_data */ dw_pcie_wr_own_conf(pp, PCIE_MSI_ADDR_LO, 4, @@ -440,6 +427,18 @@ int dw_pcie_host_init(struct pcie_port *pp) irq_set_chained_handler_and_data(pp->msi_irq, dw_chained_msi_isr, pp); + + pp->msi_page = alloc_page(GFP_KERNEL); + pp->msi_data = dma_map_page(pci->dev, pp->msi_page, + 0, PAGE_SIZE, + DMA_FROM_DEVICE); + ret = dma_mapping_error(pci->dev, pp->msi_data); + if (ret) { + dev_err(pci->dev, "Failed to map MSI data\n"); + __free_page(pp->msi_page); + pp->msi_page = NULL; + goto err_free_msi; + } } else { ret = pp->ops->msi_host_init(pp); if (ret < 0)