xref: /freebsd/sys/dev/pms/RefTisa/tisa/api/ostiapi.h (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
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 /********************************************************************************
24 **
25 ** Version Control Information:
26 **
27 **
28 *******************************************************************************/
29 /********************************************************************************
30 **
31 **   ostiapi.h
32 **
33 **   Abstract:   This module contains function prototype of the Transport
34 **               Independent (TIAPI) OS Callback interface.
35 **
36 ********************************************************************************/
37 
38 #ifndef OSTIAPI_H
39 
40 #define OSTIAPI_H
41 
42 /*
43  * Definition for return status is defined in tiStatus_t in TIDEFS.H
44  */
45 
46 /*****************************************************************************
47  *  Initiator/Target Shared Callbacks
48  *****************************************************************************/
49 
50 osGLOBAL bit32 ostiGetTransportParam(
51                         tiRoot_t    *tiRoot,
52                         char        *key,
53                         char        *subkey1,
54                         char        *subkey2,
55                         char        *subkey3,
56                         char        *subkey4,
57                         char        *subkey5,
58                         char        *valueName,
59                         char        *buffer,
60                         bit32       bufferLen,
61                         bit32       *lenReceived
62                         );
63 
64 osGLOBAL void  ostiPortEvent(
65                         tiRoot_t      *tiRoot,
66                         tiPortEvent_t eventType,
67                         bit32         status,
68                         void          *pParm
69                         );
70 
71 osGLOBAL bit32  ostiTimeStamp( tiRoot_t  *tiRoot);
72 osGLOBAL bit64  ostiTimeStamp64( tiRoot_t  *tiRoot);
73 
74 osGLOBAL FORCEINLINE bit32 ostiChipConfigReadBit32(
75                         tiRoot_t      *tiRoot,
76                         bit32         chipConfigOffset
77                         );
78 
79 osGLOBAL FORCEINLINE void ostiChipConfigWriteBit32(
80                         tiRoot_t      *tiRoot,
81                         bit32         chipConfigOffset,
82                         bit32         chipConfigValue
83                         );
84 
85 osGLOBAL FORCEINLINE bit32 ostiChipReadBit32(
86                         tiRoot_t      *tiRoot,
87                         bit32         chipOffset
88                         );
89 
90 osGLOBAL FORCEINLINE void ostiChipWriteBit32(
91                         tiRoot_t      *tiRoot,
92                         bit32         chipOffset,
93                         bit32         chipValue
94                         );
95 
96 osGLOBAL FORCEINLINE bit8 ostiChipReadBit8(
97                         tiRoot_t      *tiRoot,
98                         bit32         chipOffset
99                         );
100 
101 osGLOBAL FORCEINLINE void ostiChipWriteBit8(
102                         tiRoot_t      *tiRoot,
103                         bit32         chipOffset,
104                         bit8          chipValue
105                         );
106 
107 osGLOBAL void ostiFlashReadBlock(
108                         tiRoot_t      *tiRoot,
109                         bit32         flashOffset,
110                         void          *buffer,
111                         bit32         bufferLen
112                         );
113 
114 osGLOBAL FORCEINLINE
115 tiDeviceHandle_t*
116 ostiGetDevHandleFromSasAddr(
117   tiRoot_t    *root,
118   unsigned char *sas_addr
119 );
120 
121 osGLOBAL FORCEINLINE void ostidisableEncryption(tiRoot_t *root);
122 
123 osGLOBAL FORCEINLINE void ostiSingleThreadedEnter(
124                         tiRoot_t      *tiRoot,
125                         bit32         queueId
126                         );
127 
128 osGLOBAL FORCEINLINE void ostiSingleThreadedLeave(
129                         tiRoot_t      *tiRoot,
130                         bit32         queueId
131                         );
132 
133 
134 osGLOBAL bit32 ostiNumOfLUNIOCTLreq(tiRoot_t           *root,
135 									void               *param1,
136                                     void               *param2,
137                                     void                           **tiRequestBody,
138                                     tiIORequest_t          **tiIORequest
139                                     );
140 
141 #ifdef PERF_COUNT
142 osGLOBAL void ostiEnter(tiRoot_t *ptiRoot, bit32 layer, int io);
143 osGLOBAL void ostiLeave(tiRoot_t *ptiRoot, bit32 layer, int io);
144 #define OSTI_INP_ENTER(root) ostiEnter(root, 2, 0)
145 #define OSTI_INP_LEAVE(root) ostiLeave(root, 2, 0)
146 #define OSTI_OUT_ENTER(root) ostiEnter(root, 2, 1)
147 #define OSTI_OUT_LEAVE(root) ostiLeave(root, 2, 1)
148 #else
149 #define OSTI_INP_ENTER(root)
150 #define OSTI_INP_LEAVE(root)
151 #define OSTI_OUT_ENTER(root)
152 #define OSTI_OUT_LEAVE(root)
153 #endif
154 
155 osGLOBAL void  ostiStallThread(
156                         tiRoot_t      *tiRoot,
157                         bit32         microseconds
158                         );
159 
160 osGLOBAL FORCEINLINE bit8
161 ostiBitScanForward(
162                   tiRoot_t   *root,
163                   bit32      *Index,
164                   bit32       Mask
165                   );
166 
167 #ifdef LINUX_VERSION_CODE
168 
169 osGLOBAL sbit32
170 ostiAtomicIncrement(
171                    tiRoot_t        *root,
172                    sbit32 volatile *Addend
173                    );
174 
175 osGLOBAL sbit32
176 ostiAtomicDecrement(
177                    tiRoot_t        *root,
178                    sbit32 volatile *Addend
179                    );
180 
181 
182 osGLOBAL sbit32
183 ostiAtomicBitClear(
184                    tiRoot_t          *root,
185                    sbit32 volatile   *Destination,
186                    sbit32             Value
187                    );
188 
189 osGLOBAL sbit32
190 ostiAtomicBitSet(
191                    tiRoot_t          *root,
192                    sbit32 volatile   *Destination,
193                    sbit32             Value
194                    );
195 
196 osGLOBAL sbit32
197 ostiAtomicExchange(
198                    tiRoot_t         *root,
199                    sbit32 volatile  *Target,
200                    sbit32            Value
201                    );
202 
203 #else
204 
205 osGLOBAL FORCEINLINE sbit32
206 ostiInterlockedIncrement(
207                    tiRoot_t        *root,
208                    sbit32 volatile *Addend
209                    );
210 
211 osGLOBAL FORCEINLINE sbit32
212 ostiInterlockedDecrement(
213                    tiRoot_t         *root,
214                    sbit32 volatile  *Addend
215                    );
216 
217 
218 osGLOBAL FORCEINLINE sbit32
219 ostiInterlockedAnd(
220                    tiRoot_t         *root,
221                    sbit32 volatile  *Destination,
222                    sbit32            Value
223                    );
224 
225 osGLOBAL FORCEINLINE sbit32
226 ostiInterlockedOr(
227                    tiRoot_t         *root,
228                    sbit32 volatile  *Destination,
229                    sbit32            Value
230                    );
231 
232 osGLOBAL FORCEINLINE sbit32
233 ostiInterlockedExchange(
234                    tiRoot_t        *root,
235                    sbit32 volatile *Target,
236                    sbit32           Value
237                    );
238 #endif /*LINUX_VERSION_CODE*/
239 
240 osGLOBAL bit32 ostiAllocMemory(
241                         tiRoot_t    *tiRoot,
242                         void        **osMemHandle,
243                         void        ** virtPtr,
244                         bit32       * physAddrUpper,
245                         bit32       * physAddrLower,
246                         bit32       alignment,
247                         bit32       allocLength,
248                         agBOOLEAN   isCacheable
249                         );
250 
251 osGLOBAL bit32 ostiFreeMemory(
252                         tiRoot_t    *tiRoot,
253                         void        *osDMAHandle,
254                         bit32       allocLength
255                         );
256 
257 osGLOBAL FORCEINLINE void ostiCacheFlush(
258                         tiRoot_t    *tiRoot,
259                         void        *osMemHandle,
260                         void        *virtPtr,
261                         bit32       length
262                         );
263 
264 osGLOBAL FORCEINLINE void ostiCacheInvalidate(
265                         tiRoot_t    *tiRoot,
266                         void        *osMemHandle,
267                         void        *virtPtr,
268                         bit32       length
269                         );
270 
271 osGLOBAL FORCEINLINE void ostiCachePreFlush(
272                         tiRoot_t    *tiRoot,
273                         void        *osMemHandle,
274                         void        *virtPtr,
275                         bit32       length
276                         );
277 
278 /*
279  *  The following two functions are for SAS/SATA
280  */
281 osGLOBAL void
282 ostiInterruptEnable(
283                         tiRoot_t  *ptiRoot,
284                         bit32     channelNum
285                         );
286 
287 osGLOBAL void
288 ostiInterruptDisable(
289                        tiRoot_t  *ptiRoot,
290                        bit32     channelNum
291                        );
292 
293 osGLOBAL FORCEINLINE bit32
294 ostiChipReadBit32Ext(
295                         tiRoot_t  *tiRoot,
296                         bit32     busBaseNumber,
297                         bit32     chipOffset
298                         );
299 
300 osGLOBAL FORCEINLINE void
301 ostiChipWriteBit32Ext(
302                         tiRoot_t  *tiRoot,
303                         bit32     busBaseNumber,
304                         bit32     chipOffset,
305                         bit32     chipValue
306                         );
307 
308 
309 /*****************************************************************************
310  *  Initiator specific Callbacks
311  *****************************************************************************/
312 
313 /*
314  * Initiator specific IO Completion
315  */
316 osGLOBAL void ostiInitiatorIOCompleted(
317                         tiRoot_t            *tiRoot,
318                         tiIORequest_t       *tiIORequest,
319                         tiIOStatus_t        status,
320                         bit32               statusDetail,
321                         tiSenseData_t       *senseData,
322                         bit32               context
323                         );
324 
325 osGLOBAL tiDeviceHandle_t*
326 ostiMapToDevHandle(tiRoot_t  *root,
327                           bit8      pathId,
328                           bit8      targetId,
329                           bit8      LUN
330                           );
331 osGLOBAL bit32 ostiSendResetDeviceIoctl(tiRoot_t *root,
332 			  void *pccb,
333 			  bit8 pathId,
334   			  bit8 targetId,
335 			  bit8 lun,
336 			  unsigned long resetType
337 			);
338 
339 osGLOBAL void
340 ostiGetSenseKeyCount(tiRoot_t  *root,
341                             bit32      fIsClear,
342                             void      *SenseKeyCount,
343                             bit32      length
344                             );
345 
346 osGLOBAL void
347 ostiGetSCSIStatusCount(tiRoot_t  *root,
348                             bit32      fIsClear,
349                             void      *ScsiStatusCount,
350                             bit32      length
351                             );
352 
353 osGLOBAL bit32
354 ostiSetDeviceQueueDepth(tiRoot_t       *tiRoot,
355                                 tiIORequest_t  *tiIORequest,
356                                 bit32           QueueDepth
357                                 );
358 
359 
360 #ifdef FAST_IO_TEST
361 typedef void (*ostiFastSSPCb_t)(tiRoot_t     *ptiRoot,
362                                  void         *arg,
363                                  tiIOStatus_t IOStatus,
364                                  bit32         statusDetail);
365 
366 void osti_FastIOCb(tiRoot_t     *ptiRoot,
367                    void         *arg,
368                    tiIOStatus_t IOStatus,
369                    bit32        statusDetail);
370 #endif
371 
372 osGLOBAL void
373 ostiInitiatorSMPCompleted(tiRoot_t    *tiRoot,
374                tiIORequest_t  *tiSMPRequest,
375                tiSMPStatus_t  smpStatus,
376                bit32          tiSMPInfoLen,
377                void           *tiFrameHandle,
378                bit32          context);
379 /*
380  * Initiator specific event
381  */
382 osGLOBAL void ostiInitiatorEvent (
383                         tiRoot_t            *tiRoot,
384                         tiPortalContext_t   *portalContext,
385                         tiDeviceHandle_t    *tiDeviceHandle,
386                         tiIntrEventType_t   eventType,
387                         bit32               eventStatus,
388                         void                *parm
389                         );
390 
391 
392 /*
393  * PMC-Sierra IOCTL semaphoring
394  */
395 osGLOBAL void ostiIOCTLClearSignal (
396                         tiRoot_t    *tiRoot,
397                         void        **agParam1,
398                         void        **agParam2,
399                         void        **agParam3
400                         );
401 
402 osGLOBAL void ostiIOCTLWaitForSignal (
403                         tiRoot_t    *tigRoot,
404                         void        *agParam1,
405                         void        *agParam2,
406                         void        *agParam3
407                         );
408 
409 osGLOBAL void ostiIOCTLSetSignal (
410                         tiRoot_t    *tiRoot,
411                         void        *agParam1,
412                         void        *agParam2,
413                         void        *agParam3
414                         );
415 
416 osGLOBAL void ostiIOCTLWaitForComplete (
417                         tiRoot_t    *tigRoot,
418                         void        *agParam1,
419                         void        *agParam2,
420                         void        *agParam3
421                         );
422 
423 osGLOBAL void ostiIOCTLComplete (
424                         tiRoot_t    *tiRoot,
425                         void        *agParam1,
426                         void        *agParam2,
427                         void        *agParam3
428                         );
429 
430 /*****************************************************************************
431  *  Target specific Callbacks
432  *****************************************************************************/
433 
434 osGLOBAL void ostiProcessScsiReq(
435                         tiRoot_t            *tiRoot,
436                         tiTargetScsiCmnd_t  *tiTgtScsiCmnd,
437                         void                *agFrameHandle,
438                         bit32               immDataLength,
439                         tiIORequest_t       *tiIORequest,
440                         tiDeviceHandle_t    *tiDeviceHandle);
441 
442 osGLOBAL void ostiNextDataPhase(
443                         tiRoot_t          *tiRoot,
444                         tiIORequest_t     *tiIORequest);
445 
446 osGLOBAL void ostiTaskManagement (
447                         tiRoot_t          *tiRoot,
448                         bit32             task,
449                         bit8              *scsiLun,
450                         tiIORequest_t     *refTiIORequest,
451                         tiIORequest_t     *tiTMRequest,
452                         tiDeviceHandle_t  *tiDeviceHandle);
453 
454 osGLOBAL void ostiTargetIOCompleted(
455                         tiRoot_t          *tiRoot,
456                         tiIORequest_t     *tiIORequest,
457                         tiIOStatus_t      status
458                         );
459 
460 osGLOBAL bit32 ostiTargetEvent (
461                         tiRoot_t          *tiRoot,
462                         tiPortalContext_t *portalContext,
463                         tiDeviceHandle_t  *tiDeviceHandle,
464                         tiTgtEventType_t  eventType,
465                         bit32             eventStatus,
466                         void              *parm
467                         );
468 
469 osGLOBAL void ostiTargetIOError(
470                         tiRoot_t          *tiRoot,
471                         tiIORequest_t     *tiIORequest,
472                         tiIOStatus_t      status,
473                         bit32             statusDetail
474                         );
475 
476 osGLOBAL void ostiTargetTmCompleted(
477                         tiRoot_t          *tiRoot,
478                         tiIORequest_t     *tiTmRequest,
479                         tiIOStatus_t      status,
480                         bit32             statusDetail
481                         );
482 
483 osGLOBAL void ostiPCI_TRIGGER( tiRoot_t *tiRoot );
484 
485 
486 #endif  /* OSTIAPI_H */
487