3w-9xxx.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /*
  2. 3w-9xxx.h -- 3ware 9000 Storage Controller device driver for Linux.
  3. Written By: Adam Radford <linuxraid@lsi.com>
  4. Modifications By: Tom Couch <linuxraid@lsi.com>
  5. Copyright (C) 2004-2009 Applied Micro Circuits Corporation.
  6. Copyright (C) 2010 LSI Corporation.
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; version 2 of the License.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. NO WARRANTY
  15. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  16. CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  17. LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  18. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  19. solely responsible for determining the appropriateness of using and
  20. distributing the Program and assumes all risks associated with its
  21. exercise of rights under this Agreement, including but not limited to
  22. the risks and costs of program errors, damage to or loss of data,
  23. programs or equipment, and unavailability or interruption of operations.
  24. DISCLAIMER OF LIABILITY
  25. NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  26. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  28. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  29. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  30. USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  31. HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  32. You should have received a copy of the GNU General Public License
  33. along with this program; if not, write to the Free Software
  34. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  35. Bugs/Comments/Suggestions should be mailed to:
  36. linuxraid@lsi.com
  37. For more information, goto:
  38. http://www.lsi.com
  39. */
  40. #ifndef _3W_9XXX_H
  41. #define _3W_9XXX_H
  42. /* AEN string type */
  43. typedef struct TAG_twa_message_type {
  44. unsigned int code;
  45. char* text;
  46. } twa_message_type;
  47. /* AEN strings */
  48. static twa_message_type twa_aen_table[] = {
  49. {0x0000, "AEN queue empty"},
  50. {0x0001, "Controller reset occurred"},
  51. {0x0002, "Degraded unit detected"},
  52. {0x0003, "Controller error occurred"},
  53. {0x0004, "Background rebuild failed"},
  54. {0x0005, "Background rebuild done"},
  55. {0x0006, "Incomplete unit detected"},
  56. {0x0007, "Background initialize done"},
  57. {0x0008, "Unclean shutdown detected"},
  58. {0x0009, "Drive timeout detected"},
  59. {0x000A, "Drive error detected"},
  60. {0x000B, "Rebuild started"},
  61. {0x000C, "Background initialize started"},
  62. {0x000D, "Entire logical unit was deleted"},
  63. {0x000E, "Background initialize failed"},
  64. {0x000F, "SMART attribute exceeded threshold"},
  65. {0x0010, "Power supply reported AC under range"},
  66. {0x0011, "Power supply reported DC out of range"},
  67. {0x0012, "Power supply reported a malfunction"},
  68. {0x0013, "Power supply predicted malfunction"},
  69. {0x0014, "Battery charge is below threshold"},
  70. {0x0015, "Fan speed is below threshold"},
  71. {0x0016, "Temperature sensor is above threshold"},
  72. {0x0017, "Power supply was removed"},
  73. {0x0018, "Power supply was inserted"},
  74. {0x0019, "Drive was removed from a bay"},
  75. {0x001A, "Drive was inserted into a bay"},
  76. {0x001B, "Drive bay cover door was opened"},
  77. {0x001C, "Drive bay cover door was closed"},
  78. {0x001D, "Product case was opened"},
  79. {0x0020, "Prepare for shutdown (power-off)"},
  80. {0x0021, "Downgrade UDMA mode to lower speed"},
  81. {0x0022, "Upgrade UDMA mode to higher speed"},
  82. {0x0023, "Sector repair completed"},
  83. {0x0024, "Sbuf memory test failed"},
  84. {0x0025, "Error flushing cached write data to array"},
  85. {0x0026, "Drive reported data ECC error"},
  86. {0x0027, "DCB has checksum error"},
  87. {0x0028, "DCB version is unsupported"},
  88. {0x0029, "Background verify started"},
  89. {0x002A, "Background verify failed"},
  90. {0x002B, "Background verify done"},
  91. {0x002C, "Bad sector overwritten during rebuild"},
  92. {0x002D, "Background rebuild error on source drive"},
  93. {0x002E, "Replace failed because replacement drive too small"},
  94. {0x002F, "Verify failed because array was never initialized"},
  95. {0x0030, "Unsupported ATA drive"},
  96. {0x0031, "Synchronize host/controller time"},
  97. {0x0032, "Spare capacity is inadequate for some units"},
  98. {0x0033, "Background migration started"},
  99. {0x0034, "Background migration failed"},
  100. {0x0035, "Background migration done"},
  101. {0x0036, "Verify detected and fixed data/parity mismatch"},
  102. {0x0037, "SO-DIMM incompatible"},
  103. {0x0038, "SO-DIMM not detected"},
  104. {0x0039, "Corrected Sbuf ECC error"},
  105. {0x003A, "Drive power on reset detected"},
  106. {0x003B, "Background rebuild paused"},
  107. {0x003C, "Background initialize paused"},
  108. {0x003D, "Background verify paused"},
  109. {0x003E, "Background migration paused"},
  110. {0x003F, "Corrupt flash file system detected"},
  111. {0x0040, "Flash file system repaired"},
  112. {0x0041, "Unit number assignments were lost"},
  113. {0x0042, "Error during read of primary DCB"},
  114. {0x0043, "Latent error found in backup DCB"},
  115. {0x00FC, "Recovered/finished array membership update"},
  116. {0x00FD, "Handler lockup"},
  117. {0x00FE, "Retrying PCI transfer"},
  118. {0x00FF, "AEN queue is full"},
  119. {0xFFFFFFFF, (char*) 0}
  120. };
  121. /* AEN severity table */
  122. static char *twa_aen_severity_table[] =
  123. {
  124. "None", "ERROR", "WARNING", "INFO", "DEBUG", (char*) 0
  125. };
  126. /* Error strings */
  127. static twa_message_type twa_error_table[] = {
  128. {0x0100, "SGL entry contains zero data"},
  129. {0x0101, "Invalid command opcode"},
  130. {0x0102, "SGL entry has unaligned address"},
  131. {0x0103, "SGL size does not match command"},
  132. {0x0104, "SGL entry has illegal length"},
  133. {0x0105, "Command packet is not aligned"},
  134. {0x0106, "Invalid request ID"},
  135. {0x0107, "Duplicate request ID"},
  136. {0x0108, "ID not locked"},
  137. {0x0109, "LBA out of range"},
  138. {0x010A, "Logical unit not supported"},
  139. {0x010B, "Parameter table does not exist"},
  140. {0x010C, "Parameter index does not exist"},
  141. {0x010D, "Invalid field in CDB"},
  142. {0x010E, "Specified port has invalid drive"},
  143. {0x010F, "Parameter item size mismatch"},
  144. {0x0110, "Failed memory allocation"},
  145. {0x0111, "Memory request too large"},
  146. {0x0112, "Out of memory segments"},
  147. {0x0113, "Invalid address to deallocate"},
  148. {0x0114, "Out of memory"},
  149. {0x0115, "Out of heap"},
  150. {0x0120, "Double degrade"},
  151. {0x0121, "Drive not degraded"},
  152. {0x0122, "Reconstruct error"},
  153. {0x0123, "Replace not accepted"},
  154. {0x0124, "Replace drive capacity too small"},
  155. {0x0125, "Sector count not allowed"},
  156. {0x0126, "No spares left"},
  157. {0x0127, "Reconstruct error"},
  158. {0x0128, "Unit is offline"},
  159. {0x0129, "Cannot update status to DCB"},
  160. {0x0130, "Invalid stripe handle"},
  161. {0x0131, "Handle that was not locked"},
  162. {0x0132, "Handle that was not empty"},
  163. {0x0133, "Handle has different owner"},
  164. {0x0140, "IPR has parent"},
  165. {0x0150, "Illegal Pbuf address alignment"},
  166. {0x0151, "Illegal Pbuf transfer length"},
  167. {0x0152, "Illegal Sbuf address alignment"},
  168. {0x0153, "Illegal Sbuf transfer length"},
  169. {0x0160, "Command packet too large"},
  170. {0x0161, "SGL exceeds maximum length"},
  171. {0x0162, "SGL has too many entries"},
  172. {0x0170, "Insufficient resources for rebuilder"},
  173. {0x0171, "Verify error (data != parity)"},
  174. {0x0180, "Requested segment not in directory of this DCB"},
  175. {0x0181, "DCB segment has unsupported version"},
  176. {0x0182, "DCB segment has checksum error"},
  177. {0x0183, "DCB support (settings) segment invalid"},
  178. {0x0184, "DCB UDB (unit descriptor block) segment invalid"},
  179. {0x0185, "DCB GUID (globally unique identifier) segment invalid"},
  180. {0x01A0, "Could not clear Sbuf"},
  181. {0x01C0, "Flash identify failed"},
  182. {0x01C1, "Flash out of bounds"},
  183. {0x01C2, "Flash verify error"},
  184. {0x01C3, "Flash file object not found"},
  185. {0x01C4, "Flash file already present"},
  186. {0x01C5, "Flash file system full"},
  187. {0x01C6, "Flash file not present"},
  188. {0x01C7, "Flash file size error"},
  189. {0x01C8, "Bad flash file checksum"},
  190. {0x01CA, "Corrupt flash file system detected"},
  191. {0x01D0, "Invalid field in parameter list"},
  192. {0x01D1, "Parameter list length error"},
  193. {0x01D2, "Parameter item is not changeable"},
  194. {0x01D3, "Parameter item is not saveable"},
  195. {0x0200, "UDMA CRC error"},
  196. {0x0201, "Internal CRC error"},
  197. {0x0202, "Data ECC error"},
  198. {0x0203, "ADP level 1 error"},
  199. {0x0204, "Port timeout"},
  200. {0x0205, "Drive power on reset"},
  201. {0x0206, "ADP level 2 error"},
  202. {0x0207, "Soft reset failed"},
  203. {0x0208, "Drive not ready"},
  204. {0x0209, "Unclassified port error"},
  205. {0x020A, "Drive aborted command"},
  206. {0x0210, "Internal CRC error"},
  207. {0x0211, "PCI abort error"},
  208. {0x0212, "PCI parity error"},
  209. {0x0213, "Port handler error"},
  210. {0x0214, "Token interrupt count error"},
  211. {0x0215, "Timeout waiting for PCI transfer"},
  212. {0x0216, "Corrected buffer ECC"},
  213. {0x0217, "Uncorrected buffer ECC"},
  214. {0x0230, "Unsupported command during flash recovery"},
  215. {0x0231, "Next image buffer expected"},
  216. {0x0232, "Binary image architecture incompatible"},
  217. {0x0233, "Binary image has no signature"},
  218. {0x0234, "Binary image has bad checksum"},
  219. {0x0235, "Image downloaded overflowed buffer"},
  220. {0x0240, "I2C device not found"},
  221. {0x0241, "I2C transaction aborted"},
  222. {0x0242, "SO-DIMM parameter(s) incompatible using defaults"},
  223. {0x0243, "SO-DIMM unsupported"},
  224. {0x0248, "SPI transfer status error"},
  225. {0x0249, "SPI transfer timeout error"},
  226. {0x0250, "Invalid unit descriptor size in CreateUnit"},
  227. {0x0251, "Unit descriptor size exceeds data buffer in CreateUnit"},
  228. {0x0252, "Invalid value in CreateUnit descriptor"},
  229. {0x0253, "Inadequate disk space to support descriptor in CreateUnit"},
  230. {0x0254, "Unable to create data channel for this unit descriptor"},
  231. {0x0255, "CreateUnit descriptor specifies a drive already in use"},
  232. {0x0256, "Unable to write configuration to all disks during CreateUnit"},
  233. {0x0257, "CreateUnit does not support this descriptor version"},
  234. {0x0258, "Invalid subunit for RAID 0 or 5 in CreateUnit"},
  235. {0x0259, "Too many descriptors in CreateUnit"},
  236. {0x025A, "Invalid configuration specified in CreateUnit descriptor"},
  237. {0x025B, "Invalid LBA offset specified in CreateUnit descriptor"},
  238. {0x025C, "Invalid stripelet size specified in CreateUnit descriptor"},
  239. {0x0260, "SMART attribute exceeded threshold"},
  240. {0xFFFFFFFF, (char*) 0}
  241. };
  242. /* Control register bit definitions */
  243. #define TW_CONTROL_CLEAR_HOST_INTERRUPT 0x00080000
  244. #define TW_CONTROL_CLEAR_ATTENTION_INTERRUPT 0x00040000
  245. #define TW_CONTROL_MASK_COMMAND_INTERRUPT 0x00020000
  246. #define TW_CONTROL_MASK_RESPONSE_INTERRUPT 0x00010000
  247. #define TW_CONTROL_UNMASK_COMMAND_INTERRUPT 0x00008000
  248. #define TW_CONTROL_UNMASK_RESPONSE_INTERRUPT 0x00004000
  249. #define TW_CONTROL_CLEAR_ERROR_STATUS 0x00000200
  250. #define TW_CONTROL_ISSUE_SOFT_RESET 0x00000100
  251. #define TW_CONTROL_ENABLE_INTERRUPTS 0x00000080
  252. #define TW_CONTROL_DISABLE_INTERRUPTS 0x00000040
  253. #define TW_CONTROL_ISSUE_HOST_INTERRUPT 0x00000020
  254. #define TW_CONTROL_CLEAR_PARITY_ERROR 0x00800000
  255. #define TW_CONTROL_CLEAR_QUEUE_ERROR 0x00400000
  256. #define TW_CONTROL_CLEAR_PCI_ABORT 0x00100000
  257. /* Status register bit definitions */
  258. #define TW_STATUS_MAJOR_VERSION_MASK 0xF0000000
  259. #define TW_STATUS_MINOR_VERSION_MASK 0x0F000000
  260. #define TW_STATUS_PCI_PARITY_ERROR 0x00800000
  261. #define TW_STATUS_QUEUE_ERROR 0x00400000
  262. #define TW_STATUS_MICROCONTROLLER_ERROR 0x00200000
  263. #define TW_STATUS_PCI_ABORT 0x00100000
  264. #define TW_STATUS_HOST_INTERRUPT 0x00080000
  265. #define TW_STATUS_ATTENTION_INTERRUPT 0x00040000
  266. #define TW_STATUS_COMMAND_INTERRUPT 0x00020000
  267. #define TW_STATUS_RESPONSE_INTERRUPT 0x00010000
  268. #define TW_STATUS_COMMAND_QUEUE_FULL 0x00008000
  269. #define TW_STATUS_RESPONSE_QUEUE_EMPTY 0x00004000
  270. #define TW_STATUS_MICROCONTROLLER_READY 0x00002000
  271. #define TW_STATUS_COMMAND_QUEUE_EMPTY 0x00001000
  272. #define TW_STATUS_EXPECTED_BITS 0x00002000
  273. #define TW_STATUS_UNEXPECTED_BITS 0x00F00000
  274. #define TW_STATUS_VALID_INTERRUPT 0x00DF0000
  275. /* PCI related defines */
  276. #define TW_PCI_CLEAR_PARITY_ERRORS 0xc100
  277. #define TW_PCI_CLEAR_PCI_ABORT 0x2000
  278. /* Command packet opcodes used by the driver */
  279. #define TW_OP_INIT_CONNECTION 0x1
  280. #define TW_OP_GET_PARAM 0x12
  281. #define TW_OP_SET_PARAM 0x13
  282. #define TW_OP_EXECUTE_SCSI 0x10
  283. #define TW_OP_DOWNLOAD_FIRMWARE 0x16
  284. #define TW_OP_RESET 0x1C
  285. /* Asynchronous Event Notification (AEN) codes used by the driver */
  286. #define TW_AEN_QUEUE_EMPTY 0x0000
  287. #define TW_AEN_SOFT_RESET 0x0001
  288. #define TW_AEN_SYNC_TIME_WITH_HOST 0x031
  289. #define TW_AEN_SEVERITY_ERROR 0x1
  290. #define TW_AEN_SEVERITY_DEBUG 0x4
  291. #define TW_AEN_NOT_RETRIEVED 0x1
  292. #define TW_AEN_RETRIEVED 0x2
  293. /* Command state defines */
  294. #define TW_S_INITIAL 0x1 /* Initial state */
  295. #define TW_S_STARTED 0x2 /* Id in use */
  296. #define TW_S_POSTED 0x4 /* Posted to the controller */
  297. #define TW_S_PENDING 0x8 /* Waiting to be posted in isr */
  298. #define TW_S_COMPLETED 0x10 /* Completed by isr */
  299. #define TW_S_FINISHED 0x20 /* I/O completely done */
  300. /* Compatibility defines */
  301. #define TW_9000_ARCH_ID 0x5
  302. #define TW_CURRENT_DRIVER_SRL 35
  303. #define TW_CURRENT_DRIVER_BUILD 0
  304. #define TW_CURRENT_DRIVER_BRANCH 0
  305. /* Misc defines */
  306. #define TW_9550SX_DRAIN_COMPLETED 0xFFFF
  307. #define TW_SECTOR_SIZE 512
  308. #define TW_ALIGNMENT_9000 4 /* 4 bytes */
  309. #define TW_ALIGNMENT_9000_SGL 0x3
  310. #define TW_MAX_UNITS 16
  311. #define TW_MAX_UNITS_9650SE 32
  312. #define TW_INIT_MESSAGE_CREDITS 0x100
  313. #define TW_INIT_COMMAND_PACKET_SIZE 0x3
  314. #define TW_INIT_COMMAND_PACKET_SIZE_EXTENDED 0x6
  315. #define TW_EXTENDED_INIT_CONNECT 0x2
  316. #define TW_BUNDLED_FW_SAFE_TO_FLASH 0x4
  317. #define TW_CTLR_FW_RECOMMENDS_FLASH 0x8
  318. #define TW_CTLR_FW_COMPATIBLE 0x2
  319. #define TW_BASE_FW_SRL 24
  320. #define TW_BASE_FW_BRANCH 0
  321. #define TW_BASE_FW_BUILD 1
  322. #define TW_FW_SRL_LUNS_SUPPORTED 28
  323. #define TW_Q_LENGTH 256
  324. #define TW_Q_START 0
  325. #define TW_MAX_SLOT 32
  326. #define TW_MAX_RESET_TRIES 2
  327. #define TW_MAX_CMDS_PER_LUN 254
  328. #define TW_MAX_RESPONSE_DRAIN 256
  329. #define TW_MAX_AEN_DRAIN 255
  330. #define TW_IN_RESET 2
  331. #define TW_USING_MSI 3
  332. #define TW_IN_ATTENTION_LOOP 4
  333. #define TW_MAX_SECTORS 256
  334. #define TW_AEN_WAIT_TIME 1000
  335. #define TW_IOCTL_WAIT_TIME (1 * HZ) /* 1 second */
  336. #define TW_MAX_CDB_LEN 16
  337. #define TW_ISR_DONT_COMPLETE 2
  338. #define TW_ISR_DONT_RESULT 3
  339. #define TW_IOCTL_CHRDEV_TIMEOUT 60 /* 60 seconds */
  340. #define TW_IOCTL_CHRDEV_FREE -1
  341. #define TW_COMMAND_OFFSET 128 /* 128 bytes */
  342. #define TW_VERSION_TABLE 0x0402
  343. #define TW_TIMEKEEP_TABLE 0x040A
  344. #define TW_INFORMATION_TABLE 0x0403
  345. #define TW_PARAM_FWVER 3
  346. #define TW_PARAM_FWVER_LENGTH 16
  347. #define TW_PARAM_BIOSVER 4
  348. #define TW_PARAM_BIOSVER_LENGTH 16
  349. #define TW_PARAM_PORTCOUNT 3
  350. #define TW_PARAM_PORTCOUNT_LENGTH 1
  351. #define TW_MIN_SGL_LENGTH 0x200 /* 512 bytes */
  352. #define TW_MAX_SENSE_LENGTH 256
  353. #define TW_EVENT_SOURCE_AEN 0x1000
  354. #define TW_EVENT_SOURCE_COMMAND 0x1001
  355. #define TW_EVENT_SOURCE_PCHIP 0x1002
  356. #define TW_EVENT_SOURCE_DRIVER 0x1003
  357. #define TW_IOCTL_GET_COMPATIBILITY_INFO 0x101
  358. #define TW_IOCTL_GET_LAST_EVENT 0x102
  359. #define TW_IOCTL_GET_FIRST_EVENT 0x103
  360. #define TW_IOCTL_GET_NEXT_EVENT 0x104
  361. #define TW_IOCTL_GET_PREVIOUS_EVENT 0x105
  362. #define TW_IOCTL_GET_LOCK 0x106
  363. #define TW_IOCTL_RELEASE_LOCK 0x107
  364. #define TW_IOCTL_FIRMWARE_PASS_THROUGH 0x108
  365. #define TW_IOCTL_ERROR_STATUS_NOT_LOCKED 0x1001 // Not locked
  366. #define TW_IOCTL_ERROR_STATUS_LOCKED 0x1002 // Already locked
  367. #define TW_IOCTL_ERROR_STATUS_NO_MORE_EVENTS 0x1003 // No more events
  368. #define TW_IOCTL_ERROR_STATUS_AEN_CLOBBER 0x1004 // AEN clobber occurred
  369. #define TW_IOCTL_ERROR_OS_EFAULT -EFAULT // Bad address
  370. #define TW_IOCTL_ERROR_OS_EINTR -EINTR // Interrupted system call
  371. #define TW_IOCTL_ERROR_OS_EINVAL -EINVAL // Invalid argument
  372. #define TW_IOCTL_ERROR_OS_ENOMEM -ENOMEM // Out of memory
  373. #define TW_IOCTL_ERROR_OS_ERESTARTSYS -ERESTARTSYS // Restart system call
  374. #define TW_IOCTL_ERROR_OS_EIO -EIO // I/O error
  375. #define TW_IOCTL_ERROR_OS_ENOTTY -ENOTTY // Not a typewriter
  376. #define TW_IOCTL_ERROR_OS_ENODEV -ENODEV // No such device
  377. #define TW_ALLOCATION_LENGTH 128
  378. #define TW_SENSE_DATA_LENGTH 18
  379. #define TW_STATUS_CHECK_CONDITION 2
  380. #define TW_ERROR_LOGICAL_UNIT_NOT_SUPPORTED 0x10a
  381. #define TW_ERROR_UNIT_OFFLINE 0x128
  382. #define TW_MESSAGE_SOURCE_CONTROLLER_ERROR 3
  383. #define TW_MESSAGE_SOURCE_CONTROLLER_EVENT 4
  384. #define TW_MESSAGE_SOURCE_LINUX_DRIVER 6
  385. #define TW_DRIVER TW_MESSAGE_SOURCE_LINUX_DRIVER
  386. #define TW_MESSAGE_SOURCE_LINUX_OS 9
  387. #define TW_OS TW_MESSAGE_SOURCE_LINUX_OS
  388. #ifndef PCI_DEVICE_ID_3WARE_9000
  389. #define PCI_DEVICE_ID_3WARE_9000 0x1002
  390. #endif
  391. #ifndef PCI_DEVICE_ID_3WARE_9550SX
  392. #define PCI_DEVICE_ID_3WARE_9550SX 0x1003
  393. #endif
  394. #ifndef PCI_DEVICE_ID_3WARE_9650SE
  395. #define PCI_DEVICE_ID_3WARE_9650SE 0x1004
  396. #endif
  397. #ifndef PCI_DEVICE_ID_3WARE_9690SA
  398. #define PCI_DEVICE_ID_3WARE_9690SA 0x1005
  399. #endif
  400. /* Bitmask macros to eliminate bitfields */
  401. /* opcode: 5, reserved: 3 */
  402. #define TW_OPRES_IN(x,y) ((x << 5) | (y & 0x1f))
  403. #define TW_OP_OUT(x) (x & 0x1f)
  404. /* opcode: 5, sgloffset: 3 */
  405. #define TW_OPSGL_IN(x,y) ((x << 5) | (y & 0x1f))
  406. #define TW_SGL_OUT(x) ((x >> 5) & 0x7)
  407. /* severity: 3, reserved: 5 */
  408. #define TW_SEV_OUT(x) (x & 0x7)
  409. /* reserved_1: 4, response_id: 8, reserved_2: 20 */
  410. #define TW_RESID_OUT(x) ((x >> 4) & 0xff)
  411. /* request_id: 12, lun: 4 */
  412. #define TW_REQ_LUN_IN(lun, request_id) (((lun << 12) & 0xf000) | (request_id & 0xfff))
  413. #define TW_LUN_OUT(lun) ((lun >> 12) & 0xf)
  414. /* Macros */
  415. #define TW_CONTROL_REG_ADDR(x) (x->base_addr)
  416. #define TW_STATUS_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + 0x4)
  417. #define TW_COMMAND_QUEUE_REG_ADDR(x) (sizeof(dma_addr_t) > 4 ? ((unsigned char __iomem *)x->base_addr + 0x20) : ((unsigned char __iomem *)x->base_addr + 0x8))
  418. #define TW_COMMAND_QUEUE_REG_ADDR_LARGE(x) ((unsigned char __iomem *)x->base_addr + 0x20)
  419. #define TW_RESPONSE_QUEUE_REG_ADDR(x) ((unsigned char __iomem *)x->base_addr + 0xC)
  420. #define TW_RESPONSE_QUEUE_REG_ADDR_LARGE(x) ((unsigned char __iomem *)x->base_addr + 0x30)
  421. #define TW_CLEAR_ALL_INTERRUPTS(x) (writel(TW_STATUS_VALID_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
  422. #define TW_CLEAR_ATTENTION_INTERRUPT(x) (writel(TW_CONTROL_CLEAR_ATTENTION_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
  423. #define TW_CLEAR_HOST_INTERRUPT(x) (writel(TW_CONTROL_CLEAR_HOST_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
  424. #define TW_DISABLE_INTERRUPTS(x) (writel(TW_CONTROL_DISABLE_INTERRUPTS, TW_CONTROL_REG_ADDR(x)))
  425. #define TW_ENABLE_AND_CLEAR_INTERRUPTS(x) (writel(TW_CONTROL_CLEAR_ATTENTION_INTERRUPT | TW_CONTROL_UNMASK_RESPONSE_INTERRUPT | TW_CONTROL_ENABLE_INTERRUPTS, TW_CONTROL_REG_ADDR(x)))
  426. #define TW_MASK_COMMAND_INTERRUPT(x) (writel(TW_CONTROL_MASK_COMMAND_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
  427. #define TW_UNMASK_COMMAND_INTERRUPT(x) (writel(TW_CONTROL_UNMASK_COMMAND_INTERRUPT, TW_CONTROL_REG_ADDR(x)))
  428. #define TW_SOFT_RESET(x) (writel(TW_CONTROL_ISSUE_SOFT_RESET | \
  429. TW_CONTROL_CLEAR_HOST_INTERRUPT | \
  430. TW_CONTROL_CLEAR_ATTENTION_INTERRUPT | \
  431. TW_CONTROL_MASK_COMMAND_INTERRUPT | \
  432. TW_CONTROL_MASK_RESPONSE_INTERRUPT | \
  433. TW_CONTROL_CLEAR_ERROR_STATUS | \
  434. TW_CONTROL_DISABLE_INTERRUPTS, TW_CONTROL_REG_ADDR(x)))
  435. #define TW_PRINTK(h,a,b,c) { \
  436. if (h) \
  437. printk(KERN_WARNING "3w-9xxx: scsi%d: ERROR: (0x%02X:0x%04X): %s.\n",h->host_no,a,b,c); \
  438. else \
  439. printk(KERN_WARNING "3w-9xxx: ERROR: (0x%02X:0x%04X): %s.\n",a,b,c); \
  440. }
  441. #define TW_MAX_LUNS(srl) (srl < TW_FW_SRL_LUNS_SUPPORTED ? 1 : 16)
  442. #define TW_COMMAND_SIZE (sizeof(dma_addr_t) > 4 ? 5 : 4)
  443. #define TW_APACHE_MAX_SGL_LENGTH (sizeof(dma_addr_t) > 4 ? 72 : 109)
  444. #define TW_ESCALADE_MAX_SGL_LENGTH (sizeof(dma_addr_t) > 4 ? 41 : 62)
  445. #define TW_PADDING_LENGTH (sizeof(dma_addr_t) > 4 ? 8 : 0)
  446. #define TW_CPU_TO_SGL(x) (sizeof(dma_addr_t) > 4 ? cpu_to_le64(x) : cpu_to_le32(x))
  447. #pragma pack(1)
  448. /* Scatter Gather List Entry */
  449. typedef struct TAG_TW_SG_Entry {
  450. dma_addr_t address;
  451. u32 length;
  452. } TW_SG_Entry;
  453. /* Command Packet */
  454. typedef struct TW_Command {
  455. unsigned char opcode__sgloffset;
  456. unsigned char size;
  457. unsigned char request_id;
  458. unsigned char unit__hostid;
  459. /* Second DWORD */
  460. unsigned char status;
  461. unsigned char flags;
  462. union {
  463. unsigned short block_count;
  464. unsigned short parameter_count;
  465. } byte6_offset;
  466. union {
  467. struct {
  468. u32 lba;
  469. TW_SG_Entry sgl[TW_ESCALADE_MAX_SGL_LENGTH];
  470. dma_addr_t padding;
  471. } io;
  472. struct {
  473. TW_SG_Entry sgl[TW_ESCALADE_MAX_SGL_LENGTH];
  474. u32 padding;
  475. dma_addr_t padding2;
  476. } param;
  477. } byte8_offset;
  478. } TW_Command;
  479. /* Command Packet for 9000+ controllers */
  480. typedef struct TAG_TW_Command_Apache {
  481. unsigned char opcode__reserved;
  482. unsigned char unit;
  483. unsigned short request_id__lunl;
  484. unsigned char status;
  485. unsigned char sgl_offset;
  486. unsigned short sgl_entries__lunh;
  487. unsigned char cdb[16];
  488. TW_SG_Entry sg_list[TW_APACHE_MAX_SGL_LENGTH];
  489. unsigned char padding[TW_PADDING_LENGTH];
  490. } TW_Command_Apache;
  491. /* New command packet header */
  492. typedef struct TAG_TW_Command_Apache_Header {
  493. unsigned char sense_data[TW_SENSE_DATA_LENGTH];
  494. struct {
  495. char reserved[4];
  496. unsigned short error;
  497. unsigned char padding;
  498. unsigned char severity__reserved;
  499. } status_block;
  500. unsigned char err_specific_desc[98];
  501. struct {
  502. unsigned char size_header;
  503. unsigned short reserved;
  504. unsigned char size_sense;
  505. } header_desc;
  506. } TW_Command_Apache_Header;
  507. /* This struct is a union of the 2 command packets */
  508. typedef struct TAG_TW_Command_Full {
  509. TW_Command_Apache_Header header;
  510. union {
  511. TW_Command oldcommand;
  512. TW_Command_Apache newcommand;
  513. } command;
  514. } TW_Command_Full;
  515. /* Initconnection structure */
  516. typedef struct TAG_TW_Initconnect {
  517. unsigned char opcode__reserved;
  518. unsigned char size;
  519. unsigned char request_id;
  520. unsigned char res2;
  521. unsigned char status;
  522. unsigned char flags;
  523. unsigned short message_credits;
  524. u32 features;
  525. unsigned short fw_srl;
  526. unsigned short fw_arch_id;
  527. unsigned short fw_branch;
  528. unsigned short fw_build;
  529. u32 result;
  530. } TW_Initconnect;
  531. /* Event info structure */
  532. typedef struct TAG_TW_Event
  533. {
  534. unsigned int sequence_id;
  535. unsigned int time_stamp_sec;
  536. unsigned short aen_code;
  537. unsigned char severity;
  538. unsigned char retrieved;
  539. unsigned char repeat_count;
  540. unsigned char parameter_len;
  541. unsigned char parameter_data[98];
  542. } TW_Event;
  543. typedef struct TAG_TW_Ioctl_Driver_Command {
  544. unsigned int control_code;
  545. unsigned int status;
  546. unsigned int unique_id;
  547. unsigned int sequence_id;
  548. unsigned int os_specific;
  549. unsigned int buffer_length;
  550. } TW_Ioctl_Driver_Command;
  551. typedef struct TAG_TW_Ioctl_Apache {
  552. TW_Ioctl_Driver_Command driver_command;
  553. char padding[488];
  554. TW_Command_Full firmware_command;
  555. char data_buffer[1];
  556. } TW_Ioctl_Buf_Apache;
  557. /* Lock structure for ioctl get/release lock */
  558. typedef struct TAG_TW_Lock {
  559. unsigned long timeout_msec;
  560. unsigned long time_remaining_msec;
  561. unsigned long force_flag;
  562. } TW_Lock;
  563. /* GetParam descriptor */
  564. typedef struct {
  565. unsigned short table_id;
  566. unsigned short parameter_id;
  567. unsigned short parameter_size_bytes;
  568. unsigned short actual_parameter_size_bytes;
  569. unsigned char data[1];
  570. } TW_Param_Apache, *PTW_Param_Apache;
  571. /* Response queue */
  572. typedef union TAG_TW_Response_Queue {
  573. u32 response_id;
  574. u32 value;
  575. } TW_Response_Queue;
  576. /* Compatibility information structure */
  577. typedef struct TAG_TW_Compatibility_Info
  578. {
  579. char driver_version[32];
  580. unsigned short working_srl;
  581. unsigned short working_branch;
  582. unsigned short working_build;
  583. unsigned short driver_srl_high;
  584. unsigned short driver_branch_high;
  585. unsigned short driver_build_high;
  586. unsigned short driver_srl_low;
  587. unsigned short driver_branch_low;
  588. unsigned short driver_build_low;
  589. unsigned short fw_on_ctlr_srl;
  590. unsigned short fw_on_ctlr_branch;
  591. unsigned short fw_on_ctlr_build;
  592. } TW_Compatibility_Info;
  593. #pragma pack()
  594. typedef struct TAG_TW_Device_Extension {
  595. u32 __iomem *base_addr;
  596. unsigned long *generic_buffer_virt[TW_Q_LENGTH];
  597. dma_addr_t generic_buffer_phys[TW_Q_LENGTH];
  598. TW_Command_Full *command_packet_virt[TW_Q_LENGTH];
  599. dma_addr_t command_packet_phys[TW_Q_LENGTH];
  600. struct pci_dev *tw_pci_dev;
  601. struct scsi_cmnd *srb[TW_Q_LENGTH];
  602. unsigned char free_queue[TW_Q_LENGTH];
  603. unsigned char free_head;
  604. unsigned char free_tail;
  605. unsigned char pending_queue[TW_Q_LENGTH];
  606. unsigned char pending_head;
  607. unsigned char pending_tail;
  608. int state[TW_Q_LENGTH];
  609. unsigned int posted_request_count;
  610. unsigned int max_posted_request_count;
  611. unsigned int pending_request_count;
  612. unsigned int max_pending_request_count;
  613. unsigned int max_sgl_entries;
  614. unsigned int sgl_entries;
  615. unsigned int num_resets;
  616. unsigned int sector_count;
  617. unsigned int max_sector_count;
  618. unsigned int aen_count;
  619. struct Scsi_Host *host;
  620. long flags;
  621. int reset_print;
  622. TW_Event *event_queue[TW_Q_LENGTH];
  623. unsigned char error_index;
  624. unsigned char event_queue_wrapped;
  625. unsigned int error_sequence_id;
  626. int ioctl_sem_lock;
  627. u32 ioctl_msec;
  628. int chrdev_request_id;
  629. wait_queue_head_t ioctl_wqueue;
  630. struct mutex ioctl_lock;
  631. char aen_clobber;
  632. TW_Compatibility_Info tw_compat_info;
  633. } TW_Device_Extension;
  634. #endif /* _3W_9XXX_H */