xref: /onnv-gate/usr/src/uts/common/sys/pcie_impl.h (revision 10187:ad62e2dfbe0c)
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 /*
228495SAlan.Adamson@Sun.COM  * Copyright 2009 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>
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*10187SKrishna.Elango@Sun.COM 	PCIE_DIP2BUS(dip)->bus_bdg_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))
613274Set142600 
626313Skrishnae #define	PCIE_IS_PCIE(bus_p) (bus_p->bus_pcie_off)
636313Skrishnae #define	PCIE_IS_PCIX(bus_p) (bus_p->bus_pcix_off)
649921SKrishna.Elango@Sun.COM #define	PCIE_IS_PCI(bus_p) (!PCIE_IS_PCIE(bus_p))
656313Skrishnae #define	PCIE_HAS_AER(bus_p) (bus_p->bus_aer_off)
666313Skrishnae /* IS_ROOT = is RC or RP */
676313Skrishnae #define	PCIE_IS_ROOT(bus_p) (PCIE_IS_RC(bus_p) || PCIE_IS_RP(bus_p))
686313Skrishnae /*
696313Skrishnae  * This is a pseudo pcie "device type", but it's needed to explain describe
706313Skrishnae  * nodes such as PX and NPE, which aren't really PCI devices but do control or
716313Skrishnae  * interaction with PCI error handling.
726313Skrishnae  */
736313Skrishnae #define	PCIE_IS_RC(bus_p) \
746313Skrishnae 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_RC_PSEUDO)
756313Skrishnae #define	PCIE_IS_RP(bus_p) \
766313Skrishnae 	((bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_ROOT) && \
776313Skrishnae 	    PCIE_IS_PCIE(bus_p))
789921SKrishna.Elango@Sun.COM #define	PCIE_IS_SWU(bus_p) \
799921SKrishna.Elango@Sun.COM 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_UP)
809921SKrishna.Elango@Sun.COM #define	PCIE_IS_SWD(bus_p) \
819921SKrishna.Elango@Sun.COM 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_DOWN)
826313Skrishnae #define	PCIE_IS_SW(bus_p) \
839921SKrishna.Elango@Sun.COM 	(PCIE_IS_SWU(bus_p) || PCIE_IS_SWD(bus_p))
846313Skrishnae #define	PCIE_IS_BDG(bus_p)  (bus_p->bus_hdr_type == PCI_HEADER_ONE)
859921SKrishna.Elango@Sun.COM #define	PCIE_IS_PCI_BDG(bus_p) (PCIE_IS_PCI(bus_p) && PCIE_IS_BDG(bus_p))
866313Skrishnae #define	PCIE_IS_PCIE_BDG(bus_p) \
876313Skrishnae 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_PCIE2PCI)
887987SErwin.Tsaur@Sun.COM #define	PCIE_IS_PCI2PCIE(bus_p) \
897987SErwin.Tsaur@Sun.COM 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_PCI2PCIE)
906313Skrishnae #define	PCIE_IS_PCIE_SEC(bus_p) \
916313Skrishnae 	(PCIE_IS_PCIE(bus_p) && PCIE_IS_BDG(bus_p) && !PCIE_IS_PCIE_BDG(bus_p))
926313Skrishnae #define	PCIX_ECC_VERSION_CHECK(bus_p) \
936313Skrishnae 	((bus_p->bus_ecc_ver == PCI_PCIX_VER_1) || \
946313Skrishnae 	    (bus_p->bus_ecc_ver == PCI_PCIX_VER_2))
953274Set142600 
966313Skrishnae #define	PCIE_VENID(bus_p)	(bus_p->bus_dev_ven_id & 0xffff)
976313Skrishnae #define	PCIE_DEVID(bus_p)	((bus_p->bus_dev_ven_id >> 16) & 0xffff)
983274Set142600 
996313Skrishnae /* PCIE Cap/AER shortcuts */
1006313Skrishnae #define	PCIE_GET(sz, bus_p, off) \
1016313Skrishnae 	pci_config_get ## sz(bus_p->bus_cfg_hdl, off)
1026313Skrishnae #define	PCIE_PUT(sz, bus_p, off, val) \
1036313Skrishnae 	pci_config_put ## sz(bus_p->bus_cfg_hdl, off, val)
1046313Skrishnae #define	PCIE_CAP_GET(sz, bus_p, off) \
1056313Skrishnae 	PCI_CAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcie_off, off)
1066313Skrishnae #define	PCIE_CAP_PUT(sz, bus_p, off, val) \
1076313Skrishnae 	PCI_CAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcie_off, off, \
1086313Skrishnae 	    val)
1096313Skrishnae #define	PCIE_AER_GET(sz, bus_p, off) \
1106313Skrishnae 	PCI_XCAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_aer_off, off)
1116313Skrishnae #define	PCIE_AER_PUT(sz, bus_p, off, val) \
1126313Skrishnae 	PCI_XCAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_aer_off, off, \
1136313Skrishnae 	    val)
1146313Skrishnae #define	PCIX_CAP_GET(sz, bus_p, off) \
1156313Skrishnae 	PCI_CAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcix_off, off)
1166313Skrishnae #define	PCIX_CAP_PUT(sz, bus_p, off, val) \
1176313Skrishnae 	PCI_CAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcix_off, off, \
1186313Skrishnae 	    val)
1193274Set142600 
1206313Skrishnae /* Translate PF error return values to DDI_FM values */
1216313Skrishnae #define	PF_ERR2DDIFM_ERR(sts) \
1226313Skrishnae 	(sts & PF_ERR_FATAL_FLAGS ? DDI_FM_FATAL :	\
1236313Skrishnae 	(sts == PF_ERR_NO_ERROR ? DDI_FM_OK : DDI_FM_NONFATAL))
1243274Set142600 
12527Sjchu /*
1262549Sgovinda  * The following flag is used for Broadcom 5714/5715 bridge prefetch issue.
127*10187SKrishna.Elango@Sun.COM  * This flag will be used both by px and pcieb nexus drivers.
1282549Sgovinda  */
1292549Sgovinda #define	PX_DMAI_FLAGS_MAP_BUFZONE	0x40000
1302549Sgovinda 
1316313Skrishnae /*
1326313Skrishnae  * PCI(e/-X) structures used to to gather and report errors detected by
1336313Skrishnae  * PCI(e/-X) compliant devices.  These registers only contain "dynamic" data.
1346313Skrishnae  * Static data such as Capability Offsets and Version #s is saved in the parent
1356313Skrishnae  * private data.
1366313Skrishnae  */
1376313Skrishnae #define	PCI_ERR_REG(pfd_p)	   pfd_p->pe_pci_regs
1386313Skrishnae #define	PCI_BDG_ERR_REG(pfd_p)	   PCI_ERR_REG(pfd_p)->pci_bdg_regs
1396313Skrishnae #define	PCIX_ERR_REG(pfd_p)	   pfd_p->pe_ext.pe_pcix_regs
1406313Skrishnae #define	PCIX_ECC_REG(pfd_p)	   PCIX_ERR_REG(pfd_p)->pcix_ecc_regs
1416313Skrishnae #define	PCIX_BDG_ERR_REG(pfd_p)	   pfd_p->pe_pcix_bdg_regs
1426313Skrishnae #define	PCIX_BDG_ECC_REG(pfd_p, n) PCIX_BDG_ERR_REG(pfd_p)->pcix_bdg_ecc_regs[n]
1436313Skrishnae #define	PCIE_ERR_REG(pfd_p)	   pfd_p->pe_ext.pe_pcie_regs
1446313Skrishnae #define	PCIE_RP_REG(pfd_p)	   PCIE_ERR_REG(pfd_p)->pcie_rp_regs
1456313Skrishnae #define	PCIE_ROOT_FAULT(pfd_p)	   pfd_p->pe_root_fault
1466313Skrishnae #define	PCIE_ADV_REG(pfd_p)	   PCIE_ERR_REG(pfd_p)->pcie_adv_regs
1476313Skrishnae #define	PCIE_ADV_HDR(pfd_p, n)	   PCIE_ADV_REG(pfd_p)->pcie_ue_hdr[n]
1486313Skrishnae #define	PCIE_ADV_BDG_REG(pfd_p) \
1496313Skrishnae 	PCIE_ADV_REG(pfd_p)->pcie_ext.pcie_adv_bdg_regs
1506313Skrishnae #define	PCIE_ADV_BDG_HDR(pfd_p, n) PCIE_ADV_BDG_REG(pfd_p)->pcie_sue_hdr[n]
1516313Skrishnae #define	PCIE_ADV_RP_REG(pfd_p) \
1526313Skrishnae 	PCIE_ADV_REG(pfd_p)->pcie_ext.pcie_adv_rp_regs
1536313Skrishnae #define	PFD_IS_ROOT(pfd_p)	   PCIE_IS_ROOT(PCIE_PFD2BUS(pfd_p))
1546313Skrishnae #define	PFD_IS_RC(pfd_p)	   PCIE_IS_RC(PCIE_PFD2BUS(pfd_p))
1556313Skrishnae #define	PFD_IS_RP(pfd_p)	   PCIE_IS_RP(PCIE_PFD2BUS(pfd_p))
1566313Skrishnae 
1576313Skrishnae typedef struct pf_pci_bdg_err_regs {
1586313Skrishnae 	uint16_t pci_bdg_sec_stat;	/* PCI secondary status reg */
1596313Skrishnae 	uint16_t pci_bdg_ctrl;		/* PCI bridge control reg */
1606313Skrishnae } pf_pci_bdg_err_regs_t;
1616313Skrishnae 
1626313Skrishnae typedef struct pf_pci_err_regs {
1636313Skrishnae 	uint16_t pci_err_status;	/* pci status register */
1646313Skrishnae 	uint16_t pci_cfg_comm;		/* pci command register */
1656313Skrishnae 	pf_pci_bdg_err_regs_t *pci_bdg_regs;
1666313Skrishnae } pf_pci_err_regs_t;
1676313Skrishnae 
1686313Skrishnae typedef struct pf_pcix_ecc_regs {
1696313Skrishnae 	uint32_t pcix_ecc_ctlstat;	/* pcix ecc control status reg */
1706313Skrishnae 	uint32_t pcix_ecc_fstaddr;	/* pcix ecc first address reg */
1716313Skrishnae 	uint32_t pcix_ecc_secaddr;	/* pcix ecc second address reg */
1726313Skrishnae 	uint32_t pcix_ecc_attr;		/* pcix ecc attributes reg */
1736313Skrishnae } pf_pcix_ecc_regs_t;
1743274Set142600 
1756313Skrishnae typedef struct pf_pcix_err_regs {
1766313Skrishnae 	uint16_t pcix_command;		/* pcix command register */
1776313Skrishnae 	uint32_t pcix_status;		/* pcix status register */
1786313Skrishnae 	pf_pcix_ecc_regs_t *pcix_ecc_regs;	/* pcix ecc registers */
1796313Skrishnae } pf_pcix_err_regs_t;
1806313Skrishnae 
1816313Skrishnae typedef struct pf_pcix_bdg_err_regs {
1826313Skrishnae 	uint16_t pcix_bdg_sec_stat;	/* pcix bridge secondary status reg */
1836313Skrishnae 	uint32_t pcix_bdg_stat;		/* pcix bridge status reg */
1846313Skrishnae 	pf_pcix_ecc_regs_t *pcix_bdg_ecc_regs[2];	/* pcix ecc registers */
1856313Skrishnae } pf_pcix_bdg_err_regs_t;
1866313Skrishnae 
1876313Skrishnae typedef struct pf_pcie_adv_bdg_err_regs {
1886313Skrishnae 	uint32_t pcie_sue_ctl;		/* pcie bridge secondary ue control */
1896313Skrishnae 	uint32_t pcie_sue_status;	/* pcie bridge secondary ue status */
1906313Skrishnae 	uint32_t pcie_sue_mask;		/* pcie bridge secondary ue mask */
1916313Skrishnae 	uint32_t pcie_sue_sev;		/* pcie bridge secondary ue severity */
1926313Skrishnae 	uint32_t pcie_sue_hdr[4];	/* pcie bridge secondary ue hdr log */
1936313Skrishnae 	uint32_t pcie_sue_tgt_trans;	/* Fault trans type from SAER Logs */
1946313Skrishnae 	uint64_t pcie_sue_tgt_addr;	/* Fault addr from SAER Logs */
1956313Skrishnae 	pcie_req_id_t pcie_sue_tgt_bdf;	/* Fault bdf from SAER Logs */
1966313Skrishnae } pf_pcie_adv_bdg_err_regs_t;
1973274Set142600 
1986313Skrishnae typedef struct pf_pcie_adv_rp_err_regs {
1996313Skrishnae 	uint32_t pcie_rp_err_status;	/* pcie root complex error status reg */
2006313Skrishnae 	uint32_t pcie_rp_err_cmd;	/* pcie root complex error cmd reg */
2016313Skrishnae 	uint16_t pcie_rp_ce_src_id;	/* pcie root complex ce sourpe id */
2026313Skrishnae 	uint16_t pcie_rp_ue_src_id;	/* pcie root complex ue sourpe id */
2036313Skrishnae } pf_pcie_adv_rp_err_regs_t;
2046313Skrishnae 
2056313Skrishnae typedef struct pf_pcie_adv_err_regs {
2066313Skrishnae 	uint32_t pcie_adv_ctl;		/* pcie advanced control reg */
2076313Skrishnae 	uint32_t pcie_ue_status;	/* pcie ue error status reg */
2086313Skrishnae 	uint32_t pcie_ue_mask;		/* pcie ue error mask reg */
2096313Skrishnae 	uint32_t pcie_ue_sev;		/* pcie ue error severity reg */
2106313Skrishnae 	uint32_t pcie_ue_hdr[4];	/* pcie ue header log */
2116313Skrishnae 	uint32_t pcie_ce_status;	/* pcie ce error status reg */
2126313Skrishnae 	uint32_t pcie_ce_mask;		/* pcie ce error mask reg */
2136313Skrishnae 	union {
2146313Skrishnae 		pf_pcie_adv_bdg_err_regs_t *pcie_adv_bdg_regs; /* bdg regs */
2156313Skrishnae 		pf_pcie_adv_rp_err_regs_t *pcie_adv_rp_regs;	 /* rp regs */
2166313Skrishnae 	} pcie_ext;
2176313Skrishnae 	uint32_t pcie_ue_tgt_trans;	/* Fault trans type from AER Logs */
2186313Skrishnae 	uint64_t pcie_ue_tgt_addr;	/* Fault addr from AER Logs */
2199921SKrishna.Elango@Sun.COM 	pcie_req_id_t pcie_ue_tgt_bdf;	/* Fault bdf from AER Logs */
2206313Skrishnae } pf_pcie_adv_err_regs_t;
2216313Skrishnae 
2226313Skrishnae typedef struct pf_pcie_rp_err_regs {
2236313Skrishnae 	uint32_t pcie_rp_status;	/* root complex status register */
2246313Skrishnae 	uint16_t pcie_rp_ctl;		/* root complex control register */
2256313Skrishnae } pf_pcie_rp_err_regs_t;
2263274Set142600 
2276313Skrishnae typedef struct pf_pcie_err_regs {
2286313Skrishnae 	uint16_t pcie_err_status;	/* pcie device status register */
2296313Skrishnae 	uint16_t pcie_err_ctl;		/* pcie error control register */
2306313Skrishnae 	uint32_t pcie_dev_cap;		/* pcie device capabilities register */
2316313Skrishnae 	pf_pcie_rp_err_regs_t *pcie_rp_regs;	 /* pcie root complex regs */
2326313Skrishnae 	pf_pcie_adv_err_regs_t *pcie_adv_regs; /* pcie aer regs */
2336313Skrishnae } pf_pcie_err_regs_t;
2346313Skrishnae 
2356313Skrishnae typedef struct pf_root_fault {
2369921SKrishna.Elango@Sun.COM 	pcie_req_id_t	scan_bdf;	/* BDF from error logs */
2379921SKrishna.Elango@Sun.COM 	uint64_t	scan_addr;	/* Addr from error logs */
2386313Skrishnae 	boolean_t	full_scan;	/* Option to do a full scan */
2396313Skrishnae } pf_root_fault_t;
2406313Skrishnae 
2416313Skrishnae typedef struct pf_data pf_data_t;
2426313Skrishnae 
2436313Skrishnae typedef struct pcie_bus {
2446313Skrishnae 	/* Needed for PCI/PCIe fabric error handling */
2456313Skrishnae 	dev_info_t	*bus_dip;
2466313Skrishnae 	dev_info_t	*bus_rp_dip;
2476313Skrishnae 	ddi_acc_handle_t bus_cfg_hdl;		/* error handling acc handle */
2486313Skrishnae 	uint_t		bus_fm_flags;
2496313Skrishnae 
2506313Skrishnae 	/* Static PCI/PCIe information */
2516313Skrishnae 	pcie_req_id_t	bus_bdf;
2526313Skrishnae 	pcie_req_id_t	bus_rp_bdf;		/* BDF of device's Root Port */
2536313Skrishnae 	uint32_t	bus_dev_ven_id;		/* device/vendor ID */
2546313Skrishnae 	uint8_t		bus_rev_id;		/* revision ID */
2556313Skrishnae 	uint8_t		bus_hdr_type;		/* pci header type, see pci.h */
2566313Skrishnae 	uint16_t	bus_dev_type;		/* PCI-E dev type, see pcie.h */
2576313Skrishnae 	uint8_t		bus_bdg_secbus;		/* Bridge secondary bus num */
2586313Skrishnae 	uint16_t	bus_pcie_off;		/* PCIe Capability Offset */
2596313Skrishnae 	uint16_t	bus_aer_off;		/* PCIe Advanced Error Offset */
2606313Skrishnae 	uint16_t	bus_pcix_off;		/* PCIx Capability Offset */
2616313Skrishnae 	uint16_t	bus_ecc_ver;		/* PCIX ecc version */
2626313Skrishnae 	pci_bus_range_t	bus_bus_range;		/* pci bus-range property */
2636313Skrishnae 	ppb_ranges_t	*bus_addr_ranges;	/* pci range property */
2646313Skrishnae 	int		bus_addr_entries;	/* number of range prop */
2656313Skrishnae 	pci_regspec_t	*bus_assigned_addr;	/* "assigned-address" prop */
2666313Skrishnae 	int		bus_assigned_entries;	/* number of prop entries */
2676313Skrishnae 
2686313Skrishnae 	/* Cache of last fault data */
2696313Skrishnae 	pf_data_t	*bus_pfd;
2707596SAlan.Adamson@Sun.COM 
2717596SAlan.Adamson@Sun.COM 	int		bus_mps;		/* Maximum Payload Size */
2729455SKrishna.Elango@Sun.COM 
2739455SKrishna.Elango@Sun.COM 	void		*bus_plat_private;	/* Platform specific */
2746313Skrishnae } pcie_bus_t;
2753274Set142600 
2766313Skrishnae struct pf_data {
2776313Skrishnae 	boolean_t		pe_lock;
2786313Skrishnae 	boolean_t		pe_valid;
2796313Skrishnae 	uint32_t		pe_severity_flags;	/* Severity of error */
2806313Skrishnae 	pcie_bus_t		*pe_bus_p;
2816313Skrishnae 	pf_root_fault_t		*pe_root_fault;	/* Only valid for RC and RP */
2826313Skrishnae 	pf_pci_err_regs_t	*pe_pci_regs;	/* PCI error reg */
2836313Skrishnae 	union {
2846313Skrishnae 		pf_pcix_err_regs_t	*pe_pcix_regs;	/* PCI-X error reg */
2856313Skrishnae 		pf_pcie_err_regs_t	*pe_pcie_regs;	/* PCIe error reg */
2866313Skrishnae 	} pe_ext;
2876313Skrishnae 	pf_pcix_bdg_err_regs_t *pe_pcix_bdg_regs; /* PCI-X bridge regs */
2886313Skrishnae 	pf_data_t		*pe_prev;	/* Next error in queue */
2896313Skrishnae 	pf_data_t		*pe_next;	/* Next error in queue */
2907848SKrishna.Elango@Sun.COM 	boolean_t		pe_rber_fatal;
2916313Skrishnae };
2926313Skrishnae 
2936313Skrishnae /* Information used while handling errors in the fabric. */
2946313Skrishnae typedef struct pf_impl {
2956313Skrishnae 	ddi_fm_error_t	*pf_derr;
2966313Skrishnae 	pf_root_fault_t	*pf_fault;	/* captured fault bdf/addr to scan */
2976313Skrishnae 	pf_data_t	*pf_dq_head_p;	/* ptr to fault data queue */
2986313Skrishnae 	pf_data_t	*pf_dq_tail_p;	/* ptr pt last fault data q */
2996313Skrishnae 	uint32_t	pf_total;	/* total non RC pf_datas */
3006313Skrishnae } pf_impl_t;
3016313Skrishnae 
3026313Skrishnae /* bus_fm_flags field */
3036313Skrishnae #define	PF_FM_READY		(1 << 0)	/* bus_fm_lock initialized */
3046313Skrishnae #define	PF_FM_IS_NH		(1 << 1)	/* known as non-hardened */
3053274Set142600 
3066313Skrishnae /*
3076313Skrishnae  * PCIe fabric handle lookup address flags.  Used to define what type of
3086313Skrishnae  * transaction the address is for.  These same value are defined again in
3096313Skrishnae  * fabric-xlate FM module.  Do not modify these variables, without modifying
3106313Skrishnae  * those.
3116313Skrishnae  */
3126313Skrishnae #define	PF_ADDR_DMA		(1 << 0)
3136313Skrishnae #define	PF_ADDR_PIO		(1 << 1)
3146313Skrishnae #define	PF_ADDR_CFG		(1 << 2)
3153274Set142600 
3166313Skrishnae /* PCIe fabric error scanning status flags */
3176313Skrishnae #define	PF_SCAN_SUCCESS		(1 << 0)
3186313Skrishnae #define	PF_SCAN_CB_FAILURE	(1 << 1) /* hardened device callback failure */
3196313Skrishnae #define	PF_SCAN_NO_ERR_IN_CHILD	(1 << 2) /* no errors in bridge sec stat reg */
3206313Skrishnae #define	PF_SCAN_IN_DQ		(1 << 3) /* already present in the faultq */
3216313Skrishnae #define	PF_SCAN_DEADLOCK	(1 << 4) /* deadlock detected */
3226313Skrishnae #define	PF_SCAN_BAD_RESPONSE	(1 << 5) /* Incorrect device response */
3236313Skrishnae 
3246313Skrishnae /* PCIe fabric error handling severity return flags */
3256313Skrishnae #define	PF_ERR_NO_ERROR		(1 << 0) /* No error seen */
3266313Skrishnae #define	PF_ERR_CE		(1 << 1) /* Correctable Error */
3276313Skrishnae #define	PF_ERR_NO_PANIC		(1 << 2) /* Error should not panic sys */
3286313Skrishnae #define	PF_ERR_MATCHED_DEVICE	(1 << 3) /* Error Handled By Device */
3296313Skrishnae #define	PF_ERR_MATCHED_RC	(1 << 4) /* Error Handled By RC */
3306313Skrishnae #define	PF_ERR_MATCHED_PARENT	(1 << 5) /* Error Handled By Parent */
3316313Skrishnae #define	PF_ERR_PANIC		(1 << 6) /* Error should panic system */
3326313Skrishnae #define	PF_ERR_PANIC_DEADLOCK	(1 << 7) /* deadlock detected */
3336313Skrishnae 
3346313Skrishnae #define	PF_ERR_FATAL_FLAGS	(PF_ERR_PANIC | PF_ERR_PANIC_DEADLOCK)
3356313Skrishnae 
3366313Skrishnae #define	PF_HDL_FOUND		1
3376313Skrishnae #define	PF_HDL_NOTFOUND		2
3386313Skrishnae 
3399921SKrishna.Elango@Sun.COM /*
3409921SKrishna.Elango@Sun.COM  * PCIe Capability Device Type Pseudo Definitions.
3419921SKrishna.Elango@Sun.COM  *
3429921SKrishna.Elango@Sun.COM  * PCI_PSEUDO is used on real PCI devices.  The Legacy PCI definition in the
3439921SKrishna.Elango@Sun.COM  * PCIe spec really refers to PCIe devices that *require* IO Space access.  IO
3449921SKrishna.Elango@Sun.COM  * Space access is usually frowned upon now in PCIe, but there for legacy
3459921SKrishna.Elango@Sun.COM  * purposes.
3469921SKrishna.Elango@Sun.COM  */
3479921SKrishna.Elango@Sun.COM #define	PCIE_PCIECAP_DEV_TYPE_RC_PSEUDO		0x100
3489921SKrishna.Elango@Sun.COM #define	PCIE_PCIECAP_DEV_TYPE_PCI_PSEUDO	0x101
3499921SKrishna.Elango@Sun.COM 
3509921SKrishna.Elango@Sun.COM #define	PCIE_INVALID_BDF	0xFFFF
3519921SKrishna.Elango@Sun.COM #define	PCIE_CHECK_VALID_BDF(x)	(x != PCIE_INVALID_BDF)
3523274Set142600 
3537596SAlan.Adamson@Sun.COM typedef struct {
3547596SAlan.Adamson@Sun.COM 	dev_info_t	*dip;
3557596SAlan.Adamson@Sun.COM 	int		highest_common_mps;
3567596SAlan.Adamson@Sun.COM } pcie_max_supported_t;
3577596SAlan.Adamson@Sun.COM 
3589455SKrishna.Elango@Sun.COM #ifdef	DEBUG
3599455SKrishna.Elango@Sun.COM extern uint_t pcie_debug_flags;
3609455SKrishna.Elango@Sun.COM #define	PCIE_DBG pcie_dbg
3619455SKrishna.Elango@Sun.COM /* Common Debugging shortcuts */
3629455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CFG(dip, bus_p, name, sz, off, org) \
3639455SKrishna.Elango@Sun.COM 	PCIE_DBG("%s:%d:(0x%x) %s(0x%x) 0x%x -> 0x%x\n", ddi_node_name(dip), \
3649455SKrishna.Elango@Sun.COM 	    ddi_get_instance(dip), bus_p->bus_bdf, name, off, org, \
3659455SKrishna.Elango@Sun.COM 	    PCIE_GET(sz, bus_p, off))
3669455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CAP(dip, bus_p, name, sz, off, org) \
3679455SKrishna.Elango@Sun.COM 	PCIE_DBG("%s:%d:(0x%x) %s(0x%x) 0x%x -> 0x%x\n", ddi_node_name(dip), \
3689455SKrishna.Elango@Sun.COM 	    ddi_get_instance(dip), bus_p->bus_bdf, name, off, org, \
3699455SKrishna.Elango@Sun.COM 	    PCIE_CAP_GET(sz, bus_p, off))
3709455SKrishna.Elango@Sun.COM #define	PCIE_DBG_AER(dip, bus_p, name, sz, off, org) \
3719455SKrishna.Elango@Sun.COM 	PCIE_DBG("%s:%d:(0x%x) %s(0x%x) 0x%x -> 0x%x\n", ddi_node_name(dip), \
3729455SKrishna.Elango@Sun.COM 	    ddi_get_instance(dip), bus_p->bus_bdf, name, off, org, \
3739455SKrishna.Elango@Sun.COM 	    PCIE_AER_GET(sz, bus_p, off))
3749455SKrishna.Elango@Sun.COM 
3759455SKrishna.Elango@Sun.COM extern void pcie_dbg(char *fmt, ...);
3769455SKrishna.Elango@Sun.COM 
3779455SKrishna.Elango@Sun.COM #else	/* DEBUG */
3789455SKrishna.Elango@Sun.COM 
3799455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CFG 0 &&
3809455SKrishna.Elango@Sun.COM #define	PCIE_DBG 0 &&
3819455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CAP 0 &&
3829455SKrishna.Elango@Sun.COM #define	PCIE_DBG_AER 0 &&
3839455SKrishna.Elango@Sun.COM 
3849455SKrishna.Elango@Sun.COM #endif	/* DEBUG */
3859455SKrishna.Elango@Sun.COM 
3863274Set142600 /* PCIe Friendly Functions */
3878495SAlan.Adamson@Sun.COM extern void pcie_init_root_port_mps(dev_info_t *dip);
38827Sjchu extern int pcie_initchild(dev_info_t *dip);
38927Sjchu extern void pcie_uninitchild(dev_info_t *dip);
3906313Skrishnae extern void pcie_clear_errors(dev_info_t *dip);
3912738Skrishnae extern int pcie_postattach_child(dev_info_t *dip);
3926313Skrishnae extern void pcie_enable_errors(dev_info_t *dip);
3936313Skrishnae extern void pcie_disable_errors(dev_info_t *dip);
3946313Skrishnae extern int pcie_enable_ce(dev_info_t *dip);
3956313Skrishnae extern boolean_t pcie_bridge_is_link_disabled(dev_info_t *);
3966313Skrishnae 
3976313Skrishnae extern pcie_bus_t *pcie_init_bus(dev_info_t *cdip);
3986313Skrishnae extern void pcie_fini_bus(dev_info_t *cdip);
3996313Skrishnae extern void pcie_rc_init_bus(dev_info_t *dip);
4006313Skrishnae extern void pcie_rc_fini_bus(dev_info_t *dip);
4016313Skrishnae extern void pcie_rc_init_pfd(dev_info_t *dip, pf_data_t *pfd);
4026313Skrishnae extern void pcie_rc_fini_pfd(pf_data_t *pfd);
4036313Skrishnae extern boolean_t pcie_is_child(dev_info_t *dip, dev_info_t *rdip);
4046313Skrishnae extern int pcie_get_bdf_from_dip(dev_info_t *dip, pcie_req_id_t *bdf);
4053156Sgirish extern dev_info_t *pcie_get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip);
4063249Sgovinda extern uint32_t pcie_get_bdf_for_dma_xfer(dev_info_t *dip, dev_info_t *rdip);
4077596SAlan.Adamson@Sun.COM extern int pcie_dev(dev_info_t *dip);
4087596SAlan.Adamson@Sun.COM extern void pcie_get_fabric_mps(dev_info_t *rc_dip, dev_info_t *dip,
4097596SAlan.Adamson@Sun.COM 	int *max_supported);
4107596SAlan.Adamson@Sun.COM extern int pcie_root_port(dev_info_t *dip);
4117596SAlan.Adamson@Sun.COM extern int pcie_initchild_mps(dev_info_t *dip);
4127848SKrishna.Elango@Sun.COM extern void pcie_set_rber_fatal(dev_info_t *dip, boolean_t val);
4137848SKrishna.Elango@Sun.COM extern boolean_t pcie_get_rber_fatal(dev_info_t *dip);
4143274Set142600 
4156313Skrishnae extern uint32_t pcie_get_aer_uce_mask();
4166313Skrishnae extern uint32_t pcie_get_aer_ce_mask();
4176313Skrishnae extern uint32_t pcie_get_aer_suce_mask();
4186313Skrishnae extern uint32_t pcie_get_serr_mask();
4196313Skrishnae extern void pcie_set_aer_uce_mask(uint32_t mask);
4206313Skrishnae extern void pcie_set_aer_ce_mask(uint32_t mask);
4216313Skrishnae extern void pcie_set_aer_suce_mask(uint32_t mask);
4226313Skrishnae extern void pcie_set_serr_mask(uint32_t mask);
4239455SKrishna.Elango@Sun.COM extern void pcie_init_plat(dev_info_t *dip);
4249455SKrishna.Elango@Sun.COM extern void pcie_fini_plat(dev_info_t *dip);
4253274Set142600 
4263274Set142600 /* PCIe error handling functions */
4273274Set142600 extern int pf_scan_fabric(dev_info_t *rpdip, ddi_fm_error_t *derr,
4286313Skrishnae     pf_data_t *root_pfd_p);
4296313Skrishnae extern void pf_init(dev_info_t *, ddi_iblock_cookie_t, ddi_attach_cmd_t);
4306313Skrishnae extern void pf_fini(dev_info_t *, ddi_detach_cmd_t);
4316313Skrishnae extern int pf_hdl_lookup(dev_info_t *, uint64_t, uint32_t, uint64_t,
4326313Skrishnae     pcie_req_id_t);
4336313Skrishnae extern int pf_tlp_decode(pcie_bus_t *, pf_pcie_adv_err_regs_t *);
43427Sjchu 
43527Sjchu #ifdef	__cplusplus
43627Sjchu }
43727Sjchu #endif
43827Sjchu 
43927Sjchu #endif	/* _SYS_PCIE_IMPL_H */
440