megaraid_sas.h 25 KB

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