xref: /freebsd/sys/dev/pms/RefTisa/tisa/sassata/common/tdioctl.c (revision 193d9e768ba63fcfb187cfd17f461f7d41345048)
1 /*******************************************************************************
2 *Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3 *
4 *Redistribution and use in source and binary forms, with or without modification, are permitted provided
5 *that the following conditions are met:
6 *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7 *following disclaimer.
8 *2. Redistributions in binary form must reproduce the above copyright notice,
9 *this list of conditions and the following disclaimer in the documentation and/or other materials provided
10 *with the distribution.
11 *
12 *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 *WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 *FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16 *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18 *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19 *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20 
21 ********************************************************************************/
22 /*******************************************************************************/
23 /** \file
24  *
25  *
26  * This file contains Management IOCTL APIs
27  *
28  */
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31 #include <dev/pms/config.h>
32 
33 #include <dev/pms/freebsd/driver/common/osenv.h>
34 #include <dev/pms/freebsd/driver/common/ostypes.h>
35 #include <dev/pms/freebsd/driver/common/osdebug.h>
36 
37 #include <dev/pms/RefTisa/sallsdk/api/sa.h>
38 #include <dev/pms/RefTisa/sallsdk/api/saapi.h>
39 #include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
40 
41 #include <dev/pms/RefTisa/tisa/api/titypes.h>
42 #include <dev/pms/RefTisa/tisa/api/ostiapi.h>
43 #include <dev/pms/RefTisa/tisa/api/tiapi.h>
44 #include <dev/pms/RefTisa/tisa/api/tiglobal.h>
45 
46 #ifdef FDS_SM
47 #include <dev/pms/RefTisa/sat/api/sm.h>
48 #include <dev/pms/RefTisa/sat/api/smapi.h>
49 #include <dev/pms/RefTisa/sat/api/tdsmapi.h>
50 #endif
51 
52 #ifdef FDS_DM
53 #include <dev/pms/RefTisa/discovery/api/dm.h>
54 #include <dev/pms/RefTisa/discovery/api/dmapi.h>
55 #include <dev/pms/RefTisa/discovery/api/tddmapi.h>
56 #endif
57 
58 #include <dev/pms/RefTisa/tisa/sassata/sas/common/tdtypes.h>
59 #include <dev/pms/freebsd/driver/common/osstring.h>
60 #include <dev/pms/RefTisa/tisa/sassata/common/tdutil.h>
61 #include <dev/pms/RefTisa/sallsdk/spc/mpidebug.h>
62 
63 #ifdef INITIATOR_DRIVER
64 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdtypes.h>
65 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itddefs.h>
66 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdglobl.h>
67 #endif
68 
69 #ifdef TARGET_DRIVER
70 #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdglobl.h>
71 #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdxchg.h>
72 #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdtypes.h>
73 #endif
74 
75 #include <dev/pms/RefTisa/tisa/sassata/common/tdsatypes.h>
76 #include <dev/pms/RefTisa/tisa/sassata/common/tdproto.h>
77 #include <dev/pms/RefTisa/tisa/sassata/common/tdioctl.h>
78 
79 #include <dev/pms/RefTisa/sallsdk/spc/sadefs.h>
80 #include <dev/pms/RefTisa/sallsdk/spc/spcdefs.h>
81 #include <dev/pms/RefTisa/sallsdk/spc/mpi.h>
82 #include <dev/pms/RefTisa/sallsdk/spc/sallist.h>
83 #include <dev/pms/RefTisa/sallsdk/spc/satypes.h>
84 
85 
86 #define agFieldOffset(baseType,fieldName) \
87             /*lint -e545 */ \
88             ((bit32)((bitptr)(&(((baseType *)0)->fieldName)))) \
89 
90 #ifdef SA_LL_API_TEST
91 osGLOBAL bit32 tdLlApiTestIoctl(tiRoot_t *tiRoot,
92                                 tiIOCTLPayload_t *agIOCTLPayload,
93                                 void *agParam1,
94                                 void *agParam2,
95                                 void *agParam3);
96 #endif /* SA_LL_API_TEST */
97 
98 
99 extern bit32 volatile sgpioResponseSet;
100 
101 #ifdef SPC_ENABLE_PROFILE
102 /*****************************************************************************
103 *
104 * tdipFWProfileIoctl
105 *
106 * Purpose:  This routine is called to process the FW Profile IOCTL function.
107 *           This function is used for both target and initiator.
108 *
109 * Parameters:
110 *   tiRoot:         Pointer to driver instance
111 *   agIOCTLPayload: Pointer to the IOCTL payload.
112 *   agParam1:       Pointer to pass context handle for IOCTL DMA operation
113 *   agParam2:       Pointer to pass context handle for IOCTL DMA operation
114 *   agParam3:       Pointer to pass context handle for IOCTL DMA operation
115 *
116 * Return:
117 *
118 *   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
119 *   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
120 *                             Detail error code is function specific and
121 *                             defined by the specific IOCTL function.
122 *   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
123 *
124 *
125 *****************************************************************************/
126 osGLOBAL bit32 tdipFWProfileIoctl(
127                         tiRoot_t            *tiRoot,
128                         tiIOCTLPayload_t    *agIOCTLPayload,
129                         void                *agParam1,
130                         void                *agParam2,
131                         void                *agParam3
132                         )
133 {
134 
135   bit32                status = IOCTL_CALL_SUCCESS;
136   bit32                bufAddrUpper = 0;
137   bit32                bufAddrLower = 0;
138   tdFWProfile_t        *fwProfile;
139 
140   void                 *osMemHandle = agNULL;
141   void                 *buffer = agNULL;
142   agsaFwProfile_t     fwProfileInfo = {0};
143 
144   tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
145   tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
146   agsaRoot_t           *agRoot = &tdsaAllShared->agRootInt;
147 
148   fwProfile = (tdFWProfile_t *)&agIOCTLPayload->FunctionSpecificArea[0];
149 
150 
151   fwProfileInfo.processor = fwProfile->processor;
152   fwProfileInfo.cmd = fwProfile->cmd;
153   fwProfileInfo.len = fwProfile->len;
154   fwProfileInfo.tcid = fwProfile->tcid;
155   if(fwProfile->cmd == START_CODE_PROFILE)
156   {
157     fwProfileInfo.codeStartAdd = fwProfile->codeStartAdd;
158       fwProfileInfo.codeEndAdd = fwProfile->codeEndAdd;
159   }
160   if((fwProfile->cmd == STOP_TIMER_PROFILE) || (fwProfile->cmd == STOP_CODE_PROFILE))
161   {
162     if(fwProfile->len != 0)
163     {
164       if(ostiAllocMemory( tiRoot,
165               &osMemHandle,
166               (void **)&buffer,
167               &bufAddrUpper,
168               &bufAddrLower,
169               8,
170               fwProfile->len,
171               agFALSE))
172         {
173           return IOCTL_CALL_FAIL;
174         }
175       osti_memset((void *)buffer, 0, fwProfile->len);
176     }
177     fwProfileInfo.agSgl.sgLower = bufAddrLower;
178     fwProfileInfo.agSgl.sgUpper = bufAddrUpper;
179     fwProfileInfo.agSgl.len = fwProfile->len;
180     fwProfileInfo.agSgl.extReserved = 0;
181     tdsaAllShared->tdFWProfileEx.buffer = osMemHandle;
182     tdsaAllShared->tdFWProfileEx.virtAddr = buffer;
183     tdsaAllShared->tdFWProfileEx.len = fwProfile->len;
184   }
185   tdsaAllShared->tdFWProfileEx.tdFWProfile = fwProfile;
186   tdsaAllShared->tdFWProfileEx.param1 = agParam1;
187   tdsaAllShared->tdFWProfileEx.param2 = agParam2;
188   tdsaAllShared->tdFWProfileEx.payload = agIOCTLPayload;
189   tdsaAllShared->tdFWProfileEx.inProgress = 1;
190   status = saFwProfile(agRoot,
191             agNULL,
192             0,
193             &fwProfileInfo
194             );
195   if(status)
196   {
197     if((fwProfile->cmd == STOP_TIMER_PROFILE) || (fwProfile->cmd == STOP_CODE_PROFILE))
198       ostiFreeMemory(tiRoot, osMemHandle, fwProfile->len);
199     status = IOCTL_CALL_FAIL;
200   }
201   else
202     status = IOCTL_CALL_PENDING;
203   return status;
204 }
205 
206 
207 #endif
208 
209 /*****************************************************************************
210 *
211 * tdipFWControlIoctl
212 *
213 * Purpose:  This routine is called to process the FW control IOCTL function.
214 *           This function is used for both target and initiator.
215 *
216 * Parameters:
217 *   tiRoot:         Pointer to driver instance
218 *   agIOCTLPayload: Pointer to the IOCTL payload.
219 *   agParam1:       Pointer to pass context handle for IOCTL DMA operation
220 *   agParam2:       Pointer to pass context handle for IOCTL DMA operation
221 *   agParam3:       Pointer to pass context handle for IOCTL DMA operation
222 *
223 * Return:
224 *
225 *   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
226 *   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
227 *                             Detail error code is function specific and
228 *                             defined by the specific IOCTL function.
229 *   IOCTL_CALL_PENDING        This request is asynchronous and completed
230 *                             in some other context.
231 *   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
232 *
233 *
234 *****************************************************************************/
235 osGLOBAL bit32 tdipFWControlIoctl(
236   tiRoot_t            *tiRoot,
237   tiIOCTLPayload_t    *agIOCTLPayload,
238   void                *agParam1,
239   void                *agParam2,
240   void                *agParam3
241   ) {
242 
243   bit32               status = IOCTL_CALL_PENDING;
244   bit32               bufAddrUpper = 0;
245   bit32               bufAddrLower = 0;
246   tdFWControl_t      *fwControl;
247   void               *osMemHandle = agNULL;
248   void               *buffer = agNULL;
249   agsaUpdateFwFlash_t flashUpdateInfo;
250   tdsaRoot_t         *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
251   tdsaContext_t      *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
252   agsaRoot_t         *agRoot = &tdsaAllShared->agRootInt;
253 
254   if( agIOCTLPayload->Length <
255       ( agFieldOffset(tiIOCTLPayload_t, FunctionSpecificArea) +
256         sizeof(tdFWControl_t) ) )  {
257     agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
258     status = IOCTL_CALL_FAIL;
259     return status;
260   }
261   fwControl = (tdFWControl_t *)&agIOCTLPayload->FunctionSpecificArea[0];
262 
263   if(fwControl->len != 0)
264   {
265     if(ostiAllocMemory( tiRoot,
266                         &osMemHandle,
267                         (void **)&buffer,
268                         &bufAddrUpper,
269                         &bufAddrLower,
270                         8,
271                         fwControl->len,
272                         agFALSE) )
273       return IOCTL_CALL_FAIL;
274   }
275   osti_memset( (void *)buffer, 0, fwControl->len );
276   osti_memcpy( (void *)buffer,
277                fwControl->buffer,
278                fwControl->len );
279   flashUpdateInfo.agSgl.sgLower = bufAddrLower;
280   flashUpdateInfo.agSgl.sgUpper = bufAddrUpper;
281   flashUpdateInfo.agSgl.len     = fwControl->len;
282   flashUpdateInfo.agSgl.extReserved  = 0;
283   flashUpdateInfo.currentImageOffset = fwControl->offset;
284   flashUpdateInfo.currentImageLen    = fwControl->len;
285   flashUpdateInfo.totalImageLen      = fwControl->size;
286   switch (agIOCTLPayload->MinorFunction)
287   {
288     case IOCTL_MN_FW_DOWNLOAD_DATA:
289     {
290       TI_DBG6(("tdipFWControlIoctl: calling saFwFlashUpdate\n"));
291       tdsaAllShared->tdFWControlEx.tdFWControl = fwControl;
292       tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
293       tdsaAllShared->tdFWControlEx.param1 = agParam1;
294       tdsaAllShared->tdFWControlEx.param2 = agParam2;
295       tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
296       tdsaAllShared->tdFWControlEx.inProgress = 1;
297       status = saFwFlashUpdate( agRoot,
298                                 agNULL,
299                                 0,
300                                 &flashUpdateInfo );
301       if(status) {
302         status = IOCTL_CALL_FAIL;
303         fwControl->retcode = IOCTL_CALL_TIMEOUT;
304       }
305       else {
306         status = IOCTL_CALL_PENDING;
307       }
308       break;
309     }
310     default:
311       status = IOCTL_CALL_INVALID_CODE;
312       TI_DBG1( ("tdipFWControlIoctl: ERROR: Wrong IOCTL code %d\n",
313                 agIOCTLPayload->MinorFunction) );
314       ostiFreeMemory(tiRoot, osMemHandle, fwControl->len);
315       return status;
316   } /* end IOCTL switch */
317   return status;
318 } /* tdipFWControlIoctl */
319 
320 
321 /*****************************************************************************
322 *
323 * tiCOMMgntIOCTL
324 *
325 * Purpose:  This routine is a TISA API for processing the PMC specific
326 *           IOCTL function.
327 *
328 *           Each IOCTL function is identified by the IOCTL header
329 *           specified in the data payload as the following:
330 *           Field                 Description
331 *           -----                 -----------
332 *           Signature             PMC IOCTL signature.
333 *                                 #define PMC_IOCTL_SIGNATURE   0x1234
334 *           MajorFunction         Major function number.
335 *           MinorFunction         Minor function number.
336 *           Length                Length of this structure in bytes.
337 *           Status                Return status for this IOCTL function.
338 *           FunctionSpecificArea  Variable length function specific area.
339 *
340 * Parameters:
341 *   tiRoot:         Pointer to driver instance
342 *   agIOCTLPayload: Pointer to the IOCTL payload.
343 *   agParam1:       Pointer to pass context handle for IOCTL DMA operation
344 *   agParam2:       Pointer to pass context handle for IOCTL DMA operation
345 *   agParam3:       Pointer to pass context handle for IOCTL DMA operation
346 *
347 * Return:
348 *
349 *   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
350 *   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
351 *                             Detail error code is function specific and
352 *                             defined by the specific IOCTL function.
353 *   IOCTL_CALL_PENDING        This request is asynchronous and completed
354 *                             in some other context.
355 *   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
356 *   IOCTL_CALL_INVALID_DEVICE Invalid target or destination device.
357 *
358 * Note:
359 *  Used ostiAllocMemory() OS layer callback function to allocate memory
360 *  for DMA operaion. Then use ostiFreeMemory() to deallocate the memory.
361 *
362 *****************************************************************************/
363 osGLOBAL bit32
364 tiCOMMgntIOCTL(
365                tiRoot_t            *tiRoot,
366                tiIOCTLPayload_t    *agIOCTLPayload,
367                void                *agParam1,
368                void                *agParam2,
369                void                *agParam3
370                )
371 {
372   bit32                     status = IOCTL_CALL_INVALID_CODE;
373   tdsaRoot_t                *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
374   tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
375   agsaRoot_t                *agRoot = &(tdsaAllShared->agRootNonInt);
376   bit32                     EventLogLength = 0;
377   bit32                     EventLogOption;
378   bit32                     ReadLength = 0;
379   bit32                     Offset = 0;
380   bit32                     RequestLength = 0;  /* user request on how much data to pass to application */
381   agsaContext_t		    *agContext = NULL;
382   bit8                      *loc = NULL;
383 
384   TI_DBG3(("tiCOMMgntIOCTL: start\n"));
385 
386   TI_DBG3(("tiCOMMgntIOCTL: tiRoot %p agIOCTLPayload %p agParam1 %p agParam2 %p agParam3 %p\n",
387                             tiRoot,agIOCTLPayload,agParam1,agParam2,agParam3 ));
388 
389   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",
390                            agIOCTLPayload->Signature,
391                            agIOCTLPayload->MajorFunction,
392                            agIOCTLPayload->MinorFunction,
393                            agIOCTLPayload->Length,
394                            agIOCTLPayload->Status,
395                            agIOCTLPayload->Reserved,
396                            agIOCTLPayload->FunctionSpecificArea[0] ));
397 
398   /* PMC IOCTL signatures matched ? */
399   if(agIOCTLPayload->Signature != PMC_IOCTL_SIGNATURE)
400   {
401     TI_DBG1(("tiCOMMgntIOCTL:agIOCTLPayload->Signature %x IOCTL_CALL_INVALID_CODE\n",agIOCTLPayload->Signature ));
402     status = IOCTL_CALL_INVALID_CODE;
403     return (status);
404   }
405 
406   switch (agIOCTLPayload->MajorFunction)
407   {
408 //TODO: make the card identification more robust. For now - just to keep going with FW download
409 #ifdef IOCTL_INTERRUPT_TIME_CONFIG
410   case IOCTL_MJ_CARD_PARAMETER:
411   {
412     switch( agIOCTLPayload->MinorFunction )
413     {
414       case  IOCTL_MN_CARD_GET_INTERRUPT_CONFIG:
415       {
416           agsaInterruptConfigPage_t *pInterruptConfig = (agsaInterruptConfigPage_t *)&agIOCTLPayload->FunctionSpecificArea[0];
417           status = saGetControllerConfig(agRoot,
418                                 0,
419                                 AGSA_INTERRUPT_CONFIGURATION_PAGE,
420                                 pInterruptConfig->vectorMask0,
421                                 pInterruptConfig->vectorMask1,
422                                 agParam2);
423           if(status == AGSA_RC_SUCCESS) {
424               status = IOCTL_CALL_PENDING;
425               agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
426           } else {
427               agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
428           }
429           break;
430       }
431       case  IOCTL_MN_CARD_GET_TIMER_CONFIG:
432           status = saGetControllerConfig(agRoot, 0, AGSA_SAS_PROTOCOL_TIMER_CONFIG_PAGE, 0, 0, agParam2);
433           if(status == AGSA_RC_SUCCESS) {
434               status = IOCTL_CALL_PENDING;
435               agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
436           } else {
437               agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
438           }
439           break;
440     }
441     break;
442   }
443 #endif /* IOCTL_INTERRUPT_TIME_CONFIG */
444   case IOCTL_MJ_INI_DRIVER_IDENTIFY:
445   {
446     status=IOCTL_CALL_SUCCESS;
447     break;
448   }
449   case IOCTL_MJ_GET_DEVICE_LUN:
450 		status = tdsaGetNumOfLUNIOCTL(tiRoot,agIOCTLPayload, agParam1, agParam2, agParam3);
451     	if(status == IOCTL_CALL_SUCCESS)
452         {
453     	  status = IOCTL_CALL_PENDING;
454     	}
455    break;
456 case IOCTL_MJ_SMP_REQUEST:
457 	status = tdsaSendSMPIoctl(tiRoot, agIOCTLPayload,
458              	agParam1,agParam2,agParam3);
459 	break;
460 
461   case IOCTL_MJ_FW_CONTROL:
462   {
463     //ostiIOCTLClearSignal (tiRoot, &agParam1, &agParam2, &agParam3);
464     status = tdipFWControlIoctl( tiRoot, agIOCTLPayload,
465                                    agParam1, agParam2, agParam3);
466 
467     break;
468   }
469 //#ifdef EVENT_LOG_INFO_TESTING
470   /* Reserved field in tiIOCTLPayload_t is used as offset */
471   case IOCTL_MJ_GET_EVENT_LOG1:
472   {
473     switch (agIOCTLPayload->MinorFunction)
474     {
475       case IOCTL_MN_FW_GET_TRACE_BUFFER:
476       {
477         agsaControllerEventLog_t EventLog;
478         saGetControllerEventLogInfo(agRoot, &EventLog);
479         TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MJ_GET_EVENT_LOG1 Length %d\n", agIOCTLPayload->Length));
480         RequestLength = agIOCTLPayload->Length;
481         Offset = agIOCTLPayload->Reserved;
482         EventLogLength = EventLog.eventLog1.totalLength;
483         EventLogOption = EventLog.eventLog1Option;
484         if (EventLogLength <= Offset)
485         {
486           TI_DBG1(("tiCOMMgntIOCTL: 1 out of range Requestlength %d Offset %d event log length %d\n", RequestLength, Offset, EventLogLength));
487           // out of range
488           agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
489           agIOCTLPayload->Length = 0;
490           if(EventLogOption == 0)
491           {
492             agIOCTLPayload->Status = IOCTL_ERR_FW_EVENTLOG_DISABLED;
493           }
494           status=IOCTL_CALL_SUCCESS;
495           return status;
496          }
497         ReadLength = MIN(EventLogLength - Offset, RequestLength);
498         loc = (bit8 *)EventLog.eventLog1.virtPtr + Offset;
499         osti_memcpy(&(agIOCTLPayload->FunctionSpecificArea), loc, ReadLength);
500       //   tdhexdump("IOCTL_MJ_GET_EVENT_LOG1 first 32bytes", (bit8 *)&(agIOCTLPayload->FunctionSpecificArea), 32);
501         agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
502         agIOCTLPayload->Length = (bit16)ReadLength;
503         status=IOCTL_CALL_SUCCESS;
504         break;
505      }
506      case IOCTL_MN_FW_GET_EVENT_FLASH_LOG1:
507      {
508        TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MN_FW_GET_EVENT_FLASH_LOG1\n"));
509        status = tdsaRegDumpGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
510        break;
511      }
512    }
513    break;
514   }
515 
516   case IOCTL_MJ_GET_EVENT_LOG2:
517   {
518     switch (agIOCTLPayload->MinorFunction)
519     {
520       case IOCTL_MN_FW_GET_TRACE_BUFFER:
521       {
522         agsaControllerEventLog_t EventLog;
523         saGetControllerEventLogInfo(agRoot, &EventLog);
524         TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MJ_GET_EVENT_LOG2 Length %d\n", agIOCTLPayload->Length));
525         RequestLength = agIOCTLPayload->Length;
526         Offset = agIOCTLPayload->Reserved;
527         EventLogLength = EventLog.eventLog2.totalLength;
528         EventLogOption = EventLog.eventLog2Option;
529         if (EventLogLength <= Offset)
530         {
531           TI_DBG1(("tiCOMMgntIOCTL: 2 out of range Requestlength %d Offset %d event log length %d\n", RequestLength, Offset, EventLogLength));
532           /* out of range */
533           agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
534           agIOCTLPayload->Length = 0;
535           if(EventLogOption == 0)
536           {
537             agIOCTLPayload->Status = IOCTL_ERR_FW_EVENTLOG_DISABLED;
538           }
539           status=IOCTL_CALL_SUCCESS;
540           return status;
541         }
542         ReadLength = MIN(EventLogLength - Offset, RequestLength);
543         loc = (bit8 *)EventLog.eventLog2.virtPtr + Offset;
544         osti_memcpy(&(agIOCTLPayload->FunctionSpecificArea), loc, ReadLength);
545     //    tdhexdump("IOCTL_MJ_GET_EVENT_LOG2 first 32bytes", (bit8 *)&(agIOCTLPayload->FunctionSpecificArea), 32);
546         agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
547         agIOCTLPayload->Length = (bit16)ReadLength;
548         status=IOCTL_CALL_SUCCESS;
549         break;
550       }
551       case IOCTL_MN_FW_GET_EVENT_FLASH_LOG2:
552       {
553         TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MN_FW_GET_EVENT_FLASH_LOG2\n"));
554         status = tdsaRegDumpGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
555         break;
556       }
557     }
558     break;
559   }
560 
561 
562   case IOCTL_MJ_FW_INFO:
563   {
564     agsaControllerInfo_t ControllerInfo;
565     saGetControllerInfo(agRoot, &ControllerInfo);
566     TI_DBG1(("tiCOMMgntIOCTL: IOCTL_MJ_FW_INFO Length %d\n", agIOCTLPayload->Length));
567     RequestLength = agIOCTLPayload->Length;
568     Offset = agIOCTLPayload->Reserved;
569     if (RequestLength == 0)
570     {
571       TI_DBG1(("tiCOMMgntIOCTL: IOCTL_MJ_FW_INFO: No more Data!\n"));
572       /* out of range */
573       agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
574       agIOCTLPayload->Length = 0;
575       status=IOCTL_CALL_SUCCESS;
576       return status;
577     }
578 
579     osti_memcpy((bit8*)&(agIOCTLPayload->FunctionSpecificArea), (bit8*)&ControllerInfo, sizeof(agsaControllerInfo_t));
580 
581     TI_DBG1(("tiCOMMgntIOCTL:IOCTL_MJ_FW_INFO ControllerInfo signature 0x%X\n",ControllerInfo.signature));
582     TI_DBG1(("tiCOMMgntIOCTL:IOCTL_MJ_FW_INFO ControllerInfo PCILinkRate 0x%X\n",ControllerInfo.PCILinkRate));
583     TI_DBG1(("tiCOMMgntIOCTL:IOCTL_MJ_FW_INFO ControllerInfo PCIWidth 0x%X\n",ControllerInfo.PCIWidth));
584     agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
585     status=IOCTL_CALL_SUCCESS;
586     break;
587 
588   }
589 
590   case IOCTL_MJ_GET_FW_REV:
591   {
592     agsaControllerInfo_t ControllerInfo;
593     saGetControllerInfo(agRoot, &ControllerInfo);
594     TI_DBG3(("tiCOMMgntIOCTL: IOCTL_MJ_GET_FW_REV Length %d\n", agIOCTLPayload->Length));
595     RequestLength = agIOCTLPayload->Length;
596     Offset = agIOCTLPayload->Reserved;
597     if (RequestLength == 0)
598     {
599       TI_DBG1(("tiCOMMgntIOCTL: IOCTL_MJ_GET_FW_REV: No more Data!\n"));
600       /* out of range */
601       agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
602       agIOCTLPayload->Length = 0;
603       status=IOCTL_CALL_SUCCESS;
604       return status;
605     }
606 
607     osti_memcpy((bit8*)&(agIOCTLPayload->FunctionSpecificArea), (bit8*)&ControllerInfo.fwRevision, sizeof(bit32));
608     loc = (bit8 *)&(agIOCTLPayload->FunctionSpecificArea)+ sizeof(bit32);
609     osti_memcpy(loc, (bit8*)&ControllerInfo.sdkRevision, sizeof(bit32));
610 
611     agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
612     status=IOCTL_CALL_SUCCESS;
613     break;
614 
615   }
616 
617 #ifdef SPC_ENABLE_PROFILE
618   case IOCTL_MJ_FW_PROFILE:
619   {
620     TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MJ_FW_PROFILE\n"));
621     status = tdipFWProfileIoctl( tiRoot, agIOCTLPayload,
622                                    agParam1, agParam2, agParam3);
623     break;
624   }
625 #endif /* SPC_ENABLE_PROFILE */
626 
627   case IOCTL_MJ_GET_CORE_DUMP:
628   {
629     TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MJ_GET_CORE_DUMP\n"));
630     if (tiIS_SPC(agRoot))
631     {
632       status = tdsaRegDumpGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
633     }
634     else
635     {
636       agIOCTLPayload->Status = IOCTL_ERR_STATUS_NOT_SUPPORTED;
637       status = IOCTL_CALL_SUCCESS;
638     }
639     break;
640   }
641 //#endif
642   case IOCTL_MJ_NVMD_SET:
643   {
644     bit8 nvmDev;
645     TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MJ_NVMD_SET\n"));
646     nvmDev = (bit8) agIOCTLPayload->Status;
647     agIOCTLPayload->Status = 0;
648     status = tdsaNVMDSetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, &nvmDev);
649 	break;
650 	}
651 #if 0
652 case IOCTL_MJ_GPIO:
653   {
654     bit32 sVid =0;
655     TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MJ_GPIO\n"));
656 
657     /* Get Subsystem vendor  */
658     sVid = ostiChipConfigReadBit32(tiRoot,0x2C);
659     sVid = sVid & 0xFFFF;
660 
661     /* GPIO is only intended for chip down design
662      * therefore it's only applies to 8H/SPCv product family
663      */
664     if(sVid == 0x9005)
665     return IOCTL_CALL_INVALID_DEVICE;
666 
667     status = tdsaGpioSetup(tiRoot, agContext, agIOCTLPayload, agParam1, agParam2);
668     if(status == IOCTL_CALL_SUCCESS)
669         status = IOCTL_CALL_PENDING; /* Wait for response from the Controller */
670     else
671       return status;
672 
673     break;
674   }
675 #endif
676 
677   case IOCTL_MJ_SGPIO:
678   {
679     TI_DBG6(("tiCOMMgntIOCTL: IOCTL_MJ_SGPIO\n"));
680     status = tdsaSGpioIoctlSetup(tiRoot, agContext, agIOCTLPayload, agParam1, agParam2);
681     break;
682   }
683 
684   case IOCTL_MJ_NVMD_GET:
685   {
686     bit8 nvmDev;
687     TI_DBG3(("tiCOMMgntIOCTL: IOCTL_MJ_NVMD_GET\n"));
688     nvmDev = (bit8) agIOCTLPayload->Status;
689     agIOCTLPayload->Status = 0;
690     status = tdsaNVMDGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, &nvmDev);
691     break;
692   }
693 
694   case IOCTL_MJ_GET_FORENSIC_DATA:
695   {
696     TI_DBG3(("tiCOMMgntIOCTL: IOCTL_MJ_GET_FORENSIC_DATA\n"));
697     status = tdsaForensicDataGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
698     break;
699   }
700   case IOCTL_MJ_GET_DEVICE_INFO:
701   {
702     TI_DBG3(("tiCOMMgntIOCTL: IOCTL_MJ_GET_DEVICE_INFO\n"));
703     status = tdsaDeviceInfoGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
704     break;
705   }
706 
707   case IOCTL_MJ_GET_IO_ERROR_STATISTIC:
708   {
709     TI_DBG3(("tiCOMMgntIOCTL: IOCTL_MJ_GET_IO_ERROR_STATISTIC\n"));
710     status = tdsaIoErrorStatisticGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
711     break;
712   }
713 
714   case IOCTL_MJ_GET_IO_EVENT_STATISTIC:
715   {
716     TI_DBG3(("tiCOMMgntIOCTL: IOCTL_MJ_GET_IO_EVENT_STATISTIC\n"));
717     status = tdsaIoEventStatisticGetIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
718     break;
719   }
720 
721   case IOCTL_MJ_SEND_BIST:
722   {
723     TI_DBG1(("tiCOMMgntIOCTL: IOCTL_MJ_SEND_BIST\n"));
724     status = tdsaSendBISTIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
725     break;
726   }
727 
728 #if 0
729   case IOCTL_MJ_SET_OR_GET_REGISTER:
730   {
731     TI_DBG3(("tiCOMMgntIOCTL: IOCTL_MJ_SET_OR_GET_REGISTER\n"));
732     status = tdsaRegisterIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
733     break;
734   }
735 
736 #endif
737    case IOCTL_MJ_PHY_DETAILS:
738    {
739 	PhyDetails_t  *PhyDetails = (PhyDetails_t*)&agIOCTLPayload->FunctionSpecificArea;
740         agsaRoot_t  *agRoot = &(tdsaAllShared->agRootNonInt);
741         agsaLLRoot_t  *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
742 	bit8  *sasAddressHi;
743 	bit8  *sasAddressLo;
744 	bit8  sas_dev_type;
745 	int i = 0;
746 
747 	tiIniGetDirectSataSasAddr(tiRoot, i , &sasAddressHi, &sasAddressLo);
748 	for( i = 0; i < saRoot->phyCount ; i++)
749         {
750 		PhyDetails[i].attached_phy = saRoot->phys[i].sasIdentify.phyIdentifier;
751 		/* deice types
752  		 * SAS
753  		 * 0x01 - Sas end device
754  		 * 0x02 - Expander device
755  		 * SATA
756  		 * 0x11 - Sata
757  		 * NO DEVICE 0x00
758  		 */
759 		sas_dev_type = (saRoot->phys[i].sasIdentify.deviceType_addressFrameType & 0x70 ) >> 4 ;
760 		if ((saRoot->phys[i].status == 1) && (sas_dev_type == 0)){ //status 1 - Phy Up
761 			//Sata phy
762 			PhyDetails[i].attached_dev_type = SAS_PHY_SATA_DEVICE;//0x11 for sata end device
763 			osti_memcpy(&PhyDetails[i].attached_sasAddressHi, tdsaAllShared->Ports[i].SASID.sasAddressHi, sizeof(bit32));
764 			osti_memcpy(&PhyDetails[i].attached_sasAddressLo, tdsaAllShared->Ports[i].SASID.sasAddressLo, sizeof(bit32));
765 			PhyDetails[i].attached_sasAddressLo[3] += i + 16;
766 		}
767 		else {
768 			PhyDetails[i].attached_dev_type = sas_dev_type;
769 	        	osti_memcpy(&PhyDetails[i].attached_sasAddressHi, saRoot->phys[i].sasIdentify.sasAddressHi, sizeof(bit32));
770 			osti_memcpy(&PhyDetails[i].attached_sasAddressLo, saRoot->phys[i].sasIdentify.sasAddressLo, sizeof(bit32));
771 		}
772 		osti_memcpy(&PhyDetails[i].sasAddressLo,&(tdsaAllShared->Ports[i].SASID.sasAddressLo), sizeof(bit32));
773 		osti_memcpy(&PhyDetails[i].sasAddressHi,&(tdsaAllShared->Ports[i].SASID.sasAddressHi), sizeof(bit32));
774 	}
775 
776 //    	osti_memcpy(&agIoctlPayload->FunctionSpecificArea,&PhyInfo, sizeof(agsaSGpioReqResponse_t));
777 //	printk("Ioctl success\n");
778 	return IOCTL_CALL_SUCCESS;
779    }
780 
781    case IOCTL_MJ_PHY_GENERAL_STATUS:
782  	  {
783 		agsaPhyGeneralState_t     *PhyData=NULL;
784 		bit32					   ret = AGSA_RC_FAILURE;
785   		PhyData = (agsaPhyGeneralState_t*) &agIOCTLPayload->FunctionSpecificArea[0];
786 
787         PhyData->Reserved2 = 0;
788         /* Validate the length */
789         if (agIOCTLPayload->Length < sizeof(agsaPhyGeneralState_t))
790         {
791           status = IOCTL_CALL_FAIL;
792           break;
793         }
794 
795         tdsaAllShared->tdFWControlEx.param1 = agParam1;
796         tdsaAllShared->tdFWControlEx.param2 = agParam2;
797         tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
798         tdsaAllShared->tdFWControlEx.inProgress = 1;
799 	//tdsaAllShared->tdFWControlEx.usrAddr = PhyData;
800 
801     	ret = tdsaGetPhyGeneralStatusIoctl(tiRoot,PhyData);
802     	if(ret == AGSA_RC_FAILURE)
803         {
804     	  status = IOCTL_CALL_FAIL;
805 		  tdsaAllShared->tdFWControlEx.payload = NULL;
806 		  tdsaAllShared->tdFWControlEx.inProgress = 0;
807 		  break;
808     	}
809 		else if(ret == IOCTL_ERR_STATUS_NOT_SUPPORTED)
810 		{
811 
812 		  agIOCTLPayload->Status = IOCTL_ERR_STATUS_NOT_SUPPORTED;
813 		  status = IOCTL_CALL_SUCCESS;
814 		  break;
815 		}
816 
817     	//status = IOCTL_CALL_PENDING;
818     	status = IOCTL_CALL_PENDING;
819      }
820 
821    break;
822 #if 1
823   case IOCTL_MJ_GET_PHY_PROFILE:
824   {
825     TI_DBG1(("tiCOMMgntIOCTL: IOCTL_MJ_GET_PHY_PROFILE %p %p %p\n",agParam1,agParam2,agParam3));
826     status = tdsaPhyProfileIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, agParam3);
827     break;
828   }
829 #endif
830   case IOCTL_MJ_LL_TRACING:
831   {
832     void * stu = &agIOCTLPayload->FunctionSpecificArea[0];
833     switch(agIOCTLPayload->MinorFunction)
834     {
835 
836       case IOCTL_MN_LL_RESET_TRACE_INDEX:
837       {
838 
839 #ifdef SA_ENABLE_TRACE_FUNCTIONS
840         TSTMTID_TRACE_BUFFER_RESET *llist = (TSTMTID_TRACE_BUFFER_RESET *)stu;
841         hpTraceBufferParms_t  BufferParms;
842         TI_DBG5(("tdReturnIOCTL_Info: hpIOCTL_ResetTraceIndex\n"));
843 
844         BufferParms.TraceCompiled  = 0;
845         BufferParms.TraceWrap      = 0;
846         BufferParms.CurrentTraceIndexWrapCount = 0;
847         BufferParms.BufferSize     = 0;
848         BufferParms.CurrentIndex   = 0;
849         BufferParms.pTrace         = NULL;
850         BufferParms.pTraceIndexWrapCount        = NULL;
851         BufferParms.pTraceMask     = NULL;
852         BufferParms.pCurrentTraceIndex  = NULL;
853 
854         smTraceGetInfo(agRoot,&BufferParms);
855         TI_DBG5(("tdReturnIOCTL_Info: pTrace                %p\n",BufferParms.pTrace));
856         TI_DBG5(("tdReturnIOCTL_Info: pCurrentTraceIndex    %p %X\n",BufferParms.pCurrentTraceIndex,*BufferParms.pCurrentTraceIndex));
857         TI_DBG5(("tdReturnIOCTL_Info: pTraceIndexWrapCount  %p %X\n",BufferParms.pTraceIndexWrapCount,*BufferParms.pTraceIndexWrapCount));
858         TI_DBG5(("tdReturnIOCTL_Info: pTraceMask            %p %X\n",BufferParms.pTraceMask,*BufferParms.pTraceMask));
859 
860         if( llist->Flag != 0)
861         {
862           if( llist->TraceMask != *BufferParms.pTraceMask)
863           {
864             smTraceSetMask(agRoot,  llist->TraceMask );
865           }
866         }
867         if( llist->Reset)
868         {
869 
870           *BufferParms.pCurrentTraceIndex = 0;
871           smResetTraceBuffer(agRoot);
872 
873           *BufferParms.pCurrentTraceIndex = 0;
874           *BufferParms.pTraceIndexWrapCount =0;
875           llist->TraceMask = *BufferParms.pTraceMask;
876         }
877 #endif  /* SA_ENABLE_TRACE_FUNCTIONS  */
878         agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
879         status = IOCTL_CALL_SUCCESS;
880 
881       }
882       break;
883 
884     case IOCTL_MN_LL_GET_TRACE_BUFFER_INFO:
885       {
886         hpTraceBufferParms_t  BufferParms;
887         TSTMTID_TRACE_BUFFER_INFO *llist = (TSTMTID_TRACE_BUFFER_INFO *)stu;
888         TI_DBG5(("tdReturnIOCTL_Info: hpIOCTL_GetTraceBufferInfo\n"));
889 
890 
891         BufferParms.TraceCompiled  = 0;
892         BufferParms.TraceWrap      = 0;
893         BufferParms.CurrentTraceIndexWrapCount = 0;
894         BufferParms.BufferSize     = 0;
895         BufferParms.CurrentIndex   = 0;
896         BufferParms.pTrace         = NULL;
897         BufferParms.pTraceMask     = NULL;
898 #ifdef SA_ENABLE_TRACE_FUNCTIONS
899         smTraceGetInfo(agRoot,&BufferParms);
900 #endif  /* SA_ENABLE_TRACE_FUNCTIONS not enabled */
901         llist->TraceCompiled = BufferParms.TraceCompiled;
902         llist->BufferSize = BufferParms.BufferSize;
903         llist->CurrentIndex = BufferParms.CurrentIndex ;
904         llist->CurrentTraceIndexWrapCount =  BufferParms.CurrentTraceIndexWrapCount;
905         llist->TraceWrap = BufferParms.TraceWrap;
906         if(BufferParms.pTraceMask != NULL)
907         {
908           llist->TraceMask = *BufferParms.pTraceMask;
909         }
910         agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
911         status = IOCTL_CALL_SUCCESS;
912       }
913       break;
914 
915     case IOCTL_MN_LL_GET_TRACE_BUFFER:
916       {
917 #ifdef SA_ENABLE_TRACE_FUNCTIONS
918         TSTMTID_TRACE_BUFFER_FETCH *llist = (TSTMTID_TRACE_BUFFER_FETCH *)stu;
919 
920         hpTraceBufferParms_t  BufferParms;
921         bit32 c= 0;
922 
923         BufferParms.TraceCompiled  = 0;
924         BufferParms.TraceWrap      = 0;
925         BufferParms.CurrentTraceIndexWrapCount = 0;
926         BufferParms.BufferSize     = 0;
927         BufferParms.CurrentIndex   = 0;
928         BufferParms.pTrace         = NULL;
929         smTraceGetInfo(agRoot,&BufferParms);
930 
931         TI_DBG6(("tdReturnIOCTL_Info: hpIOCTL_GetTraceBuffer\n"));
932 
933         if(llist->LowFence != LowFence32Bits)
934         {
935           break;
936         }
937         if(llist->HighFence != HighFence32Bits)
938         {
939           break;
940         }
941 
942         if(llist->BufferOffsetBegin + FetchBufferSIZE > BufferParms.BufferSize  )
943         {
944         }
945 
946         for ( c=0; c < FetchBufferSIZE;c++)
947         {
948           llist->Data[c] = *(BufferParms.pTrace+( c + llist->BufferOffsetBegin));
949         }
950 #endif  /* SA_ENABLE_TRACE_FUNCTIONS not enabled */
951       }
952       agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
953       status = IOCTL_CALL_SUCCESS;
954       break;
955     }
956     break;
957   }
958 
959 #ifdef SA_LL_API_TEST
960   case IOCTL_MJ_LL_API_TEST:
961   {
962     status = tdLlApiTestIoctl( tiRoot, agIOCTLPayload,
963                agParam1,agParam2,agParam3 );
964     break;
965   }
966 
967 #endif /* SA_LL_API_TEST */
968 
969   case IOCTL_MJ_MODE_CTL_PAGE:
970   {
971     /* The SPCv controller has some options accessed via mode pages */
972     tiEncryptDekConfigPage_t *pModePage= (tiEncryptDekConfigPage_t *) &agIOCTLPayload->FunctionSpecificArea[0];
973     bit32 pageLength = 0;
974     bit32 pageCode;
975     bit32 modeOperation;
976 
977     pageCode = pModePage->pageCode & 0xFF;
978     modeOperation = *(bit32 *) agParam2;
979 
980     switch(modeOperation)
981     {
982 
983       case tiModePageSet:
984         switch (pageCode)
985         {
986           case TI_ENCRYPTION_DEK_CONFIG_PAGE:
987             pageLength = sizeof(tiEncryptDekConfigPage_t);
988             break;
989 
990           case TI_ENCRYPTION_CONTROL_PARM_PAGE:
991             pageLength = sizeof(tiEncryptControlParamPage_t);
992             break;
993 
994           case TI_ENCRYPTION_GENERAL_CONFIG_PAGE:
995             /* Pages are currently unsupported */
996             pageLength = 0;
997             break;
998         }
999 
1000         status = saSetControllerConfig(agRoot, 0, pageCode, pageLength, pModePage, (agsaContext_t *)agIOCTLPayload);
1001         break;
1002 
1003       case tiModePageGet:
1004         status = saGetControllerConfig(agRoot, 0, pageCode, 0, 0, (agsaContext_t *)agIOCTLPayload);
1005         break;
1006 
1007       default:
1008         agIOCTLPayload->Status = IOCTL_ERR_STATUS_NOT_SUPPORTED;
1009     }
1010   }
1011     break;
1012 #ifdef PHY_RESTART_TEST
1013     case IOCTL_MJ_PORT_START:
1014     {
1015       bit32 portID, tiStatus;
1016       bit32 *data = (bit32*) &agIOCTLPayload->FunctionSpecificArea[0];
1017       portID = *data;
1018 
1019       tiStatus = tiCOMPortStart(tiRoot, portID, tdsaAllShared->Ports[portID].tiPortalContext, 0);
1020 
1021       if (tiStatus == tiSuccess)
1022       {
1023         agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
1024       }
1025       else
1026       {
1027         agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1028       }
1029       status = IOCTL_CALL_SUCCESS;
1030       break;
1031     }
1032 
1033     case IOCTL_MJ_PORT_STOP:
1034     {
1035       bit32 portID, tiStatus;
1036       bit32 *data = (bit32*) &agIOCTLPayload->FunctionSpecificArea[0];
1037       portID =  *data;
1038 
1039       tiStatus = tiCOMPortStop(tiRoot, tdsaAllShared->Ports[portID].tiPortalContext);
1040       if (tiStatus == tiSuccess)
1041       {
1042         agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
1043       }
1044       else
1045       {
1046         agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1047       }
1048 
1049       status = IOCTL_CALL_SUCCESS;
1050       break;
1051     }
1052 #endif
1053  case IOCTL_MJ_SEND_TMF:
1054        switch(agIOCTLPayload->MinorFunction)
1055 	{
1056 	     case IOCTL_MN_TMF_DEVICE_RESET:
1057 		status = tdsaSendTMFIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, AG_TARGET_WARM_RESET);
1058 	        break;
1059 	     case IOCTL_MN_TMF_LUN_RESET:
1060 	 	status = tdsaSendTMFIoctl(tiRoot, agIOCTLPayload, agParam1, agParam2, AG_LOGICAL_UNIT_RESET);
1061 		break;
1062 	}
1063 	break;
1064  case IOCTL_MJ_GET_DRIVER_VERSION:
1065         osti_sprintf(agIOCTLPayload->FunctionSpecificArea, "%s", AGTIAPI_DRIVER_VERSION);
1066         agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
1067         status=IOCTL_CALL_SUCCESS;
1068 	break;
1069   default:
1070     agIOCTLPayload->Status = IOCTL_ERR_STATUS_NOT_SUPPORTED;
1071     break;
1072   }
1073 
1074   return status;
1075 }
1076 
1077 #if 0
1078 /*****************************************************************************
1079 *
1080 * tdsaGpioSetup
1081 *
1082 * Purpose:  This routine is called to set Gpio parameters to the controller.
1083 *
1084 * Parameters:
1085 *   tiRoot:         Pointer to driver instance
1086 *   agsaContext_t :
1087 *   tiIOCTLPayload_t :  ioctl header with payload gpio info
1088 *   agParam1,agParam2 :  Generic parameters
1089 *
1090 * Return: status
1091 *
1092 *
1093 *****************************************************************************/
1094 osGLOBAL bit32
1095 tdsaGpioSetup(
1096                 tiRoot_t            *tiRoot,
1097                 agsaContext_t       *agContext,
1098                 tiIOCTLPayload_t    *agIOCTLPayload,
1099                 void                *agParam1,
1100                 void                *agParam2
1101                 )
1102 {
1103 
1104   tdsaTimerRequest_t        *osIoctlTimer;
1105   agsaGpioEventSetupInfo_t  *gpioEventSetupInfo;
1106   agsaGpioWriteSetupInfo_t  *gpioWriteSetupInfo;
1107   agsaGpioPinSetupInfo_t    *gpioPinSetupInfo;
1108   tdsaRoot_t                *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1109   tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1110   agsaRoot_t                *agRoot = &(tdsaAllShared->agRootInt);
1111   bit32                     status = IOCTL_CALL_SUCCESS;
1112 
1113   TI_DBG3(("tdsaGpioSetup: start\n"));
1114 
1115   if(tiRoot == agNULL || agIOCTLPayload == agNULL )
1116   return IOCTL_CALL_FAIL;
1117 
1118   osIoctlTimer = &tdsaAllShared->osIoctlTimer;
1119   tdsaInitTimerRequest(tiRoot, osIoctlTimer);
1120   tdIoctlStartTimer(tiRoot, osIoctlTimer); /* Start the timout handler for both ioctl and controller response */
1121   tdsaAllShared->tdFWControlEx.virtAddr = (bit8 *)osIoctlTimer;
1122 
1123   tdsaAllShared->tdFWControlEx.usrAddr = (bit8 *)&agIOCTLPayload->FunctionSpecificArea[0];
1124   tdsaAllShared->tdFWControlEx.param1 = agParam1;
1125   tdsaAllShared->tdFWControlEx.param2 = agParam2;
1126   tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
1127   tdsaAllShared->tdFWControlEx.inProgress = 1;
1128 
1129     switch (agIOCTLPayload->MinorFunction)
1130     {
1131 
1132      case IOCTL_MN_GPIO_PINSETUP:
1133      {
1134 	 TI_DBG3(("tdsaGpioSetup: IOCTL_MN_GPIO_PINSETUP\n"));
1135          gpioPinSetupInfo =(agsaGpioPinSetupInfo_t *)&agIOCTLPayload->FunctionSpecificArea[0];
1136          status = saGpioPinSetup(agRoot, agContext, 0, gpioPinSetupInfo);
1137 
1138          break;
1139      }
1140      case IOCTL_MN_GPIO_EVENTSETUP:
1141      {
1142 	TI_DBG3(("tdsaGpioSetup: IOCTL_MN_GPIO_EVENTSETUP\n"));
1143         gpioEventSetupInfo = (agsaGpioEventSetupInfo_t  *)&agIOCTLPayload->FunctionSpecificArea[0];
1144         status = saGpioEventSetup(agRoot, agContext, 0, gpioEventSetupInfo);
1145 
1146         break;
1147      }
1148 
1149      case IOCTL_MN_GPIO_READ:
1150      {
1151 	 TI_DBG3(("tdsaGpioSetup: IOCTL_MN_GPIO_READ\n"));
1152          status = saGpioRead(agRoot, agContext, 0);
1153 
1154         break;
1155      }
1156 
1157      case IOCTL_MN_GPIO_WRITE:
1158      {
1159 	 TI_DBG3(("tdsaGpioSetup: IOCTL_MN_GPIO_WRITE\n"));
1160          gpioWriteSetupInfo = (agsaGpioWriteSetupInfo_t *)&agIOCTLPayload->FunctionSpecificArea[0];
1161          status = saGpioWrite(agRoot, agContext, 0, gpioWriteSetupInfo->gpioWritemask, gpioWriteSetupInfo->gpioWriteVal);
1162 
1163          break;
1164      }
1165 
1166      default :
1167          return status;
1168     }
1169 
1170     if(status != AGSA_RC_SUCCESS)
1171     {
1172       status = IOCTL_CALL_FAIL;
1173       agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1174 
1175       tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK);
1176       if (osIoctlTimer->timerRunning == agTRUE)
1177       {
1178          tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
1179          tdsaKillTimer(tiRoot, osIoctlTimer);
1180 
1181       }else{
1182          tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
1183       }
1184     }
1185 
1186     TI_DBG3(("tdsaGpioPinSetup: End\n"));
1187     return status;
1188 
1189 }
1190 #endif
1191 
1192 /*****************************************************************************
1193 *
1194 * ostiGetGpioIOCTLRsp
1195 *
1196 * Purpose:  This routine is called for Get Gpio IOCTL reaponse has been received.
1197 *
1198 * Parameters:
1199 *   tiRoot:         Pointer to driver instance
1200 *   payloadRsp:     Pointer to the FW download IOMB's payload.
1201 *
1202 * Return: none
1203 *
1204 *
1205 *****************************************************************************/
1206 
1207 osGLOBAL void  ostiGetGpioIOCTLRsp(
1208                         tiRoot_t                 *tiRoot,
1209                         bit32                    status,
1210                         bit32                    gpioReadValue,
1211                         agsaGpioPinSetupInfo_t   *gpioPinSetupInfo,
1212                         agsaGpioEventSetupInfo_t *gpioEventSetupInfo
1213                         )
1214 {
1215      tdsaRoot_t                *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1216      tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1217      tiIOCTLPayload_t          *agIoctlPayload ;
1218      agsaGpioReadInfo_t        *gpioReadInfo;
1219 
1220      tdsaTimerRequest_t        *osIoctlTimer;
1221 	 osIoctlTimer = (tdsaTimerRequest_t *)tdsaAllShared->tdFWControlEx.virtAddr;
1222 
1223      TI_DBG2(("ostiGetGpioIOCTLRsp: start, status = %d \n", status));
1224 
1225      agIoctlPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1226 
1227      if(agIoctlPayload == agNULL){
1228         return;
1229       }
1230 
1231      agIoctlPayload->Status =(bit16) status;
1232 
1233      if( (status != IOCTL_CALL_TIMEOUT) && (osIoctlTimer != NULL))
1234      {
1235         tdsaSingleThreadedEnter(tiRoot, TD_TIMER_LOCK);
1236         if (osIoctlTimer->timerRunning == agTRUE)
1237         {
1238            tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
1239            tdsaKillTimer(tiRoot, osIoctlTimer);
1240 
1241         }else{
1242            tdsaSingleThreadedLeave(tiRoot, TD_TIMER_LOCK);
1243         }
1244      }else  {
1245          tdsaAllShared->tdFWControlEx.inProgress = 0;
1246          agIoctlPayload->Status = (bit16)status;
1247          ostiIOCTLSetSignal(tiRoot, tdsaAllShared->tdFWControlEx.param1,
1248                                tdsaAllShared->tdFWControlEx.param2, NULL);
1249         return;
1250      }
1251 
1252      if(status == SUCCESS)
1253        TI_DBG3((" ostiGetGpioIOCTLRsp:Got GPIO response from OUTBuf"));
1254     else {
1255       tdsaAllShared->tdFWControlEx.inProgress = 0;
1256       ostiIOCTLSetSignal(tiRoot, tdsaAllShared->tdFWControlEx.param1,
1257                                tdsaAllShared->tdFWControlEx.param2, NULL);
1258       return;
1259     }
1260 
1261     switch (agIoctlPayload->MinorFunction)
1262      {
1263 
1264      case IOCTL_MN_GPIO_PINSETUP:
1265       {
1266        TI_DBG3((" ostiGetGpioIOCTLRsp:Got GPIO response for IOCTL_MN_GPIO_PINSETUP"));
1267 
1268          break;
1269       }
1270      case IOCTL_MN_GPIO_EVENTSETUP:
1271      {
1272        TI_DBG3((" ostiGetGpioIOCTLRsp:Got GPIO response for IOCTL_MN_GPIO_EVENTSETUP"));
1273 
1274          break;
1275      }
1276 
1277      case IOCTL_MN_GPIO_WRITE:
1278      {
1279        TI_DBG3((" ostiGetGpioIOCTLRsp:Got GPIO response for IOCTL_MN_GPIO_WRITE"));
1280 
1281          break;
1282      }
1283 
1284     case IOCTL_MN_GPIO_READ:
1285     {
1286          gpioReadInfo = ( agsaGpioReadInfo_t *)tdsaAllShared->tdFWControlEx.usrAddr;
1287 
1288          gpioReadInfo->gpioReadValue = gpioReadValue;
1289          gpioReadInfo->gpioInputEnabled = gpioPinSetupInfo->gpioInputEnabled ; /* GPIOIE */
1290          gpioReadInfo->gpioEventLevelChangePart1 = gpioPinSetupInfo->gpioTypePart1; /* GPIEVCHANGE (pins 11-0) */
1291          gpioReadInfo->gpioEventLevelChangePart2 = gpioPinSetupInfo->gpioTypePart2; /* GPIEVCHANGE (pins 23-20) */
1292          gpioReadInfo->gpioEventRisingEdgePart1 = 0xFFF & gpioEventSetupInfo->gpioEventRisingEdge; /* GPIEVRISE (pins 11-0) */
1293          gpioReadInfo->gpioEventRisingEdgePart2 = 0x00F00000 & (gpioEventSetupInfo->gpioEventRisingEdge); /* GPIEVRISE (pins 23-20) */
1294          gpioReadInfo->gpioEventFallingEdgePart1 = 0xFFF & gpioEventSetupInfo->gpioEventFallingEdge; /* GPIEVALL (pins 11-0) */
1295          gpioReadInfo->gpioEventFallingEdgePart2 = 0x00F00000  & gpioEventSetupInfo->gpioEventFallingEdge; /* GPIEVALL (pins 23-20 */
1296 
1297          break;
1298      }
1299 
1300     default :
1301          break;
1302     }
1303 
1304     if(tdsaAllShared->tdFWControlEx.inProgress)
1305     {
1306       tdsaAllShared->tdFWControlEx.inProgress = 0;
1307       ostiIOCTLSetSignal(tiRoot, tdsaAllShared->tdFWControlEx.param1,
1308                               tdsaAllShared->tdFWControlEx.param2, NULL);
1309     }
1310     TI_DBG2(("ostiGetGpioIOCTLRsp: end \n"));
1311 
1312    return ;
1313 }
1314 
1315 /*****************************************************************************
1316 *
1317 * tdsaSGpioIoctlSetup
1318 *
1319 * Purpose:  This routine is called to send SGPIO request to the controller.
1320 *
1321 * Parameters:
1322 *   tiRoot:             Pointer to driver instance
1323 *   agsaContext_t:      Context for this request
1324 *   tiIOCTLPayload_t:   ioctl header with payload sgpio info
1325 *   agParam1,agParam2:  Generic parameters
1326 *
1327 * Return: status
1328 *
1329 *
1330 *****************************************************************************/
1331 osGLOBAL bit32
1332 tdsaSGpioIoctlSetup(
1333                 tiRoot_t            *tiRoot,
1334                 agsaContext_t       *agContext,
1335                 tiIOCTLPayload_t    *agIOCTLPayload,
1336                 void                *agParam1,
1337                 void                *agParam2
1338                 )
1339 {
1340   tdsaRoot_t                *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1341   tdsaContext_t             *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1342   agsaRoot_t                *agRoot = &(tdsaAllShared->agRootInt);
1343   bit32                     status = IOCTL_CALL_FAIL;
1344   agsaSGpioReqResponse_t    *pSGpioReq = (agsaSGpioReqResponse_t *)&agIOCTLPayload->FunctionSpecificArea[0];
1345 
1346   TI_DBG3(("tdsaSGpioIoctlSetup: start\n"));
1347 
1348   agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1349 
1350   do
1351   {
1352     if (tiRoot == agNULL || agIOCTLPayload == agNULL)
1353     {
1354       break;
1355     }
1356 
1357     /* Validate the length */
1358     if (agIOCTLPayload->Length < sizeof(agsaSGpioReqResponse_t))
1359     {
1360       TI_DBG3(("Invalid length\n"));
1361       break;
1362     }
1363 
1364     /* Validate the SMP Frame Type, Function and Register Type fields */
1365     if ((pSGpioReq->smpFrameType != SMP_REQUEST) || \
1366         ((pSGpioReq->function != SMP_READ_GPIO_REGISTER) && (pSGpioReq->function != SMP_WRITE_GPIO_REGISTER)) || \
1367         (pSGpioReq->registerType > AGSA_SGPIO_GENERAL_PURPOSE_TRANSMIT_REG))
1368     {
1369       TI_DBG4(("Invalid Parameter\n"));
1370       break;
1371     }
1372 
1373     /* Specific validation for configuration register type */
1374     if (AGSA_SGPIO_CONFIG_REG == pSGpioReq->registerType)
1375     {
1376       if ((pSGpioReq->registerIndex > 0x01) || \
1377           ((0x00 == pSGpioReq->registerIndex) && (pSGpioReq->registerCount > 0x02)) || \
1378           ((0x01 == pSGpioReq->registerIndex) && (pSGpioReq->registerCount > 0x01)))
1379       {
1380         break;
1381       }
1382     }
1383 
1384     /* Use FW control place in shared structure to keep the necessary information */
1385     tdsaAllShared->tdFWControlEx.param1 = agParam1;
1386     tdsaAllShared->tdFWControlEx.param2 = agParam2;
1387     tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
1388     tdsaAllShared->tdFWControlEx.inProgress = 1;
1389 
1390     status = saSgpio(agRoot, agContext, 0, pSGpioReq);
1391     if (status != AGSA_RC_SUCCESS)
1392     {
1393       break;
1394     }
1395 
1396     status = IOCTL_CALL_PENDING;
1397 
1398   } while (0);
1399 
1400   TI_DBG3(("tdsaGpioPinSetup: End\n"));
1401   return status;
1402 }
1403 
1404 /*****************************************************************************
1405 *
1406 * ostiSgpioIoctlRsp
1407 *
1408 * Purpose:  This routine is called when a SGPIO IOCTL response is received.
1409 *
1410 * Parameters:
1411 *   tiRoot:         Pointer to driver instance
1412 *   pSgpioResponse: Pointer to the SGPIO response
1413 *
1414 * Return: none
1415 *
1416 *
1417 *****************************************************************************/
1418 osGLOBAL void ostiSgpioIoctlRsp(
1419                             tiRoot_t                *tiRoot,
1420                             agsaSGpioReqResponse_t  *pSgpioResponse
1421                             )
1422 {
1423   tdsaRoot_t        *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1424   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1425   tiIOCTLPayload_t  *agIoctlPayload = agNULL;
1426 
1427   TI_DBG3(("ostiSgpioIoctlRsp: start\n"));
1428 
1429   if (tdsaAllShared->tdFWControlEx.inProgress)
1430   {
1431     agIoctlPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1432     if (agIoctlPayload)
1433     {
1434       tdsaAllShared->tdFWControlEx.payload = NULL;
1435       osti_memcpy(&agIoctlPayload->FunctionSpecificArea[0], pSgpioResponse, sizeof(agsaSGpioReqResponse_t));
1436       agIoctlPayload->Status = IOCTL_ERR_STATUS_OK;
1437       sgpioResponseSet = 1;
1438     }
1439 	tdsaAllShared->sgpioResponseSet = 1;    //Sunitha:Check if needed?
1440 
1441     ostiIOCTLSetSignal(tiRoot, tdsaAllShared->tdFWControlEx.param1,
1442                   tdsaAllShared->tdFWControlEx.param2, agNULL);
1443 
1444     tdsaAllShared->tdFWControlEx.inProgress = 0;
1445   }
1446 
1447   TI_DBG3(("ostiSgpioIoctlRsp: end\n"));
1448 }
1449 /*****************************************************************************
1450 *
1451 * ostiCOMMgntIOCTLRsp
1452 *
1453 * Purpose:  This routine is called when FW control IOCTL reaponse has been received.
1454 *           This function is used for both target and initiator.
1455 *
1456 * Parameters:
1457 *   tiRoot:          Pointer to driver instance
1458 *   payloadRsp:     Pointer to the FW download IOMB's payload.
1459 *
1460 * Return: none
1461 *
1462 *
1463 *
1464 *****************************************************************************/
1465 
1466 osGLOBAL void ostiCOMMgntIOCTLRsp(
1467                         tiRoot_t            *tiRoot,
1468                         bit32               status
1469                         )
1470 {
1471     tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1472     tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1473 
1474     TI_DBG1(("ostiCOMMgntIOCTLRsp: status 0x%x\n",status));
1475     (tdsaAllShared->tdFWControlEx.tdFWControl)->retcode = status;
1476 
1477     ostiFreeMemory(tiRoot,
1478                    tdsaAllShared->tdFWControlEx.buffer,
1479                    tdsaAllShared->tdFWControlEx.tdFWControl->len);
1480 
1481     ostiIOCTLSetSignal(tiRoot,
1482                        tdsaAllShared->tdFWControlEx.param1,
1483                        tdsaAllShared->tdFWControlEx.param2,
1484                        NULL);
1485 }
1486 
1487 
1488 /*****************************************************************************
1489 *
1490 * ostiRegDumpIOCTLRsp
1491 *
1492 * Purpose:  This routine is called when Register Dump from flash IOCTL reaponse has been received.
1493 *           This function is used for both target and initiator.
1494 *
1495 * Parameters:
1496 *   tiRoot:          Pointer to driver instance
1497 *   payloadRsp:     Pointer to the FW download IOMB's payload.
1498 *
1499 * Return: none
1500 *
1501 *
1502 *
1503 *****************************************************************************/
1504 
1505 osGLOBAL void ostiRegDumpIOCTLRsp(
1506                         tiRoot_t            *tiRoot,
1507                         bit32               status
1508                         )
1509 {
1510     tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1511     tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1512 
1513     TI_DBG1(("ostiRegDumpIOCTLRsp: start\n"));
1514 //    (tdsaAllShared->tdFWControlEx.tdFWControl)->retcode = status;
1515     osti_memcpy((void *)(tdsaAllShared->tdFWControlEx.usrAddr),
1516                 (void *)(tdsaAllShared->tdFWControlEx.virtAddr),
1517                 tdsaAllShared->tdFWControlEx.len);
1518 
1519     ostiFreeMemory(tiRoot,
1520                   tdsaAllShared->tdFWControlEx.buffer,
1521                   tdsaAllShared->tdFWControlEx.len);
1522 
1523     ostiIOCTLSetSignal(tiRoot,
1524                        tdsaAllShared->tdFWControlEx.param1,
1525                        tdsaAllShared->tdFWControlEx.param2,
1526                        NULL);
1527 }
1528 
1529 /*****************************************************************************
1530 *
1531 * ostiSetNVMDIOCTLRsp
1532 *
1533 * Purpose:  This routine is called for Set NVMD IOCTL reaponse has been received.
1534 *           This function is used for both target and initiator.
1535 *
1536 * Parameters:
1537 *   tiRoot:          Pointer to driver instance
1538 *   payloadRsp:     Pointer to the FW download IOMB's payload.
1539 *
1540 * Return: none
1541 *
1542 *
1543 *
1544 *****************************************************************************/
1545 
1546 osGLOBAL void ostiSetNVMDIOCTLRsp(
1547                         tiRoot_t            *tiRoot,
1548                         bit32               status
1549                         )
1550 {
1551     tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1552     tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1553     tiIOCTLPayload_t     *agIOCTLPayload;
1554 
1555     if(status)
1556     {
1557         agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1558         agIOCTLPayload->Status = (bit16)status;
1559     }
1560 
1561     TI_DBG1(("ostiSetNVMDIOCTLRsp: start, status = %d\n", status));
1562 //    (tdsaAllShared->tdFWControlEx.tdFWControl)->retcode = status;
1563     ostiFreeMemory(tiRoot,
1564                        tdsaAllShared->tdFWControlEx.buffer,
1565                        tdsaAllShared->tdFWControlEx.len);
1566 
1567     ostiIOCTLSetSignal(tiRoot,
1568                        tdsaAllShared->tdFWControlEx.param1,
1569                        tdsaAllShared->tdFWControlEx.param2,
1570                        NULL);
1571 }
1572 #ifdef SPC_ENABLE_PROFILE
1573 /*****************************************************************************
1574 *
1575 * ostiFWProfileIOCTLRsp
1576 *
1577 * Purpose:  This routine is called for Fw Profile IOCTL reaponse has been received.
1578 *           This function is used for both target and initiator.
1579 *
1580 * Parameters:
1581 *   tiRoot:          Pointer to driver instance
1582 *   status:
1583 *
1584 * Return: none
1585 *
1586 *
1587 *
1588 *****************************************************************************/
1589 
1590 osGLOBAL void ostiFWProfileIOCTLRsp(
1591                         tiRoot_t            *tiRoot,
1592                         bit32               status,
1593             bit32               len)
1594 {
1595     tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1596     tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1597     tdFWProfile_t        *fwProfile;
1598 
1599     TI_DBG1(("ostiFWProfileIOCTLRsp: start\n"));
1600     fwProfile = (tdFWProfile_t *)tdsaAllShared->tdFWProfileEx.tdFWProfile;
1601   //    (tdsaAllShared->tdFWControlEx.tdFWControl)->retcode = status;
1602     if (status == AGSA_RC_SUCCESS)
1603     {
1604       if((fwProfile->cmd == STOP_TIMER_PROFILE) || (fwProfile->cmd == STOP_CODE_PROFILE))
1605         {
1606         osti_memcpy((void *)(fwProfile->buffer),
1607                   (void *)(tdsaAllShared->tdFWProfileEx.virtAddr),
1608                   len);
1609 
1610         ostiFreeMemory(tiRoot,
1611                          tdsaAllShared->tdFWProfileEx.buffer,
1612                          tdsaAllShared->tdFWProfileEx.len);
1613       }
1614     }
1615     fwProfile->status = status;
1616     fwProfile->len = len;
1617     ostiIOCTLSetSignal(tiRoot,
1618                        tdsaAllShared->tdFWProfileEx.param1,
1619                        tdsaAllShared->tdFWProfileEx.param2,
1620                        NULL);
1621 }
1622 #endif
1623 /*****************************************************************************
1624 *
1625 * ostiGetNVMDIOCTLRsp
1626 *
1627 * Purpose:  This routine is called for Get NVMD IOCTL reaponse has been received.
1628 *           This function is used for both target and initiator.
1629 *
1630 * Parameters:
1631 *   tiRoot:          Pointer to driver instance
1632 *   payloadRsp:     Pointer to the FW download IOMB's payload.
1633 *
1634 * Return: none
1635 *
1636 *
1637 *
1638 *****************************************************************************/
1639 
1640 osGLOBAL void ostiGetNVMDIOCTLRsp(
1641                         tiRoot_t            *tiRoot,
1642                         bit32               status
1643                         )
1644 {
1645     tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1646     tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1647     tiIOCTLPayload_t     *agIOCTLPayload;
1648 
1649     if(status)
1650     {
1651         agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1652         agIOCTLPayload->Status = (bit16)status;
1653     }
1654 
1655     TI_DBG1(("ostiGetNVMDIOCTLRsp: start, status = %d\n", status));
1656     tdsaAllShared->NvmdResponseSet = 1;
1657 
1658     if(tdsaAllShared->tdFWControlEx.param1 != agNULL)
1659     {
1660     osti_memcpy((void *)(tdsaAllShared->tdFWControlEx.usrAddr),
1661                 (void *)(tdsaAllShared->tdFWControlEx.virtAddr),
1662                 tdsaAllShared->tdFWControlEx.len);
1663 
1664     ostiFreeMemory(tiRoot,
1665                    tdsaAllShared->tdFWControlEx.buffer,
1666                    tdsaAllShared->tdFWControlEx.len);
1667 
1668     ostiIOCTLSetSignal(tiRoot,
1669                        tdsaAllShared->tdFWControlEx.param1,
1670                        tdsaAllShared->tdFWControlEx.param2,
1671                        NULL);
1672     }
1673 }
1674 
1675 
1676 /*****************************************************************************
1677 *
1678 * ostiGetPhyProfileIOCTLRsp
1679 *
1680 * Purpose:  This routine is called for phy response has been received.
1681 *           This function is used for both target and initiator.
1682 *
1683 * Parameters:
1684 *   tiRoot:          Pointer to driver instance
1685 *   payloadRsp:     Pointer to the IOMB's payload.
1686 *
1687 * Return: none
1688 *
1689 *
1690 *
1691 *****************************************************************************/
1692 
1693 osGLOBAL void ostiGetPhyProfileIOCTLRsp(
1694                         tiRoot_t            *tiRoot,
1695                         bit32               status
1696                         )
1697 {
1698     tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1699     tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1700     tiIOCTLPayload_t     *agIOCTLPayload;
1701     tdPhyCount_t     *PhyBlob = agNULL;
1702     if(status)
1703     {
1704       agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1705       agIOCTLPayload->Status = (bit16)status;
1706 
1707       PhyBlob = (tdPhyCount_t*)&agIOCTLPayload->FunctionSpecificArea[0];
1708       if(PhyBlob)
1709       {
1710 //        PhyBlob->Phy |= 0x800;
1711         if(PhyBlob->phyResetProblem == 0 )
1712         {
1713           PhyBlob->phyResetProblem = -1;
1714         }
1715         TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->Phy                   0x%x\n",PhyBlob->Phy));
1716         TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->BW_rx                 0x%x\n",PhyBlob->BW_rx));
1717         TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->BW_tx                 0x%x\n",PhyBlob->BW_tx));
1718         TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->InvalidDword          0x%x\n",PhyBlob->InvalidDword));
1719         TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->runningDisparityError 0x%x\n",PhyBlob->runningDisparityError));
1720         TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->codeViolation         0x%x\n",PhyBlob->codeViolation));
1721         TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->phyResetProblem       0x%x\n",PhyBlob->phyResetProblem));
1722         TI_DBG1(("ostiGetPhyProfileIOCTLRsp: PhyBlob->inboundCRCError       0x%x\n",PhyBlob->inboundCRCError));
1723 
1724       }
1725 
1726 
1727     }
1728 
1729     TI_DBG1(("ostiGetPhyProfileIOCTLRsp: start, status = %d\n", status));
1730     TI_DBG1(("ostiGetPhyProfileIOCTLRsp: start, len = %d %p %p\n", tdsaAllShared->tdFWControlEx.len,tdsaAllShared->tdFWControlEx.usrAddr,tdsaAllShared->tdFWControlEx.virtAddr));
1731 
1732 //    osti_memcpy((void *)(tdsaAllShared->tdFWControlEx.usrAddr),
1733 //                (void *)(tdsaAllShared->tdFWControlEx.virtAddr),
1734 //                 tdsaAllShared->tdFWControlEx.len);
1735 
1736     ostiFreeMemory(tiRoot,
1737                    tdsaAllShared->tdFWControlEx.buffer,
1738                    tdsaAllShared->tdFWControlEx.len);
1739 
1740     ostiIOCTLSetSignal(tiRoot,
1741                        tdsaAllShared->tdFWControlEx.param1,
1742                        tdsaAllShared->tdFWControlEx.param2,
1743                        NULL);
1744 }
1745 
1746 
1747 /*****************************************************************************
1748 *
1749 * ostiGenEventIOCTLRsp
1750 *
1751 * Purpose:  This routine is called when General Event happened while waiting for IOCTL response.
1752 *           This function is used for both target and initiator.
1753 *
1754 * Parameters:
1755 *   tiRoot:          Pointer to driver instance
1756 *   payloadRsp:     Pointer to the FW download IOMB's payload.
1757 *
1758 * Return: none
1759 *
1760 *
1761 *
1762 *****************************************************************************/
1763 
1764 osGLOBAL void ostiGenEventIOCTLRsp(
1765                         tiRoot_t            *tiRoot,
1766                         bit32               status
1767                         )
1768 {
1769     tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
1770     tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1771     tiIOCTLPayload_t     *agIOCTLPayload;
1772 
1773     TI_DBG1(("ostiGenEventIOCTLRsp: start\n"));
1774 
1775     if(tdsaAllShared->tdFWControlEx.inProgress)  /*Free only if our IOCTL is in progress*/
1776     {
1777       agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1778       agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1779       (tdsaAllShared->tdFWControlEx.tdFWControl)->retcode = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1780 
1781       ostiFreeMemory(tiRoot,
1782                      tdsaAllShared->tdFWControlEx.buffer,
1783                      tdsaAllShared->tdFWControlEx.len);
1784 
1785       ostiIOCTLSetSignal(tiRoot,
1786                          tdsaAllShared->tdFWControlEx.param1,
1787                          tdsaAllShared->tdFWControlEx.param2,
1788                          NULL);
1789       tdsaAllShared->tdFWControlEx.inProgress = 0;
1790     }
1791 #ifdef SPC_ENABLE_PROFILE
1792     if(tdsaAllShared->tdFWProfileEx.inProgress)
1793     {
1794       agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWProfileEx.payload);
1795       agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1796       if(tdsaAllShared->tdFWProfileEx.virtAddr != NULL)  /*Free only if our IOCTL is in progress*/
1797       {
1798         ostiFreeMemory(tiRoot,
1799                        tdsaAllShared->tdFWProfileEx.buffer,
1800                        tdsaAllShared->tdFWProfileEx.len);
1801         tdsaAllShared->tdFWProfileEx.virtAddr = NULL;
1802       }
1803       ostiIOCTLSetSignal(tiRoot,
1804                          tdsaAllShared->tdFWProfileEx.param1,
1805                          tdsaAllShared->tdFWProfileEx.param2,
1806                          NULL);
1807       tdsaAllShared->tdFWProfileEx.inProgress = 0;
1808 
1809     }
1810 #endif /*SPC_ENABLE_PROFILE*/
1811 
1812 }
1813 
1814 osGLOBAL void
1815 ostiGetDeviceInfoIOCTLRsp(
1816                         tiRoot_t    *tiRoot,
1817                         bit32        status,
1818                         void        *param
1819                         )
1820 {
1821     tdsaRoot_t             *tdsaRoot       = (tdsaRoot_t *) tiRoot->tdData;
1822     tdsaContext_t          *tdsaAllShared  = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1823     tiIOCTLPayload_t       *agIOCTLPayload = agNULL;
1824     tdDeviceInfoPayload_t  *pTDDeviceInfo  = agNULL;
1825     agsaDeviceInfo_t       *pSADeviceInfo  = agNULL;
1826 
1827     TI_DBG1(("ostiGetDeviceInfoIOCTLRsp: start\n"));
1828 
1829     agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1830     pSADeviceInfo = (agsaDeviceInfo_t*)param;
1831     pTDDeviceInfo = (tdDeviceInfoPayload_t*)agIOCTLPayload->FunctionSpecificArea;
1832 
1833     if (pSADeviceInfo != agNULL)
1834     {
1835       /* fill the device information in IOCTL payload */
1836       osti_memcpy(&pTDDeviceInfo->devInfo.sasAddressHi, pSADeviceInfo->sasAddressHi, sizeof(bit32));
1837       osti_memcpy(&pTDDeviceInfo->devInfo.sasAddressLo, pSADeviceInfo->sasAddressLo, sizeof(bit32));
1838 
1839       pTDDeviceInfo->devInfo.sasAddressHi = DMA_BEBIT32_TO_BIT32(pTDDeviceInfo->devInfo.sasAddressHi);
1840       pTDDeviceInfo->devInfo.sasAddressLo = DMA_BEBIT32_TO_BIT32(pTDDeviceInfo->devInfo.sasAddressLo);
1841 
1842       pTDDeviceInfo->devInfo.deviceType = (pSADeviceInfo->devType_S_Rate & 0x30) >> 4;
1843       pTDDeviceInfo->devInfo.linkRate   = pSADeviceInfo->devType_S_Rate & 0x0F;
1844 
1845       agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
1846     }
1847     else
1848     {
1849       agIOCTLPayload->Status = IOCTL_ERR_STATUS_INVALID_DEVICE;
1850     }
1851 
1852     if(tdsaAllShared->tdFWControlEx.inProgress)  /*Free only if our IOCTL is in progress*/
1853     {
1854       ostiIOCTLSetSignal(tiRoot,
1855                          tdsaAllShared->tdFWControlEx.param1,
1856                          tdsaAllShared->tdFWControlEx.param2,
1857                          NULL);
1858       tdsaAllShared->tdFWControlEx.inProgress = 0;
1859     }
1860 }
1861 
1862 
1863 #ifdef INITIATOR_DRIVER
1864 osGLOBAL void
1865 ostiGetIoErrorStatsIOCTLRsp(
1866                         tiRoot_t    *tiRoot,
1867                         bit32        status,
1868                         void        *param
1869                         )
1870 {
1871     tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
1872     tdsaContext_t               *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1873     itdsaIni_t                  *Initiator       = (itdsaIni_t *)tdsaAllShared->itdsaIni;
1874     tiIOCTLPayload_t            *agIOCTLPayload  = agNULL;
1875     tdIoErrorStatisticPayload_t *pIoErrorPayload = agNULL;
1876     agsaIOErrorEventStats_t     *pIoErrorCount   = agNULL;
1877 
1878     OS_ASSERT(sizeof(agsaIOErrorEventStats_t) == sizeof(tdIoErrorEventStatisticIOCTL_t), "agsaIOErrorEventStats_t tdIoErrorEventStatisticIOCTL_t\n");
1879     TI_DBG1(("ostiGetIoErrorStatsIOCTLRsp: start\n"));
1880 
1881     agIOCTLPayload  = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1882     pIoErrorPayload = (tdIoErrorStatisticPayload_t*)agIOCTLPayload->FunctionSpecificArea;
1883     pIoErrorCount   = (agsaIOErrorEventStats_t*)param;
1884 
1885     osti_memcpy(&pIoErrorPayload->IoError, pIoErrorCount, sizeof(agsaIOErrorEventStats_t));
1886     /*copy SCSI status and sense key count from OS layer to TD layer*/
1887     osti_memcpy(&pIoErrorPayload->ScsiStatusCounter, &Initiator->ScsiStatusCounts, sizeof(tdSCSIStatusCount_t));
1888     osti_memcpy(&pIoErrorPayload->SenseKeyCounter, &Initiator->SenseKeyCounter, sizeof(tdSenseKeyCount_t));
1889     if (pIoErrorPayload->flag)
1890     {
1891       osti_memset(&Initiator->ScsiStatusCounts, 0,sizeof(tdSCSIStatusCount_t) );
1892       osti_memset(&Initiator->SenseKeyCounter, 0,sizeof(tdSenseKeyCount_t) );
1893     }
1894 
1895     agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
1896 }
1897 #endif /* INITIATOR_DRIVER */
1898 
1899 osGLOBAL void
1900 ostiGetIoEventStatsIOCTLRsp(
1901                         tiRoot_t    *tiRoot,
1902                         bit32        status,
1903                         void        *param
1904                         )
1905 {
1906     tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
1907     tdsaContext_t               *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1908     tiIOCTLPayload_t            *agIOCTLPayload  = agNULL;
1909     tdIoEventStatisticPayload_t *pIoEventPayload = agNULL;
1910     agsaIOErrorEventStats_t     *pIoEventCount   = agNULL;
1911 
1912     TI_DBG1(("ostiGetIoEventStatsIOCTLRsp: start\n"));
1913 
1914     agIOCTLPayload  = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1915     pIoEventPayload = (tdIoEventStatisticPayload_t*)agIOCTLPayload->FunctionSpecificArea;
1916     pIoEventCount   = (agsaIOErrorEventStats_t*)param;
1917 
1918     osti_memcpy(&pIoEventPayload->IoEvent, pIoEventCount, sizeof(agsaIOErrorEventStats_t));
1919 
1920     agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
1921 }
1922 
1923 osGLOBAL void
1924 ostiGetForensicDataIOCTLRsp(
1925                         tiRoot_t    *tiRoot,
1926                         bit32        status,
1927                         void        *param
1928                         )
1929 {
1930   tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
1931   tdsaContext_t               *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
1932   tiIOCTLPayload_t            *agIOCTLPayload  = agNULL;
1933   tdForensicDataPayload_t     *pForensicDataPayload = agNULL;
1934   agsaForensicData_t          *pForensicData   = agNULL;
1935 
1936   TI_DBG3(("ostiGetForensicDataIOCTLRsp: start, status = %d\n", status));
1937 
1938   agIOCTLPayload  = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
1939   pForensicDataPayload = (tdForensicDataPayload_t*)agIOCTLPayload->FunctionSpecificArea;
1940   pForensicData   = (agsaForensicData_t*)param;
1941 
1942   if (agNULL == agIOCTLPayload)
1943   {
1944     return;
1945   }
1946 
1947   if (FORENSIC_DATA_TYPE_CHECK_FATAL == pForensicData->DataType)
1948   {
1949     agIOCTLPayload->Status = (bit16)status;
1950     return;
1951   }
1952 
1953   if (status == AGSA_RC_SUCCESS)
1954   {
1955     switch (pForensicData->DataType)
1956     {
1957       case FORENSIC_DATA_TYPE_NON_FATAL:
1958       case FORENSIC_DATA_TYPE_FATAL:
1959            pForensicDataPayload->dataBuffer.directOffset = pForensicData->BufferType.dataBuf.directOffset;
1960            pForensicDataPayload->dataBuffer.readLen      = pForensicData->BufferType.dataBuf.readLen;
1961            break;
1962       case FORENSIC_DATA_TYPE_GSM_SPACE:
1963            pForensicDataPayload->gsmBuffer.directOffset  = pForensicData->BufferType.gsmBuf.directOffset;
1964 	   pForensicDataPayload->gsmBuffer.readLen 	 = pForensicData->BufferType.gsmBuf.readLen;
1965            break;
1966 
1967       case FORENSIC_DATA_TYPE_QUEUE:
1968            break;
1969 
1970       default:
1971            TI_DBG1(("ostiGetForensicDataIOCTLRsp: forensic data type error %d\n", pForensicData->DataType));
1972            break;
1973     }
1974     agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
1975   }
1976   else if(status == IOCTL_ERROR_NO_FATAL_ERROR)
1977   {
1978     agIOCTLPayload->Status = (bit16)status;
1979   }
1980   else
1981   {
1982     agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
1983   }
1984 
1985   /*Free only if our IOCTL is in progress*/
1986   if(tdsaAllShared->tdFWControlEx.inProgress)
1987   {
1988     TI_DBG3(("ostiGetForensicDataIOCTLRsp: Waiting for the signal \n"));
1989     ostiIOCTLSetSignal(tiRoot,
1990           tdsaAllShared->tdFWControlEx.param1,
1991           tdsaAllShared->tdFWControlEx.param2,
1992           NULL);
1993     TI_DBG3(("ostiGetForensicDataIOCTLRsp: Signal wait completed \n"));
1994     tdsaAllShared->tdFWControlEx.inProgress = 0;
1995   }
1996 }
1997 
1998 /*****************************************************************************
1999 *
2000 * tdsaRegDumpGetIoctl
2001 *
2002 * Purpose:  This routine is called to get Register Dump information.
2003 *           This function is used for both target and initiator.
2004 *
2005 * Parameters:
2006 *   tiRoot:         Pointer to driver instance
2007 *   agIOCTLPayload: Pointer to the IOCTL payload.
2008 *   agParam1:       Pointer to pass context handle for IOCTL DMA operation
2009 *   agParam2:       Pointer to pass context handle for IOCTL DMA operation
2010 *   agParam3:       Pointer to pass context handle for IOCTL DMA operation
2011 *
2012 * Return:
2013 *
2014 *   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
2015 *   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
2016 *                             Detail error code is function specific and
2017 *                             defined by the specific IOCTL function.
2018 *   IOCTL_CALL_PENDING        This request is asynchronous and completed
2019 *                             in some other context.
2020 *   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
2021 *
2022 *
2023 *****************************************************************************/
2024 osGLOBAL bit32
2025 tdsaRegDumpGetIoctl(
2026                 tiRoot_t            *tiRoot,
2027                 tiIOCTLPayload_t    *agIOCTLPayload,
2028                 void                *agParam1,
2029                 void                *agParam2,
2030                 void                *agParam3
2031                 )
2032 {
2033     tdsaRoot_t    *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
2034     tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2035     agsaRoot_t    *agRoot = &(tdsaAllShared->agRootInt);
2036 //    agsaControllerStatus_t RegDump;
2037     bit32               Offset = 0;
2038     bit32               RequestLength = 0;  /* user request on how much data to pass to application */
2039     agsaRegDumpInfo_t   regDumpInfo;
2040     void                *buffer = agNULL;
2041     void                *osMemHandle = agNULL;
2042     bit32               status = IOCTL_CALL_SUCCESS;
2043     bit32               CoreDumpLength = 16384; /* change it once data is available */
2044     bit32               EventLogOffset = 65536;
2045 
2046     ///saGetControllerStatus(agRoot, &RegDump);
2047     /* length of FSA as provided by application */
2048     RequestLength = agIOCTLPayload->Length;
2049 ///    FunctionSpecificOffset = 0; /* Offset into the FunctionSpecificArea of payload */
2050     /* offset into core dump that was passed from application */
2051     Offset = agIOCTLPayload->Reserved;
2052 
2053   if((CoreDumpLength <= Offset)&&
2054     (agIOCTLPayload->MinorFunction != IOCTL_MN_FW_GET_EVENT_FLASH_LOG1)&&
2055     (agIOCTLPayload->MinorFunction != IOCTL_MN_FW_GET_EVENT_FLASH_LOG2))
2056   {
2057       agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
2058       agIOCTLPayload->Length = 0;
2059       status=IOCTL_CALL_SUCCESS;
2060       return status;
2061     }
2062     regDumpInfo.regDumpOffset = Offset;
2063     agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
2064     /* dump either aap1 or iop registers */
2065     switch(agIOCTLPayload->MinorFunction){
2066 
2067     /*Coredump*/
2068     case IOCTL_MN_FW_GET_CORE_DUMP_AAP1:
2069             //CoreDumpBAROffset = RegDump.fatalErrorInfo.regDumpOffset0;    /* get this from mpi config table */
2070             //CoreDumpLength = RegDump.fatalErrorInfo.regDumpLen0;
2071             /*changes for added Call back*/
2072             tdsaAllShared->tdFWControlEx.param1 = agParam1;
2073             tdsaAllShared->tdFWControlEx.param2 = agParam2;
2074             regDumpInfo.regDumpSrc = 0;
2075             regDumpInfo.regDumpNum = 0;
2076             regDumpInfo.directLen = RequestLength;
2077             regDumpInfo.directData = &agIOCTLPayload->FunctionSpecificArea[0];
2078             /*changes for added Call back*/
2079             //status = IOCTL_CALL_SUCCESS;
2080             tdsaAllShared->tdFWControlEx.inProgress = 1;
2081             status = IOCTL_CALL_PENDING;
2082             break;
2083     case IOCTL_MN_FW_GET_CORE_DUMP_IOP:
2084         //CoreDumpBAROffset = RegDump.fatalErrorInfo.regDumpOffset1;    /* get this from mpi config table */
2085         //CoreDumpLength = RegDump.fatalErrorInfo.regDumpLen1;
2086         /*changes for added Call back*/
2087         tdsaAllShared->tdFWControlEx.param1 = agParam1;
2088         tdsaAllShared->tdFWControlEx.param2 = agParam2;
2089         regDumpInfo.regDumpSrc = 0;
2090         regDumpInfo.regDumpNum = 1;
2091         regDumpInfo.directLen = RequestLength;
2092         regDumpInfo.directData = &agIOCTLPayload->FunctionSpecificArea[0];
2093         /*changes for added Call back*/
2094         //status = IOCTL_CALL_SUCCESS;
2095         tdsaAllShared->tdFWControlEx.inProgress = 1;
2096         status = IOCTL_CALL_PENDING;
2097         break;
2098     case IOCTL_MN_FW_GET_CORE_DUMP_FLASH_AAP1:
2099         regDumpInfo.regDumpSrc = 1;
2100         regDumpInfo.regDumpNum = 0;
2101         if(RequestLength != 0)
2102         {
2103             if(ostiAllocMemory( tiRoot,
2104                     &osMemHandle,
2105                     (void **)&buffer,
2106                     &(regDumpInfo.indirectAddrUpper32),
2107                     &(regDumpInfo.indirectAddrLower32),
2108                     8,
2109                     RequestLength,
2110                     agFALSE))
2111                 return IOCTL_CALL_FAIL;
2112         }
2113         osti_memset((void *)buffer, 0, RequestLength);
2114         regDumpInfo.indirectLen = RequestLength;
2115 
2116         // use FW control place in shared structure to keep the neccesary information
2117         tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
2118         tdsaAllShared->tdFWControlEx.virtAddr = buffer;
2119         tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2120         tdsaAllShared->tdFWControlEx.len = RequestLength;
2121         tdsaAllShared->tdFWControlEx.param1 = agParam1;
2122         tdsaAllShared->tdFWControlEx.param2 = agParam2;
2123         tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2124         tdsaAllShared->tdFWControlEx.inProgress = 1;
2125         status = IOCTL_CALL_PENDING;
2126         break;
2127     case IOCTL_MN_FW_GET_CORE_DUMP_FLASH_IOP:
2128         regDumpInfo.regDumpSrc = 1;
2129         regDumpInfo.regDumpNum = 1;
2130         if(RequestLength != 0)
2131         {
2132             if(ostiAllocMemory( tiRoot,
2133                     &osMemHandle,
2134                     (void **)&buffer,
2135                     &(regDumpInfo.indirectAddrUpper32),
2136                     &(regDumpInfo.indirectAddrLower32),
2137                     8,
2138                     RequestLength,
2139                     agFALSE))
2140                 return IOCTL_CALL_FAIL;
2141         }
2142         osti_memset((void *)buffer, 0, RequestLength);
2143         regDumpInfo.indirectLen = RequestLength;
2144 
2145         // use FW control place in shared structure to keep the neccesary information
2146         tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
2147         tdsaAllShared->tdFWControlEx.virtAddr = buffer;
2148         tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2149         tdsaAllShared->tdFWControlEx.len = RequestLength;
2150         tdsaAllShared->tdFWControlEx.param1 = agParam1;
2151         tdsaAllShared->tdFWControlEx.param2 = agParam2;
2152         tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2153         tdsaAllShared->tdFWControlEx.inProgress = 1;
2154         status = IOCTL_CALL_PENDING;
2155         break;
2156     /*EventLog from Flash*/
2157     case IOCTL_MN_FW_GET_EVENT_FLASH_LOG1:      //aap1 Eventlog
2158       if(CoreDumpLength + EventLogOffset <= Offset)
2159       {
2160         agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
2161         agIOCTLPayload->Length = 0;
2162         status=IOCTL_CALL_SUCCESS;
2163         return status;
2164       }
2165       regDumpInfo.regDumpSrc = 1;
2166       regDumpInfo.regDumpNum = 0;
2167       if(RequestLength != 0)
2168       {
2169           if(ostiAllocMemory( tiRoot,
2170                   &osMemHandle,
2171                   (void **)&buffer,
2172                   &(regDumpInfo.indirectAddrUpper32),
2173                   &(regDumpInfo.indirectAddrLower32),
2174                   8,
2175                   RequestLength,
2176                   agFALSE))
2177               return IOCTL_CALL_FAIL;
2178       }
2179       osti_memset((void *)buffer, 0, RequestLength);
2180       regDumpInfo.indirectLen = RequestLength;
2181 
2182       // use FW control place in shared structure to keep the neccesary information
2183       tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
2184       tdsaAllShared->tdFWControlEx.virtAddr = buffer;
2185       tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2186       tdsaAllShared->tdFWControlEx.len = RequestLength;
2187       tdsaAllShared->tdFWControlEx.param1 = agParam1;
2188       tdsaAllShared->tdFWControlEx.param2 = agParam2;
2189       tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2190       tdsaAllShared->tdFWControlEx.inProgress = 1;
2191       status = IOCTL_CALL_PENDING;
2192       break;
2193     case IOCTL_MN_FW_GET_EVENT_FLASH_LOG2:      //iop Eventlog
2194       if(CoreDumpLength + EventLogOffset <= Offset)
2195       {
2196         agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
2197         agIOCTLPayload->Length = 0;
2198         status=IOCTL_CALL_SUCCESS;
2199         return status;
2200       }
2201       regDumpInfo.regDumpSrc = 1;
2202       regDumpInfo.regDumpNum = 1;
2203       if(RequestLength != 0)
2204       {
2205           if(ostiAllocMemory( tiRoot,
2206                   &osMemHandle,
2207                   (void **)&buffer,
2208                   &(regDumpInfo.indirectAddrUpper32),
2209                   &(regDumpInfo.indirectAddrLower32),
2210                   8,
2211                   RequestLength,
2212                   agFALSE))
2213               return IOCTL_CALL_FAIL;
2214       }
2215       osti_memset((void *)buffer, 0, RequestLength);
2216       regDumpInfo.indirectLen = RequestLength;
2217 
2218       // use FW control place in shared structure to keep the neccesary information
2219       tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
2220       tdsaAllShared->tdFWControlEx.virtAddr = buffer;
2221       tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2222       tdsaAllShared->tdFWControlEx.len = RequestLength;
2223       tdsaAllShared->tdFWControlEx.param1 = agParam1;
2224       tdsaAllShared->tdFWControlEx.param2 = agParam2;
2225       tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2226       tdsaAllShared->tdFWControlEx.inProgress = 1;
2227       status = IOCTL_CALL_PENDING;
2228       break;
2229   default:
2230       status = IOCTL_CALL_INVALID_CODE;
2231       TI_DBG1(("tiCOMMgntIOCTL: ERROR: Wrong IOCTL code %d\n", agIOCTLPayload->MinorFunction));
2232       break;
2233     }
2234     if(saGetRegisterDump(agRoot, agNULL, 0, &regDumpInfo) != AGSA_RC_SUCCESS)
2235     {
2236         status = IOCTL_CALL_FAIL;
2237         agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
2238     }
2239 
2240     return status;
2241 }
2242 
2243 osGLOBAL void
2244 ostiCOMMgntVPDSetIOCTLRsp(
2245                           tiRoot_t            *tiRoot,
2246                           bit32               status
2247                           )
2248 {
2249     tdsaRoot_t    *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
2250     tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2251 //    agsaRoot_t    *agRoot = &(tdsaAllShared->agRootInt);
2252 
2253     TI_DBG1(("ostiCOMMgntVPDSetIOCTLRsp: start\n"));
2254     (tdsaAllShared->tdFWControlEx.tdFWControl)->retcode = status;
2255 
2256     ostiFreeMemory(tiRoot,
2257                    tdsaAllShared->tdFWControlEx.buffer,
2258                    tdsaAllShared->tdFWControlEx.len);
2259 
2260     ostiIOCTLSetSignal(tiRoot, tdsaAllShared->tdFWControlEx.param1,
2261                                tdsaAllShared->tdFWControlEx.param2,
2262                                NULL);
2263 }
2264 
2265 /*****************************************************************************
2266 *
2267 * tdsaNVMDSetIoctl
2268 *
2269 * Purpose:  This routine is called to set Config. SEEPROM information.
2270 *           This function is used for both target and initiator.
2271 *
2272 * Parameters:
2273 *   tiRoot:         Pointer to driver instance
2274 *   agIOCTLPayload: Pointer to the IOCTL payload.
2275 *   agParam1:       Pointer to pass context handle for IOCTL DMA operation
2276 *   agParam2:       Pointer to pass context handle for IOCTL DMA operation
2277 *   agParam3:       Pointer to pass context handle for IOCTL DMA operation
2278 *
2279 * Return:
2280 *
2281 *   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
2282 *   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
2283 *                             Detail error code is function specific and
2284 *                             defined by the specific IOCTL function.
2285 *   IOCTL_CALL_PENDING        This request is asynchronous and completed
2286 *                             in some other context.
2287 *   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
2288 *
2289 *
2290 *****************************************************************************/
2291 osGLOBAL bit32
2292 tdsaNVMDSetIoctl(
2293                 tiRoot_t            *tiRoot,
2294                 tiIOCTLPayload_t    *agIOCTLPayload,
2295                 void                *agParam1,
2296                 void                *agParam2,
2297                 void                *agParam3
2298                 )
2299 {
2300   bit32                  RequestLength = 0;
2301   bit32                  bufAddrUpper = 0;
2302   bit32                  bufAddrLower = 0;
2303   tdsaRoot_t             *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
2304   tdsaContext_t          *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2305   agsaRoot_t             *agRoot = &(tdsaAllShared->agRootInt);
2306   void                   *buffer = agNULL;
2307   void                   *osMemHandle = agNULL;
2308   bit32                  status = IOCTL_CALL_SUCCESS;
2309   agsaNVMDData_t         nvmdInfo;
2310 
2311 
2312   TI_DBG2(("tdsaNVMDSetIoctl: start\n"));
2313 
2314   RequestLength = agIOCTLPayload->Length;
2315 
2316   osti_memset(&nvmdInfo, 0, sizeof(agsaNVMDData_t));
2317 
2318   switch(agIOCTLPayload->MinorFunction)
2319   {
2320     case IOCTL_MN_NVMD_SET_CONFIG:
2321 
2322       //nvmdInfo.NVMDevice = 1;
2323       nvmdInfo.NVMDevice = *((bit8*)agParam3);
2324       nvmdInfo.signature = 0xFEDCBA98;
2325       nvmdInfo.dataOffsetAddress = agIOCTLPayload->Reserved;
2326       nvmdInfo.indirectPayload = 1;
2327       nvmdInfo.indirectLen = RequestLength;
2328 
2329       if (nvmdInfo.NVMDevice == 0) {
2330         nvmdInfo.TWIDeviceAddress = 0xa0;
2331         nvmdInfo.TWIBusNumber = 0;
2332         nvmdInfo.TWIDevicePageSize = 0;
2333         nvmdInfo.TWIDeviceAddressSize = 1;
2334       }
2335 
2336       if(RequestLength != 0)
2337       {
2338         if(ostiAllocMemory( tiRoot,
2339             &osMemHandle,
2340             (void **)&buffer,
2341             &bufAddrUpper,
2342             &bufAddrLower,
2343             8,
2344             RequestLength,
2345             agFALSE))
2346           return IOCTL_CALL_FAIL;
2347       }
2348       else
2349       {
2350         return IOCTL_CALL_FAIL;
2351       }
2352 
2353       osti_memset((void *)buffer, 0, RequestLength);
2354 
2355       osti_memcpy((void *)buffer,
2356             agIOCTLPayload->FunctionSpecificArea,
2357             RequestLength);
2358 
2359       nvmdInfo.indirectAddrLower32 = bufAddrLower;
2360       nvmdInfo.indirectAddrUpper32 = bufAddrUpper;
2361       // use FW control place in shared structure to keep the neccesary information
2362       tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
2363       tdsaAllShared->tdFWControlEx.virtAddr = buffer;
2364       tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2365       tdsaAllShared->tdFWControlEx.len = RequestLength;
2366       tdsaAllShared->tdFWControlEx.param1 = agParam1;
2367       tdsaAllShared->tdFWControlEx.param2 = agParam2;
2368       tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2369       tdsaAllShared->tdFWControlEx.inProgress = 1;
2370       status = IOCTL_CALL_PENDING;
2371       break;
2372     default:
2373         status = IOCTL_CALL_INVALID_CODE;
2374         TI_DBG1(("tdsaNVMDSetIoctl: ERROR: Wrong IOCTL code %d\n", agIOCTLPayload->MinorFunction));
2375         break;
2376   }
2377 
2378   if(saSetNVMDCommand(agRoot, agNULL, 0, &nvmdInfo) != AGSA_RC_SUCCESS)
2379   {
2380       status = IOCTL_CALL_FAIL;
2381       agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
2382   }
2383 
2384   return status;
2385 
2386 }
2387 
2388 /*****************************************************************************
2389 *
2390 * tdsaNVMDGetIoctl
2391 *
2392 * Purpose:  This routine is called to get Config. SEEPROM information.
2393 *           This function is used for both target and initiator.
2394 *
2395 * Parameters:
2396 *   tiRoot:         Pointer to driver instance
2397 *   agIOCTLPayload: Pointer to the IOCTL payload.
2398 *   agParam1:       Pointer to pass context handle for IOCTL DMA operation
2399 *   agParam2:       Pointer to pass context handle for IOCTL DMA operation
2400 *   agParam3:       Pointer to pass context handle for IOCTL DMA operation
2401 *
2402 * Return:
2403 *
2404 *   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
2405 *   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
2406 *                             Detail error code is function specific and
2407 *                             defined by the specific IOCTL function.
2408 *   IOCTL_CALL_PENDING        This request is asynchronous and completed
2409 *                             in some other context.
2410 *   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
2411 *
2412 *
2413 *****************************************************************************/
2414 osGLOBAL bit32
2415 tdsaNVMDGetIoctl(
2416                 tiRoot_t            *tiRoot,
2417                 tiIOCTLPayload_t    *agIOCTLPayload,
2418                 void                *agParam1,
2419                 void                *agParam2,
2420                 void                *agParam3
2421                 )
2422 {
2423   tdsaRoot_t      *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
2424   tdsaContext_t   *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2425   agsaRoot_t      *agRoot = &(tdsaAllShared->agRootInt);
2426   void            *buffer = agNULL;
2427   void            *osMemHandle = agNULL;
2428   bit32           status = IOCTL_CALL_SUCCESS;
2429   agsaNVMDData_t  nvmdInfo;
2430   bit32           Offset = 0;
2431   bit32           RequestLength = 0;
2432   bit32		  ostiMemoryStatus = 0;
2433   bit32		  i,j;
2434   bit8*		  seepromBuffer;
2435   bit8*		  phySettingsBuffer;
2436 
2437 
2438   TI_DBG2(("tdsaNVMDGetIoctl: start\n"));
2439 
2440   RequestLength = agIOCTLPayload->Length;
2441   Offset = agIOCTLPayload->Reserved;
2442 
2443   osti_memset(&nvmdInfo, 0, sizeof(agsaNVMDData_t));
2444   /* This condition is not valid for direct read so commenting */
2445   /*if(!tiIS_SPC(agRoot)) {
2446      if( RequestLength <= Offset ) //4096-max seeprom size
2447      {
2448     	agIOCTLPayload->Status = IOCTL_ERR_STATUS_NO_MORE_DATA;
2449     	agIOCTLPayload->Length = 0;
2450     	status=IOCTL_CALL_SUCCESS;
2451     	return status;
2452      }
2453   }*/
2454 
2455   agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
2456 
2457   switch(agIOCTLPayload->MinorFunction)
2458   {
2459     case IOCTL_MN_NVMD_GET_CONFIG:
2460 
2461    //   nvmdInfo.NVMDevice = 1;
2462       nvmdInfo.NVMDevice = *((bit8*)agParam3);
2463       nvmdInfo.signature = 0xFEDCBA98;
2464       nvmdInfo.dataOffsetAddress = Offset;
2465       nvmdInfo.indirectPayload = 1;
2466       nvmdInfo.indirectLen = RequestLength;
2467 
2468       if (nvmdInfo.NVMDevice == 0) {
2469         nvmdInfo.TWIDeviceAddress = 0xa0;
2470         nvmdInfo.TWIBusNumber = 0;
2471         nvmdInfo.TWIDevicePageSize = 0;
2472         nvmdInfo.TWIDeviceAddressSize = 1;
2473       }
2474 
2475       if(RequestLength != 0)
2476       {
2477         ostiMemoryStatus = ostiAllocMemory( tiRoot,
2478             &osMemHandle,
2479             (void **)&buffer,
2480             &(nvmdInfo.indirectAddrUpper32),
2481             &(nvmdInfo.indirectAddrLower32),
2482             8,
2483             RequestLength,
2484             agFALSE);
2485 	if((ostiMemoryStatus != tiSuccess) && (buffer == agNULL))
2486         return IOCTL_CALL_FAIL;
2487      }
2488       else
2489       {
2490         return IOCTL_CALL_FAIL;
2491       }
2492       osti_memset((void *)buffer, 0, RequestLength);
2493 
2494       // use FW control place in shared structure to keep the neccesary information
2495       tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
2496       tdsaAllShared->tdFWControlEx.virtAddr = buffer;
2497       tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2498       tdsaAllShared->tdFWControlEx.len = RequestLength;
2499       tdsaAllShared->tdFWControlEx.param1 = agParam1;
2500       tdsaAllShared->tdFWControlEx.param2 = agParam2;
2501       tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2502       tdsaAllShared->tdFWControlEx.inProgress = 1;
2503       status = IOCTL_CALL_PENDING;
2504       break;
2505       default:
2506       status = IOCTL_CALL_INVALID_CODE;
2507       TI_DBG1(("tiCOMMgntIOCTL: ERROR: Wrong IOCTL code %d\n", agIOCTLPayload->MinorFunction));
2508       break;
2509   }
2510   tdsaAllShared->NvmdResponseSet = 0;
2511 
2512   if(saGetNVMDCommand(agRoot, agNULL, 0, &nvmdInfo) != AGSA_RC_SUCCESS)
2513   {
2514     status = IOCTL_CALL_FAIL;
2515     agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
2516     return status;
2517   }
2518   /* Copy the SAS address */
2519   if(agParam1 == agNULL)
2520 
2521   {
2522      while(!tdsaAllShared->NvmdResponseSet)
2523      {
2524    //	tiCOMDelayedInterruptHandler(tiRoot, 0, 1, tiNonInterruptContext);
2525      }
2526      if(nvmdInfo.NVMDevice == 4 || nvmdInfo.NVMDevice == 1)
2527      {
2528 	seepromBuffer = buffer;
2529 	/*Get Initiator SAS address*/
2530 
2531 	if(tiIS_SPC(agRoot))
2532 	{
2533 	   for(j=0,i=ADAPTER_WWN_SPC_START_OFFSET; i<= ADAPTER_WWN_SPC_END_OFFSET; i++,j++)
2534 	  agIOCTLPayload->FunctionSpecificArea[j] = seepromBuffer[i];
2535         }
2536  	else
2537 	{
2538 	  for(j=0,i=ADAPTER_WWN_START_OFFSET; i<= ADAPTER_WWN_END_OFFSET; i++,j++)
2539 	  agIOCTLPayload->FunctionSpecificArea[j] = seepromBuffer[i];
2540 	}
2541     }
2542     /* Copy the Phy settings */
2543     else if(nvmdInfo.NVMDevice == 6)
2544     {
2545       phySettingsBuffer = buffer;
2546       for(i=0; i<PHY_SETTINGS_LEN; i++)
2547 	agIOCTLPayload->FunctionSpecificArea[i] = phySettingsBuffer[i];
2548     }
2549     tdsaAllShared->NvmdResponseSet = 0;
2550     ostiFreeMemory(tiRoot, tdsaAllShared->tdFWControlEx.buffer, tdsaAllShared->tdFWControlEx.len);
2551 
2552   }
2553   return status;
2554 
2555 }
2556 
2557 /*****************************************************************************
2558 *
2559 * tdsaDeviceInfoGetIoctl
2560 *
2561 * Purpose:  This routine is called to get the specified device information.
2562 *
2563 * Parameters:
2564 *   tiRoot:         Pointer to driver instance
2565 *   agIOCTLPayload: Pointer to the IOCTL payload.
2566 *   agParam1:       Pointer to pass context handle for IOCTL DMA operation
2567 *   agParam2:       Pointer to pass context handle for IOCTL DMA operation
2568 *   agParam3:       Pointer to pass context handle for IOCTL DMA operation
2569 *
2570 * Return:
2571 *
2572 *   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
2573 *   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
2574 *                             Detail error code is function specific and
2575 *                             defined by the specific IOCTL function.
2576 *   IOCTL_CALL_PENDING        This request is asynchronous and completed
2577 *                             in some other context.
2578 *   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
2579 *
2580 *
2581 *****************************************************************************/
2582 osGLOBAL bit32
2583 tdsaDeviceInfoGetIoctl(
2584                 tiRoot_t            *tiRoot,
2585                 tiIOCTLPayload_t    *agIOCTLPayload,
2586                 void                *agParam1,
2587                 void                *agParam2,
2588                 void                *agParam3
2589                 )
2590 {
2591   tdsaDeviceData_t       *oneDeviceData = agNULL;
2592   tiDeviceHandle_t       *tiDeviceHandle = agNULL;
2593   tdDeviceInfoPayload_t  *pDeviceInfo = agNULL;
2594   /*agsaDevHandle_t  *agDevHandle = agNULL;*/
2595   bit32            status = IOCTL_CALL_SUCCESS;
2596 
2597   pDeviceInfo = (tdDeviceInfoPayload_t*)agIOCTLPayload->FunctionSpecificArea;
2598 
2599   TI_DBG3(("tdsaDeviceInfoGetIoctl: %d:%3d:%d %p %p %p\n",
2600                                      (bit8)pDeviceInfo->PathId,
2601                                      (bit8)pDeviceInfo->TargetId,
2602                                      (bit8)pDeviceInfo->Lun,
2603                                       agParam1,
2604                                       agParam2,
2605                                       agParam3));
2606 
2607   tiDeviceHandle = ostiMapToDevHandle(tiRoot,
2608                                      (bit8)pDeviceInfo->PathId,
2609                                      (bit8)pDeviceInfo->TargetId,
2610                                      (bit8)pDeviceInfo->Lun
2611                                      );
2612 
2613   if (tiDeviceHandle == agNULL)
2614   {
2615     TI_DBG1(("tdsaDeviceInfoGetIoctl: tiDeviceHandle is NULL !!!! SCSI address = %d:%3d:%d\n",
2616               pDeviceInfo->PathId, pDeviceInfo->TargetId, pDeviceInfo->Lun));
2617     agIOCTLPayload->Status = IOCTL_ERR_STATUS_INVALID_DEVICE;
2618     status = IOCTL_CALL_FAIL;
2619     return status;
2620   }
2621 
2622   oneDeviceData = (tdsaDeviceData_t *)tiDeviceHandle->tdData;
2623   if(oneDeviceData == agNULL)
2624   {
2625     TI_DBG1(("tdsaDeviceInfoGetIoctl: tiDeviceHandle=%p DeviceData is NULL!!! SCSI address = %d:%3d:%d\n",
2626              tiDeviceHandle, pDeviceInfo->PathId, pDeviceInfo->TargetId, pDeviceInfo->Lun));
2627     agIOCTLPayload->Status = IOCTL_ERR_STATUS_INVALID_DEVICE;
2628     status = IOCTL_CALL_FAIL;
2629     return status;
2630   }
2631 
2632   /* for hotplug */
2633   if (oneDeviceData->valid != agTRUE || oneDeviceData->registered != agTRUE ||
2634       oneDeviceData->tdPortContext == agNULL )
2635   {
2636     TI_DBG1(("tdsaDeviceInfoGetIoctl: tiDeviceHandle=%p did %d DeviceData was removed!!! SCSI address = %d:%3d:%d\n",
2637              tiDeviceHandle, oneDeviceData->id, pDeviceInfo->PathId, pDeviceInfo->TargetId, pDeviceInfo->Lun));
2638     agIOCTLPayload->Status = IOCTL_ERR_STATUS_INVALID_DEVICE;
2639     status = IOCTL_CALL_FAIL;
2640     return status;
2641   }
2642 
2643   /* fill the device information in IOCTL payload */
2644   pDeviceInfo->devInfo.phyId = oneDeviceData->phyID;
2645   osti_memcpy(&pDeviceInfo->devInfo.sasAddressHi, oneDeviceData->agDeviceInfo.sasAddressHi, sizeof(bit32));
2646   osti_memcpy(&pDeviceInfo->devInfo.sasAddressLo, oneDeviceData->agDeviceInfo.sasAddressLo, sizeof(bit32));
2647 
2648   pDeviceInfo->devInfo.sasAddressHi = DMA_BEBIT32_TO_BIT32(pDeviceInfo->devInfo.sasAddressHi);
2649   pDeviceInfo->devInfo.sasAddressLo = DMA_BEBIT32_TO_BIT32(pDeviceInfo->devInfo.sasAddressLo);
2650 
2651   pDeviceInfo->devInfo.deviceType = (oneDeviceData->agDeviceInfo.devType_S_Rate & 0x30) >> 4;
2652   pDeviceInfo->devInfo.linkRate   = oneDeviceData->agDeviceInfo.devType_S_Rate & 0x0F;
2653 
2654   agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
2655 
2656   TI_DBG3(("tdsaDeviceInfoGetIoctl:IOCTL_CALL_SUCCESS\n"));
2657 
2658   /*saGetDeviceInfo(agRoot, agNULL, 0, 0, agDevHandle);*/
2659 
2660   status = IOCTL_CALL_SUCCESS;
2661 
2662   return status;
2663 }
2664 /*****************************************************************************
2665 *
2666 * tdsaIoErrorStatisticGetIoctl
2667 *
2668 * Purpose:  This routine is called to get the IO error statistic.
2669 *
2670 * Parameters:
2671 *   tiRoot:         Pointer to driver instance
2672 *   agIOCTLPayload: Pointer to the IOCTL payload.
2673 *   agParam1:       Pointer to pass context handle for IOCTL DMA operation
2674 *   agParam2:       Pointer to pass context handle for IOCTL DMA operation
2675 *   agParam3:       Pointer to pass context handle for IOCTL DMA operation
2676 *
2677 * Return:
2678 *
2679 *   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
2680 *   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
2681 *                             Detail error code is function specific and
2682 *                             defined by the specific IOCTL function.
2683 *   IOCTL_CALL_PENDING        This request is asynchronous and completed
2684 *                             in some other context.
2685 *   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
2686 *
2687 *
2688 *****************************************************************************/
2689 osGLOBAL bit32
2690 tdsaIoErrorStatisticGetIoctl(
2691                  tiRoot_t            *tiRoot,
2692                  tiIOCTLPayload_t    *agIOCTLPayload,
2693                  void                *agParam1,
2694                  void                *agParam2,
2695                  void                *agParam3
2696                  )
2697 {
2698   tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
2699   tdsaContext_t               *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2700   agsaRoot_t                  *agRoot          = &(tdsaAllShared->agRootInt);
2701   tdIoErrorStatisticPayload_t *pIoErrorPayload = agNULL;
2702   bit32                        status = IOCTL_CALL_SUCCESS;
2703 
2704   pIoErrorPayload = (tdIoErrorStatisticPayload_t*)agIOCTLPayload->FunctionSpecificArea;
2705 
2706   tdsaAllShared->tdFWControlEx.buffer = agNULL;
2707   tdsaAllShared->tdFWControlEx.virtAddr = agNULL;
2708   tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2709   tdsaAllShared->tdFWControlEx.len = 0;
2710   tdsaAllShared->tdFWControlEx.param1 = agParam1;
2711   tdsaAllShared->tdFWControlEx.param2 = agParam2;
2712   tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2713   tdsaAllShared->tdFWControlEx.inProgress = 0;
2714 
2715   saGetIOErrorStats(agRoot, agNULL, pIoErrorPayload->flag);
2716 
2717   return status;
2718 }
2719 
2720 /*****************************************************************************
2721 *
2722 * tdsaIoEventStatisticGetIoctl
2723 *
2724 * Purpose:  This routine is called to get the IO event statistic.
2725 *
2726 * Parameters:
2727 *   tiRoot:         Pointer to driver instance
2728 *   agIOCTLPayload: Pointer to the IOCTL payload.
2729 *   agParam1:       Pointer to pass context handle for IOCTL DMA operation
2730 *   agParam2:       Pointer to pass context handle for IOCTL DMA operation
2731 *   agParam3:       Pointer to pass context handle for IOCTL DMA operation
2732 *
2733 * Return:
2734 *
2735 *   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
2736 *   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
2737 *                             Detail error code is function specific and
2738 *                             defined by the specific IOCTL function.
2739 *   IOCTL_CALL_PENDING        This request is asynchronous and completed
2740 *                             in some other context.
2741 *   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
2742 *
2743 *
2744 *****************************************************************************/
2745 osGLOBAL bit32
2746 tdsaIoEventStatisticGetIoctl(
2747                  tiRoot_t            *tiRoot,
2748                  tiIOCTLPayload_t    *agIOCTLPayload,
2749                  void                *agParam1,
2750                  void                *agParam2,
2751                  void                *agParam3
2752                  )
2753 {
2754   tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
2755   tdsaContext_t               *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2756   agsaRoot_t                  *agRoot          = &(tdsaAllShared->agRootInt);
2757   tdIoEventStatisticPayload_t *pIoEventPayload = agNULL;
2758   bit32                        status = IOCTL_CALL_SUCCESS;
2759 
2760   pIoEventPayload = (tdIoEventStatisticPayload_t*)agIOCTLPayload->FunctionSpecificArea;
2761 
2762   tdsaAllShared->tdFWControlEx.buffer = agNULL;
2763   tdsaAllShared->tdFWControlEx.virtAddr = agNULL;
2764   tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2765   tdsaAllShared->tdFWControlEx.len = 0;
2766   tdsaAllShared->tdFWControlEx.param1 = agParam1;
2767   tdsaAllShared->tdFWControlEx.param2 = agParam2;
2768   tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2769   tdsaAllShared->tdFWControlEx.inProgress = 0;
2770 
2771   saGetIOEventStats(agRoot, agNULL, pIoEventPayload->flag);
2772 
2773   return status;
2774 }
2775 
2776 /*****************************************************************************
2777 *
2778 * tdsaRegisterIoctl
2779 *
2780 * Purpose:  This routine is called to get Forensic Data.
2781 *
2782 * Parameters:
2783 *   tiRoot:         Pointer to driver instance
2784 *   agIOCTLPayload: Pointer to the IOCTL payload.
2785 *   agParam1:       Pointer to pass context handle for IOCTL DMA operation
2786 *   agParam2:       Pointer to pass context handle for IOCTL DMA operation
2787 *   agParam3:       Pointer to pass context handle for IOCTL DMA operation
2788 *
2789 * Return:
2790 *
2791 *   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
2792 *   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
2793 *                             Detail error code is function specific and
2794 *                             defined by the specific IOCTL function.
2795 *   IOCTL_CALL_PENDING        This request is asynchronous and completed
2796 *                             in some other context.
2797 *   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
2798 *
2799 *
2800 *****************************************************************************/
2801 osGLOBAL bit32
2802 tdsaRegisterIoctl(
2803                  tiRoot_t            *tiRoot,
2804                  tiIOCTLPayload_t    *agIOCTLPayload,
2805                  void                *agParam1,
2806                  void                *agParam2,
2807                  void                *agParam3
2808                  )
2809 {
2810   tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
2811   tdsaContext_t               *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2812 //  agsaRoot_t                  *agRoot          = &(tdsaAllShared->agRootInt);
2813   tdRegisterPayload_t         *pRegisterPayload = agNULL;
2814   bit32                        status = IOCTL_CALL_SUCCESS;
2815 
2816   pRegisterPayload = (tdRegisterPayload_t*)agIOCTLPayload->FunctionSpecificArea;
2817 
2818   tdsaAllShared->tdFWControlEx.buffer = agNULL;
2819   tdsaAllShared->tdFWControlEx.virtAddr = agNULL;
2820   tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2821   tdsaAllShared->tdFWControlEx.len = 0;
2822   tdsaAllShared->tdFWControlEx.param1 = agParam1;
2823   tdsaAllShared->tdFWControlEx.param2 = agParam2;
2824   tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2825   tdsaAllShared->tdFWControlEx.inProgress = 0;
2826 
2827   TI_DBG1(("tdsaRegisterIoctl: Flag %d RegAddr 0x%x RegValue 0x%x\n",
2828             pRegisterPayload->flag, pRegisterPayload->RegAddr, pRegisterPayload->RegValue));
2829 
2830   if (pRegisterPayload->flag)
2831   {
2832     /* set register */
2833     ostiChipWriteBit32Ext(tiRoot, 0, pRegisterPayload->RegAddr, pRegisterPayload->RegValue);
2834   }
2835   else
2836   {
2837     /* get register */
2838     pRegisterPayload->RegValue = ostiChipReadBit32Ext(tiRoot, 0, pRegisterPayload->RegAddr);
2839   }
2840   agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
2841   return status;
2842 }
2843 
2844 osGLOBAL bit32
2845 tdsaGetPhyGeneralStatusIoctl(
2846 				tiRoot_t			      *tiRoot,
2847 				agsaPhyGeneralState_t     *PhyData
2848 				)
2849 {
2850   tdsaRoot_t				*tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
2851   tdsaContext_t 			*tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2852   agsaRoot_t				*agRoot = &(tdsaAllShared->agRootNonInt);
2853 //  agsaLLRoot_t	            *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
2854 //  bit8                      totalValidPhys;
2855   bit32 					 status = AGSA_RC_SUCCESS;
2856   bit32                      i = 0;
2857   agsaControllerInfo_t ControllerInfo;
2858   saGetControllerInfo(agRoot,&ControllerInfo);
2859 
2860   TI_DBG3(("tdsaGetPhyGeneralStatusIoctl: start\n"));
2861   do
2862   {
2863     if(tIsSPC(agRoot)||tIsSPCHIL(agRoot))
2864     {
2865   	    status = IOCTL_ERR_STATUS_NOT_SUPPORTED;
2866 		break;
2867     }
2868 
2869     PhyData->Reserved1 = ControllerInfo.phyCount;
2870     for(i=0;i<PhyData->Reserved1;i++)
2871     {
2872       status = saGetPhyProfile( agRoot,agNULL,tdsaRotateQnumber(tiRoot, agNULL), AGSA_SAS_PHY_GENERAL_STATUS_PAGE,i);
2873       if(status == AGSA_RC_FAILURE)
2874 	  {
2875 	    break;
2876 	  }
2877     }
2878   }while(0);
2879   TI_DBG3(("tdsaGetPhyGeneralStatusIoctl: End\n"));
2880   return status;
2881 }
2882 /*****************************************************************************
2883 *
2884 * ostiGetPhyGeneralStatusRsp
2885 *
2886 * Purpose:  This routine is called when a PhyStatus IOCTL response is received.
2887 *
2888 * Parameters:
2889 *   tiRoot:         Pointer to driver instance
2890 *   agsaSASPhyGeneralStatusPage_t:   Status of the phy.
2891 *   bit32:          phyID
2892 *
2893 * Return: none
2894 *
2895 *
2896 *****************************************************************************/
2897 osGLOBAL void ostiGetPhyGeneralStatusRsp(
2898                             tiRoot_t                      *tiRoot,
2899                         	agsaSASPhyGeneralStatusPage_t *GenStatus,
2900                         	bit32                          phyID
2901                             )
2902 {
2903 
2904   tdsaRoot_t               *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
2905   tdsaContext_t            *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2906   tiIOCTLPayload_t         *agIoctlPayload = agNULL;
2907   agsaPhyGeneralState_t    *pSetPhyStatusRes = agNULL;
2908 
2909 
2910   TI_DBG1(("ostiGetPhyGeneralStatusRsp: start\n"));
2911 
2912   if (tdsaAllShared->tdFWControlEx.inProgress)
2913   {
2914       agIoctlPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
2915       if ((agIoctlPayload) && (PMC_IOCTL_SIGNATURE == agIoctlPayload->Signature)&&
2916 	  	                 (IOCTL_MJ_PHY_GENERAL_STATUS == agIoctlPayload->MajorFunction))
2917       {
2918         pSetPhyStatusRes = (agsaPhyGeneralState_t*) &agIoctlPayload->FunctionSpecificArea[0];
2919 		osti_memcpy(&pSetPhyStatusRes->PhyGenData[phyID], GenStatus, sizeof(agsaSASPhyGeneralStatusPage_t));
2920 		pSetPhyStatusRes->Reserved2++;
2921         if(pSetPhyStatusRes->Reserved1 == pSetPhyStatusRes->Reserved2)
2922         {
2923   		  tdsaAllShared->tdFWControlEx.payload = NULL;
2924           ostiIOCTLSetSignal(tiRoot, tdsaAllShared->tdFWControlEx.param1,
2925                           tdsaAllShared->tdFWControlEx.param2, agNULL);
2926 	  tdsaAllShared->tdFWControlEx.inProgress = 0;
2927           agIoctlPayload->Status = IOCTL_ERR_STATUS_OK;
2928 
2929         }
2930   	  }
2931   }
2932 
2933   TI_DBG1(("ostiGetPhyGeneralStatusRsp: end\n"));
2934 }
2935 
2936 
2937 osGLOBAL bit32
2938 tdsaPhyProfileIoctl(
2939                  tiRoot_t            *tiRoot,
2940                  tiIOCTLPayload_t    *agIOCTLPayload,
2941                  void                *agParam1,
2942                  void                *agParam2,
2943                  void                *agParam3
2944                  )
2945 {
2946   tdsaRoot_t       *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
2947   tdsaContext_t    *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
2948   agsaRoot_t       *agRoot          = &(tdsaAllShared->agRootInt);
2949   void             *buffer = agNULL;
2950   void             *osMemHandle = agNULL;
2951   bit32            status = IOCTL_CALL_SUCCESS;
2952   bit32            retcode = AGSA_RC_FAILURE;
2953   bit32            RequestLength= agIOCTLPayload->Length;
2954   bit32 	   bufAddrUpper = 0;
2955   bit32 	   bufAddrLower = 0;
2956 
2957   tdPhyCount_t     *PhyBlob = (tdPhyCount_t*)&agIOCTLPayload->FunctionSpecificArea[0];
2958 
2959 
2960   if(ostiAllocMemory( tiRoot,
2961       &osMemHandle,
2962       (void **)&buffer,
2963       &bufAddrUpper,
2964       &bufAddrLower,
2965       RequestLength,
2966       RequestLength,
2967       agTRUE))
2968     return IOCTL_CALL_FAIL;
2969 
2970 
2971   tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
2972   tdsaAllShared->tdFWControlEx.virtAddr = buffer;
2973   tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
2974   tdsaAllShared->tdFWControlEx.len = 32;
2975   tdsaAllShared->tdFWControlEx.param1 = agParam1;
2976   tdsaAllShared->tdFWControlEx.param2 = agParam2;
2977   tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
2978   tdsaAllShared->tdFWControlEx.inProgress = 1;
2979 
2980   TI_DBG1(("tdsaPhyProfileIoctl: MinorFunction %d\n",agIOCTLPayload->MinorFunction));
2981 //  PhyBlob->Phy |= 0x100;
2982 
2983   if( tiIS_SPC(agRoot) )
2984   {
2985     TI_DBG1(("tdsaPhyProfileIoctl: SPC operation 0x%x PHY %d\n",agIOCTLPayload->MinorFunction,PhyBlob->Phy));
2986     retcode = saLocalPhyControl(agRoot,agNULL,0 ,PhyBlob->Phy ,agIOCTLPayload->MinorFunction , agNULL);
2987     if(retcode ==  AGSA_RC_SUCCESS)
2988     {
2989       status = IOCTL_CALL_PENDING;
2990     }
2991   }
2992   else
2993   {
2994     TI_DBG1(("tdsaPhyProfileIoctl: SPCv operation 0x%x PHY %d\n",agIOCTLPayload->MinorFunction,PhyBlob->Phy));
2995     retcode = saGetPhyProfile( agRoot,agNULL,0,agIOCTLPayload->MinorFunction , PhyBlob->Phy);
2996 
2997     if(retcode ==  AGSA_RC_SUCCESS)
2998     {
2999       status = IOCTL_CALL_PENDING;
3000     }
3001 
3002   }
3003 
3004   TI_DBG2(("tdsaPhyProfileIoctl: after\n"));
3005 
3006 
3007   return status;
3008 }
3009 
3010 /*****************************************************************************
3011 *
3012 * tdsaForensicDataGetIoctl
3013 *
3014 * Purpose:  This routine is called to get Forensic Data.
3015 *
3016 * Parameters:
3017 *   tiRoot:         Pointer to driver instance
3018 *   agIOCTLPayload: Pointer to the IOCTL payload.
3019 *   agParam1:       Pointer to pass context handle for IOCTL DMA operation
3020 *   agParam2:       Pointer to pass context handle for IOCTL DMA operation
3021 *   agParam3:       Pointer to pass context handle for IOCTL DMA operation
3022 *
3023 * Return:
3024 *
3025 *   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
3026 *   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
3027 *                             Detail error code is function specific and
3028 *                             defined by the specific IOCTL function.
3029 *   IOCTL_CALL_PENDING        This request is asynchronous and completed
3030 *                             in some other context.
3031 *   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
3032 *
3033 *
3034 *****************************************************************************/
3035 osGLOBAL bit32
3036 tdsaForensicDataGetIoctl(
3037                  tiRoot_t            *tiRoot,
3038                  tiIOCTLPayload_t    *agIOCTLPayload,
3039                  void                *agParam1,
3040                  void                *agParam2,
3041                  void                *agParam3
3042                  )
3043 {
3044   tdsaRoot_t                  *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
3045   tdsaContext_t               *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3046   agsaRoot_t                  *agRoot          = &(tdsaAllShared->agRootInt);
3047   tdForensicDataPayload_t     *pForensicDataPayload = agNULL;
3048   agsaForensicData_t           ForensicData;
3049   bit32                        status = IOCTL_CALL_SUCCESS;
3050 
3051   pForensicDataPayload = (tdForensicDataPayload_t*)agIOCTLPayload->FunctionSpecificArea;
3052 
3053   tdsaAllShared->tdFWControlEx.buffer = agNULL;
3054   tdsaAllShared->tdFWControlEx.virtAddr = agNULL;
3055   tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
3056   tdsaAllShared->tdFWControlEx.len = 0;
3057   tdsaAllShared->tdFWControlEx.param1 = agParam1;
3058   tdsaAllShared->tdFWControlEx.param2 = agParam2;
3059   tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
3060   tdsaAllShared->tdFWControlEx.inProgress = 0;
3061 
3062   osti_memset(&ForensicData, 0, sizeof(agsaForensicData_t));
3063 
3064   ForensicData.DataType = pForensicDataPayload->DataType;
3065 
3066   switch (ForensicData.DataType)
3067   {
3068     case FORENSIC_DATA_TYPE_NON_FATAL:
3069     case FORENSIC_DATA_TYPE_FATAL:
3070          ForensicData.BufferType.dataBuf.directLen = pForensicDataPayload->dataBuffer.directLen;
3071          ForensicData.BufferType.dataBuf.directOffset = pForensicDataPayload->dataBuffer.directOffset;
3072          ForensicData.BufferType.dataBuf.readLen = pForensicDataPayload->dataBuffer.readLen;
3073          ForensicData.BufferType.dataBuf.directData = (void*)pForensicDataPayload->dataBuffer.directData;
3074 		 break;
3075     case FORENSIC_DATA_TYPE_GSM_SPACE:
3076          ForensicData.BufferType.gsmBuf.directLen = pForensicDataPayload->gsmBuffer.directLen;
3077          ForensicData.BufferType.gsmBuf.directOffset = pForensicDataPayload->gsmBuffer.directOffset;
3078          ForensicData.BufferType.dataBuf.readLen      = pForensicDataPayload->gsmBuffer.readLen;
3079          ForensicData.BufferType.gsmBuf.directData = (void*)pForensicDataPayload->gsmBuffer.directData;
3080          break;
3081 
3082     case FORENSIC_DATA_TYPE_IB_QUEUE:
3083          ForensicData.BufferType.queueBuf.directLen = pForensicDataPayload->queueBuffer.directLen;
3084          //ForensicData.BufferType.queueBuf.queueType = pForensicDataPayload->queueBuffer.queueType;
3085          ForensicData.BufferType.queueBuf.queueType = FORENSIC_DATA_TYPE_IB_QUEUE;
3086          ForensicData.BufferType.queueBuf.queueIndex = pForensicDataPayload->queueBuffer.queueIndex;
3087          ForensicData.BufferType.queueBuf.directData = (void*)pForensicDataPayload->queueBuffer.directData;
3088          break;
3089     case FORENSIC_DATA_TYPE_OB_QUEUE:
3090          ForensicData.BufferType.queueBuf.directLen = pForensicDataPayload->queueBuffer.directLen;
3091          ForensicData.BufferType.queueBuf.queueType = FORENSIC_DATA_TYPE_OB_QUEUE;
3092          ForensicData.BufferType.queueBuf.queueIndex = pForensicDataPayload->queueBuffer.queueIndex;
3093          ForensicData.BufferType.queueBuf.directData = (void*)pForensicDataPayload->queueBuffer.directData;
3094          break;
3095 
3096     default:
3097          TI_DBG1(("tdsaGetForensicDataIoctl: forensic data type error %d\n", pForensicDataPayload->DataType));
3098          status = IOCTL_CALL_INVALID_CODE;
3099          return status;
3100   }
3101 
3102   if ( saGetForensicData(agRoot, agNULL, &ForensicData) != AGSA_RC_SUCCESS )
3103   {
3104     status = IOCTL_CALL_FAIL;
3105   }
3106 
3107   return status;
3108 }
3109 
3110 osGLOBAL bit32
3111 tdsaSendSMPIoctl(
3112                 tiRoot_t            *tiRoot,
3113                 tiIOCTLPayload_t    *agIOCTLPayload,
3114                 void                *agParam1,
3115                 void                *agParam2,
3116                 void                *agParam3
3117                 )
3118 {
3119 	tdsaRoot_t		*tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
3120 	tdsaContext_t	*tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3121 	agsaRoot_t		*agRoot = &(tdsaAllShared->agRootInt);
3122 	void			*reqBuffer = agNULL;
3123 	void			*respBuffer = agNULL;
3124 	void			*osMemHandle = agNULL;
3125 	bit32			status = IOCTL_CALL_SUCCESS;
3126 //	bit32			Offset = 0;
3127 //	bit32			RequestLength = 0;
3128 	bit32			ostiMemoryStatus = 0;
3129 	smp_pass_through_req_t *smp_pass_through_req;
3130 
3131 	tiDeviceHandle_t *devHandle;
3132 	agsaSMPFrame_t			  agSMPFrame;
3133 	tdsaDeviceData_t          *oneDeviceData = agNULL;
3134 	bit32 i;
3135 
3136 	TI_DBG2(("tdsaSendSMPIoctl: start\n"));
3137 
3138  	smp_pass_through_req = (smp_pass_through_req_t*)agIOCTLPayload->FunctionSpecificArea;
3139 
3140 	for(i=0;i<8;i++)
3141 		TI_DBG2(("SAS Address[%d]:%x",i,smp_pass_through_req->exp_sas_addr[i]));
3142 	TI_DBG2(("SAS Request Length:%d",smp_pass_through_req->smp_req_len));
3143 	TI_DBG2(("SAS Response Length:%d",smp_pass_through_req->smp_resp_len));
3144 	for(i=0;i<smp_pass_through_req->smp_req_len;i++)
3145 		TI_DBG2(("SAS request + %d:%x",i,smp_pass_through_req->smp_req_resp[i]));
3146 
3147 	devHandle = ostiGetDevHandleFromSasAddr(tiRoot, smp_pass_through_req->exp_sas_addr);
3148 	if(devHandle == NULL)
3149 	{
3150 		status = IOCTL_CALL_FAIL;
3151 		agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
3152 		return status;
3153 	}
3154 
3155 
3156 
3157 	//agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
3158 	agIOCTLPayload->Status = IOCTL_ERR_STATUS_NOT_RESPONDING;
3159 
3160 
3161 
3162 	if((ostiMemoryStatus != tiSuccess) && (reqBuffer == agNULL  ))
3163 			return IOCTL_CALL_FAIL;
3164 
3165 
3166     tdsaAllShared->tdFWControlEx.param3 = osMemHandle;
3167 
3168 
3169 	agSMPFrame.outFrameBuf = smp_pass_through_req->smp_req_resp;
3170 	agSMPFrame.expectedRespLen = smp_pass_through_req->smp_resp_len;
3171 	agSMPFrame.inFrameLen = smp_pass_through_req->smp_resp_len - 4;
3172 
3173 	if(!(smp_pass_through_req->smp_req_len - 8) && !tiIS_SPC(agRoot))
3174 	{
3175 		agSMPFrame.flag = 1;  // Direct request Indirect response
3176 		agSMPFrame.outFrameLen = smp_pass_through_req->smp_req_len - 4; //Exclude header
3177 	}
3178 	else
3179 	{
3180 
3181 		agSMPFrame.flag = 3;  //Indirect request and Indirect response
3182 		ostiMemoryStatus = ostiAllocMemory( tiRoot,
3183 										  &osMemHandle,
3184 										  (void **)&reqBuffer,
3185 										  &(agSMPFrame.outFrameAddrUpper32),
3186 										  &(agSMPFrame.outFrameAddrLower32),
3187 										  8,
3188 										  smp_pass_through_req->smp_req_len,
3189 										  agFALSE);
3190 		tdsaAllShared->tdFWControlEx.param3 = osMemHandle;
3191 		if(tiIS_SPC(agRoot))
3192 		{
3193 		  agSMPFrame.outFrameLen = smp_pass_through_req->smp_req_len - 4; //Exclude crc
3194 		  osti_memcpy((void *)reqBuffer, (void *)(smp_pass_through_req->smp_req_resp), smp_pass_through_req->smp_req_len);
3195 		}
3196 		else
3197 		{
3198 		  agSMPFrame.outFrameLen = smp_pass_through_req->smp_req_len - 8; //Exclude header and crc
3199 		  osti_memcpy((void *)reqBuffer, (void *)(smp_pass_through_req->smp_req_resp + 4), smp_pass_through_req->smp_req_len - 4);
3200 		}
3201 	}
3202 
3203 	ostiMemoryStatus = ostiAllocMemory( tiRoot,
3204 										  &osMemHandle,
3205 										  (void **)&respBuffer,
3206 										  &(agSMPFrame.inFrameAddrUpper32),
3207 										  &(agSMPFrame.inFrameAddrLower32),
3208 										  8,
3209 										  smp_pass_through_req->smp_resp_len + 4,
3210 										  agFALSE);
3211 	if((ostiMemoryStatus != tiSuccess) && (respBuffer == agNULL  ))
3212 			return IOCTL_CALL_FAIL;
3213 
3214 
3215 	osti_memset((void *)respBuffer, 0, smp_pass_through_req->smp_resp_len);
3216 
3217 		// use FW control place in shared structure to keep the neccesary information
3218 	tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
3219 	tdsaAllShared->tdFWControlEx.virtAddr = respBuffer;
3220 	tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)smp_pass_through_req->smp_req_resp + smp_pass_through_req->smp_req_len;
3221 	tdsaAllShared->tdFWControlEx.len = smp_pass_through_req->smp_resp_len;
3222 	tdsaAllShared->tdFWControlEx.param1 = agParam1;
3223 	tdsaAllShared->tdFWControlEx.param2 = agParam2;
3224 	tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
3225 	tdsaAllShared->tdFWControlEx.inProgress = 1;
3226 	status = IOCTL_CALL_PENDING;
3227 
3228 	oneDeviceData = (tdsaDeviceData_t *)devHandle->tdData;
3229 	if(saSendSMPIoctl(agRoot, oneDeviceData->agDevHandle, 0, &agSMPFrame, &ossaSMPIoctlCompleted) != AGSA_RC_SUCCESS)
3230 	{
3231 	  status = IOCTL_CALL_FAIL;
3232 	  agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
3233 	}
3234 	return status;
3235 }
3236 
3237 osGLOBAL void ostiSendSMPIOCTLRsp(
3238                         tiRoot_t            *tiRoot,
3239                         bit32               status
3240                         )
3241 {
3242     tdsaRoot_t           *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
3243     tdsaContext_t        *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3244     tiIOCTLPayload_t     *agIOCTLPayload;
3245 
3246     agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
3247     agIOCTLPayload->Status = (bit16)status;
3248 
3249     TI_DBG1(("ostiSendSMPIOCTLRsp: start, status = %d\n", status));
3250 
3251 //	if(tdsaAllShared->tdFWControlEx.param1 != agNULL)
3252 //	{
3253       osti_memcpy((void *)(tdsaAllShared->tdFWControlEx.usrAddr),
3254                   (void *)(tdsaAllShared->tdFWControlEx.virtAddr),
3255                   tdsaAllShared->tdFWControlEx.len);
3256 //	}
3257 	ostiFreeMemory(tiRoot,
3258                    tdsaAllShared->tdFWControlEx.buffer,
3259                    tdsaAllShared->tdFWControlEx.len);
3260 	ostiFreeMemory(tiRoot,
3261                    tdsaAllShared->tdFWControlEx.param3,
3262                    tdsaAllShared->tdFWControlEx.len);
3263     //if(tdsaAllShared->tdFWControlEx.param1 != agNULL)
3264 //	{
3265       ostiIOCTLComplete(tiRoot,
3266                          tdsaAllShared->tdFWControlEx.param1,
3267                          tdsaAllShared->tdFWControlEx.param2,
3268                          NULL);
3269 //    }
3270 }
3271 
3272 
3273 
3274 
3275 /*****************************************************************************
3276 *
3277 * tdsaSendBISTIoctl
3278 *
3279 * Purpose:  This routine is called to get Forensic Data.
3280 *
3281 * Parameters:
3282 *   tiRoot:         Pointer to driver instance
3283 *   agIOCTLPayload: Pointer to the IOCTL payload.
3284 *   agParam1:       Pointer to pass context handle for IOCTL DMA operation
3285 *   agParam2:       Pointer to pass context handle for IOCTL DMA operation
3286 *   agParam3:       Pointer to pass context handle for IOCTL DMA operation
3287 *
3288 * Return:
3289 *
3290 *   IOCTL_CALL_SUCCESS        The requested operation completed successfully.
3291 *   IOCTL_CALL_FAIL           Fail to complete the IOCTL request.
3292 *                             Detail error code is function specific and
3293 *                             defined by the specific IOCTL function.
3294 *   IOCTL_CALL_PENDING        This request is asynchronous and completed
3295 *                             in some other context.
3296 *   IOCTL_CALL_INVALID_CODE   This IOCTL function is not recognized.
3297 *
3298 *
3299 *****************************************************************************/
3300 osGLOBAL bit32
3301 tdsaSendBISTIoctl(
3302                  tiRoot_t            *tiRoot,
3303                  tiIOCTLPayload_t    *agIOCTLPayload,
3304                  void                *agParam1,
3305                  void                *agParam2,
3306                  void                *agParam3
3307                  )
3308 {
3309   tdsaRoot_t      *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
3310   tdsaContext_t   *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3311   agsaRoot_t      *agRoot          = &(tdsaAllShared->agRootInt);
3312   tdBistPayload_t *pBistPayload;
3313 //  bit32            length = 0;
3314 //  bit32            status = IOCTL_CALL_SUCCESS;
3315   bit32            status = IOCTL_CALL_FAIL;
3316 
3317   pBistPayload = (tdBistPayload_t*)agIOCTLPayload->FunctionSpecificArea;
3318 
3319   tdsaAllShared->tdFWControlEx.buffer = agNULL;
3320   tdsaAllShared->tdFWControlEx.virtAddr = agNULL;
3321   tdsaAllShared->tdFWControlEx.usrAddr = (bit8*)&agIOCTLPayload->FunctionSpecificArea[0];
3322   tdsaAllShared->tdFWControlEx.len = 0;
3323   tdsaAllShared->tdFWControlEx.param1 = agParam1;
3324   tdsaAllShared->tdFWControlEx.param2 = agParam2;
3325   tdsaAllShared->tdFWControlEx.payload = agIOCTLPayload;
3326   tdsaAllShared->tdFWControlEx.inProgress = 0;
3327 
3328   TI_DBG1(("tdsaSendBISTIoctl: Type %d Length %d Data %p\n",
3329       pBistPayload->testType,
3330       pBistPayload->testLength,
3331       pBistPayload->testData ));
3332 
3333 
3334   // pBistPayload->testtype = AGSA_BIST_TEST;
3335 
3336   if( pBistPayload->testType == AGSA_BIST_TEST)
3337   {
3338     if( pBistPayload->testLength != sizeof(agsaEncryptSelfTestBitMap_t))
3339     {
3340       return status;
3341     }
3342   }
3343   else if( pBistPayload->testType == AGSA_SHA_TEST)
3344   {
3345     if( pBistPayload->testLength != sizeof(agsaEncryptSHATestDescriptor_t) )
3346     {
3347       return status;
3348     }
3349   }
3350   else if( pBistPayload->testType == AGSA_HMAC_TEST )
3351   {
3352     if( pBistPayload->testLength != sizeof(agsaEncryptHMACTestDescriptor_t))
3353     {
3354       return status;
3355     }
3356   }
3357 
3358 /*
3359 GLOBAL bit32 saEncryptSelftestExecute(
3360                         agsaRoot_t    *agRoot,
3361                         agsaContext_t *agContext,
3362                         bit32         queueNum,
3363                         bit32         type,
3364                         bit32         length,
3365                         void          *TestDescriptor);
3366 
3367 */
3368   if ( saEncryptSelftestExecute(agRoot,
3369         agNULL,
3370         0,
3371         pBistPayload->testType,
3372         pBistPayload->testLength,
3373         pBistPayload->testData  ) != AGSA_RC_SUCCESS )
3374   {
3375     status = IOCTL_CALL_FAIL;
3376   }
3377 
3378   return status;
3379 }
3380 
3381 
3382 osGLOBAL bit32
3383 tdsaSendTMFIoctl( tiRoot_t	     	*tiRoot,
3384 		  tiIOCTLPayload_t	*agIOCTLPayload,
3385 		  void                  *agParam1,
3386 		  void			*agParam2,
3387 		  unsigned long		resetType
3388 		)
3389 {
3390 	bit32		status;
3391 	tmf_pass_through_req_t  *tmf_req = (tmf_pass_through_req_t*)agIOCTLPayload->FunctionSpecificArea;
3392 #if !(defined(__FreeBSD__))
3393 	status = ostiSendResetDeviceIoctl(tiRoot, agParam2, tmf_req->pathId, tmf_req->targetId, tmf_req->lun, resetType);
3394 #endif
3395 	TI_DBG3(("Status returned from ostiSendResetDeviceIoctl is %d\n",status));
3396 	if(status !=  IOCTL_CALL_SUCCESS)
3397 	{
3398 		agIOCTLPayload->Status = status;
3399 		return status;
3400 	}
3401 	status = IOCTL_CALL_SUCCESS;
3402 	return status;
3403 }
3404 
3405 
3406 #ifdef VPD_TESTING
3407 /* temporary to test saSetVPDCommand() and saGetVPDCommand */
3408 osGLOBAL bit32
3409 tdsaVPDSet(
3410                 tiRoot_t            *tiRoot
3411                 )
3412 {
3413   tdsaRoot_t    *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
3414   tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3415   agsaRoot_t    *agRoot = &(tdsaAllShared->agRootInt);
3416   bit32         status = IOCTL_CALL_SUCCESS;
3417   agsaVPD_t     VPDInfo;
3418   bit32         ret = AGSA_RC_SUCCESS;
3419 
3420   bit32                 bufAddrUpper = 0;
3421   bit32                 bufAddrLower = 0;
3422   tdVPDControl_t        *VPDControl;
3423 
3424   void                  *osMemHandle = agNULL;
3425   void                  *buffer;
3426   bit32                 timeCount=0;
3427   bit8                  ioctlErr=0;
3428   bit8                  VPDPayload[32];
3429   bit8                  i;
3430   TI_DBG2(("tdsaVPDSet: start\n"));
3431 
3432   for(i=0;i<sizeof(VPDPayload);i++)
3433   {
3434     VPDPayload[i] = i;
3435   }
3436   if(ostiAllocMemory( tiRoot,
3437                         &osMemHandle,
3438                         (void **)&buffer,
3439                         &bufAddrUpper,
3440                         &bufAddrLower,
3441                         8,
3442                         sizeof(VPDPayload),
3443                         agFALSE))
3444   {
3445     return tiError;
3446   }
3447   osti_memcpy((void *)buffer,
3448                VPDPayload,
3449                sizeof(VPDPayload));
3450 
3451 
3452   osti_memset(&VPDInfo, 0, sizeof(agsaVPD_t));
3453 #ifdef NOT_YET /* direct mode worked */
3454   /* For now, only direct mode */
3455   VPDInfo.indirectMode = 0; /* direct mode */
3456   VPDInfo.VPDDevice = 1; /* SEEPROM-1 */
3457   VPDInfo.directLen  = (bit8)sizeof(VPDPayload);
3458   VPDInfo.VPDOffset = 0;
3459   VPDInfo.directData = buffer;
3460   VPDInfo.indirectAddrUpper32 = bufAddrUpper;
3461   VPDInfo.indirectAddrLower32 = bufAddrLower;
3462   VPDInfo.indirectLen = sizeof(VPDPayload);
3463 #endif
3464 
3465   /* indirect mode */
3466   VPDInfo.indirectMode = 1; /* indirect mode */
3467   VPDInfo.VPDDevice = 1; /* SEEPROM-1 */
3468   VPDInfo.directLen  = 0;
3469   VPDInfo.VPDOffset = 0;
3470   VPDInfo.directData = agNULL;
3471   VPDInfo.indirectAddrUpper32 = bufAddrUpper;
3472   VPDInfo.indirectAddrLower32 = bufAddrLower;
3473   VPDInfo.indirectLen = sizeof(VPDPayload);
3474 
3475   tdsaAllShared->tdFWControlEx.buffer = osMemHandle;
3476   tdsaAllShared->tdFWControlEx.param1 = agParam1;
3477   tdsaAllShared->tdFWControlEx.param2 = agParam2;
3478 
3479   /* for testing only */
3480   tdsaAllShared->addrUpper = bufAddrUpper;
3481   tdsaAllShared->addrLower = bufAddrLower;
3482 
3483   ret = saSetVPDCommand(agRoot, agNULL, 0, &VPDInfo);
3484 
3485   if (ret == AGSA_RC_SUCCESS)
3486   {
3487     status = tiSuccess;
3488   }
3489   else
3490   {
3491     status = tiError;
3492   }
3493 
3494     ostiFreeMemory(tiRoot, osMemHandle, sizeof(VPDPayload));
3495   return status;
3496 }
3497 
3498 /* temporary to test saSetVPDCommand() and saGetVPDCommand */
3499 osGLOBAL bit32
3500 tdsaVPDGet(tiRoot_t            *tiRoot)
3501 {
3502   tdsaRoot_t    *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
3503   tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3504   agsaRoot_t    *agRoot = &(tdsaAllShared->agRootInt);
3505   bit32         status = IOCTL_CALL_SUCCESS;
3506   agsaVPD_t     VPDInfo;
3507   bit32         ret = AGSA_RC_SUCCESS;
3508 
3509 
3510   TI_DBG2(("tdsaVPDGet: start\n"));
3511 
3512   osti_memset(&VPDInfo, 0, sizeof(agsaVPD_t));
3513 
3514   /* direct mode worked */
3515   VPDInfo.indirectMode = 0; /* direct mode */
3516   VPDInfo.VPDDevice = 1; /* SEEPROM-1*/
3517   VPDInfo.directLen  = 32;
3518   VPDInfo.VPDOffset = 0;
3519   VPDInfo.directData = agNULL;
3520   VPDInfo.indirectAddrUpper32 = 0;
3521   VPDInfo.indirectAddrLower32 = 0;
3522   VPDInfo.indirectLen = 0;
3523 
3524 
3525 #ifdef NOT_YET /* worked; can't read VPD in ossaGetVPDResponseCB() because of indirect */
3526   VPDInfo.indirectMode = 1; /* direct mode */
3527   VPDInfo.VPDDevice = 1; /* SEEPROM-1*/
3528   VPDInfo.directLen  = 0;
3529   VPDInfo.VPDOffset = 0;
3530   VPDInfo.directData = agNULL;
3531   VPDInfo.indirectAddrUpper32 = tdsaAllShared->addrUpper;
3532   VPDInfo.indirectAddrLower32 = tdsaAllShared->addrLower;
3533   VPDInfo.indirectLen = 32;
3534 #endif
3535   ret = saGetVPDCommand(agRoot, agNULL, 0, &VPDInfo);
3536 
3537   if (ret == AGSA_RC_SUCCESS)
3538   {
3539     status = tiSuccess;
3540   }
3541   else
3542   {
3543     status = tiError;
3544   }
3545   return status;
3546 }
3547 #endif
3548 /*****************************************************************************
3549 *
3550 * tdsaGetNumOfLUNIOCTL
3551 *
3552 * Purpose:  This routine is called to send Report LUN SSP command request.
3553 *
3554 * Parameters:
3555 *   tiRoot:         Pointer to driver instance
3556 *   tiIOCTLPayload_t:        Status of the Controller Reset.
3557 *   agParam1:        Void pointer to device extension
3558 *   agParam2:        Void pointer to SRB
3559 *   agParam3:        NULL
3560 *
3561 *   Return: status
3562 *
3563 *
3564 *****************************************************************************/
3565 osGLOBAL bit32
3566 tdsaGetNumOfLUNIOCTL(
3567                tiRoot_t            *tiRoot,
3568                tiIOCTLPayload_t    *agIOCTLPayload,
3569                void                *agParam1,
3570                void                *agParam2,
3571                void                *agParam3
3572                )
3573 {
3574   tdsaRoot_t	              *tdsaRoot			= (tdsaRoot_t *) tiRoot->tdData;
3575   tdsaContext_t               *tdsaAllShared 	= (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3576   agsaRoot_t	              *agRoot 			= &(tdsaAllShared->agRootInt);
3577   tdDeviceLUNInfoIOCTL_t	  *pDeviceLUNInfo	= agNULL;
3578   tiDeviceHandle_t            *devHandle 		= agNULL;
3579   void				          *tiRequestBody 	= agNULL;
3580   tiIORequest_t 	          *tiIORequest 		= agNULL;
3581   bit32			              status 			= IOCTL_CALL_SUCCESS;
3582 
3583   TI_DBG2(("tdsaGetNumOfLUNIOCTL: Start\n"));
3584   do
3585   {
3586     pDeviceLUNInfo = (tdDeviceLUNInfoIOCTL_t*)agIOCTLPayload->FunctionSpecificArea;
3587 
3588     if (agIOCTLPayload->Length < sizeof(tdDeviceLUNInfoIOCTL_t))
3589     {
3590   	  status = IOCTL_CALL_FAIL;
3591   	  break;
3592     }
3593     if(!pDeviceLUNInfo->tiDeviceHandle)
3594     {
3595       status = IOCTL_CALL_FAIL;
3596       agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
3597       break;
3598     }
3599 	devHandle = (tiDeviceHandle_t*)pDeviceLUNInfo->tiDeviceHandle;
3600 	agIOCTLPayload->Status = IOCTL_ERR_STATUS_OK;
3601 
3602 	status = ostiNumOfLUNIOCTLreq(tiRoot,agParam1,agParam2,&tiRequestBody,&tiIORequest);
3603 
3604 
3605     if(status != AGSA_RC_SUCCESS)
3606     {
3607       agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
3608 	  break;
3609     }
3610     status = tiNumOfLunIOCTLreq(tiRoot,tiIORequest,devHandle,tiRequestBody,agIOCTLPayload,agParam1,agParam2);
3611 
3612     if(status != AGSA_RC_SUCCESS)
3613     {
3614          agIOCTLPayload->Status = IOCTL_ERR_STATUS_INTERNAL_ERROR;
3615 	  break;
3616     }
3617 //	ostiIOCTLWaitForSignal (tiRoot, agParam1, agParam2, agParam3);
3618 
3619   }while(0);
3620   TI_DBG2(("tdsaGetNumOfLUNIOCTL: End\n"));
3621   return status;
3622 }
3623 
3624 
3625 /*****************************************************************************
3626 *
3627 * ostiNumOfLUNIOCTLRsp
3628 *
3629 * Purpose:  This routine is called when a Report LUN SSP command response id recieved.
3630 *
3631 * Parameters:
3632 *   tiRoot:         Pointer to driver instance
3633 *   bit32               status
3634 *
3635 * Return: none
3636 *
3637 *
3638 *****************************************************************************/
3639 osGLOBAL void ostiNumOfLUNIOCTLRsp(
3640                         tiRoot_t            *tiRoot,
3641                         bit32               status
3642                         )
3643 {
3644   tdsaRoot_t                  *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
3645   tdsaContext_t               *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
3646   tiIOCTLPayload_t            *agIOCTLPayload;
3647   tdDeviceLUNInfoIOCTL_t	  *pDeviceLUNInfo = NULL;
3648   bit32                       count = 0;
3649   bit32                       numOfLUN =0;
3650 
3651   TI_DBG1(("ostiNumOfLUNIOCTLRsp: start, status = %d\n", status));
3652 
3653   if(tdsaAllShared->tdFWControlEx.inProgress == 1)
3654   {
3655     agIOCTLPayload = (tiIOCTLPayload_t *)(tdsaAllShared->tdFWControlEx.payload);
3656 	if ((agIOCTLPayload) && (PMC_IOCTL_SIGNATURE == agIOCTLPayload->Signature)&&
3657 					   (IOCTL_MJ_GET_DEVICE_LUN == agIOCTLPayload->MajorFunction))
3658 	{
3659       agIOCTLPayload->Status = (bit16)status;
3660       pDeviceLUNInfo = (tdDeviceLUNInfoIOCTL_t*)agIOCTLPayload->FunctionSpecificArea;
3661       numOfLUN = ((tdsaAllShared->tdFWControlEx.virtAddr[0] << 24)|(tdsaAllShared->tdFWControlEx.virtAddr[1] << 16)|\
3662                  (tdsaAllShared->tdFWControlEx.virtAddr[2] << 8)|(tdsaAllShared->tdFWControlEx.virtAddr[3]));
3663       numOfLUN = numOfLUN/8;
3664       pDeviceLUNInfo->numOfLun = numOfLUN;
3665 //	  ostiFreeMemory(tiRoot,
3666 //                     tdsaAllShared->tdFWControlEx.virtAddr,
3667 //                     tdsaAllShared->tdFWControlEx.len);
3668   //    if(tdsaAllShared->tdFWControlEx.param1 != agNULL)
3669   //    {
3670         ostiIOCTLSetSignal(tiRoot,
3671                            tdsaAllShared->tdFWControlEx.param1,
3672                            tdsaAllShared->tdFWControlEx.param2,
3673                            NULL);
3674   	    tdsaAllShared->tdFWControlEx.payload = NULL;
3675   //    }
3676 
3677 	  tdsaAllShared->tdFWControlEx.inProgress = 0;
3678 	}
3679   }
3680   TI_DBG1(("ostiNumOfLUNIOCTLRsp: End\n"));
3681 }
3682 
3683