1 /*******************************************************************************
3 *Copyright (c) 2014 PMC-Sierra, Inc. All rights reserved.
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.
11 *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
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
22 *******************************************************************************/
24 #include <dev/pms/freebsd/driver/common/osenv.h>
25 #include <dev/pms/freebsd/driver/common/ostypes.h>
26 #include <dev/pms/freebsd/driver/common/osdebug.h>
27 #include <dev/pms/freebsd/driver/ini/src/agdef.h>
28 #include <dev/pms/freebsd/driver/common/lxcommon.h>
34 #include <dev/pms/RefTisa/discovery/api/dm.h>
36 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdtypes.h>
37 #include <dev/pms/RefTisa/tisa/sassata/sas/common/tdtypes.h>
38 #include <dev/pms/RefTisa/tisa/api/titypes.h>
41 typedef u_int32_t atomic_t;
43 #define atomic_set(p,v) (*(p) = (v))
44 #define atomic_read(p) (*(p))
45 #define atomic_inc(p) atomic_add_int(p,1)
46 #define atomic_dec(p) atomic_subtract_int(p,1)
47 #define atomic_add(n,p) atomic_add_int(p,n)
48 #define atomic_sub(n,p) atomic_subtract_int(p,n)
50 #define AGSCSI_INIT_XCHG_LEN sizeof(tiScsiInitiatorRequest_t)
51 #define AGSMP_INIT_XCHG_LEN sizeof(tiSMPFrame_t)
52 #define CMND_DMA_UNMAP( pCard, cmnd )
55 // define PMC lean flags used for bit operations to track dev listing state
56 #define DPMC_LEANFLAG_NOAGDEVYT 2 // agDev handle not present yet
57 #define DPMC_LEANFLAG_NOWWNLIST 4 // WWNList entry not present
58 #define DPMC_LEANFLAG_AGDEVUSED 8 // agDev handle used
59 #define DPMC_LEANFLAG_PDEVSUSED 16 // pDevice slot used
61 typedef bus_dmamap_t dma_addr_t; // ##
63 #define timer_list callout
65 typedef struct ccb_hdr_s {
83 caddr_t pSenseData; // auto request sense data
84 tiSgl_t *sgList; // [AGTIAPI_MAX_DMA_SEGS]
85 bus_addr_t tisgl_busaddr;
86 // dma_addr_t sglDmaHandle; // ## dmaHandle for sgList
87 tiDeviceHandle_t *devHandle;
88 struct _CCB *pccbNext;
89 struct _CCB *pccbChainNext; // forward link pointers
90 struct scsi_cmnd *cmd; // call back owner pointer
91 struct _CCB *pccbIO; // for TM TARGET_RESET
93 tiIORequest_t tiIORequest;
94 tdIORequestBody_t tdIOReqBody;
95 tiSuperScsiInitiatorRequest_t tiSuperScsiRequest;
96 tiSMPFrame_t tiSMPFrame;
97 #ifdef CCBUILD_TEST_EPL
99 dma_addr_t epl_dma_ptr;
102 #ifdef CCBUILD_TEST_DPL
107 #if defined (PERF_COUNT)
108 u64 startCmnd; // temp var to hold cmnd arrival
110 #ifdef ENABLE_NONSTANDARD_SECTORS
112 dma_addr_t dmaHandleMeta;
114 #ifdef ENABLE_SATA_DIF
116 dma_addr_t dmaHandleHole;
120 #ifdef SUPER_FAST_IO_TEST
121 agsaIORequest_t IoContext;
122 agsaSASRequestBody_t sasRequestBody;
125 agsaSgl_t *sgl; // Used for esgl
128 bus_dmamap_t CCB_dmamap;
129 union ccb *ccb; /* replacement of struct scsi_cmnd */
130 struct agtiapi_softc *pmcsc;
135 #define AGTIAPI_CCB_SIZE sizeof(struct _CCB)
138 typedef struct _ag_portal_data
140 ag_portal_info_t portalInfo;
148 DEK_TABLE_INVALID = DEK_MAX_TABLES,
151 typedef struct ag_encrypt_map_s {
152 unsigned long long lbaMin;
153 unsigned long long lbaMax;
154 dek_table_e dekTable;
159 struct list_head *list;
162 typedef struct ag_kek_table_s {
163 #define KEK_TABLE_MAX_ENTRY 8
165 tiEncryptKekBlob_t kekBlob;
168 typedef struct ag_dek_kek_map_s {
173 ** There is no LUN filed for the device structure.
174 ** The reason is if the device is a single lun device, it
175 ** will be lun 0. If is a multi-lun device such as EMC
176 ** or Galaxi, only one device structure is associated with
177 ** the device since only one device handler is provided.
179 typedef struct _ag_device {
180 //#ifdef HOTPLUG_SUPPORT
181 /* used for hot-plug, temporarily either in new or removed devices list */
192 #ifdef HOTPLUG_SUPPORT
193 struct scsi_device *sdev;
195 tiDeviceHandle_t *pDevHandle;
196 tiDeviceInfo_t devInfo;
197 ag_portal_info_t *pPortalInfo;
198 U08 targetName[AGTIAPI_MAX_NAME];
206 ** Use an array of these structures to map from assigned
207 ** device target id (which is the index into the array) to
208 ** the entry in the bd_devlist.
210 ** Please note that an extra entry has been added to both
211 ** the bd_devlist array and the bd_WWN_list. This last
212 ** entry is the "no mapping" entry -- used for initialization
213 ** and to indicate an inactive entry.
215 typedef struct _ag_tgt_map {
218 U08 targetName[AGTIAPI_MAX_NAME];
221 int sasLrIdx; // Index into SAS Local/Remote list (part of extend-portID)
222 uint32_t devRemoved; // when set, ghost target device is timing out
226 // use an array of this struct to map local/remote dyads to ag_tgt_map_t
228 typedef struct _ag_slr_map {
229 U08 localeName[AGTIAPI_MIN_NAME];
230 U08 remoteName[AGTIAPI_MAX_NAME];
236 #ifdef LINUX_PERBI_SUPPORT
237 // Use a list of these structures to hold target-WWN
238 // mapping assignments on the boot line during driver
240 typedef struct _ag_mapping_s
242 struct _ag_mapping_s *next;
246 U08 targetName[AGTIAPI_MAX_NAME];
250 typedef struct _ag_portal_data
252 ag_portal_info_t portalInfo;
257 // The softc holds our per-instance data
258 struct agtiapi_softc {
260 struct cdev *my_cdev;
262 struct cam_path *path;
263 struct resource *resirq;
266 int rscID[MAX_MSIX_NUM_VECTOR];
267 struct resource *irq[MAX_MSIX_NUM_VECTOR];
268 void *intrcookie[MAX_MSIX_NUM_VECTOR];
270 // timer stuff; mc lean
271 bus_dma_tag_t buffer_dmat;
272 struct cam_devq *devq;
273 struct callout OS_timer;
274 struct mtx OS_timer_lock;
275 struct callout IO_timer;
276 struct mtx IO_timer_lock;
277 struct callout devRmTimer;
278 struct mtx devRmTimerLock;
281 // for tiSgl_t memory
283 bus_addr_t tisgl_busaddr;
284 bus_dma_tag_t tisgl_dmat;
285 bus_dmamap_t tisgl_map;
287 // for ostiAllocMemory() pre allocation pool
289 bus_addr_t osti_busaddr;
290 bus_dma_tag_t osti_dmat;
291 bus_dmamap_t osti_mapp;
293 // pre-allocation pool
294 U32 typhn; // size needed
296 bus_addr_t typh_busaddr;
297 bus_dma_tag_t typh_dmat;
298 bus_dmamap_t typh_mapp;
303 // begin ag_card_t references (AKA pCard)
304 struct Scsi_Host *pHost;
305 tiRoot_t tiRoot; // tiRoot for the card
308 U32 flags; // keep track of state
312 U08 hostNo; // host number signed by OS
313 U08 cardNo; // host no signed by driver
314 U16 tgtCount; // total target devices
315 U16 badTgtCount; // total bad target devices
316 U16 activeCCB; // number of active CCB
317 U32 ccbTotal; // total # of CCB allocated
318 U32 devDiscover; // # of device to be discovered
321 U32 portCount; // portal count
322 U32 SimQFrozen; // simq frozen state
323 U32 devq_flag; //device busy flag
324 U32 dev_scan; //device ready
325 pccb_t ccbSendHead; // CCB send list head
326 pccb_t ccbSendTail; // CCB send list tail
327 pccb_t ccbDoneHead; // CCB done list head
328 pccb_t ccbDoneTail; // CCB done list tail
329 pccb_t smpSendHead; // CCB send list head
330 pccb_t smpSendTail; // CCB send list tail
331 pccb_t smpDoneHead; // CCB done list head
332 pccb_t smpDoneTail; // CCB done list tail
333 caddr_t *ccbChainList; // ccb chain list head
334 caddr_t *ccbFreeList; // free ccb list head
335 ccb_hdr_t *ccbAllocList; // ### ccb allocation chain list head
336 struct pci_pool *sglPool; // for SGL pci_alloc_consistent
337 struct timer_list osTimerList; // card timer list
339 struct timer_list tdTimerList; // tdlayer timer list
341 struct timer_list tiTimerList; // tilayer timer list
342 ag_portal_data_t *pPortalData; // wrapper
343 ag_card_info_t *pCardInfo;
344 ag_device_t *pDevList;
346 #define CIPHER_MODE_INVALID 0xffffffffUL
347 #define DEK_INDEX_INVALID 0xffffffffUL
348 #define KEK_INDEX_INVALID 0xffffffffUL
349 int encrypt; // enable/disable encryption flag
350 bit32 dek_size; // size of dek
351 void *ioctl_data; // encryption ioctl data pointer
353 struct list_head *encrypt_map; // encryption map
354 ag_kek_table_t kek_table[KEK_TABLE_MAX_ENTRY];
356 ag_dek_kek_map_t dek_kek_map[DEK_MAX_TABLES][DEK_MAX_TABLE_ITEMS];
357 // storage for dek index in tables (sysfs)
359 #define DEK_SIZE_PLAIN 72
360 #define DEK_SIZE_ENCRYPT 80
361 #define ENCRYPTION_MAP_MEMPOOL_SIZE 64
362 char map_cache_name[32]; // name of mapping memory pool
363 struct kmem_cache *map_cache; // handle to mapping cache
364 bit32 cipher_mode; // storage of cipher mode
365 #define ENCRYPTION_IO_ERR_MEMPOOL_SIZE 256
366 struct mtx ioerr_queue_lock;
367 char ioerr_cache_name[32];
368 struct kmem_cache *ioerr_cache; // handle to IO error cache
370 //#ifdef LINUX_PERBI_SUPPORT
371 ag_tgt_map_t *pWWNList;
372 ag_slr_map_t *pSLRList; // SAS Local/Remote map list
373 U32 numTgtHardMapped; // hard mapped target number
375 struct sema *pIoctlSem; // for ioctl sync.
376 U32_64 osLockFlag; // flag for oslayer spin lock TBU
377 #ifdef AGTIAPI_LOCAL_LOCK
378 struct mtx sendLock; // local queue lock
379 struct mtx doneLock; // local queue lock
380 struct mtx sendSMPLock; // local queue lock
381 struct mtx doneSMPLock; // local queue lock
382 struct mtx ccbLock; // ccb list lock
383 struct mtx *STLock; // Low Level & TD locks
384 unsigned long *STLockFlags; // Low Level & TD locks flags
385 struct mtx memLock; // dynamic memory allocation lock
386 struct mtx freezeLock;
388 #ifdef AGTIAPI_DPC // card deferred intr process tasklet
389 struct callout tasklet_dpc[MAX_MSIX_NUM_DPC];
391 //#ifdef HOTPLUG_SUPPORT
392 struct mtx devListLock; // device lists lock
397 int agtiapi_getdevlist( struct agtiapi_softc *pCard,
398 tiIOCTLPayload_t *agIOCTLPayload );
399 int agtiapi_getCardInfo ( struct agtiapi_softc *pCard,
403 #ifndef LINUX_PERBI_SUPPORT
404 #define INDEX(_pCard, _T) (_T)
406 #define INDEX(_pCard, _T) (((_pCard)->pWWNList + (_T))->devListIndex)