]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PCI/MSI: Convert the boolean no_64bit_msi flag to a DMA address mask
authorVivian Wang <wangruikang@iscas.ac.cn>
Thu, 29 Jan 2026 01:56:06 +0000 (09:56 +0800)
committerThomas Gleixner <tglx@kernel.org>
Sat, 31 Jan 2026 00:11:48 +0000 (01:11 +0100)
Some PCI devices have PCI_MSI_FLAGS_64BIT in the MSI capability, but
implement less than 64 address bits. This breaks on platforms where such
a device is assigned an MSI address higher than what's supported.

Currently, no_64bit_msi bit is set for these devices, meaning that only
32-bit MSI addresses are allowed for them. However, on some platforms the
MSI doorbell address is above the 32-bit limit but within the addressable
range of the device.

As a first step to enable MSI on those combinations of devices and
platforms, convert the boolean no_64bit_msi flag to a DMA mask and fixup
the affected usage sites:

  - no_64bit_msi = 1    ->    msi_addr_mask = DMA_BIT_MASK(32)
  - no_64bit_msi = 0    ->    msi_addr_mask = DMA_BIT_MASK(64)
  - if (no_64bit_msi)   ->    if (msi_addr_mask < DMA_BIT_MASK(64))

Since no values other than DMA_BIT_MASK(32) and DMA_BIT_MASK(64) are used,
this is functionally equivalent.

This prepares for changing the binary decision between 32 and 64 bit to a
DMA mask based decision which allows to support systems which have a DMA
address space less than 64bit but a MSI doorbell address above the 32-bit
limit.

[ tglx: Massaged changelog ]

Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Reviewed-by: Brett Creeley <brett.creeley@amd.com> # ionic
Reviewed-by: Thomas Gleixner <tglx@kernel.org>
Acked-by: Takashi Iwai <tiwai@suse.de> # sound
Link: https://patch.msgid.link/20260129-pci-msi-addr-mask-v4-1-70da998f2750@iscas.ac.cn
arch/powerpc/platforms/powernv/pci-ioda.c
arch/powerpc/platforms/pseries/msi.c
drivers/gpu/drm/radeon/radeon_irq_kms.c
drivers/net/ethernet/pensando/ionic/ionic_bus_pci.c
drivers/pci/msi/msi.c
drivers/pci/msi/pcidev_msi.c
drivers/pci/probe.c
include/linux/pci.h
sound/hda/controllers/intel.c

index b0c1d9d16fb52c93d28c6bb3ac11b64b9fed224a..1c78fdfb7b0366865db7a652d9a13cddf74a4667 100644 (file)
@@ -1666,7 +1666,7 @@ static int __pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev,
                return -ENXIO;
 
        /* Force 32-bit MSI on some broken devices */
-       if (dev->no_64bit_msi)
+       if (dev->msi_addr_mask < DMA_BIT_MASK(64))
                is_64 = 0;
 
        /* Assign XIVE to PE */
