megaraid_sas_fusion.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  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. #define RDPQ_MAX_INDEX_IN_ONE_CHUNK 16
  53. #define RDPQ_MAX_CHUNK_COUNT (MAX_MSIX_QUEUES_FUSION / RDPQ_MAX_INDEX_IN_ONE_CHUNK)
  54. /* Invader defines */
  55. #define MPI2_TYPE_CUDA 0x2
  56. #define MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH 0x4000
  57. #define MR_RL_FLAGS_GRANT_DESTINATION_CPU0 0x00
  58. #define MR_RL_FLAGS_GRANT_DESTINATION_CPU1 0x10
  59. #define MR_RL_FLAGS_GRANT_DESTINATION_CUDA 0x80
  60. #define MR_RL_FLAGS_SEQ_NUM_ENABLE 0x8
  61. #define MR_RL_WRITE_THROUGH_MODE 0x00
  62. #define MR_RL_WRITE_BACK_MODE 0x01
  63. /* T10 PI defines */
  64. #define MR_PROT_INFO_TYPE_CONTROLLER 0x8
  65. #define MEGASAS_SCSI_VARIABLE_LENGTH_CMD 0x7f
  66. #define MEGASAS_SCSI_SERVICE_ACTION_READ32 0x9
  67. #define MEGASAS_SCSI_SERVICE_ACTION_WRITE32 0xB
  68. #define MEGASAS_SCSI_ADDL_CDB_LEN 0x18
  69. #define MEGASAS_RD_WR_PROTECT_CHECK_ALL 0x20
  70. #define MEGASAS_RD_WR_PROTECT_CHECK_NONE 0x60
  71. #define MPI2_SUP_REPLY_POST_HOST_INDEX_OFFSET (0x0000030C)
  72. #define MPI2_REPLY_POST_HOST_INDEX_OFFSET (0x0000006C)
  73. /*
  74. * Raid context flags
  75. */
  76. #define MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT 0x4
  77. #define MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_MASK 0x30
  78. enum MR_RAID_FLAGS_IO_SUB_TYPE {
  79. MR_RAID_FLAGS_IO_SUB_TYPE_NONE = 0,
  80. MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD = 1,
  81. MR_RAID_FLAGS_IO_SUB_TYPE_RMW_DATA = 2,
  82. MR_RAID_FLAGS_IO_SUB_TYPE_RMW_P = 3,
  83. MR_RAID_FLAGS_IO_SUB_TYPE_RMW_Q = 4,
  84. MR_RAID_FLAGS_IO_SUB_TYPE_CACHE_BYPASS = 6,
  85. MR_RAID_FLAGS_IO_SUB_TYPE_LDIO_BW_LIMIT = 7
  86. };
  87. /*
  88. * Request descriptor types
  89. */
  90. #define MEGASAS_REQ_DESCRIPT_FLAGS_LD_IO 0x7
  91. #define MEGASAS_REQ_DESCRIPT_FLAGS_MFA 0x1
  92. #define MEGASAS_REQ_DESCRIPT_FLAGS_NO_LOCK 0x2
  93. #define MEGASAS_REQ_DESCRIPT_FLAGS_TYPE_SHIFT 1
  94. #define MEGASAS_FP_CMD_LEN 16
  95. #define MEGASAS_FUSION_IN_RESET 0
  96. #define MEGASAS_FUSION_OCR_NOT_POSSIBLE 1
  97. #define THRESHOLD_REPLY_COUNT 50
  98. #define RAID_1_PEER_CMDS 2
  99. #define JBOD_MAPS_COUNT 2
  100. #define MEGASAS_REDUCE_QD_COUNT 64
  101. #define IOC_INIT_FRAME_SIZE 4096
  102. /*
  103. * Raid Context structure which describes MegaRAID specific IO Parameters
  104. * This resides at offset 0x60 where the SGL normally starts in MPT IO Frames
  105. */
  106. struct RAID_CONTEXT {
  107. #if defined(__BIG_ENDIAN_BITFIELD)
  108. u8 nseg:4;
  109. u8 type:4;
  110. #else
  111. u8 type:4;
  112. u8 nseg:4;
  113. #endif
  114. u8 resvd0;
  115. __le16 timeout_value;
  116. u8 reg_lock_flags;
  117. u8 resvd1;
  118. __le16 virtual_disk_tgt_id;
  119. __le64 reg_lock_row_lba;
  120. __le32 reg_lock_length;
  121. __le16 next_lmid;
  122. u8 ex_status;
  123. u8 status;
  124. u8 raid_flags;
  125. u8 num_sge;
  126. __le16 config_seq_num;
  127. u8 span_arm;
  128. u8 priority;
  129. u8 num_sge_ext;
  130. u8 resvd2;
  131. };
  132. /*
  133. * Raid Context structure which describes ventura MegaRAID specific
  134. * IO Paramenters ,This resides at offset 0x60 where the SGL normally
  135. * starts in MPT IO Frames
  136. */
  137. struct RAID_CONTEXT_G35 {
  138. #define RAID_CONTEXT_NSEG_MASK 0x00F0
  139. #define RAID_CONTEXT_NSEG_SHIFT 4
  140. #define RAID_CONTEXT_TYPE_MASK 0x000F
  141. #define RAID_CONTEXT_TYPE_SHIFT 0
  142. u16 nseg_type;
  143. u16 timeout_value; /* 0x02 -0x03 */
  144. u16 routing_flags; // 0x04 -0x05 routing flags
  145. u16 virtual_disk_tgt_id; /* 0x06 -0x07 */
  146. u64 reg_lock_row_lba; /* 0x08 - 0x0F */
  147. u32 reg_lock_length; /* 0x10 - 0x13 */
  148. union {
  149. u16 next_lmid; /* 0x14 - 0x15 */
  150. u16 peer_smid; /* used for the raid 1/10 fp writes */
  151. } smid;
  152. u8 ex_status; /* 0x16 : OUT */
  153. u8 status; /* 0x17 status */
  154. u8 raid_flags; /* 0x18 resvd[7:6], ioSubType[5:4],
  155. * resvd[3:1], preferredCpu[0]
  156. */
  157. u8 span_arm; /* 0x1C span[7:5], arm[4:0] */
  158. u16 config_seq_num; /* 0x1A -0x1B */
  159. union {
  160. /*
  161. * Bit format:
  162. * ---------------------------------
  163. * | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
  164. * ---------------------------------
  165. * Byte0 | numSGE[7]- numSGE[0] |
  166. * ---------------------------------
  167. * Byte1 |SD | resvd | numSGE 8-11 |
  168. * --------------------------------
  169. */
  170. #define NUM_SGE_MASK_LOWER 0xFF
  171. #define NUM_SGE_MASK_UPPER 0x0F
  172. #define NUM_SGE_SHIFT_UPPER 8
  173. #define STREAM_DETECT_SHIFT 7
  174. #define STREAM_DETECT_MASK 0x80
  175. struct {
  176. #if defined(__BIG_ENDIAN_BITFIELD) /* 0x1C - 0x1D */
  177. u16 stream_detected:1;
  178. u16 reserved:3;
  179. u16 num_sge:12;
  180. #else
  181. u16 num_sge:12;
  182. u16 reserved:3;
  183. u16 stream_detected:1;
  184. #endif
  185. } bits;
  186. u8 bytes[2];
  187. } u;
  188. u8 resvd2[2]; /* 0x1E-0x1F */
  189. };
  190. #define MR_RAID_CTX_ROUTINGFLAGS_SLD_SHIFT 1
  191. #define MR_RAID_CTX_ROUTINGFLAGS_C2D_SHIFT 2
  192. #define MR_RAID_CTX_ROUTINGFLAGS_FWD_SHIFT 3
  193. #define MR_RAID_CTX_ROUTINGFLAGS_SQN_SHIFT 4
  194. #define MR_RAID_CTX_ROUTINGFLAGS_SBS_SHIFT 5
  195. #define MR_RAID_CTX_ROUTINGFLAGS_RW_SHIFT 6
  196. #define MR_RAID_CTX_ROUTINGFLAGS_LOG_SHIFT 7
  197. #define MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_SHIFT 8
  198. #define MR_RAID_CTX_ROUTINGFLAGS_CPUSEL_MASK 0x0F00
  199. #define MR_RAID_CTX_ROUTINGFLAGS_SETDIVERT_SHIFT 12
  200. #define MR_RAID_CTX_ROUTINGFLAGS_SETDIVERT_MASK 0xF000
  201. static inline void set_num_sge(struct RAID_CONTEXT_G35 *rctx_g35,
  202. u16 sge_count)
  203. {
  204. rctx_g35->u.bytes[0] = (u8)(sge_count & NUM_SGE_MASK_LOWER);
  205. rctx_g35->u.bytes[1] |= (u8)((sge_count >> NUM_SGE_SHIFT_UPPER)
  206. & NUM_SGE_MASK_UPPER);
  207. }
  208. static inline u16 get_num_sge(struct RAID_CONTEXT_G35 *rctx_g35)
  209. {
  210. u16 sge_count;
  211. sge_count = (u16)(((rctx_g35->u.bytes[1] & NUM_SGE_MASK_UPPER)
  212. << NUM_SGE_SHIFT_UPPER) | (rctx_g35->u.bytes[0]));
  213. return sge_count;
  214. }
  215. #define SET_STREAM_DETECTED(rctx_g35) \
  216. (rctx_g35.u.bytes[1] |= STREAM_DETECT_MASK)
  217. #define CLEAR_STREAM_DETECTED(rctx_g35) \
  218. (rctx_g35.u.bytes[1] &= ~(STREAM_DETECT_MASK))
  219. static inline bool is_stream_detected(struct RAID_CONTEXT_G35 *rctx_g35)
  220. {
  221. return ((rctx_g35->u.bytes[1] & STREAM_DETECT_MASK));
  222. }
  223. union RAID_CONTEXT_UNION {
  224. struct RAID_CONTEXT raid_context;
  225. struct RAID_CONTEXT_G35 raid_context_g35;
  226. };
  227. #define RAID_CTX_SPANARM_ARM_SHIFT (0)
  228. #define RAID_CTX_SPANARM_ARM_MASK (0x1f)
  229. #define RAID_CTX_SPANARM_SPAN_SHIFT (5)
  230. #define RAID_CTX_SPANARM_SPAN_MASK (0xE0)
  231. /* number of bits per index in U32 TrackStream */
  232. #define BITS_PER_INDEX_STREAM 4
  233. #define INVALID_STREAM_NUM 16
  234. #define MR_STREAM_BITMAP 0x76543210
  235. #define STREAM_MASK ((1 << BITS_PER_INDEX_STREAM) - 1)
  236. #define ZERO_LAST_STREAM 0x0fffffff
  237. #define MAX_STREAMS_TRACKED 8
  238. /*
  239. * define region lock types
  240. */
  241. enum REGION_TYPE {
  242. REGION_TYPE_UNUSED = 0,
  243. REGION_TYPE_SHARED_READ = 1,
  244. REGION_TYPE_SHARED_WRITE = 2,
  245. REGION_TYPE_EXCLUSIVE = 3,
  246. };
  247. /* MPI2 defines */
  248. #define MPI2_FUNCTION_IOC_INIT (0x02) /* IOC Init */
  249. #define MPI2_WHOINIT_HOST_DRIVER (0x04)
  250. #define MPI2_VERSION_MAJOR (0x02)
  251. #define MPI2_VERSION_MINOR (0x00)
  252. #define MPI2_VERSION_MAJOR_MASK (0xFF00)
  253. #define MPI2_VERSION_MAJOR_SHIFT (8)
  254. #define MPI2_VERSION_MINOR_MASK (0x00FF)
  255. #define MPI2_VERSION_MINOR_SHIFT (0)
  256. #define MPI2_VERSION ((MPI2_VERSION_MAJOR << MPI2_VERSION_MAJOR_SHIFT) | \
  257. MPI2_VERSION_MINOR)
  258. #define MPI2_HEADER_VERSION_UNIT (0x10)
  259. #define MPI2_HEADER_VERSION_DEV (0x00)
  260. #define MPI2_HEADER_VERSION_UNIT_MASK (0xFF00)
  261. #define MPI2_HEADER_VERSION_UNIT_SHIFT (8)
  262. #define MPI2_HEADER_VERSION_DEV_MASK (0x00FF)
  263. #define MPI2_HEADER_VERSION_DEV_SHIFT (0)
  264. #define MPI2_HEADER_VERSION ((MPI2_HEADER_VERSION_UNIT << 8) | \
  265. MPI2_HEADER_VERSION_DEV)
  266. #define MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR (0x03)
  267. #define MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG (0x8000)
  268. #define MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG (0x0400)
  269. #define MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP (0x0003)
  270. #define MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG (0x0200)
  271. #define MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD (0x0100)
  272. #define MPI2_SCSIIO_EEDPFLAGS_INSERT_OP (0x0004)
  273. /* EEDP escape mode */
  274. #define MPI25_SCSIIO_EEDPFLAGS_DO_NOT_DISABLE_MODE (0x0040)
  275. #define MPI2_FUNCTION_SCSI_IO_REQUEST (0x00) /* SCSI IO */
  276. #define MPI2_FUNCTION_SCSI_TASK_MGMT (0x01)
  277. #define MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY (0x03)
  278. #define MPI2_REQ_DESCRIPT_FLAGS_FP_IO (0x06)
  279. #define MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO (0x00)
  280. #define MPI2_SGE_FLAGS_64_BIT_ADDRESSING (0x02)
  281. #define MPI2_SCSIIO_CONTROL_WRITE (0x01000000)
  282. #define MPI2_SCSIIO_CONTROL_READ (0x02000000)
  283. #define MPI2_REQ_DESCRIPT_FLAGS_TYPE_MASK (0x0E)
  284. #define MPI2_RPY_DESCRIPT_FLAGS_UNUSED (0x0F)
  285. #define MPI2_RPY_DESCRIPT_FLAGS_SCSI_IO_SUCCESS (0x00)
  286. #define MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK (0x0F)
  287. #define MPI2_WRSEQ_FLUSH_KEY_VALUE (0x0)
  288. #define MPI2_WRITE_SEQUENCE_OFFSET (0x00000004)
  289. #define MPI2_WRSEQ_1ST_KEY_VALUE (0xF)
  290. #define MPI2_WRSEQ_2ND_KEY_VALUE (0x4)
  291. #define MPI2_WRSEQ_3RD_KEY_VALUE (0xB)
  292. #define MPI2_WRSEQ_4TH_KEY_VALUE (0x2)
  293. #define MPI2_WRSEQ_5TH_KEY_VALUE (0x7)
  294. #define MPI2_WRSEQ_6TH_KEY_VALUE (0xD)
  295. struct MPI25_IEEE_SGE_CHAIN64 {
  296. __le64 Address;
  297. __le32 Length;
  298. __le16 Reserved1;
  299. u8 NextChainOffset;
  300. u8 Flags;
  301. };
  302. struct MPI2_SGE_SIMPLE_UNION {
  303. __le32 FlagsLength;
  304. union {
  305. __le32 Address32;
  306. __le64 Address64;
  307. } u;
  308. };
  309. struct MPI2_SCSI_IO_CDB_EEDP32 {
  310. u8 CDB[20]; /* 0x00 */
  311. __be32 PrimaryReferenceTag; /* 0x14 */
  312. __be16 PrimaryApplicationTag; /* 0x18 */
  313. __be16 PrimaryApplicationTagMask; /* 0x1A */
  314. __le32 TransferLength; /* 0x1C */
  315. };
  316. struct MPI2_SGE_CHAIN_UNION {
  317. __le16 Length;
  318. u8 NextChainOffset;
  319. u8 Flags;
  320. union {
  321. __le32 Address32;
  322. __le64 Address64;
  323. } u;
  324. };
  325. struct MPI2_IEEE_SGE_SIMPLE32 {
  326. __le32 Address;
  327. __le32 FlagsLength;
  328. };
  329. struct MPI2_IEEE_SGE_CHAIN32 {
  330. __le32 Address;
  331. __le32 FlagsLength;
  332. };
  333. struct MPI2_IEEE_SGE_SIMPLE64 {
  334. __le64 Address;
  335. __le32 Length;
  336. __le16 Reserved1;
  337. u8 Reserved2;
  338. u8 Flags;
  339. };
  340. struct MPI2_IEEE_SGE_CHAIN64 {
  341. __le64 Address;
  342. __le32 Length;
  343. __le16 Reserved1;
  344. u8 Reserved2;
  345. u8 Flags;
  346. };
  347. union MPI2_IEEE_SGE_SIMPLE_UNION {
  348. struct MPI2_IEEE_SGE_SIMPLE32 Simple32;
  349. struct MPI2_IEEE_SGE_SIMPLE64 Simple64;
  350. };
  351. union MPI2_IEEE_SGE_CHAIN_UNION {
  352. struct MPI2_IEEE_SGE_CHAIN32 Chain32;
  353. struct MPI2_IEEE_SGE_CHAIN64 Chain64;
  354. };
  355. union MPI2_SGE_IO_UNION {
  356. struct MPI2_SGE_SIMPLE_UNION MpiSimple;
  357. struct MPI2_SGE_CHAIN_UNION MpiChain;
  358. union MPI2_IEEE_SGE_SIMPLE_UNION IeeeSimple;
  359. union MPI2_IEEE_SGE_CHAIN_UNION IeeeChain;
  360. };
  361. union MPI2_SCSI_IO_CDB_UNION {
  362. u8 CDB32[32];
  363. struct MPI2_SCSI_IO_CDB_EEDP32 EEDP32;
  364. struct MPI2_SGE_SIMPLE_UNION SGE;
  365. };
  366. /****************************************************************************
  367. * SCSI Task Management messages
  368. ****************************************************************************/
  369. /*SCSI Task Management Request Message */
  370. struct MPI2_SCSI_TASK_MANAGE_REQUEST {
  371. u16 DevHandle; /*0x00 */
  372. u8 ChainOffset; /*0x02 */
  373. u8 Function; /*0x03 */
  374. u8 Reserved1; /*0x04 */
  375. u8 TaskType; /*0x05 */
  376. u8 Reserved2; /*0x06 */
  377. u8 MsgFlags; /*0x07 */
  378. u8 VP_ID; /*0x08 */
  379. u8 VF_ID; /*0x09 */
  380. u16 Reserved3; /*0x0A */
  381. u8 LUN[8]; /*0x0C */
  382. u32 Reserved4[7]; /*0x14 */
  383. u16 TaskMID; /*0x30 */
  384. u16 Reserved5; /*0x32 */
  385. };
  386. /*SCSI Task Management Reply Message */
  387. struct MPI2_SCSI_TASK_MANAGE_REPLY {
  388. u16 DevHandle; /*0x00 */
  389. u8 MsgLength; /*0x02 */
  390. u8 Function; /*0x03 */
  391. u8 ResponseCode; /*0x04 */
  392. u8 TaskType; /*0x05 */
  393. u8 Reserved1; /*0x06 */
  394. u8 MsgFlags; /*0x07 */
  395. u8 VP_ID; /*0x08 */
  396. u8 VF_ID; /*0x09 */
  397. u16 Reserved2; /*0x0A */
  398. u16 Reserved3; /*0x0C */
  399. u16 IOCStatus; /*0x0E */
  400. u32 IOCLogInfo; /*0x10 */
  401. u32 TerminationCount; /*0x14 */
  402. u32 ResponseInfo; /*0x18 */
  403. };
  404. struct MR_TM_REQUEST {
  405. char request[128];
  406. };
  407. struct MR_TM_REPLY {
  408. char reply[128];
  409. };
  410. /* SCSI Task Management Request Message */
  411. struct MR_TASK_MANAGE_REQUEST {
  412. /*To be type casted to struct MPI2_SCSI_TASK_MANAGE_REQUEST */
  413. struct MR_TM_REQUEST TmRequest;
  414. union {
  415. struct {
  416. #if defined(__BIG_ENDIAN_BITFIELD)
  417. u32 reserved1:30;
  418. u32 isTMForPD:1;
  419. u32 isTMForLD:1;
  420. #else
  421. u32 isTMForLD:1;
  422. u32 isTMForPD:1;
  423. u32 reserved1:30;
  424. #endif
  425. u32 reserved2;
  426. } tmReqFlags;
  427. struct MR_TM_REPLY TMReply;
  428. };
  429. };
  430. /* TaskType values */
  431. #define MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK (0x01)
  432. #define MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET (0x02)
  433. #define MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET (0x03)
  434. #define MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET (0x05)
  435. #define MPI2_SCSITASKMGMT_TASKTYPE_CLEAR_TASK_SET (0x06)
  436. #define MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK (0x07)
  437. #define MPI2_SCSITASKMGMT_TASKTYPE_CLR_ACA (0x08)
  438. #define MPI2_SCSITASKMGMT_TASKTYPE_QRY_TASK_SET (0x09)
  439. #define MPI2_SCSITASKMGMT_TASKTYPE_QRY_ASYNC_EVENT (0x0A)
  440. /* ResponseCode values */
  441. #define MPI2_SCSITASKMGMT_RSP_TM_COMPLETE (0x00)
  442. #define MPI2_SCSITASKMGMT_RSP_INVALID_FRAME (0x02)
  443. #define MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED (0x04)
  444. #define MPI2_SCSITASKMGMT_RSP_TM_FAILED (0x05)
  445. #define MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED (0x08)
  446. #define MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN (0x09)
  447. #define MPI2_SCSITASKMGMT_RSP_TM_OVERLAPPED_TAG (0x0A)
  448. #define MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC (0x80)
  449. /*
  450. * RAID SCSI IO Request Message
  451. * Total SGE count will be one less than _MPI2_SCSI_IO_REQUEST
  452. */
  453. struct MPI2_RAID_SCSI_IO_REQUEST {
  454. __le16 DevHandle; /* 0x00 */
  455. u8 ChainOffset; /* 0x02 */
  456. u8 Function; /* 0x03 */
  457. __le16 Reserved1; /* 0x04 */
  458. u8 Reserved2; /* 0x06 */
  459. u8 MsgFlags; /* 0x07 */
  460. u8 VP_ID; /* 0x08 */
  461. u8 VF_ID; /* 0x09 */
  462. __le16 Reserved3; /* 0x0A */
  463. __le32 SenseBufferLowAddress; /* 0x0C */
  464. __le16 SGLFlags; /* 0x10 */
  465. u8 SenseBufferLength; /* 0x12 */
  466. u8 Reserved4; /* 0x13 */
  467. u8 SGLOffset0; /* 0x14 */
  468. u8 SGLOffset1; /* 0x15 */
  469. u8 SGLOffset2; /* 0x16 */
  470. u8 SGLOffset3; /* 0x17 */
  471. __le32 SkipCount; /* 0x18 */
  472. __le32 DataLength; /* 0x1C */
  473. __le32 BidirectionalDataLength; /* 0x20 */
  474. __le16 IoFlags; /* 0x24 */
  475. __le16 EEDPFlags; /* 0x26 */
  476. __le32 EEDPBlockSize; /* 0x28 */
  477. __le32 SecondaryReferenceTag; /* 0x2C */
  478. __le16 SecondaryApplicationTag; /* 0x30 */
  479. __le16 ApplicationTagTranslationMask; /* 0x32 */
  480. u8 LUN[8]; /* 0x34 */
  481. __le32 Control; /* 0x3C */
  482. union MPI2_SCSI_IO_CDB_UNION CDB; /* 0x40 */
  483. union RAID_CONTEXT_UNION RaidContext; /* 0x60 */
  484. union MPI2_SGE_IO_UNION SGL; /* 0x80 */
  485. };
  486. /*
  487. * MPT RAID MFA IO Descriptor.
  488. */
  489. struct MEGASAS_RAID_MFA_IO_REQUEST_DESCRIPTOR {
  490. u32 RequestFlags:8;
  491. u32 MessageAddress1:24;
  492. u32 MessageAddress2;
  493. };
  494. /* Default Request Descriptor */
  495. struct MPI2_DEFAULT_REQUEST_DESCRIPTOR {
  496. u8 RequestFlags; /* 0x00 */
  497. u8 MSIxIndex; /* 0x01 */
  498. __le16 SMID; /* 0x02 */
  499. __le16 LMID; /* 0x04 */
  500. __le16 DescriptorTypeDependent; /* 0x06 */
  501. };
  502. /* High Priority Request Descriptor */
  503. struct MPI2_HIGH_PRIORITY_REQUEST_DESCRIPTOR {
  504. u8 RequestFlags; /* 0x00 */
  505. u8 MSIxIndex; /* 0x01 */
  506. __le16 SMID; /* 0x02 */
  507. __le16 LMID; /* 0x04 */
  508. __le16 Reserved1; /* 0x06 */
  509. };
  510. /* SCSI IO Request Descriptor */
  511. struct MPI2_SCSI_IO_REQUEST_DESCRIPTOR {
  512. u8 RequestFlags; /* 0x00 */
  513. u8 MSIxIndex; /* 0x01 */
  514. __le16 SMID; /* 0x02 */
  515. __le16 LMID; /* 0x04 */
  516. __le16 DevHandle; /* 0x06 */
  517. };
  518. /* SCSI Target Request Descriptor */
  519. struct MPI2_SCSI_TARGET_REQUEST_DESCRIPTOR {
  520. u8 RequestFlags; /* 0x00 */
  521. u8 MSIxIndex; /* 0x01 */
  522. __le16 SMID; /* 0x02 */
  523. __le16 LMID; /* 0x04 */
  524. __le16 IoIndex; /* 0x06 */
  525. };
  526. /* RAID Accelerator Request Descriptor */
  527. struct MPI2_RAID_ACCEL_REQUEST_DESCRIPTOR {
  528. u8 RequestFlags; /* 0x00 */
  529. u8 MSIxIndex; /* 0x01 */
  530. __le16 SMID; /* 0x02 */
  531. __le16 LMID; /* 0x04 */
  532. __le16 Reserved; /* 0x06 */
  533. };
  534. /* union of Request Descriptors */
  535. union MEGASAS_REQUEST_DESCRIPTOR_UNION {
  536. struct MPI2_DEFAULT_REQUEST_DESCRIPTOR Default;
  537. struct MPI2_HIGH_PRIORITY_REQUEST_DESCRIPTOR HighPriority;
  538. struct MPI2_SCSI_IO_REQUEST_DESCRIPTOR SCSIIO;
  539. struct MPI2_SCSI_TARGET_REQUEST_DESCRIPTOR SCSITarget;
  540. struct MPI2_RAID_ACCEL_REQUEST_DESCRIPTOR RAIDAccelerator;
  541. struct MEGASAS_RAID_MFA_IO_REQUEST_DESCRIPTOR MFAIo;
  542. union {
  543. struct {
  544. __le32 low;
  545. __le32 high;
  546. } u;
  547. __le64 Words;
  548. };
  549. };
  550. /* Default Reply Descriptor */
  551. struct MPI2_DEFAULT_REPLY_DESCRIPTOR {
  552. u8 ReplyFlags; /* 0x00 */
  553. u8 MSIxIndex; /* 0x01 */
  554. __le16 DescriptorTypeDependent1; /* 0x02 */
  555. __le32 DescriptorTypeDependent2; /* 0x04 */
  556. };
  557. /* Address Reply Descriptor */
  558. struct MPI2_ADDRESS_REPLY_DESCRIPTOR {
  559. u8 ReplyFlags; /* 0x00 */
  560. u8 MSIxIndex; /* 0x01 */
  561. __le16 SMID; /* 0x02 */
  562. __le32 ReplyFrameAddress; /* 0x04 */
  563. };
  564. /* SCSI IO Success Reply Descriptor */
  565. struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR {
  566. u8 ReplyFlags; /* 0x00 */
  567. u8 MSIxIndex; /* 0x01 */
  568. __le16 SMID; /* 0x02 */
  569. __le16 TaskTag; /* 0x04 */
  570. __le16 Reserved1; /* 0x06 */
  571. };
  572. /* TargetAssist Success Reply Descriptor */
  573. struct MPI2_TARGETASSIST_SUCCESS_REPLY_DESCRIPTOR {
  574. u8 ReplyFlags; /* 0x00 */
  575. u8 MSIxIndex; /* 0x01 */
  576. __le16 SMID; /* 0x02 */
  577. u8 SequenceNumber; /* 0x04 */
  578. u8 Reserved1; /* 0x05 */
  579. __le16 IoIndex; /* 0x06 */
  580. };
  581. /* Target Command Buffer Reply Descriptor */
  582. struct MPI2_TARGET_COMMAND_BUFFER_REPLY_DESCRIPTOR {
  583. u8 ReplyFlags; /* 0x00 */
  584. u8 MSIxIndex; /* 0x01 */
  585. u8 VP_ID; /* 0x02 */
  586. u8 Flags; /* 0x03 */
  587. __le16 InitiatorDevHandle; /* 0x04 */
  588. __le16 IoIndex; /* 0x06 */
  589. };
  590. /* RAID Accelerator Success Reply Descriptor */
  591. struct MPI2_RAID_ACCELERATOR_SUCCESS_REPLY_DESCRIPTOR {
  592. u8 ReplyFlags; /* 0x00 */
  593. u8 MSIxIndex; /* 0x01 */
  594. __le16 SMID; /* 0x02 */
  595. __le32 Reserved; /* 0x04 */
  596. };
  597. /* union of Reply Descriptors */
  598. union MPI2_REPLY_DESCRIPTORS_UNION {
  599. struct MPI2_DEFAULT_REPLY_DESCRIPTOR Default;
  600. struct MPI2_ADDRESS_REPLY_DESCRIPTOR AddressReply;
  601. struct MPI2_SCSI_IO_SUCCESS_REPLY_DESCRIPTOR SCSIIOSuccess;
  602. struct MPI2_TARGETASSIST_SUCCESS_REPLY_DESCRIPTOR TargetAssistSuccess;
  603. struct MPI2_TARGET_COMMAND_BUFFER_REPLY_DESCRIPTOR TargetCommandBuffer;
  604. struct MPI2_RAID_ACCELERATOR_SUCCESS_REPLY_DESCRIPTOR
  605. RAIDAcceleratorSuccess;
  606. __le64 Words;
  607. };
  608. /* IOCInit Request message */
  609. struct MPI2_IOC_INIT_REQUEST {
  610. u8 WhoInit; /* 0x00 */
  611. u8 Reserved1; /* 0x01 */
  612. u8 ChainOffset; /* 0x02 */
  613. u8 Function; /* 0x03 */
  614. __le16 Reserved2; /* 0x04 */
  615. u8 Reserved3; /* 0x06 */
  616. u8 MsgFlags; /* 0x07 */
  617. u8 VP_ID; /* 0x08 */
  618. u8 VF_ID; /* 0x09 */
  619. __le16 Reserved4; /* 0x0A */
  620. __le16 MsgVersion; /* 0x0C */
  621. __le16 HeaderVersion; /* 0x0E */
  622. u32 Reserved5; /* 0x10 */
  623. __le16 Reserved6; /* 0x14 */
  624. u8 HostPageSize; /* 0x16 */
  625. u8 HostMSIxVectors; /* 0x17 */
  626. __le16 Reserved8; /* 0x18 */
  627. __le16 SystemRequestFrameSize; /* 0x1A */
  628. __le16 ReplyDescriptorPostQueueDepth; /* 0x1C */
  629. __le16 ReplyFreeQueueDepth; /* 0x1E */
  630. __le32 SenseBufferAddressHigh; /* 0x20 */
  631. __le32 SystemReplyAddressHigh; /* 0x24 */
  632. __le64 SystemRequestFrameBaseAddress; /* 0x28 */
  633. __le64 ReplyDescriptorPostQueueAddress;/* 0x30 */
  634. __le64 ReplyFreeQueueAddress; /* 0x38 */
  635. __le64 TimeStamp; /* 0x40 */
  636. };
  637. /* mrpriv defines */
  638. #define MR_PD_INVALID 0xFFFF
  639. #define MR_DEVHANDLE_INVALID 0xFFFF
  640. #define MAX_SPAN_DEPTH 8
  641. #define MAX_QUAD_DEPTH MAX_SPAN_DEPTH
  642. #define MAX_RAIDMAP_SPAN_DEPTH (MAX_SPAN_DEPTH)
  643. #define MAX_ROW_SIZE 32
  644. #define MAX_RAIDMAP_ROW_SIZE (MAX_ROW_SIZE)
  645. #define MAX_LOGICAL_DRIVES 64
  646. #define MAX_LOGICAL_DRIVES_EXT 256
  647. #define MAX_LOGICAL_DRIVES_DYN 512
  648. #define MAX_RAIDMAP_LOGICAL_DRIVES (MAX_LOGICAL_DRIVES)
  649. #define MAX_RAIDMAP_VIEWS (MAX_LOGICAL_DRIVES)
  650. #define MAX_ARRAYS 128
  651. #define MAX_RAIDMAP_ARRAYS (MAX_ARRAYS)
  652. #define MAX_ARRAYS_EXT 256
  653. #define MAX_API_ARRAYS_EXT (MAX_ARRAYS_EXT)
  654. #define MAX_API_ARRAYS_DYN 512
  655. #define MAX_PHYSICAL_DEVICES 256
  656. #define MAX_RAIDMAP_PHYSICAL_DEVICES (MAX_PHYSICAL_DEVICES)
  657. #define MAX_RAIDMAP_PHYSICAL_DEVICES_DYN 512
  658. #define MR_DCMD_LD_MAP_GET_INFO 0x0300e101
  659. #define MR_DCMD_SYSTEM_PD_MAP_GET_INFO 0x0200e102
  660. #define MR_DCMD_DRV_GET_TARGET_PROP 0x0200e103
  661. #define MR_DCMD_CTRL_SHARED_HOST_MEM_ALLOC 0x010e8485 /* SR-IOV HB alloc*/
  662. #define MR_DCMD_LD_VF_MAP_GET_ALL_LDS_111 0x03200200
  663. #define MR_DCMD_LD_VF_MAP_GET_ALL_LDS 0x03150200
  664. struct MR_DEV_HANDLE_INFO {
  665. __le16 curDevHdl;
  666. u8 validHandles;
  667. u8 interfaceType;
  668. __le16 devHandle[2];
  669. };
  670. struct MR_ARRAY_INFO {
  671. __le16 pd[MAX_RAIDMAP_ROW_SIZE];
  672. };
  673. struct MR_QUAD_ELEMENT {
  674. __le64 logStart;
  675. __le64 logEnd;
  676. __le64 offsetInSpan;
  677. __le32 diff;
  678. __le32 reserved1;
  679. };
  680. struct MR_SPAN_INFO {
  681. __le32 noElements;
  682. __le32 reserved1;
  683. struct MR_QUAD_ELEMENT quad[MAX_RAIDMAP_SPAN_DEPTH];
  684. };
  685. struct MR_LD_SPAN {
  686. __le64 startBlk;
  687. __le64 numBlks;
  688. __le16 arrayRef;
  689. u8 spanRowSize;
  690. u8 spanRowDataSize;
  691. u8 reserved[4];
  692. };
  693. struct MR_SPAN_BLOCK_INFO {
  694. __le64 num_rows;
  695. struct MR_LD_SPAN span;
  696. struct MR_SPAN_INFO block_span_info;
  697. };
  698. #define MR_RAID_CTX_CPUSEL_0 0
  699. #define MR_RAID_CTX_CPUSEL_1 1
  700. #define MR_RAID_CTX_CPUSEL_2 2
  701. #define MR_RAID_CTX_CPUSEL_3 3
  702. #define MR_RAID_CTX_CPUSEL_FCFS 0xF
  703. struct MR_CPU_AFFINITY_MASK {
  704. union {
  705. struct {
  706. #ifndef MFI_BIG_ENDIAN
  707. u8 hw_path:1;
  708. u8 cpu0:1;
  709. u8 cpu1:1;
  710. u8 cpu2:1;
  711. u8 cpu3:1;
  712. u8 reserved:3;
  713. #else
  714. u8 reserved:3;
  715. u8 cpu3:1;
  716. u8 cpu2:1;
  717. u8 cpu1:1;
  718. u8 cpu0:1;
  719. u8 hw_path:1;
  720. #endif
  721. };
  722. u8 core_mask;
  723. };
  724. };
  725. struct MR_IO_AFFINITY {
  726. union {
  727. struct {
  728. struct MR_CPU_AFFINITY_MASK pdRead;
  729. struct MR_CPU_AFFINITY_MASK pdWrite;
  730. struct MR_CPU_AFFINITY_MASK ldRead;
  731. struct MR_CPU_AFFINITY_MASK ldWrite;
  732. };
  733. u32 word;
  734. };
  735. u8 maxCores; /* Total cores + HW Path in ROC */
  736. u8 reserved[3];
  737. };
  738. struct MR_LD_RAID {
  739. struct {
  740. #if defined(__BIG_ENDIAN_BITFIELD)
  741. u32 reserved4:2;
  742. u32 fp_cache_bypass_capable:1;
  743. u32 fp_rmw_capable:1;
  744. u32 disable_coalescing:1;
  745. u32 fpBypassRegionLock:1;
  746. u32 tmCapable:1;
  747. u32 fpNonRWCapable:1;
  748. u32 fpReadAcrossStripe:1;
  749. u32 fpWriteAcrossStripe:1;
  750. u32 fpReadCapable:1;
  751. u32 fpWriteCapable:1;
  752. u32 encryptionType:8;
  753. u32 pdPiMode:4;
  754. u32 ldPiMode:4;
  755. u32 reserved5:2;
  756. u32 ra_capable:1;
  757. u32 fpCapable:1;
  758. #else
  759. u32 fpCapable:1;
  760. u32 ra_capable:1;
  761. u32 reserved5:2;
  762. u32 ldPiMode:4;
  763. u32 pdPiMode:4;
  764. u32 encryptionType:8;
  765. u32 fpWriteCapable:1;
  766. u32 fpReadCapable:1;
  767. u32 fpWriteAcrossStripe:1;
  768. u32 fpReadAcrossStripe:1;
  769. u32 fpNonRWCapable:1;
  770. u32 tmCapable:1;
  771. u32 fpBypassRegionLock:1;
  772. u32 disable_coalescing:1;
  773. u32 fp_rmw_capable:1;
  774. u32 fp_cache_bypass_capable:1;
  775. u32 reserved4:2;
  776. #endif
  777. } capability;
  778. __le32 reserved6;
  779. __le64 size;
  780. u8 spanDepth;
  781. u8 level;
  782. u8 stripeShift;
  783. u8 rowSize;
  784. u8 rowDataSize;
  785. u8 writeMode;
  786. u8 PRL;
  787. u8 SRL;
  788. __le16 targetId;
  789. u8 ldState;
  790. u8 regTypeReqOnWrite;
  791. u8 modFactor;
  792. u8 regTypeReqOnRead;
  793. __le16 seqNum;
  794. struct {
  795. u32 ldSyncRequired:1;
  796. u32 reserved:31;
  797. } flags;
  798. u8 LUN[8]; /* 0x24 8 byte LUN field used for SCSI IO's */
  799. u8 fpIoTimeoutForLd;/*0x2C timeout value used by driver in FP IO*/
  800. /* Ox2D This LD accept priority boost of this type */
  801. u8 ld_accept_priority_type;
  802. u8 reserved2[2]; /* 0x2E - 0x2F */
  803. /* 0x30 - 0x33, Logical block size for the LD */
  804. u32 logical_block_length;
  805. struct {
  806. #ifndef MFI_BIG_ENDIAN
  807. /* 0x34, P_I_EXPONENT from READ CAPACITY 16 */
  808. u32 ld_pi_exp:4;
  809. /* 0x34, LOGICAL BLOCKS PER PHYSICAL
  810. * BLOCK EXPONENT from READ CAPACITY 16
  811. */
  812. u32 ld_logical_block_exp:4;
  813. u32 reserved1:24; /* 0x34 */
  814. #else
  815. u32 reserved1:24; /* 0x34 */
  816. /* 0x34, LOGICAL BLOCKS PER PHYSICAL
  817. * BLOCK EXPONENT from READ CAPACITY 16
  818. */
  819. u32 ld_logical_block_exp:4;
  820. /* 0x34, P_I_EXPONENT from READ CAPACITY 16 */
  821. u32 ld_pi_exp:4;
  822. #endif
  823. }; /* 0x34 - 0x37 */
  824. /* 0x38 - 0x3f, This will determine which
  825. * core will process LD IO and PD IO.
  826. */
  827. struct MR_IO_AFFINITY cpuAffinity;
  828. /* Bit definiations are specified by MR_IO_AFFINITY */
  829. u8 reserved3[0x80 - 0x40]; /* 0x40 - 0x7f */
  830. };
  831. struct MR_LD_SPAN_MAP {
  832. struct MR_LD_RAID ldRaid;
  833. u8 dataArmMap[MAX_RAIDMAP_ROW_SIZE];
  834. struct MR_SPAN_BLOCK_INFO spanBlock[MAX_RAIDMAP_SPAN_DEPTH];
  835. };
  836. struct MR_FW_RAID_MAP {
  837. __le32 totalSize;
  838. union {
  839. struct {
  840. __le32 maxLd;
  841. __le32 maxSpanDepth;
  842. __le32 maxRowSize;
  843. __le32 maxPdCount;
  844. __le32 maxArrays;
  845. } validationInfo;
  846. __le32 version[5];
  847. };
  848. __le32 ldCount;
  849. __le32 Reserved1;
  850. u8 ldTgtIdToLd[MAX_RAIDMAP_LOGICAL_DRIVES+
  851. MAX_RAIDMAP_VIEWS];
  852. u8 fpPdIoTimeoutSec;
  853. u8 reserved2[7];
  854. struct MR_ARRAY_INFO arMapInfo[MAX_RAIDMAP_ARRAYS];
  855. struct MR_DEV_HANDLE_INFO devHndlInfo[MAX_RAIDMAP_PHYSICAL_DEVICES];
  856. struct MR_LD_SPAN_MAP ldSpanMap[1];
  857. };
  858. struct IO_REQUEST_INFO {
  859. u64 ldStartBlock;
  860. u32 numBlocks;
  861. u16 ldTgtId;
  862. u8 isRead;
  863. __le16 devHandle;
  864. u8 pd_interface;
  865. u64 pdBlock;
  866. u8 fpOkForIo;
  867. u8 IoforUnevenSpan;
  868. u8 start_span;
  869. u8 do_fp_rlbypass;
  870. u64 start_row;
  871. u8 span_arm; /* span[7:5], arm[4:0] */
  872. u8 pd_after_lb;
  873. u16 r1_alt_dev_handle; /* raid 1/10 only */
  874. bool ra_capable;
  875. };
  876. struct MR_LD_TARGET_SYNC {
  877. u8 targetId;
  878. u8 reserved;
  879. __le16 seqNum;
  880. };
  881. /*
  882. * RAID Map descriptor Types.
  883. * Each element should uniquely idetify one data structure in the RAID map
  884. */
  885. enum MR_RAID_MAP_DESC_TYPE {
  886. /* MR_DEV_HANDLE_INFO data */
  887. RAID_MAP_DESC_TYPE_DEVHDL_INFO = 0x0,
  888. /* target to Ld num Index map */
  889. RAID_MAP_DESC_TYPE_TGTID_INFO = 0x1,
  890. /* MR_ARRAY_INFO data */
  891. RAID_MAP_DESC_TYPE_ARRAY_INFO = 0x2,
  892. /* MR_LD_SPAN_MAP data */
  893. RAID_MAP_DESC_TYPE_SPAN_INFO = 0x3,
  894. RAID_MAP_DESC_TYPE_COUNT,
  895. };
  896. /*
  897. * This table defines the offset, size and num elements of each descriptor
  898. * type in the RAID Map buffer
  899. */
  900. struct MR_RAID_MAP_DESC_TABLE {
  901. /* Raid map descriptor type */
  902. u32 raid_map_desc_type;
  903. /* Offset into the RAID map buffer where
  904. * descriptor data is saved
  905. */
  906. u32 raid_map_desc_offset;
  907. /* total size of the
  908. * descriptor buffer
  909. */
  910. u32 raid_map_desc_buffer_size;
  911. /* Number of elements contained in the
  912. * descriptor buffer
  913. */
  914. u32 raid_map_desc_elements;
  915. };
  916. /*
  917. * Dynamic Raid Map Structure.
  918. */
  919. struct MR_FW_RAID_MAP_DYNAMIC {
  920. u32 raid_map_size; /* total size of RAID Map structure */
  921. u32 desc_table_offset;/* Offset of desc table into RAID map*/
  922. u32 desc_table_size; /* Total Size of desc table */
  923. /* Total Number of elements in the desc table */
  924. u32 desc_table_num_elements;
  925. u64 reserved1;
  926. u32 reserved2[3]; /*future use */
  927. /* timeout value used by driver in FP IOs */
  928. u8 fp_pd_io_timeout_sec;
  929. u8 reserved3[3];
  930. /* when this seqNum increments, driver needs to
  931. * release RMW buffers asap
  932. */
  933. u32 rmw_fp_seq_num;
  934. u16 ld_count; /* count of lds. */
  935. u16 ar_count; /* count of arrays */
  936. u16 span_count; /* count of spans */
  937. u16 reserved4[3];
  938. /*
  939. * The below structure of pointers is only to be used by the driver.
  940. * This is added in the ,API to reduce the amount of code changes
  941. * needed in the driver to support dynamic RAID map Firmware should
  942. * not update these pointers while preparing the raid map
  943. */
  944. union {
  945. struct {
  946. struct MR_DEV_HANDLE_INFO *dev_hndl_info;
  947. u16 *ld_tgt_id_to_ld;
  948. struct MR_ARRAY_INFO *ar_map_info;
  949. struct MR_LD_SPAN_MAP *ld_span_map;
  950. };
  951. u64 ptr_structure_size[RAID_MAP_DESC_TYPE_COUNT];
  952. };
  953. /*
  954. * RAID Map descriptor table defines the layout of data in the RAID Map.
  955. * The size of the descriptor table itself could change.
  956. */
  957. /* Variable Size descriptor Table. */
  958. struct MR_RAID_MAP_DESC_TABLE
  959. raid_map_desc_table[RAID_MAP_DESC_TYPE_COUNT];
  960. /* Variable Size buffer containing all data */
  961. u32 raid_map_desc_data[1];
  962. }; /* Dynamicaly sized RAID MAp structure */
  963. #define IEEE_SGE_FLAGS_ADDR_MASK (0x03)
  964. #define IEEE_SGE_FLAGS_SYSTEM_ADDR (0x00)
  965. #define IEEE_SGE_FLAGS_IOCDDR_ADDR (0x01)
  966. #define IEEE_SGE_FLAGS_IOCPLB_ADDR (0x02)
  967. #define IEEE_SGE_FLAGS_IOCPLBNTA_ADDR (0x03)
  968. #define IEEE_SGE_FLAGS_CHAIN_ELEMENT (0x80)
  969. #define IEEE_SGE_FLAGS_END_OF_LIST (0x40)
  970. #define MPI2_SGE_FLAGS_SHIFT (0x02)
  971. #define IEEE_SGE_FLAGS_FORMAT_MASK (0xC0)
  972. #define IEEE_SGE_FLAGS_FORMAT_IEEE (0x00)
  973. #define IEEE_SGE_FLAGS_FORMAT_NVME (0x02)
  974. #define MPI26_IEEE_SGE_FLAGS_NSF_MASK (0x1C)
  975. #define MPI26_IEEE_SGE_FLAGS_NSF_MPI_IEEE (0x00)
  976. #define MPI26_IEEE_SGE_FLAGS_NSF_NVME_PRP (0x08)
  977. #define MPI26_IEEE_SGE_FLAGS_NSF_NVME_SGL (0x10)
  978. struct megasas_register_set;
  979. struct megasas_instance;
  980. union desc_word {
  981. u64 word;
  982. struct {
  983. u32 low;
  984. u32 high;
  985. } u;
  986. };
  987. struct megasas_cmd_fusion {
  988. struct MPI2_RAID_SCSI_IO_REQUEST *io_request;
  989. dma_addr_t io_request_phys_addr;
  990. union MPI2_SGE_IO_UNION *sg_frame;
  991. dma_addr_t sg_frame_phys_addr;
  992. u8 *sense;
  993. dma_addr_t sense_phys_addr;
  994. struct list_head list;
  995. struct scsi_cmnd *scmd;
  996. struct megasas_instance *instance;
  997. u8 retry_for_fw_reset;
  998. union MEGASAS_REQUEST_DESCRIPTOR_UNION *request_desc;
  999. /*
  1000. * Context for a MFI frame.
  1001. * Used to get the mfi cmd from list when a MFI cmd is completed
  1002. */
  1003. u32 sync_cmd_idx;
  1004. u32 index;
  1005. u8 pd_r1_lb;
  1006. struct completion done;
  1007. u8 pd_interface;
  1008. u16 r1_alt_dev_handle; /* raid 1/10 only*/
  1009. bool cmd_completed; /* raid 1/10 fp writes status holder */
  1010. };
  1011. struct LD_LOAD_BALANCE_INFO {
  1012. u8 loadBalanceFlag;
  1013. u8 reserved1;
  1014. atomic_t scsi_pending_cmds[MAX_PHYSICAL_DEVICES];
  1015. u64 last_accessed_block[MAX_PHYSICAL_DEVICES];
  1016. };
  1017. /* SPAN_SET is info caclulated from span info from Raid map per LD */
  1018. typedef struct _LD_SPAN_SET {
  1019. u64 log_start_lba;
  1020. u64 log_end_lba;
  1021. u64 span_row_start;
  1022. u64 span_row_end;
  1023. u64 data_strip_start;
  1024. u64 data_strip_end;
  1025. u64 data_row_start;
  1026. u64 data_row_end;
  1027. u8 strip_offset[MAX_SPAN_DEPTH];
  1028. u32 span_row_data_width;
  1029. u32 diff;
  1030. u32 reserved[2];
  1031. } LD_SPAN_SET, *PLD_SPAN_SET;
  1032. typedef struct LOG_BLOCK_SPAN_INFO {
  1033. LD_SPAN_SET span_set[MAX_SPAN_DEPTH];
  1034. } LD_SPAN_INFO, *PLD_SPAN_INFO;
  1035. struct MR_FW_RAID_MAP_ALL {
  1036. struct MR_FW_RAID_MAP raidMap;
  1037. struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES - 1];
  1038. } __attribute__ ((packed));
  1039. struct MR_DRV_RAID_MAP {
  1040. /* total size of this structure, including this field.
  1041. * This feild will be manupulated by driver for ext raid map,
  1042. * else pick the value from firmware raid map.
  1043. */
  1044. __le32 totalSize;
  1045. union {
  1046. struct {
  1047. __le32 maxLd;
  1048. __le32 maxSpanDepth;
  1049. __le32 maxRowSize;
  1050. __le32 maxPdCount;
  1051. __le32 maxArrays;
  1052. } validationInfo;
  1053. __le32 version[5];
  1054. };
  1055. /* timeout value used by driver in FP IOs*/
  1056. u8 fpPdIoTimeoutSec;
  1057. u8 reserved2[7];
  1058. __le16 ldCount;
  1059. __le16 arCount;
  1060. __le16 spanCount;
  1061. __le16 reserve3;
  1062. struct MR_DEV_HANDLE_INFO
  1063. devHndlInfo[MAX_RAIDMAP_PHYSICAL_DEVICES_DYN];
  1064. u16 ldTgtIdToLd[MAX_LOGICAL_DRIVES_DYN];
  1065. struct MR_ARRAY_INFO arMapInfo[MAX_API_ARRAYS_DYN];
  1066. struct MR_LD_SPAN_MAP ldSpanMap[1];
  1067. };
  1068. /* Driver raid map size is same as raid map ext
  1069. * MR_DRV_RAID_MAP_ALL is created to sync with old raid.
  1070. * And it is mainly for code re-use purpose.
  1071. */
  1072. struct MR_DRV_RAID_MAP_ALL {
  1073. struct MR_DRV_RAID_MAP raidMap;
  1074. struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES_DYN - 1];
  1075. } __packed;
  1076. struct MR_FW_RAID_MAP_EXT {
  1077. /* Not usred in new map */
  1078. u32 reserved;
  1079. union {
  1080. struct {
  1081. u32 maxLd;
  1082. u32 maxSpanDepth;
  1083. u32 maxRowSize;
  1084. u32 maxPdCount;
  1085. u32 maxArrays;
  1086. } validationInfo;
  1087. u32 version[5];
  1088. };
  1089. u8 fpPdIoTimeoutSec;
  1090. u8 reserved2[7];
  1091. __le16 ldCount;
  1092. __le16 arCount;
  1093. __le16 spanCount;
  1094. __le16 reserve3;
  1095. struct MR_DEV_HANDLE_INFO devHndlInfo[MAX_RAIDMAP_PHYSICAL_DEVICES];
  1096. u8 ldTgtIdToLd[MAX_LOGICAL_DRIVES_EXT];
  1097. struct MR_ARRAY_INFO arMapInfo[MAX_API_ARRAYS_EXT];
  1098. struct MR_LD_SPAN_MAP ldSpanMap[MAX_LOGICAL_DRIVES_EXT];
  1099. };
  1100. /*
  1101. * * define MR_PD_CFG_SEQ structure for system PDs
  1102. * */
  1103. struct MR_PD_CFG_SEQ {
  1104. u16 seqNum;
  1105. u16 devHandle;
  1106. struct {
  1107. #if defined(__BIG_ENDIAN_BITFIELD)
  1108. u8 reserved:7;
  1109. u8 tmCapable:1;
  1110. #else
  1111. u8 tmCapable:1;
  1112. u8 reserved:7;
  1113. #endif
  1114. } capability;
  1115. u8 reserved;
  1116. u16 pd_target_id;
  1117. } __packed;
  1118. struct MR_PD_CFG_SEQ_NUM_SYNC {
  1119. __le32 size;
  1120. __le32 count;
  1121. struct MR_PD_CFG_SEQ seq[1];
  1122. } __packed;
  1123. /* stream detection */
  1124. struct STREAM_DETECT {
  1125. u64 next_seq_lba; /* next LBA to match sequential access */
  1126. struct megasas_cmd_fusion *first_cmd_fusion; /* first cmd in group */
  1127. struct megasas_cmd_fusion *last_cmd_fusion; /* last cmd in group */
  1128. u32 count_cmds_in_stream; /* count of host commands in this stream */
  1129. u16 num_sges_in_group; /* total number of SGEs in grouped IOs */
  1130. u8 is_read; /* SCSI OpCode for this stream */
  1131. u8 group_depth; /* total number of host commands in group */
  1132. /* TRUE if cannot add any more commands to this group */
  1133. bool group_flush;
  1134. u8 reserved[7]; /* pad to 64-bit alignment */
  1135. };
  1136. struct LD_STREAM_DETECT {
  1137. bool write_back; /* TRUE if WB, FALSE if WT */
  1138. bool fp_write_enabled;
  1139. bool members_ssds;
  1140. bool fp_cache_bypass_capable;
  1141. u32 mru_bit_map; /* bitmap used to track MRU and LRU stream indicies */
  1142. /* this is the array of stream detect structures (one per stream) */
  1143. struct STREAM_DETECT stream_track[MAX_STREAMS_TRACKED];
  1144. };
  1145. struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY {
  1146. u64 RDPQBaseAddress;
  1147. u32 Reserved1;
  1148. u32 Reserved2;
  1149. };
  1150. struct rdpq_alloc_detail {
  1151. struct dma_pool *dma_pool_ptr;
  1152. dma_addr_t pool_entry_phys;
  1153. union MPI2_REPLY_DESCRIPTORS_UNION *pool_entry_virt;
  1154. };
  1155. struct fusion_context {
  1156. struct megasas_cmd_fusion **cmd_list;
  1157. dma_addr_t req_frames_desc_phys;
  1158. u8 *req_frames_desc;
  1159. struct dma_pool *io_request_frames_pool;
  1160. dma_addr_t io_request_frames_phys;
  1161. u8 *io_request_frames;
  1162. struct dma_pool *sg_dma_pool;
  1163. struct dma_pool *sense_dma_pool;
  1164. u8 *sense;
  1165. dma_addr_t sense_phys_addr;
  1166. dma_addr_t reply_frames_desc_phys[MAX_MSIX_QUEUES_FUSION];
  1167. union MPI2_REPLY_DESCRIPTORS_UNION *reply_frames_desc[MAX_MSIX_QUEUES_FUSION];
  1168. struct rdpq_alloc_detail rdpq_tracker[RDPQ_MAX_CHUNK_COUNT];
  1169. struct dma_pool *reply_frames_desc_pool;
  1170. struct dma_pool *reply_frames_desc_pool_align;
  1171. u16 last_reply_idx[MAX_MSIX_QUEUES_FUSION];
  1172. u32 reply_q_depth;
  1173. u32 request_alloc_sz;
  1174. u32 reply_alloc_sz;
  1175. u32 io_frames_alloc_sz;
  1176. struct MPI2_IOC_INIT_RDPQ_ARRAY_ENTRY *rdpq_virt;
  1177. dma_addr_t rdpq_phys;
  1178. u16 max_sge_in_main_msg;
  1179. u16 max_sge_in_chain;
  1180. u8 chain_offset_io_request;
  1181. u8 chain_offset_mfi_pthru;
  1182. struct MR_FW_RAID_MAP_DYNAMIC *ld_map[2];
  1183. dma_addr_t ld_map_phys[2];
  1184. /*Non dma-able memory. Driver local copy.*/
  1185. struct MR_DRV_RAID_MAP_ALL *ld_drv_map[2];
  1186. u32 max_map_sz;
  1187. u32 current_map_sz;
  1188. u32 old_map_sz;
  1189. u32 new_map_sz;
  1190. u32 drv_map_sz;
  1191. u32 drv_map_pages;
  1192. struct MR_PD_CFG_SEQ_NUM_SYNC *pd_seq_sync[JBOD_MAPS_COUNT];
  1193. dma_addr_t pd_seq_phys[JBOD_MAPS_COUNT];
  1194. u8 fast_path_io;
  1195. struct LD_LOAD_BALANCE_INFO *load_balance_info;
  1196. u32 load_balance_info_pages;
  1197. LD_SPAN_INFO *log_to_span;
  1198. u32 log_to_span_pages;
  1199. struct LD_STREAM_DETECT **stream_detect_by_ld;
  1200. dma_addr_t ioc_init_request_phys;
  1201. struct MPI2_IOC_INIT_REQUEST *ioc_init_request;
  1202. struct megasas_cmd *ioc_init_cmd;
  1203. };
  1204. union desc_value {
  1205. __le64 word;
  1206. struct {
  1207. __le32 low;
  1208. __le32 high;
  1209. } u;
  1210. };
  1211. enum CMD_RET_VALUES {
  1212. REFIRE_CMD = 1,
  1213. COMPLETE_CMD = 2,
  1214. RETURN_CMD = 3,
  1215. };
  1216. void megasas_free_cmds_fusion(struct megasas_instance *instance);
  1217. int megasas_ioc_init_fusion(struct megasas_instance *instance);
  1218. u8 megasas_get_map_info(struct megasas_instance *instance);
  1219. int megasas_sync_map_info(struct megasas_instance *instance);
  1220. void megasas_release_fusion(struct megasas_instance *instance);
  1221. void megasas_reset_reply_desc(struct megasas_instance *instance);
  1222. int megasas_check_mpio_paths(struct megasas_instance *instance,
  1223. struct scsi_cmnd *scmd);
  1224. void megasas_fusion_ocr_wq(struct work_struct *work);
  1225. #endif /* _MEGARAID_SAS_FUSION_H_ */