···244extern long mol_trampoline;245EXPORT_SYMBOL(mol_trampoline); /* For MOL */246EXPORT_SYMBOL(flush_hash_pages); /* For MOL */247-EXPORT_SYMBOL_GPL(__handle_mm_fault); /* For MOL */248#ifdef CONFIG_SMP249extern int mmu_hash_lock;250EXPORT_SYMBOL(mmu_hash_lock); /* For MOL */
···244extern long mol_trampoline;245EXPORT_SYMBOL(mol_trampoline); /* For MOL */246EXPORT_SYMBOL(flush_hash_pages); /* For MOL */0247#ifdef CONFIG_SMP248extern int mmu_hash_lock;249EXPORT_SYMBOL(mmu_hash_lock); /* For MOL */
+1-1
arch/powerpc/kernel/rtas_pci.c
···72 return 0;73}7475-static int rtas_read_config(struct pci_dn *pdn, int where, int size, u32 *val)76{77 int returnval = -1;78 unsigned long buid, addr;
···72 return 0;73}7475+int rtas_read_config(struct pci_dn *pdn, int where, int size, u32 *val)76{77 int returnval = -1;78 unsigned long buid, addr;
-2
arch/powerpc/kernel/setup_32.c
···299 if (ppc_md.init_early)300 ppc_md.init_early();301302-#ifdef CONFIG_SERIAL_8250303 find_legacy_serial_ports();304-#endif305 finish_device_tree();306307 smp_setup_cpu_maps();
···299 if (ppc_md.init_early)300 ppc_md.init_early();3010302 find_legacy_serial_ports();0303 finish_device_tree();304305 smp_setup_cpu_maps();
-2
arch/powerpc/kernel/setup_64.c
···472 * hash table management for us, thus ioremap works. We do that early473 * so that further code can be debugged474 */475-#ifdef CONFIG_SERIAL_8250476 find_legacy_serial_ports();477-#endif478479 /*480 * "Finish" the device-tree, that is do the actual parsing of
···472 * hash table management for us, thus ioremap works. We do that early473 * so that further code can be debugged474 */0475 find_legacy_serial_ports();0476477 /*478 * "Finish" the device-tree, that is do the actual parsing of
-24
arch/powerpc/kernel/sys_ppc32.c
···552 return ret;553}554555-asmlinkage int compat_sys_pciconfig_read(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)556-{557- return sys_pciconfig_read((unsigned long) bus,558- (unsigned long) dfn,559- (unsigned long) off,560- (unsigned long) len,561- compat_ptr(ubuf));562-}563-564-asmlinkage int compat_sys_pciconfig_write(u32 bus, u32 dfn, u32 off, u32 len, u32 ubuf)565-{566- return sys_pciconfig_write((unsigned long) bus,567- (unsigned long) dfn,568- (unsigned long) off,569- (unsigned long) len,570- compat_ptr(ubuf));571-}572-573-asmlinkage int compat_sys_pciconfig_iobase(u32 which, u32 in_bus, u32 in_devfn)574-{575- return sys_pciconfig_iobase(which, in_bus, in_devfn);576-}577-578-579/* Note: it is necessary to treat mode as an unsigned int,580 * with the corresponding cast to a signed int to insure that the 581 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
···552 return ret;553}554000000000000000000000000555/* Note: it is necessary to treat mode as an unsigned int,556 * with the corresponding cast to a signed int to insure that the 557 * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
···76 */77#define EEH_MAX_FAILS 1000007879-/* Misc forward declaraions */80-static void eeh_save_bars(struct pci_dev * pdev, struct pci_dn *pdn);81-82/* RTAS tokens */83static int ibm_set_eeh_option;84static int ibm_set_slot_reset;85static int ibm_read_slot_reset_state;86static int ibm_read_slot_reset_state2;87static int ibm_slot_error_detail;008889int eeh_subsystem_enabled;90EXPORT_SYMBOL(eeh_subsystem_enabled);···97static int eeh_error_buf_size;9899/* System monitoring statistics */100-static DEFINE_PER_CPU(unsigned long, no_device);101-static DEFINE_PER_CPU(unsigned long, no_dn);102-static DEFINE_PER_CPU(unsigned long, no_cfg_addr);103-static DEFINE_PER_CPU(unsigned long, ignored_check);104-static DEFINE_PER_CPU(unsigned long, total_mmio_ffs);105-static DEFINE_PER_CPU(unsigned long, false_positives);106-static DEFINE_PER_CPU(unsigned long, ignored_failures);107-static DEFINE_PER_CPU(unsigned long, slot_resets);108109-/**110- * The pci address cache subsystem. This subsystem places111- * PCI device address resources into a red-black tree, sorted112- * according to the address range, so that given only an i/o113- * address, the corresponding PCI device can be **quickly**114- * found. It is safe to perform an address lookup in an interrupt115- * context; this ability is an important feature.116- *117- * Currently, the only customer of this code is the EEH subsystem;118- * thus, this code has been somewhat tailored to suit EEH better.119- * In particular, the cache does *not* hold the addresses of devices120- * for which EEH is not enabled.121- *122- * (Implementation Note: The RB tree seems to be better/faster123- * than any hash algo I could think of for this problem, even124- * with the penalty of slow pointer chases for d-cache misses).125- */126-struct pci_io_addr_range127-{128- struct rb_node rb_node;129- unsigned long addr_lo;130- unsigned long addr_hi;131- struct pci_dev *pcidev;132- unsigned int flags;133-};134-135-static struct pci_io_addr_cache136-{137- struct rb_root rb_root;138- spinlock_t piar_lock;139-} pci_io_addr_cache_root;140-141-static inline struct pci_dev *__pci_get_device_by_addr(unsigned long addr)142-{143- struct rb_node *n = pci_io_addr_cache_root.rb_root.rb_node;144-145- while (n) {146- struct pci_io_addr_range *piar;147- piar = rb_entry(n, struct pci_io_addr_range, rb_node);148-149- if (addr < piar->addr_lo) {150- n = n->rb_left;151- } else {152- if (addr > piar->addr_hi) {153- n = n->rb_right;154- } else {155- pci_dev_get(piar->pcidev);156- return piar->pcidev;157- }158- }159- }160-161- return NULL;162-}163-164-/**165- * pci_get_device_by_addr - Get device, given only address166- * @addr: mmio (PIO) phys address or i/o port number167- *168- * Given an mmio phys address, or a port number, find a pci device169- * that implements this address. Be sure to pci_dev_put the device170- * when finished. I/O port numbers are assumed to be offset171- * from zero (that is, they do *not* have pci_io_addr added in).172- * It is safe to call this function within an interrupt.173- */174-static struct pci_dev *pci_get_device_by_addr(unsigned long addr)175-{176- struct pci_dev *dev;177- unsigned long flags;178-179- spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);180- dev = __pci_get_device_by_addr(addr);181- spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);182- return dev;183-}184-185-#ifdef DEBUG186-/*187- * Handy-dandy debug print routine, does nothing more188- * than print out the contents of our addr cache.189- */190-static void pci_addr_cache_print(struct pci_io_addr_cache *cache)191-{192- struct rb_node *n;193- int cnt = 0;194-195- n = rb_first(&cache->rb_root);196- while (n) {197- struct pci_io_addr_range *piar;198- piar = rb_entry(n, struct pci_io_addr_range, rb_node);199- printk(KERN_DEBUG "PCI: %s addr range %d [%lx-%lx]: %s\n",200- (piar->flags & IORESOURCE_IO) ? "i/o" : "mem", cnt,201- piar->addr_lo, piar->addr_hi, pci_name(piar->pcidev));202- cnt++;203- n = rb_next(n);204- }205-}206-#endif207-208-/* Insert address range into the rb tree. */209-static struct pci_io_addr_range *210-pci_addr_cache_insert(struct pci_dev *dev, unsigned long alo,211- unsigned long ahi, unsigned int flags)212-{213- struct rb_node **p = &pci_io_addr_cache_root.rb_root.rb_node;214- struct rb_node *parent = NULL;215- struct pci_io_addr_range *piar;216-217- /* Walk tree, find a place to insert into tree */218- while (*p) {219- parent = *p;220- piar = rb_entry(parent, struct pci_io_addr_range, rb_node);221- if (ahi < piar->addr_lo) {222- p = &parent->rb_left;223- } else if (alo > piar->addr_hi) {224- p = &parent->rb_right;225- } else {226- if (dev != piar->pcidev ||227- alo != piar->addr_lo || ahi != piar->addr_hi) {228- printk(KERN_WARNING "PIAR: overlapping address range\n");229- }230- return piar;231- }232- }233- piar = (struct pci_io_addr_range *)kmalloc(sizeof(struct pci_io_addr_range), GFP_ATOMIC);234- if (!piar)235- return NULL;236-237- piar->addr_lo = alo;238- piar->addr_hi = ahi;239- piar->pcidev = dev;240- piar->flags = flags;241-242-#ifdef DEBUG243- printk(KERN_DEBUG "PIAR: insert range=[%lx:%lx] dev=%s\n",244- alo, ahi, pci_name (dev));245-#endif246-247- rb_link_node(&piar->rb_node, parent, p);248- rb_insert_color(&piar->rb_node, &pci_io_addr_cache_root.rb_root);249-250- return piar;251-}252-253-static void __pci_addr_cache_insert_device(struct pci_dev *dev)254-{255- struct device_node *dn;256- struct pci_dn *pdn;257- int i;258- int inserted = 0;259-260- dn = pci_device_to_OF_node(dev);261- if (!dn) {262- printk(KERN_WARNING "PCI: no pci dn found for dev=%s\n", pci_name(dev));263- return;264- }265-266- /* Skip any devices for which EEH is not enabled. */267- pdn = PCI_DN(dn);268- if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||269- pdn->eeh_mode & EEH_MODE_NOCHECK) {270-#ifdef DEBUG271- printk(KERN_INFO "PCI: skip building address cache for=%s - %s\n",272- pci_name(dev), pdn->node->full_name);273-#endif274- return;275- }276-277- /* The cache holds a reference to the device... */278- pci_dev_get(dev);279-280- /* Walk resources on this device, poke them into the tree */281- for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {282- unsigned long start = pci_resource_start(dev,i);283- unsigned long end = pci_resource_end(dev,i);284- unsigned int flags = pci_resource_flags(dev,i);285-286- /* We are interested only bus addresses, not dma or other stuff */287- if (0 == (flags & (IORESOURCE_IO | IORESOURCE_MEM)))288- continue;289- if (start == 0 || ~start == 0 || end == 0 || ~end == 0)290- continue;291- pci_addr_cache_insert(dev, start, end, flags);292- inserted = 1;293- }294-295- /* If there was nothing to add, the cache has no reference... */296- if (!inserted)297- pci_dev_put(dev);298-}299-300-/**301- * pci_addr_cache_insert_device - Add a device to the address cache302- * @dev: PCI device whose I/O addresses we are interested in.303- *304- * In order to support the fast lookup of devices based on addresses,305- * we maintain a cache of devices that can be quickly searched.306- * This routine adds a device to that cache.307- */308-static void pci_addr_cache_insert_device(struct pci_dev *dev)309-{310- unsigned long flags;311-312- spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);313- __pci_addr_cache_insert_device(dev);314- spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);315-}316-317-static inline void __pci_addr_cache_remove_device(struct pci_dev *dev)318-{319- struct rb_node *n;320- int removed = 0;321-322-restart:323- n = rb_first(&pci_io_addr_cache_root.rb_root);324- while (n) {325- struct pci_io_addr_range *piar;326- piar = rb_entry(n, struct pci_io_addr_range, rb_node);327-328- if (piar->pcidev == dev) {329- rb_erase(n, &pci_io_addr_cache_root.rb_root);330- removed = 1;331- kfree(piar);332- goto restart;333- }334- n = rb_next(n);335- }336-337- /* The cache no longer holds its reference to this device... */338- if (removed)339- pci_dev_put(dev);340-}341-342-/**343- * pci_addr_cache_remove_device - remove pci device from addr cache344- * @dev: device to remove345- *346- * Remove a device from the addr-cache tree.347- * This is potentially expensive, since it will walk348- * the tree multiple times (once per resource).349- * But so what; device removal doesn't need to be that fast.350- */351-static void pci_addr_cache_remove_device(struct pci_dev *dev)352-{353- unsigned long flags;354-355- spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);356- __pci_addr_cache_remove_device(dev);357- spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);358-}359-360-/**361- * pci_addr_cache_build - Build a cache of I/O addresses362- *363- * Build a cache of pci i/o addresses. This cache will be used to364- * find the pci device that corresponds to a given address.365- * This routine scans all pci busses to build the cache.366- * Must be run late in boot process, after the pci controllers367- * have been scaned for devices (after all device resources are known).368- */369-void __init pci_addr_cache_build(void)370-{371- struct device_node *dn;372- struct pci_dev *dev = NULL;373-374- if (!eeh_subsystem_enabled)375- return;376-377- spin_lock_init(&pci_io_addr_cache_root.piar_lock);378-379- while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {380- /* Ignore PCI bridges ( XXX why ??) */381- if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE) {382- continue;383- }384- pci_addr_cache_insert_device(dev);385-386- /* Save the BAR's; firmware doesn't restore these after EEH reset */387- dn = pci_device_to_OF_node(dev);388- eeh_save_bars(dev, PCI_DN(dn));389- }390-391-#ifdef DEBUG392- /* Verify tree built up above, echo back the list of addrs. */393- pci_addr_cache_print(&pci_io_addr_cache_root);394-#endif395-}396397/* --------------------------------------------------------------- */398-/* Above lies the PCI Address Cache. Below lies the EEH event infrastructure */399400void eeh_slot_error_detail (struct pci_dn *pdn, int severity)401{0402 unsigned long flags;403 int rc;404···121 spin_lock_irqsave(&slot_errbuf_lock, flags);122 memset(slot_errbuf, 0, eeh_error_buf_size);12300000124 rc = rtas_call(ibm_slot_error_detail,125- 8, 1, NULL, pdn->eeh_config_addr,126 BUID_HI(pdn->phb->buid),127 BUID_LO(pdn->phb->buid), NULL, 0,128 virt_to_phys(slot_errbuf),···147static int read_slot_reset_state(struct pci_dn *pdn, int rets[])148{149 int token, outputs;0150151 if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {152 token = ibm_read_slot_reset_state2;···158 outputs = 3;159 }160161- return rtas_call(token, 3, outputs, rets, pdn->eeh_config_addr,00000162 BUID_HI(pdn->phb->buid), BUID_LO(pdn->phb->buid));163}164···187/** 188 * Return the "partitionable endpoint" (pe) under which this device lies189 */190-static struct device_node * find_device_pe(struct device_node *dn)191{192 while ((dn->parent) && PCI_DN(dn->parent) &&193 (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) {···210 if (PCI_DN(dn)) {211 PCI_DN(dn)->eeh_mode |= mode_flag;21200000213 if (dn->child)214 __eeh_mark_slot (dn->child, mode_flag);215 }···225void eeh_mark_slot (struct device_node *dn, int mode_flag)226{227 dn = find_device_pe (dn);00000228 PCI_DN(dn)->eeh_mode |= mode_flag;229 __eeh_mark_slot (dn->child, mode_flag);230}···251{252 unsigned long flags;253 spin_lock_irqsave(&confirm_error_lock, flags);0254 dn = find_device_pe (dn);00000255 PCI_DN(dn)->eeh_mode &= ~mode_flag;256 PCI_DN(dn)->eeh_check_count = 0;257 __eeh_clear_slot (dn->child, mode_flag);···285 int rets[3];286 unsigned long flags;287 struct pci_dn *pdn;0288 int rc = 0;289290- __get_cpu_var(total_mmio_ffs)++;291292 if (!eeh_subsystem_enabled)293 return 0;294295 if (!dn) {296- __get_cpu_var(no_dn)++;297 return 0;298 }299 pdn = PCI_DN(dn);···302 /* Access to IO BARs might get this far and still not want checking. */303 if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||304 pdn->eeh_mode & EEH_MODE_NOCHECK) {305- __get_cpu_var(ignored_check)++;306#ifdef DEBUG307 printk ("EEH:ignored check (%x) for %s %s\n", 308 pdn->eeh_mode, pci_name (dev), dn->full_name);···310 return 0;311 }312313- if (!pdn->eeh_config_addr) {314- __get_cpu_var(no_cfg_addr)++;315 return 0;316 }317···353 if (ret != 0) {354 printk(KERN_WARNING "EEH: read_slot_reset_state() failed; rc=%d dn=%s\n",355 ret, dn->full_name);356- __get_cpu_var(false_positives)++;357 rc = 0;358 goto dn_unlock;359 }···362 if (rets[1] != 1) {363 printk(KERN_WARNING "EEH: event on unsupported device, rc=%d dn=%s\n",364 ret, dn->full_name);365- __get_cpu_var(false_positives)++;366 rc = 0;367 goto dn_unlock;368 }369370 /* If not the kind of error we know about, punt. */371 if (rets[0] != 2 && rets[0] != 4 && rets[0] != 5) {372- __get_cpu_var(false_positives)++;373 rc = 0;374 goto dn_unlock;375 }···377 /* Note that config-io to empty slots may fail;378 * we recognize empty because they don't have children. */379 if ((rets[0] == 5) && (dn->child == NULL)) {380- __get_cpu_var(false_positives)++;381 rc = 0;382 goto dn_unlock;383 }384385- __get_cpu_var(slot_resets)++;386387 /* Avoid repeated reports of this failure, including problems388 * with other functions on this device, and functions under···390 eeh_mark_slot (dn, EEH_MODE_ISOLATED);391 spin_unlock_irqrestore(&confirm_error_lock, flags);392393- eeh_send_failure_event (dn, dev, rets[0], rets[2]);394-00000395 /* Most EEH events are due to device driver bugs. Having396 * a stack trace will help the device-driver authors figure397 * out what happened. So print that out. */···432 addr = eeh_token_to_phys((unsigned long __force) token);433 dev = pci_get_device_by_addr(addr);434 if (!dev) {435- __get_cpu_var(no_device)++;436 return val;437 }438···463 if (rc) return rc;464465 if (rets[1] == 0) return -1; /* EEH is not supported */466- if (rets[0] == 0) return 0; /* Oll Korrect */467 if (rets[0] == 5) {468 if (rets[2] == 0) return -1; /* permanently unavailable */469 return rets[2]; /* number of millisecs to wait */470 }00000471 return -1;472}473···489static void490rtas_pci_slot_reset(struct pci_dn *pdn, int state)491{0492 int rc;493494 BUG_ON (pdn==NULL); ···500 return;501 }50200000503 rc = rtas_call(ibm_set_slot_reset,4,1, NULL,504- pdn->eeh_config_addr,505 BUID_HI(pdn->phb->buid),506 BUID_LO(pdn->phb->buid),507 state);···519520/** rtas_set_slot_reset -- assert the pci #RST line for 1/4 second521 * dn -- device node to be reset.00522 */523524-void525rtas_set_slot_reset(struct pci_dn *pdn)526{527 int i, rc;···553 * ready to be used; if not, wait for recovery. */554 for (i=0; i<10; i++) {555 rc = eeh_slot_availability (pdn);556- if (rc <= 0) break;00000557558 msleep (rc+100);559 }000000560}561562/* ------------------------------------------------------- */···622 if (!pdn) 623 return;624625- if (! pdn->eeh_is_bridge)626 __restore_bars (pdn);627628 dn = pdn->node->child;···640 * PCI devices are added individuallly; but, for the restore,641 * an entire slot is reset at a time.642 */643-static void eeh_save_bars(struct pci_dev * pdev, struct pci_dn *pdn)644{645 int i;646647- if (!pdev || !pdn )648 return;649650 for (i = 0; i < 16; i++)651- pci_read_config_dword(pdev, i * 4, &pdn->config_space[i]);652-653- if (pdev->hdr_type == PCI_HEADER_TYPE_BRIDGE)654- pdn->eeh_is_bridge = 1;655}656657void658rtas_configure_bridge(struct pci_dn *pdn)659{660- int token = rtas_token ("ibm,configure-bridge");661 int rc;662663- if (token == RTAS_UNKNOWN_SERVICE)664- return;665- rc = rtas_call(token,3,1, NULL,666- pdn->eeh_config_addr,000667 BUID_HI(pdn->phb->buid),668 BUID_LO(pdn->phb->buid));669 if (rc) {···698 int enable;699 struct pci_dn *pdn = PCI_DN(dn);7000701 pdn->eeh_mode = 0;702 pdn->eeh_check_count = 0;703 pdn->eeh_freeze_count = 0;···715 pdn->eeh_mode |= EEH_MODE_NOCHECK;716 return NULL;717 }0718719 /*720 * Now decide if we are going to "Disable" EEH checking···726 * But there are a few cases like display devices that make sense.727 */728 enable = 1; /* i.e. we will do checking */0729 if ((*class_code >> 16) == PCI_BASE_CLASS_DISPLAY)730 enable = 0;0731732 if (!enable)733 pdn->eeh_mode |= EEH_MODE_NOCHECK;···748 eeh_subsystem_enabled = 1;749 pdn->eeh_mode |= EEH_MODE_SUPPORTED;750 pdn->eeh_config_addr = regs[0];0000000000000751#ifdef DEBUG752- printk(KERN_DEBUG "EEH: %s: eeh enabled\n", dn->full_name);0753#endif754 } else {755···782 dn->full_name);783 }7840785 return NULL;786}787···816 ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2");817 ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state");818 ibm_slot_error_detail = rtas_token("ibm,slot-error-detail");00819820 if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE)821 return;···872 if (!dn || !PCI_DN(dn))873 return;874 phb = PCI_DN(dn)->phb;875- if (NULL == phb || 0 == phb->buid) {876- printk(KERN_WARNING "EEH: Expected buid but found none for %s\n",877- dn->full_name);878- dump_stack();879 return;880- }881882 info.buid_hi = BUID_HI(phb->buid);883 info.buid_lo = BUID_LO(phb->buid);···917 pdn->pcidev = dev;918919 pci_addr_cache_insert_device (dev);920- eeh_save_bars(dev, pdn);921}922EXPORT_SYMBOL_GPL(eeh_add_device_late);923···964965static int proc_eeh_show(struct seq_file *m, void *v)966{967- unsigned int cpu;968- unsigned long ffs = 0, positives = 0, failures = 0;969- unsigned long resets = 0;970- unsigned long no_dev = 0, no_dn = 0, no_cfg = 0, no_check = 0;971-972- for_each_cpu(cpu) {973- ffs += per_cpu(total_mmio_ffs, cpu);974- positives += per_cpu(false_positives, cpu);975- failures += per_cpu(ignored_failures, cpu);976- resets += per_cpu(slot_resets, cpu);977- no_dev += per_cpu(no_device, cpu);978- no_dn += per_cpu(no_dn, cpu);979- no_cfg += per_cpu(no_cfg_addr, cpu);980- no_check += per_cpu(ignored_check, cpu);981- }982-983 if (0 == eeh_subsystem_enabled) {984 seq_printf(m, "EEH Subsystem is globally disabled\n");985- seq_printf(m, "eeh_total_mmio_ffs=%ld\n", ffs);986 } else {987 seq_printf(m, "EEH Subsystem is enabled\n");988 seq_printf(m,···978 "eeh_false_positives=%ld\n"979 "eeh_ignored_failures=%ld\n"980 "eeh_slot_resets=%ld\n",981- no_dev, no_dn, no_cfg, no_check,982- ffs, positives, failures, resets);00983 }984985 return 0;
···76 */77#define EEH_MAX_FAILS 1000007800079/* RTAS tokens */80static int ibm_set_eeh_option;81static int ibm_set_slot_reset;82static int ibm_read_slot_reset_state;83static int ibm_read_slot_reset_state2;84static int ibm_slot_error_detail;85+static int ibm_get_config_addr_info;86+static int ibm_configure_bridge;8788int eeh_subsystem_enabled;89EXPORT_SYMBOL(eeh_subsystem_enabled);···98static int eeh_error_buf_size;99100/* System monitoring statistics */101+static unsigned long no_device;102+static unsigned long no_dn;103+static unsigned long no_cfg_addr;104+static unsigned long ignored_check;105+static unsigned long total_mmio_ffs;106+static unsigned long false_positives;107+static unsigned long ignored_failures;108+static unsigned long slot_resets;109110+#define IS_BRIDGE(class_code) (((class_code)<<16) == PCI_BASE_CLASS_BRIDGE)0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111112/* --------------------------------------------------------------- */113+/* Below lies the EEH event infrastructure */114115void eeh_slot_error_detail (struct pci_dn *pdn, int severity)116{117+ int config_addr;118 unsigned long flags;119 int rc;120···407 spin_lock_irqsave(&slot_errbuf_lock, flags);408 memset(slot_errbuf, 0, eeh_error_buf_size);409410+ /* Use PE configuration address, if present */411+ config_addr = pdn->eeh_config_addr;412+ if (pdn->eeh_pe_config_addr)413+ config_addr = pdn->eeh_pe_config_addr;414+415 rc = rtas_call(ibm_slot_error_detail,416+ 8, 1, NULL, config_addr,417 BUID_HI(pdn->phb->buid),418 BUID_LO(pdn->phb->buid), NULL, 0,419 virt_to_phys(slot_errbuf),···428static int read_slot_reset_state(struct pci_dn *pdn, int rets[])429{430 int token, outputs;431+ int config_addr;432433 if (ibm_read_slot_reset_state2 != RTAS_UNKNOWN_SERVICE) {434 token = ibm_read_slot_reset_state2;···438 outputs = 3;439 }440441+ /* Use PE configuration address, if present */442+ config_addr = pdn->eeh_config_addr;443+ if (pdn->eeh_pe_config_addr)444+ config_addr = pdn->eeh_pe_config_addr;445+446+ return rtas_call(token, 3, outputs, rets, config_addr,447 BUID_HI(pdn->phb->buid), BUID_LO(pdn->phb->buid));448}449···462/** 463 * Return the "partitionable endpoint" (pe) under which this device lies464 */465+struct device_node * find_device_pe(struct device_node *dn)466{467 while ((dn->parent) && PCI_DN(dn->parent) &&468 (PCI_DN(dn->parent)->eeh_mode & EEH_MODE_SUPPORTED)) {···485 if (PCI_DN(dn)) {486 PCI_DN(dn)->eeh_mode |= mode_flag;487488+ /* Mark the pci device driver too */489+ struct pci_dev *dev = PCI_DN(dn)->pcidev;490+ if (dev && dev->driver)491+ dev->error_state = pci_channel_io_frozen;492+493 if (dn->child)494 __eeh_mark_slot (dn->child, mode_flag);495 }···495void eeh_mark_slot (struct device_node *dn, int mode_flag)496{497 dn = find_device_pe (dn);498+499+ /* Back up one, since config addrs might be shared */500+ if (PCI_DN(dn) && PCI_DN(dn)->eeh_pe_config_addr)501+ dn = dn->parent;502+503 PCI_DN(dn)->eeh_mode |= mode_flag;504 __eeh_mark_slot (dn->child, mode_flag);505}···516{517 unsigned long flags;518 spin_lock_irqsave(&confirm_error_lock, flags);519+520 dn = find_device_pe (dn);521+522+ /* Back up one, since config addrs might be shared */523+ if (PCI_DN(dn) && PCI_DN(dn)->eeh_pe_config_addr)524+ dn = dn->parent;525+526 PCI_DN(dn)->eeh_mode &= ~mode_flag;527 PCI_DN(dn)->eeh_check_count = 0;528 __eeh_clear_slot (dn->child, mode_flag);···544 int rets[3];545 unsigned long flags;546 struct pci_dn *pdn;547+ enum pci_channel_state state;548 int rc = 0;549550+ total_mmio_ffs++;551552 if (!eeh_subsystem_enabled)553 return 0;554555 if (!dn) {556+ no_dn++;557 return 0;558 }559 pdn = PCI_DN(dn);···560 /* Access to IO BARs might get this far and still not want checking. */561 if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||562 pdn->eeh_mode & EEH_MODE_NOCHECK) {563+ ignored_check++;564#ifdef DEBUG565 printk ("EEH:ignored check (%x) for %s %s\n", 566 pdn->eeh_mode, pci_name (dev), dn->full_name);···568 return 0;569 }570571+ if (!pdn->eeh_config_addr && !pdn->eeh_pe_config_addr) {572+ no_cfg_addr++;573 return 0;574 }575···611 if (ret != 0) {612 printk(KERN_WARNING "EEH: read_slot_reset_state() failed; rc=%d dn=%s\n",613 ret, dn->full_name);614+ false_positives++;615 rc = 0;616 goto dn_unlock;617 }···620 if (rets[1] != 1) {621 printk(KERN_WARNING "EEH: event on unsupported device, rc=%d dn=%s\n",622 ret, dn->full_name);623+ false_positives++;624 rc = 0;625 goto dn_unlock;626 }627628 /* If not the kind of error we know about, punt. */629 if (rets[0] != 2 && rets[0] != 4 && rets[0] != 5) {630+ false_positives++;631 rc = 0;632 goto dn_unlock;633 }···635 /* Note that config-io to empty slots may fail;636 * we recognize empty because they don't have children. */637 if ((rets[0] == 5) && (dn->child == NULL)) {638+ false_positives++;639 rc = 0;640 goto dn_unlock;641 }642643+ slot_resets++;644645 /* Avoid repeated reports of this failure, including problems646 * with other functions on this device, and functions under···648 eeh_mark_slot (dn, EEH_MODE_ISOLATED);649 spin_unlock_irqrestore(&confirm_error_lock, flags);650651+ state = pci_channel_io_normal;652+ if ((rets[0] == 2) || (rets[0] == 4))653+ state = pci_channel_io_frozen;654+ if (rets[0] == 5)655+ state = pci_channel_io_perm_failure;656+ eeh_send_failure_event (dn, dev, state, rets[2]);657+658 /* Most EEH events are due to device driver bugs. Having659 * a stack trace will help the device-driver authors figure660 * out what happened. So print that out. */···685 addr = eeh_token_to_phys((unsigned long __force) token);686 dev = pci_get_device_by_addr(addr);687 if (!dev) {688+ no_device++;689 return val;690 }691···716 if (rc) return rc;717718 if (rets[1] == 0) return -1; /* EEH is not supported */719+ if (rets[0] == 0) return 0; /* Oll Korrect */720 if (rets[0] == 5) {721 if (rets[2] == 0) return -1; /* permanently unavailable */722 return rets[2]; /* number of millisecs to wait */723 }724+ if (rets[0] == 1)725+ return 250;726+727+ printk (KERN_ERR "EEH: Slot unavailable: rc=%d, rets=%d %d %d\n",728+ rc, rets[0], rets[1], rets[2]);729 return -1;730}731···737static void738rtas_pci_slot_reset(struct pci_dn *pdn, int state)739{740+ int config_addr;741 int rc;742743 BUG_ON (pdn==NULL); ···747 return;748 }749750+ /* Use PE configuration address, if present */751+ config_addr = pdn->eeh_config_addr;752+ if (pdn->eeh_pe_config_addr)753+ config_addr = pdn->eeh_pe_config_addr;754+755 rc = rtas_call(ibm_set_slot_reset,4,1, NULL,756+ config_addr,757 BUID_HI(pdn->phb->buid),758 BUID_LO(pdn->phb->buid),759 state);···761762/** rtas_set_slot_reset -- assert the pci #RST line for 1/4 second763 * dn -- device node to be reset.764+ *765+ * Return 0 if success, else a non-zero value.766 */767768+int769rtas_set_slot_reset(struct pci_dn *pdn)770{771 int i, rc;···793 * ready to be used; if not, wait for recovery. */794 for (i=0; i<10; i++) {795 rc = eeh_slot_availability (pdn);796+ if (rc < 0)797+ printk (KERN_ERR "EEH: failed (%d) to reset slot %s\n", rc, pdn->node->full_name);798+ if (rc == 0)799+ return 0;800+ if (rc < 0)801+ return -1;802803 msleep (rc+100);804 }805+806+ rc = eeh_slot_availability (pdn);807+ if (rc)808+ printk (KERN_ERR "EEH: timeout resetting slot %s\n", pdn->node->full_name);809+810+ return rc;811}812813/* ------------------------------------------------------- */···851 if (!pdn) 852 return;853854+ if ((pdn->eeh_mode & EEH_MODE_SUPPORTED) && !IS_BRIDGE(pdn->class_code))855 __restore_bars (pdn);856857 dn = pdn->node->child;···869 * PCI devices are added individuallly; but, for the restore,870 * an entire slot is reset at a time.871 */872+static void eeh_save_bars(struct pci_dn *pdn)873{874 int i;875876+ if (!pdn )877 return;878879 for (i = 0; i < 16; i++)880+ rtas_read_config(pdn, i * 4, 4, &pdn->config_space[i]);000881}882883void884rtas_configure_bridge(struct pci_dn *pdn)885{886+ int config_addr;887 int rc;888889+ /* Use PE configuration address, if present */890+ config_addr = pdn->eeh_config_addr;891+ if (pdn->eeh_pe_config_addr)892+ config_addr = pdn->eeh_pe_config_addr;893+894+ rc = rtas_call(ibm_configure_bridge,3,1, NULL,895+ config_addr,896 BUID_HI(pdn->phb->buid),897 BUID_LO(pdn->phb->buid));898 if (rc) {···927 int enable;928 struct pci_dn *pdn = PCI_DN(dn);929930+ pdn->class_code = 0;931 pdn->eeh_mode = 0;932 pdn->eeh_check_count = 0;933 pdn->eeh_freeze_count = 0;···943 pdn->eeh_mode |= EEH_MODE_NOCHECK;944 return NULL;945 }946+ pdn->class_code = *class_code;947948 /*949 * Now decide if we are going to "Disable" EEH checking···953 * But there are a few cases like display devices that make sense.954 */955 enable = 1; /* i.e. we will do checking */956+#if 0957 if ((*class_code >> 16) == PCI_BASE_CLASS_DISPLAY)958 enable = 0;959+#endif960961 if (!enable)962 pdn->eeh_mode |= EEH_MODE_NOCHECK;···973 eeh_subsystem_enabled = 1;974 pdn->eeh_mode |= EEH_MODE_SUPPORTED;975 pdn->eeh_config_addr = regs[0];976+977+ /* If the newer, better, ibm,get-config-addr-info is supported, 978+ * then use that instead. */979+ pdn->eeh_pe_config_addr = 0;980+ if (ibm_get_config_addr_info != RTAS_UNKNOWN_SERVICE) {981+ unsigned int rets[2];982+ ret = rtas_call (ibm_get_config_addr_info, 4, 2, rets, 983+ pdn->eeh_config_addr, 984+ info->buid_hi, info->buid_lo,985+ 0);986+ if (ret == 0)987+ pdn->eeh_pe_config_addr = rets[0];988+ }989#ifdef DEBUG990+ printk(KERN_DEBUG "EEH: %s: eeh enabled, config=%x pe_config=%x\n",991+ dn->full_name, pdn->eeh_config_addr, pdn->eeh_pe_config_addr);992#endif993 } else {994···993 dn->full_name);994 }995996+ eeh_save_bars(pdn);997 return NULL;998}999···1026 ibm_read_slot_reset_state2 = rtas_token("ibm,read-slot-reset-state2");1027 ibm_read_slot_reset_state = rtas_token("ibm,read-slot-reset-state");1028 ibm_slot_error_detail = rtas_token("ibm,slot-error-detail");1029+ ibm_get_config_addr_info = rtas_token("ibm,get-config-addr-info");1030+ ibm_configure_bridge = rtas_token ("ibm,configure-bridge");10311032 if (ibm_set_eeh_option == RTAS_UNKNOWN_SERVICE)1033 return;···1080 if (!dn || !PCI_DN(dn))1081 return;1082 phb = PCI_DN(dn)->phb;1083+1084+ /* USB Bus children of PCI devices will not have BUID's */1085+ if (NULL == phb || 0 == phb->buid)01086 return;010871088 info.buid_hi = BUID_HI(phb->buid);1089 info.buid_lo = BUID_LO(phb->buid);···1127 pdn->pcidev = dev;11281129 pci_addr_cache_insert_device (dev);01130}1131EXPORT_SYMBOL_GPL(eeh_add_device_late);1132···11751176static int proc_eeh_show(struct seq_file *m, void *v)1177{00000000000000001178 if (0 == eeh_subsystem_enabled) {1179 seq_printf(m, "EEH Subsystem is globally disabled\n");1180+ seq_printf(m, "eeh_total_mmio_ffs=%ld\n", total_mmio_ffs);1181 } else {1182 seq_printf(m, "EEH Subsystem is enabled\n");1183 seq_printf(m,···1205 "eeh_false_positives=%ld\n"1206 "eeh_ignored_failures=%ld\n"1207 "eeh_slot_resets=%ld\n",1208+ no_device, no_dn, no_cfg_addr, 1209+ ignored_check, total_mmio_ffs, 1210+ false_positives, ignored_failures, 1211+ slot_resets);1212 }12131214 return 0;
···1+/*2+ * eeh_cache.c3+ * PCI address cache; allows the lookup of PCI devices based on I/O address4+ *5+ * Copyright (C) 2004 Linas Vepstas <linas@austin.ibm.com> IBM Corporation6+ *7+ * This program is free software; you can redistribute it and/or modify8+ * it under the terms of the GNU General Public License as published by9+ * the Free Software Foundation; either version 2 of the License, or10+ * (at your option) any later version.11+ *12+ * This program is distributed in the hope that it will be useful,13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15+ * GNU General Public License for more details.16+ *17+ * You should have received a copy of the GNU General Public License18+ * along with this program; if not, write to the Free Software19+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA20+ */21+22+#include <linux/list.h>23+#include <linux/pci.h>24+#include <linux/rbtree.h>25+#include <linux/spinlock.h>26+#include <asm/atomic.h>27+#include <asm/pci-bridge.h>28+#include <asm/ppc-pci.h>29+30+#undef DEBUG31+32+/**33+ * The pci address cache subsystem. This subsystem places34+ * PCI device address resources into a red-black tree, sorted35+ * according to the address range, so that given only an i/o36+ * address, the corresponding PCI device can be **quickly**37+ * found. It is safe to perform an address lookup in an interrupt38+ * context; this ability is an important feature.39+ *40+ * Currently, the only customer of this code is the EEH subsystem;41+ * thus, this code has been somewhat tailored to suit EEH better.42+ * In particular, the cache does *not* hold the addresses of devices43+ * for which EEH is not enabled.44+ *45+ * (Implementation Note: The RB tree seems to be better/faster46+ * than any hash algo I could think of for this problem, even47+ * with the penalty of slow pointer chases for d-cache misses).48+ */49+struct pci_io_addr_range50+{51+ struct rb_node rb_node;52+ unsigned long addr_lo;53+ unsigned long addr_hi;54+ struct pci_dev *pcidev;55+ unsigned int flags;56+};57+58+static struct pci_io_addr_cache59+{60+ struct rb_root rb_root;61+ spinlock_t piar_lock;62+} pci_io_addr_cache_root;63+64+static inline struct pci_dev *__pci_get_device_by_addr(unsigned long addr)65+{66+ struct rb_node *n = pci_io_addr_cache_root.rb_root.rb_node;67+68+ while (n) {69+ struct pci_io_addr_range *piar;70+ piar = rb_entry(n, struct pci_io_addr_range, rb_node);71+72+ if (addr < piar->addr_lo) {73+ n = n->rb_left;74+ } else {75+ if (addr > piar->addr_hi) {76+ n = n->rb_right;77+ } else {78+ pci_dev_get(piar->pcidev);79+ return piar->pcidev;80+ }81+ }82+ }83+84+ return NULL;85+}86+87+/**88+ * pci_get_device_by_addr - Get device, given only address89+ * @addr: mmio (PIO) phys address or i/o port number90+ *91+ * Given an mmio phys address, or a port number, find a pci device92+ * that implements this address. Be sure to pci_dev_put the device93+ * when finished. I/O port numbers are assumed to be offset94+ * from zero (that is, they do *not* have pci_io_addr added in).95+ * It is safe to call this function within an interrupt.96+ */97+struct pci_dev *pci_get_device_by_addr(unsigned long addr)98+{99+ struct pci_dev *dev;100+ unsigned long flags;101+102+ spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);103+ dev = __pci_get_device_by_addr(addr);104+ spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);105+ return dev;106+}107+108+#ifdef DEBUG109+/*110+ * Handy-dandy debug print routine, does nothing more111+ * than print out the contents of our addr cache.112+ */113+static void pci_addr_cache_print(struct pci_io_addr_cache *cache)114+{115+ struct rb_node *n;116+ int cnt = 0;117+118+ n = rb_first(&cache->rb_root);119+ while (n) {120+ struct pci_io_addr_range *piar;121+ piar = rb_entry(n, struct pci_io_addr_range, rb_node);122+ printk(KERN_DEBUG "PCI: %s addr range %d [%lx-%lx]: %s\n",123+ (piar->flags & IORESOURCE_IO) ? "i/o" : "mem", cnt,124+ piar->addr_lo, piar->addr_hi, pci_name(piar->pcidev));125+ cnt++;126+ n = rb_next(n);127+ }128+}129+#endif130+131+/* Insert address range into the rb tree. */132+static struct pci_io_addr_range *133+pci_addr_cache_insert(struct pci_dev *dev, unsigned long alo,134+ unsigned long ahi, unsigned int flags)135+{136+ struct rb_node **p = &pci_io_addr_cache_root.rb_root.rb_node;137+ struct rb_node *parent = NULL;138+ struct pci_io_addr_range *piar;139+140+ /* Walk tree, find a place to insert into tree */141+ while (*p) {142+ parent = *p;143+ piar = rb_entry(parent, struct pci_io_addr_range, rb_node);144+ if (ahi < piar->addr_lo) {145+ p = &parent->rb_left;146+ } else if (alo > piar->addr_hi) {147+ p = &parent->rb_right;148+ } else {149+ if (dev != piar->pcidev ||150+ alo != piar->addr_lo || ahi != piar->addr_hi) {151+ printk(KERN_WARNING "PIAR: overlapping address range\n");152+ }153+ return piar;154+ }155+ }156+ piar = (struct pci_io_addr_range *)kmalloc(sizeof(struct pci_io_addr_range), GFP_ATOMIC);157+ if (!piar)158+ return NULL;159+160+ piar->addr_lo = alo;161+ piar->addr_hi = ahi;162+ piar->pcidev = dev;163+ piar->flags = flags;164+165+#ifdef DEBUG166+ printk(KERN_DEBUG "PIAR: insert range=[%lx:%lx] dev=%s\n",167+ alo, ahi, pci_name (dev));168+#endif169+170+ rb_link_node(&piar->rb_node, parent, p);171+ rb_insert_color(&piar->rb_node, &pci_io_addr_cache_root.rb_root);172+173+ return piar;174+}175+176+static void __pci_addr_cache_insert_device(struct pci_dev *dev)177+{178+ struct device_node *dn;179+ struct pci_dn *pdn;180+ int i;181+ int inserted = 0;182+183+ dn = pci_device_to_OF_node(dev);184+ if (!dn) {185+ printk(KERN_WARNING "PCI: no pci dn found for dev=%s\n", pci_name(dev));186+ return;187+ }188+189+ /* Skip any devices for which EEH is not enabled. */190+ pdn = PCI_DN(dn);191+ if (!(pdn->eeh_mode & EEH_MODE_SUPPORTED) ||192+ pdn->eeh_mode & EEH_MODE_NOCHECK) {193+#ifdef DEBUG194+ printk(KERN_INFO "PCI: skip building address cache for=%s - %s\n",195+ pci_name(dev), pdn->node->full_name);196+#endif197+ return;198+ }199+200+ /* The cache holds a reference to the device... */201+ pci_dev_get(dev);202+203+ /* Walk resources on this device, poke them into the tree */204+ for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {205+ unsigned long start = pci_resource_start(dev,i);206+ unsigned long end = pci_resource_end(dev,i);207+ unsigned int flags = pci_resource_flags(dev,i);208+209+ /* We are interested only bus addresses, not dma or other stuff */210+ if (0 == (flags & (IORESOURCE_IO | IORESOURCE_MEM)))211+ continue;212+ if (start == 0 || ~start == 0 || end == 0 || ~end == 0)213+ continue;214+ pci_addr_cache_insert(dev, start, end, flags);215+ inserted = 1;216+ }217+218+ /* If there was nothing to add, the cache has no reference... */219+ if (!inserted)220+ pci_dev_put(dev);221+}222+223+/**224+ * pci_addr_cache_insert_device - Add a device to the address cache225+ * @dev: PCI device whose I/O addresses we are interested in.226+ *227+ * In order to support the fast lookup of devices based on addresses,228+ * we maintain a cache of devices that can be quickly searched.229+ * This routine adds a device to that cache.230+ */231+void pci_addr_cache_insert_device(struct pci_dev *dev)232+{233+ unsigned long flags;234+235+ spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);236+ __pci_addr_cache_insert_device(dev);237+ spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);238+}239+240+static inline void __pci_addr_cache_remove_device(struct pci_dev *dev)241+{242+ struct rb_node *n;243+ int removed = 0;244+245+restart:246+ n = rb_first(&pci_io_addr_cache_root.rb_root);247+ while (n) {248+ struct pci_io_addr_range *piar;249+ piar = rb_entry(n, struct pci_io_addr_range, rb_node);250+251+ if (piar->pcidev == dev) {252+ rb_erase(n, &pci_io_addr_cache_root.rb_root);253+ removed = 1;254+ kfree(piar);255+ goto restart;256+ }257+ n = rb_next(n);258+ }259+260+ /* The cache no longer holds its reference to this device... */261+ if (removed)262+ pci_dev_put(dev);263+}264+265+/**266+ * pci_addr_cache_remove_device - remove pci device from addr cache267+ * @dev: device to remove268+ *269+ * Remove a device from the addr-cache tree.270+ * This is potentially expensive, since it will walk271+ * the tree multiple times (once per resource).272+ * But so what; device removal doesn't need to be that fast.273+ */274+void pci_addr_cache_remove_device(struct pci_dev *dev)275+{276+ unsigned long flags;277+278+ spin_lock_irqsave(&pci_io_addr_cache_root.piar_lock, flags);279+ __pci_addr_cache_remove_device(dev);280+ spin_unlock_irqrestore(&pci_io_addr_cache_root.piar_lock, flags);281+}282+283+/**284+ * pci_addr_cache_build - Build a cache of I/O addresses285+ *286+ * Build a cache of pci i/o addresses. This cache will be used to287+ * find the pci device that corresponds to a given address.288+ * This routine scans all pci busses to build the cache.289+ * Must be run late in boot process, after the pci controllers290+ * have been scaned for devices (after all device resources are known).291+ */292+void __init pci_addr_cache_build(void)293+{294+ struct device_node *dn;295+ struct pci_dev *dev = NULL;296+297+ spin_lock_init(&pci_io_addr_cache_root.piar_lock);298+299+ while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {300+ /* Ignore PCI bridges */301+ if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE)302+ continue;303+304+ pci_addr_cache_insert_device(dev);305+306+ dn = pci_device_to_OF_node(dev);307+ pci_dev_get (dev); /* matching put is in eeh_remove_device() */308+ PCI_DN(dn)->pcidev = dev;309+ }310+311+#ifdef DEBUG312+ /* Verify tree built up above, echo back the list of addrs. */313+ pci_addr_cache_print(&pci_io_addr_cache_root);314+#endif315+}316+
···1+/*2+ * PCI Error Recovery Driver for RPA-compliant PPC64 platform.3+ * Copyright (C) 2004, 2005 Linas Vepstas <linas@linas.org>4+ *5+ * All rights reserved.6+ *7+ * This program is free software; you can redistribute it and/or modify8+ * it under the terms of the GNU General Public License as published by9+ * the Free Software Foundation; either version 2 of the License, or (at10+ * your option) any later version.11+ *12+ * This program is distributed in the hope that it will be useful, but13+ * WITHOUT ANY WARRANTY; without even the implied warranty of14+ * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or15+ * NON INFRINGEMENT. See the GNU General Public License for more16+ * details.17+ *18+ * You should have received a copy of the GNU General Public License19+ * along with this program; if not, write to the Free Software20+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.21+ *22+ * Send feedback to <linas@us.ibm.com>23+ *24+ */25+#include <linux/delay.h>26+#include <linux/irq.h>27+#include <linux/interrupt.h>28+#include <linux/notifier.h>29+#include <linux/pci.h>30+#include <asm/eeh.h>31+#include <asm/eeh_event.h>32+#include <asm/ppc-pci.h>33+#include <asm/pci-bridge.h>34+#include <asm/prom.h>35+#include <asm/rtas.h>36+37+38+static inline const char * pcid_name (struct pci_dev *pdev)39+{40+ if (pdev->dev.driver)41+ return pdev->dev.driver->name;42+ return "";43+}44+45+#ifdef DEBUG46+static void print_device_node_tree (struct pci_dn *pdn, int dent)47+{48+ int i;49+ if (!pdn) return;50+ for (i=0;i<dent; i++)51+ printk(" ");52+ printk("dn=%s mode=%x \tcfg_addr=%x pe_addr=%x \tfull=%s\n",53+ pdn->node->name, pdn->eeh_mode, pdn->eeh_config_addr,54+ pdn->eeh_pe_config_addr, pdn->node->full_name);55+ dent += 3;56+ struct device_node *pc = pdn->node->child;57+ while (pc) {58+ print_device_node_tree(PCI_DN(pc), dent);59+ pc = pc->sibling;60+ }61+}62+#endif63+64+/** 65+ * irq_in_use - return true if this irq is being used 66+ */67+static int irq_in_use(unsigned int irq)68+{69+ int rc = 0;70+ unsigned long flags;71+ struct irq_desc *desc = irq_desc + irq;72+73+ spin_lock_irqsave(&desc->lock, flags);74+ if (desc->action)75+ rc = 1;76+ spin_unlock_irqrestore(&desc->lock, flags);77+ return rc;78+}79+80+/* ------------------------------------------------------- */81+/** eeh_report_error - report an EEH error to each device,82+ * collect up and merge the device responses.83+ */84+85+static void eeh_report_error(struct pci_dev *dev, void *userdata)86+{87+ enum pci_ers_result rc, *res = userdata;88+ struct pci_driver *driver = dev->driver;89+90+ dev->error_state = pci_channel_io_frozen;91+92+ if (!driver)93+ return;94+95+ if (irq_in_use (dev->irq)) {96+ struct device_node *dn = pci_device_to_OF_node(dev);97+ PCI_DN(dn)->eeh_mode |= EEH_MODE_IRQ_DISABLED;98+ disable_irq_nosync(dev->irq);99+ }100+ if (!driver->err_handler)101+ return;102+ if (!driver->err_handler->error_detected)103+ return;104+105+ rc = driver->err_handler->error_detected (dev, pci_channel_io_frozen);106+ if (*res == PCI_ERS_RESULT_NONE) *res = rc;107+ if (*res == PCI_ERS_RESULT_NEED_RESET) return;108+ if (*res == PCI_ERS_RESULT_DISCONNECT &&109+ rc == PCI_ERS_RESULT_NEED_RESET) *res = rc;110+}111+112+/** eeh_report_reset -- tell this device that the pci slot113+ * has been reset.114+ */115+116+static void eeh_report_reset(struct pci_dev *dev, void *userdata)117+{118+ struct pci_driver *driver = dev->driver;119+ struct device_node *dn = pci_device_to_OF_node(dev);120+121+ if (!driver)122+ return;123+124+ if ((PCI_DN(dn)->eeh_mode) & EEH_MODE_IRQ_DISABLED) {125+ PCI_DN(dn)->eeh_mode &= ~EEH_MODE_IRQ_DISABLED;126+ enable_irq(dev->irq);127+ }128+ if (!driver->err_handler)129+ return;130+ if (!driver->err_handler->slot_reset)131+ return;132+133+ driver->err_handler->slot_reset(dev);134+}135+136+static void eeh_report_resume(struct pci_dev *dev, void *userdata)137+{138+ struct pci_driver *driver = dev->driver;139+140+ dev->error_state = pci_channel_io_normal;141+142+ if (!driver)143+ return;144+ if (!driver->err_handler)145+ return;146+ if (!driver->err_handler->resume)147+ return;148+149+ driver->err_handler->resume(dev);150+}151+152+static void eeh_report_failure(struct pci_dev *dev, void *userdata)153+{154+ struct pci_driver *driver = dev->driver;155+156+ dev->error_state = pci_channel_io_perm_failure;157+158+ if (!driver)159+ return;160+161+ if (irq_in_use (dev->irq)) {162+ struct device_node *dn = pci_device_to_OF_node(dev);163+ PCI_DN(dn)->eeh_mode |= EEH_MODE_IRQ_DISABLED;164+ disable_irq_nosync(dev->irq);165+ }166+ if (!driver->err_handler)167+ return;168+ if (!driver->err_handler->error_detected)169+ return;170+ driver->err_handler->error_detected(dev, pci_channel_io_perm_failure);171+}172+173+/* ------------------------------------------------------- */174+/**175+ * handle_eeh_events -- reset a PCI device after hard lockup.176+ *177+ * pSeries systems will isolate a PCI slot if the PCI-Host178+ * bridge detects address or data parity errors, DMA's179+ * occuring to wild addresses (which usually happen due to180+ * bugs in device drivers or in PCI adapter firmware).181+ * Slot isolations also occur if #SERR, #PERR or other misc182+ * PCI-related errors are detected.183+ *184+ * Recovery process consists of unplugging the device driver185+ * (which generated hotplug events to userspace), then issuing186+ * a PCI #RST to the device, then reconfiguring the PCI config187+ * space for all bridges & devices under this slot, and then188+ * finally restarting the device drivers (which cause a second189+ * set of hotplug events to go out to userspace).190+ */191+192+/**193+ * eeh_reset_device() -- perform actual reset of a pci slot194+ * Args: bus: pointer to the pci bus structure corresponding195+ * to the isolated slot. A non-null value will196+ * cause all devices under the bus to be removed197+ * and then re-added.198+ * pe_dn: pointer to a "Partionable Endpoint" device node.199+ * This is the top-level structure on which pci200+ * bus resets can be performed.201+ */202+203+static int eeh_reset_device (struct pci_dn *pe_dn, struct pci_bus *bus)204+{205+ int rc;206+ if (bus)207+ pcibios_remove_pci_devices(bus);208+209+ /* Reset the pci controller. (Asserts RST#; resets config space).210+ * Reconfigure bridges and devices. Don't try to bring the system211+ * up if the reset failed for some reason. */212+ rc = rtas_set_slot_reset(pe_dn);213+ if (rc)214+ return rc;215+216+ /* New-style config addrs might be shared across multiple devices,217+ * Walk over all functions on this device */218+ if (pe_dn->eeh_pe_config_addr) {219+ struct device_node *pe = pe_dn->node;220+ pe = pe->parent->child;221+ while (pe) {222+ struct pci_dn *ppe = PCI_DN(pe);223+ if (pe_dn->eeh_pe_config_addr == ppe->eeh_pe_config_addr) {224+ rtas_configure_bridge(ppe);225+ eeh_restore_bars(ppe);226+ }227+ pe = pe->sibling;228+ }229+ } else {230+ rtas_configure_bridge(pe_dn);231+ eeh_restore_bars(pe_dn);232+ }233+234+ /* Give the system 5 seconds to finish running the user-space235+ * hotplug shutdown scripts, e.g. ifdown for ethernet. Yes, 236+ * this is a hack, but if we don't do this, and try to bring 237+ * the device up before the scripts have taken it down, 238+ * potentially weird things happen.239+ */240+ if (bus) {241+ ssleep (5);242+ pcibios_add_pci_devices(bus);243+ }244+245+ return 0;246+}247+248+/* The longest amount of time to wait for a pci device249+ * to come back on line, in seconds.250+ */251+#define MAX_WAIT_FOR_RECOVERY 15252+253+void handle_eeh_events (struct eeh_event *event)254+{255+ struct device_node *frozen_dn;256+ struct pci_dn *frozen_pdn;257+ struct pci_bus *frozen_bus;258+ int rc = 0;259+ enum pci_ers_result result = PCI_ERS_RESULT_NONE;260+261+ frozen_dn = find_device_pe(event->dn);262+ frozen_bus = pcibios_find_pci_bus(frozen_dn);263+264+ if (!frozen_dn) {265+ printk(KERN_ERR "EEH: Error: Cannot find partition endpoint for %s\n",266+ pci_name(event->dev));267+ return;268+ }269+270+ /* There are two different styles for coming up with the PE.271+ * In the old style, it was the highest EEH-capable device272+ * which was always an EADS pci bridge. In the new style,273+ * there might not be any EADS bridges, and even when there are,274+ * the firmware marks them as "EEH incapable". So another275+ * two-step is needed to find the pci bus.. */276+ if (!frozen_bus)277+ frozen_bus = pcibios_find_pci_bus (frozen_dn->parent);278+279+ if (!frozen_bus) {280+ printk(KERN_ERR "EEH: Cannot find PCI bus for %s\n",281+ frozen_dn->full_name);282+ return;283+ }284+285+#if 0286+ /* We may get "permanent failure" messages on empty slots.287+ * These are false alarms. Empty slots have no child dn. */288+ if ((event->state == pci_channel_io_perm_failure) && (frozen_device == NULL))289+ return;290+#endif291+292+ frozen_pdn = PCI_DN(frozen_dn);293+ frozen_pdn->eeh_freeze_count++;294+295+ if (frozen_pdn->eeh_freeze_count > EEH_MAX_ALLOWED_FREEZES)296+ goto hard_fail;297+298+ /* If the reset state is a '5' and the time to reset is 0 (infinity)299+ * or is more then 15 seconds, then mark this as a permanent failure.300+ */301+ if ((event->state == pci_channel_io_perm_failure) &&302+ ((event->time_unavail <= 0) ||303+ (event->time_unavail > MAX_WAIT_FOR_RECOVERY*1000)))304+ goto hard_fail;305+306+ eeh_slot_error_detail(frozen_pdn, 1 /* Temporary Error */);307+ printk(KERN_WARNING308+ "EEH: This PCI device has failed %d times since last reboot: %s - %s\n",309+ frozen_pdn->eeh_freeze_count,310+ pci_name (frozen_pdn->pcidev), 311+ pcid_name(frozen_pdn->pcidev));312+313+ /* Walk the various device drivers attached to this slot through314+ * a reset sequence, giving each an opportunity to do what it needs315+ * to accomplish the reset. Each child gets a report of the316+ * status ... if any child can't handle the reset, then the entire317+ * slot is dlpar removed and added.318+ */319+ pci_walk_bus(frozen_bus, eeh_report_error, &result);320+321+ /* If all device drivers were EEH-unaware, then shut322+ * down all of the device drivers, and hope they323+ * go down willingly, without panicing the system.324+ */325+ if (result == PCI_ERS_RESULT_NONE) {326+ rc = eeh_reset_device(frozen_pdn, frozen_bus);327+ if (rc)328+ goto hard_fail;329+ }330+331+ /* If any device called out for a reset, then reset the slot */332+ if (result == PCI_ERS_RESULT_NEED_RESET) {333+ rc = eeh_reset_device(frozen_pdn, NULL);334+ if (rc)335+ goto hard_fail;336+ pci_walk_bus(frozen_bus, eeh_report_reset, 0);337+ }338+339+ /* If all devices reported they can proceed, the re-enable PIO */340+ if (result == PCI_ERS_RESULT_CAN_RECOVER) {341+ /* XXX Not supported; we brute-force reset the device */342+ rc = eeh_reset_device(frozen_pdn, NULL);343+ if (rc)344+ goto hard_fail;345+ pci_walk_bus(frozen_bus, eeh_report_reset, 0);346+ }347+348+ /* Tell all device drivers that they can resume operations */349+ pci_walk_bus(frozen_bus, eeh_report_resume, 0);350+351+ return;352+353+hard_fail:354+ /*355+ * About 90% of all real-life EEH failures in the field356+ * are due to poorly seated PCI cards. Only 10% or so are357+ * due to actual, failed cards.358+ */359+ printk(KERN_ERR360+ "EEH: PCI device %s - %s has failed %d times \n"361+ "and has been permanently disabled. Please try reseating\n"362+ "this device or replacing it.\n",363+ pci_name (frozen_pdn->pcidev), 364+ pcid_name(frozen_pdn->pcidev), 365+ frozen_pdn->eeh_freeze_count);366+367+ eeh_slot_error_detail(frozen_pdn, 2 /* Permanent Error */);368+369+ /* Notify all devices that they're about to go down. */370+ pci_walk_bus(frozen_bus, eeh_report_failure, 0);371+372+ /* Shut down the device drivers for good. */373+ pcibios_remove_pci_devices(frozen_bus);374+}375+376+/* ---------- end of file ---------- */
+12-27
arch/powerpc/platforms/pseries/eeh_event.c
···21#include <linux/list.h>22#include <linux/pci.h>23#include <asm/eeh_event.h>02425/** Overview:26 * EEH error states may be detected within exception handlers;···36LIST_HEAD(eeh_eventlist);37static void eeh_thread_launcher(void *);38DECLARE_WORK(eeh_event_wq, eeh_thread_launcher, NULL);39-40-/**41- * eeh_panic - call panic() for an eeh event that cannot be handled.42- * The philosophy of this routine is that it is better to panic and43- * halt the OS than it is to risk possible data corruption by44- * oblivious device drivers that don't know better.45- *46- * @dev pci device that had an eeh event47- * @reset_state current reset state of the device slot48- */49-static void eeh_panic(struct pci_dev *dev, int reset_state)50-{51- /*52- * Since the panic_on_oops sysctl is used to halt the system53- * in light of potential corruption, we can use it here.54- */55- if (panic_on_oops) {56- panic("EEH: MMIO failure (%d) on device:%s\n", reset_state,57- pci_name(dev));58- }59- else {60- printk(KERN_INFO "EEH: Ignored MMIO failure (%d) on device:%s\n",61- reset_state, pci_name(dev));62- }63-}6465/**66 * eeh_event_handler - dispatch EEH events. The detection of a frozen···5859 spin_lock_irqsave(&eeh_eventlist_lock, flags);60 event = NULL;0061 if (!list_empty(&eeh_eventlist)) {62 event = list_entry(eeh_eventlist.next, struct eeh_event, list);63 list_del(&event->list);64 }000065 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);66 if (event == NULL)67 break;···75 printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n",76 pci_name(event->dev));7778- eeh_panic (event->dev, event->state);7900080 kfree(event);81 }82···107 */108int eeh_send_failure_event (struct device_node *dn,109 struct pci_dev *dev,110- int state,111 int time_unavail)112{113 unsigned long flags;
···21#include <linux/list.h>22#include <linux/pci.h>23#include <asm/eeh_event.h>24+#include <asm/ppc-pci.h>2526/** Overview:27 * EEH error states may be detected within exception handlers;···35LIST_HEAD(eeh_eventlist);36static void eeh_thread_launcher(void *);37DECLARE_WORK(eeh_event_wq, eeh_thread_launcher, NULL);00000000000000000000000003839/**40 * eeh_event_handler - dispatch EEH events. The detection of a frozen···8283 spin_lock_irqsave(&eeh_eventlist_lock, flags);84 event = NULL;85+86+ /* Unqueue the event, get ready to process. */87 if (!list_empty(&eeh_eventlist)) {88 event = list_entry(eeh_eventlist.next, struct eeh_event, list);89 list_del(&event->list);90 }91+92+ if (event)93+ eeh_mark_slot(event->dn, EEH_MODE_RECOVERING);94+95 spin_unlock_irqrestore(&eeh_eventlist_lock, flags);96 if (event == NULL)97 break;···93 printk(KERN_INFO "EEH: Detected PCI bus error on device %s\n",94 pci_name(event->dev));9596+ handle_eeh_events(event);9798+ eeh_clear_slot(event->dn, EEH_MODE_RECOVERING);99+100+ pci_dev_put(event->dev);101 kfree(event);102 }103···122 */123int eeh_send_failure_event (struct device_node *dn,124 struct pci_dev *dev,125+ enum pci_channel_state state,126 int time_unavail)127{128 unsigned long flags;
···34extern int eeh_subsystem_enabled;3536/* Values for eeh_mode bits in device_node */37-#define EEH_MODE_SUPPORTED (1<<0)38-#define EEH_MODE_NOCHECK (1<<1)39-#define EEH_MODE_ISOLATED (1<<2)004041/* Max number of EEH freezes allowed before we consider the device42 * to be permanently disabled. */
···34extern int eeh_subsystem_enabled;3536/* Values for eeh_mode bits in device_node */37+#define EEH_MODE_SUPPORTED (1<<0)38+#define EEH_MODE_NOCHECK (1<<1)39+#define EEH_MODE_ISOLATED (1<<2)40+#define EEH_MODE_RECOVERING (1<<3)41+#define EEH_MODE_IRQ_DISABLED (1<<4)4243/* Max number of EEH freezes allowed before we consider the device44 * to be permanently disabled. */
+5-2
include/asm-powerpc/eeh_event.h
···30 struct list_head list;31 struct device_node *dn; /* struct device node */32 struct pci_dev *dev; /* affected device */33- int state;34 int time_unavail; /* milliseconds until device might be available */35};36···47 */48int eeh_send_failure_event (struct device_node *dn,49 struct pci_dev *dev,50- int reset_state,51 int time_unavail);0005253#endif /* __KERNEL__ */54#endif /* ASM_PPC64_EEH_EVENT_H */
···30 struct list_head list;31 struct device_node *dn; /* struct device node */32 struct pci_dev *dev; /* affected device */33+ enum pci_channel_state state; /* PCI bus state for the affected device */34 int time_unavail; /* milliseconds until device might be available */35};36···47 */48int eeh_send_failure_event (struct device_node *dn,49 struct pci_dev *dev,50+ enum pci_channel_state state,51 int time_unavail);52+53+/* Main recovery function */54+void handle_eeh_events (struct eeh_event *);5556#endif /* __KERNEL__ */57#endif /* ASM_PPC64_EEH_EVENT_H */
+5-4
include/asm-powerpc/pci-bridge.h
···61struct iommu_table;6263struct pci_dn {64- int busno; /* for pci devices */65- int bussubno; /* for pci devices */66- int devfn; /* for pci devices */06768#ifdef CONFIG_PPC_PSERIES69 int eeh_mode; /* See eeh.h for possible EEH_MODEs */70 int eeh_config_addr;071 int eeh_check_count; /* # times driver ignored error */72 int eeh_freeze_count; /* # times this device froze up. */73- int eeh_is_bridge; /* device is pci-to-pci bridge */74#endif75 int pci_ext_config_space; /* for pci devices */76 struct pci_controller *phb; /* for pci devices */
···61struct iommu_table;6263struct pci_dn {64+ int busno; /* pci bus number */65+ int bussubno; /* pci subordinate bus number */66+ int devfn; /* pci device and function number */67+ int class_code; /* pci device class */6869#ifdef CONFIG_PPC_PSERIES70 int eeh_mode; /* See eeh.h for possible EEH_MODEs */71 int eeh_config_addr;72+ int eeh_pe_config_addr; /* new-style partition endpoint address */73 int eeh_check_count; /* # times driver ignored error */74 int eeh_freeze_count; /* # times this device froze up. */075#endif76 int pci_ext_config_space; /* for pci devices */77 struct pci_controller *phb; /* for pci devices */
+22-1
include/asm-powerpc/ppc-pci.h
···5253/* ---- EEH internal-use-only related routines ---- */54#ifdef CONFIG_EEH00000000000000055/**56 * rtas_set_slot_reset -- unfreeze a frozen slot57 *···74 * does this by asserting the PCI #RST line for 1/8th of75 * a second; this routine will sleep while the adapter is76 * being reset.0077 */78-void rtas_set_slot_reset (struct pci_dn *);7980/** 81 * eeh_restore_bars - Restore device configuration info.···101void rtas_configure_bridge(struct pci_dn *);102103int rtas_write_config(struct pci_dn *, int where, int size, u32 val);0104105/**106 * mark and clear slots: find "partition endpoint" PE and set or ···109 */110void eeh_mark_slot (struct device_node *dn, int mode_flag);111void eeh_clear_slot (struct device_node *dn, int mode_flag);000112113#endif114
···5253/* ---- EEH internal-use-only related routines ---- */54#ifdef CONFIG_EEH55+56+void pci_addr_cache_insert_device(struct pci_dev *dev);57+void pci_addr_cache_remove_device(struct pci_dev *dev);58+void pci_addr_cache_build(void);59+struct pci_dev *pci_get_device_by_addr(unsigned long addr);60+61+/**62+ * eeh_slot_error_detail -- record and EEH error condition to the log63+ * @severity: 1 if temporary, 2 if permanent failure.64+ *65+ * Obtains the the EEH error details from the RTAS subsystem,66+ * and then logs these details with the RTAS error log system.67+ */68+void eeh_slot_error_detail (struct pci_dn *pdn, int severity);69+70/**71 * rtas_set_slot_reset -- unfreeze a frozen slot72 *···59 * does this by asserting the PCI #RST line for 1/8th of60 * a second; this routine will sleep while the adapter is61 * being reset.62+ *63+ * Returns a non-zero value if the reset failed.64 */65+int rtas_set_slot_reset (struct pci_dn *);6667/** 68 * eeh_restore_bars - Restore device configuration info.···84void rtas_configure_bridge(struct pci_dn *);8586int rtas_write_config(struct pci_dn *, int where, int size, u32 val);87+int rtas_read_config(struct pci_dn *, int where, int size, u32 *val);8889/**90 * mark and clear slots: find "partition endpoint" PE and set or ···91 */92void eeh_mark_slot (struct device_node *dn, int mode_flag);93void eeh_clear_slot (struct device_node *dn, int mode_flag);94+95+/* Find the associated "Partiationable Endpoint" PE */96+struct device_node * find_device_pe(struct device_node *dn);9798#endif99
+4
include/asm-powerpc/serial.h
···15/* Default baud base if not found in device-tree */16#define BASE_BAUD ( 1843200 / 16 )17018extern void find_legacy_serial_ports(void);0001920#endif /* _PPC64_SERIAL_H */
···15/* Default baud base if not found in device-tree */16#define BASE_BAUD ( 1843200 / 16 )1718+#ifdef CONFIG_PPC_UDBG_1655019extern void find_legacy_serial_ports(void);20+#else21+#define find_legacy_serial_ports() do { } while (0)22+#endif2324#endif /* _PPC64_SERIAL_H */