1285809Sscottl/*******************************************************************************
2285809Sscottl*Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3285809Sscottl*
4285809Sscottl*Redistribution and use in source and binary forms, with or without modification, are permitted provided
5285809Sscottl*that the following conditions are met:
6285809Sscottl*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7285809Sscottl*following disclaimer.
8285809Sscottl*2. Redistributions in binary form must reproduce the above copyright notice,
9285809Sscottl*this list of conditions and the following disclaimer in the documentation and/or other materials provided
10285809Sscottl*with the distribution.
11285809Sscottl*
12285809Sscottl*THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13285809Sscottl*WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14285809Sscottl*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15285809Sscottl*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16285809Sscottl*NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17285809Sscottl*BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18285809Sscottl*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19285809Sscottl*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20285809Sscottl*
21285809Sscottl* $FreeBSD$
22285809Sscottl*
23285809Sscottl********************************************************************************/
24285809Sscottl/********************************************************************************
25285809Sscottl**
26285809Sscottl*   sm.h
27285809Sscottl*
28285809Sscottl*   Abstract:   This module defines the contants, enum and #define definition used
29285809Sscottl*               by SAT Moduled (SM).
30285809Sscottl*
31285809Sscottl********************************************************************************/
32285809Sscottl
33285809Sscottl#ifndef SM_H
34285809Sscottl#define SM_H
35285809Sscottl
36285809Sscottl/*************************************************
37285809Sscottl *   constants for type field in smMem_t
38285809Sscottl *************************************************/
39285809Sscottl#define SM_CACHED_MEM                             0x00     /**< CACHED memory type */
40285809Sscottl#define SM_DMA_MEM                                0x01     /**< DMA memory type */
41285809Sscottl#define SM_CACHED_DMA_MEM                         0x02     /**< CACHED DMA memory type */
42285809Sscottl
43285809Sscottl/*************************************************
44285809Sscottl *   constants for API return values
45285809Sscottl *************************************************/
46285809Sscottltypedef enum
47285809Sscottl{
48285809Sscottl  SM_RC_SUCCESS,
49285809Sscottl  SM_RC_FAILURE,
50285809Sscottl  SM_RC_BUSY,
51285809Sscottl  SM_RC_NODEVICE,
52285809Sscottl  SM_RC_VERSION_INCOMPATIBLE,
53285809Sscottl  SM_RC_VERSION_UNTESTED,
54285809Sscottl  SM_RC_RSV1,
55285809Sscottl  SM_RC_RSV2,
56285809Sscottl  SM_RC_RSV3,
57285809Sscottl  SM_RC_RSV4,
58285809Sscottl  SM_RC_DEVICE_BUSY, /* must be the same as tiDeviceBusy */
59285809Sscottl
60285809Sscottl} smStatus_t;
61285809Sscottl
62285809Sscottltypedef enum
63285809Sscottl{
64285809Sscottl  smIOSuccess,
65285809Sscottl  smIOOverRun,
66285809Sscottl  smIOUnderRun,
67285809Sscottl  smIOFailed,
68285809Sscottl  smIODifError,
69285809Sscottl  smIOEncryptError,
70285809Sscottl  smIORetry,           /* open retry timeout */
71285809Sscottl  smIOSTPResourceBusy, /* stp resource busy */
72285809Sscottl} smIOStatus_t;
73285809Sscottl
74285809Sscottltypedef enum
75285809Sscottl{
76285809Sscottl  smDetailBusy,
77285809Sscottl  smDetailNotValid,
78285809Sscottl  smDetailNoLogin,
79285809Sscottl  smDetailAbortLogin,
80285809Sscottl  smDetailAbortReset,
81285809Sscottl  smDetailAborted,
82285809Sscottl  smDetailDifMismatch,
83285809Sscottl  smDetailDifAppTagMismatch,
84285809Sscottl  smDetailDifRefTagMismatch,
85285809Sscottl  smDetailDifCrcMismatch,
86285809Sscottl  smDetailDekKeyCacheMiss,
87285809Sscottl  smDetailCipherModeInvalid,
88285809Sscottl  smDetailDekIVMismatch,
89285809Sscottl  smDetailDekRamInterfaceError,
90285809Sscottl  smDetailDekIndexOutofBounds,
91285809Sscottl  smDetailOtherError
92285809Sscottl} smIOStatusDetail_t;
93285809Sscottl
94285809Sscottl/*
95285809Sscottl * Data direction for I/O request
96285809Sscottl */
97285809Sscottltypedef enum
98285809Sscottl{
99285809Sscottl  smDirectionIn   = 0x0000,
100285809Sscottl  smDirectionOut  = 0x0001
101285809Sscottl}smDataDirection_t;
102285809Sscottl
103285809Sscottl/*
104285809Sscottl * Event types for tdsmEventCB()
105285809Sscottl * do not change: Needs to be in sync with TISA API
106285809Sscottl */
107285809Sscottltypedef enum
108285809Sscottl{
109285809Sscottl  smIntrEventTypeCnxError,
110285809Sscottl  smIntrEventTypeDiscovery,
111285809Sscottl  smIntrEventTypeTransportRecovery,
112285809Sscottl  smIntrEventTypeTaskManagement,
113285809Sscottl  smIntrEventTypeDeviceChange,
114285809Sscottl  smIntrEventTypeLogin,
115285809Sscottl  smIntrEventTypeLocalAbort
116285809Sscottl} smIntrEventType_t;
117285809Sscottl
118285809Sscottltypedef enum
119285809Sscottl{
120285809Sscottl  smTMOK,
121285809Sscottl  smTMFailed
122285809Sscottl} smTMEventStatus_t;
123285809Sscottl
124285809Sscottl/*
125285809Sscottl * Flags in smSuperScsiInitiatorRequest_t
126285809Sscottl */
127285809Sscottl#define SM_SCSI_INITIATOR_DIF         0x00000001
128285809Sscottl#define SM_SCSI_INITIATOR_ENCRYPT     0x00000002
129285809Sscottl
130285809Sscottl/*
131285809Sscottl * Flags in smSuperScsiInitiatorRequest_t
132285809Sscottl */
133285809Sscottl#define SM_SCSI_TARGET_DIF         0x00000001
134285809Sscottl#define SM_SCSI_TARGET_MIRROR      0x00000002
135285809Sscottl#define SM_SCSI_TARGET_ENCRYPT     0x00000004
136285809Sscottl
137285809Sscottltypedef struct {
138285809Sscottl                void		*tdData;
139285809Sscottl                void		*smData;
140285809Sscottl} smContext_t;
141285809Sscottl
142285809Sscottl
143285809Sscottltypedef    smContext_t    smDeviceHandle_t;
144285809Sscottl
145285809Sscottltypedef    smContext_t    smIORequest_t;
146285809Sscottl
147285809Sscottltypedef    smContext_t    smRoot_t;
148285809Sscottl
149285809Sscottltypedef struct
150285809Sscottl{
151285809Sscottl	bit8  lun[8];               /* logical unit number  */
152285809Sscottl} smLUN_t;
153285809Sscottl
154285809Sscottltypedef struct{
155285809Sscottl		smLUN_t         lun;
156285809Sscottl		bit32           expDataLength;
157285809Sscottl		bit32           taskAttribute;
158285809Sscottl		bit32           crn;
159285809Sscottl		bit8            cdb[16];
160285809Sscottl} smIniScsiCmnd_t;
161285809Sscottl
162285809Sscottl
163285809Sscottl
164285809Sscottltypedef struct{
165285809Sscottl               void 	*virtPtr;
166285809Sscottl               void 	*osHandle;
167285809Sscottl               bit32 	physAddrUpper;
168285809Sscottl               bit32 	physAddrLower;
169285809Sscottl               bit32 	totalLength;
170285809Sscottl               bit32 	numElements;
171285809Sscottl               bit32 	singleElementLength;
172285809Sscottl               bit32 	alignment;
173285809Sscottl               bit32 	type;
174285809Sscottl               bit32 	reserved;
175285809Sscottl} smMem_t;
176285809Sscottl
177285809Sscottl#define SM_NUM_MEM_CHUNKS 8
178285809Sscottl
179285809Sscottltypedef struct{
180285809Sscottl               bit32            count;
181285809Sscottl               smMem_t          smMemory[SM_NUM_MEM_CHUNKS];
182285809Sscottl} smMemoryRequirement_t;
183285809Sscottl
184285809Sscottltypedef struct{
185285809Sscottl	       bit32 	lower;
186285809Sscottl	       bit32 	upper;
187285809Sscottl	       bit32 	len;
188285809Sscottl	       bit32 	type;
189285809Sscottl} smSgl_t;
190285809Sscottl
191285809Sscottl/*
192285809Sscottl * DIF operation
193285809Sscottl */
194285809Sscottl#define DIF_INSERT                     0
195285809Sscottl#define DIF_VERIFY_FORWARD             1
196285809Sscottl#define DIF_VERIFY_DELETE              2
197285809Sscottl#define DIF_VERIFY_REPLACE             3
198285809Sscottl#define DIF_VERIFY_UDT_REPLACE_CRC     5
199285809Sscottl#define DIF_REPLACE_UDT_REPLACE_CRC    7
200285809Sscottl
201285809Sscottl#define DIF_UDT_SIZE              6
202285809Sscottl
203285809Sscottltypedef struct smDif
204285809Sscottl{
205285809Sscottl  agBOOLEAN   enableDIFPerLA;
206285809Sscottl  bit32       flag;
207285809Sscottl  bit16       initialIOSeed;
208285809Sscottl  bit16       reserved;
209285809Sscottl  bit32       DIFPerLAAddrLo;
210285809Sscottl  bit32       DIFPerLAAddrHi;
211285809Sscottl  bit16       DIFPerLARegion0SecCount;
212285809Sscottl  bit16       DIFPerLANumOfRegions;
213285809Sscottl  bit8        udtArray[DIF_UDT_SIZE];
214285809Sscottl  bit8        udrtArray[DIF_UDT_SIZE];
215285809Sscottl} smDif_t;
216285809Sscottl
217285809Sscottltypedef struct smEncryptDek {
218285809Sscottl    bit32          dekTable;
219285809Sscottl    bit32          dekIndex;
220285809Sscottl} smEncryptDek_t;
221285809Sscottl
222285809Sscottltypedef struct smEncrypt {
223285809Sscottl  smEncryptDek_t     dekInfo;
224285809Sscottl  bit32          kekIndex;
225285809Sscottl  agBOOLEAN      keyTagCheck;
226285809Sscottl  agBOOLEAN  	   enableEncryptionPerLA;
227285809Sscottl  bit32          sectorSizeIndex;
228285809Sscottl  bit32          encryptMode;
229285809Sscottl  bit32          keyTag_W0;
230285809Sscottl  bit32          keyTag_W1;
231285809Sscottl  bit32          tweakVal_W0;
232285809Sscottl  bit32          tweakVal_W1;
233285809Sscottl  bit32          tweakVal_W2;
234285809Sscottl  bit32          tweakVal_W3;
235285809Sscottl  bit32          EncryptionPerLAAddrLo;
236285809Sscottl  bit32          EncryptionPerLAAddrHi;
237285809Sscottl  bit16          EncryptionPerLRegion0SecCount;
238285809Sscottl  bit16          reserved;
239285809Sscottl} smEncrypt_t;
240285809Sscottl
241285809Sscottltypedef struct smScsiInitiatorRequest {
242285809Sscottl	      void                     *sglVirtualAddr;
243285809Sscottl	      smIniScsiCmnd_t          scsiCmnd;
244285809Sscottl	      smSgl_t                  smSgl1;
245285809Sscottl	      smDataDirection_t        dataDirection;
246285809Sscottl} smScsiInitiatorRequest_t;
247285809Sscottl
248285809Sscottltypedef struct smSuperScsiInitiatorRequest
249285809Sscottl{
250285809Sscottl  void                *sglVirtualAddr;
251285809Sscottl  smIniScsiCmnd_t     scsiCmnd;
252285809Sscottl  smSgl_t             smSgl1;
253285809Sscottl  smDataDirection_t   dataDirection;
254285809Sscottl  bit32               flags; /*
255285809Sscottl                               bit 0-1: reserved
256285809Sscottl                               bit 2: enable encryption
257285809Sscottl                               bit 3: enable dif
258285809Sscottl                               bit 4-7: reserved
259285809Sscottl                               bit 8-23: DIF SKIP Bytes
260285809Sscottl                               bit 24-31: Reserved
261285809Sscottl                             */
262285809Sscottl  smDif_t             Dif;
263285809Sscottl  smEncrypt_t         Encrypt;
264285809Sscottl} smSuperScsiInitiatorRequest_t;
265285809Sscottl
266285809Sscottltypedef struct{
267285809Sscottl	       void     *senseData;
268285809Sscottl	       bit8 	senseLen;
269285809Sscottl} smSenseData_t;
270285809Sscottl
271285809Sscottltypedef struct{
272285809Sscottl               bit32			maxActiveIOs;
273285809Sscottl               bit32			numDevHandles;
274285809Sscottl#ifdef SM_DEBUG
275285809Sscottl               bit32			SMDebugLevel;
276285809Sscottl#endif
277285809Sscottl} smSwConfig_t;
278285809Sscottl
279285809Sscottl
280285809Sscottl#define smBOOLEAN  bit32
281285809Sscottl
282285809Sscottl
283285809Sscottl
284285809Sscottl
285285809Sscottl
286285809Sscottl
287285809Sscottl
288285809Sscottl
289285809Sscottl
290285809Sscottl
291285809Sscottl#endif  /* SM_H */
292285809Sscottl
293