xref: /onnv-gate/usr/src/uts/common/sys/pcie_impl.h (revision 12262:23286d16230d)
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 /*
2212076SKrishna.Elango@Sun.COM  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2327Sjchu  */
2427Sjchu 
2527Sjchu #ifndef	_SYS_PCIE_IMPL_H
2627Sjchu #define	_SYS_PCIE_IMPL_H
2727Sjchu 
2827Sjchu #ifdef	__cplusplus
2927Sjchu extern "C" {
3027Sjchu #endif
3127Sjchu 
323274Set142600 #include <sys/pcie.h>
3311596SJason.Beloro@Sun.COM #include <sys/pciev.h>
343274Set142600 
356313Skrishnae #define	PCI_GET_BDF(dip)	\
366313Skrishnae 	PCIE_DIP2BUS(dip)->bus_bdf
376313Skrishnae #define	PCI_GET_SEC_BUS(dip)	\
386313Skrishnae 	PCIE_DIP2BUS(dip)->bus_bdg_secbus
396313Skrishnae #define	PCI_GET_PCIE2PCI_SECBUS(dip) \
40*12262SAlan.Adamson@Sun.COM 	PCIE_DIP2BUS(dip)->bus_pcie2pci_secbus
413274Set142600 
426313Skrishnae #define	DEVI_PORT_TYPE_PCI \
436313Skrishnae 	((PCI_CLASS_BRIDGE << 16) | (PCI_BRIDGE_PCI << 8) | \
446313Skrishnae 	PCI_BRIDGE_PCI_IF_PCI2PCI)
453274Set142600 
466313Skrishnae #define	PCIE_DIP2BUS(dip) \
476313Skrishnae 	(ndi_port_type(dip, B_TRUE, DEVI_PORT_TYPE_PCI) ? \
486313Skrishnae 	PCIE_DIP2UPBUS(dip) : \
496313Skrishnae 	ndi_port_type(dip, B_FALSE, DEVI_PORT_TYPE_PCI) ? \
506313Skrishnae 	PCIE_DIP2DOWNBUS(dip) : NULL)
513274Set142600 
526313Skrishnae #define	PCIE_DIP2UPBUS(dip) \
536313Skrishnae 	((pcie_bus_t *)ndi_get_bus_private(dip, B_TRUE))
546313Skrishnae #define	PCIE_DIP2DOWNBUS(dip) \
556313Skrishnae 	((pcie_bus_t *)ndi_get_bus_private(dip, B_FALSE))
566313Skrishnae #define	PCIE_DIP2PFD(dip) (PCIE_DIP2BUS(dip))->bus_pfd
576313Skrishnae #define	PCIE_PFD2BUS(pfd_p) pfd_p->pe_bus_p
586313Skrishnae #define	PCIE_PFD2DIP(pfd_p) PCIE_PFD2BUS(pfd_p)->bus_dip
596313Skrishnae #define	PCIE_BUS2DIP(bus_p) bus_p->bus_dip
606313Skrishnae #define	PCIE_BUS2PFD(bus_p) PCIE_DIP2PFD(PCIE_BUS2DIP(bus_p))
6111596SJason.Beloro@Sun.COM #define	PCIE_BUS2DOM(bus_p) bus_p->bus_dom
6211596SJason.Beloro@Sun.COM #define	PCIE_DIP2DOM(dip) PCIE_BUS2DOM(PCIE_DIP2BUS(dip))
633274Set142600 
6411245SZhijun.Fu@Sun.COM /*
6511245SZhijun.Fu@Sun.COM  * These macros depend on initialization of type related data in bus_p.
6611245SZhijun.Fu@Sun.COM  */
676313Skrishnae #define	PCIE_IS_PCIE(bus_p) (bus_p->bus_pcie_off)
686313Skrishnae #define	PCIE_IS_PCIX(bus_p) (bus_p->bus_pcix_off)
699921SKrishna.Elango@Sun.COM #define	PCIE_IS_PCI(bus_p) (!PCIE_IS_PCIE(bus_p))
706313Skrishnae #define	PCIE_HAS_AER(bus_p) (bus_p->bus_aer_off)
716313Skrishnae /* IS_ROOT = is RC or RP */
726313Skrishnae #define	PCIE_IS_ROOT(bus_p) (PCIE_IS_RC(bus_p) || PCIE_IS_RP(bus_p))
7310923SEvan.Yan@Sun.COM 
7410923SEvan.Yan@Sun.COM #define	PCIE_IS_HOTPLUG_CAPABLE(dip) \
7510923SEvan.Yan@Sun.COM 	(PCIE_DIP2BUS(dip)->bus_hp_sup_modes)
7610923SEvan.Yan@Sun.COM 
7710923SEvan.Yan@Sun.COM #define	PCIE_IS_HOTPLUG_ENABLED(dip) \
7810923SEvan.Yan@Sun.COM 	((PCIE_DIP2BUS(dip)->bus_hp_curr_mode == PCIE_PCI_HP_MODE) || \
7910923SEvan.Yan@Sun.COM 	(PCIE_DIP2BUS(dip)->bus_hp_curr_mode == PCIE_NATIVE_HP_MODE))
8010923SEvan.Yan@Sun.COM 
816313Skrishnae /*
826313Skrishnae  * This is a pseudo pcie "device type", but it's needed to explain describe
836313Skrishnae  * nodes such as PX and NPE, which aren't really PCI devices but do control or
846313Skrishnae  * interaction with PCI error handling.
856313Skrishnae  */
866313Skrishnae #define	PCIE_IS_RC(bus_p) \
876313Skrishnae 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_RC_PSEUDO)
886313Skrishnae #define	PCIE_IS_RP(bus_p) \
896313Skrishnae 	((bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_ROOT) && \
906313Skrishnae 	    PCIE_IS_PCIE(bus_p))
919921SKrishna.Elango@Sun.COM #define	PCIE_IS_SWU(bus_p) \
929921SKrishna.Elango@Sun.COM 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_UP)
939921SKrishna.Elango@Sun.COM #define	PCIE_IS_SWD(bus_p) \
949921SKrishna.Elango@Sun.COM 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_DOWN)
956313Skrishnae #define	PCIE_IS_SW(bus_p) \
969921SKrishna.Elango@Sun.COM 	(PCIE_IS_SWU(bus_p) || PCIE_IS_SWD(bus_p))
976313Skrishnae #define	PCIE_IS_BDG(bus_p)  (bus_p->bus_hdr_type == PCI_HEADER_ONE)
989921SKrishna.Elango@Sun.COM #define	PCIE_IS_PCI_BDG(bus_p) (PCIE_IS_PCI(bus_p) && PCIE_IS_BDG(bus_p))
996313Skrishnae #define	PCIE_IS_PCIE_BDG(bus_p) \
1006313Skrishnae 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_PCIE2PCI)
1017987SErwin.Tsaur@Sun.COM #define	PCIE_IS_PCI2PCIE(bus_p) \
1027987SErwin.Tsaur@Sun.COM 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_PCI2PCIE)
1036313Skrishnae #define	PCIE_IS_PCIE_SEC(bus_p) \
1046313Skrishnae 	(PCIE_IS_PCIE(bus_p) && PCIE_IS_BDG(bus_p) && !PCIE_IS_PCIE_BDG(bus_p))
1056313Skrishnae #define	PCIX_ECC_VERSION_CHECK(bus_p) \
1066313Skrishnae 	((bus_p->bus_ecc_ver == PCI_PCIX_VER_1) || \
1076313Skrishnae 	    (bus_p->bus_ecc_ver == PCI_PCIX_VER_2))
1083274Set142600 
1096313Skrishnae #define	PCIE_VENID(bus_p)	(bus_p->bus_dev_ven_id & 0xffff)
1106313Skrishnae #define	PCIE_DEVID(bus_p)	((bus_p->bus_dev_ven_id >> 16) & 0xffff)
1113274Set142600 
1126313Skrishnae /* PCIE Cap/AER shortcuts */
1136313Skrishnae #define	PCIE_GET(sz, bus_p, off) \
1146313Skrishnae 	pci_config_get ## sz(bus_p->bus_cfg_hdl, off)
1156313Skrishnae #define	PCIE_PUT(sz, bus_p, off, val) \
1166313Skrishnae 	pci_config_put ## sz(bus_p->bus_cfg_hdl, off, val)
1176313Skrishnae #define	PCIE_CAP_GET(sz, bus_p, off) \
1186313Skrishnae 	PCI_CAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcie_off, off)
1196313Skrishnae #define	PCIE_CAP_PUT(sz, bus_p, off, val) \
1206313Skrishnae 	PCI_CAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcie_off, off, \
1216313Skrishnae 	    val)
1226313Skrishnae #define	PCIE_AER_GET(sz, bus_p, off) \
1236313Skrishnae 	PCI_XCAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_aer_off, off)
1246313Skrishnae #define	PCIE_AER_PUT(sz, bus_p, off, val) \
1256313Skrishnae 	PCI_XCAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_aer_off, off, \
1266313Skrishnae 	    val)
1276313Skrishnae #define	PCIX_CAP_GET(sz, bus_p, off) \
1286313Skrishnae 	PCI_CAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcix_off, off)
1296313Skrishnae #define	PCIX_CAP_PUT(sz, bus_p, off, val) \
1306313Skrishnae 	PCI_CAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcix_off, off, \
1316313Skrishnae 	    val)
1323274Set142600 
1336313Skrishnae /* Translate PF error return values to DDI_FM values */
1346313Skrishnae #define	PF_ERR2DDIFM_ERR(sts) \
1356313Skrishnae 	(sts & PF_ERR_FATAL_FLAGS ? DDI_FM_FATAL :	\
1366313Skrishnae 	(sts == PF_ERR_NO_ERROR ? DDI_FM_OK : DDI_FM_NONFATAL))
1373274Set142600 
13827Sjchu /*
1392549Sgovinda  * The following flag is used for Broadcom 5714/5715 bridge prefetch issue.
14010187SKrishna.Elango@Sun.COM  * This flag will be used both by px and pcieb nexus drivers.
1412549Sgovinda  */
1422549Sgovinda #define	PX_DMAI_FLAGS_MAP_BUFZONE	0x40000
1432549Sgovinda 
1446313Skrishnae /*
1456313Skrishnae  * PCI(e/-X) structures used to to gather and report errors detected by
1466313Skrishnae  * PCI(e/-X) compliant devices.  These registers only contain "dynamic" data.
1476313Skrishnae  * Static data such as Capability Offsets and Version #s is saved in the parent
1486313Skrishnae  * private data.
1496313Skrishnae  */
1506313Skrishnae #define	PCI_ERR_REG(pfd_p)	   pfd_p->pe_pci_regs
1516313Skrishnae #define	PCI_BDG_ERR_REG(pfd_p)	   PCI_ERR_REG(pfd_p)->pci_bdg_regs
1526313Skrishnae #define	PCIX_ERR_REG(pfd_p)	   pfd_p->pe_ext.pe_pcix_regs
1536313Skrishnae #define	PCIX_ECC_REG(pfd_p)	   PCIX_ERR_REG(pfd_p)->pcix_ecc_regs
1546313Skrishnae #define	PCIX_BDG_ERR_REG(pfd_p)	   pfd_p->pe_pcix_bdg_regs
1556313Skrishnae #define	PCIX_BDG_ECC_REG(pfd_p, n) PCIX_BDG_ERR_REG(pfd_p)->pcix_bdg_ecc_regs[n]
1566313Skrishnae #define	PCIE_ERR_REG(pfd_p)	   pfd_p->pe_ext.pe_pcie_regs
1576313Skrishnae #define	PCIE_RP_REG(pfd_p)	   PCIE_ERR_REG(pfd_p)->pcie_rp_regs
1586313Skrishnae #define	PCIE_ROOT_FAULT(pfd_p)	   pfd_p->pe_root_fault
15911596SJason.Beloro@Sun.COM #define	PCIE_ROOT_EH_SRC(pfd_p)    pfd_p->pe_root_eh_src
1606313Skrishnae #define	PCIE_ADV_REG(pfd_p)	   PCIE_ERR_REG(pfd_p)->pcie_adv_regs
1616313Skrishnae #define	PCIE_ADV_HDR(pfd_p, n)	   PCIE_ADV_REG(pfd_p)->pcie_ue_hdr[n]
1626313Skrishnae #define	PCIE_ADV_BDG_REG(pfd_p) \
1636313Skrishnae 	PCIE_ADV_REG(pfd_p)->pcie_ext.pcie_adv_bdg_regs
1646313Skrishnae #define	PCIE_ADV_BDG_HDR(pfd_p, n) PCIE_ADV_BDG_REG(pfd_p)->pcie_sue_hdr[n]
1656313Skrishnae #define	PCIE_ADV_RP_REG(pfd_p) \
1666313Skrishnae 	PCIE_ADV_REG(pfd_p)->pcie_ext.pcie_adv_rp_regs
16711596SJason.Beloro@Sun.COM #define	PFD_AFFECTED_DEV(pfd_p)	   pfd_p->pe_affected_dev
16812076SKrishna.Elango@Sun.COM #define	PFD_SET_AFFECTED_FLAG(pfd_p, aff_flag) \
16912076SKrishna.Elango@Sun.COM 	PFD_AFFECTED_DEV(pfd_p)->pe_affected_flags = aff_flag
17012076SKrishna.Elango@Sun.COM #define	PFD_SET_AFFECTED_BDF(pfd_p, bdf) \
17112076SKrishna.Elango@Sun.COM 	PFD_AFFECTED_DEV(pfd_p)->pe_affected_bdf = bdf
17211596SJason.Beloro@Sun.COM 
1736313Skrishnae #define	PFD_IS_ROOT(pfd_p)	   PCIE_IS_ROOT(PCIE_PFD2BUS(pfd_p))
1746313Skrishnae #define	PFD_IS_RC(pfd_p)	   PCIE_IS_RC(PCIE_PFD2BUS(pfd_p))
1756313Skrishnae #define	PFD_IS_RP(pfd_p)	   PCIE_IS_RP(PCIE_PFD2BUS(pfd_p))
1766313Skrishnae 
17710923SEvan.Yan@Sun.COM /* bus_hp_mode field */
17810923SEvan.Yan@Sun.COM typedef enum {
17910923SEvan.Yan@Sun.COM 	PCIE_NONE_HP_MODE	= 0x0,
18010923SEvan.Yan@Sun.COM 	PCIE_ACPI_HP_MODE	= 0x1,
18110923SEvan.Yan@Sun.COM 	PCIE_PCI_HP_MODE	= 0x2,
18210923SEvan.Yan@Sun.COM 	PCIE_NATIVE_HP_MODE	= 0x4
18310923SEvan.Yan@Sun.COM } pcie_hp_mode_t;
18410923SEvan.Yan@Sun.COM 
1856313Skrishnae typedef struct pf_pci_bdg_err_regs {
1866313Skrishnae 	uint16_t pci_bdg_sec_stat;	/* PCI secondary status reg */
1876313Skrishnae 	uint16_t pci_bdg_ctrl;		/* PCI bridge control reg */
1886313Skrishnae } pf_pci_bdg_err_regs_t;
1896313Skrishnae 
1906313Skrishnae typedef struct pf_pci_err_regs {
1916313Skrishnae 	uint16_t pci_err_status;	/* pci status register */
1926313Skrishnae 	uint16_t pci_cfg_comm;		/* pci command register */
1936313Skrishnae 	pf_pci_bdg_err_regs_t *pci_bdg_regs;
1946313Skrishnae } pf_pci_err_regs_t;
1956313Skrishnae 
1966313Skrishnae typedef struct pf_pcix_ecc_regs {
1976313Skrishnae 	uint32_t pcix_ecc_ctlstat;	/* pcix ecc control status reg */
1986313Skrishnae 	uint32_t pcix_ecc_fstaddr;	/* pcix ecc first address reg */
1996313Skrishnae 	uint32_t pcix_ecc_secaddr;	/* pcix ecc second address reg */
2006313Skrishnae 	uint32_t pcix_ecc_attr;		/* pcix ecc attributes reg */
2016313Skrishnae } pf_pcix_ecc_regs_t;
2023274Set142600 
2036313Skrishnae typedef struct pf_pcix_err_regs {
2046313Skrishnae 	uint16_t pcix_command;		/* pcix command register */
2056313Skrishnae 	uint32_t pcix_status;		/* pcix status register */
2066313Skrishnae 	pf_pcix_ecc_regs_t *pcix_ecc_regs;	/* pcix ecc registers */
2076313Skrishnae } pf_pcix_err_regs_t;
2086313Skrishnae 
2096313Skrishnae typedef struct pf_pcix_bdg_err_regs {
2106313Skrishnae 	uint16_t pcix_bdg_sec_stat;	/* pcix bridge secondary status reg */
2116313Skrishnae 	uint32_t pcix_bdg_stat;		/* pcix bridge status reg */
2126313Skrishnae 	pf_pcix_ecc_regs_t *pcix_bdg_ecc_regs[2];	/* pcix ecc registers */
2136313Skrishnae } pf_pcix_bdg_err_regs_t;
2146313Skrishnae 
2156313Skrishnae typedef struct pf_pcie_adv_bdg_err_regs {
2166313Skrishnae 	uint32_t pcie_sue_ctl;		/* pcie bridge secondary ue control */
2176313Skrishnae 	uint32_t pcie_sue_status;	/* pcie bridge secondary ue status */
2186313Skrishnae 	uint32_t pcie_sue_mask;		/* pcie bridge secondary ue mask */
2196313Skrishnae 	uint32_t pcie_sue_sev;		/* pcie bridge secondary ue severity */
2206313Skrishnae 	uint32_t pcie_sue_hdr[4];	/* pcie bridge secondary ue hdr log */
2216313Skrishnae 	uint32_t pcie_sue_tgt_trans;	/* Fault trans type from SAER Logs */
2226313Skrishnae 	uint64_t pcie_sue_tgt_addr;	/* Fault addr from SAER Logs */
2236313Skrishnae 	pcie_req_id_t pcie_sue_tgt_bdf;	/* Fault bdf from SAER Logs */
2246313Skrishnae } pf_pcie_adv_bdg_err_regs_t;
2253274Set142600 
2266313Skrishnae typedef struct pf_pcie_adv_rp_err_regs {
2276313Skrishnae 	uint32_t pcie_rp_err_status;	/* pcie root complex error status reg */
2286313Skrishnae 	uint32_t pcie_rp_err_cmd;	/* pcie root complex error cmd reg */
2296313Skrishnae 	uint16_t pcie_rp_ce_src_id;	/* pcie root complex ce sourpe id */
2306313Skrishnae 	uint16_t pcie_rp_ue_src_id;	/* pcie root complex ue sourpe id */
2316313Skrishnae } pf_pcie_adv_rp_err_regs_t;
2326313Skrishnae 
2336313Skrishnae typedef struct pf_pcie_adv_err_regs {
2346313Skrishnae 	uint32_t pcie_adv_ctl;		/* pcie advanced control reg */
2356313Skrishnae 	uint32_t pcie_ue_status;	/* pcie ue error status reg */
2366313Skrishnae 	uint32_t pcie_ue_mask;		/* pcie ue error mask reg */
2376313Skrishnae 	uint32_t pcie_ue_sev;		/* pcie ue error severity reg */
2386313Skrishnae 	uint32_t pcie_ue_hdr[4];	/* pcie ue header log */
2396313Skrishnae 	uint32_t pcie_ce_status;	/* pcie ce error status reg */
2406313Skrishnae 	uint32_t pcie_ce_mask;		/* pcie ce error mask reg */
2416313Skrishnae 	union {
2426313Skrishnae 		pf_pcie_adv_bdg_err_regs_t *pcie_adv_bdg_regs; /* bdg regs */
2436313Skrishnae 		pf_pcie_adv_rp_err_regs_t *pcie_adv_rp_regs;	 /* rp regs */
2446313Skrishnae 	} pcie_ext;
2456313Skrishnae 	uint32_t pcie_ue_tgt_trans;	/* Fault trans type from AER Logs */
2466313Skrishnae 	uint64_t pcie_ue_tgt_addr;	/* Fault addr from AER Logs */
2479921SKrishna.Elango@Sun.COM 	pcie_req_id_t pcie_ue_tgt_bdf;	/* Fault bdf from AER Logs */
2486313Skrishnae } pf_pcie_adv_err_regs_t;
2496313Skrishnae 
2506313Skrishnae typedef struct pf_pcie_rp_err_regs {
2516313Skrishnae 	uint32_t pcie_rp_status;	/* root complex status register */
2526313Skrishnae 	uint16_t pcie_rp_ctl;		/* root complex control register */
2536313Skrishnae } pf_pcie_rp_err_regs_t;
2543274Set142600 
2556313Skrishnae typedef struct pf_pcie_err_regs {
2566313Skrishnae 	uint16_t pcie_err_status;	/* pcie device status register */
2576313Skrishnae 	uint16_t pcie_err_ctl;		/* pcie error control register */
2586313Skrishnae 	uint32_t pcie_dev_cap;		/* pcie device capabilities register */
2596313Skrishnae 	pf_pcie_rp_err_regs_t *pcie_rp_regs;	 /* pcie root complex regs */
2606313Skrishnae 	pf_pcie_adv_err_regs_t *pcie_adv_regs; /* pcie aer regs */
2616313Skrishnae } pf_pcie_err_regs_t;
2626313Skrishnae 
26311596SJason.Beloro@Sun.COM typedef enum {
26411596SJason.Beloro@Sun.COM 	PF_INTR_TYPE_NONE = 0,
26511596SJason.Beloro@Sun.COM 	PF_INTR_TYPE_FABRIC = 1,	/* Fabric Message */
26611596SJason.Beloro@Sun.COM 	PF_INTR_TYPE_DATA,		/* Data Access Failure, failed loads */
26711596SJason.Beloro@Sun.COM 	PF_INTR_TYPE_AER,		/* Root Port AER MSI */
26811596SJason.Beloro@Sun.COM 	PF_INTR_TYPE_INTERNAL		/* Chip specific internal errors */
26911596SJason.Beloro@Sun.COM } pf_intr_type_t;
27011596SJason.Beloro@Sun.COM 
27111596SJason.Beloro@Sun.COM typedef struct pf_root_eh_src {
27211596SJason.Beloro@Sun.COM 	pf_intr_type_t	intr_type;
27311596SJason.Beloro@Sun.COM 	void		*intr_data;	/* Interrupt Data */
27411596SJason.Beloro@Sun.COM } pf_root_eh_src_t;
27511596SJason.Beloro@Sun.COM 
2766313Skrishnae typedef struct pf_root_fault {
2779921SKrishna.Elango@Sun.COM 	pcie_req_id_t	scan_bdf;	/* BDF from error logs */
2789921SKrishna.Elango@Sun.COM 	uint64_t	scan_addr;	/* Addr from error logs */
2796313Skrishnae 	boolean_t	full_scan;	/* Option to do a full scan */
2806313Skrishnae } pf_root_fault_t;
2816313Skrishnae 
2826313Skrishnae typedef struct pf_data pf_data_t;
2836313Skrishnae 
28411245SZhijun.Fu@Sun.COM /*
28511245SZhijun.Fu@Sun.COM  * For hot plugged device, these data are init'ed during during probe
28611245SZhijun.Fu@Sun.COM  * For non-hotplugged device, these data are init'ed in pci_autoconfig (on x86),
28711245SZhijun.Fu@Sun.COM  * or in px_attach()(on sparc).
28811245SZhijun.Fu@Sun.COM  *
28911245SZhijun.Fu@Sun.COM  * For root complex the fields are initialized in pcie_rc_init_bus();
29011245SZhijun.Fu@Sun.COM  * for others part of the fields are initialized in pcie_init_bus(),
29111245SZhijun.Fu@Sun.COM  * and part of fields initialized in pcie_post_init_bus(). See comments
29211245SZhijun.Fu@Sun.COM  * on top of respective functions for details.
29311245SZhijun.Fu@Sun.COM  */
2946313Skrishnae typedef struct pcie_bus {
2956313Skrishnae 	/* Needed for PCI/PCIe fabric error handling */
2966313Skrishnae 	dev_info_t	*bus_dip;
2976313Skrishnae 	dev_info_t	*bus_rp_dip;
29810923SEvan.Yan@Sun.COM 	ddi_acc_handle_t bus_cfg_hdl;		/* error handling acc hdle */
2996313Skrishnae 	uint_t		bus_fm_flags;
30010923SEvan.Yan@Sun.COM 	uint_t		bus_soft_state;
3016313Skrishnae 
3026313Skrishnae 	/* Static PCI/PCIe information */
3036313Skrishnae 	pcie_req_id_t	bus_bdf;
3046313Skrishnae 	pcie_req_id_t	bus_rp_bdf;		/* BDF of device's Root Port */
3056313Skrishnae 	uint32_t	bus_dev_ven_id;		/* device/vendor ID */
3066313Skrishnae 	uint8_t		bus_rev_id;		/* revision ID */
3076313Skrishnae 	uint8_t		bus_hdr_type;		/* pci header type, see pci.h */
3086313Skrishnae 	uint16_t	bus_dev_type;		/* PCI-E dev type, see pcie.h */
3096313Skrishnae 	uint8_t		bus_bdg_secbus;		/* Bridge secondary bus num */
3106313Skrishnae 	uint16_t	bus_pcie_off;		/* PCIe Capability Offset */
3116313Skrishnae 	uint16_t	bus_aer_off;		/* PCIe Advanced Error Offset */
3126313Skrishnae 	uint16_t	bus_pcix_off;		/* PCIx Capability Offset */
31310923SEvan.Yan@Sun.COM 	uint16_t	bus_pci_hp_off;		/* PCI HP (SHPC) Cap Offset */
3146313Skrishnae 	uint16_t	bus_ecc_ver;		/* PCIX ecc version */
3156313Skrishnae 	pci_bus_range_t	bus_bus_range;		/* pci bus-range property */
3166313Skrishnae 	ppb_ranges_t	*bus_addr_ranges;	/* pci range property */
3176313Skrishnae 	int		bus_addr_entries;	/* number of range prop */
3186313Skrishnae 	pci_regspec_t	*bus_assigned_addr;	/* "assigned-address" prop */
3196313Skrishnae 	int		bus_assigned_entries;	/* number of prop entries */
3206313Skrishnae 
3216313Skrishnae 	/* Cache of last fault data */
3226313Skrishnae 	pf_data_t	*bus_pfd;
32311596SJason.Beloro@Sun.COM 	pcie_domain_t	*bus_dom;
3247596SAlan.Adamson@Sun.COM 
3257596SAlan.Adamson@Sun.COM 	int		bus_mps;		/* Maximum Payload Size */
3269455SKrishna.Elango@Sun.COM 
3279455SKrishna.Elango@Sun.COM 	void		*bus_plat_private;	/* Platform specific */
32810923SEvan.Yan@Sun.COM 	/* Hotplug specific fields */
32910923SEvan.Yan@Sun.COM 	pcie_hp_mode_t	bus_hp_sup_modes;	/* HP modes supported */
33010923SEvan.Yan@Sun.COM 	pcie_hp_mode_t	bus_hp_curr_mode;	/* HP mode used */
33110923SEvan.Yan@Sun.COM 	void		*bus_hp_ctrl;		/* HP bus ctrl data */
33210923SEvan.Yan@Sun.COM 	int		bus_ari;		/* ARI device */
33311245SZhijun.Fu@Sun.COM 
33411245SZhijun.Fu@Sun.COM 	uint64_t	bus_cfgacc_base;	/* config space base address */
335*12262SAlan.Adamson@Sun.COM 
336*12262SAlan.Adamson@Sun.COM 	/* workaround for PCI/PCI-X devs behind PCIe2PCI Bridge */
337*12262SAlan.Adamson@Sun.COM 	pcie_req_id_t   bus_pcie2pci_secbus;
3386313Skrishnae } pcie_bus_t;
3393274Set142600 
34011596SJason.Beloro@Sun.COM /*
34111596SJason.Beloro@Sun.COM  * Data structure to log what devices are affected in relationship to the
34211596SJason.Beloro@Sun.COM  * severity after all the errors bits have been analyzed.
34311596SJason.Beloro@Sun.COM  */
34411596SJason.Beloro@Sun.COM #define	PF_AFFECTED_ROOT	(1 << 0) /* RP/RC is affected */
34511596SJason.Beloro@Sun.COM #define	PF_AFFECTED_SELF	(1 << 1) /* Reporting Device is affected */
34611596SJason.Beloro@Sun.COM #define	PF_AFFECTED_PARENT	(1 << 2) /* Parent device is affected */
34711596SJason.Beloro@Sun.COM #define	PF_AFFECTED_CHILDREN	(1 << 3) /* All children below are affected */
34811596SJason.Beloro@Sun.COM #define	PF_AFFECTED_BDF		(1 << 4) /* See affected_bdf */
34911596SJason.Beloro@Sun.COM #define	PF_AFFECTED_AER		(1 << 5) /* See AER Registers */
35011596SJason.Beloro@Sun.COM #define	PF_AFFECTED_SAER	(1 << 6) /* See SAER Registers */
35111596SJason.Beloro@Sun.COM #define	PF_AFFECTED_ADDR	(1 << 7) /* Device targeted by addr */
35211596SJason.Beloro@Sun.COM 
35311596SJason.Beloro@Sun.COM #define	PF_MAX_AFFECTED_FLAG	PF_AFFECTED_ADDR
35411596SJason.Beloro@Sun.COM 
35511596SJason.Beloro@Sun.COM typedef struct pf_affected_dev {
35611596SJason.Beloro@Sun.COM 	uint16_t		pe_affected_flags;
35711596SJason.Beloro@Sun.COM 	pcie_req_id_t		pe_affected_bdf;
35811596SJason.Beloro@Sun.COM } pf_affected_dev_t;
35911596SJason.Beloro@Sun.COM 
3606313Skrishnae struct pf_data {
3616313Skrishnae 	boolean_t		pe_lock;
3626313Skrishnae 	boolean_t		pe_valid;
3636313Skrishnae 	uint32_t		pe_severity_flags;	/* Severity of error */
36411596SJason.Beloro@Sun.COM 	uint32_t		pe_orig_severity_flags; /* Original severity */
36511596SJason.Beloro@Sun.COM 	pf_affected_dev_t	*pe_affected_dev;
3666313Skrishnae 	pcie_bus_t		*pe_bus_p;
36711596SJason.Beloro@Sun.COM 	pf_root_fault_t		*pe_root_fault; /* Only valid for RC and RP */
36811596SJason.Beloro@Sun.COM 	pf_root_eh_src_t	*pe_root_eh_src; /* Only valid for RC and RP */
3696313Skrishnae 	pf_pci_err_regs_t	*pe_pci_regs;	/* PCI error reg */
3706313Skrishnae 	union {
3716313Skrishnae 		pf_pcix_err_regs_t	*pe_pcix_regs;	/* PCI-X error reg */
3726313Skrishnae 		pf_pcie_err_regs_t	*pe_pcie_regs;	/* PCIe error reg */
3736313Skrishnae 	} pe_ext;
3746313Skrishnae 	pf_pcix_bdg_err_regs_t *pe_pcix_bdg_regs; /* PCI-X bridge regs */
3756313Skrishnae 	pf_data_t		*pe_prev;	/* Next error in queue */
3766313Skrishnae 	pf_data_t		*pe_next;	/* Next error in queue */
3777848SKrishna.Elango@Sun.COM 	boolean_t		pe_rber_fatal;
3786313Skrishnae };
3796313Skrishnae 
3806313Skrishnae /* Information used while handling errors in the fabric. */
3816313Skrishnae typedef struct pf_impl {
3826313Skrishnae 	ddi_fm_error_t	*pf_derr;
3836313Skrishnae 	pf_root_fault_t	*pf_fault;	/* captured fault bdf/addr to scan */
3846313Skrishnae 	pf_data_t	*pf_dq_head_p;	/* ptr to fault data queue */
3856313Skrishnae 	pf_data_t	*pf_dq_tail_p;	/* ptr pt last fault data q */
3866313Skrishnae 	uint32_t	pf_total;	/* total non RC pf_datas */
3876313Skrishnae } pf_impl_t;
3886313Skrishnae 
3896313Skrishnae /* bus_fm_flags field */
3906313Skrishnae #define	PF_FM_READY		(1 << 0)	/* bus_fm_lock initialized */
3916313Skrishnae #define	PF_FM_IS_NH		(1 << 1)	/* known as non-hardened */
3923274Set142600 
3936313Skrishnae /*
3946313Skrishnae  * PCIe fabric handle lookup address flags.  Used to define what type of
3956313Skrishnae  * transaction the address is for.  These same value are defined again in
3966313Skrishnae  * fabric-xlate FM module.  Do not modify these variables, without modifying
3976313Skrishnae  * those.
3986313Skrishnae  */
3996313Skrishnae #define	PF_ADDR_DMA		(1 << 0)
4006313Skrishnae #define	PF_ADDR_PIO		(1 << 1)
4016313Skrishnae #define	PF_ADDR_CFG		(1 << 2)
4023274Set142600 
4036313Skrishnae /* PCIe fabric error scanning status flags */
4046313Skrishnae #define	PF_SCAN_SUCCESS		(1 << 0)
4056313Skrishnae #define	PF_SCAN_CB_FAILURE	(1 << 1) /* hardened device callback failure */
4066313Skrishnae #define	PF_SCAN_NO_ERR_IN_CHILD	(1 << 2) /* no errors in bridge sec stat reg */
4076313Skrishnae #define	PF_SCAN_IN_DQ		(1 << 3) /* already present in the faultq */
4086313Skrishnae #define	PF_SCAN_DEADLOCK	(1 << 4) /* deadlock detected */
4096313Skrishnae #define	PF_SCAN_BAD_RESPONSE	(1 << 5) /* Incorrect device response */
4106313Skrishnae 
4116313Skrishnae /* PCIe fabric error handling severity return flags */
4126313Skrishnae #define	PF_ERR_NO_ERROR		(1 << 0) /* No error seen */
4136313Skrishnae #define	PF_ERR_CE		(1 << 1) /* Correctable Error */
4146313Skrishnae #define	PF_ERR_NO_PANIC		(1 << 2) /* Error should not panic sys */
4156313Skrishnae #define	PF_ERR_MATCHED_DEVICE	(1 << 3) /* Error Handled By Device */
4166313Skrishnae #define	PF_ERR_MATCHED_RC	(1 << 4) /* Error Handled By RC */
4176313Skrishnae #define	PF_ERR_MATCHED_PARENT	(1 << 5) /* Error Handled By Parent */
4186313Skrishnae #define	PF_ERR_PANIC		(1 << 6) /* Error should panic system */
4196313Skrishnae #define	PF_ERR_PANIC_DEADLOCK	(1 << 7) /* deadlock detected */
42011596SJason.Beloro@Sun.COM #define	PF_ERR_PANIC_BAD_RESPONSE (1 << 8) /* Device no response */
42111596SJason.Beloro@Sun.COM #define	PF_ERR_MATCH_DOM	(1 << 9) /* Error Handled By IO domain */
4226313Skrishnae 
42311596SJason.Beloro@Sun.COM #define	PF_ERR_FATAL_FLAGS		\
42411596SJason.Beloro@Sun.COM 	(PF_ERR_PANIC | PF_ERR_PANIC_DEADLOCK | PF_ERR_PANIC_BAD_RESPONSE)
4256313Skrishnae 
4266313Skrishnae #define	PF_HDL_FOUND		1
4276313Skrishnae #define	PF_HDL_NOTFOUND		2
4286313Skrishnae 
4299921SKrishna.Elango@Sun.COM /*
4309921SKrishna.Elango@Sun.COM  * PCIe Capability Device Type Pseudo Definitions.
4319921SKrishna.Elango@Sun.COM  *
4329921SKrishna.Elango@Sun.COM  * PCI_PSEUDO is used on real PCI devices.  The Legacy PCI definition in the
4339921SKrishna.Elango@Sun.COM  * PCIe spec really refers to PCIe devices that *require* IO Space access.  IO
4349921SKrishna.Elango@Sun.COM  * Space access is usually frowned upon now in PCIe, but there for legacy
4359921SKrishna.Elango@Sun.COM  * purposes.
4369921SKrishna.Elango@Sun.COM  */
4379921SKrishna.Elango@Sun.COM #define	PCIE_PCIECAP_DEV_TYPE_RC_PSEUDO		0x100
4389921SKrishna.Elango@Sun.COM #define	PCIE_PCIECAP_DEV_TYPE_PCI_PSEUDO	0x101
4399921SKrishna.Elango@Sun.COM 
4409921SKrishna.Elango@Sun.COM #define	PCIE_INVALID_BDF	0xFFFF
4419921SKrishna.Elango@Sun.COM #define	PCIE_CHECK_VALID_BDF(x)	(x != PCIE_INVALID_BDF)
4423274Set142600 
4437596SAlan.Adamson@Sun.COM typedef struct {
4447596SAlan.Adamson@Sun.COM 	dev_info_t	*dip;
4457596SAlan.Adamson@Sun.COM 	int		highest_common_mps;
4467596SAlan.Adamson@Sun.COM } pcie_max_supported_t;
4477596SAlan.Adamson@Sun.COM 
44810923SEvan.Yan@Sun.COM /*
44910923SEvan.Yan@Sun.COM  * Default interrupt priority for all PCI and PCIe nexus drivers including
45010923SEvan.Yan@Sun.COM  * hotplug interrupts.
45110923SEvan.Yan@Sun.COM  */
45210923SEvan.Yan@Sun.COM #define	PCIE_INTR_PRI		(LOCK_LEVEL - 1)
45310923SEvan.Yan@Sun.COM 
45410923SEvan.Yan@Sun.COM /*
45510923SEvan.Yan@Sun.COM  * XXX - PCIE_IS_PCIE check is required in order not to invoke these macros
45610923SEvan.Yan@Sun.COM  * for non-standard PCI or PCI Express Hotplug Controllers.
45710923SEvan.Yan@Sun.COM  */
45810923SEvan.Yan@Sun.COM #define	PCIE_ENABLE_ERRORS(dip)	\
45910923SEvan.Yan@Sun.COM 	if (PCIE_IS_PCIE(PCIE_DIP2BUS(dip))) {	\
46010923SEvan.Yan@Sun.COM 		pcie_enable_errors(dip);	\
46110923SEvan.Yan@Sun.COM 		(void) pcie_enable_ce(dip);	\
46210923SEvan.Yan@Sun.COM 	}
46310923SEvan.Yan@Sun.COM 
46410923SEvan.Yan@Sun.COM #define	PCIE_DISABLE_ERRORS(dip)		\
46510923SEvan.Yan@Sun.COM 	if (PCIE_IS_PCIE(PCIE_DIP2BUS(dip))) {	\
46610923SEvan.Yan@Sun.COM 		pcie_disable_errors(dip);	\
46710923SEvan.Yan@Sun.COM 	}
46810923SEvan.Yan@Sun.COM 
46911245SZhijun.Fu@Sun.COM /*
47011245SZhijun.Fu@Sun.COM  * pcie_init_buspcie_fini_bus specific flags
47111245SZhijun.Fu@Sun.COM  */
47211245SZhijun.Fu@Sun.COM #define	PCIE_BUS_INITIAL	0x0001
47311245SZhijun.Fu@Sun.COM #define	PCIE_BUS_FINAL		0x0002
47411245SZhijun.Fu@Sun.COM #define	PCIE_BUS_ALL		(PCIE_BUS_INITIAL | PCIE_BUS_FINAL)
47511245SZhijun.Fu@Sun.COM 
4769455SKrishna.Elango@Sun.COM #ifdef	DEBUG
4779455SKrishna.Elango@Sun.COM #define	PCIE_DBG pcie_dbg
4789455SKrishna.Elango@Sun.COM /* Common Debugging shortcuts */
4799455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CFG(dip, bus_p, name, sz, off, org) \
4809455SKrishna.Elango@Sun.COM 	PCIE_DBG("%s:%d:(0x%x) %s(0x%x) 0x%x -> 0x%x\n", ddi_node_name(dip), \
4819455SKrishna.Elango@Sun.COM 	    ddi_get_instance(dip), bus_p->bus_bdf, name, off, org, \
4829455SKrishna.Elango@Sun.COM 	    PCIE_GET(sz, bus_p, off))
4839455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CAP(dip, bus_p, name, sz, off, org) \
4849455SKrishna.Elango@Sun.COM 	PCIE_DBG("%s:%d:(0x%x) %s(0x%x) 0x%x -> 0x%x\n", ddi_node_name(dip), \
4859455SKrishna.Elango@Sun.COM 	    ddi_get_instance(dip), bus_p->bus_bdf, name, off, org, \
4869455SKrishna.Elango@Sun.COM 	    PCIE_CAP_GET(sz, bus_p, off))
4879455SKrishna.Elango@Sun.COM #define	PCIE_DBG_AER(dip, bus_p, name, sz, off, org) \
4889455SKrishna.Elango@Sun.COM 	PCIE_DBG("%s:%d:(0x%x) %s(0x%x) 0x%x -> 0x%x\n", ddi_node_name(dip), \
4899455SKrishna.Elango@Sun.COM 	    ddi_get_instance(dip), bus_p->bus_bdf, name, off, org, \
4909455SKrishna.Elango@Sun.COM 	    PCIE_AER_GET(sz, bus_p, off))
4919455SKrishna.Elango@Sun.COM 
4929455SKrishna.Elango@Sun.COM #else	/* DEBUG */
4939455SKrishna.Elango@Sun.COM 
4949455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CFG 0 &&
4959455SKrishna.Elango@Sun.COM #define	PCIE_DBG 0 &&
49610923SEvan.Yan@Sun.COM #define	PCIE_ARI_DBG 0 &&
4979455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CAP 0 &&
4989455SKrishna.Elango@Sun.COM #define	PCIE_DBG_AER 0 &&
4999455SKrishna.Elango@Sun.COM 
5009455SKrishna.Elango@Sun.COM #endif	/* DEBUG */
5019455SKrishna.Elango@Sun.COM 
5023274Set142600 /* PCIe Friendly Functions */
50310923SEvan.Yan@Sun.COM extern int pcie_init(dev_info_t *dip, caddr_t arg);
50410923SEvan.Yan@Sun.COM extern int pcie_uninit(dev_info_t *dip);
50511445SEvan.Yan@Sun.COM extern int pcie_hpintr_enable(dev_info_t *dip);
50611445SEvan.Yan@Sun.COM extern int pcie_hpintr_disable(dev_info_t *dip);
50710923SEvan.Yan@Sun.COM extern int pcie_intr(dev_info_t *dip);
50810923SEvan.Yan@Sun.COM extern int pcie_open(dev_info_t *dip, dev_t *devp, int flags, int otyp,
50910923SEvan.Yan@Sun.COM     cred_t *credp);
51010923SEvan.Yan@Sun.COM extern int pcie_close(dev_info_t *dip, dev_t dev, int flags, int otyp,
51110923SEvan.Yan@Sun.COM     cred_t *credp);
51210923SEvan.Yan@Sun.COM extern int pcie_ioctl(dev_info_t *dip, dev_t dev, int cmd, intptr_t arg,
51310923SEvan.Yan@Sun.COM     int mode, cred_t *credp, int *rvalp);
51410923SEvan.Yan@Sun.COM extern int pcie_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op,
51510923SEvan.Yan@Sun.COM     int flags, char *name, caddr_t valuep, int *lengthp);
51610923SEvan.Yan@Sun.COM 
5178495SAlan.Adamson@Sun.COM extern void pcie_init_root_port_mps(dev_info_t *dip);
51827Sjchu extern int pcie_initchild(dev_info_t *dip);
51927Sjchu extern void pcie_uninitchild(dev_info_t *dip);
52011245SZhijun.Fu@Sun.COM extern int pcie_init_cfghdl(dev_info_t *dip);
52111245SZhijun.Fu@Sun.COM extern void pcie_fini_cfghdl(dev_info_t *dip);
5226313Skrishnae extern void pcie_clear_errors(dev_info_t *dip);
5232738Skrishnae extern int pcie_postattach_child(dev_info_t *dip);
5246313Skrishnae extern void pcie_enable_errors(dev_info_t *dip);
5256313Skrishnae extern void pcie_disable_errors(dev_info_t *dip);
5266313Skrishnae extern int pcie_enable_ce(dev_info_t *dip);
5276313Skrishnae extern boolean_t pcie_bridge_is_link_disabled(dev_info_t *);
5286313Skrishnae 
52911245SZhijun.Fu@Sun.COM extern pcie_bus_t *pcie_init_bus(dev_info_t *dip, pcie_req_id_t bdf,
53011245SZhijun.Fu@Sun.COM     uint8_t flags);
53111245SZhijun.Fu@Sun.COM extern void pcie_fini_bus(dev_info_t *dip, uint8_t flags);
53211245SZhijun.Fu@Sun.COM extern void pcie_fab_init_bus(dev_info_t *dip, uint8_t flags);
53311245SZhijun.Fu@Sun.COM extern void pcie_fab_fini_bus(dev_info_t *dip, uint8_t flags);
5346313Skrishnae extern void pcie_rc_init_bus(dev_info_t *dip);
5356313Skrishnae extern void pcie_rc_fini_bus(dev_info_t *dip);
5366313Skrishnae extern void pcie_rc_init_pfd(dev_info_t *dip, pf_data_t *pfd);
5376313Skrishnae extern void pcie_rc_fini_pfd(pf_data_t *pfd);
5386313Skrishnae extern boolean_t pcie_is_child(dev_info_t *dip, dev_info_t *rdip);
5396313Skrishnae extern int pcie_get_bdf_from_dip(dev_info_t *dip, pcie_req_id_t *bdf);
5403156Sgirish extern dev_info_t *pcie_get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip);
5413249Sgovinda extern uint32_t pcie_get_bdf_for_dma_xfer(dev_info_t *dip, dev_info_t *rdip);
5427596SAlan.Adamson@Sun.COM extern int pcie_dev(dev_info_t *dip);
5437596SAlan.Adamson@Sun.COM extern void pcie_get_fabric_mps(dev_info_t *rc_dip, dev_info_t *dip,
5447596SAlan.Adamson@Sun.COM 	int *max_supported);
5457596SAlan.Adamson@Sun.COM extern int pcie_root_port(dev_info_t *dip);
5467596SAlan.Adamson@Sun.COM extern int pcie_initchild_mps(dev_info_t *dip);
5477848SKrishna.Elango@Sun.COM extern void pcie_set_rber_fatal(dev_info_t *dip, boolean_t val);
5487848SKrishna.Elango@Sun.COM extern boolean_t pcie_get_rber_fatal(dev_info_t *dip);
5493274Set142600 
5506313Skrishnae extern uint32_t pcie_get_aer_uce_mask();
5516313Skrishnae extern uint32_t pcie_get_aer_ce_mask();
5526313Skrishnae extern uint32_t pcie_get_aer_suce_mask();
5536313Skrishnae extern uint32_t pcie_get_serr_mask();
5546313Skrishnae extern void pcie_set_aer_uce_mask(uint32_t mask);
5556313Skrishnae extern void pcie_set_aer_ce_mask(uint32_t mask);
5566313Skrishnae extern void pcie_set_aer_suce_mask(uint32_t mask);
5576313Skrishnae extern void pcie_set_serr_mask(uint32_t mask);
5589455SKrishna.Elango@Sun.COM extern void pcie_init_plat(dev_info_t *dip);
5599455SKrishna.Elango@Sun.COM extern void pcie_fini_plat(dev_info_t *dip);
56010923SEvan.Yan@Sun.COM extern int pcie_read_only_probe(dev_info_t *, char *, dev_info_t **);
56110923SEvan.Yan@Sun.COM extern dev_info_t *pcie_func_to_dip(dev_info_t *dip, pcie_req_id_t function);
56210923SEvan.Yan@Sun.COM extern int pcie_ari_disable(dev_info_t *dip);
56310923SEvan.Yan@Sun.COM extern int pcie_ari_enable(dev_info_t *dip);
56410923SEvan.Yan@Sun.COM 
56510923SEvan.Yan@Sun.COM #define	PCIE_ARI_FORW_NOT_SUPPORTED	0
56610923SEvan.Yan@Sun.COM #define	PCIE_ARI_FORW_SUPPORTED		1
56710923SEvan.Yan@Sun.COM 
56810923SEvan.Yan@Sun.COM extern int pcie_ari_supported(dev_info_t *dip);
56910923SEvan.Yan@Sun.COM 
57010923SEvan.Yan@Sun.COM #define	PCIE_ARI_FORW_DISABLED	0
57110923SEvan.Yan@Sun.COM #define	PCIE_ARI_FORW_ENABLED	1
57210923SEvan.Yan@Sun.COM 
57310923SEvan.Yan@Sun.COM extern int pcie_ari_is_enabled(dev_info_t *dip);
57410923SEvan.Yan@Sun.COM 
57510923SEvan.Yan@Sun.COM #define	PCIE_NOT_ARI_DEVICE		0
57610923SEvan.Yan@Sun.COM #define	PCIE_ARI_DEVICE			1
57710923SEvan.Yan@Sun.COM 
57810923SEvan.Yan@Sun.COM extern int pcie_ari_device(dev_info_t *dip);
57910923SEvan.Yan@Sun.COM extern int pcie_ari_get_next_function(dev_info_t *dip, int *func);
5803274Set142600 
5813274Set142600 /* PCIe error handling functions */
58211596SJason.Beloro@Sun.COM extern void pf_eh_enter(pcie_bus_t *bus_p);
58311596SJason.Beloro@Sun.COM extern void pf_eh_exit(pcie_bus_t *bus_p);
5843274Set142600 extern int pf_scan_fabric(dev_info_t *rpdip, ddi_fm_error_t *derr,
5856313Skrishnae     pf_data_t *root_pfd_p);
5866313Skrishnae extern void pf_init(dev_info_t *, ddi_iblock_cookie_t, ddi_attach_cmd_t);
5876313Skrishnae extern void pf_fini(dev_info_t *, ddi_detach_cmd_t);
5886313Skrishnae extern int pf_hdl_lookup(dev_info_t *, uint64_t, uint32_t, uint64_t,
5896313Skrishnae     pcie_req_id_t);
5906313Skrishnae extern int pf_tlp_decode(pcie_bus_t *, pf_pcie_adv_err_regs_t *);
59111040SPavel.Potoplyak@Sun.COM extern void pcie_force_fullscan();
59227Sjchu 
59310923SEvan.Yan@Sun.COM #ifdef	DEBUG
59410923SEvan.Yan@Sun.COM extern uint_t pcie_debug_flags;
59510923SEvan.Yan@Sun.COM extern void pcie_dbg(char *fmt, ...);
59610923SEvan.Yan@Sun.COM #endif	/* DEBUG */
59710923SEvan.Yan@Sun.COM 
59811596SJason.Beloro@Sun.COM /* PCIe IOV functions */
59911596SJason.Beloro@Sun.COM extern dev_info_t *pcie_find_dip_by_bdf(dev_info_t *rootp, pcie_req_id_t bdf);
60011596SJason.Beloro@Sun.COM 
60111596SJason.Beloro@Sun.COM extern boolean_t pf_in_bus_range(pcie_bus_t *, pcie_req_id_t);
60211596SJason.Beloro@Sun.COM extern boolean_t pf_in_assigned_addr(pcie_bus_t *, uint64_t);
60311596SJason.Beloro@Sun.COM extern int pf_pci_decode(pf_data_t *, uint16_t *);
60411596SJason.Beloro@Sun.COM extern pcie_bus_t *pf_find_busp_by_bdf(pf_impl_t *, pcie_req_id_t);
60511596SJason.Beloro@Sun.COM extern pcie_bus_t *pf_find_busp_by_addr(pf_impl_t *, uint64_t);
60611596SJason.Beloro@Sun.COM extern pcie_bus_t *pf_find_busp_by_aer(pf_impl_t *, pf_data_t *);
60711596SJason.Beloro@Sun.COM extern pcie_bus_t *pf_find_busp_by_saer(pf_impl_t *, pf_data_t *);
60811596SJason.Beloro@Sun.COM 
60911596SJason.Beloro@Sun.COM extern int pciev_eh(pf_data_t *, pf_impl_t *);
61011596SJason.Beloro@Sun.COM extern pcie_bus_t *pciev_get_affected_dev(pf_impl_t *, pf_data_t *,
61111596SJason.Beloro@Sun.COM     uint16_t, uint16_t);
61211596SJason.Beloro@Sun.COM extern void pciev_eh_exit(pf_data_t *, uint_t);
61311596SJason.Beloro@Sun.COM extern boolean_t pcie_in_domain(pcie_bus_t *, uint_t);
61411596SJason.Beloro@Sun.COM 
61511596SJason.Beloro@Sun.COM #define	PCIE_ZALLOC(data) kmem_zalloc(sizeof (data), KM_SLEEP)
61611596SJason.Beloro@Sun.COM 
61711596SJason.Beloro@Sun.COM 
61827Sjchu #ifdef	__cplusplus
61927Sjchu }
62027Sjchu #endif
62127Sjchu 
62227Sjchu #endif	/* _SYS_PCIE_IMPL_H */
623