Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp963224rwe; Thu, 25 Aug 2022 12:27:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR7blZoJUtN9PZdFdqQ6nCk+uBaMoYNPK9CMu3fIuMBNVqIpxR6FabQU6B6KfPomKDgg5LbL X-Received: by 2002:a05:6402:51ce:b0:43e:74bc:dce with SMTP id r14-20020a05640251ce00b0043e74bc0dcemr4459392edd.225.1661455633829; Thu, 25 Aug 2022 12:27:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661455633; cv=none; d=google.com; s=arc-20160816; b=ef+nU+zUQ6mHM7mdrCFvoX5gJu3AQLhG3fpF7IDDJdYr9IaB3cAMdeMer677GKoEx4 297Tb9FE0I4u2KCY/e9RWYNrC0OHjIgERtH8GZIBNUZmRItMS0QgYCyBB0Ab5N4ckXyO Tbk92i9mgFbv5zojLVb3f9W2V33QgFkdUmoDb1VA2LC0YBrS7Ex86PgmoxsMA4M86dju 1hCRBvDgvpq/R7fx8lQZ/WK9OuhlTx+ze03+jen8gnOQp17U+lpgbhsOf1P7U9PbLWiI WCXnwv7F+t90WqaokfBXNxjsSZQ77tlnsod9PbkQY10hSiNS701z1ToWrqUzNjY/rO/6 Dr+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=tygyO2PFYuXfHZyst5i+EgaagTYAQzq4it8NYXlV8yE=; b=zjRutv8GRDa6ExdYmb7gVulxKzwSYeiyYop9wwaLhjXWPO91jY6zOj7ShPxpBfvgSN t6AohksdnlTgXUG4kNHNvK0Qe4OWeyf/Y2twE8aL9D2cq3LOuL2PoxSn1bbBzmmF/qHp VMPsfSpaHl/dTauoTrpeKCv3zdDJ08jgvOzWZI1K+/U6XQny74lUzQE9f7S4hXfMhPWn R06Et4Mm1xMgWw33+0VDoGuRO6sWXACRoQ7Io8IFeTaVwzq3QXP9UYgPrgXMkmxYaciY Pge5pVYYZDoa8rI5uE5rnyqFvDriMpgIxtsIvvPdRYLt4g+JY52f3nwPBhVSRYHPd72X rXAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="JYmM/Laa"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b22-20020aa7df96000000b00446b9a31a1fsi165136edy.199.2022.08.25.12.26.48; Thu, 25 Aug 2022 12:27:13 -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=@google.com header.s=20210112 header.b="JYmM/Laa"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243513AbiHYSvL (ORCPT + 99 others); Thu, 25 Aug 2022 14:51:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243487AbiHYSvG (ORCPT ); Thu, 25 Aug 2022 14:51:06 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76979B2CCE for ; Thu, 25 Aug 2022 11:51:05 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id z8-20020a17090a014800b001fac4204c7eso2927521pje.8 for ; Thu, 25 Aug 2022 11:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc; bh=tygyO2PFYuXfHZyst5i+EgaagTYAQzq4it8NYXlV8yE=; b=JYmM/LaanczpZXc8FicUlLTdPcEufZxVnfyC8MxneGRytIoEsvI7SAfJuN/mAYgSm6 CjSDRzLpYl8nMwaaQsMslKv5KFqn9KI4jiqUmuaIgEVcEXGvK+JrjnySFrsm6c5aNyXH f4yAKfroHEpTHbPvUrglrrRTArXfxj3eyItIaThw4Z6rwf5JlDK5RpjD162RRVLEFpNy jpMoQ6wiysX1/eFjvdWBYzsmF4oeY9Puesv8Y/fTXeGwq1BCfqMCJsA2v/d6C//NZ992 AMkmD4xix7H4zgyfJUtgjjZVwbMRKFb7UswG35cMEacs21Rg90D+ncxl9reAU7+OP89U OaNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc; bh=tygyO2PFYuXfHZyst5i+EgaagTYAQzq4it8NYXlV8yE=; b=FTinP3KhMmOtrpoYRpsAin1OxbXx79BWWqppt8I+/dQNB85PWK22qsleCez5+y2NmA YQH2RjfgAZRbLPPqbK14cjSgRVaRkV5i0wqZzVbMOCMDef4m8ZIuXJ6560e6FoC7vrg5 FCsYJ4wieDfpp7A9NNnyYfKJmK+yZiF+P1fUFCn0bgLzMVvDS9I7eJCHujwTGajR5BvT S8q8Idx/GQg1zUrYclO2VCf18EKGzb1DB9yLj7AISKVeqgVMgNCKCB21y2CeWGfJmhwg dBw8wnAO3qLd7pEM/cHfxdTOWftP45RXsb/SASeL+QdoVR/IFDDHYAQ9HsnQdRoPmtkz YhCg== X-Gm-Message-State: ACgBeo2bXuhr6WdKq4zxsRLUhKnSpqg/bjVCfZsoxLxWfdBYNQ8aGyYH 0Gm9+iMoS+mKdij0SAYXeOdr7ejGqe9f0M3kJRs= X-Received: from wmcvicker.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5ebe]) (user=willmcvicker job=sendgmr) by 2002:aa7:9430:0:b0:537:ab14:6cd8 with SMTP id y16-20020aa79430000000b00537ab146cd8mr328878pfo.29.1661453464664; Thu, 25 Aug 2022 11:51:04 -0700 (PDT) Date: Thu, 25 Aug 2022 18:50:24 +0000 In-Reply-To: <20220825185026.3816331-1-willmcvicker@google.com> Mime-Version: 1.0 References: <20220825185026.3816331-1-willmcvicker@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220825185026.3816331-2-willmcvicker@google.com> Subject: [PATCH v5 1/2] PCI: dwc: Drop dependency on ZONE_DMA32 From: Will McVicker To: Jingoo Han , Gustavo Pimentel , Lorenzo Pieralisi , Rob Herring , "=?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?=" , Bjorn Helgaas , Will McVicker Cc: kernel-team@android.com, Vidya Sagar , Christoph Hellwig , Robin Murphy , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, "Isaac J . Manjarres" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HK_RANDOM_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 Re-work the msi_msg DMA allocation logic to use dmam_alloc_coherent() which uses the coherent DMA mask to try to return an allocation within the DMA mask limits. With that, we now can drop the msi_page parameter in struct dw_pcie_rp. This allows kernel configurations that disable ZONE_DMA32 to continue supporting a 32-bit DMA mask. Without this patch, the PCIe host device will fail to probe when ZONE_DMA32 is disabled. Fixes: 35797e672ff0 ("PCI: dwc: Fix MSI msi_msg DMA mapping") Reported-by: Isaac J. Manjarres Signed-off-by: Will McVicker Acked-by: Jingoo Han Reviewed-by: Rob Herring --- .../pci/controller/dwc/pcie-designware-host.c | 28 +++++-------------- drivers/pci/controller/dwc/pcie-designware.h | 1 - 2 files changed, 7 insertions(+), 22 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c index 7746f94a715f..39f3b37d4033 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -267,15 +267,6 @@ static void dw_pcie_free_msi(struct dw_pcie_rp *pp) irq_domain_remove(pp->msi_domain); irq_domain_remove(pp->irq_domain); - - if (pp->msi_data) { - struct dw_pcie *pci = to_dw_pcie_from_pp(pp); - struct device *dev = pci->dev; - - dma_unmap_page(dev, pp->msi_data, PAGE_SIZE, DMA_FROM_DEVICE); - if (pp->msi_page) - __free_page(pp->msi_page); - } } static void dw_pcie_msi_init(struct dw_pcie_rp *pp) @@ -336,6 +327,7 @@ static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp) struct dw_pcie *pci = to_dw_pcie_from_pp(pp); struct device *dev = pci->dev; struct platform_device *pdev = to_platform_device(dev); + u64 *msi_vaddr; int ret; u32 ctrl, num_ctrls; @@ -375,22 +367,16 @@ static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp) dw_chained_msi_isr, pp); } - ret = dma_set_mask(dev, DMA_BIT_MASK(32)); + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); if (ret) dev_warn(dev, "Failed to set DMA mask to 32-bit. Devices with only 32-bit MSI support may not work properly\n"); - pp->msi_page = alloc_page(GFP_DMA32); - 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(pci->dev, "Failed to map MSI data\n"); - __free_page(pp->msi_page); - pp->msi_page = NULL; - pp->msi_data = 0; + msi_vaddr = dmam_alloc_coherent(dev, sizeof(u64), &pp->msi_data, + GFP_KERNEL); + if (!msi_vaddr) { + dev_err(dev, "Failed to alloc and map MSI data\n"); dw_pcie_free_msi(pp); - - return ret; + return -ENOMEM; } return 0; diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h index 09b887093a84..a871ae7eb59e 100644 --- a/drivers/pci/controller/dwc/pcie-designware.h +++ b/drivers/pci/controller/dwc/pcie-designware.h @@ -243,7 +243,6 @@ struct dw_pcie_rp { struct irq_domain *irq_domain; struct irq_domain *msi_domain; dma_addr_t msi_data; - struct page *msi_page; struct irq_chip *msi_irq_chip; u32 num_vectors; u32 irq_mask[MAX_MSI_CTRLS]; -- 2.37.2.672.g94769d06f0-goog