18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2001  Dave Engebretsen & Todd Inglett IBM Corporation.
48c2ecf20Sopenharmony_ci * Copyright 2001-2012 IBM Corporation.
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef _POWERPC_EEH_H
88c2ecf20Sopenharmony_ci#define _POWERPC_EEH_H
98c2ecf20Sopenharmony_ci#ifdef __KERNEL__
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/init.h>
128c2ecf20Sopenharmony_ci#include <linux/list.h>
138c2ecf20Sopenharmony_ci#include <linux/string.h>
148c2ecf20Sopenharmony_ci#include <linux/time.h>
158c2ecf20Sopenharmony_ci#include <linux/atomic.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <uapi/asm/eeh.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cistruct pci_dev;
208c2ecf20Sopenharmony_cistruct pci_bus;
218c2ecf20Sopenharmony_cistruct pci_dn;
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#ifdef CONFIG_EEH
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/* EEH subsystem flags */
268c2ecf20Sopenharmony_ci#define EEH_ENABLED		0x01	/* EEH enabled			     */
278c2ecf20Sopenharmony_ci#define EEH_FORCE_DISABLED	0x02	/* EEH disabled			     */
288c2ecf20Sopenharmony_ci#define EEH_PROBE_MODE_DEV	0x04	/* From PCI device		     */
298c2ecf20Sopenharmony_ci#define EEH_PROBE_MODE_DEVTREE	0x08	/* From device tree		     */
308c2ecf20Sopenharmony_ci#define EEH_ENABLE_IO_FOR_LOG	0x20	/* Enable IO for log		     */
318c2ecf20Sopenharmony_ci#define EEH_EARLY_DUMP_LOG	0x40	/* Dump log immediately		     */
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci/*
348c2ecf20Sopenharmony_ci * Delay for PE reset, all in ms
358c2ecf20Sopenharmony_ci *
368c2ecf20Sopenharmony_ci * PCI specification has reset hold time of 100 milliseconds.
378c2ecf20Sopenharmony_ci * We have 250 milliseconds here. The PCI bus settlement time
388c2ecf20Sopenharmony_ci * is specified as 1.5 seconds and we have 1.8 seconds.
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ci#define EEH_PE_RST_HOLD_TIME		250
418c2ecf20Sopenharmony_ci#define EEH_PE_RST_SETTLE_TIME		1800
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci/*
448c2ecf20Sopenharmony_ci * The struct is used to trace PE related EEH functionality.
458c2ecf20Sopenharmony_ci * In theory, there will have one instance of the struct to
468c2ecf20Sopenharmony_ci * be created against particular PE. In nature, PEs correlate
478c2ecf20Sopenharmony_ci * to each other. the struct has to reflect that hierarchy in
488c2ecf20Sopenharmony_ci * order to easily pick up those affected PEs when one particular
498c2ecf20Sopenharmony_ci * PE has EEH errors.
508c2ecf20Sopenharmony_ci *
518c2ecf20Sopenharmony_ci * Also, one particular PE might be composed of PCI device, PCI
528c2ecf20Sopenharmony_ci * bus and its subordinate components. The struct also need ship
538c2ecf20Sopenharmony_ci * the information. Further more, one particular PE is only meaingful
548c2ecf20Sopenharmony_ci * in the corresponding PHB. Therefore, the root PEs should be created
558c2ecf20Sopenharmony_ci * against existing PHBs in on-to-one fashion.
568c2ecf20Sopenharmony_ci */
578c2ecf20Sopenharmony_ci#define EEH_PE_INVALID	(1 << 0)	/* Invalid   */
588c2ecf20Sopenharmony_ci#define EEH_PE_PHB	(1 << 1)	/* PHB PE    */
598c2ecf20Sopenharmony_ci#define EEH_PE_DEVICE 	(1 << 2)	/* Device PE */
608c2ecf20Sopenharmony_ci#define EEH_PE_BUS	(1 << 3)	/* Bus PE    */
618c2ecf20Sopenharmony_ci#define EEH_PE_VF	(1 << 4)	/* VF PE     */
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#define EEH_PE_ISOLATED		(1 << 0)	/* Isolated PE		*/
648c2ecf20Sopenharmony_ci#define EEH_PE_RECOVERING	(1 << 1)	/* Recovering PE	*/
658c2ecf20Sopenharmony_ci#define EEH_PE_CFG_BLOCKED	(1 << 2)	/* Block config access	*/
668c2ecf20Sopenharmony_ci#define EEH_PE_RESET		(1 << 3)	/* PE reset in progress */
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#define EEH_PE_KEEP		(1 << 8)	/* Keep PE on hotplug	*/
698c2ecf20Sopenharmony_ci#define EEH_PE_CFG_RESTRICTED	(1 << 9)	/* Block config on error */
708c2ecf20Sopenharmony_ci#define EEH_PE_REMOVED		(1 << 10)	/* Removed permanently	*/
718c2ecf20Sopenharmony_ci#define EEH_PE_PRI_BUS		(1 << 11)	/* Cached primary bus   */
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistruct eeh_pe {
748c2ecf20Sopenharmony_ci	int type;			/* PE type: PHB/Bus/Device	*/
758c2ecf20Sopenharmony_ci	int state;			/* PE EEH dependent mode	*/
768c2ecf20Sopenharmony_ci	int addr;			/* PE configuration address	*/
778c2ecf20Sopenharmony_ci	struct pci_controller *phb;	/* Associated PHB		*/
788c2ecf20Sopenharmony_ci	struct pci_bus *bus;		/* Top PCI bus for bus PE	*/
798c2ecf20Sopenharmony_ci	int check_count;		/* Times of ignored error	*/
808c2ecf20Sopenharmony_ci	int freeze_count;		/* Times of froze up		*/
818c2ecf20Sopenharmony_ci	time64_t tstamp;		/* Time on first-time freeze	*/
828c2ecf20Sopenharmony_ci	int false_positives;		/* Times of reported #ff's	*/
838c2ecf20Sopenharmony_ci	atomic_t pass_dev_cnt;		/* Count of passed through devs	*/
848c2ecf20Sopenharmony_ci	struct eeh_pe *parent;		/* Parent PE			*/
858c2ecf20Sopenharmony_ci	void *data;			/* PE auxillary data		*/
868c2ecf20Sopenharmony_ci	struct list_head child_list;	/* List of PEs below this PE	*/
878c2ecf20Sopenharmony_ci	struct list_head child;		/* Memb. child_list/eeh_phb_pe	*/
888c2ecf20Sopenharmony_ci	struct list_head edevs;		/* List of eeh_dev in this PE	*/
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#ifdef CONFIG_STACKTRACE
918c2ecf20Sopenharmony_ci	/*
928c2ecf20Sopenharmony_ci	 * Saved stack trace. When we find a PE freeze in eeh_dev_check_failure
938c2ecf20Sopenharmony_ci	 * the stack trace is saved here so we can print it in the recovery
948c2ecf20Sopenharmony_ci	 * thread if it turns out to due to a real problem rather than
958c2ecf20Sopenharmony_ci	 * a hot-remove.
968c2ecf20Sopenharmony_ci	 *
978c2ecf20Sopenharmony_ci	 * A max of 64 entries might be overkill, but it also might not be.
988c2ecf20Sopenharmony_ci	 */
998c2ecf20Sopenharmony_ci	unsigned long stack_trace[64];
1008c2ecf20Sopenharmony_ci	int trace_entries;
1018c2ecf20Sopenharmony_ci#endif /* CONFIG_STACKTRACE */
1028c2ecf20Sopenharmony_ci};
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci#define eeh_pe_for_each_dev(pe, edev, tmp) \
1058c2ecf20Sopenharmony_ci		list_for_each_entry_safe(edev, tmp, &pe->edevs, entry)
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define eeh_for_each_pe(root, pe) \
1088c2ecf20Sopenharmony_ci	for (pe = root; pe; pe = eeh_pe_next(pe, root))
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cistatic inline bool eeh_pe_passed(struct eeh_pe *pe)
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	return pe ? !!atomic_read(&pe->pass_dev_cnt) : false;
1138c2ecf20Sopenharmony_ci}
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/*
1168c2ecf20Sopenharmony_ci * The struct is used to trace EEH state for the associated
1178c2ecf20Sopenharmony_ci * PCI device node or PCI device. In future, it might
1188c2ecf20Sopenharmony_ci * represent PE as well so that the EEH device to form
1198c2ecf20Sopenharmony_ci * another tree except the currently existing tree of PCI
1208c2ecf20Sopenharmony_ci * buses and PCI devices
1218c2ecf20Sopenharmony_ci */
1228c2ecf20Sopenharmony_ci#define EEH_DEV_BRIDGE		(1 << 0)	/* PCI bridge		*/
1238c2ecf20Sopenharmony_ci#define EEH_DEV_ROOT_PORT	(1 << 1)	/* PCIe root port	*/
1248c2ecf20Sopenharmony_ci#define EEH_DEV_DS_PORT		(1 << 2)	/* Downstream port	*/
1258c2ecf20Sopenharmony_ci#define EEH_DEV_IRQ_DISABLED	(1 << 3)	/* Interrupt disabled	*/
1268c2ecf20Sopenharmony_ci#define EEH_DEV_DISCONNECTED	(1 << 4)	/* Removing from PE	*/
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#define EEH_DEV_NO_HANDLER	(1 << 8)	/* No error handler	*/
1298c2ecf20Sopenharmony_ci#define EEH_DEV_SYSFS		(1 << 9)	/* Sysfs created	*/
1308c2ecf20Sopenharmony_ci#define EEH_DEV_REMOVED		(1 << 10)	/* Removed permanently	*/
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistruct eeh_dev {
1338c2ecf20Sopenharmony_ci	int mode;			/* EEH mode			*/
1348c2ecf20Sopenharmony_ci	int bdfn;			/* bdfn of device (for cfg ops) */
1358c2ecf20Sopenharmony_ci	struct pci_controller *controller;
1368c2ecf20Sopenharmony_ci	int pe_config_addr;		/* PE config address		*/
1378c2ecf20Sopenharmony_ci	u32 config_space[16];		/* Saved PCI config space	*/
1388c2ecf20Sopenharmony_ci	int pcix_cap;			/* Saved PCIx capability	*/
1398c2ecf20Sopenharmony_ci	int pcie_cap;			/* Saved PCIe capability	*/
1408c2ecf20Sopenharmony_ci	int aer_cap;			/* Saved AER capability		*/
1418c2ecf20Sopenharmony_ci	int af_cap;			/* Saved AF capability		*/
1428c2ecf20Sopenharmony_ci	struct eeh_pe *pe;		/* Associated PE		*/
1438c2ecf20Sopenharmony_ci	struct list_head entry;		/* Membership in eeh_pe.edevs	*/
1448c2ecf20Sopenharmony_ci	struct list_head rmv_entry;	/* Membership in rmv_list	*/
1458c2ecf20Sopenharmony_ci	struct pci_dn *pdn;		/* Associated PCI device node	*/
1468c2ecf20Sopenharmony_ci	struct pci_dev *pdev;		/* Associated PCI device	*/
1478c2ecf20Sopenharmony_ci	bool in_error;			/* Error flag for edev		*/
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci	/* VF specific properties */
1508c2ecf20Sopenharmony_ci	struct pci_dev *physfn;		/* Associated SRIOV PF		*/
1518c2ecf20Sopenharmony_ci	int vf_index;			/* Index of this VF 		*/
1528c2ecf20Sopenharmony_ci};
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci/* "fmt" must be a simple literal string */
1558c2ecf20Sopenharmony_ci#define EEH_EDEV_PRINT(level, edev, fmt, ...) \
1568c2ecf20Sopenharmony_ci	pr_##level("PCI %04x:%02x:%02x.%x#%04x: EEH: " fmt, \
1578c2ecf20Sopenharmony_ci	(edev)->controller->global_number, PCI_BUSNO((edev)->bdfn), \
1588c2ecf20Sopenharmony_ci	PCI_SLOT((edev)->bdfn), PCI_FUNC((edev)->bdfn), \
1598c2ecf20Sopenharmony_ci	((edev)->pe ? (edev)->pe_config_addr : 0xffff), ##__VA_ARGS__)
1608c2ecf20Sopenharmony_ci#define eeh_edev_dbg(edev, fmt, ...) EEH_EDEV_PRINT(debug, (edev), fmt, ##__VA_ARGS__)
1618c2ecf20Sopenharmony_ci#define eeh_edev_info(edev, fmt, ...) EEH_EDEV_PRINT(info, (edev), fmt, ##__VA_ARGS__)
1628c2ecf20Sopenharmony_ci#define eeh_edev_warn(edev, fmt, ...) EEH_EDEV_PRINT(warn, (edev), fmt, ##__VA_ARGS__)
1638c2ecf20Sopenharmony_ci#define eeh_edev_err(edev, fmt, ...) EEH_EDEV_PRINT(err, (edev), fmt, ##__VA_ARGS__)
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistatic inline struct pci_dn *eeh_dev_to_pdn(struct eeh_dev *edev)
1668c2ecf20Sopenharmony_ci{
1678c2ecf20Sopenharmony_ci	return edev ? edev->pdn : NULL;
1688c2ecf20Sopenharmony_ci}
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_cistatic inline struct pci_dev *eeh_dev_to_pci_dev(struct eeh_dev *edev)
1718c2ecf20Sopenharmony_ci{
1728c2ecf20Sopenharmony_ci	return edev ? edev->pdev : NULL;
1738c2ecf20Sopenharmony_ci}
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_cistatic inline struct eeh_pe *eeh_dev_to_pe(struct eeh_dev* edev)
1768c2ecf20Sopenharmony_ci{
1778c2ecf20Sopenharmony_ci	return edev ? edev->pe : NULL;
1788c2ecf20Sopenharmony_ci}
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci/* Return values from eeh_ops::next_error */
1818c2ecf20Sopenharmony_cienum {
1828c2ecf20Sopenharmony_ci	EEH_NEXT_ERR_NONE = 0,
1838c2ecf20Sopenharmony_ci	EEH_NEXT_ERR_INF,
1848c2ecf20Sopenharmony_ci	EEH_NEXT_ERR_FROZEN_PE,
1858c2ecf20Sopenharmony_ci	EEH_NEXT_ERR_FENCED_PHB,
1868c2ecf20Sopenharmony_ci	EEH_NEXT_ERR_DEAD_PHB,
1878c2ecf20Sopenharmony_ci	EEH_NEXT_ERR_DEAD_IOC
1888c2ecf20Sopenharmony_ci};
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci/*
1918c2ecf20Sopenharmony_ci * The struct is used to trace the registered EEH operation
1928c2ecf20Sopenharmony_ci * callback functions. Actually, those operation callback
1938c2ecf20Sopenharmony_ci * functions are heavily platform dependent. That means the
1948c2ecf20Sopenharmony_ci * platform should register its own EEH operation callback
1958c2ecf20Sopenharmony_ci * functions before any EEH further operations.
1968c2ecf20Sopenharmony_ci */
1978c2ecf20Sopenharmony_ci#define EEH_OPT_DISABLE		0	/* EEH disable	*/
1988c2ecf20Sopenharmony_ci#define EEH_OPT_ENABLE		1	/* EEH enable	*/
1998c2ecf20Sopenharmony_ci#define EEH_OPT_THAW_MMIO	2	/* MMIO enable	*/
2008c2ecf20Sopenharmony_ci#define EEH_OPT_THAW_DMA	3	/* DMA enable	*/
2018c2ecf20Sopenharmony_ci#define EEH_OPT_FREEZE_PE	4	/* Freeze PE	*/
2028c2ecf20Sopenharmony_ci#define EEH_STATE_UNAVAILABLE	(1 << 0)	/* State unavailable	*/
2038c2ecf20Sopenharmony_ci#define EEH_STATE_NOT_SUPPORT	(1 << 1)	/* EEH not supported	*/
2048c2ecf20Sopenharmony_ci#define EEH_STATE_RESET_ACTIVE	(1 << 2)	/* Active reset		*/
2058c2ecf20Sopenharmony_ci#define EEH_STATE_MMIO_ACTIVE	(1 << 3)	/* Active MMIO		*/
2068c2ecf20Sopenharmony_ci#define EEH_STATE_DMA_ACTIVE	(1 << 4)	/* Active DMA		*/
2078c2ecf20Sopenharmony_ci#define EEH_STATE_MMIO_ENABLED	(1 << 5)	/* MMIO enabled		*/
2088c2ecf20Sopenharmony_ci#define EEH_STATE_DMA_ENABLED	(1 << 6)	/* DMA enabled		*/
2098c2ecf20Sopenharmony_ci#define EEH_RESET_DEACTIVATE	0	/* Deactivate the PE reset	*/
2108c2ecf20Sopenharmony_ci#define EEH_RESET_HOT		1	/* Hot reset			*/
2118c2ecf20Sopenharmony_ci#define EEH_RESET_FUNDAMENTAL	3	/* Fundamental reset		*/
2128c2ecf20Sopenharmony_ci#define EEH_LOG_TEMP		1	/* EEH temporary error log	*/
2138c2ecf20Sopenharmony_ci#define EEH_LOG_PERM		2	/* EEH permanent error log	*/
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_cistruct eeh_ops {
2168c2ecf20Sopenharmony_ci	char *name;
2178c2ecf20Sopenharmony_ci	struct eeh_dev *(*probe)(struct pci_dev *pdev);
2188c2ecf20Sopenharmony_ci	int (*set_option)(struct eeh_pe *pe, int option);
2198c2ecf20Sopenharmony_ci	int (*get_state)(struct eeh_pe *pe, int *delay);
2208c2ecf20Sopenharmony_ci	int (*reset)(struct eeh_pe *pe, int option);
2218c2ecf20Sopenharmony_ci	int (*get_log)(struct eeh_pe *pe, int severity, char *drv_log, unsigned long len);
2228c2ecf20Sopenharmony_ci	int (*configure_bridge)(struct eeh_pe *pe);
2238c2ecf20Sopenharmony_ci	int (*err_inject)(struct eeh_pe *pe, int type, int func,
2248c2ecf20Sopenharmony_ci			  unsigned long addr, unsigned long mask);
2258c2ecf20Sopenharmony_ci	int (*read_config)(struct eeh_dev *edev, int where, int size, u32 *val);
2268c2ecf20Sopenharmony_ci	int (*write_config)(struct eeh_dev *edev, int where, int size, u32 val);
2278c2ecf20Sopenharmony_ci	int (*next_error)(struct eeh_pe **pe);
2288c2ecf20Sopenharmony_ci	int (*restore_config)(struct eeh_dev *edev);
2298c2ecf20Sopenharmony_ci	int (*notify_resume)(struct eeh_dev *edev);
2308c2ecf20Sopenharmony_ci};
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ciextern int eeh_subsystem_flags;
2338c2ecf20Sopenharmony_ciextern u32 eeh_max_freezes;
2348c2ecf20Sopenharmony_ciextern bool eeh_debugfs_no_recover;
2358c2ecf20Sopenharmony_ciextern struct eeh_ops *eeh_ops;
2368c2ecf20Sopenharmony_ciextern raw_spinlock_t confirm_error_lock;
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_cistatic inline void eeh_add_flag(int flag)
2398c2ecf20Sopenharmony_ci{
2408c2ecf20Sopenharmony_ci	eeh_subsystem_flags |= flag;
2418c2ecf20Sopenharmony_ci}
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_cistatic inline void eeh_clear_flag(int flag)
2448c2ecf20Sopenharmony_ci{
2458c2ecf20Sopenharmony_ci	eeh_subsystem_flags &= ~flag;
2468c2ecf20Sopenharmony_ci}
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_cistatic inline bool eeh_has_flag(int flag)
2498c2ecf20Sopenharmony_ci{
2508c2ecf20Sopenharmony_ci        return !!(eeh_subsystem_flags & flag);
2518c2ecf20Sopenharmony_ci}
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_cistatic inline bool eeh_enabled(void)
2548c2ecf20Sopenharmony_ci{
2558c2ecf20Sopenharmony_ci	return eeh_has_flag(EEH_ENABLED) && !eeh_has_flag(EEH_FORCE_DISABLED);
2568c2ecf20Sopenharmony_ci}
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_cistatic inline void eeh_serialize_lock(unsigned long *flags)
2598c2ecf20Sopenharmony_ci{
2608c2ecf20Sopenharmony_ci	raw_spin_lock_irqsave(&confirm_error_lock, *flags);
2618c2ecf20Sopenharmony_ci}
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_cistatic inline void eeh_serialize_unlock(unsigned long flags)
2648c2ecf20Sopenharmony_ci{
2658c2ecf20Sopenharmony_ci	raw_spin_unlock_irqrestore(&confirm_error_lock, flags);
2668c2ecf20Sopenharmony_ci}
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_cistatic inline bool eeh_state_active(int state)
2698c2ecf20Sopenharmony_ci{
2708c2ecf20Sopenharmony_ci	return (state & (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE))
2718c2ecf20Sopenharmony_ci	== (EEH_STATE_MMIO_ACTIVE | EEH_STATE_DMA_ACTIVE);
2728c2ecf20Sopenharmony_ci}
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_citypedef void (*eeh_edev_traverse_func)(struct eeh_dev *edev, void *flag);
2758c2ecf20Sopenharmony_citypedef void *(*eeh_pe_traverse_func)(struct eeh_pe *pe, void *flag);
2768c2ecf20Sopenharmony_civoid eeh_set_pe_aux_size(int size);
2778c2ecf20Sopenharmony_ciint eeh_phb_pe_create(struct pci_controller *phb);
2788c2ecf20Sopenharmony_ciint eeh_wait_state(struct eeh_pe *pe, int max_wait);
2798c2ecf20Sopenharmony_cistruct eeh_pe *eeh_phb_pe_get(struct pci_controller *phb);
2808c2ecf20Sopenharmony_cistruct eeh_pe *eeh_pe_next(struct eeh_pe *pe, struct eeh_pe *root);
2818c2ecf20Sopenharmony_cistruct eeh_pe *eeh_pe_get(struct pci_controller *phb, int pe_no);
2828c2ecf20Sopenharmony_ciint eeh_pe_tree_insert(struct eeh_dev *edev, struct eeh_pe *new_pe_parent);
2838c2ecf20Sopenharmony_ciint eeh_pe_tree_remove(struct eeh_dev *edev);
2848c2ecf20Sopenharmony_civoid eeh_pe_update_time_stamp(struct eeh_pe *pe);
2858c2ecf20Sopenharmony_civoid *eeh_pe_traverse(struct eeh_pe *root,
2868c2ecf20Sopenharmony_ci		      eeh_pe_traverse_func fn, void *flag);
2878c2ecf20Sopenharmony_civoid eeh_pe_dev_traverse(struct eeh_pe *root,
2888c2ecf20Sopenharmony_ci			 eeh_edev_traverse_func fn, void *flag);
2898c2ecf20Sopenharmony_civoid eeh_pe_restore_bars(struct eeh_pe *pe);
2908c2ecf20Sopenharmony_ciconst char *eeh_pe_loc_get(struct eeh_pe *pe);
2918c2ecf20Sopenharmony_cistruct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe);
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_civoid eeh_show_enabled(void);
2948c2ecf20Sopenharmony_ciint __init eeh_init(struct eeh_ops *ops);
2958c2ecf20Sopenharmony_ciint eeh_check_failure(const volatile void __iomem *token);
2968c2ecf20Sopenharmony_ciint eeh_dev_check_failure(struct eeh_dev *edev);
2978c2ecf20Sopenharmony_civoid eeh_addr_cache_init(void);
2988c2ecf20Sopenharmony_civoid eeh_probe_device(struct pci_dev *pdev);
2998c2ecf20Sopenharmony_civoid eeh_remove_device(struct pci_dev *);
3008c2ecf20Sopenharmony_ciint eeh_unfreeze_pe(struct eeh_pe *pe);
3018c2ecf20Sopenharmony_ciint eeh_pe_reset_and_recover(struct eeh_pe *pe);
3028c2ecf20Sopenharmony_ciint eeh_dev_open(struct pci_dev *pdev);
3038c2ecf20Sopenharmony_civoid eeh_dev_release(struct pci_dev *pdev);
3048c2ecf20Sopenharmony_cistruct eeh_pe *eeh_iommu_group_to_pe(struct iommu_group *group);
3058c2ecf20Sopenharmony_ciint eeh_pe_set_option(struct eeh_pe *pe, int option);
3068c2ecf20Sopenharmony_ciint eeh_pe_get_state(struct eeh_pe *pe);
3078c2ecf20Sopenharmony_ciint eeh_pe_reset(struct eeh_pe *pe, int option, bool include_passed);
3088c2ecf20Sopenharmony_ciint eeh_pe_configure(struct eeh_pe *pe);
3098c2ecf20Sopenharmony_ciint eeh_pe_inject_err(struct eeh_pe *pe, int type, int func,
3108c2ecf20Sopenharmony_ci		      unsigned long addr, unsigned long mask);
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci/**
3138c2ecf20Sopenharmony_ci * EEH_POSSIBLE_ERROR() -- test for possible MMIO failure.
3148c2ecf20Sopenharmony_ci *
3158c2ecf20Sopenharmony_ci * If this macro yields TRUE, the caller relays to eeh_check_failure()
3168c2ecf20Sopenharmony_ci * which does further tests out of line.
3178c2ecf20Sopenharmony_ci */
3188c2ecf20Sopenharmony_ci#define EEH_POSSIBLE_ERROR(val, type)	((val) == (type)~0 && eeh_enabled())
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci/*
3218c2ecf20Sopenharmony_ci * Reads from a device which has been isolated by EEH will return
3228c2ecf20Sopenharmony_ci * all 1s.  This macro gives an all-1s value of the given size (in
3238c2ecf20Sopenharmony_ci * bytes: 1, 2, or 4) for comparing with the result of a read.
3248c2ecf20Sopenharmony_ci */
3258c2ecf20Sopenharmony_ci#define EEH_IO_ERROR_VALUE(size)	(~0U >> ((4 - (size)) * 8))
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci#else /* !CONFIG_EEH */
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_cistatic inline bool eeh_enabled(void)
3308c2ecf20Sopenharmony_ci{
3318c2ecf20Sopenharmony_ci        return false;
3328c2ecf20Sopenharmony_ci}
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_cistatic inline void eeh_show_enabled(void) { }
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_cistatic inline void eeh_dev_phb_init_dynamic(struct pci_controller *phb) { }
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_cistatic inline int eeh_check_failure(const volatile void __iomem *token)
3398c2ecf20Sopenharmony_ci{
3408c2ecf20Sopenharmony_ci	return 0;
3418c2ecf20Sopenharmony_ci}
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci#define eeh_dev_check_failure(x) (0)
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_cistatic inline void eeh_addr_cache_init(void) { }
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_cistatic inline void eeh_probe_device(struct pci_dev *dev) { }
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_cistatic inline void eeh_remove_device(struct pci_dev *dev) { }
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci#define EEH_POSSIBLE_ERROR(val, type) (0)
3528c2ecf20Sopenharmony_ci#define EEH_IO_ERROR_VALUE(size) (-1UL)
3538c2ecf20Sopenharmony_cistatic inline int eeh_phb_pe_create(struct pci_controller *phb) { return 0; }
3548c2ecf20Sopenharmony_ci#endif /* CONFIG_EEH */
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci#if defined(CONFIG_PPC_PSERIES) && defined(CONFIG_EEH)
3578c2ecf20Sopenharmony_civoid pseries_eeh_init_edev(struct pci_dn *pdn);
3588c2ecf20Sopenharmony_civoid pseries_eeh_init_edev_recursive(struct pci_dn *pdn);
3598c2ecf20Sopenharmony_ci#else
3608c2ecf20Sopenharmony_cistatic inline void pseries_eeh_add_device_early(struct pci_dn *pdn) { }
3618c2ecf20Sopenharmony_cistatic inline void pseries_eeh_add_device_tree_early(struct pci_dn *pdn) { }
3628c2ecf20Sopenharmony_ci#endif
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC64
3658c2ecf20Sopenharmony_ci/*
3668c2ecf20Sopenharmony_ci * MMIO read/write operations with EEH support.
3678c2ecf20Sopenharmony_ci */
3688c2ecf20Sopenharmony_cistatic inline u8 eeh_readb(const volatile void __iomem *addr)
3698c2ecf20Sopenharmony_ci{
3708c2ecf20Sopenharmony_ci	u8 val = in_8(addr);
3718c2ecf20Sopenharmony_ci	if (EEH_POSSIBLE_ERROR(val, u8))
3728c2ecf20Sopenharmony_ci		eeh_check_failure(addr);
3738c2ecf20Sopenharmony_ci	return val;
3748c2ecf20Sopenharmony_ci}
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_cistatic inline u16 eeh_readw(const volatile void __iomem *addr)
3778c2ecf20Sopenharmony_ci{
3788c2ecf20Sopenharmony_ci	u16 val = in_le16(addr);
3798c2ecf20Sopenharmony_ci	if (EEH_POSSIBLE_ERROR(val, u16))
3808c2ecf20Sopenharmony_ci		eeh_check_failure(addr);
3818c2ecf20Sopenharmony_ci	return val;
3828c2ecf20Sopenharmony_ci}
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_cistatic inline u32 eeh_readl(const volatile void __iomem *addr)
3858c2ecf20Sopenharmony_ci{
3868c2ecf20Sopenharmony_ci	u32 val = in_le32(addr);
3878c2ecf20Sopenharmony_ci	if (EEH_POSSIBLE_ERROR(val, u32))
3888c2ecf20Sopenharmony_ci		eeh_check_failure(addr);
3898c2ecf20Sopenharmony_ci	return val;
3908c2ecf20Sopenharmony_ci}
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_cistatic inline u64 eeh_readq(const volatile void __iomem *addr)
3938c2ecf20Sopenharmony_ci{
3948c2ecf20Sopenharmony_ci	u64 val = in_le64(addr);
3958c2ecf20Sopenharmony_ci	if (EEH_POSSIBLE_ERROR(val, u64))
3968c2ecf20Sopenharmony_ci		eeh_check_failure(addr);
3978c2ecf20Sopenharmony_ci	return val;
3988c2ecf20Sopenharmony_ci}
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_cistatic inline u16 eeh_readw_be(const volatile void __iomem *addr)
4018c2ecf20Sopenharmony_ci{
4028c2ecf20Sopenharmony_ci	u16 val = in_be16(addr);
4038c2ecf20Sopenharmony_ci	if (EEH_POSSIBLE_ERROR(val, u16))
4048c2ecf20Sopenharmony_ci		eeh_check_failure(addr);
4058c2ecf20Sopenharmony_ci	return val;
4068c2ecf20Sopenharmony_ci}
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_cistatic inline u32 eeh_readl_be(const volatile void __iomem *addr)
4098c2ecf20Sopenharmony_ci{
4108c2ecf20Sopenharmony_ci	u32 val = in_be32(addr);
4118c2ecf20Sopenharmony_ci	if (EEH_POSSIBLE_ERROR(val, u32))
4128c2ecf20Sopenharmony_ci		eeh_check_failure(addr);
4138c2ecf20Sopenharmony_ci	return val;
4148c2ecf20Sopenharmony_ci}
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_cistatic inline u64 eeh_readq_be(const volatile void __iomem *addr)
4178c2ecf20Sopenharmony_ci{
4188c2ecf20Sopenharmony_ci	u64 val = in_be64(addr);
4198c2ecf20Sopenharmony_ci	if (EEH_POSSIBLE_ERROR(val, u64))
4208c2ecf20Sopenharmony_ci		eeh_check_failure(addr);
4218c2ecf20Sopenharmony_ci	return val;
4228c2ecf20Sopenharmony_ci}
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_cistatic inline void eeh_memcpy_fromio(void *dest, const
4258c2ecf20Sopenharmony_ci				     volatile void __iomem *src,
4268c2ecf20Sopenharmony_ci				     unsigned long n)
4278c2ecf20Sopenharmony_ci{
4288c2ecf20Sopenharmony_ci	_memcpy_fromio(dest, src, n);
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci	/* Look for ffff's here at dest[n].  Assume that at least 4 bytes
4318c2ecf20Sopenharmony_ci	 * were copied. Check all four bytes.
4328c2ecf20Sopenharmony_ci	 */
4338c2ecf20Sopenharmony_ci	if (n >= 4 && EEH_POSSIBLE_ERROR(*((u32 *)(dest + n - 4)), u32))
4348c2ecf20Sopenharmony_ci		eeh_check_failure(src);
4358c2ecf20Sopenharmony_ci}
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci/* in-string eeh macros */
4388c2ecf20Sopenharmony_cistatic inline void eeh_readsb(const volatile void __iomem *addr, void * buf,
4398c2ecf20Sopenharmony_ci			      int ns)
4408c2ecf20Sopenharmony_ci{
4418c2ecf20Sopenharmony_ci	_insb(addr, buf, ns);
4428c2ecf20Sopenharmony_ci	if (EEH_POSSIBLE_ERROR((*(((u8*)buf)+ns-1)), u8))
4438c2ecf20Sopenharmony_ci		eeh_check_failure(addr);
4448c2ecf20Sopenharmony_ci}
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_cistatic inline void eeh_readsw(const volatile void __iomem *addr, void * buf,
4478c2ecf20Sopenharmony_ci			      int ns)
4488c2ecf20Sopenharmony_ci{
4498c2ecf20Sopenharmony_ci	_insw(addr, buf, ns);
4508c2ecf20Sopenharmony_ci	if (EEH_POSSIBLE_ERROR((*(((u16*)buf)+ns-1)), u16))
4518c2ecf20Sopenharmony_ci		eeh_check_failure(addr);
4528c2ecf20Sopenharmony_ci}
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_cistatic inline void eeh_readsl(const volatile void __iomem *addr, void * buf,
4558c2ecf20Sopenharmony_ci			      int nl)
4568c2ecf20Sopenharmony_ci{
4578c2ecf20Sopenharmony_ci	_insl(addr, buf, nl);
4588c2ecf20Sopenharmony_ci	if (EEH_POSSIBLE_ERROR((*(((u32*)buf)+nl-1)), u32))
4598c2ecf20Sopenharmony_ci		eeh_check_failure(addr);
4608c2ecf20Sopenharmony_ci}
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_civoid eeh_cache_debugfs_init(void);
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci#endif /* CONFIG_PPC64 */
4668c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
4678c2ecf20Sopenharmony_ci#endif /* _POWERPC_EEH_H */
468