index a82aaa786e9e02cb4a6cec1fe076186ad960ed46..7473c7ca1db07eb9f6f02cdeb30ca86b66da1bd7 100644 (file)
@@ -383,7 +383,7 @@ static int rtas_prepare_msi_irqs(struct pci_dev *pdev, int nvec_in, int type,
         */
 again:
        if (type == PCI_CAP_ID_MSI) {
-               if (pdev->no_64bit_msi) {
+               if (pdev->msi_addr_mask < DMA_BIT_MASK(64)) {
                        rc = rtas_change_msi(pdn, RTAS_CHANGE_32MSI_FN, nvec);
                        if (rc < 0) {
                                /*
@@ -409,7 +409,7 @@ again:
                if (use_32bit_msi_hack && rc > 0)
                        rtas_hack_32bit_msi_gen2(pdev);
        } else {
-               if (pdev->no_64bit_msi)
+               if (pdev->msi_addr_mask < DMA_BIT_MASK(64))
                        rc = rtas_change_msi(pdn, RTAS_CHANGE_32MSIX_FN, nvec);
                else
                        rc = rtas_change_msi(pdn, RTAS_CHANGE_MSIX_FN, nvec);
index 9961251b44ba0624c94fe3481aa7d84ac31f8687..d550554a6f3f2d64faf09b72431c206d0bb385ca 100644 (file)
@@ -252,7 +252,7 @@ static bool radeon_msi_ok(struct radeon_device *rdev)
         */
        if (rdev->family < CHIP_BONAIRE) {
                dev_info(rdev->dev, "radeon: MSI limited to 32-bit\n");
-               rdev->pdev->no_64bit_msi = 1;
+               rdev->pdev->msi_addr_mask = DMA_BIT_MASK(32);
        }
 
        /* force MSI on */
index 70d86c5f52fbb607eab22d1e900b76b3c69554ce..0671deae9a28605aec3886884e15d0187520d34d 100644 (file)
@@ -331,7 +331,7 @@ static int ionic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 #ifdef CONFIG_PPC64
        /* Ensure MSI/MSI-X interrupts lie within addressable physical memory */
-       pdev->no_64bit_msi = 1;
+       pdev->msi_addr_mask = DMA_BIT_MASK(32);
 #endif
 
        err = ionic_setup_one(ionic);
index e010ecd9f90dde998fec30c4b87cee6c86044141..fb9a42bec62eb2dc42760ce91a0d32b015b6ac3d 100644 (file)
@@ -322,7 +322,7 @@ static int msi_verify_entries(struct pci_dev *dev)
 {
        struct msi_desc *entry;
 
-       if (!dev->no_64bit_msi)
+       if (dev->msi_addr_mask == DMA_BIT_MASK(64))
                return 0;
 
        msi_for_each_desc(entry, &dev->dev, MSI_DESC_ALL) {
index 5520aff53b5670e70311c63f0f358228bf03c309..0b034681309265ce8ea862c31c3ca41106b789f5 100644 (file)
@@ -24,7 +24,7 @@ void pci_msi_init(struct pci_dev *dev)
        }
 
        if (!(ctrl & PCI_MSI_FLAGS_64BIT))
-               dev->no_64bit_msi = 1;
+               dev->msi_addr_mask = DMA_BIT_MASK(32);
 }
 
 void pci_msix_init(struct pci_dev *dev)
index 41183aed8f5d94c514e9d1787107999acbba7c4f..a2bff57176a37503f8b3b96377e939a9d826994d 100644 (file)
@@ -2047,6 +2047,13 @@ int pci_setup_device(struct pci_dev *dev)
         */
        dev->dma_mask = 0xffffffff;
 
+       /*
+        * Assume 64-bit addresses for MSI initially. Will be changed to 32-bit
+        * if MSI (rather than MSI-X) capability does not have
+        * PCI_MSI_FLAGS_64BIT. Can also be overridden by driver.
+        */
+       dev->msi_addr_mask = DMA_BIT_MASK(64);
+
        dev_set_name(&dev->dev, "%04x:%02x:%02x.%d", pci_domain_nr(dev->bus),
                     dev->bus->number, PCI_SLOT(dev->devfn),
                     PCI_FUNC(dev->devfn));
index 864775651c6fae125972cdfb062fd4d684cf294c..0fe32fef033155bacad5e6156a1b4f5c0be9fdf6 100644 (file)
@@ -377,6 +377,13 @@ struct pci_dev {
                                           0xffffffff.  You only need to change
                                           this if your device has broken DMA
                                           or supports 64-bit transfers.  */
+       u64             msi_addr_mask;  /* Mask of the bits of bus address for
+                                          MSI that this device implements.
+                                          Normally set based on device
+                                          capabilities. You only need to
+                                          change this if your device claims
+                                          to support 64-bit MSI but implements
+                                          fewer than 64 address bits. */
 
        struct device_dma_parameters dma_parms;
 
@@ -441,7 +448,6 @@ struct pci_dev {
 
        unsigned int    is_busmaster:1;         /* Is busmaster */
        unsigned int    no_msi:1;               /* May not use MSI */
-       unsigned int    no_64bit_msi:1;         /* May only use 32-bit MSIs */
        unsigned int    block_cfg_access:1;     /* Config space access blocked */
        unsigned int    broken_parity_status:1; /* Generates false positive parity */
        unsigned int    irq_reroute_variant:2;  /* Needs IRQ rerouting variant */
index 1e8e3d61291a11a1f99928248d0a736655462f04..c9542ebdf7e2b7eb0ae13b5246e9c57c500f9747 100644 (file)
@@ -1905,7 +1905,7 @@ static int azx_first_init(struct azx *chip)
 
        if (chip->msi && chip->driver_caps & AZX_DCAPS_NO_MSI64) {
                dev_dbg(card->dev, "Disabling 64bit MSI\n");
-               pci->no_64bit_msi = true;
+               pci->msi_addr_mask = DMA_BIT_MASK(32);
        }
 
        pci_set_master(pci);