3w-sas.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /*
  2. 3w-sas.h -- LSI 3ware SAS/SATA-RAID Controller device driver for Linux.
  3. Written By: Adam Radford <aradford@gmail.com>
  4. Copyright (C) 2009 LSI Corporation.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; version 2 of the License.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. NO WARRANTY
  13. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  14. CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  15. LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  16. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  17. solely responsible for determining the appropriateness of using and
  18. distributing the Program and assumes all risks associated with its
  19. exercise of rights under this Agreement, including but not limited to
  20. the risks and costs of program errors, damage to or loss of data,
  21. programs or equipment, and unavailability or interruption of operations.
  22. DISCLAIMER OF LIABILITY
  23. NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  24. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  26. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  27. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  28. USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  29. HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  30. You should have received a copy of the GNU General Public License
  31. along with this program; if not, write to the Free Software
  32. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  33. Bugs/Comments/Suggestions should be mailed to:
  34. aradford@gmail.com
  35. */
  36. #ifndef _3W_SAS_H
  37. #define _3W_SAS_H
  38. /* AEN severity table */
  39. static char *twl_aen_severity_table[] =
  40. {
  41. "None", "ERROR", "WARNING", "INFO", "DEBUG", NULL
  42. };
  43. /* Liberator register offsets */
  44. #define TWL_STATUS 0x0 /* Status */
  45. #define TWL_HIBDB 0x20 /* Inbound doorbell */
  46. #define TWL_HISTAT 0x30 /* Host interrupt status */
  47. #define TWL_HIMASK 0x34 /* Host interrupt mask */
  48. #define TWL_HOBDB 0x9C /* Outbound doorbell */
  49. #define TWL_HOBDBC 0xA0 /* Outbound doorbell clear */
  50. #define TWL_SCRPD3 0xBC /* Scratchpad */
  51. #define TWL_HIBQPL 0xC0 /* Host inbound Q low */
  52. #define TWL_HIBQPH 0xC4 /* Host inbound Q high */
  53. #define TWL_HOBQPL 0xC8 /* Host outbound Q low */
  54. #define TWL_HOBQPH 0xCC /* Host outbound Q high */
  55. #define TWL_HISTATUS_VALID_INTERRUPT 0xC
  56. #define TWL_HISTATUS_ATTENTION_INTERRUPT 0x4
  57. #define TWL_HISTATUS_RESPONSE_INTERRUPT 0x8
  58. #define TWL_STATUS_OVERRUN_SUBMIT 0x2000
  59. #define TWL_ISSUE_SOFT_RESET 0x100
  60. #define TWL_CONTROLLER_READY 0x2000
  61. #define TWL_DOORBELL_CONTROLLER_ERROR 0x200000
  62. #define TWL_DOORBELL_ATTENTION_INTERRUPT 0x40000
  63. #define TWL_PULL_MODE 0x1
  64. /* Command packet opcodes used by the driver */
  65. #define TW_OP_INIT_CONNECTION 0x1
  66. #define TW_OP_GET_PARAM 0x12
  67. #define TW_OP_SET_PARAM 0x13
  68. #define TW_OP_EXECUTE_SCSI 0x10
  69. /* Asynchronous Event Notification (AEN) codes used by the driver */
  70. #define TW_AEN_QUEUE_EMPTY 0x0000
  71. #define TW_AEN_SOFT_RESET 0x0001
  72. #define TW_AEN_SYNC_TIME_WITH_HOST 0x031
  73. #define TW_AEN_SEVERITY_ERROR 0x1
  74. #define TW_AEN_SEVERITY_DEBUG 0x4
  75. #define TW_AEN_NOT_RETRIEVED 0x1
  76. /* Command state defines */
  77. #define TW_S_INITIAL 0x1 /* Initial state */
  78. #define TW_S_STARTED 0x2 /* Id in use */
  79. #define TW_S_POSTED 0x4 /* Posted to the controller */
  80. #define TW_S_COMPLETED 0x8 /* Completed by isr */
  81. #define TW_S_FINISHED 0x10 /* I/O completely done */
  82. /* Compatibility defines */
  83. #define TW_9750_ARCH_ID 10
  84. #define TW_CURRENT_DRIVER_SRL 40
  85. #define TW_CURRENT_DRIVER_BUILD 0
  86. #define TW_CURRENT_DRIVER_BRANCH 0
  87. /* Misc defines */
  88. #define TW_SECTOR_SIZE 512
  89. #define TW_MAX_UNITS 32
  90. #define TW_INIT_MESSAGE_CREDITS 0x100
  91. #define TW_INIT_COMMAND_PACKET_SIZE 0x3
  92. #define TW_INIT_COMMAND_PACKET_SIZE_EXTENDED 0x6
  93. #define TW_EXTENDED_INIT_CONNECT 0x2
  94. #define TW_BASE_FW_SRL 24
  95. #define TW_BASE_FW_BRANCH 0
  96. #define TW_BASE_FW_BUILD 1
  97. #define TW_Q_LENGTH 256
  98. #define TW_Q_START 0
  99. #define TW_MAX_SLOT 32
  100. #define TW_MAX_RESET_TRIES 2
  101. #define TW_MAX_CMDS_PER_LUN 254
  102. #define TW_MAX_AEN_DRAIN 255
  103. #define TW_IN_RESET 2
  104. #define TW_USING_MSI 3
  105. #define TW_IN_ATTENTION_LOOP 4
  106. #define TW_MAX_SECTORS 256
  107. #define TW_MAX_CDB_LEN 16
  108. #define TW_IOCTL_CHRDEV_TIMEOUT 60 /* 60 seconds */
  109. #define TW_IOCTL_CHRDEV_FREE -1
  110. #define TW_COMMAND_OFFSET 128 /* 128 bytes */
  111. #define TW_VERSION_TABLE 0x0402
  112. #define TW_TIMEKEEP_TABLE 0x040A
  113. #define TW_INFORMATION_TABLE 0x0403
  114. #define TW_PARAM_FWVER 3
  115. #define TW_PARAM_FWVER_LENGTH 16
  116. #define TW_PARAM_BIOSVER 4
  117. #define TW_PARAM_BIOSVER_LENGTH 16
  118. #define TW_PARAM_MODEL 8
  119. #define TW_PARAM_MODEL_LENGTH 16
  120. #define TW_PARAM_PHY_SUMMARY_TABLE 1
  121. #define TW_PARAM_PHYCOUNT 2
  122. #define TW_PARAM_PHYCOUNT_LENGTH 1
  123. #define TW_IOCTL_FIRMWARE_PASS_THROUGH 0x108 // Used by smartmontools
  124. #define TW_ALLOCATION_LENGTH 128
  125. #define TW_SENSE_DATA_LENGTH 18
  126. #define TW_ERROR_LOGICAL_UNIT_NOT_SUPPORTED 0x10a
  127. #define TW_ERROR_INVALID_FIELD_IN_CDB 0x10d
  128. #define TW_ERROR_UNIT_OFFLINE 0x128
  129. #define TW_MESSAGE_SOURCE_CONTROLLER_ERROR 3
  130. #define TW_MESSAGE_SOURCE_CONTROLLER_EVENT 4
  131. #define TW_DRIVER 6
  132. #ifndef PCI_DEVICE_ID_3WARE_9750
  133. #define PCI_DEVICE_ID_3WARE_9750 0x1010
  134. #endif
  135. /* Bitmask macros to eliminate bitfields */
  136. /* opcode: 5, reserved: 3 */
  137. #define TW_OPRES_IN(x,y) ((x << 5) | (y & 0x1f))
  138. #define TW_OP_OUT(x) (x & 0x1f)
  139. /* opcode: 5, sgloffset: 3 */
  140. #define TW_OPSGL_IN(x,y) ((x << 5) | (y & 0x1f))
  141. #define TW_SGL_OUT(x) ((x >> 5) & 0x7)
  142. /* severity: 3, reserved: 5 */
  143. #define TW_SEV_OUT(x) (x & 0x7)
  144. /* not_mfa: 1, reserved: 7, status: 8, request_id: 16 */
  145. #define TW_RESID_OUT(x) ((x >> 16) & 0xffff)
  146. #define TW_NOTMFA_OUT(x) (x & 0x1)
  147. /* request_id: 12, lun: 4 */
  148. #define TW_REQ_LUN_IN(lun, request_id) (((lun << 12) & 0xf000) | (request_id & 0xfff))
  149. #define TW_LUN_OUT(lun) ((lun >> 12) & 0xf)
  150. /* Register access macros */
  151. #define TWL_STATUS_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + TWL_STATUS)
  152. #define TWL_HOBQPL_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + TWL_HOBQPL)
  153. #define TWL_HOBQPH_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + TWL_HOBQPH)
  154. #define TWL_HOBDB_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + TWL_HOBDB)
  155. #define TWL_HOBDBC_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + TWL_HOBDBC)
  156. #define TWL_HIMASK_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + TWL_HIMASK)
  157. #define TWL_HISTAT_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + TWL_HISTAT)
  158. #define TWL_HIBQPH_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + TWL_HIBQPH)
  159. #define TWL_HIBQPL_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + TWL_HIBQPL)
  160. #define TWL_HIBDB_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + TWL_HIBDB)
  161. #define TWL_SCRPD3_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + TWL_SCRPD3)
  162. #define TWL_MASK_INTERRUPTS(x) (writel(~0, TWL_HIMASK_REG_ADDR(tw_dev)))
  163. #define TWL_UNMASK_INTERRUPTS(x) (writel(~TWL_HISTATUS_VALID_INTERRUPT, TWL_HIMASK_REG_ADDR(tw_dev)))
  164. #define TWL_CLEAR_DB_INTERRUPT(x) (writel(~0, TWL_HOBDBC_REG_ADDR(tw_dev)))
  165. #define TWL_SOFT_RESET(x) (writel(TWL_ISSUE_SOFT_RESET, TWL_HIBDB_REG_ADDR(tw_dev)))
  166. /* Macros */
  167. #define TW_PRINTK(h,a,b,c) { \
  168. if (h) \
  169. printk(KERN_WARNING "3w-sas: scsi%d: ERROR: (0x%02X:0x%04X): %s.\n",h->host_no,a,b,c); \
  170. else \
  171. printk(KERN_WARNING "3w-sas: ERROR: (0x%02X:0x%04X): %s.\n",a,b,c); \
  172. }
  173. #define TW_MAX_LUNS 16
  174. #define TW_COMMAND_SIZE (sizeof(dma_addr_t) > 4 ? 6 : 4)
  175. #define TW_LIBERATOR_MAX_SGL_LENGTH (sizeof(dma_addr_t) > 4 ? 46 : 92)
  176. #define TW_LIBERATOR_MAX_SGL_LENGTH_OLD (sizeof(dma_addr_t) > 4 ? 47 : 94)
  177. #define TW_PADDING_LENGTH_LIBERATOR 136
  178. #define TW_PADDING_LENGTH_LIBERATOR_OLD 132
  179. #define TW_CPU_TO_SGL(x) (sizeof(dma_addr_t) > 4 ? cpu_to_le64(x) : cpu_to_le32(x))
  180. #pragma pack(1)
  181. /* SGL entry */
  182. typedef struct TAG_TW_SG_Entry_ISO {
  183. dma_addr_t address;
  184. dma_addr_t length;
  185. } TW_SG_Entry_ISO;
  186. /* Old Command Packet with ISO SGL */
  187. typedef struct TW_Command {
  188. unsigned char opcode__sgloffset;
  189. unsigned char size;
  190. unsigned char request_id;
  191. unsigned char unit__hostid;
  192. /* Second DWORD */
  193. unsigned char status;
  194. unsigned char flags;
  195. union {
  196. unsigned short block_count;
  197. unsigned short parameter_count;
  198. } byte6_offset;
  199. union {
  200. struct {
  201. u32 lba;
  202. TW_SG_Entry_ISO sgl[TW_LIBERATOR_MAX_SGL_LENGTH_OLD];
  203. unsigned char padding[TW_PADDING_LENGTH_LIBERATOR_OLD];
  204. } io;
  205. struct {
  206. TW_SG_Entry_ISO sgl[TW_LIBERATOR_MAX_SGL_LENGTH_OLD];
  207. u32 padding;
  208. unsigned char padding2[TW_PADDING_LENGTH_LIBERATOR_OLD];
  209. } param;
  210. } byte8_offset;
  211. } TW_Command;
  212. /* New Command Packet with ISO SGL */
  213. typedef struct TAG_TW_Command_Apache {
  214. unsigned char opcode__reserved;
  215. unsigned char unit;
  216. unsigned short request_id__lunl;
  217. unsigned char status;
  218. unsigned char sgl_offset;
  219. unsigned short sgl_entries__lunh;
  220. unsigned char cdb[16];
  221. TW_SG_Entry_ISO sg_list[TW_LIBERATOR_MAX_SGL_LENGTH];
  222. unsigned char padding[TW_PADDING_LENGTH_LIBERATOR];
  223. } TW_Command_Apache;
  224. /* New command packet header */
  225. typedef struct TAG_TW_Command_Apache_Header {
  226. unsigned char sense_data[TW_SENSE_DATA_LENGTH];
  227. struct {
  228. char reserved[4];
  229. unsigned short error;
  230. unsigned char padding;
  231. unsigned char severity__reserved;
  232. } status_block;
  233. unsigned char err_specific_desc[98];
  234. struct {
  235. unsigned char size_header;
  236. unsigned short request_id;
  237. unsigned char size_sense;
  238. } header_desc;
  239. } TW_Command_Apache_Header;
  240. /* This struct is a union of the 2 command packets */
  241. typedef struct TAG_TW_Command_Full {
  242. TW_Command_Apache_Header header;
  243. union {
  244. TW_Command oldcommand;
  245. TW_Command_Apache newcommand;
  246. } command;
  247. } TW_Command_Full;
  248. /* Initconnection structure */
  249. typedef struct TAG_TW_Initconnect {
  250. unsigned char opcode__reserved;
  251. unsigned char size;
  252. unsigned char request_id;
  253. unsigned char res2;
  254. unsigned char status;
  255. unsigned char flags;
  256. unsigned short message_credits;
  257. u32 features;
  258. unsigned short fw_srl;
  259. unsigned short fw_arch_id;
  260. unsigned short fw_branch;
  261. unsigned short fw_build;
  262. u32 result;
  263. } TW_Initconnect;
  264. /* Event info structure */
  265. typedef struct TAG_TW_Event
  266. {
  267. unsigned int sequence_id;
  268. unsigned int time_stamp_sec;
  269. unsigned short aen_code;
  270. unsigned char severity;
  271. unsigned char retrieved;
  272. unsigned char repeat_count;
  273. unsigned char parameter_len;
  274. unsigned char parameter_data[98];
  275. } TW_Event;
  276. typedef struct TAG_TW_Ioctl_Driver_Command {
  277. unsigned int control_code;
  278. unsigned int status;
  279. unsigned int unique_id;
  280. unsigned int sequence_id;
  281. unsigned int os_specific;
  282. unsigned int buffer_length;
  283. } TW_Ioctl_Driver_Command;
  284. typedef struct TAG_TW_Ioctl_Apache {
  285. TW_Ioctl_Driver_Command driver_command;
  286. char padding[488];
  287. TW_Command_Full firmware_command;
  288. char data_buffer[1];
  289. } TW_Ioctl_Buf_Apache;
  290. /* GetParam descriptor */
  291. typedef struct {
  292. unsigned short table_id;
  293. unsigned short parameter_id;
  294. unsigned short parameter_size_bytes;
  295. unsigned short actual_parameter_size_bytes;
  296. unsigned char data[1];
  297. } TW_Param_Apache;
  298. /* Compatibility information structure */
  299. typedef struct TAG_TW_Compatibility_Info
  300. {
  301. char driver_version[32];
  302. unsigned short working_srl;
  303. unsigned short working_branch;
  304. unsigned short working_build;
  305. unsigned short driver_srl_high;
  306. unsigned short driver_branch_high;
  307. unsigned short driver_build_high;
  308. unsigned short driver_srl_low;
  309. unsigned short driver_branch_low;
  310. unsigned short driver_build_low;
  311. unsigned short fw_on_ctlr_srl;
  312. unsigned short fw_on_ctlr_branch;
  313. unsigned short fw_on_ctlr_build;
  314. } TW_Compatibility_Info;
  315. #pragma pack()
  316. typedef struct TAG_TW_Device_Extension {
  317. void __iomem *base_addr;
  318. unsigned long *generic_buffer_virt[TW_Q_LENGTH];
  319. dma_addr_t generic_buffer_phys[TW_Q_LENGTH];
  320. TW_Command_Full *command_packet_virt[TW_Q_LENGTH];
  321. dma_addr_t command_packet_phys[TW_Q_LENGTH];
  322. TW_Command_Apache_Header *sense_buffer_virt[TW_Q_LENGTH];
  323. dma_addr_t sense_buffer_phys[TW_Q_LENGTH];
  324. struct pci_dev *tw_pci_dev;
  325. struct scsi_cmnd *srb[TW_Q_LENGTH];
  326. unsigned char free_queue[TW_Q_LENGTH];
  327. unsigned char free_head;
  328. unsigned char free_tail;
  329. int state[TW_Q_LENGTH];
  330. unsigned int posted_request_count;
  331. unsigned int max_posted_request_count;
  332. unsigned int max_sgl_entries;
  333. unsigned int sgl_entries;
  334. unsigned int num_resets;
  335. unsigned int sector_count;
  336. unsigned int max_sector_count;
  337. unsigned int aen_count;
  338. struct Scsi_Host *host;
  339. long flags;
  340. TW_Event *event_queue[TW_Q_LENGTH];
  341. unsigned char error_index;
  342. unsigned int error_sequence_id;
  343. int chrdev_request_id;
  344. wait_queue_head_t ioctl_wqueue;
  345. struct mutex ioctl_lock;
  346. TW_Compatibility_Info tw_compat_info;
  347. char online;
  348. } TW_Device_Extension;
  349. #endif /* _3W_SAS_H */