xref: /freebsd/sys/dev/pms/RefTisa/tisa/sassata/sas/ini/itdcb.c (revision fe75646a0234a261c0013bf1840fdac4acaf0cec)
1 /*******************************************************************************
2 **
3 *Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
4 *
5 *Redistribution and use in source and binary forms, with or without modification, are permitted provided
6 *that the following conditions are met:
7 *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8 *following disclaimer.
9 *2. Redistributions in binary form must reproduce the above copyright notice,
10 *this list of conditions and the following disclaimer in the documentation and/or other materials provided
11 *with the distribution.
12 *
13 *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
14 *WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15 *FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
18 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
19 *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
20 *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
21 **
22 ********************************************************************************/
23 /*****************************************************************************/
24 /** \file
25  *
26  * This file contains initiator CB functions
27  *
28  */
29 #include <sys/cdefs.h>
30 #include <dev/pms/config.h>
31 
32 #include <dev/pms/freebsd/driver/common/osenv.h>
33 #include <dev/pms/freebsd/driver/common/ostypes.h>
34 #include <dev/pms/freebsd/driver/common/osdebug.h>
35 
36 #include <dev/pms/RefTisa/sallsdk/api/sa.h>
37 #include <dev/pms/RefTisa/sallsdk/api/saapi.h>
38 #include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
39 
40 #include <dev/pms/RefTisa/tisa/api/titypes.h>
41 #include <dev/pms/RefTisa/tisa/api/ostiapi.h>
42 #include <dev/pms/RefTisa/tisa/api/tiapi.h>
43 #include <dev/pms/RefTisa/tisa/api/tiglobal.h>
44 
45 #ifdef FDS_SM
46 #include <dev/pms/RefTisa/sat/api/sm.h>
47 #include <dev/pms/RefTisa/sat/api/smapi.h>
48 #include <dev/pms/RefTisa/sat/api/tdsmapi.h>
49 #endif
50 
51 #ifdef FDS_DM
52 #include <dev/pms/RefTisa/discovery/api/dm.h>
53 #include <dev/pms/RefTisa/discovery/api/dmapi.h>
54 #include <dev/pms/RefTisa/discovery/api/tddmapi.h>
55 #endif
56 
57 #include <dev/pms/RefTisa/tisa/sassata/sas/common/tdtypes.h>
58 #include <dev/pms/freebsd/driver/common/osstring.h>
59 #include <dev/pms/RefTisa/tisa/sassata/common/tdutil.h>
60 
61 #ifdef INITIATOR_DRIVER
62 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdtypes.h>
63 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itddefs.h>
64 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdglobl.h>
65 #endif
66 
67 #ifdef TARGET_DRIVER
68 #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdglobl.h>
69 #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdxchg.h>
70 #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdtypes.h>
71 #endif
72 
73 #include <dev/pms/RefTisa/tisa/sassata/common/tdsatypes.h>
74 #include <dev/pms/RefTisa/tisa/sassata/common/tdproto.h>
75 
76 /*****************************************************************************
77 *!  \brief  itdssTaskCompleted
78 *
79 *  Purpose: This routine is called to complete an task management request
80 *           previously issued to the LL Layer. All task management completes with
81 *           this function except query task management.
82 *
83 *   \param  agRoot:         Pointer to driver Instance.
84 *   \param  agIORequest:    Pointer to the I/O Request data structure for
85 *                           this I/O.
86 *   \param  agIOStatus:     Status of I/O just completed.
87 *   \param  agIOInfoLen:    Length of the I/O information associated with this
88 *                           I/O request
89 *   \param   agParam        A Handle used to refer to the response frame or handle
90 *                           of abort request
91 *   \param  agOtherInfo        Residual count
92 *   \return:                None
93 *
94 *   \note - This is a initiator specific function called by the jump table.
95 *
96 *****************************************************************************/
97 osGLOBAL void
98 itdssTaskCompleted(
99                  agsaRoot_t             *agRoot,
100                  agsaIORequest_t        *agIORequest,
101                  bit32                  agIOStatus,
102                  bit32                  agIOInfoLen,
103                  void                   *agParam,
104                  bit32                  agOtherInfo
105                  )
106 {
107   tdsaRootOsData_t            *osData = (tdsaRootOsData_t *)agRoot->osData;
108   tiRoot_t                    *tiRoot = (tiRoot_t *)osData->tiRoot;
109   tiIORequest_t               *taskTag = agNULL, *currentTaskTag = agNULL;
110   tdIORequestBody_t           *tdIORequestBody = agNULL;
111   tdIORequestBody_t           *TMtdIORequestBody = agNULL;
112   tdIORequestBody_t           *AborttdIORequestBody = agNULL;
113   agsaIORequest_t             *agTaskedIORequest;
114   agsaSSPResponseInfoUnit_t   agSSPRespIU;
115   bit8                        respData[128];
116   bit32                       respLen;
117 #ifdef  TD_DEBUG_ENABLE
118   bit32                       data_status;
119 #endif
120   agsaSASRequestBody_t        *agSASRequestBody = agNULL;
121   agsaSSPScsiTaskMgntReq_t    *agSSPTaskMgntRequest = agNULL;
122   agsaIORequest_t             *agAbortIORequest;
123   tdIORequestBody_t           *tdAbortIORequestBody;
124   bit32                       PhysUpper32;
125   bit32                       PhysLower32;
126   bit32                       memAllocStatus;
127   void                        *osMemHandle;
128   bit32                       abortOrquery = agTRUE;
129   tiDeviceHandle_t            *tiDeviceHandle = agNULL;
130   tdsaDeviceData_t            *oneDeviceData = agNULL;
131   agsaDevHandle_t             *agDevHandle = agNULL;
132   bit32                        status = AGSA_RC_FAILURE;
133 
134   TI_DBG2(("itdssTaskCompleted: start\n"));
135 
136   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
137 
138   /* check the agIOStatus */
139   currentTaskTag = tdIORequestBody->IOType.InitiatorTMIO.CurrentTaskTag;
140 
141   if (currentTaskTag == agNULL)
142   {
143     TI_DBG1(("itdssTaskCompleted: currentTaskTag is NULL \n"));
144 	/* as the currentTaskTag is agNULL, shall not call ostiInitiatorEvent */
145 	#if 0
146     ostiInitiatorEvent( tiRoot,
147                         NULL,
148                         NULL,
149                         tiIntrEventTypeTaskManagement,
150                         tiTMFailed,
151                         currentTaskTag );
152     #endif
153     /* free up allocated memory */
154     ostiFreeMemory(
155                    tiRoot,
156                    tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
157                    sizeof(tdIORequestBody_t)
158                    );
159     return;
160   }
161 
162   if (agIOStatus != OSSA_IO_SUCCESS)
163   {
164     TI_DBG1(("itdssTaskCompleted: agIOStatus failed and tiTMFailed\n"));
165     if (agIOStatus == OSSA_IO_TM_TAG_NOT_FOUND)
166     {
167       TI_DBG1(("itdssTaskCompleted: agIOStatus OSSA_IO_TM_TAG_NOT_FOUND\n"));
168     }
169     else
170     if (agIOStatus == OSSA_IO_ABORTED)
171     {
172       TI_DBG1(("itdssTaskCompleted: agIOStatus OSSA_IO_ABORTED\n"));
173     }
174     else
175     {
176       TI_DBG1(("itdssTaskCompleted: agIOStatus 0x%x\n", agIOStatus));
177     }
178     ostiInitiatorEvent( tiRoot,
179                         NULL,
180                         NULL,
181                         tiIntrEventTypeTaskManagement,
182                         tiTMFailed,
183                         currentTaskTag );
184     /* free up allocated memory */
185     ostiFreeMemory(
186                    tiRoot,
187                    tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
188                    sizeof(tdIORequestBody_t)
189                    );
190     return;
191   }
192 
193   /* parse the task management response */
194   /* reads agsaSSPResponseInfoUnit_t */
195   saFrameReadBlock(agRoot, agParam, 0, &agSSPRespIU, sizeof(agsaSSPResponseInfoUnit_t));
196 #ifdef  TD_DEBUG_ENABLE
197   data_status = SA_SSPRESP_GET_DATAPRES(&agSSPRespIU);
198 #endif
199   respLen = SA_SSPRESP_GET_RESPONSEDATALEN(&agSSPRespIU);
200   TI_DBG6(("itdssTaskCompleted: dataPres %d. should be 1\n", data_status));
201   /* reads response data */
202   saFrameReadBlock(agRoot, agParam,
203                    sizeof(agsaSSPResponseInfoUnit_t),
204                    respData, respLen);
205   TI_DBG6(("itdssTaskCompleted: res code %d. should be 0\n", respData[3]));
206 
207   taskTag = tdIORequestBody->IOType.InitiatorTMIO.TaskTag;
208   if (taskTag == agNULL)
209   {
210     /* other than Abort Task or Query Task */
211     TI_DBG1(("itdssTaskCompleted: taskTag is NULL\n"));
212 
213     abortOrquery = agFALSE;
214     TMtdIORequestBody = (tdIORequestBody_t *)currentTaskTag->tdData;
215   }
216   else
217   {
218     /* Abort Task or Query Task */
219     TI_DBG2(("itdssTaskCompleted: taskTag is NOT NULL\n"));
220     abortOrquery = agTRUE;
221     TMtdIORequestBody = (tdIORequestBody_t *)currentTaskTag->tdData;
222   }
223 
224   TI_DBG2(("itdssTaskCompleted: TMtdIORequestBody %p\n", TMtdIORequestBody));
225 
226   if (TMtdIORequestBody == agNULL)
227   {
228     TI_DBG1(("itdssTaskCompleted: TMtdIORequestBody is NULL \n"));
229     ostiInitiatorEvent( tiRoot,
230                         NULL,
231                         NULL,
232                         tiIntrEventTypeTaskManagement,
233                         tiTMFailed,
234                         currentTaskTag );
235     /* free up allocated memory */
236     ostiFreeMemory(
237                    tiRoot,
238                    tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
239                    sizeof(tdIORequestBody_t)
240                    );
241     return;
242   }
243 
244   if (agIOStatus == OSSA_IO_SUCCESS && agIOInfoLen == 0)
245   {
246     TI_DBG1(("itdssTaskCompleted: agIOInfoLen is zero, wrong\n"));
247     ostiInitiatorEvent( tiRoot,
248                         NULL,
249                         NULL,
250                         tiIntrEventTypeTaskManagement,
251                         tiTMFailed,
252                         currentTaskTag );
253     /* free up allocated memory */
254     ostiFreeMemory(
255                    tiRoot,
256                    tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
257                    sizeof(tdIORequestBody_t)
258                    );
259     return;
260   }
261 
262   agSASRequestBody = (agsaSASRequestBody_t *)&(TMtdIORequestBody->transport.SAS.agSASRequestBody);
263   agSSPTaskMgntRequest = (agsaSSPScsiTaskMgntReq_t *)&(agSASRequestBody->sspTaskMgntReq);
264   TI_DBG2(("itdssTaskCompleted: agSSPTaskMgntRequest->taskMgntFunction 0x%x\n", agSSPTaskMgntRequest->taskMgntFunction));
265 
266   if ( (agSSPTaskMgntRequest->taskMgntFunction == AGSA_ABORT_TASK ||
267         agSSPTaskMgntRequest->taskMgntFunction == AGSA_QUERY_TASK) &&
268         abortOrquery == agFALSE
269       )
270   {
271     TI_DBG1(("itdssTaskCompleted: incorrect tasktag, first\n"));
272     ostiInitiatorEvent( tiRoot,
273                         NULL,
274                         NULL,
275                         tiIntrEventTypeTaskManagement,
276                         tiTMFailed,
277                         currentTaskTag );
278     /* free up allocated memory */
279     ostiFreeMemory(
280                    tiRoot,
281                    tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
282                    sizeof(tdIORequestBody_t)
283                    );
284     return;
285   }
286 
287   if ((agSSPTaskMgntRequest->taskMgntFunction == AGSA_ABORT_TASK_SET ||
288        agSSPTaskMgntRequest->taskMgntFunction == AGSA_CLEAR_TASK_SET ||
289        agSSPTaskMgntRequest->taskMgntFunction == AGSA_LOGICAL_UNIT_RESET ||
290        agSSPTaskMgntRequest->taskMgntFunction == AGSA_CLEAR_ACA ) &&
291        abortOrquery == agTRUE
292      )
293   {
294     TI_DBG1(("itdssTaskCompleted: incorrect tasktag, second\n"));
295     ostiInitiatorEvent( tiRoot,
296                         NULL,
297                         NULL,
298                         tiIntrEventTypeTaskManagement,
299                         tiTMFailed,
300                         currentTaskTag );
301     /* free up allocated memory */
302     ostiFreeMemory(
303                    tiRoot,
304                    tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
305                    sizeof(tdIORequestBody_t)
306                    );
307     return;
308   }
309 
310 
311   if (agSSPTaskMgntRequest->taskMgntFunction == AGSA_ABORT_TASK)
312   {
313     TI_DBG2(("itdssTaskCompleted: calling saSSPAbort()\n"));
314     AborttdIORequestBody = (tdIORequestBody_t *)taskTag->tdData;
315     if (AborttdIORequestBody == agNULL)
316     {
317       TI_DBG1(("itdssTaskCompleted: wrong, AborttdIORequestBody is NULL\n"));
318       return;
319     }
320 
321     tiDeviceHandle = AborttdIORequestBody->tiDevHandle;
322     if (tiDeviceHandle == agNULL)
323     {
324       TI_DBG1(("itdssTaskCompleted: wrong, tiDeviceHandle is NULL\n"));
325       return;
326     }
327     oneDeviceData  = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
328     if (oneDeviceData == agNULL)
329     {
330       TI_DBG1(("itdssTaskCompleted: wrong, oneDeviceData is NULL\n"));
331       return;
332     }
333     agDevHandle = oneDeviceData->agDevHandle;
334     if (agDevHandle == agNULL)
335     {
336       TI_DBG1(("itdssTaskCompleted: wrong, agDevHandle is NULL\n"));
337     }
338 
339     agTaskedIORequest = (agsaIORequest_t *)&(AborttdIORequestBody->agIORequest);
340     if (agTaskedIORequest == agNULL)
341     {
342       TI_DBG1(("itdssTaskCompleted: agTaskedIORequest is NULL \n"));
343       ostiInitiatorEvent( tiRoot,
344                           NULL,
345                           NULL,
346                           tiIntrEventTypeTaskManagement,
347                           tiTMFailed,
348                           currentTaskTag );
349       /* free up allocated memory */
350       ostiFreeMemory(
351                      tiRoot,
352                      tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
353                      sizeof(tdIORequestBody_t)
354                      );
355       return;
356     }
357 
358 
359     /* allocating agIORequest for abort itself */
360     memAllocStatus = ostiAllocMemory(
361                                      tiRoot,
362                                      &osMemHandle,
363                                      (void **)&tdAbortIORequestBody,
364                                      &PhysUpper32,
365                                      &PhysLower32,
366                                      8,
367                                      sizeof(tdIORequestBody_t),
368                                      agTRUE
369                                      );
370     if (memAllocStatus != tiSuccess)
371     {
372       /* let os process IO */
373       TI_DBG1(("itdssTaskCompleted: ostiAllocMemory failed...\n"));
374       return;
375     }
376 
377     if (tdAbortIORequestBody == agNULL)
378     {
379       /* let os process IO */
380       TI_DBG1(("itdssTaskCompleted: ostiAllocMemory returned NULL tdAbortIORequestBody\n"));
381       return;
382     }
383 
384     /* setup task management structure */
385     tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle = osMemHandle;
386     tdAbortIORequestBody->tiDevHandle = tiDeviceHandle;
387     /* setting callback */
388     tdAbortIORequestBody->IOCompletionFunc = itdssIOAbortedHandler;
389 
390     /* setting to NULL because the local abort is triggered by TD layer */
391     tdAbortIORequestBody->tiIOToBeAbortedRequest = agNULL;
392     /* initialize agIORequest */
393     agAbortIORequest = &(tdAbortIORequestBody->agIORequest);
394     agAbortIORequest->osData = (void *) tdAbortIORequestBody;
395     agAbortIORequest->sdkData = agNULL; /* LL takes care of this */
396 
397     status = saSSPAbort(agRoot, agAbortIORequest, tdsaRotateQnumber(tiRoot, oneDeviceData), agDevHandle, 0, agTaskedIORequest, agNULL);
398     if (status != AGSA_RC_SUCCESS)
399     {
400       TI_DBG1(("itdssTaskCompleted: saSSPAbort failed agIOInfoLen is zero, wrong\n"));
401       ostiFreeMemory(
402                      tiRoot,
403                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
404                      sizeof(tdIORequestBody_t)
405                      );
406     }
407   }
408 
409   /*
410     parse the response and based on the parse,
411     set the flag
412   */
413   if (respData[3] == AGSA_TASK_MANAGEMENT_FUNCTION_COMPLETE ||
414       respData[3] == AGSA_TASK_MANAGEMENT_FUNCTION_SUCCEEDED)
415   {
416     TI_DBG2(("itdssTaskCompleted: tiTMOK\n"));
417     tiDeviceHandle = TMtdIORequestBody->tiDevHandle;
418     if (tiDeviceHandle == agNULL)
419     {
420       TI_DBG1(("itdssTaskCompleted: wrong, tiDeviceHandle is NULL\n"));
421       return;
422     }
423     oneDeviceData  = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
424     if (oneDeviceData == agNULL)
425     {
426       TI_DBG1(("itdssTaskCompleted: wrong, oneDeviceData is NULL\n"));
427       return;
428     }
429     agDevHandle = oneDeviceData->agDevHandle;
430     if (agDevHandle == agNULL)
431     {
432       TI_DBG1(("itdssTaskCompleted: wrong, agDevHandle is NULL\n"));
433     }
434     TI_DBG2(("itdssTaskCompleted: setting Device state to SA_DS_OPERATIONAL\n"));
435 
436     saSetDeviceState(agRoot, agNULL, tdsaRotateQnumber(tiRoot, oneDeviceData), agDevHandle, SA_DS_OPERATIONAL);
437 
438     ostiInitiatorEvent( tiRoot,
439                         NULL,
440                         NULL,
441                         tiIntrEventTypeTaskManagement,
442                         tiTMOK,
443                         currentTaskTag );
444   }
445   else
446   {
447     TI_DBG1(("itdssTaskCompleted: tiTMFailed\n"));
448     ostiInitiatorEvent( tiRoot,
449                         NULL,
450                         NULL,
451                         tiIntrEventTypeTaskManagement,
452                         tiTMFailed,
453                         currentTaskTag );
454 
455   }
456 
457   /* free up allocated memory */
458   ostiFreeMemory(
459                  tiRoot,
460                  tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
461                  sizeof(tdIORequestBody_t)
462                  );
463   return;
464 }
465 
466 #ifdef INITIATOR_DRIVER
467 
468 /*****************************************************************************
469 *!  \brief  itdssQueryTaskCompleted
470 *
471 *  Purpose: This routine is called to complete an query task management request
472 *           previously issued to the LL Layer.
473 *
474 *   \param  agRoot:         Pointer to driver Instance.
475 *   \param  agIORequest:    Pointer to the I/O Request data structure for
476 *                           this I/O.
477 *   \param  agIOStatus:     Status of I/O just completed.
478 *   \param  agIOInfoLen:    Length of the I/O information associated with this
479 *                           I/O request
480 *   \param   agParam        A Handle used to refer to the response frame or handle
481 *                           of abort request
482 *
483 *   \return:                None
484 *
485 *   \note - This is a initiator specific function called by the jump table.
486 *
487 *****************************************************************************/
488 osGLOBAL void
489 itdssQueryTaskCompleted(
490                         agsaRoot_t             *agRoot,
491                         agsaIORequest_t        *agIORequest,
492                         bit32                  agIOStatus,
493                         bit32                  agIOInfoLen,
494                         void                   *agParam,
495                         bit32                  agOtherInfo
496                         )
497 {
498   tdsaRootOsData_t            *osData = (tdsaRootOsData_t *)agRoot->osData;
499   tiRoot_t                    *tiRoot = (tiRoot_t *)osData->tiRoot;
500   tiIORequest_t               *taskTag = agNULL;
501   tdIORequestBody_t           *tdIORequestBody = agNULL;  /* query task */
502   tdIORequestBody_t           *TMtdIORequestBody = agNULL; /* IO being query tasked */
503   agsaIORequest_t             *agTaskedIORequest = agNULL;
504   agsaSSPResponseInfoUnit_t   agSSPRespIU;
505   bit8                        respData[128];
506   bit32                       respLen;
507 #ifdef  TD_DEBUG_ENABLE
508   bit32                       data_status;
509 #endif
510   agsaSASRequestBody_t        *agSASRequestBody = agNULL;
511   agsaSSPScsiTaskMgntReq_t    *agSSPTaskMgntRequest = agNULL;
512   bit32                       status;
513   agsaIORequest_t             *agAbortIORequest = agNULL;
514   tdIORequestBody_t           *tdAbortIORequestBody = agNULL;
515   bit32                       PhysUpper32;
516   bit32                       PhysLower32;
517   bit32                       memAllocStatus;
518   void                        *osMemHandle = agNULL;
519   tiDeviceHandle_t            *tiDeviceHandle = agNULL;
520   tdsaDeviceData_t            *oneDeviceData = agNULL;
521   agsaDevHandle_t             *agDevHandle = agNULL;
522 
523   TI_DBG2(("itdssQueryTaskComplted: start\n"));
524 
525   /* query task management IORequestBody */
526   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
527 
528   /* OS's tiIORequest for this query taks, which is agNULL */
529   //currentTaskTag = tdIORequestBody->IOType.InitiatorTMIO.CurrentTaskTag;
530 
531   /*
532     currentTaskTag is agNULL for query task since it is generated by
533     TD layer
534   */
535   if (agIOStatus != OSSA_IO_SUCCESS)
536   {
537     /* let os process IO */
538     TI_DBG1(("itdssQueryTaskComplted: agIOStatus failed and tiTMFailed\n"));
539     /* free up allocated memory */
540     ostiFreeMemory(
541                    tiRoot,
542                    tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
543                    sizeof(tdIORequestBody_t)
544                    );
545     return;
546   }
547   /* parse the task management response */
548   /* reads agsaSSPResponseInfoUnit_t */
549   saFrameReadBlock(agRoot, agParam, 0, &agSSPRespIU, sizeof(agsaSSPResponseInfoUnit_t));
550 #ifdef  TD_DEBUG_ENABLE
551   data_status = SA_SSPRESP_GET_DATAPRES(&agSSPRespIU);
552 #endif
553   respLen = SA_SSPRESP_GET_RESPONSEDATALEN(&agSSPRespIU);
554 
555   TI_DBG6(("itdssQueryTaskCompleted: dataPres %d. should be 1\n", data_status));
556   /* reads response data */
557   saFrameReadBlock(agRoot, agParam,
558                    sizeof(agsaSSPResponseInfoUnit_t),
559                    respData, respLen);
560 
561   TI_DBG6(("itdssQueryTaskCompleted: res code %d. should be 0\n", respData[3]));
562 
563   /* IO being query tasked */
564   taskTag = tdIORequestBody->IOType.InitiatorTMIO.TaskTag;
565   if (taskTag == agNULL)
566   {
567     TI_DBG1(("itdssQueryTaskComplted: taskTag is NULL \n"));
568     /* free up allocated memory */
569     ostiFreeMemory(
570                    tiRoot,
571                    tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
572                    sizeof(tdIORequestBody_t)
573                    );
574     return;
575   }
576 
577   /* request body of IO being query tasked  */
578   TMtdIORequestBody = (tdIORequestBody_t *)taskTag->tdData;
579   if (TMtdIORequestBody == agNULL)
580   {
581     TI_DBG1(("itdssQueryTaskComplted: TMtdIORequestBody is NULL \n"));
582     /* free up allocated memory */
583     ostiFreeMemory(
584                    tiRoot,
585                    tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
586                    sizeof(tdIORequestBody_t)
587                    );
588     return;
589   }
590 
591   agTaskedIORequest = &(TMtdIORequestBody->agIORequest);
592   if (agTaskedIORequest == agNULL)
593   {
594     TI_DBG1(("itdssQueryTaskComplted: agTaskedIORequest is NULL \n"));
595     /* free up allocated memory */
596     ostiFreeMemory(
597                    tiRoot,
598                    tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
599                    sizeof(tdIORequestBody_t)
600                    );
601     return;
602   }
603 
604   if (agIOStatus == OSSA_IO_SUCCESS && agIOInfoLen == 0)
605   {
606     TI_DBG1(("itdssQueryTaskCompleted: agIOInfoLen is zero, wrong\n"));
607     /* free up allocated memory */
608     ostiFreeMemory(
609                    tiRoot,
610                    tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
611                    sizeof(tdIORequestBody_t)
612                    );
613    return;
614   }
615   /* this is query task itself */
616   agSASRequestBody = &(tdIORequestBody->transport.SAS.agSASRequestBody);
617   agSSPTaskMgntRequest = &(agSASRequestBody->sspTaskMgntReq);
618   if (agSSPTaskMgntRequest->taskMgntFunction == AGSA_QUERY_TASK)
619   {
620     /*
621       process response for query task
622       For query task, response code must be either
623       TASK MANAGEMENT FUNCTION COMPLETE or TASK MANAGEMENT FUNCTION SUCCEEDED by
624       SAM
625 
626       1. If TASK MANAGEMENT FUNCTION SUCCEEDE, do nothing
627 
628       2. If TASK MANAGEMENT FUNCTION COMPLETE and IO is not completed,
629       retry by saSSPAbort()
630     */
631     if (respData[3] == AGSA_TASK_MANAGEMENT_FUNCTION_SUCCEEDED)
632     {
633       /* OK; IO is being process at the target; do nothing */
634     }
635     else if (respData[3] == AGSA_TASK_MANAGEMENT_FUNCTION_COMPLETE)
636     {
637       tiDeviceHandle = TMtdIORequestBody->tiDevHandle;
638       if (tiDeviceHandle == agNULL)
639       {
640         TI_DBG1(("itdssQueryTaskCompleted: wrong, tiDeviceHandle is NULL\n"));
641         /* free up allocated memory */
642         ostiFreeMemory(
643                        tiRoot,
644                        tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
645                        sizeof(tdIORequestBody_t)
646                        );
647         return;
648       }
649       oneDeviceData  = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
650       if (oneDeviceData == agNULL)
651       {
652         TI_DBG1(("itdssQueryTaskCompleted: wrong, oneDeviceData is NULL\n"));
653         /* free up allocated memory */
654         ostiFreeMemory(
655                        tiRoot,
656                        tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
657                        sizeof(tdIORequestBody_t)
658                        );
659 
660         return;
661       }
662       agDevHandle = oneDeviceData->agDevHandle;
663       if (agDevHandle == agNULL)
664       {
665         TI_DBG1(("itdssQueryTaskCompleted: wrong, agDevHandle is NULL\n"));
666       }
667       /* if IO is not completed, retry IO by saSSPAbort() */
668       if (TMtdIORequestBody->ioCompleted != agTRUE)
669       {
670         /* allocating agIORequest for abort itself */
671         memAllocStatus = ostiAllocMemory(
672                                          tiRoot,
673                                          &osMemHandle,
674                                          (void **)&tdAbortIORequestBody,
675                                          &PhysUpper32,
676                                          &PhysLower32,
677                                          8,
678                                          sizeof(tdIORequestBody_t),
679                                          agTRUE
680                                          );
681         if (memAllocStatus != tiSuccess)
682         {
683           /* let os process IO */
684           TI_DBG1(("itdssQueryTaskCompleted: ostiAllocMemory failed...\n"));
685           /* free up allocated memory */
686           ostiFreeMemory(
687                          tiRoot,
688                          tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
689                          sizeof(tdIORequestBody_t)
690                          );
691 
692           return;
693         }
694         if (tdAbortIORequestBody == agNULL)
695         {
696           /* let os process IO */
697           TI_DBG1(("itdssQueryTaskCompleted: ostiAllocMemory returned NULL tdAbortIORequestBody\n"));
698           /* free up allocated memory */
699           ostiFreeMemory(
700                          tiRoot,
701                          tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
702                          sizeof(tdIORequestBody_t)
703                          );
704 
705           return;
706         }
707 
708         /* setup task management structure */
709         tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle = osMemHandle;
710         tdAbortIORequestBody->tiDevHandle = tdIORequestBody->tiDevHandle;
711         tdAbortIORequestBody->tiIOToBeAbortedRequest = agNULL;
712 
713         /* setting callback */
714         tdAbortIORequestBody->IOCompletionFunc = itdssIOAbortedHandler;
715 
716         /* initialize agIORequest */
717         agAbortIORequest = &(tdAbortIORequestBody->agIORequest);
718         agAbortIORequest->osData = (void *) tdAbortIORequestBody;
719         agAbortIORequest->sdkData = agNULL; /* LL takes care of this */
720 
721         TI_DBG2(("itdssQueryTaskCompleted: issuing saSSPAbort()\n"));
722         status = saSSPAbort(agRoot, agAbortIORequest, tdsaRotateQnumber(tiRoot, oneDeviceData), agDevHandle, 0, agTaskedIORequest, agNULL);
723         if (status != AGSA_RC_SUCCESS)
724         {
725           TI_DBG1(("itdssQueryTaskCompleted: saSSPAbort failed agIOInfoLen is zero, wrong\n"));
726           ostiFreeMemory(
727                          tiRoot,
728                          tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
729                          sizeof(tdIORequestBody_t)
730                          );
731         }
732       }
733     }
734     else
735     {
736       TI_DBG1(("itdssQueryTaskComplted: not expected response 0x%x\n",respData[3]));
737     }
738   }
739   else
740   {
741     TI_DBG1(("itdssQueryTaskCompleted: not expected task management fn %d\n",agSSPTaskMgntRequest->taskMgntFunction));
742   }
743 
744   /* free up allocated memory */
745   ostiFreeMemory(
746                  tiRoot,
747                  tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
748                  sizeof(tdIORequestBody_t)
749                  );
750   return;
751 }
752 #endif
753 
754 /*****************************************************************************
755 *!  \brief  itssdosIOCompleted
756 *
757 *  Purpose: This routine is called to complete an I/O request previously
758 *           issued to the LL Layer in saSSPStart().
759 *
760 *   \param  agRoot:       Pointer to driver Instance.
761 *   \param  agIORequest:  Pointer to the I/O Request data structure for
762 *                         this I/O.
763 *   \param  agIOStatus:   Status of I/O just completed.
764 *   \param  agIOInfoLen:  Length of the I/O information associated with this
765 *                         I/O request
766 *   \param   agParam      A Handle used to refer to the response frame or handle
767 *                         of abort request
768 *  \param  agOtherInfo    Residual count
769 *   \return:              None
770 *
771 *   \note - This is a initiator specific function called by the jump table.
772 *
773 *****************************************************************************/
774 FORCEINLINE void
775 itdssIOCompleted(
776                  agsaRoot_t             *agRoot,
777                  agsaIORequest_t        *agIORequest,
778                  bit32                   agIOStatus,
779                  bit32                   agIOInfoLen,
780                  void                   *agParam,
781                  bit32                   agOtherInfo
782                  )
783 {
784   tdsaRootOsData_t          *osData = (tdsaRootOsData_t *)agRoot->osData;
785   tiRoot_t                  *tiRoot = (tiRoot_t *)osData->tiRoot;
786   itdsaIni_t                *Initiator = (itdsaIni_t *)osData->itdsaIni;
787   tdIORequestBody_t         *tdIORequestBody  = agNULL;
788   agsaSASRequestBody_t      *agSASRequestBody = agNULL;
789   agsaSSPInitiatorRequest_t *agSSPInitiatorRequest = agNULL;
790   agsaSSPResponseInfoUnit_t  agSSPRespIU;
791 
792   bit32 scsi_status = 0;
793 
794   tiDeviceHandle_t          *tiDeviceHandle = agNULL;
795   tdsaDeviceData_t          *oneDeviceData  = agNULL;
796 
797   TI_DBG6(("itdssIOCompleted: start\n"));
798   TI_DBG6(("itdssIOCompleted: agIOInfoLen %d\n", agIOInfoLen));
799 
800   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
801   TD_ASSERT((NULL != tdIORequestBody), "itdssIOCompleted:tdIORequestBody NULL");
802   if ( NULL == tdIORequestBody )  // handle windows assert case
803   {
804     return;
805   }
806   Initiator->NumIOsActive--;
807 
808 #ifdef DBG
809   if (tdIORequestBody->ioCompleted == agTRUE)
810   {
811 #ifdef  TD_DEBUG_ENABLE
812     tiDeviceHandle = tdIORequestBody->tiDevHandle;
813     oneDeviceData  = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
814 #endif /*TD_DEBUG_ENABLE*/
815     TI_DBG1(("itdssIOCompleted: Error!!!!!! double completion\n"));
816 #ifdef  TD_DEBUG_ENABLE
817     TI_DBG1(("itdssIOCompleted: did %d \n", oneDeviceData->id));
818 #endif /*TD_DEBUG_ENABLE*/
819   }
820 
821   if (Initiator->NumIOsActive == 0)
822   {
823     /* so far, no timer assocaicated here */
824     TI_DBG6(("itdssIOCompleted: no acitve IO's. Kill timers\n"));
825   }
826 
827   if (tdIORequestBody->tiIORequest->osData == agNULL)
828   {
829     TI_DBG1( ("itdssIOCompleted: pos 1; "
830               "tdIORequestBody->tiIORequest->osData is null, wrong\n") );
831   }
832 #endif /*DBG*/
833 
834   tdIORequestBody->ioCompleted = agTRUE;
835   tdIORequestBody->ioStarted = agFALSE;
836 
837   /* Process completion for debugging, printing cbd */
838   agSASRequestBody = &(tdIORequestBody->transport.SAS.agSASRequestBody);
839   agSSPInitiatorRequest = &(agSASRequestBody->sspInitiatorReq);
840 
841   TI_DBG6( ("itdssIOCompleted: CDB 0x%x\n",
842             agSSPInitiatorRequest->sspCmdIU.cdb[0]) );
843 
844   /* no respsonse or sense data; data has been processed */
845   if((agIOStatus == OSSA_IO_SUCCESS) && (agIOInfoLen == 0))
846   {
847     // if this is a standard Inquiry command, notify Stoport to set the
848     // device queue depth to maximize oustanding IO
849     if ( (agSSPInitiatorRequest->sspCmdIU.cdb[0] == SCSIOPC_INQUIRY) &&
850          ((agSSPInitiatorRequest->sspCmdIU.cdb[1] & 0x01) == 0))
851     {
852       bit32 qdepth = 32;
853       tiDeviceHandle = tdIORequestBody->tiDevHandle;
854       if( tiDeviceHandle )
855       {
856         oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
857         if( oneDeviceData->DeviceType == TD_SAS_DEVICE )
858         {
859           qdepth = MAX_OUTSTANDING_IO_PER_LUN;
860         }
861         if( oneDeviceData->DeviceType == TD_SATA_DEVICE )
862         {
863           qdepth = 63;
864         }
865       }
866 
867       if ( ostiSetDeviceQueueDepth( tiRoot,
868                                     tdIORequestBody->tiIORequest,
869                                     MAX_OUTSTANDING_IO_PER_LUN ) == agFALSE )
870       {
871         TI_DBG1( ( "itdssIOCompleted: failed to call "
872                    "ostiSetDeviceQueueDepth() Q=%d !!!\n", qdepth ) );
873       }
874       else
875       {
876         TI_DBG2(("itdssIOCompleted: set ostiSetDeviceQueueDepth() Q=%d\n",qdepth));
877       }
878     }
879     // SCSI command was completed OK, this is the normal path. Now call the
880     // OS Specific module about this completion.
881     ostiInitiatorIOCompleted(
882                              tiRoot,
883                              tdIORequestBody->tiIORequest,
884                              tiIOSuccess,
885                              SCSI_STAT_GOOD,
886                              agNULL,
887                              agTRUE /* intContext; is not being used */
888                              );
889     return;
890   }
891 
892   else
893   {
894     TI_DBG6(("itdssIOCompleted: SUCCESS but data returned \n"));
895     TI_DBG6( ("itdssIOCompleted: agIOStatus SUCCESS but data returned 0x%x\n",
896               agIOStatus) );
897     if(tdIORequestBody)
898     {
899       tiDeviceHandle = tdIORequestBody->tiDevHandle;
900       if(tiDeviceHandle)
901       {
902         oneDeviceData  = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
903       }
904     }
905 
906     osti_memset(&agSSPRespIU, 0, sizeof(agsaSSPResponseInfoUnit_t));
907 
908     saFrameReadBlock( agRoot,
909                       agParam,
910                       0,
911                       &agSSPRespIU,
912                       sizeof(agsaSSPResponseInfoUnit_t) );
913     scsi_status = agSSPRespIU.status;
914 
915     switch (scsi_status)
916     {
917       case SCSI_STAT_GOOD:
918         TI_DBG2( ("itdssIOCompleted: SCSI_STAT_GOOD %d\n",
919                   Initiator->ScsiStatusCounts.GoodStatus) );
920         Initiator->ScsiStatusCounts.GoodStatus++;
921         break;
922        case SCSI_STAT_CHECK_CONDITION:
923         TI_DBG1( ("itdssIOCompleted: SCSI_STAT_CHECK_CONDITION %d\n",
924                   Initiator->ScsiStatusCounts.CheckCondition) );
925         Initiator->ScsiStatusCounts.CheckCondition++;
926         break;
927       case SCSI_STAT_BUSY:
928         TI_DBG1( ("itdssIOCompleted: SCSI_STAT_BUSY %d\n",
929                   Initiator->ScsiStatusCounts.BusyStatus) );
930         Initiator->ScsiStatusCounts.BusyStatus++;
931         break;
932       case SCSI_STAT_RESV_CONFLICT:
933         TI_DBG1( ("itdssIOCompleted: SCSI_STAT_RESV_CONFLICT %d\n",
934                   Initiator->ScsiStatusCounts.ResvConflict) );
935         Initiator->ScsiStatusCounts.ResvConflict++;
936         break;
937       case SCSI_STAT_TASK_SET_FULL:
938         Initiator->ScsiStatusCounts.TaskSetFull++;
939         //agIOStatus =  OSSA_IO_FAILED;
940         //agOtherInfo = tiDetailBusy;
941         TI_DBG1( ("itdssIOCompleted: SCSI_STAT_TASK_SET_FULL %d\n",
942                   Initiator->ScsiStatusCounts.TaskSetFull) );
943         break;
944       case SCSI_STAT_ACA_ACTIVE:
945         Initiator->ScsiStatusCounts.AcaActive++;
946         TI_DBG1( ("itdssIOCompleted: SCSI_STAT_ACA_ACTIVE %d\n",
947                   Initiator->ScsiStatusCounts.AcaActive) );
948         break;
949       case SCSI_STAT_TASK_ABORTED:
950         Initiator->ScsiStatusCounts.TaskAborted++;
951         TI_DBG1( ("itdssIOCompleted: SCSI_STAT_TASK_ABORTED %d\n",
952                   Initiator->ScsiStatusCounts.TaskAborted) );
953         break;
954       case SCSI_STAT_CONDITION_MET:
955         Initiator->ScsiStatusCounts.ConditionMet++;
956         TI_DBG1( ("itdssIOCompleted: SCSI_STAT_CONDITION_MET %d\n",
957                   Initiator->ScsiStatusCounts.ConditionMet) );
958         break;
959       case SCSI_STAT_INTERMEDIATE:
960         TI_DBG1( ("itdssIOCompleted: SCSI_STAT_INTERMEDIATE %d\n",
961                   Initiator->ScsiStatusCounts.ObsoleteStatus) );
962         Initiator->ScsiStatusCounts.ObsoleteStatus++;
963         break;
964       case SCSI_STAT_INTER_CONDIT_MET:
965         TI_DBG1( ("itdssIOCompleted: SCSI_STAT_INTER_CONDIT_MET %d\n",
966                   Initiator->ScsiStatusCounts.ObsoleteStatus) );
967         Initiator->ScsiStatusCounts.ObsoleteStatus++;
968         break;
969       case SCSI_STAT_COMMANDTERMINATED:
970         TI_DBG1( ("itdssIOCompleted: SCSI_STAT_COMMANDTERMINATED %d\n",
971                   Initiator->ScsiStatusCounts.ObsoleteStatus) );
972         Initiator->ScsiStatusCounts.ObsoleteStatus++;
973         break;
974       default:
975         Initiator->ScsiStatusCounts.ObsoleteStatus++;
976         TI_DBG1( ("itdssIOCompleted: Unknown scsi_status %d 0x%x\n",
977                   scsi_status,Initiator->ScsiStatusCounts.ObsoleteStatus) );
978     }
979 
980     switch (agIOStatus)
981     {
982     case OSSA_IO_SUCCESS:
983       itdssIOSuccessHandler( agRoot,
984                              agIORequest,
985                              agIOStatus,
986                              agIOInfoLen,
987                              agParam,
988                              agOtherInfo );
989       break;
990     case OSSA_IO_ABORTED:
991       itdssIOAbortedHandler( agRoot,
992                              agIORequest,
993                              agIOStatus,
994                              agIOInfoLen,
995                              agParam,
996                              agOtherInfo );
997       break;
998     case OSSA_IO_UNDERFLOW:
999       itdssIOUnderFlowHandler( agRoot,
1000                                agIORequest,
1001                                agIOStatus,
1002                                agIOInfoLen,
1003                                agParam,
1004                                agOtherInfo );
1005       break;
1006     case OSSA_IO_FAILED:
1007       itdssIOFailedHandler( agRoot,
1008                             agIORequest,
1009                             agIOStatus,
1010                             agIOInfoLen,
1011                             agParam,
1012                             agOtherInfo );
1013       break;
1014     case OSSA_IO_ABORT_RESET:
1015       itdssIOAbortResetHandler( agRoot,
1016                                 agIORequest,
1017                                 agIOStatus,
1018                                 agIOInfoLen,
1019                                 agParam,
1020                                 agOtherInfo );
1021       break;
1022     case OSSA_IO_NO_DEVICE:
1023       itdssIONoDeviceHandler( agRoot,
1024                               agIORequest,
1025                               agIOStatus,
1026                               agIOInfoLen,
1027                               agParam,
1028                               agOtherInfo );
1029       break;
1030     case OSSA_IO_XFER_ERROR_BREAK:
1031       itdssXferErrorBreakHandler( agRoot,
1032                                   agIORequest,
1033                                   agIOStatus,
1034                                   agIOInfoLen,
1035                                   agParam,
1036                                   agOtherInfo );
1037       break;
1038     case OSSA_IO_XFER_ERROR_PHY_NOT_READY:
1039       itdssXferErrorPhyNotReadyHandler( agRoot,
1040                                         agIORequest,
1041                                         agIOStatus,
1042                                         agIOInfoLen,
1043                                         agParam,
1044                                         agOtherInfo );
1045       break;
1046     case OSSA_IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
1047       itdssOpenCnxErrorProtocolNotSupprotedHandler( agRoot,
1048                                                     agIORequest,
1049                                                     agIOStatus,
1050                                                     agIOInfoLen,
1051                                                     agParam,
1052                                                     agOtherInfo );
1053       break;
1054     case OSSA_IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
1055       itdssOpenCnxErrorZoneViolationHandler( agRoot,
1056                                              agIORequest,
1057                                              agIOStatus,
1058                                              agIOInfoLen,
1059                                              agParam,
1060                                              agOtherInfo );
1061       break;
1062     case OSSA_IO_OPEN_CNX_ERROR_BREAK:
1063       itdssOpenCnxErrorBreakHandler( agRoot,
1064                                      agIORequest,
1065                                      agIOStatus,
1066                                      agIOInfoLen,
1067                                      agParam,
1068                                      agOtherInfo );
1069       break;
1070     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
1071       itdssOpenCnxErrorITNexusLossHandler( agRoot,
1072                                            agIORequest,
1073                                            agIOStatus,
1074                                            agIOInfoLen,
1075                                            agParam,
1076                                            agOtherInfo );
1077       break;
1078     case OSSA_IO_OPEN_CNX_ERROR_BAD_DESTINATION:
1079       itdssOpenCnxErrorBadDestinationHandler( agRoot,
1080                                               agIORequest,
1081                                               agIOStatus,
1082                                               agIOInfoLen,
1083                                               agParam,
1084                                               agOtherInfo );
1085       break;
1086     case OSSA_IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
1087       itdssOpenCnxErrorConnectionRateNotSupportedHandler( agRoot,
1088                                                           agIORequest,
1089                                                           agIOStatus,
1090                                                           agIOInfoLen,
1091                                                           agParam,
1092                                                           agOtherInfo );
1093       break;
1094     case OSSA_IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
1095       itdssOpenCnxErrorWrongDestinationHandler( agRoot,
1096                                                 agIORequest,
1097                                                 agIOStatus,
1098                                                 agIOInfoLen,
1099                                                 agParam,
1100                                                 agOtherInfo );
1101       break;
1102     case OSSA_IO_OPEN_CNX_ERROR_UNKNOWN_ERROR:
1103       itdssOpenCnxErrorUnknownErrorHandler( agRoot,
1104                                             agIORequest,
1105                                             agIOStatus,
1106                                             agIOInfoLen,
1107                                             agParam,
1108                                             agOtherInfo );
1109       break;
1110     case OSSA_IO_XFER_ERROR_NAK_RECEIVED:
1111       itdssXferErrorNAKReceivedHandler( agRoot,
1112                                         agIORequest,
1113                                         agIOStatus,
1114                                         agIOInfoLen,
1115                                         agParam,
1116                                         agOtherInfo );
1117       break;
1118     case OSSA_IO_XFER_ERROR_ACK_NAK_TIMEOUT:
1119       itdssXferErrorACKNAKTimeoutHandler( agRoot,
1120                                           agIORequest,
1121                                           agIOStatus,
1122                                           agIOInfoLen,
1123                                           agParam,
1124                                           agOtherInfo );
1125       break;
1126     case OSSA_IO_XFER_ERROR_DMA:
1127       itdssXferErrorDMAHandler( agRoot,
1128                                 agIORequest,
1129                                 agIOStatus,
1130                                 agIOInfoLen,
1131                                 agParam,
1132                                 agOtherInfo );
1133       break;
1134     case OSSA_IO_XFER_ERROR_OFFSET_MISMATCH:
1135       itdssXferErrorOffsetMismatchHandler( agRoot,
1136                                            agIORequest,
1137                                            agIOStatus,
1138                                            agIOInfoLen,
1139                                            agParam,
1140                                            agOtherInfo );
1141       break;
1142     case OSSA_IO_XFER_OPEN_RETRY_TIMEOUT:
1143       itdssXferOpenRetryTimeoutHandler( agRoot,
1144                                         agIORequest,
1145                                         agIOStatus,
1146                                         agIOInfoLen,
1147                                         agParam,
1148                                         agOtherInfo );
1149       break;
1150     case OSSA_IO_PORT_IN_RESET:
1151       itdssPortInResetHandler( agRoot,
1152                                agIORequest,
1153                                agIOStatus,
1154                                agIOInfoLen,
1155                                agParam,
1156                                agOtherInfo );
1157       break;
1158     case OSSA_IO_DS_NON_OPERATIONAL:
1159       itdssDsNonOperationalHandler( agRoot,
1160                                     agIORequest,
1161                                     agIOStatus,
1162                                     agIOInfoLen,
1163                                     agParam,
1164                                     agOtherInfo );
1165       break;
1166     case OSSA_IO_DS_IN_RECOVERY:
1167       itdssDsInRecoveryHandler( agRoot,
1168                                 agIORequest,
1169                                 agIOStatus,
1170                                 agIOInfoLen,
1171                                 agParam,
1172                                 agOtherInfo );
1173       break;
1174     case OSSA_IO_TM_TAG_NOT_FOUND:
1175       itdssTmTagNotFoundHandler( agRoot,
1176                                  agIORequest,
1177                                  agIOStatus,
1178                                  agIOInfoLen,
1179                                  agParam,
1180                                  agOtherInfo );
1181       break;
1182     case OSSA_IO_SSP_EXT_IU_ZERO_LEN_ERROR:
1183       itdssSSPExtIUZeroLenHandler( agRoot,
1184                                    agIORequest,
1185                                    agIOStatus,
1186                                    agIOInfoLen,
1187                                    agParam,
1188                                    agOtherInfo );
1189       break;
1190     case OSSA_IO_XFER_ERROR_UNEXPECTED_PHASE:
1191       itdssXferErrorUnexpectedPhaseHandler( agRoot,
1192                                             agIORequest,
1193                                             agIOStatus,
1194                                             agIOInfoLen,
1195                                             agParam,
1196                                             agOtherInfo );
1197       break;
1198 //new
1199     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
1200       itdssXferOpenRetryBackoffThresholdReachedHandler( agRoot,
1201                                                         agIORequest,
1202                                                         agIOStatus,
1203                                                         agIOInfoLen,
1204                                                         agParam,
1205                                                         agOtherInfo );
1206       break;
1207     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
1208       itdssOpenCnxErrorItNexusLossOpenTmoHandler( agRoot,
1209                                                   agIORequest,
1210                                                   agIOStatus,
1211                                                   agIOInfoLen,
1212                                                   agParam,
1213                                                   agOtherInfo );
1214       break;
1215     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
1216       itdssOpenCnxErrorItNexusLossNoDestHandler( agRoot,
1217                                                  agIORequest,
1218                                                  agIOStatus,
1219                                                  agIOInfoLen,
1220                                                  agParam,
1221                                                  agOtherInfo );
1222       break;
1223     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
1224       itdssOpenCnxErrorItNexusLossOpenCollideHandler( agRoot,
1225                                                       agIORequest,
1226                                                       agIOStatus,
1227                                                       agIOInfoLen,
1228                                                       agParam,
1229                                                       agOtherInfo );
1230       break;
1231     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
1232       itdssOpenCnxErrorItNexusLossOpenPathwayBlockedHandler( agRoot,
1233                                                              agIORequest,
1234                                                              agIOStatus,
1235                                                              agIOInfoLen,
1236                                                              agParam,
1237                                                              agOtherInfo );
1238       break;
1239       // encryption IO error handling
1240     case OSSA_IO_XFR_ERROR_DEK_KEY_CACHE_MISS:
1241     case OSSA_IO_XFR_ERROR_DEK_KEY_TAG_MISMATCH:
1242     case OSSA_IO_XFR_ERROR_CIPHER_MODE_INVALID:
1243     case OSSA_IO_XFR_ERROR_DEK_IV_MISMATCH:
1244     case OSSA_IO_XFR_ERROR_DEK_RAM_INTERFACE_ERROR:
1245     case OSSA_IO_XFR_ERROR_INTERNAL_RAM:
1246     case OSSA_IO_XFR_ERROR_DEK_INDEX_OUT_OF_BOUNDS:
1247       itdssEncryptionHandler( agRoot,
1248                               agIORequest,
1249                               agIOStatus,
1250                               agIOInfoLen,
1251                               agParam,
1252                               agOtherInfo );
1253       break;
1254 
1255     /* DIF IO error handling */
1256     case OSSA_IO_XFR_ERROR_DIF_MISMATCH:
1257     case OSSA_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH:
1258     case OSSA_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH:
1259     case OSSA_IO_XFR_ERROR_DIF_CRC_MISMATCH:
1260       itdssDifHandler( agRoot,
1261                        agIORequest,
1262                        agIOStatus,
1263                        agIOInfoLen,
1264                        agParam,
1265                        agOtherInfo );
1266       break;
1267     case OSSA_MPI_ERR_IO_RESOURCE_UNAVAILABLE:
1268       itdssIOResourceUnavailableHandler( agRoot,
1269                                          agIORequest,
1270                                          agIOStatus,
1271                                          agIOInfoLen,
1272                                          agParam,
1273                                          agOtherInfo );
1274       break;
1275     case OSSA_MPI_IO_RQE_BUSY_FULL:
1276       itdssIORQEBusyFullHandler( agRoot,
1277                                  agIORequest,
1278                                  agIOStatus,
1279                                  agIOInfoLen,
1280                                  agParam,
1281                                  agOtherInfo );
1282       break;
1283     case OSSA_IO_XFR_ERROR_INVALID_SSP_RSP_FRAME:
1284       itdssXferErrorInvalidSSPRspFrameHandler( agRoot,
1285                                                agIORequest,
1286                                                agIOStatus,
1287                                                agIOInfoLen,
1288                                                agParam,
1289                                                agOtherInfo );
1290       break;
1291     case OSSA_IO_XFER_ERR_EOB_DATA_OVERRUN:
1292       itdssXferErrorEOBDataOverrunHandler( agRoot,
1293                                            agIORequest,
1294                                            agIOStatus,
1295                                            agIOInfoLen,
1296                                            agParam,
1297                                            agOtherInfo );
1298       break;
1299     case OSSA_IO_OPEN_CNX_ERROR_OPEN_PREEMPTED:
1300       itdssOpenCnxErrorOpenPreemptedHandler( agRoot,
1301                                              agIORequest,
1302                                              agIOStatus,
1303                                              agIOInfoLen,
1304                                              agParam,
1305                                              agOtherInfo );
1306       break;
1307     default:
1308       TI_DBG1( ("itdssIOCompleted: Unknown agIOStatus 0x%x\n",agIOStatus) );
1309       itdssIODefaultHandler( agRoot,
1310                              agIORequest,
1311                              agIOStatus,
1312                              agIOInfoLen,
1313                              agParam,
1314                              agOtherInfo );
1315       break;
1316     }
1317   }
1318   return;
1319 }
1320 
1321 #ifdef TD_DISCOVER
1322 /*****************************************************************************
1323 *!  \brief  itdssSMPCompleted
1324 *
1325 *  Purpose: This routine is called to complete an SMP request previously
1326 *           issued to the LL Layer in saSMPStart().
1327 *
1328 *   \param  agRoot:         Pointer to driver Instance.
1329 *   \param  agIORequest:    Pointer to the I/O Request data structure for
1330 *                           this I/O.
1331 *   \param  agIOStatus:     Status of I/O just completed.
1332 *   \param  agIOInfoLen:    Length of the I/O information associated with this
1333 *                           I/O request
1334 *   \param   agFrameHandle  A Handle used to refer to the response frame
1335 *
1336 *   \return:                None
1337 *
1338 *   \note - This is a initiator specific function called by the jump table.
1339 *
1340 *****************************************************************************/
1341 osGLOBAL void
1342 itdssSMPCompleted (
1343                    agsaRoot_t            *agRoot,
1344                    agsaIORequest_t       *agIORequest,
1345                    bit32                 agIOStatus,
1346                    bit32                 agIOInfoLen,
1347                    agsaFrameHandle_t     agFrameHandle
1348                    )
1349 {
1350   tdsaRootOsData_t          *osData = (tdsaRootOsData_t *)agRoot->osData;
1351   tiRoot_t                  *tiRoot = (tiRoot_t *)osData->tiRoot;
1352 #ifdef REMOVED
1353   tdsaRoot_t                *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1354   tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&(tdsaRoot->tdsaAllShared);
1355 #endif
1356   tdssSMPRequestBody_t      *tdSMPRequestBody;
1357   agsaSASRequestBody_t      *agSASRequestBody;
1358   agsaSMPFrame_t            *agSMPFrame;
1359   tdsaDeviceData_t          *oneDeviceData;
1360   tiIORequest_t             *CurrentTaskTag;
1361   tdsaPortContext_t         *onePortContext;
1362   tdsaPortContext_t         *oldonePortContext;
1363   smpReqPhyControl_t        *smpPhyControlReq;
1364   bit8                      smpHeader[4];
1365   tdssSMPFrameHeader_t      *tdSMPFrameHeader;
1366   bit8                      *tdSMPPayload;
1367   agsaDevHandle_t           *agDevHandle;
1368   bit32                     status;
1369 #ifndef DIRECT_SMP
1370   tdssSMPFrameHeader_t      *tdRequestSMPFrameHeader;
1371   bit8                      smpRequestHeader[4];
1372 #endif
1373   bit8                      SMPRequestFunction;
1374 
1375   TI_DBG3(("itdssSMPCompleted: start\n"));
1376 
1377 
1378   tdSMPRequestBody = (tdssSMPRequestBody_t *)agIORequest->osData;
1379   CurrentTaskTag  = tdSMPRequestBody->CurrentTaskTag;
1380 
1381   oneDeviceData = tdSMPRequestBody->tdDevice;
1382   onePortContext = oneDeviceData->tdPortContext;
1383   agDevHandle = oneDeviceData->agDevHandle;
1384 
1385 
1386   agSASRequestBody = &(tdSMPRequestBody->agSASRequestBody);
1387   agSMPFrame = &(agSASRequestBody->smpFrame);
1388 
1389 #ifdef DIRECT_SMP
1390   SMPRequestFunction = tdSMPRequestBody->smpPayload[1];
1391 #else
1392   saFrameReadBlock(agRoot, tdSMPRequestBody->IndirectSMPResp, 0, smpRequestHeader, 4);
1393   tdRequestSMPFrameHeader = (tdssSMPFrameHeader_t *)smpRequestHeader;
1394   SMPRequestFunction = tdRequestSMPFrameHeader->smpFunction;
1395 #endif
1396 
1397   TI_DBG3(("itdssSMPCompleted: agIORequest %p\n", agIORequest));
1398   TI_DBG3(("itdssSMPCompleted: SMPRequestbody %p\n", tdSMPRequestBody));
1399 
1400   if (onePortContext != agNULL)
1401   {
1402     TI_DBG3(("itdssSMPCompleted: pid %d\n", onePortContext->id));
1403   }
1404   else
1405   {
1406     TI_DBG1(("itdssSMPCompleted: Wrong!!! onePortContext is NULL\n"));
1407     ostiFreeMemory(
1408                  tiRoot,
1409                  tdSMPRequestBody->osMemHandle,
1410                  sizeof(tdssSMPRequestBody_t)
1411                  );
1412 #ifndef DIRECT_SMP
1413     ostiFreeMemory(
1414                  tiRoot,
1415                  tdSMPRequestBody->IndirectSMPReqosMemHandle,
1416                  tdSMPRequestBody->IndirectSMPReqLen
1417                  );
1418     ostiFreeMemory(
1419                  tiRoot,
1420                  tdSMPRequestBody->IndirectSMPResposMemHandle,
1421                  tdSMPRequestBody->IndirectSMPRespLen
1422                  );
1423 #endif
1424     return;
1425   }
1426 
1427   oldonePortContext = tdSMPRequestBody->tdPortContext;
1428   if (oldonePortContext != agNULL)
1429   {
1430     TI_DBG3(("itdssSMPCompleted: old pid %d\n", oldonePortContext->id));
1431   }
1432   else
1433   {
1434     TI_DBG1(("itdssSMPCompleted: Wrong!!! oldonePortContext is NULL\n"));
1435     ostiFreeMemory(
1436                  tiRoot,
1437                  tdSMPRequestBody->osMemHandle,
1438                  sizeof(tdssSMPRequestBody_t)
1439                  );
1440 #ifndef DIRECT_SMP
1441     ostiFreeMemory(
1442                  tiRoot,
1443                  tdSMPRequestBody->IndirectSMPReqosMemHandle,
1444                  tdSMPRequestBody->IndirectSMPReqLen
1445                  );
1446     ostiFreeMemory(
1447                  tiRoot,
1448                  tdSMPRequestBody->IndirectSMPResposMemHandle,
1449                  tdSMPRequestBody->IndirectSMPRespLen
1450                  );
1451 #endif
1452     return;
1453   }
1454 
1455 
1456   /* decrement the number of pending SMP */
1457   onePortContext->discovery.pendingSMP--;
1458 
1459   /* for port invalid case;
1460      full discovery -> full discovery; incremental discovery -> full discovery
1461    */
1462   if (onePortContext != oldonePortContext)
1463   {
1464     TI_DBG1(("itdssSMPCompleted: portcontext has changed!!!\n"));
1465     if (SMPRequestFunction == SMP_REPORT_GENERAL || SMPRequestFunction == SMP_DISCOVER ||
1466         SMPRequestFunction == SMP_REPORT_PHY_SATA ||
1467         SMPRequestFunction == SMP_CONFIGURE_ROUTING_INFORMATION )
1468     {
1469       /* stop SMP timer */
1470       if (onePortContext->discovery.DiscoverySMPTimer.timerRunning == agTRUE)
1471       {
1472         tdsaKillTimer(
1473                       tiRoot,
1474                       &(onePortContext->discovery.DiscoverySMPTimer)
1475                      );
1476       }
1477       if (oldonePortContext->discovery.DiscoverySMPTimer.timerRunning == agTRUE)
1478       {
1479         tdsaKillTimer(
1480                       tiRoot,
1481                       &(oldonePortContext->discovery.DiscoverySMPTimer)
1482                      );
1483       }
1484     }
1485 
1486     /* clean up expanders data strucures; move to free exp when device is cleaned */
1487     tdsaCleanAllExp(tiRoot, oldonePortContext);
1488     /* remove devices */
1489     tdssInternalRemovals(oldonePortContext->agRoot,
1490                          oldonePortContext
1491                          );
1492 
1493     ostiFreeMemory(
1494                  tiRoot,
1495                  tdSMPRequestBody->osMemHandle,
1496                  sizeof(tdssSMPRequestBody_t)
1497                  );
1498 #ifndef DIRECT_SMP
1499     ostiFreeMemory(
1500                  tiRoot,
1501                  tdSMPRequestBody->IndirectSMPReqosMemHandle,
1502                  tdSMPRequestBody->IndirectSMPReqLen
1503                  );
1504     ostiFreeMemory(
1505                  tiRoot,
1506                  tdSMPRequestBody->IndirectSMPResposMemHandle,
1507                  tdSMPRequestBody->IndirectSMPRespLen
1508                  );
1509 #endif
1510     return;
1511   }
1512 
1513   if (onePortContext->valid == agFALSE)
1514   {
1515     if (SMPRequestFunction == SMP_REPORT_GENERAL || SMPRequestFunction == SMP_DISCOVER ||
1516         SMPRequestFunction == SMP_REPORT_PHY_SATA ||
1517         SMPRequestFunction == SMP_CONFIGURE_ROUTING_INFORMATION )
1518     {
1519       /* stop SMP timer */
1520       if (onePortContext->discovery.DiscoverySMPTimer.timerRunning == agTRUE)
1521       {
1522         tdsaKillTimer(
1523                       tiRoot,
1524                       &(onePortContext->discovery.DiscoverySMPTimer)
1525                       );
1526       }
1527       if (oldonePortContext->discovery.DiscoverySMPTimer.timerRunning == agTRUE)
1528       {
1529         tdsaKillTimer(
1530                       tiRoot,
1531                       &(oldonePortContext->discovery.DiscoverySMPTimer)
1532                       );
1533       }
1534     }
1535 
1536     if (onePortContext->discovery.pendingSMP == 0)
1537     {
1538       TI_DBG1(("itdssSMPCompleted: aborting discovery\n"));
1539       tdsaSASDiscoverAbort(tiRoot, onePortContext);
1540     }
1541     else
1542     {
1543       TI_DBG1(("itdssSMPCompleted: not yet abort; non zero pendingSMP %d\n", onePortContext->discovery.pendingSMP));
1544     }
1545     ostiFreeMemory(
1546                  tiRoot,
1547                  tdSMPRequestBody->osMemHandle,
1548                  sizeof(tdssSMPRequestBody_t)
1549                  );
1550 #ifndef DIRECT_SMP
1551     ostiFreeMemory(
1552                  tiRoot,
1553                  tdSMPRequestBody->IndirectSMPReqosMemHandle,
1554                  tdSMPRequestBody->IndirectSMPReqLen
1555                  );
1556     ostiFreeMemory(
1557                  tiRoot,
1558                  tdSMPRequestBody->IndirectSMPResposMemHandle,
1559                  tdSMPRequestBody->IndirectSMPRespLen
1560                  );
1561 #endif
1562     return;
1563   }
1564 
1565 
1566   if (SMPRequestFunction == SMP_REPORT_GENERAL || SMPRequestFunction == SMP_DISCOVER ||
1567       SMPRequestFunction == SMP_REPORT_PHY_SATA ||
1568       SMPRequestFunction == SMP_CONFIGURE_ROUTING_INFORMATION )
1569   {
1570     /* stop SMP timer */
1571     if (onePortContext->discovery.DiscoverySMPTimer.timerRunning == agTRUE)
1572     {
1573       tdsaKillTimer(
1574                     tiRoot,
1575                     &(onePortContext->discovery.DiscoverySMPTimer)
1576                     );
1577     }
1578     if (oldonePortContext->discovery.DiscoverySMPTimer.timerRunning == agTRUE)
1579     {
1580       tdsaKillTimer(
1581                     tiRoot,
1582                     &(oldonePortContext->discovery.DiscoverySMPTimer)
1583                     );
1584     }
1585   }
1586 
1587   /* the host as of 4/16/08 does not use indirect SMP. So, check only OSSA_IO_SUCCESS status*/
1588   if (agIOStatus == OSSA_IO_SUCCESS)
1589   {
1590     //tdhexdump("itdssSMPCompleted", (bit8*)agFrameHandle, agIOInfoLen);
1591     /* parsing SMP payload */
1592 #ifdef DIRECT_SMP
1593     saFrameReadBlock(agRoot, agFrameHandle, 0, smpHeader, 4);
1594 #else
1595     saFrameReadBlock(agRoot, tdSMPRequestBody->IndirectSMPResp, 0, smpHeader, 4);
1596 #endif
1597     tdSMPFrameHeader = (tdssSMPFrameHeader_t *)smpHeader;
1598 
1599     /* SMP function dependent payload */
1600     switch (tdSMPFrameHeader->smpFunction)
1601     {
1602     case SMP_REPORT_GENERAL:
1603       TI_DBG3(("itdssSMPCompleted: report general\n"));
1604       if (agIOInfoLen != sizeof(smpRespReportGeneral_t) + 4 &&
1605           tdSMPFrameHeader->smpFunctionResult == SMP_FUNCTION_ACCEPTED)
1606       {
1607         TI_DBG1(("itdssSMPCompleted: mismatch len agIOInfoLen 0x%x 0x%x\n", agIOInfoLen, (unsigned int)sizeof(smpRespReportGeneral_t) + 4));
1608         tdsaSASDiscoverDone(tiRoot, onePortContext, tiError);
1609         ostiFreeMemory(
1610                        tiRoot,
1611                        tdSMPRequestBody->osMemHandle,
1612                        sizeof(tdssSMPRequestBody_t)
1613                       );
1614 #ifndef DIRECT_SMP
1615         ostiFreeMemory(
1616                        tiRoot,
1617                        tdSMPRequestBody->IndirectSMPReqosMemHandle,
1618                        tdSMPRequestBody->IndirectSMPReqLen
1619                       );
1620         ostiFreeMemory(
1621                        tiRoot,
1622                        tdSMPRequestBody->IndirectSMPResposMemHandle,
1623                        tdSMPRequestBody->IndirectSMPRespLen
1624                       );
1625 #endif
1626         return;
1627       }
1628       tdsaReportGeneralRespRcvd(
1629                                 tiRoot,
1630                                 agRoot,
1631                                 agIORequest,
1632                                 oneDeviceData,
1633                                 tdSMPFrameHeader,
1634                                 agFrameHandle
1635                                 );
1636 
1637       break;
1638     case SMP_DISCOVER:
1639       TI_DBG3(("itdssSMPCompleted: discover\n"));
1640       if (agIOInfoLen != sizeof(smpRespDiscover_t) + 4 &&
1641           tdSMPFrameHeader->smpFunctionResult == SMP_FUNCTION_ACCEPTED)
1642       {
1643         TI_DBG1(("itdssSMPCompleted: mismatch len agIOInfoLen 0x%x 0x%x\n", agIOInfoLen, (unsigned int)sizeof(smpRespDiscover_t) + 4));
1644         tdsaSASDiscoverDone(tiRoot, onePortContext, tiError);
1645         ostiFreeMemory(
1646                        tiRoot,
1647                        tdSMPRequestBody->osMemHandle,
1648                        sizeof(tdssSMPRequestBody_t)
1649                       );
1650 #ifndef DIRECT_SMP
1651         ostiFreeMemory(
1652                        tiRoot,
1653                        tdSMPRequestBody->IndirectSMPReqosMemHandle,
1654                        tdSMPRequestBody->IndirectSMPReqLen
1655                       );
1656         ostiFreeMemory(
1657                        tiRoot,
1658                        tdSMPRequestBody->IndirectSMPResposMemHandle,
1659                        tdSMPRequestBody->IndirectSMPRespLen
1660                       );
1661 #endif
1662         return;
1663       }
1664       tdsaDiscoverRespRcvd(
1665                            tiRoot,
1666                            agRoot,
1667                            agIORequest,
1668                            oneDeviceData,
1669                            tdSMPFrameHeader,
1670                            agFrameHandle
1671                            );
1672       break;
1673     case SMP_REPORT_PHY_SATA:
1674       TI_DBG3(("itdssSMPCompleted: report phy sata\n"));
1675       if (agIOInfoLen != sizeof(smpRespReportPhySata_t) + 4 &&
1676           tdSMPFrameHeader->smpFunctionResult == SMP_FUNCTION_ACCEPTED)
1677       {
1678         TI_DBG1(("itdssSMPCompleted: mismatch len agIOInfoLen 0x%x 0x%x\n", agIOInfoLen, (unsigned int)sizeof(smpRespReportPhySata_t) + 4));
1679         tdsaSATADiscoverDone(tiRoot, onePortContext, tiError);
1680         ostiFreeMemory(
1681                        tiRoot,
1682                        tdSMPRequestBody->osMemHandle,
1683                        sizeof(tdssSMPRequestBody_t)
1684                       );
1685 #ifndef DIRECT_SMP
1686         ostiFreeMemory(
1687                        tiRoot,
1688                        tdSMPRequestBody->IndirectSMPReqosMemHandle,
1689                        tdSMPRequestBody->IndirectSMPReqLen
1690                       );
1691         ostiFreeMemory(
1692                        tiRoot,
1693                        tdSMPRequestBody->IndirectSMPResposMemHandle,
1694                        tdSMPRequestBody->IndirectSMPRespLen
1695                       );
1696 #endif
1697         return;
1698       }
1699       tdsaReportPhySataRcvd(
1700                             tiRoot,
1701                             agRoot,
1702                             agIORequest,
1703                             oneDeviceData,
1704                             tdSMPFrameHeader,
1705                             agFrameHandle
1706                             );
1707       break;
1708     case SMP_CONFIGURE_ROUTING_INFORMATION:
1709       TI_DBG1(("itdssSMPCompleted: configure routing information\n"));
1710       if (agIOInfoLen != 4 &&
1711           tdSMPFrameHeader->smpFunctionResult == SMP_FUNCTION_ACCEPTED)
1712       {
1713         TI_DBG1(("itdssSMPCompleted: mismatch len agIOInfoLen 0x%x 0x%x\n", agIOInfoLen, 4));
1714         tdsaSASDiscoverDone(tiRoot, onePortContext, tiError);
1715         ostiFreeMemory(
1716                        tiRoot,
1717                        tdSMPRequestBody->osMemHandle,
1718                        sizeof(tdssSMPRequestBody_t)
1719                       );
1720 #ifndef DIRECT_SMP
1721         ostiFreeMemory(
1722                        tiRoot,
1723                        tdSMPRequestBody->IndirectSMPReqosMemHandle,
1724                        tdSMPRequestBody->IndirectSMPReqLen
1725                       );
1726         ostiFreeMemory(
1727                        tiRoot,
1728                        tdSMPRequestBody->IndirectSMPResposMemHandle,
1729                        tdSMPRequestBody->IndirectSMPRespLen
1730                       );
1731 #endif
1732         return;
1733       }
1734       tdsaConfigRoutingInfoRespRcvd(
1735                                     tiRoot,
1736                                     agRoot,
1737                                     agIORequest,
1738                                     oneDeviceData,
1739                                     tdSMPFrameHeader,
1740                                     agFrameHandle
1741                                     );
1742 
1743       break;
1744     case SMP_PHY_CONTROL:
1745       TI_DBG3(("itdssSMPCompleted: phy control\n"));
1746       if (agIOInfoLen != 4 &&
1747           tdSMPFrameHeader->smpFunctionResult == SMP_FUNCTION_ACCEPTED) /*zero length is expected */
1748       {
1749         TI_DBG1(("itdssSMPCompleted: mismatch len agIOInfoLen 0x%x 0x%x\n", agIOInfoLen, 4));
1750         tdsaSASDiscoverDone(tiRoot, onePortContext, tiError);
1751         ostiFreeMemory(
1752                        tiRoot,
1753                        tdSMPRequestBody->osMemHandle,
1754                        sizeof(tdssSMPRequestBody_t)
1755                       );
1756 #ifndef DIRECT_SMP
1757         ostiFreeMemory(
1758                        tiRoot,
1759                        tdSMPRequestBody->IndirectSMPReqosMemHandle,
1760                        tdSMPRequestBody->IndirectSMPReqLen
1761                       );
1762         ostiFreeMemory(
1763                        tiRoot,
1764                        tdSMPRequestBody->IndirectSMPResposMemHandle,
1765                        tdSMPRequestBody->IndirectSMPRespLen
1766                       );
1767 #endif
1768         return;
1769       }
1770       tdsaPhyControlRespRcvd(
1771                              tiRoot,
1772                              agRoot,
1773                              agIORequest,
1774                              oneDeviceData,
1775                              tdSMPFrameHeader,
1776                              agFrameHandle,
1777                              CurrentTaskTag
1778                              );
1779 
1780       break;
1781 #ifdef REMOVED
1782 //temp for testing
1783      case SMP_REPORT_MANUFACTURE_INFORMATION:
1784       TI_DBG1(("itdssSMPCompleted: REPORT_MANUFACTURE_INFORMATION\n"));
1785       if (agIOInfoLen != sizeof(smpRespReportManufactureInfo_t) + 4 &&
1786           tdSMPFrameHeader->smpFunctionResult == SMP_FUNCTION_ACCEPTED) /*zero length is expected */
1787       {
1788         TI_DBG1(("itdssSMPCompleted: mismatch len agIOInfoLen 0x%x 0x%x\n", agIOInfoLen, 4));
1789         tdsaSASDiscoverDone(tiRoot, onePortContext, tiError);
1790         ostiFreeMemory(
1791                        tiRoot,
1792                        tdSMPRequestBody->osMemHandle,
1793                        sizeof(tdssSMPRequestBody_t)
1794                       );
1795 #ifndef DIRECT_SMP
1796         ostiFreeMemory(
1797                        tiRoot,
1798                        tdSMPRequestBody->IndirectSMPReqosMemHandle,
1799                        tdSMPRequestBody->IndirectSMPReqLen
1800                       );
1801         ostiFreeMemory(
1802                        tiRoot,
1803                        tdSMPRequestBody->IndirectSMPResposMemHandle,
1804                        tdSMPRequestBody->IndirectSMPRespLen
1805                       );
1806 #endif
1807         return;
1808       }
1809       tdsaReportManInfoRespRcvd(
1810                                 tiRoot,
1811                                 agRoot,
1812                                 oneDeviceData,
1813                                 tdSMPFrameHeader,
1814                                 agFrameHandle
1815                                 );
1816 
1817        break;
1818 //end temp for testing
1819 #endif
1820     case SMP_REPORT_ROUTING_INFORMATION:
1821     case SMP_REPORT_PHY_ERROR_LOG:
1822     case SMP_PHY_TEST_FUNCTION:
1823     case SMP_REPORT_MANUFACTURE_INFORMATION:
1824     case SMP_READ_GPIO_REGISTER:
1825     case SMP_WRITE_GPIO_REGISTER:
1826     default:
1827       TI_DBG1(("itdssSMPCompleted: wrong SMP function 0x%x\n", tdSMPFrameHeader->smpFunction));
1828       TI_DBG1(("itdssSMPCompleted: smpFrameType 0x%x\n", tdSMPFrameHeader->smpFrameType));
1829       TI_DBG1(("itdssSMPCompleted: smpFunctionResult 0x%x\n", tdSMPFrameHeader->smpFunctionResult));
1830       TI_DBG1(("itdssSMPCompleted: smpReserved 0x%x\n", tdSMPFrameHeader->smpReserved));
1831       tdhexdump("itdssSMPCompleted: SMP payload", (bit8 *)agFrameHandle, agIOInfoLen);
1832       break;
1833     }
1834   }
1835   else if (agIOStatus == OSSA_IO_ABORTED || agIOStatus == OSSA_IO_INVALID_LENGTH)
1836   {
1837     /* no retry this case */
1838     TI_DBG1(("itdssSMPCompleted: OSSA_IO_ABORTED\n"));
1839   }
1840   else if (agIOStatus == OSSA_IO_ERROR_INTERNAL_SMP_RESOURCE)
1841   {
1842     TI_DBG1(("itdssSMPCompleted: OSSA_IO_ERROR_INTERNAL_SMP_RESOURCE\n"));
1843     saFrameReadBlock(agRoot, agFrameHandle, 0, smpHeader, 4);
1844     tdSMPFrameHeader = (tdssSMPFrameHeader_t *)smpHeader;
1845 
1846     status = saSMPStart(
1847                agRoot,
1848                agIORequest,
1849                tdSMPRequestBody->queueNumber, //tdsaAllShared->SMPQNum, //tdsaRotateQnumber(tiRoot, oneDeviceData),
1850                agDevHandle,
1851                AGSA_SMP_INIT_REQ,
1852                agSASRequestBody,
1853                &ossaSMPCompleted
1854                );
1855 
1856     if (status == AGSA_RC_SUCCESS)
1857     {
1858       /* increment the number of pending SMP */
1859       onePortContext->discovery.pendingSMP++;
1860       if (SMPRequestFunction == SMP_REPORT_GENERAL || SMPRequestFunction == SMP_DISCOVER ||
1861           SMPRequestFunction == SMP_REPORT_PHY_SATA ||
1862           SMPRequestFunction == SMP_CONFIGURE_ROUTING_INFORMATION )
1863       {
1864         /* start discovery-related SMP timer */
1865         tdsaDiscoverySMPTimer(tiRoot, onePortContext, (bit32)(tdSMPFrameHeader->smpFunction), tdSMPRequestBody);
1866       }
1867       return;
1868     }
1869     else if (status == AGSA_RC_BUSY)
1870     {
1871       if (tdSMPFrameHeader->smpFunction == SMP_REPORT_GENERAL ||
1872           tdSMPFrameHeader->smpFunction == SMP_DISCOVER ||
1873           tdSMPFrameHeader->smpFunction == SMP_REPORT_PHY_SATA ||
1874           tdSMPFrameHeader->smpFunction == SMP_CONFIGURE_ROUTING_INFORMATION )
1875       {
1876         tdsaSMPBusyTimer(tiRoot, onePortContext, oneDeviceData, tdSMPRequestBody);
1877       }
1878       else if (tdSMPFrameHeader->smpFunction == SMP_PHY_CONTROL)
1879       {
1880         /* For taskmanagement SMP, let's fail task management failure */
1881         tdsaPhyControlFailureRespRcvd(
1882                                       tiRoot,
1883                                       agRoot,
1884                                       oneDeviceData,
1885                                       tdSMPFrameHeader,
1886                                       agFrameHandle,
1887                                       CurrentTaskTag
1888                                       );
1889       }
1890       else
1891       {
1892       }
1893     }
1894     else /* AGSA_RC_FAILURE */
1895     {
1896       if (tdSMPFrameHeader->smpFunction == SMP_REPORT_GENERAL ||
1897           tdSMPFrameHeader->smpFunction == SMP_DISCOVER ||
1898           tdSMPFrameHeader->smpFunction == SMP_REPORT_PHY_SATA ||
1899           tdSMPFrameHeader->smpFunction == SMP_CONFIGURE_ROUTING_INFORMATION )
1900       {
1901         tdsaSASDiscoverDone(tiRoot, onePortContext, tiError);
1902       }
1903       else if (tdSMPFrameHeader->smpFunction == SMP_PHY_CONTROL)
1904       {
1905         /* task management failure */
1906         tdsaPhyControlFailureRespRcvd(
1907                                       tiRoot,
1908                                       agRoot,
1909                                       oneDeviceData,
1910                                       tdSMPFrameHeader,
1911                                       agFrameHandle,
1912                                       CurrentTaskTag
1913                                       );
1914       }
1915       else
1916       {
1917       }
1918     }
1919   }
1920   else
1921   {
1922     if (tdSMPRequestBody->retries < SMP_RETRIES) /* 5 */
1923     {
1924       /* retry the SMP again */
1925       TI_DBG1(("itdssSMPCompleted: failed! but retries %d agIOStatus 0x%x %d agIOInfoLen %d\n",
1926                tdSMPRequestBody->retries, agIOStatus, agIOStatus, agIOInfoLen));
1927       if (agIOStatus == OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS ||
1928           agIOStatus == OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED ||
1929           agIOStatus == OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO ||
1930           agIOStatus == OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST ||
1931           agIOStatus == OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE ||
1932           agIOStatus == OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED ||
1933           agIOStatus == OSSA_IO_DS_NON_OPERATIONAL
1934          )
1935       {
1936         saSetDeviceState(agRoot, agNULL, tdSMPRequestBody->queueNumber, agDevHandle, SA_DS_OPERATIONAL);
1937       }
1938       saSMPStart(
1939                  agRoot,
1940                  agIORequest,
1941                  tdSMPRequestBody->queueNumber, //tdsaAllShared->SMPQNum, //tdsaRotateQnumber(tiRoot, oneDeviceData),
1942                  agDevHandle,
1943                  AGSA_SMP_INIT_REQ,
1944                  agSASRequestBody,
1945                  &ossaSMPCompleted
1946                  );
1947       /* increment the number of pending SMP */
1948       onePortContext->discovery.pendingSMP++;
1949       tdSMPRequestBody->retries++;
1950       return;
1951     }
1952     else
1953     {
1954       tdSMPFrameHeader = (tdssSMPFrameHeader_t *)agSMPFrame->outFrameBuf;
1955       tdSMPPayload = (bit8 *)agSMPFrame->outFrameBuf + 4;
1956       TI_DBG1(("itdssSMPCompleted: failed! no more retry! agIOStatus 0x%x %d\n", agIOStatus, agIOStatus));
1957       if (agIOStatus == OSSA_IO_DS_NON_OPERATIONAL)
1958       {
1959         TI_DBG1(("itdssSMPCompleted: failed! agIOStatus is OSSA_IO_DS_NON_OPERATIONAL\n"));
1960       }
1961 
1962       if (agIOStatus == OSSA_IO_DS_IN_RECOVERY)
1963       {
1964         TI_DBG1(("itdssSMPCompleted: failed! agIOStatus is OSSA_IO_DS_IN_RECOVERY\n"));
1965       }
1966 
1967       if (tdSMPFrameHeader->smpFunction == SMP_REPORT_GENERAL ||
1968           tdSMPFrameHeader->smpFunction == SMP_DISCOVER ||
1969           tdSMPFrameHeader->smpFunction == SMP_REPORT_PHY_SATA ||
1970           tdSMPFrameHeader->smpFunction == SMP_CONFIGURE_ROUTING_INFORMATION
1971          )
1972       {
1973         /* discovery failure */
1974         TI_DBG1(("itdssSMPCompleted: SMP function 0x%x\n", tdSMPFrameHeader->smpFunction));
1975         TI_DBG1(("itdssSMPCompleted: discover done with error\n"));
1976         tdsaSASDiscoverDone(tiRoot, onePortContext, tiError);
1977       }
1978       else if (tdSMPFrameHeader->smpFunction == SMP_PHY_CONTROL)
1979       {
1980         TI_DBG1(("itdssSMPCompleted: SMP_PHY_CONTROL\n"));
1981         smpPhyControlReq = (smpReqPhyControl_t *)tdSMPPayload;
1982         if (smpPhyControlReq->phyOperation == SMP_PHY_CONTROL_CLEAR_AFFILIATION)
1983         {
1984           TI_DBG1(("itdssSMPCompleted: discover done with error\n"));
1985           tdsaSASDiscoverDone(tiRoot, onePortContext, tiError);
1986         }
1987         else if (smpPhyControlReq->phyOperation == SMP_PHY_CONTROL_HARD_RESET ||
1988                  smpPhyControlReq->phyOperation == SMP_PHY_CONTROL_LINK_RESET )
1989         {
1990           TI_DBG1(("itdssSMPCompleted: device reset failed\n"));
1991           if (CurrentTaskTag != agNULL )
1992           {
1993             TI_DBG1(("itdssSMPCompleted: callback to OS layer with failure\n"));
1994             ostiInitiatorEvent( tiRoot,
1995                                 NULL,
1996                                 NULL,
1997                                 tiIntrEventTypeTaskManagement,
1998                                 tiTMFailed,
1999                                 CurrentTaskTag );
2000           }
2001           else
2002           {
2003             /* hard reset was not done with this device */
2004             oneDeviceData->ResetCnt = 0;
2005           }
2006         }
2007         else
2008         {
2009           TI_DBG1(("itdssSMPCompleted: unknown phy operation 0x%x\n", smpPhyControlReq->phyOperation));
2010         }
2011       } /* SMP_PHY_CONTROL */
2012       else
2013       {
2014         TI_DBG1(("itdssSMPCompleted: SMP function 0x%x\n", tdSMPFrameHeader->smpFunction));
2015       }
2016     } /* else */
2017   } /* outer else */
2018 
2019   ostiFreeMemory(
2020                  tiRoot,
2021                  tdSMPRequestBody->osMemHandle,
2022                  sizeof(tdssSMPRequestBody_t)
2023                  );
2024 #ifndef DIRECT_SMP
2025   ostiFreeMemory(
2026                  tiRoot,
2027                  tdSMPRequestBody->IndirectSMPReqosMemHandle,
2028                  tdSMPRequestBody->IndirectSMPReqLen
2029                  );
2030   ostiFreeMemory(
2031                  tiRoot,
2032                  tdSMPRequestBody->IndirectSMPResposMemHandle,
2033                  tdSMPRequestBody->IndirectSMPRespLen
2034                  );
2035 #endif
2036 
2037 
2038   return;
2039 }
2040 
2041 #else
2042 
2043 osGLOBAL void
2044 itdssSMPCompleted (
2045                    agsaRoot_t            *agRoot,
2046                    agsaIORequest_t       *agIORequest,
2047                    bit32                 agIOStatus,
2048                    bit32                 agIOInfoLen,
2049                    agsaFrameHandle_t     agFrameHandle
2050                    )
2051 {
2052   /* pass the payload to OS layer */
2053   TI_DBG3(("itdssSMPCompleted: start\n"));
2054 }
2055 #endif
2056 
2057 
2058 /*****************************************************************************
2059 *! \brief itdIoSuccessHandler
2060 *
2061 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2062 *            layer with agIOStatus = OSSA_IO_SUCCESS
2063 *
2064 *  \param  agRoot:            pointer to port instance
2065 *  \param  agIORequest:       pointer to I/O request
2066 *  \param  agIOStatus:        I/O status given by LL layer
2067 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2068 *  \param  agParam            A Handle used to refer to the response frame or handle
2069 *                             of abort request
2070 *  \param  agOtherInfo        Residual count
2071 *  \return: None
2072 *
2073 *
2074 *****************************************************************************/
2075 osGLOBAL void
2076 itdssIOSuccessHandler(
2077                       agsaRoot_t           *agRoot,
2078                       agsaIORequest_t      *agIORequest,
2079                       bit32                agIOStatus,
2080                       bit32                agIOInfoLen,
2081                       void                 *agParam,
2082                       bit32                agOtherInfo
2083                       )
2084 {
2085   tdsaRootOsData_t          *osData = (tdsaRootOsData_t *)agRoot->osData;
2086   tiRoot_t                  *tiRoot = (tiRoot_t *)osData->tiRoot;
2087   itdsaIni_t                *Initiator = (itdsaIni_t *)osData->itdsaIni;
2088   tdIORequestBody_t         *tdIORequestBody;
2089   agsaSSPResponseInfoUnit_t agSSPRespIU;
2090   tiSenseData_t             senseData;
2091   bit8                      senseDataPayload[256];
2092   bit8                      respData[128];
2093   bit32                     scsi_status;
2094   bit32                     senseLen;
2095   bit32                     respLen;
2096   bit32                     data_status;
2097   bit32                     i;
2098   tiDeviceHandle_t          *tiDeviceHandle = agNULL;
2099   tdsaDeviceData_t          *oneDeviceData = agNULL;
2100 
2101   TI_DBG2(("itdssIOSuccessHandler: start\n"));
2102   TI_DBG2(("itdssIOSuccessHandler: agIOInfoLen %d\n", agIOInfoLen));
2103 
2104   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2105 
2106   tdIORequestBody->ioCompleted = agTRUE;
2107   tdIORequestBody->ioStarted = agFALSE;
2108 
2109   /*
2110     agIOInfoLen must be >= sizeof(agsaSSPResponseInfoUnit_t), which is minimum
2111     date length
2112   */
2113   if (agIOInfoLen < sizeof(agsaSSPResponseInfoUnit_t))
2114   {
2115     TI_DBG1(("itdssIOSuccessHandler: First agIOInfoLen does not match!!!\n"));
2116     TI_DBG1(("itdssIOSuccessHandler: First agIOInfoLen 0x%x IU 0x%x\n", agIOInfoLen, (unsigned int)sizeof(agsaSSPResponseInfoUnit_t)));
2117     ostiInitiatorIOCompleted(
2118                              tiRoot,
2119                              tdIORequestBody->tiIORequest, /* tiIORequest */
2120                              tiIOFailed,
2121                              tiDetailOtherError,
2122                              agNULL,
2123                              agTRUE /* intContext; is not being used */
2124                              );
2125     return;
2126   }
2127   /* reads agsaSSPResponseInfoUnit_t */
2128   saFrameReadBlock(agRoot, agParam, 0, &agSSPRespIU, sizeof(agsaSSPResponseInfoUnit_t));
2129 
2130   data_status = SA_SSPRESP_GET_DATAPRES(&agSSPRespIU);
2131   scsi_status = agSSPRespIU.status;
2132   /* endianess is invovled here */
2133   senseLen = SA_SSPRESP_GET_SENSEDATALEN(&agSSPRespIU);
2134   respLen = SA_SSPRESP_GET_RESPONSEDATALEN(&agSSPRespIU);
2135 
2136   TI_DBG2(("itdssIOSuccessHandler: dataPres=%x\n", data_status));
2137   TI_DBG2(("itdssIOSuccessHandler: scsi status=0x%x, senselen=0x%x resplen 0x%x\n", scsi_status, senseLen, respLen));
2138 
2139   /*
2140     sanity check: do not go beyond of agIOInfoLen. if happens, return error
2141     agIOInfoLen >= sizeof(agsaSSPResponseInfoUnit_t) + senseLen + respLen -> OK
2142     because frame must be divisible by 4, so there can be extra padding
2143     agIOInfoLen < sizeof(agsaSSPResponseInfoUnit_t) + senseLen + respLen -> NOT OK
2144   */
2145   if (agIOInfoLen < sizeof(agsaSSPResponseInfoUnit_t) + senseLen + respLen)
2146   {
2147     TI_DBG1(("itdssIOSuccessHandler: Second agIOInfoLen does not match!!!\n"));
2148     TI_DBG1(("itdssIOSuccessHandler: Second agIOInfoLen 0x%x IU 0x%x senselen 0x%x resplen 0x%x\n", agIOInfoLen, (unsigned int)sizeof(agsaSSPResponseInfoUnit_t), senseLen, respLen));
2149 
2150     ostiInitiatorIOCompleted(
2151                              tiRoot,
2152                              tdIORequestBody->tiIORequest, /* tiIORequest */
2153                              tiIOFailed,
2154                              tiDetailOtherError,
2155                              agNULL,
2156                              agTRUE /* intContext; is not being used */
2157                              );
2158     return;
2159   }
2160 
2161   /* reads response data */
2162   saFrameReadBlock(agRoot, agParam,
2163                    sizeof(agsaSSPResponseInfoUnit_t),
2164                    respData, respLen);
2165   /* reads sense data */
2166   saFrameReadBlock(agRoot, agParam,
2167                    sizeof(agsaSSPResponseInfoUnit_t)
2168                    + respLen,
2169                    senseDataPayload, senseLen);
2170 
2171   if (data_status == 0)
2172   {
2173     /* NO_DATA */
2174     TI_DBG1(("itdssIOSuccessHandler: no data scsi_status 0x%x\n",scsi_status));
2175 
2176     ostiInitiatorIOCompleted(
2177                              tiRoot,
2178                              tdIORequestBody->tiIORequest, /* tiIORequest */
2179                              tiIOSuccess,
2180                              scsi_status,
2181                              agNULL,
2182                              agTRUE /* intContext; is not being used */
2183                              );
2184 
2185     return;
2186   }
2187 
2188   if (data_status == 1)
2189   {
2190     /* RESPONSE_DATA */
2191     TI_DBG1(("itdssIOSuccessHandler: response data \n"));
2192 
2193     ostiInitiatorIOCompleted(
2194                              tiRoot,
2195                              tdIORequestBody->tiIORequest, /* tiIORequest */
2196                              tiIOSuccess,
2197                              0,
2198                              agNULL,
2199                              agTRUE /* intContext; is not being used */
2200                              );
2201     return;
2202   }
2203 
2204   if (data_status == 2)
2205   {
2206     /* SENSE_DATA */
2207     TI_DBG2(("itdssIOSuccessHandler: sense data \n"));
2208 
2209     senseData.senseData = &senseDataPayload;
2210     senseData.senseLen = MIN(256, senseLen);
2211     /* debugging */
2212     tdhexdump("ResponseIU I", (bit8 *)&agSSPRespIU, sizeof(agsaSSPResponseInfoUnit_t));
2213 
2214     tiDeviceHandle = tdIORequestBody->tiDevHandle;
2215     oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
2216     TI_DBG1(("sense data Sense Key 0x%2X ASC(Code) 0x%2X ASCQ(Qualifier) 0x%2X, did 0x%x\n",*(senseDataPayload+ 2),*(senseDataPayload + 12),*(senseDataPayload + 13),
2217              oneDeviceData->id));
2218     tdhexdump("sense data I", (bit8 *)senseDataPayload, senseLen);
2219 //    tdhexdump("sense data II", (bit8 *)senseData.senseData, senseData.senseLen);
2220 
2221     if (senseDataPayload[2] == SCSI_SENSE_KEY_RECOVERED_ERROR)
2222     {
2223       Initiator->SenseKeyCounter.SoftError ++;
2224     }
2225     else if (senseDataPayload[2] == SCSI_SENSE_KEY_NOT_READY)
2226     {
2227       Initiator->SenseKeyCounter.MediumNotReady++;
2228     }
2229     else if (senseDataPayload[2] == SCSI_SENSE_KEY_MEDIUM_ERROR)
2230     {
2231       Initiator->SenseKeyCounter.MediumError++;
2232     }
2233     else if (senseDataPayload[2] == SCSI_SENSE_KEY_HARDWARE_ERROR)
2234     {
2235       Initiator->SenseKeyCounter.HardwareError++;
2236     }
2237     else if (senseDataPayload[2] == SCSI_SENSE_KEY_ILLEGAL_REQUEST)
2238     {
2239       Initiator->SenseKeyCounter.IllegalRequest++;
2240     }
2241     else if (senseDataPayload[2] == SCSI_SENSE_KEY_UNIT_ATTENTION)
2242     {
2243       Initiator->SenseKeyCounter.UnitAttention++;
2244     }
2245     else if (senseDataPayload[2] == SCSI_SENSE_KEY_ABORTED_COMMAND)
2246     {
2247       Initiator->SenseKeyCounter.AbortCommand++;
2248     }
2249     else
2250     {
2251       Initiator->SenseKeyCounter.OtherKeyType++;
2252     }
2253 
2254     /* when ASQ and ASCQ 0x04 0x11, does saLocalPhyControl for notify spinup */
2255     if ((senseDataPayload[12] == 0x04 && senseDataPayload[13] == 0x11))
2256     {
2257       TI_DBG2(("itdssIOSuccessHandler: sending notfify spinup\n"));
2258       tiDeviceHandle = tdIORequestBody->tiDevHandle;
2259       oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
2260       if (oneDeviceData->directlyAttached == agTRUE)
2261       {
2262         for (i=0;i<TD_MAX_NUM_NOTIFY_SPINUP;i++)
2263         {
2264           saLocalPhyControl(agRoot, agNULL, 0, oneDeviceData->phyID, AGSA_PHY_NOTIFY_ENABLE_SPINUP, agNULL);
2265         }
2266       }
2267     }
2268     ostiInitiatorIOCompleted(
2269                              tiRoot,
2270                              /* tiIORequest */
2271                              tdIORequestBody->tiIORequest,
2272                              tiIOSuccess,
2273                              scsi_status,
2274                              &senseData,
2275                              agTRUE /* intContext; is not being used */
2276                              );
2277     return;
2278   }
2279   if (data_status == 3)
2280   {
2281     /* RESERVED */
2282     TI_DBG1(("itdssIOSuccessHandler: reserved wrong!!!\n"));
2283     ostiInitiatorIOCompleted(
2284                              tiRoot,
2285                              tdIORequestBody->tiIORequest, /* tiIORequest */
2286                              tiIOFailed,
2287                              scsi_status,
2288                              agNULL,
2289                              agTRUE /* intContext; is not being used */
2290                              );
2291     return;
2292   }
2293 
2294 }
2295 
2296 /*****************************************************************************
2297 *! \brief itdssIOAbortedHandler
2298 *
2299 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2300 *            layer with agIOStatus = OSSA_IO_ABORTED
2301 *
2302 *  \param  agRoot:            pointer to port instance
2303 *  \param  agIORequest:       pointer to I/O request
2304 *  \param  agIOStatus:        I/O status given by LL layer
2305 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2306 *  \param  agParam            A Handle used to refer to the response frame or handle
2307 *                             of abort request
2308 *  \param  agOtherInfo        Residual count
2309 *  \return: None
2310 *
2311 *
2312 *****************************************************************************/
2313 /* see itdosIOCompleted() and itdinit.c and  itdIoAbortedHandler in itdio.c*/
2314 osGLOBAL void
2315 itdssIOAbortedHandler (
2316                        agsaRoot_t              *agRoot,
2317                        agsaIORequest_t         *agIORequest,
2318                        bit32                   agIOStatus,
2319                        bit32                   agIOInfoLen,
2320                        void                    *agParam,
2321                        bit32                   agOtherInfo
2322                        )
2323 {
2324   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
2325   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
2326   bit32                  intContext = osData->IntContext;
2327   tdIORequestBody_t      *tdIORequestBody;
2328   tiDeviceHandle_t       *tiDeviceHandle = agNULL;
2329   tdsaDeviceData_t       *oneDeviceData = agNULL;
2330 
2331   TI_DBG2(("itdssIOAbortedHandler: start\n"));
2332   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2333 
2334   if (agIOStatus != OSSA_IO_ABORTED)
2335   {
2336     TI_DBG1(("itdssIOAbortedHandler: incorrect agIOStatus 0x%x\n", agIOStatus));
2337   }
2338 
2339   if (tdIORequestBody == agNULL)
2340   {
2341     TI_DBG1(("itdssIOAbortedHandler: start\n"));
2342     return;
2343   }
2344 
2345   if (tdIORequestBody != agNULL)
2346   {
2347     tiDeviceHandle = tdIORequestBody->tiDevHandle;
2348   }
2349   if (tiDeviceHandle != agNULL)
2350   {
2351     oneDeviceData  = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
2352   }
2353   if (oneDeviceData != agNULL)
2354   {
2355     TI_DBG2(("itdssIOAbortedHandler: did %d \n", oneDeviceData->id));
2356   }
2357   else
2358   {
2359     TI_DBG1(("itdssIOAbortedHandler: oneDeviceData is NULL\n"));
2360   }
2361 
2362 
2363   ostiInitiatorIOCompleted (
2364                             tiRoot,
2365                             tdIORequestBody->tiIORequest,
2366                             tiIOFailed,
2367                             tiDetailAborted,
2368                             agNULL,
2369                             intContext
2370                             );
2371 
2372   return;
2373 }
2374 
2375 #ifdef REMOVED
2376 /*****************************************************************************
2377 *! \brief itdssIOOverFlowHandler
2378 *
2379 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2380 *            layer with agIOStatus = OSSA_IO_OVERFLOW
2381 *
2382 *  \param  agRoot:            pointer to port instance
2383 *  \param  agIORequest:       pointer to I/O request
2384 *  \param  agIOStatus:        I/O status given by LL layer
2385 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2386 *  \param  agParam            A Handle used to refer to the response frame or handle
2387 *                             of abort request
2388 *  \return: None
2389 *
2390 *
2391 *****************************************************************************/
2392 osGLOBAL void
2393 itdssIOOverFlowHandler(
2394                        agsaRoot_t              *agRoot,
2395                        agsaIORequest_t         *agIORequest,
2396                        bit32                   agIOStatus,
2397                        bit32                   agIOInfoLen,
2398                        void                    *agParam
2399                        )
2400 {
2401   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
2402   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
2403   bit32                  intContext = osData->IntContext;
2404   tdIORequestBody_t      *tdIORequestBody;
2405 
2406   TI_DBG2(("itdssIOOverFlowHandler: start\n"));
2407   TI_DBG2(("itdssIOOverFlowHandler: not transferred byte 0x%x\n", agIOInfoLen));
2408 
2409   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2410 
2411   ostiInitiatorIOCompleted (
2412                             tiRoot,
2413                             tdIORequestBody->tiIORequest,
2414                             tiIOOverRun,
2415                             agIOInfoLen,
2416                             agNULL,
2417                             intContext
2418                             );
2419 
2420   return;
2421 }
2422 #endif
2423 
2424 
2425 /*****************************************************************************
2426 *! \brief itdssIOUnderFlowHandler
2427 *
2428 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2429 *            layer with agIOStatus = OSSA_IO_UNDERFLOW
2430 *
2431 *  \param  agRoot:            pointer to port instance
2432 *  \param  agIORequest:       pointer to I/O request
2433 *  \param  agIOStatus:        I/O status given by LL layer
2434 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2435 *  \param  agParam            A Handle used to refer to the response frame or handle
2436 *                             of abort request
2437 *  \param  agOtherInfo        Residual count
2438 *  \return: None
2439 *
2440 *
2441 *****************************************************************************/
2442 osGLOBAL void
2443 itdssIOUnderFlowHandler(
2444                         agsaRoot_t              *agRoot,
2445                         agsaIORequest_t         *agIORequest,
2446                         bit32                   agIOStatus,
2447                         bit32                   agIOInfoLen,
2448                         void                    *agParam,
2449                         bit32                   agOtherInfo
2450                         )
2451 {
2452   tdsaRootOsData_t          *osData = (tdsaRootOsData_t *)agRoot->osData;
2453   tiRoot_t                  *tiRoot = (tiRoot_t *)osData->tiRoot;
2454   bit32                     intContext = osData->IntContext;
2455   tdIORequestBody_t         *tdIORequestBody;
2456 
2457   TI_DBG6(("itdssIOUnderFlowHandler: start\n"));
2458   TI_DBG6(("itdssIOUnderFlowHandler: agIOInfoLen 0x%x\n", agIOInfoLen));
2459 
2460   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2461 
2462   ostiInitiatorIOCompleted (
2463                             tiRoot,
2464                             tdIORequestBody->tiIORequest,
2465                             tiIOUnderRun,
2466                             agIOInfoLen,
2467                             agNULL,
2468                             intContext
2469                             );
2470 
2471   return;
2472 }
2473 
2474 /*****************************************************************************
2475 *! \brief itdssIOFailedHandler
2476 *
2477 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2478 *            layer with agIOStatus = OSSA_IO_FAILED
2479 *
2480 *  \param  agRoot:            pointer to port instance
2481 *  \param  agIORequest:       pointer to I/O request
2482 *  \param  agIOStatus:        I/O status given by LL layer
2483 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2484 *  \param  agParam            A Handle used to refer to the response frame or handle
2485 *                             of abort request
2486 *  \param  agOtherInfo        Residual count
2487 *  \return: None
2488 *
2489 *
2490 *****************************************************************************/
2491 osGLOBAL void
2492 itdssIOFailedHandler(
2493                      agsaRoot_t              *agRoot,
2494                      agsaIORequest_t         *agIORequest,
2495                      bit32                   agIOStatus,
2496                      bit32                   agIOInfoLen,
2497                      void                    *agParam,
2498                      bit32                   agOtherInfo
2499                      )
2500 {
2501   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
2502   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
2503   bit32                  intContext = osData->IntContext;
2504   tdIORequestBody_t      *tdIORequestBody;
2505 
2506   TI_DBG1(("itdssIOFailedHandler: start\n"));
2507 
2508   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2509 
2510   ostiInitiatorIOCompleted (
2511                             tiRoot,
2512                             tdIORequestBody->tiIORequest,
2513                             tiIOFailed,
2514                             tiDetailOtherError,
2515                             agNULL,
2516                             intContext
2517                             );
2518   return;
2519 }
2520 
2521 /*****************************************************************************
2522 *! \brief itdssIOAbortResetHandler
2523 *
2524 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2525 *            layer with agIOStatus = OSSA_IO_ABORT_RESET
2526 *
2527 *  \param  agRoot:            pointer to port instance
2528 *  \param  agIORequest:       pointer to I/O request
2529 *  \param  agIOStatus:        I/O status given by LL layer
2530 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2531 *  \param  agParam            A Handle used to refer to the response frame or handle
2532 *                             of abort request
2533 *  \param  agOtherInfo        Residual count
2534 *  \return: None
2535 *
2536 *
2537 *****************************************************************************/
2538 osGLOBAL void
2539 itdssIOAbortResetHandler(
2540                          agsaRoot_t              *agRoot,
2541                          agsaIORequest_t         *agIORequest,
2542                          bit32                   agIOStatus,
2543                          bit32                   agIOInfoLen,
2544                          void                    *agParam,
2545                          bit32                   agOtherInfo
2546                          )
2547 {
2548   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
2549   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
2550   bit32                  intContext = osData->IntContext;
2551   tdIORequestBody_t      *tdIORequestBody;
2552   TI_DBG2(("itdssIOAbortResetHandler: start\n"));
2553 
2554   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2555 
2556   ostiInitiatorIOCompleted (
2557                             tiRoot,
2558                             tdIORequestBody->tiIORequest,
2559                             tiIOFailed,
2560                             tiDetailAbortReset,
2561                             agNULL,
2562                             intContext
2563                             );
2564 
2565 
2566   return;
2567 }
2568 
2569 /*****************************************************************************
2570 *! \brief itdssIONotValidHandler
2571 *
2572 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2573 *            layer with agIOStatus = OSSA_IO_NOT_VALID
2574 *
2575 *  \param  agRoot:            pointer to port instance
2576 *  \param  agIORequest:       pointer to I/O request
2577 *  \param  agIOStatus:        I/O status given by LL layer
2578 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2579 *  \param  agParam            A Handle used to refer to the response frame or handle
2580 *                             of abort request
2581 *  \param  agOtherInfo        Residual count
2582 *  \return: None
2583 *
2584 *
2585 *****************************************************************************/
2586 osGLOBAL void
2587 itdssIONotValidHandler(
2588                        agsaRoot_t           *agRoot,
2589                        agsaIORequest_t      *agIORequest,
2590                        bit32                agIOStatus,
2591                        bit32                agIOInfoLen,
2592                        void                 *agParam,
2593                        bit32                agOtherInfo
2594                        )
2595 {
2596   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
2597   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
2598   bit32                  intContext = osData->IntContext;
2599   tdIORequestBody_t      *tdIORequestBody;
2600   TI_DBG2(("itdssIONotValidHandler: start\n"));
2601 
2602   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2603 
2604   ostiInitiatorIOCompleted (
2605                             tiRoot,
2606                             tdIORequestBody->tiIORequest,
2607                             tiIOFailed,
2608                             tiDetailNotValid,
2609                             agNULL,
2610                             intContext
2611                             );
2612   return;
2613 }
2614 
2615 /*****************************************************************************
2616 *! \brief itdssIONoDeviceHandler
2617 *
2618 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2619 *            layer with agIOStatus = OSSA_IO_NO_DEVICE
2620 *
2621 *  \param  agRoot:            pointer to port instance
2622 *  \param  agIORequest:       pointer to I/O request
2623 *  \param  agIOStatus:        I/O status given by LL layer
2624 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2625 *  \param  agParam            A Handle used to refer to the response frame or handle
2626 *                             of abort request
2627 *  \param  agOtherInfo        Residual count
2628 *  \return: None
2629 *
2630 *
2631 *****************************************************************************/
2632 osGLOBAL void
2633 itdssIONoDeviceHandler(
2634                        agsaRoot_t           *agRoot,
2635                        agsaIORequest_t      *agIORequest,
2636                        bit32                agIOStatus,
2637                        bit32                agIOInfoLen,
2638                        void                 *agParam,
2639                        bit32                agOtherInfo
2640                        )
2641 {
2642   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
2643   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
2644   bit32                  intContext = osData->IntContext;
2645   tdIORequestBody_t      *tdIORequestBody;
2646   TI_DBG2(("itdssIONoDeviceHandler: start\n"));
2647 
2648   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2649 
2650   ostiInitiatorIOCompleted (
2651                             tiRoot,
2652                             tdIORequestBody->tiIORequest,
2653                             tiIOFailed,
2654                             tiDetailNoLogin,
2655                             agNULL,
2656                             intContext
2657                             );
2658   return;
2659 }
2660 
2661 #ifdef REMOVED /* to do: removed from spec */
2662 /*****************************************************************************
2663 *! \brief itdssIllegalParameterHandler
2664 *
2665 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2666 *            layer with agIOStatus = OSSA_IO_ILLEGAL_PARAMETER
2667 *
2668 *  \param  agRoot:            pointer to port instance
2669 *  \param  agIORequest:       pointer to I/O request
2670 *  \param  agIOStatus:        I/O status given by LL layer
2671 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2672 *  \param  agParam            A Handle used to refer to the response frame or handle
2673 *                             of abort request
2674 *  \return: None
2675 *
2676 *
2677 *****************************************************************************/
2678 osGLOBAL void
2679 itdssIllegalParameterHandler(
2680                        agsaRoot_t           *agRoot,
2681                        agsaIORequest_t      *agIORequest,
2682                        bit32                agIOStatus,
2683                        bit32                agIOInfoLen,
2684                        void                 *agParam
2685                        )
2686 {
2687   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
2688   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
2689   bit32                  intContext = osData->IntContext;
2690   tdIORequestBody_t      *tdIORequestBody;
2691   TI_DBG2(("itdssIllegalParameterHandler: start\n"));
2692 
2693   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2694 
2695   ostiInitiatorIOCompleted (
2696                             tiRoot,
2697                             tdIORequestBody->tiIORequest,
2698                             tiIOFailed,
2699                             tiDetailOtherError,
2700                             agNULL,
2701                             intContext
2702                             );
2703 
2704   return;
2705 }
2706 #endif
2707 
2708 /*****************************************************************************
2709 *! \brief itdssLinkFailureHandler
2710 *
2711 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2712 *            layer with agIOStatus = OSSA_IO_LINK_FAILURE
2713 *
2714 *  \param  agRoot:            pointer to port instance
2715 *  \param  agIORequest:       pointer to I/O request
2716 *  \param  agIOStatus:        I/O status given by LL layer
2717 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2718 *  \param  agParam            A Handle used to refer to the response frame or handle
2719 *                             of abort request
2720 *  \param  agOtherInfo        Residual count
2721 *  \return: None
2722 *
2723 *
2724 *****************************************************************************/
2725 osGLOBAL void
2726 itdssLinkFailureHandler(
2727                        agsaRoot_t           *agRoot,
2728                        agsaIORequest_t      *agIORequest,
2729                        bit32                agIOStatus,
2730                        bit32                agIOInfoLen,
2731                        void                 *agParam,
2732                        bit32                agOtherInfo
2733                        )
2734 {
2735   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
2736   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
2737   bit32                  intContext = osData->IntContext;
2738   tdIORequestBody_t      *tdIORequestBody;
2739   TI_DBG1(("itdssLinkFailureHandler: start\n"));
2740 
2741   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2742 
2743   ostiInitiatorIOCompleted (
2744                             tiRoot,
2745                             tdIORequestBody->tiIORequest,
2746                             tiIOFailed,
2747                             tiDetailOtherError,
2748                             agNULL,
2749                             intContext
2750                             );
2751 
2752   return;
2753 }
2754 
2755 /*****************************************************************************
2756 *! \brief itdssProgErrorHandler
2757 *
2758 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2759 *            layer with agIOStatus = OSSA_IO_PROG_ERROR
2760 *
2761 *  \param  agRoot:            pointer to port instance
2762 *  \param  agIORequest:       pointer to I/O request
2763 *  \param  agIOStatus:        I/O status given by LL layer
2764 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2765 *  \param  agParam            A Handle used to refer to the response frame or handle
2766 *                             of abort request
2767 *  \param  agOtherInfo        Residual count
2768 *  \return: None
2769 *
2770 *
2771 *****************************************************************************/
2772 osGLOBAL void
2773 itdssProgErrorHandler(
2774                        agsaRoot_t           *agRoot,
2775                        agsaIORequest_t      *agIORequest,
2776                        bit32                agIOStatus,
2777                        bit32                agIOInfoLen,
2778                        void                 *agParam,
2779                        bit32                agOtherInfo
2780                        )
2781 {
2782   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
2783   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
2784   bit32                  intContext = osData->IntContext;
2785   tdIORequestBody_t      *tdIORequestBody;
2786   TI_DBG2(("itdssProgErrorHandler: start\n"));
2787 
2788   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2789 
2790   ostiInitiatorIOCompleted (
2791                             tiRoot,
2792                             tdIORequestBody->tiIORequest,
2793                             tiIOFailed,
2794                             tiDetailOtherError,
2795                             agNULL,
2796                             intContext
2797                             );
2798 
2799   return;
2800 }
2801 
2802 /*****************************************************************************
2803 *! \brief itdssXferErrorBreakHandler
2804 *
2805 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2806 *            layer with agIOStatus = OSSA_IO_XFER_ERROR_BREAK
2807 *
2808 *  \param  agRoot:            pointer to port instance
2809 *  \param  agIORequest:       pointer to I/O request
2810 *  \param  agIOStatus:        I/O status given by LL layer
2811 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2812 *  \param  agParam            A Handle used to refer to the response frame or handle
2813 *                             of abort request
2814 *  \param  agOtherInfo        Residual count
2815 *  \return: None
2816 *
2817 *
2818 *****************************************************************************/
2819 osGLOBAL void
2820 itdssXferErrorBreakHandler(
2821                        agsaRoot_t           *agRoot,
2822                        agsaIORequest_t      *agIORequest,
2823                        bit32                agIOStatus,
2824                        bit32                agIOInfoLen,
2825                        void                 *agParam,
2826                        bit32                agOtherInfo
2827                        )
2828 {
2829   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
2830   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
2831   bit32                  intContext = osData->IntContext;
2832   tdIORequestBody_t      *tdIORequestBody;
2833   TI_DBG1(("itdssXferErrorBreakHandler: start\n"));
2834 
2835   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2836 
2837   ostiInitiatorIOCompleted (
2838                             tiRoot,
2839                             tdIORequestBody->tiIORequest,
2840                             tiIOFailed,
2841                             tiDetailOtherError,
2842                             agNULL,
2843                             intContext
2844                             );
2845 
2846   return;
2847 }
2848 
2849 /*****************************************************************************
2850 *! \brief itdssXferErrorPhyNotReadyHandler
2851 *
2852 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2853 *            layer with agIOStatus = OSSA_IO_XFER_ERROR_PHY_NOT_READY
2854 *
2855 *  \param  agRoot:            pointer to port instance
2856 *  \param  agIORequest:       pointer to I/O request
2857 *  \param  agIOStatus:        I/O status given by LL layer
2858 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2859 *  \param  agParam            A Handle used to refer to the response frame or handle
2860 *                             of abort request
2861 *  \param  agOtherInfo        Residual count
2862 *  \return: None
2863 *
2864 *
2865 *****************************************************************************/
2866 osGLOBAL void
2867 itdssXferErrorPhyNotReadyHandler(
2868                        agsaRoot_t           *agRoot,
2869                        agsaIORequest_t      *agIORequest,
2870                        bit32                agIOStatus,
2871                        bit32                agIOInfoLen,
2872                        void                 *agParam,
2873                        bit32                agOtherInfo
2874                        )
2875 {
2876   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
2877   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
2878   bit32                  intContext = osData->IntContext;
2879   tdIORequestBody_t      *tdIORequestBody;
2880   TI_DBG2(("itdssXferErrorPhyNotReadyHandler: start\n"));
2881 
2882   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2883 
2884   ostiInitiatorIOCompleted (
2885                             tiRoot,
2886                             tdIORequestBody->tiIORequest,
2887                             tiIOFailed,
2888                             tiDetailOtherError,
2889                             agNULL,
2890                             intContext
2891                             );
2892 
2893   return;
2894 }
2895 
2896 /*****************************************************************************
2897 *! \brief itdssOpenCnxErrorProtocolNotSupprotedHandler
2898 *
2899 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2900 *            layer with agIOStatus = OSSA_IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED
2901 *
2902 *  \param  agRoot:            pointer to port instance
2903 *  \param  agIORequest:       pointer to I/O request
2904 *  \param  agIOStatus:        I/O status given by LL layer
2905 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2906 *  \param  agParam            A Handle used to refer to the response frame or handle
2907 *                             of abort request
2908 *  \param  agOtherInfo        Residual count
2909 *  \return: None
2910 *
2911 *
2912 *****************************************************************************/
2913 osGLOBAL void
2914 itdssOpenCnxErrorProtocolNotSupprotedHandler(
2915                        agsaRoot_t           *agRoot,
2916                        agsaIORequest_t      *agIORequest,
2917                        bit32                agIOStatus,
2918                        bit32                agIOInfoLen,
2919                        void                 *agParam,
2920                        bit32                agOtherInfo
2921                        )
2922 {
2923   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
2924   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
2925   bit32                  intContext = osData->IntContext;
2926   tdIORequestBody_t      *tdIORequestBody;
2927   TI_DBG2(("itdssOpenCnxErrorProtocolNotSupprotedHandler: start\n"));
2928 
2929   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2930 
2931   ostiInitiatorIOCompleted (
2932                             tiRoot,
2933                             tdIORequestBody->tiIORequest,
2934                             tiIOFailed,
2935                             tiDetailOtherError,
2936                             agNULL,
2937                             intContext
2938                             );
2939 
2940   return;
2941 }
2942 
2943 /*****************************************************************************
2944 *! \brief itdssOpenCnxErrorZoneViolationHandler
2945 *
2946 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2947 *            layer with agIOStatus = OSSA_IO_OPEN_CNX_ERROR_ZONE_VIOLATION
2948 *
2949 *  \param  agRoot:            pointer to port instance
2950 *  \param  agIORequest:       pointer to I/O request
2951 *  \param  agIOStatus:        I/O status given by LL layer
2952 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
2953 *  \param  agParam            A Handle used to refer to the response frame or handle
2954 *                             of abort request
2955 *  \param  agOtherInfo        Residual count
2956 *  \return: None
2957 *
2958 *
2959 *****************************************************************************/
2960 osGLOBAL void
2961 itdssOpenCnxErrorZoneViolationHandler(
2962                        agsaRoot_t           *agRoot,
2963                        agsaIORequest_t      *agIORequest,
2964                        bit32                agIOStatus,
2965                        bit32                agIOInfoLen,
2966                        void                 *agParam,
2967                        bit32                agOtherInfo
2968                        )
2969 {
2970   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
2971   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
2972   bit32                  intContext = osData->IntContext;
2973   tdIORequestBody_t      *tdIORequestBody;
2974   TI_DBG2(("itdssOpenCnxErrorZoneViolationHandler: start\n"));
2975 
2976   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
2977 
2978   ostiInitiatorIOCompleted (
2979                             tiRoot,
2980                             tdIORequestBody->tiIORequest,
2981                             tiIOFailed,
2982                             tiDetailOtherError,
2983                             agNULL,
2984                             intContext
2985                             );
2986 
2987   return;
2988 }
2989 
2990 /*****************************************************************************
2991 *! \brief itdssOpenCnxErrorBreakHandler
2992 *
2993 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
2994 *            layer with agIOStatus = OSSA_IO_OPEN_CNX_ERROR_BREAK
2995 *
2996 *  \param  agRoot:            pointer to port instance
2997 *  \param  agIORequest:       pointer to I/O request
2998 *  \param  agIOStatus:        I/O status given by LL layer
2999 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3000 *  \param  agParam            A Handle used to refer to the response frame or handle
3001 *                             of abort request
3002 *  \param  agOtherInfo        Residual count
3003 *  \return: None
3004 *
3005 *
3006 *****************************************************************************/
3007 osGLOBAL void
3008 itdssOpenCnxErrorBreakHandler(
3009                        agsaRoot_t           *agRoot,
3010                        agsaIORequest_t      *agIORequest,
3011                        bit32                agIOStatus,
3012                        bit32                agIOInfoLen,
3013                        void                 *agParam,
3014                        bit32                agOtherInfo
3015                        )
3016 {
3017   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3018   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3019   bit32                  intContext = osData->IntContext;
3020   tdIORequestBody_t      *tdIORequestBody;
3021   TI_DBG1(("itdssOpenCnxErrorBreakHandler: start\n"));
3022 
3023   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3024 
3025   ostiInitiatorIOCompleted (
3026                             tiRoot,
3027                             tdIORequestBody->tiIORequest,
3028                             tiIOFailed,
3029                             tiDetailOtherError,
3030                             agNULL,
3031                             intContext
3032                             );
3033 
3034   return;
3035 }
3036 
3037 /*****************************************************************************
3038 *! \brief itdssOpenCnxErrorITNexusLossHandler
3039 *
3040 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3041 *            layer with agIOStatus = OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS
3042 *
3043 *  \param  agRoot:            pointer to port instance
3044 *  \param  agIORequest:       pointer to I/O request
3045 *  \param  agIOStatus:        I/O status given by LL layer
3046 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3047 *  \param  agParam            A Handle used to refer to the response frame or handle
3048 *                             of abort request
3049 *  \param  agOtherInfo        Residual count
3050 *  \return: None
3051 *
3052 *
3053 *****************************************************************************/
3054 osGLOBAL void
3055 itdssOpenCnxErrorITNexusLossHandler(
3056                        agsaRoot_t           *agRoot,
3057                        agsaIORequest_t      *agIORequest,
3058                        bit32                agIOStatus,
3059                        bit32                agIOInfoLen,
3060                        void                 *agParam,
3061                        bit32                agOtherInfo
3062                        )
3063 {
3064   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3065   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3066   bit32                  intContext = osData->IntContext;
3067   tdIORequestBody_t      *tdIORequestBody;
3068   TI_DBG1(("itdssOpenCnxErrorITNexusLossHandler: start\n"));
3069 
3070   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3071 
3072   ostiInitiatorIOCompleted (
3073                             tiRoot,
3074                             tdIORequestBody->tiIORequest,
3075                             tiIOFailed,
3076                             tiDetailOtherError,
3077                             agNULL,
3078                             intContext
3079                             );
3080 
3081   return;
3082 }
3083 
3084 /*****************************************************************************
3085 *! \brief itdssOpenCnxErrorBadDestinationHandler
3086 *
3087 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3088 *            layer with agIOStatus = OSSA_IO_OPEN_CNX_ERROR_BAD_DESTINATION
3089 *
3090 *  \param  agRoot:            pointer to port instance
3091 *  \param  agIORequest:       pointer to I/O request
3092 *  \param  agIOStatus:        I/O status given by LL layer
3093 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3094 *  \param  agParam            A Handle used to refer to the response frame or handle
3095 *                             of abort request
3096 *  \param  agOtherInfo        Residual count
3097 *  \return: None
3098 *
3099 *
3100 *****************************************************************************/
3101 osGLOBAL void
3102 itdssOpenCnxErrorBadDestinationHandler(
3103                        agsaRoot_t           *agRoot,
3104                        agsaIORequest_t      *agIORequest,
3105                        bit32                agIOStatus,
3106                        bit32                agIOInfoLen,
3107                        void                 *agParam,
3108                        bit32                agOtherInfo
3109                        )
3110 {
3111   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3112   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3113   bit32                  intContext = osData->IntContext;
3114   tdIORequestBody_t      *tdIORequestBody;
3115   TI_DBG1(("itdssOpenCnxErrorBadDestinationHandler: start\n"));
3116 
3117   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3118 
3119   ostiInitiatorIOCompleted (
3120                             tiRoot,
3121                             tdIORequestBody->tiIORequest,
3122                             tiIOFailed,
3123                             tiDetailOtherError,
3124                             agNULL,
3125                             intContext
3126                             );
3127 
3128   return;
3129 }
3130 
3131 /*****************************************************************************
3132 *! \brief itdssOpenCnxErrorConnectionRateNotSupportedHandler
3133 *
3134 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3135 *            layer with agIOStatus = OSSA_IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED
3136 *
3137 *  \param  agRoot:            pointer to port instance
3138 *  \param  agIORequest:       pointer to I/O request
3139 *  \param  agIOStatus:        I/O status given by LL layer
3140 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3141 *  \param  agParam            A Handle used to refer to the response frame or handle
3142 *                             of abort request
3143 *  \param  agOtherInfo        Residual count
3144 *  \return: None
3145 *
3146 *
3147 *****************************************************************************/
3148 osGLOBAL void
3149 itdssOpenCnxErrorConnectionRateNotSupportedHandler(
3150                        agsaRoot_t           *agRoot,
3151                        agsaIORequest_t      *agIORequest,
3152                        bit32                agIOStatus,
3153                        bit32                agIOInfoLen,
3154                        void                 *agParam,
3155                        bit32                agOtherInfo
3156                        )
3157 {
3158   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3159   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3160   tdsaRoot_t             *tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
3161   tdsaContext_t          *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3162   bit32                  intContext = osData->IntContext;
3163   tdIORequestBody_t      *tdIORequestBody;
3164   agsaDevHandle_t        *agDevHandle = agNULL;
3165   tiDeviceHandle_t       *tiDeviceHandle = agNULL;
3166   tdsaDeviceData_t       *oneDeviceData = agNULL;
3167   bit32                  ConnRate = SAS_CONNECTION_RATE_12_0G;
3168   agsaContext_t          *agContext = agNULL;
3169   TI_DBG1(("itdssOpenCnxErrorConnectionRateNotSupportedHandler: start\n"));
3170 
3171   /* we retry by lowering link rate
3172      retry should be in ossaSetDeviceInfoCB()
3173   */
3174   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3175   tiDeviceHandle = tdIORequestBody->tiDevHandle;
3176   oneDeviceData  = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
3177   agDevHandle = oneDeviceData->agDevHandle;
3178 
3179   if (tdsaAllShared->RateAdjust)
3180   {
3181     if (oneDeviceData->valid == agTRUE && oneDeviceData->registered == agTRUE &&
3182         oneDeviceData->tdPortContext != agNULL )
3183     {
3184       ConnRate = DEVINFO_GET_LINKRATE(&oneDeviceData->agDeviceInfo);
3185       if (ConnRate == SAS_CONNECTION_RATE_1_5G)
3186       {
3187         /* no retry; completes IO */
3188         ostiInitiatorIOCompleted(
3189                                  tiRoot,
3190                                  tdIORequestBody->tiIORequest,
3191                                  tiIOFailed,
3192                                  tiDetailOtherError,
3193                                  agNULL,
3194                                  intContext
3195                                  );
3196       }
3197       else
3198       {
3199         ConnRate = ConnRate - 1;
3200       }
3201       agContext = &(tdIORequestBody->agContext);
3202       agContext->osData = agIORequest;
3203       saSetDeviceInfo(agRoot, agContext, tdsaRotateQnumber(tiRoot, oneDeviceData), agDevHandle, 32, ConnRate << 28, ossaIniSetDeviceInfoCB);
3204     }
3205   }
3206   else
3207   {
3208     ostiInitiatorIOCompleted(
3209                              tiRoot,
3210                              tdIORequestBody->tiIORequest,
3211                              tiIOFailed,
3212                              tiDetailOtherError,
3213                              agNULL,
3214                              intContext
3215                              );
3216   }
3217 
3218   return;
3219 }
3220 
3221 /*****************************************************************************
3222 *! \brief itdssOpenCnxErrorSTPResourceBusyHandler
3223 *
3224 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3225 *            layer with agIOStatus = OSSA_IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY
3226 *
3227 *  \param  agRoot:            pointer to port instance
3228 *  \param  agIORequest:       pointer to I/O request
3229 *  \param  agIOStatus:        I/O status given by LL layer
3230 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3231 *  \param  agParam            A Handle used to refer to the response frame or handle
3232 *                             of abort request
3233 *  \param  agOtherInfo        Residual count
3234 *  \return: None
3235 *
3236 *
3237 *****************************************************************************/
3238 osGLOBAL void
3239 itdssOpenCnxErrorSTPResourceBusyHandler(
3240                        agsaRoot_t           *agRoot,
3241                        agsaIORequest_t      *agIORequest,
3242                        bit32                agIOStatus,
3243                        bit32                agIOInfoLen,
3244                        void                 *agParam,
3245                        bit32                agOtherInfo
3246                        )
3247 {
3248   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3249   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3250   bit32                  intContext = osData->IntContext;
3251   tdIORequestBody_t      *tdIORequestBody;
3252   TI_DBG2(("itdssOpenCnxErrorSTPResourceBusyHandler: start\n"));
3253 
3254   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3255 
3256   ostiInitiatorIOCompleted (
3257                             tiRoot,
3258                             tdIORequestBody->tiIORequest,
3259                             tiIOFailed,
3260                             tiDetailOtherError,
3261                             agNULL,
3262                             intContext
3263                             );
3264 
3265   return;
3266 }
3267 
3268 /*****************************************************************************
3269 *! \brief itdssOpenCnxErrorWrongDestinationHandler
3270 *
3271 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3272 *            layer with agIOStatus = OSSA_IO_OPEN_CNX_ERROR_WRONG_DESTINATION
3273 *
3274 *  \param  agRoot:            pointer to port instance
3275 *  \param  agIORequest:       pointer to I/O request
3276 *  \param  agIOStatus:        I/O status given by LL layer
3277 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3278 *  \param  agParam            A Handle used to refer to the response frame or handle
3279 *                             of abort request
3280 *  \param  agOtherInfo        Residual count
3281 *  \return: None
3282 *
3283 *
3284 *****************************************************************************/
3285 osGLOBAL void
3286 itdssOpenCnxErrorWrongDestinationHandler(
3287                        agsaRoot_t           *agRoot,
3288                        agsaIORequest_t      *agIORequest,
3289                        bit32                agIOStatus,
3290                        bit32                agIOInfoLen,
3291                        void                 *agParam,
3292                        bit32                agOtherInfo
3293                        )
3294 {
3295   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3296   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3297   bit32                  intContext = osData->IntContext;
3298   tdIORequestBody_t      *tdIORequestBody;
3299   TI_DBG1(("itdssOpenCnxErrorWrongDestinationHandler: start\n"));
3300 
3301   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3302 
3303   ostiInitiatorIOCompleted (
3304                             tiRoot,
3305                             tdIORequestBody->tiIORequest,
3306                             tiIOFailed,
3307                             tiDetailOtherError,
3308                             agNULL,
3309                             intContext
3310                             );
3311 
3312   return;
3313 }
3314 
3315 /*****************************************************************************
3316 *! \brief itdssOpenCnxErrorUnknownErrorHandler
3317 *
3318 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3319 *            layer with agIOStatus = OSSA_IO_OPEN_CNX_ERROR_UNKNOWN_ERROR
3320 *
3321 *  \param  agRoot:            pointer to port instance
3322 *  \param  agIORequest:       pointer to I/O request
3323 *  \param  agIOStatus:        I/O status given by LL layer
3324 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3325 *  \param  agParam            A Handle used to refer to the response frame or handle
3326 *                             of abort request
3327 *  \param  agOtherInfo        Residual count
3328 *  \return: None
3329 *
3330 *
3331 *****************************************************************************/
3332 osGLOBAL void
3333 itdssOpenCnxErrorUnknownErrorHandler(
3334                        agsaRoot_t           *agRoot,
3335                        agsaIORequest_t      *agIORequest,
3336                        bit32                agIOStatus,
3337                        bit32                agIOInfoLen,
3338                        void                 *agParam,
3339                        bit32                agOtherInfo
3340                        )
3341 {
3342   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3343   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3344   bit32                  intContext = osData->IntContext;
3345   tdIORequestBody_t      *tdIORequestBody;
3346   TI_DBG1(("itdssOpenCnxErrorUnknownErrorHandler: start\n"));
3347 
3348   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3349 
3350   ostiInitiatorIOCompleted (
3351                             tiRoot,
3352                             tdIORequestBody->tiIORequest,
3353                             tiIOFailed,
3354                             tiDetailOtherError,
3355                             agNULL,
3356                             intContext
3357                             );
3358 
3359   return;
3360 }
3361 
3362 /*****************************************************************************
3363 *! \brief itdssXferErrorNAKReceivedHandler
3364 *
3365 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3366 *            layer with agIOStatus = OSSA_IO_XFER_ERROR_NAK_RECEIVED
3367 *
3368 *  \param  agRoot:            pointer to port instance
3369 *  \param  agIORequest:       pointer to I/O request
3370 *  \param  agIOStatus:        I/O status given by LL layer
3371 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3372 *  \param  agParam            A Handle used to refer to the response frame or handle
3373 *                             of abort request
3374 *  \param  agOtherInfo        Residual count
3375 *  \return: None
3376 *
3377 *
3378 *****************************************************************************/
3379 osGLOBAL void
3380 itdssXferErrorNAKReceivedHandler(
3381                        agsaRoot_t           *agRoot,
3382                        agsaIORequest_t      *agIORequest,
3383                        bit32                agIOStatus,
3384                        bit32                agIOInfoLen,
3385                        void                 *agParam,
3386                        bit32                agOtherInfo
3387                        )
3388 {
3389   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3390   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3391   bit32                  intContext = osData->IntContext;
3392   tdIORequestBody_t      *tdIORequestBody;
3393   TI_DBG1(("itdssXferErrorNAKReceivedHandler: start\n"));
3394 
3395   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3396 
3397   ostiInitiatorIOCompleted (
3398                             tiRoot,
3399                             tdIORequestBody->tiIORequest,
3400                             tiIOFailed,
3401                             tiDetailOtherError,
3402                             agNULL,
3403                             intContext
3404                             );
3405 
3406   return;
3407 }
3408 
3409 /*****************************************************************************
3410 *! \brief itdssXferErrorACKNAKTimeoutHandler
3411 *
3412 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3413 *            layer with agIOStatus = OSSA_IO_XFER_ERROR_ACK_NAK_TIMEOUT
3414 *
3415 *  \param  agRoot:            pointer to port instance
3416 *  \param  agIORequest:       pointer to I/O request
3417 *  \param  agIOStatus:        I/O status given by LL layer
3418 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3419 *  \param  agParam            A Handle used to refer to the response frame or handle
3420 *                             of abort request
3421 *  \param  agOtherInfo        Residual count
3422 *  \return: None
3423 *
3424 *
3425 *****************************************************************************/
3426 osGLOBAL void
3427 itdssXferErrorACKNAKTimeoutHandler(
3428                        agsaRoot_t           *agRoot,
3429                        agsaIORequest_t      *agIORequest,
3430                        bit32                agIOStatus,
3431                        bit32                agIOInfoLen,
3432                        void                 *agParam,
3433                        bit32                agOtherInfo
3434                        )
3435 {
3436   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3437   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3438   bit32                  intContext = osData->IntContext;
3439   tdIORequestBody_t      *tdIORequestBody;
3440   TI_DBG1(("itdssXferErrorACKNAKTimeoutHandler: start\n"));
3441 
3442   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3443 
3444   ostiInitiatorIOCompleted (
3445                             tiRoot,
3446                             tdIORequestBody->tiIORequest,
3447                             tiIOFailed,
3448                             tiDetailOtherError,
3449                             agNULL,
3450                             intContext
3451                             );
3452 
3453   return;
3454 }
3455 
3456 /*****************************************************************************
3457 *! \brief itdssXferErrorPeerAbortedHandler
3458 *
3459 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3460 *            layer with agIOStatus = OSSA_IO_XFER_ERROR_PEER_ABORTED
3461 *
3462 *  \param  agRoot:            pointer to port instance
3463 *  \param  agIORequest:       pointer to I/O request
3464 *  \param  agIOStatus:        I/O status given by LL layer
3465 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3466 *  \param  agParam            A Handle used to refer to the response frame or handle
3467 *                             of abort request
3468 *  \param  agOtherInfo        Residual count
3469 *  \return: None
3470 *
3471 *
3472 *****************************************************************************/
3473 osGLOBAL void
3474 itdssXferErrorPeerAbortedHandler(
3475                        agsaRoot_t           *agRoot,
3476                        agsaIORequest_t      *agIORequest,
3477                        bit32                agIOStatus,
3478                        bit32                agIOInfoLen,
3479                        void                 *agParam,
3480                        bit32                agOtherInfo
3481                        )
3482 {
3483   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3484   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3485   bit32                  intContext = osData->IntContext;
3486   tdIORequestBody_t      *tdIORequestBody;
3487   TI_DBG2(("itdssXferErrorPeerAbortedHandler: start\n"));
3488 
3489   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3490 
3491   ostiInitiatorIOCompleted (
3492                             tiRoot,
3493                             tdIORequestBody->tiIORequest,
3494                             tiIOFailed,
3495                             tiDetailOtherError,
3496                             agNULL,
3497                             intContext
3498                             );
3499 
3500   return;
3501 }
3502 
3503 /*****************************************************************************
3504 *! \brief itdssXferErrorRxFrameHandler
3505 *
3506 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3507 *            layer with agIOStatus = OSSA_IO_XFER_ERROR_RX_FRAME
3508 *
3509 *  \param  agRoot:            pointer to port instance
3510 *  \param  agIORequest:       pointer to I/O request
3511 *  \param  agIOStatus:        I/O status given by LL layer
3512 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3513 *  \param  agParam            A Handle used to refer to the response frame or handle
3514 *                             of abort request
3515 *  \param  agOtherInfo        Residual count
3516 *  \return: None
3517 *
3518 *
3519 *****************************************************************************/
3520 osGLOBAL void
3521 itdssXferErrorRxFrameHandler(
3522                        agsaRoot_t           *agRoot,
3523                        agsaIORequest_t      *agIORequest,
3524                        bit32                agIOStatus,
3525                        bit32                agIOInfoLen,
3526                        void                 *agParam,
3527                        bit32                agOtherInfo
3528                        )
3529 {
3530   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3531   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3532   bit32                  intContext = osData->IntContext;
3533   tdIORequestBody_t      *tdIORequestBody;
3534   TI_DBG1(("itdssXferErrorRxFrameHandler: start\n"));
3535 
3536   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3537 
3538   ostiInitiatorIOCompleted (
3539                             tiRoot,
3540                             tdIORequestBody->tiIORequest,
3541                             tiIOFailed,
3542                             tiDetailOtherError,
3543                             agNULL,
3544                             intContext
3545                             );
3546 
3547   return;
3548 }
3549 
3550 /*****************************************************************************
3551 *! \brief itdssXferErrorDMAHandler
3552 *
3553 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3554 *            layer with agIOStatus = OSSA_IO_XFER_ERROR_DMA
3555 *
3556 *  \param  agRoot:            pointer to port instance
3557 *  \param  agIORequest:       pointer to I/O request
3558 *  \param  agIOStatus:        I/O status given by LL layer
3559 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3560 *  \param  agParam            A Handle used to refer to the response frame or handle
3561 *                             of abort request
3562 *  \param  agOtherInfo        Residual count
3563 *  \return: None
3564 *
3565 *
3566 *****************************************************************************/
3567 osGLOBAL void
3568 itdssXferErrorDMAHandler(
3569                        agsaRoot_t           *agRoot,
3570                        agsaIORequest_t      *agIORequest,
3571                        bit32                agIOStatus,
3572                        bit32                agIOInfoLen,
3573                        void                 *agParam,
3574                        bit32                agOtherInfo
3575                        )
3576 {
3577   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3578   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3579   bit32                  intContext = osData->IntContext;
3580   tdIORequestBody_t      *tdIORequestBody;
3581   TI_DBG1(("itdssXferErrorDMAHandler: start\n"));
3582 
3583   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3584 
3585   ostiInitiatorIOCompleted (
3586                             tiRoot,
3587                             tdIORequestBody->tiIORequest,
3588                             tiIOFailed,
3589                             tiDetailOtherErrorNoRetry,
3590                             agNULL,
3591                             intContext
3592                             );
3593 
3594   return;
3595 }
3596 
3597 /*****************************************************************************
3598 *! \brief itdssXferErrorCreditTimeoutHandler
3599 *
3600 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3601 *            layer with agIOStatus = OSSA_IO_XFER_ERROR_CREDIT_TIMEOUT
3602 *
3603 *  \param  agRoot:            pointer to port instance
3604 *  \param  agIORequest:       pointer to I/O request
3605 *  \param  agIOStatus:        I/O status given by LL layer
3606 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3607 *  \param  agParam            A Handle used to refer to the response frame or handle
3608 *                             of abort request
3609 *  \param  agOtherInfo        Residual count
3610 *  \return: None
3611 *
3612 *
3613 *****************************************************************************/
3614 osGLOBAL void
3615 itdssXferErrorCreditTimeoutHandler(
3616                        agsaRoot_t           *agRoot,
3617                        agsaIORequest_t      *agIORequest,
3618                        bit32                agIOStatus,
3619                        bit32                agIOInfoLen,
3620                        void                 *agParam,
3621                        bit32                agOtherInfo
3622                        )
3623 {
3624   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3625   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3626   bit32                  intContext = osData->IntContext;
3627   tdIORequestBody_t      *tdIORequestBody;
3628   TI_DBG1(("itdssXferErrorCreditTimeoutHandler: start\n"));
3629 
3630   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3631 
3632   ostiInitiatorIOCompleted (
3633                             tiRoot,
3634                             tdIORequestBody->tiIORequest,
3635                             tiIOFailed,
3636                             tiDetailOtherError,
3637                             agNULL,
3638                             intContext
3639                             );
3640 
3641   return;
3642 }
3643 
3644 /*****************************************************************************
3645 *! \brief itdssXferErrorCMDIssueACKNAKTimeoutHandler
3646 *
3647 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3648 *            layer with agIOStatus = OSSA_IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT
3649 *
3650 *  \param  agRoot:            pointer to port instance
3651 *  \param  agIORequest:       pointer to I/O request
3652 *  \param  agIOStatus:        I/O status given by LL layer
3653 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3654 *  \param  agParam            A Handle used to refer to the response frame or handle
3655 *                             of abort request
3656 *  \param  agOtherInfo        Residual count
3657 *  \return: None
3658 *
3659 *
3660 *****************************************************************************/
3661 osGLOBAL void
3662 itdssXferErrorCMDIssueACKNAKTimeoutHandler(
3663                        agsaRoot_t           *agRoot,
3664                        agsaIORequest_t      *agIORequest,
3665                        bit32                agIOStatus,
3666                        bit32                agIOInfoLen,
3667                        void                 *agParam,
3668                        bit32                agOtherInfo
3669                        )
3670 {
3671   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3672   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3673   bit32                  intContext = osData->IntContext;
3674   tdIORequestBody_t      *tdIORequestBody;
3675   TI_DBG1(("itdssXferErrorCMDIssueACKNAKTimeoutHandler: start\n"));
3676 
3677   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3678 
3679   ostiInitiatorIOCompleted (
3680                             tiRoot,
3681                             tdIORequestBody->tiIORequest,
3682                             tiIOFailed,
3683                             tiDetailOtherError,
3684                             agNULL,
3685                             intContext
3686                             );
3687 
3688   return;
3689 }
3690 
3691 /*****************************************************************************
3692 *! \brief itdssXferErrorCMDIssueBreakBeforeACKNAKHandler
3693 *
3694 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3695 *            layer with agIOStatus = OSSA_IO_XFER_ERROR_CMD_ISSUE_BREAK_BEFORE_ACK_NAK
3696 *
3697 *  \param  agRoot:            pointer to port instance
3698 *  \param  agIORequest:       pointer to I/O request
3699 *  \param  agIOStatus:        I/O status given by LL layer
3700 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3701 *  \param  agParam            A Handle used to refer to the response frame or handle
3702 *                             of abort request
3703 *  \param  agOtherInfo        Residual count
3704 *  \return: None
3705 *
3706 *
3707 *****************************************************************************/
3708 osGLOBAL void
3709 itdssXferErrorCMDIssueBreakBeforeACKNAKHandler(
3710                        agsaRoot_t           *agRoot,
3711                        agsaIORequest_t      *agIORequest,
3712                        bit32                agIOStatus,
3713                        bit32                agIOInfoLen,
3714                        void                 *agParam,
3715                        bit32                agOtherInfo
3716                        )
3717 {
3718   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3719   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3720   bit32                  intContext = osData->IntContext;
3721   tdIORequestBody_t      *tdIORequestBody;
3722   TI_DBG1(("itdssXferErrorCMDIssueBreakBeforeACKNAKHandler: start\n"));
3723 
3724   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3725 
3726   ostiInitiatorIOCompleted (
3727                             tiRoot,
3728                             tdIORequestBody->tiIORequest,
3729                             tiIOFailed,
3730                             tiDetailOtherError,
3731                             agNULL,
3732                             intContext
3733                             );
3734 
3735   return;
3736 }
3737 
3738 /*****************************************************************************
3739 *! \brief itdssXferErrorCMDIssuePhyDownBeforeACKNAKHandler
3740 *
3741 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3742 *            layer with agIOStatus = OSSA_IO_XFER_ERROR_CMD_ISSUE_PHY_DOWN_BEFORE_ACK_NAK
3743 *
3744 *  \param  agRoot:            pointer to port instance
3745 *  \param  agIORequest:       pointer to I/O request
3746 *  \param  agIOStatus:        I/O status given by LL layer
3747 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3748 *  \param  agParam            A Handle used to refer to the response frame or handle
3749 *                             of abort request
3750 *  \param  agOtherInfo        Residual count
3751 *  \return: None
3752 *
3753 *
3754 *****************************************************************************/
3755 osGLOBAL void
3756 itdssXferErrorCMDIssuePhyDownBeforeACKNAKHandler(
3757                        agsaRoot_t           *agRoot,
3758                        agsaIORequest_t      *agIORequest,
3759                        bit32                agIOStatus,
3760                        bit32                agIOInfoLen,
3761                        void                 *agParam,
3762                        bit32                agOtherInfo
3763                        )
3764 {
3765   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3766   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3767   bit32                  intContext = osData->IntContext;
3768   tdIORequestBody_t      *tdIORequestBody;
3769   TI_DBG1(("itdssXferErrorCMDIssuePhyDownBeforeACKNAKHandler: start\n"));
3770 
3771   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3772 
3773   ostiInitiatorIOCompleted (
3774                             tiRoot,
3775                             tdIORequestBody->tiIORequest,
3776                             tiIOFailed,
3777                             tiDetailOtherError,
3778                             agNULL,
3779                             intContext
3780                             );
3781 
3782   return;
3783 }
3784 
3785 /*****************************************************************************
3786 *! \brief itdssXferErrorDisruptedPhyDownHandler
3787 *
3788 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3789 *            layer with agIOStatus = OSSA_IO_XFER_ERROR_DISRUPTED_PHY_DOWN
3790 *
3791 *  \param  agRoot:            pointer to port instance
3792 *  \param  agIORequest:       pointer to I/O request
3793 *  \param  agIOStatus:        I/O status given by LL layer
3794 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3795 *  \param  agParam            A Handle used to refer to the response frame or handle
3796 *                             of abort request
3797 *  \param  agOtherInfo        Residual count
3798 *  \return: None
3799 *
3800 *
3801 *****************************************************************************/
3802 osGLOBAL void
3803 itdssXferErrorDisruptedPhyDownHandler(
3804                        agsaRoot_t           *agRoot,
3805                        agsaIORequest_t      *agIORequest,
3806                        bit32                agIOStatus,
3807                        bit32                agIOInfoLen,
3808                        void                 *agParam,
3809                        bit32                agOtherInfo
3810                        )
3811 {
3812   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3813   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3814   bit32                  intContext = osData->IntContext;
3815   tdIORequestBody_t      *tdIORequestBody;
3816   TI_DBG2(("itdssXferErrorDisruptedPhyDownHandler: start\n"));
3817 
3818   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3819 
3820   ostiInitiatorIOCompleted (
3821                             tiRoot,
3822                             tdIORequestBody->tiIORequest,
3823                             tiIOFailed,
3824                             tiDetailOtherError,
3825                             agNULL,
3826                             intContext
3827                             );
3828 
3829   return;
3830 }
3831 
3832 /*****************************************************************************
3833 *! \brief itdssXferErrorOffsetMismatchHandler
3834 *
3835 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3836 *            layer with agIOStatus = OSSA_IO_XFER_ERROR_OFFSET_MISMATCH
3837 *
3838 *  \param  agRoot:            pointer to port instance
3839 *  \param  agIORequest:       pointer to I/O request
3840 *  \param  agIOStatus:        I/O status given by LL layer
3841 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3842 *  \param  agParam            A Handle used to refer to the response frame or handle
3843 *                             of abort request
3844 *  \param  agOtherInfo        Residual count
3845 *  \return: None
3846 *
3847 *
3848 *****************************************************************************/
3849 osGLOBAL void
3850 itdssXferErrorOffsetMismatchHandler(
3851                        agsaRoot_t           *agRoot,
3852                        agsaIORequest_t      *agIORequest,
3853                        bit32                agIOStatus,
3854                        bit32                agIOInfoLen,
3855                        void                 *agParam,
3856                        bit32                agOtherInfo
3857                        )
3858 {
3859   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3860   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3861   bit32                  intContext = osData->IntContext;
3862   tdIORequestBody_t      *tdIORequestBody;
3863   TI_DBG1(("itdssXferErrorOffsetMismatchHandler: start\n"));
3864 
3865   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3866 
3867   ostiInitiatorIOCompleted (
3868                             tiRoot,
3869                             tdIORequestBody->tiIORequest,
3870                             tiIOFailed,
3871                             tiDetailOtherError,
3872                             agNULL,
3873                             intContext
3874                             );
3875 
3876   return;
3877 }
3878 
3879 /*****************************************************************************
3880 *! \brief itdssXferErrorXferZeroDataLenHandler
3881 *
3882 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3883 *            layer with agIOStatus = OSSA_IO_XFER_ERROR_XFER_ZERO_DATA_LEN
3884 *
3885 *  \param  agRoot:            pointer to port instance
3886 *  \param  agIORequest:       pointer to I/O request
3887 *  \param  agIOStatus:        I/O status given by LL layer
3888 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3889 *  \param  agParam            A Handle used to refer to the response frame or handle
3890 *                             of abort request
3891 *  \param  agOtherInfo        Residual count
3892 *  \return: None
3893 *
3894 *
3895 *****************************************************************************/
3896 osGLOBAL void
3897 itdssXferErrorXferZeroDataLenHandler(
3898                        agsaRoot_t           *agRoot,
3899                        agsaIORequest_t      *agIORequest,
3900                        bit32                agIOStatus,
3901                        bit32                agIOInfoLen,
3902                        void                 *agParam,
3903                        bit32                agOtherInfo
3904                        )
3905 {
3906   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3907   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3908   bit32                  intContext = osData->IntContext;
3909   tdIORequestBody_t      *tdIORequestBody;
3910   TI_DBG2(("itdssXferErrorXferZeroDataLenHandler: start\n"));
3911 
3912   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3913 
3914   ostiInitiatorIOCompleted (
3915                             tiRoot,
3916                             tdIORequestBody->tiIORequest,
3917                             tiIOFailed,
3918                             tiDetailOtherError,
3919                             agNULL,
3920                             intContext
3921                             );
3922 
3923   return;
3924 }
3925 
3926 /*****************************************************************************
3927 *! \brief itdssXferOpenRetryTimeoutHandler
3928 *
3929 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
3930 *            layer with agIOStatus = OSSA_IO_XFER_OPEN_RETRY_TIMEOUT
3931 *
3932 *  \param  agRoot:            pointer to port instance
3933 *  \param  agIORequest:       pointer to I/O request
3934 *  \param  agIOStatus:        I/O status given by LL layer
3935 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
3936 *  \param  agParam            A Handle used to refer to the response frame or handle
3937 *                             of abort request
3938 *  \param  agOtherInfo        Residual count
3939 *  \return: None
3940 *
3941 *
3942 *****************************************************************************/
3943 osGLOBAL void
3944 itdssXferOpenRetryTimeoutHandler(
3945                        agsaRoot_t           *agRoot,
3946                        agsaIORequest_t      *agIORequest,
3947                        bit32                agIOStatus,
3948                        bit32                agIOInfoLen,
3949                        void                 *agParam,
3950                        bit32                agOtherInfo
3951                        )
3952 {
3953   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
3954   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
3955   tdsaRoot_t             *tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
3956   tdsaContext_t          *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3957   itdsaIni_t             *Initiator = (itdsaIni_t *)tdsaAllShared->itdsaIni;
3958   bit32                  intContext = osData->IntContext;
3959   tdIORequestBody_t      *tdIORequestBody;
3960   agsaDevHandle_t        *agDevHandle = agNULL;
3961   tiDeviceHandle_t       *tiDeviceHandle = agNULL;
3962   tdsaDeviceData_t       *oneDeviceData = agNULL;
3963   bit32                  saStatus = AGSA_RC_FAILURE;
3964 
3965   TI_DBG2(("itdssXferOpenRetryTimeoutHandler: start\n"));
3966 
3967   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
3968   tiDeviceHandle = tdIORequestBody->tiDevHandle;
3969   oneDeviceData  = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
3970   agDevHandle = oneDeviceData->agDevHandle;
3971 
3972   if (oneDeviceData->valid == agTRUE && oneDeviceData->registered == agTRUE &&
3973       oneDeviceData->tdPortContext != agNULL )
3974   {
3975     if (tdIORequestBody->reTries < OPEN_RETRY_RETRIES) /* 10 */
3976     {
3977       saStatus = saSSPStart(agRoot,
3978                             agIORequest,
3979                             tdsaRotateQnumber(tiRoot, oneDeviceData),
3980                             agDevHandle,
3981                             tdIORequestBody->agRequestType,
3982                             &(tdIORequestBody->transport.SAS.agSASRequestBody),
3983                             agNULL,
3984                             &ossaSSPCompleted);
3985 
3986       if (saStatus == AGSA_RC_SUCCESS)
3987       {
3988         TI_DBG2(("itdssXferOpenRetryTimeoutHandler: retried\n"));
3989         Initiator->NumIOsActive++;
3990         tdIORequestBody->ioStarted = agTRUE;
3991         tdIORequestBody->ioCompleted = agFALSE;
3992         tdIORequestBody->reTries++;
3993         return;
3994       }
3995       else
3996       {
3997         TI_DBG1(("itdssXferOpenRetryTimeoutHandler: retry failed\n"));
3998         tdIORequestBody->ioStarted = agFALSE;
3999         tdIORequestBody->ioCompleted = agTRUE;
4000         tdIORequestBody->reTries = 0;
4001       }
4002     }
4003     else
4004     {
4005       TI_DBG1(("itdssXferOpenRetryTimeoutHandler: retry is over and fail\n"));
4006       tdIORequestBody->reTries = 0;
4007     }
4008   }
4009   else
4010   {
4011     TI_DBG1(("itdssXferOpenRetryTimeoutHandler: not valid deivce no retry\n"));
4012     tdIORequestBody->reTries = 0;
4013   }
4014   ostiInitiatorIOCompleted(
4015                            tiRoot,
4016                            tdIORequestBody->tiIORequest,
4017                            tiIOFailed,
4018                            tiDetailOtherError,
4019                            agNULL,
4020                            intContext
4021                            );
4022   return;
4023 }
4024 
4025 /*****************************************************************************
4026 *! \brief itdssPortInResetHandler
4027 *
4028 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
4029 *            layer with agIOStatus = OSSA_IO_PORT_IN_RESET
4030 *
4031 *  \param  agRoot:            pointer to port instance
4032 *  \param  agIORequest:       pointer to I/O request
4033 *  \param  agIOStatus:        I/O status given by LL layer
4034 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
4035 *  \param  agParam            A Handle used to refer to the response frame or handle
4036 *                             of abort request
4037 *  \param  agOtherInfo        Residual count
4038 *  \return: None
4039 *
4040 *
4041 *****************************************************************************/
4042 osGLOBAL void
4043 itdssPortInResetHandler(
4044                        agsaRoot_t           *agRoot,
4045                        agsaIORequest_t      *agIORequest,
4046                        bit32                agIOStatus,
4047                        bit32                agIOInfoLen,
4048                        void                 *agParam,
4049                        bit32                agOtherInfo
4050                        )
4051 {
4052   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
4053   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
4054   bit32                  intContext = osData->IntContext;
4055   tdIORequestBody_t      *tdIORequestBody;
4056   TI_DBG2(("itdssPortInResetHandler: start\n"));
4057 
4058   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4059 
4060   ostiInitiatorIOCompleted (
4061                             tiRoot,
4062                             tdIORequestBody->tiIORequest,
4063                             tiIOFailed,
4064                             tiDetailOtherError,
4065                             agNULL,
4066                             intContext
4067                             );
4068 
4069   return;
4070 }
4071 
4072 /*****************************************************************************
4073 *! \brief itdssDsNonOperationalHandler
4074 *
4075 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
4076 *            layer with agIOStatus = OSSA_IO_DS_NON_OPERATIONAL
4077 *
4078 *  \param  agRoot:            pointer to port instance
4079 *  \param  agIORequest:       pointer to I/O request
4080 *  \param  agIOStatus:        I/O status given by LL layer
4081 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
4082 *  \param  agParam            A Handle used to refer to the response frame or handle
4083 *                             of abort request
4084 *  \param  agOtherInfo        Residual count
4085 *  \return: None
4086 *
4087 *
4088 *****************************************************************************/
4089 osGLOBAL void
4090 itdssDsNonOperationalHandler(
4091                        agsaRoot_t           *agRoot,
4092                        agsaIORequest_t      *agIORequest,
4093                        bit32                agIOStatus,
4094                        bit32                agIOInfoLen,
4095                        void                 *agParam,
4096                        bit32                agOtherInfo
4097                        )
4098 {
4099   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
4100   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
4101   bit32                  intContext = osData->IntContext;
4102   tdIORequestBody_t      *tdIORequestBody;
4103   agsaDevHandle_t        *agDevHandle = agNULL;
4104   tiDeviceHandle_t       *tiDeviceHandle = agNULL;
4105   tdsaDeviceData_t       *oneDeviceData = agNULL;
4106 
4107 
4108   TI_DBG2(("itdssDsNonOperationalHandler: start\n"));
4109 
4110 
4111   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4112 
4113 #if 1 /* TBD */
4114   /* let's do it only once ????? */
4115   tiDeviceHandle = tdIORequestBody->tiDevHandle;
4116   oneDeviceData  = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
4117   agDevHandle = oneDeviceData->agDevHandle;
4118   if (oneDeviceData->valid == agTRUE && oneDeviceData->registered == agTRUE &&
4119       oneDeviceData->tdPortContext != agNULL )
4120   {
4121     saSetDeviceState(agRoot, agNULL, tdsaRotateQnumber(tiRoot, oneDeviceData), agDevHandle, SA_DS_OPERATIONAL);
4122   }
4123 #endif
4124 
4125   ostiInitiatorIOCompleted (
4126                             tiRoot,
4127                             tdIORequestBody->tiIORequest,
4128                             tiIOFailed,
4129                             tiDetailOtherError,
4130                             agNULL,
4131                             intContext
4132                             );
4133 
4134   return;
4135 }
4136 
4137 /*****************************************************************************
4138 *! \brief itdssDsInRecoveryHandler
4139 *
4140 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
4141 *            layer with agIOStatus = OSSA_IO_DS_IN_RECOVERY
4142 *
4143 *  \param  agRoot:            pointer to port instance
4144 *  \param  agIORequest:       pointer to I/O request
4145 *  \param  agIOStatus:        I/O status given by LL layer
4146 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
4147 *  \param  agParam            A Handle used to refer to the response frame or handle
4148 *                             of abort request
4149 *  \param  agOtherInfo        Residual count
4150 *  \return: None
4151 *
4152 *
4153 *****************************************************************************/
4154 osGLOBAL void
4155 itdssDsInRecoveryHandler(
4156                        agsaRoot_t           *agRoot,
4157                        agsaIORequest_t      *agIORequest,
4158                        bit32                agIOStatus,
4159                        bit32                agIOInfoLen,
4160                        void                 *agParam,
4161                        bit32                agOtherInfo
4162                        )
4163 {
4164   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
4165   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
4166   bit32                  intContext = osData->IntContext;
4167   tdIORequestBody_t      *tdIORequestBody;
4168   TI_DBG2(("itdssDsInRecoveryHandler: start\n"));
4169 
4170   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4171 
4172   ostiInitiatorIOCompleted (
4173                             tiRoot,
4174                             tdIORequestBody->tiIORequest,
4175                             tiIOFailed,
4176                             tiDetailOtherError,
4177                             agNULL,
4178                             intContext
4179                             );
4180 
4181   return;
4182 }
4183 
4184 /*****************************************************************************
4185 *! \brief itdssTmTagNotFoundHandler
4186 *
4187 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
4188 *            layer with agIOStatus = OSSA_IO_TM_TAG_NOT_FOUND
4189 *
4190 *  \param  agRoot:            pointer to port instance
4191 *  \param  agIORequest:       pointer to I/O request
4192 *  \param  agIOStatus:        I/O status given by LL layer
4193 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
4194 *  \param  agParam            A Handle used to refer to the response frame or handle
4195 *                             of abort request
4196 *  \param  agOtherInfo        Residual count
4197 *  \return: None
4198 *
4199 *
4200 *****************************************************************************/
4201 osGLOBAL void
4202 itdssTmTagNotFoundHandler(
4203                        agsaRoot_t           *agRoot,
4204                        agsaIORequest_t      *agIORequest,
4205                        bit32                agIOStatus,
4206                        bit32                agIOInfoLen,
4207                        void                 *agParam,
4208                        bit32                agOtherInfo
4209                        )
4210 {
4211   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
4212   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
4213   bit32                  intContext = osData->IntContext;
4214   tdIORequestBody_t      *tdIORequestBody;
4215   TI_DBG2(("itdssTmTagNotFoundHandler: start\n"));
4216 
4217   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4218 
4219   ostiInitiatorIOCompleted (
4220                             tiRoot,
4221                             tdIORequestBody->tiIORequest,
4222                             tiIOFailed,
4223                             tiDetailOtherError,
4224                             agNULL,
4225                             intContext
4226                             );
4227 
4228   return;
4229 }
4230 
4231 /*****************************************************************************
4232 *! \brief itdssSSPExtIUZeroLenHandler
4233 *
4234 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
4235 *            layer with agIOStatus = OSSA_IO_SSP_EXT_IU_ZERO_LEN_ERROR
4236 *
4237 *  \param  agRoot:            pointer to port instance
4238 *  \param  agIORequest:       pointer to I/O request
4239 *  \param  agIOStatus:        I/O status given by LL layer
4240 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
4241 *  \param  agParam            A Handle used to refer to the response frame or handle
4242 *                             of abort request
4243 *  \param  agOtherInfo        Residual count
4244 *  \return: None
4245 *
4246 *
4247 *****************************************************************************/
4248 osGLOBAL void
4249 itdssSSPExtIUZeroLenHandler(
4250                        agsaRoot_t           *agRoot,
4251                        agsaIORequest_t      *agIORequest,
4252                        bit32                agIOStatus,
4253                        bit32                agIOInfoLen,
4254                        void                 *agParam,
4255                        bit32                agOtherInfo
4256                        )
4257 {
4258   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
4259   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
4260   bit32                  intContext = osData->IntContext;
4261   tdIORequestBody_t      *tdIORequestBody;
4262   TI_DBG2(("itdssSSPExtIUZeroLenHandler: start\n"));
4263 
4264   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4265 
4266   ostiInitiatorIOCompleted (
4267                             tiRoot,
4268                             tdIORequestBody->tiIORequest,
4269                             tiIOFailed,
4270                             tiDetailOtherError,
4271                             agNULL,
4272                             intContext
4273                             );
4274 
4275   return;
4276 }
4277 
4278 /*****************************************************************************
4279 *! \brief itdssXferErrorUnexpectedPhaseHandler
4280 *
4281 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
4282 *            layer with agIOStatus = OSSA_IO_XFER_ERROR_UNEXPECTED_PHASE
4283 *
4284 *  \param  agRoot:            pointer to port instance
4285 *  \param  agIORequest:       pointer to I/O request
4286 *  \param  agIOStatus:        I/O status given by LL layer
4287 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
4288 *  \param  agParam            A Handle used to refer to the response frame or handle
4289 *                             of abort request
4290 *  \param  agOtherInfo        Residual count
4291 *  \return: None
4292 *
4293 *
4294 *****************************************************************************/
4295 osGLOBAL void
4296 itdssXferErrorUnexpectedPhaseHandler(
4297                        agsaRoot_t           *agRoot,
4298                        agsaIORequest_t      *agIORequest,
4299                        bit32                agIOStatus,
4300                        bit32                agIOInfoLen,
4301                        void                 *agParam,
4302                        bit32                agOtherInfo
4303                        )
4304 {
4305   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
4306   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
4307   bit32                  intContext = osData->IntContext;
4308   tdIORequestBody_t      *tdIORequestBody;
4309   TI_DBG2(("itdssXferErrorUnexpectedPhaseHandler: start\n"));
4310 
4311   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4312 
4313   ostiInitiatorIOCompleted (
4314                             tiRoot,
4315                             tdIORequestBody->tiIORequest,
4316                             tiIOFailed,
4317                             tiDetailOtherError,
4318                             agNULL,
4319                             intContext
4320                             );
4321 
4322   return;
4323 }
4324 
4325 #ifdef REMOVED
4326 /*****************************************************************************
4327 *! \brief itdssIOUnderFlowWithChkConditionHandler
4328 *
4329 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
4330 *            layer with agIOStatus = OSSA_IO_UNDERFLOW_WITH_CHK_COND
4331 *
4332 *  \param  agRoot:            pointer to port instance
4333 *  \param  agIORequest:       pointer to I/O request
4334 *  \param  agIOStatus:        I/O status given by LL layer
4335 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
4336 *  \param  agParam            A Handle used to refer to the response frame or handle
4337 *                             of abort request
4338 *  \return: None
4339 *
4340 *
4341 *****************************************************************************/
4342 /*
4343   How to report SCSI_STAT_CHECK_CONDITION and tiIOUnderRun simultaneoulsy???
4344   ostiInitiatorIOCompleted(
4345                              tiRoot,
4346                              tdIORequestBody->tiIORequest,
4347                              tiIOSuccess,
4348                              SCSI_STAT_CHECK_CONDITION,
4349                              &senseData,
4350                              agTRUE
4351                              );
4352 
4353                  vs
4354 
4355   ostiInitiatorIOCompleted (
4356                             tiRoot,
4357                             tdIORequestBody->tiIORequest,
4358                             tiIOUnderRun,
4359                             agIOInfoLen,
4360                             agNULL,
4361                             intContext
4362                             );
4363 
4364   For now, SCSI_STAT_CHECK_CONDITION is reported until TISA changes (as of 1/6/09)
4365   In other words, this handler is the practically same as itdssIOSuccessHandler()
4366 */
4367 osGLOBAL void
4368 itdssIOUnderFlowWithChkConditionHandler(
4369                         agsaRoot_t              *agRoot,
4370                         agsaIORequest_t         *agIORequest,
4371                         bit32                   agIOStatus,
4372                         bit32                   agIOInfoLen,
4373                         void                    *agParam
4374                         )
4375 {
4376   tdsaRootOsData_t          *osData = (tdsaRootOsData_t *)agRoot->osData;
4377   tiRoot_t                  *tiRoot = (tiRoot_t *)osData->tiRoot;
4378   tdIORequestBody_t         *tdIORequestBody;
4379   agsaSSPResponseInfoUnit_t agSSPRespIU;
4380   tiSenseData_t             senseData;
4381   bit8                      senseDataPayload[256];
4382   bit8                      respData[128];
4383   bit32                     scsi_status;
4384   bit32                     senseLen;
4385   bit32                     respLen;
4386   bit32                     data_status;
4387   bit32                     i;
4388   tiDeviceHandle_t          *tiDeviceHandle = agNULL;
4389   tdsaDeviceData_t          *oneDeviceData = agNULL;
4390 
4391   TI_DBG2(("itdssIOUnderFlowWithChkConditionHandler: start\n"));
4392   TI_DBG2(("itdssIOUnderFlowWithChkConditionHandler: agIOInfoLen 0x%x\n", agIOInfoLen));
4393 
4394   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4395 
4396   tdIORequestBody->ioCompleted = agTRUE;
4397   tdIORequestBody->ioStarted = agFALSE;
4398 
4399   /*
4400     agIOInfoLen must be >= sizeof(agsaSSPResponseInfoUnit_t), which is minimum
4401     date length
4402   */
4403   if (agIOInfoLen < sizeof(agsaSSPResponseInfoUnit_t))
4404   {
4405     TI_DBG1(("itdssIOUnderFlowWithChkConditionHandler: First agIOInfoLen does not match!!!\n"));
4406     TI_DBG1(("itdssIOUnderFlowWithChkConditionHandler: First agIOInfoLen 0x%x IU 0x%x\n", agIOInfoLen, (unsigned int)sizeof(agsaSSPResponseInfoUnit_t)));
4407     ostiInitiatorIOCompleted(
4408                              tiRoot,
4409                              tdIORequestBody->tiIORequest, /* tiIORequest */
4410                              tiIOFailed,
4411                              tiDetailOtherError,
4412                              agNULL,
4413                              agTRUE /* intContext; is not being used */
4414                              );
4415     return;
4416   }
4417   /* reads agsaSSPResponseInfoUnit_t */
4418   saFrameReadBlock(agRoot, agParam, 0, &agSSPRespIU, sizeof(agsaSSPResponseInfoUnit_t));
4419 
4420   data_status = SA_SSPRESP_GET_DATAPRES(&agSSPRespIU);
4421   scsi_status = agSSPRespIU.status;
4422   /* endianess is invovled here */
4423   senseLen = SA_SSPRESP_GET_SENSEDATALEN(&agSSPRespIU);
4424   respLen = SA_SSPRESP_GET_RESPONSEDATALEN(&agSSPRespIU);
4425 
4426   TI_DBG2(("itdssIOUnderFlowWithChkConditionHandler: dataPres=%x\n", data_status));
4427   TI_DBG2(("itdssIOUnderFlowWithChkConditionHandler: scsi status=0x%x, senselen=0x%x resplen 0x%x\n", scsi_status, senseLen, respLen));
4428 
4429   /*
4430     sanity check: do not go beyond of agIOInfoLen. if happens, return error
4431     agIOInfoLen >= sizeof(agsaSSPResponseInfoUnit_t) + senseLen + respLen -> OK
4432     because frame must be divisible by 4, so there can be extra padding
4433     agIOInfoLen < sizeof(agsaSSPResponseInfoUnit_t) + senseLen + respLen -> NOT OK
4434   */
4435   if (agIOInfoLen < sizeof(agsaSSPResponseInfoUnit_t) + senseLen + respLen)
4436   {
4437     TI_DBG1(("itdssIOUnderFlowWithChkConditionHandler: Second agIOInfoLen does not match!!!\n"));
4438     TI_DBG1(("itdssIOUnderFlowWithChkConditionHandler: Second agIOInfoLen 0x%x IU 0x%x senselen 0x%x resplen 0x%x\n", agIOInfoLen, (unsigned int)sizeof(agsaSSPResponseInfoUnit_t), senseLen, respLen));
4439 
4440     ostiInitiatorIOCompleted(
4441                              tiRoot,
4442                              tdIORequestBody->tiIORequest, /* tiIORequest */
4443                              tiIOFailed,
4444                              tiDetailOtherError,
4445                              agNULL,
4446                              agTRUE /* intContext; is not being used */
4447                              );
4448     return;
4449   }
4450 
4451   /* reads response data */
4452   saFrameReadBlock(agRoot, agParam,
4453                    sizeof(agsaSSPResponseInfoUnit_t),
4454                    respData, respLen);
4455   /* reads sense data */
4456   saFrameReadBlock(agRoot, agParam,
4457                    sizeof(agsaSSPResponseInfoUnit_t)
4458                    + respLen,
4459                    senseDataPayload, senseLen);
4460 
4461   if (data_status == 0)
4462   {
4463     /* NO_DATA */
4464     TI_DBG2(("itdssIOUnderFlowWithChkConditionHandler: no data\n"));
4465 
4466     ostiInitiatorIOCompleted(
4467                              tiRoot,
4468                              tdIORequestBody->tiIORequest, /* tiIORequest */
4469                              tiIOSuccess,
4470                              scsi_status,
4471                              agNULL,
4472                              agTRUE /* intContext; is not being used */
4473                              );
4474 
4475     return;
4476   }
4477 
4478   if (data_status == 1)
4479   {
4480     /* RESPONSE_DATA */
4481     TI_DBG2(("itdssIOUnderFlowWithChkConditionHandler: response data \n"));
4482 
4483     ostiInitiatorIOCompleted(
4484                              tiRoot,
4485                              tdIORequestBody->tiIORequest, /* tiIORequest */
4486                              tiIOSuccess,
4487                              0,
4488                              agNULL,
4489                              agTRUE /* intContext; is not being used */
4490                              );
4491     return;
4492   }
4493 
4494   if (data_status == 2)
4495   {
4496     /* SENSE_DATA */
4497     TI_DBG2(("itdssIOUnderFlowWithChkConditionHandler: sense data \n"));
4498 
4499     senseData.senseData = &senseDataPayload;
4500     senseData.senseLen = MIN(256, senseLen);
4501     /* debugging */
4502     tdhexdump("ResponseIU I", (bit8 *)&agSSPRespIU, sizeof(agsaSSPResponseInfoUnit_t));
4503 
4504     tdhexdump("sense data I", (bit8 *)senseDataPayload, senseLen);
4505     tdhexdump("sense data II", (bit8 *)senseData.senseData, senseData.senseLen);
4506 
4507     if (senseDataPayload[2] == SCSI_SENSE_KEY_RECOVERED_ERROR)
4508     {
4509       Initiator->SenseKeyCounter.SoftError ++;
4510     }
4511     else if (senseDataPayload[2] == SCSI_SENSE_KEY_NOT_READY)
4512     {
4513       Initiator->SenseKeyCounter.MediumNotReady++;
4514     }
4515     else if (senseDataPayload[2] == SCSI_SENSE_KEY_MEDIUM_ERROR)
4516     {
4517       Initiator->SenseKeyCounter.MediumError++;
4518     }
4519     else if (senseDataPayload[2] == SCSI_SENSE_KEY_HARDWARE_ERROR)
4520     {
4521       Initiator->SenseKeyCounter.HardwareError++;
4522     }
4523     else if (senseDataPayload[2] == SCSI_SENSE_KEY_ILLEGAL_REQUEST)
4524     {
4525       Initiator->SenseKeyCounter.IllegalRequest++;
4526     }
4527     else if (senseDataPayload[2] == SCSI_SENSE_KEY_UNIT_ATTENTION)
4528     {
4529       Initiator->SenseKeyCounter.UnitAttention++;
4530     }
4531     else if (senseDataPayload[2] == SCSI_SENSE_KEY_ABORTED_COMMAND)
4532     {
4533       Initiator->SenseKeyCounter.AbortCommand++;
4534     }
4535     else
4536     {
4537       Initiator->SenseKeyCounter.OtherKeyType++;
4538     }
4539 
4540     /* when ASQ and ASCQ 0x04 0x11, does saLocalPhyControl for notify spinup */
4541     if ((senseDataPayload[12] == 0x04 && senseDataPayload[13] == 0x11))
4542     {
4543       TI_DBG2(("itdssIOUnderFlowWithChkConditionHandler: sending notfify spinup\n"));
4544       tiDeviceHandle = tdIORequestBody->tiDevHandle;
4545       oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
4546       if (oneDeviceData->directlyAttached == agTRUE)
4547       {
4548         for (i=0;i<TD_MAX_NUM_NOTIFY_SPINUP;i++)
4549         {
4550           saLocalPhyControl(agRoot, agNULL, 0, oneDeviceData->phyID, AGSA_PHY_NOTIFY_ENABLE_SPINUP, agNULL);
4551         }
4552       }
4553     }
4554     ostiInitiatorIOCompleted(
4555                              tiRoot,
4556                              /* tiIORequest */
4557                              tdIORequestBody->tiIORequest,
4558                              tiIOSuccess,
4559                              scsi_status,
4560                              &senseData,
4561                              agTRUE /* intContext; is not being used */
4562                              );
4563     return;
4564   }
4565   if (data_status == 3)
4566   {
4567     /* RESERVED */
4568     TI_DBG1(("itdssIOUnderFlowWithChkConditionHandler: reserved wrong!!!\n"));
4569     ostiInitiatorIOCompleted(
4570                              tiRoot,
4571                              tdIORequestBody->tiIORequest, /* tiIORequest */
4572                              tiIOFailed,
4573                              scsi_status,
4574                              agNULL,
4575                              agTRUE /* intContext; is not being used */
4576                              );
4577     return;
4578   }
4579 
4580 
4581   return;
4582 }
4583 #endif
4584 
4585 /*****************************************************************************
4586 *! \brief itdssXferOpenRetryBackoffThresholdReachedHandler
4587 *
4588 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
4589 *            layer with agIOStatus =
4590 *            OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED
4591 *
4592 *  \param  agRoot:            pointer to port instance
4593 *  \param  agIORequest:       pointer to I/O request
4594 *  \param  agIOStatus:        I/O status given by LL layer
4595 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
4596 *  \param  agParam            A Handle used to refer to the response frame or handle
4597 *                             of abort request
4598 *  \param  agOtherInfo        Residual count
4599 *  \return: None
4600 *
4601 *
4602 *****************************************************************************/
4603 osGLOBAL void
4604 itdssXferOpenRetryBackoffThresholdReachedHandler(
4605                                                  agsaRoot_t           *agRoot,
4606                                                  agsaIORequest_t      *agIORequest,
4607                                                  bit32                agIOStatus,
4608                                                  bit32                agIOInfoLen,
4609                                                  void                 *agParam,
4610                                                  bit32                agOtherInfo
4611                                                 )
4612 {
4613   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
4614   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
4615   bit32                  intContext = osData->IntContext;
4616   tdIORequestBody_t      *tdIORequestBody;
4617   TI_DBG2(("itdssXferOpenRetryBackoffThresholdReachedHandler: start\n"));
4618 
4619   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4620 
4621   ostiInitiatorIOCompleted (
4622                             tiRoot,
4623                             tdIORequestBody->tiIORequest,
4624                             tiIOFailed,
4625                             tiDetailOtherError,
4626                             agNULL,
4627                             intContext
4628                             );
4629 
4630   return;
4631 }
4632 
4633 /*****************************************************************************
4634 *! \brief itdssOpenCnxErrorItNexusLossOpenTmoHandler
4635 *
4636 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
4637 *            layer with agIOStatus = OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO
4638 *
4639 *  \param  agRoot:            pointer to port instance
4640 *  \param  agIORequest:       pointer to I/O request
4641 *  \param  agIOStatus:        I/O status given by LL layer
4642 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
4643 *  \param  agParam            A Handle used to refer to the response frame or handle
4644 *                             of abort request
4645 *  \param  agOtherInfo        Residual count
4646 *  \return: None
4647 *
4648 *
4649 *****************************************************************************/
4650 osGLOBAL void
4651 itdssOpenCnxErrorItNexusLossOpenTmoHandler(
4652                                            agsaRoot_t           *agRoot,
4653                                            agsaIORequest_t      *agIORequest,
4654                                            bit32                agIOStatus,
4655                                            bit32                agIOInfoLen,
4656                                            void                 *agParam,
4657                                            bit32                agOtherInfo
4658                                           )
4659 {
4660   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
4661   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
4662   bit32                  intContext = osData->IntContext;
4663   tdIORequestBody_t      *tdIORequestBody;
4664   TI_DBG2(("itdssOpenCnxErrorItNexusLossOpenTmoHandler: start\n"));
4665 
4666   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4667 
4668   ostiInitiatorIOCompleted (
4669                             tiRoot,
4670                             tdIORequestBody->tiIORequest,
4671                             tiIOFailed,
4672                             tiDetailOtherError,
4673                             agNULL,
4674                             intContext
4675                             );
4676 
4677   return;
4678 }
4679 
4680 /*****************************************************************************
4681 *! \brief itdssOpenCnxErrorItNexusLossNoDestHandler
4682 *
4683 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
4684 *            layer with agIOStatus = OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST
4685 *
4686 *  \param  agRoot:            pointer to port instance
4687 *  \param  agIORequest:       pointer to I/O request
4688 *  \param  agIOStatus:        I/O status given by LL layer
4689 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
4690 *  \param  agParam            A Handle used to refer to the response frame or handle
4691 *                             of abort request
4692 *  \param  agOtherInfo        Residual count
4693 *  \return: None
4694 *
4695 *
4696 *****************************************************************************/
4697 osGLOBAL void
4698 itdssOpenCnxErrorItNexusLossNoDestHandler(
4699                                           agsaRoot_t           *agRoot,
4700                                           agsaIORequest_t      *agIORequest,
4701                                           bit32                agIOStatus,
4702                                           bit32                agIOInfoLen,
4703                                           void                 *agParam,
4704                                           bit32                agOtherInfo
4705                                          )
4706 {
4707   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
4708   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
4709   bit32                  intContext = osData->IntContext;
4710   tdIORequestBody_t      *tdIORequestBody;
4711   TI_DBG2(("itdssOpenCnxErrorItNexusLossNoDestHandler: start\n"));
4712 
4713   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4714 
4715   ostiInitiatorIOCompleted (
4716                             tiRoot,
4717                             tdIORequestBody->tiIORequest,
4718                             tiIOFailed,
4719                             tiDetailOtherError,
4720                             agNULL,
4721                             intContext
4722                             );
4723 
4724   return;
4725 }
4726 
4727 /*****************************************************************************
4728 *! \brief itdssOpenCnxErrorItNexusLossOpenCollideHandler
4729 *
4730 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
4731 *            layer with agIOStatus = OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE
4732 *
4733 *  \param  agRoot:            pointer to port instance
4734 *  \param  agIORequest:       pointer to I/O request
4735 *  \param  agIOStatus:        I/O status given by LL layer
4736 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
4737 *  \param  agParam            A Handle used to refer to the response frame or handle
4738 *                             of abort request
4739 *  \param  agOtherInfo        Residual count
4740 *  \return: None
4741 *
4742 *
4743 *****************************************************************************/
4744 osGLOBAL void
4745 itdssOpenCnxErrorItNexusLossOpenCollideHandler(
4746                                                agsaRoot_t           *agRoot,
4747                                                agsaIORequest_t      *agIORequest,
4748                                                bit32                agIOStatus,
4749                                                bit32                agIOInfoLen,
4750                                                void                 *agParam,
4751                                                bit32                agOtherInfo
4752                                               )
4753 {
4754   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
4755   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
4756   bit32                  intContext = osData->IntContext;
4757   tdIORequestBody_t      *tdIORequestBody;
4758   TI_DBG2(("itdssOpenCnxErrorItNexusLossOpenCollideHandler: start\n"));
4759 
4760   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4761 
4762   ostiInitiatorIOCompleted (
4763                             tiRoot,
4764                             tdIORequestBody->tiIORequest,
4765                             tiIOFailed,
4766                             tiDetailOtherError,
4767                             agNULL,
4768                             intContext
4769                             );
4770 
4771   return;
4772 }
4773 
4774 /*****************************************************************************
4775 *! \brief itdssOpenCnxErrorItNexusLossOpenPathwayBlockedHandler
4776 *
4777 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
4778 *            layer with agIOStatus = OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED
4779 *
4780 *  \param  agRoot:            pointer to port instance
4781 *  \param  agIORequest:       pointer to I/O request
4782 *  \param  agIOStatus:        I/O status given by LL layer
4783 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
4784 *  \param  agParam            A Handle used to refer to the response frame or handle
4785 *                             of abort request
4786 *  \param  agOtherInfo        Residual count
4787 *  \return: None
4788 *
4789 *
4790 *****************************************************************************/
4791 osGLOBAL void
4792 itdssOpenCnxErrorItNexusLossOpenPathwayBlockedHandler(
4793                                                       agsaRoot_t           *agRoot,
4794                                                       agsaIORequest_t      *agIORequest,
4795                                                       bit32                agIOStatus,
4796                                                       bit32                agIOInfoLen,
4797                                                       void                 *agParam,
4798                                                       bit32                agOtherInfo
4799                                                      )
4800 {
4801   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
4802   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
4803   bit32                  intContext = osData->IntContext;
4804   tdIORequestBody_t      *tdIORequestBody;
4805   TI_DBG2(("itdssOpenCnxErrorItNexusLossOpenPathwayBlockedHandler: start\n"));
4806 
4807   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4808 
4809   ostiInitiatorIOCompleted (
4810                             tiRoot,
4811                             tdIORequestBody->tiIORequest,
4812                             tiIOFailed,
4813                             tiDetailOtherError,
4814                             agNULL,
4815                             intContext
4816                             );
4817 
4818   return;
4819 }
4820 
4821 /*****************************************************************************
4822 *! \brief itdssEncryptionHandler
4823 *
4824 *  Purpose:  This function processes I/Os completed and returned by SAS lower
4825 *            layer with any encryption specific agIOStatus.
4826 *
4827 *  \param  agRoot:            pointer to port instance
4828 *  \param  agIORequest:       pointer to I/O request
4829 *  \param  agIOStatus:        I/O status given by LL layer
4830 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
4831 *  \param  agParam            A Handle used to refer to the response frame or handle
4832 *                             of abort request
4833 *  \return: None
4834 *
4835 *
4836 *****************************************************************************/
4837 osGLOBAL void
4838 itdssEncryptionHandler (
4839                        agsaRoot_t              *agRoot,
4840                        agsaIORequest_t         *agIORequest,
4841                        bit32                   agIOStatus,
4842                        bit32                   agIOInfoLen,
4843                        void                    *agParam,
4844                        bit32                   agOtherInfo
4845                        )
4846 {
4847   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
4848   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
4849   bit32                  intContext = osData->IntContext;
4850   bit32                  errorDetail = tiDetailOtherError;
4851   tdIORequestBody_t      *tdIORequestBody;
4852   TI_DBG1(("itdssEncryptionHandler: start\n"));
4853   TI_DBG1(("itdssEncryptionHandler: agIOStatus 0x%x\n", agIOStatus));
4854 
4855   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4856 
4857   switch (agIOStatus)
4858   {
4859   case OSSA_IO_XFR_ERROR_DEK_KEY_CACHE_MISS:
4860       TI_DBG1(("itdssEncryptionHandler: OSSA_IO_XFR_ERROR_DEK_KEY_CACHE_MISS\n"));
4861       errorDetail = tiDetailDekKeyCacheMiss;
4862       break;
4863   case OSSA_IO_XFR_ERROR_CIPHER_MODE_INVALID:
4864       TI_DBG1(("itdssEncryptionHandler: OSSA_IO_XFR_ERROR_CIPHER_MODE_INVALID\n"));
4865       errorDetail = tiDetailCipherModeInvalid;
4866       break;
4867   case OSSA_IO_XFR_ERROR_DEK_IV_MISMATCH:
4868       TI_DBG1(("itdssEncryptionHandler: OSSA_IO_XFR_ERROR_DEK_IV_MISMATCH\n"));
4869       errorDetail = tiDetailDekIVMismatch;
4870       break;
4871   case OSSA_IO_XFR_ERROR_DEK_RAM_INTERFACE_ERROR:
4872       TI_DBG1(("itdssEncryptionHandler: OSSA_IO_XFR_ERROR_DEK_RAM_INTERFACE_ERROR\n"));
4873       errorDetail = tiDetailDekRamInterfaceError;
4874       break;
4875   case OSSA_IO_XFR_ERROR_DEK_INDEX_OUT_OF_BOUNDS:
4876       TI_DBG1(("itdssEncryptionHandler: OSSA_IO_XFR_ERROR_DEK_INDEX_OUT_OF_BOUNDS\n"));
4877       errorDetail = tiDetailDekIndexOutofBounds;
4878       break;
4879   case OSSA_IO_XFR_ERROR_DEK_ILLEGAL_TABLE:
4880       TI_DBG1(("itdssEncryptionHandler: OSSA_IO_XFR_ERROR_DEK_ILLEGAL_TABLE\n"));
4881       errorDetail = tiDetailOtherError;
4882       break;
4883   default:
4884       TI_DBG1(("itdssEncryptionHandler: other error!!! 0x%x\n", agIOStatus));
4885       errorDetail = tiDetailOtherError;
4886       break;
4887   }
4888 
4889   ostiInitiatorIOCompleted (
4890                             tiRoot,
4891                             tdIORequestBody->tiIORequest,
4892                             tiIOEncryptError,
4893                             errorDetail,
4894                             agNULL,
4895                             intContext
4896                             );
4897   return;
4898 }
4899 
4900 /*****************************************************************************
4901 *! \brief itdssDifHandler
4902 *
4903 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
4904 *            layer with any DIF specific agIOStatus
4905 *
4906 *  \param  agRoot:            pointer to port instance
4907 *  \param  agIORequest:       pointer to I/O request
4908 *  \param  agIOStatus:        I/O status given by LL layer
4909 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
4910 *  \param  agParam            A Handle used to refer to the response frame or handle
4911 *                             of abort request
4912 *  \param  agOtherInfo        Residual count
4913 *  \return: None
4914 *
4915 *
4916 *****************************************************************************/
4917 osGLOBAL void
4918 itdssDifHandler(
4919                 agsaRoot_t           *agRoot,
4920                 agsaIORequest_t      *agIORequest,
4921                 bit32                agIOStatus,
4922                 bit32                agIOInfoLen,
4923                 void                 *agParam,
4924                 bit32                agOtherInfo
4925                )
4926 {
4927   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
4928   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
4929   bit32                  intContext = osData->IntContext;
4930   bit32                  errorDetail = tiDetailOtherError;
4931   tdIORequestBody_t      *tdIORequestBody;
4932 #ifdef  TD_DEBUG_ENABLE
4933   agsaDifDetails_t       *DifDetail;
4934 #endif
4935 
4936   TI_DBG1(("itdssDifHandler: start\n"));
4937   TI_DBG1(("itdssDifHandler: agIOStatus 0x%x\n", agIOStatus));
4938   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4939 #ifdef  TD_DEBUG_ENABLE
4940   DifDetail = (agsaDifDetails_t *)agParam;
4941 #endif
4942   switch (agIOStatus)
4943   {
4944   case OSSA_IO_XFR_ERROR_DIF_MISMATCH:
4945       errorDetail = tiDetailDifMismatch;
4946       TI_DBG1(("itdssDifHandler: OSSA_IO_XFR_ERROR_DIF_MISMATCH\n"));
4947       break;
4948   case OSSA_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH:
4949       errorDetail = tiDetailDifAppTagMismatch;
4950       TI_DBG1(("itdssDifHandler: OSSA_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH\n"));
4951       break;
4952   case OSSA_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH:
4953       errorDetail = tiDetailDifRefTagMismatch;
4954       TI_DBG1(("itdssDifHandler: OSSA_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH\n"));
4955       break;
4956   case OSSA_IO_XFR_ERROR_DIF_CRC_MISMATCH:
4957       errorDetail = tiDetailDifCrcMismatch;
4958       TI_DBG1(("itdssDifHandler: OSSA_IO_XFR_ERROR_DIF_CRC_MISMATCH\n"));
4959       break;
4960   default:
4961       errorDetail = tiDetailOtherError;
4962       TI_DBG1(("itdssDifHandler: other error!!! 0x%x\n", agIOStatus));
4963       break;
4964   }
4965   TI_DBG1(("itdssDifHandler: DIF detail UpperLBA 0x%08x LowerLBA 0x%08x\n", DifDetail->UpperLBA, DifDetail->LowerLBA));
4966   ostiInitiatorIOCompleted (
4967                             tiRoot,
4968                             tdIORequestBody->tiIORequest,
4969                             tiIODifError,
4970                             errorDetail,
4971                             agNULL,
4972                             intContext
4973                             );
4974   return;
4975 }
4976 
4977 /*****************************************************************************
4978 *! \brief itdssIOResourceUnavailableHandler
4979 *
4980 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
4981 *            layer with agIOStatus = OSSA_MPI_ERR_IO_RESOURCE_UNAVAILABLE
4982 *
4983 *  \param  agRoot:            pointer to port instance
4984 *  \param  agIORequest:       pointer to I/O request
4985 *  \param  agIOStatus:        I/O status given by LL layer
4986 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
4987 *  \param  agParam            A Handle used to refer to the response frame or handle
4988 *                             of abort request
4989 *  \param  agOtherInfo        Residual count
4990 *  \return: None
4991 *
4992 *
4993 *****************************************************************************/
4994 osGLOBAL void
4995 itdssIOResourceUnavailableHandler(
4996                                   agsaRoot_t              *agRoot,
4997                                   agsaIORequest_t         *agIORequest,
4998                                   bit32                   agIOStatus,
4999                                   bit32                   agIOInfoLen,
5000                                   void                    *agParam,
5001                                   bit32                   agOtherInfo
5002                                  )
5003 {
5004   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
5005   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
5006   bit32                  intContext = osData->IntContext;
5007   tdIORequestBody_t      *tdIORequestBody;
5008   TI_DBG2(("itdssIOResourceUnavailableHandler: start\n"));
5009   TI_DBG2(("itdssIOResourceUnavailableHandler: agIOStatus 0x%x\n", agIOStatus));
5010 
5011   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
5012 
5013   ostiInitiatorIOCompleted (
5014                             tiRoot,
5015                             tdIORequestBody->tiIORequest,
5016                             tiIOFailed,
5017                             tiDetailBusy,
5018                             agNULL,
5019                             intContext
5020                             );
5021   return;
5022 }
5023 /*****************************************************************************
5024 *! \brief itdssIORQEBusyFullHandler
5025 *
5026 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
5027 *            layer with agIOStatus = OSSA_MPI_IO_RQE_BUSY_FULL
5028 *
5029 *  \param  agRoot:            pointer to port instance
5030 *  \param  agIORequest:       pointer to I/O request
5031 *  \param  agIOStatus:        I/O status given by LL layer
5032 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
5033 *  \param  agParam            A Handle used to refer to the response frame or handle
5034 *                             of abort request
5035 *  \param  agOtherInfo        Residual count
5036 *  \return: None
5037 *
5038 *
5039 *****************************************************************************/
5040 osGLOBAL void
5041 itdssIORQEBusyFullHandler(
5042                                   agsaRoot_t              *agRoot,
5043                                   agsaIORequest_t         *agIORequest,
5044                                   bit32                   agIOStatus,
5045                                   bit32                   agIOInfoLen,
5046                                   void                    *agParam,
5047                                   bit32                   agOtherInfo
5048                                  )
5049 {
5050   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
5051   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
5052   bit32                  intContext = osData->IntContext;
5053   tdIORequestBody_t      *tdIORequestBody;
5054   TI_DBG2(("itdssIORQEBusyFullHandler: start\n"));
5055   TI_DBG2(("itdssIORQEBusyFullHandler: agIOStatus 0x%x\n", agIOStatus));
5056 
5057   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
5058 
5059   ostiInitiatorIOCompleted (
5060                             tiRoot,
5061                             tdIORequestBody->tiIORequest,
5062                             tiIOFailed,
5063                             tiDetailBusy,
5064                             agNULL,
5065                             intContext
5066                             );
5067   return;
5068 }
5069 
5070 /*****************************************************************************
5071 *! \brief itdssXferErrorInvalidSSPRspFrameHandler
5072 *
5073 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
5074 *            layer with agIOStatus = OSSA_IO_XFR_ERROR_INVALID_SSP_RSP_FRAME
5075 *
5076 *  \param  agRoot:            pointer to port instance
5077 *  \param  agIORequest:       pointer to I/O request
5078 *  \param  agIOStatus:        I/O status given by LL layer
5079 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
5080 *  \param  agParam            A Handle used to refer to the response frame or handle
5081 *                             of abort request
5082 *  \param  agOtherInfo        Residual count
5083 *  \return: None
5084 *
5085 *
5086 *****************************************************************************/
5087 osGLOBAL void
5088 itdssXferErrorInvalidSSPRspFrameHandler(
5089                                   agsaRoot_t              *agRoot,
5090                                   agsaIORequest_t         *agIORequest,
5091                                   bit32                   agIOStatus,
5092                                   bit32                   agIOInfoLen,
5093                                   void                    *agParam,
5094                                   bit32                   agOtherInfo
5095                                  )
5096 {
5097   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
5098   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
5099   bit32                  intContext = osData->IntContext;
5100   tdIORequestBody_t      *tdIORequestBody;
5101   TI_DBG2(("itdssXferErrorInvalidSSPRspFrameHandler: start\n"));
5102   TI_DBG2(("itdssXferErrorInvalidSSPRspFrameHandler: agIOStatus 0x%x\n", agIOStatus));
5103 
5104   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
5105 
5106   ostiInitiatorIOCompleted (
5107                             tiRoot,
5108                             tdIORequestBody->tiIORequest,
5109                             tiIOFailed,
5110                             tiDetailOtherError,
5111                             agNULL,
5112                             intContext
5113                             );
5114   return;
5115 }
5116 
5117 /*****************************************************************************
5118 *! \brief itdssXferErrorEOBDataOverrunHandler
5119 *
5120 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
5121 *            layer with agIOStatus = OSSA_IO_XFER_ERR_EOB_DATA_OVERRUN
5122 *
5123 *  \param  agRoot:            pointer to port instance
5124 *  \param  agIORequest:       pointer to I/O request
5125 *  \param  agIOStatus:        I/O status given by LL layer
5126 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
5127 *  \param  agParam            A Handle used to refer to the response frame or handle
5128 *                             of abort request
5129 *  \param  agOtherInfo        Residual count
5130 *  \return: None
5131 *
5132 *
5133 *****************************************************************************/
5134 osGLOBAL void
5135 itdssXferErrorEOBDataOverrunHandler(
5136                                   agsaRoot_t              *agRoot,
5137                                   agsaIORequest_t         *agIORequest,
5138                                   bit32                   agIOStatus,
5139                                   bit32                   agIOInfoLen,
5140                                   void                    *agParam,
5141                                   bit32                   agOtherInfo
5142                                  )
5143 {
5144   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
5145   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
5146   bit32                  intContext = osData->IntContext;
5147   tdIORequestBody_t      *tdIORequestBody;
5148   TI_DBG2(("itdssXferErrorEOBDataOverrunHandler: start\n"));
5149   TI_DBG2(("itdssXferErrorEOBDataOverrunHandler: agIOStatus 0x%x\n", agIOStatus));
5150 
5151   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
5152 
5153   ostiInitiatorIOCompleted (
5154                             tiRoot,
5155                             tdIORequestBody->tiIORequest,
5156                             tiIOFailed,
5157                             tiDetailOtherError,
5158                             agNULL,
5159                             intContext
5160                             );
5161   return;
5162 }
5163 
5164 /*****************************************************************************
5165 *! \brief itdssOpenCnxErrorOpenPreemptedHandler
5166 *
5167 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
5168 *            layer with agIOStatus = OSSA_IO_OPEN_CNX_ERROR_OPEN_PREEMPTED
5169 *
5170 *  \param  agRoot:            pointer to port instance
5171 *  \param  agIORequest:       pointer to I/O request
5172 *  \param  agIOStatus:        I/O status given by LL layer
5173 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
5174 *  \param  agParam            A Handle used to refer to the response frame or handle
5175 *                             of abort request
5176 *  \param  agOtherInfo        Residual count
5177 *  \return: None
5178 *
5179 *
5180 *****************************************************************************/
5181 osGLOBAL void
5182 itdssOpenCnxErrorOpenPreemptedHandler(
5183                                   agsaRoot_t              *agRoot,
5184                                   agsaIORequest_t         *agIORequest,
5185                                   bit32                   agIOStatus,
5186                                   bit32                   agIOInfoLen,
5187                                   void                    *agParam,
5188                                   bit32                   agOtherInfo
5189                                  )
5190 {
5191   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
5192   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
5193   bit32                  intContext = osData->IntContext;
5194   tdIORequestBody_t      *tdIORequestBody;
5195   TI_DBG2(("itdssOpenCnxErrorOpenPreemptedHandler: start\n"));
5196   TI_DBG2(("itdssOpenCnxErrorOpenPreemptedHandler: agIOStatus 0x%x\n", agIOStatus));
5197 
5198   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
5199 
5200   ostiInitiatorIOCompleted (
5201                             tiRoot,
5202                             tdIORequestBody->tiIORequest,
5203                             tiIOFailed,
5204                             tiDetailOtherError,
5205                             agNULL,
5206                             intContext
5207                             );
5208   return;
5209 }
5210 
5211 /* default */
5212 /*****************************************************************************
5213 *! \brief itdssIODefaultHandler
5214 *
5215 *  Purpose:  This function processes I/Os completed and returned by SAS/SATA lower
5216 *            layer with agIOStatus = unspecified
5217 *
5218 *  \param  agRoot:            pointer to port instance
5219 *  \param  agIORequest:       pointer to I/O request
5220 *  \param  agIOStatus:        I/O status given by LL layer
5221 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
5222 *  \param  agParam            A Handle used to refer to the response frame or handle
5223 *                             of abort request
5224 *  \param  agOtherInfo        Residual count
5225 *  \return: None
5226 *
5227 *
5228 *****************************************************************************/
5229 osGLOBAL void
5230 itdssIODefaultHandler (
5231                        agsaRoot_t              *agRoot,
5232                        agsaIORequest_t         *agIORequest,
5233                        bit32                   agIOStatus,
5234                        bit32                   agIOInfoLen,
5235                        void                    *agParam,
5236                        bit32                   agOtherInfo
5237                        )
5238 {
5239   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
5240   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
5241   bit32                  intContext = osData->IntContext;
5242   tdIORequestBody_t      *tdIORequestBody;
5243   TI_DBG2(("itdssIODefaultHandler: start\n"));
5244   TI_DBG2(("itdssIODefaultHandler: agIOStatus 0x%x\n", agIOStatus));
5245 
5246   tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
5247 
5248   ostiInitiatorIOCompleted (
5249                             tiRoot,
5250                             tdIORequestBody->tiIORequest,
5251                             tiIOFailed,
5252                             tiDetailOtherError,
5253                             agNULL,
5254                             intContext
5255                             );
5256   return;
5257 }
5258 
5259 /*****************************************************************************
5260 *! \brief itdssIOForDebugging1Completed
5261 *
5262 *  Purpose:  This function is only for debugging. This function should NOT be
5263 *            called.
5264 *
5265 *  \param  agRoot:            pointer to port instance
5266 *  \param  agIORequest:       pointer to I/O request
5267 *  \param  agIOStatus:        I/O status given by LL layer
5268 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
5269 *  \param  agParam            A Handle used to refer to the response frame or handle
5270 *                             of abort request
5271 *  \param  agOtherInfo        Residual count
5272 *  \return: None
5273 *
5274 *
5275 *****************************************************************************/
5276 osGLOBAL void
5277 itdssIOForDebugging1Completed(
5278                  agsaRoot_t             *agRoot,
5279                  agsaIORequest_t        *agIORequest,
5280                  bit32                  agIOStatus,
5281                  bit32                  agIOInfoLen,
5282                  void                   *agParam,
5283                  bit32                  agOtherInfo
5284                  )
5285 {
5286   TI_DBG1(("itdssIOForDebugging1Completed: start, error!!! can't be called. \n"));
5287 }
5288 
5289 /*****************************************************************************
5290 *! \brief itdssIOForDebugging2Completed
5291 *
5292 *  Purpose:  This function is only for debugging. This function should NOT be
5293 *            called.
5294 *
5295 *  \param  agRoot:            pointer to port instance
5296 *  \param  agIORequest:       pointer to I/O request
5297 *  \param  agIOStatus:        I/O status given by LL layer
5298 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
5299 *  \param  agParam            A Handle used to refer to the response frame or handle
5300 *                             of abort request
5301 *  \param  agOtherInfo        Residual count
5302 *  \return: None
5303 *
5304 *
5305 *****************************************************************************/
5306 osGLOBAL void
5307 itdssIOForDebugging2Completed(
5308                  agsaRoot_t             *agRoot,
5309                  agsaIORequest_t        *agIORequest,
5310                  bit32                  agIOStatus,
5311                  bit32                  agIOInfoLen,
5312                  void                   *agParam,
5313                  bit32                  agOtherInfo
5314                  )
5315 {
5316   TI_DBG1(("itdssIOForDebugging2Completed: start, error!!! can't be called.  \n"));
5317 }
5318 
5319 /*****************************************************************************
5320 *! \brief itdssIOForDebugging3Completed
5321 *
5322 *  Purpose:  This function is only for debugging. This function should NOT be
5323 *            called.
5324 *
5325 *  \param  agRoot:            pointer to port instance
5326 *  \param  agIORequest:       pointer to I/O request
5327 *  \param  agIOStatus:        I/O status given by LL layer
5328 *  \param  agIOInfoLen:       lenth of complete SAS RESP frame
5329 *  \param  agParam            A Handle used to refer to the response frame or handle
5330 *                             of abort request
5331 *  \param  agOtherInfo        Residual count
5332 *  \return: None
5333 *
5334 *
5335 *****************************************************************************/
5336 osGLOBAL void
5337 itdssIOForDebugging3Completed(
5338                  agsaRoot_t             *agRoot,
5339                  agsaIORequest_t        *agIORequest,
5340                  bit32                  agIOStatus,
5341                  bit32                  agIOInfoLen,
5342                  void                   *agParam,
5343                  bit32                  agOtherInfo
5344                  )
5345 {
5346   TI_DBG1(("itdssIOForDebugging3Completed: start, error!!! can't be called.  \n"));
5347 }
5348 
5349 
5350