xref: /onnv-gate/usr/src/uts/common/sys/pcie_impl.h (revision 10923:df470fd79c3c)
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) \
4010187SKrishna.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))
68*10923SEvan.Yan@Sun.COM 
69*10923SEvan.Yan@Sun.COM #define	PCIE_IS_HOTPLUG_CAPABLE(dip) \
70*10923SEvan.Yan@Sun.COM 	(PCIE_DIP2BUS(dip)->bus_hp_sup_modes)
71*10923SEvan.Yan@Sun.COM 
72*10923SEvan.Yan@Sun.COM #define	PCIE_IS_HOTPLUG_ENABLED(dip) \
73*10923SEvan.Yan@Sun.COM 	((PCIE_DIP2BUS(dip)->bus_hp_curr_mode == PCIE_PCI_HP_MODE) || \
74*10923SEvan.Yan@Sun.COM 	(PCIE_DIP2BUS(dip)->bus_hp_curr_mode == PCIE_NATIVE_HP_MODE))
75*10923SEvan.Yan@Sun.COM 
766313Skrishnae /*
776313Skrishnae  * This is a pseudo pcie "device type", but it's needed to explain describe
786313Skrishnae  * nodes such as PX and NPE, which aren't really PCI devices but do control or
796313Skrishnae  * interaction with PCI error handling.
806313Skrishnae  */
816313Skrishnae #define	PCIE_IS_RC(bus_p) \
826313Skrishnae 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_RC_PSEUDO)
836313Skrishnae #define	PCIE_IS_RP(bus_p) \
846313Skrishnae 	((bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_ROOT) && \
856313Skrishnae 	    PCIE_IS_PCIE(bus_p))
869921SKrishna.Elango@Sun.COM #define	PCIE_IS_SWU(bus_p) \
879921SKrishna.Elango@Sun.COM 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_UP)
889921SKrishna.Elango@Sun.COM #define	PCIE_IS_SWD(bus_p) \
899921SKrishna.Elango@Sun.COM 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_DOWN)
906313Skrishnae #define	PCIE_IS_SW(bus_p) \
919921SKrishna.Elango@Sun.COM 	(PCIE_IS_SWU(bus_p) || PCIE_IS_SWD(bus_p))
926313Skrishnae #define	PCIE_IS_BDG(bus_p)  (bus_p->bus_hdr_type == PCI_HEADER_ONE)
939921SKrishna.Elango@Sun.COM #define	PCIE_IS_PCI_BDG(bus_p) (PCIE_IS_PCI(bus_p) && PCIE_IS_BDG(bus_p))
946313Skrishnae #define	PCIE_IS_PCIE_BDG(bus_p) \
956313Skrishnae 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_PCIE2PCI)
967987SErwin.Tsaur@Sun.COM #define	PCIE_IS_PCI2PCIE(bus_p) \
977987SErwin.Tsaur@Sun.COM 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_PCI2PCIE)
986313Skrishnae #define	PCIE_IS_PCIE_SEC(bus_p) \
996313Skrishnae 	(PCIE_IS_PCIE(bus_p) && PCIE_IS_BDG(bus_p) && !PCIE_IS_PCIE_BDG(bus_p))
1006313Skrishnae #define	PCIX_ECC_VERSION_CHECK(bus_p) \
1016313Skrishnae 	((bus_p->bus_ecc_ver == PCI_PCIX_VER_1) || \
1026313Skrishnae 	    (bus_p->bus_ecc_ver == PCI_PCIX_VER_2))
1033274Set142600 
1046313Skrishnae #define	PCIE_VENID(bus_p)	(bus_p->bus_dev_ven_id & 0xffff)
1056313Skrishnae #define	PCIE_DEVID(bus_p)	((bus_p->bus_dev_ven_id >> 16) & 0xffff)
1063274Set142600 
1076313Skrishnae /* PCIE Cap/AER shortcuts */
1086313Skrishnae #define	PCIE_GET(sz, bus_p, off) \
1096313Skrishnae 	pci_config_get ## sz(bus_p->bus_cfg_hdl, off)
1106313Skrishnae #define	PCIE_PUT(sz, bus_p, off, val) \
1116313Skrishnae 	pci_config_put ## sz(bus_p->bus_cfg_hdl, off, val)
1126313Skrishnae #define	PCIE_CAP_GET(sz, bus_p, off) \
1136313Skrishnae 	PCI_CAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcie_off, off)
1146313Skrishnae #define	PCIE_CAP_PUT(sz, bus_p, off, val) \
1156313Skrishnae 	PCI_CAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcie_off, off, \
1166313Skrishnae 	    val)
1176313Skrishnae #define	PCIE_AER_GET(sz, bus_p, off) \
1186313Skrishnae 	PCI_XCAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_aer_off, off)
1196313Skrishnae #define	PCIE_AER_PUT(sz, bus_p, off, val) \
1206313Skrishnae 	PCI_XCAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_aer_off, off, \
1216313Skrishnae 	    val)
1226313Skrishnae #define	PCIX_CAP_GET(sz, bus_p, off) \
1236313Skrishnae 	PCI_CAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcix_off, off)
1246313Skrishnae #define	PCIX_CAP_PUT(sz, bus_p, off, val) \
1256313Skrishnae 	PCI_CAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcix_off, off, \
1266313Skrishnae 	    val)
1273274Set142600 
1286313Skrishnae /* Translate PF error return values to DDI_FM values */
1296313Skrishnae #define	PF_ERR2DDIFM_ERR(sts) \
1306313Skrishnae 	(sts & PF_ERR_FATAL_FLAGS ? DDI_FM_FATAL :	\
1316313Skrishnae 	(sts == PF_ERR_NO_ERROR ? DDI_FM_OK : DDI_FM_NONFATAL))
1323274Set142600 
13327Sjchu /*
1342549Sgovinda  * The following flag is used for Broadcom 5714/5715 bridge prefetch issue.
13510187SKrishna.Elango@Sun.COM  * This flag will be used both by px and pcieb nexus drivers.
1362549Sgovinda  */
1372549Sgovinda #define	PX_DMAI_FLAGS_MAP_BUFZONE	0x40000
1382549Sgovinda 
1396313Skrishnae /*
1406313Skrishnae  * PCI(e/-X) structures used to to gather and report errors detected by
1416313Skrishnae  * PCI(e/-X) compliant devices.  These registers only contain "dynamic" data.
1426313Skrishnae  * Static data such as Capability Offsets and Version #s is saved in the parent
1436313Skrishnae  * private data.
1446313Skrishnae  */
1456313Skrishnae #define	PCI_ERR_REG(pfd_p)	   pfd_p->pe_pci_regs
1466313Skrishnae #define	PCI_BDG_ERR_REG(pfd_p)	   PCI_ERR_REG(pfd_p)->pci_bdg_regs
1476313Skrishnae #define	PCIX_ERR_REG(pfd_p)	   pfd_p->pe_ext.pe_pcix_regs
1486313Skrishnae #define	PCIX_ECC_REG(pfd_p)	   PCIX_ERR_REG(pfd_p)->pcix_ecc_regs
1496313Skrishnae #define	PCIX_BDG_ERR_REG(pfd_p)	   pfd_p->pe_pcix_bdg_regs
1506313Skrishnae #define	PCIX_BDG_ECC_REG(pfd_p, n) PCIX_BDG_ERR_REG(pfd_p)->pcix_bdg_ecc_regs[n]
1516313Skrishnae #define	PCIE_ERR_REG(pfd_p)	   pfd_p->pe_ext.pe_pcie_regs
1526313Skrishnae #define	PCIE_RP_REG(pfd_p)	   PCIE_ERR_REG(pfd_p)->pcie_rp_regs
1536313Skrishnae #define	PCIE_ROOT_FAULT(pfd_p)	   pfd_p->pe_root_fault
1546313Skrishnae #define	PCIE_ADV_REG(pfd_p)	   PCIE_ERR_REG(pfd_p)->pcie_adv_regs
1556313Skrishnae #define	PCIE_ADV_HDR(pfd_p, n)	   PCIE_ADV_REG(pfd_p)->pcie_ue_hdr[n]
1566313Skrishnae #define	PCIE_ADV_BDG_REG(pfd_p) \
1576313Skrishnae 	PCIE_ADV_REG(pfd_p)->pcie_ext.pcie_adv_bdg_regs
1586313Skrishnae #define	PCIE_ADV_BDG_HDR(pfd_p, n) PCIE_ADV_BDG_REG(pfd_p)->pcie_sue_hdr[n]
1596313Skrishnae #define	PCIE_ADV_RP_REG(pfd_p) \
1606313Skrishnae 	PCIE_ADV_REG(pfd_p)->pcie_ext.pcie_adv_rp_regs
1616313Skrishnae #define	PFD_IS_ROOT(pfd_p)	   PCIE_IS_ROOT(PCIE_PFD2BUS(pfd_p))
1626313Skrishnae #define	PFD_IS_RC(pfd_p)	   PCIE_IS_RC(PCIE_PFD2BUS(pfd_p))
1636313Skrishnae #define	PFD_IS_RP(pfd_p)	   PCIE_IS_RP(PCIE_PFD2BUS(pfd_p))
1646313Skrishnae 
165*10923SEvan.Yan@Sun.COM /* bus_hp_mode field */
166*10923SEvan.Yan@Sun.COM typedef enum {
167*10923SEvan.Yan@Sun.COM 	PCIE_NONE_HP_MODE	= 0x0,
168*10923SEvan.Yan@Sun.COM 	PCIE_ACPI_HP_MODE	= 0x1,
169*10923SEvan.Yan@Sun.COM 	PCIE_PCI_HP_MODE	= 0x2,
170*10923SEvan.Yan@Sun.COM 	PCIE_NATIVE_HP_MODE	= 0x4
171*10923SEvan.Yan@Sun.COM } pcie_hp_mode_t;
172*10923SEvan.Yan@Sun.COM 
1736313Skrishnae typedef struct pf_pci_bdg_err_regs {
1746313Skrishnae 	uint16_t pci_bdg_sec_stat;	/* PCI secondary status reg */
1756313Skrishnae 	uint16_t pci_bdg_ctrl;		/* PCI bridge control reg */
1766313Skrishnae } pf_pci_bdg_err_regs_t;
1776313Skrishnae 
1786313Skrishnae typedef struct pf_pci_err_regs {
1796313Skrishnae 	uint16_t pci_err_status;	/* pci status register */
1806313Skrishnae 	uint16_t pci_cfg_comm;		/* pci command register */
1816313Skrishnae 	pf_pci_bdg_err_regs_t *pci_bdg_regs;
1826313Skrishnae } pf_pci_err_regs_t;
1836313Skrishnae 
1846313Skrishnae typedef struct pf_pcix_ecc_regs {
1856313Skrishnae 	uint32_t pcix_ecc_ctlstat;	/* pcix ecc control status reg */
1866313Skrishnae 	uint32_t pcix_ecc_fstaddr;	/* pcix ecc first address reg */
1876313Skrishnae 	uint32_t pcix_ecc_secaddr;	/* pcix ecc second address reg */
1886313Skrishnae 	uint32_t pcix_ecc_attr;		/* pcix ecc attributes reg */
1896313Skrishnae } pf_pcix_ecc_regs_t;
1903274Set142600 
1916313Skrishnae typedef struct pf_pcix_err_regs {
1926313Skrishnae 	uint16_t pcix_command;		/* pcix command register */
1936313Skrishnae 	uint32_t pcix_status;		/* pcix status register */
1946313Skrishnae 	pf_pcix_ecc_regs_t *pcix_ecc_regs;	/* pcix ecc registers */
1956313Skrishnae } pf_pcix_err_regs_t;
1966313Skrishnae 
1976313Skrishnae typedef struct pf_pcix_bdg_err_regs {
1986313Skrishnae 	uint16_t pcix_bdg_sec_stat;	/* pcix bridge secondary status reg */
1996313Skrishnae 	uint32_t pcix_bdg_stat;		/* pcix bridge status reg */
2006313Skrishnae 	pf_pcix_ecc_regs_t *pcix_bdg_ecc_regs[2];	/* pcix ecc registers */
2016313Skrishnae } pf_pcix_bdg_err_regs_t;
2026313Skrishnae 
2036313Skrishnae typedef struct pf_pcie_adv_bdg_err_regs {
2046313Skrishnae 	uint32_t pcie_sue_ctl;		/* pcie bridge secondary ue control */
2056313Skrishnae 	uint32_t pcie_sue_status;	/* pcie bridge secondary ue status */
2066313Skrishnae 	uint32_t pcie_sue_mask;		/* pcie bridge secondary ue mask */
2076313Skrishnae 	uint32_t pcie_sue_sev;		/* pcie bridge secondary ue severity */
2086313Skrishnae 	uint32_t pcie_sue_hdr[4];	/* pcie bridge secondary ue hdr log */
2096313Skrishnae 	uint32_t pcie_sue_tgt_trans;	/* Fault trans type from SAER Logs */
2106313Skrishnae 	uint64_t pcie_sue_tgt_addr;	/* Fault addr from SAER Logs */
2116313Skrishnae 	pcie_req_id_t pcie_sue_tgt_bdf;	/* Fault bdf from SAER Logs */
2126313Skrishnae } pf_pcie_adv_bdg_err_regs_t;
2133274Set142600 
2146313Skrishnae typedef struct pf_pcie_adv_rp_err_regs {
2156313Skrishnae 	uint32_t pcie_rp_err_status;	/* pcie root complex error status reg */
2166313Skrishnae 	uint32_t pcie_rp_err_cmd;	/* pcie root complex error cmd reg */
2176313Skrishnae 	uint16_t pcie_rp_ce_src_id;	/* pcie root complex ce sourpe id */
2186313Skrishnae 	uint16_t pcie_rp_ue_src_id;	/* pcie root complex ue sourpe id */
2196313Skrishnae } pf_pcie_adv_rp_err_regs_t;
2206313Skrishnae 
2216313Skrishnae typedef struct pf_pcie_adv_err_regs {
2226313Skrishnae 	uint32_t pcie_adv_ctl;		/* pcie advanced control reg */
2236313Skrishnae 	uint32_t pcie_ue_status;	/* pcie ue error status reg */
2246313Skrishnae 	uint32_t pcie_ue_mask;		/* pcie ue error mask reg */
2256313Skrishnae 	uint32_t pcie_ue_sev;		/* pcie ue error severity reg */
2266313Skrishnae 	uint32_t pcie_ue_hdr[4];	/* pcie ue header log */
2276313Skrishnae 	uint32_t pcie_ce_status;	/* pcie ce error status reg */
2286313Skrishnae 	uint32_t pcie_ce_mask;		/* pcie ce error mask reg */
2296313Skrishnae 	union {
2306313Skrishnae 		pf_pcie_adv_bdg_err_regs_t *pcie_adv_bdg_regs; /* bdg regs */
2316313Skrishnae 		pf_pcie_adv_rp_err_regs_t *pcie_adv_rp_regs;	 /* rp regs */
2326313Skrishnae 	} pcie_ext;
2336313Skrishnae 	uint32_t pcie_ue_tgt_trans;	/* Fault trans type from AER Logs */
2346313Skrishnae 	uint64_t pcie_ue_tgt_addr;	/* Fault addr from AER Logs */
2359921SKrishna.Elango@Sun.COM 	pcie_req_id_t pcie_ue_tgt_bdf;	/* Fault bdf from AER Logs */
2366313Skrishnae } pf_pcie_adv_err_regs_t;
2376313Skrishnae 
2386313Skrishnae typedef struct pf_pcie_rp_err_regs {
2396313Skrishnae 	uint32_t pcie_rp_status;	/* root complex status register */
2406313Skrishnae 	uint16_t pcie_rp_ctl;		/* root complex control register */
2416313Skrishnae } pf_pcie_rp_err_regs_t;
2423274Set142600 
2436313Skrishnae typedef struct pf_pcie_err_regs {
2446313Skrishnae 	uint16_t pcie_err_status;	/* pcie device status register */
2456313Skrishnae 	uint16_t pcie_err_ctl;		/* pcie error control register */
2466313Skrishnae 	uint32_t pcie_dev_cap;		/* pcie device capabilities register */
2476313Skrishnae 	pf_pcie_rp_err_regs_t *pcie_rp_regs;	 /* pcie root complex regs */
2486313Skrishnae 	pf_pcie_adv_err_regs_t *pcie_adv_regs; /* pcie aer regs */
2496313Skrishnae } pf_pcie_err_regs_t;
2506313Skrishnae 
2516313Skrishnae typedef struct pf_root_fault {
2529921SKrishna.Elango@Sun.COM 	pcie_req_id_t	scan_bdf;	/* BDF from error logs */
2539921SKrishna.Elango@Sun.COM 	uint64_t	scan_addr;	/* Addr from error logs */
2546313Skrishnae 	boolean_t	full_scan;	/* Option to do a full scan */
2556313Skrishnae } pf_root_fault_t;
2566313Skrishnae 
2576313Skrishnae typedef struct pf_data pf_data_t;
2586313Skrishnae 
2596313Skrishnae typedef struct pcie_bus {
2606313Skrishnae 	/* Needed for PCI/PCIe fabric error handling */
2616313Skrishnae 	dev_info_t	*bus_dip;
2626313Skrishnae 	dev_info_t	*bus_rp_dip;
263*10923SEvan.Yan@Sun.COM 	ddi_acc_handle_t bus_cfg_hdl;		/* error handling acc hdle */
2646313Skrishnae 	uint_t		bus_fm_flags;
265*10923SEvan.Yan@Sun.COM 	uint_t		bus_soft_state;
2666313Skrishnae 
2676313Skrishnae 	/* Static PCI/PCIe information */
2686313Skrishnae 	pcie_req_id_t	bus_bdf;
2696313Skrishnae 	pcie_req_id_t	bus_rp_bdf;		/* BDF of device's Root Port */
2706313Skrishnae 	uint32_t	bus_dev_ven_id;		/* device/vendor ID */
2716313Skrishnae 	uint8_t		bus_rev_id;		/* revision ID */
2726313Skrishnae 	uint8_t		bus_hdr_type;		/* pci header type, see pci.h */
2736313Skrishnae 	uint16_t	bus_dev_type;		/* PCI-E dev type, see pcie.h */
2746313Skrishnae 	uint8_t		bus_bdg_secbus;		/* Bridge secondary bus num */
2756313Skrishnae 	uint16_t	bus_pcie_off;		/* PCIe Capability Offset */
2766313Skrishnae 	uint16_t	bus_aer_off;		/* PCIe Advanced Error Offset */
2776313Skrishnae 	uint16_t	bus_pcix_off;		/* PCIx Capability Offset */
278*10923SEvan.Yan@Sun.COM 	uint16_t	bus_pci_hp_off;		/* PCI HP (SHPC) Cap Offset */
2796313Skrishnae 	uint16_t	bus_ecc_ver;		/* PCIX ecc version */
2806313Skrishnae 	pci_bus_range_t	bus_bus_range;		/* pci bus-range property */
2816313Skrishnae 	ppb_ranges_t	*bus_addr_ranges;	/* pci range property */
2826313Skrishnae 	int		bus_addr_entries;	/* number of range prop */
2836313Skrishnae 	pci_regspec_t	*bus_assigned_addr;	/* "assigned-address" prop */
2846313Skrishnae 	int		bus_assigned_entries;	/* number of prop entries */
2856313Skrishnae 
2866313Skrishnae 	/* Cache of last fault data */
2876313Skrishnae 	pf_data_t	*bus_pfd;
2887596SAlan.Adamson@Sun.COM 
2897596SAlan.Adamson@Sun.COM 	int		bus_mps;		/* Maximum Payload Size */
2909455SKrishna.Elango@Sun.COM 
2919455SKrishna.Elango@Sun.COM 	void		*bus_plat_private;	/* Platform specific */
292*10923SEvan.Yan@Sun.COM 	/* Hotplug specific fields */
293*10923SEvan.Yan@Sun.COM 	pcie_hp_mode_t	bus_hp_sup_modes;	/* HP modes supported */
294*10923SEvan.Yan@Sun.COM 	pcie_hp_mode_t	bus_hp_curr_mode;	/* HP mode used */
295*10923SEvan.Yan@Sun.COM 	void		*bus_hp_ctrl;		/* HP bus ctrl data */
296*10923SEvan.Yan@Sun.COM 	int		bus_ari;		/* ARI device */
2976313Skrishnae } pcie_bus_t;
2983274Set142600 
2996313Skrishnae struct pf_data {
3006313Skrishnae 	boolean_t		pe_lock;
3016313Skrishnae 	boolean_t		pe_valid;
3026313Skrishnae 	uint32_t		pe_severity_flags;	/* Severity of error */
3036313Skrishnae 	pcie_bus_t		*pe_bus_p;
3046313Skrishnae 	pf_root_fault_t		*pe_root_fault;	/* Only valid for RC and RP */
3056313Skrishnae 	pf_pci_err_regs_t	*pe_pci_regs;	/* PCI error reg */
3066313Skrishnae 	union {
3076313Skrishnae 		pf_pcix_err_regs_t	*pe_pcix_regs;	/* PCI-X error reg */
3086313Skrishnae 		pf_pcie_err_regs_t	*pe_pcie_regs;	/* PCIe error reg */
3096313Skrishnae 	} pe_ext;
3106313Skrishnae 	pf_pcix_bdg_err_regs_t *pe_pcix_bdg_regs; /* PCI-X bridge regs */
3116313Skrishnae 	pf_data_t		*pe_prev;	/* Next error in queue */
3126313Skrishnae 	pf_data_t		*pe_next;	/* Next error in queue */
3137848SKrishna.Elango@Sun.COM 	boolean_t		pe_rber_fatal;
3146313Skrishnae };
3156313Skrishnae 
3166313Skrishnae /* Information used while handling errors in the fabric. */
3176313Skrishnae typedef struct pf_impl {
3186313Skrishnae 	ddi_fm_error_t	*pf_derr;
3196313Skrishnae 	pf_root_fault_t	*pf_fault;	/* captured fault bdf/addr to scan */
3206313Skrishnae 	pf_data_t	*pf_dq_head_p;	/* ptr to fault data queue */
3216313Skrishnae 	pf_data_t	*pf_dq_tail_p;	/* ptr pt last fault data q */
3226313Skrishnae 	uint32_t	pf_total;	/* total non RC pf_datas */
3236313Skrishnae } pf_impl_t;
3246313Skrishnae 
3256313Skrishnae /* bus_fm_flags field */
3266313Skrishnae #define	PF_FM_READY		(1 << 0)	/* bus_fm_lock initialized */
3276313Skrishnae #define	PF_FM_IS_NH		(1 << 1)	/* known as non-hardened */
3283274Set142600 
3296313Skrishnae /*
3306313Skrishnae  * PCIe fabric handle lookup address flags.  Used to define what type of
3316313Skrishnae  * transaction the address is for.  These same value are defined again in
3326313Skrishnae  * fabric-xlate FM module.  Do not modify these variables, without modifying
3336313Skrishnae  * those.
3346313Skrishnae  */
3356313Skrishnae #define	PF_ADDR_DMA		(1 << 0)
3366313Skrishnae #define	PF_ADDR_PIO		(1 << 1)
3376313Skrishnae #define	PF_ADDR_CFG		(1 << 2)
3383274Set142600 
3396313Skrishnae /* PCIe fabric error scanning status flags */
3406313Skrishnae #define	PF_SCAN_SUCCESS		(1 << 0)
3416313Skrishnae #define	PF_SCAN_CB_FAILURE	(1 << 1) /* hardened device callback failure */
3426313Skrishnae #define	PF_SCAN_NO_ERR_IN_CHILD	(1 << 2) /* no errors in bridge sec stat reg */
3436313Skrishnae #define	PF_SCAN_IN_DQ		(1 << 3) /* already present in the faultq */
3446313Skrishnae #define	PF_SCAN_DEADLOCK	(1 << 4) /* deadlock detected */
3456313Skrishnae #define	PF_SCAN_BAD_RESPONSE	(1 << 5) /* Incorrect device response */
3466313Skrishnae 
3476313Skrishnae /* PCIe fabric error handling severity return flags */
3486313Skrishnae #define	PF_ERR_NO_ERROR		(1 << 0) /* No error seen */
3496313Skrishnae #define	PF_ERR_CE		(1 << 1) /* Correctable Error */
3506313Skrishnae #define	PF_ERR_NO_PANIC		(1 << 2) /* Error should not panic sys */
3516313Skrishnae #define	PF_ERR_MATCHED_DEVICE	(1 << 3) /* Error Handled By Device */
3526313Skrishnae #define	PF_ERR_MATCHED_RC	(1 << 4) /* Error Handled By RC */
3536313Skrishnae #define	PF_ERR_MATCHED_PARENT	(1 << 5) /* Error Handled By Parent */
3546313Skrishnae #define	PF_ERR_PANIC		(1 << 6) /* Error should panic system */
3556313Skrishnae #define	PF_ERR_PANIC_DEADLOCK	(1 << 7) /* deadlock detected */
3566313Skrishnae 
3576313Skrishnae #define	PF_ERR_FATAL_FLAGS	(PF_ERR_PANIC | PF_ERR_PANIC_DEADLOCK)
3586313Skrishnae 
3596313Skrishnae #define	PF_HDL_FOUND		1
3606313Skrishnae #define	PF_HDL_NOTFOUND		2
3616313Skrishnae 
3629921SKrishna.Elango@Sun.COM /*
3639921SKrishna.Elango@Sun.COM  * PCIe Capability Device Type Pseudo Definitions.
3649921SKrishna.Elango@Sun.COM  *
3659921SKrishna.Elango@Sun.COM  * PCI_PSEUDO is used on real PCI devices.  The Legacy PCI definition in the
3669921SKrishna.Elango@Sun.COM  * PCIe spec really refers to PCIe devices that *require* IO Space access.  IO
3679921SKrishna.Elango@Sun.COM  * Space access is usually frowned upon now in PCIe, but there for legacy
3689921SKrishna.Elango@Sun.COM  * purposes.
3699921SKrishna.Elango@Sun.COM  */
3709921SKrishna.Elango@Sun.COM #define	PCIE_PCIECAP_DEV_TYPE_RC_PSEUDO		0x100
3719921SKrishna.Elango@Sun.COM #define	PCIE_PCIECAP_DEV_TYPE_PCI_PSEUDO	0x101
3729921SKrishna.Elango@Sun.COM 
3739921SKrishna.Elango@Sun.COM #define	PCIE_INVALID_BDF	0xFFFF
3749921SKrishna.Elango@Sun.COM #define	PCIE_CHECK_VALID_BDF(x)	(x != PCIE_INVALID_BDF)
3753274Set142600 
3767596SAlan.Adamson@Sun.COM typedef struct {
3777596SAlan.Adamson@Sun.COM 	dev_info_t	*dip;
3787596SAlan.Adamson@Sun.COM 	int		highest_common_mps;
3797596SAlan.Adamson@Sun.COM } pcie_max_supported_t;
3807596SAlan.Adamson@Sun.COM 
381*10923SEvan.Yan@Sun.COM /*
382*10923SEvan.Yan@Sun.COM  * Default interrupt priority for all PCI and PCIe nexus drivers including
383*10923SEvan.Yan@Sun.COM  * hotplug interrupts.
384*10923SEvan.Yan@Sun.COM  */
385*10923SEvan.Yan@Sun.COM #define	PCIE_INTR_PRI		(LOCK_LEVEL - 1)
386*10923SEvan.Yan@Sun.COM 
387*10923SEvan.Yan@Sun.COM /*
388*10923SEvan.Yan@Sun.COM  * XXX - PCIE_IS_PCIE check is required in order not to invoke these macros
389*10923SEvan.Yan@Sun.COM  * for non-standard PCI or PCI Express Hotplug Controllers.
390*10923SEvan.Yan@Sun.COM  */
391*10923SEvan.Yan@Sun.COM #define	PCIE_ENABLE_ERRORS(dip)	\
392*10923SEvan.Yan@Sun.COM 	if (PCIE_IS_PCIE(PCIE_DIP2BUS(dip))) {	\
393*10923SEvan.Yan@Sun.COM 		pcie_enable_errors(dip);	\
394*10923SEvan.Yan@Sun.COM 		(void) pcie_enable_ce(dip);	\
395*10923SEvan.Yan@Sun.COM 	}
396*10923SEvan.Yan@Sun.COM 
397*10923SEvan.Yan@Sun.COM #define	PCIE_DISABLE_ERRORS(dip)		\
398*10923SEvan.Yan@Sun.COM 	if (PCIE_IS_PCIE(PCIE_DIP2BUS(dip))) {	\
399*10923SEvan.Yan@Sun.COM 		pcie_disable_errors(dip);	\
400*10923SEvan.Yan@Sun.COM 	}
401*10923SEvan.Yan@Sun.COM 
4029455SKrishna.Elango@Sun.COM #ifdef	DEBUG
4039455SKrishna.Elango@Sun.COM #define	PCIE_DBG pcie_dbg
4049455SKrishna.Elango@Sun.COM /* Common Debugging shortcuts */
4059455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CFG(dip, bus_p, name, sz, off, org) \
4069455SKrishna.Elango@Sun.COM 	PCIE_DBG("%s:%d:(0x%x) %s(0x%x) 0x%x -> 0x%x\n", ddi_node_name(dip), \
4079455SKrishna.Elango@Sun.COM 	    ddi_get_instance(dip), bus_p->bus_bdf, name, off, org, \
4089455SKrishna.Elango@Sun.COM 	    PCIE_GET(sz, bus_p, off))
4099455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CAP(dip, bus_p, name, sz, off, org) \
4109455SKrishna.Elango@Sun.COM 	PCIE_DBG("%s:%d:(0x%x) %s(0x%x) 0x%x -> 0x%x\n", ddi_node_name(dip), \
4119455SKrishna.Elango@Sun.COM 	    ddi_get_instance(dip), bus_p->bus_bdf, name, off, org, \
4129455SKrishna.Elango@Sun.COM 	    PCIE_CAP_GET(sz, bus_p, off))
4139455SKrishna.Elango@Sun.COM #define	PCIE_DBG_AER(dip, bus_p, name, sz, off, org) \
4149455SKrishna.Elango@Sun.COM 	PCIE_DBG("%s:%d:(0x%x) %s(0x%x) 0x%x -> 0x%x\n", ddi_node_name(dip), \
4159455SKrishna.Elango@Sun.COM 	    ddi_get_instance(dip), bus_p->bus_bdf, name, off, org, \
4169455SKrishna.Elango@Sun.COM 	    PCIE_AER_GET(sz, bus_p, off))
4179455SKrishna.Elango@Sun.COM 
4189455SKrishna.Elango@Sun.COM #else	/* DEBUG */
4199455SKrishna.Elango@Sun.COM 
4209455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CFG 0 &&
4219455SKrishna.Elango@Sun.COM #define	PCIE_DBG 0 &&
422*10923SEvan.Yan@Sun.COM #define	PCIE_ARI_DBG 0 &&
4239455SKrishna.Elango@Sun.COM #define	PCIE_DBG_CAP 0 &&
4249455SKrishna.Elango@Sun.COM #define	PCIE_DBG_AER 0 &&
4259455SKrishna.Elango@Sun.COM 
4269455SKrishna.Elango@Sun.COM #endif	/* DEBUG */
4279455SKrishna.Elango@Sun.COM 
4283274Set142600 /* PCIe Friendly Functions */
429*10923SEvan.Yan@Sun.COM extern int pcie_init(dev_info_t *dip, caddr_t arg);
430*10923SEvan.Yan@Sun.COM extern int pcie_uninit(dev_info_t *dip);
431*10923SEvan.Yan@Sun.COM extern int pcie_intr(dev_info_t *dip);
432*10923SEvan.Yan@Sun.COM extern int pcie_open(dev_info_t *dip, dev_t *devp, int flags, int otyp,
433*10923SEvan.Yan@Sun.COM     cred_t *credp);
434*10923SEvan.Yan@Sun.COM extern int pcie_close(dev_info_t *dip, dev_t dev, int flags, int otyp,
435*10923SEvan.Yan@Sun.COM     cred_t *credp);
436*10923SEvan.Yan@Sun.COM extern int pcie_ioctl(dev_info_t *dip, dev_t dev, int cmd, intptr_t arg,
437*10923SEvan.Yan@Sun.COM     int mode, cred_t *credp, int *rvalp);
438*10923SEvan.Yan@Sun.COM extern int pcie_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op,
439*10923SEvan.Yan@Sun.COM     int flags, char *name, caddr_t valuep, int *lengthp);
440*10923SEvan.Yan@Sun.COM 
4418495SAlan.Adamson@Sun.COM extern void pcie_init_root_port_mps(dev_info_t *dip);
44227Sjchu extern int pcie_initchild(dev_info_t *dip);
44327Sjchu extern void pcie_uninitchild(dev_info_t *dip);
4446313Skrishnae extern void pcie_clear_errors(dev_info_t *dip);
4452738Skrishnae extern int pcie_postattach_child(dev_info_t *dip);
4466313Skrishnae extern void pcie_enable_errors(dev_info_t *dip);
4476313Skrishnae extern void pcie_disable_errors(dev_info_t *dip);
4486313Skrishnae extern int pcie_enable_ce(dev_info_t *dip);
4496313Skrishnae extern boolean_t pcie_bridge_is_link_disabled(dev_info_t *);
4506313Skrishnae 
4516313Skrishnae extern pcie_bus_t *pcie_init_bus(dev_info_t *cdip);
4526313Skrishnae extern void pcie_fini_bus(dev_info_t *cdip);
4536313Skrishnae extern void pcie_rc_init_bus(dev_info_t *dip);
4546313Skrishnae extern void pcie_rc_fini_bus(dev_info_t *dip);
4556313Skrishnae extern void pcie_rc_init_pfd(dev_info_t *dip, pf_data_t *pfd);
4566313Skrishnae extern void pcie_rc_fini_pfd(pf_data_t *pfd);
4576313Skrishnae extern boolean_t pcie_is_child(dev_info_t *dip, dev_info_t *rdip);
4586313Skrishnae extern int pcie_get_bdf_from_dip(dev_info_t *dip, pcie_req_id_t *bdf);
4593156Sgirish extern dev_info_t *pcie_get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip);
4603249Sgovinda extern uint32_t pcie_get_bdf_for_dma_xfer(dev_info_t *dip, dev_info_t *rdip);
4617596SAlan.Adamson@Sun.COM extern int pcie_dev(dev_info_t *dip);
4627596SAlan.Adamson@Sun.COM extern void pcie_get_fabric_mps(dev_info_t *rc_dip, dev_info_t *dip,
4637596SAlan.Adamson@Sun.COM 	int *max_supported);
4647596SAlan.Adamson@Sun.COM extern int pcie_root_port(dev_info_t *dip);
4657596SAlan.Adamson@Sun.COM extern int pcie_initchild_mps(dev_info_t *dip);
4667848SKrishna.Elango@Sun.COM extern void pcie_set_rber_fatal(dev_info_t *dip, boolean_t val);
4677848SKrishna.Elango@Sun.COM extern boolean_t pcie_get_rber_fatal(dev_info_t *dip);
4683274Set142600 
4696313Skrishnae extern uint32_t pcie_get_aer_uce_mask();
4706313Skrishnae extern uint32_t pcie_get_aer_ce_mask();
4716313Skrishnae extern uint32_t pcie_get_aer_suce_mask();
4726313Skrishnae extern uint32_t pcie_get_serr_mask();
4736313Skrishnae extern void pcie_set_aer_uce_mask(uint32_t mask);
4746313Skrishnae extern void pcie_set_aer_ce_mask(uint32_t mask);
4756313Skrishnae extern void pcie_set_aer_suce_mask(uint32_t mask);
4766313Skrishnae extern void pcie_set_serr_mask(uint32_t mask);
4779455SKrishna.Elango@Sun.COM extern void pcie_init_plat(dev_info_t *dip);
4789455SKrishna.Elango@Sun.COM extern void pcie_fini_plat(dev_info_t *dip);
479*10923SEvan.Yan@Sun.COM extern int pcie_read_only_probe(dev_info_t *, char *, dev_info_t **);
480*10923SEvan.Yan@Sun.COM extern dev_info_t *pcie_func_to_dip(dev_info_t *dip, pcie_req_id_t function);
481*10923SEvan.Yan@Sun.COM extern int pcie_ari_disable(dev_info_t *dip);
482*10923SEvan.Yan@Sun.COM extern int pcie_ari_enable(dev_info_t *dip);
483*10923SEvan.Yan@Sun.COM 
484*10923SEvan.Yan@Sun.COM #define	PCIE_ARI_FORW_NOT_SUPPORTED	0
485*10923SEvan.Yan@Sun.COM #define	PCIE_ARI_FORW_SUPPORTED		1
486*10923SEvan.Yan@Sun.COM 
487*10923SEvan.Yan@Sun.COM extern int pcie_ari_supported(dev_info_t *dip);
488*10923SEvan.Yan@Sun.COM 
489*10923SEvan.Yan@Sun.COM #define	PCIE_ARI_FORW_DISABLED	0
490*10923SEvan.Yan@Sun.COM #define	PCIE_ARI_FORW_ENABLED	1
491*10923SEvan.Yan@Sun.COM 
492*10923SEvan.Yan@Sun.COM extern int pcie_ari_is_enabled(dev_info_t *dip);
493*10923SEvan.Yan@Sun.COM 
494*10923SEvan.Yan@Sun.COM #define	PCIE_NOT_ARI_DEVICE		0
495*10923SEvan.Yan@Sun.COM #define	PCIE_ARI_DEVICE			1
496*10923SEvan.Yan@Sun.COM 
497*10923SEvan.Yan@Sun.COM extern int pcie_ari_device(dev_info_t *dip);
498*10923SEvan.Yan@Sun.COM extern int pcie_ari_get_next_function(dev_info_t *dip, int *func);
4993274Set142600 
5003274Set142600 /* PCIe error handling functions */
5013274Set142600 extern int pf_scan_fabric(dev_info_t *rpdip, ddi_fm_error_t *derr,
5026313Skrishnae     pf_data_t *root_pfd_p);
5036313Skrishnae extern void pf_init(dev_info_t *, ddi_iblock_cookie_t, ddi_attach_cmd_t);
5046313Skrishnae extern void pf_fini(dev_info_t *, ddi_detach_cmd_t);
5056313Skrishnae extern int pf_hdl_lookup(dev_info_t *, uint64_t, uint32_t, uint64_t,
5066313Skrishnae     pcie_req_id_t);
5076313Skrishnae extern int pf_tlp_decode(pcie_bus_t *, pf_pcie_adv_err_regs_t *);
50827Sjchu 
509*10923SEvan.Yan@Sun.COM #ifdef	DEBUG
510*10923SEvan.Yan@Sun.COM extern uint_t pcie_debug_flags;
511*10923SEvan.Yan@Sun.COM extern void pcie_dbg(char *fmt, ...);
512*10923SEvan.Yan@Sun.COM #endif	/* DEBUG */
513*10923SEvan.Yan@Sun.COM 
51427Sjchu #ifdef	__cplusplus
51527Sjchu }
51627Sjchu #endif
51727Sjchu 
51827Sjchu #endif	/* _SYS_PCIE_IMPL_H */
519