megaraid_sas.h 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  1. /*
  2. *
  3. * Linux MegaRAID driver for SAS based RAID controllers
  4. *
  5. * Copyright (c) 2003-2005 LSI Logic Corporation.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. *
  12. * FILE : megaraid_sas.h
  13. */
  14. #ifndef LSI_MEGARAID_SAS_H
  15. #define LSI_MEGARAID_SAS_H
  16. /*
  17. * MegaRAID SAS Driver meta data
  18. */
  19. #define MEGASAS_VERSION "00.00.03.10-rc5"
  20. #define MEGASAS_RELDATE "May 17, 2007"
  21. #define MEGASAS_EXT_VERSION "Thu May 17 10:09:32 PDT 2007"
  22. /*
  23. * Device IDs
  24. */
  25. #define PCI_DEVICE_ID_LSI_SAS1078R 0x0060
  26. #define PCI_DEVICE_ID_LSI_VERDE_ZCR 0x0413
  27. /*
  28. * =====================================
  29. * MegaRAID SAS MFI firmware definitions
  30. * =====================================
  31. */
  32. /*
  33. * MFI stands for MegaRAID SAS FW Interface. This is just a moniker for
  34. * protocol between the software and firmware. Commands are issued using
  35. * "message frames"
  36. */
  37. /*
  38. * FW posts its state in upper 4 bits of outbound_msg_0 register
  39. */
  40. #define MFI_STATE_MASK 0xF0000000
  41. #define MFI_STATE_UNDEFINED 0x00000000
  42. #define MFI_STATE_BB_INIT 0x10000000
  43. #define MFI_STATE_FW_INIT 0x40000000
  44. #define MFI_STATE_WAIT_HANDSHAKE 0x60000000
  45. #define MFI_STATE_FW_INIT_2 0x70000000
  46. #define MFI_STATE_DEVICE_SCAN 0x80000000
  47. #define MFI_STATE_BOOT_MESSAGE_PENDING 0x90000000
  48. #define MFI_STATE_FLUSH_CACHE 0xA0000000
  49. #define MFI_STATE_READY 0xB0000000
  50. #define MFI_STATE_OPERATIONAL 0xC0000000
  51. #define MFI_STATE_FAULT 0xF0000000
  52. #define MEGAMFI_FRAME_SIZE 64
  53. /*
  54. * During FW init, clear pending cmds & reset state using inbound_msg_0
  55. *
  56. * ABORT : Abort all pending cmds
  57. * READY : Move from OPERATIONAL to READY state; discard queue info
  58. * MFIMODE : Discard (possible) low MFA posted in 64-bit mode (??)
  59. * CLR_HANDSHAKE: FW is waiting for HANDSHAKE from BIOS or Driver
  60. * HOTPLUG : Resume from Hotplug
  61. * MFI_STOP_ADP : Send signal to FW to stop processing
  62. */
  63. #define MFI_INIT_ABORT 0x00000001
  64. #define MFI_INIT_READY 0x00000002
  65. #define MFI_INIT_MFIMODE 0x00000004
  66. #define MFI_INIT_CLEAR_HANDSHAKE 0x00000008
  67. #define MFI_INIT_HOTPLUG 0x00000010
  68. #define MFI_STOP_ADP 0x00000020
  69. #define MFI_RESET_FLAGS MFI_INIT_READY| \
  70. MFI_INIT_MFIMODE| \
  71. MFI_INIT_ABORT
  72. /*
  73. * MFI frame flags
  74. */
  75. #define MFI_FRAME_POST_IN_REPLY_QUEUE 0x0000
  76. #define MFI_FRAME_DONT_POST_IN_REPLY_QUEUE 0x0001
  77. #define MFI_FRAME_SGL32 0x0000
  78. #define MFI_FRAME_SGL64 0x0002
  79. #define MFI_FRAME_SENSE32 0x0000
  80. #define MFI_FRAME_SENSE64 0x0004
  81. #define MFI_FRAME_DIR_NONE 0x0000
  82. #define MFI_FRAME_DIR_WRITE 0x0008
  83. #define MFI_FRAME_DIR_READ 0x0010
  84. #define MFI_FRAME_DIR_BOTH 0x0018
  85. /*
  86. * Definition for cmd_status
  87. */
  88. #define MFI_CMD_STATUS_POLL_MODE 0xFF
  89. /*
  90. * MFI command opcodes
  91. */
  92. #define MFI_CMD_INIT 0x00
  93. #define MFI_CMD_LD_READ 0x01
  94. #define MFI_CMD_LD_WRITE 0x02
  95. #define MFI_CMD_LD_SCSI_IO 0x03
  96. #define MFI_CMD_PD_SCSI_IO 0x04
  97. #define MFI_CMD_DCMD 0x05
  98. #define MFI_CMD_ABORT 0x06
  99. #define MFI_CMD_SMP 0x07
  100. #define MFI_CMD_STP 0x08
  101. #define MR_DCMD_CTRL_GET_INFO 0x01010000
  102. #define MR_DCMD_CTRL_CACHE_FLUSH 0x01101000
  103. #define MR_FLUSH_CTRL_CACHE 0x01
  104. #define MR_FLUSH_DISK_CACHE 0x02
  105. #define MR_DCMD_CTRL_SHUTDOWN 0x01050000
  106. #define MR_ENABLE_DRIVE_SPINDOWN 0x01
  107. #define MR_DCMD_CTRL_EVENT_GET_INFO 0x01040100
  108. #define MR_DCMD_CTRL_EVENT_GET 0x01040300
  109. #define MR_DCMD_CTRL_EVENT_WAIT 0x01040500
  110. #define MR_DCMD_LD_GET_PROPERTIES 0x03030000
  111. #define MR_DCMD_CLUSTER 0x08000000
  112. #define MR_DCMD_CLUSTER_RESET_ALL 0x08010100
  113. #define MR_DCMD_CLUSTER_RESET_LD 0x08010200
  114. /*
  115. * MFI command completion codes
  116. */
  117. enum MFI_STAT {
  118. MFI_STAT_OK = 0x00,
  119. MFI_STAT_INVALID_CMD = 0x01,
  120. MFI_STAT_INVALID_DCMD = 0x02,
  121. MFI_STAT_INVALID_PARAMETER = 0x03,
  122. MFI_STAT_INVALID_SEQUENCE_NUMBER = 0x04,
  123. MFI_STAT_ABORT_NOT_POSSIBLE = 0x05,
  124. MFI_STAT_APP_HOST_CODE_NOT_FOUND = 0x06,
  125. MFI_STAT_APP_IN_USE = 0x07,
  126. MFI_STAT_APP_NOT_INITIALIZED = 0x08,
  127. MFI_STAT_ARRAY_INDEX_INVALID = 0x09,
  128. MFI_STAT_ARRAY_ROW_NOT_EMPTY = 0x0a,
  129. MFI_STAT_CONFIG_RESOURCE_CONFLICT = 0x0b,
  130. MFI_STAT_DEVICE_NOT_FOUND = 0x0c,
  131. MFI_STAT_DRIVE_TOO_SMALL = 0x0d,
  132. MFI_STAT_FLASH_ALLOC_FAIL = 0x0e,
  133. MFI_STAT_FLASH_BUSY = 0x0f,
  134. MFI_STAT_FLASH_ERROR = 0x10,
  135. MFI_STAT_FLASH_IMAGE_BAD = 0x11,
  136. MFI_STAT_FLASH_IMAGE_INCOMPLETE = 0x12,
  137. MFI_STAT_FLASH_NOT_OPEN = 0x13,
  138. MFI_STAT_FLASH_NOT_STARTED = 0x14,
  139. MFI_STAT_FLUSH_FAILED = 0x15,
  140. MFI_STAT_HOST_CODE_NOT_FOUNT = 0x16,
  141. MFI_STAT_LD_CC_IN_PROGRESS = 0x17,
  142. MFI_STAT_LD_INIT_IN_PROGRESS = 0x18,
  143. MFI_STAT_LD_LBA_OUT_OF_RANGE = 0x19,
  144. MFI_STAT_LD_MAX_CONFIGURED = 0x1a,
  145. MFI_STAT_LD_NOT_OPTIMAL = 0x1b,
  146. MFI_STAT_LD_RBLD_IN_PROGRESS = 0x1c,
  147. MFI_STAT_LD_RECON_IN_PROGRESS = 0x1d,
  148. MFI_STAT_LD_WRONG_RAID_LEVEL = 0x1e,
  149. MFI_STAT_MAX_SPARES_EXCEEDED = 0x1f,
  150. MFI_STAT_MEMORY_NOT_AVAILABLE = 0x20,
  151. MFI_STAT_MFC_HW_ERROR = 0x21,
  152. MFI_STAT_NO_HW_PRESENT = 0x22,
  153. MFI_STAT_NOT_FOUND = 0x23,
  154. MFI_STAT_NOT_IN_ENCL = 0x24,
  155. MFI_STAT_PD_CLEAR_IN_PROGRESS = 0x25,
  156. MFI_STAT_PD_TYPE_WRONG = 0x26,
  157. MFI_STAT_PR_DISABLED = 0x27,
  158. MFI_STAT_ROW_INDEX_INVALID = 0x28,
  159. MFI_STAT_SAS_CONFIG_INVALID_ACTION = 0x29,
  160. MFI_STAT_SAS_CONFIG_INVALID_DATA = 0x2a,
  161. MFI_STAT_SAS_CONFIG_INVALID_PAGE = 0x2b,
  162. MFI_STAT_SAS_CONFIG_INVALID_TYPE = 0x2c,
  163. MFI_STAT_SCSI_DONE_WITH_ERROR = 0x2d,
  164. MFI_STAT_SCSI_IO_FAILED = 0x2e,
  165. MFI_STAT_SCSI_RESERVATION_CONFLICT = 0x2f,
  166. MFI_STAT_SHUTDOWN_FAILED = 0x30,
  167. MFI_STAT_TIME_NOT_SET = 0x31,
  168. MFI_STAT_WRONG_STATE = 0x32,
  169. MFI_STAT_LD_OFFLINE = 0x33,
  170. MFI_STAT_PEER_NOTIFICATION_REJECTED = 0x34,
  171. MFI_STAT_PEER_NOTIFICATION_FAILED = 0x35,
  172. MFI_STAT_RESERVATION_IN_PROGRESS = 0x36,
  173. MFI_STAT_I2C_ERRORS_DETECTED = 0x37,
  174. MFI_STAT_PCI_ERRORS_DETECTED = 0x38,
  175. MFI_STAT_INVALID_STATUS = 0xFF
  176. };
  177. /*
  178. * Number of mailbox bytes in DCMD message frame
  179. */
  180. #define MFI_MBOX_SIZE 12
  181. enum MR_EVT_CLASS {
  182. MR_EVT_CLASS_DEBUG = -2,
  183. MR_EVT_CLASS_PROGRESS = -1,
  184. MR_EVT_CLASS_INFO = 0,
  185. MR_EVT_CLASS_WARNING = 1,
  186. MR_EVT_CLASS_CRITICAL = 2,
  187. MR_EVT_CLASS_FATAL = 3,
  188. MR_EVT_CLASS_DEAD = 4,
  189. };
  190. enum MR_EVT_LOCALE {
  191. MR_EVT_LOCALE_LD = 0x0001,
  192. MR_EVT_LOCALE_PD = 0x0002,
  193. MR_EVT_LOCALE_ENCL = 0x0004,
  194. MR_EVT_LOCALE_BBU = 0x0008,
  195. MR_EVT_LOCALE_SAS = 0x0010,
  196. MR_EVT_LOCALE_CTRL = 0x0020,
  197. MR_EVT_LOCALE_CONFIG = 0x0040,
  198. MR_EVT_LOCALE_CLUSTER = 0x0080,
  199. MR_EVT_LOCALE_ALL = 0xffff,
  200. };
  201. enum MR_EVT_ARGS {
  202. MR_EVT_ARGS_NONE,
  203. MR_EVT_ARGS_CDB_SENSE,
  204. MR_EVT_ARGS_LD,
  205. MR_EVT_ARGS_LD_COUNT,
  206. MR_EVT_ARGS_LD_LBA,
  207. MR_EVT_ARGS_LD_OWNER,
  208. MR_EVT_ARGS_LD_LBA_PD_LBA,
  209. MR_EVT_ARGS_LD_PROG,
  210. MR_EVT_ARGS_LD_STATE,
  211. MR_EVT_ARGS_LD_STRIP,
  212. MR_EVT_ARGS_PD,
  213. MR_EVT_ARGS_PD_ERR,
  214. MR_EVT_ARGS_PD_LBA,
  215. MR_EVT_ARGS_PD_LBA_LD,
  216. MR_EVT_ARGS_PD_PROG,
  217. MR_EVT_ARGS_PD_STATE,
  218. MR_EVT_ARGS_PCI,
  219. MR_EVT_ARGS_RATE,
  220. MR_EVT_ARGS_STR,
  221. MR_EVT_ARGS_TIME,
  222. MR_EVT_ARGS_ECC,
  223. };
  224. /*
  225. * SAS controller properties
  226. */
  227. struct megasas_ctrl_prop {
  228. u16 seq_num;
  229. u16 pred_fail_poll_interval;
  230. u16 intr_throttle_count;
  231. u16 intr_throttle_timeouts;
  232. u8 rebuild_rate;
  233. u8 patrol_read_rate;
  234. u8 bgi_rate;
  235. u8 cc_rate;
  236. u8 recon_rate;
  237. u8 cache_flush_interval;
  238. u8 spinup_drv_count;
  239. u8 spinup_delay;
  240. u8 cluster_enable;
  241. u8 coercion_mode;
  242. u8 alarm_enable;
  243. u8 disable_auto_rebuild;
  244. u8 disable_battery_warn;
  245. u8 ecc_bucket_size;
  246. u16 ecc_bucket_leak_rate;
  247. u8 restore_hotspare_on_insertion;
  248. u8 expose_encl_devices;
  249. u8 reserved[38];
  250. } __attribute__ ((packed));
  251. /*
  252. * SAS controller information
  253. */
  254. struct megasas_ctrl_info {
  255. /*
  256. * PCI device information
  257. */
  258. struct {
  259. u16 vendor_id;
  260. u16 device_id;
  261. u16 sub_vendor_id;
  262. u16 sub_device_id;
  263. u8 reserved[24];
  264. } __attribute__ ((packed)) pci;
  265. /*
  266. * Host interface information
  267. */
  268. struct {
  269. u8 PCIX:1;
  270. u8 PCIE:1;
  271. u8 iSCSI:1;
  272. u8 SAS_3G:1;
  273. u8 reserved_0:4;
  274. u8 reserved_1[6];
  275. u8 port_count;
  276. u64 port_addr[8];
  277. } __attribute__ ((packed)) host_interface;
  278. /*
  279. * Device (backend) interface information
  280. */
  281. struct {
  282. u8 SPI:1;
  283. u8 SAS_3G:1;
  284. u8 SATA_1_5G:1;
  285. u8 SATA_3G:1;
  286. u8 reserved_0:4;
  287. u8 reserved_1[6];
  288. u8 port_count;
  289. u64 port_addr[8];
  290. } __attribute__ ((packed)) device_interface;
  291. /*
  292. * List of components residing in flash. All str are null terminated
  293. */
  294. u32 image_check_word;
  295. u32 image_component_count;
  296. struct {
  297. char name[8];
  298. char version[32];
  299. char build_date[16];
  300. char built_time[16];
  301. } __attribute__ ((packed)) image_component[8];
  302. /*
  303. * List of flash components that have been flashed on the card, but
  304. * are not in use, pending reset of the adapter. This list will be
  305. * empty if a flash operation has not occurred. All stings are null
  306. * terminated
  307. */
  308. u32 pending_image_component_count;
  309. struct {
  310. char name[8];
  311. char version[32];
  312. char build_date[16];
  313. char build_time[16];
  314. } __attribute__ ((packed)) pending_image_component[8];
  315. u8 max_arms;
  316. u8 max_spans;
  317. u8 max_arrays;
  318. u8 max_lds;
  319. char product_name[80];
  320. char serial_no[32];
  321. /*
  322. * Other physical/controller/operation information. Indicates the
  323. * presence of the hardware
  324. */
  325. struct {
  326. u32 bbu:1;
  327. u32 alarm:1;
  328. u32 nvram:1;
  329. u32 uart:1;
  330. u32 reserved:28;
  331. } __attribute__ ((packed)) hw_present;
  332. u32 current_fw_time;
  333. /*
  334. * Maximum data transfer sizes
  335. */
  336. u16 max_concurrent_cmds;
  337. u16 max_sge_count;
  338. u32 max_request_size;
  339. /*
  340. * Logical and physical device counts
  341. */
  342. u16 ld_present_count;
  343. u16 ld_degraded_count;
  344. u16 ld_offline_count;
  345. u16 pd_present_count;
  346. u16 pd_disk_present_count;
  347. u16 pd_disk_pred_failure_count;
  348. u16 pd_disk_failed_count;
  349. /*
  350. * Memory size information
  351. */
  352. u16 nvram_size;
  353. u16 memory_size;
  354. u16 flash_size;
  355. /*
  356. * Error counters
  357. */
  358. u16 mem_correctable_error_count;
  359. u16 mem_uncorrectable_error_count;
  360. /*
  361. * Cluster information
  362. */
  363. u8 cluster_permitted;
  364. u8 cluster_active;
  365. /*
  366. * Additional max data transfer sizes
  367. */
  368. u16 max_strips_per_io;
  369. /*
  370. * Controller capabilities structures
  371. */
  372. struct {
  373. u32 raid_level_0:1;
  374. u32 raid_level_1:1;
  375. u32 raid_level_5:1;
  376. u32 raid_level_1E:1;
  377. u32 raid_level_6:1;
  378. u32 reserved:27;
  379. } __attribute__ ((packed)) raid_levels;
  380. struct {
  381. u32 rbld_rate:1;
  382. u32 cc_rate:1;
  383. u32 bgi_rate:1;
  384. u32 recon_rate:1;
  385. u32 patrol_rate:1;
  386. u32 alarm_control:1;
  387. u32 cluster_supported:1;
  388. u32 bbu:1;
  389. u32 spanning_allowed:1;
  390. u32 dedicated_hotspares:1;
  391. u32 revertible_hotspares:1;
  392. u32 foreign_config_import:1;
  393. u32 self_diagnostic:1;
  394. u32 mixed_redundancy_arr:1;
  395. u32 global_hot_spares:1;
  396. u32 reserved:17;
  397. } __attribute__ ((packed)) adapter_operations;
  398. struct {
  399. u32 read_policy:1;
  400. u32 write_policy:1;
  401. u32 io_policy:1;
  402. u32 access_policy:1;
  403. u32 disk_cache_policy:1;
  404. u32 reserved:27;
  405. } __attribute__ ((packed)) ld_operations;
  406. struct {
  407. u8 min;
  408. u8 max;
  409. u8 reserved[2];
  410. } __attribute__ ((packed)) stripe_sz_ops;
  411. struct {
  412. u32 force_online:1;
  413. u32 force_offline:1;
  414. u32 force_rebuild:1;
  415. u32 reserved:29;
  416. } __attribute__ ((packed)) pd_operations;
  417. struct {
  418. u32 ctrl_supports_sas:1;
  419. u32 ctrl_supports_sata:1;
  420. u32 allow_mix_in_encl:1;
  421. u32 allow_mix_in_ld:1;
  422. u32 allow_sata_in_cluster:1;
  423. u32 reserved:27;
  424. } __attribute__ ((packed)) pd_mix_support;
  425. /*
  426. * Define ECC single-bit-error bucket information
  427. */
  428. u8 ecc_bucket_count;
  429. u8 reserved_2[11];
  430. /*
  431. * Include the controller properties (changeable items)
  432. */
  433. struct megasas_ctrl_prop properties;
  434. /*
  435. * Define FW pkg version (set in envt v'bles on OEM basis)
  436. */
  437. char package_version[0x60];
  438. u8 pad[0x800 - 0x6a0];
  439. } __attribute__ ((packed));
  440. /*
  441. * ===============================
  442. * MegaRAID SAS driver definitions
  443. * ===============================
  444. */
  445. #define MEGASAS_MAX_PD_CHANNELS 2
  446. #define MEGASAS_MAX_LD_CHANNELS 2
  447. #define MEGASAS_MAX_CHANNELS (MEGASAS_MAX_PD_CHANNELS + \
  448. MEGASAS_MAX_LD_CHANNELS)
  449. #define MEGASAS_MAX_DEV_PER_CHANNEL 128
  450. #define MEGASAS_DEFAULT_INIT_ID -1
  451. #define MEGASAS_MAX_LUN 8
  452. #define MEGASAS_MAX_LD 64
  453. #define MEGASAS_DBG_LVL 1
  454. #define MEGASAS_FW_BUSY 1
  455. /*
  456. * When SCSI mid-layer calls driver's reset routine, driver waits for
  457. * MEGASAS_RESET_WAIT_TIME seconds for all outstanding IO to complete. Note
  458. * that the driver cannot _actually_ abort or reset pending commands. While
  459. * it is waiting for the commands to complete, it prints a diagnostic message
  460. * every MEGASAS_RESET_NOTICE_INTERVAL seconds
  461. */
  462. #define MEGASAS_RESET_WAIT_TIME 180
  463. #define MEGASAS_INTERNAL_CMD_WAIT_TIME 180
  464. #define MEGASAS_RESET_NOTICE_INTERVAL 5
  465. #define MEGASAS_IOCTL_CMD 0
  466. #define MEGASAS_DEFAULT_CMD_TIMEOUT 90
  467. /*
  468. * FW reports the maximum of number of commands that it can accept (maximum
  469. * commands that can be outstanding) at any time. The driver must report a
  470. * lower number to the mid layer because it can issue a few internal commands
  471. * itself (E.g, AEN, abort cmd, IOCTLs etc). The number of commands it needs
  472. * is shown below
  473. */
  474. #define MEGASAS_INT_CMDS 32
  475. /*
  476. * FW can accept both 32 and 64 bit SGLs. We want to allocate 32/64 bit
  477. * SGLs based on the size of dma_addr_t
  478. */
  479. #define IS_DMA64 (sizeof(dma_addr_t) == 8)
  480. #define MFI_OB_INTR_STATUS_MASK 0x00000002
  481. #define MFI_POLL_TIMEOUT_SECS 10
  482. #define MFI_REPLY_1078_MESSAGE_INTERRUPT 0x80000000
  483. /*
  484. * register set for both 1068 and 1078 controllers
  485. * structure extended for 1078 registers
  486. */
  487. struct megasas_register_set {
  488. u32 reserved_0[4]; /*0000h*/
  489. u32 inbound_msg_0; /*0010h*/
  490. u32 inbound_msg_1; /*0014h*/
  491. u32 outbound_msg_0; /*0018h*/
  492. u32 outbound_msg_1; /*001Ch*/
  493. u32 inbound_doorbell; /*0020h*/
  494. u32 inbound_intr_status; /*0024h*/
  495. u32 inbound_intr_mask; /*0028h*/
  496. u32 outbound_doorbell; /*002Ch*/
  497. u32 outbound_intr_status; /*0030h*/
  498. u32 outbound_intr_mask; /*0034h*/
  499. u32 reserved_1[2]; /*0038h*/
  500. u32 inbound_queue_port; /*0040h*/
  501. u32 outbound_queue_port; /*0044h*/
  502. u32 reserved_2[22]; /*0048h*/
  503. u32 outbound_doorbell_clear; /*00A0h*/
  504. u32 reserved_3[3]; /*00A4h*/
  505. u32 outbound_scratch_pad ; /*00B0h*/
  506. u32 reserved_4[3]; /*00B4h*/
  507. u32 inbound_low_queue_port ; /*00C0h*/
  508. u32 inbound_high_queue_port ; /*00C4h*/
  509. u32 reserved_5; /*00C8h*/
  510. u32 index_registers[820]; /*00CCh*/
  511. } __attribute__ ((packed));
  512. struct megasas_sge32 {
  513. u32 phys_addr;
  514. u32 length;
  515. } __attribute__ ((packed));
  516. struct megasas_sge64 {
  517. u64 phys_addr;
  518. u32 length;
  519. } __attribute__ ((packed));
  520. union megasas_sgl {
  521. struct megasas_sge32 sge32[1];
  522. struct megasas_sge64 sge64[1];
  523. } __attribute__ ((packed));
  524. struct megasas_header {
  525. u8 cmd; /*00h */
  526. u8 sense_len; /*01h */
  527. u8 cmd_status; /*02h */
  528. u8 scsi_status; /*03h */
  529. u8 target_id; /*04h */
  530. u8 lun; /*05h */
  531. u8 cdb_len; /*06h */
  532. u8 sge_count; /*07h */
  533. u32 context; /*08h */
  534. u32 pad_0; /*0Ch */
  535. u16 flags; /*10h */
  536. u16 timeout; /*12h */
  537. u32 data_xferlen; /*14h */
  538. } __attribute__ ((packed));
  539. union megasas_sgl_frame {
  540. struct megasas_sge32 sge32[8];
  541. struct megasas_sge64 sge64[5];
  542. } __attribute__ ((packed));
  543. struct megasas_init_frame {
  544. u8 cmd; /*00h */
  545. u8 reserved_0; /*01h */
  546. u8 cmd_status; /*02h */
  547. u8 reserved_1; /*03h */
  548. u32 reserved_2; /*04h */
  549. u32 context; /*08h */
  550. u32 pad_0; /*0Ch */
  551. u16 flags; /*10h */
  552. u16 reserved_3; /*12h */
  553. u32 data_xfer_len; /*14h */
  554. u32 queue_info_new_phys_addr_lo; /*18h */
  555. u32 queue_info_new_phys_addr_hi; /*1Ch */
  556. u32 queue_info_old_phys_addr_lo; /*20h */
  557. u32 queue_info_old_phys_addr_hi; /*24h */
  558. u32 reserved_4[6]; /*28h */
  559. } __attribute__ ((packed));
  560. struct megasas_init_queue_info {
  561. u32 init_flags; /*00h */
  562. u32 reply_queue_entries; /*04h */
  563. u32 reply_queue_start_phys_addr_lo; /*08h */
  564. u32 reply_queue_start_phys_addr_hi; /*0Ch */
  565. u32 producer_index_phys_addr_lo; /*10h */
  566. u32 producer_index_phys_addr_hi; /*14h */
  567. u32 consumer_index_phys_addr_lo; /*18h */
  568. u32 consumer_index_phys_addr_hi; /*1Ch */
  569. } __attribute__ ((packed));
  570. struct megasas_io_frame {
  571. u8 cmd; /*00h */
  572. u8 sense_len; /*01h */
  573. u8 cmd_status; /*02h */
  574. u8 scsi_status; /*03h */
  575. u8 target_id; /*04h */
  576. u8 access_byte; /*05h */
  577. u8 reserved_0; /*06h */
  578. u8 sge_count; /*07h */
  579. u32 context; /*08h */
  580. u32 pad_0; /*0Ch */
  581. u16 flags; /*10h */
  582. u16 timeout; /*12h */
  583. u32 lba_count; /*14h */
  584. u32 sense_buf_phys_addr_lo; /*18h */
  585. u32 sense_buf_phys_addr_hi; /*1Ch */
  586. u32 start_lba_lo; /*20h */
  587. u32 start_lba_hi; /*24h */
  588. union megasas_sgl sgl; /*28h */
  589. } __attribute__ ((packed));
  590. struct megasas_pthru_frame {
  591. u8 cmd; /*00h */
  592. u8 sense_len; /*01h */
  593. u8 cmd_status; /*02h */
  594. u8 scsi_status; /*03h */
  595. u8 target_id; /*04h */
  596. u8 lun; /*05h */
  597. u8 cdb_len; /*06h */
  598. u8 sge_count; /*07h */
  599. u32 context; /*08h */
  600. u32 pad_0; /*0Ch */
  601. u16 flags; /*10h */
  602. u16 timeout; /*12h */
  603. u32 data_xfer_len; /*14h */
  604. u32 sense_buf_phys_addr_lo; /*18h */
  605. u32 sense_buf_phys_addr_hi; /*1Ch */
  606. u8 cdb[16]; /*20h */
  607. union megasas_sgl sgl; /*30h */
  608. } __attribute__ ((packed));
  609. struct megasas_dcmd_frame {
  610. u8 cmd; /*00h */
  611. u8 reserved_0; /*01h */
  612. u8 cmd_status; /*02h */
  613. u8 reserved_1[4]; /*03h */
  614. u8 sge_count; /*07h */
  615. u32 context; /*08h */
  616. u32 pad_0; /*0Ch */
  617. u16 flags; /*10h */
  618. u16 timeout; /*12h */
  619. u32 data_xfer_len; /*14h */
  620. u32 opcode; /*18h */
  621. union { /*1Ch */
  622. u8 b[12];
  623. u16 s[6];
  624. u32 w[3];
  625. } mbox;
  626. union megasas_sgl sgl; /*28h */
  627. } __attribute__ ((packed));
  628. struct megasas_abort_frame {
  629. u8 cmd; /*00h */
  630. u8 reserved_0; /*01h */
  631. u8 cmd_status; /*02h */
  632. u8 reserved_1; /*03h */
  633. u32 reserved_2; /*04h */
  634. u32 context; /*08h */
  635. u32 pad_0; /*0Ch */
  636. u16 flags; /*10h */
  637. u16 reserved_3; /*12h */
  638. u32 reserved_4; /*14h */
  639. u32 abort_context; /*18h */
  640. u32 pad_1; /*1Ch */
  641. u32 abort_mfi_phys_addr_lo; /*20h */
  642. u32 abort_mfi_phys_addr_hi; /*24h */
  643. u32 reserved_5[6]; /*28h */
  644. } __attribute__ ((packed));
  645. struct megasas_smp_frame {
  646. u8 cmd; /*00h */
  647. u8 reserved_1; /*01h */
  648. u8 cmd_status; /*02h */
  649. u8 connection_status; /*03h */
  650. u8 reserved_2[3]; /*04h */
  651. u8 sge_count; /*07h */
  652. u32 context; /*08h */
  653. u32 pad_0; /*0Ch */
  654. u16 flags; /*10h */
  655. u16 timeout; /*12h */
  656. u32 data_xfer_len; /*14h */
  657. u64 sas_addr; /*18h */
  658. union {
  659. struct megasas_sge32 sge32[2]; /* [0]: resp [1]: req */
  660. struct megasas_sge64 sge64[2]; /* [0]: resp [1]: req */
  661. } sgl;
  662. } __attribute__ ((packed));
  663. struct megasas_stp_frame {
  664. u8 cmd; /*00h */
  665. u8 reserved_1; /*01h */
  666. u8 cmd_status; /*02h */
  667. u8 reserved_2; /*03h */
  668. u8 target_id; /*04h */
  669. u8 reserved_3[2]; /*05h */
  670. u8 sge_count; /*07h */
  671. u32 context; /*08h */
  672. u32 pad_0; /*0Ch */
  673. u16 flags; /*10h */
  674. u16 timeout; /*12h */
  675. u32 data_xfer_len; /*14h */
  676. u16 fis[10]; /*18h */
  677. u32 stp_flags;
  678. union {
  679. struct megasas_sge32 sge32[2]; /* [0]: resp [1]: data */
  680. struct megasas_sge64 sge64[2]; /* [0]: resp [1]: data */
  681. } sgl;
  682. } __attribute__ ((packed));
  683. union megasas_frame {
  684. struct megasas_header hdr;
  685. struct megasas_init_frame init;
  686. struct megasas_io_frame io;
  687. struct megasas_pthru_frame pthru;
  688. struct megasas_dcmd_frame dcmd;
  689. struct megasas_abort_frame abort;
  690. struct megasas_smp_frame smp;
  691. struct megasas_stp_frame stp;
  692. u8 raw_bytes[64];
  693. };
  694. struct megasas_cmd;
  695. union megasas_evt_class_locale {
  696. struct {
  697. u16 locale;
  698. u8 reserved;
  699. s8 class;
  700. } __attribute__ ((packed)) members;
  701. u32 word;
  702. } __attribute__ ((packed));
  703. struct megasas_evt_log_info {
  704. u32 newest_seq_num;
  705. u32 oldest_seq_num;
  706. u32 clear_seq_num;
  707. u32 shutdown_seq_num;
  708. u32 boot_seq_num;
  709. } __attribute__ ((packed));
  710. struct megasas_progress {
  711. u16 progress;
  712. u16 elapsed_seconds;
  713. } __attribute__ ((packed));
  714. struct megasas_evtarg_ld {
  715. u16 target_id;
  716. u8 ld_index;
  717. u8 reserved;
  718. } __attribute__ ((packed));
  719. struct megasas_evtarg_pd {
  720. u16 device_id;
  721. u8 encl_index;
  722. u8 slot_number;
  723. } __attribute__ ((packed));
  724. struct megasas_evt_detail {
  725. u32 seq_num;
  726. u32 time_stamp;
  727. u32 code;
  728. union megasas_evt_class_locale cl;
  729. u8 arg_type;
  730. u8 reserved1[15];
  731. union {
  732. struct {
  733. struct megasas_evtarg_pd pd;
  734. u8 cdb_length;
  735. u8 sense_length;
  736. u8 reserved[2];
  737. u8 cdb[16];
  738. u8 sense[64];
  739. } __attribute__ ((packed)) cdbSense;
  740. struct megasas_evtarg_ld ld;
  741. struct {
  742. struct megasas_evtarg_ld ld;
  743. u64 count;
  744. } __attribute__ ((packed)) ld_count;
  745. struct {
  746. u64 lba;
  747. struct megasas_evtarg_ld ld;
  748. } __attribute__ ((packed)) ld_lba;
  749. struct {
  750. struct megasas_evtarg_ld ld;
  751. u32 prevOwner;
  752. u32 newOwner;
  753. } __attribute__ ((packed)) ld_owner;
  754. struct {
  755. u64 ld_lba;
  756. u64 pd_lba;
  757. struct megasas_evtarg_ld ld;
  758. struct megasas_evtarg_pd pd;
  759. } __attribute__ ((packed)) ld_lba_pd_lba;
  760. struct {
  761. struct megasas_evtarg_ld ld;
  762. struct megasas_progress prog;
  763. } __attribute__ ((packed)) ld_prog;
  764. struct {
  765. struct megasas_evtarg_ld ld;
  766. u32 prev_state;
  767. u32 new_state;
  768. } __attribute__ ((packed)) ld_state;
  769. struct {
  770. u64 strip;
  771. struct megasas_evtarg_ld ld;
  772. } __attribute__ ((packed)) ld_strip;
  773. struct megasas_evtarg_pd pd;
  774. struct {
  775. struct megasas_evtarg_pd pd;
  776. u32 err;
  777. } __attribute__ ((packed)) pd_err;
  778. struct {
  779. u64 lba;
  780. struct megasas_evtarg_pd pd;
  781. } __attribute__ ((packed)) pd_lba;
  782. struct {
  783. u64 lba;
  784. struct megasas_evtarg_pd pd;
  785. struct megasas_evtarg_ld ld;
  786. } __attribute__ ((packed)) pd_lba_ld;
  787. struct {
  788. struct megasas_evtarg_pd pd;
  789. struct megasas_progress prog;
  790. } __attribute__ ((packed)) pd_prog;
  791. struct {
  792. struct megasas_evtarg_pd pd;
  793. u32 prevState;
  794. u32 newState;
  795. } __attribute__ ((packed)) pd_state;
  796. struct {
  797. u16 vendorId;
  798. u16 deviceId;
  799. u16 subVendorId;
  800. u16 subDeviceId;
  801. } __attribute__ ((packed)) pci;
  802. u32 rate;
  803. char str[96];
  804. struct {
  805. u32 rtc;
  806. u32 elapsedSeconds;
  807. } __attribute__ ((packed)) time;
  808. struct {
  809. u32 ecar;
  810. u32 elog;
  811. char str[64];
  812. } __attribute__ ((packed)) ecc;
  813. u8 b[96];
  814. u16 s[48];
  815. u32 w[24];
  816. u64 d[12];
  817. } args;
  818. char description[128];
  819. } __attribute__ ((packed));
  820. struct megasas_instance_template {
  821. void (*fire_cmd)(dma_addr_t ,u32 ,struct megasas_register_set __iomem *);
  822. void (*enable_intr)(struct megasas_register_set __iomem *) ;
  823. void (*disable_intr)(struct megasas_register_set __iomem *);
  824. int (*clear_intr)(struct megasas_register_set __iomem *);
  825. u32 (*read_fw_status_reg)(struct megasas_register_set __iomem *);
  826. };
  827. struct megasas_instance {
  828. u32 *producer;
  829. dma_addr_t producer_h;
  830. u32 *consumer;
  831. dma_addr_t consumer_h;
  832. u32 *reply_queue;
  833. dma_addr_t reply_queue_h;
  834. unsigned long base_addr;
  835. struct megasas_register_set __iomem *reg_set;
  836. s8 init_id;
  837. u16 max_num_sge;
  838. u16 max_fw_cmds;
  839. u32 max_sectors_per_req;
  840. struct megasas_cmd **cmd_list;
  841. struct list_head cmd_pool;
  842. spinlock_t cmd_pool_lock;
  843. struct dma_pool *frame_dma_pool;
  844. struct dma_pool *sense_dma_pool;
  845. struct megasas_evt_detail *evt_detail;
  846. dma_addr_t evt_detail_h;
  847. struct megasas_cmd *aen_cmd;
  848. struct semaphore aen_mutex;
  849. struct semaphore ioctl_sem;
  850. struct Scsi_Host *host;
  851. wait_queue_head_t int_cmd_wait_q;
  852. wait_queue_head_t abort_cmd_wait_q;
  853. struct pci_dev *pdev;
  854. u32 unique_id;
  855. atomic_t fw_outstanding;
  856. u32 hw_crit_error;
  857. struct megasas_instance_template *instancet;
  858. struct tasklet_struct isr_tasklet;
  859. u8 flag;
  860. unsigned long last_time;
  861. };
  862. #define MEGASAS_IS_LOGICAL(scp) \
  863. (scp->device->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1
  864. #define MEGASAS_DEV_INDEX(inst, scp) \
  865. ((scp->device->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) + \
  866. scp->device->id
  867. struct megasas_cmd {
  868. union megasas_frame *frame;
  869. dma_addr_t frame_phys_addr;
  870. u8 *sense;
  871. dma_addr_t sense_phys_addr;
  872. u32 index;
  873. u8 sync_cmd;
  874. u8 cmd_status;
  875. u16 abort_aen;
  876. struct list_head list;
  877. struct scsi_cmnd *scmd;
  878. struct megasas_instance *instance;
  879. u32 frame_count;
  880. };
  881. #define MAX_MGMT_ADAPTERS 1024
  882. #define MAX_IOCTL_SGE 16
  883. struct megasas_iocpacket {
  884. u16 host_no;
  885. u16 __pad1;
  886. u32 sgl_off;
  887. u32 sge_count;
  888. u32 sense_off;
  889. u32 sense_len;
  890. union {
  891. u8 raw[128];
  892. struct megasas_header hdr;
  893. } frame;
  894. struct iovec sgl[MAX_IOCTL_SGE];
  895. } __attribute__ ((packed));
  896. struct megasas_aen {
  897. u16 host_no;
  898. u16 __pad1;
  899. u32 seq_num;
  900. u32 class_locale_word;
  901. } __attribute__ ((packed));
  902. #ifdef CONFIG_COMPAT
  903. struct compat_megasas_iocpacket {
  904. u16 host_no;
  905. u16 __pad1;
  906. u32 sgl_off;
  907. u32 sge_count;
  908. u32 sense_off;
  909. u32 sense_len;
  910. union {
  911. u8 raw[128];
  912. struct megasas_header hdr;
  913. } frame;
  914. struct compat_iovec sgl[MAX_IOCTL_SGE];
  915. } __attribute__ ((packed));
  916. #define MEGASAS_IOC_FIRMWARE32 _IOWR('M', 1, struct compat_megasas_iocpacket)
  917. #endif
  918. #define MEGASAS_IOC_FIRMWARE _IOWR('M', 1, struct megasas_iocpacket)
  919. #define MEGASAS_IOC_GET_AEN _IOW('M', 3, struct megasas_aen)
  920. struct megasas_mgmt_info {
  921. u16 count;
  922. struct megasas_instance *instance[MAX_MGMT_ADAPTERS];
  923. int max_index;
  924. };
  925. #endif /*LSI_MEGARAID_SAS_H */