1285809Sscottl/*******************************************************************************
2285809Sscottl*Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3285809Sscottl*
4285809Sscottl*Redistribution and use in source and binary forms, with or without modification, are permitted provided
5285809Sscottl*that the following conditions are met:
6285809Sscottl*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7285809Sscottl*following disclaimer.
8285809Sscottl*2. Redistributions in binary form must reproduce the above copyright notice,
9285809Sscottl*this list of conditions and the following disclaimer in the documentation and/or other materials provided
10285809Sscottl*with the distribution.
11285809Sscottl*
12285809Sscottl*THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13285809Sscottl*WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14285809Sscottl*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15285809Sscottl*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16285809Sscottl*NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17285809Sscottl*BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18285809Sscottl*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19285809Sscottl*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20285809Sscottl
21285809Sscottl********************************************************************************/
22285809Sscottl/*******************************************************************************/
23285809Sscottl/** \file
24285809Sscottl *
25285809Sscottl *
26285809Sscottl * This file contains Management IOCTL APIs
27285809Sscottl *
28285809Sscottl */
29285809Sscottl#include <sys/cdefs.h>
30285809Sscottl__FBSDID("$FreeBSD$");
31285809Sscottl#include <dev/pms/config.h>
32285809Sscottl
33285809Sscottl#include <dev/pms/freebsd/driver/common/osenv.h>
34285809Sscottl#include <dev/pms/freebsd/driver/common/ostypes.h>
35285809Sscottl#include <dev/pms/freebsd/driver/common/osdebug.h>
36285809Sscottl
37285809Sscottl#include <dev/pms/RefTisa/sallsdk/api/sa.h>
38285809Sscottl#include <dev/pms/RefTisa/sallsdk/api/saapi.h>
39285809Sscottl#include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
40285809Sscottl
41285809Sscottl#include <dev/pms/RefTisa/tisa/api/titypes.h>
42285809Sscottl#include <dev/pms/RefTisa/tisa/api/ostiapi.h>
43285809Sscottl#include <dev/pms/RefTisa/tisa/api/tiapi.h>
44285809Sscottl#include <dev/pms/RefTisa/tisa/api/tiglobal.h>
45285809Sscottl
46285809Sscottl#ifdef FDS_SM
47285809Sscottl#include <dev/pms/RefTisa/sat/api/sm.h>
48285809Sscottl#include <dev/pms/RefTisa/sat/api/smapi.h>
49285809Sscottl#include <dev/pms/RefTisa/sat/api/tdsmapi.h>
50285809Sscottl#endif
51285809Sscottl
52285809Sscottl#ifdef FDS_DM
53285809Sscottl#include <dev/pms/RefTisa/discovery/api/dm.h>
54285809Sscottl#include <dev/pms/RefTisa/discovery/api/dmapi.h>
55285809Sscottl#include <dev/pms/RefTisa/discovery/api/tddmapi.h>
56285809Sscottl#endif
57285809Sscottl
58285809Sscottl#include <dev/pms/RefTisa/tisa/sassata/sas/common/tdtypes.h>
59285809Sscottl#include <dev/pms/freebsd/driver/common/osstring.h>
60285809Sscottl#include <dev/pms/RefTisa/tisa/sassata/common/tdutil.h>
61285809Sscottl#include <dev/pms/RefTisa/sallsdk/spc/mpidebug.h>
62285809Sscottl
63285809Sscottl#ifdef INITIATOR_DRIVER
64285809Sscottl#include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdtypes.h>
65285809Sscottl#include <dev/pms/RefTisa/tisa/sassata/sas/ini/itddefs.h>
66285809Sscottl#include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdglobl.h>
67285809Sscottl#endif
68285809Sscottl
69285809Sscottl#ifdef TARGET_DRIVER
70285809Sscottl#include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdglobl.h>
71285809Sscottl#include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdxchg.h>
72285809Sscottl#include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdtypes.h>
73285809Sscottl#endif
74285809Sscottl
75285809Sscottl#include <dev/pms/RefTisa/tisa/sassata/common/tdsatypes.h>
76285809Sscottl#include <dev/pms/RefTisa/tisa/sassata/common/tdproto.h>
77285809Sscottl#include <dev/pms/RefTisa/tisa/sassata/common/tdioctl.h>
78285809Sscottl
79285809Sscottl#include <dev/pms/RefTisa/sallsdk/spc/sadefs.h>
80285809Sscottl#include <dev/pms/RefTisa/sallsdk/spc/spcdefs.h>
81285809Sscottl#include <dev/pms/RefTisa/sallsdk/spc/mpi.h>
82285809Sscottl#include <dev/pms/RefTisa/sallsdk/spc/sallist.h>
83285809Sscottl#include <dev/pms/RefTisa/sallsdk/spc/satypes.h>
84285809Sscottl
85285809Sscottl
86285809Sscottl#define agFieldOffset(baseType,fieldName) \
87285809Sscottl            /*lint -e545 */ \
88285809Sscottl            ((bit32)((bitptr)(&(((baseType *)0)->fieldName)))) \
89285809Sscottl
90285809Sscottl#ifdef SA_LL_API_TEST
91285809SscottlosGLOBAL bit32 tdLlApiTestIoctl(tiRoot_t *tiRoot,
92285809Sscottl                                tiIOCTLPayload_t *agIOCTLPayload,
93285809Sscottl                                void *agParam1,
94285809Sscottl                                void *agParam2,
95285809Sscottl                                void *agParam3);
96285809Sscottl#endif /* SA_LL_API_TEST */
97285809Sscottl
98285809Sscottl
99285809Sscottlextern bit32 volatile sgpioResponseSet;
100285809Sscottl
101285809Sscottl#ifdef SPC_ENABLE_PROFILE
102285809Sscottl/*****************************************************************************
103285809Sscottl*
104285809Sscottl* tdipFWProfileIoctl
105285809Sscottl*
106285809Sscottl* Purpose:  This routine is called to process the FW Profile IOCTL function.
107285809Sscottl*           This function is used for both target and initiator.
108285809Sscottl*
109285809Sscottl* Parameters:
110285809Sscottl*   tiRoot:         Pointer to driver instance
111285809Sscottl*   agIOCTLPayload: Pointer to the IOCTL payload.
112285809Sscottl*   agParam1:       Pointer to pass context handle for IOCTL DMA operation
113285809Sscottl*   agParam2:       Pointer to pass context handle for IOCTL DMA operation
114285809Sscottl*   agParam3:       Pointer to pass context handle for IOCTL DMA operation
115285809Sscottl*
116285809Sscottl* Return:
117285809Sscottl*
118285809Sscottl*   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
119285809Sscottl*   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
120285809Sscottl*                             Detail error code is function specific and
121285809Sscottl*                             defined by the specific IOCTL function.
122285809Sscottl*   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
123285809Sscottl*
124285809Sscottl*
125285809Sscottl*****************************************************************************/
126285809SscottlosGLOBAL bit32 tdipFWProfileIoctl(
127285809Sscottl                        tiRoot_t            *tiRoot,
128285809Sscottl                        tiIOCTLPayload_t    *agIOCTLPayload,
129285809Sscottl                        void                *agParam1,
130285809Sscottl                        void                *agParam2,
131285809Sscottl                        void                *agParam3
132285809Sscottl                        )
133285809Sscottl{
134285809Sscottl
135285809Sscottl  bit32                status = IOCTL_CALL_SUCCESS;
136285809Sscottl  bit32                bufAddrUpper = 0;
137285809Sscottl  bit32                bufAddrLower = 0;
138285809Sscottl  tdFWProfile_t        *fwProfile;
139285809Sscottl
140285809Sscottl  void                 *osMemHandle = agNULL;
141285809Sscottl  void                 *buffer = agNULL;
142285809Sscottl  agsaFwProfile_t     fwProfileInfo = {0};
143285809Sscottl
144285809Sscottl  tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
145285809Sscottl  tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
146285809Sscottl  agsaRoot_t           *agRoot = &tdsaAllShared->agRootInt;
147285809Sscottl
148285809Sscottl  fwProfile = (tdFWProfile_t *)&agIOCTLPayload->FunctionSpecificArea[0];
149285809Sscottl
150285809Sscottl
151285809Sscottl  fwProfileInfo.processor = fwProfile->processor;
152285809Sscottl  fwProfileInfo.cmd = fwProfile->cmd;
153285809Sscottl  fwProfileInfo.len = fwProfile->len;
154285809Sscottl  fwProfileInfo.tcid = fwProfile->tcid;
155285809Sscottl  if(fwProfile->cmd == START_CODE_PROFILE)
156285809Sscottl  {
157285809Sscottl    fwProfileInfo.codeStartAdd = fwProfile->codeStartAdd;
158285809Sscottl      fwProfileInfo.codeEndAdd = fwProfile->codeEndAdd;
159285809Sscottl  }
160285809Sscottl  if((fwProfile->cmd == STOP_TIMER_PROFILE) || (fwProfile->cmd == STOP_CODE_PROFILE))
161285809Sscottl  {
162285809Sscottl    if(fwProfile->len != 0)
163285809Sscottl    {
164285809Sscottl      if(ostiAllocMemory( tiRoot,
165285809Sscottl              &osMemHandle,
166285809Sscottl              (void **)&buffer,
167285809Sscottl              &bufAddrUpper,
168285809Sscottl              &bufAddrLower,
169285809Sscottl              8,
170285809Sscottl              fwProfile->len,
171285809Sscottl              agFALSE))
172285809Sscottl        {
173285809Sscottl          return IOCTL_CALL_FAIL;
174285809Sscottl        }
175285809Sscottl      osti_memset((void *)buffer, 0, fwProfile->len);
176285809Sscottl    }
177285809Sscottl    fwProfileInfo.agSgl.sgLower = bufAddrLower;
178285809Sscottl    fwProfileInfo.agSgl.sgUpper = bufAddrUpper;
179285809Sscottl    fwProfileInfo.agSgl.len = fwProfile->len;
180285809Sscottl    fwProfileInfo.agSgl.extReserved = 0;
181285809Sscottl    tdsaAllShared->tdFWProfileEx.buffer = osMemHandle;
182285809Sscottl    tdsaAllShared->tdFWProfileEx.virtAddr = buffer;
183285809Sscottl    tdsaAllShared->tdFWProfileEx.len = fwProfile->len;
184285809Sscottl  }
185285809Sscottl  tdsaAllShared->tdFWProfileEx.tdFWProfile = fwProfile;
186285809Sscottl  tdsaAllShared->tdFWProfileEx.param1 = agParam1;
187285809Sscottl  tdsaAllShared->tdFWProfileEx.param2 = agParam2;
188285809Sscottl  tdsaAllShared->tdFWProfileEx.payload = agIOCTLPayload;
189285809Sscottl  tdsaAllShared->tdFWProfileEx.inProgress = 1;
190285809Sscottl  status = saFwProfile(agRoot,
191285809Sscottl            agNULL,
192285809Sscottl            0,
193285809Sscottl            &fwProfileInfo
194285809Sscottl            );
195285809Sscottl  if(status)
196285809Sscottl  {
197285809Sscottl    if((fwProfile->cmd == STOP_TIMER_PROFILE) || (fwProfile->cmd == STOP_CODE_PROFILE))
198285809Sscottl      ostiFreeMemory(tiRoot, osMemHandle, fwProfile->len);
199285809Sscottl    status = IOCTL_CALL_FAIL;
200285809Sscottl  }
201285809Sscottl  else
202285809Sscottl    status = IOCTL_CALL_PENDING;
203285809Sscottl  return status;
204285809Sscottl}
205285809Sscottl
206285809Sscottl
207285809Sscottl#endif
208285809Sscottl
209285809Sscottl/*****************************************************************************
210285809Sscottl*
211285809Sscottl* tdipFWControlIoctl
212285809Sscottl*
213285809Sscottl* Purpose:  This routine is called to process the FW control IOCTL function.
214285809Sscottl*           This function is used for both target and initiator.
215285809Sscottl*
216285809Sscottl* Parameters:
217285809Sscottl*   tiRoot:         Pointer to driver instance
218285809Sscottl*   agIOCTLPayload: Pointer to the IOCTL payload.
219285809Sscottl*   agParam1:       Pointer to pass context handle for IOCTL DMA operation
220285809Sscottl*   agParam2:       Pointer to pass context handle for IOCTL DMA operation
221285809Sscottl*   agParam3:       Pointer to pass context handle for IOCTL DMA operation
222285809Sscottl*
223285809Sscottl* Return:
224285809Sscottl*
225285809Sscottl*   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
226285809Sscottl*   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
227285809Sscottl*                             Detail error code is function specific and
228285809Sscottl*                             defined by the specific IOCTL function.
229285809Sscottl*   IOCTL_CALL_PENDING        This request is asynchronous and completed
230285809Sscottl*                             in some other context.
231285809Sscottl*   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
232285809Sscottl*
233285809Sscottl*
234285809Sscottl*****************************************************************************/
235285809SscottlosGLOBAL bit32 tdipFWControlIoctl(
236285809Sscottl  tiRoot_t            *tiRoot,
237285809Sscottl  tiIOCTLPayload_t    *agIOCTLPayload,
238285809Sscottl  void                *agParam1,
239285809Sscottl  void                *agParam2,
240285809Sscottl  void                *agParam3
241285809Sscottl  ) {
242285809Sscottl
243285809Sscottl  bit32               status = IOCTL_CALL_PENDING;
244285809Sscottl  bit32               bufAddrUpper = 0;
245285809Sscottl  bit32               bufAddrLower = 0;
246285809Sscottl  tdFWControl_t      *fwControl;
247285809Sscottl  void               *osMemHandle = agNULL;
248285809Sscottl  void               *buffer = agNULL;
249285809Sscottl  agsaUpdateFwFlash_t flashUpdateInfo;
250285809Sscottl  tdsaRoot_t         *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
251285809Sscottl  tdsaContext_t      *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
252285809Sscottl  agsaRoot_t         *agRoot = &tdsaAllShared->agRootInt;
253285809Sscottl
254285809Sscottl  if( agIOCTLPayload->Length <
255285809Sscottl      ( agFieldOffset(tiIOCTLPayload_t, FunctionSpecificArea) +
256285809Sscottl        sizeof(tdFWControl_t) ) )  {
257285809Sscottl    agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
258285809Sscottl    status = IOCTL_CALL_FAIL;
259285809Sscottl    return status;
260285809Sscottl  }
261285809Sscottl  fwControl = (tdFWControl_t *)&agIOCTLPayload->FunctionSpecificArea[0];
262285809Sscottl
263285809Sscottl  if(fwControl->len != 0)
264285809Sscottl  {
265285809Sscottl    if(ostiAllocMemory( tiRoot,
266285809Sscottl                        &osMemHandle,
267285809Sscottl                        (void **)&buffer,
268285809Sscottl                        &bufAddrUpper,
269285809Sscottl                        &bufAddrLower,
270285809Sscottl                        8,
271285809Sscottl                        fwControl->len,
272285809Sscottl                        agFALSE) )
273285809Sscottl      return IOCTL_CALL_FAIL;
274285809Sscottl  }
275285809Sscottl  osti_memset( (void *)buffer, 0, fwControl->len );
276285809Sscottl  osti_memcpy( (void *)buffer,
277285809Sscottl               fwControl->buffer,
278285809Sscottl               fwControl->len );
279285809Sscottl  flashUpdateInfo.agSgl.sgLower = bufAddrLower;
280285809Sscottl  flashUpdateInfo.agSgl.sgUpper = bufAddrUpper;
281285809Sscottl  flashUpdateInfo.agSgl.len     = fwControl->len;
282285809Sscottl  flashUpdateInfo.agSgl.extReserved  = 0;
283285809Sscottl  flashUpdateInfo.currentImageOffset = fwControl->offset;
284285809Sscottl  flashUpdateInfo.currentImageLen    = fwControl->len;
285285809Sscottl  flashUpdateInfo.totalImageLen      = fwControl->size;
286285809Sscottl  switch (agIOCTLPayload->MinorFunction)
287285809Sscottl  {
288285809Sscottl    case IOCTL_MN_FW_DOWNLOAD_DATA:
289285809Sscottl    {
290285809Sscottl      TI_DBG6(("tdipFWControlIoctl: calling saFwFlashUpdate\n"));
291285809Sscottl      tdsaAllShared->tdFWControlEx.tdFWControl = fwControl;
292285809Sscottl      tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
293285809Sscottl      tdsaAllShared->tdFWControlEx.param1 = agParam1;
294285809Sscottl      tdsaAllShared->tdFWControlEx.param2 = agParam2;
295285809Sscottl      tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
296285809Sscottl      tdsaAllShared->tdFWControlEx.inProgress = 1;
297285809Sscottl      status = saFwFlashUpdate( agRoot,
298285809Sscottl                                agNULL,
299285809Sscottl                                0,
300285809Sscottl                                &flashUpdateInfo );
301285809Sscottl      if(status) {
302285809Sscottl        status = IOCTL_CALL_FAIL;
303285809Sscottl        fwControl->retcode = IOCTL_CALL_TIMEOUT;
304285809Sscottl      }
305285809Sscottl      else {
306285809Sscottl        status = IOCTL_CALL_PENDING;
307285809Sscottl      }
308285809Sscottl      break;
309285809Sscottl    }
310285809Sscottl    default:
311285809Sscottl      status = IOCTL_CALL_INVALID_CODE;
312285809Sscottl      TI_DBG1( ("tdipFWControlIoctl: ERROR: Wrong IOCTL code %d\n",
313285809Sscottl                agIOCTLPayload->MinorFunction) );
314285809Sscottl      ostiFreeMemory(tiRoot, osMemHandle, fwControl->len);
315285809Sscottl      return status;
316285809Sscottl  } /* end IOCTL switch */
317285809Sscottl  return status;
318285809Sscottl} /* tdipFWControlIoctl */
319285809Sscottl
320285809Sscottl
321285809Sscottl/*****************************************************************************
322285809Sscottl*
323285809Sscottl* tiCOMMgntIOCTL
324285809Sscottl*
325285809Sscottl* Purpose:  This routine is a TISA API for processing the PMC specific
326285809Sscottl*           IOCTL function.
327285809Sscottl*
328285809Sscottl*           Each IOCTL function is identified by the IOCTL header
329285809Sscottl*           specified in the data payload as the following:
330285809Sscottl*           Field                 Description
331285809Sscottl*           -----                 -----------
332285809Sscottl*           Signature             PMC IOCTL signature.
333285809Sscottl*                                 #define PMC_IOCTL_SIGNATURE   0x1234
334285809Sscottl*           MajorFunction         Major function number.
335285809Sscottl*           MinorFunction         Minor function number.
336285809Sscottl*           Length                Length of this structure in bytes.
337285809Sscottl*           Status                Return status for this IOCTL function.
338285809Sscottl*           FunctionSpecificArea  Variable length function specific area.
339285809Sscottl*
340285809Sscottl* Parameters:
341285809Sscottl*   tiRoot:         Pointer to driver instance
342285809Sscottl*   agIOCTLPayload: Pointer to the IOCTL payload.
343285809Sscottl*   agParam1:       Pointer to pass context handle for IOCTL DMA operation
344285809Sscottl*   agParam2:       Pointer to pass context handle for IOCTL DMA operation
345285809Sscottl*   agParam3:       Pointer to pass context handle for IOCTL DMA operation
346285809Sscottl*
347285809Sscottl* Return:
348285809Sscottl*
349285809Sscottl*   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
350285809Sscottl*   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
351285809Sscottl*                             Detail error code is function specific and
352285809Sscottl*                             defined by the specific IOCTL function.
353285809Sscottl*   IOCTL_CALL_PENDING        This request is asynchronous and completed
354285809Sscottl*                             in some other context.
355285809Sscottl*   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
356285809Sscottl*   IOCTL_CALL_INVALID_DEVICE Invalid target or destination device.
357285809Sscottl*
358285809Sscottl* Note:
359285809Sscottl*  Used ostiAllocMemory() OS layer callback function to allocate memory
360285809Sscottl*  for DMA operaion. Then use ostiFreeMemory() to deallocate the memory.
361285809Sscottl*
362285809Sscottl*****************************************************************************/
363285809SscottlosGLOBAL bit32
364285809SscottltiCOMMgntIOCTL(
365285809Sscottl               tiRoot_t            *tiRoot,
366285809Sscottl               tiIOCTLPayload_t    *agIOCTLPayload,
367285809Sscottl               void                *agParam1,
368285809Sscottl               void                *agParam2,
369285809Sscottl               void                *agParam3
370285809Sscottl               )
371285809Sscottl{
372285809Sscottl  bit32                     status = IOCTL_CALL_INVALID_CODE;
373285809Sscottl  tdsaRoot_t                *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
374285809Sscottl  tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
375285809Sscottl  agsaRoot_t                *agRoot = &(tdsaAllShared->agRootNonInt);
376285809Sscottl  bit32                     EventLogLength = 0;
377285809Sscottl  bit32                     EventLogOption;
378285809Sscottl  bit32                     ReadLength = 0;
379285809Sscottl  bit32                     Offset = 0;
380285809Sscottl  bit32                     RequestLength = 0;  /* user request on how much data to pass to application */
381285809Sscottl  agsaContext_t		    *agContext = NULL;
382285809Sscottl  bit8                      *loc = 0;
383285809Sscottl
384285809Sscottl  TI_DBG3(("tiCOMMgntIOCTL: start\n"));
385285809Sscottl
386285809Sscottl  TI_DBG3(("tiCOMMgntIOCTL: tiRoot %p agIOCTLPayload %p agParam1 %p agParam2 %p agParam3 %p\n",
387285809Sscottl                            tiRoot,agIOCTLPayload,agParam1,agParam2,agParam3 ));
388285809Sscottl
389285809Sscottl  TI_DBG3(("tiCOMMgntIOCTL: Signature %X\ntiCOMMgntIOCTL: MajorFunction 0x%X\ntiCOMMgntIOCTL: MinorFunction 0x%X\ntiCOMMgntIOCTL: Length 0x%X\ntiCOMMgntIOCTL: Status 0x%X\ntiCOMMgntIOCTL: Reserved 0x%X\ntiCOMMgntIOCTL: FunctionSpecificArea 0x%X\n",
390285809Sscottl                           agIOCTLPayload->Signature,
391285809Sscottl                           agIOCTLPayload->MajorFunction,
392285809Sscottl                           agIOCTLPayload->MinorFunction,
393285809Sscottl                           agIOCTLPayload->Length,
394285809Sscottl                           agIOCTLPayload->Status,
395285809Sscottl                           agIOCTLPayload->Reserved,
396285809Sscottl                           agIOCTLPayload->FunctionSpecificArea[0] ));
397285809Sscottl
398285809Sscottl  /* PMC IOCTL signatures matched ? */
399285809Sscottl  if(agIOCTLPayload->Signature != PMC_IOCTL_SIGNATURE)
400285809Sscottl  {
401285809Sscottl    TI_DBG1(("tiCOMMgntIOCTL:agIOCTLPayload->Signature %x IOCTL_CALL_INVALID_CODE\n",agIOCTLPayload->Signature ));
402285809Sscottl    status = IOCTL_CALL_INVALID_CODE;
403285809Sscottl    return (status);
404285809Sscottl  }
405285809Sscottl
406285809Sscottl  switch (agIOCTLPayload->MajorFunction)
407285809Sscottl  {
408285809Sscottl//TODO: make the card identification more robust. For now - just to keep going with FW download
409285809Sscottl#ifdef IOCTL_INTERRUPT_TIME_CONFIG
410285809Sscottl  case IOCTL_MJ_CARD_PARAMETER:
411285809Sscottl  {
412285809Sscottl    switch( agIOCTLPayload->MinorFunction )
413285809Sscottl    {
414285809Sscottl      case  IOCTL_MN_CARD_GET_INTERRUPT_CONFIG:
415285809Sscottl      {
416285809Sscottl          agsaInterruptConfigPage_t *pInterruptConfig = (agsaInterruptConfigPage_t *)&agIOCTLPayload->FunctionSpecificArea[0];
417285809Sscottl          status = saGetControllerConfig(agRoot,
418285809Sscottl                                0,
419285809Sscottl                                AGSA_INTERRUPT_CONFIGURATION_PAGE,
420285809Sscottl                                pInterruptConfig->vectorMask0,
421285809Sscottl                                pInterruptConfig->vectorMask1,
422285809Sscottl                                agParam2);
423285809Sscottl          if(status == AGSA_RC_SUCCESS) {
424285809Sscottl              status = IOCTL_CALL_PENDING;
425285809Sscottl              agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
426285809Sscottl          } else {
427285809Sscottl              agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
428285809Sscottl          }
429285809Sscottl          break;
430285809Sscottl      }
431285809Sscottl      case  IOCTL_MN_CARD_GET_TIMER_CONFIG:
432285809Sscottl          status = saGetControllerConfig(agRoot, 0, AGSA_SAS_PROTOCOL_TIMER_CONFIG_PAGE, 0, 0, agParam2);
433285809Sscottl          if(status == AGSA_RC_SUCCESS) {
434285809Sscottl              status = IOCTL_CALL_PENDING;
435285809Sscottl              agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
436285809Sscottl          } else {
437285809Sscottl              agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
438285809Sscottl          }
439285809Sscottl          break;
440285809Sscottl    }
441285809Sscottl    break;
442285809Sscottl  }
443285809Sscottl#endif /* IOCTL_INTERRUPT_TIME_CONFIG */
444285809Sscottl  case IOCTL_MJ_INI_DRIVER_IDENTIFY:
445285809Sscottl  {
446285809Sscottl    status=IOCTL_CALL_SUCCESS;
447285809Sscottl    break;
448285809Sscottl  }
449285809Sscottl  case IOCTL_MJ_GET_DEVICE_LUN:
450285809Sscottl		status = tdsaGetNumOfLUNIOCTL(tiRoot,agIOCTLPayload, agParam1, agParam2, agParam3);
451285809Sscottl    	if(status == IOCTL_CALL_SUCCESS)
452285809Sscottl        {
453285809Sscottl    	  status = IOCTL_CALL_PENDING;
454285809Sscottl    	}
455285809Sscottl   break;
456285809Sscottlcase IOCTL_MJ_SMP_REQUEST:
457285809Sscottl	status = tdsaSendSMPIoctl(tiRoot, agIOCTLPayload,
458285809Sscottl             	agParam1,agParam2,agParam3);
459285809Sscottl	break;
460285809Sscottl
461285809Sscottl  case IOCTL_MJ_FW_CONTROL:
462285809Sscottl  {
463285809Sscottl    //ostiIOCTLClearSignal (tiRoot, &agParam1, &agParam2, &agParam3);
464285809Sscottl    status = tdipFWControlIoctl( tiRoot, agIOCTLPayload,
465285809Sscottl                                   agParam1, agParam2, agParam3);
466285809Sscottl
467285809Sscottl    break;
468285809Sscottl  }
469285809Sscottl//#ifdef EVENT_LOG_INFO_TESTING
470285809Sscottl  /* Reserved field in tiIOCTLPayload_t is used as offset */
471285809Sscottl  case IOCTL_MJ_GET_EVENT_LOG1:
472285809Sscottl  {
473285809Sscottl    switch (agIOCTLPayload->MinorFunction)
474285809Sscottl    {
475285809Sscottl      case IOCTL_MN_FW_GET_TRACE_BUFFER:
476285809Sscottl      {
477285809Sscottl        agsaControllerEventLog_t EventLog;
478285809Sscottl        saGetControllerEventLogInfo(agRoot, &EventLog);
479285809Sscottl        TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MJ_GET_EVENT_LOG1 Length %d\n", agIOCTLPayload->Length));
480285809Sscottl        RequestLength = agIOCTLPayload->Length;
481285809Sscottl        Offset = agIOCTLPayload->Reserved;
482285809Sscottl        EventLogLength = EventLog.eventLog1.totalLength;
483285809Sscottl        EventLogOption = EventLog.eventLog1Option;
484285809Sscottl        if (EventLogLength <= Offset)
485285809Sscottl        {
486285809Sscottl          TI_DBG1(("tiCOMMgntIOCTL: 1 out of range Requestlength %d Offset %d event log length %d\n", RequestLength, Offset, EventLogLength));
487285809Sscottl          // out of range
488285809Sscottl          agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
489285809Sscottl          agIOCTLPayload->Length = 0;
490285809Sscottl          if(EventLogOption == 0)
491285809Sscottl          {
492285809Sscottl            agIOCTLPayload->Status = IOCTL_ERR_FW_EVENTLOG_DISABLED;
493285809Sscottl          }
494285809Sscottl          status=IOCTL_CALL_SUCCESS;
495285809Sscottl          return status;
496285809Sscottl         }
497285809Sscottl        ReadLength = MIN(EventLogLength - Offset, RequestLength);
498285809Sscottl        loc = (bit8 *)EventLog.eventLog1.virtPtr + Offset;
499285809Sscottl        osti_memcpy(&(agIOCTLPayload->FunctionSpecificArea), loc, ReadLength);
500285809Sscottl      //   tdhexdump("IOCTL_MJ_GET_EVENT_LOG1 first 32bytes", (bit8 *)&(agIOCTLPayload->FunctionSpecificArea), 32);
501285809Sscottl        agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
502285809Sscottl        agIOCTLPayload->Length = (bit16)ReadLength;
503285809Sscottl        status=IOCTL_CALL_SUCCESS;
504285809Sscottl        break;
505285809Sscottl     }
506285809Sscottl     case IOCTL_MN_FW_GET_EVENT_FLASH_LOG1:
507285809Sscottl     {
508285809Sscottl       TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MN_FW_GET_EVENT_FLASH_LOG1\n"));
509285809Sscottl       status = tdsaRegDumpGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
510285809Sscottl       break;
511285809Sscottl     }
512285809Sscottl   }
513285809Sscottl   break;
514285809Sscottl  }
515285809Sscottl
516285809Sscottl  case IOCTL_MJ_GET_EVENT_LOG2:
517285809Sscottl  {
518285809Sscottl    switch (agIOCTLPayload->MinorFunction)
519285809Sscottl    {
520285809Sscottl      case IOCTL_MN_FW_GET_TRACE_BUFFER:
521285809Sscottl      {
522285809Sscottl        agsaControllerEventLog_t EventLog;
523285809Sscottl        saGetControllerEventLogInfo(agRoot, &EventLog);
524285809Sscottl        TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MJ_GET_EVENT_LOG2 Length %d\n", agIOCTLPayload->Length));
525285809Sscottl        RequestLength = agIOCTLPayload->Length;
526285809Sscottl        Offset = agIOCTLPayload->Reserved;
527285809Sscottl        EventLogLength = EventLog.eventLog2.totalLength;
528285809Sscottl        EventLogOption = EventLog.eventLog2Option;
529285809Sscottl        if (EventLogLength <= Offset)
530285809Sscottl        {
531285809Sscottl          TI_DBG1(("tiCOMMgntIOCTL: 2 out of range Requestlength %d Offset %d event log length %d\n", RequestLength, Offset, EventLogLength));
532285809Sscottl          /* out of range */
533285809Sscottl          agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
534285809Sscottl          agIOCTLPayload->Length = 0;
535285809Sscottl          if(EventLogOption == 0)
536285809Sscottl          {
537285809Sscottl            agIOCTLPayload->Status = IOCTL_ERR_FW_EVENTLOG_DISABLED;
538285809Sscottl          }
539285809Sscottl          status=IOCTL_CALL_SUCCESS;
540285809Sscottl          return status;
541285809Sscottl        }
542285809Sscottl        ReadLength = MIN(EventLogLength - Offset, RequestLength);
543285809Sscottl        loc = (bit8 *)EventLog.eventLog2.virtPtr + Offset;
544285809Sscottl        osti_memcpy(&(agIOCTLPayload->FunctionSpecificArea), loc, ReadLength);
545285809Sscottl    //    tdhexdump("IOCTL_MJ_GET_EVENT_LOG2 first 32bytes", (bit8 *)&(agIOCTLPayload->FunctionSpecificArea), 32);
546285809Sscottl        agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
547285809Sscottl        agIOCTLPayload->Length = (bit16)ReadLength;
548285809Sscottl        status=IOCTL_CALL_SUCCESS;
549285809Sscottl        break;
550285809Sscottl      }
551285809Sscottl      case IOCTL_MN_FW_GET_EVENT_FLASH_LOG2:
552285809Sscottl      {
553285809Sscottl        TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MN_FW_GET_EVENT_FLASH_LOG2\n"));
554285809Sscottl        status = tdsaRegDumpGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
555285809Sscottl        break;
556285809Sscottl      }
557285809Sscottl    }
558285809Sscottl    break;
559285809Sscottl  }
560285809Sscottl
561285809Sscottl
562285809Sscottl  case IOCTL_MJ_FW_INFO:
563285809Sscottl  {
564285809Sscottl    agsaControllerInfo_t ControllerInfo;
565285809Sscottl    saGetControllerInfo(agRoot, &ControllerInfo);
566285809Sscottl    TI_DBG1(("tiCOMMgntIOCTL: IOCTL_MJ_FW_INFO Length %d\n", agIOCTLPayload->Length));
567285809Sscottl    RequestLength = agIOCTLPayload->Length;
568285809Sscottl    Offset = agIOCTLPayload->Reserved;
569285809Sscottl    if (RequestLength == 0)
570285809Sscottl    {
571285809Sscottl      TI_DBG1(("tiCOMMgntIOCTL: IOCTL_MJ_FW_INFO: No more Data!\n"));
572285809Sscottl      /* out of range */
573285809Sscottl      agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
574285809Sscottl      agIOCTLPayload->Length = 0;
575285809Sscottl      status=IOCTL_CALL_SUCCESS;
576285809Sscottl      return status;
577285809Sscottl    }
578285809Sscottl
579285809Sscottl    osti_memcpy((bit8*)&(agIOCTLPayload->FunctionSpecificArea), (bit8*)&ControllerInfo, sizeof(agsaControllerInfo_t));
580285809Sscottl
581285809Sscottl    TI_DBG1(("tiCOMMgntIOCTL:IOCTL_MJ_FW_INFO ControllerInfo signature 0x%X\n",ControllerInfo.signature));
582285809Sscottl    TI_DBG1(("tiCOMMgntIOCTL:IOCTL_MJ_FW_INFO ControllerInfo PCILinkRate 0x%X\n",ControllerInfo.PCILinkRate));
583285809Sscottl    TI_DBG1(("tiCOMMgntIOCTL:IOCTL_MJ_FW_INFO ControllerInfo PCIWidth 0x%X\n",ControllerInfo.PCIWidth));
584285809Sscottl    agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
585285809Sscottl    status=IOCTL_CALL_SUCCESS;
586285809Sscottl    break;
587285809Sscottl
588285809Sscottl  }
589285809Sscottl
590285809Sscottl  case IOCTL_MJ_GET_FW_REV:
591285809Sscottl  {
592285809Sscottl    agsaControllerInfo_t ControllerInfo;
593285809Sscottl    saGetControllerInfo(agRoot, &ControllerInfo);
594285809Sscottl    TI_DBG3(("tiCOMMgntIOCTL: IOCTL_MJ_GET_FW_REV Length %d\n", agIOCTLPayload->Length));
595285809Sscottl    RequestLength = agIOCTLPayload->Length;
596285809Sscottl    Offset = agIOCTLPayload->Reserved;
597285809Sscottl    if (RequestLength == 0)
598285809Sscottl    {
599285809Sscottl      TI_DBG1(("tiCOMMgntIOCTL: IOCTL_MJ_GET_FW_REV: No more Data!\n"));
600285809Sscottl      /* out of range */
601285809Sscottl      agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
602285809Sscottl      agIOCTLPayload->Length = 0;
603285809Sscottl      status=IOCTL_CALL_SUCCESS;
604285809Sscottl      return status;
605285809Sscottl    }
606285809Sscottl
607285809Sscottl    osti_memcpy((bit8*)&(agIOCTLPayload->FunctionSpecificArea), (bit8*)&ControllerInfo.fwRevision, sizeof(bit32));
608285809Sscottl    loc = (bit8 *)&(agIOCTLPayload->FunctionSpecificArea)+ sizeof(bit32);
609285809Sscottl    osti_memcpy(loc, (bit8*)&ControllerInfo.sdkRevision, sizeof(bit32));
610285809Sscottl
611285809Sscottl    agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
612285809Sscottl    status=IOCTL_CALL_SUCCESS;
613285809Sscottl    break;
614285809Sscottl
615285809Sscottl  }
616285809Sscottl
617285809Sscottl#ifdef SPC_ENABLE_PROFILE
618285809Sscottl  case IOCTL_MJ_FW_PROFILE:
619285809Sscottl  {
620285809Sscottl    TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MJ_FW_PROFILE\n"));
621285809Sscottl    status = tdipFWProfileIoctl( tiRoot, agIOCTLPayload,
622285809Sscottl                                   agParam1, agParam2, agParam3);
623285809Sscottl    break;
624285809Sscottl  }
625285809Sscottl#endif /* SPC_ENABLE_PROFILE */
626285809Sscottl
627285809Sscottl  case IOCTL_MJ_GET_CORE_DUMP:
628285809Sscottl  {
629285809Sscottl    TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MJ_GET_CORE_DUMP\n"));
630285809Sscottl    if (tiIS_SPC(agRoot))
631285809Sscottl    {
632285809Sscottl      status = tdsaRegDumpGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
633285809Sscottl    }
634285809Sscottl    else
635285809Sscottl    {
636285809Sscottl      agIOCTLPayload->Status = IOCTL_ERR_STATUS_NOT_SUPPORTED;
637285809Sscottl      status = IOCTL_CALL_SUCCESS;
638285809Sscottl    }
639285809Sscottl    break;
640285809Sscottl  }
641285809Sscottl//#endif
642285809Sscottl  case IOCTL_MJ_NVMD_SET:
643285809Sscottl  {
644285809Sscottl    bit8 nvmDev;
645285809Sscottl    TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MJ_NVMD_SET\n"));
646285809Sscottl    nvmDev = (bit8) agIOCTLPayload->Status;
647285809Sscottl    agIOCTLPayload->Status = 0;
648285809Sscottl    status = tdsaNVMDSetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, &nvmDev);
649285809Sscottl	break;
650285809Sscottl	}
651285809Sscottl#if 0
652285809Sscottlcase IOCTL_MJ_GPIO:
653285809Sscottl  {
654285809Sscottl    bit32 sVid =0;
655285809Sscottl    TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MJ_GPIO\n"));
656285809Sscottl
657285809Sscottl    /* Get Subsystem vendor  */
658285809Sscottl    sVid = ostiChipConfigReadBit32(tiRoot,0x2C);
659285809Sscottl    sVid = sVid & 0xFFFF;
660285809Sscottl
661285809Sscottl    /* GPIO is only intended for chip down design
662285809Sscottl     * therefore it's only applies to 8H/SPCv product family
663285809Sscottl     */
664285809Sscottl    if(sVid == 0x9005)
665285809Sscottl    return IOCTL_CALL_INVALID_DEVICE;
666285809Sscottl
667285809Sscottl    status = tdsaGpioSetup(tiRoot, agContext, agIOCTLPayload, agParam1, agParam2);
668285809Sscottl    if(status == IOCTL_CALL_SUCCESS)
669285809Sscottl        status = IOCTL_CALL_PENDING; /* Wait for response from the Controller */
670285809Sscottl    else
671285809Sscottl      return status;
672285809Sscottl
673285809Sscottl    break;
674285809Sscottl  }
675285809Sscottl#endif
676285809Sscottl
677285809Sscottl  case IOCTL_MJ_SGPIO:
678285809Sscottl  {
679285809Sscottl    TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MJ_SGPIO\n"));
680285809Sscottl    status = tdsaSGpioIoctlSetup(tiRoot, agContext, agIOCTLPayload, agParam1, agParam2);
681285809Sscottl    break;
682285809Sscottl  }
683285809Sscottl
684285809Sscottl  case IOCTL_MJ_NVMD_GET:
685285809Sscottl  {
686285809Sscottl    bit8 nvmDev;
687285809Sscottl    TI_DBG3(("tiCOMMgntIOCTL: IOCTL_MJ_NVMD_GET\n"));
688285809Sscottl    nvmDev = (bit8) agIOCTLPayload->Status;
689285809Sscottl    agIOCTLPayload->Status = 0;
690285809Sscottl    status = tdsaNVMDGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, &nvmDev);
691285809Sscottl    break;
692285809Sscottl  }
693285809Sscottl
694285809Sscottl  case IOCTL_MJ_GET_FORENSIC_DATA:
695285809Sscottl  {
696285809Sscottl    TI_DBG3(("tiCOMMgntIOCTL: IOCTL_MJ_GET_FORENSIC_DATA\n"));
697285809Sscottl    status = tdsaForensicDataGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
698285809Sscottl    break;
699285809Sscottl  }
700285809Sscottl  case IOCTL_MJ_GET_DEVICE_INFO:
701285809Sscottl  {
702285809Sscottl    TI_DBG3(("tiCOMMgntIOCTL: IOCTL_MJ_GET_DEVICE_INFO\n"));
703285809Sscottl    status = tdsaDeviceInfoGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
704285809Sscottl    break;
705285809Sscottl  }
706285809Sscottl
707285809Sscottl  case IOCTL_MJ_GET_IO_ERROR_STATISTIC:
708285809Sscottl  {
709285809Sscottl    TI_DBG3(("tiCOMMgntIOCTL: IOCTL_MJ_GET_IO_ERROR_STATISTIC\n"));
710285809Sscottl    status = tdsaIoErrorStatisticGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
711285809Sscottl    break;
712285809Sscottl  }
713285809Sscottl
714285809Sscottl  case IOCTL_MJ_GET_IO_EVENT_STATISTIC:
715285809Sscottl  {
716285809Sscottl    TI_DBG3(("tiCOMMgntIOCTL: IOCTL_MJ_GET_IO_EVENT_STATISTIC\n"));
717285809Sscottl    status = tdsaIoEventStatisticGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
718285809Sscottl    break;
719285809Sscottl  }
720285809Sscottl
721285809Sscottl  case IOCTL_MJ_SEND_BIST:
722285809Sscottl  {
723285809Sscottl    TI_DBG1(("tiCOMMgntIOCTL: IOCTL_MJ_SEND_BIST\n"));
724285809Sscottl    status = tdsaSendBISTIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
725285809Sscottl    break;
726285809Sscottl  }
727285809Sscottl
728285809Sscottl#if 0
729285809Sscottl  case IOCTL_MJ_SET_OR_GET_REGISTER:
730285809Sscottl  {
731285809Sscottl    TI_DBG3(("tiCOMMgntIOCTL: IOCTL_MJ_SET_OR_GET_REGISTER\n"));
732285809Sscottl    status = tdsaRegisterIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
733285809Sscottl    break;
734285809Sscottl  }
735285809Sscottl
736285809Sscottl#endif
737285809Sscottl   case IOCTL_MJ_PHY_DETAILS:
738285809Sscottl   {
739285809Sscottl	PhyDetails_t  *PhyDetails = (PhyDetails_t*)&agIOCTLPayload->FunctionSpecificArea;
740285809Sscottl        agsaRoot_t  *agRoot = &(tdsaAllShared->agRootNonInt);
741285809Sscottl        agsaLLRoot_t  *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
742285809Sscottl	bit8  *sasAddressHi;
743285809Sscottl	bit8  *sasAddressLo;
744285809Sscottl	bit8  sas_dev_type;
745285809Sscottl	int i = 0;
746285809Sscottl
747285809Sscottl	tiIniGetDirectSataSasAddr(tiRoot, i , &sasAddressHi, &sasAddressLo);
748285809Sscottl	for( i = 0; i < saRoot->phyCount ; i++)
749285809Sscottl        {
750285809Sscottl		PhyDetails[i].attached_phy = saRoot->phys[i].sasIdentify.phyIdentifier;
751285809Sscottl		/* deice types
752285809Sscottl 		 * SAS
753285809Sscottl 		 * 0x01 - Sas end device
754285809Sscottl 		 * 0x02 - Expander device
755285809Sscottl 		 * SATA
756285809Sscottl 		 * 0x11 - Sata
757285809Sscottl 		 * NO DEVICE 0x00
758285809Sscottl 		 */
759285809Sscottl		sas_dev_type = (saRoot->phys[i].sasIdentify.deviceType_addressFrameType & 0x70 ) >> 4 ;
760285809Sscottl		if ((saRoot->phys[i].status == 1) && (sas_dev_type == 0)){ //status 1 - Phy Up
761285809Sscottl			//Sata phy
762285809Sscottl			PhyDetails[i].attached_dev_type = SAS_PHY_SATA_DEVICE;//0x11 for sata end device
763285809Sscottl			osti_memcpy(&PhyDetails[i].attached_sasAddressHi, tdsaAllShared->Ports[i].SASID.sasAddressHi, sizeof(bit32));
764285809Sscottl			osti_memcpy(&PhyDetails[i].attached_sasAddressLo, tdsaAllShared->Ports[i].SASID.sasAddressLo, sizeof(bit32));
765285809Sscottl			PhyDetails[i].attached_sasAddressLo[3] += i + 16;
766285809Sscottl		}
767285809Sscottl		else {
768285809Sscottl			PhyDetails[i].attached_dev_type = sas_dev_type;
769285809Sscottl	        	osti_memcpy(&PhyDetails[i].attached_sasAddressHi, saRoot->phys[i].sasIdentify.sasAddressHi, sizeof(bit32));
770285809Sscottl			osti_memcpy(&PhyDetails[i].attached_sasAddressLo, saRoot->phys[i].sasIdentify.sasAddressLo, sizeof(bit32));
771285809Sscottl		}
772285809Sscottl		osti_memcpy(&PhyDetails[i].sasAddressLo,&(tdsaAllShared->Ports[i].SASID.sasAddressLo), sizeof(bit32));
773285809Sscottl		osti_memcpy(&PhyDetails[i].sasAddressHi,&(tdsaAllShared->Ports[i].SASID.sasAddressHi), sizeof(bit32));
774285809Sscottl	}
775285809Sscottl
776285809Sscottl//    	osti_memcpy(&agIoctlPayload->FunctionSpecificArea,&PhyInfo, sizeof(agsaSGpioReqResponse_t));
777285809Sscottl//	printk("Ioctl success\n");
778285809Sscottl	return IOCTL_CALL_SUCCESS;
779285809Sscottl   }
780285809Sscottl
781285809Sscottl   case IOCTL_MJ_PHY_GENERAL_STATUS:
782285809Sscottl 	  {
783285809Sscottl		agsaPhyGeneralState_t     *PhyData=NULL;
784285809Sscottl		bit32					   ret = AGSA_RC_FAILURE;
785285809Sscottl  		PhyData = (agsaPhyGeneralState_t*) &agIOCTLPayload->FunctionSpecificArea[0];
786285809Sscottl
787285809Sscottl        PhyData->Reserved2 = 0;
788285809Sscottl        /* Validate the length */
789285809Sscottl        if (agIOCTLPayload->Length < sizeof(agsaPhyGeneralState_t))
790285809Sscottl        {
791285809Sscottl          status = IOCTL_CALL_FAIL;
792285809Sscottl          break;
793285809Sscottl        }
794285809Sscottl
795285809Sscottl        tdsaAllShared->tdFWControlEx.param1 = agParam1;
796285809Sscottl        tdsaAllShared->tdFWControlEx.param2 = agParam2;
797285809Sscottl        tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
798285809Sscottl        tdsaAllShared->tdFWControlEx.inProgress = 1;
799285809Sscottl	//tdsaAllShared->tdFWControlEx.usrAddr = PhyData;
800285809Sscottl
801285809Sscottl    	ret = tdsaGetPhyGeneralStatusIoctl(tiRoot,PhyData);
802285809Sscottl    	if(ret == AGSA_RC_FAILURE)
803285809Sscottl        {
804285809Sscottl    	  status = IOCTL_CALL_FAIL;
805285809Sscottl		  tdsaAllShared->tdFWControlEx.payload = NULL;
806285809Sscottl		  tdsaAllShared->tdFWControlEx.inProgress = 0;
807285809Sscottl		  break;
808285809Sscottl    	}
809285809Sscottl		else if(ret == IOCTL_ERR_STATUS_NOT_SUPPORTED)
810285809Sscottl		{
811285809Sscottl
812285809Sscottl		  agIOCTLPayload->Status = IOCTL_ERR_STATUS_NOT_SUPPORTED;
813285809Sscottl		  status = IOCTL_CALL_SUCCESS;
814285809Sscottl		  break;
815285809Sscottl		}
816285809Sscottl
817285809Sscottl    	//status = IOCTL_CALL_PENDING;
818285809Sscottl    	status = IOCTL_CALL_PENDING;
819285809Sscottl     }
820285809Sscottl
821285809Sscottl   break;
822285809Sscottl#if 1
823285809Sscottl  case IOCTL_MJ_GET_PHY_PROFILE:
824285809Sscottl  {
825285809Sscottl    TI_DBG1(("tiCOMMgntIOCTL: IOCTL_MJ_GET_PHY_PROFILE %p %p %p\n",agParam1,agParam2,agParam3));
826285809Sscottl    status = tdsaPhyProfileIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
827285809Sscottl    break;
828285809Sscottl  }
829285809Sscottl#endif
830285809Sscottl  case IOCTL_MJ_LL_TRACING:
831285809Sscottl  {
832285809Sscottl    void * stu = &agIOCTLPayload->FunctionSpecificArea[0];
833285809Sscottl    switch(agIOCTLPayload->MinorFunction)
834285809Sscottl    {
835285809Sscottl
836285809Sscottl      case IOCTL_MN_LL_RESET_TRACE_INDEX:
837285809Sscottl      {
838285809Sscottl
839285809Sscottl#ifdef SA_ENABLE_TRACE_FUNCTIONS
840285809Sscottl        TSTMTID_TRACE_BUFFER_RESET *llist = (TSTMTID_TRACE_BUFFER_RESET *)stu;
841285809Sscottl        hpTraceBufferParms_t  BufferParms;
842285809Sscottl        TI_DBG5(("tdReturnIOCTL_Info: hpIOCTL_ResetTraceIndex\n"));
843285809Sscottl
844285809Sscottl        BufferParms.TraceCompiled  = 0;
845285809Sscottl        BufferParms.TraceWrap      = 0;
846285809Sscottl        BufferParms.CurrentTraceIndexWrapCount = 0;
847285809Sscottl        BufferParms.BufferSize     = 0;
848285809Sscottl        BufferParms.CurrentIndex   = 0;
849285809Sscottl        BufferParms.pTrace         = NULL;
850285809Sscottl        BufferParms.pTraceIndexWrapCount        = NULL;
851285809Sscottl        BufferParms.pTraceMask     = NULL;
852285809Sscottl        BufferParms.pCurrentTraceIndex  = NULL;
853285809Sscottl
854285809Sscottl        smTraceGetInfo(agRoot,&BufferParms);
855285809Sscottl        TI_DBG5(("tdReturnIOCTL_Info: pTrace                %p\n",BufferParms.pTrace));
856285809Sscottl        TI_DBG5(("tdReturnIOCTL_Info: pCurrentTraceIndex    %p %X\n",BufferParms.pCurrentTraceIndex,*BufferParms.pCurrentTraceIndex));
857285809Sscottl        TI_DBG5(("tdReturnIOCTL_Info: pTraceIndexWrapCount  %p %X\n",BufferParms.pTraceIndexWrapCount,*BufferParms.pTraceIndexWrapCount));
858285809Sscottl        TI_DBG5(("tdReturnIOCTL_Info: pTraceMask            %p %X\n",BufferParms.pTraceMask,*BufferParms.pTraceMask));
859285809Sscottl
860285809Sscottl        if( llist->Flag != 0)
861285809Sscottl        {
862285809Sscottl          if( llist->TraceMask != *BufferParms.pTraceMask)
863285809Sscottl          {
864285809Sscottl            smTraceSetMask(agRoot,  llist->TraceMask );
865285809Sscottl          }
866285809Sscottl        }
867285809Sscottl        if( llist->Reset)
868285809Sscottl        {
869285809Sscottl
870285809Sscottl          *BufferParms.pCurrentTraceIndex = 0;
871285809Sscottl          smResetTraceBuffer(agRoot);
872285809Sscottl
873285809Sscottl          *BufferParms.pCurrentTraceIndex = 0;
874285809Sscottl          *BufferParms.pTraceIndexWrapCount =0;
875285809Sscottl          llist->TraceMask = *BufferParms.pTraceMask;
876285809Sscottl        }
877285809Sscottl#endif  /* SA_ENABLE_TRACE_FUNCTIONS  */
878285809Sscottl        agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
879285809Sscottl        status = IOCTL_CALL_SUCCESS;
880285809Sscottl
881285809Sscottl      }
882285809Sscottl      break;
883285809Sscottl
884285809Sscottl    case IOCTL_MN_LL_GET_TRACE_BUFFER_INFO:
885285809Sscottl      {
886285809Sscottl        hpTraceBufferParms_t  BufferParms;
887285809Sscottl        TSTMTID_TRACE_BUFFER_INFO *llist = (TSTMTID_TRACE_BUFFER_INFO *)stu;
888285809Sscottl        TI_DBG5(("tdReturnIOCTL_Info: hpIOCTL_GetTraceBufferInfo\n"));
889285809Sscottl
890285809Sscottl
891285809Sscottl        BufferParms.TraceCompiled  = 0;
892285809Sscottl        BufferParms.TraceWrap      = 0;
893285809Sscottl        BufferParms.CurrentTraceIndexWrapCount = 0;
894285809Sscottl        BufferParms.BufferSize     = 0;
895285809Sscottl        BufferParms.CurrentIndex   = 0;
896285809Sscottl        BufferParms.pTrace         = NULL;
897285809Sscottl        BufferParms.pTraceMask     = NULL;
898285809Sscottl#ifdef SA_ENABLE_TRACE_FUNCTIONS
899285809Sscottl        smTraceGetInfo(agRoot,&BufferParms);
900285809Sscottl#endif  /* SA_ENABLE_TRACE_FUNCTIONS not enabled */
901285809Sscottl        llist->TraceCompiled = BufferParms.TraceCompiled;
902285809Sscottl        llist->BufferSize = BufferParms.BufferSize;
903285809Sscottl        llist->CurrentIndex = BufferParms.CurrentIndex ;
904285809Sscottl        llist->CurrentTraceIndexWrapCount =  BufferParms.CurrentTraceIndexWrapCount;
905285809Sscottl        llist->TraceWrap = BufferParms.TraceWrap;
906285809Sscottl        if(BufferParms.pTraceMask != NULL)
907285809Sscottl        {
908285809Sscottl          llist->TraceMask = *BufferParms.pTraceMask;
909285809Sscottl        }
910285809Sscottl        agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
911285809Sscottl        status = IOCTL_CALL_SUCCESS;
912285809Sscottl      }
913285809Sscottl      break;
914285809Sscottl
915285809Sscottl    case IOCTL_MN_LL_GET_TRACE_BUFFER:
916285809Sscottl      {
917285809Sscottl#ifdef SA_ENABLE_TRACE_FUNCTIONS
918285809Sscottl        TSTMTID_TRACE_BUFFER_FETCH *llist = (TSTMTID_TRACE_BUFFER_FETCH *)stu;
919285809Sscottl
920285809Sscottl        hpTraceBufferParms_t  BufferParms;
921285809Sscottl        bit32 c= 0;
922285809Sscottl
923285809Sscottl        BufferParms.TraceCompiled  = 0;
924285809Sscottl        BufferParms.TraceWrap      = 0;
925285809Sscottl        BufferParms.CurrentTraceIndexWrapCount = 0;
926285809Sscottl        BufferParms.BufferSize     = 0;
927285809Sscottl        BufferParms.CurrentIndex   = 0;
928285809Sscottl        BufferParms.pTrace         = NULL;
929285809Sscottl        smTraceGetInfo(agRoot,&BufferParms);
930285809Sscottl
931285809Sscottl        TI_DBG6(("tdReturnIOCTL_Info: hpIOCTL_GetTraceBuffer\n"));
932285809Sscottl
933285809Sscottl        if(llist->LowFence != LowFence32Bits)
934285809Sscottl        {
935285809Sscottl          break;
936285809Sscottl        }
937285809Sscottl        if(llist->HighFence != HighFence32Bits)
938285809Sscottl        {
939285809Sscottl          break;
940285809Sscottl        }
941285809Sscottl
942285809Sscottl        if(llist->BufferOffsetBegin + FetchBufferSIZE > BufferParms.BufferSize  )
943285809Sscottl        {
944285809Sscottl        }
945285809Sscottl
946285809Sscottl        for ( c=0; c < FetchBufferSIZE;c++)
947285809Sscottl        {
948285809Sscottl          llist->Data[c] = *(BufferParms.pTrace+( c + llist->BufferOffsetBegin));
949285809Sscottl        }
950285809Sscottl#endif  /* SA_ENABLE_TRACE_FUNCTIONS not enabled */
951285809Sscottl      }
952285809Sscottl      agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
953285809Sscottl      status = IOCTL_CALL_SUCCESS;
954285809Sscottl      break;
955285809Sscottl    }
956285809Sscottl    break;
957285809Sscottl  }
958285809Sscottl
959285809Sscottl#ifdef SA_LL_API_TEST
960285809Sscottl  case IOCTL_MJ_LL_API_TEST:
961285809Sscottl  {
962285809Sscottl    status = tdLlApiTestIoctl( tiRoot, agIOCTLPayload,
963285809Sscottl               agParam1,agParam2,agParam3 );
964285809Sscottl    break;
965285809Sscottl  }
966285809Sscottl
967285809Sscottl#endif /* SA_LL_API_TEST */
968285809Sscottl
969285809Sscottl  case IOCTL_MJ_MODE_CTL_PAGE:
970285809Sscottl  {
971285809Sscottl    /* The SPCv controller has some options accessed via mode pages */
972285809Sscottl    tiEncryptDekConfigPage_t *pModePage= (tiEncryptDekConfigPage_t *) &agIOCTLPayload->FunctionSpecificArea[0];
973285809Sscottl    bit32 pageLength = 0;
974285809Sscottl    bit32 pageCode;
975285809Sscottl    bit32 modeOperation;
976285809Sscottl
977285809Sscottl    pageCode = pModePage->pageCode & 0xFF;
978285809Sscottl    modeOperation = *(bit32 *) agParam2;
979285809Sscottl
980285809Sscottl    switch(modeOperation)
981285809Sscottl    {
982285809Sscottl
983285809Sscottl      case tiModePageSet:
984285809Sscottl        switch (pageCode)
985285809Sscottl        {
986285809Sscottl          case TI_ENCRYPTION_DEK_CONFIG_PAGE:
987285809Sscottl            pageLength = sizeof(tiEncryptDekConfigPage_t);
988285809Sscottl            break;
989285809Sscottl
990285809Sscottl          case TI_ENCRYPTION_CONTROL_PARM_PAGE:
991285809Sscottl            pageLength = sizeof(tiEncryptControlParamPage_t);
992285809Sscottl            break;
993285809Sscottl
994285809Sscottl          case TI_ENCRYPTION_GENERAL_CONFIG_PAGE:
995285809Sscottl            /* Pages are currently unsupported */
996285809Sscottl            pageLength = 0;
997285809Sscottl            break;
998285809Sscottl        }
999285809Sscottl
1000285809Sscottl        status = saSetControllerConfig(agRoot, 0, pageCode, pageLength, pModePage, (agsaContext_t *)agIOCTLPayload);
1001285809Sscottl        break;
1002285809Sscottl
1003285809Sscottl      case tiModePageGet:
1004285809Sscottl        status = saGetControllerConfig(agRoot, 0, pageCode, 0, 0, (agsaContext_t *)agIOCTLPayload);
1005285809Sscottl        break;
1006285809Sscottl
1007285809Sscottl      default:
1008285809Sscottl        agIOCTLPayload->Status = IOCTL_ERR_STATUS_NOT_SUPPORTED;
1009285809Sscottl    }
1010285809Sscottl  }
1011285809Sscottl    break;
1012285809Sscottl#ifdef PHY_RESTART_TEST
1013285809Sscottl    case IOCTL_MJ_PORT_START:
1014285809Sscottl    {
1015285809Sscottl      bit32 portID, tiStatus;
1016285809Sscottl      bit32 *data = (bit32*) &agIOCTLPayload->FunctionSpecificArea[0];
1017285809Sscottl      portID = *data;
1018285809Sscottl
1019285809Sscottl      tiStatus = tiCOMPortStart(tiRoot, portID, tdsaAllShared->Ports[portID].tiPortalContext, 0);
1020285809Sscottl
1021285809Sscottl      if (tiStatus == tiSuccess)
1022285809Sscottl      {
1023285809Sscottl        agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
1024285809Sscottl      }
1025285809Sscottl      else
1026285809Sscottl      {
1027285809Sscottl        agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1028285809Sscottl      }
1029285809Sscottl      status = IOCTL_CALL_SUCCESS;
1030285809Sscottl      break;
1031285809Sscottl    }
1032285809Sscottl
1033285809Sscottl    case IOCTL_MJ_PORT_STOP:
1034285809Sscottl    {
1035285809Sscottl      bit32 portID, tiStatus;
1036285809Sscottl      bit32 *data = (bit32*) &agIOCTLPayload->FunctionSpecificArea[0];
1037285809Sscottl      portID =  *data;
1038285809Sscottl
1039285809Sscottl      tiStatus = tiCOMPortStop(tiRoot, tdsaAllShared->Ports[portID].tiPortalContext);
1040285809Sscottl      if (tiStatus == tiSuccess)
1041285809Sscottl      {
1042285809Sscottl        agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
1043285809Sscottl      }
1044285809Sscottl      else
1045285809Sscottl      {
1046285809Sscottl        agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1047285809Sscottl      }
1048285809Sscottl
1049285809Sscottl      status = IOCTL_CALL_SUCCESS;
1050285809Sscottl      break;
1051285809Sscottl    }
1052285809Sscottl#endif
1053285809Sscottl case IOCTL_MJ_SEND_TMF:
1054285809Sscottl       switch(agIOCTLPayload->MinorFunction)
1055285809Sscottl	{
1056285809Sscottl	     case IOCTL_MN_TMF_DEVICE_RESET:
1057285809Sscottl		status = tdsaSendTMFIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, AG_TARGET_WARM_RESET);
1058285809Sscottl	        break;
1059285809Sscottl	     case IOCTL_MN_TMF_LUN_RESET:
1060285809Sscottl	 	status = tdsaSendTMFIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, AG_LOGICAL_UNIT_RESET);
1061285809Sscottl		break;
1062285809Sscottl	}
1063285809Sscottl	break;
1064285809Sscottl case IOCTL_MJ_GET_DRIVER_VERSION:
1065285809Sscottl        osti_sprintf(agIOCTLPayload->FunctionSpecificArea, "%s", AGTIAPI_DRIVER_VERSION);
1066285809Sscottl        agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
1067285809Sscottl        status=IOCTL_CALL_SUCCESS;
1068285809Sscottl	break;
1069285809Sscottl  default:
1070285809Sscottl    agIOCTLPayload->Status = IOCTL_ERR_STATUS_NOT_SUPPORTED;
1071285809Sscottl    break;
1072285809Sscottl  }
1073285809Sscottl
1074285809Sscottl  return status;
1075285809Sscottl}
1076285809Sscottl
1077285809Sscottl#if 0
1078285809Sscottl/*****************************************************************************
1079285809Sscottl*
1080285809Sscottl* tdsaGpioSetup
1081285809Sscottl*
1082285809Sscottl* Purpose:  This routine is called to set Gpio parameters to the controller.
1083285809Sscottl*
1084285809Sscottl* Parameters:
1085285809Sscottl*   tiRoot:         Pointer to driver instance
1086285809Sscottl*   agsaContext_t :
1087285809Sscottl*   tiIOCTLPayload_t :  ioctl header with payload gpio info
1088285809Sscottl*   agParam1,agParam2 :  Generic parameters
1089285809Sscottl*
1090285809Sscottl* Return: status
1091285809Sscottl*
1092285809Sscottl*
1093285809Sscottl*****************************************************************************/
1094285809SscottlosGLOBAL bit32
1095285809SscottltdsaGpioSetup(
1096285809Sscottl                tiRoot_t            *tiRoot,
1097285809Sscottl                agsaContext_t       *agContext,
1098285809Sscottl                tiIOCTLPayload_t    *agIOCTLPayload,
1099285809Sscottl                void                *agParam1,
1100285809Sscottl                void                *agParam2
1101285809Sscottl                )
1102285809Sscottl{
1103285809Sscottl
1104285809Sscottl  tdsaTimerRequest_t        *osIoctlTimer;
1105285809Sscottl  agsaGpioEventSetupInfo_t  *gpioEventSetupInfo;
1106285809Sscottl  agsaGpioWriteSetupInfo_t  *gpioWriteSetupInfo;
1107285809Sscottl  agsaGpioPinSetupInfo_t    *gpioPinSetupInfo;
1108285809Sscottl  tdsaRoot_t                *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1109285809Sscottl  tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1110285809Sscottl  agsaRoot_t                *agRoot = &(tdsaAllShared->agRootInt);
1111285809Sscottl  bit32                     status = IOCTL_CALL_SUCCESS;
1112285809Sscottl
1113285809Sscottl  TI_DBG3(("tdsaGpioSetup: start\n"));
1114285809Sscottl
1115285809Sscottl  if(tiRoot == agNULL || agIOCTLPayload == agNULL )
1116285809Sscottl  return IOCTL_CALL_FAIL;
1117285809Sscottl
1118285809Sscottl  osIoctlTimer = &tdsaAllShared->osIoctlTimer;
1119285809Sscottl  tdsaInitTimerRequest(tiRoot, osIoctlTimer);
1120285809Sscottl  tdIoctlStartTimer(tiRoot, osIoctlTimer); /* Start the timout handler for both ioctl and controller response */
1121285809Sscottl  tdsaAllShared->tdFWControlEx.virtAddr = (bit8 *)osIoctlTimer;
1122285809Sscottl
1123285809Sscottl  tdsaAllShared->tdFWControlEx.usrAddr = (bit8 *)&agIOCTLPayload->FunctionSpecificArea[0];
1124285809Sscottl  tdsaAllShared->tdFWControlEx.param1 = agParam1;
1125285809Sscottl  tdsaAllShared->tdFWControlEx.param2 = agParam2;
1126285809Sscottl  tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
1127285809Sscottl  tdsaAllShared->tdFWControlEx.inProgress = 1;
1128285809Sscottl
1129285809Sscottl    switch (agIOCTLPayload->MinorFunction)
1130285809Sscottl    {
1131285809Sscottl
1132285809Sscottl     case IOCTL_MN_GPIO_PINSETUP:
1133285809Sscottl     {
1134285809Sscottl	 TI_DBG3(("tdsaGpioSetup: IOCTL_MN_GPIO_PINSETUP\n"));
1135285809Sscottl         gpioPinSetupInfo =(agsaGpioPinSetupInfo_t *)&agIOCTLPayload->FunctionSpecificArea[0];
1136285809Sscottl         status = saGpioPinSetup(agRoot, agContext, 0, gpioPinSetupInfo);
1137285809Sscottl
1138285809Sscottl         break;
1139285809Sscottl     }
1140285809Sscottl     case IOCTL_MN_GPIO_EVENTSETUP:
1141285809Sscottl     {
1142285809Sscottl	TI_DBG3(("tdsaGpioSetup: IOCTL_MN_GPIO_EVENTSETUP\n"));
1143285809Sscottl        gpioEventSetupInfo = (agsaGpioEventSetupInfo_t  *)&agIOCTLPayload->FunctionSpecificArea[0];
1144285809Sscottl        status = saGpioEventSetup(agRoot, agContext, 0, gpioEventSetupInfo);
1145285809Sscottl
1146285809Sscottl        break;
1147285809Sscottl     }
1148285809Sscottl
1149285809Sscottl     case IOCTL_MN_GPIO_READ:
1150285809Sscottl     {
1151285809Sscottl	 TI_DBG3(("tdsaGpioSetup: IOCTL_MN_GPIO_READ\n"));
1152285809Sscottl         status = saGpioRead(agRoot, agContext, 0);
1153285809Sscottl
1154285809Sscottl        break;
1155285809Sscottl     }
1156285809Sscottl
1157285809Sscottl     case IOCTL_MN_GPIO_WRITE:
1158285809Sscottl     {
1159285809Sscottl	 TI_DBG3(("tdsaGpioSetup: IOCTL_MN_GPIO_WRITE\n"));
1160285809Sscottl         gpioWriteSetupInfo = (agsaGpioWriteSetupInfo_t *)&agIOCTLPayload->FunctionSpecificArea[0];
1161285809Sscottl         status = saGpioWrite(agRoot, agContext, 0, gpioWriteSetupInfo->gpioWritemask, gpioWriteSetupInfo->gpioWriteVal);
1162285809Sscottl
1163285809Sscottl         break;
1164285809Sscottl     }
1165285809Sscottl
1166285809Sscottl     default :
1167285809Sscottl         return status;
1168285809Sscottl    }
1169285809Sscottl
1170285809Sscottl    if(status != AGSA_RC_SUCCESS)
1171285809Sscottl    {
1172285809Sscottl      status = IOCTL_CALL_FAIL;
1173285809Sscottl      agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1174285809Sscottl
1175285809Sscottl      tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK);
1176285809Sscottl      if (osIoctlTimer->timerRunning == agTRUE)
1177285809Sscottl      {
1178285809Sscottl         tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
1179285809Sscottl         tdsaKillTimer(tiRoot, osIoctlTimer);
1180285809Sscottl
1181285809Sscottl      }else{
1182285809Sscottl         tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
1183285809Sscottl      }
1184285809Sscottl    }
1185285809Sscottl
1186285809Sscottl    TI_DBG3(("tdsaGpioPinSetup: End\n"));
1187285809Sscottl    return status;
1188285809Sscottl
1189285809Sscottl}
1190285809Sscottl#endif
1191285809Sscottl
1192285809Sscottl/*****************************************************************************
1193285809Sscottl*
1194285809Sscottl* ostiGetGpioIOCTLRsp
1195285809Sscottl*
1196285809Sscottl* Purpose:  This routine is called for Get Gpio IOCTL reaponse has been received.
1197285809Sscottl*
1198285809Sscottl* Parameters:
1199285809Sscottl*   tiRoot:         Pointer to driver instance
1200285809Sscottl*   payloadRsp:     Pointer to the FW download IOMB's payload.
1201285809Sscottl*
1202285809Sscottl* Return: none
1203285809Sscottl*
1204285809Sscottl*
1205285809Sscottl*****************************************************************************/
1206285809Sscottl
1207285809SscottlosGLOBAL void  ostiGetGpioIOCTLRsp(
1208285809Sscottl                        tiRoot_t                 *tiRoot,
1209285809Sscottl                        bit32                    status,
1210285809Sscottl                        bit32                    gpioReadValue,
1211285809Sscottl                        agsaGpioPinSetupInfo_t   *gpioPinSetupInfo,
1212285809Sscottl                        agsaGpioEventSetupInfo_t *gpioEventSetupInfo
1213285809Sscottl                        )
1214285809Sscottl{
1215285809Sscottl     tdsaRoot_t                *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1216285809Sscottl     tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1217285809Sscottl     tiIOCTLPayload_t          *agIoctlPayload ;
1218285809Sscottl     agsaGpioReadInfo_t        *gpioReadInfo;
1219285809Sscottl
1220285809Sscottl     tdsaTimerRequest_t        *osIoctlTimer;
1221285809Sscottl	 osIoctlTimer = (tdsaTimerRequest_t *)tdsaAllShared->tdFWControlEx.virtAddr;
1222285809Sscottl
1223285809Sscottl     TI_DBG2(("ostiGetGpioIOCTLRsp: start, status = %d \n", status));
1224285809Sscottl
1225285809Sscottl     agIoctlPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1226285809Sscottl
1227285809Sscottl     if(agIoctlPayload == agNULL){
1228285809Sscottl        return;
1229285809Sscottl      }
1230285809Sscottl
1231285809Sscottl     agIoctlPayload->Status =(bit16) status;
1232285809Sscottl
1233285809Sscottl     if( (status != IOCTL_CALL_TIMEOUT) && (osIoctlTimer != NULL))
1234285809Sscottl     {
1235285809Sscottl        tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK);
1236285809Sscottl        if (osIoctlTimer->timerRunning == agTRUE)
1237285809Sscottl        {
1238285809Sscottl           tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
1239285809Sscottl           tdsaKillTimer(tiRoot, osIoctlTimer);
1240285809Sscottl
1241285809Sscottl        }else{
1242285809Sscottl           tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
1243285809Sscottl        }
1244285809Sscottl     }else  {
1245285809Sscottl         tdsaAllShared->tdFWControlEx.inProgress = 0;
1246285809Sscottl         agIoctlPayload->Status = (bit16)status;
1247285809Sscottl         ostiIOCTLSetSignal(tiRoot, tdsaAllShared->tdFWControlEx.param1,
1248285809Sscottl                               tdsaAllShared->tdFWControlEx.param2, NULL);
1249285809Sscottl        return;
1250285809Sscottl     }
1251285809Sscottl
1252285809Sscottl     if(status == SUCCESS)
1253285809Sscottl       TI_DBG3((" ostiGetGpioIOCTLRsp:Got GPIO response from OUTBuf"));
1254285809Sscottl    else {
1255285809Sscottl      tdsaAllShared->tdFWControlEx.inProgress = 0;
1256285809Sscottl      ostiIOCTLSetSignal(tiRoot, tdsaAllShared->tdFWControlEx.param1,
1257285809Sscottl                               tdsaAllShared->tdFWControlEx.param2, NULL);
1258285809Sscottl      return;
1259285809Sscottl    }
1260285809Sscottl
1261285809Sscottl    switch (agIoctlPayload->MinorFunction)
1262285809Sscottl     {
1263285809Sscottl
1264285809Sscottl     case IOCTL_MN_GPIO_PINSETUP:
1265285809Sscottl      {
1266285809Sscottl       TI_DBG3((" ostiGetGpioIOCTLRsp:Got GPIO response for IOCTL_MN_GPIO_PINSETUP"));
1267285809Sscottl
1268285809Sscottl         break;
1269285809Sscottl      }
1270285809Sscottl     case IOCTL_MN_GPIO_EVENTSETUP:
1271285809Sscottl     {
1272285809Sscottl       TI_DBG3((" ostiGetGpioIOCTLRsp:Got GPIO response for IOCTL_MN_GPIO_EVENTSETUP"));
1273285809Sscottl
1274285809Sscottl         break;
1275285809Sscottl     }
1276285809Sscottl
1277285809Sscottl     case IOCTL_MN_GPIO_WRITE:
1278285809Sscottl     {
1279285809Sscottl       TI_DBG3((" ostiGetGpioIOCTLRsp:Got GPIO response for IOCTL_MN_GPIO_WRITE"));
1280285809Sscottl
1281285809Sscottl         break;
1282285809Sscottl     }
1283285809Sscottl
1284285809Sscottl    case IOCTL_MN_GPIO_READ:
1285285809Sscottl    {
1286285809Sscottl         gpioReadInfo = ( agsaGpioReadInfo_t *)tdsaAllShared->tdFWControlEx.usrAddr;
1287285809Sscottl
1288285809Sscottl         gpioReadInfo->gpioReadValue = gpioReadValue;
1289285809Sscottl         gpioReadInfo->gpioInputEnabled = gpioPinSetupInfo->gpioInputEnabled ; /* GPIOIE */
1290285809Sscottl         gpioReadInfo->gpioEventLevelChangePart1 = gpioPinSetupInfo->gpioTypePart1; /* GPIEVCHANGE (pins 11-0) */
1291285809Sscottl         gpioReadInfo->gpioEventLevelChangePart2 = gpioPinSetupInfo->gpioTypePart2; /* GPIEVCHANGE (pins 23-20) */
1292285809Sscottl         gpioReadInfo->gpioEventRisingEdgePart1 = 0xFFF & gpioEventSetupInfo->gpioEventRisingEdge; /* GPIEVRISE (pins 11-0) */
1293285809Sscottl         gpioReadInfo->gpioEventRisingEdgePart2 = 0x00F00000 & (gpioEventSetupInfo->gpioEventRisingEdge); /* GPIEVRISE (pins 23-20) */
1294285809Sscottl         gpioReadInfo->gpioEventFallingEdgePart1 = 0xFFF & gpioEventSetupInfo->gpioEventFallingEdge; /* GPIEVALL (pins 11-0) */
1295285809Sscottl         gpioReadInfo->gpioEventFallingEdgePart2 = 0x00F00000  & gpioEventSetupInfo->gpioEventFallingEdge; /* GPIEVALL (pins 23-20 */
1296285809Sscottl
1297285809Sscottl         break;
1298285809Sscottl     }
1299285809Sscottl
1300285809Sscottl    default :
1301285809Sscottl         break;
1302285809Sscottl    }
1303285809Sscottl
1304285809Sscottl    if(tdsaAllShared->tdFWControlEx.inProgress)
1305285809Sscottl    {
1306285809Sscottl      tdsaAllShared->tdFWControlEx.inProgress = 0;
1307285809Sscottl      ostiIOCTLSetSignal(tiRoot, tdsaAllShared->tdFWControlEx.param1,
1308285809Sscottl                              tdsaAllShared->tdFWControlEx.param2, NULL);
1309285809Sscottl    }
1310285809Sscottl    TI_DBG2(("ostiGetGpioIOCTLRsp: end \n"));
1311285809Sscottl
1312285809Sscottl   return ;
1313285809Sscottl}
1314285809Sscottl
1315285809Sscottl/*****************************************************************************
1316285809Sscottl*
1317285809Sscottl* tdsaSGpioIoctlSetup
1318285809Sscottl*
1319285809Sscottl* Purpose:  This routine is called to send SGPIO request to the controller.
1320285809Sscottl*
1321285809Sscottl* Parameters:
1322285809Sscottl*   tiRoot:             Pointer to driver instance
1323285809Sscottl*   agsaContext_t:      Context for this request
1324285809Sscottl*   tiIOCTLPayload_t:   ioctl header with payload sgpio info
1325285809Sscottl*   agParam1,agParam2:  Generic parameters
1326285809Sscottl*
1327285809Sscottl* Return: status
1328285809Sscottl*
1329285809Sscottl*
1330285809Sscottl*****************************************************************************/
1331285809SscottlosGLOBAL bit32
1332285809SscottltdsaSGpioIoctlSetup(
1333285809Sscottl                tiRoot_t            *tiRoot,
1334285809Sscottl                agsaContext_t       *agContext,
1335285809Sscottl                tiIOCTLPayload_t    *agIOCTLPayload,
1336285809Sscottl                void                *agParam1,
1337285809Sscottl                void                *agParam2
1338285809Sscottl                )
1339285809Sscottl{
1340285809Sscottl  tdsaRoot_t                *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1341285809Sscottl  tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1342285809Sscottl  agsaRoot_t                *agRoot = &(tdsaAllShared->agRootInt);
1343285809Sscottl  bit32                     status = IOCTL_CALL_FAIL;
1344285809Sscottl  agsaSGpioReqResponse_t    *pSGpioReq = (agsaSGpioReqResponse_t *)&agIOCTLPayload->FunctionSpecificArea[0];
1345285809Sscottl
1346285809Sscottl  TI_DBG3(("tdsaSGpioIoctlSetup: start\n"));
1347285809Sscottl
1348285809Sscottl  agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1349285809Sscottl
1350285809Sscottl  do
1351285809Sscottl  {
1352285809Sscottl    if (tiRoot == agNULL || agIOCTLPayload == agNULL)
1353285809Sscottl    {
1354285809Sscottl      break;
1355285809Sscottl    }
1356285809Sscottl
1357285809Sscottl    /* Validate the length */
1358285809Sscottl    if (agIOCTLPayload->Length < sizeof(agsaSGpioReqResponse_t))
1359285809Sscottl    {
1360285809Sscottl      TI_DBG3(("Invalid length\n"));
1361285809Sscottl      break;
1362285809Sscottl    }
1363285809Sscottl
1364285809Sscottl    /* Validate the SMP Frame Type, Function and Register Type fields */
1365285809Sscottl    if ((pSGpioReq->smpFrameType != SMP_REQUEST) || \
1366285809Sscottl        ((pSGpioReq->function != SMP_READ_GPIO_REGISTER) && (pSGpioReq->function != SMP_WRITE_GPIO_REGISTER)) || \
1367285809Sscottl        (pSGpioReq->registerType > AGSA_SGPIO_GENERAL_PURPOSE_TRANSMIT_REG))
1368285809Sscottl    {
1369285809Sscottl      TI_DBG4(("Invalid Parameter\n"));
1370285809Sscottl      break;
1371285809Sscottl    }
1372285809Sscottl
1373285809Sscottl    /* Specific validation for configuration register type */
1374285809Sscottl    if (AGSA_SGPIO_CONFIG_REG == pSGpioReq->registerType)
1375285809Sscottl    {
1376285809Sscottl      if ((pSGpioReq->registerIndex > 0x01) || \
1377285809Sscottl          ((0x00 == pSGpioReq->registerIndex) && (pSGpioReq->registerCount > 0x02)) || \
1378285809Sscottl          ((0x01 == pSGpioReq->registerIndex) && (pSGpioReq->registerCount > 0x01)))
1379285809Sscottl      {
1380285809Sscottl        break;
1381285809Sscottl      }
1382285809Sscottl    }
1383285809Sscottl
1384285809Sscottl    /* Use FW control place in shared structure to keep the necessary information */
1385285809Sscottl    tdsaAllShared->tdFWControlEx.param1 = agParam1;
1386285809Sscottl    tdsaAllShared->tdFWControlEx.param2 = agParam2;
1387285809Sscottl    tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
1388285809Sscottl    tdsaAllShared->tdFWControlEx.inProgress = 1;
1389285809Sscottl
1390285809Sscottl    status = saSgpio(agRoot, agContext, 0, pSGpioReq);
1391285809Sscottl    if (status != AGSA_RC_SUCCESS)
1392285809Sscottl    {
1393285809Sscottl      break;
1394285809Sscottl    }
1395285809Sscottl
1396285809Sscottl    status = IOCTL_CALL_PENDING;
1397285809Sscottl
1398285809Sscottl  } while (0);
1399285809Sscottl
1400285809Sscottl  TI_DBG3(("tdsaGpioPinSetup: End\n"));
1401285809Sscottl  return status;
1402285809Sscottl}
1403285809Sscottl
1404285809Sscottl/*****************************************************************************
1405285809Sscottl*
1406285809Sscottl* ostiSgpioIoctlRsp
1407285809Sscottl*
1408285809Sscottl* Purpose:  This routine is called when a SGPIO IOCTL response is received.
1409285809Sscottl*
1410285809Sscottl* Parameters:
1411285809Sscottl*   tiRoot:         Pointer to driver instance
1412285809Sscottl*   pSgpioResponse: Pointer to the SGPIO response
1413285809Sscottl*
1414285809Sscottl* Return: none
1415285809Sscottl*
1416285809Sscottl*
1417285809Sscottl*****************************************************************************/
1418285809SscottlosGLOBAL void ostiSgpioIoctlRsp(
1419285809Sscottl                            tiRoot_t                *tiRoot,
1420285809Sscottl                            agsaSGpioReqResponse_t  *pSgpioResponse
1421285809Sscottl                            )
1422285809Sscottl{
1423285809Sscottl  tdsaRoot_t        *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1424285809Sscottl  tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1425285809Sscottl  tiIOCTLPayload_t  *agIoctlPayload = agNULL;
1426285809Sscottl
1427285809Sscottl  TI_DBG3(("ostiSgpioIoctlRsp: start\n"));
1428285809Sscottl
1429285809Sscottl  if (tdsaAllShared->tdFWControlEx.inProgress)
1430285809Sscottl  {
1431285809Sscottl    agIoctlPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1432285809Sscottl    if (agIoctlPayload)
1433285809Sscottl    {
1434285809Sscottl      tdsaAllShared->tdFWControlEx.payload = NULL;
1435285809Sscottl      osti_memcpy(&agIoctlPayload->FunctionSpecificArea[0], pSgpioResponse, sizeof(agsaSGpioReqResponse_t));
1436285809Sscottl      agIoctlPayload->Status = IOCTL_ERR_STATUS_OK;
1437285809Sscottl      sgpioResponseSet = 1;
1438285809Sscottl    }
1439285809Sscottl	tdsaAllShared->sgpioResponseSet = 1;    //Sunitha:Check if needed?
1440285809Sscottl
1441285809Sscottl    ostiIOCTLSetSignal(tiRoot, tdsaAllShared->tdFWControlEx.param1,
1442285809Sscottl                  tdsaAllShared->tdFWControlEx.param2, agNULL);
1443285809Sscottl
1444285809Sscottl    tdsaAllShared->tdFWControlEx.inProgress = 0;
1445285809Sscottl  }
1446285809Sscottl
1447285809Sscottl  TI_DBG3(("ostiSgpioIoctlRsp: end\n"));
1448285809Sscottl}
1449285809Sscottl/*****************************************************************************
1450285809Sscottl*
1451285809Sscottl* ostiCOMMgntIOCTLRsp
1452285809Sscottl*
1453285809Sscottl* Purpose:  This routine is called when FW control IOCTL reaponse has been received.
1454285809Sscottl*           This function is used for both target and initiator.
1455285809Sscottl*
1456285809Sscottl* Parameters:
1457285809Sscottl*   tiRoot:          Pointer to driver instance
1458285809Sscottl*   payloadRsp:     Pointer to the FW download IOMB's payload.
1459285809Sscottl*
1460285809Sscottl* Return: none
1461285809Sscottl*
1462285809Sscottl*
1463285809Sscottl*
1464285809Sscottl*****************************************************************************/
1465285809Sscottl
1466285809SscottlosGLOBAL void ostiCOMMgntIOCTLRsp(
1467285809Sscottl                        tiRoot_t            *tiRoot,
1468285809Sscottl                        bit32               status
1469285809Sscottl                        )
1470285809Sscottl{
1471285809Sscottl    tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1472285809Sscottl    tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1473285809Sscottl
1474285809Sscottl    TI_DBG1(("ostiCOMMgntIOCTLRsp: status 0x%x\n",status));
1475285809Sscottl    (tdsaAllShared->tdFWControlEx.tdFWControl)->retcode = status;
1476285809Sscottl
1477285809Sscottl    ostiFreeMemory(tiRoot,
1478285809Sscottl                   tdsaAllShared->tdFWControlEx.buffer,
1479285809Sscottl                   tdsaAllShared->tdFWControlEx.tdFWControl->len);
1480285809Sscottl
1481285809Sscottl    ostiIOCTLSetSignal(tiRoot,
1482285809Sscottl                       tdsaAllShared->tdFWControlEx.param1,
1483285809Sscottl                       tdsaAllShared->tdFWControlEx.param2,
1484285809Sscottl                       NULL);
1485285809Sscottl}
1486285809Sscottl
1487285809Sscottl
1488285809Sscottl/*****************************************************************************
1489285809Sscottl*
1490285809Sscottl* ostiRegDumpIOCTLRsp
1491285809Sscottl*
1492285809Sscottl* Purpose:  This routine is called when Register Dump from flash IOCTL reaponse has been received.
1493285809Sscottl*           This function is used for both target and initiator.
1494285809Sscottl*
1495285809Sscottl* Parameters:
1496285809Sscottl*   tiRoot:          Pointer to driver instance
1497285809Sscottl*   payloadRsp:     Pointer to the FW download IOMB's payload.
1498285809Sscottl*
1499285809Sscottl* Return: none
1500285809Sscottl*
1501285809Sscottl*
1502285809Sscottl*
1503285809Sscottl*****************************************************************************/
1504285809Sscottl
1505285809SscottlosGLOBAL void ostiRegDumpIOCTLRsp(
1506285809Sscottl                        tiRoot_t            *tiRoot,
1507285809Sscottl                        bit32               status
1508285809Sscottl                        )
1509285809Sscottl{
1510285809Sscottl    tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1511285809Sscottl    tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1512285809Sscottl
1513285809Sscottl    TI_DBG1(("ostiRegDumpIOCTLRsp: start\n"));
1514285809Sscottl//    (tdsaAllShared->tdFWControlEx.tdFWControl)->retcode = status;
1515285809Sscottl    osti_memcpy((void *)(tdsaAllShared->tdFWControlEx.usrAddr),
1516285809Sscottl                (void *)(tdsaAllShared->tdFWControlEx.virtAddr),
1517285809Sscottl                tdsaAllShared->tdFWControlEx.len);
1518285809Sscottl
1519285809Sscottl    ostiFreeMemory(tiRoot,
1520285809Sscottl                  tdsaAllShared->tdFWControlEx.buffer,
1521285809Sscottl                  tdsaAllShared->tdFWControlEx.len);
1522285809Sscottl
1523285809Sscottl    ostiIOCTLSetSignal(tiRoot,
1524285809Sscottl                       tdsaAllShared->tdFWControlEx.param1,
1525285809Sscottl                       tdsaAllShared->tdFWControlEx.param2,
1526285809Sscottl                       NULL);
1527285809Sscottl}
1528285809Sscottl
1529285809Sscottl/*****************************************************************************
1530285809Sscottl*
1531285809Sscottl* ostiSetNVMDIOCTLRsp
1532285809Sscottl*
1533285809Sscottl* Purpose:  This routine is called for Set NVMD IOCTL reaponse has been received.
1534285809Sscottl*           This function is used for both target and initiator.
1535285809Sscottl*
1536285809Sscottl* Parameters:
1537285809Sscottl*   tiRoot:          Pointer to driver instance
1538285809Sscottl*   payloadRsp:     Pointer to the FW download IOMB's payload.
1539285809Sscottl*
1540285809Sscottl* Return: none
1541285809Sscottl*
1542285809Sscottl*
1543285809Sscottl*
1544285809Sscottl*****************************************************************************/
1545285809Sscottl
1546285809SscottlosGLOBAL void ostiSetNVMDIOCTLRsp(
1547285809Sscottl                        tiRoot_t            *tiRoot,
1548285809Sscottl                        bit32               status
1549285809Sscottl                        )
1550285809Sscottl{
1551285809Sscottl    tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1552285809Sscottl    tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1553285809Sscottl    tiIOCTLPayload_t     *agIOCTLPayload;
1554285809Sscottl
1555285809Sscottl    if(status)
1556285809Sscottl    {
1557285809Sscottl        agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1558285809Sscottl        agIOCTLPayload->Status = (bit16)status;
1559285809Sscottl    }
1560285809Sscottl
1561285809Sscottl    TI_DBG1(("ostiSetNVMDIOCTLRsp: start, status = %d\n", status));
1562285809Sscottl//    (tdsaAllShared->tdFWControlEx.tdFWControl)->retcode = status;
1563285809Sscottl    ostiFreeMemory(tiRoot,
1564285809Sscottl                       tdsaAllShared->tdFWControlEx.buffer,
1565285809Sscottl                       tdsaAllShared->tdFWControlEx.len);
1566285809Sscottl
1567285809Sscottl    ostiIOCTLSetSignal(tiRoot,
1568285809Sscottl                       tdsaAllShared->tdFWControlEx.param1,
1569285809Sscottl                       tdsaAllShared->tdFWControlEx.param2,
1570285809Sscottl                       NULL);
1571285809Sscottl}
1572285809Sscottl#ifdef SPC_ENABLE_PROFILE
1573285809Sscottl/*****************************************************************************
1574285809Sscottl*
1575285809Sscottl* ostiFWProfileIOCTLRsp
1576285809Sscottl*
1577285809Sscottl* Purpose:  This routine is called for Fw Profile IOCTL reaponse has been received.
1578285809Sscottl*           This function is used for both target and initiator.
1579285809Sscottl*
1580285809Sscottl* Parameters:
1581285809Sscottl*   tiRoot:          Pointer to driver instance
1582285809Sscottl*   status:
1583285809Sscottl*
1584285809Sscottl* Return: none
1585285809Sscottl*
1586285809Sscottl*
1587285809Sscottl*
1588285809Sscottl*****************************************************************************/
1589285809Sscottl
1590285809SscottlosGLOBAL void ostiFWProfileIOCTLRsp(
1591285809Sscottl                        tiRoot_t            *tiRoot,
1592285809Sscottl                        bit32               status,
1593285809Sscottl            bit32               len)
1594285809Sscottl{
1595285809Sscottl    tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1596285809Sscottl    tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1597285809Sscottl    tdFWProfile_t        *fwProfile;
1598285809Sscottl
1599285809Sscottl    TI_DBG1(("ostiFWProfileIOCTLRsp: start\n"));
1600285809Sscottl    fwProfile = (tdFWProfile_t *)tdsaAllShared->tdFWProfileEx.tdFWProfile;
1601285809Sscottl  //    (tdsaAllShared->tdFWControlEx.tdFWControl)->retcode = status;
1602285809Sscottl    if (status == AGSA_RC_SUCCESS)
1603285809Sscottl    {
1604285809Sscottl      if((fwProfile->cmd == STOP_TIMER_PROFILE) || (fwProfile->cmd == STOP_CODE_PROFILE))
1605285809Sscottl        {
1606285809Sscottl        osti_memcpy((void *)(fwProfile->buffer),
1607285809Sscottl                  (void *)(tdsaAllShared->tdFWProfileEx.virtAddr),
1608285809Sscottl                  len);
1609285809Sscottl
1610285809Sscottl        ostiFreeMemory(tiRoot,
1611285809Sscottl                         tdsaAllShared->tdFWProfileEx.buffer,
1612285809Sscottl                         tdsaAllShared->tdFWProfileEx.len);
1613285809Sscottl      }
1614285809Sscottl    }
1615285809Sscottl    fwProfile->status = status;
1616285809Sscottl    fwProfile->len = len;
1617285809Sscottl    ostiIOCTLSetSignal(tiRoot,
1618285809Sscottl                       tdsaAllShared->tdFWProfileEx.param1,
1619285809Sscottl                       tdsaAllShared->tdFWProfileEx.param2,
1620285809Sscottl                       NULL);
1621285809Sscottl}
1622285809Sscottl#endif
1623285809Sscottl/*****************************************************************************
1624285809Sscottl*
1625285809Sscottl* ostiGetNVMDIOCTLRsp
1626285809Sscottl*
1627285809Sscottl* Purpose:  This routine is called for Get NVMD IOCTL reaponse has been received.
1628285809Sscottl*           This function is used for both target and initiator.
1629285809Sscottl*
1630285809Sscottl* Parameters:
1631285809Sscottl*   tiRoot:          Pointer to driver instance
1632285809Sscottl*   payloadRsp:     Pointer to the FW download IOMB's payload.
1633285809Sscottl*
1634285809Sscottl* Return: none
1635285809Sscottl*
1636285809Sscottl*
1637285809Sscottl*
1638285809Sscottl*****************************************************************************/
1639285809Sscottl
1640285809SscottlosGLOBAL void ostiGetNVMDIOCTLRsp(
1641285809Sscottl                        tiRoot_t            *tiRoot,
1642285809Sscottl                        bit32               status
1643285809Sscottl                        )
1644285809Sscottl{
1645285809Sscottl    tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1646285809Sscottl    tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1647285809Sscottl    tiIOCTLPayload_t     *agIOCTLPayload;
1648285809Sscottl
1649285809Sscottl    if(status)
1650285809Sscottl    {
1651285809Sscottl        agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1652285809Sscottl        agIOCTLPayload->Status = (bit16)status;
1653285809Sscottl    }
1654285809Sscottl
1655285809Sscottl    TI_DBG1(("ostiGetNVMDIOCTLRsp: start, status = %d\n", status));
1656285809Sscottl    tdsaAllShared->NvmdResponseSet = 1;
1657285809Sscottl
1658285809Sscottl    if(tdsaAllShared->tdFWControlEx.param1 != agNULL)
1659285809Sscottl    {
1660285809Sscottl    osti_memcpy((void *)(tdsaAllShared->tdFWControlEx.usrAddr),
1661285809Sscottl                (void *)(tdsaAllShared->tdFWControlEx.virtAddr),
1662285809Sscottl                tdsaAllShared->tdFWControlEx.len);
1663285809Sscottl
1664285809Sscottl    ostiFreeMemory(tiRoot,
1665285809Sscottl                   tdsaAllShared->tdFWControlEx.buffer,
1666285809Sscottl                   tdsaAllShared->tdFWControlEx.len);
1667285809Sscottl
1668285809Sscottl    ostiIOCTLSetSignal(tiRoot,
1669285809Sscottl                       tdsaAllShared->tdFWControlEx.param1,
1670285809Sscottl                       tdsaAllShared->tdFWControlEx.param2,
1671285809Sscottl                       NULL);
1672285809Sscottl    }
1673285809Sscottl}
1674285809Sscottl
1675285809Sscottl
1676285809Sscottl/*****************************************************************************
1677285809Sscottl*
1678285809Sscottl* ostiGetPhyProfileIOCTLRsp
1679285809Sscottl*
1680285809Sscottl* Purpose:  This routine is called for phy response has been received.
1681285809Sscottl*           This function is used for both target and initiator.
1682285809Sscottl*
1683285809Sscottl* Parameters:
1684285809Sscottl*   tiRoot:          Pointer to driver instance
1685285809Sscottl*   payloadRsp:     Pointer to the IOMB's payload.
1686285809Sscottl*
1687285809Sscottl* Return: none
1688285809Sscottl*
1689285809Sscottl*
1690285809Sscottl*
1691285809Sscottl*****************************************************************************/
1692285809Sscottl
1693285809SscottlosGLOBAL void ostiGetPhyProfileIOCTLRsp(
1694285809Sscottl                        tiRoot_t            *tiRoot,
1695285809Sscottl                        bit32               status
1696285809Sscottl                        )
1697285809Sscottl{
1698285809Sscottl    tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1699285809Sscottl    tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1700285809Sscottl    tiIOCTLPayload_t     *agIOCTLPayload;
1701285809Sscottl    tdPhyCount_t     *PhyBlob = agNULL;
1702285809Sscottl    if(status)
1703285809Sscottl    {
1704285809Sscottl      agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1705285809Sscottl      agIOCTLPayload->Status = (bit16)status;
1706285809Sscottl
1707285809Sscottl      PhyBlob = (tdPhyCount_t*)&agIOCTLPayload->FunctionSpecificArea[0];
1708285809Sscottl      if(PhyBlob)
1709285809Sscottl      {
1710285809Sscottl//        PhyBlob->Phy |= 0x800;
1711285809Sscottl        if(PhyBlob->phyResetProblem == 0 )
1712285809Sscottl        {
1713285809Sscottl          PhyBlob->phyResetProblem = -1;
1714285809Sscottl        }
1715285809Sscottl        TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->Phy                   0x%x\n",PhyBlob->Phy));
1716285809Sscottl        TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->BW_rx                 0x%x\n",PhyBlob->BW_rx));
1717285809Sscottl        TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->BW_tx                 0x%x\n",PhyBlob->BW_tx));
1718285809Sscottl        TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->InvalidDword          0x%x\n",PhyBlob->InvalidDword));
1719285809Sscottl        TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->runningDisparityError 0x%x\n",PhyBlob->runningDisparityError));
1720285809Sscottl        TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->codeViolation         0x%x\n",PhyBlob->codeViolation));
1721285809Sscottl        TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->phyResetProblem       0x%x\n",PhyBlob->phyResetProblem));
1722285809Sscottl        TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->inboundCRCError       0x%x\n",PhyBlob->inboundCRCError));
1723285809Sscottl
1724285809Sscottl      }
1725285809Sscottl
1726285809Sscottl
1727285809Sscottl    }
1728285809Sscottl
1729285809Sscottl    TI_DBG1(("ostiGetPhyProfileIOCTLRsp: start, status = %d\n", status));
1730285809Sscottl    TI_DBG1(("ostiGetPhyProfileIOCTLRsp: start, len = %d %p %p\n", tdsaAllShared->tdFWControlEx.len,tdsaAllShared->tdFWControlEx.usrAddr,tdsaAllShared->tdFWControlEx.virtAddr));
1731285809Sscottl
1732285809Sscottl//    osti_memcpy((void *)(tdsaAllShared->tdFWControlEx.usrAddr),
1733285809Sscottl//                (void *)(tdsaAllShared->tdFWControlEx.virtAddr),
1734285809Sscottl//                 tdsaAllShared->tdFWControlEx.len);
1735285809Sscottl
1736285809Sscottl    ostiFreeMemory(tiRoot,
1737285809Sscottl                   tdsaAllShared->tdFWControlEx.buffer,
1738285809Sscottl                   tdsaAllShared->tdFWControlEx.len);
1739285809Sscottl
1740285809Sscottl    ostiIOCTLSetSignal(tiRoot,
1741285809Sscottl                       tdsaAllShared->tdFWControlEx.param1,
1742285809Sscottl                       tdsaAllShared->tdFWControlEx.param2,
1743285809Sscottl                       NULL);
1744285809Sscottl}
1745285809Sscottl
1746285809Sscottl
1747285809Sscottl/*****************************************************************************
1748285809Sscottl*
1749285809Sscottl* ostiGenEventIOCTLRsp
1750285809Sscottl*
1751285809Sscottl* Purpose:  This routine is called when General Event happened while waiting for IOCTL response.
1752285809Sscottl*           This function is used for both target and initiator.
1753285809Sscottl*
1754285809Sscottl* Parameters:
1755285809Sscottl*   tiRoot:          Pointer to driver instance
1756285809Sscottl*   payloadRsp:     Pointer to the FW download IOMB's payload.
1757285809Sscottl*
1758285809Sscottl* Return: none
1759285809Sscottl*
1760285809Sscottl*
1761285809Sscottl*
1762285809Sscottl*****************************************************************************/
1763285809Sscottl
1764285809SscottlosGLOBAL void ostiGenEventIOCTLRsp(
1765285809Sscottl                        tiRoot_t            *tiRoot,
1766285809Sscottl                        bit32               status
1767285809Sscottl                        )
1768285809Sscottl{
1769285809Sscottl    tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1770285809Sscottl    tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1771285809Sscottl    tiIOCTLPayload_t     *agIOCTLPayload;
1772285809Sscottl
1773285809Sscottl    TI_DBG1(("ostiGenEventIOCTLRsp: start\n"));
1774285809Sscottl
1775285809Sscottl    if(tdsaAllShared->tdFWControlEx.inProgress)  /*Free only if our IOCTL is in progress*/
1776285809Sscottl    {
1777285809Sscottl      agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1778285809Sscottl      agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1779285809Sscottl      (tdsaAllShared->tdFWControlEx.tdFWControl)->retcode = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1780285809Sscottl
1781285809Sscottl      ostiFreeMemory(tiRoot,
1782285809Sscottl                     tdsaAllShared->tdFWControlEx.buffer,
1783285809Sscottl                     tdsaAllShared->tdFWControlEx.len);
1784285809Sscottl
1785285809Sscottl      ostiIOCTLSetSignal(tiRoot,
1786285809Sscottl                         tdsaAllShared->tdFWControlEx.param1,
1787285809Sscottl                         tdsaAllShared->tdFWControlEx.param2,
1788285809Sscottl                         NULL);
1789285809Sscottl      tdsaAllShared->tdFWControlEx.inProgress = 0;
1790285809Sscottl    }
1791285809Sscottl#ifdef SPC_ENABLE_PROFILE
1792285809Sscottl    if(tdsaAllShared->tdFWProfileEx.inProgress)
1793285809Sscottl    {
1794285809Sscottl      agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWProfileEx.payload);
1795285809Sscottl      agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1796285809Sscottl      if(tdsaAllShared->tdFWProfileEx.virtAddr != NULL)  /*Free only if our IOCTL is in progress*/
1797285809Sscottl      {
1798285809Sscottl        ostiFreeMemory(tiRoot,
1799285809Sscottl                       tdsaAllShared->tdFWProfileEx.buffer,
1800285809Sscottl                       tdsaAllShared->tdFWProfileEx.len);
1801285809Sscottl        tdsaAllShared->tdFWProfileEx.virtAddr = NULL;
1802285809Sscottl      }
1803285809Sscottl      ostiIOCTLSetSignal(tiRoot,
1804285809Sscottl                         tdsaAllShared->tdFWProfileEx.param1,
1805285809Sscottl                         tdsaAllShared->tdFWProfileEx.param2,
1806285809Sscottl                         NULL);
1807285809Sscottl      tdsaAllShared->tdFWProfileEx.inProgress = 0;
1808285809Sscottl
1809285809Sscottl    }
1810285809Sscottl#endif /*SPC_ENABLE_PROFILE*/
1811285809Sscottl
1812285809Sscottl}
1813285809Sscottl
1814285809SscottlosGLOBAL void
1815285809SscottlostiGetDeviceInfoIOCTLRsp(
1816285809Sscottl                        tiRoot_t    *tiRoot,
1817285809Sscottl                        bit32        status,
1818285809Sscottl                        void        *param
1819285809Sscottl                        )
1820285809Sscottl{
1821285809Sscottl    tdsaRoot_t             *tdsaRoot       = (tdsaRoot_t *) tiRoot->tdData;
1822285809Sscottl    tdsaContext_t          *tdsaAllShared  = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1823285809Sscottl    tiIOCTLPayload_t       *agIOCTLPayload = agNULL;
1824285809Sscottl    tdDeviceInfoPayload_t  *pTDDeviceInfo  = agNULL;
1825285809Sscottl    agsaDeviceInfo_t       *pSADeviceInfo  = agNULL;
1826285809Sscottl
1827285809Sscottl    TI_DBG1(("ostiGetDeviceInfoIOCTLRsp: start\n"));
1828285809Sscottl
1829285809Sscottl    agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1830285809Sscottl    pSADeviceInfo = (agsaDeviceInfo_t*)param;
1831285809Sscottl    pTDDeviceInfo = (tdDeviceInfoPayload_t*)agIOCTLPayload->FunctionSpecificArea;
1832285809Sscottl
1833285809Sscottl    if (pSADeviceInfo != agNULL)
1834285809Sscottl    {
1835285809Sscottl      /* fill the device information in IOCTL payload */
1836285809Sscottl      osti_memcpy(&pTDDeviceInfo->devInfo.sasAddressHi, pSADeviceInfo->sasAddressHi, sizeof(bit32));
1837285809Sscottl      osti_memcpy(&pTDDeviceInfo->devInfo.sasAddressLo, pSADeviceInfo->sasAddressLo, sizeof(bit32));
1838285809Sscottl
1839285809Sscottl      pTDDeviceInfo->devInfo.sasAddressHi = DMA_BEBIT32_TO_BIT32(pTDDeviceInfo->devInfo.sasAddressHi);
1840285809Sscottl      pTDDeviceInfo->devInfo.sasAddressLo = DMA_BEBIT32_TO_BIT32(pTDDeviceInfo->devInfo.sasAddressLo);
1841285809Sscottl
1842285809Sscottl      pTDDeviceInfo->devInfo.deviceType = (pSADeviceInfo->devType_S_Rate & 0x30) >> 4;
1843285809Sscottl      pTDDeviceInfo->devInfo.linkRate   = pSADeviceInfo->devType_S_Rate & 0x0F;
1844285809Sscottl
1845285809Sscottl      agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
1846285809Sscottl    }
1847285809Sscottl    else
1848285809Sscottl    {
1849285809Sscottl      agIOCTLPayload->Status = IOCTL_ERR_STATUS_INVALID_DEVICE;
1850285809Sscottl    }
1851285809Sscottl
1852285809Sscottl    if(tdsaAllShared->tdFWControlEx.inProgress)  /*Free only if our IOCTL is in progress*/
1853285809Sscottl    {
1854285809Sscottl      ostiIOCTLSetSignal(tiRoot,
1855285809Sscottl                         tdsaAllShared->tdFWControlEx.param1,
1856285809Sscottl                         tdsaAllShared->tdFWControlEx.param2,
1857285809Sscottl                         NULL);
1858285809Sscottl      tdsaAllShared->tdFWControlEx.inProgress = 0;
1859285809Sscottl    }
1860285809Sscottl}
1861285809Sscottl
1862285809Sscottl
1863285809Sscottl#ifdef INITIATOR_DRIVER
1864285809SscottlosGLOBAL void
1865285809SscottlostiGetIoErrorStatsIOCTLRsp(
1866285809Sscottl                        tiRoot_t    *tiRoot,
1867285809Sscottl                        bit32        status,
1868285809Sscottl                        void        *param
1869285809Sscottl                        )
1870285809Sscottl{
1871285809Sscottl    tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
1872285809Sscottl    tdsaContext_t               *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1873285809Sscottl    itdsaIni_t                  *Initiator       = (itdsaIni_t *)tdsaAllShared->itdsaIni;
1874285809Sscottl    tiIOCTLPayload_t            *agIOCTLPayload  = agNULL;
1875285809Sscottl    tdIoErrorStatisticPayload_t *pIoErrorPayload = agNULL;
1876285809Sscottl    agsaIOErrorEventStats_t     *pIoErrorCount   = agNULL;
1877285809Sscottl
1878285809Sscottl    OS_ASSERT(sizeof(agsaIOErrorEventStats_t) == sizeof(tdIoErrorEventStatisticIOCTL_t), "agsaIOErrorEventStats_t tdIoErrorEventStatisticIOCTL_t\n");
1879285809Sscottl    TI_DBG1(("ostiGetIoErrorStatsIOCTLRsp: start\n"));
1880285809Sscottl
1881285809Sscottl    agIOCTLPayload  = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1882285809Sscottl    pIoErrorPayload = (tdIoErrorStatisticPayload_t*)agIOCTLPayload->FunctionSpecificArea;
1883285809Sscottl    pIoErrorCount   = (agsaIOErrorEventStats_t*)param;
1884285809Sscottl
1885285809Sscottl    osti_memcpy(&pIoErrorPayload->IoError, pIoErrorCount, sizeof(agsaIOErrorEventStats_t));
1886285809Sscottl    /*copy SCSI status and sense key count from OS layer to TD layer*/
1887285809Sscottl    osti_memcpy(&pIoErrorPayload->ScsiStatusCounter, &Initiator->ScsiStatusCounts, sizeof(tdSCSIStatusCount_t));
1888285809Sscottl    osti_memcpy(&pIoErrorPayload->SenseKeyCounter, &Initiator->SenseKeyCounter, sizeof(tdSenseKeyCount_t));
1889285809Sscottl    if (pIoErrorPayload->flag)
1890285809Sscottl    {
1891285809Sscottl      osti_memset(&Initiator->ScsiStatusCounts, 0,sizeof(tdSCSIStatusCount_t) );
1892285809Sscottl      osti_memset(&Initiator->SenseKeyCounter, 0,sizeof(tdSenseKeyCount_t) );
1893285809Sscottl    }
1894285809Sscottl
1895285809Sscottl    agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
1896285809Sscottl}
1897285809Sscottl#endif /* INITIATOR_DRIVER */
1898285809Sscottl
1899285809SscottlosGLOBAL void
1900285809SscottlostiGetIoEventStatsIOCTLRsp(
1901285809Sscottl                        tiRoot_t    *tiRoot,
1902285809Sscottl                        bit32        status,
1903285809Sscottl                        void        *param
1904285809Sscottl                        )
1905285809Sscottl{
1906285809Sscottl    tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
1907285809Sscottl    tdsaContext_t               *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1908285809Sscottl    tiIOCTLPayload_t            *agIOCTLPayload  = agNULL;
1909285809Sscottl    tdIoEventStatisticPayload_t *pIoEventPayload = agNULL;
1910285809Sscottl    agsaIOErrorEventStats_t     *pIoEventCount   = agNULL;
1911285809Sscottl
1912285809Sscottl    TI_DBG1(("ostiGetIoEventStatsIOCTLRsp: start\n"));
1913285809Sscottl
1914285809Sscottl    agIOCTLPayload  = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1915285809Sscottl    pIoEventPayload = (tdIoEventStatisticPayload_t*)agIOCTLPayload->FunctionSpecificArea;
1916285809Sscottl    pIoEventCount   = (agsaIOErrorEventStats_t*)param;
1917285809Sscottl
1918285809Sscottl    osti_memcpy(&pIoEventPayload->IoEvent, pIoEventCount, sizeof(agsaIOErrorEventStats_t));
1919285809Sscottl
1920285809Sscottl    agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
1921285809Sscottl}
1922285809Sscottl
1923285809SscottlosGLOBAL void
1924285809SscottlostiGetForensicDataIOCTLRsp(
1925285809Sscottl                        tiRoot_t    *tiRoot,
1926285809Sscottl                        bit32        status,
1927285809Sscottl                        void        *param
1928285809Sscottl                        )
1929285809Sscottl{
1930285809Sscottl  tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
1931285809Sscottl  tdsaContext_t               *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1932285809Sscottl  tiIOCTLPayload_t            *agIOCTLPayload  = agNULL;
1933285809Sscottl  tdForensicDataPayload_t     *pForensicDataPayload = agNULL;
1934285809Sscottl  agsaForensicData_t          *pForensicData   = agNULL;
1935285809Sscottl
1936285809Sscottl  TI_DBG3(("ostiGetForensicDataIOCTLRsp: start, status = %d\n", status));
1937285809Sscottl
1938285809Sscottl  agIOCTLPayload  = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1939285809Sscottl  pForensicDataPayload = (tdForensicDataPayload_t*)agIOCTLPayload->FunctionSpecificArea;
1940285809Sscottl  pForensicData   = (agsaForensicData_t*)param;
1941285809Sscottl
1942285809Sscottl  if (agNULL == agIOCTLPayload)
1943285809Sscottl  {
1944285809Sscottl    return;
1945285809Sscottl  }
1946285809Sscottl
1947285809Sscottl  if (FORENSIC_DATA_TYPE_CHECK_FATAL == pForensicData->DataType)
1948285809Sscottl  {
1949285809Sscottl    agIOCTLPayload->Status = (bit16)status;
1950285809Sscottl    return;
1951285809Sscottl  }
1952285809Sscottl
1953285809Sscottl  if (status == AGSA_RC_SUCCESS)
1954285809Sscottl  {
1955285809Sscottl    switch (pForensicData->DataType)
1956285809Sscottl    {
1957285809Sscottl      case FORENSIC_DATA_TYPE_NON_FATAL:
1958285809Sscottl      case FORENSIC_DATA_TYPE_FATAL:
1959285809Sscottl           pForensicDataPayload->dataBuffer.directOffset = pForensicData->BufferType.dataBuf.directOffset;
1960285809Sscottl           pForensicDataPayload->dataBuffer.readLen      = pForensicData->BufferType.dataBuf.readLen;
1961285809Sscottl           break;
1962285809Sscottl      case FORENSIC_DATA_TYPE_GSM_SPACE:
1963285809Sscottl           pForensicDataPayload->gsmBuffer.directOffset  = pForensicData->BufferType.gsmBuf.directOffset;
1964285809Sscottl	   pForensicDataPayload->gsmBuffer.readLen 	 = pForensicData->BufferType.gsmBuf.readLen;
1965285809Sscottl           break;
1966285809Sscottl
1967285809Sscottl      case FORENSIC_DATA_TYPE_QUEUE:
1968285809Sscottl           break;
1969285809Sscottl
1970285809Sscottl      default:
1971285809Sscottl           TI_DBG1(("ostiGetForensicDataIOCTLRsp: forensic data type error %d\n", pForensicData->DataType));
1972285809Sscottl           break;
1973285809Sscottl    }
1974285809Sscottl    agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
1975285809Sscottl  }
1976285809Sscottl  else if(status == IOCTL_ERROR_NO_FATAL_ERROR)
1977285809Sscottl  {
1978285809Sscottl    agIOCTLPayload->Status = (bit16)status;
1979285809Sscottl  }
1980285809Sscottl  else
1981285809Sscottl  {
1982285809Sscottl    agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1983285809Sscottl  }
1984285809Sscottl
1985285809Sscottl  /*Free only if our IOCTL is in progress*/
1986285809Sscottl  if(tdsaAllShared->tdFWControlEx.inProgress)
1987285809Sscottl  {
1988285809Sscottl    TI_DBG3(("ostiGetForensicDataIOCTLRsp: Waiting for the signal \n"));
1989285809Sscottl    ostiIOCTLSetSignal(tiRoot,
1990285809Sscottl          tdsaAllShared->tdFWControlEx.param1,
1991285809Sscottl          tdsaAllShared->tdFWControlEx.param2,
1992285809Sscottl          NULL);
1993285809Sscottl    TI_DBG3(("ostiGetForensicDataIOCTLRsp: Signal wait completed \n"));
1994285809Sscottl    tdsaAllShared->tdFWControlEx.inProgress = 0;
1995285809Sscottl  }
1996285809Sscottl}
1997285809Sscottl
1998285809Sscottl/*****************************************************************************
1999285809Sscottl*
2000285809Sscottl* tdsaRegDumpGetIoctl
2001285809Sscottl*
2002285809Sscottl* Purpose:  This routine is called to get Register Dump information.
2003285809Sscottl*           This function is used for both target and initiator.
2004285809Sscottl*
2005285809Sscottl* Parameters:
2006285809Sscottl*   tiRoot:         Pointer to driver instance
2007285809Sscottl*   agIOCTLPayload: Pointer to the IOCTL payload.
2008285809Sscottl*   agParam1:       Pointer to pass context handle for IOCTL DMA operation
2009285809Sscottl*   agParam2:       Pointer to pass context handle for IOCTL DMA operation
2010285809Sscottl*   agParam3:       Pointer to pass context handle for IOCTL DMA operation
2011285809Sscottl*
2012285809Sscottl* Return:
2013285809Sscottl*
2014285809Sscottl*   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
2015285809Sscottl*   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
2016285809Sscottl*                             Detail error code is function specific and
2017285809Sscottl*                             defined by the specific IOCTL function.
2018285809Sscottl*   IOCTL_CALL_PENDING        This request is asynchronous and completed
2019285809Sscottl*                             in some other context.
2020285809Sscottl*   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
2021285809Sscottl*
2022285809Sscottl*
2023285809Sscottl*****************************************************************************/
2024285809SscottlosGLOBAL bit32
2025285809SscottltdsaRegDumpGetIoctl(
2026285809Sscottl                tiRoot_t            *tiRoot,
2027285809Sscottl                tiIOCTLPayload_t    *agIOCTLPayload,
2028285809Sscottl                void                *agParam1,
2029285809Sscottl                void                *agParam2,
2030285809Sscottl                void                *agParam3
2031285809Sscottl                )
2032285809Sscottl{
2033285809Sscottl    tdsaRoot_t    *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
2034285809Sscottl    tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2035285809Sscottl    agsaRoot_t    *agRoot = &(tdsaAllShared->agRootInt);
2036285809Sscottl//    agsaControllerStatus_t RegDump;
2037285809Sscottl    bit32               Offset = 0;
2038285809Sscottl    bit32               RequestLength = 0;  /* user request on how much data to pass to application */
2039285809Sscottl    agsaRegDumpInfo_t   regDumpInfo;
2040285809Sscottl    void                *buffer = agNULL;
2041285809Sscottl    void                *osMemHandle = agNULL;
2042285809Sscottl    bit32               status = IOCTL_CALL_SUCCESS;
2043285809Sscottl    bit32               CoreDumpLength = 16384; /* change it once data is available */
2044285809Sscottl    bit32               EventLogOffset = 65536;
2045285809Sscottl
2046285809Sscottl    ///saGetControllerStatus(agRoot, &RegDump);
2047285809Sscottl    /* length of FSA as provided by application */
2048285809Sscottl    RequestLength = agIOCTLPayload->Length;
2049285809Sscottl///    FunctionSpecificOffset = 0; /* Offset into the FunctionSpecificArea of payload */
2050285809Sscottl    /* offset into core dump that was passed from application */
2051285809Sscottl    Offset = agIOCTLPayload->Reserved;
2052285809Sscottl
2053285809Sscottl  if((CoreDumpLength <= Offset)&&
2054285809Sscottl    (agIOCTLPayload->MinorFunction != IOCTL_MN_FW_GET_EVENT_FLASH_LOG1)&&
2055285809Sscottl    (agIOCTLPayload->MinorFunction != IOCTL_MN_FW_GET_EVENT_FLASH_LOG2))
2056285809Sscottl  {
2057285809Sscottl      agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
2058285809Sscottl      agIOCTLPayload->Length = 0;
2059285809Sscottl      status=IOCTL_CALL_SUCCESS;
2060285809Sscottl      return status;
2061285809Sscottl    }
2062285809Sscottl    regDumpInfo.regDumpOffset = Offset;
2063285809Sscottl    agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
2064285809Sscottl    /* dump either aap1 or iop registers */
2065285809Sscottl    switch(agIOCTLPayload->MinorFunction){
2066285809Sscottl
2067285809Sscottl    /*Coredump*/
2068285809Sscottl    case IOCTL_MN_FW_GET_CORE_DUMP_AAP1:
2069285809Sscottl            //CoreDumpBAROffset = RegDump.fatalErrorInfo.regDumpOffset0;    /* get this from mpi config table */
2070285809Sscottl            //CoreDumpLength = RegDump.fatalErrorInfo.regDumpLen0;
2071285809Sscottl            /*changes for added Call back*/
2072285809Sscottl            tdsaAllShared->tdFWControlEx.param1 = agParam1;
2073285809Sscottl            tdsaAllShared->tdFWControlEx.param2 = agParam2;
2074285809Sscottl            regDumpInfo.regDumpSrc = 0;
2075285809Sscottl            regDumpInfo.regDumpNum = 0;
2076285809Sscottl            regDumpInfo.directLen = RequestLength;
2077285809Sscottl            regDumpInfo.directData = &agIOCTLPayload->FunctionSpecificArea[0];
2078285809Sscottl            /*changes for added Call back*/
2079285809Sscottl            //status = IOCTL_CALL_SUCCESS;
2080285809Sscottl            tdsaAllShared->tdFWControlEx.inProgress = 1;
2081285809Sscottl            status = IOCTL_CALL_PENDING;
2082285809Sscottl            break;
2083285809Sscottl    case IOCTL_MN_FW_GET_CORE_DUMP_IOP:
2084285809Sscottl        //CoreDumpBAROffset = RegDump.fatalErrorInfo.regDumpOffset1;    /* get this from mpi config table */
2085285809Sscottl        //CoreDumpLength = RegDump.fatalErrorInfo.regDumpLen1;
2086285809Sscottl        /*changes for added Call back*/
2087285809Sscottl        tdsaAllShared->tdFWControlEx.param1 = agParam1;
2088285809Sscottl        tdsaAllShared->tdFWControlEx.param2 = agParam2;
2089285809Sscottl        regDumpInfo.regDumpSrc = 0;
2090285809Sscottl        regDumpInfo.regDumpNum = 1;
2091285809Sscottl        regDumpInfo.directLen = RequestLength;
2092285809Sscottl        regDumpInfo.directData = &agIOCTLPayload->FunctionSpecificArea[0];
2093285809Sscottl        /*changes for added Call back*/
2094285809Sscottl        //status = IOCTL_CALL_SUCCESS;
2095285809Sscottl        tdsaAllShared->tdFWControlEx.inProgress = 1;
2096285809Sscottl        status = IOCTL_CALL_PENDING;
2097285809Sscottl        break;
2098285809Sscottl    case IOCTL_MN_FW_GET_CORE_DUMP_FLASH_AAP1:
2099285809Sscottl        regDumpInfo.regDumpSrc = 1;
2100285809Sscottl        regDumpInfo.regDumpNum = 0;
2101285809Sscottl        if(RequestLength != 0)
2102285809Sscottl        {
2103285809Sscottl            if(ostiAllocMemory( tiRoot,
2104285809Sscottl                    &osMemHandle,
2105285809Sscottl                    (void **)&buffer,
2106285809Sscottl                    &(regDumpInfo.indirectAddrUpper32),
2107285809Sscottl                    &(regDumpInfo.indirectAddrLower32),
2108285809Sscottl                    8,
2109285809Sscottl                    RequestLength,
2110285809Sscottl                    agFALSE))
2111285809Sscottl                return IOCTL_CALL_FAIL;
2112285809Sscottl        }
2113285809Sscottl        osti_memset((void *)buffer, 0, RequestLength);
2114285809Sscottl        regDumpInfo.indirectLen = RequestLength;
2115285809Sscottl
2116285809Sscottl        // use FW control place in shared structure to keep the neccesary information
2117285809Sscottl        tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
2118285809Sscottl        tdsaAllShared->tdFWControlEx.virtAddr = buffer;
2119285809Sscottl        tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2120285809Sscottl        tdsaAllShared->tdFWControlEx.len = RequestLength;
2121285809Sscottl        tdsaAllShared->tdFWControlEx.param1 = agParam1;
2122285809Sscottl        tdsaAllShared->tdFWControlEx.param2 = agParam2;
2123285809Sscottl        tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2124285809Sscottl        tdsaAllShared->tdFWControlEx.inProgress = 1;
2125285809Sscottl        status = IOCTL_CALL_PENDING;
2126285809Sscottl        break;
2127285809Sscottl    case IOCTL_MN_FW_GET_CORE_DUMP_FLASH_IOP:
2128285809Sscottl        regDumpInfo.regDumpSrc = 1;
2129285809Sscottl        regDumpInfo.regDumpNum = 1;
2130285809Sscottl        if(RequestLength != 0)
2131285809Sscottl        {
2132285809Sscottl            if(ostiAllocMemory( tiRoot,
2133285809Sscottl                    &osMemHandle,
2134285809Sscottl                    (void **)&buffer,
2135285809Sscottl                    &(regDumpInfo.indirectAddrUpper32),
2136285809Sscottl                    &(regDumpInfo.indirectAddrLower32),
2137285809Sscottl                    8,
2138285809Sscottl                    RequestLength,
2139285809Sscottl                    agFALSE))
2140285809Sscottl                return IOCTL_CALL_FAIL;
2141285809Sscottl        }
2142285809Sscottl        osti_memset((void *)buffer, 0, RequestLength);
2143285809Sscottl        regDumpInfo.indirectLen = RequestLength;
2144285809Sscottl
2145285809Sscottl        // use FW control place in shared structure to keep the neccesary information
2146285809Sscottl        tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
2147285809Sscottl        tdsaAllShared->tdFWControlEx.virtAddr = buffer;
2148285809Sscottl        tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2149285809Sscottl        tdsaAllShared->tdFWControlEx.len = RequestLength;
2150285809Sscottl        tdsaAllShared->tdFWControlEx.param1 = agParam1;
2151285809Sscottl        tdsaAllShared->tdFWControlEx.param2 = agParam2;
2152285809Sscottl        tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2153285809Sscottl        tdsaAllShared->tdFWControlEx.inProgress = 1;
2154285809Sscottl        status = IOCTL_CALL_PENDING;
2155285809Sscottl        break;
2156285809Sscottl    /*EventLog from Flash*/
2157285809Sscottl    case IOCTL_MN_FW_GET_EVENT_FLASH_LOG1:      //aap1 Eventlog
2158285809Sscottl      if(CoreDumpLength + EventLogOffset <= Offset)
2159285809Sscottl      {
2160285809Sscottl        agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
2161285809Sscottl        agIOCTLPayload->Length = 0;
2162285809Sscottl        status=IOCTL_CALL_SUCCESS;
2163285809Sscottl        return status;
2164285809Sscottl      }
2165285809Sscottl      regDumpInfo.regDumpSrc = 1;
2166285809Sscottl      regDumpInfo.regDumpNum = 0;
2167285809Sscottl      if(RequestLength != 0)
2168285809Sscottl      {
2169285809Sscottl          if(ostiAllocMemory( tiRoot,
2170285809Sscottl                  &osMemHandle,
2171285809Sscottl                  (void **)&buffer,
2172285809Sscottl                  &(regDumpInfo.indirectAddrUpper32),
2173285809Sscottl                  &(regDumpInfo.indirectAddrLower32),
2174285809Sscottl                  8,
2175285809Sscottl                  RequestLength,
2176285809Sscottl                  agFALSE))
2177285809Sscottl              return IOCTL_CALL_FAIL;
2178285809Sscottl      }
2179285809Sscottl      osti_memset((void *)buffer, 0, RequestLength);
2180285809Sscottl      regDumpInfo.indirectLen = RequestLength;
2181285809Sscottl
2182285809Sscottl      // use FW control place in shared structure to keep the neccesary information
2183285809Sscottl      tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
2184285809Sscottl      tdsaAllShared->tdFWControlEx.virtAddr = buffer;
2185285809Sscottl      tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2186285809Sscottl      tdsaAllShared->tdFWControlEx.len = RequestLength;
2187285809Sscottl      tdsaAllShared->tdFWControlEx.param1 = agParam1;
2188285809Sscottl      tdsaAllShared->tdFWControlEx.param2 = agParam2;
2189285809Sscottl      tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2190285809Sscottl      tdsaAllShared->tdFWControlEx.inProgress = 1;
2191285809Sscottl      status = IOCTL_CALL_PENDING;
2192285809Sscottl      break;
2193285809Sscottl    case IOCTL_MN_FW_GET_EVENT_FLASH_LOG2:      //iop Eventlog
2194285809Sscottl      if(CoreDumpLength + EventLogOffset <= Offset)
2195285809Sscottl      {
2196285809Sscottl        agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
2197285809Sscottl        agIOCTLPayload->Length = 0;
2198285809Sscottl        status=IOCTL_CALL_SUCCESS;
2199285809Sscottl        return status;
2200285809Sscottl      }
2201285809Sscottl      regDumpInfo.regDumpSrc = 1;
2202285809Sscottl      regDumpInfo.regDumpNum = 1;
2203285809Sscottl      if(RequestLength != 0)
2204285809Sscottl      {
2205285809Sscottl          if(ostiAllocMemory( tiRoot,
2206285809Sscottl                  &osMemHandle,
2207285809Sscottl                  (void **)&buffer,
2208285809Sscottl                  &(regDumpInfo.indirectAddrUpper32),
2209285809Sscottl                  &(regDumpInfo.indirectAddrLower32),
2210285809Sscottl                  8,
2211285809Sscottl                  RequestLength,
2212285809Sscottl                  agFALSE))
2213285809Sscottl              return IOCTL_CALL_FAIL;
2214285809Sscottl      }
2215285809Sscottl      osti_memset((void *)buffer, 0, RequestLength);
2216285809Sscottl      regDumpInfo.indirectLen = RequestLength;
2217285809Sscottl
2218285809Sscottl      // use FW control place in shared structure to keep the neccesary information
2219285809Sscottl      tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
2220285809Sscottl      tdsaAllShared->tdFWControlEx.virtAddr = buffer;
2221285809Sscottl      tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2222285809Sscottl      tdsaAllShared->tdFWControlEx.len = RequestLength;
2223285809Sscottl      tdsaAllShared->tdFWControlEx.param1 = agParam1;
2224285809Sscottl      tdsaAllShared->tdFWControlEx.param2 = agParam2;
2225285809Sscottl      tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2226285809Sscottl      tdsaAllShared->tdFWControlEx.inProgress = 1;
2227285809Sscottl      status = IOCTL_CALL_PENDING;
2228285809Sscottl      break;
2229285809Sscottl  default:
2230285809Sscottl      status = IOCTL_CALL_INVALID_CODE;
2231285809Sscottl      TI_DBG1(("tiCOMMgntIOCTL: ERROR: Wrong IOCTL code %d\n", agIOCTLPayload->MinorFunction));
2232285809Sscottl      break;
2233285809Sscottl    }
2234285809Sscottl    if(saGetRegisterDump(agRoot, agNULL, 0, &regDumpInfo) != AGSA_RC_SUCCESS)
2235285809Sscottl    {
2236285809Sscottl        status = IOCTL_CALL_FAIL;
2237285809Sscottl        agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
2238285809Sscottl    }
2239285809Sscottl
2240285809Sscottl    return status;
2241285809Sscottl}
2242285809Sscottl
2243285809SscottlosGLOBAL void
2244285809SscottlostiCOMMgntVPDSetIOCTLRsp(
2245285809Sscottl                          tiRoot_t            *tiRoot,
2246285809Sscottl                          bit32               status
2247285809Sscottl                          )
2248285809Sscottl{
2249285809Sscottl    tdsaRoot_t    *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
2250285809Sscottl    tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2251285809Sscottl//    agsaRoot_t    *agRoot = &(tdsaAllShared->agRootInt);
2252285809Sscottl
2253285809Sscottl    TI_DBG1(("ostiCOMMgntVPDSetIOCTLRsp: start\n"));
2254285809Sscottl    (tdsaAllShared->tdFWControlEx.tdFWControl)->retcode = status;
2255285809Sscottl
2256285809Sscottl    ostiFreeMemory(tiRoot,
2257285809Sscottl                   tdsaAllShared->tdFWControlEx.buffer,
2258285809Sscottl                   tdsaAllShared->tdFWControlEx.len);
2259285809Sscottl
2260285809Sscottl    ostiIOCTLSetSignal(tiRoot, tdsaAllShared->tdFWControlEx.param1,
2261285809Sscottl                               tdsaAllShared->tdFWControlEx.param2,
2262285809Sscottl                               NULL);
2263285809Sscottl}
2264285809Sscottl
2265285809Sscottl/*****************************************************************************
2266285809Sscottl*
2267285809Sscottl* tdsaNVMDSetIoctl
2268285809Sscottl*
2269285809Sscottl* Purpose:  This routine is called to set Config. SEEPROM information.
2270285809Sscottl*           This function is used for both target and initiator.
2271285809Sscottl*
2272285809Sscottl* Parameters:
2273285809Sscottl*   tiRoot:         Pointer to driver instance
2274285809Sscottl*   agIOCTLPayload: Pointer to the IOCTL payload.
2275285809Sscottl*   agParam1:       Pointer to pass context handle for IOCTL DMA operation
2276285809Sscottl*   agParam2:       Pointer to pass context handle for IOCTL DMA operation
2277285809Sscottl*   agParam3:       Pointer to pass context handle for IOCTL DMA operation
2278285809Sscottl*
2279285809Sscottl* Return:
2280285809Sscottl*
2281285809Sscottl*   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
2282285809Sscottl*   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
2283285809Sscottl*                             Detail error code is function specific and
2284285809Sscottl*                             defined by the specific IOCTL function.
2285285809Sscottl*   IOCTL_CALL_PENDING        This request is asynchronous and completed
2286285809Sscottl*                             in some other context.
2287285809Sscottl*   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
2288285809Sscottl*
2289285809Sscottl*
2290285809Sscottl*****************************************************************************/
2291285809SscottlosGLOBAL bit32
2292285809SscottltdsaNVMDSetIoctl(
2293285809Sscottl                tiRoot_t            *tiRoot,
2294285809Sscottl                tiIOCTLPayload_t    *agIOCTLPayload,
2295285809Sscottl                void                *agParam1,
2296285809Sscottl                void                *agParam2,
2297285809Sscottl                void                *agParam3
2298285809Sscottl                )
2299285809Sscottl{
2300285809Sscottl  bit32                  RequestLength = 0;
2301285809Sscottl  bit32                  bufAddrUpper = 0;
2302285809Sscottl  bit32                  bufAddrLower = 0;
2303285809Sscottl  tdsaRoot_t             *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
2304285809Sscottl  tdsaContext_t          *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2305285809Sscottl  agsaRoot_t             *agRoot = &(tdsaAllShared->agRootInt);
2306285809Sscottl  void                   *buffer = agNULL;
2307285809Sscottl  void                   *osMemHandle = agNULL;
2308285809Sscottl  bit32                  status = IOCTL_CALL_SUCCESS;
2309285809Sscottl  agsaNVMDData_t         nvmdInfo;
2310285809Sscottl
2311285809Sscottl
2312285809Sscottl  TI_DBG2(("tdsaNVMDSetIoctl: start\n"));
2313285809Sscottl
2314285809Sscottl  RequestLength = agIOCTLPayload->Length;
2315285809Sscottl
2316285809Sscottl  osti_memset(&nvmdInfo, 0, sizeof(agsaNVMDData_t));
2317285809Sscottl
2318285809Sscottl  switch(agIOCTLPayload->MinorFunction)
2319285809Sscottl  {
2320285809Sscottl    case IOCTL_MN_NVMD_SET_CONFIG:
2321285809Sscottl
2322285809Sscottl      //nvmdInfo.NVMDevice = 1;
2323285809Sscottl      nvmdInfo.NVMDevice = *((bit8*)agParam3);
2324285809Sscottl      nvmdInfo.signature = 0xFEDCBA98;
2325285809Sscottl      nvmdInfo.dataOffsetAddress = agIOCTLPayload->Reserved;
2326285809Sscottl      nvmdInfo.indirectPayload = 1;
2327285809Sscottl      nvmdInfo.indirectLen = RequestLength;
2328285809Sscottl
2329285809Sscottl      if (nvmdInfo.NVMDevice == 0) {
2330285809Sscottl        nvmdInfo.TWIDeviceAddress = 0xa0;
2331285809Sscottl        nvmdInfo.TWIBusNumber = 0;
2332285809Sscottl        nvmdInfo.TWIDevicePageSize = 0;
2333285809Sscottl        nvmdInfo.TWIDeviceAddressSize = 1;
2334285809Sscottl      }
2335285809Sscottl
2336285809Sscottl      if(RequestLength != 0)
2337285809Sscottl      {
2338285809Sscottl        if(ostiAllocMemory( tiRoot,
2339285809Sscottl            &osMemHandle,
2340285809Sscottl            (void **)&buffer,
2341285809Sscottl            &bufAddrUpper,
2342285809Sscottl            &bufAddrLower,
2343285809Sscottl            8,
2344285809Sscottl            RequestLength,
2345285809Sscottl            agFALSE))
2346285809Sscottl          return IOCTL_CALL_FAIL;
2347285809Sscottl      }
2348285809Sscottl      else
2349285809Sscottl      {
2350285809Sscottl        return IOCTL_CALL_FAIL;
2351285809Sscottl      }
2352285809Sscottl
2353285809Sscottl      osti_memset((void *)buffer, 0, RequestLength);
2354285809Sscottl
2355285809Sscottl      osti_memcpy((void *)buffer,
2356285809Sscottl            agIOCTLPayload->FunctionSpecificArea,
2357285809Sscottl            RequestLength);
2358285809Sscottl
2359285809Sscottl      nvmdInfo.indirectAddrLower32 = bufAddrLower;
2360285809Sscottl      nvmdInfo.indirectAddrUpper32 = bufAddrUpper;
2361285809Sscottl      // use FW control place in shared structure to keep the neccesary information
2362285809Sscottl      tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
2363285809Sscottl      tdsaAllShared->tdFWControlEx.virtAddr = buffer;
2364285809Sscottl      tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2365285809Sscottl      tdsaAllShared->tdFWControlEx.len = RequestLength;
2366285809Sscottl      tdsaAllShared->tdFWControlEx.param1 = agParam1;
2367285809Sscottl      tdsaAllShared->tdFWControlEx.param2 = agParam2;
2368285809Sscottl      tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2369285809Sscottl      tdsaAllShared->tdFWControlEx.inProgress = 1;
2370285809Sscottl      status = IOCTL_CALL_PENDING;
2371285809Sscottl      break;
2372285809Sscottl    default:
2373285809Sscottl        status = IOCTL_CALL_INVALID_CODE;
2374285809Sscottl        TI_DBG1(("tdsaNVMDSetIoctl: ERROR: Wrong IOCTL code %d\n", agIOCTLPayload->MinorFunction));
2375285809Sscottl        break;
2376285809Sscottl  }
2377285809Sscottl
2378285809Sscottl  if(saSetNVMDCommand(agRoot, agNULL, 0, &nvmdInfo) != AGSA_RC_SUCCESS)
2379285809Sscottl  {
2380285809Sscottl      status = IOCTL_CALL_FAIL;
2381285809Sscottl      agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
2382285809Sscottl  }
2383285809Sscottl
2384285809Sscottl  return status;
2385285809Sscottl
2386285809Sscottl}
2387285809Sscottl
2388285809Sscottl/*****************************************************************************
2389285809Sscottl*
2390285809Sscottl* tdsaNVMDGetIoctl
2391285809Sscottl*
2392285809Sscottl* Purpose:  This routine is called to get Config. SEEPROM information.
2393285809Sscottl*           This function is used for both target and initiator.
2394285809Sscottl*
2395285809Sscottl* Parameters:
2396285809Sscottl*   tiRoot:         Pointer to driver instance
2397285809Sscottl*   agIOCTLPayload: Pointer to the IOCTL payload.
2398285809Sscottl*   agParam1:       Pointer to pass context handle for IOCTL DMA operation
2399285809Sscottl*   agParam2:       Pointer to pass context handle for IOCTL DMA operation
2400285809Sscottl*   agParam3:       Pointer to pass context handle for IOCTL DMA operation
2401285809Sscottl*
2402285809Sscottl* Return:
2403285809Sscottl*
2404285809Sscottl*   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
2405285809Sscottl*   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
2406285809Sscottl*                             Detail error code is function specific and
2407285809Sscottl*                             defined by the specific IOCTL function.
2408285809Sscottl*   IOCTL_CALL_PENDING        This request is asynchronous and completed
2409285809Sscottl*                             in some other context.
2410285809Sscottl*   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
2411285809Sscottl*
2412285809Sscottl*
2413285809Sscottl*****************************************************************************/
2414285809SscottlosGLOBAL bit32
2415285809SscottltdsaNVMDGetIoctl(
2416285809Sscottl                tiRoot_t            *tiRoot,
2417285809Sscottl                tiIOCTLPayload_t    *agIOCTLPayload,
2418285809Sscottl                void                *agParam1,
2419285809Sscottl                void                *agParam2,
2420285809Sscottl                void                *agParam3
2421285809Sscottl                )
2422285809Sscottl{
2423285809Sscottl  tdsaRoot_t      *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
2424285809Sscottl  tdsaContext_t   *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2425285809Sscottl  agsaRoot_t      *agRoot = &(tdsaAllShared->agRootInt);
2426285809Sscottl  void            *buffer = agNULL;
2427285809Sscottl  void            *osMemHandle = agNULL;
2428285809Sscottl  bit32           status = IOCTL_CALL_SUCCESS;
2429285809Sscottl  agsaNVMDData_t  nvmdInfo;
2430285809Sscottl  bit32           Offset = 0;
2431285809Sscottl  bit32           RequestLength = 0;
2432285809Sscottl  bit32		  ostiMemoryStatus = 0;
2433285809Sscottl  bit32		  i,j;
2434285809Sscottl  bit8*		  seepromBuffer;
2435285809Sscottl  bit8*		  phySettingsBuffer;
2436285809Sscottl
2437285809Sscottl
2438285809Sscottl  TI_DBG2(("tdsaNVMDGetIoctl: start\n"));
2439285809Sscottl
2440285809Sscottl  RequestLength = agIOCTLPayload->Length;
2441285809Sscottl  Offset = agIOCTLPayload->Reserved;
2442285809Sscottl
2443285809Sscottl  osti_memset(&nvmdInfo, 0, sizeof(agsaNVMDData_t));
2444285809Sscottl  /* This condition is not valid for direct read so commenting */
2445285809Sscottl  /*if(!tiIS_SPC(agRoot)) {
2446285809Sscottl     if( RequestLength <= Offset ) //4096-max seeprom size
2447285809Sscottl     {
2448285809Sscottl    	agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
2449285809Sscottl    	agIOCTLPayload->Length = 0;
2450285809Sscottl    	status=IOCTL_CALL_SUCCESS;
2451285809Sscottl    	return status;
2452285809Sscottl     }
2453285809Sscottl  }*/
2454285809Sscottl
2455285809Sscottl  agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
2456285809Sscottl
2457285809Sscottl  switch(agIOCTLPayload->MinorFunction)
2458285809Sscottl  {
2459285809Sscottl    case IOCTL_MN_NVMD_GET_CONFIG:
2460285809Sscottl
2461285809Sscottl   //   nvmdInfo.NVMDevice = 1;
2462285809Sscottl      nvmdInfo.NVMDevice = *((bit8*)agParam3);
2463285809Sscottl      nvmdInfo.signature = 0xFEDCBA98;
2464285809Sscottl      nvmdInfo.dataOffsetAddress = Offset;
2465285809Sscottl      nvmdInfo.indirectPayload = 1;
2466285809Sscottl      nvmdInfo.indirectLen = RequestLength;
2467285809Sscottl
2468285809Sscottl      if (nvmdInfo.NVMDevice == 0) {
2469285809Sscottl        nvmdInfo.TWIDeviceAddress = 0xa0;
2470285809Sscottl        nvmdInfo.TWIBusNumber = 0;
2471285809Sscottl        nvmdInfo.TWIDevicePageSize = 0;
2472285809Sscottl        nvmdInfo.TWIDeviceAddressSize = 1;
2473285809Sscottl      }
2474285809Sscottl
2475285809Sscottl      if(RequestLength != 0)
2476285809Sscottl      {
2477285809Sscottl        ostiMemoryStatus = ostiAllocMemory( tiRoot,
2478285809Sscottl            &osMemHandle,
2479285809Sscottl            (void **)&buffer,
2480285809Sscottl            &(nvmdInfo.indirectAddrUpper32),
2481285809Sscottl            &(nvmdInfo.indirectAddrLower32),
2482285809Sscottl            8,
2483285809Sscottl            RequestLength,
2484285809Sscottl            agFALSE);
2485285809Sscottl	if((ostiMemoryStatus != tiSuccess) && (buffer == agNULL))
2486285809Sscottl        return IOCTL_CALL_FAIL;
2487285809Sscottl     }
2488285809Sscottl      else
2489285809Sscottl      {
2490285809Sscottl        return IOCTL_CALL_FAIL;
2491285809Sscottl      }
2492285809Sscottl      osti_memset((void *)buffer, 0, RequestLength);
2493285809Sscottl
2494285809Sscottl      // use FW control place in shared structure to keep the neccesary information
2495285809Sscottl      tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
2496285809Sscottl      tdsaAllShared->tdFWControlEx.virtAddr = buffer;
2497285809Sscottl      tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2498285809Sscottl      tdsaAllShared->tdFWControlEx.len = RequestLength;
2499285809Sscottl      tdsaAllShared->tdFWControlEx.param1 = agParam1;
2500285809Sscottl      tdsaAllShared->tdFWControlEx.param2 = agParam2;
2501285809Sscottl      tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2502285809Sscottl      tdsaAllShared->tdFWControlEx.inProgress = 1;
2503285809Sscottl      status = IOCTL_CALL_PENDING;
2504285809Sscottl      break;
2505285809Sscottl      default:
2506285809Sscottl      status = IOCTL_CALL_INVALID_CODE;
2507285809Sscottl      TI_DBG1(("tiCOMMgntIOCTL: ERROR: Wrong IOCTL code %d\n", agIOCTLPayload->MinorFunction));
2508285809Sscottl      break;
2509285809Sscottl  }
2510285809Sscottl  tdsaAllShared->NvmdResponseSet = 0;
2511285809Sscottl
2512285809Sscottl  if(saGetNVMDCommand(agRoot, agNULL, 0, &nvmdInfo) != AGSA_RC_SUCCESS)
2513285809Sscottl  {
2514285809Sscottl    status = IOCTL_CALL_FAIL;
2515285809Sscottl    agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
2516285809Sscottl    return status;
2517285809Sscottl  }
2518285809Sscottl  /* Copy the SAS address */
2519285809Sscottl  if(agParam1 == agNULL)
2520285809Sscottl
2521285809Sscottl  {
2522285809Sscottl     while(!tdsaAllShared->NvmdResponseSet)
2523285809Sscottl     {
2524285809Sscottl   //	tiCOMDelayedInterruptHandler(tiRoot, 0, 1, tiNonInterruptContext);
2525285809Sscottl     }
2526285809Sscottl     if(nvmdInfo.NVMDevice == 4 || nvmdInfo.NVMDevice == 1)
2527285809Sscottl     {
2528285809Sscottl	seepromBuffer = buffer;
2529285809Sscottl	/*Get Initiator SAS address*/
2530285809Sscottl
2531285809Sscottl	if(tiIS_SPC(agRoot))
2532285809Sscottl	{
2533285809Sscottl	   for(j=0,i=ADAPTER_WWN_SPC_START_OFFSET; i<= ADAPTER_WWN_SPC_END_OFFSET; i++,j++)
2534285809Sscottl	  agIOCTLPayload->FunctionSpecificArea[j] = seepromBuffer[i];
2535285809Sscottl        }
2536285809Sscottl 	else
2537285809Sscottl	{
2538285809Sscottl	  for(j=0,i=ADAPTER_WWN_START_OFFSET; i<= ADAPTER_WWN_END_OFFSET; i++,j++)
2539285809Sscottl	  agIOCTLPayload->FunctionSpecificArea[j] = seepromBuffer[i];
2540285809Sscottl	}
2541285809Sscottl    }
2542285809Sscottl    /* Copy the Phy settings */
2543285809Sscottl    else if(nvmdInfo.NVMDevice == 6)
2544285809Sscottl    {
2545285809Sscottl      phySettingsBuffer = buffer;
2546285809Sscottl      for(i=0; i<PHY_SETTINGS_LEN; i++)
2547285809Sscottl	agIOCTLPayload->FunctionSpecificArea[i] = phySettingsBuffer[i];
2548285809Sscottl    }
2549285809Sscottl    tdsaAllShared->NvmdResponseSet = 0;
2550285809Sscottl    ostiFreeMemory(tiRoot, tdsaAllShared->tdFWControlEx.buffer, tdsaAllShared->tdFWControlEx.len);
2551285809Sscottl
2552285809Sscottl  }
2553285809Sscottl  return status;
2554285809Sscottl
2555285809Sscottl}
2556285809Sscottl
2557285809Sscottl/*****************************************************************************
2558285809Sscottl*
2559285809Sscottl* tdsaDeviceInfoGetIoctl
2560285809Sscottl*
2561285809Sscottl* Purpose:  This routine is called to get the specified device information.
2562285809Sscottl*
2563285809Sscottl* Parameters:
2564285809Sscottl*   tiRoot:         Pointer to driver instance
2565285809Sscottl*   agIOCTLPayload: Pointer to the IOCTL payload.
2566285809Sscottl*   agParam1:       Pointer to pass context handle for IOCTL DMA operation
2567285809Sscottl*   agParam2:       Pointer to pass context handle for IOCTL DMA operation
2568285809Sscottl*   agParam3:       Pointer to pass context handle for IOCTL DMA operation
2569285809Sscottl*
2570285809Sscottl* Return:
2571285809Sscottl*
2572285809Sscottl*   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
2573285809Sscottl*   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
2574285809Sscottl*                             Detail error code is function specific and
2575285809Sscottl*                             defined by the specific IOCTL function.
2576285809Sscottl*   IOCTL_CALL_PENDING        This request is asynchronous and completed
2577285809Sscottl*                             in some other context.
2578285809Sscottl*   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
2579285809Sscottl*
2580285809Sscottl*
2581285809Sscottl*****************************************************************************/
2582285809SscottlosGLOBAL bit32
2583285809SscottltdsaDeviceInfoGetIoctl(
2584285809Sscottl                tiRoot_t            *tiRoot,
2585285809Sscottl                tiIOCTLPayload_t    *agIOCTLPayload,
2586285809Sscottl                void                *agParam1,
2587285809Sscottl                void                *agParam2,
2588285809Sscottl                void                *agParam3
2589285809Sscottl                )
2590285809Sscottl{
2591285809Sscottl  tdsaDeviceData_t       *oneDeviceData = agNULL;
2592285809Sscottl  tiDeviceHandle_t       *tiDeviceHandle = agNULL;
2593285809Sscottl  tdDeviceInfoPayload_t  *pDeviceInfo = agNULL;
2594285809Sscottl  /*agsaDevHandle_t  *agDevHandle = agNULL;*/
2595285809Sscottl  bit32            status = IOCTL_CALL_SUCCESS;
2596285809Sscottl
2597285809Sscottl  pDeviceInfo = (tdDeviceInfoPayload_t*)agIOCTLPayload->FunctionSpecificArea;
2598285809Sscottl
2599285809Sscottl  TI_DBG3(("tdsaDeviceInfoGetIoctl: %d:%3d:%d %p %p %p\n",
2600285809Sscottl                                     (bit8)pDeviceInfo->PathId,
2601285809Sscottl                                     (bit8)pDeviceInfo->TargetId,
2602285809Sscottl                                     (bit8)pDeviceInfo->Lun,
2603285809Sscottl                                      agParam1,
2604285809Sscottl                                      agParam2,
2605285809Sscottl                                      agParam3));
2606285809Sscottl
2607285809Sscottl  tiDeviceHandle = ostiMapToDevHandle(tiRoot,
2608285809Sscottl                                     (bit8)pDeviceInfo->PathId,
2609285809Sscottl                                     (bit8)pDeviceInfo->TargetId,
2610285809Sscottl                                     (bit8)pDeviceInfo->Lun
2611285809Sscottl                                     );
2612285809Sscottl
2613285809Sscottl  if (tiDeviceHandle == agNULL)
2614285809Sscottl  {
2615285809Sscottl    TI_DBG1(("tdsaDeviceInfoGetIoctl: tiDeviceHandle is NULL !!!! SCSI address = %d:%3d:%d\n",
2616285809Sscottl              pDeviceInfo->PathId, pDeviceInfo->TargetId, pDeviceInfo->Lun));
2617285809Sscottl    agIOCTLPayload->Status = IOCTL_ERR_STATUS_INVALID_DEVICE;
2618285809Sscottl    status = IOCTL_CALL_FAIL;
2619285809Sscottl    return status;
2620285809Sscottl  }
2621285809Sscottl
2622285809Sscottl  oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
2623285809Sscottl  if(oneDeviceData == agNULL)
2624285809Sscottl  {
2625285809Sscottl    TI_DBG1(("tdsaDeviceInfoGetIoctl: tiDeviceHandle=%p DeviceData is NULL!!! SCSI address = %d:%3d:%d\n",
2626285809Sscottl             tiDeviceHandle, pDeviceInfo->PathId, pDeviceInfo->TargetId, pDeviceInfo->Lun));
2627285809Sscottl    agIOCTLPayload->Status = IOCTL_ERR_STATUS_INVALID_DEVICE;
2628285809Sscottl    status = IOCTL_CALL_FAIL;
2629285809Sscottl    return status;
2630285809Sscottl  }
2631285809Sscottl
2632285809Sscottl  /* for hotplug */
2633285809Sscottl  if (oneDeviceData->valid != agTRUE || oneDeviceData->registered != agTRUE ||
2634285809Sscottl      oneDeviceData->tdPortContext == agNULL )
2635285809Sscottl  {
2636285809Sscottl    TI_DBG1(("tdsaDeviceInfoGetIoctl: tiDeviceHandle=%p did %d DeviceData was removed!!! SCSI address = %d:%3d:%d\n",
2637285809Sscottl             tiDeviceHandle, oneDeviceData->id, pDeviceInfo->PathId, pDeviceInfo->TargetId, pDeviceInfo->Lun));
2638285809Sscottl    agIOCTLPayload->Status = IOCTL_ERR_STATUS_INVALID_DEVICE;
2639285809Sscottl    status = IOCTL_CALL_FAIL;
2640285809Sscottl    return status;
2641285809Sscottl  }
2642285809Sscottl
2643285809Sscottl  /* fill the device information in IOCTL payload */
2644285809Sscottl  pDeviceInfo->devInfo.phyId = oneDeviceData->phyID;
2645285809Sscottl  osti_memcpy(&pDeviceInfo->devInfo.sasAddressHi, oneDeviceData->agDeviceInfo.sasAddressHi, sizeof(bit32));
2646285809Sscottl  osti_memcpy(&pDeviceInfo->devInfo.sasAddressLo, oneDeviceData->agDeviceInfo.sasAddressLo, sizeof(bit32));
2647285809Sscottl
2648285809Sscottl  pDeviceInfo->devInfo.sasAddressHi = DMA_BEBIT32_TO_BIT32(pDeviceInfo->devInfo.sasAddressHi);
2649285809Sscottl  pDeviceInfo->devInfo.sasAddressLo = DMA_BEBIT32_TO_BIT32(pDeviceInfo->devInfo.sasAddressLo);
2650285809Sscottl
2651285809Sscottl  pDeviceInfo->devInfo.deviceType = (oneDeviceData->agDeviceInfo.devType_S_Rate & 0x30) >> 4;
2652285809Sscottl  pDeviceInfo->devInfo.linkRate   = oneDeviceData->agDeviceInfo.devType_S_Rate & 0x0F;
2653285809Sscottl
2654285809Sscottl  agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
2655285809Sscottl
2656285809Sscottl  TI_DBG3(("tdsaDeviceInfoGetIoctl:IOCTL_CALL_SUCCESS\n"));
2657285809Sscottl
2658285809Sscottl  /*saGetDeviceInfo(agRoot, agNULL, 0, 0, agDevHandle);*/
2659285809Sscottl
2660285809Sscottl  status = IOCTL_CALL_SUCCESS;
2661285809Sscottl
2662285809Sscottl  return status;
2663285809Sscottl}
2664285809Sscottl/*****************************************************************************
2665285809Sscottl*
2666285809Sscottl* tdsaIoErrorStatisticGetIoctl
2667285809Sscottl*
2668285809Sscottl* Purpose:  This routine is called to get the IO error statistic.
2669285809Sscottl*
2670285809Sscottl* Parameters:
2671285809Sscottl*   tiRoot:         Pointer to driver instance
2672285809Sscottl*   agIOCTLPayload: Pointer to the IOCTL payload.
2673285809Sscottl*   agParam1:       Pointer to pass context handle for IOCTL DMA operation
2674285809Sscottl*   agParam2:       Pointer to pass context handle for IOCTL DMA operation
2675285809Sscottl*   agParam3:       Pointer to pass context handle for IOCTL DMA operation
2676285809Sscottl*
2677285809Sscottl* Return:
2678285809Sscottl*
2679285809Sscottl*   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
2680285809Sscottl*   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
2681285809Sscottl*                             Detail error code is function specific and
2682285809Sscottl*                             defined by the specific IOCTL function.
2683285809Sscottl*   IOCTL_CALL_PENDING        This request is asynchronous and completed
2684285809Sscottl*                             in some other context.
2685285809Sscottl*   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
2686285809Sscottl*
2687285809Sscottl*
2688285809Sscottl*****************************************************************************/
2689285809SscottlosGLOBAL bit32
2690285809SscottltdsaIoErrorStatisticGetIoctl(
2691285809Sscottl                 tiRoot_t            *tiRoot,
2692285809Sscottl                 tiIOCTLPayload_t    *agIOCTLPayload,
2693285809Sscottl                 void                *agParam1,
2694285809Sscottl                 void                *agParam2,
2695285809Sscottl                 void                *agParam3
2696285809Sscottl                 )
2697285809Sscottl{
2698285809Sscottl  tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
2699285809Sscottl  tdsaContext_t               *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2700285809Sscottl  agsaRoot_t                  *agRoot          = &(tdsaAllShared->agRootInt);
2701285809Sscottl  tdIoErrorStatisticPayload_t *pIoErrorPayload = agNULL;
2702285809Sscottl  bit32                        status = IOCTL_CALL_SUCCESS;
2703285809Sscottl
2704285809Sscottl  pIoErrorPayload = (tdIoErrorStatisticPayload_t*)agIOCTLPayload->FunctionSpecificArea;
2705285809Sscottl
2706285809Sscottl  tdsaAllShared->tdFWControlEx.buffer = agNULL;
2707285809Sscottl  tdsaAllShared->tdFWControlEx.virtAddr = agNULL;
2708285809Sscottl  tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2709285809Sscottl  tdsaAllShared->tdFWControlEx.len = 0;
2710285809Sscottl  tdsaAllShared->tdFWControlEx.param1 = agParam1;
2711285809Sscottl  tdsaAllShared->tdFWControlEx.param2 = agParam2;
2712285809Sscottl  tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2713285809Sscottl  tdsaAllShared->tdFWControlEx.inProgress = 0;
2714285809Sscottl
2715285809Sscottl  saGetIOErrorStats(agRoot, agNULL, pIoErrorPayload->flag);
2716285809Sscottl
2717285809Sscottl  return status;
2718285809Sscottl}
2719285809Sscottl
2720285809Sscottl/*****************************************************************************
2721285809Sscottl*
2722285809Sscottl* tdsaIoEventStatisticGetIoctl
2723285809Sscottl*
2724285809Sscottl* Purpose:  This routine is called to get the IO event statistic.
2725285809Sscottl*
2726285809Sscottl* Parameters:
2727285809Sscottl*   tiRoot:         Pointer to driver instance
2728285809Sscottl*   agIOCTLPayload: Pointer to the IOCTL payload.
2729285809Sscottl*   agParam1:       Pointer to pass context handle for IOCTL DMA operation
2730285809Sscottl*   agParam2:       Pointer to pass context handle for IOCTL DMA operation
2731285809Sscottl*   agParam3:       Pointer to pass context handle for IOCTL DMA operation
2732285809Sscottl*
2733285809Sscottl* Return:
2734285809Sscottl*
2735285809Sscottl*   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
2736285809Sscottl*   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
2737285809Sscottl*                             Detail error code is function specific and
2738285809Sscottl*                             defined by the specific IOCTL function.
2739285809Sscottl*   IOCTL_CALL_PENDING        This request is asynchronous and completed
2740285809Sscottl*                             in some other context.
2741285809Sscottl*   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
2742285809Sscottl*
2743285809Sscottl*
2744285809Sscottl*****************************************************************************/
2745285809SscottlosGLOBAL bit32
2746285809SscottltdsaIoEventStatisticGetIoctl(
2747285809Sscottl                 tiRoot_t            *tiRoot,
2748285809Sscottl                 tiIOCTLPayload_t    *agIOCTLPayload,
2749285809Sscottl                 void                *agParam1,
2750285809Sscottl                 void                *agParam2,
2751285809Sscottl                 void                *agParam3
2752285809Sscottl                 )
2753285809Sscottl{
2754285809Sscottl  tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
2755285809Sscottl  tdsaContext_t               *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2756285809Sscottl  agsaRoot_t                  *agRoot          = &(tdsaAllShared->agRootInt);
2757285809Sscottl  tdIoEventStatisticPayload_t *pIoEventPayload = agNULL;
2758285809Sscottl  bit32                        status = IOCTL_CALL_SUCCESS;
2759285809Sscottl
2760285809Sscottl  pIoEventPayload = (tdIoEventStatisticPayload_t*)agIOCTLPayload->FunctionSpecificArea;
2761285809Sscottl
2762285809Sscottl  tdsaAllShared->tdFWControlEx.buffer = agNULL;
2763285809Sscottl  tdsaAllShared->tdFWControlEx.virtAddr = agNULL;
2764285809Sscottl  tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2765285809Sscottl  tdsaAllShared->tdFWControlEx.len = 0;
2766285809Sscottl  tdsaAllShared->tdFWControlEx.param1 = agParam1;
2767285809Sscottl  tdsaAllShared->tdFWControlEx.param2 = agParam2;
2768285809Sscottl  tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2769285809Sscottl  tdsaAllShared->tdFWControlEx.inProgress = 0;
2770285809Sscottl
2771285809Sscottl  saGetIOEventStats(agRoot, agNULL, pIoEventPayload->flag);
2772285809Sscottl
2773285809Sscottl  return status;
2774285809Sscottl}
2775285809Sscottl
2776285809Sscottl/*****************************************************************************
2777285809Sscottl*
2778285809Sscottl* tdsaRegisterIoctl
2779285809Sscottl*
2780285809Sscottl* Purpose:  This routine is called to get Forensic Data.
2781285809Sscottl*
2782285809Sscottl* Parameters:
2783285809Sscottl*   tiRoot:         Pointer to driver instance
2784285809Sscottl*   agIOCTLPayload: Pointer to the IOCTL payload.
2785285809Sscottl*   agParam1:       Pointer to pass context handle for IOCTL DMA operation
2786285809Sscottl*   agParam2:       Pointer to pass context handle for IOCTL DMA operation
2787285809Sscottl*   agParam3:       Pointer to pass context handle for IOCTL DMA operation
2788285809Sscottl*
2789285809Sscottl* Return:
2790285809Sscottl*
2791285809Sscottl*   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
2792285809Sscottl*   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
2793285809Sscottl*                             Detail error code is function specific and
2794285809Sscottl*                             defined by the specific IOCTL function.
2795285809Sscottl*   IOCTL_CALL_PENDING        This request is asynchronous and completed
2796285809Sscottl*                             in some other context.
2797285809Sscottl*   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
2798285809Sscottl*
2799285809Sscottl*
2800285809Sscottl*****************************************************************************/
2801285809SscottlosGLOBAL bit32
2802285809SscottltdsaRegisterIoctl(
2803285809Sscottl                 tiRoot_t            *tiRoot,
2804285809Sscottl                 tiIOCTLPayload_t    *agIOCTLPayload,
2805285809Sscottl                 void                *agParam1,
2806285809Sscottl                 void                *agParam2,
2807285809Sscottl                 void                *agParam3
2808285809Sscottl                 )
2809285809Sscottl{
2810285809Sscottl  tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
2811285809Sscottl  tdsaContext_t               *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2812285809Sscottl//  agsaRoot_t                  *agRoot          = &(tdsaAllShared->agRootInt);
2813285809Sscottl  tdRegisterPayload_t         *pRegisterPayload = agNULL;
2814285809Sscottl  bit32                        status = IOCTL_CALL_SUCCESS;
2815285809Sscottl
2816285809Sscottl  pRegisterPayload = (tdRegisterPayload_t*)agIOCTLPayload->FunctionSpecificArea;
2817285809Sscottl
2818285809Sscottl  tdsaAllShared->tdFWControlEx.buffer = agNULL;
2819285809Sscottl  tdsaAllShared->tdFWControlEx.virtAddr = agNULL;
2820285809Sscottl  tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2821285809Sscottl  tdsaAllShared->tdFWControlEx.len = 0;
2822285809Sscottl  tdsaAllShared->tdFWControlEx.param1 = agParam1;
2823285809Sscottl  tdsaAllShared->tdFWControlEx.param2 = agParam2;
2824285809Sscottl  tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2825285809Sscottl  tdsaAllShared->tdFWControlEx.inProgress = 0;
2826285809Sscottl
2827285809Sscottl  TI_DBG1(("tdsaRegisterIoctl: Flag %d RegAddr 0x%x RegValue 0x%x\n",
2828285809Sscottl            pRegisterPayload->flag, pRegisterPayload->RegAddr, pRegisterPayload->RegValue));
2829285809Sscottl
2830285809Sscottl  if (pRegisterPayload->flag)
2831285809Sscottl  {
2832285809Sscottl    /* set register */
2833285809Sscottl    ostiChipWriteBit32Ext(tiRoot, 0, pRegisterPayload->RegAddr, pRegisterPayload->RegValue);
2834285809Sscottl  }
2835285809Sscottl  else
2836285809Sscottl  {
2837285809Sscottl    /* get register */
2838285809Sscottl    pRegisterPayload->RegValue = ostiChipReadBit32Ext(tiRoot, 0, pRegisterPayload->RegAddr);
2839285809Sscottl  }
2840285809Sscottl  agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
2841285809Sscottl  return status;
2842285809Sscottl}
2843285809Sscottl
2844285809SscottlosGLOBAL bit32
2845285809SscottltdsaGetPhyGeneralStatusIoctl(
2846285809Sscottl				tiRoot_t			      *tiRoot,
2847285809Sscottl				agsaPhyGeneralState_t     *PhyData
2848285809Sscottl				)
2849285809Sscottl{
2850285809Sscottl  tdsaRoot_t				*tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
2851285809Sscottl  tdsaContext_t 			*tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2852285809Sscottl  agsaRoot_t				*agRoot = &(tdsaAllShared->agRootNonInt);
2853285809Sscottl//  agsaLLRoot_t	            *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
2854285809Sscottl//  bit8                      totalValidPhys;
2855285809Sscottl  bit32 					 status = AGSA_RC_SUCCESS;
2856285809Sscottl  bit32                      i = 0;
2857285809Sscottl  agsaControllerInfo_t ControllerInfo;
2858285809Sscottl  saGetControllerInfo(agRoot,&ControllerInfo);
2859285809Sscottl
2860285809Sscottl  TI_DBG3(("tdsaGetPhyGeneralStatusIoctl: start\n"));
2861285809Sscottl  do
2862285809Sscottl  {
2863285809Sscottl    if(tIsSPC(agRoot)||tIsSPCHIL(agRoot))
2864285809Sscottl    {
2865285809Sscottl  	    status = IOCTL_ERR_STATUS_NOT_SUPPORTED;
2866285809Sscottl		break;
2867285809Sscottl    }
2868285809Sscottl
2869285809Sscottl    PhyData->Reserved1 = ControllerInfo.phyCount;
2870285809Sscottl    for(i=0;i<PhyData->Reserved1;i++)
2871285809Sscottl    {
2872285809Sscottl      status = saGetPhyProfile( agRoot,agNULL,tdsaRotateQnumber(tiRoot, agNULL), AGSA_SAS_PHY_GENERAL_STATUS_PAGE,i);
2873285809Sscottl      if(status == AGSA_RC_FAILURE)
2874285809Sscottl	  {
2875285809Sscottl	    break;
2876285809Sscottl	  }
2877285809Sscottl    }
2878285809Sscottl  }while(0);
2879285809Sscottl  TI_DBG3(("tdsaGetPhyGeneralStatusIoctl: End\n"));
2880285809Sscottl  return status;
2881285809Sscottl}
2882285809Sscottl/*****************************************************************************
2883285809Sscottl*
2884285809Sscottl* ostiGetPhyGeneralStatusRsp
2885285809Sscottl*
2886285809Sscottl* Purpose:  This routine is called when a PhyStatus IOCTL response is received.
2887285809Sscottl*
2888285809Sscottl* Parameters:
2889285809Sscottl*   tiRoot:         Pointer to driver instance
2890285809Sscottl*   agsaSASPhyGeneralStatusPage_t:   Status of the phy.
2891285809Sscottl*   bit32:          phyID
2892285809Sscottl*
2893285809Sscottl* Return: none
2894285809Sscottl*
2895285809Sscottl*
2896285809Sscottl*****************************************************************************/
2897285809SscottlosGLOBAL void ostiGetPhyGeneralStatusRsp(
2898285809Sscottl                            tiRoot_t                      *tiRoot,
2899285809Sscottl                        	agsaSASPhyGeneralStatusPage_t *GenStatus,
2900285809Sscottl                        	bit32                          phyID
2901285809Sscottl                            )
2902285809Sscottl{
2903285809Sscottl
2904285809Sscottl  tdsaRoot_t               *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
2905285809Sscottl  tdsaContext_t            *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2906285809Sscottl  tiIOCTLPayload_t         *agIoctlPayload = agNULL;
2907285809Sscottl  agsaPhyGeneralState_t    *pSetPhyStatusRes = agNULL;
2908285809Sscottl
2909285809Sscottl
2910285809Sscottl  TI_DBG1(("ostiGetPhyGeneralStatusRsp: start\n"));
2911285809Sscottl
2912285809Sscottl  if (tdsaAllShared->tdFWControlEx.inProgress)
2913285809Sscottl  {
2914285809Sscottl      agIoctlPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
2915285809Sscottl      if ((agIoctlPayload) && (PMC_IOCTL_SIGNATURE == agIoctlPayload->Signature)&&
2916285809Sscottl	  	                 (IOCTL_MJ_PHY_GENERAL_STATUS == agIoctlPayload->MajorFunction))
2917285809Sscottl      {
2918285809Sscottl        pSetPhyStatusRes = (agsaPhyGeneralState_t*) &agIoctlPayload->FunctionSpecificArea[0];
2919285809Sscottl		osti_memcpy(&pSetPhyStatusRes->PhyGenData[phyID], GenStatus, sizeof(agsaSASPhyGeneralStatusPage_t));
2920285809Sscottl		pSetPhyStatusRes->Reserved2++;
2921285809Sscottl        if(pSetPhyStatusRes->Reserved1 == pSetPhyStatusRes->Reserved2)
2922285809Sscottl        {
2923285809Sscottl  		  tdsaAllShared->tdFWControlEx.payload = NULL;
2924285809Sscottl          ostiIOCTLSetSignal(tiRoot, tdsaAllShared->tdFWControlEx.param1,
2925285809Sscottl                          tdsaAllShared->tdFWControlEx.param2, agNULL);
2926285809Sscottl	  tdsaAllShared->tdFWControlEx.inProgress = 0;
2927285809Sscottl          agIoctlPayload->Status = IOCTL_ERR_STATUS_OK;
2928285809Sscottl
2929285809Sscottl        }
2930285809Sscottl  	  }
2931285809Sscottl  }
2932285809Sscottl
2933285809Sscottl  TI_DBG1(("ostiGetPhyGeneralStatusRsp: end\n"));
2934285809Sscottl}
2935285809Sscottl
2936285809Sscottl
2937285809SscottlosGLOBAL bit32
2938285809SscottltdsaPhyProfileIoctl(
2939285809Sscottl                 tiRoot_t            *tiRoot,
2940285809Sscottl                 tiIOCTLPayload_t    *agIOCTLPayload,
2941285809Sscottl                 void                *agParam1,
2942285809Sscottl                 void                *agParam2,
2943285809Sscottl                 void                *agParam3
2944285809Sscottl                 )
2945285809Sscottl{
2946285809Sscottl  tdsaRoot_t       *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
2947285809Sscottl  tdsaContext_t    *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2948285809Sscottl  agsaRoot_t       *agRoot          = &(tdsaAllShared->agRootInt);
2949285809Sscottl  void             *buffer = agNULL;
2950285809Sscottl  void             *osMemHandle = agNULL;
2951285809Sscottl  bit32            status = IOCTL_CALL_SUCCESS;
2952285809Sscottl  bit32            retcode = AGSA_RC_FAILURE;
2953285809Sscottl  bit32            RequestLength= agIOCTLPayload->Length;
2954285809Sscottl  bit32 	   bufAddrUpper = 0;
2955285809Sscottl  bit32 	   bufAddrLower = 0;
2956285809Sscottl
2957285809Sscottl  tdPhyCount_t     *PhyBlob = (tdPhyCount_t*)&agIOCTLPayload->FunctionSpecificArea[0];
2958285809Sscottl
2959285809Sscottl
2960285809Sscottl  if(ostiAllocMemory( tiRoot,
2961285809Sscottl      &osMemHandle,
2962285809Sscottl      (void **)&buffer,
2963285809Sscottl      &bufAddrUpper,
2964285809Sscottl      &bufAddrLower,
2965285809Sscottl      RequestLength,
2966285809Sscottl      RequestLength,
2967285809Sscottl      agTRUE))
2968285809Sscottl    return IOCTL_CALL_FAIL;
2969285809Sscottl
2970285809Sscottl
2971285809Sscottl  tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
2972285809Sscottl  tdsaAllShared->tdFWControlEx.virtAddr = buffer;
2973285809Sscottl  tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2974285809Sscottl  tdsaAllShared->tdFWControlEx.len = 32;
2975285809Sscottl  tdsaAllShared->tdFWControlEx.param1 = agParam1;
2976285809Sscottl  tdsaAllShared->tdFWControlEx.param2 = agParam2;
2977285809Sscottl  tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2978285809Sscottl  tdsaAllShared->tdFWControlEx.inProgress = 1;
2979285809Sscottl
2980285809Sscottl  TI_DBG1(("tdsaPhyProfileIoctl: MinorFunction %d\n",agIOCTLPayload->MinorFunction));
2981285809Sscottl//  PhyBlob->Phy |= 0x100;
2982285809Sscottl
2983285809Sscottl  if( tiIS_SPC(agRoot) )
2984285809Sscottl  {
2985285809Sscottl    TI_DBG1(("tdsaPhyProfileIoctl: SPC operation 0x%x PHY %d\n",agIOCTLPayload->MinorFunction,PhyBlob->Phy));
2986285809Sscottl    retcode = saLocalPhyControl(agRoot,agNULL,0 ,PhyBlob->Phy ,agIOCTLPayload->MinorFunction , agNULL);
2987285809Sscottl    if(retcode ==  AGSA_RC_SUCCESS)
2988285809Sscottl    {
2989285809Sscottl      status = IOCTL_CALL_PENDING;
2990285809Sscottl    }
2991285809Sscottl  }
2992285809Sscottl  else
2993285809Sscottl  {
2994285809Sscottl    TI_DBG1(("tdsaPhyProfileIoctl: SPCv operation 0x%x PHY %d\n",agIOCTLPayload->MinorFunction,PhyBlob->Phy));
2995285809Sscottl    retcode = saGetPhyProfile( agRoot,agNULL,0,agIOCTLPayload->MinorFunction , PhyBlob->Phy);
2996285809Sscottl
2997285809Sscottl    if(retcode ==  AGSA_RC_SUCCESS)
2998285809Sscottl    {
2999285809Sscottl      status = IOCTL_CALL_PENDING;
3000285809Sscottl    }
3001285809Sscottl
3002285809Sscottl  }
3003285809Sscottl
3004285809Sscottl  TI_DBG2(("tdsaPhyProfileIoctl: after\n"));
3005285809Sscottl
3006285809Sscottl
3007285809Sscottl  return status;
3008285809Sscottl}
3009285809Sscottl
3010285809Sscottl/*****************************************************************************
3011285809Sscottl*
3012285809Sscottl* tdsaForensicDataGetIoctl
3013285809Sscottl*
3014285809Sscottl* Purpose:  This routine is called to get Forensic Data.
3015285809Sscottl*
3016285809Sscottl* Parameters:
3017285809Sscottl*   tiRoot:         Pointer to driver instance
3018285809Sscottl*   agIOCTLPayload: Pointer to the IOCTL payload.
3019285809Sscottl*   agParam1:       Pointer to pass context handle for IOCTL DMA operation
3020285809Sscottl*   agParam2:       Pointer to pass context handle for IOCTL DMA operation
3021285809Sscottl*   agParam3:       Pointer to pass context handle for IOCTL DMA operation
3022285809Sscottl*
3023285809Sscottl* Return:
3024285809Sscottl*
3025285809Sscottl*   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
3026285809Sscottl*   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
3027285809Sscottl*                             Detail error code is function specific and
3028285809Sscottl*                             defined by the specific IOCTL function.
3029285809Sscottl*   IOCTL_CALL_PENDING        This request is asynchronous and completed
3030285809Sscottl*                             in some other context.
3031285809Sscottl*   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
3032285809Sscottl*
3033285809Sscottl*
3034285809Sscottl*****************************************************************************/
3035285809SscottlosGLOBAL bit32
3036285809SscottltdsaForensicDataGetIoctl(
3037285809Sscottl                 tiRoot_t            *tiRoot,
3038285809Sscottl                 tiIOCTLPayload_t    *agIOCTLPayload,
3039285809Sscottl                 void                *agParam1,
3040285809Sscottl                 void                *agParam2,
3041285809Sscottl                 void                *agParam3
3042285809Sscottl                 )
3043285809Sscottl{
3044285809Sscottl  tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
3045285809Sscottl  tdsaContext_t               *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3046285809Sscottl  agsaRoot_t                  *agRoot          = &(tdsaAllShared->agRootInt);
3047285809Sscottl  tdForensicDataPayload_t     *pForensicDataPayload = agNULL;
3048285809Sscottl  agsaForensicData_t           ForensicData;
3049285809Sscottl  bit32                        status = IOCTL_CALL_SUCCESS;
3050285809Sscottl
3051285809Sscottl  pForensicDataPayload = (tdForensicDataPayload_t*)agIOCTLPayload->FunctionSpecificArea;
3052285809Sscottl
3053285809Sscottl  tdsaAllShared->tdFWControlEx.buffer = agNULL;
3054285809Sscottl  tdsaAllShared->tdFWControlEx.virtAddr = agNULL;
3055285809Sscottl  tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
3056285809Sscottl  tdsaAllShared->tdFWControlEx.len = 0;
3057285809Sscottl  tdsaAllShared->tdFWControlEx.param1 = agParam1;
3058285809Sscottl  tdsaAllShared->tdFWControlEx.param2 = agParam2;
3059285809Sscottl  tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
3060285809Sscottl  tdsaAllShared->tdFWControlEx.inProgress = 0;
3061285809Sscottl
3062285809Sscottl  osti_memset(&ForensicData, 0, sizeof(agsaForensicData_t));
3063285809Sscottl
3064285809Sscottl  ForensicData.DataType = pForensicDataPayload->DataType;
3065285809Sscottl
3066285809Sscottl  switch (ForensicData.DataType)
3067285809Sscottl  {
3068285809Sscottl    case FORENSIC_DATA_TYPE_NON_FATAL:
3069285809Sscottl    case FORENSIC_DATA_TYPE_FATAL:
3070285809Sscottl         ForensicData.BufferType.dataBuf.directLen = pForensicDataPayload->dataBuffer.directLen;
3071285809Sscottl         ForensicData.BufferType.dataBuf.directOffset = pForensicDataPayload->dataBuffer.directOffset;
3072285809Sscottl         ForensicData.BufferType.dataBuf.readLen = pForensicDataPayload->dataBuffer.readLen;
3073285809Sscottl         ForensicData.BufferType.dataBuf.directData = (void*)pForensicDataPayload->dataBuffer.directData;
3074285809Sscottl		 break;
3075285809Sscottl    case FORENSIC_DATA_TYPE_GSM_SPACE:
3076285809Sscottl         ForensicData.BufferType.gsmBuf.directLen = pForensicDataPayload->gsmBuffer.directLen;
3077285809Sscottl         ForensicData.BufferType.gsmBuf.directOffset = pForensicDataPayload->gsmBuffer.directOffset;
3078285809Sscottl         ForensicData.BufferType.dataBuf.readLen      = pForensicDataPayload->gsmBuffer.readLen;
3079285809Sscottl         ForensicData.BufferType.gsmBuf.directData = (void*)pForensicDataPayload->gsmBuffer.directData;
3080285809Sscottl         break;
3081285809Sscottl
3082285809Sscottl    case FORENSIC_DATA_TYPE_IB_QUEUE:
3083285809Sscottl         ForensicData.BufferType.queueBuf.directLen = pForensicDataPayload->queueBuffer.directLen;
3084285809Sscottl         //ForensicData.BufferType.queueBuf.queueType = pForensicDataPayload->queueBuffer.queueType;
3085285809Sscottl         ForensicData.BufferType.queueBuf.queueType = FORENSIC_DATA_TYPE_IB_QUEUE;
3086285809Sscottl         ForensicData.BufferType.queueBuf.queueIndex = pForensicDataPayload->queueBuffer.queueIndex;
3087285809Sscottl         ForensicData.BufferType.queueBuf.directData = (void*)pForensicDataPayload->queueBuffer.directData;
3088285809Sscottl         break;
3089285809Sscottl    case FORENSIC_DATA_TYPE_OB_QUEUE:
3090285809Sscottl         ForensicData.BufferType.queueBuf.directLen = pForensicDataPayload->queueBuffer.directLen;
3091285809Sscottl         ForensicData.BufferType.queueBuf.queueType = FORENSIC_DATA_TYPE_OB_QUEUE;
3092285809Sscottl         ForensicData.BufferType.queueBuf.queueIndex = pForensicDataPayload->queueBuffer.queueIndex;
3093285809Sscottl         ForensicData.BufferType.queueBuf.directData = (void*)pForensicDataPayload->queueBuffer.directData;
3094285809Sscottl         break;
3095285809Sscottl
3096285809Sscottl    default:
3097285809Sscottl         TI_DBG1(("tdsaGetForensicDataIoctl: forensic data type error %d\n", pForensicDataPayload->DataType));
3098285809Sscottl         status = IOCTL_CALL_INVALID_CODE;
3099285809Sscottl         return status;
3100285809Sscottl  }
3101285809Sscottl
3102285809Sscottl  if ( saGetForensicData(agRoot, agNULL, &ForensicData) != AGSA_RC_SUCCESS )
3103285809Sscottl  {
3104285809Sscottl    status = IOCTL_CALL_FAIL;
3105285809Sscottl  }
3106285809Sscottl
3107285809Sscottl  return status;
3108285809Sscottl}
3109285809Sscottl
3110285809SscottlosGLOBAL bit32
3111285809SscottltdsaSendSMPIoctl(
3112285809Sscottl                tiRoot_t            *tiRoot,
3113285809Sscottl                tiIOCTLPayload_t    *agIOCTLPayload,
3114285809Sscottl                void                *agParam1,
3115285809Sscottl                void                *agParam2,
3116285809Sscottl                void                *agParam3
3117285809Sscottl                )
3118285809Sscottl{
3119285809Sscottl	tdsaRoot_t		*tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
3120285809Sscottl	tdsaContext_t	*tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3121285809Sscottl	agsaRoot_t		*agRoot = &(tdsaAllShared->agRootInt);
3122285809Sscottl	void			*reqBuffer = agNULL;
3123285809Sscottl	void			*respBuffer = agNULL;
3124285809Sscottl	void			*osMemHandle = agNULL;
3125285809Sscottl	bit32			status = IOCTL_CALL_SUCCESS;
3126285809Sscottl//	bit32			Offset = 0;
3127285809Sscottl//	bit32			RequestLength = 0;
3128285809Sscottl	bit32			ostiMemoryStatus = 0;
3129285809Sscottl	smp_pass_through_req_t *smp_pass_through_req;
3130285809Sscottl
3131285809Sscottl	tiDeviceHandle_t *devHandle;
3132285809Sscottl	agsaSMPFrame_t			  agSMPFrame;
3133285809Sscottl	tdsaDeviceData_t          *oneDeviceData = agNULL;
3134285809Sscottl	bit32 i;
3135285809Sscottl
3136285809Sscottl	TI_DBG2(("tdsaSendSMPIoctl: start\n"));
3137285809Sscottl
3138285809Sscottl 	smp_pass_through_req = (smp_pass_through_req_t*)agIOCTLPayload->FunctionSpecificArea;
3139285809Sscottl
3140285809Sscottl	for(i=0;i<8;i++)
3141285809Sscottl		TI_DBG2(("SAS Address[%d]:%x",i,smp_pass_through_req->exp_sas_addr[i]));
3142285809Sscottl	TI_DBG2(("SAS Request Length:%d",smp_pass_through_req->smp_req_len));
3143285809Sscottl	TI_DBG2(("SAS Response Length:%d",smp_pass_through_req->smp_resp_len));
3144285809Sscottl	for(i=0;i<smp_pass_through_req->smp_req_len;i++)
3145285809Sscottl		TI_DBG2(("SAS request + %d:%x",i,smp_pass_through_req->smp_req_resp[i]));
3146285809Sscottl
3147285809Sscottl	devHandle = ostiGetDevHandleFromSasAddr(tiRoot, smp_pass_through_req->exp_sas_addr);
3148285809Sscottl	if(devHandle == NULL)
3149285809Sscottl	{
3150285809Sscottl		status = IOCTL_CALL_FAIL;
3151285809Sscottl		agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
3152285809Sscottl		return status;
3153285809Sscottl	}
3154285809Sscottl
3155285809Sscottl
3156285809Sscottl
3157285809Sscottl	//agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
3158285809Sscottl	agIOCTLPayload->Status = IOCTL_ERR_STATUS_NOT_RESPONDING;
3159285809Sscottl
3160285809Sscottl
3161285809Sscottl
3162285809Sscottl	if((ostiMemoryStatus != tiSuccess) && (reqBuffer == agNULL  ))
3163285809Sscottl			return IOCTL_CALL_FAIL;
3164285809Sscottl
3165285809Sscottl
3166285809Sscottl    tdsaAllShared->tdFWControlEx.param3 = osMemHandle;
3167285809Sscottl
3168285809Sscottl
3169285809Sscottl	agSMPFrame.outFrameBuf = smp_pass_through_req->smp_req_resp;
3170285809Sscottl	agSMPFrame.expectedRespLen = smp_pass_through_req->smp_resp_len;
3171285809Sscottl	agSMPFrame.inFrameLen = smp_pass_through_req->smp_resp_len - 4;
3172285809Sscottl
3173285809Sscottl	if(!(smp_pass_through_req->smp_req_len - 8) && !tiIS_SPC(agRoot))
3174285809Sscottl	{
3175285809Sscottl		agSMPFrame.flag = 1;  // Direct request Indirect response
3176285809Sscottl		agSMPFrame.outFrameLen = smp_pass_through_req->smp_req_len - 4; //Exclude header
3177285809Sscottl	}
3178285809Sscottl	else
3179285809Sscottl	{
3180285809Sscottl
3181285809Sscottl		agSMPFrame.flag = 3;  //Indirect request and Indirect response
3182285809Sscottl		ostiMemoryStatus = ostiAllocMemory( tiRoot,
3183285809Sscottl										  &osMemHandle,
3184285809Sscottl										  (void **)&reqBuffer,
3185285809Sscottl										  &(agSMPFrame.outFrameAddrUpper32),
3186285809Sscottl										  &(agSMPFrame.outFrameAddrLower32),
3187285809Sscottl										  8,
3188285809Sscottl										  smp_pass_through_req->smp_req_len,
3189285809Sscottl										  agFALSE);
3190285809Sscottl		tdsaAllShared->tdFWControlEx.param3 = osMemHandle;
3191285809Sscottl		if(tiIS_SPC(agRoot))
3192285809Sscottl		{
3193285809Sscottl		  agSMPFrame.outFrameLen = smp_pass_through_req->smp_req_len - 4; //Exclude crc
3194285809Sscottl		  osti_memcpy((void *)reqBuffer, (void *)(smp_pass_through_req->smp_req_resp), smp_pass_through_req->smp_req_len);
3195285809Sscottl		}
3196285809Sscottl		else
3197285809Sscottl		{
3198285809Sscottl		  agSMPFrame.outFrameLen = smp_pass_through_req->smp_req_len - 8; //Exclude header and crc
3199285809Sscottl		  osti_memcpy((void *)reqBuffer, (void *)(smp_pass_through_req->smp_req_resp + 4), smp_pass_through_req->smp_req_len - 4);
3200285809Sscottl		}
3201285809Sscottl	}
3202285809Sscottl
3203285809Sscottl	ostiMemoryStatus = ostiAllocMemory( tiRoot,
3204285809Sscottl										  &osMemHandle,
3205285809Sscottl										  (void **)&respBuffer,
3206285809Sscottl										  &(agSMPFrame.inFrameAddrUpper32),
3207285809Sscottl										  &(agSMPFrame.inFrameAddrLower32),
3208285809Sscottl										  8,
3209285809Sscottl										  smp_pass_through_req->smp_resp_len + 4,
3210285809Sscottl										  agFALSE);
3211285809Sscottl	if((ostiMemoryStatus != tiSuccess) && (respBuffer == agNULL  ))
3212285809Sscottl			return IOCTL_CALL_FAIL;
3213285809Sscottl
3214285809Sscottl
3215285809Sscottl	osti_memset((void *)respBuffer, 0, smp_pass_through_req->smp_resp_len);
3216285809Sscottl
3217285809Sscottl		// use FW control place in shared structure to keep the neccesary information
3218285809Sscottl	tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
3219285809Sscottl	tdsaAllShared->tdFWControlEx.virtAddr = respBuffer;
3220285809Sscottl	tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)smp_pass_through_req->smp_req_resp + smp_pass_through_req->smp_req_len;
3221285809Sscottl	tdsaAllShared->tdFWControlEx.len = smp_pass_through_req->smp_resp_len;
3222285809Sscottl	tdsaAllShared->tdFWControlEx.param1 = agParam1;
3223285809Sscottl	tdsaAllShared->tdFWControlEx.param2 = agParam2;
3224285809Sscottl	tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
3225285809Sscottl	tdsaAllShared->tdFWControlEx.inProgress = 1;
3226285809Sscottl	status = IOCTL_CALL_PENDING;
3227285809Sscottl
3228285809Sscottl	oneDeviceData = (tdsaDeviceData_t *)devHandle->tdData;
3229285809Sscottl	if(saSendSMPIoctl(agRoot, oneDeviceData->agDevHandle, 0, &agSMPFrame, &ossaSMPIoctlCompleted) != AGSA_RC_SUCCESS)
3230285809Sscottl	{
3231285809Sscottl	  status = IOCTL_CALL_FAIL;
3232285809Sscottl	  agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
3233285809Sscottl	}
3234285809Sscottl	return status;
3235285809Sscottl}
3236285809Sscottl
3237285809SscottlosGLOBAL void ostiSendSMPIOCTLRsp(
3238285809Sscottl                        tiRoot_t            *tiRoot,
3239285809Sscottl                        bit32               status
3240285809Sscottl                        )
3241285809Sscottl{
3242285809Sscottl    tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
3243285809Sscottl    tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3244285809Sscottl    tiIOCTLPayload_t     *agIOCTLPayload;
3245285809Sscottl
3246285809Sscottl    agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
3247285809Sscottl    agIOCTLPayload->Status = (bit16)status;
3248285809Sscottl
3249285809Sscottl    TI_DBG1(("ostiSendSMPIOCTLRsp: start, status = %d\n", status));
3250285809Sscottl
3251285809Sscottl//	if(tdsaAllShared->tdFWControlEx.param1 != agNULL)
3252285809Sscottl//	{
3253285809Sscottl      osti_memcpy((void *)(tdsaAllShared->tdFWControlEx.usrAddr),
3254285809Sscottl                  (void *)(tdsaAllShared->tdFWControlEx.virtAddr),
3255285809Sscottl                  tdsaAllShared->tdFWControlEx.len);
3256285809Sscottl//	}
3257285809Sscottl	ostiFreeMemory(tiRoot,
3258285809Sscottl                   tdsaAllShared->tdFWControlEx.buffer,
3259285809Sscottl                   tdsaAllShared->tdFWControlEx.len);
3260285809Sscottl	ostiFreeMemory(tiRoot,
3261285809Sscottl                   tdsaAllShared->tdFWControlEx.param3,
3262285809Sscottl                   tdsaAllShared->tdFWControlEx.len);
3263285809Sscottl    //if(tdsaAllShared->tdFWControlEx.param1 != agNULL)
3264285809Sscottl//	{
3265285809Sscottl      ostiIOCTLComplete(tiRoot,
3266285809Sscottl                         tdsaAllShared->tdFWControlEx.param1,
3267285809Sscottl                         tdsaAllShared->tdFWControlEx.param2,
3268285809Sscottl                         NULL);
3269285809Sscottl//    }
3270285809Sscottl}
3271285809Sscottl
3272285809Sscottl
3273285809Sscottl
3274285809Sscottl
3275285809Sscottl/*****************************************************************************
3276285809Sscottl*
3277285809Sscottl* tdsaSendBISTIoctl
3278285809Sscottl*
3279285809Sscottl* Purpose:  This routine is called to get Forensic Data.
3280285809Sscottl*
3281285809Sscottl* Parameters:
3282285809Sscottl*   tiRoot:         Pointer to driver instance
3283285809Sscottl*   agIOCTLPayload: Pointer to the IOCTL payload.
3284285809Sscottl*   agParam1:       Pointer to pass context handle for IOCTL DMA operation
3285285809Sscottl*   agParam2:       Pointer to pass context handle for IOCTL DMA operation
3286285809Sscottl*   agParam3:       Pointer to pass context handle for IOCTL DMA operation
3287285809Sscottl*
3288285809Sscottl* Return:
3289285809Sscottl*
3290285809Sscottl*   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
3291285809Sscottl*   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
3292285809Sscottl*                             Detail error code is function specific and
3293285809Sscottl*                             defined by the specific IOCTL function.
3294285809Sscottl*   IOCTL_CALL_PENDING        This request is asynchronous and completed
3295285809Sscottl*                             in some other context.
3296285809Sscottl*   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
3297285809Sscottl*
3298285809Sscottl*
3299285809Sscottl*****************************************************************************/
3300285809SscottlosGLOBAL bit32
3301285809SscottltdsaSendBISTIoctl(
3302285809Sscottl                 tiRoot_t            *tiRoot,
3303285809Sscottl                 tiIOCTLPayload_t    *agIOCTLPayload,
3304285809Sscottl                 void                *agParam1,
3305285809Sscottl                 void                *agParam2,
3306285809Sscottl                 void                *agParam3
3307285809Sscottl                 )
3308285809Sscottl{
3309285809Sscottl  tdsaRoot_t      *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
3310285809Sscottl  tdsaContext_t   *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3311285809Sscottl  agsaRoot_t      *agRoot          = &(tdsaAllShared->agRootInt);
3312285809Sscottl  tdBistPayload_t *pBistPayload;
3313285809Sscottl//  bit32            length = 0;
3314285809Sscottl//  bit32            status = IOCTL_CALL_SUCCESS;
3315285809Sscottl  bit32            status = IOCTL_CALL_FAIL;
3316285809Sscottl
3317285809Sscottl  pBistPayload = (tdBistPayload_t*)agIOCTLPayload->FunctionSpecificArea;
3318285809Sscottl
3319285809Sscottl  tdsaAllShared->tdFWControlEx.buffer = agNULL;
3320285809Sscottl  tdsaAllShared->tdFWControlEx.virtAddr = agNULL;
3321285809Sscottl  tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
3322285809Sscottl  tdsaAllShared->tdFWControlEx.len = 0;
3323285809Sscottl  tdsaAllShared->tdFWControlEx.param1 = agParam1;
3324285809Sscottl  tdsaAllShared->tdFWControlEx.param2 = agParam2;
3325285809Sscottl  tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
3326285809Sscottl  tdsaAllShared->tdFWControlEx.inProgress = 0;
3327285809Sscottl
3328285809Sscottl  TI_DBG1(("tdsaSendBISTIoctl: Type %d Length %d Data %p\n",
3329285809Sscottl      pBistPayload->testType,
3330285809Sscottl      pBistPayload->testLength,
3331285809Sscottl      pBistPayload->testData ));
3332285809Sscottl
3333285809Sscottl
3334285809Sscottl  // pBistPayload->testtype = AGSA_BIST_TEST;
3335285809Sscottl
3336285809Sscottl  if( pBistPayload->testType == AGSA_BIST_TEST)
3337285809Sscottl  {
3338285809Sscottl    if( pBistPayload->testLength != sizeof(agsaEncryptSelfTestBitMap_t))
3339285809Sscottl    {
3340285809Sscottl      return status;
3341285809Sscottl    }
3342285809Sscottl  }
3343285809Sscottl  else if( pBistPayload->testType == AGSA_SHA_TEST)
3344285809Sscottl  {
3345285809Sscottl    if( pBistPayload->testLength != sizeof(agsaEncryptSHATestDescriptor_t) )
3346285809Sscottl    {
3347285809Sscottl      return status;
3348285809Sscottl    }
3349285809Sscottl  }
3350285809Sscottl  else if( pBistPayload->testType == AGSA_HMAC_TEST )
3351285809Sscottl  {
3352285809Sscottl    if( pBistPayload->testLength != sizeof(agsaEncryptHMACTestDescriptor_t))
3353285809Sscottl    {
3354285809Sscottl      return status;
3355285809Sscottl    }
3356285809Sscottl  }
3357285809Sscottl
3358285809Sscottl/*
3359285809SscottlGLOBAL bit32 saEncryptSelftestExecute(
3360285809Sscottl                        agsaRoot_t    *agRoot,
3361285809Sscottl                        agsaContext_t *agContext,
3362285809Sscottl                        bit32         queueNum,
3363285809Sscottl                        bit32         type,
3364285809Sscottl                        bit32         length,
3365285809Sscottl                        void          *TestDescriptor);
3366285809Sscottl
3367285809Sscottl*/
3368285809Sscottl  if ( saEncryptSelftestExecute(agRoot,
3369285809Sscottl        agNULL,
3370285809Sscottl        0,
3371285809Sscottl        pBistPayload->testType,
3372285809Sscottl        pBistPayload->testLength,
3373285809Sscottl        pBistPayload->testData  ) != AGSA_RC_SUCCESS )
3374285809Sscottl  {
3375285809Sscottl    status = IOCTL_CALL_FAIL;
3376285809Sscottl  }
3377285809Sscottl
3378285809Sscottl  return status;
3379285809Sscottl}
3380285809Sscottl
3381285809Sscottl
3382285809SscottlosGLOBAL bit32
3383285809SscottltdsaSendTMFIoctl( tiRoot_t	     	*tiRoot,
3384285809Sscottl		  tiIOCTLPayload_t	*agIOCTLPayload,
3385285809Sscottl		  void                  *agParam1,
3386285809Sscottl		  void			*agParam2,
3387285809Sscottl		  unsigned long		resetType
3388285809Sscottl		)
3389285809Sscottl{
3390285809Sscottl	bit32		status;
3391285809Sscottl	tmf_pass_through_req_t  *tmf_req = (tmf_pass_through_req_t*)agIOCTLPayload->FunctionSpecificArea;
3392285809Sscottl#if !(defined(__FreeBSD__))
3393285809Sscottl	status = ostiSendResetDeviceIoctl(tiRoot, agParam2, tmf_req->pathId, tmf_req->targetId, tmf_req->lun, resetType);
3394285809Sscottl#endif
3395285809Sscottl	TI_DBG3(("Status returned from ostiSendResetDeviceIoctl is %d\n",status));
3396285809Sscottl	if(status !=  IOCTL_CALL_SUCCESS)
3397285809Sscottl	{
3398285809Sscottl		agIOCTLPayload->Status = status;
3399285809Sscottl		return status;
3400285809Sscottl	}
3401285809Sscottl	status = IOCTL_CALL_SUCCESS;
3402285809Sscottl	return status;
3403285809Sscottl}
3404285809Sscottl
3405285809Sscottl
3406285809Sscottl#ifdef VPD_TESTING
3407285809Sscottl/* temporary to test saSetVPDCommand() and saGetVPDCommand */
3408285809SscottlosGLOBAL bit32
3409285809SscottltdsaVPDSet(
3410285809Sscottl                tiRoot_t            *tiRoot
3411285809Sscottl                )
3412285809Sscottl{
3413285809Sscottl  tdsaRoot_t    *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
3414285809Sscottl  tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3415285809Sscottl  agsaRoot_t    *agRoot = &(tdsaAllShared->agRootInt);
3416285809Sscottl  bit32         status = IOCTL_CALL_SUCCESS;
3417285809Sscottl  agsaVPD_t     VPDInfo;
3418285809Sscottl  bit32         ret = AGSA_RC_SUCCESS;
3419285809Sscottl
3420285809Sscottl  bit32                 bufAddrUpper = 0;
3421285809Sscottl  bit32                 bufAddrLower = 0;
3422285809Sscottl  tdVPDControl_t        *VPDControl;
3423285809Sscottl
3424285809Sscottl  void                  *osMemHandle = agNULL;
3425285809Sscottl  void                  *buffer;
3426285809Sscottl  bit32                 timeCount=0;
3427285809Sscottl  bit8                  ioctlErr=0;
3428285809Sscottl  bit8                  VPDPayload[32];
3429285809Sscottl  bit8                  i;
3430285809Sscottl  TI_DBG2(("tdsaVPDSet: start\n"));
3431285809Sscottl
3432285809Sscottl  for(i=0;i<sizeof(VPDPayload);i++)
3433285809Sscottl  {
3434285809Sscottl    VPDPayload[i] = i;
3435285809Sscottl  }
3436285809Sscottl  if(ostiAllocMemory( tiRoot,
3437285809Sscottl                        &osMemHandle,
3438285809Sscottl                        (void **)&buffer,
3439285809Sscottl                        &bufAddrUpper,
3440285809Sscottl                        &bufAddrLower,
3441285809Sscottl                        8,
3442285809Sscottl                        sizeof(VPDPayload),
3443285809Sscottl                        agFALSE))
3444285809Sscottl  {
3445285809Sscottl    return tiError;
3446285809Sscottl  }
3447285809Sscottl  osti_memcpy((void *)buffer,
3448285809Sscottl               VPDPayload,
3449285809Sscottl               sizeof(VPDPayload));
3450285809Sscottl
3451285809Sscottl
3452285809Sscottl  osti_memset(&VPDInfo, 0, sizeof(agsaVPD_t));
3453285809Sscottl#ifdef NOT_YET /* direct mode worked */
3454285809Sscottl  /* For now, only direct mode */
3455285809Sscottl  VPDInfo.indirectMode = 0; /* direct mode */
3456285809Sscottl  VPDInfo.VPDDevice = 1; /* SEEPROM-1 */
3457285809Sscottl  VPDInfo.directLen  = (bit8)sizeof(VPDPayload);
3458285809Sscottl  VPDInfo.VPDOffset = 0;
3459285809Sscottl  VPDInfo.directData = buffer;
3460285809Sscottl  VPDInfo.indirectAddrUpper32 = bufAddrUpper;
3461285809Sscottl  VPDInfo.indirectAddrLower32 = bufAddrLower;
3462285809Sscottl  VPDInfo.indirectLen = sizeof(VPDPayload);
3463285809Sscottl#endif
3464285809Sscottl
3465285809Sscottl  /* indirect mode */
3466285809Sscottl  VPDInfo.indirectMode = 1; /* indirect mode */
3467285809Sscottl  VPDInfo.VPDDevice = 1; /* SEEPROM-1 */
3468285809Sscottl  VPDInfo.directLen  = 0;
3469285809Sscottl  VPDInfo.VPDOffset = 0;
3470285809Sscottl  VPDInfo.directData = agNULL;
3471285809Sscottl  VPDInfo.indirectAddrUpper32 = bufAddrUpper;
3472285809Sscottl  VPDInfo.indirectAddrLower32 = bufAddrLower;
3473285809Sscottl  VPDInfo.indirectLen = sizeof(VPDPayload);
3474285809Sscottl
3475285809Sscottl  tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
3476285809Sscottl  tdsaAllShared->tdFWControlEx.param1 = agParam1;
3477285809Sscottl  tdsaAllShared->tdFWControlEx.param2 = agParam2;
3478285809Sscottl
3479285809Sscottl  /* for testing only */
3480285809Sscottl  tdsaAllShared->addrUpper = bufAddrUpper;
3481285809Sscottl  tdsaAllShared->addrLower = bufAddrLower;
3482285809Sscottl
3483285809Sscottl  ret = saSetVPDCommand(agRoot, agNULL, 0, &VPDInfo);
3484285809Sscottl
3485285809Sscottl  if (ret == AGSA_RC_SUCCESS)
3486285809Sscottl  {
3487285809Sscottl    status = tiSuccess;
3488285809Sscottl  }
3489285809Sscottl  else
3490285809Sscottl  {
3491285809Sscottl    status = tiError;
3492285809Sscottl  }
3493285809Sscottl
3494285809Sscottl    ostiFreeMemory(tiRoot, osMemHandle, sizeof(VPDPayload));
3495285809Sscottl  return status;
3496285809Sscottl}
3497285809Sscottl
3498285809Sscottl/* temporary to test saSetVPDCommand() and saGetVPDCommand */
3499285809SscottlosGLOBAL bit32
3500285809SscottltdsaVPDGet(tiRoot_t            *tiRoot)
3501285809Sscottl{
3502285809Sscottl  tdsaRoot_t    *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
3503285809Sscottl  tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3504285809Sscottl  agsaRoot_t    *agRoot = &(tdsaAllShared->agRootInt);
3505285809Sscottl  bit32         status = IOCTL_CALL_SUCCESS;
3506285809Sscottl  agsaVPD_t     VPDInfo;
3507285809Sscottl  bit32         ret = AGSA_RC_SUCCESS;
3508285809Sscottl
3509285809Sscottl
3510285809Sscottl  TI_DBG2(("tdsaVPDGet: start\n"));
3511285809Sscottl
3512285809Sscottl  osti_memset(&VPDInfo, 0, sizeof(agsaVPD_t));
3513285809Sscottl
3514285809Sscottl  /* direct mode worked */
3515285809Sscottl  VPDInfo.indirectMode = 0; /* direct mode */
3516285809Sscottl  VPDInfo.VPDDevice = 1; /* SEEPROM-1*/
3517285809Sscottl  VPDInfo.directLen  = 32;
3518285809Sscottl  VPDInfo.VPDOffset = 0;
3519285809Sscottl  VPDInfo.directData = agNULL;
3520285809Sscottl  VPDInfo.indirectAddrUpper32 = 0;
3521285809Sscottl  VPDInfo.indirectAddrLower32 = 0;
3522285809Sscottl  VPDInfo.indirectLen = 0;
3523285809Sscottl
3524285809Sscottl
3525285809Sscottl#ifdef NOT_YET /* worked; can't read VPD in ossaGetVPDResponseCB() because of indirect */
3526285809Sscottl  VPDInfo.indirectMode = 1; /* direct mode */
3527285809Sscottl  VPDInfo.VPDDevice = 1; /* SEEPROM-1*/
3528285809Sscottl  VPDInfo.directLen  = 0;
3529285809Sscottl  VPDInfo.VPDOffset = 0;
3530285809Sscottl  VPDInfo.directData = agNULL;
3531285809Sscottl  VPDInfo.indirectAddrUpper32 = tdsaAllShared->addrUpper;
3532285809Sscottl  VPDInfo.indirectAddrLower32 = tdsaAllShared->addrLower;
3533285809Sscottl  VPDInfo.indirectLen = 32;
3534285809Sscottl#endif
3535285809Sscottl  ret = saGetVPDCommand(agRoot, agNULL, 0, &VPDInfo);
3536285809Sscottl
3537285809Sscottl  if (ret == AGSA_RC_SUCCESS)
3538285809Sscottl  {
3539285809Sscottl    status = tiSuccess;
3540285809Sscottl  }
3541285809Sscottl  else
3542285809Sscottl  {
3543285809Sscottl    status = tiError;
3544285809Sscottl  }
3545285809Sscottl  return status;
3546285809Sscottl}
3547285809Sscottl#endif
3548285809Sscottl/*****************************************************************************
3549285809Sscottl*
3550285809Sscottl* tdsaGetNumOfLUNIOCTL
3551285809Sscottl*
3552285809Sscottl* Purpose:  This routine is called to send Report LUN SSP command request.
3553285809Sscottl*
3554285809Sscottl* Parameters:
3555285809Sscottl*   tiRoot:         Pointer to driver instance
3556285809Sscottl*   tiIOCTLPayload_t:        Status of the Controller Reset.
3557285809Sscottl*   agParam1:        Void pointer to device extension
3558285809Sscottl*   agParam2:        Void pointer to SRB
3559285809Sscottl*   agParam3:        NULL
3560285809Sscottl*
3561285809Sscottl*   Return: status
3562285809Sscottl*
3563285809Sscottl*
3564285809Sscottl*****************************************************************************/
3565285809SscottlosGLOBAL bit32
3566285809SscottltdsaGetNumOfLUNIOCTL(
3567285809Sscottl               tiRoot_t            *tiRoot,
3568285809Sscottl               tiIOCTLPayload_t    *agIOCTLPayload,
3569285809Sscottl               void                *agParam1,
3570285809Sscottl               void                *agParam2,
3571285809Sscottl               void                *agParam3
3572285809Sscottl               )
3573285809Sscottl{
3574285809Sscottl  tdsaRoot_t	              *tdsaRoot			= (tdsaRoot_t *) tiRoot->tdData;
3575285809Sscottl  tdsaContext_t               *tdsaAllShared 	= (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3576285809Sscottl  agsaRoot_t	              *agRoot 			= &(tdsaAllShared->agRootInt);
3577285809Sscottl  tdDeviceLUNInfoIOCTL_t	  *pDeviceLUNInfo	= agNULL;
3578285809Sscottl  tiDeviceHandle_t            *devHandle 		= agNULL;
3579285809Sscottl  void				          *tiRequestBody 	= agNULL;
3580285809Sscottl  tiIORequest_t 	          *tiIORequest 		= agNULL;
3581285809Sscottl  bit32			              status 			= IOCTL_CALL_SUCCESS;
3582285809Sscottl
3583285809Sscottl  TI_DBG2(("tdsaGetNumOfLUNIOCTL: Start\n"));
3584285809Sscottl  do
3585285809Sscottl  {
3586285809Sscottl    pDeviceLUNInfo = (tdDeviceLUNInfoIOCTL_t*)agIOCTLPayload->FunctionSpecificArea;
3587285809Sscottl
3588285809Sscottl    if (agIOCTLPayload->Length < sizeof(tdDeviceLUNInfoIOCTL_t))
3589285809Sscottl    {
3590285809Sscottl  	  status = IOCTL_CALL_FAIL;
3591285809Sscottl  	  break;
3592285809Sscottl    }
3593285809Sscottl    if(!pDeviceLUNInfo->tiDeviceHandle)
3594285809Sscottl    {
3595285809Sscottl      status = IOCTL_CALL_FAIL;
3596285809Sscottl      agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
3597285809Sscottl      break;
3598285809Sscottl    }
3599285809Sscottl	devHandle = (tiDeviceHandle_t*)pDeviceLUNInfo->tiDeviceHandle;
3600285809Sscottl	agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
3601285809Sscottl
3602285809Sscottl	status = ostiNumOfLUNIOCTLreq(tiRoot,agParam1,agParam2,&tiRequestBody,&tiIORequest);
3603285809Sscottl
3604285809Sscottl
3605285809Sscottl    if(status != AGSA_RC_SUCCESS)
3606285809Sscottl    {
3607285809Sscottl      agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
3608285809Sscottl	  break;
3609285809Sscottl    }
3610285809Sscottl    status = tiNumOfLunIOCTLreq(tiRoot,tiIORequest,devHandle,tiRequestBody,agIOCTLPayload,agParam1,agParam2);
3611285809Sscottl
3612285809Sscottl    if(status != AGSA_RC_SUCCESS)
3613285809Sscottl    {
3614285809Sscottl         agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
3615285809Sscottl	  break;
3616285809Sscottl    }
3617285809Sscottl//	ostiIOCTLWaitForSignal (tiRoot, agParam1, agParam2, agParam3);
3618285809Sscottl
3619285809Sscottl  }while(0);
3620285809Sscottl  TI_DBG2(("tdsaGetNumOfLUNIOCTL: End\n"));
3621285809Sscottl  return status;
3622285809Sscottl}
3623285809Sscottl
3624285809Sscottl
3625285809Sscottl/*****************************************************************************
3626285809Sscottl*
3627285809Sscottl* ostiNumOfLUNIOCTLRsp
3628285809Sscottl*
3629285809Sscottl* Purpose:  This routine is called when a Report LUN SSP command response id recieved.
3630285809Sscottl*
3631285809Sscottl* Parameters:
3632285809Sscottl*   tiRoot:         Pointer to driver instance
3633285809Sscottl*   bit32               status
3634285809Sscottl*
3635285809Sscottl* Return: none
3636285809Sscottl*
3637285809Sscottl*
3638285809Sscottl*****************************************************************************/
3639285809SscottlosGLOBAL void ostiNumOfLUNIOCTLRsp(
3640285809Sscottl                        tiRoot_t            *tiRoot,
3641285809Sscottl                        bit32               status
3642285809Sscottl                        )
3643285809Sscottl{
3644285809Sscottl  tdsaRoot_t                  *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
3645285809Sscottl  tdsaContext_t               *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3646285809Sscottl  tiIOCTLPayload_t            *agIOCTLPayload;
3647285809Sscottl  tdDeviceLUNInfoIOCTL_t	  *pDeviceLUNInfo = NULL;
3648285809Sscottl  bit32                       count = 0;
3649285809Sscottl  bit32                       numOfLUN =0;
3650285809Sscottl
3651285809Sscottl  TI_DBG1(("ostiNumOfLUNIOCTLRsp: start, status = %d\n", status));
3652285809Sscottl
3653285809Sscottl  if(tdsaAllShared->tdFWControlEx.inProgress == 1)
3654285809Sscottl  {
3655285809Sscottl    agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
3656285809Sscottl	if ((agIOCTLPayload) && (PMC_IOCTL_SIGNATURE == agIOCTLPayload->Signature)&&
3657285809Sscottl					   (IOCTL_MJ_GET_DEVICE_LUN == agIOCTLPayload->MajorFunction))
3658285809Sscottl	{
3659285809Sscottl      agIOCTLPayload->Status = (bit16)status;
3660285809Sscottl      pDeviceLUNInfo = (tdDeviceLUNInfoIOCTL_t*)agIOCTLPayload->FunctionSpecificArea;
3661285809Sscottl      numOfLUN = ((tdsaAllShared->tdFWControlEx.virtAddr[0] << 24)|(tdsaAllShared->tdFWControlEx.virtAddr[1] << 16)|\
3662285809Sscottl                 (tdsaAllShared->tdFWControlEx.virtAddr[2] << 8)|(tdsaAllShared->tdFWControlEx.virtAddr[3]));
3663285809Sscottl      numOfLUN = numOfLUN/8;
3664285809Sscottl      pDeviceLUNInfo->numOfLun = numOfLUN;
3665285809Sscottl//	  ostiFreeMemory(tiRoot,
3666285809Sscottl//                     tdsaAllShared->tdFWControlEx.virtAddr,
3667285809Sscottl//                     tdsaAllShared->tdFWControlEx.len);
3668285809Sscottl  //    if(tdsaAllShared->tdFWControlEx.param1 != agNULL)
3669285809Sscottl  //    {
3670285809Sscottl        ostiIOCTLSetSignal(tiRoot,
3671285809Sscottl                           tdsaAllShared->tdFWControlEx.param1,
3672285809Sscottl                           tdsaAllShared->tdFWControlEx.param2,
3673285809Sscottl                           NULL);
3674285809Sscottl  	    tdsaAllShared->tdFWControlEx.payload = NULL;
3675285809Sscottl  //    }
3676285809Sscottl
3677285809Sscottl	  tdsaAllShared->tdFWControlEx.inProgress = 0;
3678285809Sscottl	}
3679285809Sscottl  }
3680285809Sscottl  TI_DBG1(("ostiNumOfLUNIOCTLRsp: End\n"));
3681285809Sscottl}
3682285809Sscottl
3683