siisatareg.h revision 1.3 1 /* $NetBSD: siisatareg.h,v 1.3 2009/06/17 04:37:57 jakllsch Exp $ */
2 /* Id: siisatareg.h,v 1.10 2008/05/21 15:51:36 jakllsch Exp */
3
4 /*-
5 * Copyright (c) 2007, 2008 Jonathan A. Kollasch.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29
30 /* Silicon Image SATA 2 controller register defines */
31
32 #include <sys/cdefs.h>
33
34 /* the SiI3124 has 4 ports, all others so far have less */
35 #define SIISATA_MAX_PORTS 4
36 /* all parts have a full complement of slots (so far) */
37 #define SIISATA_MAX_SLOTS 31
38
39 /* structures */
40
41 /* Scatter/Gather Entry */
42 struct siisata_sge {
43 #if 0
44 uint32_t sge_dal; /* data address low */
45 uint32_t sge_dah; /* " " high */
46 #else
47 uint64_t sge_da;
48 #endif
49 uint32_t sge_dc; /* data count (bytes) */
50 uint32_t sge_flags; /* */
51 #define SGE_FLAG_TRM __BIT(31)
52 #define SGE_FLAG_LNK __BIT(30)
53 #define SGE_FLAG_DRD __BIT(29)
54 #define SGE_FLAG_XCF __BIT(28)
55 } __packed;
56
57 /* Scatter/Gather Table */
58 /* must be aligned to 64-bit boundary */
59 struct siisata_sgt {
60 struct siisata_sge sgt_sge[4];
61 } __packed;
62
63 /* Port Request Block */
64 struct siisata_prb {
65 uint16_t prb_control; /* Control Field */
66 #define PRB_CF_PROTOCOL_OVERRIDE __BIT(0)
67 #define PRB_CF_RETRANSMIT __BIT(1)
68 #define PRB_CF_EXTERNAL_COMMAND __BIT(2)
69 #define PRB_CF_RECEIVE __BIT(3)
70 #define PRB_CF_PACKET_READ __BIT(4)
71 #define PRB_CF_PACKET_WRITE __BIT(5)
72 #define PRB_CF_INTERRUPT_MASK __BIT(6)
73 #define PRB_CF_SOFT_RESET __BIT(7)
74 uint16_t prb_protocol_override;
75 #define PRB_PO_PACKET __BIT(0)
76 #define PRB_PO_LCQ __BIT(1)
77 #define PRB_PO_NCQ __BIT(2)
78 #define PRB_PO_READ __BIT(3)
79 #define PRB_PO_WRITE __BIT(4)
80 #define PRB_PO_TRANSPARENT __BIT(5)
81 uint32_t prb_transfer_count;
82 uint8_t prb_fis[20];
83 uint32_t prb_reserved_0x1C; /* "must be zero" */
84 /* First SGE in PRB is always reserved for ATAPI in this implementation. */
85 uint8_t prb_atapi[16]; /* zero for non-ATAPI */
86 struct siisata_sge prb_sge[1]; /* extended to NSGE */
87 } __packed;
88
89
90 #define SIISATA_NSGE ((MAXPHYS/PAGE_SIZE) + 1)
91 #define SIISATA_CMD_ALIGN 0x7f
92 #define SIISATA_CMD_SIZE \
93 ( ( sizeof(struct siisata_prb) + (SIISATA_NSGE - 1) * sizeof(struct siisata_sge) + SIISATA_CMD_ALIGN ) & ~SIISATA_CMD_ALIGN )
94
95 /* PCI stuff */
96 #define SIISATA_PCI_BAR0 0x10
97 #define SIISATA_PCI_BAR1 0x18
98 #define SIISATA_PCI_BAR2 0x20
99
100 /* BAR 0 */
101
102 /* port n slot status */
103 #define GR_PXSS(n) (n*4)
104 /* global control */
105 #define GR_GC 0x40
106 /* global interrupt status */
107 #define GR_GIS 0x44
108 /* phy config - don't touch */
109 #define GR_PHYC 0x48
110 /* BIST */
111 #define GR_BIST_CONTROL 0x50
112 #define GR_BIST_PATTERN 0x54
113 #define GR_BIST_STATUS 0x58
114 /* I2C SiI3132 */
115 #define GR_SII3132_IICCONTROL 0x60
116 #define GR_SII3132_IICSTATUS 0x64
117 #define GR_SII3132_IICSLAVEADDR 0x68
118 #define GR_SII3132_IICDATA 0x6c
119 /* Flash */
120 #define GR_FLSHADDR 0x70
121 #define GR_FLSHDATA 0x74
122 /* I2C SiI3124 */
123 #define GR_SII3124_IICADDR 0x78
124 #define GR_SII3124_IICDATA 0x7c
125
126
127 /* GR_GC bits */
128 #define GR_GC_GLBLRST __BIT(31)
129 #define GR_GC_MSIACK __BIT(30)
130 #define GR_GC_I2CINTEN __BIT(29)
131 #define GR_GC_PERRRPTDSBL __BIT(28)
132 #define GR_GC_3GBPS __BIT(24)
133 #define GR_GC_REQ64 __BIT(20)
134 #define GR_GC_DEVSEL __BIT(19)
135 #define GR_GC_STOP __BIT(18)
136 #define GR_GC_TRDY __BIT(17)
137 #define GR_GC_M66EN __BIT(16)
138 #define GR_GC_PXIE_MASK __BITS(SIISATA_MAX_PORTS - 1, 0)
139 #define GR_GC_PXIE(n) __SHIFTIN(__BIT(n), GR_GC_PXIE_MASK)
140
141 /* GR_GIS bits */
142 #define GR_GIS_I2C __BIT(29)
143 #define GR_GIS_PXIS_MASK __BITS(SIISATA_MAX_PORTS - 1, 0)
144 #define GR_GIS_PXIS(n) __SHIFTIN(__BIT(n), GR_GIS_PXIS_MASK)
145
146
147 /* BAR 1 */
148
149 /* hmm, this could use a better name */
150 #define PR_PORT_SIZE 0x2000
151 #define PR_SLOT_SIZE 0x80
152 /* get the register by port number and offset */
153 #define PRO(p) (PR_PORT_SIZE * p)
154 #define PRX(p,r) (PRO(p) + r)
155 #define PRSX(p,s,o) (PRX(p, PR_SLOT_SIZE * s + o))
156
157 #define PRSO_RTC 0x04 /* recieved transfer count */
158 #define PRSO_FIS 0x08 /* base of FIS */
159
160 #define PRO_PCS 0x1000 /* (write) port control set */
161 #define PRO_PS PRO_PCS /* (read) port status */
162 #define PRO_PCC 0x1004 /* port control clear */
163 #define PRO_PIS 0x1008 /* port interrupt status */
164 #define PRO_PIES 0x1010 /* port interrupt enable set */
165 #define PRO_PIEC 0x1014 /* port interrupt enable clear */
166 #define PRO_32BAUA 0x101c /* 32-bit activation upper address */
167 #define PRO_PCEF 0x1020 /* port command execution fifo */
168 #define PRO_PCE 0x1024 /* port command error */
169 #define PRO_PFISC 0x1028 /* port FIS config */
170 #define PRO_PCIRFIFOT 0x102c /* pci request fifo threshhold */
171 #define PRO_P8B10BDEC 0x1040 /* port 8B/10B decode error counter */
172 #define PRO_PCRCEC 0x1044 /* port crc error count */
173 #define PRO_PHEC 0x1048 /* port handshake error count */
174 #define PRO_PPHYC 0x1050 /* phy config */
175 #define PRO_PSS 0x1800 /* port slot status */
176 /* technically this is a shadow of the CAR */
177 #define PRO_CAR 0x1c00
178
179 #define PRO_CARX(p,s) (PRX(p, PRO_CAR) + s * sizeof(uint64_t))
180
181 #define PRO_PCR 0x1e04 /* port context register */
182 #define PRO_SCONTROL 0x1f00 /* SControl */
183 #define PRO_SSTATUS 0x1f04 /* SStatus */
184 #define PRO_SERROR 0x1f08 /* SError */
185 #define PRO_SACTIVE 0x1f0c /* SActive */
186
187
188 /* Port Command Error */
189 #define PR_PCE_DEVICEERROR 1
190 #define PR_PCE_SDBERROR 2
191 #define PR_PCE_DATAFISERROR 3
192 #define PR_PCE_SENDFISERROR 4
193 #define PR_PCE_INCONSISTENTSTATE 5
194 #define PR_PCE_DIRECTIONERROR 6
195 #define PR_PCE_UNDERRUNERROR 7
196 #define PR_PCE_OVERRUNERROR 8
197 #define PR_PCE_LINKFIFOOVERRUN 9
198 #define PR_PCE_PACKETPROTOCOLERROR 11
199 #define PR_PCE_PLDSGTERRORBOUNDARY 16
200 #define PR_PCE_PLDSGTERRORTARGETABORT 17
201 #define PR_PCE_PLDSGTERRORMASTERABORT 18
202 #define PR_PCE_PLDSGTERRORPCIPERR 19
203 #define PR_PCE_PLDCMDERRORBOUNDARY 24
204 #define PR_PCE_PLDCMDERRORTARGETABORT 25
205 #define PR_PCE_PLDCMDERRORMASTERABORT 26
206 #define PR_PCE_PLDCMDERRORPCIPERR 27
207 #define PR_PCE_PSDERRORTARGETABORT 33
208 #define PR_PCE_PSDERRORMASTERABORT 34
209 #define PR_PCE_PSDERRORPCIPERR 35
210 #define PR_PCE_SENDSERVICEERROROR 36
211
212
213 #define PR_PIS_UNMASKED_SHIFT 16
214 #define PR_PIS_CMDCMPL __BIT(0) /* command completion */
215 #define PR_PIS_CMDERRR __BIT(1) /* command error */
216 #define PR_PIS_PRTRDY __BIT(2) /* port ready */
217 #define PR_PIS_PMCHNG __BIT(3) /* power management state change */
218 #define PR_PIS_PHYRDYCHG __BIT(4)
219 #define PR_PIS_COMWAKE __BIT(5)
220 #define PR_PIS_UNRECFIS __BIT(6)
221 #define PR_PIS_DEVEXCHG __BIT(7)
222 #define PR_PIS_8B10BDET __BIT(8)
223 #define PR_PIS_CRCET __BIT(9)
224 #define PR_PIS_HET __BIT(10)
225 #define PR_PIS_SDBN __BIT(11)
226
227 #define PR_PC_PORT_RESET __BIT(0)
228 #define PR_PC_DEVICE_RESET __BIT(1)
229 #define PR_PC_PORT_INITIALIZE __BIT(2)
230 #define PR_PC_INCOR __BIT(3)
231 #define PR_PC_LED_DISABLE __BIT(4)
232 #define PR_PC_PACKET_LENGTH __BIT(5)
233 #define PR_PC_RESUME __BIT(6)
234 #define PR_PC_TXBIST __BIT(7)
235 #define PR_PC_CONT_DISABLE __BIT(8)
236 #define PR_PC_SCRAMBLER_DISABLE __BIT(9)
237 #define PR_PC_32BA __BIT(10)
238 #define PR_PC_INTERLOCK_REJECT __BIT(11)
239 #define PR_PC_INTERLOCK_ACCEPT __BIT(12)
240 #define PR_PC_PMP_ENABLE __BIT(13)
241 #define PR_PC_AIA __BIT(14)
242 #define PR_PC_LED_ON __BIT(15)
243 #define PR_PC_OOB_BYPASS __BIT(25)
244 #define PR_PS_PORT_READY __BIT(31)
245
246 #define PR_PSS_ATTENTION __BIT(31)
247 #define PR_PSS_SLOT_MASK __BITS(30, 0)
248 #define PR_PXSS(n) __SHIFTIN(__BIT(n), PR_PSS_SLOT_MASK)
249