1285242Sachim/*******************************************************************************
2285242Sachim*Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3285242Sachim*
4285242Sachim*Redistribution and use in source and binary forms, with or without modification, are permitted provided
5285242Sachim*that the following conditions are met:
6285242Sachim*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7285242Sachim*following disclaimer.
8285242Sachim*2. Redistributions in binary form must reproduce the above copyright notice,
9285242Sachim*this list of conditions and the following disclaimer in the documentation and/or other materials provided
10285242Sachim*with the distribution.
11285242Sachim*
12285242Sachim*THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13285242Sachim*WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14285242Sachim*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15285242Sachim*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16285242Sachim*NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17285242Sachim*BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18285242Sachim*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19285242Sachim*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20285242Sachim
21285242Sachim********************************************************************************/
22285242Sachim/*******************************************************************************/
23285242Sachim/** \file
24285242Sachim *
25285242Sachim *
26285242Sachim * This file contains TB misc. functions
27285242Sachim *
28285242Sachim */
29285242Sachim#include <sys/cdefs.h>
30285242Sachim__FBSDID("$FreeBSD$");
31285242Sachim#include <dev/pms/config.h>
32285242Sachim
33285242Sachim#include <dev/pms/freebsd/driver/common/osenv.h>
34285242Sachim#include <dev/pms/freebsd/driver/common/ostypes.h>
35285242Sachim#include <dev/pms/freebsd/driver/common/osdebug.h>
36285242Sachim
37285242Sachim#include <dev/pms/RefTisa/sallsdk/api/sa.h>
38285242Sachim#include <dev/pms/RefTisa/sallsdk/api/saapi.h>
39285242Sachim#include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
40285242Sachim
41285242Sachim#include <dev/pms/RefTisa/tisa/api/titypes.h>
42285242Sachim#include <dev/pms/RefTisa/tisa/api/ostiapi.h>
43285242Sachim#include <dev/pms/RefTisa/tisa/api/tiapi.h>
44285242Sachim#include <dev/pms/RefTisa/tisa/api/tiglobal.h>
45285242Sachim
46285242Sachim#ifdef FDS_SM
47285242Sachim#include <dev/pms/RefTisa/sat/api/sm.h>
48285242Sachim#include <dev/pms/RefTisa/sat/api/smapi.h>
49285242Sachim#include <dev/pms/RefTisa/sat/api/tdsmapi.h>
50285242Sachim#endif
51285242Sachim
52285242Sachim#ifdef FDS_DM
53285242Sachim#include <dev/pms/RefTisa/discovery/api/dm.h>
54285242Sachim#include <dev/pms/RefTisa/discovery/api/dmapi.h>
55285242Sachim#include <dev/pms/RefTisa/discovery/api/tddmapi.h>
56285242Sachim#endif
57285242Sachim
58285242Sachim#include <dev/pms/RefTisa/tisa/sassata/sas/common/tdtypes.h>
59285242Sachim#include <dev/pms/freebsd/driver/common/osstring.h>
60285242Sachim#include <dev/pms/RefTisa/tisa/sassata/common/tdutil.h>
61285242Sachim
62285242Sachim#ifdef INITIATOR_DRIVER
63285242Sachim#include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdtypes.h>
64285242Sachim#include <dev/pms/RefTisa/tisa/sassata/sas/ini/itddefs.h>
65285242Sachim#include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdglobl.h>
66285242Sachim#endif
67285242Sachim
68285242Sachim#ifdef TARGET_DRIVER
69285242Sachim#include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdglobl.h>
70285242Sachim#include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdxchg.h>
71285242Sachim#include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdtypes.h>
72285242Sachim#endif
73285242Sachim
74285242Sachim#include <dev/pms/RefTisa/tisa/sassata/common/tdsatypes.h>
75285242Sachim#include <dev/pms/RefTisa/tisa/sassata/common/tdproto.h>
76285242Sachim
77285242Sachim/*****************************************************************************
78285242Sachim*! \brief tiINIIOAbort
79285242Sachim*
80285242Sachim*  Purpose:  This function is called to abort an I/O request previously started
81285242Sachim*             by a call to tiINIIOStart() or tiINIIOStartDif() .
82285242Sachim*
83285242Sachim*  \param  tiRoot:          Pointer to initiator driver/port instance.
84285242Sachim*  \param  taskTag:         Pointer to the associated task to be aborted
85285242Sachim*
86285242Sachim*  \return:
87285242Sachim*
88285242Sachim*          tiSuccess:     I/O request successfully initiated.
89285242Sachim*          tiBusy:        No resources available, try again later.
90285242Sachim*          tiIONoDevice:  Invalid device handle.
91285242Sachim*          tiError:       Other errors that prevent the I/O request to be
92285242Sachim*                         started.
93285242Sachim*
94285242Sachim*****************************************************************************/
95285242Sachim#ifdef INITIATOR_DRIVER							/*TBD: INITIATOR SPECIFIC API in tiapi.h (TP)*/
96285242SachimosGLOBAL bit32
97285242SachimtiINIIOAbort(
98285242Sachim             tiRoot_t            *tiRoot,
99285242Sachim             tiIORequest_t       *taskTag
100285242Sachim             )
101285242Sachim{
102285242Sachim  tdsaRoot_t          *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
103285242Sachim  tdsaContext_t       *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
104285242Sachim  agsaRoot_t          *agRoot = agNULL;
105285242Sachim  tdIORequestBody_t   *tdIORequestBody = agNULL;
106285242Sachim  agsaIORequest_t     *agIORequest = agNULL;
107285242Sachim  bit32               sasStatus = AGSA_RC_FAILURE;
108285242Sachim  tdsaDeviceData_t    *oneDeviceData;
109285242Sachim  bit32               status= tiError;
110285242Sachim  agsaIORequest_t     *agAbortIORequest;
111285242Sachim  tdIORequestBody_t   *tdAbortIORequestBody;
112285242Sachim  bit32               PhysUpper32;
113285242Sachim  bit32               PhysLower32;
114285242Sachim  bit32               memAllocStatus;
115285242Sachim  void                *osMemHandle;
116285242Sachim  agsaDevHandle_t     *agDevHandle = agNULL;
117285242Sachim#ifdef FDS_SM
118285242Sachim  smRoot_t                    *smRoot;
119285242Sachim  tdIORequestBody_t           *ToBeAbortedtdIORequestBody;
120285242Sachim  smIORequest_t               *ToBeAborted = agNULL;
121285242Sachim#endif
122285242Sachim  TI_DBG2(("tiINIIOAbort: start\n"));
123285242Sachim
124285242Sachim  if(taskTag == agNULL)
125285242Sachim  {
126285242Sachim    TI_DBG1(("tiINIIOAbort: taskTag is NULL\n"));
127285242Sachim    return tiError;
128285242Sachim  }
129285242Sachim
130285242Sachim  agRoot          = &(tdsaAllShared->agRootNonInt);
131285242Sachim  tdIORequestBody = (tdIORequestBody_t *)taskTag->tdData;
132285242Sachim  agIORequest     = &(tdIORequestBody->agIORequest);
133285242Sachim  oneDeviceData   = tdIORequestBody->tiDevHandle->tdData;
134285242Sachim
135285242Sachim  if(oneDeviceData == agNULL)
136285242Sachim  {
137285242Sachim    TI_DBG1(("tiINIIOAbort: DeviceData is NULL\n"));
138285242Sachim    return tiSuccess;
139285242Sachim  }
140285242Sachim
141285242Sachim  agDevHandle = oneDeviceData->agDevHandle;
142285242Sachim
143285242Sachim  TI_DBG2(("tiINIIOAbort: did %d\n", oneDeviceData->id));
144285242Sachim
145285242Sachim  /* for hotplug */
146285242Sachim  if (oneDeviceData->valid != agTRUE || oneDeviceData->registered != agTRUE ||
147285242Sachim      oneDeviceData->tdPortContext == agNULL )
148285242Sachim  {
149285242Sachim    TI_DBG1(("tiINIIOAbort: NO Device did %d\n", oneDeviceData->id ));
150285242Sachim    TI_DBG1(("tiINIIOAbort: device AddrHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
151285242Sachim    TI_DBG1(("tiINIIOAbort: device AddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
152285242Sachim    return tiError;
153285242Sachim  }
154285242Sachim
155285242Sachim  /* allocating agIORequest for abort itself */
156285242Sachim  memAllocStatus = ostiAllocMemory(
157285242Sachim                                   tiRoot,
158285242Sachim                                   &osMemHandle,
159285242Sachim                                   (void **)&tdAbortIORequestBody,
160285242Sachim                                   &PhysUpper32,
161285242Sachim                                   &PhysLower32,
162285242Sachim                                   8,
163285242Sachim                                   sizeof(tdIORequestBody_t),
164285242Sachim                                   agTRUE
165285242Sachim                                   );
166285242Sachim  if (memAllocStatus != tiSuccess)
167285242Sachim  {
168285242Sachim    /* let os process IO */
169285242Sachim    TI_DBG1(("tiINIIOAbort: ostiAllocMemory failed...\n"));
170285242Sachim    return tiError;
171285242Sachim  }
172285242Sachim
173285242Sachim  if (tdAbortIORequestBody == agNULL)
174285242Sachim  {
175285242Sachim    /* let os process IO */
176285242Sachim    TI_DBG1(("tiINIIOAbort: ostiAllocMemory returned NULL tdAbortIORequestBody\n"));
177285242Sachim    return tiError;
178285242Sachim  }
179285242Sachim
180285242Sachim  /* setup task management structure */
181285242Sachim  tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle = osMemHandle;
182285242Sachim  /* setting callback */
183285242Sachim  tdAbortIORequestBody->IOCompletionFunc = itdssIOAbortedHandler;
184285242Sachim  tdAbortIORequestBody->tiDevHandle = tdIORequestBody->tiDevHandle;
185285242Sachim
186285242Sachim  /* initialize agIORequest */
187285242Sachim  agAbortIORequest = &(tdAbortIORequestBody->agIORequest);
188285242Sachim  agAbortIORequest->osData = (void *) tdAbortIORequestBody;
189285242Sachim  agAbortIORequest->sdkData = agNULL; /* LL takes care of this */
190285242Sachim
191285242Sachim  /* remember IO to be aborted */
192285242Sachim  tdAbortIORequestBody->tiIOToBeAbortedRequest = taskTag;
193285242Sachim
194285242Sachim  if (oneDeviceData->DeviceType == TD_SAS_DEVICE)
195285242Sachim  {
196285242Sachim    sasStatus = saSSPAbort(agRoot,
197285242Sachim                           agAbortIORequest,
198285242Sachim                           tdsaRotateQnumber(tiRoot, oneDeviceData),
199285242Sachim                           agDevHandle,
200285242Sachim                           0/* flag */,
201285242Sachim                           agIORequest,
202285242Sachim                           agNULL);
203285242Sachim
204285242Sachim    if (sasStatus == AGSA_RC_SUCCESS)
205285242Sachim    {
206285242Sachim      return tiSuccess;
207285242Sachim    }
208285242Sachim    else
209285242Sachim    {
210285242Sachim      return tiError;
211285242Sachim    }
212285242Sachim  }
213285242Sachim
214285242Sachim  else if (oneDeviceData->DeviceType == TD_SATA_DEVICE)
215285242Sachim  {
216285242Sachim    TI_DBG2(("tiINIIOAbort: calling satIOAbort() oneDeviceData=%p\n", oneDeviceData));
217285242Sachim#ifdef FDS_SM
218285242Sachim    smRoot = &(tdsaAllShared->smRoot);
219285242Sachim    if ( taskTag != agNULL)
220285242Sachim    {
221285242Sachim      ToBeAbortedtdIORequestBody = (tdIORequestBody_t *)taskTag->tdData;
222285242Sachim      ToBeAborted = &(ToBeAbortedtdIORequestBody->smIORequest);
223285242Sachim      status = smIOAbort(smRoot, ToBeAborted);
224285242Sachim      return status;
225285242Sachim    }
226285242Sachim    else
227285242Sachim    {
228285242Sachim      TI_DBG1(("tiINIIOAbort: taskTag is NULL!!!\n"));
229285242Sachim      return tiError;
230285242Sachim    }
231285242Sachim
232285242Sachim#else
233285242Sachim
234285242Sachim#ifdef SATA_ENABLE
235285242Sachim    status = satIOAbort(tiRoot, taskTag );
236285242Sachim#endif
237285242Sachim
238285242Sachim    return status;
239285242Sachim#endif /* else FDS_SM */
240285242Sachim  }
241285242Sachim
242285242Sachim  else
243285242Sachim  {
244285242Sachim    return tiError;
245285242Sachim  }
246285242Sachim
247285242Sachim}
248285242Sachim
249285242SachimosGLOBAL bit32
250285242SachimtiINIIOAbortAll(
251285242Sachim             tiRoot_t            *tiRoot,
252285242Sachim             tiDeviceHandle_t    *tiDeviceHandle
253285242Sachim             )
254285242Sachim{
255285242Sachim  agsaRoot_t          *agRoot = agNULL;
256285242Sachim  tdsaDeviceData_t    *oneDeviceData = agNULL;
257285242Sachim  bit32               status = tiError;
258285242Sachim#ifdef FDS_SM
259285242Sachim  tdsaRoot_t          *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
260285242Sachim  tdsaContext_t       *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
261285242Sachim  smRoot_t            *smRoot = &(tdsaAllShared->smRoot);
262285242Sachim  smDeviceHandle_t    *smDeviceHandle;
263285242Sachim#endif
264285242Sachim
265285242Sachim  TI_DBG1(("tiINIIOAbortAll: start\n"));
266285242Sachim
267285242Sachim  if (tiDeviceHandle == agNULL)
268285242Sachim  {
269285242Sachim    TI_DBG1(("tiINIIOAbortAll: tiDeviceHandle is NULL!!!\n"));
270285242Sachim    return tiError;
271285242Sachim  }
272285242Sachim
273285242Sachim  oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
274285242Sachim
275285242Sachim  if (oneDeviceData == agNULL)
276285242Sachim  {
277285242Sachim    TI_DBG1(("tiINIIOAbortAll: oneDeviceData is NULL!!!\n"));
278285242Sachim    return tiError;
279285242Sachim  }
280285242Sachim
281285242Sachim  /* for hotplug */
282285242Sachim  if (oneDeviceData->valid != agTRUE || oneDeviceData->registered != agTRUE ||
283285242Sachim      oneDeviceData->tdPortContext == agNULL )
284285242Sachim  {
285285242Sachim    TI_DBG1(("tiINIIOAbortAll: NO Device did %d\n", oneDeviceData->id ));
286285242Sachim    TI_DBG1(("tiINIIOAbortAll: device AddrHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
287285242Sachim    TI_DBG1(("tiINIIOAbortAll: device AddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
288285242Sachim    return tiError;
289285242Sachim  }
290285242Sachim
291285242Sachim  agRoot = oneDeviceData->agRoot;
292285242Sachim
293285242Sachim  if (agRoot == agNULL)
294285242Sachim  {
295285242Sachim    TI_DBG1(("tiINIIOAbortAll: agRoot is NULL!!!\n"));
296285242Sachim    return tiError;
297285242Sachim  }
298285242Sachim
299285242Sachim  /* this is processed in ossaSSPAbortCB, ossaSATAAbortCB, ossaSMPAbortCB */
300285242Sachim  if (oneDeviceData->OSAbortAll == agTRUE)
301285242Sachim  {
302285242Sachim    TI_DBG1(("tiINIIOAbortAll: already pending!!!\n"));
303285242Sachim    return tiBusy;
304285242Sachim  }
305285242Sachim  else
306285242Sachim  {
307285242Sachim    oneDeviceData->OSAbortAll = agTRUE;
308285242Sachim  }
309285242Sachim
310285242Sachim#ifdef FDS_SM
311285242Sachim  if ( DEVICE_IS_SSP_TARGET(oneDeviceData) || DEVICE_IS_SMP_TARGET(oneDeviceData))
312285242Sachim  {
313285242Sachim    status = tdsaAbortAll(tiRoot, agRoot, oneDeviceData);
314285242Sachim  }
315285242Sachim  else if (DEVICE_IS_SATA_DEVICE(oneDeviceData) ||
316285242Sachim           DEVICE_IS_STP_TARGET(oneDeviceData)
317285242Sachim          )
318285242Sachim  {
319285242Sachim    TI_DBG2(("tiINIIOAbortAll: calling smIOAbortAll\n"));
320285242Sachim    smDeviceHandle = (smDeviceHandle_t *)&(oneDeviceData->smDeviceHandle);
321285242Sachim    smDeviceHandle->tdData = oneDeviceData;
322285242Sachim    status = smIOAbortAll(smRoot, smDeviceHandle);
323285242Sachim  }
324285242Sachim  else
325285242Sachim  {
326285242Sachim    TI_DBG1(("tiINIIOAbortAll: unknow device type!!! 0x%x\n", oneDeviceData->target_ssp_stp_smp));
327285242Sachim    status = AGSA_RC_FAILURE;
328285242Sachim  }
329285242Sachim#else
330285242Sachim  status = tdsaAbortAll(tiRoot, agRoot, oneDeviceData);
331285242Sachim#endif
332285242Sachim
333285242Sachim  return status;
334285242Sachim
335285242Sachim}
336285242Sachim#endif /* INITIATOR_DRIVER	*/
337285242Sachim
338285242Sachim/*****************************************************************************
339285242Sachim*! \brief tdsaAbortAll
340285242Sachim*
341285242Sachim*  Purpose:  This function is called to abort an all pending I/O request on a
342285242Sachim*            device
343285242Sachim*
344285242Sachim*  \param  tiRoot:          Pointer to initiator driver/port instance.
345285242Sachim*  \param  agRoot:          Pointer to chip/driver Instance.
346285242Sachim*  \param  oneDeviceData:   Pointer to the device
347285242Sachim*
348285242Sachim*  \return:
349285242Sachim*
350285242Sachim*          None
351285242Sachim*
352285242Sachim*****************************************************************************/
353285242SachimosGLOBAL bit32
354285242SachimtdsaAbortAll(
355285242Sachim             tiRoot_t                   *tiRoot,
356285242Sachim             agsaRoot_t                 *agRoot,
357285242Sachim             tdsaDeviceData_t           *oneDeviceData
358285242Sachim             )
359285242Sachim{
360285242Sachim  agsaIORequest_t     *agAbortIORequest = agNULL;
361285242Sachim  tdIORequestBody_t   *tdAbortIORequestBody = agNULL;
362285242Sachim  bit32               PhysUpper32;
363285242Sachim  bit32               PhysLower32;
364285242Sachim  bit32               memAllocStatus;
365285242Sachim  void                *osMemHandle;
366285242Sachim  bit32               status = AGSA_RC_FAILURE;
367285242Sachim
368285242Sachim  TI_DBG1(("tdsaAbortAll: did %d\n", oneDeviceData->id));
369285242Sachim
370285242Sachim  /* allocating agIORequest for abort itself */
371285242Sachim  memAllocStatus = ostiAllocMemory(
372285242Sachim                                   tiRoot,
373285242Sachim                                   &osMemHandle,
374285242Sachim                                   (void **)&tdAbortIORequestBody,
375285242Sachim                                   &PhysUpper32,
376285242Sachim                                   &PhysLower32,
377285242Sachim                                   8,
378285242Sachim                                   sizeof(tdIORequestBody_t),
379285242Sachim                                   agTRUE
380285242Sachim                                   );
381285242Sachim  if (memAllocStatus != tiSuccess)
382285242Sachim  {
383285242Sachim    /* let os process IO */
384285242Sachim    TI_DBG1(("tdsaAbortAll: ostiAllocMemory failed...\n"));
385285242Sachim    return tiError;
386285242Sachim  }
387285242Sachim
388285242Sachim  if (tdAbortIORequestBody == agNULL)
389285242Sachim  {
390285242Sachim    /* let os process IO */
391285242Sachim    TI_DBG1(("tdsaAbortAll: ostiAllocMemory returned NULL tdAbortIORequestBody\n"));
392285242Sachim    return tiError;
393285242Sachim  }
394285242Sachim
395285242Sachim  /* setup task management structure */
396285242Sachim  tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle = osMemHandle;
397285242Sachim  /* setting callback but not used later */
398285242Sachim  tdAbortIORequestBody->IOCompletionFunc = agNULL;
399285242Sachim  //tdAbortIORequestBody->IOCompletionFunc = itdssIOAbortedHandler;
400285242Sachim
401285242Sachim  tdAbortIORequestBody->tiDevHandle = (tiDeviceHandle_t *)&(oneDeviceData->tiDeviceHandle);
402285242Sachim
403285242Sachim  /* initialize agIORequest */
404285242Sachim  agAbortIORequest = &(tdAbortIORequestBody->agIORequest);
405285242Sachim  agAbortIORequest->osData = (void *) tdAbortIORequestBody;
406285242Sachim  agAbortIORequest->sdkData = agNULL; /* LL takes care of this */
407285242Sachim
408285242Sachim  if ( DEVICE_IS_SSP_TARGET(oneDeviceData))
409285242Sachim  {
410285242Sachim    /* SSPAbort */
411285242Sachim    status = saSSPAbort(agRoot,
412285242Sachim                        agAbortIORequest,
413285242Sachim                        tdsaRotateQnumber(tiRoot, oneDeviceData), //0,
414285242Sachim                        oneDeviceData->agDevHandle,
415285242Sachim                        1, /* abort all */
416285242Sachim                        agNULL,
417285242Sachim                        agNULL
418285242Sachim                        );
419285242Sachim  }
420285242Sachim  else if (DEVICE_IS_SATA_DEVICE(oneDeviceData) ||
421285242Sachim           DEVICE_IS_STP_TARGET(oneDeviceData)
422285242Sachim          )
423285242Sachim  {
424285242Sachim    /* SATAAbort*/
425285242Sachim    if (oneDeviceData->satDevData.IDDeviceValid == agFALSE)
426285242Sachim    {
427285242Sachim      TI_DBG2(("tdsaAbortAll: saSATAAbort\n"));
428285242Sachim      status = saSATAAbort(agRoot,
429285242Sachim                           agAbortIORequest,
430285242Sachim                           0,
431285242Sachim                           oneDeviceData->agDevHandle,
432285242Sachim                           1, /* abort all */
433285242Sachim                           agNULL,
434285242Sachim                           agNULL
435285242Sachim                           );
436285242Sachim    }
437285242Sachim    else
438285242Sachim    {
439285242Sachim      TI_DBG2(("tdsaAbortAll: saSATAAbort IDDeviceValid\n"));
440285242Sachim      status = saSATAAbort(agRoot,
441285242Sachim                           agAbortIORequest,
442285242Sachim                           tdsaRotateQnumber(tiRoot, oneDeviceData), //0,
443285242Sachim                           oneDeviceData->agDevHandle,
444285242Sachim                           1, /* abort all */
445285242Sachim                           agNULL,
446285242Sachim                           agNULL
447285242Sachim                           );
448285242Sachim    }
449285242Sachim  }
450285242Sachim  else if (DEVICE_IS_SMP_TARGET(oneDeviceData))
451285242Sachim  {
452285242Sachim    /* SMPAbort*/
453285242Sachim    TI_DBG2(("tdsaAbortAll: saSMPAbort \n"));
454285242Sachim    status = saSMPAbort(agRoot,
455285242Sachim                        agAbortIORequest,
456285242Sachim                        tdsaRotateQnumber(tiRoot, oneDeviceData), //0,
457285242Sachim                        oneDeviceData->agDevHandle,
458285242Sachim                        1, /* abort all */
459285242Sachim                        agNULL,
460285242Sachim                        agNULL
461285242Sachim                        );
462285242Sachim  }
463285242Sachim  else
464285242Sachim  {
465285242Sachim    TI_DBG1(("tdsaAbortAll: unknown device type!!! 0x%x\n", oneDeviceData->target_ssp_stp_smp));
466285242Sachim    status = AGSA_RC_FAILURE;
467285242Sachim  }
468285242Sachim
469285242Sachim  if (status == AGSA_RC_SUCCESS)
470285242Sachim  {
471285242Sachim    return tiSuccess;
472285242Sachim  }
473285242Sachim  else
474285242Sachim  {
475285242Sachim    TI_DBG1(("tdsaAbortAll: failed status=%d\n", status));
476285242Sachim    //failed to send abort command, we need to free the memory
477285242Sachim    ostiFreeMemory(
478285242Sachim               tiRoot,
479285242Sachim               tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle,
480285242Sachim               sizeof(tdIORequestBody_t)
481285242Sachim               );
482285242Sachim    return tiError;
483285242Sachim  }
484285242Sachim
485285242Sachim}
486285242Sachim
487285242Sachim
488285242Sachim
489285242Sachim/*****************************************************************************
490285242Sachim*! \brief tiCOMReset
491285242Sachim*
492285242Sachim*  Purpose:  This function is called to trigger soft or hard reset
493285242Sachim*
494285242Sachim*  \param  tiRoot:          Pointer to initiator driver/port instance.
495285242Sachim*  \param  option:          Options
496285242Sachim*
497285242Sachim*  \return:
498285242Sachim*
499285242Sachim*          None
500285242Sachim*
501285242Sachim*****************************************************************************/
502285242SachimosGLOBAL void
503285242SachimtiCOMReset(
504285242Sachim           tiRoot_t    *tiRoot,
505285242Sachim           bit32       option
506285242Sachim           )
507285242Sachim{
508285242Sachim  tdsaRoot_t                *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
509285242Sachim  tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
510285242Sachim  agsaRoot_t                *agRoot = agNULL;
511285242Sachim
512285242Sachim
513285242Sachim#ifdef TI_GETFOR_ONRESET
514285242Sachim  agsaControllerStatus_t controllerStatus;
515285242Sachim  agsaForensicData_t         forensicData;
516285242Sachim  bit32 once = 1;
517285242Sachim  bit32 status;
518285242Sachim#endif /* TI_GETFOR_ONRESET */
519285242Sachim
520285242Sachim  TI_DBG1(("tiCOMReset: start option 0x%x\n",option));
521285242Sachim  tdsaAllShared->resetCount++;
522285242Sachim  TI_DBG2(("tiCOMReset: reset count %d\n", tdsaAllShared->resetCount));
523285242Sachim
524285242Sachim  agRoot = &(tdsaAllShared->agRootNonInt);
525285242Sachim
526285242Sachim  if (tdsaAllShared->flags.resetInProgress == agTRUE)
527285242Sachim  {
528285242Sachim    TI_DBG1(("tiCOMReset : Reset is already in progress : \n"));
529285242Sachim
530285242Sachim    /* don't do anything : just return */
531285242Sachim    return;
532285242Sachim  }
533285242Sachim
534285242Sachim  tdsaAllShared->flags.resetInProgress            = agTRUE;
535285242Sachim
536285242Sachim#ifdef TI_GETFOR_ONRESET
537285242Sachim  saGetControllerStatus(agRoot, &controllerStatus);
538285242Sachim  if(controllerStatus.fatalErrorInfo.errorInfo1)
539285242Sachim  {
540285242Sachim
541285242Sachim    bit8 * DirectData = (bit8 * )tdsaAllShared->FatalErrorData;
542285242Sachim    forensicData.DataType = TYPE_FATAL;
543285242Sachim    forensicData.dataBuf.directLen =  (8 * 1024);
544285242Sachim    forensicData.dataBuf.directOffset = 0; /* current offset */
545285242Sachim    forensicData.dataBuf.readLen = 0;   /* Data read */
546285242Sachim    getmoreData:
547285242Sachim    forensicData.dataBuf.directData = DirectData;
548285242Sachim    status = saGetForensicData( agRoot, agNULL, &forensicData);
549285242Sachim    TI_DBG1(("tiCOMReset:status %d readLen 0x%x directLen 0x%x directOffset 0x%x\n",
550285242Sachim      status,
551285242Sachim      forensicData.dataBuf.readLen,
552285242Sachim      forensicData.dataBuf.directLen,
553285242Sachim      forensicData.dataBuf.directOffset));
554285242Sachim
555285242Sachim    if( forensicData.dataBuf.readLen == forensicData.dataBuf.directLen && !status && once)
556285242Sachim    {
557285242Sachim       DirectData += forensicData.dataBuf.readLen;
558285242Sachim      goto getmoreData;
559285242Sachim    }
560285242Sachim    TI_DBG1(("tiCOMReset:saGetForensicData type %d read 0x%x bytes\n",    forensicData.DataType,    forensicData.dataBuf.directOffset ));
561285242Sachim  }
562285242Sachim
563285242Sachim#endif /* TI_GETFOR_ONRESET */
564285242Sachim  if (option == tiSoftReset)
565285242Sachim  {
566285242Sachim    /* soft reset */
567285242Sachim    TI_DBG6(("tiCOMReset: soft reset\n"));
568285242Sachim    saHwReset(agRoot, AGSA_SOFT_RESET, 0);
569285242Sachim    return;
570285242Sachim  }
571285242Sachim  else
572285242Sachim  {
573285242Sachim    saHwReset(agRoot, AGSA_SOFT_RESET, 0);
574285242Sachim#ifdef NOT_YET
575285242Sachim    /* hard reset */
576285242Sachim    saHwReset(agRoot, AGSA_CHIP_RESET, 0);
577285242Sachim#endif
578285242Sachim  }
579285242Sachim  return;
580285242Sachim}
581285242Sachim
582285242Sachim
583285242Sachim/*****************************************************************************/
584285242Sachim/*! \biref tiINIReportErrorToEventLog
585285242Sachim *
586285242Sachim *  Purpose: This function is called to report errors that needs to be logged
587285242Sachim *           into event log.
588285242Sachim *
589285242Sachim *  \param tiRoot:      Pointer to initiator specific root data structure  for this
590285242Sachim *                      instance of the driver.
591285242Sachim *  \param agEventData: Event data structure.
592285242Sachim *
593285242Sachim *  \return None.
594285242Sachim *
595285242Sachim */
596285242Sachim/*****************************************************************************/
597285242Sachim#ifdef INITIATOR_DRIVER
598285242SachimosGLOBAL bit32
599285242SachimtiINIReportErrorToEventLog(
600285242Sachim                           tiRoot_t            *tiRoot,
601285242Sachim                           tiEVTData_t         *agEventData
602285242Sachim                           )
603285242Sachim{
604285242Sachim  TI_DBG6(("tiINIReportErrorToEventLog: start\n"));
605285242Sachim  return tiError;
606285242Sachim}
607285242Sachim#endif /* INITIATOR_DRIVER */
608285242Sachim
609285242Sachim/*****************************************************************************/
610285242Sachim/*! \brief ossaReenableInterrupts
611285242Sachim *
612285242Sachim *
613285242Sachim *  Purpose: This routine is called to enable interrupt
614285242Sachim *
615285242Sachim *
616285242Sachim *  \param  agRoot:               Pointer to chip/driver Instance.
617285242Sachim *  \param  outboundChannelNum:   Zero-base channel number
618285242Sachim *
619285242Sachim *
620285242Sachim *  \return None.
621285242Sachim *
622285242Sachim *  \note - The scope is shared target and initiator.
623285242Sachim *
624285242Sachim */
625285242Sachim/*****************************************************************************/
626285242Sachim#ifndef ossaReenableInterrupts
627285242SachimosGLOBAL void
628285242SachimossaReenableInterrupts(
629285242Sachim                       agsaRoot_t  *agRoot,
630285242Sachim                       bit32       outboundChannelNum
631285242Sachim                       )
632285242Sachim{
633285242Sachim  tdsaRootOsData_t *osData = (tdsaRootOsData_t *) (agRoot->osData);
634285242Sachim
635285242Sachim  ostiInterruptEnable(
636285242Sachim                      osData->tiRoot,
637285242Sachim                      outboundChannelNum
638285242Sachim                      );
639285242Sachim  return;
640285242Sachim}
641285242Sachim
642285242Sachim#endif
643285242Sachim
644285242Sachim
645285242Sachim
646285242Sachim
647285242Sachim/*
648285242Sachim1. initiator
649285242Sachim   send task management
650285242Sachim   call saSSPAbort()
651285242Sachim
652285242Sachim2. Target
653285242Sachim   call saSSPAbort()
654285242Sachim
655285242Sachim*/
656285242Sachim
657285242Sachim/*****************************************************************************
658285242Sachim*! \brief tiINITaskManagement
659285242Sachim*
660285242Sachim* Purpose:  This routine is called to explicitly ask the Transport Dependent
661285242Sachim*           Layer to issue a Task Management command to a device.
662285242Sachim*
663285242Sachim*  \param tiRoot:         Pointer to driver instance
664285242Sachim*  \param tiDeviveHandle: Pointer to the device handle for this session.
665285242Sachim*  \param task:           SAM-2 task management request.
666285242Sachim*  \param lun:            Pointer to the SCSI-3 LUN information
667285242Sachim*                         when applicable. Set to zero when not applicable.
668285242Sachim*  \param taskTag:        Pointer to the associated task where the task
669285242Sachim*                         management command is to be applied. Set to agNULL
670285242Sachim*                         if not applicable for the specific Task Management
671285242Sachim*                         task.
672285242Sachim*  \param currentTaskTag: The current context or task tag for this task. This
673285242Sachim*                         task tag will be passed back in ostiInitiatorEvent()
674285242Sachim*                         when this task management is completed.
675285242Sachim*
676285242Sachim*  \return:
677285242Sachim*         tiSuccess     TM request successfully initiated.
678285242Sachim*         tiBusy        No resources available, try again later.
679285242Sachim*         tiIONoDevice  Invalid device handle.
680285242Sachim*         tiError       Other errors that prevent the TM request to be started.
681285242Sachim*
682285242Sachim*****************************************************************************/
683285242Sachim/*
684285242Sachim  warm reset->smp phy control(hard reset) or saLocalPhyControl(AGSA_PHY_HARD_RESET)
685285242Sachim
686285242Sachim*/
687285242Sachim#ifdef INITIATOR_DRIVER
688285242SachimosGLOBAL bit32
689285242SachimtiINITaskManagement (
690285242Sachim                     tiRoot_t          *tiRoot,
691285242Sachim                     tiDeviceHandle_t  *tiDeviceHandle,
692285242Sachim                     bit32             task,
693285242Sachim                     tiLUN_t           *lun,
694285242Sachim                     tiIORequest_t     *taskTag, /* being aborted one */
695285242Sachim                     tiIORequest_t     *currentTaskTag /* task management itself */
696285242Sachim                     )
697285242Sachim{
698285242Sachim
699285242Sachim  tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
700285242Sachim  tdsaContext_t               *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
701285242Sachim  itdsaIni_t                  *Initiator = (itdsaIni_t *)tdsaAllShared->itdsaIni;
702285242Sachim  agsaRoot_t                  *agRoot = agNULL;
703285242Sachim  bit32                       tiStatus = tiError;
704285242Sachim  bit32                       notImplemented = agFALSE;
705285242Sachim  tdsaDeviceData_t            *oneDeviceData = agNULL;
706285242Sachim  void                        *osMemHandle;
707285242Sachim  tdIORequestBody_t           *TMtdIORequestBody;
708285242Sachim  bit32                       PhysUpper32;
709285242Sachim  bit32                       PhysLower32;
710285242Sachim  bit32                       memAllocStatus;
711285242Sachim  bit32                       agRequestType;
712285242Sachim  agsaIORequest_t             *agIORequest = agNULL; /* task management itself */
713285242Sachim  agsaIORequest_t             *agTMRequest = agNULL; /* IO being task managed */
714285242Sachim  agsaDevHandle_t             *agDevHandle = agNULL;
715285242Sachim  agsaSASRequestBody_t        *agSASRequestBody = agNULL;
716285242Sachim  agsaSSPScsiTaskMgntReq_t    *agSSPTaskMgntRequest;
717285242Sachim  bit32                       saStatus;
718285242Sachim  tdIORequestBody_t           *tdIORequestBody;
719285242Sachim#ifdef FDS_SM
720285242Sachim  smRoot_t                    *smRoot;
721285242Sachim  smDeviceHandle_t            *smDeviceHandle;
722285242Sachim  smIORequest_t               *ToBeAborted = agNULL;
723285242Sachim  smIORequest_t               *TaskManagement;
724285242Sachim  tdIORequestBody_t           *ToBeAbortedtdIORequestBody;
725285242Sachim  tdIORequestBody_t           *SMTMtdIORequestBody;
726285242Sachim  void                        *SMosMemHandle;
727285242Sachim  bit32                       SMPhysUpper32;
728285242Sachim  bit32                       SMPhysLower32;
729285242Sachim  bit32                       SMmemAllocStatus;
730285242Sachim#endif
731285242Sachim
732285242Sachim  TI_DBG2(("tiINITaskManagement: start\n"));
733285242Sachim
734285242Sachim  /* just for testing only */
735285242Sachim#ifdef REMOVED
736285242Sachim//start temp
737285242Sachim  if(tiDeviceHandle == agNULL)
738285242Sachim  {
739285242Sachim    TI_DBG1(("tiINITaskManagement: tiDeviceHandle is NULL\n"));
740285242Sachim    return tiError;
741285242Sachim  }
742285242Sachim
743285242Sachim  oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
744285242Sachim  if(oneDeviceData == agNULL)
745285242Sachim  {
746285242Sachim    TI_DBG1(("tiINITaskManagement: tiDeviceHandle=%p DeviceData is NULL\n", tiDeviceHandle));
747285242Sachim    return tiError;
748285242Sachim  }
749285242Sachim  TI_DBG1(("tiINITaskManagement: did %d\n", oneDeviceData->id ));
750285242Sachim  return tiError;
751285242Sachim//end temp
752285242Sachim
753285242Sachim// just for testing
754285242Sachim  if (task == AG_LOGICAL_UNIT_RESET)
755285242Sachim  {
756285242Sachim    TI_DBG1(("tiINITaskManagement: failing LUN RESET for testing\n"));
757285242Sachim    return tiError;
758285242Sachim  }
759285242Sachim
760285242Sachim#endif
761285242Sachim
762285242Sachim  switch(task)
763285242Sachim  {
764285242Sachim  case AG_ABORT_TASK:
765285242Sachim    TI_DBG6(("tiINITaskManagement: ABORT_TASK\n"));
766285242Sachim    break;
767285242Sachim  case AG_ABORT_TASK_SET:
768285242Sachim    TI_DBG6(("tiINITaskManagement: ABORT_TASK_SET\n"));
769285242Sachim    break;
770285242Sachim  case AG_CLEAR_ACA:
771285242Sachim    TI_DBG6(("tiINITaskManagement: CLEAR_ACA\n"));
772285242Sachim    break;
773285242Sachim  case AG_CLEAR_TASK_SET:
774285242Sachim    TI_DBG6(("tiINITaskManagement: CLEAR_TASK_SET\n"));
775285242Sachim    break;
776285242Sachim  case AG_LOGICAL_UNIT_RESET:
777285242Sachim    TI_DBG6(("tiINITaskManagement: LOGICAL_UNIT_RESET\n"));
778285242Sachim    break;
779285242Sachim  case AG_TARGET_WARM_RESET:
780285242Sachim    TI_DBG6(("tiINITaskManagement: TARGET_WARM_RESET\n"));
781285242Sachim    break;
782285242Sachim  case AG_QUERY_TASK:
783285242Sachim    TI_DBG6(("tiINITaskManagement: QUERY_TASK\n"));
784285242Sachim    break;
785285242Sachim  default:
786285242Sachim    TI_DBG1(("tiINITaskManagement: notImplemented 0x%0x !!!\n",task));
787285242Sachim    notImplemented = agTRUE;
788285242Sachim    break;
789285242Sachim  }
790285242Sachim
791285242Sachim  if (notImplemented)
792285242Sachim  {
793285242Sachim    TI_DBG1(("tiINITaskManagement: not implemented 0x%0x !!!\n",task));
794285242Sachim    return tiStatus;
795285242Sachim  }
796285242Sachim
797285242Sachim  if(tiDeviceHandle == agNULL)
798285242Sachim  {
799285242Sachim    TI_DBG1(("tiINITaskManagement: tiDeviceHandle is NULL\n"));
800285242Sachim    return tiError;
801285242Sachim  }
802285242Sachim
803285242Sachim  oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
804285242Sachim  if(oneDeviceData == agNULL)
805285242Sachim  {
806285242Sachim    TI_DBG1(("tiINITaskManagement: tiDeviceHandle=%p DeviceData is NULL\n", tiDeviceHandle));
807285242Sachim    return tiIONoDevice;
808285242Sachim  }
809285242Sachim
810285242Sachim  /* for hotplug */
811285242Sachim  if (oneDeviceData->valid != agTRUE || oneDeviceData->registered != agTRUE ||
812285242Sachim      oneDeviceData->tdPortContext == agNULL )
813285242Sachim  {
814285242Sachim    TI_DBG1(("tiINITaskManagement: NO Device did %d Addr 0x%08x:0x%08x\n", oneDeviceData->id , oneDeviceData->SASAddressID.sasAddressHi, oneDeviceData->SASAddressID.sasAddressLo));
815285242Sachim    return tiIONoDevice;
816285242Sachim  }
817285242Sachim
818285242Sachim  /* 1. call tiINIOAbort()
819285242Sachim     2. call tdssTaskXmit()
820285242Sachim  */
821285242Sachim
822285242Sachim  if (oneDeviceData->DeviceType == TD_SAS_DEVICE)
823285242Sachim  {
824285242Sachim    agRoot = oneDeviceData->agRoot;
825285242Sachim    agDevHandle = oneDeviceData->agDevHandle;
826285242Sachim    TI_DBG1(("tiINITaskManagement: SAS Device\n"));
827285242Sachim
828285242Sachim    /*
829285242Sachim      WARM_RESET is experimental code.
830285242Sachim      Needs more testing and debugging
831285242Sachim    */
832285242Sachim    if (task == AG_TARGET_WARM_RESET)
833285242Sachim    {
834285242Sachim      agsaContext_t           *agContext;
835285242Sachim      tdsaDeviceData_t        *tdsaDeviceData;
836285242Sachim
837285242Sachim      tdsaDeviceData  = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
838285242Sachim      currentTaskTag->tdData = tdsaDeviceData;
839285242Sachim      agContext = &(tdsaDeviceData->agDeviceResetContext);
840285242Sachim      agContext->osData = currentTaskTag;
841285242Sachim
842285242Sachim      TI_DBG2(("tiINITaskManagement: did %d device reset for SAS\n", oneDeviceData->id));
843285242Sachim      saSetDeviceState(agRoot, agNULL, tdsaRotateQnumber(tiRoot, oneDeviceData), agDevHandle, SA_DS_IN_RECOVERY);
844285242Sachim
845285242Sachim      /* warm reset by saLocalPhyControl or SMP PHY control */
846285242Sachim      if (oneDeviceData->directlyAttached == agTRUE)
847285242Sachim      {
848285242Sachim        TI_DBG2(("tiINITaskManagement: device reset directly attached\n"));
849285242Sachim        saLocalPhyControl(agRoot,
850285242Sachim                          agContext,
851285242Sachim                          tdsaRotateQnumber(tiRoot, oneDeviceData),
852285242Sachim                          oneDeviceData->phyID,
853285242Sachim                          AGSA_PHY_HARD_RESET,
854285242Sachim                          agNULL
855285242Sachim                          );
856285242Sachim        return tiSuccess;
857285242Sachim      }
858285242Sachim      else
859285242Sachim      {
860285242Sachim        TI_DBG2(("tiINITaskManagement: device reset expander attached\n"));
861285242Sachim        saStatus = tdsaPhyControlSend(tiRoot,
862285242Sachim                                      oneDeviceData,
863285242Sachim                                      SMP_PHY_CONTROL_HARD_RESET,
864285242Sachim                                      currentTaskTag,
865285242Sachim                                      tdsaRotateQnumber(tiRoot, oneDeviceData)
866285242Sachim                                     );
867285242Sachim        return saStatus;
868285242Sachim      }
869285242Sachim    }
870285242Sachim    else
871285242Sachim    {
872285242Sachim      /* task management */
873285242Sachim      TI_DBG6(("tiINITaskManagement: making task management frame \n"));
874285242Sachim      /* 1. create task management frame
875285242Sachim         2. sends it using "saSSPStart()"
876285242Sachim      */
877285242Sachim      /* Allocate memory for task management */
878285242Sachim      memAllocStatus = ostiAllocMemory(
879285242Sachim                                       tiRoot,
880285242Sachim                                       &osMemHandle,
881285242Sachim                                       (void **)&TMtdIORequestBody,
882285242Sachim                                       &PhysUpper32,
883285242Sachim                                       &PhysLower32,
884285242Sachim                                       8,
885285242Sachim                                       sizeof(tdIORequestBody_t),
886285242Sachim                                       agTRUE
887285242Sachim                                       );
888285242Sachim
889285242Sachim      if (memAllocStatus != tiSuccess)
890285242Sachim      {
891285242Sachim        TI_DBG1(("tiINITaskManagement: ostiAllocMemory failed...\n"));
892285242Sachim        return tiError;
893285242Sachim      }
894285242Sachim
895285242Sachim      if (TMtdIORequestBody == agNULL)
896285242Sachim      {
897285242Sachim        TI_DBG1(("tiINITaskManagement: ostiAllocMemory returned NULL TMIORequestBody\n"));
898285242Sachim        return tiError;
899285242Sachim      }
900285242Sachim
901285242Sachim      /* initialize */
902285242Sachim      osti_memset(TMtdIORequestBody, 0, sizeof(tdIORequestBody_t));
903285242Sachim
904285242Sachim      /* setup task management structure */
905285242Sachim      TMtdIORequestBody->IOType.InitiatorTMIO.osMemHandle = osMemHandle;
906285242Sachim      TMtdIORequestBody->IOType.InitiatorTMIO.CurrentTaskTag = currentTaskTag;
907285242Sachim      TMtdIORequestBody->IOType.InitiatorTMIO.TaskTag = taskTag;
908285242Sachim
909285242Sachim      /* let's initialize tdIOrequestBody */
910285242Sachim      /* initialize jump table */
911285242Sachim
912285242Sachim      /* direct callback for task management */
913285242Sachim      TMtdIORequestBody->IOCompletionFunc = itdssTaskCompleted;
914285242Sachim      /* to be removed */
915285242Sachim      /* TMtdIORequestBody->IOCompletionFunc = itdssIOCompleted; */
916285242Sachim
917285242Sachim      /* initialize tiDevhandle */
918285242Sachim      TMtdIORequestBody->tiDevHandle = tiDeviceHandle;
919285242Sachim
920285242Sachim      /* initialize tiIORequest */
921285242Sachim      TMtdIORequestBody->tiIORequest = currentTaskTag;
922285242Sachim      /* save context if we need to abort later */
923285242Sachim      currentTaskTag->tdData = TMtdIORequestBody;
924285242Sachim
925285242Sachim      /* initialize agIORequest */
926285242Sachim      agIORequest = &(TMtdIORequestBody->agIORequest);
927285242Sachim      agIORequest->osData = (void *) TMtdIORequestBody;
928285242Sachim      agIORequest->sdkData = agNULL; /* SA takes care of this */
929285242Sachim
930285242Sachim      /* request type */
931285242Sachim      agRequestType = AGSA_SSP_TASK_MGNT_REQ;
932285242Sachim      TMtdIORequestBody->agRequestType = AGSA_SSP_TASK_MGNT_REQ;
933285242Sachim      /*
934285242Sachim        initialize
935285242Sachim        tdIORequestBody_t tdIORequestBody -> agSASRequestBody
936285242Sachim      */
937285242Sachim      agSASRequestBody = &(TMtdIORequestBody->transport.SAS.agSASRequestBody);
938285242Sachim      agSSPTaskMgntRequest = &(agSASRequestBody->sspTaskMgntReq);
939285242Sachim
940285242Sachim      TI_DBG2(("tiINITaskManagement: did %d LUN reset for SAS\n", oneDeviceData->id));
941285242Sachim      /* fill up LUN field */
942285242Sachim      if (lun == agNULL)
943285242Sachim      {
944285242Sachim        osti_memset(agSSPTaskMgntRequest->lun, 0, 8);
945285242Sachim      }
946285242Sachim      else
947285242Sachim      {
948285242Sachim        osti_memcpy(agSSPTaskMgntRequest->lun, lun->lun, 8);
949285242Sachim      }
950285242Sachim
951285242Sachim      /* default: unconditionally set device state to SA_DS_IN_RECOVERY
952285242Sachim         bit1 (DS) bit0 (ADS)
953285242Sachim         bit1: 1 bit0: 0
954285242Sachim      */
955285242Sachim      agSSPTaskMgntRequest->tmOption = 2;
956285242Sachim
957285242Sachim       /* sets taskMgntFunction field */
958285242Sachim      switch(task)
959285242Sachim      {
960285242Sachim      case AG_ABORT_TASK:
961285242Sachim        agSSPTaskMgntRequest->taskMgntFunction = AGSA_ABORT_TASK;
962285242Sachim        /* For abort task management, unconditionally set device state to SA_DS_IN_RECOVERY
963285242Sachim           and if can't find, set device state to SA_DS_IN_RECOVERY
964285242Sachim           bit1 (DS) bit0 (ADS)
965285242Sachim           bit1: 1; bit0: 1
966285242Sachim        */
967285242Sachim        agSSPTaskMgntRequest->tmOption = 3;
968285242Sachim        break;
969285242Sachim      case AG_ABORT_TASK_SET:
970285242Sachim        agSSPTaskMgntRequest->taskMgntFunction = AGSA_ABORT_TASK_SET;
971285242Sachim        break;
972285242Sachim      case AG_CLEAR_ACA:
973285242Sachim        agSSPTaskMgntRequest->taskMgntFunction = AGSA_CLEAR_ACA;
974285242Sachim        break;
975285242Sachim      case AG_CLEAR_TASK_SET:
976285242Sachim        agSSPTaskMgntRequest->taskMgntFunction = AGSA_CLEAR_TASK_SET;
977285242Sachim        break;
978285242Sachim      case AG_LOGICAL_UNIT_RESET:
979285242Sachim        agSSPTaskMgntRequest->taskMgntFunction = AGSA_LOGICAL_UNIT_RESET;
980285242Sachim        break;
981285242Sachim      case AG_QUERY_TASK:
982285242Sachim        agSSPTaskMgntRequest->taskMgntFunction = AGSA_QUERY_TASK;
983285242Sachim        break;
984285242Sachim      default:
985285242Sachim        TI_DBG1(("tiINITaskManagement: notImplemented task\n"));
986285242Sachim        break;
987285242Sachim      }
988285242Sachim
989285242Sachim      if (task == AGSA_ABORT_TASK || task == AGSA_QUERY_TASK)
990285242Sachim      {
991285242Sachim        /* set agTMRequest, which is IO being task managed */
992285242Sachim        tdIORequestBody = (tdIORequestBody_t *)taskTag->tdData;
993285242Sachim        if (tdIORequestBody == agNULL)
994285242Sachim        {
995285242Sachim           /* to be aborted IO has been completed. */
996285242Sachim          /* free up allocated memory */
997285242Sachim          TI_DBG1(("tiINITaskManagement: IO has been completed\n"));
998285242Sachim          ostiFreeMemory(
999285242Sachim                         tiRoot,
1000285242Sachim                         osMemHandle,
1001285242Sachim                         sizeof(tdIORequestBody_t)
1002285242Sachim                         );
1003285242Sachim          return tiIONoDevice;
1004285242Sachim        }
1005285242Sachim        else
1006285242Sachim        {
1007285242Sachim        agTMRequest = &(tdIORequestBody->agIORequest);
1008285242Sachim        }
1009285242Sachim      }
1010285242Sachim      else
1011285242Sachim      {
1012285242Sachim        /*
1013285242Sachim          For LUN RESET, WARM_RESET, ABORT_TASK_SET, CLEAR_ACA and CLEAR_TASK_SET
1014285242Sachim          no tag to be managed.
1015285242Sachim          Therefore, set it to zero.
1016285242Sachim        */
1017285242Sachim        agSSPTaskMgntRequest->tagOfTaskToBeManaged = 0;
1018285242Sachim        agTMRequest = agNULL;
1019285242Sachim
1020285242Sachim      }
1021285242Sachim
1022285242Sachim      TDLIST_INIT_HDR(&TMtdIORequestBody->EsglPageList);
1023285242Sachim      /* debuggging */
1024285242Sachim      if (TMtdIORequestBody->IOCompletionFunc == agNULL)
1025285242Sachim      {
1026285242Sachim        TI_DBG1(("tiINITaskManagement: Error!!!!! IOCompletionFunc is NULL\n"));
1027285242Sachim      }
1028285242Sachim      saStatus = saSSPStart(agRoot,
1029285242Sachim                            agIORequest, /* task management itself */
1030285242Sachim                            tdsaRotateQnumber(tiRoot, oneDeviceData),
1031285242Sachim                            agDevHandle,
1032285242Sachim                            agRequestType,
1033285242Sachim                            agSASRequestBody, /* task management itself */
1034285242Sachim                            agTMRequest, /* io to be aborted if exits */
1035285242Sachim                            &ossaSSPCompleted);
1036285242Sachim
1037285242Sachim
1038285242Sachim      if (saStatus == AGSA_RC_SUCCESS)
1039285242Sachim      {
1040285242Sachim        Initiator->NumIOsActive++;
1041285242Sachim        tiStatus = tiSuccess;
1042285242Sachim      }
1043285242Sachim      else
1044285242Sachim      {
1045285242Sachim        TI_DBG1(("tiINITaskManagement: saSSPStart failed 0x%x\n",saStatus));
1046285242Sachim        /* free up allocated memory */
1047285242Sachim        ostiFreeMemory(
1048285242Sachim                       tiRoot,
1049285242Sachim                       TMtdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
1050285242Sachim                       sizeof(tdIORequestBody_t)
1051285242Sachim                      );
1052285242Sachim        if (saStatus == AGSA_RC_FAILURE)
1053285242Sachim        {
1054285242Sachim          tiStatus = tiError;
1055285242Sachim        }
1056285242Sachim        else
1057285242Sachim        {
1058285242Sachim          /* AGSA_RC_BUSY */
1059285242Sachim          tiStatus = tiBusy;
1060285242Sachim        }
1061285242Sachim      }
1062285242Sachim    }
1063285242Sachim  } /* end of sas device */
1064285242Sachim
1065285242Sachim#ifdef FDS_SM
1066285242Sachim  else if (oneDeviceData->DeviceType == TD_SATA_DEVICE)
1067285242Sachim  {
1068285242Sachim    agsaContext_t           *agContext = agNULL;
1069285242Sachim
1070285242Sachim    /* save the task tag in tdsaDeviceData_t structure, for handling PORT_RESET_COMPLETE hw event */
1071285242Sachim    agContext = &(oneDeviceData->agDeviceResetContext);
1072285242Sachim    agContext->osData = currentTaskTag;
1073285242Sachim
1074285242Sachim#ifdef REMOVED
1075285242Sachim    /* for directly attached SATA, do localphycontrol for LUN and target reset, not smTaskManagement*/
1076285242Sachim    if (oneDeviceData->directlyAttached == agTRUE &&
1077285242Sachim        (task == AG_LOGICAL_UNIT_RESET || task == AG_TARGET_WARM_RESET))
1078285242Sachim    {
1079285242Sachim      agRoot = oneDeviceData->agRoot;
1080285242Sachim      agDevHandle = oneDeviceData->agDevHandle;
1081285242Sachim
1082285242Sachim      currentTaskTag->tdData = oneDeviceData;
1083285242Sachim
1084285242Sachim      if (task == AG_LOGICAL_UNIT_RESET)
1085285242Sachim      {
1086285242Sachim        if ( (lun->lun[0] | lun->lun[1] | lun->lun[2] | lun->lun[3] |
1087285242Sachim              lun->lun[4] | lun->lun[5] | lun->lun[6] | lun->lun[7] ) != 0 )
1088285242Sachim        {
1089285242Sachim          TI_DBG1(("tiINITaskManagement: *** REJECT *** LUN not zero, tiDeviceHandle=%p\n",
1090285242Sachim                  tiDeviceHandle));
1091285242Sachim          return tiError;
1092285242Sachim        }
1093285242Sachim     }
1094285242Sachim     saSetDeviceState(agRoot, agNULL, tdsaRotateQnumber(tiRoot, oneDeviceData), agDevHandle, SA_DS_IN_RECOVERY);
1095285242Sachim     tiStatus = saLocalPhyControl(agRoot, agContext, tdsaRotateQnumber(tiRoot, oneDeviceData), oneDeviceData->phyID, AGSA_PHY_HARD_RESET, agNULL);
1096285242Sachim    }
1097285242Sachim    else
1098285242Sachim#endif
1099285242Sachim    {
1100285242Sachim      smRoot = &(tdsaAllShared->smRoot);
1101285242Sachim      smDeviceHandle = &(oneDeviceData->smDeviceHandle);
1102285242Sachim      TI_DBG1(("tiINITaskManagement: FDS_SM SATA Device\n"));
1103285242Sachim
1104285242Sachim      if ( taskTag != agNULL)
1105285242Sachim      {
1106285242Sachim        ToBeAbortedtdIORequestBody = (tdIORequestBody_t *)taskTag->tdData;
1107285242Sachim        ToBeAborted = &(ToBeAbortedtdIORequestBody->smIORequest);
1108285242Sachim      }
1109285242Sachim      SMmemAllocStatus = ostiAllocMemory(
1110285242Sachim                                         tiRoot,
1111285242Sachim                                         &SMosMemHandle,
1112285242Sachim                                         (void **)&SMTMtdIORequestBody,
1113285242Sachim                                         &SMPhysUpper32,
1114285242Sachim                                         &SMPhysLower32,
1115285242Sachim                                         8,
1116285242Sachim                                         sizeof(tdIORequestBody_t),
1117285242Sachim                                         agTRUE
1118285242Sachim                                         );
1119285242Sachim      if (SMmemAllocStatus != tiSuccess)
1120285242Sachim      {
1121285242Sachim        TI_DBG1(("tiINITaskManagement: ostiAllocMemory failed... loc 2\n"));
1122285242Sachim        return tiError;
1123285242Sachim      }
1124285242Sachim
1125285242Sachim      if (SMTMtdIORequestBody == agNULL)
1126285242Sachim      {
1127285242Sachim        TI_DBG1(("tiINITaskManagement: ostiAllocMemory returned NULL TMIORequestBody loc 2\n"));
1128285242Sachim        return tiError;
1129285242Sachim      }
1130285242Sachim
1131285242Sachim      /* initialize */
1132285242Sachim      osti_memset(SMTMtdIORequestBody, 0, sizeof(tdIORequestBody_t));
1133285242Sachim
1134285242Sachim      /* setup task management structure */
1135285242Sachim      SMTMtdIORequestBody->IOType.InitiatorTMIO.osMemHandle = SMosMemHandle;
1136285242Sachim      SMTMtdIORequestBody->IOType.InitiatorTMIO.CurrentTaskTag = currentTaskTag;
1137285242Sachim      SMTMtdIORequestBody->IOType.InitiatorTMIO.TaskTag = taskTag;
1138285242Sachim
1139285242Sachim      /* initialize tiDevhandle */
1140285242Sachim      SMTMtdIORequestBody->tiDevHandle = tiDeviceHandle;
1141285242Sachim
1142285242Sachim      /* initialize tiIORequest */
1143285242Sachim      SMTMtdIORequestBody->tiIORequest = currentTaskTag;
1144285242Sachim      /* save context if we need to abort later */
1145285242Sachim      currentTaskTag->tdData = SMTMtdIORequestBody;
1146285242Sachim
1147285242Sachim      TaskManagement = &(SMTMtdIORequestBody->smIORequest);
1148285242Sachim
1149285242Sachim      TaskManagement->tdData = SMTMtdIORequestBody;
1150285242Sachim      TaskManagement->smData = &SMTMtdIORequestBody->smIORequestBody;
1151285242Sachim
1152285242Sachim      tiStatus = smTaskManagement(smRoot,
1153285242Sachim      	                           smDeviceHandle,
1154285242Sachim      	                           task,
1155285242Sachim      	                           (smLUN_t*)lun,
1156285242Sachim      	                           ToBeAborted,
1157285242Sachim      	                           TaskManagement
1158285242Sachim      	                           );
1159285242Sachim      if (tiStatus != SM_RC_SUCCESS)
1160285242Sachim      {
1161285242Sachim        TI_DBG1(("tiINITaskManagement: smTaskManagement failed... loc 2\n"));
1162285242Sachim        /* free up allocated memory */
1163285242Sachim        ostiFreeMemory(
1164285242Sachim                       tiRoot,
1165285242Sachim                       SMTMtdIORequestBody->IOType.InitiatorTMIO.osMemHandle,
1166285242Sachim                       sizeof(tdIORequestBody_t)
1167285242Sachim                      );
1168285242Sachim      }
1169285242Sachim    } /* else */
1170285242Sachim  }
1171285242Sachim#else
1172285242Sachim  else if (oneDeviceData->DeviceType == TD_SATA_DEVICE)
1173285242Sachim  {
1174285242Sachim    agRoot = oneDeviceData->agRoot;
1175285242Sachim    agDevHandle = oneDeviceData->agDevHandle;
1176285242Sachim    TI_DBG1(("tiINITaskManagement: not FDS_SM SATA Device\n"));
1177285242Sachim    /*
1178285242Sachim      WARM_RESET is experimental
1179285242Sachim      Needs more testing and debugging
1180285242Sachim      Soft reset for SATA as LUN RESET tends not to work.
1181285242Sachim      Let's do hard reset
1182285242Sachim    */
1183285242Sachim    if (task == AG_LOGICAL_UNIT_RESET || task == AG_TARGET_WARM_RESET)
1184285242Sachim    {
1185285242Sachim
1186285242Sachim      agsaContext_t           *agContext;
1187285242Sachim      satDeviceData_t         *satDevData;
1188285242Sachim      tdsaDeviceData_t        *tdsaDeviceData;
1189285242Sachim
1190285242Sachim      TI_DBG2(("tiINITaskManagement: did %d LUN reset or device reset for SATA\n", oneDeviceData->id));
1191285242Sachim      tdsaDeviceData  = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
1192285242Sachim      satDevData      = &tdsaDeviceData->satDevData;
1193285242Sachim      currentTaskTag->tdData = tdsaDeviceData;
1194285242Sachim      agContext = &(tdsaDeviceData->agDeviceResetContext);
1195285242Sachim      agContext->osData = currentTaskTag;
1196285242Sachim
1197285242Sachim
1198285242Sachim      if (task == AG_LOGICAL_UNIT_RESET)
1199285242Sachim      {
1200285242Sachim        if ( (lun->lun[0] | lun->lun[1] | lun->lun[2] | lun->lun[3] |
1201285242Sachim              lun->lun[4] | lun->lun[5] | lun->lun[6] | lun->lun[7] ) != 0 )
1202285242Sachim        {
1203285242Sachim          TI_DBG1(("tiINITaskManagement: *** REJECT *** LUN not zero, tiDeviceHandle=%p\n",
1204285242Sachim                  tiDeviceHandle));
1205285242Sachim          return tiError;
1206285242Sachim        }
1207285242Sachim
1208285242Sachim        /*
1209285242Sachim         * Check if there is other TM request pending
1210285242Sachim         */
1211285242Sachim        if (satDevData->satTmTaskTag != agNULL)
1212285242Sachim        {
1213285242Sachim          TI_DBG1(("tiINITaskManagement: *** REJECT *** other TM pending, tiDeviceHandle=%p\n",
1214285242Sachim                   tiDeviceHandle));
1215285242Sachim          return tiError;
1216285242Sachim        }
1217285242Sachim      }
1218285242Sachim      satDevData->satDriveState = SAT_DEV_STATE_IN_RECOVERY;
1219285242Sachim      satDevData->satAbortAfterReset = agFALSE;
1220285242Sachim
1221285242Sachim      saSetDeviceState(agRoot, agNULL, tdsaRotateQnumber(tiRoot, oneDeviceData), agDevHandle, SA_DS_IN_RECOVERY);
1222285242Sachim
1223285242Sachim      /*
1224285242Sachim        warm reset by saLocalPhyControl or SMP PHY control
1225285242Sachim       */
1226285242Sachim      if (oneDeviceData->directlyAttached == agTRUE)
1227285242Sachim      {
1228285242Sachim        TI_DBG1(("tiINITaskManagement: LUN reset or device reset directly attached\n"));
1229285242Sachim        saLocalPhyControl(agRoot, agContext, tdsaRotateQnumber(tiRoot, oneDeviceData), oneDeviceData->phyID, AGSA_PHY_HARD_RESET, agNULL);
1230285242Sachim        return tiSuccess;
1231285242Sachim      }
1232285242Sachim      else
1233285242Sachim      {
1234285242Sachim        TI_DBG1(("tiINITaskManagement: LUN reset or device reset expander attached\n"));
1235285242Sachim        saStatus = tdsaPhyControlSend(tiRoot,
1236285242Sachim                                      oneDeviceData,
1237285242Sachim                                      SMP_PHY_CONTROL_HARD_RESET,
1238285242Sachim                                      currentTaskTag,
1239285242Sachim                                      tdsaRotateQnumber(tiRoot, oneDeviceData)
1240285242Sachim                                     );
1241285242Sachim        return saStatus;
1242285242Sachim      }
1243285242Sachim    }
1244285242Sachim    else
1245285242Sachim    {
1246285242Sachim      TI_DBG2(("tiINITaskManagement: calling satTM().\n"));
1247285242Sachim      /* allocation tdIORequestBody and pass it to satTM() */
1248285242Sachim      memAllocStatus = ostiAllocMemory(
1249285242Sachim                                       tiRoot,
1250285242Sachim                                       &osMemHandle,
1251285242Sachim                                       (void **)&TMtdIORequestBody,
1252285242Sachim                                       &PhysUpper32,
1253285242Sachim                                       &PhysLower32,
1254285242Sachim                                       8,
1255285242Sachim                                       sizeof(tdIORequestBody_t),
1256285242Sachim                                       agTRUE
1257285242Sachim                                       );
1258285242Sachim
1259285242Sachim      if (memAllocStatus != tiSuccess)
1260285242Sachim      {
1261285242Sachim        TI_DBG1(("tiINITaskManagement: ostiAllocMemory failed... loc 2\n"));
1262285242Sachim        return tiError;
1263285242Sachim      }
1264285242Sachim
1265285242Sachim      if (TMtdIORequestBody == agNULL)
1266285242Sachim      {
1267285242Sachim        TI_DBG1(("tiINITaskManagement: ostiAllocMemory returned NULL TMIORequestBody loc 2\n"));
1268285242Sachim        return tiError;
1269285242Sachim
1270285242Sachim      }
1271285242Sachim
1272285242Sachim      /* initialize */
1273285242Sachim      osti_memset(TMtdIORequestBody, 0, sizeof(tdIORequestBody_t));
1274285242Sachim
1275285242Sachim      /* setup task management structure */
1276285242Sachim      TMtdIORequestBody->IOType.InitiatorTMIO.osMemHandle = osMemHandle;
1277285242Sachim      TMtdIORequestBody->IOType.InitiatorTMIO.CurrentTaskTag = currentTaskTag;
1278285242Sachim      TMtdIORequestBody->IOType.InitiatorTMIO.TaskTag = taskTag;
1279285242Sachim
1280285242Sachim      /* initialize tiDevhandle */
1281285242Sachim      TMtdIORequestBody->tiDevHandle = tiDeviceHandle;
1282285242Sachim
1283285242Sachim      /* initialize tiIORequest */
1284285242Sachim      TMtdIORequestBody->tiIORequest = currentTaskTag;
1285285242Sachim      /* save context if we need to abort later */
1286285242Sachim      currentTaskTag->tdData = TMtdIORequestBody;
1287285242Sachim
1288285242Sachim      /* initialize agIORequest */
1289285242Sachim      agIORequest = &(TMtdIORequestBody->agIORequest);
1290285242Sachim      agIORequest->osData = (void *) TMtdIORequestBody;
1291285242Sachim      agIORequest->sdkData = agNULL; /* SA takes care of this */
1292285242Sachim
1293285242Sachim
1294285242Sachim#ifdef  SATA_ENABLE
1295285242Sachim      tiStatus = satTM( tiRoot,
1296285242Sachim                        tiDeviceHandle,
1297285242Sachim                        task,
1298285242Sachim                        lun,
1299285242Sachim                        taskTag,
1300285242Sachim                        currentTaskTag,
1301285242Sachim                        TMtdIORequestBody,
1302285242Sachim                        agTRUE
1303285242Sachim                        );
1304285242Sachim#endif
1305285242Sachim    }
1306285242Sachim  }
1307285242Sachim#endif /* FDS_SM else*/
1308285242Sachim
1309285242Sachim  return tiStatus;
1310285242Sachim}
1311285242Sachim#endif  /* INITIATOR_DRIVER */
1312285242Sachim
1313285242Sachim#ifdef PASSTHROUGH
1314285242SachimosGLOBAL bit32
1315285242SachimtiCOMPassthroughCmndStart(
1316285242Sachim                          tiRoot_t                *tiRoot,
1317285242Sachim                          tiPassthroughRequest_t      *tiPassthroughRequest,
1318285242Sachim                          tiDeviceHandle_t            *tiDeviceHandle,
1319285242Sachim                          tiPassthroughCmnd_t           *tiPassthroughCmnd,
1320285242Sachim                          void                      *tiPassthroughBody,
1321285242Sachim                          tiPortalContext_t           *tiportalContext,
1322285242Sachim                          ostiPassthroughCmndEvent_t        agEventCB
1323285242Sachim                          )
1324285242Sachim{
1325285242Sachim  tdsaRoot_t                *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
1326285242Sachim  tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1327285242Sachim  tdsaDeviceData_t          *oneDeviceData;
1328285242Sachim  agsaRoot_t                *agRoot = agNULL;
1329285242Sachim  agsaIORequest_t           *agIORequest = agNULL;
1330285242Sachim  agsaDevHandle_t           *agDevHandle = agNULL;
1331285242Sachim  bit32                     agRequestType;
1332285242Sachim  agsaSASRequestBody_t      *agSASRequestBody = agNULL;
1333285242Sachim
1334285242Sachim  tdPassthroughCmndBody_t   *tdPTCmndBody;
1335285242Sachim  tdssSMPRequestBody_t      *tdssSMPRequestBody;
1336285242Sachim  agsaSMPFrame_t            *agSMPFrame;
1337285242Sachim  agsaSSPVSFrame_t          *agSSPVendorFrame; /* RMC */
1338285242Sachim  bit32                     SMPFn, SMPFnResult, SMPFrameLen;
1339285242Sachim  bit32                     tiStatus = tiError;
1340285242Sachim  bit32                     saStatus = AGSA_RC_FAILURE;
1341285242Sachim  tdsaPortStartInfo_t       *tdsaPortStartInfo;
1342285242Sachim  tdsaPortContext_t         *tdsaPortContext;
1343285242Sachim
1344285242Sachim  TI_DBG2(("tiCOMPassthroughCmndStart: start\n"));
1345285242Sachim
1346285242Sachim  oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
1347285242Sachim
1348285242Sachim  TI_DBG6(("tiCOMPassthroughCmndStart: onedevicedata %p\n", oneDeviceData));
1349285242Sachim
1350285242Sachim
1351285242Sachim  tdPTCmndBody = (tdPassthroughCmndBody_t *)tiPassthroughBody;
1352285242Sachim
1353285242Sachim
1354285242Sachim  if (tiPassthroughCmnd->passthroughCmnd != tiSMPCmnd ||
1355285242Sachim      tiPassthroughCmnd->passthroughCmnd != tiRMCCmnd)
1356285242Sachim  {
1357285242Sachim    return tiNotSupported;
1358285242Sachim  }
1359285242Sachim
1360285242Sachim
1361285242Sachim  if (oneDeviceData == agNULL && tiPassthroughCmnd->passthroughCmnd != tiSMPCmnd)
1362285242Sachim  {
1363285242Sachim    TI_DBG1(("tiCOMPassthroughCmndStart: tiDeviceHandle=%p DeviceData is NULL\n", tiDeviceHandle ));
1364285242Sachim    return tiIONoDevice;
1365285242Sachim  }
1366285242Sachim
1367285242Sachim  /* starting IO with SAS device */
1368285242Sachim  if (oneDeviceData->DeviceType == TD_SAS_DEVICE)
1369285242Sachim  {
1370285242Sachim    if (tiPassthroughCmnd->passthroughCmnd == tiSMPCmnd)
1371285242Sachim    {
1372285242Sachim      TI_DBG2(("tiCOMPassthroughCmndStart: SMP\n"));
1373285242Sachim      if (oneDeviceData == agNULL)
1374285242Sachim      {
1375285242Sachim        tdsaPortStartInfo = (tdsaPortStartInfo_t *)tiportalContext->tdData;
1376285242Sachim        tdsaPortContext = tdsaPortStartInfo->portContext;
1377285242Sachim        agRoot = tdsaPortContext->agRoot;
1378285242Sachim      }
1379285242Sachim      else
1380285242Sachim      {
1381285242Sachim        agRoot = oneDeviceData->agRoot;
1382285242Sachim        agDevHandle = oneDeviceData->agDevHandle;
1383285242Sachim      }
1384285242Sachim
1385285242Sachim
1386285242Sachim      tdssSMPRequestBody =  &(tdPTCmndBody->protocol.SMP.SMPBody);
1387285242Sachim      agSASRequestBody = &(tdssSMPRequestBody->agSASRequestBody);
1388285242Sachim      agSMPFrame = &(agSASRequestBody->smpFrame);
1389285242Sachim
1390285242Sachim      /* saves callback function */
1391285242Sachim      tdPTCmndBody->EventCB = agEventCB;
1392285242Sachim
1393285242Sachim      /* initialize command type  */
1394285242Sachim      tdPTCmndBody->tiPassthroughCmndType = tiSMPCmnd;
1395285242Sachim
1396285242Sachim      /* initialize tipassthroughrequest  */
1397285242Sachim      tdPTCmndBody->tiPassthroughRequest = tiPassthroughRequest;
1398285242Sachim      tiPassthroughRequest->tdData = tdPTCmndBody;
1399285242Sachim
1400285242Sachim      /* initialize tiDevhandle */
1401285242Sachim      tdPTCmndBody->tiDevHandle = tiDeviceHandle;
1402285242Sachim
1403285242Sachim      /* fill in SMP header */
1404285242Sachim      agSMPFrame->frameHeader.smpFrameType
1405285242Sachim        = tiPassthroughCmnd->protocol.SMP.SMPHeader.smpFrameType;
1406285242Sachim      agSMPFrame->frameHeader.smpFunction
1407285242Sachim        = tiPassthroughCmnd->protocol.SMP.SMPHeader.smpFunction;
1408285242Sachim      agSMPFrame->frameHeader.smpFunctionResult
1409285242Sachim        = tiPassthroughCmnd->protocol.SMP.SMPHeader.smpFunctionResult;
1410285242Sachim      agSMPFrame->frameHeader.smpReserved
1411285242Sachim        = tiPassthroughCmnd->protocol.SMP.SMPHeader.smpReserved;
1412285242Sachim
1413285242Sachim      if (tiPassthroughCmnd->protocol.SMP.IT == SMP_INITIATOR)
1414285242Sachim        {
1415285242Sachim          agRequestType = AGSA_SMP_INIT_REQ;
1416285242Sachim        }
1417285242Sachim      else
1418285242Sachim        {
1419285242Sachim          agRequestType = AGSA_SMP_TGT_RESPONSE;
1420285242Sachim          /* this is only for SMP target */
1421285242Sachim          agSMPFrame->phyId = tiPassthroughCmnd->protocol.SMP.phyID;
1422285242Sachim        }
1423285242Sachim
1424285242Sachim      /* fill in payload */
1425285242Sachim      /* assumption: SMP payload is in tisgl1 */
1426285242Sachim      agSMPFrame->frameAddrUpper32 = tiPassthroughCmnd->tiSgl.upper;
1427285242Sachim      agSMPFrame->frameAddrLower32 = tiPassthroughCmnd->tiSgl.lower;
1428285242Sachim
1429285242Sachim      /* This length excluding SMP header (4 bytes) and CRC field */
1430285242Sachim      agSMPFrame->frameLen = tiPassthroughCmnd->tiSgl.len;
1431285242Sachim
1432285242Sachim      /* initialize agIORequest */
1433285242Sachim      /*
1434285242Sachim        Compare:
1435285242Sachim        tdIORequestBody        = (tdIORequestBody_t *)agIORequest->osData;
1436285242Sachim      */
1437285242Sachim      agIORequest = &(tdssSMPRequestBody->agIORequest);
1438285242Sachim      agIORequest->osData = (void *) tdPTCmndBody;
1439285242Sachim      agIORequest->sdkData = agNULL; /* LL takes care of this */
1440285242Sachim
1441285242Sachim
1442285242Sachim
1443285242Sachim      /* not work yet because of high priority q */
1444285242Sachim      saStatus = saSMPStart(
1445285242Sachim                            agRoot,
1446285242Sachim                            agIORequest,
1447285242Sachim                            agDevHandle,
1448285242Sachim                            agRequestType,
1449285242Sachim                            agSASRequestBody,
1450285242Sachim                            &ossaSMPCompleted
1451285242Sachim                            );
1452285242Sachim
1453285242Sachim      if (saStatus == AGSA_RC_SUCCESS)
1454285242Sachim      {
1455285242Sachim        tiStatus = tiSuccess;
1456285242Sachim      }
1457285242Sachim      else if (saStatus == AGSA_RC_FAILURE)
1458285242Sachim      {
1459285242Sachim        TI_DBG1(("tiCOMPassthroughCmndStart: saSMPStart failed\n"));
1460285242Sachim        tiStatus = tiError;
1461285242Sachim      }
1462285242Sachim      else
1463285242Sachim      {
1464285242Sachim        /* AGSA_RC_BUSY */
1465285242Sachim        TI_DBG1(("tiCOMPassthroughCmndStart: saSMPStart busy\n"));
1466285242Sachim        tiStatus = tiBusy;
1467285242Sachim      }
1468285242Sachim      return tiStatus;
1469285242Sachim
1470285242Sachim
1471285242Sachim#ifdef TO_DO
1472285242Sachim      /* fill in SMP header */
1473285242Sachim      if (tdPTCmndBody->protocol.SMP.IT == SMP_INITIATOR)
1474285242Sachim        {
1475285242Sachim          agSMPFrame->frameHeader.smpFrameType = SMP_REQUEST; /* SMP REQUEST */
1476285242Sachim          agRequestType = AGSA_SMP_INIT_REQ;
1477285242Sachim        }
1478285242Sachim      else
1479285242Sachim        {
1480285242Sachim          /* SMP target */
1481285242Sachim          agSMPFrame->frameHeader.smpFrameType = SMP_RESPONSE; /* SMP RESPONSE */
1482285242Sachim          agRequestType = AGSA_SMP_TGT_RESPONSE;
1483285242Sachim          switch (tdPTCmndBody->protocol.SMP.SMPFnResult)
1484285242Sachim          {
1485285242Sachim          case tiSMPFunctionAccepted:
1486285242Sachim            SMPFnResult = SMP_FUNCTION_ACCEPTED;
1487285242Sachim            break;
1488285242Sachim          case tiUnknownSMPFunction:
1489285242Sachim            SMPFnResult = UNKNOWN_SMP_FUNCTION;
1490285242Sachim            break;
1491285242Sachim          case tiSMPFunctionFailed:
1492285242Sachim            SMPFnResult = SMP_FUNCTION_FAILED;
1493285242Sachim            break;
1494285242Sachim          case tiInvalidRequestFrameLength:
1495285242Sachim            SMPFnResult = INVALID_REQUEST_FRAME_LENGTH;
1496285242Sachim            break;
1497285242Sachim          case tiPhyDoesNotExist:
1498285242Sachim            SMPFnResult =PHY_DOES_NOT_EXIST;
1499285242Sachim            break;
1500285242Sachim          case tiIndexDoesNotExist:
1501285242Sachim            SMPFnResult = INDEX_DOES_NOT_EXIST;
1502285242Sachim            break;
1503285242Sachim          case tiPhyDoesNotSupportSATA:
1504285242Sachim            SMPFnResult = PHY_DOES_NOT_SUPPORT_SATA;
1505285242Sachim            break;
1506285242Sachim          case tiUnknownPhyOperation:
1507285242Sachim            SMPFnResult = UNKNOWN_PHY_OPERATION;
1508285242Sachim            break;
1509285242Sachim          case tiUnknownPhyTestFunction:
1510285242Sachim            SMPFnResult = UNKNOWN_PHY_TEST_FUNCTION;
1511285242Sachim            break;
1512285242Sachim          case tiPhyTestFunctionInProgress:
1513285242Sachim            SMPFnResult = PHY_TEST_FUNCTION_IN_PROGRESS;
1514285242Sachim            break;
1515285242Sachim          case tiPhyVacant:
1516285242Sachim            SMPFnResult = PHY_VACANT;
1517285242Sachim            break;
1518285242Sachim
1519285242Sachim          default:
1520285242Sachim            TI_DBG1(("tiCOMPassthroughCmndStart: unknown SMP function result %d\n", tdPTCmndBody->protocol.SMP.SMPFnResult));
1521285242Sachim            return tiError;
1522285242Sachim          }
1523285242Sachim          agSMPFrame->frameHeader.smpFunctionResult = SMPFnResult;
1524285242Sachim        }
1525285242Sachim
1526285242Sachim      /* common */
1527285242Sachim      switch (tdPTCmndBody->protocol.SMP.SMPFn)
1528285242Sachim      {
1529285242Sachim      case tiGeneral:
1530285242Sachim        SMPFn = SMP_REPORT_GENERAL;
1531285242Sachim        if (tdPTCmndBody->protocol.SMP.IT == SMP_INITIATOR)
1532285242Sachim        {
1533285242Sachim          SMPFrameLen = 0;
1534285242Sachim        }
1535285242Sachim        else
1536285242Sachim        {
1537285242Sachim          SMPFrameLen = sizeof(smpRespReportGeneral_t);
1538285242Sachim        }
1539285242Sachim        break;
1540285242Sachim
1541285242Sachim      case tiManufacturerInfo:
1542285242Sachim        SMPFn = SMP_REPORT_MANUFACTURE_INFORMATION;
1543285242Sachim        if (tdPTCmndBody->protocol.SMP.IT == SMP_INITIATOR)
1544285242Sachim        {
1545285242Sachim          SMPFrameLen = 0;
1546285242Sachim        }
1547285242Sachim        else
1548285242Sachim        {
1549285242Sachim          SMPFrameLen = sizeof(smpRespReportManufactureInfo_t);
1550285242Sachim        }
1551285242Sachim        break;
1552285242Sachim
1553285242Sachim      case tiDiscover:
1554285242Sachim        SMPFn = SMP_DISCOVER;
1555285242Sachim        if (tdPTCmndBody->protocol.SMP.IT == SMP_INITIATOR)
1556285242Sachim        {
1557285242Sachim          SMPFrameLen = sizeof(smpReqDiscover_t);
1558285242Sachim        }
1559285242Sachim        else
1560285242Sachim        {
1561285242Sachim          SMPFrameLen = sizeof(smpRespDiscover_t);
1562285242Sachim        }
1563285242Sachim        break;
1564285242Sachim
1565285242Sachim      case tiReportPhyErrLog:
1566285242Sachim        SMPFn = SMP_REPORT_PHY_ERROR_LOG;
1567285242Sachim        if (tdPTCmndBody->protocol.SMP.IT == SMP_INITIATOR)
1568285242Sachim        {
1569285242Sachim          SMPFrameLen = 8;
1570285242Sachim        }
1571285242Sachim        else
1572285242Sachim        {
1573285242Sachim          SMPFrameLen = 24;
1574285242Sachim        }
1575285242Sachim        break;
1576285242Sachim
1577285242Sachim      case tiReportPhySATA:
1578285242Sachim        SMPFn = SMP_REPORT_PHY_SATA;
1579285242Sachim        if (tdPTCmndBody->protocol.SMP.IT == SMP_INITIATOR)
1580285242Sachim        {
1581285242Sachim          SMPFrameLen = sizeof(SmpReqReportPhySata_t);
1582285242Sachim        }
1583285242Sachim        else
1584285242Sachim        {
1585285242Sachim          SMPFrameLen = sizeof(SmpRespReportPhySata_t);
1586285242Sachim        }
1587285242Sachim        break;
1588285242Sachim
1589285242Sachim      case tiReportRteInfo:
1590285242Sachim        SMPFn = SMP_REPORT_ROUTING_INFORMATION;
1591285242Sachim        if (tdPTCmndBody->protocol.SMP.IT == SMP_INITIATOR)
1592285242Sachim        {
1593285242Sachim          SMPFrameLen = sizeof(SmpReqReportRouteTable_t);
1594285242Sachim        }
1595285242Sachim        else
1596285242Sachim        {
1597285242Sachim          SMPFrameLen = sizeof(SmpRespReportRouteTable_t);
1598285242Sachim        }
1599285242Sachim        break;
1600285242Sachim
1601285242Sachim      case tiConfigureRteInfo:
1602285242Sachim        SMPFn = SMP_CONFIGURE_ROUTING_INFORMATION;;
1603285242Sachim        if (tdPTCmndBody->protocol.SMP.IT == SMP_INITIATOR)
1604285242Sachim        {
1605285242Sachim          SMPFrameLen = sizeof(SmpReqConfigureRouteInformation_t);
1606285242Sachim        }
1607285242Sachim        else
1608285242Sachim        {
1609285242Sachim          SMPFrameLen = 0;
1610285242Sachim        }
1611285242Sachim        break;
1612285242Sachim
1613285242Sachim      case tiPhyCtrl:
1614285242Sachim        SMPFn = SMP_PHY_CONTROL;
1615285242Sachim        if (tdPTCmndBody->protocol.SMP.IT == SMP_INITIATOR)
1616285242Sachim        {
1617285242Sachim          SMPFrameLen = sizeof(SmpReqPhyControl_t);
1618285242Sachim        }
1619285242Sachim        else
1620285242Sachim        {
1621285242Sachim          SMPFrameLen = 0;
1622285242Sachim        }
1623285242Sachim        break;
1624285242Sachim
1625285242Sachim      case tiPhyTestFn:
1626285242Sachim        SMPFn = SMP_PHY_TEST_FUNCTION;
1627285242Sachim        if (tdPTCmndBody->protocol.SMP.IT == SMP_INITIATOR)
1628285242Sachim        {
1629285242Sachim          SMPFrameLen = 36;
1630285242Sachim        }
1631285242Sachim        else
1632285242Sachim        {
1633285242Sachim          SMPFrameLen = 0;
1634285242Sachim        }
1635285242Sachim        break;
1636285242Sachim
1637285242Sachim      case tiPMC:
1638285242Sachim        SMPFn = SMP_PMC_SPECIFIC;
1639285242Sachim        if (tdPTCmndBody->protocol.SMP.IT == SMP_INITIATOR)
1640285242Sachim        {
1641285242Sachim          SMPFrameLen = 0;
1642285242Sachim        }
1643285242Sachim        else
1644285242Sachim        {
1645285242Sachim          SMPFrameLen = 0;
1646285242Sachim        }
1647285242Sachim        break;
1648285242Sachim
1649285242Sachim
1650285242Sachim      default:
1651285242Sachim        TI_DBG1(("tiCOMPassthroughCmndStart: unknown SMP function %d\n", tdPTCmndBody->protocol.SMP.SMPFn));
1652285242Sachim        return tiError;
1653285242Sachim      }
1654285242Sachim      agSMPFrame->frameHeader.smpFunction = SMPFn;
1655285242Sachim
1656285242Sachim
1657285242Sachim      /* assumption: SMP payload is in tisgl1 */
1658285242Sachim      agSMPFrame->frameAddrUpper32 = tdPTCmndBody->tiSgl.upper;
1659285242Sachim      agSMPFrame->frameAddrLower32 = tdPTCmndBody->tiSgl.lower;
1660285242Sachim
1661285242Sachim      /* This length excluding SMP header (4 bytes) and CRC field */
1662285242Sachim      agSMPFrame->frameLen = SMPFrameLen;
1663285242Sachim
1664285242Sachim
1665285242Sachim
1666285242Sachim
1667285242Sachim
1668285242Sachim
1669285242Sachim#endif
1670285242Sachim
1671285242Sachim
1672285242Sachim    }
1673285242Sachim    else if (tiPassthroughCmnd->passthroughCmnd == tiRMCCmnd)
1674285242Sachim    {
1675285242Sachim      TI_DBG2(("tiCOMPassthroughCmndStart: RMC\n"));
1676285242Sachim    }
1677285242Sachim    else
1678285242Sachim    {
1679285242Sachim      TI_DBG1(("tiCOMPassthroughCmndStart: unknown protocol %d\n", tiPassthroughCmnd->passthroughCmnd));
1680285242Sachim    }
1681285242Sachim
1682285242Sachim
1683285242Sachim  }
1684285242Sachim  else if (oneDeviceData->DeviceType == TD_SATA_DEVICE)
1685285242Sachim  {
1686285242Sachim    TI_DBG1(("tiCOMPassthroughCmndStart: error !!! no SATA support\n"));
1687285242Sachim    return tiError;
1688285242Sachim  }
1689285242Sachim  else
1690285242Sachim  {
1691285242Sachim    TI_DBG1(("tiCOMPassthroughCmndStart: error !!! unknown devietype %d\n", oneDeviceData->DeviceType));
1692285242Sachim    return tiError;
1693285242Sachim
1694285242Sachim  }
1695285242Sachim
1696285242Sachim  return tiSuccess;
1697285242Sachim}
1698285242Sachim
1699285242Sachim
1700285242SachimosGLOBAL bit32
1701285242SachimtiCOMPassthroughCmndAbort(
1702285242Sachim                          tiRoot_t                *tiRoot,
1703285242Sachim                          tiPassthroughRequest_t    *taskTag
1704285242Sachim                          )
1705285242Sachim{
1706285242Sachim  tdsaRoot_t                *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1707285242Sachim  tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1708285242Sachim  agsaRoot_t                *agRoot = agNULL;
1709285242Sachim  tdPassthroughCmndBody_t   *tdPTCmndBody = agNULL;
1710285242Sachim  tdssSMPRequestBody_t      *tdssSMPRequestBody = agNULL;
1711285242Sachim  agsaIORequest_t           *agIORequest = agNULL;
1712285242Sachim  bit32                     saStatus, tiStatus = tiError;
1713285242Sachim
1714285242Sachim  TI_DBG2(("tiCOMPassthroughCmndAbort: start\n"));
1715285242Sachim
1716285242Sachim  agRoot          = &(tdsaAllShared->agRootNonInt);
1717285242Sachim  tdPTCmndBody    = (tdPassthroughCmndBody_t *)taskTag->tdData;
1718285242Sachim
1719285242Sachim  if (tdPTCmndBody->tiPassthroughCmndType == tiSMPCmnd)
1720285242Sachim  {
1721285242Sachim    tdssSMPRequestBody =  &(tdPTCmndBody->protocol.SMP.SMPBody);
1722285242Sachim    agIORequest = &(tdssSMPRequestBody->agIORequest);
1723285242Sachim
1724285242Sachim    saStatus = saSMPAbort(agRoot, agIORequest);
1725285242Sachim
1726285242Sachim    if (saStatus == AGSA_RC_SUCCESS)
1727285242Sachim      {
1728285242Sachim        tiStatus = tiSuccess;
1729285242Sachim      }
1730285242Sachim      else if (saStatus == AGSA_RC_FAILURE)
1731285242Sachim      {
1732285242Sachim        TI_DBG1(("tiCOMPassthroughCmndAbort: saSMPAbort failed\n"));
1733285242Sachim        tiStatus = tiError;
1734285242Sachim      }
1735285242Sachim      else
1736285242Sachim      {
1737285242Sachim        /* AGSA_RC_BUSY */
1738285242Sachim        TI_DBG1(("tiCOMPassthroughCmndAbort: saSMPAbort busy\n"));
1739285242Sachim        tiStatus = tiBusy;
1740285242Sachim      }
1741285242Sachim      return tiStatus;
1742285242Sachim  }
1743285242Sachim  else if (tdPTCmndBody->tiPassthroughCmndType == tiRMCCmnd)
1744285242Sachim  {
1745285242Sachim    TI_DBG1(("tiCOMPassthroughCmndAbort: RMC passthrough command type, not yet\n"));
1746285242Sachim
1747285242Sachim  }
1748285242Sachim  else
1749285242Sachim  {
1750285242Sachim    TI_DBG1(("tiCOMPassthroughCmndAbort: unknown passthrough command type %d\n", tdPTCmndBody->tiPassthroughCmndType));
1751285242Sachim    return tiStatus;
1752285242Sachim  }
1753285242Sachim
1754285242Sachim
1755285242Sachim}
1756285242Sachim
1757285242SachimosGLOBAL bit32
1758285242SachimtiINIPassthroughCmndRemoteAbort(
1759285242Sachim                                tiRoot_t            *tiRoot,
1760285242Sachim                                tiDeviceHandle_t      *tiDeviceHandle,
1761285242Sachim                                tiPassthroughRequest_t    *taskTag,
1762285242Sachim                                tiPassthroughRequest_t    *currentTaskTag,
1763285242Sachim                                tiPortalContext_t       *tiportalContext
1764285242Sachim                                )
1765285242Sachim{
1766285242Sachim  TI_DBG2(("tiINIPassthroughCmndRemoteAbort: start\n"));
1767285242Sachim  /*
1768285242Sachim    for SMP, nothing. Can't abot remotely
1769285242Sachim  */
1770285242Sachim  return tiSuccess;
1771285242Sachim}
1772285242Sachim#endif /* PASSTHROUGH */
1773285242Sachim
1774285242Sachim
1775285242Sachim/*****************************************************************************
1776285242Sachim*! \brief tiCOMShutDown
1777285242Sachim*
1778285242Sachim*  Purpose: This function is called to shutdown the initiator and/or target
1779285242Sachim*           operation. Following the completion of this call, the state is
1780285242Sachim*           equivalent to the state prior to tiCOMInit()
1781285242Sachim*
1782285242Sachim*  \param tiRoot:  Pointer to root data structure.
1783285242Sachim*
1784285242Sachim*  \return     None
1785285242Sachim*
1786285242Sachim*
1787285242Sachim*****************************************************************************/
1788285242SachimosGLOBAL void
1789285242SachimtiCOMShutDown( tiRoot_t    *tiRoot)
1790285242Sachim{
1791285242Sachim  tdsaRoot_t                *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
1792285242Sachim  tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1793285242Sachim
1794285242Sachim// #define  TI_GETFOR_ONSHUTDOWN
1795285242Sachim#ifdef TI_GETFOR_ONSHUTDOWN
1796285242Sachim  agsaForensicData_t         forensicData;
1797285242Sachim  bit32 once = 1;
1798285242Sachim  bit32  status;
1799285242Sachim#endif /* TI_GETFOR_ONSHUTDOWN */
1800285242Sachim
1801285242Sachim  agsaRoot_t                *agRoot = agNULL;
1802285242Sachim
1803285242Sachim  TI_DBG1(("tiCOMShutDown: start\n"));
1804285242Sachim
1805285242Sachim
1806285242Sachim  agRoot = &(tdsaAllShared->agRootNonInt);
1807285242Sachim  /*
1808285242Sachim    1. free up cardID
1809285242Sachim    2. call saHwShutdown()
1810285242Sachim    3. tdInitEsgl(tiRoot);
1811285242Sachim    4. tdsaResetComMemFlags(tiRoot)
1812285242Sachim    5. ostiPortEvent()
1813285242Sachim  */
1814285242Sachim
1815285242Sachim  tdsaFreeCardID(tiRoot, tdsaAllShared->CardID);
1816285242Sachim
1817285242Sachim#ifdef TI_GETFOR_ONSHUTDOWN
1818285242Sachim  forensicData.DataType = TYPE_NON_FATAL;
1819285242Sachim  forensicData.dataBuf.directLen =  (8 * 1024);
1820285242Sachim  forensicData.dataBuf.directOffset = 0; /* current offset */
1821285242Sachim  forensicData.dataBuf.directData = agNULL;
1822285242Sachim  forensicData.dataBuf.readLen = 0;   /* Data read */
1823285242Sachim
1824285242Sachim  getmoreData:
1825285242Sachim  status = saGetForensicData( agRoot, agNULL, &forensicData);
1826285242Sachim
1827285242Sachim  TI_DBG1(("tiCOMShutDown:readLen 0x%x directLen 0x%x directOffset 0x%x\n",
1828285242Sachim      forensicData.dataBuf.readLen,
1829285242Sachim      forensicData.dataBuf.directLen,
1830285242Sachim      forensicData.dataBuf.directOffset));
1831285242Sachim  if( forensicData.dataBuf.readLen == forensicData.dataBuf.directLen && !status && once)
1832285242Sachim  {
1833285242Sachim    goto getmoreData;
1834285242Sachim  }
1835285242Sachim
1836285242Sachim  TI_DBG1(("tiCOMShutDown:saGetForensicData type %d read 0x%x bytes\n",    forensicData.DataType,    forensicData.dataBuf.directOffset ));
1837285242Sachim#endif /* TI_GETFOR_ONSHUTDOWN */
1838285242Sachim
1839285242Sachim  saHwShutdown(agRoot);
1840285242Sachim
1841285242Sachim  /* resets all the relevant flags */
1842285242Sachim  tdsaResetComMemFlags(tiRoot);
1843285242Sachim
1844285242Sachim  /*
1845285242Sachim   * send an event to the oslayer
1846285242Sachim   */
1847285242Sachim  ostiPortEvent (
1848285242Sachim                 tiRoot,
1849285242Sachim                 tiPortShutdown,
1850285242Sachim                 tiSuccess,
1851285242Sachim                 agNULL
1852285242Sachim                 );
1853285242Sachim
1854285242Sachim  return;
1855285242Sachim}
1856285242Sachim
1857285242Sachim#ifdef INITIATOR_DRIVER
1858285242SachimosGLOBAL void
1859285242SachimtiINITimerTick( tiRoot_t  *tiRoot )
1860285242Sachim{
1861285242Sachim  /*
1862285242Sachim    no timer is used in SAS TD layer.
1863285242Sachim    Therefore, this function is null.
1864285242Sachim  */
1865285242Sachim  //  TI_DBG2(("tiINITimerTick: start\n"));
1866285242Sachim  /*itdsaProcessTimers(tiRoot);*/
1867285242Sachim  return;
1868285242Sachim}
1869285242Sachim#endif
1870285242Sachim
1871285242Sachim/*****************************************************************************/
1872285242Sachim/*! \brief ossaDisableInterrupts
1873285242Sachim *
1874285242Sachim *
1875285242Sachim *  Purpose: This routine is called to disable interrupt
1876285242Sachim *
1877285242Sachim *
1878285242Sachim *  \param  agRoot:               Pointer to chip/driver Instance.
1879285242Sachim *  \param  outboundChannelNum:   Zero-base channel number
1880285242Sachim *
1881285242Sachim *
1882285242Sachim *  \return None.
1883285242Sachim *
1884285242Sachim *  \note - The scope is shared target and initiator.
1885285242Sachim *
1886285242Sachim */
1887285242Sachim/*****************************************************************************/
1888285242Sachim#ifndef ossaDisableInterrupts
1889285242SachimosGLOBAL void
1890285242SachimossaDisableInterrupts(
1891285242Sachim                      agsaRoot_t  *agRoot,
1892285242Sachim                      bit32       outboundChannelNum
1893285242Sachim                      )
1894285242Sachim{
1895285242Sachim  tdsaRootOsData_t *osData = (tdsaRootOsData_t *) (agRoot->osData);
1896285242Sachim
1897285242Sachim  ostiInterruptDisable(
1898285242Sachim                       osData->tiRoot,
1899285242Sachim                       outboundChannelNum
1900285242Sachim                       );
1901285242Sachim  return;
1902285242Sachim}
1903285242Sachim
1904285242Sachim#endif
1905285242Sachim
1906285242Sachim
1907285242SachimosGLOBAL void
1908285242SachimtiCOMFrameReadBlock(
1909285242Sachim                    tiRoot_t          *tiRoot,
1910285242Sachim                    void              *agFrame,
1911285242Sachim                    bit32             FrameOffset,
1912285242Sachim                    void              *FrameBuffer,
1913285242Sachim                    bit32             FrameBufLen )
1914285242Sachim{
1915285242Sachim  tdsaRoot_t                *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
1916285242Sachim  tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1917285242Sachim  agsaRoot_t                *agRoot = agNULL;
1918285242Sachim
1919285242Sachim  TI_DBG6(("tiCOMFrameReadBlock: start\n"));
1920285242Sachim
1921285242Sachim
1922285242Sachim  agRoot = &(tdsaAllShared->agRootNonInt);
1923285242Sachim
1924285242Sachim
1925285242Sachim  TI_DBG6(("tiCOMFrameReadBlock: start\n"));
1926285242Sachim
1927285242Sachim  saFrameReadBlock(agRoot, agFrame, FrameOffset, FrameBuffer, FrameBufLen);
1928285242Sachim
1929285242Sachim  return;
1930285242Sachim}
1931285242Sachim
1932285242Sachim
1933285242Sachim
1934285242Sachim/*****************************************************************************
1935285242Sachim*! \brief tiINITransportRecovery
1936285242Sachim*
1937285242Sachim* Purpose:  This routine is called to explicitly ask the Transport Dependent
1938285242Sachim*           Layer to initiate the recovery for the transport/protocol specific
1939285242Sachim*           error for a specific device connection.
1940285242Sachim*
1941285242Sachim*  \param   tiRoot:         Pointer to driver instance
1942285242Sachim*  \param   tiDeviveHandle: Pointer to the device handle for this session.
1943285242Sachim*
1944285242Sachim*  \return: None
1945285242Sachim*
1946285242Sachim*
1947285242Sachim*****************************************************************************/
1948285242Sachim#ifdef INITIATOR_DRIVER
1949285242SachimosGLOBAL void
1950285242SachimtiINITransportRecovery (
1951285242Sachim                        tiRoot_t          *tiRoot,
1952285242Sachim                        tiDeviceHandle_t  *tiDeviceHandle
1953285242Sachim                        )
1954285242Sachim{
1955285242Sachim  agsaRoot_t                  *agRoot = agNULL;
1956285242Sachim  tdsaDeviceData_t            *oneDeviceData = agNULL;
1957285242Sachim  tdsaPortContext_t           *onePortContext = agNULL;
1958285242Sachim  tiPortalContext_t           *tiPortalContext = agNULL;
1959285242Sachim  tiIORequest_t               *currentTaskTag;
1960285242Sachim  agsaDevHandle_t             *agDevHandle = agNULL;
1961285242Sachim
1962285242Sachim  TI_DBG1(("tiINITransportRecovery: start\n"));
1963285242Sachim
1964285242Sachim  if (tiDeviceHandle == agNULL)
1965285242Sachim  {
1966285242Sachim    TI_DBG1(("tiINITransportRecovery: tiDeviceHandle is NULL\n"));
1967285242Sachim
1968285242Sachim    return;
1969285242Sachim  }
1970285242Sachim
1971285242Sachim  oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
1972285242Sachim
1973285242Sachim  if (oneDeviceData == agNULL)
1974285242Sachim  {
1975285242Sachim    TI_DBG1(("tiINITransportRecovery: oneDeviceData is NULL\n"));
1976285242Sachim    return;
1977285242Sachim  }
1978285242Sachim
1979285242Sachim  /* for hotplug */
1980285242Sachim  if (oneDeviceData->valid != agTRUE || oneDeviceData->registered != agTRUE ||
1981285242Sachim      oneDeviceData->tdPortContext == agNULL )
1982285242Sachim  {
1983285242Sachim    TI_DBG1(("tiINITransportRecovery: NO Device did %d\n", oneDeviceData->id ));
1984285242Sachim    TI_DBG1(("tiINITransportRecovery: device AddrHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
1985285242Sachim    TI_DBG1(("tiINITransportRecovery: device AddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
1986285242Sachim    return;
1987285242Sachim  }
1988285242Sachim
1989285242Sachim  onePortContext = oneDeviceData->tdPortContext;
1990285242Sachim
1991285242Sachim  if (onePortContext == agNULL)
1992285242Sachim  {
1993285242Sachim    TI_DBG1(("tiINITransportRecovery: onePortContext is NULL\n"));
1994285242Sachim    return;
1995285242Sachim  }
1996285242Sachim
1997285242Sachim  tiPortalContext = onePortContext->tiPortalContext;
1998285242Sachim  currentTaskTag = &(oneDeviceData->TransportRecoveryIO);
1999285242Sachim  currentTaskTag->osData = agNULL;
2000285242Sachim  agRoot = oneDeviceData->agRoot;
2001285242Sachim  agDevHandle = oneDeviceData->agDevHandle;
2002285242Sachim
2003285242Sachim  if (oneDeviceData->DeviceType == TD_SAS_DEVICE)
2004285242Sachim  {
2005285242Sachim    agsaContext_t           *agContext;
2006285242Sachim    currentTaskTag->tdData = oneDeviceData;
2007285242Sachim    agContext = &(oneDeviceData->agDeviceResetContext);
2008285242Sachim    agContext->osData = currentTaskTag;
2009285242Sachim    oneDeviceData->TRflag = agTRUE;
2010285242Sachim
2011285242Sachim    TI_DBG2(("tiINITransportRecovery: SAS device\n"));
2012285242Sachim    saSetDeviceState(agRoot, agNULL, tdsaRotateQnumber(tiRoot, oneDeviceData), agDevHandle, SA_DS_IN_RECOVERY);
2013285242Sachim
2014285242Sachim    if (oneDeviceData->directlyAttached == agTRUE)
2015285242Sachim    {
2016285242Sachim      TI_DBG2(("tiINITransportRecovery: saLocalPhyControl\n"));
2017285242Sachim      saLocalPhyControl(agRoot, agContext, tdsaRotateQnumber(tiRoot, oneDeviceData), oneDeviceData->phyID, AGSA_PHY_HARD_RESET, agNULL);
2018285242Sachim      ostiInitiatorEvent(tiRoot,
2019285242Sachim                         tiPortalContext,
2020285242Sachim                         tiDeviceHandle,
2021285242Sachim                         tiIntrEventTypeTransportRecovery,
2022285242Sachim                         tiRecStarted,
2023285242Sachim                         agNULL
2024285242Sachim                        );
2025285242Sachim
2026285242Sachim      return;
2027285242Sachim    }
2028285242Sachim    else
2029285242Sachim    {
2030285242Sachim      TI_DBG2(("tiINITransportRecovery: device reset expander attached\n"));
2031285242Sachim      tdsaPhyControlSend(tiRoot,
2032285242Sachim                         oneDeviceData,
2033285242Sachim                         SMP_PHY_CONTROL_HARD_RESET,
2034285242Sachim                         currentTaskTag,
2035285242Sachim                         tdsaRotateQnumber(tiRoot, oneDeviceData)
2036285242Sachim                        );
2037285242Sachim      ostiInitiatorEvent(tiRoot,
2038285242Sachim                         tiPortalContext,
2039285242Sachim                         tiDeviceHandle,
2040285242Sachim                         tiIntrEventTypeTransportRecovery,
2041285242Sachim                         tiRecStarted,
2042285242Sachim                         agNULL
2043285242Sachim                        );
2044285242Sachim      return;
2045285242Sachim    }
2046285242Sachim  }
2047285242Sachim  else if (oneDeviceData->DeviceType == TD_SATA_DEVICE)
2048285242Sachim  {
2049285242Sachim    agsaContext_t           *agContext;
2050285242Sachim    currentTaskTag->tdData = oneDeviceData;
2051285242Sachim    agContext = &(oneDeviceData->agDeviceResetContext);
2052285242Sachim    agContext->osData = currentTaskTag;
2053285242Sachim    oneDeviceData->TRflag = agTRUE;
2054285242Sachim
2055285242Sachim    TI_DBG2(("tiINITransportRecovery: SATA device\n"));
2056285242Sachim    saSetDeviceState(agRoot, agNULL, tdsaRotateQnumber(tiRoot, oneDeviceData), agDevHandle, SA_DS_IN_RECOVERY);
2057285242Sachim
2058285242Sachim    if (oneDeviceData->directlyAttached == agTRUE)
2059285242Sachim    {
2060285242Sachim      TI_DBG2(("tiINITransportRecovery: saLocalPhyControl\n"));
2061285242Sachim      saLocalPhyControl(agRoot, agContext, tdsaRotateQnumber(tiRoot, oneDeviceData), oneDeviceData->phyID, AGSA_PHY_LINK_RESET, agNULL);
2062285242Sachim      ostiInitiatorEvent(tiRoot,
2063285242Sachim                         tiPortalContext,
2064285242Sachim                         tiDeviceHandle,
2065285242Sachim                         tiIntrEventTypeTransportRecovery,
2066285242Sachim                         tiRecStarted,
2067285242Sachim                         agNULL
2068285242Sachim                        );
2069285242Sachim
2070285242Sachim      return;
2071285242Sachim    }
2072285242Sachim    else
2073285242Sachim    {
2074285242Sachim      TI_DBG2(("tiINITransportRecovery: device reset expander attached\n"));
2075285242Sachim      tdsaPhyControlSend(tiRoot,
2076285242Sachim                         oneDeviceData,
2077285242Sachim                         SMP_PHY_CONTROL_LINK_RESET,
2078285242Sachim                         currentTaskTag,
2079285242Sachim                         tdsaRotateQnumber(tiRoot, oneDeviceData)
2080285242Sachim                        );
2081285242Sachim      ostiInitiatorEvent(tiRoot,
2082285242Sachim                         tiPortalContext,
2083285242Sachim                         tiDeviceHandle,
2084285242Sachim                         tiIntrEventTypeTransportRecovery,
2085285242Sachim                         tiRecStarted,
2086285242Sachim                         agNULL
2087285242Sachim                        );
2088285242Sachim      return;
2089285242Sachim    }
2090285242Sachim  }
2091285242Sachim  else
2092285242Sachim  {
2093285242Sachim    TI_DBG1(("tiINITransportRecovery: wrong device type %d\n", oneDeviceData->DeviceType));
2094285242Sachim  }
2095285242Sachim
2096285242Sachim
2097285242Sachim  return;
2098285242Sachim}
2099285242Sachim#endif
2100285242Sachim
2101285242Sachim#if defined (INITIATOR_DRIVER) && defined (TARGET_DRIVER)
2102285242Sachim/*****************************************************************************
2103285242Sachim*! \brief  tdsaPhyControlSend
2104285242Sachim*
2105285242Sachim*  Purpose:  This function sends Phy Control to a device.
2106285242Sachim*
2107285242Sachim*  \param   tiRoot: Pointer to the OS Specific module allocated tiRoot_t
2108285242Sachim*                   instance.
2109285242Sachim*  \param   oneDeviceData: Pointer to the device data.
2110285242Sachim*  \param   phyId: Phy Identifier.
2111285242Sachim*  \param   queueNumber: bits 0-15:  inbound queue number.
2112285242Sachim*                        bits 16-31: outbound queue number.
2113285242Sachim*
2114285242Sachim*  \return:
2115285242Sachim*           Status
2116285242Sachim*
2117285242Sachim*   \note:
2118285242Sachim*
2119285242Sachim*****************************************************************************/
2120285242Sachim/* phyop of interest
2121285242SachimSMP_PHY_CONTROL_HARD_RESET or SMP_PHY_CONTROL_CLEAR_AFFILIATION
2122285242Sachimif CurrentTaskTag == agNULL, clear affiliation
2123285242Sachimif CurrentTaskTag != agNULL, PHY_CONTROL (device reset)
2124285242Sachim
2125285242Sachim*/
2126285242SachimosGLOBAL bit32
2127285242SachimtdsaPhyControlSend(
2128285242Sachim                   tiRoot_t             *tiRoot,
2129285242Sachim                   tdsaDeviceData_t     *oneDeviceData, /* taget disk */
2130285242Sachim                   bit8                 phyOp,
2131285242Sachim                   tiIORequest_t        *CurrentTaskTag,
2132285242Sachim                   bit32                queueNumber
2133285242Sachim                   )
2134285242Sachim{
2135285242Sachim  return 0;
2136285242Sachim}
2137285242Sachim#endif
2138285242Sachim
2139285242Sachim#ifdef TARGET_DRIVER
2140285242Sachim/*****************************************************************************
2141285242Sachim*! \brief  tdsaPhyControlSend
2142285242Sachim*
2143285242Sachim*  Purpose:  This function sends Phy Control to a device.
2144285242Sachim*
2145285242Sachim*  \param   tiRoot: Pointer to the OS Specific module allocated tiRoot_t
2146285242Sachim*                   instance.
2147285242Sachim*  \param   oneDeviceData: Pointer to the device data.
2148285242Sachim*  \param   phyId: Phy Identifier.
2149285242Sachim*  \param   queueNumber: bits 0-15:  inbound queue number.
2150285242Sachim*                        bits 16-31: outbound queue number.
2151285242Sachim*
2152285242Sachim*  \return:
2153285242Sachim*           Status
2154285242Sachim*
2155285242Sachim*   \note:
2156285242Sachim*
2157285242Sachim*****************************************************************************/
2158285242Sachim/* phyop of interest
2159285242SachimSMP_PHY_CONTROL_HARD_RESET or SMP_PHY_CONTROL_CLEAR_AFFILIATION
2160285242Sachimif CurrentTaskTag == agNULL, clear affiliation
2161285242Sachimif CurrentTaskTag != agNULL, PHY_CONTROL (device reset)
2162285242Sachim
2163285242Sachim*/
2164285242SachimosGLOBAL bit32
2165285242SachimtdsaPhyControlSend(
2166285242Sachim                   tiRoot_t             *tiRoot,
2167285242Sachim                   tdsaDeviceData_t     *oneDeviceData, /* taget disk */
2168285242Sachim                   bit8                 phyOp,
2169285242Sachim                   tiIORequest_t        *CurrentTaskTag,
2170285242Sachim                   bit32                queueNumber
2171285242Sachim                   )
2172285242Sachim{
2173285242Sachim  return 0;
2174285242Sachim}
2175285242Sachim#endif
2176285242Sachim
2177285242Sachim
2178285242Sachim#ifdef INITIATOR_DRIVER
2179285242Sachim/*****************************************************************************
2180285242Sachim*! \brief  tdsaPhyControlSend
2181285242Sachim*
2182285242Sachim*  Purpose:  This function sends Phy Control to a device.
2183285242Sachim*
2184285242Sachim*  \param   tiRoot: Pointer to the OS Specific module allocated tiRoot_t
2185285242Sachim*                   instance.
2186285242Sachim*  \param   oneDeviceData: Pointer to the device data.
2187285242Sachim*  \param   phyId: Phy Identifier.
2188285242Sachim*  \param   queueNumber: bits 0-15:  inbound queue number.
2189285242Sachim*                        bits 16-31: outbound queue number.
2190285242Sachim*
2191285242Sachim*  \return:
2192285242Sachim*           Status
2193285242Sachim*
2194285242Sachim*   \note:
2195285242Sachim*
2196285242Sachim*****************************************************************************/
2197285242Sachim/* phyop of interest
2198285242SachimSMP_PHY_CONTROL_HARD_RESET or SMP_PHY_CONTROL_CLEAR_AFFILIATION
2199285242Sachimif CurrentTaskTag == agNULL, clear affiliation
2200285242Sachimif CurrentTaskTag != agNULL, PHY_CONTROL (device reset)
2201285242Sachim
2202285242Sachim*/
2203285242SachimosGLOBAL bit32
2204285242SachimtdsaPhyControlSend(
2205285242Sachim                   tiRoot_t             *tiRoot,
2206285242Sachim                   tdsaDeviceData_t     *oneDeviceData, /* taget disk */
2207285242Sachim                   bit8                 phyOp,
2208285242Sachim                   tiIORequest_t        *CurrentTaskTag,
2209285242Sachim                   bit32                queueNumber
2210285242Sachim                   )
2211285242Sachim{
2212285242Sachim  agsaRoot_t            *agRoot;
2213285242Sachim  tdsaDeviceData_t      *oneExpDeviceData;
2214285242Sachim  tdsaPortContext_t     *onePortContext;
2215285242Sachim  smpReqPhyControl_t    smpPhyControlReq;
2216285242Sachim  bit8                  phyID;
2217285242Sachim  bit32                 status;
2218285242Sachim
2219285242Sachim  TI_DBG3(("tdsaPhyControlSend: start\n"));
2220285242Sachim
2221285242Sachim  agRoot = oneDeviceData->agRoot;
2222285242Sachim  onePortContext = oneDeviceData->tdPortContext;
2223285242Sachim  oneExpDeviceData = oneDeviceData->ExpDevice;
2224285242Sachim  phyID = oneDeviceData->phyID;
2225285242Sachim
2226285242Sachim  if (oneDeviceData->directlyAttached == agTRUE)
2227285242Sachim  {
2228285242Sachim    TI_DBG1(("tdsaPhyControlSend: Error!!! deivce is directly attached\n"));
2229285242Sachim    return AGSA_RC_FAILURE;
2230285242Sachim  }
2231285242Sachim  if (onePortContext == agNULL)
2232285242Sachim  {
2233285242Sachim    TI_DBG1(("tdsaPhyControlSend: Error!!! portcontext is NULL\n"));
2234285242Sachim    return AGSA_RC_FAILURE;
2235285242Sachim  }
2236285242Sachim
2237285242Sachim  if (oneExpDeviceData == agNULL)
2238285242Sachim  {
2239285242Sachim    TI_DBG1(("tdsaPhyControlSend: Error!!! expander is NULL\n"));
2240285242Sachim    return AGSA_RC_FAILURE;
2241285242Sachim  }
2242285242Sachim
2243285242Sachim  if (phyOp == SMP_PHY_CONTROL_HARD_RESET)
2244285242Sachim  {
2245285242Sachim    TI_DBG3(("tdsaPhyControlSend: SMP_PHY_CONTROL_HARD_RESET\n"));
2246285242Sachim  }
2247285242Sachim  if (phyOp == SMP_PHY_CONTROL_LINK_RESET)
2248285242Sachim  {
2249285242Sachim    TI_DBG3(("tdsaPhyControlSend: SMP_PHY_CONTROL_LINK_RESET\n"));
2250285242Sachim  }
2251285242Sachim  if (phyOp == SMP_PHY_CONTROL_CLEAR_AFFILIATION)
2252285242Sachim  {
2253285242Sachim    TI_DBG3(("tdsaPhyControlSend: SMP_PHY_CONTROL_CLEAR_AFFILIATION\n"));
2254285242Sachim  }
2255285242Sachim  TI_DBG3(("tdsaPhyControlSend: target device AddrHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
2256285242Sachim  TI_DBG3(("tdsaPhyControlSend: target device AddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
2257285242Sachim  TI_DBG3(("tdsaPhyControlSend: expander AddrHi 0x%08x\n", oneExpDeviceData->SASAddressID.sasAddressHi));
2258285242Sachim  TI_DBG3(("tdsaPhyControlSend: expander AddrLo 0x%08x\n", oneExpDeviceData->SASAddressID.sasAddressLo));
2259285242Sachim  TI_DBG3(("tdsaPhyControlSend: did %d expander did %d phyid %d\n", oneDeviceData->id, oneExpDeviceData->id, phyID));
2260285242Sachim
2261285242Sachim
2262285242Sachim  osti_memset(&smpPhyControlReq, 0, sizeof(smpReqPhyControl_t));
2263285242Sachim
2264285242Sachim  /* fill in SMP payload */
2265285242Sachim  smpPhyControlReq.phyIdentifier = phyID;
2266285242Sachim  smpPhyControlReq.phyOperation = phyOp;
2267285242Sachim
2268285242Sachim  status = tdSMPStart(
2269285242Sachim                      tiRoot,
2270285242Sachim                      agRoot,
2271285242Sachim                      oneExpDeviceData,
2272285242Sachim                      SMP_PHY_CONTROL,
2273285242Sachim                      (bit8 *)&smpPhyControlReq,
2274285242Sachim                      sizeof(smpReqPhyControl_t),
2275285242Sachim                      AGSA_SMP_INIT_REQ,
2276285242Sachim                      CurrentTaskTag,
2277285242Sachim                      queueNumber
2278285242Sachim                     );
2279285242Sachim  return status;
2280285242Sachim}
2281285242Sachim#endif
2282285242Sachim
2283285242Sachim/*****************************************************************************
2284285242Sachim*! \brief  tdsaPhyControlFailureRespRcvd
2285285242Sachim*
2286285242Sachim*  Purpose:  This function processes the failure of Phy Control response.
2287285242Sachim*
2288285242Sachim*  \param   tiRoot: Pointer to the OS Specific module allocated tiRoot_t
2289285242Sachim*                   instance.
2290285242Sachim*  \param   agRoot: Pointer to chip/driver Instance.
2291285242Sachim*  \param   oneDeviceData: Pointer to the device data.
2292285242Sachim*  \param   frameHeader: Pointer to SMP frame header.
2293285242Sachim*  \param   frameHandle: A Handle used to refer to the response frame
2294285242Sachim*
2295285242Sachim*  \return:
2296285242Sachim*           None
2297285242Sachim*
2298285242Sachim*   \note:
2299285242Sachim*
2300285242Sachim*****************************************************************************/
2301285242SachimosGLOBAL void
2302285242SachimtdsaPhyControlFailureRespRcvd(
2303285242Sachim                              tiRoot_t              *tiRoot,
2304285242Sachim                              agsaRoot_t            *agRoot,
2305285242Sachim                              tdsaDeviceData_t      *oneDeviceData,
2306285242Sachim                              tdssSMPFrameHeader_t  *frameHeader,
2307285242Sachim                              agsaFrameHandle_t     frameHandle,
2308285242Sachim                              tiIORequest_t         *CurrentTaskTag
2309285242Sachim                             )
2310285242Sachim{
2311285242Sachim#if defined(INITIATOR_DRIVER) || defined(TD_DEBUG_ENABLE)
2312285242Sachim  tdsaDeviceData_t      *TargetDeviceData = agNULL;
2313285242Sachim#endif
2314285242Sachim#ifdef TD_DEBUG_ENABLE
2315285242Sachim  satDeviceData_t       *pSatDevData = agNULL;
2316285242Sachim#endif
2317285242Sachim//  agsaDevHandle_t       *agDevHandle = agNULL;
2318285242Sachim
2319285242Sachim  TI_DBG1(("tdsaPhyControlFailureRespRcvd: start\n"));
2320285242Sachim
2321285242Sachim  TI_DBG3(("tdsaPhyControlFailureRespRcvd: expander device AddrHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
2322285242Sachim  TI_DBG3(("tdsaPhyControlFailureRespRcvd: expander device AddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
2323285242Sachim
2324285242Sachim  if (CurrentTaskTag != agNULL )
2325285242Sachim  {
2326285242Sachim    /* This was set in tiINITaskmanagement() */
2327285242Sachim#if defined(INITIATOR_DRIVER) || defined(TD_DEBUG_ENABLE)
2328285242Sachim    TargetDeviceData = (tdsaDeviceData_t *)CurrentTaskTag->tdData;
2329285242Sachim#endif
2330285242Sachim#ifdef TD_DEBUG_ENABLE
2331285242Sachim    pSatDevData = (satDeviceData_t *)&(TargetDeviceData->satDevData);
2332285242Sachim#endif
2333285242Sachim//    agDevHandle = TargetDeviceData->agDevHandle;
2334285242Sachim    TI_DBG2(("tdsaPhyControlFailureRespRcvd: target AddrHi 0x%08x\n", TargetDeviceData->SASAddressID.sasAddressHi));
2335285242Sachim    TI_DBG2(("tdsaPhyControlFailureRespRcvd: target AddrLo 0x%08x\n", TargetDeviceData->SASAddressID.sasAddressLo));
2336285242Sachim
2337285242Sachim#ifdef TD_DEBUG_ENABLE
2338285242Sachim    TI_DBG2(("tdsaPhyControlFailureRespRcvd: satPendingIO %d satNCQMaxIO %d\n", pSatDevData->satPendingIO, pSatDevData->satNCQMaxIO ));
2339285242Sachim    TI_DBG2(("tdsaPhyControlFailureRespRcvd: satPendingNCQIO %d satPendingNONNCQIO %d\n", pSatDevData->satPendingNCQIO, pSatDevData->satPendingNONNCQIO));
2340285242Sachim#endif
2341285242Sachim  }
2342285242Sachim
2343285242Sachim#ifdef INITIATOR_DRIVER
2344285242Sachim  if (CurrentTaskTag != agNULL )
2345285242Sachim  {
2346285242Sachim    TI_DBG1(("tdsaPhyControlRespRcvd: callback to OS layer with failure\n"));
2347285242Sachim    if (TargetDeviceData->TRflag == agTRUE)
2348285242Sachim    {
2349285242Sachim      TargetDeviceData->TRflag = agFALSE;
2350285242Sachim      ostiInitiatorEvent(tiRoot,
2351285242Sachim                         TargetDeviceData->tdPortContext->tiPortalContext,
2352285242Sachim                         &(TargetDeviceData->tiDeviceHandle),
2353285242Sachim                         tiIntrEventTypeTransportRecovery,
2354285242Sachim                         tiRecFailed ,
2355285242Sachim                         agNULL
2356285242Sachim                        );
2357285242Sachim    }
2358285242Sachim    else
2359285242Sachim    {
2360285242Sachim      ostiInitiatorEvent( tiRoot,
2361285242Sachim                          NULL,
2362285242Sachim                          NULL,
2363285242Sachim                          tiIntrEventTypeTaskManagement,
2364285242Sachim                          tiTMFailed,
2365285242Sachim                          CurrentTaskTag );
2366285242Sachim    }
2367285242Sachim  }
2368285242Sachim#endif
2369285242Sachim  return;
2370285242Sachim}
2371285242Sachim/*****************************************************************************
2372285242Sachim*! \brief  tdsaPhyControlRespRcvd
2373285242Sachim*
2374285242Sachim*  Purpose:  This function processes Phy Control response.
2375285242Sachim*
2376285242Sachim*  \param   tiRoot: Pointer to the OS Specific module allocated tiRoot_t
2377285242Sachim*                   instance.
2378285242Sachim*  \param   agRoot: Pointer to chip/driver Instance.
2379285242Sachim*  \param   oneDeviceData: Pointer to the device data.
2380285242Sachim*  \param   frameHeader: Pointer to SMP frame header.
2381285242Sachim*  \param   frameHandle: A Handle used to refer to the response frame
2382285242Sachim*
2383285242Sachim*  \return:
2384285242Sachim*           None
2385285242Sachim*
2386285242Sachim*   \note:
2387285242Sachim*
2388285242Sachim*****************************************************************************/
2389285242SachimosGLOBAL void
2390285242SachimtdsaPhyControlRespRcvd(
2391285242Sachim                       tiRoot_t              *tiRoot,
2392285242Sachim                       agsaRoot_t            *agRoot,
2393285242Sachim                       agsaIORequest_t       *agIORequest,
2394285242Sachim                       tdsaDeviceData_t      *oneDeviceData,
2395285242Sachim                       tdssSMPFrameHeader_t  *frameHeader,
2396285242Sachim                       agsaFrameHandle_t     frameHandle,
2397285242Sachim                       tiIORequest_t         *CurrentTaskTag
2398285242Sachim                       )
2399285242Sachim{
2400285242Sachim#if defined(INITIATOR_DRIVER) || defined(TD_DEBUG_ENABLE)
2401285242Sachim  tdsaDeviceData_t      *TargetDeviceData = agNULL;
2402285242Sachim#endif
2403285242Sachim#ifdef INITIATOR_DRIVER
2404285242Sachim  satDeviceData_t       *pSatDevData = agNULL;
2405285242Sachim  agsaDevHandle_t       *agDevHandle = agNULL;
2406285242Sachim#endif
2407285242Sachim
2408285242Sachim  TI_DBG3(("tdsaPhyControlRespRcvd: start\n"));
2409285242Sachim
2410285242Sachim  TI_DBG3(("tdsaPhyControlRespRcvd: expander device AddrHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
2411285242Sachim  TI_DBG3(("tdsaPhyControlRespRcvd: expander device AddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
2412285242Sachim
2413285242Sachim  if (CurrentTaskTag != agNULL )
2414285242Sachim  {
2415285242Sachim    /* This was set in tiINITaskmanagement() */
2416285242Sachim#if defined(INITIATOR_DRIVER) || defined(TD_DEBUG_ENABLE)
2417285242Sachim    TargetDeviceData = (tdsaDeviceData_t *)CurrentTaskTag->tdData;
2418285242Sachim#endif
2419285242Sachim#ifdef INITIATOR_DRIVER
2420285242Sachim    pSatDevData = (satDeviceData_t *)&(TargetDeviceData->satDevData);
2421285242Sachim    agDevHandle = TargetDeviceData->agDevHandle;
2422285242Sachim#endif
2423285242Sachim    TI_DBG2(("tdsaPhyControlRespRcvd: target AddrHi 0x%08x\n", TargetDeviceData->SASAddressID.sasAddressHi));
2424285242Sachim    TI_DBG2(("tdsaPhyControlRespRcvd: target AddrLo 0x%08x\n", TargetDeviceData->SASAddressID.sasAddressLo));
2425285242Sachim
2426285242Sachim#ifdef INITIATOR_DRIVER
2427285242Sachim    TI_DBG2(("tdsaPhyControlRespRcvd: satPendingIO %d satNCQMaxIO %d\n", pSatDevData->satPendingIO, pSatDevData->satNCQMaxIO ));
2428285242Sachim    TI_DBG2(("tdsaPhyControlRespRcvd: satPendingNCQIO %d satPendingNONNCQIO %d\n", pSatDevData->satPendingNCQIO, pSatDevData->satPendingNONNCQIO));
2429285242Sachim#endif
2430285242Sachim  }
2431285242Sachim
2432285242Sachim#ifdef INITIATOR_DRIVER
2433285242Sachim  /* no payload */
2434285242Sachim  if (frameHeader->smpFunctionResult == SMP_FUNCTION_ACCEPTED)
2435285242Sachim  {
2436285242Sachim    TI_DBG3(("tdsaPhyControlRespRcvd: SMP success\n"));
2437285242Sachim
2438285242Sachim    /* warm reset or clear affiliation is done
2439285242Sachim       call ostiInitiatorEvent()
2440285242Sachim    */
2441285242Sachim    if (CurrentTaskTag != agNULL )
2442285242Sachim    {
2443285242Sachim      TI_DBG3(("tdsaPhyControlRespRcvd: callback to OS layer with success\n"));
2444285242Sachim      pSatDevData->satDriveState = SAT_DEV_STATE_NORMAL;
2445285242Sachim      saSetDeviceState(agRoot, agNULL, tdsaRotateQnumber(tiRoot, TargetDeviceData), agDevHandle, SA_DS_OPERATIONAL);
2446285242Sachim
2447285242Sachim      if (TargetDeviceData->TRflag == agTRUE)
2448285242Sachim      {
2449285242Sachim        TargetDeviceData->TRflag = agFALSE;
2450285242Sachim        ostiInitiatorEvent(tiRoot,
2451285242Sachim                           TargetDeviceData->tdPortContext->tiPortalContext,
2452285242Sachim                           &(TargetDeviceData->tiDeviceHandle),
2453285242Sachim                           tiIntrEventTypeTransportRecovery,
2454285242Sachim                           tiRecOK,
2455285242Sachim                           agNULL
2456285242Sachim                          );
2457285242Sachim      }
2458285242Sachim      else
2459285242Sachim      {
2460285242Sachim        agDevHandle = TargetDeviceData->agDevHandle;
2461285242Sachim        if (agDevHandle == agNULL)
2462285242Sachim        {
2463285242Sachim          TI_DBG1(("tdsaPhyControlRespRcvd: wrong, agDevHandle is NULL\n"));
2464285242Sachim        }
2465285242Sachim        ostiInitiatorEvent( tiRoot,
2466285242Sachim                            NULL,
2467285242Sachim                            NULL,
2468285242Sachim                            tiIntrEventTypeTaskManagement,
2469285242Sachim                            tiTMOK,
2470285242Sachim                            CurrentTaskTag );
2471285242Sachim      }
2472285242Sachim    }
2473285242Sachim
2474285242Sachim  }
2475285242Sachim  else
2476285242Sachim  {
2477285242Sachim    TI_DBG1(("tdsaPhyControlRespRcvd: SMP failure; result %d\n", frameHeader->smpFunctionResult));
2478285242Sachim    /* warm reset or clear affiliation is done
2479285242Sachim    */
2480285242Sachim    if (CurrentTaskTag != agNULL )
2481285242Sachim    {
2482285242Sachim      TI_DBG1(("tdsaPhyControlRespRcvd: callback to OS layer with failure\n"));
2483285242Sachim      if (TargetDeviceData->TRflag == agTRUE)
2484285242Sachim      {
2485285242Sachim        TargetDeviceData->TRflag = agFALSE;
2486285242Sachim        ostiInitiatorEvent(tiRoot,
2487285242Sachim                           TargetDeviceData->tdPortContext->tiPortalContext,
2488285242Sachim                           &(TargetDeviceData->tiDeviceHandle),
2489285242Sachim                           tiIntrEventTypeTransportRecovery,
2490285242Sachim                           tiRecFailed ,
2491285242Sachim                           agNULL
2492285242Sachim                          );
2493285242Sachim      }
2494285242Sachim      else
2495285242Sachim      {
2496285242Sachim        ostiInitiatorEvent( tiRoot,
2497285242Sachim                            NULL,
2498285242Sachim                            NULL,
2499285242Sachim                            tiIntrEventTypeTaskManagement,
2500285242Sachim                            tiTMFailed,
2501285242Sachim                            CurrentTaskTag );
2502285242Sachim      }
2503285242Sachim    }
2504285242Sachim
2505285242Sachim  }
2506285242Sachim#endif
2507285242Sachim  return;
2508285242Sachim}
2509285242Sachim
2510285242Sachim
2511285242Sachim#ifdef TARGET_DRIVER
2512285242Sachim/*****************************************************************************
2513285242Sachim*! \brief ttdsaAbortAll
2514285242Sachim*
2515285242Sachim*  Purpose:  This function is called to abort an all pending I/O request on a
2516285242Sachim*            device
2517285242Sachim*
2518285242Sachim*  \param  tiRoot:          Pointer to initiator driver/port instance.
2519285242Sachim*  \param  agRoot:          Pointer to chip/driver Instance.
2520285242Sachim*  \param  oneDeviceData:   Pointer to the device
2521285242Sachim*
2522285242Sachim*  \return:
2523285242Sachim*
2524285242Sachim*          None
2525285242Sachim*
2526285242Sachim*****************************************************************************/
2527285242Sachim/*
2528285242Sachim  for abort itself,
2529285242Sachim  should we allocate tdAbortIORequestBody or get one from ttdsaXchg_t?
2530285242Sachim  Currently, we allocate tdAbortIORequestBody.
2531285242Sachim*/
2532285242SachimosGLOBAL void
2533285242SachimttdsaAbortAll(
2534285242Sachim             tiRoot_t                   *tiRoot,
2535285242Sachim             agsaRoot_t                 *agRoot,
2536285242Sachim             tdsaDeviceData_t           *oneDeviceData
2537285242Sachim             )
2538285242Sachim{
2539285242Sachim  agsaIORequest_t     *agAbortIORequest = agNULL;
2540285242Sachim  tdIORequestBody_t   *tdAbortIORequestBody = agNULL;
2541285242Sachim  bit32               PhysUpper32;
2542285242Sachim  bit32               PhysLower32;
2543285242Sachim  bit32               memAllocStatus;
2544285242Sachim  void                *osMemHandle;
2545285242Sachim
2546285242Sachim  TI_DBG3(("tdsaAbortAll: start\n"));
2547285242Sachim
2548285242Sachim  TI_DBG3(("tdsaAbortAll: did %d\n", oneDeviceData->id));
2549285242Sachim
2550285242Sachim
2551285242Sachim  /* allocating agIORequest for abort itself */
2552285242Sachim  memAllocStatus = ostiAllocMemory(
2553285242Sachim                                   tiRoot,
2554285242Sachim                                   &osMemHandle,
2555285242Sachim                                   (void **)&tdAbortIORequestBody,
2556285242Sachim                                   &PhysUpper32,
2557285242Sachim                                   &PhysLower32,
2558285242Sachim                                   8,
2559285242Sachim                                   sizeof(tdIORequestBody_t),
2560285242Sachim                                   agTRUE
2561285242Sachim                                   );
2562285242Sachim  if (memAllocStatus != tiSuccess)
2563285242Sachim  {
2564285242Sachim    /* let os process IO */
2565285242Sachim    TI_DBG1(("tdsaAbortAll: ostiAllocMemory failed...\n"));
2566285242Sachim    return;
2567285242Sachim  }
2568285242Sachim
2569285242Sachim  if (tdAbortIORequestBody == agNULL)
2570285242Sachim  {
2571285242Sachim    /* let os process IO */
2572285242Sachim    TI_DBG1(("tdsaAbortAll: ostiAllocMemory returned NULL tdAbortIORequestBody\n"));
2573285242Sachim    return;
2574285242Sachim  }
2575285242Sachim
2576285242Sachim  /* setup task management structure */
2577285242Sachim  tdAbortIORequestBody->IOType.InitiatorTMIO.osMemHandle = osMemHandle;
2578285242Sachim  /* setting callback */
2579285242Sachim  /* not needed; it is already set to be ossaSSPAbortCB() */
2580285242Sachim  tdAbortIORequestBody->IOCompletionFunc = ttdssIOAbortedHandler;
2581285242Sachim
2582285242Sachim  tdAbortIORequestBody->tiDevHandle = (tiDeviceHandle_t *)&(oneDeviceData->tiDeviceHandle);
2583285242Sachim
2584285242Sachim  /* initialize agIORequest */
2585285242Sachim  agAbortIORequest = &(tdAbortIORequestBody->agIORequest);
2586285242Sachim  agAbortIORequest->osData = (void *) tdAbortIORequestBody;
2587285242Sachim  agAbortIORequest->sdkData = agNULL; /* LL takes care of this */
2588285242Sachim
2589285242Sachim  /* SSPAbort */
2590285242Sachim  saSSPAbort(agRoot,
2591285242Sachim             agAbortIORequest,
2592285242Sachim             0,
2593285242Sachim             oneDeviceData->agDevHandle,
2594285242Sachim             1, /* abort all */
2595285242Sachim             agNULL,
2596285242Sachim             agNULL
2597285242Sachim             );
2598285242Sachim  return;
2599285242Sachim}
2600285242Sachim#endif /* TARGET_DRIVER */
2601285242Sachim
2602285242Sachim
2603285242SachimosGLOBAL void
2604285242SachimtdsaDeregisterDevicesInPort(
2605285242Sachim                tiRoot_t             *tiRoot,
2606285242Sachim                tdsaPortContext_t    *onePortContext
2607285242Sachim               )
2608285242Sachim{
2609285242Sachim  tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
2610285242Sachim  tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2611285242Sachim  tdsaDeviceData_t  *oneDeviceData = agNULL;
2612285242Sachim  tdList_t          *DeviceListList;
2613285242Sachim  agsaRoot_t        *agRoot = agNULL;
2614285242Sachim
2615285242Sachim  agRoot = &(tdsaAllShared->agRootNonInt);
2616285242Sachim
2617285242Sachim  TI_DBG1(("tdsaDeregisterDevicesInPort: start\n"));
2618285242Sachim
2619285242Sachim  /* find a device's existence */
2620285242Sachim  DeviceListList = tdsaAllShared->MainDeviceList.flink;
2621285242Sachim  while (DeviceListList != &(tdsaAllShared->MainDeviceList))
2622285242Sachim  {
2623285242Sachim    oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
2624285242Sachim    if (oneDeviceData == agNULL)
2625285242Sachim    {
2626285242Sachim      TI_DBG1(("tdsaDeregisterDevicesInPort: oneDeviceData is NULL!!!\n"));
2627285242Sachim      return;
2628285242Sachim    }
2629285242Sachim    if (oneDeviceData->tdPortContext == onePortContext)
2630285242Sachim    {
2631285242Sachim      TI_DBG3(("tdsaDeregisterDevicesInPort: Found pid %d did %d\n", onePortContext->id, oneDeviceData->id));
2632285242Sachim      if ( !( DEVICE_IS_SMP_TARGET(oneDeviceData) && oneDeviceData->directlyAttached == agTRUE))
2633285242Sachim      {
2634285242Sachim        saDeregisterDeviceHandle(agRoot, agNULL, oneDeviceData->agDevHandle, tdsaRotateQnumber(tiRoot, oneDeviceData));
2635285242Sachim      }
2636285242Sachim      else
2637285242Sachim      {
2638285242Sachim        TI_DBG1(("tdsaDeregisterDevicesInPort: keeping\n"));
2639285242Sachim        oneDeviceData->registered = agTRUE;
2640285242Sachim      }
2641285242Sachim     }
2642285242Sachim    DeviceListList = DeviceListList->flink;
2643285242Sachim  }
2644285242Sachim
2645285242Sachim  TI_DBG3(("tdsaDeregisterDevicesInPort: end\n"));
2646285242Sachim
2647285242Sachim  return;
2648285242Sachim}
2649285242Sachim
2650285242Sachim/******************** for debugging only ***************************/
2651285242SachimosGLOBAL void
2652285242SachimtdsaPrintSwConfig(
2653285242Sachim                  agsaSwConfig_t *SwConfig
2654285242Sachim                  )
2655285242Sachim{
2656285242Sachim  if (SwConfig == agNULL)
2657285242Sachim  {
2658285242Sachim    TI_DBG6(("tdsaPrintSwConfig: SwConfig is NULL\n"));
2659285242Sachim    return;
2660285242Sachim  }
2661285242Sachim  else
2662285242Sachim  {
2663285242Sachim    TI_DBG6(("SwConfig->maxActiveIOs %d\n", SwConfig->maxActiveIOs));
2664285242Sachim    TI_DBG6(("SwConfig->smpReqTimeout %d\n", SwConfig->smpReqTimeout));
2665285242Sachim  }
2666285242Sachim
2667285242Sachim  return;
2668285242Sachim
2669285242Sachim}
2670285242Sachim
2671285242SachimosGLOBAL void
2672285242SachimtdsaPrintHwConfig(
2673285242Sachim                  agsaHwConfig_t *HwConfig
2674285242Sachim                  )
2675285242Sachim{
2676285242Sachim  if  (HwConfig == agNULL)
2677285242Sachim  {
2678285242Sachim    TI_DBG6(("tdsaPrintHwConfig: HwConfig is NULL\n"));
2679285242Sachim    return;
2680285242Sachim  }
2681285242Sachim  else
2682285242Sachim  {
2683285242Sachim    TI_DBG6(("HwConfig->phyCount %d\n", HwConfig->phyCount));
2684285242Sachim  }
2685285242Sachim  return;
2686285242Sachim}
2687285242Sachim
2688285242SachimosGLOBAL void
2689285242SachimtdssPrintSASIdentify(
2690285242Sachim                     agsaSASIdentify_t *id
2691285242Sachim                     )
2692285242Sachim{
2693285242Sachim  if  (id == agNULL)
2694285242Sachim  {
2695285242Sachim    TI_DBG1(("tdsaPrintSASIdentify: ID is NULL\n"));
2696285242Sachim    return;
2697285242Sachim  }
2698285242Sachim  else
2699285242Sachim  {
2700285242Sachim    TI_DBG6(("SASID->sspTargetPort %d\n", SA_IDFRM_IS_SSP_TARGET(id)?1:0));
2701285242Sachim    TI_DBG6(("SASID->stpTargetPort %d\n", SA_IDFRM_IS_STP_TARGET(id)?1:0));
2702285242Sachim    TI_DBG6(("SASID->smpTargetPort %d\n", SA_IDFRM_IS_SMP_TARGET(id)?1:0));
2703285242Sachim    TI_DBG6(("SASID->sspInitiatorPort %d\n", SA_IDFRM_IS_SSP_INITIATOR(id)?1:0));
2704285242Sachim    TI_DBG6(("SASID->stpInitiatorPort %d\n", SA_IDFRM_IS_STP_INITIATOR(id)?1:0));
2705285242Sachim    TI_DBG6(("SASID->smpInitiatorPort %d\n", SA_IDFRM_IS_SMP_INITIATOR(id)?1:0));
2706285242Sachim    TI_DBG6(("SASID->deviceType %d\n", SA_IDFRM_GET_DEVICETTYPE(id)));
2707285242Sachim    TI_DBG6(("SASID->sasAddressHi 0x%x\n", SA_IDFRM_GET_SAS_ADDRESSHI(id)));
2708285242Sachim    TI_DBG6(("SASID->sasAddressLo 0x%x\n", SA_IDFRM_GET_SAS_ADDRESSLO(id)));
2709285242Sachim    TI_DBG6(("SASID->phyIdentifier 0x%x\n", id->phyIdentifier));
2710285242Sachim
2711285242Sachim  }
2712285242Sachim
2713285242Sachim  return;
2714285242Sachim}
2715285242Sachim
2716285242SachimosGLOBAL void
2717285242SachimtdsaInitTimerHandler(
2718285242Sachim                     tiRoot_t  *tiRoot,
2719285242Sachim                     void      *timerData
2720285242Sachim                     )
2721285242Sachim{
2722285242Sachim
2723285242Sachim  TI_DBG6(("tdsaInitTimerHandler: start\n"));
2724285242Sachim  return;
2725285242Sachim}
2726285242Sachim
2727285242Sachim/*
2728285242Sachim  type: 1 portcontext 2 devicedata
2729285242Sachim  flag: 1 FreeLink 2 MainLink
2730285242Sachim*/
2731285242Sachim
2732285242SachimosGLOBAL void
2733285242Sachimprint_tdlist_flink(tdList_t *hdr, int type, int flag)
2734285242Sachim{
2735285242Sachim  tdList_t *hdr_tmp1 = NULL;
2736285242Sachim#ifdef  TD_DEBUG_ENABLE
2737285242Sachim  tdsaPortContext_t *ele1;
2738285242Sachim#endif
2739285242Sachim#ifdef REMOVED
2740285242Sachim  tdsaDeviceData_t *ele2;
2741285242Sachim#endif
2742285242Sachim  hdr_tmp1 = hdr;
2743285242Sachim
2744285242Sachim  if (type == 1 && flag == 1)
2745285242Sachim  {
2746285242Sachim    TI_DBG6(("PortContext and FreeLink\n"));
2747285242Sachim  }
2748285242Sachim  else if (type != 1 && flag == 1)
2749285242Sachim  {
2750285242Sachim    TI_DBG6(("DeviceData and FreeLink\n"));
2751285242Sachim  }
2752285242Sachim  else if (type == 1 && flag != 1)
2753285242Sachim  {
2754285242Sachim    TI_DBG6(("PortContext and MainLink\n"));
2755285242Sachim  }
2756285242Sachim  else
2757285242Sachim  {
2758285242Sachim    TI_DBG6(("DeviceData and MainLink\n"));
2759285242Sachim  }
2760285242Sachim  if (type == 1)
2761285242Sachim  {
2762285242Sachim    do
2763285242Sachim    {
2764285242Sachim      /* data structure type variable = (data structure type, file name, header of the tdList) */
2765285242Sachim      if (flag == 1)
2766285242Sachim      {
2767285242Sachim#ifdef  TD_DEBUG_ENABLE
2768285242Sachim        ele1 = TDLIST_OBJECT_BASE(tdsaPortContext_t, FreeLink, hdr_tmp1);
2769285242Sachim#endif
2770285242Sachim      }
2771285242Sachim      else
2772285242Sachim      {
2773285242Sachim#ifdef  TD_DEBUG_ENABLE
2774285242Sachim        ele1 = TDLIST_OBJECT_BASE(tdsaPortContext_t, MainLink, hdr_tmp1);
2775285242Sachim#endif
2776285242Sachim      }
2777285242Sachim      TI_DBG6(("flist ele %d\n", ele1->id));
2778285242Sachim      TI_DBG6(("flist ele %p\n", ele1));
2779285242Sachim      hdr_tmp1 = hdr_tmp1->flink;
2780285242Sachim    } while (hdr_tmp1 != hdr);
2781285242Sachim  }
2782285242Sachim  else
2783285242Sachim  {
2784285242Sachim    do
2785285242Sachim    {
2786285242Sachim      /* data structure type variable = (data structure type, file name, header of the tdList) */
2787285242Sachim#ifdef REMOVED
2788285242Sachim      if (flag == 1)
2789285242Sachim      {
2790285242Sachim        ele2 = TDLIST_OBJECT_BASE(tdsaDeviceData_t, FreeLink, hdr_tmp1);
2791285242Sachim      }
2792285242Sachim      else
2793285242Sachim      {
2794285242Sachim        ele2 = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, hdr_tmp1);
2795285242Sachim      }
2796285242Sachim      TI_DBG6(("flist ele %d\n", ele2->id));
2797285242Sachim      TI_DBG6(("flist ele %p\n", ele2));
2798285242Sachim#endif
2799285242Sachim      hdr_tmp1 = hdr_tmp1->flink;
2800285242Sachim    } while (hdr_tmp1 != hdr);
2801285242Sachim  }
2802285242Sachim  TI_DBG6(("\n"));
2803285242Sachim}
2804285242Sachim
2805285242Sachim/* not verified yet. 6/15/2005 */
2806285242SachimosGLOBAL void
2807285242Sachimprint_tdlist_blink(tdList_t *hdr, int flag)
2808285242Sachim{
2809285242Sachim  tdList_t *hdr_tmp1 = NULL;
2810285242Sachim#ifdef REMOVED
2811285242Sachim  tdsaPortContext_t *ele1;
2812285242Sachim#endif
2813285242Sachim  hdr_tmp1 = hdr;
2814285242Sachim
2815285242Sachim  do
2816285242Sachim  {
2817285242Sachim    /* data structure type variable = (data structure type, file name, header of the tdList) */
2818285242Sachim#ifdef REMOVED
2819285242Sachim    if (flag == 1)
2820285242Sachim    {
2821285242Sachim      ele1 = TDLIST_OBJECT_BASE(tdsaPortContext_t, FreeLink, hdr_tmp1);
2822285242Sachim    }
2823285242Sachim    else
2824285242Sachim    {
2825285242Sachim      ele1 = TDLIST_OBJECT_BASE(tdsaPortContext_t, MainLink, hdr_tmp1);
2826285242Sachim    }
2827285242Sachim    TI_DBG6(("blist ele %d\n", ele1->id));
2828285242Sachim#endif
2829285242Sachim
2830285242Sachim    hdr_tmp1 = hdr_tmp1->blink;
2831285242Sachim  } while (hdr_tmp1 != hdr);
2832285242Sachim}
2833285242Sachim
2834285242Sachim
2835285242Sachim/** hexidecimal dump */
2836285242Sachimvoid tdhexdump(const char *ptitle, bit8 *pbuf, int len)
2837285242Sachim{
2838285242Sachim  int i;
2839285242Sachim  TI_DBG2(("%s - hexdump(len=%d):\n", ptitle, (int)len));
2840285242Sachim  if (!pbuf)
2841285242Sachim  {
2842285242Sachim    TI_DBG1(("pbuf is NULL\n"));
2843285242Sachim    return;
2844285242Sachim  }
2845285242Sachim  for (i = 0; i < len; )
2846285242Sachim  {
2847285242Sachim    if (len - i > 4)
2848285242Sachim    {
2849285242Sachim      TI_DBG2((" 0x%02x, 0x%02x, 0x%02x, 0x%02x,\n", pbuf[i], pbuf[i+1], pbuf[i+2], pbuf[i+3]));
2850285242Sachim      i += 4;
2851285242Sachim    }
2852285242Sachim    else
2853285242Sachim    {
2854285242Sachim      TI_DBG2((" 0x%02x,", pbuf[i]));
2855285242Sachim      i++;
2856285242Sachim    }
2857285242Sachim  }
2858285242Sachim  TI_DBG2(("\n"));
2859285242Sachim}
2860285242Sachim
2861285242Sachimvoid
2862285242SachimtdsaSingleThreadedEnter(tiRoot_t *ptiRoot, bit32 queueId)
2863285242Sachim{
2864285242Sachim  tdsaRoot_t * tiroot = agNULL;
2865285242Sachim  bit32 offset = 0;
2866285242Sachim  TD_ASSERT(ptiRoot,"ptiRoot");
2867285242Sachim  tiroot = ptiRoot->tdData;
2868285242Sachim
2869285242Sachim  offset = tiroot->tdsaAllShared.MaxNumLLLocks + tiroot->tdsaAllShared.MaxNumOSLocks;
2870285242Sachim
2871285242Sachim  ostiSingleThreadedEnter(ptiRoot, queueId + offset);
2872285242Sachim}
2873285242Sachim
2874285242Sachimvoid
2875285242SachimtdsaSingleThreadedLeave(tiRoot_t *ptiRoot, bit32 queueId)
2876285242Sachim{
2877285242Sachim  tdsaRoot_t * tiroot = agNULL;
2878285242Sachim  bit32 offset = 0;
2879285242Sachim
2880285242Sachim  TD_ASSERT(ptiRoot,"ptiRoot");
2881285242Sachim  tiroot = ptiRoot->tdData;
2882285242Sachim
2883285242Sachim  offset = tiroot->tdsaAllShared.MaxNumLLLocks + tiroot->tdsaAllShared.MaxNumOSLocks;
2884285242Sachim
2885285242Sachim  ostiSingleThreadedLeave(ptiRoot, queueId + offset);
2886285242Sachim}
2887285242Sachim
2888285242Sachim#ifdef PERF_COUNT
2889285242Sachimvoid
2890285242SachimtdsaEnter(tiRoot_t *ptiRoot, int io)
2891285242Sachim{
2892285242Sachim  ostiEnter(ptiRoot, 1, io);
2893285242Sachim}
2894285242Sachim
2895285242Sachimvoid
2896285242SachimtdsaLeave(tiRoot_t *ptiRoot, int io)
2897285242Sachim{
2898285242Sachim  ostiLeave(ptiRoot, 1, io);
2899285242Sachim}
2900285242Sachim#endif
2901285242Sachim
2902