1285809Sscottl/*******************************************************************************
2285809Sscottl*Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3285809Sscottl*
4285809Sscottl*Redistribution and use in source and binary forms, with or without modification, are permitted provided
5285809Sscottl*that the following conditions are met:
6285809Sscottl*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7285809Sscottl*following disclaimer.
8285809Sscottl*2. Redistributions in binary form must reproduce the above copyright notice,
9285809Sscottl*this list of conditions and the following disclaimer in the documentation and/or other materials provided
10285809Sscottl*with the distribution.
11285809Sscottl*
12285809Sscottl*THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13285809Sscottl*WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14285809Sscottl*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15285809Sscottl*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16285809Sscottl*NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17285809Sscottl*BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18285809Sscottl*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19285809Sscottl*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20285809Sscottl ********************************************************************************/
21285809Sscottl/*******************************************************************************/
22285809Sscottl/** \file
23285809Sscottl *
24285809Sscottl * $RCSfile: ttdio.c,v $
25285809Sscottl *
26285809Sscottl * Copyright 2006 PMC-Sierra, Inc.
27285809Sscottl *
28285809Sscottl *
29285809Sscottl * This file contains initiator IO related functions in TD layer
30285809Sscottl *
31285809Sscottl */
32285809Sscottl#include <osenv.h>
33285809Sscottl#include <ostypes.h>
34285809Sscottl#include <osdebug.h>
35285809Sscottl
36285809Sscottl#include <sa.h>
37285809Sscottl#include <saapi.h>
38285809Sscottl#include <saosapi.h>
39285809Sscottl
40285809Sscottl#include <titypes.h>
41285809Sscottl#include <ostiapi.h>
42285809Sscottl#include <tiapi.h>
43285809Sscottl#include <tiglobal.h>
44285809Sscottl
45285809Sscottl#include <tdtypes.h>
46285809Sscottl#include <osstring.h>
47285809Sscottl#include <tdutil.h>
48285809Sscottl
49285809Sscottl#ifdef INITIATOR_DRIVER
50285809Sscottl#include <itdtypes.h>
51285809Sscottl#include <itddefs.h>
52285809Sscottl#include <itdglobl.h>
53285809Sscottl#endif
54285809Sscottl
55285809Sscottl#ifdef TARGET_DRIVER
56285809Sscottl#include <ttdglobl.h>
57285809Sscottl#include <ttdtxchg.h>
58285809Sscottl#include <ttdtypes.h>
59285809Sscottl#endif
60285809Sscottl
61285809Sscottl#include <tdsatypes.h>
62285809Sscottl#include <tdproto.h>
63285809Sscottl
64285809Sscottl
65285809Sscottl/*  Start For trace only */
66285809Sscottl#ifdef REMOVED
67285809Sscottlunsigned __int64
68285809SscottlGetHiResTimeStamp(void);
69285809Sscottl#endif
70285809Sscottl#undef TD_DEBUG_TRACE_ENABLE
71285809Sscottl#define TD_DEBUG_IO_TRACE_BUFFER_MAX  1024
72285809Sscottl
73285809Sscottl
74285809Sscottltypedef struct TDDebugTraceEntry_s
75285809Sscottl{
76285809Sscottl    bit64             Time;
77285809Sscottl    ttdsaXchg_t       ttdsaXchg;
78285809Sscottl    tdsaDeviceData_t  oneDeviceData;
79285809Sscottl} TDDebugTraceEntry_t;
80285809Sscottl
81285809Sscottltypedef struct TDDebugTrace_s
82285809Sscottl{
83285809Sscottl    bit32                 Idx;
84285809Sscottl    bit32                 pad;
85285809Sscottl    TDDebugTraceEntry_t  Data[TD_DEBUG_IO_TRACE_BUFFER_MAX];
86285809Sscottl} TDDebugTrace_t;
87285809Sscottl
88285809Sscottlvoid TDTraceInit(void);
89285809Sscottlvoid TDTraceAdd(ttdsaXchg_t *ttdsaXchg, tdsaDeviceData_t  *oneDeviceData);
90285809Sscottl
91285809Sscottl#ifdef TD_DEBUG_TRACE_ENABLE
92285809Sscottl#define TD_DEBUG_TRACE(ttdsaXchg, oneDeviceData) TDTraceAdd(ttdsaXchg, oneDeviceData)
93285809Sscottl#else
94285809Sscottl#define TD_DEBUG_TRACE(ttdsaXchg, oneDeviceData)
95285809Sscottl#endif
96285809Sscottl
97285809SscottlTDDebugTrace_t TraceData;
98285809Sscottl
99285809Sscottlvoid TDTraceInit(void)
100285809Sscottl{
101285809Sscottl    osti_memset(&TraceData, 0, sizeof(TraceData));
102285809Sscottl}
103285809Sscottl
104285809Sscottlvoid TDTraceAdd(ttdsaXchg_t *ttdsaXchg, tdsaDeviceData_t  *oneDeviceData)
105285809Sscottl{
106285809Sscottl    static bit32 TraceIdx = 0;
107285809Sscottl
108285809Sscottl    TraceData.Idx = TraceIdx;
109285809Sscottl#ifdef REMOVED
110285809Sscottl    TraceData.Data[TraceIdx].Time = GetHiResTimeStamp();
111285809Sscottl#endif
112285809Sscottl    osti_memcpy((bit8 *)&(TraceData.Data[TraceIdx].ttdsaXchg), (bit8 *)ttdsaXchg, sizeof(ttdsaXchg_t));
113285809Sscottl    osti_memcpy((bit8 *)&(TraceData.Data[TraceIdx].oneDeviceData), (bit8 *)oneDeviceData, sizeof(tdsaDeviceData_t));
114285809Sscottl#ifdef REMOVED
115285809Sscottl    TraceData.Data[TraceIdx].ttdsaXchg = ttdsaXchg;
116285809Sscottl    TraceData.Data[TraceIdx].oneDeviceData = oneDeviceData;
117285809Sscottl#endif
118285809Sscottl
119285809Sscottl    TraceIdx++;
120285809Sscottl    if (TraceIdx >= TD_DEBUG_IO_TRACE_BUFFER_MAX)
121285809Sscottl    {
122285809Sscottl        TraceIdx = 0;
123285809Sscottl    }
124285809Sscottl
125285809Sscottl    return;
126285809Sscottl}
127285809Sscottl
128285809Sscottl
129285809Sscottl/*  End For trace only */
130285809Sscottl
131285809Sscottl
132285809SscottlosGLOBAL void
133285809SscottlttdsaSSPReqReceived(
134285809Sscottl        agsaRoot_t           *agRoot,
135285809Sscottl        agsaDevHandle_t      *agDevHandle,
136285809Sscottl        agsaFrameHandle_t    agFrameHandle,
137285809Sscottl        bit32                agInitiatorTag,
138285809Sscottl        bit32                parameter,
139285809Sscottl        bit32                      agFrameLen
140285809Sscottl)
141285809Sscottl{
142285809Sscottl    tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
143285809Sscottl    tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
144285809Sscottl    ttdsaXchg_t            *ttdsaXchg;
145285809Sscottl    /*  agsaSSPCmdInfoUnit_t   cmdIU; */
146285809Sscottl    tdsaDeviceData_t       *oneDeviceData = agNULL;
147285809Sscottl    bit32                  agFrameType, TLR;
148285809Sscottl
149285809Sscottl    TD_XCHG_CONTEXT_NO_CMD_RCVD(tiRoot)        = TD_XCHG_CONTEXT_NO_CMD_RCVD(tiRoot)+1;
150285809Sscottl
151285809Sscottl    TI_DBG4(("ttdsaSSPReqReceived: start\n"));
152285809Sscottl
153285809Sscottl    agFrameType = TD_GET_FRAME_TYPE(parameter);
154285809Sscottl    TLR = TD_GET_TLR(parameter);
155285809Sscottl
156285809Sscottl
157285809Sscottl    /*note:
158285809Sscottl    in ini, agDevHandle->osData =  tdsaDeviceData_t
159285809Sscottl    is set in tdssAddDevicedataToSharedcontext()
160285809Sscottl
161285809Sscottl    in tdsaDeviceDataInit()
162285809Sscottl    oneDeviceData->tiDeviceHandle.tdData has been initialized
163285809Sscottl     */
164285809Sscottl    oneDeviceData = (tdsaDeviceData_t *)agDevHandle->osData;
165285809Sscottl
166285809Sscottl    if (oneDeviceData == agNULL)
167285809Sscottl    {
168285809Sscottl        TI_DBG1(("ttdsaSSPReqReceived: no device data\n"));
169285809Sscottl        return;
170285809Sscottl    }
171285809Sscottl
172285809Sscottl
173285809Sscottl
174285809Sscottl    ttdsaXchg = ttdsaXchgGetStruct(agRoot);
175285809Sscottl
176285809Sscottl    if (ttdsaXchg == agNULL)
177285809Sscottl    {
178285809Sscottl        TI_DBG1(("ttdsaSSPReqReceived: no free xchg structures\n"));
179285809Sscottl        //    ttdsaDumpallXchg(tiRoot);
180285809Sscottl        return;
181285809Sscottl    }
182285809Sscottl
183285809Sscottl    if (ttdsaXchg->IORequestBody.tiIORequest == agNULL)
184285809Sscottl    {
185285809Sscottl        TI_DBG1(("ttdsaSSPReqReceived: tiIORequest is NULL\n"));
186285809Sscottl        //    ttdsaDumpallXchg(tiRoot);
187285809Sscottl        return;
188285809Sscottl    }
189285809Sscottl
190285809Sscottl    oneDeviceData->agDevHandle = agDevHandle;
191285809Sscottl    oneDeviceData->agRoot = agRoot;
192285809Sscottl
193285809Sscottl    /* saving the device */
194285809Sscottl    ttdsaXchg->DeviceData = oneDeviceData;
195285809Sscottl
196285809Sscottl    ttdsaXchg->agRoot  = agRoot;
197285809Sscottl    ttdsaXchg->tiRoot  = tiRoot;
198285809Sscottl
199285809Sscottl    ttdsaXchg->IORequestBody.agIORequest.sdkData = agNULL;
200285809Sscottl
201285809Sscottl    /* initiator tag */
202285809Sscottl    ttdsaXchg->tag      = (bit16)agInitiatorTag;
203285809Sscottl    ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq.agTag
204285809Sscottl    = ttdsaXchg->tag;
205285809Sscottl    ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse.agTag
206285809Sscottl    = ttdsaXchg->tag;
207285809Sscottl
208285809Sscottl    TI_DBG6(("ttdsaSSPReqReceived: initiator tag 0x%x\n", agInitiatorTag));
209285809Sscottl
210285809Sscottl    if (agFrameType == OSSA_FRAME_TYPE_SSP_CMD)
211285809Sscottl    {
212285809Sscottl        TI_DBG4(("ttdsaSSPReqReceived: CMD frame type\n"));
213285809Sscottl        /* reads agsaSSPResponseInfoUnit_t */
214285809Sscottl        saFrameReadBlock(
215285809Sscottl                agRoot,
216285809Sscottl                agFrameHandle,
217285809Sscottl                0,
218285809Sscottl                &ttdsaXchg->agSSPCmndIU,
219285809Sscottl                agFrameLen
220285809Sscottl        );
221285809Sscottl
222285809Sscottl        tdsaProcessCDB(&ttdsaXchg->agSSPCmndIU, ttdsaXchg);
223285809Sscottl        ttdsaXchg->FrameType = SAS_CMND;
224285809Sscottl
225285809Sscottl        /*
226285809Sscottl         ** As the last thing we call the disk module to handle the SCSI CDB.
227285809Sscottl         ** The disk module will call tiTGTIOStart to start a data phase.
228285809Sscottl         */
229285809Sscottl
230285809Sscottl        /* typedef struct
231285809Sscottl       {
232285809Sscottl       bit8      *reqCDB;
233285809Sscottl       bit8      *scsiLun,
234285809Sscottl       bit32     taskAttribute;
235285809Sscottl       bi32      taskId;
236285809Sscottl       bit32     crn;
237285809Sscottl       } tiTargetScsiCmnd_t;
238285809Sscottl         */
239285809Sscottl        /* what about reqCDB and scsiLun */
240285809Sscottl
241285809Sscottl        /* coverting task attributes from SAS TISA */
242285809Sscottl        switch (SA_SSPCMD_GET_TASKATTRIB(&ttdsaXchg->agSSPCmndIU))
243285809Sscottl        {
244285809Sscottl        case 0:
245285809Sscottl            ttdsaXchg->tiTgtScsiCmnd.taskAttribute = TASK_SIMPLE;
246285809Sscottl            break;
247285809Sscottl        case 1:
248285809Sscottl            ttdsaXchg->tiTgtScsiCmnd.taskAttribute = TASK_HEAD_OF_QUEUE;
249285809Sscottl            break;
250285809Sscottl        case 2:
251285809Sscottl            ttdsaXchg->tiTgtScsiCmnd.taskAttribute = TASK_ORDERED;
252285809Sscottl            break;
253285809Sscottl        case 3:
254285809Sscottl            TI_DBG1(("ttdsaSSPReqReceived: reserved taskAttribute 0x%x\n",ttdsaXchg->agSSPCmndIU.efb_tp_taskAttribute));
255285809Sscottl            ttdsaXchg->tiTgtScsiCmnd.taskAttribute = TASK_SIMPLE;
256285809Sscottl            break;
257285809Sscottl        case 4:
258285809Sscottl            ttdsaXchg->tiTgtScsiCmnd.taskAttribute = TASK_ACA;
259285809Sscottl            break;
260285809Sscottl        default:
261285809Sscottl            TI_DBG1(("ttdsaSSPReqReceived: unknown taskAttribute 0x%x\n",ttdsaXchg->agSSPCmndIU.efb_tp_taskAttribute));
262285809Sscottl            ttdsaXchg->agSSPCmndIU.efb_tp_taskAttribute = TASK_SIMPLE;
263285809Sscottl            break;
264285809Sscottl        }
265285809Sscottl
266285809Sscottl        ttdsaXchg->tiTgtScsiCmnd.taskId = agInitiatorTag;
267285809Sscottl        ttdsaXchg->tiTgtScsiCmnd.crn = 0;
268285809Sscottl        ttdsaXchg->TLR = TLR;
269285809Sscottl
270285809Sscottl        /* call ostiProcessScsiReq */
271285809Sscottl        ostiProcessScsiReq( tiRoot,
272285809Sscottl                &ttdsaXchg->tiTgtScsiCmnd,
273285809Sscottl                agFrameHandle,
274285809Sscottl                0,
275285809Sscottl                ttdsaXchg->IORequestBody.tiIORequest,
276285809Sscottl                &ttdsaXchg->DeviceData->tiDeviceHandle);
277285809Sscottl
278285809Sscottl
279285809Sscottl    }
280285809Sscottl    else if (agFrameType == OSSA_FRAME_TYPE_SSP_TASK)
281285809Sscottl    {
282285809Sscottl        TI_DBG4(("ttdsaSSPReqReceived: TM frame type\n"));
283285809Sscottl
284285809Sscottl        /*
285285809Sscottl      reads aagsaSSPScsiTaskMgntReq_t
286285809Sscottl      including lun
287285809Sscottl         */
288285809Sscottl        saFrameReadBlock(
289285809Sscottl                agRoot,
290285809Sscottl                agFrameHandle,
291285809Sscottl                0,
292285809Sscottl                &ttdsaXchg->agTMIU,
293285809Sscottl                agFrameLen
294285809Sscottl        );
295285809Sscottl
296285809Sscottl        ttdsaXchg->FrameType = SAS_TM;
297285809Sscottl        /*
298285809Sscottl      call task process mangement fn
299285809Sscottl         */
300285809Sscottl        ttdsaTMProcess(tiRoot, ttdsaXchg);
301285809Sscottl        return;
302285809Sscottl    }
303285809Sscottl    else
304285809Sscottl    {
305285809Sscottl        TI_DBG1(("ttdsaSSPReqReceived: unknown frame type\n"));
306285809Sscottl        return;
307285809Sscottl    }
308285809Sscottl
309285809Sscottl    return;
310285809Sscottl}
311285809Sscottl
312285809Sscottlvoid
313285809SscottldumpCDB(bit8 *cdb)
314285809Sscottl{
315285809Sscottl    bit32 i;
316285809Sscottl    for(i=0;i<10;i++)
317285809Sscottl    {
318285809Sscottl        TI_DBG4(("cdb[%d] 0x%x\n", i, cdb[i]));
319285809Sscottl    }
320285809Sscottl    return;
321285809Sscottl}
322285809Sscottl
323285809SscottlosGLOBAL void
324285809SscottltdsaProcessCDB(
325285809Sscottl        agsaSSPCmdInfoUnit_t      *cmdIU,
326285809Sscottl        ttdsaXchg_t               *ttdsaXchg
327285809Sscottl)
328285809Sscottl{
329285809Sscottl    tdsaRoot_t    *tdsaRoot      = (tdsaRoot_t *) ttdsaXchg->tiRoot->tdData;
330285809Sscottl    tdsaContext_t *tdsaAllShared = (tdsaContext_t *) &tdsaRoot->tdsaAllShared;
331285809Sscottl    ttdsaTgt_t    *Target        = (ttdsaTgt_t *) tdsaAllShared->ttdsaTgt;
332285809Sscottl    bit8 group;
333285809Sscottl#ifdef TD_DEBUG_ENABLE
334285809Sscottl    CDB6_t *cdb6;
335285809Sscottl#endif
336285809Sscottl    CDB10_t *cdb10;
337285809Sscottl    CDB12_t *cdb12;
338285809Sscottl    CDB16_t *cdb16;
339285809Sscottl    bit32   unknown = agFALSE;
340285809Sscottl    bit32   len=0;
341285809Sscottl    group = cmdIU->cdb[0] & CDB_GRP_MASK;
342285809Sscottl
343285809Sscottl    TI_DBG4(("tdsaProcessCDB: start\n"));
344285809Sscottl
345285809Sscottl    switch (cmdIU->cdb[0])
346285809Sscottl    {
347285809Sscottl    case SCSIOPC_REPORT_LUN:
348285809Sscottl        TI_DBG4(("tdsaProcessCDB: REPORT_LUN\n"));
349285809Sscottl        ttdsaXchg->XchType = AGSA_SSP_TGT_READ_DATA;
350285809Sscottl        break;
351285809Sscottl    case SCSIOPC_INQUIRY:
352285809Sscottl        TI_DBG4(("tdsaProcessCDB: INQUIRY\n"));
353285809Sscottl        ttdsaXchg->XchType = AGSA_SSP_TGT_READ_DATA;
354285809Sscottl        break;
355285809Sscottl
356285809Sscottl    case SCSIOPC_TEST_UNIT_READY:
357285809Sscottl        TI_DBG4(("tdsaProcessCDB: TEST_UNIT_READY\n"));
358285809Sscottl        ttdsaXchg->XchType = AGSA_SSP_TGT_READ_DATA;
359285809Sscottl        break;
360285809Sscottl
361285809Sscottl    case SCSIOPC_READ_CAPACITY_10:
362285809Sscottl    case SCSIOPC_READ_CAPACITY_16:
363285809Sscottl        TI_DBG4(("tdsaProcessCDB: READ CAPACITY\n"));
364285809Sscottl        ttdsaXchg->XchType = AGSA_SSP_TGT_READ_DATA;
365285809Sscottl        break;
366285809Sscottl
367285809Sscottl    case SCSIOPC_READ_6: /* fall through */
368285809Sscottl    case SCSIOPC_READ_10:
369285809Sscottl        TI_DBG4(("tdsaProcessCDB: READ\n"));
370285809Sscottl        ttdsaXchg->XchType = AGSA_SSP_TGT_READ_DATA;
371285809Sscottl        break;
372285809Sscottl
373285809Sscottl    case SCSIOPC_WRITE_6: /* fall through */
374285809Sscottl    case SCSIOPC_WRITE_10:
375285809Sscottl        TI_DBG4(("tdsaProcessCDB: WRITE\n"));
376285809Sscottl        ttdsaXchg->XchType = AGSA_SSP_TGT_WRITE_DATA;
377285809Sscottl        break;
378285809Sscottl
379285809Sscottl    case SCSIOPC_MODE_SENSE_6: /* fall through */
380285809Sscottl    case SCSIOPC_MODE_SENSE_10:
381285809Sscottl        TI_DBG4(("tdsaProcessCDB: MODE SENSE\n"));
382285809Sscottl        ttdsaXchg->XchType = AGSA_SSP_TGT_READ_DATA;
383285809Sscottl        break;
384285809Sscottl    case SCSIOPC_SYNCHRONIZE_CACHE_10:
385285809Sscottl        TI_DBG4(("tdsaProcessCDB: SCSIOPC_SYNCHRONIZE_CACHE_10\n"));
386285809Sscottl        ttdsaXchg->XchType = AGSA_SSP_TGT_CMD_OR_TASK_RSP;
387285809Sscottl        break;
388285809Sscottl    case SCSIOPC_REQUEST_SENSE:
389285809Sscottl        TI_DBG2(("tdsaProcessCDB: SCSIOPC_REQUEST_SENSE\n"));
390285809Sscottl        ttdsaXchg->XchType = AGSA_SSP_TGT_READ_DATA;
391285809Sscottl        break;
392285809Sscottl    default:
393285809Sscottl        TI_DBG4(("tdsaProcessCDB: UNKNOWN, cbd %d 0x%x\n", cmdIU->cdb[0], cmdIU->cdb[0]));
394285809Sscottl        ttdsaXchg->XchType = TargetUnknown;
395285809Sscottl        break;
396285809Sscottl    }
397285809Sscottl
398285809Sscottl    /* parse datalen */
399285809Sscottl    switch (group)
400285809Sscottl    {
401285809Sscottl    case CDB_6BYTE:
402285809Sscottl        TI_DBG4(("tdsaProcessCDB: CDB 6 byte, not yet\n"));
403285809Sscottl#ifdef TD_DEBUG_ENABLE
404285809Sscottl        cdb6 = (CDB6_t *)(cmdIU->cdb);
405285809Sscottl#endif
406285809Sscottl        TI_DBG4(("tdsaProcessCDB: CDB len 0x%x\n", cdb6->len));
407285809Sscottl        break;
408285809Sscottl    case CDB_10BYTE1: /* fall through */
409285809Sscottl    case CDB_10BYTE2:
410285809Sscottl        TI_DBG4(("tdsaProcessCDB: CDB 10 byte\n"));
411285809Sscottl        cdb10 = (CDB10_t *)(cmdIU->cdb);
412285809Sscottl        OSSA_READ_BE_16(AGROOT, &len, cdb10->len, 0);
413285809Sscottl        TI_DBG4(("tdsaProcessCDB: CDB len 0x%x\n", len));
414285809Sscottl        dumpCDB(cmdIU->cdb);
415285809Sscottl        break;
416285809Sscottl    case CDB_12BYTE:
417285809Sscottl        TI_DBG4(("tdsaProcessCDB: CDB 12 byte, not yet\n"));
418285809Sscottl        cdb12 = (CDB12_t *)(cmdIU->cdb);
419285809Sscottl        OSSA_READ_BE_32(AGROOT, &len, cdb12->len, 0);
420285809Sscottl        TI_DBG4(("tdsaProcessCDB: CDB len 0x%x\n", len));
421285809Sscottl        break;
422285809Sscottl    case CDB_16BYTE:
423285809Sscottl        TI_DBG4(("tdsaProcessCDB: CDB 16 byte, not yet\n"));
424285809Sscottl        cdb16 = (CDB16_t *)(cmdIU->cdb);
425285809Sscottl        OSSA_READ_BE_32(AGROOT, &len, cdb16->len, 0);
426285809Sscottl        TI_DBG4(("tdsaProcessCDB: CDB len 0x%x\n", len));
427285809Sscottl        break;
428285809Sscottl    default:
429285809Sscottl        TI_DBG4(("tdsaProcessCDB: unknow CDB, group %d 0x%x\n", group, group));
430285809Sscottl        len = 0;
431285809Sscottl        unknown = agTRUE;
432285809Sscottl        break;
433285809Sscottl    }
434285809Sscottl    if (cmdIU->cdb[0] == SCSIOPC_READ_6  || cmdIU->cdb[0] == SCSIOPC_READ_10 ||
435285809Sscottl        cmdIU->cdb[0] == SCSIOPC_WRITE_6 || cmdIU->cdb[0] == SCSIOPC_WRITE_10  )
436285809Sscottl    {
437285809Sscottl      ttdsaXchg->dataLen  = len * Target->OperatingOption.BlockSize;
438285809Sscottl    }
439285809Sscottl    else
440285809Sscottl    {
441285809Sscottl      ttdsaXchg->dataLen  = len;
442285809Sscottl    }
443285809Sscottl
444285809Sscottl    if (ttdsaXchg->dataLen == 0 && unknown == agFALSE)
445285809Sscottl    {
446285809Sscottl        /* this is needed because of min operation in tiTGTIOstart() */
447285809Sscottl        ttdsaXchg->dataLen      = 0xffffffff;
448285809Sscottl    }
449285809Sscottl    /*  TI_DBG4(("tdsaProcessCDB: datalen 0x%x %d\n", ttdsaXchg->dataLen, ttdsaXchg->dataLen)); */
450285809Sscottl    return;
451285809Sscottl}
452285809Sscottl
453285809Sscottl
454285809Sscottl
455285809Sscottl
456285809Sscottl/*****************************************************************************
457285809Sscottl *
458285809Sscottl *  tiTGTIOStart
459285809Sscottl *
460285809Sscottl *  Purpose: This function is called by the target OS Specific Module to start
461285809Sscottl *           the next phase of a SCSI Request.
462285809Sscottl *
463285809Sscottl *  Parameters:
464285809Sscottl *   tiRoot:         Pointer to driver Instance.
465285809Sscottl *   tiIORequest:    Pointer to the I/O request context for this I/O.
466285809Sscottl *                   This context was initially passed to the OS Specific Module
467285809Sscottl *                   in ostiProcessScsiReq().
468285809Sscottl *   dataOffset:     Offset into the buffer space for this phase.
469285809Sscottl *   dataLength:     Length of data to move for this phase.
470285809Sscottl *   dataSGL:        Length/Address pair of where the data is. The SGL list is
471285809Sscottl *                   allocated and initialized by the OS Specific module.
472285809Sscottl *   sglVirtualAddr: The virtual address of the first element in agSgl1 when
473285809Sscottl *                   agSgl1 is used with the type tiSglList.
474285809Sscottl *                   This field is needed for the TD Layer.
475285809Sscottl *
476285809Sscottl *  Return:
477285809Sscottl *   tiSuccess:     I/O request successfully initiated.
478285809Sscottl *   tiBusy:        No resources available, try again later.
479285809Sscottl *   tiError:       Other errors that prevent the I/O request to be started.
480285809Sscottl *
481285809Sscottl *  Note:
482285809Sscottl *
483285809Sscottl *****************************************************************************/
484285809SscottlosGLOBAL bit32
485285809SscottltiTGTIOStart( tiRoot_t         *tiRoot,
486285809Sscottl        tiIORequest_t    *tiIORequest,
487285809Sscottl        bit32             dataOffset,
488285809Sscottl        bit32             dataLength,
489285809Sscottl        tiSgl_t          *dataSGL,
490285809Sscottl        void             *sglVirtualAddr
491285809Sscottl)
492285809Sscottl
493285809Sscottl{
494285809Sscottl    ttdsaXchg_t               *ttdsaXchg;
495285809Sscottl    agsaSSPTargetRequest_t    *agSSPTargetReq;
496285809Sscottl    bit32                     tiStatus;
497285809Sscottl    bit32                     saStatus;
498285809Sscottl    bit32                     tdStatus;
499285809Sscottl    tdsaPortContext_t         *onePortContext = agNULL;
500285809Sscottl    tdsaDeviceData_t          *oneDeviceData = agNULL;
501285809Sscottl
502285809Sscottl    TI_DBG4(("tiTGTIOStart: start\n"));
503285809Sscottl    TI_DBG4(("tiTGTIOStart: dataLength 0x%x %d\n", dataLength, dataLength));
504285809Sscottl    TI_DBG4(("tiTGTIOStart: dataOffset 0x%x %d\n", dataOffset, dataOffset));
505285809Sscottl
506285809Sscottl    /* save infor in ttdsaXchg */
507285809Sscottl    ttdsaXchg     = (ttdsaXchg_t *)tiIORequest->tdData;
508285809Sscottl
509285809Sscottl    /* check the state of port */
510285809Sscottl    oneDeviceData = ttdsaXchg->DeviceData;
511285809Sscottl    onePortContext= oneDeviceData->tdPortContext;
512285809Sscottl    if (onePortContext->valid == agFALSE)
513285809Sscottl    {
514285809Sscottl        TI_DBG1(("tiTGTIOStart: portcontext pid %d is invalid\n", onePortContext->id));
515285809Sscottl        return tiError;
516285809Sscottl    }
517285809Sscottl
518285809Sscottl
519285809Sscottl    agSSPTargetReq
520285809Sscottl    = &(ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq);
521285809Sscottl
522285809Sscottl    /* fills in agsaSASRequestBody_t.agsaSSPTargetRequest_t */
523285809Sscottl    agSSPTargetReq->dataLength = (bit32) MIN(dataLength, ttdsaXchg->dataLen);
524285809Sscottl    agSSPTargetReq->offset = dataOffset;
525285809Sscottl    agSSPTargetReq->agTag = ttdsaXchg->tag;
526285809Sscottl    /* SSPTargetReq->agTag has been set in ttdsaSSPReqReceived() */
527285809Sscottl
528285809Sscottl    /* Process TLR */
529285809Sscottl    if (ttdsaXchg->TLR == 2)
530285809Sscottl    {
531285809Sscottl        /* diable TLR */
532285809Sscottl        agSSPTargetReq->sspOption = 0;
533285809Sscottl    }
534285809Sscottl    else
535285809Sscottl    {
536285809Sscottl        /* enable TLR */
537285809Sscottl        /* bit5: 0 1 11 11 :bit0 */
538285809Sscottl        agSSPTargetReq->sspOption = 0x1F;
539285809Sscottl    }
540285809Sscottl
541285809Sscottl    ttdsaXchg->IORequestBody.IOType.TargetIO.TargetIOType.RegIO.sglVirtualAddr
542285809Sscottl    = sglVirtualAddr;
543285809Sscottl
544285809Sscottl    if (agSSPTargetReq->dataLength != 0)
545285809Sscottl    {
546285809Sscottl        TI_DBG6(("tiTGTIOStart: pos 1\n"));
547285809Sscottl        ttdsaXchg->IORequestBody.IOType.TargetIO.TargetIOType.RegIO.tiSgl1
548285809Sscottl        = *dataSGL;
549285809Sscottl    }
550285809Sscottl    else
551285809Sscottl    {
552285809Sscottl        TI_DBG6(("tiTGTIOStart: pos 2\n"));
553285809Sscottl        ttdsaXchg->IORequestBody.IOType.TargetIO.TargetIOType.RegIO.tiSgl1.len
554285809Sscottl        = 0;
555285809Sscottl        ttdsaXchg->IORequestBody.IOType.TargetIO.TargetIOType.RegIO.tiSgl1.type
556285809Sscottl        = tiSgl;
557285809Sscottl
558285809Sscottl        /* let's send response frame */
559285809Sscottl        if (ttdsaXchg->resp.length != 0)
560285809Sscottl        {
561285809Sscottl            /* senselen != 0, send respsonse */
562285809Sscottl            TI_DBG4(("tiTGTIOStart: send respsonse\n"));
563285809Sscottl            TI_DBG4(("tiTGTIOStart: resp.length 0x%x\n",
564285809Sscottl                    ttdsaXchg->resp.length));
565285809Sscottl            ttdsaXchg->responseSent = agTRUE;
566285809Sscottl            ttdsaXchg->DeviceData->IOResponse++;
567285809Sscottl            TD_DEBUG_TRACE(ttdsaXchg, ttdsaXchg->DeviceData);
568285809Sscottl            tdStatus = ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
569285809Sscottl            if (tdStatus == AGSA_RC_SUCCESS)
570285809Sscottl            {
571285809Sscottl                return tiSuccess;
572285809Sscottl            }
573285809Sscottl            else if (tdStatus == AGSA_RC_FAILURE)
574285809Sscottl            {
575285809Sscottl                TI_DBG1(("tiTGTIOStart: (ttdsaSendResp) sending not successful\n"));
576285809Sscottl                return tiError;
577285809Sscottl            }
578285809Sscottl            else
579285809Sscottl            {
580285809Sscottl                TI_DBG1(("tiTGTIOStart: (ttdsaSendResp) sending busy\n"));
581285809Sscottl                return tiBusy;
582285809Sscottl            }
583285809Sscottl        }
584285809Sscottl    }
585285809Sscottl
586285809Sscottl
587285809Sscottl    /* sets SSPTargetReq->agSgl */
588285809Sscottl    tiStatus = ttdssIOPrepareSGL(tiRoot, &ttdsaXchg->IORequestBody, dataSGL, NULL, sglVirtualAddr);
589285809Sscottl
590285809Sscottl    if (tiStatus != tiSuccess)
591285809Sscottl    {
592285809Sscottl        TI_DBG1(("tiTGTIOStart: ttdIOPrepareSGL did not return success\n"));
593285809Sscottl        return tiStatus;
594285809Sscottl    }
595285809Sscottl
596285809Sscottl    TI_DBG4(("tiTGTIOStart: agroot %p ttdsaXchg %p\n", ttdsaXchg->agRoot, ttdsaXchg));
597285809Sscottl    TI_DBG4(("tiTGTIOStart: agDevHanlde %p\n", ttdsaXchg->DeviceData->agDevHandle));
598285809Sscottl
599285809Sscottl    if ( (ttdsaXchg->readRspCollapsed == agTRUE) || (ttdsaXchg->wrtRspCollapsed == agTRUE) )
600285809Sscottl    {
601285809Sscottl        /* collapse good response with read  */
602285809Sscottl        TI_DBG4(("tiTGTIOStart: read rsp collapse\n"));
603285809Sscottl        TI_DBG4(("tiTGTIOStart: initiator tag 0x%x\n", ttdsaXchg->tag));
604285809Sscottl
605285809Sscottl        TD_XCHG_CONTEXT_NO_START_IO(tiRoot)        = TD_XCHG_CONTEXT_NO_START_IO(tiRoot)+1;
606285809Sscottl        ttdsaXchg->DeviceData->IOStart++;
607285809Sscottl        TD_DEBUG_TRACE(ttdsaXchg, ttdsaXchg->DeviceData);
608285809Sscottl        saStatus = saSSPStart(
609285809Sscottl                ttdsaXchg->agRoot,
610285809Sscottl                &ttdsaXchg->IORequestBody.agIORequest,
611285809Sscottl                tdsaRotateQnumber(tiRoot, oneDeviceData),
612285809Sscottl                ttdsaXchg->DeviceData->agDevHandle,
613285809Sscottl                ttdsaXchg->readRspCollapsed ? AGSA_SSP_TGT_READ_GOOD_RESP : AGSA_SSP_TGT_WRITE_GOOD_RESP,
614285809Sscottl                        &ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody,
615285809Sscottl                        agNULL,
616285809Sscottl                        &ossaSSPCompleted
617285809Sscottl        );
618285809Sscottl    }
619285809Sscottl    else
620285809Sscottl    {
621285809Sscottl        TI_DBG4(("tiTGTIOStart: normal\n"));
622285809Sscottl        TI_DBG4(("tiTGTIOStart: initiator tag 0x%x\n", ttdsaXchg->tag));
623285809Sscottl        TD_XCHG_CONTEXT_NO_START_IO(tiRoot)        = TD_XCHG_CONTEXT_NO_START_IO(tiRoot)+1;
624285809Sscottl        ttdsaXchg->DeviceData->IOStart++;
625285809Sscottl        TD_DEBUG_TRACE(ttdsaXchg, ttdsaXchg->DeviceData);
626285809Sscottl        saStatus = saSSPStart(
627285809Sscottl                ttdsaXchg->agRoot, /* agRoot, */
628285809Sscottl                &ttdsaXchg->IORequestBody.agIORequest,
629285809Sscottl                tdsaRotateQnumber(tiRoot, oneDeviceData),
630285809Sscottl                ttdsaXchg->DeviceData->agDevHandle,
631285809Sscottl                ttdsaXchg->XchType,
632285809Sscottl                &ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody,
633285809Sscottl                agNULL,
634285809Sscottl                &ossaSSPCompleted
635285809Sscottl        );
636285809Sscottl
637285809Sscottl    }
638285809Sscottl
639285809Sscottl    if (saStatus == AGSA_RC_SUCCESS)
640285809Sscottl    {
641285809Sscottl        return tiSuccess;
642285809Sscottl    }
643285809Sscottl    else if (saStatus == AGSA_RC_FAILURE)
644285809Sscottl    {
645285809Sscottl        TI_DBG1(("tiTGTIOStart: sending not successful\n"));
646285809Sscottl        return tiError;
647285809Sscottl    }
648285809Sscottl    else
649285809Sscottl    {
650285809Sscottl        TI_DBG1(("tiTGTIOStart: sending busy\n"));
651285809Sscottl        return tiBusy;
652285809Sscottl    }
653285809Sscottl
654285809Sscottl}
655285809Sscottl
656285809Sscottl#ifdef EDC_ENABLE
657285809Sscottl/*****************************************************************************
658285809Sscottl *
659285809Sscottl *  tiTGTIOStart
660285809Sscottl *
661285809Sscottl *  Purpose: This function is called by the target OS Specific Module to start
662285809Sscottl *           the next phase of a SCSI Request.
663285809Sscottl *
664285809Sscottl *  Parameters:
665285809Sscottl *   tiRoot:         Pointer to driver Instance.
666285809Sscottl *   tiIORequest:    Pointer to the I/O request context for this I/O.
667285809Sscottl *                   This context was initially passed to the OS Specific Module
668285809Sscottl *                   in ostiProcessScsiReq().
669285809Sscottl *   dataOffset:     Offset into the buffer space for this phase.
670285809Sscottl *   dataLength:     Length of data to move for this phase.
671285809Sscottl *   dataSGL:        Length/Address pair of where the data is. The SGL list is
672285809Sscottl *                   allocated and initialized by the OS Specific module.
673285809Sscottl *   sglVirtualAddr: The virtual address of the first element in agSgl1 when
674285809Sscottl *                   agSgl1 is used with the type tiSglList.
675285809Sscottl *                   This field is needed for the TD Layer.
676285809Sscottl *   difOption:      DIF option.
677285809Sscottl *
678285809Sscottl *  Return:
679285809Sscottl *   tiSuccess:     I/O request successfully initiated.
680285809Sscottl *   tiBusy:        No resources available, try again later.
681285809Sscottl *   tiError:       Other errors that prevent the I/O request to be started.
682285809Sscottl *
683285809Sscottl *  Note:
684285809Sscottl *
685285809Sscottl *****************************************************************************/
686285809SscottlosGLOBAL bit32 tiTGTIOStartDif(
687285809Sscottl        tiRoot_t        *tiRoot,
688285809Sscottl        tiIORequest_t   *tiIORequest,
689285809Sscottl        bit32           dataOffset,
690285809Sscottl        bit32           dataLength,
691285809Sscottl        tiSgl_t         *dataSGL,
692285809Sscottl        void            *sglVirtualAddr,
693285809Sscottl        tiDif_t         *difOption
694285809Sscottl)
695285809Sscottl{
696285809Sscottl
697285809Sscottl    /* This function was never used by SAS/SATA. Use tiTGTSuperIOStart() instead. */
698285809Sscottl    return tiBusy;
699285809Sscottl}
700285809Sscottl#endif
701285809Sscottl
702285809SscottlosGLOBAL bit32
703285809SscottlttdssIOPrepareSGL(
704285809Sscottl        tiRoot_t                 *tiRoot,
705285809Sscottl        tdIORequestBody_t        *tdIORequestBody,
706285809Sscottl        tiSgl_t                  *tiSgl1,
707285809Sscottl        tiSgl_t                  *tiSgl2,
708285809Sscottl        void                     *sglVirtualAddr
709285809Sscottl)
710285809Sscottl{
711285809Sscottl    agsaSgl_t                 *agSgl;
712285809Sscottl
713285809Sscottl    TI_DBG6(("ttdssIOPrepareSGL: start\n"));
714285809Sscottl
715285809Sscottl    agSgl = &(tdIORequestBody->transport.SAS.agSASRequestBody.sspTargetReq.agSgl);
716285809Sscottl
717285809Sscottl    agSgl->len = 0;
718285809Sscottl
719285809Sscottl    if (tiSgl1 == agNULL)
720285809Sscottl    {
721285809Sscottl        TI_DBG1(("ttdssIOPrepareSGL: Error tiSgl1 is NULL\n"));
722285809Sscottl        return tiError;
723285809Sscottl    }
724285809Sscottl
725285809Sscottl    agSgl->sgUpper = tiSgl1->upper;
726285809Sscottl    agSgl->sgLower = tiSgl1->lower;
727285809Sscottl    agSgl->len = tiSgl1->len;
728285809Sscottl    agSgl->extReserved = tiSgl1->type;
729285809Sscottl
730285809Sscottl    return tiSuccess;
731285809Sscottl}
732285809Sscottl
733285809Sscottl/* temp for debugging */
734285809Sscottlvoid
735285809Sscottldumpresp(bit8 *resp, bit32 len)
736285809Sscottl{
737285809Sscottl    bit32 i;
738285809Sscottl
739285809Sscottl    for(i=0;i<len;i++)
740285809Sscottl    {
741285809Sscottl        TI_DBG4(("resp[%d] 0x%x\n", i, resp[i]));
742285809Sscottl    }
743285809Sscottl
744285809Sscottl    return;
745285809Sscottl}
746285809Sscottl
747285809SscottlosGLOBAL bit32
748285809SscottlttdsaSendResp(
749285809Sscottl        agsaRoot_t            *agRoot,
750285809Sscottl        ttdsaXchg_t           *ttdsaXchg
751285809Sscottl)
752285809Sscottl{
753285809Sscottl    tdsaRootOsData_t          *osData = (tdsaRootOsData_t *)agRoot->osData;
754285809Sscottl    tiRoot_t                  *tiRoot = (tiRoot_t *)osData->tiRoot;
755285809Sscottl    tdsaDeviceData_t          *oneDeviceData = agNULL;
756285809Sscottl    bit32                     agRequestType;
757285809Sscottl    bit32                     saStatus;
758285809Sscottl    agsaSSPTargetResponse_t   *agSSPTargetResp;
759285809Sscottl    agRequestType = AGSA_SSP_TGT_CMD_OR_TASK_RSP;
760285809Sscottl
761285809Sscottl    TI_DBG4(("ttdsaSendResp: start\n"));
762285809Sscottl    TI_DBG4(("ttdsaSendResp: agroot %p ttdsaXchg %p\n", ttdsaXchg->agRoot, ttdsaXchg));
763285809Sscottl
764285809Sscottl    TI_DBG4(("ttdsaSendResp:: agDevHanlde %p\n", ttdsaXchg->DeviceData->agDevHandle));
765285809Sscottl
766285809Sscottl    /* sas response */
767285809Sscottl    TI_DBG4(("ttdsaSendResp: len 0x%x \n",
768285809Sscottl            ttdsaXchg->resp.length));
769285809Sscottl    TI_DBG4(("ttdsaSendResp: upper 0x%x \n",
770285809Sscottl            ttdsaXchg->resp.phyAddrUpper));
771285809Sscottl    TI_DBG4(("ttdsaSendResp: lower 0x%x \n",
772285809Sscottl            ttdsaXchg->resp.phyAddrLower));
773285809Sscottl    TI_DBG4(("ttdsaSendResp: initiator tag 0x%x\n", ttdsaXchg->tag));
774285809Sscottl
775285809Sscottl    agSSPTargetResp = &(ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse);
776285809Sscottl    agSSPTargetResp->agTag = ttdsaXchg->tag;
777285809Sscottl    agSSPTargetResp->respBufLength = ttdsaXchg->resp.length;
778285809Sscottl    agSSPTargetResp->respBufUpper = ttdsaXchg->resp.phyAddrUpper;
779285809Sscottl    agSSPTargetResp->respBufLower = ttdsaXchg->resp.phyAddrLower;
780285809Sscottl    agSSPTargetResp->respOption = 3; /* Retry on both ACK/NAK timeout and NAK received */
781285809Sscottl    /* temporary solution for T2D Combo*/
782285809Sscottl#if defined (INITIATOR_DRIVER) && defined (TARGET_DRIVER)
783285809Sscottl    /* nothing */
784285809Sscottl#else
785285809Sscottl    if (agSSPTargetResp->respBufLength <= AGSA_MAX_SSPPAYLOAD_VIA_SFO)
786285809Sscottl        agSSPTargetResp->frameBuf = ttdsaXchg->resp.virtAddr;
787285809Sscottl    else
788285809Sscottl        agSSPTargetResp->frameBuf = NULL;
789285809Sscottl#endif
790285809Sscottl    dumpresp((bit8 *)ttdsaXchg->resp.virtAddr, ttdsaXchg->resp.length);
791285809Sscottl
792285809Sscottl    TD_XCHG_CONTEXT_NO_SEND_RSP(TD_GET_TIROOT(agRoot))        =
793285809Sscottl            TD_XCHG_CONTEXT_NO_SEND_RSP(TD_GET_TIROOT(agRoot))+1;
794285809Sscottl
795285809Sscottl    oneDeviceData = ttdsaXchg->DeviceData;
796285809Sscottl    saStatus = saSSPStart(
797285809Sscottl            ttdsaXchg->agRoot, /* agRoot,*/
798285809Sscottl            &ttdsaXchg->IORequestBody.agIORequest,
799285809Sscottl            tdsaRotateQnumber(tiRoot, oneDeviceData),
800285809Sscottl            ttdsaXchg->DeviceData->agDevHandle, /* agDevHandle, */
801285809Sscottl            agRequestType,
802285809Sscottl            &ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody,
803285809Sscottl            agNULL,
804285809Sscottl            &ossaSSPCompleted
805285809Sscottl    );
806285809Sscottl
807285809Sscottl    if (saStatus == AGSA_RC_SUCCESS)
808285809Sscottl    {
809285809Sscottl        TI_DBG4(("ttdsaSendResp: sending successful\n"));
810285809Sscottl        return AGSA_RC_SUCCESS;
811285809Sscottl    }
812285809Sscottl    else if (saStatus == AGSA_RC_FAILURE)
813285809Sscottl    {
814285809Sscottl        TI_DBG1(("ttdsaSendResp: sending not successful\n"));
815285809Sscottl        return AGSA_RC_FAILURE;
816285809Sscottl    }
817285809Sscottl    else
818285809Sscottl    {
819285809Sscottl        TI_DBG1(("ttdsaSendResp: sending busy\n"));
820285809Sscottl        return AGSA_RC_BUSY;
821285809Sscottl    }
822285809Sscottl
823285809Sscottl}
824285809Sscottl
825285809SscottlosGLOBAL void
826285809SscottlttdsaIOCompleted(
827285809Sscottl        agsaRoot_t             *agRoot,
828285809Sscottl        agsaIORequest_t        *agIORequest,
829285809Sscottl        bit32                  agIOStatus,
830285809Sscottl        bit32                  agIOInfoLen,
831285809Sscottl        agsaFrameHandle_t      agFrameHandle,
832285809Sscottl        bit32                  agOtherInfo
833285809Sscottl)
834285809Sscottl{
835285809Sscottl
836285809Sscottl    ttdsaXchg_t       *ttdsaXchg    = (ttdsaXchg_t *)agIORequest->osData;
837285809Sscottl    /* done in ttdsaXchgInit() */
838285809Sscottl    bit32             IOFailed = agFALSE;
839285809Sscottl    bit32             status;
840285809Sscottl    bit32             statusDetail = 0;
841285809Sscottl    tiRoot_t          *tiRoot;
842285809Sscottl#ifdef REMOVED
843285809Sscottl    tdsaRoot_t        *tdsaRoot;
844285809Sscottl    tdsaContext_t     *tdsaAllShared;
845285809Sscottl#endif
846285809Sscottl    bit32             tdStatus;
847285809Sscottl    bit32             saStatus = AGSA_RC_FAILURE;
848285809Sscottl#ifdef  TD_DEBUG_ENABLE
849285809Sscottl    agsaDifDetails_t  *DifDetail;
850285809Sscottl#endif
851285809Sscottl
852285809Sscottl    TI_DBG4(("ttdsaIOCompleted: start\n"));
853285809Sscottl    tiRoot = ((tdsaRootOsData_t *)agRoot->osData)->tiRoot;
854285809Sscottl#ifdef REMOVED
855285809Sscottl    tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
856285809Sscottl    tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
857285809Sscottl#endif
858285809Sscottl#ifdef  TD_DEBUG_ENABLE
859285809Sscottl    DifDetail = (agsaDifDetails_t *)agFrameHandle;
860285809Sscottl#endif
861285809Sscottl
862285809Sscottl    if (tiRoot == agNULL)
863285809Sscottl    {
864285809Sscottl        TI_DBG1(("ttdsaIOCompleted: tiRoot is NULL\n"));
865285809Sscottl        return;
866285809Sscottl    }
867285809Sscottl
868285809Sscottl    TD_XCHG_CONTEXT_NO_IO_COMPLETED(tiRoot)    = TD_XCHG_CONTEXT_NO_IO_COMPLETED(tiRoot)+1;
869285809Sscottl
870285809Sscottl    if(TD_XCHG_GET_STATE(ttdsaXchg) != TD_XCHG_STATE_ACTIVE)
871285809Sscottl    {
872285809Sscottl        TI_DBG1(("ttdsaIOCompleted: XCHG is not active *****************\n"));
873285809Sscottl        return;
874285809Sscottl    }
875285809Sscottl
876285809Sscottl    if (ttdsaXchg->isTMRequest != agTRUE)
877285809Sscottl    {
878285809Sscottl        TI_DBG6(("ttdsaIOCompleted: COMMAND \n"));
879285809Sscottl        TI_DBG6(("ttdsaIOCompleted: ttdsaXchg %p\n", ttdsaXchg));
880285809Sscottl        TI_DBG6(("ttdsaIOCompleted: ttdsaXchg->IORequestBody.EsglPageList %p\n", &ttdsaXchg->IORequestBody.EsglPageList));
881285809Sscottl        TI_DBG6(("ttdsaIOCompleted: command initiator tag 0x%x\n", ttdsaXchg->tag));
882285809Sscottl
883285809Sscottl#ifdef REMOVED
884285809Sscottl        /* call tdsafreeesglpages only for xchg that used eslg */
885285809Sscottl        if (ttdsaXchg->usedEsgl == agTRUE)
886285809Sscottl        {
887285809Sscottl            tdsaFreeEsglPages(tiRoot, &ttdsaXchg->IORequestBody.EsglPageList);
888285809Sscottl            ttdsaXchg->usedEsgl = agFALSE;
889285809Sscottl        }
890285809Sscottl#endif
891285809Sscottl
892285809Sscottl        /* successful case */
893285809Sscottl        if (agIOStatus ==  OSSA_IO_SUCCESS)
894285809Sscottl        {
895285809Sscottl            TI_DBG6(("ttdsaIOCompleted: osIOSuccess\n"));
896285809Sscottl            if ( (ttdsaXchg->readRspCollapsed == agTRUE) || (ttdsaXchg->wrtRspCollapsed == agTRUE) )
897285809Sscottl            {
898285809Sscottl                ttdsaXchg->responseSent = agTRUE;
899285809Sscottl                TI_DBG4(("ttdsaIOCompleted: read rsp collapse\n"));
900285809Sscottl            }
901285809Sscottl
902285809Sscottl            if (ttdsaXchg->statusSent == agTRUE)
903285809Sscottl            {
904285809Sscottl                /*
905285809Sscottl          the response has already been set and ready
906285809Sscottl          but has NOT been sent
907285809Sscottl                 */
908285809Sscottl                if (ttdsaXchg->responseSent == agFALSE)
909285809Sscottl                {
910285809Sscottl                    /* let's send the response for IO */
911285809Sscottl                    TI_DBG6(("ttdsaIOCompleted: sending response\n"));
912285809Sscottl                    TD_DEBUG_TRACE(ttdsaXchg, ttdsaXchg->DeviceData);
913285809Sscottl                    tdStatus = ttdsaSendResp(agRoot, ttdsaXchg);
914285809Sscottl                    if (tdStatus != AGSA_RC_SUCCESS)
915285809Sscottl                    {
916285809Sscottl                        TI_DBG1(("ttdsaIOCompleted: attention needed\n"));
917285809Sscottl                        return;
918285809Sscottl                    }
919285809Sscottl                    ttdsaXchg->responseSent = agTRUE;
920285809Sscottl                }
921285809Sscottl                else
922285809Sscottl                {
923285809Sscottl                    TI_DBG4(("ttdsaIOCompleted: read rsp collapse and complete \n"));
924285809Sscottl                    /* the response has been sent */
925285809Sscottl                    TI_DBG6(("ttdsaIOCompleted: already sent response, notify OS\n"));
926285809Sscottl
927285809Sscottl                    if (TD_XCHG_GET_STATE(ttdsaXchg) == TD_XCHG_STATE_INACTIVE)
928285809Sscottl                    {
929285809Sscottl                        TI_DBG1(("ttdsaIOCompleted: wrong DEQUEUE_THIS\n"));
930285809Sscottl                    }
931285809Sscottl
932285809Sscottl                    /*
933285809Sscottl                     * Notify the OS Specific Module, so it can free its resource.
934285809Sscottl                     */
935285809Sscottl                    TI_DBG4(("ttdsaIOCompleted: calling ostiTargetIOCompleted\n"));
936285809Sscottl                    ostiTargetIOCompleted( tiRoot,
937285809Sscottl                            ttdsaXchg->IORequestBody.tiIORequest,
938285809Sscottl                            tiIOSuccess );
939285809Sscottl
940285809Sscottl                    /* clean up resources */
941285809Sscottl                    ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
942285809Sscottl                }
943285809Sscottl            } /* sent */
944285809Sscottl            else
945285809Sscottl            {
946285809Sscottl                TI_DBG4(("ttdsaIOCompleted: osIOSuccess: nextphase\n"));
947285809Sscottl                /* the response has not been set; still in data phase */
948285809Sscottl                /* we need to tell the disk module to start the next phase */
949285809Sscottl                ostiNextDataPhase(ttdsaXchg->tiRoot,
950285809Sscottl                        ttdsaXchg->IORequestBody.tiIORequest );
951285809Sscottl            }
952285809Sscottl            return;
953285809Sscottl        } /* success */
954285809Sscottl
955285809Sscottl        /* handle error cases */
956285809Sscottl        if (agIOStatus == OSSA_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH || agIOStatus == OSSA_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH
957285809Sscottl                || agIOStatus == OSSA_IO_XFR_ERROR_DIF_CRC_MISMATCH)
958285809Sscottl        {
959285809Sscottl            TI_DBG1(("ttdsaIOCompleted: DIF detail UpperLBA 0x%08x LowerLBA 0x%08x\n", DifDetail->UpperLBA, DifDetail->LowerLBA));
960285809Sscottl        }
961285809Sscottl        switch (agIOStatus)
962285809Sscottl        {
963285809Sscottl        case OSSA_IO_ABORTED:
964285809Sscottl            TI_DBG1(("ttdsaIOCompleted: ABORTED\n"));
965285809Sscottl            status        = tiIOFailed;
966285809Sscottl            statusDetail  = tiDetailAborted;
967285809Sscottl            IOFailed      = agTRUE;
968285809Sscottl            break;
969285809Sscottl#ifdef REMOVED
970285809Sscottl        case OSSA_IO_OVERFLOW:
971285809Sscottl            TI_DBG1(("ttdsaIOCompleted: OVERFLOW\n"));
972285809Sscottl            status        = tiIOOverRun;
973285809Sscottl            IOFailed      = agTRUE;
974285809Sscottl            break;
975285809Sscottl#endif
976285809Sscottl        case OSSA_IO_UNDERFLOW:
977285809Sscottl            TI_DBG1(("ttdsaIOCompleted: UNDERFLOW\n"));
978285809Sscottl            status        = tiIOUnderRun;
979285809Sscottl            IOFailed      = agTRUE;
980285809Sscottl            break;
981285809Sscottl        case OSSA_IO_ABORT_RESET:
982285809Sscottl            TI_DBG1(("ttdsaIOCompleted: ABORT_RESET\n"));
983285809Sscottl            status        = tiIOFailed;
984285809Sscottl            statusDetail  = tiDetailAbortReset;
985285809Sscottl            IOFailed      = agTRUE;
986285809Sscottl            break;
987285809Sscottl        case OSSA_IO_XFR_ERROR_DEK_KEY_CACHE_MISS:
988285809Sscottl            TI_DBG1(("ttdsaIOCompleted: OSSA_IO_XFR_ERROR_DEK_KEY_CACHE_MISS\n"));
989285809Sscottl            status        = tiIOEncryptError;
990285809Sscottl            statusDetail  = tiDetailDekKeyCacheMiss;
991285809Sscottl            IOFailed      = agTRUE;
992285809Sscottl            break;
993285809Sscottl        case OSSA_IO_XFR_ERROR_DEK_KEY_TAG_MISMATCH:
994285809Sscottl            TI_DBG1(("ttdsaIOCompleted: OSSA_IO_XFR_ERROR_DEK_KEY_TAG_MISMATCH\n"));
995285809Sscottl            status        = tiIOEncryptError;
996285809Sscottl            statusDetail  = tiDetailDekKeyCacheMiss;
997285809Sscottl            IOFailed      = agTRUE;
998285809Sscottl            break;
999285809Sscottl        case OSSA_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH:
1000285809Sscottl            TI_DBG1(("ttdsaIOCompleted: OSSA_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH\n"));
1001285809Sscottl            status        = tiIODifError;
1002285809Sscottl            statusDetail  = tiDetailDifAppTagMismatch;
1003285809Sscottl            IOFailed      = agTRUE;
1004285809Sscottl            break;
1005285809Sscottl        case OSSA_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH:
1006285809Sscottl            TI_DBG1(("ttdsaIOCompleted: OSSA_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH\n"));
1007285809Sscottl            status        = tiIODifError;
1008285809Sscottl            statusDetail  = tiDetailDifRefTagMismatch;
1009285809Sscottl            IOFailed      = agTRUE;
1010285809Sscottl            break;
1011285809Sscottl        case OSSA_IO_XFR_ERROR_DIF_CRC_MISMATCH:
1012285809Sscottl            TI_DBG1(("ttdsaIOCompleted: OSSA_IO_XFR_ERROR_DIF_CRC_MISMATCH\n"));
1013285809Sscottl            status        = tiIODifError;
1014285809Sscottl            statusDetail  = tiDetailDifCrcMismatch;
1015285809Sscottl            IOFailed      = agTRUE;
1016285809Sscottl            break;
1017285809Sscottl        case OSSA_IO_FAILED: /* fall through */
1018285809Sscottl        case OSSA_IO_NO_DEVICE: /* fall through */
1019285809Sscottl            //case OSSA_IO_NO_SUPPORT: /* fall through */       /*added to compile tgt_drv (TP)*/
1020285809Sscottl        case OSSA_IO_LINK_FAILURE: /* fall through */
1021285809Sscottl        case OSSA_IO_PROG_ERROR: /* fall through */
1022285809Sscottl        case OSSA_IO_DS_NON_OPERATIONAL: /* fall through */
1023285809Sscottl        case OSSA_IO_DS_IN_RECOVERY: /* fall through */
1024285809Sscottl        case OSSA_IO_TM_TAG_NOT_FOUND: /* fall through */
1025285809Sscottl        case OSSA_MPI_ERR_IO_RESOURCE_UNAVAILABLE: /* fall through */
1026285809Sscottl        default:
1027285809Sscottl            status        = tiIOFailed;
1028285809Sscottl            statusDetail  = tiDetailOtherError;
1029285809Sscottl            IOFailed      = agTRUE;
1030285809Sscottl            TI_DBG1(("ttdsaIOCompleted: Fail!!!!!!! agIOStatus=0x%x  agIOInfoLen=0x%x agOtherInfo=0x%x\n", agIOStatus, agIOInfoLen, agOtherInfo));
1031285809Sscottl            //      ttdsaDumpallXchg(tiRoot);
1032285809Sscottl            if (agIOStatus == OSSA_IO_XFER_OPEN_RETRY_TIMEOUT)
1033285809Sscottl            {
1034285809Sscottl                TI_DBG1(("ttdsaIOCompleted: OSSA_IO_XFER_OPEN_RETRY_TIMEOUT ttdsaXchg->id 0x%x datalen 0x%x offset 0x%x agTag 0x%x\n",
1035285809Sscottl                        ttdsaXchg->id,
1036285809Sscottl                        ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq.dataLength,
1037285809Sscottl                        ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq.offset,
1038285809Sscottl                        ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq.agTag));
1039285809Sscottl                TI_DBG1(("ttdsaIOCompleted: statusSent %d responseSent %d\n", ttdsaXchg->statusSent, ttdsaXchg->responseSent));
1040285809Sscottl
1041285809Sscottl            }
1042285809Sscottl            break;
1043285809Sscottl        } /* switch */
1044285809Sscottl
1045285809Sscottl        if (IOFailed == agTRUE)
1046285809Sscottl        {
1047285809Sscottl            if (agIORequest->sdkData == agNULL)
1048285809Sscottl            {
1049285809Sscottl                tiIORequest_t tiIORequest;
1050285809Sscottl                TI_DBG1(("ttdsaIOCompleted: ERROR ttdsaXchg=%p agIOStatus= 0x%x\n",
1051285809Sscottl                        ttdsaXchg,
1052285809Sscottl                        agIOStatus ));
1053285809Sscottl                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",
1054285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[0],
1055285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[1],
1056285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[2],
1057285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[3],
1058285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[4],
1059285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[5],
1060285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[6],
1061285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[7],
1062285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[8],
1063285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[9],
1064285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[10],
1065285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[11],
1066285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[12],
1067285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[13],
1068285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[14],
1069285809Sscottl                        ttdsaXchg->agSSPCmndIU.cdb[15] ));
1070285809Sscottl
1071285809Sscottl                if (TD_XCHG_GET_STATE(ttdsaXchg) == TD_XCHG_STATE_INACTIVE)
1072285809Sscottl                {
1073285809Sscottl                    TI_DBG1(("ttdsaIOCompleted: wrong DEQUEUE_THIS  1\n"));
1074285809Sscottl                }
1075285809Sscottl                if (ttdsaXchg->retries <= OPEN_RETRY_RETRIES && agIOStatus == OSSA_IO_XFER_OPEN_RETRY_TIMEOUT)
1076285809Sscottl                {
1077285809Sscottl                    TI_DBG2(("ttdsaIOCompleted: 1 loc retries on OSSA_IO_XFER_OPEN_RETRY_TIMEOUT\n"));
1078285809Sscottl                    if ( (agOtherInfo & 0x1) == 1)
1079285809Sscottl                    {
1080285809Sscottl                        /* repsonse phase */
1081285809Sscottl                        TI_DBG2(("ttdsaIOCompleted: 0 loc response retry\n"));
1082285809Sscottl                        /* repsonse retry */
1083285809Sscottl                        saStatus = ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
1084285809Sscottl                        if (saStatus == AGSA_RC_SUCCESS)
1085285809Sscottl                        {
1086285809Sscottl                            TI_DBG2(("ttdsaIOCompleted: 0 loc retried\n"));
1087285809Sscottl                            ttdsaXchg->retries++;
1088285809Sscottl                        }
1089285809Sscottl                        else
1090285809Sscottl                        {
1091285809Sscottl                            TI_DBG1(("ttdsaIOCompleted: 0 loc retry failed\n"));
1092285809Sscottl                            ttdsaXchg->retries = 0;
1093285809Sscottl                            /*
1094285809Sscottl                             * because we are freeing up the exchange
1095285809Sscottl                             * we must let the oslayer know that
1096285809Sscottl                             * we are releasing the resources by
1097285809Sscottl                             * setting the tdData to NULL
1098285809Sscottl                             */
1099285809Sscottl                            tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1100285809Sscottl                            tiIORequest.tdData = agNULL;
1101285809Sscottl
1102285809Sscottl                            ostiTargetIOError(
1103285809Sscottl                                    tiRoot,
1104285809Sscottl                                    &tiIORequest,
1105285809Sscottl                                    status,
1106285809Sscottl                                    statusDetail
1107285809Sscottl                            );
1108285809Sscottl
1109285809Sscottl                            /* clean up resources */
1110285809Sscottl                            ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1111285809Sscottl                        }
1112285809Sscottl                    }
1113285809Sscottl                    else if ( (ttdsaXchg->readRspCollapsed == agTRUE) || (ttdsaXchg->wrtRspCollapsed == agTRUE) )
1114285809Sscottl                    {
1115285809Sscottl                        saStatus = saSSPStart(
1116285809Sscottl                                ttdsaXchg->agRoot, /* agRoot, */
1117285809Sscottl                                &ttdsaXchg->IORequestBody.agIORequest,
1118285809Sscottl                                0,
1119285809Sscottl                                ttdsaXchg->DeviceData->agDevHandle, /* agDevHandle, */
1120285809Sscottl                                ttdsaXchg->readRspCollapsed ? AGSA_SSP_TGT_READ_GOOD_RESP : AGSA_SSP_TGT_WRITE_GOOD_RESP,
1121285809Sscottl                                        &ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody,
1122285809Sscottl                                        agNULL,
1123285809Sscottl                                        &ossaSSPCompleted
1124285809Sscottl                        );
1125285809Sscottl                        if (saStatus == AGSA_RC_SUCCESS)
1126285809Sscottl                        {
1127285809Sscottl                            TI_DBG1(("ttdsaIOCompleted: 1 loc retried\n"));
1128285809Sscottl                            ttdsaXchg->retries++;
1129285809Sscottl                        }
1130285809Sscottl                        else
1131285809Sscottl                        {
1132285809Sscottl                            TI_DBG1(("ttdsaIOCompleted: 1 loc retry failed\n"));
1133285809Sscottl                            ttdsaXchg->retries = 0;
1134285809Sscottl                            /*
1135285809Sscottl                             * because we are freeing up the exchange
1136285809Sscottl                             * we must let the oslayer know that
1137285809Sscottl                             * we are releasing the resources by
1138285809Sscottl                             * setting the tdData to NULL
1139285809Sscottl                             */
1140285809Sscottl                            tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1141285809Sscottl                            tiIORequest.tdData = agNULL;
1142285809Sscottl
1143285809Sscottl                            ostiTargetIOError(
1144285809Sscottl                                    tiRoot,
1145285809Sscottl                                    &tiIORequest,
1146285809Sscottl                                    status,
1147285809Sscottl                                    statusDetail
1148285809Sscottl                            );
1149285809Sscottl
1150285809Sscottl                            /* clean up resources */
1151285809Sscottl                            ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1152285809Sscottl                        }
1153285809Sscottl                    }
1154285809Sscottl                    else
1155285809Sscottl                    {
1156285809Sscottl                        if (ttdsaXchg->responseSent == agFALSE)
1157285809Sscottl                        {
1158285809Sscottl                            saStatus = saSSPStart(
1159285809Sscottl                                    ttdsaXchg->agRoot, /* agRoot, */
1160285809Sscottl                                    &ttdsaXchg->IORequestBody.agIORequest, /*agIORequest, */
1161285809Sscottl                                    0, /* queue number */
1162285809Sscottl                                    ttdsaXchg->DeviceData->agDevHandle, /* agDevHandle, */
1163285809Sscottl                                    ttdsaXchg->XchType,
1164285809Sscottl                                    &ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody,
1165285809Sscottl                                    agNULL,
1166285809Sscottl                                    &ossaSSPCompleted
1167285809Sscottl                            );
1168285809Sscottl                        }
1169285809Sscottl                        else
1170285809Sscottl                        {
1171285809Sscottl                            /* repsonse retry */
1172285809Sscottl                            TI_DBG1(("ttdsaIOCompleted: 2 loc reponse retry\n"));
1173285809Sscottl                            saStatus = ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
1174285809Sscottl                        }
1175285809Sscottl                        if (saStatus == AGSA_RC_SUCCESS)
1176285809Sscottl                        {
1177285809Sscottl                            TI_DBG1(("ttdsaIOCompleted: 2 loc retried\n"));
1178285809Sscottl                            ttdsaXchg->retries++;
1179285809Sscottl                        }
1180285809Sscottl                        else
1181285809Sscottl                        {
1182285809Sscottl                            TI_DBG1(("ttdsaIOCompleted: 2 loc retry failed\n"));
1183285809Sscottl                            ttdsaXchg->retries = 0;
1184285809Sscottl                            /*
1185285809Sscottl                             * because we are freeing up the exchange
1186285809Sscottl                             * we must let the oslayer know that
1187285809Sscottl                             * we are releasing the resources by
1188285809Sscottl                             * setting the tdData to NULL
1189285809Sscottl                             */
1190285809Sscottl                            tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1191285809Sscottl                            tiIORequest.tdData = agNULL;
1192285809Sscottl
1193285809Sscottl                            ostiTargetIOError(
1194285809Sscottl                                    tiRoot,
1195285809Sscottl                                    &tiIORequest,
1196285809Sscottl                                    status,
1197285809Sscottl                                    statusDetail
1198285809Sscottl                            );
1199285809Sscottl
1200285809Sscottl                            /* clean up resources */
1201285809Sscottl                            ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1202285809Sscottl                        }
1203285809Sscottl                    }
1204285809Sscottl                }
1205285809Sscottl                else
1206285809Sscottl                {
1207285809Sscottl                    ttdsaXchg->retries = 0;
1208285809Sscottl                    /*
1209285809Sscottl                     * because we are freeing up the exchange
1210285809Sscottl                     * we must let the oslayer know that
1211285809Sscottl                     * we are releasing the resources by
1212285809Sscottl                     * setting the tdData to NULL
1213285809Sscottl                     */
1214285809Sscottl                    tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1215285809Sscottl                    tiIORequest.tdData = agNULL;
1216285809Sscottl
1217285809Sscottl                    ostiTargetIOError(
1218285809Sscottl                            tiRoot,
1219285809Sscottl                            &tiIORequest,
1220285809Sscottl                            status,
1221285809Sscottl                            statusDetail
1222285809Sscottl                    );
1223285809Sscottl
1224285809Sscottl                    /* clean up resources */
1225285809Sscottl                    ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1226285809Sscottl                }
1227285809Sscottl            } /* saData == agNULL */
1228285809Sscottl            else
1229285809Sscottl            {
1230285809Sscottl                tiIORequest_t tiIORequest;
1231285809Sscottl
1232285809Sscottl                TI_DBG1(("ttdsaIOCompleted: 2\n"));
1233285809Sscottl                if (TD_XCHG_GET_STATE(ttdsaXchg) == TD_XCHG_STATE_INACTIVE)
1234285809Sscottl                {
1235285809Sscottl                    TI_DBG1(("ttdsaIOCompleted: wrong DEQUEUE_THIS  2\n"));
1236285809Sscottl                }
1237285809Sscottl                if (ttdsaXchg->retries <= OPEN_RETRY_RETRIES && agIOStatus == OSSA_IO_XFER_OPEN_RETRY_TIMEOUT)
1238285809Sscottl                {
1239285809Sscottl                    TI_DBG1(("ttdsaIOCompleted: 2 loc retries on OSSA_IO_XFER_OPEN_RETRY_TIMEOUT\n"));
1240285809Sscottl                    if ( (agOtherInfo & 0x1) == 1)
1241285809Sscottl                    {
1242285809Sscottl                        /* repsonse phase */
1243285809Sscottl                        TI_DBG2(("ttdsaIOCompleted: 0 loc response retry\n"));
1244285809Sscottl                        /* repsonse retry */
1245285809Sscottl                        saStatus = ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
1246285809Sscottl                        if (saStatus == AGSA_RC_SUCCESS)
1247285809Sscottl                        {
1248285809Sscottl                            TI_DBG2(("ttdsaIOCompleted: 0 loc retried\n"));
1249285809Sscottl                            ttdsaXchg->retries++;
1250285809Sscottl                        }
1251285809Sscottl                        else
1252285809Sscottl                        {
1253285809Sscottl                            TI_DBG1(("ttdsaIOCompleted: 0 loc retry failed\n"));
1254285809Sscottl                            ttdsaXchg->retries = 0;
1255285809Sscottl                            /*
1256285809Sscottl                             * because we are freeing up the exchange
1257285809Sscottl                             * we must let the oslayer know that
1258285809Sscottl                             * we are releasing the resources by
1259285809Sscottl                             * setting the tdData to NULL
1260285809Sscottl                             */
1261285809Sscottl                            tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1262285809Sscottl                            tiIORequest.tdData = agNULL;
1263285809Sscottl
1264285809Sscottl                            ostiTargetIOError(
1265285809Sscottl                                    tiRoot,
1266285809Sscottl                                    &tiIORequest,
1267285809Sscottl                                    status,
1268285809Sscottl                                    statusDetail
1269285809Sscottl                            );
1270285809Sscottl
1271285809Sscottl                            /* clean up resources */
1272285809Sscottl                            ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1273285809Sscottl                        }
1274285809Sscottl                    }
1275285809Sscottl                    else if ( (ttdsaXchg->readRspCollapsed == agTRUE) || (ttdsaXchg->wrtRspCollapsed == agTRUE) )
1276285809Sscottl                    {
1277285809Sscottl                        saStatus = saSSPStart(
1278285809Sscottl                                ttdsaXchg->agRoot, /* agRoot, */
1279285809Sscottl                                &ttdsaXchg->IORequestBody.agIORequest, /* agIORequest, */
1280285809Sscottl                                0, /* queue number */
1281285809Sscottl                                ttdsaXchg->DeviceData->agDevHandle, /* agDevHandle, */
1282285809Sscottl                                ttdsaXchg->readRspCollapsed ? AGSA_SSP_TGT_READ_GOOD_RESP : AGSA_SSP_TGT_WRITE_GOOD_RESP,
1283285809Sscottl                                        &ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody,
1284285809Sscottl                                        agNULL,
1285285809Sscottl                                        &ossaSSPCompleted
1286285809Sscottl                        );
1287285809Sscottl                        if (saStatus == AGSA_RC_SUCCESS)
1288285809Sscottl                        {
1289285809Sscottl                            TI_DBG1(("ttdsaIOCompleted: 1 loc retried\n"));
1290285809Sscottl                            ttdsaXchg->retries++;
1291285809Sscottl                        }
1292285809Sscottl                        else
1293285809Sscottl                        {
1294285809Sscottl                            TI_DBG1(("ttdsaIOCompleted: 1 loc retry failed\n"));
1295285809Sscottl                            ttdsaXchg->retries = 0;
1296285809Sscottl                            /*
1297285809Sscottl                             * because we are freeing up the exchange
1298285809Sscottl                             * we must let the oslayer know that
1299285809Sscottl                             * we are releasing the resources by
1300285809Sscottl                             * setting the tdData to NULL
1301285809Sscottl                             */
1302285809Sscottl                            tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1303285809Sscottl                            tiIORequest.tdData = agNULL;
1304285809Sscottl
1305285809Sscottl                            ostiTargetIOError(
1306285809Sscottl                                    tiRoot,
1307285809Sscottl                                    &tiIORequest,
1308285809Sscottl                                    status,
1309285809Sscottl                                    statusDetail
1310285809Sscottl                            );
1311285809Sscottl
1312285809Sscottl                            /* clean up resources */
1313285809Sscottl                            ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1314285809Sscottl                        }
1315285809Sscottl                    }
1316285809Sscottl                    else
1317285809Sscottl                    {
1318285809Sscottl                        TI_DBG1(("ttdsaIOCompleted: 2 loc ttdsaXchg->id 0x%x datalen 0x%x offset 0x%x agTag 0x%x\n",
1319285809Sscottl                                ttdsaXchg->id,
1320285809Sscottl                                ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq.dataLength,
1321285809Sscottl                                ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq.offset,
1322285809Sscottl                                ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetReq.agTag));
1323285809Sscottl                        if (ttdsaXchg->responseSent == agFALSE)
1324285809Sscottl                        {
1325285809Sscottl                            saStatus = saSSPStart(
1326285809Sscottl                                    ttdsaXchg->agRoot, /* agRoot, */
1327285809Sscottl                                    &ttdsaXchg->IORequestBody.agIORequest, /* agIORequest, */
1328285809Sscottl                                    0, /* queue number */
1329285809Sscottl                                    ttdsaXchg->DeviceData->agDevHandle, /* agDevHandle, */
1330285809Sscottl                                    ttdsaXchg->XchType,
1331285809Sscottl                                    &ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody,
1332285809Sscottl                                    agNULL,
1333285809Sscottl                                    &ossaSSPCompleted
1334285809Sscottl                            );
1335285809Sscottl                        }
1336285809Sscottl                        else
1337285809Sscottl                        {
1338285809Sscottl                            TI_DBG1(("ttdsaIOCompleted: 2 loc response retry\n"));
1339285809Sscottl                            /* repsonse retry */
1340285809Sscottl                            saStatus = ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
1341285809Sscottl                        }
1342285809Sscottl                        if (saStatus == AGSA_RC_SUCCESS)
1343285809Sscottl                        {
1344285809Sscottl                            TI_DBG1(("ttdsaIOCompleted: 2 loc retried\n"));
1345285809Sscottl                            ttdsaXchg->retries++;
1346285809Sscottl                        }
1347285809Sscottl                        else
1348285809Sscottl                        {
1349285809Sscottl                            TI_DBG1(("ttdsaIOCompleted: 2 loc retry failed\n"));
1350285809Sscottl                            ttdsaXchg->retries = 0;
1351285809Sscottl                            /*
1352285809Sscottl                             * because we are freeing up the exchange
1353285809Sscottl                             * we must let the oslayer know that
1354285809Sscottl                             * we are releasing the resources by
1355285809Sscottl                             * setting the tdData to NULL
1356285809Sscottl                             */
1357285809Sscottl                            tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1358285809Sscottl                            tiIORequest.tdData = agNULL;
1359285809Sscottl
1360285809Sscottl                            ostiTargetIOError(
1361285809Sscottl                                    tiRoot,
1362285809Sscottl                                    &tiIORequest,
1363285809Sscottl                                    status,
1364285809Sscottl                                    statusDetail
1365285809Sscottl                            );
1366285809Sscottl
1367285809Sscottl                            /* clean up resources */
1368285809Sscottl                            ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1369285809Sscottl                        }
1370285809Sscottl                    }
1371285809Sscottl                }
1372285809Sscottl                else
1373285809Sscottl                {
1374285809Sscottl                    TI_DBG1(("ttdsaIOCompleted: retry is over\n"));
1375285809Sscottl                    ttdsaXchg->retries = 0;
1376285809Sscottl
1377285809Sscottl                    tiIORequest = ttdsaXchg->IORequestBody.IOType.TargetIO.tiIORequest;
1378285809Sscottl                    tiIORequest.tdData = agNULL;
1379285809Sscottl
1380285809Sscottl                    ostiTargetIOError(
1381285809Sscottl                            tiRoot,
1382285809Sscottl                            &tiIORequest,
1383285809Sscottl                            status,
1384285809Sscottl                            statusDetail
1385285809Sscottl                    );
1386285809Sscottl
1387285809Sscottl                    /* clean up resources */
1388285809Sscottl                    ttdsaXchgFreeStruct(tiRoot,ttdsaXchg);
1389285809Sscottl                }
1390285809Sscottl            } /* saData != agNULL */
1391285809Sscottl        }/* if (IOFailed == agTRUE) */
1392285809Sscottl    } /* not TMrequest */
1393285809Sscottl    else /* TMrequest */
1394285809Sscottl    {
1395285809Sscottl        TI_DBG1(("ttdsaIOCompleted: TM request\n"));
1396285809Sscottl        TI_DBG1(("ttdsaIOCompleted: TM initiator tag 0x%x\n", ttdsaXchg->tag));
1397285809Sscottl
1398285809Sscottl        switch(agIOStatus)
1399285809Sscottl        {
1400285809Sscottl        case OSSA_IO_SUCCESS:
1401285809Sscottl            TI_DBG1(("ttdsaIOCompleted: success\n"));
1402285809Sscottl            status = tiIOSuccess;
1403285809Sscottl            break;
1404285809Sscottl        case OSSA_IO_ABORTED:
1405285809Sscottl            TI_DBG1(("ttdsaIOCompleted: ABORTED\n"));
1406285809Sscottl            status        = tiIOFailed;
1407285809Sscottl            statusDetail  = tiDetailAborted;
1408285809Sscottl            IOFailed      = agTRUE;
1409285809Sscottl            break;
1410285809Sscottl        case OSSA_IO_ABORT_RESET:
1411285809Sscottl            TI_DBG1(("ttdsaIOCompleted: ABORT_RESET\n"));
1412285809Sscottl            status        = tiIOFailed;
1413285809Sscottl            statusDetail  = tiDetailAbortReset;
1414285809Sscottl            IOFailed      = agTRUE;
1415285809Sscottl            break;
1416285809Sscottl#ifdef REMOVED
1417285809Sscottl        case OSSA_IO_OVERFLOW: /* fall through */
1418285809Sscottl#endif
1419285809Sscottl        case OSSA_IO_UNDERFLOW: /* fall through */
1420285809Sscottl        case OSSA_IO_FAILED: /* fall through */
1421285809Sscottl#ifdef REMOVED
1422285809Sscottl        case OSSA_IO_NOT_VALID: /* fall through */
1423285809Sscottl#endif
1424285809Sscottl        case OSSA_IO_NO_DEVICE: /* fall through */
1425285809Sscottl            //case OSSA_IO_NO_SUPPORT: /* fall through */       /*added to compile tgt_drv (TP)*/
1426285809Sscottl        case OSSA_IO_LINK_FAILURE: /* fall through */
1427285809Sscottl        case OSSA_IO_PROG_ERROR: /* fall through */
1428285809Sscottl        case OSSA_IO_DS_NON_OPERATIONAL: /* fall through */
1429285809Sscottl        case OSSA_IO_DS_IN_RECOVERY: /* fall through */
1430285809Sscottl        case OSSA_IO_TM_TAG_NOT_FOUND: /* fall through */
1431285809Sscottl        case OSSA_MPI_ERR_IO_RESOURCE_UNAVAILABLE: /* fall through */
1432285809Sscottl        default:
1433285809Sscottl            status        = tiIOFailed;
1434285809Sscottl            statusDetail  = tiDetailOtherError;
1435285809Sscottl            IOFailed      = agTRUE;
1436285809Sscottl            break;
1437285809Sscottl        } /* switch */
1438285809Sscottl
1439285809Sscottl        /* for not found IO, we don't call OS */
1440285809Sscottl        if (ttdsaXchg->io_found == agTRUE)
1441285809Sscottl        {
1442285809Sscottl            ostiTargetTmCompleted(
1443285809Sscottl                    tiRoot,
1444285809Sscottl                    ttdsaXchg->IORequestBody.tiIORequest,
1445285809Sscottl                    status,
1446285809Sscottl                    statusDetail
1447285809Sscottl            );
1448285809Sscottl        }
1449285809Sscottl
1450285809Sscottl        /* clean up resources */
1451285809Sscottl        ttdsaXchgFreeStruct(tiRoot, ttdsaXchg);
1452285809Sscottl
1453285809Sscottl
1454285809Sscottl    } /* TM Request */
1455285809Sscottl    return;
1456285809Sscottl}
1457285809Sscottl
1458285809SscottlosGLOBAL void
1459285809SscottlttdsaTMProcess(
1460285809Sscottl        tiRoot_t    *tiRoot,
1461285809Sscottl        ttdsaXchg_t *ttdsaXchg
1462285809Sscottl)
1463285809Sscottl{
1464285809Sscottl    tdsaRoot_t                *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
1465285809Sscottl    tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1466285809Sscottl
1467285809Sscottl    ttdsaTgt_t                *Target = (ttdsaTgt_t *)tdsaAllShared->ttdsaTgt;
1468285809Sscottl    agsaSSPScsiTaskMgntReq_t  *agTMIU;
1469285809Sscottl    bit8                       TMFun;
1470285809Sscottl    bit32                      tiTMFun;
1471285809Sscottl    tiIORequest_t              *reftiIORequest = agNULL;
1472285809Sscottl    tdList_t                   *IOList;
1473285809Sscottl    bit32                      IOFound = agFALSE;
1474285809Sscottl    ttdsaXchg_t                *tmp_ttdsaXchg = agNULL;
1475285809Sscottl    agsaRoot_t                 *agRoot = (agsaRoot_t *)&(tdsaAllShared->agRootNonInt);
1476285809Sscottl    agsaIORequest_t            *agIORequest = agNULL;
1477285809Sscottl    agsaIORequest_t            *agIOAbortRequest = agNULL;
1478285809Sscottl    tdsaDeviceData_t           *oneDeviceData = agNULL;
1479285809Sscottl    agsaDevHandle_t            *agDevHandle = agNULL;
1480285809Sscottl
1481285809Sscottl    TI_DBG1(("ttdsaTMProcess: start\n"));
1482285809Sscottl
1483285809Sscottl    ttdsaXchg->isTMRequest = agTRUE;
1484285809Sscottl
1485285809Sscottl    agTMIU = (agsaSSPScsiTaskMgntReq_t *)&(ttdsaXchg->agTMIU);
1486285809Sscottl    TMFun = agTMIU->taskMgntFunction;
1487285809Sscottl
1488285809Sscottl    switch (TMFun)
1489285809Sscottl    {
1490285809Sscottl    case AGSA_ABORT_TASK:
1491285809Sscottl        TI_DBG1(("ttdsaTMProcess: ABORT_TASK\n"));
1492285809Sscottl        tiTMFun = AG_ABORT_TASK;
1493285809Sscottl        break;
1494285809Sscottl    case AGSA_ABORT_TASK_SET:
1495285809Sscottl        TI_DBG1(("ttdsaTMProcess: ABORT_TASK_SET\n"));
1496285809Sscottl        tiTMFun = AG_ABORT_TASK_SET;
1497285809Sscottl        break;
1498285809Sscottl    case AGSA_CLEAR_TASK_SET:
1499285809Sscottl        TI_DBG1(("ttdsaTMProcess: CLEAR_TASK_SET\n"));
1500285809Sscottl        tiTMFun = AG_CLEAR_TASK_SET;
1501285809Sscottl        break;
1502285809Sscottl    case AGSA_LOGICAL_UNIT_RESET:
1503285809Sscottl        TI_DBG1(("ttdsaTMProcess: LOGICAL_UNIT_RESET\n"));
1504285809Sscottl        tiTMFun = AG_LOGICAL_UNIT_RESET;
1505285809Sscottl        break;
1506285809Sscottl    case AGSA_CLEAR_ACA:
1507285809Sscottl        TI_DBG1(("ttdsaTMProcess: CLEAR_ACA\n"));
1508285809Sscottl        tiTMFun = AG_CLEAR_ACA;
1509285809Sscottl        break;
1510285809Sscottl    case AGSA_QUERY_TASK:
1511285809Sscottl        TI_DBG1(("ttdsaTMProcess: QUERY_TASK\n"));
1512285809Sscottl        tiTMFun = AG_QUERY_TASK;
1513285809Sscottl        break;
1514285809Sscottl    default:
1515285809Sscottl        TI_DBG1(("ttdsaTMProcess: RESERVED TM 0x%x %d\n", TMFun, TMFun));
1516285809Sscottl        tiTMFun = 0xff; /* unknown task management request */
1517285809Sscottl        break;
1518285809Sscottl    }
1519285809Sscottl
1520285809Sscottl    /*
1521285809Sscottl     * Give the OS Specific module to apply it's Task management policy.
1522285809Sscottl     */
1523285809Sscottl
1524285809Sscottl
1525285809Sscottl    /*
1526285809Sscottl     osGLOBAL void ostiTaskManagement (
1527285809Sscottl                        tiRoot_t          *tiRoot,
1528285809Sscottl                        bit32             task,
1529285809Sscottl                        bit8              *scsiLun,
1530285809Sscottl                        tiIORequest_t     *refTiIORequest,
1531285809Sscottl                        tiIORequest_t     *tiTMRequest,
1532285809Sscottl                        tiDeviceHandle_t  *tiDeviceHandle);
1533285809Sscottl     */
1534285809Sscottl    if (TMFun == AGSA_ABORT_TASK)
1535285809Sscottl    {
1536285809Sscottl        TI_DBG1(("ttdsaTMProcess: if abort task; to be tested \n"));
1537285809Sscottl        /*
1538285809Sscottl      needs to find a reftIIORequest and set it
1539285809Sscottl         */
1540285809Sscottl
1541285809Sscottl        IOList = Target->ttdsaXchgData.xchgBusyList.flink;
1542285809Sscottl        IOFound = agFALSE;
1543285809Sscottl
1544285809Sscottl        /* search through the current IOList */
1545285809Sscottl        while (IOList != &Target->ttdsaXchgData.xchgBusyList)
1546285809Sscottl        {
1547285809Sscottl
1548285809Sscottl            tmp_ttdsaXchg = TDLIST_OBJECT_BASE(ttdsaXchg_t, XchgLinks, IOList);
1549285809Sscottl            if (tmp_ttdsaXchg->tag == agTMIU->tagOfTaskToBeManaged)
1550285809Sscottl            {
1551285809Sscottl                TI_DBG1(("ttdsaTMProcess: tag 0x%x\n",tmp_ttdsaXchg->tag));
1552285809Sscottl                IOFound = agTRUE;
1553285809Sscottl                break;
1554285809Sscottl            }
1555285809Sscottl            IOList = IOList->flink;
1556285809Sscottl        } /* while */
1557285809Sscottl
1558285809Sscottl        if (IOFound == agTRUE)
1559285809Sscottl        {
1560285809Sscottl
1561285809Sscottl            TI_DBG1(("ttdsaTMProcess: found \n"));
1562285809Sscottl            /* call saSSPAbort() */
1563285809Sscottl
1564285809Sscottl            TI_DBG1(("ttdsaTMProcess: loc 1\n"));
1565285809Sscottl            /* abort taskmanagement itself */
1566285809Sscottl            agIOAbortRequest = (agsaIORequest_t *)&(ttdsaXchg->IORequestBody.agIORequest);
1567285809Sscottl
1568285809Sscottl            /* IO to be aborted */
1569285809Sscottl            agIORequest = (agsaIORequest_t *)&(tmp_ttdsaXchg->IORequestBody.agIORequest);
1570285809Sscottl            oneDeviceData = tmp_ttdsaXchg->DeviceData;
1571285809Sscottl            agDevHandle = oneDeviceData->agDevHandle;
1572285809Sscottl
1573285809Sscottl            if (agIORequest == agNULL)
1574285809Sscottl            {
1575285809Sscottl                TI_DBG1(("ttdsaTMProcess: agIORequest is NULL\n"));
1576285809Sscottl            }
1577285809Sscottl            else
1578285809Sscottl            {
1579285809Sscottl              TI_DBG1(("ttdsaTMProcess: agIORequest is NOT NULL\n"));
1580285809Sscottl              if (agIORequest->sdkData == agNULL)
1581285809Sscottl              {
1582285809Sscottl                TI_DBG1(("ttdsaTMProcess: agIORequest->saData is NULL\n"));
1583285809Sscottl              }
1584285809Sscottl              else
1585285809Sscottl              {
1586285809Sscottl                TI_DBG1(("ttdsaTMProcess: agIORequest->saData is NOT NULL\n"));
1587285809Sscottl#ifdef RPM_SOC
1588285809Sscottl                saSSPAbort(agRoot, agIORequest);
1589285809Sscottl#else
1590285809Sscottl                saSSPAbort(agRoot, agIOAbortRequest,0,agDevHandle,0,agIORequest, agNULL);
1591285809Sscottl#endif
1592285809Sscottl              }
1593285809Sscottl            }
1594285809Sscottl
1595285809Sscottl        } /* FOUND */
1596285809Sscottl        else
1597285809Sscottl        {
1598285809Sscottl            ttdsaXchg->io_found = agFALSE;
1599285809Sscottl            tiTGTSendTmResp(tiRoot,
1600285809Sscottl                    ttdsaXchg->IORequestBody.tiIORequest,
1601285809Sscottl                    tiError /* this is FUNCTION_FAILED */ );
1602285809Sscottl            TI_DBG1(("ttdsaTMProcess: ABORT_TASK not found\n"));
1603285809Sscottl            return;
1604285809Sscottl        }
1605285809Sscottl
1606285809Sscottl    } /* ABORT_TASK */
1607285809Sscottl    /*
1608285809Sscottl    reftiIORequest: referred IO request.
1609285809Sscottl    If found, not null. But not used in ramdisk
1610285809Sscottl     */
1611285809Sscottl    TI_DBG1(("ttdsaTMProcess: calling ostiTaskManagement\n"));
1612285809Sscottl    ostiTaskManagement(
1613285809Sscottl            tiRoot,
1614285809Sscottl            tiTMFun,
1615285809Sscottl            ttdsaXchg->agTMIU.lun,
1616285809Sscottl            reftiIORequest,
1617285809Sscottl            ttdsaXchg->IORequestBody.tiIORequest,
1618285809Sscottl            &ttdsaXchg->DeviceData->tiDeviceHandle
1619285809Sscottl    );
1620285809Sscottl
1621285809Sscottl
1622285809Sscottl
1623285809Sscottl    return;
1624285809Sscottl}
1625285809Sscottl
1626285809Sscottl/*****************************************************************************
1627285809Sscottl *
1628285809Sscottl *  tiTGTIOAbort
1629285809Sscottl *
1630285809Sscottl *  Purpose: This function is called to abort an IO previously reported
1631285809Sscottl *           to oslayer through ostiProcessRequest() function.
1632285809Sscottl *
1633285809Sscottl *  Parameters:
1634285809Sscottl *   tiRoot:         Pointer to driver Instance.
1635285809Sscottl *   tiIORequest:    Pointer to the I/O request context for this I/O.
1636285809Sscottl *                   This context was initially passed to the OS Specific
1637285809Sscottl *                   Module in ostiProcessScsiReq().
1638285809Sscottl *  Return:
1639285809Sscottl *   tiSuccess:      Abort request was successfully initiated
1640285809Sscottl *   tiBusy:         No resources available, try again later
1641285809Sscottl *   tiError:        Other errors that prevent the abort request from being
1642285809Sscottl *                   started
1643285809Sscottl *  Note:
1644285809Sscottl *
1645285809Sscottl *****************************************************************************/
1646285809SscottlosGLOBAL bit32
1647285809SscottltiTGTIOAbort (
1648285809Sscottl        tiRoot_t            *tiRoot,
1649285809Sscottl        tiIORequest_t       *taskTag
1650285809Sscottl)
1651285809Sscottl{
1652285809Sscottl    ttdsaXchg_t                 *ttdsaXchg;
1653285809Sscottl    ttdsaXchg_t                 *ttdsaIOAbortXchg;
1654285809Sscottl    tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
1655285809Sscottl    tdsaContext_t               *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1656285809Sscottl    agsaRoot_t                  *agRoot = (agsaRoot_t *)&(tdsaAllShared->agRootNonInt);
1657285809Sscottl    agsaIORequest_t             *agIORequest = agNULL;
1658285809Sscottl    agsaIORequest_t             *agIOAbortRequest = agNULL;
1659285809Sscottl    tdsaDeviceData_t            *oneDeviceData = agNULL;
1660285809Sscottl    agsaDevHandle_t             *agDevHandle = agNULL;
1661285809Sscottl
1662285809Sscottl    TI_DBG1(("tiTGTIOAbort: start\n"));
1663285809Sscottl
1664285809Sscottl    ttdsaXchg        = (ttdsaXchg_t *)taskTag->tdData;
1665285809Sscottl
1666285809Sscottl    if (ttdsaXchg == agNULL)
1667285809Sscottl    {
1668285809Sscottl        TI_DBG1(("tiTGTIOAbort: IOError 1 \n"));
1669285809Sscottl        /*
1670285809Sscottl         * this exchange has already been freed.
1671285809Sscottl         * No need to free it
1672285809Sscottl         */
1673285809Sscottl        ostiTargetIOError(
1674285809Sscottl                tiRoot,
1675285809Sscottl                taskTag,
1676285809Sscottl                tiIOFailed,
1677285809Sscottl                tiDetailAborted
1678285809Sscottl        );
1679285809Sscottl    }
1680285809Sscottl    else if (ttdsaXchg->IORequestBody.agIORequest.sdkData == agNULL)
1681285809Sscottl    {
1682285809Sscottl        TI_DBG1(("tiTGTIOAbort: IOError 2 \n"));
1683285809Sscottl        /* We have not issued this IO to the salayer.
1684285809Sscottl         * Abort it right here.
1685285809Sscottl         */
1686285809Sscottl        if (TD_XCHG_GET_STATE(ttdsaXchg) == TD_XCHG_STATE_INACTIVE)
1687285809Sscottl        {
1688285809Sscottl            TI_DBG1(("tiTGTIOAbort: wrong DEQUEUE_THIS\n"));
1689285809Sscottl        }
1690285809Sscottl
1691285809Sscottl        TI_DBG1(("tiTGTIOAbort: IOError 3\n"));
1692285809Sscottl
1693285809Sscottl        ostiTargetIOError(
1694285809Sscottl                tiRoot,
1695285809Sscottl                taskTag,
1696285809Sscottl                tiIOFailed,
1697285809Sscottl                tiDetailAborted
1698285809Sscottl        );
1699285809Sscottl        TI_DBG1(("tiTGTIOAbort: IOError 4\n"));
1700285809Sscottl
1701285809Sscottl        ttdsaXchgFreeStruct(
1702285809Sscottl                ttdsaXchg->tiRoot,
1703285809Sscottl                ttdsaXchg
1704285809Sscottl        );
1705285809Sscottl        TI_DBG1(("tiTGTIOAbort: IOError 5\n"));
1706285809Sscottl
1707285809Sscottl    }
1708285809Sscottl    else /* to be tested */
1709285809Sscottl    {
1710285809Sscottl        TI_DBG1(("tiTGTIOAbort: aborting; to be tested \n"));
1711285809Sscottl        /* abort io request itself */
1712285809Sscottl        ttdsaIOAbortXchg = ttdsaXchgGetStruct(agRoot);
1713285809Sscottl
1714285809Sscottl        if (ttdsaIOAbortXchg == agNULL)
1715285809Sscottl        {
1716285809Sscottl            TI_DBG1(("tiTGTIOAbort: no free xchg structures\n"));
1717285809Sscottl            //      ttdsaDumpallXchg(tiRoot);
1718285809Sscottl            return tiError;
1719285809Sscottl        }
1720285809Sscottl        ttdsaIOAbortXchg->agRoot  = agRoot;
1721285809Sscottl        ttdsaIOAbortXchg->tiRoot  = tiRoot;
1722285809Sscottl        agIOAbortRequest= &(ttdsaXchg->IORequestBody.agIORequest);
1723285809Sscottl        /* remember IO to be aborted */
1724285809Sscottl        ttdsaIOAbortXchg->tiIOToBeAbortedRequest  = taskTag;
1725285809Sscottl        ttdsaIOAbortXchg->XchgToBeAborted = ttdsaXchg;
1726285809Sscottl
1727285809Sscottl        //    ttdsaIOAbortXchg->FrameType = SAS_TM;
1728285809Sscottl
1729285809Sscottl        /* io is being aborted */
1730285809Sscottl        ttdsaXchg->oslayerAborting = agTRUE;
1731285809Sscottl        agIORequest = (agsaIORequest_t *)&(ttdsaXchg->IORequestBody.agIORequest);
1732285809Sscottl        oneDeviceData = ttdsaXchg->DeviceData;
1733285809Sscottl        if (oneDeviceData == agNULL)
1734285809Sscottl        {
1735285809Sscottl            TI_DBG1(("tiTGTIOAbort: oneDeviceData is null; wrong\n"));
1736285809Sscottl        }
1737285809Sscottl        else
1738285809Sscottl        {
1739285809Sscottl          agDevHandle = oneDeviceData->agDevHandle;
1740285809Sscottl          ttdsaIOAbortXchg->DeviceData = oneDeviceData;
1741285809Sscottl        }
1742285809Sscottl#ifdef RPM_SOC
1743285809Sscottl        saSSPAbort(agRoot, agIORequest);
1744285809Sscottl#else
1745285809Sscottl        saSSPAbort(agRoot, agIOAbortRequest,0,agDevHandle,0,agIORequest, agNULL);
1746285809Sscottl    }
1747285809Sscottl
1748285809Sscottl    return tiSuccess;
1749285809Sscottl}
1750285809Sscottl
1751285809SscottlosGLOBAL bit32
1752285809SscottltiTGTIOAbortAll(
1753285809Sscottl        tiRoot_t            *tiRoot,
1754285809Sscottl        tiDeviceHandle_t    *tiDeviceHandle
1755285809Sscottl)
1756285809Sscottl{
1757285809Sscottl    agsaRoot_t                *agRoot = agNULL;
1758285809Sscottl    tdsaDeviceData_t          *oneDeviceData = agNULL;
1759285809Sscottl    bit32                     status = tiError;
1760285809Sscottl
1761285809Sscottl    TI_DBG3(("tiTGTIOAbortAll: start\n"));
1762285809Sscottl
1763285809Sscottl    oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
1764285809Sscottl
1765285809Sscottl    if (oneDeviceData == agNULL)
1766285809Sscottl    {
1767285809Sscottl        TI_DBG1(("tiTGTIOAbortAll: oneDeviceData is NULL!!!\n"));
1768285809Sscottl        return tiError;
1769285809Sscottl    }
1770285809Sscottl
1771285809Sscottl    /* for hotplug */
1772285809Sscottl    if (oneDeviceData->valid != agTRUE || oneDeviceData->registered != agTRUE ||
1773285809Sscottl            oneDeviceData->tdPortContext == agNULL )
1774285809Sscottl    {
1775285809Sscottl        TI_DBG1(("tiTGTIOAbortAll: NO Device did %d\n", oneDeviceData->id ));
1776285809Sscottl        TI_DBG1(("tiTGTIOAbortAll: device AddrHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
1777285809Sscottl        TI_DBG1(("tiTGTIOAbortAll: device AddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
1778285809Sscottl        return tiError;
1779285809Sscottl    }
1780285809Sscottl
1781285809Sscottl    agRoot = oneDeviceData->agRoot;
1782285809Sscottl
1783285809Sscottl    if (agRoot == agNULL)
1784285809Sscottl    {
1785285809Sscottl        TI_DBG1(("tiTGTIOAbortAll: agRoot is NULL!!!\n"));
1786285809Sscottl        return tiError;
1787285809Sscottl    }
1788285809Sscottl
1789285809Sscottl    /* this is processed in ossaSSPAbortCB, ossaSATAAbortCB, ossaSMPAbortCB */
1790285809Sscottl    oneDeviceData->OSAbortAll = agTRUE;
1791285809Sscottl
1792285809Sscottl    status = tdsaAbortAll(tiRoot, agRoot, oneDeviceData);
1793285809Sscottl
1794285809Sscottl    return status;
1795285809Sscottl
1796285809Sscottl}
1797285809Sscottl
1798285809Sscottl
1799285809Sscottl/*****************************************************************************
1800285809Sscottl *
1801285809Sscottl *  tiTGTSendTmResp
1802285809Sscottl *
1803285809Sscottl *  Purpose: This function is called to abort an IO previously reported
1804285809Sscottl *           to oslayer through ostiProcessRequest() function.
1805285809Sscottl *
1806285809Sscottl *  Parameters:
1807285809Sscottl *   tiRoot:         Pointer to driver Instance.
1808285809Sscottl *   tiIORequest:    Pointer to the I/O request context for this I/O.
1809285809Sscottl *                   This context was initially passed to the OS Specific
1810285809Sscottl *                   Module in ostiProcessScsiReq().
1811285809Sscottl *  Return:
1812285809Sscottl *   tiSuccess:      Abort request was successfully initiated
1813285809Sscottl *   tiBusy:         No resources available, try again later
1814285809Sscottl *   tiError:        Other errors that prevent the abort request from being
1815285809Sscottl *                   started
1816285809Sscottl *  Note:
1817285809Sscottl *
1818285809Sscottl *****************************************************************************/
1819285809SscottlosGLOBAL bit32
1820285809SscottltiTGTSendTmResp(
1821285809Sscottl        tiRoot_t          *tiRoot,
1822285809Sscottl        tiIORequest_t     *tiTMRequest,
1823285809Sscottl        bit32             status
1824285809Sscottl)
1825285809Sscottl{
1826285809Sscottl    ttdsaXchg_t               *ttdsaXchg;
1827285809Sscottl    sas_resp_t                *SASResp;
1828285809Sscottl    bit32                     tdStatus;
1829285809Sscottl    TI_DBG1(("tiTGTSendTmResp: start 1\n"));
1830285809Sscottl
1831285809Sscottl    ttdsaXchg     = (ttdsaXchg_t *)tiTMRequest->tdData;
1832285809Sscottl    /* set the response and send it */
1833285809Sscottl    /* response status is 0 */
1834285809Sscottl    /* status is TM status */
1835285809Sscottl
1836285809Sscottl    TI_DBG1(("tiTGTSendTmResp: start 2\n"));
1837285809Sscottl    SASResp = (sas_resp_t *)ttdsaXchg->resp.virtAddr;
1838285809Sscottl    TI_DBG1(("tiTGTSendTmResp: start 3\n"));
1839285809Sscottl
1840285809Sscottl    if (ttdsaXchg->FrameType == SAS_TM)
1841285809Sscottl    {
1842285809Sscottl        SASResp->agResp.status = 0;
1843285809Sscottl        SASResp->agResp.dataPres = RESPONSE_DATA;
1844285809Sscottl        OSSA_WRITE_BE_32(agRoot, SASResp->agResp.responsedataLen, 0, RESPONSE_DATA_LEN);
1845285809Sscottl        OSSA_WRITE_BE_32(agRoot, SASResp->agResp.senseDataLen, 0, 0);
1846285809Sscottl        switch (status)
1847285809Sscottl        {
1848285809Sscottl        case tiSuccess:
1849285809Sscottl            TI_DBG2(("tiTGTSendTmResp: tiSuccess\n"));
1850285809Sscottl            SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_SUCCEEDED;
1851285809Sscottl            break;
1852285809Sscottl        case tiError:
1853285809Sscottl            TI_DBG1(("tiTGTSendTmResp: tiError\n"));
1854285809Sscottl            SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1855285809Sscottl            break;
1856285809Sscottl        case tiBusy:
1857285809Sscottl            TI_DBG1(("tiTGTSendTmResp: tibusy\n"));
1858285809Sscottl            SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1859285809Sscottl            break;
1860285809Sscottl        case tiIONoDevice:
1861285809Sscottl            TI_DBG1(("tiTGTSendTmResp: tiionodevicee\n"));
1862285809Sscottl            SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1863285809Sscottl            break;
1864285809Sscottl        case tiMemoryTooLarge:
1865285809Sscottl            TI_DBG1(("tiTGTSendTmResp: timemorytoolarge\n"));
1866285809Sscottl            SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1867285809Sscottl            break;
1868285809Sscottl        case tiMemoryNotAvail:
1869285809Sscottl            TI_DBG1(("tiTGTSendTmResp: timemorynotavail\n"));
1870285809Sscottl            SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1871285809Sscottl            break;
1872285809Sscottl        case tiInvalidHandle:
1873285809Sscottl            TI_DBG1(("tiTGTSendTmResp: tiinvalidhandle\n"));
1874285809Sscottl            SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1875285809Sscottl            break;
1876285809Sscottl        case tiNotSupported:
1877285809Sscottl            TI_DBG1(("tiTGTSendTmResp: tiNotsupported\n"));
1878285809Sscottl            SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_NOT_SUPPORTED;
1879285809Sscottl            break;
1880285809Sscottl        case tiReject:
1881285809Sscottl            TI_DBG1(("tiTGTSendTmResp: tireject\n"));
1882285809Sscottl            SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1883285809Sscottl            break;
1884285809Sscottl        case tiIncorrectLun:
1885285809Sscottl            TI_DBG1(("tiTGTSendTmResp: tiincorrectlun\n"));
1886285809Sscottl            SASResp->RespData[3] = AGSA_INCORRECT_LOGICAL_UNIT_NUMBER;
1887285809Sscottl            break;
1888285809Sscottl        default:
1889285809Sscottl            TI_DBG1(("tiTGTSendTmResp: default\n"));
1890285809Sscottl            SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_FAILED;
1891285809Sscottl            break;
1892285809Sscottl        }
1893285809Sscottl        ttdsaXchg->resp.length = sizeof(agsaSSPResponseInfoUnit_t) + RESPONSE_DATA_LEN;
1894285809Sscottl        ttdsaXchg->statusSent = agTRUE;
1895285809Sscottl    }
1896285809Sscottl    else
1897285809Sscottl    {
1898285809Sscottl        TI_DBG1(("tiTGTSendTmResp: not TM frame\n"));
1899285809Sscottl        return tiError;
1900285809Sscottl    }
1901285809Sscottl
1902285809Sscottl    tdStatus = ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
1903285809Sscottl    if (tdStatus == AGSA_RC_SUCCESS)
1904285809Sscottl    {
1905285809Sscottl        TI_DBG1(("tiTGTSendTmResp: send success\n"));
1906285809Sscottl        return tiSuccess;
1907285809Sscottl    }
1908285809Sscottl    else if (tdStatus == AGSA_RC_FAILURE)
1909285809Sscottl    {
1910285809Sscottl        TI_DBG1(("tiTGTSendTmResp: sending not successful\n"));
1911285809Sscottl        return tiError;
1912285809Sscottl    }
1913285809Sscottl    else
1914285809Sscottl    {
1915285809Sscottl        TI_DBG1(("tiTGTSendTmResp: send busy\n"));
1916285809Sscottl        return tiBusy;
1917285809Sscottl    }
1918285809Sscottl
1919285809Sscottl
1920285809Sscottl#ifdef REMOVED
1921285809Sscottl
1922285809Sscottl    tiTGTSetResp(tiRoot, tiTMRequest, 0, 0, 0);
1923285809Sscottl#endif
1924285809Sscottl
1925285809Sscottl#ifdef REMOVED
1926285809Sscottl
1927285809Sscottl    if (ttdsaXchg->resp.length != 0)
1928285809Sscottl    {
1929285809Sscottl        TI_DBG1(("tiTGTSendTmResp: respsonse is set \n"));
1930285809Sscottl        TI_DBG1(("tiTGTSendTmResp: resp.length 0x%x\n",
1931285809Sscottl                ttdsaXchg->resp.length));
1932285809Sscottl        ttdsaXchg->responseSent = agTRUE;
1933285809Sscottl
1934285809Sscottl        ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
1935285809Sscottl    }
1936285809Sscottl    else
1937285809Sscottl    {
1938285809Sscottl        /* no respsonse is set, direct call */
1939285809Sscottl        TI_DBG1(("tiTGTSendTmResp: direct call\n"));
1940285809Sscottl        tiTGTSetResp(tiRoot, tiTMRequest, 0, 0, 0);
1941285809Sscottl        ttdsaXchg->responseSent = agTRUE;
1942285809Sscottl        ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
1943285809Sscottl    }
1944285809Sscottl
1945285809Sscottl#define TASK_MANAGEMENT_FUNCTION_COMPLETE         0x0
1946285809Sscottl#define INVALID_FRAME                             0x2
1947285809Sscottl#define TASK_MANAGEMENT_FUNCTION_NOT_SUPPORTED    0x4
1948285809Sscottl#define TASK_MANAGEMENT_FUNCTION_FAILED           0x5
1949285809Sscottl#define TASK_MANAGEMENT_FUNCTION_SUCCEEDED        0x8
1950285809Sscottl#define INVALID_LOGICAL_UNIT_NUMBER               0x9
1951285809Sscottl#endif
1952285809Sscottl
1953285809Sscottl}
1954285809Sscottl
1955285809Sscottl
1956285809Sscottl
1957285809Sscottl/*****************************************************************************
1958285809Sscottl *
1959285809Sscottl *  tiTGTSenseBufferGet
1960285809Sscottl *
1961285809Sscottl *  Purpose: This function is called to get the address of sense buffer from
1962285809Sscottl *           the target specific Transport Dependent Layer.
1963285809Sscottl *
1964285809Sscottl *  Parameters:
1965285809Sscottl *     tiRoot:        Pointer to driver/port instance.
1966285809Sscottl *     tiIORequest:   I/O request context.
1967285809Sscottl *     length:        Lenght in bytes of the sense buffer.
1968285809Sscottl *
1969285809Sscottl *  Return:  none
1970285809Sscottl *
1971285809Sscottl *  Note:
1972285809Sscottl *
1973285809Sscottl *****************************************************************************/
1974285809SscottlosGLOBAL void *tiTGTSenseBufferGet( tiRoot_t      *tiRoot,
1975285809Sscottl        tiIORequest_t *tiIORequest,
1976285809Sscottl        bit32          length
1977285809Sscottl)
1978285809Sscottl{
1979285809Sscottl
1980285809Sscottl    ttdsaXchg_t         *ttdsaXchg;
1981285809Sscottl
1982285809Sscottl    ttdsaXchg = (ttdsaXchg_t *)tiIORequest->tdData;
1983285809Sscottl
1984285809Sscottl    TI_DBG4(("tiTGTSenseBufferGet: start\n"));
1985285809Sscottl    OS_ASSERT((length <= 64), "length too big in tiTGTSenseBufferGet");
1986285809Sscottl
1987285809Sscottl    return &ttdsaXchg->resp.virtAddr[sizeof(agsaSSPResponseInfoUnit_t)];
1988285809Sscottl}
1989285809Sscottl
1990285809Sscottl/*****************************************************************************
1991285809Sscottl *
1992285809Sscottl *  tiTGTSetResp
1993285809Sscottl *
1994285809Sscottl *  Purpose: This function is called when the target OS Specific Module is ready
1995285809Sscottl *           to send a response with the next tiTGTIOStart()
1996285809Sscottl *           function call. This function allows the TD Layer to setup its
1997285809Sscottl *           portion of the status and mark it to be sent on the next
1998285809Sscottl *           tiTGTIOStart() function call.
1999285809Sscottl *
2000285809Sscottl *  Parameters:
2001285809Sscottl *   tiRoot:         Pointer to driver Instance.
2002285809Sscottl *   tiIORequest:    Pointer to the I/O request context for this I/O.
2003285809Sscottl *                   This context was initially passed to the OS Specific Module
2004285809Sscottl *                   in ostiProcessScsiReq().
2005285809Sscottl *   dataSentLength: How much data sent or received for this Request.
2006285809Sscottl *   ScsiStatus:     Status for this SCSI command.
2007285809Sscottl *   senseLength:    Length of sense data if any.
2008285809Sscottl *
2009285809Sscottl *  Return: none
2010285809Sscottl *
2011285809Sscottl *  Note:
2012285809Sscottl *
2013285809Sscottl *****************************************************************************/
2014285809SscottlosGLOBAL void
2015285809SscottltiTGTSetResp( tiRoot_t        *tiRoot,
2016285809Sscottl        tiIORequest_t   *tiIORequest,
2017285809Sscottl        bit32            dataSentLength,
2018285809Sscottl        bit8             ScsiStatus,
2019285809Sscottl        bit32            senseLength
2020285809Sscottl)
2021285809Sscottl{
2022285809Sscottl    /* no call to saSSPStart() in this function */
2023285809Sscottl    /*
2024285809Sscottl    response is normally for task management
2025285809Sscottl    sense is for command with error
2026285809Sscottl    need to know this is for TM or cmd
2027285809Sscottl     */
2028285809Sscottl    /*
2029285809Sscottl  tiTGTSetResp(rdRoot->pTiRoot,
2030285809Sscottl               rdIORequest->tiIORequest,
2031285809Sscottl               dataSentLength,
2032285809Sscottl               ScsiStatus,
2033285809Sscottl               senseLength);
2034285809Sscottl
2035285809Sscottl
2036285809Sscottl
2037285809Sscottl     */
2038285809Sscottl    ttdsaXchg_t               *ttdsaXchg;
2039285809Sscottl    tdsaRoot_t                *tdsaRoot  = (tdsaRoot_t *)tiRoot->tdData;
2040285809Sscottl#ifdef REMOVED
2041285809Sscottl    agsaSSPTargetResponse_t   *agSSPTargetResp;
2042285809Sscottl#endif
2043285809Sscottl    sas_resp_t                *SASResp;
2044285809Sscottl    bit32                      TotalRespLen = 0;
2045285809Sscottl
2046285809Sscottl    TI_DBG4 (("tiTGTSetResp: start\n"));
2047285809Sscottl    TI_DBG4 (("tiTGTSetResp: datelen %d senselen %d\n", dataSentLength, senseLength));
2048285809Sscottl
2049285809Sscottl    ttdsaXchg = (ttdsaXchg_t *)tiIORequest->tdData;
2050285809Sscottl    SASResp = (sas_resp_t *)ttdsaXchg->resp.virtAddr;
2051285809Sscottl
2052285809Sscottl    SASResp->agResp.status = ScsiStatus;
2053285809Sscottl
2054285809Sscottl    if (ttdsaXchg->FrameType == SAS_TM)
2055285809Sscottl    {
2056285809Sscottl
2057285809Sscottl        TI_DBG1(("tiTGTSetResp: TM\n"));
2058285809Sscottl        if (senseLength != 0)
2059285809Sscottl        {
2060285809Sscottl            TI_DBG1 (("tiTGTSetResp: non-zero sensedatalen for TM\n"));
2061285809Sscottl            return;
2062285809Sscottl        }
2063285809Sscottl        SASResp->agResp.dataPres = RESPONSE_DATA;
2064285809Sscottl        OSSA_WRITE_BE_32(agRoot, SASResp->agResp.responsedataLen, 0, RESPONSE_DATA_LEN);
2065285809Sscottl        OSSA_WRITE_BE_32(agRoot, SASResp->agResp.senseDataLen, 0, 0);
2066285809Sscottl        SASResp->RespData[3] = AGSA_TASK_MANAGEMENT_FUNCTION_NOT_SUPPORTED;
2067285809Sscottl        TotalRespLen = sizeof(agsaSSPResponseInfoUnit_t) + RESPONSE_DATA_LEN;
2068285809Sscottl    }
2069285809Sscottl    else
2070285809Sscottl    {
2071285809Sscottl        if (senseLength == 0)
2072285809Sscottl        {
2073285809Sscottl            TI_DBG4 (("tiTGTSetResp: CMND, no data\n"));
2074285809Sscottl            /* good and no data present */
2075285809Sscottl            SASResp->agResp.dataPres = NO_DATA;
2076285809Sscottl            OSSA_WRITE_BE_32(agRoot, SASResp->agResp.responsedataLen, 0, 0);
2077285809Sscottl            OSSA_WRITE_BE_32(agRoot, SASResp->agResp.senseDataLen, 0, 0);
2078285809Sscottl            TotalRespLen = sizeof(agsaSSPResponseInfoUnit_t);
2079285809Sscottl            /* collapse good response with READ */
2080285809Sscottl            if (ttdsaXchg->XchType == AGSA_SSP_TGT_READ_DATA)
2081285809Sscottl            {
2082285809Sscottl                TI_DBG4(("tiTGTSetResp: read rsp collapse\n"));
2083285809Sscottl
2084285809Sscottl                if (tdsaRoot->autoGoodRSP & READ_GOOD_RESPONSE)
2085285809Sscottl                    ttdsaXchg->readRspCollapsed = agTRUE;
2086285809Sscottl            }
2087285809Sscottl            /* collapse good response with WRITE */
2088285809Sscottl            if (ttdsaXchg->XchType == AGSA_SSP_TGT_WRITE_DATA)
2089285809Sscottl            {
2090285809Sscottl                TI_DBG4(("tiTGTSetResp: write rsp collapse\n"));
2091285809Sscottl                if (tdsaRoot->autoGoodRSP & WRITE_GOOD_RESPONSE)
2092285809Sscottl                {
2093285809Sscottl                  if (tiIS_SPC(TI_TIROOT_TO_AGROOT(tiRoot)))
2094285809Sscottl                  {
2095285809Sscottl                    ttdsaXchg->wrtRspCollapsed = agFALSE;
2096285809Sscottl                  }
2097285809Sscottl                  else
2098285809Sscottl                  {
2099285809Sscottl                    ttdsaXchg->wrtRspCollapsed = agTRUE;
2100285809Sscottl                  }
2101285809Sscottl
2102285809Sscottl                }
2103285809Sscottl            }
2104285809Sscottl        }
2105285809Sscottl        else
2106285809Sscottl        {
2107285809Sscottl            TI_DBG4 (("tiTGTSetResp: CMND, sense data\n"));
2108285809Sscottl            /* bad and sense data */
2109285809Sscottl            SASResp->agResp.dataPres = SENSE_DATA;
2110285809Sscottl            OSSA_WRITE_BE_32(agRoot, SASResp->agResp.responsedataLen, 0, 0);
2111285809Sscottl            OSSA_WRITE_BE_32(agRoot, SASResp->agResp.senseDataLen, 0, senseLength);
2112285809Sscottl            TotalRespLen = sizeof(agsaSSPResponseInfoUnit_t) + senseLength;
2113285809Sscottl        }
2114285809Sscottl    }
2115285809Sscottl
2116285809Sscottl    ttdsaXchg->statusSent = agTRUE;
2117285809Sscottl
2118285809Sscottl    TI_DBG4(("tiTGTSetResp: ttdsaXchg %p\n", ttdsaXchg));
2119285809Sscottl    TI_DBG4(("tiTGTSetResp: TotalRespLen 0x%x \n", TotalRespLen));
2120285809Sscottl    TI_DBG4(("tiTGTSetResp: upper 0x%x \n",
2121285809Sscottl            ttdsaXchg->resp.phyAddrUpper));
2122285809Sscottl    TI_DBG4(("tiTGTSetResp: lower 0x%x \n",
2123285809Sscottl            ttdsaXchg->resp.phyAddrLower));
2124285809Sscottl
2125285809Sscottl
2126285809Sscottl
2127285809Sscottl    /* set the correct response length */
2128285809Sscottl    ttdsaXchg->resp.length = TotalRespLen;
2129285809Sscottl
2130285809Sscottl    dumpresp((bit8 *)ttdsaXchg->resp.virtAddr, ttdsaXchg->resp.length);
2131285809Sscottl
2132285809Sscottl#ifdef REMOVED
2133285809Sscottl    /*
2134285809Sscottl    send TM reponse (which has only  response data not sense data here
2135285809Sscottl    since ramdisk does not call IOstart for this
2136285809Sscottl     */
2137285809Sscottl
2138285809Sscottl    if (ttdsaXchg->FrameType == SAS_TM)
2139285809Sscottl    {
2140285809Sscottl        TI_DBG1(("tiTGTSetResp: respsonse is set \n"));
2141285809Sscottl        TI_DBG1(("tiTGTSetResp: resp.length 0x%x\n",
2142285809Sscottl                ttdsaXchg->resp.length));
2143285809Sscottl        ttdsaSendResp(ttdsaXchg->agRoot, ttdsaXchg);
2144285809Sscottl    }
2145285809Sscottl#endif
2146285809Sscottl#ifdef REMOVED
2147285809Sscottl    /* sas response */
2148285809Sscottl    agSSPTargetResp =
2149285809Sscottl            &(ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse);
2150285809Sscottl
2151285809Sscottl    agSSPTargetResp->agTag = ttdsaXchg->tag;
2152285809Sscottl    agSSPTargetResp->respBufLength = TotalRespLen;
2153285809Sscottl    agSSPTargetResp->respBufUpper
2154285809Sscottl    = ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse.respBufUpper;
2155285809Sscottl    agSSPTargetResp->respBufLower
2156285809Sscottl    = ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse.respBufLower;
2157285809Sscottl
2158285809Sscottl
2159285809Sscottl
2160285809Sscottl    TI_DBG4(("tiTGTSetResp: len 0x%x \n",
2161285809Sscottl            ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse.respBufLength));
2162285809Sscottl    TI_DBG4(("tiTGTSetResp: upper 0x%x \n",
2163285809Sscottl            ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse.respBufUpper));
2164285809Sscottl    TI_DBG4(("tiTGTSetResp: lower 0x%x \n",
2165285809Sscottl            ttdsaXchg->IORequestBody.transport.SAS.agSASRequestBody.sspTargetResponse.respBufLower));
2166285809Sscottl#endif
2167285809Sscottl
2168285809Sscottl    return;
2169285809Sscottl}
2170285809Sscottl
2171285809Sscottl
2172285809Sscottl
2173285809Sscottl/******************************************************************************
2174285809Sscottl *
2175285809Sscottl *  tiTGTGetDeviceHandles
2176285809Sscottl *
2177285809Sscottl *  Purpose: This routine is called to to return the device handles for each
2178285809Sscottl *           device currently available.
2179285809Sscottl *
2180285809Sscottl *  Parameters:
2181285809Sscottl *     tiRoot:   Pointer to driver Instance.
2182285809Sscottl *     agDev[]:  Array to receive pointers to the device handles.
2183285809Sscottl *     maxDevs:  Number of device handles which will fit in array pointed
2184285809Sscottl *               by agDev.
2185285809Sscottl *  Return:
2186285809Sscottl *    Number of device handle slots present (however, only maxDevs
2187285809Sscottl *    are copied into tiDev[]) which may be greater than the number of
2188285809Sscottl *    handles actually present.
2189285809Sscottl *
2190285809Sscottl *  Note:
2191285809Sscottl *
2192285809Sscottl ******************************************************************************/
2193285809Sscottl
2194285809SscottlosGLOBAL bit32
2195285809SscottltiTGTGetDeviceHandles(
2196285809Sscottl        tiRoot_t            *tiRoot,
2197285809Sscottl        tiPortalContext_t   *tiPortalContext,
2198285809Sscottl        tiDeviceHandle_t    *tiDev[],
2199285809Sscottl        bit32               maxDevs
2200285809Sscottl)
2201285809Sscottl{
2202285809Sscottl    tdsaRoot_t                *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
2203285809Sscottl    tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2204285809Sscottl    ttdsaTgt_t                *Target = (ttdsaTgt_t *)tdsaAllShared->ttdsaTgt;
2205285809Sscottl    bit32                     deviceToReturn;
2206285809Sscottl    bit32                     devicePresent=0;
2207285809Sscottl    bit32                     deviceIndex=0;
2208285809Sscottl    tdList_t                  *PortContextList;
2209285809Sscottl    tdsaPortContext_t         *onePortContext = agNULL;
2210285809Sscottl    tdList_t                  *DeviceListList;
2211285809Sscottl    tdsaDeviceData_t          *oneDeviceData = agNULL;
2212285809Sscottl    bit32                     found = agFALSE;
2213285809Sscottl
2214285809Sscottl
2215285809Sscottl    TI_DBG4 (("tiTGTGetDeviceHandles: start\n"));
2216285809Sscottl
2217285809Sscottl    /* Check boundary condition */
2218285809Sscottl    if (maxDevs > Target->OperatingOption.MaxTargets)
2219285809Sscottl    {
2220285809Sscottl        deviceToReturn = Target->OperatingOption.MaxTargets;
2221285809Sscottl    }
2222285809Sscottl    else
2223285809Sscottl    {
2224285809Sscottl        deviceToReturn = maxDevs;
2225285809Sscottl    }
2226285809Sscottl
2227285809Sscottl
2228285809Sscottl    /* make sure tiPortalContext is valid */
2229285809Sscottl    PortContextList = tdsaAllShared->MainPortContextList.flink;
2230285809Sscottl    while (PortContextList != &(tdsaAllShared->MainPortContextList))
2231285809Sscottl    {
2232285809Sscottl        onePortContext = TDLIST_OBJECT_BASE(tdsaPortContext_t, MainLink, PortContextList);
2233285809Sscottl        if (onePortContext->tiPortalContext == tiPortalContext)
2234285809Sscottl        {
2235285809Sscottl            TI_DBG4(("tiTGTGetDeviceHandles: found; oneportContext ID %d\n", onePortContext->id));
2236285809Sscottl            found = agTRUE;
2237285809Sscottl            break;
2238285809Sscottl        }
2239285809Sscottl        PortContextList = PortContextList->flink;
2240285809Sscottl    }
2241285809Sscottl
2242285809Sscottl    if (found == agFALSE)
2243285809Sscottl    {
2244285809Sscottl        TI_DBG4(("tiTGTGetDeviceHandles: No corressponding tdsaPortContext\n"));
2245285809Sscottl        return 0;
2246285809Sscottl    }
2247285809Sscottl
2248285809Sscottl
2249285809Sscottl    /* go through device list and returns them */
2250285809Sscottl    DeviceListList = tdsaAllShared->MainDeviceList.flink;
2251285809Sscottl    while (DeviceListList != &(tdsaAllShared->MainDeviceList))
2252285809Sscottl    {
2253285809Sscottl        oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
2254285809Sscottl        TI_DBG4(("tiTGTGetDeviceHandles: pid %d did %d\n", onePortContext->id, oneDeviceData->id));
2255285809Sscottl        TI_DBG4(("tiTGTGetDeviceHandles: device AddrHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
2256285809Sscottl        TI_DBG4(("tiTGTGetDeviceHandles: device AddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
2257285809Sscottl        TI_DBG4(("tiTGTGetDeviceHandles: handle %p\n",  &(oneDeviceData->tiDeviceHandle)));
2258285809Sscottl        if (oneDeviceData->valid == agTRUE)
2259285809Sscottl        {
2260285809Sscottl            TI_DBG4(("tiTGTGetDeviceHandles: valid deviceindex %d devicePresent %d\n", deviceIndex, devicePresent));
2261285809Sscottl
2262285809Sscottl            tiDev[deviceIndex] = &(oneDeviceData->tiDeviceHandle);
2263285809Sscottl            devicePresent++;
2264285809Sscottl        }
2265285809Sscottl        else
2266285809Sscottl        {
2267285809Sscottl            tiDev[deviceIndex] = agNULL;
2268285809Sscottl            TI_DBG4(("tiTGTGetDeviceHandles: not valid deviceindex %d devicePresent %d\n", deviceIndex, devicePresent));
2269285809Sscottl        }
2270285809Sscottl        deviceIndex++;
2271285809Sscottl
2272285809Sscottl        if (devicePresent >= deviceToReturn )
2273285809Sscottl        {
2274285809Sscottl            break;
2275285809Sscottl        }
2276285809Sscottl        DeviceListList = DeviceListList->flink;
2277285809Sscottl    }
2278285809Sscottl
2279285809Sscottl    return devicePresent;
2280285809Sscottl}
2281285809Sscottl
2282285809Sscottl
2283285809Sscottl
2284285809Sscottl
2285285809Sscottl/******************************************************************************
2286285809Sscottl *
2287285809Sscottl *  tiTGTGetDeviceInfo
2288285809Sscottl *
2289285809Sscottl *  Purpose: This routine is called to to return the device information for
2290285809Sscottl *           specified device handle.
2291285809Sscottl *
2292285809Sscottl *  Parameters:
2293285809Sscottl *     tiRoot:   Pointer to driver Instance.
2294285809Sscottl *     tiDeviceHandle:  device handle associated with the device for which
2295285809Sscottl *                      information is queried
2296285809Sscottl *     tiDeviceInfo:    device information structure containing address and name.
2297285809Sscottl *
2298285809Sscottl *  Return:
2299285809Sscottl *     tiSuccess: if the device handle is valid.
2300285809Sscottl *     tiError  : if the device handle is not valid.
2301285809Sscottl *
2302285809Sscottl *  Note:
2303285809Sscottl *
2304285809Sscottl ******************************************************************************/
2305285809SscottlosGLOBAL bit32
2306285809SscottltiTGTGetDeviceInfo(
2307285809Sscottl        tiRoot_t            *tiRoot,
2308285809Sscottl        tiDeviceHandle_t    *tiDeviceHandle,
2309285809Sscottl        tiDeviceInfo_t      *tiDeviceInfo)
2310285809Sscottl{
2311285809Sscottl    tdsaDeviceData_t       *oneDeviceData = agNULL;
2312285809Sscottl
2313285809Sscottl
2314285809Sscottl    TI_DBG4 (("tiTGTGetDeviceInfo: start\n"));
2315285809Sscottl
2316285809Sscottl    if (tiDeviceHandle == agNULL)
2317285809Sscottl    {
2318285809Sscottl        TI_DBG4 (("tiTGTGetDeviceInfo: tiDeviceHandle is NULL\n"));
2319285809Sscottl        return tiError;
2320285809Sscottl    }
2321285809Sscottl
2322285809Sscottl    oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
2323285809Sscottl
2324285809Sscottl    if (oneDeviceData == agNULL)
2325285809Sscottl    {
2326285809Sscottl        TI_DBG4 (("tiTGTGetDeviceInfo: oneDeviceData is NULL\n"));
2327285809Sscottl        return tiError;
2328285809Sscottl    }
2329285809Sscottl
2330285809Sscottl    /* filling in the link rate */
2331285809Sscottl    if (oneDeviceData->registered == agTRUE)
2332285809Sscottl    {
2333285809Sscottl        tiDeviceInfo->info.devType_S_Rate = oneDeviceData->agDeviceInfo.devType_S_Rate;
2334285809Sscottl    }
2335285809Sscottl    else
2336285809Sscottl    {
2337285809Sscottl        tiDeviceInfo->info.devType_S_Rate = oneDeviceData->agDeviceInfo.devType_S_Rate & 0x0f;
2338285809Sscottl    }
2339285809Sscottl
2340285809Sscottl    /* temp just returning local and remote SAS address; doesn't have a name */
2341285809Sscottl    tiDeviceInfo->remoteName    = (char *)&(oneDeviceData->tdPortContext->sasRemoteAddressHi);
2342285809Sscottl    tiDeviceInfo->remoteAddress = (char *)&(oneDeviceData->tdPortContext->sasRemoteAddressLo);
2343285809Sscottl
2344285809Sscottl    tiDeviceInfo->localName     = (char *)&(oneDeviceData->tdPortContext->sasLocalAddressHi);
2345285809Sscottl    tiDeviceInfo->localAddress  = (char *)&(oneDeviceData->tdPortContext->sasLocalAddressLo);
2346285809Sscottl
2347285809Sscottl    return tiSuccess;
2348285809Sscottl}
2349285809Sscottl
2350285809Sscottl/*****************************************************************************
2351285809Sscottl *! \brief ttdssIOAbortedHandler
2352285809Sscottl *
2353285809Sscottl *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2354285809Sscottl *            layer with agIOStatus = OSSA_IO_ABORTED
2355285809Sscottl *
2356285809Sscottl *  \param  agRoot:            pointer to port instance
2357285809Sscottl *  \param  agIORequest:       pointer to I/O request
2358285809Sscottl *  \param  agIOStatus:        I/O status given by LL layer
2359285809Sscottl *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2360285809Sscottl *  \param  agParam            A Handle used to refer to the response frame or handle
2361285809Sscottl *                             of abort request
2362285809Sscottl *  \param  agOtherInfo        Residual count
2363285809Sscottl *  \return: None
2364285809Sscottl *
2365285809Sscottl *
2366285809Sscottl *****************************************************************************/
2367285809Sscottl/* see itdosIOCompleted() and itdinit.c and  itdIoAbortedHandler in itdio.c*/
2368285809SscottlosGLOBAL void
2369285809SscottlttdssIOAbortedHandler (
2370285809Sscottl        agsaRoot_t              *agRoot,
2371285809Sscottl        agsaIORequest_t         *agIORequest,
2372285809Sscottl        bit32                   agIOStatus,
2373285809Sscottl        bit32                   agIOInfoLen,
2374285809Sscottl        void                    *agParam,
2375285809Sscottl        bit32                   agOtherInfo
2376285809Sscottl)
2377285809Sscottl{
2378285809Sscottl    tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
2379285809Sscottl    tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
2380285809Sscottl    tdIORequestBody_t      *tdIORequestBody;
2381285809Sscottl
2382285809Sscottl    TI_DBG1(("itdssIOAbortedHandler: start\n"));
2383285809Sscottl    tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2384285809Sscottl
2385285809Sscottl    if (agIOStatus != OSSA_IO_ABORTED)
2386285809Sscottl    {
2387285809Sscottl        TI_DBG1(("itdssIOAbortedHandler: incorrect agIOStatus 0x%x\n", agIOStatus));
2388285809Sscottl
2389285809Sscottl    }
2390285809Sscottl
2391285809Sscottl    ostiTargetIOError(
2392285809Sscottl            tiRoot,
2393285809Sscottl            tdIORequestBody->tiIORequest,
2394285809Sscottl            tiIOFailed,
2395285809Sscottl            tiDetailAborted
2396285809Sscottl    );
2397285809Sscottl
2398285809Sscottl    return;
2399285809Sscottl}
2400285809Sscottl
2401285809Sscottl
2402