1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef	_PCIE_CORE_H
18 #define	_PCIE_CORE_H
19 
20 /* cpp contortions to concatenate w/arg prescan */
21 #ifndef PAD
22 #define	_PADLINE(line)	pad ## line
23 #define	_XSTR(line)	_PADLINE(line)
24 #define	PAD		_XSTR(__LINE__)
25 #endif
26 
27 /* PCIE Enumeration space offsets */
28 #define  PCIE_CORE_CONFIG_OFFSET	0x0
29 #define  PCIE_FUNC0_CONFIG_OFFSET	0x400
30 #define  PCIE_FUNC1_CONFIG_OFFSET	0x500
31 #define  PCIE_FUNC2_CONFIG_OFFSET	0x600
32 #define  PCIE_FUNC3_CONFIG_OFFSET	0x700
33 #define  PCIE_SPROM_SHADOW_OFFSET	0x800
34 #define  PCIE_SBCONFIG_OFFSET		0xE00
35 
36 /* PCIE Bar0 Address Mapping. Each function maps 16KB config space */
37 #define PCIE_DEV_BAR0_SIZE		0x4000
38 #define PCIE_BAR0_WINMAPCORE_OFFSET	0x0
39 #define PCIE_BAR0_EXTSPROM_OFFSET	0x1000
40 #define PCIE_BAR0_PCIECORE_OFFSET	0x2000
41 #define PCIE_BAR0_CCCOREREG_OFFSET	0x3000
42 
43 /* different register spaces to access thr'u pcie indirect access */
44 #define PCIE_CONFIGREGS 	1	/* Access to config space */
45 #define PCIE_PCIEREGS 		2	/* Access to pcie registers */
46 
47 /* SB side: PCIE core and host control registers */
48 typedef struct sbpcieregs {
49 	u32 control;		/* host mode only */
50 	u32 PAD[2];
51 	u32 biststatus;	/* bist Status: 0x00C */
52 	u32 gpiosel;		/* PCIE gpio sel: 0x010 */
53 	u32 gpioouten;	/* PCIE gpio outen: 0x14 */
54 	u32 PAD[2];
55 	u32 intstatus;	/* Interrupt status: 0x20 */
56 	u32 intmask;		/* Interrupt mask: 0x24 */
57 	u32 sbtopcimailbox;	/* sb to pcie mailbox: 0x028 */
58 	u32 PAD[53];
59 	u32 sbtopcie0;	/* sb to pcie translation 0: 0x100 */
60 	u32 sbtopcie1;	/* sb to pcie translation 1: 0x104 */
61 	u32 sbtopcie2;	/* sb to pcie translation 2: 0x108 */
62 	u32 PAD[5];
63 
64 	/* pcie core supports in direct access to config space */
65 	u32 configaddr;	/* pcie config space access: Address field: 0x120 */
66 	u32 configdata;	/* pcie config space access: Data field: 0x124 */
67 
68 	/* mdio access to serdes */
69 	u32 mdiocontrol;	/* controls the mdio access: 0x128 */
70 	u32 mdiodata;	/* Data to the mdio access: 0x12c */
71 
72 	/* pcie protocol phy/dllp/tlp register indirect access mechanism */
73 	u32 pcieindaddr;	/* indirect access to the internal register: 0x130 */
74 	u32 pcieinddata;	/* Data to/from the internal regsiter: 0x134 */
75 
76 	u32 clkreqenctrl;	/* >= rev 6, Clkreq rdma control : 0x138 */
77 	u32 PAD[177];
78 	u32 pciecfg[4][64];	/* 0x400 - 0x7FF, PCIE Cfg Space */
79 	u16 sprom[64];	/* SPROM shadow Area */
80 } sbpcieregs_t;
81 
82 /* PCI control */
83 #define PCIE_RST_OE	0x01	/* When set, drives PCI_RESET out to pin */
84 #define PCIE_RST	0x02	/* Value driven out to pin */
85 
86 #define	PCIE_CFGADDR	0x120	/* offsetof(configaddr) */
87 #define	PCIE_CFGDATA	0x124	/* offsetof(configdata) */
88 
89 /* Interrupt status/mask */
90 #define PCIE_INTA	0x01	/* PCIE INTA message is received */
91 #define PCIE_INTB	0x02	/* PCIE INTB message is received */
92 #define PCIE_INTFATAL	0x04	/* PCIE INTFATAL message is received */
93 #define PCIE_INTNFATAL	0x08	/* PCIE INTNONFATAL message is received */
94 #define PCIE_INTCORR	0x10	/* PCIE INTCORR message is received */
95 #define PCIE_INTPME	0x20	/* PCIE INTPME message is received */
96 
97 /* SB to PCIE translation masks */
98 #define SBTOPCIE0_MASK	0xfc000000
99 #define SBTOPCIE1_MASK	0xfc000000
100 #define SBTOPCIE2_MASK	0xc0000000
101 
102 /* Access type bits (0:1) */
103 #define SBTOPCIE_MEM	0
104 #define SBTOPCIE_IO	1
105 #define SBTOPCIE_CFG0	2
106 #define SBTOPCIE_CFG1	3
107 
108 /* Prefetch enable bit 2 */
109 #define SBTOPCIE_PF		4
110 
111 /* Write Burst enable for memory write bit 3 */
112 #define SBTOPCIE_WR_BURST	8
113 
114 /* config access */
115 #define CONFIGADDR_FUNC_MASK	0x7000
116 #define CONFIGADDR_FUNC_SHF	12
117 #define CONFIGADDR_REG_MASK	0x0FFF
118 #define CONFIGADDR_REG_SHF	0
119 
120 #define PCIE_CONFIG_INDADDR(f, r)	\
121 	((((f) & CONFIGADDR_FUNC_MASK) << CONFIGADDR_FUNC_SHF) | \
122 	(((r) & CONFIGADDR_REG_MASK) << CONFIGADDR_REG_SHF))
123 
124 /* PCIE protocol regs Indirect Address */
125 #define PCIEADDR_PROT_MASK	0x300
126 #define PCIEADDR_PROT_SHF	8
127 #define PCIEADDR_PL_TLP		0
128 #define PCIEADDR_PL_DLLP	1
129 #define PCIEADDR_PL_PLP		2
130 
131 /* PCIE protocol PHY diagnostic registers */
132 #define	PCIE_PLP_MODEREG		0x200	/* Mode */
133 #define	PCIE_PLP_STATUSREG		0x204	/* Status */
134 #define PCIE_PLP_LTSSMCTRLREG		0x208	/* LTSSM control */
135 #define PCIE_PLP_LTLINKNUMREG		0x20c	/* Link Training Link number */
136 #define PCIE_PLP_LTLANENUMREG		0x210	/* Link Training Lane number */
137 #define PCIE_PLP_LTNFTSREG		0x214	/* Link Training N_FTS */
138 #define PCIE_PLP_ATTNREG		0x218	/* Attention */
139 #define PCIE_PLP_ATTNMASKREG		0x21C	/* Attention Mask */
140 #define PCIE_PLP_RXERRCTR		0x220	/* Rx Error */
141 #define PCIE_PLP_RXFRMERRCTR		0x224	/* Rx Framing Error */
142 #define PCIE_PLP_RXERRTHRESHREG		0x228	/* Rx Error threshold */
143 #define PCIE_PLP_TESTCTRLREG		0x22C	/* Test Control reg */
144 #define PCIE_PLP_SERDESCTRLOVRDREG	0x230	/* SERDES Control Override */
145 #define PCIE_PLP_TIMINGOVRDREG		0x234	/* Timing param override */
146 #define PCIE_PLP_RXTXSMDIAGREG		0x238	/* RXTX State Machine Diag */
147 #define PCIE_PLP_LTSSMDIAGREG		0x23C	/* LTSSM State Machine Diag */
148 
149 /* PCIE protocol DLLP diagnostic registers */
150 #define PCIE_DLLP_LCREG			0x100	/* Link Control */
151 #define PCIE_DLLP_LSREG			0x104	/* Link Status */
152 #define PCIE_DLLP_LAREG			0x108	/* Link Attention */
153 #define PCIE_DLLP_LAMASKREG		0x10C	/* Link Attention Mask */
154 #define PCIE_DLLP_NEXTTXSEQNUMREG	0x110	/* Next Tx Seq Num */
155 #define PCIE_DLLP_ACKEDTXSEQNUMREG	0x114	/* Acked Tx Seq Num */
156 #define PCIE_DLLP_PURGEDTXSEQNUMREG	0x118	/* Purged Tx Seq Num */
157 #define PCIE_DLLP_RXSEQNUMREG		0x11C	/* Rx Sequence Number */
158 #define PCIE_DLLP_LRREG			0x120	/* Link Replay */
159 #define PCIE_DLLP_LACKTOREG		0x124	/* Link Ack Timeout */
160 #define PCIE_DLLP_PMTHRESHREG		0x128	/* Power Management Threshold */
161 #define PCIE_DLLP_RTRYWPREG		0x12C	/* Retry buffer write ptr */
162 #define PCIE_DLLP_RTRYRPREG		0x130	/* Retry buffer Read ptr */
163 #define PCIE_DLLP_RTRYPPREG		0x134	/* Retry buffer Purged ptr */
164 #define PCIE_DLLP_RTRRWREG		0x138	/* Retry buffer Read/Write */
165 #define PCIE_DLLP_ECTHRESHREG		0x13C	/* Error Count Threshold */
166 #define PCIE_DLLP_TLPERRCTRREG		0x140	/* TLP Error Counter */
167 #define PCIE_DLLP_ERRCTRREG		0x144	/* Error Counter */
168 #define PCIE_DLLP_NAKRXCTRREG		0x148	/* NAK Received Counter */
169 #define PCIE_DLLP_TESTREG		0x14C	/* Test */
170 #define PCIE_DLLP_PKTBIST		0x150	/* Packet BIST */
171 #define PCIE_DLLP_PCIE11		0x154	/* DLLP PCIE 1.1 reg */
172 
173 #define PCIE_DLLP_LSREG_LINKUP		(1 << 16)
174 
175 /* PCIE protocol TLP diagnostic registers */
176 #define PCIE_TLP_CONFIGREG		0x000	/* Configuration */
177 #define PCIE_TLP_WORKAROUNDSREG		0x004	/* TLP Workarounds */
178 #define PCIE_TLP_WRDMAUPPER		0x010	/* Write DMA Upper Address */
179 #define PCIE_TLP_WRDMALOWER		0x014	/* Write DMA Lower Address */
180 #define PCIE_TLP_WRDMAREQ_LBEREG	0x018	/* Write DMA Len/ByteEn Req */
181 #define PCIE_TLP_RDDMAUPPER		0x01C	/* Read DMA Upper Address */
182 #define PCIE_TLP_RDDMALOWER		0x020	/* Read DMA Lower Address */
183 #define PCIE_TLP_RDDMALENREG		0x024	/* Read DMA Len Req */
184 #define PCIE_TLP_MSIDMAUPPER		0x028	/* MSI DMA Upper Address */
185 #define PCIE_TLP_MSIDMALOWER		0x02C	/* MSI DMA Lower Address */
186 #define PCIE_TLP_MSIDMALENREG		0x030	/* MSI DMA Len Req */
187 #define PCIE_TLP_SLVREQLENREG		0x034	/* Slave Request Len */
188 #define PCIE_TLP_FCINPUTSREQ		0x038	/* Flow Control Inputs */
189 #define PCIE_TLP_TXSMGRSREQ		0x03C	/* Tx StateMachine and Gated Req */
190 #define PCIE_TLP_ADRACKCNTARBLEN	0x040	/* Address Ack XferCnt and ARB Len */
191 #define PCIE_TLP_DMACPLHDR0		0x044	/* DMA Completion Hdr 0 */
192 #define PCIE_TLP_DMACPLHDR1		0x048	/* DMA Completion Hdr 1 */
193 #define PCIE_TLP_DMACPLHDR2		0x04C	/* DMA Completion Hdr 2 */
194 #define PCIE_TLP_DMACPLMISC0		0x050	/* DMA Completion Misc0 */
195 #define PCIE_TLP_DMACPLMISC1		0x054	/* DMA Completion Misc1 */
196 #define PCIE_TLP_DMACPLMISC2		0x058	/* DMA Completion Misc2 */
197 #define PCIE_TLP_SPTCTRLLEN		0x05C	/* Split Controller Req len */
198 #define PCIE_TLP_SPTCTRLMSIC0		0x060	/* Split Controller Misc 0 */
199 #define PCIE_TLP_SPTCTRLMSIC1		0x064	/* Split Controller Misc 1 */
200 #define PCIE_TLP_BUSDEVFUNC		0x068	/* Bus/Device/Func */
201 #define PCIE_TLP_RESETCTR		0x06C	/* Reset Counter */
202 #define PCIE_TLP_RTRYBUF		0x070	/* Retry Buffer value */
203 #define PCIE_TLP_TGTDEBUG1		0x074	/* Target Debug Reg1 */
204 #define PCIE_TLP_TGTDEBUG2		0x078	/* Target Debug Reg2 */
205 #define PCIE_TLP_TGTDEBUG3		0x07C	/* Target Debug Reg3 */
206 #define PCIE_TLP_TGTDEBUG4		0x080	/* Target Debug Reg4 */
207 
208 /* MDIO control */
209 #define MDIOCTL_DIVISOR_MASK		0x7f	/* clock to be used on MDIO */
210 #define MDIOCTL_DIVISOR_VAL		0x2
211 #define MDIOCTL_PREAM_EN		0x80	/* Enable preamble sequnce */
212 #define MDIOCTL_ACCESS_DONE		0x100	/* Tranaction complete */
213 
214 /* MDIO Data */
215 #define MDIODATA_MASK			0x0000ffff	/* data 2 bytes */
216 #define MDIODATA_TA			0x00020000	/* Turnaround */
217 #define MDIODATA_REGADDR_SHF_OLD	18	/* Regaddr shift (rev < 10) */
218 #define MDIODATA_REGADDR_MASK_OLD	0x003c0000	/* Regaddr Mask (rev < 10) */
219 #define MDIODATA_DEVADDR_SHF_OLD	22	/* Physmedia devaddr shift (rev < 10) */
220 #define MDIODATA_DEVADDR_MASK_OLD	0x0fc00000	/* Physmedia devaddr Mask (rev < 10) */
221 #define MDIODATA_REGADDR_SHF		18	/* Regaddr shift */
222 #define MDIODATA_REGADDR_MASK		0x007c0000	/* Regaddr Mask */
223 #define MDIODATA_DEVADDR_SHF		23	/* Physmedia devaddr shift */
224 #define MDIODATA_DEVADDR_MASK		0x0f800000	/* Physmedia devaddr Mask */
225 #define MDIODATA_WRITE			0x10000000	/* write Transaction */
226 #define MDIODATA_READ			0x20000000	/* Read Transaction */
227 #define MDIODATA_START			0x40000000	/* start of Transaction */
228 
229 #define MDIODATA_DEV_ADDR		0x0	/* dev address for serdes */
230 #define	MDIODATA_BLK_ADDR		0x1F	/* blk address for serdes */
231 
232 /* MDIO devices (SERDES modules)
233  *  unlike old pcie cores (rev < 10), rev10 pcie serde organizes registers into a few blocks.
234  *  two layers mapping (blockidx, register offset) is required
235  */
236 #define MDIO_DEV_IEEE0		0x000
237 #define MDIO_DEV_IEEE1		0x001
238 #define MDIO_DEV_BLK0		0x800
239 #define MDIO_DEV_BLK1		0x801
240 #define MDIO_DEV_BLK2		0x802
241 #define MDIO_DEV_BLK3		0x803
242 #define MDIO_DEV_BLK4		0x804
243 #define MDIO_DEV_TXPLL		0x808	/* TXPLL register block idx */
244 #define MDIO_DEV_TXCTRL0	0x820
245 #define MDIO_DEV_SERDESID	0x831
246 #define MDIO_DEV_RXCTRL0	0x840
247 
248 /* serdes regs (rev < 10) */
249 #define MDIODATA_DEV_PLL       		0x1d	/* SERDES PLL Dev */
250 #define MDIODATA_DEV_TX        		0x1e	/* SERDES TX Dev */
251 #define MDIODATA_DEV_RX        		0x1f	/* SERDES RX Dev */
252 	/* SERDES RX registers */
253 #define SERDES_RX_CTRL			1	/* Rx cntrl */
254 #define SERDES_RX_TIMER1		2	/* Rx Timer1 */
255 #define SERDES_RX_CDR			6	/* CDR */
256 #define SERDES_RX_CDRBW			7	/* CDR BW */
257 
258 	/* SERDES RX control register */
259 #define SERDES_RX_CTRL_FORCE		0x80	/* rxpolarity_force */
260 #define SERDES_RX_CTRL_POLARITY		0x40	/* rxpolarity_value */
261 
262 	/* SERDES PLL registers */
263 #define SERDES_PLL_CTRL                 1	/* PLL control reg */
264 #define PLL_CTRL_FREQDET_EN             0x4000	/* bit 14 is FREQDET on */
265 
266 /* Power management threshold */
267 #define PCIE_L0THRESHOLDTIME_MASK       0xFF00	/* bits 0 - 7 */
268 #define PCIE_L1THRESHOLDTIME_MASK       0xFF00	/* bits 8 - 15 */
269 #define PCIE_L1THRESHOLDTIME_SHIFT      8	/* PCIE_L1THRESHOLDTIME_SHIFT */
270 #define PCIE_L1THRESHOLD_WARVAL         0x72	/* WAR value */
271 #define PCIE_ASPMTIMER_EXTEND		0x01000000	/* > rev7: enable extend ASPM timer */
272 
273 /* SPROM offsets */
274 #define SRSH_ASPM_OFFSET		4	/* word 4 */
275 #define SRSH_ASPM_ENB			0x18	/* bit 3, 4 */
276 #define SRSH_ASPM_L1_ENB		0x10	/* bit 4 */
277 #define SRSH_ASPM_L0s_ENB		0x8	/* bit 3 */
278 #define SRSH_PCIE_MISC_CONFIG		5	/* word 5 */
279 #define SRSH_L23READY_EXIT_NOPERST	0x8000	/* bit 15 */
280 #define SRSH_CLKREQ_OFFSET_REV5		20	/* word 20 for srom rev <= 5 */
281 #define SRSH_CLKREQ_OFFSET_REV8		52	/* word 52 for srom rev 8 */
282 #define SRSH_CLKREQ_ENB			0x0800	/* bit 11 */
283 #define SRSH_BD_OFFSET                  6	/* word 6 */
284 #define SRSH_AUTOINIT_OFFSET            18	/* auto initialization enable */
285 
286 /* Linkcontrol reg offset in PCIE Cap */
287 #define PCIE_CAP_LINKCTRL_OFFSET	16	/* linkctrl offset in pcie cap */
288 #define PCIE_CAP_LCREG_ASPML0s		0x01	/* ASPM L0s in linkctrl */
289 #define PCIE_CAP_LCREG_ASPML1		0x02	/* ASPM L1 in linkctrl */
290 #define PCIE_CLKREQ_ENAB		0x100	/* CLKREQ Enab in linkctrl */
291 
292 #define PCIE_ASPM_ENAB			3	/* ASPM L0s & L1 in linkctrl */
293 #define PCIE_ASPM_L1_ENAB		2	/* ASPM L0s & L1 in linkctrl */
294 #define PCIE_ASPM_L0s_ENAB		1	/* ASPM L0s & L1 in linkctrl */
295 #define PCIE_ASPM_DISAB			0	/* ASPM L0s & L1 in linkctrl */
296 
297 /* Status reg PCIE_PLP_STATUSREG */
298 #define PCIE_PLP_POLARITYINV_STAT	0x10
299 #endif				/* _PCIE_CORE_H */
300