megaraid_sas.h 24 KB

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