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