Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp964785rwe; Thu, 25 Aug 2022 12:29:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR6Lzlk8+JgtDlst7lGL1/fri5T3YWlZgg+547Gj+oZaSYErv2wFmoeuAx/pogHQkW9sj5zD X-Received: by 2002:a17:907:6e0c:b0:73d:8b64:5c3 with SMTP id sd12-20020a1709076e0c00b0073d8b6405c3mr3331130ejc.297.1661455771716; Thu, 25 Aug 2022 12:29:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661455771; cv=none; d=google.com; s=arc-20160816; b=0F8k4SGpIYeFTQAXDtsTz012LL/8ctQgBIcOG1YFbWsoTafG6oQZsC/n8EHOhxYE/W PeEAUnT45Xxp74kO0pZYb5vIbZ7COMidSend0huIJS4ESF5TCch+bhkEFti1EVNWnFBw 3j4HJz0rXdGWSd9fGTAYe/yPgiVp4R+10Yhw9HLy//ScoT8TF2iXDSxfemQLAfJOPD4S hPb2u4K4mYSQ7F8kWKiEPfs0a239XFd/9aPf13A/zdjAlZpqXotJoDQiBKvChv8C6B7b GIoubePKZcB9aTPJS1H227hlyBMOX8eszdc6xHW7gg2y3XEPjWhoqa7oPlVyepq40xnp ffqA== 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=lGAqB/GNmrDPPkV5jr9OoJ3q9SKii5qWo4ibcFCW7eo=; b=nQdymjyof/MFhQBYQ0HgXeqMiDBmTPRifzWPalpQ8oniqqQOpjNYDgWyBjz7I1Md9/ Vf8shV41RXhKmN7f/WIKSO4/4fuUW/yExeR8SViixHSCpQj1vmV91o2+8ix0xaMXncSq 9x0eWjcitvkKKID1tNwVkyMUALHba1s0q9h3vaF5F2j8XAbi8AfpEaKo1Ed0C9skT3oJ kyYgbMtrUn/MpARc7rVRTVI45a4fnYPK9X7JWy6KW59P2ZXkw4xRg4EIEHg7ZuQqLDbM 5Z5s/1NMxMgHSoSw/cgcwCP8qH0KS8L6f3d/kFSaNMY4ZRTZdmqMpnzbpAGbo1u+xkG/ 2eXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DeaANBLO; 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 g5-20020a170906538500b00718d1cddac1si3881675ejo.833.2022.08.25.12.29.06; Thu, 25 Aug 2022 12:29:31 -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=DeaANBLO; 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 S243543AbiHYSvV (ORCPT + 99 others); Thu, 25 Aug 2022 14:51:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243511AbiHYSvK (ORCPT ); Thu, 25 Aug 2022 14:51:10 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D3EBB4E83 for ; Thu, 25 Aug 2022 11:51:09 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id m34-20020a634c62000000b0042aff6dff12so3795904pgl.14 for ; Thu, 25 Aug 2022 11:51:09 -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=lGAqB/GNmrDPPkV5jr9OoJ3q9SKii5qWo4ibcFCW7eo=; b=DeaANBLOlr0ppKzAtlWXDTLwAmUNq9XIpss/f40nbT0JHkuWGR7LsYXfdKztC0j5gG HiOL2Xh6qQRXSJDdzCKZi86XRNjr6lrlmT4k65meiRrXvQq5u8rPZ3QJXOLKt7FeYyJa 5M/Z7/erNaZfGrGdUgBr3uSIceCSe5Ul3oByGVVKVt8shq0Uyl3ye9j5cfxJrHtAGBLi n8Xc1I5FWqMB/sqcuTWOL44ocC8VC8HYMbmx2Ut8ILk4wYhQrwRDmBf/8XaIc0Xt+vg/ vt0P6bTefJ956in4EEkcFKuJfzj8EmfCd7DSYWZ8D+2hdwGwyr4t4fewwhKKY6ql0aes YuxA== 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=lGAqB/GNmrDPPkV5jr9OoJ3q9SKii5qWo4ibcFCW7eo=; b=T0W0hcyPigxKEkCJjwoh04zF1MV3mb3bkKbXMnz2D5JM+LUhkcn7HLv6/B3a9TSZdw e/RxBecxOjSB5SLwLowxu1CIJJcCX5OTkGN/MJZPd+GyukJ9HP9BglS23dqpXIUkTsHn Ctw0klEWoTTQNt+yAQ+b2zPnJKc+5umSkHj74FZCFftuNvQ9Xkp0NQaXr/PwwM0f5KjZ 1kLR6XdkHSofil3ncGsoep/iYt+GM8rEqcOpgUL/M7r/WHUBSMpjB8M2X+734OtPZrot 5mqcRDe1+ReoJpCo0wfPGddlALNii8BZxjGQxjyJc9+CgHL0iT5Ckl0aGXEzOiVltlhw 1ung== X-Gm-Message-State: ACgBeo0GRw1PpAKLkSINRZaCNNfXN49OLHieqh1mUIQOnpyqFvlSmH2c Dw8G/GnrH/18abEI6vhgwbFU/T0G/TPuZkkVJWI= X-Received: from wmcvicker.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5ebe]) (user=willmcvicker job=sendgmr) by 2002:a17:90a:e558:b0:1fb:c4b7:1a24 with SMTP id ei24-20020a17090ae55800b001fbc4b71a24mr19452pjb.1.1661453467971; Thu, 25 Aug 2022 11:51:07 -0700 (PDT) Date: Thu, 25 Aug 2022 18:50:25 +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-3-willmcvicker@google.com> Subject: [PATCH v5 2/2] PCI: dwc: Add support for 64-bit MSI target address 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, kernel test robot 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 Since not all devices require a 32-bit MSI address, add support to the PCIe host driver to allow setting the DMA mask to 64-bits if the 32-bit allocation fails. This allows kernels to disable ZONE_DMA32 and bounce buffering (swiotlb) without risking not being able to get a 32-bit address during DMA allocation. Basically, in the slim chance that there are no 32-bit allocations available, the current PCIe host driver will fail to allocate the msi_msg page due to a DMA address overflow (seen in [1]). With this patch, the PCIe host can retry the allocation with a 64-bit DMA mask if the current PCIe device advertises 64-bit support via its MSI capabilities. [1] https://lore.kernel.org/all/Yo0soniFborDl7+C@google.com/ Reported-by: kernel test robot Signed-off-by: Will McVicker Reviewed-by: Rob Herring Acked-by: Jingoo Han --- .../pci/controller/dwc/pcie-designware-host.c | 38 ++++++++++++++----- drivers/pci/controller/dwc/pcie-designware.c | 8 ++++ drivers/pci/controller/dwc/pcie-designware.h | 1 + 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-designware-host.c b/drivers/pci/controller/dwc/pcie-designware-host.c index 39f3b37d4033..8928a9a29d58 100644 --- a/drivers/pci/controller/dwc/pcie-designware-host.c +++ b/drivers/pci/controller/dwc/pcie-designware-host.c @@ -330,6 +330,9 @@ static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp) u64 *msi_vaddr; int ret; u32 ctrl, num_ctrls; + bool msi_64bit = false; + bool retry_64bit = false; + u16 msi_capabilities; for (ctrl = 0; ctrl < MAX_MSI_CTRLS; ctrl++) pp->irq_mask[ctrl] = ~0; @@ -367,16 +370,33 @@ static int dw_pcie_msi_host_init(struct dw_pcie_rp *pp) dw_chained_msi_isr, pp); } - 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"); + msi_capabilities = dw_pcie_msi_capabilities(pci); + if (msi_capabilities & PCI_MSI_FLAGS_ENABLE) + msi_64bit = msi_capabilities & PCI_MSI_FLAGS_64BIT; - 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 -ENOMEM; + while (true) { + dev_dbg(dev, "Setting MSI DMA mask to %s-bit.\n", + retry_64bit ? "64" : "32"); + ret = dma_set_mask_and_coherent(dev, retry_64bit ? + DMA_BIT_MASK(64) : + DMA_BIT_MASK(32)); + if (ret) + dev_warn(dev, "Failed to set DMA mask to %s-bit.\n", + retry_64bit ? "64" : "32"); + + 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"); + if (msi_64bit && !retry_64bit) { + retry_64bit = true; + continue; + } + + dw_pcie_free_msi(pp); + return -ENOMEM; + } + break; } return 0; diff --git a/drivers/pci/controller/dwc/pcie-designware.c b/drivers/pci/controller/dwc/pcie-designware.c index c6725c519a47..650a7f22f9d0 100644 --- a/drivers/pci/controller/dwc/pcie-designware.c +++ b/drivers/pci/controller/dwc/pcie-designware.c @@ -82,6 +82,14 @@ u8 dw_pcie_find_capability(struct dw_pcie *pci, u8 cap) } EXPORT_SYMBOL_GPL(dw_pcie_find_capability); +u16 dw_pcie_msi_capabilities(struct dw_pcie *pci) +{ + u8 offset; + + offset = dw_pcie_find_capability(pci, PCI_CAP_ID_MSI); + return dw_pcie_readw_dbi(pci, offset + PCI_MSI_FLAGS); +} + static u16 dw_pcie_find_next_ext_capability(struct dw_pcie *pci, u16 start, u8 cap) { diff --git a/drivers/pci/controller/dwc/pcie-designware.h b/drivers/pci/controller/dwc/pcie-designware.h index a871ae7eb59e..45fcdfc8c035 100644 --- a/drivers/pci/controller/dwc/pcie-designware.h +++ b/drivers/pci/controller/dwc/pcie-designware.h @@ -332,6 +332,7 @@ void dw_pcie_version_detect(struct dw_pcie *pci); u8 dw_pcie_find_capability(struct dw_pcie *pci, u8 cap); u16 dw_pcie_find_ext_capability(struct dw_pcie *pci, u8 cap); +u16 dw_pcie_msi_capabilities(struct dw_pcie *pci); int dw_pcie_read(void __iomem *addr, int size, u32 *val); int dw_pcie_write(void __iomem *addr, int size, u32 val); -- 2.37.2.672.g94769d06f0-goog