hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/arch/powerpc/kernel/eeh_driver.c
....@@ -1,24 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * PCI Error Recovery Driver for RPA-compliant PPC64 platform.
34 * Copyright IBM Corp. 2004 2005
45 * Copyright Linas Vepstas <linas@linas.org> 2004, 2005
5
- *
6
- * All rights reserved.
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 (at
11
- * your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful, but
14
- * WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
16
- * NON INFRINGEMENT. See the GNU General Public License for more
17
- * details.
18
- *
19
- * You should have received a copy of the GNU General Public License
20
- * along with this program; if not, write to the Free Software
21
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
226 *
237 * Send comments and feedback to Linas Vepstas <linas@austin.ibm.com>
248 */
....@@ -27,6 +11,7 @@
2711 #include <linux/irq.h>
2812 #include <linux/module.h>
2913 #include <linux/pci.h>
14
+#include <linux/pci_hotplug.h>
3015 #include <asm/eeh.h>
3116 #include <asm/eeh_event.h>
3217 #include <asm/ppc-pci.h>
....@@ -35,8 +20,8 @@
3520 #include <asm/rtas.h>
3621
3722 struct eeh_rmv_data {
38
- struct list_head edev_list;
39
- int removed;
23
+ struct list_head removed_vf_list;
24
+ int removed_dev_count;
4025 };
4126
4227 static int eeh_result_priority(enum pci_ers_result result)
....@@ -60,7 +45,7 @@
6045 }
6146 };
6247
63
-const char *pci_ers_result_name(enum pci_ers_result result)
48
+static const char *pci_ers_result_name(enum pci_ers_result result)
6449 {
6550 switch (result) {
6651 case PCI_ERS_RESULT_NONE:
....@@ -81,23 +66,6 @@
8166 }
8267 };
8368
84
-static __printf(2, 3) void eeh_edev_info(const struct eeh_dev *edev,
85
- const char *fmt, ...)
86
-{
87
- struct va_format vaf;
88
- va_list args;
89
-
90
- va_start(args, fmt);
91
-
92
- vaf.fmt = fmt;
93
- vaf.va = &args;
94
-
95
- printk(KERN_INFO "EEH: PE#%x (PCI %s): %pV\n", edev->pe_config_addr,
96
- edev->pdev ? dev_name(&edev->pdev->dev) : "none", &vaf);
97
-
98
- va_end(args);
99
-}
100
-
10169 static enum pci_ers_result pci_ers_merge_result(enum pci_ers_result old,
10270 enum pci_ers_result new)
10371 {
....@@ -113,8 +81,16 @@
11381
11482 static bool eeh_edev_actionable(struct eeh_dev *edev)
11583 {
116
- return (edev->pdev && !eeh_dev_removed(edev) &&
117
- !eeh_pe_passed(edev->pe));
84
+ if (!edev->pdev)
85
+ return false;
86
+ if (edev->pdev->error_state == pci_channel_io_perm_failure)
87
+ return false;
88
+ if (eeh_dev_removed(edev))
89
+ return false;
90
+ if (eeh_pe_passed(edev->pe))
91
+ return false;
92
+
93
+ return true;
11894 }
11995
12096 /**
....@@ -214,12 +190,12 @@
214190 }
215191 }
216192
217
-static void *eeh_dev_save_state(struct eeh_dev *edev, void *userdata)
193
+static void eeh_dev_save_state(struct eeh_dev *edev, void *userdata)
218194 {
219195 struct pci_dev *pdev;
220196
221197 if (!edev)
222
- return NULL;
198
+ return;
223199
224200 /*
225201 * We cannot access the config space on some adapters.
....@@ -229,17 +205,16 @@
229205 * device is created.
230206 */
231207 if (edev->pe && (edev->pe->state & EEH_PE_CFG_RESTRICTED))
232
- return NULL;
208
+ return;
233209
234210 pdev = eeh_dev_to_pci_dev(edev);
235211 if (!pdev)
236
- return NULL;
212
+ return;
237213
238214 pci_save_state(pdev);
239
- return NULL;
240215 }
241216
242
-static void eeh_set_channel_state(struct eeh_pe *root, enum pci_channel_state s)
217
+static void eeh_set_channel_state(struct eeh_pe *root, pci_channel_state_t s)
243218 {
244219 struct eeh_pe *pe;
245220 struct eeh_dev *edev, *tmp;
....@@ -274,20 +249,27 @@
274249 }
275250
276251 typedef enum pci_ers_result (*eeh_report_fn)(struct eeh_dev *,
252
+ struct pci_dev *,
277253 struct pci_driver *);
278254 static void eeh_pe_report_edev(struct eeh_dev *edev, eeh_report_fn fn,
279255 enum pci_ers_result *result)
280256 {
257
+ struct pci_dev *pdev;
281258 struct pci_driver *driver;
282259 enum pci_ers_result new_result;
283260
284
- if (!edev->pdev) {
261
+ pci_lock_rescan_remove();
262
+ pdev = edev->pdev;
263
+ if (pdev)
264
+ get_device(&pdev->dev);
265
+ pci_unlock_rescan_remove();
266
+ if (!pdev) {
285267 eeh_edev_info(edev, "no device");
286268 return;
287269 }
288
- device_lock(&edev->pdev->dev);
270
+ device_lock(&pdev->dev);
289271 if (eeh_edev_actionable(edev)) {
290
- driver = eeh_pcid_get(edev->pdev);
272
+ driver = eeh_pcid_get(pdev);
291273
292274 if (!driver)
293275 eeh_edev_info(edev, "no driver");
....@@ -296,7 +278,7 @@
296278 else if (edev->mode & EEH_DEV_NO_HANDLER)
297279 eeh_edev_info(edev, "driver bound too late");
298280 else {
299
- new_result = fn(edev, driver);
281
+ new_result = fn(edev, pdev, driver);
300282 eeh_edev_info(edev, "%s driver reports: '%s'",
301283 driver->name,
302284 pci_ers_result_name(new_result));
....@@ -305,12 +287,15 @@
305287 new_result);
306288 }
307289 if (driver)
308
- eeh_pcid_put(edev->pdev);
290
+ eeh_pcid_put(pdev);
309291 } else {
310
- eeh_edev_info(edev, "not actionable (%d,%d,%d)", !!edev->pdev,
292
+ eeh_edev_info(edev, "not actionable (%d,%d,%d)", !!pdev,
311293 !eeh_dev_removed(edev), !eeh_pe_passed(edev->pe));
312294 }
313
- device_unlock(&edev->pdev->dev);
295
+ device_unlock(&pdev->dev);
296
+ if (edev->pdev != pdev)
297
+ eeh_edev_warn(edev, "Device changed during processing!\n");
298
+ put_device(&pdev->dev);
314299 }
315300
316301 static void eeh_pe_report(const char *name, struct eeh_pe *root,
....@@ -337,20 +322,20 @@
337322 * Report an EEH error to each device driver.
338323 */
339324 static enum pci_ers_result eeh_report_error(struct eeh_dev *edev,
325
+ struct pci_dev *pdev,
340326 struct pci_driver *driver)
341327 {
342328 enum pci_ers_result rc;
343
- struct pci_dev *dev = edev->pdev;
344329
345330 if (!driver->err_handler->error_detected)
346331 return PCI_ERS_RESULT_NONE;
347332
348333 eeh_edev_info(edev, "Invoking %s->error_detected(IO frozen)",
349334 driver->name);
350
- rc = driver->err_handler->error_detected(dev, pci_channel_io_frozen);
335
+ rc = driver->err_handler->error_detected(pdev, pci_channel_io_frozen);
351336
352337 edev->in_error = true;
353
- pci_uevent_ers(dev, PCI_ERS_RESULT_NONE);
338
+ pci_uevent_ers(pdev, PCI_ERS_RESULT_NONE);
354339 return rc;
355340 }
356341
....@@ -363,12 +348,13 @@
363348 * are now enabled.
364349 */
365350 static enum pci_ers_result eeh_report_mmio_enabled(struct eeh_dev *edev,
351
+ struct pci_dev *pdev,
366352 struct pci_driver *driver)
367353 {
368354 if (!driver->err_handler->mmio_enabled)
369355 return PCI_ERS_RESULT_NONE;
370356 eeh_edev_info(edev, "Invoking %s->mmio_enabled()", driver->name);
371
- return driver->err_handler->mmio_enabled(edev->pdev);
357
+ return driver->err_handler->mmio_enabled(pdev);
372358 }
373359
374360 /**
....@@ -382,20 +368,21 @@
382368 * driver can work again while the device is recovered.
383369 */
384370 static enum pci_ers_result eeh_report_reset(struct eeh_dev *edev,
371
+ struct pci_dev *pdev,
385372 struct pci_driver *driver)
386373 {
387374 if (!driver->err_handler->slot_reset || !edev->in_error)
388375 return PCI_ERS_RESULT_NONE;
389376 eeh_edev_info(edev, "Invoking %s->slot_reset()", driver->name);
390
- return driver->err_handler->slot_reset(edev->pdev);
377
+ return driver->err_handler->slot_reset(pdev);
391378 }
392379
393
-static void *eeh_dev_restore_state(struct eeh_dev *edev, void *userdata)
380
+static void eeh_dev_restore_state(struct eeh_dev *edev, void *userdata)
394381 {
395382 struct pci_dev *pdev;
396383
397384 if (!edev)
398
- return NULL;
385
+ return;
399386
400387 /*
401388 * The content in the config space isn't saved because
....@@ -404,18 +391,17 @@
404391 * EEH device is created.
405392 */
406393 if (edev->pe && (edev->pe->state & EEH_PE_CFG_RESTRICTED)) {
407
- if (list_is_last(&edev->list, &edev->pe->edevs))
394
+ if (list_is_last(&edev->entry, &edev->pe->edevs))
408395 eeh_pe_restore_bars(edev->pe);
409396
410
- return NULL;
397
+ return;
411398 }
412399
413400 pdev = eeh_dev_to_pci_dev(edev);
414401 if (!pdev)
415
- return NULL;
402
+ return;
416403
417404 pci_restore_state(pdev);
418
- return NULL;
419405 }
420406
421407 /**
....@@ -428,18 +414,19 @@
428414 * to make the recovered device work again.
429415 */
430416 static enum pci_ers_result eeh_report_resume(struct eeh_dev *edev,
417
+ struct pci_dev *pdev,
431418 struct pci_driver *driver)
432419 {
433420 if (!driver->err_handler->resume || !edev->in_error)
434421 return PCI_ERS_RESULT_NONE;
435422
436423 eeh_edev_info(edev, "Invoking %s->resume()", driver->name);
437
- driver->err_handler->resume(edev->pdev);
424
+ driver->err_handler->resume(pdev);
438425
439426 pci_uevent_ers(edev->pdev, PCI_ERS_RESULT_RECOVERED);
440427 #ifdef CONFIG_PCI_IOV
441
- if (eeh_ops->notify_resume && eeh_dev_to_pdn(edev))
442
- eeh_ops->notify_resume(eeh_dev_to_pdn(edev));
428
+ if (eeh_ops->notify_resume)
429
+ eeh_ops->notify_resume(edev);
443430 #endif
444431 return PCI_ERS_RESULT_NONE;
445432 }
....@@ -453,6 +440,7 @@
453440 * dead, and that no further recovery attempts will be made on it.
454441 */
455442 static enum pci_ers_result eeh_report_failure(struct eeh_dev *edev,
443
+ struct pci_dev *pdev,
456444 struct pci_driver *driver)
457445 {
458446 enum pci_ers_result rc;
....@@ -462,24 +450,20 @@
462450
463451 eeh_edev_info(edev, "Invoking %s->error_detected(permanent failure)",
464452 driver->name);
465
- rc = driver->err_handler->error_detected(edev->pdev,
453
+ rc = driver->err_handler->error_detected(pdev,
466454 pci_channel_io_perm_failure);
467455
468
- pci_uevent_ers(edev->pdev, PCI_ERS_RESULT_DISCONNECT);
456
+ pci_uevent_ers(pdev, PCI_ERS_RESULT_DISCONNECT);
469457 return rc;
470458 }
471459
472
-static void *eeh_add_virt_device(void *data, void *userdata)
460
+static void *eeh_add_virt_device(struct eeh_dev *edev)
473461 {
474462 struct pci_driver *driver;
475
- struct eeh_dev *edev = (struct eeh_dev *)data;
476463 struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
477
- struct pci_dn *pdn = eeh_dev_to_pdn(edev);
478464
479465 if (!(edev->physfn)) {
480
- pr_warn("%s: EEH dev %04x:%02x:%02x.%01x not for VF\n",
481
- __func__, pdn->phb->global_number, pdn->busno,
482
- PCI_SLOT(pdn->devfn), PCI_FUNC(pdn->devfn));
466
+ eeh_edev_warn(edev, "Not for VF\n");
483467 return NULL;
484468 }
485469
....@@ -493,17 +477,16 @@
493477 }
494478
495479 #ifdef CONFIG_PCI_IOV
496
- pci_iov_add_virtfn(edev->physfn, pdn->vf_index);
480
+ pci_iov_add_virtfn(edev->physfn, edev->vf_index);
497481 #endif
498482 return NULL;
499483 }
500484
501
-static void *eeh_rmv_device(struct eeh_dev *edev, void *userdata)
485
+static void eeh_rmv_device(struct eeh_dev *edev, void *userdata)
502486 {
503487 struct pci_driver *driver;
504488 struct pci_dev *dev = eeh_dev_to_pci_dev(edev);
505489 struct eeh_rmv_data *rmv_data = (struct eeh_rmv_data *)userdata;
506
- int *removed = rmv_data ? &rmv_data->removed : NULL;
507490
508491 /*
509492 * Actually, we should remove the PCI bridges as well.
....@@ -512,58 +495,42 @@
512495 * support EEH. So we just care about PCI devices for
513496 * simplicity here.
514497 */
515
- if (!dev || (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE))
516
- return NULL;
498
+ if (!eeh_edev_actionable(edev) ||
499
+ (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE))
500
+ return;
517501
518
- /*
519
- * We rely on count-based pcibios_release_device() to
520
- * detach permanently offlined PEs. Unfortunately, that's
521
- * not reliable enough. We might have the permanently
522
- * offlined PEs attached, but we needn't take care of
523
- * them and their child devices.
524
- */
525
- if (eeh_dev_removed(edev))
526
- return NULL;
527
-
528
- if (removed) {
529
- if (eeh_pe_passed(edev->pe))
530
- return NULL;
502
+ if (rmv_data) {
531503 driver = eeh_pcid_get(dev);
532504 if (driver) {
533505 if (driver->err_handler &&
534506 driver->err_handler->error_detected &&
535507 driver->err_handler->slot_reset) {
536508 eeh_pcid_put(dev);
537
- return NULL;
509
+ return;
538510 }
539511 eeh_pcid_put(dev);
540512 }
541513 }
542514
543515 /* Remove it from PCI subsystem */
544
- pr_debug("EEH: Removing %s without EEH sensitive driver\n",
545
- pci_name(dev));
546
- edev->bus = dev->bus;
516
+ pr_info("EEH: Removing %s without EEH sensitive driver\n",
517
+ pci_name(dev));
547518 edev->mode |= EEH_DEV_DISCONNECTED;
548
- if (removed)
549
- (*removed)++;
519
+ if (rmv_data)
520
+ rmv_data->removed_dev_count++;
550521
551522 if (edev->physfn) {
552523 #ifdef CONFIG_PCI_IOV
553
- struct pci_dn *pdn = eeh_dev_to_pdn(edev);
554
-
555
- pci_iov_remove_virtfn(edev->physfn, pdn->vf_index);
524
+ pci_iov_remove_virtfn(edev->physfn, edev->vf_index);
556525 edev->pdev = NULL;
557526 #endif
558527 if (rmv_data)
559
- list_add(&edev->rmv_list, &rmv_data->edev_list);
528
+ list_add(&edev->rmv_entry, &rmv_data->removed_vf_list);
560529 } else {
561530 pci_lock_rescan_remove();
562531 pci_stop_and_remove_bus_device(dev);
563532 pci_unlock_rescan_remove();
564533 }
565
-
566
- return NULL;
567534 }
568535
569536 static void *eeh_pe_detach_dev(struct eeh_pe *pe, void *userdata)
....@@ -575,7 +542,7 @@
575542 continue;
576543
577544 edev->mode &= ~(EEH_DEV_DISCONNECTED | EEH_DEV_IRQ_DISABLED);
578
- eeh_rmv_from_parent_pe(edev);
545
+ eeh_pe_tree_remove(edev);
579546 }
580547
581548 return NULL;
....@@ -588,34 +555,22 @@
588555 * PE reset (for 3 times), we try to clear the frozen state
589556 * for 3 times as well.
590557 */
591
-static void *__eeh_clear_pe_frozen_state(struct eeh_pe *pe, void *flag)
558
+static int eeh_clear_pe_frozen_state(struct eeh_pe *root, bool include_passed)
592559 {
593
- bool clear_sw_state = *(bool *)flag;
594
- int i, rc = 1;
560
+ struct eeh_pe *pe;
561
+ int i;
595562
596
- for (i = 0; rc && i < 3; i++)
597
- rc = eeh_unfreeze_pe(pe, clear_sw_state);
598
-
599
- /* Stop immediately on any errors */
600
- if (rc) {
601
- pr_warn("%s: Failure %d unfreezing PHB#%x-PE#%x\n",
602
- __func__, rc, pe->phb->global_number, pe->addr);
603
- return (void *)pe;
563
+ eeh_for_each_pe(root, pe) {
564
+ if (include_passed || !eeh_pe_passed(pe)) {
565
+ for (i = 0; i < 3; i++)
566
+ if (!eeh_unfreeze_pe(pe))
567
+ break;
568
+ if (i >= 3)
569
+ return -EIO;
570
+ }
604571 }
605
-
606
- return NULL;
607
-}
608
-
609
-static int eeh_clear_pe_frozen_state(struct eeh_pe *pe,
610
- bool clear_sw_state)
611
-{
612
- void *rc;
613
-
614
- rc = eeh_pe_traverse(pe, __eeh_clear_pe_frozen_state, &clear_sw_state);
615
- if (!rc)
616
- eeh_pe_state_clear(pe, EEH_PE_ISOLATED);
617
-
618
- return rc ? -EIO : 0;
572
+ eeh_pe_state_clear(root, EEH_PE_ISOLATED, include_passed);
573
+ return 0;
619574 }
620575
621576 int eeh_pe_reset_and_recover(struct eeh_pe *pe)
....@@ -633,16 +588,16 @@
633588 eeh_pe_dev_traverse(pe, eeh_dev_save_state, NULL);
634589
635590 /* Issue reset */
636
- ret = eeh_pe_reset_full(pe);
591
+ ret = eeh_pe_reset_full(pe, true);
637592 if (ret) {
638
- eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
593
+ eeh_pe_state_clear(pe, EEH_PE_RECOVERING, true);
639594 return ret;
640595 }
641596
642597 /* Unfreeze the PE */
643598 ret = eeh_clear_pe_frozen_state(pe, true);
644599 if (ret) {
645
- eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
600
+ eeh_pe_state_clear(pe, EEH_PE_RECOVERING, true);
646601 return ret;
647602 }
648603
....@@ -650,7 +605,7 @@
650605 eeh_pe_dev_traverse(pe, eeh_dev_restore_state, NULL);
651606
652607 /* Clear recovery mode */
653
- eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
608
+ eeh_pe_state_clear(pe, EEH_PE_RECOVERING, true);
654609
655610 return 0;
656611 }
....@@ -673,6 +628,11 @@
673628 time64_t tstamp;
674629 int cnt, rc;
675630 struct eeh_dev *edev;
631
+ struct eeh_pe *tmp_pe;
632
+ bool any_passed = false;
633
+
634
+ eeh_for_each_pe(pe, tmp_pe)
635
+ any_passed |= eeh_pe_passed(tmp_pe);
676636
677637 /* pcibios will clear the counter; save the value */
678638 cnt = pe->freeze_count;
....@@ -685,7 +645,7 @@
685645 * into pci_hp_add_devices().
686646 */
687647 eeh_pe_state_mark(pe, EEH_PE_KEEP);
688
- if (driver_eeh_aware || (pe->type & EEH_PE_VF)) {
648
+ if (any_passed || driver_eeh_aware || (pe->type & EEH_PE_VF)) {
689649 eeh_pe_dev_traverse(pe, eeh_rmv_device, rmv_data);
690650 } else {
691651 pci_lock_rescan_remove();
....@@ -702,7 +662,7 @@
702662 * config accesses. So we prefer to block them. However, controlled
703663 * PCI config accesses initiated from EEH itself are allowed.
704664 */
705
- rc = eeh_pe_reset_full(pe);
665
+ rc = eeh_pe_reset_full(pe, false);
706666 if (rc)
707667 return rc;
708668
....@@ -725,7 +685,7 @@
725685 * the device up before the scripts have taken it down,
726686 * potentially weird things happen.
727687 */
728
- if (!driver_eeh_aware || rmv_data->removed) {
688
+ if (!driver_eeh_aware || rmv_data->removed_dev_count) {
729689 pr_info("EEH: Sleep 5s ahead of %s hotplug\n",
730690 (driver_eeh_aware ? "partial" : "complete"));
731691 ssleep(5);
....@@ -735,17 +695,17 @@
735695 * PE. We should disconnect it so the binding can be
736696 * rebuilt when adding PCI devices.
737697 */
738
- edev = list_first_entry(&pe->edevs, struct eeh_dev, list);
698
+ edev = list_first_entry(&pe->edevs, struct eeh_dev, entry);
739699 eeh_pe_traverse(pe, eeh_pe_detach_dev, NULL);
740700 if (pe->type & EEH_PE_VF) {
741
- eeh_add_virt_device(edev, NULL);
701
+ eeh_add_virt_device(edev);
742702 } else {
743703 if (!driver_eeh_aware)
744
- eeh_pe_state_clear(pe, EEH_PE_PRI_BUS);
704
+ eeh_pe_state_clear(pe, EEH_PE_PRI_BUS, true);
745705 pci_hp_add_devices(bus);
746706 }
747707 }
748
- eeh_pe_state_clear(pe, EEH_PE_KEEP);
708
+ eeh_pe_state_clear(pe, EEH_PE_KEEP, true);
749709
750710 pe->tstamp = tstamp;
751711 pe->freeze_count = cnt;
....@@ -758,6 +718,99 @@
758718 * to come back on line, in seconds.
759719 */
760720 #define MAX_WAIT_FOR_RECOVERY 300
721
+
722
+
723
+/* Walks the PE tree after processing an event to remove any stale PEs.
724
+ *
725
+ * NB: This needs to be recursive to ensure the leaf PEs get removed
726
+ * before their parents do. Although this is possible to do recursively
727
+ * we don't since this is easier to read and we need to garantee
728
+ * the leaf nodes will be handled first.
729
+ */
730
+static void eeh_pe_cleanup(struct eeh_pe *pe)
731
+{
732
+ struct eeh_pe *child_pe, *tmp;
733
+
734
+ list_for_each_entry_safe(child_pe, tmp, &pe->child_list, child)
735
+ eeh_pe_cleanup(child_pe);
736
+
737
+ if (pe->state & EEH_PE_KEEP)
738
+ return;
739
+
740
+ if (!(pe->state & EEH_PE_INVALID))
741
+ return;
742
+
743
+ if (list_empty(&pe->edevs) && list_empty(&pe->child_list)) {
744
+ list_del(&pe->child);
745
+ kfree(pe);
746
+ }
747
+}
748
+
749
+/**
750
+ * eeh_check_slot_presence - Check if a device is still present in a slot
751
+ * @pdev: pci_dev to check
752
+ *
753
+ * This function may return a false positive if we can't determine the slot's
754
+ * presence state. This might happen for for PCIe slots if the PE containing
755
+ * the upstream bridge is also frozen, or the bridge is part of the same PE
756
+ * as the device.
757
+ *
758
+ * This shouldn't happen often, but you might see it if you hotplug a PCIe
759
+ * switch.
760
+ */
761
+static bool eeh_slot_presence_check(struct pci_dev *pdev)
762
+{
763
+ const struct hotplug_slot_ops *ops;
764
+ struct pci_slot *slot;
765
+ u8 state;
766
+ int rc;
767
+
768
+ if (!pdev)
769
+ return false;
770
+
771
+ if (pdev->error_state == pci_channel_io_perm_failure)
772
+ return false;
773
+
774
+ slot = pdev->slot;
775
+ if (!slot || !slot->hotplug)
776
+ return true;
777
+
778
+ ops = slot->hotplug->ops;
779
+ if (!ops || !ops->get_adapter_status)
780
+ return true;
781
+
782
+ /* set the attention indicator while we've got the slot ops */
783
+ if (ops->set_attention_status)
784
+ ops->set_attention_status(slot->hotplug, 1);
785
+
786
+ rc = ops->get_adapter_status(slot->hotplug, &state);
787
+ if (rc)
788
+ return true;
789
+
790
+ return !!state;
791
+}
792
+
793
+static void eeh_clear_slot_attention(struct pci_dev *pdev)
794
+{
795
+ const struct hotplug_slot_ops *ops;
796
+ struct pci_slot *slot;
797
+
798
+ if (!pdev)
799
+ return;
800
+
801
+ if (pdev->error_state == pci_channel_io_perm_failure)
802
+ return;
803
+
804
+ slot = pdev->slot;
805
+ if (!slot || !slot->hotplug)
806
+ return;
807
+
808
+ ops = slot->hotplug->ops;
809
+ if (!ops || !ops->set_attention_status)
810
+ return;
811
+
812
+ ops->set_attention_status(slot->hotplug, 0);
813
+}
761814
762815 /**
763816 * eeh_handle_normal_event - Handle EEH events on a specific PE
....@@ -787,7 +840,9 @@
787840 struct eeh_pe *tmp_pe;
788841 int rc = 0;
789842 enum pci_ers_result result = PCI_ERS_RESULT_NONE;
790
- struct eeh_rmv_data rmv_data = {LIST_HEAD_INIT(rmv_data.edev_list), 0};
843
+ struct eeh_rmv_data rmv_data =
844
+ {LIST_HEAD_INIT(rmv_data.removed_vf_list), 0};
845
+ int devices = 0;
791846
792847 bus = eeh_pe_bus_get(pe);
793848 if (!bus) {
....@@ -796,7 +851,59 @@
796851 return;
797852 }
798853
799
- eeh_pe_state_mark(pe, EEH_PE_RECOVERING);
854
+ /*
855
+ * When devices are hot-removed we might get an EEH due to
856
+ * a driver attempting to touch the MMIO space of a removed
857
+ * device. In this case we don't have a device to recover
858
+ * so suppress the event if we can't find any present devices.
859
+ *
860
+ * The hotplug driver should take care of tearing down the
861
+ * device itself.
862
+ */
863
+ eeh_for_each_pe(pe, tmp_pe)
864
+ eeh_pe_for_each_dev(tmp_pe, edev, tmp)
865
+ if (eeh_slot_presence_check(edev->pdev))
866
+ devices++;
867
+
868
+ if (!devices) {
869
+ pr_debug("EEH: Frozen PHB#%x-PE#%x is empty!\n",
870
+ pe->phb->global_number, pe->addr);
871
+ goto out; /* nothing to recover */
872
+ }
873
+
874
+ /* Log the event */
875
+ if (pe->type & EEH_PE_PHB) {
876
+ pr_err("EEH: Recovering PHB#%x, location: %s\n",
877
+ pe->phb->global_number, eeh_pe_loc_get(pe));
878
+ } else {
879
+ struct eeh_pe *phb_pe = eeh_phb_pe_get(pe->phb);
880
+
881
+ pr_err("EEH: Recovering PHB#%x-PE#%x\n",
882
+ pe->phb->global_number, pe->addr);
883
+ pr_err("EEH: PE location: %s, PHB location: %s\n",
884
+ eeh_pe_loc_get(pe), eeh_pe_loc_get(phb_pe));
885
+ }
886
+
887
+#ifdef CONFIG_STACKTRACE
888
+ /*
889
+ * Print the saved stack trace now that we've verified there's
890
+ * something to recover.
891
+ */
892
+ if (pe->trace_entries) {
893
+ void **ptrs = (void **) pe->stack_trace;
894
+ int i;
895
+
896
+ pr_err("EEH: Frozen PHB#%x-PE#%x detected\n",
897
+ pe->phb->global_number, pe->addr);
898
+
899
+ /* FIXME: Use the same format as dump_stack() */
900
+ pr_err("EEH: Call Trace:\n");
901
+ for (i = 0; i < pe->trace_entries; i++)
902
+ pr_err("EEH: [%pK] %pS\n", ptrs[i], ptrs[i]);
903
+
904
+ pe->trace_entries = 0;
905
+ }
906
+#endif /* CONFIG_STACKTRACE */
800907
801908 eeh_pe_update_time_stamp(pe);
802909 pe->freeze_count++;
....@@ -804,10 +911,8 @@
804911 pr_err("EEH: PHB#%x-PE#%x has failed %d times in the last hour and has been permanently disabled.\n",
805912 pe->phb->global_number, pe->addr,
806913 pe->freeze_count);
807
- goto hard_fail;
914
+ result = PCI_ERS_RESULT_DISCONNECT;
808915 }
809
- pr_warn("EEH: This PCI device has failed %d times in the last hour and will be permanently disabled after %d failures.\n",
810
- pe->freeze_count, eeh_max_freezes);
811916
812917 eeh_for_each_pe(pe, tmp_pe)
813918 eeh_pe_for_each_dev(tmp_pe, edev, tmp)
....@@ -823,31 +928,39 @@
823928 * the error. Override the result if necessary to have partially
824929 * hotplug for this case.
825930 */
826
- pr_info("EEH: Notify device drivers to shutdown\n");
827
- eeh_set_channel_state(pe, pci_channel_io_frozen);
828
- eeh_set_irq_state(pe, false);
829
- eeh_pe_report("error_detected(IO frozen)", pe, eeh_report_error,
830
- &result);
831
- if ((pe->type & EEH_PE_PHB) &&
832
- result != PCI_ERS_RESULT_NONE &&
833
- result != PCI_ERS_RESULT_NEED_RESET)
834
- result = PCI_ERS_RESULT_NEED_RESET;
931
+ if (result != PCI_ERS_RESULT_DISCONNECT) {
932
+ pr_warn("EEH: This PCI device has failed %d times in the last hour and will be permanently disabled after %d failures.\n",
933
+ pe->freeze_count, eeh_max_freezes);
934
+ pr_info("EEH: Notify device drivers to shutdown\n");
935
+ eeh_set_channel_state(pe, pci_channel_io_frozen);
936
+ eeh_set_irq_state(pe, false);
937
+ eeh_pe_report("error_detected(IO frozen)", pe,
938
+ eeh_report_error, &result);
939
+ if ((pe->type & EEH_PE_PHB) &&
940
+ result != PCI_ERS_RESULT_NONE &&
941
+ result != PCI_ERS_RESULT_NEED_RESET)
942
+ result = PCI_ERS_RESULT_NEED_RESET;
943
+ }
835944
836945 /* Get the current PCI slot state. This can take a long time,
837946 * sometimes over 300 seconds for certain systems.
838947 */
839
- rc = eeh_ops->wait_state(pe, MAX_WAIT_FOR_RECOVERY*1000);
840
- if (rc < 0 || rc == EEH_STATE_NOT_SUPPORT) {
841
- pr_warn("EEH: Permanent failure\n");
842
- goto hard_fail;
948
+ if (result != PCI_ERS_RESULT_DISCONNECT) {
949
+ rc = eeh_wait_state(pe, MAX_WAIT_FOR_RECOVERY*1000);
950
+ if (rc < 0 || rc == EEH_STATE_NOT_SUPPORT) {
951
+ pr_warn("EEH: Permanent failure\n");
952
+ result = PCI_ERS_RESULT_DISCONNECT;
953
+ }
843954 }
844955
845956 /* Since rtas may enable MMIO when posting the error log,
846957 * don't post the error log until after all dev drivers
847958 * have been informed.
848959 */
849
- pr_info("EEH: Collect temporary log\n");
850
- eeh_slot_error_detail(pe, EEH_LOG_TEMP);
960
+ if (result != PCI_ERS_RESULT_DISCONNECT) {
961
+ pr_info("EEH: Collect temporary log\n");
962
+ eeh_slot_error_detail(pe, EEH_LOG_TEMP);
963
+ }
851964
852965 /* If all device drivers were EEH-unaware, then shut
853966 * down all of the device drivers, and hope they
....@@ -859,7 +972,7 @@
859972 if (rc) {
860973 pr_warn("%s: Unable to reset, err=%d\n",
861974 __func__, rc);
862
- goto hard_fail;
975
+ result = PCI_ERS_RESULT_DISCONNECT;
863976 }
864977 }
865978
....@@ -868,9 +981,9 @@
868981 pr_info("EEH: Enable I/O for affected devices\n");
869982 rc = eeh_pci_enable(pe, EEH_OPT_THAW_MMIO);
870983
871
- if (rc < 0)
872
- goto hard_fail;
873
- if (rc) {
984
+ if (rc < 0) {
985
+ result = PCI_ERS_RESULT_DISCONNECT;
986
+ } else if (rc) {
874987 result = PCI_ERS_RESULT_NEED_RESET;
875988 } else {
876989 pr_info("EEH: Notify device drivers to resume I/O\n");
....@@ -884,9 +997,9 @@
884997 pr_info("EEH: Enabled DMA for affected devices\n");
885998 rc = eeh_pci_enable(pe, EEH_OPT_THAW_DMA);
886999
887
- if (rc < 0)
888
- goto hard_fail;
889
- if (rc) {
1000
+ if (rc < 0) {
1001
+ result = PCI_ERS_RESULT_DISCONNECT;
1002
+ } else if (rc) {
8901003 result = PCI_ERS_RESULT_NEED_RESET;
8911004 } else {
8921005 /*
....@@ -894,15 +1007,9 @@
8941007 * is still in frozen state. Clear it before
8951008 * resuming the PE.
8961009 */
897
- eeh_pe_state_clear(pe, EEH_PE_ISOLATED);
1010
+ eeh_pe_state_clear(pe, EEH_PE_ISOLATED, true);
8981011 result = PCI_ERS_RESULT_RECOVERED;
8991012 }
900
- }
901
-
902
- /* If any device has a hard failure, then shut off everything. */
903
- if (result == PCI_ERS_RESULT_DISCONNECT) {
904
- pr_warn("EEH: Device driver gave up\n");
905
- goto hard_fail;
9061013 }
9071014
9081015 /* If any device called out for a reset, then reset the slot */
....@@ -912,65 +1019,60 @@
9121019 if (rc) {
9131020 pr_warn("%s: Cannot reset, err=%d\n",
9141021 __func__, rc);
915
- goto hard_fail;
1022
+ result = PCI_ERS_RESULT_DISCONNECT;
1023
+ } else {
1024
+ result = PCI_ERS_RESULT_NONE;
1025
+ eeh_set_channel_state(pe, pci_channel_io_normal);
1026
+ eeh_set_irq_state(pe, true);
1027
+ eeh_pe_report("slot_reset", pe, eeh_report_reset,
1028
+ &result);
1029
+ }
1030
+ }
1031
+
1032
+ if ((result == PCI_ERS_RESULT_RECOVERED) ||
1033
+ (result == PCI_ERS_RESULT_NONE)) {
1034
+ /*
1035
+ * For those hot removed VFs, we should add back them after PF
1036
+ * get recovered properly.
1037
+ */
1038
+ list_for_each_entry_safe(edev, tmp, &rmv_data.removed_vf_list,
1039
+ rmv_entry) {
1040
+ eeh_add_virt_device(edev);
1041
+ list_del(&edev->rmv_entry);
9161042 }
9171043
918
- pr_info("EEH: Notify device drivers "
919
- "the completion of reset\n");
920
- result = PCI_ERS_RESULT_NONE;
1044
+ /* Tell all device drivers that they can resume operations */
1045
+ pr_info("EEH: Notify device driver to resume\n");
9211046 eeh_set_channel_state(pe, pci_channel_io_normal);
9221047 eeh_set_irq_state(pe, true);
923
- eeh_pe_report("slot_reset", pe, eeh_report_reset, &result);
924
- }
925
-
926
- /* All devices should claim they have recovered by now. */
927
- if ((result != PCI_ERS_RESULT_RECOVERED) &&
928
- (result != PCI_ERS_RESULT_NONE)) {
929
- pr_warn("EEH: Not recovered\n");
930
- goto hard_fail;
931
- }
932
-
933
- /*
934
- * For those hot removed VFs, we should add back them after PF get
935
- * recovered properly.
936
- */
937
- list_for_each_entry_safe(edev, tmp, &rmv_data.edev_list, rmv_list) {
938
- eeh_add_virt_device(edev, NULL);
939
- list_del(&edev->rmv_list);
940
- }
941
-
942
- /* Tell all device drivers that they can resume operations */
943
- pr_info("EEH: Notify device driver to resume\n");
944
- eeh_set_channel_state(pe, pci_channel_io_normal);
945
- eeh_set_irq_state(pe, true);
946
- eeh_pe_report("resume", pe, eeh_report_resume, NULL);
947
- eeh_for_each_pe(pe, tmp_pe) {
948
- eeh_pe_for_each_dev(tmp_pe, edev, tmp) {
949
- edev->mode &= ~EEH_DEV_NO_HANDLER;
950
- edev->in_error = false;
1048
+ eeh_pe_report("resume", pe, eeh_report_resume, NULL);
1049
+ eeh_for_each_pe(pe, tmp_pe) {
1050
+ eeh_pe_for_each_dev(tmp_pe, edev, tmp) {
1051
+ edev->mode &= ~EEH_DEV_NO_HANDLER;
1052
+ edev->in_error = false;
1053
+ }
9511054 }
1055
+
1056
+ pr_info("EEH: Recovery successful.\n");
1057
+ goto out;
9521058 }
9531059
954
- pr_info("EEH: Recovery successful.\n");
955
- goto final;
956
-
957
-hard_fail:
9581060 /*
9591061 * About 90% of all real-life EEH failures in the field
9601062 * are due to poorly seated PCI cards. Only 10% or so are
9611063 * due to actual, failed cards.
9621064 */
9631065 pr_err("EEH: Unable to recover from failure from PHB#%x-PE#%x.\n"
964
- "Please try reseating or replacing it\n",
1066
+ "Please try reseating or replacing it\n",
9651067 pe->phb->global_number, pe->addr);
9661068
9671069 eeh_slot_error_detail(pe, EEH_LOG_PERM);
9681070
9691071 /* Notify all devices that they're about to go down. */
970
- eeh_set_channel_state(pe, pci_channel_io_perm_failure);
9711072 eeh_set_irq_state(pe, false);
9721073 eeh_pe_report("error_detected(permanent failure)", pe,
9731074 eeh_report_failure, NULL);
1075
+ eeh_set_channel_state(pe, pci_channel_io_perm_failure);
9741076
9751077 /* Mark the PE to be removed permanently */
9761078 eeh_pe_state_mark(pe, EEH_PE_REMOVED);
....@@ -984,7 +1086,7 @@
9841086 eeh_pe_dev_traverse(pe, eeh_rmv_device, NULL);
9851087 eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
9861088 } else {
987
- eeh_pe_state_clear(pe, EEH_PE_PRI_BUS);
1089
+ eeh_pe_state_clear(pe, EEH_PE_PRI_BUS, true);
9881090 eeh_pe_dev_mode_mark(pe, EEH_DEV_REMOVED);
9891091
9901092 pci_lock_rescan_remove();
....@@ -993,8 +1095,20 @@
9931095 /* The passed PE should no longer be used */
9941096 return;
9951097 }
996
-final:
997
- eeh_pe_state_clear(pe, EEH_PE_RECOVERING);
1098
+
1099
+out:
1100
+ /*
1101
+ * Clean up any PEs without devices. While marked as EEH_PE_RECOVERYING
1102
+ * we don't want to modify the PE tree structure so we do it here.
1103
+ */
1104
+ eeh_pe_cleanup(pe);
1105
+
1106
+ /* clear the slot attention LED for all recovered devices */
1107
+ eeh_for_each_pe(pe, tmp_pe)
1108
+ eeh_pe_for_each_dev(tmp_pe, edev, tmp)
1109
+ eeh_clear_slot_attention(edev->pdev);
1110
+
1111
+ eeh_pe_state_clear(pe, EEH_PE_RECOVERING, true);
9981112 }
9991113
10001114 /**
....@@ -1029,7 +1143,7 @@
10291143 phb_pe = eeh_phb_pe_get(hose);
10301144 if (!phb_pe) continue;
10311145
1032
- eeh_pe_state_mark(phb_pe, EEH_PE_ISOLATED);
1146
+ eeh_pe_mark_isolated(phb_pe);
10331147 }
10341148
10351149 eeh_serialize_unlock(flags);
....@@ -1044,11 +1158,9 @@
10441158 /* Purge all events of the PHB */
10451159 eeh_remove_event(pe, true);
10461160
1047
- if (rc == EEH_NEXT_ERR_DEAD_PHB)
1048
- eeh_pe_state_mark(pe, EEH_PE_ISOLATED);
1049
- else
1050
- eeh_pe_state_mark(pe,
1051
- EEH_PE_ISOLATED | EEH_PE_RECOVERING);
1161
+ if (rc != EEH_NEXT_ERR_DEAD_PHB)
1162
+ eeh_pe_state_mark(pe, EEH_PE_RECOVERING);
1163
+ eeh_pe_mark_isolated(pe);
10521164
10531165 eeh_serialize_unlock(flags);
10541166
....@@ -1068,8 +1180,20 @@
10681180 */
10691181 if (rc == EEH_NEXT_ERR_FROZEN_PE ||
10701182 rc == EEH_NEXT_ERR_FENCED_PHB) {
1183
+ eeh_pe_state_mark(pe, EEH_PE_RECOVERING);
10711184 eeh_handle_normal_event(pe);
10721185 } else {
1186
+ eeh_for_each_pe(pe, tmp_pe)
1187
+ eeh_pe_for_each_dev(tmp_pe, edev, tmp_edev)
1188
+ edev->mode &= ~EEH_DEV_NO_HANDLER;
1189
+
1190
+ /* Notify all devices to be down */
1191
+ eeh_pe_state_clear(pe, EEH_PE_PRI_BUS, true);
1192
+ eeh_pe_report(
1193
+ "error_detected(permanent failure)", pe,
1194
+ eeh_report_failure, NULL);
1195
+ eeh_set_channel_state(pe, pci_channel_io_perm_failure);
1196
+
10731197 pci_lock_rescan_remove();
10741198 list_for_each_entry(hose, &hose_list, list_node) {
10751199 phb_pe = eeh_phb_pe_get(hose);
....@@ -1078,16 +1202,6 @@
10781202 (phb_pe->state & EEH_PE_RECOVERING))
10791203 continue;
10801204
1081
- eeh_for_each_pe(pe, tmp_pe)
1082
- eeh_pe_for_each_dev(tmp_pe, edev, tmp_edev)
1083
- edev->mode &= ~EEH_DEV_NO_HANDLER;
1084
-
1085
- /* Notify all devices to be down */
1086
- eeh_pe_state_clear(pe, EEH_PE_PRI_BUS);
1087
- eeh_set_channel_state(pe, pci_channel_io_perm_failure);
1088
- eeh_pe_report(
1089
- "error_detected(permanent failure)", pe,
1090
- eeh_report_failure, NULL);
10911205 bus = eeh_pe_bus_get(phb_pe);
10921206 if (!bus) {
10931207 pr_err("%s: Cannot find PCI bus for "