xref: /freebsd/sys/dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdio.c (revision b5ff185e19f6013ca565b2a15bc2d6abce933f46)
1*4e1bc9a0SAchim Leubner /*******************************************************************************
2*4e1bc9a0SAchim Leubner *Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3*4e1bc9a0SAchim Leubner *
4*4e1bc9a0SAchim Leubner *Redistribution and use in source and binary forms, with or without modification, are permitted provided
5*4e1bc9a0SAchim Leubner *that the following conditions are met:
6*4e1bc9a0SAchim Leubner *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7*4e1bc9a0SAchim Leubner *following disclaimer.
8*4e1bc9a0SAchim Leubner *2. Redistributions in binary form must reproduce the above copyright notice,
9*4e1bc9a0SAchim Leubner *this list of conditions and the following disclaimer in the documentation and/or other materials provided
10*4e1bc9a0SAchim Leubner *with the distribution.
11*4e1bc9a0SAchim Leubner *
12*4e1bc9a0SAchim Leubner *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13*4e1bc9a0SAchim Leubner *WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14*4e1bc9a0SAchim Leubner *FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15*4e1bc9a0SAchim Leubner *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16*4e1bc9a0SAchim Leubner *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17*4e1bc9a0SAchim Leubner *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18*4e1bc9a0SAchim Leubner *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19*4e1bc9a0SAchim Leubner *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20*4e1bc9a0SAchim Leubner  ********************************************************************************/
21*4e1bc9a0SAchim Leubner /*******************************************************************************/
22*4e1bc9a0SAchim Leubner /** \file
23*4e1bc9a0SAchim Leubner  *
24*4e1bc9a0SAchim Leubner  * $RCSfile: ttdio.c,v $
25*4e1bc9a0SAchim Leubner  *
26*4e1bc9a0SAchim Leubner  * Copyright 2006 PMC-Sierra, Inc.
27*4e1bc9a0SAchim Leubner  *
28*4e1bc9a0SAchim Leubner  *
29*4e1bc9a0SAchim Leubner  * This file contains initiator IO related functions in TD layer
30*4e1bc9a0SAchim Leubner  *
31*4e1bc9a0SAchim Leubner  */
32*4e1bc9a0SAchim Leubner #include <osenv.h>
33*4e1bc9a0SAchim Leubner #include <ostypes.h>
34*4e1bc9a0SAchim Leubner #include <osdebug.h>
35*4e1bc9a0SAchim Leubner 
36*4e1bc9a0SAchim Leubner #include <sa.h>
37*4e1bc9a0SAchim Leubner #include <saapi.h>
38*4e1bc9a0SAchim Leubner #include <saosapi.h>
39*4e1bc9a0SAchim Leubner 
40*4e1bc9a0SAchim Leubner #include <titypes.h>
41*4e1bc9a0SAchim Leubner #include <ostiapi.h>
42*4e1bc9a0SAchim Leubner #include <tiapi.h>
43*4e1bc9a0SAchim Leubner #include <tiglobal.h>
44*4e1bc9a0SAchim Leubner 
45*4e1bc9a0SAchim Leubner #include <tdtypes.h>
46*4e1bc9a0SAchim Leubner #include <osstring.h>
47*4e1bc9a0SAchim Leubner #include <tdutil.h>
48*4e1bc9a0SAchim Leubner 
49*4e1bc9a0SAchim Leubner #ifdef INITIATOR_DRIVER
50*4e1bc9a0SAchim Leubner #include <itdtypes.h>
51*4e1bc9a0SAchim Leubner #include <itddefs.h>
52*4e1bc9a0SAchim Leubner #include <itdglobl.h>
53*4e1bc9a0SAchim Leubner #endif
54*4e1bc9a0SAchim Leubner 
55*4e1bc9a0SAchim Leubner #ifdef TARGET_DRIVER
56*4e1bc9a0SAchim Leubner #include <ttdglobl.h>
57*4e1bc9a0SAchim Leubner #include <ttdtxchg.h>
58*4e1bc9a0SAchim Leubner #include <ttdtypes.h>
59*4e1bc9a0SAchim Leubner #endif
60*4e1bc9a0SAchim Leubner 
61*4e1bc9a0SAchim Leubner #include <tdsatypes.h>
62*4e1bc9a0SAchim Leubner #include <tdproto.h>
63*4e1bc9a0SAchim Leubner 
64*4e1bc9a0SAchim Leubner 
65*4e1bc9a0SAchim Leubner /*  Start For trace only */
66*4e1bc9a0SAchim Leubner #ifdef REMOVED
67*4e1bc9a0SAchim Leubner unsigned __int64
68*4e1bc9a0SAchim Leubner GetHiResTimeStamp(void);
69*4e1bc9a0SAchim Leubner #endif
70*4e1bc9a0SAchim Leubner #undef TD_DEBUG_TRACE_ENABLE
71*4e1bc9a0SAchim Leubner #define TD_DEBUG_IO_TRACE_BUFFER_MAX  1024
72*4e1bc9a0SAchim Leubner 
73*4e1bc9a0SAchim Leubner 
74*4e1bc9a0SAchim Leubner typedef struct TDDebugTraceEntry_s
75*4e1bc9a0SAchim Leubner {
76*4e1bc9a0SAchim Leubner     bit64             Time;
77*4e1bc9a0SAchim Leubner     ttdsaXchg_t       ttdsaXchg;
78*4e1bc9a0SAchim Leubner     tdsaDeviceData_t  oneDeviceData;
79*4e1bc9a0SAchim Leubner } TDDebugTraceEntry_t;
80*4e1bc9a0SAchim Leubner 
81*4e1bc9a0SAchim Leubner typedef struct TDDebugTrace_s
82*4e1bc9a0SAchim Leubner {
83*4e1bc9a0SAchim Leubner     bit32                 Idx;
84*4e1bc9a0SAchim Leubner     bit32                 pad;
85*4e1bc9a0SAchim Leubner     TDDebugTraceEntry_t  Data[TD_DEBUG_IO_TRACE_BUFFER_MAX];
86*4e1bc9a0SAchim Leubner } TDDebugTrace_t;
87*4e1bc9a0SAchim Leubner 
88*4e1bc9a0SAchim Leubner void TDTraceInit(void);
89*4e1bc9a0SAchim Leubner void TDTraceAdd(ttdsaXchg_t *ttdsaXchg, tdsaDeviceData_t  *oneDeviceData);
90*4e1bc9a0SAchim Leubner 
91*4e1bc9a0SAchim Leubner #ifdef TD_DEBUG_TRACE_ENABLE
92*4e1bc9a0SAchim Leubner #define TD_DEBUG_TRACE(ttdsaXchg, oneDeviceData) TDTraceAdd(ttdsaXchg, oneDeviceData)
93*4e1bc9a0SAchim Leubner #else
94*4e1bc9a0SAchim Leubner #define TD_DEBUG_TRACE(ttdsaXchg, oneDeviceData)
95*4e1bc9a0SAchim Leubner #endif
96*4e1bc9a0SAchim Leubner 
97*4e1bc9a0SAchim Leubner TDDebugTrace_t TraceData;
98*4e1bc9a0SAchim Leubner 
TDTraceInit(void)99*4e1bc9a0SAchim Leubner void TDTraceInit(void)
100*4e1bc9a0SAchim Leubner {
101*4e1bc9a0SAchim Leubner     osti_memset(&TraceData, 0, sizeof(TraceData));
102*4e1bc9a0SAchim Leubner }
103*4e1bc9a0SAchim Leubner 
TDTraceAdd(ttdsaXchg_t * ttdsaXchg,tdsaDeviceData_t * oneDeviceData)104*4e1bc9a0SAchim Leubner void TDTraceAdd(ttdsaXchg_t *ttdsaXchg, tdsaDeviceData_t  *oneDeviceData)
105*4e1bc9a0SAchim Leubner {
106*4e1bc9a0SAchim Leubner     static bit32 TraceIdx = 0;
107*4e1bc9a0SAchim Leubner 
108*4e1bc9a0SAchim Leubner     TraceData.Idx = TraceIdx;
109*4e1bc9a0SAchim Leubner #ifdef REMOVED
110*4e1bc9a0SAchim Leubner     TraceData.Data[TraceIdx].Time = GetHiResTimeStamp();
111*4e1bc9a0SAchim Leubner #endif
112*4e1bc9a0SAchim Leubner     osti_memcpy((bit8 *)&(TraceData.Data[TraceIdx].ttdsaXchg), (bit8 *)ttdsaXchg, sizeof(ttdsaXchg_t));
113*4e1bc9a0SAchim Leubner     osti_memcpy((bit8 *)&(TraceData.Data[TraceIdx].oneDeviceData), (bit8 *)oneDeviceData, sizeof(tdsaDeviceData_t));
114*4e1bc9a0SAchim Leubner #ifdef REMOVED
115*4e1bc9a0SAchim Leubner     TraceData.Data[TraceIdx].ttdsaXchg = ttdsaXchg;
116*4e1bc9a0SAchim Leubner     TraceData.Data[TraceIdx].oneDeviceData = oneDeviceData;
117*4e1bc9a0SAchim Leubner #endif
118*4e1bc9a0SAchim Leubner 
119*4e1bc9a0SAchim Leubner     TraceIdx++;
120*4e1bc9a0SAchim Leubner     if (TraceIdx >= TD_DEBUG_IO_TRACE_BUFFER_MAX)
121*4e1bc9a0SAchim Leubner     {
122*4e1bc9a0SAchim Leubner         TraceIdx = 0;
123*4e1bc9a0SAchim Leubner     }
124*4e1bc9a0SAchim Leubner 
125*4e1bc9a0SAchim Leubner     return;
126*4e1bc9a0SAchim Leubner }
127*4e1bc9a0SAchim Leubner 
128*4e1bc9a0SAchim Leubner 
129*4e1bc9a0SAchim Leubner /*  End For trace only */
130*4e1bc9a0SAchim Leubner 
131*4e1bc9a0SAchim Leubner 
132*4e1bc9a0SAchim Leubner osGLOBAL void
ttdsaSSPReqReceived(agsaRoot_t * agRoot,agsaDevHandle_t * agDevHandle,agsaFrameHandle_t agFrameHandle,bit32 agInitiatorTag,bit32 parameter,bit32 agFrameLen)133*4e1bc9a0SAchim Leubner ttdsaSSPReqReceived(
134*4e1bc9a0SAchim Leubner         agsaRoot_t           *agRoot,
135*4e1bc9a0SAchim Leubner         agsaDevHandle_t      *agDevHandle,
136*4e1bc9a0SAchim Leubner         agsaFrameHandle_t    agFrameHandle,
137*4e1bc9a0SAchim Leubner         bit32                agInitiatorTag,
138*4e1bc9a0SAchim Leubner         bit32                parameter,
139*4e1bc9a0SAchim Leubner         bit32                      agFrameLen
140*4e1bc9a0SAchim Leubner )
141*4e1bc9a0SAchim Leubner {
142*4e1bc9a0SAchim Leubner     tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
143*4e1bc9a0SAchim Leubner     tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
144*4e1bc9a0SAchim Leubner     ttdsaXchg_t            *ttdsaXchg;
145*4e1bc9a0SAchim Leubner     /*  agsaSSPCmdInfoUnit_t   cmdIU; */
146*4e1bc9a0SAchim Leubner     tdsaDeviceData_t       *oneDeviceData = agNULL;
147*4e1bc9a0SAchim Leubner     bit32                  agFrameType, TLR;
148*4e1bc9a0SAchim Leubner 
149*4e1bc9a0SAchim Leubner     TD_XCHG_CONTEXT_NO_CMD_RCVD(tiRoot)        = TD_XCHG_CONTEXT_NO_CMD_RCVD(tiRoot)+1;
150*4e1bc9a0SAchim Leubner 
151*4e1bc9a0SAchim Leubner     TI_DBG4(("ttdsaSSPReqReceived: start\n"));
152*4e1bc9a0SAchim Leubner 
153*4e1bc9a0SAchim Leubner     agFrameType = TD_GET_FRAME_TYPE(parameter);
154*4e1bc9a0SAchim Leubner     TLR = TD_GET_TLR(parameter);
155*4e1bc9a0SAchim Leubner 
156*4e1bc9a0SAchim Leubner 
157*4e1bc9a0SAchim Leubner     /*note:
158*4e1bc9a0SAchim Leubner     in ini, agDevHandle->osData =  tdsaDeviceData_t
159*4e1bc9a0SAchim Leubner     is set in tdssAddDevicedataToSharedcontext()
160*4e1bc9a0SAchim Leubner 
161*4e1bc9a0SAchim Leubner     in tdsaDeviceDataInit()
162*4e1bc9a0SAchim Leubner     oneDeviceData->tiDeviceHandle.tdData has been initialized
163*4e1bc9a0SAchim Leubner      */
164*4e1bc9a0SAchim Leubner     oneDeviceData = (tdsaDeviceData_t *)agDevHandle->osData;
165*4e1bc9a0SAchim Leubner 
166*4e1bc9a0SAchim Leubner     if (oneDeviceData == agNULL)
167*4e1bc9a0SAchim Leubner     {
168*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaSSPReqReceived: no device data\n"));
169*4e1bc9a0SAchim Leubner         return;
170*4e1bc9a0SAchim Leubner     }
171*4e1bc9a0SAchim Leubner 
172*4e1bc9a0SAchim Leubner 
173*4e1bc9a0SAchim Leubner 
174*4e1bc9a0SAchim Leubner     ttdsaXchg = ttdsaXchgGetStruct(agRoot);
175*4e1bc9a0SAchim Leubner 
176*4e1bc9a0SAchim Leubner     if (ttdsaXchg == agNULL)
177*4e1bc9a0SAchim Leubner     {
178*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaSSPReqReceived: no free xchg structures\n"));
179*4e1bc9a0SAchim Leubner         //    ttdsaDumpallXchg(tiRoot);
180*4e1bc9a0SAchim Leubner         return;
181*4e1bc9a0SAchim Leubner     }
182*4e1bc9a0SAchim Leubner 
183*4e1bc9a0SAchim Leubner     if (ttdsaXchg->IORequestBody.tiIORequest == agNULL)
184*4e1bc9a0SAchim Leubner     {
185*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaSSPReqReceived: tiIORequest is NULL\n"));
186*4e1bc9a0SAchim Leubner         //    ttdsaDumpallXchg(tiRoot);
187*4e1bc9a0SAchim Leubner         return;
188*4e1bc9a0SAchim Leubner     }
189*4e1bc9a0SAchim Leubner 
190*4e1bc9a0SAchim Leubner     oneDeviceData->agDevHandle = agDevHandle;
191*4e1bc9a0SAchim Leubner     oneDeviceData->agRoot = agRoot;
192*4e1bc9a0SAchim Leubner 
193*4e1bc9a0SAchim Leubner     /* saving the device */
194*4e1bc9a0SAchim Leubner     ttdsaXchg->DeviceData = oneDeviceData;
195*4e1bc9a0SAchim Leubner 
196*4e1bc9a0SAchim Leubner     ttdsaXchg->agRoot  = agRoot;
197*4e1bc9a0SAchim Leubner     ttdsaXchg->tiRoot  = tiRoot;
198*4e1bc9a0SAchim Leubner 
199*4e1bc9a0SAchim Leubner     ttdsaXchg->IORequestBody.agIORequest.sdkData = agNULL;
200*4e1bc9a0SAchim Leubner 
201*4e1bc9a0SAchim Leubner     /* initiator tag */
202*4e1bc9a0SAchim Leubner     ttdsaXchg->tag      = (bit16)agInitiatorTag;
203*4e1bc9a0SAchim Leubner     ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq.agTag
204*4e1bc9a0SAchim Leubner     = ttdsaXchg->tag;
205*4e1bc9a0SAchim Leubner     ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse.agTag
206*4e1bc9a0SAchim Leubner     = ttdsaXchg->tag;
207*4e1bc9a0SAchim Leubner 
208*4e1bc9a0SAchim Leubner     TI_DBG6(("ttdsaSSPReqReceived: initiator tag 0x%x\n", agInitiatorTag));
209*4e1bc9a0SAchim Leubner 
210*4e1bc9a0SAchim Leubner     if (agFrameType == OSSA_FRAME_TYPE_SSP_CMD)
211*4e1bc9a0SAchim Leubner     {
212*4e1bc9a0SAchim Leubner         TI_DBG4(("ttdsaSSPReqReceived: CMD frame type\n"));
213*4e1bc9a0SAchim Leubner         /* reads agsaSSPResponseInfoUnit_t */
214*4e1bc9a0SAchim Leubner         saFrameReadBlock(
215*4e1bc9a0SAchim Leubner                 agRoot,
216*4e1bc9a0SAchim Leubner                 agFrameHandle,
217*4e1bc9a0SAchim Leubner                 0,
218*4e1bc9a0SAchim Leubner                 &ttdsaXchg->agSSPCmndIU,
219*4e1bc9a0SAchim Leubner                 agFrameLen
220*4e1bc9a0SAchim Leubner         );
221*4e1bc9a0SAchim Leubner 
222*4e1bc9a0SAchim Leubner         tdsaProcessCDB(&ttdsaXchg->agSSPCmndIU, ttdsaXchg);
223*4e1bc9a0SAchim Leubner         ttdsaXchg->FrameType = SAS_CMND;
224*4e1bc9a0SAchim Leubner 
225*4e1bc9a0SAchim Leubner         /*
226*4e1bc9a0SAchim Leubner          ** As the last thing we call the disk module to handle the SCSI CDB.
227*4e1bc9a0SAchim Leubner          ** The disk module will call tiTGTIOStart to start a data phase.
228*4e1bc9a0SAchim Leubner          */
229*4e1bc9a0SAchim Leubner 
230*4e1bc9a0SAchim Leubner         /* typedef struct
231*4e1bc9a0SAchim Leubner        {
232*4e1bc9a0SAchim Leubner        bit8      *reqCDB;
233*4e1bc9a0SAchim Leubner        bit8      *scsiLun,
234*4e1bc9a0SAchim Leubner        bit32     taskAttribute;
235*4e1bc9a0SAchim Leubner        bi32      taskId;
236*4e1bc9a0SAchim Leubner        bit32     crn;
237*4e1bc9a0SAchim Leubner        } tiTargetScsiCmnd_t;
238*4e1bc9a0SAchim Leubner          */
239*4e1bc9a0SAchim Leubner         /* what about reqCDB and scsiLun */
240*4e1bc9a0SAchim Leubner 
241*4e1bc9a0SAchim Leubner         /* coverting task attributes from SAS TISA */
242*4e1bc9a0SAchim Leubner         switch (SA_SSPCMD_GET_TASKATTRIB(&ttdsaXchg->agSSPCmndIU))
243*4e1bc9a0SAchim Leubner         {
244*4e1bc9a0SAchim Leubner         case 0:
245*4e1bc9a0SAchim Leubner             ttdsaXchg->tiTgtScsiCmnd.taskAttribute = TASK_SIMPLE;
246*4e1bc9a0SAchim Leubner             break;
247*4e1bc9a0SAchim Leubner         case 1:
248*4e1bc9a0SAchim Leubner             ttdsaXchg->tiTgtScsiCmnd.taskAttribute = TASK_HEAD_OF_QUEUE;
249*4e1bc9a0SAchim Leubner             break;
250*4e1bc9a0SAchim Leubner         case 2:
251*4e1bc9a0SAchim Leubner             ttdsaXchg->tiTgtScsiCmnd.taskAttribute = TASK_ORDERED;
252*4e1bc9a0SAchim Leubner             break;
253*4e1bc9a0SAchim Leubner         case 3:
254*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaSSPReqReceived: reserved taskAttribute 0x%x\n",ttdsaXchg->agSSPCmndIU.efb_tp_taskAttribute));
255*4e1bc9a0SAchim Leubner             ttdsaXchg->tiTgtScsiCmnd.taskAttribute = TASK_SIMPLE;
256*4e1bc9a0SAchim Leubner             break;
257*4e1bc9a0SAchim Leubner         case 4:
258*4e1bc9a0SAchim Leubner             ttdsaXchg->tiTgtScsiCmnd.taskAttribute = TASK_ACA;
259*4e1bc9a0SAchim Leubner             break;
260*4e1bc9a0SAchim Leubner         default:
261*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaSSPReqReceived: unknown taskAttribute 0x%x\n",ttdsaXchg->agSSPCmndIU.efb_tp_taskAttribute));
262*4e1bc9a0SAchim Leubner             ttdsaXchg->agSSPCmndIU.efb_tp_taskAttribute = TASK_SIMPLE;
263*4e1bc9a0SAchim Leubner             break;
264*4e1bc9a0SAchim Leubner         }
265*4e1bc9a0SAchim Leubner 
266*4e1bc9a0SAchim Leubner         ttdsaXchg->tiTgtScsiCmnd.taskId = agInitiatorTag;
267*4e1bc9a0SAchim Leubner         ttdsaXchg->tiTgtScsiCmnd.crn = 0;
268*4e1bc9a0SAchim Leubner         ttdsaXchg->TLR = TLR;
269*4e1bc9a0SAchim Leubner 
270*4e1bc9a0SAchim Leubner         /* call ostiProcessScsiReq */
271*4e1bc9a0SAchim Leubner         ostiProcessScsiReq( tiRoot,
272*4e1bc9a0SAchim Leubner                 &ttdsaXchg->tiTgtScsiCmnd,
273*4e1bc9a0SAchim Leubner                 agFrameHandle,
274*4e1bc9a0SAchim Leubner                 0,
275*4e1bc9a0SAchim Leubner                 ttdsaXchg->IORequestBody.tiIORequest,
276*4e1bc9a0SAchim Leubner                 &ttdsaXchg->DeviceData->tiDeviceHandle);
277*4e1bc9a0SAchim Leubner 
278*4e1bc9a0SAchim Leubner 
279*4e1bc9a0SAchim Leubner     }
280*4e1bc9a0SAchim Leubner     else if (agFrameType == OSSA_FRAME_TYPE_SSP_TASK)
281*4e1bc9a0SAchim Leubner     {
282*4e1bc9a0SAchim Leubner         TI_DBG4(("ttdsaSSPReqReceived: TM frame type\n"));
283*4e1bc9a0SAchim Leubner 
284*4e1bc9a0SAchim Leubner         /*
285*4e1bc9a0SAchim Leubner       reads aagsaSSPScsiTaskMgntReq_t
286*4e1bc9a0SAchim Leubner       including lun
287*4e1bc9a0SAchim Leubner          */
288*4e1bc9a0SAchim Leubner         saFrameReadBlock(
289*4e1bc9a0SAchim Leubner                 agRoot,
290*4e1bc9a0SAchim Leubner                 agFrameHandle,
291*4e1bc9a0SAchim Leubner                 0,
292*4e1bc9a0SAchim Leubner                 &ttdsaXchg->agTMIU,
293*4e1bc9a0SAchim Leubner                 agFrameLen
294*4e1bc9a0SAchim Leubner         );
295*4e1bc9a0SAchim Leubner 
296*4e1bc9a0SAchim Leubner         ttdsaXchg->FrameType = SAS_TM;
297*4e1bc9a0SAchim Leubner         /*
298*4e1bc9a0SAchim Leubner       call task process mangement fn
299*4e1bc9a0SAchim Leubner          */
300*4e1bc9a0SAchim Leubner         ttdsaTMProcess(tiRoot, ttdsaXchg);
301*4e1bc9a0SAchim Leubner         return;
302*4e1bc9a0SAchim Leubner     }
303*4e1bc9a0SAchim Leubner     else
304*4e1bc9a0SAchim Leubner     {
305*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaSSPReqReceived: unknown frame type\n"));
306*4e1bc9a0SAchim Leubner         return;
307*4e1bc9a0SAchim Leubner     }
308*4e1bc9a0SAchim Leubner 
309*4e1bc9a0SAchim Leubner     return;
310*4e1bc9a0SAchim Leubner }
311*4e1bc9a0SAchim Leubner 
312*4e1bc9a0SAchim Leubner void
dumpCDB(bit8 * cdb)313*4e1bc9a0SAchim Leubner dumpCDB(bit8 *cdb)
314*4e1bc9a0SAchim Leubner {
315*4e1bc9a0SAchim Leubner     bit32 i;
316*4e1bc9a0SAchim Leubner     for(i=0;i<10;i++)
317*4e1bc9a0SAchim Leubner     {
318*4e1bc9a0SAchim Leubner         TI_DBG4(("cdb[%d] 0x%x\n", i, cdb[i]));
319*4e1bc9a0SAchim Leubner     }
320*4e1bc9a0SAchim Leubner     return;
321*4e1bc9a0SAchim Leubner }
322*4e1bc9a0SAchim Leubner 
323*4e1bc9a0SAchim Leubner osGLOBAL void
tdsaProcessCDB(agsaSSPCmdInfoUnit_t * cmdIU,ttdsaXchg_t * ttdsaXchg)324*4e1bc9a0SAchim Leubner tdsaProcessCDB(
325*4e1bc9a0SAchim Leubner         agsaSSPCmdInfoUnit_t      *cmdIU,
326*4e1bc9a0SAchim Leubner         ttdsaXchg_t               *ttdsaXchg
327*4e1bc9a0SAchim Leubner )
328*4e1bc9a0SAchim Leubner {
329*4e1bc9a0SAchim Leubner     tdsaRoot_t    *tdsaRoot      = (tdsaRoot_t *) ttdsaXchg->tiRoot->tdData;
330*4e1bc9a0SAchim Leubner     tdsaContext_t *tdsaAllShared = (tdsaContext_t *) &tdsaRoot->tdsaAllShared;
331*4e1bc9a0SAchim Leubner     ttdsaTgt_t    *Target        = (ttdsaTgt_t *) tdsaAllShared->ttdsaTgt;
332*4e1bc9a0SAchim Leubner     bit8 group;
333*4e1bc9a0SAchim Leubner #ifdef TD_DEBUG_ENABLE
334*4e1bc9a0SAchim Leubner     CDB6_t *cdb6;
335*4e1bc9a0SAchim Leubner #endif
336*4e1bc9a0SAchim Leubner     CDB10_t *cdb10;
337*4e1bc9a0SAchim Leubner     CDB12_t *cdb12;
338*4e1bc9a0SAchim Leubner     CDB16_t *cdb16;
339*4e1bc9a0SAchim Leubner     bit32   unknown = agFALSE;
340*4e1bc9a0SAchim Leubner     bit32   len=0;
341*4e1bc9a0SAchim Leubner     group = cmdIU->cdb[0] & CDB_GRP_MASK;
342*4e1bc9a0SAchim Leubner 
343*4e1bc9a0SAchim Leubner     TI_DBG4(("tdsaProcessCDB: start\n"));
344*4e1bc9a0SAchim Leubner 
345*4e1bc9a0SAchim Leubner     switch (cmdIU->cdb[0])
346*4e1bc9a0SAchim Leubner     {
347*4e1bc9a0SAchim Leubner     case SCSIOPC_REPORT_LUN:
348*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: REPORT_LUN\n"));
349*4e1bc9a0SAchim Leubner         ttdsaXchg->XchType = AGSA_SSP_TGT_READ_DATA;
350*4e1bc9a0SAchim Leubner         break;
351*4e1bc9a0SAchim Leubner     case SCSIOPC_INQUIRY:
352*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: INQUIRY\n"));
353*4e1bc9a0SAchim Leubner         ttdsaXchg->XchType = AGSA_SSP_TGT_READ_DATA;
354*4e1bc9a0SAchim Leubner         break;
355*4e1bc9a0SAchim Leubner 
356*4e1bc9a0SAchim Leubner     case SCSIOPC_TEST_UNIT_READY:
357*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: TEST_UNIT_READY\n"));
358*4e1bc9a0SAchim Leubner         ttdsaXchg->XchType = AGSA_SSP_TGT_READ_DATA;
359*4e1bc9a0SAchim Leubner         break;
360*4e1bc9a0SAchim Leubner 
361*4e1bc9a0SAchim Leubner     case SCSIOPC_READ_CAPACITY_10:
362*4e1bc9a0SAchim Leubner     case SCSIOPC_READ_CAPACITY_16:
363*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: READ CAPACITY\n"));
364*4e1bc9a0SAchim Leubner         ttdsaXchg->XchType = AGSA_SSP_TGT_READ_DATA;
365*4e1bc9a0SAchim Leubner         break;
366*4e1bc9a0SAchim Leubner 
367*4e1bc9a0SAchim Leubner     case SCSIOPC_READ_6: /* fall through */
368*4e1bc9a0SAchim Leubner     case SCSIOPC_READ_10:
369*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: READ\n"));
370*4e1bc9a0SAchim Leubner         ttdsaXchg->XchType = AGSA_SSP_TGT_READ_DATA;
371*4e1bc9a0SAchim Leubner         break;
372*4e1bc9a0SAchim Leubner 
373*4e1bc9a0SAchim Leubner     case SCSIOPC_WRITE_6: /* fall through */
374*4e1bc9a0SAchim Leubner     case SCSIOPC_WRITE_10:
375*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: WRITE\n"));
376*4e1bc9a0SAchim Leubner         ttdsaXchg->XchType = AGSA_SSP_TGT_WRITE_DATA;
377*4e1bc9a0SAchim Leubner         break;
378*4e1bc9a0SAchim Leubner 
379*4e1bc9a0SAchim Leubner     case SCSIOPC_MODE_SENSE_6: /* fall through */
380*4e1bc9a0SAchim Leubner     case SCSIOPC_MODE_SENSE_10:
381*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: MODE SENSE\n"));
382*4e1bc9a0SAchim Leubner         ttdsaXchg->XchType = AGSA_SSP_TGT_READ_DATA;
383*4e1bc9a0SAchim Leubner         break;
384*4e1bc9a0SAchim Leubner     case SCSIOPC_SYNCHRONIZE_CACHE_10:
385*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: SCSIOPC_SYNCHRONIZE_CACHE_10\n"));
386*4e1bc9a0SAchim Leubner         ttdsaXchg->XchType = AGSA_SSP_TGT_CMD_OR_TASK_RSP;
387*4e1bc9a0SAchim Leubner         break;
388*4e1bc9a0SAchim Leubner     case SCSIOPC_REQUEST_SENSE:
389*4e1bc9a0SAchim Leubner         TI_DBG2(("tdsaProcessCDB: SCSIOPC_REQUEST_SENSE\n"));
390*4e1bc9a0SAchim Leubner         ttdsaXchg->XchType = AGSA_SSP_TGT_READ_DATA;
391*4e1bc9a0SAchim Leubner         break;
392*4e1bc9a0SAchim Leubner     default:
393*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: UNKNOWN, cbd %d 0x%x\n", cmdIU->cdb[0], cmdIU->cdb[0]));
394*4e1bc9a0SAchim Leubner         ttdsaXchg->XchType = TargetUnknown;
395*4e1bc9a0SAchim Leubner         break;
396*4e1bc9a0SAchim Leubner     }
397*4e1bc9a0SAchim Leubner 
398*4e1bc9a0SAchim Leubner     /* parse datalen */
399*4e1bc9a0SAchim Leubner     switch (group)
400*4e1bc9a0SAchim Leubner     {
401*4e1bc9a0SAchim Leubner     case CDB_6BYTE:
402*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: CDB 6 byte, not yet\n"));
403*4e1bc9a0SAchim Leubner #ifdef TD_DEBUG_ENABLE
404*4e1bc9a0SAchim Leubner         cdb6 = (CDB6_t *)(cmdIU->cdb);
405*4e1bc9a0SAchim Leubner #endif
406*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: CDB len 0x%x\n", cdb6->len));
407*4e1bc9a0SAchim Leubner         break;
408*4e1bc9a0SAchim Leubner     case CDB_10BYTE1: /* fall through */
409*4e1bc9a0SAchim Leubner     case CDB_10BYTE2:
410*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: CDB 10 byte\n"));
411*4e1bc9a0SAchim Leubner         cdb10 = (CDB10_t *)(cmdIU->cdb);
412*4e1bc9a0SAchim Leubner         OSSA_READ_BE_16(AGROOT, &len, cdb10->len, 0);
413*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: CDB len 0x%x\n", len));
414*4e1bc9a0SAchim Leubner         dumpCDB(cmdIU->cdb);
415*4e1bc9a0SAchim Leubner         break;
416*4e1bc9a0SAchim Leubner     case CDB_12BYTE:
417*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: CDB 12 byte, not yet\n"));
418*4e1bc9a0SAchim Leubner         cdb12 = (CDB12_t *)(cmdIU->cdb);
419*4e1bc9a0SAchim Leubner         OSSA_READ_BE_32(AGROOT, &len, cdb12->len, 0);
420*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: CDB len 0x%x\n", len));
421*4e1bc9a0SAchim Leubner         break;
422*4e1bc9a0SAchim Leubner     case CDB_16BYTE:
423*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: CDB 16 byte, not yet\n"));
424*4e1bc9a0SAchim Leubner         cdb16 = (CDB16_t *)(cmdIU->cdb);
425*4e1bc9a0SAchim Leubner         OSSA_READ_BE_32(AGROOT, &len, cdb16->len, 0);
426*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: CDB len 0x%x\n", len));
427*4e1bc9a0SAchim Leubner         break;
428*4e1bc9a0SAchim Leubner     default:
429*4e1bc9a0SAchim Leubner         TI_DBG4(("tdsaProcessCDB: unknow CDB, group %d 0x%x\n", group, group));
430*4e1bc9a0SAchim Leubner         len = 0;
431*4e1bc9a0SAchim Leubner         unknown = agTRUE;
432*4e1bc9a0SAchim Leubner         break;
433*4e1bc9a0SAchim Leubner     }
434*4e1bc9a0SAchim Leubner     if (cmdIU->cdb[0] == SCSIOPC_READ_6  || cmdIU->cdb[0] == SCSIOPC_READ_10 ||
435*4e1bc9a0SAchim Leubner         cmdIU->cdb[0] == SCSIOPC_WRITE_6 || cmdIU->cdb[0] == SCSIOPC_WRITE_10  )
436*4e1bc9a0SAchim Leubner     {
437*4e1bc9a0SAchim Leubner       ttdsaXchg->dataLen  = len * Target->OperatingOption.BlockSize;
438*4e1bc9a0SAchim Leubner     }
439*4e1bc9a0SAchim Leubner     else
440*4e1bc9a0SAchim Leubner     {
441*4e1bc9a0SAchim Leubner       ttdsaXchg->dataLen  = len;
442*4e1bc9a0SAchim Leubner     }
443*4e1bc9a0SAchim Leubner 
444*4e1bc9a0SAchim Leubner     if (ttdsaXchg->dataLen == 0 && unknown == agFALSE)
445*4e1bc9a0SAchim Leubner     {
446*4e1bc9a0SAchim Leubner         /* this is needed because of min operation in tiTGTIOstart() */
447*4e1bc9a0SAchim Leubner         ttdsaXchg->dataLen      = 0xffffffff;
448*4e1bc9a0SAchim Leubner     }
449*4e1bc9a0SAchim Leubner     /*  TI_DBG4(("tdsaProcessCDB: datalen 0x%x %d\n", ttdsaXchg->dataLen, ttdsaXchg->dataLen)); */
450*4e1bc9a0SAchim Leubner     return;
451*4e1bc9a0SAchim Leubner }
452*4e1bc9a0SAchim Leubner 
453*4e1bc9a0SAchim Leubner 
454*4e1bc9a0SAchim Leubner 
455*4e1bc9a0SAchim Leubner 
456*4e1bc9a0SAchim Leubner /*****************************************************************************
457*4e1bc9a0SAchim Leubner  *
458*4e1bc9a0SAchim Leubner  *  tiTGTIOStart
459*4e1bc9a0SAchim Leubner  *
460*4e1bc9a0SAchim Leubner  *  Purpose: This function is called by the target OS Specific Module to start
461*4e1bc9a0SAchim Leubner  *           the next phase of a SCSI Request.
462*4e1bc9a0SAchim Leubner  *
463*4e1bc9a0SAchim Leubner  *  Parameters:
464*4e1bc9a0SAchim Leubner  *   tiRoot:         Pointer to driver Instance.
465*4e1bc9a0SAchim Leubner  *   tiIORequest:    Pointer to the I/O request context for this I/O.
466*4e1bc9a0SAchim Leubner  *                   This context was initially passed to the OS Specific Module
467*4e1bc9a0SAchim Leubner  *                   in ostiProcessScsiReq().
468*4e1bc9a0SAchim Leubner  *   dataOffset:     Offset into the buffer space for this phase.
469*4e1bc9a0SAchim Leubner  *   dataLength:     Length of data to move for this phase.
470*4e1bc9a0SAchim Leubner  *   dataSGL:        Length/Address pair of where the data is. The SGL list is
471*4e1bc9a0SAchim Leubner  *                   allocated and initialized by the OS Specific module.
472*4e1bc9a0SAchim Leubner  *   sglVirtualAddr: The virtual address of the first element in agSgl1 when
473*4e1bc9a0SAchim Leubner  *                   agSgl1 is used with the type tiSglList.
474*4e1bc9a0SAchim Leubner  *                   This field is needed for the TD Layer.
475*4e1bc9a0SAchim Leubner  *
476*4e1bc9a0SAchim Leubner  *  Return:
477*4e1bc9a0SAchim Leubner  *   tiSuccess:     I/O request successfully initiated.
478*4e1bc9a0SAchim Leubner  *   tiBusy:        No resources available, try again later.
479*4e1bc9a0SAchim Leubner  *   tiError:       Other errors that prevent the I/O request to be started.
480*4e1bc9a0SAchim Leubner  *
481*4e1bc9a0SAchim Leubner  *  Note:
482*4e1bc9a0SAchim Leubner  *
483*4e1bc9a0SAchim Leubner  *****************************************************************************/
484*4e1bc9a0SAchim Leubner osGLOBAL bit32
tiTGTIOStart(tiRoot_t * tiRoot,tiIORequest_t * tiIORequest,bit32 dataOffset,bit32 dataLength,tiSgl_t * dataSGL,void * sglVirtualAddr)485*4e1bc9a0SAchim Leubner tiTGTIOStart( tiRoot_t         *tiRoot,
486*4e1bc9a0SAchim Leubner         tiIORequest_t    *tiIORequest,
487*4e1bc9a0SAchim Leubner         bit32             dataOffset,
488*4e1bc9a0SAchim Leubner         bit32             dataLength,
489*4e1bc9a0SAchim Leubner         tiSgl_t          *dataSGL,
490*4e1bc9a0SAchim Leubner         void             *sglVirtualAddr
491*4e1bc9a0SAchim Leubner )
492*4e1bc9a0SAchim Leubner 
493*4e1bc9a0SAchim Leubner {
494*4e1bc9a0SAchim Leubner     ttdsaXchg_t               *ttdsaXchg;
495*4e1bc9a0SAchim Leubner     agsaSSPTargetRequest_t    *agSSPTargetReq;
496*4e1bc9a0SAchim Leubner     bit32                     tiStatus;
497*4e1bc9a0SAchim Leubner     bit32                     saStatus;
498*4e1bc9a0SAchim Leubner     bit32                     tdStatus;
499*4e1bc9a0SAchim Leubner     tdsaPortContext_t         *onePortContext = agNULL;
500*4e1bc9a0SAchim Leubner     tdsaDeviceData_t          *oneDeviceData = agNULL;
501*4e1bc9a0SAchim Leubner 
502*4e1bc9a0SAchim Leubner     TI_DBG4(("tiTGTIOStart: start\n"));
503*4e1bc9a0SAchim Leubner     TI_DBG4(("tiTGTIOStart: dataLength 0x%x %d\n", dataLength, dataLength));
504*4e1bc9a0SAchim Leubner     TI_DBG4(("tiTGTIOStart: dataOffset 0x%x %d\n", dataOffset, dataOffset));
505*4e1bc9a0SAchim Leubner 
506*4e1bc9a0SAchim Leubner     /* save infor in ttdsaXchg */
507*4e1bc9a0SAchim Leubner     ttdsaXchg     = (ttdsaXchg_t *)tiIORequest->tdData;
508*4e1bc9a0SAchim Leubner 
509*4e1bc9a0SAchim Leubner     /* check the state of port */
510*4e1bc9a0SAchim Leubner     oneDeviceData = ttdsaXchg->DeviceData;
511*4e1bc9a0SAchim Leubner     onePortContext= oneDeviceData->tdPortContext;
512*4e1bc9a0SAchim Leubner     if (onePortContext->valid == agFALSE)
513*4e1bc9a0SAchim Leubner     {
514*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTIOStart: portcontext pid %d is invalid\n", onePortContext->id));
515*4e1bc9a0SAchim Leubner         return tiError;
516*4e1bc9a0SAchim Leubner     }
517*4e1bc9a0SAchim Leubner 
518*4e1bc9a0SAchim Leubner 
519*4e1bc9a0SAchim Leubner     agSSPTargetReq
520*4e1bc9a0SAchim Leubner     = &(ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq);
521*4e1bc9a0SAchim Leubner 
522*4e1bc9a0SAchim Leubner     /* fills in agsaSASRequestBody_t.agsaSSPTargetRequest_t */
523*4e1bc9a0SAchim Leubner     agSSPTargetReq->dataLength = (bit32) MIN(dataLength, ttdsaXchg->dataLen);
524*4e1bc9a0SAchim Leubner     agSSPTargetReq->offset = dataOffset;
525*4e1bc9a0SAchim Leubner     agSSPTargetReq->agTag = ttdsaXchg->tag;
526*4e1bc9a0SAchim Leubner     /* SSPTargetReq->agTag has been set in ttdsaSSPReqReceived() */
527*4e1bc9a0SAchim Leubner 
528*4e1bc9a0SAchim Leubner     /* Process TLR */
529*4e1bc9a0SAchim Leubner     if (ttdsaXchg->TLR == 2)
530*4e1bc9a0SAchim Leubner     {
531*4e1bc9a0SAchim Leubner         /* diable TLR */
532*4e1bc9a0SAchim Leubner         agSSPTargetReq->sspOption = 0;
533*4e1bc9a0SAchim Leubner     }
534*4e1bc9a0SAchim Leubner     else
535*4e1bc9a0SAchim Leubner     {
536*4e1bc9a0SAchim Leubner         /* enable TLR */
537*4e1bc9a0SAchim Leubner         /* bit5: 0 1 11 11 :bit0 */
538*4e1bc9a0SAchim Leubner         agSSPTargetReq->sspOption = 0x1F;
539*4e1bc9a0SAchim Leubner     }
540*4e1bc9a0SAchim Leubner 
541*4e1bc9a0SAchim Leubner     ttdsaXchg->IORequestBody.IOType.TargetIO.TargetIOType.RegIO.sglVirtualAddr
542*4e1bc9a0SAchim Leubner     = sglVirtualAddr;
543*4e1bc9a0SAchim Leubner 
544*4e1bc9a0SAchim Leubner     if (agSSPTargetReq->dataLength != 0)
545*4e1bc9a0SAchim Leubner     {
546*4e1bc9a0SAchim Leubner         TI_DBG6(("tiTGTIOStart: pos 1\n"));
547*4e1bc9a0SAchim Leubner         ttdsaXchg->IORequestBody.IOType.TargetIO.TargetIOType.RegIO.tiSgl1
548*4e1bc9a0SAchim Leubner         = *dataSGL;
549*4e1bc9a0SAchim Leubner     }
550*4e1bc9a0SAchim Leubner     else
551*4e1bc9a0SAchim Leubner     {
552*4e1bc9a0SAchim Leubner         TI_DBG6(("tiTGTIOStart: pos 2\n"));
553*4e1bc9a0SAchim Leubner         ttdsaXchg->IORequestBody.IOType.TargetIO.TargetIOType.RegIO.tiSgl1.len
554*4e1bc9a0SAchim Leubner         = 0;
555*4e1bc9a0SAchim Leubner         ttdsaXchg->IORequestBody.IOType.TargetIO.TargetIOType.RegIO.tiSgl1.type
556*4e1bc9a0SAchim Leubner         = tiSgl;
557*4e1bc9a0SAchim Leubner 
558*4e1bc9a0SAchim Leubner         /* let's send response frame */
559*4e1bc9a0SAchim Leubner         if (ttdsaXchg->resp.length != 0)
560*4e1bc9a0SAchim Leubner         {
561*4e1bc9a0SAchim Leubner             /* senselen != 0, send respsonse */
562*4e1bc9a0SAchim Leubner             TI_DBG4(("tiTGTIOStart: send respsonse\n"));
563*4e1bc9a0SAchim Leubner             TI_DBG4(("tiTGTIOStart: resp.length 0x%x\n",
564*4e1bc9a0SAchim Leubner                     ttdsaXchg->resp.length));
565*4e1bc9a0SAchim Leubner             ttdsaXchg->responseSent = agTRUE;
566*4e1bc9a0SAchim Leubner             ttdsaXchg->DeviceData->IOResponse++;
567*4e1bc9a0SAchim Leubner             TD_DEBUG_TRACE(ttdsaXchg, ttdsaXchg->DeviceData);
568*4e1bc9a0SAchim Leubner             tdStatus = ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
569*4e1bc9a0SAchim Leubner             if (tdStatus == AGSA_RC_SUCCESS)
570*4e1bc9a0SAchim Leubner             {
571*4e1bc9a0SAchim Leubner                 return tiSuccess;
572*4e1bc9a0SAchim Leubner             }
573*4e1bc9a0SAchim Leubner             else if (tdStatus == AGSA_RC_FAILURE)
574*4e1bc9a0SAchim Leubner             {
575*4e1bc9a0SAchim Leubner                 TI_DBG1(("tiTGTIOStart: (ttdsaSendResp) sending not successful\n"));
576*4e1bc9a0SAchim Leubner                 return tiError;
577*4e1bc9a0SAchim Leubner             }
578*4e1bc9a0SAchim Leubner             else
579*4e1bc9a0SAchim Leubner             {
580*4e1bc9a0SAchim Leubner                 TI_DBG1(("tiTGTIOStart: (ttdsaSendResp) sending busy\n"));
581*4e1bc9a0SAchim Leubner                 return tiBusy;
582*4e1bc9a0SAchim Leubner             }
583*4e1bc9a0SAchim Leubner         }
584*4e1bc9a0SAchim Leubner     }
585*4e1bc9a0SAchim Leubner 
586*4e1bc9a0SAchim Leubner 
587*4e1bc9a0SAchim Leubner     /* sets SSPTargetReq->agSgl */
588*4e1bc9a0SAchim Leubner     tiStatus = ttdssIOPrepareSGL(tiRoot, &ttdsaXchg->IORequestBody, dataSGL, NULL, sglVirtualAddr);
589*4e1bc9a0SAchim Leubner 
590*4e1bc9a0SAchim Leubner     if (tiStatus != tiSuccess)
591*4e1bc9a0SAchim Leubner     {
592*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTIOStart: ttdIOPrepareSGL did not return success\n"));
593*4e1bc9a0SAchim Leubner         return tiStatus;
594*4e1bc9a0SAchim Leubner     }
595*4e1bc9a0SAchim Leubner 
596*4e1bc9a0SAchim Leubner     TI_DBG4(("tiTGTIOStart: agroot %p ttdsaXchg %p\n", ttdsaXchg->agRoot, ttdsaXchg));
597*4e1bc9a0SAchim Leubner     TI_DBG4(("tiTGTIOStart: agDevHanlde %p\n", ttdsaXchg->DeviceData->agDevHandle));
598*4e1bc9a0SAchim Leubner 
599*4e1bc9a0SAchim Leubner     if ( (ttdsaXchg->readRspCollapsed == agTRUE) || (ttdsaXchg->wrtRspCollapsed == agTRUE) )
600*4e1bc9a0SAchim Leubner     {
601*4e1bc9a0SAchim Leubner         /* collapse good response with read  */
602*4e1bc9a0SAchim Leubner         TI_DBG4(("tiTGTIOStart: read rsp collapse\n"));
603*4e1bc9a0SAchim Leubner         TI_DBG4(("tiTGTIOStart: initiator tag 0x%x\n", ttdsaXchg->tag));
604*4e1bc9a0SAchim Leubner 
605*4e1bc9a0SAchim Leubner         TD_XCHG_CONTEXT_NO_START_IO(tiRoot)        = TD_XCHG_CONTEXT_NO_START_IO(tiRoot)+1;
606*4e1bc9a0SAchim Leubner         ttdsaXchg->DeviceData->IOStart++;
607*4e1bc9a0SAchim Leubner         TD_DEBUG_TRACE(ttdsaXchg, ttdsaXchg->DeviceData);
608*4e1bc9a0SAchim Leubner         saStatus = saSSPStart(
609*4e1bc9a0SAchim Leubner                 ttdsaXchg->agRoot,
610*4e1bc9a0SAchim Leubner                 &ttdsaXchg->IORequestBody.agIORequest,
611*4e1bc9a0SAchim Leubner                 tdsaRotateQnumber(tiRoot, oneDeviceData),
612*4e1bc9a0SAchim Leubner                 ttdsaXchg->DeviceData->agDevHandle,
613*4e1bc9a0SAchim Leubner                 ttdsaXchg->readRspCollapsed ? AGSA_SSP_TGT_READ_GOOD_RESP : AGSA_SSP_TGT_WRITE_GOOD_RESP,
614*4e1bc9a0SAchim Leubner                         &ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody,
615*4e1bc9a0SAchim Leubner                         agNULL,
616*4e1bc9a0SAchim Leubner                         &ossaSSPCompleted
617*4e1bc9a0SAchim Leubner         );
618*4e1bc9a0SAchim Leubner     }
619*4e1bc9a0SAchim Leubner     else
620*4e1bc9a0SAchim Leubner     {
621*4e1bc9a0SAchim Leubner         TI_DBG4(("tiTGTIOStart: normal\n"));
622*4e1bc9a0SAchim Leubner         TI_DBG4(("tiTGTIOStart: initiator tag 0x%x\n", ttdsaXchg->tag));
623*4e1bc9a0SAchim Leubner         TD_XCHG_CONTEXT_NO_START_IO(tiRoot)        = TD_XCHG_CONTEXT_NO_START_IO(tiRoot)+1;
624*4e1bc9a0SAchim Leubner         ttdsaXchg->DeviceData->IOStart++;
625*4e1bc9a0SAchim Leubner         TD_DEBUG_TRACE(ttdsaXchg, ttdsaXchg->DeviceData);
626*4e1bc9a0SAchim Leubner         saStatus = saSSPStart(
627*4e1bc9a0SAchim Leubner                 ttdsaXchg->agRoot, /* agRoot, */
628*4e1bc9a0SAchim Leubner                 &ttdsaXchg->IORequestBody.agIORequest,
629*4e1bc9a0SAchim Leubner                 tdsaRotateQnumber(tiRoot, oneDeviceData),
630*4e1bc9a0SAchim Leubner                 ttdsaXchg->DeviceData->agDevHandle,
631*4e1bc9a0SAchim Leubner                 ttdsaXchg->XchType,
632*4e1bc9a0SAchim Leubner                 &ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody,
633*4e1bc9a0SAchim Leubner                 agNULL,
634*4e1bc9a0SAchim Leubner                 &ossaSSPCompleted
635*4e1bc9a0SAchim Leubner         );
636*4e1bc9a0SAchim Leubner 
637*4e1bc9a0SAchim Leubner     }
638*4e1bc9a0SAchim Leubner 
639*4e1bc9a0SAchim Leubner     if (saStatus == AGSA_RC_SUCCESS)
640*4e1bc9a0SAchim Leubner     {
641*4e1bc9a0SAchim Leubner         return tiSuccess;
642*4e1bc9a0SAchim Leubner     }
643*4e1bc9a0SAchim Leubner     else if (saStatus == AGSA_RC_FAILURE)
644*4e1bc9a0SAchim Leubner     {
645*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTIOStart: sending not successful\n"));
646*4e1bc9a0SAchim Leubner         return tiError;
647*4e1bc9a0SAchim Leubner     }
648*4e1bc9a0SAchim Leubner     else
649*4e1bc9a0SAchim Leubner     {
650*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTIOStart: sending busy\n"));
651*4e1bc9a0SAchim Leubner         return tiBusy;
652*4e1bc9a0SAchim Leubner     }
653*4e1bc9a0SAchim Leubner 
654*4e1bc9a0SAchim Leubner }
655*4e1bc9a0SAchim Leubner 
656*4e1bc9a0SAchim Leubner #ifdef EDC_ENABLE
657*4e1bc9a0SAchim Leubner /*****************************************************************************
658*4e1bc9a0SAchim Leubner  *
659*4e1bc9a0SAchim Leubner  *  tiTGTIOStart
660*4e1bc9a0SAchim Leubner  *
661*4e1bc9a0SAchim Leubner  *  Purpose: This function is called by the target OS Specific Module to start
662*4e1bc9a0SAchim Leubner  *           the next phase of a SCSI Request.
663*4e1bc9a0SAchim Leubner  *
664*4e1bc9a0SAchim Leubner  *  Parameters:
665*4e1bc9a0SAchim Leubner  *   tiRoot:         Pointer to driver Instance.
666*4e1bc9a0SAchim Leubner  *   tiIORequest:    Pointer to the I/O request context for this I/O.
667*4e1bc9a0SAchim Leubner  *                   This context was initially passed to the OS Specific Module
668*4e1bc9a0SAchim Leubner  *                   in ostiProcessScsiReq().
669*4e1bc9a0SAchim Leubner  *   dataOffset:     Offset into the buffer space for this phase.
670*4e1bc9a0SAchim Leubner  *   dataLength:     Length of data to move for this phase.
671*4e1bc9a0SAchim Leubner  *   dataSGL:        Length/Address pair of where the data is. The SGL list is
672*4e1bc9a0SAchim Leubner  *                   allocated and initialized by the OS Specific module.
673*4e1bc9a0SAchim Leubner  *   sglVirtualAddr: The virtual address of the first element in agSgl1 when
674*4e1bc9a0SAchim Leubner  *                   agSgl1 is used with the type tiSglList.
675*4e1bc9a0SAchim Leubner  *                   This field is needed for the TD Layer.
676*4e1bc9a0SAchim Leubner  *   difOption:      DIF option.
677*4e1bc9a0SAchim Leubner  *
678*4e1bc9a0SAchim Leubner  *  Return:
679*4e1bc9a0SAchim Leubner  *   tiSuccess:     I/O request successfully initiated.
680*4e1bc9a0SAchim Leubner  *   tiBusy:        No resources available, try again later.
681*4e1bc9a0SAchim Leubner  *   tiError:       Other errors that prevent the I/O request to be started.
682*4e1bc9a0SAchim Leubner  *
683*4e1bc9a0SAchim Leubner  *  Note:
684*4e1bc9a0SAchim Leubner  *
685*4e1bc9a0SAchim Leubner  *****************************************************************************/
tiTGTIOStartDif(tiRoot_t * tiRoot,tiIORequest_t * tiIORequest,bit32 dataOffset,bit32 dataLength,tiSgl_t * dataSGL,void * sglVirtualAddr,tiDif_t * difOption)686*4e1bc9a0SAchim Leubner osGLOBAL bit32 tiTGTIOStartDif(
687*4e1bc9a0SAchim Leubner         tiRoot_t        *tiRoot,
688*4e1bc9a0SAchim Leubner         tiIORequest_t   *tiIORequest,
689*4e1bc9a0SAchim Leubner         bit32           dataOffset,
690*4e1bc9a0SAchim Leubner         bit32           dataLength,
691*4e1bc9a0SAchim Leubner         tiSgl_t         *dataSGL,
692*4e1bc9a0SAchim Leubner         void            *sglVirtualAddr,
693*4e1bc9a0SAchim Leubner         tiDif_t         *difOption
694*4e1bc9a0SAchim Leubner )
695*4e1bc9a0SAchim Leubner {
696*4e1bc9a0SAchim Leubner 
697*4e1bc9a0SAchim Leubner     /* This function was never used by SAS/SATA. Use tiTGTSuperIOStart() instead. */
698*4e1bc9a0SAchim Leubner     return tiBusy;
699*4e1bc9a0SAchim Leubner }
700*4e1bc9a0SAchim Leubner #endif
701*4e1bc9a0SAchim Leubner 
702*4e1bc9a0SAchim Leubner osGLOBAL bit32
ttdssIOPrepareSGL(tiRoot_t * tiRoot,tdIORequestBody_t * tdIORequestBody,tiSgl_t * tiSgl1,tiSgl_t * tiSgl2,void * sglVirtualAddr)703*4e1bc9a0SAchim Leubner ttdssIOPrepareSGL(
704*4e1bc9a0SAchim Leubner         tiRoot_t                 *tiRoot,
705*4e1bc9a0SAchim Leubner         tdIORequestBody_t        *tdIORequestBody,
706*4e1bc9a0SAchim Leubner         tiSgl_t                  *tiSgl1,
707*4e1bc9a0SAchim Leubner         tiSgl_t                  *tiSgl2,
708*4e1bc9a0SAchim Leubner         void                     *sglVirtualAddr
709*4e1bc9a0SAchim Leubner )
710*4e1bc9a0SAchim Leubner {
711*4e1bc9a0SAchim Leubner     agsaSgl_t                 *agSgl;
712*4e1bc9a0SAchim Leubner 
713*4e1bc9a0SAchim Leubner     TI_DBG6(("ttdssIOPrepareSGL: start\n"));
714*4e1bc9a0SAchim Leubner 
715*4e1bc9a0SAchim Leubner     agSgl = &(tdIORequestBody->transport.SAS.agSASRequestBody.sspTargetReq.agSgl);
716*4e1bc9a0SAchim Leubner 
717*4e1bc9a0SAchim Leubner     agSgl->len = 0;
718*4e1bc9a0SAchim Leubner 
719*4e1bc9a0SAchim Leubner     if (tiSgl1 == agNULL)
720*4e1bc9a0SAchim Leubner     {
721*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdssIOPrepareSGL: Error tiSgl1 is NULL\n"));
722*4e1bc9a0SAchim Leubner         return tiError;
723*4e1bc9a0SAchim Leubner     }
724*4e1bc9a0SAchim Leubner 
725*4e1bc9a0SAchim Leubner     agSgl->sgUpper = tiSgl1->upper;
726*4e1bc9a0SAchim Leubner     agSgl->sgLower = tiSgl1->lower;
727*4e1bc9a0SAchim Leubner     agSgl->len = tiSgl1->len;
728*4e1bc9a0SAchim Leubner     agSgl->extReserved = tiSgl1->type;
729*4e1bc9a0SAchim Leubner 
730*4e1bc9a0SAchim Leubner     return tiSuccess;
731*4e1bc9a0SAchim Leubner }
732*4e1bc9a0SAchim Leubner 
733*4e1bc9a0SAchim Leubner /* temp for debugging */
734*4e1bc9a0SAchim Leubner void
dumpresp(bit8 * resp,bit32 len)735*4e1bc9a0SAchim Leubner dumpresp(bit8 *resp, bit32 len)
736*4e1bc9a0SAchim Leubner {
737*4e1bc9a0SAchim Leubner     bit32 i;
738*4e1bc9a0SAchim Leubner 
739*4e1bc9a0SAchim Leubner     for(i=0;i<len;i++)
740*4e1bc9a0SAchim Leubner     {
741*4e1bc9a0SAchim Leubner         TI_DBG4(("resp[%d] 0x%x\n", i, resp[i]));
742*4e1bc9a0SAchim Leubner     }
743*4e1bc9a0SAchim Leubner 
744*4e1bc9a0SAchim Leubner     return;
745*4e1bc9a0SAchim Leubner }
746*4e1bc9a0SAchim Leubner 
747*4e1bc9a0SAchim Leubner osGLOBAL bit32
ttdsaSendResp(agsaRoot_t * agRoot,ttdsaXchg_t * ttdsaXchg)748*4e1bc9a0SAchim Leubner ttdsaSendResp(
749*4e1bc9a0SAchim Leubner         agsaRoot_t            *agRoot,
750*4e1bc9a0SAchim Leubner         ttdsaXchg_t           *ttdsaXchg
751*4e1bc9a0SAchim Leubner )
752*4e1bc9a0SAchim Leubner {
753*4e1bc9a0SAchim Leubner     tdsaRootOsData_t          *osData = (tdsaRootOsData_t *)agRoot->osData;
754*4e1bc9a0SAchim Leubner     tiRoot_t                  *tiRoot = (tiRoot_t *)osData->tiRoot;
755*4e1bc9a0SAchim Leubner     tdsaDeviceData_t          *oneDeviceData = agNULL;
756*4e1bc9a0SAchim Leubner     bit32                     agRequestType;
757*4e1bc9a0SAchim Leubner     bit32                     saStatus;
758*4e1bc9a0SAchim Leubner     agsaSSPTargetResponse_t   *agSSPTargetResp;
759*4e1bc9a0SAchim Leubner     agRequestType = AGSA_SSP_TGT_CMD_OR_TASK_RSP;
760*4e1bc9a0SAchim Leubner 
761*4e1bc9a0SAchim Leubner     TI_DBG4(("ttdsaSendResp: start\n"));
762*4e1bc9a0SAchim Leubner     TI_DBG4(("ttdsaSendResp: agroot %p ttdsaXchg %p\n", ttdsaXchg->agRoot, ttdsaXchg));
763*4e1bc9a0SAchim Leubner 
764*4e1bc9a0SAchim Leubner     TI_DBG4(("ttdsaSendResp:: agDevHanlde %p\n", ttdsaXchg->DeviceData->agDevHandle));
765*4e1bc9a0SAchim Leubner 
766*4e1bc9a0SAchim Leubner     /* sas response */
767*4e1bc9a0SAchim Leubner     TI_DBG4(("ttdsaSendResp: len 0x%x \n",
768*4e1bc9a0SAchim Leubner             ttdsaXchg->resp.length));
769*4e1bc9a0SAchim Leubner     TI_DBG4(("ttdsaSendResp: upper 0x%x \n",
770*4e1bc9a0SAchim Leubner             ttdsaXchg->resp.phyAddrUpper));
771*4e1bc9a0SAchim Leubner     TI_DBG4(("ttdsaSendResp: lower 0x%x \n",
772*4e1bc9a0SAchim Leubner             ttdsaXchg->resp.phyAddrLower));
773*4e1bc9a0SAchim Leubner     TI_DBG4(("ttdsaSendResp: initiator tag 0x%x\n", ttdsaXchg->tag));
774*4e1bc9a0SAchim Leubner 
775*4e1bc9a0SAchim Leubner     agSSPTargetResp = &(ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse);
776*4e1bc9a0SAchim Leubner     agSSPTargetResp->agTag = ttdsaXchg->tag;
777*4e1bc9a0SAchim Leubner     agSSPTargetResp->respBufLength = ttdsaXchg->resp.length;
778*4e1bc9a0SAchim Leubner     agSSPTargetResp->respBufUpper = ttdsaXchg->resp.phyAddrUpper;
779*4e1bc9a0SAchim Leubner     agSSPTargetResp->respBufLower = ttdsaXchg->resp.phyAddrLower;
780*4e1bc9a0SAchim Leubner     agSSPTargetResp->respOption = 3; /* Retry on both ACK/NAK timeout and NAK received */
781*4e1bc9a0SAchim Leubner     /* temporary solution for T2D Combo*/
782*4e1bc9a0SAchim Leubner #if defined (INITIATOR_DRIVER) && defined (TARGET_DRIVER)
783*4e1bc9a0SAchim Leubner     /* nothing */
784*4e1bc9a0SAchim Leubner #else
785*4e1bc9a0SAchim Leubner     if (agSSPTargetResp->respBufLength <= AGSA_MAX_SSPPAYLOAD_VIA_SFO)
786*4e1bc9a0SAchim Leubner         agSSPTargetResp->frameBuf = ttdsaXchg->resp.virtAddr;
787*4e1bc9a0SAchim Leubner     else
788*4e1bc9a0SAchim Leubner         agSSPTargetResp->frameBuf = NULL;
789*4e1bc9a0SAchim Leubner #endif
790*4e1bc9a0SAchim Leubner     dumpresp((bit8 *)ttdsaXchg->resp.virtAddr, ttdsaXchg->resp.length);
791*4e1bc9a0SAchim Leubner 
792*4e1bc9a0SAchim Leubner     TD_XCHG_CONTEXT_NO_SEND_RSP(TD_GET_TIROOT(agRoot))        =
793*4e1bc9a0SAchim Leubner             TD_XCHG_CONTEXT_NO_SEND_RSP(TD_GET_TIROOT(agRoot))+1;
794*4e1bc9a0SAchim Leubner 
795*4e1bc9a0SAchim Leubner     oneDeviceData = ttdsaXchg->DeviceData;
796*4e1bc9a0SAchim Leubner     saStatus = saSSPStart(
797*4e1bc9a0SAchim Leubner             ttdsaXchg->agRoot, /* agRoot,*/
798*4e1bc9a0SAchim Leubner             &ttdsaXchg->IORequestBody.agIORequest,
799*4e1bc9a0SAchim Leubner             tdsaRotateQnumber(tiRoot, oneDeviceData),
800*4e1bc9a0SAchim Leubner             ttdsaXchg->DeviceData->agDevHandle, /* agDevHandle, */
801*4e1bc9a0SAchim Leubner             agRequestType,
802*4e1bc9a0SAchim Leubner             &ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody,
803*4e1bc9a0SAchim Leubner             agNULL,
804*4e1bc9a0SAchim Leubner             &ossaSSPCompleted
805*4e1bc9a0SAchim Leubner     );
806*4e1bc9a0SAchim Leubner 
807*4e1bc9a0SAchim Leubner     if (saStatus == AGSA_RC_SUCCESS)
808*4e1bc9a0SAchim Leubner     {
809*4e1bc9a0SAchim Leubner         TI_DBG4(("ttdsaSendResp: sending successful\n"));
810*4e1bc9a0SAchim Leubner         return AGSA_RC_SUCCESS;
811*4e1bc9a0SAchim Leubner     }
812*4e1bc9a0SAchim Leubner     else if (saStatus == AGSA_RC_FAILURE)
813*4e1bc9a0SAchim Leubner     {
814*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaSendResp: sending not successful\n"));
815*4e1bc9a0SAchim Leubner         return AGSA_RC_FAILURE;
816*4e1bc9a0SAchim Leubner     }
817*4e1bc9a0SAchim Leubner     else
818*4e1bc9a0SAchim Leubner     {
819*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaSendResp: sending busy\n"));
820*4e1bc9a0SAchim Leubner         return AGSA_RC_BUSY;
821*4e1bc9a0SAchim Leubner     }
822*4e1bc9a0SAchim Leubner 
823*4e1bc9a0SAchim Leubner }
824*4e1bc9a0SAchim Leubner 
825*4e1bc9a0SAchim Leubner osGLOBAL void
ttdsaIOCompleted(agsaRoot_t * agRoot,agsaIORequest_t * agIORequest,bit32 agIOStatus,bit32 agIOInfoLen,agsaFrameHandle_t agFrameHandle,bit32 agOtherInfo)826*4e1bc9a0SAchim Leubner ttdsaIOCompleted(
827*4e1bc9a0SAchim Leubner         agsaRoot_t             *agRoot,
828*4e1bc9a0SAchim Leubner         agsaIORequest_t        *agIORequest,
829*4e1bc9a0SAchim Leubner         bit32                  agIOStatus,
830*4e1bc9a0SAchim Leubner         bit32                  agIOInfoLen,
831*4e1bc9a0SAchim Leubner         agsaFrameHandle_t      agFrameHandle,
832*4e1bc9a0SAchim Leubner         bit32                  agOtherInfo
833*4e1bc9a0SAchim Leubner )
834*4e1bc9a0SAchim Leubner {
835*4e1bc9a0SAchim Leubner 
836*4e1bc9a0SAchim Leubner     ttdsaXchg_t       *ttdsaXchg    = (ttdsaXchg_t *)agIORequest->osData;
837*4e1bc9a0SAchim Leubner     /* done in ttdsaXchgInit() */
838*4e1bc9a0SAchim Leubner     bit32             IOFailed = agFALSE;
839*4e1bc9a0SAchim Leubner     bit32             status;
840*4e1bc9a0SAchim Leubner     bit32             statusDetail = 0;
841*4e1bc9a0SAchim Leubner     tiRoot_t          *tiRoot;
842*4e1bc9a0SAchim Leubner #ifdef REMOVED
843*4e1bc9a0SAchim Leubner     tdsaRoot_t        *tdsaRoot;
844*4e1bc9a0SAchim Leubner     tdsaContext_t     *tdsaAllShared;
845*4e1bc9a0SAchim Leubner #endif
846*4e1bc9a0SAchim Leubner     bit32             tdStatus;
847*4e1bc9a0SAchim Leubner     bit32             saStatus = AGSA_RC_FAILURE;
848*4e1bc9a0SAchim Leubner #ifdef  TD_DEBUG_ENABLE
849*4e1bc9a0SAchim Leubner     agsaDifDetails_t  *DifDetail;
850*4e1bc9a0SAchim Leubner #endif
851*4e1bc9a0SAchim Leubner 
852*4e1bc9a0SAchim Leubner     TI_DBG4(("ttdsaIOCompleted: start\n"));
853*4e1bc9a0SAchim Leubner     tiRoot = ((tdsaRootOsData_t *)agRoot->osData)->tiRoot;
854*4e1bc9a0SAchim Leubner #ifdef REMOVED
855*4e1bc9a0SAchim Leubner     tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
856*4e1bc9a0SAchim Leubner     tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
857*4e1bc9a0SAchim Leubner #endif
858*4e1bc9a0SAchim Leubner #ifdef  TD_DEBUG_ENABLE
859*4e1bc9a0SAchim Leubner     DifDetail = (agsaDifDetails_t *)agFrameHandle;
860*4e1bc9a0SAchim Leubner #endif
861*4e1bc9a0SAchim Leubner 
862*4e1bc9a0SAchim Leubner     if (tiRoot == agNULL)
863*4e1bc9a0SAchim Leubner     {
864*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaIOCompleted: tiRoot is NULL\n"));
865*4e1bc9a0SAchim Leubner         return;
866*4e1bc9a0SAchim Leubner     }
867*4e1bc9a0SAchim Leubner 
868*4e1bc9a0SAchim Leubner     TD_XCHG_CONTEXT_NO_IO_COMPLETED(tiRoot)    = TD_XCHG_CONTEXT_NO_IO_COMPLETED(tiRoot)+1;
869*4e1bc9a0SAchim Leubner 
870*4e1bc9a0SAchim Leubner     if(TD_XCHG_GET_STATE(ttdsaXchg) != TD_XCHG_STATE_ACTIVE)
871*4e1bc9a0SAchim Leubner     {
872*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaIOCompleted: XCHG is not active *****************\n"));
873*4e1bc9a0SAchim Leubner         return;
874*4e1bc9a0SAchim Leubner     }
875*4e1bc9a0SAchim Leubner 
876*4e1bc9a0SAchim Leubner     if (ttdsaXchg->isTMRequest != agTRUE)
877*4e1bc9a0SAchim Leubner     {
878*4e1bc9a0SAchim Leubner         TI_DBG6(("ttdsaIOCompleted: COMMAND \n"));
879*4e1bc9a0SAchim Leubner         TI_DBG6(("ttdsaIOCompleted: ttdsaXchg %p\n", ttdsaXchg));
880*4e1bc9a0SAchim Leubner         TI_DBG6(("ttdsaIOCompleted: ttdsaXchg->IORequestBody.EsglPageList %p\n", &ttdsaXchg->IORequestBody.EsglPageList));
881*4e1bc9a0SAchim Leubner         TI_DBG6(("ttdsaIOCompleted: command initiator tag 0x%x\n", ttdsaXchg->tag));
882*4e1bc9a0SAchim Leubner 
883*4e1bc9a0SAchim Leubner #ifdef REMOVED
884*4e1bc9a0SAchim Leubner         /* call tdsafreeesglpages only for xchg that used eslg */
885*4e1bc9a0SAchim Leubner         if (ttdsaXchg->usedEsgl == agTRUE)
886*4e1bc9a0SAchim Leubner         {
887*4e1bc9a0SAchim Leubner             tdsaFreeEsglPages(tiRoot, &ttdsaXchg->IORequestBody.EsglPageList);
888*4e1bc9a0SAchim Leubner             ttdsaXchg->usedEsgl = agFALSE;
889*4e1bc9a0SAchim Leubner         }
890*4e1bc9a0SAchim Leubner #endif
891*4e1bc9a0SAchim Leubner 
892*4e1bc9a0SAchim Leubner         /* successful case */
893*4e1bc9a0SAchim Leubner         if (agIOStatus ==  OSSA_IO_SUCCESS)
894*4e1bc9a0SAchim Leubner         {
895*4e1bc9a0SAchim Leubner             TI_DBG6(("ttdsaIOCompleted: osIOSuccess\n"));
896*4e1bc9a0SAchim Leubner             if ( (ttdsaXchg->readRspCollapsed == agTRUE) || (ttdsaXchg->wrtRspCollapsed == agTRUE) )
897*4e1bc9a0SAchim Leubner             {
898*4e1bc9a0SAchim Leubner                 ttdsaXchg->responseSent = agTRUE;
899*4e1bc9a0SAchim Leubner                 TI_DBG4(("ttdsaIOCompleted: read rsp collapse\n"));
900*4e1bc9a0SAchim Leubner             }
901*4e1bc9a0SAchim Leubner 
902*4e1bc9a0SAchim Leubner             if (ttdsaXchg->statusSent == agTRUE)
903*4e1bc9a0SAchim Leubner             {
904*4e1bc9a0SAchim Leubner                 /*
905*4e1bc9a0SAchim Leubner           the response has already been set and ready
906*4e1bc9a0SAchim Leubner           but has NOT been sent
907*4e1bc9a0SAchim Leubner                  */
908*4e1bc9a0SAchim Leubner                 if (ttdsaXchg->responseSent == agFALSE)
909*4e1bc9a0SAchim Leubner                 {
910*4e1bc9a0SAchim Leubner                     /* let's send the response for IO */
911*4e1bc9a0SAchim Leubner                     TI_DBG6(("ttdsaIOCompleted: sending response\n"));
912*4e1bc9a0SAchim Leubner                     TD_DEBUG_TRACE(ttdsaXchg, ttdsaXchg->DeviceData);
913*4e1bc9a0SAchim Leubner                     tdStatus = ttdsaSendResp(agRoot, ttdsaXchg);
914*4e1bc9a0SAchim Leubner                     if (tdStatus != AGSA_RC_SUCCESS)
915*4e1bc9a0SAchim Leubner                     {
916*4e1bc9a0SAchim Leubner                         TI_DBG1(("ttdsaIOCompleted: attention needed\n"));
917*4e1bc9a0SAchim Leubner                         return;
918*4e1bc9a0SAchim Leubner                     }
919*4e1bc9a0SAchim Leubner                     ttdsaXchg->responseSent = agTRUE;
920*4e1bc9a0SAchim Leubner                 }
921*4e1bc9a0SAchim Leubner                 else
922*4e1bc9a0SAchim Leubner                 {
923*4e1bc9a0SAchim Leubner                     TI_DBG4(("ttdsaIOCompleted: read rsp collapse and complete \n"));
924*4e1bc9a0SAchim Leubner                     /* the response has been sent */
925*4e1bc9a0SAchim Leubner                     TI_DBG6(("ttdsaIOCompleted: already sent response, notify OS\n"));
926*4e1bc9a0SAchim Leubner 
927*4e1bc9a0SAchim Leubner                     if (TD_XCHG_GET_STATE(ttdsaXchg) == TD_XCHG_STATE_INACTIVE)
928*4e1bc9a0SAchim Leubner                     {
929*4e1bc9a0SAchim Leubner                         TI_DBG1(("ttdsaIOCompleted: wrong DEQUEUE_THIS\n"));
930*4e1bc9a0SAchim Leubner                     }
931*4e1bc9a0SAchim Leubner 
932*4e1bc9a0SAchim Leubner                     /*
933*4e1bc9a0SAchim Leubner                      * Notify the OS Specific Module, so it can free its resource.
934*4e1bc9a0SAchim Leubner                      */
935*4e1bc9a0SAchim Leubner                     TI_DBG4(("ttdsaIOCompleted: calling ostiTargetIOCompleted\n"));
936*4e1bc9a0SAchim Leubner                     ostiTargetIOCompleted( tiRoot,
937*4e1bc9a0SAchim Leubner                             ttdsaXchg->IORequestBody.tiIORequest,
938*4e1bc9a0SAchim Leubner                             tiIOSuccess );
939*4e1bc9a0SAchim Leubner 
940*4e1bc9a0SAchim Leubner                     /* clean up resources */
941*4e1bc9a0SAchim Leubner                     ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
942*4e1bc9a0SAchim Leubner                 }
943*4e1bc9a0SAchim Leubner             } /* sent */
944*4e1bc9a0SAchim Leubner             else
945*4e1bc9a0SAchim Leubner             {
946*4e1bc9a0SAchim Leubner                 TI_DBG4(("ttdsaIOCompleted: osIOSuccess: nextphase\n"));
947*4e1bc9a0SAchim Leubner                 /* the response has not been set; still in data phase */
948*4e1bc9a0SAchim Leubner                 /* we need to tell the disk module to start the next phase */
949*4e1bc9a0SAchim Leubner                 ostiNextDataPhase(ttdsaXchg->tiRoot,
950*4e1bc9a0SAchim Leubner                         ttdsaXchg->IORequestBody.tiIORequest );
951*4e1bc9a0SAchim Leubner             }
952*4e1bc9a0SAchim Leubner             return;
953*4e1bc9a0SAchim Leubner         } /* success */
954*4e1bc9a0SAchim Leubner 
955*4e1bc9a0SAchim Leubner         /* handle error cases */
956*4e1bc9a0SAchim Leubner         if (agIOStatus == OSSA_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH || agIOStatus == OSSA_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH
957*4e1bc9a0SAchim Leubner                 || agIOStatus == OSSA_IO_XFR_ERROR_DIF_CRC_MISMATCH)
958*4e1bc9a0SAchim Leubner         {
959*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaIOCompleted: DIF detail UpperLBA 0x%08x LowerLBA 0x%08x\n", DifDetail->UpperLBA, DifDetail->LowerLBA));
960*4e1bc9a0SAchim Leubner         }
961*4e1bc9a0SAchim Leubner         switch (agIOStatus)
962*4e1bc9a0SAchim Leubner         {
963*4e1bc9a0SAchim Leubner         case OSSA_IO_ABORTED:
964*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaIOCompleted: ABORTED\n"));
965*4e1bc9a0SAchim Leubner             status        = tiIOFailed;
966*4e1bc9a0SAchim Leubner             statusDetail  = tiDetailAborted;
967*4e1bc9a0SAchim Leubner             IOFailed      = agTRUE;
968*4e1bc9a0SAchim Leubner             break;
969*4e1bc9a0SAchim Leubner #ifdef REMOVED
970*4e1bc9a0SAchim Leubner         case OSSA_IO_OVERFLOW:
971*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaIOCompleted: OVERFLOW\n"));
972*4e1bc9a0SAchim Leubner             status        = tiIOOverRun;
973*4e1bc9a0SAchim Leubner             IOFailed      = agTRUE;
974*4e1bc9a0SAchim Leubner             break;
975*4e1bc9a0SAchim Leubner #endif
976*4e1bc9a0SAchim Leubner         case OSSA_IO_UNDERFLOW:
977*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaIOCompleted: UNDERFLOW\n"));
978*4e1bc9a0SAchim Leubner             status        = tiIOUnderRun;
979*4e1bc9a0SAchim Leubner             IOFailed      = agTRUE;
980*4e1bc9a0SAchim Leubner             break;
981*4e1bc9a0SAchim Leubner         case OSSA_IO_ABORT_RESET:
982*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaIOCompleted: ABORT_RESET\n"));
983*4e1bc9a0SAchim Leubner             status        = tiIOFailed;
984*4e1bc9a0SAchim Leubner             statusDetail  = tiDetailAbortReset;
985*4e1bc9a0SAchim Leubner             IOFailed      = agTRUE;
986*4e1bc9a0SAchim Leubner             break;
987*4e1bc9a0SAchim Leubner         case OSSA_IO_XFR_ERROR_DEK_KEY_CACHE_MISS:
988*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaIOCompleted: OSSA_IO_XFR_ERROR_DEK_KEY_CACHE_MISS\n"));
989*4e1bc9a0SAchim Leubner             status        = tiIOEncryptError;
990*4e1bc9a0SAchim Leubner             statusDetail  = tiDetailDekKeyCacheMiss;
991*4e1bc9a0SAchim Leubner             IOFailed      = agTRUE;
992*4e1bc9a0SAchim Leubner             break;
993*4e1bc9a0SAchim Leubner         case OSSA_IO_XFR_ERROR_DEK_KEY_TAG_MISMATCH:
994*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaIOCompleted: OSSA_IO_XFR_ERROR_DEK_KEY_TAG_MISMATCH\n"));
995*4e1bc9a0SAchim Leubner             status        = tiIOEncryptError;
996*4e1bc9a0SAchim Leubner             statusDetail  = tiDetailDekKeyCacheMiss;
997*4e1bc9a0SAchim Leubner             IOFailed      = agTRUE;
998*4e1bc9a0SAchim Leubner             break;
999*4e1bc9a0SAchim Leubner         case OSSA_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH:
1000*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaIOCompleted: OSSA_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH\n"));
1001*4e1bc9a0SAchim Leubner             status        = tiIODifError;
1002*4e1bc9a0SAchim Leubner             statusDetail  = tiDetailDifAppTagMismatch;
1003*4e1bc9a0SAchim Leubner             IOFailed      = agTRUE;
1004*4e1bc9a0SAchim Leubner             break;
1005*4e1bc9a0SAchim Leubner         case OSSA_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH:
1006*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaIOCompleted: OSSA_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH\n"));
1007*4e1bc9a0SAchim Leubner             status        = tiIODifError;
1008*4e1bc9a0SAchim Leubner             statusDetail  = tiDetailDifRefTagMismatch;
1009*4e1bc9a0SAchim Leubner             IOFailed      = agTRUE;
1010*4e1bc9a0SAchim Leubner             break;
1011*4e1bc9a0SAchim Leubner         case OSSA_IO_XFR_ERROR_DIF_CRC_MISMATCH:
1012*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaIOCompleted: OSSA_IO_XFR_ERROR_DIF_CRC_MISMATCH\n"));
1013*4e1bc9a0SAchim Leubner             status        = tiIODifError;
1014*4e1bc9a0SAchim Leubner             statusDetail  = tiDetailDifCrcMismatch;
1015*4e1bc9a0SAchim Leubner             IOFailed      = agTRUE;
1016*4e1bc9a0SAchim Leubner             break;
1017*4e1bc9a0SAchim Leubner         case OSSA_IO_FAILED: /* fall through */
1018*4e1bc9a0SAchim Leubner         case OSSA_IO_NO_DEVICE: /* fall through */
1019*4e1bc9a0SAchim Leubner             //case OSSA_IO_NO_SUPPORT: /* fall through */       /*added to compile tgt_drv (TP)*/
1020*4e1bc9a0SAchim Leubner         case OSSA_IO_LINK_FAILURE: /* fall through */
1021*4e1bc9a0SAchim Leubner         case OSSA_IO_PROG_ERROR: /* fall through */
1022*4e1bc9a0SAchim Leubner         case OSSA_IO_DS_NON_OPERATIONAL: /* fall through */
1023*4e1bc9a0SAchim Leubner         case OSSA_IO_DS_IN_RECOVERY: /* fall through */
1024*4e1bc9a0SAchim Leubner         case OSSA_IO_TM_TAG_NOT_FOUND: /* fall through */
1025*4e1bc9a0SAchim Leubner         case OSSA_MPI_ERR_IO_RESOURCE_UNAVAILABLE: /* fall through */
1026*4e1bc9a0SAchim Leubner         default:
1027*4e1bc9a0SAchim Leubner             status        = tiIOFailed;
1028*4e1bc9a0SAchim Leubner             statusDetail  = tiDetailOtherError;
1029*4e1bc9a0SAchim Leubner             IOFailed      = agTRUE;
1030*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaIOCompleted: Fail!!!!!!! agIOStatus=0x%x  agIOInfoLen=0x%x agOtherInfo=0x%x\n", agIOStatus, agIOInfoLen, agOtherInfo));
1031*4e1bc9a0SAchim Leubner             //      ttdsaDumpallXchg(tiRoot);
1032*4e1bc9a0SAchim Leubner             if (agIOStatus == OSSA_IO_XFER_OPEN_RETRY_TIMEOUT)
1033*4e1bc9a0SAchim Leubner             {
1034*4e1bc9a0SAchim Leubner                 TI_DBG1(("ttdsaIOCompleted: OSSA_IO_XFER_OPEN_RETRY_TIMEOUT ttdsaXchg->id 0x%x datalen 0x%x offset 0x%x agTag 0x%x\n",
1035*4e1bc9a0SAchim Leubner                         ttdsaXchg->id,
1036*4e1bc9a0SAchim Leubner                         ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq.dataLength,
1037*4e1bc9a0SAchim Leubner                         ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq.offset,
1038*4e1bc9a0SAchim Leubner                         ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq.agTag));
1039*4e1bc9a0SAchim Leubner                 TI_DBG1(("ttdsaIOCompleted: statusSent %d responseSent %d\n", ttdsaXchg->statusSent, ttdsaXchg->responseSent));
1040*4e1bc9a0SAchim Leubner 
1041*4e1bc9a0SAchim Leubner             }
1042*4e1bc9a0SAchim Leubner             break;
1043*4e1bc9a0SAchim Leubner         } /* switch */
1044*4e1bc9a0SAchim Leubner 
1045*4e1bc9a0SAchim Leubner         if (IOFailed == agTRUE)
1046*4e1bc9a0SAchim Leubner         {
1047*4e1bc9a0SAchim Leubner             if (agIORequest->sdkData == agNULL)
1048*4e1bc9a0SAchim Leubner             {
1049*4e1bc9a0SAchim Leubner                 tiIORequest_t tiIORequest;
1050*4e1bc9a0SAchim Leubner                 TI_DBG1(("ttdsaIOCompleted: ERROR ttdsaXchg=%p agIOStatus= 0x%x\n",
1051*4e1bc9a0SAchim Leubner                         ttdsaXchg,
1052*4e1bc9a0SAchim Leubner                         agIOStatus ));
1053*4e1bc9a0SAchim Leubner                 TI_DBG1(("CDB= 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1054*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[0],
1055*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[1],
1056*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[2],
1057*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[3],
1058*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[4],
1059*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[5],
1060*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[6],
1061*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[7],
1062*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[8],
1063*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[9],
1064*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[10],
1065*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[11],
1066*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[12],
1067*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[13],
1068*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[14],
1069*4e1bc9a0SAchim Leubner                         ttdsaXchg->agSSPCmndIU.cdb[15] ));
1070*4e1bc9a0SAchim Leubner 
1071*4e1bc9a0SAchim Leubner                 if (TD_XCHG_GET_STATE(ttdsaXchg) == TD_XCHG_STATE_INACTIVE)
1072*4e1bc9a0SAchim Leubner                 {
1073*4e1bc9a0SAchim Leubner                     TI_DBG1(("ttdsaIOCompleted: wrong DEQUEUE_THIS  1\n"));
1074*4e1bc9a0SAchim Leubner                 }
1075*4e1bc9a0SAchim Leubner                 if (ttdsaXchg->retries <= OPEN_RETRY_RETRIES && agIOStatus == OSSA_IO_XFER_OPEN_RETRY_TIMEOUT)
1076*4e1bc9a0SAchim Leubner                 {
1077*4e1bc9a0SAchim Leubner                     TI_DBG2(("ttdsaIOCompleted: 1 loc retries on OSSA_IO_XFER_OPEN_RETRY_TIMEOUT\n"));
1078*4e1bc9a0SAchim Leubner                     if ( (agOtherInfo & 0x1) == 1)
1079*4e1bc9a0SAchim Leubner                     {
1080*4e1bc9a0SAchim Leubner                         /* repsonse phase */
1081*4e1bc9a0SAchim Leubner                         TI_DBG2(("ttdsaIOCompleted: 0 loc response retry\n"));
1082*4e1bc9a0SAchim Leubner                         /* repsonse retry */
1083*4e1bc9a0SAchim Leubner                         saStatus = ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
1084*4e1bc9a0SAchim Leubner                         if (saStatus == AGSA_RC_SUCCESS)
1085*4e1bc9a0SAchim Leubner                         {
1086*4e1bc9a0SAchim Leubner                             TI_DBG2(("ttdsaIOCompleted: 0 loc retried\n"));
1087*4e1bc9a0SAchim Leubner                             ttdsaXchg->retries++;
1088*4e1bc9a0SAchim Leubner                         }
1089*4e1bc9a0SAchim Leubner                         else
1090*4e1bc9a0SAchim Leubner                         {
1091*4e1bc9a0SAchim Leubner                             TI_DBG1(("ttdsaIOCompleted: 0 loc retry failed\n"));
1092*4e1bc9a0SAchim Leubner                             ttdsaXchg->retries = 0;
1093*4e1bc9a0SAchim Leubner                             /*
1094*4e1bc9a0SAchim Leubner                              * because we are freeing up the exchange
1095*4e1bc9a0SAchim Leubner                              * we must let the oslayer know that
1096*4e1bc9a0SAchim Leubner                              * we are releasing the resources by
1097*4e1bc9a0SAchim Leubner                              * setting the tdData to NULL
1098*4e1bc9a0SAchim Leubner                              */
1099*4e1bc9a0SAchim Leubner                             tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1100*4e1bc9a0SAchim Leubner                             tiIORequest.tdData = agNULL;
1101*4e1bc9a0SAchim Leubner 
1102*4e1bc9a0SAchim Leubner                             ostiTargetIOError(
1103*4e1bc9a0SAchim Leubner                                     tiRoot,
1104*4e1bc9a0SAchim Leubner                                     &tiIORequest,
1105*4e1bc9a0SAchim Leubner                                     status,
1106*4e1bc9a0SAchim Leubner                                     statusDetail
1107*4e1bc9a0SAchim Leubner                             );
1108*4e1bc9a0SAchim Leubner 
1109*4e1bc9a0SAchim Leubner                             /* clean up resources */
1110*4e1bc9a0SAchim Leubner                             ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1111*4e1bc9a0SAchim Leubner                         }
1112*4e1bc9a0SAchim Leubner                     }
1113*4e1bc9a0SAchim Leubner                     else if ( (ttdsaXchg->readRspCollapsed == agTRUE) || (ttdsaXchg->wrtRspCollapsed == agTRUE) )
1114*4e1bc9a0SAchim Leubner                     {
1115*4e1bc9a0SAchim Leubner                         saStatus = saSSPStart(
1116*4e1bc9a0SAchim Leubner                                 ttdsaXchg->agRoot, /* agRoot, */
1117*4e1bc9a0SAchim Leubner                                 &ttdsaXchg->IORequestBody.agIORequest,
1118*4e1bc9a0SAchim Leubner                                 0,
1119*4e1bc9a0SAchim Leubner                                 ttdsaXchg->DeviceData->agDevHandle, /* agDevHandle, */
1120*4e1bc9a0SAchim Leubner                                 ttdsaXchg->readRspCollapsed ? AGSA_SSP_TGT_READ_GOOD_RESP : AGSA_SSP_TGT_WRITE_GOOD_RESP,
1121*4e1bc9a0SAchim Leubner                                         &ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody,
1122*4e1bc9a0SAchim Leubner                                         agNULL,
1123*4e1bc9a0SAchim Leubner                                         &ossaSSPCompleted
1124*4e1bc9a0SAchim Leubner                         );
1125*4e1bc9a0SAchim Leubner                         if (saStatus == AGSA_RC_SUCCESS)
1126*4e1bc9a0SAchim Leubner                         {
1127*4e1bc9a0SAchim Leubner                             TI_DBG1(("ttdsaIOCompleted: 1 loc retried\n"));
1128*4e1bc9a0SAchim Leubner                             ttdsaXchg->retries++;
1129*4e1bc9a0SAchim Leubner                         }
1130*4e1bc9a0SAchim Leubner                         else
1131*4e1bc9a0SAchim Leubner                         {
1132*4e1bc9a0SAchim Leubner                             TI_DBG1(("ttdsaIOCompleted: 1 loc retry failed\n"));
1133*4e1bc9a0SAchim Leubner                             ttdsaXchg->retries = 0;
1134*4e1bc9a0SAchim Leubner                             /*
1135*4e1bc9a0SAchim Leubner                              * because we are freeing up the exchange
1136*4e1bc9a0SAchim Leubner                              * we must let the oslayer know that
1137*4e1bc9a0SAchim Leubner                              * we are releasing the resources by
1138*4e1bc9a0SAchim Leubner                              * setting the tdData to NULL
1139*4e1bc9a0SAchim Leubner                              */
1140*4e1bc9a0SAchim Leubner                             tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1141*4e1bc9a0SAchim Leubner                             tiIORequest.tdData = agNULL;
1142*4e1bc9a0SAchim Leubner 
1143*4e1bc9a0SAchim Leubner                             ostiTargetIOError(
1144*4e1bc9a0SAchim Leubner                                     tiRoot,
1145*4e1bc9a0SAchim Leubner                                     &tiIORequest,
1146*4e1bc9a0SAchim Leubner                                     status,
1147*4e1bc9a0SAchim Leubner                                     statusDetail
1148*4e1bc9a0SAchim Leubner                             );
1149*4e1bc9a0SAchim Leubner 
1150*4e1bc9a0SAchim Leubner                             /* clean up resources */
1151*4e1bc9a0SAchim Leubner                             ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1152*4e1bc9a0SAchim Leubner                         }
1153*4e1bc9a0SAchim Leubner                     }
1154*4e1bc9a0SAchim Leubner                     else
1155*4e1bc9a0SAchim Leubner                     {
1156*4e1bc9a0SAchim Leubner                         if (ttdsaXchg->responseSent == agFALSE)
1157*4e1bc9a0SAchim Leubner                         {
1158*4e1bc9a0SAchim Leubner                             saStatus = saSSPStart(
1159*4e1bc9a0SAchim Leubner                                     ttdsaXchg->agRoot, /* agRoot, */
1160*4e1bc9a0SAchim Leubner                                     &ttdsaXchg->IORequestBody.agIORequest, /*agIORequest, */
1161*4e1bc9a0SAchim Leubner                                     0, /* queue number */
1162*4e1bc9a0SAchim Leubner                                     ttdsaXchg->DeviceData->agDevHandle, /* agDevHandle, */
1163*4e1bc9a0SAchim Leubner                                     ttdsaXchg->XchType,
1164*4e1bc9a0SAchim Leubner                                     &ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody,
1165*4e1bc9a0SAchim Leubner                                     agNULL,
1166*4e1bc9a0SAchim Leubner                                     &ossaSSPCompleted
1167*4e1bc9a0SAchim Leubner                             );
1168*4e1bc9a0SAchim Leubner                         }
1169*4e1bc9a0SAchim Leubner                         else
1170*4e1bc9a0SAchim Leubner                         {
1171*4e1bc9a0SAchim Leubner                             /* repsonse retry */
1172*4e1bc9a0SAchim Leubner                             TI_DBG1(("ttdsaIOCompleted: 2 loc reponse retry\n"));
1173*4e1bc9a0SAchim Leubner                             saStatus = ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
1174*4e1bc9a0SAchim Leubner                         }
1175*4e1bc9a0SAchim Leubner                         if (saStatus == AGSA_RC_SUCCESS)
1176*4e1bc9a0SAchim Leubner                         {
1177*4e1bc9a0SAchim Leubner                             TI_DBG1(("ttdsaIOCompleted: 2 loc retried\n"));
1178*4e1bc9a0SAchim Leubner                             ttdsaXchg->retries++;
1179*4e1bc9a0SAchim Leubner                         }
1180*4e1bc9a0SAchim Leubner                         else
1181*4e1bc9a0SAchim Leubner                         {
1182*4e1bc9a0SAchim Leubner                             TI_DBG1(("ttdsaIOCompleted: 2 loc retry failed\n"));
1183*4e1bc9a0SAchim Leubner                             ttdsaXchg->retries = 0;
1184*4e1bc9a0SAchim Leubner                             /*
1185*4e1bc9a0SAchim Leubner                              * because we are freeing up the exchange
1186*4e1bc9a0SAchim Leubner                              * we must let the oslayer know that
1187*4e1bc9a0SAchim Leubner                              * we are releasing the resources by
1188*4e1bc9a0SAchim Leubner                              * setting the tdData to NULL
1189*4e1bc9a0SAchim Leubner                              */
1190*4e1bc9a0SAchim Leubner                             tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1191*4e1bc9a0SAchim Leubner                             tiIORequest.tdData = agNULL;
1192*4e1bc9a0SAchim Leubner 
1193*4e1bc9a0SAchim Leubner                             ostiTargetIOError(
1194*4e1bc9a0SAchim Leubner                                     tiRoot,
1195*4e1bc9a0SAchim Leubner                                     &tiIORequest,
1196*4e1bc9a0SAchim Leubner                                     status,
1197*4e1bc9a0SAchim Leubner                                     statusDetail
1198*4e1bc9a0SAchim Leubner                             );
1199*4e1bc9a0SAchim Leubner 
1200*4e1bc9a0SAchim Leubner                             /* clean up resources */
1201*4e1bc9a0SAchim Leubner                             ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1202*4e1bc9a0SAchim Leubner                         }
1203*4e1bc9a0SAchim Leubner                     }
1204*4e1bc9a0SAchim Leubner                 }
1205*4e1bc9a0SAchim Leubner                 else
1206*4e1bc9a0SAchim Leubner                 {
1207*4e1bc9a0SAchim Leubner                     ttdsaXchg->retries = 0;
1208*4e1bc9a0SAchim Leubner                     /*
1209*4e1bc9a0SAchim Leubner                      * because we are freeing up the exchange
1210*4e1bc9a0SAchim Leubner                      * we must let the oslayer know that
1211*4e1bc9a0SAchim Leubner                      * we are releasing the resources by
1212*4e1bc9a0SAchim Leubner                      * setting the tdData to NULL
1213*4e1bc9a0SAchim Leubner                      */
1214*4e1bc9a0SAchim Leubner                     tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1215*4e1bc9a0SAchim Leubner                     tiIORequest.tdData = agNULL;
1216*4e1bc9a0SAchim Leubner 
1217*4e1bc9a0SAchim Leubner                     ostiTargetIOError(
1218*4e1bc9a0SAchim Leubner                             tiRoot,
1219*4e1bc9a0SAchim Leubner                             &tiIORequest,
1220*4e1bc9a0SAchim Leubner                             status,
1221*4e1bc9a0SAchim Leubner                             statusDetail
1222*4e1bc9a0SAchim Leubner                     );
1223*4e1bc9a0SAchim Leubner 
1224*4e1bc9a0SAchim Leubner                     /* clean up resources */
1225*4e1bc9a0SAchim Leubner                     ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1226*4e1bc9a0SAchim Leubner                 }
1227*4e1bc9a0SAchim Leubner             } /* saData == agNULL */
1228*4e1bc9a0SAchim Leubner             else
1229*4e1bc9a0SAchim Leubner             {
1230*4e1bc9a0SAchim Leubner                 tiIORequest_t tiIORequest;
1231*4e1bc9a0SAchim Leubner 
1232*4e1bc9a0SAchim Leubner                 TI_DBG1(("ttdsaIOCompleted: 2\n"));
1233*4e1bc9a0SAchim Leubner                 if (TD_XCHG_GET_STATE(ttdsaXchg) == TD_XCHG_STATE_INACTIVE)
1234*4e1bc9a0SAchim Leubner                 {
1235*4e1bc9a0SAchim Leubner                     TI_DBG1(("ttdsaIOCompleted: wrong DEQUEUE_THIS  2\n"));
1236*4e1bc9a0SAchim Leubner                 }
1237*4e1bc9a0SAchim Leubner                 if (ttdsaXchg->retries <= OPEN_RETRY_RETRIES && agIOStatus == OSSA_IO_XFER_OPEN_RETRY_TIMEOUT)
1238*4e1bc9a0SAchim Leubner                 {
1239*4e1bc9a0SAchim Leubner                     TI_DBG1(("ttdsaIOCompleted: 2 loc retries on OSSA_IO_XFER_OPEN_RETRY_TIMEOUT\n"));
1240*4e1bc9a0SAchim Leubner                     if ( (agOtherInfo & 0x1) == 1)
1241*4e1bc9a0SAchim Leubner                     {
1242*4e1bc9a0SAchim Leubner                         /* repsonse phase */
1243*4e1bc9a0SAchim Leubner                         TI_DBG2(("ttdsaIOCompleted: 0 loc response retry\n"));
1244*4e1bc9a0SAchim Leubner                         /* repsonse retry */
1245*4e1bc9a0SAchim Leubner                         saStatus = ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
1246*4e1bc9a0SAchim Leubner                         if (saStatus == AGSA_RC_SUCCESS)
1247*4e1bc9a0SAchim Leubner                         {
1248*4e1bc9a0SAchim Leubner                             TI_DBG2(("ttdsaIOCompleted: 0 loc retried\n"));
1249*4e1bc9a0SAchim Leubner                             ttdsaXchg->retries++;
1250*4e1bc9a0SAchim Leubner                         }
1251*4e1bc9a0SAchim Leubner                         else
1252*4e1bc9a0SAchim Leubner                         {
1253*4e1bc9a0SAchim Leubner                             TI_DBG1(("ttdsaIOCompleted: 0 loc retry failed\n"));
1254*4e1bc9a0SAchim Leubner                             ttdsaXchg->retries = 0;
1255*4e1bc9a0SAchim Leubner                             /*
1256*4e1bc9a0SAchim Leubner                              * because we are freeing up the exchange
1257*4e1bc9a0SAchim Leubner                              * we must let the oslayer know that
1258*4e1bc9a0SAchim Leubner                              * we are releasing the resources by
1259*4e1bc9a0SAchim Leubner                              * setting the tdData to NULL
1260*4e1bc9a0SAchim Leubner                              */
1261*4e1bc9a0SAchim Leubner                             tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1262*4e1bc9a0SAchim Leubner                             tiIORequest.tdData = agNULL;
1263*4e1bc9a0SAchim Leubner 
1264*4e1bc9a0SAchim Leubner                             ostiTargetIOError(
1265*4e1bc9a0SAchim Leubner                                     tiRoot,
1266*4e1bc9a0SAchim Leubner                                     &tiIORequest,
1267*4e1bc9a0SAchim Leubner                                     status,
1268*4e1bc9a0SAchim Leubner                                     statusDetail
1269*4e1bc9a0SAchim Leubner                             );
1270*4e1bc9a0SAchim Leubner 
1271*4e1bc9a0SAchim Leubner                             /* clean up resources */
1272*4e1bc9a0SAchim Leubner                             ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1273*4e1bc9a0SAchim Leubner                         }
1274*4e1bc9a0SAchim Leubner                     }
1275*4e1bc9a0SAchim Leubner                     else if ( (ttdsaXchg->readRspCollapsed == agTRUE) || (ttdsaXchg->wrtRspCollapsed == agTRUE) )
1276*4e1bc9a0SAchim Leubner                     {
1277*4e1bc9a0SAchim Leubner                         saStatus = saSSPStart(
1278*4e1bc9a0SAchim Leubner                                 ttdsaXchg->agRoot, /* agRoot, */
1279*4e1bc9a0SAchim Leubner                                 &ttdsaXchg->IORequestBody.agIORequest, /* agIORequest, */
1280*4e1bc9a0SAchim Leubner                                 0, /* queue number */
1281*4e1bc9a0SAchim Leubner                                 ttdsaXchg->DeviceData->agDevHandle, /* agDevHandle, */
1282*4e1bc9a0SAchim Leubner                                 ttdsaXchg->readRspCollapsed ? AGSA_SSP_TGT_READ_GOOD_RESP : AGSA_SSP_TGT_WRITE_GOOD_RESP,
1283*4e1bc9a0SAchim Leubner                                         &ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody,
1284*4e1bc9a0SAchim Leubner                                         agNULL,
1285*4e1bc9a0SAchim Leubner                                         &ossaSSPCompleted
1286*4e1bc9a0SAchim Leubner                         );
1287*4e1bc9a0SAchim Leubner                         if (saStatus == AGSA_RC_SUCCESS)
1288*4e1bc9a0SAchim Leubner                         {
1289*4e1bc9a0SAchim Leubner                             TI_DBG1(("ttdsaIOCompleted: 1 loc retried\n"));
1290*4e1bc9a0SAchim Leubner                             ttdsaXchg->retries++;
1291*4e1bc9a0SAchim Leubner                         }
1292*4e1bc9a0SAchim Leubner                         else
1293*4e1bc9a0SAchim Leubner                         {
1294*4e1bc9a0SAchim Leubner                             TI_DBG1(("ttdsaIOCompleted: 1 loc retry failed\n"));
1295*4e1bc9a0SAchim Leubner                             ttdsaXchg->retries = 0;
1296*4e1bc9a0SAchim Leubner                             /*
1297*4e1bc9a0SAchim Leubner                              * because we are freeing up the exchange
1298*4e1bc9a0SAchim Leubner                              * we must let the oslayer know that
1299*4e1bc9a0SAchim Leubner                              * we are releasing the resources by
1300*4e1bc9a0SAchim Leubner                              * setting the tdData to NULL
1301*4e1bc9a0SAchim Leubner                              */
1302*4e1bc9a0SAchim Leubner                             tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1303*4e1bc9a0SAchim Leubner                             tiIORequest.tdData = agNULL;
1304*4e1bc9a0SAchim Leubner 
1305*4e1bc9a0SAchim Leubner                             ostiTargetIOError(
1306*4e1bc9a0SAchim Leubner                                     tiRoot,
1307*4e1bc9a0SAchim Leubner                                     &tiIORequest,
1308*4e1bc9a0SAchim Leubner                                     status,
1309*4e1bc9a0SAchim Leubner                                     statusDetail
1310*4e1bc9a0SAchim Leubner                             );
1311*4e1bc9a0SAchim Leubner 
1312*4e1bc9a0SAchim Leubner                             /* clean up resources */
1313*4e1bc9a0SAchim Leubner                             ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1314*4e1bc9a0SAchim Leubner                         }
1315*4e1bc9a0SAchim Leubner                     }
1316*4e1bc9a0SAchim Leubner                     else
1317*4e1bc9a0SAchim Leubner                     {
1318*4e1bc9a0SAchim Leubner                         TI_DBG1(("ttdsaIOCompleted: 2 loc ttdsaXchg->id 0x%x datalen 0x%x offset 0x%x agTag 0x%x\n",
1319*4e1bc9a0SAchim Leubner                                 ttdsaXchg->id,
1320*4e1bc9a0SAchim Leubner                                 ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq.dataLength,
1321*4e1bc9a0SAchim Leubner                                 ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq.offset,
1322*4e1bc9a0SAchim Leubner                                 ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq.agTag));
1323*4e1bc9a0SAchim Leubner                         if (ttdsaXchg->responseSent == agFALSE)
1324*4e1bc9a0SAchim Leubner                         {
1325*4e1bc9a0SAchim Leubner                             saStatus = saSSPStart(
1326*4e1bc9a0SAchim Leubner                                     ttdsaXchg->agRoot, /* agRoot, */
1327*4e1bc9a0SAchim Leubner                                     &ttdsaXchg->IORequestBody.agIORequest, /* agIORequest, */
1328*4e1bc9a0SAchim Leubner                                     0, /* queue number */
1329*4e1bc9a0SAchim Leubner                                     ttdsaXchg->DeviceData->agDevHandle, /* agDevHandle, */
1330*4e1bc9a0SAchim Leubner                                     ttdsaXchg->XchType,
1331*4e1bc9a0SAchim Leubner                                     &ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody,
1332*4e1bc9a0SAchim Leubner                                     agNULL,
1333*4e1bc9a0SAchim Leubner                                     &ossaSSPCompleted
1334*4e1bc9a0SAchim Leubner                             );
1335*4e1bc9a0SAchim Leubner                         }
1336*4e1bc9a0SAchim Leubner                         else
1337*4e1bc9a0SAchim Leubner                         {
1338*4e1bc9a0SAchim Leubner                             TI_DBG1(("ttdsaIOCompleted: 2 loc response retry\n"));
1339*4e1bc9a0SAchim Leubner                             /* repsonse retry */
1340*4e1bc9a0SAchim Leubner                             saStatus = ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
1341*4e1bc9a0SAchim Leubner                         }
1342*4e1bc9a0SAchim Leubner                         if (saStatus == AGSA_RC_SUCCESS)
1343*4e1bc9a0SAchim Leubner                         {
1344*4e1bc9a0SAchim Leubner                             TI_DBG1(("ttdsaIOCompleted: 2 loc retried\n"));
1345*4e1bc9a0SAchim Leubner                             ttdsaXchg->retries++;
1346*4e1bc9a0SAchim Leubner                         }
1347*4e1bc9a0SAchim Leubner                         else
1348*4e1bc9a0SAchim Leubner                         {
1349*4e1bc9a0SAchim Leubner                             TI_DBG1(("ttdsaIOCompleted: 2 loc retry failed\n"));
1350*4e1bc9a0SAchim Leubner                             ttdsaXchg->retries = 0;
1351*4e1bc9a0SAchim Leubner                             /*
1352*4e1bc9a0SAchim Leubner                              * because we are freeing up the exchange
1353*4e1bc9a0SAchim Leubner                              * we must let the oslayer know that
1354*4e1bc9a0SAchim Leubner                              * we are releasing the resources by
1355*4e1bc9a0SAchim Leubner                              * setting the tdData to NULL
1356*4e1bc9a0SAchim Leubner                              */
1357*4e1bc9a0SAchim Leubner                             tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1358*4e1bc9a0SAchim Leubner                             tiIORequest.tdData = agNULL;
1359*4e1bc9a0SAchim Leubner 
1360*4e1bc9a0SAchim Leubner                             ostiTargetIOError(
1361*4e1bc9a0SAchim Leubner                                     tiRoot,
1362*4e1bc9a0SAchim Leubner                                     &tiIORequest,
1363*4e1bc9a0SAchim Leubner                                     status,
1364*4e1bc9a0SAchim Leubner                                     statusDetail
1365*4e1bc9a0SAchim Leubner                             );
1366*4e1bc9a0SAchim Leubner 
1367*4e1bc9a0SAchim Leubner                             /* clean up resources */
1368*4e1bc9a0SAchim Leubner                             ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1369*4e1bc9a0SAchim Leubner                         }
1370*4e1bc9a0SAchim Leubner                     }
1371*4e1bc9a0SAchim Leubner                 }
1372*4e1bc9a0SAchim Leubner                 else
1373*4e1bc9a0SAchim Leubner                 {
1374*4e1bc9a0SAchim Leubner                     TI_DBG1(("ttdsaIOCompleted: retry is over\n"));
1375*4e1bc9a0SAchim Leubner                     ttdsaXchg->retries = 0;
1376*4e1bc9a0SAchim Leubner 
1377*4e1bc9a0SAchim Leubner                     tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1378*4e1bc9a0SAchim Leubner                     tiIORequest.tdData = agNULL;
1379*4e1bc9a0SAchim Leubner 
1380*4e1bc9a0SAchim Leubner                     ostiTargetIOError(
1381*4e1bc9a0SAchim Leubner                             tiRoot,
1382*4e1bc9a0SAchim Leubner                             &tiIORequest,
1383*4e1bc9a0SAchim Leubner                             status,
1384*4e1bc9a0SAchim Leubner                             statusDetail
1385*4e1bc9a0SAchim Leubner                     );
1386*4e1bc9a0SAchim Leubner 
1387*4e1bc9a0SAchim Leubner                     /* clean up resources */
1388*4e1bc9a0SAchim Leubner                     ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1389*4e1bc9a0SAchim Leubner                 }
1390*4e1bc9a0SAchim Leubner             } /* saData != agNULL */
1391*4e1bc9a0SAchim Leubner         }/* if (IOFailed == agTRUE) */
1392*4e1bc9a0SAchim Leubner     } /* not TMrequest */
1393*4e1bc9a0SAchim Leubner     else /* TMrequest */
1394*4e1bc9a0SAchim Leubner     {
1395*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaIOCompleted: TM request\n"));
1396*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaIOCompleted: TM initiator tag 0x%x\n", ttdsaXchg->tag));
1397*4e1bc9a0SAchim Leubner 
1398*4e1bc9a0SAchim Leubner         switch(agIOStatus)
1399*4e1bc9a0SAchim Leubner         {
1400*4e1bc9a0SAchim Leubner         case OSSA_IO_SUCCESS:
1401*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaIOCompleted: success\n"));
1402*4e1bc9a0SAchim Leubner             status = tiIOSuccess;
1403*4e1bc9a0SAchim Leubner             break;
1404*4e1bc9a0SAchim Leubner         case OSSA_IO_ABORTED:
1405*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaIOCompleted: ABORTED\n"));
1406*4e1bc9a0SAchim Leubner             status        = tiIOFailed;
1407*4e1bc9a0SAchim Leubner             statusDetail  = tiDetailAborted;
1408*4e1bc9a0SAchim Leubner             IOFailed      = agTRUE;
1409*4e1bc9a0SAchim Leubner             break;
1410*4e1bc9a0SAchim Leubner         case OSSA_IO_ABORT_RESET:
1411*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaIOCompleted: ABORT_RESET\n"));
1412*4e1bc9a0SAchim Leubner             status        = tiIOFailed;
1413*4e1bc9a0SAchim Leubner             statusDetail  = tiDetailAbortReset;
1414*4e1bc9a0SAchim Leubner             IOFailed      = agTRUE;
1415*4e1bc9a0SAchim Leubner             break;
1416*4e1bc9a0SAchim Leubner #ifdef REMOVED
1417*4e1bc9a0SAchim Leubner         case OSSA_IO_OVERFLOW: /* fall through */
1418*4e1bc9a0SAchim Leubner #endif
1419*4e1bc9a0SAchim Leubner         case OSSA_IO_UNDERFLOW: /* fall through */
1420*4e1bc9a0SAchim Leubner         case OSSA_IO_FAILED: /* fall through */
1421*4e1bc9a0SAchim Leubner #ifdef REMOVED
1422*4e1bc9a0SAchim Leubner         case OSSA_IO_NOT_VALID: /* fall through */
1423*4e1bc9a0SAchim Leubner #endif
1424*4e1bc9a0SAchim Leubner         case OSSA_IO_NO_DEVICE: /* fall through */
1425*4e1bc9a0SAchim Leubner             //case OSSA_IO_NO_SUPPORT: /* fall through */       /*added to compile tgt_drv (TP)*/
1426*4e1bc9a0SAchim Leubner         case OSSA_IO_LINK_FAILURE: /* fall through */
1427*4e1bc9a0SAchim Leubner         case OSSA_IO_PROG_ERROR: /* fall through */
1428*4e1bc9a0SAchim Leubner         case OSSA_IO_DS_NON_OPERATIONAL: /* fall through */
1429*4e1bc9a0SAchim Leubner         case OSSA_IO_DS_IN_RECOVERY: /* fall through */
1430*4e1bc9a0SAchim Leubner         case OSSA_IO_TM_TAG_NOT_FOUND: /* fall through */
1431*4e1bc9a0SAchim Leubner         case OSSA_MPI_ERR_IO_RESOURCE_UNAVAILABLE: /* fall through */
1432*4e1bc9a0SAchim Leubner         default:
1433*4e1bc9a0SAchim Leubner             status        = tiIOFailed;
1434*4e1bc9a0SAchim Leubner             statusDetail  = tiDetailOtherError;
1435*4e1bc9a0SAchim Leubner             IOFailed      = agTRUE;
1436*4e1bc9a0SAchim Leubner             break;
1437*4e1bc9a0SAchim Leubner         } /* switch */
1438*4e1bc9a0SAchim Leubner 
1439*4e1bc9a0SAchim Leubner         /* for not found IO, we don't call OS */
1440*4e1bc9a0SAchim Leubner         if (ttdsaXchg->io_found == agTRUE)
1441*4e1bc9a0SAchim Leubner         {
1442*4e1bc9a0SAchim Leubner             ostiTargetTmCompleted(
1443*4e1bc9a0SAchim Leubner                     tiRoot,
1444*4e1bc9a0SAchim Leubner                     ttdsaXchg->IORequestBody.tiIORequest,
1445*4e1bc9a0SAchim Leubner                     status,
1446*4e1bc9a0SAchim Leubner                     statusDetail
1447*4e1bc9a0SAchim Leubner             );
1448*4e1bc9a0SAchim Leubner         }
1449*4e1bc9a0SAchim Leubner 
1450*4e1bc9a0SAchim Leubner         /* clean up resources */
1451*4e1bc9a0SAchim Leubner         ttdsaXchgFreeStruct(tiRoot, ttdsaXchg);
1452*4e1bc9a0SAchim Leubner 
1453*4e1bc9a0SAchim Leubner 
1454*4e1bc9a0SAchim Leubner     } /* TM Request */
1455*4e1bc9a0SAchim Leubner     return;
1456*4e1bc9a0SAchim Leubner }
1457*4e1bc9a0SAchim Leubner 
1458*4e1bc9a0SAchim Leubner osGLOBAL void
ttdsaTMProcess(tiRoot_t * tiRoot,ttdsaXchg_t * ttdsaXchg)1459*4e1bc9a0SAchim Leubner ttdsaTMProcess(
1460*4e1bc9a0SAchim Leubner         tiRoot_t    *tiRoot,
1461*4e1bc9a0SAchim Leubner         ttdsaXchg_t *ttdsaXchg
1462*4e1bc9a0SAchim Leubner )
1463*4e1bc9a0SAchim Leubner {
1464*4e1bc9a0SAchim Leubner     tdsaRoot_t                *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
1465*4e1bc9a0SAchim Leubner     tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1466*4e1bc9a0SAchim Leubner 
1467*4e1bc9a0SAchim Leubner     ttdsaTgt_t                *Target = (ttdsaTgt_t *)tdsaAllShared->ttdsaTgt;
1468*4e1bc9a0SAchim Leubner     agsaSSPScsiTaskMgntReq_t  *agTMIU;
1469*4e1bc9a0SAchim Leubner     bit8                       TMFun;
1470*4e1bc9a0SAchim Leubner     bit32                      tiTMFun;
1471*4e1bc9a0SAchim Leubner     tiIORequest_t              *reftiIORequest = agNULL;
1472*4e1bc9a0SAchim Leubner     tdList_t                   *IOList;
1473*4e1bc9a0SAchim Leubner     bit32                      IOFound = agFALSE;
1474*4e1bc9a0SAchim Leubner     ttdsaXchg_t                *tmp_ttdsaXchg = agNULL;
1475*4e1bc9a0SAchim Leubner     agsaRoot_t                 *agRoot = (agsaRoot_t *)&(tdsaAllShared->agRootNonInt);
1476*4e1bc9a0SAchim Leubner     agsaIORequest_t            *agIORequest = agNULL;
1477*4e1bc9a0SAchim Leubner     agsaIORequest_t            *agIOAbortRequest = agNULL;
1478*4e1bc9a0SAchim Leubner     tdsaDeviceData_t           *oneDeviceData = agNULL;
1479*4e1bc9a0SAchim Leubner     agsaDevHandle_t            *agDevHandle = agNULL;
1480*4e1bc9a0SAchim Leubner 
1481*4e1bc9a0SAchim Leubner     TI_DBG1(("ttdsaTMProcess: start\n"));
1482*4e1bc9a0SAchim Leubner 
1483*4e1bc9a0SAchim Leubner     ttdsaXchg->isTMRequest = agTRUE;
1484*4e1bc9a0SAchim Leubner 
1485*4e1bc9a0SAchim Leubner     agTMIU = (agsaSSPScsiTaskMgntReq_t *)&(ttdsaXchg->agTMIU);
1486*4e1bc9a0SAchim Leubner     TMFun = agTMIU->taskMgntFunction;
1487*4e1bc9a0SAchim Leubner 
1488*4e1bc9a0SAchim Leubner     switch (TMFun)
1489*4e1bc9a0SAchim Leubner     {
1490*4e1bc9a0SAchim Leubner     case AGSA_ABORT_TASK:
1491*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaTMProcess: ABORT_TASK\n"));
1492*4e1bc9a0SAchim Leubner         tiTMFun = AG_ABORT_TASK;
1493*4e1bc9a0SAchim Leubner         break;
1494*4e1bc9a0SAchim Leubner     case AGSA_ABORT_TASK_SET:
1495*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaTMProcess: ABORT_TASK_SET\n"));
1496*4e1bc9a0SAchim Leubner         tiTMFun = AG_ABORT_TASK_SET;
1497*4e1bc9a0SAchim Leubner         break;
1498*4e1bc9a0SAchim Leubner     case AGSA_CLEAR_TASK_SET:
1499*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaTMProcess: CLEAR_TASK_SET\n"));
1500*4e1bc9a0SAchim Leubner         tiTMFun = AG_CLEAR_TASK_SET;
1501*4e1bc9a0SAchim Leubner         break;
1502*4e1bc9a0SAchim Leubner     case AGSA_LOGICAL_UNIT_RESET:
1503*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaTMProcess: LOGICAL_UNIT_RESET\n"));
1504*4e1bc9a0SAchim Leubner         tiTMFun = AG_LOGICAL_UNIT_RESET;
1505*4e1bc9a0SAchim Leubner         break;
1506*4e1bc9a0SAchim Leubner     case AGSA_CLEAR_ACA:
1507*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaTMProcess: CLEAR_ACA\n"));
1508*4e1bc9a0SAchim Leubner         tiTMFun = AG_CLEAR_ACA;
1509*4e1bc9a0SAchim Leubner         break;
1510*4e1bc9a0SAchim Leubner     case AGSA_QUERY_TASK:
1511*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaTMProcess: QUERY_TASK\n"));
1512*4e1bc9a0SAchim Leubner         tiTMFun = AG_QUERY_TASK;
1513*4e1bc9a0SAchim Leubner         break;
1514*4e1bc9a0SAchim Leubner     default:
1515*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaTMProcess: RESERVED TM 0x%x %d\n", TMFun, TMFun));
1516*4e1bc9a0SAchim Leubner         tiTMFun = 0xff; /* unknown task management request */
1517*4e1bc9a0SAchim Leubner         break;
1518*4e1bc9a0SAchim Leubner     }
1519*4e1bc9a0SAchim Leubner 
1520*4e1bc9a0SAchim Leubner     /*
1521*4e1bc9a0SAchim Leubner      * Give the OS Specific module to apply it's Task management policy.
1522*4e1bc9a0SAchim Leubner      */
1523*4e1bc9a0SAchim Leubner 
1524*4e1bc9a0SAchim Leubner 
1525*4e1bc9a0SAchim Leubner     /*
1526*4e1bc9a0SAchim Leubner      osGLOBAL void ostiTaskManagement (
1527*4e1bc9a0SAchim Leubner                         tiRoot_t          *tiRoot,
1528*4e1bc9a0SAchim Leubner                         bit32             task,
1529*4e1bc9a0SAchim Leubner                         bit8              *scsiLun,
1530*4e1bc9a0SAchim Leubner                         tiIORequest_t     *refTiIORequest,
1531*4e1bc9a0SAchim Leubner                         tiIORequest_t     *tiTMRequest,
1532*4e1bc9a0SAchim Leubner                         tiDeviceHandle_t  *tiDeviceHandle);
1533*4e1bc9a0SAchim Leubner      */
1534*4e1bc9a0SAchim Leubner     if (TMFun == AGSA_ABORT_TASK)
1535*4e1bc9a0SAchim Leubner     {
1536*4e1bc9a0SAchim Leubner         TI_DBG1(("ttdsaTMProcess: if abort task; to be tested \n"));
1537*4e1bc9a0SAchim Leubner         /*
1538*4e1bc9a0SAchim Leubner       needs to find a reftIIORequest and set it
1539*4e1bc9a0SAchim Leubner          */
1540*4e1bc9a0SAchim Leubner 
1541*4e1bc9a0SAchim Leubner         IOList = Target->ttdsaXchgData.xchgBusyList.flink;
1542*4e1bc9a0SAchim Leubner         IOFound = agFALSE;
1543*4e1bc9a0SAchim Leubner 
1544*4e1bc9a0SAchim Leubner         /* search through the current IOList */
1545*4e1bc9a0SAchim Leubner         while (IOList != &Target->ttdsaXchgData.xchgBusyList)
1546*4e1bc9a0SAchim Leubner         {
1547*4e1bc9a0SAchim Leubner 
1548*4e1bc9a0SAchim Leubner             tmp_ttdsaXchg = TDLIST_OBJECT_BASE(ttdsaXchg_t, XchgLinks, IOList);
1549*4e1bc9a0SAchim Leubner             if (tmp_ttdsaXchg->tag == agTMIU->tagOfTaskToBeManaged)
1550*4e1bc9a0SAchim Leubner             {
1551*4e1bc9a0SAchim Leubner                 TI_DBG1(("ttdsaTMProcess: tag 0x%x\n",tmp_ttdsaXchg->tag));
1552*4e1bc9a0SAchim Leubner                 IOFound = agTRUE;
1553*4e1bc9a0SAchim Leubner                 break;
1554*4e1bc9a0SAchim Leubner             }
1555*4e1bc9a0SAchim Leubner             IOList = IOList->flink;
1556*4e1bc9a0SAchim Leubner         } /* while */
1557*4e1bc9a0SAchim Leubner 
1558*4e1bc9a0SAchim Leubner         if (IOFound == agTRUE)
1559*4e1bc9a0SAchim Leubner         {
1560*4e1bc9a0SAchim Leubner 
1561*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaTMProcess: found \n"));
1562*4e1bc9a0SAchim Leubner             /* call saSSPAbort() */
1563*4e1bc9a0SAchim Leubner 
1564*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaTMProcess: loc 1\n"));
1565*4e1bc9a0SAchim Leubner             /* abort taskmanagement itself */
1566*4e1bc9a0SAchim Leubner             agIOAbortRequest = (agsaIORequest_t *)&(ttdsaXchg->IORequestBody.agIORequest);
1567*4e1bc9a0SAchim Leubner 
1568*4e1bc9a0SAchim Leubner             /* IO to be aborted */
1569*4e1bc9a0SAchim Leubner             agIORequest = (agsaIORequest_t *)&(tmp_ttdsaXchg->IORequestBody.agIORequest);
1570*4e1bc9a0SAchim Leubner             oneDeviceData = tmp_ttdsaXchg->DeviceData;
1571*4e1bc9a0SAchim Leubner             agDevHandle = oneDeviceData->agDevHandle;
1572*4e1bc9a0SAchim Leubner 
1573*4e1bc9a0SAchim Leubner             if (agIORequest == agNULL)
1574*4e1bc9a0SAchim Leubner             {
1575*4e1bc9a0SAchim Leubner                 TI_DBG1(("ttdsaTMProcess: agIORequest is NULL\n"));
1576*4e1bc9a0SAchim Leubner             }
1577*4e1bc9a0SAchim Leubner             else
1578*4e1bc9a0SAchim Leubner             {
1579*4e1bc9a0SAchim Leubner               TI_DBG1(("ttdsaTMProcess: agIORequest is NOT NULL\n"));
1580*4e1bc9a0SAchim Leubner               if (agIORequest->sdkData == agNULL)
1581*4e1bc9a0SAchim Leubner               {
1582*4e1bc9a0SAchim Leubner                 TI_DBG1(("ttdsaTMProcess: agIORequest->saData is NULL\n"));
1583*4e1bc9a0SAchim Leubner               }
1584*4e1bc9a0SAchim Leubner               else
1585*4e1bc9a0SAchim Leubner               {
1586*4e1bc9a0SAchim Leubner                 TI_DBG1(("ttdsaTMProcess: agIORequest->saData is NOT NULL\n"));
1587*4e1bc9a0SAchim Leubner #ifdef RPM_SOC
1588*4e1bc9a0SAchim Leubner                 saSSPAbort(agRoot, agIORequest);
1589*4e1bc9a0SAchim Leubner #else
1590*4e1bc9a0SAchim Leubner                 saSSPAbort(agRoot, agIOAbortRequest,0,agDevHandle,0,agIORequest, agNULL);
1591*4e1bc9a0SAchim Leubner #endif
1592*4e1bc9a0SAchim Leubner               }
1593*4e1bc9a0SAchim Leubner             }
1594*4e1bc9a0SAchim Leubner 
1595*4e1bc9a0SAchim Leubner         } /* FOUND */
1596*4e1bc9a0SAchim Leubner         else
1597*4e1bc9a0SAchim Leubner         {
1598*4e1bc9a0SAchim Leubner             ttdsaXchg->io_found = agFALSE;
1599*4e1bc9a0SAchim Leubner             tiTGTSendTmResp(tiRoot,
1600*4e1bc9a0SAchim Leubner                     ttdsaXchg->IORequestBody.tiIORequest,
1601*4e1bc9a0SAchim Leubner                     tiError /* this is FUNCTION_FAILED */ );
1602*4e1bc9a0SAchim Leubner             TI_DBG1(("ttdsaTMProcess: ABORT_TASK not found\n"));
1603*4e1bc9a0SAchim Leubner             return;
1604*4e1bc9a0SAchim Leubner         }
1605*4e1bc9a0SAchim Leubner 
1606*4e1bc9a0SAchim Leubner     } /* ABORT_TASK */
1607*4e1bc9a0SAchim Leubner     /*
1608*4e1bc9a0SAchim Leubner     reftiIORequest: referred IO request.
1609*4e1bc9a0SAchim Leubner     If found, not null. But not used in ramdisk
1610*4e1bc9a0SAchim Leubner      */
1611*4e1bc9a0SAchim Leubner     TI_DBG1(("ttdsaTMProcess: calling ostiTaskManagement\n"));
1612*4e1bc9a0SAchim Leubner     ostiTaskManagement(
1613*4e1bc9a0SAchim Leubner             tiRoot,
1614*4e1bc9a0SAchim Leubner             tiTMFun,
1615*4e1bc9a0SAchim Leubner             ttdsaXchg->agTMIU.lun,
1616*4e1bc9a0SAchim Leubner             reftiIORequest,
1617*4e1bc9a0SAchim Leubner             ttdsaXchg->IORequestBody.tiIORequest,
1618*4e1bc9a0SAchim Leubner             &ttdsaXchg->DeviceData->tiDeviceHandle
1619*4e1bc9a0SAchim Leubner     );
1620*4e1bc9a0SAchim Leubner 
1621*4e1bc9a0SAchim Leubner 
1622*4e1bc9a0SAchim Leubner 
1623*4e1bc9a0SAchim Leubner     return;
1624*4e1bc9a0SAchim Leubner }
1625*4e1bc9a0SAchim Leubner 
1626*4e1bc9a0SAchim Leubner /*****************************************************************************
1627*4e1bc9a0SAchim Leubner  *
1628*4e1bc9a0SAchim Leubner  *  tiTGTIOAbort
1629*4e1bc9a0SAchim Leubner  *
1630*4e1bc9a0SAchim Leubner  *  Purpose: This function is called to abort an IO previously reported
1631*4e1bc9a0SAchim Leubner  *           to oslayer through ostiProcessRequest() function.
1632*4e1bc9a0SAchim Leubner  *
1633*4e1bc9a0SAchim Leubner  *  Parameters:
1634*4e1bc9a0SAchim Leubner  *   tiRoot:         Pointer to driver Instance.
1635*4e1bc9a0SAchim Leubner  *   tiIORequest:    Pointer to the I/O request context for this I/O.
1636*4e1bc9a0SAchim Leubner  *                   This context was initially passed to the OS Specific
1637*4e1bc9a0SAchim Leubner  *                   Module in ostiProcessScsiReq().
1638*4e1bc9a0SAchim Leubner  *  Return:
1639*4e1bc9a0SAchim Leubner  *   tiSuccess:      Abort request was successfully initiated
1640*4e1bc9a0SAchim Leubner  *   tiBusy:         No resources available, try again later
1641*4e1bc9a0SAchim Leubner  *   tiError:        Other errors that prevent the abort request from being
1642*4e1bc9a0SAchim Leubner  *                   started
1643*4e1bc9a0SAchim Leubner  *  Note:
1644*4e1bc9a0SAchim Leubner  *
1645*4e1bc9a0SAchim Leubner  *****************************************************************************/
1646*4e1bc9a0SAchim Leubner osGLOBAL bit32
tiTGTIOAbort(tiRoot_t * tiRoot,tiIORequest_t * taskTag)1647*4e1bc9a0SAchim Leubner tiTGTIOAbort (
1648*4e1bc9a0SAchim Leubner         tiRoot_t            *tiRoot,
1649*4e1bc9a0SAchim Leubner         tiIORequest_t       *taskTag
1650*4e1bc9a0SAchim Leubner )
1651*4e1bc9a0SAchim Leubner {
1652*4e1bc9a0SAchim Leubner     ttdsaXchg_t                 *ttdsaXchg;
1653*4e1bc9a0SAchim Leubner     ttdsaXchg_t                 *ttdsaIOAbortXchg;
1654*4e1bc9a0SAchim Leubner     tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
1655*4e1bc9a0SAchim Leubner     tdsaContext_t               *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1656*4e1bc9a0SAchim Leubner     agsaRoot_t                  *agRoot = (agsaRoot_t *)&(tdsaAllShared->agRootNonInt);
1657*4e1bc9a0SAchim Leubner     agsaIORequest_t             *agIORequest = agNULL;
1658*4e1bc9a0SAchim Leubner     agsaIORequest_t             *agIOAbortRequest = agNULL;
1659*4e1bc9a0SAchim Leubner     tdsaDeviceData_t            *oneDeviceData = agNULL;
1660*4e1bc9a0SAchim Leubner     agsaDevHandle_t             *agDevHandle = agNULL;
1661*4e1bc9a0SAchim Leubner 
1662*4e1bc9a0SAchim Leubner     TI_DBG1(("tiTGTIOAbort: start\n"));
1663*4e1bc9a0SAchim Leubner 
1664*4e1bc9a0SAchim Leubner     ttdsaXchg        = (ttdsaXchg_t *)taskTag->tdData;
1665*4e1bc9a0SAchim Leubner 
1666*4e1bc9a0SAchim Leubner     if (ttdsaXchg == agNULL)
1667*4e1bc9a0SAchim Leubner     {
1668*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTIOAbort: IOError 1 \n"));
1669*4e1bc9a0SAchim Leubner         /*
1670*4e1bc9a0SAchim Leubner          * this exchange has already been freed.
1671*4e1bc9a0SAchim Leubner          * No need to free it
1672*4e1bc9a0SAchim Leubner          */
1673*4e1bc9a0SAchim Leubner         ostiTargetIOError(
1674*4e1bc9a0SAchim Leubner                 tiRoot,
1675*4e1bc9a0SAchim Leubner                 taskTag,
1676*4e1bc9a0SAchim Leubner                 tiIOFailed,
1677*4e1bc9a0SAchim Leubner                 tiDetailAborted
1678*4e1bc9a0SAchim Leubner         );
1679*4e1bc9a0SAchim Leubner     }
1680*4e1bc9a0SAchim Leubner     else if (ttdsaXchg->IORequestBody.agIORequest.sdkData == agNULL)
1681*4e1bc9a0SAchim Leubner     {
1682*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTIOAbort: IOError 2 \n"));
1683*4e1bc9a0SAchim Leubner         /* We have not issued this IO to the salayer.
1684*4e1bc9a0SAchim Leubner          * Abort it right here.
1685*4e1bc9a0SAchim Leubner          */
1686*4e1bc9a0SAchim Leubner         if (TD_XCHG_GET_STATE(ttdsaXchg) == TD_XCHG_STATE_INACTIVE)
1687*4e1bc9a0SAchim Leubner         {
1688*4e1bc9a0SAchim Leubner             TI_DBG1(("tiTGTIOAbort: wrong DEQUEUE_THIS\n"));
1689*4e1bc9a0SAchim Leubner         }
1690*4e1bc9a0SAchim Leubner 
1691*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTIOAbort: IOError 3\n"));
1692*4e1bc9a0SAchim Leubner 
1693*4e1bc9a0SAchim Leubner         ostiTargetIOError(
1694*4e1bc9a0SAchim Leubner                 tiRoot,
1695*4e1bc9a0SAchim Leubner                 taskTag,
1696*4e1bc9a0SAchim Leubner                 tiIOFailed,
1697*4e1bc9a0SAchim Leubner                 tiDetailAborted
1698*4e1bc9a0SAchim Leubner         );
1699*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTIOAbort: IOError 4\n"));
1700*4e1bc9a0SAchim Leubner 
1701*4e1bc9a0SAchim Leubner         ttdsaXchgFreeStruct(
1702*4e1bc9a0SAchim Leubner                 ttdsaXchg->tiRoot,
1703*4e1bc9a0SAchim Leubner                 ttdsaXchg
1704*4e1bc9a0SAchim Leubner         );
1705*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTIOAbort: IOError 5\n"));
1706*4e1bc9a0SAchim Leubner 
1707*4e1bc9a0SAchim Leubner     }
1708*4e1bc9a0SAchim Leubner     else /* to be tested */
1709*4e1bc9a0SAchim Leubner     {
1710*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTIOAbort: aborting; to be tested \n"));
1711*4e1bc9a0SAchim Leubner         /* abort io request itself */
1712*4e1bc9a0SAchim Leubner         ttdsaIOAbortXchg = ttdsaXchgGetStruct(agRoot);
1713*4e1bc9a0SAchim Leubner 
1714*4e1bc9a0SAchim Leubner         if (ttdsaIOAbortXchg == agNULL)
1715*4e1bc9a0SAchim Leubner         {
1716*4e1bc9a0SAchim Leubner             TI_DBG1(("tiTGTIOAbort: no free xchg structures\n"));
1717*4e1bc9a0SAchim Leubner             //      ttdsaDumpallXchg(tiRoot);
1718*4e1bc9a0SAchim Leubner             return tiError;
1719*4e1bc9a0SAchim Leubner         }
1720*4e1bc9a0SAchim Leubner         ttdsaIOAbortXchg->agRoot  = agRoot;
1721*4e1bc9a0SAchim Leubner         ttdsaIOAbortXchg->tiRoot  = tiRoot;
1722*4e1bc9a0SAchim Leubner         agIOAbortRequest= &(ttdsaXchg->IORequestBody.agIORequest);
1723*4e1bc9a0SAchim Leubner         /* remember IO to be aborted */
1724*4e1bc9a0SAchim Leubner         ttdsaIOAbortXchg->tiIOToBeAbortedRequest  = taskTag;
1725*4e1bc9a0SAchim Leubner         ttdsaIOAbortXchg->XchgToBeAborted = ttdsaXchg;
1726*4e1bc9a0SAchim Leubner 
1727*4e1bc9a0SAchim Leubner         //    ttdsaIOAbortXchg->FrameType = SAS_TM;
1728*4e1bc9a0SAchim Leubner 
1729*4e1bc9a0SAchim Leubner         /* io is being aborted */
1730*4e1bc9a0SAchim Leubner         ttdsaXchg->oslayerAborting = agTRUE;
1731*4e1bc9a0SAchim Leubner         agIORequest = (agsaIORequest_t *)&(ttdsaXchg->IORequestBody.agIORequest);
1732*4e1bc9a0SAchim Leubner         oneDeviceData = ttdsaXchg->DeviceData;
1733*4e1bc9a0SAchim Leubner         if (oneDeviceData == agNULL)
1734*4e1bc9a0SAchim Leubner         {
1735*4e1bc9a0SAchim Leubner             TI_DBG1(("tiTGTIOAbort: oneDeviceData is null; wrong\n"));
1736*4e1bc9a0SAchim Leubner         }
1737*4e1bc9a0SAchim Leubner         else
1738*4e1bc9a0SAchim Leubner         {
1739*4e1bc9a0SAchim Leubner           agDevHandle = oneDeviceData->agDevHandle;
1740*4e1bc9a0SAchim Leubner           ttdsaIOAbortXchg->DeviceData = oneDeviceData;
1741*4e1bc9a0SAchim Leubner         }
1742*4e1bc9a0SAchim Leubner #ifdef RPM_SOC
1743*4e1bc9a0SAchim Leubner         saSSPAbort(agRoot, agIORequest);
1744*4e1bc9a0SAchim Leubner #else
1745*4e1bc9a0SAchim Leubner         saSSPAbort(agRoot, agIOAbortRequest,0,agDevHandle,0,agIORequest, agNULL);
1746*4e1bc9a0SAchim Leubner     }
1747*4e1bc9a0SAchim Leubner 
1748*4e1bc9a0SAchim Leubner     return tiSuccess;
1749*4e1bc9a0SAchim Leubner }
1750*4e1bc9a0SAchim Leubner 
1751*4e1bc9a0SAchim Leubner osGLOBAL bit32
tiTGTIOAbortAll(tiRoot_t * tiRoot,tiDeviceHandle_t * tiDeviceHandle)1752*4e1bc9a0SAchim Leubner tiTGTIOAbortAll(
1753*4e1bc9a0SAchim Leubner         tiRoot_t            *tiRoot,
1754*4e1bc9a0SAchim Leubner         tiDeviceHandle_t    *tiDeviceHandle
1755*4e1bc9a0SAchim Leubner )
1756*4e1bc9a0SAchim Leubner {
1757*4e1bc9a0SAchim Leubner     agsaRoot_t                *agRoot = agNULL;
1758*4e1bc9a0SAchim Leubner     tdsaDeviceData_t          *oneDeviceData = agNULL;
1759*4e1bc9a0SAchim Leubner     bit32                     status = tiError;
1760*4e1bc9a0SAchim Leubner 
1761*4e1bc9a0SAchim Leubner     TI_DBG3(("tiTGTIOAbortAll: start\n"));
1762*4e1bc9a0SAchim Leubner 
1763*4e1bc9a0SAchim Leubner     oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
1764*4e1bc9a0SAchim Leubner 
1765*4e1bc9a0SAchim Leubner     if (oneDeviceData == agNULL)
1766*4e1bc9a0SAchim Leubner     {
1767*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTIOAbortAll: oneDeviceData is NULL!!!\n"));
1768*4e1bc9a0SAchim Leubner         return tiError;
1769*4e1bc9a0SAchim Leubner     }
1770*4e1bc9a0SAchim Leubner 
1771*4e1bc9a0SAchim Leubner     /* for hotplug */
1772*4e1bc9a0SAchim Leubner     if (oneDeviceData->valid != agTRUE || oneDeviceData->registered != agTRUE ||
1773*4e1bc9a0SAchim Leubner             oneDeviceData->tdPortContext == agNULL )
1774*4e1bc9a0SAchim Leubner     {
1775*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTIOAbortAll: NO Device did %d\n", oneDeviceData->id ));
1776*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTIOAbortAll: device AddrHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
1777*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTIOAbortAll: device AddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
1778*4e1bc9a0SAchim Leubner         return tiError;
1779*4e1bc9a0SAchim Leubner     }
1780*4e1bc9a0SAchim Leubner 
1781*4e1bc9a0SAchim Leubner     agRoot = oneDeviceData->agRoot;
1782*4e1bc9a0SAchim Leubner 
1783*4e1bc9a0SAchim Leubner     if (agRoot == agNULL)
1784*4e1bc9a0SAchim Leubner     {
1785*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTIOAbortAll: agRoot is NULL!!!\n"));
1786*4e1bc9a0SAchim Leubner         return tiError;
1787*4e1bc9a0SAchim Leubner     }
1788*4e1bc9a0SAchim Leubner 
1789*4e1bc9a0SAchim Leubner     /* this is processed in ossaSSPAbortCB, ossaSATAAbortCB, ossaSMPAbortCB */
1790*4e1bc9a0SAchim Leubner     oneDeviceData->OSAbortAll = agTRUE;
1791*4e1bc9a0SAchim Leubner 
1792*4e1bc9a0SAchim Leubner     status = tdsaAbortAll(tiRoot, agRoot, oneDeviceData);
1793*4e1bc9a0SAchim Leubner 
1794*4e1bc9a0SAchim Leubner     return status;
1795*4e1bc9a0SAchim Leubner 
1796*4e1bc9a0SAchim Leubner }
1797*4e1bc9a0SAchim Leubner 
1798*4e1bc9a0SAchim Leubner 
1799*4e1bc9a0SAchim Leubner /*****************************************************************************
1800*4e1bc9a0SAchim Leubner  *
1801*4e1bc9a0SAchim Leubner  *  tiTGTSendTmResp
1802*4e1bc9a0SAchim Leubner  *
1803*4e1bc9a0SAchim Leubner  *  Purpose: This function is called to abort an IO previously reported
1804*4e1bc9a0SAchim Leubner  *           to oslayer through ostiProcessRequest() function.
1805*4e1bc9a0SAchim Leubner  *
1806*4e1bc9a0SAchim Leubner  *  Parameters:
1807*4e1bc9a0SAchim Leubner  *   tiRoot:         Pointer to driver Instance.
1808*4e1bc9a0SAchim Leubner  *   tiIORequest:    Pointer to the I/O request context for this I/O.
1809*4e1bc9a0SAchim Leubner  *                   This context was initially passed to the OS Specific
1810*4e1bc9a0SAchim Leubner  *                   Module in ostiProcessScsiReq().
1811*4e1bc9a0SAchim Leubner  *  Return:
1812*4e1bc9a0SAchim Leubner  *   tiSuccess:      Abort request was successfully initiated
1813*4e1bc9a0SAchim Leubner  *   tiBusy:         No resources available, try again later
1814*4e1bc9a0SAchim Leubner  *   tiError:        Other errors that prevent the abort request from being
1815*4e1bc9a0SAchim Leubner  *                   started
1816*4e1bc9a0SAchim Leubner  *  Note:
1817*4e1bc9a0SAchim Leubner  *
1818*4e1bc9a0SAchim Leubner  *****************************************************************************/
1819*4e1bc9a0SAchim Leubner osGLOBAL bit32
tiTGTSendTmResp(tiRoot_t * tiRoot,tiIORequest_t * tiTMRequest,bit32 status)1820*4e1bc9a0SAchim Leubner tiTGTSendTmResp(
1821*4e1bc9a0SAchim Leubner         tiRoot_t          *tiRoot,
1822*4e1bc9a0SAchim Leubner         tiIORequest_t     *tiTMRequest,
1823*4e1bc9a0SAchim Leubner         bit32             status
1824*4e1bc9a0SAchim Leubner )
1825*4e1bc9a0SAchim Leubner {
1826*4e1bc9a0SAchim Leubner     ttdsaXchg_t               *ttdsaXchg;
1827*4e1bc9a0SAchim Leubner     sas_resp_t                *SASResp;
1828*4e1bc9a0SAchim Leubner     bit32                     tdStatus;
1829*4e1bc9a0SAchim Leubner     TI_DBG1(("tiTGTSendTmResp: start 1\n"));
1830*4e1bc9a0SAchim Leubner 
1831*4e1bc9a0SAchim Leubner     ttdsaXchg     = (ttdsaXchg_t *)tiTMRequest->tdData;
1832*4e1bc9a0SAchim Leubner     /* set the response and send it */
1833*4e1bc9a0SAchim Leubner     /* response status is 0 */
1834*4e1bc9a0SAchim Leubner     /* status is TM status */
1835*4e1bc9a0SAchim Leubner 
1836*4e1bc9a0SAchim Leubner     TI_DBG1(("tiTGTSendTmResp: start 2\n"));
1837*4e1bc9a0SAchim Leubner     SASResp = (sas_resp_t *)ttdsaXchg->resp.virtAddr;
1838*4e1bc9a0SAchim Leubner     TI_DBG1(("tiTGTSendTmResp: start 3\n"));
1839*4e1bc9a0SAchim Leubner 
1840*4e1bc9a0SAchim Leubner     if (ttdsaXchg->FrameType == SAS_TM)
1841*4e1bc9a0SAchim Leubner     {
1842*4e1bc9a0SAchim Leubner         SASResp->agResp.status = 0;
1843*4e1bc9a0SAchim Leubner         SASResp->agResp.dataPres = RESPONSE_DATA;
1844*4e1bc9a0SAchim Leubner         OSSA_WRITE_BE_32(agRoot, SASResp->agResp.responsedataLen, 0, RESPONSE_DATA_LEN);
1845*4e1bc9a0SAchim Leubner         OSSA_WRITE_BE_32(agRoot, SASResp->agResp.senseDataLen, 0, 0);
1846*4e1bc9a0SAchim Leubner         switch (status)
1847*4e1bc9a0SAchim Leubner         {
1848*4e1bc9a0SAchim Leubner         case tiSuccess:
1849*4e1bc9a0SAchim Leubner             TI_DBG2(("tiTGTSendTmResp: tiSuccess\n"));
1850*4e1bc9a0SAchim Leubner             SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_SUCCEEDED;
1851*4e1bc9a0SAchim Leubner             break;
1852*4e1bc9a0SAchim Leubner         case tiError:
1853*4e1bc9a0SAchim Leubner             TI_DBG1(("tiTGTSendTmResp: tiError\n"));
1854*4e1bc9a0SAchim Leubner             SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1855*4e1bc9a0SAchim Leubner             break;
1856*4e1bc9a0SAchim Leubner         case tiBusy:
1857*4e1bc9a0SAchim Leubner             TI_DBG1(("tiTGTSendTmResp: tibusy\n"));
1858*4e1bc9a0SAchim Leubner             SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1859*4e1bc9a0SAchim Leubner             break;
1860*4e1bc9a0SAchim Leubner         case tiIONoDevice:
1861*4e1bc9a0SAchim Leubner             TI_DBG1(("tiTGTSendTmResp: tiionodevicee\n"));
1862*4e1bc9a0SAchim Leubner             SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1863*4e1bc9a0SAchim Leubner             break;
1864*4e1bc9a0SAchim Leubner         case tiMemoryTooLarge:
1865*4e1bc9a0SAchim Leubner             TI_DBG1(("tiTGTSendTmResp: timemorytoolarge\n"));
1866*4e1bc9a0SAchim Leubner             SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1867*4e1bc9a0SAchim Leubner             break;
1868*4e1bc9a0SAchim Leubner         case tiMemoryNotAvail:
1869*4e1bc9a0SAchim Leubner             TI_DBG1(("tiTGTSendTmResp: timemorynotavail\n"));
1870*4e1bc9a0SAchim Leubner             SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1871*4e1bc9a0SAchim Leubner             break;
1872*4e1bc9a0SAchim Leubner         case tiInvalidHandle:
1873*4e1bc9a0SAchim Leubner             TI_DBG1(("tiTGTSendTmResp: tiinvalidhandle\n"));
1874*4e1bc9a0SAchim Leubner             SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1875*4e1bc9a0SAchim Leubner             break;
1876*4e1bc9a0SAchim Leubner         case tiNotSupported:
1877*4e1bc9a0SAchim Leubner             TI_DBG1(("tiTGTSendTmResp: tiNotsupported\n"));
1878*4e1bc9a0SAchim Leubner             SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_NOT_SUPPORTED;
1879*4e1bc9a0SAchim Leubner             break;
1880*4e1bc9a0SAchim Leubner         case tiReject:
1881*4e1bc9a0SAchim Leubner             TI_DBG1(("tiTGTSendTmResp: tireject\n"));
1882*4e1bc9a0SAchim Leubner             SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1883*4e1bc9a0SAchim Leubner             break;
1884*4e1bc9a0SAchim Leubner         case tiIncorrectLun:
1885*4e1bc9a0SAchim Leubner             TI_DBG1(("tiTGTSendTmResp: tiincorrectlun\n"));
1886*4e1bc9a0SAchim Leubner             SASResp->RespData[3] = AGSA_INCORRECT_LOGICAL_UNIT_NUMBER;
1887*4e1bc9a0SAchim Leubner             break;
1888*4e1bc9a0SAchim Leubner         default:
1889*4e1bc9a0SAchim Leubner             TI_DBG1(("tiTGTSendTmResp: default\n"));
1890*4e1bc9a0SAchim Leubner             SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1891*4e1bc9a0SAchim Leubner             break;
1892*4e1bc9a0SAchim Leubner         }
1893*4e1bc9a0SAchim Leubner         ttdsaXchg->resp.length = sizeof(agsaSSPResponseInfoUnit_t) + RESPONSE_DATA_LEN;
1894*4e1bc9a0SAchim Leubner         ttdsaXchg->statusSent = agTRUE;
1895*4e1bc9a0SAchim Leubner     }
1896*4e1bc9a0SAchim Leubner     else
1897*4e1bc9a0SAchim Leubner     {
1898*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTSendTmResp: not TM frame\n"));
1899*4e1bc9a0SAchim Leubner         return tiError;
1900*4e1bc9a0SAchim Leubner     }
1901*4e1bc9a0SAchim Leubner 
1902*4e1bc9a0SAchim Leubner     tdStatus = ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
1903*4e1bc9a0SAchim Leubner     if (tdStatus == AGSA_RC_SUCCESS)
1904*4e1bc9a0SAchim Leubner     {
1905*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTSendTmResp: send success\n"));
1906*4e1bc9a0SAchim Leubner         return tiSuccess;
1907*4e1bc9a0SAchim Leubner     }
1908*4e1bc9a0SAchim Leubner     else if (tdStatus == AGSA_RC_FAILURE)
1909*4e1bc9a0SAchim Leubner     {
1910*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTSendTmResp: sending not successful\n"));
1911*4e1bc9a0SAchim Leubner         return tiError;
1912*4e1bc9a0SAchim Leubner     }
1913*4e1bc9a0SAchim Leubner     else
1914*4e1bc9a0SAchim Leubner     {
1915*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTSendTmResp: send busy\n"));
1916*4e1bc9a0SAchim Leubner         return tiBusy;
1917*4e1bc9a0SAchim Leubner     }
1918*4e1bc9a0SAchim Leubner 
1919*4e1bc9a0SAchim Leubner 
1920*4e1bc9a0SAchim Leubner #ifdef REMOVED
1921*4e1bc9a0SAchim Leubner 
1922*4e1bc9a0SAchim Leubner     tiTGTSetResp(tiRoot, tiTMRequest, 0, 0, 0);
1923*4e1bc9a0SAchim Leubner #endif
1924*4e1bc9a0SAchim Leubner 
1925*4e1bc9a0SAchim Leubner #ifdef REMOVED
1926*4e1bc9a0SAchim Leubner 
1927*4e1bc9a0SAchim Leubner     if (ttdsaXchg->resp.length != 0)
1928*4e1bc9a0SAchim Leubner     {
1929*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTSendTmResp: respsonse is set \n"));
1930*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTSendTmResp: resp.length 0x%x\n",
1931*4e1bc9a0SAchim Leubner                 ttdsaXchg->resp.length));
1932*4e1bc9a0SAchim Leubner         ttdsaXchg->responseSent = agTRUE;
1933*4e1bc9a0SAchim Leubner 
1934*4e1bc9a0SAchim Leubner         ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
1935*4e1bc9a0SAchim Leubner     }
1936*4e1bc9a0SAchim Leubner     else
1937*4e1bc9a0SAchim Leubner     {
1938*4e1bc9a0SAchim Leubner         /* no respsonse is set, direct call */
1939*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTSendTmResp: direct call\n"));
1940*4e1bc9a0SAchim Leubner         tiTGTSetResp(tiRoot, tiTMRequest, 0, 0, 0);
1941*4e1bc9a0SAchim Leubner         ttdsaXchg->responseSent = agTRUE;
1942*4e1bc9a0SAchim Leubner         ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
1943*4e1bc9a0SAchim Leubner     }
1944*4e1bc9a0SAchim Leubner 
1945*4e1bc9a0SAchim Leubner #define TASK_MANAGEMENT_FUNCTION_COMPLETE         0x0
1946*4e1bc9a0SAchim Leubner #define INVALID_FRAME                             0x2
1947*4e1bc9a0SAchim Leubner #define TASK_MANAGEMENT_FUNCTION_NOT_SUPPORTED    0x4
1948*4e1bc9a0SAchim Leubner #define TASK_MANAGEMENT_FUNCTION_FAILED           0x5
1949*4e1bc9a0SAchim Leubner #define TASK_MANAGEMENT_FUNCTION_SUCCEEDED        0x8
1950*4e1bc9a0SAchim Leubner #define INVALID_LOGICAL_UNIT_NUMBER               0x9
1951*4e1bc9a0SAchim Leubner #endif
1952*4e1bc9a0SAchim Leubner 
1953*4e1bc9a0SAchim Leubner }
1954*4e1bc9a0SAchim Leubner 
1955*4e1bc9a0SAchim Leubner 
1956*4e1bc9a0SAchim Leubner 
1957*4e1bc9a0SAchim Leubner /*****************************************************************************
1958*4e1bc9a0SAchim Leubner  *
1959*4e1bc9a0SAchim Leubner  *  tiTGTSenseBufferGet
1960*4e1bc9a0SAchim Leubner  *
1961*4e1bc9a0SAchim Leubner  *  Purpose: This function is called to get the address of sense buffer from
1962*4e1bc9a0SAchim Leubner  *           the target specific Transport Dependent Layer.
1963*4e1bc9a0SAchim Leubner  *
1964*4e1bc9a0SAchim Leubner  *  Parameters:
1965*4e1bc9a0SAchim Leubner  *     tiRoot:        Pointer to driver/port instance.
1966*4e1bc9a0SAchim Leubner  *     tiIORequest:   I/O request context.
1967*4e1bc9a0SAchim Leubner  *     length:        Lenght in bytes of the sense buffer.
1968*4e1bc9a0SAchim Leubner  *
1969*4e1bc9a0SAchim Leubner  *  Return:  none
1970*4e1bc9a0SAchim Leubner  *
1971*4e1bc9a0SAchim Leubner  *  Note:
1972*4e1bc9a0SAchim Leubner  *
1973*4e1bc9a0SAchim Leubner  *****************************************************************************/
tiTGTSenseBufferGet(tiRoot_t * tiRoot,tiIORequest_t * tiIORequest,bit32 length)1974*4e1bc9a0SAchim Leubner osGLOBAL void *tiTGTSenseBufferGet( tiRoot_t      *tiRoot,
1975*4e1bc9a0SAchim Leubner         tiIORequest_t *tiIORequest,
1976*4e1bc9a0SAchim Leubner         bit32          length
1977*4e1bc9a0SAchim Leubner )
1978*4e1bc9a0SAchim Leubner {
1979*4e1bc9a0SAchim Leubner 
1980*4e1bc9a0SAchim Leubner     ttdsaXchg_t         *ttdsaXchg;
1981*4e1bc9a0SAchim Leubner 
1982*4e1bc9a0SAchim Leubner     ttdsaXchg = (ttdsaXchg_t *)tiIORequest->tdData;
1983*4e1bc9a0SAchim Leubner 
1984*4e1bc9a0SAchim Leubner     TI_DBG4(("tiTGTSenseBufferGet: start\n"));
1985*4e1bc9a0SAchim Leubner     OS_ASSERT((length <= 64), "length too big in tiTGTSenseBufferGet");
1986*4e1bc9a0SAchim Leubner 
1987*4e1bc9a0SAchim Leubner     return &ttdsaXchg->resp.virtAddr[sizeof(agsaSSPResponseInfoUnit_t)];
1988*4e1bc9a0SAchim Leubner }
1989*4e1bc9a0SAchim Leubner 
1990*4e1bc9a0SAchim Leubner /*****************************************************************************
1991*4e1bc9a0SAchim Leubner  *
1992*4e1bc9a0SAchim Leubner  *  tiTGTSetResp
1993*4e1bc9a0SAchim Leubner  *
1994*4e1bc9a0SAchim Leubner  *  Purpose: This function is called when the target OS Specific Module is ready
1995*4e1bc9a0SAchim Leubner  *           to send a response with the next tiTGTIOStart()
1996*4e1bc9a0SAchim Leubner  *           function call. This function allows the TD Layer to setup its
1997*4e1bc9a0SAchim Leubner  *           portion of the status and mark it to be sent on the next
1998*4e1bc9a0SAchim Leubner  *           tiTGTIOStart() function call.
1999*4e1bc9a0SAchim Leubner  *
2000*4e1bc9a0SAchim Leubner  *  Parameters:
2001*4e1bc9a0SAchim Leubner  *   tiRoot:         Pointer to driver Instance.
2002*4e1bc9a0SAchim Leubner  *   tiIORequest:    Pointer to the I/O request context for this I/O.
2003*4e1bc9a0SAchim Leubner  *                   This context was initially passed to the OS Specific Module
2004*4e1bc9a0SAchim Leubner  *                   in ostiProcessScsiReq().
2005*4e1bc9a0SAchim Leubner  *   dataSentLength: How much data sent or received for this Request.
2006*4e1bc9a0SAchim Leubner  *   ScsiStatus:     Status for this SCSI command.
2007*4e1bc9a0SAchim Leubner  *   senseLength:    Length of sense data if any.
2008*4e1bc9a0SAchim Leubner  *
2009*4e1bc9a0SAchim Leubner  *  Return: none
2010*4e1bc9a0SAchim Leubner  *
2011*4e1bc9a0SAchim Leubner  *  Note:
2012*4e1bc9a0SAchim Leubner  *
2013*4e1bc9a0SAchim Leubner  *****************************************************************************/
2014*4e1bc9a0SAchim Leubner osGLOBAL void
tiTGTSetResp(tiRoot_t * tiRoot,tiIORequest_t * tiIORequest,bit32 dataSentLength,bit8 ScsiStatus,bit32 senseLength)2015*4e1bc9a0SAchim Leubner tiTGTSetResp( tiRoot_t        *tiRoot,
2016*4e1bc9a0SAchim Leubner         tiIORequest_t   *tiIORequest,
2017*4e1bc9a0SAchim Leubner         bit32            dataSentLength,
2018*4e1bc9a0SAchim Leubner         bit8             ScsiStatus,
2019*4e1bc9a0SAchim Leubner         bit32            senseLength
2020*4e1bc9a0SAchim Leubner )
2021*4e1bc9a0SAchim Leubner {
2022*4e1bc9a0SAchim Leubner     /* no call to saSSPStart() in this function */
2023*4e1bc9a0SAchim Leubner     /*
2024*4e1bc9a0SAchim Leubner     response is normally for task management
2025*4e1bc9a0SAchim Leubner     sense is for command with error
2026*4e1bc9a0SAchim Leubner     need to know this is for TM or cmd
2027*4e1bc9a0SAchim Leubner      */
2028*4e1bc9a0SAchim Leubner     /*
2029*4e1bc9a0SAchim Leubner   tiTGTSetResp(rdRoot->pTiRoot,
2030*4e1bc9a0SAchim Leubner                rdIORequest->tiIORequest,
2031*4e1bc9a0SAchim Leubner                dataSentLength,
2032*4e1bc9a0SAchim Leubner                ScsiStatus,
2033*4e1bc9a0SAchim Leubner                senseLength);
2034*4e1bc9a0SAchim Leubner 
2035*4e1bc9a0SAchim Leubner 
2036*4e1bc9a0SAchim Leubner 
2037*4e1bc9a0SAchim Leubner      */
2038*4e1bc9a0SAchim Leubner     ttdsaXchg_t               *ttdsaXchg;
2039*4e1bc9a0SAchim Leubner     tdsaRoot_t                *tdsaRoot  = (tdsaRoot_t *)tiRoot->tdData;
2040*4e1bc9a0SAchim Leubner #ifdef REMOVED
2041*4e1bc9a0SAchim Leubner     agsaSSPTargetResponse_t   *agSSPTargetResp;
2042*4e1bc9a0SAchim Leubner #endif
2043*4e1bc9a0SAchim Leubner     sas_resp_t                *SASResp;
2044*4e1bc9a0SAchim Leubner     bit32                      TotalRespLen = 0;
2045*4e1bc9a0SAchim Leubner 
2046*4e1bc9a0SAchim Leubner     TI_DBG4 (("tiTGTSetResp: start\n"));
2047*4e1bc9a0SAchim Leubner     TI_DBG4 (("tiTGTSetResp: datelen %d senselen %d\n", dataSentLength, senseLength));
2048*4e1bc9a0SAchim Leubner 
2049*4e1bc9a0SAchim Leubner     ttdsaXchg = (ttdsaXchg_t *)tiIORequest->tdData;
2050*4e1bc9a0SAchim Leubner     SASResp = (sas_resp_t *)ttdsaXchg->resp.virtAddr;
2051*4e1bc9a0SAchim Leubner 
2052*4e1bc9a0SAchim Leubner     SASResp->agResp.status = ScsiStatus;
2053*4e1bc9a0SAchim Leubner 
2054*4e1bc9a0SAchim Leubner     if (ttdsaXchg->FrameType == SAS_TM)
2055*4e1bc9a0SAchim Leubner     {
2056*4e1bc9a0SAchim Leubner 
2057*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTSetResp: TM\n"));
2058*4e1bc9a0SAchim Leubner         if (senseLength != 0)
2059*4e1bc9a0SAchim Leubner         {
2060*4e1bc9a0SAchim Leubner             TI_DBG1 (("tiTGTSetResp: non-zero sensedatalen for TM\n"));
2061*4e1bc9a0SAchim Leubner             return;
2062*4e1bc9a0SAchim Leubner         }
2063*4e1bc9a0SAchim Leubner         SASResp->agResp.dataPres = RESPONSE_DATA;
2064*4e1bc9a0SAchim Leubner         OSSA_WRITE_BE_32(agRoot, SASResp->agResp.responsedataLen, 0, RESPONSE_DATA_LEN);
2065*4e1bc9a0SAchim Leubner         OSSA_WRITE_BE_32(agRoot, SASResp->agResp.senseDataLen, 0, 0);
2066*4e1bc9a0SAchim Leubner         SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_NOT_SUPPORTED;
2067*4e1bc9a0SAchim Leubner         TotalRespLen = sizeof(agsaSSPResponseInfoUnit_t) + RESPONSE_DATA_LEN;
2068*4e1bc9a0SAchim Leubner     }
2069*4e1bc9a0SAchim Leubner     else
2070*4e1bc9a0SAchim Leubner     {
2071*4e1bc9a0SAchim Leubner         if (senseLength == 0)
2072*4e1bc9a0SAchim Leubner         {
2073*4e1bc9a0SAchim Leubner             TI_DBG4 (("tiTGTSetResp: CMND, no data\n"));
2074*4e1bc9a0SAchim Leubner             /* good and no data present */
2075*4e1bc9a0SAchim Leubner             SASResp->agResp.dataPres = NO_DATA;
2076*4e1bc9a0SAchim Leubner             OSSA_WRITE_BE_32(agRoot, SASResp->agResp.responsedataLen, 0, 0);
2077*4e1bc9a0SAchim Leubner             OSSA_WRITE_BE_32(agRoot, SASResp->agResp.senseDataLen, 0, 0);
2078*4e1bc9a0SAchim Leubner             TotalRespLen = sizeof(agsaSSPResponseInfoUnit_t);
2079*4e1bc9a0SAchim Leubner             /* collapse good response with READ */
2080*4e1bc9a0SAchim Leubner             if (ttdsaXchg->XchType == AGSA_SSP_TGT_READ_DATA)
2081*4e1bc9a0SAchim Leubner             {
2082*4e1bc9a0SAchim Leubner                 TI_DBG4(("tiTGTSetResp: read rsp collapse\n"));
2083*4e1bc9a0SAchim Leubner 
2084*4e1bc9a0SAchim Leubner                 if (tdsaRoot->autoGoodRSP & READ_GOOD_RESPONSE)
2085*4e1bc9a0SAchim Leubner                     ttdsaXchg->readRspCollapsed = agTRUE;
2086*4e1bc9a0SAchim Leubner             }
2087*4e1bc9a0SAchim Leubner             /* collapse good response with WRITE */
2088*4e1bc9a0SAchim Leubner             if (ttdsaXchg->XchType == AGSA_SSP_TGT_WRITE_DATA)
2089*4e1bc9a0SAchim Leubner             {
2090*4e1bc9a0SAchim Leubner                 TI_DBG4(("tiTGTSetResp: write rsp collapse\n"));
2091*4e1bc9a0SAchim Leubner                 if (tdsaRoot->autoGoodRSP & WRITE_GOOD_RESPONSE)
2092*4e1bc9a0SAchim Leubner                 {
2093*4e1bc9a0SAchim Leubner                   if (tiIS_SPC(TI_TIROOT_TO_AGROOT(tiRoot)))
2094*4e1bc9a0SAchim Leubner                   {
2095*4e1bc9a0SAchim Leubner                     ttdsaXchg->wrtRspCollapsed = agFALSE;
2096*4e1bc9a0SAchim Leubner                   }
2097*4e1bc9a0SAchim Leubner                   else
2098*4e1bc9a0SAchim Leubner                   {
2099*4e1bc9a0SAchim Leubner                     ttdsaXchg->wrtRspCollapsed = agTRUE;
2100*4e1bc9a0SAchim Leubner                   }
2101*4e1bc9a0SAchim Leubner 
2102*4e1bc9a0SAchim Leubner                 }
2103*4e1bc9a0SAchim Leubner             }
2104*4e1bc9a0SAchim Leubner         }
2105*4e1bc9a0SAchim Leubner         else
2106*4e1bc9a0SAchim Leubner         {
2107*4e1bc9a0SAchim Leubner             TI_DBG4 (("tiTGTSetResp: CMND, sense data\n"));
2108*4e1bc9a0SAchim Leubner             /* bad and sense data */
2109*4e1bc9a0SAchim Leubner             SASResp->agResp.dataPres = SENSE_DATA;
2110*4e1bc9a0SAchim Leubner             OSSA_WRITE_BE_32(agRoot, SASResp->agResp.responsedataLen, 0, 0);
2111*4e1bc9a0SAchim Leubner             OSSA_WRITE_BE_32(agRoot, SASResp->agResp.senseDataLen, 0, senseLength);
2112*4e1bc9a0SAchim Leubner             TotalRespLen = sizeof(agsaSSPResponseInfoUnit_t) + senseLength;
2113*4e1bc9a0SAchim Leubner         }
2114*4e1bc9a0SAchim Leubner     }
2115*4e1bc9a0SAchim Leubner 
2116*4e1bc9a0SAchim Leubner     ttdsaXchg->statusSent = agTRUE;
2117*4e1bc9a0SAchim Leubner 
2118*4e1bc9a0SAchim Leubner     TI_DBG4(("tiTGTSetResp: ttdsaXchg %p\n", ttdsaXchg));
2119*4e1bc9a0SAchim Leubner     TI_DBG4(("tiTGTSetResp: TotalRespLen 0x%x \n", TotalRespLen));
2120*4e1bc9a0SAchim Leubner     TI_DBG4(("tiTGTSetResp: upper 0x%x \n",
2121*4e1bc9a0SAchim Leubner             ttdsaXchg->resp.phyAddrUpper));
2122*4e1bc9a0SAchim Leubner     TI_DBG4(("tiTGTSetResp: lower 0x%x \n",
2123*4e1bc9a0SAchim Leubner             ttdsaXchg->resp.phyAddrLower));
2124*4e1bc9a0SAchim Leubner 
2125*4e1bc9a0SAchim Leubner 
2126*4e1bc9a0SAchim Leubner 
2127*4e1bc9a0SAchim Leubner     /* set the correct response length */
2128*4e1bc9a0SAchim Leubner     ttdsaXchg->resp.length = TotalRespLen;
2129*4e1bc9a0SAchim Leubner 
2130*4e1bc9a0SAchim Leubner     dumpresp((bit8 *)ttdsaXchg->resp.virtAddr, ttdsaXchg->resp.length);
2131*4e1bc9a0SAchim Leubner 
2132*4e1bc9a0SAchim Leubner #ifdef REMOVED
2133*4e1bc9a0SAchim Leubner     /*
2134*4e1bc9a0SAchim Leubner     send TM reponse (which has only  response data not sense data here
2135*4e1bc9a0SAchim Leubner     since ramdisk does not call IOstart for this
2136*4e1bc9a0SAchim Leubner      */
2137*4e1bc9a0SAchim Leubner 
2138*4e1bc9a0SAchim Leubner     if (ttdsaXchg->FrameType == SAS_TM)
2139*4e1bc9a0SAchim Leubner     {
2140*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTSetResp: respsonse is set \n"));
2141*4e1bc9a0SAchim Leubner         TI_DBG1(("tiTGTSetResp: resp.length 0x%x\n",
2142*4e1bc9a0SAchim Leubner                 ttdsaXchg->resp.length));
2143*4e1bc9a0SAchim Leubner         ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
2144*4e1bc9a0SAchim Leubner     }
2145*4e1bc9a0SAchim Leubner #endif
2146*4e1bc9a0SAchim Leubner #ifdef REMOVED
2147*4e1bc9a0SAchim Leubner     /* sas response */
2148*4e1bc9a0SAchim Leubner     agSSPTargetResp =
2149*4e1bc9a0SAchim Leubner             &(ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse);
2150*4e1bc9a0SAchim Leubner 
2151*4e1bc9a0SAchim Leubner     agSSPTargetResp->agTag = ttdsaXchg->tag;
2152*4e1bc9a0SAchim Leubner     agSSPTargetResp->respBufLength = TotalRespLen;
2153*4e1bc9a0SAchim Leubner     agSSPTargetResp->respBufUpper
2154*4e1bc9a0SAchim Leubner     = ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse.respBufUpper;
2155*4e1bc9a0SAchim Leubner     agSSPTargetResp->respBufLower
2156*4e1bc9a0SAchim Leubner     = ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse.respBufLower;
2157*4e1bc9a0SAchim Leubner 
2158*4e1bc9a0SAchim Leubner 
2159*4e1bc9a0SAchim Leubner 
2160*4e1bc9a0SAchim Leubner     TI_DBG4(("tiTGTSetResp: len 0x%x \n",
2161*4e1bc9a0SAchim Leubner             ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse.respBufLength));
2162*4e1bc9a0SAchim Leubner     TI_DBG4(("tiTGTSetResp: upper 0x%x \n",
2163*4e1bc9a0SAchim Leubner             ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse.respBufUpper));
2164*4e1bc9a0SAchim Leubner     TI_DBG4(("tiTGTSetResp: lower 0x%x \n",
2165*4e1bc9a0SAchim Leubner             ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse.respBufLower));
2166*4e1bc9a0SAchim Leubner #endif
2167*4e1bc9a0SAchim Leubner 
2168*4e1bc9a0SAchim Leubner     return;
2169*4e1bc9a0SAchim Leubner }
2170*4e1bc9a0SAchim Leubner 
2171*4e1bc9a0SAchim Leubner 
2172*4e1bc9a0SAchim Leubner 
2173*4e1bc9a0SAchim Leubner /******************************************************************************
2174*4e1bc9a0SAchim Leubner  *
2175*4e1bc9a0SAchim Leubner  *  tiTGTGetDeviceHandles
2176*4e1bc9a0SAchim Leubner  *
2177*4e1bc9a0SAchim Leubner  *  Purpose: This routine is called to to return the device handles for each
2178*4e1bc9a0SAchim Leubner  *           device currently available.
2179*4e1bc9a0SAchim Leubner  *
2180*4e1bc9a0SAchim Leubner  *  Parameters:
2181*4e1bc9a0SAchim Leubner  *     tiRoot:   Pointer to driver Instance.
2182*4e1bc9a0SAchim Leubner  *     agDev[]:  Array to receive pointers to the device handles.
2183*4e1bc9a0SAchim Leubner  *     maxDevs:  Number of device handles which will fit in array pointed
2184*4e1bc9a0SAchim Leubner  *               by agDev.
2185*4e1bc9a0SAchim Leubner  *  Return:
2186*4e1bc9a0SAchim Leubner  *    Number of device handle slots present (however, only maxDevs
2187*4e1bc9a0SAchim Leubner  *    are copied into tiDev[]) which may be greater than the number of
2188*4e1bc9a0SAchim Leubner  *    handles actually present.
2189*4e1bc9a0SAchim Leubner  *
2190*4e1bc9a0SAchim Leubner  *  Note:
2191*4e1bc9a0SAchim Leubner  *
2192*4e1bc9a0SAchim Leubner  ******************************************************************************/
2193*4e1bc9a0SAchim Leubner 
2194*4e1bc9a0SAchim Leubner osGLOBAL bit32
tiTGTGetDeviceHandles(tiRoot_t * tiRoot,tiPortalContext_t * tiPortalContext,tiDeviceHandle_t * tiDev[],bit32 maxDevs)2195*4e1bc9a0SAchim Leubner tiTGTGetDeviceHandles(
2196*4e1bc9a0SAchim Leubner         tiRoot_t            *tiRoot,
2197*4e1bc9a0SAchim Leubner         tiPortalContext_t   *tiPortalContext,
2198*4e1bc9a0SAchim Leubner         tiDeviceHandle_t    *tiDev[],
2199*4e1bc9a0SAchim Leubner         bit32               maxDevs
2200*4e1bc9a0SAchim Leubner )
2201*4e1bc9a0SAchim Leubner {
2202*4e1bc9a0SAchim Leubner     tdsaRoot_t                *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
2203*4e1bc9a0SAchim Leubner     tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2204*4e1bc9a0SAchim Leubner     ttdsaTgt_t                *Target = (ttdsaTgt_t *)tdsaAllShared->ttdsaTgt;
2205*4e1bc9a0SAchim Leubner     bit32                     deviceToReturn;
2206*4e1bc9a0SAchim Leubner     bit32                     devicePresent=0;
2207*4e1bc9a0SAchim Leubner     bit32                     deviceIndex=0;
2208*4e1bc9a0SAchim Leubner     tdList_t                  *PortContextList;
2209*4e1bc9a0SAchim Leubner     tdsaPortContext_t         *onePortContext = agNULL;
2210*4e1bc9a0SAchim Leubner     tdList_t                  *DeviceListList;
2211*4e1bc9a0SAchim Leubner     tdsaDeviceData_t          *oneDeviceData = agNULL;
2212*4e1bc9a0SAchim Leubner     bit32                     found = agFALSE;
2213*4e1bc9a0SAchim Leubner 
2214*4e1bc9a0SAchim Leubner 
2215*4e1bc9a0SAchim Leubner     TI_DBG4 (("tiTGTGetDeviceHandles: start\n"));
2216*4e1bc9a0SAchim Leubner 
2217*4e1bc9a0SAchim Leubner     /* Check boundary condition */
2218*4e1bc9a0SAchim Leubner     if (maxDevs > Target->OperatingOption.MaxTargets)
2219*4e1bc9a0SAchim Leubner     {
2220*4e1bc9a0SAchim Leubner         deviceToReturn = Target->OperatingOption.MaxTargets;
2221*4e1bc9a0SAchim Leubner     }
2222*4e1bc9a0SAchim Leubner     else
2223*4e1bc9a0SAchim Leubner     {
2224*4e1bc9a0SAchim Leubner         deviceToReturn = maxDevs;
2225*4e1bc9a0SAchim Leubner     }
2226*4e1bc9a0SAchim Leubner 
2227*4e1bc9a0SAchim Leubner 
2228*4e1bc9a0SAchim Leubner     /* make sure tiPortalContext is valid */
2229*4e1bc9a0SAchim Leubner     PortContextList = tdsaAllShared->MainPortContextList.flink;
2230*4e1bc9a0SAchim Leubner     while (PortContextList != &(tdsaAllShared->MainPortContextList))
2231*4e1bc9a0SAchim Leubner     {
2232*4e1bc9a0SAchim Leubner         onePortContext = TDLIST_OBJECT_BASE(tdsaPortContext_t, MainLink, PortContextList);
2233*4e1bc9a0SAchim Leubner         if (onePortContext->tiPortalContext == tiPortalContext)
2234*4e1bc9a0SAchim Leubner         {
2235*4e1bc9a0SAchim Leubner             TI_DBG4(("tiTGTGetDeviceHandles: found; oneportContext ID %d\n", onePortContext->id));
2236*4e1bc9a0SAchim Leubner             found = agTRUE;
2237*4e1bc9a0SAchim Leubner             break;
2238*4e1bc9a0SAchim Leubner         }
2239*4e1bc9a0SAchim Leubner         PortContextList = PortContextList->flink;
2240*4e1bc9a0SAchim Leubner     }
2241*4e1bc9a0SAchim Leubner 
2242*4e1bc9a0SAchim Leubner     if (found == agFALSE)
2243*4e1bc9a0SAchim Leubner     {
2244*4e1bc9a0SAchim Leubner         TI_DBG4(("tiTGTGetDeviceHandles: No corressponding tdsaPortContext\n"));
2245*4e1bc9a0SAchim Leubner         return 0;
2246*4e1bc9a0SAchim Leubner     }
2247*4e1bc9a0SAchim Leubner 
2248*4e1bc9a0SAchim Leubner 
2249*4e1bc9a0SAchim Leubner     /* go through device list and returns them */
2250*4e1bc9a0SAchim Leubner     DeviceListList = tdsaAllShared->MainDeviceList.flink;
2251*4e1bc9a0SAchim Leubner     while (DeviceListList != &(tdsaAllShared->MainDeviceList))
2252*4e1bc9a0SAchim Leubner     {
2253*4e1bc9a0SAchim Leubner         oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
2254*4e1bc9a0SAchim Leubner         TI_DBG4(("tiTGTGetDeviceHandles: pid %d did %d\n", onePortContext->id, oneDeviceData->id));
2255*4e1bc9a0SAchim Leubner         TI_DBG4(("tiTGTGetDeviceHandles: device AddrHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
2256*4e1bc9a0SAchim Leubner         TI_DBG4(("tiTGTGetDeviceHandles: device AddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
2257*4e1bc9a0SAchim Leubner         TI_DBG4(("tiTGTGetDeviceHandles: handle %p\n",  &(oneDeviceData->tiDeviceHandle)));
2258*4e1bc9a0SAchim Leubner         if (oneDeviceData->valid == agTRUE)
2259*4e1bc9a0SAchim Leubner         {
2260*4e1bc9a0SAchim Leubner             TI_DBG4(("tiTGTGetDeviceHandles: valid deviceindex %d devicePresent %d\n", deviceIndex, devicePresent));
2261*4e1bc9a0SAchim Leubner 
2262*4e1bc9a0SAchim Leubner             tiDev[deviceIndex] = &(oneDeviceData->tiDeviceHandle);
2263*4e1bc9a0SAchim Leubner             devicePresent++;
2264*4e1bc9a0SAchim Leubner         }
2265*4e1bc9a0SAchim Leubner         else
2266*4e1bc9a0SAchim Leubner         {
2267*4e1bc9a0SAchim Leubner             tiDev[deviceIndex] = agNULL;
2268*4e1bc9a0SAchim Leubner             TI_DBG4(("tiTGTGetDeviceHandles: not valid deviceindex %d devicePresent %d\n", deviceIndex, devicePresent));
2269*4e1bc9a0SAchim Leubner         }
2270*4e1bc9a0SAchim Leubner         deviceIndex++;
2271*4e1bc9a0SAchim Leubner 
2272*4e1bc9a0SAchim Leubner         if (devicePresent >= deviceToReturn )
2273*4e1bc9a0SAchim Leubner         {
2274*4e1bc9a0SAchim Leubner             break;
2275*4e1bc9a0SAchim Leubner         }
2276*4e1bc9a0SAchim Leubner         DeviceListList = DeviceListList->flink;
2277*4e1bc9a0SAchim Leubner     }
2278*4e1bc9a0SAchim Leubner 
2279*4e1bc9a0SAchim Leubner     return devicePresent;
2280*4e1bc9a0SAchim Leubner }
2281*4e1bc9a0SAchim Leubner 
2282*4e1bc9a0SAchim Leubner 
2283*4e1bc9a0SAchim Leubner 
2284*4e1bc9a0SAchim Leubner 
2285*4e1bc9a0SAchim Leubner /******************************************************************************
2286*4e1bc9a0SAchim Leubner  *
2287*4e1bc9a0SAchim Leubner  *  tiTGTGetDeviceInfo
2288*4e1bc9a0SAchim Leubner  *
2289*4e1bc9a0SAchim Leubner  *  Purpose: This routine is called to to return the device information for
2290*4e1bc9a0SAchim Leubner  *           specified device handle.
2291*4e1bc9a0SAchim Leubner  *
2292*4e1bc9a0SAchim Leubner  *  Parameters:
2293*4e1bc9a0SAchim Leubner  *     tiRoot:   Pointer to driver Instance.
2294*4e1bc9a0SAchim Leubner  *     tiDeviceHandle:  device handle associated with the device for which
2295*4e1bc9a0SAchim Leubner  *                      information is queried
2296*4e1bc9a0SAchim Leubner  *     tiDeviceInfo:    device information structure containing address and name.
2297*4e1bc9a0SAchim Leubner  *
2298*4e1bc9a0SAchim Leubner  *  Return:
2299*4e1bc9a0SAchim Leubner  *     tiSuccess: if the device handle is valid.
2300*4e1bc9a0SAchim Leubner  *     tiError  : if the device handle is not valid.
2301*4e1bc9a0SAchim Leubner  *
2302*4e1bc9a0SAchim Leubner  *  Note:
2303*4e1bc9a0SAchim Leubner  *
2304*4e1bc9a0SAchim Leubner  ******************************************************************************/
2305*4e1bc9a0SAchim Leubner osGLOBAL bit32
tiTGTGetDeviceInfo(tiRoot_t * tiRoot,tiDeviceHandle_t * tiDeviceHandle,tiDeviceInfo_t * tiDeviceInfo)2306*4e1bc9a0SAchim Leubner tiTGTGetDeviceInfo(
2307*4e1bc9a0SAchim Leubner         tiRoot_t            *tiRoot,
2308*4e1bc9a0SAchim Leubner         tiDeviceHandle_t    *tiDeviceHandle,
2309*4e1bc9a0SAchim Leubner         tiDeviceInfo_t      *tiDeviceInfo)
2310*4e1bc9a0SAchim Leubner {
2311*4e1bc9a0SAchim Leubner     tdsaDeviceData_t       *oneDeviceData = agNULL;
2312*4e1bc9a0SAchim Leubner 
2313*4e1bc9a0SAchim Leubner 
2314*4e1bc9a0SAchim Leubner     TI_DBG4 (("tiTGTGetDeviceInfo: start\n"));
2315*4e1bc9a0SAchim Leubner 
2316*4e1bc9a0SAchim Leubner     if (tiDeviceHandle == agNULL)
2317*4e1bc9a0SAchim Leubner     {
2318*4e1bc9a0SAchim Leubner         TI_DBG4 (("tiTGTGetDeviceInfo: tiDeviceHandle is NULL\n"));
2319*4e1bc9a0SAchim Leubner         return tiError;
2320*4e1bc9a0SAchim Leubner     }
2321*4e1bc9a0SAchim Leubner 
2322*4e1bc9a0SAchim Leubner     oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
2323*4e1bc9a0SAchim Leubner 
2324*4e1bc9a0SAchim Leubner     if (oneDeviceData == agNULL)
2325*4e1bc9a0SAchim Leubner     {
2326*4e1bc9a0SAchim Leubner         TI_DBG4 (("tiTGTGetDeviceInfo: oneDeviceData is NULL\n"));
2327*4e1bc9a0SAchim Leubner         return tiError;
2328*4e1bc9a0SAchim Leubner     }
2329*4e1bc9a0SAchim Leubner 
2330*4e1bc9a0SAchim Leubner     /* filling in the link rate */
2331*4e1bc9a0SAchim Leubner     if (oneDeviceData->registered == agTRUE)
2332*4e1bc9a0SAchim Leubner     {
2333*4e1bc9a0SAchim Leubner         tiDeviceInfo->info.devType_S_Rate = oneDeviceData->agDeviceInfo.devType_S_Rate;
2334*4e1bc9a0SAchim Leubner     }
2335*4e1bc9a0SAchim Leubner     else
2336*4e1bc9a0SAchim Leubner     {
2337*4e1bc9a0SAchim Leubner         tiDeviceInfo->info.devType_S_Rate = oneDeviceData->agDeviceInfo.devType_S_Rate & 0x0f;
2338*4e1bc9a0SAchim Leubner     }
2339*4e1bc9a0SAchim Leubner 
2340*4e1bc9a0SAchim Leubner     /* temp just returning local and remote SAS address; doesn't have a name */
2341*4e1bc9a0SAchim Leubner     tiDeviceInfo->remoteName    = (char *)&(oneDeviceData->tdPortContext->sasRemoteAddressHi);
2342*4e1bc9a0SAchim Leubner     tiDeviceInfo->remoteAddress = (char *)&(oneDeviceData->tdPortContext->sasRemoteAddressLo);
2343*4e1bc9a0SAchim Leubner 
2344*4e1bc9a0SAchim Leubner     tiDeviceInfo->localName     = (char *)&(oneDeviceData->tdPortContext->sasLocalAddressHi);
2345*4e1bc9a0SAchim Leubner     tiDeviceInfo->localAddress  = (char *)&(oneDeviceData->tdPortContext->sasLocalAddressLo);
2346*4e1bc9a0SAchim Leubner 
2347*4e1bc9a0SAchim Leubner     return tiSuccess;
2348*4e1bc9a0SAchim Leubner }
2349*4e1bc9a0SAchim Leubner 
2350*4e1bc9a0SAchim Leubner /*****************************************************************************
2351*4e1bc9a0SAchim Leubner  *! \brief ttdssIOAbortedHandler
2352*4e1bc9a0SAchim Leubner  *
2353*4e1bc9a0SAchim Leubner  *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2354*4e1bc9a0SAchim Leubner  *            layer with agIOStatus = OSSA_IO_ABORTED
2355*4e1bc9a0SAchim Leubner  *
2356*4e1bc9a0SAchim Leubner  *  \param  agRoot:            pointer to port instance
2357*4e1bc9a0SAchim Leubner  *  \param  agIORequest:       pointer to I/O request
2358*4e1bc9a0SAchim Leubner  *  \param  agIOStatus:        I/O status given by LL layer
2359*4e1bc9a0SAchim Leubner  *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2360*4e1bc9a0SAchim Leubner  *  \param  agParam            A Handle used to refer to the response frame or handle
2361*4e1bc9a0SAchim Leubner  *                             of abort request
2362*4e1bc9a0SAchim Leubner  *  \param  agOtherInfo        Residual count
2363*4e1bc9a0SAchim Leubner  *  \return: None
2364*4e1bc9a0SAchim Leubner  *
2365*4e1bc9a0SAchim Leubner  *
2366*4e1bc9a0SAchim Leubner  *****************************************************************************/
2367*4e1bc9a0SAchim Leubner /* see itdosIOCompleted() and itdinit.c and  itdIoAbortedHandler in itdio.c*/
2368*4e1bc9a0SAchim Leubner osGLOBAL void
ttdssIOAbortedHandler(agsaRoot_t * agRoot,agsaIORequest_t * agIORequest,bit32 agIOStatus,bit32 agIOInfoLen,void * agParam,bit32 agOtherInfo)2369*4e1bc9a0SAchim Leubner ttdssIOAbortedHandler (
2370*4e1bc9a0SAchim Leubner         agsaRoot_t              *agRoot,
2371*4e1bc9a0SAchim Leubner         agsaIORequest_t         *agIORequest,
2372*4e1bc9a0SAchim Leubner         bit32                   agIOStatus,
2373*4e1bc9a0SAchim Leubner         bit32                   agIOInfoLen,
2374*4e1bc9a0SAchim Leubner         void                    *agParam,
2375*4e1bc9a0SAchim Leubner         bit32                   agOtherInfo
2376*4e1bc9a0SAchim Leubner )
2377*4e1bc9a0SAchim Leubner {
2378*4e1bc9a0SAchim Leubner     tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
2379*4e1bc9a0SAchim Leubner     tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
2380*4e1bc9a0SAchim Leubner     tdIORequestBody_t      *tdIORequestBody;
2381*4e1bc9a0SAchim Leubner 
2382*4e1bc9a0SAchim Leubner     TI_DBG1(("itdssIOAbortedHandler: start\n"));
2383*4e1bc9a0SAchim Leubner     tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2384*4e1bc9a0SAchim Leubner 
2385*4e1bc9a0SAchim Leubner     if (agIOStatus != OSSA_IO_ABORTED)
2386*4e1bc9a0SAchim Leubner     {
2387*4e1bc9a0SAchim Leubner         TI_DBG1(("itdssIOAbortedHandler: incorrect agIOStatus 0x%x\n", agIOStatus));
2388*4e1bc9a0SAchim Leubner 
2389*4e1bc9a0SAchim Leubner     }
2390*4e1bc9a0SAchim Leubner 
2391*4e1bc9a0SAchim Leubner     ostiTargetIOError(
2392*4e1bc9a0SAchim Leubner             tiRoot,
2393*4e1bc9a0SAchim Leubner             tdIORequestBody->tiIORequest,
2394*4e1bc9a0SAchim Leubner             tiIOFailed,
2395*4e1bc9a0SAchim Leubner             tiDetailAborted
2396*4e1bc9a0SAchim Leubner     );
2397*4e1bc9a0SAchim Leubner 
2398*4e1bc9a0SAchim Leubner     return;
2399*4e1bc9a0SAchim Leubner }
2400*4e1bc9a0SAchim Leubner 
2401*4e1bc9a0SAchim Leubner 
2402