pmcraid.h 35 KB

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