Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Support PCI/PCIe on PowerNV platforms |
| 3 | * |
| 4 | * Currently supports only P5IOC2 |
| 5 | * |
| 6 | * Copyright 2011 Benjamin Herrenschmidt, IBM Corp. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * as published by the Free Software Foundation; either version |
| 11 | * 2 of the License, or (at your option) any later version. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/pci.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/string.h> |
| 18 | #include <linux/init.h> |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 19 | #include <linux/irq.h> |
| 20 | #include <linux/io.h> |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 21 | #include <linux/msi.h> |
Alexey Kardashevskiy | 4e13c1a | 2013-05-21 13:33:09 +1000 | [diff] [blame] | 22 | #include <linux/iommu.h> |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 23 | |
| 24 | #include <asm/sections.h> |
| 25 | #include <asm/io.h> |
| 26 | #include <asm/prom.h> |
| 27 | #include <asm/pci-bridge.h> |
| 28 | #include <asm/machdep.h> |
Gavin Shan | fb1b55d | 2013-03-05 21:12:37 +0000 | [diff] [blame] | 29 | #include <asm/msi_bitmap.h> |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 30 | #include <asm/ppc-pci.h> |
| 31 | #include <asm/opal.h> |
| 32 | #include <asm/iommu.h> |
| 33 | #include <asm/tce.h> |
Stephen Rothwell | f533927 | 2012-03-15 18:18:00 +0000 | [diff] [blame] | 34 | #include <asm/firmware.h> |
Gavin Shan | be7e744 | 2013-06-20 13:21:15 +0800 | [diff] [blame] | 35 | #include <asm/eeh_event.h> |
| 36 | #include <asm/eeh.h> |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 37 | |
| 38 | #include "powernv.h" |
| 39 | #include "pci.h" |
| 40 | |
Benjamin Herrenschmidt | 82ba129 | 2011-09-19 17:45:07 +0000 | [diff] [blame] | 41 | /* Delay in usec */ |
| 42 | #define PCI_RESET_DELAY_US 3000000 |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 43 | |
| 44 | #define cfg_dbg(fmt...) do { } while(0) |
| 45 | //#define cfg_dbg(fmt...) printk(fmt) |
| 46 | |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 47 | #ifdef CONFIG_PCI_MSI |
Daniel Axtens | 92ae035 | 2015-04-28 15:12:05 +1000 | [diff] [blame] | 48 | int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type) |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 49 | { |
| 50 | struct pci_controller *hose = pci_bus_to_host(pdev->bus); |
| 51 | struct pnv_phb *phb = hose->private_data; |
| 52 | struct msi_desc *entry; |
| 53 | struct msi_msg msg; |
Gavin Shan | fb1b55d | 2013-03-05 21:12:37 +0000 | [diff] [blame] | 54 | int hwirq; |
| 55 | unsigned int virq; |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 56 | int rc; |
| 57 | |
Alexander Gordeev | 6b2fd7ef | 2014-09-07 20:57:53 +0200 | [diff] [blame] | 58 | if (WARN_ON(!phb) || !phb->msi_bmp.bitmap) |
| 59 | return -ENODEV; |
| 60 | |
Benjamin Herrenschmidt | 3607438 | 2014-10-07 16:12:36 +1100 | [diff] [blame] | 61 | if (pdev->no_64bit_msi && !phb->msi32_support) |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 62 | return -ENODEV; |
| 63 | |
| 64 | list_for_each_entry(entry, &pdev->msi_list, list) { |
| 65 | if (!entry->msi_attrib.is_64 && !phb->msi32_support) { |
| 66 | pr_warn("%s: Supports only 64-bit MSIs\n", |
| 67 | pci_name(pdev)); |
| 68 | return -ENXIO; |
| 69 | } |
Gavin Shan | fb1b55d | 2013-03-05 21:12:37 +0000 | [diff] [blame] | 70 | hwirq = msi_bitmap_alloc_hwirqs(&phb->msi_bmp, 1); |
| 71 | if (hwirq < 0) { |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 72 | pr_warn("%s: Failed to find a free MSI\n", |
| 73 | pci_name(pdev)); |
| 74 | return -ENOSPC; |
| 75 | } |
Gavin Shan | fb1b55d | 2013-03-05 21:12:37 +0000 | [diff] [blame] | 76 | virq = irq_create_mapping(NULL, phb->msi_base + hwirq); |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 77 | if (virq == NO_IRQ) { |
| 78 | pr_warn("%s: Failed to map MSI to linux irq\n", |
| 79 | pci_name(pdev)); |
Gavin Shan | fb1b55d | 2013-03-05 21:12:37 +0000 | [diff] [blame] | 80 | msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq, 1); |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 81 | return -ENOMEM; |
| 82 | } |
Gavin Shan | fb1b55d | 2013-03-05 21:12:37 +0000 | [diff] [blame] | 83 | rc = phb->msi_setup(phb, pdev, phb->msi_base + hwirq, |
Gavin Shan | 137436c | 2013-04-25 19:20:59 +0000 | [diff] [blame] | 84 | virq, entry->msi_attrib.is_64, &msg); |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 85 | if (rc) { |
| 86 | pr_warn("%s: Failed to setup MSI\n", pci_name(pdev)); |
| 87 | irq_dispose_mapping(virq); |
Gavin Shan | fb1b55d | 2013-03-05 21:12:37 +0000 | [diff] [blame] | 88 | msi_bitmap_free_hwirqs(&phb->msi_bmp, hwirq, 1); |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 89 | return rc; |
| 90 | } |
| 91 | irq_set_msi_desc(virq, entry); |
Jiang Liu | 83a1891 | 2014-11-09 23:10:34 +0800 | [diff] [blame] | 92 | pci_write_msi_msg(virq, &msg); |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 93 | } |
| 94 | return 0; |
| 95 | } |
| 96 | |
Daniel Axtens | 92ae035 | 2015-04-28 15:12:05 +1000 | [diff] [blame] | 97 | void pnv_teardown_msi_irqs(struct pci_dev *pdev) |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 98 | { |
| 99 | struct pci_controller *hose = pci_bus_to_host(pdev->bus); |
| 100 | struct pnv_phb *phb = hose->private_data; |
| 101 | struct msi_desc *entry; |
| 102 | |
| 103 | if (WARN_ON(!phb)) |
| 104 | return; |
| 105 | |
| 106 | list_for_each_entry(entry, &pdev->msi_list, list) { |
| 107 | if (entry->irq == NO_IRQ) |
| 108 | continue; |
| 109 | irq_set_msi_desc(entry->irq, NULL); |
Gavin Shan | fb1b55d | 2013-03-05 21:12:37 +0000 | [diff] [blame] | 110 | msi_bitmap_free_hwirqs(&phb->msi_bmp, |
| 111 | virq_to_hw(entry->irq) - phb->msi_base, 1); |
Benjamin Herrenschmidt | c1a2562 | 2011-09-19 17:45:06 +0000 | [diff] [blame] | 112 | irq_dispose_mapping(entry->irq); |
| 113 | } |
| 114 | } |
| 115 | #endif /* CONFIG_PCI_MSI */ |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 116 | |
Gavin Shan | 93aef2a | 2013-11-22 16:28:45 +0800 | [diff] [blame] | 117 | static void pnv_pci_dump_p7ioc_diag_data(struct pci_controller *hose, |
| 118 | struct OpalIoPhbErrorCommon *common) |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 119 | { |
Gavin Shan | 93aef2a | 2013-11-22 16:28:45 +0800 | [diff] [blame] | 120 | struct OpalIoP7IOCPhbErrorData *data; |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 121 | int i; |
| 122 | |
Gavin Shan | 93aef2a | 2013-11-22 16:28:45 +0800 | [diff] [blame] | 123 | data = (struct OpalIoP7IOCPhbErrorData *)common; |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 124 | pr_info("P7IOC PHB#%d Diag-data (Version: %d)\n", |
Gavin Shan | f18440f | 2014-07-17 14:41:42 +1000 | [diff] [blame] | 125 | hose->global_number, be32_to_cpu(common->version)); |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 126 | |
Gavin Shan | af87d2f | 2014-02-25 15:28:38 +0800 | [diff] [blame] | 127 | if (data->brdgCtl) |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 128 | pr_info("brdgCtl: %08x\n", |
Gavin Shan | f18440f | 2014-07-17 14:41:42 +1000 | [diff] [blame] | 129 | be32_to_cpu(data->brdgCtl)); |
Gavin Shan | af87d2f | 2014-02-25 15:28:38 +0800 | [diff] [blame] | 130 | if (data->portStatusReg || data->rootCmplxStatus || |
| 131 | data->busAgentStatus) |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 132 | pr_info("UtlSts: %08x %08x %08x\n", |
Gavin Shan | f18440f | 2014-07-17 14:41:42 +1000 | [diff] [blame] | 133 | be32_to_cpu(data->portStatusReg), |
| 134 | be32_to_cpu(data->rootCmplxStatus), |
| 135 | be32_to_cpu(data->busAgentStatus)); |
Gavin Shan | af87d2f | 2014-02-25 15:28:38 +0800 | [diff] [blame] | 136 | if (data->deviceStatus || data->slotStatus || |
| 137 | data->linkStatus || data->devCmdStatus || |
| 138 | data->devSecStatus) |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 139 | pr_info("RootSts: %08x %08x %08x %08x %08x\n", |
Gavin Shan | f18440f | 2014-07-17 14:41:42 +1000 | [diff] [blame] | 140 | be32_to_cpu(data->deviceStatus), |
| 141 | be32_to_cpu(data->slotStatus), |
| 142 | be32_to_cpu(data->linkStatus), |
| 143 | be32_to_cpu(data->devCmdStatus), |
| 144 | be32_to_cpu(data->devSecStatus)); |
Gavin Shan | af87d2f | 2014-02-25 15:28:38 +0800 | [diff] [blame] | 145 | if (data->rootErrorStatus || data->uncorrErrorStatus || |
| 146 | data->corrErrorStatus) |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 147 | pr_info("RootErrSts: %08x %08x %08x\n", |
Gavin Shan | f18440f | 2014-07-17 14:41:42 +1000 | [diff] [blame] | 148 | be32_to_cpu(data->rootErrorStatus), |
| 149 | be32_to_cpu(data->uncorrErrorStatus), |
| 150 | be32_to_cpu(data->corrErrorStatus)); |
Gavin Shan | af87d2f | 2014-02-25 15:28:38 +0800 | [diff] [blame] | 151 | if (data->tlpHdr1 || data->tlpHdr2 || |
| 152 | data->tlpHdr3 || data->tlpHdr4) |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 153 | pr_info("RootErrLog: %08x %08x %08x %08x\n", |
Gavin Shan | f18440f | 2014-07-17 14:41:42 +1000 | [diff] [blame] | 154 | be32_to_cpu(data->tlpHdr1), |
| 155 | be32_to_cpu(data->tlpHdr2), |
| 156 | be32_to_cpu(data->tlpHdr3), |
| 157 | be32_to_cpu(data->tlpHdr4)); |
Gavin Shan | af87d2f | 2014-02-25 15:28:38 +0800 | [diff] [blame] | 158 | if (data->sourceId || data->errorClass || |
| 159 | data->correlator) |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 160 | pr_info("RootErrLog1: %08x %016llx %016llx\n", |
Gavin Shan | f18440f | 2014-07-17 14:41:42 +1000 | [diff] [blame] | 161 | be32_to_cpu(data->sourceId), |
| 162 | be64_to_cpu(data->errorClass), |
| 163 | be64_to_cpu(data->correlator)); |
Gavin Shan | af87d2f | 2014-02-25 15:28:38 +0800 | [diff] [blame] | 164 | if (data->p7iocPlssr || data->p7iocCsr) |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 165 | pr_info("PhbSts: %016llx %016llx\n", |
Gavin Shan | f18440f | 2014-07-17 14:41:42 +1000 | [diff] [blame] | 166 | be64_to_cpu(data->p7iocPlssr), |
| 167 | be64_to_cpu(data->p7iocCsr)); |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 168 | if (data->lemFir) |
| 169 | pr_info("Lem: %016llx %016llx %016llx\n", |
Gavin Shan | f18440f | 2014-07-17 14:41:42 +1000 | [diff] [blame] | 170 | be64_to_cpu(data->lemFir), |
| 171 | be64_to_cpu(data->lemErrorMask), |
| 172 | be64_to_cpu(data->lemWOF)); |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 173 | if (data->phbErrorStatus) |
| 174 | pr_info("PhbErr: %016llx %016llx %016llx %016llx\n", |
Gavin Shan | f18440f | 2014-07-17 14:41:42 +1000 | [diff] [blame] | 175 | be64_to_cpu(data->phbErrorStatus), |
| 176 | be64_to_cpu(data->phbFirstErrorStatus), |
| 177 | be64_to_cpu(data->phbErrorLog0), |
| 178 | be64_to_cpu(data->phbErrorLog1)); |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 179 | if (data->mmioErrorStatus) |
| 180 | pr_info("OutErr: %016llx %016llx %016llx %016llx\n", |
Gavin Shan | f18440f | 2014-07-17 14:41:42 +1000 | [diff] [blame] | 181 | be64_to_cpu(data->mmioErrorStatus), |
| 182 | be64_to_cpu(data->mmioFirstErrorStatus), |
| 183 | be64_to_cpu(data->mmioErrorLog0), |
| 184 | be64_to_cpu(data->mmioErrorLog1)); |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 185 | if (data->dma0ErrorStatus) |
| 186 | pr_info("InAErr: %016llx %016llx %016llx %016llx\n", |
Gavin Shan | f18440f | 2014-07-17 14:41:42 +1000 | [diff] [blame] | 187 | be64_to_cpu(data->dma0ErrorStatus), |
| 188 | be64_to_cpu(data->dma0FirstErrorStatus), |
| 189 | be64_to_cpu(data->dma0ErrorLog0), |
| 190 | be64_to_cpu(data->dma0ErrorLog1)); |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 191 | if (data->dma1ErrorStatus) |
| 192 | pr_info("InBErr: %016llx %016llx %016llx %016llx\n", |
Gavin Shan | f18440f | 2014-07-17 14:41:42 +1000 | [diff] [blame] | 193 | be64_to_cpu(data->dma1ErrorStatus), |
| 194 | be64_to_cpu(data->dma1FirstErrorStatus), |
| 195 | be64_to_cpu(data->dma1ErrorLog0), |
| 196 | be64_to_cpu(data->dma1ErrorLog1)); |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 197 | |
| 198 | for (i = 0; i < OPAL_P7IOC_NUM_PEST_REGS; i++) { |
| 199 | if ((data->pestA[i] >> 63) == 0 && |
| 200 | (data->pestB[i] >> 63) == 0) |
| 201 | continue; |
Gavin Shan | 93aef2a | 2013-11-22 16:28:45 +0800 | [diff] [blame] | 202 | |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 203 | pr_info("PE[%3d] A/B: %016llx %016llx\n", |
Gavin Shan | f18440f | 2014-07-17 14:41:42 +1000 | [diff] [blame] | 204 | i, be64_to_cpu(data->pestA[i]), |
| 205 | be64_to_cpu(data->pestB[i])); |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
Gavin Shan | 93aef2a | 2013-11-22 16:28:45 +0800 | [diff] [blame] | 209 | static void pnv_pci_dump_phb3_diag_data(struct pci_controller *hose, |
| 210 | struct OpalIoPhbErrorCommon *common) |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 211 | { |
Gavin Shan | 93aef2a | 2013-11-22 16:28:45 +0800 | [diff] [blame] | 212 | struct OpalIoPhb3ErrorData *data; |
| 213 | int i; |
| 214 | |
| 215 | data = (struct OpalIoPhb3ErrorData*)common; |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 216 | pr_info("PHB3 PHB#%d Diag-data (Version: %d)\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 217 | hose->global_number, be32_to_cpu(common->version)); |
Gavin Shan | af87d2f | 2014-02-25 15:28:38 +0800 | [diff] [blame] | 218 | if (data->brdgCtl) |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 219 | pr_info("brdgCtl: %08x\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 220 | be32_to_cpu(data->brdgCtl)); |
Gavin Shan | af87d2f | 2014-02-25 15:28:38 +0800 | [diff] [blame] | 221 | if (data->portStatusReg || data->rootCmplxStatus || |
| 222 | data->busAgentStatus) |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 223 | pr_info("UtlSts: %08x %08x %08x\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 224 | be32_to_cpu(data->portStatusReg), |
| 225 | be32_to_cpu(data->rootCmplxStatus), |
| 226 | be32_to_cpu(data->busAgentStatus)); |
Gavin Shan | af87d2f | 2014-02-25 15:28:38 +0800 | [diff] [blame] | 227 | if (data->deviceStatus || data->slotStatus || |
| 228 | data->linkStatus || data->devCmdStatus || |
| 229 | data->devSecStatus) |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 230 | pr_info("RootSts: %08x %08x %08x %08x %08x\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 231 | be32_to_cpu(data->deviceStatus), |
| 232 | be32_to_cpu(data->slotStatus), |
| 233 | be32_to_cpu(data->linkStatus), |
| 234 | be32_to_cpu(data->devCmdStatus), |
| 235 | be32_to_cpu(data->devSecStatus)); |
Gavin Shan | af87d2f | 2014-02-25 15:28:38 +0800 | [diff] [blame] | 236 | if (data->rootErrorStatus || data->uncorrErrorStatus || |
| 237 | data->corrErrorStatus) |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 238 | pr_info("RootErrSts: %08x %08x %08x\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 239 | be32_to_cpu(data->rootErrorStatus), |
| 240 | be32_to_cpu(data->uncorrErrorStatus), |
| 241 | be32_to_cpu(data->corrErrorStatus)); |
Gavin Shan | af87d2f | 2014-02-25 15:28:38 +0800 | [diff] [blame] | 242 | if (data->tlpHdr1 || data->tlpHdr2 || |
| 243 | data->tlpHdr3 || data->tlpHdr4) |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 244 | pr_info("RootErrLog: %08x %08x %08x %08x\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 245 | be32_to_cpu(data->tlpHdr1), |
| 246 | be32_to_cpu(data->tlpHdr2), |
| 247 | be32_to_cpu(data->tlpHdr3), |
| 248 | be32_to_cpu(data->tlpHdr4)); |
Gavin Shan | af87d2f | 2014-02-25 15:28:38 +0800 | [diff] [blame] | 249 | if (data->sourceId || data->errorClass || |
| 250 | data->correlator) |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 251 | pr_info("RootErrLog1: %08x %016llx %016llx\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 252 | be32_to_cpu(data->sourceId), |
| 253 | be64_to_cpu(data->errorClass), |
| 254 | be64_to_cpu(data->correlator)); |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 255 | if (data->nFir) |
| 256 | pr_info("nFir: %016llx %016llx %016llx\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 257 | be64_to_cpu(data->nFir), |
| 258 | be64_to_cpu(data->nFirMask), |
| 259 | be64_to_cpu(data->nFirWOF)); |
Gavin Shan | af87d2f | 2014-02-25 15:28:38 +0800 | [diff] [blame] | 260 | if (data->phbPlssr || data->phbCsr) |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 261 | pr_info("PhbSts: %016llx %016llx\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 262 | be64_to_cpu(data->phbPlssr), |
| 263 | be64_to_cpu(data->phbCsr)); |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 264 | if (data->lemFir) |
| 265 | pr_info("Lem: %016llx %016llx %016llx\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 266 | be64_to_cpu(data->lemFir), |
| 267 | be64_to_cpu(data->lemErrorMask), |
| 268 | be64_to_cpu(data->lemWOF)); |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 269 | if (data->phbErrorStatus) |
| 270 | pr_info("PhbErr: %016llx %016llx %016llx %016llx\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 271 | be64_to_cpu(data->phbErrorStatus), |
| 272 | be64_to_cpu(data->phbFirstErrorStatus), |
| 273 | be64_to_cpu(data->phbErrorLog0), |
| 274 | be64_to_cpu(data->phbErrorLog1)); |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 275 | if (data->mmioErrorStatus) |
| 276 | pr_info("OutErr: %016llx %016llx %016llx %016llx\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 277 | be64_to_cpu(data->mmioErrorStatus), |
| 278 | be64_to_cpu(data->mmioFirstErrorStatus), |
| 279 | be64_to_cpu(data->mmioErrorLog0), |
| 280 | be64_to_cpu(data->mmioErrorLog1)); |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 281 | if (data->dma0ErrorStatus) |
| 282 | pr_info("InAErr: %016llx %016llx %016llx %016llx\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 283 | be64_to_cpu(data->dma0ErrorStatus), |
| 284 | be64_to_cpu(data->dma0FirstErrorStatus), |
| 285 | be64_to_cpu(data->dma0ErrorLog0), |
| 286 | be64_to_cpu(data->dma0ErrorLog1)); |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 287 | if (data->dma1ErrorStatus) |
| 288 | pr_info("InBErr: %016llx %016llx %016llx %016llx\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 289 | be64_to_cpu(data->dma1ErrorStatus), |
| 290 | be64_to_cpu(data->dma1FirstErrorStatus), |
| 291 | be64_to_cpu(data->dma1ErrorLog0), |
| 292 | be64_to_cpu(data->dma1ErrorLog1)); |
Gavin Shan | 93aef2a | 2013-11-22 16:28:45 +0800 | [diff] [blame] | 293 | |
| 294 | for (i = 0; i < OPAL_PHB3_NUM_PEST_REGS; i++) { |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 295 | if ((be64_to_cpu(data->pestA[i]) >> 63) == 0 && |
| 296 | (be64_to_cpu(data->pestB[i]) >> 63) == 0) |
Gavin Shan | 93aef2a | 2013-11-22 16:28:45 +0800 | [diff] [blame] | 297 | continue; |
| 298 | |
Gavin Shan | b34497d | 2014-04-24 18:00:10 +1000 | [diff] [blame] | 299 | pr_info("PE[%3d] A/B: %016llx %016llx\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 300 | i, be64_to_cpu(data->pestA[i]), |
| 301 | be64_to_cpu(data->pestB[i])); |
Gavin Shan | 93aef2a | 2013-11-22 16:28:45 +0800 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
| 305 | void pnv_pci_dump_phb_diag_data(struct pci_controller *hose, |
| 306 | unsigned char *log_buff) |
| 307 | { |
| 308 | struct OpalIoPhbErrorCommon *common; |
| 309 | |
| 310 | if (!hose || !log_buff) |
| 311 | return; |
| 312 | |
| 313 | common = (struct OpalIoPhbErrorCommon *)log_buff; |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 314 | switch (be32_to_cpu(common->ioType)) { |
Gavin Shan | 93aef2a | 2013-11-22 16:28:45 +0800 | [diff] [blame] | 315 | case OPAL_PHB_ERROR_DATA_TYPE_P7IOC: |
| 316 | pnv_pci_dump_p7ioc_diag_data(hose, common); |
| 317 | break; |
| 318 | case OPAL_PHB_ERROR_DATA_TYPE_PHB3: |
| 319 | pnv_pci_dump_phb3_diag_data(hose, common); |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 320 | break; |
| 321 | default: |
Gavin Shan | 93aef2a | 2013-11-22 16:28:45 +0800 | [diff] [blame] | 322 | pr_warn("%s: Unrecognized ioType %d\n", |
Guo Chao | ddf0322a | 2014-06-09 16:58:51 +0800 | [diff] [blame] | 323 | __func__, be32_to_cpu(common->ioType)); |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 324 | } |
| 325 | } |
| 326 | |
| 327 | static void pnv_pci_handle_eeh_config(struct pnv_phb *phb, u32 pe_no) |
| 328 | { |
| 329 | unsigned long flags, rc; |
Gavin Shan | 98fd700 | 2014-07-21 14:42:35 +1000 | [diff] [blame] | 330 | int has_diag, ret = 0; |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 331 | |
| 332 | spin_lock_irqsave(&phb->lock, flags); |
| 333 | |
Gavin Shan | 98fd700 | 2014-07-21 14:42:35 +1000 | [diff] [blame] | 334 | /* Fetch PHB diag-data */ |
Gavin Shan | 2377323 | 2013-06-20 13:21:05 +0800 | [diff] [blame] | 335 | rc = opal_pci_get_phb_diag_data2(phb->opal_id, phb->diag.blob, |
| 336 | PNV_PCI_DIAG_BUF_SIZE); |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 337 | has_diag = (rc == OPAL_SUCCESS); |
| 338 | |
Gavin Shan | 98fd700 | 2014-07-21 14:42:35 +1000 | [diff] [blame] | 339 | /* If PHB supports compound PE, to handle it */ |
| 340 | if (phb->unfreeze_pe) { |
| 341 | ret = phb->unfreeze_pe(phb, |
| 342 | pe_no, |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 343 | OPAL_EEH_ACTION_CLEAR_FREEZE_ALL); |
Gavin Shan | 98fd700 | 2014-07-21 14:42:35 +1000 | [diff] [blame] | 344 | } else { |
| 345 | rc = opal_pci_eeh_freeze_clear(phb->opal_id, |
| 346 | pe_no, |
| 347 | OPAL_EEH_ACTION_CLEAR_FREEZE_ALL); |
| 348 | if (rc) { |
| 349 | pr_warn("%s: Failure %ld clearing frozen " |
| 350 | "PHB#%x-PE#%x\n", |
| 351 | __func__, rc, phb->hose->global_number, |
| 352 | pe_no); |
| 353 | ret = -EIO; |
| 354 | } |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Gavin Shan | 98fd700 | 2014-07-21 14:42:35 +1000 | [diff] [blame] | 357 | /* |
| 358 | * For now, let's only display the diag buffer when we fail to clear |
| 359 | * the EEH status. We'll do more sensible things later when we have |
| 360 | * proper EEH support. We need to make sure we don't pollute ourselves |
| 361 | * with the normal errors generated when probing empty slots |
| 362 | */ |
| 363 | if (has_diag && ret) |
| 364 | pnv_pci_dump_phb_diag_data(phb->hose, phb->diag.blob); |
| 365 | |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 366 | spin_unlock_irqrestore(&phb->lock, flags); |
| 367 | } |
| 368 | |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 369 | static void pnv_pci_config_check_eeh(struct pci_dn *pdn) |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 370 | { |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 371 | struct pnv_phb *phb = pdn->phb->private_data; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 372 | u8 fstate; |
Benjamin Herrenschmidt | 3a1a466 | 2013-09-23 12:05:01 +1000 | [diff] [blame] | 373 | __be16 pcierr; |
Gavin Shan | 98fd700 | 2014-07-21 14:42:35 +1000 | [diff] [blame] | 374 | int pe_no; |
| 375 | s64 rc; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 376 | |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 377 | /* |
| 378 | * Get the PE#. During the PCI probe stage, we might not |
| 379 | * setup that yet. So all ER errors should be mapped to |
Gavin Shan | 36954dc | 2013-11-04 16:32:47 +0800 | [diff] [blame] | 380 | * reserved PE. |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 381 | */ |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 382 | pe_no = pdn->pe_number; |
Gavin Shan | 36954dc | 2013-11-04 16:32:47 +0800 | [diff] [blame] | 383 | if (pe_no == IODA_INVALID_PE) { |
| 384 | if (phb->type == PNV_PHB_P5IOC2) |
| 385 | pe_no = 0; |
| 386 | else |
| 387 | pe_no = phb->ioda.reserved_pe; |
| 388 | } |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 389 | |
Gavin Shan | 98fd700 | 2014-07-21 14:42:35 +1000 | [diff] [blame] | 390 | /* |
| 391 | * Fetch frozen state. If the PHB support compound PE, |
| 392 | * we need handle that case. |
| 393 | */ |
| 394 | if (phb->get_pe_state) { |
| 395 | fstate = phb->get_pe_state(phb, pe_no); |
| 396 | } else { |
| 397 | rc = opal_pci_eeh_freeze_status(phb->opal_id, |
| 398 | pe_no, |
| 399 | &fstate, |
| 400 | &pcierr, |
| 401 | NULL); |
| 402 | if (rc) { |
| 403 | pr_warn("%s: Failure %lld getting PHB#%x-PE#%x state\n", |
| 404 | __func__, rc, phb->hose->global_number, pe_no); |
| 405 | return; |
| 406 | } |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 407 | } |
Gavin Shan | 98fd700 | 2014-07-21 14:42:35 +1000 | [diff] [blame] | 408 | |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 409 | cfg_dbg(" -> EEH check, bdfn=%04x PE#%d fstate=%x\n", |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 410 | (pdn->busno << 8) | (pdn->devfn), pe_no, fstate); |
Gavin Shan | 98fd700 | 2014-07-21 14:42:35 +1000 | [diff] [blame] | 411 | |
| 412 | /* Clear the frozen state if applicable */ |
| 413 | if (fstate == OPAL_EEH_STOPPED_MMIO_FREEZE || |
| 414 | fstate == OPAL_EEH_STOPPED_DMA_FREEZE || |
| 415 | fstate == OPAL_EEH_STOPPED_MMIO_DMA_FREEZE) { |
| 416 | /* |
| 417 | * If PHB supports compound PE, freeze it for |
| 418 | * consistency. |
| 419 | */ |
| 420 | if (phb->freeze_pe) |
| 421 | phb->freeze_pe(phb, pe_no); |
| 422 | |
Benjamin Herrenschmidt | cee72d5 | 2011-11-29 18:22:53 +0000 | [diff] [blame] | 423 | pnv_pci_handle_eeh_config(phb, pe_no); |
Gavin Shan | 98fd700 | 2014-07-21 14:42:35 +1000 | [diff] [blame] | 424 | } |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 427 | int pnv_pci_cfg_read(struct pci_dn *pdn, |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 428 | int where, int size, u32 *val) |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 429 | { |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 430 | struct pnv_phb *phb = pdn->phb->private_data; |
| 431 | u32 bdfn = (pdn->busno << 8) | pdn->devfn; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 432 | s64 rc; |
| 433 | |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 434 | switch (size) { |
| 435 | case 1: { |
| 436 | u8 v8; |
| 437 | rc = opal_pci_config_read_byte(phb->opal_id, bdfn, where, &v8); |
| 438 | *val = (rc == OPAL_SUCCESS) ? v8 : 0xff; |
| 439 | break; |
| 440 | } |
| 441 | case 2: { |
Benjamin Herrenschmidt | 3a1a466 | 2013-09-23 12:05:01 +1000 | [diff] [blame] | 442 | __be16 v16; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 443 | rc = opal_pci_config_read_half_word(phb->opal_id, bdfn, where, |
| 444 | &v16); |
Benjamin Herrenschmidt | 3a1a466 | 2013-09-23 12:05:01 +1000 | [diff] [blame] | 445 | *val = (rc == OPAL_SUCCESS) ? be16_to_cpu(v16) : 0xffff; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 446 | break; |
| 447 | } |
| 448 | case 4: { |
Benjamin Herrenschmidt | 3a1a466 | 2013-09-23 12:05:01 +1000 | [diff] [blame] | 449 | __be32 v32; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 450 | rc = opal_pci_config_read_word(phb->opal_id, bdfn, where, &v32); |
Benjamin Herrenschmidt | 3a1a466 | 2013-09-23 12:05:01 +1000 | [diff] [blame] | 451 | *val = (rc == OPAL_SUCCESS) ? be32_to_cpu(v32) : 0xffffffff; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 452 | break; |
| 453 | } |
| 454 | default: |
| 455 | return PCIBIOS_FUNC_NOT_SUPPORTED; |
| 456 | } |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 457 | |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 458 | cfg_dbg("%s: bus: %x devfn: %x +%x/%x -> %08x\n", |
| 459 | __func__, pdn->busno, pdn->devfn, where, size, *val); |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 460 | return PCIBIOS_SUCCESSFUL; |
| 461 | } |
| 462 | |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 463 | int pnv_pci_cfg_write(struct pci_dn *pdn, |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 464 | int where, int size, u32 val) |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 465 | { |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 466 | struct pnv_phb *phb = pdn->phb->private_data; |
| 467 | u32 bdfn = (pdn->busno << 8) | pdn->devfn; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 468 | |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 469 | cfg_dbg("%s: bus: %x devfn: %x +%x/%x -> %08x\n", |
| 470 | pdn->busno, pdn->devfn, where, size, val); |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 471 | switch (size) { |
| 472 | case 1: |
| 473 | opal_pci_config_write_byte(phb->opal_id, bdfn, where, val); |
| 474 | break; |
| 475 | case 2: |
| 476 | opal_pci_config_write_half_word(phb->opal_id, bdfn, where, val); |
| 477 | break; |
| 478 | case 4: |
| 479 | opal_pci_config_write_word(phb->opal_id, bdfn, where, val); |
| 480 | break; |
| 481 | default: |
| 482 | return PCIBIOS_FUNC_NOT_SUPPORTED; |
| 483 | } |
Gavin Shan | be7e744 | 2013-06-20 13:21:15 +0800 | [diff] [blame] | 484 | |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 485 | return PCIBIOS_SUCCESSFUL; |
| 486 | } |
| 487 | |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 488 | #if CONFIG_EEH |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 489 | static bool pnv_pci_cfg_check(struct pci_dn *pdn) |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 490 | { |
| 491 | struct eeh_dev *edev = NULL; |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 492 | struct pnv_phb *phb = pdn->phb->private_data; |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 493 | |
| 494 | /* EEH not enabled ? */ |
| 495 | if (!(phb->flags & PNV_PHB_FLAG_EEH)) |
| 496 | return true; |
| 497 | |
Gavin Shan | d2b0f6f | 2014-04-24 18:00:19 +1000 | [diff] [blame] | 498 | /* PE reset or device removed ? */ |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 499 | edev = pdn->edev; |
Gavin Shan | d2b0f6f | 2014-04-24 18:00:19 +1000 | [diff] [blame] | 500 | if (edev) { |
| 501 | if (edev->pe && |
Gavin Shan | 8a6b371 | 2014-10-01 17:07:50 +1000 | [diff] [blame] | 502 | (edev->pe->state & EEH_PE_CFG_BLOCKED)) |
Gavin Shan | d2b0f6f | 2014-04-24 18:00:19 +1000 | [diff] [blame] | 503 | return false; |
| 504 | |
| 505 | if (edev->mode & EEH_DEV_REMOVED) |
| 506 | return false; |
| 507 | } |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 508 | |
| 509 | return true; |
| 510 | } |
| 511 | #else |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 512 | static inline pnv_pci_cfg_check(struct pci_dn *pdn) |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 513 | { |
| 514 | return true; |
| 515 | } |
| 516 | #endif /* CONFIG_EEH */ |
| 517 | |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 518 | static int pnv_pci_read_config(struct pci_bus *bus, |
| 519 | unsigned int devfn, |
| 520 | int where, int size, u32 *val) |
| 521 | { |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 522 | struct pci_dn *pdn; |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 523 | struct pnv_phb *phb; |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 524 | int ret; |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 525 | |
| 526 | *val = 0xFFFFFFFF; |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 527 | pdn = pci_get_pdn_by_devfn(bus, devfn); |
| 528 | if (!pdn) |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 529 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 530 | |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 531 | if (!pnv_pci_cfg_check(pdn)) |
| 532 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 533 | |
| 534 | ret = pnv_pci_cfg_read(pdn, where, size, val); |
| 535 | phb = pdn->phb->private_data; |
| 536 | if (phb->flags & PNV_PHB_FLAG_EEH && pdn->edev) { |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 537 | if (*val == EEH_IO_ERROR_VALUE(size) && |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 538 | eeh_dev_check_failure(pdn->edev)) |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 539 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 540 | } else { |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 541 | pnv_pci_config_check_eeh(pdn); |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | return ret; |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | static int pnv_pci_write_config(struct pci_bus *bus, |
| 548 | unsigned int devfn, |
| 549 | int where, int size, u32 val) |
| 550 | { |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 551 | struct pci_dn *pdn; |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 552 | struct pnv_phb *phb; |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 553 | int ret; |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 554 | |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 555 | pdn = pci_get_pdn_by_devfn(bus, devfn); |
| 556 | if (!pdn) |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 557 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 558 | |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 559 | if (!pnv_pci_cfg_check(pdn)) |
| 560 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 561 | |
| 562 | ret = pnv_pci_cfg_write(pdn, where, size, val); |
| 563 | phb = pdn->phb->private_data; |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 564 | if (!(phb->flags & PNV_PHB_FLAG_EEH)) |
Gavin Shan | 3532a741 | 2015-03-17 16:15:03 +1100 | [diff] [blame] | 565 | pnv_pci_config_check_eeh(pdn); |
Gavin Shan | d0914f5 | 2014-04-24 18:00:12 +1000 | [diff] [blame] | 566 | |
| 567 | return ret; |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 568 | } |
| 569 | |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 570 | struct pci_ops pnv_pci_ops = { |
Gavin Shan | 9bf41be | 2013-06-27 13:46:48 +0800 | [diff] [blame] | 571 | .read = pnv_pci_read_config, |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 572 | .write = pnv_pci_write_config, |
| 573 | }; |
| 574 | |
| 575 | static int pnv_tce_build(struct iommu_table *tbl, long index, long npages, |
| 576 | unsigned long uaddr, enum dma_data_direction direction, |
Alexey Kardashevskiy | 8e0a161 | 2013-08-28 18:37:43 +1000 | [diff] [blame] | 577 | struct dma_attrs *attrs, bool rm) |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 578 | { |
| 579 | u64 proto_tce; |
Benjamin Herrenschmidt | 3a1a466 | 2013-09-23 12:05:01 +1000 | [diff] [blame] | 580 | __be64 *tcep, *tces; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 581 | u64 rpn; |
| 582 | |
| 583 | proto_tce = TCE_PCI_READ; // Read allowed |
| 584 | |
| 585 | if (direction != DMA_TO_DEVICE) |
| 586 | proto_tce |= TCE_PCI_WRITE; |
| 587 | |
Anton Blanchard | 5e4da53 | 2013-09-23 12:05:06 +1000 | [diff] [blame] | 588 | tces = tcep = ((__be64 *)tbl->it_base) + index - tbl->it_offset; |
Alexey Kardashevskiy | bc32057 | 2014-06-06 18:44:02 +1000 | [diff] [blame] | 589 | rpn = __pa(uaddr) >> tbl->it_page_shift; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 590 | |
Benjamin Herrenschmidt | 1f1616e | 2011-11-06 18:55:59 +0000 | [diff] [blame] | 591 | while (npages--) |
Alexey Kardashevskiy | bc32057 | 2014-06-06 18:44:02 +1000 | [diff] [blame] | 592 | *(tcep++) = cpu_to_be64(proto_tce | |
| 593 | (rpn++ << tbl->it_page_shift)); |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 594 | |
Benjamin Herrenschmidt | 1f1616e | 2011-11-06 18:55:59 +0000 | [diff] [blame] | 595 | /* Some implementations won't cache invalid TCEs and thus may not |
| 596 | * need that flush. We'll probably turn it_type into a bit mask |
| 597 | * of flags if that becomes the case |
| 598 | */ |
| 599 | if (tbl->it_type & TCE_PCI_SWINV_CREATE) |
Alexey Kardashevskiy | 8e0a161 | 2013-08-28 18:37:43 +1000 | [diff] [blame] | 600 | pnv_pci_ioda_tce_invalidate(tbl, tces, tcep - 1, rm); |
Benjamin Herrenschmidt | 1f1616e | 2011-11-06 18:55:59 +0000 | [diff] [blame] | 601 | |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 602 | return 0; |
| 603 | } |
| 604 | |
Alexey Kardashevskiy | 8e0a161 | 2013-08-28 18:37:43 +1000 | [diff] [blame] | 605 | static int pnv_tce_build_vm(struct iommu_table *tbl, long index, long npages, |
| 606 | unsigned long uaddr, |
| 607 | enum dma_data_direction direction, |
| 608 | struct dma_attrs *attrs) |
| 609 | { |
| 610 | return pnv_tce_build(tbl, index, npages, uaddr, direction, attrs, |
| 611 | false); |
| 612 | } |
| 613 | |
| 614 | static void pnv_tce_free(struct iommu_table *tbl, long index, long npages, |
| 615 | bool rm) |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 616 | { |
Benjamin Herrenschmidt | 3a1a466 | 2013-09-23 12:05:01 +1000 | [diff] [blame] | 617 | __be64 *tcep, *tces; |
Benjamin Herrenschmidt | 1f1616e | 2011-11-06 18:55:59 +0000 | [diff] [blame] | 618 | |
Anton Blanchard | 5e4da53 | 2013-09-23 12:05:06 +1000 | [diff] [blame] | 619 | tces = tcep = ((__be64 *)tbl->it_base) + index - tbl->it_offset; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 620 | |
| 621 | while (npages--) |
Benjamin Herrenschmidt | 3a1a466 | 2013-09-23 12:05:01 +1000 | [diff] [blame] | 622 | *(tcep++) = cpu_to_be64(0); |
Benjamin Herrenschmidt | 1f1616e | 2011-11-06 18:55:59 +0000 | [diff] [blame] | 623 | |
Benjamin Herrenschmidt | 605e44d | 2013-05-20 17:25:15 +0000 | [diff] [blame] | 624 | if (tbl->it_type & TCE_PCI_SWINV_FREE) |
Alexey Kardashevskiy | 8e0a161 | 2013-08-28 18:37:43 +1000 | [diff] [blame] | 625 | pnv_pci_ioda_tce_invalidate(tbl, tces, tcep - 1, rm); |
| 626 | } |
| 627 | |
| 628 | static void pnv_tce_free_vm(struct iommu_table *tbl, long index, long npages) |
| 629 | { |
| 630 | pnv_tce_free(tbl, index, npages, false); |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Alexey Kardashevskiy | 11f63d3 | 2012-09-04 15:19:35 +0000 | [diff] [blame] | 633 | static unsigned long pnv_tce_get(struct iommu_table *tbl, long index) |
| 634 | { |
| 635 | return ((u64 *)tbl->it_base)[index - tbl->it_offset]; |
| 636 | } |
| 637 | |
Alexey Kardashevskiy | 8e0a161 | 2013-08-28 18:37:43 +1000 | [diff] [blame] | 638 | static int pnv_tce_build_rm(struct iommu_table *tbl, long index, long npages, |
| 639 | unsigned long uaddr, |
| 640 | enum dma_data_direction direction, |
| 641 | struct dma_attrs *attrs) |
| 642 | { |
| 643 | return pnv_tce_build(tbl, index, npages, uaddr, direction, attrs, true); |
| 644 | } |
| 645 | |
| 646 | static void pnv_tce_free_rm(struct iommu_table *tbl, long index, long npages) |
| 647 | { |
| 648 | pnv_tce_free(tbl, index, npages, true); |
| 649 | } |
| 650 | |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 651 | void pnv_pci_setup_iommu_table(struct iommu_table *tbl, |
| 652 | void *tce_mem, u64 tce_size, |
Alexey Kardashevskiy | 8fa5d45 | 2014-06-06 18:44:03 +1000 | [diff] [blame] | 653 | u64 dma_offset, unsigned page_shift) |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 654 | { |
| 655 | tbl->it_blocksize = 16; |
| 656 | tbl->it_base = (unsigned long)tce_mem; |
Alexey Kardashevskiy | 8fa5d45 | 2014-06-06 18:44:03 +1000 | [diff] [blame] | 657 | tbl->it_page_shift = page_shift; |
Alistair Popple | 3a55317 | 2013-12-09 18:17:02 +1100 | [diff] [blame] | 658 | tbl->it_offset = dma_offset >> tbl->it_page_shift; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 659 | tbl->it_index = 0; |
| 660 | tbl->it_size = tce_size >> 3; |
| 661 | tbl->it_busno = 0; |
| 662 | tbl->it_type = TCE_PCI; |
| 663 | } |
| 664 | |
Daniel Axtens | 92ae035 | 2015-04-28 15:12:05 +1000 | [diff] [blame] | 665 | void pnv_pci_dma_dev_setup(struct pci_dev *pdev) |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 666 | { |
| 667 | struct pci_controller *hose = pci_bus_to_host(pdev->bus); |
| 668 | struct pnv_phb *phb = hose->private_data; |
Wei Yang | 781a868 | 2015-03-25 16:23:57 +0800 | [diff] [blame] | 669 | #ifdef CONFIG_PCI_IOV |
| 670 | struct pnv_ioda_pe *pe; |
| 671 | struct pci_dn *pdn; |
| 672 | |
| 673 | /* Fix the VF pdn PE number */ |
| 674 | if (pdev->is_virtfn) { |
| 675 | pdn = pci_get_pdn(pdev); |
| 676 | WARN_ON(pdn->pe_number != IODA_INVALID_PE); |
| 677 | list_for_each_entry(pe, &phb->ioda.pe_list, list) { |
| 678 | if (pe->rid == ((pdev->bus->number << 8) | |
| 679 | (pdev->devfn & 0xff))) { |
| 680 | pdn->pe_number = pe->pe_number; |
| 681 | pe->pdev = pdev; |
| 682 | break; |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | #endif /* CONFIG_PCI_IOV */ |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 687 | |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 688 | if (phb && phb->dma_dev_setup) |
| 689 | phb->dma_dev_setup(phb, pdev); |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 690 | } |
| 691 | |
Gavin Shan | fe7e85c | 2014-09-30 12:39:10 +1000 | [diff] [blame] | 692 | u64 pnv_pci_dma_get_required_mask(struct pci_dev *pdev) |
| 693 | { |
| 694 | struct pci_controller *hose = pci_bus_to_host(pdev->bus); |
| 695 | struct pnv_phb *phb = hose->private_data; |
| 696 | |
| 697 | if (phb && phb->dma_get_required_mask) |
| 698 | return phb->dma_get_required_mask(phb, pdev); |
| 699 | |
| 700 | return __dma_get_required_mask(&pdev->dev); |
| 701 | } |
| 702 | |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 703 | void pnv_pci_shutdown(void) |
| 704 | { |
| 705 | struct pci_controller *hose; |
| 706 | |
Michael Neuling | 7a8e6bb | 2015-05-27 16:06:59 +1000 | [diff] [blame] | 707 | list_for_each_entry(hose, &hose_list, list_node) |
| 708 | if (hose->controller_ops.shutdown) |
| 709 | hose->controller_ops.shutdown(hose); |
Benjamin Herrenschmidt | 73ed148 | 2013-05-10 16:59:18 +1000 | [diff] [blame] | 710 | } |
| 711 | |
Gavin Shan | aa0c033 | 2013-04-25 19:20:57 +0000 | [diff] [blame] | 712 | /* Fixup wrong class code in p7ioc and p8 root complex */ |
Greg Kroah-Hartman | cad5cef | 2012-12-21 14:04:10 -0800 | [diff] [blame] | 713 | static void pnv_p7ioc_rc_quirk(struct pci_dev *dev) |
Benjamin Herrenschmidt | ca45cfe | 2011-11-06 18:56:00 +0000 | [diff] [blame] | 714 | { |
| 715 | dev->class = PCI_CLASS_BRIDGE_PCI << 8; |
| 716 | } |
| 717 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_IBM, 0x3b9, pnv_p7ioc_rc_quirk); |
| 718 | |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 719 | void __init pnv_pci_init(void) |
| 720 | { |
| 721 | struct device_node *np; |
Michael Ellerman | 646b54f | 2015-03-12 17:27:11 +1100 | [diff] [blame] | 722 | bool found_ioda = false; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 723 | |
Bjorn Helgaas | 673c975 | 2012-02-23 20:18:58 -0700 | [diff] [blame] | 724 | pci_add_flags(PCI_CAN_SKIP_ISA_ALIGN); |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 725 | |
Michael Ellerman | 646b54f | 2015-03-12 17:27:11 +1100 | [diff] [blame] | 726 | /* If we don't have OPAL, eg. in sim, just skip PCI probe */ |
| 727 | if (!firmware_has_feature(FW_FEATURE_OPAL)) |
| 728 | return; |
| 729 | |
| 730 | /* Look for IODA IO-Hubs. We don't support mixing IODA |
| 731 | * and p5ioc2 due to the need to change some global |
| 732 | * probing flags |
| 733 | */ |
| 734 | for_each_compatible_node(np, NULL, "ibm,ioda-hub") { |
| 735 | pnv_pci_init_ioda_hub(np); |
| 736 | found_ioda = true; |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 737 | } |
Benjamin Herrenschmidt | 184cd4a | 2011-11-15 17:29:08 +0000 | [diff] [blame] | 738 | |
Michael Ellerman | 646b54f | 2015-03-12 17:27:11 +1100 | [diff] [blame] | 739 | /* Look for p5ioc2 IO-Hubs */ |
| 740 | if (!found_ioda) |
| 741 | for_each_compatible_node(np, NULL, "ibm,p5ioc2") |
| 742 | pnv_pci_init_p5ioc2_hub(np); |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 743 | |
Michael Ellerman | 646b54f | 2015-03-12 17:27:11 +1100 | [diff] [blame] | 744 | /* Look for ioda2 built-in PHB3's */ |
| 745 | for_each_compatible_node(np, NULL, "ibm,ioda2-phb") |
| 746 | pnv_pci_init_ioda2_phb(np); |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 747 | |
| 748 | /* Setup the linkage between OF nodes and PHBs */ |
| 749 | pci_devs_phb_init(); |
| 750 | |
| 751 | /* Configure IOMMU DMA hooks */ |
Alexey Kardashevskiy | 8e0a161 | 2013-08-28 18:37:43 +1000 | [diff] [blame] | 752 | ppc_md.tce_build = pnv_tce_build_vm; |
| 753 | ppc_md.tce_free = pnv_tce_free_vm; |
| 754 | ppc_md.tce_build_rm = pnv_tce_build_rm; |
| 755 | ppc_md.tce_free_rm = pnv_tce_free_rm; |
Alexey Kardashevskiy | 11f63d3 | 2012-09-04 15:19:35 +0000 | [diff] [blame] | 756 | ppc_md.tce_get = pnv_tce_get; |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 757 | set_pci_dma_ops(&dma_iommu_ops); |
Benjamin Herrenschmidt | 61305a9 | 2011-09-19 17:45:05 +0000 | [diff] [blame] | 758 | } |
Alexey Kardashevskiy | d905c5d | 2013-11-21 17:43:14 +1100 | [diff] [blame] | 759 | |
Michael Ellerman | b14726c | 2014-07-15 22:22:24 +1000 | [diff] [blame] | 760 | machine_subsys_initcall_sync(powernv, tce_iommu_bus_notifier_init); |