xref: /freebsd/sys/dev/pms/RefTisa/tisa/sassata/common/tdsmcmnapi.c (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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 #include <sys/cdefs.h>
23 #include <dev/pms/config.h>
24 
25 #include <dev/pms/freebsd/driver/common/osenv.h>
26 #include <dev/pms/freebsd/driver/common/ostypes.h>
27 #include <dev/pms/freebsd/driver/common/osdebug.h>
28 
29 #include <dev/pms/RefTisa/tisa/api/titypes.h>
30 #include <dev/pms/RefTisa/tisa/api/ostiapi.h>
31 #include <dev/pms/RefTisa/tisa/api/tiapi.h>
32 /* for TIDEBUG_MSG */
33 #include <dev/pms/RefTisa/tisa/api/tiglobal.h>
34 
35 #ifdef FDS_SM
36 
37 #include <dev/pms/RefTisa/sat/api/sm.h>
38 #include <dev/pms/RefTisa/sat/api/smapi.h>
39 #include <dev/pms/RefTisa/sat/api/tdsmapi.h>
40 
41 #ifdef FDS_DM
42 #include <dev/pms/RefTisa/discovery/api/dm.h>
43 #endif
44 
45 #ifdef INITIATOR_DRIVER
46 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdtypes.h>
47 #endif
48 
49 #include <dev/pms/RefTisa/tisa/sassata/sas/common/tdtypes.h>
50 #include <dev/pms/RefTisa/tisa/sassata/common/tdsatypes.h>
51 #include <dev/pms/RefTisa/tisa/sassata/common/tdproto.h>
52 
53 #if defined(SM_DEBUG)
54 extern bit32 gSMDebugLevel;
55 #endif
56 
57 osGLOBAL void
58 smReportRemovalDirect(
59                        tiRoot_t             *tiRoot,
60                        agsaRoot_t           *agRoot,
61                        tdsaDeviceData_t     *oneDeviceData
62          )
63 {
64   tdsaRoot_t              *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
65   tdsaContext_t           *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
66   bit8                    PhyID;
67 
68   TI_DBG2(("smReportRemovalDirect: start\n"));
69 
70   PhyID                  = oneDeviceData->phyID;
71 
72   tdsaAbortAll(tiRoot, agRoot, oneDeviceData);
73   oneDeviceData->valid = agFALSE;
74   oneDeviceData->valid2 = agFALSE;
75   /* put onedevicedata back to free list */
76   osti_memset(&(oneDeviceData->satDevData.satIdentifyData), 0xFF, sizeof(agsaSATAIdentifyData_t));
77   TDLIST_DEQUEUE_THIS(&(oneDeviceData->MainLink));
78   TDLIST_ENQUEUE_AT_TAIL(&(oneDeviceData->FreeLink), &(tdsaAllShared->FreeDeviceList));
79 
80   /* notifying link up */
81   ostiPortEvent (
82                  tiRoot,
83                  tiPortLinkUp,
84                  tiSuccess,
85                  (void *)tdsaAllShared->Ports[PhyID].tiPortalContext
86                 );
87 #ifdef INITIATOR_DRIVER
88   /* triggers discovery */
89   ostiPortEvent(
90                 tiRoot,
91                 tiPortDiscoveryReady,
92                 tiSuccess,
93                 (void *) tdsaAllShared->Ports[PhyID].tiPortalContext
94                 );
95 #endif
96   return;
97 }
98 
99 osGLOBAL void
100 smReportRemoval(
101                  tiRoot_t             *tiRoot,
102                  agsaRoot_t           *agRoot,
103                  tdsaDeviceData_t     *oneDeviceData,
104                  tdsaPortContext_t    *onePortContext
105          )
106 {
107   TI_DBG2(("smReportRemoval: start\n"));
108 
109   if (oneDeviceData->registered == agTRUE)
110   {
111     /*
112       1. remove this device
113       2. device removal event
114     */
115     tdsaAbortAll(tiRoot, agRoot, oneDeviceData);
116     oneDeviceData->valid = agFALSE;
117     oneDeviceData->valid2 = agFALSE;
118     oneDeviceData->registered = agFALSE;
119     ostiInitiatorEvent(
120                        tiRoot,
121                        onePortContext->tiPortalContext,
122                        agNULL,
123                        tiIntrEventTypeDeviceChange,
124                        tiDeviceRemoval,
125                        agNULL
126                      );
127   }
128 
129   return;
130 }
131 osGLOBAL void
132 smHandleDirect(
133                 tiRoot_t             *tiRoot,
134                 agsaRoot_t           *agRoot,
135                 tdsaDeviceData_t     *oneDeviceData,
136                 void                 *IDdata
137         )
138 {
139   tdsaRoot_t              *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
140   tdsaContext_t           *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
141   agsaSATAIdentifyData_t  *pSATAIdData;
142   tdList_t                *DeviceListList;
143   tdsaDeviceData_t        *tmpOneDeviceData = agNULL;
144   int                     new_device = agTRUE;
145   bit8                    PhyID;
146 
147   TI_DBG2(("smHandleDirect: start\n"));
148   PhyID = oneDeviceData->phyID;
149 
150   pSATAIdData = (agsaSATAIdentifyData_t *)IDdata;
151   //tdhexdump("satAddSATAIDDevCB after", (bit8 *)pSATAIdData, sizeof(agsaSATAIdentifyData_t));
152 
153   /* compare idenitfy device data to the exiting list */
154   DeviceListList = tdsaAllShared->MainDeviceList.flink;
155   while (DeviceListList != &(tdsaAllShared->MainDeviceList))
156   {
157     tmpOneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
158     if (tmpOneDeviceData == agNULL)
159     {
160       TI_DBG1(("smHandleDirect: tmpOneDeviceData is NULL!!!\n"));
161       return;
162     }
163     TI_DBG1(("smHandleDirect: LOOP tmpOneDeviceData %p did %d\n", tmpOneDeviceData, tmpOneDeviceData->id));
164     //tdhexdump("smHandleDirect LOOP", (bit8 *)&tmpOneDeviceData->satDevData.satIdentifyData, sizeof(agsaSATAIdentifyData_t));
165 
166     /* what is unique ID for sata device -> response of identify devicedata; not really
167        Let's compare serial number, firmware version, model number
168     */
169     if ( tmpOneDeviceData->DeviceType == TD_SATA_DEVICE &&
170          (osti_memcmp (tmpOneDeviceData->satDevData.satIdentifyData.serialNumber,
171                        pSATAIdData->serialNumber,
172                        20) == 0) &&
173          (osti_memcmp (tmpOneDeviceData->satDevData.satIdentifyData.firmwareVersion,
174                        pSATAIdData->firmwareVersion,
175                        8) == 0) &&
176          (osti_memcmp (tmpOneDeviceData->satDevData.satIdentifyData.modelNumber,
177                        pSATAIdData->modelNumber,
178                        40) == 0)
179        )
180     {
181       TI_DBG2(("smHandleDirect: did %d\n", tmpOneDeviceData->id));
182       new_device = agFALSE;
183       break;
184     }
185     DeviceListList = DeviceListList->flink;
186   }
187 
188 
189   if (new_device == agFALSE)
190   {
191     TI_DBG2(("smHandleDirect: old device data\n"));
192     tmpOneDeviceData->valid = agTRUE;
193     tmpOneDeviceData->valid2 = agTRUE;
194     /* save data field from new device data */
195     tmpOneDeviceData->agRoot = agRoot;
196     tmpOneDeviceData->agDevHandle = oneDeviceData->agDevHandle;
197     tmpOneDeviceData->agDevHandle->osData = tmpOneDeviceData; /* TD layer */
198     tmpOneDeviceData->tdPortContext = oneDeviceData->tdPortContext;
199     tmpOneDeviceData->phyID = oneDeviceData->phyID;
200 
201     /*
202       one SATA directly attached device per phy;
203       Therefore, deregister then register
204     */
205     saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
206 
207     if (tmpOneDeviceData->registered == agFALSE)
208     {
209       TI_DBG2(("smHandleDirect: re-registering old device data\n"));
210       /* already has old information; just register it again */
211       saRegisterNewDevice( /* smHandleDirect */
212                           agRoot,
213                           &tmpOneDeviceData->agContext,
214                           0,/*tdsaRotateQnumber(tiRoot, tmpOneDeviceData),*/
215                           &tmpOneDeviceData->agDeviceInfo,
216                           tmpOneDeviceData->tdPortContext->agPortContext,
217                           0
218                           );
219     }
220 
221 //    tdsaAbortAll(tiRoot, agRoot, oneDeviceData);
222     /* put tmpOneDeviceData back to free list */
223     osti_memset(&(oneDeviceData->satDevData.satIdentifyData), 0xFF, sizeof(agsaSATAIdentifyData_t));
224     TDLIST_DEQUEUE_THIS(&(oneDeviceData->MainLink));
225     TDLIST_ENQUEUE_AT_TAIL(&(oneDeviceData->FreeLink), &(tdsaAllShared->FreeDeviceList));
226 
227     TI_DBG2(("smHandleDirect: pid %d\n", tdsaAllShared->Ports[PhyID].portContext->id));
228     /* notifying link up */
229     ostiPortEvent (
230                    tiRoot,
231                    tiPortLinkUp,
232                    tiSuccess,
233                    (void *)tdsaAllShared->Ports[PhyID].tiPortalContext
234                    );
235 
236 
237 #ifdef INITIATOR_DRIVER
238     /* triggers discovery */
239     ostiPortEvent(
240                   tiRoot,
241                   tiPortDiscoveryReady,
242                   tiSuccess,
243                   (void *) tdsaAllShared->Ports[PhyID].tiPortalContext
244                   );
245 #endif
246      return;
247   }
248 
249   TI_DBG2(("smHandleDirect: new device data\n"));
250   oneDeviceData->satDevData.satIdentifyData = *pSATAIdData;
251   /* notifying link up */
252   ostiPortEvent (
253                  tiRoot,
254                  tiPortLinkUp,
255                  tiSuccess,
256                  (void *)tdsaAllShared->Ports[PhyID].tiPortalContext
257                  );
258 #ifdef INITIATOR_DRIVER
259   /* triggers discovery */
260   ostiPortEvent(
261                 tiRoot,
262                 tiPortDiscoveryReady,
263                 tiSuccess,
264                 (void *) tdsaAllShared->Ports[PhyID].tiPortalContext
265                 );
266 #endif
267 
268   return;
269 }
270 
271 /*
272   combine satAddSATAIDDevCB(expander) and satAddSATAIDDevCB(directly attached)
273 */
274 osGLOBAL void
275 tdsmIDCompletedCB(
276                   smRoot_t      *smRoot,
277                   smIORequest_t     *smIORequest,
278                   smDeviceHandle_t    *smDeviceHandle,
279                   bit32       status,
280                   void        *IDdata
281                  )
282 {
283   tdsaRoot_t                *tdsaRoot;
284   tdsaContext_t             *tdsaAllShared;
285   tiRoot_t                  *tiRoot;
286   agsaRoot_t                *agRoot;
287   tdIORequestBody_t         *tdIORequestBody;
288   tdsaDeviceData_t          *oneDeviceData;
289   tdsaPortContext_t         *onePortContext;
290   tiPortalContext_t         *tiPortalContext;
291   bit32                     pid = 0xff;
292   bit32                     IDstatus;
293   agsaSATAIdentifyData_t    *pSATAIdData;
294 
295   TI_DBG2(("tdsmIDCompletedCB: start\n"));
296 
297   tdsaRoot = (tdsaRoot_t *)smRoot->tdData;
298   tdsaAllShared = &(tdsaRoot->tdsaAllShared);
299   tiRoot = tdsaAllShared->agRootOsDataForInt.tiRoot;
300   tdIORequestBody = (tdIORequestBody_t *)smIORequest->tdData;
301 
302   if (smDeviceHandle == agNULL)
303   {
304      TI_DBG1(("tdsmIDCompletedCB: smDeviceHandle is NULL !!!!\n"));
305      ostiFreeMemory(
306                    tiRoot,
307                    tdIORequestBody->osMemHandle,
308                    sizeof(tdIORequestBody_t)
309                    );
310      return;
311   }
312 
313   oneDeviceData = (tdsaDeviceData_t *)smDeviceHandle->tdData;
314   onePortContext = oneDeviceData->tdPortContext;
315   agRoot = oneDeviceData->agRoot;
316   pid = tdIORequestBody->pid;
317 
318 
319 //  oneDeviceData->satDevData.IDDeviceValid = agFALSE;
320   oneDeviceData->satDevData.IDPending = agFALSE;
321 
322   TI_DBG2(("tdsmIDCompletedCB: tdIORequestBody %p  tdIORequestBody->osMemHandle %p\n", tdIORequestBody, tdIORequestBody->osMemHandle));
323 
324   tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK);
325 
326   if (oneDeviceData->tdIDTimer.timerRunning == agTRUE)
327   {
328     tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
329     tdsaKillTimer(
330                   tiRoot,
331                   &oneDeviceData->tdIDTimer
332                   );
333   }
334   else
335   {
336     tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
337   }
338 
339   if (onePortContext == agNULL)
340   {
341     TI_DBG1(("tdsmIDCompletedCB: onePortContext is NULL!!!\n"));
342     ostiFreeMemory(
343                     tiRoot,
344                     tdIORequestBody->osMemHandle,
345                     sizeof(tdIORequestBody_t)
346                   );
347     return;
348   }
349 
350   /* check port id */
351   if (pid != onePortContext->id)
352   {
353     TI_DBG1(("tdsmIDCompletedCB: not matching pid; pid %d onePortContext->id %d!!!\n", pid, onePortContext->id));
354     if (oneDeviceData->directlyAttached == agTRUE)
355     {
356       smReportRemovalDirect(tiRoot, agRoot, oneDeviceData);
357     }
358     else
359     {
360       smReportRemoval(tiRoot, agRoot, oneDeviceData, onePortContext);
361     }
362     ostiFreeMemory(
363                     tiRoot,
364                     tdIORequestBody->osMemHandle,
365                     sizeof(tdIORequestBody_t)
366                   );
367     return;
368   }
369 
370   tiPortalContext= onePortContext->tiPortalContext;
371 
372   if (tiPortalContext == agNULL)
373   {
374     TI_DBG1(("tdsmIDCompletedCB: tiPortalContext is NULL!!!\n"));
375     if (oneDeviceData->directlyAttached == agTRUE)
376     {
377       smReportRemovalDirect(tiRoot, agRoot, oneDeviceData);
378     }
379     else
380     {
381       smReportRemoval(tiRoot, agRoot, oneDeviceData, onePortContext);
382     }
383     ostiFreeMemory(
384                     tiRoot,
385                     tdIORequestBody->osMemHandle,
386                     sizeof(tdIORequestBody_t)
387                   );
388     return;
389   }
390 
391   if (agRoot == agNULL)
392   {
393     TI_DBG1(("tdsmIDCompletedCB: agRoot is NULL!!!\n"));
394     ostiFreeMemory(
395                     tiRoot,
396                     tdIORequestBody->osMemHandle,
397                     sizeof(tdIORequestBody_t)
398                   );
399     return;
400   }
401 
402   if (status == smIOSuccess)
403   {
404     TI_DBG2(("tdsmIDCompletedCB: smIOSuccess\n"));
405 
406     oneDeviceData->satDevData.IDDeviceValid = agTRUE;
407     if (oneDeviceData->directlyAttached == agTRUE)
408     {
409       TI_DBG2(("tdsmIDCompletedCB: directlyAttached\n"));
410       pSATAIdData = (agsaSATAIdentifyData_t *)IDdata;
411       smHandleDirect(tiRoot, agRoot, oneDeviceData, IDdata);
412       /* filling in */
413       osti_memcpy(onePortContext->remoteName, pSATAIdData->serialNumber, 20);
414       osti_memcpy(&(onePortContext->remoteName[20]), pSATAIdData->firmwareVersion, 8);
415       osti_memcpy(&(onePortContext->remoteName[28]), pSATAIdData->modelNumber, 40);
416     }
417     else /* expander attached */
418     {
419 
420       TI_DBG2(("tdsmIDCompletedCB: expander attached\n"));
421 
422       if (onePortContext->DiscoveryState == ITD_DSTATE_COMPLETED)
423       {
424         TI_DBG1(("tdsmIDCompletedCB: ID completed after discovery is done; tiDeviceArrival\n"));
425         /* ID data completed after discovery is completed */
426         ostiInitiatorEvent(
427                            tiRoot,
428                            tiPortalContext,
429                            agNULL,
430                            tiIntrEventTypeDeviceChange,
431                            tiDeviceArrival,
432                            agNULL
433                            );
434       }
435     }
436     TI_DBG2(("tdsmIDCompletedCB: tdIORequestBody %p  tdIORequestBody->osMemHandle %p\n", tdIORequestBody, tdIORequestBody->osMemHandle));
437     ostiFreeMemory(
438                     tiRoot,
439                     tdIORequestBody->osMemHandle,
440                     sizeof(tdIORequestBody_t)
441                   );
442 
443   }
444   else if ( status == smIORetry)
445   {
446     TI_DBG1(("tdsmIDCompletedCB: smIORetry!!!\n"));
447     if ( !(oneDeviceData->valid == agTRUE && oneDeviceData->registered == agTRUE &&
448            oneDeviceData->tdPortContext != agNULL)
449        )
450     {
451       TI_DBG1(("tdsmIDCompletedCB: smIORetry but device is not valid!!!\n"));
452       tdIORequestBody->reTries = 0;
453       tdIORequestBody->ioCompleted = agTRUE;
454       tdIORequestBody->ioStarted = agFALSE;
455       ostiFreeMemory(
456                      tiRoot,
457                      tdIORequestBody->osMemHandle,
458                      sizeof(tdIORequestBody_t)
459              );
460       oneDeviceData->satDevData.IDDeviceValid = agFALSE;
461       return;
462     }
463 
464     if (tdIORequestBody->reTries <= SM_RETRIES)
465     {
466       tdIORequestBody->tiIORequest = agNULL; /* not in use */
467       tdIORequestBody->pid = onePortContext->id;
468       smIORequest->tdData = tdIORequestBody;
469       smIORequest->smData = &tdIORequestBody->smIORequestBody;
470 
471       smDeviceHandle->tdData = oneDeviceData;
472 
473       oneDeviceData->satDevData.IDDeviceValid = agFALSE;
474 
475       IDstatus = smIDStart(smRoot,
476                            smIORequest,
477                            smDeviceHandle
478                            );
479       if (IDstatus != SM_RC_SUCCESS)
480       {
481         /* identify device data is not valid */
482         TI_DBG1(("tdsmIDCompletedCB: smIDStart fail or busy %d!!!\n", IDstatus));
483         tdIORequestBody->reTries = 0;
484         tdIORequestBody->ioCompleted = agTRUE;
485         tdIORequestBody->ioStarted = agFALSE;
486         ostiFreeMemory(
487                        tiRoot,
488                        tdIORequestBody->osMemHandle,
489                        sizeof(tdIORequestBody_t)
490                         );
491         smReportRemoval(tiRoot, agRoot, oneDeviceData, onePortContext);
492         return;
493       }
494       tdIORequestBody->reTries++;
495       tdIORequestBody->ioCompleted = agFALSE;
496       tdIORequestBody->ioStarted = agTRUE;
497       oneDeviceData->satDevData.IDPending = agTRUE;
498       /* start a timer */
499       tdIDStartTimer(tiRoot, smIORequest, oneDeviceData);
500       TI_DBG1(("tdsmIDCompletedCB: being retried!!!\n"));
501     }
502     else
503     {
504       /* give up */
505       TI_DBG1(("tdsmIDCompletedCB: retries are over!!!\n"));
506       tdIORequestBody->reTries = 0;
507       tdIORequestBody->ioCompleted = agTRUE;
508       tdIORequestBody->ioStarted = agFALSE;
509       ostiFreeMemory(
510                      tiRoot,
511                      tdIORequestBody->osMemHandle,
512                      sizeof(tdIORequestBody_t)
513                      );
514       oneDeviceData->satDevData.IDDeviceValid = agFALSE;
515       /* SATA device is not usable; remove it */
516       smReportRemoval(tiRoot, agRoot, oneDeviceData, onePortContext);
517     }
518   }
519   else if ( status == smIOSTPResourceBusy)
520   {
521     /* decides to send smp hard reset or not */
522     TI_DBG1(("tdsmIDCompletedCB: smIOSTPResourceBusy\n"));
523     ostiFreeMemory(
524                    tiRoot,
525                    tdIORequestBody->osMemHandle,
526                    sizeof(tdIORequestBody_t)
527                   );
528     oneDeviceData->satDevData.IDDeviceValid = agFALSE;
529     if (tdsaAllShared->FCA)
530     {
531       if (oneDeviceData->SMNumOfFCA <= 0) /* does SMP HARD RESET only upto one time */
532       {
533         TI_DBG1(("tdsmIDCompletedCB: OSSA_IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY; sending HARD_RESET\n"));
534         oneDeviceData->SMNumOfFCA++;
535         tdsaPhyControlSend(tiRoot,
536                            oneDeviceData,
537                            SMP_PHY_CONTROL_HARD_RESET,
538                            agNULL,
539                            tdsaRotateQnumber(tiRoot, oneDeviceData)
540                           );
541       }
542       else
543       {
544         /* given up after one time of SMP HARD RESET; */
545         TI_DBG1(("tdsmIDCompletedCB: OSSA_IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY; but giving up sending HARD_RESET!!!\n"));
546         smReportRemoval(tiRoot, agRoot, oneDeviceData, onePortContext);
547       }
548     }
549     else
550     {
551       /* do nothing */
552     }
553   }
554   else
555   {
556     TI_DBG1(("tdsmIDCompletedCB: smIDStart fail, status 0x%x!!!\n", status));
557     TI_DBG1(("tdsmIDCompletedCB: did %d!!!\n", oneDeviceData->id));
558     if ( !(oneDeviceData->valid == agTRUE && oneDeviceData->registered == agTRUE &&
559            oneDeviceData->tdPortContext != agNULL)
560        )
561     {
562       TI_DBG1(("tdsmIDCompletedCB: fail but device is not valid!!!\n"));
563       tdIORequestBody->reTries = 0;
564       tdIORequestBody->ioCompleted = agTRUE;
565       tdIORequestBody->ioStarted = agFALSE;
566       ostiFreeMemory(
567                      tiRoot,
568                      tdIORequestBody->osMemHandle,
569                      sizeof(tdIORequestBody_t)
570                      );
571       oneDeviceData->satDevData.IDDeviceValid = agFALSE;
572       return;
573     }
574     tdsaAllShared->IDRetry = agTRUE;
575     if (tdsaAllShared->IDRetry)
576     {
577       if (tdIORequestBody->reTries <= SM_RETRIES)
578       {
579         tdIORequestBody->tiIORequest = agNULL; /* not in use */
580         tdIORequestBody->pid = onePortContext->id;
581         smIORequest->tdData = tdIORequestBody;
582         smIORequest->smData = &tdIORequestBody->smIORequestBody;
583 
584         smDeviceHandle->tdData = oneDeviceData;
585         IDstatus = smIDStart(smRoot,
586                              smIORequest,
587                              smDeviceHandle
588                              );
589         if (IDstatus != SM_RC_SUCCESS)
590         {
591           /* identify device data is not valid */
592           TI_DBG1(("tdsmIDCompletedCB: smIDStart fail or busy %d!!!\n", IDstatus));
593           tdIORequestBody->reTries = 0;
594           tdIORequestBody->ioCompleted = agTRUE;
595           tdIORequestBody->ioStarted = agFALSE;
596           ostiFreeMemory(
597                          tiRoot,
598                          tdIORequestBody->osMemHandle,
599                          sizeof(tdIORequestBody_t)
600                          );
601           oneDeviceData->satDevData.IDDeviceValid = agFALSE;
602           if (oneDeviceData->directlyAttached == agTRUE)
603           {
604             smReportRemovalDirect(tiRoot, agRoot, oneDeviceData);
605           }
606           else
607           {
608             smReportRemoval(tiRoot, agRoot, oneDeviceData, onePortContext);
609           }
610           return;
611         }
612         tdIORequestBody->reTries++;
613         tdIORequestBody->ioCompleted = agFALSE;
614         tdIORequestBody->ioStarted = agTRUE;
615         oneDeviceData->satDevData.IDPending = agTRUE;
616         /* start a timer */
617         tdIDStartTimer(tiRoot, smIORequest, oneDeviceData);
618         TI_DBG1(("tdsmIDCompletedCB: being retried!!!\n"));
619       }
620       else
621       {
622         /* give up */
623         TI_DBG1(("tdsmIDCompletedCB: retries are over; sending hard reset!!!\n"));
624         tdIORequestBody->reTries = 0;
625         tdIORequestBody->ioCompleted = agTRUE;
626         tdIORequestBody->ioStarted = agFALSE;
627         ostiFreeMemory(
628                        tiRoot,
629                        tdIORequestBody->osMemHandle,
630                        sizeof(tdIORequestBody_t)
631                        );
632         oneDeviceData->satDevData.IDDeviceValid = agFALSE;
633 
634         if (oneDeviceData->SMNumOfID <= 0) /* does SMP HARD RESET only upto one time */
635         {
636           TI_DBG1(("tdsmIDCompletedCB: fail; sending HARD_RESET\n"));
637           oneDeviceData->SMNumOfID++;
638           if (oneDeviceData->directlyAttached == agTRUE)
639           {
640             saLocalPhyControl(agRoot, agNULL, tdsaRotateQnumber(tiRoot, oneDeviceData), oneDeviceData->phyID, AGSA_PHY_HARD_RESET, agNULL);
641           }
642           else
643           {
644             tdsaPhyControlSend(tiRoot,
645                                oneDeviceData,
646                                SMP_PHY_CONTROL_HARD_RESET,
647                                agNULL,
648                                tdsaRotateQnumber(tiRoot, oneDeviceData)
649                               );
650           }
651         }
652         else
653         {
654           /* given up after one time of SMP HARD RESET; */
655           TI_DBG1(("tdsmIDCompletedCB: fail; but giving up sending HARD_RESET!!!\n"));
656           if (oneDeviceData->directlyAttached == agTRUE)
657           {
658             smReportRemovalDirect(tiRoot, agRoot, oneDeviceData);
659           }
660           else
661           {
662             smReportRemoval(tiRoot, agRoot, oneDeviceData, onePortContext);
663           }
664         }
665       }
666     }
667     else
668     {
669       /* do nothing */
670     }
671 
672 
673   }
674 
675 
676   return;
677 }
678 
679 FORCEINLINE void
680 tdsmIOCompletedCB(
681                   smRoot_t      *smRoot,
682                   smIORequest_t     *smIORequest,
683                   bit32       status,
684                   bit32       statusDetail,
685                   smSenseData_t     *senseData,
686                   bit32       interruptContext
687                   )
688 {
689   tdsaRoot_t                *tdsaRoot         = (tdsaRoot_t *)smRoot->tdData;
690   tdsaContext_t             *tdsaAllShared    = &(tdsaRoot->tdsaAllShared);
691   tiRoot_t                  *tiRoot           = tdsaAllShared->agRootOsDataForInt.tiRoot;
692   tdIORequestBody_t         *tdIORequestBody  = (tdIORequestBody_t *)smIORequest->tdData;
693   tiIORequest_t             *tiIORequest      = tdIORequestBody->tiIORequest;
694 
695   tdsaDeviceData_t          *oneDeviceData;
696   tiDeviceHandle_t          *tiDeviceHandle;
697   smDeviceHandle_t          *smDeviceHandle;
698   smScsiInitiatorRequest_t  *smSCSIRequest;
699   smSuperScsiInitiatorRequest_t  *smSuperSCSIRequest;
700 
701   bit32                     SMStatus = SM_RC_FAILURE;
702 
703 
704   TI_DBG5(("tdsmIOCompletedCB: start\n"));
705 
706   if (status == smIOSuccess)
707   {
708     ostiInitiatorIOCompleted( tiRoot,
709                          tiIORequest,
710                          status,
711                          statusDetail,
712                          (tiSenseData_t *)senseData,
713                          interruptContext);
714   }
715   else if (status == smIORetry)
716   {
717     TI_DBG1(("tdsmIOCompletedCB: smIORetry!!!\n"));
718     smIORequest = (smIORequest_t *)&(tdIORequestBody->smIORequest);
719     tiDeviceHandle = tdIORequestBody->tiDevHandle;
720     oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
721 
722     if (! (oneDeviceData->valid == agTRUE && oneDeviceData->registered == agTRUE &&
723            oneDeviceData->tdPortContext != agNULL)
724        )
725     {
726       TI_DBG1(("tdsmIOCompletedCB: smIORetry but device is not valid!!!\n"));
727       tdIORequestBody->reTries = 0;
728       tdIORequestBody->ioCompleted = agTRUE;
729       tdIORequestBody->ioStarted = agFALSE;
730       ostiInitiatorIOCompleted( tiRoot,
731                                 tiIORequest,
732                                 status,
733                                 statusDetail,
734                                 (tiSenseData_t *)senseData,
735                                 interruptContext);
736       return;
737     }
738     if (tdIORequestBody->reTries <= SM_RETRIES)
739     {
740       smDeviceHandle = (smDeviceHandle_t *)&(oneDeviceData->smDeviceHandle);
741       if (tdIORequestBody->superIOFlag == agTRUE)
742       {
743         smSuperSCSIRequest = (smSuperScsiInitiatorRequest_t *)&(tdIORequestBody->SM.smSuperSCSIRequest);
744         SMStatus = smSuperIOStart(smRoot,
745                                   smIORequest,
746                                   smDeviceHandle,
747                                   smSuperSCSIRequest,
748                                   oneDeviceData->SASAddressID.sasAddressHi,
749                                   oneDeviceData->SASAddressID.sasAddressLo,
750                                   interruptContext);
751       }
752       else
753       {
754         smSCSIRequest = (smScsiInitiatorRequest_t *)&(tdIORequestBody->SM.smSCSIRequest);
755         SMStatus = smIOStart(smRoot,
756                              smIORequest,
757                              smDeviceHandle,
758                              smSCSIRequest,
759                              interruptContext);
760       }
761 
762 
763       if (SMStatus != SM_RC_SUCCESS)
764       {
765         TI_DBG1(("tdsmIOCompletedCB: smIDStart fail or busy %d!!!\n", SMStatus));
766         tdIORequestBody->reTries = 0;
767         tdIORequestBody->ioCompleted = agTRUE;
768         tdIORequestBody->ioStarted = agFALSE;
769         ostiInitiatorIOCompleted( tiRoot,
770                                   tiIORequest,
771                                   status,
772                                   statusDetail,
773                                   (tiSenseData_t *)senseData,
774                                   interruptContext);
775         return;
776       }
777       else
778       {
779         TI_DBG1(("tdsmIOCompletedCB: being retried!!!\n"));
780         tdIORequestBody->reTries++;
781         tdIORequestBody->ioCompleted = agFALSE;
782         tdIORequestBody->ioStarted = agTRUE;
783       }
784     }
785     else
786     {
787       /* give up; complete IO */
788       TI_DBG1(("tdsmIOCompletedCB: retries are over!!!\n"));
789       tdIORequestBody->reTries = 0;
790       tdIORequestBody->ioCompleted = agTRUE;
791       tdIORequestBody->ioStarted = agFALSE;
792       ostiInitiatorIOCompleted( tiRoot,
793                                 tiIORequest,
794                                 status,
795                                 statusDetail,
796                                 (tiSenseData_t *)senseData,
797                                 interruptContext);
798       return;
799     }
800 
801   }
802   else if ( status == smIOSTPResourceBusy)
803   {
804     /* decides to send smp hard reset or not */
805     TI_DBG1(("tdsmIOCompletedCB: smIOSTPResourceBusy\n"));
806     if (tdsaAllShared->FCA)
807     {
808       smIORequest = (smIORequest_t *)&(tdIORequestBody->smIORequest);
809       tiDeviceHandle = tdIORequestBody->tiDevHandle;
810       oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
811       if (oneDeviceData->SMNumOfFCA <= 0) /* does SMP HARD RESET only upto one time */
812       {
813         TI_DBG1(("tdsmIOCompletedCB: OSSA_IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY; sending HARD_RESET\n"));
814         oneDeviceData->SMNumOfFCA++;
815         tdsaPhyControlSend(tiRoot,
816                            oneDeviceData,
817                            SMP_PHY_CONTROL_HARD_RESET,
818                            agNULL,
819                            tdsaRotateQnumber(tiRoot, oneDeviceData)
820                           );
821       }
822       else
823       {
824         /* given up after one time of SMP HARD RESET; */
825         TI_DBG1(("tdsmIOCompletedCB: OSSA_IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY; but giving up sending HARD_RESET!!!\n"));
826       }
827     }
828     ostiInitiatorIOCompleted( tiRoot,
829                               tiIORequest,
830                               status,
831                               statusDetail,
832                               (tiSenseData_t *)senseData,
833                               interruptContext);
834     return;
835   }
836   else
837   {
838     if (statusDetail == smDetailAborted)
839     {
840       tiDeviceHandle = tdIORequestBody->tiDevHandle;
841       oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
842       TI_DBG1(("tdsmIOCompletedCB: agIOStatus = OSSA_IO_ABORTED did %d\n", oneDeviceData->id));
843     }
844     ostiInitiatorIOCompleted( tiRoot,
845                               tiIORequest,
846                               status,
847                               statusDetail,
848                               (tiSenseData_t *)senseData,
849                               interruptContext);
850   }
851 
852   return;
853 }
854 
855 /* completion of taskmanagement
856 osGLOBAL void ostiInitiatorEvent (
857                         tiRoot_t            *tiRoot,
858                         tiPortalContext_t   *portalContext,
859                         tiDeviceHandle_t    *tiDeviceHandle,
860                         tiIntrEventType_t   eventType,
861                         bit32               eventStatus,
862                         void                *parm
863                         );
864 
865 */
866 //qqq1
867 osGLOBAL void
868 tdsmEventCB(
869             smRoot_t          *smRoot,
870             smDeviceHandle_t  *smDeviceHandle,
871             smIntrEventType_t  eventType,
872             bit32              eventStatus,
873             void              *parm
874            )
875 {
876   tdsaRoot_t                  *tdsaRoot;
877   tdsaContext_t               *tdsaAllShared;
878   tiRoot_t                    *tiRoot;
879   tdIORequestBody_t           *tdIORequestBody;
880   smIORequest_t               *SMcurrentTaskTag;
881   tiIORequest_t               *currentTaskTag;
882   tdsaDeviceData_t            *oneDeviceData;
883   void                        *osMemHandle;
884   tdsaPortContext_t           *onePortContext;
885   tiPortalContext_t           *tiportalContext;
886   tiDeviceHandle_t            *tiDeviceHandle;
887 
888   /* be sure to free using tdIORequestBody->->IOType.InitiatorTMIO.osMemHandle but how???
889      parm = pSatDevData->satTmTaskTag (currentTaskTag in tiINITaskManagement)
890      In this case, parm is smIORequest_t
891   */
892 
893   TI_DBG2(("tdsmEventCB: start\n"));
894 
895   tdsaRoot = (tdsaRoot_t *)smRoot->tdData;
896   tdsaAllShared = &(tdsaRoot->tdsaAllShared);
897   tiRoot = tdsaAllShared->agRootOsDataForInt.tiRoot;
898 
899 
900   if (eventType == smIntrEventTypeLocalAbort)
901   {
902     oneDeviceData = (tdsaDeviceData_t *)smDeviceHandle->tdData;
903     if (oneDeviceData == agNULL)
904     {
905       TI_DBG1(("tdsmEventCB: oneDeviceData is NULL\n"));
906       return;
907     }
908     else
909     {
910       tiDeviceHandle = &(oneDeviceData->tiDeviceHandle);
911       if (oneDeviceData->OSAbortAll == agTRUE)
912       {
913         oneDeviceData->OSAbortAll = agFALSE;
914         ostiInitiatorEvent( tiRoot,
915                             agNULL,
916                             tiDeviceHandle,
917                             tiIntrEventTypeLocalAbort,
918                             tiAbortOK,
919                             agNULL);
920       }
921     }
922   }
923   else
924   {
925 
926     SMcurrentTaskTag = (smIORequest_t *)parm;
927     if (SMcurrentTaskTag == agNULL)
928     {
929       TI_DBG1(("tdsmEventCB: SMcurrentTaskTag is NULL!!!\n"));
930       return;
931     }
932 
933     tdIORequestBody = (tdIORequestBody_t *)SMcurrentTaskTag->tdData;
934     if (tdIORequestBody == agNULL)
935     {
936       TI_DBG1(("tdsmEventCB: tdIORequestBody is NULL!!!\n"));
937       return;
938     }
939 
940     osMemHandle =  tdIORequestBody->IOType.InitiatorTMIO.osMemHandle;
941     currentTaskTag = tdIORequestBody->IOType.InitiatorTMIO.CurrentTaskTag;
942 
943 
944     oneDeviceData = (tdsaDeviceData_t *)smDeviceHandle->tdData;
945     if (oneDeviceData == agNULL)
946     {
947       TI_DBG1(("tdsmEventCB: oneDeviceData is NULL!!!\n"));
948       return;
949     }
950 
951     tiDeviceHandle = &(oneDeviceData->tiDeviceHandle);
952     onePortContext = oneDeviceData->tdPortContext;
953     if (onePortContext == agNULL)
954     {
955       TI_DBG1(("tdsmEventCB: onePortContext is NULL!!!\n"));
956       return;
957     }
958     tiportalContext = onePortContext->tiPortalContext;
959 
960     /* free tdIORequestBody */
961     ostiFreeMemory(
962                     tiRoot,
963                     osMemHandle,
964                     sizeof(tdIORequestBody_t)
965                    );
966 
967 
968     TI_DBG2(("tdsmEventCB: calling ostiInitiatorEvent\n"));
969     ostiInitiatorEvent(
970                         tiRoot,
971                         tiportalContext,
972                         tiDeviceHandle,
973                         eventType,
974                         eventStatus,
975                         (void *)currentTaskTag
976                        );
977 
978 
979       /* completion of taskmanagement
980       osGLOBAL void ostiInitiatorEvent (
981                               tiRoot_t            *tiRoot,
982                               tiPortalContext_t   *portalContext,
983                               tiDeviceHandle_t    *tiDeviceHandle,
984                               tiIntrEventType_t   eventType,
985                               bit32               eventStatus,
986                               void                *parm
987                               );
988 
989 
990       ostiFreeAlloc()
991     */
992 
993   }
994 
995   return;
996 }
997 
998 
999 FORCEINLINE void
1000 tdsmSingleThreadedEnter(
1001                         smRoot_t    *smRoot,
1002                         bit32        syncLockId
1003                         )
1004 {
1005   tdsaRoot_t         *tdsaRoot;
1006   tdsaContext_t      *tdsaAllShared;
1007   tiRoot_t           *tiRoot;
1008   bit32              offset = 0;
1009 
1010   TI_DBG7(("tdsmSingleThreadedEnter: start\n"));
1011 
1012   tdsaRoot = (tdsaRoot_t *)smRoot->tdData;
1013   if (tdsaRoot == agNULL)
1014   {
1015     TI_DBG1(("tdsmSingleThreadedEnter: tdsaRoot is NULL\n"));
1016     return;
1017   }
1018 
1019   tdsaAllShared = &(tdsaRoot->tdsaAllShared);
1020   if (tdsaAllShared == agNULL)
1021   {
1022     TI_DBG1(("tdsmSingleThreadedEnter: tdsaAllShared is NULL\n"));
1023     return;
1024   }
1025 
1026   tiRoot = tdsaAllShared->agRootOsDataForInt.tiRoot;
1027   if (tiRoot == agNULL)
1028   {
1029     TI_DBG1(("tdsmSingleThreadedEnter: tiRoot is NULL\n"));
1030     return;
1031   }
1032 
1033   offset = tdsaAllShared->MaxNumLLLocks + tdsaAllShared->MaxNumOSLocks + TD_MAX_LOCKS + tdsaAllShared->MaxNumDMLocks;
1034 
1035   ostiSingleThreadedEnter(tiRoot, syncLockId + offset);
1036 
1037   return;
1038 }
1039 
1040 FORCEINLINE void
1041 tdsmSingleThreadedLeave(
1042                         smRoot_t    *smRoot,
1043                         bit32       syncLockId
1044                         )
1045 {
1046   tdsaRoot_t         *tdsaRoot;
1047   tdsaContext_t      *tdsaAllShared;
1048   tiRoot_t           *tiRoot;
1049   bit32              offset = 0;
1050 
1051   TI_DBG7(("tdsmSingleThreadedLeave: start\n"));
1052 
1053   tdsaRoot = (tdsaRoot_t *)smRoot->tdData;
1054   if (tdsaRoot == agNULL)
1055   {
1056     TI_DBG1(("tdsmSingleThreadedLeave: tdsaRoot is NULL\n"));
1057     return;
1058   }
1059 
1060   tdsaAllShared = &(tdsaRoot->tdsaAllShared);
1061   if (tdsaAllShared == agNULL)
1062   {
1063     TI_DBG1(("tdsmSingleThreadedLeave: tdsaAllShared is NULL\n"));
1064     return;
1065   }
1066 
1067   tiRoot = tdsaAllShared->agRootOsDataForInt.tiRoot;
1068   if (tiRoot == agNULL)
1069   {
1070     TI_DBG1(("tdsmSingleThreadedLeave: tiRoot is NULL\n"));
1071     return;
1072   }
1073   offset = tdsaAllShared->MaxNumLLLocks + tdsaAllShared->MaxNumOSLocks + TD_MAX_LOCKS + tdsaAllShared->MaxNumDMLocks;
1074 
1075   ostiSingleThreadedLeave(tiRoot, syncLockId + offset);
1076 
1077   return;
1078 }
1079 
1080 osGLOBAL FORCEINLINE bit8
1081 tdsmBitScanForward(
1082                   smRoot_t    *smRoot,
1083                   bit32      *Index,
1084                   bit32       Mask
1085                   )
1086 {
1087     return ostiBitScanForward(agNULL, Index, Mask);
1088 }
1089 
1090 #ifdef LINUX_VERSION_CODE
1091 
1092 osGLOBAL FORCEINLINE sbit32
1093 tdsmInterlockedIncrement(
1094                    smRoot_t         *smRoot,
1095                    sbit32 volatile  *Addend
1096                    )
1097 {
1098    return ostiAtomicIncrement(agNULL, Addend);
1099 }
1100 
1101 osGLOBAL FORCEINLINE sbit32
1102 tdsmInterlockedDecrement(
1103                    smRoot_t         *smRoot,
1104                    sbit32 volatile  *Addend
1105                    )
1106 {
1107    return ostiAtomicDecrement(agNULL, Addend);
1108 }
1109 
1110 
1111 
1112 osGLOBAL FORCEINLINE sbit32
1113 tdsmAtomicBitClear(
1114                smRoot_t         *smRoot,
1115                sbit32 volatile  *Destination,
1116                sbit32            Value
1117                )
1118 {
1119    return ostiAtomicBitClear(agNULL, Destination, Value);
1120 }
1121 
1122 osGLOBAL FORCEINLINE sbit32
1123 tdsmAtomicBitSet(
1124                smRoot_t         *smRoot,
1125                sbit32 volatile  *Destination,
1126                sbit32            Value
1127                )
1128 {
1129    return ostiAtomicBitSet(agNULL, Destination, Value);
1130 }
1131 
1132 osGLOBAL FORCEINLINE sbit32
1133 tdsmAtomicExchange(
1134                smRoot_t         *smRoot,
1135                sbit32 volatile  *Target,
1136                sbit32            Value
1137                )
1138 {
1139     return ostiAtomicExchange(agNULL, Target, Value);
1140 }
1141 
1142 #else
1143 
1144 osGLOBAL FORCEINLINE sbit32
1145 tdsmInterlockedIncrement(
1146                    smRoot_t         *smRoot,
1147                    sbit32 volatile  *Addend
1148                    )
1149 {
1150    return ostiInterlockedIncrement(agNULL, Addend);
1151 }
1152 
1153 osGLOBAL FORCEINLINE sbit32
1154 tdsmInterlockedDecrement(
1155                    smRoot_t        *smRoot,
1156                    sbit32 volatile *Addend
1157                    )
1158 {
1159    return ostiInterlockedDecrement(agNULL, Addend);
1160 }
1161 
1162 
1163 
1164 osGLOBAL FORCEINLINE sbit32
1165 tdsmInterlockedAnd(
1166                smRoot_t        *smRoot,
1167                sbit32 volatile  *Destination,
1168                sbit32            Value
1169                )
1170 {
1171 
1172    return ostiInterlockedAnd(agNULL, Destination, Value);
1173 }
1174 
1175 osGLOBAL FORCEINLINE sbit32
1176 tdsmInterlockedOr(
1177                smRoot_t        *smRoot,
1178                sbit32 volatile  *Destination,
1179                sbit32            Value
1180                )
1181 {
1182    return ostiInterlockedOr(agNULL, Destination, Value);
1183 }
1184 
1185 osGLOBAL FORCEINLINE sbit32
1186 tdsmInterlockedExchange(
1187                smRoot_t          *smRoot,
1188                sbit32  volatile  *Target,
1189                sbit32             Value
1190                )
1191 {
1192     return ostiInterlockedExchange(agNULL, Target, Value);
1193 }
1194 
1195 #endif /*LINUX_VERSION_CODE*/
1196 
1197 osGLOBAL bit32
1198 tdsmAllocMemory(
1199                 smRoot_t    *smRoot,
1200                 void        **osMemHandle,
1201                 void        ** virtPtr,
1202                 bit32       * physAddrUpper,
1203                 bit32       * physAddrLower,
1204                 bit32       alignment,
1205                 bit32       allocLength,
1206                 smBOOLEAN   isCacheable
1207                )
1208 {
1209   tdsaRoot_t         *tdsaRoot;
1210   tdsaContext_t      *tdsaAllShared;
1211   tiRoot_t           *tiRoot;
1212   bit32               status;
1213 
1214   TI_DBG5(("tdsmAllocMemory: start\n"));
1215 
1216   tdsaRoot = (tdsaRoot_t *)smRoot->tdData;
1217   if (tdsaRoot == agNULL)
1218   {
1219     TI_DBG1(("tdsmAllocMemory: tdsaRoot is NULL\n"));
1220     return SM_RC_FAILURE;
1221   }
1222 
1223   tdsaAllShared = &(tdsaRoot->tdsaAllShared);
1224   if (tdsaAllShared == agNULL)
1225   {
1226     TI_DBG1(("tdsmAllocMemory: tdsaAllShared is NULL\n"));
1227     return SM_RC_FAILURE;
1228   }
1229 
1230   tiRoot = tdsaAllShared->agRootOsDataForInt.tiRoot;
1231   if (tiRoot == agNULL)
1232   {
1233     TI_DBG1(("tdsmAllocMemory: tiRoot is NULL\n"));
1234     return SM_RC_FAILURE;
1235   }
1236 
1237   status = ostiAllocMemory(tiRoot,
1238                            osMemHandle,
1239                            virtPtr,
1240                            physAddrUpper,
1241                            physAddrLower,
1242                            alignment,
1243                            allocLength,
1244                            isCacheable);
1245 
1246   if (status == tiSuccess)
1247   {
1248     return SM_RC_SUCCESS;
1249   }
1250   else
1251   {
1252     return SM_RC_FAILURE;
1253   }
1254 
1255 }
1256 
1257 osGLOBAL bit32
1258 tdsmFreeMemory(
1259                smRoot_t    *smRoot,
1260                void        *osDMAHandle,
1261                bit32       allocLength
1262               )
1263 {
1264   tdsaRoot_t         *tdsaRoot;
1265   tdsaContext_t      *tdsaAllShared;
1266   tiRoot_t           *tiRoot;
1267   bit32               status;
1268 
1269   TI_DBG5(("tdsmFreeMemory: start\n"));
1270 
1271   tdsaRoot = (tdsaRoot_t *)smRoot->tdData;
1272   if (tdsaRoot == agNULL)
1273   {
1274     TI_DBG1(("tdsmFreeMemory: tdsaRoot is NULL\n"));
1275     return SM_RC_FAILURE;
1276   }
1277 
1278   tdsaAllShared = &(tdsaRoot->tdsaAllShared);
1279   if (tdsaAllShared == agNULL)
1280   {
1281     TI_DBG1(("tdsmFreeMemory: tdsaAllShared is NULL\n"));
1282     return SM_RC_FAILURE;
1283   }
1284 
1285   tiRoot = tdsaAllShared->agRootOsDataForInt.tiRoot;
1286   if (tiRoot == agNULL)
1287   {
1288     TI_DBG1(("tdsmFreeMemory: tiRoot is NULL\n"));
1289     return SM_RC_FAILURE;
1290   }
1291 
1292   status = ostiFreeMemory(tiRoot,
1293                           osDMAHandle,
1294                           allocLength);
1295 
1296   if (status == tiSuccess)
1297   {
1298     return SM_RC_SUCCESS;
1299   }
1300   else
1301   {
1302     return SM_RC_FAILURE;
1303   }
1304 }
1305 
1306 FORCEINLINE bit32
1307 tdsmRotateQnumber(smRoot_t        *smRoot,
1308                          smDeviceHandle_t *smDeviceHandle
1309                          )
1310 {
1311   tdsaRoot_t         *tdsaRoot;
1312   tdsaContext_t      *tdsaAllShared;
1313   tiRoot_t           *tiRoot;
1314   tdsaDeviceData_t   *oneDeviceData;
1315   bit32              ret = 0;
1316 
1317   tdsaRoot = (tdsaRoot_t *)smRoot->tdData;
1318   tdsaAllShared = &(tdsaRoot->tdsaAllShared);
1319   tiRoot = tdsaAllShared->agRootOsDataForInt.tiRoot;
1320 
1321 
1322   TI_DBG6(("tdsmRotateQnumber: start\n"));
1323 
1324   if (smDeviceHandle == agNULL)
1325   {
1326      TI_DBG1(("tdsmRotateQnumber: smDeviceHandle is NULL !!!!\n"));
1327      return ret;
1328   }
1329   oneDeviceData = (tdsaDeviceData_t *)smDeviceHandle->tdData;
1330   if (oneDeviceData == agNULL)
1331   {
1332      TI_DBG1(("tdsmRotateQnumber: oneDeviceData is NULL !!!!\n"));
1333      return ret;
1334   }
1335   return tdsaRotateQnumber(tiRoot, oneDeviceData);
1336 }
1337 
1338 osGLOBAL bit32
1339 tdsmSetDeviceQueueDepth(smRoot_t      *smRoot,
1340                                  smIORequest_t  *smIORequest,
1341                                  bit32          QueueDepth
1342                                  )
1343 {
1344   tdsaRoot_t         *tdsaRoot      = agNULL;
1345   tdsaContext_t      *tdsaAllShared = agNULL;
1346   tiRoot_t           *tiRoot        = agNULL;
1347   tdIORequestBody_t  *tdIORequestBody  = (tdIORequestBody_t *)smIORequest->tdData;
1348   tiIORequest_t      *tiIORequest      = tdIORequestBody->tiIORequest;
1349 
1350 
1351   TI_DBG5(("tdsmSetDeviceQueueDepth: start\n"));
1352 
1353   tdsaRoot = (tdsaRoot_t *)smRoot->tdData;
1354   if (tdsaRoot == agNULL)
1355   {
1356     TI_DBG1(("tdsmSetDeviceQueueDepth: tdsaRoot is NULL\n"));
1357     return SM_RC_FAILURE;
1358   }
1359 
1360   tdsaAllShared = &(tdsaRoot->tdsaAllShared);
1361   if (tdsaAllShared == agNULL)
1362   {
1363     TI_DBG1(("tdsmSetDeviceQueueDepth: tdsaAllShared is NULL\n"));
1364     return SM_RC_FAILURE;
1365   }
1366 
1367   tiRoot = tdsaAllShared->agRootOsDataForInt.tiRoot;
1368   if (tiRoot == agNULL)
1369   {
1370     TI_DBG1(("tdsmFreeMemory: tiRoot is NULL\n"));
1371     return SM_RC_FAILURE;
1372   }
1373 
1374   return ostiSetDeviceQueueDepth(tiRoot, tiIORequest, QueueDepth);
1375 }
1376 
1377 osGLOBAL bit32 tdsmGetTransportParam(
1378                         smRoot_t    *smRoot,
1379                         char        *key,
1380                         char        *subkey1,
1381                         char        *subkey2,
1382                         char        *subkey3,
1383                         char        *subkey4,
1384                         char        *subkey5,
1385                         char        *valueName,
1386                         char        *buffer,
1387                         bit32       bufferLen,
1388                         bit32       *lenReceived
1389                         )
1390 {
1391   bit32              ret = tiError;
1392 
1393   TI_DBG7(("tdsmGetTransportParam: start\n"));
1394   ret = ostiGetTransportParam(agNULL,
1395                               key,
1396                               subkey1,
1397                               subkey2,
1398                               subkey3,
1399                               subkey4,
1400                               subkey5,
1401                               valueName,
1402                               buffer,
1403                               bufferLen,
1404                               lenReceived
1405                               );
1406   return ret;
1407 }
1408 #endif /* FDS_SM */
1409 
1410