1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (C) 2001 Dave Engebretsen & Todd Inglett IBM Corporation.
4*4882a593Smuzhiyun * Copyright 2001-2012 IBM Corporation.
5*4882a593Smuzhiyun */
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun #ifndef _POWERPC_EEH_H
8*4882a593Smuzhiyun #define _POWERPC_EEH_H
9*4882a593Smuzhiyun #ifdef __KERNEL__
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #include <linux/init.h>
12*4882a593Smuzhiyun #include <linux/list.h>
13*4882a593Smuzhiyun #include <linux/string.h>
14*4882a593Smuzhiyun #include <linux/time.h>
15*4882a593Smuzhiyun #include <linux/atomic.h>
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #include <uapi/asm/eeh.h>
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun struct pci_dev;
20*4882a593Smuzhiyun struct pci_bus;
21*4882a593Smuzhiyun struct pci_dn;
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun #ifdef CONFIG_EEH
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun /* EEH subsystem flags */
26*4882a593Smuzhiyun #define EEH_ENABLED 0x01 /* EEH enabled */
27*4882a593Smuzhiyun #define EEH_FORCE_DISABLED 0x02 /* EEH disabled */
28*4882a593Smuzhiyun #define EEH_PROBE_MODE_DEV 0x04 /* From PCI device */
29*4882a593Smuzhiyun #define EEH_PROBE_MODE_DEVTREE 0x08 /* From device tree */
30*4882a593Smuzhiyun #define EEH_ENABLE_IO_FOR_LOG 0x20 /* Enable IO for log */
31*4882a593Smuzhiyun #define EEH_EARLY_DUMP_LOG 0x40 /* Dump log immediately */
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun /*
34*4882a593Smuzhiyun * Delay for PE reset, all in ms
35*4882a593Smuzhiyun *
36*4882a593Smuzhiyun * PCI specification has reset hold time of 100 milliseconds.
37*4882a593Smuzhiyun * We have 250 milliseconds here. The PCI bus settlement time
38*4882a593Smuzhiyun * is specified as 1.5 seconds and we have 1.8 seconds.
39*4882a593Smuzhiyun */
40*4882a593Smuzhiyun #define EEH_PE_RST_HOLD_TIME 250
41*4882a593Smuzhiyun #define EEH_PE_RST_SETTLE_TIME 1800
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun /*
44*4882a593Smuzhiyun * The struct is used to trace PE related EEH functionality.
45*4882a593Smuzhiyun * In theory, there will have one instance of the struct to
46*4882a593Smuzhiyun * be created against particular PE. In nature, PEs correlate
47*4882a593Smuzhiyun * to each other. the struct has to reflect that hierarchy in
48*4882a593Smuzhiyun * order to easily pick up those affected PEs when one particular
49*4882a593Smuzhiyun * PE has EEH errors.
50*4882a593Smuzhiyun *
51*4882a593Smuzhiyun * Also, one particular PE might be composed of PCI device, PCI
52*4882a593Smuzhiyun * bus and its subordinate components. The struct also need ship
53*4882a593Smuzhiyun * the information. Further more, one particular PE is only meaingful
54*4882a593Smuzhiyun * in the corresponding PHB. Therefore, the root PEs should be created
55*4882a593Smuzhiyun * against existing PHBs in on-to-one fashion.
56*4882a593Smuzhiyun */
57*4882a593Smuzhiyun #define EEH_PE_INVALID (1 << 0) /* Invalid */
58*4882a593Smuzhiyun #define EEH_PE_PHB (1 << 1) /* PHB PE */
59*4882a593Smuzhiyun #define EEH_PE_DEVICE (1 << 2) /* Device PE */
60*4882a593Smuzhiyun #define EEH_PE_BUS (1 << 3) /* Bus PE */
61*4882a593Smuzhiyun #define EEH_PE_VF (1 << 4) /* VF PE */
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun #define EEH_PE_ISOLATED (1 << 0) /* Isolated PE */
64*4882a593Smuzhiyun #define EEH_PE_RECOVERING (1 << 1) /* Recovering PE */
65*4882a593Smuzhiyun #define EEH_PE_CFG_BLOCKED (1 << 2) /* Block config access */
66*4882a593Smuzhiyun #define EEH_PE_RESET (1 << 3) /* PE reset in progress */
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun #define EEH_PE_KEEP (1 << 8) /* Keep PE on hotplug */
69*4882a593Smuzhiyun #define EEH_PE_CFG_RESTRICTED (1 << 9) /* Block config on error */
70*4882a593Smuzhiyun #define EEH_PE_REMOVED (1 << 10) /* Removed permanently */
71*4882a593Smuzhiyun #define EEH_PE_PRI_BUS (1 << 11) /* Cached primary bus */
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun struct eeh_pe {
74*4882a593Smuzhiyun int type; /* PE type: PHB/Bus/Device */
75*4882a593Smuzhiyun int state; /* PE EEH dependent mode */
76*4882a593Smuzhiyun int addr; /* PE configuration address */
77*4882a593Smuzhiyun struct pci_controller *phb; /* Associated PHB */
78*4882a593Smuzhiyun struct pci_bus *bus; /* Top PCI bus for bus PE */
79*4882a593Smuzhiyun int check_count; /* Times of ignored error */
80*4882a593Smuzhiyun int freeze_count; /* Times of froze up */
81*4882a593Smuzhiyun time64_t tstamp; /* Time on first-time freeze */
82*4882a593Smuzhiyun int false_positives; /* Times of reported #ff's */
83*4882a593Smuzhiyun atomic_t pass_dev_cnt; /* Count of passed through devs */
84*4882a593Smuzhiyun struct eeh_pe *parent; /* Parent PE */
85*4882a593Smuzhiyun void *data; /* PE auxillary data */
86*4882a593Smuzhiyun struct list_head child_list; /* List of PEs below this PE */
87*4882a593Smuzhiyun struct list_head child; /* Memb. child_list/eeh_phb_pe */
88*4882a593Smuzhiyun struct list_head edevs; /* List of eeh_dev in this PE */
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun #ifdef CONFIG_STACKTRACE
91*4882a593Smuzhiyun /*
92*4882a593Smuzhiyun * Saved stack trace. When we find a PE freeze in eeh_dev_check_failure
93*4882a593Smuzhiyun * the stack trace is saved here so we can print it in the recovery
94*4882a593Smuzhiyun * thread if it turns out to due to a real problem rather than
95*4882a593Smuzhiyun * a hot-remove.
96*4882a593Smuzhiyun *
97*4882a593Smuzhiyun * A max of 64 entries might be overkill, but it also might not be.
98*4882a593Smuzhiyun */
99*4882a593Smuzhiyun unsigned long stack_trace[64];
100*4882a593Smuzhiyun int trace_entries;
101*4882a593Smuzhiyun #endif /* CONFIG_STACKTRACE */
102*4882a593Smuzhiyun };
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun #define eeh_pe_for_each_dev(pe, edev, tmp) \
105*4882a593Smuzhiyun list_for_each_entry_safe(edev, tmp, &pe->edevs, entry)
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun #define eeh_for_each_pe(root, pe) \
108*4882a593Smuzhiyun for (pe = root; pe; pe = eeh_pe_next(pe, root))
109*4882a593Smuzhiyun
eeh_pe_passed(struct eeh_pe * pe)110*4882a593Smuzhiyun static inline bool eeh_pe_passed(struct eeh_pe *pe)
111*4882a593Smuzhiyun {
112*4882a593Smuzhiyun return pe ? !!atomic_read(&pe->pass_dev_cnt) : false;
113*4882a593Smuzhiyun }
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun /*
116*4882a593Smuzhiyun * The struct is used to trace EEH state for the associated
117*4882a593Smuzhiyun * PCI device node or PCI device. In future, it might
118*4882a593Smuzhiyun * represent PE as well so that the EEH device to form
119*4882a593Smuzhiyun * another tree except the currently existing tree of PCI
120*4882a593Smuzhiyun * buses and PCI devices
121*4882a593Smuzhiyun */
122*4882a593Smuzhiyun #define EEH_DEV_BRIDGE (1 << 0) /* PCI bridge */
123*4882a593Smuzhiyun #define EEH_DEV_ROOT_PORT (1 << 1) /* PCIe root port */
124*4882a593Smuzhiyun #define EEH_DEV_DS_PORT (1 << 2) /* Downstream port */
125*4882a593Smuzhiyun #define EEH_DEV_IRQ_DISABLED (1 << 3) /* Interrupt disabled */
126*4882a593Smuzhiyun #define EEH_DEV_DISCONNECTED (1 << 4) /* Removing from PE */
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun #define EEH_DEV_NO_HANDLER (1 << 8) /* No error handler */
129*4882a593Smuzhiyun #define EEH_DEV_SYSFS (1 << 9) /* Sysfs created */
130*4882a593Smuzhiyun #define EEH_DEV_REMOVED (1 << 10) /* Removed permanently */
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun struct eeh_dev {
133*4882a593Smuzhiyun int mode; /* EEH mode */
134*4882a593Smuzhiyun int bdfn; /* bdfn of device (for cfg ops) */
135*4882a593Smuzhiyun struct pci_controller *controller;
136*4882a593Smuzhiyun int pe_config_addr; /* PE config address */
137*4882a593Smuzhiyun u32 config_space[16]; /* Saved PCI config space */
138*4882a593Smuzhiyun int pcix_cap; /* Saved PCIx capability */
139*4882a593Smuzhiyun int pcie_cap; /* Saved PCIe capability */
140*4882a593Smuzhiyun int aer_cap; /* Saved AER capability */
141*4882a593Smuzhiyun int af_cap; /* Saved AF capability */
142*4882a593Smuzhiyun struct eeh_pe *pe; /* Associated PE */
143*4882a593Smuzhiyun struct list_head entry; /* Membership in eeh_pe.edevs */
144*4882a593Smuzhiyun struct list_head rmv_entry; /* Membership in rmv_list */
145*4882a593Smuzhiyun struct pci_dn *pdn; /* Associated PCI device node */
146*4882a593Smuzhiyun struct pci_dev *pdev; /* Associated PCI device */
147*4882a593Smuzhiyun bool in_error; /* Error flag for edev */
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun /* VF specific properties */
150*4882a593Smuzhiyun struct pci_dev *physfn; /* Associated SRIOV PF */
151*4882a593Smuzhiyun int vf_index; /* Index of this VF */
152*4882a593Smuzhiyun };
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun /* "fmt" must be a simple literal string */
155*4882a593Smuzhiyun #define EEH_EDEV_PRINT(level, edev, fmt, ...) \
156*4882a593Smuzhiyun pr_##level("PCI %04x:%02x:%02x.%x#%04x: EEH: " fmt, \
157*4882a593Smuzhiyun (edev)->controller->global_number, PCI_BUSNO((edev)->bdfn), \
158*4882a593Smuzhiyun PCI_SLOT((edev)->bdfn), PCI_FUNC((edev)->bdfn), \
159*4882a593Smuzhiyun ((edev)->pe ? (edev)->pe_config_addr : 0xffff), ##__VA_ARGS__)
160*4882a593Smuzhiyun #define eeh_edev_dbg(edev, fmt, ...) EEH_EDEV_PRINT(debug, (edev), fmt, ##__VA_ARGS__)
161*4882a593Smuzhiyun #define eeh_edev_info(edev, fmt, ...) EEH_EDEV_PRINT(info, (edev), fmt, ##__VA_ARGS__)
162*4882a593Smuzhiyun #define eeh_edev_warn(edev, fmt, ...) EEH_EDEV_PRINT(warn, (edev), fmt, ##__VA_ARGS__)
163*4882a593Smuzhiyun #define eeh_edev_err(edev, fmt, ...) EEH_EDEV_PRINT(err, (edev), fmt, ##__VA_ARGS__)
164*4882a593Smuzhiyun
eeh_dev_to_pdn(struct eeh_dev * edev)165*4882a593Smuzhiyun static inline struct pci_dn *eeh_dev_to_pdn(struct eeh_dev *edev)
166*4882a593Smuzhiyun {
167*4882a593Smuzhiyun return edev ? edev->pdn : NULL;
168*4882a593Smuzhiyun }
169*4882a593Smuzhiyun
eeh_dev_to_pci_dev(struct eeh_dev * edev)170*4882a593Smuzhiyun static inline struct pci_dev *eeh_dev_to_pci_dev(struct eeh_dev *edev)
171*4882a593Smuzhiyun {
172*4882a593Smuzhiyun return edev ? edev->pdev : NULL;
173*4882a593Smuzhiyun }
174*4882a593Smuzhiyun
eeh_dev_to_pe(struct eeh_dev * edev)175*4882a593Smuzhiyun static inline struct eeh_pe *eeh_dev_to_pe(struct eeh_dev* edev)
176*4882a593Smuzhiyun {
177*4882a593Smuzhiyun return edev ? edev->pe : NULL;
178*4882a593Smuzhiyun }
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun /* Return values from eeh_ops::next_error */
181*4882a593Smuzhiyun enum {
182*4882a593Smuzhiyun EEH_NEXT_ERR_NONE = 0,
183*4882a593Smuzhiyun EEH_NEXT_ERR_INF,
184*4882a593Smuzhiyun EEH_NEXT_ERR_FROZEN_PE,
185*4882a593Smuzhiyun EEH_NEXT_ERR_FENCED_PHB,
186*4882a593Smuzhiyun EEH_NEXT_ERR_DEAD_PHB,
187*4882a593Smuzhiyun EEH_NEXT_ERR_DEAD_IOC
188*4882a593Smuzhiyun };
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun /*
191*4882a593Smuzhiyun * The struct is used to trace the registered EEH operation
192*4882a593Smuzhiyun * callback functions. Actually, those operation callback
193*4882a593Smuzhiyun * functions are heavily platform dependent. That means the
194*4882a593Smuzhiyun * platform should register its own EEH operation callback
195*4882a593Smuzhiyun * functions before any EEH further operations.
196*4882a593Smuzhiyun */
197*4882a593Smuzhiyun #define EEH_OPT_DISABLE 0 /* EEH disable */
198*4882a593Smuzhiyun #define EEH_OPT_ENABLE 1 /* EEH enable */
199*4882a593Smuzhiyun #define EEH_OPT_THAW_MMIO 2 /* MMIO enable */
200*4882a593Smuzhiyun #define EEH_OPT_THAW_DMA 3 /* DMA enable */
201*4882a593Smuzhiyun #define EEH_OPT_FREEZE_PE 4 /* Freeze PE */
202*4882a593Smuzhiyun #define EEH_STATE_UNAVAILABLE (1 << 0) /* State unavailable */
203*4882a593Smuzhiyun #define EEH_STATE_NOT_SUPPORT (1 << 1) /* EEH not supported */
204*4882a593Smuzhiyun #define EEH_STATE_RESET_ACTIVE (1 << 2) /* Active reset */
205*4882a593Smuzhiyun #define EEH_STATE_MMIO_ACTIVE (1 << 3) /* Active MMIO */
206*4882a593Smuzhiyun #define EEH_STATE_DMA_ACTIVE (1 << 4) /* Active DMA */
207*4882a593Smuzhiyun #define EEH_STATE_MMIO_ENABLED (1 << 5) /* MMIO enabled */
208*4882a593Smuzhiyun #define EEH_STATE_DMA_ENABLED (1 << 6) /* DMA enabled */
209*4882a593Smuzhiyun #define EEH_RESET_DEACTIVATE 0 /* Deactivate the PE reset */
210*4882a593Smuzhiyun #define EEH_RESET_HOT 1 /* Hot reset */
211*4882a593Smuzhiyun #define EEH_RESET_FUNDAMENTAL 3 /* Fundamental reset */
212*4882a593Smuzhiyun #define EEH_LOG_TEMP 1 /* EEH temporary error log */
213*4882a593Smuzhiyun #define EEH_LOG_PERM 2 /* EEH permanent error log */
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun struct eeh_ops {
216*4882a593Smuzhiyun char *name;
217*4882a593Smuzhiyun struct eeh_dev *(*probe)(struct pci_dev *pdev);
218*4882a593Smuzhiyun int (*set_option)(struct eeh_pe *pe, int option);
219*4882a593Smuzhiyun int (*get_state)(struct eeh_pe *pe, int *delay);
220*4882a593Smuzhiyun int (*reset)(struct eeh_pe *pe, int option);
221*4882a593Smuzhiyun int (*get_log)(struct eeh_pe *pe, int severity, char *drv_log, unsigned long len);
222*4882a593Smuzhiyun int (*configure_bridge)(struct eeh_pe *pe);
223*4882a593Smuzhiyun int (*err_inject)(struct eeh_pe *pe, int type, int func,
224*4882a593Smuzhiyun unsigned long addr, unsigned long mask);
225*4882a593Smuzhiyun int (*read_config)(struct eeh_dev *edev, int where, int size, u32 *val);
226*4882a593Smuzhiyun int (*write_config)(struct eeh_dev *edev, int where, int size, u32 val);
227*4882a593Smuzhiyun int (*next_error)(struct eeh_pe **pe);
228*4882a593Smuzhiyun int (*restore_config)(struct eeh_dev *edev);
229*4882a593Smuzhiyun int (*notify_resume)(struct eeh_dev *edev);
230*4882a593Smuzhiyun };
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun extern int eeh_subsystem_flags;
233*4882a593Smuzhiyun extern u32 eeh_max_freezes;
234*4882a593Smuzhiyun extern bool eeh_debugfs_no_recover;
235*4882a593Smuzhiyun extern struct eeh_ops *eeh_ops;
236*4882a593Smuzhiyun extern raw_spinlock_t confirm_error_lock;
237*4882a593Smuzhiyun
eeh_add_flag(int flag)238*4882a593Smuzhiyun static inline void eeh_add_flag(int flag)
239*4882a593Smuzhiyun {
240*4882a593Smuzhiyun eeh_subsystem_flags |= flag;
241*4882a593Smuzhiyun }
242*4882a593Smuzhiyun
eeh_clear_flag(int flag)243*4882a593Smuzhiyun static inline void eeh_clear_flag(int flag)
244*4882a593Smuzhiyun {
245*4882a593Smuzhiyun eeh_subsystem_flags &= ~flag;
246*4882a593Smuzhiyun }
247*4882a593Smuzhiyun
eeh_has_flag(int flag)248*4882a593Smuzhiyun static inline bool eeh_has_flag(int flag)
249*4882a593Smuzhiyun {
250*4882a593Smuzhiyun return !!(eeh_subsystem_flags & flag);
251*4882a593Smuzhiyun }
252*4882a593Smuzhiyun
eeh_enabled(void)253*4882a593Smuzhiyun static inline bool eeh_enabled(void)
254*4882a593Smuzhiyun {
255*4882a593Smuzhiyun return eeh_has_flag(EEH_ENABLED) && !eeh_has_flag(EEH_FORCE_DISABLED);
256*4882a593Smuzhiyun }
257*4882a593Smuzhiyun
eeh_serialize_lock(unsigned long * flags)258*4882a593Smuzhiyun static inline void eeh_serialize_lock(unsigned long *flags)
259*4882a593Smuzhiyun {
260*4882a593Smuzhiyun raw_spin_lock_irqsave(&confirm_error_lock, *flags);
261*4882a593Smuzhiyun }
262*4882a593Smuzhiyun
eeh_serialize_unlock(unsigned long flags)263*4882a593Smuzhiyun static inline void eeh_serialize_unlock(unsigned long flags)
264*4882a593Smuzhiyun {
265*4882a593Smuzhiyun raw_spin_unlock_irqrestore(&confirm_error_lock, flags);
266*4882a593Smuzhiyun }
267*4882a593Smuzhiyun
eeh_state_active(int state)268*4882a593Smuzhiyun static inline bool eeh_state_active(int state)
269*4882a593Smuzhiyun {
270*4882a593Smuzhiyun return (state & (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE))
271*4882a593Smuzhiyun == (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE);
272*4882a593Smuzhiyun }
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun typedef void (*eeh_edev_traverse_func)(struct eeh_dev *edev, void *flag);
275*4882a593Smuzhiyun typedef void *(*eeh_pe_traverse_func)(struct eeh_pe *pe, void *flag);
276*4882a593Smuzhiyun void eeh_set_pe_aux_size(int size);
277*4882a593Smuzhiyun int eeh_phb_pe_create(struct pci_controller *phb);
278*4882a593Smuzhiyun int eeh_wait_state(struct eeh_pe *pe, int max_wait);
279*4882a593Smuzhiyun struct eeh_pe *eeh_phb_pe_get(struct pci_controller *phb);
280*4882a593Smuzhiyun struct eeh_pe *eeh_pe_next(struct eeh_pe *pe, struct eeh_pe *root);
281*4882a593Smuzhiyun struct eeh_pe *eeh_pe_get(struct pci_controller *phb, int pe_no);
282*4882a593Smuzhiyun int eeh_pe_tree_insert(struct eeh_dev *edev, struct eeh_pe *new_pe_parent);
283*4882a593Smuzhiyun int eeh_pe_tree_remove(struct eeh_dev *edev);
284*4882a593Smuzhiyun void eeh_pe_update_time_stamp(struct eeh_pe *pe);
285*4882a593Smuzhiyun void *eeh_pe_traverse(struct eeh_pe *root,
286*4882a593Smuzhiyun eeh_pe_traverse_func fn, void *flag);
287*4882a593Smuzhiyun void eeh_pe_dev_traverse(struct eeh_pe *root,
288*4882a593Smuzhiyun eeh_edev_traverse_func fn, void *flag);
289*4882a593Smuzhiyun void eeh_pe_restore_bars(struct eeh_pe *pe);
290*4882a593Smuzhiyun const char *eeh_pe_loc_get(struct eeh_pe *pe);
291*4882a593Smuzhiyun struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe);
292*4882a593Smuzhiyun
293*4882a593Smuzhiyun void eeh_show_enabled(void);
294*4882a593Smuzhiyun int __init eeh_init(struct eeh_ops *ops);
295*4882a593Smuzhiyun int eeh_check_failure(const volatile void __iomem *token);
296*4882a593Smuzhiyun int eeh_dev_check_failure(struct eeh_dev *edev);
297*4882a593Smuzhiyun void eeh_addr_cache_init(void);
298*4882a593Smuzhiyun void eeh_probe_device(struct pci_dev *pdev);
299*4882a593Smuzhiyun void eeh_remove_device(struct pci_dev *);
300*4882a593Smuzhiyun int eeh_unfreeze_pe(struct eeh_pe *pe);
301*4882a593Smuzhiyun int eeh_pe_reset_and_recover(struct eeh_pe *pe);
302*4882a593Smuzhiyun int eeh_dev_open(struct pci_dev *pdev);
303*4882a593Smuzhiyun void eeh_dev_release(struct pci_dev *pdev);
304*4882a593Smuzhiyun struct eeh_pe *eeh_iommu_group_to_pe(struct iommu_group *group);
305*4882a593Smuzhiyun int eeh_pe_set_option(struct eeh_pe *pe, int option);
306*4882a593Smuzhiyun int eeh_pe_get_state(struct eeh_pe *pe);
307*4882a593Smuzhiyun int eeh_pe_reset(struct eeh_pe *pe, int option, bool include_passed);
308*4882a593Smuzhiyun int eeh_pe_configure(struct eeh_pe *pe);
309*4882a593Smuzhiyun int eeh_pe_inject_err(struct eeh_pe *pe, int type, int func,
310*4882a593Smuzhiyun unsigned long addr, unsigned long mask);
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun /**
313*4882a593Smuzhiyun * EEH_POSSIBLE_ERROR() -- test for possible MMIO failure.
314*4882a593Smuzhiyun *
315*4882a593Smuzhiyun * If this macro yields TRUE, the caller relays to eeh_check_failure()
316*4882a593Smuzhiyun * which does further tests out of line.
317*4882a593Smuzhiyun */
318*4882a593Smuzhiyun #define EEH_POSSIBLE_ERROR(val, type) ((val) == (type)~0 && eeh_enabled())
319*4882a593Smuzhiyun
320*4882a593Smuzhiyun /*
321*4882a593Smuzhiyun * Reads from a device which has been isolated by EEH will return
322*4882a593Smuzhiyun * all 1s. This macro gives an all-1s value of the given size (in
323*4882a593Smuzhiyun * bytes: 1, 2, or 4) for comparing with the result of a read.
324*4882a593Smuzhiyun */
325*4882a593Smuzhiyun #define EEH_IO_ERROR_VALUE(size) (~0U >> ((4 - (size)) * 8))
326*4882a593Smuzhiyun
327*4882a593Smuzhiyun #else /* !CONFIG_EEH */
328*4882a593Smuzhiyun
eeh_enabled(void)329*4882a593Smuzhiyun static inline bool eeh_enabled(void)
330*4882a593Smuzhiyun {
331*4882a593Smuzhiyun return false;
332*4882a593Smuzhiyun }
333*4882a593Smuzhiyun
eeh_show_enabled(void)334*4882a593Smuzhiyun static inline void eeh_show_enabled(void) { }
335*4882a593Smuzhiyun
eeh_dev_phb_init_dynamic(struct pci_controller * phb)336*4882a593Smuzhiyun static inline void eeh_dev_phb_init_dynamic(struct pci_controller *phb) { }
337*4882a593Smuzhiyun
eeh_check_failure(const volatile void __iomem * token)338*4882a593Smuzhiyun static inline int eeh_check_failure(const volatile void __iomem *token)
339*4882a593Smuzhiyun {
340*4882a593Smuzhiyun return 0;
341*4882a593Smuzhiyun }
342*4882a593Smuzhiyun
343*4882a593Smuzhiyun #define eeh_dev_check_failure(x) (0)
344*4882a593Smuzhiyun
eeh_addr_cache_init(void)345*4882a593Smuzhiyun static inline void eeh_addr_cache_init(void) { }
346*4882a593Smuzhiyun
eeh_probe_device(struct pci_dev * dev)347*4882a593Smuzhiyun static inline void eeh_probe_device(struct pci_dev *dev) { }
348*4882a593Smuzhiyun
eeh_remove_device(struct pci_dev * dev)349*4882a593Smuzhiyun static inline void eeh_remove_device(struct pci_dev *dev) { }
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun #define EEH_POSSIBLE_ERROR(val, type) (0)
352*4882a593Smuzhiyun #define EEH_IO_ERROR_VALUE(size) (-1UL)
eeh_phb_pe_create(struct pci_controller * phb)353*4882a593Smuzhiyun static inline int eeh_phb_pe_create(struct pci_controller *phb) { return 0; }
354*4882a593Smuzhiyun #endif /* CONFIG_EEH */
355*4882a593Smuzhiyun
356*4882a593Smuzhiyun #if defined(CONFIG_PPC_PSERIES) && defined(CONFIG_EEH)
357*4882a593Smuzhiyun void pseries_eeh_init_edev(struct pci_dn *pdn);
358*4882a593Smuzhiyun void pseries_eeh_init_edev_recursive(struct pci_dn *pdn);
359*4882a593Smuzhiyun #else
pseries_eeh_add_device_early(struct pci_dn * pdn)360*4882a593Smuzhiyun static inline void pseries_eeh_add_device_early(struct pci_dn *pdn) { }
pseries_eeh_add_device_tree_early(struct pci_dn * pdn)361*4882a593Smuzhiyun static inline void pseries_eeh_add_device_tree_early(struct pci_dn *pdn) { }
362*4882a593Smuzhiyun #endif
363*4882a593Smuzhiyun
364*4882a593Smuzhiyun #ifdef CONFIG_PPC64
365*4882a593Smuzhiyun /*
366*4882a593Smuzhiyun * MMIO read/write operations with EEH support.
367*4882a593Smuzhiyun */
eeh_readb(const volatile void __iomem * addr)368*4882a593Smuzhiyun static inline u8 eeh_readb(const volatile void __iomem *addr)
369*4882a593Smuzhiyun {
370*4882a593Smuzhiyun u8 val = in_8(addr);
371*4882a593Smuzhiyun if (EEH_POSSIBLE_ERROR(val, u8))
372*4882a593Smuzhiyun eeh_check_failure(addr);
373*4882a593Smuzhiyun return val;
374*4882a593Smuzhiyun }
375*4882a593Smuzhiyun
eeh_readw(const volatile void __iomem * addr)376*4882a593Smuzhiyun static inline u16 eeh_readw(const volatile void __iomem *addr)
377*4882a593Smuzhiyun {
378*4882a593Smuzhiyun u16 val = in_le16(addr);
379*4882a593Smuzhiyun if (EEH_POSSIBLE_ERROR(val, u16))
380*4882a593Smuzhiyun eeh_check_failure(addr);
381*4882a593Smuzhiyun return val;
382*4882a593Smuzhiyun }
383*4882a593Smuzhiyun
eeh_readl(const volatile void __iomem * addr)384*4882a593Smuzhiyun static inline u32 eeh_readl(const volatile void __iomem *addr)
385*4882a593Smuzhiyun {
386*4882a593Smuzhiyun u32 val = in_le32(addr);
387*4882a593Smuzhiyun if (EEH_POSSIBLE_ERROR(val, u32))
388*4882a593Smuzhiyun eeh_check_failure(addr);
389*4882a593Smuzhiyun return val;
390*4882a593Smuzhiyun }
391*4882a593Smuzhiyun
eeh_readq(const volatile void __iomem * addr)392*4882a593Smuzhiyun static inline u64 eeh_readq(const volatile void __iomem *addr)
393*4882a593Smuzhiyun {
394*4882a593Smuzhiyun u64 val = in_le64(addr);
395*4882a593Smuzhiyun if (EEH_POSSIBLE_ERROR(val, u64))
396*4882a593Smuzhiyun eeh_check_failure(addr);
397*4882a593Smuzhiyun return val;
398*4882a593Smuzhiyun }
399*4882a593Smuzhiyun
eeh_readw_be(const volatile void __iomem * addr)400*4882a593Smuzhiyun static inline u16 eeh_readw_be(const volatile void __iomem *addr)
401*4882a593Smuzhiyun {
402*4882a593Smuzhiyun u16 val = in_be16(addr);
403*4882a593Smuzhiyun if (EEH_POSSIBLE_ERROR(val, u16))
404*4882a593Smuzhiyun eeh_check_failure(addr);
405*4882a593Smuzhiyun return val;
406*4882a593Smuzhiyun }
407*4882a593Smuzhiyun
eeh_readl_be(const volatile void __iomem * addr)408*4882a593Smuzhiyun static inline u32 eeh_readl_be(const volatile void __iomem *addr)
409*4882a593Smuzhiyun {
410*4882a593Smuzhiyun u32 val = in_be32(addr);
411*4882a593Smuzhiyun if (EEH_POSSIBLE_ERROR(val, u32))
412*4882a593Smuzhiyun eeh_check_failure(addr);
413*4882a593Smuzhiyun return val;
414*4882a593Smuzhiyun }
415*4882a593Smuzhiyun
eeh_readq_be(const volatile void __iomem * addr)416*4882a593Smuzhiyun static inline u64 eeh_readq_be(const volatile void __iomem *addr)
417*4882a593Smuzhiyun {
418*4882a593Smuzhiyun u64 val = in_be64(addr);
419*4882a593Smuzhiyun if (EEH_POSSIBLE_ERROR(val, u64))
420*4882a593Smuzhiyun eeh_check_failure(addr);
421*4882a593Smuzhiyun return val;
422*4882a593Smuzhiyun }
423*4882a593Smuzhiyun
eeh_memcpy_fromio(void * dest,const volatile void __iomem * src,unsigned long n)424*4882a593Smuzhiyun static inline void eeh_memcpy_fromio(void *dest, const
425*4882a593Smuzhiyun volatile void __iomem *src,
426*4882a593Smuzhiyun unsigned long n)
427*4882a593Smuzhiyun {
428*4882a593Smuzhiyun _memcpy_fromio(dest, src, n);
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun /* Look for ffff's here at dest[n]. Assume that at least 4 bytes
431*4882a593Smuzhiyun * were copied. Check all four bytes.
432*4882a593Smuzhiyun */
433*4882a593Smuzhiyun if (n >= 4 && EEH_POSSIBLE_ERROR(*((u32 *)(dest + n - 4)), u32))
434*4882a593Smuzhiyun eeh_check_failure(src);
435*4882a593Smuzhiyun }
436*4882a593Smuzhiyun
437*4882a593Smuzhiyun /* in-string eeh macros */
eeh_readsb(const volatile void __iomem * addr,void * buf,int ns)438*4882a593Smuzhiyun static inline void eeh_readsb(const volatile void __iomem *addr, void * buf,
439*4882a593Smuzhiyun int ns)
440*4882a593Smuzhiyun {
441*4882a593Smuzhiyun _insb(addr, buf, ns);
442*4882a593Smuzhiyun if (EEH_POSSIBLE_ERROR((*(((u8*)buf)+ns-1)), u8))
443*4882a593Smuzhiyun eeh_check_failure(addr);
444*4882a593Smuzhiyun }
445*4882a593Smuzhiyun
eeh_readsw(const volatile void __iomem * addr,void * buf,int ns)446*4882a593Smuzhiyun static inline void eeh_readsw(const volatile void __iomem *addr, void * buf,
447*4882a593Smuzhiyun int ns)
448*4882a593Smuzhiyun {
449*4882a593Smuzhiyun _insw(addr, buf, ns);
450*4882a593Smuzhiyun if (EEH_POSSIBLE_ERROR((*(((u16*)buf)+ns-1)), u16))
451*4882a593Smuzhiyun eeh_check_failure(addr);
452*4882a593Smuzhiyun }
453*4882a593Smuzhiyun
eeh_readsl(const volatile void __iomem * addr,void * buf,int nl)454*4882a593Smuzhiyun static inline void eeh_readsl(const volatile void __iomem *addr, void * buf,
455*4882a593Smuzhiyun int nl)
456*4882a593Smuzhiyun {
457*4882a593Smuzhiyun _insl(addr, buf, nl);
458*4882a593Smuzhiyun if (EEH_POSSIBLE_ERROR((*(((u32*)buf)+nl-1)), u32))
459*4882a593Smuzhiyun eeh_check_failure(addr);
460*4882a593Smuzhiyun }
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun
463*4882a593Smuzhiyun void eeh_cache_debugfs_init(void);
464*4882a593Smuzhiyun
465*4882a593Smuzhiyun #endif /* CONFIG_PPC64 */
466*4882a593Smuzhiyun #endif /* __KERNEL__ */
467*4882a593Smuzhiyun #endif /* _POWERPC_EEH_H */
468