1285242Sachim/*******************************************************************************
2285242Sachim*Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3285242Sachim*
4285242Sachim*Redistribution and use in source and binary forms, with or without modification, are permitted provided
5285242Sachim*that the following conditions are met:
6285242Sachim*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7285242Sachim*following disclaimer.
8285242Sachim*2. Redistributions in binary form must reproduce the above copyright notice,
9285242Sachim*this list of conditions and the following disclaimer in the documentation and/or other materials provided
10285242Sachim*with the distribution.
11285242Sachim*
12285242Sachim*THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13285242Sachim*WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14285242Sachim*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15285242Sachim*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16285242Sachim*NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17285242Sachim*BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18285242Sachim*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19285242Sachim*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20285242Sachim*
21285242Sachim* $FreeBSD$
22285242Sachim*
23285242Sachim********************************************************************************/
24285242Sachim/********************************************************************************
25285242Sachim**
26285242Sachim** Version Control Information:
27285242Sachim**
28285242Sachim**
29285242Sachim*******************************************************************************/
30285242Sachim/********************************************************************************
31285242Sachim**
32285242Sachim**   ostiapi.h
33285242Sachim**
34285242Sachim**   Abstract:   This module contains function prototype of the Transport
35285242Sachim**               Independent (TIAPI) OS Callback interface.
36285242Sachim**
37285242Sachim********************************************************************************/
38285242Sachim
39285242Sachim#ifndef OSTIAPI_H
40285242Sachim
41285242Sachim#define OSTIAPI_H
42285242Sachim
43285242Sachim/*
44285242Sachim * Definition for return status is defined in tiStatus_t in TIDEFS.H
45285242Sachim */
46285242Sachim
47285242Sachim/*****************************************************************************
48285242Sachim *  Initiator/Target Shared Callbacks
49285242Sachim *****************************************************************************/
50285242Sachim
51285242SachimosGLOBAL bit32 ostiGetTransportParam(
52285242Sachim                        tiRoot_t    *tiRoot,
53285242Sachim                        char        *key,
54285242Sachim                        char        *subkey1,
55285242Sachim                        char        *subkey2,
56285242Sachim                        char        *subkey3,
57285242Sachim                        char        *subkey4,
58285242Sachim                        char        *subkey5,
59285242Sachim                        char        *valueName,
60285242Sachim                        char        *buffer,
61285242Sachim                        bit32       bufferLen,
62285242Sachim                        bit32       *lenReceived
63285242Sachim                        );
64285242Sachim
65285242SachimosGLOBAL void  ostiPortEvent(
66285242Sachim                        tiRoot_t      *tiRoot,
67285242Sachim                        tiPortEvent_t eventType,
68285242Sachim                        bit32         status,
69285242Sachim                        void          *pParm
70285242Sachim                        );
71285242Sachim
72285242SachimosGLOBAL bit32  ostiTimeStamp( tiRoot_t  *tiRoot);
73285242SachimosGLOBAL bit64  ostiTimeStamp64( tiRoot_t  *tiRoot);
74285242Sachim
75285242SachimosGLOBAL FORCEINLINE bit32 ostiChipConfigReadBit32(
76285242Sachim                        tiRoot_t      *tiRoot,
77285242Sachim                        bit32         chipConfigOffset
78285242Sachim                        );
79285242Sachim
80285242SachimosGLOBAL FORCEINLINE void ostiChipConfigWriteBit32(
81285242Sachim                        tiRoot_t      *tiRoot,
82285242Sachim                        bit32         chipConfigOffset,
83285242Sachim                        bit32         chipConfigValue
84285242Sachim                        );
85285242Sachim
86285242SachimosGLOBAL FORCEINLINE bit32 ostiChipReadBit32(
87285242Sachim                        tiRoot_t      *tiRoot,
88285242Sachim                        bit32         chipOffset
89285242Sachim                        );
90285242Sachim
91285242SachimosGLOBAL FORCEINLINE void ostiChipWriteBit32(
92285242Sachim                        tiRoot_t      *tiRoot,
93285242Sachim                        bit32         chipOffset,
94285242Sachim                        bit32         chipValue
95285242Sachim                        );
96285242Sachim
97285242SachimosGLOBAL FORCEINLINE bit8 ostiChipReadBit8(
98285242Sachim                        tiRoot_t      *tiRoot,
99285242Sachim                        bit32         chipOffset
100285242Sachim                        );
101285242Sachim
102285242SachimosGLOBAL FORCEINLINE void ostiChipWriteBit8(
103285242Sachim                        tiRoot_t      *tiRoot,
104285242Sachim                        bit32         chipOffset,
105285242Sachim                        bit8          chipValue
106285242Sachim                        );
107285242Sachim
108285242SachimosGLOBAL void ostiFlashReadBlock(
109285242Sachim                        tiRoot_t      *tiRoot,
110285242Sachim                        bit32         flashOffset,
111285242Sachim                        void          *buffer,
112285242Sachim                        bit32         bufferLen
113285242Sachim                        );
114285242Sachim
115285242SachimosGLOBAL FORCEINLINE
116285242SachimtiDeviceHandle_t*
117285242SachimostiGetDevHandleFromSasAddr(
118285242Sachim  tiRoot_t    *root,
119285242Sachim  unsigned char *sas_addr
120285242Sachim);
121285242Sachim
122285242SachimosGLOBAL FORCEINLINE void ostidisableEncryption(tiRoot_t *root);
123285242Sachim
124285242SachimosGLOBAL FORCEINLINE void ostiSingleThreadedEnter(
125285242Sachim                        tiRoot_t      *tiRoot,
126285242Sachim                        bit32         queueId
127285242Sachim                        );
128285242Sachim
129285242SachimosGLOBAL FORCEINLINE void ostiSingleThreadedLeave(
130285242Sachim                        tiRoot_t      *tiRoot,
131285242Sachim                        bit32         queueId
132285242Sachim                        );
133285242Sachim
134285242Sachim
135285242SachimosGLOBAL bit32 ostiNumOfLUNIOCTLreq(tiRoot_t           *root,
136285242Sachim									void               *param1,
137285242Sachim                                    void               *param2,
138285242Sachim                                    void                           **tiRequestBody,
139285242Sachim                                    tiIORequest_t          **tiIORequest
140285242Sachim                                    );
141285242Sachim
142285242Sachim#ifdef PERF_COUNT
143285242SachimosGLOBAL void ostiEnter(tiRoot_t *ptiRoot, bit32 layer, int io);
144285242SachimosGLOBAL void ostiLeave(tiRoot_t *ptiRoot, bit32 layer, int io);
145285242Sachim#define OSTI_INP_ENTER(root) ostiEnter(root, 2, 0)
146285242Sachim#define OSTI_INP_LEAVE(root) ostiLeave(root, 2, 0)
147285242Sachim#define OSTI_OUT_ENTER(root) ostiEnter(root, 2, 1)
148285242Sachim#define OSTI_OUT_LEAVE(root) ostiLeave(root, 2, 1)
149285242Sachim#else
150285242Sachim#define OSTI_INP_ENTER(root)
151285242Sachim#define OSTI_INP_LEAVE(root)
152285242Sachim#define OSTI_OUT_ENTER(root)
153285242Sachim#define OSTI_OUT_LEAVE(root)
154285242Sachim#endif
155285242Sachim
156285242SachimosGLOBAL void  ostiStallThread(
157285242Sachim                        tiRoot_t      *tiRoot,
158285242Sachim                        bit32         microseconds
159285242Sachim                        );
160285242Sachim
161285242SachimosGLOBAL FORCEINLINE bit8
162285242SachimostiBitScanForward(
163285242Sachim                  tiRoot_t   *root,
164285242Sachim                  bit32      *Index,
165285242Sachim                  bit32       Mask
166285242Sachim                  );
167285242Sachim
168285242Sachim#ifdef LINUX_VERSION_CODE
169285242Sachim
170285242SachimosGLOBAL sbit32
171285242SachimostiAtomicIncrement(
172285242Sachim                   tiRoot_t        *root,
173285242Sachim                   sbit32 volatile *Addend
174285242Sachim                   );
175285242Sachim
176285242SachimosGLOBAL sbit32
177285242SachimostiAtomicDecrement(
178285242Sachim                   tiRoot_t        *root,
179285242Sachim                   sbit32 volatile *Addend
180285242Sachim                   );
181285242Sachim
182285242Sachim
183285242SachimosGLOBAL sbit32
184285242SachimostiAtomicBitClear(
185285242Sachim                   tiRoot_t          *root,
186285242Sachim                   sbit32 volatile   *Destination,
187285242Sachim                   sbit32             Value
188285242Sachim                   );
189285242Sachim
190285242SachimosGLOBAL sbit32
191285242SachimostiAtomicBitSet(
192285242Sachim                   tiRoot_t          *root,
193285242Sachim                   sbit32 volatile   *Destination,
194285242Sachim                   sbit32             Value
195285242Sachim                   );
196285242Sachim
197285242SachimosGLOBAL sbit32
198285242SachimostiAtomicExchange(
199285242Sachim                   tiRoot_t         *root,
200285242Sachim                   sbit32 volatile  *Target,
201285242Sachim                   sbit32            Value
202285242Sachim                   );
203285242Sachim
204285242Sachim#else
205285242Sachim
206285242SachimosGLOBAL FORCEINLINE sbit32
207285242SachimostiInterlockedIncrement(
208285242Sachim                   tiRoot_t        *root,
209285242Sachim                   sbit32 volatile *Addend
210285242Sachim                   );
211285242Sachim
212285242SachimosGLOBAL FORCEINLINE sbit32
213285242SachimostiInterlockedDecrement(
214285242Sachim                   tiRoot_t         *root,
215285242Sachim                   sbit32 volatile  *Addend
216285242Sachim                   );
217285242Sachim
218285242Sachim
219285242SachimosGLOBAL FORCEINLINE sbit32
220285242SachimostiInterlockedAnd(
221285242Sachim                   tiRoot_t         *root,
222285242Sachim                   sbit32 volatile  *Destination,
223285242Sachim                   sbit32            Value
224285242Sachim                   );
225285242Sachim
226285242SachimosGLOBAL FORCEINLINE sbit32
227285242SachimostiInterlockedOr(
228285242Sachim                   tiRoot_t         *root,
229285242Sachim                   sbit32 volatile  *Destination,
230285242Sachim                   sbit32            Value
231285242Sachim                   );
232285242Sachim
233285242SachimosGLOBAL FORCEINLINE sbit32
234285242SachimostiInterlockedExchange(
235285242Sachim                   tiRoot_t        *root,
236285242Sachim                   sbit32 volatile *Target,
237285242Sachim                   sbit32           Value
238285242Sachim                   );
239285242Sachim#endif /*LINUX_VERSION_CODE*/
240285242Sachim
241285242SachimosGLOBAL bit32 ostiAllocMemory(
242285242Sachim                        tiRoot_t    *tiRoot,
243285242Sachim                        void        **osMemHandle,
244285242Sachim                        void        ** virtPtr,
245285242Sachim                        bit32       * physAddrUpper,
246285242Sachim                        bit32       * physAddrLower,
247285242Sachim                        bit32       alignment,
248285242Sachim                        bit32       allocLength,
249285242Sachim                        agBOOLEAN   isCacheable
250285242Sachim                        );
251285242Sachim
252285242SachimosGLOBAL bit32 ostiFreeMemory(
253285242Sachim                        tiRoot_t    *tiRoot,
254285242Sachim                        void        *osDMAHandle,
255285242Sachim                        bit32       allocLength
256285242Sachim                        );
257285242Sachim
258285242SachimosGLOBAL FORCEINLINE void ostiCacheFlush(
259285242Sachim                        tiRoot_t    *tiRoot,
260285242Sachim                        void        *osMemHandle,
261285242Sachim                        void        *virtPtr,
262285242Sachim                        bit32       length
263285242Sachim                        );
264285242Sachim
265285242SachimosGLOBAL FORCEINLINE void ostiCacheInvalidate(
266285242Sachim                        tiRoot_t    *tiRoot,
267285242Sachim                        void        *osMemHandle,
268285242Sachim                        void        *virtPtr,
269285242Sachim                        bit32       length
270285242Sachim                        );
271285242Sachim
272285242SachimosGLOBAL FORCEINLINE void ostiCachePreFlush(
273285242Sachim                        tiRoot_t    *tiRoot,
274285242Sachim                        void        *osMemHandle,
275285242Sachim                        void        *virtPtr,
276285242Sachim                        bit32       length
277285242Sachim                        );
278285242Sachim
279285242Sachim/*
280285242Sachim *  The following two functions are for SAS/SATA
281285242Sachim */
282285242SachimosGLOBAL void
283285242SachimostiInterruptEnable(
284285242Sachim                        tiRoot_t  *ptiRoot,
285285242Sachim                        bit32     channelNum
286285242Sachim                        );
287285242Sachim
288285242SachimosGLOBAL void
289285242SachimostiInterruptDisable(
290285242Sachim                       tiRoot_t  *ptiRoot,
291285242Sachim                       bit32     channelNum
292285242Sachim                       );
293285242Sachim
294285242SachimosGLOBAL FORCEINLINE bit32
295285242SachimostiChipReadBit32Ext(
296285242Sachim                        tiRoot_t  *tiRoot,
297285242Sachim                        bit32     busBaseNumber,
298285242Sachim                        bit32     chipOffset
299285242Sachim                        );
300285242Sachim
301285242SachimosGLOBAL FORCEINLINE void
302285242SachimostiChipWriteBit32Ext(
303285242Sachim                        tiRoot_t  *tiRoot,
304285242Sachim                        bit32     busBaseNumber,
305285242Sachim                        bit32     chipOffset,
306285242Sachim                        bit32     chipValue
307285242Sachim                        );
308285242Sachim
309285242Sachim
310285242Sachim/*****************************************************************************
311285242Sachim *  Initiator specific Callbacks
312285242Sachim *****************************************************************************/
313285242Sachim
314285242Sachim/*
315285242Sachim * Initiator specific IO Completion
316285242Sachim */
317285242SachimosGLOBAL void ostiInitiatorIOCompleted(
318285242Sachim                        tiRoot_t            *tiRoot,
319285242Sachim                        tiIORequest_t       *tiIORequest,
320285242Sachim                        tiIOStatus_t        status,
321285242Sachim                        bit32               statusDetail,
322285242Sachim                        tiSenseData_t       *senseData,
323285242Sachim                        bit32               context
324285242Sachim                        );
325285242Sachim
326285242SachimosGLOBAL tiDeviceHandle_t*
327285242SachimostiMapToDevHandle(tiRoot_t  *root,
328285242Sachim                          bit8      pathId,
329285242Sachim                          bit8      targetId,
330285242Sachim                          bit8      LUN
331285242Sachim                          );
332285242SachimosGLOBAL bit32 ostiSendResetDeviceIoctl(tiRoot_t *root,
333285242Sachim			  void *pccb,
334285242Sachim			  bit8 pathId,
335285242Sachim  			  bit8 targetId,
336285242Sachim			  bit8 lun,
337285242Sachim			  unsigned long resetType
338285242Sachim			);
339285242Sachim
340285242SachimosGLOBAL void
341285242SachimostiGetSenseKeyCount(tiRoot_t  *root,
342285242Sachim                            bit32      fIsClear,
343285242Sachim                            void      *SenseKeyCount,
344285242Sachim                            bit32      length
345285242Sachim                            );
346285242Sachim
347285242SachimosGLOBAL void
348285242SachimostiGetSCSIStatusCount(tiRoot_t  *root,
349285242Sachim                            bit32      fIsClear,
350285242Sachim                            void      *ScsiStatusCount,
351285242Sachim                            bit32      length
352285242Sachim                            );
353285242Sachim
354285242SachimosGLOBAL bit32
355285242SachimostiSetDeviceQueueDepth(tiRoot_t       *tiRoot,
356285242Sachim                                tiIORequest_t  *tiIORequest,
357285242Sachim                                bit32           QueueDepth
358285242Sachim                                );
359285242Sachim
360285242Sachim
361285242Sachim#ifdef FAST_IO_TEST
362285242Sachimtypedef void (*ostiFastSSPCb_t)(tiRoot_t     *ptiRoot,
363285242Sachim                                 void         *arg,
364285242Sachim                                 tiIOStatus_t IOStatus,
365285242Sachim                                 bit32         statusDetail);
366285242Sachim
367285242Sachimvoid osti_FastIOCb(tiRoot_t     *ptiRoot,
368285242Sachim                   void         *arg,
369285242Sachim                   tiIOStatus_t IOStatus,
370285242Sachim                   bit32        statusDetail);
371285242Sachim#endif
372285242Sachim
373285242SachimosGLOBAL void
374285242SachimostiInitiatorSMPCompleted(tiRoot_t    *tiRoot,
375285242Sachim               tiIORequest_t  *tiSMPRequest,
376285242Sachim               tiSMPStatus_t  smpStatus,
377285242Sachim               bit32          tiSMPInfoLen,
378285242Sachim               void           *tiFrameHandle,
379285242Sachim               bit32          context);
380285242Sachim/*
381285242Sachim * Initiator specific event
382285242Sachim */
383285242SachimosGLOBAL void ostiInitiatorEvent (
384285242Sachim                        tiRoot_t            *tiRoot,
385285242Sachim                        tiPortalContext_t   *portalContext,
386285242Sachim                        tiDeviceHandle_t    *tiDeviceHandle,
387285242Sachim                        tiIntrEventType_t   eventType,
388285242Sachim                        bit32               eventStatus,
389285242Sachim                        void                *parm
390285242Sachim                        );
391285242Sachim
392285242Sachim
393285242Sachim/*
394285242Sachim * PMC-Sierra IOCTL semaphoring
395285242Sachim */
396285242SachimosGLOBAL void ostiIOCTLClearSignal (
397285242Sachim                        tiRoot_t    *tiRoot,
398285242Sachim                        void        **agParam1,
399285242Sachim                        void        **agParam2,
400285242Sachim                        void        **agParam3
401285242Sachim                        );
402285242Sachim
403285242SachimosGLOBAL void ostiIOCTLWaitForSignal (
404285242Sachim                        tiRoot_t    *tigRoot,
405285242Sachim                        void        *agParam1,
406285242Sachim                        void        *agParam2,
407285242Sachim                        void        *agParam3
408285242Sachim                        );
409285242Sachim
410285242SachimosGLOBAL void ostiIOCTLSetSignal (
411285242Sachim                        tiRoot_t    *tiRoot,
412285242Sachim                        void        *agParam1,
413285242Sachim                        void        *agParam2,
414285242Sachim                        void        *agParam3
415285242Sachim                        );
416285242Sachim
417285242SachimosGLOBAL void ostiIOCTLWaitForComplete (
418285242Sachim                        tiRoot_t    *tigRoot,
419285242Sachim                        void        *agParam1,
420285242Sachim                        void        *agParam2,
421285242Sachim                        void        *agParam3
422285242Sachim                        );
423285242Sachim
424285242SachimosGLOBAL void ostiIOCTLComplete (
425285242Sachim                        tiRoot_t    *tiRoot,
426285242Sachim                        void        *agParam1,
427285242Sachim                        void        *agParam2,
428285242Sachim                        void        *agParam3
429285242Sachim                        );
430285242Sachim
431285242Sachim/*****************************************************************************
432285242Sachim *  Target specific Callbacks
433285242Sachim *****************************************************************************/
434285242Sachim
435285242SachimosGLOBAL void ostiProcessScsiReq(
436285242Sachim                        tiRoot_t            *tiRoot,
437285242Sachim                        tiTargetScsiCmnd_t  *tiTgtScsiCmnd,
438285242Sachim                        void                *agFrameHandle,
439285242Sachim                        bit32               immDataLength,
440285242Sachim                        tiIORequest_t       *tiIORequest,
441285242Sachim                        tiDeviceHandle_t    *tiDeviceHandle);
442285242Sachim
443285242SachimosGLOBAL void ostiNextDataPhase(
444285242Sachim                        tiRoot_t          *tiRoot,
445285242Sachim                        tiIORequest_t     *tiIORequest);
446285242Sachim
447285242SachimosGLOBAL void ostiTaskManagement (
448285242Sachim                        tiRoot_t          *tiRoot,
449285242Sachim                        bit32             task,
450285242Sachim                        bit8              *scsiLun,
451285242Sachim                        tiIORequest_t     *refTiIORequest,
452285242Sachim                        tiIORequest_t     *tiTMRequest,
453285242Sachim                        tiDeviceHandle_t  *tiDeviceHandle);
454285242Sachim
455285242SachimosGLOBAL void ostiTargetIOCompleted(
456285242Sachim                        tiRoot_t          *tiRoot,
457285242Sachim                        tiIORequest_t     *tiIORequest,
458285242Sachim                        tiIOStatus_t      status
459285242Sachim                        );
460285242Sachim
461285242SachimosGLOBAL bit32 ostiTargetEvent (
462285242Sachim                        tiRoot_t          *tiRoot,
463285242Sachim                        tiPortalContext_t *portalContext,
464285242Sachim                        tiDeviceHandle_t  *tiDeviceHandle,
465285242Sachim                        tiTgtEventType_t  eventType,
466285242Sachim                        bit32             eventStatus,
467285242Sachim                        void              *parm
468285242Sachim                        );
469285242Sachim
470285242SachimosGLOBAL void ostiTargetIOError(
471285242Sachim                        tiRoot_t          *tiRoot,
472285242Sachim                        tiIORequest_t     *tiIORequest,
473285242Sachim                        tiIOStatus_t      status,
474285242Sachim                        bit32             statusDetail
475285242Sachim                        );
476285242Sachim
477285242SachimosGLOBAL void ostiTargetTmCompleted(
478285242Sachim                        tiRoot_t          *tiRoot,
479285242Sachim                        tiIORequest_t     *tiTmRequest,
480285242Sachim                        tiIOStatus_t      status,
481285242Sachim                        bit32             statusDetail
482285242Sachim                        );
483285242Sachim
484285242SachimosGLOBAL void ostiPCI_TRIGGER( tiRoot_t *tiRoot );
485285242Sachim
486285242Sachim
487285242Sachim#endif  /* OSTIAPI_H */
488