pmcraid.h 35 KB

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