powerpc/eeh: Set EEH_PE_RESET on PE reset
[deliverable/linux.git] / arch / powerpc / platforms / powernv / eeh-ioda.c
1 /*
2 * The file intends to implement the functions needed by EEH, which is
3 * built on IODA compliant chip. Actually, lots of functions related
4 * to EEH would be built based on the OPAL APIs.
5 *
6 * Copyright Benjamin Herrenschmidt & Gavin Shan, IBM Corporation 2013.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14 #include <linux/debugfs.h>
15 #include <linux/delay.h>
16 #include <linux/io.h>
17 #include <linux/irq.h>
18 #include <linux/kernel.h>
19 #include <linux/msi.h>
20 #include <linux/notifier.h>
21 #include <linux/pci.h>
22 #include <linux/string.h>
23
24 #include <asm/eeh.h>
25 #include <asm/eeh_event.h>
26 #include <asm/io.h>
27 #include <asm/iommu.h>
28 #include <asm/msi_bitmap.h>
29 #include <asm/opal.h>
30 #include <asm/pci-bridge.h>
31 #include <asm/ppc-pci.h>
32 #include <asm/tce.h>
33
34 #include "powernv.h"
35 #include "pci.h"
36
37 static int ioda_eeh_nb_init = 0;
38
39 static int ioda_eeh_event(struct notifier_block *nb,
40 unsigned long events, void *change)
41 {
42 uint64_t changed_evts = (uint64_t)change;
43
44 /*
45 * We simply send special EEH event if EEH has
46 * been enabled, or clear pending events in
47 * case that we enable EEH soon
48 */
49 if (!(changed_evts & OPAL_EVENT_PCI_ERROR) ||
50 !(events & OPAL_EVENT_PCI_ERROR))
51 return 0;
52
53 if (eeh_enabled())
54 eeh_send_failure_event(NULL);
55 else
56 opal_notifier_update_evt(OPAL_EVENT_PCI_ERROR, 0x0ul);
57
58 return 0;
59 }
60
61 static struct notifier_block ioda_eeh_nb = {
62 .notifier_call = ioda_eeh_event,
63 .next = NULL,
64 .priority = 0
65 };
66
67 #ifdef CONFIG_DEBUG_FS
68 static ssize_t ioda_eeh_ei_write(struct file *filp,
69 const char __user *user_buf,
70 size_t count, loff_t *ppos)
71 {
72 struct pci_controller *hose = filp->private_data;
73 struct pnv_phb *phb = hose->private_data;
74 struct eeh_dev *edev;
75 struct eeh_pe *pe;
76 int pe_no, type, func;
77 unsigned long addr, mask;
78 char buf[50];
79 int ret;
80
81 if (!phb->eeh_ops || !phb->eeh_ops->err_inject)
82 return -ENXIO;
83
84 ret = simple_write_to_buffer(buf, sizeof(buf), ppos, user_buf, count);
85 if (!ret)
86 return -EFAULT;
87
88 /* Retrieve parameters */
89 ret = sscanf(buf, "%x:%x:%x:%lx:%lx",
90 &pe_no, &type, &func, &addr, &mask);
91 if (ret != 5)
92 return -EINVAL;
93
94 /* Retrieve PE */
95 edev = kzalloc(sizeof(*edev), GFP_KERNEL);
96 if (!edev)
97 return -ENOMEM;
98 edev->phb = hose;
99 edev->pe_config_addr = pe_no;
100 pe = eeh_pe_get(edev);
101 kfree(edev);
102 if (!pe)
103 return -ENODEV;
104
105 /* Do error injection */
106 ret = phb->eeh_ops->err_inject(pe, type, func, addr, mask);
107 return ret < 0 ? ret : count;
108 }
109
110 static const struct file_operations ioda_eeh_ei_fops = {
111 .open = simple_open,
112 .llseek = no_llseek,
113 .write = ioda_eeh_ei_write,
114 };
115
116 static int ioda_eeh_dbgfs_set(void *data, int offset, u64 val)
117 {
118 struct pci_controller *hose = data;
119 struct pnv_phb *phb = hose->private_data;
120
121 out_be64(phb->regs + offset, val);
122 return 0;
123 }
124
125 static int ioda_eeh_dbgfs_get(void *data, int offset, u64 *val)
126 {
127 struct pci_controller *hose = data;
128 struct pnv_phb *phb = hose->private_data;
129
130 *val = in_be64(phb->regs + offset);
131 return 0;
132 }
133
134 static int ioda_eeh_outb_dbgfs_set(void *data, u64 val)
135 {
136 return ioda_eeh_dbgfs_set(data, 0xD10, val);
137 }
138
139 static int ioda_eeh_outb_dbgfs_get(void *data, u64 *val)
140 {
141 return ioda_eeh_dbgfs_get(data, 0xD10, val);
142 }
143
144 static int ioda_eeh_inbA_dbgfs_set(void *data, u64 val)
145 {
146 return ioda_eeh_dbgfs_set(data, 0xD90, val);
147 }
148
149 static int ioda_eeh_inbA_dbgfs_get(void *data, u64 *val)
150 {
151 return ioda_eeh_dbgfs_get(data, 0xD90, val);
152 }
153
154 static int ioda_eeh_inbB_dbgfs_set(void *data, u64 val)
155 {
156 return ioda_eeh_dbgfs_set(data, 0xE10, val);
157 }
158
159 static int ioda_eeh_inbB_dbgfs_get(void *data, u64 *val)
160 {
161 return ioda_eeh_dbgfs_get(data, 0xE10, val);
162 }
163
164 DEFINE_SIMPLE_ATTRIBUTE(ioda_eeh_outb_dbgfs_ops, ioda_eeh_outb_dbgfs_get,
165 ioda_eeh_outb_dbgfs_set, "0x%llx\n");
166 DEFINE_SIMPLE_ATTRIBUTE(ioda_eeh_inbA_dbgfs_ops, ioda_eeh_inbA_dbgfs_get,
167 ioda_eeh_inbA_dbgfs_set, "0x%llx\n");
168 DEFINE_SIMPLE_ATTRIBUTE(ioda_eeh_inbB_dbgfs_ops, ioda_eeh_inbB_dbgfs_get,
169 ioda_eeh_inbB_dbgfs_set, "0x%llx\n");
170 #endif /* CONFIG_DEBUG_FS */
171
172
173 /**
174 * ioda_eeh_post_init - Chip dependent post initialization
175 * @hose: PCI controller
176 *
177 * The function will be called after eeh PEs and devices
178 * have been built. That means the EEH is ready to supply
179 * service with I/O cache.
180 */
181 static int ioda_eeh_post_init(struct pci_controller *hose)
182 {
183 struct pnv_phb *phb = hose->private_data;
184 int ret;
185
186 /* Register OPAL event notifier */
187 if (!ioda_eeh_nb_init) {
188 ret = opal_notifier_register(&ioda_eeh_nb);
189 if (ret) {
190 pr_err("%s: Can't register OPAL event notifier (%d)\n",
191 __func__, ret);
192 return ret;
193 }
194
195 ioda_eeh_nb_init = 1;
196 }
197
198 #ifdef CONFIG_DEBUG_FS
199 if (!phb->has_dbgfs && phb->dbgfs) {
200 phb->has_dbgfs = 1;
201
202 debugfs_create_file("err_injct", 0200,
203 phb->dbgfs, hose,
204 &ioda_eeh_ei_fops);
205
206 debugfs_create_file("err_injct_outbound", 0600,
207 phb->dbgfs, hose,
208 &ioda_eeh_outb_dbgfs_ops);
209 debugfs_create_file("err_injct_inboundA", 0600,
210 phb->dbgfs, hose,
211 &ioda_eeh_inbA_dbgfs_ops);
212 debugfs_create_file("err_injct_inboundB", 0600,
213 phb->dbgfs, hose,
214 &ioda_eeh_inbB_dbgfs_ops);
215 }
216 #endif
217
218 /* If EEH is enabled, we're going to rely on that.
219 * Otherwise, we restore to conventional mechanism
220 * to clear frozen PE during PCI config access.
221 */
222 if (eeh_enabled())
223 phb->flags |= PNV_PHB_FLAG_EEH;
224 else
225 phb->flags &= ~PNV_PHB_FLAG_EEH;
226
227 return 0;
228 }
229
230 /**
231 * ioda_eeh_set_option - Set EEH operation or I/O setting
232 * @pe: EEH PE
233 * @option: options
234 *
235 * Enable or disable EEH option for the indicated PE. The
236 * function also can be used to enable I/O or DMA for the
237 * PE.
238 */
239 static int ioda_eeh_set_option(struct eeh_pe *pe, int option)
240 {
241 struct pci_controller *hose = pe->phb;
242 struct pnv_phb *phb = hose->private_data;
243 bool freeze_pe = false;
244 int enable, ret = 0;
245 s64 rc;
246
247 /* Check on PE number */
248 if (pe->addr < 0 || pe->addr >= phb->ioda.total_pe) {
249 pr_err("%s: PE address %x out of range [0, %x] "
250 "on PHB#%x\n",
251 __func__, pe->addr, phb->ioda.total_pe,
252 hose->global_number);
253 return -EINVAL;
254 }
255
256 switch (option) {
257 case EEH_OPT_DISABLE:
258 return -EPERM;
259 case EEH_OPT_ENABLE:
260 return 0;
261 case EEH_OPT_THAW_MMIO:
262 enable = OPAL_EEH_ACTION_CLEAR_FREEZE_MMIO;
263 break;
264 case EEH_OPT_THAW_DMA:
265 enable = OPAL_EEH_ACTION_CLEAR_FREEZE_DMA;
266 break;
267 case EEH_OPT_FREEZE_PE:
268 freeze_pe = true;
269 enable = OPAL_EEH_ACTION_SET_FREEZE_ALL;
270 break;
271 default:
272 pr_warn("%s: Invalid option %d\n",
273 __func__, option);
274 return -EINVAL;
275 }
276
277 /* If PHB supports compound PE, to handle it */
278 if (freeze_pe) {
279 if (phb->freeze_pe) {
280 phb->freeze_pe(phb, pe->addr);
281 } else {
282 rc = opal_pci_eeh_freeze_set(phb->opal_id,
283 pe->addr,
284 enable);
285 if (rc != OPAL_SUCCESS) {
286 pr_warn("%s: Failure %lld freezing "
287 "PHB#%x-PE#%x\n",
288 __func__, rc,
289 phb->hose->global_number, pe->addr);
290 ret = -EIO;
291 }
292 }
293 } else {
294 if (phb->unfreeze_pe) {
295 ret = phb->unfreeze_pe(phb, pe->addr, enable);
296 } else {
297 rc = opal_pci_eeh_freeze_clear(phb->opal_id,
298 pe->addr,
299 enable);
300 if (rc != OPAL_SUCCESS) {
301 pr_warn("%s: Failure %lld enable %d "
302 "for PHB#%x-PE#%x\n",
303 __func__, rc, option,
304 phb->hose->global_number, pe->addr);
305 ret = -EIO;
306 }
307 }
308 }
309
310 return ret;
311 }
312
313 static void ioda_eeh_phb_diag(struct eeh_pe *pe)
314 {
315 struct pnv_phb *phb = pe->phb->private_data;
316 long rc;
317
318 rc = opal_pci_get_phb_diag_data2(phb->opal_id, pe->data,
319 PNV_PCI_DIAG_BUF_SIZE);
320 if (rc != OPAL_SUCCESS)
321 pr_warn("%s: Failed to get diag-data for PHB#%x (%ld)\n",
322 __func__, pe->phb->global_number, rc);
323 }
324
325 static int ioda_eeh_get_phb_state(struct eeh_pe *pe)
326 {
327 struct pnv_phb *phb = pe->phb->private_data;
328 u8 fstate;
329 __be16 pcierr;
330 s64 rc;
331 int result = 0;
332
333 rc = opal_pci_eeh_freeze_status(phb->opal_id,
334 pe->addr,
335 &fstate,
336 &pcierr,
337 NULL);
338 if (rc != OPAL_SUCCESS) {
339 pr_warn("%s: Failure %lld getting PHB#%x state\n",
340 __func__, rc, phb->hose->global_number);
341 return EEH_STATE_NOT_SUPPORT;
342 }
343
344 /*
345 * Check PHB state. If the PHB is frozen for the
346 * first time, to dump the PHB diag-data.
347 */
348 if (be16_to_cpu(pcierr) != OPAL_EEH_PHB_ERROR) {
349 result = (EEH_STATE_MMIO_ACTIVE |
350 EEH_STATE_DMA_ACTIVE |
351 EEH_STATE_MMIO_ENABLED |
352 EEH_STATE_DMA_ENABLED);
353 } else if (!(pe->state & EEH_PE_ISOLATED)) {
354 eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
355 ioda_eeh_phb_diag(pe);
356 }
357
358 return result;
359 }
360
361 static int ioda_eeh_get_pe_state(struct eeh_pe *pe)
362 {
363 struct pnv_phb *phb = pe->phb->private_data;
364 u8 fstate;
365 __be16 pcierr;
366 s64 rc;
367 int result;
368
369 /*
370 * We don't clobber hardware frozen state until PE
371 * reset is completed. In order to keep EEH core
372 * moving forward, we have to return operational
373 * state during PE reset.
374 */
375 if (pe->state & EEH_PE_RESET) {
376 result = (EEH_STATE_MMIO_ACTIVE |
377 EEH_STATE_DMA_ACTIVE |
378 EEH_STATE_MMIO_ENABLED |
379 EEH_STATE_DMA_ENABLED);
380 return result;
381 }
382
383 /*
384 * Fetch PE state from hardware. If the PHB
385 * supports compound PE, let it handle that.
386 */
387 if (phb->get_pe_state) {
388 fstate = phb->get_pe_state(phb, pe->addr);
389 } else {
390 rc = opal_pci_eeh_freeze_status(phb->opal_id,
391 pe->addr,
392 &fstate,
393 &pcierr,
394 NULL);
395 if (rc != OPAL_SUCCESS) {
396 pr_warn("%s: Failure %lld getting PHB#%x-PE%x state\n",
397 __func__, rc, phb->hose->global_number, pe->addr);
398 return EEH_STATE_NOT_SUPPORT;
399 }
400 }
401
402 /* Figure out state */
403 switch (fstate) {
404 case OPAL_EEH_STOPPED_NOT_FROZEN:
405 result = (EEH_STATE_MMIO_ACTIVE |
406 EEH_STATE_DMA_ACTIVE |
407 EEH_STATE_MMIO_ENABLED |
408 EEH_STATE_DMA_ENABLED);
409 break;
410 case OPAL_EEH_STOPPED_MMIO_FREEZE:
411 result = (EEH_STATE_DMA_ACTIVE |
412 EEH_STATE_DMA_ENABLED);
413 break;
414 case OPAL_EEH_STOPPED_DMA_FREEZE:
415 result = (EEH_STATE_MMIO_ACTIVE |
416 EEH_STATE_MMIO_ENABLED);
417 break;
418 case OPAL_EEH_STOPPED_MMIO_DMA_FREEZE:
419 result = 0;
420 break;
421 case OPAL_EEH_STOPPED_RESET:
422 result = EEH_STATE_RESET_ACTIVE;
423 break;
424 case OPAL_EEH_STOPPED_TEMP_UNAVAIL:
425 result = EEH_STATE_UNAVAILABLE;
426 break;
427 case OPAL_EEH_STOPPED_PERM_UNAVAIL:
428 result = EEH_STATE_NOT_SUPPORT;
429 break;
430 default:
431 result = EEH_STATE_NOT_SUPPORT;
432 pr_warn("%s: Invalid PHB#%x-PE#%x state %x\n",
433 __func__, phb->hose->global_number,
434 pe->addr, fstate);
435 }
436
437 /*
438 * If PHB supports compound PE, to freeze all
439 * slave PEs for consistency.
440 *
441 * If the PE is switching to frozen state for the
442 * first time, to dump the PHB diag-data.
443 */
444 if (!(result & EEH_STATE_NOT_SUPPORT) &&
445 !(result & EEH_STATE_UNAVAILABLE) &&
446 !(result & EEH_STATE_MMIO_ACTIVE) &&
447 !(result & EEH_STATE_DMA_ACTIVE) &&
448 !(pe->state & EEH_PE_ISOLATED)) {
449 if (phb->freeze_pe)
450 phb->freeze_pe(phb, pe->addr);
451
452 eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
453 ioda_eeh_phb_diag(pe);
454 }
455
456 return result;
457 }
458
459 /**
460 * ioda_eeh_get_state - Retrieve the state of PE
461 * @pe: EEH PE
462 *
463 * The PE's state should be retrieved from the PEEV, PEST
464 * IODA tables. Since the OPAL has exported the function
465 * to do it, it'd better to use that.
466 */
467 static int ioda_eeh_get_state(struct eeh_pe *pe)
468 {
469 struct pnv_phb *phb = pe->phb->private_data;
470
471 /* Sanity check on PE number. PHB PE should have 0 */
472 if (pe->addr < 0 ||
473 pe->addr >= phb->ioda.total_pe) {
474 pr_warn("%s: PHB#%x-PE#%x out of range [0, %x]\n",
475 __func__, phb->hose->global_number,
476 pe->addr, phb->ioda.total_pe);
477 return EEH_STATE_NOT_SUPPORT;
478 }
479
480 if (pe->type & EEH_PE_PHB)
481 return ioda_eeh_get_phb_state(pe);
482
483 return ioda_eeh_get_pe_state(pe);
484 }
485
486 static s64 ioda_eeh_phb_poll(struct pnv_phb *phb)
487 {
488 s64 rc = OPAL_HARDWARE;
489
490 while (1) {
491 rc = opal_pci_poll(phb->opal_id);
492 if (rc <= 0)
493 break;
494
495 if (system_state < SYSTEM_RUNNING)
496 udelay(1000 * rc);
497 else
498 msleep(rc);
499 }
500
501 return rc;
502 }
503
504 int ioda_eeh_phb_reset(struct pci_controller *hose, int option)
505 {
506 struct pnv_phb *phb = hose->private_data;
507 s64 rc = OPAL_HARDWARE;
508
509 pr_debug("%s: Reset PHB#%x, option=%d\n",
510 __func__, hose->global_number, option);
511
512 /* Issue PHB complete reset request */
513 if (option == EEH_RESET_FUNDAMENTAL ||
514 option == EEH_RESET_HOT)
515 rc = opal_pci_reset(phb->opal_id,
516 OPAL_RESET_PHB_COMPLETE,
517 OPAL_ASSERT_RESET);
518 else if (option == EEH_RESET_DEACTIVATE)
519 rc = opal_pci_reset(phb->opal_id,
520 OPAL_RESET_PHB_COMPLETE,
521 OPAL_DEASSERT_RESET);
522 if (rc < 0)
523 goto out;
524
525 /*
526 * Poll state of the PHB until the request is done
527 * successfully. The PHB reset is usually PHB complete
528 * reset followed by hot reset on root bus. So we also
529 * need the PCI bus settlement delay.
530 */
531 rc = ioda_eeh_phb_poll(phb);
532 if (option == EEH_RESET_DEACTIVATE) {
533 if (system_state < SYSTEM_RUNNING)
534 udelay(1000 * EEH_PE_RST_SETTLE_TIME);
535 else
536 msleep(EEH_PE_RST_SETTLE_TIME);
537 }
538 out:
539 if (rc != OPAL_SUCCESS)
540 return -EIO;
541
542 return 0;
543 }
544
545 static int ioda_eeh_root_reset(struct pci_controller *hose, int option)
546 {
547 struct pnv_phb *phb = hose->private_data;
548 s64 rc = OPAL_SUCCESS;
549
550 pr_debug("%s: Reset PHB#%x, option=%d\n",
551 __func__, hose->global_number, option);
552
553 /*
554 * During the reset deassert time, we needn't care
555 * the reset scope because the firmware does nothing
556 * for fundamental or hot reset during deassert phase.
557 */
558 if (option == EEH_RESET_FUNDAMENTAL)
559 rc = opal_pci_reset(phb->opal_id,
560 OPAL_RESET_PCI_FUNDAMENTAL,
561 OPAL_ASSERT_RESET);
562 else if (option == EEH_RESET_HOT)
563 rc = opal_pci_reset(phb->opal_id,
564 OPAL_RESET_PCI_HOT,
565 OPAL_ASSERT_RESET);
566 else if (option == EEH_RESET_DEACTIVATE)
567 rc = opal_pci_reset(phb->opal_id,
568 OPAL_RESET_PCI_HOT,
569 OPAL_DEASSERT_RESET);
570 if (rc < 0)
571 goto out;
572
573 /* Poll state of the PHB until the request is done */
574 rc = ioda_eeh_phb_poll(phb);
575 if (option == EEH_RESET_DEACTIVATE)
576 msleep(EEH_PE_RST_SETTLE_TIME);
577 out:
578 if (rc != OPAL_SUCCESS)
579 return -EIO;
580
581 return 0;
582 }
583
584 static int ioda_eeh_bridge_reset(struct pci_dev *dev, int option)
585
586 {
587 struct device_node *dn = pci_device_to_OF_node(dev);
588 struct eeh_dev *edev = of_node_to_eeh_dev(dn);
589 int aer = edev ? edev->aer_cap : 0;
590 u32 ctrl;
591
592 pr_debug("%s: Reset PCI bus %04x:%02x with option %d\n",
593 __func__, pci_domain_nr(dev->bus),
594 dev->bus->number, option);
595
596 switch (option) {
597 case EEH_RESET_FUNDAMENTAL:
598 case EEH_RESET_HOT:
599 /* Don't report linkDown event */
600 if (aer) {
601 eeh_ops->read_config(dn, aer + PCI_ERR_UNCOR_MASK,
602 4, &ctrl);
603 ctrl |= PCI_ERR_UNC_SURPDN;
604 eeh_ops->write_config(dn, aer + PCI_ERR_UNCOR_MASK,
605 4, ctrl);
606 }
607
608 eeh_ops->read_config(dn, PCI_BRIDGE_CONTROL, 2, &ctrl);
609 ctrl |= PCI_BRIDGE_CTL_BUS_RESET;
610 eeh_ops->write_config(dn, PCI_BRIDGE_CONTROL, 2, ctrl);
611 msleep(EEH_PE_RST_HOLD_TIME);
612
613 break;
614 case EEH_RESET_DEACTIVATE:
615 eeh_ops->read_config(dn, PCI_BRIDGE_CONTROL, 2, &ctrl);
616 ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET;
617 eeh_ops->write_config(dn, PCI_BRIDGE_CONTROL, 2, ctrl);
618 msleep(EEH_PE_RST_SETTLE_TIME);
619
620 /* Continue reporting linkDown event */
621 if (aer) {
622 eeh_ops->read_config(dn, aer + PCI_ERR_UNCOR_MASK,
623 4, &ctrl);
624 ctrl &= ~PCI_ERR_UNC_SURPDN;
625 eeh_ops->write_config(dn, aer + PCI_ERR_UNCOR_MASK,
626 4, ctrl);
627 }
628
629 break;
630 }
631
632 return 0;
633 }
634
635 void pnv_pci_reset_secondary_bus(struct pci_dev *dev)
636 {
637 struct pci_controller *hose;
638
639 if (pci_is_root_bus(dev->bus)) {
640 hose = pci_bus_to_host(dev->bus);
641 ioda_eeh_root_reset(hose, EEH_RESET_HOT);
642 ioda_eeh_root_reset(hose, EEH_RESET_DEACTIVATE);
643 } else {
644 ioda_eeh_bridge_reset(dev, EEH_RESET_HOT);
645 ioda_eeh_bridge_reset(dev, EEH_RESET_DEACTIVATE);
646 }
647 }
648
649 /**
650 * ioda_eeh_reset - Reset the indicated PE
651 * @pe: EEH PE
652 * @option: reset option
653 *
654 * Do reset on the indicated PE. For PCI bus sensitive PE,
655 * we need to reset the parent p2p bridge. The PHB has to
656 * be reinitialized if the p2p bridge is root bridge. For
657 * PCI device sensitive PE, we will try to reset the device
658 * through FLR. For now, we don't have OPAL APIs to do HARD
659 * reset yet, so all reset would be SOFT (HOT) reset.
660 */
661 static int ioda_eeh_reset(struct eeh_pe *pe, int option)
662 {
663 struct pci_controller *hose = pe->phb;
664 struct pci_bus *bus;
665 int ret;
666
667 /*
668 * For PHB reset, we always have complete reset. For those PEs whose
669 * primary bus derived from root complex (root bus) or root port
670 * (usually bus#1), we apply hot or fundamental reset on the root port.
671 * For other PEs, we always have hot reset on the PE primary bus.
672 *
673 * Here, we have different design to pHyp, which always clear the
674 * frozen state during PE reset. However, the good idea here from
675 * benh is to keep frozen state before we get PE reset done completely
676 * (until BAR restore). With the frozen state, HW drops illegal IO
677 * or MMIO access, which can incur recrusive frozen PE during PE
678 * reset. The side effect is that EEH core has to clear the frozen
679 * state explicitly after BAR restore.
680 */
681 if (pe->type & EEH_PE_PHB) {
682 ret = ioda_eeh_phb_reset(hose, option);
683 } else {
684 struct pnv_phb *phb;
685 s64 rc;
686
687 /*
688 * The frozen PE might be caused by PAPR error injection
689 * registers, which are expected to be cleared after hitting
690 * frozen PE as stated in the hardware spec. Unfortunately,
691 * that's not true on P7IOC. So we have to clear it manually
692 * to avoid recursive EEH errors during recovery.
693 */
694 phb = hose->private_data;
695 if (phb->model == PNV_PHB_MODEL_P7IOC &&
696 (option == EEH_RESET_HOT ||
697 option == EEH_RESET_FUNDAMENTAL)) {
698 rc = opal_pci_reset(phb->opal_id,
699 OPAL_RESET_PHB_ERROR,
700 OPAL_ASSERT_RESET);
701 if (rc != OPAL_SUCCESS) {
702 pr_warn("%s: Failure %lld clearing "
703 "error injection registers\n",
704 __func__, rc);
705 return -EIO;
706 }
707 }
708
709 bus = eeh_pe_bus_get(pe);
710 if (pci_is_root_bus(bus) ||
711 pci_is_root_bus(bus->parent))
712 ret = ioda_eeh_root_reset(hose, option);
713 else
714 ret = ioda_eeh_bridge_reset(bus->self, option);
715 }
716
717 return ret;
718 }
719
720 /**
721 * ioda_eeh_get_log - Retrieve error log
722 * @pe: frozen PE
723 * @severity: permanent or temporary error
724 * @drv_log: device driver log
725 * @len: length of device driver log
726 *
727 * Retrieve error log, which contains log from device driver
728 * and firmware.
729 */
730 static int ioda_eeh_get_log(struct eeh_pe *pe, int severity,
731 char *drv_log, unsigned long len)
732 {
733 pnv_pci_dump_phb_diag_data(pe->phb, pe->data);
734
735 return 0;
736 }
737
738 /**
739 * ioda_eeh_configure_bridge - Configure the PCI bridges for the indicated PE
740 * @pe: EEH PE
741 *
742 * For particular PE, it might have included PCI bridges. In order
743 * to make the PE work properly, those PCI bridges should be configured
744 * correctly. However, we need do nothing on P7IOC since the reset
745 * function will do everything that should be covered by the function.
746 */
747 static int ioda_eeh_configure_bridge(struct eeh_pe *pe)
748 {
749 return 0;
750 }
751
752 static int ioda_eeh_err_inject(struct eeh_pe *pe, int type, int func,
753 unsigned long addr, unsigned long mask)
754 {
755 struct pci_controller *hose = pe->phb;
756 struct pnv_phb *phb = hose->private_data;
757 s64 ret;
758
759 /* Sanity check on error type */
760 if (type != OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR &&
761 type != OPAL_ERR_INJECT_TYPE_IOA_BUS_ERR64) {
762 pr_warn("%s: Invalid error type %d\n",
763 __func__, type);
764 return -ERANGE;
765 }
766
767 if (func < OPAL_ERR_INJECT_FUNC_IOA_LD_MEM_ADDR ||
768 func > OPAL_ERR_INJECT_FUNC_IOA_DMA_WR_TARGET) {
769 pr_warn("%s: Invalid error function %d\n",
770 __func__, func);
771 return -ERANGE;
772 }
773
774 /* Firmware supports error injection ? */
775 if (!opal_check_token(OPAL_PCI_ERR_INJECT)) {
776 pr_warn("%s: Firmware doesn't support error injection\n",
777 __func__);
778 return -ENXIO;
779 }
780
781 /* Do error injection */
782 ret = opal_pci_err_inject(phb->opal_id, pe->addr,
783 type, func, addr, mask);
784 if (ret != OPAL_SUCCESS) {
785 pr_warn("%s: Failure %lld injecting error "
786 "%d-%d to PHB#%x-PE#%x\n",
787 __func__, ret, type, func,
788 hose->global_number, pe->addr);
789 return -EIO;
790 }
791
792 return 0;
793 }
794
795 static void ioda_eeh_hub_diag_common(struct OpalIoP7IOCErrorData *data)
796 {
797 /* GEM */
798 if (data->gemXfir || data->gemRfir ||
799 data->gemRirqfir || data->gemMask || data->gemRwof)
800 pr_info(" GEM: %016llx %016llx %016llx %016llx %016llx\n",
801 be64_to_cpu(data->gemXfir),
802 be64_to_cpu(data->gemRfir),
803 be64_to_cpu(data->gemRirqfir),
804 be64_to_cpu(data->gemMask),
805 be64_to_cpu(data->gemRwof));
806
807 /* LEM */
808 if (data->lemFir || data->lemErrMask ||
809 data->lemAction0 || data->lemAction1 || data->lemWof)
810 pr_info(" LEM: %016llx %016llx %016llx %016llx %016llx\n",
811 be64_to_cpu(data->lemFir),
812 be64_to_cpu(data->lemErrMask),
813 be64_to_cpu(data->lemAction0),
814 be64_to_cpu(data->lemAction1),
815 be64_to_cpu(data->lemWof));
816 }
817
818 static void ioda_eeh_hub_diag(struct pci_controller *hose)
819 {
820 struct pnv_phb *phb = hose->private_data;
821 struct OpalIoP7IOCErrorData *data = &phb->diag.hub_diag;
822 long rc;
823
824 rc = opal_pci_get_hub_diag_data(phb->hub_id, data, sizeof(*data));
825 if (rc != OPAL_SUCCESS) {
826 pr_warn("%s: Failed to get HUB#%llx diag-data (%ld)\n",
827 __func__, phb->hub_id, rc);
828 return;
829 }
830
831 switch (data->type) {
832 case OPAL_P7IOC_DIAG_TYPE_RGC:
833 pr_info("P7IOC diag-data for RGC\n\n");
834 ioda_eeh_hub_diag_common(data);
835 if (data->rgc.rgcStatus || data->rgc.rgcLdcp)
836 pr_info(" RGC: %016llx %016llx\n",
837 be64_to_cpu(data->rgc.rgcStatus),
838 be64_to_cpu(data->rgc.rgcLdcp));
839 break;
840 case OPAL_P7IOC_DIAG_TYPE_BI:
841 pr_info("P7IOC diag-data for BI %s\n\n",
842 data->bi.biDownbound ? "Downbound" : "Upbound");
843 ioda_eeh_hub_diag_common(data);
844 if (data->bi.biLdcp0 || data->bi.biLdcp1 ||
845 data->bi.biLdcp2 || data->bi.biFenceStatus)
846 pr_info(" BI: %016llx %016llx %016llx %016llx\n",
847 be64_to_cpu(data->bi.biLdcp0),
848 be64_to_cpu(data->bi.biLdcp1),
849 be64_to_cpu(data->bi.biLdcp2),
850 be64_to_cpu(data->bi.biFenceStatus));
851 break;
852 case OPAL_P7IOC_DIAG_TYPE_CI:
853 pr_info("P7IOC diag-data for CI Port %d\n\n",
854 data->ci.ciPort);
855 ioda_eeh_hub_diag_common(data);
856 if (data->ci.ciPortStatus || data->ci.ciPortLdcp)
857 pr_info(" CI: %016llx %016llx\n",
858 be64_to_cpu(data->ci.ciPortStatus),
859 be64_to_cpu(data->ci.ciPortLdcp));
860 break;
861 case OPAL_P7IOC_DIAG_TYPE_MISC:
862 pr_info("P7IOC diag-data for MISC\n\n");
863 ioda_eeh_hub_diag_common(data);
864 break;
865 case OPAL_P7IOC_DIAG_TYPE_I2C:
866 pr_info("P7IOC diag-data for I2C\n\n");
867 ioda_eeh_hub_diag_common(data);
868 break;
869 default:
870 pr_warn("%s: Invalid type of HUB#%llx diag-data (%d)\n",
871 __func__, phb->hub_id, data->type);
872 }
873 }
874
875 static int ioda_eeh_get_pe(struct pci_controller *hose,
876 u16 pe_no, struct eeh_pe **pe)
877 {
878 struct pnv_phb *phb = hose->private_data;
879 struct pnv_ioda_pe *pnv_pe;
880 struct eeh_pe *dev_pe;
881 struct eeh_dev edev;
882
883 /*
884 * If PHB supports compound PE, to fetch
885 * the master PE because slave PE is invisible
886 * to EEH core.
887 */
888 pnv_pe = &phb->ioda.pe_array[pe_no];
889 if (pnv_pe->flags & PNV_IODA_PE_SLAVE) {
890 pnv_pe = pnv_pe->master;
891 WARN_ON(!pnv_pe ||
892 !(pnv_pe->flags & PNV_IODA_PE_MASTER));
893 pe_no = pnv_pe->pe_number;
894 }
895
896 /* Find the PE according to PE# */
897 memset(&edev, 0, sizeof(struct eeh_dev));
898 edev.phb = hose;
899 edev.pe_config_addr = pe_no;
900 dev_pe = eeh_pe_get(&edev);
901 if (!dev_pe)
902 return -EEXIST;
903
904 /* Freeze the (compound) PE */
905 *pe = dev_pe;
906 if (!(dev_pe->state & EEH_PE_ISOLATED))
907 phb->freeze_pe(phb, pe_no);
908
909 /*
910 * At this point, we're sure the (compound) PE should
911 * have been frozen. However, we still need poke until
912 * hitting the frozen PE on top level.
913 */
914 dev_pe = dev_pe->parent;
915 while (dev_pe && !(dev_pe->type & EEH_PE_PHB)) {
916 int ret;
917 int active_flags = (EEH_STATE_MMIO_ACTIVE |
918 EEH_STATE_DMA_ACTIVE);
919
920 ret = eeh_ops->get_state(dev_pe, NULL);
921 if (ret <= 0 || (ret & active_flags) == active_flags) {
922 dev_pe = dev_pe->parent;
923 continue;
924 }
925
926 /* Frozen parent PE */
927 *pe = dev_pe;
928 if (!(dev_pe->state & EEH_PE_ISOLATED))
929 phb->freeze_pe(phb, dev_pe->addr);
930
931 /* Next one */
932 dev_pe = dev_pe->parent;
933 }
934
935 return 0;
936 }
937
938 /**
939 * ioda_eeh_next_error - Retrieve next error for EEH core to handle
940 * @pe: The affected PE
941 *
942 * The function is expected to be called by EEH core while it gets
943 * special EEH event (without binding PE). The function calls to
944 * OPAL APIs for next error to handle. The informational error is
945 * handled internally by platform. However, the dead IOC, dead PHB,
946 * fenced PHB and frozen PE should be handled by EEH core eventually.
947 */
948 static int ioda_eeh_next_error(struct eeh_pe **pe)
949 {
950 struct pci_controller *hose;
951 struct pnv_phb *phb;
952 struct eeh_pe *phb_pe, *parent_pe;
953 __be64 frozen_pe_no;
954 __be16 err_type, severity;
955 int active_flags = (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE);
956 long rc;
957 int state, ret = EEH_NEXT_ERR_NONE;
958
959 /*
960 * While running here, it's safe to purge the event queue.
961 * And we should keep the cached OPAL notifier event sychronized
962 * between the kernel and firmware.
963 */
964 eeh_remove_event(NULL, false);
965 opal_notifier_update_evt(OPAL_EVENT_PCI_ERROR, 0x0ul);
966
967 list_for_each_entry(hose, &hose_list, list_node) {
968 /*
969 * If the subordinate PCI buses of the PHB has been
970 * removed or is exactly under error recovery, we
971 * needn't take care of it any more.
972 */
973 phb = hose->private_data;
974 phb_pe = eeh_phb_pe_get(hose);
975 if (!phb_pe || (phb_pe->state & EEH_PE_ISOLATED))
976 continue;
977
978 rc = opal_pci_next_error(phb->opal_id,
979 &frozen_pe_no, &err_type, &severity);
980
981 /* If OPAL API returns error, we needn't proceed */
982 if (rc != OPAL_SUCCESS) {
983 pr_devel("%s: Invalid return value on "
984 "PHB#%x (0x%lx) from opal_pci_next_error",
985 __func__, hose->global_number, rc);
986 continue;
987 }
988
989 /* If the PHB doesn't have error, stop processing */
990 if (be16_to_cpu(err_type) == OPAL_EEH_NO_ERROR ||
991 be16_to_cpu(severity) == OPAL_EEH_SEV_NO_ERROR) {
992 pr_devel("%s: No error found on PHB#%x\n",
993 __func__, hose->global_number);
994 continue;
995 }
996
997 /*
998 * Processing the error. We're expecting the error with
999 * highest priority reported upon multiple errors on the
1000 * specific PHB.
1001 */
1002 pr_devel("%s: Error (%d, %d, %llu) on PHB#%x\n",
1003 __func__, be16_to_cpu(err_type), be16_to_cpu(severity),
1004 be64_to_cpu(frozen_pe_no), hose->global_number);
1005 switch (be16_to_cpu(err_type)) {
1006 case OPAL_EEH_IOC_ERROR:
1007 if (be16_to_cpu(severity) == OPAL_EEH_SEV_IOC_DEAD) {
1008 pr_err("EEH: dead IOC detected\n");
1009 ret = EEH_NEXT_ERR_DEAD_IOC;
1010 } else if (be16_to_cpu(severity) == OPAL_EEH_SEV_INF) {
1011 pr_info("EEH: IOC informative error "
1012 "detected\n");
1013 ioda_eeh_hub_diag(hose);
1014 ret = EEH_NEXT_ERR_NONE;
1015 }
1016
1017 break;
1018 case OPAL_EEH_PHB_ERROR:
1019 if (be16_to_cpu(severity) == OPAL_EEH_SEV_PHB_DEAD) {
1020 *pe = phb_pe;
1021 pr_err("EEH: dead PHB#%x detected, "
1022 "location: %s\n",
1023 hose->global_number,
1024 eeh_pe_loc_get(phb_pe));
1025 ret = EEH_NEXT_ERR_DEAD_PHB;
1026 } else if (be16_to_cpu(severity) ==
1027 OPAL_EEH_SEV_PHB_FENCED) {
1028 *pe = phb_pe;
1029 pr_err("EEH: Fenced PHB#%x detected, "
1030 "location: %s\n",
1031 hose->global_number,
1032 eeh_pe_loc_get(phb_pe));
1033 ret = EEH_NEXT_ERR_FENCED_PHB;
1034 } else if (be16_to_cpu(severity) == OPAL_EEH_SEV_INF) {
1035 pr_info("EEH: PHB#%x informative error "
1036 "detected, location: %s\n",
1037 hose->global_number,
1038 eeh_pe_loc_get(phb_pe));
1039 ioda_eeh_phb_diag(phb_pe);
1040 pnv_pci_dump_phb_diag_data(hose, phb_pe->data);
1041 ret = EEH_NEXT_ERR_NONE;
1042 }
1043
1044 break;
1045 case OPAL_EEH_PE_ERROR:
1046 /*
1047 * If we can't find the corresponding PE, we
1048 * just try to unfreeze.
1049 */
1050 if (ioda_eeh_get_pe(hose,
1051 be64_to_cpu(frozen_pe_no), pe)) {
1052 /* Try best to clear it */
1053 pr_info("EEH: Clear non-existing PHB#%x-PE#%llx\n",
1054 hose->global_number, frozen_pe_no);
1055 pr_info("EEH: PHB location: %s\n",
1056 eeh_pe_loc_get(phb_pe));
1057 opal_pci_eeh_freeze_clear(phb->opal_id, frozen_pe_no,
1058 OPAL_EEH_ACTION_CLEAR_FREEZE_ALL);
1059 ret = EEH_NEXT_ERR_NONE;
1060 } else if ((*pe)->state & EEH_PE_ISOLATED ||
1061 eeh_pe_passed(*pe)) {
1062 ret = EEH_NEXT_ERR_NONE;
1063 } else {
1064 pr_err("EEH: Frozen PE#%x on PHB#%x detected\n",
1065 (*pe)->addr, (*pe)->phb->global_number);
1066 pr_err("EEH: PE location: %s, PHB location: %s\n",
1067 eeh_pe_loc_get(*pe), eeh_pe_loc_get(phb_pe));
1068 ret = EEH_NEXT_ERR_FROZEN_PE;
1069 }
1070
1071 break;
1072 default:
1073 pr_warn("%s: Unexpected error type %d\n",
1074 __func__, be16_to_cpu(err_type));
1075 }
1076
1077 /*
1078 * EEH core will try recover from fenced PHB or
1079 * frozen PE. In the time for frozen PE, EEH core
1080 * enable IO path for that before collecting logs,
1081 * but it ruins the site. So we have to dump the
1082 * log in advance here.
1083 */
1084 if ((ret == EEH_NEXT_ERR_FROZEN_PE ||
1085 ret == EEH_NEXT_ERR_FENCED_PHB) &&
1086 !((*pe)->state & EEH_PE_ISOLATED)) {
1087 eeh_pe_state_mark(*pe, EEH_PE_ISOLATED);
1088 ioda_eeh_phb_diag(*pe);
1089 }
1090
1091 /*
1092 * We probably have the frozen parent PE out there and
1093 * we need have to handle frozen parent PE firstly.
1094 */
1095 if (ret == EEH_NEXT_ERR_FROZEN_PE) {
1096 parent_pe = (*pe)->parent;
1097 while (parent_pe) {
1098 /* Hit the ceiling ? */
1099 if (parent_pe->type & EEH_PE_PHB)
1100 break;
1101
1102 /* Frozen parent PE ? */
1103 state = ioda_eeh_get_state(parent_pe);
1104 if (state > 0 &&
1105 (state & active_flags) != active_flags)
1106 *pe = parent_pe;
1107
1108 /* Next parent level */
1109 parent_pe = parent_pe->parent;
1110 }
1111
1112 /* We possibly migrate to another PE */
1113 eeh_pe_state_mark(*pe, EEH_PE_ISOLATED);
1114 }
1115
1116 /*
1117 * If we have no errors on the specific PHB or only
1118 * informative error there, we continue poking it.
1119 * Otherwise, we need actions to be taken by upper
1120 * layer.
1121 */
1122 if (ret > EEH_NEXT_ERR_INF)
1123 break;
1124 }
1125
1126 return ret;
1127 }
1128
1129 struct pnv_eeh_ops ioda_eeh_ops = {
1130 .post_init = ioda_eeh_post_init,
1131 .set_option = ioda_eeh_set_option,
1132 .get_state = ioda_eeh_get_state,
1133 .reset = ioda_eeh_reset,
1134 .get_log = ioda_eeh_get_log,
1135 .configure_bridge = ioda_eeh_configure_bridge,
1136 .err_inject = ioda_eeh_err_inject,
1137 .next_error = ioda_eeh_next_error
1138 };
This page took 0.224216 seconds and 5 git commands to generate.