xref: /onnv-gate/usr/src/uts/common/sys/pcie_impl.h (revision 11596:e9010337bcd3)
127Sjchu /*
227Sjchu  * CDDL HEADER START
327Sjchu  *
427Sjchu  * The contents of this file are subject to the terms of the
52549Sgovinda  * Common Development and Distribution License (the "License").
62549Sgovinda  * You may not use this file except in compliance with the License.
727Sjchu  *
827Sjchu  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
927Sjchu  * or http://www.opensolaris.org/os/licensing.
1027Sjchu  * See the License for the specific language governing permissions
1127Sjchu  * and limitations under the License.
1227Sjchu  *
1327Sjchu  * When distributing Covered Code, include this CDDL HEADER in each
1427Sjchu  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1527Sjchu  * If applicable, add the following below this CDDL HEADER, with the
1627Sjchu  * fields enclosed by brackets "[]" replaced with your own identifying
1727Sjchu  * information: Portions Copyright [yyyy] [name of copyright owner]
1827Sjchu  *
1927Sjchu  * CDDL HEADER END
2027Sjchu  */
2127Sjchu /*
2211445SEvan.Yan@Sun.COM  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
2327Sjchu  * Use is subject to license terms.
2427Sjchu  */
2527Sjchu 
2627Sjchu #ifndef	_SYS_PCIE_IMPL_H
2727Sjchu #define	_SYS_PCIE_IMPL_H
2827Sjchu 
2927Sjchu #ifdef	__cplusplus
3027Sjchu extern "C" {
3127Sjchu #endif
3227Sjchu 
333274Set142600 #include <sys/pcie.h>
34*11596SJason.Beloro@Sun.COM #include <sys/pciev.h>
353274Set142600 
366313Skrishnae #define	PCI_GET_BDF(dip)	\
376313Skrishnae 	PCIE_DIP2BUS(dip)->bus_bdf
386313Skrishnae #define	PCI_GET_SEC_BUS(dip)	\
396313Skrishnae 	PCIE_DIP2BUS(dip)->bus_bdg_secbus
406313Skrishnae #define	PCI_GET_PCIE2PCI_SECBUS(dip) \
4110187SKrishna.Elango@Sun.COM 	PCIE_DIP2BUS(dip)->bus_bdg_secbus
423274Set142600 
436313Skrishnae #define	DEVI_PORT_TYPE_PCI \
446313Skrishnae 	((PCI_CLASS_BRIDGE << 16) | (PCI_BRIDGE_PCI << 8) | \
456313Skrishnae 	PCI_BRIDGE_PCI_IF_PCI2PCI)
463274Set142600 
476313Skrishnae #define	PCIE_DIP2BUS(dip) \
486313Skrishnae 	(ndi_port_type(dip, B_TRUE, DEVI_PORT_TYPE_PCI) ? \
496313Skrishnae 	PCIE_DIP2UPBUS(dip) : \
506313Skrishnae 	ndi_port_type(dip, B_FALSE, DEVI_PORT_TYPE_PCI) ? \
516313Skrishnae 	PCIE_DIP2DOWNBUS(dip) : NULL)
523274Set142600 
536313Skrishnae #define	PCIE_DIP2UPBUS(dip) \
546313Skrishnae 	((pcie_bus_t *)ndi_get_bus_private(dip, B_TRUE))
556313Skrishnae #define	PCIE_DIP2DOWNBUS(dip) \
566313Skrishnae 	((pcie_bus_t *)ndi_get_bus_private(dip, B_FALSE))
576313Skrishnae #define	PCIE_DIP2PFD(dip) (PCIE_DIP2BUS(dip))->bus_pfd
586313Skrishnae #define	PCIE_PFD2BUS(pfd_p) pfd_p->pe_bus_p
596313Skrishnae #define	PCIE_PFD2DIP(pfd_p) PCIE_PFD2BUS(pfd_p)->bus_dip
606313Skrishnae #define	PCIE_BUS2DIP(bus_p) bus_p->bus_dip
616313Skrishnae #define	PCIE_BUS2PFD(bus_p) PCIE_DIP2PFD(PCIE_BUS2DIP(bus_p))
62*11596SJason.Beloro@Sun.COM #define	PCIE_BUS2DOM(bus_p) bus_p->bus_dom
63*11596SJason.Beloro@Sun.COM #define	PCIE_DIP2DOM(dip) PCIE_BUS2DOM(PCIE_DIP2BUS(dip))
643274Set142600 
6511245SZhijun.Fu@Sun.COM /*
6611245SZhijun.Fu@Sun.COM  * These macros depend on initialization of type related data in bus_p.
6711245SZhijun.Fu@Sun.COM  */
686313Skrishnae #define	PCIE_IS_PCIE(bus_p) (bus_p->bus_pcie_off)
696313Skrishnae #define	PCIE_IS_PCIX(bus_p) (bus_p->bus_pcix_off)
709921SKrishna.Elango@Sun.COM #define	PCIE_IS_PCI(bus_p) (!PCIE_IS_PCIE(bus_p))
716313Skrishnae #define	PCIE_HAS_AER(bus_p) (bus_p->bus_aer_off)
726313Skrishnae /* IS_ROOT = is RC or RP */
736313Skrishnae #define	PCIE_IS_ROOT(bus_p) (PCIE_IS_RC(bus_p) || PCIE_IS_RP(bus_p))
7410923SEvan.Yan@Sun.COM 
7510923SEvan.Yan@Sun.COM #define	PCIE_IS_HOTPLUG_CAPABLE(dip) \
7610923SEvan.Yan@Sun.COM 	(PCIE_DIP2BUS(dip)->bus_hp_sup_modes)
7710923SEvan.Yan@Sun.COM 
7810923SEvan.Yan@Sun.COM #define	PCIE_IS_HOTPLUG_ENABLED(dip) \
7910923SEvan.Yan@Sun.COM 	((PCIE_DIP2BUS(dip)->bus_hp_curr_mode == PCIE_PCI_HP_MODE) || \
8010923SEvan.Yan@Sun.COM 	(PCIE_DIP2BUS(dip)->bus_hp_curr_mode == PCIE_NATIVE_HP_MODE))
8110923SEvan.Yan@Sun.COM 
826313Skrishnae /*
836313Skrishnae  * This is a pseudo pcie "device type", but it's needed to explain describe
846313Skrishnae  * nodes such as PX and NPE, which aren't really PCI devices but do control or
856313Skrishnae  * interaction with PCI error handling.
866313Skrishnae  */
876313Skrishnae #define	PCIE_IS_RC(bus_p) \
886313Skrishnae 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_RC_PSEUDO)
896313Skrishnae #define	PCIE_IS_RP(bus_p) \
906313Skrishnae 	((bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_ROOT) && \
916313Skrishnae 	    PCIE_IS_PCIE(bus_p))
929921SKrishna.Elango@Sun.COM #define	PCIE_IS_SWU(bus_p) \
939921SKrishna.Elango@Sun.COM 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_UP)
949921SKrishna.Elango@Sun.COM #define	PCIE_IS_SWD(bus_p) \
959921SKrishna.Elango@Sun.COM 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_DOWN)
966313Skrishnae #define	PCIE_IS_SW(bus_p) \
979921SKrishna.Elango@Sun.COM 	(PCIE_IS_SWU(bus_p) || PCIE_IS_SWD(bus_p))
986313Skrishnae #define	PCIE_IS_BDG(bus_p)  (bus_p->bus_hdr_type == PCI_HEADER_ONE)
999921SKrishna.Elango@Sun.COM #define	PCIE_IS_PCI_BDG(bus_p) (PCIE_IS_PCI(bus_p) && PCIE_IS_BDG(bus_p))
1006313Skrishnae #define	PCIE_IS_PCIE_BDG(bus_p) \
1016313Skrishnae 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_PCIE2PCI)
1027987SErwin.Tsaur@Sun.COM #define	PCIE_IS_PCI2PCIE(bus_p) \
1037987SErwin.Tsaur@Sun.COM 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_PCI2PCIE)
1046313Skrishnae #define	PCIE_IS_PCIE_SEC(bus_p) \
1056313Skrishnae 	(PCIE_IS_PCIE(bus_p) && PCIE_IS_BDG(bus_p) && !PCIE_IS_PCIE_BDG(bus_p))
1066313Skrishnae #define	PCIX_ECC_VERSION_CHECK(bus_p) \
1076313Skrishnae 	((bus_p->bus_ecc_ver == PCI_PCIX_VER_1) || \
1086313Skrishnae 	    (bus_p->bus_ecc_ver == PCI_PCIX_VER_2))
1093274Set142600 
1106313Skrishnae #define	PCIE_VENID(bus_p)	(bus_p->bus_dev_ven_id & 0xffff)
1116313Skrishnae #define	PCIE_DEVID(bus_p)	((bus_p->bus_dev_ven_id >> 16) & 0xffff)
1123274Set142600 
1136313Skrishnae /* PCIE Cap/AER shortcuts */
1146313Skrishnae #define	PCIE_GET(sz, bus_p, off) \
1156313Skrishnae 	pci_config_get ## sz(bus_p->bus_cfg_hdl, off)
1166313Skrishnae #define	PCIE_PUT(sz, bus_p, off, val) \
1176313Skrishnae 	pci_config_put ## sz(bus_p->bus_cfg_hdl, off, val)
1186313Skrishnae #define	PCIE_CAP_GET(sz, bus_p, off) \
1196313Skrishnae 	PCI_CAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcie_off, off)
1206313Skrishnae #define	PCIE_CAP_PUT(sz, bus_p, off, val) \
1216313Skrishnae 	PCI_CAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcie_off, off, \
1226313Skrishnae 	    val)
1236313Skrishnae #define	PCIE_AER_GET(sz, bus_p, off) \
1246313Skrishnae 	PCI_XCAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_aer_off, off)
1256313Skrishnae #define	PCIE_AER_PUT(sz, bus_p, off, val) \
1266313Skrishnae 	PCI_XCAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_aer_off, off, \
1276313Skrishnae 	    val)
1286313Skrishnae #define	PCIX_CAP_GET(sz, bus_p, off) \
1296313Skrishnae 	PCI_CAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcix_off, off)
1306313Skrishnae #define	PCIX_CAP_PUT(sz, bus_p, off, val) \
1316313Skrishnae 	PCI_CAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcix_off, off, \
1326313Skrishnae 	    val)
1333274Set142600 
1346313Skrishnae /* Translate PF error return values to DDI_FM values */
1356313Skrishnae #define	PF_ERR2DDIFM_ERR(sts) \
1366313Skrishnae 	(sts & PF_ERR_FATAL_FLAGS ? DDI_FM_FATAL :	\
1376313Skrishnae 	(sts == PF_ERR_NO_ERROR ? DDI_FM_OK : DDI_FM_NONFATAL))
1383274Set142600 
13927Sjchu /*
1402549Sgovinda  * The following flag is used for Broadcom 5714/5715 bridge prefetch issue.
14110187SKrishna.Elango@Sun.COM  * This flag will be used both by px and pcieb nexus drivers.
1422549Sgovinda  */
1432549Sgovinda #define	PX_DMAI_FLAGS_MAP_BUFZONE	0x40000
1442549Sgovinda 
1456313Skrishnae /*
1466313Skrishnae  * PCI(e/-X) structures used to to gather and report errors detected by
1476313Skrishnae  * PCI(e/-X) compliant devices.  These registers only contain "dynamic" data.
1486313Skrishnae  * Static data such as Capability Offsets and Version #s is saved in the parent
1496313Skrishnae  * private data.
1506313Skrishnae  */
1516313Skrishnae #define	PCI_ERR_REG(pfd_p)	   pfd_p->pe_pci_regs
1526313Skrishnae #define	PCI_BDG_ERR_REG(pfd_p)	   PCI_ERR_REG(pfd_p)->pci_bdg_regs
1536313Skrishnae #define	PCIX_ERR_REG(pfd_p)	   pfd_p->pe_ext.pe_pcix_regs
1546313Skrishnae #define	PCIX_ECC_REG(pfd_p)	   PCIX_ERR_REG(pfd_p)->pcix_ecc_regs
1556313Skrishnae #define	PCIX_BDG_ERR_REG(pfd_p)	   pfd_p->pe_pcix_bdg_regs
1566313Skrishnae #define	PCIX_BDG_ECC_REG(pfd_p, n) PCIX_BDG_ERR_REG(pfd_p)->pcix_bdg_ecc_regs[n]
1576313Skrishnae #define	PCIE_ERR_REG(pfd_p)	   pfd_p->pe_ext.pe_pcie_regs
1586313Skrishnae #define	PCIE_RP_REG(pfd_p)	   PCIE_ERR_REG(pfd_p)->pcie_rp_regs
1596313Skrishnae #define	PCIE_ROOT_FAULT(pfd_p)	   pfd_p->pe_root_fault
160*11596SJason.Beloro@Sun.COM #define	PCIE_ROOT_EH_SRC(pfd_p)    pfd_p->pe_root_eh_src
1616313Skrishnae #define	PCIE_ADV_REG(pfd_p)	   PCIE_ERR_REG(pfd_p)->pcie_adv_regs
1626313Skrishnae #define	PCIE_ADV_HDR(pfd_p, n)	   PCIE_ADV_REG(pfd_p)->pcie_ue_hdr[n]
1636313Skrishnae #define	PCIE_ADV_BDG_REG(pfd_p) \
1646313Skrishnae 	PCIE_ADV_REG(pfd_p)->pcie_ext.pcie_adv_bdg_regs
1656313Skrishnae #define	PCIE_ADV_BDG_HDR(pfd_p, n) PCIE_ADV_BDG_REG(pfd_p)->pcie_sue_hdr[n]
1666313Skrishnae #define	PCIE_ADV_RP_REG(pfd_p) \
1676313Skrishnae 	PCIE_ADV_REG(pfd_p)->pcie_ext.pcie_adv_rp_regs
168*11596SJason.Beloro@Sun.COM #define	PFD_AFFECTED_DEV(pfd_p)	   pfd_p->pe_affected_dev
169*11596SJason.Beloro@Sun.COM 
1706313Skrishnae #define	PFD_IS_ROOT(pfd_p)	   PCIE_IS_ROOT(PCIE_PFD2BUS(pfd_p))
1716313Skrishnae #define	PFD_IS_RC(pfd_p)	   PCIE_IS_RC(PCIE_PFD2BUS(pfd_p))
1726313Skrishnae #define	PFD_IS_RP(pfd_p)	   PCIE_IS_RP(PCIE_PFD2BUS(pfd_p))
1736313Skrishnae 
17410923SEvan.Yan@Sun.COM /* bus_hp_mode field */
17510923SEvan.Yan@Sun.COM typedef enum {
17610923SEvan.Yan@Sun.COM 	PCIE_NONE_HP_MODE	= 0x0,
17710923SEvan.Yan@Sun.COM 	PCIE_ACPI_HP_MODE	= 0x1,
17810923SEvan.Yan@Sun.COM 	PCIE_PCI_HP_MODE	= 0x2,
17910923SEvan.Yan@Sun.COM 	PCIE_NATIVE_HP_MODE	= 0x4
18010923SEvan.Yan@Sun.COM } pcie_hp_mode_t;
18110923SEvan.Yan@Sun.COM 
1826313Skrishnae typedef struct pf_pci_bdg_err_regs {
1836313Skrishnae 	uint16_t pci_bdg_sec_stat;	/* PCI secondary status reg */
1846313Skrishnae 	uint16_t pci_bdg_ctrl;		/* PCI bridge control reg */
1856313Skrishnae } pf_pci_bdg_err_regs_t;
1866313Skrishnae 
1876313Skrishnae typedef struct pf_pci_err_regs {
1886313Skrishnae 	uint16_t pci_err_status;	/* pci status register */
1896313Skrishnae 	uint16_t pci_cfg_comm;		/* pci command register */
1906313Skrishnae 	pf_pci_bdg_err_regs_t *pci_bdg_regs;
1916313Skrishnae } pf_pci_err_regs_t;
1926313Skrishnae 
1936313Skrishnae typedef struct pf_pcix_ecc_regs {
1946313Skrishnae 	uint32_t pcix_ecc_ctlstat;	/* pcix ecc control status reg */
1956313Skrishnae 	uint32_t pcix_ecc_fstaddr;	/* pcix ecc first address reg */
1966313Skrishnae 	uint32_t pcix_ecc_secaddr;	/* pcix ecc second address reg */
1976313Skrishnae 	uint32_t pcix_ecc_attr;		/* pcix ecc attributes reg */
1986313Skrishnae } pf_pcix_ecc_regs_t;
1993274Set142600 
2006313Skrishnae typedef struct pf_pcix_err_regs {
2016313Skrishnae 	uint16_t pcix_command;		/* pcix command register */
2026313Skrishnae 	uint32_t pcix_status;		/* pcix status register */
2036313Skrishnae 	pf_pcix_ecc_regs_t *pcix_ecc_regs;	/* pcix ecc registers */
2046313Skrishnae } pf_pcix_err_regs_t;
2056313Skrishnae 
2066313Skrishnae typedef struct pf_pcix_bdg_err_regs {
2076313Skrishnae 	uint16_t pcix_bdg_sec_stat;	/* pcix bridge secondary status reg */
2086313Skrishnae 	uint32_t pcix_bdg_stat;		/* pcix bridge status reg */
2096313Skrishnae 	pf_pcix_ecc_regs_t *pcix_bdg_ecc_regs[2];	/* pcix ecc registers */
2106313Skrishnae } pf_pcix_bdg_err_regs_t;
2116313Skrishnae 
2126313Skrishnae typedef struct pf_pcie_adv_bdg_err_regs {
2136313Skrishnae 	uint32_t pcie_sue_ctl;		/* pcie bridge secondary ue control */
2146313Skrishnae 	uint32_t pcie_sue_status;	/* pcie bridge secondary ue status */
2156313Skrishnae 	uint32_t pcie_sue_mask;		/* pcie bridge secondary ue mask */
2166313Skrishnae 	uint32_t pcie_sue_sev;		/* pcie bridge secondary ue severity */
2176313Skrishnae 	uint32_t pcie_sue_hdr[4];	/* pcie bridge secondary ue hdr log */
2186313Skrishnae 	uint32_t pcie_sue_tgt_trans;	/* Fault trans type from SAER Logs */
2196313Skrishnae 	uint64_t pcie_sue_tgt_addr;	/* Fault addr from SAER Logs */
2206313Skrishnae 	pcie_req_id_t pcie_sue_tgt_bdf;	/* Fault bdf from SAER Logs */
2216313Skrishnae } pf_pcie_adv_bdg_err_regs_t;
2223274Set142600 
2236313Skrishnae typedef struct pf_pcie_adv_rp_err_regs {
2246313Skrishnae 	uint32_t pcie_rp_err_status;	/* pcie root complex error status reg */
2256313Skrishnae 	uint32_t pcie_rp_err_cmd;	/* pcie root complex error cmd reg */
2266313Skrishnae 	uint16_t pcie_rp_ce_src_id;	/* pcie root complex ce sourpe id */
2276313Skrishnae 	uint16_t pcie_rp_ue_src_id;	/* pcie root complex ue sourpe id */
2286313Skrishnae } pf_pcie_adv_rp_err_regs_t;
2296313Skrishnae 
2306313Skrishnae typedef struct pf_pcie_adv_err_regs {
2316313Skrishnae 	uint32_t pcie_adv_ctl;		/* pcie advanced control reg */
2326313Skrishnae 	uint32_t pcie_ue_status;	/* pcie ue error status reg */
2336313Skrishnae 	uint32_t pcie_ue_mask;		/* pcie ue error mask reg */
2346313Skrishnae 	uint32_t pcie_ue_sev;		/* pcie ue error severity reg */
2356313Skrishnae 	uint32_t pcie_ue_hdr[4];	/* pcie ue header log */
2366313Skrishnae 	uint32_t pcie_ce_status;	/* pcie ce error status reg */
2376313Skrishnae 	uint32_t pcie_ce_mask;		/* pcie ce error mask reg */
2386313Skrishnae 	union {
2396313Skrishnae 		pf_pcie_adv_bdg_err_regs_t *pcie_adv_bdg_regs; /* bdg regs */
2406313Skrishnae 		pf_pcie_adv_rp_err_regs_t *pcie_adv_rp_regs;	 /* rp regs */
2416313Skrishnae 	} pcie_ext;
2426313Skrishnae 	uint32_t pcie_ue_tgt_trans;	/* Fault trans type from AER Logs */
2436313Skrishnae 	uint64_t pcie_ue_tgt_addr;	/* Fault addr from AER Logs */
2449921SKrishna.Elango@Sun.COM 	pcie_req_id_t pcie_ue_tgt_bdf;	/* Fault bdf from AER Logs */
2456313Skrishnae } pf_pcie_adv_err_regs_t;
2466313Skrishnae 
2476313Skrishnae typedef struct pf_pcie_rp_err_regs {
2486313Skrishnae 	uint32_t pcie_rp_status;	/* root complex status register */
2496313Skrishnae 	uint16_t pcie_rp_ctl;		/* root complex control register */
2506313Skrishnae } pf_pcie_rp_err_regs_t;
2513274Set142600 
2526313Skrishnae typedef struct pf_pcie_err_regs {
2536313Skrishnae 	uint16_t pcie_err_status;	/* pcie device status register */
2546313Skrishnae 	uint16_t pcie_err_ctl;		/* pcie error control register */
2556313Skrishnae 	uint32_t pcie_dev_cap;		/* pcie device capabilities register */
2566313Skrishnae 	pf_pcie_rp_err_regs_t *pcie_rp_regs;	 /* pcie root complex regs */
2576313Skrishnae 	pf_pcie_adv_err_regs_t *pcie_adv_regs; /* pcie aer regs */
2586313Skrishnae } pf_pcie_err_regs_t;
2596313Skrishnae 
260*11596SJason.Beloro@Sun.COM typedef enum {
261*11596SJason.Beloro@Sun.COM 	PF_INTR_TYPE_NONE = 0,
262*11596SJason.Beloro@Sun.COM 	PF_INTR_TYPE_FABRIC = 1,	/* Fabric Message */
263*11596SJason.Beloro@Sun.COM 	PF_INTR_TYPE_DATA,		/* Data Access Failure, failed loads */
264*11596SJason.Beloro@Sun.COM 	PF_INTR_TYPE_AER,		/* Root Port AER MSI */
265*11596SJason.Beloro@Sun.COM 	PF_INTR_TYPE_INTERNAL		/* Chip specific internal errors */
266*11596SJason.Beloro@Sun.COM } pf_intr_type_t;
267*11596SJason.Beloro@Sun.COM 
268*11596SJason.Beloro@Sun.COM typedef struct pf_root_eh_src {
269*11596SJason.Beloro@Sun.COM 	pf_intr_type_t	intr_type;
270*11596SJason.Beloro@Sun.COM 	void		*intr_data;	/* Interrupt Data */
271*11596SJason.Beloro@Sun.COM } pf_root_eh_src_t;
272*11596SJason.Beloro@Sun.COM 
2736313Skrishnae typedef struct pf_root_fault {
2749921SKrishna.Elango@Sun.COM 	pcie_req_id_t	scan_bdf;	/* BDF from error logs */
2759921SKrishna.Elango@Sun.COM 	uint64_t	scan_addr;	/* Addr from error logs */
2766313Skrishnae 	boolean_t	full_scan;	/* Option to do a full scan */
2776313Skrishnae } pf_root_fault_t;
2786313Skrishnae 
2796313Skrishnae typedef struct pf_data pf_data_t;
2806313Skrishnae 
28111245SZhijun.Fu@Sun.COM /*
28211245SZhijun.Fu@Sun.COM  * For hot plugged device, these data are init'ed during during probe
28311245SZhijun.Fu@Sun.COM  * For non-hotplugged device, these data are init'ed in pci_autoconfig (on x86),
28411245SZhijun.Fu@Sun.COM  * or in px_attach()(on sparc).
28511245SZhijun.Fu@Sun.COM  *
28611245SZhijun.Fu@Sun.COM  * For root complex the fields are initialized in pcie_rc_init_bus();
28711245SZhijun.Fu@Sun.COM  * for others part of the fields are initialized in pcie_init_bus(),
28811245SZhijun.Fu@Sun.COM  * and part of fields initialized in pcie_post_init_bus(). See comments
28911245SZhijun.Fu@Sun.COM  * on top of respective functions for details.
29011245SZhijun.Fu@Sun.COM  */
2916313Skrishnae typedef struct pcie_bus {
2926313Skrishnae 	/* Needed for PCI/PCIe fabric error handling */
2936313Skrishnae 	dev_info_t	*bus_dip;
2946313Skrishnae 	dev_info_t	*bus_rp_dip;
29510923SEvan.Yan@Sun.COM 	ddi_acc_handle_t bus_cfg_hdl;		/* error handling acc hdle */
2966313Skrishnae 	uint_t		bus_fm_flags;
29710923SEvan.Yan@Sun.COM 	uint_t		bus_soft_state;
2986313Skrishnae 
2996313Skrishnae 	/* Static PCI/PCIe information */
3006313Skrishnae 	pcie_req_id_t	bus_bdf;
3016313Skrishnae 	pcie_req_id_t	bus_rp_bdf;		/* BDF of device's Root Port */
3026313Skrishnae 	uint32_t	bus_dev_ven_id;		/* device/vendor ID */
3036313Skrishnae 	uint8_t		bus_rev_id;		/* revision ID */
3046313Skrishnae 	uint8_t		bus_hdr_type;		/* pci header type, see pci.h */
3056313Skrishnae 	uint16_t	bus_dev_type;		/* PCI-E dev type, see pcie.h */
3066313Skrishnae 	uint8_t		bus_bdg_secbus;		/* Bridge secondary bus num */
3076313Skrishnae 	uint16_t	bus_pcie_off;		/* PCIe Capability Offset */
3086313Skrishnae 	uint16_t	bus_aer_off;		/* PCIe Advanced Error Offset */
3096313Skrishnae 	uint16_t	bus_pcix_off;		/* PCIx Capability Offset */
31010923SEvan.Yan@Sun.COM 	uint16_t	bus_pci_hp_off;		/* PCI HP (SHPC) Cap Offset */
3116313Skrishnae 	uint16_t	bus_ecc_ver;		/* PCIX ecc version */
3126313Skrishnae 	pci_bus_range_t	bus_bus_range;		/* pci bus-range property */
3136313Skrishnae 	ppb_ranges_t	*bus_addr_ranges;	/* pci range property */
3146313Skrishnae 	int		bus_addr_entries;	/* number of range prop */
3156313Skrishnae 	pci_regspec_t	*bus_assigned_addr;	/* "assigned-address" prop */
3166313Skrishnae 	int		bus_assigned_entries;	/* number of prop entries */
3176313Skrishnae 
3186313Skrishnae 	/* Cache of last fault data */
3196313Skrishnae 	pf_data_t	*bus_pfd;
320*11596SJason.Beloro@Sun.COM 	pcie_domain_t	*bus_dom;
3217596SAlan.Adamson@Sun.COM 
3227596SAlan.Adamson@Sun.COM 	int		bus_mps;		/* Maximum Payload Size */
3239455SKrishna.Elango@Sun.COM 
3249455SKrishna.Elango@Sun.COM 	void		*bus_plat_private;	/* Platform specific */
32510923SEvan.Yan@Sun.COM 	/* Hotplug specific fields */
32610923SEvan.Yan@Sun.COM 	pcie_hp_mode_t	bus_hp_sup_modes;	/* HP modes supported */
32710923SEvan.Yan@Sun.COM 	pcie_hp_mode_t	bus_hp_curr_mode;	/* HP mode used */
32810923SEvan.Yan@Sun.COM 	void		*bus_hp_ctrl;		/* HP bus ctrl data */
32910923SEvan.Yan@Sun.COM 	int		bus_ari;		/* ARI device */
33011245SZhijun.Fu@Sun.COM 
33111245SZhijun.Fu@Sun.COM 	uint64_t	bus_cfgacc_base;	/* config space base address */
3326313Skrishnae } pcie_bus_t;
3333274Set142600 
334*11596SJason.Beloro@Sun.COM /*
335*11596SJason.Beloro@Sun.COM  * Data structure to log what devices are affected in relationship to the
336*11596SJason.Beloro@Sun.COM  * severity after all the errors bits have been analyzed.
337*11596SJason.Beloro@Sun.COM  */
338*11596SJason.Beloro@Sun.COM #define	PF_AFFECTED_ROOT	(1 << 0) /* RP/RC is affected */
339*11596SJason.Beloro@Sun.COM #define	PF_AFFECTED_SELF	(1 << 1) /* Reporting Device is affected */
340*11596SJason.Beloro@Sun.COM #define	PF_AFFECTED_PARENT	(1 << 2) /* Parent device is affected */
341*11596SJason.Beloro@Sun.COM #define	PF_AFFECTED_CHILDREN	(1 << 3) /* All children below are affected */
342*11596SJason.Beloro@Sun.COM #define	PF_AFFECTED_BDF		(1 << 4) /* See affected_bdf */
343*11596SJason.Beloro@Sun.COM #define	PF_AFFECTED_AER		(1 << 5) /* See AER Registers */
344*11596SJason.Beloro@Sun.COM #define	PF_AFFECTED_SAER	(1 << 6) /* See SAER Registers */
345*11596SJason.Beloro@Sun.COM #define	PF_AFFECTED_ADDR	(1 << 7) /* Device targeted by addr */
346*11596SJason.Beloro@Sun.COM 
347*11596SJason.Beloro@Sun.COM #define	PF_MAX_AFFECTED_FLAG	PF_AFFECTED_ADDR
348*11596SJason.Beloro@Sun.COM 
349*11596SJason.Beloro@Sun.COM typedef struct pf_affected_dev {
350*11596SJason.Beloro@Sun.COM 	uint16_t		pe_affected_flags;
351*11596SJason.Beloro@Sun.COM 	pcie_req_id_t		pe_affected_bdf;
352*11596SJason.Beloro@Sun.COM } pf_affected_dev_t;
353*11596SJason.Beloro@Sun.COM 
3546313Skrishnae struct pf_data {
3556313Skrishnae 	boolean_t		pe_lock;
3566313Skrishnae 	boolean_t		pe_valid;
3576313Skrishnae 	uint32_t		pe_severity_flags;	/* Severity of error */
358*11596SJason.Beloro@Sun.COM 	uint32_t		pe_orig_severity_flags; /* Original severity */
359*11596SJason.Beloro@Sun.COM 	pf_affected_dev_t	*pe_affected_dev;
3606313Skrishnae 	pcie_bus_t		*pe_bus_p;
361*11596SJason.Beloro@Sun.COM 	pf_root_fault_t		*pe_root_fault; /* Only valid for RC and RP */
362*11596SJason.Beloro@Sun.COM 	pf_root_eh_src_t	*pe_root_eh_src; /* Only valid for RC and RP */
3636313Skrishnae 	pf_pci_err_regs_t	*pe_pci_regs;	/* PCI error reg */
3646313Skrishnae 	union {
3656313Skrishnae 		pf_pcix_err_regs_t	*pe_pcix_regs;	/* PCI-X error reg */
3666313Skrishnae 		pf_pcie_err_regs_t	*pe_pcie_regs;	/* PCIe error reg */
3676313Skrishnae 	} pe_ext;
3686313Skrishnae 	pf_pcix_bdg_err_regs_t *pe_pcix_bdg_regs; /* PCI-X bridge regs */
3696313Skrishnae 	pf_data_t		*pe_prev;	/* Next error in queue */
3706313Skrishnae 	pf_data_t		*pe_next;	/* Next error in queue */
3717848SKrishna.Elango@Sun.COM 	boolean_t		pe_rber_fatal;
3726313Skrishnae };
3736313Skrishnae 
3746313Skrishnae /* Information used while handling errors in the fabric. */
3756313Skrishnae typedef struct pf_impl {
3766313Skrishnae 	ddi_fm_error_t	*pf_derr;
3776313Skrishnae 	pf_root_fault_t	*pf_fault;	/* captured fault bdf/addr to scan */
3786313Skrishnae 	pf_data_t	*pf_dq_head_p;	/* ptr to fault data queue */
3796313Skrishnae 	pf_data_t	*pf_dq_tail_p;	/* ptr pt last fault data q */
3806313Skrishnae 	uint32_t	pf_total;	/* total non RC pf_datas */
3816313Skrishnae } pf_impl_t;
3826313Skrishnae 
3836313Skrishnae /* bus_fm_flags field */
3846313Skrishnae #define	PF_FM_READY		(1 << 0)	/* bus_fm_lock initialized */
3856313Skrishnae #define	PF_FM_IS_NH		(1 << 1)	/* known as non-hardened */
3863274Set142600 
3876313Skrishnae /*
3886313Skrishnae  * PCIe fabric handle lookup address flags.  Used to define what type of
3896313Skrishnae  * transaction the address is for.  These same value are defined again in
3906313Skrishnae  * fabric-xlate FM module.  Do not modify these variables, without modifying
3916313Skrishnae  * those.
3926313Skrishnae  */
3936313Skrishnae #define	PF_ADDR_DMA		(1 << 0)
3946313Skrishnae #define	PF_ADDR_PIO		(1 << 1)
3956313Skrishnae #define	PF_ADDR_CFG		(1 << 2)
3963274Set142600 
3976313Skrishnae /* PCIe fabric error scanning status flags */
3986313Skrishnae #define	PF_SCAN_SUCCESS		(1 << 0)
3996313Skrishnae #define	PF_SCAN_CB_FAILURE	(1 << 1) /* hardened device callback failure */
4006313Skrishnae #define	PF_SCAN_NO_ERR_IN_CHILD	(1 << 2) /* no errors in bridge sec stat reg */
4016313Skrishnae #define	PF_SCAN_IN_DQ		(1 << 3) /* already present in the faultq */
4026313Skrishnae #define	PF_SCAN_DEADLOCK	(1 << 4) /* deadlock detected */
4036313Skrishnae #define	PF_SCAN_BAD_RESPONSE	(1 << 5) /* Incorrect device response */
4046313Skrishnae 
4056313Skrishnae /* PCIe fabric error handling severity return flags */
4066313Skrishnae #define	PF_ERR_NO_ERROR		(1 << 0) /* No error seen */
4076313Skrishnae #define	PF_ERR_CE		(1 << 1) /* Correctable Error */
4086313Skrishnae #define	PF_ERR_NO_PANIC		(1 << 2) /* Error should not panic sys */
4096313Skrishnae #define	PF_ERR_MATCHED_DEVICE	(1 << 3) /* Error Handled By Device */
4106313Skrishnae #define	PF_ERR_MATCHED_RC	(1 << 4) /* Error Handled By RC */
4116313Skrishnae #define	PF_ERR_MATCHED_PARENT	(1 << 5) /* Error Handled By Parent */
4126313Skrishnae #define	PF_ERR_PANIC		(1 << 6) /* Error should panic system */
4136313Skrishnae #define	PF_ERR_PANIC_DEADLOCK	(1 << 7) /* deadlock detected */
414*11596SJason.Beloro@Sun.COM #define	PF_ERR_PANIC_BAD_RESPONSE (1 << 8) /* Device no response */
415*11596SJason.Beloro@Sun.COM #define	PF_ERR_MATCH_DOM	(1 << 9) /* Error Handled By IO domain */
4166313Skrishnae 
417*11596SJason.Beloro@Sun.COM #define	PF_ERR_FATAL_FLAGS		\
418*11596SJason.Beloro@Sun.COM 	(PF_ERR_PANIC | PF_ERR_PANIC_DEADLOCK | PF_ERR_PANIC_BAD_RESPONSE)
4196313Skrishnae 
4206313Skrishnae #define	PF_HDL_FOUND		1
4216313Skrishnae #define	PF_HDL_NOTFOUND		2
4226313Skrishnae 
4239921SKrishna.Elango@Sun.COM /*
4249921SKrishna.Elango@Sun.COM  * PCIe Capability Device Type Pseudo Definitions.
4259921SKrishna.Elango@Sun.COM  *
4269921SKrishna.Elango@Sun.COM  * PCI_PSEUDO is used on real PCI devices.  The Legacy PCI definition in the
4279921SKrishna.Elango@Sun.COM  * PCIe spec really refers to PCIe devices that *require* IO Space access.  IO
4289921SKrishna.Elango@Sun.COM  * Space access is usually frowned upon now in PCIe, but there for legacy
4299921SKrishna.Elango@Sun.COM  * purposes.
4309921SKrishna.Elango@Sun.COM  */
4319921SKrishna.Elango@Sun.COM #define	PCIE_PCIECAP_DEV_TYPE_RC_PSEUDO		0x100
4329921SKrishna.Elango@Sun.COM #define	PCIE_PCIECAP_DEV_TYPE_PCI_PSEUDO	0x101
4339921SKrishna.Elango@Sun.COM 
4349921SKrishna.Elango@Sun.COM #define	PCIE_INVALID_BDF	0xFFFF
4359921SKrishna.Elango@Sun.COM #define	PCIE_CHECK_VALID_BDF(x)	(x != PCIE_INVALID_BDF)
4363274Set142600 
4377596SAlan.Adamson@Sun.COM typedef struct {
4387596SAlan.Adamson@Sun.COM 	dev_info_t	*dip;
4397596SAlan.Adamson@Sun.COM 	int		highest_common_mps;
4407596SAlan.Adamson@Sun.COM } pcie_max_supported_t;
4417596SAlan.Adamson@Sun.COM 
44210923SEvan.Yan@Sun.COM /*
44310923SEvan.Yan@Sun.COM  * Default interrupt priority for all PCI and PCIe nexus drivers including
44410923SEvan.Yan@Sun.COM  * hotplug interrupts.
44510923SEvan.Yan@Sun.COM  */
44610923SEvan.Yan@Sun.COM #define	PCIE_INTR_PRI		(LOCK_LEVEL - 1)
44710923SEvan.Yan@Sun.COM 
44810923SEvan.Yan@Sun.COM /*
44910923SEvan.Yan@Sun.COM  * XXX - PCIE_IS_PCIE check is required in order not to invoke these macros
45010923SEvan.Yan@Sun.COM  * for non-standard PCI or PCI Express Hotplug Controllers.
45110923SEvan.Yan@Sun.COM  */
45210923SEvan.Yan@Sun.COM #define	PCIE_ENABLE_ERRORS(dip)	\
45310923SEvan.Yan@Sun.COM 	if (PCIE_IS_PCIE(PCIE_DIP2BUS(dip))) {	\
45410923SEvan.Yan@Sun.COM 		pcie_enable_errors(dip);	\
45510923SEvan.Yan@Sun.COM 		(void) pcie_enable_ce(dip);	\
45610923SEvan.Yan@Sun.COM 	}
45710923SEvan.Yan@Sun.COM 
45810923SEvan.Yan@Sun.COM #define	PCIE_DISABLE_ERRORS(dip)		\
45910923SEvan.Yan@Sun.COM 	if (PCIE_IS_PCIE(PCIE_DIP2BUS(dip))) {	\
46010923SEvan.Yan@Sun.COM 		pcie_disable_errors(dip);	\
46110923SEvan.Yan@Sun.COM 	}
46210923SEvan.Yan@Sun.COM 
46311245SZhijun.Fu@Sun.COM /*
46411245SZhijun.Fu@Sun.COM  * pcie_init_buspcie_fini_bus specific flags
46511245SZhijun.Fu@Sun.COM  */
46611245SZhijun.Fu@Sun.COM #define	PCIE_BUS_INITIAL	0x0001
46711245SZhijun.Fu@Sun.COM #define	PCIE_BUS_FINAL		0x0002
46811245SZhijun.Fu@Sun.COM #define	PCIE_BUS_ALL		(PCIE_BUS_INITIAL | PCIE_BUS_FINAL)
46911245SZhijun.Fu@Sun.COM 
4709455SKrishna.Elango@Sun.COM #ifdef	DEBUG
4719455SKrishna.Elango@Sun.COM #define	PCIE_DBG pcie_dbg
4729455SKrishna.Elango@Sun.COM /* Common Debugging shortcuts */
4739455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CFG(dip, bus_p, name, sz, off, org) \
4749455SKrishna.Elango@Sun.COM 	PCIE_DBG("%s:%d:(0x%x) %s(0x%x) 0x%x -> 0x%x\n", ddi_node_name(dip), \
4759455SKrishna.Elango@Sun.COM 	    ddi_get_instance(dip), bus_p->bus_bdf, name, off, org, \
4769455SKrishna.Elango@Sun.COM 	    PCIE_GET(sz, bus_p, off))
4779455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CAP(dip, bus_p, name, sz, off, org) \
4789455SKrishna.Elango@Sun.COM 	PCIE_DBG("%s:%d:(0x%x) %s(0x%x) 0x%x -> 0x%x\n", ddi_node_name(dip), \
4799455SKrishna.Elango@Sun.COM 	    ddi_get_instance(dip), bus_p->bus_bdf, name, off, org, \
4809455SKrishna.Elango@Sun.COM 	    PCIE_CAP_GET(sz, bus_p, off))
4819455SKrishna.Elango@Sun.COM #define	PCIE_DBG_AER(dip, bus_p, name, sz, off, org) \
4829455SKrishna.Elango@Sun.COM 	PCIE_DBG("%s:%d:(0x%x) %s(0x%x) 0x%x -> 0x%x\n", ddi_node_name(dip), \
4839455SKrishna.Elango@Sun.COM 	    ddi_get_instance(dip), bus_p->bus_bdf, name, off, org, \
4849455SKrishna.Elango@Sun.COM 	    PCIE_AER_GET(sz, bus_p, off))
4859455SKrishna.Elango@Sun.COM 
4869455SKrishna.Elango@Sun.COM #else	/* DEBUG */
4879455SKrishna.Elango@Sun.COM 
4889455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CFG 0 &&
4899455SKrishna.Elango@Sun.COM #define	PCIE_DBG 0 &&
49010923SEvan.Yan@Sun.COM #define	PCIE_ARI_DBG 0 &&
4919455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CAP 0 &&
4929455SKrishna.Elango@Sun.COM #define	PCIE_DBG_AER 0 &&
4939455SKrishna.Elango@Sun.COM 
4949455SKrishna.Elango@Sun.COM #endif	/* DEBUG */
4959455SKrishna.Elango@Sun.COM 
4963274Set142600 /* PCIe Friendly Functions */
49710923SEvan.Yan@Sun.COM extern int pcie_init(dev_info_t *dip, caddr_t arg);
49810923SEvan.Yan@Sun.COM extern int pcie_uninit(dev_info_t *dip);
49911445SEvan.Yan@Sun.COM extern int pcie_hpintr_enable(dev_info_t *dip);
50011445SEvan.Yan@Sun.COM extern int pcie_hpintr_disable(dev_info_t *dip);
50110923SEvan.Yan@Sun.COM extern int pcie_intr(dev_info_t *dip);
50210923SEvan.Yan@Sun.COM extern int pcie_open(dev_info_t *dip, dev_t *devp, int flags, int otyp,
50310923SEvan.Yan@Sun.COM     cred_t *credp);
50410923SEvan.Yan@Sun.COM extern int pcie_close(dev_info_t *dip, dev_t dev, int flags, int otyp,
50510923SEvan.Yan@Sun.COM     cred_t *credp);
50610923SEvan.Yan@Sun.COM extern int pcie_ioctl(dev_info_t *dip, dev_t dev, int cmd, intptr_t arg,
50710923SEvan.Yan@Sun.COM     int mode, cred_t *credp, int *rvalp);
50810923SEvan.Yan@Sun.COM extern int pcie_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op,
50910923SEvan.Yan@Sun.COM     int flags, char *name, caddr_t valuep, int *lengthp);
51010923SEvan.Yan@Sun.COM 
5118495SAlan.Adamson@Sun.COM extern void pcie_init_root_port_mps(dev_info_t *dip);
51227Sjchu extern int pcie_initchild(dev_info_t *dip);
51327Sjchu extern void pcie_uninitchild(dev_info_t *dip);
51411245SZhijun.Fu@Sun.COM extern int pcie_init_cfghdl(dev_info_t *dip);
51511245SZhijun.Fu@Sun.COM extern void pcie_fini_cfghdl(dev_info_t *dip);
5166313Skrishnae extern void pcie_clear_errors(dev_info_t *dip);
5172738Skrishnae extern int pcie_postattach_child(dev_info_t *dip);
5186313Skrishnae extern void pcie_enable_errors(dev_info_t *dip);
5196313Skrishnae extern void pcie_disable_errors(dev_info_t *dip);
5206313Skrishnae extern int pcie_enable_ce(dev_info_t *dip);
5216313Skrishnae extern boolean_t pcie_bridge_is_link_disabled(dev_info_t *);
5226313Skrishnae 
52311245SZhijun.Fu@Sun.COM extern pcie_bus_t *pcie_init_bus(dev_info_t *dip, pcie_req_id_t bdf,
52411245SZhijun.Fu@Sun.COM     uint8_t flags);
52511245SZhijun.Fu@Sun.COM extern void pcie_fini_bus(dev_info_t *dip, uint8_t flags);
52611245SZhijun.Fu@Sun.COM extern void pcie_fab_init_bus(dev_info_t *dip, uint8_t flags);
52711245SZhijun.Fu@Sun.COM extern void pcie_fab_fini_bus(dev_info_t *dip, uint8_t flags);
5286313Skrishnae extern void pcie_rc_init_bus(dev_info_t *dip);
5296313Skrishnae extern void pcie_rc_fini_bus(dev_info_t *dip);
5306313Skrishnae extern void pcie_rc_init_pfd(dev_info_t *dip, pf_data_t *pfd);
5316313Skrishnae extern void pcie_rc_fini_pfd(pf_data_t *pfd);
5326313Skrishnae extern boolean_t pcie_is_child(dev_info_t *dip, dev_info_t *rdip);
5336313Skrishnae extern int pcie_get_bdf_from_dip(dev_info_t *dip, pcie_req_id_t *bdf);
5343156Sgirish extern dev_info_t *pcie_get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip);
5353249Sgovinda extern uint32_t pcie_get_bdf_for_dma_xfer(dev_info_t *dip, dev_info_t *rdip);
5367596SAlan.Adamson@Sun.COM extern int pcie_dev(dev_info_t *dip);
5377596SAlan.Adamson@Sun.COM extern void pcie_get_fabric_mps(dev_info_t *rc_dip, dev_info_t *dip,
5387596SAlan.Adamson@Sun.COM 	int *max_supported);
5397596SAlan.Adamson@Sun.COM extern int pcie_root_port(dev_info_t *dip);
5407596SAlan.Adamson@Sun.COM extern int pcie_initchild_mps(dev_info_t *dip);
5417848SKrishna.Elango@Sun.COM extern void pcie_set_rber_fatal(dev_info_t *dip, boolean_t val);
5427848SKrishna.Elango@Sun.COM extern boolean_t pcie_get_rber_fatal(dev_info_t *dip);
5433274Set142600 
5446313Skrishnae extern uint32_t pcie_get_aer_uce_mask();
5456313Skrishnae extern uint32_t pcie_get_aer_ce_mask();
5466313Skrishnae extern uint32_t pcie_get_aer_suce_mask();
5476313Skrishnae extern uint32_t pcie_get_serr_mask();
5486313Skrishnae extern void pcie_set_aer_uce_mask(uint32_t mask);
5496313Skrishnae extern void pcie_set_aer_ce_mask(uint32_t mask);
5506313Skrishnae extern void pcie_set_aer_suce_mask(uint32_t mask);
5516313Skrishnae extern void pcie_set_serr_mask(uint32_t mask);
5529455SKrishna.Elango@Sun.COM extern void pcie_init_plat(dev_info_t *dip);
5539455SKrishna.Elango@Sun.COM extern void pcie_fini_plat(dev_info_t *dip);
55410923SEvan.Yan@Sun.COM extern int pcie_read_only_probe(dev_info_t *, char *, dev_info_t **);
55510923SEvan.Yan@Sun.COM extern dev_info_t *pcie_func_to_dip(dev_info_t *dip, pcie_req_id_t function);
55610923SEvan.Yan@Sun.COM extern int pcie_ari_disable(dev_info_t *dip);
55710923SEvan.Yan@Sun.COM extern int pcie_ari_enable(dev_info_t *dip);
55810923SEvan.Yan@Sun.COM 
55910923SEvan.Yan@Sun.COM #define	PCIE_ARI_FORW_NOT_SUPPORTED	0
56010923SEvan.Yan@Sun.COM #define	PCIE_ARI_FORW_SUPPORTED		1
56110923SEvan.Yan@Sun.COM 
56210923SEvan.Yan@Sun.COM extern int pcie_ari_supported(dev_info_t *dip);
56310923SEvan.Yan@Sun.COM 
56410923SEvan.Yan@Sun.COM #define	PCIE_ARI_FORW_DISABLED	0
56510923SEvan.Yan@Sun.COM #define	PCIE_ARI_FORW_ENABLED	1
56610923SEvan.Yan@Sun.COM 
56710923SEvan.Yan@Sun.COM extern int pcie_ari_is_enabled(dev_info_t *dip);
56810923SEvan.Yan@Sun.COM 
56910923SEvan.Yan@Sun.COM #define	PCIE_NOT_ARI_DEVICE		0
57010923SEvan.Yan@Sun.COM #define	PCIE_ARI_DEVICE			1
57110923SEvan.Yan@Sun.COM 
57210923SEvan.Yan@Sun.COM extern int pcie_ari_device(dev_info_t *dip);
57310923SEvan.Yan@Sun.COM extern int pcie_ari_get_next_function(dev_info_t *dip, int *func);
5743274Set142600 
5753274Set142600 /* PCIe error handling functions */
576*11596SJason.Beloro@Sun.COM extern void pf_eh_enter(pcie_bus_t *bus_p);
577*11596SJason.Beloro@Sun.COM extern void pf_eh_exit(pcie_bus_t *bus_p);
5783274Set142600 extern int pf_scan_fabric(dev_info_t *rpdip, ddi_fm_error_t *derr,
5796313Skrishnae     pf_data_t *root_pfd_p);
5806313Skrishnae extern void pf_init(dev_info_t *, ddi_iblock_cookie_t, ddi_attach_cmd_t);
5816313Skrishnae extern void pf_fini(dev_info_t *, ddi_detach_cmd_t);
5826313Skrishnae extern int pf_hdl_lookup(dev_info_t *, uint64_t, uint32_t, uint64_t,
5836313Skrishnae     pcie_req_id_t);
5846313Skrishnae extern int pf_tlp_decode(pcie_bus_t *, pf_pcie_adv_err_regs_t *);
58511040SPavel.Potoplyak@Sun.COM extern void pcie_force_fullscan();
58627Sjchu 
58710923SEvan.Yan@Sun.COM #ifdef	DEBUG
58810923SEvan.Yan@Sun.COM extern uint_t pcie_debug_flags;
58910923SEvan.Yan@Sun.COM extern void pcie_dbg(char *fmt, ...);
59010923SEvan.Yan@Sun.COM #endif	/* DEBUG */
59110923SEvan.Yan@Sun.COM 
592*11596SJason.Beloro@Sun.COM /* PCIe IOV functions */
593*11596SJason.Beloro@Sun.COM extern dev_info_t *pcie_find_dip_by_bdf(dev_info_t *rootp, pcie_req_id_t bdf);
594*11596SJason.Beloro@Sun.COM 
595*11596SJason.Beloro@Sun.COM extern boolean_t pf_in_bus_range(pcie_bus_t *, pcie_req_id_t);
596*11596SJason.Beloro@Sun.COM extern boolean_t pf_in_assigned_addr(pcie_bus_t *, uint64_t);
597*11596SJason.Beloro@Sun.COM extern int pf_pci_decode(pf_data_t *, uint16_t *);
598*11596SJason.Beloro@Sun.COM extern pcie_bus_t *pf_find_busp_by_bdf(pf_impl_t *, pcie_req_id_t);
599*11596SJason.Beloro@Sun.COM extern pcie_bus_t *pf_find_busp_by_addr(pf_impl_t *, uint64_t);
600*11596SJason.Beloro@Sun.COM extern pcie_bus_t *pf_find_busp_by_aer(pf_impl_t *, pf_data_t *);
601*11596SJason.Beloro@Sun.COM extern pcie_bus_t *pf_find_busp_by_saer(pf_impl_t *, pf_data_t *);
602*11596SJason.Beloro@Sun.COM 
603*11596SJason.Beloro@Sun.COM extern int pciev_eh(pf_data_t *, pf_impl_t *);
604*11596SJason.Beloro@Sun.COM extern pcie_bus_t *pciev_get_affected_dev(pf_impl_t *, pf_data_t *,
605*11596SJason.Beloro@Sun.COM     uint16_t, uint16_t);
606*11596SJason.Beloro@Sun.COM extern void pciev_eh_exit(pf_data_t *, uint_t);
607*11596SJason.Beloro@Sun.COM extern boolean_t pcie_in_domain(pcie_bus_t *, uint_t);
608*11596SJason.Beloro@Sun.COM 
609*11596SJason.Beloro@Sun.COM #define	PCIE_ZALLOC(data) kmem_zalloc(sizeof (data), KM_SLEEP)
610*11596SJason.Beloro@Sun.COM 
611*11596SJason.Beloro@Sun.COM 
61227Sjchu #ifdef	__cplusplus
61327Sjchu }
61427Sjchu #endif
61527Sjchu 
61627Sjchu #endif	/* _SYS_PCIE_IMPL_H */
617