xref: /freebsd/sys/dev/pms/RefTisa/tisa/sassata/common/ossacmnapi.c (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1 /*******************************************************************************
2 *Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3 *
4 *Redistribution and use in source and binary forms, with or without modification, are permitted provided
5 *that the following conditions are met:
6 *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7 *following disclaimer.
8 *2. Redistributions in binary form must reproduce the above copyright notice,
9 *this list of conditions and the following disclaimer in the documentation and/or other materials provided
10 *with the distribution.
11 *
12 *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 *WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 *FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16 *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18 *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19 *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20 
21 ********************************************************************************/
22 /*******************************************************************************/
23 /** \file
24  *
25  *
26  *
27  * This file contains CB functions used by lower layer in SAS/SATA TD layer
28  *
29  */
30 #include <sys/cdefs.h>
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 #ifdef ECHO_TESTING
78 /* temporary to test saEchoCommand() */
79 extern bit8 gEcho;
80 #endif
81 
82 #if defined(SALLSDK_DEBUG)
83 extern bit32 gLLDebugLevel;
84 #endif
85 
86 
87 #include <dev/pms/RefTisa/sallsdk/spc/mpidebug.h>
88 
89 #ifdef SA_ENABLE_TRACE_FUNCTIONS
90 
91 #ifdef siTraceFileID
92 #undef siTraceFileID
93 #endif
94 #define siTraceFileID 'R'
95 #endif
96 /*
97   functions that are common to SAS and SATA
98 */
99 
100 FORCEINLINE
101 void ossaCacheInvalidate(
102                          agsaRoot_t  *agRoot,
103                          void        *osMemHandle,
104                          void        *virtPtr,
105                          bit32       length
106                          )
107 {
108   tdsaRootOsData_t     *osData = (tdsaRootOsData_t *)agRoot->osData;
109   tiRoot_t             *tiRoot = (tiRoot_t *)osData->tiRoot;
110 
111   TI_DBG6(("ossaCacheInvalidate: start\n"));
112   ostiCacheInvalidate(tiRoot, osMemHandle, virtPtr, length);
113   return;
114 }
115 
116 FORCEINLINE
117 void ossaCacheFlush(
118                agsaRoot_t  *agRoot,
119                void        *osMemHandle,
120                void        *virtPtr,
121                bit32       length
122                )
123 {
124   tdsaRootOsData_t     *osData = (tdsaRootOsData_t *)agRoot->osData;
125   tiRoot_t             *tiRoot = (tiRoot_t *)osData->tiRoot;
126 
127   TI_DBG6(("ossaCacheFlush: start\n"));
128   ostiCacheFlush(tiRoot, osMemHandle, virtPtr, length);
129   return;
130 }
131 
132 FORCEINLINE
133 void ossaCachePreFlush(
134                   agsaRoot_t  *agRoot,
135                   void        *osMemHandle,
136                   void        *virtPtr,
137                   bit32       length
138                    )
139 
140 {
141   tdsaRootOsData_t     *osData = (tdsaRootOsData_t *)agRoot->osData;
142   tiRoot_t             *tiRoot = (tiRoot_t *)osData->tiRoot;
143 
144   TI_DBG6(("ossaCachePreFlush: start\n"));
145   ostiCachePreFlush(tiRoot, osMemHandle, virtPtr, length);
146   return;
147 }
148 
149 /*****************************************************************************
150 *! \brief ossaDeviceHandleAccept
151 *
152 *  Purpose:  This function is called by lower layer to inform TD layer of
153 *            a new SAS device arrival. Used only at the target
154 *
155 *
156 *  \param   agRoot         Pointer to chip/driver Instance.
157 *  \param   agDevHandle    Pointer to the device handle of the device
158 *  \param   agDevInfo      Pointer to the device info structure
159 *  \param   agPortContext  Pointer to a port context
160 *
161 *  \return:
162 *          OSSA_RC_REJECT  A device is accpeted
163 *          OSSA_RC_ACCEPT  A device is rejected
164 *
165 *  \note -  For details, refer to SAS/SATA Low-Level API Specification
166 *
167 *****************************************************************************/
168 osGLOBAL bit32 ossaDeviceHandleAccept(
169                        agsaRoot_t          *agRoot,
170                        agsaDevHandle_t     *agDevHandle,
171                        agsaSASDeviceInfo_t *agDevInfo,
172                        agsaPortContext_t   *agPortContext,
173                        bit32               *hostAssignedDeviceId
174                        )
175 {
176 #ifdef TARGET_DRIVER
177   tdsaRootOsData_t     *osData = (tdsaRootOsData_t *)agRoot->osData;
178   tiRoot_t             *tiRoot = (tiRoot_t *)osData->tiRoot;
179   tdsaRoot_t           *tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
180   tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
181 
182   tdsaPortContext_t    *onePortContext = agNULL;
183   tiPortalContext_t    *tiPortalContext = agNULL;
184   tdsaDeviceData_t     *oneDeviceData = agNULL;
185   tiDeviceHandle_t     *tiDeviceHandle = agNULL;
186   tdsaSASSubID_t       agSASSubID;
187   bit32                option;
188   bit32                param;
189   /*
190     at target only
191     by default TD layer accpets all devices
192   */
193   /*
194     at this point,
195     by LINK_UP event tdsaPortContext should have been created
196   */
197   smTraceFuncEnter(hpDBG_VERY_LOUD, "Y0");
198   TI_DBG1(("ossaDeviceHandleAccept: start hostAssignedDeviceId 0x%X\n",*hostAssignedDeviceId));
199 
200 
201   if (agPortContext == agNULL)
202   {
203     TI_DBG1(("ossaDeviceHandleAccept: NULL agsaPortContext; wrong\n"));
204     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Y0");
205     return OSSA_RC_REJECT;
206   }
207 
208 
209   onePortContext = (tdsaPortContext_t *)agPortContext->osData;
210 
211   if (onePortContext == agNULL)
212   {
213     TI_DBG1(("ossaDeviceHandleAccept: NULL oneportcontext; wrong\n"));
214     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "Y0");
215     return OSSA_RC_REJECT;
216   }
217 
218   tiPortalContext = (tiPortalContext_t *)onePortContext->tiPortalContext;
219 
220   if (tiPortalContext == agNULL)
221   {
222     TI_DBG1(("ossaDeviceHandleAccept: NULL tiPortalContext; wrong\n"));
223     smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "Y0");
224     return OSSA_RC_REJECT;
225   }
226 
227   /*
228     add the device to device list
229     cf) OSSA_DISCOVER_FOUND_DEVICE
230   */
231   TI_DBG4(("ossaDeviceHandleAccept: sasAddressHi 0x%08x\n", SA_DEVINFO_GET_SAS_ADDRESSHI(&agDevInfo->commonDevInfo)));
232   TI_DBG4(("ossaDeviceHandleAccept: sasAddressLo 0x%08x\n", SA_DEVINFO_GET_SAS_ADDRESSLO(&agDevInfo->commonDevInfo)));
233   TI_DBG4(("ossaDeviceHandleAccept: device type  0x%x\n", DEVINFO_GET_DEVICETTYPE(&agDevInfo->commonDevInfo)));
234   TI_DBG4(("ossaDeviceHandleAccept: phys %d\n", agDevInfo->numOfPhys));
235   TI_DBG4(("ossaDeviceHandleAccept: pid %d\n", onePortContext->id));
236 
237   if (DEVINFO_GET_DEVICETTYPE(&agDevInfo->commonDevInfo) == SAS_END_DEVICE)
238   {
239     TI_DBG4(("ossaDeviceHandleAccept: SAS_END_DEVICE\n"));
240   }
241   else if (DEVINFO_GET_DEVICETTYPE(&agDevInfo->commonDevInfo) == SAS_EDGE_EXPANDER_DEVICE)
242   {
243     TI_DBG4(("ossaDeviceHandleAccept: SAS_EDGE_EXPANDER_DEVICE\n"));
244   }
245   else /* SAS_FANOUT_EXPANDER_DEVICE */
246   {
247     TI_DBG4(("ossaDeviceHandleAccept: SAS_FANOUT_EXPANDER_DEVICE\n"));
248   }
249   agSASSubID.sasAddressHi = SA_DEVINFO_GET_SAS_ADDRESSHI(&agDevInfo->commonDevInfo);
250   agSASSubID.sasAddressLo = SA_DEVINFO_GET_SAS_ADDRESSLO(&agDevInfo->commonDevInfo);
251   agSASSubID.initiator_ssp_stp_smp = agDevInfo->initiator_ssp_stp_smp;
252   agSASSubID.target_ssp_stp_smp = agDevInfo->target_ssp_stp_smp;
253 
254 
255   tdssAddSASToSharedcontext(
256                             onePortContext,
257                             agRoot,
258                             agDevHandle,
259                             &agSASSubID,
260                             agTRUE,
261                             0xFF,
262                             TD_OPERATION_TARGET
263                             );
264 
265   /* at this point devicedata for new device exists */
266   oneDeviceData = (tdsaDeviceData_t *)agDevHandle->osData;
267 
268   if (oneDeviceData == agNULL)
269   {
270     TI_DBG1(("ossaDeviceHandleAccept: NULL oneDeviceData; wrong\n"));
271     return OSSA_RC_REJECT;
272   }
273 
274   oneDeviceData->registered = agTRUE;
275 
276   tiDeviceHandle = &(oneDeviceData->tiDeviceHandle);
277 
278   if (tiDeviceHandle == agNULL)
279   {
280     TI_DBG1(("ossaDeviceHandleAccept: NULL tiDeviceHandle; wrong\n"));
281     smTraceFuncExit(hpDBG_VERY_LOUD, 'd', "Y0");
282     return OSSA_RC_REJECT;
283   }
284 
285   /* setting MCN in agsaDeviceInfo_t*/
286   agDevInfo->commonDevInfo.flag = agDevInfo->commonDevInfo.flag | (tdsaAllShared->MCN << 16);
287   /* increment RegisteredDevNums */
288   onePortContext->RegisteredDevNums++;
289 
290   *hostAssignedDeviceId |= 0xBEEF0000;
291 
292   TI_DBG1(("ossaDeviceHandleAccept: Now hostAssignedDeviceId 0x%X\n", *hostAssignedDeviceId));
293 
294 
295   /* no login in SAS */
296   /*
297     osGLOBAL bit32 ostiTargetEvent (
298                         tiRoot_t          *tiRoot,
299                         tiPortalContext_t *portalContext,
300                         tiDeviceHandle_t  *tiDeviceHandle,
301                         tiTgtEventType_t  eventType,
302                         bit32             eventStatus,
303                         void              *parm
304                         );
305   */
306 
307   ostiTargetEvent(
308                   tiRoot,
309                   tiPortalContext,
310                   tiDeviceHandle,
311                   tiTgtEventTypeDeviceChange,
312                   tiDeviceArrival,
313                   agNULL
314                   );
315   /* set MCN and initiator role bit using saSetDeviceInfo */
316   option = 24; /* setting MCN and initiator role 1 1000b*/
317   param = (1 << 18) | (tdsaAllShared->MCN << 24);
318   TI_DBG1(("ossaDeviceHandleAccept: option 0x%x param 0x%x MCN 0x%x\n", option, param, tdsaAllShared->MCN));
319   saSetDeviceInfo(agRoot, agNULL, 0, agDevHandle, option, param, ossaSetDeviceInfoCB);
320   smTraceFuncExit(hpDBG_VERY_LOUD, 'e', "Y0");
321   return OSSA_RC_ACCEPT;
322 #endif
323 
324 #ifdef INITIATOR_DRIVER
325   /* this function is not used in case of Initiator */
326   return OSSA_RC_ACCEPT;
327 #endif
328 }
329 
330 #ifdef INITIATOR_DRIVER
331 /*****************************************************************************
332 *! \brief ossaDiscoverSasCB
333 *
334 *  Purpose:  This function is called by lower layer to inform TD layer of
335 *            SAS discovery results
336 *
337 *
338 *  \param   agRoot         Pointer to chip/driver Instance.
339 *  \param   agPortContext  Pointer to the port context of TD and Lower layer
340 *  \param   event          event type
341 *  \param   pParm1         Pointer to data associated with event
342 *  \param   pParm2         Pointer to data associated with event
343 *
344 *  \return: none
345 *
346 *  \note -  For details, refer to SAS/SATA Low-Level API Specification
347 *
348 *****************************************************************************/
349 osGLOBAL void ossaDiscoverSasCB(agsaRoot_t        *agRoot,
350                   agsaPortContext_t *agPortContext,
351                   bit32             event,
352                   void              *pParm1,
353                   void              *pParm2
354                   )
355 {
356   tdsaRootOsData_t     *osData = (tdsaRootOsData_t *)agRoot->osData;
357   tiRoot_t             *tiRoot = (tiRoot_t *)osData->tiRoot;
358   tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)osData->tdsaAllShared;
359 
360   tdsaPortContext_t    *onePortContext = agNULL;
361   tdsaDeviceData_t     *oneDeviceData = agNULL;
362 
363   agsaDevHandle_t      *agDevHandle = agNULL;
364   agsaSASDeviceInfo_t  *agDeviceInfo = agNULL;
365   tiPortalContext_t    *tiPortalContext = agNULL;
366   tdList_t             *DeviceListList;
367   tdsaSASSubID_t       agSASSubID;
368 
369   smTraceFuncEnter(hpDBG_VERY_LOUD,"Y1");
370   TI_DBG2(("ossaDiscoverSasCB: start\n"));
371 
372   if (agPortContext == agNULL)
373   {
374     TI_DBG1(("ossaDiscoverSasCB: NULL agsaPortContext; wrong\n"));
375     return;
376   }
377 
378   onePortContext = (tdsaPortContext_t *)agPortContext->osData;
379   tiPortalContext = (tiPortalContext_t *)onePortContext->tiPortalContext;
380 
381   switch ( event )
382   {
383   case OSSA_DISCOVER_STARTED:
384   {
385     TI_DBG3(("ossaDiscoverSasCB: STARTED pid %d\n", onePortContext->id));
386     /*
387       invalidate all devices in current device list
388     */
389     DeviceListList = tdsaAllShared->MainDeviceList.flink;
390     while (DeviceListList != &(tdsaAllShared->MainDeviceList))
391     {
392       oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
393       TI_DBG3(("ossaDiscoverSasCB: loop did %d\n", oneDeviceData->id));
394       TI_DBG3(("ossaDiscoverSasCB: loop sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
395       TI_DBG6(("ossaDiscoverSasCB: loop sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
396       if (oneDeviceData->tdPortContext == onePortContext)
397       {
398         TI_DBG3(("ossaDiscoverSasCB: did %d is invalidated \n", oneDeviceData->id));
399         /* temporary solution: only for sata direct attached */
400       }
401       DeviceListList = DeviceListList->flink;
402     }
403     onePortContext->DiscoveryState = ITD_DSTATE_STARTED;
404     break;
405   }
406 
407   case OSSA_DISCOVER_FOUND_DEVICE:
408   {
409     TI_DBG4(("ossaDiscoverSasCB: $$$$$ FOUND_DEVICE pid %d\n", onePortContext->id));
410     agDevHandle = (agsaDevHandle_t *)pParm1;
411     agDeviceInfo = (agsaSASDeviceInfo_t *)pParm2;
412     TI_DBG5(("ossaDiscoverSasCB: sasAddressHi 0x%08x\n", SA_DEVINFO_GET_SAS_ADDRESSHI(&agDeviceInfo->commonDevInfo)));
413     TI_DBG5(("ossaDiscoverSasCB: sasAddressLo 0x%08x\n", SA_DEVINFO_GET_SAS_ADDRESSLO(&agDeviceInfo->commonDevInfo)));
414     TI_DBG5(("ossaDiscoverSasCB: device type  0x%x\n", DEVINFO_GET_DEVICETTYPE(&agDeviceInfo->commonDevInfo)));
415 
416     TI_DBG6(("ossaDiscoverSasCB: phys %d\n", agDeviceInfo->numOfPhys));
417     TI_DBG4(("ossaDiscoverSasCB: pid %d\n", onePortContext->id));
418 
419 
420     /* Add only target devices; do not add expander device */
421     if (DEVINFO_GET_DEVICETTYPE(&agDeviceInfo->commonDevInfo) == SAS_END_DEVICE)
422     {
423       agSASSubID.sasAddressHi = SA_DEVINFO_GET_SAS_ADDRESSHI(&agDeviceInfo->commonDevInfo);
424       agSASSubID.sasAddressLo = SA_DEVINFO_GET_SAS_ADDRESSLO(&agDeviceInfo->commonDevInfo);
425       agSASSubID.initiator_ssp_stp_smp = agDeviceInfo->initiator_ssp_stp_smp;
426       agSASSubID.target_ssp_stp_smp = agDeviceInfo->target_ssp_stp_smp;
427 
428       TI_DBG2(("ossaDiscoverSasCB: adding ....\n"));
429 
430       tdssAddSASToSharedcontext(
431                                 onePortContext,
432                                 agRoot,
433                                 agDevHandle,
434                                 &agSASSubID,
435                                 agTRUE,
436                                 agDeviceInfo->phyIdentifier,
437                                 TD_OPERATION_INITIATOR
438                                 );
439       ostiInitiatorEvent(
440                          tiRoot,
441                          tiPortalContext,
442                          agNULL,
443                          tiIntrEventTypeDeviceChange,
444                          tiDeviceArrival,
445                          agNULL
446                          );
447     }
448     else
449     {
450       TI_DBG5(("ossaDiscoverSasCB: $$$$$ not end device. not adding....\n"));
451     }
452 
453 
454     break;
455   }
456 
457   case OSSA_DISCOVER_REMOVED_DEVICE:
458   {
459     TI_DBG3(("ossaDiscoverSasCB: REMOVED_DEVICE\n"));
460     agDevHandle = (agsaDevHandle_t *)pParm1;
461     agDeviceInfo = (agsaSASDeviceInfo_t *)pParm2;
462     oneDeviceData = (tdsaDeviceData_t *) agDevHandle->osData;
463 
464     TI_DBG6(("ossaDiscoverSasCB: sasAddressHi 0x%08x\n",
465              SA_DEVINFO_GET_SAS_ADDRESSHI(&agDeviceInfo->commonDevInfo)));
466     TI_DBG6(("ossaDiscoverSasCB: sasAddressLo 0x%08x\n",
467              SA_DEVINFO_GET_SAS_ADDRESSLO(&agDeviceInfo->commonDevInfo)));
468     TI_DBG6(("ossaDiscoverSasCB: phys %d\n", agDeviceInfo->numOfPhys));
469     TI_DBG6(("ossaDiscoverSasCB: onePortContext->id %d\n", onePortContext->id));
470 
471     if (oneDeviceData == agNULL)
472     {
473       TI_DBG1(("ossaDiscoverSasCB: Wrong. DevHandle->osData is NULL but is being removed\n"));
474     }
475     else
476     {
477       tdssRemoveSASFromSharedcontext(onePortContext,
478                                      oneDeviceData,
479                                      agRoot);
480       agDevHandle->osData = agNULL;
481       ostiInitiatorEvent(
482                          tiRoot,
483                          tiPortalContext,
484                          agNULL,
485                          tiIntrEventTypeDeviceChange,
486                          tiDeviceRemoval,
487                          agNULL
488                          );
489     }
490 
491     break;
492   }
493   case OSSA_DISCOVER_COMPLETE:
494   {
495     TI_DBG2(("ossaDiscoverSasCB: SAS COMPLETE pid %d\n", onePortContext->id));
496     /*
497       note:
498       SAS discovery must be called before SATA discovery
499       "onePortContext->DiscoveryState = ITD_DSTATE_COMPLETED" is
500       in ossaDiscoverSataCB not in ossaDiscoverSasCB when SATA_ENABLE
501     */
502 #ifndef SATA_ENABLE
503     onePortContext->DiscoveryState = ITD_DSTATE_COMPLETED;
504     TI_DBG6(("ossaDiscoverSasCB: COMPLETE pid %d\n", onePortContext->id));
505 #endif
506 
507 #ifdef SATA_ENABLE
508     TI_DBG2(("ossaDiscoverSasCB: calling SATA discovery\n"));
509 
510     /* Continue with SATA discovery */
511     saDiscover(agRoot, agPortContext, AG_SA_DISCOVERY_TYPE_SATA,
512                onePortContext->discoveryOptions);
513 
514 #else /* SATA not enable */
515 
516 #ifdef TD_INTERNAL_DEBUG /* for debugging */
517     /* dump device list */
518     DeviceListList = tdsaAllShared->MainPortContextList.flink;
519 
520     while (DeviceListList != &(tdsaAllShared->MainPortContextList))
521     {
522       oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
523       TI_DBG2(("ossaDiscoverSasCB: did %d valid %d\n", oneDeviceData->id, oneDeviceData->valid));
524       TI_DBG2(("ossaDiscoverSasCB: device AddrHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
525       TI_DBG2(("ossaDiscoverSasCB: device AddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
526       DeviceListList = DeviceListList->flink;
527     }
528 #endif
529 
530     /* letting OS layer know discovery has been successfully complete */
531     ostiInitiatorEvent(
532                        tiRoot,
533                        tiPortalContext,
534                        agNULL,
535                        tiIntrEventTypeDiscovery,
536                        tiDiscOK,
537                        agNULL
538                        );
539 #endif  /* SATA_ENABLE */
540 
541     break;
542   }
543   case OSSA_DISCOVER_ABORT:
544   {
545     TI_DBG3(("ossaDiscoverSasCB: ABORT\n"));
546     /* letting OS layer know discovery has not been successfully complete */
547     ostiInitiatorEvent(
548                        tiRoot,
549                        tiPortalContext,
550                        agNULL,
551                        tiIntrEventTypeDiscovery,
552                        tiDiscFailed,
553                        agNULL
554                        );
555     break;
556   }
557   case OSSA_DISCOVER_ABORT_ERROR_1:
558   {
559     TI_DBG3(("ossaDiscoverSasCB: ERROR 1\n"));
560     /* letting OS layer know discovery has not been successfully complete */
561     ostiInitiatorEvent(
562                        tiRoot,
563                        tiPortalContext,
564                        agNULL,
565                        tiIntrEventTypeDiscovery,
566                        tiDiscFailed,
567                        agNULL
568                        );
569     break;
570   }
571 
572   case OSSA_DISCOVER_ABORT_ERROR_2:
573   {
574     TI_DBG3(("ossaDiscoverSasCB: ERROR 2\n"));
575     /* letting OS layer know discovery has not been successfully complete */
576     ostiInitiatorEvent(
577                        tiRoot,
578                        tiPortalContext,
579                        agNULL,
580                        tiIntrEventTypeDiscovery,
581                        tiDiscFailed,
582                        agNULL
583                        );
584     break;
585   }
586 
587   case OSSA_DISCOVER_ABORT_ERROR_3:
588   {
589     TI_DBG3(("ossaDiscoverSasCB: ERROR 3\n"));
590     /* letting OS layer know discovery has not been successfully complete */
591     ostiInitiatorEvent(
592                        tiRoot,
593                        tiPortalContext,
594                        agNULL,
595                        tiIntrEventTypeDiscovery,
596                        tiDiscFailed,
597                        agNULL
598                        );
599     break;
600   }
601   case OSSA_DISCOVER_ABORT_ERROR_4:
602   {
603     TI_DBG3(("ossaDiscoverSasCB: ERROR 4\n"));
604     /* letting OS layer know discovery has not been successfully complete */
605     ostiInitiatorEvent(
606                        tiRoot,
607                        tiPortalContext,
608                        agNULL,
609                        tiIntrEventTypeDiscovery,
610                        tiDiscFailed,
611                        agNULL
612                        );
613         break;
614   }
615   case OSSA_DISCOVER_ABORT_ERROR_5:
616   {
617     TI_DBG3(("ossaDiscoverSasCB: ERROR 5\n"));
618     /* letting OS layer know discovery has not been successfully complete */
619     ostiInitiatorEvent(
620                        tiRoot,
621                        tiPortalContext,
622                        agNULL,
623                        tiIntrEventTypeDiscovery,
624                        tiDiscFailed,
625                        agNULL
626                        );
627     break;
628   }
629   case OSSA_DISCOVER_ABORT_ERROR_6:
630   {
631     TI_DBG3(("ossaDiscoverSasCB: ERROR 6\n"));
632     /* letting OS layer know discovery has not been successfully complete */
633     ostiInitiatorEvent(
634                        tiRoot,
635                        tiPortalContext,
636                        agNULL,
637                        tiIntrEventTypeDiscovery,
638                        tiDiscFailed,
639                        agNULL
640                        );
641     break;
642   }
643   case OSSA_DISCOVER_ABORT_ERROR_7:
644   {
645     TI_DBG3(("ossaDiscoverSasCB: ERROR 7\n"));
646     /* letting OS layer know discovery has not been successfully complete */
647     ostiInitiatorEvent(
648                        tiRoot,
649                        tiPortalContext,
650                        agNULL,
651                        tiIntrEventTypeDiscovery,
652                        tiDiscFailed,
653                        agNULL
654                        );
655     break;
656   }
657   case OSSA_DISCOVER_ABORT_ERROR_8:
658   {
659     TI_DBG3(("ossaDiscoverSasCB: ERROR 8\n"));
660     /* letting OS layer know discovery has not been successfully complete */
661     ostiInitiatorEvent(
662                        tiRoot,
663                        tiPortalContext,
664                        agNULL,
665                        tiIntrEventTypeDiscovery,
666                        tiDiscFailed,
667                        agNULL
668                        );
669     break;
670   }
671   case OSSA_DISCOVER_ABORT_ERROR_9:
672   {
673     TI_DBG3(("ossaDiscoverSasCB: ERROR 9\n"));
674     /* letting OS layer know discovery has not been successfully complete */
675     ostiInitiatorEvent(
676                        tiRoot,
677                        tiPortalContext,
678                        agNULL,
679                        tiIntrEventTypeDiscovery,
680                        tiDiscFailed,
681                        agNULL
682                        );
683     break;
684   }
685   default:
686     TI_DBG3(("ossaDiscoverSasCB: ERROR default event 0x%x\n", event));
687     /* letting OS layer know discovery has not been successfully complete */
688     ostiInitiatorEvent(
689                        tiRoot,
690                        tiPortalContext,
691                        agNULL,
692                        tiIntrEventTypeDiscovery,
693                        tiDiscFailed,
694                        agNULL
695                        );
696     break;
697   } /* end of switch */
698   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Y1");
699   return;
700 }
701 #endif // #ifdef INITIATOR_DRIVER
702 
703 osGLOBAL void ossaLogTrace0(
704                agsaRoot_t           *agRoot,
705                bit32               traceCode
706                )
707 {
708   return;
709 }
710 
711 osGLOBAL void ossaLogTrace1(
712                agsaRoot_t           *agRoot,
713                bit32               traceCode,
714                bit32               value1
715                )
716 {
717   return;
718 }
719 
720 osGLOBAL void ossaLogTrace2(
721                agsaRoot_t           *agRoot,
722                bit32               traceCode,
723                bit32               value1,
724                bit32               value2
725                )
726 {
727   return;
728 }
729 
730 osGLOBAL void ossaLogTrace3(
731                agsaRoot_t           *agRoot,
732                bit32               traceCode,
733                bit32               value1,
734                bit32               value2,
735                bit32               value3
736                )
737 {
738   return;
739 }
740 
741 
742 osGLOBAL void
743 ossaLogTrace4(
744                agsaRoot_t           *agRoot,
745                bit32               traceCode,
746                bit32               value1,
747                bit32               value2,
748                bit32               value3,
749                bit32               value4
750                )
751 {
752   return;
753 }
754 
755 
756 /*****************************************************************************
757 *! \brief ossaHwCB
758 *
759 *  Purpose:  This function is called by lower layer to inform TD layer of
760 *            HW related results
761 *
762 *  \param   agRoot         Pointer to chip/driver Instance.
763 *  \param   agPortContext  Pointer to the port context of TD and Lower layer
764 *  \param   event          event type
765 *  \param   eventParm1     event-specific parameter
766 *  \param   eventParm2     event-specific parameter
767 *  \param   eventParm3     event-specific parameter of pointer type
768 *
769 *  \return: none
770 *
771 *  \note -  For details, refer to SAS/SATA Low-Level API Specification
772 *
773 *****************************************************************************/
774 osGLOBAL void ossaHwCB(
775          agsaRoot_t        *agRoot,
776          agsaPortContext_t *agPortContext,
777          bit32             event,
778          bit32             eventParm1,
779          void              *eventParm2,
780          void              *eventParm3
781          )
782 {
783   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
784   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
785   tdsaContext_t       *tdsaAllShared = (tdsaContext_t *)osData->tdsaAllShared;
786   tdList_t            *PortContextList = agNULL;
787   tdsaPortContext_t   *onePortContext = agNULL;
788   agsaDevHandle_t     *agDevHandle = agNULL;
789   agsaSASIdentify_t   *IDframe = agNULL;
790   int                 i = 0;
791 #ifdef INITIATOR_DRIVER
792   tdsaSASSubID_t      agSASSubID;
793 #endif
794   bit32               PhyID;
795   bit32               PhyStatus;
796   bit32               LinkRate;
797   bit32               PortState;
798   bit32               HwAckSatus = AGSA_RC_SUCCESS;
799 
800 // #ifdef INITIATOR_DRIVER
801 #ifdef INITIATOR_DRIVER
802   agsaFisRegDeviceToHost_t *RegD2H = agNULL;
803   tdsaDeviceData_t         *oneDeviceData = agNULL;
804   tdList_t                 *DeviceListList;
805 #endif
806 #ifdef REMOVED
807   bit32                    found = agFALSE;
808 #endif
809   agsaHWEventEncrypt_t     *pEncryptCBData;
810   agsaEncryptInfo_t        *pEncryptInfo;
811   agsaHWEventMode_t        *pModeEvent;
812   tiEncryptPort_t          encryptEventData;
813   tiEncryptInfo_t          encryptInfo;
814   bit32                    *pModePage;
815   bit32                    securityMode;
816   bit32                    cipherMode;
817   bit32                    encryptStatus;
818   bit32                    securitySetModeStatus;
819   bit32                    securityModeStatus;
820 
821 // #endif /* INITIATOR_DRIVER */
822   agsaPhyErrCountersPage_t *agPhyErrCountersPage;
823   agsaEventSource_t        eventSource;
824 
825 #ifdef FDS_DM
826   dmRoot_t                 *dmRoot = &(tdsaAllShared->dmRoot);
827   dmPortContext_t          *dmPortContext = agNULL;
828   bit32                    status = DM_RC_FAILURE;
829   dmPortInfo_t             dmPortInfo;
830 //  bit32                    discStatus = dmDiscInProgress;
831 #endif
832 
833   smTraceFuncEnter(hpDBG_VERY_LOUD,"Y2");
834 
835   TI_DBG2(("ossaHwCB: agPortContext %p event 0x%x eventParm1 0x%x eventParm2 %p eventParm3 %p\n",
836                       agPortContext,event,eventParm1,eventParm2,eventParm3 ));
837 
838   switch ( event )
839   {
840   case OSSA_HW_EVENT_SAS_PHY_UP:
841   {
842     PhyID = TD_GET_PHY_ID(eventParm1);
843     LinkRate = TD_GET_LINK_RATE(eventParm1);
844     PortState = TD_GET_PORT_STATE(eventParm1);
845     agDevHandle = agNULL;
846     IDframe = (agsaSASIdentify_t *)eventParm3;
847 
848 
849     TI_DBG2(("ossaHwCB: Phy%d SAS link Up\n", PhyID));
850 
851     if (agPortContext == agNULL)
852     {
853       TI_DBG1(("ossaHwCB: agPortContext null, wrong\n"));
854       smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Y2");
855       return;
856     }
857     if (agDevHandle == agNULL)
858     {
859       TI_DBG3(("ossaHwCB: agDevHandle null by design change\n"));
860     }
861 
862     if (IDframe == agNULL)
863     {
864       TI_DBG1(("ossaHwCB: IDframe null, wrong\n"));
865       smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "Y2");
866       return;
867     }
868     /* debugging only */
869     if (LinkRate == 0x01)
870     {
871       TI_DBG1(("ossaHwCB: SAS Link Rate is 1.5 Gbps PhyID %d\n",PhyID));
872     }
873     if (LinkRate == 0x02)
874     {
875       TI_DBG1(("ossaHwCB: SAS Link Rate is 3.0 Gbps PhyID %d\n",PhyID));
876     }
877     if (LinkRate == 0x04)
878     {
879       TI_DBG1(("ossaHwCB: SAS Link Rate is 6.0 Gbps PhyID %d\n",PhyID));
880     }
881     if (LinkRate == 0x08)
882     {
883       TI_DBG1(("ossaHwCB: SAS Link Rate is 12.0 Gbps PhyID %d\n",PhyID));
884     }
885 
886     if (PortState == OSSA_PORT_INVALID)
887     {
888       TI_DBG1(("ossaHwCB: Wrong port state with SAS link up\n"));
889       smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "Y2");
890       return;
891     }
892 
893     if ( agPortContext->osData == agNULL)
894     {/* if */
895       TI_DBG6 (("ossaHwCB: PhyID %d tdsaAllShared %p\n", PhyID, tdsaAllShared));
896       if (tdsaAllShared->Ports[PhyID].tiPortalContext == agNULL)
897       {
898         TI_DBG6(("ossaHwCB: NULL portalcontext\n"));
899       }
900       else
901       {
902         TI_DBG6(("ossaHwCB: NOT NULL portalcontext\n"));
903       }
904 
905       if (IDframe == agNULL)
906       {
907         TI_DBG1(("ossaHwCB: IDFrame is NULL; SATA !!!!\n"));
908       }
909       else
910       {
911         TI_DBG3(("ossaHwCB: IDframe->sasAddressHi 0x%08x \n",
912                  SA_IDFRM_GET_SAS_ADDRESSHI(IDframe)));
913         TI_DBG3(("ossaHwCB: IDframe->sasAddressLo 0x%08x \n",
914                  SA_IDFRM_GET_SAS_ADDRESSLO(IDframe)));
915 
916       }
917       /*
918         setting tdsaPortContext fields
919         take the head from the FreeLink of tdsaPortContext_t
920         then modify it
921         then put it in MainLink of tdsaPortContext_t
922       */
923       tdsaSingleThreadedEnter(tiRoot, TD_PORT_LOCK);
924       if (TDLIST_NOT_EMPTY(&(tdsaAllShared->FreePortContextList)))
925       {
926         TDLIST_DEQUEUE_FROM_HEAD(&PortContextList, &(tdsaAllShared->FreePortContextList));
927         tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
928         onePortContext = TDLIST_OBJECT_BASE(tdsaPortContext_t, FreeLink, PortContextList);
929         TI_DBG2(("ossaHwCB: pid %d\n", onePortContext->id));
930         TI_DBG6(("ossaHwCB: onePortContext %p\n", onePortContext));
931         if (onePortContext == agNULL)
932         {
933           TI_DBG1(("ossaHwCB: onePortContext is NULL in allocation, wrong!\n"));
934           return;
935         }
936 
937         /* sets fields of tdsaportcontext */
938 #ifdef INITIATOR_DRIVER
939         onePortContext->DiscoveryState = ITD_DSTATE_NOT_STARTED;
940         onePortContext->discoveryOptions = AG_SA_DISCOVERY_OPTION_FULL_START;
941 #endif
942         onePortContext->PhyIDList[PhyID] = agTRUE;
943         if (IDframe == agNULL)
944         {
945           onePortContext->sasRemoteAddressHi = 0xFFFFFFFF;
946           onePortContext->sasRemoteAddressLo = 0xFFFFFFFF;
947           onePortContext->directAttatchedSAS = agTRUE;
948         }
949         else
950         {
951           onePortContext->sasRemoteAddressHi = SA_IDFRM_GET_SAS_ADDRESSHI(IDframe);
952           onePortContext->sasRemoteAddressLo = SA_IDFRM_GET_SAS_ADDRESSLO(IDframe);
953           /* Create ID frame and storing ID frame */
954           osti_memcpy(&onePortContext->sasIDframe, IDframe, sizeof(agsaSASIdentify_t));
955           tdhexdump("ossaHWCB: sasIDframe", (bit8 *)(&onePortContext->sasIDframe), sizeof(agsaSASIdentify_t));
956           if (SA_IDFRM_GET_DEVICETTYPE(IDframe) == SAS_END_DEVICE)
957           {
958             onePortContext->directAttatchedSAS = agTRUE;
959           }
960 #ifdef FDS_DM
961           if (SA_IDFRM_GET_DEVICETTYPE(IDframe) == SAS_EDGE_EXPANDER_DEVICE ||
962               SA_IDFRM_GET_DEVICETTYPE(IDframe) == SAS_FANOUT_EXPANDER_DEVICE
963              )
964           {
965             onePortContext->UseDM = agTRUE;
966           }
967 #endif
968         }
969 
970         onePortContext->sasLocalAddressHi = SA_IDFRM_GET_SAS_ADDRESSHI(&tdsaAllShared->Ports[PhyID].SASID);
971         onePortContext->sasLocalAddressLo = SA_IDFRM_GET_SAS_ADDRESSLO(&tdsaAllShared->Ports[PhyID].SASID);
972         onePortContext->tiPortalContext = tdsaAllShared->Ports[PhyID].tiPortalContext;
973         onePortContext->agRoot = agRoot;
974         onePortContext->agPortContext = agPortContext;
975         tdsaAllShared->Ports[PhyID].portContext = onePortContext;
976         agPortContext->osData = onePortContext;
977         onePortContext->valid = agTRUE;
978         if (LinkRate == 0x01)
979         {
980           onePortContext->LinkRate = SAS_CONNECTION_RATE_1_5G;
981         }
982         else if (LinkRate == 0x02)
983         {
984           onePortContext->LinkRate = SAS_CONNECTION_RATE_3_0G;
985         }
986         else if (LinkRate == 0x04)
987         {
988           onePortContext->LinkRate = SAS_CONNECTION_RATE_6_0G;
989         }
990         else /* (LinkRate == 0x08) */
991         {
992           onePortContext->LinkRate = SAS_CONNECTION_RATE_12_0G;
993         }
994 
995         tdsaSingleThreadedEnter(tiRoot, TD_PORT_LOCK);
996         TDLIST_ENQUEUE_AT_TAIL(&(onePortContext->MainLink), &(tdsaAllShared->MainPortContextList));
997         tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
998 #ifdef FDS_DM
999         dmPortContext = &(onePortContext->dmPortContext);
1000         dmPortContext->tdData = onePortContext;
1001         /* set up dmPortInfo_t */
1002         PORTINFO_PUT_SAS_REMOTE_ADDRESSLO(&dmPortInfo, onePortContext->sasRemoteAddressLo);
1003         PORTINFO_PUT_SAS_REMOTE_ADDRESSHI(&dmPortInfo, onePortContext->sasRemoteAddressHi);
1004         PORTINFO_PUT_SAS_LOCAL_ADDRESSLO(&dmPortInfo, onePortContext->sasLocalAddressLo);
1005         PORTINFO_PUT_SAS_LOCAL_ADDRESSHI(&dmPortInfo, onePortContext->sasLocalAddressHi);
1006 
1007         TI_DBG2(("ossaHwCB: phy %d hi 0x%x lo 0x%x\n", PhyID,
1008                  SA_IDFRM_GET_SAS_ADDRESSHI(&(tdsaAllShared->Ports[PhyID].SASID)),
1009                  SA_IDFRM_GET_SAS_ADDRESSLO(&(tdsaAllShared->Ports[PhyID].SASID))));
1010         TI_DBG2(("ossaHwCB: LocalAddrHi 0x%08x LocaAddrLo 0x%08x\n", onePortContext->sasLocalAddressHi, onePortContext->sasLocalAddressLo));
1011 
1012         dmPortInfo.flag = onePortContext->LinkRate;
1013 
1014         if (onePortContext->UseDM == agTRUE)
1015         {
1016           TI_DBG1(("ossaHwCB: calling dmCreatePort\n"));
1017           status = dmCreatePort(dmRoot, dmPortContext, &dmPortInfo);
1018           if (status != DM_RC_SUCCESS)
1019           {
1020             TI_DBG1(("ossaHwCB: dmCreatePort failed!!! 0x%x\n", status));
1021           }
1022         }
1023 #endif
1024 
1025       }
1026       else
1027       {
1028         tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
1029         TI_DBG1(("\nossaHwCB: Attention!!! no more free PortContext.\n"));
1030       }
1031 #ifdef TD_INTERNAL_DEBUG     /* for debugging only */
1032 
1033       print_tdlist_flink(&(tdsaPortContext->FreeLink), 1, 1);
1034       print_tdlist_flink(&(tdsaPortContext->MainLink), 1, 2);
1035       print_tdlist_flink(&(tdsaDeviceData->FreeLink), 2, 1);
1036       print_tdlist_flink(&(tdsaDeviceData->MainLink), 2, 2);
1037 #endif
1038 
1039 #ifdef TD_INTERNAL_DEBUG      /* for debugging */
1040       PortContextList = tdsaPortContext->MainLink.flink;
1041       while (PortContextList != &(tdsaPortContext->MainLink))
1042       {
1043         twoPortContext = TDLIST_OBJECT_BASE(tdsaPortContext_t, MainLink, PortContextList);
1044         TI_DBG6(("ossaHwCB: in while portContext ID %d\n", twoPortContext->id));
1045         TI_DBG6(("ossaHwCB: in while PortContext %p\n", twoPortContext));
1046         PortContextList = PortContextList->flink;
1047       }
1048 #endif
1049       /* add agDevHandle */
1050       if (SA_IDFRM_GET_DEVICETTYPE(IDframe) != SAS_NO_DEVICE)
1051       {
1052 #ifdef INITIATOR_DRIVER
1053         agSASSubID.sasAddressHi = SA_IDFRM_GET_SAS_ADDRESSHI(IDframe);
1054         agSASSubID.sasAddressLo = SA_IDFRM_GET_SAS_ADDRESSLO(IDframe);
1055         agSASSubID.initiator_ssp_stp_smp = IDframe->initiator_ssp_stp_smp;
1056         agSASSubID.target_ssp_stp_smp = IDframe->target_ssp_stp_smp;
1057 #endif
1058 
1059         TI_DBG2(("ossaHwCB: adding ....\n"));
1060         /* uses only SASIDframe not agsaSASDeviceInfo_t */
1061 #ifdef INITIATOR_DRIVER
1062         tdssAddSASToSharedcontext(
1063                                   onePortContext,
1064                                   agRoot,
1065                                   agDevHandle, /* agNULL */
1066                                   &agSASSubID,
1067                                   agTRUE,
1068                                   (bit8)PhyID,
1069                                   TD_OPERATION_INITIATOR
1070                                   );
1071 #endif
1072 
1073 #ifdef FDS_DM
1074         if (SA_IDFRM_GET_DEVICETTYPE(IDframe) == SAS_END_DEVICE &&
1075             SA_IDFRM_IS_SSP_TARGET(IDframe) )
1076         {
1077           TI_DBG2(("ossaHwCB: NOTIFY_ENABLE_SPINUP PhyID %d \n", PhyID));
1078 
1079           for (i=0;i<TD_MAX_NUM_NOTIFY_SPINUP;i++)
1080           {
1081             saLocalPhyControl(agRoot, agNULL, 0, PhyID, AGSA_PHY_NOTIFY_ENABLE_SPINUP, agNULL);
1082           }
1083         }
1084 
1085         /* update MCN */
1086         tdsaUpdateMCN(dmRoot, onePortContext);
1087 #endif
1088 
1089 #ifdef TARGET_DRIVER
1090         TI_DBG1(("ossaHwCB: target, link up PhyID 0x%x\n",PhyID));
1091 
1092         /* notifying link up */
1093         ostiPortEvent (
1094                        tiRoot,
1095                        tiPortLinkUp,
1096                        tiSuccess,
1097                        (void *)tdsaAllShared->Ports[PhyID].tiPortalContext
1098                        );
1099 #endif
1100       }
1101       else
1102       {
1103         TI_DBG5(("ossaHwCB: $$$$$ not end device. not adding....\n"));
1104       }
1105 
1106       saPortControl(agRoot, /* AGSA_PORT_SET_PORT_RECOVERY_TIME */
1107                     agNULL,
1108                     0,
1109                     agPortContext,
1110                     AGSA_PORT_SET_PORT_RECOVERY_TIME,
1111                     tdsaAllShared->portTMO, //PORT_RECOVERY_TIMEOUT
1112                     0
1113                     );
1114       /* setting SAS PORT RESET TMO and SATA PORT RESET TMO*/
1115       if (tIsSPCV12G(agRoot))
1116       {
1117         saPortControl(agRoot, /* AGSA_PORT_SET_PORT_RESET_TIME */
1118                       agNULL,
1119                       0,
1120                       agPortContext,
1121                       AGSA_PORT_SET_PORT_RESET_TIME,
1122                       SAS_12G_PORT_RESET_TMO, // 800 ms
1123                       0
1124                       );
1125       }
1126       else
1127       {
1128         saPortControl(agRoot, /* AGSA_PORT_SET_PORT_RESET_TIME */
1129                       agNULL,
1130                       0,
1131                       agPortContext,
1132                       AGSA_PORT_SET_PORT_RESET_TIME,
1133                       SAS_PORT_RESET_TMO, // 300 ms
1134                       0
1135                       );
1136       }
1137     }
1138     else
1139     {
1140       /*
1141         an existing portcontext
1142         to be tested
1143       */
1144 
1145       TI_DBG2(("ossaHwCB: SAS existing portcontext returned\n"));
1146 
1147       onePortContext  = (tdsaPortContext_t *)agPortContext->osData;
1148       if (onePortContext == agNULL)
1149       {
1150         TI_DBG1(("ossaHwCB: onePortContext is NULL, wrong!\n"));
1151         return;
1152       }
1153       if (onePortContext->valid == agFALSE)
1154       {
1155         /* port has been invalidated; needs to be allocated */
1156         TI_DBG2(("ossaHwCB: SAS allocating port context\n"));
1157 
1158         tdsaSingleThreadedEnter(tiRoot, TD_PORT_LOCK);
1159         if (TDLIST_NOT_EMPTY(&(tdsaAllShared->FreePortContextList)))
1160         {
1161           TDLIST_DEQUEUE_FROM_HEAD(&PortContextList, &(tdsaAllShared->FreePortContextList));
1162           tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
1163           onePortContext = TDLIST_OBJECT_BASE(tdsaPortContext_t, FreeLink, PortContextList);
1164           TI_DBG2(("ossaHwCB: allocating pid %d\n", onePortContext->id));
1165           TI_DBG6(("ossaHwCB: allocating onePortContext %p\n", onePortContext));
1166           if (onePortContext == agNULL)
1167           {
1168             TI_DBG1(("ossaHwCB: onePortContext is NULL in allocation, wrong!\n"));
1169             return;
1170           }
1171           /* sets fields of tdsaportcontext */
1172 #ifdef INITIATOR_DRIVER
1173           onePortContext->DiscoveryState = ITD_DSTATE_NOT_STARTED;
1174           onePortContext->discoveryOptions = AG_SA_DISCOVERY_OPTION_FULL_START;
1175 #endif
1176           onePortContext->PhyIDList[PhyID] = agTRUE;
1177           if (IDframe == agNULL)
1178           {
1179             onePortContext->sasRemoteAddressHi = 0xFFFFFFFF;
1180             onePortContext->sasRemoteAddressLo = 0xFFFFFFFF;
1181             onePortContext->directAttatchedSAS = agTRUE;
1182           }
1183           else
1184           {
1185             onePortContext->sasRemoteAddressHi = SA_IDFRM_GET_SAS_ADDRESSHI(IDframe);
1186             onePortContext->sasRemoteAddressLo = SA_IDFRM_GET_SAS_ADDRESSLO(IDframe);
1187             /* Create ID frame and storing ID frame */
1188             osti_memcpy(&onePortContext->sasIDframe, IDframe, sizeof(agsaSASIdentify_t));
1189             tdhexdump("ossaHWCB: sasIDframe", (bit8 *)(&onePortContext->sasIDframe), sizeof(agsaSASIdentify_t));
1190             if (SA_IDFRM_GET_DEVICETTYPE(IDframe) == SAS_END_DEVICE)
1191             {
1192               onePortContext->directAttatchedSAS = agTRUE;
1193             }
1194           }
1195 
1196           onePortContext->sasLocalAddressHi = SA_IDFRM_GET_SAS_ADDRESSHI(&tdsaAllShared->Ports[PhyID].SASID);
1197           onePortContext->sasLocalAddressLo = SA_IDFRM_GET_SAS_ADDRESSLO(&tdsaAllShared->Ports[PhyID].SASID);
1198           onePortContext->tiPortalContext = tdsaAllShared->Ports[PhyID].tiPortalContext;
1199           onePortContext->agRoot = agRoot;
1200           onePortContext->agPortContext = agPortContext;
1201           tdsaAllShared->Ports[PhyID].portContext = onePortContext;
1202           agPortContext->osData = onePortContext;
1203           onePortContext->valid = agTRUE;
1204           if (LinkRate == 0x01)
1205           {
1206             onePortContext->LinkRate = SAS_CONNECTION_RATE_1_5G;
1207           }
1208           else if (LinkRate == 0x02)
1209           {
1210             onePortContext->LinkRate = SAS_CONNECTION_RATE_3_0G;
1211           }
1212           else if (LinkRate == 0x04)
1213           {
1214             onePortContext->LinkRate = SAS_CONNECTION_RATE_6_0G;
1215           }
1216           else /* (LinkRate == 0x08) */
1217           {
1218             onePortContext->LinkRate = SAS_CONNECTION_RATE_12_0G;
1219           }
1220           tdsaSingleThreadedEnter(tiRoot, TD_PORT_LOCK);
1221           TDLIST_ENQUEUE_AT_TAIL(&(onePortContext->MainLink), &(tdsaAllShared->MainPortContextList));
1222           tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
1223         }
1224         else
1225         {
1226           tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
1227           TI_DBG1(("\nossaHwCB: Attention!!! no more free PortContext.\n"));
1228           smTraceFuncExit(hpDBG_VERY_LOUD, 'd', "Y2");
1229           return;
1230         }
1231       } /* invalidated port */
1232       else
1233       {
1234         /* already alloacated */
1235         TI_DBG2(("ossaHwCB: SAS already allocated port context\n"));
1236         if (TDLIST_EMPTY(&(tdsaAllShared->MainPortContextList)))
1237         {
1238           TI_DBG1(("ossaHwCB: wrong!!!  null tdsaPortContext list\n"));
1239           smTraceFuncExit(hpDBG_VERY_LOUD, 'e', "Y2");
1240           return;
1241         }
1242         if (onePortContext == agNULL)
1243         {
1244           TI_DBG1(("ossaHwCB: wrong !!! No corressponding tdsaPortContext\n"));
1245           smTraceFuncExit(hpDBG_VERY_LOUD, 'f', "Y2");
1246           return;
1247         }
1248 
1249         TI_DBG2(("ossaHwCB: existing pid %d\n", onePortContext->id));
1250         if (tdsaAllShared->Ports[PhyID].portContext == agNULL)
1251         {
1252           TI_DBG1(("ossaHwCB: existing allshared pid is NULL\n"));
1253         }
1254         else
1255         {
1256           TI_DBG2(("ossaHwCB: existing allshared pid %d\n", tdsaAllShared->Ports[PhyID].portContext->id));
1257         }
1258         /* updates PhyID belong to a port */
1259         onePortContext->PhyIDList[PhyID] = agTRUE;
1260 #ifdef FDS_DM
1261         if (SA_IDFRM_GET_DEVICETTYPE(IDframe) == SAS_END_DEVICE &&
1262             SA_IDFRM_IS_SSP_TARGET(IDframe) )
1263         {
1264           TI_DBG2(("ossaHwCB: NOTIFY_ENABLE_SPINUP PhyID %d \n", PhyID));
1265 
1266           for (i=0;i<TD_MAX_NUM_NOTIFY_SPINUP;i++)
1267           {
1268             saLocalPhyControl(agRoot, agNULL, 0, PhyID, AGSA_PHY_NOTIFY_ENABLE_SPINUP, agNULL);
1269           }
1270         }
1271 
1272         /* update MCN */
1273         tdsaUpdateMCN(dmRoot, onePortContext);
1274 #endif
1275       }
1276       onePortContext->SeenLinkUp = agTRUE;
1277     } /* else, old portcontext */
1278 
1279     break;
1280   }
1281 #ifdef INITIATOR_DRIVER
1282   case OSSA_HW_EVENT_SATA_PHY_UP:
1283   {
1284     PhyID = TD_GET_PHY_ID(eventParm1);
1285     LinkRate = TD_GET_LINK_RATE(eventParm1);
1286     PortState = TD_GET_PORT_STATE(eventParm1);
1287     agDevHandle = agNULL;
1288     RegD2H = ( agsaFisRegDeviceToHost_t *)eventParm3;
1289 
1290     TI_DBG2(("ossaHwCB: Phy%d SATA link Up\n", PhyID));
1291 
1292     if (agDevHandle == agNULL)
1293     {
1294       TI_DBG3(("ossaHwCB: agDevHandle null by design change\n"));
1295     }
1296 
1297     if (RegD2H == agNULL)
1298     {
1299       TI_DBG1(("ossaHwCB: RegD2H null, wrong\n"));
1300       smTraceFuncExit(hpDBG_VERY_LOUD, 'g', "Y2");
1301       return;
1302     }
1303 
1304 
1305     TI_DBG2(("ossaHwCB: agDevHandle %p\n", agDevHandle));
1306     tdhexdump("ossaHWCB RegD2H", (bit8 *)RegD2H, sizeof(agsaFisRegDeviceToHost_t));
1307     TI_DBG2(("ossaHwCB: Sector Count %d\n", RegD2H->d.sectorCount));
1308     TI_DBG2(("ossaHwCB: LBA LOW %d\n", RegD2H->d.lbaLow));
1309     TI_DBG2(("ossaHwCB: LBA MID  %d\n", RegD2H->d.lbaMid));
1310     TI_DBG2(("ossaHwCB: LBA HIGH  %d\n", RegD2H->d.lbaHigh));
1311     TI_DBG2(("ossaHwCB: DEVICE  %d\n", RegD2H->d.device));
1312 
1313     /* debugging only */
1314     if (LinkRate == 0x01)
1315     {
1316       TI_DBG1(("ossaHwCB: SATA Link Rate is 1.5 Gbps PhyID %d\n",PhyID));
1317     }
1318     if (LinkRate == 0x02)
1319     {
1320       TI_DBG1(("ossaHwCB: SATA Link Rate is 3.0 Gbps PhyID %d\n",PhyID));
1321     }
1322     if (LinkRate == 0x04)
1323     {
1324       TI_DBG1(("ossaHwCB: SATA Link Rate is 6.0 Gbps PhyID %d\n",PhyID));
1325     }
1326     if (LinkRate == 0x08)
1327     {
1328       TI_DBG1(("ossaHwCB: SATA Link Rate is 12.0 Gbps PhyID %d\n",PhyID));
1329     }
1330 
1331     if (PortState == OSSA_PORT_INVALID)
1332     {
1333       TI_DBG1(("ossaHwCB: Wrong port state with SATA link up\n"));
1334       smTraceFuncExit(hpDBG_VERY_LOUD, 'h', "Y2");
1335       return;
1336     }
1337 
1338     if ( agPortContext->osData == agNULL)
1339     {/* if */
1340       TI_DBG6 (("ossaHwCB: PhyID %d tdsaAllShared %p\n", PhyID, tdsaAllShared));
1341       tdsaSingleThreadedEnter(tiRoot, TD_PORT_LOCK);
1342       if (TDLIST_NOT_EMPTY(&(tdsaAllShared->FreePortContextList)))
1343       {
1344         TDLIST_DEQUEUE_FROM_HEAD(&PortContextList, &(tdsaAllShared->FreePortContextList));
1345         tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
1346         onePortContext = TDLIST_OBJECT_BASE(tdsaPortContext_t, FreeLink, PortContextList);
1347         TI_DBG2(("ossaHwCB: pid %d\n", onePortContext->id));
1348         TI_DBG6(("ossaHwCB: onePortContext %p\n", onePortContext));
1349         if (onePortContext == agNULL)
1350         {
1351           TI_DBG1(("ossaHwCB: onePortContext is NULL in allocation, wrong!\n"));
1352           return;
1353         }
1354 
1355         /* sets fields of tdsaportcontext */
1356         onePortContext->DiscoveryState = ITD_DSTATE_NOT_STARTED;
1357         onePortContext->discoveryOptions = AG_SA_DISCOVERY_OPTION_FULL_START;
1358         onePortContext->PhyIDList[PhyID] = agTRUE;
1359         /* NO sas address for SATA */
1360         onePortContext->sasRemoteAddressHi = 0xFFFFFFFF;
1361         onePortContext->sasRemoteAddressLo = 0xFFFFFFFF;
1362         /* copying the signature */
1363         onePortContext->remoteSignature[0] = RegD2H->d.sectorCount;
1364         onePortContext->remoteSignature[1] = RegD2H->d.lbaLow;
1365         onePortContext->remoteSignature[2] = RegD2H->d.lbaMid;
1366         onePortContext->remoteSignature[3] = RegD2H->d.lbaHigh;
1367         onePortContext->remoteSignature[4] = RegD2H->d.device;
1368 
1369         onePortContext->sasLocalAddressHi = SA_IDFRM_GET_SAS_ADDRESSHI(&tdsaAllShared->Ports[PhyID].SASID);
1370         onePortContext->sasLocalAddressLo = SA_IDFRM_GET_SAS_ADDRESSLO(&tdsaAllShared->Ports[PhyID].SASID);
1371         onePortContext->tiPortalContext = tdsaAllShared->Ports[PhyID].tiPortalContext;
1372         onePortContext->agRoot = agRoot;
1373         onePortContext->agPortContext = agPortContext;
1374         tdsaAllShared->Ports[PhyID].portContext = onePortContext;
1375         agPortContext->osData = onePortContext;
1376         onePortContext->nativeSATAMode = agTRUE;
1377         onePortContext->valid = agTRUE;
1378         if (LinkRate == 0x01)
1379         {
1380           onePortContext->LinkRate = SAS_CONNECTION_RATE_1_5G;
1381         }
1382         else if (LinkRate == 0x02)
1383         {
1384           onePortContext->LinkRate = SAS_CONNECTION_RATE_3_0G;
1385         }
1386         else if (LinkRate == 0x04)
1387         {
1388           onePortContext->LinkRate = SAS_CONNECTION_RATE_6_0G;
1389         }
1390         else /* (LinkRate == 0x08) */
1391         {
1392           onePortContext->LinkRate = SAS_CONNECTION_RATE_12_0G;
1393         }
1394 
1395         tdsaSingleThreadedEnter(tiRoot, TD_PORT_LOCK);
1396         TDLIST_ENQUEUE_AT_TAIL(&(onePortContext->MainLink), &(tdsaAllShared->MainPortContextList));
1397         tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
1398       }
1399       else
1400       {
1401         tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
1402         TI_DBG1(("\nossaHwCB: Attention!!! no more free PortContext.\n"));
1403         smTraceFuncExit(hpDBG_VERY_LOUD, 'i', "Y2");
1404         return;
1405       }
1406 #ifdef SATA_ENABLE
1407       /* tdssAddSATAToSharedcontext() sends identify device data to find out the uniqueness of
1408          target. In identify device data CB fn (satAddSATAIDDevCB()),
1409          tiPortLinkUp and tiPortDiscoveryReady happen
1410       */
1411       tdssAddSATAToSharedcontext(
1412                                   onePortContext,
1413                                   agRoot,
1414                                   agDevHandle, /* agNULL */
1415                                   agNULL,
1416                                   agTRUE,
1417                                   (bit8)PhyID
1418                                   );
1419 #endif
1420       /* setting SAS PORT RESET TMO and SATA PORT RESET TMO*/
1421       saPortControl(agRoot, /* AGSA_PORT_SET_PORT_RESET_TIME */
1422                     agNULL,
1423                     0,
1424                     agPortContext,
1425                     AGSA_PORT_SET_PORT_RESET_TIME,
1426                     0,
1427                     SATA_PORT_RESET_TMO // 8000 ms
1428                     );
1429 
1430     }
1431     else
1432     {
1433       /*
1434         an existing portcontext
1435         to be tested
1436       */
1437 
1438       TI_DBG1(("ossaHwCB: SATA existing portcontext returned. need testing\n"));
1439       onePortContext  = (tdsaPortContext_t *)agPortContext->osData;
1440       /* for debugging only */
1441       if (onePortContext->valid == agFALSE)
1442       {
1443         /* port has been invalidated; needs to be allocated */
1444         TI_DBG2(("ossaHwCB: SATA allocating port context\n"));
1445       }
1446       else
1447       {
1448         /* already alloacated */
1449         TI_DBG1(("ossaHwCB: Wrong!!! SATA already allocated port context\n"));
1450         smTraceFuncExit(hpDBG_VERY_LOUD, 'j', "Y2");
1451         return;
1452       }
1453 
1454       tdsaSingleThreadedEnter(tiRoot, TD_PORT_LOCK);
1455       if (TDLIST_NOT_EMPTY(&(tdsaAllShared->FreePortContextList)))
1456       {
1457         TDLIST_DEQUEUE_FROM_HEAD(&PortContextList, &(tdsaAllShared->FreePortContextList));
1458         tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
1459         onePortContext = TDLIST_OBJECT_BASE(tdsaPortContext_t, FreeLink, PortContextList);
1460         TI_DBG2(("ossaHwCB: pid %d\n", onePortContext->id));
1461         TI_DBG6(("ossaHwCB: onePortContext %p\n", onePortContext));
1462         if (onePortContext == agNULL)
1463         {
1464           TI_DBG1(("ossaHwCB: onePortContext is NULL in allocation, wrong!\n"));
1465           return;
1466         }
1467 
1468         /* sets fields of tdsaportcontext */
1469         onePortContext->DiscoveryState = ITD_DSTATE_NOT_STARTED;
1470         onePortContext->discoveryOptions = AG_SA_DISCOVERY_OPTION_FULL_START;
1471         onePortContext->PhyIDList[PhyID] = agTRUE;
1472         /* NO sas address for SATA */
1473         onePortContext->sasRemoteAddressHi = 0xFFFFFFFF;
1474         onePortContext->sasRemoteAddressLo = 0xFFFFFFFF;
1475         /* copying the signature */
1476         onePortContext->remoteSignature[0] = RegD2H->d.sectorCount;
1477         onePortContext->remoteSignature[1] = RegD2H->d.lbaLow;
1478         onePortContext->remoteSignature[2] = RegD2H->d.lbaMid;
1479         onePortContext->remoteSignature[3] = RegD2H->d.lbaHigh;
1480         onePortContext->remoteSignature[4] = RegD2H->d.device;
1481 
1482         onePortContext->sasLocalAddressHi = SA_IDFRM_GET_SAS_ADDRESSHI(&tdsaAllShared->Ports[PhyID].SASID);
1483         onePortContext->sasLocalAddressLo = SA_IDFRM_GET_SAS_ADDRESSLO(&tdsaAllShared->Ports[PhyID].SASID);
1484         onePortContext->tiPortalContext = tdsaAllShared->Ports[PhyID].tiPortalContext;
1485         onePortContext->agRoot = agRoot;
1486         onePortContext->agPortContext = agPortContext;
1487         tdsaAllShared->Ports[PhyID].portContext = onePortContext;
1488         agPortContext->osData = onePortContext;
1489         onePortContext->nativeSATAMode = agTRUE;
1490         onePortContext->valid = agTRUE;
1491         if (LinkRate == 0x01)
1492         {
1493           onePortContext->LinkRate = SAS_CONNECTION_RATE_1_5G;
1494         }
1495         else if (LinkRate == 0x02)
1496         {
1497           onePortContext->LinkRate = SAS_CONNECTION_RATE_3_0G;
1498         }
1499         else if (LinkRate == 0x04)
1500         {
1501           onePortContext->LinkRate = SAS_CONNECTION_RATE_6_0G;
1502         }
1503         else /* (LinkRate == 0x08) */
1504         {
1505           onePortContext->LinkRate = SAS_CONNECTION_RATE_12_0G;
1506         }
1507 
1508         tdsaSingleThreadedEnter(tiRoot, TD_PORT_LOCK);
1509         TDLIST_ENQUEUE_AT_TAIL(&(onePortContext->MainLink), &(tdsaAllShared->MainPortContextList));
1510         tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
1511       }
1512       else
1513       {
1514         tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
1515         TI_DBG1(("\nossaHwCB: Attention!!! no more free PortContext.\n"));
1516         smTraceFuncExit(hpDBG_VERY_LOUD, 'k', "Y2");
1517         return;
1518       }
1519 
1520 
1521       /*hotplug */
1522 #ifdef SATA_ENABLE
1523       tdssAddSATAToSharedcontext(
1524                                   onePortContext,
1525                                   agRoot,
1526                                   agDevHandle, /* agNULL */
1527                                   agNULL,
1528                                   agTRUE,
1529                                   (bit8)PhyID
1530                                   );
1531 #endif
1532     /* end hotplug */
1533     }
1534 
1535     break;
1536   }
1537 #endif
1538   case OSSA_HW_EVENT_SATA_SPINUP_HOLD:
1539   {
1540     PhyID = TD_GET_PHY_ID(eventParm1);
1541 
1542     TI_DBG2(("ossaHwCB: spinup hold PhyID %d\n", PhyID));
1543     break;
1544   }
1545 
1546   case OSSA_HW_EVENT_PHY_DOWN:
1547   {
1548     bit32 AllPhyDown = agTRUE;
1549 
1550     /* 4/15/08 spec */
1551     PhyID = TD_GET_PHY_ID(eventParm1);
1552     LinkRate = TD_GET_LINK_RATE(eventParm1);
1553     PortState = TD_GET_PORT_STATE(eventParm1);
1554 
1555 
1556     TI_DBG2(("ossaHwCB: Phy%d link Down\n", PhyID));
1557 
1558     if (agPortContext == agNULL)
1559     {
1560       TI_DBG1(("ossaHwCB: agPortContext null, wrong\n"));
1561       smTraceFuncExit(hpDBG_VERY_LOUD, 'l', "Y2");
1562       return;
1563     }
1564 
1565     if ( agPortContext->osData == agNULL)
1566     { /* if */
1567       /* PortContext must exit at this point */
1568       TI_DBG1(("ossaHwCB: NULL portalcontext. Error. Can't be NULL\n"));
1569     }
1570     else
1571     {
1572       TI_DBG3(("ossaHwCB: NOT NULL portalcontext\n"));
1573       onePortContext  = (tdsaPortContext_t *)agPortContext->osData;
1574       if (onePortContext == agNULL)
1575       {
1576         TI_DBG1(("ossaHwCB: wrong !!! No corressponding tdsaPortContext\n"));
1577         smTraceFuncExit(hpDBG_VERY_LOUD, 'm', "Y2");
1578         return;
1579       }
1580       onePortContext->PhyIDList[PhyID] = agFALSE;
1581       for(i=0;i<TD_MAX_NUM_PHYS;i++)
1582       {
1583         if (onePortContext->PhyIDList[i] == agTRUE)
1584         {
1585           TI_DBG3(("ossaHwCB: Phy %d is still up\n", i));
1586           AllPhyDown = agFALSE;
1587           break;
1588         }
1589       }
1590 
1591       /* last phy belong to the portcontext */
1592       if (AllPhyDown == agTRUE)
1593       {
1594 #ifdef NOT_YET
1595         TI_DBG1(("ossaHwCB: calling tiPortLinkDown\n"));
1596         ostiPortEvent (
1597                        tiRoot,
1598                        tiPortLinkDown,
1599                        tiSuccess,
1600                        (void *)onePortContext->tiPortalContext
1601                        );
1602 #endif
1603       }
1604 
1605       if (PortState == OSSA_PORT_VALID)
1606       {
1607         /* do nothing */
1608         /* no ack for every phy down */
1609 #ifdef FDS_DM
1610         /* update MCN for all devices belong to this port */
1611         tdsaUpdateMCN(dmRoot, onePortContext);
1612 #endif
1613       }
1614       else if (PortState == OSSA_PORT_LOSTCOMM)
1615       {
1616         /*
1617          1. Mark the port as invalid and stop the io for that port and its device
1618          No ack here. Otherwise, port will be released by FW.
1619         */
1620         TI_DBG2(("ossaHwCB: phy Down and OSSA_PORT_LOSTCOMM\n"));
1621         /* save eventSource related information in tdsaAllShared */
1622         tdsaAllShared->eventSource[PhyID].EventValid =  agTRUE;
1623         tdsaAllShared->eventSource[PhyID].Source.agPortContext =  agPortContext;
1624         tdsaAllShared->eventSource[PhyID].Source.event =  OSSA_HW_EVENT_PHY_DOWN;
1625         /* phy ID */
1626         tdsaAllShared->eventSource[PhyID].Source.param =  PhyID;
1627         /* phy ID */
1628         onePortContext->eventPhyID = PhyID;
1629         /* to stop IO's */
1630         onePortContext->valid = agFALSE;
1631         break;
1632       }
1633       else if (PortState == OSSA_PORT_IN_RESET)
1634       {
1635         TI_DBG2(("ossaHwCB: phy Down and OSSA_PORT_IN_RESET\n"));
1636         /* save eventSource related information in tdsaAllShared */
1637         tdsaAllShared->eventSource[PhyID].EventValid =  agTRUE;
1638         tdsaAllShared->eventSource[PhyID].Source.agPortContext =  agPortContext;
1639         tdsaAllShared->eventSource[PhyID].Source.event =  OSSA_HW_EVENT_PHY_DOWN;
1640         /* phy ID */
1641         tdsaAllShared->eventSource[PhyID].Source.param =  PhyID;
1642         /* phy ID */
1643         onePortContext->eventPhyID = PhyID;
1644         /* to stop IO's */
1645         onePortContext->valid = agFALSE;
1646         break;
1647       }
1648       else if (PortState == OSSA_PORT_INVALID)
1649       {
1650         TI_DBG1(("ossaHwCB: Last phy Down and port invalid OSSA_PORT_INVALID\n"));
1651         /*
1652           invalidate port
1653           then, saHwEventAck() in ossaDeregisterDeviceHandleCB()
1654         */
1655 
1656         /* save eventSource related information in tdsaAllShared */
1657         tdsaAllShared->eventSource[PhyID].EventValid =  agTRUE;
1658         tdsaAllShared->eventSource[PhyID].Source.agPortContext =  agPortContext;
1659         tdsaAllShared->eventSource[PhyID].Source.event =  OSSA_HW_EVENT_PHY_DOWN;
1660         /* phy ID */
1661         tdsaAllShared->eventSource[PhyID].Source.param =  PhyID;
1662         /* phy ID */
1663         onePortContext->eventPhyID = PhyID;
1664 
1665         onePortContext->valid = agFALSE;
1666 
1667         TI_DBG2(("ossaHwCB: pid %d\n", onePortContext->id));
1668 #ifdef INITIATOR_DRIVER
1669         /* notifying link down (all links belonging to a port are down) */
1670         ostiPortEvent(
1671                       tiRoot,
1672                       tiPortStopped,
1673                       tiSuccess,
1674                       (void *)onePortContext->tiPortalContext
1675                       );
1676 #endif
1677 
1678 #ifdef TARGET_DRIVER
1679         ostiPortEvent(
1680                       tiRoot,
1681                       tiPortLinkDown,
1682                       tiSuccess,
1683                       (void *)onePortContext->tiPortalContext
1684                       );
1685 
1686 #endif
1687 
1688 #ifdef INITIATOR_DRIVER
1689         tdssReportRemovals(agRoot,
1690                          onePortContext,
1691                          agFALSE
1692                         );
1693 #endif
1694 #ifdef TARGET_DRIVER
1695         ttdssReportRemovals(agRoot,
1696                             onePortContext,
1697                             agFALSE
1698                            );
1699 
1700 #endif
1701 
1702         /* find a PhyID and reset for portContext in tdssSASShared */
1703         for(i=0;i<TD_MAX_NUM_PHYS;i++)
1704         {
1705           if (onePortContext->PhyIDList[i] == agTRUE)
1706           {
1707             tdsaAllShared->Ports[i].portContext = agNULL;
1708           }
1709         }
1710     /* portcontext is removed from MainLink to FreeLink in tdssReportRemovals or
1711        ossaDeregisterDeviceHandleCB
1712      */
1713       }/* OSSA_PORT_INVALID */
1714       else
1715       {
1716         /* other newly defined port state */
1717         /* do nothing */
1718         TI_DBG2(("ossaHwCB: portstate 0x%x\n", PortState));
1719       }
1720     } /* big else */
1721     break;
1722   }
1723   case OSSA_HW_EVENT_PHY_START_STATUS:
1724   {
1725     PhyID = TD_GET_PHY_ID(eventParm1);
1726     PhyStatus =  TD_GET_PHY_STATUS(eventParm1);
1727 
1728     TI_DBG6(("ossaHwCB: OSSA_HW_EVENT_PHY_START_STATUS\n"));
1729     if (PhyStatus == 0x00)
1730     {
1731       TI_DBG6(("ossaHwCB: OSSA_HW_EVENT_PHY_START_STATUS, SUCCESS\n"));
1732     }
1733     else if (PhyStatus == 0x01)
1734     {
1735       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_START_STATUS, INVALID_PHY\n"));
1736     }
1737     else if (PhyStatus == 0x02)
1738     {
1739       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_START_STATUS, PHY_NOT_DISABLED\n"));
1740     }
1741     else
1742     {
1743       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_START_STATUS, OTHER_FAILURE %d\n", PhyStatus));
1744     }
1745     break;
1746   }
1747   case OSSA_HW_EVENT_PHY_STOP_STATUS:
1748   {
1749     agsaContext_t     *agContext;
1750     PhyID = TD_GET_PHY_ID(eventParm1);
1751     PhyStatus =  TD_GET_PHY_STATUS(eventParm1);
1752     PortState = TD_GET_PORT_STATE(eventParm1);
1753 
1754     TI_DBG2(("ossaHwCB: OSSA_HW_EVENT_PHY_STOP_STATUS\n"));
1755     if (PhyStatus == 0x00)
1756     {
1757       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_STOP_STATUS, SUCCESS\n"));
1758       agContext = (agsaContext_t *)eventParm2;
1759       onePortContext  = (tdsaPortContext_t *)agContext->osData;
1760       if (onePortContext == agNULL)
1761       {
1762         TI_DBG1(("ossaHwCB: onePortContext is null, wrong!!!\n"));
1763         return;
1764       }
1765       onePortContext->PhyIDList[PhyID] = agFALSE;
1766       if (PortState == OSSA_PORT_INVALID) /* invalid port */
1767       {
1768         TI_DBG1(("ossaHwCB: OSSA_PORT_INVALID\n"));
1769         tdsaAllShared->eventSource[PhyID].EventValid =  NO_ACK;
1770         onePortContext->eventPhyID = PhyID;
1771         onePortContext->valid = agFALSE;
1772 
1773         TI_DBG2(("ossaHwCB: pid %d\n", onePortContext->id));
1774 #ifdef INITIATOR_DRIVER
1775         /* notifying link down (all links belonging to a port are down) */
1776         ostiPortEvent(
1777                       tiRoot,
1778                       tiPortStopped,
1779                       tiSuccess,
1780                       (void *)onePortContext->tiPortalContext
1781                       );
1782 #endif
1783 
1784 #ifdef TARGET_DRIVER
1785         ostiPortEvent(
1786                       tiRoot,
1787                       tiPortLinkDown,
1788                       tiSuccess,
1789                       (void *)onePortContext->tiPortalContext
1790                       );
1791 
1792 #endif
1793 
1794 #ifdef INITIATOR_DRIVER
1795         tdssReportRemovals(agRoot,
1796                            onePortContext,
1797                            agFALSE
1798                           );
1799 #endif
1800 #ifdef TARGET_DRIVER
1801         ttdssReportRemovals(agRoot,
1802                             onePortContext,
1803                             agFALSE
1804                            );
1805 
1806 #endif
1807 
1808         /* find a PhyID and reset for portContext in tdssSASShared */
1809         for(i=0;i<TD_MAX_NUM_PHYS;i++)
1810         {
1811           if (onePortContext->PhyIDList[i] == agTRUE)
1812           {
1813             tdsaAllShared->Ports[i].portContext = agNULL;
1814           }
1815         }
1816     /* portcontext is removed from MainLink to FreeLink in tdssReportRemovals or
1817        ossaDeregisterDeviceHandleCB
1818      */
1819       } /* invalid port */
1820     }
1821     else if (PhyStatus == 0x01)
1822     {
1823       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_STOP_STATUS, INVALID_PHY\n"));
1824     }
1825     else if (PhyStatus == 0x02)
1826     {
1827       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_STOP_STATUS, DEVICES_ATTACHED\n"));
1828     }
1829     else if (PhyStatus == 0x03)
1830     {
1831       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_STOP_STATUS, OTHER_FAILURE\n"));
1832     }
1833     else if (PhyStatus == 0x04)
1834     {
1835       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_STOP_STATUS, PHY_NOT_DISABLED\n"));
1836     }
1837     else
1838     {
1839       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_STOP_STATUS, Unknown %d\n", PhyStatus));
1840     }
1841     break;
1842   }
1843 
1844   case OSSA_HW_EVENT_RESET_START:
1845   {
1846     bit32 new_status = TD_GET_RESET_STATUS(eventParm1);
1847     TI_DBG2(("ossaHwCB: RESET_START, status %d\n", new_status));
1848     if (new_status == OSSA_SUCCESS)
1849     {
1850       tdsaAllShared->flags.resetInProgress = agTRUE;
1851       TI_DBG2(("ossaHwCB: RESET_START, SUCCESS\n"));
1852     }
1853     else if (new_status == OSSA_FAILURE)
1854     {
1855       TI_DBG1(("ossaHwCB: RESET_START, FAILURE\n"));
1856     }
1857     else
1858     {
1859       TI_DBG1(("ossaHwCB: RESET_START, PENDING\n"));
1860     }
1861     break;
1862   }
1863 
1864   case OSSA_HW_EVENT_RESET_COMPLETE:
1865   {
1866     bit32 new_status = TD_GET_RESET_STATUS(eventParm1);
1867 #ifdef SOFT_RESET_TEST
1868     DbgPrint("Reset Complete\n");
1869 #endif
1870     TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_RESET_COMPLETE, status %d\n", new_status));
1871     if (new_status == OSSA_SUCCESS)
1872     {
1873       /* remove all portcontext and devices */
1874 #ifdef INITIATOR_DRIVER
1875       tdssRemoveSASSATAFromSharedcontextByReset(agRoot);
1876 #endif
1877       tdsaAllShared->flags.resetInProgress = agFALSE;
1878       /*
1879         a callback notifying reset completion
1880       */
1881       ostiPortEvent(
1882                     tiRoot,
1883                     tiPortResetComplete,
1884                     tiSuccess,
1885                     agNULL
1886                     );
1887     }
1888     else
1889     {
1890       /*
1891         a callback notifying reset completion
1892       */
1893       tdsaAllShared->flags.resetInProgress = agFALSE;
1894       ostiPortEvent(
1895                     tiRoot,
1896                     tiPortResetComplete,
1897                     tiError,
1898                     agNULL
1899                     );
1900 
1901     }
1902     break;
1903   }
1904 
1905   case OSSA_HW_EVENT_PHY_ERR_INBOUND_CRC:
1906   {
1907     PhyID = TD_GET_PHY_ID(eventParm1);
1908     PortState = TD_GET_PORT_STATE(eventParm1);
1909     agPhyErrCountersPage = (agsaPhyErrCountersPage_t *)eventParm2;
1910 
1911     TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_INBOUND_CRC from PhyID %d; to be tested\n", PhyID));
1912 
1913     if (PortState == OSSA_PORT_INVALID)
1914     {
1915       TI_DBG1(("ossaHwCB: Wrong port state with OSSA_HW_EVENT_PHY_ERR_INBOUND_CRC\n"));
1916       smTraceFuncExit(hpDBG_VERY_LOUD, 'n', "Y2");
1917       return;
1918     }
1919 
1920     if (agPhyErrCountersPage != agNULL)
1921     {
1922       TI_DBG2(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_INBOUND_CRC from PhyID %d\n", PhyID));
1923       TI_DBG1(("ossaHwCB: iDw %d rDE %d cV %d lS %d rP %d iCRC %d\n",
1924                         agPhyErrCountersPage->invalidDword,
1925                         agPhyErrCountersPage->runningDisparityError,
1926                         agPhyErrCountersPage->codeViolation,
1927                         agPhyErrCountersPage->lossOfDwordSynch,
1928                         agPhyErrCountersPage->phyResetProblem,
1929                         agPhyErrCountersPage->inboundCRCError ));
1930     }
1931     else
1932     {
1933       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_INBOUND_CRC: Error!!!  eventParm2 is NULL\n"));
1934     }
1935 
1936     /* saHwEventAck() */
1937     eventSource.agPortContext = agPortContext;
1938     eventSource.event = OSSA_HW_EVENT_PHY_ERR_INBOUND_CRC;
1939     /* phy ID */
1940     eventSource.param = PhyID;
1941     HwAckSatus = saHwEventAck(
1942                               agRoot,
1943                               agNULL, /* agContext */
1944                               0,
1945                               &eventSource, /* agsaEventSource_t */
1946                               0,
1947                               0
1948                               );
1949     if ( HwAckSatus != AGSA_RC_SUCCESS)
1950     {
1951       TI_DBG1(("ossaHwCB: failing in saHwEventAck; status %d\n", HwAckSatus));
1952       smTraceFuncExit(hpDBG_VERY_LOUD, 'o', "Y2");
1953       return;
1954     }
1955     break;
1956   }
1957 #ifdef REMOVED
1958   case OSSA_HW_EVENT_PORT_INVALID:
1959   {
1960     TI_DBG1(("ossaHwCB: PORT_INVALID\n"));
1961 
1962     if ( agPortContext == agNULL)
1963     {
1964       TI_DBG1(("ossaHwCB: agPortContext is NULL, wrong.\n"));
1965       smTraceFuncExit(hpDBG_VERY_LOUD, 'p', "Y2");
1966       return;
1967     }
1968     if ( agPortContext->osData != agNULL)
1969     {
1970       TI_DBG1(("ossaHwCB: NOT NULL osDATA\n"));
1971       /*
1972         put the old portcontext back to free list
1973       */
1974       onePortContext = (tdsaPortContext_t *)agPortContext->osData;
1975       TI_DBG1(("ossaHwCB: pid %d\n", onePortContext->id));
1976 
1977 #ifdef INITIATOR_DRIVER
1978       /* notifying link down (all links belonging to a port are down) */
1979       ostiPortEvent (
1980                      tiRoot,
1981                      tiPortStopped,
1982                      tiSuccess,
1983                      (void *)onePortContext->tiPortalContext
1984 
1985                      );
1986 #endif /* INITIATOR_DRIVER */
1987 #ifdef TARGET_DRIVER
1988         ostiPortEvent(
1989                       tiRoot,
1990                       tiPortLinkDown,
1991                       tiSuccess,
1992                       (void *)onePortContext->tiPortalContext
1993                       );
1994 
1995 #endif /*TARGET_DRIVER  */
1996 
1997       /* find the device belonging to the port and remove it from the device list */
1998       //tdssRemoveSASSATAFromSharedcontext(agRoot, tdsaDeviceData, onePortContext);
1999 
2000 
2001 #ifdef INITIATOR_DRIVER
2002       /* reset the fields of portcontext */
2003       onePortContext->DiscoveryState = ITD_DSTATE_NOT_STARTED;
2004       tdssReportRemovals(agRoot,
2005                          onePortContext,
2006                          agFALSE
2007                         );
2008 
2009       onePortContext->discoveryOptions = AG_SA_DISCOVERY_OPTION_FULL_START;
2010       onePortContext->DiscoveryRdyGiven = agFALSE;
2011       onePortContext->SeenLinkUp = agFALSE;
2012 
2013 #endif /* INITIATOR_DRIVER */
2014 
2015 
2016 
2017       /* for hotplug */
2018 
2019       /* find a PhyID and reset for portContext in tdssSASShared */
2020       for(i=0;i<TD_MAX_NUM_PHYS;i++)
2021       {
2022         if (onePortContext->PhyIDList[i] == agTRUE)
2023         {
2024           tdsaAllShared->Ports[i].portContext = agNULL;
2025         }
2026       }
2027 
2028       /* reset PhyIDList in portcontext */
2029       for(i=0;i<TD_MAX_NUM_PHYS;i++)
2030       {
2031         onePortContext->PhyIDList[i] = agFALSE;
2032       }
2033 
2034 //      onePortContext->tiPortalContext = agNULL;
2035 //      onePortContext->agRoot = agNULL;
2036       onePortContext->agPortContext = agNULL;
2037       onePortContext->valid = agFALSE;
2038 
2039       TI_DBG4(("ossaHwCB: pid %d count %d\n", onePortContext->id, onePortContext->Count));
2040 
2041       /* resets the number of devices in onePortContext */
2042       onePortContext->Count = 0;
2043       onePortContext->discovery.pendingSMP = 0;
2044       onePortContext->discovery.SeenBC = agFALSE;
2045 
2046 
2047       /*
2048         put all devices belonging to the onePortContext
2049         back to the free link
2050       */
2051 
2052       tdsaSingleThreadedEnter(tiRoot, TD_PORT_LOCK);
2053       TDLIST_DEQUEUE_THIS(&(onePortContext->MainLink));
2054       TDLIST_ENQUEUE_AT_TAIL(&(onePortContext->FreeLink), &(tdsaPortContext->FreeLink));
2055       tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
2056     }
2057     else
2058     {
2059       TI_DBG1(("ossaHwCB: NULL osDATA: wrong\n"));
2060     }
2061     TI_DBG6(("ossaHwCB: PORT_INVALID end\n"));
2062     break;
2063   }
2064 #endif /* REMOVED */
2065 
2066   case OSSA_HW_EVENT_BROADCAST_CHANGE:
2067   {
2068     PhyID = TD_GET_PHY_ID(eventParm1);
2069     PortState = TD_GET_PORT_STATE(eventParm1);
2070     TI_DBG1(("ossaHwCB: BROADCAST_CHANGE from PhyID %d\n", PhyID));
2071 
2072     if (PortState == OSSA_PORT_INVALID)
2073     {
2074       TI_DBG1(("ossaHwCB: Wrong port state with  BROADCAST_CHANGE\n"));
2075       smTraceFuncExit(hpDBG_VERY_LOUD, 'q', "Y2");
2076       return;
2077     }
2078     /* saHwEventAck() */
2079     eventSource.agPortContext = agPortContext;
2080     eventSource.event = OSSA_HW_EVENT_BROADCAST_CHANGE;
2081     /* phy ID */
2082     eventSource.param = PhyID;
2083     HwAckSatus = saHwEventAck(
2084                               agRoot,
2085                               agNULL, /* agContext */
2086                               0,
2087                               &eventSource, /* agsaEventSource_t */
2088                               0,
2089                               0
2090                               );
2091     TI_DBG4(("ossaHwCB: calling saHwEventAck\n"));
2092 
2093     if ( HwAckSatus != AGSA_RC_SUCCESS)
2094     {
2095       TI_DBG1(("ossaHwCB: failing in saHwEventAck; status %d\n", HwAckSatus));
2096       smTraceFuncExit(hpDBG_VERY_LOUD, 'r', "Y2");
2097       return;
2098     }
2099     if (tIsSPC12SATA(agRoot))
2100     {
2101       TI_DBG1(("ossaHwCB: BROADCAST_CHANGE received for SATA Controller\n"));
2102       break;
2103     }
2104     /*
2105      * incremental discovery is to be tested and debugged further
2106      */
2107 
2108      /* just for testing discovery abort */
2109 #ifdef FDS_DM_NO
2110     if (agPortContext == agNULL)
2111     {
2112       /* this case happens when broadcase is received first before the link up */
2113       TI_DBG2(("ossaHwCB: agPortContext is NULL. Do nothing.\n"));
2114     }
2115     else if ( agPortContext->osData != agNULL)
2116     {
2117       dmRoot = &(tdsaAllShared->dmRoot);
2118       onePortContext = (tdsaPortContext_t *)agPortContext->osData;
2119       dmPortContext = &(onePortContext->dmPortContext);
2120 
2121       dmQueryDiscovery(dmRoot, dmPortContext);
2122 //      dmDiscover(dmRoot, dmPortContext, DM_DISCOVERY_OPTION_ABORT);
2123 
2124 #if 1
2125       if (onePortContext->DMDiscoveryState == dmDiscInProgress)
2126       {
2127         dmDiscover(dmRoot, dmPortContext, DM_DISCOVERY_OPTION_ABORT);
2128       }
2129 #endif /* 1 */
2130 
2131       TI_DBG2(("ossaHwCB: portcontext pid %d\n", onePortContext->id));
2132       if (onePortContext->DMDiscoveryState == dmDiscCompleted ||
2133           onePortContext->DMDiscoveryState == dmDiscAborted ||
2134           onePortContext->DMDiscoveryState == dmDiscAbortInvalid )
2135       {
2136         TI_DBG1(("ossaHwCB: BROADCAST_CHANGE; calling dmNotifyBC and does incremental discovery\n"));
2137         dmNotifyBC(dmRoot, dmPortContext, OSSA_HW_EVENT_BROADCAST_CHANGE);
2138         dmDiscover(dmRoot, dmPortContext, DM_DISCOVERY_OPTION_INCREMENTAL_START);
2139 
2140       }
2141       else
2142       {
2143         TI_DBG2(("ossaHwCB: pid %d BROADCAST_CHANGE; updating SeenBC. calling dmNotifyBC\n", onePortContext->id));
2144         dmNotifyBC(dmRoot, dmPortContext, OSSA_HW_EVENT_BROADCAST_CHANGE);
2145       }
2146     }
2147     else
2148     {
2149       TI_DBG1(("ossaHwCB: BROADCAST_CHANGE NULL osDATA wrong !!! \n"));
2150     }
2151 
2152 
2153 #endif /* FDS_DM_NO */
2154 
2155 #ifdef FDS_DM
2156     if (agPortContext == agNULL)
2157     {
2158       /* this case happens when broadcase is received first before the link up */
2159       TI_DBG2(("ossaHwCB: agPortContext is NULL. Do nothing.\n"));
2160     }
2161     else if ( agPortContext->osData != agNULL)
2162     {
2163       dmRoot = &(tdsaAllShared->dmRoot);
2164       onePortContext = (tdsaPortContext_t *)agPortContext->osData;
2165       dmPortContext = &(onePortContext->dmPortContext);
2166 
2167       dmQueryDiscovery(dmRoot, dmPortContext);
2168 
2169       TI_DBG2(("ossaHwCB: portcontext pid %d\n", onePortContext->id));
2170       if (onePortContext->DMDiscoveryState == dmDiscCompleted ||
2171           onePortContext->DMDiscoveryState == dmDiscAborted ||
2172           onePortContext->DMDiscoveryState == dmDiscAbortInvalid )
2173       {
2174         TI_DBG1(("ossaHwCB: BROADCAST_CHANGE; calling dmNotifyBC and does incremental discovery, pid %d\n", onePortContext->id));
2175         onePortContext->DiscoveryState = ITD_DSTATE_STARTED;
2176         dmNotifyBC(dmRoot, dmPortContext, OSSA_HW_EVENT_BROADCAST_CHANGE);
2177         dmDiscover(dmRoot, dmPortContext, DM_DISCOVERY_OPTION_INCREMENTAL_START);
2178 
2179       }
2180       else if (onePortContext->DMDiscoveryState == dmDiscFailed )
2181       {
2182         TI_DBG1(("ossaHwCB: dmDiscFailed; pid %d BROADCAST_CHANGE; updating SeenBC. calling dmNotifyBC\n", onePortContext->id));
2183         onePortContext->DiscFailNSeenBC = agTRUE;
2184         dmNotifyBC(dmRoot, dmPortContext, OSSA_HW_EVENT_BROADCAST_CHANGE);
2185       }
2186       else
2187       {
2188         TI_DBG2(("ossaHwCB: pid %d BROADCAST_CHANGE; updating SeenBC. calling dmNotifyBC\n", onePortContext->id));
2189         dmNotifyBC(dmRoot, dmPortContext, OSSA_HW_EVENT_BROADCAST_CHANGE);
2190       }
2191     }
2192     else
2193     {
2194       TI_DBG1(("ossaHwCB: BROADCAST_CHANGE NULL osDATA wrong !!! \n"));
2195     }
2196 #endif /* FDS_DM */
2197 
2198 #ifdef FDS_DM_WORKED
2199     if (agPortContext == agNULL)
2200     {
2201       /* this case happens when broadcase is received first before the link up */
2202       TI_DBG2(("ossaHwCB: agPortContext is NULL. Do nothing.\n"));
2203     }
2204     else if ( agPortContext->osData != agNULL)
2205     {
2206       onePortContext = (tdsaPortContext_t *)agPortContext->osData;
2207       TI_DBG2(("ossaHwCB: calling dmNotifyBC\n"));
2208       dmRoot = &(tdsaAllShared->dmRoot);
2209       dmPortContext = &(onePortContext->dmPortContext);
2210       dmNotifyBC(dmRoot, dmPortContext, OSSA_HW_EVENT_BROADCAST_CHANGE);
2211     }
2212 #endif /* FDS_DM_WORKED */
2213 
2214 #ifndef FDS_DM
2215 #ifdef INITIATOR_DRIVER
2216     if (agPortContext == agNULL)
2217     {
2218       /* this case happens when broadcase is received first before the link up */
2219       TI_DBG2(("ossaHwCB: agPortContext is NULL. Do nothing.\n"));
2220     }
2221     else if ( agPortContext->osData != agNULL)
2222     {
2223       onePortContext = (tdsaPortContext_t *)agPortContext->osData;
2224       TI_DBG2(("ossaHwCB: portcontext pid %d\n", onePortContext->id));
2225       if (onePortContext->DiscoveryState == ITD_DSTATE_COMPLETED)
2226       {
2227         TI_DBG1(("ossaHwCB: BROADCAST_CHANGE; does incremental discovery\n"));
2228         onePortContext->DiscoveryState = ITD_DSTATE_NOT_STARTED;
2229         onePortContext->discoveryOptions = AG_SA_DISCOVERY_OPTION_INCREMENTAL_START;
2230         /* processed broadcast change */
2231         onePortContext->discovery.SeenBC = agFALSE;
2232 #ifdef TD_DISCOVER
2233         if (tdsaAllShared->ResetInDiscovery != 0 &&
2234             onePortContext->discovery.ResetTriggerred == agTRUE)
2235         {
2236           TI_DBG2(("ossaHwCB: tdsaBCTimer\n"));
2237           tdsaBCTimer(tiRoot, onePortContext);
2238         }
2239         else
2240         {
2241           tdsaDiscover(
2242                      tiRoot,
2243                      onePortContext,
2244                      TDSA_DISCOVERY_TYPE_SAS,
2245                      TDSA_DISCOVERY_OPTION_INCREMENTAL_START
2246                     );
2247         }
2248 #else
2249         saDiscover(agRoot,
2250                    agPortContext,
2251                    AG_SA_DISCOVERY_TYPE_SAS,
2252                    onePortContext->discoveryOptions);
2253 #endif
2254       }
2255       else
2256       {
2257         TI_DBG2(("ossaHwCB: pid %d BROADCAST_CHANGE; updating SeenBC. Do nothing.\n", onePortContext->id));
2258         onePortContext->discovery.SeenBC = agTRUE;
2259       }
2260     }
2261     else
2262     {
2263       TI_DBG1(("ossaHwCB: BROADCAST_CHANGE NULL osDATA wrong !!! \n"));
2264     }
2265 #endif
2266 #endif /* ifndef FDS_DM */
2267 
2268     break;
2269   }
2270 
2271   case OSSA_HW_EVENT_PORT_RECOVERY_TIMER_TMO:
2272   {
2273     PhyID = TD_GET_PHY_ID(eventParm1);
2274     PortState = TD_GET_PORT_STATE(eventParm1);
2275 
2276     /*
2277       1. tear town the portcontext just like link down last phy down
2278       2. ack
2279       port state must be invalid
2280     */
2281 
2282     TI_DBG2(("ossaHwCB: OSSA_HW_EVENT_PORT_RECOVERY_TIMER_TMO\n"));
2283 
2284     if (PortState == OSSA_PORT_VALID)
2285     {
2286       TI_DBG1(("ossaHwCB: Wrong port state\n"));
2287       smTraceFuncExit(hpDBG_VERY_LOUD, 's', "Y2");
2288       return;
2289     }
2290 
2291     TD_ASSERT(agPortContext, "agPortContext");
2292     if ( agPortContext->osData == agNULL)
2293     { /* if */
2294       /* PortContext must exit at this point */
2295       TI_DBG1(("ossaHwCB: NULL portalcontext. Error. Can't be NULL\n"));
2296     }
2297     else
2298     {
2299       onePortContext  = (tdsaPortContext_t *)agPortContext->osData;
2300       onePortContext->valid = agFALSE;
2301 
2302       TI_DBG1(("ossaHwCB: tiPortStopped pid %d\n", onePortContext->id));
2303 #ifdef INITIATOR_DRIVER
2304       /* notifying link down (all links belonging to a port are down) */
2305       ostiPortEvent(
2306                     tiRoot,
2307                     tiPortStopped,
2308                     tiSuccess,
2309                     (void *)onePortContext->tiPortalContext
2310                     );
2311 #endif
2312 
2313 #ifdef TARGET_DRIVER
2314         ostiPortEvent(
2315                       tiRoot,
2316                       tiPortLinkDown,
2317                       tiSuccess,
2318                       (void *)onePortContext->tiPortalContext
2319                       );
2320 
2321 #endif
2322 
2323 #ifdef INITIATOR_DRIVER
2324       tdssReportRemovals(agRoot,
2325                          onePortContext,
2326                          agFALSE
2327                          );
2328 #endif
2329 #ifdef TARGET_DRIVER
2330       ttdssReportRemovals(agRoot,
2331                           onePortContext,
2332                           agFALSE
2333                          );
2334 
2335 #endif
2336       /* find a PhyID and reset for portContext in tdssSASShared */
2337       for(i=0;i<TD_MAX_NUM_PHYS;i++)
2338       {
2339         if (onePortContext->PhyIDList[i] == agTRUE)
2340         {
2341           tdsaAllShared->Ports[i].portContext = agNULL;
2342         }
2343       }
2344       /* portcontext is removed from MainLink to FreeLink in tdssReportRemovals or
2345          ossaDeregisterDeviceHandleCB
2346        */
2347     }
2348 
2349     break;
2350   }
2351 
2352   case OSSA_HW_EVENT_PORT_RESET_TIMER_TMO:
2353   {
2354     /*
2355        clean up
2356     */
2357     PhyID = TD_GET_PHY_ID(eventParm1);
2358     PortState = TD_GET_PORT_STATE(eventParm1);
2359 
2360     TI_DBG2(("ossaHwCB: OSSA_HW_EVENT_PORT_RESET_TIMER_TMO\n"));
2361 
2362     if (PortState == OSSA_PORT_VALID)
2363     {
2364       TI_DBG1(("ossaHwCB: Wrong port state\n"));
2365       smTraceFuncExit(hpDBG_VERY_LOUD, 't', "Y2");
2366       return;
2367     }
2368 
2369     if (agPortContext == agNULL)
2370     {
2371       TI_DBG1(("ossaHwCB: agPortContext is NULL, error\n"));
2372       smTraceFuncExit(hpDBG_VERY_LOUD, 'u', "Y2");
2373       return;
2374     }
2375 
2376     if ( agPortContext->osData == agNULL)
2377     { /* if */
2378       /* PortContext must exit at this point */
2379       TI_DBG1(("ossaHwCB: NULL portalcontext. Error. Can't be NULL\n"));
2380     }
2381     else
2382     {
2383       onePortContext  = (tdsaPortContext_t *)agPortContext->osData;
2384       onePortContext->valid = agFALSE;
2385 
2386       TI_DBG1(("ossaHwCB: pid %d tiPortStopped\n", onePortContext->id));
2387 
2388 #ifdef INITIATOR_DRIVER
2389       /* notifying link down (all links belonging to a port are down) */
2390       ostiPortEvent(
2391                     tiRoot,
2392                     tiPortStopped,
2393                     tiSuccess,
2394                     (void *)onePortContext->tiPortalContext
2395                     );
2396 #endif
2397 
2398 #ifdef TARGET_DRIVER
2399         ostiPortEvent(
2400                       tiRoot,
2401                       tiPortLinkDown,
2402                       tiSuccess,
2403                       (void *)onePortContext->tiPortalContext
2404                       );
2405 
2406 #endif
2407 
2408 #ifdef INITIATOR_DRIVER
2409       tdssReportRemovals(agRoot,
2410                          onePortContext,
2411                          agFALSE
2412                          );
2413 #endif
2414 #ifdef TARGET_DRIVER
2415       ttdssReportRemovals(agRoot,
2416                           onePortContext,
2417                           agFALSE
2418                          );
2419 
2420 #endif
2421       /* find a PhyID and reset for portContext in tdssSASShared */
2422       for(i=0;i<TD_MAX_NUM_PHYS;i++)
2423       {
2424         if (onePortContext->PhyIDList[i] == agTRUE)
2425         {
2426           tdsaAllShared->Ports[i].portContext = agNULL;
2427         }
2428       }
2429       /* portcontext is removed from MainLink to FreeLink in tdssReportRemovals or
2430          ossaDeregisterDeviceHandleCB
2431        */
2432     }
2433 
2434     break;
2435   }
2436 
2437   case OSSA_HW_EVENT_PORT_RESET_COMPLETE:
2438   {
2439 #ifdef INITIATOR_DRIVER
2440     tiIORequest_t *currentTaskTag = agNULL;
2441 #endif
2442 
2443 #ifdef REMOVED
2444     smRoot_t  *smRoot = &(tdsaAllShared->smRoot);
2445 #endif
2446 
2447     PhyID = TD_GET_PHY_ID(eventParm1);
2448     PortState = TD_GET_PORT_STATE(eventParm1);
2449     IDframe = (agsaSASIdentify_t *)eventParm3;
2450 
2451     /* completes for Lun Reset and Target reset for directly attached SATA */
2452     /* completes for Target reset for directly attached SAS */
2453 
2454     TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PORT_RESET_COMPLETE, phyID %d\n", PhyID));
2455 
2456     /* error check */
2457     if (PortState == OSSA_PORT_INVALID)
2458     {
2459       TI_DBG1(("ossaHwCB: Wrong port state\n"));
2460       smTraceFuncExit(hpDBG_VERY_LOUD, 'v', "Y2");
2461       return;
2462     }
2463 
2464     if (agPortContext == agNULL)
2465     {
2466       TI_DBG1(("ossaHwCB: agPortContext null, wrong\n"));
2467       smTraceFuncExit(hpDBG_VERY_LOUD, 'w', "Y2");
2468       return;
2469     }
2470     if ( agPortContext->osData == agNULL)
2471     {
2472       TI_DBG1(("ossaHwCB: agPortContext->osData null, wrong\n"));
2473       smTraceFuncExit(hpDBG_VERY_LOUD, 'x', "Y2");
2474       return;
2475     }
2476 
2477     /* find a corresponding portcontext */
2478     onePortContext  = (tdsaPortContext_t *)agPortContext->osData;
2479 
2480     if (onePortContext == agNULL)
2481     {
2482       TI_DBG1(("ossaHwCB: oneportContext is NULL; wrong??????\n"));
2483     }
2484     else
2485     {
2486       TI_DBG1(("ossaHwCB: oneportContext %p pid %d\n", onePortContext, onePortContext->id));
2487       onePortContext->valid = agTRUE;
2488 #ifdef INITIATOR_DRIVER
2489 #ifdef REMOVED
2490       if (tdsaAllShared->ResetInDiscovery != 0)
2491       {
2492         DeviceListList = tdsaAllShared->MainDeviceList.flink;
2493         while (DeviceListList != &(tdsaAllShared->MainDeviceList))
2494         {
2495           oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
2496           if (oneDeviceData->tdPortContext != onePortContext)
2497           {
2498             DeviceListList = DeviceListList->flink;
2499           }
2500           else
2501           {
2502             found = agTRUE;
2503             break;
2504           }
2505         } /* while */
2506         if (found == agTRUE)
2507         {
2508           /* applied to only SATA devices */
2509           if (DEVICE_IS_SATA_DEVICE(oneDeviceData) || DEVICE_IS_STP_TARGET(oneDeviceData))
2510           {
2511           #ifdef FDS_SM
2512             tdIDStart(tiRoot, agRoot, smRoot, oneDeviceData, onePortContext);
2513           #else
2514             tdssRetrySATAID(tiRoot, oneDeviceData);
2515           #endif
2516           }
2517         }
2518         else
2519         {
2520           TI_DBG1(("ossaHwCB: no onedevicedata found!\n"));
2521         }
2522       }
2523 #endif
2524       /* completed TM */
2525       DeviceListList = tdsaAllShared->MainDeviceList.flink;
2526       while (DeviceListList != &(tdsaAllShared->MainDeviceList))
2527       {
2528         oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
2529         if ( oneDeviceData == agNULL)
2530         {
2531           TI_DBG1(("ossaHwCB: oneDeviceData is NULL!!!\n"));
2532           return;
2533         }
2534 
2535         if ( (oneDeviceData->tdPortContext == onePortContext) &&
2536              (oneDeviceData->directlyAttached == agTRUE) &&
2537              (oneDeviceData->phyID == PhyID) )
2538         {
2539           TI_DBG1(("ossaHwCB: found the onePortContext and oneDeviceData!!\n"));
2540 
2541           currentTaskTag = (tiIORequest_t *)oneDeviceData->agDeviceResetContext.osData;
2542           if (currentTaskTag != agNULL )
2543           {
2544             /* applied to only SATA devices */
2545             if (DEVICE_IS_SATA_DEVICE(oneDeviceData))
2546             {
2547                tdIORequestBody_t  *SMTMtdIORequestBody = agNULL;
2548                SMTMtdIORequestBody = (tdIORequestBody_t *)currentTaskTag->tdData;
2549                if (SMTMtdIORequestBody != agNULL)
2550                {
2551                  /* free the SMTMtdIORequestBody memory allocated in tiINITaskManagement function */
2552                  ostiFreeMemory(
2553                        tiRoot,
2554                        SMTMtdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
2555                        sizeof(tdIORequestBody_t)
2556                       );
2557                }
2558                else
2559                {
2560                  TI_DBG1(("ossaHwCB: SATA device but SMTMtdIORequestBody is NULL!!!\n"));
2561                }
2562             }
2563             /* set device state to DS_OPERATIONAL */
2564             saSetDeviceState(agRoot,
2565                             agNULL,
2566                             tdsaRotateQnumber(tiRoot, oneDeviceData),
2567                             oneDeviceData->agDevHandle,
2568                             SA_DS_OPERATIONAL
2569                             );
2570             /* notify OS layer to complete the TMF IO */
2571             ostiInitiatorEvent(tiRoot,
2572                               agNULL,
2573                               agNULL,
2574                               tiIntrEventTypeTaskManagement,
2575                               tiTMOK,
2576                               currentTaskTag
2577                               );
2578 
2579           }
2580           else
2581           {
2582             TI_DBG1(("ossaHwCB: currentTaskTag is NULL!!!\n"));
2583           }
2584 
2585           break;
2586         }
2587         else
2588         {
2589           DeviceListList = DeviceListList->flink;
2590         }
2591       }
2592 #endif
2593     }
2594     break;
2595   }
2596   case OSSA_HW_EVENT_BROADCAST_ASYNCH_EVENT:
2597   {
2598     PhyID = TD_GET_PHY_ID(eventParm1);
2599     PortState = TD_GET_PORT_STATE(eventParm1);
2600 
2601     TI_DBG2(("ossaHwCB: OSSA_HW_EVENT_BROADCAST_ASYNCH_EVENT\n"));
2602     if (tIsSPC12SATA(agRoot))
2603     {
2604       TI_DBG1(("ossaHwCB: BROADCAST_ASYNCH_EVENT received for SATA Controller\n"));
2605       break;
2606     }
2607     if (agPortContext == agNULL)
2608     {
2609       TI_DBG1(("ossaHwCB: Error!!! agPortContext is NULL %d\n", PhyID));
2610       smTraceFuncExit(hpDBG_VERY_LOUD, 'y', "Y2");
2611       return;
2612     }
2613     onePortContext = (tdsaPortContext_t *)agPortContext->osData;
2614     if (onePortContext == agNULL)
2615     {
2616       TI_DBG1(("ossaHwCB: Error!!! onePortContext is NULL %d\n", PhyID));
2617       smTraceFuncExit(hpDBG_VERY_LOUD, 'z', "Y2");
2618       return;
2619     }
2620 
2621     if (onePortContext->tiPortalContext != agNULL)
2622     {
2623 #if 0
2624       ostiInitiatorEvent(
2625                          tiRoot,
2626                          onePortContext->tiPortalContext,
2627                          agNULL,
2628                          tiIntrEventTypeDeviceChange,
2629                          OSSA_HW_EVENT_BROADCAST_ASYNCH_EVENT,
2630                          agNULL
2631                          );
2632 #endif
2633     }
2634     else
2635     {
2636       TI_DBG1(("ossaHwCB: Error!!! onePortContext->tiPortalContext is NULL\n"));
2637       smTraceFuncExit(hpDBG_VERY_LOUD, 'A', "Y2");
2638       return;
2639     }
2640 
2641     break;
2642    }
2643 
2644   case OSSA_HW_EVENT_PORT_RECOVER:
2645   {
2646 
2647     PhyID = TD_GET_PHY_ID(eventParm1);
2648     if (agPortContext == agNULL)
2649     {
2650       TI_DBG1(("ossaHwCB: Error!!! agPortContext is NULL %d\n", PhyID));
2651       smTraceFuncExit(hpDBG_VERY_LOUD, 'B', "Y2");
2652       return;
2653     }
2654 
2655     LinkRate = TD_GET_LINK_RATE(eventParm1);
2656     PortState = TD_GET_PORT_STATE(eventParm1);
2657     agDevHandle = agNULL;
2658     IDframe = (agsaSASIdentify_t *)eventParm3;
2659 
2660     /*
2661       1. this is like link up
2662       2. handle the phyID
2663       3. no trigger discovery (broadcast change will do this later)
2664       port state must be valid
2665     */
2666 
2667     TI_DBG2(("ossaHwCB: OSSA_HW_EVENT_PORT_RECOVER, phyID %d\n", PhyID));
2668 
2669     if (PortState == OSSA_PORT_INVALID)
2670     {
2671       TI_DBG1(("ossaHwCB: Wrong port state\n"));
2672       smTraceFuncExit(hpDBG_VERY_LOUD, 'C', "Y2");
2673       return;
2674     }
2675     if ( agPortContext->osData == agNULL)
2676     { /* if */
2677       /* PortContext must exit at this point */
2678       TI_DBG1(("ossaHwCB: NULL portalcontext. Error. Can't be NULL\n"));
2679     }
2680     else
2681     {
2682       onePortContext  = (tdsaPortContext_t *)agPortContext->osData;
2683       TI_DBG2(("ossaHwCB: pid %d\n", onePortContext->id));
2684       onePortContext->PhyIDList[PhyID] = agTRUE;
2685       onePortContext->valid = agTRUE;
2686       tdsaAllShared->Ports[PhyID].portContext = onePortContext;
2687       onePortContext->tiPortalContext = tdsaAllShared->Ports[PhyID].tiPortalContext;
2688       onePortContext->PortRecoverPhyID = PhyID;
2689       if (LinkRate == 0x01)
2690       {
2691         onePortContext->LinkRate = SAS_CONNECTION_RATE_1_5G;
2692       }
2693       else if (LinkRate == 0x02)
2694       {
2695         onePortContext->LinkRate = SAS_CONNECTION_RATE_3_0G;
2696       }
2697       else if (LinkRate == 0x04)
2698       {
2699         onePortContext->LinkRate = SAS_CONNECTION_RATE_6_0G;
2700       }
2701       else /* (LinkRate == 0x08) */
2702       {
2703         onePortContext->LinkRate = SAS_CONNECTION_RATE_12_0G;
2704       }
2705 
2706       if (SA_IDFRM_GET_DEVICETTYPE(&onePortContext->sasIDframe) == SAS_END_DEVICE &&
2707           SA_IDFRM_IS_SSP_TARGET(&onePortContext->sasIDframe) )
2708       {
2709         TI_DBG2(("ossaHwCB: OSSA_HW_EVENT_PORT_RECOVER, sending spinup on phyID %d\n", PhyID));
2710         for (i=0;i<TD_MAX_NUM_NOTIFY_SPINUP;i++)
2711         {
2712           saLocalPhyControl(agRoot, agNULL, 0, PhyID, AGSA_PHY_NOTIFY_ENABLE_SPINUP, agNULL);
2713         }
2714       }
2715 
2716       /* transient period between link up and link down/port recovery */
2717       if (onePortContext->Transient == agTRUE && onePortContext->RegisteredDevNums == 0)
2718       {
2719         TI_DBG2(("ossaHwCB: OSSA_HW_EVENT_PORT_RECOVER transient period"));
2720         if (SA_IDFRM_GET_DEVICETTYPE(IDframe) != SAS_NO_DEVICE)
2721         {
2722 #ifdef INITIATOR_DRIVER
2723           agSASSubID.sasAddressHi = SA_IDFRM_GET_SAS_ADDRESSHI(IDframe);
2724           agSASSubID.sasAddressLo = SA_IDFRM_GET_SAS_ADDRESSLO(IDframe);
2725           agSASSubID.initiator_ssp_stp_smp = IDframe->initiator_ssp_stp_smp;
2726           agSASSubID.target_ssp_stp_smp = IDframe->target_ssp_stp_smp;
2727           tdssAddSASToSharedcontext(
2728                                     onePortContext,
2729                                     agRoot,
2730                                     agDevHandle, /* agNULL */
2731                                     &agSASSubID,
2732                                     agTRUE,
2733                                     (bit8)PhyID,
2734                                     TD_OPERATION_INITIATOR
2735                                     );
2736 #endif
2737         }
2738         onePortContext->Transient = agFALSE;
2739       }
2740 
2741 
2742 
2743 
2744     }
2745     break;
2746   }
2747 
2748   case OSSA_HW_EVENT_BROADCAST_SES:
2749   {
2750     PhyID = TD_GET_PHY_ID(eventParm1);
2751     PortState = TD_GET_PORT_STATE(eventParm1);
2752 
2753     TI_DBG2(("ossaHwCB: BROADCAST_SES  from PhyID %d; to be tested\n", PhyID));
2754     if (tIsSPC12SATA(agRoot))
2755     {
2756       TI_DBG1(("ossaHwCB: BROADCAST_SES received for SATA Controller\n"));
2757       break;
2758     }
2759     if (PortState == OSSA_PORT_INVALID)
2760     {
2761       TI_DBG1(("ossaHwCB: Wrong port state with  BROADCAST_SES\n"));
2762       smTraceFuncExit(hpDBG_VERY_LOUD, 'D', "Y2");
2763       return;
2764     }
2765 
2766     /*
2767        let os layer read payload
2768     */
2769     break;
2770   }
2771   case OSSA_HW_EVENT_BROADCAST_EXP:
2772   {
2773     PhyID = TD_GET_PHY_ID(eventParm1);
2774     PortState = TD_GET_PORT_STATE(eventParm1);
2775 
2776     TI_DBG2(("ossaHwCB: BROADCAST_EXP from PhyID %d; to be tested\n", PhyID));
2777     if (tIsSPC12SATA(agRoot))
2778     {
2779       TI_DBG1(("ossaHwCB: BROADCAST_EXP received for SATA Controller\n"));
2780       break;
2781     }
2782 
2783     if (PortState == OSSA_PORT_INVALID)
2784     {
2785       TI_DBG1(("ossaHwCB: Wrong port state with  BROADCAST_EXP\n"));
2786       smTraceFuncExit(hpDBG_VERY_LOUD, 'E', "Y2");
2787       return;
2788     }
2789     /* to-do:
2790        let os layer read payload
2791     */
2792     break;
2793   }
2794 
2795   case OSSA_HW_EVENT_HARD_RESET_RECEIVED:
2796   {
2797     PhyID = TD_GET_PHY_ID(eventParm1);
2798     PortState = TD_GET_PORT_STATE(eventParm1);
2799 
2800     TI_DBG2(("ossaHwCB: HARD_RESET_RECEIVED from PhyID %d\n", PhyID));
2801 
2802     if (PortState == OSSA_PORT_VALID && tiIS_SPC(agRoot))
2803     {
2804       TI_DBG1(("ossaHwCB: calling saPortControl and OSSA_PORT_VALID\n"));
2805       saPortControl(agRoot, agNULL, 0, agPortContext, AGSA_PORT_HARD_RESET, 0,0);
2806     }
2807     else if (PortState == OSSA_PORT_3RDPARTY_RESET && (tIsSPCV12or6G(agRoot))  )
2808     {
2809       TI_DBG1(("ossaHwCB: calling saPortControl and OSSA_PORT_3RDPARTY_RESET\n"));
2810       saPortControl(agRoot, agNULL, 0, agPortContext, AGSA_PORT_HARD_RESET, 0,0);
2811     }
2812     else /* PortState == OSSA_PORT_INVALID */
2813     {
2814       TI_DBG1(("ossaHwCB: Error. Port state is invalid\n"));
2815 #ifdef REMOVED
2816       TI_DBG1(("ossaHwCB: calling saLocalPhyControl on phyID %d\n", PhyID));
2817       saLocalPhyControl(agRoot, agNULL, 0, PhyID, AGSA_PHY_LINK_RESET, agNULL);
2818 #endif
2819     }
2820 
2821     break;
2822   }
2823 
2824   case OSSA_HW_EVENT_MALFUNCTION:
2825   {
2826 #ifdef TD_DEBUG_ENABLE
2827     agsaFatalErrorInfo_t  *FatalError = (agsaFatalErrorInfo_t *)eventParm2;
2828 #endif
2829     TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_MALFUNCTION \n"));
2830     TI_DBG1(("ossaHwCB: errorInfo0 %8X errorInfo1 %8X\n", FatalError->errorInfo0, FatalError->errorInfo1));
2831     TI_DBG1(("ossaHwCB: errorInfo2 %8X errorInfo3 %8X\n", FatalError->errorInfo2, FatalError->errorInfo3));
2832     TI_DBG1(("ossaHwCB: regDumpBusBaseNum0 %8X regDumpOffset0 %8X regDumpLen0 %8X\n", FatalError->regDumpBusBaseNum0, FatalError->regDumpOffset0, FatalError->regDumpLen0));
2833     TI_DBG1(("ossaHwCB: regDumpBusBaseNum1 %8X regDumpOffset1 %8X regDumpLen1 %8X\n", FatalError->regDumpBusBaseNum1, FatalError->regDumpOffset1, FatalError->regDumpLen1));
2834 
2835 
2836     if (eventParm1 == agTRUE)
2837     {
2838       TI_DBG1(("ossaHwCB: fatal error\n"));
2839       /* port panic */
2840       ostiPortEvent (
2841                      tiRoot,
2842                      tiPortPanic,
2843                      0,
2844                      agNULL
2845                      );
2846     }
2847     else
2848     {
2849       TI_DBG1(("ossaHwCB: non-fatal error \n"));
2850     }
2851     break;
2852   }
2853 
2854   case OSSA_HW_EVENT_ID_FRAME_TIMEOUT:
2855   {
2856     PhyID = TD_GET_PHY_ID(eventParm1);
2857     PortState = TD_GET_PORT_STATE(eventParm1);
2858 
2859     TI_DBG2(("ossaHwCB: OSSA_HW_EVENT_ID_FRAME_TIMEOUT from PhyID %d\n", PhyID));
2860 
2861     if (PortState == OSSA_PORT_INVALID)
2862     {
2863       TI_DBG1(("ossaHwCB: Wrong port state with  OSSA_HW_EVENT_ID_FRAME_TIMEOUT\n"));
2864       smTraceFuncExit(hpDBG_VERY_LOUD, 'F', "Y2");
2865       return;
2866     }
2867     break;
2868   }
2869 
2870   case OSSA_HW_EVENT_PHY_ERR_INVALID_DWORD:
2871   {
2872     PhyID = TD_GET_PHY_ID(eventParm1);
2873     PortState = TD_GET_PORT_STATE(eventParm1);
2874     agPhyErrCountersPage = (agsaPhyErrCountersPage_t *)eventParm2;
2875     TI_DBG2(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_INVALID_DWORD\n"));
2876 
2877     if (PortState == OSSA_PORT_INVALID)
2878     {
2879       TI_DBG1(("ossaHwCB: Wrong port state with  OSSA_HW_EVENT_PHY_ERR_INVALID_DWORD\n"));
2880       smTraceFuncExit(hpDBG_VERY_LOUD, 'G', "Y2");
2881       return;
2882     }
2883 
2884     if (agPhyErrCountersPage != agNULL)
2885     {
2886       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_INVALID_DWORD from PhyID %d\n", PhyID));
2887       TI_DBG1(("ossaHwCB: invalidDword %d\n", agPhyErrCountersPage->invalidDword));
2888     }
2889     else
2890     {
2891       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_INVALID_DWORD: Error!!!  eventParm2 is NULL\n"));
2892     }
2893 
2894     /* saHwEventAck() */
2895     eventSource.agPortContext = agPortContext;
2896     eventSource.event = OSSA_HW_EVENT_PHY_ERR_INVALID_DWORD;
2897     /* phy ID */
2898     eventSource.param = PhyID;
2899     HwAckSatus = saHwEventAck(
2900                               agRoot,
2901                               agNULL, /* agContext */
2902                               0,
2903                               &eventSource, /* agsaEventSource_t */
2904                               0,
2905                               0
2906                               );
2907     if ( HwAckSatus != AGSA_RC_SUCCESS)
2908     {
2909       TI_DBG1(("ossaHwCB: failing in saHwEventAck; status %d\n", HwAckSatus));
2910       smTraceFuncExit(hpDBG_VERY_LOUD, 'H', "Y2");
2911       return;
2912     }
2913 
2914     break;
2915   }
2916 
2917   case OSSA_HW_EVENT_PHY_ERR_DISPARITY_ERROR:
2918   {
2919     PhyID = TD_GET_PHY_ID(eventParm1);
2920     PortState = TD_GET_PORT_STATE(eventParm1);
2921     agPhyErrCountersPage = (agsaPhyErrCountersPage_t *)eventParm2;
2922     TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_DISPARITY_ERROR\n"));
2923 
2924     if (PortState == OSSA_PORT_INVALID)
2925     {
2926       TI_DBG1(("ossaHwCB: Wrong port state with  OSSA_HW_EVENT_PHY_ERR_DISPARITY_ERROR\n"));
2927       smTraceFuncExit(hpDBG_VERY_LOUD, 'I', "Y2");
2928       return;
2929     }
2930 
2931     if (agPhyErrCountersPage != agNULL)
2932     {
2933       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_DISPARITY_ERROR from PhyID %d\n", PhyID));
2934       TI_DBG1(("ossaHwCB: runningDisparityError %d\n", agPhyErrCountersPage->runningDisparityError));
2935     }
2936     else
2937     {
2938       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_DISPARITY_ERROR: Error!!!  eventParm2 is NULL\n"));
2939     }
2940 
2941     /* saHwEventAck() */
2942     eventSource.agPortContext = agPortContext;
2943     eventSource.event = OSSA_HW_EVENT_PHY_ERR_DISPARITY_ERROR;
2944     /* phy ID */
2945     eventSource.param = PhyID;
2946     HwAckSatus = saHwEventAck(
2947                               agRoot,
2948                               agNULL, /* agContext */
2949                               0,
2950                               &eventSource, /* agsaEventSource_t */
2951                               0,
2952                               0
2953                               );
2954     if ( HwAckSatus != AGSA_RC_SUCCESS)
2955     {
2956       TI_DBG1(("ossaHwCB: failing in saHwEventAck; status %d\n", HwAckSatus));
2957       smTraceFuncExit(hpDBG_VERY_LOUD, 'J', "Y2");
2958       return;
2959     }
2960 
2961     break;
2962   }
2963 
2964   case OSSA_HW_EVENT_PHY_ERR_CODE_VIOLATION:
2965   {
2966     PhyID = TD_GET_PHY_ID(eventParm1);
2967     PortState = TD_GET_PORT_STATE(eventParm1);
2968     agPhyErrCountersPage = (agsaPhyErrCountersPage_t *)eventParm2;
2969     TI_DBG2(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_CODE_VIOLATION\n"));
2970 
2971     if (PortState == OSSA_PORT_INVALID)
2972     {
2973       TI_DBG1(("ossaHwCB: Wrong port state with  OSSA_HW_EVENT_PHY_ERR_CODE_VIOLATION\n"));
2974       smTraceFuncExit(hpDBG_VERY_LOUD, 'K', "Y2");
2975       return;
2976     }
2977 
2978     if (agPhyErrCountersPage != agNULL)
2979     {
2980       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_CODE_VIOLATION from PhyID %d\n", PhyID));
2981       TI_DBG1(("ossaHwCB: codeViolation %d\n", agPhyErrCountersPage->codeViolation));
2982     }
2983     else
2984     {
2985       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_CODE_VIOLATION: Error!!!  eventParm2 is NULL\n"));
2986     }
2987 
2988     /* saHwEventAck() */
2989     eventSource.agPortContext = agPortContext;
2990     eventSource.event = OSSA_HW_EVENT_PHY_ERR_CODE_VIOLATION;
2991     /* phy ID */
2992     eventSource.param = PhyID;
2993     HwAckSatus = saHwEventAck(
2994                               agRoot,
2995                               agNULL, /* agContext */
2996                               0,
2997                               &eventSource, /* agsaEventSource_t */
2998                               0,
2999                               0
3000                               );
3001     if ( HwAckSatus != AGSA_RC_SUCCESS)
3002     {
3003       TI_DBG1(("ossaHwCB: failing in saHwEventAck; status %d\n", HwAckSatus));
3004       smTraceFuncExit(hpDBG_VERY_LOUD, 'L', "Y2");
3005       return;
3006     }
3007 
3008     break;
3009   }
3010 
3011 #ifdef REMOVED
3012   case OSSA_HW_EVENT_LINK_ERR_CODE_VIOLATION1:
3013   {
3014     PhyID = eventParm1 & 0xFF;
3015     agPhyErrCountersPage = (agsaPhyErrCountersPage_t *)eventParm2;
3016 
3017     if (agPhyErrCountersPage != agNULL)
3018     {
3019       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_LINK_ERR_CODE_VIOLATION1 from PhyID %d\n", PhyID));
3020       TI_DBG1(("ossaHwCB: invalidDword %d\n", agPhyErrCountersPage->invalidDword));
3021       TI_DBG1(("ossaHwCB: runningDisparityError %d\n", agPhyErrCountersPage->runningDisparityError));
3022       TI_DBG1(("ossaHwCB: codeViolation %d\n", agPhyErrCountersPage->codeViolation));
3023       TI_DBG1(("ossaHwCB: lostOfDwordSynch %d\n", agPhyErrCountersPage->lossOfDwordSynch));
3024       TI_DBG1(("ossaHwCB: phyResetProblem %d\n", agPhyErrCountersPage->phyResetProblem));
3025       TI_DBG1(("ossaHwCB: inboundCRCError %d\n", agPhyErrCountersPage->inboundCRCError));
3026     }
3027     else
3028     {
3029       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_LINK_ERR_CODE_VIOLATION1: Error!!!  eventParm2 is NULL\n"));
3030     }
3031     break;
3032   }
3033 #endif /* REMOVED */
3034 
3035   case OSSA_HW_EVENT_PHY_ERR_LOSS_OF_DWORD_SYNCH:
3036   {
3037     PhyID = TD_GET_PHY_ID(eventParm1);
3038     PortState = TD_GET_PORT_STATE(eventParm1);
3039     agPhyErrCountersPage = (agsaPhyErrCountersPage_t *)eventParm2;
3040     TI_DBG2(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_LOSS_OF_DWORD_SYNCH\n"));
3041 
3042     if (PortState == OSSA_PORT_INVALID)
3043     {
3044       TI_DBG1(("ossaHwCB: Wrong port state with  OSSA_HW_EVENT_PHY_ERR_LOSS_OF_DWORD_SYNCH\n"));
3045       smTraceFuncExit(hpDBG_VERY_LOUD, 'M', "Y2");
3046       return;
3047     }
3048 
3049     if (agPhyErrCountersPage != agNULL)
3050     {
3051       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_LOSS_OF_DWORD_SYNCH from PhyID %d\n", PhyID));
3052       TI_DBG1(("ossaHwCB: lostOfDwordSynch %d\n", agPhyErrCountersPage->lossOfDwordSynch));
3053     }
3054     else
3055     {
3056       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_LOSS_OF_DWORD_SYNCH: Error!!!  eventParm2 is NULL\n"));
3057     }
3058 
3059     /* saHwEventAck() */
3060     eventSource.agPortContext = agPortContext;
3061     eventSource.event = OSSA_HW_EVENT_PHY_ERR_LOSS_OF_DWORD_SYNCH;
3062     /* phy ID */
3063     eventSource.param = PhyID;
3064     HwAckSatus = saHwEventAck(
3065                               agRoot,
3066                               agNULL, /* agContext */
3067                               0,
3068                               &eventSource, /* agsaEventSource_t */
3069                               0,
3070                               0
3071                               );
3072     if ( HwAckSatus != AGSA_RC_SUCCESS)
3073     {
3074       TI_DBG1(("ossaHwCB: failing in saHwEventAck; status %d\n", HwAckSatus));
3075       smTraceFuncExit(hpDBG_VERY_LOUD, 'N', "Y2");
3076       return;
3077     }
3078 
3079     break;
3080   }
3081 
3082   case OSSA_HW_EVENT_PHY_ERR_PHY_RESET_FAILED:
3083   {
3084     PhyID = TD_GET_PHY_ID(eventParm1);
3085     PortState = TD_GET_PORT_STATE(eventParm1);
3086     agPhyErrCountersPage = (agsaPhyErrCountersPage_t *)eventParm2;
3087 
3088     TI_DBG2(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_PHY_RESET_FAILED\n"));
3089 
3090     if (PortState == OSSA_PORT_INVALID)
3091     {
3092       TI_DBG1(("ossaHwCB: Wrong port state with  OSSA_HW_EVENT_PHY_ERR_PHY_RESET_FAILED\n"));
3093       smTraceFuncExit(hpDBG_VERY_LOUD, 'O', "Y2");
3094       return;
3095     }
3096 
3097     if (agPhyErrCountersPage != agNULL)
3098     {
3099       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_PHY_RESET_FAILED from PhyID %d\n", PhyID));
3100       TI_DBG1(("ossaHwCB: phyResetProblem %d\n", agPhyErrCountersPage->phyResetProblem));
3101     }
3102     else
3103     {
3104       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_ERR_PHY_RESET_FAILED: Error!!!  eventParm2 is NULL\n"));
3105     }
3106 
3107     /* saHwEventAck() */
3108     eventSource.agPortContext = agPortContext;
3109     eventSource.event = OSSA_HW_EVENT_PHY_ERR_PHY_RESET_FAILED;
3110     /* phy ID */
3111     eventSource.param = PhyID;
3112     HwAckSatus = saHwEventAck(
3113                               agRoot,
3114                               agNULL, /* agContext */
3115                               0,
3116                               &eventSource, /* agsaEventSource_t */
3117                               0,
3118                               0
3119                               );
3120     if ( HwAckSatus != AGSA_RC_SUCCESS)
3121     {
3122       TI_DBG1(("ossaHwCB: failing in saHwEventAck; status %d\n", HwAckSatus));
3123       smTraceFuncExit(hpDBG_VERY_LOUD, 'P', "Y2");
3124       return;
3125     }
3126 
3127     break;
3128   }
3129 
3130 // #ifdef INITIATOR_DRIVER
3131   case OSSA_HW_EVENT_ENCRYPTION:
3132   {
3133     pEncryptCBData = (agsaHWEventEncrypt_t *) eventParm2;
3134     TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_ENCRYPTION: encryptOperation 0x%x\n",pEncryptCBData->encryptOperation));
3135     TI_DBG1(("ossaHwCB: event 0x%x eventParm1 0x%x eventParm2 %p eventParm3 %p\n",event,eventParm1,eventParm2,eventParm3));
3136 
3137     /*
3138      * All events and status need to be translated from
3139      * SAS specific values to TISA specific values. This
3140      * is effectively a NOP, but the OS layer won't want to
3141      * look for SAS values.
3142      */
3143     if (pEncryptCBData->encryptOperation == OSSA_HW_ENCRYPT_KEK_UPDATE_AND_STORE)
3144     {
3145       TI_DBG1(("ossaHwCB: OSSA_HW_ENCRYPT_KEK_UPDATE_AND_STORE\n"));
3146       encryptEventData.encryptEvent = tiEncryptKekStore;
3147     }
3148     else if (pEncryptCBData->encryptOperation == OSSA_HW_ENCRYPT_KEK_UPDATE)
3149     {
3150       TI_DBG1(("ossaHwCB:OSSA_HW_ENCRYPT_KEK_UPDATE \n"));
3151       encryptEventData.encryptEvent = tiEncryptKekAdd;
3152     }
3153     else if (pEncryptCBData->encryptOperation == OSSA_HW_ENCRYPT_KEK_INVALIDTE)
3154     {
3155       TI_DBG1(("ossaHwCB:OSSA_HW_ENCRYPT_KEK_INVALIDTE \n"));
3156       /* none */
3157     }
3158     else if (pEncryptCBData->encryptOperation == OSSA_HW_ENCRYPT_DEK_UPDATE)
3159     {
3160       TI_DBG1(("ossaHwCB: OSSA_HW_ENCRYPT_DEK_UPDATE\n"));
3161       encryptEventData.encryptEvent = tiEncryptDekAdd;
3162     }
3163     else if (pEncryptCBData->encryptOperation == OSSA_HW_ENCRYPT_DEK_INVALIDTE)
3164     {
3165       TI_DBG1(("ossaHwCB: OSSA_HW_ENCRYPT_DEK_INVALIDTE\n"));
3166       encryptEventData.encryptEvent = tiEncryptDekInvalidate;
3167     }
3168     else if (pEncryptCBData->encryptOperation == OSSA_HW_ENCRYPT_OPERATOR_MANAGEMENT)
3169     {
3170       TI_DBG1(("ossaHwCB: OSSA_HW_ENCRYPT_OPERATOR_MANAGEMENT\n"));
3171       encryptEventData.encryptEvent = tiEncryptOperatorManagement;
3172     }
3173     else if (pEncryptCBData->encryptOperation == OSSA_HW_ENCRYPT_TEST_EXECUTE)
3174     {
3175       TI_DBG1(("ossaHwCB: OSSA_HW_ENCRYPT_TEST_EXECUTE\n"));
3176       encryptEventData.encryptEvent = tiEncryptSelfTest;
3177       encryptEventData.subEvent = pEncryptCBData->eq;
3178     }
3179     else
3180     {
3181       TI_DBG1(("ossaHwCB: unknown encryptOperation 0x%x\n",pEncryptCBData->encryptOperation));
3182     }
3183 
3184     if (pEncryptCBData->status != OSSA_SUCCESS)
3185     {
3186       encryptStatus = tiError;
3187 
3188       /* prints out status and error qualifier */
3189       TI_DBG1(("ossaHwCB: encrypt response status 0x%x error qualifier 0x%x\n", pEncryptCBData->status, pEncryptCBData->eq));
3190     }
3191     else
3192     {
3193       encryptStatus = tiSuccess;
3194     }
3195 
3196     if (pEncryptCBData->encryptOperation == OSSA_HW_ENCRYPT_KEK_UPDATE_AND_STORE ||
3197         pEncryptCBData->encryptOperation == OSSA_HW_ENCRYPT_KEK_UPDATE )
3198     {
3199       /* returning new KEK index */
3200       encryptEventData.pData = pEncryptCBData->handle;
3201     }
3202     else
3203     {
3204       /* returning current KEK index or DEK index */
3205       encryptEventData.pData = pEncryptCBData->param;
3206     }
3207 
3208     ostiPortEvent(tiRoot,
3209                   tiEncryptOperation,
3210                   encryptStatus,
3211                   &encryptEventData);
3212     break;
3213   }
3214   case OSSA_HW_EVENT_SECURITY_MODE:
3215   {
3216     securitySetModeStatus = eventParm1;
3217     pEncryptInfo = (agsaEncryptInfo_t *) eventParm2;
3218 
3219     TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_SECURITY_MODE\n"));
3220     if (securitySetModeStatus == OSSA_SUCCESS)
3221     {
3222       securityModeStatus = tiSuccess;
3223     }
3224     else
3225     {
3226       securityModeStatus = tiError;
3227     }
3228 
3229     encryptEventData.encryptEvent = tiEncryptSetMode;
3230     /* process status to fill in subevent */
3231     /* See PM 4.26.12.6 */
3232     TI_DBG1(("ossaHwCB: pEncryptInfo->status 0x%x\n", pEncryptInfo->status));
3233     if ( pEncryptInfo->status == OSSA_SUCCESS)
3234     {
3235       encryptEventData.subEvent = tiNVRAMSuccess;
3236     }
3237     else if (pEncryptInfo->status == 0x24)
3238     {
3239       encryptEventData.subEvent = tiNVRAMNotFound;
3240     }
3241     else if (pEncryptInfo->status == 0x05 || pEncryptInfo->status == 0x20 || pEncryptInfo->status == 0x21)
3242     {
3243       encryptEventData.subEvent = tiNVRAMAccessTimeout;
3244     }
3245     else
3246     {
3247       encryptEventData.subEvent = tiNVRAMWriteFail;
3248     }
3249 
3250     encryptEventData.pData = agNULL;
3251     ostiPortEvent(tiRoot,
3252                   tiEncryptOperation,
3253                   securityModeStatus,
3254                   &encryptEventData);
3255 
3256     break;
3257   }
3258   case OSSA_HW_EVENT_MODE:
3259   {
3260     pModeEvent = (agsaHWEventMode_t *) eventParm2;
3261     pModePage = (bit32 *) pModeEvent->modePage;
3262 
3263     TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_MODE modePageOperation 0x%x status 0x%x modePageLen 0x%x\n",
3264               pModeEvent->modePageOperation, pModeEvent->status, pModeEvent->modePageLen));
3265 
3266     if (pModeEvent->modePageOperation == agsaModePageSet)
3267     {
3268       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_MODE page code 0x%x error qualifier 0x%x\n", (eventParm1 & 0xFF), (eventParm1 >> 16)));
3269       ostiPortEvent(tiRoot,
3270                     tiModePageOperation,
3271                     pModeEvent->status,
3272                     eventParm2);
3273     }
3274     else if (pModeEvent->modePageOperation == agsaModePageGet)
3275     {
3276       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_MODE error qualifier 0x%x\n", eventParm1));
3277       switch ((*pModePage) & 0xFF)
3278       {
3279       case AGSA_ENCRYPTION_GENERAL_CONFIG_PAGE:
3280         TI_DBG1(("ossaHwCB: AGSA_ENCRYPTION_GENERAL_CONFIG_PAGE 0x%x %p\n", pModeEvent->status,eventParm2));
3281         TI_DBG1(("ossaHwCB:modePageOperation 0x%x status 0x%x modePageLen 0x%x modePage %p context %p\n",
3282                       pModeEvent->modePageOperation,
3283                       pModeEvent->status,
3284                       pModeEvent->modePageLen,
3285                       pModeEvent->modePage,
3286                       pModeEvent->context));
3287         ostiPortEvent(tiRoot,
3288                       tiModePageOperation,
3289                       pModeEvent->status,
3290                       eventParm2);
3291         break;
3292       case AGSA_ENCRYPTION_DEK_CONFIG_PAGE:
3293         TI_DBG1(("ossaHwCB: AGSA_ENCRYPTION_DEK_CONFIG_PAGE 0x%x %p\n", pModeEvent->status,eventParm2));
3294         ostiPortEvent(tiRoot,
3295                       tiModePageOperation,
3296                       pModeEvent->status,
3297                       eventParm2);
3298         break;
3299       case AGSA_ENCRYPTION_HMAC_CONFIG_PAGE:
3300         TI_DBG1(("ossaHwCB: AGSA_ENCRYPTION_HMAC_CONFIG_PAGE 0x%x %p\n", pModeEvent->status,eventParm2));
3301         ostiPortEvent(tiRoot,
3302                       tiModePageOperation,
3303                       pModeEvent->status,
3304                       eventParm2);
3305         break;
3306       case AGSA_ENCRYPTION_CONTROL_PARM_PAGE:
3307         TI_DBG1(("ossaHwCB: AGSA_ENCRYPTION_CONTROL_PARM_PAGE 0x%x %p\n", pModeEvent->status,eventParm2));
3308         /*
3309          * This page is directly related to tiCOMEncryptGetInfo() and
3310          * will be translated into a tiEncrytOperation for the OS layer.
3311          */
3312 
3313         /* Fill out tiEncryptInfo_t */
3314         securityMode = *pModePage & 0x0F00 >> 8;
3315         cipherMode = *pModePage & 0xF000 >> 12;
3316 
3317         if (securityMode == agsaEncryptSMA)
3318         {
3319           encryptInfo.securityCipherMode = TI_ENCRYPT_SEC_MODE_A;
3320         }
3321         else if (securityMode == agsaEncryptSMB)
3322         {
3323           encryptInfo.securityCipherMode = TI_ENCRYPT_SEC_MODE_B;
3324         }
3325         else
3326         {
3327           encryptInfo.securityCipherMode = TI_ENCRYPT_SEC_MODE_FACT_INIT;
3328         }
3329 
3330         if (cipherMode == agsaEncryptCipherModeECB)
3331         {
3332           encryptInfo.securityCipherMode |= TI_ENCRYPT_ATTRIB_CIPHER_ECB;
3333         }
3334 
3335         if (cipherMode == agsaEncryptCipherModeXTS)
3336         {
3337           encryptInfo.securityCipherMode |= TI_ENCRYPT_ATTRIB_CIPHER_XTS;
3338         }
3339 
3340         /* How will subEvents be tracked? */
3341         encryptInfo.status = 0;
3342 
3343         encryptInfo.sectorSize[0] = 512;  /* DIF is allowed on 512 BPS SATA drives */
3344         encryptInfo.sectorSize[1] = 520;
3345         encryptInfo.sectorSize[2] = 528;
3346         encryptInfo.sectorSize[3] = 4104;
3347         encryptInfo.sectorSize[4] = 4168;
3348         encryptInfo.sectorSize[5] = 4232;
3349 
3350         encryptEventData.encryptEvent = tiEncryptGetInfo;
3351         encryptEventData.subEvent = 0;
3352         encryptEventData.pData = &encryptInfo;
3353 
3354         ostiPortEvent(tiRoot,
3355                     tiEncryptOperation,
3356                     pModeEvent->status,
3357                     &encryptEventData);
3358         break;
3359       case AGSA_SAS_PROTOCOL_TIMER_CONFIG_PAGE:
3360         TI_DBG1(("ossaHwCB: AGSA_SAS_PROTOCOL_TIMER_CONFIG_PAGE 0x%x %p\n", pModeEvent->status,eventParm2));
3361 
3362 #ifdef IOCTL_INTERRUPT_TIME_CONFIG
3363          ostiPortEvent(tiRoot,
3364                     tiModePageOperation,
3365                     pModeEvent->status,
3366                     eventParm2
3367                  );
3368 #endif /* IOCTL_INTERRUPT_TIME_CONFIG */
3369 
3370         /*ostiPortEvent(tiRoot,
3371                     tiModePageOperation,
3372                     pModeEvent->status,
3373                     &encryptEventData);*/
3374         break;
3375       case AGSA_INTERRUPT_CONFIGURATION_PAGE:
3376         TI_DBG1(("ossaHwCB: AGSA_INTERRUPT_CONFIGURATION_PAGE 0x%x %p\n", pModeEvent->status,eventParm2));
3377 
3378 #ifdef IOCTL_INTERRUPT_TIME_CONFIG
3379         ostiPortEvent(tiRoot,
3380                     tiModePageOperation,
3381                     pModeEvent->status,
3382                     eventParm2
3383                     );
3384 #endif /* IOCTL_INTERRUPT_TIME_CONFIG */
3385 
3386         break;
3387       default:
3388         TI_DBG1(("ossaHwCB: Unknown Mode Event %x\n", *pModePage));
3389          break;
3390       }
3391 
3392     }
3393     else
3394     {
3395       TI_DBG1(("ossaHwCB: Unknown modePageOperation %x\n", pModeEvent->modePageOperation));
3396     }
3397     break;
3398   }
3399 
3400 // #endif  /* INITIATOR_DRIVER */
3401 
3402 #ifdef REMOVED
3403   case OSSA_HW_EVENT_PHY_UNRECOVERABLE_ERROR:
3404   {
3405     PhyID = TD_GET_PHY_ID(eventParm1);
3406     PortState = TD_GET_PORT_STATE(eventParm1);
3407 
3408     TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_PHY_UNRECOVERABLE_ERROR\n"));
3409 
3410     if (PortState == OSSA_PORT_INVALID)
3411     {
3412       TI_DBG1(("ossaHwCB: INVALID port state\n"));
3413     }
3414     else
3415     {
3416       TI_DBG1(("ossaHwCB: VALID port state\n"));
3417     }
3418     break;
3419   }
3420 #endif /* REMOVED */
3421     case OSSA_HW_EVENT_OPEN_RETRY_BACKOFF_THR_ADJUSTED:
3422     {
3423       TI_DBG1(("ossaHwCB: OSSA_HW_EVENT_OPEN_RETRY_BACKOFF_THR_ADJUSTED\n"));
3424       break;
3425     }
3426 
3427     default:
3428     {
3429       TI_DBG1(("ossaHwCB: default error (0x%X)!!!!!\n",event));
3430       break;
3431     }
3432   }
3433 
3434   smTraceFuncExit(hpDBG_VERY_LOUD, 'R', "Y2");
3435   return;
3436 }
3437 
3438 osGLOBAL void ossaPortControlCB(
3439                   agsaRoot_t          *agRoot,
3440                   agsaContext_t       *agContext,
3441                   agsaPortContext_t   *agPortContext,
3442                   bit32               portOperation,
3443                   bit32               status)
3444 {
3445   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
3446   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
3447   tdsaPortContext_t   *onePortContext = agNULL;
3448 
3449   TI_DBG6(("ossaPortControlCB: start\n"));
3450 
3451   smTraceFuncEnter(hpDBG_VERY_LOUD,"Y3");
3452   if (portOperation == AGSA_PORT_SET_SMP_PHY_WIDTH)
3453   {
3454     TI_DBG1(("ossaPortControlCB: portOperation AGSA_PORT_SET_SMP_PHY_WIDTH\n"));
3455   }
3456   else if (portOperation == AGSA_PORT_SET_PORT_RECOVERY_TIME)
3457   {
3458     TI_DBG1(("ossaPortControlCB: portOperation AGSA_PORT_SET_PORT_RECOVERY_TIME\n"));
3459   }
3460   else if (portOperation == AGSA_PORT_IO_ABORT)
3461   {
3462     TI_DBG1(("ossaPortControlCB: portOperation AGSA_PORT_IO_ABORT\n"));
3463     /* code is here because disocvery failed
3464        deregister all targets. Then, later call discovery if broacast is seen in ossaDeregisterDeviceHandleCB.
3465     */
3466     onePortContext = (tdsaPortContext_t *)agPortContext->osData;
3467     if (onePortContext == agNULL)
3468     {
3469       TI_DBG1(("ossaPortControlCB: onePortContext is NULL\n"));
3470       return;
3471     }
3472     /* qqqqq deregister all devices */
3473    tdsaDeregisterDevicesInPort(tiRoot, onePortContext);
3474 
3475   }
3476   else if (portOperation == AGSA_PORT_SET_PORT_RESET_TIME)
3477   {
3478     TI_DBG1(("ossaPortControlCB: portOperation AGSA_PORT_SET_PORT_RESET_TIME\n"));
3479   }
3480   else if (portOperation == AGSA_PORT_HARD_RESET)
3481   {
3482     TI_DBG1(("ossaPortControlCB: portOperation AGSA_PORT_HARD_RESET\n"));
3483   }
3484   else if (portOperation == AGSA_PORT_CLEAN_UP)
3485   {
3486     TI_DBG1(("ossaPortControlCB: portOperation AGSA_PORT_CLEAN_UP\n"));
3487   }
3488   else if (portOperation == AGSA_STOP_PORT_RECOVERY_TIMER)
3489   {
3490     TI_DBG1(("ossaPortControlCB: portOperation AGSA_STOP_PORT_RECOVERY_TIMER\n"));
3491   }
3492   else
3493   {
3494     TI_DBG1(("ossaPortControlCB: undefined portOperation %d\n", portOperation));
3495   }
3496 
3497   TI_DBG1(("ossaPortControlCB: status %d\n", status));
3498 
3499   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Y3");
3500   return;
3501 }
3502 
3503 /*****************************************************************************
3504 *! \brief  ossaHwRegRead
3505 *
3506 *  Purpose: This routine is called to read a 32-bit value from the PCI
3507 *           registers of the controller
3508 *
3509 *  \param  agRoot:       Pointer to chip/driver Instance.
3510 *  \param  regOffset:    Byte offset to chip register from which to read a 32-bit
3511 *                        value.
3512 *
3513 *  \return:             32-bit value.
3514 *
3515 *  \note - The scope is shared target and initiator.
3516 *
3517 *****************************************************************************/
3518 FORCEINLINE
3519 bit32
3520 ossaHwRegRead(agsaRoot_t *agRoot,
3521               bit32      regOffset
3522               )
3523 {
3524   tdsaRootOsData_t *osData = (tdsaRootOsData_t *) (agRoot->osData);
3525   bit32 return_value;
3526 
3527 
3528   return_value =  ostiChipReadBit32 (
3529                              osData->tiRoot,
3530                              regOffset
3531                              );
3532   if( agNULL != agRoot->sdkData )
3533   {
3534     smTrace(hpDBG_REGISTERS,"RR",regOffset);
3535     /* TP:RR regOffset */
3536     smTrace(hpDBG_REGISTERS,"RV",return_value);
3537     /* TP:RV value read */
3538   }
3539 
3540   return(return_value);
3541 
3542 }
3543 
3544 /*****************************************************************************
3545 *! \brief  ossaHwRegWrite
3546 *
3547 *  Purpose: This routine is called to write a 32-bit value to the PCI
3548 *           registers of the controller.
3549 *
3550 *  \param   agRoot:     Pointer to chip/driver Instance.
3551 *  \param   regOffset:  Byte offset to chip register to which chipIOValue is
3552 *                       written.
3553 *  \param   regValue:   32-bit value to write at chipIOOffset in host byte order.
3554 *
3555 *  \return:             None.
3556 *
3557 *  \note - The scope is shared target and initiator.
3558 *
3559 *****************************************************************************/
3560 FORCEINLINE
3561 void
3562 ossaHwRegWrite(agsaRoot_t *agRoot,
3563                bit32      regOffset,
3564                bit32      regValue
3565                )
3566 {
3567 
3568   tdsaRootOsData_t *osData = (tdsaRootOsData_t *) (agRoot->osData);
3569   if( agNULL != agRoot->sdkData )
3570   {
3571     smTrace(hpDBG_REGISTERS,"RW",regOffset);
3572     /* TP:RW regOffset */
3573     smTrace(hpDBG_REGISTERS,"VW",regValue);
3574     /* TP:VW value written */
3575   }
3576 
3577   ostiChipWriteBit32 (
3578                       osData->tiRoot,
3579                       regOffset,
3580                       regValue
3581                       );
3582   return;
3583 }
3584 
3585 /*****************************************************************************
3586 *! \brief  ossaHwRegReadExt
3587 *
3588 *  Purpose: This routine is called to read a 32-bit value from a bus-specific
3589 *           mapped registers of the controller
3590 *
3591 *  \param  agRoot:       Pointer to chip/driver Instance.
3592 *  \param  regOffset:    Byte offset to chip register from which to read a 32-bit
3593 *                        value.
3594 *
3595 *  \return:             32-bit value.
3596 *
3597 *  \note - The scope is shared target and initiator.
3598 *
3599 *****************************************************************************/
3600 FORCEINLINE
3601 bit32
3602 ossaHwRegReadExt(
3603                  agsaRoot_t  *agRoot,
3604                  bit32       busBaseNumber,
3605                  bit32       regOffset
3606                  )
3607 {
3608   tdsaRootOsData_t *osData = (tdsaRootOsData_t *) (agRoot->osData);
3609 
3610   bit32 return_value;
3611 
3612   return_value = ostiChipReadBit32Ext(
3613                                osData->tiRoot,
3614                                busBaseNumber,
3615                                regOffset
3616                                );
3617 
3618   /* TI_DBG4(("#_R: 0x%x:0x%x=0x%x\n",busBaseNumber,regOffset,return_value)); */
3619 
3620   if( agNULL != agRoot->sdkData )
3621   {
3622     smTrace(hpDBG_REGISTERS,"EB",busBaseNumber);
3623     /* TP:EB EX read busBaseNumber */
3624     smTrace(hpDBG_REGISTERS,"EO",regOffset);
3625     /* TP:EO regOffset */
3626     smTrace(hpDBG_REGISTERS,"ER",return_value);
3627     /* TP:ER value read */
3628   }
3629   return(return_value);
3630 }
3631 
3632 void ossaPCI_TRIGGER(agsaRoot_t  *agRoot )
3633 {
3634   tdsaRootOsData_t *osData = (tdsaRootOsData_t *) (agRoot->osData);
3635   ostiPCI_TRIGGER(osData->tiRoot);
3636 
3637 }
3638 
3639 
3640 
3641 /*****************************************************************************
3642 *! \brief  ossaHwRegWriteExt
3643 *
3644 *  Purpose: This routine is called to write a 32-bit value to a bus specific
3645 *           mapped registers of the controller.
3646 *
3647 *  \param   agRoot:     Pointer to chip/driver Instance.
3648 *  \param   regOffset:  Byte offset to chip register to which chipIOValue is
3649 *                       written.
3650 *  \param   regValue:   32-bit value to write at chipIOOffset in host byte order.
3651 *
3652 *  \return:             None.
3653 *
3654 *  \note - The scope is shared target and initiator.
3655 *
3656 *****************************************************************************/
3657 FORCEINLINE
3658 void
3659 ossaHwRegWriteExt(
3660                   agsaRoot_t  *agRoot,
3661                   bit32       busBaseNumber,
3662                   bit32       regOffset,
3663                   bit32       regValue
3664                   )
3665 {
3666   tdsaRootOsData_t *osData = (tdsaRootOsData_t *) (agRoot->osData);
3667   ostiChipWriteBit32Ext(
3668                         osData->tiRoot,
3669                         busBaseNumber,
3670                         regOffset,
3671                         regValue
3672                         );
3673 
3674   /*  TI_DBG4(("#_W: 0x%x:0x%x=0x%x\n",busBaseNumber,regOffset,regValue)); */
3675 
3676   if( agNULL != agRoot->sdkData )
3677   {
3678     smTrace(hpDBG_REGISTERS,"Eb",busBaseNumber);
3679     /* TP:Eb Ex Write busBaseNumber */
3680     smTrace(hpDBG_REGISTERS,"Eo",regOffset);
3681     /* TP:Eo regOffset */
3682     smTrace(hpDBG_REGISTERS,"Ew",regValue);
3683     /* TP:Ew value written  regValue*/
3684   }
3685   return;
3686 }
3687 
3688 
3689 osGLOBAL bit32 ossaHwRegReadConfig32(
3690               agsaRoot_t  *agRoot,
3691               bit32       regOffset
3692               )
3693 {
3694   tdsaRootOsData_t *osData = (tdsaRootOsData_t *) (agRoot->osData);
3695   bit32 to_ret;
3696   to_ret= ostiChipConfigReadBit32( osData->tiRoot, regOffset);
3697   TI_DBG4(("ossaHwRegReadConfig32: regOffset 0x%x returns 0x%x\n",regOffset,to_ret));
3698   return(to_ret);
3699 }
3700 
3701 
3702 
3703 
3704 #ifdef TD_INT_COALESCE
3705 void
3706 ossaIntCoalesceInitCB(
3707                       agsaRoot_t                *agRoot,
3708                       agsaIntCoalesceContext_t    *agIntCoContext,
3709                       bit32                   status
3710                       )
3711 {
3712   tdsaRootOsData_t          *osData = (tdsaRootOsData_t *)agRoot->osData;
3713   tiRoot_t                  *tiRoot = (tiRoot_t *)osData->tiRoot;
3714   tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)osData->tdsaAllShared;
3715   tiIntCoalesceContext_t    *tiIntCoalesceCxt;
3716   tdsaIntCoalesceContext_t  *tdsaIntCoalCxt;
3717   tdsaIntCoalesceContext_t  *tdsaIntCoalCxtHead
3718     = (tdsaIntCoalesceContext_t *)tdsaAllShared->IntCoalesce;
3719   bit32                     tiStatus;
3720 
3721   TI_DBG2(("ossaIntCoalesceInitCB: start\n"));
3722 
3723   tdsaIntCoalCxt = (tdsaIntCoalesceContext_t *)agIntCoContext->osData;
3724   tiIntCoalesceCxt = tdsaIntCoalCxt->tiIntCoalesceCxt;
3725   switch (status)
3726   {
3727   case AGSA_RC_SUCCESS:
3728     tiStatus = tiSuccess;
3729     break;
3730   case AGSA_RC_BUSY:
3731     tiStatus = tiBusy;
3732     break;
3733   case AGSA_RC_FAILURE:
3734     tiStatus = tiError;
3735     break;
3736   default:
3737     TI_DBG1(("ossaIntCoalesceInitCB: unknown status %d\n", status));
3738     tiStatus = tiError;
3739     break;
3740   }
3741 
3742   TI_DBG2(("ossaIntCoalesceInitCB: status %d\n", tiStatus));
3743 
3744   /* enqueue tdsaIntCoalCxt to freelink */
3745   tdsaIntCoalCxt->tiIntCoalesceCxt = agNULL;
3746   TI_DBG2(("ossaIntCoalesceInitCB: id %d\n", tdsaIntCoalCxt->id));
3747 
3748   tdsaSingleThreadedEnter(tiRoot, TD_INTCOAL_LOCK);
3749   TDLIST_DEQUEUE_THIS(&(tdsaIntCoalCxt->MainLink));
3750   TDLIST_ENQUEUE_AT_TAIL(&(tdsaIntCoalCxt->FreeLink), &(tdsaIntCoalCxtHead->FreeLink));
3751   tdsaSingleThreadedLeave(tiRoot, TD_INTCOAL_LOCK);
3752 
3753 #ifdef OS_INT_COALESCE
3754   ostiInitiatorIntCoalesceInitCB(tiRoot,
3755                                  tiIntCoalesceCxt,
3756                                  tiStatus);
3757 #endif
3758 
3759   TI_DBG2(("ossaIntCoalesceInitCB: return end\n"));
3760 
3761   return;
3762 }
3763 #endif /* TD_INT_COALESCE */
3764 
3765 /*****************************************************************************/
3766 /*! \brief ossaSingleThreadedEnter
3767  *
3768  *
3769  * Purpose: This routine is called to ensure that only a single thread of
3770  *          the given port instance executes code in the region protected by
3771  *          this function.
3772  *
3773  *
3774  *  \param   agRoot:       Pointer to chip/driver Instance.
3775  *  \param   syncLockId    to be explained.
3776  *
3777  *
3778  *  \return None.
3779  *
3780  *  \note - The scope is shared target and initiator.
3781  *
3782  */
3783 /*****************************************************************************/
3784 FORCEINLINE
3785 void ossaSingleThreadedEnter(
3786      agsaRoot_t *agRoot,
3787      bit32  syncLockId
3788      )
3789 {
3790   tdsaRootOsData_t *pOsData = agNULL;
3791   tiRoot_t  *ptiRoot = agNULL;
3792   tdsaContext_t *tdsaAllShared = agNULL;
3793 
3794   TD_ASSERT(agRoot, "agRoot");
3795   pOsData = (tdsaRootOsData_t *) (agRoot->osData);
3796   TD_ASSERT(pOsData, "pOsData");
3797   ptiRoot = pOsData->tiRoot;
3798   TD_ASSERT(ptiRoot, "ptiRoot");
3799 
3800   tdsaAllShared = (tdsaContext_t *)pOsData->tdsaAllShared;
3801   TD_ASSERT(tdsaAllShared, "tdsaAllShared");
3802 
3803   ostiSingleThreadedEnter(ptiRoot, syncLockId + tdsaAllShared->MaxNumOSLocks);
3804   return;
3805 }
3806 
3807 /*****************************************************************************/
3808 /*! \brief ossaSingleThreadedLeave
3809  *
3810  *
3811  *  Purpose: This routine is called to leave a critical region of code
3812  *           previously protected by a call to osSingleThreadedEnter()
3813  *
3814  *
3815  *  \param   agRoot:       Pointer to chip/driver Instance.
3816  *  \param   syncLockId    to be explained.
3817  *
3818  *
3819  *  \return None.
3820  *
3821  *  \note - The scope is shared target and initiator.
3822  *
3823  */
3824 /*****************************************************************************/
3825 FORCEINLINE
3826 void ossaSingleThreadedLeave(
3827      agsaRoot_t *agRoot,
3828      bit32  syncLockId
3829      )
3830 {
3831   tdsaRootOsData_t *pOsData = agNULL;
3832   tiRoot_t  *ptiRoot = agNULL;
3833   tdsaContext_t *tdsaAllShared = agNULL;
3834 
3835   TD_ASSERT(agRoot, "agRoot");
3836   pOsData = (tdsaRootOsData_t *) (agRoot->osData);
3837   TD_ASSERT(pOsData, "pOsData");
3838   ptiRoot = pOsData->tiRoot;
3839   TD_ASSERT(ptiRoot, "ptiRoot");
3840 
3841   tdsaAllShared = (tdsaContext_t *)pOsData->tdsaAllShared;
3842   TD_ASSERT(tdsaAllShared, "tdsaAllShared");
3843 
3844   ostiSingleThreadedLeave(ptiRoot, syncLockId + tdsaAllShared->MaxNumOSLocks);
3845   return;
3846 }
3847 
3848 #ifdef PERF_COUNT
3849 osGLOBAL void ossaEnter(agsaRoot_t *agRoot, int io)
3850 {
3851   ostiEnter(((tdsaRootOsData_t*)(agRoot->osData))->tiRoot, 0, io);
3852   return;
3853 }
3854 
3855 osGLOBAL void ossaLeave(agsaRoot_t *agRoot, int io)
3856 {
3857   ostiLeave(((tdsaRootOsData_t*)(agRoot->osData))->tiRoot, 0, io);
3858   return;
3859 }
3860 #endif
3861 
3862 
3863 osGLOBAL void
3864 ossaSSPIoctlCompleted(
3865                         agsaRoot_t                        *agRoot,
3866                         agsaIORequest_t           *agIORequest,
3867                         bit32                             agIOStatus,
3868                         bit32                             agIOInfoLen,
3869                         void                              *agParam,
3870                         bit16                             sspTag,
3871                         bit32                             agOtherInfo
3872                    )
3873 {
3874   tdsaRootOsData_t                              *osData           = (tdsaRootOsData_t *)agRoot->osData;
3875   tiRoot_t                                              *tiRoot           = (tiRoot_t *)osData->tiRoot;
3876   tdIORequestBody_t                             *tdIORequestBody  = (tdIORequestBody_t *)agIORequest->osData;
3877   agsaSASRequestBody_t                  *agSASRequestBody = agNULL;
3878   agsaSSPInitiatorRequest_t             *agSSPFrame       = agNULL;
3879   bit8                          scsiOpcode        = 0;
3880 
3881   agSASRequestBody = &(tdIORequestBody->transport.SAS.agSASRequestBody);
3882   agSSPFrame = &(agSASRequestBody->sspInitiatorReq);
3883   scsiOpcode = agSSPFrame->sspCmdIU.cdb[0];
3884 
3885   TI_DBG2(("ossaSSPIoctlCompleted: start\n"));
3886 
3887   if (agIOStatus == OSSA_SUCCESS)
3888   {
3889     TI_DBG2(("ossaSSPIoctlCompleted: Success status\n"));
3890   }
3891   else
3892   {
3893     TI_DBG1(("ossaSSPIoctlCompleted: Status 0x%x\n", agIOStatus));
3894   }
3895   switch(scsiOpcode)
3896   {
3897   case REPORT_LUN_OPCODE:
3898     ostiNumOfLUNIOCTLRsp(tiRoot, agIOStatus);
3899         break;
3900 
3901   default:
3902         TI_DBG1(("ossaSSPIoctlCompleted: Unsupported SCSI command Response  0x%x\n",scsiOpcode));
3903         break;
3904   }
3905   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yi");
3906   return;
3907 
3908 }
3909 
3910 osGLOBAL void
3911 ossaSMPIoctlCompleted(
3912                  agsaRoot_t            *agRoot,
3913                  agsaIORequest_t       *agIORequest,
3914                  bit32                 agIOStatus,
3915                  bit32                 agIOInfoLen,
3916                  agsaFrameHandle_t     agFrameHandle
3917                  )
3918 {
3919         tdsaRootOsData_t        *osData = (tdsaRootOsData_t *)agRoot->osData;
3920         tiRoot_t                        *tiRoot = (tiRoot_t *)osData->tiRoot;
3921         TI_DBG2(("ossaSMPIoctlCompleted: start\n"));
3922 
3923         if (agIOStatus == OSSA_SUCCESS)
3924         {
3925           TI_DBG2(("ossaSMPIoctlCompleted: Success status\n"));
3926         }
3927         else
3928         {
3929           TI_DBG1(("ossaSMPIoctlCompleted: Status 0x%x\n", agIOStatus));
3930         }
3931 
3932         ostiSendSMPIOCTLRsp(tiRoot, agIOStatus);
3933         smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yi");
3934         return;
3935 
3936 }
3937 
3938 
3939 /*****************************************************************************/
3940 /*! \brief ossaSMPCompleted
3941  *
3942  *
3943  *  Purpose: This routine is called by lower layer to indicate the completion of
3944  *           SMP request
3945  *
3946  *  \param   agRoot:       Pointer to chip/driver Instance.
3947  *  \param   agIORequest   Pointer to SMP request handle
3948  *  \param   agIOStatus    Status
3949  *  \param   agFrameHeader:Pointer to SMP frame header.
3950  *  \param   agIOInfoLen   IO information length assoicated with the IO
3951  *  \param   agFrameHandle A Handle used to refer to the response frame
3952  *
3953  *
3954  *  \return None.
3955  *
3956  *  \note - The scope is shared target and initiator.
3957  *          For details, refer to SAS/SATA Low-Level API Specification
3958  */
3959 /*****************************************************************************/
3960 osGLOBAL void ossaSMPCompleted(
3961                  agsaRoot_t            *agRoot,
3962                  agsaIORequest_t       *agIORequest,
3963                  bit32                 agIOStatus,
3964                  bit32                 agIOInfoLen,
3965                  agsaFrameHandle_t     agFrameHandle
3966                  )
3967 {
3968 #ifdef PASSTHROUGH
3969   tdsaRootOsData_t         *osData = (tdsaRootOsData_t *)agRoot->osData;
3970   tiRoot_t                 *tiRoot = (tiRoot_t *)osData->tiRoot;
3971   tdPassthroughCmndBody_t  *tdPTCmndBody  = (tdPassthroughCmndBody_t *)agIORequest->osData;
3972   bit32                    tiStatus = tiPassthroughError;
3973   bit8                     SMPframe[agIOInfoLen + sizeof(agsaSMPFrameHeader_t)];
3974   bit8                     SMPpayload[agIOInfoLen];
3975 
3976   TI_DBG2(("ossaSMPCompleted: start and passthrough\n"));
3977 #else /* not PASSTHROUGH */
3978 
3979   tdssSMPRequestBody_t *pSMPRequestBody = (tdssSMPRequestBody_t *) agIORequest->osData;
3980   TI_DBG4(("ossaSMPCompleted: start\n"));
3981 #endif /* end not PASSTHROUGH */
3982 
3983   TDSA_OUT_ENTER((tiRoot_t *)((tdsaRootOsData_t *)agRoot->osData)->tiRoot);
3984   smTraceFuncEnter(hpDBG_VERY_LOUD,"Y4");
3985 
3986 #ifdef PASSTHROUGH
3987   if (tdPTCmndBody == agNULL)
3988   {
3989     TI_DBG1(("ossaSMPCompleted: tdPTCmndBody is NULL \n"));
3990     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Y4");
3991     goto ext;
3992   }
3993 
3994   if (tdPTCmndBody->EventCB == agNULL)
3995   {
3996     TI_DBG1(("ossaSMPCompleted: tdPTCmndBody->EventCB is NULL \n"));
3997     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "Y4");
3998     goto ext;
3999   }
4000 
4001   if (agIOStatus == OSSA_IO_SUCCESS)
4002   {
4003     tiStatus = tiPassthroughSuccess;
4004   }
4005   else if (agIOStatus == OSSA_IO_ABORTED)
4006   {
4007     tiStatus = tiPassthroughAborted;
4008   }
4009   else
4010   {
4011     tiStatus = tiPassthroughError;
4012   }
4013 
4014   osti_memset(SMPpayload, 0, agIOInfoLen);
4015   osti_memset(SMPframe, 0, agIOInfoLen + sizeof(agsaSMPFrameHeader_t));
4016 
4017   /* combine the header and payload */
4018   saFrameReadBlock(agRoot, agFrameHandle, 0, &SMPpayload, agIOInfoLen);
4019   osti_memcpy(SMPframe, agFrameHeader, sizeof(agsaSMPFrameHeader_t));
4020   osti_memcpy(SMPframe+sizeof(agsaSMPFrameHeader_t), SMPpayload, agIOInfoLen);
4021 
4022   tdPTCmndBody->EventCB(tiRoot,
4023                         tdPTCmndBody->tiPassthroughRequest,
4024                         tiStatus,
4025                         SMPframe,
4026                         agIOInfoLen + sizeof(agsaSMPFrameHeader_t)
4027                         );
4028 
4029 
4030 #else /* not PASSTHROUGH */
4031 
4032   /*
4033     At initiator, passing SMP to TD layer, itdssSMPCompleted(), which does nothing.
4034     At target, passing SMP to TD layer, ttdsaSMPCompleted()
4035   */
4036   /*
4037      how to use agFrameHandle, when saFrameReadBlock() is used
4038   */
4039 
4040   /* SPC can't be SMP target */
4041 
4042   TI_DBG4(("ossaSMPCompleted: start\n"));
4043 
4044   if (pSMPRequestBody == agNULL)
4045   {
4046     TI_DBG1(("ossaSMPCompleted: pSMPRequestBody is NULL \n"));
4047     smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "Y4");
4048     goto ext;
4049   }
4050 
4051   if (pSMPRequestBody->SMPCompletionFunc == agNULL)
4052   {
4053     TI_DBG1(("ossaSMPCompleted: pSMPRequestBody->SMPCompletionFunc is NULL \n"));
4054     smTraceFuncExit(hpDBG_VERY_LOUD, 'd', "Y4");
4055     goto ext;
4056   }
4057 #ifdef TD_INTERNAL_DEBUG /* debugging */
4058   TI_DBG4(("ossaSMPCompleted: agIOrequest %p\n", agIORequest->osData));
4059   TI_DBG4(("ossaSMPCompleted: sizeof(tdIORequestBody_t) %d 0x%x\n", sizeof(tdIORequestBody_t),
4060            sizeof(tdIORequestBody_t)));
4061   TI_DBG4(("ossaSMPCompleted: SMPRequestbody %p\n", pSMPRequestBody));
4062   TI_DBG4(("ossaSMPCompleted: calling callback fn\n"));
4063   TI_DBG4(("ossaSMPCompleted: callback fn %p\n",pSMPRequestBody->SMPCompletionFunc));
4064 #endif /* TD_INTERNAL_DEBUG */
4065   /*
4066     if initiator, calling itdssSMPCompleted() in itdcb.c
4067     if target,    calling ttdsaSMPCompleted() in ttdsmp.c
4068   */
4069   pSMPRequestBody->SMPCompletionFunc(
4070                                      agRoot,
4071                                      agIORequest,
4072                                      agIOStatus,
4073                                      agIOInfoLen,
4074                                      agFrameHandle
4075                                      );
4076 
4077 #endif /* Not PASSTHROUGH */
4078 
4079   smTraceFuncExit(hpDBG_VERY_LOUD, 'e', "Y4");
4080 ext:
4081   TDSA_OUT_LEAVE((tiRoot_t *)((tdsaRootOsData_t *)agRoot->osData)->tiRoot);
4082   return;
4083 }
4084 
4085 osGLOBAL void
4086 ossaSMPReqReceived(
4087                    agsaRoot_t           *agRoot,
4088                    agsaDevHandle_t      *agDevHandle,
4089                    agsaFrameHandle_t    agFrameHandle,
4090                    bit32                agIOInfoLen,
4091                    bit32                phyId
4092                    )
4093 {
4094   smTraceFuncEnter(hpDBG_VERY_LOUD,"Y5");
4095   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Y5");
4096   return;
4097 }
4098 
4099 /*****************************************************************************/
4100 /*! \brief ossaSMPCAMCompleted
4101  *
4102  *
4103  *  Purpose: This routine is called by lower layer to indicate the completion of
4104  *           SMP request
4105  *
4106  *  \param   agRoot:       Pointer to chip/driver Instance.
4107  *  \param   agIORequest   Pointer to SMP request handle
4108  *  \param   agIOStatus    Status
4109  *  \param   agIOInfoLen   IO information length assoicated with the IO
4110  *  \param   agFrameHandle A Handle used to refer to the response frame
4111  *
4112  *
4113  *  \return None.
4114  *
4115  *  \note - The scope is shared target and initiator.
4116  *          For details, refer to SAS/SATA Low-Level API Specification
4117  */
4118 /*****************************************************************************/
4119 osGLOBAL void ossaSMPCAMCompleted(
4120                  agsaRoot_t            *agRoot,
4121                  agsaIORequest_t       *agIORequest,
4122                  bit32                 agIOStatus,
4123                  bit32                 agIOInfoLen,
4124                  agsaFrameHandle_t     agFrameHandle
4125                  )
4126 {
4127   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
4128   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
4129   tdIORequestBody_t   *tdSMPRequestBody  = agNULL;
4130   bit32                context = osData->IntContext;
4131   tiSMPStatus_t        status;
4132   bit32               PhysUpper32;
4133   bit32               PhysLower32;
4134   bit32               memAllocStatus;
4135   void                *osMemHandle;
4136   bit32               *SMPpayload;
4137   TI_DBG2(("ossaSMPCAMCompleted: start\n"));
4138   TI_DBG2(("ossaSMPCAMCompleted: agIOInfoLen %d\n", agIOInfoLen));
4139   if (!agIORequest->osData)
4140   {
4141     TD_ASSERT((0), "ossaSMPCAMCompleted agIORequest->osData");
4142     goto ext;
4143   }
4144   tdSMPRequestBody = (tdIORequestBody_t *)agIORequest->osData;
4145   if (tdSMPRequestBody->tiIORequest->osData == agNULL)
4146   {
4147     TI_DBG1(("ossaSMPCAMCompleted: tdIORequestBody->tiIORequest->osData is null, wrong\n"));
4148     goto ext;
4149   }
4150   /* allocating agIORequest for SMP Payload itself */
4151   memAllocStatus = ostiAllocMemory(
4152                                    tiRoot,
4153                                    &osMemHandle,
4154                                    (void **)&SMPpayload,
4155                                    &PhysUpper32,
4156                                    &PhysLower32,
4157                                    8,
4158                                    agIOInfoLen,
4159                                    agTRUE
4160                                    );
4161   if (memAllocStatus != tiSuccess)
4162   {
4163     /* let os process IO */
4164     TI_DBG1(("ossaSMPCAMCompleted: ostiAllocMemory failed...\n"));
4165     goto ext;
4166   }
4167   if (SMPpayload == agNULL)
4168   {
4169     TI_DBG1(("ossaSMPCAMCompleted: ostiAllocMemory returned NULL SMPpayload\n"));
4170     goto ext;
4171   }
4172   if (agIOStatus == OSSA_IO_SUCCESS)
4173   {
4174     TI_DBG1(("ossaSMPCAMCompleted: Success status\n"));
4175     osti_memset(SMPpayload, 0, agIOInfoLen);
4176     TI_DBG1(("ossaSMPCAMCompleted: after memset\n"));
4177     saFrameReadBlock(agRoot, agFrameHandle, 0, SMPpayload, agIOInfoLen);
4178     TI_DBG1(("ossaSMPCAMCompleted: after read \n"));
4179     status = tiSMPSuccess;
4180   }
4181   else if (agIOStatus == OSSA_IO_ABORTED)
4182   {
4183     TI_DBG1(("ossaSMPCAMCompleted: SMP Aborted status\n"));
4184     status = tiSMPAborted;
4185     TI_DBG1(("ossaSMPCAMCompleted: failed status=%d\n", status));
4186     //failed to send smp command, we need to free the memory
4187     ostiFreeMemory(
4188                   tiRoot,
4189                   osMemHandle,
4190                   agIOInfoLen
4191                   );
4192   }
4193   else
4194   {
4195     TI_DBG1(("ossaSMPCAMCompleted: SMP failed status\n"));
4196     status = tiSMPFailed;
4197     TI_DBG1(("ossaSMPCAMCompleted: failed status=%d\n", status));
4198     //failed to send smp command, we need to free the memory
4199     ostiFreeMemory(
4200                   tiRoot,
4201                   osMemHandle,
4202                   agIOInfoLen
4203                   );
4204   }
4205   ostiInitiatorSMPCompleted(tiRoot,
4206                             tdSMPRequestBody->tiIORequest,
4207                             status,
4208                             agIOInfoLen,
4209                             SMPpayload,
4210                             context
4211                             );
4212   ext:
4213   TDSA_OUT_LEAVE((tiRoot_t*)((tdsaRootOsData_t*)agRoot->osData)->tiRoot);
4214   return;
4215 }
4216 #ifdef REMOVED
4217 #ifdef TARGET_DRIVER
4218 /*****************************************************************************/
4219 /*! \brief ossaSMPReqReceived
4220  *
4221  *
4222  *  Purpose: This routine is called by lower layer to indicate the reception of
4223  *           SMP request
4224  *
4225  *  \param   agRoot:       Pointer to chip/driver Instance.
4226  *  \param   agDevHandle   Pointer to the device handle of the device
4227  *  \param   agFrameHandle A Handle used to refer to the response frame
4228  *
4229  *
4230  *  \return None.
4231  *
4232  *  \note - The scope is target only
4233  *          For details, refer to SAS/SATA Low-Level API Specification
4234  */
4235 /*****************************************************************************/
4236 osGLOBAL void ossaSMPReqReceived(
4237                    agsaRoot_t           *agRoot,
4238                    agsaDevHandle_t      *agDevHandle,
4239                    agsaFrameHandle_t    agFrameHandle,
4240                    bit32                 agFrameLength,
4241                    bit32                phyId
4242                    )
4243 {
4244   bit8                   smpHeader[4];
4245   agsaSMPFrameHeader_t   *agFrameHeader;
4246 #ifdef PASSTHROUGH
4247   /* call the registered function(parameter in tiTGTPassthroughCmndRegister() by target */
4248   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
4249   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
4250   ttdsaTgt_t             *Target = (ttdsaTgt_t *)osData->ttdsaTgt;
4251 
4252   bit8                   SMPframe[agIOInfoLen + sizeof(agsaSMPFrameHeader_t)];
4253   bit8                   SMPpayload[agIOInfoLen];
4254 
4255   TI_DBG2(("ossaSMPReqReceived: start and passthrough\n"));
4256   osti_memset(SMPpayload, 0, agIOInfoLen);
4257   osti_memset(SMPframe, 0, agIOInfoLen + sizeof(agsaSMPFrameHeader_t));
4258   /* combine smp header and payload */
4259   saFrameReadBlock(agRoot, agFrameHandle, 0, &SMPpayload, agIOInfoLen);
4260   osti_memcpy(SMPframe, agFrameHeader, sizeof(agsaSMPFrameHeader_t));
4261   osti_memcpy(SMPframe+sizeof(agsaSMPFrameHeader_t), SMPpayload, agIOInfoLen);
4262 
4263   Target->PasthroughCB(
4264                        tiRoot,
4265                        tiSASATA,
4266                        tiSMP,
4267                        tiSMPResponse,
4268                        SMPframe,
4269                        agIOInfoLen + sizeof(agsaSMPFrameHeader_t),
4270                        phyId
4271                        );
4272 
4273 #else
4274 
4275   /*
4276     agDevHandle_t->osData points to tdssDeviceData_t
4277    */
4278   tdsaDeviceData_t *pDeviceData = (tdsaDeviceData_t *) agDevHandle->osData;
4279 
4280     saFrameReadBlock(agRoot, agFrameHandle, 0, smpHeader, 4);
4281     agFrameHeader = (agsaSMPFrameHeader_t *)smpHeader;
4282   TI_DBG4(("ossaSMPReqReceived: start\n"));
4283 
4284   /* tdtypes.h, calling  ttdsaSMPReqReceived in ttdsmp.c */
4285   pDeviceData->pJumpTable->pSMPReqReceived (
4286                                             agRoot,
4287                                             agDevHandle,
4288                                             agFrameHeader,
4289                                             agFrameHandle,
4290                                             agFrameLength,
4291                                             phyId
4292                                             );
4293 #endif
4294   return;
4295 }
4296 #endif
4297 #endif
4298 
4299 /*****************************************************************************/
4300 /*! \brief ossaSSPCompleted
4301  *
4302  *
4303  *  Purpose: This routine is called by lower layer to indicate the completion of
4304  *           SSP request
4305  *
4306  *  \param   agRoot:       Pointer to chip/driver Instance.
4307  *  \param   agIORequest   Pointer to SMP request handle
4308  *  \param   agIOStatus    Status
4309  *  \param   agIOInfoLen   IO information length assoicated with the IO
4310  *  \param   agFrameHandle A Handle used to refer to the response frame
4311  *
4312  *
4313  *  \return None.
4314  *
4315  *  \note - The scope is shared target and initiator.
4316  *          For details, refer to SAS/SATA Low-Level API Specification
4317  */
4318 /*****************************************************************************/
4319 FORCEINLINE
4320 void ossaSSPCompleted(
4321                  agsaRoot_t          *agRoot,
4322                  agsaIORequest_t     *agIORequest,
4323                  bit32               agIOStatus,
4324                  bit32               agIOInfoLen,
4325                  void                *agParam,
4326                  bit16               sspTag,
4327                  bit32               agOtherInfo
4328                 )
4329 {
4330   tdIORequestBody_t  *pIORequestBody;
4331 #ifdef TD_DEBUG_ENABLE
4332   tiDeviceHandle_t   *tiDeviceHandle = agNULL;
4333   tdsaDeviceData_t   *oneDeviceData = agNULL;
4334 #endif
4335 
4336   TDSA_OUT_ENTER((tiRoot_t*)((tdsaRootOsData_t*)agRoot->osData)->tiRoot);
4337   smTraceFuncEnter(hpDBG_VERY_LOUD,"2L");
4338 
4339   if(!agIORequest->osData)
4340   {
4341     TD_ASSERT((0), "ossaSSPCompleted agIORequest->osData");
4342     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2L");
4343     goto ext;
4344   }
4345   pIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4346 
4347 
4348   TI_DBG4(("ossaSSPCompleted: start\n"));
4349 
4350   if (pIORequestBody == agNULL)
4351   {
4352     TI_DBG1(("ossaSSPCompleted: pIORequestBody is NULL \n"));
4353     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2L");
4354     goto ext;
4355   }
4356   if (pIORequestBody->IOCompletionFunc == agNULL)
4357   {
4358 #ifdef TD_DEBUG_ENABLE
4359     tiDeviceHandle = pIORequestBody->tiDevHandle;
4360     oneDeviceData  = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
4361 #endif
4362     TI_DBG1(("ossaSSPCompleted: IOCompletionFunc is NULL \n"));
4363     TI_DBG1(("ossaSSPCompleted: did %d \n", oneDeviceData->id));
4364     smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "2L");
4365     goto ext;
4366   }
4367 
4368    /*
4369      if initiator, calling itdssIOCompleted() in itdcb.c
4370      if initiator, calling itdssTaskCompleted in itdcb.c
4371      if target,    calling ttdsaIOCompleted() in ttdio.c
4372    */
4373   pIORequestBody->IOCompletionFunc(
4374                                    agRoot,
4375                                    agIORequest,
4376                                    agIOStatus,
4377                                    agIOInfoLen,
4378                                    agParam,
4379                                    agOtherInfo
4380                                    );
4381   smTraceFuncExit(hpDBG_VERY_LOUD, 'd', "2L");
4382 ext:
4383   TDSA_OUT_LEAVE((tiRoot_t*)((tdsaRootOsData_t*)agRoot->osData)->tiRoot);
4384   return;
4385 }
4386 
4387 #ifdef FAST_IO_TEST
4388 GLOBAL void ossaFastSSPCompleted(
4389                  agsaRoot_t          *agRoot,
4390                  agsaIORequest_t     *cbArg,
4391                  bit32               agIOStatus,
4392                  bit32               agIOInfoLen,
4393                  void                *agParam,
4394                  bit16               sspTag,
4395                  bit32               agOtherInfo
4396                 )
4397 {
4398   agsaFastCBBuf_t    *safb = (agsaFastCBBuf_t*)cbArg;
4399   tdsaRootOsData_t *osData = (tdsaRootOsData_t*)agRoot->osData;
4400   tiRoot_t         *tiRoot = (tiRoot_t*)osData->tiRoot;
4401   bit32            scsi_status;
4402   bit32            data_status;
4403   bit32            respLen;
4404   bit8             respData[128];
4405   bit32            senseLen;
4406   agsaSSPResponseInfoUnit_t agSSPRespIU;
4407 
4408   TDSA_OUT_ENTER((tiRoot_t*)((tdsaRootOsData_t*)agRoot->osData)->tiRoot);
4409   smTraceFuncEnter(hpDBG_VERY_LOUD,"Y6");
4410 
4411   TI_DBG4(("ossaSSPCompleted: start\n"));
4412 
4413   if (safb->cb == agNULL || safb->cbArg == agNULL)
4414   {
4415     TI_DBG1(("ossaFastSSPCompleted: pIORequestBody is NULL \n"));
4416     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Y6");
4417     TD_ASSERT((0), "");
4418     goto ext;
4419   }
4420 
4421   switch (agIOStatus)
4422   {
4423     case OSSA_IO_SUCCESS:
4424 
4425       /* ~ itdssIOSuccessHandler */
4426       if ((agIOInfoLen < sizeof(agsaSSPResponseInfoUnit_t)))
4427       {
4428         ((ostiFastSSPCb_t)safb->cb)(tiRoot, safb->cbArg, OSSA_IO_SUCCESS, 0);
4429         break;
4430       }
4431 
4432       /* reads agsaSSPResponseInfoUnit_t */
4433       saFrameReadBlock(agRoot, agParam, 0, &agSSPRespIU,
4434                        sizeof(agsaSSPResponseInfoUnit_t));
4435 
4436       data_status = SA_SSPRESP_GET_DATAPRES(&agSSPRespIU);
4437       scsi_status = agSSPRespIU.status;
4438 
4439       TI_DBG1(("itdssIOSuccessHandler: scsi_status %d\n", scsi_status));
4440 
4441       /* endianess is invovled here */
4442       senseLen = SA_SSPRESP_GET_SENSEDATALEN(&agSSPRespIU);
4443       respLen = SA_SSPRESP_GET_RESPONSEDATALEN(&agSSPRespIU);
4444       TI_DBG2(("itdssIOSuccessHandler: scsi status=0x%x, senselen=0x%x resplen "
4445                "0x%x\n", scsi_status, senseLen, respLen));
4446 
4447       if (agIOInfoLen < sizeof(agsaSSPResponseInfoUnit_t) + senseLen + respLen)
4448       {
4449         ((ostiFastSSPCb_t)safb->cb)(tiRoot, safb->cbArg, tiIOFailed,
4450                                      tiDetailOtherError);
4451         break;
4452       }
4453 
4454       /* reads response data */
4455       saFrameReadBlock(agRoot, agParam, sizeof(agsaSSPResponseInfoUnit_t),
4456                        respData, respLen);
4457       /* reads sense data */
4458       saFrameReadBlock(agRoot, agParam, sizeof(agsaSSPResponseInfoUnit_t)
4459                        + respLen, safb->pSenseData, senseLen);
4460 
4461       if (data_status == 0)
4462       {
4463         /* NO_DATA */
4464         TI_DBG2(("ossaFastSSPCompleted: no data\n"));
4465         ((ostiFastSSPCb_t)safb->cb)(tiRoot, safb->cbArg, tiIOSuccess,
4466                                      scsi_status);
4467         break;
4468       }
4469 
4470       if (data_status == 1)
4471       {
4472         /* RESPONSE_DATA */
4473         TI_DBG1(("ossaFastSSPCompleted: response data \n"));
4474         ((ostiFastSSPCb_t)safb->cb)(tiRoot, safb->cbArg, tiIOSuccess, 0);
4475         break;
4476       }
4477 
4478       if (data_status == 2)
4479       {
4480         tiSenseData_t senseData;
4481 
4482         /* SENSE_DATA */
4483         TI_DBG2(("itdssIOSuccessHandler: sense data \n"));
4484 
4485         senseData.senseData = safb->pSenseData;
4486         senseData.senseLen = MIN(*(safb->senseLen), senseLen);
4487 
4488         /* when ASC = 0x04 - Log Unit Not Ready,
4489            and ASCQ = 0x11 - Enable Spinup Required:
4490            call saLocalPhyControl to notify spinup */
4491         if (((char*)safb->pSenseData)[12] == 0x04 &&
4492             ((char*)safb->pSenseData)[13] == 0x11)
4493         {
4494           int i;
4495 
4496           TI_DBG2(("ossaFastSSPCompleted: sending notfify spinup\n"));
4497 
4498           if (((tdsaDeviceData_t*)safb->oneDeviceData)->directlyAttached ==
4499                agTRUE)
4500           {
4501             for (i = 0; i < TD_MAX_NUM_NOTIFY_SPINUP; i++)
4502             {
4503               saLocalPhyControl(agRoot, agNULL, 0,
4504                                 ((tdsaDeviceData_t*)safb->oneDeviceData)->phyID,
4505                                 AGSA_PHY_NOTIFY_ENABLE_SPINUP,
4506                                 agNULL);
4507             }
4508           }
4509         }
4510 
4511         if (*(safb->senseLen) > senseData.senseLen)
4512           *(safb->senseLen) = senseData.senseLen;
4513 //       memcpy((void *)safb->pSenseData, senseData.senseData, safb->senseLen);
4514 
4515         ((ostiFastSSPCb_t)safb->cb)(tiRoot, safb->cbArg, tiIOSuccess,
4516                                      scsi_status);
4517         break;
4518       }
4519 
4520       if (data_status == 3)
4521       {
4522         /* RESERVED */
4523         TI_DBG1(("ossaFastSSPCompleted: reserved wrong!!!\n"));
4524 
4525         ((ostiFastSSPCb_t)safb->cb)(tiRoot, safb->cbArg, tiIOFailed,
4526                                      scsi_status);
4527         break;
4528       }
4529       break;
4530 #ifdef REMOVED
4531     case OSSA_IO_OVERFLOW:
4532       ((ostiFastSSPCb_t)safb->cb)(tiRoot, safb->cbArg, tiIOOverRun,
4533                                    agIOInfoLen);
4534       break;
4535 #endif /* REMOVED */
4536     case OSSA_IO_UNDERFLOW:
4537       ((ostiFastSSPCb_t)safb->cb)(tiRoot, safb->cbArg, tiIOUnderRun,
4538                                    agIOInfoLen);
4539       break;
4540 
4541     case OSSA_IO_ABORTED:
4542       ((ostiFastSSPCb_t)safb->cb)(tiRoot, safb->cbArg, tiIOFailed,
4543                                    tiDetailAborted);
4544       break;
4545     case OSSA_IO_ABORT_RESET:
4546       ((ostiFastSSPCb_t)safb->cb)(tiRoot, safb->cbArg, tiIOFailed,
4547                                    tiDetailAbortReset);
4548       break;
4549     case OSSA_IO_NO_DEVICE:
4550       ((ostiFastSSPCb_t)safb->cb)(tiRoot, safb->cbArg, tiIOFailed,
4551                                    tiDetailNoLogin);
4552       break;
4553     case OSSA_IO_DS_NON_OPERATIONAL:
4554     {
4555 
4556       tdsaDeviceData_t *oneDeviceData;
4557 
4558       oneDeviceData = (tdsaDeviceData_t*)safb->oneDeviceData;
4559       if (oneDeviceData->valid == agTRUE &&
4560           oneDeviceData->registered == agTRUE &&
4561           oneDeviceData->tdPortContext != agNULL)
4562       {
4563         saSetDeviceState(oneDeviceData->agRoot, agNULL, tdsaRotateQnumber(tiRoot, oneDeviceData),
4564                          oneDeviceData->agDevHandle, SA_DS_OPERATIONAL);
4565       }
4566       /* fall through */
4567     }
4568 
4569     default:
4570       ((ostiFastSSPCb_t)safb->cb)(tiRoot, safb->cbArg, tiIOFailed,
4571                                    tiDetailOtherError);
4572       break;
4573   }
4574 
4575   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "Y6");
4576 
4577 ext:
4578   TDSA_OUT_LEAVE((tiRoot_t*)((tdsaRootOsData_t*)agRoot->osData)->tiRoot);
4579   return;
4580 } /* ossaFastSSPCompleted */
4581 #endif
4582 
4583 /*****************************************************************************/
4584 /*! \brief ossaSSPReqReceived
4585  *
4586  *
4587  *  Purpose: This routine is called by lower layer to indicate the reception of
4588  *           SMP request
4589  *
4590  *  \param   agRoot:         Pointer to chip/driver Instance.
4591  *  \param   agDevHandle     Pointer to the device handle of the device
4592  *  \param   agFrameHandle   A Handle used to refer to the response frame
4593  *  \param   agInitiatorTag  the initiator tag
4594  *  \param   agFrameType     SSP frame type
4595  *
4596  *  \return none.
4597  *
4598  *  \note - The scope is target only
4599  *          For details, refer to SAS/SATA Low-Level API Specification
4600  */
4601 /*****************************************************************************/
4602 osGLOBAL void ossaSSPReqReceived(
4603                    agsaRoot_t           *agRoot,
4604                    agsaDevHandle_t      *agDevHandle,
4605                    agsaFrameHandle_t    agFrameHandle,
4606                    bit16                agInitiatorTag,
4607                    bit32                parameter,
4608                    bit32                agFrameLen
4609                    )
4610 {
4611   /*
4612     at target only
4613     uses jumptable, not callback
4614   */
4615   /*
4616     agDevHandle_t->osData points to tdssDeviceData_t
4617   */
4618   tdsaDeviceData_t *pDeviceData = (tdsaDeviceData_t *) agDevHandle->osData;
4619   smTraceFuncEnter(hpDBG_VERY_LOUD,"Y7");
4620 
4621   /* tdtypes.h, calling  ttdsaSSPReqReceived() in ttdio.c */
4622   pDeviceData->pJumpTable->pSSPReqReceived (
4623                                             agRoot,
4624                                             agDevHandle,
4625                                             agFrameHandle,
4626                                             agInitiatorTag,
4627                                             parameter,
4628                                             agFrameLen
4629                                             );
4630   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Y7");
4631   return;
4632 }
4633 /*****************************************************************************/
4634 /*! \brief ossaStallThread
4635  *
4636  *
4637  *  Purpose: This routine is called to stall this thread for a number of
4638  *           microseconds.
4639  *
4640  *
4641  *  \param  agRoot:       Pointer to chip/driver Instance.
4642  *  \param   microseconds: Micro second to stall.
4643  *
4644  *
4645  *  \return None.
4646  *
4647  *  \note - The scope is shared target and initiator.
4648  *
4649  */
4650 /*****************************************************************************/
4651 osGLOBAL void ossaStallThread(agsaRoot_t *agRoot,
4652                 bit32 microseconds
4653                 )
4654 {
4655   tdsaRootOsData_t *pOsData = (tdsaRootOsData_t *) (agRoot->osData);
4656 
4657   ostiStallThread (
4658                    pOsData->tiRoot,
4659                    microseconds
4660                    );
4661   return;
4662 }
4663 
4664 
4665 /*****************************************************************************
4666 *! \brief  ossaSSPEvent
4667 *
4668 *   This routine is called to notify the OS Layer of an event associated with
4669 *   SAS port or SAS device
4670 *
4671 *  \param   agRoot:         Handles for this instance of SAS/SATA hardware
4672 *  \param   agIORequest     Pointer to IO request
4673 *  \param   event:          event type
4674 *  \param   agIOInfoLen:    not in use
4675 *  \param   agFrameHandle:  not in use
4676 *
4677 *  \return: none
4678 *
4679 *****************************************************************************/
4680 /* in case of CMD ACK_NAK timeout, send query task */
4681 osGLOBAL void ossaSSPEvent(
4682              agsaRoot_t           *agRoot,
4683              agsaIORequest_t      *agIORequest,
4684              agsaPortContext_t    *agPortContext,
4685              agsaDevHandle_t      *agDevHandle,
4686              bit32                event,
4687              bit16                sspTag,
4688              bit32                agIOInfoLen,
4689              void                 *agParam
4690              )
4691 {
4692 #ifdef INITIATOR_DRIVER
4693   tdsaRootOsData_t            *osData = (tdsaRootOsData_t *)agRoot->osData;
4694   tiRoot_t                    *tiRoot = (tiRoot_t *)osData->tiRoot;
4695   /*  bit32                       intContext = osData->IntContext; */
4696   void                        *osMemHandle;
4697   tdIORequestBody_t           *TMtdIORequestBody;
4698   bit32                       PhysUpper32;
4699   bit32                       PhysLower32;
4700   bit32                       memAllocStatus;
4701   bit32                       agRequestType;
4702   agsaIORequest_t             *agTMIORequest = agNULL;  /* task management itself */
4703   agsaSASRequestBody_t        *agSASRequestBody = agNULL;
4704   agsaSSPScsiTaskMgntReq_t    *agSSPTaskMgntRequest;
4705   bit32                       saStatus;
4706   bit32                       agIORequestType;  /* type of IO recevied */
4707   tiIORequest_t               *taskTag;                 /* being task managed one */
4708   tdIORequestBody_t           *tdIORequestBody;
4709 #endif
4710 
4711 #ifdef REMOVED
4712   tiDeviceHandle_t            *tiDeviceHandle;
4713   tdsaDeviceData_t            *oneDeviceData = agNULL;
4714   tdIORequestBody_t           *tdAbortIORequestBody;
4715 #endif
4716   agsaDifDetails_t            agDifDetails;
4717   bit8                        framePayload[256];
4718 #ifdef REMOVED
4719   bit16                       frameOffset = 0;
4720 #endif
4721   bit16                       frameLen = 0;
4722 
4723   TI_DBG6(("ossaSSPEvent: start\n"));
4724   smTraceFuncEnter(hpDBG_VERY_LOUD,"Y9");
4725 
4726 
4727 
4728   if (event == OSSA_IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT ||
4729       event == OSSA_IO_XFER_ERROR_BREAK ||
4730       event == OSSA_IO_XFER_ERROR_PHY_NOT_READY
4731       )
4732   {
4733 
4734     /* IO being task managed(the original IO) depending on event */
4735 #ifdef INITIATOR_DRIVER
4736     tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4737     taskTag         = tdIORequestBody->tiIORequest;
4738 #endif
4739 #ifdef REMOVED
4740     tiDeviceHandle  = tdIORequestBody->tiDevHandle;
4741     oneDeviceData   = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
4742 #endif
4743 
4744 #ifdef INITIATOR_DRIVER
4745     agIORequestType = tdIORequestBody->agRequestType;
4746 
4747     /* error checking; only command is expected here */
4748     if (agIORequestType == AGSA_REQ_TYPE_UNKNOWN)
4749     {
4750       TI_DBG1(("ossaSSPEvent: incorrect frame 0x%x. Should be command\n", agIORequestType));
4751       smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Y9");
4752       return;
4753     }
4754 
4755     /* Allocate memory for query task management */
4756     memAllocStatus = ostiAllocMemory(
4757                                      tiRoot,
4758                                      &osMemHandle,
4759                                      (void **)&TMtdIORequestBody,
4760                                      &PhysUpper32,
4761                                      &PhysLower32,
4762                                      8,
4763                                      sizeof(tdIORequestBody_t),
4764                                      agTRUE
4765                                      );
4766 
4767     if (memAllocStatus != tiSuccess)
4768     {
4769       /* let os process IO */
4770       TI_DBG1(("ossaSSPEvent: ostiAllocMemory failed...\n"));
4771       smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "Y9");
4772       return;
4773     }
4774 
4775     if (TMtdIORequestBody == agNULL)
4776     {
4777       /* let os process IO */
4778       TI_DBG1(("ossaSSPEvent: ostiAllocMemory returned NULL TMIORequestBody\n"));
4779       smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "Y9");
4780       return;
4781     }
4782 
4783     /* setup task management structure */
4784     TMtdIORequestBody->IOType.InitiatorTMIO.osMemHandle = osMemHandle;
4785     /* TD generates Query Task not OS layer */
4786     TMtdIORequestBody->IOType.InitiatorTMIO.CurrentTaskTag = agNULL;
4787     TMtdIORequestBody->IOType.InitiatorTMIO.TaskTag = taskTag;
4788 
4789     /* initialize callback function */
4790     TMtdIORequestBody->IOCompletionFunc = itdssQueryTaskCompleted;
4791 
4792     /* initialize tiDevhandle */
4793     TMtdIORequestBody->tiDevHandle = tdIORequestBody->tiDevHandle;
4794 
4795 
4796     /* initialize agIORequest */
4797     agTMIORequest = &(TMtdIORequestBody->agIORequest);
4798     agTMIORequest->osData = (void *) TMtdIORequestBody;
4799     agTMIORequest->sdkData = agNULL; /* LL takes care of this */
4800 
4801     /* request type */
4802     agRequestType = AGSA_SSP_TASK_MGNT_REQ;
4803     TMtdIORequestBody->agRequestType = AGSA_SSP_TASK_MGNT_REQ;
4804 
4805     /*
4806       initialize
4807       tdIORequestBody_t tdIORequestBody -> agSASRequestBody
4808     */
4809     agSASRequestBody = &(TMtdIORequestBody->transport.SAS.agSASRequestBody);
4810     agSSPTaskMgntRequest = &(agSASRequestBody->sspTaskMgntReq);
4811 
4812     /* fill up LUN field */
4813     osti_memset(agSSPTaskMgntRequest->lun, 0, 8);
4814 
4815     /* sets taskMgntFunction field */
4816     agSSPTaskMgntRequest->taskMgntFunction = AGSA_QUERY_TASK;
4817     /* debugging */
4818     if (TMtdIORequestBody->IOCompletionFunc == agNULL)
4819     {
4820       TI_DBG1(("ossaSSPEvent: Error !!! IOCompletionFunc is NULL\n"));
4821     }
4822     /* send query task management */
4823     saStatus = saSSPStart(agRoot,
4824                           agTMIORequest,
4825                           0,
4826                           agDevHandle,
4827                           agRequestType,
4828                           agSASRequestBody,
4829                           agIORequest,
4830                           &ossaSSPCompleted);
4831 
4832     if (saStatus != AGSA_RC_SUCCESS)
4833     {
4834       /* free up allocated memory */
4835       ostiFreeMemory(
4836                      tiRoot,
4837                      TMtdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
4838                      sizeof(tdIORequestBody_t)
4839                      );
4840       TI_DBG1(("ossaSSPEvent: saSSPStart failed\n"));
4841       return;
4842     }
4843 #endif
4844   }
4845 #ifdef REMOVED
4846   else if (event == OSSA_IO_ABORTED)
4847   {
4848     TI_DBG2(("ossaSSPEvent: OSSA_IO_ABORTED\n"));
4849     /* clean up TD layer's IORequestBody */
4850     tdAbortIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4851     ostiFreeMemory(
4852                    tiRoot,
4853                    tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
4854                    sizeof(tdIORequestBody_t)
4855                    );
4856 
4857   }
4858   else if (event == OSSA_IO_NOT_VALID)
4859   {
4860     TI_DBG1(("ossaSSPEvent: OSSA_IO_NOT_VALID\n"));
4861     tdAbortIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4862     ostiFreeMemory(
4863                    tiRoot,
4864                    tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
4865                    sizeof(tdIORequestBody_t)
4866                    );
4867 
4868 
4869   }
4870 #endif
4871   else if (event == OSSA_IO_XFER_CMD_FRAME_ISSUED)
4872   {
4873     TI_DBG2(("ossaSSPEvent: OSSA_IO_XFER_CMD_FRAME_ISSUED\n"));
4874   }
4875   else if (event == OSSA_IO_XFER_ERROR_OFFSET_MISMATCH)
4876   {
4877     TI_DBG1(("ossaSSPEvent: OSSA_IO_XFER_ERROR_OFFSET_MISMATCH\n"));
4878   }
4879   else if (event == OSSA_IO_OVERFLOW)
4880   {
4881     TI_DBG1(("ossaSSPEvent: OSSA_IO_OVERFLOW\n"));
4882     /*
4883     ??? can't call; missing agIOInfoLen
4884     ostiInitiatorIOCompleted (
4885                               tiRoot,
4886                               tdIORequestBody->tiIORequest,
4887                               tiIOOverRun,
4888                               agIOInfoLen,
4889                               agNULL,
4890                               intContext
4891                               );
4892 
4893     */
4894 
4895   }
4896   else if (event == OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED)
4897   {
4898     TI_DBG1(("ossaSSPEvent: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED\n"));
4899   }
4900   else if (event == OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO)
4901   {
4902     TI_DBG1(("ossaSSPEvent: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO\n"));
4903   }
4904   else if (event == OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST)
4905   {
4906     TI_DBG1(("ossaSSPEvent: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST\n"));
4907   }
4908   else if (event == OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE)
4909   {
4910     TI_DBG1(("ossaSSPEvent: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE\n"));
4911   }
4912   else if (event == OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED)
4913   {
4914     TI_DBG1(("ossaSSPEvent: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED\n"));
4915   }
4916   else if (event == OSSA_IO_XFR_ERROR_DEK_KEY_TAG_MISMATCH)
4917   {
4918     TI_DBG1(("ossaSSPEvent: OSSA_IO_XFR_ERROR_DEK_KEY_TAG_MISMATCH\n"));
4919   }
4920   else if (event == OSSA_IO_XFER_ERROR_XFER_RDY_OVERRUN)
4921   {
4922     TI_DBG1(("ossaSSPEvent: OSSA_IO_XFER_ERROR_XFER_RDY_OVERRUN\n"));
4923   }
4924   else if (event == OSSA_IO_XFR_ERROR_DIF_MISMATCH                 ||
4925            event == OSSA_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH ||
4926            event == OSSA_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH   ||
4927            event == OSSA_IO_XFR_ERROR_DIF_CRC_MISMATCH                 )
4928   {
4929     TI_DBG1(("ossaSSPEvent: DIF related, event 0x%x\n", event));
4930     /* process DIF detail information */
4931     TI_DBG2(("ossaSSPEvent: agIOInfoLen %d\n", agIOInfoLen));
4932     if (agParam == agNULL)
4933     {
4934       TI_DBG2(("ossaSSPEvent: agParam is NULL!!!\n"));
4935       return;
4936     }
4937     if (agIOInfoLen < sizeof(agsaDifDetails_t))
4938     {
4939       TI_DBG2(("ossaSSPEvent: wrong agIOInfoLen!!! agIOInfoLen %d sizeof(agsaDifDetails_t) %d\n", agIOInfoLen, (int)sizeof(agsaDifDetails_t)));
4940       return;
4941     }
4942     /* reads agsaDifDetails_t */
4943     saFrameReadBlock(agRoot, agParam, 0, &agDifDetails, sizeof(agsaDifDetails_t));
4944 #ifdef REMOVED
4945     frameOffset = (agDifDetails.ErrBoffsetEDataLen & 0xFFFF);
4946 #endif
4947     frameLen = (bit16)((agDifDetails.ErrBoffsetEDataLen & 0xFFFF0000) >> 16);
4948 
4949     TI_DBG2(("ossaSSPEvent: UpperLBA 0x%08x LowerLBA 0x%08x\n", agDifDetails.UpperLBA, agDifDetails.LowerLBA));
4950     TI_DBG2(("ossaSSPEvent: SASAddrHI 0x%08x SASAddrLO 0x%08x\n",
4951              TD_GET_SAS_ADDRESSHI(agDifDetails.sasAddressHi), TD_GET_SAS_ADDRESSLO(agDifDetails.sasAddressLo)));
4952     TI_DBG2(("ossaSSPEvent: DIF error mask 0x%x Device ID 0x%x\n",
4953              (agDifDetails.DIFErrDevID) & 0xFF, (agDifDetails.DIFErrDevID & 0xFFFF0000) >> 16));
4954     if (frameLen != 0 && frameLen <= 256)
4955     {
4956       saFrameReadBlock(agRoot, agParam, sizeof(agsaDifDetails_t), framePayload, frameLen);
4957       tdhexdump("ossaSSPEvent frame", framePayload, frameLen);
4958     }
4959   }
4960   else
4961   {
4962     TI_DBG1(("ossaSSPEvent: other event 0x%x\n", event));
4963   }
4964 
4965   smTraceFuncExit(hpDBG_VERY_LOUD, 'd', "Y9");
4966   return;
4967 }
4968 
4969 #ifdef FDS_SM
4970 osGLOBAL void ossaSATAIDAbortCB(
4971                agsaRoot_t               *agRoot,
4972                agsaIORequest_t          *agIORequest,
4973                bit32                    flag,
4974                bit32                    status)
4975 {
4976   tdsaRootOsData_t        *osData = (tdsaRootOsData_t *)agRoot->osData;
4977   tiRoot_t                *tiRoot = (tiRoot_t *)osData->tiRoot;
4978   tdIORequestBody_t       *tdAbortIORequestBody;
4979 
4980   TI_DBG1(("ossaSATAIDAbortCB: start flag %d status %d\n", flag, status));
4981 
4982   tdAbortIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
4983 
4984   /*
4985    triggered by tdIDStartTimerCB
4986   */
4987   ostiFreeMemory(
4988                  tiRoot,
4989                  tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
4990                  sizeof(tdIORequestBody_t)
4991                 );
4992   return;
4993 }
4994 #endif
4995 
4996 #ifdef INITIATOR_DRIVER
4997 osGLOBAL void ossaSSPAbortCB(
4998                agsaRoot_t               *agRoot,
4999                agsaIORequest_t          *agIORequest,
5000                bit32                    flag,
5001                bit32                    status)
5002 {
5003   tdsaRootOsData_t        *osData = (tdsaRootOsData_t *)agRoot->osData;
5004   tiRoot_t                *tiRoot = (tiRoot_t *)osData->tiRoot;
5005   tdIORequestBody_t       *tdAbortIORequestBody = agNULL;
5006   tdsaDeviceData_t        *oneDeviceData        = agNULL;
5007   tiDeviceHandle_t        *tiDeviceHandle       = agNULL;
5008   tiIORequest_t           *taskTag              = agNULL;
5009 
5010   TI_DBG2(("ossaSSPAbortCB: start\n"));
5011   smTraceFuncEnter(hpDBG_VERY_LOUD,"Ya");
5012 
5013   tdAbortIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
5014   if (tdAbortIORequestBody == agNULL)
5015   {
5016     TI_DBG1(("ossaSSPAbortCB: tdAbortIORequestBody is NULL warning!!!!\n"));
5017     return;
5018   }
5019 
5020   if (flag == 2)
5021   {
5022     /* abort per port */
5023     TI_DBG1(("ossaSSPAbortCB: abort per port\n"));
5024   }
5025   else if (flag == 1)
5026   {
5027     TI_DBG2(("ossaSSPAbortCB: abort all\n"));
5028 
5029     tiDeviceHandle = (tiDeviceHandle_t *)tdAbortIORequestBody->tiDevHandle;
5030     if (tiDeviceHandle == agNULL)
5031     {
5032       TI_DBG1(("ossaSSPAbortCB: tiDeviceHandle is NULL warning!!!!\n"));
5033       ostiFreeMemory(
5034                tiRoot,
5035                tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5036                sizeof(tdIORequestBody_t)
5037                );
5038       return;
5039     }
5040 
5041     oneDeviceData  = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
5042     if (oneDeviceData == agNULL)
5043     {
5044       TI_DBG1(("ossaSSPAbortCB: oneDeviceData is NULL warning!!!!\n"));
5045       ostiFreeMemory(
5046                tiRoot,
5047                tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5048                sizeof(tdIORequestBody_t)
5049                );
5050       return;
5051     }
5052 
5053     if (status == OSSA_IO_SUCCESS)
5054     {
5055       TI_DBG2(("ossaSSPAbortCB: OSSA_IO_SUCCESS\n"));
5056       /* clean up TD layer's IORequestBody */
5057       if (oneDeviceData->OSAbortAll == agTRUE)
5058       {
5059         oneDeviceData->OSAbortAll = agFALSE;
5060         ostiInitiatorEvent( tiRoot,
5061                             agNULL,
5062                             tiDeviceHandle,
5063                             tiIntrEventTypeLocalAbort,
5064                             tiAbortOK,
5065                             agNULL);
5066       }
5067       else
5068       {
5069         TI_DBG2(("ossaSSPAbortCB: calling saDeregisterDeviceHandle\n"));
5070         saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
5071       }
5072       TI_DBG2(("ossaSSPAbortCB: did %d\n", oneDeviceData->id));
5073       ostiFreeMemory(
5074                      tiRoot,
5075                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5076                      sizeof(tdIORequestBody_t)
5077                      );
5078 
5079     }
5080     else if (status == OSSA_IO_NOT_VALID)
5081     {
5082       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_NOT_VALID\n"));
5083       /* clean up TD layer's IORequestBody */
5084       if (oneDeviceData->OSAbortAll == agTRUE)
5085       {
5086         oneDeviceData->OSAbortAll = agFALSE;
5087         ostiInitiatorEvent( tiRoot,
5088                             agNULL,
5089                             tiDeviceHandle,
5090                             tiIntrEventTypeLocalAbort,
5091                             tiAbortFailed,
5092                             agNULL );
5093       }
5094       else
5095       {
5096         TI_DBG2(("ossaSSPAbortCB: calling saDeregisterDeviceHandle\n"));
5097         saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
5098       }
5099       TI_DBG2(("ossaSSPAbortCB: did %d\n", oneDeviceData->id));
5100       ostiFreeMemory(
5101                      tiRoot,
5102                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5103                      sizeof(tdIORequestBody_t)
5104                      );
5105     }
5106     else if (status == OSSA_IO_NO_DEVICE)
5107     {
5108       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_NO_DEVICE\n"));
5109       /* clean up TD layer's IORequestBody */
5110       if (oneDeviceData->OSAbortAll == agTRUE)
5111       {
5112         oneDeviceData->OSAbortAll = agFALSE;
5113         ostiInitiatorEvent( tiRoot,
5114                             agNULL,
5115                             tiDeviceHandle,
5116                             tiIntrEventTypeLocalAbort,
5117                             tiAbortInProgress,
5118                             agNULL );
5119       }
5120       else
5121       {
5122         TI_DBG2(("ossaSSPAbortCB: calling saDeregisterDeviceHandle\n"));
5123         saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
5124       }
5125       TI_DBG2(("ossaSSPAbortCB: did %d\n", oneDeviceData->id));
5126       ostiFreeMemory(
5127                      tiRoot,
5128                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5129                      sizeof(tdIORequestBody_t)
5130                      );
5131     }
5132     else if (status == OSSA_IO_ABORT_IN_PROGRESS)
5133     {
5134       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_ABORT_IN_PROGRESS\n"));
5135       /* clean up TD layer's IORequestBody */
5136       if (oneDeviceData->OSAbortAll == agTRUE)
5137       {
5138         oneDeviceData->OSAbortAll = agFALSE;
5139         ostiInitiatorEvent( tiRoot,
5140                             agNULL,
5141                             tiDeviceHandle,
5142                             tiIntrEventTypeLocalAbort,
5143                             tiAbortInProgress,
5144                             agNULL );
5145       }
5146       else
5147       {
5148         TI_DBG2(("ossaSSPAbortCB: calling saDeregisterDeviceHandle\n"));
5149         saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
5150       }
5151       TI_DBG2(("ossaSSPAbortCB: did %d\n", oneDeviceData->id));
5152       ostiFreeMemory(
5153                      tiRoot,
5154                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5155                      sizeof(tdIORequestBody_t)
5156                      );
5157     }
5158 #ifdef REMOVED
5159     else if (status == OSSA_IO_ABORT_DELAYED)
5160     {
5161       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_ABORT_DELAYED\n"));
5162       /* clean up TD layer's IORequestBody */
5163       if (oneDeviceData->OSAbortAll == agTRUE)
5164       {
5165         oneDeviceData->OSAbortAll = agFALSE;
5166         ostiInitiatorEvent( tiRoot,
5167                             agNULL,
5168                             tiDeviceHandle,
5169                             tiIntrEventTypeLocalAbort,
5170                             tiAbortDelayed,
5171                             agNULL );
5172       }
5173       else
5174       {
5175         TI_DBG2(("ossaSSPAbortCB: calling saDeregisterDeviceHandle\n"));
5176         saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
5177       }
5178       TI_DBG2(("ossaSSPAbortCB: did %d\n", oneDeviceData->id));
5179       ostiFreeMemory(
5180                      tiRoot,
5181                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5182                      sizeof(tdIORequestBody_t)
5183                      );
5184     }
5185 #endif
5186     else
5187     {
5188       TI_DBG1(("ossaSSPAbortCB: other status %d\n", status));
5189       /* clean up TD layer's IORequestBody */
5190       if (oneDeviceData->OSAbortAll == agTRUE)
5191       {
5192         oneDeviceData->OSAbortAll = agFALSE;
5193         ostiInitiatorEvent( tiRoot,
5194                             agNULL,
5195                             tiDeviceHandle,
5196                             tiIntrEventTypeLocalAbort,
5197                             tiAbortInProgress,
5198                             agNULL );
5199       }
5200       else
5201       {
5202         TI_DBG2(("ossaSSPAbortCB: calling saDeregisterDeviceHandle\n"));
5203         saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
5204       }
5205       TI_DBG2(("ossaSSPAbortCB: did %d\n", oneDeviceData->id));
5206       ostiFreeMemory(
5207                      tiRoot,
5208                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5209                      sizeof(tdIORequestBody_t)
5210                      );
5211     }
5212   }
5213   else if (flag == 0)
5214   {
5215     TI_DBG2(("ossaSSPAbortCB: abort one\n"));
5216     taskTag = tdAbortIORequestBody->tiIOToBeAbortedRequest;
5217 
5218     if ( taskTag == agNULL)
5219     {
5220       TI_DBG1(("ossaSSPAbortCB: taskTag is NULL; triggered by itdssQueryTaskCompleted\n"));
5221     }
5222     if (status == OSSA_IO_SUCCESS)
5223     {
5224       TI_DBG2(("ossaSSPAbortCB: OSSA_IO_SUCCESS\n"));
5225       if (taskTag != agNULL)
5226       {
5227         ostiInitiatorEvent( tiRoot,
5228                             agNULL,
5229                             agNULL,
5230                             tiIntrEventTypeLocalAbort,
5231                             tiAbortOK,
5232                             taskTag );
5233       }
5234       ostiFreeMemory(
5235                      tiRoot,
5236                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5237                      sizeof(tdIORequestBody_t)
5238                      );
5239 
5240     }
5241     else if (status == OSSA_IO_NOT_VALID)
5242     {
5243       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_NOT_VALID\n"));
5244 
5245       if (taskTag != agNULL)
5246       {
5247         ostiInitiatorEvent( tiRoot,
5248                             agNULL,
5249                             agNULL,
5250                             tiIntrEventTypeLocalAbort,
5251                             tiAbortFailed,
5252                             taskTag );
5253       }
5254       ostiFreeMemory(
5255                      tiRoot,
5256                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5257                      sizeof(tdIORequestBody_t)
5258                      );
5259     }
5260     else if (status == OSSA_IO_NO_DEVICE)
5261     {
5262       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_NO_DEVICE\n"));
5263 
5264       if (taskTag != agNULL)
5265       {
5266         ostiInitiatorEvent( tiRoot,
5267                             agNULL,
5268                             agNULL,
5269                             tiIntrEventTypeLocalAbort,
5270                             tiAbortInProgress,
5271                             taskTag );
5272       }
5273       ostiFreeMemory(
5274                      tiRoot,
5275                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5276                      sizeof(tdIORequestBody_t)
5277                      );
5278     }
5279     else if (status == OSSA_IO_ABORT_IN_PROGRESS)
5280     {
5281       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_ABORT_IN_PROGRESS\n"));
5282 
5283       if (taskTag != agNULL)
5284       {
5285         ostiInitiatorEvent( tiRoot,
5286                             agNULL,
5287                             agNULL,
5288                             tiIntrEventTypeLocalAbort,
5289                             tiAbortInProgress,
5290                             taskTag );
5291       }
5292       ostiFreeMemory(
5293                      tiRoot,
5294                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5295                      sizeof(tdIORequestBody_t)
5296                      );
5297     }
5298 #ifdef REMOVED
5299     else if (status == OSSA_IO_ABORT_DELAYED)
5300     {
5301       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_ABORT_DELAYED\n"));
5302 
5303       if (taskTag != agNULL)
5304       {
5305         ostiInitiatorEvent( tiRoot,
5306                             agNULL,
5307                             agNULL,
5308                             tiIntrEventTypeLocalAbort,
5309                             tiAbortDelayed,
5310                             taskTag );
5311       }
5312       ostiFreeMemory(
5313                      tiRoot,
5314                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5315                      sizeof(tdIORequestBody_t)
5316                      );
5317     }
5318 #endif
5319     else
5320     {
5321       TI_DBG1(("ossaSSPAbortCB: other status %d\n", status));
5322 
5323       if (taskTag != agNULL)
5324       {
5325         ostiInitiatorEvent( tiRoot,
5326                             agNULL,
5327                             agNULL,
5328                             tiIntrEventTypeLocalAbort,
5329                             tiAbortFailed,
5330                             taskTag );
5331       }
5332       ostiFreeMemory(
5333                      tiRoot,
5334                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5335                      sizeof(tdIORequestBody_t)
5336                      );
5337     }
5338   }
5339   else
5340   {
5341     TI_DBG1(("ossaSSPAbortCB: wrong flag %d\n", flag));
5342   }
5343   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Ya");
5344   return;
5345 
5346 }
5347 #endif
5348 
5349 
5350 #ifdef TARGET_DRIVER
5351 osGLOBAL void ossaSSPAbortCB(
5352                agsaRoot_t       *agRoot,
5353                agsaIORequest_t  *agIORequest,
5354                bit32            flag,
5355                bit32            status)
5356 {
5357   tdsaRootOsData_t        *osData = (tdsaRootOsData_t *)agRoot->osData;
5358   tiRoot_t                *tiRoot = (tiRoot_t *)osData->tiRoot;
5359   tdIORequestBody_t       *tdAbortIORequestBody;
5360   tdsaDeviceData_t        *oneDeviceData;
5361   tiDeviceHandle_t        *tiDeviceHandle;
5362 
5363   TI_DBG3(("ossaSSPAbortCB: start\n"));
5364   tdAbortIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
5365 
5366   if (flag == 2)
5367   {
5368     /* abort per port */
5369     TI_DBG2(("ossaSSPAbortCB: abort per port\n"));
5370   }
5371   else if (flag == 1)
5372   {
5373     TI_DBG2(("ossaSSPAbortCB: abort all\n"));
5374     tiDeviceHandle = (tiDeviceHandle_t *)tdAbortIORequestBody->tiDevHandle;
5375     oneDeviceData  = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
5376     if (status == OSSA_IO_SUCCESS)
5377     {
5378       TI_DBG2(("ossaSSPAbortCB: OSSA_IO_SUCCESS\n"));
5379       /* clean up TD layer's IORequestBody */
5380       TI_DBG3(("ossaSSPAbortCB: calling saDeregisterDeviceHandle\n"));
5381       saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
5382       TI_DBG2(("ossaSSPAbortCB: did %d\n", oneDeviceData->id));
5383       ostiFreeMemory(
5384                      tiRoot,
5385                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5386                      sizeof(tdIORequestBody_t)
5387                      );
5388 
5389     }
5390     else if (status == OSSA_IO_NOT_VALID)
5391     {
5392       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_NOT_VALID\n"));
5393       /* clean up TD layer's IORequestBody */
5394       TI_DBG2(("ossaSSPAbortCB: calling saDeregisterDeviceHandle\n"));
5395       saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
5396       TI_DBG2(("ossaSSPAbortCB: did %d\n", oneDeviceData->id));
5397       ostiFreeMemory(
5398                      tiRoot,
5399                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5400                      sizeof(tdIORequestBody_t)
5401                      );
5402     }
5403     else if (status == OSSA_IO_NO_DEVICE)
5404     {
5405       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_NO_DEVICE\n"));
5406       /* clean up TD layer's IORequestBody */
5407       TI_DBG2(("ossaSSPAbortCB: calling saDeregisterDeviceHandle\n"));
5408       saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
5409       TI_DBG2(("ossaSSPAbortCB: did %d\n", oneDeviceData->id));
5410       ostiFreeMemory(
5411                      tiRoot,
5412                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5413                      sizeof(tdIORequestBody_t)
5414                      );
5415     }
5416     else if (status == OSSA_IO_ABORT_IN_PROGRESS)
5417     {
5418       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_ABORT_IN_PROGRESS\n"));
5419       /* clean up TD layer's IORequestBody */
5420       TI_DBG2(("ossaSSPAbortCB: calling saDeregisterDeviceHandle\n"));
5421       saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
5422       TI_DBG2(("ossaSSPAbortCB: did %d\n", oneDeviceData->id));
5423       ostiFreeMemory(
5424                      tiRoot,
5425                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5426                      sizeof(tdIORequestBody_t)
5427                      );
5428     }
5429 #ifdef REMOVED
5430     else if (status == OSSA_IO_ABORT_DELAYED)
5431     {
5432       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_ABORT_DELAYED\n"));
5433       /* clean up TD layer's IORequestBody */
5434       TI_DBG2(("ossaSSPAbortCB: calling saDeregisterDeviceHandle\n"));
5435       saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
5436       TI_DBG2(("ossaSSPAbortCB: did %d\n", oneDeviceData->id));
5437       ostiFreeMemory(
5438                      tiRoot,
5439                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5440                      sizeof(tdIORequestBody_t)
5441                      );
5442     }
5443 #endif
5444     else
5445     {
5446       TI_DBG1(("ossaSSPAbortCB: other status %d\n", status));
5447       /* clean up TD layer's IORequestBody */
5448       TI_DBG2(("ossaSSPAbortCB: calling saDeregisterDeviceHandle\n"));
5449       saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
5450       TI_DBG1(("ossaSSPAbortCB: did %d\n", oneDeviceData->id));
5451       ostiFreeMemory(
5452                      tiRoot,
5453                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5454                      sizeof(tdIORequestBody_t)
5455                      );
5456     }
5457   }
5458   else if (flag == 0)
5459   {
5460     TI_DBG2(("ossaSSPAbortCB: abort one\n"));
5461     if (status == OSSA_IO_SUCCESS)
5462     {
5463       TI_DBG2(("ossaSSPAbortCB: OSSA_IO_SUCCESS\n"));
5464       ostiFreeMemory(
5465                      tiRoot,
5466                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5467                      sizeof(tdIORequestBody_t)
5468                      );
5469 
5470     }
5471     else if (status == OSSA_IO_NOT_VALID)
5472     {
5473       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_NOT_VALID\n"));
5474       ostiFreeMemory(
5475                      tiRoot,
5476                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5477                      sizeof(tdIORequestBody_t)
5478                      );
5479     }
5480     else if (status == OSSA_IO_NO_DEVICE)
5481     {
5482       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_NO_DEVICE\n"));
5483       ostiFreeMemory(
5484                      tiRoot,
5485                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5486                      sizeof(tdIORequestBody_t)
5487                      );
5488     }
5489     else if (status == OSSA_IO_ABORT_IN_PROGRESS)
5490     {
5491       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_ABORT_IN_PROGRESS\n"));
5492       ostiFreeMemory(
5493                      tiRoot,
5494                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5495                      sizeof(tdIORequestBody_t)
5496                      );
5497     }
5498 #ifdef REMOVED
5499     else if (status == OSSA_IO_ABORT_DELAYED)
5500     {
5501       TI_DBG1(("ossaSSPAbortCB: OSSA_IO_ABORT_DELAYED\n"));
5502       ostiFreeMemory(
5503                      tiRoot,
5504                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5505                      sizeof(tdIORequestBody_t)
5506                      );
5507     }
5508 #endif
5509     else
5510     {
5511       TI_DBG1(("ossaSSPAbortCB: other status %d\n", status));
5512       ostiFreeMemory(
5513                      tiRoot,
5514                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
5515                      sizeof(tdIORequestBody_t)
5516                      );
5517     }
5518   }
5519   else
5520   {
5521     TI_DBG1(("ossaSSPAbortCB: wrong flag %d\n", flag));
5522   }
5523 
5524   return;
5525 
5526 }
5527 #endif
5528 
5529 
5530 /*****************************************************************************/
5531 /*! \brief ossaLocalPhyControlCB
5532  *
5533  *
5534  *  Purpose: This routine is called by lower layer to indicate the status of
5535  *           phy operations
5536  *
5537  *  \param   agRoot:       Pointer to chip/driver Instance.
5538  *  \param   phyId         Phy id
5539  *  \param   phyOperation  Operation to be done on the phy
5540  *  \param   status        Phy operation specific completion status
5541  *  \param   parm          Additional parameter, phy operation and status specific
5542  *
5543  *
5544  *  \return None.
5545  *
5546  */
5547 /*****************************************************************************/
5548 osGLOBAL void ossaLocalPhyControlCB(
5549                       agsaRoot_t  *agRoot,
5550                       agsaContext_t *agContext,
5551                       bit32       phyId,
5552                       bit32       phyOperation,
5553                       bit32       status,
5554                       void        *parm
5555                       )
5556 {
5557 #ifdef REMVOED
5558   agsaPhyErrCounters_t    *agPhyErrCounters;
5559 #endif
5560 #ifdef INITIATOR_DRIVER
5561   tdsaRootOsData_t         *osData = (tdsaRootOsData_t *)agRoot->osData;
5562   tiRoot_t                 *tiRoot = (tiRoot_t *)osData->tiRoot;
5563   tiIORequest_t            *currentTaskTag;
5564   tdsaDeviceData_t         *TargetDeviceData;
5565   satDeviceData_t          *pSatDevData;
5566   agsaDevHandle_t          *agDevHandle = agNULL;
5567   agsaContext_t            *agContextDevice;
5568 #endif
5569 
5570   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yb");
5571   TI_DBG3(("ossaLocalPhyControlCB: start phyID %d\n", phyId));
5572   TI_DBG3(("ossaLocalPhyControlCB: phyOperation %d status 0x%x\n", phyOperation, status));
5573   switch (phyOperation)
5574   {
5575   case AGSA_PHY_LINK_RESET: /* fall through */
5576   case AGSA_PHY_HARD_RESET:
5577     if (phyOperation == AGSA_PHY_LINK_RESET)
5578     {
5579       TI_DBG1(("ossaLocalPhyControlCB: AGSA_PHY_LINK_RESET, status 0x%x\n", status));
5580     }
5581     else
5582     {
5583       TI_DBG1(("ossaLocalPhyControlCB: AGSA_PHY_HARD_RESET, status 0x%x\n", status));
5584     }
5585 #ifdef INITIATOR_DRIVER
5586     if (agContext != agNULL)
5587     {
5588       currentTaskTag = (tiIORequest_t *)agContext->osData;
5589       if (status == OSSA_SUCCESS)
5590       {
5591         if (currentTaskTag != agNULL)
5592         {
5593           TI_DBG2(("ossaLocalPhyControlCB: callback to OS layer with success\n"));
5594           TargetDeviceData = (tdsaDeviceData_t *)currentTaskTag->tdData;
5595           pSatDevData = (satDeviceData_t *)&(TargetDeviceData->satDevData);
5596           agDevHandle = TargetDeviceData->agDevHandle;
5597           TI_DBG2(("ossaLocalPhyControlCB: satPendingIO %d satNCQMaxIO %d\n", pSatDevData->satPendingIO, pSatDevData->satNCQMaxIO ));
5598           TI_DBG2(("ossaLocalPhyControlCB: satPendingNCQIO %d satPendingNONNCQIO %d\n", pSatDevData->satPendingNCQIO, pSatDevData->satPendingNONNCQIO));
5599           pSatDevData->satDriveState = SAT_DEV_STATE_NORMAL;
5600 
5601           if (TargetDeviceData->TRflag == agTRUE)
5602           {
5603             saSetDeviceState(agRoot, agNULL, tdsaRotateQnumber(tiRoot, TargetDeviceData), agDevHandle, SA_DS_OPERATIONAL);
5604             TargetDeviceData->TRflag = agFALSE;
5605             ostiInitiatorEvent(tiRoot,
5606                                TargetDeviceData->tdPortContext->tiPortalContext,
5607                                &(TargetDeviceData->tiDeviceHandle),
5608                                tiIntrEventTypeTransportRecovery,
5609                                tiRecOK,
5610                                agNULL
5611                               );
5612           }
5613           else
5614           {
5615             agDevHandle = TargetDeviceData->agDevHandle;
5616             if (agDevHandle == agNULL)
5617             {
5618               TI_DBG1(("ossaLocalPhyControlCB: wrong, agDevHandle is NULL\n"));
5619             }
5620             /* move this to OSSA_HW_EVENT_PORT_RESET_COMPLETE in ossaHwCB() */
5621             agContextDevice = &(TargetDeviceData->agDeviceResetContext);
5622             agContextDevice->osData = currentTaskTag;
5623 
5624 #ifdef REMOVED
5625             ostiInitiatorEvent( tiRoot,
5626                                 NULL,
5627                                 NULL,
5628                                 tiIntrEventTypeTaskManagement,
5629                                 tiTMOK,
5630                                 currentTaskTag );
5631 #endif
5632           }
5633         }
5634       }
5635       else
5636       {
5637         if (currentTaskTag != agNULL)
5638         {
5639           TI_DBG1(("ossaLocalPhyControlCB: callback to OS layer with failure\n"));
5640           TargetDeviceData = (tdsaDeviceData_t *)currentTaskTag->tdData;
5641           pSatDevData = (satDeviceData_t *)&(TargetDeviceData->satDevData);
5642           TI_DBG1(("ossaLocalPhyControlCB: satPendingIO %d satNCQMaxIO %d\n", pSatDevData->satPendingIO, pSatDevData->satNCQMaxIO ));
5643           TI_DBG1(("ossaLocalPhyControlCB: satPendingNCQIO %d satPendingNONNCQIO %d\n", pSatDevData->satPendingNCQIO, pSatDevData->satPendingNONNCQIO));
5644           if (TargetDeviceData->TRflag == agTRUE)
5645           {
5646             TargetDeviceData->TRflag = agFALSE;
5647             ostiInitiatorEvent(tiRoot,
5648                                TargetDeviceData->tdPortContext->tiPortalContext,
5649                                &(TargetDeviceData->tiDeviceHandle),
5650                                tiIntrEventTypeTransportRecovery,
5651                                tiRecFailed ,
5652                                agNULL
5653                               );
5654           }
5655           else
5656           {
5657             ostiInitiatorEvent( tiRoot,
5658                                 NULL,
5659                                 NULL,
5660                                 tiIntrEventTypeTaskManagement,
5661                                 tiTMFailed,
5662                                 currentTaskTag );
5663           }
5664         }
5665       }
5666     }
5667 #endif
5668     break;
5669 #ifdef REMOVED
5670   case AGSA_PHY_GET_ERROR_COUNTS:
5671 
5672     TI_DBG2(("ossaLocalPhyControlCB: AGSA_PHY_GET_ERROR_COUNTS, status 0x%x\n", status));
5673     if(parm !=agNULL )
5674     {
5675       agPhyErrCounters = (agsaPhyErrCounters_t *)parm;
5676       TI_DBG2(("ossaLocalPhyControlCB: invalidDword %d\n", agPhyErrCounters->invalidDword));
5677       TI_DBG2(("ossaLocalPhyControlCB: runningDisparityError %d\n", agPhyErrCounters->runningDisparityError));
5678       TI_DBG2(("ossaLocalPhyControlCB: lostOfDwordSynch %d\n", agPhyErrCounters->lossOfDwordSynch));
5679       TI_DBG2(("ossaLocalPhyControlCB: phyResetProblem %d\n", agPhyErrCounters->phyResetProblem));
5680       TI_DBG2(("ossaLocalPhyControlCB: elasticityBufferOverflow %d\n", agPhyErrCounters->elasticityBufferOverflow));
5681       TI_DBG2(("ossaLocalPhyControlCB: receivedErrorPrimitive %d\n", agPhyErrCounters->receivedErrorPrimitive));
5682     }
5683     break;
5684   case AGSA_PHY_CLEAR_ERROR_COUNTS:
5685     TI_DBG2(("ossaLocalPhyControlCB: AGSA_PHY_CLEAR_ERROR_COUNTS, status 0x%x\n", status));
5686     break;
5687 #endif
5688   case AGSA_PHY_NOTIFY_ENABLE_SPINUP:
5689     TI_DBG2(("ossaLocalPhyControlCB: AGSA_PHY_NOTIFY_ENABLE_SPINUP, status 0x%x\n", status));
5690     break;
5691   case AGSA_PHY_BROADCAST_ASYNCH_EVENT:
5692     TI_DBG2(("ossaLocalPhyControlCB: AGSA_PHY_BROADCAST_ASYNCH_EVENT, status 0x%x\n", status));
5693     if (tIsSPC12SATA(agRoot))
5694     {
5695       TI_DBG1(("ossaLocalPhyControlCB: BROADCAST_ASYNCH_EVENT received for SATA Controller\n"));
5696       break;
5697     }
5698     break;
5699   case AGSA_PHY_COMINIT_OOB :
5700     TI_DBG2(("ossaLocalPhyControlCB: AGSA_PHY_COMINIT_OOB, status 0x%x\n", status));
5701     break;
5702   default:
5703     TI_DBG1(("ossaLocalPhyControlCB: UNKNOWN default case. phyOperation %d status 0x%x\n", phyOperation, status));
5704     break;
5705   }
5706   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yb");
5707   return;
5708 }
5709 
5710 GLOBAL void   ossaGetPhyProfileCB(
5711                       agsaRoot_t    *agRoot,
5712                       agsaContext_t *agContext,
5713                       bit32         status,
5714                       bit32         ppc,
5715                       bit32         phyID,
5716                       void          *parm )
5717 {
5718 
5719   tdsaRootOsData_t  *osData        = (tdsaRootOsData_t *)agRoot->osData;
5720   tiRoot_t          *tiRoot        = (tiRoot_t *)osData->tiRoot;
5721   tdsaRoot_t        *tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
5722   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
5723 #ifdef CCFLAGS_PHYCONTROL_COUNTS
5724   agsaPhyAnalogSettingsPage_t *analog;
5725 #endif /* CCFLAGS_PHYCONTROL_COUNTS   */
5726   tdPhyCount_t      *PhyBlob = agNULL;
5727 
5728   agsaPhyBWCountersPage_t       *agBWCounters;
5729   agsaPhyErrCountersPage_t      *agPhyErrCounters;
5730   TI_DBG1(("ossaGetPhyProfileCB: agContext %p parm %p\n", agContext, parm));
5731 /*
5732   if(  tdsaAllShared->tdFWControlEx.inProgress )
5733   {
5734     tdsaAllShared->tdFWControlEx.inProgress = 0;
5735     PhyBlob = (tdPhyCount_t  *)tdsaAllShared->tdFWControlEx.usrAddr;
5736   }
5737 */
5738   switch(ppc)
5739   {
5740     case  AGSA_SAS_PHY_BW_COUNTERS_PAGE:
5741       TI_DBG1(("ossaGetPhyProfileCB: AGSA_SAS_PHY_BW_COUNTERS_PAGE, status 0x%x phyID %d\n", status, phyID));
5742       if(parm !=agNULL )
5743       {
5744         agBWCounters = (agsaPhyBWCountersPage_t *)parm;
5745         TI_DBG1(("ossaGetPhyProfileCB: RX %d TX %d\n", agBWCounters->RXBWCounter,agBWCounters->TXBWCounter));
5746         if(PhyBlob !=agNULL )
5747         {
5748           PhyBlob->InvalidDword = 0;
5749           PhyBlob->runningDisparityError = 0;
5750           PhyBlob->codeViolation = 0;
5751           PhyBlob->phyResetProblem = 0;
5752           PhyBlob->inboundCRCError = 0;
5753           PhyBlob->BW_rx = agBWCounters->RXBWCounter;
5754           PhyBlob->BW_tx = agBWCounters->TXBWCounter;
5755         }
5756 
5757       }
5758       break;
5759     case AGSA_SAS_PHY_ERR_COUNTERS_PAGE:
5760       if(  tdsaAllShared->tdFWControlEx.inProgress )
5761       {
5762   	  tdsaAllShared->tdFWControlEx.inProgress = 0;
5763   	  PhyBlob = (tdPhyCount_t  *)tdsaAllShared->tdFWControlEx.usrAddr;
5764       }
5765       TI_DBG1(("ossaGetPhyProfileCB: AGSA_SAS_PHY_ERR_COUNTERS_PAGE, status 0x%x phyID %d\n", status, phyID));
5766       if(parm !=agNULL )
5767       {
5768         agPhyErrCounters = (agsaPhyErrCountersPage_t *)parm;
5769         if(PhyBlob !=agNULL )
5770         {
5771 
5772           PhyBlob->InvalidDword          = agPhyErrCounters->invalidDword;
5773           PhyBlob->runningDisparityError = agPhyErrCounters->runningDisparityError;
5774           PhyBlob->LossOfSyncDW          = agPhyErrCounters->lossOfDwordSynch;
5775           PhyBlob->codeViolation         = agPhyErrCounters->codeViolation;
5776           PhyBlob->phyResetProblem       = agPhyErrCounters->phyResetProblem;
5777           PhyBlob->inboundCRCError       = agPhyErrCounters->inboundCRCError;
5778           PhyBlob->BW_rx = 0;
5779           PhyBlob->BW_tx = 0;
5780 
5781           TI_DBG2(("ossaGetPhyProfileCB: invalidDword          %d\n", agPhyErrCounters->invalidDword));
5782           TI_DBG2(("ossaGetPhyProfileCB: runningDisparityError %d\n", agPhyErrCounters->runningDisparityError));
5783           TI_DBG2(("ossaGetPhyProfileCB: lostOfDwordSynch      %d\n", agPhyErrCounters->lossOfDwordSynch));
5784           TI_DBG2(("ossaGetPhyProfileCB: phyResetProblem       %d\n", agPhyErrCounters->phyResetProblem));
5785           TI_DBG2(("ossaGetPhyProfileCB: inboundCRCError       %d\n", agPhyErrCounters->inboundCRCError));
5786         }
5787       }
5788       break;
5789     case AGSA_SAS_PHY_ERR_COUNTERS_CLR_PAGE:
5790       TI_DBG1(("ossaGetPhyProfileCB: AGSA_SAS_PHY_ERR_COUNTERS_CLR_PAGE status 0x%x phyID %d\n", status, phyID));
5791       break;
5792     case AGSA_SAS_PHY_ANALOG_SETTINGS_PAGE:
5793       TI_DBG1(("ossaGetPhyProfileCB:AGSA_SAS_PHY_ANALOG_SETTINGS_PAGE status 0x%x phyID %d\n", status, phyID));
5794 #ifdef CCFLAGS_PHYCONTROL_COUNTS
5795       if(parm !=agNULL )
5796       {
5797         analog = (agsaPhyAnalogSettingsPage_t *)parm;
5798         TI_DBG1(("ossaGetPhyProfileCB: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
5799           analog->Dword0, analog->Dword1, analog->Dword2, analog->Dword3, analog->Dword4,
5800           analog->Dword5, analog->Dword6, analog->Dword7, analog->Dword8, analog->Dword9));
5801         tdsaAllShared->analog[phyID].spaRegister0 = analog->Dword0;
5802         tdsaAllShared->analog[phyID].spaRegister1 = analog->Dword1;
5803         tdsaAllShared->analog[phyID].spaRegister2 = analog->Dword2;
5804         tdsaAllShared->analog[phyID].spaRegister3 = analog->Dword3;
5805         tdsaAllShared->analog[phyID].spaRegister4 = analog->Dword4;
5806         saSetPhyProfile( agRoot,agContext,tdsaRotateQnumber(tiRoot, agNULL), AGSA_SAS_PHY_ANALOG_SETTINGS_PAGE,sizeof(agsaPhyAnalogSetupRegisters_t),&tdsaAllShared->analog[phyID],phyID);
5807       }
5808 #endif /* CCFLAGS_PHYCONTROL_COUNTS   */
5809      break;
5810     case AGSA_SAS_PHY_OPEN_REJECT_RETRY_BACKOFF_THRESHOLD_PAGE:
5811     {
5812       TI_DBG1(("ossaGetPhyProfileCB:AGSA_SAS_PHY_OPEN_REJECT_RETRY_BACKOFF_THRESHOLD_PAGE status 0x%x phyID %d\n", status, phyID));
5813       if( parm !=agNULL )
5814       {
5815 #ifdef TD_DEBUG_ENABLE
5816         agsaSASPhyOpenRejectRetryBackOffThresholdPage_t *Backoff =
5817           (agsaSASPhyOpenRejectRetryBackOffThresholdPage_t *)parm;
5818 #endif
5819         TI_DBG2(("ossaGetPhyProfileCB: DW0 0x%X DW1 0x%X DW2 0x%X DW3 0x%X\n",
5820                  Backoff->Dword0,Backoff->Dword1,
5821                  Backoff->Dword2,Backoff->Dword3));
5822        }
5823       break;
5824     }
5825 
5826     case AGSA_SAS_PHY_GENERAL_STATUS_PAGE:
5827     {
5828       agsaSASPhyGeneralStatusPage_t * GenStatus = NULL;
5829 
5830       TI_DBG1(("ossaGetPhyProfileCB: AGSA_SAS_PHY_GENERAL_STATUS_PAGE status 0x%x phyID %d\n",
5831                status, phyID));
5832       if( parm !=agNULL )
5833       {
5834           GenStatus=
5835           (agsaSASPhyGeneralStatusPage_t *)parm;
5836         TI_DBG2(("ossaGetPhyProfileCB: "
5837                  "AGSA_SAS_PHY_GENERAL_STATUS_PAGE status %d DW0 0x%x DW1 0x%x\n",
5838                  status, GenStatus->Dword0, GenStatus->Dword1));
5839       }
5840       ostiGetPhyGeneralStatusRsp(tiRoot, GenStatus, phyID);
5841 //      break;
5842       return ;
5843     }
5844 
5845     default:
5846       TI_DBG1(("ossaGetPhyProfileCB: UNKNOWN default case. phyOperation %d status 0x%x\n", ppc, status));
5847       break;
5848 
5849   }
5850 
5851   ostiGetPhyProfileIOCTLRsp(tiRoot, status);
5852 
5853 }
5854 
5855 
5856 GLOBAL void ossaSetPhyProfileCB(
5857                      agsaRoot_t    *agRoot,
5858                      agsaContext_t *agContext,
5859                      bit32         status,
5860                      bit32         ppc,
5861                      bit32         phyID,
5862                      void          *parm )
5863 {
5864   TI_DBG1(("ossaSetPhyProfileCB:agContext %p status 0x%x ppc %d phyID %d parm %p\n",agContext, status, ppc, phyID,parm));
5865 }
5866 
5867 
5868 /*****************************************************************************/
5869 /*! \brief ossaGetDeviceHandlesCB
5870  *
5871  *
5872  *  Purpose: This routine is called by lower layer to corresponding to
5873  *           saGetDeviceHandles()
5874  *
5875  *  \param   agRoot:       Pointer to chip/driver Instance.
5876  *  \param   agContext:    Context of the get device handle request originally passed into
5877  *                         saGetDeviceHandles().
5878  *  \param   agPortContext:Pointer to this instance of a port context
5879  *  \param   agDev:        Array containing pointers to the device handles
5880 
5881  *  \param   validDevs     Number of valid device handles
5882  *
5883  *
5884  *  \return None.
5885  *
5886  *  \note - The scope is shared target and initiator.
5887  *          For details, refer to SAS/SATA Low-Level API Specification
5888  */
5889 /*****************************************************************************/
5890 osGLOBAL void ossaGetDeviceHandlesCB(
5891                        agsaRoot_t           *agRoot,
5892                        agsaContext_t        *agContext,
5893                        agsaPortContext_t    *agPortContext,
5894                        agsaDevHandle_t      *agDev[],
5895                        bit32                validDevs
5896                        )
5897 {
5898   TI_DBG2(("ossaGetDeviceHandlesCB: start\n"));
5899   TI_DBG2(("ossaGetDeviceHandlesCB: validDevs %d\n", validDevs));
5900   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yc");
5901 #ifdef TO_DO
5902   for (i = 0 ; i < validDevs ; i++)
5903   {
5904     agDev[i];
5905   }
5906 #endif
5907   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yc");
5908   return;
5909 }
5910 
5911 /*****************************************************************************/
5912 /*! \brief ossaGetDeviceInfoCB
5913  *
5914  *
5915  *  Purpose: This routine is called by lower layer to corresponding to
5916  *           saGetDeviceInfo()
5917  *
5918  *  \param   agRoot:       Pointer to chip/driver Instance.
5919  *  \param   agDevHandle:  Handle of the device
5920  *  \param   status:       status
5921  *  \param   agInfo:       Pointer to the structure that describes device information
5922  *
5923  *
5924  *  \return None.
5925  *
5926  *  \note - The scope is shared target and initiator.
5927  *          For details, refer to SAS/SATA Low-Level API Specification
5928  */
5929 /*****************************************************************************/
5930 osGLOBAL void ossaGetDeviceInfoCB(
5931                     agsaRoot_t        *agRoot,
5932                     agsaContext_t     *agContext,
5933                     agsaDevHandle_t   *agDevHandle,
5934                     bit32             status,
5935                     void              *agInfo
5936                     )
5937 {
5938 
5939 #ifdef TD_DEBUG_ENABLE
5940   agsaDeviceInfo_t       *agDeviceInfo;
5941   agsaSASDeviceInfo_t    *agSASDeviceInfo;
5942   agsaSATADeviceInfo_t   *agSATADeviceInfo;
5943 #endif
5944   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yd");
5945 
5946   TI_DBG1(("ossaGetDeviceInfoCB: start agContext %p\n",agContext));
5947   switch (status)
5948   {
5949   case OSSA_DEV_INFO_INVALID_HANDLE:
5950     TI_DBG1(("ossaGetDeviceInfoCB: OSSA_DEV_INFO_INVALID_HANDLE\n"));
5951     /*ostiGetDeviceInfoIOCTLRsp(tiRoot, status, agNULL);*/
5952     break;
5953   case OSSA_DEV_INFO_NO_EXTENDED_INFO:
5954 #ifdef TD_DEBUG_ENABLE
5955     agDeviceInfo = (agsaDeviceInfo_t *)agInfo;
5956 #endif
5957     TI_DBG1(("ossaGetDeviceInfoCB: OSSA_DEV_INFO_NO_EXTENDED_INFO\n"));
5958     TI_DBG1(("ossaGetDeviceInfoCB: sasAddressHi 0x%08x\n", SA_DEVINFO_GET_SAS_ADDRESSHI(agDeviceInfo)));
5959     TI_DBG1(("ossaGetDeviceInfoCB: sasAddressLo 0x%08x\n", SA_DEVINFO_GET_SAS_ADDRESSLO(agDeviceInfo)));
5960     TI_DBG1(("ossaGetDeviceInfoCB: devType_S_Rate 0x%08x\n", agDeviceInfo->devType_S_Rate));
5961     TI_DBG1(("ossaGetDeviceInfoCB: firstBurstSize 0x%08x\n", agDeviceInfo->firstBurstSize));
5962 
5963     /*ostiPortEvent (tiRoot, tiGetDevInfo, tiSuccess,(void *)agContext );*/
5964     /*ostiGetDeviceInfoIOCTLRsp(tiRoot, status, agDeviceInfo);*/
5965     break;
5966   case OSSA_DEV_INFO_SAS_EXTENDED_INFO:
5967 #ifdef TD_DEBUG_ENABLE
5968     agSASDeviceInfo = (agsaSASDeviceInfo_t *)agInfo;
5969 #endif
5970     TI_DBG2(("ossaGetDeviceInfoCB: OSSA_DEV_INFO_SAS_EXTENDED_INFO\n"));
5971     TI_DBG2(("ossaGetDeviceInfoCB: sasAddressHi 0x%08x\n", SA_DEVINFO_GET_SAS_ADDRESSHI(&agSASDeviceInfo->commonDevInfo)));
5972     TI_DBG2(("ossaGetDeviceInfoCB: sasAddressLo 0x%08x\n", SA_DEVINFO_GET_SAS_ADDRESSLO(&agSASDeviceInfo->commonDevInfo)));
5973     TI_DBG2(("ossaGetDeviceInfoCB: initiator_ssp_stp_smp %d\n", agSASDeviceInfo->initiator_ssp_stp_smp));
5974     TI_DBG2(("ossaGetDeviceInfoCB: target_ssp_stp_smp %d\n", agSASDeviceInfo->target_ssp_stp_smp));
5975     TI_DBG2(("ossaGetDeviceInfoCB: numOfPhys %d\n", agSASDeviceInfo->numOfPhys));
5976     TI_DBG2(("ossaGetDeviceInfoCB: phyIdentifier %d\n", agSASDeviceInfo->phyIdentifier));
5977 
5978     break;
5979   case OSSA_DEV_INFO_SATA_EXTENDED_INFO:
5980 #ifdef TD_DEBUG_ENABLE
5981     agSATADeviceInfo = (agsaSATADeviceInfo_t *)agInfo;
5982 #endif
5983     TI_DBG2(("ossaGetDeviceInfoCB: OSSA_DEV_INFO_SATA_EXTENDED_INFO\n"));
5984     TI_DBG2(("ossaGetDeviceInfoCB: sasAddressHi 0x%08x\n", SA_DEVINFO_GET_SAS_ADDRESSHI(&agSATADeviceInfo->commonDevInfo)));
5985     TI_DBG2(("ossaGetDeviceInfoCB: sasAddressLo 0x%08x\n", SA_DEVINFO_GET_SAS_ADDRESSLO(&agSATADeviceInfo->commonDevInfo)));
5986     TI_DBG2(("ossaGetDeviceInfoCB: connection %d\n", agSATADeviceInfo->connection));
5987     TI_DBG2(("ossaGetDeviceInfoCB: portMultiplierField %d\n", agSATADeviceInfo->portMultiplierField));
5988     TI_DBG2(("ossaGetDeviceInfoCB: stpPhyIdentifier %d\n", agSATADeviceInfo->stpPhyIdentifier));
5989 #ifdef TD_DEBUG_ENABLE
5990     tdhexdump("ossaGetDeviceInfoCB: signature", (bit8 *)agSATADeviceInfo->signature, 8);
5991 #endif
5992      break;
5993   default:
5994     TI_DBG2(("ossaGetDeviceInfoCB: error default case, status is %d\n", status));
5995     break;
5996   }
5997   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yd");
5998   return;
5999 }
6000 
6001 /*****************************************************************************/
6002 /*! \brief ossaDeviceRegistrationCB
6003  *
6004  *
6005  *  Purpose: This routine is called by lower layer to corresponding to
6006  *           saRegisterNewDevice()
6007  *
6008  *  \param   agRoot:       Pointer to chip/driver Instance.
6009  *  \param   agContext:    Context of the get device handle request originally
6010  *                         passed into saRegisterNewDevice().
6011  *  \param   status:       status
6012  *  \param   agDevHandle:  Pointer to the assigned device handle for the
6013  *                         registered device.
6014  *
6015  *
6016  *  \return None.
6017  *
6018  */
6019 /*****************************************************************************/
6020 osGLOBAL void ossaDeviceRegistrationCB(
6021                          agsaRoot_t        *agRoot,
6022                          agsaContext_t     *agContext,
6023                          bit32             status,
6024                          agsaDevHandle_t   *agDevHandle,
6025                          bit32             deviceID
6026                          )
6027 {
6028 #ifdef INITIATOR_DRIVER
6029   tdsaRootOsData_t     *osData = (tdsaRootOsData_t *)agRoot->osData;
6030   tiRoot_t             *tiRoot = (tiRoot_t *)osData->tiRoot;
6031   tdsaRoot_t           *tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
6032   tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
6033   bit32                Indenom = tdsaAllShared->QueueConfig.numInboundQueues;
6034   bit32                Outdenom = tdsaAllShared->QueueConfig.numOutboundQueues;
6035   tdsaDeviceData_t     *oneDeviceData = (tdsaDeviceData_t *)agContext->osData;
6036   tdsaPortContext_t    *onePortContext = oneDeviceData->tdPortContext;
6037   tiPortalContext_t    *tiPortalContext = onePortContext->tiPortalContext;
6038 #ifdef FDS_DM
6039   dmRoot_t             *dmRoot = &(tdsaAllShared->dmRoot);
6040   dmPortContext_t      *dmPortContext = &(onePortContext->dmPortContext);
6041   dmDeviceInfo_t       dmDeviceInfo;
6042   bit32                DMstatus = DM_RC_FAILURE;
6043   bit16                ext = 0;
6044   bit32                expanderType = 1;
6045 #endif
6046 
6047 #if defined(FDS_DM) && !defined(FDS_SM)
6048   bit32                IDstatus;
6049 #endif
6050 
6051 #ifdef FDS_SM
6052   smRoot_t             *smRoot = &(tdsaAllShared->smRoot);
6053   bit32                SMstatus = SM_RC_FAILURE;
6054 #endif
6055   smTraceFuncEnter(hpDBG_VERY_LOUD,"Ye");
6056   TI_DBG3(("ossaDeviceRegistrationCB: start status 0x%x\n",status));
6057   TI_DBG3(("ossaDeviceRegistrationCB: device AddrHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
6058   TI_DBG3(("ossaDeviceRegistrationCB: device AddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
6059   TI_DBG3(("ossaDeviceRegistrationCB: did 0x%x\n", oneDeviceData->id));
6060   TI_DBG3(("ossaDeviceRegistrationCB: deviceID 0x%x\n", deviceID));
6061   TI_DBG3(("ossaDeviceRegistrationCB: agDevHandle %p %p %p\n",agDevHandle,agDevHandle->osData,agDevHandle->sdkData ));
6062 
6063   /* transient period caused by tdssReportRemovals(), device was in the middle
6064     of registration but port is invalidated
6065   */
6066   if (oneDeviceData->valid == agFALSE && oneDeviceData->valid2 == agFALSE
6067       && oneDeviceData->DeviceType == TD_DEFAULT_DEVICE)
6068   {
6069     if (status == OSSA_SUCCESS)
6070     {
6071       TI_DBG2(("ossaDeviceRegistrationCB: transient, calling saDeregisterDeviceHandle, did %d\n", oneDeviceData->id));
6072       oneDeviceData->agDevHandle = agDevHandle;
6073       agDevHandle->osData = oneDeviceData;
6074       if (DEVICE_IS_SATA_DEVICE(oneDeviceData) || DEVICE_IS_STP_TARGET(oneDeviceData))
6075       {
6076         if (oneDeviceData->satDevData.IDDeviceValid == agFALSE)
6077         {
6078           saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, 0);
6079         }
6080         else
6081         {
6082           saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
6083         }
6084       }
6085       else
6086       {
6087         saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
6088       }
6089     }
6090     else if (status == OSSA_FAILURE_PORT_NOT_VALID_STATE || status == OSSA_ERR_PORT_STATE_NOT_VALID)
6091     {
6092       /* do nothing */
6093       TI_DBG2(("ossaDeviceRegistrationCB: transient, do nothing did %d\n", oneDeviceData->id));
6094     }
6095     return;
6096   }
6097 
6098   if (agDevHandle == agNULL)
6099   {
6100     TI_DBG3(("ossaDeviceRegistrationCB: agDevHandle is NULL\n"));
6101   }
6102   else
6103   {
6104     TI_DBG3(("ossaDeviceRegistrationCB: agDevHandle is NOT NULL\n"));
6105   }
6106 
6107   switch (status)
6108   {
6109   case OSSA_SUCCESS:
6110     TI_DBG3(("ossaDeviceRegistrationCB: success\n"));
6111     TI_DBG2(("ossaDeviceRegistrationCB: Success did %d FW did 0x%x\n", oneDeviceData->id, deviceID));
6112     TI_DBG2(("ossaDeviceRegistrationCB: Success pid %d\n", onePortContext->id));
6113     if (agDevHandle == agNULL)
6114     {
6115       TI_DBG1(("ossaDeviceRegistrationCB: agDevHandle is NULL, wrong!\n"));
6116       return;
6117     }
6118     oneDeviceData->agDevHandle = agDevHandle;
6119     agDevHandle->osData = oneDeviceData;
6120     oneDeviceData->registered = agTRUE;
6121     oneDeviceData->InQID = oneDeviceData->id % Indenom;
6122     oneDeviceData->OutQID = oneDeviceData->id % Outdenom;
6123     onePortContext->RegisteredDevNums++;
6124 
6125     TI_DBG3(("ossaDeviceRegistrationCB: direct %d STP target %d target_ssp_stp_smp %d\n", oneDeviceData->directlyAttached, DEVICE_IS_STP_TARGET(oneDeviceData), oneDeviceData->target_ssp_stp_smp));
6126     TI_DBG3(("ossaDeviceRegistrationCB: pid %d registeredNumDevice %d\n", onePortContext->id, onePortContext->RegisteredDevNums));
6127     TI_DBG3(("ossaDeviceRegistrationCB: pid %d Count %d\n", onePortContext->id, onePortContext->Count));
6128 
6129 #ifdef FDS_DM
6130     /* if device is an expander, register it to DM */
6131     if (onePortContext->valid == agTRUE)
6132     {
6133       if (DEVICE_IS_SMP_TARGET(oneDeviceData))
6134       {
6135         TI_DBG1(("ossaDeviceRegistrationCB: calling dmRegisterDevice\n"));
6136         TI_DBG1(("ossaDeviceRegistrationCB: device AddrHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
6137         TI_DBG1(("ossaDeviceRegistrationCB: device AddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
6138         /* set up dmDeviceInfo */
6139         osti_memset(&dmDeviceInfo, 0, sizeof(dmDeviceInfo_t));
6140         DEVINFO_PUT_SAS_ADDRESSLO(&dmDeviceInfo, oneDeviceData->SASAddressID.sasAddressLo);
6141         DEVINFO_PUT_SAS_ADDRESSHI(&dmDeviceInfo, oneDeviceData->SASAddressID.sasAddressHi);
6142         dmDeviceInfo.initiator_ssp_stp_smp = oneDeviceData->initiator_ssp_stp_smp;
6143         dmDeviceInfo.target_ssp_stp_smp = oneDeviceData->target_ssp_stp_smp;
6144         dmDeviceInfo.devType_S_Rate = oneDeviceData->agDeviceInfo.devType_S_Rate;
6145         if (oneDeviceData->directlyAttached == agTRUE)
6146         {
6147           /* setting SMP bit */
6148           ext = (bit16)(ext | 0x100);
6149           expanderType = SA_IDFRM_GET_DEVICETTYPE(&onePortContext->sasIDframe);
6150           ext = (bit16)( ext | (expanderType << 9));
6151           /* setting MCN field to 0xF */
6152           ext = (bit16)(ext | (bit16)(0xF << 11));
6153           TI_DBG1(("ossaDeviceRegistrationCB: directlyAttached ext 0x%x\n", ext));
6154           dmDeviceInfo.ext = ext;
6155         }
6156         DMstatus = dmRegisterDevice(dmRoot, dmPortContext, &dmDeviceInfo, oneDeviceData->agDevHandle);
6157         if (DMstatus != DM_RC_SUCCESS)
6158         {
6159           TI_DBG1(("ossaDeviceRegistrationCB: dmRegisterDevice failed!!! 0x%x\n", DMstatus));
6160         }
6161       }
6162     }
6163 #endif /* FDS_DM */
6164 #ifdef FDS_SM
6165     /* if device is SATA, register it to SM */
6166     if (onePortContext->valid == agTRUE)
6167     {
6168       if (DEVICE_IS_SATA_DEVICE(oneDeviceData) || DEVICE_IS_STP_TARGET(oneDeviceData))
6169       {
6170         TI_DBG1(("ossaDeviceRegistrationCB: calling smRegisterDevice\n"));
6171         if (oneDeviceData->directlyAttached == agTRUE)
6172         {
6173           SMstatus = smRegisterDevice(smRoot,
6174                                       agDevHandle,
6175                                       &(oneDeviceData->smDeviceHandle),
6176                                       agNULL,
6177                                       (bit32)oneDeviceData->phyID,
6178                                       oneDeviceData->satDevData.satDeviceType);
6179         }
6180         else
6181         {
6182           if (oneDeviceData->ExpDevice == agNULL)
6183           {
6184             TI_DBG1(("ossaDeviceRegistrationCB: oneDeviceData->ExpDevice NULL!!!\n"));
6185             return;
6186           }
6187           if (oneDeviceData->ExpDevice->agDevHandle == agNULL)
6188           {
6189             TI_DBG1(("ossaDeviceRegistrationCB: oneDeviceData->ExpDevice->agDevHandle NULL!!!\n"));
6190           }
6191           SMstatus = smRegisterDevice(smRoot,
6192                                       agDevHandle,
6193                                       &(oneDeviceData->smDeviceHandle),
6194                                       oneDeviceData->ExpDevice->agDevHandle,
6195                                       (bit32)oneDeviceData->phyID,
6196                                       oneDeviceData->satDevData.satDeviceType);
6197         }
6198         if (SMstatus != SM_RC_SUCCESS)
6199         {
6200           TI_DBG1(("ossaDeviceRegistrationCB: smRegisterDevice failed!!! 0x%x\n", DMstatus));
6201         }
6202       }
6203     }
6204 #endif /* FDS_SM */
6205     /* special case for directly attached targets */
6206     if (oneDeviceData->directlyAttached == agTRUE)
6207     {
6208       TI_DBG3(("ossaDeviceRegistrationCB: directly attached did %d\n", oneDeviceData->id));
6209       if (oneDeviceData->DeviceType == TD_SAS_DEVICE)
6210       {
6211         TI_DBG3(("ossaDeviceRegistrationCB: SAS target\n"));
6212         if (onePortContext->valid == agTRUE)
6213         {
6214           if (onePortContext->PortRecoverPhyID != 0xFF)
6215           {
6216             oneDeviceData->phyID = (bit8)onePortContext->PortRecoverPhyID;
6217             onePortContext->PortRecoverPhyID = 0xFF;
6218             TI_DBG3(("ossaDeviceRegistrationCB: PortRecoverPhyID %d\n", oneDeviceData->phyID));
6219           }
6220           /* link up and discovery ready event */
6221           if (onePortContext->DiscoveryRdyGiven == agFALSE)
6222           {
6223             TI_DBG2(("ossaDeviceRegistrationCB: link up and discovery ready\n"));
6224             TI_DBG3(("ossaDeviceRegistrationCB: phyID %d pid %d\n", oneDeviceData->phyID, onePortContext->id));
6225             TI_DBG3(("ossaDeviceRegistrationCB: tiPortalContext %p\n", tdsaAllShared->Ports[oneDeviceData->phyID].tiPortalContext));
6226             TI_DBG3(("ossaDeviceRegistrationCB: onePortContext->tiPortalContext %p\n", onePortContext->tiPortalContext));
6227             onePortContext->DiscoveryRdyGiven = agTRUE;
6228             if (onePortContext->DiscoveryState != ITD_DSTATE_NOT_STARTED)
6229             {
6230               TI_DBG1(("ossaDeviceRegistrationCB: wrong discovery state 0x%x\n", onePortContext->DiscoveryState));
6231             }
6232             /* notifying link up */
6233             ostiPortEvent (
6234                            tiRoot,
6235                            tiPortLinkUp,
6236                            tiSuccess,
6237                            (void *)onePortContext->tiPortalContext
6238                            );
6239 #ifdef INITIATOR_DRIVER
6240             /* triggers discovery */
6241             ostiPortEvent(
6242                           tiRoot,
6243                           tiPortDiscoveryReady,
6244                           tiSuccess,
6245                           (void *)onePortContext->tiPortalContext
6246                           );
6247 #endif
6248           }
6249         }
6250         else
6251         {
6252           TI_DBG2(("ossaDeviceRegistrationCB: abort call\n"));
6253           /* abort all followed by deregistration of sas target */
6254           tdsaAbortAll(tiRoot, agRoot, oneDeviceData);
6255         }
6256       }
6257       else
6258       {
6259         TI_DBG2(("ossaDeviceRegistrationCB: SATA target\n"));
6260         if (onePortContext->valid == agTRUE)
6261         {
6262           if (oneDeviceData->satDevData.IDDeviceValid == agFALSE)
6263           {
6264 #ifdef FDS_SM
6265             /* send identify device data */
6266             tdIDStart(tiRoot, agRoot, smRoot, oneDeviceData, onePortContext);
6267 
6268 #else
6269             /* send identify device data */
6270             tdssSubAddSATAToSharedcontext(tiRoot, oneDeviceData);
6271 #endif
6272           }
6273         }
6274         else
6275         {
6276           TI_DBG2(("ossaDeviceRegistrationCB: abort call\n"));
6277           /* abort all followed by deregistration of sas target */
6278           tdsaAbortAll(tiRoot, agRoot, oneDeviceData);
6279         }
6280       }
6281     }
6282     else /* behind the expander */
6283     {
6284 #if defined(FDS_DM) && defined(FDS_SM)
6285       /* send ID to SATA targets
6286          needs go allocate tdIORequestBody_t for smIORequest
6287       */
6288 
6289       if ( (DEVICE_IS_SATA_DEVICE(oneDeviceData) || DEVICE_IS_STP_TARGET(oneDeviceData))
6290           &&
6291           oneDeviceData->satDevData.IDDeviceValid == agFALSE)
6292       {
6293         tdIDStart(tiRoot, agRoot, smRoot, oneDeviceData, onePortContext);
6294       }
6295 
6296 #elif defined(FDS_DM) /* worked with DM */
6297       if ( (DEVICE_IS_SATA_DEVICE(oneDeviceData) || DEVICE_IS_STP_TARGET(oneDeviceData))
6298           &&
6299           oneDeviceData->satDevData.IDDeviceValid == agFALSE)
6300       {
6301          IDstatus = tdsaDiscoveryStartIDDev(tiRoot,
6302                                          agNULL,
6303                                          &(oneDeviceData->tiDeviceHandle),
6304                                          agNULL,
6305                                          oneDeviceData);
6306 
6307         if (IDstatus != tiSuccess)
6308         {
6309           /* identify device data is not valid */
6310           TI_DBG1(("ossaDeviceRegistrationCB: fail or busy %d\n", IDstatus));
6311           oneDeviceData->satDevData.IDDeviceValid = agFALSE;
6312         }
6313       }
6314 #endif
6315 
6316 
6317    }
6318     /* after discovery is finished */
6319     if (onePortContext->DiscoveryState == ITD_DSTATE_COMPLETED)
6320     {
6321       TI_DBG2(("ossaDeviceRegistrationCB: calling new device arrival\n"));
6322       if (DEVICE_IS_SSP_TARGET(oneDeviceData))
6323       {
6324         /* in case registration is finished after discovery is finished */
6325 #ifdef AGTIAPI_CTL
6326         if (tdsaAllShared->SASConnectTimeLimit)
6327           tdsaCTLSet(tiRoot, onePortContext, tiIntrEventTypeDeviceChange,
6328                      tiDeviceArrival);
6329         else
6330 #endif
6331           ostiInitiatorEvent(
6332                              tiRoot,
6333                              tiPortalContext,
6334                              agNULL,
6335                              tiIntrEventTypeDeviceChange,
6336                              tiDeviceArrival,
6337                              agNULL
6338                              );
6339       }
6340       else if ( (DEVICE_IS_SATA_DEVICE(oneDeviceData) || DEVICE_IS_STP_TARGET(oneDeviceData))
6341                 &&
6342                 oneDeviceData->satDevData.IDDeviceValid == agTRUE )
6343       {
6344         /* in case registration is finished after discovery is finished */
6345         ostiInitiatorEvent(
6346                            tiRoot,
6347                            tiPortalContext,
6348                            agNULL,
6349                            tiIntrEventTypeDeviceChange,
6350                            tiDeviceArrival,
6351                            agNULL
6352                            );
6353       }
6354     }
6355     break;
6356   case OSSA_FAILURE_OUT_OF_RESOURCE: /* fall through */
6357   case OSSA_ERR_DEVICE_HANDLE_UNAVAILABLE:
6358     TI_DBG1(("ossaDeviceRegistrationCB: OSSA_FAILURE_OUT_OF_RESOURCE or OSSA_ERR_DEVICE_HANDLE_UNAVAILABLE\n"));
6359     oneDeviceData->registered = agFALSE;
6360     break;
6361   case OSSA_FAILURE_DEVICE_ALREADY_REGISTERED: /* fall through */
6362   case OSSA_ERR_DEVICE_ALREADY_REGISTERED:
6363     /* do nothing */
6364     TI_DBG1(("ossaDeviceRegistrationCB: OSSA_FAILURE_DEVICE_ALREADY_REGISTERED or OSSA_ERR_DEVICE_ALREADY_REGISTERED\n"));
6365     break;
6366   case OSSA_FAILURE_INVALID_PHY_ID: /* fall through */
6367   case OSSA_ERR_PHY_ID_INVALID:
6368     TI_DBG1(("ossaDeviceRegistrationCB: OSSA_FAILURE_INVALID_PHY_ID or OSSA_ERR_PHY_ID_INVALID\n"));
6369     oneDeviceData->registered = agFALSE;
6370     break;
6371   case OSSA_FAILURE_PHY_ID_ALREADY_REGISTERED: /* fall through */
6372   case OSSA_ERR_PHY_ID_ALREADY_REGISTERED:
6373     /* do nothing */
6374     TI_DBG1(("ossaDeviceRegistrationCB: OSSA_FAILURE_PHY_ID_ALREADY_REGISTERED or OSSA_ERR_PHY_ID_ALREADY_REGISTERED\n"));
6375     break;
6376   case OSSA_FAILURE_PORT_ID_OUT_OF_RANGE: /* fall through */
6377   case OSSA_ERR_PORT_INVALID:
6378     TI_DBG1(("ossaDeviceRegistrationCB: OSSA_FAILURE_PORT_ID_OUT_OF_RANGE or OSSA_ERR_PORT_INVALID\n"));
6379     oneDeviceData->registered = agFALSE;
6380     break;
6381   case OSSA_FAILURE_PORT_NOT_VALID_STATE: /* fall through */
6382   case OSSA_ERR_PORT_STATE_NOT_VALID:
6383     TI_DBG1(("ossaDeviceRegistrationCB: OSSA_FAILURE_PORT_NOT_VALID_STATE or OSSA_ERR_PORT_STATE_NOT_VALID\n"));
6384     TI_DBG2(("ossaDeviceRegistrationCB: did %d pid %d\n", oneDeviceData->id, onePortContext->id));
6385     oneDeviceData->registered = agFALSE;
6386     /* transient period between link up and link down/port recovery */
6387     onePortContext->Transient = agTRUE;
6388     if (onePortContext->valid == agTRUE && (oneDeviceData->valid == agTRUE || oneDeviceData->valid2 == agTRUE))
6389     {
6390       TI_DBG1(("ossaDeviceRegistrationCB: retries regisration\n"));
6391 #ifdef REMOVED
6392       //temp; setting MCN to tdsaAllShared->MCN
6393       oneDeviceData->agDeviceInfo.flag = oneDeviceData->agDeviceInfo.flag | (tdsaAllShared->MCN << 16);
6394       //end temp
6395 #endif
6396       saRegisterNewDevice( /* ossaDeviceRegistrationCB */
6397                           agRoot,
6398                           &oneDeviceData->agContext,
6399                           0,
6400                           &oneDeviceData->agDeviceInfo,
6401                           onePortContext->agPortContext,
6402                           0
6403                          );
6404     }
6405     else if (oneDeviceData->directlyAttached == agTRUE && DEVICE_IS_SATA_DEVICE(oneDeviceData))
6406     {
6407       TI_DBG1(("ossaDeviceRegistrationCB: directly attached SATA, put back into free list\n"));
6408       tdsaDeviceDataReInit(tiRoot, oneDeviceData);
6409       tdsaSingleThreadedEnter(tiRoot, TD_DEVICE_LOCK);
6410       TDLIST_ENQUEUE_AT_TAIL(&(oneDeviceData->FreeLink), &(tdsaAllShared->FreeDeviceList));
6411       tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
6412     }
6413     break;
6414   case OSSA_FAILURE_DEVICE_TYPE_NOT_VALID: /* fall through */
6415   case OSSA_ERR_DEVICE_TYPE_NOT_VALID:
6416     TI_DBG1(("ossaDeviceRegistrationCB: OSSA_FAILURE_DEVICE_TYPE_NOT_VALID or OSSA_ERR_DEVICE_TYPE_NOT_VALID\n"));
6417     oneDeviceData->registered = agFALSE;
6418     break;
6419   default:
6420     TI_DBG1(("ossaDeviceRegistrationCB: wrong. default status is %d\n", status));
6421     break;
6422 
6423 
6424     }
6425   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Ye");
6426   return;
6427 #endif
6428 }
6429 
6430 /*****************************************************************************/
6431 /*! \brief ossaDeregisterDeviceHandleCB
6432  *
6433  *
6434  *  Purpose: This routine is called by lower layer to corresponding to
6435  *           saDeregisterDeviceHandle()
6436  *
6437  *  \param   agRoot:       Pointer to chip/driver Instance.
6438  *  \param   agDevHandle:  Pointer to the assigned device handle for the
6439  *                         registered device.
6440  *  \param   status:       status
6441  *
6442  *
6443  *  \return None.
6444  *
6445  */
6446 /*****************************************************************************/
6447 osGLOBAL void ossaDeregisterDeviceHandleCB(
6448                              agsaRoot_t          *agRoot,
6449                              agsaContext_t       *agContext,
6450                              agsaDevHandle_t     *agDevHandle,
6451                              bit32               status
6452                              )
6453 {
6454   tdsaRootOsData_t     *osData = (tdsaRootOsData_t *)agRoot->osData;
6455   tiRoot_t             *tiRoot = (tiRoot_t *)osData->tiRoot;
6456   tdsaRoot_t           *tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
6457   tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
6458   tdsaDeviceData_t     *oneDeviceData = agNULL;
6459   tdsaPortContext_t    *onePortContext = agNULL;
6460   agsaEventSource_t    *eventSource;
6461   bit32                HwAckSatus;
6462   bit32                PhyID;
6463 #ifdef FDS_DM
6464   dmRoot_t             *dmRoot = &(tdsaAllShared->dmRoot);
6465   dmPortContext_t      *dmPortContext = agNULL;
6466   dmPortInfo_t         dmPortInfo;
6467   bit32                DMstatus = DM_RC_FAILURE;
6468 #endif
6469 #ifdef FDS_SM
6470   smRoot_t             *smRoot = &(tdsaAllShared->smRoot);
6471 #endif
6472 
6473   TI_DBG3(("ossaDeregisterDeviceHandleCB: start\n"));
6474   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yf");
6475 
6476   if (status == OSSA_ERR_DEVICE_HANDLE_INVALID)
6477   {
6478     /* there is no device handle to process */
6479     TI_DBG2(("ossaDeregisterDeviceHandleCB: OSSA_ERR_DEVICE_HANDLE_INVALID\n"));
6480     return;
6481   }
6482 
6483   oneDeviceData = (tdsaDeviceData_t *)agDevHandle->osData;
6484   onePortContext = oneDeviceData->tdPortContext;
6485 #ifdef FDS_DM
6486   dmPortContext = &(onePortContext->dmPortContext);
6487 #endif
6488 
6489   if (oneDeviceData->valid == agFALSE && oneDeviceData->valid2 == agFALSE &&
6490       oneDeviceData->DeviceType == TD_DEFAULT_DEVICE && onePortContext->valid == agTRUE)
6491   {
6492     TI_DBG2(("ossaDeregisterDeviceHandleCB: transient did %d\n", oneDeviceData->id));
6493     return;
6494   }
6495 
6496   if (onePortContext != agNULL)
6497   {
6498     TI_DBG2(("ossaDeregisterDeviceHandleCB: pid %d registeredNumDevice %d\n", onePortContext->id, onePortContext->RegisteredDevNums));
6499   }
6500 
6501   switch (status)
6502   {
6503   case OSSA_SUCCESS:
6504     TI_DBG3(("ossaDeregisterDeviceHandleCB: Success\n"));
6505     if (onePortContext == agNULL)
6506     {
6507       TI_DBG1(("ossaDeregisterDeviceHandleCB: onePortContext is NULL, wrong!\n"));
6508       return;
6509     }
6510     /* port is going down */
6511     if (onePortContext->valid == agFALSE)
6512     {
6513       if (!(oneDeviceData->valid == agFALSE && oneDeviceData->valid2 == agFALSE && oneDeviceData->DeviceType == TD_DEFAULT_DEVICE))
6514       {
6515         /* remove oneDevice from MainLink */
6516         TI_DBG2(("ossaDeregisterDeviceHandleCB: delete from MainLink\n"));
6517 #ifdef FDS_SM
6518         if (DEVICE_IS_SATA_DEVICE(oneDeviceData) || DEVICE_IS_STP_TARGET(oneDeviceData))
6519         {
6520           TI_DBG1(("ossaDeregisterDeviceHandleCB: did %d calling smDeregisterDevice\n", oneDeviceData->id));
6521           smDeregisterDevice(smRoot, oneDeviceData->agDevHandle, &(oneDeviceData->smDeviceHandle));
6522         }
6523 #endif
6524         tdsaDeviceDataReInit(tiRoot, oneDeviceData);
6525         osti_memset(&(oneDeviceData->satDevData.satIdentifyData), 0xFF, sizeof(agsaSATAIdentifyData_t));
6526 
6527         tdsaSingleThreadedEnter(tiRoot, TD_DEVICE_LOCK);
6528         TDLIST_DEQUEUE_THIS(&(oneDeviceData->MainLink));
6529         TDLIST_ENQUEUE_AT_TAIL(&(oneDeviceData->FreeLink), &(tdsaAllShared->FreeDeviceList));
6530         tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
6531       }
6532       /* for portcontext */
6533       PhyID = onePortContext->eventPhyID;
6534       TI_DBG3(("ossaDeregisterDeviceHandleCB: PhyID %d\n", PhyID));
6535       onePortContext->RegisteredDevNums--;
6536       /*
6537         check if valid in tdsaAllShared and the last registered device in a portcontext;
6538         if so, call saHwEventAck()
6539        */
6540       if (tdsaAllShared->eventSource[PhyID].EventValid == agTRUE &&
6541           onePortContext->RegisteredDevNums == 0 &&
6542           PhyID != 0xFF
6543           )
6544       {
6545         TI_DBG2(("ossaDeregisterDeviceHandleCB: calling saHwEventAck\n"));
6546         eventSource = &(tdsaAllShared->eventSource[PhyID].Source);
6547         HwAckSatus = saHwEventAck(
6548                                   agRoot,
6549                                   agNULL, /* agContext */
6550                                   0,
6551                                   eventSource, /* agsaEventSource_t */
6552                                   0,
6553                                   0
6554                                   );
6555         if ( HwAckSatus != AGSA_RC_SUCCESS)
6556         {
6557           TI_DBG1(("ossaDeregisterDeviceHandleCB: failing in saHwEventAck; status %d\n", HwAckSatus));
6558         }
6559 
6560         /* toggle */
6561         tdsaAllShared->eventSource[PhyID].EventValid = agFALSE;
6562 
6563 #ifdef FDS_DM
6564         if (onePortContext->UseDM == agTRUE)
6565         {
6566           TI_DBG1(("ossaDeregisterDeviceHandleCB: calling dmDestroyPort\n"));
6567           /* setup dmPortInfo */
6568           PORTINFO_PUT_SAS_REMOTE_ADDRESSLO(&dmPortInfo, onePortContext->sasRemoteAddressLo);
6569           PORTINFO_PUT_SAS_REMOTE_ADDRESSHI(&dmPortInfo, onePortContext->sasRemoteAddressHi);
6570           PORTINFO_PUT_SAS_LOCAL_ADDRESSLO(&dmPortInfo, onePortContext->sasLocalAddressLo);
6571           PORTINFO_PUT_SAS_LOCAL_ADDRESSHI(&dmPortInfo, onePortContext->sasLocalAddressHi);
6572           DMstatus = dmDestroyPort(dmRoot, dmPortContext, &dmPortInfo);
6573           if (DMstatus != DM_RC_SUCCESS)
6574           {
6575              TI_DBG1(("ossaDeregisterDeviceHandleCB: dmDestroyPort failed!!! 0x%x\n", DMstatus));
6576           }
6577         }
6578 #endif
6579         tdsaPortContextReInit(tiRoot, onePortContext);
6580         /*
6581           put all devices belonging to the onePortContext
6582           back to the free link
6583         */
6584 
6585         tdsaSingleThreadedEnter(tiRoot, TD_PORT_LOCK);
6586         TDLIST_DEQUEUE_THIS(&(onePortContext->MainLink));
6587         TDLIST_ENQUEUE_AT_TAIL(&(onePortContext->FreeLink), &(tdsaAllShared->FreePortContextList));
6588         tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
6589       }
6590       else if (tdsaAllShared->eventSource[PhyID].EventValid == NO_ACK &&
6591                onePortContext->RegisteredDevNums == 0
6592               )
6593       {
6594         TI_DBG2(("ossaDeregisterDeviceHandleCB: NO ACK case\n"));
6595 #ifdef FDS_DM
6596         if (onePortContext->UseDM == agTRUE)
6597         {
6598           TI_DBG1(("ossaDeregisterDeviceHandleCB: calling dmDestroyPort\n"));
6599           /* setup dmPortInfo */
6600           PORTINFO_PUT_SAS_REMOTE_ADDRESSLO(&dmPortInfo, onePortContext->sasRemoteAddressLo);
6601           PORTINFO_PUT_SAS_REMOTE_ADDRESSHI(&dmPortInfo, onePortContext->sasRemoteAddressHi);
6602           PORTINFO_PUT_SAS_LOCAL_ADDRESSLO(&dmPortInfo, onePortContext->sasLocalAddressLo);
6603           PORTINFO_PUT_SAS_LOCAL_ADDRESSHI(&dmPortInfo, onePortContext->sasLocalAddressHi);
6604           DMstatus = dmDestroyPort(dmRoot, dmPortContext, &dmPortInfo);
6605           if (DMstatus != DM_RC_SUCCESS)
6606           {
6607             TI_DBG1(("ossaDeregisterDeviceHandleCB: dmDestroyPort failed!!! 0x%x\n", DMstatus));
6608           }
6609         }
6610 #endif
6611         tdsaPortContextReInit(tiRoot, onePortContext);
6612         /*
6613           put all devices belonging to the onePortContext
6614           back to the free link
6615         */
6616 
6617         tdsaSingleThreadedEnter(tiRoot, TD_PORT_LOCK);
6618         TDLIST_DEQUEUE_THIS(&(onePortContext->MainLink));
6619         TDLIST_ENQUEUE_AT_TAIL(&(onePortContext->FreeLink), &(tdsaAllShared->FreePortContextList));
6620         tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
6621       }
6622       else
6623       {
6624         if (PhyID < TD_MAX_NUM_PHYS)
6625         {
6626           TI_DBG3(("ossaDeregisterDeviceHandleCB: pid %d eventvalid %d registeredNumDevice %d\n", onePortContext->id, tdsaAllShared->eventSource[PhyID].EventValid , onePortContext->RegisteredDevNums));
6627         }
6628         else
6629         {
6630           TI_DBG3(("ossaDeregisterDeviceHandleCB: pid %d registeredNumDevice %d wrong phyid %d\n", onePortContext->id, onePortContext->RegisteredDevNums, PhyID));
6631         }
6632       }
6633     }
6634     else
6635     {
6636       PhyID = onePortContext->eventPhyID;
6637       TI_DBG3(("ossaDeregisterDeviceHandleCB: PhyID %d\n", PhyID));
6638       onePortContext->RegisteredDevNums--;
6639 #ifdef FDS_SM
6640       oneDeviceData->satDevData.IDDeviceValid = agFALSE;
6641       if (DEVICE_IS_SATA_DEVICE(oneDeviceData) || DEVICE_IS_STP_TARGET(oneDeviceData))
6642       {
6643         smDeregisterDevice(smRoot, oneDeviceData->agDevHandle, &(oneDeviceData->smDeviceHandle));
6644       }
6645 #endif
6646       /*
6647         check if valid in tdsaAllShared and the last registered device in a portcontext;
6648         if so, call saHwEventAck()
6649       */
6650       if (tdsaAllShared->eventSource[PhyID].EventValid == agTRUE &&
6651           onePortContext->RegisteredDevNums == 0 &&
6652           PhyID != 0xFF
6653           )
6654       {
6655         TI_DBG2(("ossaDeregisterDeviceHandleCB: calling saHwEventAck\n"));
6656         eventSource = &(tdsaAllShared->eventSource[PhyID].Source);
6657         HwAckSatus = saHwEventAck(
6658                                   agRoot,
6659                                   agNULL, /* agContext */
6660                                   0,
6661                                   eventSource, /* agsaEventSource_t */
6662                                   0,
6663                                   0
6664                                   );
6665         if ( HwAckSatus != AGSA_RC_SUCCESS)
6666         {
6667           TI_DBG1(("ossaDeregisterDeviceHandleCB: failing in saHwEventAck; status %d\n", HwAckSatus));
6668         }
6669 
6670         /* toggle */
6671         tdsaAllShared->eventSource[PhyID].EventValid = agFALSE;
6672       }
6673 #ifdef INITIATOR_DRIVER
6674       else if (onePortContext->RegisteredDevNums == 1)
6675       {
6676         TI_DBG1(("ossaDeregisterDeviceHandleCB: all devices have been deregistered except directly attached EXP\n"));
6677         /* qqqqq If broadcast has been seen, call incremental discovery*/
6678         if (onePortContext->DiscFailNSeenBC == agTRUE)
6679         {
6680           TI_DBG1(("ossaDeregisterDeviceHandleCB: calling dmDiscover, incremental, pid %d\n", onePortContext->id));
6681           dmDiscover(dmRoot, dmPortContext, DM_DISCOVERY_OPTION_INCREMENTAL_START);
6682           onePortContext->DiscFailNSeenBC = agFALSE;
6683         }
6684         else
6685         {
6686           TI_DBG1(("ossaDeregisterDeviceHandleCB: not calling dmDiscover\n"));
6687           /* qqqqq needs to change discovery state to onePortContext->DMDiscoveryState == dmDiscCompleted
6688              in dmQueryDiscovery
6689              change the discovery state from dmDiscFailed to dmDiscCompleted
6690           */
6691           dmResetFailedDiscovery(dmRoot, dmPortContext);
6692 
6693         }
6694       }
6695 #endif
6696       else
6697       {
6698         if (PhyID < TD_MAX_NUM_PHYS)
6699         {
6700           TI_DBG3(("ossaDeregisterDeviceHandleCB: pid %d eventvalid %d registeredNumDevice %d\n", onePortContext->id, tdsaAllShared->eventSource[PhyID].EventValid , onePortContext->RegisteredDevNums));
6701         }
6702         else
6703         {
6704           TI_DBG3(("ossaDeregisterDeviceHandleCB: pid %d registeredNumDevice %d wrong phyid %d\n", onePortContext->id, onePortContext->RegisteredDevNums, PhyID));
6705         }
6706       }
6707     }
6708     break;
6709   case OSSA_INVALID_HANDLE:
6710     TI_DBG1(("ossaDeregisterDeviceHandleCB: OSSA_INVALID_HANDLE\n"));
6711     break;
6712 #ifdef REMOVED
6713   case OSSA_FAILURE_DEVICE_DIRECT_ATTACH:
6714     TI_DBG1(("ossaDeregisterDeviceHandleCB: OSSA_FAILURE_DEVICE_DIRECT_ATTACH\n"));
6715     break;
6716 #endif
6717   case OSSA_ERR_DEVICE_HANDLE_INVALID:
6718     TI_DBG1(("ossaDeregisterDeviceHandleCB: OSSA_ERR_DEVICE_HANDLE_INVALID\n"));
6719     break;
6720   case OSSA_ERR_DEVICE_BUSY:
6721     TI_DBG1(("ossaDeregisterDeviceHandleCB: OSSA_ERR_DEVICE_BUSY\n"));
6722     break;
6723   default:
6724     TI_DBG1(("ossaDeregisterDeviceHandleCB: unknown status 0x%x\n", status));
6725     break;
6726   }
6727 
6728   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yf");
6729   return;
6730 }
6731 
6732 /*****************************************************************************/
6733 /*! \brief ossaDeviceHandleRemovedEvent
6734  *
6735  *
6736  *  Purpose: This routine is called by lower layer to notify the device removal
6737  *
6738  *
6739  *  \param   agRoot:       Pointer to chip/driver Instance.
6740  *  \param   agDevHandle:  Pointer to the assigned device handle for the
6741  *                         registered device.
6742  *  \param   agPortContext:Pointer to this instance of port context.
6743  *
6744  *
6745  *  \return None.
6746  *
6747  */
6748 /*****************************************************************************/
6749 osGLOBAL void ossaDeviceHandleRemovedEvent (
6750                                 agsaRoot_t        *agRoot,
6751                                 agsaDevHandle_t   *agDevHandle,
6752                                 agsaPortContext_t *agPortContext
6753                                 )
6754 {
6755 #ifdef NOT_YET
6756   tdsaRootOsData_t  *osData = (tdsaRootOsData_t *)agRoot->osData;
6757   tiRoot_t          *tiRoot = (tiRoot_t *)osData->tiRoot;
6758 #endif
6759   tdsaPortContext_t *onePortContext = agNULL;
6760   tdsaDeviceData_t  *oneDeviceData = (tdsaDeviceData_t *)agDevHandle->osData;
6761 
6762   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yg");
6763   TI_DBG2(("ossaDeviceHandleRemovedEvent: start\n"));
6764   if (oneDeviceData == agNULL)
6765   {
6766     TI_DBG1(("ossaDeviceHandleRemovedEvent: Wrong! oneDeviceData is NULL\n"));
6767     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yg");
6768     return;
6769   }
6770   TI_DBG2(("ossaDeviceHandleRemovedEvent: did %d\n", oneDeviceData->id));
6771   oneDeviceData->registered = agFALSE;
6772   onePortContext  = (tdsaPortContext_t *)agPortContext->osData;
6773   if (onePortContext == agNULL)
6774   {
6775     TI_DBG1(("ossaDeviceHandleRemovedEvent: Wrong! onePortContext is NULL\n"));
6776     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "Yg");
6777     return;
6778   }
6779   TI_DBG2(("ossaDeviceHandleRemovedEvent: pid %d\n", onePortContext->id));
6780   onePortContext->RegisteredDevNums--;
6781 #ifdef NOT_YET
6782   ostiInitiatorEvent(
6783                      tiRoot,
6784                      onePortContext->tiPortalContext,
6785                      agNULL,
6786                      tiIntrEventTypeDeviceChange,
6787                      tiDeviceRemoval,
6788                      agNULL
6789                      );
6790 #endif
6791 
6792   smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "Yg");
6793   return;
6794 }
6795 
6796 #ifdef SPC_ENABLE_PROFILE
6797 /*****************************************************************************/
6798 /*! \brief ossaFwProfileCB
6799  *
6800  *
6801  *  Purpose: This routine is called by lower layer to corresponding to
6802  *           saFwProfile()
6803  *
6804  *  \param   agRoot:       Pointer to chip/driver Instance.
6805  *  \param   agContext:    Context of the operation originally passed
6806  *                         into saFwProfile()
6807  *  \param   status:       status
6808  *
6809  *
6810  *  \return None.
6811  *
6812  */
6813 /*****************************************************************************/
6814 osGLOBAL void ossaFwProfileCB(
6815                     agsaRoot_t          *agRoot,
6816                     agsaContext_t       *agContext,
6817                     bit32                status,
6818                     bit32                len)
6819 {
6820   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
6821   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
6822 
6823   TI_DBG2(("ossaFwProfileCB: start\n"));
6824 
6825   switch (status)
6826   {
6827     case AGSA_RC_SUCCESS:
6828     {
6829       TI_DBG2(("ossaFwProfileCB: SUCCESS\n"));
6830       break;
6831     }
6832     case AGSA_RC_FAILURE:
6833     {
6834       TI_DBG1(("ossaFwProfileCB: FAIL\n"));
6835       break;
6836     }
6837     default:
6838     {
6839       TI_DBG1(("ossaFwProfileCB: !!! default, status %d\n", status));
6840       break;
6841     }
6842   }
6843 
6844   ostiFWProfileIOCTLRsp(tiRoot, status, len);
6845   return;
6846 }
6847 #endif
6848 /*****************************************************************************/
6849 /*! \brief ossaFwFlashUpdateCB
6850  *
6851  *
6852  *  Purpose: This routine is called by lower layer to corresponding to
6853  *           saFwFlashUpdate()
6854  *
6855  *  \param   agRoot:       Pointer to chip/driver Instance.
6856  *  \param   agContext:    Context of the operation originally passed
6857  *                         into saFwFlashUpdate()
6858  *  \param   status:       status
6859  *
6860  *
6861  *  \return None.
6862  *
6863  */
6864 /*****************************************************************************/
6865 osGLOBAL void ossaFwFlashUpdateCB(
6866                     agsaRoot_t          *agRoot,
6867                     agsaContext_t       *agContext,
6868                     bit32               status
6869                     )
6870 {
6871   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
6872   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
6873 
6874   TI_DBG2(("ossaFwFlashUpdateCB: start\n"));
6875 
6876   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yh");
6877   switch (status)
6878   {
6879   case OSSA_FLASH_UPDATE_COMPLETE_PENDING_REBOOT:
6880   {
6881     TI_DBG2(("ossaFwFlashUpdateCB: OSSA_FLASH_UPDATE_COMPLETE_PENDING_REBOOT\n"));
6882     break;
6883   }
6884   case OSSA_FLASH_UPDATE_IN_PROGRESS:
6885   {
6886     TI_DBG2(("ossaFwFlashUpdateCB: OSSA_FLASH_UPDATE_IN_PROGRESS\n"));
6887     break;
6888   }
6889   case OSSA_FLASH_UPDATE_HDR_ERR:
6890   {
6891     TI_DBG1(("ossaFwFlashUpdateCB: OSSA_FLASH_UPDATE_HDR_ERR\n"));
6892     break;
6893   }
6894   case OSSA_FLASH_UPDATE_OFFSET_ERR:
6895   {
6896     TI_DBG1(("ossaFwFlashUpdateCB: OSSA_FLASH_UPDATE_OFFSET_ERR\n"));
6897     break;
6898   }
6899   case OSSA_FLASH_UPDATE_CRC_ERR:
6900   {
6901     TI_DBG1(("ossaFwFlashUpdateCB: OSSA_FLASH_UPDATE_CRC_ERR\n"));
6902     break;
6903   }
6904   case OSSA_FLASH_UPDATE_LENGTH_ERR:
6905   {
6906     TI_DBG1(("ossaFwFlashUpdateCB: OSSA_FLASH_UPDATE_LENGTH_ERR\n"));
6907     break;
6908   }
6909   case OSSA_FLASH_UPDATE_HW_ERR:
6910   {
6911     TI_DBG1(("ossaFwFlashUpdateCB: OSSA_FLASH_UPDATE_HW_ERR\n"));
6912     break;
6913   }
6914   case OSSA_FLASH_UPDATE_DNLD_NOT_SUPPORTED:
6915   {
6916     TI_DBG1(("ossaFwFlashUpdateCB: OSSA_FLASH_UPDATE_DNLD_NOT_SUPPORTED\n"));
6917     break;
6918   }
6919   case OSSA_FLASH_UPDATE_DISABLED:
6920   {
6921     TI_DBG1(("ossaFwFlashUpdateCB: OSSA_FLASH_UPDATE_DISABLED\n"));
6922     break;
6923   }
6924   case OSSA_FLASH_FWDNLD_DEVICE_UNSUPPORT:
6925   {
6926     TI_DBG1(("ossaFwFlashUpdateCB: OSSA_FLASH_FWDNLD_DEVICE_UNSUPPORT\n"));
6927     break;
6928   }
6929   case OSSA_MPI_ERR_IO_RESOURCE_UNAVAILABLE:
6930   {
6931     TI_DBG1(("ossaFwFlashUpdateCB: OSSA_MPI_ERR_IO_RESOURCE_UNAVAILABLE\n"));
6932     break;
6933   }
6934   case OSSA_FLASH_UPDATE_HMAC_ERR:
6935   {
6936     TI_DBG1(("ossaFwFlashUpdateCB: OSSA_FLASH_UPDATE_HMAC_ERR\n"));
6937     break;
6938   }
6939 
6940   default:
6941   {
6942     TI_DBG1(("ossaFwFlashUpdateCB: !!! default, status 0x%X\n", status));
6943     break;
6944   }
6945   }
6946 
6947   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yh");
6948   ostiCOMMgntIOCTLRsp(tiRoot, status);
6949   return;
6950 
6951 }
6952 
6953 
6954 GLOBAL void   ossaFlashExtExecuteCB(
6955                       agsaRoot_t               *agRoot,
6956                       agsaContext_t            *agContext,
6957                       bit32                    status,
6958                       bit32                    command,
6959                       agsaFlashExtResponse_t  *agFlashExtRsp)
6960 {
6961     TI_DBG1(("ossaFlashExtExecuteCB: command  0x%X status 0x%X\n",command, status));
6962 
6963 }
6964 
6965 
6966 
6967 /*****************************************************************************/
6968 /*! \brief ossaGetNVMDResponseCB
6969  *
6970  *
6971  *  Purpose: This routine is called by lower layer to corresponding to
6972  *           saGetNVMDCommand()
6973  *
6974  *  \param   agRoot:           Pointer to chip/driver Instance.
6975  *  \param   agContext:        Context of the operation originally passed
6976  *                             into saGetVPDCommand()
6977  *  \param   status:           status
6978  *  \param   indirectPayload:  The value passed in agsaNVMDData_t when
6979  *                             calling saGetNVMDCommand()
6980  *  \param   agInfoLen:        the length of VPD information
6981  *  \param   agFrameHandle:    handler of VPD information
6982  *
6983  *
6984  *  \return None.
6985  *
6986  */
6987 /*****************************************************************************/
6988 osGLOBAL void ossaGetNVMDResponseCB(
6989                       agsaRoot_t                    *agRoot,
6990                       agsaContext_t                 *agContext,
6991                       bit32                         status,
6992                       bit8                          indirectPayload,
6993                       bit32                         agInfoLen,
6994                       agsaFrameHandle_t             agFrameHandle
6995 )
6996 {
6997   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
6998   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
6999   TI_DBG2(("ossaGetNVMDResponseCB: start\n"));
7000   TI_DBG2(("ossaGetNVMDResponseCB: agInfoLen %d\n", agInfoLen));
7001   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yi");
7002 
7003   if (status == OSSA_SUCCESS)
7004   {
7005     TI_DBG2(("ossaGetNVMDResponseCB: Success status\n"));
7006     if (indirectPayload == 0 && agInfoLen != 0)
7007     {
7008       TI_DBG2(("ossaGetNVMDResponseCB: direct\n"));
7009       tdhexdump("ossaGetNVMDResponseCB", (bit8 *)agFrameHandle, agInfoLen);
7010     }
7011   }
7012   else
7013   {
7014     TI_DBG1(("ossaGetNVMDResponseCB: Status 0x%x\n", status));
7015   }
7016 
7017   if (indirectPayload == 0)
7018   {
7019     TI_DBG2(("ossaGetNVMDResponseCB: direct\n"));
7020   }
7021   else
7022   {
7023     TI_DBG2(("ossaGetNVMDResponseCB: indirect\n"));
7024   }
7025 
7026   ostiGetNVMDIOCTLRsp(tiRoot, status);
7027   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yi");
7028   return;
7029 }
7030 
7031 
7032 /*****************************************************************************/
7033 /*! \brief ossaSetNVMDResponseCB
7034  *
7035  *
7036  *  Purpose: This routine is called by lower layer to corresponding to
7037  *           saSetNVMDCommand()
7038  *
7039  *  \param   agRoot:       Pointer to chip/driver Instance.
7040  *  \param   agContext:    Context of the operation originally passed
7041  *                         into saSetVPDCommand()
7042  *  \param   status:       status
7043  *
7044  *
7045  *  \return None.
7046  *
7047  */
7048 /*****************************************************************************/
7049 osGLOBAL void ossaSetNVMDResponseCB(
7050                       agsaRoot_t            *agRoot,
7051                       agsaContext_t         *agContext,
7052                       bit32                 status
7053                       )
7054 {
7055   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
7056   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
7057   TI_DBG2(("ossaSetNVMDResponseCB: start\n"));
7058   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yj");
7059   if (status == OSSA_SUCCESS)
7060   {
7061     TI_DBG2(("ossaSetNVMDResponseCB: success\n"));
7062   }
7063   else
7064   {
7065     TI_DBG1(("ossaSetNVMDResponseCB: fail or undefined staus %d\n", status));
7066   }
7067   ostiSetNVMDIOCTLRsp(tiRoot, status);
7068   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yj");
7069   return;
7070 }
7071 
7072 
7073 #ifdef REMOVED
7074 /*****************************************************************************/
7075 /*! \brief ossaGetVPDResponseCB
7076  *
7077  *
7078  *  Purpose: This routine is called by lower layer to corresponding to
7079  *           saGetVPDCommand()
7080  *
7081  *  \param   agRoot:       Pointer to chip/driver Instance.
7082  *  \param   agContext:    Context of the operation originally passed
7083  *                         into saGetVPDCommand()
7084  *  \param   status:       status
7085  *  \param   agInfoLen:    the length of VPD information
7086  *  \param   agFrameHandle:handler of VPD information
7087  *
7088  *
7089  *  \return None.
7090  *
7091  */
7092 /*****************************************************************************/
7093 osGLOBAL void ossaGetVPDResponseCB(
7094                      agsaRoot_t         *agRoot,
7095                      agsaContext_t      *agContext,
7096                      bit32              status,
7097                      bit8               indirectMode,
7098                      bit32              agInfoLen,
7099                      agsaFrameHandle_t  agFrameHandle
7100                      )
7101 {
7102   bit8 VPDData[48];
7103 
7104   TI_DBG2(("ossaGetVPDResponseCB: start\n"));
7105 
7106   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yk");
7107   if (status == OSSA_SUCCESS)
7108   {
7109     TI_DBG2(("ossaGetVPDResponseCB: agInfoLen %d\n", agInfoLen));
7110     osti_memset(VPDData, 0, 48);
7111     /* We can read only in case of Direct */
7112     saFrameReadBlock(agRoot, agFrameHandle, 0, VPDData, agInfoLen);
7113     tdhexdump("ossaGetVPDResponseCB", (bit8 *)VPDData, agInfoLen);
7114     /*
7115       callback osti....
7116     */
7117   }
7118   else
7119   {
7120     TI_DBG1(("ossaGetVPDResponseCB: fail or undefined staus %d\n", status));
7121   }
7122   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yk");
7123   return;
7124 }
7125 
7126 
7127 /*****************************************************************************/
7128 /*! \brief ossaSetVPDResponseCB
7129  *
7130  *
7131  *  Purpose: This routine is called by lower layer to corresponding to
7132  *           saSetVPDCommand()
7133  *
7134  *  \param   agRoot:       Pointer to chip/driver Instance.
7135  *  \param   agContext:    Context of the operation originally passed
7136  *                         into saSetVPDCommand()
7137  *  \param   status:       status
7138  *
7139  *
7140  *  \return None.
7141  *
7142  */
7143 /*****************************************************************************/
7144 osGLOBAL void ossaSetVPDResponseCB(
7145                      agsaRoot_t         *agRoot,
7146                      agsaContext_t      *agContext,
7147                      bit32              status
7148                      )
7149 {
7150   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
7151   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
7152 
7153   TI_DBG2(("ossaSetVPDResponseCB: start\n"));
7154   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yl");
7155 
7156   if (status == OSSA_SUCCESS)
7157   {
7158     TI_DBG2(("ossaSetVPDResponseCB: success\n"));
7159     ostiCOMMgntVPDSetIOCTLRsp(tiRoot, 0);
7160     /*
7161       callback osti.....
7162     */
7163 
7164 #ifdef VPD_TESTING
7165     /* temporary to test saSetVPDCommand() and saGetVPDCommand */
7166     tdsaVPDGet(tiRoot);
7167 #endif
7168 
7169   }
7170   else
7171   {
7172     TI_DBG1(("ossaSetVPDResponseCB: fail or undefined staus %d\n", status));
7173   }
7174   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yl");
7175   return;
7176 }
7177 #endif
7178 
7179 /*****************************************************************************/
7180 /*! \brief ossaEchoCB
7181  *
7182  *
7183  *  Purpose: This routine is called by lower layer to corresponding to
7184  *           saEchoCommand()
7185  *
7186  *  \param   agRoot:        Pointer to chip/driver Instance.
7187  *  \param   agContext:     Context of the operation originally passed
7188  *                          into saEchoCommand()
7189  *  \param   echoPayload:   Pointer to the echo payload
7190  *
7191  *
7192  *  \return None.
7193  *
7194  */
7195 /*****************************************************************************/
7196 osGLOBAL void ossaEchoCB(
7197             agsaRoot_t      *agRoot,
7198             agsaContext_t   *agContext,
7199             void            *echoPayload
7200           )
7201 {
7202 #ifdef ECHO_TESTING
7203   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
7204   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
7205   bit8                payload[56];
7206 #endif
7207 
7208   TI_DBG2(("ossaEchoCB: start\n"));
7209   smTraceFuncEnter(hpDBG_VERY_LOUD,"Ym");
7210 
7211   /* dumping received echo payload is 56 bytes */
7212   tdhexdump("ossaEchoCB: echoPayload", (bit8 *)(echoPayload), 56);
7213 
7214 #ifdef ECHO_TESTING
7215   /* temporary to test saEchoCommand() */
7216 
7217   /* new echo payload */
7218   osti_memset(payload,0, sizeof(payload));
7219 
7220   payload[0] = gEcho;
7221   payload[55] = gEcho;
7222 
7223   TI_DBG2(("ossaEchoCB: gEcho %d\n", gEcho));
7224 
7225   saEchoCommand(agRoot, agNULL, tdsaRotateQnumber(tiRoot, agNULL), (void *)&payload);
7226 
7227   if (gEcho == 0xFF)
7228   {
7229     gEcho = 0;
7230   }
7231   else
7232   {
7233     gEcho++;
7234   }
7235 #endif
7236 
7237   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Ym");
7238   return;
7239 }
7240 
7241 /*****************************************************************************/
7242 /*! \brief ossaGpioResponseCB
7243  *
7244  *
7245  *  Purpose: This routine is called by lower layer to corresponding to
7246  *           saGpioEventSetup(), saGpioPinSetup(), saGpioRead(), or
7247  *           saGpioWrite()
7248  *
7249  *  \param   agRoot:              Pointer to chip/driver Instance.
7250  *  \param   agContext:           Context of the operation originally passed
7251  *                                in.
7252  *  \param   status:              GPIO operation completion status
7253  *  \param   gpioReadValue:       a bit map containing the corresponding
7254  *                                value for each GPIO pin.
7255  *  \param   gpioPinSetupInfo:    Pointer to agsaGpioPinSetupInfo_t structure
7256  *                                describing the GPIO pin setup
7257  *  \param   gpioEventSetupInfo   Pointer to agsaGpioEventSetupInfo_t structure
7258  *                                describing the GPIO event setups
7259  *
7260  *
7261  *  \return None.
7262  *
7263  */
7264 /*****************************************************************************/
7265 osGLOBAL void ossaGpioResponseCB(
7266                    agsaRoot_t               *agRoot,
7267                    agsaContext_t            *agContext,
7268                    bit32                    status,
7269                    bit32                    gpioReadValue,
7270                    agsaGpioPinSetupInfo_t   *gpioPinSetupInfo,
7271                    agsaGpioEventSetupInfo_t *gpioEventSetupInfo
7272                    )
7273 {
7274   TI_DBG2(("ossaGpioResponseCB: start\n"));
7275   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yn");
7276   if (status == OSSA_SUCCESS)
7277   {
7278     TI_DBG2(("ossaGpioResponseCB: Success\n"));
7279     /* printing gpioReadValue, agsaGpioPinSetupInfo_t and agsaGpioEventSetupInfo_t */
7280     TI_DBG2(("ossaGpioResponseCB: gpioReadValue 0x%x\n", gpioReadValue));
7281     TI_DBG2(("ossaGpioResponseCB: PinSetupInfo gpioInputEnabled 0x%x\n", gpioPinSetupInfo->gpioInputEnabled));
7282     TI_DBG2(("ossaGpioResponseCB: PinSetupInfo gpioTypePart1 0x%x\n", gpioPinSetupInfo->gpioTypePart1));
7283     TI_DBG2(("ossaGpioResponseCB: PinSetupInfo gpioTypePart2 0x%x\n", gpioPinSetupInfo->gpioTypePart2));
7284     TI_DBG2(("ossaGpioResponseCB: EventSetupInfo gpioEventLevel 0x%x\n", gpioEventSetupInfo->gpioEventLevel));
7285     TI_DBG2(("ossaGpioResponseCB: EventSetupInfo gpioEventRisingEdge 0x%x\n", gpioEventSetupInfo->gpioEventRisingEdge));
7286     TI_DBG2(("ossaGpioResponseCB: EventSetupInfo gpioEventFallingEdge 0x%x\n", gpioEventSetupInfo->gpioEventFallingEdge));
7287   }
7288   else
7289   {
7290     TI_DBG1(("ossaGpioResponseCB: Failure\n"));
7291   }
7292   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yn");
7293   return;
7294 }
7295 
7296 /*****************************************************************************/
7297 /*! \brief ossaGpioEvent
7298  *
7299  *
7300  *  Purpose: This routine is called by lower layer to corresponding to
7301  *           saGpioEventSetup(), saGpioPinSetup(), saGpioRead(), or
7302  *           saGpioWrite()
7303  *
7304  *  \param   agRoot:              Pointer to chip/driver Instance.
7305  *  \param   gpioEvent:           a bit map that indicates which GPIO
7306  *                                input pins have generated the event.
7307  *
7308  *
7309  *  \return None.
7310  *
7311  */
7312 /*****************************************************************************/
7313 osGLOBAL void ossaGpioEvent(
7314               agsaRoot_t    *agRoot,
7315               bit32         gpioEvent
7316               )
7317 {
7318   TI_DBG2(("ossaGpioEvent: start\n"));
7319   TI_DBG2(("ossaGpioEvent: gpioEvent 0x%x\n", gpioEvent));
7320   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yo");
7321   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yo");
7322   return;
7323 }
7324 
7325 
7326 /*****************************************************************************/
7327 /*! \brief ossaSASDiagExecuteCB
7328  *
7329  *
7330  *  Purpose: This routine is called by lower layer to corresponding to
7331  *           saSASDiagExecute()
7332  *
7333  *  \param   agRoot:              Pointer to chip/driver Instance.
7334  *  \param   agContext:           Context of the operation originally passed
7335  *                                in.
7336  *  \param   status:              Diagnostic operation completion status
7337  *  \param   command:             SAS diagnostic command field in agsaSASDiagExecute_t
7338  *                                structure passed in saSASDiagExecute().
7339  *  \param   reportData:          Report Diagnostic Data
7340  *
7341  *
7342  *  \return None.
7343  *
7344  */
7345 /*****************************************************************************/
7346 osGLOBAL void ossaSASDiagExecuteCB(
7347                       agsaRoot_t      *agRoot,
7348                       agsaContext_t   *agContext,
7349                       bit32           status,
7350                       bit32           command,
7351                       bit32           reportData)
7352 {
7353   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yq");
7354   TI_DBG2(("ossaSASDiagExecuteCB: start\n"));
7355   TI_DBG2(("ossaSASDiagExecuteCB: status %d\n", status));
7356   TI_DBG2(("ossaSASDiagExecuteCB: command %d\n", command));
7357   TI_DBG2(("ossaSASDiagExecuteCB: reportData %d\n", reportData));
7358 
7359   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yq");
7360   return;
7361 
7362 }
7363 
7364 
7365 /*****************************************************************************/
7366 /*! \brief ossaSASDiagStartEndCB
7367  *
7368  *
7369  *  Purpose: This routine is called by lower layer to corresponding to
7370  *           saSASDiagExecute()
7371  *
7372  *  \param   agRoot:              Pointer to chip/driver Instance.
7373  *  \param   agContext:           Context of the operation originally passed
7374  *                                in.
7375  *  \param   status:              Diagnostic operation completion status
7376  *
7377  *
7378  *  \return None.
7379  *
7380  */
7381 /*****************************************************************************/
7382 osGLOBAL void ossaSASDiagStartEndCB(
7383                       agsaRoot_t        *agRoot,
7384                       agsaContext_t     *agContext,
7385                       bit32             status)
7386 {
7387   TI_DBG2(("ossaSASDiagStartEndCB: start\n"));
7388   TI_DBG2(("ossaSASDiagStartEndCB: status %d\n", status));
7389   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yr");
7390   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yr");
7391   return;
7392 }
7393 
7394 /*****************************************************************************/
7395 /*! \brief ossaReconfigSASParamsCB
7396  *
7397  *
7398  *  Purpose: This routine is called by lower layer to corresponding to
7399  *           saReconfigSASParams()
7400  *
7401  *  \param   agRoot:              Pointer to chip/driver Instance.
7402  *  \param   agContext:           Context of the operation originally passed
7403  *                                in saReconfigSASParams().
7404  *  \param   status:              saReconfigSASParams() completion status
7405  *  \param   agSASConfig:         Pointer to the data structure agsaSASReconfig_t
7406  *
7407  *
7408  *  \return None.
7409  *
7410  */
7411 /*****************************************************************************/
7412 osGLOBAL void   ossaReconfigSASParamsCB(
7413                         agsaRoot_t        *agRoot,
7414                         agsaContext_t     *agContext,
7415                         bit32             status,
7416                         agsaSASReconfig_t *agSASConfig)
7417 {
7418   TI_DBG2(("ossaReconfigSASParamsCB: status %d\n", status));
7419   return;
7420 }
7421 
7422 GLOBAL void ossaPCIeDiagExecuteCB(
7423             agsaRoot_t             *agRoot,
7424             agsaContext_t         *agContext,
7425             bit32                  status,
7426             bit32                  command,
7427             agsaPCIeDiagResponse_t *resp )
7428 {
7429   TI_DBG2(("ossaPCIeDiagExecuteCB: status %d\n", status));
7430   TI_DBG2(("ossaPCIeDiagExecuteCB: ERR_BLKH 0x%X\n",resp->ERR_BLKH ));
7431   TI_DBG2(("ossaPCIeDiagExecuteCB: ERR_BLKL 0x%X\n",resp->ERR_BLKL ));
7432   TI_DBG2(("ossaPCIeDiagExecuteCB: DWord8 0x%X\n",resp->DWord8 ));
7433   TI_DBG2(("ossaPCIeDiagExecuteCB: DWord9 0x%X\n",resp->DWord9 ));
7434   TI_DBG2(("ossaPCIeDiagExecuteCB: DWord10 0x%X\n",resp->DWord10 ));
7435   TI_DBG2(("ossaPCIeDiagExecuteCB: DWord11 0x%X\n",resp->DWord11 ));
7436   TI_DBG2(("ossaPCIeDiagExecuteCB: DIF_ERR 0x%X\n",resp->DIF_ERR ));
7437 
7438   return;
7439 }
7440 
7441 
7442 #ifndef BIOS
7443 GLOBAL void ossaSGpioCB(
7444                     agsaRoot_t              *agRoot,
7445                     agsaContext_t           *agContext,
7446                     agsaSGpioReqResponse_t  *pSgpioResponse
7447                     )
7448 {
7449   tdsaRootOsData_t  *osData = (tdsaRootOsData_t *)agRoot->osData;
7450   tiRoot_t          *tiRoot = (tiRoot_t *)osData->tiRoot;
7451 
7452   TI_DBG2(("ossaSGpioCB:  smpFrameType: 0x%02x \n", pSgpioResponse->smpFrameType));
7453  // printf("SS:ossaSGpioCB:  smpFrameType: 0x%02x \n", pSgpioResponse->smpFrameType);
7454   TI_DBG2(("ossaSGpioCB:  function: 0x%02x \n", pSgpioResponse->function));
7455   TI_DBG2(("ossaSGpioCB:  functionResult: 0x%02x \n", pSgpioResponse->functionResult));
7456   //printf("SS:ossaSGpioCB:  functionResult: 0x%02x \n", pSgpioResponse->functionResult);
7457 
7458   tdhexdump("ossaSGpioCB Response", (bit8 *)pSgpioResponse, sizeof(agsaSGpioReqResponse_t));
7459   ostiSgpioIoctlRsp(tiRoot, pSgpioResponse);
7460 }
7461 
7462 #endif /* BIOS */
7463 
7464 /*****************************************************************************/
7465 /*! \brief ossaLogDebugString
7466  *
7467  *
7468  *  Purpose: This routine is called by lower layer to log.
7469  *
7470  *  \param   agRoot:              Pointer to chip/driver Instance.
7471  *  \param   level:               Detail of information desired.
7472  *  \param   string:              Pointer to the character string.
7473  *  \param   ptr1:                First pointer value.
7474  *  \param   ptr2:                Second pointer value.
7475  *  \param   value1:              First 32-bit value related to the specific information.
7476  *  \param   value2:              Second 32-bit value related to the specific information.
7477  *
7478  *  \return None.
7479  *
7480  */
7481 /*****************************************************************************/
7482 GLOBAL void ossaLogDebugString(
7483                          agsaRoot_t   *agRoot,
7484                          bit32        level,
7485                          char         *string,
7486                          void         *ptr1,
7487                          void         *ptr2,
7488                          bit32        value1,
7489                          bit32        value2
7490                          )
7491 {
7492 #if defined(SALLSDK_DEBUG)
7493   TIDEBUG_MSG(gLLDebugLevel, level, ("%s %p %p %d %d\n", string, ptr1, ptr2, value1, value2));
7494 #endif
7495   return;
7496 }
7497 
7498 /*****************************************************************************/
7499 /*! \brief ossaHwEventAckCB
7500  *
7501  *
7502  *  Purpose: This routine is called by lower layer to corresponding to
7503  *           saHwEventAck(()
7504  *
7505  *  \param   agRoot:              Pointer to chip/driver Instance.
7506  *  \param   agContext:           Context of the operation originally passed
7507  *                                in.
7508  *  \param   status:              Status
7509  *
7510  *
7511  *  \return None.
7512  *
7513  */
7514 /*****************************************************************************/
7515 GLOBAL void ossaHwEventAckCB(
7516                              agsaRoot_t         *agRoot,
7517                              agsaContext_t      *agContext,
7518                              bit32              status
7519                              )
7520 {
7521   TI_DBG3(("ossaHwEventAckCB: start\n"));
7522   smTraceFuncEnter(hpDBG_VERY_LOUD,"Ys");
7523   if (status == tiSuccess)
7524   {
7525     TI_DBG3(("ossaHwEventAckCB: SUCCESS status\n"));
7526   }
7527   else
7528   {
7529     TI_DBG1(("ossaHwEventAckCB: FAIL status 0x%X\n", status));
7530     TI_DBG1(("ossaHwEventAckCB: invalid event status bit0 %d\n", status & 0x01));
7531     TI_DBG1(("ossaHwEventAckCB: invalid phyid status bit1 %d\n", (status & 0x02) >> 1 ));
7532     TI_DBG1(("ossaHwEventAckCB: invalid portcontext status bit2 %d\n", (status & 0x04) >> 2));
7533     TI_DBG1(("ossaHwEventAckCB: invalid param0 status bit3 %d\n", (status & 0x08) >> 3));
7534   }
7535 
7536   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Ys");
7537   return;
7538 }
7539 
7540 /*****************************************************************************/
7541 /*! \brief ossaGetTimeStampCB
7542  *
7543  *
7544  *  Purpose: This routine is called by lower layer to corresponding to
7545  *           saGetTimeStamp()
7546  *
7547  *  \param   agRoot:              Pointer to chip/driver Instance.
7548  *  \param   agContext:           Context of the operation originally passed
7549  *                                in.
7550  *  \param   timeStampLower:      The controller lower 32-bit of internal time
7551  *                                stamp associated with event log.
7552  *  \param   timeStampUpper:      The controller upper 32-bit of internal time
7553  *                                stamp associated with event log.
7554  *
7555  *
7556  *  \return None.
7557  *
7558  */
7559 /*****************************************************************************/
7560 GLOBAL void ossaGetTimeStampCB(
7561                          agsaRoot_t    *agRoot,
7562                          agsaContext_t *agContext,
7563                          bit32         timeStampLower,
7564                          bit32         timeStampUpper
7565                          )
7566 {
7567   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yt");
7568   TI_DBG4(("ossaGetTimeStampCB: start\n"));
7569   TI_DBG4(("ossaGetTimeStampCB: timeStampUpper 0x%x timeStampLower 0x%x\n", timeStampUpper, timeStampLower));
7570   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yt");
7571   return;
7572 }
7573 
7574 
7575 /*****************************************************************************/
7576 /*! \brief ossaSMPAbortCB
7577  *
7578  *
7579  *  Purpose: This routine is called by lower layer to corresponding to
7580  *           saSMPAbort()
7581  *
7582  *  \param   agRoot:              Pointer to chip/driver Instance.
7583  *  \param   agIORequest:         This is the agIORequest parameter passed in
7584  *                                saSMPAbort()
7585  *  \param   status:              Status of abort
7586  *
7587  *  \return None.
7588  *
7589  */
7590 /*****************************************************************************/
7591 GLOBAL void ossaSMPAbortCB(
7592                            agsaRoot_t           *agRoot,
7593                            agsaIORequest_t      *agIORequest,
7594                            bit32                flag,
7595                            bit32                status)
7596 {
7597   tdsaRootOsData_t        *osData = (tdsaRootOsData_t *)agRoot->osData;
7598   tiRoot_t                *tiRoot = (tiRoot_t *)osData->tiRoot;
7599   tdIORequestBody_t       *tdAbortIORequestBody = agNULL;
7600   tdsaDeviceData_t        *oneDeviceData        = agNULL;
7601   tiDeviceHandle_t        *tiDeviceHandle       = agNULL;
7602 
7603   TI_DBG4(("ossaSMPAbortCB: start\n"));
7604   TI_DBG4(("ossaSMPAbortCB: flag %d\n", flag));
7605   TI_DBG4(("ossaSMPAbortCB: status %d\n", status));
7606   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yu");
7607 
7608   tdAbortIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
7609   if (tdAbortIORequestBody == agNULL)
7610   {
7611     TI_DBG1(("ossaSMPAbortCB: tdAbortIORequestBody is NULL warning!!!!\n"));
7612     return;
7613   }
7614 
7615   if (flag == 2)
7616   {
7617     /* abort per port */
7618     TI_DBG2(("ossaSMPAbortCB: abort per port\n"));
7619   }
7620   else if (flag == 1)
7621   {
7622     TI_DBG2(("ossaSMPAbortCB: abort all\n"));
7623 
7624     tiDeviceHandle = (tiDeviceHandle_t *)tdAbortIORequestBody->tiDevHandle;
7625     if (tiDeviceHandle == agNULL)
7626     {
7627       TI_DBG1(("ossaSMPAbortCB: tiDeviceHandle is NULL warning!!!!\n"));
7628       ostiFreeMemory(
7629                tiRoot,
7630                tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
7631                sizeof(tdIORequestBody_t)
7632                );
7633       return;
7634     }
7635 
7636     oneDeviceData  = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
7637     if (oneDeviceData == agNULL)
7638     {
7639       TI_DBG1(("ossaSMPAbortCB: oneDeviceData is NULL warning!!!!\n"));
7640       ostiFreeMemory(
7641                tiRoot,
7642                tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
7643                sizeof(tdIORequestBody_t)
7644                );
7645       return;
7646     }
7647 
7648     if (status == OSSA_IO_SUCCESS)
7649     {
7650       TI_DBG2(("ossaSMPAbortCB: OSSA_IO_SUCCESS\n"));
7651       /* clean up TD layer's IORequestBody */
7652       TI_DBG3(("ossaSMPAbortCB: calling saDeregisterDeviceHandle\n"));
7653       saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
7654       TI_DBG2(("ossaSMPAbortCB: did %d\n", oneDeviceData->id));
7655       ostiFreeMemory(
7656                      tiRoot,
7657                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
7658                      sizeof(tdIORequestBody_t)
7659                      );
7660 
7661     }
7662     else if (status == OSSA_IO_NOT_VALID)
7663     {
7664       TI_DBG1(("ossaSMPAbortCB: OSSA_IO_NOT_VALID\n"));
7665       /* clean up TD layer's IORequestBody */
7666       TI_DBG1(("ossaSMPAbortCB: calling saDeregisterDeviceHandle\n"));
7667       saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
7668       TI_DBG1(("ossaSMPAbortCB: did %d\n", oneDeviceData->id));
7669       ostiFreeMemory(
7670                      tiRoot,
7671                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
7672                      sizeof(tdIORequestBody_t)
7673                      );
7674     }
7675     else if (status == OSSA_IO_NO_DEVICE)
7676     {
7677       TI_DBG1(("ossaSMPAbortCB: OSSA_IO_NO_DEVICE\n"));
7678       /* clean up TD layer's IORequestBody */
7679       TI_DBG1(("ossaSMPAbortCB: calling saDeregisterDeviceHandle\n"));
7680       saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
7681       TI_DBG1(("ossaSMPAbortCB: did %d\n", oneDeviceData->id));
7682       ostiFreeMemory(
7683                      tiRoot,
7684                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
7685                      sizeof(tdIORequestBody_t)
7686                      );
7687     }
7688     else if (status == OSSA_IO_ABORT_IN_PROGRESS)
7689     {
7690       TI_DBG1(("ossaSMPAbortCB: OSSA_IO_ABORT_IN_PROGRESS\n"));
7691       /* clean up TD layer's IORequestBody */
7692       TI_DBG1(("ossaSMPAbortCB: calling saDeregisterDeviceHandle\n"));
7693       saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
7694       TI_DBG1(("ossaSMPAbortCB: did %d\n", oneDeviceData->id));
7695       ostiFreeMemory(
7696                      tiRoot,
7697                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
7698                      sizeof(tdIORequestBody_t)
7699                      );
7700     }
7701 #ifdef REMOVED
7702     else if (status == OSSA_IO_ABORT_DELAYED)
7703     {
7704       TI_DBG1(("ossaSMPAbortCB: OSSA_IO_ABORT_DELAYED\n"));
7705       /* clean up TD layer's IORequestBody */
7706       TI_DBG1(("ossaSMPAbortCB: calling saDeregisterDeviceHandle\n"));
7707       saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
7708       TI_DBG1(("ossaSMPAbortCB: did %d\n", oneDeviceData->id));
7709       ostiFreeMemory(
7710                      tiRoot,
7711                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
7712                      sizeof(tdIORequestBody_t)
7713                      );
7714     }
7715 #endif
7716     else
7717     {
7718       TI_DBG1(("ossaSMPAbortCB: other status %d\n", status));
7719       /* clean up TD layer's IORequestBody */
7720       TI_DBG1(("ossaSMPAbortCB: calling saDeregisterDeviceHandle\n"));
7721       saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
7722       TI_DBG1(("ossaSMPAbortCB: did %d\n", oneDeviceData->id));
7723       ostiFreeMemory(
7724                      tiRoot,
7725                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
7726                      sizeof(tdIORequestBody_t)
7727                      );
7728     }
7729   }
7730   else if (flag == 0)
7731   {
7732     TI_DBG2(("ossaSMPAbortCB: abort one\n"));
7733     if (status == OSSA_IO_SUCCESS)
7734     {
7735       TI_DBG2(("ossaSMPAbortCB: OSSA_IO_SUCCESS\n"));
7736       ostiFreeMemory(
7737                      tiRoot,
7738                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
7739                      sizeof(tdIORequestBody_t)
7740                      );
7741 
7742     }
7743     else if (status == OSSA_IO_NOT_VALID)
7744     {
7745       TI_DBG1(("ossaSMPAbortCB: OSSA_IO_NOT_VALID\n"));
7746       ostiFreeMemory(
7747                      tiRoot,
7748                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
7749                      sizeof(tdIORequestBody_t)
7750                      );
7751     }
7752     else if (status == OSSA_IO_NO_DEVICE)
7753     {
7754       TI_DBG1(("ossaSMPAbortCB: OSSA_IO_NO_DEVICE\n"));
7755       ostiFreeMemory(
7756                      tiRoot,
7757                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
7758                      sizeof(tdIORequestBody_t)
7759                      );
7760     }
7761     else if (status == OSSA_IO_ABORT_IN_PROGRESS)
7762     {
7763       TI_DBG1(("ossaSMPAbortCB: OSSA_IO_ABORT_IN_PROGRESS\n"));
7764       ostiFreeMemory(
7765                      tiRoot,
7766                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
7767                      sizeof(tdIORequestBody_t)
7768                      );
7769     }
7770 #ifdef REMOVED
7771     else if (status == OSSA_IO_ABORT_DELAYED)
7772     {
7773       TI_DBG1(("ossaSMPAbortCB: OSSA_IO_ABORT_DELAYED\n"));
7774       ostiFreeMemory(
7775                      tiRoot,
7776                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
7777                      sizeof(tdIORequestBody_t)
7778                      );
7779     }
7780 #endif
7781     else
7782     {
7783       TI_DBG1(("ossaSMPAbortCB: other status %d\n", status));
7784       ostiFreeMemory(
7785                      tiRoot,
7786                      tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
7787                      sizeof(tdIORequestBody_t)
7788                      );
7789     }
7790   }
7791   else
7792   {
7793     TI_DBG1(("ossaSMPAbortCB: wrong flag %d\n", flag));
7794   }
7795 
7796 
7797   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yu");
7798   return;
7799 }
7800 
7801 /*****************************************************************************/
7802 /*! \brief ossaGeneralEvent
7803  *
7804  *
7805  *  Purpose: This is the event notification for debugging purposes sent to
7806  *           inform the OS layer of some general error related to a specific
7807  *           inbound operation.
7808  *
7809  *  \param   agRoot:              Pointer to chip/driver Instance.
7810  *  \param   status:              Status associated with this event
7811  *  \param   msg:                 Pointer to controller specific command
7812  *                                massage that caused the error
7813  *
7814  *  \return None.
7815  *
7816  */
7817 /*****************************************************************************/
7818 GLOBAL void ossaGeneralEvent(
7819                              agsaRoot_t    *agRoot,
7820                              bit32         status,
7821                              agsaContext_t *agContext,
7822                              bit32         *msg)
7823 {
7824   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
7825   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
7826 
7827   TI_DBG1(("ossaGeneralEvent: start\n"));
7828   TI_DBG1(("ossaGeneralEvent: status %d\n", status));
7829 
7830   if(msg)
7831   {
7832     TI_DBG1(("ossaGeneralEvent: *msg %X\n", *msg));
7833   }
7834 
7835   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yv");
7836   ostiGenEventIOCTLRsp(tiRoot, status);
7837   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yv");
7838   return;
7839 }
7840 
7841 GLOBAL void   ossaGetForensicDataCB (
7842         agsaRoot_t         *agRoot,
7843         agsaContext_t      *agContext,
7844         bit32              status,
7845         agsaForensicData_t *forensicData)
7846 {
7847   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
7848   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
7849 
7850   ostiGetForensicDataIOCTLRsp(tiRoot, status, forensicData);
7851   return;
7852 }
7853 
7854 
7855 #ifdef INITIATOR_DRIVER
7856 
7857 GLOBAL void ossaGetIOErrorStatsCB (
7858                       agsaRoot_t               *agRoot,
7859                       agsaContext_t            *agContext,
7860                       bit32                     status,
7861                       agsaIOErrorEventStats_t  *stats)
7862 
7863 {
7864   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
7865   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
7866 
7867   ostiGetIoErrorStatsIOCTLRsp(tiRoot, status, stats);
7868 }
7869 #else
7870 GLOBAL void ossaGetIOErrorStatsCB (
7871                       agsaRoot_t               *agRoot,
7872                       agsaContext_t            *agContext,
7873                       bit32                     status,
7874                       agsaIOErrorEventStats_t  *stats)
7875 
7876 {
7877 
7878 }
7879 
7880 #endif
7881 
7882 GLOBAL void ossaGetIOEventStatsCB (
7883                       agsaRoot_t               *agRoot,
7884                       agsaContext_t            *agContext,
7885                       bit32                     status,
7886                       agsaIOErrorEventStats_t  *stats)
7887 
7888 {
7889   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
7890   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
7891 
7892   ostiGetIoEventStatsIOCTLRsp(tiRoot, status, stats);
7893 }
7894 
7895 
7896 /*****************************************************************************/
7897 /*! \brief ossaGetRegisterDumpCB
7898  *
7899  *
7900  *  Purpose: ossaGetRegisterDumpCB() is the response callback function
7901  *           called by the LL Layer to indicate a response to
7902  *           saGetRegisterDump()
7903  *
7904  *  \param   agRoot:              Pointer to chip/driver Instance.
7905  *  \param   agContext:           Context of the operation originally
7906  *                                passed into saGetRegisterDump()
7907  *  \param   status:              status
7908  *
7909  *  \return None.
7910  *
7911  */
7912 /*****************************************************************************/
7913 GLOBAL void ossaGetRegisterDumpCB(
7914                                   agsaRoot_t    *agRoot,
7915                                   agsaContext_t *agContext,
7916                                   bit32         status
7917 )
7918 {
7919   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
7920   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
7921 
7922   TI_DBG4(("ossaGetRegisterDumpCB: start\n"));
7923   TI_DBG4(("ossaGetRegisterDumpCB: status %d\n", status));
7924   smTraceFuncEnter(hpDBG_VERY_LOUD,"Yw");
7925 
7926   ostiRegDumpIOCTLRsp(tiRoot, status);
7927   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "Yw");
7928   return;
7929 }
7930 
7931 /*****************************************************************************/
7932 /*! \brief ossaSetDeviceStateCB
7933  *
7934  *
7935  *  Purpose: ossaSetDeviceStateCB() is the response callback function
7936  *           called by the LL Layer to indicate a response to
7937  *           saSetDeviceState()
7938  *
7939  *  \param   agRoot:              Pointer to chip/driver Instance.
7940  *  \param   agContext:           Context of the operation originally
7941  *                                passed into saGetRegisterDump()
7942  *  \param   agDevHandle          Pointer to the device handle of the device
7943  *  \param   status:              status
7944  *  \param   newDeviceState:      newly set device status
7945  *  \param   previousDeviceState: old device status
7946  *
7947  *  \return None.
7948  *
7949  */
7950 /*****************************************************************************/
7951 GLOBAL void ossaSetDeviceStateCB(
7952                                  agsaRoot_t         *agRoot,
7953                                  agsaContext_t      *agContext,
7954                                  agsaDevHandle_t    *agDevHandle,
7955                                  bit32              status,
7956                                  bit32              newDeviceState,
7957                                  bit32              previousDeviceState
7958                                  )
7959 {
7960   tdsaDeviceData_t            *oneDeviceData = agNULL;
7961 
7962   TI_DBG2(("ossaSetDeviceStateCB: start\n"));
7963   TI_DBG2(("ossaSetDeviceStateCB: status %d\n", status));
7964   TI_DBG2(("ossaSetDeviceStateCB: newDeviceState %d\n", newDeviceState));
7965   TI_DBG2(("ossaSetDeviceStateCB: previousDeviceState %d\n", previousDeviceState));
7966 
7967   if (agDevHandle == agNULL)
7968   {
7969     TI_DBG4(("ossaSetDeviceStateCB: agDevHandle is NULL\n"));
7970     return;
7971   }
7972 
7973   oneDeviceData = (tdsaDeviceData_t *)agDevHandle->osData;
7974 
7975   if (oneDeviceData == agNULL)
7976   {
7977     TI_DBG1(("ossaSetDeviceStateCB: wrong; oneDeviceData is NULL\n"));
7978   }
7979   else
7980   {
7981     TI_DBG2(("ossaSetDeviceStateCB: did %d\n", oneDeviceData->id));
7982   }
7983 
7984   return;
7985 }
7986 
7987 /*****************************************************************************/
7988 /*! \brief ossaGetDeviceStateCB
7989  *
7990  *
7991  *  Purpose: ossaGetDeviceStateCB() is the response callback function
7992  *           called by the LL Layer to indicate a response to
7993  *           saGetDeviceState()
7994  *
7995  *  \param   agRoot:              Pointer to chip/driver Instance.
7996  *  \param   agContext:           Context of the operation originally
7997  *                                passed into saGetRegisterDump()
7998  *  \param   agDevHandle          Pointer to the device handle of the device
7999  *  \param   status:              status
8000  *  \param   deviceState:         device status
8001  *
8002  *  \return None.
8003  *
8004  */
8005 /*****************************************************************************/
8006 GLOBAL void ossaGetDeviceStateCB(
8007                                  agsaRoot_t         *agRoot,
8008                                  agsaContext_t      *agContext,
8009                                  agsaDevHandle_t    *agDevHandle,
8010                                  bit32              status,
8011                                  bit32              deviceState
8012                                  )
8013 {
8014   TI_DBG4(("ossaGetDeviceStateCB: start\n"));
8015   TI_DBG4(("ossaGetDeviceStateCB: status %d\n", status));
8016   TI_DBG4(("ossaGetDeviceStateCB: deviceState %d\n", deviceState));
8017 
8018   return;
8019 }
8020 
8021 #ifdef INITIATOR_DRIVER
8022 /*****************************************************************************/
8023 /*! \brief ossaIniSetDeviceInfoCB
8024  *
8025  *
8026  *  Purpose: ossaIniSetDeviceInfoCB() is the response callback function
8027  *           called by the LL Layer to indicate a response to
8028  *           saSetDeviceInfo()
8029  *
8030  *  \param   agRoot:              Pointer to chip/driver Instance.
8031  *  \param   agContext:           Context of the operation originally
8032  *                                passed into saSetDeviceInfo()
8033  *  \param   agDevHandle          Pointer to the device handle of the device
8034  *  \param   status:              status
8035  *  \param   option:              option parameter passed in saSetDeviceInfo()
8036  *  \param   param:               param parameter passed in saSetDeviceInfo()
8037  *
8038  *  \return None.
8039  *
8040  */
8041 /*****************************************************************************/
8042 osGLOBAL void
8043 ossaIniSetDeviceInfoCB(
8044                         agsaRoot_t        *agRoot,
8045                         agsaContext_t     *agContext,
8046                         agsaDevHandle_t   *agDevHandle,
8047                         bit32             status,
8048                         bit32             option,
8049                         bit32             param
8050                       )
8051 {
8052   tdsaRootOsData_t       *osData = (tdsaRootOsData_t *)agRoot->osData;
8053   tiRoot_t               *tiRoot = (tiRoot_t *)osData->tiRoot;
8054   tdsaRoot_t             *tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
8055   tdsaContext_t          *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
8056   itdsaIni_t             *Initiator = (itdsaIni_t *)tdsaAllShared->itdsaIni;
8057   bit32                  intContext = osData->IntContext;
8058   tdIORequestBody_t      *tdIORequestBody = agNULL;
8059   agsaIORequest_t        *agIORequest = agNULL;
8060   bit32                  saStatus = AGSA_RC_FAILURE;
8061   bit8                   devType_S_Rate;
8062   tdsaDeviceData_t       *oneDeviceData = agNULL;
8063 
8064   TI_DBG4(("ossaIniSetDeviceInfoCB: start\n"));
8065   TI_DBG4(("ossaIniSetDeviceInfoCB: status 0x%x\n", status));
8066   TI_DBG4(("ossaIniSetDeviceInfoCB: option 0x%x\n", option));
8067   TI_DBG4(("ossaIniSetDeviceInfoCB: param 0x%x\n", param));
8068 
8069   if (status != OSSA_SUCCESS)
8070   {
8071     TI_DBG1(("ossaIniSetDeviceInfoCB: status %d\n", status));
8072     TI_DBG1(("ossaIniSetDeviceInfoCB: option 0x%x\n", option));
8073     TI_DBG1(("ossaIniSetDeviceInfoCB: param 0x%x\n", param));
8074     if (option == 32) /* set connection rate */
8075     {
8076       TI_DBG1(("ossaIniSetDeviceInfoCB: IO failure\n"));
8077       agIORequest = (agsaIORequest_t *)agContext->osData;
8078       tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
8079       ostiInitiatorIOCompleted(
8080                                tiRoot,
8081                                tdIORequestBody->tiIORequest,
8082                                tiIOFailed,
8083                                tiDetailOtherError,
8084                                agNULL,
8085                                intContext
8086                                );
8087     }
8088   }
8089   if (agDevHandle == agNULL)
8090   {
8091     TI_DBG4(("ossaIniSetDeviceInfoCB: agDevHandle is NULL\n"));
8092     return;
8093   }
8094   oneDeviceData = (tdsaDeviceData_t *)agDevHandle->osData;
8095   if (oneDeviceData == agNULL)
8096   {
8097     TI_DBG1(("ossaIniSetDeviceInfoCB: wrong; oneDeviceData is NULL\n"));
8098     return;
8099   }
8100   else
8101   {
8102     TI_DBG4(("ossaIniSetDeviceInfoCB: did %d\n", oneDeviceData->id));
8103   }
8104 
8105   /* retry IOs */
8106   if (option == 32) /* set connection rate */
8107   {
8108     TI_DBG1(("ossaIniSetDeviceInfoCB: set connection rate option\n"));
8109     agIORequest = (agsaIORequest_t *)agContext->osData;
8110     tdIORequestBody = (tdIORequestBody_t *)agIORequest->osData;
8111     devType_S_Rate = oneDeviceData->agDeviceInfo.devType_S_Rate;
8112     devType_S_Rate = (devType_S_Rate & 0xF0) | (param >> 28);
8113     oneDeviceData->agDeviceInfo.devType_S_Rate =  devType_S_Rate;
8114     TI_DBG1(("ossaIniSetDeviceInfoCB: new rate is 0x%x\n", DEVINFO_GET_LINKRATE(&oneDeviceData->agDeviceInfo)));
8115     if (oneDeviceData->valid == agTRUE && oneDeviceData->registered == agTRUE &&
8116         oneDeviceData->tdPortContext != agNULL )
8117     {
8118       saStatus = saSSPStart(agRoot,
8119                             agIORequest,
8120                             tdsaRotateQnumber(tiRoot, oneDeviceData),
8121                             agDevHandle,
8122                             tdIORequestBody->agRequestType,
8123                             &(tdIORequestBody->transport.SAS.agSASRequestBody),
8124                             agNULL,
8125                             &ossaSSPCompleted);
8126       if (saStatus == AGSA_RC_SUCCESS)
8127       {
8128         TI_DBG1(("ossaIniSetDeviceInfoCB: retried\n"));
8129         Initiator->NumIOsActive++;
8130         tdIORequestBody->ioStarted = agTRUE;
8131         tdIORequestBody->ioCompleted = agFALSE;
8132         return;
8133       }
8134       else
8135       {
8136         TI_DBG1(("ossaIniSetDeviceInfoCB: retry failed\n"));
8137         tdIORequestBody->ioStarted = agFALSE;
8138         tdIORequestBody->ioCompleted = agTRUE;
8139         ostiInitiatorIOCompleted(
8140                                  tiRoot,
8141                                  tdIORequestBody->tiIORequest,
8142                                  tiIOFailed,
8143                                  tiDetailOtherError,
8144                                  agNULL,
8145                                  intContext
8146                                  );
8147        }
8148     }
8149   }
8150   return;
8151 }
8152 #endif
8153 /*****************************************************************************/
8154 /*! \brief ossaSetDeviceInfoCB
8155  *
8156  *
8157  *  Purpose: ossaSetDeviceInfoCB() is the response callback function
8158  *           called by the LL Layer to indicate a response to
8159  *           saSetDeviceInfo()
8160  *
8161  *  \param   agRoot:              Pointer to chip/driver Instance.
8162  *  \param   agContext:           Context of the operation originally
8163  *                                passed into saSetDeviceInfo()
8164  *  \param   agDevHandle          Pointer to the device handle of the device
8165  *  \param   status:              status
8166  *  \param   option:              option parameter passed in saSetDeviceInfo()
8167  *  \param   param:               param parameter passed in saSetDeviceInfo()
8168  *
8169  *  \return None.
8170  *
8171  */
8172 /*****************************************************************************/
8173 GLOBAL void ossaSetDeviceInfoCB(
8174                                  agsaRoot_t         *agRoot,
8175                                  agsaContext_t      *agContext,
8176                                  agsaDevHandle_t    *agDevHandle,
8177                                  bit32              status,
8178                                  bit32              option,
8179                                  bit32              param
8180                                 )
8181 {
8182   tdsaDeviceData_t       *oneDeviceData = agNULL;
8183 
8184   TI_DBG4(("ossaSetDeviceInfoCB: start\n"));
8185   TI_DBG4(("ossaSetDeviceInfoCB: status 0x%x\n", status));
8186   TI_DBG4(("ossaSetDeviceInfoCB: option 0x%x\n", option));
8187   TI_DBG4(("ossaSetDeviceInfoCB: param 0x%x\n", param));
8188 
8189   if (status != OSSA_SUCCESS)
8190   {
8191     TI_DBG1(("ossaSetDeviceInfoCB: status %d\n", status));
8192     TI_DBG1(("ossaSetDeviceInfoCB: option 0x%x\n", option));
8193     TI_DBG1(("ossaSetDeviceInfoCB: param 0x%x\n", param));
8194   }
8195 
8196   if (agDevHandle == agNULL)
8197   {
8198     TI_DBG4(("ossaSetDeviceInfoCB: agDevHandle is NULL\n"));
8199     return;
8200   }
8201 
8202   oneDeviceData = (tdsaDeviceData_t *)agDevHandle->osData;
8203 
8204   if (oneDeviceData == agNULL)
8205   {
8206     TI_DBG1(("ossaSetDeviceInfoCB: wrong; oneDeviceData is NULL\n"));
8207   }
8208   else
8209   {
8210     TI_DBG4(("ossaSetDeviceInfoCB: did %d\n", oneDeviceData->id));
8211   }
8212 
8213   return;
8214 }
8215 
8216 /*****************************************************************************/
8217 /*! \brief ossaGetDFEDataCB
8218  *
8219  *
8220  *  Purpose: ossaGetDFEDataCB() is the response callback function
8221  *           called by the LL Layer to indicate a response to
8222  *           saGetDFEData()
8223  *
8224  *  \param   agRoot:              Pointer to chip/driver Instance.
8225  *  \param   agContext:           Context of the operation originally
8226  *                                passed into saGetDFEData()
8227  *  \param   status:              status
8228  *  \param   agInfoLen:           length in bytes of DFE data captured and transferred
8229  *
8230  *  \return None.
8231  *
8232  */
8233 /*****************************************************************************/
8234 GLOBAL void ossaGetDFEDataCB(
8235                              agsaRoot_t     *agRoot,
8236                              agsaContext_t  *agContext,
8237                              bit32   status,
8238                              bit32   agInfoLen)
8239 {
8240   TI_DBG1(("ossaGetDFEDataCB: start\n"));
8241   TI_DBG1(("ossaGetDFEDataCB: status 0x%x agInfoLen 0x%x\n", status, agInfoLen));
8242   return;
8243 }
8244 
8245 /*****************************************************************************/
8246 /*! \brief ossaVhistCaptureCB
8247  *
8248  *
8249  *  Purpose: ossaVhistCaptureCB() is the response callback function
8250  *           called by the LL Layer to indicate a response to
8251  *           saGetDFEData()
8252  *
8253  *  \param   agRoot:              Pointer to chip/driver Instance.
8254  *  \param   agContext:           Context of the operation originally
8255  *                                passed into ()
8256  *  \param   status:              status
8257  *  \param   len:           length in bytes of Vis data captured and transferred
8258  *
8259  *  \return None.
8260  *
8261  */
8262 /*****************************************************************************/
8263 
8264 void ossaVhistCaptureCB(
8265         agsaRoot_t    *agRoot,
8266         agsaContext_t *agContext,
8267         bit32         status,
8268         bit32         len)
8269 {
8270   TI_DBG1(("ossaVhistCaptureCB: start\n"));
8271   TI_DBG1(("ossaVhistCaptureCB: status 0x%x agInfoLen 0x%x\n", status,len ));
8272   return;
8273 }
8274 
8275 GLOBAL void ossaOperatorManagementCB(
8276                   agsaRoot_t    *agRoot,
8277                   agsaContext_t *agContext,
8278                   bit32          status,
8279                   bit32          eq
8280                   )
8281 {
8282   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
8283   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
8284   tiEncryptPort_t      encryptEventData;
8285 
8286   TI_DBG1(("ossaOperatorManagementCB: status 0x%x eq 0x%x\n", status, eq));
8287 
8288   osti_memset(&encryptEventData, 0, sizeof(tiEncryptPort_t));
8289   encryptEventData.encryptEvent = tiEncryptOperatorManagement;
8290   encryptEventData.subEvent = eq;
8291   encryptEventData.pData = agNULL;
8292 
8293   ostiPortEvent(tiRoot,
8294               tiEncryptOperation,
8295               status,
8296               &encryptEventData);
8297 }
8298 
8299 GLOBAL void ossaEncryptSelftestExecuteCB (
8300                         agsaRoot_t    *agRoot,
8301                         agsaContext_t *agContext,
8302                         bit32          status,
8303                         bit32          type,
8304                         bit32          length,
8305                         void          *TestResult
8306                         )
8307 {
8308   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
8309   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
8310   tiEncryptPort_t      encryptEventData;
8311 
8312   TI_DBG1(("ossaEncryptSelftestExecuteCB: status 0x%x type 0x%x length 0x%x\n", status, type, length));
8313 
8314   osti_memset(&encryptEventData, 0, sizeof(tiEncryptPort_t));
8315   encryptEventData.encryptEvent = tiEncryptSelfTest;
8316   encryptEventData.subEvent = type;
8317   encryptEventData.pData = (void*)TestResult;
8318 
8319   ostiPortEvent(tiRoot,
8320               tiEncryptOperation,
8321               status,
8322               &encryptEventData);
8323 }
8324 
8325 GLOBAL void ossaGetOperatorCB(
8326                agsaRoot_t    *agRoot,
8327                agsaContext_t *agContext,
8328                bit32          status,
8329                bit32          option,
8330                bit32          num,
8331                bit32          role,
8332                agsaID_t      *id
8333                )
8334 {
8335 
8336   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
8337   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
8338   tiEncryptPort_t      encryptEventData;
8339 
8340   TI_DBG1(("ossaGetOperatorCB: status 0x%x option 0x%x num 0x%x role 0x%x\n",
8341                 status, option, num, role));
8342   TI_DBG1(("ossaGetOperatorCB: agContext %p id %p\n",agContext,id));
8343   osti_memset(&encryptEventData, 0, sizeof(tiEncryptPort_t));
8344   encryptEventData.encryptEvent = tiEncryptGetOperator;
8345   encryptEventData.subEvent = option;
8346   encryptEventData.pData = agNULL;
8347 
8348   switch(status)
8349   {
8350     case OSSA_IO_SUCCESS:
8351       TI_DBG1(("ossaGetOperatorCB: OSSA_IO_SUCCESS option 0x%x\n", option));
8352       if(option == 1)
8353       {
8354         TI_DBG2(("ossaGetOperatorCB: 0x%02x 0x%02x 0x%02x 0x%02x\n",id->ID[0], id->ID[1], id->ID[2], id->ID[3]));
8355         TI_DBG2(("ossaGetOperatorCB: 0x%02x 0x%02x 0x%02x 0x%02x\n",id->ID[4], id->ID[5], id->ID[6], id->ID[7]));
8356         TI_DBG2(("ossaGetOperatorCB: 0x%02x 0x%02x 0x%02x 0x%02x\n",id->ID[8], id->ID[9], id->ID[10],id->ID[11]));
8357         TI_DBG2(("ossaGetOperatorCB: 0x%02x 0x%02x 0x%02x 0x%02x\n",id->ID[12],id->ID[13],id->ID[14],id->ID[15]));
8358         TI_DBG2(("ossaGetOperatorCB: 0x%02x 0x%02x 0x%02x 0x%02x\n",id->ID[16],id->ID[17],id->ID[18],id->ID[19]));
8359         TI_DBG2(("ossaGetOperatorCB: 0x%02x 0x%02x 0x%02x 0x%02x\n",id->ID[20],id->ID[21],id->ID[22],id->ID[23]));
8360         TI_DBG2(("ossaGetOperatorCB: 0x%02x 0x%02x 0x%02x 0x%02x\n",id->ID[24],id->ID[25],id->ID[26],id->ID[27]));
8361         TI_DBG2(("ossaGetOperatorCB: 0x%02x 0x%02x 0x%02x\n",       id->ID[28],id->ID[29],id->ID[30]));
8362       }else if(option == 2)
8363       {
8364         TI_DBG1(("ossaGetOperatorCB: number operators 0x%02x\n", num ));
8365       }
8366 
8367       encryptEventData.pData = id;
8368       break;
8369     case OSSA_MPI_ENC_ERR_UNSUPPORTED_OPTION:
8370       TI_DBG1(("ossaGetOperatorCB: OSSA_MPI_ENC_ERR_UNSUPPORTED_OPTION 0x%x\n",option));
8371       break;
8372     case OSSA_MPI_ENC_ERR_ID_TRANSFER_FAILURE:
8373       TI_DBG1(("ossaGetOperatorCB: OSSA_MPI_ENC_ERR_ID_TRANSFER_FAILURE 0x%x\n",option));
8374       break;
8375     default:
8376       TI_DBG1(("ossaGetOperatorCB: Unknown status 0x%x\n",status));
8377   }
8378   ostiPortEvent(tiRoot,
8379               tiEncryptOperation,
8380               status,
8381               &encryptEventData);
8382 
8383 }
8384 
8385 GLOBAL void ossaSetOperatorCB(
8386               agsaRoot_t    *agRoot,
8387               agsaContext_t *agContext,
8388               bit32          status,
8389               bit32          eq
8390               )
8391 {
8392   tdsaRootOsData_t    *osData = (tdsaRootOsData_t *)agRoot->osData;
8393   tiRoot_t            *tiRoot = (tiRoot_t *)osData->tiRoot;
8394   tiEncryptPort_t      encryptEventData;
8395 
8396   TI_DBG1(("ossaSetOperatorCB: agContext %p status 0x%x eq 0x%x\n",agContext, status, eq));
8397 
8398   osti_memset(&encryptEventData, 0, sizeof(tiEncryptPort_t));
8399   encryptEventData.encryptEvent = tiEncryptSetOperator;
8400   encryptEventData.subEvent = 0;
8401   switch(status)
8402   {
8403     case OSSA_IO_SUCCESS:
8404       TI_DBG1(("ossaSetOperatorCB: OSSA_IO_SUCCESS\n"));
8405       encryptEventData.pData = agNULL;
8406       break;
8407     case OSSA_MPI_ENC_ERR_CONTROLLER_NOT_IDLE:
8408       TI_DBG1(("ossaSetOperatorCB: OSSA_MPI_ENC_ERR_CONTROLLER_NOT_IDLE\n"));
8409       break;
8410     case OSSA_MPI_ENC_OPERATOR_AUTH_FAILURE:
8411       TI_DBG1(("ossaSetOperatorCB: OSSA_MPI_ENC_OPERATOR_AUTH_FAILURE error qualifier 0x%x\n",eq));
8412       break;
8413     case OSSA_MPI_ENC_OPERATOR_OPERATOR_ALREADY_LOGGED_IN:
8414       TI_DBG1(("ossaSetOperatorCB: OSSA_MPI_ENC_OPERATOR_OPERATOR_ALREADY_LOGGED_IN\n"));
8415       break;
8416     case OSSA_MPI_ENC_OPERATOR_ILLEGAL_PARAMETER:
8417       TI_DBG1(("ossaSetOperatorCB: OSSA_MPI_ENC_OPERATOR_ILLEGAL_PARAMETER\n"));
8418       break;
8419     case OSSA_MPI_ENC_ERR_UNSUPPORTED_OPTION:
8420       TI_DBG1(("ossaSetOperatorCB: OSSA_MPI_ENC_ERR_UNSUPPORTED_OPTION\n"));
8421       break;
8422     case OSSA_MPI_ENC_ERR_ID_TRANSFER_FAILURE:
8423       TI_DBG1(("ossaSetOperatorCB: OSSA_MPI_ENC_ERR_ID_TRANSFER_FAILURE\n"));
8424       break;
8425     default:
8426       TI_DBG1(("ossaGetOperatorCB: Unknown status 0x%x\n",status));
8427   }
8428   ostiPortEvent(tiRoot,
8429               tiEncryptOperation,
8430               status,
8431               &encryptEventData);
8432 }
8433 
8434 GLOBAL void ossaDIFEncryptionOffloadStartCB(
8435                              agsaRoot_t     *agRoot,
8436                              agsaContext_t  *agContext,
8437                              bit32   status,
8438                              agsaOffloadDifDetails_t *agsaOffloadDifDetails)
8439 {
8440   TI_DBG1(("ossaDIFEncryptionOffloadStartCB: start\n"));
8441   TI_DBG1(("ossaDIFEncryptionOffloadStartCB: status 0x%x agsaOffloadDifDetails=%p\n", status, agsaOffloadDifDetails));
8442   return;
8443 }
8444 
8445 GLOBAL bit32 ossaTimeStamp( agsaRoot_t     *agRoot )
8446 {
8447   tdsaRootOsData_t    *osData= agNULL;
8448   tiRoot_t            *tiRoot= agNULL;
8449   if(agRoot)
8450   {
8451     osData = (tdsaRootOsData_t *)agRoot->osData;
8452   }
8453   if(osData)
8454   {
8455     tiRoot = (tiRoot_t *)osData->tiRoot;
8456   }
8457   return(ostiTimeStamp(tiRoot));
8458 }
8459 
8460 GLOBAL bit64 ossaTimeStamp64( agsaRoot_t     *agRoot)
8461 {
8462   tdsaRootOsData_t    *osData= agNULL;
8463   tiRoot_t            *tiRoot= agNULL;
8464   if(agRoot)
8465   {
8466     osData = (tdsaRootOsData_t *)agRoot->osData;
8467   }
8468   if(osData)
8469   {
8470     tiRoot = (tiRoot_t *)osData->tiRoot;
8471   }
8472   return(ostiTimeStamp64(tiRoot));
8473 }
8474 
8475 #ifdef FDS_SM
8476 osGLOBAL void
8477 tdIDStartTimer(tiRoot_t                 *tiRoot,
8478                   smIORequest_t            *smIORequest,
8479                   tdsaDeviceData_t         *oneDeviceData
8480                   )
8481 {
8482   tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
8483   tdsaContext_t               *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
8484   itdsaIni_t                  *Initiator = (itdsaIni_t *)tdsaAllShared->itdsaIni;
8485 
8486   TI_DBG1(("tdIDStartTimer: start\n"));
8487 
8488   tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK);
8489   if (oneDeviceData->tdIDTimer.timerRunning == agTRUE)
8490   {
8491     tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
8492     tdsaKillTimer(
8493                   tiRoot,
8494                   &oneDeviceData->tdIDTimer
8495                   );
8496   }
8497   else
8498   {
8499     tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
8500   }
8501 
8502   tdsaSetTimerRequest(
8503                       tiRoot,
8504                       &oneDeviceData->tdIDTimer,
8505                       SATA_ID_DEVICE_DATA_TIMER_VALUE/Initiator->OperatingOption.UsecsPerTick,
8506                       tdIDStartTimerCB,
8507                       smIORequest,
8508                       oneDeviceData,
8509                       agNULL
8510                      );
8511 
8512   tdsaAddTimer(
8513                tiRoot,
8514                &Initiator->timerlist,
8515                &oneDeviceData->tdIDTimer
8516               );
8517   TI_DBG1(("tdIDStartTimer: end\n"));
8518   return;
8519 }
8520 
8521 osGLOBAL void
8522 tdIDStartTimerCB(
8523                   tiRoot_t    * tiRoot,
8524                   void        * timerData1,
8525                   void        * timerData2,
8526                   void        * timerData3
8527                 )
8528 {
8529   tdsaRoot_t         *tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
8530   tdsaContext_t      *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
8531   smIORequest_t      *smIORequest;
8532   tdsaDeviceData_t   *oneDeviceData;
8533   smRoot_t           *smRoot;
8534   tdIORequestBody_t  *tdIORequestBody;
8535   smDeviceHandle_t   *smDeviceHandle;
8536   tdsaPortContext_t  *onePortContext;
8537 #ifdef REMOVED
8538   agsaRoot_t         *agRoot;
8539   bit32               IDstatus;
8540 //#endif
8541 //#ifdef REMOVED
8542   agsaIORequest_t    *agAbortIORequest = agNULL;
8543   tdIORequestBody_t  *tdAbortIORequestBody = agNULL;
8544   bit32               PhysUpper32;
8545   bit32               PhysLower32;
8546   bit32               memAllocStatus;
8547   void               *osMemHandle;
8548 #endif // REMOVED
8549 #ifdef  TD_DEBUG_ENABLE
8550   bit32               status = AGSA_RC_FAILURE;
8551 #endif
8552 
8553   TI_DBG1(("tdIDStartTimerCB start\n"));
8554   smIORequest = (smIORequest_t *)timerData1;
8555   oneDeviceData = (tdsaDeviceData_t *)timerData2;
8556   smRoot = &(tdsaAllShared->smRoot);
8557 #ifdef REMOVED
8558   agRoot = oneDeviceData->agRoot;
8559 #endif // REMOVED
8560 
8561   if (smIORequest == agNULL)
8562   {
8563     TI_DBG1(("tdIDStartTimerCB: smIORequest == agNULL !!!!!!\n"));
8564     return;
8565   }
8566 
8567   if (oneDeviceData == agNULL)
8568   {
8569     TI_DBG1(("tdIDStartTimerCB: oneDeviceData == agNULL !!!!!!\n"));
8570     return;
8571   }
8572 
8573   if (oneDeviceData->satDevData.IDPending == agFALSE || oneDeviceData->satDevData.IDDeviceValid == agTRUE)
8574   {
8575      /*the Identify Device command already normally completed, just return*/
8576      return;
8577   }
8578 
8579   tdIORequestBody = (tdIORequestBody_t *)smIORequest->tdData;
8580   smDeviceHandle = (smDeviceHandle_t *)&(oneDeviceData->smDeviceHandle);
8581   onePortContext = oneDeviceData->tdPortContext;
8582   if (tdIORequestBody == agNULL)
8583   {
8584     TI_DBG1(("tdIDStartTimerCB: tdIORequestBody == agNULL !!!!!!\n"));
8585     return;
8586   }
8587 
8588   if (smDeviceHandle == agNULL)
8589   {
8590     TI_DBG1(("tdIDStartTimerCB: smDeviceHandle == agNULL !!!!!!\n"));
8591     return;
8592   }
8593 
8594   if (onePortContext == agNULL)
8595   {
8596     TI_DBG1(("tdIDStartTimerCB: onePortContext == agNULL !!!!!!\n"));
8597     return;
8598   }
8599 
8600   TI_DBG1(("tdIDStartTimerCB: did %d\n", oneDeviceData->id));
8601   /*
8602    1. smIOabort()
8603    2. in tdsmIDCompletedCB(), retry
8604   */
8605   if (oneDeviceData->valid == agFALSE)
8606   {
8607     TI_DBG1(("tdIDStartTimerCB: invalid device\n"));
8608     return;
8609   }
8610 #ifdef  TD_DEBUG_ENABLE
8611   status = smIOAbort( smRoot, smIORequest );
8612 #else
8613   smIOAbort( smRoot, smIORequest );
8614 #endif
8615 
8616 #ifdef REMOVED
8617   /* allocating agIORequest for abort itself */
8618   memAllocStatus = ostiAllocMemory(
8619                                    tiRoot,
8620                                    &osMemHandle,
8621                                    (void **)&tdAbortIORequestBody,
8622                                    &PhysUpper32,
8623                                    &PhysLower32,
8624                                    8,
8625                                    sizeof(tdIORequestBody_t),
8626                                    agTRUE
8627                                    );
8628   if (memAllocStatus != tiSuccess)
8629   {
8630     /* let os process IO */
8631     TI_DBG1(("tdIDStartTimerCB: ostiAllocMemory failed...; can't retry ID data \n"));
8632     return;
8633   }
8634   if (tdAbortIORequestBody == agNULL)
8635   {
8636     /* let os process IO */
8637     TI_DBG1(("tdIDStartTimerCB: ostiAllocMemory returned NULL tdAbortIORequestBody; can't retry ID data\n"));
8638     return;
8639   }
8640   /* setup task management structure */
8641   tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle = osMemHandle;
8642   /* setting callback but not used later */
8643   tdAbortIORequestBody->IOCompletionFunc = agNULL;
8644   //tdAbortIORequestBody->IOCompletionFunc = itdssIOAbortedHandler;
8645   tdAbortIORequestBody->tiDevHandle = (tiDeviceHandle_t *)&(oneDeviceData->tiDeviceHandle);
8646   /* initialize agIORequest */
8647   agAbortIORequest = &(tdAbortIORequestBody->agIORequest);
8648   agAbortIORequest->osData = (void *) tdAbortIORequestBody;
8649   agAbortIORequest->sdkData = agNULL; /* LL takes care of this */
8650 //#endif
8651 //#ifdef REMOVED
8652   status = saSATAAbort(agRoot,
8653                        agAbortIORequest,
8654                        0,
8655                        oneDeviceData->agDevHandle,
8656                        1, /* abort all */
8657                        agNULL,
8658                        ossaSATAIDAbortCB
8659                        );
8660   status = saSATAAbort(agRoot,
8661                        agAbortIORequest,
8662                        0,
8663                        oneDeviceData->agDevHandle,
8664                        0, /* abort one */
8665                        agIORequest,
8666                        ossaSATAIDAbortCB
8667                        );
8668 //#endif
8669 //#ifdef REMOVED
8670   if (status != AGSA_RC_SUCCESS)
8671   {
8672     TI_DBG1(("tdIDStartTimerCB: saSATAAbort failed; can't retry ID data\n"));
8673   }
8674   if (oneDeviceData->satDevData.IDDeviceValid == agTRUE)
8675   {
8676     TI_DBG1(("tdIDStartTimerCB: IDDeviceValid is valid, no need to retry\n"));
8677     return;
8678   }
8679   if (tdIORequestBody->reTries <= SM_RETRIES)
8680   {
8681     tdIORequestBody->tiIORequest = agNULL; /* not in use */
8682     tdIORequestBody->pid = onePortContext->id;
8683     smIORequest->tdData = tdIORequestBody;
8684     smIORequest->smData = &tdIORequestBody->smIORequestBody;
8685     smDeviceHandle->tdData = oneDeviceData;
8686     IDstatus = smIDStart(smRoot, smIORequest, smDeviceHandle );
8687     if (IDstatus == SM_RC_SUCCESS)
8688     {
8689       TI_DBG1(("tdIDStartTimerCB: being retried!!!\n"));
8690       tdIORequestBody->reTries++;
8691       tdIORequestBody->ioCompleted = agFALSE;
8692       tdIORequestBody->ioStarted = agTRUE;
8693       tdIDStartTimer(tiRoot, smIORequest, oneDeviceData);
8694     }
8695     else
8696     {
8697       /* identify device data is not valid */
8698       TI_DBG1(("tdIDStartTimerCB: smIDStart fail or busy %d!!!\n", IDstatus));
8699       tdIORequestBody->reTries = 0;
8700       tdIORequestBody->ioCompleted = agTRUE;
8701       tdIORequestBody->ioStarted = agFALSE;
8702       ostiFreeMemory( tiRoot,
8703                       tdIORequestBody->osMemHandle,
8704                       sizeof(tdIORequestBody_t)
8705                     );
8706       oneDeviceData->satDevData.IDDeviceValid = agFALSE;
8707       smReportRemoval(tiRoot, agRoot, oneDeviceData, onePortContext);
8708       return;
8709     }
8710   }
8711   else
8712   {
8713     /* give up */
8714     TI_DBG1(("tdIDStartTimerCB: retries are over!!!\n"));
8715     if (oneDeviceData->tdIDTimer.timerRunning == agTRUE)
8716     {
8717       tdsaKillTimer( tiRoot, &oneDeviceData->tdIDTimer );
8718     }
8719     tdIORequestBody->reTries = 0;
8720     tdIORequestBody->ioCompleted = agTRUE;
8721     tdIORequestBody->ioStarted = agFALSE;
8722     ostiFreeMemory(
8723                    tiRoot,
8724                    tdIORequestBody->osMemHandle,
8725                    sizeof(tdIORequestBody_t)
8726             );
8727     oneDeviceData->satDevData.IDDeviceValid = agFALSE;
8728 
8729     if (oneDeviceData->SMNumOfID <= 0) /* does SMP HARD RESET only upto one time */
8730     {
8731       TI_DBG1(("tdIDStartTimerCB: fail; sending HARD_RESET\n"));
8732       oneDeviceData->SMNumOfID++;
8733       if (oneDeviceData->directlyAttached == agTRUE)
8734       {
8735         saLocalPhyControl(agRoot, agNULL, 0, oneDeviceData->phyID, AGSA_PHY_HARD_RESET, agNULL);
8736       }
8737       else
8738       {
8739         tdsaPhyControlSend(tiRoot,
8740                            oneDeviceData,
8741                            SMP_PHY_CONTROL_HARD_RESET,
8742                            agNULL);
8743       }
8744     }
8745     else
8746     {
8747       /* given up after one time of SMP HARD RESET; */
8748       TI_DBG1(("tdIDStartTimerCB: fail; but giving up sending HARD_RESET!!!\n"));
8749       if (oneDeviceData->directlyAttached == agTRUE)
8750       {
8751         smReportRemovalDirect(tiRoot, agRoot, oneDeviceData);
8752       }
8753       else
8754       {
8755         smReportRemoval(tiRoot, agRoot, oneDeviceData, onePortContext);
8756       }
8757     }
8758   }
8759 #endif // REMOVED
8760 
8761   TI_DBG1(("tdIDStartTimerCB: end, smIOAbort status %d\n", status));
8762   return;
8763 }
8764 #endif // FDS_SM
8765 
8766 
8767 #if defined(FDS_DM) && defined(FDS_SM)
8768 //start here
8769 GLOBAL void
8770 tdIDStart(
8771            tiRoot_t             *tiRoot,
8772            agsaRoot_t           *agRoot,
8773            smRoot_t             *smRoot,
8774            tdsaDeviceData_t     *oneDeviceData,
8775            tdsaPortContext_t    *onePortContext
8776           )
8777 {
8778   tdsaRoot_t           *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
8779   tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
8780   bit32                SMstatus = SM_RC_FAILURE;
8781   tdIORequestBody_t    *tdIORequestBody;
8782   smIORequest_t        *smIORequest;
8783   smDeviceHandle_t     *smDeviceHandle;
8784   bit32                PhysUpper32;
8785   bit32                PhysLower32;
8786   bit32                memAllocStatus;
8787   void                 *osMemHandle;
8788 
8789 
8790   TI_DBG1(("tdIDStart: start, did %d\n",oneDeviceData->id));
8791 
8792   if ( (DEVICE_IS_SATA_DEVICE(oneDeviceData)|| DEVICE_IS_STP_TARGET(oneDeviceData))
8793       &&
8794       oneDeviceData->satDevData.IDDeviceValid == agFALSE
8795       &&
8796       oneDeviceData->satDevData.IDPending == agFALSE
8797       )
8798   {
8799     TI_DBG2(("tdIDStart: in loop, did %d\n", oneDeviceData->id));
8800     /* allocating tdIORequestBody */
8801     memAllocStatus = ostiAllocMemory(
8802                                       tiRoot,
8803                                       &osMemHandle,
8804                                       (void **)&tdIORequestBody,
8805                                       &PhysUpper32,
8806                                       &PhysLower32,
8807                                       8,
8808                                       sizeof(tdIORequestBody_t),
8809                                       agTRUE
8810                                     );
8811     if (memAllocStatus != tiSuccess || tdIORequestBody == agNULL)
8812     {
8813       /* let os process IO */
8814       TI_DBG1(("tdIDStart: ostiAllocMemory failed... or ostiAllocMemory returned NULL tdIORequestBody!!!\n"));
8815       oneDeviceData->satDevData.IDDeviceValid = agFALSE;
8816       if (oneDeviceData->directlyAttached == agTRUE)
8817       {
8818         /* notifying link up */
8819         ostiPortEvent(
8820                        tiRoot,
8821                        tiPortLinkUp,
8822                        tiSuccess,
8823                        (void *)onePortContext->tiPortalContext
8824                      );
8825 #ifdef INITIATOR_DRIVER
8826         /* triggers discovery */
8827         ostiPortEvent(
8828                        tiRoot,
8829                        tiPortDiscoveryReady,
8830                        tiSuccess,
8831                        (void *) onePortContext->tiPortalContext
8832                      );
8833 #endif
8834       }
8835     }
8836     else
8837     {
8838       /* initialize */
8839       osti_memset(tdIORequestBody, 0, sizeof(tdIORequestBody_t));
8840 
8841       tdIORequestBody->osMemHandle = osMemHandle;
8842       TI_DBG2(("tdIDStart: tdIORequestBody %p  tdIORequestBody->osMemHandle %p\n", tdIORequestBody, tdIORequestBody->osMemHandle));
8843 
8844       /* not in use */
8845       tdIORequestBody->IOCompletionFunc = agNULL;
8846       tdIORequestBody->tiDevHandle = agNULL;
8847 
8848       tdIORequestBody->tiIORequest = agNULL; /* not in use */
8849       tdIORequestBody->pid = onePortContext->id;
8850       tdIORequestBody->reTries = 0;
8851       smIORequest = (smIORequest_t *)&(tdIORequestBody->smIORequest);
8852       smIORequest->tdData = tdIORequestBody;
8853       smIORequest->smData = &tdIORequestBody->smIORequestBody;
8854 
8855       smDeviceHandle = (smDeviceHandle_t *)&(oneDeviceData->smDeviceHandle);
8856       smDeviceHandle->tdData = oneDeviceData;
8857 
8858       TI_DBG2(("tdIDStart: smIORequest %p\n", smIORequest));
8859 
8860       SMstatus = smIDStart(smRoot,
8861                            smIORequest,
8862                            &(oneDeviceData->smDeviceHandle)
8863                            );
8864 
8865       if (SMstatus == SM_RC_SUCCESS)
8866       {
8867         if (oneDeviceData->directlyAttached == agTRUE)
8868         {
8869           TI_DBG2(("tdIDStart: successfully sent identify device data\n"));
8870 
8871           /* Add the devicedata to the mainlink */
8872           tdsaSingleThreadedEnter(tiRoot, TD_DEVICE_LOCK);
8873           TDLIST_ENQUEUE_AT_TAIL(&(oneDeviceData->MainLink), &(tdsaAllShared->MainDeviceList));
8874           tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
8875           TI_DBG6(("tdIDStart: one case did %d \n", oneDeviceData->id));
8876         }
8877         oneDeviceData->satDevData.IDPending = agTRUE;
8878         /* start a timer */
8879         tdIDStartTimer(tiRoot, smIORequest, oneDeviceData);
8880       }
8881       else
8882       {
8883         /* failed to send  */
8884         TI_DBG1(("tdIDStart: smIDStart fail or busy %d\n", SMstatus));
8885 
8886         /* free up allocated memory */
8887         ostiFreeMemory(
8888                    tiRoot,
8889                    tdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
8890                    sizeof(tdIORequestBody_t)
8891                    );
8892 
8893         oneDeviceData->satDevData.IDDeviceValid = agFALSE;
8894         if (oneDeviceData->directlyAttached == agTRUE)
8895         {
8896           TI_DBG1(("tdIDStart: failed in sending identify device data\n"));
8897           /* put onedevicedata back to free list */
8898           tdsaSingleThreadedEnter(tiRoot, TD_DEVICE_LOCK);
8899           TDLIST_ENQUEUE_AT_TAIL(&(oneDeviceData->FreeLink), &(tdsaAllShared->FreeDeviceList));
8900           tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
8901           /* notifying link up */
8902           ostiPortEvent(
8903                          tiRoot,
8904                          tiPortLinkUp,
8905                          tiSuccess,
8906                          (void *)onePortContext->tiPortalContext
8907                        );
8908 #ifdef INITIATOR_DRIVER
8909           /* triggers discovery */
8910           ostiPortEvent(
8911                          tiRoot,
8912                          tiPortDiscoveryReady,
8913                          tiSuccess,
8914                          (void *) onePortContext->tiPortalContext
8915                        );
8916 #endif
8917         }
8918         else
8919         {
8920           smReportRemoval(tiRoot, agRoot, oneDeviceData, onePortContext);
8921         }
8922       }
8923     }
8924   }
8925   TI_DBG1(("tdIDStart: exit\n"));
8926   return;
8927 }
8928 
8929 #endif
8930 
8931 #ifdef SALLSDK_OS_IOMB_LOG_ENABLE
8932 GLOBAL void ossaLogIomb(agsaRoot_t  *agRoot,
8933                         bit32        queueNum,
8934                         agBOOLEAN      isInbound,
8935                         void        *pMsg,
8936                         bit32        msgLength)
8937 {
8938   return;
8939 }
8940 #endif /* SALLSDK_OS_IOMB_LOG_ENABLE */
8941 
8942 #ifndef SATA_ENABLE
8943 /*
8944  * These callback routines are defined in ossasat.c which are included in the
8945  * compilation if SATA_ENABLED is defined.
8946  */
8947 
8948 /*****************************************************************************
8949 *! \brief ossaDiscoverSataCB
8950 *
8951 *  Purpose:  This function is called by lower layer to inform TD layer of
8952 *            STP/SATA discovery results
8953 *
8954 *
8955 *  \param   agRoot         Pointer to chip/driver Instance.
8956 *  \param   agPortContext  Pointer to the port context of TD and Lower layer
8957 *  \param   event          event type
8958 *  \param   pParm1         Pointer to data associated with event
8959 *  \param   pParm2         Pointer to data associated with event
8960 *
8961 *  \return: none
8962 *
8963 *  \note -  For details, refer to SAS/SATA Low-Level API Specification
8964 *
8965 *****************************************************************************/
8966 
8967 osGLOBAL void ossaDiscoverSataCB( agsaRoot_t        *agRoot,
8968                     agsaPortContext_t *agPortContext,
8969                     bit32             event,
8970                     void              *pParm1,
8971                     void              *pParm2
8972                     )
8973 {
8974   return;
8975 }
8976 
8977 
8978 /*****************************************************************************
8979 *! \brief  ossaSATACompleted
8980 *
8981 *   This routine is called to complete a SATA request previously issued to the
8982 *    LL Layer in saSATAStart()
8983 *
8984 *  \param   agRoot:      Handles for this instance of SAS/SATA hardware
8985 *  \param   agIORequest: Pointer to the LL I/O request context for this I/O.
8986 *  \param   agIOStatus:  Status of completed I/O.
8987 *  \param   agFirstDword:Pointer to the four bytes of FIS.
8988 *  \param   agIOInfoLen: Length in bytes of overrun/underrun residual or FIS
8989 *                        length.
8990 *  \param   agParam:     Additional info based on status.
8991 *
8992 *  \return: none
8993 *
8994 *****************************************************************************/
8995 GLOBAL void ossaSATACompleted(
8996                   agsaRoot_t        *agRoot,
8997                   agsaIORequest_t   *agIORequest,
8998                   bit32             agIOStatus,
8999                   void              *agFirstDword,
9000                   bit32             agIOInfoLen,
9001                   void              *agParam
9002                   )
9003 {
9004   return;
9005 }
9006 
9007 
9008 /*****************************************************************************
9009 *! \brief  ossaSATAEvent
9010 *
9011 *   This routine is called to notify the OS Layer of an event associated with
9012 *   SATA port or SATA device
9013 *
9014 *  \param   agRoot:        Handles for this instance of SAS/SATA hardware
9015 *  \param   agIORequest:   Pointer to the LL I/O request context for this I/O.
9016 *  \param   agPortContext  Pointer to the port context of TD and Lower layer
9017 *  \param   agDevHandle:   Pointer to a device handle
9018 *  \param   event:         event type
9019 *
9020 *  \return: none
9021 *
9022 *****************************************************************************/
9023 osGLOBAL void ossaSATAEvent(
9024                         agsaRoot_t        *agRoot,
9025                         agsaIORequest_t   *agIORequest,
9026                         agsaPortContext_t *agPortContext,
9027                         agsaDevHandle_t   *agDevHandle,
9028                         bit32             event,
9029                         bit32             agIOInfoLen,
9030                         void              *agParam
9031                         )
9032 {
9033   return;
9034 }
9035 
9036 
9037 /*****************************************************************************
9038 *! \brief  ossaSATADeviceResetCB
9039 *
9040 *   This routine is called to complete a SATA device reset request previously
9041 *   issued to the LL Layer in saSATADeviceReset().
9042 *
9043 *  \param agRoot:      Handles for this instance of SAS/SATA hardware
9044 *  \param agDevHandle: Pointer to a device handle
9045 *  \param resetStatus: Reset status:
9046 *                      OSSA_SUCCESS: The reset operation completed successfully.
9047 *                      OSSA_FAILURE: The reset operation failed.
9048 *  \param resetparm:  Pointer to the Device-To-Host FIS received from the device.
9049 *
9050 *  \return: none
9051 *
9052 *****************************************************************************/
9053 osGLOBAL void ossaSATADeviceResetCB(
9054                       agsaRoot_t        *agRoot,
9055                       agsaDevHandle_t   *agDevHandle,
9056                       bit32             resetStatus,
9057                       void              *resetparm)
9058 {
9059 
9060   return;
9061 
9062 }
9063 
9064 /*****************************************************************************
9065 *! \brief ossaDiscoverSasCB
9066 *
9067 *  Purpose:  This function is called by lower layer to inform TD layer of
9068 *            SAS discovery results
9069 *
9070 *
9071 *  \param   agRoot         Pointer to chip/driver Instance.
9072 *  \param   agPortContext  Pointer to the port context of TD and Lower layer
9073 *  \param   event          event type
9074 *  \param   pParm1         Pointer to data associated with event
9075 *  \param   pParm2         Pointer to data associated with event
9076 *
9077 *  \return: none
9078 *
9079 *  \note -  For details, refer to SAS/SATA Low-Level API Specification
9080 *
9081 *****************************************************************************/
9082 osGLOBAL void ossaDiscoverSasCB(agsaRoot_t        *agRoot,
9083                   agsaPortContext_t *agPortContext,
9084                   bit32             event,
9085                   void              *pParm1,
9086                   void              *pParm2
9087                   )
9088 {
9089   return;
9090 }
9091 #endif
9092 
9093