xref: /illumos-gate/usr/src/uts/common/sys/pcie.h (revision 772eca3305893e0fc7b9c13ec6a1a6df72251dbd)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 /*
26  * Copyright 2019 Joyent, Inc.
27  * Copyright 2021 Oxide Computer Company
28  */
29 
30 #ifndef	_SYS_PCIE_H
31 #define	_SYS_PCIE_H
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 #include <sys/pci.h>
38 
39 /*
40  * PCI Express capability registers in PCI configuration space relative to
41  * the PCI Express Capability structure.
42  */
43 #define	PCIE_CAP_ID			PCI_CAP_ID
44 #define	PCIE_CAP_NEXT_PTR		PCI_CAP_NEXT_PTR
45 #define	PCIE_PCIECAP			0x02	/* PCI-e Capability Reg */
46 #define	PCIE_DEVCAP			0x04	/* Device Capability */
47 #define	PCIE_DEVCTL			0x08	/* Device Control */
48 #define	PCIE_DEVSTS			0x0A	/* Device Status */
49 #define	PCIE_LINKCAP			0x0C	/* Link Capability */
50 #define	PCIE_LINKCTL			0x10	/* Link Control */
51 #define	PCIE_LINKSTS			0x12	/* Link Status */
52 #define	PCIE_SLOTCAP			0x14	/* Slot Capability */
53 #define	PCIE_SLOTCTL			0x18	/* Slot Control */
54 #define	PCIE_SLOTSTS			0x1A	/* Slot Status */
55 #define	PCIE_ROOTCTL			0x1C	/* Root Control */
56 #define	PCIE_ROOTCAP			0x1E	/* Root Capabilities */
57 #define	PCIE_ROOTSTS			0x20	/* Root Status */
58 #define	PCIE_DEVCAP2			0x24	/* Device Capability 2 */
59 #define	PCIE_DEVCTL2			0x28	/* Device Control 2 */
60 #define	PCIE_DEVSTS2			0x2A	/* Device Status 2 */
61 #define	PCIE_LINKCAP2			0x2C	/* Link Capability 2 */
62 #define	PCIE_LINKCTL2			0x30	/* Link Control 2 */
63 #define	PCIE_LINKSTS2			0x32	/* Link Status 2 */
64 #define	PCIE_SLOTCAP2			0x34	/* Slot Capability 2 */
65 #define	PCIE_SLOTCTL2			0x38	/* Slot Control 2 */
66 #define	PCIE_SLOTSTS2			0x3A	/* Slot Status 2 */
67 
68 /*
69  * PCI-Express Config Space size
70  */
71 #define	PCIE_CONF_HDR_SIZE	4096	/* PCIe configuration header size */
72 
73 /*
74  * PCI-Express Capabilities Register (2 bytes)
75  */
76 #define	PCIE_PCIECAP_VER_1_0		0x1	/* PCI-E spec 1.0 */
77 #define	PCIE_PCIECAP_VER_2_0		0x2	/* PCI-E spec 2.0 */
78 #define	PCIE_PCIECAP_VER_MASK		0xF	/* Version Mask */
79 #define	PCIE_PCIECAP_DEV_TYPE_PCIE_DEV	0x00	/* PCI-E Endpont Device */
80 #define	PCIE_PCIECAP_DEV_TYPE_PCI_DEV	0x10	/* "Leg PCI" Endpont Device */
81 #define	PCIE_PCIECAP_DEV_TYPE_ROOT	0x40	/* Root Port of Root Complex */
82 #define	PCIE_PCIECAP_DEV_TYPE_UP	0x50	/* Upstream Port of Switch */
83 #define	PCIE_PCIECAP_DEV_TYPE_DOWN	0x60	/* Downstream Port of Switch */
84 #define	PCIE_PCIECAP_DEV_TYPE_PCIE2PCI	0x70	/* PCI-E to PCI Bridge */
85 #define	PCIE_PCIECAP_DEV_TYPE_PCI2PCIE	0x80	/* PCI to PCI-E Bridge */
86 #define	PCIE_PCIECAP_DEV_TYPE_RC_IEP	0x90	/* RootComplex Integrated Dev */
87 #define	PCIE_PCIECAP_DEV_TYPE_RC_EC	0xA0	/* RootComplex Evt Collector */
88 #define	PCIE_PCIECAP_DEV_TYPE_MASK	0xF0	/* Device/Port Type Mask */
89 #define	PCIE_PCIECAP_SLOT_IMPL		0x100	/* Slot Impl vs Integrated */
90 #define	PCIE_PCIECAP_INT_MSG_NUM	0x3E00	/* Interrupt Message Number */
91 
92 /*
93  * Device Capabilities Register (4 bytes)
94  */
95 #define	PCIE_DEVCAP_MAX_PAYLOAD_128	0x0
96 #define	PCIE_DEVCAP_MAX_PAYLOAD_256	0x1
97 #define	PCIE_DEVCAP_MAX_PAYLOAD_512	0x2
98 #define	PCIE_DEVCAP_MAX_PAYLOAD_1024	0x3
99 #define	PCIE_DEVCAP_MAX_PAYLOAD_2048	0x4
100 #define	PCIE_DEVCAP_MAX_PAYLOAD_4096	0x5
101 #define	PCIE_DEVCAP_MAX_PAYLOAD_MASK	0x7	/* Max Payload Size Supported */
102 
103 #define	PCIE_DEVCAP_PHTM_FUNC_NONE	0x00	/* No Function # bits used */
104 #define	PCIE_DEVCAP_PHTM_FUNC_ONE	0x08	/* First most sig. bit used */
105 #define	PCIE_DEVCAP_PHTM_FUNC_TWO	0x10	/* First 2 most sig bit used */
106 #define	PCIE_DEVCAP_PHTM_FUNC_THREE	0x18	/* All 3 bits used */
107 #define	PCIE_DEVCAP_PHTM_FUNC_MASK	0x18	/* Phantom Func Supported */
108 
109 #define	PCIE_DEVCAP_EXT_TAG_5BIT	0x00	/* 5-Bit Tag Field Supported */
110 #define	PCIE_DEVCAP_EXT_TAG_8BIT	0x20	/* 8-Bit Tag Field Supported */
111 #define	PCIE_DEVCAP_EXT_TAG_MASK	0x20	/* Ext. Tag Field Supported */
112 
113 #define	PCIE_DEVCAP_EP_L0S_LAT_MIN	0x000	/* < 64 ns */
114 #define	PCIE_DEVCAP_EP_L0S_LAT_64ns	0x040	/* 64 ns - 128 ns */
115 #define	PCIE_DEVCAP_EP_L0S_LAT_128ns	0x080	/* 128 ns - 256 ns */
116 #define	PCIE_DEVCAP_EP_L0S_LAT_256ns	0x0C0	/* 256 ns - 512 ns */
117 #define	PCIE_DEVCAP_EP_L0S_LAT_512ns	0x100	/* 512 ns - 1 us */
118 #define	PCIE_DEVCAP_EP_L0S_LAT_1us	0x140	/* 1 us - 2 us */
119 #define	PCIE_DEVCAP_EP_L0S_LAT_2us	0x180	/* 2 us - 4 us */
120 #define	PCIE_DEVCAP_EP_L0S_LAT_MAX	0x1C0	/* > 4 us */
121 #define	PCIE_DEVCAP_EP_L0S_LAT_MASK	0x1C0	/* EP L0s Accetable Latency */
122 
123 #define	PCIE_DEVCAP_EP_L1_LAT_MIN	0x000	/* < 1 us */
124 #define	PCIE_DEVCAP_EP_L1_LAT_1us	0x140	/* 1 us - 2 us */
125 #define	PCIE_DEVCAP_EP_L1_LAT_2us	0x180	/* 2 us - 4 us */
126 #define	PCIE_DEVCAP_EP_L1_LAT_4us	0x140	/* 4 us - 8 us */
127 #define	PCIE_DEVCAP_EP_L1_LAT_8us	0x180	/* 8 us - 16 us */
128 #define	PCIE_DEVCAP_EP_L1_LAT_16us	0x140	/* 16 us - 32 us */
129 #define	PCIE_DEVCAP_EP_L1_LAT_32us	0x180	/* 32 us - 64 us */
130 #define	PCIE_DEVCAP_EP_L1_LAT_MAX	0x1C0	/* > 64 us */
131 #define	PCIE_DEVCAP_EP_L1_LAT_MASK	0x700	/* EP L1 Accetable Latency */
132 
133 /*
134  * As of PCIe 2.x these three bits are now undefined.
135  */
136 #define	PCIE_DEVCAP_ATTN_BUTTON		0x1000	/* Attention Button Present */
137 #define	PCIE_DEVCAP_ATTN_INDICATOR	0x2000	/* Attn Indicator Present */
138 #define	PCIE_DEVCAP_PWR_INDICATOR	0x4000	/* Power Indicator Present */
139 
140 #define	PCIE_DEVCAP_ROLE_BASED_ERR_REP	0x8000	/* Role Based Error Reporting */
141 
142 #define	PCIE_DEVCAP_PLMT_VAL_SHIFT	18	/* Power Limit Value Shift */
143 #define	PCIE_DEVCAP_PLMT_VAL_MASK	0xFF	/* Power Limit Value Mask */
144 
145 #define	PCIE_DEVCAP_PLMT_SCL_1_BY_1	0x0000000	/* 1x Scale */
146 #define	PCIE_DEVCAP_PLMT_SCL_1_BY_10	0x4000000	/* 0.1x Scale */
147 #define	PCIE_DEVCAP_PLMT_SCL_1_BY_100	0x8000000	/* 0.01x Scale */
148 #define	PCIE_DEVCAP_PLMT_SCL_1_BY_1000	0xC000000	/* 0.001x Scale */
149 #define	PCIE_DEVCAP_PLMT_SCL_MASK	0xC000000	/* Power Limit Scale */
150 
151 #define	PCIE_DEVCAP_FLR			0x10000000 /* Function Level Reset */
152 
153 /*
154  * Device Control Register (2 bytes)
155  */
156 #define	PCIE_DEVCTL_CE_REPORTING_EN	0x1	/* Correctable Error Enable */
157 #define	PCIE_DEVCTL_NFE_REPORTING_EN	0x2	/* Non-Fatal Error Enable */
158 #define	PCIE_DEVCTL_FE_REPORTING_EN	0x4	/* Fatal Error Enable */
159 #define	PCIE_DEVCTL_UR_REPORTING_EN	0x8	/* Unsupported Request Enable */
160 #define	PCIE_DEVCTL_ERR_MASK		0xF	/* All of the above bits */
161 
162 #define	PCIE_DEVCTL_RO_EN		0x10	/* Enable Relaxed Ordering */
163 
164 #define	PCIE_DEVCTL_MAX_PAYLOAD_128	0x00
165 #define	PCIE_DEVCTL_MAX_PAYLOAD_256	0x20
166 #define	PCIE_DEVCTL_MAX_PAYLOAD_512	0x40
167 #define	PCIE_DEVCTL_MAX_PAYLOAD_1024	0x60
168 #define	PCIE_DEVCTL_MAX_PAYLOAD_2048	0x80
169 #define	PCIE_DEVCTL_MAX_PAYLOAD_4096	0xA0
170 #define	PCIE_DEVCTL_MAX_PAYLOAD_MASK	0xE0	/* Max_Payload_Size */
171 #define	PCIE_DEVCTL_MAX_PAYLOAD_SHIFT	0x5
172 
173 #define	PCIE_DEVCTL_EXT_TAG_FIELD_EN	0x100	/* Extended Tag Field Enable */
174 #define	PCIE_DEVCTL_PHTM_FUNC_EN	0x200	/* Phantom Functions Enable */
175 #define	PCIE_DEVCTL_AUX_POWER_PM_EN	0x400	/* Auxiliary Power PM Enable */
176 #define	PCIE_DEVCTL_ENABLE_NO_SNOOP	0x800	/* Enable No Snoop */
177 
178 #define	PCIE_DEVCTL_MAX_READ_REQ_128	0x0000
179 #define	PCIE_DEVCTL_MAX_READ_REQ_256	0x1000
180 #define	PCIE_DEVCTL_MAX_READ_REQ_512	0x2000
181 #define	PCIE_DEVCTL_MAX_READ_REQ_1024	0x3000
182 #define	PCIE_DEVCTL_MAX_READ_REQ_2048	0x4000
183 #define	PCIE_DEVCTL_MAX_READ_REQ_4096	0x5000
184 #define	PCIE_DEVCTL_MAX_READ_REQ_MASK	0x7000	/* Max_Read_Request_Size */
185 #define	PCIE_DEVCTL_MAX_READ_REQ_SHIFT	0xC
186 
187 #define	PCIE_DEVCTL_BRIDGE_RETRY	0x8000	/* Bridge can return CRS */
188 #define	PCIE_DEVCTL_INITIATE_FLR	0x8000	/* Start Function Level Reset */
189 
190 /*
191  * Device Status Register (2 bytes)
192  */
193 #define	PCIE_DEVSTS_CE_DETECTED		0x1	/* Correctable Error Detected */
194 #define	PCIE_DEVSTS_NFE_DETECTED	0x2	/* Non Fatal Error Detected */
195 #define	PCIE_DEVSTS_FE_DETECTED		0x4	/* Fatal Error Detected */
196 #define	PCIE_DEVSTS_UR_DETECTED		0x8	/* Unsupported Req Detected */
197 #define	PCIE_DEVSTS_AUX_POWER		0x10	/* AUX Power Detected */
198 #define	PCIE_DEVSTS_TRANS_PENDING	0x20	/* Transactions Pending */
199 #define	PCIE_DEVSTS_EPR_DETECTED	0x40	/* Emergency Power Reduction */
200 
201 /*
202  * Link Capability Register (4 bytes)
203  */
204 #define	PCIE_LINKCAP_MAX_SPEED_2_5	0x1	/* 2.5 GT/s Speed */
205 /*
206  * In version 2 of PCI express, this indicated that both 5.0 GT/s and 2.5 GT/s
207  * speeds were supported. The use of this as the maximum link speed was added
208  * with PCIex v3.
209  */
210 #define	PCIE_LINKCAP_MAX_SPEED_5	0x2	/* 5.0 GT/s Speed */
211 #define	PCIE_LINKCAP_MAX_SPEED_8	0x3	/* 8.0 GT/s Speed */
212 #define	PCIE_LINKCAP_MAX_SPEED_16	0x4	/* 16.0 GT/s Speed */
213 #define	PCIE_LINKCAP_MAX_SPEED_MASK	0xF	/* Maximum Link Speed */
214 #define	PCIE_LINKCAP_MAX_WIDTH_X1	0x010
215 #define	PCIE_LINKCAP_MAX_WIDTH_X2	0x020
216 #define	PCIE_LINKCAP_MAX_WIDTH_X4	0x040
217 #define	PCIE_LINKCAP_MAX_WIDTH_X8	0x080
218 #define	PCIE_LINKCAP_MAX_WIDTH_X12	0x0C0
219 #define	PCIE_LINKCAP_MAX_WIDTH_X16	0x100
220 #define	PCIE_LINKCAP_MAX_WIDTH_X32	0x200
221 #define	PCIE_LINKCAP_MAX_WIDTH_MASK	0x3f0	/* Maximum Link Width */
222 
223 #define	PCIE_LINKCAP_ASPM_SUP_L0S	0x400	/* L0s Entry Supported */
224 #define	PCIE_LINKCAP_ASPM_SUP_L1	0x800	/* L1 Entry Supported */
225 #define	PCIE_LINKCAP_ASPM_SUP_L0S_L1	0xC00	/* L0s abd L1 Supported */
226 #define	PCIE_LINKCAP_ASPM_SUP_MASK	0xC00	/* ASPM Support */
227 
228 #define	PCIE_LINKCAP_L0S_EXIT_LAT_MIN	0x0000	/* < 64 ns */
229 #define	PCIE_LINKCAP_L0S_EXIT_LAT_64ns	0x1000	/* 64 ns - 128 ns */
230 #define	PCIE_LINKCAP_L0S_EXIT_LAT_128ns	0x2000	/* 128 ns - 256 ns */
231 #define	PCIE_LINKCAP_L0S_EXIT_LAT_256ns	0x3000	/* 256 ns - 512 ns */
232 #define	PCIE_LINKCAP_L0S_EXIT_LAT_512ns	0x4000	/* 512 ns - 1 us */
233 #define	PCIE_LINKCAP_L0S_EXIT_LAT_1us	0x5000	/* 1 us - 2 us */
234 #define	PCIE_LINKCAP_L0S_EXIT_LAT_2us	0x6000	/* 2 us - 4 us */
235 #define	PCIE_LINKCAP_L0S_EXIT_LAT_MAX	0x7000	/* > 4 us */
236 #define	PCIE_LINKCAP_L0S_EXIT_LAT_MASK	0x7000	/* L0s Exit Latency */
237 
238 #define	PCIE_LINKCAP_L1_EXIT_LAT_MIN	0x00000	/* < 1 us */
239 #define	PCIE_LINKCAP_L1_EXIT_LAT_1us	0x08000	/* 1 us - 2 us */
240 #define	PCIE_LINKCAP_L1_EXIT_LAT_2us	0x10000	/* 2 us - 4 us */
241 #define	PCIE_LINKCAP_L1_EXIT_LAT_4us	0x18000	/* 4 us - 8 us */
242 #define	PCIE_LINKCAP_L1_EXIT_LAT_8us	0x20000	/* 8 us - 16 us */
243 #define	PCIE_LINKCAP_L1_EXIT_LAT_16us	0x28000	/* 16 us - 32 us */
244 #define	PCIE_LINKCAP_L1_EXIT_LAT_32us	0x30000	/* 32 us - 64 us */
245 #define	PCIE_LINKCAP_L1_EXIT_LAT_MAX	0x38000	/* > 64 us */
246 #define	PCIE_LINKCAP_L1_EXIT_LAT_MASK	0x38000	/* L1 Exit Latency */
247 
248 #define	PCIE_LINKCAP_CLOCK_POWER_MGMT	0x40000	/* Clock Power Management */
249 #define	PCIE_LINKCAP_SDER_CAP		0x80000 /* Surprise Down Err report */
250 #define	PCIE_LINKCAP_DLL_ACTIVE_REP_CAPABLE	0x100000    /* DLL Active */
251 							    /* Capable bit */
252 #define	PCIE_LINKCAP_LINK_BW_NOTIFY_CAP	0x200000 /* Link Bandwidth Notify Cap */
253 #define	PCIE_LINKCAP_ASPM_OPTIONAL	0x400000 /* ASPM Opt. Comp. */
254 
255 #define	PCIE_LINKCAP_PORT_NUMBER	0xFF000000	/* Port Number */
256 #define	PCIE_LINKCAP_PORT_NUMBER_SHIFT	24	/* Port Number Shift */
257 #define	PCIE_LINKCAP_PORT_NUMBER_MASK	0xFF	/* Port Number Mask */
258 
259 /*
260  * Link Control Register (2 bytes)
261  */
262 #define	PCIE_LINKCTL_ASPM_CTL_DIS	0x0	/* ASPM Disable */
263 #define	PCIE_LINKCTL_ASPM_CTL_L0S	0x1	/* ASPM L0s only */
264 #define	PCIE_LINKCTL_ASPM_CTL_L1	0x2	/* ASPM L1 only */
265 #define	PCIE_LINKCTL_ASPM_CTL_L0S_L1	0x3	/* ASPM L0s and L1 only */
266 #define	PCIE_LINKCTL_ASPM_CTL_MASK	0x3	/* ASPM Control */
267 
268 #define	PCIE_LINKCTL_RCB_64_BYTE	0x0	/* 64 Byte */
269 #define	PCIE_LINKCTL_RCB_128_BYTE	0x8	/* 128 Byte */
270 #define	PCIE_LINKCTL_RCB_MASK		0x8	/* Read Completion Boundary */
271 
272 #define	PCIE_LINKCTL_LINK_DISABLE	0x10	/* Link Disable */
273 #define	PCIE_LINKCTL_RETRAIN_LINK	0x20	/* Retrain Link */
274 #define	PCIE_LINKCTL_COMMON_CLK_CFG	0x40	/* Common Clock Configuration */
275 #define	PCIE_LINKCTL_EXT_SYNCH		0x80	/* Extended Synch */
276 #define	PCIE_LINKCTL_CLOCK_POWER_MGMT	0x100	/* Enable Clock Power Mgmt. */
277 #define	PCIE_LINKCTL_HW_WIDTH_DISABLE	0x200	/* hw auto width disable */
278 #define	PCIE_LINKCTL_LINK_BW_INTR_EN	0x400	/* Link bw mgmt intr */
279 #define	PCIE_LINKCTL_LINK_AUTO_BW_INTR_EN	0x800	/* Auto bw intr */
280 
281 #define	PCI_LINKCTRL_DRS_SIG_CTRL_NO_REP	0x00
282 #define	PCI_LINKCTRL_DRS_SIG_CTRL_IE		0x4000
283 #define	PCI_LINKCTRL_DRS_SIG_CTRL_DRS_FRS	0x8000
284 #define	PCIE_LINKCTL_DRS_SIG_CTRL_MASK	0xC000	/* DRS Signaling Control */
285 
286 /*
287  * Link Status Register (2 bytes)
288  */
289 #define	PCIE_LINKSTS_SPEED_2_5		0x1	/* 2.5 GT/s Link Speed */
290 #define	PCIE_LINKSTS_SPEED_5		0x2	/* 5.0 GT/s Link Speed */
291 #define	PCIE_LINKSTS_SPEED_8		0x3	/* 8.0 GT/s Link Speed */
292 #define	PCIE_LINKSTS_SPEED_16		0x4	/* 16.0 GT/s Link Speed */
293 #define	PCIE_LINKSTS_SPEED_MASK		0xF	/* Link Speed */
294 
295 #define	PCIE_LINKSTS_NEG_WIDTH_X1	0x010
296 #define	PCIE_LINKSTS_NEG_WIDTH_X2	0x020
297 #define	PCIE_LINKSTS_NEG_WIDTH_X4	0x040
298 #define	PCIE_LINKSTS_NEG_WIDTH_X8	0x080
299 #define	PCIE_LINKSTS_NEG_WIDTH_X12	0x0C0
300 #define	PCIE_LINKSTS_NEG_WIDTH_X16	0x100
301 #define	PCIE_LINKSTS_NEG_WIDTH_X32	0x200
302 #define	PCIE_LINKSTS_NEG_WIDTH_MASK	0x3F0	/* Negotiated Link Width */
303 
304 /* This bit is undefined as of PCIe 2.x */
305 #define	PCIE_LINKSTS_TRAINING_ERROR	0x400	/* Training Error */
306 #define	PCIE_LINKSTS_LINK_TRAINING	0x800	/* Link Training */
307 #define	PCIE_LINKSTS_SLOT_CLK_CFG	0x1000	/* Slot Clock Configuration */
308 #define	PCIE_LINKSTS_DLL_LINK_ACTIVE	0x2000	/* DLL Link Active */
309 #define	PCIE_LINKSTS_LINK_BW_MGMT	0x4000	/* Link bw mgmt status */
310 #define	PCIE_LINKSTS_AUTO_BW		0x8000	/* Link auto BW status */
311 
312 /*
313  * Slot Capability Register (4 bytes)
314  */
315 #define	PCIE_SLOTCAP_ATTN_BUTTON	0x1	/* Attention Button Present */
316 #define	PCIE_SLOTCAP_POWER_CONTROLLER	0x2	/* Power Controller Present */
317 #define	PCIE_SLOTCAP_MRL_SENSOR		0x4	/* MRL Sensor Present */
318 #define	PCIE_SLOTCAP_ATTN_INDICATOR	0x8	/* Attn Indicator Present */
319 #define	PCIE_SLOTCAP_PWR_INDICATOR	0x10	/* Power Indicator Present */
320 #define	PCIE_SLOTCAP_HP_SURPRISE	0x20	/* Hot-Plug Surprise */
321 #define	PCIE_SLOTCAP_HP_CAPABLE		0x40	/* Hot-Plug Capable */
322 
323 #define	PCIE_SLOTCAP_PLMT_VAL_SHIFT	7	/* Slot Pwr Limit Value Shift */
324 #define	PCIE_SLOTCAP_PLMT_VAL_MASK	0xFF	/* Slot Pwr Limit Value */
325 
326 #define	PCIE_SLOTCAP_PLMT_SCL_1_BY_1	0x00000	/* 1x Scale */
327 #define	PCIE_SLOTCAP_PLMT_SCL_1_BY_10	0x08000	/* 0.1x Scale */
328 #define	PCIE_SLOTCAP_PLMT_SCL_1_BY_100	0x10000	/* 0.01x Scale */
329 #define	PCIE_SLOTCAP_PLMT_SCL_1_BY_1000	0x18000	/* 0.001x Scale */
330 #define	PCIE_SLOTCAP_PLMT_SCL_MASK	0x18000	/* Slot Power Limit Scale */
331 #define	PCIE_SLOTCAP_EMI_LOCK_PRESENT	0x20000 /* EMI Lock Present */
332 #define	PCIE_SLOTCAP_NO_CMD_COMP_SUPP	0x40000 /* No Command Comp. Supported */
333 
334 #define	PCIE_SLOTCAP_PHY_SLOT_NUM_SHIFT	19	/* Physical Slot Num Shift */
335 #define	PCIE_SLOTCAP_PHY_SLOT_NUM_MASK	0x1FFF	/* Physical Slot Num Mask */
336 
337 #define	PCIE_SLOTCAP_PHY_SLOT_NUM(reg) \
338 	    (((reg) >> PCIE_SLOTCAP_PHY_SLOT_NUM_SHIFT) & \
339 	    PCIE_SLOTCAP_PHY_SLOT_NUM_MASK)
340 
341 /*
342  * Slot Control Register (2 bytes)
343  */
344 #define	PCIE_SLOTCTL_ATTN_BTN_EN	0x1	/* Attn Button Pressed Enable */
345 #define	PCIE_SLOTCTL_PWR_FAULT_EN	0x2	/* Pwr Fault Detected Enable */
346 #define	PCIE_SLOTCTL_MRL_SENSOR_EN	0x4	/* MRL Sensor Changed Enable */
347 #define	PCIE_SLOTCTL_PRESENCE_CHANGE_EN	0x8	/* Presence Detect Changed En */
348 #define	PCIE_SLOTCTL_CMD_INTR_EN	0x10	/* CMD Completed Interrupt En */
349 #define	PCIE_SLOTCTL_HP_INTR_EN		0x20	/* Hot-Plug Interrupt Enable */
350 #define	PCIE_SLOTCTL_PWR_CONTROL	0x0400	/* Power controller Control */
351 #define	PCIE_SLOTCTL_EMI_LOCK_CONTROL	0x0800	/* EMI Lock control */
352 #define	PCIE_SLOTCTL_DLL_STATE_EN	0x1000	/* DLL State Changed En */
353 #define	PCIE_SLOTCTL_AUTO_SLOT_PL_DIS	0x2000	/* Auto Slot Power Limit Dis */
354 #define	PCIE_SLOTCTL_ATTN_INDICATOR_MASK 0x00C0	/* Attn Indicator mask */
355 #define	PCIE_SLOTCTL_PWR_INDICATOR_MASK	0x0300	/* Power Indicator mask */
356 #define	PCIE_SLOTCTL_INTR_MASK		0x103f	/* Supported intr mask */
357 
358 /* State values for the Power and Attention Indicators */
359 #define	PCIE_SLOTCTL_INDICATOR_STATE_ON		0x1	/* indicator ON */
360 #define	PCIE_SLOTCTL_INDICATOR_STATE_BLINK	0x2	/* indicator BLINK */
361 #define	PCIE_SLOTCTL_INDICATOR_STATE_OFF	0x3	/* indicator OFF */
362 
363 /*
364  * Macros to set/get the state of Power and Attention Indicators
365  * in the PCI Express Slot Control Register.
366  */
367 #define	pcie_slotctl_pwr_indicator_get(reg)	\
368 	(((reg) & PCIE_SLOTCTL_PWR_INDICATOR_MASK) >> 8)
369 #define	pcie_slotctl_attn_indicator_get(ctrl)	\
370 	(((ctrl) & PCIE_SLOTCTL_ATTN_INDICATOR_MASK) >> 6)
371 #define	pcie_slotctl_attn_indicator_set(ctrl, v)\
372 	(((ctrl) & ~PCIE_SLOTCTL_ATTN_INDICATOR_MASK) | ((v) << 6))
373 #define	pcie_slotctl_pwr_indicator_set(ctrl, v)\
374 	(((ctrl) & ~PCIE_SLOTCTL_PWR_INDICATOR_MASK) | ((v) << 8))
375 
376 /*
377  * Slot Status register (2 bytes)
378  */
379 #define	PCIE_SLOTSTS_ATTN_BTN_PRESSED	0x1	/* Attention Button Pressed */
380 #define	PCIE_SLOTSTS_PWR_FAULT_DETECTED	0x2	/* Power Fault Detected */
381 #define	PCIE_SLOTSTS_MRL_SENSOR_CHANGED	0x4	/* MRL Sensor Changed */
382 #define	PCIE_SLOTSTS_PRESENCE_CHANGED	0x8	/* Presence Detect Changed */
383 #define	PCIE_SLOTSTS_COMMAND_COMPLETED	0x10	/* Command Completed */
384 #define	PCIE_SLOTSTS_MRL_SENSOR_OPEN	0x20	/* MRL Sensor Open */
385 #define	PCIE_SLOTSTS_PRESENCE_DETECTED	0x40	/* Card Present in slot */
386 #define	PCIE_SLOTSTS_EMI_LOCK_SET	0x0080	/* EMI Lock set */
387 #define	PCIE_SLOTSTS_DLL_STATE_CHANGED	0x0100	/* DLL State Changed */
388 #define	PCIE_SLOTSTS_STATUS_EVENTS	0x11f	/* Supported events */
389 
390 /*
391  * Root Control Register (2 bytes)
392  */
393 #define	PCIE_ROOTCTL_SYS_ERR_ON_CE_EN	0x1	/* Sys Err on Cor Err Enable */
394 #define	PCIE_ROOTCTL_SYS_ERR_ON_NFE_EN	0x2	/* Sys Err on NF Err Enable */
395 #define	PCIE_ROOTCTL_SYS_ERR_ON_FE_EN	0x4	/* Sys Err on Fatal Err En */
396 #define	PCIE_ROOTCTL_PME_INTERRUPT_EN	0x8	/* PME Interrupt Enable */
397 #define	PCIE_ROOTCTL_CRS_SW_VIS_EN	0x10	/* CRS SW Visibility EN */
398 
399 /*
400  * Root Capabilities register (2 bytes)
401  */
402 #define	PCIE_ROOTCAP_CRS_SW_VIS		0x01	/* CRS SW Visible */
403 
404 /*
405  * Root Status Register (4 bytes)
406  */
407 #define	PCIE_ROOTSTS_PME_REQ_ID_SHIFT	0	/* PME Requestor ID */
408 #define	PCIE_ROOTSTS_PME_REQ_ID_MASK	0xFFFF	/* PME Requestor ID */
409 
410 #define	PCIE_ROOTSTS_PME_STATUS		0x10000	/* PME Status */
411 #define	PCIE_ROOTSTS_PME_PENDING	0x20000	/* PME Pending */
412 
413 /*
414  * Device Capabilities 2 Register (4 bytes)
415  */
416 #define	PCIE_DEVCAP2_COM_TO_RANGE_MASK	0xF
417 #define	PCIE_DEVCAP2_COM_TO_DISABLE	0x10
418 #define	PCIE_DEVCAP2_ARI_FORWARD	0x20
419 #define	PCIE_DEVCAP2_ATOMICOP_ROUTING	0x40
420 #define	PCIE_DEVCAP2_32_ATOMICOP_COMPL  0x80
421 #define	PCIE_DEVCAP2_64_ATOMICOP_COMPL  0x100
422 #define	PCIE_DEVCAP2_128_CAS_COMPL	0x200
423 #define	PCIE_DEVCAP2_NO_RO_PR_PR_PASS	0x400
424 #define	PCIE_DEVCAP2_LTR_MECH		0x800
425 #define	PCIE_DEVCAP2_TPH_COMP_SHIFT	12
426 #define	PCIE_DEVCAP2_TPH_COMP_MASK	0x3
427 #define	PCIE_DEVCAP2_LNSYS_CLS_SHIFT	14
428 #define	PCIE_DEVCAP2_LNSYS_CLS_MASK	0x3
429 #define	PCIE_DEVCAP2_10B_TAG_COMP_SUP	0x10000
430 #define	PCIE_DEVCAP2_10B_TAG_REQ_SUP	0x20000
431 #define	PCIE_DEVCAP2_OBFF_SHIFT		18
432 #define	PCIE_DEVCAP2_OBFF_MASK		0x3
433 #define	PCIE_DEVCAP2_EXT_FMT_FIELD	0x100000
434 #define	PCIE_DEVCAP2_END_END_TLP_PREFIX	0x200000
435 #define	PCIE_DEVCAP2_MAX_END_END_SHIFT	22
436 #define	PCIE_DEVCAP2_MAX_END_END_MASK	0x3
437 #define	PCIE_DEVCAP2_EPR_SUP_SHIFT	24
438 #define	PCIE_DEVCAP2_EPR_SUP_MASK	0x3
439 #define	PCIE_DEVCAP2_EPR_INIT_REQ	0x4000000
440 #define	PCIE_DEVCAP2_FRS_SUP		0x80000000
441 
442 /*
443  * Device Control 2 Register (2 bytes)
444  */
445 #define	PCIE_DEVCTL2_COM_TO_RANGE_MASK	0xf
446 #define	PCIE_DEVCTL2_COM_TO_RANGE_0	0x0
447 #define	PCIE_DEVCTL2_COM_TO_RANGE_1	0x1
448 #define	PCIE_DEVCTL2_COM_TO_RANGE_2	0x2
449 #define	PCIE_DEVCTL2_COM_TO_RANGE_3	0x5
450 #define	PCIE_DEVCTL2_COM_TO_RANGE_4	0x6
451 #define	PCIE_DEVCTL2_COM_TO_RANGE_5	0x9
452 #define	PCIE_DEVCTL2_COM_TO_RANGE_6	0xa
453 #define	PCIE_DEVCTL2_COM_TO_RANGE_7	0xd
454 #define	PCIE_DEVCTL2_COM_TO_RANGE_8	0xe
455 #define	PCIE_DEVCTL2_COM_TO_DISABLE	0x10
456 #define	PCIE_DEVCTL2_ARI_FORWARD_EN	0x20
457 #define	PCIE_DEVCTL2_ATOMICOP_REQ_EN	0x40
458 #define	PCIE_DEVCTL2_ATOMICOP_EGRS_BLK	0x80
459 #define	PCIE_DEVCTL2_IDO_REQ_EN		0x100
460 #define	PCIE_DEVCTL2_IDO_COMPL_EN	0x200
461 #define	PCIE_DEVCTL2_LTR_MECH_EN	0x400
462 #define	PCIE_DEVCTL2_EPR_REQ		0x800
463 #define	PCIE_DEVCTL2_10BTAG_REQ_EN	0x1000
464 #define	PCIE_DEVCTL2_OBFF_MASK		0x6000
465 #define	PCIE_DEVCTL2_OBFF_DISABLE	0x0000
466 #define	PCIE_DEVCTL2_OBFF_EN_VARA	0x2000
467 #define	PCIE_DEVCTL2_OBFF_EN_VARB	0x4000
468 #define	PCIE_DEVCTL2_OBFF_EN_WAKE	0x6000
469 #define	PCIE_DEVCTL2_END_END_TLP_PREFIX	0x8000
470 
471 
472 /*
473  * Link Capability 2 Register (4 bytes)
474  */
475 #define	PCIE_LINKCAP2_SPEED_2_5		0x02
476 #define	PCIE_LINKCAP2_SPEED_5		0x04
477 #define	PCIE_LINKCAP2_SPEED_8		0x08
478 #define	PCIE_LINKCAP2_SPEED_16		0x10
479 #define	PCIE_LINKCAP2_SPEED_MASK	0xfe
480 #define	PCIE_LINKCAP2_CROSSLINK		0x100
481 #define	PCIE_LINKCAP2_LSKP_OSGSS_MASK	0xfe00
482 #define	PCIE_LINKCAP2_LKSP_OSGSS_2_5	0x0200
483 #define	PCIE_LINKCAP2_LKSP_OSGSS_5	0x0400
484 #define	PCIE_LINKCAP2_LKSP_OSGSS_8	0x0800
485 #define	PCIE_LINKCAP2_LKSP_OSGSS_16	0x1000
486 #define	PCIE_LINKCAP2_LKSP_OSRSS_MASK	0x7f0000
487 #define	PCIE_LINKCAP2_LKSP_OSRSS_2_5	0x010000
488 #define	PCIE_LINKCAP2_LKSP_OSRSS_5	0x020000
489 #define	PCIE_LINKCAP2_LKSP_OSRSS_8	0x040000
490 #define	PCIE_LINKCAP2_LKSP_OSRSS_16	0x080000
491 #define	PCIE_LINKCAP2_RTPD_SUP		0x800000
492 #define	PCIE_LINKCAP2_TRTPD_SUP		0x01000000
493 #define	PCIE_LINKCAP2_DRS		0x80000000
494 
495 /*
496  * Link Control 2 Register (2 bytes)
497  */
498 
499 #define	PCIE_LINKCTL2_TARGET_SPEED_2_5	0x1	/* 2.5 GT/s Speed */
500 #define	PCIE_LINKCTL2_TARGET_SPEED_5	0x2	/* 5.0 GT/s Speed */
501 #define	PCIE_LINKCTL2_TARGET_SPEED_8	0x3	/* 8.0 GT/s Speed */
502 #define	PCIE_LINKCTL2_TARGET_SPEED_16	0x4	/* 16.0 GT/s Speed */
503 #define	PCIE_LINKCTL2_TARGET_SPEED_MASK	0x000f
504 #define	PICE_LINKCTL2_ENTER_COMPLIANCE	0x0010
505 #define	PCIE_LINKCTL2_HW_AUTO_SPEED_DIS	0x0020
506 #define	PCIE_LINKCTL2_SELECT_DEEMPH	0x0040
507 #define	PCIE_LINKCTL2_TX_MARGIN_MASK	0x0380
508 #define	PCIE_LINKCTL2_ENTER_MOD_COMP	0x0400
509 #define	PCIE_LINKCTL2_COMP_SOS		0x0800
510 #define	PCIE_LINKCTL2_COMP_DEEMPM_MASK	0xf000
511 
512 /*
513  * Link Status 2 Register (2 bytes)
514  */
515 #define	PCIE_LINKSTS2_CUR_DEEMPH	0x0001
516 #define	PCIE_LINKSTS2_EQ8GT_COMP	0x0002
517 #define	PCIE_LINKSTS2_EQ8GT_P1_SUC	0x0004
518 #define	PCIE_LINKSTS2_EQ8GT_P2_SUC	0x0008
519 #define	PCIE_LINKSTS2_EQ8GT_P3_SUC	0x0010
520 #define	PCIE_LINKSTS2_LINK_EQ_REQ	0x0020
521 #define	PCIE_LINKSTS2_RETIMER_PRES_DET	0x0040
522 #define	PCIE_LINKSTS2_2RETIMER_PRES_DET	0x0080
523 #define	PCIE_LINKSTS2_XLINK_RES		0x0300
524 #define	PCIE_LINKSTS2_DS_COMP_PRES_MASK	0x7000
525 #define	PCIE_LINKSTS2_DRS_MSG_RX	0x8000
526 
527 /*
528  * PCI-Express Enhanced Capabilities Link Entry Bit Offsets
529  */
530 #define	PCIE_EXT_CAP			0x100	/* Base Address of Ext Cap */
531 
532 #define	PCIE_EXT_CAP_ID_SHIFT		0	/* PCI-e Ext Cap ID */
533 #define	PCIE_EXT_CAP_ID_MASK		0xFFFF
534 #define	PCIE_EXT_CAP_VER_SHIFT		16	/* PCI-e Ext Cap Ver */
535 #define	PCIE_EXT_CAP_VER_MASK		0xF
536 #define	PCIE_EXT_CAP_NEXT_PTR_SHIFT	20	/* PCI-e Ext Cap Next Ptr */
537 #define	PCIE_EXT_CAP_NEXT_PTR_MASK	0xFFF
538 
539 #define	PCIE_EXT_CAP_NEXT_PTR_NULL	0x0
540 #define	PCIE_EXT_CAP_MAX_PTR		0x3c0	/* max. number of caps */
541 
542 /*
543  * PCI-Express Enhanced Capability Identifier Values
544  */
545 #define	PCIE_EXT_CAP_ID_AER		0x1	/* Advanced Error Handling */
546 #define	PCIE_EXT_CAP_ID_VC		0x2	/* Virtual Channel, no MFVC */
547 #define	PCIE_EXT_CAP_ID_SER		0x3	/* Serial Number */
548 #define	PCIE_EXT_CAP_ID_PWR_BUDGET	0x4	/* Power Budgeting */
549 #define	PCIE_EXT_CAP_ID_RC_LINK_DECL	0x5	/* RC Link Declaration */
550 #define	PCIE_EXT_CAP_ID_RC_INT_LINKCTRL	0x6	/* RC Internal Link Control */
551 #define	PCIE_EXT_CAP_ID_RC_EVNT_CEA	0x7	/* RC Event Collector */
552 						/* Endpoint Association */
553 #define	PCIE_EXT_CAP_ID_MFVC		0x8	/* Multi-func Virtual Channel */
554 #define	PCIE_EXT_CAP_ID_VC_WITH_MFVC	0x9	/* Virtual Channel w/ MFVC */
555 #define	PCIE_EXT_CAP_ID_RCRB		0xA	/* Root Complex Register Blck */
556 #define	PCIE_EXT_CAP_ID_VS		0xB	/* Vendor Spec Extended Cap */
557 #define	PCIE_EXT_CAP_ID_CAC		0xC	/* Config Access Correlation */
558 #define	PCIE_EXT_CAP_ID_ACS		0xD	/* Access Control Services */
559 #define	PCIE_EXT_CAP_ID_ARI		0xE	/* Alternative Routing ID */
560 #define	PCIE_EXT_CAP_ID_ATS		0xF	/* Address Translation Svcs */
561 #define	PCIE_EXT_CAP_ID_SRIOV		0x10	/* Single Root I/O Virt. */
562 #define	PCIE_EXT_CAP_ID_MRIOV		0x11	/* Multi Root I/O Virt. */
563 #define	PCIE_EXT_CAP_ID_MULTICAST	0x12	/* Multicast Services */
564 #define	PCIE_EXT_CAP_ID_PGREQ		0x13	/* Page Request */
565 #define	PCIE_EXT_CAP_ID_EA		0x14	/* Enhanced Allocation */
566 #define	PCIE_EXT_CAP_ID_RESIZE_BAR	0x15	/* Resizable BAR */
567 #define	PCIE_EXT_CAP_ID_DPA		0x16	/* Dynamic Power Allocation */
568 #define	PCIE_EXT_CAP_ID_TPH_REQ		0x17	/* TPH Requester */
569 #define	PCIE_EXT_CAP_ID_LTR		0x18	/* Latency Tolerance Report */
570 #define	PCIE_EXT_CAP_ID_PCIE2		0x19	/* PCI Express Capability 2 */
571 #define	PCIE_EXT_CAP_ID_PASID		0x1B	/* PASID */
572 #define	PCIE_EXT_CAP_ID_LNR		0x1C	/* LNR */
573 #define	PCIE_EXT_CAP_ID_DPC		0x1D	/* DPC */
574 #define	PCIE_EXT_CAP_ID_L1PM		0x1E	/* L1 PM Substrates */
575 #define	PCIE_EXT_CAP_ID_PTM		0x1F	/* Precision Time Management */
576 #define	PCIE_EXT_CAP_ID_FRS		0x21	/* Function Ready Stat. Queue */
577 #define	PCIE_EXT_CAP_ID_RTR		0x22	/* Readiness Time Reporting */
578 #define	PCIE_EXT_CAP_ID_DVS		0x23	/* Designated Vendor-Specific */
579 #define	PCIE_EXT_CAP_ID_VFRBAR		0x24	/* VF Resizable BAR */
580 #define	PCIE_EXT_CAP_ID_DLF		0x25	/* Data Link Feature */
581 #define	PCIE_EXT_CAP_ID_PL16GT		0x26	/* Physical Layer 16.0 GT/s */
582 #define	PCIE_EXT_CAP_ID_LANE_MARGIN	0x27	/* Lane Margining */
583 #define	PCIE_EXT_CAP_ID_HIEARCHY_ID	0x28	/* Hierarchy ID */
584 #define	PCIE_EXT_CAP_ID_NPEM		0x29	/* Native PCIe Enclosure Mgmt */
585 #define	PCIE_EXT_CAP_ID_PL32GT		0x2A	/* Physical Layer 32.0 GT/s */
586 #define	PCIE_EXT_CAP_ID_AP		0x2B	/* Alternate Protocol */
587 #define	PCIE_EXT_CAP_ID_SFI		0x2C	/* Sys. Firmware Intermediary */
588 #define	PCIE_EXT_CAP_ID_SHDW_FUNC	0x2D	/* Shadow Functions */
589 #define	PCIE_EXT_CAP_ID_DOE		0x2E	/* Data Object Exchange */
590 #define	PCIE_EXT_CAP_ID_DEV3		0x2F	/* Device 3 */
591 #define	PCIE_EXT_CAP_ID_IDE		0x30	/* Integrity and Data Encr. */
592 #define	PCIE_EXT_CAP_ID_PL64GT		0x31	/* Physical Layer 64.0 GT/s */
593 #define	PCIE_EXT_CAP_ID_FLIT_LOG	0x32	/* Flit Logging */
594 #define	PCIE_EXT_CAP_ID_FLIT_PERF	0x33	/* Flit Perf. Measurement */
595 #define	PCIE_EXT_CAP_ID_FLIT_ERR	0x34	/* Flit Error Injection */
596 
597 /*
598  * PCI-Express Advanced Error Reporting Extended Capability Offsets
599  */
600 #define	PCIE_AER_CAP			0x0	/* Enhanced Capability Header */
601 #define	PCIE_AER_UCE_STS		0x4	/* Uncorrectable Error Status */
602 #define	PCIE_AER_UCE_MASK		0x8	/* Uncorrectable Error Mask */
603 #define	PCIE_AER_UCE_SERV		0xc	/* Uncor Error Severity */
604 #define	PCIE_AER_CE_STS			0x10	/* Correctable Error Status */
605 #define	PCIE_AER_CE_MASK		0x14	/* Correctable Error Mask */
606 #define	PCIE_AER_CTL			0x18	/* AER Capability & Control */
607 #define	PCIE_AER_HDR_LOG		0x1c	/* Header Log */
608 
609 /* Root Ports Only */
610 #define	PCIE_AER_RE_CMD			0x2c	/* Root Error Command */
611 #define	PCIE_AER_RE_STS			0x30	/* Root Error Status */
612 #define	PCIE_AER_CE_SRC_ID		0x34	/* Error Source ID */
613 #define	PCIE_AER_ERR_SRC_ID		0x36	/* Error Source ID */
614 #define	PCIE_AER_TLP_PRE_LOG		0x38	/* TLP Prefix Log */
615 
616 /* Bridges Only */
617 #define	PCIE_AER_SUCE_STS		0x2c	/* Secondary UCE Status */
618 #define	PCIE_AER_SUCE_MASK		0x30	/* Secondary UCE Mask */
619 #define	PCIE_AER_SUCE_SERV		0x34	/* Secondary UCE Severity */
620 #define	PCIE_AER_SCTL			0x38	/* Secondary Cap & Ctl */
621 #define	PCIE_AER_SHDR_LOG		0x3c	/* Secondary Header Log */
622 
623 /*
624  * AER Uncorrectable Error Status/Mask/Severity Register
625  */
626 #define	PCIE_AER_UCE_TRAINING		0x1	/* Training Error Status */
627 #define	PCIE_AER_UCE_DLP		0x10	/* Data Link Protocol Error */
628 #define	PCIE_AER_UCE_SD			0x20	/* Link Surprise down */
629 #define	PCIE_AER_UCE_PTLP		0x1000	/* Poisoned TLP Status */
630 #define	PCIE_AER_UCE_FCP		0x2000	/* Flow Control Protocol Sts */
631 #define	PCIE_AER_UCE_TO			0x4000	/* Completion Timeout Status */
632 #define	PCIE_AER_UCE_CA			0x8000	/* Completer Abort Status */
633 #define	PCIE_AER_UCE_UC			0x10000	/* Unexpected Completion Sts */
634 #define	PCIE_AER_UCE_RO			0x20000	/* Receiver Overflow Status */
635 #define	PCIE_AER_UCE_MTLP		0x40000	/* Malformed TLP Status */
636 #define	PCIE_AER_UCE_ECRC		0x80000	/* ECRC Error Status */
637 #define	PCIE_AER_UCE_UR			0x100000 /* Unsupported Req */
638 #define	PCIE_AER_UCE_BITS		(PCIE_AER_UCE_TRAINING | \
639     PCIE_AER_UCE_DLP | PCIE_AER_UCE_SD | PCIE_AER_UCE_PTLP | \
640     PCIE_AER_UCE_FCP | PCIE_AER_UCE_TO | PCIE_AER_UCE_CA | \
641     PCIE_AER_UCE_UC | PCIE_AER_UCE_RO | PCIE_AER_UCE_MTLP | \
642     PCIE_AER_UCE_ECRC | PCIE_AER_UCE_UR)
643 #define	PCIE_AER_UCE_LOG_BITS		(PCIE_AER_UCE_PTLP | PCIE_AER_UCE_CA | \
644     PCIE_AER_UCE_UC | PCIE_AER_UCE_MTLP | PCIE_AER_UCE_ECRC | PCIE_AER_UCE_UR)
645 
646 /*
647  * AER Correctable Error Status/Mask Register
648  */
649 #define	PCIE_AER_CE_RECEIVER_ERR	0x1	/* Receiver Error Status */
650 #define	PCIE_AER_CE_BAD_TLP		0x40	/* Bad TLP Status */
651 #define	PCIE_AER_CE_BAD_DLLP		0x80	/* Bad DLLP Status */
652 #define	PCIE_AER_CE_REPLAY_ROLLOVER	0x100	/* REPLAY_NUM Rollover Status */
653 #define	PCIE_AER_CE_REPLAY_TO		0x1000	/* Replay Timer Timeout Sts */
654 #define	PCIE_AER_CE_AD_NFE		0x2000	/* Advisory Non-Fatal Status */
655 #define	PCIE_AER_CE_BITS		(PCIE_AER_CE_RECEIVER_ERR | \
656     PCIE_AER_CE_BAD_TLP | PCIE_AER_CE_BAD_DLLP | PCIE_AER_CE_REPLAY_ROLLOVER | \
657     PCIE_AER_CE_REPLAY_TO)
658 
659 /*
660  * AER Capability & Control
661  */
662 #define	PCIE_AER_CTL_FST_ERR_PTR_MASK	0x1F	/* First Error Pointer */
663 #define	PCIE_AER_CTL_ECRC_GEN_CAP	0x20	/* ECRC Generation Capable */
664 #define	PCIE_AER_CTL_ECRC_GEN_ENA	0x40	/* ECRC Generation Enable */
665 #define	PCIE_AER_CTL_ECRC_CHECK_CAP	0x80	/* ECRC Check Capable */
666 #define	PCIE_AER_CTL_ECRC_CHECK_ENA	0x100	/* ECRC Check Enable */
667 
668 /*
669  * AER Root Command Register
670  */
671 #define	PCIE_AER_RE_CMD_CE_REP_EN	0x1	/* Correctable Error Enable */
672 #define	PCIE_AER_RE_CMD_NFE_REP_EN	0x2	/* Non-Fatal Error Enable */
673 #define	PCIE_AER_RE_CMD_FE_REP_EN	0x4	/* Fatal Error Enable */
674 
675 /*
676  * AER Root Error Status Register
677  */
678 #define	PCIE_AER_RE_STS_CE_RCVD		0x1	/* ERR_COR Received */
679 #define	PCIE_AER_RE_STS_MUL_CE_RCVD	0x2	/* Multiple ERR_COR Received */
680 #define	PCIE_AER_RE_STS_FE_NFE_RCVD	0x4	/* FATAL/NON-FATAL Received */
681 #define	PCIE_AER_RE_STS_MUL_FE_NFE_RCVD	0x8	/* Multiple ERR_F/NF Received */
682 #define	PCIE_AER_RE_STS_FIRST_UC_FATAL	0x10	/* First Uncorrectable Fatal */
683 #define	PCIE_AER_RE_STS_NFE_MSGS_RCVD	0x20	/* Non-Fatal Error Msgs Rcvd */
684 #define	PCIE_AER_RE_STS_FE_MSGS_RCVD	0x40	/* Fatal Error Messages Rcvd */
685 
686 #define	PCIE_AER_RE_STS_MSG_NUM_SHIFT	27	/* Offset of Intr Msg Number */
687 #define	PCIE_AER_RE_STS_MSG_NUM_MASK	0x1F	/* Intr Msg Number Mask */
688 
689 /*
690  * AER Error Source Identification Register
691  */
692 #define	PCIE_AER_ERR_SRC_ID_CE_SHIFT	0	/* ERR_COR Source ID */
693 #define	PCIE_AER_ERR_SRC_ID_CE_MASK	0xFFFF
694 #define	PCIE_AER_ERR_SRC_ID_UE_SHIFT	16	/* ERR_FATAL/NONFATAL Src ID */
695 #define	PCIE_AER_ERR_SRC_ID_UE_MASK	0xFFFF
696 
697 /*
698  * AER Secondary Uncorrectable Error Register
699  */
700 #define	PCIE_AER_SUCE_TA_ON_SC		0x1	/* Target Abort on Split Comp */
701 #define	PCIE_AER_SUCE_MA_ON_SC		0x2	/* Master Abort on Split Comp */
702 #define	PCIE_AER_SUCE_RCVD_TA		0x4	/* Received Target Abort */
703 #define	PCIE_AER_SUCE_RCVD_MA		0x8	/* Received Master Abort */
704 #define	PCIE_AER_SUCE_USC_ERR		0x20	/* Unexpected Split Comp Err */
705 #define	PCIE_AER_SUCE_USC_MSG_DATA_ERR	0x40	/* USC Message Data Error */
706 #define	PCIE_AER_SUCE_UC_DATA_ERR	0x80	/* Uncorrectable Data Error */
707 #define	PCIE_AER_SUCE_UC_ATTR_ERR	0x100	/* UC Attribute Err */
708 #define	PCIE_AER_SUCE_UC_ADDR_ERR	0x200	/* Uncorrectable Address Err */
709 #define	PCIE_AER_SUCE_TIMER_EXPIRED	0x400	/* Delayed xtion discard */
710 #define	PCIE_AER_SUCE_PERR_ASSERT	0x800	/* PERR Assertion Detected */
711 #define	PCIE_AER_SUCE_SERR_ASSERT	0x1000	/* SERR Assertion Detected */
712 #define	PCIE_AER_SUCE_INTERNAL_ERR	0x2000	/* Internal Bridge Err Detect */
713 
714 #define	PCIE_AER_SUCE_HDR_CMD_LWR_MASK	0xF	/* Lower Command Mask */
715 #define	PCIE_AER_SUCE_HDR_CMD_LWR_SHIFT	4	/* Lower Command Shift */
716 #define	PCIE_AER_SUCE_HDR_CMD_UP_MASK	0xF	/* Upper Command Mask */
717 #define	PCIE_AER_SUCE_HDR_CMD_UP_SHIFT	8	/* Upper Command Shift */
718 #define	PCIE_AER_SUCE_HDR_ADDR_SHIFT	32	/* Upper Command Shift */
719 
720 #define	PCIE_AER_SUCE_BITS		(PCIE_AER_SUCE_TA_ON_SC | \
721     PCIE_AER_SUCE_MA_ON_SC | PCIE_AER_SUCE_RCVD_TA | PCIE_AER_SUCE_RCVD_MA | \
722     PCIE_AER_SUCE_USC_ERR | PCIE_AER_SUCE_USC_MSG_DATA_ERR | \
723     PCIE_AER_SUCE_UC_DATA_ERR | PCIE_AER_SUCE_UC_ATTR_ERR | \
724     PCIE_AER_SUCE_UC_ADDR_ERR |	PCIE_AER_SUCE_TIMER_EXPIRED | \
725     PCIE_AER_SUCE_PERR_ASSERT |	PCIE_AER_SUCE_SERR_ASSERT | \
726     PCIE_AER_SUCE_INTERNAL_ERR)
727 #define	PCIE_AER_SUCE_LOG_BITS		(PCIE_AER_SUCE_TA_ON_SC | \
728     PCIE_AER_SUCE_MA_ON_SC | PCIE_AER_SUCE_RCVD_TA | PCIE_AER_SUCE_RCVD_MA | \
729     PCIE_AER_SUCE_USC_ERR | PCIE_AER_SUCE_USC_MSG_DATA_ERR | \
730     PCIE_AER_SUCE_UC_DATA_ERR | PCIE_AER_SUCE_UC_ATTR_ERR | \
731     PCIE_AER_SUCE_UC_ADDR_ERR |	PCIE_AER_SUCE_PERR_ASSERT)
732 
733 /*
734  * AER Secondary Capability & Control
735  */
736 #define	PCIE_AER_SCTL_FST_ERR_PTR_MASK	0x1F	/* First Error Pointer */
737 
738 /*
739  * AER Secondary Headers
740  * The Secondary Header Logs is 4 DW long.
741  * The first 2 DW are split into 3 sections
742  * o Transaction Attribute
743  * o Transaction Command Lower
744  * o Transaction Command Higher
745  * The last 2 DW is the Transaction Address
746  */
747 #define	PCIE_AER_SHDR_LOG_ATTR_MASK	0xFFFFFFFFF
748 #define	PCIE_AER_SHDR_LOG_CMD_LOW_MASK	0xF000000000
749 #define	PCIE_AER_SHDR_LOG_CMD_HIGH_MASK	0xF0000000000
750 #define	PCIE_AER_SHDR_LOG_ADDR_MASK	0xFFFFFFFFFFFFFFFF
751 
752 /*
753  * PCI-Express Device Serial Number Capability Offsets.
754  */
755 #define	PCIE_SER_CAP		0x0	/* Enhanced Capability Header */
756 #define	PCIE_SER_SID_LOWER_DW	0x4	/* Lower 32-bit Serial Number */
757 #define	PCIE_SER_SID_UPPER_DW	0x8	/* Upper 32-bit Serial Number */
758 
759 /*
760  * ARI Capability Offsets
761  */
762 #define	PCIE_ARI_HDR	0x0		/* Enhanced Capability Header */
763 #define	PCIE_ARI_CAP	0x4		/* ARI Capability Register */
764 #define	PCIE_ARI_CTL	0x6		/* ARI Control Register */
765 
766 #define	PCIE_ARI_CAP_MFVC_FUNC_GRP	0x01
767 #define	PCIE_ARI_CAP_ASC_FUNC_GRP	0x02
768 
769 #define	PCIE_ARI_CAP_NEXT_FUNC_SHIFT	8
770 #define	PCIE_ARI_CAP_NEXT_FUNC_MASK	0xffff
771 
772 #define	PCIE_ARI_CTRL_MFVC_FUNC_GRP	0x01
773 #define	PCIE_ARI_CTRL_ASC_FUNC_GRP	0x02
774 
775 #define	PCIE_ARI_CTRL_FUNC_GRP_SHIFT	4
776 #define	PCIE_ARI_CTRL_FUNC_GRP_MASK	0x7
777 
778 /*
779  * PCI-E Common TLP Header Fields
780  */
781 #define	PCIE_TLP_FMT_3DW	0x00
782 #define	PCIE_TLP_FMT_4DW	0x20
783 #define	PCIE_TLP_FMT_3DW_DATA	0x40
784 #define	PCIE_TLP_FMT_4DW_DATA	0x60
785 
786 #define	PCIE_TLP_TYPE_MEM	0x0
787 #define	PCIE_TLP_TYPE_MEMLK	0x1
788 #define	PCIE_TLP_TYPE_IO	0x2
789 #define	PCIE_TLP_TYPE_CFG0	0x4
790 #define	PCIE_TLP_TYPE_CFG1	0x5
791 #define	PCIE_TLP_TYPE_MSG	0x10
792 #define	PCIE_TLP_TYPE_CPL	0xA
793 #define	PCIE_TLP_TYPE_CPLLK	0xB
794 #define	PCIE_TLP_TYPE_MSI	0x18
795 
796 #define	PCIE_TLP_MRD3		(PCIE_TLP_FMT_3DW | PCIE_TLP_TYPE_MEM)
797 #define	PCIE_TLP_MRD4		(PCIE_TLP_FMT_4DW | PCIE_TLP_TYPE_MEM)
798 #define	PCIE_TLP_MRDLK3		(PCIE_TLP_FMT_3DW | PCIE_TLP_TYPE_MEMLK)
799 #define	PCIE_TLP_MRDLK4		(PCIE_TLP_FMT_4DW | PCIE_TLP_TYPE_MEMLK)
800 #define	PCIE_TLP_MRDWR3		(PCIE_TLP_FMT_3DW_DATA | PCIE_TLP_TYPE_MEM)
801 #define	PCIE_TLP_MRDWR4		(PCIE_TLP_FMT_4DW_DATA | PCIE_TLP_TYPE_MEM)
802 #define	PCIE_TLP_IORD		(PCIE_TLP_FMT_3DW | PCIE_TLP_TYPE_IO)
803 #define	PCIE_TLP_IOWR		(PCIE_TLP_FMT_3DW_DATA | PCIE_TLP_TYPE_IO)
804 #define	PCIE_TLP_CFGRD0		(PCIE_TLP_FMT_3DW | PCIE_TLP_TYPE_CFG0)
805 #define	PCIE_TLP_CFGWR0		(PCIE_TLP_FMT_3DW_DATA | PCIE_TLP_TYPE_CFG0)
806 #define	PCIE_TLP_CFGRD1		(PCIE_TLP_FMT_3DW | PCIE_TLP_TYPE_CFG1)
807 #define	PCIE_TLP_CFGWR1		(PCIE_TLP_FMT_3DW_DATA | PCIE_TLP_TYPE_CFG1)
808 #define	PCIE_TLP_MSG		(PCIE_TLP_FMT_4DW | PCIE_TLP_TYPE_MSG)
809 #define	PCIE_TLP_MSGD		(PCIE_TLP_FMT_4DW_DATA | PCIE_TLP_TYPE_MSG)
810 #define	PCIE_TLP_CPL		(PCIE_TLP_FMT_3DW | PCIE_TLP_TYPE_CPL)
811 #define	PCIE_TLP_CPLD		(PCIE_TLP_FMT_3DW_DATA | PCIE_TLP_TYPE_CPL)
812 #define	PCIE_TLP_CPLLK		(PCIE_TLP_FMT_3DW | PCIE_TLP_TYPE_CPLLK)
813 #define	PCIE_TLP_CPLDLK		(PCIE_TLP_FMT_3DW_DATA | PCIE_TLP_TYPE_CPLLK)
814 #define	PCIE_TLP_MSI32		(PCIE_TLP_FMT_3DW_DATA | PCIE_TLP_TYPE_MSI)
815 #define	PCIE_TLP_MSI64		(PCIE_TLP_FMT_4DW_DATA | PCIE_TLP_TYPE_MSI)
816 
817 typedef uint16_t pcie_req_id_t;
818 
819 #define	PCIE_REQ_ID_BUS_SHIFT	8
820 #define	PCIE_REQ_ID_BUS_MASK	0xFF00
821 #define	PCIE_REQ_ID_DEV_SHIFT	3
822 #define	PCIE_REQ_ID_DEV_MASK	0x00F8
823 #define	PCIE_REQ_ID_FUNC_SHIFT	0
824 #define	PCIE_REQ_ID_FUNC_MASK	0x0007
825 #define	PCIE_REQ_ID_ARI_FUNC_MASK	0x00FF
826 
827 #define	PCIE_CPL_STS_SUCCESS	0
828 #define	PCIE_CPL_STS_UR		1
829 #define	PCIE_CPL_STS_CRS	2
830 #define	PCIE_CPL_STS_CA		4
831 
832 #if defined(_BIT_FIELDS_LTOH)
833 /*
834  * PCI Express little-endian common TLP header format
835  */
836 typedef struct pcie_tlp_hdr {
837 	uint32_t	len	:10,
838 			rsvd3   :2,
839 			attr    :2,
840 			ep	:1,
841 			td	:1,
842 			rsvd2   :4,
843 			tc	:3,
844 			rsvd1   :1,
845 			type    :5,
846 			fmt	:2,
847 			rsvd0   :1;
848 } pcie_tlp_hdr_t;
849 
850 typedef struct pcie_mem64 {
851 	uint32_t	fbe	:4,
852 			lbe	:4,
853 			tag	:8,
854 			rid	:16;
855 	uint32_t	addr1;
856 	uint32_t	rsvd0   :2,
857 			addr0   :30;
858 } pcie_mem64_t;
859 
860 typedef struct pcie_memio32 {
861 	uint32_t	fbe	:4,
862 			lbe	:4,
863 			tag	:8,
864 			rid	:16;
865 	uint32_t	rsvd0   :2,
866 			addr0   :30;
867 } pcie_memio32_t;
868 
869 typedef struct pcie_cfg {
870 	uint32_t	fbe	:4,
871 			lbe	:4,
872 			tag	:8,
873 			rid	:16;
874 	uint32_t	rsvd1   :2,
875 			reg	:6,
876 			extreg  :4,
877 			rsvd0   :4,
878 			func    :3,
879 			dev	:5,
880 			bus	:8;
881 } pcie_cfg_t;
882 
883 typedef struct pcie_cpl {
884 	uint32_t	bc	:12,
885 			bcm	:1,
886 			status  :3,
887 			cid	:16;
888 	uint32_t	laddr   :7,
889 			rsvd0   :1,
890 			tag	:8,
891 			rid	:16;
892 } pcie_cpl_t;
893 
894 /*
895  * PCI-Express Message Request Header
896  */
897 typedef struct pcie_msg {
898 	uint32_t	msg_code:8,	/* DW1 */
899 			tag	:8,
900 			rid	:16;
901 	uint32_t	unused[2];	/* DW 2 & 3 */
902 } pcie_msg_t;
903 
904 #elif defined(_BIT_FIELDS_HTOL)
905 /*
906  * PCI Express big-endian common TLP header format
907  */
908 typedef struct pcie_tlp_hdr {
909 	uint32_t	rsvd0	:1,
910 			fmt	:2,
911 			type	:5,
912 			rsvd1	:1,
913 			tc	:3,
914 			rsvd2	:4,
915 			td	:1,
916 			ep	:1,
917 			attr	:2,
918 			rsvd3	:2,
919 			len	:10;
920 } pcie_tlp_hdr_t;
921 
922 typedef struct pcie_mem64 {
923 	uint32_t	rid	:16,
924 			tag	:8,
925 			lbe	:4,
926 			fbe	:4;
927 	uint32_t	addr1;
928 	uint32_t	addr0	:30,
929 			rsvd0	:2;
930 } pcie_mem64_t;
931 
932 typedef struct pcie_memio32 {
933 	uint32_t	rid	:16,
934 			tag	:8,
935 			lbe	:4,
936 			fbe	:4;
937 	uint32_t	addr0	:30,
938 			rsvd0	:2;
939 } pcie_memio32_t;
940 
941 typedef struct pcie_cfg {
942 	uint32_t	rid	:16,
943 			tag	:8,
944 			lbe	:4,
945 			fbe	:4;
946 	uint32_t	bus	:8,
947 			dev	:5,
948 			func	:3,
949 			rsvd0	:4,
950 			extreg	:4,
951 			reg	:6,
952 			rsvd1	:2;
953 } pcie_cfg_t;
954 
955 typedef struct pcie_cpl {
956 	uint32_t	cid	:16,
957 			status	:3,
958 			bcm	:1,
959 			bc	:12;
960 	uint32_t	rid	:16,
961 			tag	:8,
962 			rsvd0	:1,
963 			laddr	:7;
964 } pcie_cpl_t;
965 
966 /*
967  * PCI-Express Message Request Header
968  */
969 typedef struct pcie_msg {
970 	uint32_t	rid	:16,	/* DW1 */
971 			tag	:8,
972 			msg_code:8;
973 	uint32_t	unused[2];	/* DW 2 & 3 */
974 } pcie_msg_t;
975 #else
976 #error "bit field not defined"
977 #endif
978 
979 #define	PCIE_MSG_CODE_ERR_COR		0x30
980 #define	PCIE_MSG_CODE_ERR_NONFATAL	0x31
981 #define	PCIE_MSG_CODE_ERR_FATAL		0x33
982 
983 #ifdef	__cplusplus
984 }
985 #endif
986 
987 #endif	/* _SYS_PCIE_H */
988