xref: /freebsd/sys/dev/pms/freebsd/driver/ini/src/agtiapi.h (revision 61e21613)
1 /*******************************************************************************
2 **
3 *Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
4 *
5 *Redistribution and use in source and binary forms, with or without modification, are permitted provided
6 *that the following conditions are met:
7 *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 *2. Redistributions in binary form must reproduce the above copyright notice,
9 *this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10 *
11 *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
12 *
13 *INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
14 *ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
15 *SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
16 *OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
17 *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
18 *THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
19 **
20 **
21 *******************************************************************************/
22 
23 #include <dev/pms/freebsd/driver/common/osenv.h>
24 #include <dev/pms/freebsd/driver/common/ostypes.h>
25 #include <dev/pms/freebsd/driver/common/osdebug.h>
26 #include <dev/pms/freebsd/driver/ini/src/agdef.h>
27 #include <dev/pms/freebsd/driver/common/lxcommon.h>
28 #ifdef AGTIAPI_ISCSI
29 #include "cmtypes.h"
30 #include "bktypes.h"
31 #endif
32 #ifdef FDS_DM
33 #include <dev/pms/RefTisa/discovery/api/dm.h>
34 #endif
35 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdtypes.h>
36 #include <dev/pms/RefTisa/tisa/sassata/sas/common/tdtypes.h>
37 #include <dev/pms/RefTisa/tisa/api/titypes.h>
38 #include <vm/uma.h>
39 
40 typedef u_int32_t atomic_t;
41 
42 #define atomic_set(p,v)		(*(p) = (v))
43 #define atomic_read(p)		(*(p))
44 #define atomic_inc(p)		atomic_add_int(p,1)
45 #define atomic_dec(p)		atomic_subtract_int(p,1)
46 #define atomic_add(n,p)		atomic_add_int(p,n)
47 #define atomic_sub(n,p)		atomic_subtract_int(p,n)
48 
49 #define AGSCSI_INIT_XCHG_LEN  sizeof(tiScsiInitiatorRequest_t)
50 #define AGSMP_INIT_XCHG_LEN   sizeof(tiSMPFrame_t)
51 #define CMND_DMA_UNMAP( pCard, cmnd )
52 
53 
54 // define PMC lean flags used for bit operations to track dev listing state
55 #define DPMC_LEANFLAG_NOAGDEVYT     2  // agDev handle not present yet
56 #define DPMC_LEANFLAG_NOWWNLIST     4  // WWNList entry not present
57 #define DPMC_LEANFLAG_AGDEVUSED     8  // agDev handle used
58 #define DPMC_LEANFLAG_PDEVSUSED    16  // pDevice slot used
59 
60 typedef bus_dmamap_t dma_addr_t; // ##
61 
62 #define timer_list callout
63 
64 typedef struct ccb_hdr_s {
65   void *next;
66 } ccb_hdr_t;
67 
68 
69 typedef struct _CCB {
70   U32               targetId;
71   U32               lun;
72   U32               channel;
73   U16               ccbStatus;
74   U16               scsiStatus;
75   U32               dataLen;
76   U08               senseLen;
77   U08               addrMode;
78   U08               retryCount;
79   U16               numSgElements;
80   U32               flags;
81   U32_64            dmaHandle;
82   caddr_t           pSenseData;   // auto request sense data
83   tiSgl_t          *sgList;           // [AGTIAPI_MAX_DMA_SEGS]
84   bus_addr_t        tisgl_busaddr;
85   //  dma_addr_t        sglDmaHandle;      // ## dmaHandle for sgList
86   tiDeviceHandle_t *devHandle;
87   struct _CCB      *pccbNext;
88   struct _CCB      *pccbChainNext;    // forward link pointers
89   struct scsi_cmnd *cmd;              // call back owner pointer
90   struct _CCB      *pccbIO;           // for TM TARGET_RESET
91   U32_64            startTime;
92   tiIORequest_t     tiIORequest;
93   tdIORequestBody_t tdIOReqBody;
94   tiSuperScsiInitiatorRequest_t tiSuperScsiRequest;
95   tiSMPFrame_t 		  tiSMPFrame;
96 #ifdef CCBUILD_TEST_EPL
97   caddr_t           epl_ptr;
98   dma_addr_t        epl_dma_ptr;
99 #endif
100 
101 #ifdef CCBUILD_TEST_DPL
102   caddr_t           dplPtr;
103   dma_addr_t        dplDma;
104 #endif
105 
106 #if defined (PERF_COUNT)
107   u64               startCmnd;         // temp var to hold cmnd arrival
108 #endif
109 #ifdef ENABLE_NONSTANDARD_SECTORS
110   caddr_t           metaPtr;
111   dma_addr_t        dmaHandleMeta;
112 #endif
113 #ifdef ENABLE_SATA_DIF
114   caddr_t           holePtr;
115   dma_addr_t        dmaHandleHole;
116   int               scaling_done;
117 #endif
118 
119 #ifdef SUPER_FAST_IO_TEST
120   agsaIORequest_t      IoContext;
121   agsaSASRequestBody_t sasRequestBody;
122   u32                  reqType;
123   u32                  queueId;
124   agsaSgl_t           *sgl; // Used for esgl
125 #endif
126   //new
127   bus_dmamap_t	        CCB_dmamap;
128   union ccb           *ccb; /* replacement of struct scsi_cmnd */
129   struct agtiapi_softc *pmcsc;
130 
131 } ccb_t, *pccb_t;
132 
133 
134 #define AGTIAPI_CCB_SIZE  sizeof(struct _CCB)
135 
136 /*
137 typedef struct _ag_portal_data
138 {
139   ag_portal_info_t    portalInfo;
140   void                *pCard;
141 } ag_portal_data_t;
142 */
143 
144 typedef enum {
145 	DEK_TABLE_0 = 0,
146 	DEK_TABLE_1 = 1,
147 	DEK_TABLE_INVALID = DEK_MAX_TABLES,
148      } dek_table_e;
149 
150 typedef struct ag_encrypt_map_s {
151 	unsigned long long lbaMin;
152 	unsigned long long lbaMax;
153 	dek_table_e        dekTable;
154 	bit32	     	   dekIndex;
155 	bit32		   kekIndex;
156 	bit32		   kekTagCheck;
157 	bit32		   kekTag[2];
158 	struct list_head   *list;
159     } ag_encrypt_map_t;
160 
161 typedef struct ag_kek_table_s {
162  #define KEK_TABLE_MAX_ENTRY  8
163 	bit32		   wrapperIndex;
164 	tiEncryptKekBlob_t kekBlob;
165    } ag_kek_table_t;
166 
167 typedef struct ag_dek_kek_map_s {
168 	bit32   	  kekIndex;
169    } ag_dek_kek_map_t;
170 
171 /*
172 ** There is no LUN filed for the device structure.
173 ** The reason is if the device is a single lun device, it
174 ** will be lun 0.  If is a multi-lun device such as EMC
175 ** or Galaxi, only one device structure is associated with
176 ** the device since only one device handler is provided.
177 */
178 typedef struct _ag_device {
179 //#ifdef HOTPLUG_SUPPORT
180   /* used for hot-plug, temporarily either in new or removed devices list */
181   LINK_NODE           devLink;
182 //#endif
183   U32                 targetId;
184   U32                 flags;
185   U16                 devType;
186   U16                 resetCount;
187   U32                 portalId;
188   void               *pCard;
189   U32                 sector_size;
190   U32		      CCBCount;
191 #ifdef HOTPLUG_SUPPORT
192   struct scsi_device *sdev;
193 #endif
194   tiDeviceHandle_t   *pDevHandle;
195   tiDeviceInfo_t      devInfo;
196   ag_portal_info_t   *pPortalInfo;
197   U08                 targetName[AGTIAPI_MAX_NAME];
198   U16                 targetLen;
199   U32		          qbusy;
200   U32		          qdepth;
201 } ag_device_t;
202 
203 
204 /*
205 ** Use an array of these structures to map from assigned
206 ** device target id (which is the index into the array) to
207 ** the entry in the bd_devlist.
208 **
209 ** Please note that an extra entry has been added to both
210 ** the bd_devlist array and the bd_WWN_list.  This last
211 ** entry is the "no mapping" entry -- used for initialization
212 ** and to indicate an inactive entry.
213 */
214 typedef struct _ag_tgt_map {
215   U16      devListIndex;
216   U16      flags;
217   U08      targetName[AGTIAPI_MAX_NAME];
218   U16      targetLen;
219   U08      portId;
220   int      sasLrIdx; // Index into SAS Local/Remote list (part of extend-portID)
221   uint32_t devRemoved; // when set, ghost target device is timing out
222 } ag_tgt_map_t;
223 
224 
225 // use an array of this struct to map local/remote dyads to ag_tgt_map_t
226 // entries
227 typedef struct _ag_slr_map {
228   U08  localeName[AGTIAPI_MIN_NAME];
229   U08  remoteName[AGTIAPI_MAX_NAME];
230   int  localeNameLen;
231   int  remoteNameLen;
232 } ag_slr_map_t;
233 
234 
235 #ifdef LINUX_PERBI_SUPPORT
236 // Use a list of these structures to hold target-WWN
237 // mapping assignments on the boot line during driver
238 // loading.
239 typedef struct _ag_mapping_s
240 {
241   struct _ag_mapping_s *next;
242   U16                   targetId;
243   U08                   cardNo;
244   U08                   targetLen;
245   U08                   targetName[AGTIAPI_MAX_NAME];
246 } ag_mapping_t;
247 #endif
248 
249 typedef struct _ag_portal_data
250 {
251   ag_portal_info_t    portalInfo;
252   void               *pCard;
253 } ag_portal_data_t;
254 
255 
256 // The softc holds our per-instance data
257 struct agtiapi_softc {
258   device_t            my_dev;
259   struct cdev        *my_cdev;
260   struct cam_sim     *sim;
261   struct cam_path    *path;
262   struct resource    *resirq;
263   void               *intr_cookie;
264 
265   int                 rscID[MAX_MSIX_NUM_VECTOR];
266   struct resource    *irq[MAX_MSIX_NUM_VECTOR];
267   void               *intrcookie[MAX_MSIX_NUM_VECTOR];
268 
269   // timer stuff; mc lean
270   bus_dma_tag_t       buffer_dmat;
271   struct cam_devq    *devq;
272   struct callout      OS_timer;
273   struct mtx          OS_timer_lock;
274   struct callout      IO_timer;
275   struct mtx          IO_timer_lock;
276   struct callout      devRmTimer;
277   struct mtx          devRmTimerLock;
278   uint16_t            rmChkCt;
279 
280   // for tiSgl_t memory
281   tiSgl_t            *tisgl_mem;
282   bus_addr_t          tisgl_busaddr;
283   bus_dma_tag_t       tisgl_dmat;
284   bus_dmamap_t        tisgl_map;
285 
286   // for ostiAllocMemory() pre allocation pool
287   void               *osti_mem;
288   bus_addr_t          osti_busaddr;
289   bus_dma_tag_t       osti_dmat;
290   bus_dmamap_t        osti_mapp;
291 
292   // pre-allocation pool
293   U32                 typhn; // size needed
294   void               *typh_mem;
295   bus_addr_t          typh_busaddr;
296   bus_dma_tag_t       typh_dmat;
297   bus_dmamap_t        typh_mapp;
298   U32                 typhIdx;
299   U32                 tyPhsIx;
300 
301 
302   // begin ag_card_t references (AKA pCard)
303   struct Scsi_Host   *pHost;
304   tiRoot_t            tiRoot;             // tiRoot for the card
305   U32                 VidDid;
306   U32                 SVID_SSID;
307   U32                 flags;              // keep track of state
308   U32                 freezeSim;
309   U32                 up_count;
310   U32                 down_count;
311   U08                 hostNo;             // host number signed by OS
312   U08                 cardNo;             // host no signed by driver
313   U16                 tgtCount;           // total target devices
314   U16                 badTgtCount;        // total bad target devices
315   U16                 activeCCB;          // number of active CCB
316   U32                 ccbTotal;           // total # of CCB allocated
317   U32                 devDiscover;        // # of device to be discovered
318   U32                 resetCount;
319   U32                 timeoutTicks;
320   U32                 portCount;          // portal count
321   U32                 SimQFrozen;         // simq frozen state
322   U32                 devq_flag;      //device busy flag
323   U32                 dev_scan;           //device ready
324   pccb_t              ccbSendHead;        // CCB send list head
325   pccb_t              ccbSendTail;        // CCB send list tail
326   pccb_t              ccbDoneHead;        // CCB done list head
327   pccb_t              ccbDoneTail;        // CCB done list tail
328   pccb_t              smpSendHead;        // CCB send list head
329   pccb_t              smpSendTail;        // CCB send list tail
330   pccb_t              smpDoneHead;        // CCB done list head
331   pccb_t              smpDoneTail;        // CCB done list tail
332   caddr_t            *ccbChainList;       // ccb chain list head
333   caddr_t            *ccbFreeList;        // free ccb list head
334   ccb_hdr_t          *ccbAllocList;       // ### ccb allocation chain list head
335   struct pci_pool    *sglPool;            // for SGL pci_alloc_consistent
336   struct timer_list   osTimerList;        // card timer list
337 #ifdef TD_TIMER
338   struct timer_list   tdTimerList;        // tdlayer timer list
339 #endif
340   struct timer_list   tiTimerList;        // tilayer timer list
341   ag_portal_data_t   *pPortalData;        // wrapper
342   ag_card_info_t     *pCardInfo;
343   ag_device_t        *pDevList;
344 
345 #define CIPHER_MODE_INVALID 0xffffffffUL
346 #define DEK_INDEX_INVALID   0xffffffffUL
347 #define KEK_INDEX_INVALID   0xffffffffUL
348   int                 encrypt;            // enable/disable encryption flag
349   bit32               dek_size;           // size of dek
350   void               *ioctl_data;         // encryption ioctl data pointer
351 
352   struct list_head   *encrypt_map;        // encryption map
353   ag_kek_table_t      kek_table[KEK_TABLE_MAX_ENTRY];
354   // KEK table
355   ag_dek_kek_map_t    dek_kek_map[DEK_MAX_TABLES][DEK_MAX_TABLE_ITEMS];
356   // storage for dek index in tables (sysfs)
357   int                 dek_index[2];
358 #define DEK_SIZE_PLAIN   72
359 #define DEK_SIZE_ENCRYPT 80
360 #define ENCRYPTION_MAP_MEMPOOL_SIZE 64
361   char                map_cache_name[32]; // name of mapping memory pool
362   struct kmem_cache  *map_cache;          // handle to mapping cache
363   bit32               cipher_mode;        // storage of cipher mode
364 #define ENCRYPTION_IO_ERR_MEMPOOL_SIZE 256
365   struct mtx          ioerr_queue_lock;
366   char                ioerr_cache_name[32];
367   struct kmem_cache  *ioerr_cache;        // handle to IO error cache
368 
369 //#ifdef LINUX_PERBI_SUPPORT
370   ag_tgt_map_t       *pWWNList;
371   ag_slr_map_t       *pSLRList;           // SAS Local/Remote map list
372   U32                 numTgtHardMapped;   // hard mapped target number
373 //#endif
374   struct sema  		 *pIoctlSem;         // for ioctl sync.
375   U32_64              osLockFlag;         // flag for oslayer spin lock TBU
376 #ifdef AGTIAPI_LOCAL_LOCK
377   struct mtx          sendLock;           // local queue lock
378   struct mtx          doneLock;           // local queue lock
379   struct mtx          sendSMPLock;        // local queue lock
380   struct mtx          doneSMPLock;        // local queue lock
381   struct mtx          ccbLock;            // ccb list lock
382   struct mtx         *STLock;             // Low Level & TD locks
383   unsigned long      *STLockFlags;        // Low Level & TD locks flags
384   struct mtx          memLock;            // dynamic memory allocation lock
385   struct mtx          freezeLock;
386 #endif
387 #ifdef AGTIAPI_DPC                        // card deferred intr process tasklet
388   struct callout      tasklet_dpc[MAX_MSIX_NUM_DPC];
389 #endif
390 //#ifdef HOTPLUG_SUPPORT
391   struct mtx          devListLock;        // device lists lock
392 //#endif
393 
394 };
395 
396 int agtiapi_getdevlist( struct agtiapi_softc *pCard,
397                         tiIOCTLPayload_t *agIOCTLPayload );
398 int agtiapi_getCardInfo ( struct agtiapi_softc      *pCard,
399                           U32_64			size,
400                           void			      *buffer );
401 
402 #ifndef LINUX_PERBI_SUPPORT
403 #define INDEX(_pCard, _T)   (_T)
404 #else
405 #define INDEX(_pCard, _T)   (((_pCard)->pWWNList + (_T))->devListIndex)
406 #endif
407 
408