xref: /illumos-gate/usr/src/uts/common/sys/pciev.h (revision 296f12dc)
1fc256490SJason Beloro /*
2fc256490SJason Beloro  * CDDL HEADER START
3fc256490SJason Beloro  *
4fc256490SJason Beloro  * The contents of this file are subject to the terms of the
5fc256490SJason Beloro  * Common Development and Distribution License (the "License").
6fc256490SJason Beloro  * You may not use this file except in compliance with the License.
7fc256490SJason Beloro  *
8fc256490SJason Beloro  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fc256490SJason Beloro  * or http://www.opensolaris.org/os/licensing.
10fc256490SJason Beloro  * See the License for the specific language governing permissions
11fc256490SJason Beloro  * and limitations under the License.
12fc256490SJason Beloro  *
13fc256490SJason Beloro  * When distributing Covered Code, include this CDDL HEADER in each
14fc256490SJason Beloro  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fc256490SJason Beloro  * If applicable, add the following below this CDDL HEADER, with the
16fc256490SJason Beloro  * fields enclosed by brackets "[]" replaced with your own identifying
17fc256490SJason Beloro  * information: Portions Copyright [yyyy] [name of copyright owner]
18fc256490SJason Beloro  *
19fc256490SJason Beloro  * CDDL HEADER END
20fc256490SJason Beloro  */
21fc256490SJason Beloro /*
22fc256490SJason Beloro  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23fc256490SJason Beloro  * Use is subject to license terms.
24fc256490SJason Beloro  */
25fc256490SJason Beloro 
26fc256490SJason Beloro #ifndef	_SYS_PCIEV_H
27fc256490SJason Beloro #define	_SYS_PCIEV_H
28fc256490SJason Beloro 
29fc256490SJason Beloro #ifdef	__cplusplus
30fc256490SJason Beloro extern "C" {
31fc256490SJason Beloro #endif
32fc256490SJason Beloro 
33fc256490SJason Beloro typedef struct pcie_eh_data {
34fc256490SJason Beloro 	uint16_t minor_ver;	/* Minor data packet version, added data */
35fc256490SJason Beloro 	uint16_t major_ver;	/* Major data packet version, struct change */
36fc256490SJason Beloro 	uint16_t pci_err_status;	/* pci status register */
37fc256490SJason Beloro 	uint16_t pci_bdg_sec_stat;	/* PCI secondary status reg */
38fc256490SJason Beloro 	uint32_t pcix_status;		/* pcix status register */
39fc256490SJason Beloro 	uint16_t pcix_bdg_sec_stat;	/* pcix bridge secondary status reg */
40fc256490SJason Beloro 	uint32_t pcix_bdg_stat;		/* pcix bridge status reg */
41fc256490SJason Beloro 	uint16_t pcix_ecc_control_0;	/* pcix ecc control status reg */
42fc256490SJason Beloro 	uint16_t pcix_ecc_status_0;	/* pcix ecc control status reg */
43fc256490SJason Beloro 	uint32_t pcix_ecc_fst_addr_0;	/* pcix ecc first address reg */
44fc256490SJason Beloro 	uint32_t pcix_ecc_sec_addr_0;	/* pcix ecc second address reg */
45fc256490SJason Beloro 	uint32_t pcix_ecc_attr_0;	/* pcix ecc attributes reg */
46fc256490SJason Beloro 	uint16_t pcix_ecc_control_1;	/* pcix ecc control status reg */
47fc256490SJason Beloro 	uint16_t pcix_ecc_status_1;	/* pcix ecc control status reg */
48fc256490SJason Beloro 	uint32_t pcix_ecc_fst_addr_1;	/* pcix ecc first address reg */
49fc256490SJason Beloro 	uint32_t pcix_ecc_sec_addr_1;	/* pcix ecc second address reg */
50fc256490SJason Beloro 	uint32_t pcix_ecc_attr_1;	/* pcix ecc attributes reg */
51fc256490SJason Beloro 	uint16_t pcie_err_status;	/* pcie device status register */
52fc256490SJason Beloro 	uint32_t pcie_ue_status;	/* pcie ue error status reg */
53fc256490SJason Beloro 	uint32_t pcie_ue_hdr[4];	/* pcie ue header log */
54fc256490SJason Beloro 	uint32_t pcie_ce_status;	/* pcie ce error status reg */
55fc256490SJason Beloro 	uint32_t pcie_sue_status;	/* pcie bridge secondary ue status */
56fc256490SJason Beloro 	uint32_t pcie_sue_hdr[4];	/* pcie bridge secondary ue hdr log */
57fc256490SJason Beloro 	uint16_t pcie_rp_ctl;		/* root port control register */
58fc256490SJason Beloro 	uint32_t pcie_rp_err_status;	/* pcie root port error status reg */
59fc256490SJason Beloro 	uint32_t pcie_rp_err_cmd;	/* pcie root port error cmd reg */
60fc256490SJason Beloro 	uint16_t pcie_rp_ce_src_id;	/* pcie root port ce sourpe id */
61fc256490SJason Beloro 	uint16_t pcie_rp_ue_src_id;	/* pcie root port ue sourpe id */
62fc256490SJason Beloro } pcie_eh_data_t;
63fc256490SJason Beloro 
64fc256490SJason Beloro typedef struct pcie_domains {
65fc256490SJason Beloro 	uint_t domain_id;
66fc256490SJason Beloro 	uint_t cached_count;	/* Reference Count of cached dom id list */
67fc256490SJason Beloro 	uint_t faulty_count;	/* Reference Count of faulty dom id list */
68fc256490SJason Beloro 	struct pcie_domains *cached_next; /* Next on cached dom id list */
69fc256490SJason Beloro 	struct pcie_domains *faulty_prev; /* Prev on faulty dom id list */
70fc256490SJason Beloro 	struct pcie_domains *faulty_next; /* Next on faulty dom id list */
71fc256490SJason Beloro } pcie_domains_t;
72fc256490SJason Beloro 
73fc256490SJason Beloro typedef struct pcie_req_id_list {
74fc256490SJason Beloro 	pcie_req_id_t		bdf;
75fc256490SJason Beloro 	struct pcie_req_id_list	*next;
76fc256490SJason Beloro } pcie_req_id_list_t;
77fc256490SJason Beloro 
78fc256490SJason Beloro typedef struct pcie_child_domains {
79fc256490SJason Beloro 	pcie_domains_t *ids;
80fc256490SJason Beloro 	pcie_req_id_list_t *bdfs;
81fc256490SJason Beloro } pcie_child_domains_t;
82fc256490SJason Beloro 
83fc256490SJason Beloro /*
84fc256490SJason Beloro  * IOV data structure:
85fc256490SJason Beloro  * This data strucutre is now statically allocated during bus_p
86fc256490SJason Beloro  * initializing time. Do we need to have this data structure for
87fc256490SJason Beloro  * non-root domains? If not, is there a way to differentiate root
88fc256490SJason Beloro  * domain and non-root domain so that we do the initialization for
89fc256490SJason Beloro  * root domain only?
90fc256490SJason Beloro  */
91fc256490SJason Beloro typedef struct pcie_domain {
92fc256490SJason Beloro 	/*
93fc256490SJason Beloro 	 * Bridges:
94fc256490SJason Beloro 	 * Cache the domain/channel id and bdfs of all it's children.
95fc256490SJason Beloro 	 *
96fc256490SJason Beloro 	 * Leaves:
97fc256490SJason Beloro 	 * Cache just the domain/channel id of self.
98fc256490SJason Beloro 	 * Bridges will contain 0 <= N <= NumChild
99fc256490SJason Beloro 	 *
100fc256490SJason Beloro 	 * Note:
101fc256490SJason Beloro 	 * there is no lock to protect the access to
102fc256490SJason Beloro 	 * pcie_domains_t data struture. Currently we don't see
103fc256490SJason Beloro 	 * the need for lock. But we need to pay attention if there
104fc256490SJason Beloro 	 * might be issues when hotplug is enabled.
105fc256490SJason Beloro 	 */
106fc256490SJason Beloro 	union {
107fc256490SJason Beloro 		pcie_child_domains_t ids;
108fc256490SJason Beloro 		pcie_domains_t id;
109fc256490SJason Beloro 	} domain;
110fc256490SJason Beloro 
111fc256490SJason Beloro 	/*
112fc256490SJason Beloro 	 * Reference count of the domain type for this device and it's children.
113fc256490SJason Beloro 	 * For leaf devices, fmadom + nfma + root = 1
114fc256490SJason Beloro 	 * For bridges, the sum of the counts = number of LEAF children.
115fc256490SJason Beloro 	 *
116fc256490SJason Beloro 	 * All devices start with a count of 1 for either nfmadom or rootdom.
117fc256490SJason Beloro 	 */
118fc256490SJason Beloro 	uint_t		fmadom_count;	/* FMA channel capable domain */
119fc256490SJason Beloro 	uint_t		nfmadom_count;	/* Non-FMA channel domain */
120fc256490SJason Beloro 	uint_t		rootdom_count;	/* Root domain */
121fc256490SJason Beloro 
122fc256490SJason Beloro 	/* flag if the affected dev will cause guest domains to panic */
123fc256490SJason Beloro 	boolean_t	nfma_panic;
124fc256490SJason Beloro } pcie_domain_t;
125fc256490SJason Beloro 
126fc256490SJason Beloro extern void pcie_domain_list_add(uint_t, pcie_domains_t **);
127fc256490SJason Beloro extern void pcie_domain_list_remove(uint_t, pcie_domains_t *);
128fc256490SJason Beloro extern void pcie_save_domain_id(pcie_domains_t *);
129fc256490SJason Beloro extern void pcie_init_dom(dev_info_t *);
130fc256490SJason Beloro extern void pcie_fini_dom(dev_info_t *);
131fc256490SJason Beloro 
132fc256490SJason Beloro #define	PCIE_ASSIGNED_TO_FMA_DOM(bus_p)	\
133fc256490SJason Beloro 	(!PCIE_IS_BDG(bus_p) && PCIE_BUS2DOM(bus_p)->fmadom_count > 0)
134fc256490SJason Beloro #define	PCIE_ASSIGNED_TO_NFMA_DOM(bus_p)	\
135fc256490SJason Beloro 	(!PCIE_IS_BDG(bus_p) && PCIE_BUS2DOM(bus_p)->nfmadom_count > 0)
136fc256490SJason Beloro #define	PCIE_ASSIGNED_TO_ROOT_DOM(bus_p)			\
137fc256490SJason Beloro 	(PCIE_IS_BDG(bus_p) || PCIE_BUS2DOM(bus_p)->rootdom_count > 0)
138fc256490SJason Beloro #define	PCIE_BDG_HAS_CHILDREN_FMA_DOM(bus_p)			\
139fc256490SJason Beloro 	(PCIE_IS_BDG(bus_p) && PCIE_BUS2DOM(bus_p)->fmadom_count > 0)
140fc256490SJason Beloro #define	PCIE_BDG_HAS_CHILDREN_NFMA_DOM(bus_p)			\
141fc256490SJason Beloro 	(PCIE_IS_BDG(bus_p) && PCIE_BUS2DOM(bus_p)->nfmadom_count > 0)
142fc256490SJason Beloro #define	PCIE_BDG_HAS_CHILDREN_ROOT_DOM(bus_p)			\
143fc256490SJason Beloro 	(PCIE_IS_BDG(bus_p) && PCIE_BUS2DOM(bus_p)->rootdom_count > 0)
144fc256490SJason Beloro #define	PCIE_IS_ASSIGNED(bus_p)	\
145fc256490SJason Beloro 	(!PCIE_ASSIGNED_TO_ROOT_DOM(bus_p))
146fc256490SJason Beloro #define	PCIE_BDG_IS_UNASSIGNED(bus_p)	\
147fc256490SJason Beloro 	(PCIE_IS_BDG(bus_p) &&		\
148fc256490SJason Beloro 	(!PCIE_BDG_HAS_CHILDREN_NFMA_DOM(bus_p)) &&	\
149fc256490SJason Beloro 	(!PCIE_BDG_HAS_CHILDREN_FMA_DOM(bus_p)))
150fc256490SJason Beloro 
151fc256490SJason Beloro 
152fc256490SJason Beloro #define	PCIE_IN_DOMAIN(bus_p, id) (pcie_in_domain((bus_p), (id)))
153fc256490SJason Beloro 
154fc256490SJason Beloro /* Following macros are only valid for leaf devices */
155fc256490SJason Beloro #define	PCIE_DOMAIN_ID_GET(bus_p) \
156fc256490SJason Beloro 	((uint_t)(PCIE_IS_ASSIGNED(bus_p)			\
157*296f12dcSToomas Soome 	    ? PCIE_BUS2DOM(bus_p)->domain.id.domain_id : 0))
158fc256490SJason Beloro #define	PCIE_DOMAIN_ID_SET(bus_p, new_id) \
159fc256490SJason Beloro 	if (!PCIE_IS_BDG(bus_p)) \
160fc256490SJason Beloro 		PCIE_BUS2DOM(bus_p)->domain.id.domain_id = (uint_t)(new_id)
161fc256490SJason Beloro #define	PCIE_DOMAIN_ID_INCR_REF_COUNT(bus_p)	\
162fc256490SJason Beloro 	if (!PCIE_IS_BDG(bus_p))	\
163fc256490SJason Beloro 		PCIE_BUS2DOM(bus_p)->domain.id.cached_count = 1;
164fc256490SJason Beloro #define	PCIE_DOMAIN_ID_DECR_REF_COUNT(bus_p)	\
165fc256490SJason Beloro 	if (!PCIE_IS_BDG(bus_p))	\
166fc256490SJason Beloro 		PCIE_BUS2DOM(bus_p)->domain.id.cached_count = 0;
167fc256490SJason Beloro 
168fc256490SJason Beloro /* Following macros are only valid for bridges */
169fc256490SJason Beloro #define	PCIE_DOMAIN_LIST_GET(bus_p) \
170fc256490SJason Beloro 	((pcie_domains_t *)(PCIE_IS_BDG(bus_p) ?	\
171fc256490SJason Beloro 	    PCIE_BUS2DOM(bus_p)->domain.ids.ids : NULL))
172fc256490SJason Beloro #define	PCIE_DOMAIN_LIST_ADD(bus_p, domain_id) \
173fc256490SJason Beloro 	if (PCIE_IS_BDG(bus_p)) \
174fc256490SJason Beloro 	    pcie_domain_list_add(domain_id, \
175fc256490SJason Beloro 		&PCIE_BUS2DOM(bus_p)->domain.ids.ids)
176fc256490SJason Beloro #define	PCIE_DOMAIN_LIST_REMOVE(bus_p, domain_id) \
177fc256490SJason Beloro 	if (PCIE_IS_BDG(bus_p)) \
178fc256490SJason Beloro 	    pcie_domain_list_remove(domain_id, \
179fc256490SJason Beloro 		PCIE_BUS2DOM(bus_p)->domain.ids.ids)
180fc256490SJason Beloro 
181fc256490SJason Beloro #define	PCIE_BDF_LIST_GET(bus_p) \
182fc256490SJason Beloro 	((pcie_req_id_list_t *)(PCIE_IS_BDG(bus_p) ? \
183fc256490SJason Beloro 	    PCIE_BUS2DOM(bus_p)->domain.ids.bdfs : NULL))
184fc256490SJason Beloro #define	PCIE_BDF_LIST_ADD(bus_p, bdf) \
185fc256490SJason Beloro 	if (PCIE_IS_BDG(bus_p)) \
186fc256490SJason Beloro 		pcie_bdf_list_add(bdf, &PCIE_BUS2DOM(bus_p)->domain.ids.bdfs)
187fc256490SJason Beloro #define	PCIE_BDF_LIST_REMOVE(bus_p, bdf) \
188fc256490SJason Beloro 	if (PCIE_IS_BDG(bus_p)) \
189fc256490SJason Beloro 		pcie_bdf_list_remove(bdf, &PCIE_BUS2DOM(bus_p)->domain.ids.bdfs)
190fc256490SJason Beloro 
191fc256490SJason Beloro #ifdef	__cplusplus
192fc256490SJason Beloro }
193fc256490SJason Beloro #endif
194fc256490SJason Beloro 
195fc256490SJason Beloro #endif	/* _SYS_PCIEV_H */
196