xref: /onnv-gate/usr/src/uts/common/sys/pcie_impl.h (revision 6313:3f914b76f189)
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 /*
22*6313Skrishnae  * Copyright 2008 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
3027Sjchu 
3127Sjchu #ifdef	__cplusplus
3227Sjchu extern "C" {
3327Sjchu #endif
3427Sjchu 
353274Set142600 #include <sys/pcie.h>
363274Set142600 
37*6313Skrishnae #define	PCI_GET_BDF(dip)	\
38*6313Skrishnae 	PCIE_DIP2BUS(dip)->bus_bdf
39*6313Skrishnae #define	PCI_GET_SEC_BUS(dip)	\
40*6313Skrishnae 	PCIE_DIP2BUS(dip)->bus_bdg_secbus
41*6313Skrishnae #define	PCI_GET_PCIE2PCI_SECBUS(dip) \
42*6313Skrishnae 	PCIE_DIP2BUS(dip)->bus_pcie2pci_secbus
433274Set142600 
44*6313Skrishnae #define	DEVI_PORT_TYPE_PCI \
45*6313Skrishnae 	((PCI_CLASS_BRIDGE << 16) | (PCI_BRIDGE_PCI << 8) | \
46*6313Skrishnae 	PCI_BRIDGE_PCI_IF_PCI2PCI)
473274Set142600 
48*6313Skrishnae #define	PCIE_DIP2BUS(dip) \
49*6313Skrishnae 	(ndi_port_type(dip, B_TRUE, DEVI_PORT_TYPE_PCI) ? \
50*6313Skrishnae 	PCIE_DIP2UPBUS(dip) : \
51*6313Skrishnae 	ndi_port_type(dip, B_FALSE, DEVI_PORT_TYPE_PCI) ? \
52*6313Skrishnae 	PCIE_DIP2DOWNBUS(dip) : NULL)
533274Set142600 
54*6313Skrishnae #define	PCIE_DIP2UPBUS(dip) \
55*6313Skrishnae 	((pcie_bus_t *)ndi_get_bus_private(dip, B_TRUE))
56*6313Skrishnae #define	PCIE_DIP2DOWNBUS(dip) \
57*6313Skrishnae 	((pcie_bus_t *)ndi_get_bus_private(dip, B_FALSE))
58*6313Skrishnae #define	PCIE_DIP2PFD(dip) (PCIE_DIP2BUS(dip))->bus_pfd
59*6313Skrishnae #define	PCIE_PFD2BUS(pfd_p) pfd_p->pe_bus_p
60*6313Skrishnae #define	PCIE_PFD2DIP(pfd_p) PCIE_PFD2BUS(pfd_p)->bus_dip
61*6313Skrishnae #define	PCIE_BUS2DIP(bus_p) bus_p->bus_dip
62*6313Skrishnae #define	PCIE_BUS2PFD(bus_p) PCIE_DIP2PFD(PCIE_BUS2DIP(bus_p))
633274Set142600 
64*6313Skrishnae #define	PCIE_IS_PCIE(bus_p) (bus_p->bus_pcie_off)
65*6313Skrishnae #define	PCIE_IS_PCIX(bus_p) (bus_p->bus_pcix_off)
66*6313Skrishnae #define	PCIE_IS_PCI(bus_p) \
67*6313Skrishnae 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_PCI_DEV)
68*6313Skrishnae #define	PCIE_HAS_AER(bus_p) (bus_p->bus_aer_off)
69*6313Skrishnae /* IS_ROOT = is RC or RP */
70*6313Skrishnae #define	PCIE_IS_ROOT(bus_p) (PCIE_IS_RC(bus_p) || PCIE_IS_RP(bus_p))
71*6313Skrishnae /*
72*6313Skrishnae  * This is a pseudo pcie "device type", but it's needed to explain describe
73*6313Skrishnae  * nodes such as PX and NPE, which aren't really PCI devices but do control or
74*6313Skrishnae  * interaction with PCI error handling.
75*6313Skrishnae  */
76*6313Skrishnae #define	PCIE_IS_RC(bus_p) \
77*6313Skrishnae 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_RC_PSEUDO)
78*6313Skrishnae #define	PCIE_IS_RP(bus_p) \
79*6313Skrishnae 	((bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_ROOT) && \
80*6313Skrishnae 	    PCIE_IS_PCIE(bus_p))
81*6313Skrishnae #define	PCIE_IS_SW(bus_p) \
82*6313Skrishnae 	((bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_UP) || \
83*6313Skrishnae 	    (bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_DOWN))
84*6313Skrishnae #define	PCIE_IS_BDG(bus_p)  (bus_p->bus_hdr_type == PCI_HEADER_ONE)
85*6313Skrishnae #define	PCIE_IS_PCI_BDG(bus_p) \
86*6313Skrishnae 	((bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_PCI_DEV) && \
87*6313Skrishnae 	    PCIE_IS_BDG(bus_p))
88*6313Skrishnae #define	PCIE_IS_PCIE_BDG(bus_p) \
89*6313Skrishnae 	(bus_p->bus_dev_type == PCIE_PCIECAP_DEV_TYPE_PCIE2PCI)
90*6313Skrishnae #define	PCIE_IS_PCIE_SEC(bus_p) \
91*6313Skrishnae 	(PCIE_IS_PCIE(bus_p) && PCIE_IS_BDG(bus_p) && !PCIE_IS_PCIE_BDG(bus_p))
92*6313Skrishnae #define	PCIX_ECC_VERSION_CHECK(bus_p) \
93*6313Skrishnae 	((bus_p->bus_ecc_ver == PCI_PCIX_VER_1) || \
94*6313Skrishnae 	    (bus_p->bus_ecc_ver == PCI_PCIX_VER_2))
953274Set142600 
96*6313Skrishnae #define	PCIE_VENID(bus_p)	(bus_p->bus_dev_ven_id & 0xffff)
97*6313Skrishnae #define	PCIE_DEVID(bus_p)	((bus_p->bus_dev_ven_id >> 16) & 0xffff)
983274Set142600 
99*6313Skrishnae /* PCIE Cap/AER shortcuts */
100*6313Skrishnae #define	PCIE_GET(sz, bus_p, off) \
101*6313Skrishnae 	pci_config_get ## sz(bus_p->bus_cfg_hdl, off)
102*6313Skrishnae #define	PCIE_PUT(sz, bus_p, off, val) \
103*6313Skrishnae 	pci_config_put ## sz(bus_p->bus_cfg_hdl, off, val)
104*6313Skrishnae #define	PCIE_CAP_GET(sz, bus_p, off) \
105*6313Skrishnae 	PCI_CAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcie_off, off)
106*6313Skrishnae #define	PCIE_CAP_PUT(sz, bus_p, off, val) \
107*6313Skrishnae 	PCI_CAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcie_off, off, \
108*6313Skrishnae 	    val)
109*6313Skrishnae #define	PCIE_AER_GET(sz, bus_p, off) \
110*6313Skrishnae 	PCI_XCAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_aer_off, off)
111*6313Skrishnae #define	PCIE_AER_PUT(sz, bus_p, off, val) \
112*6313Skrishnae 	PCI_XCAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_aer_off, off, \
113*6313Skrishnae 	    val)
114*6313Skrishnae #define	PCIX_CAP_GET(sz, bus_p, off) \
115*6313Skrishnae 	PCI_CAP_GET ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcix_off, off)
116*6313Skrishnae #define	PCIX_CAP_PUT(sz, bus_p, off, val) \
117*6313Skrishnae 	PCI_CAP_PUT ## sz(bus_p->bus_cfg_hdl, NULL, bus_p->bus_pcix_off, off, \
118*6313Skrishnae 	    val)
1193274Set142600 
120*6313Skrishnae /* Translate PF error return values to DDI_FM values */
121*6313Skrishnae #define	PF_ERR2DDIFM_ERR(sts) \
122*6313Skrishnae 	(sts & PF_ERR_FATAL_FLAGS ? DDI_FM_FATAL :	\
123*6313Skrishnae 	(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.
1272549Sgovinda  * This flag will be used both by px and px_pci nexus drivers.
1282549Sgovinda  */
1292549Sgovinda #define	PX_DMAI_FLAGS_MAP_BUFZONE	0x40000
1302549Sgovinda 
131*6313Skrishnae /*
132*6313Skrishnae  * PCI(e/-X) structures used to to gather and report errors detected by
133*6313Skrishnae  * PCI(e/-X) compliant devices.  These registers only contain "dynamic" data.
134*6313Skrishnae  * Static data such as Capability Offsets and Version #s is saved in the parent
135*6313Skrishnae  * private data.
136*6313Skrishnae  */
137*6313Skrishnae #define	PCI_ERR_REG(pfd_p)	   pfd_p->pe_pci_regs
138*6313Skrishnae #define	PCI_BDG_ERR_REG(pfd_p)	   PCI_ERR_REG(pfd_p)->pci_bdg_regs
139*6313Skrishnae #define	PCIX_ERR_REG(pfd_p)	   pfd_p->pe_ext.pe_pcix_regs
140*6313Skrishnae #define	PCIX_ECC_REG(pfd_p)	   PCIX_ERR_REG(pfd_p)->pcix_ecc_regs
141*6313Skrishnae #define	PCIX_BDG_ERR_REG(pfd_p)	   pfd_p->pe_pcix_bdg_regs
142*6313Skrishnae #define	PCIX_BDG_ECC_REG(pfd_p, n) PCIX_BDG_ERR_REG(pfd_p)->pcix_bdg_ecc_regs[n]
143*6313Skrishnae #define	PCIE_ERR_REG(pfd_p)	   pfd_p->pe_ext.pe_pcie_regs
144*6313Skrishnae #define	PCIE_RP_REG(pfd_p)	   PCIE_ERR_REG(pfd_p)->pcie_rp_regs
145*6313Skrishnae #define	PCIE_ROOT_FAULT(pfd_p)	   pfd_p->pe_root_fault
146*6313Skrishnae #define	PCIE_ADV_REG(pfd_p)	   PCIE_ERR_REG(pfd_p)->pcie_adv_regs
147*6313Skrishnae #define	PCIE_ADV_HDR(pfd_p, n)	   PCIE_ADV_REG(pfd_p)->pcie_ue_hdr[n]
148*6313Skrishnae #define	PCIE_ADV_BDG_REG(pfd_p) \
149*6313Skrishnae 	PCIE_ADV_REG(pfd_p)->pcie_ext.pcie_adv_bdg_regs
150*6313Skrishnae #define	PCIE_ADV_BDG_HDR(pfd_p, n) PCIE_ADV_BDG_REG(pfd_p)->pcie_sue_hdr[n]
151*6313Skrishnae #define	PCIE_ADV_RP_REG(pfd_p) \
152*6313Skrishnae 	PCIE_ADV_REG(pfd_p)->pcie_ext.pcie_adv_rp_regs
153*6313Skrishnae #define	PFD_IS_ROOT(pfd_p)	   PCIE_IS_ROOT(PCIE_PFD2BUS(pfd_p))
154*6313Skrishnae #define	PFD_IS_RC(pfd_p)	   PCIE_IS_RC(PCIE_PFD2BUS(pfd_p))
155*6313Skrishnae #define	PFD_IS_RP(pfd_p)	   PCIE_IS_RP(PCIE_PFD2BUS(pfd_p))
156*6313Skrishnae 
157*6313Skrishnae typedef struct pf_pci_bdg_err_regs {
158*6313Skrishnae 	uint16_t pci_bdg_sec_stat;	/* PCI secondary status reg */
159*6313Skrishnae 	uint16_t pci_bdg_ctrl;		/* PCI bridge control reg */
160*6313Skrishnae } pf_pci_bdg_err_regs_t;
161*6313Skrishnae 
162*6313Skrishnae typedef struct pf_pci_err_regs {
163*6313Skrishnae 	uint16_t pci_err_status;	/* pci status register */
164*6313Skrishnae 	uint16_t pci_cfg_comm;		/* pci command register */
165*6313Skrishnae 	pf_pci_bdg_err_regs_t *pci_bdg_regs;
166*6313Skrishnae } pf_pci_err_regs_t;
167*6313Skrishnae 
168*6313Skrishnae typedef struct pf_pcix_ecc_regs {
169*6313Skrishnae 	uint32_t pcix_ecc_ctlstat;	/* pcix ecc control status reg */
170*6313Skrishnae 	uint32_t pcix_ecc_fstaddr;	/* pcix ecc first address reg */
171*6313Skrishnae 	uint32_t pcix_ecc_secaddr;	/* pcix ecc second address reg */
172*6313Skrishnae 	uint32_t pcix_ecc_attr;		/* pcix ecc attributes reg */
173*6313Skrishnae } pf_pcix_ecc_regs_t;
1743274Set142600 
175*6313Skrishnae typedef struct pf_pcix_err_regs {
176*6313Skrishnae 	uint16_t pcix_command;		/* pcix command register */
177*6313Skrishnae 	uint32_t pcix_status;		/* pcix status register */
178*6313Skrishnae 	pf_pcix_ecc_regs_t *pcix_ecc_regs;	/* pcix ecc registers */
179*6313Skrishnae } pf_pcix_err_regs_t;
180*6313Skrishnae 
181*6313Skrishnae typedef struct pf_pcix_bdg_err_regs {
182*6313Skrishnae 	uint16_t pcix_bdg_sec_stat;	/* pcix bridge secondary status reg */
183*6313Skrishnae 	uint32_t pcix_bdg_stat;		/* pcix bridge status reg */
184*6313Skrishnae 	pf_pcix_ecc_regs_t *pcix_bdg_ecc_regs[2];	/* pcix ecc registers */
185*6313Skrishnae } pf_pcix_bdg_err_regs_t;
186*6313Skrishnae 
187*6313Skrishnae typedef struct pf_pcie_adv_bdg_err_regs {
188*6313Skrishnae 	uint32_t pcie_sue_ctl;		/* pcie bridge secondary ue control */
189*6313Skrishnae 	uint32_t pcie_sue_status;	/* pcie bridge secondary ue status */
190*6313Skrishnae 	uint32_t pcie_sue_mask;		/* pcie bridge secondary ue mask */
191*6313Skrishnae 	uint32_t pcie_sue_sev;		/* pcie bridge secondary ue severity */
192*6313Skrishnae 	uint32_t pcie_sue_hdr[4];	/* pcie bridge secondary ue hdr log */
193*6313Skrishnae 	uint32_t pcie_sue_tgt_trans;	/* Fault trans type from SAER Logs */
194*6313Skrishnae 	uint64_t pcie_sue_tgt_addr;	/* Fault addr from SAER Logs */
195*6313Skrishnae 	pcie_req_id_t pcie_sue_tgt_bdf;	/* Fault bdf from SAER Logs */
196*6313Skrishnae } pf_pcie_adv_bdg_err_regs_t;
1973274Set142600 
198*6313Skrishnae typedef struct pf_pcie_adv_rp_err_regs {
199*6313Skrishnae 	uint32_t pcie_rp_err_status;	/* pcie root complex error status reg */
200*6313Skrishnae 	uint32_t pcie_rp_err_cmd;	/* pcie root complex error cmd reg */
201*6313Skrishnae 	uint16_t pcie_rp_ce_src_id;	/* pcie root complex ce sourpe id */
202*6313Skrishnae 	uint16_t pcie_rp_ue_src_id;	/* pcie root complex ue sourpe id */
203*6313Skrishnae } pf_pcie_adv_rp_err_regs_t;
204*6313Skrishnae 
205*6313Skrishnae typedef struct pf_pcie_adv_err_regs {
206*6313Skrishnae 	uint32_t pcie_adv_ctl;		/* pcie advanced control reg */
207*6313Skrishnae 	uint32_t pcie_ue_status;	/* pcie ue error status reg */
208*6313Skrishnae 	uint32_t pcie_ue_mask;		/* pcie ue error mask reg */
209*6313Skrishnae 	uint32_t pcie_ue_sev;		/* pcie ue error severity reg */
210*6313Skrishnae 	uint32_t pcie_ue_hdr[4];	/* pcie ue header log */
211*6313Skrishnae 	uint32_t pcie_ce_status;	/* pcie ce error status reg */
212*6313Skrishnae 	uint32_t pcie_ce_mask;		/* pcie ce error mask reg */
213*6313Skrishnae 	union {
214*6313Skrishnae 		pf_pcie_adv_bdg_err_regs_t *pcie_adv_bdg_regs; /* bdg regs */
215*6313Skrishnae 		pf_pcie_adv_rp_err_regs_t *pcie_adv_rp_regs;	 /* rp regs */
216*6313Skrishnae 	} pcie_ext;
217*6313Skrishnae 	uint32_t pcie_ue_tgt_trans;	/* Fault trans type from AER Logs */
218*6313Skrishnae 	uint64_t pcie_ue_tgt_addr;	/* Fault addr from AER Logs */
219*6313Skrishnae 	pcie_req_id_t pcie_ue_tgt_bdf;	/* Fault bdf from SAER Logs */
220*6313Skrishnae } pf_pcie_adv_err_regs_t;
221*6313Skrishnae 
222*6313Skrishnae typedef struct pf_pcie_rp_err_regs {
223*6313Skrishnae 	uint32_t pcie_rp_status;	/* root complex status register */
224*6313Skrishnae 	uint16_t pcie_rp_ctl;		/* root complex control register */
225*6313Skrishnae } pf_pcie_rp_err_regs_t;
2263274Set142600 
227*6313Skrishnae typedef struct pf_pcie_err_regs {
228*6313Skrishnae 	uint16_t pcie_err_status;	/* pcie device status register */
229*6313Skrishnae 	uint16_t pcie_err_ctl;		/* pcie error control register */
230*6313Skrishnae 	uint32_t pcie_dev_cap;		/* pcie device capabilities register */
231*6313Skrishnae 	pf_pcie_rp_err_regs_t *pcie_rp_regs;	 /* pcie root complex regs */
232*6313Skrishnae 	pf_pcie_adv_err_regs_t *pcie_adv_regs; /* pcie aer regs */
233*6313Skrishnae } pf_pcie_err_regs_t;
234*6313Skrishnae 
235*6313Skrishnae typedef struct pf_root_fault {
236*6313Skrishnae 	pcie_req_id_t	fault_bdf;	/* Fault BDF of error */
237*6313Skrishnae 	uint64_t	fault_addr;	/* Fault Addr of error */
238*6313Skrishnae 	boolean_t	full_scan;	/* Option to do a full scan */
239*6313Skrishnae } pf_root_fault_t;
240*6313Skrishnae 
241*6313Skrishnae typedef struct pf_data pf_data_t;
242*6313Skrishnae 
243*6313Skrishnae typedef struct pcie_bus {
244*6313Skrishnae 	/* Needed for PCI/PCIe fabric error handling */
245*6313Skrishnae 	dev_info_t	*bus_dip;
246*6313Skrishnae 	dev_info_t	*bus_rp_dip;
247*6313Skrishnae 	ddi_acc_handle_t bus_cfg_hdl;		/* error handling acc handle */
248*6313Skrishnae 	uint_t		bus_fm_flags;
249*6313Skrishnae 
250*6313Skrishnae 	/* Static PCI/PCIe information */
251*6313Skrishnae 	pcie_req_id_t	bus_bdf;
252*6313Skrishnae 	pcie_req_id_t	bus_rp_bdf;		/* BDF of device's Root Port */
253*6313Skrishnae 	uint32_t	bus_dev_ven_id;		/* device/vendor ID */
254*6313Skrishnae 	uint8_t		bus_rev_id;		/* revision ID */
255*6313Skrishnae 	uint8_t		bus_hdr_type;		/* pci header type, see pci.h */
256*6313Skrishnae 	pcie_req_id_t	bus_pcie2pci_secbus;	/* PCIe2PCI Bridge secbus num */
257*6313Skrishnae 	uint16_t	bus_dev_type;		/* PCI-E dev type, see pcie.h */
258*6313Skrishnae 	uint8_t		bus_bdg_secbus;		/* Bridge secondary bus num */
259*6313Skrishnae 	uint16_t	bus_pcie_off;		/* PCIe Capability Offset */
260*6313Skrishnae 	uint16_t	bus_aer_off;		/* PCIe Advanced Error Offset */
261*6313Skrishnae 	uint16_t	bus_pcix_off;		/* PCIx Capability Offset */
262*6313Skrishnae 	uint16_t	bus_ecc_ver;		/* PCIX ecc version */
263*6313Skrishnae 	pci_bus_range_t	bus_bus_range;		/* pci bus-range property */
264*6313Skrishnae 	ppb_ranges_t	*bus_addr_ranges;	/* pci range property */
265*6313Skrishnae 	int		bus_addr_entries;	/* number of range prop */
266*6313Skrishnae 	pci_regspec_t	*bus_assigned_addr;	/* "assigned-address" prop */
267*6313Skrishnae 	int		bus_assigned_entries;	/* number of prop entries */
268*6313Skrishnae 
269*6313Skrishnae 	/* Cache of last fault data */
270*6313Skrishnae 	pf_data_t	*bus_pfd;
271*6313Skrishnae } pcie_bus_t;
2723274Set142600 
273*6313Skrishnae struct pf_data {
274*6313Skrishnae 	boolean_t		pe_lock;
275*6313Skrishnae 	boolean_t		pe_valid;
276*6313Skrishnae 	uint32_t		pe_severity_flags;	/* Severity of error */
277*6313Skrishnae 	pcie_bus_t		*pe_bus_p;
278*6313Skrishnae 	pf_root_fault_t		*pe_root_fault;	/* Only valid for RC and RP */
279*6313Skrishnae 	pf_pci_err_regs_t	*pe_pci_regs;	/* PCI error reg */
280*6313Skrishnae 	union {
281*6313Skrishnae 		pf_pcix_err_regs_t	*pe_pcix_regs;	/* PCI-X error reg */
282*6313Skrishnae 		pf_pcie_err_regs_t	*pe_pcie_regs;	/* PCIe error reg */
283*6313Skrishnae 	} pe_ext;
284*6313Skrishnae 	pf_pcix_bdg_err_regs_t *pe_pcix_bdg_regs; /* PCI-X bridge regs */
285*6313Skrishnae 	pf_data_t		*pe_prev;	/* Next error in queue */
286*6313Skrishnae 	pf_data_t		*pe_next;	/* Next error in queue */
287*6313Skrishnae };
288*6313Skrishnae 
289*6313Skrishnae /* Information used while handling errors in the fabric. */
290*6313Skrishnae typedef struct pf_impl {
291*6313Skrishnae 	ddi_fm_error_t	*pf_derr;
292*6313Skrishnae 	pf_root_fault_t	*pf_fault;	/* captured fault bdf/addr to scan */
293*6313Skrishnae 	pf_data_t	*pf_dq_head_p;	/* ptr to fault data queue */
294*6313Skrishnae 	pf_data_t	*pf_dq_tail_p;	/* ptr pt last fault data q */
295*6313Skrishnae 	uint32_t	pf_total;	/* total non RC pf_datas */
296*6313Skrishnae } pf_impl_t;
297*6313Skrishnae 
298*6313Skrishnae /* bus_fm_flags field */
299*6313Skrishnae #define	PF_FM_READY		(1 << 0)	/* bus_fm_lock initialized */
300*6313Skrishnae #define	PF_FM_IS_NH		(1 << 1)	/* known as non-hardened */
3013274Set142600 
302*6313Skrishnae /*
303*6313Skrishnae  * PCIe fabric handle lookup address flags.  Used to define what type of
304*6313Skrishnae  * transaction the address is for.  These same value are defined again in
305*6313Skrishnae  * fabric-xlate FM module.  Do not modify these variables, without modifying
306*6313Skrishnae  * those.
307*6313Skrishnae  */
308*6313Skrishnae #define	PF_ADDR_DMA		(1 << 0)
309*6313Skrishnae #define	PF_ADDR_PIO		(1 << 1)
310*6313Skrishnae #define	PF_ADDR_CFG		(1 << 2)
3113274Set142600 
312*6313Skrishnae /* PCIe fabric error scanning status flags */
313*6313Skrishnae #define	PF_SCAN_SUCCESS		(1 << 0)
314*6313Skrishnae #define	PF_SCAN_CB_FAILURE	(1 << 1) /* hardened device callback failure */
315*6313Skrishnae #define	PF_SCAN_NO_ERR_IN_CHILD	(1 << 2) /* no errors in bridge sec stat reg */
316*6313Skrishnae #define	PF_SCAN_IN_DQ		(1 << 3) /* already present in the faultq */
317*6313Skrishnae #define	PF_SCAN_DEADLOCK	(1 << 4) /* deadlock detected */
318*6313Skrishnae #define	PF_SCAN_BAD_RESPONSE	(1 << 5) /* Incorrect device response */
319*6313Skrishnae 
320*6313Skrishnae /* PCIe fabric error handling severity return flags */
321*6313Skrishnae #define	PF_ERR_NO_ERROR		(1 << 0) /* No error seen */
322*6313Skrishnae #define	PF_ERR_CE		(1 << 1) /* Correctable Error */
323*6313Skrishnae #define	PF_ERR_NO_PANIC		(1 << 2) /* Error should not panic sys */
324*6313Skrishnae #define	PF_ERR_MATCHED_DEVICE	(1 << 3) /* Error Handled By Device */
325*6313Skrishnae #define	PF_ERR_MATCHED_RC	(1 << 4) /* Error Handled By RC */
326*6313Skrishnae #define	PF_ERR_MATCHED_PARENT	(1 << 5) /* Error Handled By Parent */
327*6313Skrishnae #define	PF_ERR_PANIC		(1 << 6) /* Error should panic system */
328*6313Skrishnae #define	PF_ERR_PANIC_DEADLOCK	(1 << 7) /* deadlock detected */
329*6313Skrishnae 
330*6313Skrishnae #define	PF_ERR_FATAL_FLAGS	(PF_ERR_PANIC | PF_ERR_PANIC_DEADLOCK)
331*6313Skrishnae 
332*6313Skrishnae #define	PF_HDL_FOUND		1
333*6313Skrishnae #define	PF_HDL_NOTFOUND		2
334*6313Skrishnae 
335*6313Skrishnae #define	PCIE_PCIECAP_DEV_TYPE_RC_PSEUDO	0x100
3363274Set142600 
3373274Set142600 /* PCIe Friendly Functions */
33827Sjchu extern int pcie_initchild(dev_info_t *dip);
33927Sjchu extern void pcie_uninitchild(dev_info_t *dip);
340*6313Skrishnae extern void pcie_clear_errors(dev_info_t *dip);
3412738Skrishnae extern int pcie_postattach_child(dev_info_t *dip);
342*6313Skrishnae extern void pcie_enable_errors(dev_info_t *dip);
343*6313Skrishnae extern void pcie_disable_errors(dev_info_t *dip);
344*6313Skrishnae extern int pcie_enable_ce(dev_info_t *dip);
345*6313Skrishnae extern boolean_t pcie_bridge_is_link_disabled(dev_info_t *);
346*6313Skrishnae 
347*6313Skrishnae extern pcie_bus_t *pcie_init_bus(dev_info_t *cdip);
348*6313Skrishnae extern void pcie_fini_bus(dev_info_t *cdip);
349*6313Skrishnae extern void pcie_rc_init_bus(dev_info_t *dip);
350*6313Skrishnae extern void pcie_rc_fini_bus(dev_info_t *dip);
351*6313Skrishnae extern void pcie_rc_init_pfd(dev_info_t *dip, pf_data_t *pfd);
352*6313Skrishnae extern void pcie_rc_fini_pfd(pf_data_t *pfd);
353*6313Skrishnae extern boolean_t pcie_is_child(dev_info_t *dip, dev_info_t *rdip);
354*6313Skrishnae extern int pcie_get_bdf_from_dip(dev_info_t *dip, pcie_req_id_t *bdf);
3553156Sgirish extern dev_info_t *pcie_get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip);
3563249Sgovinda extern uint32_t pcie_get_bdf_for_dma_xfer(dev_info_t *dip, dev_info_t *rdip);
3573274Set142600 
358*6313Skrishnae extern uint32_t pcie_get_aer_uce_mask();
359*6313Skrishnae extern uint32_t pcie_get_aer_ce_mask();
360*6313Skrishnae extern uint32_t pcie_get_aer_suce_mask();
361*6313Skrishnae extern uint32_t pcie_get_serr_mask();
362*6313Skrishnae extern void pcie_set_aer_uce_mask(uint32_t mask);
363*6313Skrishnae extern void pcie_set_aer_ce_mask(uint32_t mask);
364*6313Skrishnae extern void pcie_set_aer_suce_mask(uint32_t mask);
365*6313Skrishnae extern void pcie_set_serr_mask(uint32_t mask);
3663274Set142600 
3673274Set142600 /* PCIe error handling functions */
3683274Set142600 extern int pf_scan_fabric(dev_info_t *rpdip, ddi_fm_error_t *derr,
369*6313Skrishnae     pf_data_t *root_pfd_p);
370*6313Skrishnae extern void pf_init(dev_info_t *, ddi_iblock_cookie_t, ddi_attach_cmd_t);
371*6313Skrishnae extern void pf_fini(dev_info_t *, ddi_detach_cmd_t);
372*6313Skrishnae extern int pf_hdl_lookup(dev_info_t *, uint64_t, uint32_t, uint64_t,
373*6313Skrishnae     pcie_req_id_t);
374*6313Skrishnae extern int pf_tlp_decode(pcie_bus_t *, pf_pcie_adv_err_regs_t *);
37527Sjchu 
37627Sjchu #ifdef	__cplusplus
37727Sjchu }
37827Sjchu #endif
37927Sjchu 
38027Sjchu #endif	/* _SYS_PCIE_IMPL_H */
381