megaraid_sas.h 24 KB

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