1 /******************************************************************************* 2 *Copyright (c) 2014 PMC-Sierra, Inc. All rights reserved. 3 * 4 *Redistribution and use in source and binary forms, with or without modification, are permitted provided 5 *that the following conditions are met: 6 *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the 7 *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 10 *with the distribution. 11 * 12 *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED 13 *WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 14 *FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 15 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 16 *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 17 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 18 *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 19 *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 20 * 21 * 22 ********************************************************************************/ 23 #ifndef __SMTYPES_H__ 24 #define __SMTYPES_H__ 25 26 #include <dev/pms/freebsd/driver/common/osenv.h> 27 #include <dev/pms/freebsd/driver/common/ostypes.h> 28 #include <dev/pms/freebsd/driver/common/osdebug.h> 29 30 #include <dev/pms/RefTisa/sallsdk/api/sa.h> 31 #include <dev/pms/RefTisa/sallsdk/api/saapi.h> 32 #include <dev/pms/RefTisa/sallsdk/api/saosapi.h> 33 34 #include <dev/pms/RefTisa/sat/api/sm.h> 35 #include <dev/pms/RefTisa/sat/api/smapi.h> 36 #include <dev/pms/RefTisa/sat/api/tdsmapi.h> 37 38 #include <dev/pms/RefTisa/sat/src/smlist.h> 39 40 /* 41 * SAT specific structure per SATA drive 42 */ 43 #define SAT_NONNCQ_MAX 1 44 #define SAT_NCQ_MAX 32 45 #define SAT_MAX_INT_IO 16 46 #define SAT_APAPI_CMDQ_MAX 2 47 48 /* SMP direct payload size limit: IOMB direct payload size = 48 */ 49 #define SMP_DIRECT_PAYLOAD_LIMIT 44 50 51 /* timer functions ; both I and T */ 52 typedef void (*smTimerCBFunc_t)(smRoot_t *smRoot, void *timerData1, void *timerData2, void *timerData3); 53 54 55 /** \brief data structure for timer request 56 * Timer requests are enqueued and dequeued using smList_t 57 * and have a callback function 58 */ 59 typedef struct smTimerRequest_s { 60 /* the number of ticks */ 61 bit32 timeout; 62 void *timerData1; 63 void *timerData2; 64 void *timerData3; 65 smTimerCBFunc_t timerCBFunc; 66 smList_t timerLink; 67 bit32 timerRunning; 68 } smTimerRequest_t; 69 70 71 72 typedef struct smSatInternalIo_s 73 { 74 smList_t satIntIoLink; 75 smIORequest_t satIntSmIORequest; /* old satIntTiIORequest */ 76 void *satIntRequestBody; /* maps to smIOrequestBody */ 77 smScsiInitiatorRequest_t satIntSmScsiXchg; /* old satIntTiScsiXchg*/ 78 smMem_t satIntDmaMem; 79 smMem_t satIntReqBodyMem; 80 bit32 satIntFlag; 81 smIORequest_t *satOrgSmIORequest; /* old satOrgTiIORequest */ 82 bit32 id; 83 } smSatInternalIo_t; 84 85 86 87 typedef struct smDeviceData_s { 88 smList_t FreeLink; /* free dev list */ 89 smList_t MainLink; /* main(in use) dev list */ 90 bit32 id; /* for debugging only */ 91 smRoot_t *smRoot; 92 agsaDevHandle_t *agDevHandle; 93 bit32 valid; /* valid or registered */ 94 smTimerRequest_t SATAIDDeviceTimer; /* ID Device Data timer for SATA device */ 95 bit32 SMAbortAll; /* flag for abortall case */ 96 smDeviceHandle_t *smDevHandle; 97 bit32 directlyAttached; 98 agsaDevHandle_t *agExpDevHandle; /* expander a device is attached to if expander attached */ 99 bit32 phyID; 100 agsaContext_t agDeviceResetContext; /* used in saLocalPhyControl() */ 101 bit32 SMNumOfFCA; 102 103 /* from satDeviceData_t */ 104 smList_t satIoLinkList; /* Normal I/O from TISA */ 105 smList_t satFreeIntIoLinkList; /* SAT internal I/O free list */ 106 smList_t satActiveIntIoLinkList; /* SAT internal I/O active list */ 107 smSatInternalIo_t satIntIo[SAT_MAX_INT_IO]; /* Internal I/O resource */ 108 agsaSATAIdentifyData_t satIdentifyData; /* Copy of SATA Id Dev data */ 109 bit32 satNCQ; /* Flag for NCQ support */ 110 bit32 sat48BitSupport; /* Flag for 48-bit addressing */ 111 bit32 satSMARTSelfTest; /* Flag for SMART self test */ 112 bit32 satSMARTFeatureSet; /* Flag for SMART feature set */ 113 bit32 satSMARTEnabled; /* Flag for SMART enabled */ 114 bit32 satRemovableMedia; /* Flag for Removable Media */ 115 bit32 satRemovableMediaEnabled; /* Flag for Removable Media Enabled */ 116 bit32 satDMASupport; /* Flag for DMA Support */ 117 bit32 satDMAEnabled; /* Flag for DMA Enabled */ 118 bit32 satUltraDMAMode; /* Ultra DMA mode value */ 119 bit32 satDMADIRSupport; /* Flag for DMA direction */ 120 bit32 satReadLookAheadSupport; /* Flag for Read Look Ahead */ 121 bit32 satVolatileWriteCacheSupport; /* Flag for Volatile Write Cache support*/ 122 bit32 satWWNSupport; /* Flag for DMA Enabled */ 123 bit32 satDMASetupAA; /* Flag for DMA Setup Auto-Activate */ 124 bit32 satNCQQMgntCmd; /* Flag for NCQ Queue Management Command */ 125 bit32 volatile satPendingIO; /* Number of pending I/O */ 126 bit32 volatile satPendingNCQIO; /* Number of pending NCQ I/O */ 127 bit32 volatile satPendingNONNCQIO; /* Number of pending NON NCW I/O*/ 128 bit32 satNCQMaxIO; /* Max NCQ I/O in SAT or drive */ 129 bit32 satDriveState; /* State of SAT/drive */ 130 bit32 satAbortAfterReset; /* Flag: abort after SATA reset */ 131 bit32 satAbortCalled; /* Flag: abort called indication*/ 132 bit32 satVerifyState; /* Flag: Read Vrf state for diag*/ 133 bit32 satMaxUserAddrSectors; /* max user addressable setctors*/ 134 bit32 satWriteCacheEnabled; /* Flag for write cache enabled */ 135 bit32 satLookAheadEnabled; /* Flag for look ahead enabled */ 136 bit32 satDeviceFaultState; /* State of DF */ 137 bit32 satStopState; /* State of Start and Stop */ 138 bit32 satFormatState; /* State of format */ 139 bit32 satPMField; /* PM field, first 4 bits */ 140 bit8 satSignature[8]; /* Signature */ 141 bit32 satDeviceType; /* ATA device type */ 142 bit32 satSectorDone; /* Number of Sector done by Cmnd*/ 143 bit32 freeSATAFDMATagBitmap; /* SATA NCQ tag bit map */ 144 bit32 IDDeviceValid; /* ID DeviceData valid bit */ 145 bit8 satMaxLBA[8]; /* MAXLBA is from read capacity */ 146 bit32 satBGPendingDiag; /* Pending Diagnostic in backgound */ 147 bit32 NumOfFCA; /* number of SMP HARD RESET on this device */ 148 bit32 NumOfIDRetries; /* number of SMP HARD RESET after ID retries */ 149 smIORequest_t *satTmTaskTag; /* TM Task Tag */ 150 void *satSaDeviceData; /* Pointer back to sa dev data */ 151 bit32 ID_Retries; /* identify device data retries */ 152 bit32 OSAbortAll; /* OS calls abort all */ 153 bit32 ReadCapacity; /* Read Capacity Type; 10, 16 */ 154 bit32 sasAddressLo; /**< HOST SAS address lower part */ 155 bit32 sasAddressHi; /**< HOST SAS address higher part */ 156 157 } smDeviceData_t; 158 159 typedef struct smAtaPassThroughHdr_s 160 { 161 bit8 opc; 162 bit8 mulCount : 3; 163 bit8 proto : 4; 164 bit8 extend : 1; 165 bit8 offline : 2; 166 bit8 ckCond : 1; 167 bit8 tType : 1; 168 bit8 tDir : 1; 169 bit8 byteBlock : 1; 170 bit8 tlength : 2; 171 172 }smAtaPassThroughHdr_t; 173 174 /* 175 * SCSI Sense Data 176 */ 177 typedef struct 178 { 179 bit8 snsRespCode; 180 bit8 snsSegment; 181 bit8 senseKey; /* sense key */ 182 bit8 info[4]; 183 bit8 addSenseLen; /* 11 always */ 184 bit8 cmdSpecific[4]; 185 bit8 addSenseCode; /* additional sense code */ 186 bit8 senseQual; /* additional sense code qualifier */ 187 bit8 fru; 188 bit8 skeySpecific[3]; 189 } smScsiRspSense_t; 190 191 192 /* 193 * SATA SAT specific function pointer for SATA completion for SAT commands. 194 */ 195 typedef void (*smSatCompleteCbPtr_t )( 196 agsaRoot_t *agRoot, 197 agsaIORequest_t *agIORequest, 198 bit32 agIOStatus, 199 agsaFisHeader_t *agFirstDword, 200 bit32 agIOInfoLen, 201 agsaFrameHandle_t agFrameHandle, 202 void *satIOContext 203 ); 204 205 /* for SMP only */ 206 typedef void (*smSMPCompleted_t)( 207 agsaRoot_t *, 208 agsaIORequest_t *, 209 bit32 , 210 bit32 , 211 agsaFrameHandle_t 212 ); 213 214 215 /* 216 * SATA SAT specific function for I/O context 217 */ 218 typedef struct smSatIOContext_s 219 { 220 smList_t satIoContextLink; 221 smDeviceData_t *pSatDevData; 222 agsaFisRegHostToDevice_t *pFis; 223 smIniScsiCmnd_t *pScsiCmnd; 224 smScsiRspSense_t *pSense; 225 smSenseData_t *pSmSenseData; /* old pTiSenseData */ 226 void *smRequestBody; /* smIORequestBody_t; old tiRequestBody*/ 227 void *smScsiXchg; /* for writesame10(); old tiScsiXchg */ 228 bit32 reqType; 229 bit32 interruptContext; 230 smSatCompleteCbPtr_t satCompleteCB; 231 smSatInternalIo_t *satIntIoContext; /* SATM generated IOs */ 232 smDeviceHandle_t *psmDeviceHandle; /* old ptiDeviceHandle */ 233 bit8 sataTag; 234 bit8 superIOFlag;/* Flag indicating type for smScsiXchg */ 235 bit8 reserved1; /* Padding for allignment */ 236 bit8 reserved2; /* Padding for allignment */ 237 bit32 currentLBA; /* current LBA for read and write */ 238 bit32 ATACmd; /* ATA command */ 239 bit32 OrgTL; /* original tranfer length(tl) */ 240 bit32 LoopNum; /* denominator tl */ 241 bit32 LoopNum2; /* denominator tl */ 242 bit8 LBA[8]; /* for reassign blocks; current LBA */ 243 bit32 ParmIndex; /* for reassign blocks;current idx in defective LBA LIST */ 244 bit32 ParmLen; /* for reassign blocks; defective LBA list length */ 245 bit32 NotifyOS; /* only for task management */ 246 bit32 TMF; /* task management function */ 247 struct smSatIOContext_s *satToBeAbortedIOContext; 248 struct smSatIOContext_s *satOrgIOContext; 249 bit32 UpperAddr; 250 bit32 LowerAddr; 251 bit32 SplitIdx; 252 bit32 AdjustBytes; 253 bit32 EsglLen; 254 /* For the SAT Passthrough */ 255 bit8 ck_cond; 256 bit8 extend; 257 bit8 sectorCnt07; 258 bit8 LBAHigh07; 259 bit8 LBAMid07; 260 bit8 LBALow07; 261 bit8 Sector_Cnt_Upper_Nonzero; 262 bit8 LBA_Upper_Nonzero; 263 bit32 pid; /* port id; used to protect double completion */ 264 bit32 id; /* for debugging */ 265 } smSatIOContext_t; 266 267 typedef struct smIORequestBody_s { 268 smList_t satIoBodyLink; 269 smDeviceHandle_t *smDevHandle; 270 smIORequest_t *smIORequest; 271 agsaIORequest_t agIORequest; 272 smIORequest_t *smIOToBeAbortedRequest; /* IO to be aborted; old tiIOToBeAbortedRequest */ 273 bit32 id; 274 bit32 InUse; 275 union { 276 struct { 277 agsaSATAInitiatorRequest_t agSATARequestBody; 278 smScsiRspSense_t sensePayload; 279 smSenseData_t smSenseData; /* old tiSenseData */ 280 smSatIOContext_t satIOContext; 281 } SATA; 282 } transport; 283 bit32 ioStarted; 284 bit32 ioCompleted; 285 bit32 reTries; 286 union { 287 struct { 288 bit32 expDataLength; 289 smSgl_t smSgl1; /* old tiSgl1 */ 290 smSgl_t smSgl2; /* old tiSgl2 */ 291 void *sglVirtualAddr; 292 } InitiatorRegIO; /* regular IO */ 293 struct { 294 void *osMemHandle; 295 smIORequest_t *CurrentTaskTag; 296 smIORequest_t *TaskTag; 297 } InitiatorTMIO; /* task management */ 298 } IOType; 299 300 } smIORequestBody_t; 301 302 typedef struct smSMPRequestBody_s { 303 smSMPCompleted_t SMPCompletionFunc;/* must be the second */ 304 305 smDeviceHandle_t *smDevHandle; /* not used for SM generated SMP */ 306 agsaIORequest_t agIORequest; 307 agsaSASRequestBody_t agSASRequestBody; 308 void *osMemHandle; 309 smDeviceData_t *smDeviceData; 310 smIORequest_t *CurrentTaskTag; /* SMP is used for simulate target reset */ 311 // tdsaPortContext_t *tdPortContext; /* portcontext where SMP is sent from */ 312 bit8 smpPayload[SMP_DIRECT_PAYLOAD_LIMIT]; /* for smp retries; 313 only for direct SMP */ 314 bit32 retries; /* number of retries */ 315 316 } smSMPRequestBody_t; 317 318 319 typedef struct smRootOsData_s { 320 smRoot_t *smRoot; /**< Pointer back to smRoot */ 321 void *smAllShared; /**< Pointer to smIntContext_t */ 322 void *smIni; /**< Pointer to SAS/SATA initiator */ 323 } smRootOsData_t; 324 325 typedef struct smIntContext_s { 326 /**< agsaRoot_t->osData points to this */ 327 struct smRootOsData_s smRootOsData; 328 329 bit32 usecsPerTick; 330 agsaRoot_t *agRoot; 331 332 /**< software-related initialization params used in saInitialize() */ 333 smSwConfig_t SwConfig; 334 335 /**< timers used commonly in SAS/SATA */ 336 smList_t timerlist; 337 338 /**< pointer to Device memory */ 339 smDeviceData_t *DeviceMem; 340 smList_t FreeDeviceList; 341 smList_t MainDeviceList; 342 343 /**< pointer to IO memory */ 344 smIORequestBody_t *IOMem; 345 smList_t freeIOList; 346 smList_t mainIOList; 347 bit32 FCA; 348 } smIntContext_t; 349 350 typedef struct smIntRoot_s 351 { 352 /**<< common data structure for SAS/SATA */ 353 smIntContext_t smAllShared; 354 } smIntRoot_t; 355 356 357 #endif /* __SMTYPES_H__ */ 358 359