megaraid_sas.h 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  1. /*
  2. * Linux MegaRAID driver for SAS based RAID controllers
  3. *
  4. * Copyright (c) 2003-2012 LSI Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. * FILE: megaraid_sas.h
  21. *
  22. * Authors: LSI Corporation
  23. *
  24. * Send feedback to: <megaraidlinux@lsi.com>
  25. *
  26. * Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035
  27. * ATTN: Linuxraid
  28. */
  29. #ifndef LSI_MEGARAID_SAS_H
  30. #define LSI_MEGARAID_SAS_H
  31. /*
  32. * MegaRAID SAS Driver meta data
  33. */
  34. #define MEGASAS_VERSION "06.700.06.00-rc1"
  35. #define MEGASAS_RELDATE "Aug. 31, 2013"
  36. #define MEGASAS_EXT_VERSION "Sat. Aug. 31 17:00:00 PDT 2013"
  37. /*
  38. * Device IDs
  39. */
  40. #define PCI_DEVICE_ID_LSI_SAS1078R 0x0060
  41. #define PCI_DEVICE_ID_LSI_SAS1078DE 0x007C
  42. #define PCI_DEVICE_ID_LSI_VERDE_ZCR 0x0413
  43. #define PCI_DEVICE_ID_LSI_SAS1078GEN2 0x0078
  44. #define PCI_DEVICE_ID_LSI_SAS0079GEN2 0x0079
  45. #define PCI_DEVICE_ID_LSI_SAS0073SKINNY 0x0073
  46. #define PCI_DEVICE_ID_LSI_SAS0071SKINNY 0x0071
  47. #define PCI_DEVICE_ID_LSI_FUSION 0x005b
  48. #define PCI_DEVICE_ID_LSI_INVADER 0x005d
  49. #define PCI_DEVICE_ID_LSI_FURY 0x005f
  50. /*
  51. * Intel HBA SSDIDs
  52. */
  53. #define MEGARAID_INTEL_RS3DC080_SSDID 0x9360
  54. #define MEGARAID_INTEL_RS3DC040_SSDID 0x9362
  55. #define MEGARAID_INTEL_RS3SC008_SSDID 0x9380
  56. #define MEGARAID_INTEL_RS3MC044_SSDID 0x9381
  57. #define MEGARAID_INTEL_RS3WC080_SSDID 0x9341
  58. #define MEGARAID_INTEL_RS3WC040_SSDID 0x9343
  59. /*
  60. * Intel HBA branding
  61. */
  62. #define MEGARAID_INTEL_RS3DC080_BRANDING \
  63. "Intel(R) RAID Controller RS3DC080"
  64. #define MEGARAID_INTEL_RS3DC040_BRANDING \
  65. "Intel(R) RAID Controller RS3DC040"
  66. #define MEGARAID_INTEL_RS3SC008_BRANDING \
  67. "Intel(R) RAID Controller RS3SC008"
  68. #define MEGARAID_INTEL_RS3MC044_BRANDING \
  69. "Intel(R) RAID Controller RS3MC044"
  70. #define MEGARAID_INTEL_RS3WC080_BRANDING \
  71. "Intel(R) RAID Controller RS3WC080"
  72. #define MEGARAID_INTEL_RS3WC040_BRANDING \
  73. "Intel(R) RAID Controller RS3WC040"
  74. /*
  75. * =====================================
  76. * MegaRAID SAS MFI firmware definitions
  77. * =====================================
  78. */
  79. /*
  80. * MFI stands for MegaRAID SAS FW Interface. This is just a moniker for
  81. * protocol between the software and firmware. Commands are issued using
  82. * "message frames"
  83. */
  84. /*
  85. * FW posts its state in upper 4 bits of outbound_msg_0 register
  86. */
  87. #define MFI_STATE_MASK 0xF0000000
  88. #define MFI_STATE_UNDEFINED 0x00000000
  89. #define MFI_STATE_BB_INIT 0x10000000
  90. #define MFI_STATE_FW_INIT 0x40000000
  91. #define MFI_STATE_WAIT_HANDSHAKE 0x60000000
  92. #define MFI_STATE_FW_INIT_2 0x70000000
  93. #define MFI_STATE_DEVICE_SCAN 0x80000000
  94. #define MFI_STATE_BOOT_MESSAGE_PENDING 0x90000000
  95. #define MFI_STATE_FLUSH_CACHE 0xA0000000
  96. #define MFI_STATE_READY 0xB0000000
  97. #define MFI_STATE_OPERATIONAL 0xC0000000
  98. #define MFI_STATE_FAULT 0xF0000000
  99. #define MFI_RESET_REQUIRED 0x00000001
  100. #define MFI_RESET_ADAPTER 0x00000002
  101. #define MEGAMFI_FRAME_SIZE 64
  102. /*
  103. * During FW init, clear pending cmds & reset state using inbound_msg_0
  104. *
  105. * ABORT : Abort all pending cmds
  106. * READY : Move from OPERATIONAL to READY state; discard queue info
  107. * MFIMODE : Discard (possible) low MFA posted in 64-bit mode (??)
  108. * CLR_HANDSHAKE: FW is waiting for HANDSHAKE from BIOS or Driver
  109. * HOTPLUG : Resume from Hotplug
  110. * MFI_STOP_ADP : Send signal to FW to stop processing
  111. */
  112. #define WRITE_SEQUENCE_OFFSET (0x0000000FC) /* I20 */
  113. #define HOST_DIAGNOSTIC_OFFSET (0x000000F8) /* I20 */
  114. #define DIAG_WRITE_ENABLE (0x00000080)
  115. #define DIAG_RESET_ADAPTER (0x00000004)
  116. #define MFI_ADP_RESET 0x00000040
  117. #define MFI_INIT_ABORT 0x00000001
  118. #define MFI_INIT_READY 0x00000002
  119. #define MFI_INIT_MFIMODE 0x00000004
  120. #define MFI_INIT_CLEAR_HANDSHAKE 0x00000008
  121. #define MFI_INIT_HOTPLUG 0x00000010
  122. #define MFI_STOP_ADP 0x00000020
  123. #define MFI_RESET_FLAGS MFI_INIT_READY| \
  124. MFI_INIT_MFIMODE| \
  125. MFI_INIT_ABORT
  126. /*
  127. * MFI frame flags
  128. */
  129. #define MFI_FRAME_POST_IN_REPLY_QUEUE 0x0000
  130. #define MFI_FRAME_DONT_POST_IN_REPLY_QUEUE 0x0001
  131. #define MFI_FRAME_SGL32 0x0000
  132. #define MFI_FRAME_SGL64 0x0002
  133. #define MFI_FRAME_SENSE32 0x0000
  134. #define MFI_FRAME_SENSE64 0x0004
  135. #define MFI_FRAME_DIR_NONE 0x0000
  136. #define MFI_FRAME_DIR_WRITE 0x0008
  137. #define MFI_FRAME_DIR_READ 0x0010
  138. #define MFI_FRAME_DIR_BOTH 0x0018
  139. #define MFI_FRAME_IEEE 0x0020
  140. /*
  141. * Definition for cmd_status
  142. */
  143. #define MFI_CMD_STATUS_POLL_MODE 0xFF
  144. /*
  145. * MFI command opcodes
  146. */
  147. #define MFI_CMD_INIT 0x00
  148. #define MFI_CMD_LD_READ 0x01
  149. #define MFI_CMD_LD_WRITE 0x02
  150. #define MFI_CMD_LD_SCSI_IO 0x03
  151. #define MFI_CMD_PD_SCSI_IO 0x04
  152. #define MFI_CMD_DCMD 0x05
  153. #define MFI_CMD_ABORT 0x06
  154. #define MFI_CMD_SMP 0x07
  155. #define MFI_CMD_STP 0x08
  156. #define MFI_CMD_INVALID 0xff
  157. #define MR_DCMD_CTRL_GET_INFO 0x01010000
  158. #define MR_DCMD_LD_GET_LIST 0x03010000
  159. #define MR_DCMD_LD_LIST_QUERY 0x03010100
  160. #define MR_DCMD_CTRL_CACHE_FLUSH 0x01101000
  161. #define MR_FLUSH_CTRL_CACHE 0x01
  162. #define MR_FLUSH_DISK_CACHE 0x02
  163. #define MR_DCMD_CTRL_SHUTDOWN 0x01050000
  164. #define MR_DCMD_HIBERNATE_SHUTDOWN 0x01060000
  165. #define MR_ENABLE_DRIVE_SPINDOWN 0x01
  166. #define MR_DCMD_CTRL_EVENT_GET_INFO 0x01040100
  167. #define MR_DCMD_CTRL_EVENT_GET 0x01040300
  168. #define MR_DCMD_CTRL_EVENT_WAIT 0x01040500
  169. #define MR_DCMD_LD_GET_PROPERTIES 0x03030000
  170. #define MR_DCMD_CLUSTER 0x08000000
  171. #define MR_DCMD_CLUSTER_RESET_ALL 0x08010100
  172. #define MR_DCMD_CLUSTER_RESET_LD 0x08010200
  173. #define MR_DCMD_PD_LIST_QUERY 0x02010100
  174. /*
  175. * Global functions
  176. */
  177. extern u8 MR_ValidateMapInfo(struct megasas_instance *instance);
  178. /*
  179. * MFI command completion codes
  180. */
  181. enum MFI_STAT {
  182. MFI_STAT_OK = 0x00,
  183. MFI_STAT_INVALID_CMD = 0x01,
  184. MFI_STAT_INVALID_DCMD = 0x02,
  185. MFI_STAT_INVALID_PARAMETER = 0x03,
  186. MFI_STAT_INVALID_SEQUENCE_NUMBER = 0x04,
  187. MFI_STAT_ABORT_NOT_POSSIBLE = 0x05,
  188. MFI_STAT_APP_HOST_CODE_NOT_FOUND = 0x06,
  189. MFI_STAT_APP_IN_USE = 0x07,
  190. MFI_STAT_APP_NOT_INITIALIZED = 0x08,
  191. MFI_STAT_ARRAY_INDEX_INVALID = 0x09,
  192. MFI_STAT_ARRAY_ROW_NOT_EMPTY = 0x0a,
  193. MFI_STAT_CONFIG_RESOURCE_CONFLICT = 0x0b,
  194. MFI_STAT_DEVICE_NOT_FOUND = 0x0c,
  195. MFI_STAT_DRIVE_TOO_SMALL = 0x0d,
  196. MFI_STAT_FLASH_ALLOC_FAIL = 0x0e,
  197. MFI_STAT_FLASH_BUSY = 0x0f,
  198. MFI_STAT_FLASH_ERROR = 0x10,
  199. MFI_STAT_FLASH_IMAGE_BAD = 0x11,
  200. MFI_STAT_FLASH_IMAGE_INCOMPLETE = 0x12,
  201. MFI_STAT_FLASH_NOT_OPEN = 0x13,
  202. MFI_STAT_FLASH_NOT_STARTED = 0x14,
  203. MFI_STAT_FLUSH_FAILED = 0x15,
  204. MFI_STAT_HOST_CODE_NOT_FOUNT = 0x16,
  205. MFI_STAT_LD_CC_IN_PROGRESS = 0x17,
  206. MFI_STAT_LD_INIT_IN_PROGRESS = 0x18,
  207. MFI_STAT_LD_LBA_OUT_OF_RANGE = 0x19,
  208. MFI_STAT_LD_MAX_CONFIGURED = 0x1a,
  209. MFI_STAT_LD_NOT_OPTIMAL = 0x1b,
  210. MFI_STAT_LD_RBLD_IN_PROGRESS = 0x1c,
  211. MFI_STAT_LD_RECON_IN_PROGRESS = 0x1d,
  212. MFI_STAT_LD_WRONG_RAID_LEVEL = 0x1e,
  213. MFI_STAT_MAX_SPARES_EXCEEDED = 0x1f,
  214. MFI_STAT_MEMORY_NOT_AVAILABLE = 0x20,
  215. MFI_STAT_MFC_HW_ERROR = 0x21,
  216. MFI_STAT_NO_HW_PRESENT = 0x22,
  217. MFI_STAT_NOT_FOUND = 0x23,
  218. MFI_STAT_NOT_IN_ENCL = 0x24,
  219. MFI_STAT_PD_CLEAR_IN_PROGRESS = 0x25,
  220. MFI_STAT_PD_TYPE_WRONG = 0x26,
  221. MFI_STAT_PR_DISABLED = 0x27,
  222. MFI_STAT_ROW_INDEX_INVALID = 0x28,
  223. MFI_STAT_SAS_CONFIG_INVALID_ACTION = 0x29,
  224. MFI_STAT_SAS_CONFIG_INVALID_DATA = 0x2a,
  225. MFI_STAT_SAS_CONFIG_INVALID_PAGE = 0x2b,
  226. MFI_STAT_SAS_CONFIG_INVALID_TYPE = 0x2c,
  227. MFI_STAT_SCSI_DONE_WITH_ERROR = 0x2d,
  228. MFI_STAT_SCSI_IO_FAILED = 0x2e,
  229. MFI_STAT_SCSI_RESERVATION_CONFLICT = 0x2f,
  230. MFI_STAT_SHUTDOWN_FAILED = 0x30,
  231. MFI_STAT_TIME_NOT_SET = 0x31,
  232. MFI_STAT_WRONG_STATE = 0x32,
  233. MFI_STAT_LD_OFFLINE = 0x33,
  234. MFI_STAT_PEER_NOTIFICATION_REJECTED = 0x34,
  235. MFI_STAT_PEER_NOTIFICATION_FAILED = 0x35,
  236. MFI_STAT_RESERVATION_IN_PROGRESS = 0x36,
  237. MFI_STAT_I2C_ERRORS_DETECTED = 0x37,
  238. MFI_STAT_PCI_ERRORS_DETECTED = 0x38,
  239. MFI_STAT_CONFIG_SEQ_MISMATCH = 0x67,
  240. MFI_STAT_INVALID_STATUS = 0xFF
  241. };
  242. /*
  243. * Number of mailbox bytes in DCMD message frame
  244. */
  245. #define MFI_MBOX_SIZE 12
  246. enum MR_EVT_CLASS {
  247. MR_EVT_CLASS_DEBUG = -2,
  248. MR_EVT_CLASS_PROGRESS = -1,
  249. MR_EVT_CLASS_INFO = 0,
  250. MR_EVT_CLASS_WARNING = 1,
  251. MR_EVT_CLASS_CRITICAL = 2,
  252. MR_EVT_CLASS_FATAL = 3,
  253. MR_EVT_CLASS_DEAD = 4,
  254. };
  255. enum MR_EVT_LOCALE {
  256. MR_EVT_LOCALE_LD = 0x0001,
  257. MR_EVT_LOCALE_PD = 0x0002,
  258. MR_EVT_LOCALE_ENCL = 0x0004,
  259. MR_EVT_LOCALE_BBU = 0x0008,
  260. MR_EVT_LOCALE_SAS = 0x0010,
  261. MR_EVT_LOCALE_CTRL = 0x0020,
  262. MR_EVT_LOCALE_CONFIG = 0x0040,
  263. MR_EVT_LOCALE_CLUSTER = 0x0080,
  264. MR_EVT_LOCALE_ALL = 0xffff,
  265. };
  266. enum MR_EVT_ARGS {
  267. MR_EVT_ARGS_NONE,
  268. MR_EVT_ARGS_CDB_SENSE,
  269. MR_EVT_ARGS_LD,
  270. MR_EVT_ARGS_LD_COUNT,
  271. MR_EVT_ARGS_LD_LBA,
  272. MR_EVT_ARGS_LD_OWNER,
  273. MR_EVT_ARGS_LD_LBA_PD_LBA,
  274. MR_EVT_ARGS_LD_PROG,
  275. MR_EVT_ARGS_LD_STATE,
  276. MR_EVT_ARGS_LD_STRIP,
  277. MR_EVT_ARGS_PD,
  278. MR_EVT_ARGS_PD_ERR,
  279. MR_EVT_ARGS_PD_LBA,
  280. MR_EVT_ARGS_PD_LBA_LD,
  281. MR_EVT_ARGS_PD_PROG,
  282. MR_EVT_ARGS_PD_STATE,
  283. MR_EVT_ARGS_PCI,
  284. MR_EVT_ARGS_RATE,
  285. MR_EVT_ARGS_STR,
  286. MR_EVT_ARGS_TIME,
  287. MR_EVT_ARGS_ECC,
  288. MR_EVT_ARGS_LD_PROP,
  289. MR_EVT_ARGS_PD_SPARE,
  290. MR_EVT_ARGS_PD_INDEX,
  291. MR_EVT_ARGS_DIAG_PASS,
  292. MR_EVT_ARGS_DIAG_FAIL,
  293. MR_EVT_ARGS_PD_LBA_LBA,
  294. MR_EVT_ARGS_PORT_PHY,
  295. MR_EVT_ARGS_PD_MISSING,
  296. MR_EVT_ARGS_PD_ADDRESS,
  297. MR_EVT_ARGS_BITMAP,
  298. MR_EVT_ARGS_CONNECTOR,
  299. MR_EVT_ARGS_PD_PD,
  300. MR_EVT_ARGS_PD_FRU,
  301. MR_EVT_ARGS_PD_PATHINFO,
  302. MR_EVT_ARGS_PD_POWER_STATE,
  303. MR_EVT_ARGS_GENERIC,
  304. };
  305. /*
  306. * define constants for device list query options
  307. */
  308. enum MR_PD_QUERY_TYPE {
  309. MR_PD_QUERY_TYPE_ALL = 0,
  310. MR_PD_QUERY_TYPE_STATE = 1,
  311. MR_PD_QUERY_TYPE_POWER_STATE = 2,
  312. MR_PD_QUERY_TYPE_MEDIA_TYPE = 3,
  313. MR_PD_QUERY_TYPE_SPEED = 4,
  314. MR_PD_QUERY_TYPE_EXPOSED_TO_HOST = 5,
  315. };
  316. enum MR_LD_QUERY_TYPE {
  317. MR_LD_QUERY_TYPE_ALL = 0,
  318. MR_LD_QUERY_TYPE_EXPOSED_TO_HOST = 1,
  319. MR_LD_QUERY_TYPE_USED_TGT_IDS = 2,
  320. MR_LD_QUERY_TYPE_CLUSTER_ACCESS = 3,
  321. MR_LD_QUERY_TYPE_CLUSTER_LOCALE = 4,
  322. };
  323. #define MR_EVT_CFG_CLEARED 0x0004
  324. #define MR_EVT_LD_STATE_CHANGE 0x0051
  325. #define MR_EVT_PD_INSERTED 0x005b
  326. #define MR_EVT_PD_REMOVED 0x0070
  327. #define MR_EVT_LD_CREATED 0x008a
  328. #define MR_EVT_LD_DELETED 0x008b
  329. #define MR_EVT_FOREIGN_CFG_IMPORTED 0x00db
  330. #define MR_EVT_LD_OFFLINE 0x00fc
  331. #define MR_EVT_CTRL_HOST_BUS_SCAN_REQUESTED 0x0152
  332. #define MAX_LOGICAL_DRIVES 64
  333. enum MR_PD_STATE {
  334. MR_PD_STATE_UNCONFIGURED_GOOD = 0x00,
  335. MR_PD_STATE_UNCONFIGURED_BAD = 0x01,
  336. MR_PD_STATE_HOT_SPARE = 0x02,
  337. MR_PD_STATE_OFFLINE = 0x10,
  338. MR_PD_STATE_FAILED = 0x11,
  339. MR_PD_STATE_REBUILD = 0x14,
  340. MR_PD_STATE_ONLINE = 0x18,
  341. MR_PD_STATE_COPYBACK = 0x20,
  342. MR_PD_STATE_SYSTEM = 0x40,
  343. };
  344. /*
  345. * defines the physical drive address structure
  346. */
  347. struct MR_PD_ADDRESS {
  348. u16 deviceId;
  349. u16 enclDeviceId;
  350. union {
  351. struct {
  352. u8 enclIndex;
  353. u8 slotNumber;
  354. } mrPdAddress;
  355. struct {
  356. u8 enclPosition;
  357. u8 enclConnectorIndex;
  358. } mrEnclAddress;
  359. };
  360. u8 scsiDevType;
  361. union {
  362. u8 connectedPortBitmap;
  363. u8 connectedPortNumbers;
  364. };
  365. u64 sasAddr[2];
  366. } __packed;
  367. /*
  368. * defines the physical drive list structure
  369. */
  370. struct MR_PD_LIST {
  371. u32 size;
  372. u32 count;
  373. struct MR_PD_ADDRESS addr[1];
  374. } __packed;
  375. struct megasas_pd_list {
  376. u16 tid;
  377. u8 driveType;
  378. u8 driveState;
  379. } __packed;
  380. /*
  381. * defines the logical drive reference structure
  382. */
  383. union MR_LD_REF {
  384. struct {
  385. u8 targetId;
  386. u8 reserved;
  387. u16 seqNum;
  388. };
  389. u32 ref;
  390. } __packed;
  391. /*
  392. * defines the logical drive list structure
  393. */
  394. struct MR_LD_LIST {
  395. u32 ldCount;
  396. u32 reserved;
  397. struct {
  398. union MR_LD_REF ref;
  399. u8 state;
  400. u8 reserved[3];
  401. u64 size;
  402. } ldList[MAX_LOGICAL_DRIVES];
  403. } __packed;
  404. struct MR_LD_TARGETID_LIST {
  405. u32 size;
  406. u32 count;
  407. u8 pad[3];
  408. u8 targetId[MAX_LOGICAL_DRIVES];
  409. };
  410. /*
  411. * SAS controller properties
  412. */
  413. struct megasas_ctrl_prop {
  414. u16 seq_num;
  415. u16 pred_fail_poll_interval;
  416. u16 intr_throttle_count;
  417. u16 intr_throttle_timeouts;
  418. u8 rebuild_rate;
  419. u8 patrol_read_rate;
  420. u8 bgi_rate;
  421. u8 cc_rate;
  422. u8 recon_rate;
  423. u8 cache_flush_interval;
  424. u8 spinup_drv_count;
  425. u8 spinup_delay;
  426. u8 cluster_enable;
  427. u8 coercion_mode;
  428. u8 alarm_enable;
  429. u8 disable_auto_rebuild;
  430. u8 disable_battery_warn;
  431. u8 ecc_bucket_size;
  432. u16 ecc_bucket_leak_rate;
  433. u8 restore_hotspare_on_insertion;
  434. u8 expose_encl_devices;
  435. u8 maintainPdFailHistory;
  436. u8 disallowHostRequestReordering;
  437. u8 abortCCOnError;
  438. u8 loadBalanceMode;
  439. u8 disableAutoDetectBackplane;
  440. u8 snapVDSpace;
  441. /*
  442. * Add properties that can be controlled by
  443. * a bit in the following structure.
  444. */
  445. struct {
  446. #if defined(__BIG_ENDIAN_BITFIELD)
  447. u32 reserved:18;
  448. u32 enableJBOD:1;
  449. u32 disableSpinDownHS:1;
  450. u32 allowBootWithPinnedCache:1;
  451. u32 disableOnlineCtrlReset:1;
  452. u32 enableSecretKeyControl:1;
  453. u32 autoEnhancedImport:1;
  454. u32 enableSpinDownUnconfigured:1;
  455. u32 SSDPatrolReadEnabled:1;
  456. u32 SSDSMARTerEnabled:1;
  457. u32 disableNCQ:1;
  458. u32 useFdeOnly:1;
  459. u32 prCorrectUnconfiguredAreas:1;
  460. u32 SMARTerEnabled:1;
  461. u32 copyBackDisabled:1;
  462. #else
  463. u32 copyBackDisabled:1;
  464. u32 SMARTerEnabled:1;
  465. u32 prCorrectUnconfiguredAreas:1;
  466. u32 useFdeOnly:1;
  467. u32 disableNCQ:1;
  468. u32 SSDSMARTerEnabled:1;
  469. u32 SSDPatrolReadEnabled:1;
  470. u32 enableSpinDownUnconfigured:1;
  471. u32 autoEnhancedImport:1;
  472. u32 enableSecretKeyControl:1;
  473. u32 disableOnlineCtrlReset:1;
  474. u32 allowBootWithPinnedCache:1;
  475. u32 disableSpinDownHS:1;
  476. u32 enableJBOD:1;
  477. u32 reserved:18;
  478. #endif
  479. } OnOffProperties;
  480. u8 autoSnapVDSpace;
  481. u8 viewSpace;
  482. u16 spinDownTime;
  483. u8 reserved[24];
  484. } __packed;
  485. /*
  486. * SAS controller information
  487. */
  488. struct megasas_ctrl_info {
  489. /*
  490. * PCI device information
  491. */
  492. struct {
  493. u16 vendor_id;
  494. u16 device_id;
  495. u16 sub_vendor_id;
  496. u16 sub_device_id;
  497. u8 reserved[24];
  498. } __attribute__ ((packed)) pci;
  499. /*
  500. * Host interface information
  501. */
  502. struct {
  503. u8 PCIX:1;
  504. u8 PCIE:1;
  505. u8 iSCSI:1;
  506. u8 SAS_3G:1;
  507. u8 reserved_0:4;
  508. u8 reserved_1[6];
  509. u8 port_count;
  510. u64 port_addr[8];
  511. } __attribute__ ((packed)) host_interface;
  512. /*
  513. * Device (backend) interface information
  514. */
  515. struct {
  516. u8 SPI:1;
  517. u8 SAS_3G:1;
  518. u8 SATA_1_5G:1;
  519. u8 SATA_3G:1;
  520. u8 reserved_0:4;
  521. u8 reserved_1[6];
  522. u8 port_count;
  523. u64 port_addr[8];
  524. } __attribute__ ((packed)) device_interface;
  525. /*
  526. * List of components residing in flash. All str are null terminated
  527. */
  528. u32 image_check_word;
  529. u32 image_component_count;
  530. struct {
  531. char name[8];
  532. char version[32];
  533. char build_date[16];
  534. char built_time[16];
  535. } __attribute__ ((packed)) image_component[8];
  536. /*
  537. * List of flash components that have been flashed on the card, but
  538. * are not in use, pending reset of the adapter. This list will be
  539. * empty if a flash operation has not occurred. All stings are null
  540. * terminated
  541. */
  542. u32 pending_image_component_count;
  543. struct {
  544. char name[8];
  545. char version[32];
  546. char build_date[16];
  547. char build_time[16];
  548. } __attribute__ ((packed)) pending_image_component[8];
  549. u8 max_arms;
  550. u8 max_spans;
  551. u8 max_arrays;
  552. u8 max_lds;
  553. char product_name[80];
  554. char serial_no[32];
  555. /*
  556. * Other physical/controller/operation information. Indicates the
  557. * presence of the hardware
  558. */
  559. struct {
  560. u32 bbu:1;
  561. u32 alarm:1;
  562. u32 nvram:1;
  563. u32 uart:1;
  564. u32 reserved:28;
  565. } __attribute__ ((packed)) hw_present;
  566. u32 current_fw_time;
  567. /*
  568. * Maximum data transfer sizes
  569. */
  570. u16 max_concurrent_cmds;
  571. u16 max_sge_count;
  572. u32 max_request_size;
  573. /*
  574. * Logical and physical device counts
  575. */
  576. u16 ld_present_count;
  577. u16 ld_degraded_count;
  578. u16 ld_offline_count;
  579. u16 pd_present_count;
  580. u16 pd_disk_present_count;
  581. u16 pd_disk_pred_failure_count;
  582. u16 pd_disk_failed_count;
  583. /*
  584. * Memory size information
  585. */
  586. u16 nvram_size;
  587. u16 memory_size;
  588. u16 flash_size;
  589. /*
  590. * Error counters
  591. */
  592. u16 mem_correctable_error_count;
  593. u16 mem_uncorrectable_error_count;
  594. /*
  595. * Cluster information
  596. */
  597. u8 cluster_permitted;
  598. u8 cluster_active;
  599. /*
  600. * Additional max data transfer sizes
  601. */
  602. u16 max_strips_per_io;
  603. /*
  604. * Controller capabilities structures
  605. */
  606. struct {
  607. u32 raid_level_0:1;
  608. u32 raid_level_1:1;
  609. u32 raid_level_5:1;
  610. u32 raid_level_1E:1;
  611. u32 raid_level_6:1;
  612. u32 reserved:27;
  613. } __attribute__ ((packed)) raid_levels;
  614. struct {
  615. u32 rbld_rate:1;
  616. u32 cc_rate:1;
  617. u32 bgi_rate:1;
  618. u32 recon_rate:1;
  619. u32 patrol_rate:1;
  620. u32 alarm_control:1;
  621. u32 cluster_supported:1;
  622. u32 bbu:1;
  623. u32 spanning_allowed:1;
  624. u32 dedicated_hotspares:1;
  625. u32 revertible_hotspares:1;
  626. u32 foreign_config_import:1;
  627. u32 self_diagnostic:1;
  628. u32 mixed_redundancy_arr:1;
  629. u32 global_hot_spares:1;
  630. u32 reserved:17;
  631. } __attribute__ ((packed)) adapter_operations;
  632. struct {
  633. u32 read_policy:1;
  634. u32 write_policy:1;
  635. u32 io_policy:1;
  636. u32 access_policy:1;
  637. u32 disk_cache_policy:1;
  638. u32 reserved:27;
  639. } __attribute__ ((packed)) ld_operations;
  640. struct {
  641. u8 min;
  642. u8 max;
  643. u8 reserved[2];
  644. } __attribute__ ((packed)) stripe_sz_ops;
  645. struct {
  646. u32 force_online:1;
  647. u32 force_offline:1;
  648. u32 force_rebuild:1;
  649. u32 reserved:29;
  650. } __attribute__ ((packed)) pd_operations;
  651. struct {
  652. u32 ctrl_supports_sas:1;
  653. u32 ctrl_supports_sata:1;
  654. u32 allow_mix_in_encl:1;
  655. u32 allow_mix_in_ld:1;
  656. u32 allow_sata_in_cluster:1;
  657. u32 reserved:27;
  658. } __attribute__ ((packed)) pd_mix_support;
  659. /*
  660. * Define ECC single-bit-error bucket information
  661. */
  662. u8 ecc_bucket_count;
  663. u8 reserved_2[11];
  664. /*
  665. * Include the controller properties (changeable items)
  666. */
  667. struct megasas_ctrl_prop properties;
  668. /*
  669. * Define FW pkg version (set in envt v'bles on OEM basis)
  670. */
  671. char package_version[0x60];
  672. /*
  673. * If adapterOperations.supportMoreThan8Phys is set,
  674. * and deviceInterface.portCount is greater than 8,
  675. * SAS Addrs for first 8 ports shall be populated in
  676. * deviceInterface.portAddr, and the rest shall be
  677. * populated in deviceInterfacePortAddr2.
  678. */
  679. u64 deviceInterfacePortAddr2[8]; /*6a0h */
  680. u8 reserved3[128]; /*6e0h */
  681. struct { /*760h */
  682. u16 minPdRaidLevel_0:4;
  683. u16 maxPdRaidLevel_0:12;
  684. u16 minPdRaidLevel_1:4;
  685. u16 maxPdRaidLevel_1:12;
  686. u16 minPdRaidLevel_5:4;
  687. u16 maxPdRaidLevel_5:12;
  688. u16 minPdRaidLevel_1E:4;
  689. u16 maxPdRaidLevel_1E:12;
  690. u16 minPdRaidLevel_6:4;
  691. u16 maxPdRaidLevel_6:12;
  692. u16 minPdRaidLevel_10:4;
  693. u16 maxPdRaidLevel_10:12;
  694. u16 minPdRaidLevel_50:4;
  695. u16 maxPdRaidLevel_50:12;
  696. u16 minPdRaidLevel_60:4;
  697. u16 maxPdRaidLevel_60:12;
  698. u16 minPdRaidLevel_1E_RLQ0:4;
  699. u16 maxPdRaidLevel_1E_RLQ0:12;
  700. u16 minPdRaidLevel_1E0_RLQ0:4;
  701. u16 maxPdRaidLevel_1E0_RLQ0:12;
  702. u16 reserved[6];
  703. } pdsForRaidLevels;
  704. u16 maxPds; /*780h */
  705. u16 maxDedHSPs; /*782h */
  706. u16 maxGlobalHSPs; /*784h */
  707. u16 ddfSize; /*786h */
  708. u8 maxLdsPerArray; /*788h */
  709. u8 partitionsInDDF; /*789h */
  710. u8 lockKeyBinding; /*78ah */
  711. u8 maxPITsPerLd; /*78bh */
  712. u8 maxViewsPerLd; /*78ch */
  713. u8 maxTargetId; /*78dh */
  714. u16 maxBvlVdSize; /*78eh */
  715. u16 maxConfigurableSSCSize; /*790h */
  716. u16 currentSSCsize; /*792h */
  717. char expanderFwVersion[12]; /*794h */
  718. u16 PFKTrialTimeRemaining; /*7A0h */
  719. u16 cacheMemorySize; /*7A2h */
  720. struct { /*7A4h */
  721. #if defined(__BIG_ENDIAN_BITFIELD)
  722. u32 reserved:11;
  723. u32 supportUnevenSpans:1;
  724. u32 dedicatedHotSparesLimited:1;
  725. u32 headlessMode:1;
  726. u32 supportEmulatedDrives:1;
  727. u32 supportResetNow:1;
  728. u32 realTimeScheduler:1;
  729. u32 supportSSDPatrolRead:1;
  730. u32 supportPerfTuning:1;
  731. u32 disableOnlinePFKChange:1;
  732. u32 supportJBOD:1;
  733. u32 supportBootTimePFKChange:1;
  734. u32 supportSetLinkSpeed:1;
  735. u32 supportEmergencySpares:1;
  736. u32 supportSuspendResumeBGops:1;
  737. u32 blockSSDWriteCacheChange:1;
  738. u32 supportShieldState:1;
  739. u32 supportLdBBMInfo:1;
  740. u32 supportLdPIType3:1;
  741. u32 supportLdPIType2:1;
  742. u32 supportLdPIType1:1;
  743. u32 supportPIcontroller:1;
  744. #else
  745. u32 supportPIcontroller:1;
  746. u32 supportLdPIType1:1;
  747. u32 supportLdPIType2:1;
  748. u32 supportLdPIType3:1;
  749. u32 supportLdBBMInfo:1;
  750. u32 supportShieldState:1;
  751. u32 blockSSDWriteCacheChange:1;
  752. u32 supportSuspendResumeBGops:1;
  753. u32 supportEmergencySpares:1;
  754. u32 supportSetLinkSpeed:1;
  755. u32 supportBootTimePFKChange:1;
  756. u32 supportJBOD:1;
  757. u32 disableOnlinePFKChange:1;
  758. u32 supportPerfTuning:1;
  759. u32 supportSSDPatrolRead:1;
  760. u32 realTimeScheduler:1;
  761. u32 supportResetNow:1;
  762. u32 supportEmulatedDrives:1;
  763. u32 headlessMode:1;
  764. u32 dedicatedHotSparesLimited:1;
  765. u32 supportUnevenSpans:1;
  766. u32 reserved:11;
  767. #endif
  768. } adapterOperations2;
  769. u8 driverVersion[32]; /*7A8h */
  770. u8 maxDAPdCountSpinup60; /*7C8h */
  771. u8 temperatureROC; /*7C9h */
  772. u8 temperatureCtrl; /*7CAh */
  773. u8 reserved4; /*7CBh */
  774. u16 maxConfigurablePds; /*7CCh */
  775. u8 reserved5[2]; /*0x7CDh */
  776. /*
  777. * HA cluster information
  778. */
  779. struct {
  780. u32 peerIsPresent:1;
  781. u32 peerIsIncompatible:1;
  782. u32 hwIncompatible:1;
  783. u32 fwVersionMismatch:1;
  784. u32 ctrlPropIncompatible:1;
  785. u32 premiumFeatureMismatch:1;
  786. u32 reserved:26;
  787. } cluster;
  788. char clusterId[16]; /*7D4h */
  789. u8 pad[0x800-0x7E4]; /*7E4 */
  790. } __packed;
  791. /*
  792. * ===============================
  793. * MegaRAID SAS driver definitions
  794. * ===============================
  795. */
  796. #define MEGASAS_MAX_PD_CHANNELS 2
  797. #define MEGASAS_MAX_LD_CHANNELS 1
  798. #define MEGASAS_MAX_CHANNELS (MEGASAS_MAX_PD_CHANNELS + \
  799. MEGASAS_MAX_LD_CHANNELS)
  800. #define MEGASAS_MAX_DEV_PER_CHANNEL 128
  801. #define MEGASAS_DEFAULT_INIT_ID -1
  802. #define MEGASAS_MAX_LUN 8
  803. #define MEGASAS_MAX_LD 64
  804. #define MEGASAS_DEFAULT_CMD_PER_LUN 256
  805. #define MEGASAS_MAX_PD (MEGASAS_MAX_PD_CHANNELS * \
  806. MEGASAS_MAX_DEV_PER_CHANNEL)
  807. #define MEGASAS_MAX_LD_IDS (MEGASAS_MAX_LD_CHANNELS * \
  808. MEGASAS_MAX_DEV_PER_CHANNEL)
  809. #define MEGASAS_MAX_SECTORS (2*1024)
  810. #define MEGASAS_MAX_SECTORS_IEEE (2*128)
  811. #define MEGASAS_DBG_LVL 1
  812. #define MEGASAS_FW_BUSY 1
  813. /* Frame Type */
  814. #define IO_FRAME 0
  815. #define PTHRU_FRAME 1
  816. /*
  817. * When SCSI mid-layer calls driver's reset routine, driver waits for
  818. * MEGASAS_RESET_WAIT_TIME seconds for all outstanding IO to complete. Note
  819. * that the driver cannot _actually_ abort or reset pending commands. While
  820. * it is waiting for the commands to complete, it prints a diagnostic message
  821. * every MEGASAS_RESET_NOTICE_INTERVAL seconds
  822. */
  823. #define MEGASAS_RESET_WAIT_TIME 180
  824. #define MEGASAS_INTERNAL_CMD_WAIT_TIME 180
  825. #define MEGASAS_RESET_NOTICE_INTERVAL 5
  826. #define MEGASAS_IOCTL_CMD 0
  827. #define MEGASAS_DEFAULT_CMD_TIMEOUT 90
  828. #define MEGASAS_THROTTLE_QUEUE_DEPTH 16
  829. /*
  830. * FW reports the maximum of number of commands that it can accept (maximum
  831. * commands that can be outstanding) at any time. The driver must report a
  832. * lower number to the mid layer because it can issue a few internal commands
  833. * itself (E.g, AEN, abort cmd, IOCTLs etc). The number of commands it needs
  834. * is shown below
  835. */
  836. #define MEGASAS_INT_CMDS 32
  837. #define MEGASAS_SKINNY_INT_CMDS 5
  838. #define MEGASAS_MAX_MSIX_QUEUES 128
  839. /*
  840. * FW can accept both 32 and 64 bit SGLs. We want to allocate 32/64 bit
  841. * SGLs based on the size of dma_addr_t
  842. */
  843. #define IS_DMA64 (sizeof(dma_addr_t) == 8)
  844. #define MFI_XSCALE_OMR0_CHANGE_INTERRUPT 0x00000001
  845. #define MFI_INTR_FLAG_REPLY_MESSAGE 0x00000001
  846. #define MFI_INTR_FLAG_FIRMWARE_STATE_CHANGE 0x00000002
  847. #define MFI_G2_OUTBOUND_DOORBELL_CHANGE_INTERRUPT 0x00000004
  848. #define MFI_OB_INTR_STATUS_MASK 0x00000002
  849. #define MFI_POLL_TIMEOUT_SECS 60
  850. #define MFI_REPLY_1078_MESSAGE_INTERRUPT 0x80000000
  851. #define MFI_REPLY_GEN2_MESSAGE_INTERRUPT 0x00000001
  852. #define MFI_GEN2_ENABLE_INTERRUPT_MASK (0x00000001 | 0x00000004)
  853. #define MFI_REPLY_SKINNY_MESSAGE_INTERRUPT 0x40000000
  854. #define MFI_SKINNY_ENABLE_INTERRUPT_MASK (0x00000001)
  855. #define MFI_1068_PCSR_OFFSET 0x84
  856. #define MFI_1068_FW_HANDSHAKE_OFFSET 0x64
  857. #define MFI_1068_FW_READY 0xDDDD0000
  858. #define MR_MAX_REPLY_QUEUES_OFFSET 0X0000001F
  859. #define MR_MAX_REPLY_QUEUES_EXT_OFFSET 0X003FC000
  860. #define MR_MAX_REPLY_QUEUES_EXT_OFFSET_SHIFT 14
  861. #define MR_MAX_MSIX_REG_ARRAY 16
  862. /*
  863. * register set for both 1068 and 1078 controllers
  864. * structure extended for 1078 registers
  865. */
  866. struct megasas_register_set {
  867. u32 doorbell; /*0000h*/
  868. u32 fusion_seq_offset; /*0004h*/
  869. u32 fusion_host_diag; /*0008h*/
  870. u32 reserved_01; /*000Ch*/
  871. u32 inbound_msg_0; /*0010h*/
  872. u32 inbound_msg_1; /*0014h*/
  873. u32 outbound_msg_0; /*0018h*/
  874. u32 outbound_msg_1; /*001Ch*/
  875. u32 inbound_doorbell; /*0020h*/
  876. u32 inbound_intr_status; /*0024h*/
  877. u32 inbound_intr_mask; /*0028h*/
  878. u32 outbound_doorbell; /*002Ch*/
  879. u32 outbound_intr_status; /*0030h*/
  880. u32 outbound_intr_mask; /*0034h*/
  881. u32 reserved_1[2]; /*0038h*/
  882. u32 inbound_queue_port; /*0040h*/
  883. u32 outbound_queue_port; /*0044h*/
  884. u32 reserved_2[9]; /*0048h*/
  885. u32 reply_post_host_index; /*006Ch*/
  886. u32 reserved_2_2[12]; /*0070h*/
  887. u32 outbound_doorbell_clear; /*00A0h*/
  888. u32 reserved_3[3]; /*00A4h*/
  889. u32 outbound_scratch_pad ; /*00B0h*/
  890. u32 outbound_scratch_pad_2; /*00B4h*/
  891. u32 reserved_4[2]; /*00B8h*/
  892. u32 inbound_low_queue_port ; /*00C0h*/
  893. u32 inbound_high_queue_port ; /*00C4h*/
  894. u32 reserved_5; /*00C8h*/
  895. u32 res_6[11]; /*CCh*/
  896. u32 host_diag;
  897. u32 seq_offset;
  898. u32 index_registers[807]; /*00CCh*/
  899. } __attribute__ ((packed));
  900. struct megasas_sge32 {
  901. u32 phys_addr;
  902. u32 length;
  903. } __attribute__ ((packed));
  904. struct megasas_sge64 {
  905. u64 phys_addr;
  906. u32 length;
  907. } __attribute__ ((packed));
  908. struct megasas_sge_skinny {
  909. u64 phys_addr;
  910. u32 length;
  911. u32 flag;
  912. } __packed;
  913. union megasas_sgl {
  914. struct megasas_sge32 sge32[1];
  915. struct megasas_sge64 sge64[1];
  916. struct megasas_sge_skinny sge_skinny[1];
  917. } __attribute__ ((packed));
  918. struct megasas_header {
  919. u8 cmd; /*00h */
  920. u8 sense_len; /*01h */
  921. u8 cmd_status; /*02h */
  922. u8 scsi_status; /*03h */
  923. u8 target_id; /*04h */
  924. u8 lun; /*05h */
  925. u8 cdb_len; /*06h */
  926. u8 sge_count; /*07h */
  927. u32 context; /*08h */
  928. u32 pad_0; /*0Ch */
  929. u16 flags; /*10h */
  930. u16 timeout; /*12h */
  931. u32 data_xferlen; /*14h */
  932. } __attribute__ ((packed));
  933. union megasas_sgl_frame {
  934. struct megasas_sge32 sge32[8];
  935. struct megasas_sge64 sge64[5];
  936. } __attribute__ ((packed));
  937. typedef union _MFI_CAPABILITIES {
  938. struct {
  939. #if defined(__BIG_ENDIAN_BITFIELD)
  940. u32 reserved:30;
  941. u32 support_additional_msix:1;
  942. u32 support_fp_remote_lun:1;
  943. #else
  944. u32 support_fp_remote_lun:1;
  945. u32 support_additional_msix:1;
  946. u32 reserved:30;
  947. #endif
  948. } mfi_capabilities;
  949. u32 reg;
  950. } MFI_CAPABILITIES;
  951. struct megasas_init_frame {
  952. u8 cmd; /*00h */
  953. u8 reserved_0; /*01h */
  954. u8 cmd_status; /*02h */
  955. u8 reserved_1; /*03h */
  956. MFI_CAPABILITIES driver_operations; /*04h*/
  957. u32 context; /*08h */
  958. u32 pad_0; /*0Ch */
  959. u16 flags; /*10h */
  960. u16 reserved_3; /*12h */
  961. u32 data_xfer_len; /*14h */
  962. u32 queue_info_new_phys_addr_lo; /*18h */
  963. u32 queue_info_new_phys_addr_hi; /*1Ch */
  964. u32 queue_info_old_phys_addr_lo; /*20h */
  965. u32 queue_info_old_phys_addr_hi; /*24h */
  966. u32 reserved_4[6]; /*28h */
  967. } __attribute__ ((packed));
  968. struct megasas_init_queue_info {
  969. u32 init_flags; /*00h */
  970. u32 reply_queue_entries; /*04h */
  971. u32 reply_queue_start_phys_addr_lo; /*08h */
  972. u32 reply_queue_start_phys_addr_hi; /*0Ch */
  973. u32 producer_index_phys_addr_lo; /*10h */
  974. u32 producer_index_phys_addr_hi; /*14h */
  975. u32 consumer_index_phys_addr_lo; /*18h */
  976. u32 consumer_index_phys_addr_hi; /*1Ch */
  977. } __attribute__ ((packed));
  978. struct megasas_io_frame {
  979. u8 cmd; /*00h */
  980. u8 sense_len; /*01h */
  981. u8 cmd_status; /*02h */
  982. u8 scsi_status; /*03h */
  983. u8 target_id; /*04h */
  984. u8 access_byte; /*05h */
  985. u8 reserved_0; /*06h */
  986. u8 sge_count; /*07h */
  987. u32 context; /*08h */
  988. u32 pad_0; /*0Ch */
  989. u16 flags; /*10h */
  990. u16 timeout; /*12h */
  991. u32 lba_count; /*14h */
  992. u32 sense_buf_phys_addr_lo; /*18h */
  993. u32 sense_buf_phys_addr_hi; /*1Ch */
  994. u32 start_lba_lo; /*20h */
  995. u32 start_lba_hi; /*24h */
  996. union megasas_sgl sgl; /*28h */
  997. } __attribute__ ((packed));
  998. struct megasas_pthru_frame {
  999. u8 cmd; /*00h */
  1000. u8 sense_len; /*01h */
  1001. u8 cmd_status; /*02h */
  1002. u8 scsi_status; /*03h */
  1003. u8 target_id; /*04h */
  1004. u8 lun; /*05h */
  1005. u8 cdb_len; /*06h */
  1006. u8 sge_count; /*07h */
  1007. u32 context; /*08h */
  1008. u32 pad_0; /*0Ch */
  1009. u16 flags; /*10h */
  1010. u16 timeout; /*12h */
  1011. u32 data_xfer_len; /*14h */
  1012. u32 sense_buf_phys_addr_lo; /*18h */
  1013. u32 sense_buf_phys_addr_hi; /*1Ch */
  1014. u8 cdb[16]; /*20h */
  1015. union megasas_sgl sgl; /*30h */
  1016. } __attribute__ ((packed));
  1017. struct megasas_dcmd_frame {
  1018. u8 cmd; /*00h */
  1019. u8 reserved_0; /*01h */
  1020. u8 cmd_status; /*02h */
  1021. u8 reserved_1[4]; /*03h */
  1022. u8 sge_count; /*07h */
  1023. u32 context; /*08h */
  1024. u32 pad_0; /*0Ch */
  1025. u16 flags; /*10h */
  1026. u16 timeout; /*12h */
  1027. u32 data_xfer_len; /*14h */
  1028. u32 opcode; /*18h */
  1029. union { /*1Ch */
  1030. u8 b[12];
  1031. u16 s[6];
  1032. u32 w[3];
  1033. } mbox;
  1034. union megasas_sgl sgl; /*28h */
  1035. } __attribute__ ((packed));
  1036. struct megasas_abort_frame {
  1037. u8 cmd; /*00h */
  1038. u8 reserved_0; /*01h */
  1039. u8 cmd_status; /*02h */
  1040. u8 reserved_1; /*03h */
  1041. u32 reserved_2; /*04h */
  1042. u32 context; /*08h */
  1043. u32 pad_0; /*0Ch */
  1044. u16 flags; /*10h */
  1045. u16 reserved_3; /*12h */
  1046. u32 reserved_4; /*14h */
  1047. u32 abort_context; /*18h */
  1048. u32 pad_1; /*1Ch */
  1049. u32 abort_mfi_phys_addr_lo; /*20h */
  1050. u32 abort_mfi_phys_addr_hi; /*24h */
  1051. u32 reserved_5[6]; /*28h */
  1052. } __attribute__ ((packed));
  1053. struct megasas_smp_frame {
  1054. u8 cmd; /*00h */
  1055. u8 reserved_1; /*01h */
  1056. u8 cmd_status; /*02h */
  1057. u8 connection_status; /*03h */
  1058. u8 reserved_2[3]; /*04h */
  1059. u8 sge_count; /*07h */
  1060. u32 context; /*08h */
  1061. u32 pad_0; /*0Ch */
  1062. u16 flags; /*10h */
  1063. u16 timeout; /*12h */
  1064. u32 data_xfer_len; /*14h */
  1065. u64 sas_addr; /*18h */
  1066. union {
  1067. struct megasas_sge32 sge32[2]; /* [0]: resp [1]: req */
  1068. struct megasas_sge64 sge64[2]; /* [0]: resp [1]: req */
  1069. } sgl;
  1070. } __attribute__ ((packed));
  1071. struct megasas_stp_frame {
  1072. u8 cmd; /*00h */
  1073. u8 reserved_1; /*01h */
  1074. u8 cmd_status; /*02h */
  1075. u8 reserved_2; /*03h */
  1076. u8 target_id; /*04h */
  1077. u8 reserved_3[2]; /*05h */
  1078. u8 sge_count; /*07h */
  1079. u32 context; /*08h */
  1080. u32 pad_0; /*0Ch */
  1081. u16 flags; /*10h */
  1082. u16 timeout; /*12h */
  1083. u32 data_xfer_len; /*14h */
  1084. u16 fis[10]; /*18h */
  1085. u32 stp_flags;
  1086. union {
  1087. struct megasas_sge32 sge32[2]; /* [0]: resp [1]: data */
  1088. struct megasas_sge64 sge64[2]; /* [0]: resp [1]: data */
  1089. } sgl;
  1090. } __attribute__ ((packed));
  1091. union megasas_frame {
  1092. struct megasas_header hdr;
  1093. struct megasas_init_frame init;
  1094. struct megasas_io_frame io;
  1095. struct megasas_pthru_frame pthru;
  1096. struct megasas_dcmd_frame dcmd;
  1097. struct megasas_abort_frame abort;
  1098. struct megasas_smp_frame smp;
  1099. struct megasas_stp_frame stp;
  1100. u8 raw_bytes[64];
  1101. };
  1102. struct megasas_cmd;
  1103. union megasas_evt_class_locale {
  1104. struct {
  1105. u16 locale;
  1106. u8 reserved;
  1107. s8 class;
  1108. } __attribute__ ((packed)) members;
  1109. u32 word;
  1110. } __attribute__ ((packed));
  1111. struct megasas_evt_log_info {
  1112. u32 newest_seq_num;
  1113. u32 oldest_seq_num;
  1114. u32 clear_seq_num;
  1115. u32 shutdown_seq_num;
  1116. u32 boot_seq_num;
  1117. } __attribute__ ((packed));
  1118. struct megasas_progress {
  1119. u16 progress;
  1120. u16 elapsed_seconds;
  1121. } __attribute__ ((packed));
  1122. struct megasas_evtarg_ld {
  1123. u16 target_id;
  1124. u8 ld_index;
  1125. u8 reserved;
  1126. } __attribute__ ((packed));
  1127. struct megasas_evtarg_pd {
  1128. u16 device_id;
  1129. u8 encl_index;
  1130. u8 slot_number;
  1131. } __attribute__ ((packed));
  1132. struct megasas_evt_detail {
  1133. u32 seq_num;
  1134. u32 time_stamp;
  1135. u32 code;
  1136. union megasas_evt_class_locale cl;
  1137. u8 arg_type;
  1138. u8 reserved1[15];
  1139. union {
  1140. struct {
  1141. struct megasas_evtarg_pd pd;
  1142. u8 cdb_length;
  1143. u8 sense_length;
  1144. u8 reserved[2];
  1145. u8 cdb[16];
  1146. u8 sense[64];
  1147. } __attribute__ ((packed)) cdbSense;
  1148. struct megasas_evtarg_ld ld;
  1149. struct {
  1150. struct megasas_evtarg_ld ld;
  1151. u64 count;
  1152. } __attribute__ ((packed)) ld_count;
  1153. struct {
  1154. u64 lba;
  1155. struct megasas_evtarg_ld ld;
  1156. } __attribute__ ((packed)) ld_lba;
  1157. struct {
  1158. struct megasas_evtarg_ld ld;
  1159. u32 prevOwner;
  1160. u32 newOwner;
  1161. } __attribute__ ((packed)) ld_owner;
  1162. struct {
  1163. u64 ld_lba;
  1164. u64 pd_lba;
  1165. struct megasas_evtarg_ld ld;
  1166. struct megasas_evtarg_pd pd;
  1167. } __attribute__ ((packed)) ld_lba_pd_lba;
  1168. struct {
  1169. struct megasas_evtarg_ld ld;
  1170. struct megasas_progress prog;
  1171. } __attribute__ ((packed)) ld_prog;
  1172. struct {
  1173. struct megasas_evtarg_ld ld;
  1174. u32 prev_state;
  1175. u32 new_state;
  1176. } __attribute__ ((packed)) ld_state;
  1177. struct {
  1178. u64 strip;
  1179. struct megasas_evtarg_ld ld;
  1180. } __attribute__ ((packed)) ld_strip;
  1181. struct megasas_evtarg_pd pd;
  1182. struct {
  1183. struct megasas_evtarg_pd pd;
  1184. u32 err;
  1185. } __attribute__ ((packed)) pd_err;
  1186. struct {
  1187. u64 lba;
  1188. struct megasas_evtarg_pd pd;
  1189. } __attribute__ ((packed)) pd_lba;
  1190. struct {
  1191. u64 lba;
  1192. struct megasas_evtarg_pd pd;
  1193. struct megasas_evtarg_ld ld;
  1194. } __attribute__ ((packed)) pd_lba_ld;
  1195. struct {
  1196. struct megasas_evtarg_pd pd;
  1197. struct megasas_progress prog;
  1198. } __attribute__ ((packed)) pd_prog;
  1199. struct {
  1200. struct megasas_evtarg_pd pd;
  1201. u32 prevState;
  1202. u32 newState;
  1203. } __attribute__ ((packed)) pd_state;
  1204. struct {
  1205. u16 vendorId;
  1206. u16 deviceId;
  1207. u16 subVendorId;
  1208. u16 subDeviceId;
  1209. } __attribute__ ((packed)) pci;
  1210. u32 rate;
  1211. char str[96];
  1212. struct {
  1213. u32 rtc;
  1214. u32 elapsedSeconds;
  1215. } __attribute__ ((packed)) time;
  1216. struct {
  1217. u32 ecar;
  1218. u32 elog;
  1219. char str[64];
  1220. } __attribute__ ((packed)) ecc;
  1221. u8 b[96];
  1222. u16 s[48];
  1223. u32 w[24];
  1224. u64 d[12];
  1225. } args;
  1226. char description[128];
  1227. } __attribute__ ((packed));
  1228. struct megasas_aen_event {
  1229. struct delayed_work hotplug_work;
  1230. struct megasas_instance *instance;
  1231. };
  1232. struct megasas_irq_context {
  1233. struct megasas_instance *instance;
  1234. u32 MSIxIndex;
  1235. };
  1236. struct megasas_instance {
  1237. u32 *producer;
  1238. dma_addr_t producer_h;
  1239. u32 *consumer;
  1240. dma_addr_t consumer_h;
  1241. u32 *reply_queue;
  1242. dma_addr_t reply_queue_h;
  1243. unsigned long base_addr;
  1244. struct megasas_register_set __iomem *reg_set;
  1245. u32 *reply_post_host_index_addr[MR_MAX_MSIX_REG_ARRAY];
  1246. struct megasas_pd_list pd_list[MEGASAS_MAX_PD];
  1247. u8 ld_ids[MEGASAS_MAX_LD_IDS];
  1248. s8 init_id;
  1249. u16 max_num_sge;
  1250. u16 max_fw_cmds;
  1251. /* For Fusion its num IOCTL cmds, for others MFI based its
  1252. max_fw_cmds */
  1253. u16 max_mfi_cmds;
  1254. u32 max_sectors_per_req;
  1255. struct megasas_aen_event *ev;
  1256. struct megasas_cmd **cmd_list;
  1257. struct list_head cmd_pool;
  1258. /* used to sync fire the cmd to fw */
  1259. spinlock_t cmd_pool_lock;
  1260. /* used to sync fire the cmd to fw */
  1261. spinlock_t hba_lock;
  1262. /* used to synch producer, consumer ptrs in dpc */
  1263. spinlock_t completion_lock;
  1264. struct dma_pool *frame_dma_pool;
  1265. struct dma_pool *sense_dma_pool;
  1266. struct megasas_evt_detail *evt_detail;
  1267. dma_addr_t evt_detail_h;
  1268. struct megasas_cmd *aen_cmd;
  1269. struct mutex aen_mutex;
  1270. struct semaphore ioctl_sem;
  1271. struct Scsi_Host *host;
  1272. wait_queue_head_t int_cmd_wait_q;
  1273. wait_queue_head_t abort_cmd_wait_q;
  1274. struct pci_dev *pdev;
  1275. u32 unique_id;
  1276. u32 fw_support_ieee;
  1277. atomic_t fw_outstanding;
  1278. atomic_t fw_reset_no_pci_access;
  1279. struct megasas_instance_template *instancet;
  1280. struct tasklet_struct isr_tasklet;
  1281. struct work_struct work_init;
  1282. u8 flag;
  1283. u8 unload;
  1284. u8 flag_ieee;
  1285. u8 issuepend_done;
  1286. u8 disableOnlineCtrlReset;
  1287. u8 UnevenSpanSupport;
  1288. u8 adprecovery;
  1289. unsigned long last_time;
  1290. u32 mfiStatus;
  1291. u32 last_seq_num;
  1292. struct list_head internal_reset_pending_q;
  1293. /* Ptr to hba specific information */
  1294. void *ctrl_context;
  1295. unsigned int msix_vectors;
  1296. struct msix_entry msixentry[MEGASAS_MAX_MSIX_QUEUES];
  1297. struct megasas_irq_context irq_context[MEGASAS_MAX_MSIX_QUEUES];
  1298. u64 map_id;
  1299. struct megasas_cmd *map_update_cmd;
  1300. unsigned long bar;
  1301. long reset_flags;
  1302. struct mutex reset_mutex;
  1303. int throttlequeuedepth;
  1304. u8 mask_interrupts;
  1305. u8 is_imr;
  1306. };
  1307. enum {
  1308. MEGASAS_HBA_OPERATIONAL = 0,
  1309. MEGASAS_ADPRESET_SM_INFAULT = 1,
  1310. MEGASAS_ADPRESET_SM_FW_RESET_SUCCESS = 2,
  1311. MEGASAS_ADPRESET_SM_OPERATIONAL = 3,
  1312. MEGASAS_HW_CRITICAL_ERROR = 4,
  1313. MEGASAS_ADPRESET_INPROG_SIGN = 0xDEADDEAD,
  1314. };
  1315. struct megasas_instance_template {
  1316. void (*fire_cmd)(struct megasas_instance *, dma_addr_t, \
  1317. u32, struct megasas_register_set __iomem *);
  1318. void (*enable_intr)(struct megasas_instance *);
  1319. void (*disable_intr)(struct megasas_instance *);
  1320. int (*clear_intr)(struct megasas_register_set __iomem *);
  1321. u32 (*read_fw_status_reg)(struct megasas_register_set __iomem *);
  1322. int (*adp_reset)(struct megasas_instance *, \
  1323. struct megasas_register_set __iomem *);
  1324. int (*check_reset)(struct megasas_instance *, \
  1325. struct megasas_register_set __iomem *);
  1326. irqreturn_t (*service_isr)(int irq, void *devp);
  1327. void (*tasklet)(unsigned long);
  1328. u32 (*init_adapter)(struct megasas_instance *);
  1329. u32 (*build_and_issue_cmd) (struct megasas_instance *,
  1330. struct scsi_cmnd *);
  1331. void (*issue_dcmd) (struct megasas_instance *instance,
  1332. struct megasas_cmd *cmd);
  1333. };
  1334. #define MEGASAS_IS_LOGICAL(scp) \
  1335. (scp->device->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1
  1336. #define MEGASAS_DEV_INDEX(inst, scp) \
  1337. ((scp->device->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) + \
  1338. scp->device->id
  1339. struct megasas_cmd {
  1340. union megasas_frame *frame;
  1341. dma_addr_t frame_phys_addr;
  1342. u8 *sense;
  1343. dma_addr_t sense_phys_addr;
  1344. u32 index;
  1345. u8 sync_cmd;
  1346. u8 cmd_status;
  1347. u8 abort_aen;
  1348. u8 retry_for_fw_reset;
  1349. struct list_head list;
  1350. struct scsi_cmnd *scmd;
  1351. struct megasas_instance *instance;
  1352. union {
  1353. struct {
  1354. u16 smid;
  1355. u16 resvd;
  1356. } context;
  1357. u32 frame_count;
  1358. };
  1359. };
  1360. #define MAX_MGMT_ADAPTERS 1024
  1361. #define MAX_IOCTL_SGE 16
  1362. struct megasas_iocpacket {
  1363. u16 host_no;
  1364. u16 __pad1;
  1365. u32 sgl_off;
  1366. u32 sge_count;
  1367. u32 sense_off;
  1368. u32 sense_len;
  1369. union {
  1370. u8 raw[128];
  1371. struct megasas_header hdr;
  1372. } frame;
  1373. struct iovec sgl[MAX_IOCTL_SGE];
  1374. } __attribute__ ((packed));
  1375. struct megasas_aen {
  1376. u16 host_no;
  1377. u16 __pad1;
  1378. u32 seq_num;
  1379. u32 class_locale_word;
  1380. } __attribute__ ((packed));
  1381. #ifdef CONFIG_COMPAT
  1382. struct compat_megasas_iocpacket {
  1383. u16 host_no;
  1384. u16 __pad1;
  1385. u32 sgl_off;
  1386. u32 sge_count;
  1387. u32 sense_off;
  1388. u32 sense_len;
  1389. union {
  1390. u8 raw[128];
  1391. struct megasas_header hdr;
  1392. } frame;
  1393. struct compat_iovec sgl[MAX_IOCTL_SGE];
  1394. } __attribute__ ((packed));
  1395. #define MEGASAS_IOC_FIRMWARE32 _IOWR('M', 1, struct compat_megasas_iocpacket)
  1396. #endif
  1397. #define MEGASAS_IOC_FIRMWARE _IOWR('M', 1, struct megasas_iocpacket)
  1398. #define MEGASAS_IOC_GET_AEN _IOW('M', 3, struct megasas_aen)
  1399. struct megasas_mgmt_info {
  1400. u16 count;
  1401. struct megasas_instance *instance[MAX_MGMT_ADAPTERS];
  1402. int max_index;
  1403. };
  1404. u8
  1405. MR_BuildRaidContext(struct megasas_instance *instance,
  1406. struct IO_REQUEST_INFO *io_info,
  1407. struct RAID_CONTEXT *pRAID_Context,
  1408. struct MR_FW_RAID_MAP_ALL *map, u8 **raidLUN);
  1409. u16 MR_TargetIdToLdGet(u32 ldTgtId, struct MR_FW_RAID_MAP_ALL *map);
  1410. struct MR_LD_RAID *MR_LdRaidGet(u32 ld, struct MR_FW_RAID_MAP_ALL *map);
  1411. u16 MR_ArPdGet(u32 ar, u32 arm, struct MR_FW_RAID_MAP_ALL *map);
  1412. u16 MR_LdSpanArrayGet(u32 ld, u32 span, struct MR_FW_RAID_MAP_ALL *map);
  1413. u16 MR_PdDevHandleGet(u32 pd, struct MR_FW_RAID_MAP_ALL *map);
  1414. u16 MR_GetLDTgtId(u32 ld, struct MR_FW_RAID_MAP_ALL *map);
  1415. #endif /*LSI_MEGARAID_SAS_H */