3w-xxxx.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /*
  2. 3w-xxxx.h -- 3ware Storage Controller device driver for Linux.
  3. Written By: Adam Radford <linuxraid@lsi.com>
  4. Modifications By: Joel Jacobson <linux@3ware.com>
  5. Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  6. Brad Strand <linux@3ware.com>
  7. Copyright (C) 1999-2010 3ware Inc.
  8. Kernel compatibility By: Andre Hedrick <andre@suse.com>
  9. Non-Copyright (C) 2000 Andre Hedrick <andre@suse.com>
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; version 2 of the License.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. NO WARRANTY
  18. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  19. CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  20. LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  21. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  22. solely responsible for determining the appropriateness of using and
  23. distributing the Program and assumes all risks associated with its
  24. exercise of rights under this Agreement, including but not limited to
  25. the risks and costs of program errors, damage to or loss of data,
  26. programs or equipment, and unavailability or interruption of operations.
  27. DISCLAIMER OF LIABILITY
  28. NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  29. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  31. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  32. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  33. USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  34. HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  35. You should have received a copy of the GNU General Public License
  36. along with this program; if not, write to the Free Software
  37. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  38. Bugs/Comments/Suggestions should be mailed to:
  39. linuxraid@lsi.com
  40. For more information, goto:
  41. http://www.lsi.com
  42. */
  43. #ifndef _3W_XXXX_H
  44. #define _3W_XXXX_H
  45. #include <linux/types.h>
  46. /* AEN strings */
  47. static char *tw_aen_string[] = {
  48. [0x000] = "INFO: AEN queue empty",
  49. [0x001] = "INFO: Soft reset occurred",
  50. [0x002] = "ERROR: Unit degraded: Unit #",
  51. [0x003] = "ERROR: Controller error",
  52. [0x004] = "ERROR: Rebuild failed: Unit #",
  53. [0x005] = "INFO: Rebuild complete: Unit #",
  54. [0x006] = "ERROR: Incomplete unit detected: Unit #",
  55. [0x007] = "INFO: Initialization complete: Unit #",
  56. [0x008] = "WARNING: Unclean shutdown detected: Unit #",
  57. [0x009] = "WARNING: ATA port timeout: Port #",
  58. [0x00A] = "ERROR: Drive error: Port #",
  59. [0x00B] = "INFO: Rebuild started: Unit #",
  60. [0x00C] = "INFO: Initialization started: Unit #",
  61. [0x00D] = "ERROR: Logical unit deleted: Unit #",
  62. [0x00F] = "WARNING: SMART threshold exceeded: Port #",
  63. [0x021] = "WARNING: ATA UDMA downgrade: Port #",
  64. [0x022] = "WARNING: ATA UDMA upgrade: Port #",
  65. [0x023] = "WARNING: Sector repair occurred: Port #",
  66. [0x024] = "ERROR: SBUF integrity check failure",
  67. [0x025] = "ERROR: Lost cached write: Port #",
  68. [0x026] = "ERROR: Drive ECC error detected: Port #",
  69. [0x027] = "ERROR: DCB checksum error: Port #",
  70. [0x028] = "ERROR: DCB unsupported version: Port #",
  71. [0x029] = "INFO: Verify started: Unit #",
  72. [0x02A] = "ERROR: Verify failed: Port #",
  73. [0x02B] = "INFO: Verify complete: Unit #",
  74. [0x02C] = "WARNING: Overwrote bad sector during rebuild: Port #",
  75. [0x02D] = "ERROR: Encountered bad sector during rebuild: Port #",
  76. [0x02E] = "ERROR: Replacement drive is too small: Port #",
  77. [0x02F] = "WARNING: Verify error: Unit not previously initialized: Unit #",
  78. [0x030] = "ERROR: Drive not supported: Port #"
  79. };
  80. /*
  81. Sense key lookup table
  82. Format: ESDC/flags,SenseKey,AdditionalSenseCode,AdditionalSenseCodeQualifier
  83. */
  84. static unsigned char tw_sense_table[][4] =
  85. {
  86. /* Codes for newer firmware */
  87. // ATA Error SCSI Error
  88. {0x01, 0x03, 0x13, 0x00}, // Address mark not found Address mark not found for data field
  89. {0x04, 0x0b, 0x00, 0x00}, // Aborted command Aborted command
  90. {0x10, 0x0b, 0x14, 0x00}, // ID not found Recorded entity not found
  91. {0x40, 0x03, 0x11, 0x00}, // Uncorrectable ECC error Unrecovered read error
  92. {0x61, 0x04, 0x00, 0x00}, // Device fault Hardware error
  93. {0x84, 0x0b, 0x47, 0x00}, // Data CRC error SCSI parity error
  94. {0xd0, 0x0b, 0x00, 0x00}, // Device busy Aborted command
  95. {0xd1, 0x0b, 0x00, 0x00}, // Device busy Aborted command
  96. {0x37, 0x02, 0x04, 0x00}, // Unit offline Not ready
  97. {0x09, 0x02, 0x04, 0x00}, // Unrecovered disk error Not ready
  98. /* Codes for older firmware */
  99. // 3ware Error SCSI Error
  100. {0x51, 0x0b, 0x00, 0x00} // Unspecified Aborted command
  101. };
  102. /* Control register bit definitions */
  103. #define TW_CONTROL_CLEAR_HOST_INTERRUPT 0x00080000
  104. #define TW_CONTROL_CLEAR_ATTENTION_INTERRUPT 0x00040000
  105. #define TW_CONTROL_MASK_COMMAND_INTERRUPT 0x00020000
  106. #define TW_CONTROL_MASK_RESPONSE_INTERRUPT 0x00010000
  107. #define TW_CONTROL_UNMASK_COMMAND_INTERRUPT 0x00008000
  108. #define TW_CONTROL_UNMASK_RESPONSE_INTERRUPT 0x00004000
  109. #define TW_CONTROL_CLEAR_ERROR_STATUS 0x00000200
  110. #define TW_CONTROL_ISSUE_SOFT_RESET 0x00000100
  111. #define TW_CONTROL_ENABLE_INTERRUPTS 0x00000080
  112. #define TW_CONTROL_DISABLE_INTERRUPTS 0x00000040
  113. #define TW_CONTROL_ISSUE_HOST_INTERRUPT 0x00000020
  114. #define TW_CONTROL_CLEAR_PARITY_ERROR 0x00800000
  115. #define TW_CONTROL_CLEAR_QUEUE_ERROR 0x00400000
  116. #define TW_CONTROL_CLEAR_PCI_ABORT 0x00100000
  117. #define TW_CONTROL_CLEAR_SBUF_WRITE_ERROR 0x00000008
  118. /* Status register bit definitions */
  119. #define TW_STATUS_MAJOR_VERSION_MASK 0xF0000000
  120. #define TW_STATUS_MINOR_VERSION_MASK 0x0F000000
  121. #define TW_STATUS_PCI_PARITY_ERROR 0x00800000
  122. #define TW_STATUS_QUEUE_ERROR 0x00400000
  123. #define TW_STATUS_MICROCONTROLLER_ERROR 0x00200000
  124. #define TW_STATUS_PCI_ABORT 0x00100000
  125. #define TW_STATUS_HOST_INTERRUPT 0x00080000
  126. #define TW_STATUS_ATTENTION_INTERRUPT 0x00040000
  127. #define TW_STATUS_COMMAND_INTERRUPT 0x00020000
  128. #define TW_STATUS_RESPONSE_INTERRUPT 0x00010000
  129. #define TW_STATUS_COMMAND_QUEUE_FULL 0x00008000
  130. #define TW_STATUS_RESPONSE_QUEUE_EMPTY 0x00004000
  131. #define TW_STATUS_MICROCONTROLLER_READY 0x00002000
  132. #define TW_STATUS_COMMAND_QUEUE_EMPTY 0x00001000
  133. #define TW_STATUS_ALL_INTERRUPTS 0x000F0000
  134. #define TW_STATUS_CLEARABLE_BITS 0x00D00000
  135. #define TW_STATUS_EXPECTED_BITS 0x00002000
  136. #define TW_STATUS_UNEXPECTED_BITS 0x00F00008
  137. #define TW_STATUS_SBUF_WRITE_ERROR 0x00000008
  138. #define TW_STATUS_VALID_INTERRUPT 0x00DF0008
  139. /* RESPONSE QUEUE BIT DEFINITIONS */
  140. #define TW_RESPONSE_ID_MASK 0x00000FF0
  141. /* PCI related defines */
  142. #define TW_IO_ADDRESS_RANGE 0x10
  143. #define TW_DEVICE_NAME "3ware Storage Controller"
  144. #define TW_VENDOR_ID (0x13C1) /* 3ware */
  145. #define TW_DEVICE_ID (0x1000) /* Storage Controller */
  146. #define TW_DEVICE_ID2 (0x1001) /* 7000 series controller */
  147. #define TW_NUMDEVICES 2
  148. #define TW_PCI_CLEAR_PARITY_ERRORS 0xc100
  149. #define TW_PCI_CLEAR_PCI_ABORT 0x2000
  150. /* Command packet opcodes */
  151. #define TW_OP_NOP 0x0
  152. #define TW_OP_INIT_CONNECTION 0x1
  153. #define TW_OP_READ 0x2
  154. #define TW_OP_WRITE 0x3
  155. #define TW_OP_VERIFY 0x4
  156. #define TW_OP_GET_PARAM 0x12
  157. #define TW_OP_SET_PARAM 0x13
  158. #define TW_OP_SECTOR_INFO 0x1a
  159. #define TW_OP_AEN_LISTEN 0x1c
  160. #define TW_OP_FLUSH_CACHE 0x0e
  161. #define TW_CMD_PACKET 0x1d
  162. #define TW_CMD_PACKET_WITH_DATA 0x1f
  163. /* Asynchronous Event Notification (AEN) Codes */
  164. #define TW_AEN_QUEUE_EMPTY 0x0000
  165. #define TW_AEN_SOFT_RESET 0x0001
  166. #define TW_AEN_DEGRADED_MIRROR 0x0002
  167. #define TW_AEN_CONTROLLER_ERROR 0x0003
  168. #define TW_AEN_REBUILD_FAIL 0x0004
  169. #define TW_AEN_REBUILD_DONE 0x0005
  170. #define TW_AEN_QUEUE_FULL 0x00ff
  171. #define TW_AEN_TABLE_UNDEFINED 0x15
  172. #define TW_AEN_APORT_TIMEOUT 0x0009
  173. #define TW_AEN_DRIVE_ERROR 0x000A
  174. #define TW_AEN_SMART_FAIL 0x000F
  175. #define TW_AEN_SBUF_FAIL 0x0024
  176. /* Misc defines */
  177. #define TW_ALIGNMENT_6000 64 /* 64 bytes */
  178. #define TW_ALIGNMENT_7000 4 /* 4 bytes */
  179. #define TW_MAX_UNITS 16
  180. #define TW_COMMAND_ALIGNMENT_MASK 0x1ff
  181. #define TW_INIT_MESSAGE_CREDITS 0x100
  182. #define TW_INIT_COMMAND_PACKET_SIZE 0x3
  183. #define TW_POLL_MAX_RETRIES 20000
  184. #define TW_MAX_SGL_LENGTH 62
  185. #define TW_ATA_PASS_SGL_MAX 60
  186. #define TW_Q_LENGTH 256
  187. #define TW_Q_START 0
  188. #define TW_MAX_SLOT 32
  189. #define TW_MAX_PCI_BUSES 255
  190. #define TW_MAX_RESET_TRIES 3
  191. #define TW_UNIT_INFORMATION_TABLE_BASE 0x300
  192. #define TW_MAX_CMDS_PER_LUN 254 /* 254 for io, 1 for
  193. chrdev ioctl, one for
  194. internal aen post */
  195. #define TW_BLOCK_SIZE 0x200 /* 512-byte blocks */
  196. #define TW_IOCTL 0x80
  197. #define TW_UNIT_ONLINE 1
  198. #define TW_IN_INTR 1
  199. #define TW_IN_RESET 2
  200. #define TW_IN_CHRDEV_IOCTL 3
  201. #define TW_MAX_SECTORS 256
  202. #define TW_MAX_IOCTL_SECTORS 512
  203. #define TW_AEN_WAIT_TIME 1000
  204. #define TW_IOCTL_WAIT_TIME (1 * HZ) /* 1 second */
  205. #define TW_ISR_DONT_COMPLETE 2
  206. #define TW_ISR_DONT_RESULT 3
  207. #define TW_IOCTL_TIMEOUT 25 /* 25 seconds */
  208. #define TW_IOCTL_CHRDEV_TIMEOUT 60 /* 60 seconds */
  209. #define TW_IOCTL_CHRDEV_FREE -1
  210. #define TW_DMA_MASK DMA_BIT_MASK(32)
  211. #define TW_MAX_CDB_LEN 16
  212. /* Bitmask macros to eliminate bitfields */
  213. /* opcode: 5, sgloffset: 3 */
  214. #define TW_OPSGL_IN(x,y) ((x << 5) | (y & 0x1f))
  215. #define TW_SGL_OUT(x) ((x >> 5) & 0x7)
  216. /* reserved_1: 4, response_id: 8, reserved_2: 20 */
  217. #define TW_RESID_OUT(x) ((x >> 4) & 0xff)
  218. /* unit: 4, host_id: 4 */
  219. #define TW_UNITHOST_IN(x,y) ((x << 4) | ( y & 0xf))
  220. #define TW_UNIT_OUT(x) (x & 0xf)
  221. /* Macros */
  222. #define TW_CONTROL_REG_ADDR(x) (x->base_addr)
  223. #define TW_STATUS_REG_ADDR(x) (x->base_addr + 0x4)
  224. #define TW_COMMAND_QUEUE_REG_ADDR(x) (x->base_addr + 0x8)
  225. #define TW_RESPONSE_QUEUE_REG_ADDR(x) (x->base_addr + 0xC)
  226. #define TW_CLEAR_ALL_INTERRUPTS(x) (outl(TW_STATUS_VALID_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
  227. #define TW_CLEAR_ATTENTION_INTERRUPT(x) (outl(TW_CONTROL_CLEAR_ATTENTION_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
  228. #define TW_CLEAR_HOST_INTERRUPT(x) (outl(TW_CONTROL_CLEAR_HOST_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
  229. #define TW_DISABLE_INTERRUPTS(x) (outl(TW_CONTROL_DISABLE_INTERRUPTS, TW_CONTROL_REG_ADDR(x)))
  230. #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)))
  231. #define TW_MASK_COMMAND_INTERRUPT(x) (outl(TW_CONTROL_MASK_COMMAND_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
  232. #define TW_UNMASK_COMMAND_INTERRUPT(x) (outl(TW_CONTROL_UNMASK_COMMAND_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
  233. #define TW_SOFT_RESET(x) (outl(TW_CONTROL_ISSUE_SOFT_RESET | \
  234. TW_CONTROL_CLEAR_HOST_INTERRUPT | \
  235. TW_CONTROL_CLEAR_ATTENTION_INTERRUPT | \
  236. TW_CONTROL_MASK_COMMAND_INTERRUPT | \
  237. TW_CONTROL_MASK_RESPONSE_INTERRUPT | \
  238. TW_CONTROL_CLEAR_ERROR_STATUS | \
  239. TW_CONTROL_DISABLE_INTERRUPTS, TW_CONTROL_REG_ADDR(x)))
  240. #define TW_STATUS_ERRORS(x) \
  241. (((x & TW_STATUS_PCI_ABORT) || \
  242. (x & TW_STATUS_PCI_PARITY_ERROR) || \
  243. (x & TW_STATUS_QUEUE_ERROR) || \
  244. (x & TW_STATUS_MICROCONTROLLER_ERROR)) && \
  245. (x & TW_STATUS_MICROCONTROLLER_READY))
  246. #ifdef TW_DEBUG
  247. #define dprintk(msg...) printk(msg)
  248. #else
  249. #define dprintk(msg...) do { } while(0)
  250. #endif
  251. #pragma pack(1)
  252. /* Scatter Gather List Entry */
  253. typedef struct TAG_TW_SG_Entry {
  254. u32 address;
  255. u32 length;
  256. } TW_SG_Entry;
  257. typedef unsigned char TW_Sector[512];
  258. /* Command Packet */
  259. typedef struct TW_Command {
  260. unsigned char opcode__sgloffset;
  261. unsigned char size;
  262. unsigned char request_id;
  263. unsigned char unit__hostid;
  264. /* Second DWORD */
  265. unsigned char status;
  266. unsigned char flags;
  267. union {
  268. unsigned short block_count;
  269. unsigned short parameter_count;
  270. unsigned short message_credits;
  271. } byte6;
  272. union {
  273. struct {
  274. u32 lba;
  275. TW_SG_Entry sgl[TW_MAX_SGL_LENGTH];
  276. u32 padding; /* pad to 512 bytes */
  277. } io;
  278. struct {
  279. TW_SG_Entry sgl[TW_MAX_SGL_LENGTH];
  280. u32 padding[2];
  281. } param;
  282. struct {
  283. u32 response_queue_pointer;
  284. u32 padding[125];
  285. } init_connection;
  286. struct {
  287. char version[504];
  288. } ioctl_miniport_version;
  289. } byte8;
  290. } TW_Command;
  291. #pragma pack()
  292. typedef struct TAG_TW_Ioctl {
  293. unsigned char opcode;
  294. unsigned short table_id;
  295. unsigned char parameter_id;
  296. unsigned char parameter_size_bytes;
  297. unsigned char unit_index;
  298. unsigned char data[1];
  299. } TW_Ioctl;
  300. #pragma pack(1)
  301. /* Structure for new chardev ioctls */
  302. typedef struct TAG_TW_New_Ioctl {
  303. unsigned int data_buffer_length;
  304. unsigned char padding [508];
  305. TW_Command firmware_command;
  306. char data_buffer[1];
  307. } TW_New_Ioctl;
  308. /* GetParam descriptor */
  309. typedef struct {
  310. unsigned short table_id;
  311. unsigned char parameter_id;
  312. unsigned char parameter_size_bytes;
  313. unsigned char data[1];
  314. } TW_Param, *PTW_Param;
  315. /* Response queue */
  316. typedef union TAG_TW_Response_Queue {
  317. u32 response_id;
  318. u32 value;
  319. } TW_Response_Queue;
  320. typedef int TW_Cmd_State;
  321. #define TW_S_INITIAL 0x1 /* Initial state */
  322. #define TW_S_STARTED 0x2 /* Id in use */
  323. #define TW_S_POSTED 0x4 /* Posted to the controller */
  324. #define TW_S_PENDING 0x8 /* Waiting to be posted in isr */
  325. #define TW_S_COMPLETED 0x10 /* Completed by isr */
  326. #define TW_S_FINISHED 0x20 /* I/O completely done */
  327. #define TW_START_MASK (TW_S_STARTED | TW_S_POSTED | TW_S_PENDING | TW_S_COMPLETED)
  328. /* Command header for ATA pass-thru */
  329. typedef struct TAG_TW_Passthru
  330. {
  331. unsigned char opcode__sgloffset;
  332. unsigned char size;
  333. unsigned char request_id;
  334. unsigned char aport__hostid;
  335. unsigned char status;
  336. unsigned char flags;
  337. unsigned short param;
  338. unsigned short features;
  339. unsigned short sector_count;
  340. unsigned short sector_num;
  341. unsigned short cylinder_lo;
  342. unsigned short cylinder_hi;
  343. unsigned char drive_head;
  344. unsigned char command;
  345. TW_SG_Entry sg_list[TW_ATA_PASS_SGL_MAX];
  346. unsigned char padding[12];
  347. } TW_Passthru;
  348. #pragma pack()
  349. typedef struct TAG_TW_Device_Extension {
  350. u32 base_addr;
  351. unsigned long *alignment_virtual_address[TW_Q_LENGTH];
  352. unsigned long alignment_physical_address[TW_Q_LENGTH];
  353. int is_unit_present[TW_MAX_UNITS];
  354. unsigned long *command_packet_virtual_address[TW_Q_LENGTH];
  355. unsigned long command_packet_physical_address[TW_Q_LENGTH];
  356. struct pci_dev *tw_pci_dev;
  357. struct scsi_cmnd *srb[TW_Q_LENGTH];
  358. unsigned char free_queue[TW_Q_LENGTH];
  359. unsigned char free_head;
  360. unsigned char free_tail;
  361. unsigned char pending_queue[TW_Q_LENGTH];
  362. unsigned char pending_head;
  363. unsigned char pending_tail;
  364. TW_Cmd_State state[TW_Q_LENGTH];
  365. u32 posted_request_count;
  366. u32 max_posted_request_count;
  367. u32 request_count_marked_pending;
  368. u32 pending_request_count;
  369. u32 max_pending_request_count;
  370. u32 max_sgl_entries;
  371. u32 sgl_entries;
  372. u32 num_resets;
  373. u32 sector_count;
  374. u32 max_sector_count;
  375. u32 aen_count;
  376. struct Scsi_Host *host;
  377. struct mutex ioctl_lock;
  378. unsigned short aen_queue[TW_Q_LENGTH];
  379. unsigned char aen_head;
  380. unsigned char aen_tail;
  381. volatile long flags; /* long req'd for set_bit --RR */
  382. int reset_print;
  383. volatile int chrdev_request_id;
  384. wait_queue_head_t ioctl_wqueue;
  385. } TW_Device_Extension;
  386. #endif /* _3W_XXXX_H */