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