megaraid_sas_fusion.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  1. /*
  2. * Linux MegaRAID driver for SAS based RAID controllers
  3. *
  4. * Copyright (c) 2009-2013 LSI Corporation
  5. * Copyright (c) 2013-2014 Avago Technologies
  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 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * FILE: megaraid_sas_fusion.h
  21. *
  22. * Authors: Avago Technologies
  23. * Manoj Jose
  24. * Sumant Patro
  25. * Kashyap Desai <kashyap.desai@avagotech.com>
  26. * Sumit Saxena <sumit.saxena@avagotech.com>
  27. *
  28. * Send feedback to: megaraidlinux.pdl@avagotech.com
  29. *
  30. * Mail to: Avago Technologies, 350 West Trimble Road, Building 90,
  31. * San Jose, California 95131
  32. */
  33. #ifndef _MEGARAID_SAS_FUSION_H_
  34. #define _MEGARAID_SAS_FUSION_H_
  35. /* Fusion defines */
  36. #define MEGASAS_CHAIN_FRAME_SZ_MIN 1024
  37. #define MFI_FUSION_ENABLE_INTERRUPT_MASK (0x00000009)
  38. #define MEGASAS_MAX_CHAIN_SHIFT 5
  39. #define MEGASAS_MAX_CHAIN_SIZE_UNITS_MASK 0x400000
  40. #define MEGASAS_MAX_CHAIN_SIZE_MASK 0x3E0
  41. #define MEGASAS_256K_IO 128
  42. #define MEGASAS_1MB_IO (MEGASAS_256K_IO * 4)
  43. #define MEGA_MPI2_RAID_DEFAULT_IO_FRAME_SIZE 256
  44. #define MEGASAS_MPI2_FUNCTION_PASSTHRU_IO_REQUEST 0xF0
  45. #define MEGASAS_MPI2_FUNCTION_LD_IO_REQUEST 0xF1
  46. #define MEGASAS_LOAD_BALANCE_FLAG 0x1
  47. #define MEGASAS_DCMD_MBOX_PEND_FLAG 0x1
  48. #define HOST_DIAG_WRITE_ENABLE 0x80
  49. #define HOST_DIAG_RESET_ADAPTER 0x4
  50. #define MEGASAS_FUSION_MAX_RESET_TRIES 3
  51. #define MAX_MSIX_QUEUES_FUSION 128
  52. /* Invader defines */
  53. #define MPI2_TYPE_CUDA 0x2
  54. #define MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH 0x4000
  55. #define MR_RL_FLAGS_GRANT_DESTINATION_CPU0 0x00
  56. #define MR_RL_FLAGS_GRANT_DESTINATION_CPU1 0x10
  57. #define MR_RL_FLAGS_GRANT_DESTINATION_CUDA 0x80
  58. #define MR_RL_FLAGS_SEQ_NUM_ENABLE 0x8
  59. /* T10 PI defines */
  60. #define MR_PROT_INFO_TYPE_CONTROLLER 0x8
  61. #define MEGASAS_SCSI_VARIABLE_LENGTH_CMD 0x7f
  62. #define MEGASAS_SCSI_SERVICE_ACTION_READ32 0x9
  63. #define MEGASAS_SCSI_SERVICE_ACTION_WRITE32 0xB
  64. #define MEGASAS_SCSI_ADDL_CDB_LEN 0x18
  65. #define MEGASAS_RD_WR_PROTECT_CHECK_ALL 0x20
  66. #define MEGASAS_RD_WR_PROTECT_CHECK_NONE 0x60
  67. #define MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET (0x0000030C)
  68. #define MPI2_REPLY_POST_HOST_INDEX_OFFSET (0x0000006C)
  69. /*
  70. * Raid context flags
  71. */
  72. #define MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT 0x4
  73. #define MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_MASK 0x30
  74. enum MR_RAID_FLAGS_IO_SUB_TYPE {
  75. MR_RAID_FLAGS_IO_SUB_TYPE_NONE = 0,
  76. MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD = 1,
  77. };
  78. /*
  79. * Request descriptor types
  80. */
  81. #define MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO 0x7
  82. #define MEGASAS_REQ_DESCRIPT_FLAGS_MFA 0x1
  83. #define MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK 0x2
  84. #define MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT 1
  85. #define MEGASAS_FP_CMD_LEN 16
  86. #define MEGASAS_FUSION_IN_RESET 0
  87. #define THRESHOLD_REPLY_COUNT 50
  88. #define JBOD_MAPS_COUNT 2
  89. enum MR_FUSION_ADAPTER_TYPE {
  90. THUNDERBOLT_SERIES = 0,
  91. INVADER_SERIES = 1,
  92. };
  93. /*
  94. * Raid Context structure which describes MegaRAID specific IO Parameters
  95. * This resides at offset 0x60 where the SGL normally starts in MPT IO Frames
  96. */
  97. struct RAID_CONTEXT {
  98. #if defined(__BIG_ENDIAN_BITFIELD)
  99. u8 nseg:4;
  100. u8 Type:4;
  101. #else
  102. u8 Type:4;
  103. u8 nseg:4;
  104. #endif
  105. u8 resvd0;
  106. __le16 timeoutValue;
  107. u8 regLockFlags;
  108. u8 resvd1;
  109. __le16 VirtualDiskTgtId;
  110. __le64 regLockRowLBA;
  111. __le32 regLockLength;
  112. __le16 nextLMId;
  113. u8 exStatus;
  114. u8 status;
  115. u8 RAIDFlags;
  116. u8 numSGE;
  117. __le16 configSeqNum;
  118. u8 spanArm;
  119. u8 priority;
  120. u8 numSGEExt;
  121. u8 resvd2;
  122. };
  123. #define RAID_CTX_SPANARM_ARM_SHIFT (0)
  124. #define RAID_CTX_SPANARM_ARM_MASK (0x1f)
  125. #define RAID_CTX_SPANARM_SPAN_SHIFT (5)
  126. #define RAID_CTX_SPANARM_SPAN_MASK (0xE0)
  127. /*
  128. * define region lock types
  129. */
  130. enum REGION_TYPE {
  131. REGION_TYPE_UNUSED = 0,
  132. REGION_TYPE_SHARED_READ = 1,
  133. REGION_TYPE_SHARED_WRITE = 2,
  134. REGION_TYPE_EXCLUSIVE = 3,
  135. };
  136. /* MPI2 defines */
  137. #define MPI2_FUNCTION_IOC_INIT (0x02) /* IOC Init */
  138. #define MPI2_WHOINIT_HOST_DRIVER (0x04)
  139. #define MPI2_VERSION_MAJOR (0x02)
  140. #define MPI2_VERSION_MINOR (0x00)
  141. #define MPI2_VERSION_MAJOR_MASK (0xFF00)
  142. #define MPI2_VERSION_MAJOR_SHIFT (8)
  143. #define MPI2_VERSION_MINOR_MASK (0x00FF)
  144. #define MPI2_VERSION_MINOR_SHIFT (0)
  145. #define MPI2_VERSION ((MPI2_VERSION_MAJOR << MPI2_VERSION_MAJOR_SHIFT) | \
  146. MPI2_VERSION_MINOR)
  147. #define MPI2_HEADER_VERSION_UNIT (0x10)
  148. #define MPI2_HEADER_VERSION_DEV (0x00)
  149. #define MPI2_HEADER_VERSION_UNIT_MASK (0xFF00)
  150. #define MPI2_HEADER_VERSION_UNIT_SHIFT (8)
  151. #define MPI2_HEADER_VERSION_DEV_MASK (0x00FF)
  152. #define MPI2_HEADER_VERSION_DEV_SHIFT (0)
  153. #define MPI2_HEADER_VERSION ((MPI2_HEADER_VERSION_UNIT << 8) | \
  154. MPI2_HEADER_VERSION_DEV)
  155. #define MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR (0x03)
  156. #define MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG (0x8000)
  157. #define MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG (0x0400)
  158. #define MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP (0x0003)
  159. #define MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG (0x0200)
  160. #define MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD (0x0100)
  161. #define MPI2_SCSIIO_EEDPFLAGS_INSERT_OP (0x0004)
  162. #define MPI2_FUNCTION_SCSI_IO_REQUEST (0x00) /* SCSI IO */
  163. #define MPI2_FUNCTION_SCSI_TASK_MGMT (0x01)
  164. #define MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY (0x03)
  165. #define MPI2_REQ_DESCRIPT_FLAGS_FP_IO (0x06)
  166. #define MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO (0x00)
  167. #define MPI2_SGE_FLAGS_64_BIT_ADDRESSING (0x02)
  168. #define MPI2_SCSIIO_CONTROL_WRITE (0x01000000)
  169. #define MPI2_SCSIIO_CONTROL_READ (0x02000000)
  170. #define MPI2_REQ_DESCRIPT_FLAGS_TYPE_MASK (0x0E)
  171. #define MPI2_RPY_DESCRIPT_FLAGS_UNUSED (0x0F)
  172. #define MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS (0x00)
  173. #define MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK (0x0F)
  174. #define MPI2_WRSEQ_FLUSH_KEY_VALUE (0x0)
  175. #define MPI2_WRITE_SEQUENCE_OFFSET (0x00000004)
  176. #define MPI2_WRSEQ_1ST_KEY_VALUE (0xF)
  177. #define MPI2_WRSEQ_2ND_KEY_VALUE (0x4)
  178. #define MPI2_WRSEQ_3RD_KEY_VALUE (0xB)
  179. #define MPI2_WRSEQ_4TH_KEY_VALUE (0x2)
  180. #define MPI2_WRSEQ_5TH_KEY_VALUE (0x7)
  181. #define MPI2_WRSEQ_6TH_KEY_VALUE (0xD)
  182. struct MPI25_IEEE_SGE_CHAIN64 {
  183. __le64 Address;
  184. __le32 Length;
  185. __le16 Reserved1;
  186. u8 NextChainOffset;
  187. u8 Flags;
  188. };
  189. struct MPI2_SGE_SIMPLE_UNION {
  190. __le32 FlagsLength;
  191. union {
  192. __le32 Address32;
  193. __le64 Address64;
  194. } u;
  195. };
  196. struct MPI2_SCSI_IO_CDB_EEDP32 {
  197. u8 CDB[20]; /* 0x00 */
  198. __be32 PrimaryReferenceTag; /* 0x14 */
  199. __be16 PrimaryApplicationTag; /* 0x18 */
  200. __be16 PrimaryApplicationTagMask; /* 0x1A */
  201. __le32 TransferLength; /* 0x1C */
  202. };
  203. struct MPI2_SGE_CHAIN_UNION {
  204. __le16 Length;
  205. u8 NextChainOffset;
  206. u8 Flags;
  207. union {
  208. __le32 Address32;
  209. __le64 Address64;
  210. } u;
  211. };
  212. struct MPI2_IEEE_SGE_SIMPLE32 {
  213. __le32 Address;
  214. __le32 FlagsLength;
  215. };
  216. struct MPI2_IEEE_SGE_CHAIN32 {
  217. __le32 Address;
  218. __le32 FlagsLength;
  219. };
  220. struct MPI2_IEEE_SGE_SIMPLE64 {
  221. __le64 Address;
  222. __le32 Length;
  223. __le16 Reserved1;
  224. u8 Reserved2;
  225. u8 Flags;
  226. };
  227. struct MPI2_IEEE_SGE_CHAIN64 {
  228. __le64 Address;
  229. __le32 Length;
  230. __le16 Reserved1;
  231. u8 Reserved2;
  232. u8 Flags;
  233. };
  234. union MPI2_IEEE_SGE_SIMPLE_UNION {
  235. struct MPI2_IEEE_SGE_SIMPLE32 Simple32;
  236. struct MPI2_IEEE_SGE_SIMPLE64 Simple64;
  237. };
  238. union MPI2_IEEE_SGE_CHAIN_UNION {
  239. struct MPI2_IEEE_SGE_CHAIN32 Chain32;
  240. struct MPI2_IEEE_SGE_CHAIN64 Chain64;
  241. };
  242. union MPI2_SGE_IO_UNION {
  243. struct MPI2_SGE_SIMPLE_UNION MpiSimple;
  244. struct MPI2_SGE_CHAIN_UNION MpiChain;
  245. union MPI2_IEEE_SGE_SIMPLE_UNION IeeeSimple;
  246. union MPI2_IEEE_SGE_CHAIN_UNION IeeeChain;
  247. };
  248. union MPI2_SCSI_IO_CDB_UNION {
  249. u8 CDB32[32];
  250. struct MPI2_SCSI_IO_CDB_EEDP32 EEDP32;
  251. struct MPI2_SGE_SIMPLE_UNION SGE;
  252. };
  253. /****************************************************************************
  254. * SCSI Task Management messages
  255. ****************************************************************************/
  256. /*SCSI Task Management Request Message */
  257. struct MPI2_SCSI_TASK_MANAGE_REQUEST {
  258. u16 DevHandle; /*0x00 */
  259. u8 ChainOffset; /*0x02 */
  260. u8 Function; /*0x03 */
  261. u8 Reserved1; /*0x04 */
  262. u8 TaskType; /*0x05 */
  263. u8 Reserved2; /*0x06 */
  264. u8 MsgFlags; /*0x07 */
  265. u8 VP_ID; /*0x08 */
  266. u8 VF_ID; /*0x09 */
  267. u16 Reserved3; /*0x0A */
  268. u8 LUN[8]; /*0x0C */
  269. u32 Reserved4[7]; /*0x14 */
  270. u16 TaskMID; /*0x30 */
  271. u16 Reserved5; /*0x32 */
  272. };
  273. /*SCSI Task Management Reply Message */
  274. struct MPI2_SCSI_TASK_MANAGE_REPLY {
  275. u16 DevHandle; /*0x00 */
  276. u8 MsgLength; /*0x02 */
  277. u8 Function; /*0x03 */
  278. u8 ResponseCode; /*0x04 */
  279. u8 TaskType; /*0x05 */
  280. u8 Reserved1; /*0x06 */
  281. u8 MsgFlags; /*0x07 */
  282. u8 VP_ID; /*0x08 */
  283. u8 VF_ID; /*0x09 */
  284. u16 Reserved2; /*0x0A */
  285. u16 Reserved3; /*0x0C */
  286. u16 IOCStatus; /*0x0E */
  287. u32 IOCLogInfo; /*0x10 */
  288. u32 TerminationCount; /*0x14 */
  289. u32 ResponseInfo; /*0x18 */
  290. };
  291. struct MR_TM_REQUEST {
  292. char request[128];
  293. };
  294. struct MR_TM_REPLY {
  295. char reply[128];
  296. };
  297. /* SCSI Task Management Request Message */
  298. struct MR_TASK_MANAGE_REQUEST {
  299. /*To be type casted to struct MPI2_SCSI_TASK_MANAGE_REQUEST */
  300. struct MR_TM_REQUEST TmRequest;
  301. union {
  302. struct {
  303. #if defined(__BIG_ENDIAN_BITFIELD)
  304. u32 reserved1:30;
  305. u32 isTMForPD:1;
  306. u32 isTMForLD:1;
  307. #else
  308. u32 isTMForLD:1;
  309. u32 isTMForPD:1;
  310. u32 reserved1:30;
  311. #endif
  312. u32 reserved2;
  313. } tmReqFlags;
  314. struct MR_TM_REPLY TMReply;
  315. };
  316. };
  317. /* TaskType values */
  318. #define MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK (0x01)
  319. #define MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET (0x02)
  320. #define MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET (0x03)
  321. #define MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET (0x05)
  322. #define MPI2_SCSITASKMGMT_TASKTYPE_CLEAR_TASK_SET (0x06)
  323. #define MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK (0x07)
  324. #define MPI2_SCSITASKMGMT_TASKTYPE_CLR_ACA (0x08)
  325. #define MPI2_SCSITASKMGMT_TASKTYPE_QRY_TASK_SET (0x09)
  326. #define MPI2_SCSITASKMGMT_TASKTYPE_QRY_ASYNC_EVENT (0x0A)
  327. /* ResponseCode values */
  328. #define MPI2_SCSITASKMGMT_RSP_TM_COMPLETE (0x00)
  329. #define MPI2_SCSITASKMGMT_RSP_INVALID_FRAME (0x02)
  330. #define MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED (0x04)
  331. #define MPI2_SCSITASKMGMT_RSP_TM_FAILED (0x05)
  332. #define MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED (0x08)
  333. #define MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN (0x09)
  334. #define MPI2_SCSITASKMGMT_RSP_TM_OVERLAPPED_TAG (0x0A)
  335. #define MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC (0x80)
  336. /*
  337. * RAID SCSI IO Request Message
  338. * Total SGE count will be one less than _MPI2_SCSI_IO_REQUEST
  339. */
  340. struct MPI2_RAID_SCSI_IO_REQUEST {
  341. __le16 DevHandle; /* 0x00 */
  342. u8 ChainOffset; /* 0x02 */
  343. u8 Function; /* 0x03 */
  344. __le16 Reserved1; /* 0x04 */
  345. u8 Reserved2; /* 0x06 */
  346. u8 MsgFlags; /* 0x07 */
  347. u8 VP_ID; /* 0x08 */
  348. u8 VF_ID; /* 0x09 */
  349. __le16 Reserved3; /* 0x0A */
  350. __le32 SenseBufferLowAddress; /* 0x0C */
  351. __le16 SGLFlags; /* 0x10 */
  352. u8 SenseBufferLength; /* 0x12 */
  353. u8 Reserved4; /* 0x13 */
  354. u8 SGLOffset0; /* 0x14 */
  355. u8 SGLOffset1; /* 0x15 */
  356. u8 SGLOffset2; /* 0x16 */
  357. u8 SGLOffset3; /* 0x17 */
  358. __le32 SkipCount; /* 0x18 */
  359. __le32 DataLength; /* 0x1C */
  360. __le32 BidirectionalDataLength; /* 0x20 */
  361. __le16 IoFlags; /* 0x24 */
  362. __le16 EEDPFlags; /* 0x26 */
  363. __le32 EEDPBlockSize; /* 0x28 */
  364. __le32 SecondaryReferenceTag; /* 0x2C */
  365. __le16 SecondaryApplicationTag; /* 0x30 */
  366. __le16 ApplicationTagTranslationMask; /* 0x32 */
  367. u8 LUN[8]; /* 0x34 */
  368. __le32 Control; /* 0x3C */
  369. union MPI2_SCSI_IO_CDB_UNION CDB; /* 0x40 */
  370. struct RAID_CONTEXT RaidContext; /* 0x60 */
  371. union MPI2_SGE_IO_UNION SGL; /* 0x80 */
  372. };
  373. /*
  374. * MPT RAID MFA IO Descriptor.
  375. */
  376. struct MEGASAS_RAID_MFA_IO_REQUEST_DESCRIPTOR {
  377. u32 RequestFlags:8;
  378. u32 MessageAddress1:24;
  379. u32 MessageAddress2;
  380. };
  381. /* Default Request Descriptor */
  382. struct MPI2_DEFAULT_REQUEST_DESCRIPTOR {
  383. u8 RequestFlags; /* 0x00 */
  384. u8 MSIxIndex; /* 0x01 */
  385. __le16 SMID; /* 0x02 */
  386. __le16 LMID; /* 0x04 */
  387. __le16 DescriptorTypeDependent; /* 0x06 */
  388. };
  389. /* High Priority Request Descriptor */
  390. struct MPI2_HIGH_PRIORITY_REQUEST_DESCRIPTOR {
  391. u8 RequestFlags; /* 0x00 */
  392. u8 MSIxIndex; /* 0x01 */
  393. __le16 SMID; /* 0x02 */
  394. __le16 LMID; /* 0x04 */
  395. __le16 Reserved1; /* 0x06 */
  396. };
  397. /* SCSI IO Request Descriptor */
  398. struct MPI2_SCSI_IO_REQUEST_DESCRIPTOR {
  399. u8 RequestFlags; /* 0x00 */
  400. u8 MSIxIndex; /* 0x01 */
  401. __le16 SMID; /* 0x02 */
  402. __le16 LMID; /* 0x04 */
  403. __le16 DevHandle; /* 0x06 */
  404. };
  405. /* SCSI Target Request Descriptor */
  406. struct MPI2_SCSI_TARGET_REQUEST_DESCRIPTOR {
  407. u8 RequestFlags; /* 0x00 */
  408. u8 MSIxIndex; /* 0x01 */
  409. __le16 SMID; /* 0x02 */
  410. __le16 LMID; /* 0x04 */
  411. __le16 IoIndex; /* 0x06 */
  412. };
  413. /* RAID Accelerator Request Descriptor */
  414. struct MPI2_RAID_ACCEL_REQUEST_DESCRIPTOR {
  415. u8 RequestFlags; /* 0x00 */
  416. u8 MSIxIndex; /* 0x01 */
  417. __le16 SMID; /* 0x02 */
  418. __le16 LMID; /* 0x04 */
  419. __le16 Reserved; /* 0x06 */
  420. };
  421. /* union of Request Descriptors */
  422. union MEGASAS_REQUEST_DESCRIPTOR_UNION {
  423. struct MPI2_DEFAULT_REQUEST_DESCRIPTOR Default;
  424. struct MPI2_HIGH_PRIORITY_REQUEST_DESCRIPTOR HighPriority;
  425. struct MPI2_SCSI_IO_REQUEST_DESCRIPTOR SCSIIO;
  426. struct MPI2_SCSI_TARGET_REQUEST_DESCRIPTOR SCSITarget;
  427. struct MPI2_RAID_ACCEL_REQUEST_DESCRIPTOR RAIDAccelerator;
  428. struct MEGASAS_RAID_MFA_IO_REQUEST_DESCRIPTOR MFAIo;
  429. union {
  430. struct {
  431. __le32 low;
  432. __le32 high;
  433. } u;
  434. __le64 Words;
  435. };
  436. };
  437. /* Default Reply Descriptor */
  438. struct MPI2_DEFAULT_REPLY_DESCRIPTOR {
  439. u8 ReplyFlags; /* 0x00 */
  440. u8 MSIxIndex; /* 0x01 */
  441. __le16 DescriptorTypeDependent1; /* 0x02 */
  442. __le32 DescriptorTypeDependent2; /* 0x04 */
  443. };
  444. /* Address Reply Descriptor */
  445. struct MPI2_ADDRESS_REPLY_DESCRIPTOR {
  446. u8 ReplyFlags; /* 0x00 */
  447. u8 MSIxIndex; /* 0x01 */
  448. __le16 SMID; /* 0x02 */
  449. __le32 ReplyFrameAddress; /* 0x04 */
  450. };
  451. /* SCSI IO Success Reply Descriptor */
  452. struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR {
  453. u8 ReplyFlags; /* 0x00 */
  454. u8 MSIxIndex; /* 0x01 */
  455. __le16 SMID; /* 0x02 */
  456. __le16 TaskTag; /* 0x04 */
  457. __le16 Reserved1; /* 0x06 */
  458. };
  459. /* TargetAssist Success Reply Descriptor */
  460. struct MPI2_TARGETASSIST_SUCCESS_REPLY_DESCRIPTOR {
  461. u8 ReplyFlags; /* 0x00 */
  462. u8 MSIxIndex; /* 0x01 */
  463. __le16 SMID; /* 0x02 */
  464. u8 SequenceNumber; /* 0x04 */
  465. u8 Reserved1; /* 0x05 */
  466. __le16 IoIndex; /* 0x06 */
  467. };
  468. /* Target Command Buffer Reply Descriptor */
  469. struct MPI2_TARGET_COMMAND_BUFFER_REPLY_DESCRIPTOR {
  470. u8 ReplyFlags; /* 0x00 */
  471. u8 MSIxIndex; /* 0x01 */
  472. u8 VP_ID; /* 0x02 */
  473. u8 Flags; /* 0x03 */
  474. __le16 InitiatorDevHandle; /* 0x04 */
  475. __le16 IoIndex; /* 0x06 */
  476. };
  477. /* RAID Accelerator Success Reply Descriptor */
  478. struct MPI2_RAID_ACCELERATOR_SUCCESS_REPLY_DESCRIPTOR {
  479. u8 ReplyFlags; /* 0x00 */
  480. u8 MSIxIndex; /* 0x01 */
  481. __le16 SMID; /* 0x02 */
  482. __le32 Reserved; /* 0x04 */
  483. };
  484. /* union of Reply Descriptors */
  485. union MPI2_REPLY_DESCRIPTORS_UNION {
  486. struct MPI2_DEFAULT_REPLY_DESCRIPTOR Default;
  487. struct MPI2_ADDRESS_REPLY_DESCRIPTOR AddressReply;
  488. struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR SCSIIOSuccess;
  489. struct MPI2_TARGETASSIST_SUCCESS_REPLY_DESCRIPTOR TargetAssistSuccess;
  490. struct MPI2_TARGET_COMMAND_BUFFER_REPLY_DESCRIPTOR TargetCommandBuffer;
  491. struct MPI2_RAID_ACCELERATOR_SUCCESS_REPLY_DESCRIPTOR
  492. RAIDAcceleratorSuccess;
  493. __le64 Words;
  494. };
  495. /* IOCInit Request message */
  496. struct MPI2_IOC_INIT_REQUEST {
  497. u8 WhoInit; /* 0x00 */
  498. u8 Reserved1; /* 0x01 */
  499. u8 ChainOffset; /* 0x02 */
  500. u8 Function; /* 0x03 */
  501. __le16 Reserved2; /* 0x04 */
  502. u8 Reserved3; /* 0x06 */
  503. u8 MsgFlags; /* 0x07 */
  504. u8 VP_ID; /* 0x08 */
  505. u8 VF_ID; /* 0x09 */
  506. __le16 Reserved4; /* 0x0A */
  507. __le16 MsgVersion; /* 0x0C */
  508. __le16 HeaderVersion; /* 0x0E */
  509. u32 Reserved5; /* 0x10 */
  510. __le16 Reserved6; /* 0x14 */
  511. u8 Reserved7; /* 0x16 */
  512. u8 HostMSIxVectors; /* 0x17 */
  513. __le16 Reserved8; /* 0x18 */
  514. __le16 SystemRequestFrameSize; /* 0x1A */
  515. __le16 ReplyDescriptorPostQueueDepth; /* 0x1C */
  516. __le16 ReplyFreeQueueDepth; /* 0x1E */
  517. __le32 SenseBufferAddressHigh; /* 0x20 */
  518. __le32 SystemReplyAddressHigh; /* 0x24 */
  519. __le64 SystemRequestFrameBaseAddress; /* 0x28 */
  520. __le64 ReplyDescriptorPostQueueAddress;/* 0x30 */
  521. __le64 ReplyFreeQueueAddress; /* 0x38 */
  522. __le64 TimeStamp; /* 0x40 */
  523. };
  524. /* mrpriv defines */
  525. #define MR_PD_INVALID 0xFFFF
  526. #define MAX_SPAN_DEPTH 8
  527. #define MAX_QUAD_DEPTH MAX_SPAN_DEPTH
  528. #define MAX_RAIDMAP_SPAN_DEPTH (MAX_SPAN_DEPTH)
  529. #define MAX_ROW_SIZE 32
  530. #define MAX_RAIDMAP_ROW_SIZE (MAX_ROW_SIZE)
  531. #define MAX_LOGICAL_DRIVES 64
  532. #define MAX_LOGICAL_DRIVES_EXT 256
  533. #define MAX_RAIDMAP_LOGICAL_DRIVES (MAX_LOGICAL_DRIVES)
  534. #define MAX_RAIDMAP_VIEWS (MAX_LOGICAL_DRIVES)
  535. #define MAX_ARRAYS 128
  536. #define MAX_RAIDMAP_ARRAYS (MAX_ARRAYS)
  537. #define MAX_ARRAYS_EXT 256
  538. #define MAX_API_ARRAYS_EXT (MAX_ARRAYS_EXT)
  539. #define MAX_PHYSICAL_DEVICES 256
  540. #define MAX_RAIDMAP_PHYSICAL_DEVICES (MAX_PHYSICAL_DEVICES)
  541. #define MR_DCMD_LD_MAP_GET_INFO 0x0300e101
  542. #define MR_DCMD_SYSTEM_PD_MAP_GET_INFO 0x0200e102
  543. #define MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC 0x010e8485 /* SR-IOV HB alloc*/
  544. #define MR_DCMD_LD_VF_MAP_GET_ALL_LDS_111 0x03200200
  545. #define MR_DCMD_LD_VF_MAP_GET_ALL_LDS 0x03150200
  546. struct MR_DEV_HANDLE_INFO {
  547. __le16 curDevHdl;
  548. u8 validHandles;
  549. u8 reserved;
  550. __le16 devHandle[2];
  551. };
  552. struct MR_ARRAY_INFO {
  553. __le16 pd[MAX_RAIDMAP_ROW_SIZE];
  554. };
  555. struct MR_QUAD_ELEMENT {
  556. __le64 logStart;
  557. __le64 logEnd;
  558. __le64 offsetInSpan;
  559. __le32 diff;
  560. __le32 reserved1;
  561. };
  562. struct MR_SPAN_INFO {
  563. __le32 noElements;
  564. __le32 reserved1;
  565. struct MR_QUAD_ELEMENT quad[MAX_RAIDMAP_SPAN_DEPTH];
  566. };
  567. struct MR_LD_SPAN {
  568. __le64 startBlk;
  569. __le64 numBlks;
  570. __le16 arrayRef;
  571. u8 spanRowSize;
  572. u8 spanRowDataSize;
  573. u8 reserved[4];
  574. };
  575. struct MR_SPAN_BLOCK_INFO {
  576. __le64 num_rows;
  577. struct MR_LD_SPAN span;
  578. struct MR_SPAN_INFO block_span_info;
  579. };
  580. struct MR_LD_RAID {
  581. struct {
  582. #if defined(__BIG_ENDIAN_BITFIELD)
  583. u32 reserved4:5;
  584. u32 fpBypassRegionLock:1;
  585. u32 tmCapable:1;
  586. u32 fpNonRWCapable:1;
  587. u32 fpReadAcrossStripe:1;
  588. u32 fpWriteAcrossStripe:1;
  589. u32 fpReadCapable:1;
  590. u32 fpWriteCapable:1;
  591. u32 encryptionType:8;
  592. u32 pdPiMode:4;
  593. u32 ldPiMode:4;
  594. u32 reserved5:3;
  595. u32 fpCapable:1;
  596. #else
  597. u32 fpCapable:1;
  598. u32 reserved5:3;
  599. u32 ldPiMode:4;
  600. u32 pdPiMode:4;
  601. u32 encryptionType:8;
  602. u32 fpWriteCapable:1;
  603. u32 fpReadCapable:1;
  604. u32 fpWriteAcrossStripe:1;
  605. u32 fpReadAcrossStripe:1;
  606. u32 fpNonRWCapable:1;
  607. u32 tmCapable:1;
  608. u32 fpBypassRegionLock:1;
  609. u32 reserved4:5;
  610. #endif
  611. } capability;
  612. __le32 reserved6;
  613. __le64 size;
  614. u8 spanDepth;
  615. u8 level;
  616. u8 stripeShift;
  617. u8 rowSize;
  618. u8 rowDataSize;
  619. u8 writeMode;
  620. u8 PRL;
  621. u8 SRL;
  622. __le16 targetId;
  623. u8 ldState;
  624. u8 regTypeReqOnWrite;
  625. u8 modFactor;
  626. u8 regTypeReqOnRead;
  627. __le16 seqNum;
  628. struct {
  629. u32 ldSyncRequired:1;
  630. u32 reserved:31;
  631. } flags;
  632. u8 LUN[8]; /* 0x24 8 byte LUN field used for SCSI IO's */
  633. u8 fpIoTimeoutForLd;/*0x2C timeout value used by driver in FP IO*/
  634. u8 reserved3[0x80-0x2D]; /* 0x2D */
  635. };
  636. struct MR_LD_SPAN_MAP {
  637. struct MR_LD_RAID ldRaid;
  638. u8 dataArmMap[MAX_RAIDMAP_ROW_SIZE];
  639. struct MR_SPAN_BLOCK_INFO spanBlock[MAX_RAIDMAP_SPAN_DEPTH];
  640. };
  641. struct MR_FW_RAID_MAP {
  642. __le32 totalSize;
  643. union {
  644. struct {
  645. __le32 maxLd;
  646. __le32 maxSpanDepth;
  647. __le32 maxRowSize;
  648. __le32 maxPdCount;
  649. __le32 maxArrays;
  650. } validationInfo;
  651. __le32 version[5];
  652. };
  653. __le32 ldCount;
  654. __le32 Reserved1;
  655. u8 ldTgtIdToLd[MAX_RAIDMAP_LOGICAL_DRIVES+
  656. MAX_RAIDMAP_VIEWS];
  657. u8 fpPdIoTimeoutSec;
  658. u8 reserved2[7];
  659. struct MR_ARRAY_INFO arMapInfo[MAX_RAIDMAP_ARRAYS];
  660. struct MR_DEV_HANDLE_INFO devHndlInfo[MAX_RAIDMAP_PHYSICAL_DEVICES];
  661. struct MR_LD_SPAN_MAP ldSpanMap[1];
  662. };
  663. struct IO_REQUEST_INFO {
  664. u64 ldStartBlock;
  665. u32 numBlocks;
  666. u16 ldTgtId;
  667. u8 isRead;
  668. __le16 devHandle;
  669. u64 pdBlock;
  670. u8 fpOkForIo;
  671. u8 IoforUnevenSpan;
  672. u8 start_span;
  673. u8 do_fp_rlbypass;
  674. u64 start_row;
  675. u8 span_arm; /* span[7:5], arm[4:0] */
  676. u8 pd_after_lb;
  677. };
  678. struct MR_LD_TARGET_SYNC {
  679. u8 targetId;
  680. u8 reserved;
  681. __le16 seqNum;
  682. };
  683. #define IEEE_SGE_FLAGS_ADDR_MASK (0x03)
  684. #define IEEE_SGE_FLAGS_SYSTEM_ADDR (0x00)
  685. #define IEEE_SGE_FLAGS_IOCDDR_ADDR (0x01)
  686. #define IEEE_SGE_FLAGS_IOCPLB_ADDR (0x02)
  687. #define IEEE_SGE_FLAGS_IOCPLBNTA_ADDR (0x03)
  688. #define IEEE_SGE_FLAGS_CHAIN_ELEMENT (0x80)
  689. #define IEEE_SGE_FLAGS_END_OF_LIST (0x40)
  690. struct megasas_register_set;
  691. struct megasas_instance;
  692. union desc_word {
  693. u64 word;
  694. struct {
  695. u32 low;
  696. u32 high;
  697. } u;
  698. };
  699. struct megasas_cmd_fusion {
  700. struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
  701. dma_addr_t io_request_phys_addr;
  702. union MPI2_SGE_IO_UNION *sg_frame;
  703. dma_addr_t sg_frame_phys_addr;
  704. u8 *sense;
  705. dma_addr_t sense_phys_addr;
  706. struct list_head list;
  707. struct scsi_cmnd *scmd;
  708. struct megasas_instance *instance;
  709. u8 retry_for_fw_reset;
  710. union MEGASAS_REQUEST_DESCRIPTOR_UNION *request_desc;
  711. /*
  712. * Context for a MFI frame.
  713. * Used to get the mfi cmd from list when a MFI cmd is completed
  714. */
  715. u32 sync_cmd_idx;
  716. u32 index;
  717. u8 pd_r1_lb;
  718. struct completion done;
  719. };
  720. struct LD_LOAD_BALANCE_INFO {
  721. u8 loadBalanceFlag;
  722. u8 reserved1;
  723. atomic_t scsi_pending_cmds[MAX_PHYSICAL_DEVICES];
  724. u64 last_accessed_block[MAX_PHYSICAL_DEVICES];
  725. };
  726. /* SPAN_SET is info caclulated from span info from Raid map per LD */
  727. typedef struct _LD_SPAN_SET {
  728. u64 log_start_lba;
  729. u64 log_end_lba;
  730. u64 span_row_start;
  731. u64 span_row_end;
  732. u64 data_strip_start;
  733. u64 data_strip_end;
  734. u64 data_row_start;
  735. u64 data_row_end;
  736. u8 strip_offset[MAX_SPAN_DEPTH];
  737. u32 span_row_data_width;
  738. u32 diff;
  739. u32 reserved[2];
  740. } LD_SPAN_SET, *PLD_SPAN_SET;
  741. typedef struct LOG_BLOCK_SPAN_INFO {
  742. LD_SPAN_SET span_set[MAX_SPAN_DEPTH];
  743. } LD_SPAN_INFO, *PLD_SPAN_INFO;
  744. struct MR_FW_RAID_MAP_ALL {
  745. struct MR_FW_RAID_MAP raidMap;
  746. struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES - 1];
  747. } __attribute__ ((packed));
  748. struct MR_DRV_RAID_MAP {
  749. /* total size of this structure, including this field.
  750. * This feild will be manupulated by driver for ext raid map,
  751. * else pick the value from firmware raid map.
  752. */
  753. __le32 totalSize;
  754. union {
  755. struct {
  756. __le32 maxLd;
  757. __le32 maxSpanDepth;
  758. __le32 maxRowSize;
  759. __le32 maxPdCount;
  760. __le32 maxArrays;
  761. } validationInfo;
  762. __le32 version[5];
  763. };
  764. /* timeout value used by driver in FP IOs*/
  765. u8 fpPdIoTimeoutSec;
  766. u8 reserved2[7];
  767. __le16 ldCount;
  768. __le16 arCount;
  769. __le16 spanCount;
  770. __le16 reserve3;
  771. struct MR_DEV_HANDLE_INFO devHndlInfo[MAX_RAIDMAP_PHYSICAL_DEVICES];
  772. u8 ldTgtIdToLd[MAX_LOGICAL_DRIVES_EXT];
  773. struct MR_ARRAY_INFO arMapInfo[MAX_API_ARRAYS_EXT];
  774. struct MR_LD_SPAN_MAP ldSpanMap[1];
  775. };
  776. /* Driver raid map size is same as raid map ext
  777. * MR_DRV_RAID_MAP_ALL is created to sync with old raid.
  778. * And it is mainly for code re-use purpose.
  779. */
  780. struct MR_DRV_RAID_MAP_ALL {
  781. struct MR_DRV_RAID_MAP raidMap;
  782. struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES_EXT - 1];
  783. } __packed;
  784. struct MR_FW_RAID_MAP_EXT {
  785. /* Not usred in new map */
  786. u32 reserved;
  787. union {
  788. struct {
  789. u32 maxLd;
  790. u32 maxSpanDepth;
  791. u32 maxRowSize;
  792. u32 maxPdCount;
  793. u32 maxArrays;
  794. } validationInfo;
  795. u32 version[5];
  796. };
  797. u8 fpPdIoTimeoutSec;
  798. u8 reserved2[7];
  799. __le16 ldCount;
  800. __le16 arCount;
  801. __le16 spanCount;
  802. __le16 reserve3;
  803. struct MR_DEV_HANDLE_INFO devHndlInfo[MAX_RAIDMAP_PHYSICAL_DEVICES];
  804. u8 ldTgtIdToLd[MAX_LOGICAL_DRIVES_EXT];
  805. struct MR_ARRAY_INFO arMapInfo[MAX_API_ARRAYS_EXT];
  806. struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES_EXT];
  807. };
  808. /*
  809. * * define MR_PD_CFG_SEQ structure for system PDs
  810. * */
  811. struct MR_PD_CFG_SEQ {
  812. u16 seqNum;
  813. u16 devHandle;
  814. struct {
  815. #if defined(__BIG_ENDIAN_BITFIELD)
  816. u8 reserved:7;
  817. u8 tmCapable:1;
  818. #else
  819. u8 tmCapable:1;
  820. u8 reserved:7;
  821. #endif
  822. } capability;
  823. u8 reserved[3];
  824. } __packed;
  825. struct MR_PD_CFG_SEQ_NUM_SYNC {
  826. __le32 size;
  827. __le32 count;
  828. struct MR_PD_CFG_SEQ seq[1];
  829. } __packed;
  830. struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY {
  831. u64 RDPQBaseAddress;
  832. u32 Reserved1;
  833. u32 Reserved2;
  834. };
  835. struct fusion_context {
  836. struct megasas_cmd_fusion **cmd_list;
  837. dma_addr_t req_frames_desc_phys;
  838. u8 *req_frames_desc;
  839. struct dma_pool *io_request_frames_pool;
  840. dma_addr_t io_request_frames_phys;
  841. u8 *io_request_frames;
  842. struct dma_pool *sg_dma_pool;
  843. struct dma_pool *sense_dma_pool;
  844. dma_addr_t reply_frames_desc_phys[MAX_MSIX_QUEUES_FUSION];
  845. union MPI2_REPLY_DESCRIPTORS_UNION *reply_frames_desc[MAX_MSIX_QUEUES_FUSION];
  846. struct dma_pool *reply_frames_desc_pool;
  847. u16 last_reply_idx[MAX_MSIX_QUEUES_FUSION];
  848. u32 reply_q_depth;
  849. u32 request_alloc_sz;
  850. u32 reply_alloc_sz;
  851. u32 io_frames_alloc_sz;
  852. struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY *rdpq_virt;
  853. dma_addr_t rdpq_phys;
  854. u16 max_sge_in_main_msg;
  855. u16 max_sge_in_chain;
  856. u8 chain_offset_io_request;
  857. u8 chain_offset_mfi_pthru;
  858. struct MR_FW_RAID_MAP_ALL *ld_map[2];
  859. dma_addr_t ld_map_phys[2];
  860. /*Non dma-able memory. Driver local copy.*/
  861. struct MR_DRV_RAID_MAP_ALL *ld_drv_map[2];
  862. u32 max_map_sz;
  863. u32 current_map_sz;
  864. u32 drv_map_sz;
  865. u32 drv_map_pages;
  866. struct MR_PD_CFG_SEQ_NUM_SYNC *pd_seq_sync[JBOD_MAPS_COUNT];
  867. dma_addr_t pd_seq_phys[JBOD_MAPS_COUNT];
  868. u8 fast_path_io;
  869. struct LD_LOAD_BALANCE_INFO load_balance_info[MAX_LOGICAL_DRIVES_EXT];
  870. LD_SPAN_INFO log_to_span[MAX_LOGICAL_DRIVES_EXT];
  871. u8 adapter_type;
  872. };
  873. union desc_value {
  874. __le64 word;
  875. struct {
  876. __le32 low;
  877. __le32 high;
  878. } u;
  879. };
  880. void megasas_free_cmds_fusion(struct megasas_instance *instance);
  881. int megasas_ioc_init_fusion(struct megasas_instance *instance);
  882. u8 megasas_get_map_info(struct megasas_instance *instance);
  883. int megasas_sync_map_info(struct megasas_instance *instance);
  884. void megasas_release_fusion(struct megasas_instance *instance);
  885. void megasas_reset_reply_desc(struct megasas_instance *instance);
  886. int megasas_check_mpio_paths(struct megasas_instance *instance,
  887. struct scsi_cmnd *scmd);
  888. void megasas_fusion_ocr_wq(struct work_struct *work);
  889. #endif /* _MEGARAID_SAS_FUSION_H_ */