xref: /illumos-gate/usr/src/uts/common/sys/pcie.h (revision 445f2479fe3d7435daab18bf2cdc310b86cd6738)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_PCIE_H
28 #define	_SYS_PCIE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/pci.h>
37 
38 /*
39  * PCI Express capability registers in PCI configuration space relative to
40  * the PCI Express Capability structure.
41  */
42 #define	PCIE_CAP_ID			PCI_CAP_ID
43 #define	PCIE_CAP_NEXT_PTR		PCI_CAP_NEXT_PTR
44 #define	PCIE_PCIECAP			0x02	/* PCI-e Capability Reg */
45 #define	PCIE_DEVCAP			0x04	/* Device Capability */
46 #define	PCIE_DEVCTL			0x08	/* Device Control */
47 #define	PCIE_DEVSTS			0x0A	/* Device Status */
48 #define	PCIE_LINKCAP			0x04	/* Link Capability */
49 #define	PCIE_LINKCTL			0x0C	/* Link Control */
50 #define	PCIE_LINKSTS			0x10	/* Link Status */
51 #define	PCIE_SLOTCAP			0x14	/* Slot Capability */
52 #define	PCIE_SLOTCTL			0x18	/* Slot Control */
53 #define	PCIE_SLOTSTS			0x1A	/* Slot Status */
54 #define	PCIE_ROOTCTL			0x1C	/* Root Control */
55 #define	PCIE_ROOTSTS			0x20	/* Root Status */
56 
57 /*
58  * PCI-Express Config Space size
59  */
60 #define	PCIE_CONF_HDR_SIZE	4096	/* PCIe configuration header size */
61 
62 /*
63  * PCI-Express Capabilities Register (2 bytes)
64  */
65 #define	PCIE_PCIECAP_VER_1_0		0x1	/* PCI-E spec 1.0 */
66 #define	PCIE_PCIECAP_VER_MASK		0xF	/* Version Mask */
67 #define	PCIE_PCIECAP_DEV_TYPE_PCIE_DEV	0x00	/* PCI-E Endpont Device */
68 #define	PCIE_PCIECAP_DEV_TYPE_PCI_DEV	0x10	/* Leg PCI Endpont Device */
69 #define	PCIE_PCIECAP_DEV_TYPE_ROOT	0x40	/* Root Port of Root Complex */
70 #define	PCIE_PCIECAP_DEV_TYPE_UP	0x50	/* Upstream Port of Switch */
71 #define	PCIE_PCIECAP_DEV_TYPE_DOWN	0x60	/* Downstream Port of Switch */
72 #define	PCIE_PCIECAP_DEV_TYPE_PCIE2PCI	0x70	/* PCI-E to PCI Bridge */
73 #define	PCIE_PCIECAP_DEV_TYPE_PCI2PCIE	0x80	/* PCI to PCI-E Bridge */
74 #define	PCIE_PCIECAP_DEV_TYPE_MASK	0xF0	/* Device/Port Type Mask */
75 #define	PCIE_PCIECAP_SLOT_IMPL		0x100	/* Slot Impl vs Integrated */
76 #define	PCIE_PCIECAP_INT_MSG_NUM	0x3700	/* Interrupt Message Number */
77 
78 /*
79  * Device Capabilities Register (4 bytes)
80  */
81 #define	PCIE_DEVCAP_MAX_PAYLOAD_128	0x0
82 #define	PCIE_DEVCAP_MAX_PAYLOAD_256	0x1
83 #define	PCIE_DEVCAP_MAX_PAYLOAD_512	0x2
84 #define	PCIE_DEVCAP_MAX_PAYLOAD_1024	0x3
85 #define	PCIE_DEVCAP_MAX_PAYLOAD_2048	0x4
86 #define	PCIE_DEVCAP_MAX_PAYLOAD_4096	0x5
87 #define	PCIE_DEVCAP_MAX_PAYLOAD_MASK	0x7	/* Max Payload Size Supported */
88 
89 #define	PCIE_DEVCAP_PHTM_FUNC_NONE	0x00	/* No Function # bits used */
90 #define	PCIE_DEVCAP_PHTM_FUNC_ONE	0x08	/* First most sig. bit used */
91 #define	PCIE_DEVCAP_PHTM_FUNC_TWO	0x10	/* First 2 most sig bit used */
92 #define	PCIE_DEVCAP_PHTM_FUNC_THREE	0x18	/* All 3 bits used */
93 #define	PCIE_DEVCAP_PHTM_FUNC_MASK	0x18	/* Phantom Func Supported */
94 
95 #define	PCIE_DEVCAP_EXT_TAG_5BIT	0x00	/* 5-Bit Tag Field Supported */
96 #define	PCIE_DEVCAP_EXT_TAG_8BIT	0x20	/* 8-Bit Tag Field Supported */
97 #define	PCIE_DEVCAP_EXT_TAG_MASK	0x20	/* Ext. Tag Field Supported */
98 
99 #define	PCIE_DEVCAP_EP_L0S_LAT_MIN	0x000	/* < 64 ns */
100 #define	PCIE_DEVCAP_EP_L0S_LAT_64ns	0x040	/* 64 ns - 128 ns */
101 #define	PCIE_DEVCAP_EP_L0S_LAT_128ns	0x080	/* 128 ns - 256 ns */
102 #define	PCIE_DEVCAP_EP_L0S_LAT_256ns	0x0C0	/* 256 ns - 512 ns */
103 #define	PCIE_DEVCAP_EP_L0S_LAT_512ns	0x100	/* 512 ns - 1 us */
104 #define	PCIE_DEVCAP_EP_L0S_LAT_1us	0x140	/* 1 us - 2 us */
105 #define	PCIE_DEVCAP_EP_L0S_LAT_2us	0x180	/* 2 us - 4 us */
106 #define	PCIE_DEVCAP_EP_L0S_LAT_MAX	0x1C0	/* > 4 us */
107 #define	PCIE_DEVCAP_EP_L0S_LAT_MASK	0x1C0	/* EP L0s Accetable Latency */
108 
109 #define	PCIE_DEVCAP_EP_L1_LAT_MIN	0x000	/* < 1 us */
110 #define	PCIE_DEVCAP_EP_L1_LAT_1us	0x140	/* 1 us - 2 us */
111 #define	PCIE_DEVCAP_EP_L1_LAT_2us	0x180	/* 2 us - 4 us */
112 #define	PCIE_DEVCAP_EP_L1_LAT_4us	0x140	/* 4 us - 8 us */
113 #define	PCIE_DEVCAP_EP_L1_LAT_8us	0x180	/* 8 us - 16 us */
114 #define	PCIE_DEVCAP_EP_L1_LAT_16us	0x140	/* 16 us - 32 us */
115 #define	PCIE_DEVCAP_EP_L1_LAT_32us	0x180	/* 32 us - 64 us */
116 #define	PCIE_DEVCAP_EP_L1_LAT_MAX	0x1C0	/* > 64 us */
117 #define	PCIE_DEVCAP_EP_L1_LAT_MASK	0x700	/* EP L1 Accetable Latency */
118 
119 #define	PCIE_DEVCAP_ATTN_BUTTON		0x1000	/* Attention Button Present */
120 #define	PCIE_DEVCAP_ATTN_INDICATOR	0x2000	/* Attn Indicator Present */
121 #define	PCIE_DEVCAP_PWR_INDICATOR	0x4000	/* Power Indicator Present */
122 
123 #define	PCIE_DEVCAP_PLMT_VAL_SHIFT	18	/* Power Limit Value Shift */
124 #define	PCIE_DEVCAP_PLMT_VAL_MASK	0xFF	/* Power Limit Value Mask */
125 
126 #define	PCIE_DEVCAP_PLMT_SCL_1_BY_1	0x0000000	/* 1x Scale */
127 #define	PCIE_DEVCAP_PLMT_SCL_1_BY_10	0x4000000	/* 0.1x Scale */
128 #define	PCIE_DEVCAP_PLMT_SCL_1_BY_100	0x8000000	/* 0.01x Scale */
129 #define	PCIE_DEVCAP_PLMT_SCL_1_BY_1000	0xC000000	/* 0.001x Scale */
130 #define	PCIE_DEVCAP_PLMT_SCL_MASK	0xC000000	/* Power Limit Scale */
131 
132 /*
133  * Device Control Register (2 bytes)
134  */
135 #define	PCIE_DEVCTL_CE_REPORTING_EN	0x1	/* Correctable Error Enable */
136 #define	PCIE_DEVCTL_NFE_REPORTING_EN	0x2	/* Non-Fatal Error Enable */
137 #define	PCIE_DEVCTL_FE_REPORTING_EN	0x4	/* Fatal Error Enable */
138 #define	PCIE_DEVCTL_UR_REPORTING_EN	0x8	/* Unsupported Request Enable */
139 #define	PCIE_DEVCTL_RO_EN		0x10	/* Enable Relaxed Ordering */
140 
141 #define	PCIE_DEVCTL_MAX_PAYLOAD_128	0x00
142 #define	PCIE_DEVCTL_MAX_PAYLOAD_256	0x20
143 #define	PCIE_DEVCTL_MAX_PAYLOAD_512	0x40
144 #define	PCIE_DEVCTL_MAX_PAYLOAD_1024	0x60
145 #define	PCIE_DEVCTL_MAX_PAYLOAD_2048	0x80
146 #define	PCIE_DEVCTL_MAX_PAYLOAD_4096	0xA0
147 #define	PCIE_DEVCTL_MAX_PAYLOAD_MASK	0xE0	/* Max_Payload_Size */
148 
149 #define	PCIE_DEVCTL_EXT_TAG_FIELD_EN	0x100	/* Extended Tag Field Enable */
150 #define	PCIE_DEVCTL_PHTM_FUNC_EN	0x200	/* Phantom Functions Enable */
151 #define	PCIE_DEVCTL_AUX_POWER_PM_EN	0x400	/* Auxiliary Power PM Enable */
152 #define	PCIE_DEVCTL_ENABLE_NO_SNOOP	0x800	/* Enable No Snoop */
153 
154 #define	PCIE_DEVCTL_MAX_READ_REQ_128	0x00
155 #define	PCIE_DEVCTL_MAX_READ_REQ_256	0x10
156 #define	PCIE_DEVCTL_MAX_READ_REQ_512	0x20
157 #define	PCIE_DEVCTL_MAX_READ_REQ_1024	0x30
158 #define	PCIE_DEVCTL_MAX_READ_REQ_2048	0x40
159 #define	PCIE_DEVCTL_MAX_READ_REQ_4096	0x50
160 #define	PCIE_DEVCTL_MAX_READ_REQ_MASK	0x7000	/* Max_Read_Request_Size */
161 
162 /*
163  * Device Status Register (2 bytes)
164  */
165 #define	PCIE_DEVSTS_CE_DETECTED		0x1	/* Correctable Error Detected */
166 #define	PCIE_DEVSTS_NFE_DETECTED	0x2	/* Non Fatal Error Detected */
167 #define	PCIE_DEVSTS_FE_DETECTED		0x4	/* Fatal Error Detected */
168 #define	PCIE_DEVSTS_UR_DETECTED		0x8	/* Unsupported Req Detected */
169 #define	PCIE_DEVSTS_AUX_POWER		0x10	/* AUX Power Detected */
170 #define	PCIE_DEVSTS_TRANS_PENDING	0x20	/* Transactions Pending */
171 
172 /*
173  * Link Capability Register (4 bytes)
174  */
175 #define	PCIE_LINKCAP_MAX_SPEED_2_5	0x1	/* 2.5 Gb/s Speed */
176 #define	PCIE_LINKCAP_MAX_SPEED_MASK	0xF	/* Maximum Link Speed */
177 #define	PCIE_LINKCAP_MAX_WIDTH_X1	0x010
178 #define	PCIE_LINKCAP_MAX_WIDTH_X2	0x020
179 #define	PCIE_LINKCAP_MAX_WIDTH_X4	0x040
180 #define	PCIE_LINKCAP_MAX_WIDTH_X8	0x080
181 #define	PCIE_LINKCAP_MAX_WIDTH_X12	0x0C0
182 #define	PCIE_LINKCAP_MAX_WIDTH_X16	0x100
183 #define	PCIE_LINKCAP_MAX_WIDTH_X32	0x200
184 #define	PCIE_LINKCAP_MAX_WIDTH_MASK	0x3f0	/* Maximum Link Width */
185 
186 #define	PCIE_LINKCAP_ASPM_SUP_L0S	0x400	/* L0s Entry Supported */
187 #define	PCIE_LINKCAP_ASPM_SUP_L0S_L1	0xC00	/* L0s abd L1 Supported */
188 #define	PCIE_LINKCAP_ASPM_SUP_MASK	0xC00	/* ASPM Support */
189 
190 #define	PCIE_LINKCAP_L0S_EXIT_LAT_MIN	0x0000	/* < 64 ns */
191 #define	PCIE_LINKCAP_L0S_EXIT_LAT_64ns	0x1000	/* 64 ns - 128 ns */
192 #define	PCIE_LINKCAP_L0S_EXIT_LAT_128ns	0x2000	/* 128 ns - 256 ns */
193 #define	PCIE_LINKCAP_L0S_EXIT_LAT_256ns	0x3000	/* 256 ns - 512 ns */
194 #define	PCIE_LINKCAP_L0S_EXIT_LAT_512ns	0x4000	/* 512 ns - 1 us */
195 #define	PCIE_LINKCAP_L0S_EXIT_LAT_1us	0x5000	/* 1 us - 2 us */
196 #define	PCIE_LINKCAP_L0S_EXIT_LAT_2us	0x6000	/* 2 us - 4 us */
197 #define	PCIE_LINKCAP_L0S_EXIT_LAT_MAX	0x7000	/* > 4 us */
198 #define	PCIE_LINKCAP_L0S_EXIT_LAT_MASK	0x7000	/* L0s Exit Latency */
199 
200 #define	PCIE_LINKCAP_L1_EXIT_LAT_MIN	0x00000	/* < 1 us */
201 #define	PCIE_LINKCAP_L1_EXIT_LAT_1us	0x08000	/* 1 us - 2 us */
202 #define	PCIE_LINKCAP_L1_EXIT_LAT_2us	0x10000	/* 2 us - 4 us */
203 #define	PCIE_LINKCAP_L1_EXIT_LAT_4us	0x18000	/* 4 us - 8 us */
204 #define	PCIE_LINKCAP_L1_EXIT_LAT_8us	0x20000	/* 8 us - 16 us */
205 #define	PCIE_LINKCAP_L1_EXIT_LAT_16us	0x28000	/* 16 us - 32 us */
206 #define	PCIE_LINKCAP_L1_EXIT_LAT_32us	0x30000	/* 32 us - 64 us */
207 #define	PCIE_LINKCAP_L1_EXIT_LAT_MAX	0x38000	/* > 64 us */
208 #define	PCIE_LINKCAP_L1_EXIT_LAT_MASK	0x38000	/* L1 Exit Latency */
209 
210 /* PCIe v1.1 spec based */
211 #define	PCIE_LINKCAP_DLL_ACTIVE_REP_CAPABLE	0x100000    /* DLL Active */
212 							    /* Capable bit */
213 
214 #define	PCIE_LINKCAP_PORT_NUMBER	0xF0000000	/* Port Number */
215 
216 /*
217  * Link Control Register (2 bytes)
218  */
219 #define	PCIE_LINKCTL_ASPM_CTL_DIS	0x0	/* ASPM Disable */
220 #define	PCIE_LINKCTL_ASPM_CTL_L0S	0x1	/* ASPM L0s only */
221 #define	PCIE_LINKCTL_ASPM_CTL_L1	0x2	/* ASPM L1 only */
222 #define	PCIE_LINKCTL_ASPM_CTL_L0S_L1	0x3	/* ASPM L0s and L1 only */
223 #define	PCIE_LINKCTL_ASPM_CTL_MASK	0x3	/* ASPM Control */
224 
225 #define	PCIE_LINKCTL_RCB_64_BYTE	0x0	/* 64 Byte */
226 #define	PCIE_LINKCTL_RCB_128_BYTE	0x8	/* 128 Byte */
227 #define	PCIE_LINKCTL_RCB_MASK		0x8	/* Read Completion Boundary */
228 
229 #define	PCIE_LINKCTL_LINK_DISABLE	0x10	/* Link Disable */
230 #define	PCIE_LINKCTL_RETRAIN_LINK	0x20	/* Retrain Link */
231 #define	PCIE_LINKCTL_COMMON_CLK_CFG	0x40	/* Common Clock Configuration */
232 #define	PCIE_LINKCTL_EXT_SYNCH		0x80	/* Extended Synch */
233 
234 /*
235  * Link Status Register (2 bytes)
236  */
237 #define	PCIE_LINKSTS_SPEED_2_5		0x1	/* Link Speed */
238 #define	PCIE_LINKSTS_SPEED_MASK		0xF	/* Link Speed */
239 
240 #define	PCIE_LINKSTS_NEG_WIDTH_X1	0x010
241 #define	PCIE_LINKSTS_NEG_WIDTH_X2	0x020
242 #define	PCIE_LINKSTS_NEG_WIDTH_X4	0x040
243 #define	PCIE_LINKSTS_NEG_WIDTH_X8	0x080
244 #define	PCIE_LINKSTS_NEG_WIDTH_X12	0x0C0
245 #define	PCIE_LINKSTS_NEG_WIDTH_X16	0x100
246 #define	PCIE_LINKSTS_NEG_WIDTH_X32	0x200
247 #define	PCIE_LINKSTS_NEG_WIDTH_MASK	0x3F0	/* Negotiated Link Width */
248 
249 #define	PCIE_LINKSTS_TRAINING_ERROR	0x400	/* Training Error */
250 #define	PCIE_LINKSTS_LINK_TRAINING	0x800	/* Link Training */
251 #define	PCIE_LINKSTS_SLOT_CLK_CFG	0x1000	/* Slot Clock Configuration */
252 
253 /*
254  * Slot Capability Register (4 bytes)
255  */
256 #define	PCIE_SLOTCAP_ATTN_BUTTON	0x1	/* Attention Button Present */
257 #define	PCIE_SLOTCAP_POWER_CONTROLLER	0x2	/* Power Controller Present */
258 #define	PCIE_SLOTCAP_MRL_SENSOR		0x4	/* MRL Sensor Present */
259 #define	PCIE_SLOTCAP_ATTN_INDICATOR	0x8	/* Attn Indicator Present */
260 #define	PCIE_SLOTCAP_PWR_INDICATOR	0x10	/* Power Indicator Present */
261 #define	PCIE_SLOTCAP_HP_SURPRISE	0x20	/* Hot-Plug Surprise */
262 #define	PCIE_SLOTCAP_HP_CAPABLE		0x40	/* Hot-Plug Capable */
263 
264 #define	PCIE_SLOTCAP_PLMT_VAL_SHIFT	7	/* Slot Pwr Limit Value Shift */
265 #define	PCIE_SLOTCAP_PLMT_VAL_MASK	0xFF	/* Slot Pwr Limit Value */
266 
267 #define	PCIE_SLOTCAP_PLMT_SCL_1_BY_1	0x00000	/* 1x Scale */
268 #define	PCIE_SLOTCAP_PLMT_SCL_1_BY_10	0x08000	/* 0.1x Scale */
269 #define	PCIE_SLOTCAP_PLMT_SCL_1_BY_100	0x10000	/* 0.01x Scale */
270 #define	PCIE_SLOTCAP_PLMT_SCL_1_BY_1000	0x18000	/* 0.001x Scale */
271 #define	PCIE_SLOTCAP_PLMT_SCL_MASK	0x18000	/* Slot Power Limit Scale */
272 #define	PCIE_SLOTCAP_EMI_LOCK_PRESENT	0x20000 /* EMI Lock Present */
273 #define	PCIE_SLOTCAP_NO_CMD_COMP_SUPP	0x40000 /* No Command Comp. Supported */
274 
275 #define	PCIE_SLOTCAP_PHY_SLOT_NUM_SHIFT	19	/* Physical Slot Num Shift */
276 #define	PCIE_SLOTCAP_PHY_SLOT_NUM_MASK	0x1FFF	/* Physical Slot Num Mask */
277 
278 #define	PCIE_SLOTCAP_PHY_SLOT_NUM(reg) \
279 	    (((reg) >> PCIE_SLOTCAP_PHY_SLOT_NUM_SHIFT) & \
280 	    PCIE_SLOTCAP_PHY_SLOT_NUM_MASK)
281 
282 /*
283  * Slot Control Register (2 bytes)
284  */
285 #define	PCIE_SLOTCTL_ATTN_BTN_EN	0x1	/* Attn Button Pressed Enable */
286 #define	PCIE_SLOTCTL_PWR_FAULT_EN	0x2	/* Pwr Fault Detected Enable */
287 #define	PCIE_SLOTCTL_MRL_SENSOR_EN	0x4	/* MRL Sensor Changed Enable */
288 #define	PCIE_SLOTCTL_PRESENCE_CHANGE_EN	0x8	/* Presence Detect Changed En */
289 #define	PCIE_SLOTCTL_CMD_INTR_EN	0x10	/* CMD Completed Interrupt En */
290 #define	PCIE_SLOTCTL_HP_INTR_EN		0x20	/* Hot-Plug Interrupt Enable */
291 #define	PCIE_SLOTCTL_PWR_CONTROL	0x0400	/* Power controller Control */
292 #define	PCIE_SLOTCTL_EMI_LOCK_CONTROL	0x0800	/* EMI Lock control */
293 #define	PCIE_SLOTCTL_ATTN_INDICATOR_MASK 0x00C0	/* Attn Indicator mask */
294 #define	PCIE_SLOTCTL_PWR_INDICATOR_MASK	0x0300	/* Power Indicator mask */
295 
296 /* State values for the Power and Attention Indicators */
297 #define	PCIE_SLOTCTL_INDICATOR_STATE_ON		0x1	/* indicator ON */
298 #define	PCIE_SLOTCTL_INDICATOR_STATE_BLINK	0x2	/* indicator BLINK */
299 #define	PCIE_SLOTCTL_INDICATOR_STATE_OFF	0x3	/* indicator OFF */
300 
301 /*
302  * Macros to set/get the state of Power and Attention Indicators
303  * in the PCI Express Slot Control Register.
304  */
305 #define	pcie_slotctl_pwr_indicator_get(reg)	\
306 	(((reg) & PCIE_SLOTCTL_PWR_INDICATOR_MASK) >> 8)
307 #define	pcie_slotctl_attn_indicator_get(ctrl)	\
308 	(((ctrl) & PCIE_SLOTCTL_ATTN_INDICATOR_MASK) >> 6)
309 #define	pcie_slotctl_attn_indicator_set(ctrl, v)\
310 	(((ctrl) & ~PCIE_SLOTCTL_ATTN_INDICATOR_MASK) | ((v) << 6))
311 #define	pcie_slotctl_pwr_indicator_set(ctrl, v)\
312 	(((ctrl) & ~PCIE_SLOTCTL_PWR_INDICATOR_MASK) | ((v) << 8))
313 
314 /*
315  * Slot Status register (2 bytes)
316  */
317 #define	PCIE_SLOTSTS_ATTN_BTN_PRESSED	0x1	/* Attention Button Pressed */
318 #define	PCIE_SLOTSTS_PWR_FAULT_DETECTED	0x2	/* Power Fault Detected */
319 #define	PCIE_SLOTSTS_MRL_SENSOR_CHANGED	0x4	/* MRL Sensor Changed */
320 #define	PCIE_SLOTSTS_PRESENCE_CHANGED	0x8	/* Presence Detect Changed */
321 #define	PCIE_SLOTSTS_COMMAND_COMPLETED	0x10	/* Command Completed */
322 #define	PCIE_SLOTSTS_MRL_SENSOR_OPEN	0x20	/* MRL Sensor Open */
323 #define	PCIE_SLOTSTS_PRESENCE_DETECTED	0x40	/* Card Present in slot */
324 #define	PCIE_SLOTSTS_EMI_LOCK_SET	0x0080	/* EMI Lock set */
325 #define	PCIE_SLOTSTS_DLL_STATE_CHANGED	0x0100	/* DLL State Changed */
326 
327 /*
328  * Root Control Register (2 bytes)
329  */
330 #define	PCIE_ROOTCTL_SYS_ERR_ON_CE_EN	0x1	/* Sys Err on Cor Err Enable */
331 #define	PCIE_ROOTCTL_SYS_ERR_ON_NFE_EN	0x2	/* Sys Err on NF Err Enable */
332 #define	PCIE_ROOTCTL_SYS_ERR_ON_FE_EN	0x4	/* Sys Err on Fatal Err En */
333 #define	PCIE_ROOTCTL_PME_INTERRUPT_EN	0x8	/* PME Interrupt Enable */
334 
335 /*
336  * Root Status Register (4 bytes)
337  */
338 #define	PCIE_ROOTSTS_PME_REQ_ID_SHIFT	0	/* PME Requestor ID */
339 #define	PCIE_ROOTSTS_PME_REQ_ID_MASK	0xFFFF	/* PME Requestor ID */
340 
341 #define	PCIE_ROOTSTS_PME_STATUS		0x10000	/* PME Status */
342 #define	PCIE_ROOTSTS_PME_PENDING	0x20000	/* PME Pending */
343 
344 
345 /*
346  * PCI-Express Enhanced Capabilities Link Entry Bit Offsets
347  */
348 #define	PCIE_EXT_CAP			0x100	/* Base Address of Ext Cap */
349 
350 #define	PCIE_EXT_CAP_ID_SHIFT		0	/* PCI-e Ext Cap ID */
351 #define	PCIE_EXT_CAP_ID_MASK		0xFFFF
352 #define	PCIE_EXT_CAP_VER_SHIFT		16	/* PCI-e Ext Cap Ver */
353 #define	PCIE_EXT_CAP_VER_MASK		0xF
354 #define	PCIE_EXT_CAP_NEXT_PTR_SHIFT	20	/* PCI-e Ext Cap Next Ptr */
355 #define	PCIE_EXT_CAP_NEXT_PTR_MASK	0xFFF
356 
357 #define	PCIE_EXT_CAP_NEXT_PTR_NULL	0x0
358 
359 /*
360  * PCI-Express Enhanced Capability Identifier Values
361  */
362 #define	PCIE_EXT_CAP_ID_AER		0x1	/* Advanced Error Handling */
363 #define	PCIE_EXT_CAP_ID_VC		0x2	/* Virtual Channel */
364 #define	PCIE_EXT_CAP_ID_SER		0x3	/* Serial Number */
365 #define	PCIE_EXT_CAP_ID_PWR_BUDGET	0x4	/* Power Budgeting */
366 
367 /*
368  * PCI-Express Advanced Error Reporting Extended Capability Offsets
369  */
370 #define	PCIE_AER_CAP			0x0	/* Enhanced Capability Header */
371 #define	PCIE_AER_UCE_STS		0x4	/* Uncorrectable Error Status */
372 #define	PCIE_AER_UCE_MASK		0x8	/* Uncorrectable Error Mask */
373 #define	PCIE_AER_UCE_SERV		0xc	/* Uncor Error Severity */
374 #define	PCIE_AER_CE_STS			0x10	/* Correctable Error Status */
375 #define	PCIE_AER_CE_MASK		0x14	/* Correctable Error Mask */
376 #define	PCIE_AER_CTL			0x18	/* AER Capability & Control */
377 #define	PCIE_AER_HDR_LOG		0x1c	/* Header Log */
378 
379 /* Root Ports Only */
380 #define	PCIE_AER_RE_CMD			0x2c	/* Root Error Command */
381 #define	PCIE_AER_RE_STS			0x30	/* Root Error Status */
382 #define	PCIE_AER_CE_SRC_ID		0x34	/* Error Source ID */
383 #define	PCIE_AER_ERR_SRC_ID		0x36	/* Error Source ID */
384 
385 /* Bridges Only */
386 #define	PCIE_AER_SUCE_STS		0x2c	/* Secondary UCE Status */
387 #define	PCIE_AER_SUCE_MASK		0x30	/* Secondary UCE Mask */
388 #define	PCIE_AER_SUCE_SERV		0x34	/* Secondary UCE Severity */
389 #define	PCIE_AER_SCTL			0x38	/* Secondary Cap & Ctl */
390 #define	PCIE_AER_SHDR_LOG		0x3c	/* Secondary Header Log */
391 
392 /*
393  * AER Uncorrectable Error Status/Mask/Severity Register
394  */
395 #define	PCIE_AER_UCE_TRAINING		0x0	/* Training Error Status */
396 #define	PCIE_AER_UCE_DLP		0x10	/* Data Link Protocol Error */
397 #define	PCIE_AER_UCE_PTLP		0x1000	/* Poisoned TLP Status */
398 #define	PCIE_AER_UCE_FCP		0x2000	/* Flow Control Protocol Sts */
399 #define	PCIE_AER_UCE_TO			0x4000	/* Completion Timeout Status */
400 #define	PCIE_AER_UCE_CA			0x8000	/* Completer Abort Status */
401 #define	PCIE_AER_UCE_UC			0x10000	/* Unexpected Completion Sts */
402 #define	PCIE_AER_UCE_RO			0x20000	/* Receiver Overflow Status */
403 #define	PCIE_AER_UCE_MTLP		0x40000	/* Malformed TLP Status */
404 #define	PCIE_AER_UCE_ECRC		0x80000	/* ECRC Error Status */
405 #define	PCIE_AER_UCE_UR		0x100000	/* Unsupported Req */
406 #define	PCIE_AER_UCE_BITS		(PCIE_AER_UCE_TRAINING | \
407     PCIE_AER_UCE_DLP | PCIE_AER_UCE_PTLP | PCIE_AER_UCE_FCP | \
408     PCIE_AER_UCE_TO | PCIE_AER_UCE_CA | PCIE_AER_UCE_UC | PCIE_AER_UCE_RO | \
409     PCIE_AER_UCE_MTLP | PCIE_AER_UCE_ECRC | PCIE_AER_UCE_UR)
410 
411 /*
412  * AER Correctable Error Status/Mask Register
413  */
414 #define	PCIE_AER_CE_RECEIVER_ERR	0x1	/* Receiver Error Status */
415 #define	PCIE_AER_CE_BAD_TLP		0x40	/* Bad TLP Status */
416 #define	PCIE_AER_CE_BAD_DLLP		0x80	/* Bad DLLP Status */
417 #define	PCIE_AER_CE_REPLAY_ROLLOVER	0x100	/* REPLAY_NUM Rollover Status */
418 #define	PCIE_AER_CE_REPLAY_TO		0x1000	/* Replay Timer Timeout Sts */
419 #define	PCIE_AER_CE_BITS		(PCIE_AER_CE_RECEIVER_ERR | \
420     PCIE_AER_CE_BAD_TLP | PCIE_AER_CE_BAD_DLLP | PCIE_AER_CE_REPLAY_ROLLOVER | \
421     PCIE_AER_CE_REPLAY_TO)
422 
423 /*
424  * AER Capability & Control
425  */
426 #define	PCIE_AER_CTL_FST_ERR_PTR_MASK	0x1F	/* First Error Pointer */
427 #define	PCIE_AER_CTL_ECRC_GEN_CAP	0x20	/* ECRC Generation Capable */
428 #define	PCIE_AER_CTL_ECRC_GEN_ENA	0x40	/* ECRC Generation Enable */
429 #define	PCIE_AER_CTL_ECRC_CHECK_CAP	0x80	/* ECRC Check Capable */
430 #define	PCIE_AER_CTL_ECRC_CHECK_ENA	0x100	/* ECRC Check Enable */
431 
432 /*
433  * AER Root Command Register
434  */
435 #define	PCIE_AER_RE_CMD_CE_REP_EN	0x1	/* Correctable Error Enable */
436 #define	PCIE_AER_RE_CMD_NFE_REP_EN	0x2	/* Non-Fatal Error Enable */
437 #define	PCIE_AER_RE_CMD_FE_REP_EN	0x4	/* Fatal Error Enable */
438 
439 /*
440  * AER Root Error Status Register
441  */
442 #define	PCIE_AER_RE_STS_CE_RCVD		0x1	/* ERR_COR Received */
443 #define	PCIE_AER_RE_STS_MUL_CE_RCVD	0x2	/* Multiple ERR_COR Received */
444 #define	PCIE_AER_RE_STS_FE_NFE_RCVD	0x4	/* FATAL/NON-FATAL Received */
445 #define	PCIE_AER_RE_STS_MUL_FE_NFE_RCVD	0x8	/* Multiple ERR_F/NF Received */
446 #define	PCIE_AER_RE_STS_FIRST_UC_FATAL	0x10	/* First Uncorrectable Fatal */
447 #define	PCIE_AER_RE_STS_NFE_MSGS_RCVD	0x20	/* Non-Fatal Error Msgs Rcvd */
448 #define	PCIE_AER_RE_STS_FE_MSGS_RCVD	0x40	/* Fatal Error Messages Rcvd */
449 
450 #define	PCIE_AER_RE_STS_MSG_NUM_SHIFT	27	/* Offset of Intr Msg Number */
451 #define	PCIE_AER_RE_STS_MSG_NUM_MASK	0x1F	/* Intr Msg Number Mask */
452 
453 /*
454  * AER Error Source Identification Register
455  */
456 #define	PCIE_AER_ERR_SRC_ID_CE_SHIFT	0	/* ERR_COR Source ID */
457 #define	PCIE_AER_ERR_SRC_ID_CE_MASK	0xFFFF
458 #define	PCIE_AER_ERR_SRC_ID_UE_SHIFT	16	/* ERR_FATAL/NONFATAL Src ID */
459 #define	PCIE_AER_ERR_SRC_ID_UE_MASK	0xFFF
460 
461 /*
462  * AER Secondary Uncorrectable Error Register
463  */
464 #define	PCIE_AER_SUCE_TA_ON_SC		0x1	/* Target Abort on Split Comp */
465 #define	PCIE_AER_SUCE_MA_ON_SC 		0x2	/* Master Abort on Split Comp */
466 #define	PCIE_AER_SUCE_RCVD_TA		0x4	/* Received Target Abort */
467 #define	PCIE_AER_SUCE_RCVD_MA 		0x8	/* Received Master Abort */
468 #define	PCIE_AER_SUCE_USC_ERR 		0x20	/* Unexpected Split Comp Err */
469 #define	PCIE_AER_SUCE_USC_MSG_DATA_ERR	0x40	/* USC Message Data Error */
470 #define	PCIE_AER_SUCE_UC_DATA_ERR	0x80	/* Uncorrectable Data Error */
471 #define	PCIE_AER_SUCE_UC_ATTR_ERR	0x100	/* UC Attribute Err */
472 #define	PCIE_AER_SUCE_UC_ADDR_ERR	0x200	/* Uncorrectable Address Err */
473 #define	PCIE_AER_SUCE_TIMER_EXPIRED	0x400	/* Delayed xtion discard */
474 #define	PCIE_AER_SUCE_PERR_ASSERT	0x800	/* PERR Assertion Detected */
475 #define	PCIE_AER_SUCE_SERR_ASSERT	0x1000	/* SERR Assertion Detected */
476 #define	PCIE_AER_SUCE_INTERNAL_ERR	0x2000	/* Internal Bridge Err Detect */
477 #define	PCIE_AER_SUCE_BITS		(PCIE_AER_SUCE_TA_ON_SC | \
478     PCIE_AER_SUCE_MA_ON_SC | PCIE_AER_SUCE_RCVD_TA | PCIE_AER_SUCE_RCVD_MA | \
479     PCIE_AER_SUCE_USC_ERR | PCIE_AER_SUCE_USC_MSG_DATA_ERR | \
480     PCIE_AER_SUCE_UC_DATA_ERR | PCIE_AER_SUCE_UC_ATTR_ERR | \
481     PCIE_AER_SUCE_UC_ADDR_ERR |	PCIE_AER_SUCE_TIMER_EXPIRED | \
482     PCIE_AER_SUCE_PERR_ASSERT |	PCIE_AER_SUCE_SERR_ASSERT | \
483     PCIE_AER_SUCE_INTERNAL_ERR)
484 
485 /*
486  * AER Secondary Capability & Control
487  */
488 #define	PCIE_AER_SCTL_FST_ERR_PTR_MASK	0x1F	/* First Error Pointer */
489 
490 /*
491  * AER Secondary Headers
492  * The Secondary Header Logs is 4 DW long.
493  * The first 2 DW are split into 3 sections
494  * o Transaction Attribute
495  * o Transaction Command Lower
496  * o Transaction Command Higher
497  * The last 2 DW is the Transaction Address
498  */
499 #define	PCIE_AER_SHDR_LOG_ATTR_MASK	0xFFFFFFFFF
500 #define	PCIE_AER_SHDR_LOG_CMD_LOW_MASK	0xF000000000
501 #define	PCIE_AER_SHDR_LOG_CMD_HIGH_MASK	0xF0000000000
502 #define	PCIE_AER_SHDR_LOG_ADDR_MASK	0xFFFFFFFFFFFFFFFF
503 
504 /*
505  * PCI-E Common TLP Header Fields
506  */
507 #define	PCIE_TLP_FMT_3DW 	0x00
508 #define	PCIE_TLP_FMT_4DW	0x20
509 #define	PCIE_TLP_FMT_3DW_DATA	0x40
510 #define	PCIE_TLP_FMT_4DW_DATA	0x60
511 
512 #define	PCIE_TLP_TYPE_MEM	0x0
513 #define	PCIE_TLP_TYPE_MEMLK	0x1
514 #define	PCIE_TLP_TYPE_IO 	0x2
515 #define	PCIE_TLP_TYPE_CFG0	0x4
516 #define	PCIE_TLP_TYPE_CFG1	0x5
517 #define	PCIE_TLP_TYPE_MSG 	0x10
518 #define	PCIE_TLP_TYPE_CPL	0xA
519 #define	PCIE_TLP_TYPE_CPLLK	0xB
520 #define	PCIE_TLP_TYPE_MSI	0x18
521 
522 #define	PCIE_TLP_MRD3		(PCIE_TLP_FMT_3DW | PCIE_TLP_TYPE_MEM)
523 #define	PCIE_TLP_MRD4		(PCIE_TLP_FMT_4DW | PCIE_TLP_TYPE_MEM)
524 #define	PCIE_TLP_MRDLK3		(PCIE_TLP_FMT_3DW | PCIE_TLP_TYPE_MEMLK)
525 #define	PCIE_TLP_MRDLK4		(PCIE_TLP_FMT_4DW | PCIE_TLP_TYPE_MEMLK)
526 #define	PCIE_TLP_MRDWR3		(PCIE_TLP_FMT_3DW_DATA | PCIE_TLP_TYPE_MEM)
527 #define	PCIE_TLP_MRDWR4		(PCIE_TLP_FMT_4DW_DATA | PCIE_TLP_TYPE_MEM)
528 #define	PCIE_TLP_IORD 		(PCIE_TLP_FMT_3DW | PCIE_TLP_TYPE_IO)
529 #define	PCIE_TLP_IOWR 		(PCIE_TLP_FMT_3DW_DATA | PCIE_TLP_TYPE_IO)
530 #define	PCIE_TLP_CFGRD0		(PCIE_TLP_FMT_3DW | PCIE_TLP_TYPE_CFG0)
531 #define	PCIE_TLP_CFGWR0		(PCIE_TLP_FMT_3DW_DATA | PCIE_TLP_TYPE_CFG0)
532 #define	PCIE_TLP_CFGRD1		(PCIE_TLP_FMT_3DW | PCIE_TLP_TYPE_CFG1)
533 #define	PCIE_TLP_CFGWR1		(PCIE_TLP_FMT_3DW_DATA | PCIE_TLP_TYPE_CFG1)
534 #define	PCIE_TLP_MSG 		(PCIE_TLP_FMT_4DW | PCIE_TLP_TYPE_MSG)
535 #define	PCIE_TLP_MSGD 		(PCIE_TLP_FMT_4DW_DATA | PCIE_TLP_TYPE_MSG)
536 #define	PCIE_TLP_CPL		(PCIE_TLP_FMT_3DW | PCIE_TLP_TYPE_CPL)
537 #define	PCIE_TLP_CPLD		(PCIE_TLP_FMT_3DW_DATA | PCIE_TLP_TYPE_CPL)
538 #define	PCIE_TLP_CPLLK		(PCIE_TLP_FMT_3DW | PCIE_TLP_TYPE_CPLLK)
539 #define	PCIE_TLP_CPLDLK		(PCIE_TLP_FMT_3DW_DATA | PCIE_TLP_TYPE_CPLLK)
540 #define	PCIE_TLP_MSI32		(PCIE_TLP_FMT_3DW_DATA | PCIE_TLP_TYPE_MSI)
541 #define	PCIE_TLP_MSI64		(PCIE_TLP_FMT_4DW_DATA | PCIE_TLP_TYPE_MSI)
542 
543 typedef uint16_t pcie_req_id_t;
544 
545 #define	PCIE_REQ_ID_BUS_SHIFT	8
546 #define	PCIE_REQ_ID_BUS_MASK	0xFF00
547 #define	PCIE_REQ_ID_DEV_SHIFT	3
548 #define	PCIE_REQ_ID_DEV_MASK	0x00F1
549 #define	PCIE_REQ_ID_FUNC_SHIFT	0
550 #define	PCIE_REQ_ID_FUNC_MASK	0x0007
551 
552 /*
553  * PCI-Express Message Request Header
554  */
555 typedef struct pcie_msg {
556 	uint32_t	rsvd1	:16,	/* DW0 */
557 			td	:1,
558 			ep	:1,
559 			attr	:2,
560 			rsvd2	:2,
561 			len	:10;
562 	uint32_t	rid	:16,	/* DW1 */
563 			tag	:8,
564 			msg_code:8;
565 	uint32_t	unused[2];	/* DW 2 & 3 */
566 } pcie_msg_t;
567 
568 #define	PCIE_MSG_CODE_ERR_COR		0x30
569 #define	PCIE_MSG_CODE_ERR_NONFATAL	0x31
570 #define	PCIE_MSG_CODE_ERR_FATAL		0x33
571 
572 /*
573  * Exported PCI-express property names
574  */
575 #define	SAVED_PCIEX_CAP_REG	"pciex-cap-reg"
576 #define	SAVED_PCIEX_SLOTCAP_REG	"pciex-slotcap-reg"
577 
578 #ifdef	__cplusplus
579 }
580 #endif
581 
582 #endif	/* _SYS_PCIE_H */
583