This source file includes following definitions.
- eeh_result_priority
- pci_ers_result_name
- pci_ers_merge_result
- eeh_dev_removed
- eeh_edev_actionable
- eeh_pcid_get
- eeh_pcid_put
- eeh_disable_irq
- eeh_enable_irq
- eeh_dev_save_state
- eeh_set_channel_state
- eeh_set_irq_state
- edev
- pci_lock_rescan_remove
- pci_unlock_rescan_remove
- pci_ers_result_name
- eeh_dev_removed
- eeh_pe_passed
- pr_info
- pe
- edev
- pr_info
- pci_ers_result_name
- pr_info
- list_is_last
- eeh_dev_to_pdn
- pr_info
- pci_name
- pci_lock_rescan_remove
- pci_unlock_rescan_remove
- eeh_pe_reset_and_recover
- eeh_reset_device
- eeh_pe_cleanup
- eeh_slot_presence_check
- eeh_clear_slot_attention
- eeh_handle_normal_event
- eeh_handle_special_event
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #include <linux/delay.h>
26 #include <linux/interrupt.h>
27 #include <linux/irq.h>
28 #include <linux/module.h>
29 #include <linux/pci.h>
30 #include <linux/pci_hotplug.h>
31 #include <asm/eeh.h>
32 #include <asm/eeh_event.h>
33 #include <asm/ppc-pci.h>
34 #include <asm/pci-bridge.h>
35 #include <asm/prom.h>
36 #include <asm/rtas.h>
37
38 struct eeh_rmv_data {
39 struct list_head removed_vf_list;
40 int removed_dev_count;
41 };
42
43 static int eeh_result_priority(enum pci_ers_result result)
44 {
45 switch (result) {
46 case PCI_ERS_RESULT_NONE:
47 return 1;
48 case PCI_ERS_RESULT_NO_AER_DRIVER:
49 return 2;
50 case PCI_ERS_RESULT_RECOVERED:
51 return 3;
52 case PCI_ERS_RESULT_CAN_RECOVER:
53 return 4;
54 case PCI_ERS_RESULT_DISCONNECT:
55 return 5;
56 case PCI_ERS_RESULT_NEED_RESET:
57 return 6;
58 default:
59 WARN_ONCE(1, "Unknown pci_ers_result value: %d\n", (int)result);
60 return 0;
61 }
62 };
63
64 static const char *pci_ers_result_name(enum pci_ers_result result)
65 {
66 switch (result) {
67 case PCI_ERS_RESULT_NONE:
68 return "none";
69 case PCI_ERS_RESULT_CAN_RECOVER:
70 return "can recover";
71 case PCI_ERS_RESULT_NEED_RESET:
72 return "need reset";
73 case PCI_ERS_RESULT_DISCONNECT:
74 return "disconnect";
75 case PCI_ERS_RESULT_RECOVERED:
76 return "recovered";
77 case PCI_ERS_RESULT_NO_AER_DRIVER:
78 return "no AER driver";
79 default:
80 WARN_ONCE(1, "Unknown result type: %d\n", (int)result);
81 return "unknown";
82 }
83 };
84
85 static enum pci_ers_result pci_ers_merge_result(enum pci_ers_result old,
86 enum pci_ers_result new)
87 {
88 if (eeh_result_priority(new) > eeh_result_priority(old))
89 return new;
90 return old;
91 }
92
93 static bool eeh_dev_removed(struct eeh_dev *edev)
94 {
95 return !edev || (edev->mode & EEH_DEV_REMOVED);
96 }
97
98 static bool eeh_edev_actionable(struct eeh_dev *edev)
99 {
100 if (!edev->pdev)
101 return false;
102 if (edev->pdev->error_state == pci_channel_io_perm_failure)
103 return false;
104 if (eeh_dev_removed(edev))
105 return false;
106 if (eeh_pe_passed(edev->pe))
107 return false;
108
109 return true;
110 }
111
112
113
114
115
116
117
118
119
120
121 static inline struct pci_driver *eeh_pcid_get(struct pci_dev *pdev)
122 {
123 if (!pdev || !pdev->driver)
124 return NULL;
125
126 if (!try_module_get(pdev->driver->driver.owner))
127 return NULL;
128
129 return pdev->driver;
130 }
131
132
133
134
135
136
137
138
139 static inline void eeh_pcid_put(struct pci_dev *pdev)
140 {
141 if (!pdev || !pdev->driver)
142 return;
143
144 module_put(pdev->driver->driver.owner);
145 }
146
147
148
149
150
151
152
153
154
155
156
157 static void eeh_disable_irq(struct eeh_dev *edev)
158 {
159
160
161
162
163 if (edev->pdev->msi_enabled || edev->pdev->msix_enabled)
164 return;
165
166 if (!irq_has_action(edev->pdev->irq))
167 return;
168
169 edev->mode |= EEH_DEV_IRQ_DISABLED;
170 disable_irq_nosync(edev->pdev->irq);
171 }
172
173
174
175
176
177
178
179
180 static void eeh_enable_irq(struct eeh_dev *edev)
181 {
182 if ((edev->mode) & EEH_DEV_IRQ_DISABLED) {
183 edev->mode &= ~EEH_DEV_IRQ_DISABLED;
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204 if (irqd_irq_disabled(irq_get_irq_data(edev->pdev->irq)))
205 enable_irq(edev->pdev->irq);
206 }
207 }
208
209 static void eeh_dev_save_state(struct eeh_dev *edev, void *userdata)
210 {
211 struct pci_dev *pdev;
212
213 if (!edev)
214 return;
215
216
217
218
219
220
221
222
223 if (edev->pe && (edev->pe->state & EEH_PE_CFG_RESTRICTED))
224 return;
225
226 pdev = eeh_dev_to_pci_dev(edev);
227 if (!pdev)
228 return;
229
230 pci_save_state(pdev);
231 }
232
233 static void eeh_set_channel_state(struct eeh_pe *root, enum pci_channel_state s)
234 {
235 struct eeh_pe *pe;
236 struct eeh_dev *edev, *tmp;
237
238 eeh_for_each_pe(root, pe)
239 eeh_pe_for_each_dev(pe, edev, tmp)
240 if (eeh_edev_actionable(edev))
241 edev->pdev->error_state = s;
242 }
243
244 static void eeh_set_irq_state(struct eeh_pe *root, bool enable)
245 {
246 struct eeh_pe *pe;
247 struct eeh_dev *edev, *tmp;
248
249 eeh_for_each_pe(root, pe) {
250 eeh_pe_for_each_dev(pe, edev, tmp) {
251 if (!eeh_edev_actionable(edev))
252 continue;
253
254 if (!eeh_pcid_get(edev->pdev))
255 continue;
256
257 if (enable)
258 eeh_enable_irq(edev);
259 else
260 eeh_disable_irq(edev);
261
262 eeh_pcid_put(edev->pdev);
263 }
264 }
265 }
266
267 typedef enum pci_ers_result (*eeh_report_fn)(struct eeh_dev *,
268 struct pci_dev *,
269 struct pci_driver *);
270 static void eeh_pe_report_edev(struct eeh_dev *edev, eeh_report_fn fn,
271 enum pci_ers_result *result)
272 {
273 struct pci_dev *pdev;
274 struct pci_driver *driver;
275 enum pci_ers_result new_result;
276
277 pci_lock_rescan_remove();
278 pdev = edev->pdev;
279 if (pdev)
280 get_device(&pdev->dev);
281 pci_unlock_rescan_remove();
282 if (!pdev) {
283 eeh_edev_info(edev, "no device");
284 return;
285 }
286 device_lock(&pdev->dev);
287 if (eeh_edev_actionable(edev)) {
288 driver = eeh_pcid_get(pdev);
289
290 if (!driver)
291 eeh_edev_info(edev, "no driver");
292 else if (!driver->err_handler)
293 eeh_edev_info(edev, "driver not EEH aware");
294 else if (edev->mode & EEH_DEV_NO_HANDLER)
295 eeh_edev_info(edev, "driver bound too late");
296 else {
297 new_result = fn(edev, pdev, driver);
298 eeh_edev_info(edev, "%s driver reports: '%s'",
299 driver->name,
300 pci_ers_result_name(new_result));
301 if (result)
302 *result = pci_ers_merge_result(*result,
303 new_result);
304 }
305 if (driver)
306 eeh_pcid_put(pdev);
307 } else {
308 eeh_edev_info(edev, "not actionable (%d,%d,%d)", !!pdev,
309 !eeh_dev_removed(edev), !eeh_pe_passed(edev->pe));
310 }
311 device_unlock(&pdev->dev);
312 if (edev->pdev != pdev)
313 eeh_edev_warn(edev, "Device changed during processing!\n");
314 put_device(&pdev->dev);
315 }
316
317 static void eeh_pe_report(const char *name, struct eeh_pe *root,
318 eeh_report_fn fn, enum pci_ers_result *result)
319 {
320 struct eeh_pe *pe;
321 struct eeh_dev *edev, *tmp;
322
323 pr_info("EEH: Beginning: '%s'\n", name);
324 eeh_for_each_pe(root, pe) eeh_pe_for_each_dev(pe, edev, tmp)
325 eeh_pe_report_edev(edev, fn, result);
326 if (result)
327 pr_info("EEH: Finished:'%s' with aggregate recovery state:'%s'\n",
328 name, pci_ers_result_name(*result));
329 else
330 pr_info("EEH: Finished:'%s'", name);
331 }
332
333
334
335
336
337
338
339
340 static enum pci_ers_result eeh_report_error(struct eeh_dev *edev,
341 struct pci_dev *pdev,
342 struct pci_driver *driver)
343 {
344 enum pci_ers_result rc;
345
346 if (!driver->err_handler->error_detected)
347 return PCI_ERS_RESULT_NONE;
348
349 eeh_edev_info(edev, "Invoking %s->error_detected(IO frozen)",
350 driver->name);
351 rc = driver->err_handler->error_detected(pdev, pci_channel_io_frozen);
352
353 edev->in_error = true;
354 pci_uevent_ers(pdev, PCI_ERS_RESULT_NONE);
355 return rc;
356 }
357
358
359
360
361
362
363
364
365
366 static enum pci_ers_result eeh_report_mmio_enabled(struct eeh_dev *edev,
367 struct pci_dev *pdev,
368 struct pci_driver *driver)
369 {
370 if (!driver->err_handler->mmio_enabled)
371 return PCI_ERS_RESULT_NONE;
372 eeh_edev_info(edev, "Invoking %s->mmio_enabled()", driver->name);
373 return driver->err_handler->mmio_enabled(pdev);
374 }
375
376
377
378
379
380
381
382
383
384
385
386 static enum pci_ers_result eeh_report_reset(struct eeh_dev *edev,
387 struct pci_dev *pdev,
388 struct pci_driver *driver)
389 {
390 if (!driver->err_handler->slot_reset || !edev->in_error)
391 return PCI_ERS_RESULT_NONE;
392 eeh_edev_info(edev, "Invoking %s->slot_reset()", driver->name);
393 return driver->err_handler->slot_reset(pdev);
394 }
395
396 static void eeh_dev_restore_state(struct eeh_dev *edev, void *userdata)
397 {
398 struct pci_dev *pdev;
399
400 if (!edev)
401 return;
402
403
404
405
406
407
408
409 if (edev->pe && (edev->pe->state & EEH_PE_CFG_RESTRICTED)) {
410 if (list_is_last(&edev->entry, &edev->pe->edevs))
411 eeh_pe_restore_bars(edev->pe);
412
413 return;
414 }
415
416 pdev = eeh_dev_to_pci_dev(edev);
417 if (!pdev)
418 return;
419
420 pci_restore_state(pdev);
421 }
422
423
424
425
426
427
428
429
430
431
432 static enum pci_ers_result eeh_report_resume(struct eeh_dev *edev,
433 struct pci_dev *pdev,
434 struct pci_driver *driver)
435 {
436 if (!driver->err_handler->resume || !edev->in_error)
437 return PCI_ERS_RESULT_NONE;
438
439 eeh_edev_info(edev, "Invoking %s->resume()", driver->name);
440 driver->err_handler->resume(pdev);
441
442 pci_uevent_ers(edev->pdev, PCI_ERS_RESULT_RECOVERED);
443 #ifdef CONFIG_PCI_IOV
444 if (eeh_ops->notify_resume && eeh_dev_to_pdn(edev))
445 eeh_ops->notify_resume(eeh_dev_to_pdn(edev));
446 #endif
447 return PCI_ERS_RESULT_NONE;
448 }
449
450
451
452
453
454
455
456
457
458 static enum pci_ers_result eeh_report_failure(struct eeh_dev *edev,
459 struct pci_dev *pdev,
460 struct pci_driver *driver)
461 {
462 enum pci_ers_result rc;
463
464 if (!driver->err_handler->error_detected)
465 return PCI_ERS_RESULT_NONE;
466
467 eeh_edev_info(edev, "Invoking %s->error_detected(permanent failure)",
468 driver->name);
469 rc = driver->err_handler->error_detected(pdev,
470 pci_channel_io_perm_failure);
471
472 pci_uevent_ers(pdev, PCI_ERS_RESULT_DISCONNECT);
473 return rc;
474 }
475
476 static void *eeh_add_virt_device(struct eeh_dev *edev)
477 {
478 struct pci_driver *driver;
479 struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
480
481 if (!(edev->physfn)) {
482 eeh_edev_warn(edev, "Not for VF\n");
483 return NULL;
484 }
485
486 driver = eeh_pcid_get(dev);
487 if (driver) {
488 if (driver->err_handler) {
489 eeh_pcid_put(dev);
490 return NULL;
491 }
492 eeh_pcid_put(dev);
493 }
494
495 #ifdef CONFIG_PCI_IOV
496 pci_iov_add_virtfn(edev->physfn, eeh_dev_to_pdn(edev)->vf_index);
497 #endif
498 return NULL;
499 }
500
501 static void eeh_rmv_device(struct eeh_dev *edev, void *userdata)
502 {
503 struct pci_driver *driver;
504 struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
505 struct eeh_rmv_data *rmv_data = (struct eeh_rmv_data *)userdata;
506
507
508
509
510
511
512
513
514 if (!eeh_edev_actionable(edev) ||
515 (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE))
516 return;
517
518 if (rmv_data) {
519 driver = eeh_pcid_get(dev);
520 if (driver) {
521 if (driver->err_handler &&
522 driver->err_handler->error_detected &&
523 driver->err_handler->slot_reset) {
524 eeh_pcid_put(dev);
525 return;
526 }
527 eeh_pcid_put(dev);
528 }
529 }
530
531
532 pr_info("EEH: Removing %s without EEH sensitive driver\n",
533 pci_name(dev));
534 edev->mode |= EEH_DEV_DISCONNECTED;
535 if (rmv_data)
536 rmv_data->removed_dev_count++;
537
538 if (edev->physfn) {
539 #ifdef CONFIG_PCI_IOV
540 struct pci_dn *pdn = eeh_dev_to_pdn(edev);
541
542 pci_iov_remove_virtfn(edev->physfn, pdn->vf_index);
543 edev->pdev = NULL;
544 #endif
545 if (rmv_data)
546 list_add(&edev->rmv_entry, &rmv_data->removed_vf_list);
547 } else {
548 pci_lock_rescan_remove();
549 pci_stop_and_remove_bus_device(dev);
550 pci_unlock_rescan_remove();
551 }
552 }
553
554 static void *eeh_pe_detach_dev(struct eeh_pe *pe, void *userdata)
555 {
556 struct eeh_dev *edev, *tmp;
557
558 eeh_pe_for_each_dev(pe, edev, tmp) {
559 if (!(edev->mode & EEH_DEV_DISCONNECTED))
560 continue;
561
562 edev->mode &= ~(EEH_DEV_DISCONNECTED | EEH_DEV_IRQ_DISABLED);
563 eeh_rmv_from_parent_pe(edev);
564 }
565
566 return NULL;
567 }
568
569
570
571
572
573
574
575
576 static int eeh_clear_pe_frozen_state(struct eeh_pe *root, bool include_passed)
577 {
578 struct eeh_pe *pe;
579 int i;
580
581 eeh_for_each_pe(root, pe) {
582 if (include_passed || !eeh_pe_passed(pe)) {
583 for (i = 0; i < 3; i++)
584 if (!eeh_unfreeze_pe(pe))
585 break;
586 if (i >= 3)
587 return -EIO;
588 }
589 }
590 eeh_pe_state_clear(root, EEH_PE_ISOLATED, include_passed);
591 return 0;
592 }
593
594 int eeh_pe_reset_and_recover(struct eeh_pe *pe)
595 {
596 int ret;
597
598
599 if (pe->state & EEH_PE_RECOVERING)
600 return 0;
601
602
603 eeh_pe_state_mark(pe, EEH_PE_RECOVERING);
604
605
606 eeh_pe_dev_traverse(pe, eeh_dev_save_state, NULL);
607
608
609 ret = eeh_pe_reset_full(pe, true);
610 if (ret) {
611 eeh_pe_state_clear(pe, EEH_PE_RECOVERING, true);
612 return ret;
613 }
614
615
616 ret = eeh_clear_pe_frozen_state(pe, true);
617 if (ret) {
618 eeh_pe_state_clear(pe, EEH_PE_RECOVERING, true);
619 return ret;
620 }
621
622
623 eeh_pe_dev_traverse(pe, eeh_dev_restore_state, NULL);
624
625
626 eeh_pe_state_clear(pe, EEH_PE_RECOVERING, true);
627
628 return 0;
629 }
630
631
632
633
634
635
636
637
638
639
640
641
642 static int eeh_reset_device(struct eeh_pe *pe, struct pci_bus *bus,
643 struct eeh_rmv_data *rmv_data,
644 bool driver_eeh_aware)
645 {
646 time64_t tstamp;
647 int cnt, rc;
648 struct eeh_dev *edev;
649 struct eeh_pe *tmp_pe;
650 bool any_passed = false;
651
652 eeh_for_each_pe(pe, tmp_pe)
653 any_passed |= eeh_pe_passed(tmp_pe);
654
655
656 cnt = pe->freeze_count;
657 tstamp = pe->tstamp;
658
659
660
661
662
663
664
665 eeh_pe_state_mark(pe, EEH_PE_KEEP);
666 if (any_passed || driver_eeh_aware || (pe->type & EEH_PE_VF)) {
667 eeh_pe_dev_traverse(pe, eeh_rmv_device, rmv_data);
668 } else {
669 pci_lock_rescan_remove();
670 pci_hp_remove_devices(bus);
671 pci_unlock_rescan_remove();
672 }
673
674
675
676
677
678
679
680
681
682
683 rc = eeh_pe_reset_full(pe, false);
684 if (rc)
685 return rc;
686
687 pci_lock_rescan_remove();
688
689
690 eeh_ops->configure_bridge(pe);
691 eeh_pe_restore_bars(pe);
692
693
694 rc = eeh_clear_pe_frozen_state(pe, false);
695 if (rc) {
696 pci_unlock_rescan_remove();
697 return rc;
698 }
699
700
701
702
703
704
705
706 if (!driver_eeh_aware || rmv_data->removed_dev_count) {
707 pr_info("EEH: Sleep 5s ahead of %s hotplug\n",
708 (driver_eeh_aware ? "partial" : "complete"));
709 ssleep(5);
710
711
712
713
714
715
716 edev = list_first_entry(&pe->edevs, struct eeh_dev, entry);
717 eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL);
718 if (pe->type & EEH_PE_VF) {
719 eeh_add_virt_device(edev);
720 } else {
721 if (!driver_eeh_aware)
722 eeh_pe_state_clear(pe, EEH_PE_PRI_BUS, true);
723 pci_hp_add_devices(bus);
724 }
725 }
726 eeh_pe_state_clear(pe, EEH_PE_KEEP, true);
727
728 pe->tstamp = tstamp;
729 pe->freeze_count = cnt;
730
731 pci_unlock_rescan_remove();
732 return 0;
733 }
734
735
736
737
738 #define MAX_WAIT_FOR_RECOVERY 300
739
740
741
742
743
744
745
746
747
748 static void eeh_pe_cleanup(struct eeh_pe *pe)
749 {
750 struct eeh_pe *child_pe, *tmp;
751
752 list_for_each_entry_safe(child_pe, tmp, &pe->child_list, child)
753 eeh_pe_cleanup(child_pe);
754
755 if (pe->state & EEH_PE_KEEP)
756 return;
757
758 if (!(pe->state & EEH_PE_INVALID))
759 return;
760
761 if (list_empty(&pe->edevs) && list_empty(&pe->child_list)) {
762 list_del(&pe->child);
763 kfree(pe);
764 }
765 }
766
767
768
769
770
771
772
773
774
775
776
777
778
779 static bool eeh_slot_presence_check(struct pci_dev *pdev)
780 {
781 const struct hotplug_slot_ops *ops;
782 struct pci_slot *slot;
783 u8 state;
784 int rc;
785
786 if (!pdev)
787 return false;
788
789 if (pdev->error_state == pci_channel_io_perm_failure)
790 return false;
791
792 slot = pdev->slot;
793 if (!slot || !slot->hotplug)
794 return true;
795
796 ops = slot->hotplug->ops;
797 if (!ops || !ops->get_adapter_status)
798 return true;
799
800
801 if (ops->set_attention_status)
802 ops->set_attention_status(slot->hotplug, 1);
803
804 rc = ops->get_adapter_status(slot->hotplug, &state);
805 if (rc)
806 return true;
807
808 return !!state;
809 }
810
811 static void eeh_clear_slot_attention(struct pci_dev *pdev)
812 {
813 const struct hotplug_slot_ops *ops;
814 struct pci_slot *slot;
815
816 if (!pdev)
817 return;
818
819 if (pdev->error_state == pci_channel_io_perm_failure)
820 return;
821
822 slot = pdev->slot;
823 if (!slot || !slot->hotplug)
824 return;
825
826 ops = slot->hotplug->ops;
827 if (!ops || !ops->set_attention_status)
828 return;
829
830 ops->set_attention_status(slot->hotplug, 0);
831 }
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854 void eeh_handle_normal_event(struct eeh_pe *pe)
855 {
856 struct pci_bus *bus;
857 struct eeh_dev *edev, *tmp;
858 struct eeh_pe *tmp_pe;
859 int rc = 0;
860 enum pci_ers_result result = PCI_ERS_RESULT_NONE;
861 struct eeh_rmv_data rmv_data =
862 {LIST_HEAD_INIT(rmv_data.removed_vf_list), 0};
863 int devices = 0;
864
865 bus = eeh_pe_bus_get(pe);
866 if (!bus) {
867 pr_err("%s: Cannot find PCI bus for PHB#%x-PE#%x\n",
868 __func__, pe->phb->global_number, pe->addr);
869 return;
870 }
871
872
873
874
875
876
877
878
879
880
881 eeh_for_each_pe(pe, tmp_pe)
882 eeh_pe_for_each_dev(tmp_pe, edev, tmp)
883 if (eeh_slot_presence_check(edev->pdev))
884 devices++;
885
886 if (!devices) {
887 pr_debug("EEH: Frozen PHB#%x-PE#%x is empty!\n",
888 pe->phb->global_number, pe->addr);
889 goto out;
890 }
891
892
893 if (pe->type & EEH_PE_PHB) {
894 pr_err("EEH: Recovering PHB#%x, location: %s\n",
895 pe->phb->global_number, eeh_pe_loc_get(pe));
896 } else {
897 struct eeh_pe *phb_pe = eeh_phb_pe_get(pe->phb);
898
899 pr_err("EEH: Recovering PHB#%x-PE#%x\n",
900 pe->phb->global_number, pe->addr);
901 pr_err("EEH: PE location: %s, PHB location: %s\n",
902 eeh_pe_loc_get(pe), eeh_pe_loc_get(phb_pe));
903 }
904
905 #ifdef CONFIG_STACKTRACE
906
907
908
909
910 if (pe->trace_entries) {
911 void **ptrs = (void **) pe->stack_trace;
912 int i;
913
914 pr_err("EEH: Frozen PHB#%x-PE#%x detected\n",
915 pe->phb->global_number, pe->addr);
916
917
918 pr_err("EEH: Call Trace:\n");
919 for (i = 0; i < pe->trace_entries; i++)
920 pr_err("EEH: [%pK] %pS\n", ptrs[i], ptrs[i]);
921
922 pe->trace_entries = 0;
923 }
924 #endif
925
926 eeh_pe_update_time_stamp(pe);
927 pe->freeze_count++;
928 if (pe->freeze_count > eeh_max_freezes) {
929 pr_err("EEH: PHB#%x-PE#%x has failed %d times in the last hour and has been permanently disabled.\n",
930 pe->phb->global_number, pe->addr,
931 pe->freeze_count);
932 result = PCI_ERS_RESULT_DISCONNECT;
933 }
934
935 eeh_for_each_pe(pe, tmp_pe)
936 eeh_pe_for_each_dev(tmp_pe, edev, tmp)
937 edev->mode &= ~EEH_DEV_NO_HANDLER;
938
939
940
941
942
943
944
945
946
947
948
949 if (result != PCI_ERS_RESULT_DISCONNECT) {
950 pr_warn("EEH: This PCI device has failed %d times in the last hour and will be permanently disabled after %d failures.\n",
951 pe->freeze_count, eeh_max_freezes);
952 pr_info("EEH: Notify device drivers to shutdown\n");
953 eeh_set_channel_state(pe, pci_channel_io_frozen);
954 eeh_set_irq_state(pe, false);
955 eeh_pe_report("error_detected(IO frozen)", pe,
956 eeh_report_error, &result);
957 if ((pe->type & EEH_PE_PHB) &&
958 result != PCI_ERS_RESULT_NONE &&
959 result != PCI_ERS_RESULT_NEED_RESET)
960 result = PCI_ERS_RESULT_NEED_RESET;
961 }
962
963
964
965
966 if (result != PCI_ERS_RESULT_DISCONNECT) {
967 rc = eeh_wait_state(pe, MAX_WAIT_FOR_RECOVERY*1000);
968 if (rc < 0 || rc == EEH_STATE_NOT_SUPPORT) {
969 pr_warn("EEH: Permanent failure\n");
970 result = PCI_ERS_RESULT_DISCONNECT;
971 }
972 }
973
974
975
976
977
978 if (result != PCI_ERS_RESULT_DISCONNECT) {
979 pr_info("EEH: Collect temporary log\n");
980 eeh_slot_error_detail(pe, EEH_LOG_TEMP);
981 }
982
983
984
985
986
987 if (result == PCI_ERS_RESULT_NONE) {
988 pr_info("EEH: Reset with hotplug activity\n");
989 rc = eeh_reset_device(pe, bus, NULL, false);
990 if (rc) {
991 pr_warn("%s: Unable to reset, err=%d\n",
992 __func__, rc);
993 result = PCI_ERS_RESULT_DISCONNECT;
994 }
995 }
996
997
998 if (result == PCI_ERS_RESULT_CAN_RECOVER) {
999 pr_info("EEH: Enable I/O for affected devices\n");
1000 rc = eeh_pci_enable(pe, EEH_OPT_THAW_MMIO);
1001
1002 if (rc < 0) {
1003 result = PCI_ERS_RESULT_DISCONNECT;
1004 } else if (rc) {
1005 result = PCI_ERS_RESULT_NEED_RESET;
1006 } else {
1007 pr_info("EEH: Notify device drivers to resume I/O\n");
1008 eeh_pe_report("mmio_enabled", pe,
1009 eeh_report_mmio_enabled, &result);
1010 }
1011 }
1012
1013
1014 if (result == PCI_ERS_RESULT_CAN_RECOVER) {
1015 pr_info("EEH: Enabled DMA for affected devices\n");
1016 rc = eeh_pci_enable(pe, EEH_OPT_THAW_DMA);
1017
1018 if (rc < 0) {
1019 result = PCI_ERS_RESULT_DISCONNECT;
1020 } else if (rc) {
1021 result = PCI_ERS_RESULT_NEED_RESET;
1022 } else {
1023
1024
1025
1026
1027
1028 eeh_pe_state_clear(pe, EEH_PE_ISOLATED, true);
1029 result = PCI_ERS_RESULT_RECOVERED;
1030 }
1031 }
1032
1033
1034 if (result == PCI_ERS_RESULT_NEED_RESET) {
1035 pr_info("EEH: Reset without hotplug activity\n");
1036 rc = eeh_reset_device(pe, bus, &rmv_data, true);
1037 if (rc) {
1038 pr_warn("%s: Cannot reset, err=%d\n",
1039 __func__, rc);
1040 result = PCI_ERS_RESULT_DISCONNECT;
1041 } else {
1042 result = PCI_ERS_RESULT_NONE;
1043 eeh_set_channel_state(pe, pci_channel_io_normal);
1044 eeh_set_irq_state(pe, true);
1045 eeh_pe_report("slot_reset", pe, eeh_report_reset,
1046 &result);
1047 }
1048 }
1049
1050 if ((result == PCI_ERS_RESULT_RECOVERED) ||
1051 (result == PCI_ERS_RESULT_NONE)) {
1052
1053
1054
1055
1056 list_for_each_entry_safe(edev, tmp, &rmv_data.removed_vf_list,
1057 rmv_entry) {
1058 eeh_add_virt_device(edev);
1059 list_del(&edev->rmv_entry);
1060 }
1061
1062
1063 pr_info("EEH: Notify device driver to resume\n");
1064 eeh_set_channel_state(pe, pci_channel_io_normal);
1065 eeh_set_irq_state(pe, true);
1066 eeh_pe_report("resume", pe, eeh_report_resume, NULL);
1067 eeh_for_each_pe(pe, tmp_pe) {
1068 eeh_pe_for_each_dev(tmp_pe, edev, tmp) {
1069 edev->mode &= ~EEH_DEV_NO_HANDLER;
1070 edev->in_error = false;
1071 }
1072 }
1073
1074 pr_info("EEH: Recovery successful.\n");
1075 } else {
1076
1077
1078
1079
1080
1081 pr_err("EEH: Unable to recover from failure from PHB#%x-PE#%x.\n"
1082 "Please try reseating or replacing it\n",
1083 pe->phb->global_number, pe->addr);
1084
1085 eeh_slot_error_detail(pe, EEH_LOG_PERM);
1086
1087
1088 eeh_set_channel_state(pe, pci_channel_io_perm_failure);
1089 eeh_set_irq_state(pe, false);
1090 eeh_pe_report("error_detected(permanent failure)", pe,
1091 eeh_report_failure, NULL);
1092
1093
1094 eeh_pe_state_mark(pe, EEH_PE_REMOVED);
1095
1096
1097
1098
1099
1100
1101 if (pe->type & EEH_PE_VF) {
1102 eeh_pe_dev_traverse(pe, eeh_rmv_device, NULL);
1103 eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
1104 } else {
1105 eeh_pe_state_clear(pe, EEH_PE_PRI_BUS, true);
1106 eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
1107
1108 pci_lock_rescan_remove();
1109 pci_hp_remove_devices(bus);
1110 pci_unlock_rescan_remove();
1111
1112 return;
1113 }
1114 }
1115
1116 out:
1117
1118
1119
1120
1121 eeh_pe_cleanup(pe);
1122
1123
1124 eeh_for_each_pe(pe, tmp_pe)
1125 eeh_pe_for_each_dev(tmp_pe, edev, tmp)
1126 eeh_clear_slot_attention(edev->pdev);
1127
1128 eeh_pe_state_clear(pe, EEH_PE_RECOVERING, true);
1129 }
1130
1131
1132
1133
1134
1135
1136
1137
1138 void eeh_handle_special_event(void)
1139 {
1140 struct eeh_pe *pe, *phb_pe, *tmp_pe;
1141 struct eeh_dev *edev, *tmp_edev;
1142 struct pci_bus *bus;
1143 struct pci_controller *hose;
1144 unsigned long flags;
1145 int rc;
1146
1147
1148 do {
1149 rc = eeh_ops->next_error(&pe);
1150
1151 switch (rc) {
1152 case EEH_NEXT_ERR_DEAD_IOC:
1153
1154 eeh_serialize_lock(&flags);
1155
1156
1157 eeh_remove_event(NULL, true);
1158
1159 list_for_each_entry(hose, &hose_list, list_node) {
1160 phb_pe = eeh_phb_pe_get(hose);
1161 if (!phb_pe) continue;
1162
1163 eeh_pe_mark_isolated(phb_pe);
1164 }
1165
1166 eeh_serialize_unlock(flags);
1167
1168 break;
1169 case EEH_NEXT_ERR_FROZEN_PE:
1170 case EEH_NEXT_ERR_FENCED_PHB:
1171 case EEH_NEXT_ERR_DEAD_PHB:
1172
1173 eeh_serialize_lock(&flags);
1174
1175
1176 eeh_remove_event(pe, true);
1177
1178 if (rc != EEH_NEXT_ERR_DEAD_PHB)
1179 eeh_pe_state_mark(pe, EEH_PE_RECOVERING);
1180 eeh_pe_mark_isolated(pe);
1181
1182 eeh_serialize_unlock(flags);
1183
1184 break;
1185 case EEH_NEXT_ERR_NONE:
1186 return;
1187 default:
1188 pr_warn("%s: Invalid value %d from next_error()\n",
1189 __func__, rc);
1190 return;
1191 }
1192
1193
1194
1195
1196
1197
1198 if (rc == EEH_NEXT_ERR_FROZEN_PE ||
1199 rc == EEH_NEXT_ERR_FENCED_PHB) {
1200 eeh_pe_state_mark(pe, EEH_PE_RECOVERING);
1201 eeh_handle_normal_event(pe);
1202 } else {
1203 eeh_for_each_pe(pe, tmp_pe)
1204 eeh_pe_for_each_dev(tmp_pe, edev, tmp_edev)
1205 edev->mode &= ~EEH_DEV_NO_HANDLER;
1206
1207
1208 eeh_pe_state_clear(pe, EEH_PE_PRI_BUS, true);
1209 eeh_set_channel_state(pe, pci_channel_io_perm_failure);
1210 eeh_pe_report(
1211 "error_detected(permanent failure)", pe,
1212 eeh_report_failure, NULL);
1213
1214 pci_lock_rescan_remove();
1215 list_for_each_entry(hose, &hose_list, list_node) {
1216 phb_pe = eeh_phb_pe_get(hose);
1217 if (!phb_pe ||
1218 !(phb_pe->state & EEH_PE_ISOLATED) ||
1219 (phb_pe->state & EEH_PE_RECOVERING))
1220 continue;
1221
1222 bus = eeh_pe_bus_get(phb_pe);
1223 if (!bus) {
1224 pr_err("%s: Cannot find PCI bus for "
1225 "PHB#%x-PE#%x\n",
1226 __func__,
1227 pe->phb->global_number,
1228 pe->addr);
1229 break;
1230 }
1231 pci_hp_remove_devices(bus);
1232 }
1233 pci_unlock_rescan_remove();
1234 }
1235
1236
1237
1238
1239
1240 if (rc == EEH_NEXT_ERR_DEAD_IOC)
1241 break;
1242 } while (rc != EEH_NEXT_ERR_NONE);
1243 }