pmcraid.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  1. /*
  2. * pmcraid.h -- PMC Sierra MaxRAID controller driver header file
  3. *
  4. * Copyright (C) 2008, 2009 PMC Sierra Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #ifndef _PMCRAID_H
  21. #define _PMCRAID_H
  22. #include <linux/version.h>
  23. #include <linux/types.h>
  24. #include <linux/completion.h>
  25. #include <linux/list.h>
  26. #include <scsi/scsi.h>
  27. #include <linux/kref.h>
  28. #include <scsi/scsi_cmnd.h>
  29. #include <linux/cdev.h>
  30. #include <net/netlink.h>
  31. #include <net/genetlink.h>
  32. #include <linux/connector.h>
  33. /*
  34. * Driver name : string representing the driver name
  35. * Device file : /dev file to be used for management interfaces
  36. * Driver version: version string in major_version.minor_version.patch format
  37. * Driver date : date information in "Mon dd yyyy" format
  38. */
  39. #define PMCRAID_DRIVER_NAME "PMC MaxRAID"
  40. #define PMCRAID_DEVFILE "pmcsas"
  41. #define PMCRAID_DRIVER_VERSION "1.0.2"
  42. #define PMCRAID_DRIVER_DATE __DATE__
  43. /* Maximum number of adapters supported by current version of the driver */
  44. #define PMCRAID_MAX_ADAPTERS 1024
  45. /* Bit definitions as per firmware, bit position [0][1][2].....[31] */
  46. #define PMC_BIT8(n) (1 << (7-n))
  47. #define PMC_BIT16(n) (1 << (15-n))
  48. #define PMC_BIT32(n) (1 << (31-n))
  49. /* PMC PCI vendor ID and device ID values */
  50. #define PCI_VENDOR_ID_PMC 0x11F8
  51. #define PCI_DEVICE_ID_PMC_MAXRAID 0x5220
  52. /*
  53. * MAX_CMD : maximum commands that can be outstanding with IOA
  54. * MAX_IO_CMD : command blocks available for IO commands
  55. * MAX_HCAM_CMD : command blocks avaibale for HCAMS
  56. * MAX_INTERNAL_CMD : command blocks avaible for internal commands like reset
  57. */
  58. #define PMCRAID_MAX_CMD 1024
  59. #define PMCRAID_MAX_IO_CMD 1020
  60. #define PMCRAID_MAX_HCAM_CMD 2
  61. #define PMCRAID_MAX_INTERNAL_CMD 2
  62. /* MAX_IOADLS : max number of scatter-gather lists supported by IOA
  63. * IOADLS_INTERNAL : number of ioadls included as part of IOARCB.
  64. * IOADLS_EXTERNAL : number of ioadls allocated external to IOARCB
  65. */
  66. #define PMCRAID_IOADLS_INTERNAL 27
  67. #define PMCRAID_IOADLS_EXTERNAL 37
  68. #define PMCRAID_MAX_IOADLS PMCRAID_IOADLS_INTERNAL
  69. /* HRRQ_ENTRY_SIZE : size of hrrq buffer
  70. * IOARCB_ALIGNMENT : alignment required for IOARCB
  71. * IOADL_ALIGNMENT : alignment requirement for IOADLs
  72. * MSIX_VECTORS : number of MSIX vectors supported
  73. */
  74. #define HRRQ_ENTRY_SIZE sizeof(__le32)
  75. #define PMCRAID_IOARCB_ALIGNMENT 32
  76. #define PMCRAID_IOADL_ALIGNMENT 16
  77. #define PMCRAID_IOASA_ALIGNMENT 4
  78. #define PMCRAID_NUM_MSIX_VECTORS 1
  79. /* various other limits */
  80. #define PMCRAID_VENDOR_ID_LEN 8
  81. #define PMCRAID_PRODUCT_ID_LEN 16
  82. #define PMCRAID_SERIAL_NUM_LEN 8
  83. #define PMCRAID_LUN_LEN 8
  84. #define PMCRAID_MAX_CDB_LEN 16
  85. #define PMCRAID_DEVICE_ID_LEN 8
  86. #define PMCRAID_SENSE_DATA_LEN 256
  87. #define PMCRAID_ADD_CMD_PARAM_LEN 48
  88. #define PMCRAID_MAX_BUS_TO_SCAN 1
  89. #define PMCRAID_MAX_NUM_TARGETS_PER_BUS 256
  90. #define PMCRAID_MAX_NUM_LUNS_PER_TARGET 8
  91. /* IOA bus/target/lun number of IOA resources */
  92. #define PMCRAID_IOA_BUS_ID 0xfe
  93. #define PMCRAID_IOA_TARGET_ID 0xff
  94. #define PMCRAID_IOA_LUN_ID 0xff
  95. #define PMCRAID_VSET_BUS_ID 0x1
  96. #define PMCRAID_VSET_LUN_ID 0x0
  97. #define PMCRAID_PHYS_BUS_ID 0x0
  98. #define PMCRAID_VIRTUAL_ENCL_BUS_ID 0x8
  99. #define PMCRAID_MAX_VSET_TARGETS 240
  100. #define PMCRAID_MAX_VSET_LUNS_PER_TARGET 8
  101. #define PMCRAID_IOA_MAX_SECTORS 32767
  102. #define PMCRAID_VSET_MAX_SECTORS 512
  103. #define PMCRAID_MAX_CMD_PER_LUN 254
  104. /* Number of configuration table entries (resources) */
  105. #define PMCRAID_MAX_NUM_OF_VSETS 240
  106. /* Todo : Check max limit for Phase 1 */
  107. #define PMCRAID_MAX_NUM_OF_PHY_DEVS 256
  108. /* MAX_NUM_OF_DEVS includes 1 FP, 1 Dummy Enclosure device */
  109. #define PMCRAID_MAX_NUM_OF_DEVS \
  110. (PMCRAID_MAX_NUM_OF_VSETS + PMCRAID_MAX_NUM_OF_PHY_DEVS + 2)
  111. #define PMCRAID_MAX_RESOURCES PMCRAID_MAX_NUM_OF_DEVS
  112. /* Adapter Commands used by driver */
  113. #define PMCRAID_QUERY_RESOURCE_STATE 0xC2
  114. #define PMCRAID_RESET_DEVICE 0xC3
  115. /* options to select reset target */
  116. #define ENABLE_RESET_MODIFIER 0x80
  117. #define RESET_DEVICE_LUN 0x40
  118. #define RESET_DEVICE_TARGET 0x20
  119. #define RESET_DEVICE_BUS 0x10
  120. #define PMCRAID_IDENTIFY_HRRQ 0xC4
  121. #define PMCRAID_QUERY_IOA_CONFIG 0xC5
  122. #define PMCRAID_QUERY_CMD_STATUS 0xCB
  123. #define PMCRAID_ABORT_CMD 0xC7
  124. /* CANCEL ALL command, provides option for setting SYNC_COMPLETE
  125. * on the target resources for which commands got cancelled
  126. */
  127. #define PMCRAID_CANCEL_ALL_REQUESTS 0xCE
  128. #define PMCRAID_SYNC_COMPLETE_AFTER_CANCEL PMC_BIT8(0)
  129. /* HCAM command and types of HCAM supported by IOA */
  130. #define PMCRAID_HOST_CONTROLLED_ASYNC 0xCF
  131. #define PMCRAID_HCAM_CODE_CONFIG_CHANGE 0x01
  132. #define PMCRAID_HCAM_CODE_LOG_DATA 0x02
  133. /* IOA shutdown command and various shutdown types */
  134. #define PMCRAID_IOA_SHUTDOWN 0xF7
  135. #define PMCRAID_SHUTDOWN_NORMAL 0x00
  136. #define PMCRAID_SHUTDOWN_PREPARE_FOR_NORMAL 0x40
  137. #define PMCRAID_SHUTDOWN_NONE 0x100
  138. #define PMCRAID_SHUTDOWN_ABBREV 0x80
  139. /* SET SUPPORTED DEVICES command and the option to select all the
  140. * devices to be supported
  141. */
  142. #define PMCRAID_SET_SUPPORTED_DEVICES 0xFB
  143. #define ALL_DEVICES_SUPPORTED PMC_BIT8(0)
  144. /* This option is used with SCSI WRITE_BUFFER command */
  145. #define PMCRAID_WR_BUF_DOWNLOAD_AND_SAVE 0x05
  146. /* IOASC Codes used by driver */
  147. #define PMCRAID_IOASC_SENSE_MASK 0xFFFFFF00
  148. #define PMCRAID_IOASC_SENSE_KEY(ioasc) ((ioasc) >> 24)
  149. #define PMCRAID_IOASC_SENSE_CODE(ioasc) (((ioasc) & 0x00ff0000) >> 16)
  150. #define PMCRAID_IOASC_SENSE_QUAL(ioasc) (((ioasc) & 0x0000ff00) >> 8)
  151. #define PMCRAID_IOASC_SENSE_STATUS(ioasc) ((ioasc) & 0x000000ff)
  152. #define PMCRAID_IOASC_GOOD_COMPLETION 0x00000000
  153. #define PMCRAID_IOASC_NR_INIT_CMD_REQUIRED 0x02040200
  154. #define PMCRAID_IOASC_NR_IOA_RESET_REQUIRED 0x02048000
  155. #define PMCRAID_IOASC_NR_SYNC_REQUIRED 0x023F0000
  156. #define PMCRAID_IOASC_ME_READ_ERROR_NO_REALLOC 0x03110C00
  157. #define PMCRAID_IOASC_HW_CANNOT_COMMUNICATE 0x04050000
  158. #define PMCRAID_IOASC_HW_DEVICE_TIMEOUT 0x04080100
  159. #define PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR 0x04448500
  160. #define PMCRAID_IOASC_HW_IOA_RESET_REQUIRED 0x04448600
  161. #define PMCRAID_IOASC_IR_INVALID_RESOURCE_HANDLE 0x05250000
  162. #define PMCRAID_IOASC_AC_TERMINATED_BY_HOST 0x0B5A0000
  163. #define PMCRAID_IOASC_UA_BUS_WAS_RESET 0x06290000
  164. #define PMCRAID_IOASC_UA_BUS_WAS_RESET_BY_OTHER 0x06298000
  165. /* Driver defined IOASCs */
  166. #define PMCRAID_IOASC_IOA_WAS_RESET 0x10000001
  167. #define PMCRAID_IOASC_PCI_ACCESS_ERROR 0x10000002
  168. /* Various timeout values (in milliseconds) used. If any of these are chip
  169. * specific, move them to pmcraid_chip_details structure.
  170. */
  171. #define PMCRAID_PCI_DEASSERT_TIMEOUT 2000
  172. #define PMCRAID_BIST_TIMEOUT 2000
  173. #define PMCRAID_AENWAIT_TIMEOUT 5000
  174. #define PMCRAID_TRANSOP_TIMEOUT 60000
  175. #define PMCRAID_RESET_TIMEOUT (2 * HZ)
  176. #define PMCRAID_CHECK_FOR_RESET_TIMEOUT ((HZ / 10))
  177. #define PMCRAID_VSET_IO_TIMEOUT (60 * HZ)
  178. #define PMCRAID_INTERNAL_TIMEOUT (60 * HZ)
  179. #define PMCRAID_SHUTDOWN_TIMEOUT (150 * HZ)
  180. #define PMCRAID_RESET_BUS_TIMEOUT (60 * HZ)
  181. #define PMCRAID_RESET_HOST_TIMEOUT (150 * HZ)
  182. #define PMCRAID_REQUEST_SENSE_TIMEOUT (30 * HZ)
  183. #define PMCRAID_SET_SUP_DEV_TIMEOUT (2 * 60 * HZ)
  184. /* structure to represent a scatter-gather element (IOADL descriptor) */
  185. struct pmcraid_ioadl_desc {
  186. __le64 address;
  187. __le32 data_len;
  188. __u8 reserved[3];
  189. __u8 flags;
  190. } __attribute__((packed, aligned(PMCRAID_IOADL_ALIGNMENT)));
  191. /* pmcraid_ioadl_desc.flags values */
  192. #define IOADL_FLAGS_CHAINED PMC_BIT8(0)
  193. #define IOADL_FLAGS_LAST_DESC PMC_BIT8(1)
  194. #define IOADL_FLAGS_READ_LAST PMC_BIT8(1)
  195. #define IOADL_FLAGS_WRITE_LAST PMC_BIT8(1)
  196. /* additional IOARCB data which can be CDB or additional request parameters
  197. * or list of IOADLs. Firmware supports max of 512 bytes for IOARCB, hence then
  198. * number of IOADLs are limted to 27. In case they are more than 27, they will
  199. * be used in chained form
  200. */
  201. struct pmcraid_ioarcb_add_data {
  202. union {
  203. struct pmcraid_ioadl_desc ioadl[PMCRAID_IOADLS_INTERNAL];
  204. __u8 add_cmd_params[PMCRAID_ADD_CMD_PARAM_LEN];
  205. } u;
  206. };
  207. /*
  208. * IOA Request Control Block
  209. */
  210. struct pmcraid_ioarcb {
  211. __le64 ioarcb_bus_addr;
  212. __le32 resource_handle;
  213. __le32 response_handle;
  214. __le64 ioadl_bus_addr;
  215. __le32 ioadl_length;
  216. __le32 data_transfer_length;
  217. __le64 ioasa_bus_addr;
  218. __le16 ioasa_len;
  219. __le16 cmd_timeout;
  220. __le16 add_cmd_param_offset;
  221. __le16 add_cmd_param_length;
  222. __le32 reserved1[2];
  223. __le32 reserved2;
  224. __u8 request_type;
  225. __u8 request_flags0;
  226. __u8 request_flags1;
  227. __u8 hrrq_id;
  228. __u8 cdb[PMCRAID_MAX_CDB_LEN];
  229. struct pmcraid_ioarcb_add_data add_data;
  230. } __attribute__((packed, aligned(PMCRAID_IOARCB_ALIGNMENT)));
  231. /* well known resource handle values */
  232. #define PMCRAID_IOA_RES_HANDLE 0xffffffff
  233. #define PMCRAID_INVALID_RES_HANDLE 0
  234. /* pmcraid_ioarcb.request_type values */
  235. #define REQ_TYPE_SCSI 0x00
  236. #define REQ_TYPE_IOACMD 0x01
  237. #define REQ_TYPE_HCAM 0x02
  238. /* pmcraid_ioarcb.flags0 values */
  239. #define TRANSFER_DIR_WRITE PMC_BIT8(0)
  240. #define INHIBIT_UL_CHECK PMC_BIT8(2)
  241. #define SYNC_OVERRIDE PMC_BIT8(3)
  242. #define SYNC_COMPLETE PMC_BIT8(4)
  243. #define NO_LINK_DESCS PMC_BIT8(5)
  244. /* pmcraid_ioarcb.flags1 values */
  245. #define DELAY_AFTER_RESET PMC_BIT8(0)
  246. #define TASK_TAG_SIMPLE 0x10
  247. #define TASK_TAG_ORDERED 0x20
  248. #define TASK_TAG_QUEUE_HEAD 0x30
  249. /* toggle bit offset in response handle */
  250. #define HRRQ_TOGGLE_BIT 0x01
  251. #define HRRQ_RESPONSE_BIT 0x02
  252. /* IOA Status Area */
  253. struct pmcraid_ioasa_vset {
  254. __le32 failing_lba_hi;
  255. __le32 failing_lba_lo;
  256. __le32 reserved;
  257. } __attribute__((packed, aligned(4)));
  258. struct pmcraid_ioasa {
  259. __le32 ioasc;
  260. __le16 returned_status_length;
  261. __le16 available_status_length;
  262. __le32 residual_data_length;
  263. __le32 ilid;
  264. __le32 fd_ioasc;
  265. __le32 fd_res_address;
  266. __le32 fd_res_handle;
  267. __le32 reserved;
  268. /* resource specific sense information */
  269. union {
  270. struct pmcraid_ioasa_vset vset;
  271. } u;
  272. /* IOA autosense data */
  273. __le16 auto_sense_length;
  274. __le16 error_data_length;
  275. __u8 sense_data[PMCRAID_SENSE_DATA_LEN];
  276. } __attribute__((packed, aligned(4)));
  277. #define PMCRAID_DRIVER_ILID 0xffffffff
  278. /* Config Table Entry per Resource */
  279. struct pmcraid_config_table_entry {
  280. __u8 resource_type;
  281. __u8 bus_protocol;
  282. __le16 array_id;
  283. __u8 common_flags0;
  284. __u8 common_flags1;
  285. __u8 unique_flags0;
  286. __u8 unique_flags1; /*also used as vset target_id */
  287. __le32 resource_handle;
  288. __le32 resource_address;
  289. __u8 device_id[PMCRAID_DEVICE_ID_LEN];
  290. __u8 lun[PMCRAID_LUN_LEN];
  291. } __attribute__((packed, aligned(4)));
  292. /* resource types (config_table_entry.resource_type values) */
  293. #define RES_TYPE_AF_DASD 0x00
  294. #define RES_TYPE_GSCSI 0x01
  295. #define RES_TYPE_VSET 0x02
  296. #define RES_TYPE_IOA_FP 0xFF
  297. #define RES_IS_IOA(res) ((res).resource_type == RES_TYPE_IOA_FP)
  298. #define RES_IS_GSCSI(res) ((res).resource_type == RES_TYPE_GSCSI)
  299. #define RES_IS_VSET(res) ((res).resource_type == RES_TYPE_VSET)
  300. #define RES_IS_AFDASD(res) ((res).resource_type == RES_TYPE_AF_DASD)
  301. /* bus_protocol values used by driver */
  302. #define RES_TYPE_VENCLOSURE 0x8
  303. /* config_table_entry.common_flags0 */
  304. #define MULTIPATH_RESOURCE PMC_BIT32(0)
  305. /* unique_flags1 */
  306. #define IMPORT_MODE_MANUAL PMC_BIT8(0)
  307. /* well known resource handle values */
  308. #define RES_HANDLE_IOA 0xFFFFFFFF
  309. #define RES_HANDLE_NONE 0x00000000
  310. /* well known resource address values */
  311. #define RES_ADDRESS_IOAFP 0xFEFFFFFF
  312. #define RES_ADDRESS_INVALID 0xFFFFFFFF
  313. /* BUS/TARGET/LUN values from resource_addrr */
  314. #define RES_BUS(res_addr) (le32_to_cpu(res_addr) & 0xFF)
  315. #define RES_TARGET(res_addr) ((le32_to_cpu(res_addr) >> 16) & 0xFF)
  316. #define RES_LUN(res_addr) 0x0
  317. /* configuration table structure */
  318. struct pmcraid_config_table {
  319. __le16 num_entries;
  320. __u8 table_format;
  321. __u8 reserved1;
  322. __u8 flags;
  323. __u8 reserved2[11];
  324. struct pmcraid_config_table_entry entries[PMCRAID_MAX_RESOURCES];
  325. } __attribute__((packed, aligned(4)));
  326. /* config_table.flags value */
  327. #define MICROCODE_UPDATE_REQUIRED PMC_BIT32(0)
  328. /*
  329. * HCAM format
  330. */
  331. #define PMCRAID_HOSTRCB_LDNSIZE 4056
  332. /* Error log notification format */
  333. struct pmcraid_hostrcb_error {
  334. __le32 fd_ioasc;
  335. __le32 fd_ra;
  336. __le32 fd_rh;
  337. __le32 prc;
  338. union {
  339. __u8 data[PMCRAID_HOSTRCB_LDNSIZE];
  340. } u;
  341. } __attribute__ ((packed, aligned(4)));
  342. struct pmcraid_hcam_hdr {
  343. __u8 op_code;
  344. __u8 notification_type;
  345. __u8 notification_lost;
  346. __u8 flags;
  347. __u8 overlay_id;
  348. __u8 reserved1[3];
  349. __le32 ilid;
  350. __le32 timestamp1;
  351. __le32 timestamp2;
  352. __le32 data_len;
  353. } __attribute__((packed, aligned(4)));
  354. #define PMCRAID_AEN_GROUP 0x3
  355. struct pmcraid_hcam_ccn {
  356. struct pmcraid_hcam_hdr header;
  357. struct pmcraid_config_table_entry cfg_entry;
  358. } __attribute__((packed, aligned(4)));
  359. struct pmcraid_hcam_ldn {
  360. struct pmcraid_hcam_hdr header;
  361. struct pmcraid_hostrcb_error error_log;
  362. } __attribute__((packed, aligned(4)));
  363. /* pmcraid_hcam.op_code values */
  364. #define HOSTRCB_TYPE_CCN 0xE1
  365. #define HOSTRCB_TYPE_LDN 0xE2
  366. /* pmcraid_hcam.notification_type values */
  367. #define NOTIFICATION_TYPE_ENTRY_CHANGED 0x0
  368. #define NOTIFICATION_TYPE_ENTRY_NEW 0x1
  369. #define NOTIFICATION_TYPE_ENTRY_DELETED 0x2
  370. #define NOTIFICATION_TYPE_ERROR_LOG 0x10
  371. #define NOTIFICATION_TYPE_INFORMATION_LOG 0x11
  372. #define HOSTRCB_NOTIFICATIONS_LOST PMC_BIT8(0)
  373. /* pmcraid_hcam.flags values */
  374. #define HOSTRCB_INTERNAL_OP_ERROR PMC_BIT8(0)
  375. #define HOSTRCB_ERROR_RESPONSE_SENT PMC_BIT8(1)
  376. /* pmcraid_hcam.overlay_id values */
  377. #define HOSTRCB_OVERLAY_ID_08 0x08
  378. #define HOSTRCB_OVERLAY_ID_09 0x09
  379. #define HOSTRCB_OVERLAY_ID_11 0x11
  380. #define HOSTRCB_OVERLAY_ID_12 0x12
  381. #define HOSTRCB_OVERLAY_ID_13 0x13
  382. #define HOSTRCB_OVERLAY_ID_14 0x14
  383. #define HOSTRCB_OVERLAY_ID_16 0x16
  384. #define HOSTRCB_OVERLAY_ID_17 0x17
  385. #define HOSTRCB_OVERLAY_ID_20 0x20
  386. #define HOSTRCB_OVERLAY_ID_FF 0xFF
  387. /* Implementation specific card details */
  388. struct pmcraid_chip_details {
  389. /* hardware register offsets */
  390. unsigned long ioastatus;
  391. unsigned long ioarrin;
  392. unsigned long mailbox;
  393. unsigned long global_intr_mask;
  394. unsigned long ioa_host_intr;
  395. unsigned long ioa_host_intr_clr;
  396. unsigned long ioa_host_mask;
  397. unsigned long ioa_host_mask_clr;
  398. unsigned long host_ioa_intr;
  399. unsigned long host_ioa_intr_clr;
  400. /* timeout used during transitional to operational state */
  401. unsigned long transop_timeout;
  402. };
  403. /* IOA to HOST doorbells (interrupts) */
  404. #define INTRS_TRANSITION_TO_OPERATIONAL PMC_BIT32(0)
  405. #define INTRS_IOARCB_TRANSFER_FAILED PMC_BIT32(3)
  406. #define INTRS_IOA_UNIT_CHECK PMC_BIT32(4)
  407. #define INTRS_NO_HRRQ_FOR_CMD_RESPONSE PMC_BIT32(5)
  408. #define INTRS_CRITICAL_OP_IN_PROGRESS PMC_BIT32(6)
  409. #define INTRS_IO_DEBUG_ACK PMC_BIT32(7)
  410. #define INTRS_IOARRIN_LOST PMC_BIT32(27)
  411. #define INTRS_SYSTEM_BUS_MMIO_ERROR PMC_BIT32(28)
  412. #define INTRS_IOA_PROCESSOR_ERROR PMC_BIT32(29)
  413. #define INTRS_HRRQ_VALID PMC_BIT32(30)
  414. #define INTRS_OPERATIONAL_STATUS PMC_BIT32(0)
  415. /* Host to IOA Doorbells */
  416. #define DOORBELL_RUNTIME_RESET PMC_BIT32(1)
  417. #define DOORBELL_IOA_RESET_ALERT PMC_BIT32(7)
  418. #define DOORBELL_IOA_DEBUG_ALERT PMC_BIT32(9)
  419. #define DOORBELL_ENABLE_DESTRUCTIVE_DIAGS PMC_BIT32(8)
  420. #define DOORBELL_IOA_START_BIST PMC_BIT32(23)
  421. #define DOORBELL_RESET_IOA PMC_BIT32(31)
  422. /* Global interrupt mask register value */
  423. #define GLOBAL_INTERRUPT_MASK 0x4ULL
  424. #define PMCRAID_ERROR_INTERRUPTS (INTRS_IOARCB_TRANSFER_FAILED | \
  425. INTRS_IOA_UNIT_CHECK | \
  426. INTRS_NO_HRRQ_FOR_CMD_RESPONSE | \
  427. INTRS_IOARRIN_LOST | \
  428. INTRS_SYSTEM_BUS_MMIO_ERROR | \
  429. INTRS_IOA_PROCESSOR_ERROR)
  430. #define PMCRAID_PCI_INTERRUPTS (PMCRAID_ERROR_INTERRUPTS | \
  431. INTRS_HRRQ_VALID | \
  432. INTRS_CRITICAL_OP_IN_PROGRESS |\
  433. INTRS_TRANSITION_TO_OPERATIONAL)
  434. /* control_block, associated with each of the commands contains IOARCB, IOADLs
  435. * memory for IOASA. Additional 3 * 16 bytes are allocated in order to support
  436. * additional request parameters (of max size 48) any command.
  437. */
  438. struct pmcraid_control_block {
  439. struct pmcraid_ioarcb ioarcb;
  440. struct pmcraid_ioadl_desc ioadl[PMCRAID_IOADLS_EXTERNAL + 3];
  441. struct pmcraid_ioasa ioasa;
  442. } __attribute__ ((packed, aligned(PMCRAID_IOARCB_ALIGNMENT)));
  443. /* pmcraid_sglist - Scatter-gather list allocated for passthrough ioctls
  444. */
  445. struct pmcraid_sglist {
  446. u32 order;
  447. u32 num_sg;
  448. u32 num_dma_sg;
  449. u32 buffer_len;
  450. struct scatterlist scatterlist[1];
  451. };
  452. /* pmcraid_cmd - LLD representation of SCSI command */
  453. struct pmcraid_cmd {
  454. /* Ptr and bus address of DMA.able control block for this command */
  455. struct pmcraid_control_block *ioa_cb;
  456. dma_addr_t ioa_cb_bus_addr;
  457. /* sense buffer for REQUEST SENSE command if firmware is not sending
  458. * auto sense data
  459. */
  460. dma_addr_t sense_buffer_dma;
  461. dma_addr_t dma_handle;
  462. u8 *sense_buffer;
  463. /* pointer to mid layer structure of SCSI commands */
  464. struct scsi_cmnd *scsi_cmd;
  465. struct list_head free_list;
  466. struct completion wait_for_completion;
  467. struct timer_list timer; /* needed for internal commands */
  468. u32 timeout; /* current timeout value */
  469. u32 index; /* index into the command list */
  470. u8 completion_req; /* for handling internal commands */
  471. u8 release; /* for handling completions */
  472. void (*cmd_done) (struct pmcraid_cmd *);
  473. struct pmcraid_instance *drv_inst;
  474. struct pmcraid_sglist *sglist; /* used for passthrough IOCTLs */
  475. /* scratch used during reset sequence */
  476. union {
  477. unsigned long time_left;
  478. struct pmcraid_resource_entry *res;
  479. } u;
  480. };
  481. /*
  482. * Interrupt registers of IOA
  483. */
  484. struct pmcraid_interrupts {
  485. void __iomem *ioa_host_interrupt_reg;
  486. void __iomem *ioa_host_interrupt_clr_reg;
  487. void __iomem *ioa_host_interrupt_mask_reg;
  488. void __iomem *ioa_host_interrupt_mask_clr_reg;
  489. void __iomem *global_interrupt_mask_reg;
  490. void __iomem *host_ioa_interrupt_reg;
  491. void __iomem *host_ioa_interrupt_clr_reg;
  492. };
  493. /* ISR parameters LLD allocates (one for each MSI-X if enabled) vectors */
  494. struct pmcraid_isr_param {
  495. u8 hrrq_id; /* hrrq entry index */
  496. u16 vector; /* allocated msi-x vector */
  497. struct pmcraid_instance *drv_inst;
  498. };
  499. /* AEN message header sent as part of event data to applications */
  500. struct pmcraid_aen_msg {
  501. u32 hostno;
  502. u32 length;
  503. u8 reserved[8];
  504. u8 data[0];
  505. };
  506. struct pmcraid_hostrcb {
  507. struct pmcraid_instance *drv_inst;
  508. struct pmcraid_aen_msg *msg;
  509. struct pmcraid_hcam_hdr *hcam; /* pointer to hcam buffer */
  510. struct pmcraid_cmd *cmd; /* pointer to command block used */
  511. dma_addr_t baddr; /* system address of hcam buffer */
  512. atomic_t ignore; /* process HCAM response ? */
  513. };
  514. #define PMCRAID_AEN_HDR_SIZE sizeof(struct pmcraid_aen_msg)
  515. /*
  516. * Per adapter structure maintained by LLD
  517. */
  518. struct pmcraid_instance {
  519. /* Array of allowed-to-be-exposed resources, initialized from
  520. * Configutation Table, later updated with CCNs
  521. */
  522. struct pmcraid_resource_entry *res_entries;
  523. struct list_head free_res_q; /* res_entries lists for easy lookup */
  524. struct list_head used_res_q; /* List of to be exposed resources */
  525. spinlock_t resource_lock; /* spinlock to protect resource list */
  526. void __iomem *mapped_dma_addr;
  527. void __iomem *ioa_status; /* Iomapped IOA status register */
  528. void __iomem *mailbox; /* Iomapped mailbox register */
  529. void __iomem *ioarrin; /* IOmapped IOARR IN register */
  530. struct pmcraid_interrupts int_regs;
  531. struct pmcraid_chip_details *chip_cfg;
  532. /* HostRCBs needed for HCAM */
  533. struct pmcraid_hostrcb ldn;
  534. struct pmcraid_hostrcb ccn;
  535. /* Bus address of start of HRRQ */
  536. dma_addr_t hrrq_start_bus_addr[PMCRAID_NUM_MSIX_VECTORS];
  537. /* Pointer to 1st entry of HRRQ */
  538. __be32 *hrrq_start[PMCRAID_NUM_MSIX_VECTORS];
  539. /* Pointer to last entry of HRRQ */
  540. __be32 *hrrq_end[PMCRAID_NUM_MSIX_VECTORS];
  541. /* Pointer to current pointer of hrrq */
  542. __be32 *hrrq_curr[PMCRAID_NUM_MSIX_VECTORS];
  543. /* Lock for HRRQ access */
  544. spinlock_t hrrq_lock[PMCRAID_NUM_MSIX_VECTORS];
  545. /* Expected toggle bit at host */
  546. u8 host_toggle_bit[PMCRAID_NUM_MSIX_VECTORS];
  547. /* No of Reset IOA retries . IOA marked dead if threshold exceeds */
  548. u8 ioa_reset_attempts;
  549. #define PMCRAID_RESET_ATTEMPTS 3
  550. /* Wait Q for threads to wait for Reset IOA completion */
  551. wait_queue_head_t reset_wait_q;
  552. struct pmcraid_cmd *reset_cmd;
  553. /* structures for supporting SIGIO based AEN. */
  554. struct fasync_struct *aen_queue;
  555. struct mutex aen_queue_lock; /* lock for aen subscribers list */
  556. struct cdev cdev;
  557. struct Scsi_Host *host; /* mid layer interface structure handle */
  558. struct pci_dev *pdev; /* PCI device structure handle */
  559. u8 current_log_level; /* default level for logging IOASC errors */
  560. u8 num_hrrq; /* Number of interrupt vectors allocated */
  561. dev_t dev; /* Major-Minor numbers for Char device */
  562. /* Used as ISR handler argument */
  563. struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
  564. /* configuration table */
  565. struct pmcraid_config_table *cfg_table;
  566. dma_addr_t cfg_table_bus_addr;
  567. /* structures related to command blocks */
  568. struct kmem_cache *cmd_cachep; /* cache for cmd blocks */
  569. struct pci_pool *control_pool; /* pool for control blocks */
  570. char cmd_pool_name[64]; /* name of cmd cache */
  571. char ctl_pool_name[64]; /* name of control cache */
  572. struct pmcraid_cmd *cmd_list[PMCRAID_MAX_CMD];
  573. struct list_head free_cmd_pool;
  574. struct list_head pending_cmd_pool;
  575. spinlock_t free_pool_lock; /* free pool lock */
  576. spinlock_t pending_pool_lock; /* pending pool lock */
  577. /* No of IO commands pending with FW */
  578. atomic_t outstanding_cmds;
  579. /* should add/delete resources to mid-layer now ?*/
  580. atomic_t expose_resources;
  581. /* Tasklet to handle deferred processing */
  582. struct tasklet_struct isr_tasklet[PMCRAID_NUM_MSIX_VECTORS];
  583. /* Work-queue (Shared) for deferred reset processing */
  584. struct work_struct worker_q;
  585. u32 ioa_state:4; /* For IOA Reset sequence FSM */
  586. #define IOA_STATE_OPERATIONAL 0x0
  587. #define IOA_STATE_UNKNOWN 0x1
  588. #define IOA_STATE_DEAD 0x2
  589. #define IOA_STATE_IN_SOFT_RESET 0x3
  590. #define IOA_STATE_IN_HARD_RESET 0x4
  591. #define IOA_STATE_IN_RESET_ALERT 0x5
  592. #define IOA_STATE_IN_BRINGDOWN 0x6
  593. #define IOA_STATE_IN_BRINGUP 0x7
  594. u32 ioa_reset_in_progress:1; /* true if IOA reset is in progress */
  595. u32 ioa_hard_reset:1; /* TRUE if Hard Reset is needed */
  596. u32 ioa_unit_check:1; /* Indicates Unit Check condition */
  597. u32 ioa_bringdown:1; /* whether IOA needs to be brought down */
  598. u32 force_ioa_reset:1; /* force adapter reset ? */
  599. u32 reinit_cfg_table:1; /* reinit config table due to lost CCN */
  600. u32 ioa_shutdown_type:2;/* shutdown type used during reset */
  601. #define SHUTDOWN_NONE 0x0
  602. #define SHUTDOWN_NORMAL 0x1
  603. #define SHUTDOWN_ABBREV 0x2
  604. };
  605. /* LLD maintained resource entry structure */
  606. struct pmcraid_resource_entry {
  607. struct list_head queue; /* link to "to be exposed" resources */
  608. struct pmcraid_config_table_entry cfg_entry;
  609. struct scsi_device *scsi_dev; /* Link scsi_device structure */
  610. atomic_t read_failures; /* count of failed READ commands */
  611. atomic_t write_failures; /* count of failed WRITE commands */
  612. /* To indicate add/delete/modify during CCN */
  613. u8 change_detected;
  614. #define RES_CHANGE_ADD 0x1 /* add this to mid-layer */
  615. #define RES_CHANGE_DEL 0x2 /* remove this from mid-layer */
  616. u8 reset_progress; /* Device is resetting */
  617. /*
  618. * When IOA asks for sync (i.e. IOASC = Not Ready, Sync Required), this
  619. * flag will be set, mid layer will be asked to retry. In the next
  620. * attempt, this flag will be checked in queuecommand() to set
  621. * SYNC_COMPLETE flag in IOARCB (flag_0).
  622. */
  623. u8 sync_reqd;
  624. /* target indicates the mapped target_id assigned to this resource if
  625. * this is VSET resource. For non-VSET resources this will be un-used
  626. * or zero
  627. */
  628. u8 target;
  629. };
  630. /* Data structures used in IOASC error code logging */
  631. struct pmcraid_ioasc_error {
  632. u32 ioasc_code; /* IOASC code */
  633. u8 log_level; /* default log level assignment. */
  634. char *error_string;
  635. };
  636. /* Initial log_level assignments for various IOASCs */
  637. #define IOASC_LOG_LEVEL_NONE 0x0 /* no logging */
  638. #define IOASC_LOG_LEVEL_MUST 0x1 /* must log: all high-severity errors */
  639. #define IOASC_LOG_LEVEL_HARD 0x2 /* optional – low severity errors */
  640. /* Error information maintained by LLD. LLD initializes the pmcraid_error_table
  641. * statically.
  642. */
  643. static struct pmcraid_ioasc_error pmcraid_ioasc_error_table[] = {
  644. {0x01180600, IOASC_LOG_LEVEL_MUST,
  645. "Recovered Error, soft media error, sector reassignment suggested"},
  646. {0x015D0000, IOASC_LOG_LEVEL_MUST,
  647. "Recovered Error, failure prediction thresold exceeded"},
  648. {0x015D9200, IOASC_LOG_LEVEL_MUST,
  649. "Recovered Error, soft Cache Card Battery error thresold"},
  650. {0x015D9200, IOASC_LOG_LEVEL_MUST,
  651. "Recovered Error, soft Cache Card Battery error thresold"},
  652. {0x02048000, IOASC_LOG_LEVEL_MUST,
  653. "Not Ready, IOA Reset Required"},
  654. {0x02408500, IOASC_LOG_LEVEL_MUST,
  655. "Not Ready, IOA microcode download required"},
  656. {0x03110B00, IOASC_LOG_LEVEL_MUST,
  657. "Medium Error, data unreadable, reassignment suggested"},
  658. {0x03110C00, IOASC_LOG_LEVEL_MUST,
  659. "Medium Error, data unreadable do not reassign"},
  660. {0x03310000, IOASC_LOG_LEVEL_MUST,
  661. "Medium Error, media corrupted"},
  662. {0x04050000, IOASC_LOG_LEVEL_MUST,
  663. "Hardware Error, IOA can't communicate with device"},
  664. {0x04080000, IOASC_LOG_LEVEL_MUST,
  665. "Hardware Error, device bus error"},
  666. {0x04080000, IOASC_LOG_LEVEL_MUST,
  667. "Hardware Error, device bus is not functioning"},
  668. {0x04118000, IOASC_LOG_LEVEL_MUST,
  669. "Hardware Error, IOA reserved area data check"},
  670. {0x04118100, IOASC_LOG_LEVEL_MUST,
  671. "Hardware Error, IOA reserved area invalid data pattern"},
  672. {0x04118200, IOASC_LOG_LEVEL_MUST,
  673. "Hardware Error, IOA reserved area LRC error"},
  674. {0x04320000, IOASC_LOG_LEVEL_MUST,
  675. "Hardware Error, reassignment space exhausted"},
  676. {0x04330000, IOASC_LOG_LEVEL_MUST,
  677. "Hardware Error, data transfer underlength error"},
  678. {0x04330000, IOASC_LOG_LEVEL_MUST,
  679. "Hardware Error, data transfer overlength error"},
  680. {0x04418000, IOASC_LOG_LEVEL_MUST,
  681. "Hardware Error, PCI bus error"},
  682. {0x04440000, IOASC_LOG_LEVEL_MUST,
  683. "Hardware Error, device error"},
  684. {0x04448300, IOASC_LOG_LEVEL_MUST,
  685. "Hardware Error, undefined device response"},
  686. {0x04448400, IOASC_LOG_LEVEL_MUST,
  687. "Hardware Error, IOA microcode error"},
  688. {0x04448600, IOASC_LOG_LEVEL_MUST,
  689. "Hardware Error, IOA reset required"},
  690. {0x04449200, IOASC_LOG_LEVEL_MUST,
  691. "Hardware Error, hard Cache Fearuee Card Battery error"},
  692. {0x0444A000, IOASC_LOG_LEVEL_MUST,
  693. "Hardware Error, failed device altered"},
  694. {0x0444A200, IOASC_LOG_LEVEL_MUST,
  695. "Hardware Error, data check after reassignment"},
  696. {0x0444A300, IOASC_LOG_LEVEL_MUST,
  697. "Hardware Error, LRC error after reassignment"},
  698. {0x044A0000, IOASC_LOG_LEVEL_MUST,
  699. "Hardware Error, device bus error (msg/cmd phase)"},
  700. {0x04670400, IOASC_LOG_LEVEL_MUST,
  701. "Hardware Error, new device can't be used"},
  702. {0x04678000, IOASC_LOG_LEVEL_MUST,
  703. "Hardware Error, invalid multiadapter configuration"},
  704. {0x04678100, IOASC_LOG_LEVEL_MUST,
  705. "Hardware Error, incorrect connection between enclosures"},
  706. {0x04678200, IOASC_LOG_LEVEL_MUST,
  707. "Hardware Error, connections exceed IOA design limits"},
  708. {0x04678300, IOASC_LOG_LEVEL_MUST,
  709. "Hardware Error, incorrect multipath connection"},
  710. {0x04679000, IOASC_LOG_LEVEL_MUST,
  711. "Hardware Error, command to LUN failed"},
  712. {0x064C8000, IOASC_LOG_LEVEL_HARD,
  713. "Unit Attention, cache exists for missing/failed device"},
  714. {0x06670100, IOASC_LOG_LEVEL_HARD,
  715. "Unit Attention, incompatible exposed mode device"},
  716. {0x06670600, IOASC_LOG_LEVEL_HARD,
  717. "Unit Attention, attachment of logical unit failed"},
  718. {0x06678000, IOASC_LOG_LEVEL_MUST,
  719. "Unit Attention, cables exceed connective design limit"},
  720. {0x06678300, IOASC_LOG_LEVEL_MUST,
  721. "Unit Attention, incomplete multipath connection between" \
  722. "IOA and enclosure"},
  723. {0x06678400, IOASC_LOG_LEVEL_MUST,
  724. "Unit Attention, incomplete multipath connection between" \
  725. "device and enclosure"},
  726. {0x06678500, IOASC_LOG_LEVEL_MUST,
  727. "Unit Attention, incomplete multipath connection between" \
  728. "IOA and remote IOA"},
  729. {0x06678600, IOASC_LOG_LEVEL_HARD,
  730. "Unit Attention, missing remote IOA"},
  731. {0x06679100, IOASC_LOG_LEVEL_HARD,
  732. "Unit Attention, enclosure doesn't support required multipath" \
  733. "function"},
  734. {0x06698200, IOASC_LOG_LEVEL_HARD,
  735. "Unit Attention, corrupt array parity detected on device"},
  736. {0x066B0200, IOASC_LOG_LEVEL_MUST,
  737. "Unit Attention, array exposed"},
  738. {0x066B8200, IOASC_LOG_LEVEL_HARD,
  739. "Unit Attention, exposed array is still protected"},
  740. {0x066B9200, IOASC_LOG_LEVEL_MUST,
  741. "Unit Attention, Multipath redundancy level got worse"},
  742. {0x07270000, IOASC_LOG_LEVEL_HARD,
  743. "Data Protect, device is read/write protected by IOA"},
  744. {0x07278000, IOASC_LOG_LEVEL_HARD,
  745. "Data Protect, IOA doesn't support device attribute"},
  746. {0x07278100, IOASC_LOG_LEVEL_HARD,
  747. "Data Protect, NVRAM mirroring prohibited"},
  748. {0x07278400, IOASC_LOG_LEVEL_MUST,
  749. "Data Protect, array is short 2 or more devices"},
  750. {0x07278600, IOASC_LOG_LEVEL_MUST,
  751. "Data Protect, exposed array is short a required device"},
  752. {0x07278700, IOASC_LOG_LEVEL_MUST,
  753. "Data Protect, array members not at required addresses"},
  754. {0x07278800, IOASC_LOG_LEVEL_MUST,
  755. "Data Protect, exposed mode device resource address conflict"},
  756. {0x07278900, IOASC_LOG_LEVEL_MUST,
  757. "Data Protect, incorrect resource address of exposed mode device"},
  758. {0x07278A00, IOASC_LOG_LEVEL_MUST,
  759. "Data Protect, Array is missing a device and parity is out of sync"},
  760. {0x07278B00, IOASC_LOG_LEVEL_MUST,
  761. "Data Protect, maximum number of arrays already exist"},
  762. {0x07278C00, IOASC_LOG_LEVEL_HARD,
  763. "Data Protect, cannot locate cache data for device"},
  764. {0x07278D00, IOASC_LOG_LEVEL_HARD,
  765. "Data Protect, cache data exits for a changed device"},
  766. {0x07279100, IOASC_LOG_LEVEL_MUST,
  767. "Data Protect, detection of a device requiring format"},
  768. {0x07279200, IOASC_LOG_LEVEL_MUST,
  769. "Data Protect, IOA exceeds maximum number of devices"},
  770. {0x07279600, IOASC_LOG_LEVEL_MUST,
  771. "Data Protect, missing array, volume set is not functional"},
  772. {0x07279700, IOASC_LOG_LEVEL_MUST,
  773. "Data Protect, single device for a volume set"},
  774. {0x07279800, IOASC_LOG_LEVEL_MUST,
  775. "Data Protect, missing multiple devices for a volume set"},
  776. {0x07279900, IOASC_LOG_LEVEL_HARD,
  777. "Data Protect, maximum number of volument sets already exists"},
  778. {0x07279A00, IOASC_LOG_LEVEL_MUST,
  779. "Data Protect, other volume set problem"},
  780. };
  781. /* macros to help in debugging */
  782. #define pmcraid_err(...) \
  783. printk(KERN_ERR "MaxRAID: "__VA_ARGS__)
  784. #define pmcraid_info(...) \
  785. if (pmcraid_debug_log) \
  786. printk(KERN_INFO "MaxRAID: "__VA_ARGS__)
  787. /* check if given command is a SCSI READ or SCSI WRITE command */
  788. #define SCSI_READ_CMD 0x1 /* any of SCSI READ commands */
  789. #define SCSI_WRITE_CMD 0x2 /* any of SCSI WRITE commands */
  790. #define SCSI_CMD_TYPE(opcode) \
  791. ({ u8 op = opcode; u8 __type = 0;\
  792. if (op == READ_6 || op == READ_10 || op == READ_12 || op == READ_16)\
  793. __type = SCSI_READ_CMD;\
  794. else if (op == WRITE_6 || op == WRITE_10 || op == WRITE_12 || \
  795. op == WRITE_16)\
  796. __type = SCSI_WRITE_CMD;\
  797. __type;\
  798. })
  799. #define IS_SCSI_READ_WRITE(opcode) \
  800. ({ u8 __type = SCSI_CMD_TYPE(opcode); \
  801. (__type == SCSI_READ_CMD || __type == SCSI_WRITE_CMD) ? 1 : 0;\
  802. })
  803. /*
  804. * pmcraid_ioctl_header - definition of header structure that preceeds all the
  805. * buffers given as ioctl arguements.
  806. *
  807. * .signature : always ASCII string, "PMCRAID"
  808. * .reserved : not used
  809. * .buffer_length : length of the buffer following the header
  810. */
  811. struct pmcraid_ioctl_header {
  812. u8 signature[8];
  813. u32 reserved;
  814. u32 buffer_length;
  815. };
  816. #define PMCRAID_IOCTL_SIGNATURE "PMCRAID"
  817. /*
  818. * pmcraid_event_details - defines AEN details that apps can retrieve from LLD
  819. *
  820. * .rcb_ccn - complete RCB of CCN
  821. * .rcb_ldn - complete RCB of CCN
  822. */
  823. struct pmcraid_event_details {
  824. struct pmcraid_hcam_ccn rcb_ccn;
  825. struct pmcraid_hcam_ldn rcb_ldn;
  826. };
  827. /*
  828. * pmcraid_driver_ioctl_buffer - structure passed as argument to most of the
  829. * PMC driver handled ioctls.
  830. */
  831. struct pmcraid_driver_ioctl_buffer {
  832. struct pmcraid_ioctl_header ioctl_header;
  833. struct pmcraid_event_details event_details;
  834. };
  835. /*
  836. * pmcraid_passthrough_ioctl_buffer - structure given as argument to
  837. * passthrough(or firmware handled) IOCTL commands. Note that ioarcb requires
  838. * 32-byte alignment so, it is necessary to pack this structure to avoid any
  839. * holes between ioctl_header and passthrough buffer
  840. *
  841. * .ioactl_header : ioctl header
  842. * .ioarcb : filled-up ioarcb buffer, driver always reads this buffer
  843. * .ioasa : buffer for ioasa, driver fills this with IOASA from firmware
  844. * .request_buffer: The I/O buffer (flat), driver reads/writes to this based on
  845. * the transfer directions passed in ioarcb.flags0. Contents
  846. * of this buffer are valid only when ioarcb.data_transfer_len
  847. * is not zero.
  848. */
  849. struct pmcraid_passthrough_ioctl_buffer {
  850. struct pmcraid_ioctl_header ioctl_header;
  851. struct pmcraid_ioarcb ioarcb;
  852. struct pmcraid_ioasa ioasa;
  853. u8 request_buffer[1];
  854. } __attribute__ ((packed));
  855. /*
  856. * keys to differentiate between driver handled IOCTLs and passthrough
  857. * IOCTLs passed to IOA. driver determines the ioctl type using macro
  858. * _IOC_TYPE
  859. */
  860. #define PMCRAID_DRIVER_IOCTL 'D'
  861. #define PMCRAID_PASSTHROUGH_IOCTL 'F'
  862. #define DRV_IOCTL(n, size) \
  863. _IOC(_IOC_READ|_IOC_WRITE, PMCRAID_DRIVER_IOCTL, (n), (size))
  864. #define FMW_IOCTL(n, size) \
  865. _IOC(_IOC_READ|_IOC_WRITE, PMCRAID_PASSTHROUGH_IOCTL, (n), (size))
  866. /*
  867. * _ARGSIZE: macro that gives size of the argument type passed to an IOCTL cmd.
  868. * This is to facilitate applications avoiding un-necessary memory allocations.
  869. * For example, most of driver handled ioctls do not require ioarcb, ioasa.
  870. */
  871. #define _ARGSIZE(arg) (sizeof(struct pmcraid_ioctl_header) + sizeof(arg))
  872. /* Driver handled IOCTL command definitions */
  873. #define PMCRAID_IOCTL_RESET_ADAPTER \
  874. DRV_IOCTL(5, sizeof(struct pmcraid_ioctl_header))
  875. /* passthrough/firmware handled commands */
  876. #define PMCRAID_IOCTL_PASSTHROUGH_COMMAND \
  877. FMW_IOCTL(1, sizeof(struct pmcraid_passthrough_ioctl_buffer))
  878. #define PMCRAID_IOCTL_DOWNLOAD_MICROCODE \
  879. FMW_IOCTL(2, sizeof(struct pmcraid_passthrough_ioctl_buffer))
  880. #endif /* _PMCRAID_H */