Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * The file intends to implement the platform dependent EEH operations on pseries. |
| 3 | * Actually, the pseries platform is built based on RTAS heavily. That means the |
| 4 | * pseries platform dependent EEH operations will be built on RTAS calls. The functions |
| 5 | * are devired from arch/powerpc/platforms/pseries/eeh.c and necessary cleanup has |
| 6 | * been done. |
| 7 | * |
| 8 | * Copyright Benjamin Herrenschmidt & Gavin Shan, IBM Corporation 2011. |
| 9 | * Copyright IBM Corporation 2001, 2005, 2006 |
| 10 | * Copyright Dave Engebretsen & Todd Inglett 2001 |
| 11 | * Copyright Linas Vepstas 2005, 2006 |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software |
| 25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 26 | */ |
| 27 | |
| 28 | #include <linux/atomic.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/export.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/list.h> |
| 33 | #include <linux/of.h> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/proc_fs.h> |
| 36 | #include <linux/rbtree.h> |
| 37 | #include <linux/sched.h> |
| 38 | #include <linux/seq_file.h> |
| 39 | #include <linux/spinlock.h> |
| 40 | |
| 41 | #include <asm/eeh.h> |
| 42 | #include <asm/eeh_event.h> |
| 43 | #include <asm/io.h> |
| 44 | #include <asm/machdep.h> |
| 45 | #include <asm/ppc-pci.h> |
| 46 | #include <asm/rtas.h> |
| 47 | |
Gavin Shan | e2af155 | 2012-02-27 20:03:54 +0000 | [diff] [blame] | 48 | /* RTAS tokens */ |
| 49 | static int ibm_set_eeh_option; |
| 50 | static int ibm_set_slot_reset; |
| 51 | static int ibm_read_slot_reset_state; |
| 52 | static int ibm_read_slot_reset_state2; |
| 53 | static int ibm_slot_error_detail; |
| 54 | static int ibm_get_config_addr_info; |
| 55 | static int ibm_get_config_addr_info2; |
| 56 | static int ibm_configure_bridge; |
| 57 | static int ibm_configure_pe; |
| 58 | |
Gavin Shan | 8d63329 | 2012-02-27 20:04:00 +0000 | [diff] [blame] | 59 | /* |
| 60 | * Buffer for reporting slot-error-detail rtas calls. Its here |
| 61 | * in BSS, and not dynamically alloced, so that it ends up in |
| 62 | * RMO where RTAS can access it. |
| 63 | */ |
| 64 | static unsigned char slot_errbuf[RTAS_ERROR_LOG_MAX]; |
| 65 | static DEFINE_SPINLOCK(slot_errbuf_lock); |
| 66 | static int eeh_error_buf_size; |
| 67 | |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 68 | /** |
| 69 | * pseries_eeh_init - EEH platform dependent initialization |
| 70 | * |
| 71 | * EEH platform dependent initialization on pseries. |
| 72 | */ |
| 73 | static int pseries_eeh_init(void) |
| 74 | { |
Gavin Shan | e2af155 | 2012-02-27 20:03:54 +0000 | [diff] [blame] | 75 | /* figure out EEH RTAS function call tokens */ |
| 76 | ibm_set_eeh_option = rtas_token("ibm,set-eeh-option"); |
| 77 | ibm_set_slot_reset = rtas_token("ibm,set-slot-reset"); |
| 78 | ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2"); |
| 79 | ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state"); |
| 80 | ibm_slot_error_detail = rtas_token("ibm,slot-error-detail"); |
| 81 | ibm_get_config_addr_info2 = rtas_token("ibm,get-config-addr-info2"); |
| 82 | ibm_get_config_addr_info = rtas_token("ibm,get-config-addr-info"); |
| 83 | ibm_configure_pe = rtas_token("ibm,configure-pe"); |
Michael Neuling | 9c41ef0 | 2012-06-26 18:12:01 +0000 | [diff] [blame] | 84 | ibm_configure_bridge = rtas_token("ibm,configure-bridge"); |
Gavin Shan | e2af155 | 2012-02-27 20:03:54 +0000 | [diff] [blame] | 85 | |
Gavin Shan | b8b3de2 | 2013-06-05 14:25:50 +0000 | [diff] [blame^] | 86 | /* |
| 87 | * Necessary sanity check. We needn't check "get-config-addr-info" |
| 88 | * and its variant since the old firmware probably support address |
| 89 | * of domain/bus/slot/function for EEH RTAS operations. |
| 90 | */ |
Gavin Shan | e2af155 | 2012-02-27 20:03:54 +0000 | [diff] [blame] | 91 | if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE) { |
| 92 | pr_warning("%s: RTAS service <ibm,set-eeh-option> invalid\n", |
| 93 | __func__); |
| 94 | return -EINVAL; |
| 95 | } else if (ibm_set_slot_reset == RTAS_UNKNOWN_SERVICE) { |
Michael Neuling | 9c41ef0 | 2012-06-26 18:12:01 +0000 | [diff] [blame] | 96 | pr_warning("%s: RTAS service <ibm,set-slot-reset> invalid\n", |
Gavin Shan | e2af155 | 2012-02-27 20:03:54 +0000 | [diff] [blame] | 97 | __func__); |
| 98 | return -EINVAL; |
| 99 | } else if (ibm_read_slot_reset_state2 == RTAS_UNKNOWN_SERVICE && |
| 100 | ibm_read_slot_reset_state == RTAS_UNKNOWN_SERVICE) { |
| 101 | pr_warning("%s: RTAS service <ibm,read-slot-reset-state2> and " |
| 102 | "<ibm,read-slot-reset-state> invalid\n", |
| 103 | __func__); |
| 104 | return -EINVAL; |
| 105 | } else if (ibm_slot_error_detail == RTAS_UNKNOWN_SERVICE) { |
| 106 | pr_warning("%s: RTAS service <ibm,slot-error-detail> invalid\n", |
| 107 | __func__); |
| 108 | return -EINVAL; |
Gavin Shan | e2af155 | 2012-02-27 20:03:54 +0000 | [diff] [blame] | 109 | } else if (ibm_configure_pe == RTAS_UNKNOWN_SERVICE && |
| 110 | ibm_configure_bridge == RTAS_UNKNOWN_SERVICE) { |
| 111 | pr_warning("%s: RTAS service <ibm,configure-pe> and " |
| 112 | "<ibm,configure-bridge> invalid\n", |
| 113 | __func__); |
| 114 | return -EINVAL; |
| 115 | } |
| 116 | |
Gavin Shan | 8d63329 | 2012-02-27 20:04:00 +0000 | [diff] [blame] | 117 | /* Initialize error log lock and size */ |
| 118 | spin_lock_init(&slot_errbuf_lock); |
| 119 | eeh_error_buf_size = rtas_token("rtas-error-log-max"); |
| 120 | if (eeh_error_buf_size == RTAS_UNKNOWN_SERVICE) { |
| 121 | pr_warning("%s: unknown EEH error log size\n", |
| 122 | __func__); |
| 123 | eeh_error_buf_size = 1024; |
| 124 | } else if (eeh_error_buf_size > RTAS_ERROR_LOG_MAX) { |
| 125 | pr_warning("%s: EEH error log size %d exceeds the maximal %d\n", |
| 126 | __func__, eeh_error_buf_size, RTAS_ERROR_LOG_MAX); |
| 127 | eeh_error_buf_size = RTAS_ERROR_LOG_MAX; |
| 128 | } |
| 129 | |
Gavin Shan | d7bb886 | 2012-09-07 22:44:21 +0000 | [diff] [blame] | 130 | /* Set EEH probe mode */ |
| 131 | eeh_probe_mode_set(EEH_PROBE_MODE_DEVTREE); |
| 132 | |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | /** |
Gavin Shan | d7bb886 | 2012-09-07 22:44:21 +0000 | [diff] [blame] | 137 | * pseries_eeh_of_probe - EEH probe on the given device |
| 138 | * @dn: OF node |
| 139 | * @flag: Unused |
| 140 | * |
| 141 | * When EEH module is installed during system boot, all PCI devices |
| 142 | * are checked one by one to see if it supports EEH. The function |
| 143 | * is introduced for the purpose. |
| 144 | */ |
| 145 | static void *pseries_eeh_of_probe(struct device_node *dn, void *flag) |
| 146 | { |
| 147 | struct eeh_dev *edev; |
| 148 | struct eeh_pe pe; |
| 149 | const u32 *class_code, *vendor_id, *device_id; |
| 150 | const u32 *regs; |
| 151 | int enable = 0; |
| 152 | int ret; |
| 153 | |
| 154 | /* Retrieve OF node and eeh device */ |
| 155 | edev = of_node_to_eeh_dev(dn); |
| 156 | if (!of_device_is_available(dn)) |
| 157 | return NULL; |
| 158 | |
| 159 | /* Retrieve class/vendor/device IDs */ |
| 160 | class_code = of_get_property(dn, "class-code", NULL); |
| 161 | vendor_id = of_get_property(dn, "vendor-id", NULL); |
| 162 | device_id = of_get_property(dn, "device-id", NULL); |
| 163 | |
| 164 | /* Skip for bad OF node or PCI-ISA bridge */ |
| 165 | if (!class_code || !vendor_id || !device_id) |
| 166 | return NULL; |
| 167 | if (dn->type && !strcmp(dn->type, "isa")) |
| 168 | return NULL; |
| 169 | |
| 170 | /* Update class code and mode of eeh device */ |
| 171 | edev->class_code = *class_code; |
| 172 | edev->mode = 0; |
| 173 | |
| 174 | /* Retrieve the device address */ |
| 175 | regs = of_get_property(dn, "reg", NULL); |
| 176 | if (!regs) { |
| 177 | pr_warning("%s: OF node property %s::reg not found\n", |
| 178 | __func__, dn->full_name); |
| 179 | return NULL; |
| 180 | } |
| 181 | |
| 182 | /* Initialize the fake PE */ |
| 183 | memset(&pe, 0, sizeof(struct eeh_pe)); |
| 184 | pe.phb = edev->phb; |
| 185 | pe.config_addr = regs[0]; |
| 186 | |
| 187 | /* Enable EEH on the device */ |
| 188 | ret = eeh_ops->set_option(&pe, EEH_OPT_ENABLE); |
| 189 | if (!ret) { |
| 190 | edev->config_addr = regs[0]; |
| 191 | /* Retrieve PE address */ |
| 192 | edev->pe_config_addr = eeh_ops->get_pe_addr(&pe); |
| 193 | pe.addr = edev->pe_config_addr; |
| 194 | |
| 195 | /* Some older systems (Power4) allow the ibm,set-eeh-option |
| 196 | * call to succeed even on nodes where EEH is not supported. |
| 197 | * Verify support explicitly. |
| 198 | */ |
| 199 | ret = eeh_ops->get_state(&pe, NULL); |
| 200 | if (ret > 0 && ret != EEH_STATE_NOT_SUPPORT) |
| 201 | enable = 1; |
| 202 | |
| 203 | if (enable) { |
| 204 | eeh_subsystem_enabled = 1; |
| 205 | eeh_add_to_parent_pe(edev); |
| 206 | |
| 207 | pr_debug("%s: EEH enabled on %s PHB#%d-PE#%x, config addr#%x\n", |
| 208 | __func__, dn->full_name, pe.phb->global_number, |
| 209 | pe.addr, pe.config_addr); |
| 210 | } else if (dn->parent && of_node_to_eeh_dev(dn->parent) && |
| 211 | (of_node_to_eeh_dev(dn->parent))->pe) { |
| 212 | /* This device doesn't support EEH, but it may have an |
| 213 | * EEH parent, in which case we mark it as supported. |
| 214 | */ |
| 215 | edev->config_addr = of_node_to_eeh_dev(dn->parent)->config_addr; |
| 216 | edev->pe_config_addr = of_node_to_eeh_dev(dn->parent)->pe_config_addr; |
| 217 | eeh_add_to_parent_pe(edev); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | /* Save memory bars */ |
| 222 | eeh_save_bars(edev); |
| 223 | |
| 224 | return NULL; |
| 225 | } |
| 226 | |
| 227 | /** |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 228 | * pseries_eeh_set_option - Initialize EEH or MMIO/DMA reenable |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 229 | * @pe: EEH PE |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 230 | * @option: operation to be issued |
| 231 | * |
| 232 | * The function is used to control the EEH functionality globally. |
| 233 | * Currently, following options are support according to PAPR: |
| 234 | * Enable EEH, Disable EEH, Enable MMIO and Enable DMA |
| 235 | */ |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 236 | static int pseries_eeh_set_option(struct eeh_pe *pe, int option) |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 237 | { |
Gavin Shan | 8fb8f70 | 2012-02-27 20:03:55 +0000 | [diff] [blame] | 238 | int ret = 0; |
Gavin Shan | 8fb8f70 | 2012-02-27 20:03:55 +0000 | [diff] [blame] | 239 | int config_addr; |
| 240 | |
Gavin Shan | 8fb8f70 | 2012-02-27 20:03:55 +0000 | [diff] [blame] | 241 | /* |
| 242 | * When we're enabling or disabling EEH functioality on |
| 243 | * the particular PE, the PE config address is possibly |
| 244 | * unavailable. Therefore, we have to figure it out from |
| 245 | * the FDT node. |
| 246 | */ |
| 247 | switch (option) { |
| 248 | case EEH_OPT_DISABLE: |
| 249 | case EEH_OPT_ENABLE: |
Gavin Shan | 8fb8f70 | 2012-02-27 20:03:55 +0000 | [diff] [blame] | 250 | case EEH_OPT_THAW_MMIO: |
| 251 | case EEH_OPT_THAW_DMA: |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 252 | config_addr = pe->config_addr; |
| 253 | if (pe->addr) |
| 254 | config_addr = pe->addr; |
Gavin Shan | 8fb8f70 | 2012-02-27 20:03:55 +0000 | [diff] [blame] | 255 | break; |
| 256 | |
| 257 | default: |
| 258 | pr_err("%s: Invalid option %d\n", |
| 259 | __func__, option); |
| 260 | return -EINVAL; |
| 261 | } |
| 262 | |
| 263 | ret = rtas_call(ibm_set_eeh_option, 4, 1, NULL, |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 264 | config_addr, BUID_HI(pe->phb->buid), |
| 265 | BUID_LO(pe->phb->buid), option); |
Gavin Shan | 8fb8f70 | 2012-02-27 20:03:55 +0000 | [diff] [blame] | 266 | |
| 267 | return ret; |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | /** |
| 271 | * pseries_eeh_get_pe_addr - Retrieve PE address |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 272 | * @pe: EEH PE |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 273 | * |
| 274 | * Retrieve the assocated PE address. Actually, there're 2 RTAS |
| 275 | * function calls dedicated for the purpose. We need implement |
| 276 | * it through the new function and then the old one. Besides, |
| 277 | * you should make sure the config address is figured out from |
| 278 | * FDT node before calling the function. |
| 279 | * |
| 280 | * It's notable that zero'ed return value means invalid PE config |
| 281 | * address. |
| 282 | */ |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 283 | static int pseries_eeh_get_pe_addr(struct eeh_pe *pe) |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 284 | { |
Gavin Shan | c8c29b3 | 2012-02-27 20:03:56 +0000 | [diff] [blame] | 285 | int ret = 0; |
| 286 | int rets[3]; |
| 287 | |
Gavin Shan | c8c29b3 | 2012-02-27 20:03:56 +0000 | [diff] [blame] | 288 | if (ibm_get_config_addr_info2 != RTAS_UNKNOWN_SERVICE) { |
| 289 | /* |
| 290 | * First of all, we need to make sure there has one PE |
| 291 | * associated with the device. Otherwise, PE address is |
| 292 | * meaningless. |
| 293 | */ |
| 294 | ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets, |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 295 | pe->config_addr, BUID_HI(pe->phb->buid), |
| 296 | BUID_LO(pe->phb->buid), 1); |
Gavin Shan | c8c29b3 | 2012-02-27 20:03:56 +0000 | [diff] [blame] | 297 | if (ret || (rets[0] == 0)) |
| 298 | return 0; |
| 299 | |
| 300 | /* Retrieve the associated PE config address */ |
| 301 | ret = rtas_call(ibm_get_config_addr_info2, 4, 2, rets, |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 302 | pe->config_addr, BUID_HI(pe->phb->buid), |
| 303 | BUID_LO(pe->phb->buid), 0); |
Gavin Shan | c8c29b3 | 2012-02-27 20:03:56 +0000 | [diff] [blame] | 304 | if (ret) { |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 305 | pr_warning("%s: Failed to get address for PHB#%d-PE#%x\n", |
| 306 | __func__, pe->phb->global_number, pe->config_addr); |
Gavin Shan | c8c29b3 | 2012-02-27 20:03:56 +0000 | [diff] [blame] | 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | return rets[0]; |
| 311 | } |
| 312 | |
| 313 | if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) { |
| 314 | ret = rtas_call(ibm_get_config_addr_info, 4, 2, rets, |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 315 | pe->config_addr, BUID_HI(pe->phb->buid), |
| 316 | BUID_LO(pe->phb->buid), 0); |
Gavin Shan | c8c29b3 | 2012-02-27 20:03:56 +0000 | [diff] [blame] | 317 | if (ret) { |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 318 | pr_warning("%s: Failed to get address for PHB#%d-PE#%x\n", |
| 319 | __func__, pe->phb->global_number, pe->config_addr); |
Gavin Shan | c8c29b3 | 2012-02-27 20:03:56 +0000 | [diff] [blame] | 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | return rets[0]; |
| 324 | } |
| 325 | |
| 326 | return ret; |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /** |
| 330 | * pseries_eeh_get_state - Retrieve PE state |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 331 | * @pe: EEH PE |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 332 | * @state: return value |
| 333 | * |
| 334 | * Retrieve the state of the specified PE. On RTAS compliant |
| 335 | * pseries platform, there already has one dedicated RTAS function |
| 336 | * for the purpose. It's notable that the associated PE config address |
| 337 | * might be ready when calling the function. Therefore, endeavour to |
| 338 | * use the PE config address if possible. Further more, there're 2 |
| 339 | * RTAS calls for the purpose, we need to try the new one and back |
| 340 | * to the old one if the new one couldn't work properly. |
| 341 | */ |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 342 | static int pseries_eeh_get_state(struct eeh_pe *pe, int *state) |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 343 | { |
Gavin Shan | eb594a4 | 2012-02-27 20:03:57 +0000 | [diff] [blame] | 344 | int config_addr; |
| 345 | int ret; |
| 346 | int rets[4]; |
| 347 | int result; |
| 348 | |
| 349 | /* Figure out PE config address if possible */ |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 350 | config_addr = pe->config_addr; |
| 351 | if (pe->addr) |
| 352 | config_addr = pe->addr; |
Gavin Shan | eb594a4 | 2012-02-27 20:03:57 +0000 | [diff] [blame] | 353 | |
| 354 | if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) { |
| 355 | ret = rtas_call(ibm_read_slot_reset_state2, 3, 4, rets, |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 356 | config_addr, BUID_HI(pe->phb->buid), |
| 357 | BUID_LO(pe->phb->buid)); |
Gavin Shan | eb594a4 | 2012-02-27 20:03:57 +0000 | [diff] [blame] | 358 | } else if (ibm_read_slot_reset_state != RTAS_UNKNOWN_SERVICE) { |
| 359 | /* Fake PE unavailable info */ |
| 360 | rets[2] = 0; |
| 361 | ret = rtas_call(ibm_read_slot_reset_state, 3, 3, rets, |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 362 | config_addr, BUID_HI(pe->phb->buid), |
| 363 | BUID_LO(pe->phb->buid)); |
Gavin Shan | eb594a4 | 2012-02-27 20:03:57 +0000 | [diff] [blame] | 364 | } else { |
| 365 | return EEH_STATE_NOT_SUPPORT; |
| 366 | } |
| 367 | |
| 368 | if (ret) |
| 369 | return ret; |
| 370 | |
| 371 | /* Parse the result out */ |
| 372 | result = 0; |
| 373 | if (rets[1]) { |
| 374 | switch(rets[0]) { |
| 375 | case 0: |
| 376 | result &= ~EEH_STATE_RESET_ACTIVE; |
| 377 | result |= EEH_STATE_MMIO_ACTIVE; |
| 378 | result |= EEH_STATE_DMA_ACTIVE; |
| 379 | break; |
| 380 | case 1: |
| 381 | result |= EEH_STATE_RESET_ACTIVE; |
| 382 | result |= EEH_STATE_MMIO_ACTIVE; |
| 383 | result |= EEH_STATE_DMA_ACTIVE; |
| 384 | break; |
| 385 | case 2: |
| 386 | result &= ~EEH_STATE_RESET_ACTIVE; |
| 387 | result &= ~EEH_STATE_MMIO_ACTIVE; |
| 388 | result &= ~EEH_STATE_DMA_ACTIVE; |
| 389 | break; |
| 390 | case 4: |
| 391 | result &= ~EEH_STATE_RESET_ACTIVE; |
| 392 | result &= ~EEH_STATE_MMIO_ACTIVE; |
| 393 | result &= ~EEH_STATE_DMA_ACTIVE; |
| 394 | result |= EEH_STATE_MMIO_ENABLED; |
| 395 | break; |
| 396 | case 5: |
| 397 | if (rets[2]) { |
| 398 | if (state) *state = rets[2]; |
| 399 | result = EEH_STATE_UNAVAILABLE; |
| 400 | } else { |
| 401 | result = EEH_STATE_NOT_SUPPORT; |
| 402 | } |
| 403 | default: |
| 404 | result = EEH_STATE_NOT_SUPPORT; |
| 405 | } |
| 406 | } else { |
| 407 | result = EEH_STATE_NOT_SUPPORT; |
| 408 | } |
| 409 | |
| 410 | return result; |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /** |
| 414 | * pseries_eeh_reset - Reset the specified PE |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 415 | * @pe: EEH PE |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 416 | * @option: reset option |
| 417 | * |
| 418 | * Reset the specified PE |
| 419 | */ |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 420 | static int pseries_eeh_reset(struct eeh_pe *pe, int option) |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 421 | { |
Gavin Shan | 2652481 | 2012-02-27 20:03:59 +0000 | [diff] [blame] | 422 | int config_addr; |
| 423 | int ret; |
| 424 | |
| 425 | /* Figure out PE address */ |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 426 | config_addr = pe->config_addr; |
| 427 | if (pe->addr) |
| 428 | config_addr = pe->addr; |
Gavin Shan | 2652481 | 2012-02-27 20:03:59 +0000 | [diff] [blame] | 429 | |
| 430 | /* Reset PE through RTAS call */ |
| 431 | ret = rtas_call(ibm_set_slot_reset, 4, 1, NULL, |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 432 | config_addr, BUID_HI(pe->phb->buid), |
| 433 | BUID_LO(pe->phb->buid), option); |
Gavin Shan | 2652481 | 2012-02-27 20:03:59 +0000 | [diff] [blame] | 434 | |
| 435 | /* If fundamental-reset not supported, try hot-reset */ |
| 436 | if (option == EEH_RESET_FUNDAMENTAL && |
| 437 | ret == -8) { |
| 438 | ret = rtas_call(ibm_set_slot_reset, 4, 1, NULL, |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 439 | config_addr, BUID_HI(pe->phb->buid), |
| 440 | BUID_LO(pe->phb->buid), EEH_RESET_HOT); |
Gavin Shan | 2652481 | 2012-02-27 20:03:59 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | return ret; |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | /** |
| 447 | * pseries_eeh_wait_state - Wait for PE state |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 448 | * @pe: EEH PE |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 449 | * @max_wait: maximal period in microsecond |
| 450 | * |
| 451 | * Wait for the state of associated PE. It might take some time |
| 452 | * to retrieve the PE's state. |
| 453 | */ |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 454 | static int pseries_eeh_wait_state(struct eeh_pe *pe, int max_wait) |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 455 | { |
Gavin Shan | b0e5f74 | 2012-02-27 20:03:58 +0000 | [diff] [blame] | 456 | int ret; |
| 457 | int mwait; |
| 458 | |
| 459 | /* |
| 460 | * According to PAPR, the state of PE might be temporarily |
| 461 | * unavailable. Under the circumstance, we have to wait |
| 462 | * for indicated time determined by firmware. The maximal |
| 463 | * wait time is 5 minutes, which is acquired from the original |
| 464 | * EEH implementation. Also, the original implementation |
| 465 | * also defined the minimal wait time as 1 second. |
| 466 | */ |
| 467 | #define EEH_STATE_MIN_WAIT_TIME (1000) |
| 468 | #define EEH_STATE_MAX_WAIT_TIME (300 * 1000) |
| 469 | |
| 470 | while (1) { |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 471 | ret = pseries_eeh_get_state(pe, &mwait); |
Gavin Shan | b0e5f74 | 2012-02-27 20:03:58 +0000 | [diff] [blame] | 472 | |
| 473 | /* |
| 474 | * If the PE's state is temporarily unavailable, |
| 475 | * we have to wait for the specified time. Otherwise, |
| 476 | * the PE's state will be returned immediately. |
| 477 | */ |
| 478 | if (ret != EEH_STATE_UNAVAILABLE) |
| 479 | return ret; |
| 480 | |
| 481 | if (max_wait <= 0) { |
| 482 | pr_warning("%s: Timeout when getting PE's state (%d)\n", |
| 483 | __func__, max_wait); |
| 484 | return EEH_STATE_NOT_SUPPORT; |
| 485 | } |
| 486 | |
| 487 | if (mwait <= 0) { |
| 488 | pr_warning("%s: Firmware returned bad wait value %d\n", |
| 489 | __func__, mwait); |
| 490 | mwait = EEH_STATE_MIN_WAIT_TIME; |
| 491 | } else if (mwait > EEH_STATE_MAX_WAIT_TIME) { |
| 492 | pr_warning("%s: Firmware returned too long wait value %d\n", |
| 493 | __func__, mwait); |
| 494 | mwait = EEH_STATE_MAX_WAIT_TIME; |
| 495 | } |
| 496 | |
| 497 | max_wait -= mwait; |
| 498 | msleep(mwait); |
| 499 | } |
| 500 | |
| 501 | return EEH_STATE_NOT_SUPPORT; |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /** |
| 505 | * pseries_eeh_get_log - Retrieve error log |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 506 | * @pe: EEH PE |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 507 | * @severity: temporary or permanent error log |
| 508 | * @drv_log: driver log to be combined with retrieved error log |
| 509 | * @len: length of driver log |
| 510 | * |
| 511 | * Retrieve the temporary or permanent error from the PE. |
| 512 | * Actually, the error will be retrieved through the dedicated |
| 513 | * RTAS call. |
| 514 | */ |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 515 | static int pseries_eeh_get_log(struct eeh_pe *pe, int severity, char *drv_log, unsigned long len) |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 516 | { |
Gavin Shan | 8d63329 | 2012-02-27 20:04:00 +0000 | [diff] [blame] | 517 | int config_addr; |
| 518 | unsigned long flags; |
| 519 | int ret; |
| 520 | |
Gavin Shan | 8d63329 | 2012-02-27 20:04:00 +0000 | [diff] [blame] | 521 | spin_lock_irqsave(&slot_errbuf_lock, flags); |
| 522 | memset(slot_errbuf, 0, eeh_error_buf_size); |
| 523 | |
| 524 | /* Figure out the PE address */ |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 525 | config_addr = pe->config_addr; |
| 526 | if (pe->addr) |
| 527 | config_addr = pe->addr; |
Gavin Shan | 8d63329 | 2012-02-27 20:04:00 +0000 | [diff] [blame] | 528 | |
| 529 | ret = rtas_call(ibm_slot_error_detail, 8, 1, NULL, config_addr, |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 530 | BUID_HI(pe->phb->buid), BUID_LO(pe->phb->buid), |
Gavin Shan | 8d63329 | 2012-02-27 20:04:00 +0000 | [diff] [blame] | 531 | virt_to_phys(drv_log), len, |
| 532 | virt_to_phys(slot_errbuf), eeh_error_buf_size, |
| 533 | severity); |
| 534 | if (!ret) |
| 535 | log_error(slot_errbuf, ERR_TYPE_RTAS_LOG, 0); |
| 536 | spin_unlock_irqrestore(&slot_errbuf_lock, flags); |
| 537 | |
| 538 | return ret; |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | /** |
| 542 | * pseries_eeh_configure_bridge - Configure PCI bridges in the indicated PE |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 543 | * @pe: EEH PE |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 544 | * |
| 545 | * The function will be called to reconfigure the bridges included |
| 546 | * in the specified PE so that the mulfunctional PE would be recovered |
| 547 | * again. |
| 548 | */ |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 549 | static int pseries_eeh_configure_bridge(struct eeh_pe *pe) |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 550 | { |
Gavin Shan | 1823fbf | 2012-02-27 20:04:01 +0000 | [diff] [blame] | 551 | int config_addr; |
| 552 | int ret; |
| 553 | |
| 554 | /* Figure out the PE address */ |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 555 | config_addr = pe->config_addr; |
| 556 | if (pe->addr) |
| 557 | config_addr = pe->addr; |
Gavin Shan | 1823fbf | 2012-02-27 20:04:01 +0000 | [diff] [blame] | 558 | |
| 559 | /* Use new configure-pe function, if supported */ |
| 560 | if (ibm_configure_pe != RTAS_UNKNOWN_SERVICE) { |
| 561 | ret = rtas_call(ibm_configure_pe, 3, 1, NULL, |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 562 | config_addr, BUID_HI(pe->phb->buid), |
| 563 | BUID_LO(pe->phb->buid)); |
Gavin Shan | 1823fbf | 2012-02-27 20:04:01 +0000 | [diff] [blame] | 564 | } else if (ibm_configure_bridge != RTAS_UNKNOWN_SERVICE) { |
| 565 | ret = rtas_call(ibm_configure_bridge, 3, 1, NULL, |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 566 | config_addr, BUID_HI(pe->phb->buid), |
| 567 | BUID_LO(pe->phb->buid)); |
Gavin Shan | 1823fbf | 2012-02-27 20:04:01 +0000 | [diff] [blame] | 568 | } else { |
| 569 | return -EFAULT; |
| 570 | } |
| 571 | |
| 572 | if (ret) |
Gavin Shan | 371a395 | 2012-09-07 22:44:14 +0000 | [diff] [blame] | 573 | pr_warning("%s: Unable to configure bridge PHB#%d-PE#%x (%d)\n", |
| 574 | __func__, pe->phb->global_number, pe->addr, ret); |
Gavin Shan | 1823fbf | 2012-02-27 20:04:01 +0000 | [diff] [blame] | 575 | |
| 576 | return ret; |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 577 | } |
| 578 | |
Gavin Shan | 3780444 | 2012-02-27 20:04:11 +0000 | [diff] [blame] | 579 | /** |
| 580 | * pseries_eeh_read_config - Read PCI config space |
| 581 | * @dn: device node |
| 582 | * @where: PCI address |
| 583 | * @size: size to read |
| 584 | * @val: return value |
| 585 | * |
| 586 | * Read config space from the speicifed device |
| 587 | */ |
| 588 | static int pseries_eeh_read_config(struct device_node *dn, int where, int size, u32 *val) |
| 589 | { |
| 590 | struct pci_dn *pdn; |
| 591 | |
| 592 | pdn = PCI_DN(dn); |
| 593 | |
| 594 | return rtas_read_config(pdn, where, size, val); |
| 595 | } |
| 596 | |
| 597 | /** |
| 598 | * pseries_eeh_write_config - Write PCI config space |
| 599 | * @dn: device node |
| 600 | * @where: PCI address |
| 601 | * @size: size to write |
| 602 | * @val: value to be written |
| 603 | * |
| 604 | * Write config space to the specified device |
| 605 | */ |
| 606 | static int pseries_eeh_write_config(struct device_node *dn, int where, int size, u32 val) |
| 607 | { |
| 608 | struct pci_dn *pdn; |
| 609 | |
| 610 | pdn = PCI_DN(dn); |
| 611 | |
| 612 | return rtas_write_config(pdn, where, size, val); |
| 613 | } |
| 614 | |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 615 | static struct eeh_ops pseries_eeh_ops = { |
| 616 | .name = "pseries", |
| 617 | .init = pseries_eeh_init, |
Gavin Shan | d7bb886 | 2012-09-07 22:44:21 +0000 | [diff] [blame] | 618 | .of_probe = pseries_eeh_of_probe, |
| 619 | .dev_probe = NULL, |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 620 | .set_option = pseries_eeh_set_option, |
| 621 | .get_pe_addr = pseries_eeh_get_pe_addr, |
| 622 | .get_state = pseries_eeh_get_state, |
| 623 | .reset = pseries_eeh_reset, |
| 624 | .wait_state = pseries_eeh_wait_state, |
| 625 | .get_log = pseries_eeh_get_log, |
Gavin Shan | 3780444 | 2012-02-27 20:04:11 +0000 | [diff] [blame] | 626 | .configure_bridge = pseries_eeh_configure_bridge, |
| 627 | .read_config = pseries_eeh_read_config, |
| 628 | .write_config = pseries_eeh_write_config |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 629 | }; |
| 630 | |
| 631 | /** |
| 632 | * eeh_pseries_init - Register platform dependent EEH operations |
| 633 | * |
| 634 | * EEH initialization on pseries platform. This function should be |
| 635 | * called before any EEH related functions. |
| 636 | */ |
Gavin Shan | 35e5cfe | 2012-09-07 22:44:02 +0000 | [diff] [blame] | 637 | static int __init eeh_pseries_init(void) |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 638 | { |
Gavin Shan | 3ea1ae9 | 2012-09-07 22:44:04 +0000 | [diff] [blame] | 639 | int ret = -EINVAL; |
| 640 | |
| 641 | if (!machine_is(pseries)) |
| 642 | return ret; |
| 643 | |
| 644 | ret = eeh_ops_register(&pseries_eeh_ops); |
| 645 | if (!ret) |
| 646 | pr_info("EEH: pSeries platform initialized\n"); |
| 647 | else |
| 648 | pr_info("EEH: pSeries platform initialization failure (%d)\n", |
| 649 | ret); |
| 650 | |
| 651 | return ret; |
Gavin Shan | aa1e637 | 2012-02-27 20:03:53 +0000 | [diff] [blame] | 652 | } |
Gavin Shan | 35e5cfe | 2012-09-07 22:44:02 +0000 | [diff] [blame] | 653 | |
| 654 | early_initcall(eeh_pseries_init); |