Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc: Fix MSI support on U4 bridge PCIe slot

On machines using the Apple U4 bridge (AKA IBM CPC945) PCIe interface such
as the latest generation G5 machines x16 slot or the x16 slot of the
PowerStation, MSIs are currently broken (and will oops when enabling).

This fixes the oops and implements proper support for those. Instead of
using the PCIe <-> HT bridge conversion, on such slots we need to use
a bunch of magic registers in the bridge as the MSI target, encoding
the interrupt number in the low bits of the address itself

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

+49 -8
+10 -1
arch/powerpc/sysdev/mpic_msi.c
··· 39 39 40 40 pr_debug("mpic: found U3, guessing msi allocator setup\n"); 41 41 42 - /* Reserve source numbers we know are reserved in the HW */ 42 + /* Reserve source numbers we know are reserved in the HW. 43 + * 44 + * This is a bit of a mix of U3 and U4 reserves but that's going 45 + * to work fine, we have plenty enugh numbers left so let's just 46 + * mark anything we don't like reserved. 47 + */ 43 48 for (i = 0; i < 8; i++) 44 49 msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i); 45 50 ··· 53 48 54 49 for (i = 100; i < 105; i++) 55 50 msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i); 51 + 52 + for (i = 124; i < mpic->irq_count; i++) 53 + msi_bitmap_reserve_hwirq(&mpic->msi_bitmap, i); 54 + 56 55 57 56 np = NULL; 58 57 while ((np = of_find_all_nodes(np))) {
+39 -7
arch/powerpc/sysdev/mpic_u3msi.c
··· 64 64 return addr; 65 65 } 66 66 67 - static u64 find_ht_magic_addr(struct pci_dev *pdev) 67 + static u64 find_ht_magic_addr(struct pci_dev *pdev, unsigned int hwirq) 68 68 { 69 69 struct pci_bus *bus; 70 70 unsigned int pos; 71 71 72 - for (bus = pdev->bus; bus; bus = bus->parent) { 72 + for (bus = pdev->bus; bus && bus->self; bus = bus->parent) { 73 73 pos = pci_find_ht_capability(bus->self, HT_CAPTYPE_MSI_MAPPING); 74 74 if (pos) 75 75 return read_ht_magic_addr(bus->self, pos); 76 76 } 77 + 78 + return 0; 79 + } 80 + 81 + static u64 find_u4_magic_addr(struct pci_dev *pdev, unsigned int hwirq) 82 + { 83 + struct pci_controller *hose = pci_bus_to_host(pdev->bus); 84 + 85 + /* U4 PCIe MSIs need to write to the special register in 86 + * the bridge that generates interrupts. There should be 87 + * theorically a register at 0xf8005000 where you just write 88 + * the MSI number and that triggers the right interrupt, but 89 + * unfortunately, this is busted in HW, the bridge endian swaps 90 + * the value and hits the wrong nibble in the register. 91 + * 92 + * So instead we use another register set which is used normally 93 + * for converting HT interrupts to MPIC interrupts, which decodes 94 + * the interrupt number as part of the low address bits 95 + * 96 + * This will not work if we ever use more than one legacy MSI in 97 + * a block but we never do. For one MSI or multiple MSI-X where 98 + * each interrupt address can be specified separately, it works 99 + * just fine. 100 + */ 101 + if (of_device_is_compatible(hose->dn, "u4-pcie") || 102 + of_device_is_compatible(hose->dn, "U4-pcie")) 103 + return 0xf8004000 | (hwirq << 4); 77 104 78 105 return 0; 79 106 } ··· 111 84 pr_debug("u3msi: MSI-X untested, trying anyway.\n"); 112 85 113 86 /* If we can't find a magic address then MSI ain't gonna work */ 114 - if (find_ht_magic_addr(pdev) == 0) { 87 + if (find_ht_magic_addr(pdev, 0) == 0 && 88 + find_u4_magic_addr(pdev, 0) == 0) { 115 89 pr_debug("u3msi: no magic address found for %s\n", 116 90 pci_name(pdev)); 117 91 return -ENXIO; ··· 146 118 u64 addr; 147 119 int hwirq; 148 120 149 - addr = find_ht_magic_addr(pdev); 150 - msg.address_lo = addr & 0xFFFFFFFF; 151 - msg.address_hi = addr >> 32; 152 - 153 121 list_for_each_entry(entry, &pdev->msi_list, list) { 154 122 hwirq = msi_bitmap_alloc_hwirqs(&msi_mpic->msi_bitmap, 1); 155 123 if (hwirq < 0) { 156 124 pr_debug("u3msi: failed allocating hwirq\n"); 157 125 return hwirq; 158 126 } 127 + 128 + addr = find_ht_magic_addr(pdev, hwirq); 129 + if (addr == 0) 130 + addr = find_u4_magic_addr(pdev, hwirq); 131 + msg.address_lo = addr & 0xFFFFFFFF; 132 + msg.address_hi = addr >> 32; 159 133 160 134 virq = irq_create_mapping(msi_mpic->irqhost, hwirq); 161 135 if (virq == NO_IRQ) { ··· 173 143 pr_debug("u3msi: allocated virq 0x%x (hw 0x%x) addr 0x%lx\n", 174 144 virq, hwirq, (unsigned long)addr); 175 145 146 + printk("u3msi: allocated virq 0x%x (hw 0x%x) addr 0x%lx\n", 147 + virq, hwirq, (unsigned long)addr); 176 148 msg.data = hwirq; 177 149 write_msi_msg(virq, &msg); 178 150