megaraid_sas.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  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.01"
  20. #define MEGASAS_RELDATE "May 14, 2006"
  21. #define MEGASAS_EXT_VERSION "Sun May 14 22:49:52 PDT 2006"
  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. /*
  455. * When SCSI mid-layer calls driver's reset routine, driver waits for
  456. * MEGASAS_RESET_WAIT_TIME seconds for all outstanding IO to complete. Note
  457. * that the driver cannot _actually_ abort or reset pending commands. While
  458. * it is waiting for the commands to complete, it prints a diagnostic message
  459. * every MEGASAS_RESET_NOTICE_INTERVAL seconds
  460. */
  461. #define MEGASAS_RESET_WAIT_TIME 180
  462. #define MEGASAS_RESET_NOTICE_INTERVAL 5
  463. #define MEGASAS_IOCTL_CMD 0
  464. /*
  465. * FW reports the maximum of number of commands that it can accept (maximum
  466. * commands that can be outstanding) at any time. The driver must report a
  467. * lower number to the mid layer because it can issue a few internal commands
  468. * itself (E.g, AEN, abort cmd, IOCTLs etc). The number of commands it needs
  469. * is shown below
  470. */
  471. #define MEGASAS_INT_CMDS 32
  472. /*
  473. * FW can accept both 32 and 64 bit SGLs. We want to allocate 32/64 bit
  474. * SGLs based on the size of dma_addr_t
  475. */
  476. #define IS_DMA64 (sizeof(dma_addr_t) == 8)
  477. #define MFI_OB_INTR_STATUS_MASK 0x00000002
  478. #define MFI_POLL_TIMEOUT_SECS 10
  479. #define MFI_REPLY_1078_MESSAGE_INTERRUPT 0x80000000
  480. /*
  481. * register set for both 1068 and 1078 controllers
  482. * structure extended for 1078 registers
  483. */
  484. struct megasas_register_set {
  485. u32 reserved_0[4]; /*0000h*/
  486. u32 inbound_msg_0; /*0010h*/
  487. u32 inbound_msg_1; /*0014h*/
  488. u32 outbound_msg_0; /*0018h*/
  489. u32 outbound_msg_1; /*001Ch*/
  490. u32 inbound_doorbell; /*0020h*/
  491. u32 inbound_intr_status; /*0024h*/
  492. u32 inbound_intr_mask; /*0028h*/
  493. u32 outbound_doorbell; /*002Ch*/
  494. u32 outbound_intr_status; /*0030h*/
  495. u32 outbound_intr_mask; /*0034h*/
  496. u32 reserved_1[2]; /*0038h*/
  497. u32 inbound_queue_port; /*0040h*/
  498. u32 outbound_queue_port; /*0044h*/
  499. u32 reserved_2[22]; /*0048h*/
  500. u32 outbound_doorbell_clear; /*00A0h*/
  501. u32 reserved_3[3]; /*00A4h*/
  502. u32 outbound_scratch_pad ; /*00B0h*/
  503. u32 reserved_4[3]; /*00B4h*/
  504. u32 inbound_low_queue_port ; /*00C0h*/
  505. u32 inbound_high_queue_port ; /*00C4h*/
  506. u32 reserved_5; /*00C8h*/
  507. u32 index_registers[820]; /*00CCh*/
  508. } __attribute__ ((packed));
  509. struct megasas_sge32 {
  510. u32 phys_addr;
  511. u32 length;
  512. } __attribute__ ((packed));
  513. struct megasas_sge64 {
  514. u64 phys_addr;
  515. u32 length;
  516. } __attribute__ ((packed));
  517. union megasas_sgl {
  518. struct megasas_sge32 sge32[1];
  519. struct megasas_sge64 sge64[1];
  520. } __attribute__ ((packed));
  521. struct megasas_header {
  522. u8 cmd; /*00h */
  523. u8 sense_len; /*01h */
  524. u8 cmd_status; /*02h */
  525. u8 scsi_status; /*03h */
  526. u8 target_id; /*04h */
  527. u8 lun; /*05h */
  528. u8 cdb_len; /*06h */
  529. u8 sge_count; /*07h */
  530. u32 context; /*08h */
  531. u32 pad_0; /*0Ch */
  532. u16 flags; /*10h */
  533. u16 timeout; /*12h */
  534. u32 data_xferlen; /*14h */
  535. } __attribute__ ((packed));
  536. union megasas_sgl_frame {
  537. struct megasas_sge32 sge32[8];
  538. struct megasas_sge64 sge64[5];
  539. } __attribute__ ((packed));
  540. struct megasas_init_frame {
  541. u8 cmd; /*00h */
  542. u8 reserved_0; /*01h */
  543. u8 cmd_status; /*02h */
  544. u8 reserved_1; /*03h */
  545. u32 reserved_2; /*04h */
  546. u32 context; /*08h */
  547. u32 pad_0; /*0Ch */
  548. u16 flags; /*10h */
  549. u16 reserved_3; /*12h */
  550. u32 data_xfer_len; /*14h */
  551. u32 queue_info_new_phys_addr_lo; /*18h */
  552. u32 queue_info_new_phys_addr_hi; /*1Ch */
  553. u32 queue_info_old_phys_addr_lo; /*20h */
  554. u32 queue_info_old_phys_addr_hi; /*24h */
  555. u32 reserved_4[6]; /*28h */
  556. } __attribute__ ((packed));
  557. struct megasas_init_queue_info {
  558. u32 init_flags; /*00h */
  559. u32 reply_queue_entries; /*04h */
  560. u32 reply_queue_start_phys_addr_lo; /*08h */
  561. u32 reply_queue_start_phys_addr_hi; /*0Ch */
  562. u32 producer_index_phys_addr_lo; /*10h */
  563. u32 producer_index_phys_addr_hi; /*14h */
  564. u32 consumer_index_phys_addr_lo; /*18h */
  565. u32 consumer_index_phys_addr_hi; /*1Ch */
  566. } __attribute__ ((packed));
  567. struct megasas_io_frame {
  568. u8 cmd; /*00h */
  569. u8 sense_len; /*01h */
  570. u8 cmd_status; /*02h */
  571. u8 scsi_status; /*03h */
  572. u8 target_id; /*04h */
  573. u8 access_byte; /*05h */
  574. u8 reserved_0; /*06h */
  575. u8 sge_count; /*07h */
  576. u32 context; /*08h */
  577. u32 pad_0; /*0Ch */
  578. u16 flags; /*10h */
  579. u16 timeout; /*12h */
  580. u32 lba_count; /*14h */
  581. u32 sense_buf_phys_addr_lo; /*18h */
  582. u32 sense_buf_phys_addr_hi; /*1Ch */
  583. u32 start_lba_lo; /*20h */
  584. u32 start_lba_hi; /*24h */
  585. union megasas_sgl sgl; /*28h */
  586. } __attribute__ ((packed));
  587. struct megasas_pthru_frame {
  588. u8 cmd; /*00h */
  589. u8 sense_len; /*01h */
  590. u8 cmd_status; /*02h */
  591. u8 scsi_status; /*03h */
  592. u8 target_id; /*04h */
  593. u8 lun; /*05h */
  594. u8 cdb_len; /*06h */
  595. u8 sge_count; /*07h */
  596. u32 context; /*08h */
  597. u32 pad_0; /*0Ch */
  598. u16 flags; /*10h */
  599. u16 timeout; /*12h */
  600. u32 data_xfer_len; /*14h */
  601. u32 sense_buf_phys_addr_lo; /*18h */
  602. u32 sense_buf_phys_addr_hi; /*1Ch */
  603. u8 cdb[16]; /*20h */
  604. union megasas_sgl sgl; /*30h */
  605. } __attribute__ ((packed));
  606. struct megasas_dcmd_frame {
  607. u8 cmd; /*00h */
  608. u8 reserved_0; /*01h */
  609. u8 cmd_status; /*02h */
  610. u8 reserved_1[4]; /*03h */
  611. u8 sge_count; /*07h */
  612. u32 context; /*08h */
  613. u32 pad_0; /*0Ch */
  614. u16 flags; /*10h */
  615. u16 timeout; /*12h */
  616. u32 data_xfer_len; /*14h */
  617. u32 opcode; /*18h */
  618. union { /*1Ch */
  619. u8 b[12];
  620. u16 s[6];
  621. u32 w[3];
  622. } mbox;
  623. union megasas_sgl sgl; /*28h */
  624. } __attribute__ ((packed));
  625. struct megasas_abort_frame {
  626. u8 cmd; /*00h */
  627. u8 reserved_0; /*01h */
  628. u8 cmd_status; /*02h */
  629. u8 reserved_1; /*03h */
  630. u32 reserved_2; /*04h */
  631. u32 context; /*08h */
  632. u32 pad_0; /*0Ch */
  633. u16 flags; /*10h */
  634. u16 reserved_3; /*12h */
  635. u32 reserved_4; /*14h */
  636. u32 abort_context; /*18h */
  637. u32 pad_1; /*1Ch */
  638. u32 abort_mfi_phys_addr_lo; /*20h */
  639. u32 abort_mfi_phys_addr_hi; /*24h */
  640. u32 reserved_5[6]; /*28h */
  641. } __attribute__ ((packed));
  642. struct megasas_smp_frame {
  643. u8 cmd; /*00h */
  644. u8 reserved_1; /*01h */
  645. u8 cmd_status; /*02h */
  646. u8 connection_status; /*03h */
  647. u8 reserved_2[3]; /*04h */
  648. u8 sge_count; /*07h */
  649. u32 context; /*08h */
  650. u32 pad_0; /*0Ch */
  651. u16 flags; /*10h */
  652. u16 timeout; /*12h */
  653. u32 data_xfer_len; /*14h */
  654. u64 sas_addr; /*18h */
  655. union {
  656. struct megasas_sge32 sge32[2]; /* [0]: resp [1]: req */
  657. struct megasas_sge64 sge64[2]; /* [0]: resp [1]: req */
  658. } sgl;
  659. } __attribute__ ((packed));
  660. struct megasas_stp_frame {
  661. u8 cmd; /*00h */
  662. u8 reserved_1; /*01h */
  663. u8 cmd_status; /*02h */
  664. u8 reserved_2; /*03h */
  665. u8 target_id; /*04h */
  666. u8 reserved_3[2]; /*05h */
  667. u8 sge_count; /*07h */
  668. u32 context; /*08h */
  669. u32 pad_0; /*0Ch */
  670. u16 flags; /*10h */
  671. u16 timeout; /*12h */
  672. u32 data_xfer_len; /*14h */
  673. u16 fis[10]; /*18h */
  674. u32 stp_flags;
  675. union {
  676. struct megasas_sge32 sge32[2]; /* [0]: resp [1]: data */
  677. struct megasas_sge64 sge64[2]; /* [0]: resp [1]: data */
  678. } sgl;
  679. } __attribute__ ((packed));
  680. union megasas_frame {
  681. struct megasas_header hdr;
  682. struct megasas_init_frame init;
  683. struct megasas_io_frame io;
  684. struct megasas_pthru_frame pthru;
  685. struct megasas_dcmd_frame dcmd;
  686. struct megasas_abort_frame abort;
  687. struct megasas_smp_frame smp;
  688. struct megasas_stp_frame stp;
  689. u8 raw_bytes[64];
  690. };
  691. struct megasas_cmd;
  692. union megasas_evt_class_locale {
  693. struct {
  694. u16 locale;
  695. u8 reserved;
  696. s8 class;
  697. } __attribute__ ((packed)) members;
  698. u32 word;
  699. } __attribute__ ((packed));
  700. struct megasas_evt_log_info {
  701. u32 newest_seq_num;
  702. u32 oldest_seq_num;
  703. u32 clear_seq_num;
  704. u32 shutdown_seq_num;
  705. u32 boot_seq_num;
  706. } __attribute__ ((packed));
  707. struct megasas_progress {
  708. u16 progress;
  709. u16 elapsed_seconds;
  710. } __attribute__ ((packed));
  711. struct megasas_evtarg_ld {
  712. u16 target_id;
  713. u8 ld_index;
  714. u8 reserved;
  715. } __attribute__ ((packed));
  716. struct megasas_evtarg_pd {
  717. u16 device_id;
  718. u8 encl_index;
  719. u8 slot_number;
  720. } __attribute__ ((packed));
  721. struct megasas_evt_detail {
  722. u32 seq_num;
  723. u32 time_stamp;
  724. u32 code;
  725. union megasas_evt_class_locale cl;
  726. u8 arg_type;
  727. u8 reserved1[15];
  728. union {
  729. struct {
  730. struct megasas_evtarg_pd pd;
  731. u8 cdb_length;
  732. u8 sense_length;
  733. u8 reserved[2];
  734. u8 cdb[16];
  735. u8 sense[64];
  736. } __attribute__ ((packed)) cdbSense;
  737. struct megasas_evtarg_ld ld;
  738. struct {
  739. struct megasas_evtarg_ld ld;
  740. u64 count;
  741. } __attribute__ ((packed)) ld_count;
  742. struct {
  743. u64 lba;
  744. struct megasas_evtarg_ld ld;
  745. } __attribute__ ((packed)) ld_lba;
  746. struct {
  747. struct megasas_evtarg_ld ld;
  748. u32 prevOwner;
  749. u32 newOwner;
  750. } __attribute__ ((packed)) ld_owner;
  751. struct {
  752. u64 ld_lba;
  753. u64 pd_lba;
  754. struct megasas_evtarg_ld ld;
  755. struct megasas_evtarg_pd pd;
  756. } __attribute__ ((packed)) ld_lba_pd_lba;
  757. struct {
  758. struct megasas_evtarg_ld ld;
  759. struct megasas_progress prog;
  760. } __attribute__ ((packed)) ld_prog;
  761. struct {
  762. struct megasas_evtarg_ld ld;
  763. u32 prev_state;
  764. u32 new_state;
  765. } __attribute__ ((packed)) ld_state;
  766. struct {
  767. u64 strip;
  768. struct megasas_evtarg_ld ld;
  769. } __attribute__ ((packed)) ld_strip;
  770. struct megasas_evtarg_pd pd;
  771. struct {
  772. struct megasas_evtarg_pd pd;
  773. u32 err;
  774. } __attribute__ ((packed)) pd_err;
  775. struct {
  776. u64 lba;
  777. struct megasas_evtarg_pd pd;
  778. } __attribute__ ((packed)) pd_lba;
  779. struct {
  780. u64 lba;
  781. struct megasas_evtarg_pd pd;
  782. struct megasas_evtarg_ld ld;
  783. } __attribute__ ((packed)) pd_lba_ld;
  784. struct {
  785. struct megasas_evtarg_pd pd;
  786. struct megasas_progress prog;
  787. } __attribute__ ((packed)) pd_prog;
  788. struct {
  789. struct megasas_evtarg_pd pd;
  790. u32 prevState;
  791. u32 newState;
  792. } __attribute__ ((packed)) pd_state;
  793. struct {
  794. u16 vendorId;
  795. u16 deviceId;
  796. u16 subVendorId;
  797. u16 subDeviceId;
  798. } __attribute__ ((packed)) pci;
  799. u32 rate;
  800. char str[96];
  801. struct {
  802. u32 rtc;
  803. u32 elapsedSeconds;
  804. } __attribute__ ((packed)) time;
  805. struct {
  806. u32 ecar;
  807. u32 elog;
  808. char str[64];
  809. } __attribute__ ((packed)) ecc;
  810. u8 b[96];
  811. u16 s[48];
  812. u32 w[24];
  813. u64 d[12];
  814. } args;
  815. char description[128];
  816. } __attribute__ ((packed));
  817. struct megasas_instance_template {
  818. void (*fire_cmd)(dma_addr_t ,u32 ,struct megasas_register_set __iomem *);
  819. void (*enable_intr)(struct megasas_register_set __iomem *) ;
  820. void (*disable_intr)(struct megasas_register_set __iomem *);
  821. int (*clear_intr)(struct megasas_register_set __iomem *);
  822. u32 (*read_fw_status_reg)(struct megasas_register_set __iomem *);
  823. };
  824. struct megasas_instance {
  825. u32 *producer;
  826. dma_addr_t producer_h;
  827. u32 *consumer;
  828. dma_addr_t consumer_h;
  829. u32 *reply_queue;
  830. dma_addr_t reply_queue_h;
  831. unsigned long base_addr;
  832. struct megasas_register_set __iomem *reg_set;
  833. s8 init_id;
  834. u8 reserved[3];
  835. u16 max_num_sge;
  836. u16 max_fw_cmds;
  837. u32 max_sectors_per_req;
  838. struct megasas_cmd **cmd_list;
  839. struct list_head cmd_pool;
  840. spinlock_t cmd_pool_lock;
  841. struct dma_pool *frame_dma_pool;
  842. struct dma_pool *sense_dma_pool;
  843. struct megasas_evt_detail *evt_detail;
  844. dma_addr_t evt_detail_h;
  845. struct megasas_cmd *aen_cmd;
  846. struct semaphore aen_mutex;
  847. struct semaphore ioctl_sem;
  848. struct Scsi_Host *host;
  849. wait_queue_head_t int_cmd_wait_q;
  850. wait_queue_head_t abort_cmd_wait_q;
  851. struct pci_dev *pdev;
  852. u32 unique_id;
  853. atomic_t fw_outstanding;
  854. u32 hw_crit_error;
  855. struct megasas_instance_template *instancet;
  856. struct tasklet_struct isr_tasklet;
  857. };
  858. #define MEGASAS_IS_LOGICAL(scp) \
  859. (scp->device->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1
  860. #define MEGASAS_DEV_INDEX(inst, scp) \
  861. ((scp->device->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) + \
  862. scp->device->id
  863. struct megasas_cmd {
  864. union megasas_frame *frame;
  865. dma_addr_t frame_phys_addr;
  866. u8 *sense;
  867. dma_addr_t sense_phys_addr;
  868. u32 index;
  869. u8 sync_cmd;
  870. u8 cmd_status;
  871. u16 abort_aen;
  872. struct list_head list;
  873. struct scsi_cmnd *scmd;
  874. struct megasas_instance *instance;
  875. u32 frame_count;
  876. };
  877. #define MAX_MGMT_ADAPTERS 1024
  878. #define MAX_IOCTL_SGE 16
  879. struct megasas_iocpacket {
  880. u16 host_no;
  881. u16 __pad1;
  882. u32 sgl_off;
  883. u32 sge_count;
  884. u32 sense_off;
  885. u32 sense_len;
  886. union {
  887. u8 raw[128];
  888. struct megasas_header hdr;
  889. } frame;
  890. struct iovec sgl[MAX_IOCTL_SGE];
  891. } __attribute__ ((packed));
  892. struct megasas_aen {
  893. u16 host_no;
  894. u16 __pad1;
  895. u32 seq_num;
  896. u32 class_locale_word;
  897. } __attribute__ ((packed));
  898. #ifdef CONFIG_COMPAT
  899. struct compat_megasas_iocpacket {
  900. u16 host_no;
  901. u16 __pad1;
  902. u32 sgl_off;
  903. u32 sge_count;
  904. u32 sense_off;
  905. u32 sense_len;
  906. union {
  907. u8 raw[128];
  908. struct megasas_header hdr;
  909. } frame;
  910. struct compat_iovec sgl[MAX_IOCTL_SGE];
  911. } __attribute__ ((packed));
  912. #define MEGASAS_IOC_FIRMWARE32 _IOWR('M', 1, struct compat_megasas_iocpacket)
  913. #endif
  914. #define MEGASAS_IOC_FIRMWARE _IOWR('M', 1, struct megasas_iocpacket)
  915. #define MEGASAS_IOC_GET_AEN _IOW('M', 3, struct megasas_aen)
  916. struct megasas_mgmt_info {
  917. u16 count;
  918. struct megasas_instance *instance[MAX_MGMT_ADAPTERS];
  919. int max_index;
  920. };
  921. #endif /*LSI_MEGARAID_SAS_H */