57 #include <linux/types.h>
60 static char *tw_aen_string[] = {
61 [0x000] =
"INFO: AEN queue empty",
62 [0x001] =
"INFO: Soft reset occurred",
63 [0x002] =
"ERROR: Unit degraded: Unit #",
64 [0x003] =
"ERROR: Controller error",
65 [0x004] =
"ERROR: Rebuild failed: Unit #",
66 [0x005] =
"INFO: Rebuild complete: Unit #",
67 [0x006] =
"ERROR: Incomplete unit detected: Unit #",
68 [0x007] =
"INFO: Initialization complete: Unit #",
69 [0x008] =
"WARNING: Unclean shutdown detected: Unit #",
70 [0x009] =
"WARNING: ATA port timeout: Port #",
71 [0x00A] =
"ERROR: Drive error: Port #",
72 [0x00B] =
"INFO: Rebuild started: Unit #",
73 [0x00C] =
"INFO: Initialization started: Unit #",
74 [0x00D] =
"ERROR: Logical unit deleted: Unit #",
75 [0x00F] =
"WARNING: SMART threshold exceeded: Port #",
76 [0x021] =
"WARNING: ATA UDMA downgrade: Port #",
77 [0x022] =
"WARNING: ATA UDMA upgrade: Port #",
78 [0x023] =
"WARNING: Sector repair occurred: Port #",
79 [0x024] =
"ERROR: SBUF integrity check failure",
80 [0x025] =
"ERROR: Lost cached write: Port #",
81 [0x026] =
"ERROR: Drive ECC error detected: Port #",
82 [0x027] =
"ERROR: DCB checksum error: Port #",
83 [0x028] =
"ERROR: DCB unsupported version: Port #",
84 [0x029] =
"INFO: Verify started: Unit #",
85 [0x02A] =
"ERROR: Verify failed: Port #",
86 [0x02B] =
"INFO: Verify complete: Unit #",
87 [0x02C] =
"WARNING: Overwrote bad sector during rebuild: Port #",
88 [0x02D] =
"ERROR: Encountered bad sector during rebuild: Port #",
89 [0x02E] =
"ERROR: Replacement drive is too small: Port #",
90 [0x02F] =
"WARNING: Verify error: Unit not previously initialized: Unit #",
91 [0x030] =
"ERROR: Drive not supported: Port #"
98 static unsigned char tw_sense_table[][4] =
102 {0x01, 0x03, 0x13, 0x00},
103 {0x04, 0x0b, 0x00, 0x00},
104 {0x10, 0x0b, 0x14, 0x00},
105 {0x40, 0x03, 0x11, 0x00},
106 {0x61, 0x04, 0x00, 0x00},
107 {0x84, 0x0b, 0x47, 0x00},
108 {0xd0, 0x0b, 0x00, 0x00},
109 {0xd1, 0x0b, 0x00, 0x00},
110 {0x37, 0x02, 0x04, 0x00},
111 {0x09, 0x02, 0x04, 0x00},
115 {0x51, 0x0b, 0x00, 0x00}
119 #define TW_CONTROL_CLEAR_HOST_INTERRUPT 0x00080000
120 #define TW_CONTROL_CLEAR_ATTENTION_INTERRUPT 0x00040000
121 #define TW_CONTROL_MASK_COMMAND_INTERRUPT 0x00020000
122 #define TW_CONTROL_MASK_RESPONSE_INTERRUPT 0x00010000
123 #define TW_CONTROL_UNMASK_COMMAND_INTERRUPT 0x00008000
124 #define TW_CONTROL_UNMASK_RESPONSE_INTERRUPT 0x00004000
125 #define TW_CONTROL_CLEAR_ERROR_STATUS 0x00000200
126 #define TW_CONTROL_ISSUE_SOFT_RESET 0x00000100
127 #define TW_CONTROL_ENABLE_INTERRUPTS 0x00000080
128 #define TW_CONTROL_DISABLE_INTERRUPTS 0x00000040
129 #define TW_CONTROL_ISSUE_HOST_INTERRUPT 0x00000020
130 #define TW_CONTROL_CLEAR_PARITY_ERROR 0x00800000
131 #define TW_CONTROL_CLEAR_QUEUE_ERROR 0x00400000
132 #define TW_CONTROL_CLEAR_PCI_ABORT 0x00100000
133 #define TW_CONTROL_CLEAR_SBUF_WRITE_ERROR 0x00000008
136 #define TW_STATUS_MAJOR_VERSION_MASK 0xF0000000
137 #define TW_STATUS_MINOR_VERSION_MASK 0x0F000000
138 #define TW_STATUS_PCI_PARITY_ERROR 0x00800000
139 #define TW_STATUS_QUEUE_ERROR 0x00400000
140 #define TW_STATUS_MICROCONTROLLER_ERROR 0x00200000
141 #define TW_STATUS_PCI_ABORT 0x00100000
142 #define TW_STATUS_HOST_INTERRUPT 0x00080000
143 #define TW_STATUS_ATTENTION_INTERRUPT 0x00040000
144 #define TW_STATUS_COMMAND_INTERRUPT 0x00020000
145 #define TW_STATUS_RESPONSE_INTERRUPT 0x00010000
146 #define TW_STATUS_COMMAND_QUEUE_FULL 0x00008000
147 #define TW_STATUS_RESPONSE_QUEUE_EMPTY 0x00004000
148 #define TW_STATUS_MICROCONTROLLER_READY 0x00002000
149 #define TW_STATUS_COMMAND_QUEUE_EMPTY 0x00001000
150 #define TW_STATUS_ALL_INTERRUPTS 0x000F0000
151 #define TW_STATUS_CLEARABLE_BITS 0x00D00000
152 #define TW_STATUS_EXPECTED_BITS 0x00002000
153 #define TW_STATUS_UNEXPECTED_BITS 0x00F00008
154 #define TW_STATUS_SBUF_WRITE_ERROR 0x00000008
155 #define TW_STATUS_VALID_INTERRUPT 0x00DF0008
158 #define TW_RESPONSE_ID_MASK 0x00000FF0
161 #define TW_IO_ADDRESS_RANGE 0x10
162 #define TW_DEVICE_NAME "3ware Storage Controller"
163 #define TW_VENDOR_ID (0x13C1)
164 #define TW_DEVICE_ID (0x1000)
165 #define TW_DEVICE_ID2 (0x1001)
166 #define TW_NUMDEVICES 2
167 #define TW_PCI_CLEAR_PARITY_ERRORS 0xc100
168 #define TW_PCI_CLEAR_PCI_ABORT 0x2000
171 #define TW_OP_NOP 0x0
172 #define TW_OP_INIT_CONNECTION 0x1
173 #define TW_OP_READ 0x2
174 #define TW_OP_WRITE 0x3
175 #define TW_OP_VERIFY 0x4
176 #define TW_OP_GET_PARAM 0x12
177 #define TW_OP_SET_PARAM 0x13
178 #define TW_OP_SECTOR_INFO 0x1a
179 #define TW_OP_AEN_LISTEN 0x1c
180 #define TW_OP_FLUSH_CACHE 0x0e
181 #define TW_CMD_PACKET 0x1d
182 #define TW_CMD_PACKET_WITH_DATA 0x1f
185 #define TW_AEN_QUEUE_EMPTY 0x0000
186 #define TW_AEN_SOFT_RESET 0x0001
187 #define TW_AEN_DEGRADED_MIRROR 0x0002
188 #define TW_AEN_CONTROLLER_ERROR 0x0003
189 #define TW_AEN_REBUILD_FAIL 0x0004
190 #define TW_AEN_REBUILD_DONE 0x0005
191 #define TW_AEN_QUEUE_FULL 0x00ff
192 #define TW_AEN_TABLE_UNDEFINED 0x15
193 #define TW_AEN_APORT_TIMEOUT 0x0009
194 #define TW_AEN_DRIVE_ERROR 0x000A
195 #define TW_AEN_SMART_FAIL 0x000F
196 #define TW_AEN_SBUF_FAIL 0x0024
199 #define TW_PHASE_INITIAL 0
200 #define TW_PHASE_SINGLE 1
201 #define TW_PHASE_SGLIST 2
204 #define TW_ALIGNMENT_6000 64
205 #define TW_ALIGNMENT_7000 4
206 #define TW_MAX_UNITS 16
207 #define TW_COMMAND_ALIGNMENT_MASK 0x1ff
208 #define TW_INIT_MESSAGE_CREDITS 0x100
209 #define TW_INIT_COMMAND_PACKET_SIZE 0x3
210 #define TW_POLL_MAX_RETRIES 20000
211 #define TW_MAX_SGL_LENGTH 62
212 #define TW_ATA_PASS_SGL_MAX 60
213 #define TW_Q_LENGTH 256
215 #define TW_MAX_SLOT 32
216 #define TW_MAX_PCI_BUSES 255
217 #define TW_MAX_RESET_TRIES 3
218 #define TW_UNIT_INFORMATION_TABLE_BASE 0x300
219 #define TW_MAX_CMDS_PER_LUN 254
222 #define TW_BLOCK_SIZE 0x200
223 #define TW_IOCTL 0x80
224 #define TW_UNIT_ONLINE 1
226 #define TW_IN_RESET 2
227 #define TW_IN_CHRDEV_IOCTL 3
228 #define TW_MAX_SECTORS 256
229 #define TW_MAX_IOCTL_SECTORS 512
230 #define TW_AEN_WAIT_TIME 1000
231 #define TW_IOCTL_WAIT_TIME (1 * HZ)
232 #define TW_ISR_DONT_COMPLETE 2
233 #define TW_ISR_DONT_RESULT 3
234 #define TW_IOCTL_TIMEOUT 25
235 #define TW_IOCTL_CHRDEV_TIMEOUT 60
236 #define TW_IOCTL_CHRDEV_FREE -1
237 #define TW_DMA_MASK DMA_BIT_MASK(32)
238 #define TW_MAX_CDB_LEN 16
243 #define TW_OPSGL_IN(x,y) ((x << 5) | (y & 0x1f))
244 #define TW_SGL_OUT(x) ((x >> 5) & 0x7)
247 #define TW_RESID_OUT(x) ((x >> 4) & 0xff)
250 #define TW_UNITHOST_IN(x,y) ((x << 4) | ( y & 0xf))
251 #define TW_UNIT_OUT(x) (x & 0xf)
254 #define TW_CONTROL_REG_ADDR(x) (x->base_addr)
255 #define TW_STATUS_REG_ADDR(x) (x->base_addr + 0x4)
256 #define TW_COMMAND_QUEUE_REG_ADDR(x) (x->base_addr + 0x8)
257 #define TW_RESPONSE_QUEUE_REG_ADDR(x) (x->base_addr + 0xC)
258 #define TW_CLEAR_ALL_INTERRUPTS(x) (outl(TW_STATUS_VALID_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
259 #define TW_CLEAR_ATTENTION_INTERRUPT(x) (outl(TW_CONTROL_CLEAR_ATTENTION_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
260 #define TW_CLEAR_HOST_INTERRUPT(x) (outl(TW_CONTROL_CLEAR_HOST_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
261 #define TW_DISABLE_INTERRUPTS(x) (outl(TW_CONTROL_DISABLE_INTERRUPTS, TW_CONTROL_REG_ADDR(x)))
262 #define TW_ENABLE_AND_CLEAR_INTERRUPTS(x) (outl(TW_CONTROL_CLEAR_ATTENTION_INTERRUPT | TW_CONTROL_UNMASK_RESPONSE_INTERRUPT | TW_CONTROL_ENABLE_INTERRUPTS, TW_CONTROL_REG_ADDR(x)))
263 #define TW_MASK_COMMAND_INTERRUPT(x) (outl(TW_CONTROL_MASK_COMMAND_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
264 #define TW_UNMASK_COMMAND_INTERRUPT(x) (outl(TW_CONTROL_UNMASK_COMMAND_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
265 #define TW_SOFT_RESET(x) (outl(TW_CONTROL_ISSUE_SOFT_RESET | \
266 TW_CONTROL_CLEAR_HOST_INTERRUPT | \
267 TW_CONTROL_CLEAR_ATTENTION_INTERRUPT | \
268 TW_CONTROL_MASK_COMMAND_INTERRUPT | \
269 TW_CONTROL_MASK_RESPONSE_INTERRUPT | \
270 TW_CONTROL_CLEAR_ERROR_STATUS | \
271 TW_CONTROL_DISABLE_INTERRUPTS, TW_CONTROL_REG_ADDR(x)))
272 #define TW_STATUS_ERRORS(x) \
273 (((x & TW_STATUS_PCI_ABORT) || \
274 (x & TW_STATUS_PCI_PARITY_ERROR) || \
275 (x & TW_STATUS_QUEUE_ERROR) || \
276 (x & TW_STATUS_MICROCONTROLLER_ERROR)) && \
277 (x & TW_STATUS_MICROCONTROLLER_READY))
280 #define dprintk(msg...) printk(msg)
282 #define dprintk(msg...) do { } while(0)
337 unsigned char data[1];
352 unsigned short table_id;
353 unsigned char parameter_id;
354 unsigned char parameter_size_bytes;
355 unsigned char data[1];
366 #define TW_S_INITIAL 0x1
367 #define TW_S_STARTED 0x2
368 #define TW_S_POSTED 0x4
369 #define TW_S_PENDING 0x8
370 #define TW_S_COMPLETED 0x10
371 #define TW_S_FINISHED 0x20
372 #define TW_START_MASK (TW_S_STARTED | TW_S_POSTED | TW_S_PENDING | TW_S_COMPLETED)