xref: /freebsd/sys/dev/pms/RefTisa/sallsdk/spc/sampirsp.c (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
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 sampirsp.c
24  *  \brief The file implements the functions of MPI Outbound Response Message
25  *
26  */
27 /******************************************************************************/
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30 #include <dev/pms/config.h>
31 
32 #include <dev/pms/RefTisa/sallsdk/spc/saglobal.h>
33 #ifdef SA_ENABLE_TRACE_FUNCTIONS
34 #ifdef siTraceFileID
35 #undef siTraceFileID
36 #endif
37 #define siTraceFileID 'J'
38 #endif
39 
40 /******************************************************************************/
41 /* Protoytpes */
42 void saReturnRequestToFreePool(
43                             agsaRoot_t          *agRoot,
44                             agsaIORequestDesc_t *pRequest
45                             );
46 
47 /******************************************************************************/
48 /*! \brief Process Outbound IOMB Message
49  *
50  *  Process Outbound IOMB from SPC
51  *
52  *  \param agRoot       Handles for this instance of SAS/SATA LL Layer
53  *  \param pMsg1        Pointer of Response IOMB message 1
54  *  \param category     category of outbpond IOMB header
55  *  \param opcode       Opcode of Outbound IOMB header
56  *  \param bc           buffer count of IOMB header
57  *
58  *  \return success or fail
59  *
60  */
61 /*******************************************************************************/
62 #if 0
63 FORCEINLINE bit32
64 mpiParseOBIomb(
65   agsaRoot_t        *agRoot,
66   bit32             *pMsg1,
67   mpiMsgCategory_t  category,
68   bit16             opcode
69   )
70 {
71   agsaLLRoot_t      *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
72   bit32              ret = AGSA_RC_SUCCESS;
73   bit32              parserStatus = AGSA_RC_SUCCESS;
74 
75   smTraceFuncEnter(hpDBG_VERY_LOUD, "2f");
76 
77   switch (opcode)
78   {
79     case OPC_OUB_COMBINED_SSP_COMP:
80     {
81       agsaSSPCoalescedCompletionRsp_t  *pIomb = (agsaSSPCoalescedCompletionRsp_t *)pMsg1;
82       agsaIORequestDesc_t              *pRequest = agNULL;
83       bit32  tag     = 0;
84       bit32  sspTag  = 0;
85       bit32  count   = 0;
86 
87 #ifdef SALL_API_TEST
88       saRoot->LLCounters.IOCounter.numSSPCompleted++;
89       SA_DBG3(("mpiParseOBIomb, SSP_COMP Response received IOMB=%p %d\n",
90          pMsg1, saRoot->LLCounters.IOCounter.numSSPCompleted));
91 #else
92       SA_DBG3(("mpiParseOBIomb, OPC_OUB_COMBINED_SSP_COMP Response received IOMB=%p\n", pMsg1));
93 #endif
94       /* get Tag */
95       for (count = 0; count < pIomb->coalescedCount; count++)
96       {
97         tag = pIomb->sspComplCxt[count].tag;
98         sspTag = pIomb->sspComplCxt[count].SSPTag;
99         pRequest = (agsaIORequestDesc_t *)saRoot->IOMap[tag].IORequest;
100         SA_ASSERT((pRequest), "pRequest");
101 
102         if(pRequest == agNULL)
103         {
104           SA_DBG1(("mpiParseOBIomb,OPC_OUB_COMBINED_SSP_COMP Resp IOMB tag=0x%x, status=0x%x, param=0x%x, SSPTag=0x%x\n", tag, OSSA_IO_SUCCESS, 0, sspTag));
105           return(AGSA_RC_FAILURE);
106         }
107         SA_ASSERT((pRequest->valid), "pRequest->valid");
108 
109         SA_DBG3(("mpiParseOBIomb, OPC_OUB_COMBINED_SSP_COMP IOMB tag=0x%x, status=0x%x, param=0x%x, SSPTag=0x%x\n", tag, OSSA_IO_SUCCESS, 0, sspTag));
110 
111         /* Completion of SSP without Response Data */
112         siIODone( agRoot, pRequest, OSSA_IO_SUCCESS, sspTag);
113       }
114     }
115     break;
116 
117     case OPC_OUB_SSP_COMP:
118     {
119 #ifdef SALL_API_TEST
120       saRoot->LLCounters.IOCounter.numSSPCompleted++;
121       SA_DBG3(("mpiParseOBIomb, SSP_COMP Response received IOMB=%p %d\n",
122          pMsg1, saRoot->LLCounters.IOCounter.numSSPCompleted));
123 #else
124       SA_DBG3(("mpiParseOBIomb, SSP_COMP Response received IOMB=%p\n", pMsg1));
125 #endif
126       /* process the SSP IO Completed response message */
127       mpiSSPCompletion(agRoot, pMsg1);
128       break;
129     }
130     case OPC_OUB_COMBINED_SATA_COMP:
131     {
132       agsaSATACoalescedCompletionRsp_t    *pIomb;
133       agsaIORequestDesc_t       *pRequest;
134       bit32                     tag;
135       bit32                     count;
136 
137     #ifdef SALL_API_TEST
138       saRoot->LLCounters.IOCounter.numSSPCompleted++;
139       SA_DBG3(("mpiParseOBIomb, OPC_OUB_COMBINED_SATA_COMP Response received IOMB=%p %d\n",
140          pMsg1, saRoot->LLCounters.IOCounter.numSSPCompleted));
141     #else
142       SA_DBG3(("mpiParseOBIomb, OPC_OUB_COMBINED_SATA_COMP Response received IOMB=%p\n", pMsg1));
143     #endif
144 
145       pIomb = (agsaSATACoalescedCompletionRsp_t *)pMsg1;
146       /* get Tag */
147       for (count = 0; count < pIomb->coalescedCount; count++)
148       {
149         tag = pIomb->stpComplCxt[count].tag;
150         pRequest = (agsaIORequestDesc_t *)saRoot->IOMap[tag].IORequest;
151         SA_ASSERT((pRequest), "pRequest");
152 
153         if(pRequest == agNULL)
154         {
155           SA_DBG1(("mpiParseOBIomb,OPC_OUB_COMBINED_SATA_COMP Resp IOMB tag=0x%x, status=0x%x, param=0x%x\n", tag, OSSA_IO_SUCCESS, 0));
156           return(AGSA_RC_FAILURE);
157         }
158         SA_ASSERT((pRequest->valid), "pRequest->valid");
159 
160         SA_DBG3(("mpiParseOBIomb, OPC_OUB_COMBINED_SATA_COMP IOMB tag=0x%x, status=0x%x, param=0x%x\n", tag, OSSA_IO_SUCCESS, 0));
161 
162         /* Completion of SATA without Response Data */
163         siIODone( agRoot, pRequest, OSSA_IO_SUCCESS, 0);
164       }
165       break;
166     }
167     case OPC_OUB_SATA_COMP:
168     {
169 #ifdef SALL_API_TEST
170       saRoot->LLCounters.IOCounter.numSataCompleted++;
171       SA_DBG3(("mpiParseOBIomb, SATA_COMP Response received IOMB=%p %d\n",
172              pMsg1, saRoot->LLCounters.IOCounter.numSataCompleted));
173 #else
174       SA_DBG3(("mpiParseOBIomb, SATA_COMP Response received IOMB=%p\n", pMsg1));
175 #endif
176       /* process the response message */
177       mpiSATACompletion(agRoot, pMsg1);
178       break;
179     }
180     case OPC_OUB_SSP_ABORT_RSP:
181     {
182 #ifdef SALL_API_TEST
183       saRoot->LLCounters.IOCounter.numSSPAbortedCB++;
184 #else
185       SA_DBG3(("mpiParseOBIomb, SSP_ABORT Response received IOMB=%p\n", pMsg1));
186 #endif
187       /* process the response message */
188       parserStatus = mpiSSPAbortRsp(agRoot, (agsaSSPAbortRsp_t *)pMsg1);
189       if(parserStatus !=  AGSA_RC_SUCCESS)
190       {
191          SA_DBG3(("mpiParseOBIomb, mpiSSPAbortRsp FAIL IOMB=%p\n", pMsg1));
192       }
193 
194       break;
195     }
196     case OPC_OUB_SATA_ABORT_RSP:
197     {
198 #ifdef SALL_API_TEST
199       saRoot->LLCounters.IOCounter.numSataAbortedCB++;
200 #else
201       SA_DBG3(("mpiParseOBIomb, SATA_ABORT Response received IOMB=%p\n", pMsg1));
202 #endif
203       /* process the response message */
204       mpiSATAAbortRsp(agRoot, (agsaSATAAbortRsp_t *)pMsg1);
205       break;
206     }
207     case OPC_OUB_SATA_EVENT:
208     {
209       SA_DBG3(("mpiParseOBIomb, SATA_EVENT Response received IOMB=%p\n", pMsg1));
210       /* process the response message */
211       mpiSATAEvent(agRoot, (agsaSATAEventRsp_t *)pMsg1);
212       break;
213     }
214     case OPC_OUB_SSP_EVENT:
215     {
216       SA_DBG3(("mpiParseOBIomb, SSP_EVENT Response received IOMB=%p\n", pMsg1));
217       /* process the response message */
218       mpiSSPEvent(agRoot, (agsaSSPEventRsp_t *)pMsg1);
219       break;
220     }
221     case OPC_OUB_SMP_COMP:
222     {
223 #ifdef SALL_API_TEST
224       saRoot->LLCounters.IOCounter.numSMPCompleted++;
225       SA_DBG3(("mpiParseOBIomb, SMP_COMP Response received IOMB=%p, %d\n",
226              pMsg1, saRoot->LLCounters.IOCounter.numSMPCompleted));
227 #else
228       SA_DBG3(("mpiParseOBIomb, SMP_COMP Response received IOMB=%p\n", pMsg1));
229 #endif
230       /* process the response message */
231       mpiSMPCompletion(agRoot, (agsaSMPCompletionRsp_t *)pMsg1);
232       break;
233     }
234 #ifndef BIOS
235     case OPC_OUB_ECHO:
236     {
237 #ifdef SALL_API_TEST
238       saRoot->LLCounters.IOCounter.numEchoCB++;
239       SA_DBG3(("mpiParseOBIomb, ECHO Response received %d\n", saRoot->LLCounters.IOCounter.numEchoCB));
240 #else
241       SA_DBG3(("mpiParseOBIomb, ECHO Response received\n"));
242 #endif
243       /* process the response message */
244       mpiEchoRsp(agRoot, (agsaEchoRsp_t *)pMsg1);
245       break;
246     }
247 #endif
248     case OPC_OUB_GET_NVMD_DATA:
249     {
250       SA_DBG3(("mpiParseOBIomb, OPC_OUB_GET_NVMD_DATA received IOMB=%p\n", pMsg1));
251       /* process the response message */
252       mpiGetNVMDataRsp(agRoot, (agsaGetNVMDataRsp_t *)pMsg1);
253       break;
254     }
255     case OPC_OUB_SPC_HW_EVENT:
256     {
257       SA_ASSERT((smIS_SPC(agRoot)), "smIS_SPC");
258       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SPC_HW_EVENT Response received IOMB=%p\n", pMsg1));
259       /* process the response message */
260       mpiHWevent(agRoot, (agsaHWEvent_SPC_OUB_t *)pMsg1);
261       break;
262     }
263     case OPC_OUB_HW_EVENT:
264     {
265       SA_DBG3(("mpiParseOBIomb, HW_EVENT Response received IOMB=%p\n", pMsg1));
266       /* process the response message */
267       mpiHWevent(agRoot, (agsaHWEvent_SPC_OUB_t *)pMsg1);
268       break;
269     }
270     case OPC_OUB_PHY_START_RESPONSE:
271     {
272       SA_DBG1(("mpiParseOBIomb, OPC_OUB_PHY_START_RESPONSE Response received IOMB=%p\n", pMsg1));
273       /* process the response message */
274       mpiPhyStartEvent( agRoot, (agsaHWEvent_Phy_OUB_t  *)pMsg1  );
275 
276       break;
277     }
278     case OPC_OUB_PHY_STOP_RESPONSE:
279     {
280       SA_DBG1(("mpiParseOBIomb, OPC_OUB_PHY_STOP_RESPONSE Response received IOMB=%p\n", pMsg1));
281       /* process the response message */
282       mpiPhyStopEvent( agRoot, (agsaHWEvent_Phy_OUB_t  *)pMsg1  );
283       break;
284     }
285 
286     case OPC_OUB_LOCAL_PHY_CNTRL:
287     {
288       SA_DBG3(("mpiParseOBIomb, PHY CONTROL Response received IOMB=%p\n", pMsg1));
289       /* process the response message */
290       mpiPhyCntrlRsp(agRoot, (agsaLocalPhyCntrlRsp_t *)pMsg1);
291       break;
292     }
293     case OPC_OUB_SPC_DEV_REGIST:
294     {
295       SA_ASSERT((smIS_SPC(agRoot)), "smIS_SPC");
296       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SPC_DEV_REGIST Response received IOMB=%p\n", pMsg1));
297       /* process the response message */
298       mpiDeviceRegRsp(agRoot, (agsaDeviceRegistrationRsp_t *)pMsg1);
299       break;
300     }
301     case OPC_OUB_DEV_REGIST:
302     {
303       SA_DBG2(("mpiParseOBIomb, DEV_REGISTRATION Response received IOMB=%p\n", pMsg1));
304       /* process the response message */
305       mpiDeviceRegRsp(agRoot, (agsaDeviceRegistrationRsp_t *)pMsg1);
306       break;
307     }
308     case OPC_OUB_DEREG_DEV:
309     {
310       SA_DBG3(("mpiParseOBIomb, DEREGISTRATION DEVICE Response received IOMB=%p\n", pMsg1));
311       /* process the response message */
312       mpiDeregDevHandleRsp(agRoot, (agsaDeregDevHandleRsp_t *)pMsg1);
313       break;
314     }
315 #ifndef BIOS
316     case OPC_OUB_GET_DEV_HANDLE:
317     {
318       SA_DBG3(("mpiParseOBIomb, GET_DEV_HANDLE Response received IOMB=%p\n", pMsg1));
319       /* process the response message */
320       mpiGetDevHandleRsp(agRoot, (agsaGetDevHandleRsp_t *)pMsg1);
321       break;
322     }
323 #endif
324     case OPC_OUB_SPC_DEV_HANDLE_ARRIV:
325     {
326       SA_DBG3(("mpiParseOBIomb, SPC_DEV_HANDLE_ARRIV Response received IOMB=%p\n", pMsg1));
327       /* process the response message */
328       mpiDeviceHandleArrived(agRoot, (agsaDeviceHandleArrivedNotify_t *)pMsg1);
329       break;
330     }
331     case OPC_OUB_DEV_HANDLE_ARRIV:
332     {
333       SA_DBG3(("mpiParseOBIomb, DEV_HANDLE_ARRIV Response received IOMB=%p\n", pMsg1));
334       /* process the response message */
335       mpiDeviceHandleArrived(agRoot, (agsaDeviceHandleArrivedNotify_t *)pMsg1);
336       break;
337     }
338 #if 0 //Sunitha
339 	case OPC_OUB_THERM_HW_EVENT:
340 	{
341       SA_DBG3(("mpiParseOBIomb, THERM_HW_EVENT Response received IOMB=%p\n", pMsg1));
342       ossaLogThermalEvent(agRoot, (agsaThermal_Hw_Event_Notify_t *)pMsg1);
343       break;
344 	}
345 #endif //Sunitha
346     case OPC_OUB_SSP_RECV_EVENT:
347     {
348       SA_DBG3(("mpiParseOBIomb, SSP_RECV_EVENT Response received IOMB=%p\n", pMsg1));
349       /* process the response message */
350       mpiSSPReqReceivedNotify(agRoot, (agsaSSPReqReceivedNotify_t *)pMsg1);
351       break;
352     }
353     case OPC_OUB_DEV_INFO:
354     {
355       SA_ASSERT((smIS_SPCV(agRoot)), "smIS_SPCV");
356       SA_DBG3(("mpiParseOBIomb, DEV_INFO Response received IOMB=%p\n", pMsg1));
357       /* process the response message */
358       mpiGetDevInfoRsp(agRoot, (agsaGetDevInfoRspV_t *)pMsg1);
359       break;
360     }
361 #ifndef BIOS
362     case OPC_OUB_GET_PHY_PROFILE_RSP:
363     {
364       SA_ASSERT((smIS_SPCV(agRoot)), "smIS_SPCV");
365       SA_DBG2(("mpiParseOBIomb, OPC_OUB_GET_PHY_PROFILE_RSP Response received IOMB=%p\n", pMsg1));
366       /* process the response message */
367       mpiGetPhyProfileRsp(agRoot, (agsaGetPhyProfileRspV_t *)pMsg1);
368       break;
369     }
370     case OPC_OUB_SET_PHY_PROFILE_RSP:
371     {
372       SA_ASSERT((smIS_SPCV(agRoot)), "smIS_SPCV");
373       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SET_PHY_PROFILE_RSP Response received IOMB=%p\n", pMsg1));
374       /* process the response message */
375       mpiSetPhyProfileRsp(agRoot, (agsaSetPhyProfileRspV_t *)pMsg1);
376       break;
377     }
378 #endif /* BIOS */
379     case OPC_OUB_SPC_DEV_INFO:
380     {
381       SA_ASSERT((smIS_SPC(agRoot)), "smIS_SPC");
382       SA_DBG3(("mpiParseOBIomb, DEV_INFO Response received IOMB=%p\n", pMsg1));
383       /* process the response message */
384       mpiGetDevInfoRspSpc(agRoot, (agsaGetDevInfoRsp_t *)pMsg1);
385       break;
386     }
387     case OPC_OUB_FW_FLASH_UPDATE:
388     {
389       SA_DBG3(("mpiParseOBIomb, OPC_OUB_FW_FLASH_UPDATE Response received IOMB=%p\n", pMsg1));
390       /* process the response message */
391       mpiFwFlashUpdateRsp(agRoot, (agsaFwFlashUpdateRsp_t *)pMsg1);
392       break;
393     }
394     case OPC_OUB_FLASH_OP_EXT_RSP:
395     {
396       SA_DBG3(("mpiParseOBIomb, OPC_OUB_FW_FLASH_UPDATE Response received IOMB=%p\n", pMsg1));
397       /* process the response message */
398       mpiFwExtFlashUpdateRsp(agRoot, (agsaFwFlashOpExtRsp_t *)pMsg1);
399       break;
400     }
401 #ifndef BIOS
402 #ifdef SPC_ENABLE_PROFILE
403     case OPC_OUB_FW_PROFILE:
404     {
405       SA_DBG3(("mpiParseOBIomb, OPC_OUB_FW_PROFILE Response received IOMB=%p\n", pMsg1));
406       /* process the response message */
407       mpiFwProfileRsp(agRoot, (agsaFwProfileRsp_t *)pMsg1);
408       break;
409     }
410 #endif
411     case OPC_OUB_SET_NVMD_DATA:
412     {
413       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SET_NVMD_DATA received IOMB=%p\n", pMsg1));
414       /* process the response message */
415       mpiSetNVMDataRsp(agRoot, (agsaSetNVMDataRsp_t *)pMsg1);
416       break;
417     }
418 
419     case OPC_OUB_GPIO_RESPONSE:
420     {
421       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SET_GPIO_RESPONSE Response received IOMB=%p\n", pMsg1));
422       /* process the response message */
423       mpiGPIORsp(agRoot, (agsaGPIORsp_t *)pMsg1);
424       break;
425     }
426     case OPC_OUB_GPIO_EVENT:
427     {
428       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SET_GPIO_RESPONSE Response received IOMB=%p\n", pMsg1));
429       /* process the response message */
430       mpiGPIOEventRsp(agRoot, (agsaGPIOEvent_t *)pMsg1);
431       break;
432     }
433 #endif  /* BIOS */
434     case OPC_OUB_GENERAL_EVENT:
435     {
436       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SET_GENERAL_EVENT Response received IOMB=%p\n", pMsg1));
437       /* process the response message */
438       mpiGeneralEventRsp(agRoot, (agsaGeneralEventRsp_t *)pMsg1);
439       break;
440     }
441 #ifndef BIOS
442     case OPC_OUB_SAS_DIAG_MODE_START_END:
443     {
444       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SAS_DIAG_MODE_START_END Response received IOMB=%p\n", pMsg1));
445       /* process the response message */
446       mpiSASDiagStartEndRsp(agRoot, (agsaSASDiagStartEndRsp_t *)pMsg1);
447       break;
448     }
449     case OPC_OUB_SAS_DIAG_EXECUTE:
450     {
451       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SAS_DIAG_EXECUTE_RSP Response received IOMB=%p\n", pMsg1));
452       /* process the response message */
453       mpiSASDiagExecuteRsp(agRoot, (agsaSASDiagExecuteRsp_t *)pMsg1);
454       break;
455     }
456 #endif /* BIOS */
457     case OPC_OUB_GET_TIME_STAMP:
458     {
459       SA_DBG3(("mpiParseOBIomb, OPC_OUB_GET_TIME_STAMP Response received IOMB=%p\n", pMsg1));
460       /* process the response message */
461       mpiGetTimeStampRsp(agRoot, (agsaGetTimeStampRsp_t *)pMsg1);
462       break;
463     }
464 
465     case OPC_OUB_SPC_SAS_HW_EVENT_ACK:
466     {
467       SA_ASSERT((smIS_SPC(agRoot)), "smIS_SPC");
468       SA_DBG3(("mpiParseOBIomb,OPC_OUB_SPC_SAS_HW_EVENT_ACK  Response received IOMB=%p\n", pMsg1));
469       /* process the response message */
470       mpiSASHwEventAckRsp(agRoot, (agsaSASHwEventAckRsp_t *)pMsg1);
471       break;
472     }
473 
474     case OPC_OUB_SAS_HW_EVENT_ACK:
475     {
476       SA_ASSERT((smIS_SPCV(agRoot)), "smIS_SPCV");
477       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SAS_HW_EVENT_ACK Response received IOMB=%p\n", pMsg1));
478       /* process the response message */
479       mpiSASHwEventAckRsp(agRoot, (agsaSASHwEventAckRsp_t *)pMsg1);
480       break;
481     }
482     case OPC_OUB_PORT_CONTROL:
483     {
484       SA_DBG3(("mpiParseOBIomb, OPC_OUB_PORT_CONTROL Response received IOMB=%p\n", pMsg1));
485       /* process the response message */
486       mpiPortControlRsp(agRoot, (agsaPortControlRsp_t *)pMsg1);
487       break;
488     }
489     case OPC_OUB_SMP_ABORT_RSP:
490     {
491 #ifdef SALL_API_TEST
492       saRoot->LLCounters.IOCounter.numSMPAbortedCB++;
493       SA_DBG3(("mpiParseOBIomb, SMP_ABORT Response received IOMB=%p, %d\n",
494              pMsg1, saRoot->LLCounters.IOCounter.numSMPAbortedCB));
495 #else
496       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SMP_ABORT_RSP Response received IOMB=%p\n", pMsg1));
497 #endif
498       /* process the response message */
499       mpiSMPAbortRsp(agRoot, (agsaSMPAbortRsp_t *)pMsg1);
500       break;
501     }
502     case OPC_OUB_DEVICE_HANDLE_REMOVAL:
503     {
504       SA_DBG3(("mpiParseOBIomb, OPC_OUB_DEVICE_HANDLE_REMOVAL received IOMB=%p\n", pMsg1));
505       /* process the response message */
506       mpiDeviceHandleRemoval(agRoot, (agsaDeviceHandleRemoval_t *)pMsg1);
507       break;
508     }
509     case OPC_OUB_SET_DEVICE_STATE:
510     {
511       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SET_DEVICE_STATE received IOMB=%p\n", pMsg1));
512       /* process the response message */
513       mpiSetDeviceStateRsp(agRoot, (agsaSetDeviceStateRsp_t *)pMsg1);
514       break;
515     }
516 
517 #ifndef BIOS
518     case OPC_OUB_GET_DEVICE_STATE:
519     {
520       SA_DBG3(("mpiParseOBIomb, OPC_OUB_GET_DEVICE_STATE received IOMB=%p\n", pMsg1));
521       /* process the response message */
522       mpiGetDeviceStateRsp(agRoot, (agsaGetDeviceStateRsp_t *)pMsg1);
523       break;
524     }
525 #endif  /* BIOS */
526 
527     case OPC_OUB_SET_DEV_INFO:
528     {
529       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SET_DEV_INFO received IOMB=%p\n", pMsg1));
530       /* process the response message */
531       mpiSetDevInfoRsp(agRoot, (agsaSetDeviceInfoRsp_t *)pMsg1);
532       break;
533     }
534 
535 #ifndef BIOS_DEBUG
536     case OPC_OUB_SAS_RE_INITIALIZE:
537     {
538       SA_ASSERT((smIS_SPC(agRoot)), "smIS_SPC");
539       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SAS_RE_INITIALIZE received IOMB=%p\n", pMsg1));
540       /* process the response message */
541       mpiSasReInitializeRsp(agRoot, (agsaSasReInitializeRsp_t *)pMsg1);
542       break;
543     }
544 #endif  /* BIOS */
545 
546     case OPC_OUB_SGPIO_RESPONSE:
547     {
548       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SGPIO_RESPONSE Response received IOMB=%p\n", pMsg1));
549       /* process the response message */
550       mpiSGpioRsp(agRoot, (agsaSGpioRsp_t *)pMsg1);
551       break;
552     }
553 
554 #ifndef BIOS
555     case OPC_OUB_PCIE_DIAG_EXECUTE:
556     {
557       SA_DBG3(("mpiParseOBIomb, OPC_OUB_PCIE_DIAG_EXECUTE Response received IOMB=%p\n", pMsg1));
558       /* process the response message */
559       mpiPCIeDiagExecuteRsp(agRoot, (agsaPCIeDiagExecuteRsp_t *)pMsg1);
560       break;
561     }
562     case 2104: //delray start
563     {
564       if(smIS_SPC6V(agRoot))
565       {
566       SA_DBG3(("mpiParseOBIomb, OPC_OUB_GET_DFE_DATA_RSP Response received IOMB=%p\n", pMsg1));
567       /* process the response message */
568       mpiGetDFEDataRsp(agRoot, (agsaGetDDEFDataRsp_t *)pMsg1);
569       }
570       if(smIS_SPC12V(agRoot))
571       {
572         SA_DBG3(("mpiParseOBIomb, OPC_INB_GET_VIST_CAP Response received IOMB=%p\n", pMsg1));
573         mpiGetVisRsp(agRoot, (agsaGetVisCapRsp_t *)pMsg1);
574       }
575       else
576       {
577         SA_DBG1(("mpiParseOBIomb, 2104  Response received IOMB=%p\n", pMsg1));
578       }
579       break;
580     }
581 #endif   /* BIOS */
582     case OPC_OUB_SET_CONTROLLER_CONFIG:
583     {
584       SA_DBG3(("mpiParseOBIomb, OPC_OUB_SET_CONTROLLER_CONFIG Response received IOMB=%p\n", pMsg1));
585       mpiSetControllerConfigRsp(agRoot, (agsaSetControllerConfigRsp_t *)pMsg1);
586       break;
587     }
588 #ifndef BIOS
589     case OPC_OUB_GET_CONTROLLER_CONFIG:
590     {
591       SA_DBG3(("mpiParseOBIomb, OPC_OUB_GET_CONTROLLER_CONFIG Response received IOMB=%p\n", pMsg1));
592       mpiGetControllerConfigRsp(agRoot, (agsaGetControllerConfigRsp_t *)pMsg1);
593       break;
594     }
595     case OPC_OUB_KEK_MANAGEMENT:
596     {
597       SA_DBG3(("mpiParseOBIomb, OPC_OUB_KEK_MANAGEMENT Response received IOMB=%p\n", pMsg1));
598       mpiKekManagementRsp(agRoot, (agsaKekManagementRsp_t *)pMsg1);
599       break;
600     }
601 #endif  /* BIOS */
602 #ifdef UN_USED_FUNC
603     case OPC_OUB_DEK_MANAGEMENT:
604     {
605       SA_DBG3(("mpiParseOBIomb, OPC_OUB_DEK_MANAGEMENT Response received IOMB=%p\n", pMsg1));
606       mpiDekManagementRsp(agRoot, (agsaDekManagementRsp_t *)pMsg1);
607       break;
608     }
609 #endif
610 #ifndef BIOS
611     case OPC_OUB_OPR_MGMT:
612     {
613       SA_DBG1(("mpiParseOBIomb, OPC_OUB_OPR_MGMT Response received IOMB=%p\n", pMsg1));
614       mpiOperatorManagementRsp(agRoot, (agsaOperatorMangmenRsp_t *)pMsg1);
615       break;
616     }
617     case OPC_OUB_ENC_TEST_EXECUTE:
618     {
619       SA_DBG1(("mpiParseOBIomb, OPC_OUB_ENC_TEST_EXECUTE Response received IOMB=%p\n", pMsg1));
620       mpiBistRsp(agRoot, (agsaEncryptBistRsp_t *)pMsg1);
621       break;
622     }
623 #endif /* BIOS */
624     case OPC_OUB_SET_OPERATOR:
625     {
626       SA_DBG1(("mpiParseOBIomb, OPC_OUB_SET_OPERATOR Response received IOMB=%p\n", pMsg1));
627       mpiSetOperatorRsp(agRoot, (agsaSetOperatorRsp_t *)pMsg1);
628       break;
629     }
630     case OPC_OUB_GET_OPERATOR:
631     {
632       SA_DBG1(("mpiParseOBIomb, OPC_OUB_GET_OPERATOR Response received IOMB=%p\n", pMsg1));
633       mpiGetOperatorRsp(agRoot, (agsaGetOperatorRsp_t *)pMsg1);
634       break;
635     }
636     case OPC_OUB_DIF_ENC_OFFLOAD_RSP://delray start
637     {
638       SA_ASSERT((smIS_SPCV(agRoot)), "smIS_SPCV");
639       SA_DBG1(("mpiParseOBIomb, OPC_OUB_DIF_ENC_OFFLOAD_RSP Response received IOMB=%p\n", pMsg1));
640       mpiDifEncOffloadRsp(agRoot, (agsaDifEncOffloadRspV_t *)pMsg1);
641       break;
642     }			//delray end
643     default:
644     {
645 #ifdef SALL_API_TEST
646       saRoot->LLCounters.IOCounter.numUNKNWRespIOMB++;
647       SA_DBG1(("mpiParseOBIomb, UnKnown Response received IOMB=%p, %d\n",
648              pMsg1, saRoot->LLCounters.IOCounter.numUNKNWRespIOMB));
649 #else
650       SA_DBG1(("mpiParseOBIomb, Unknown IOMB Response received opcode 0x%X IOMB=%p\n",opcode, pMsg1));
651 #endif
652       break;
653     }
654   } /* switch */
655 
656   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2f");
657 
658   return ret;
659 
660 }
661 #endif
662 
663 #ifndef BIOS
664 #endif
665 
666 /******************************************************************************/
667 /*! \brief ECHO Response
668  *
669  *  This routine handles the response of ECHO Command
670  *
671  *  \param agRoot       Handles for this instance of SAS/SATA LLL
672  *  \param pIomb        Pointer of IOMB Mesage
673  *
674  *  \return sucess or fail
675  *
676  */
677 /*******************************************************************************/
678 GLOBAL bit32 mpiEchoRsp(
679   agsaRoot_t          *agRoot,
680   agsaEchoRsp_t       *pIomb
681   )
682 {
683   bit32               ret = AGSA_RC_SUCCESS;
684   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
685   agsaIORequestDesc_t *pRequest;
686   agsaContext_t       *agContext;
687   bit32               tag;
688 
689   smTraceFuncEnter(hpDBG_VERY_LOUD, "2g");
690 
691   SA_DBG3(("mpiEchoRsp: HTAG=0x%x\n", pIomb->tag));
692 
693   /* get request from IOMap */
694   OSSA_READ_LE_32(agRoot, &tag, pIomb, OSSA_OFFSET_OF(agsaEchoRsp_t, tag));
695 
696   pRequest = (agsaIORequestDesc_t *)saRoot->IOMap[tag].IORequest;
697   if (agNULL == pRequest)
698   {
699     SA_DBG1(("mpiEchoRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x\n", tag));
700     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2g");
701     return AGSA_RC_FAILURE;
702   }
703 
704   agContext = saRoot->IOMap[tag].agContext;
705 
706   ossaEchoCB(agRoot, agContext, (void *)&pIomb->payload[0]);
707 
708   /* remove the request from IOMap */
709   saRoot->IOMap[tag].Tag = MARK_OFF;
710   saRoot->IOMap[tag].IORequest = agNULL;
711   saRoot->IOMap[tag].agContext = agNULL;
712 
713   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
714   SA_ASSERT((pRequest->valid), "pRequest->valid");
715   pRequest->valid = agFALSE;
716   /* return the request to free pool */
717   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
718   {
719     SA_DBG1(("mpiEchoRsp: saving pRequest (%p) for later use\n", pRequest));
720     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
721   }
722   else
723   {
724     /* return the request to free pool */
725     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
726   }
727   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
728 
729   /* return value */
730   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2g");
731   return ret;
732 }
733 
734 /******************************************************************************/
735 /*! \brief Get NVM Data Response
736  *
737  *  This routine handles the response of GET NVM Data Response
738  *
739  *  \param agRoot       Handles for this instance of SAS/SATA LLL
740  *  \param pIomb        Pointer of IOMB Mesage
741  *
742  *  \return sucess or fail
743  *
744  */
745 /*******************************************************************************/
746 GLOBAL bit32 mpiGetNVMDataRsp(
747   agsaRoot_t          *agRoot,
748   agsaGetNVMDataRsp_t *pIomb
749   )
750 {
751   bit32               ret = AGSA_RC_SUCCESS;
752   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
753   agsaIORequestDesc_t *pRequest;
754   agsaContext_t       *agContext;
755   bit32               i, dataLen;
756   bit32               DlenStatus, tag, iRTdaBnDpsAsNvm;
757 
758   smTraceFuncEnter(hpDBG_VERY_LOUD, "2h");
759 
760   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaGetNVMDataRsp_t, tag));
761   OSSA_READ_LE_32(AGROOT, &DlenStatus, pIomb, OSSA_OFFSET_OF(agsaGetNVMDataRsp_t, DlenStatus));
762   OSSA_READ_LE_32(AGROOT, &iRTdaBnDpsAsNvm, pIomb, OSSA_OFFSET_OF(agsaGetNVMDataRsp_t, iRTdaBnDpsAsNvm));
763   OSSA_READ_LE_32(AGROOT, &dataLen, pIomb, OSSA_OFFSET_OF(agsaGetNVMDataRsp_t, NVMData[10])) ;
764 
765   SA_DBG1(("mpiGetNVMDataRsp: HTAG=0x%x\n", tag));
766 
767   /* get request from IOMap */
768   pRequest = (agsaIORequestDesc_t *)saRoot->IOMap[tag].IORequest;
769   if (agNULL == pRequest)
770   {
771     SA_DBG1(("mpiGetNVMDataRsp: Bad Response IOMB!!! pRequest is NULL.\n"));
772     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2h");
773     return AGSA_RC_FAILURE;
774   }
775 
776   agContext = saRoot->IOMap[tag].agContext;
777 
778   if (iRTdaBnDpsAsNvm & IRMode)
779   {
780     /* indirect mode - IR bit set */
781     SA_DBG1(("mpiGetNVMDataRsp: OSSA_SUCCESS, IR=1, DataLen=%d\n", dataLen));
782     if (((iRTdaBnDpsAsNvm & NVMD_TYPE) == AGSA_NVMD_CONFIG_SEEPROM) ||
783         ((iRTdaBnDpsAsNvm & NVMD_TYPE) == AGSA_NVMD_VPD_FLASH) ||
784         ((iRTdaBnDpsAsNvm & NVMD_TYPE) == AGSA_NVMD_TWI_DEVICES) ||
785         ((iRTdaBnDpsAsNvm & NVMD_TYPE) == AGSA_NVMD_EXPANSION_ROM) ||
786         ((iRTdaBnDpsAsNvm & NVMD_TYPE) == AGSA_NVMD_IOP_REG_FLASH))
787     {
788       /* CB for NVMD */
789 //#ifdef UN_USED_FUNC
790       ossaGetNVMDResponseCB(agRoot, agContext, (DlenStatus & NVMD_STAT), INDIRECT_MODE, dataLen, agNULL);
791 //#endif
792     }
793     else if (((iRTdaBnDpsAsNvm & NVMD_TYPE) == AAP1_RDUMP) ||
794              ((iRTdaBnDpsAsNvm & NVMD_TYPE) == IOP_RDUMP))
795     {
796 #ifdef UN_USED_FUNC
797       if ((DlenStatus & NVMD_STAT) == 0)
798       {
799         /* CB for Register Dump */
800 
801         ossaGetRegisterDumpCB(agRoot, agContext, OSSA_SUCCESS);
802       }
803       else
804       {
805         /* CB for Register Dump */
806         ossaGetRegisterDumpCB(agRoot, agContext, OSSA_FAILURE);
807       }
808 #endif
809     }
810     else
811     {
812       /* Should not be happened */
813       SA_DBG1(("mpiGetNVMDataRsp: (IR=1)Wrong Device type 0x%x\n", iRTdaBnDpsAsNvm));
814     }
815   }
816   else /* direct mode */
817   {
818     SA_DBG1(("mpiGetNVMDataRsp: OSSA_SUCCESS, IR=0, DataLen=%d\n", ((DlenStatus & NVMD_LEN) >> SHIFT24)));
819     for (i = 0; i < (((DlenStatus & NVMD_LEN) >> SHIFT24)/4); i++)
820     {
821       SA_DBG1(("mpiGetNVMDataRsp: OSSA_SUCCESS, NVMDATA=0x%x\n", pIomb->NVMData[i]));
822     }
823     if (((iRTdaBnDpsAsNvm & NVMD_TYPE) == AGSA_NVMD_CONFIG_SEEPROM) ||
824         ((iRTdaBnDpsAsNvm & NVMD_TYPE) == AGSA_NVMD_VPD_FLASH) ||
825         ((iRTdaBnDpsAsNvm & NVMD_TYPE) == AGSA_NVMD_TWI_DEVICES))
826     {
827       /* CB for NVMD */
828   //    char * safe_type_pun = (char *)(&pIomb->NVMData[0]);
829 #ifdef UN_USED_FUNC
830       ossaGetNVMDResponseCB(agRoot, agContext, (DlenStatus & NVMD_STAT), DIRECT_MODE,
831          ((DlenStatus & NVMD_LEN) >> SHIFT24), (agsaFrameHandle_t *)safe_type_pun);
832 #endif
833     }
834     else if (((iRTdaBnDpsAsNvm & NVMD_TYPE) == AAP1_RDUMP) ||
835              ((iRTdaBnDpsAsNvm & NVMD_TYPE) == IOP_RDUMP))
836     {
837 #ifdef UN_USED_FUNC
838 
839       if ((DlenStatus & NVMD_STAT) == 0)
840       {
841         /* CB for Register Dump */
842         ossaGetRegisterDumpCB(agRoot, agContext, OSSA_SUCCESS);
843       }
844       else
845       {
846         /* CB for Register Dump */
847         ossaGetRegisterDumpCB(agRoot, agContext, OSSA_FAILURE);
848       }
849 #endif
850     }
851     else
852     {
853       /* Should not be happened */
854       SA_DBG1(("mpiGetNVMDataRsp: (IR=0)Wrong Device type 0x%x\n", iRTdaBnDpsAsNvm));
855     }
856   }
857 
858   /* remove the request from IOMap */
859   saRoot->IOMap[tag].Tag = MARK_OFF;
860   saRoot->IOMap[tag].IORequest = agNULL;
861   saRoot->IOMap[tag].agContext = agNULL;
862 
863   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
864   SA_ASSERT((pRequest->valid), "pRequest->valid");
865   pRequest->valid = agFALSE;
866   /* return the request to free pool */
867   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
868   {
869     SA_DBG1(("mpiGetNVMDataRsp: saving pRequest (%p) for later use\n", pRequest));
870     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
871   }
872   else
873   {
874     /* return the request to free pool */
875     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
876   }
877   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
878 
879   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2h");
880 
881   /* return value */
882   return ret;
883 }
884 
885 /******************************************************************************/
886 /*! \brief Phy Event Response from SPCv
887  *
888  *  Process Phy Event from SPC
889  *
890  *  \param agRoot        Handles for this instance of SAS/SATA LL Layer
891  *  \param pIomb         pointer of IOMB
892  *
893  *  \return success or fail
894  *
895  */
896 /*******************************************************************************/
897 
898 GLOBAL bit32 mpiPhyStartEvent(
899   agsaRoot_t        *agRoot,
900   agsaHWEvent_Phy_OUB_t  *pIomb
901   )
902 {
903   bit32                    ret = AGSA_RC_SUCCESS;
904   agsaLLRoot_t             *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
905 
906   bit32                    phyId;
907   bit32                    IOMBStatus;
908   bit32                    tag;
909 
910   agsaIORequestDesc_t *pRequest;
911   agsaContext_t       *agContext;
912   bit32                HwCBStatus;
913 
914   if(saRoot == agNULL)
915   {
916     SA_DBG1(("mpiPhyStartEvent: saRoot == agNULL\n"));
917     return(AGSA_RC_FAILURE);
918   }
919   smTraceFuncEnter(hpDBG_VERY_LOUD, "2H");
920 
921   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaHWEvent_Phy_OUB_t, tag)) ;
922 
923   /* get request from IOMap */
924   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
925   agContext = saRoot->IOMap[tag].agContext;
926   /* remove the request from IOMap */
927   saRoot->IOMap[tag].Tag = MARK_OFF;
928   saRoot->IOMap[tag].IORequest = agNULL;
929   saRoot->IOMap[tag].agContext = agNULL;
930   if (agNULL == pRequest)
931   {
932     SA_DBG1(("mpiPhyStartEvent: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x \n", tag));
933     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2H");
934     return AGSA_RC_FAILURE;
935   }
936 
937   SA_DBG1(("mpiPhyStartEvent: Status 0x%X PhyId 0x%X\n",pIomb->Status,pIomb->ReservedPhyId));
938 
939   OSSA_READ_LE_32(AGROOT, &IOMBStatus, pIomb, OSSA_OFFSET_OF(agsaHWEvent_Phy_OUB_t,Status ));
940   OSSA_READ_LE_32(AGROOT, &phyId, pIomb, OSSA_OFFSET_OF(agsaHWEvent_Phy_OUB_t,ReservedPhyId ));
941 
942   switch (IOMBStatus)
943   {
944     case OSSA_MPI_IO_SUCCESS:                  /* PhyStart operation completed successfully */
945       HwCBStatus = 0;
946       saRoot->phys[phyId].linkstatus = 1;
947       SA_DBG1(("mpiPhyStartEvent:MPI_IO_SUCCESS IOMBStatus 0x%x for phyId 0x%x\n",IOMBStatus,phyId));
948       /* Callback with PHY_UP */
949       break;
950     case OSSA_MPI_ERR_INVALID_PHY_ID:      /* identifier specified in the PHY_START command is invalid i.e out of supported range for this product. */
951       HwCBStatus = 1;
952       saRoot->phys[phyId].linkstatus = 0;
953       SA_DBG1(("mpiPhyStartEvent: MPI_ERR_INVALID_PHY_ID IOMBStatus 0x%x for phyId 0x%x\n",IOMBStatus,phyId));
954       ret = AGSA_RC_FAILURE;
955       break;
956     case OSSA_MPI_ERR_PHY_ALREADY_STARTED:
957       HwCBStatus = 2;
958       saRoot->phys[phyId].linkstatus = 1;
959       SA_DBG1(("mpiPhyStartEvent: MPI_ERR_PHY_ALREADY_STARTED IOMBStatus 0x%x for phyId 0x%x\n",IOMBStatus,phyId));
960       ret = AGSA_RC_FAILURE;
961       break;
962     case OSSA_MPI_ERR_INVALID_ANALOG_TBL_IDX:
963       HwCBStatus = 4;
964       saRoot->phys[phyId].linkstatus = 0;
965       SA_DBG1(("mpiPhyStartEvent: MPI_ERR_INVALID_ANALOG_TBL_IDX IOMBStatus 0x%x for phyId 0x%x\n",IOMBStatus,phyId));
966       ret = AGSA_RC_FAILURE;
967       break;
968     default:
969       HwCBStatus = 3;
970       saRoot->phys[phyId].linkstatus = 0;
971       SA_DBG1(("mpiPhyStartEvent: Unknown IOMBStatus 0x%x for phyId 0x%x\n",IOMBStatus,phyId));
972       ret = AGSA_RC_FAILURE;
973     break;
974   }
975 
976   ossaHwCB(agRoot,agNULL, OSSA_HW_EVENT_PHY_START_STATUS ,((HwCBStatus << SHIFT8) | phyId) ,agContext, agNULL);
977 
978   /* return the request to free pool */
979   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
980   SA_ASSERT((pRequest->valid), "pRequest->valid");
981   pRequest->valid = agFALSE;
982   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
983   {
984     SA_DBG1(("mpiPhyStartEvent: saving pRequest (%p) for later use\n", pRequest));
985     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
986   }
987   else
988   {
989     /* return the request to free pool */
990     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
991   }
992   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
993 
994   return(ret);
995 }
996 
997 
998 GLOBAL bit32 mpiPhyStopEvent(
999   agsaRoot_t        *agRoot,
1000   agsaHWEvent_Phy_OUB_t  *pIomb
1001   )
1002 {
1003   bit32                    ret = AGSA_RC_SUCCESS;
1004   agsaLLRoot_t             *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
1005   bit32                    phyId;
1006 
1007   bit32                    IOMBStatus;
1008   bit32                    HwCBStatus;
1009 
1010   bit32                    tag;
1011 
1012   agsaIORequestDesc_t *pRequest;
1013   agsaContext_t       *agContext;
1014 
1015   agsaPhy_t               *pPhy;
1016   agsaPort_t              *pPort;
1017 
1018 
1019   if(saRoot == agNULL)
1020   {
1021     SA_DBG1(("mpiPhyStopEvent: saRoot == agNULL\n"));
1022     return(AGSA_RC_FAILURE);
1023   }
1024   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaHWEvent_Phy_OUB_t, tag)) ;
1025 
1026   /* get request from IOMap */
1027   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
1028   agContext = saRoot->IOMap[tag].agContext;
1029   /* remove the request from IOMap */
1030   saRoot->IOMap[tag].Tag = MARK_OFF;
1031   saRoot->IOMap[tag].IORequest = agNULL;
1032   saRoot->IOMap[tag].agContext = agNULL;
1033   if (agNULL == pRequest)
1034   {
1035     SA_DBG1(("mpiPhyStopEvent: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x \n", tag));
1036     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2H");
1037     return AGSA_RC_FAILURE;
1038   }
1039 
1040   OSSA_READ_LE_32(AGROOT, &IOMBStatus, pIomb, OSSA_OFFSET_OF(agsaHWEvent_Phy_OUB_t,Status ));
1041   OSSA_READ_LE_32(AGROOT, &phyId, pIomb, OSSA_OFFSET_OF(agsaHWEvent_Phy_OUB_t,ReservedPhyId ));
1042   SA_DBG1(("mpiPhyStopEvent: Status %08X PhyId %08X\n",IOMBStatus,phyId));
1043 
1044   if(smIS_SPCV(agRoot))
1045   {
1046       phyId &= 0xff;  // SPCv PHY_ID is one byte wide
1047   }
1048 
1049   saRoot->phys[phyId].linkstatus = 0;
1050 
1051   switch (IOMBStatus)
1052   {
1053     case OSSA_MPI_IO_SUCCESS:                  /* PhyStart operation completed successfully */
1054       SA_DBG1(("mpiPhyStopEvent:MPI_IO_SUCCESS  0x%x for phyId 0x%x\n",IOMBStatus,phyId));
1055       HwCBStatus = 0;
1056       /* Callback with PHY_DOWN */
1057       break;
1058     case OSSA_MPI_ERR_INVALID_PHY_ID:      /* identifier specified in the PHY_START command is invalid i.e out of supported range for this product. */
1059       SA_DBG1(("mpiPhyStopEvent: MPI_ERR_INVALID_PHY_ID 0x%x for phyId 0x%x\n",IOMBStatus,phyId));
1060       HwCBStatus = 1;
1061       break;
1062     case OSSA_MPI_ERR_PHY_NOT_STARTED:  /* An attempt to stop a phy which is not started  */
1063       HwCBStatus = 4;
1064       SA_DBG1(("mpiPhyStopEvent:  0x%x for phyId 0x%x\n",IOMBStatus,phyId));
1065       break;
1066 
1067     case OSSA_MPI_ERR_DEVICES_ATTACHED:  /* All the devices in a port need to be deregistered if the PHY_STOP is for the last phy  */
1068       HwCBStatus = 2;
1069       SA_DBG1(("mpiPhyStopEvent:  0x%x for phyId 0x%x\n",IOMBStatus,phyId));
1070       break;
1071 
1072     default:
1073       HwCBStatus = 3;
1074       SA_DBG1(("mpiPhyStopEvent: Unknown Status 0x%x for phyId 0x%x\n",IOMBStatus,phyId));
1075       break;
1076   }
1077 
1078 
1079   if(HwCBStatus == 0)
1080   {
1081     pPhy = &(saRoot->phys[phyId]);
1082     /* get the port of the phy */
1083     pPort = pPhy->pPort;
1084     if ( agNULL != pPort )
1085     {
1086       SA_DBG1(("siPhyStopCB: phy%d invalidating port\n", phyId));
1087       /* invalid port state, remove the port */
1088       pPort->status |= PORT_INVALIDATING;
1089       saRoot->PortMap[pPort->portId].PortStatus  |= PORT_INVALIDATING;
1090       /* invalid the port */
1091       siPortInvalid(agRoot, pPort);
1092       /* map out the portmap */
1093       saRoot->PortMap[pPort->portId].PortContext = agNULL;
1094       saRoot->PortMap[pPort->portId].PortID = PORT_MARK_OFF;
1095       saRoot->PortMap[pPort->portId].PortStatus  |= PORT_INVALIDATING;
1096       ossaHwCB(agRoot,&(pPort->portContext) , OSSA_HW_EVENT_PHY_STOP_STATUS, ((HwCBStatus << SHIFT8) | phyId ),agContext, agNULL);
1097     }
1098     else
1099     {
1100       SA_DBG1(("siPhyStopCB: phy%d - Port is not established\n", phyId));
1101       ossaHwCB(agRoot, agNULL, OSSA_HW_EVENT_PHY_STOP_STATUS, ((HwCBStatus << SHIFT8) | phyId ) , agContext, agNULL);
1102     }
1103 
1104     /* set PHY_STOPPED status */
1105     PHY_STATUS_SET(pPhy, PHY_STOPPED);
1106 
1107     /* Exclude the phy from a port */
1108     if ( agNULL != pPort )
1109     {
1110       /* Acquire port list lock */
1111       ossaSingleThreadedEnter(agRoot, LL_PORT_LOCK);
1112 
1113       /* Delete the phy from the port */
1114       pPort->phyMap[phyId] = agFALSE;
1115       saRoot->phys[phyId].pPort = agNULL;
1116 
1117       /* Release port list lock */
1118       ossaSingleThreadedLeave(agRoot, LL_PORT_LOCK);
1119     }
1120 
1121   }
1122   else
1123   {
1124     SA_DBG1(("siPhyStopCB: Error phy%d - Port is not established\n", phyId));
1125     ossaHwCB(agRoot, agNULL, OSSA_HW_EVENT_PHY_STOP_STATUS, ((HwCBStatus << SHIFT8) | phyId ) , agContext, agNULL);
1126   }
1127 
1128   /* return the request to free pool */
1129   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
1130   SA_ASSERT((pRequest->valid), "pRequest->valid");
1131   pRequest->valid = agFALSE;
1132   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
1133   {
1134     SA_DBG1(("mpiPhyStartEvent: saving pRequest (%p) for later use\n", pRequest));
1135     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
1136   }
1137   else
1138   {
1139     /* return the request to free pool */
1140     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
1141   }
1142   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
1143 
1144   return(ret);
1145 }
1146 
1147 
1148 /******************************************************************************/
1149 /*! \brief Hardware Event Response from SPC
1150  *
1151  *  Process HW Event from SPC
1152  *
1153  *  \param agRoot        Handles for this instance of SAS/SATA LL Layer
1154  *  \param pIomb         pointer of IOMB
1155  *
1156  *  \return success or fail
1157  *
1158  */
1159 /*******************************************************************************/
1160 GLOBAL bit32 mpiHWevent(
1161   agsaRoot_t            *agRoot,
1162   agsaHWEvent_SPC_OUB_t *pIomb
1163   )
1164 {
1165   bit32                    ret = AGSA_RC_SUCCESS;
1166   agsaLLRoot_t             *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
1167   agsaIORequestDesc_t      *pRequest;
1168   agsaPortContext_t        *agPortContext;
1169   agsaSASIdentify_t        *IDframe;
1170   agsaFisRegDeviceToHost_t *sataFis;
1171   agsaContext_t            *agContext;
1172   agsaPort_t               *pPort = agNULL;
1173   bit32                    phyId;
1174   bit32                    portId;
1175   bit32                    Event;
1176   bit32                    tag, status;
1177   bit8                     linkRate;
1178   bit32                    LREventPhyIdPortId;
1179   bit32                    npipps, eventParam,npip,port_state;
1180 
1181   smTraceFuncEnter(hpDBG_VERY_LOUD,"2j");
1182 
1183   SA_ASSERT((agNULL !=saRoot ), "");
1184   if(saRoot == agNULL)
1185   {
1186     SA_DBG1(("mpiHWevent: saRoot == agNULL\n"));
1187     return(AGSA_RC_FAILURE);
1188   }
1189   if(smIS_SPC(agRoot))
1190   {
1191     OSSA_READ_LE_32(AGROOT, &LREventPhyIdPortId, pIomb, OSSA_OFFSET_OF(agsaHWEvent_SPC_OUB_t, LRStatusEventPhyIdPortId));
1192     OSSA_READ_LE_32(AGROOT, &npipps, pIomb, OSSA_OFFSET_OF(agsaHWEvent_SPC_OUB_t, NpipPortState));
1193     OSSA_READ_LE_32(AGROOT, &eventParam, pIomb, OSSA_OFFSET_OF(agsaHWEvent_SPC_OUB_t, EVParam));
1194     SA_DBG2(("mpiHWEvent: S, LREventPhyIdPortId 0x%08x npipps 0x%08x eventParam 0x%08x\n", LREventPhyIdPortId ,npipps ,eventParam ));
1195 
1196     /* get port context */
1197     portId = LREventPhyIdPortId & PORTID_MASK;
1198     smTrace(hpDBG_VERY_LOUD,"QK",portId);
1199     /* TP:QK portId */
1200 
1201     /* get phyId */
1202     phyId = (LREventPhyIdPortId & PHY_ID_BITS) >> SHIFT4;
1203 
1204     smTrace(hpDBG_VERY_LOUD,"QK",npipps);
1205     /* TP:QK npipps */
1206     smTrace(hpDBG_VERY_LOUD,"QL",portId);
1207     /* TP:QL portId */
1208     smTrace(hpDBG_VERY_LOUD,"QM",phyId);
1209     /* TP:QM phyId */
1210 
1211     SA_DBG1(("mpiHWEvent:SPC, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1212                 phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, (npipps & PORT_STATE_MASK)));
1213   }
1214   else
1215   {
1216     OSSA_READ_LE_32(AGROOT, &LREventPhyIdPortId, pIomb, OSSA_OFFSET_OF(agsaHWEvent_V_OUB_t, LRStatEventPortId));
1217     OSSA_READ_LE_32(AGROOT, &npipps, pIomb, OSSA_OFFSET_OF(agsaHWEvent_V_OUB_t, RsvPhyIdNpipRsvPortState));
1218     OSSA_READ_LE_32(AGROOT, &eventParam, pIomb, OSSA_OFFSET_OF(agsaHWEvent_V_OUB_t, EVParam));
1219     SA_DBG2(("mpiHWEvent: V, LREventPhyIdPortId 0x%08x npipps 0x%08x eventParam 0x%08x\n", LREventPhyIdPortId ,npipps ,eventParam ));
1220 
1221     smTrace(hpDBG_VERY_LOUD,"QN",npipps);
1222     /* TP:QN npipps */
1223 
1224     /* get port context */
1225     portId = LREventPhyIdPortId & PORTID_MASK;
1226 
1227     smTrace(hpDBG_VERY_LOUD,"QO",portId);
1228     /* TP:QO portId */
1229 
1230     /* get phyId */
1231     phyId = (npipps & PHY_ID_V_BITS) >> SHIFT16;
1232     smTrace(hpDBG_VERY_LOUD,"QP",phyId);
1233     /* TP:QP phyId */
1234 
1235     /* get npipps */
1236     npip =(npipps & 0xFF00 ) >> SHIFT4;
1237     port_state  =(npipps & 0xF );
1238     npipps = npip | port_state; // Make it look like SPCs nipps
1239 
1240 
1241     SA_DBG1(("mpiHWEvent: V, PhyID 0x%x PortID 0x%x NPIP 0x%x PS 0x%x npipps 0x%x\n",
1242                 phyId, portId,npip,port_state,npipps));
1243   }
1244 
1245   Event = (LREventPhyIdPortId & HW_EVENT_BITS) >> SHIFT8;
1246 
1247   /* get Link Rate */
1248   linkRate = (bit8)((LREventPhyIdPortId & LINK_RATE_MASK) >> SHIFT28);
1249   /* get status byte */
1250   status = (LREventPhyIdPortId & STATUS_BITS) >> SHIFT24;
1251 
1252   smTrace(hpDBG_VERY_LOUD,"HA",portId);
1253   /* TP:HA portId */
1254   smTrace(hpDBG_VERY_LOUD,"HB",linkRate);
1255   /* TP:HB linkRate */
1256   smTrace(hpDBG_VERY_LOUD,"HC",phyId);
1257   /* TP:HC phyId */
1258   smTrace(hpDBG_VERY_LOUD,"HD",npipps);
1259   /* TP:HD npipps */
1260   smTrace(hpDBG_VERY_LOUD,"HE",status);
1261   /* TP:HE status */
1262 
1263   if (portId > saRoot->phyCount)
1264   {
1265     if (OSSA_PORT_NOT_ESTABLISHED == (npipps & PORT_STATE_MASK))
1266     {
1267       /* out of range checking for portId */
1268       SA_DBG1(("mpiHWEvent: PORT_ID is out of range, PhyID %d PortID %d\n",
1269                 phyId, portId));
1270       /* port is not estiblished */
1271       agPortContext = agNULL;
1272     }
1273     else
1274     {
1275       /* portId is bad and state is correct - should not happen */
1276       SA_DBG1(("mpiHWEvent: PORT_ID is bad with correct Port State, PhyID %d PortID %d\n",
1277                 phyId, portId));
1278       smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2j");
1279       return AGSA_RC_FAILURE;
1280     }
1281   }
1282   else
1283   {
1284     SA_DBG2(("mpiHWEvent:PortID 0x%x PortStatus 0x%x PortContext %p\n",saRoot->PortMap[portId & PORTID_MASK].PortID,saRoot->PortMap[portId & PORTID_MASK].PortStatus,saRoot->PortMap[portId & PORTID_MASK].PortContext));
1285     agPortContext = (agsaPortContext_t *)saRoot->PortMap[portId].PortContext;
1286   }
1287 
1288   if(agPortContext == agNULL)
1289   {
1290     SA_DBG1(("mpiHWEvent: agPortContext is NULL, PhyID %d PortID %d\n",
1291                 phyId, portId));
1292   }
1293 
1294   smTrace(hpDBG_VERY_LOUD,"HF",Event);
1295   /* TP:HF OSSA_HW_EVENT */
1296 
1297   switch (Event)
1298   {
1299     case OSSA_HW_EVENT_SAS_PHY_UP:
1300     {
1301       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_SAS_PHY_UP, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1302                 phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, (npipps & PORT_STATE_MASK)));
1303 
1304       /* get SAS Identify info */
1305       IDframe = (agsaSASIdentify_t *)&pIomb->sasIdentify;
1306       /* Callback about SAS link up */
1307       saRoot->phys[phyId].linkstatus |= 2;
1308       saRoot->phys[phyId].sasIdentify.phyIdentifier = IDframe->phyIdentifier;
1309       saRoot->phys[phyId].sasIdentify.deviceType_addressFrameType = IDframe->deviceType_addressFrameType;
1310 
1311       si_memcpy(&(saRoot->phys[phyId].sasIdentify.sasAddressHi),&(IDframe->sasAddressHi),4);
1312       si_memcpy(&(saRoot->phys[phyId].sasIdentify.sasAddressLo),&(IDframe->sasAddressLo),4);
1313       siEventPhyUpRcvd(agRoot, phyId, IDframe, portId, npipps, linkRate);
1314       break;
1315     }
1316     case OSSA_HW_EVENT_SATA_PHY_UP:
1317     {
1318       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_SATA_PHY_UP, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1319                 phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, (npipps & PORT_STATE_MASK)));
1320 
1321       /* get SATA FIS info */
1322       saRoot->phys[phyId].linkstatus |= 2;
1323       sataFis = (agsaFisRegDeviceToHost_t *)&pIomb->sataFis;
1324       /* Callback about SATA Link Up */
1325       siEventSATASignatureRcvd(agRoot, phyId, (void *)sataFis, portId, npipps, linkRate);
1326       break;
1327     }
1328     case OSSA_HW_EVENT_SATA_SPINUP_HOLD:
1329     {
1330       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_SATA_SPINUP_HOLD, PhyID %d\n", phyId));
1331       ossaHwCB(agRoot, agNULL, OSSA_HW_EVENT_SATA_SPINUP_HOLD, phyId, agNULL, agNULL);
1332       break;
1333     }
1334     case OSSA_HW_EVENT_PHY_DOWN:
1335     {
1336       agsaPhy_t *pPhy = &(saRoot->phys[phyId]);
1337 
1338       if(pPhy) {
1339 		osti_memset(&pPhy->sasIdentify,0,sizeof(agsaSASIdentify_t));
1340       }
1341       saRoot->phys[phyId].linkstatus &= 1;
1342       if (agNULL != agPortContext)
1343       {
1344         pPort = (agsaPort_t *) (agPortContext->sdkData);
1345       }
1346 
1347       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_DOWN, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1348                 phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, npipps & PORT_STATE_MASK));
1349 
1350       /* callback */
1351       if ( agNULL != pPort )
1352       {
1353         if (OSSA_PORT_VALID == (npipps & PORT_STATE_MASK))
1354         {
1355           pPort->status &= ~PORT_INVALIDATING;
1356           saRoot->PortMap[portId].PortStatus  &= ~PORT_INVALIDATING;
1357           SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_DOWN, PhyID %d  ~PORT_INVALIDATING \n", phyId));
1358         }
1359         else
1360         {
1361           if (OSSA_PORT_INVALID == (npipps & PORT_STATE_MASK))
1362           {
1363             /* set port invalid flag */
1364             pPort->status |= PORT_INVALIDATING;
1365             saRoot->PortMap[portId].PortStatus  |= PORT_INVALIDATING;
1366             SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_DOWN PortInvalid portID %d PortContext %p NPIP 0x%x\n", portId, agPortContext,npipps));
1367           }
1368           else
1369           {
1370             if (OSSA_PORT_IN_RESET == (npipps & PORT_STATE_MASK))
1371             {
1372               SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_DOWN PortInReset portID %d PortContext %p\n", portId, agPortContext));
1373             }
1374             else
1375             {
1376               SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_DOWN Not PortInReset portID %d PortContext %p\n", portId, agPortContext));
1377             }
1378           }
1379         }
1380 
1381         /* report PhyId, NPIP, PortState */
1382         phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16);
1383         /* Callback with PHY_DOWN */
1384         ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_PHY_DOWN, phyId, agNULL, agNULL);
1385       }
1386       else
1387       {
1388         /* no portcontext.- error */
1389         SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_DOWN PhyDown pPort is NULL.\n"));
1390       }
1391 
1392       /* set PHY_DOWN status */
1393       PHY_STATUS_SET(pPhy, PHY_DOWN);
1394       break;
1395     }
1396     case OSSA_HW_EVENT_PHY_ERR_INBOUND_CRC:
1397     {
1398       agsaPhyErrCountersPage_t errorParam;
1399       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_ERR_INBOUND_CRC, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1400                 phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, npipps & PORT_STATE_MASK));
1401       si_memset(&errorParam, 0, sizeof(agsaPhyErrCountersPage_t));
1402       errorParam.inboundCRCError = eventParam;
1403       /* report PhyId, NPIP, PortState */
1404       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16);
1405       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_PHY_ERR_INBOUND_CRC, phyId, (void *)&errorParam, agNULL);
1406       break;
1407     }
1408     case OSSA_HW_EVENT_HARD_RESET_RECEIVED:
1409     {
1410       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_HARD_RESET_RECEIVED, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1411                 phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, npipps & PORT_STATE_MASK));
1412       /* report PhyId, NPIP, PortState */
1413       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16);
1414       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_HARD_RESET_RECEIVED, phyId, agNULL, agNULL);
1415       break;
1416     }
1417     case OSSA_HW_EVENT_PHY_ERR_INVALID_DWORD:
1418     {
1419       agsaPhyErrCountersPage_t errorParam;
1420       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_LINK_ERR_INVALID_DWORD, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1421                 phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, npipps & PORT_STATE_MASK));
1422       si_memset(&errorParam, 0, sizeof(agsaPhyErrCountersPage_t));
1423       errorParam.invalidDword = eventParam;
1424       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16);
1425       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_PHY_ERR_INVALID_DWORD, phyId, (void *)&errorParam, agNULL);
1426       break;
1427     }
1428     case OSSA_HW_EVENT_PHY_ERR_DISPARITY_ERROR:
1429     {
1430       agsaPhyErrCountersPage_t errorParam;
1431       SA_DBG3(("mpiHWEvent: OSSA_HW_EVENT_LINK_ERR_DISPARITY_ERROR, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1432                 phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, npipps & PORT_STATE_MASK));
1433       /* report PhyId, NPIP, PortState */
1434       si_memset(&errorParam, 0, sizeof(agsaPhyErrCountersPage_t));
1435       errorParam.runningDisparityError = eventParam;
1436       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16);
1437       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_PHY_ERR_DISPARITY_ERROR, phyId, (void *)&errorParam, agNULL);
1438       break;
1439     }
1440     case OSSA_HW_EVENT_PHY_ERR_CODE_VIOLATION:
1441     {
1442       agsaPhyErrCountersPage_t errorParam;
1443       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_LINK_ERR_CODE_VIOLATION, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1444                 phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, npipps & PORT_STATE_MASK));
1445       /* report PhyId, NPIP, PortState */
1446       si_memset(&errorParam, 0, sizeof(agsaPhyErrCountersPage_t));
1447       errorParam.codeViolation = eventParam;
1448       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16);
1449       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_PHY_ERR_CODE_VIOLATION, phyId, (void *)&errorParam, agNULL);
1450       break;
1451     }
1452     case OSSA_HW_EVENT_PHY_ERR_LOSS_OF_DWORD_SYNCH:
1453     {
1454       agsaPhyErrCountersPage_t errorParam;
1455       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_LINK_ERR_LOSS_OF_DWORD_SYNCH, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1456                 phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, npipps & PORT_STATE_MASK));
1457       /* report PhyId, NPIP, PortState */
1458       si_memset(&errorParam, 0, sizeof(agsaPhyErrCountersPage_t));
1459       errorParam.lossOfDwordSynch = eventParam;
1460       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16);
1461       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_PHY_ERR_LOSS_OF_DWORD_SYNCH, phyId, (void *)&errorParam, agNULL);
1462       break;
1463     }
1464     case OSSA_HW_EVENT_PORT_RECOVERY_TIMER_TMO:
1465     {
1466       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PORT_RECOVERY_TIMER_TMO, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1467         phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, npipps & PORT_STATE_MASK));
1468 
1469       if (agNULL != agPortContext)
1470       {
1471         pPort = (agsaPort_t *) (agPortContext->sdkData);
1472       }
1473       else
1474       {
1475         SA_ASSERT((agPortContext), "agPortContext agNULL was there a PHY UP?");
1476         return(AGSA_RC_FAILURE);
1477       }
1478 
1479       /* report PhyId, NPIP, PortState */
1480       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16);
1481       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_PORT_RECOVERY_TIMER_TMO, phyId, agNULL, agNULL);
1482 
1483       if (OSSA_PORT_VALID == (npipps & PORT_STATE_MASK))
1484       {
1485          pPort->status &= ~PORT_INVALIDATING;
1486          saRoot->PortMap[portId].PortStatus  &= ~PORT_INVALIDATING;
1487          SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PORT_RECOVERY_TIMER_TMO NOT PORT_INVALIDATING portID %d PortContext %p\n", portId, agPortContext));
1488       }
1489       else
1490       {
1491         if (OSSA_PORT_INVALID == (npipps & PORT_STATE_MASK))
1492         {
1493           /* set port invalid flag */
1494           pPort->status |= PORT_INVALIDATING;
1495           saRoot->PortMap[portId].PortStatus  |= PORT_INVALIDATING;
1496           SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PORT_RECOVERY_TIMER_TMO PORT_INVALIDATING portID %d PortContext %p\n", portId, agPortContext));
1497          }
1498         else
1499         {
1500           if (OSSA_PORT_IN_RESET == (npipps & PORT_STATE_MASK))
1501           {
1502             SA_DBG1(("mpiHWEvent: PortInReset portID %d PortContext %p\n", portId, agPortContext));
1503           }
1504         }
1505       }
1506       break;
1507     }
1508     case OSSA_HW_EVENT_PORT_RECOVER:
1509     {
1510       if (agNULL != agPortContext)
1511       {
1512         pPort = (agsaPort_t *) (agPortContext->sdkData);
1513       }
1514 
1515       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PORT_RECOVER, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1516         phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, npipps & PORT_STATE_MASK));
1517 
1518       if (OSSA_PORT_VALID == (npipps & PORT_STATE_MASK))
1519       {
1520         if (agNULL != pPort)
1521         {
1522           /* reset port invalid flag */
1523           pPort->status &= ~PORT_INVALIDATING;
1524           SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PORT_RECOVER NOT PORT_INVALIDATING portID %d PortContext %p\n", portId, agPortContext));
1525         }
1526         saRoot->PortMap[portId].PortStatus  &= ~PORT_INVALIDATING;
1527       }
1528       /* get SAS Identify info */
1529       IDframe = (agsaSASIdentify_t *)&pIomb->sasIdentify;
1530       /* report PhyId, NPIP, PortState and LinkRate */
1531       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16) | (linkRate << SHIFT8);
1532       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_PORT_RECOVER, phyId, agNULL, (void *)IDframe);
1533       break;
1534     }
1535     case OSSA_HW_EVENT_PHY_STOP_STATUS:
1536     {
1537       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_STOP_STATUS PhyId=0x%x, status=0x%x eventParam=0x%x\n", phyId, status,eventParam));
1538       OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaHWEvent_SPC_OUB_t, EVParam));
1539 
1540       switch(eventParam)
1541       {
1542         case 0:
1543           SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_STOP_STATUS Stopped 0\n" ));
1544         break;
1545         case 1:
1546           SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_STOP_STATUS INVALID_PHY 1\n" ));
1547         break;
1548         case 2:
1549           SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_STOP_STATUS DEVICES_ATTACHED 2\n" ));
1550         break;
1551         case 3:
1552           SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_STOP_STATUS OTHER_FAILURE 3\n" ));
1553         break;
1554         case 4:
1555           SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_STOP_STATUS PHY_NOT_ENABLED 4\n" ));
1556         break;
1557         default:
1558           SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_STOP_STATUS Unknown code 0x%x\n", eventParam));
1559           break;
1560       }
1561 
1562       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_STOP_STATUS phyId 0x%x status 0x%x eventParam 0x%x\n", phyId, status,eventParam));
1563       /* get request from IOMap */
1564       pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
1565       SA_ASSERT((pRequest), "pRequest NULL");
1566       SA_ASSERT((pRequest->valid), "pRequest->valid");
1567 
1568       agContext = saRoot->IOMap[tag].agContext;
1569 
1570       siPhyStopCB(agRoot, phyId, status, agContext, portId, npipps);
1571 
1572       /* remove the request from IOMap */
1573       saRoot->IOMap[tag].Tag = MARK_OFF;
1574       saRoot->IOMap[tag].IORequest = agNULL;
1575       saRoot->IOMap[tag].agContext = agNULL;
1576 
1577       ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
1578       pRequest->valid = agFALSE;
1579       /* return the request to free pool */
1580       if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
1581       {
1582         SA_DBG1(("mpiHWevent: saving pRequest (%p) for later use\n", pRequest));
1583         saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
1584       }
1585       else
1586       {
1587         /* return the request to free pool */
1588         saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
1589       }
1590       ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
1591       break;
1592     }
1593     case OSSA_HW_EVENT_BROADCAST_CHANGE:
1594     {
1595       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_BROADCAST_CHANGE, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1596                 phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, npipps & PORT_STATE_MASK));
1597       /* report PhyId, NPIP, PortState */
1598       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16);
1599       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_BROADCAST_CHANGE, phyId, agNULL, agNULL);
1600       break;
1601     }
1602     case OSSA_HW_EVENT_BROADCAST_SES:
1603     {
1604       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_BROADCAST_CHANGE_SES, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1605                 phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, npipps & PORT_STATE_MASK));
1606       /* report PhyId, NPIP, PortState */
1607       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16);
1608       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_BROADCAST_SES, phyId, agNULL, agNULL);
1609       break;
1610     }
1611     case OSSA_HW_EVENT_BROADCAST_EXP:
1612     {
1613       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_BROADCAST_EXP, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1614                 phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, npipps & PORT_STATE_MASK));
1615       /* report PhyId, NPIP, PortState */
1616       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16);
1617       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_BROADCAST_EXP, phyId, agNULL, agNULL);
1618       break;
1619     }
1620     case OSSA_HW_EVENT_ID_FRAME_TIMEOUT:
1621     {
1622       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_ID_FRAME_TIMEOUT, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1623                 phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, npipps & PORT_STATE_MASK));
1624       /* report PhyId, NPIP, PortState */
1625       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16);
1626       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_ID_FRAME_TIMEOUT, phyId, agNULL, agNULL);
1627       break;
1628     }
1629     case OSSA_HW_EVENT_PHY_START_STATUS:
1630     {
1631       OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaHWEvent_SPC_OUB_t, EVParam)) ;
1632       /* get request from IOMap */
1633       pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
1634 
1635       SA_ASSERT((pRequest), "pRequest");
1636       if( pRequest == agNULL)
1637       {
1638          SA_DBG1(("mpiHWevent: pRequest (%p) NULL\n", pRequest));
1639          ret = AGSA_RC_FAILURE;
1640          break;
1641       }
1642 
1643       agContext = saRoot->IOMap[tag].agContext;
1644 
1645       /* makeup for CB */
1646       status = (status << 8) | phyId;
1647       ossaHwCB(agRoot, agNULL, OSSA_HW_EVENT_PHY_START_STATUS, status, agContext, agNULL);
1648 
1649       /* remove the request from IOMap */
1650       saRoot->IOMap[tag].Tag = MARK_OFF;
1651       saRoot->IOMap[tag].IORequest = agNULL;
1652       saRoot->IOMap[tag].agContext = agNULL;
1653 
1654       ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
1655       SA_ASSERT((pRequest->valid), "pRequest->valid");
1656       pRequest->valid = agFALSE;
1657       /* return the request to free pool */
1658       if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
1659       {
1660         SA_DBG1(("mpiHWevent: saving pRequest (%p) for later use\n", pRequest));
1661         saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
1662       }
1663       else
1664       {
1665         /* return the request to free pool */
1666         saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
1667       }
1668       ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
1669 
1670       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_START_STATUS, PhyID %d\n", phyId));
1671 
1672       break;
1673     }
1674     case OSSA_HW_EVENT_PHY_ERR_PHY_RESET_FAILED:
1675     {
1676       agsaPhyErrCountersPage_t errorParam;
1677       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PHY_ERR_PHY_RESET_FAILED, PhyID %d PortID %d NPIP 0x%x PS 0x%x\n",
1678                 phyId, portId, (npipps & PHY_IN_PORT_MASK) >> SHIFT4, npipps & PORT_STATE_MASK));
1679       /* report PhyId, NPIP, PortState */
1680       si_memset(&errorParam, 0, sizeof(agsaPhyErrCountersPage_t));
1681       errorParam.phyResetProblem = eventParam;
1682       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16);
1683       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_PHY_ERR_PHY_RESET_FAILED, phyId, (void *)&errorParam, agNULL);
1684       break;
1685     }
1686     case OSSA_HW_EVENT_PORT_RESET_TIMER_TMO:
1687     {
1688       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PORT_RESET_TIMER_TMO, PhyID %d PortID %d\n", phyId, portId));
1689       /* report PhyId, NPIP, PortState */
1690       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16);
1691       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_PORT_RESET_TIMER_TMO, phyId, agNULL, agNULL);
1692       break;
1693     }
1694     case OSSA_HW_EVENT_PORT_RESET_COMPLETE:
1695     {
1696       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_PORT_RESET_COMPLETE, PhyID %d PortID %d\n", phyId, portId));
1697       /* get SAS Identify info */
1698       IDframe = (agsaSASIdentify_t *)&pIomb->sasIdentify;
1699       /* report PhyId, NPIP, PortState and LinkRate */
1700       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16) | (linkRate << SHIFT8);
1701       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_PORT_RESET_COMPLETE, phyId, agNULL, (void *)IDframe);
1702       break;
1703     }
1704     case OSSA_HW_EVENT_BROADCAST_ASYNCH_EVENT:
1705     {
1706       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_BROADCAST_ASYNCH_EVENT, PhyID %d PortID %d\n", phyId, portId));
1707       /* report PhyId, NPIP, PortState */
1708       phyId |= (npipps & PHY_IN_PORT_MASK) | ((npipps & PORT_STATE_MASK) << SHIFT16);
1709       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_BROADCAST_ASYNCH_EVENT, phyId, agNULL, agNULL);
1710       break;
1711     }
1712     case OSSA_HW_EVENT_IT_NEXUS_LOSS:
1713     {
1714       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_IT_NEXUS_LOSS, PhyID %d PortID %d status 0x%X\n", phyId, portId,status));
1715       break;
1716     }
1717     case OSSA_HW_EVENT_OPEN_RETRY_BACKOFF_THR_ADJUSTED:
1718     {
1719       SA_DBG1(("mpiHWEvent: OSSA_HW_EVENT_OPEN_RETRY_BACKOFF_THR_ADJUSTED, PhyID %d PortID %d status 0x%X\n", phyId, portId,status));
1720       ossaHwCB(agRoot, agPortContext, OSSA_HW_EVENT_OPEN_RETRY_BACKOFF_THR_ADJUSTED, phyId, agNULL, agNULL);
1721       break;
1722     }
1723 
1724     default:
1725     {
1726       SA_DBG1(("mpiHWEvent: Unknown HW Event 0x%x status 0x%X\n", Event ,status));
1727       break;
1728     }
1729   }
1730 
1731   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2j");
1732   return ret;
1733 }
1734 
1735 /******************************************************************************/
1736 /*! \brief SPC MPI SMP Completion
1737  *
1738  *  This function handles the SMP completion.
1739  *
1740  *  \param agRoot       Handles for this instance of SAS/SATA hardware
1741  *  \param pIomb        pointer of Message1
1742  *  \param bc           buffer count
1743  *
1744  *  \return The read value
1745  *
1746  */
1747 /*******************************************************************************/
1748 GLOBAL bit32 mpiSMPCompletion(
1749   agsaRoot_t             *agRoot,
1750   agsaSMPCompletionRsp_t *pIomb
1751   )
1752 {
1753   bit32               ret = AGSA_RC_SUCCESS;
1754   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
1755   bit32               status;
1756   bit32               tag;
1757   bit32               param;
1758   agsaIORequestDesc_t *pRequest;
1759 
1760   SA_DBG3(("mpiSMPCompletion: start, HTAG=0x%x\n", pIomb->tag));
1761 
1762   smTraceFuncEnter(hpDBG_VERY_LOUD,"2k");
1763 
1764   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaSMPCompletionRsp_t, tag)) ;
1765   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaSMPCompletionRsp_t, status)) ;
1766   OSSA_READ_LE_32(AGROOT, &param, pIomb, OSSA_OFFSET_OF(agsaSMPCompletionRsp_t, param)) ;
1767    /* get SMP request from IOMap */
1768   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
1769   if (agNULL == pRequest)
1770   {
1771     SA_DBG1(("mpiSMPCompletion: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x PARAM=0x%x\n", tag, status, param));
1772     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2k");
1773     return AGSA_RC_FAILURE;
1774   }
1775 
1776   switch (status)
1777   {
1778   case OSSA_IO_SUCCESS:
1779     SA_DBG3(("mpiSMPCompletion: OSSA_IO_SUCCESS HTAG = 0x%x\n", tag));
1780     /* process message */
1781     siSMPRespRcvd(agRoot, pIomb, param, tag);
1782     break;
1783 
1784   case OSSA_IO_OVERFLOW:
1785     SA_DBG1(("mpiSMPCompletion: OSSA_IO_OVERFLOW HTAG = 0x%x\n", tag));
1786     saRoot->IoErrorCount.agOSSA_IO_OVERFLOW++;
1787     /* SMP failed */
1788     siAbnormal(agRoot, pRequest, status, 0, 0);
1789     break;
1790 
1791   case OSSA_IO_ABORTED:
1792     SA_DBG1(("mpiSMPCompletion: OSSA_IO_ABORTED HTAG = 0x%x\n", tag));
1793 
1794     saRoot->IoErrorCount.agOSSA_IO_ABORTED++;
1795 #ifdef SA_PRINTOUT_IN_WINDBG
1796 #ifndef DBG
1797         DbgPrint("agOSSA_IO_ABORTED  %d\n",  saRoot->IoErrorCount.agOSSA_IO_ABORTED);
1798 #endif /* DBG  */
1799 #endif /* SA_PRINTOUT_IN_WINDBG  */
1800     /* SMP failed */
1801     siAbnormal(agRoot, pRequest, status, 0, 0);
1802     break;
1803 
1804   case OSSA_IO_NO_DEVICE:
1805     SA_DBG1(("mpiSMPCompletion: OSSA_IO_NO_DEVICE HTAG = 0x%x\n", tag));
1806     saRoot->IoErrorCount.agOSSA_IO_NO_DEVICE++;
1807     siAbnormal(agRoot, pRequest, status, 0, 0);
1808     break;
1809 
1810   case OSSA_IO_ERROR_HW_TIMEOUT:
1811     SA_DBG1(("mpiSMPCompletion: OSSA_IO_ERROR_HW_TIMEOUT HTAG = 0x%x\n", tag));
1812     saRoot->IoErrorCount.agOSSA_IO_ERROR_HW_TIMEOUT++;
1813     siAbnormal(agRoot, pRequest, status, 0, 0);
1814     break;
1815 
1816   case OSSA_IO_XFER_ERROR_BREAK:
1817     SA_DBG1(("mpiSMPCompletion: OSSA_IO_XFER_ERROR_BREAK HTAG = 0x%x\n", tag));
1818     saRoot->IoErrorCount.agOSSA_IO_XFER_ERROR_BREAK++;
1819     siAbnormal(agRoot, pRequest, status, 0, 0);
1820     break;
1821 
1822   case OSSA_IO_XFER_ERROR_PHY_NOT_READY:
1823     SA_DBG1(("mpiSMPCompletion: OSSA_IO_XFER_ERROR_PHY_NOT_READY HTAG = 0x%x\n", tag));
1824     saRoot->IoErrorCount.agOSSA_IO_XFER_ERROR_PHY_NOT_READY++;
1825     siAbnormal(agRoot, pRequest, status, 0, 0);
1826     break;
1827 
1828   case OSSA_IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
1829     SA_DBG1(("mpiSMPCompletion: OSSA_IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED HTAG = 0x%x\n", tag));
1830     saRoot->IoErrorCount.agOSSA_IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED++;
1831     siAbnormal(agRoot, pRequest, status, 0, 0);
1832     break;
1833 
1834   case OSSA_IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
1835     SA_DBG1(("mpiSMPCompletion: OSSA_IO_OPEN_CNX_ERROR_ZONE_VIOLATION HTAG = 0x%x\n", tag));
1836     saRoot->IoErrorCount.agOSSA_IO_OPEN_CNX_ERROR_ZONE_VIOLATION++;
1837     siAbnormal(agRoot, pRequest, status, 0, 0);
1838     break;
1839 
1840   case OSSA_IO_OPEN_CNX_ERROR_BREAK:
1841     SA_DBG1(("mpiSMPCompletion: OSSA_IO_OPEN_CNX_ERROR_BREAK HTAG = 0x%x\n", tag));
1842     saRoot->IoErrorCount.agOSSA_IO_OPEN_CNX_ERROR_BREAK++;
1843     siAbnormal(agRoot, pRequest, status, 0, 0);
1844     break;
1845 
1846   case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
1847     SA_DBG1(("mpiSMPCompletion: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS HTAG = 0x%x\n", tag));
1848     saRoot->IoErrorCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS++;
1849     siAbnormal(agRoot, pRequest, status, 0, 0);
1850     break;
1851 
1852   case OSSA_IO_OPEN_CNX_ERROR_BAD_DESTINATION:
1853     SA_DBG1(("mpiSMPCompletion: OSSA_IO_OPEN_CNX_ERROR_BAD_DESTINATION HTAG = 0x%x\n", tag));
1854     saRoot->IoErrorCount.agOSSA_IO_OPEN_CNX_ERROR_BAD_DESTINATION++;
1855     siAbnormal(agRoot, pRequest, status, 0, 0);
1856     break;
1857 
1858   case OSSA_IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
1859     SA_DBG1(("mpiSMPCompletion: OSSA_IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED HTAG = 0x%x\n", tag));
1860     saRoot->IoErrorCount.agOSSA_IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED++;
1861     siAbnormal(agRoot, pRequest, status, 0, 0);
1862     break;
1863 
1864   case OSSA_IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
1865     SA_DBG1(("mpiSMPCompletion: OSSA_IO_OPEN_CNX_ERROR_WRONG_DESTINATION HTAG = 0x%x\n", tag));
1866     saRoot->IoErrorCount.agOSSA_IO_OPEN_CNX_ERROR_WRONG_DESTINATION++;
1867     siAbnormal(agRoot, pRequest, status, 0, 0);
1868     break;
1869 
1870   case OSSA_IO_XFER_ERROR_RX_FRAME:
1871     SA_DBG1(("mpiSMPCompletion: OSSA_IO_XFER_ERROR_RX_FRAME HTAG = 0x%x\n", tag));
1872     saRoot->IoErrorCount.agOSSA_IO_XFER_ERROR_RX_FRAME++;
1873     siAbnormal(agRoot, pRequest, status, 0, 0);
1874     break;
1875 
1876   case OSSA_IO_XFER_OPEN_RETRY_TIMEOUT:
1877     SA_DBG1(("mpiSMPCompletion: OSSA_IO_XFER_OPEN_RETRY_TIMEOUT HTAG = 0x%x\n", tag));
1878     saRoot->IoErrorCount.agOSSA_IO_XFER_OPEN_RETRY_TIMEOUT++;
1879     siAbnormal(agRoot, pRequest, status, 0, 0);
1880     break;
1881 
1882   case OSSA_IO_ERROR_INTERNAL_SMP_RESOURCE:
1883     SA_DBG1(("mpiSMPCompletion: OSSA_IO_ERROR_INTERNAL_SMP_RESOURCE HTAG = 0x%x\n", tag));
1884     saRoot->IoErrorCount.agOSSA_IO_ERROR_INTERNAL_SMP_RESOURCE++;
1885     siAbnormal(agRoot, pRequest, status, 0, 0);
1886     break;
1887 
1888   case OSSA_IO_PORT_IN_RESET:
1889     SA_DBG1(("mpiSMPCompletion: OSSA_IO_PORT_IN_RESET HTAG = 0x%x\n", tag));
1890     saRoot->IoErrorCount.agOSSA_IO_PORT_IN_RESET++;
1891     siAbnormal(agRoot, pRequest, status, 0, 0);
1892     break;
1893 
1894   case OSSA_IO_DS_NON_OPERATIONAL:
1895     SA_DBG1(("mpiSMPCompletion: OSSA_IO_DS_NON_OPERATIONAL HTAG = 0x%x\n", tag));
1896     saRoot->IoErrorCount.agOSSA_IO_DS_NON_OPERATIONAL++;
1897     siAbnormal(agRoot, pRequest, status, 0, 0);
1898     break;
1899 
1900   case OSSA_IO_DS_IN_RECOVERY:
1901     SA_DBG1(("mpiSMPCompletion: OSSA_IO_DS_IN_RECOVERY HTAG = 0x%x\n", tag));
1902     saRoot->IoErrorCount.agOSSA_IO_DS_IN_RECOVERY++;
1903     siAbnormal(agRoot, pRequest, status, 0, 0);
1904     break;
1905 
1906   case OSSA_IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY:
1907     SA_DBG1(("mpiSMPCompletion: OSSA_IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY HTAG = 0x%x\n", tag));
1908     saRoot->IoErrorCount.agOSSA_IO_OPEN_CNX_ERROR_HW_RESOURCE_BUSY++;
1909     siAbnormal(agRoot, pRequest, status, 0, 0);
1910     break;
1911 
1912   case OSSA_IO_ABORT_IN_PROGRESS:
1913     SA_DBG1(("mpiSMPCompletion: OSSA_IO_ABORT_IN_PROGRESS HTAG = 0x%x\n", tag));
1914     saRoot->IoErrorCount.agOSSA_IO_ABORT_IN_PROGRESS++;
1915     siAbnormal(agRoot, pRequest, status, 0, 0);
1916     break;
1917 
1918   case OSSA_IO_ABORT_DELAYED:
1919     SA_DBG1(("mpiSMPCompletion:OSSA_IO_ABORT_DELAYED  HTAG = 0x%x\n", tag));
1920     saRoot->IoErrorCount.agOSSA_IO_ABORT_DELAYED++;
1921     siAbnormal(agRoot, pRequest, status, 0, 0);
1922     break;
1923 
1924   case OSSA_IO_INVALID_LENGTH:
1925     SA_DBG1(("mpiSMPCompletion: OSSA_IO_INVALID_LENGTH HTAG = 0x%x\n", tag));
1926     saRoot->IoErrorCount.agOSSA_IO_INVALID_LENGTH++;
1927     siAbnormal(agRoot, pRequest, status, 0, 0);
1928     break;
1929 
1930   case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
1931     SA_DBG1(("mpiSMPCompletion: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED HTAG = 0x%x\n", tag));
1932     saRoot->IoErrorCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED++;
1933     siAbnormal(agRoot, pRequest, status, 0, 0);
1934     break;
1935 
1936   case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
1937     SA_DBG1(("mpiSMPCompletion: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO HTAG = 0x%x\n", tag));
1938     saRoot->IoErrorCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO++;
1939     siAbnormal(agRoot, pRequest, status, 0, 0);
1940     break;
1941 
1942   case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
1943     SA_DBG1(("mpiSMPCompletion: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST HTAG = 0x%x\n", tag));
1944     saRoot->IoErrorCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST++;
1945     siAbnormal(agRoot, pRequest, status, 0, 0);
1946     break;
1947 
1948   case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
1949     SA_DBG1(("mpiSMPCompletion: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE HTAG = 0x%x\n", tag));
1950     saRoot->IoErrorCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST++;
1951     siAbnormal(agRoot, pRequest, status, 0, 0);
1952     break;
1953 
1954   case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
1955     SA_DBG1(("mpiSMPCompletion: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED HTAG = 0x%x\n", tag));
1956     saRoot->IoErrorCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED++;
1957     siAbnormal(agRoot, pRequest, status, 0, 0);
1958     break;
1959 
1960   case OSSA_IO_DS_INVALID:
1961     SA_DBG1(("mpiSMPCompletion: OSSA_IO_DS_INVALID HTAG = 0x%x\n", tag));
1962     saRoot->IoErrorCount.agOSSA_IO_DS_INVALID++;
1963     siAbnormal(agRoot, pRequest, status, 0, 0);
1964     break;
1965 
1966   case OSSA_IO_XFER_READ_COMPL_ERR:
1967     SA_DBG1(("mpiSMPCompletion: OSSA_IO_XFER_READ_COMPL_ERR HTAG = 0x%x\n", tag));
1968     saRoot->IoErrorCount.agOSSA_IO_XFER_READ_COMPL_ERR++;
1969     siAbnormal(agRoot, pRequest, status, 0, 0);
1970     break;
1971 
1972   case OSSA_MPI_ERR_IO_RESOURCE_UNAVAILABLE:
1973     SA_DBG1(("mpiSMPCompletion: OSSA_MPI_ERR_IO_RESOURCE_UNAVAILABLE HTAG = 0x%x\n", tag));
1974     saRoot->IoErrorCount.agOSSA_MPI_ERR_IO_RESOURCE_UNAVAILABLE++;
1975     siAbnormal(agRoot, pRequest, status, 0, 0);
1976     break;
1977 
1978   case OSSA_MPI_ERR_OFFLOAD_DIF_OR_ENC_NOT_ENABLED:
1979     SA_DBG1(("mpiSMPCompletion: OSSA_MPI_ERR_IO_RESOURCE_UNAVAILABLE HTAG = 0x%x\n", tag));
1980     saRoot->IoErrorCount.agOSSA_MPI_ERR_OFFLOAD_DIF_OR_ENC_NOT_ENABLED++;
1981     siAbnormal(agRoot, pRequest, status, 0, 0);
1982     break;
1983 
1984   case OSSA_IO_OPEN_CNX_ERROR_OPEN_PREEMPTED:
1985     SA_DBG1(("mpiSMPCompletion: OSSA_IO_OPEN_CNX_ERROR_OPEN_PREEMPTED HTAG = 0x%x\n", tag));
1986     saRoot->IoErrorCount.agOSSA_IO_OPEN_CNX_ERROR_OPEN_PREEMPTED++;
1987     siAbnormal(agRoot, pRequest, status, 0, 0);
1988     break;
1989 
1990   default:
1991     SA_DBG1(("mpiSMPCompletion: Unknown Status = 0x%x Tag 0x%x\n", status, tag));
1992     saRoot->IoErrorCount.agOSSA_IO_UNKNOWN_ERROR++;
1993     /* not allowed case. Therefore, assert */
1994     SA_ASSERT((agFALSE), "mpiSMPCompletion: Unknown Status");
1995     break;
1996   }
1997 
1998   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2k");
1999   return ret;
2000 }
2001 
2002 /******************************************************************************/
2003 /*! \brief SPC MPI Get Device Handle Command Response
2004  *
2005  *  This function handles the response of Get Device Handle Command.
2006  *
2007  *  \param agRoot       Handles for this instance of SAS/SATA hardware
2008  *  \param pIomb        pointer of Message
2009  *  \param bc           buffer count
2010  *
2011  *  \return The read value
2012  *
2013  */
2014 /*******************************************************************************/
2015 GLOBAL bit32 mpiGetDevHandleRsp(
2016   agsaRoot_t             *agRoot,
2017   agsaGetDevHandleRsp_t  *pIomb
2018   )
2019 {
2020   bit32 ret = AGSA_RC_SUCCESS;
2021   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
2022   agsaIORequestDesc_t *pRequest;
2023   agsaPortContext_t   *agPortContext;
2024   agsaContext_t       *agContext;
2025   agsaDeviceDesc_t    *pDevice;
2026   bit8 portId;
2027   bit32 deviceid=0, deviceIdc, i;
2028   bit32 DeviceIdcPortId, tag;
2029 
2030   SA_DBG3(("mpiGetDevHandleRsp: start, HTAG=0x%x\n", pIomb->tag));
2031 
2032   smTraceFuncEnter(hpDBG_VERY_LOUD,"2m");
2033 
2034   OSSA_READ_LE_32(AGROOT, &DeviceIdcPortId, pIomb, OSSA_OFFSET_OF(agsaGetDevHandleRsp_t, DeviceIdcPortId)) ;
2035   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaGetDevHandleRsp_t, tag)) ;
2036   /* get request from IOMap */
2037   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
2038   agContext = saRoot->IOMap[tag].agContext;
2039   /* remove the request from IOMap */
2040   saRoot->IOMap[tag].Tag = MARK_OFF;
2041   saRoot->IOMap[tag].IORequest = agNULL;
2042   saRoot->IOMap[tag].agContext = agNULL;
2043   if (agNULL == pRequest)
2044   {
2045     SA_DBG1(("mpiGetDevHandleRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x DeviceIdcPortId=0x%x\n", tag, DeviceIdcPortId));
2046     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2m");
2047     return AGSA_RC_FAILURE;
2048   }
2049 
2050   /* get port context */
2051   portId = (bit8)(DeviceIdcPortId & PORTID_MASK);
2052   SA_DBG2(("mpiGetDevHandleRsp:PortID 0x%x PortStatus 0x%x PortContext %p\n",saRoot->PortMap[portId & PORTID_MASK].PortID,saRoot->PortMap[portId & PORTID_MASK].PortStatus,saRoot->PortMap[portId & PORTID_MASK].PortContext));
2053   agPortContext = (agsaPortContext_t *)saRoot->PortMap[portId].PortContext;
2054 
2055   /* get Device ID count */
2056   deviceIdc = (bit8)((DeviceIdcPortId & DEVICE_IDC_BITS) >> SHIFT8);
2057 
2058   /* based on the deviceIDC to get all device handles */
2059   for (i = 0; i < deviceIdc; i++)
2060   {
2061     OSSA_READ_LE_32(AGROOT, &deviceid, pIomb, OSSA_OFFSET_OF(agsaGetDevHandleRsp_t, deviceId[i])) ;
2062     /* find device handle from device index */
2063     pDevice = (agsaDeviceDesc_t *)saRoot->DeviceMap[deviceid & DEVICE_ID_BITS].DeviceHandle;
2064     if (pDevice->targetDevHandle.sdkData)
2065      saRoot->DeviceHandle[i] = &(pDevice->targetDevHandle);
2066     else
2067      saRoot->DeviceHandle[i] = &(pDevice->initiatorDevHandle);
2068   }
2069 
2070   SA_DBG1(("mpiGetDevHandleRsp:deviceid 0x%x  0x%x\n",deviceid, (deviceid & DEVICE_ID_BITS)));
2071   /* call back oslayer */
2072   ossaGetDeviceHandlesCB(agRoot, agContext, agPortContext, saRoot->DeviceHandle, deviceIdc);
2073 
2074   /* return the request to free pool */
2075   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2076   SA_ASSERT((pRequest->valid), "pRequest->valid");
2077   pRequest->valid = agFALSE;
2078   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
2079   {
2080     SA_DBG1(("mpiGetDevHandleRsp: saving pRequest (%p) for later use\n", pRequest));
2081     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
2082   }
2083   else
2084   {
2085     /* return the request to free pool */
2086     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
2087   }
2088   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2089 
2090   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2m");
2091 
2092   return ret;
2093 }
2094 
2095 /******************************************************************************/
2096 /*! \brief SPC MPI Phy Control Command Response
2097  *
2098  *  This function handles the response of PHY Control Command.
2099  *
2100  *  \param agRoot       Handles for this instance of SAS/SATA hardware
2101  *  \param pIomb        pointer of Message
2102  *
2103  *  \return The read value
2104  *
2105  */
2106 /*******************************************************************************/
2107 GLOBAL bit32 mpiPhyCntrlRsp(
2108   agsaRoot_t             *agRoot,
2109   agsaLocalPhyCntrlRsp_t *pIomb
2110   )
2111 {
2112   bit32               ret = AGSA_RC_SUCCESS;
2113   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
2114   agsaIORequestDesc_t *pRequest;
2115   agsaContext_t       *agContext = agNULL;
2116   bit32               phyId, operation, status, tag, phyOpId;
2117 
2118   smTraceFuncEnter(hpDBG_VERY_LOUD,"2n");
2119 
2120   SA_DBG3(("mpiPhyCntrlRsp: start, HTAG=0x%x,\n", pIomb->tag));
2121 
2122   /* get tag */
2123   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaLocalPhyCntrlRsp_t, tag)) ;
2124   OSSA_READ_LE_32(AGROOT, &phyOpId, pIomb, OSSA_OFFSET_OF(agsaLocalPhyCntrlRsp_t, phyOpId)) ;
2125   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaLocalPhyCntrlRsp_t, status)) ;
2126   /* get request from IOMap */
2127   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
2128   if (agNULL == pRequest)
2129   {
2130     SA_DBG1(("mpiPhyCntrlRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x PhyOpId=0x%x\n", tag, status, phyOpId));
2131     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2n");
2132     return AGSA_RC_FAILURE;
2133   }
2134   agContext = saRoot->IOMap[tag].agContext;
2135   /* remove the request from IOMap */
2136   saRoot->IOMap[tag].Tag = MARK_OFF;
2137   saRoot->IOMap[tag].IORequest = agNULL;
2138   saRoot->IOMap[tag].agContext = agNULL;
2139 
2140   phyId = phyOpId & LOCAL_PHY_PHYID;
2141   operation = (phyOpId & LOCAL_PHY_OP_BITS) >> SHIFT8;
2142 
2143 
2144   SA_DBG3(("mpiPhyCntrlRsp: phyId=0x%x Operation=0x%x Status=0x%x\n", phyId, operation, status));
2145 
2146   if( pRequest->completionCB == agNULL )
2147   {
2148     /* call back with the status */
2149     ossaLocalPhyControlCB(agRoot, agContext, phyId, operation, status, agNULL);
2150   }
2151   else
2152   {
2153     (*(ossaLocalPhyControlCB_t)(pRequest->completionCB))(agRoot, agContext, phyId, operation, status, agNULL );
2154   }
2155 
2156   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2157   SA_ASSERT((pRequest->valid), "pRequest->valid");
2158   pRequest->valid = agFALSE;
2159   /* return the request to free pool */
2160   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
2161   {
2162     SA_DBG1(("mpiPhyCntrlRsp: saving pRequest (%p) for later use\n", pRequest));
2163     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
2164   }
2165   else
2166   {
2167     /* return the request to free pool */
2168     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
2169   }
2170   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2171 
2172   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2n");
2173   return ret;
2174 }
2175 
2176 /******************************************************************************/
2177 /*! \brief SPC MPI Device Register Command Response
2178  *
2179  *  This function handles the response of Device Register Command.
2180  *
2181  *  \param agRoot       Handles for this instance of SAS/SATA hardware
2182  *  \param pIomb        pointer of Message
2183  *
2184  *  \return The read value
2185  *
2186  */
2187 /*******************************************************************************/
2188 GLOBAL bit32 mpiDeviceRegRsp(
2189   agsaRoot_t    *agRoot,
2190   agsaDeviceRegistrationRsp_t *pIomb
2191   )
2192 {
2193   bit32               ret = AGSA_RC_SUCCESS;
2194   agsaLLRoot_t        *saRoot = agNULL;
2195   agsaIORequestDesc_t *pRequest;
2196   agsaContext_t       *agContext;
2197   bit32               deviceId;
2198   agsaDeviceDesc_t    *pDevice = agNULL;
2199   agsaDeviceDesc_t    *pDeviceRemove = agNULL;
2200   bit32               deviceIdx,status, tag;
2201 
2202   smTraceFuncEnter(hpDBG_VERY_LOUD,"2p");
2203 
2204   /* sanity check */
2205   SA_ASSERT((agNULL != agRoot), "");
2206   saRoot = (agsaLLRoot_t *) (agRoot->sdkData);
2207   SA_ASSERT((agNULL != saRoot), "");
2208 
2209   SA_DBG3(("mpiDeviceRegRsp: start, HTAG=0x%x\n", pIomb->tag));
2210 
2211   SA_ASSERT((NULL != saRoot->DeviceRegistrationCB), "DeviceRegistrationCB can not be NULL");
2212   OSSA_READ_LE_32(AGROOT, &deviceId, pIomb, OSSA_OFFSET_OF(agsaDeviceRegistrationRsp_t, deviceId)) ;
2213   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaDeviceRegistrationRsp_t, tag)) ;
2214   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaDeviceRegistrationRsp_t, status)) ;
2215 
2216   SA_DBG1(("mpiDeviceRegRsp: deviceID 0x%x \n", deviceId));
2217 
2218   /* get request from IOMap */
2219   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
2220   if (agNULL == pRequest)
2221   {
2222     SA_DBG1(("mpiDeviceRegRsp: Bad IOMB!!! pRequest is NULL. TAG=0x%x, STATUS=0x%x DEVICEID=0x%x\n", tag, status, deviceId));
2223     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2p");
2224     return AGSA_RC_FAILURE;
2225   }
2226 
2227   pDevice = pRequest->pDevice;
2228 
2229   agContext = saRoot->IOMap[tag].agContext;
2230   SA_ASSERT((pRequest->valid), "pRequest->valid");
2231   /* remove the request from IOMap */
2232   saRoot->IOMap[tag].Tag = MARK_OFF;
2233   saRoot->IOMap[tag].IORequest = agNULL;
2234   saRoot->IOMap[tag].agContext = agNULL;
2235 
2236   /* get Device Id or status */
2237   SA_DBG3(("mpiDeviceRegRsp: hosttag 0x%x\n", tag));
2238   SA_DBG3(("mpiDeviceRegRsp: deviceID 0x%x Device Context %p\n", deviceId, pDevice));
2239 
2240   if (agNULL == pDevice)
2241   {
2242     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2243     pRequest->valid = agFALSE;
2244     /* return the request to free pool */
2245     if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
2246     {
2247       SA_DBG1(("mpiDeviceRegRsp: saving pRequest (%p) for later use\n", pRequest));
2248       saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
2249     }
2250     else
2251     {
2252       /* return the request to free pool */
2253       saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
2254     }
2255     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2256 
2257     SA_DBG1(("mpiDeviceRegRsp: warning!!! no device is found\n"));
2258     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2p");
2259     return AGSA_RC_FAILURE;
2260   }
2261 
2262   if (agNULL == saRoot->DeviceRegistrationCB)
2263   {
2264     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2265     pRequest->valid = agFALSE;
2266     /* return the request to free pool */
2267     if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
2268     {
2269       SA_DBG1(("mpiDeviceRegRsp: saving pRequest (%p) for later use\n", pRequest));
2270       saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
2271     }
2272     else
2273     {
2274       /* return the request to free pool */
2275       saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
2276     }
2277     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2278 
2279     SA_DBG1(("mpiDeviceRegRsp: warning!!! no DeviceRegistrationCB is found\n"));
2280     smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "2p");
2281     return AGSA_RC_FAILURE;
2282   }
2283 
2284 
2285   if(smIS_SPCV(agRoot))
2286   {
2287     switch( status)
2288     {
2289       case 0:
2290           status = OSSA_SUCCESS;
2291           break;
2292       case MPI_ERR_DEVICE_HANDLE_UNAVAILABLE:
2293           status = OSSA_FAILURE_OUT_OF_RESOURCE;
2294           break;
2295       case MPI_ERR_DEVICE_ALREADY_REGISTERED:
2296           status = OSSA_FAILURE_DEVICE_ALREADY_REGISTERED;
2297           break;
2298       case MPI_ERR_PHY_ID_INVALID:
2299           status = OSSA_FAILURE_INVALID_PHY_ID;
2300           break;
2301       case MPI_ERR_PHY_ID_ALREADY_REGISTERED:
2302           status = OSSA_FAILURE_PHY_ID_ALREADY_REGISTERED;
2303           break;
2304       case MPI_ERR_PORT_INVALID_PORT_ID:
2305           status = OSSA_FAILURE_PORT_ID_OUT_OF_RANGE;
2306           break;
2307       case MPI_ERR_PORT_STATE_NOT_VALID:
2308           status = OSSA_FAILURE_PORT_NOT_VALID_STATE;
2309           break;
2310       case MPI_ERR_DEVICE_TYPE_NOT_VALID:
2311           status = OSSA_FAILURE_DEVICE_TYPE_NOT_VALID;
2312           break;
2313       default:
2314         SA_ASSERT((0), "DeviceRegistration Unknown status");
2315         ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2316         pRequest->valid = agFALSE;
2317         /* return the request to free pool */
2318         if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
2319         {
2320           SA_DBG1(("mpiDeviceRegRsp: saving pRequest (%p) for later use\n", pRequest));
2321           saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
2322         }
2323         else
2324         {
2325           /* return the request to free pool */
2326           saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
2327         }
2328         ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2329 
2330         return AGSA_RC_FAILURE;
2331     }
2332   }
2333 
2334   switch (status)
2335   {
2336   case OSSA_SUCCESS:
2337     /* mapping the device handle and device id */
2338     deviceIdx = deviceId & DEVICE_ID_BITS;
2339     OS_ASSERT(deviceIdx < MAX_IO_DEVICE_ENTRIES, "deviceIdx MAX_IO_DEVICE_ENTRIES");
2340     saRoot->DeviceMap[deviceIdx].DeviceIdFromFW = deviceId;
2341     saRoot->DeviceMap[deviceIdx].DeviceHandle = (void *)pDevice;
2342     pDevice->DeviceMapIndex = deviceId;
2343 
2344     (*(ossaDeviceRegistrationCB_t)(saRoot->DeviceRegistrationCB))(agRoot,
2345                                                                   agContext,
2346                                                                   OSSA_SUCCESS,
2347                                                                   &pDevice->targetDevHandle,
2348                                                                   deviceId
2349                                                                   );
2350 
2351     break;
2352   case OSSA_FAILURE_OUT_OF_RESOURCE:
2353     SA_DBG1(("mpiDeviceRegRsp: OSSA_FAILURE_OUT_OF_RESOURCE\n"));
2354     /* remove device from LL device list */
2355     siPortDeviceRemove(agRoot, pDevice->pPort, pDevice, agFALSE);
2356 
2357     /* call ossaDeviceRegistrationCB_t */
2358     (*(ossaDeviceRegistrationCB_t)(saRoot->DeviceRegistrationCB))(agRoot,
2359                                                                   agContext,
2360                                                                   OSSA_FAILURE_OUT_OF_RESOURCE,
2361                                                                   &pDevice->targetDevHandle,
2362                                                                   deviceId
2363                                                                   );
2364 
2365 
2366     break;
2367   case OSSA_FAILURE_DEVICE_ALREADY_REGISTERED:
2368     /* get original device handle and device id */
2369     pDeviceRemove = pDevice;
2370     deviceIdx = deviceId & DEVICE_ID_BITS;
2371     OS_ASSERT(deviceIdx < MAX_IO_DEVICE_ENTRIES, "deviceIdx MAX_IO_DEVICE_ENTRIES");
2372     pDevice = (agsaDeviceDesc_t *)saRoot->DeviceMap[deviceIdx].DeviceHandle;
2373     SA_DBG1(("mpiDeviceRegRsp: OSSA_FAILURE_DEVICE_ALREADY_REGISTERED, existing deviceContext %p\n", pDevice));
2374     /* no auto registration */
2375     if (pDevice != agNULL)
2376     {
2377       /* remove device from LL device list */
2378       siPortDeviceListRemove(agRoot, pDevice->pPort, pDeviceRemove);
2379 
2380       /* call ossaDeviceRegistrationCB_t */
2381       (*(ossaDeviceRegistrationCB_t)(saRoot->DeviceRegistrationCB))(agRoot,
2382                                                                     agContext,
2383                                                                     OSSA_FAILURE_DEVICE_ALREADY_REGISTERED,
2384                                                                     &pDevice->targetDevHandle,
2385                                                                     deviceId
2386                                                                     );
2387     }
2388     else
2389     {
2390       SA_DBG1(("mpiDeviceRegRsp: pDevice is NULL. TAG=0x%x, STATUS=0x%x DEVICEID=0x%x\n", tag, status, deviceId));
2391       smTraceFuncExit(hpDBG_VERY_LOUD, 'd', "2p");
2392       return AGSA_RC_FAILURE;
2393     }
2394 
2395     break;
2396   case OSSA_FAILURE_INVALID_PHY_ID:
2397     SA_DBG1(("mpiDeviceRegRsp: OSSA_FAILURE_INVALID_PHY_ID\n"));
2398     /* remove device from LL device list */
2399     siPortDeviceRemove(agRoot, pDevice->pPort, pDevice, agFALSE);
2400 
2401     /* call ossaDeviceRegistrationCB_t */
2402     (*(ossaDeviceRegistrationCB_t)(saRoot->DeviceRegistrationCB))(agRoot,
2403                                                                   agContext,
2404                                                                   OSSA_FAILURE_INVALID_PHY_ID,
2405                                                                   &pDevice->targetDevHandle,
2406                                                                   deviceId
2407                                                                   );
2408     break;
2409   case OSSA_FAILURE_PHY_ID_ALREADY_REGISTERED:
2410     /* get original device handle and device id */
2411     pDeviceRemove = pDevice;
2412     deviceIdx = deviceId & DEVICE_ID_BITS;
2413     OS_ASSERT(deviceIdx < MAX_IO_DEVICE_ENTRIES, "deviceIdx MAX_IO_DEVICE_ENTRIES");
2414     pDevice = (agsaDeviceDesc_t *)saRoot->DeviceMap[deviceIdx].DeviceHandle;
2415     SA_DBG1(("mpiDeviceRegRsp: OSSA_FAILURE_PHY_ID_ALREADY_REGISTERED, existing deviceContext %p\n", pDevice));
2416     /* no auto registration */
2417     if (pDevice != agNULL)
2418     {
2419       /* remove device from LL device list */
2420       siPortDeviceListRemove(agRoot, pDevice->pPort, pDeviceRemove);
2421 
2422       /* call ossaDeviceRegistrationCB_t */
2423       (*(ossaDeviceRegistrationCB_t)(saRoot->DeviceRegistrationCB))(agRoot,
2424                                                                     agContext,
2425                                                                     OSSA_FAILURE_PHY_ID_ALREADY_REGISTERED,
2426                                                                     &pDevice->targetDevHandle,
2427                                                                     deviceId
2428                                                                     );
2429     }
2430     else
2431     {
2432       SA_DBG1(("mpiDeviceRegRsp: pDevice is NULL. TAG=0x%x, STATUS=0x%x DEVICEID=0x%x\n", tag, status, deviceId));
2433       smTraceFuncExit(hpDBG_VERY_LOUD, 'e', "2p");
2434       return AGSA_RC_FAILURE;
2435     }
2436 
2437     break;
2438   case OSSA_FAILURE_PORT_ID_OUT_OF_RANGE:
2439     SA_DBG1(("mpiDeviceRegRsp: OSSA_FAILURE_OUT_OF_RESOURCE\n"));
2440     /* remove device from LL device list */
2441     siPortDeviceRemove(agRoot, pDevice->pPort, pDevice, agFALSE);
2442 
2443     /* call ossaDeviceRegistrationCB_t */
2444     (*(ossaDeviceRegistrationCB_t)(saRoot->DeviceRegistrationCB))(agRoot,
2445                                                                   agContext,
2446                                                                   OSSA_FAILURE_PORT_ID_OUT_OF_RANGE,
2447                                                                   &pDevice->targetDevHandle,
2448                                                                   deviceId
2449                                                                   );
2450     break;
2451   case OSSA_FAILURE_PORT_NOT_VALID_STATE:
2452     SA_DBG1(("mpiDeviceRegRsp: OSSA_FAILURE_PORT_NOT_VALID_STATE\n"));
2453     /* remove device from LL device list */
2454     siPortDeviceRemove(agRoot, pDevice->pPort, pDevice, agFALSE);
2455 
2456     /* call ossaDeviceRegistrationCB_t */
2457     (*(ossaDeviceRegistrationCB_t)(saRoot->DeviceRegistrationCB))(agRoot,
2458                                                                   agContext,
2459                                                                   OSSA_FAILURE_PORT_NOT_VALID_STATE,
2460                                                                   &pDevice->targetDevHandle,
2461                                                                   deviceId
2462                                                                   );
2463     break;
2464   case OSSA_FAILURE_DEVICE_TYPE_NOT_VALID:
2465     SA_DBG1(("mpiDeviceRegRsp: OSSA_FAILURE_DEVICE_TYPE_NOT_VALID\n"));
2466     /* remove device from LL device list */
2467     siPortDeviceRemove(agRoot, pDevice->pPort, pDevice, agFALSE);
2468     /* call ossaDeviceRegistrationCB_t */
2469     (*(ossaDeviceRegistrationCB_t)(saRoot->DeviceRegistrationCB))(agRoot,
2470                                                                   agContext,
2471                                                                   OSSA_FAILURE_DEVICE_TYPE_NOT_VALID,
2472                                                                   &pDevice->targetDevHandle,
2473                                                                   deviceId
2474                                                                   );
2475     break;
2476   default:
2477     SA_DBG3(("mpiDeviceRegRsp, unknown status in response %d\n", status));
2478     break;
2479   }
2480 
2481   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2482   pRequest->valid = agFALSE;
2483   /* return the request to free pool */
2484   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
2485   {
2486     SA_DBG1(("mpiDeviceRegRsp: saving pRequest (%p) for later use\n", pRequest));
2487     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
2488   }
2489   else
2490   {
2491     /* return the request to free pool */
2492     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
2493   }
2494   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2495 
2496   smTraceFuncExit(hpDBG_VERY_LOUD, 'f', "2p");
2497   return ret;
2498 }
2499 
2500 /******************************************************************************/
2501 /*! \brief SPC MPI Deregister Device Command Response
2502  *
2503  *  This function handles the response of Deregister Command.
2504  *
2505  *  \param agRoot       Handles for this instance of SAS/SATA hardware
2506  *  \param pIomb        pointer of Message
2507  *
2508  *  \return The read value
2509  *
2510  */
2511 /*******************************************************************************/
2512 GLOBAL bit32 mpiDeregDevHandleRsp(
2513   agsaRoot_t              *agRoot,
2514   agsaDeregDevHandleRsp_t *pIomb
2515   )
2516 {
2517   bit32               ret = AGSA_RC_SUCCESS;
2518   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
2519   agsaIORequestDesc_t *pRequest;
2520   agsaDevHandle_t     *agDevHandle;
2521   agsaContext_t       *agContext;
2522   agsaDeviceDesc_t    *pDevice;
2523   bit32               deviceIdx, status, tag;
2524 
2525   smTraceFuncEnter(hpDBG_VERY_LOUD,"2r");
2526   SA_ASSERT((NULL != saRoot->DeviceDeregistrationCB), "DeviceDeregistrationCB can not be NULL");
2527 
2528   SA_DBG3(("mpiDeregDevHandleRsp: start, HTAG=0x%x\n", pIomb->tag));
2529 
2530   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaDeregDevHandleRsp_t, tag)) ;
2531   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaDeregDevHandleRsp_t, status)) ;
2532   OSSA_READ_LE_32(AGROOT, &deviceIdx, pIomb, OSSA_OFFSET_OF(agsaDeregDevHandleRsp_t, deviceId)) ;
2533   /* get request from IOMap */
2534 
2535   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
2536   if (agNULL == pRequest)
2537   {
2538     SA_DBG1(("mpiDeregDevHandleRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x deviceIdx 0x%x\n", tag, status,deviceIdx));
2539     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2r");
2540     return AGSA_RC_FAILURE;
2541   }
2542 
2543   agContext = saRoot->IOMap[tag].agContext;
2544   /* remove the request from IOMap */
2545   saRoot->IOMap[tag].Tag = MARK_OFF;
2546   saRoot->IOMap[tag].IORequest = agNULL;
2547   saRoot->IOMap[tag].agContext = agNULL;
2548 
2549   SA_ASSERT((pRequest->valid), "pRequest->valid");
2550 
2551   pDevice = pRequest->pDevice;
2552   if (pDevice != agNULL)
2553   {
2554     if (pDevice->targetDevHandle.sdkData)
2555     {
2556       agDevHandle = &(pDevice->targetDevHandle);
2557     }
2558     else
2559     {
2560       agDevHandle = &(pDevice->initiatorDevHandle);
2561     }
2562   }
2563   else
2564   {
2565     SA_DBG1(("mpiDeregDevHandleRsp: pDevice is NULL"));
2566     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2r");
2567     return AGSA_RC_FAILURE;
2568   }
2569 
2570   if (agNULL == agDevHandle)
2571   {
2572     SA_DBG1(("mpiDeregDevHandleRsp: warning!!! no deviceHandle is found"));
2573     smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "2r");
2574 
2575     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2576     pRequest->valid = agFALSE;
2577     /* return the request to free pool */
2578     if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
2579     {
2580       SA_DBG1(("mpiDeregDevHandleRsp: saving pRequest (%p) for later use\n", pRequest));
2581       saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
2582     }
2583     else
2584     {
2585       /* return the request to free pool */
2586       saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
2587     }
2588     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2589 
2590     return AGSA_RC_FAILURE;
2591   }
2592 
2593   SA_DBG1(("mpiDeregDevHandleRsp: deviceID 0x%x Device Context %p\n", pDevice->DeviceMapIndex, pDevice));
2594 
2595   if (agNULL == saRoot->DeviceDeregistrationCB)
2596   {
2597     SA_DBG1(("mpiDeregDevHandleRsp: warning!!! no DeviceDeregistrationCB is found"));
2598     smTraceFuncExit(hpDBG_VERY_LOUD, 'd', "2r");
2599 
2600     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2601     pRequest->valid = agFALSE;
2602     /* return the request to free pool */
2603     if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
2604     {
2605       SA_DBG1(("mpiDeregDevHandleRsp: saving pRequest (%p) for later use\n", pRequest));
2606       saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
2607     }
2608     else
2609     {
2610       /* return the request to free pool */
2611       saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
2612     }
2613     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2614 
2615     return AGSA_RC_FAILURE;
2616   }
2617 
2618   switch (status)
2619   {
2620     case OSSA_SUCCESS:
2621      (*(ossaDeregisterDeviceHandleCB_t)(saRoot->DeviceDeregistrationCB))(agRoot,
2622                                                                 agContext,
2623                                                                 agDevHandle,
2624                                                                 OSSA_SUCCESS
2625                                                                 );
2626       siRemoveDevHandle(agRoot, agDevHandle);
2627       break;
2628     case OSSA_ERR_DEVICE_HANDLE_INVALID:
2629     case OSSA_INVALID_HANDLE:
2630       (*(ossaDeregisterDeviceHandleCB_t)(saRoot->DeviceDeregistrationCB))(agRoot,
2631                                                                 agContext,
2632                                                                 agDevHandle,
2633                                                                 status
2634                                                                 );
2635 // already removed and no device to remove
2636 //      siRemoveDevHandle(agRoot, agDevHandle);
2637       SA_DBG1(("mpiDeregDevRegRsp, OSSA_INVALID_HANDLE status in response %d\n", status));
2638       break;
2639     case OSSA_ERR_DEVICE_BUSY:
2640       (*(ossaDeregisterDeviceHandleCB_t)(saRoot->DeviceDeregistrationCB))(agRoot,
2641                                                                 agContext,
2642                                                                 agDevHandle,
2643                                                                 status
2644                                                                 );
2645       SA_DBG1(("mpiDeregDevRegRsp, OSSA_ERR_DEVICE_BUSY status in response %d\n", status));
2646       ret = AGSA_RC_BUSY;
2647       break;
2648     default:
2649       SA_DBG1(("mpiDeregDevRegRsp, unknown status in response 0x%X\n", status));
2650       break;
2651   }
2652 
2653   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2654   pRequest->valid = agFALSE;
2655   /* return the request to free pool */
2656   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
2657   {
2658     SA_DBG1(("mpiDeregDevHandleRsp: saving pRequest (%p) for later use\n", pRequest));
2659     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
2660   }
2661   else
2662   {
2663     /* return the request to free pool */
2664     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
2665   }
2666   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2667 
2668   smTraceFuncExit(hpDBG_VERY_LOUD, 'e', "2r");
2669   return ret;
2670 }
2671 
2672 
2673 /******************************************************************************/
2674 /*! \brief Get Phy Profile Response SPCv
2675  *
2676  *  This routine handles the response of Get Phy Profile Command Response
2677  *
2678  *  \param agRoot       Handles for this instance of SAS/SATA LLL
2679  *  \param pIomb        Pointer of IOMB Message
2680  *
2681  *  \return sucess or fail
2682  *  SPC  only
2683  */
2684 /*******************************************************************************/
2685 
2686 GLOBAL bit32 mpiGetPhyProfileRsp(
2687   agsaRoot_t             *agRoot,
2688   agsaGetPhyProfileRspV_t *pIomb
2689   )
2690 {
2691   bit32               ret = AGSA_RC_SUCCESS;
2692   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
2693   agsaIORequestDesc_t *pRequest;
2694   agsaContext_t       *agContext;
2695   bit32              status, tag;
2696 
2697   bit32          Reserved_SOP_PHYID;
2698   bit32          PhyId;
2699   bit32          SOP;
2700 
2701   smTraceFuncEnter(hpDBG_VERY_LOUD,"2J");
2702   OSSA_READ_LE_32(agRoot, &status, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t, status));
2703   OSSA_READ_LE_32(agRoot, &tag, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t, tag));
2704   /* get TAG */
2705   SA_DBG1(("mpiGetPhyProfileRsp: HTag=0x%x\n", tag));
2706 
2707   /* get request from IOMap */
2708   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
2709   if (agNULL == pRequest)
2710   {
2711     SA_DBG1(("mpiGetPhyProfileRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
2712     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2J");
2713     return AGSA_RC_FAILURE;
2714   }
2715 
2716   agContext = saRoot->IOMap[tag].agContext;
2717 
2718   OSSA_READ_LE_32(agRoot, &Reserved_SOP_PHYID, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,Reserved_Ppc_SOP_PHYID ));
2719 
2720   /* remove the request from IOMap */
2721   saRoot->IOMap[tag].Tag = MARK_OFF;
2722   saRoot->IOMap[tag].IORequest = agNULL;
2723   saRoot->IOMap[tag].agContext = agNULL;
2724 
2725   SA_ASSERT((pRequest->valid), "pRequest->valid");
2726   SA_DBG1(("mpiGetPhyProfileRsp:   %p\n",pIomb));
2727   SA_DBG1(("mpiGetPhyProfileRsp: completionCB %p\n",pRequest->completionCB ));
2728 
2729   SOP = (Reserved_SOP_PHYID & 0xFF00) >> SHIFT8;
2730   PhyId = Reserved_SOP_PHYID & 0xFF;
2731 
2732   /* check status success or failure */
2733   if (status)
2734   {
2735     /* status is FAILED */
2736     SA_DBG1(("mpiGetPhyProfileRsp:AGSA_RC_FAILURE  0x%08X\n", status));
2737     switch(SOP)
2738     {
2739       case AGSA_SAS_PHY_ERR_COUNTERS_PAGE:
2740       {
2741         SA_DBG1(("mpiGetPhyProfileRsp: AGSA_SAS_PHY_ERR_COUNTERS_PAGE SOP 0x%x\n", SOP));
2742         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId , agNULL );
2743         break;
2744       }
2745       case AGSA_SAS_PHY_ERR_COUNTERS_CLR_PAGE:
2746       {
2747         SA_DBG1(("mpiGetPhyProfileRsp: AGSA_SAS_PHY_ERR_COUNTERS_CLR_PAGE SOP 0x%x\n", SOP));
2748         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId , agNULL );
2749         break;
2750       }
2751       case AGSA_SAS_PHY_BW_COUNTERS_PAGE:
2752       {
2753         SA_DBG1(("mpiGetPhyProfileRsp: GET_SAS_PHY_BW_COUNTERS SOP 0x%x\n", SOP));
2754         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId , agNULL );
2755         break;
2756       }
2757       case AGSA_SAS_PHY_ANALOG_SETTINGS_PAGE:
2758       {
2759         SA_DBG1(("mpiGetPhyProfileRsp: AGSA_SAS_PHY_ANALOG_SETTINGS_PAGE SOP 0x%x\n", SOP));
2760         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId , agNULL );
2761         break;
2762       }
2763       case AGSA_SAS_PHY_GENERAL_STATUS_PAGE:
2764       {
2765         SA_DBG1(("mpiGetPhyProfileRsp: AGSA_SAS_PHY_GENERAL_STATUS_PAGE SOP 0x%x\n", SOP));
2766         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId , agNULL );
2767         break;
2768       }
2769       case AGSA_PHY_SNW3_PAGE:
2770       {
2771         SA_DBG1(("mpiGetPhyProfileRsp: AGSA_PHY_SNW3_PAGE SOP 0x%x\n", SOP));
2772         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId , agNULL );
2773         break;
2774       }
2775       case AGSA_PHY_RATE_CONTROL_PAGE:
2776       {
2777         SA_DBG1(("mpiGetPhyProfileRsp: AGSA_PHY_RATE_CONTROL_PAGE SOP 0x%x\n", SOP));
2778         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId , agNULL );
2779         break;
2780       }
2781       case AGSA_SAS_PHY_OPEN_REJECT_RETRY_BACKOFF_THRESHOLD_PAGE:
2782       {
2783         SA_DBG1(("mpiGetPhyProfileRsp: AGSA_SAS_PHY_OPEN_REJECT_RETRY_BACKOFF_THRESHOLD_PAGE SOP 0x%x\n", SOP));
2784         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId , agNULL );
2785         break;
2786       }
2787       default:
2788       {
2789         SA_DBG1(("mpiGetPhyProfileRsp: undefined SOP 0x%x\n", SOP));
2790         break;
2791       }
2792     }
2793     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2J");
2794     return AGSA_RC_FAILURE;
2795   }
2796   else
2797   {
2798     SA_DBG1(("mpiGetPhyProfileRsp: SUCCESS type 0x%X\n",SOP ));
2799     switch(SOP)
2800     {
2801       case AGSA_SAS_PHY_ERR_COUNTERS_CLR_PAGE:
2802         /* call back with the status */
2803         SA_DBG1(("mpiGetPhyProfileRsp: AGSA_SAS_PHY_ERR_COUNTERS_CLR_PAGE PhyId %d\n",PhyId));
2804         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId , agNULL);
2805         break;
2806       case AGSA_SAS_PHY_ERR_COUNTERS_PAGE:
2807       {
2808 
2809         agsaPhyErrCountersPage_t Errors;
2810 
2811         OSSA_READ_LE_32(agRoot, &Errors.invalidDword,          pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[0] ));
2812         OSSA_READ_LE_32(agRoot, &Errors.runningDisparityError, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[1] ));
2813         OSSA_READ_LE_32(agRoot, &Errors.codeViolation,         pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[2] ));
2814         OSSA_READ_LE_32(agRoot, &Errors.lossOfDwordSynch,      pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[3] ));
2815         OSSA_READ_LE_32(agRoot, &Errors.phyResetProblem,       pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[4] ));
2816         OSSA_READ_LE_32(agRoot, &Errors.inboundCRCError,       pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[5] ));
2817 
2818         /* call back with the status */
2819         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId , &Errors);
2820         /* status is SUCCESS */
2821 
2822         SA_DBG3(("mpiGetPhyProfileRsp: pIomb %p\n",pIomb));
2823         SA_DBG1(("mpiGetPhyProfileRsp: Reserved_SOP_PHYID    0x%08X\n",Reserved_SOP_PHYID));
2824         SA_DBG1(("mpiGetPhyProfileRsp: invalidDword          0x%08X\n",Errors.invalidDword ));
2825         SA_DBG1(("mpiGetPhyProfileRsp: runningDisparityError 0x%08X\n",Errors.runningDisparityError ));
2826         SA_DBG1(("mpiGetPhyProfileRsp: codeViolation         0x%08X\n",Errors.codeViolation ));
2827         SA_DBG1(("mpiGetPhyProfileRsp: lossOfDwordSynch      0x%08X\n",Errors.lossOfDwordSynch ));
2828         SA_DBG1(("mpiGetPhyProfileRsp: phyResetProblem       0x%08X\n",Errors.phyResetProblem ));
2829         SA_DBG1(("mpiGetPhyProfileRsp: inboundCRCError       0x%08X\n",Errors.inboundCRCError ));
2830         break;
2831 
2832       }
2833       case AGSA_SAS_PHY_BW_COUNTERS_PAGE:
2834       {
2835 
2836         agsaPhyBWCountersPage_t  bw_counts;
2837         OSSA_READ_LE_32(agRoot, &bw_counts.TXBWCounter, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[0] ));
2838         OSSA_READ_LE_32(agRoot, &bw_counts.RXBWCounter, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[1] ));
2839 
2840         SA_DBG1(("mpiGetPhyProfileRsp: GET_SAS_PHY_BW_COUNTERS TX 0x%08X RX 0x%08X\n",bw_counts.TXBWCounter,bw_counts.RXBWCounter));
2841         /* call back with the status */
2842         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId, &bw_counts);
2843         break;
2844       }
2845       case AGSA_SAS_PHY_ANALOG_SETTINGS_PAGE:
2846       {
2847         agsaPhyAnalogSettingsPage_t analog;
2848 
2849         SA_DBG1(("mpiGetPhyProfileRsp: AGSA_SAS_PHY_ANALOG_SETTINGS_PAGE 0x%X\n",SOP));
2850         OSSA_READ_LE_32(agRoot, &analog.Dword0, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[0] ));
2851         OSSA_READ_LE_32(agRoot, &analog.Dword1, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[1] ));
2852         OSSA_READ_LE_32(agRoot, &analog.Dword2, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[2] ));
2853         OSSA_READ_LE_32(agRoot, &analog.Dword3, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[3] ));
2854         OSSA_READ_LE_32(agRoot, &analog.Dword4, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[4] ));
2855           /* call back with the status */
2856         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId, &analog);
2857         break;
2858       }
2859 
2860       case AGSA_SAS_PHY_GENERAL_STATUS_PAGE:
2861       {
2862         agsaSASPhyGeneralStatusPage_t GenStatus;
2863         OSSA_READ_LE_32(agRoot, &GenStatus.Dword0, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[0] ));
2864         OSSA_READ_LE_32(agRoot, &GenStatus.Dword1, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[1] ));
2865         SA_DBG1(("mpiGetPhyProfileRsp: AGSA_SAS_PHY_GENERAL_STATUS_PAGE SOP 0x%x 0x%x 0x%x\n", SOP,GenStatus.Dword0,GenStatus.Dword1));
2866         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId , &GenStatus );
2867         break;
2868       }
2869       case AGSA_PHY_SNW3_PAGE:
2870       {
2871         agsaPhySNW3Page_t Snw3;
2872         OSSA_READ_LE_32(agRoot, &Snw3.LSNW3, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[0] ));
2873         OSSA_READ_LE_32(agRoot, &Snw3.RSNW3, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[1] ));
2874 
2875         SA_DBG1(("mpiGetPhyProfileRsp: AGSA_PHY_SNW3_PAGE SOP 0x%x\n", SOP));
2876         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId , &Snw3 );
2877         break;
2878       }
2879       case AGSA_PHY_RATE_CONTROL_PAGE:
2880       {
2881         agsaPhyRateControlPage_t RateControl;
2882         OSSA_READ_LE_32(agRoot, &RateControl.Dword0, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[0] ));
2883         OSSA_READ_LE_32(agRoot, &RateControl.Dword1, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[1] ));
2884         OSSA_READ_LE_32(agRoot, &RateControl.Dword2, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[2] ));
2885         SA_DBG1(("mpiGetPhyProfileRsp: AGSA_PHY_RATE_CONTROL_PAGE SOP 0x%x\n", SOP));
2886         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId , &RateControl );
2887         break;
2888       }
2889       case AGSA_SAS_PHY_OPEN_REJECT_RETRY_BACKOFF_THRESHOLD_PAGE:
2890       {
2891         agsaSASPhyOpenRejectRetryBackOffThresholdPage_t Backoff;
2892         OSSA_READ_LE_32(agRoot, &Backoff.Dword0, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[0] ));
2893         OSSA_READ_LE_32(agRoot, &Backoff.Dword1, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[1] ));
2894         OSSA_READ_LE_32(agRoot, &Backoff.Dword2, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[2] ));
2895         OSSA_READ_LE_32(agRoot, &Backoff.Dword3, pIomb, OSSA_OFFSET_OF(agsaGetPhyProfileRspV_t,PageSpecificArea[3] ));
2896         SA_DBG1(("mpiGetPhyProfileRsp: AGSA_SAS_PHY_OPEN_REJECT_RETRY_BACKOFF_THRESHOLD_PAGE SOP 0x%x\n", SOP));
2897         ossaGetPhyProfileCB(agRoot, agContext, status, SOP, PhyId , &Backoff );
2898         break;
2899       }
2900       default:
2901       {
2902         SA_DBG1(("mpiGetPhyProfileRsp: undefined successful SOP 0x%x\n", SOP));
2903         break;
2904       }
2905 
2906     }
2907   }
2908 
2909   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2910   pRequest->valid = agFALSE;
2911   /* return the request to free pool */
2912   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
2913   {
2914     SA_DBG1(("mpiGetPhyProfileRsp: saving pRequest (%p) for later use\n", pRequest));
2915     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
2916   }
2917   else
2918   {
2919     /* return the request to free pool */
2920     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
2921   }
2922   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
2923 
2924   /* return value */
2925   smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "2J");
2926   return ret;
2927 }
2928 
2929 
2930 GLOBAL bit32 mpiSetPhyProfileRsp(
2931   agsaRoot_t             *agRoot,
2932   agsaSetPhyProfileRspV_t *pIomb
2933   )
2934 {
2935   bit32               ret = AGSA_RC_SUCCESS;
2936   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
2937   agsaIORequestDesc_t *pRequest;
2938   agsaContext_t       *agContext;
2939   bit32                status, tag;
2940 
2941   bit32           Reserved_Ppc_PHYID;
2942   bit32           PhyId;
2943   bit16           SOP;
2944 
2945   smTraceFuncEnter(hpDBG_VERY_LOUD,"2Q");
2946   OSSA_READ_LE_32(agRoot, &status, pIomb, OSSA_OFFSET_OF(agsaSetPhyProfileRspV_t, status));
2947   OSSA_READ_LE_32(agRoot, &tag, pIomb, OSSA_OFFSET_OF(agsaSetPhyProfileRspV_t, tag));
2948   OSSA_READ_LE_32(agRoot, &Reserved_Ppc_PHYID, pIomb, OSSA_OFFSET_OF(agsaSetPhyProfileRspV_t, Reserved_Ppc_PHYID));
2949   /* get TAG */
2950   SA_DBG1(("mpiSetPhyProfileRsp: HTag=0x%x\n", tag));
2951 
2952   /* get request from IOMap */
2953   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
2954   if (agNULL == pRequest)
2955   {
2956     SA_DBG1(("mpiSetPhyProfileRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
2957     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2Q");
2958     return AGSA_RC_FAILURE;
2959   }
2960 
2961   agContext = saRoot->IOMap[tag].agContext;
2962 
2963   /* remove the request from IOMap */
2964   saRoot->IOMap[tag].Tag = MARK_OFF;
2965   saRoot->IOMap[tag].IORequest = agNULL;
2966   saRoot->IOMap[tag].agContext = agNULL;
2967 
2968   SA_DBG1(("mpiSetPhyProfileRsp:   %p\n",pIomb));
2969 
2970   SOP = pRequest->SOP;
2971   PhyId = Reserved_Ppc_PHYID & 0xFF;
2972 
2973   /* check status success or failure */
2974   if (status)
2975   {
2976     /* status is FAILED */
2977     SA_DBG1(("mpiSetPhyProfileRsp:AGSA_RC_FAILURE  0x%08X\n", status));
2978     switch(SOP)
2979     {
2980       case AGSA_SAS_PHY_ANALOG_SETTINGS_PAGE:
2981       {
2982         SA_DBG1(("mpiSetPhyProfileRsp: AGSA_SAS_PHY_ANALOG_SETTINGS_PAGE SOP 0x%x\n", SOP));
2983         ossaSetPhyProfileCB(agRoot, agContext, status, SOP, PhyId, agNULL );
2984         break;
2985       }
2986       case AGSA_PHY_SNW3_PAGE:
2987       {
2988         SA_DBG1(("mpiSetPhyProfileRsp: AGSA_PHY_SNW3_PAGE SOP 0x%x\n", SOP));
2989         ossaSetPhyProfileCB(agRoot, agContext, status, SOP, PhyId, agNULL );
2990         break;
2991       }
2992 
2993       case AGSA_PHY_RATE_CONTROL_PAGE:
2994       {
2995         SA_DBG1(("mpiSetPhyProfileRsp: AGSA_PHY_RATE_CONTROL_PAGE SOP 0x%x\n", SOP));
2996         ossaSetPhyProfileCB(agRoot, agContext, status, SOP, PhyId, agNULL );
2997         break;
2998       }
2999      case AGSA_SAS_PHY_MISC_PAGE:
3000       {
3001         SA_DBG1(("mpiSetPhyProfileRsp: AGSA_SAS_PHY_MISC_PAGE SOP 0x%x\n", SOP));
3002         ossaSetPhyProfileCB(agRoot, agContext, status, SOP, PhyId, agNULL );
3003         break;
3004       }
3005 
3006       default:
3007       {
3008         SA_DBG1(("mpiSetPhyProfileRsp: undefined SOP 0x%x\n", SOP));
3009         break;
3010       }
3011     }
3012     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2Q");
3013     return AGSA_RC_FAILURE;
3014   }
3015   else
3016   {
3017     SA_DBG1(("mpiSetPhyProfileRsp: SUCCESS type 0x%X\n",SOP ));
3018     switch(SOP)
3019     {
3020       case AGSA_PHY_SNW3_PAGE:
3021       case AGSA_PHY_RATE_CONTROL_PAGE:
3022       {
3023         SA_DBG1(("mpiSetPhyProfileRsp: Status 0x%x SOP 0x%x PhyId %d\n",status, SOP, PhyId));
3024         ossaSetPhyProfileCB(agRoot, agContext, status, SOP, PhyId, agNULL );
3025         break;
3026 
3027       }
3028       case AGSA_SAS_PHY_ANALOG_SETTINGS_PAGE:
3029       {
3030         agsaPhyAnalogSettingsPage_t analog;
3031 
3032         SA_DBG1(("mpiSetPhyProfileRsp: AGSA_SAS_PHY_ANALOG_SETTINGS_PAGE 0x%X\n",SOP));
3033         OSSA_READ_LE_32(agRoot, &analog.Dword0, pIomb, OSSA_OFFSET_OF(agsaSetPhyProfileRspV_t,PageSpecificArea[0] ));
3034         OSSA_READ_LE_32(agRoot, &analog.Dword1, pIomb, OSSA_OFFSET_OF(agsaSetPhyProfileRspV_t,PageSpecificArea[1] ));
3035         OSSA_READ_LE_32(agRoot, &analog.Dword2, pIomb, OSSA_OFFSET_OF(agsaSetPhyProfileRspV_t,PageSpecificArea[2] ));
3036         OSSA_READ_LE_32(agRoot, &analog.Dword3, pIomb, OSSA_OFFSET_OF(agsaSetPhyProfileRspV_t,PageSpecificArea[3] ));
3037         OSSA_READ_LE_32(agRoot, &analog.Dword4, pIomb, OSSA_OFFSET_OF(agsaSetPhyProfileRspV_t,PageSpecificArea[4] ));
3038           /* call back with the status */
3039         ossaSetPhyProfileCB(agRoot, agContext, status, SOP, PhyId, &analog );
3040         break;
3041       }
3042       default:
3043       {
3044         SA_DBG1(("mpiSetPhyProfileRsp: undefined successful SOP 0x%x\n", SOP));
3045         break;
3046       }
3047 
3048     }
3049   }
3050 
3051   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3052   SA_ASSERT((pRequest->valid), "pRequest->valid");
3053   SA_DBG1(("mpiSetPhyProfileRsp: completionCB %p\n",pRequest->completionCB ));
3054 
3055   pRequest->valid = agFALSE;
3056   /* return the request to free pool */
3057   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
3058   {
3059     SA_DBG1(("mpiSetPhyProfileRsp: saving pRequest (%p) for later use\n", pRequest));
3060     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
3061   }
3062   else
3063   {
3064     /* return the request to free pool */
3065     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
3066   }
3067   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3068 
3069   /* return value */
3070   smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "2Q");
3071   return ret;
3072 }
3073 
3074 
3075 
3076 /******************************************************************************/
3077 /*! \brief Get Device Information Response
3078  *
3079  *  This routine handles the response of Get Device Info Command Response
3080  *
3081  *  \param agRoot       Handles for this instance of SAS/SATA LLL
3082  *  \param pIomb        Pointer of IOMB Message
3083  *
3084  *  \return sucess or fail
3085  *
3086  */
3087 /*******************************************************************************/
3088 GLOBAL bit32 mpiGetDevInfoRsp(
3089   agsaRoot_t          *agRoot,
3090   agsaGetDevInfoRspV_t *pIomb
3091   )
3092 {
3093   bit32               ret = AGSA_RC_SUCCESS;
3094   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
3095   agsaIORequestDesc_t *pRequest;
3096   agsaDevHandle_t     *agDevHandle;
3097   agsaDeviceDesc_t    *pDevice;
3098   agsaContext_t       *agContext;
3099   agsaDeviceInfo_t    commonDevInfo;
3100   bit32               ARSrateSMPTimeOutPortID, IRMcnITNexusTimeOut, status, tag;
3101   bit32               deviceid;
3102   bit32               sasAddrHi;
3103   bit32               sasAddrLow;
3104 #if defined(SALLSDK_DEBUG)
3105   bit32               option;
3106 #endif /* SALLSDK_DEBUG */
3107 
3108   smTraceFuncEnter(hpDBG_VERY_LOUD,"2M");
3109   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaGetDevInfoRspV_t, status));
3110   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaGetDevInfoRspV_t, tag));
3111   /* get TAG */
3112   SA_DBG3(("mpiGetDevInfoRsp: HTag=0x%x\n", tag));
3113 
3114   /* get request from IOMap */
3115   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
3116   if (agNULL == pRequest)
3117   {
3118     SA_DBG1(("mpiGetDevInfoRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
3119     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2M");
3120     return AGSA_RC_FAILURE;
3121   }
3122 
3123   agContext = saRoot->IOMap[tag].agContext;
3124 
3125   /* remove the request from IOMap */
3126   saRoot->IOMap[tag].Tag = MARK_OFF;
3127   saRoot->IOMap[tag].IORequest = agNULL;
3128   saRoot->IOMap[tag].agContext = agNULL;
3129 
3130   SA_ASSERT((pRequest->valid), "pRequest->valid");
3131 
3132   /* check status success or failure */
3133   if (status)
3134   {
3135     /* status is FAILED */
3136     ossaGetDeviceInfoCB(agRoot, agContext, agNULL, OSSA_DEV_INFO_INVALID_HANDLE, agNULL);
3137     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2M");
3138 
3139     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3140     pRequest->valid = agFALSE;
3141 #if defined(SALLSDK_DEBUG)
3142     option = (bit32)pRequest->DeviceInfoCmdOption;
3143 #endif /* SALLSDK_DEBUG */
3144     /* return the request to free pool */
3145     if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
3146     {
3147       SA_DBG1(("mpiGetDevInfoRsp: saving pRequest (%p) for later use\n", pRequest));
3148       saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
3149     }
3150     else
3151     {
3152       /* return the request to free pool */
3153       saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
3154     }
3155     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3156 
3157     return AGSA_RC_FAILURE;
3158   }
3159 
3160   /* status is SUCCESS */
3161   OSSA_READ_LE_32(AGROOT, &deviceid, pIomb,                OSSA_OFFSET_OF(agsaGetDevInfoRspV_t, deviceId));
3162   OSSA_READ_LE_32(AGROOT, &ARSrateSMPTimeOutPortID, pIomb, OSSA_OFFSET_OF(agsaGetDevInfoRspV_t, ARSrateSMPTimeOutPortID));
3163   OSSA_READ_LE_32(AGROOT, &IRMcnITNexusTimeOut, pIomb,       OSSA_OFFSET_OF(agsaGetDevInfoRspV_t, IRMcnITNexusTimeOut));
3164   OSSA_READ_LE_32(AGROOT, &sasAddrHi, pIomb,       OSSA_OFFSET_OF(agsaGetDevInfoRspV_t,sasAddrHi[0] ));
3165   OSSA_READ_LE_32(AGROOT, &sasAddrLow, pIomb,       OSSA_OFFSET_OF(agsaGetDevInfoRspV_t,sasAddrLow[0] ));
3166 
3167   /* find device handle from device index */
3168   pDevice = (agsaDeviceDesc_t *)saRoot->DeviceMap[deviceid & DEVICE_ID_BITS].DeviceHandle;
3169   if (pDevice != agNULL)
3170   {
3171     if (pDevice->targetDevHandle.sdkData)
3172     {
3173       agDevHandle = &(pDevice->targetDevHandle);
3174     }
3175     else
3176     {
3177       agDevHandle = &(pDevice->initiatorDevHandle);
3178     }
3179   }
3180   else
3181   {
3182     SA_DBG1(("mpiGetDevInfoRsp: pDevice is NULL"));
3183     smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "2M");
3184     return AGSA_RC_FAILURE;
3185   }
3186 
3187   if (agDevHandle == agNULL)
3188   {
3189     SA_DBG1(("mpiGetDevInfoRsp: warning!!! no deviceHandle is found"));
3190     ossaGetDeviceInfoCB(agRoot, agContext, agNULL, OSSA_DEV_INFO_INVALID_HANDLE, agNULL);
3191     smTraceFuncExit(hpDBG_VERY_LOUD, 'd', "2M");
3192 
3193     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3194     pRequest->valid = agFALSE;
3195 #if defined(SALLSDK_DEBUG)
3196     option = (bit32)pRequest->DeviceInfoCmdOption;
3197 #endif /* SALLSDK_DEBUG */
3198     /* return the request to free pool */
3199     if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
3200     {
3201       SA_DBG1(("mpiGetDevInfoRsp: saving pRequest (%p) for later use\n", pRequest));
3202       saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
3203     }
3204     else
3205     {
3206       /* return the request to free pool */
3207       saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
3208     }
3209     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3210 
3211     return AGSA_RC_FAILURE;
3212   }
3213 
3214   /* setup common device information */
3215   si_memset(&commonDevInfo, 0, sizeof(agsaDeviceInfo_t));
3216   commonDevInfo.smpTimeout       = (bit16)((ARSrateSMPTimeOutPortID >> SHIFT8 ) & SMPTO_VBITS);
3217   commonDevInfo.it_NexusTimeout  = (bit16)(IRMcnITNexusTimeOut & NEXUSTO_VBITS);
3218   commonDevInfo.firstBurstSize   = (bit16)((IRMcnITNexusTimeOut >> SHIFT16) & FIRST_BURST_MCN);
3219   commonDevInfo.devType_S_Rate   = (bit8)((ARSrateSMPTimeOutPortID >> SHIFT24) & 0x3f);
3220   commonDevInfo.flag = (bit32)((ARSrateSMPTimeOutPortID >> SHIFT30 ) & FLAG_VBITS);
3221   commonDevInfo.flag |= IRMcnITNexusTimeOut & 0xf0000;
3222   if (IRMcnITNexusTimeOut & 0x1000000)
3223   {
3224     commonDevInfo.flag |= 0x100000;
3225   }
3226 
3227   /* check SAS device then copy SAS Address */
3228   if ( ((ARSrateSMPTimeOutPortID & DEV_TYPE_BITS) >> SHIFT28 == 0x00) ||
3229        ((ARSrateSMPTimeOutPortID & DEV_TYPE_BITS) >> SHIFT28 == 0x01))
3230   {
3231     /* copy the sasAddressHi byte-by-byte : no endianness */
3232     commonDevInfo.sasAddressHi[0] = pIomb->sasAddrHi[0];
3233     commonDevInfo.sasAddressHi[1] = pIomb->sasAddrHi[1];
3234     commonDevInfo.sasAddressHi[2] = pIomb->sasAddrHi[2];
3235     commonDevInfo.sasAddressHi[3] = pIomb->sasAddrHi[3];
3236 
3237     /* copy the sasAddressLow byte-by-byte : no endianness */
3238     commonDevInfo.sasAddressLo[0] = pIomb->sasAddrLow[0];
3239     commonDevInfo.sasAddressLo[1] = pIomb->sasAddrLow[1];
3240     commonDevInfo.sasAddressLo[2] = pIomb->sasAddrLow[2];
3241     commonDevInfo.sasAddressLo[3] = pIomb->sasAddrLow[3];
3242   }
3243 
3244   /* copy common device information to SAS and SATA device common header*/
3245   si_memcpy(&pDevice->devInfo.sasDeviceInfo.commonDevInfo, &commonDevInfo, sizeof(agsaDeviceInfo_t));
3246   si_memcpy(&pDevice->devInfo.sataDeviceInfo.commonDevInfo, &commonDevInfo, sizeof(agsaDeviceInfo_t));
3247 
3248   /* setup device firstBurstSize infomation */
3249   pDevice->devInfo.sataDeviceInfo.commonDevInfo.firstBurstSize =
3250        (bit16)((IRMcnITNexusTimeOut >> SHIFT16) & FIRST_BURST);
3251 
3252   /* Display Device Information */
3253   SA_DBG3(("mpiGetDevInfoRsp: smpTimeout=0x%x\n", pDevice->devInfo.sasDeviceInfo.commonDevInfo.smpTimeout));
3254   SA_DBG3(("mpiGetDevInfoRsp: it_NexusTimeout=0x%x\n", pDevice->devInfo.sasDeviceInfo.commonDevInfo.it_NexusTimeout));
3255   SA_DBG3(("mpiGetDevInfoRsp: firstBurstSize=0x%x\n", pDevice->devInfo.sasDeviceInfo.commonDevInfo.firstBurstSize));
3256   SA_DBG3(("mpiGetDevInfoRsp: devType_S_Rate=0x%x\n", pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate));
3257 
3258   /*
3259   D518 P2I[15-12]: Disk  HP      DG0146FAMWL     , HPDE, WWID=5000c500:17459a31, 6.0G
3260   */
3261 
3262   SA_DBG1(("mpiGetDevInfoRsp: Device 0x%08X flag 0x%08X %s WWID= %02x%02x%02x%02x:%02x%02x%02x%02x, %s\n",
3263     deviceid,
3264     pDevice->devInfo.sasDeviceInfo.commonDevInfo.flag,
3265     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF0) == 0x20 ? "SATA DA" :
3266     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF0) == 0x10 ? "SSP/SMP" :
3267     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF0) == 0x0 ? "  STP  " : "Unknown",
3268 
3269     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[3],
3270     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[2],
3271     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[1],
3272     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[0],
3273     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[3],
3274     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[2],
3275     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[1],
3276     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[0],
3277 
3278     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF) == 8  ? " 1.5G" :
3279     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF) == 9  ? " 3.0G" :
3280     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF) == 10 ? " 6.0G" :
3281     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF) == 11 ? "12.0G" : "????" ));
3282 
3283   ossaGetDeviceInfoCB(agRoot, agContext, agDevHandle, OSSA_DEV_INFO_NO_EXTENDED_INFO, &commonDevInfo);
3284 
3285   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3286   pRequest->valid = agFALSE;
3287 #if defined(SALLSDK_DEBUG)
3288   option = (bit32)pRequest->DeviceInfoCmdOption;
3289 #endif /* SALLSDK_DEBUG */
3290   /* return the request to free pool */
3291   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
3292   {
3293     SA_DBG1(("mpiGetDevInfoRsp: saving pRequest (%p) for later use\n", pRequest));
3294     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
3295   }
3296   else
3297   {
3298     /* return the request to free pool */
3299     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
3300   }
3301   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3302 
3303   /* return value */
3304   smTraceFuncExit(hpDBG_VERY_LOUD, 'e', "2M");
3305   return ret;
3306 }
3307 
3308 /******************************************************************************/
3309 /*! \brief Get Device Information Response
3310  *
3311  *  This routine handles the response of Get Device Info Command Response
3312  *
3313  *  \param agRoot       Handles for this instance of SAS/SATA LLL
3314  *  \param pIomb        Pointer of IOMB Message
3315  *
3316  *  \return sucess or fail
3317  *
3318  */
3319 /*******************************************************************************/
3320 GLOBAL bit32 mpiGetDevInfoRspSpc(
3321   agsaRoot_t          *agRoot,
3322   agsaGetDevInfoRsp_t *pIomb
3323   )
3324 {
3325   bit32               ret = AGSA_RC_SUCCESS;
3326   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
3327   agsaIORequestDesc_t *pRequest;
3328   agsaDevHandle_t     *agDevHandle;
3329   agsaDeviceDesc_t    *pDevice;
3330   agsaContext_t       *agContext;
3331   bit32               dTypeSrateSMPTOPortID, FirstBurstSizeITNexusTimeOut, status, tag;
3332   bit32               deviceid;
3333   bit32               sasAddrHi;
3334   bit32               sasAddrLow;
3335   bit32               Info_avail = 0;
3336 
3337   smTraceFuncEnter(hpDBG_VERY_LOUD,"2t");
3338   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaGetDevInfoRsp_t, status));
3339   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaGetDevInfoRsp_t, tag));
3340   /* get TAG */
3341   SA_DBG3(("mpiGetDevInfoRspSpc: HTag=0x%x\n", tag));
3342 
3343   /* get request from IOMap */
3344   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
3345   if (agNULL == pRequest)
3346   {
3347     SA_DBG1(("mpiGetDevInfoRspSpc: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
3348     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2t");
3349     return AGSA_RC_FAILURE;
3350   }
3351 
3352   agContext = saRoot->IOMap[tag].agContext;
3353 
3354   /* remove the request from IOMap */
3355   saRoot->IOMap[tag].Tag = MARK_OFF;
3356   saRoot->IOMap[tag].IORequest = agNULL;
3357   saRoot->IOMap[tag].agContext = agNULL;
3358 
3359   SA_ASSERT((pRequest->valid), "pRequest->valid");
3360 
3361   /* check status success or failure */
3362   if (status)
3363   {
3364     /* status is FAILED */
3365     ossaGetDeviceInfoCB(agRoot, agContext, agNULL, OSSA_DEV_INFO_INVALID_HANDLE, agNULL);
3366     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2t");
3367     return AGSA_RC_FAILURE;
3368   }
3369 
3370   /* status is SUCCESS */
3371   OSSA_READ_LE_32(AGROOT, &deviceid, pIomb, OSSA_OFFSET_OF(agsaGetDevInfoRsp_t, deviceId));
3372   OSSA_READ_LE_32(AGROOT, &dTypeSrateSMPTOPortID, pIomb, OSSA_OFFSET_OF(agsaGetDevInfoRsp_t, dTypeSrateSMPTOArPortID));
3373   OSSA_READ_LE_32(AGROOT, &FirstBurstSizeITNexusTimeOut, pIomb, OSSA_OFFSET_OF(agsaGetDevInfoRsp_t, FirstBurstSizeITNexusTimeOut));
3374   OSSA_READ_LE_32(AGROOT, &sasAddrHi, pIomb, OSSA_OFFSET_OF(agsaGetDevInfoRsp_t, sasAddrHi[0]));
3375   OSSA_READ_LE_32(AGROOT, &sasAddrLow, pIomb, OSSA_OFFSET_OF(agsaGetDevInfoRsp_t, sasAddrLow[0]));
3376 
3377 
3378   SA_DBG2(("mpiGetDevInfoRspSpc:deviceid                     0x%08X\n",deviceid));
3379   SA_DBG2(("mpiGetDevInfoRspSpc:dTypeSrateSMPTOPortID        0x%08X\n",dTypeSrateSMPTOPortID));
3380   SA_DBG2(("mpiGetDevInfoRspSpc:FirstBurstSizeITNexusTimeOut 0x%08X\n",FirstBurstSizeITNexusTimeOut));
3381   SA_DBG2(("mpiGetDevInfoRspSpc:sasAddrHi                    0x%08X\n",sasAddrHi));
3382   SA_DBG2(("mpiGetDevInfoRspSpc:sasAddrLow                   0x%08X\n",sasAddrLow));
3383 
3384 
3385   /* find device handle from device index */
3386   pDevice = (agsaDeviceDesc_t *)saRoot->DeviceMap[deviceid & DEVICE_ID_BITS].DeviceHandle;
3387   if (pDevice != agNULL)
3388   {
3389     if (pDevice->targetDevHandle.sdkData)
3390     {
3391       agDevHandle = &(pDevice->targetDevHandle);
3392     }
3393     else
3394     {
3395       agDevHandle = &(pDevice->initiatorDevHandle);
3396     }
3397   }
3398   else
3399   {
3400     SA_DBG1(("mpiGetDevInfoRspSpc: pDevice is NULL"));
3401     smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "2t");
3402     return AGSA_RC_FAILURE;
3403   }
3404 
3405   if (agDevHandle == agNULL)
3406   {
3407     SA_DBG1(("mpiGetDevInfoRspSpc: warning!!! no deviceHandle is found"));
3408     ossaGetDeviceInfoCB(agRoot, agContext, agNULL, OSSA_DEV_INFO_INVALID_HANDLE, agNULL);
3409     smTraceFuncExit(hpDBG_VERY_LOUD, 'd', "2t");
3410 
3411     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3412     pRequest->valid = agFALSE;
3413     /* return the request to free pool */
3414     if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
3415     {
3416       SA_DBG1(("mpiGetDevInfoRspSpc: saving pRequest (%p) for later use\n", pRequest));
3417       saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
3418     }
3419     else
3420     {
3421       /* return the request to free pool */
3422       saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
3423     }
3424     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3425 
3426     return AGSA_RC_FAILURE;
3427   }
3428 
3429   Info_avail = OSSA_DEV_INFO_NO_EXTENDED_INFO;
3430 
3431   /* setup device common infomation */
3432   pDevice->devInfo.sasDeviceInfo.commonDevInfo.smpTimeout =
3433     (bit16)((dTypeSrateSMPTOPortID >> SHIFT8 ) & SMPTO_BITS);
3434 
3435   pDevice->devInfo.sataDeviceInfo.commonDevInfo.smpTimeout =
3436     (bit16)((dTypeSrateSMPTOPortID >> SHIFT8 ) & SMPTO_BITS);
3437 
3438   pDevice->devInfo.sasDeviceInfo.commonDevInfo.it_NexusTimeout =
3439     (bit16)(FirstBurstSizeITNexusTimeOut & NEXUSTO_BITS);
3440 
3441   pDevice->devInfo.sataDeviceInfo.commonDevInfo.it_NexusTimeout =
3442     (bit16)(FirstBurstSizeITNexusTimeOut & NEXUSTO_BITS);
3443 
3444   pDevice->devInfo.sasDeviceInfo.commonDevInfo.firstBurstSize =
3445     (bit16)((FirstBurstSizeITNexusTimeOut >> SHIFT16) & FIRST_BURST);
3446 
3447   pDevice->devInfo.sataDeviceInfo.commonDevInfo.firstBurstSize =
3448     (bit16)((FirstBurstSizeITNexusTimeOut >> SHIFT16) & FIRST_BURST);
3449 
3450   pDevice->devInfo.sasDeviceInfo.commonDevInfo.flag = (bit32)((dTypeSrateSMPTOPortID >> SHIFT4 ) & FLAG_BITS);
3451 
3452   pDevice->devInfo.sataDeviceInfo.commonDevInfo.flag = (bit32)((dTypeSrateSMPTOPortID >> SHIFT4 ) & FLAG_BITS);
3453 
3454   pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate =
3455     (bit8)((dTypeSrateSMPTOPortID >> SHIFT24) & LINK_RATE_BITS);
3456 
3457   pDevice->devInfo.sataDeviceInfo.commonDevInfo.devType_S_Rate =
3458     (bit8)((dTypeSrateSMPTOPortID >> SHIFT24) & LINK_RATE_BITS);
3459 
3460   /* check SAS device then copy SAS Address */
3461   if ( ((dTypeSrateSMPTOPortID & DEV_TYPE_BITS) >> SHIFT28 == 0x00) ||
3462        ((dTypeSrateSMPTOPortID & DEV_TYPE_BITS) >> SHIFT28 == 0x01))
3463   {
3464     /* copy the sasAddressHi byte-by-byte : no endianness */
3465     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[0] = pIomb->sasAddrHi[0];
3466     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[1] = pIomb->sasAddrHi[1];
3467     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[2] = pIomb->sasAddrHi[2];
3468     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[3] = pIomb->sasAddrHi[3];
3469 
3470     /* copy the sasAddressLow byte-by-byte : no endianness */
3471     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[0] = pIomb->sasAddrLow[0];
3472     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[1] = pIomb->sasAddrLow[1];
3473     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[2] = pIomb->sasAddrLow[2];
3474     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[3] = pIomb->sasAddrLow[3];
3475   }
3476 
3477   /* Display Device Information */
3478   SA_DBG3(("mpiGetDevInfoRspSpc: smpTimeout=     0x%x\n", pDevice->devInfo.sasDeviceInfo.commonDevInfo.smpTimeout));
3479   SA_DBG3(("mpiGetDevInfoRspSpc: it_NexusTimeout=0x%x\n", pDevice->devInfo.sasDeviceInfo.commonDevInfo.it_NexusTimeout));
3480   SA_DBG3(("mpiGetDevInfoRspSpc: firstBurstSize= 0x%x\n", pDevice->devInfo.sasDeviceInfo.commonDevInfo.firstBurstSize));
3481   SA_DBG3(("mpiGetDevInfoRspSpc: devType_S_Rate= 0x%x\n", pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate));
3482 
3483 
3484   SA_DBG1(("Device SPC deviceid 0x%08X flag 0x%08X %s WWID= %02x%02x%02x%02x:%02x%02x%02x%02x, %s\n",
3485     deviceid,
3486     pDevice->devInfo.sasDeviceInfo.commonDevInfo.flag,
3487     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF0) == 0x20 ? "SATA DA" :
3488     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF0) == 0x10 ? "SSP/SMP" :
3489     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF0) == 0x0 ? "  STP  " : "Unknown",
3490 
3491     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[3],
3492     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[2],
3493     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[1],
3494     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[0],
3495     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[3],
3496     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[2],
3497     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[1],
3498     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[0],
3499 
3500     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF) == 8  ? " 1.5G" :
3501     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF) == 9  ? " 3.0G" :
3502     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF) == 10 ? " 6.0G" :
3503     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF) == 11 ? "12.0G" : "????" ));
3504 
3505   ossaGetDeviceInfoCB(agRoot, agContext, agDevHandle, Info_avail, &pDevice->devInfo.sasDeviceInfo.commonDevInfo);
3506 
3507   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3508   pRequest->valid = agFALSE;
3509   /* return the request to free pool */
3510   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
3511   {
3512     SA_DBG1(("mpiGetDevInfoRspSpc: saving pRequest (%p) for later use\n", pRequest));
3513     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
3514   }
3515   else
3516   {
3517     /* return the request to free pool */
3518     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
3519   }
3520   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3521 
3522   /* return value */
3523   smTraceFuncExit(hpDBG_VERY_LOUD, 'e', "2t");
3524   return ret;
3525 }
3526 
3527 /******************************************************************************/
3528 /*! \brief Set Device Information Response
3529  *
3530  *  This routine handles the response of Set Device Info Command Response
3531  *
3532  *  \param agRoot       Handles for this instance of SAS/SATA LLL
3533  *  \param pIomb        Pointer of IOMB Message
3534  *
3535  *  \return sucess or fail
3536  *
3537  */
3538 /*******************************************************************************/
3539 GLOBAL bit32 mpiSetDevInfoRsp(
3540   agsaRoot_t             *agRoot,
3541   agsaSetDeviceInfoRsp_t *pIomb
3542   )
3543 {
3544   bit32               ret = AGSA_RC_SUCCESS;
3545   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
3546   agsaIORequestDesc_t *pRequest;
3547   agsaDevHandle_t     *agDevHandle;
3548   agsaDeviceDesc_t    *pDevice;
3549   agsaContext_t       *agContext;
3550   bit32               tag, status, deviceid, option, param;
3551 
3552   smTraceFuncEnter(hpDBG_VERY_LOUD,"2v");
3553   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaSetDeviceInfoRsp_t, status));
3554   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaSetDeviceInfoRsp_t, tag));
3555   /* get TAG */
3556   SA_DBG3(("mpiSetDevInfoRsp: HTag=0x%x\n", tag));
3557 
3558   /* get request from IOMap */
3559   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
3560   if (agNULL == pRequest)
3561   {
3562     SA_DBG1(("mpiSetDevInfoRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
3563     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2v");
3564     return AGSA_RC_FAILURE;
3565   }
3566 
3567   agContext = saRoot->IOMap[tag].agContext;
3568 
3569   /* remove the request from IOMap */
3570   saRoot->IOMap[tag].Tag = MARK_OFF;
3571   saRoot->IOMap[tag].IORequest = agNULL;
3572   saRoot->IOMap[tag].agContext = agNULL;
3573 
3574   SA_ASSERT((pRequest->valid), "pRequest->valid");
3575   /* check status success or failure */
3576   if (status)
3577   {
3578     /* status is FAILED */
3579     if (pRequest->completionCB == agNULL)
3580     {
3581       SA_DBG1(("mpiSetDevInfoRsp: status is FAILED pRequest->completionCB == agNULL\n" ));
3582       ossaSetDeviceInfoCB(agRoot, agContext, agNULL, status, 0, 0);
3583     }
3584     else
3585     {
3586       SA_DBG1(("mpiSetDevInfoRsp: status is FAILED use CB\n" ));
3587       (*(ossaSetDeviceInfoCB_t)(pRequest->completionCB))(agRoot, agContext, agNULL, status, 0, 0);
3588     }
3589     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2v");
3590 
3591     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3592     pRequest->valid = agFALSE;
3593     /* return the request to free pool */
3594     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
3595     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3596 
3597     return AGSA_RC_FAILURE;
3598   }
3599 
3600   /* status is SUCCESS */
3601   OSSA_READ_LE_32(AGROOT, &deviceid, pIomb, OSSA_OFFSET_OF(agsaSetDeviceInfoRsp_t, deviceId));
3602   OSSA_READ_LE_32(AGROOT, &option, pIomb, OSSA_OFFSET_OF(agsaSetDeviceInfoRsp_t, SA_SR_SI));
3603   OSSA_READ_LE_32(AGROOT, &param, pIomb, OSSA_OFFSET_OF(agsaSetDeviceInfoRsp_t, A_R_ITNT));
3604 
3605   /* find device handle from device index */
3606   pDevice = (agsaDeviceDesc_t *)saRoot->DeviceMap[deviceid & DEVICE_ID_BITS].DeviceHandle;
3607   if (pDevice != agNULL)
3608   {
3609     if (pDevice->targetDevHandle.sdkData)
3610     {
3611       agDevHandle = &(pDevice->targetDevHandle);
3612     }
3613     else
3614     {
3615       agDevHandle = &(pDevice->initiatorDevHandle);
3616     }
3617   }
3618   else
3619   {
3620     SA_DBG1(("mpiSetDevInfoRsp: pDevice is NULL"));
3621     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3622     pRequest->valid = agFALSE;
3623     /* return the request to free pool */
3624     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
3625     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3626     smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "2v");
3627     return AGSA_RC_FAILURE;
3628   }
3629 
3630   if (agDevHandle == agNULL)
3631   {
3632     SA_DBG1(("mpiSetDevInfoRsp: warning!!! no deviceHandle is found"));
3633     if (pRequest->completionCB == agNULL)
3634     {
3635       ossaSetDeviceInfoCB(agRoot, agContext, agNULL, OSSA_IO_NO_DEVICE, 0, 0);
3636     }
3637     else
3638     {
3639       (*(ossaSetDeviceInfoCB_t)(pRequest->completionCB))(agRoot, agContext, agNULL, OSSA_IO_NO_DEVICE, 0, 0);
3640     }
3641     smTraceFuncExit(hpDBG_VERY_LOUD, 'd', "2v");
3642 
3643     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3644     pRequest->valid = agFALSE;
3645     /* return the request to free pool */
3646     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
3647     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3648 
3649     return AGSA_RC_FAILURE;
3650   }
3651 
3652   SA_DBG2(("mpiSetDevInfoRsp:, option 0x%X param 0x%X\n", option, param));
3653 
3654   if(smIS_SPCV(agRoot))
3655   {
3656     SA_DBG2(("mpiSetDevInfoRsp:was option 0x%X param 0x%X\n", option, param));
3657     SA_DBG2(("mpiSetDevInfoRsp:pDevice->option 0x%X pDevice->param 0x%X\n", pDevice->option, pDevice->param));
3658     option |= pDevice->option;
3659     param |= pDevice->param;
3660     SA_DBG2(("mpiSetDevInfoRsp:now option 0x%X param 0x%X\n", option, param));
3661     if (pRequest->completionCB == agNULL)
3662     {
3663       ossaSetDeviceInfoCB(agRoot, agContext, agDevHandle, OSSA_SUCCESS, option, param);
3664     }
3665     else
3666     {
3667       (*(ossaSetDeviceInfoCB_t)(pRequest->completionCB))(agRoot, agContext, agDevHandle, OSSA_SUCCESS, option, param);
3668     }
3669   }
3670   else
3671   {
3672     SA_DBG2(("mpiSetDevInfoRsp:, option 0x%X param 0x%X\n", option, param));
3673     if (pRequest->completionCB == agNULL)
3674     {
3675       ossaSetDeviceInfoCB(agRoot, agContext, agDevHandle, OSSA_SUCCESS, option, param);
3676     }
3677     else
3678     {
3679       (*(ossaSetDeviceInfoCB_t)(pRequest->completionCB))(agRoot, agContext, agDevHandle, OSSA_SUCCESS, option, param);
3680     }
3681   }
3682 
3683   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3684   pRequest->valid = agFALSE;
3685   /* return the request to free pool */
3686   saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
3687   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
3688 
3689   /* return value */
3690   smTraceFuncExit(hpDBG_VERY_LOUD, 'e', "2v");
3691   return ret;
3692 }
3693 
3694 /******************************************************************************/
3695 /*! \brief SPC MPI SSP Event
3696  *
3697  *  This function handles the SAS Event.
3698  *
3699  *  \param agRoot       Handles for this instance of SAS/SATA LLL
3700  *  \param pIomb        pointer of Message
3701  *
3702  *  \return The read value
3703  *
3704  */
3705 /*******************************************************************************/
3706 GLOBAL bit32 mpiSSPEvent(
3707   agsaRoot_t        *agRoot,
3708   agsaSSPEventRsp_t *pIomb
3709   )
3710 {
3711   bit32               ret = AGSA_RC_SUCCESS;
3712   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
3713   agsaIORequestDesc_t *pRequest;
3714   agsaPortContext_t   *agPortContext;
3715   agsaDevHandle_t     *agDevHandle;
3716   agsaDeviceDesc_t    *pDevice;
3717   bit32               event,deviceId;
3718   bit32               deviceIdx, tag, portId_tmp;
3719   bit32               SSPTag;
3720   bit16               sspTag;
3721   bit8                portId;
3722 
3723   agsaDifDetails_t Dif_details;
3724 
3725   smTraceFuncEnter(hpDBG_VERY_LOUD,"2u");
3726 
3727   OSSA_READ_LE_32(AGROOT, &event, pIomb, OSSA_OFFSET_OF(agsaSSPEventRsp_t, event));
3728   OSSA_READ_LE_32(AGROOT, &deviceId, pIomb, OSSA_OFFSET_OF(agsaSSPEventRsp_t, deviceId));
3729   OSSA_READ_LE_32(AGROOT, &portId_tmp, pIomb, OSSA_OFFSET_OF(agsaSSPEventRsp_t, portId));
3730   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaSSPEventRsp_t, tag));
3731   OSSA_READ_LE_32(AGROOT, &SSPTag, pIomb, OSSA_OFFSET_OF(agsaSSPEventRsp_t, SSPTag));
3732 
3733 
3734   sspTag = (bit16)(SSPTag & SSPTAG_BITS);
3735 
3736   /* get IORequest from IOMap */
3737   pRequest  = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
3738 
3739   SA_ASSERT((pRequest), "pRequest");
3740 
3741   if(agNULL == pRequest)
3742   {
3743     SA_DBG1(("mpiSSPEvent: agNULL == pRequest event 0x%X\n", event));
3744     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2u");
3745     return AGSA_RC_FAILURE;
3746   }
3747 
3748   /* get port context */
3749   portId = (bit8)(portId_tmp & PORTID_MASK);
3750   SA_DBG2(("mpiSSPEvent:PortID 0x%x PortStatus 0x%x PortContext %p\n",saRoot->PortMap[portId & PORTID_MASK].PortID,saRoot->PortMap[portId & PORTID_MASK].PortStatus,saRoot->PortMap[portId & PORTID_MASK].PortContext));
3751   agPortContext = (agsaPortContext_t *)saRoot->PortMap[portId].PortContext;
3752   /* get device Id */
3753   deviceIdx = deviceId & DEVICE_ID_BITS;
3754   OS_ASSERT(deviceIdx < MAX_IO_DEVICE_ENTRIES, "deviceIdx MAX_IO_DEVICE_ENTRIES");
3755   /* find device handle from device index */
3756   pDevice = (agsaDeviceDesc_t *)saRoot->DeviceMap[deviceIdx].DeviceHandle;
3757 
3758   if( agNULL == pDevice )
3759   {
3760     OS_ASSERT(pDevice, "pDevice");
3761     agDevHandle = agNULL;
3762   }
3763   else
3764   {
3765     if (pDevice->targetDevHandle.sdkData)
3766     {
3767       agDevHandle = &(pDevice->targetDevHandle);
3768     }
3769     else
3770     {
3771       agDevHandle = &(pDevice->initiatorDevHandle);
3772     }
3773   }
3774 
3775   switch (event)
3776   {
3777     case  OSSA_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH:
3778     case  OSSA_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH:
3779     case  OSSA_IO_XFR_ERROR_DIF_CRC_MISMATCH:
3780     case  OSSA_IO_XFR_ERROR_DIF_MISMATCH:
3781     {
3782 
3783       SA_DBG1(("mpiSSPEvent:  DIF Event 0x%x HTAG = 0x%x\n", event, tag));
3784 
3785       OSSA_READ_LE_32(AGROOT, &Dif_details.UpperLBA,           pIomb, OSSA_OFFSET_OF(agsaSSPEventRsp_t, EVT_PARAM0_or_LBAH));
3786       OSSA_READ_LE_32(AGROOT, &Dif_details.LowerLBA,           pIomb, OSSA_OFFSET_OF(agsaSSPEventRsp_t, EVT_PARAM1_or_LBAL));
3787       OSSA_READ_LE_32(AGROOT, &Dif_details.sasAddressHi,       pIomb, OSSA_OFFSET_OF(agsaSSPEventRsp_t, SAS_ADDRH));
3788       OSSA_READ_LE_32(AGROOT, &Dif_details.sasAddressLo,       pIomb, OSSA_OFFSET_OF(agsaSSPEventRsp_t, SAS_ADDRL));
3789       OSSA_READ_LE_32(AGROOT, &Dif_details.ExpectedCRCUDT01,   pIomb, OSSA_OFFSET_OF(agsaSSPEventRsp_t, UDT1_E_UDT0_E_CRC_E));
3790       OSSA_READ_LE_32(AGROOT, &Dif_details.ExpectedUDT2345,    pIomb, OSSA_OFFSET_OF(agsaSSPEventRsp_t, UDT5_E_UDT4_E_UDT3_E_UDT2_E));
3791       OSSA_READ_LE_32(AGROOT, &Dif_details.ActualCRCUDT01,     pIomb, OSSA_OFFSET_OF(agsaSSPEventRsp_t, UDT1_A_UDT0_A_CRC_A));
3792       OSSA_READ_LE_32(AGROOT, &Dif_details.ActualUDT2345,      pIomb, OSSA_OFFSET_OF(agsaSSPEventRsp_t, UDT5_A_UDT4_A_UDT3_A_UDT2_A));
3793       OSSA_READ_LE_32(AGROOT, &Dif_details.DIFErrDevID,        pIomb, OSSA_OFFSET_OF(agsaSSPEventRsp_t, HW_DEVID_Reserved_DIF_ERR));
3794       OSSA_READ_LE_32(AGROOT, &Dif_details.ErrBoffsetEDataLen, pIomb, OSSA_OFFSET_OF(agsaSSPEventRsp_t, EDATA_LEN_ERR_BOFF));
3795 
3796       SA_DBG2(("mpiSSPEvent: UpperLBA.         0x%08X LowerLBA.           0x%08X\n",Dif_details.UpperLBA,         Dif_details.LowerLBA));
3797       SA_DBG2(("mpiSSPEvent: sasAddressHi.     0x%02X%02X%02X%02X sasAddressLo.       0x%02X%02X%02X%02X\n",
3798                           Dif_details.sasAddressHi[0],Dif_details.sasAddressHi[1],Dif_details.sasAddressHi[2],Dif_details.sasAddressHi[3],
3799                           Dif_details.sasAddressLo[0],Dif_details.sasAddressLo[1],Dif_details.sasAddressLo[2],Dif_details.sasAddressLo[3]));
3800       SA_DBG2(("mpiSSPEvent: ExpectedCRCUDT01. 0x%08X ExpectedUDT2345.    0x%08X\n",Dif_details.ExpectedCRCUDT01, Dif_details.ExpectedUDT2345));
3801       SA_DBG2(("mpiSSPEvent: ActualCRCUDT01.   0x%08X ActualUDT2345.      0x%08X\n",Dif_details.ActualCRCUDT01,   Dif_details.ActualUDT2345));
3802       SA_DBG2(("mpiSSPEvent: DIFErrDevID.      0x%08X ErrBoffsetEDataLen. 0x%08X\n",Dif_details.DIFErrDevID,      Dif_details.ErrBoffsetEDataLen));
3803     }
3804 
3805     default:
3806     {
3807       SA_DBG3(("mpiSSPEvent:  Non DIF event"));
3808       break;
3809     }
3810   }
3811 
3812 
3813   /* get event */
3814   switch (event)
3815   {
3816     case OSSA_IO_OVERFLOW:
3817     {
3818       SA_DBG1(("mpiSSPEvent: OSSA_IO_OVERFLOW tag 0x%x ssptag 0x%x\n", tag, sspTag));
3819       saRoot->IoEventCount.agOSSA_IO_OVERFLOW++;
3820       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3821       break;
3822     }
3823     case OSSA_IO_XFER_ERROR_BREAK:
3824     {
3825       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFER_ERROR_BREAK tag 0x%x ssptag 0x%x\n", tag, sspTag));
3826       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_BREAK++;
3827       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3828       break;
3829     }
3830     case OSSA_IO_XFER_ERROR_PHY_NOT_READY:
3831     {
3832       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFER_ERROR_PHY_NOT_READY tag 0x%x ssptag 0x%x\n", tag, sspTag));
3833       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_PHY_NOT_READY++;
3834       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3835       break;
3836     }
3837     case OSSA_IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
3838     {
3839       SA_DBG1(("mpiSSPEvent: OSSA_IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED tag 0x%x ssptag 0x%x\n", tag, sspTag));
3840       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED++;
3841       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3842       break;
3843     }
3844     case OSSA_IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
3845     {
3846       SA_DBG1(("mpiSSPEvent: OSSA_IO_OPEN_CNX_ERROR_ZONE_VIOLATION tag 0x%x ssptag 0x%x\n", tag, sspTag));
3847       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_ZONE_VIOLATION++;
3848       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3849       break;
3850     }
3851     case OSSA_IO_OPEN_CNX_ERROR_BREAK:
3852     {
3853       SA_DBG1(("mpiSSPEvent: OSSA_IO_OPEN_CNX_ERROR_BREAK tag 0x%x ssptag 0x%x\n", tag, sspTag));
3854       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_BREAK++;
3855       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3856       break;
3857     }
3858     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
3859     {
3860       SA_DBG1(("mpiSSPEvent: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS tag 0x%x ssptag 0x%x\n", tag, sspTag));
3861       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS++;
3862       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3863       break;
3864     }
3865     case OSSA_IO_OPEN_CNX_ERROR_BAD_DESTINATION:
3866     {
3867       SA_DBG1(("mpiSSPEvent: OSSA_IO_OPEN_CNX_ERROR_BAD_DESTINATION tag 0x%x ssptag 0x%x\n", tag, sspTag));
3868       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_BAD_DESTINATION++;
3869       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3870       break;
3871     }
3872     case OSSA_IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
3873     {
3874       SA_DBG1(("mpiSSPEvent: OSSA_IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED tag 0x%x ssptag 0x%x\n", tag, sspTag));
3875       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED++;
3876       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3877       break;
3878     }
3879     case OSSA_IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
3880     {
3881       SA_DBG1(("mpiSSPEvent: OSSA_IO_OPEN_CNX_ERROR_WRONG_DESTINATION tag 0x%x ssptag 0x%x\n", tag, sspTag));
3882       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_WRONG_DESTINATION++;
3883       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3884       break;
3885     }
3886     case OSSA_IO_XFER_ERROR_NAK_RECEIVED:
3887     {
3888       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFER_ERROR_NAK_RECEIVED tag 0x%x ssptag 0x%x\n", tag, sspTag));
3889       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_NAK_RECEIVED++;
3890       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3891       break;
3892     }
3893     case OSSA_IO_XFER_ERROR_ACK_NAK_TIMEOUT:
3894     {
3895       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFER_ERROR_ACK_NAK_TIMEOUT tag 0x%x ssptag 0x%x\n", tag, sspTag));
3896       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_ACK_NAK_TIMEOUT++;
3897       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3898       break;
3899     }
3900     case OSSA_IO_XFER_ERROR_OFFSET_MISMATCH:
3901     {
3902       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFER_ERROR_OFFSET_MISMATCH tag 0x%x ssptag 0x%x\n", tag, sspTag));
3903 #ifdef SA_ENABLE_PCI_TRIGGER
3904       if( saRoot->swConfig.PCI_trigger & PCI_TRIGGER_OFFSET_MISMATCH )
3905       {
3906         siPCITriger(agRoot);
3907       }
3908 #endif /* SA_ENABLE_PCI_TRIGGER */
3909       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_OFFSET_MISMATCH++;
3910       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3911       break;
3912     }
3913     case OSSA_IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
3914     {
3915       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFER_ERROR_XFER_ZERO_DATA_LEN tag 0x%x ssptag 0x%x\n", tag, sspTag));
3916       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_XFER_ZERO_DATA_LEN++;
3917       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3918       break;
3919     }
3920     case OSSA_IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT:
3921     {
3922       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT tag 0x%x ssptag 0x%x\n", tag, sspTag));
3923       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_CMD_ISSUE_ACK_NAK_TIMEOUT++;
3924       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3925       break;
3926     }
3927     case OSSA_IO_XFER_OPEN_RETRY_TIMEOUT:
3928     {
3929       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFER_OPEN_RETRY_TIMEOUT tag 0x%x ssptag 0x%x\n", tag, sspTag));
3930       saRoot->IoEventCount.agOSSA_IO_XFER_OPEN_RETRY_TIMEOUT++;
3931       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3932       break;
3933     }
3934     case OSSA_IO_XFER_ERROR_XFER_RDY_OVERRUN:
3935     {
3936       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFER_ERROR_XFER_RDY_OVERRUN tag 0x%x ssptag 0x%x\n", tag, sspTag));
3937       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_XFER_RDY_OVERRUN++;
3938       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3939       break;
3940     }
3941     case OSSA_IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
3942     {
3943       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED tag 0x%x ssptag 0x%x\n", tag, sspTag));
3944       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED++;
3945       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3946       break;
3947     }
3948     case OSSA_IO_XFER_CMD_FRAME_ISSUED:
3949     {
3950       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFER_CMD_FRAME_ISSUED tag 0x%x ssptag 0x%x\n", tag, sspTag));
3951       saRoot->IoEventCount.agOSSA_IO_XFER_CMD_FRAME_ISSUED++;
3952       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3953       break;
3954     }
3955     case OSSA_IO_XFER_ERROR_UNEXPECTED_PHASE:
3956     {
3957       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFER_ERROR_UNEXPECTED_PHASE tag 0x%x ssptag 0x%x\n", tag, sspTag));
3958       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_UNEXPECTED_PHASE++;
3959       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3960       break;
3961     }
3962     case  OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
3963     {
3964       SA_DBG1(("mpiSSPEvent:OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED HTAG = 0x%x sspTag = 0x%x\n", tag, sspTag));
3965       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED++;
3966       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3967       break;
3968     }
3969     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO:
3970     {
3971       SA_DBG1(("mpiSSPEvent: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO tag 0x%x ssptag 0x%x\n", tag, sspTag));
3972       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_TMO++;
3973       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3974       break;
3975     }
3976     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
3977     {
3978       SA_DBG1(("mpiSSPEvent: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST tag 0x%x ssptag 0x%x\n", tag, sspTag));
3979       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST++;
3980       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3981       break;
3982     }
3983     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
3984     {
3985       SA_DBG1(("mpiSSPEvent: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE tag 0x%x ssptag 0x%x\n", tag, sspTag));
3986       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE++;
3987       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3988       break;
3989     }
3990     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
3991     {
3992       SA_DBG1(("mpiSSPEvent: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED tag 0x%x ssptag 0x%x\n", tag, sspTag));
3993       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED++;
3994       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
3995       break;
3996     }
3997     case OSSA_IO_XFR_ERROR_DEK_KEY_CACHE_MISS:
3998     {
3999       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFR_ERROR_DEK_KEY_CACHE_MISS tag 0x%x ssptag 0x%x\n", tag, sspTag));
4000       saRoot->IoEventCount.agOSSA_IO_XFR_ERROR_DEK_KEY_CACHE_MISS++;
4001       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
4002       break;
4003     }
4004     case OSSA_IO_XFR_ERROR_DEK_KEY_TAG_MISMATCH:
4005     {
4006       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFR_ERROR_DEK_KEY_TAG_MISMATCH tag 0x%x ssptag 0x%x\n", tag, sspTag));
4007       saRoot->IoEventCount.agOSSA_IO_XFR_ERROR_DEK_KEY_TAG_MISMATCH++;
4008       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
4009       break;
4010     }
4011     case  OSSA_IO_XFR_ERROR_INTERNAL_CRC_ERROR:
4012     {
4013       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFR_ERROR_INTERNAL_CRC_ERROR HTAG = 0x%x\n", tag));
4014       saRoot->IoEventCount.agOSSA_IO_XFR_ERROR_INTERNAL_CRC_ERROR++;
4015       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
4016       break;
4017     }
4018     case  OSSA_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH:
4019     {
4020       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH tag 0x%x ssptag 0x%x\n", tag, sspTag));
4021       saRoot->IoEventCount.agOSSA_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH++;
4022       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag,sizeof(agsaDifDetails_t),&Dif_details);
4023       break;
4024     }
4025     case  OSSA_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH:
4026     {
4027       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH tag 0x%x ssptag 0x%x\n", tag, sspTag));
4028       saRoot->IoEventCount.agOSSA_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH++;
4029       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag,sizeof(agsaDifDetails_t),&Dif_details);
4030       break;
4031     }
4032     case  OSSA_IO_XFR_ERROR_DIF_CRC_MISMATCH:
4033     {
4034       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFR_ERROR_DIF_CRC_MISMATCH tag 0x%x ssptag 0x%x\n", tag, sspTag));
4035       saRoot->IoEventCount.agOSSA_IO_XFR_ERROR_DIF_CRC_MISMATCH++;
4036       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag,sizeof(agsaDifDetails_t),&Dif_details);
4037       break;
4038     }
4039     case  OSSA_IO_XFR_ERROR_DIF_MISMATCH:
4040     {
4041       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFR_ERROR_DIF_MISMATCH tag 0x%x ssptag 0x%x\n", tag, sspTag));
4042       saRoot->IoEventCount.agOSSA_IO_XFR_ERROR_DIF_MISMATCH++;
4043       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag,sizeof(agsaDifDetails_t),&Dif_details);
4044       break;
4045     }
4046     case  OSSA_IO_XFER_ERR_EOB_DATA_OVERRUN:
4047     {
4048       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFER_ERR_EOB_DATA_OVERRUN tag 0x%x ssptag 0x%x\n", tag, sspTag));
4049       saRoot->IoEventCount.agOSSA_IO_XFER_ERR_EOB_DATA_OVERRUN++;
4050       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0, agNULL);
4051       break;
4052     }
4053     case OSSA_IO_XFER_READ_COMPL_ERR:
4054     {
4055       SA_DBG1(("mpiSSPEvent: OSSA_IO_XFER_READ_COMPL_ERR tag 0x%x ssptag 0x%x\n", tag, sspTag));
4056       saRoot->IoEventCount.agOSSA_IO_XFER_READ_COMPL_ERR++;
4057       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0, agNULL);
4058       break;
4059     }
4060     default:
4061     {
4062       SA_DBG1(("mpiSSPEvent:  Unknown Event 0x%x tag 0x%x ssptag 0x%x\n", event, tag, sspTag));
4063       saRoot->IoEventCount.agOSSA_IO_UNKNOWN_ERROR++;
4064       ossaSSPEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, sspTag, 0,agNULL);
4065       break;
4066     }
4067   }
4068 
4069   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2u");
4070   /* return value */
4071   return ret;
4072 }
4073 
4074 /******************************************************************************/
4075 /*! \brief SPC MPI SATA Event
4076  *
4077  *  This function handles the SATA Event.
4078  *
4079  *  \param agRoot       Handles for this instance of SAS/SATA LLL
4080  *  \param pIomb        pointer of Message
4081  *
4082  *  \return The read value
4083  *
4084  */
4085 /*******************************************************************************/
4086 GLOBAL bit32 mpiSATAEvent(
4087   agsaRoot_t         *agRoot,
4088   agsaSATAEventRsp_t *pIomb
4089   )
4090 {
4091   bit32               ret = AGSA_RC_SUCCESS;
4092   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
4093   agsaIORequestDesc_t *pRequest = agNULL;
4094   agsaPortContext_t   *agPortContext;
4095   agsaDevHandle_t     *agDevHandle;
4096   agsaDeviceDesc_t    *pDevice;
4097   bit32               deviceIdx, portId_tmp, event, tag, deviceId;
4098   bit8                portId;
4099 
4100   smTraceFuncEnter(hpDBG_VERY_LOUD,"2w");
4101 
4102   /* get port context */
4103   OSSA_READ_LE_32(AGROOT, &portId_tmp, pIomb, OSSA_OFFSET_OF(agsaSATAEventRsp_t, portId));
4104   OSSA_READ_LE_32(AGROOT, &deviceId, pIomb, OSSA_OFFSET_OF(agsaSATAEventRsp_t, deviceId));
4105   OSSA_READ_LE_32(AGROOT, &event, pIomb, OSSA_OFFSET_OF(agsaSATAEventRsp_t, event));
4106   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaSATAEventRsp_t, tag));
4107 
4108   if (OSSA_IO_XFER_ERROR_ABORTED_NCQ_MODE != event)
4109   {
4110     /* get IORequest from IOMap */
4111     pRequest  = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
4112   }
4113   /* get port context - only for OSSA_IO_XFER_ERROR_ABORTED_NCQ_MODE */
4114   portId = (bit8)(portId_tmp & PORTID_MASK);
4115   SA_DBG2(("mpiSATAEvent:PortID 0x%x PortStatus 0x%x PortContext %p\n",saRoot->PortMap[portId & PORTID_MASK].PortID,saRoot->PortMap[portId & PORTID_MASK].PortStatus,saRoot->PortMap[portId & PORTID_MASK].PortContext));
4116   agPortContext = (agsaPortContext_t *)saRoot->PortMap[portId].PortContext;
4117   /* get device Id - only for OSSA_IO_XFER_ERROR_ABORTED_NCQ_MODE*/
4118   deviceIdx = deviceId & DEVICE_ID_BITS;
4119   OS_ASSERT(deviceIdx < MAX_IO_DEVICE_ENTRIES, "deviceIdx MAX_IO_DEVICE_ENTRIES");
4120   /* find device handle from device index */
4121   pDevice = (agsaDeviceDesc_t *)saRoot->DeviceMap[deviceIdx].DeviceHandle;
4122   agDevHandle = &(pDevice->targetDevHandle);
4123 
4124   /* get event */
4125   switch (event)
4126   {
4127     case OSSA_IO_OVERFLOW:
4128     {
4129       SA_DBG1(("mpiSATAEvent: OSSA_IO_OVERFLOW HTAG = 0x%x\n", tag));
4130       saRoot->IoEventCount.agOSSA_IO_OVERFLOW++;
4131       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4132       break;
4133     }
4134     case OSSA_IO_XFER_ERROR_BREAK:
4135     {
4136       SA_DBG1(("mpiSATAEvent: OSSA_IO_XFER_ERROR_BREAK HTAG = 0x%x\n", tag));
4137       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_BREAK++;
4138       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4139       break;
4140     }
4141     case OSSA_IO_XFER_ERROR_PHY_NOT_READY:
4142     {
4143       SA_DBG1(("mpiSATAEvent: OSSA_IO_XFER_ERROR_PHY_NOT_READY HTAG = 0x%x\n", tag));
4144       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_PHY_NOT_READY++;
4145       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4146       break;
4147     }
4148     case OSSA_IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED:
4149     {
4150       SA_DBG1(("mpiSATAEvent: OSSA_IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED HTAG = 0x%x\n", tag));
4151       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_PROTOCOL_NOT_SUPPORTED++;
4152       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4153       break;
4154     }
4155     case OSSA_IO_OPEN_CNX_ERROR_ZONE_VIOLATION:
4156     {
4157       SA_DBG1(("mpiSATAEvent: OSSA_IO_OPEN_CNX_ERROR_ZONE_VIOLATION HTAG = 0x%x\n", tag));
4158       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_ZONE_VIOLATION++;
4159       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4160       break;
4161     }
4162     case OSSA_IO_OPEN_CNX_ERROR_BREAK:
4163     {
4164       SA_DBG1(("mpiSATAEvent: OSSA_IO_OPEN_CNX_ERROR_BREAK HTAG = 0x%x\n", tag));
4165       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_BREAK++;
4166       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4167       break;
4168     }
4169 
4170     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST:
4171     {
4172       SA_DBG1(("mpiSATAEvent: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST HTAG = 0x%x\n", tag));
4173       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_NO_DEST++;
4174       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4175       break;
4176     }
4177     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE:
4178     {
4179       SA_DBG1(("mpiSATAEvent:  HTAG = 0x%x\n", tag));
4180       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_COLLIDE++;
4181       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4182       break;
4183     }
4184     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED:
4185     {
4186       SA_DBG1(("mpiSATAEvent:OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED  HTAG = 0x%x\n", tag));
4187       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_PATHWAY_BLOCKED++;
4188       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4189       break;
4190     }
4191     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS:
4192     {
4193       SA_DBG1(("mpiSATAEvent: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS HTAG = 0x%x\n", tag));
4194       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS++;
4195       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4196       break;
4197     }
4198     case OSSA_IO_OPEN_CNX_ERROR_BAD_DESTINATION:
4199     {
4200       SA_DBG1(("mpiSATAEvent: OSSA_IO_OPEN_CNX_ERROR_BAD_DESTINATION HTAG = 0x%x\n", tag));
4201       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_BAD_DESTINATION++;
4202       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4203       break;
4204     }
4205     case OSSA_IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED:
4206     {
4207       SA_DBG1(("mpiSATAEvent: OSSA_IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED HTAG = 0x%x\n", tag));
4208       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_CONNECTION_RATE_NOT_SUPPORTED++;
4209       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4210       break;
4211     }
4212     case OSSA_IO_OPEN_CNX_ERROR_WRONG_DESTINATION:
4213     {
4214       SA_DBG1(("mpiSATAEvent: OSSA_IO_OPEN_CNX_ERROR_WRONG_DESTINATION HTAG = 0x%x\n", tag));
4215       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_WRONG_DESTINATION++;
4216       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4217       break;
4218     }
4219     case OSSA_IO_XFER_ERROR_NAK_RECEIVED:
4220     {
4221       SA_DBG1(("mpiSATAEvent: OSSA_IO_XFER_ERROR_NAK_RECEIVED HTAG = 0x%x\n", tag));
4222       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_NAK_RECEIVED++;
4223       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4224       break;
4225     }
4226     case OSSA_IO_XFER_ERROR_ABORTED_NCQ_MODE:
4227     {
4228       SA_DBG1(("mpiSATAEvent: OSSA_IO_XFER_ERROR_ABORTED_NCQ_MODE HTAG = 0x%x\n", tag));
4229       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_ABORTED_NCQ_MODE++;
4230       ossaSATAEvent(agRoot, agNULL, agPortContext, agDevHandle, event, 0, agNULL);
4231       break;
4232     }
4233     case OSSA_IO_XFER_ERROR_OFFSET_MISMATCH:
4234     {
4235       SA_DBG1(("mpiSATAEvent: OSSA_IO_XFER_ERROR_OFFSET_MISMATCH HTAG = 0x%x\n", tag));
4236       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_OFFSET_MISMATCH++;
4237       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4238       break;
4239     }
4240     case OSSA_IO_XFER_ERROR_XFER_ZERO_DATA_LEN:
4241     {
4242       SA_DBG1(("mpiSATAEvent: OSSA_IO_XFER_ERROR_XFER_ZERO_DATA_LEN HTAG = 0x%x\n", tag));
4243       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_XFER_ZERO_DATA_LEN++;
4244       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4245       break;
4246     }
4247     case OSSA_IO_XFER_OPEN_RETRY_TIMEOUT:
4248     {
4249       SA_DBG1(("mpiSATAEvent: OSSA_IO_XFER_OPEN_RETRY_TIMEOUT HTAG = 0x%x\n", tag));
4250       saRoot->IoEventCount.agOSSA_IO_XFER_OPEN_RETRY_TIMEOUT++;
4251       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4252       break;
4253     }
4254     case OSSA_IO_XFER_ERROR_PEER_ABORTED:
4255     {
4256       SA_DBG1(("mpiSATAEvent: OSSA_IO_XFER_ERROR_PEER_ABORTED HTAG = 0x%x\n", tag));
4257       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_PEER_ABORTED++;
4258       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4259       break;
4260     }
4261     case OSSA_IO_XFER_CMD_FRAME_ISSUED:
4262     {
4263       SA_DBG1(("mpiSATAEvent: OSSA_IO_XFER_CMD_FRAME_ISSUED HTAG = 0x%x\n", tag));
4264       saRoot->IoEventCount.agOSSA_IO_XFER_CMD_FRAME_ISSUED++;
4265       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4266       break;
4267     }
4268     case OSSA_IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY:
4269     {
4270       SA_DBG1(("mpiSATAEvent, OSSA_IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY HTAG = 0x%x\n", tag));
4271       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_STP_RESOURCES_BUSY++;
4272       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4273       break;
4274     }
4275     case OSSA_IO_XFER_ERROR_UNEXPECTED_PHASE:
4276     {
4277       SA_DBG1(("mpiSATAEvent, OSSA_IO_XFER_ERROR_UNEXPECTED_PHASE HTAG = 0x%x\n", tag));
4278       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_UNEXPECTED_PHASE++;
4279       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4280       break;
4281     }
4282     case OSSA_IO_XFER_ERROR_XFER_RDY_OVERRUN:
4283     {
4284       SA_DBG1(("mpiSATAEvent, OSSA_IO_XFER_ERROR_XFER_RDY_OVERRUN HTAG = 0x%x\n", tag));
4285       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_XFER_RDY_OVERRUN++;
4286       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4287       break;
4288     }
4289     case OSSA_IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED:
4290     {
4291       SA_DBG1(("mpiSATAEvent, OSSA_IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED HTAG = 0x%x\n", tag));
4292       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_XFER_RDY_NOT_EXPECTED++;
4293       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4294       break;
4295     }
4296     case OSSA_IO_XFER_PIO_SETUP_ERROR:
4297     {
4298       SA_DBG1(("mpiSATAEvent: OSSA_IO_XFER_PIO_SETUP_ERROR HTAG = 0x%x\n", tag));
4299       saRoot->IoEventCount.agOSSA_IO_XFER_PIO_SETUP_ERROR++;
4300       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4301       break;
4302     }
4303     case OSSA_IO_XFR_ERROR_DIF_MISMATCH:
4304     {
4305       SA_DBG1(("mpiSATAEvent: OSSA_IO_XFR_ERROR_DIF_MISMATCH HTAG = 0x%x\n", tag));
4306       saRoot->IoEventCount.agOSSA_IO_XFR_ERROR_DIF_MISMATCH++;
4307       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4308       break;
4309     }
4310     case OSSA_IO_XFR_ERROR_INTERNAL_CRC_ERROR:
4311     {
4312       SA_DBG1(("mpiSATAEvent: OSSA_IO_XFR_ERROR_INTERNAL_CRC_ERROR HTAG = 0x%x\n", tag));
4313       saRoot->IoEventCount.agOSSA_IO_XFR_ERROR_INTERNAL_CRC_ERROR++;
4314       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4315       break;
4316     }
4317     case OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED:
4318     {
4319       SA_DBG1(("mpiSATAEvent: OSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED HTAG = 0x%x\n", tag));
4320       saRoot->IoEventCount.agOSSA_IO_OPEN_CNX_ERROR_IT_NEXUS_LOSS_OPEN_RETRY_BACKOFF_THRESHOLD_REACHED++;
4321       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4322       break;
4323     }
4324     case OSSA_IO_XFER_ERR_EOB_DATA_OVERRUN:
4325     {
4326       SA_DBG1(("mpiSATAEvent: OSSA_IO_XFER_ERR_EOB_DATA_OVERRUN HTAG = 0x%x\n", tag));
4327       saRoot->IoEventCount.agOSSA_IO_XFER_ERR_EOB_DATA_OVERRUN++;
4328       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4329       break;
4330     }
4331     case OSSA_IO_XFER_ERROR_DMA_ACTIVATE_TIMEOUT:
4332     {
4333       SA_DBG1(("mpiSATAEvent: OSSA_IO_XFER_ERROR_DMA_ACTIVATE_TIMEOUT HTAG = 0x%x\n", tag));
4334       saRoot->IoEventCount.agOSSA_IO_XFER_ERROR_DMA_ACTIVATE_TIMEOUT++;
4335       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4336       break;
4337     }
4338     default:
4339     {
4340       SA_DBG1(("mpiSATAEvent: Unknown Event 0x%x HTAG = 0x%x\n", event, tag));
4341       saRoot->IoEventCount.agOSSA_IO_UNKNOWN_ERROR++;
4342       ossaSATAEvent(agRoot, pRequest->pIORequestContext, agPortContext, agDevHandle, event, 0, agNULL);
4343       break;
4344     }
4345   }
4346 
4347   /* return value */
4348   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2w");
4349   return ret;
4350 }
4351 
4352 /******************************************************************************/
4353 /*! \brief Set NVM Data Response
4354  *
4355  *  This routine handles the response of SET NVM Data Response
4356  *
4357  *  \param agRoot       Handles for this instance of SAS/SATA LLL
4358  *  \param pIomb        Pointer of IOMB Mesage
4359  *
4360  *  \return sucess or fail
4361  *
4362  */
4363 /*******************************************************************************/
4364 GLOBAL bit32 mpiSetNVMDataRsp(
4365   agsaRoot_t          *agRoot,
4366   agsaSetNVMDataRsp_t *pIomb
4367   )
4368 {
4369   bit32               ret = AGSA_RC_SUCCESS;
4370   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
4371   agsaIORequestDesc_t *pRequest;
4372   agsaContext_t       *agContext;
4373   bit32               tag, status, iPTdaBnDpsAsNvm;
4374 
4375   smTraceFuncEnter(hpDBG_VERY_LOUD,"2x");
4376 
4377   SA_DBG1(("mpiSetNVMDataRsp: HTag=0x%x\n", pIomb->tag));
4378 
4379   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaSetNVMDataRsp_t, tag));
4380   OSSA_READ_LE_32(AGROOT, &iPTdaBnDpsAsNvm, pIomb, OSSA_OFFSET_OF(agsaSetNVMDataRsp_t, iPTdaBnDpsAsNvm));
4381   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaSetNVMDataRsp_t, status));
4382 
4383   /* get request from IOMap */
4384   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
4385   if (agNULL == pRequest)
4386   {
4387     SA_DBG1(("mpiSetNVMDataRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
4388     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2x");
4389     return AGSA_RC_FAILURE;
4390   }
4391 
4392   agContext = saRoot->IOMap[tag].agContext;
4393   /* remove the request from IOMap */
4394   saRoot->IOMap[tag].Tag = MARK_OFF;
4395   saRoot->IOMap[tag].IORequest = agNULL;
4396   saRoot->IOMap[tag].agContext = agNULL;
4397 
4398   SA_ASSERT((pRequest->valid), "pRequest->valid");
4399 
4400   if (((iPTdaBnDpsAsNvm & NVMD_TYPE) == AGSA_NVMD_CONFIG_SEEPROM) ||
4401       ((iPTdaBnDpsAsNvm & NVMD_TYPE) == AGSA_NVMD_VPD_FLASH) ||
4402       ((iPTdaBnDpsAsNvm & NVMD_TYPE) == AGSA_NVMD_TWI_DEVICES))
4403   {
4404     /* CB for VPD for SEEPROM-0, VPD_FLASH and TWI */
4405     ossaSetNVMDResponseCB(agRoot, agContext, (status & NVMD_STAT));
4406   }
4407   else
4408   {
4409     /* should not happend */
4410     SA_DBG1(("mpiSetNVMDataRsp: NVMD is wrong. TAG=0x%x STATUS=0x%x\n", tag, (iPTdaBnDpsAsNvm & NVMD_TYPE)));
4411     ret = AGSA_RC_FAILURE;
4412   }
4413 
4414   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
4415   pRequest->valid = agFALSE;
4416   /* return the request to free pool */
4417   saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
4418   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
4419 
4420   /* return value */
4421   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2x");
4422   return ret;
4423 }
4424 
4425 /******************************************************************************/
4426 /*! \brief SPC MPI SSP ABORT Response
4427  *
4428  *  This function handles the SSP Abort Response.
4429  *
4430  *  \param agRoot       Handles for this instance of SAS/SATA LLL
4431  *  \param pIomb        pointer of Message
4432  *
4433  *  \return The read value
4434  *
4435  */
4436 /*******************************************************************************/
4437 GLOBAL bit32 mpiSSPAbortRsp(
4438   agsaRoot_t         *agRoot,
4439   agsaSSPAbortRsp_t  *pIomb
4440   )
4441 {
4442   bit32               ret = AGSA_RC_SUCCESS;
4443   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
4444   agsaIORequestDesc_t *pRequest;
4445   agsaDeviceDesc_t    *pDevice;
4446   bit32               tag, status, scope;
4447   smTraceFuncEnter(hpDBG_VERY_LOUD,"2y");
4448 
4449   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaSSPAbortRsp_t, tag));
4450   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaSSPAbortRsp_t, status));
4451   OSSA_READ_LE_32(AGROOT, &scope, pIomb, OSSA_OFFSET_OF(agsaSSPAbortRsp_t, scp));
4452   scope &= 3;
4453   /* get IORequest from IOMap */
4454   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
4455 
4456   if (agNULL == pRequest)
4457   {
4458     /* remove the SSP_ABORT or SATA_ABORT request from IOMap */
4459     saRoot->IOMap[tag].Tag = MARK_OFF;
4460     saRoot->IOMap[tag].IORequest = agNULL;
4461     SA_ASSERT((pRequest), "pRequest");
4462     SA_DBG1(("mpiSSPAbortRsp: the request is NULL. Tag=%x\n", tag));
4463     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2y");
4464     return AGSA_RC_FAILURE;
4465   }
4466 
4467 
4468   if ( agTRUE == pRequest->valid )
4469   {
4470     pDevice = pRequest->pDevice;
4471     SA_ASSERT((pRequest->pDevice), "pRequest->pDevice");
4472 
4473     SA_DBG3(("mpiSSPAbortRsp: request abort is valid Htag 0x%x\n", tag));
4474     /* remove the SSP_ABORT or SATA_ABORT request from IOMap */
4475     saRoot->IOMap[tag].Tag = MARK_OFF;
4476     saRoot->IOMap[tag].IORequest = agNULL;
4477 
4478     if( pRequest->completionCB == agNULL )
4479     {
4480       ossaSSPAbortCB(agRoot, pRequest->pIORequestContext, scope, status);
4481     }
4482     else
4483     {
4484       (*(ossaGenericAbortCB_t)(pRequest->completionCB))(agRoot, pRequest->pIORequestContext, scope, status);
4485     }
4486 
4487     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
4488     pRequest->valid = agFALSE;
4489     /* Delete the request from the pendingIORequests */
4490     saLlistIORemove(&(pDevice->pendingIORequests), &(pRequest->linkNode));
4491 
4492     if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
4493     {
4494       SA_DBG1(("mpiSSPAbortRsp: saving pRequest (%p) for later use\n", pRequest));
4495       saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
4496     }
4497     else
4498     {
4499       /* return the request to free pool */
4500       saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
4501     }
4502 
4503     if(scope)
4504     {
4505       siCountActiveIORequestsOnDevice( agRoot, pDevice->DeviceMapIndex );
4506     }
4507 
4508     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
4509 
4510   }
4511   else
4512   {
4513     ret = AGSA_RC_FAILURE;
4514     SA_DBG1(("mpiSSPAbortRsp: the request is not valid any more. Tag=%x\n", pRequest->HTag));
4515   }
4516 
4517   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2y");
4518   return ret;
4519 }
4520 
4521 /******************************************************************************/
4522 /*! \brief SPC MPI SATA ABORT Response
4523  *
4524  *  This function handles the SATA Event.
4525  *
4526  *  \param agRoot       Handles for this instance of SAS/SATA LLL
4527  *  \param pIomb        pointer of Message
4528  *
4529  *  \return The read value
4530  *
4531  */
4532 /*******************************************************************************/
4533 GLOBAL bit32 mpiSATAAbortRsp(
4534   agsaRoot_t         *agRoot,
4535   agsaSATAAbortRsp_t *pIomb
4536   )
4537 {
4538   bit32               ret = AGSA_RC_SUCCESS;
4539   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
4540   agsaIORequestDesc_t *pRequest;
4541   agsaDeviceDesc_t    *pDevice;
4542   bit32               tag, status, scope;
4543 
4544   smTraceFuncEnter(hpDBG_VERY_LOUD,"3B");
4545   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaSATAAbortRsp_t, tag));
4546   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaSATAAbortRsp_t, status));
4547   OSSA_READ_LE_32(AGROOT, &scope, pIomb, OSSA_OFFSET_OF(agsaSATAAbortRsp_t, scp));
4548 
4549   /* get IORequest from IOMap */
4550   pRequest  = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
4551 
4552   if (agNULL == pRequest)
4553   {
4554     /* remove the SSP_ABORT or SATA_ABORT request from IOMap */
4555     saRoot->IOMap[tag].Tag = MARK_OFF;
4556     saRoot->IOMap[tag].IORequest = agNULL;
4557     SA_DBG1(("mpiSATAAbortRsp: the request is NULL. Tag=%x\n", tag));
4558     SA_ASSERT((pRequest), "pRequest");
4559     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3B");
4560     return AGSA_RC_FAILURE;
4561   }
4562 
4563   if ( agTRUE == pRequest->valid )
4564   {
4565     pDevice = pRequest->pDevice;
4566     SA_ASSERT((pRequest->pDevice), "pRequest->pDevice");
4567 
4568     SA_DBG3(("mpiSATAAbortRsp: request abort is valid Htag 0x%x\n", tag));
4569 
4570     if( pRequest->completionCB == agNULL )
4571     {
4572       ossaSATAAbortCB(agRoot, pRequest->pIORequestContext, scope, status);
4573     }
4574     else
4575     {
4576       (*(ossaGenericAbortCB_t)(pRequest->completionCB))(agRoot, pRequest->pIORequestContext, scope, status);
4577     }
4578     /* remove the SATA_ABORT request from IOMap */
4579     saRoot->IOMap[tag].Tag = MARK_OFF;
4580     saRoot->IOMap[tag].IORequest = agNULL;
4581     saRoot->IOMap[tag].agContext = agNULL;
4582 
4583     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
4584     pRequest->valid = agFALSE;
4585     /* Delete the request from the pendingIORequests */
4586     saLlistIORemove(&(pDevice->pendingIORequests), &(pRequest->linkNode));
4587     /* return the request to free pool */
4588     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
4589     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
4590 
4591   }
4592   else
4593   {
4594     ret = AGSA_RC_FAILURE;
4595     SA_DBG1(("mpiSATAAbortRsp: the request is not valid any more. Tag=%x\n", pRequest->HTag));
4596   }
4597 
4598 
4599   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3B");
4600   return ret;
4601 }
4602 
4603 /******************************************************************************/
4604 /*! \brief Set GPIO Response
4605  *
4606  *  This routine handles the response of GPIO Command
4607  *
4608  *  \param agRoot       Handles for this instance of SAS/SATA LLL
4609  *  \param pIomb        Pointer of IOMB Mesage
4610  *
4611  *  \return sucess or fail
4612  *
4613  */
4614 /*******************************************************************************/
4615 GLOBAL bit32 mpiGPIORsp(
4616   agsaRoot_t          *agRoot,
4617   agsaGPIORsp_t       *pIomb
4618   )
4619 {
4620   bit32                    ret = AGSA_RC_SUCCESS;
4621   agsaLLRoot_t             *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
4622   agsaContext_t            *agContext;
4623   agsaIORequestDesc_t      *pRequest;
4624   agsaGpioPinSetupInfo_t   pinSetupInfo;
4625   agsaGpioEventSetupInfo_t eventSetupInfo;
4626   bit32 GpioIe, OT11_0, OT19_12, GPIEVChange, GPIEVFall, GPIEVRise, GpioRdVal, tag;
4627 
4628   smTraceFuncEnter(hpDBG_VERY_LOUD,"5C");
4629 
4630   SA_DBG3(("mpiGPIORsp: HTag=0x%x\n", pIomb->tag));
4631 
4632   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaGPIORsp_t, tag));
4633 
4634   /* get request from IOMap */
4635   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
4636   if (agNULL == pRequest)
4637   {
4638     SA_DBG1(("mpiGPIORsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x\n", tag));
4639     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "5C");
4640     return AGSA_RC_FAILURE;
4641   }
4642 
4643   agContext = saRoot->IOMap[tag].agContext;
4644   /* remove the request from IOMap */
4645   saRoot->IOMap[tag].Tag = MARK_OFF;
4646   saRoot->IOMap[tag].IORequest = agNULL;
4647   saRoot->IOMap[tag].agContext = agNULL;
4648   SA_ASSERT((pRequest->valid), "pRequest->valid");
4649 
4650   /* set payload to zeros */
4651   si_memset(&pinSetupInfo, 0, sizeof(agsaGpioPinSetupInfo_t));
4652   si_memset(&eventSetupInfo, 0, sizeof(agsaGpioEventSetupInfo_t));
4653 
4654   OSSA_READ_LE_32(AGROOT, &GpioIe, pIomb, OSSA_OFFSET_OF(agsaGPIORsp_t, GpioIe));
4655   OSSA_READ_LE_32(AGROOT, &OT11_0, pIomb, OSSA_OFFSET_OF(agsaGPIORsp_t, OT11_0));
4656   OSSA_READ_LE_32(AGROOT, &OT19_12, pIomb, OSSA_OFFSET_OF(agsaGPIORsp_t, OT19_12));
4657   OSSA_READ_LE_32(AGROOT, &GPIEVChange, pIomb, OSSA_OFFSET_OF(agsaGPIORsp_t, GPIEVChange));
4658   OSSA_READ_LE_32(AGROOT, &GPIEVFall, pIomb, OSSA_OFFSET_OF(agsaGPIORsp_t, GPIEVFall));
4659   OSSA_READ_LE_32(AGROOT, &GPIEVRise, pIomb, OSSA_OFFSET_OF(agsaGPIORsp_t, GPIEVRise));
4660   OSSA_READ_LE_32(AGROOT, &GpioRdVal, pIomb, OSSA_OFFSET_OF(agsaGPIORsp_t, GpioRdVal));
4661   pinSetupInfo.gpioInputEnabled = GpioIe;
4662   pinSetupInfo.gpioTypePart1 = OT11_0;
4663   pinSetupInfo.gpioTypePart2 = OT19_12;
4664   eventSetupInfo.gpioEventLevel = GPIEVChange;
4665   eventSetupInfo.gpioEventFallingEdge = GPIEVFall;
4666   eventSetupInfo.gpioEventRisingEdge = GPIEVRise;
4667 
4668   ossaGpioResponseCB(agRoot, agContext, OSSA_IO_SUCCESS, GpioRdVal,
4669                      &pinSetupInfo,
4670                      &eventSetupInfo);
4671 
4672   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
4673   pRequest->valid = agFALSE;
4674   /* return the request to free pool */
4675   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
4676   {
4677     SA_DBG1(("mpiGPIORsp: saving pRequest (%p) for later use\n", pRequest));
4678     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
4679   }
4680   else
4681   {
4682     /* return the request to free pool */
4683     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
4684   }
4685   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
4686 
4687   /* return value */
4688   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "5C");
4689   return ret;
4690 }
4691 
4692 /******************************************************************************/
4693 /*! \brief Set GPIO Event Response
4694  *
4695  *  This routine handles the response of GPIO Event
4696  *
4697  *  \param agRoot       Handles for this instance of SAS/SATA LLL
4698  *  \param pIomb        Pointer of IOMB Mesage
4699  *
4700  *  \return sucess or fail
4701  *
4702  */
4703 /*******************************************************************************/
4704 GLOBAL bit32 mpiGPIOEventRsp(
4705   agsaRoot_t          *agRoot,
4706   agsaGPIOEvent_t     *pIomb
4707   )
4708 {
4709   bit32       ret = AGSA_RC_SUCCESS;
4710   bit32       GpioEvent;
4711 
4712   smTraceFuncEnter(hpDBG_VERY_LOUD,"3D");
4713 
4714   OSSA_READ_LE_32(AGROOT, &GpioEvent, pIomb, OSSA_OFFSET_OF(agsaGPIOEvent_t, GpioEvent));
4715 
4716   ossaGpioEvent(agRoot, GpioEvent);
4717 
4718   /* return value */
4719   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3D");
4720   return ret;
4721 }
4722 
4723 /******************************************************************************/
4724 /*! \brief SAS Diagnostic Start/End Response
4725  *
4726  *  This routine handles the response of SAS Diagnostic Start/End Command
4727  *
4728  *  \param agRoot       Handles for this instance of SAS/SATA LLL
4729  *  \param pIomb        Pointer of IOMB Mesage
4730  *
4731  *  \return sucess or fail
4732  *
4733  */
4734 /*******************************************************************************/
4735 GLOBAL bit32 mpiSASDiagStartEndRsp(
4736   agsaRoot_t               *agRoot,
4737   agsaSASDiagStartEndRsp_t *pIomb
4738   )
4739 {
4740   bit32               ret = AGSA_RC_SUCCESS;
4741   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
4742   agsaIORequestDesc_t *pRequest;
4743   agsaContext_t       *agContext;
4744   bit32               tag, Status;
4745 
4746   smTraceFuncEnter(hpDBG_VERY_LOUD,"2F");
4747 
4748   SA_DBG3(("mpiSASDiagStartEndRsp: HTAG=0x%x\n", pIomb->tag));
4749 
4750   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaSASDiagStartEndRsp_t, tag));
4751   OSSA_READ_LE_32(AGROOT, &Status, pIomb, OSSA_OFFSET_OF(agsaSASDiagStartEndRsp_t, Status));
4752 
4753   /* get request from IOMap */
4754   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
4755   if (agNULL == pRequest)
4756   {
4757     SA_DBG1(("mpiSASDiagStartEndRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, Status));
4758     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2F");
4759     return AGSA_RC_FAILURE;
4760   }
4761 
4762   agContext = saRoot->IOMap[tag].agContext;
4763   /* remove the request from IOMap */
4764   saRoot->IOMap[tag].Tag = MARK_OFF;
4765   saRoot->IOMap[tag].IORequest = agNULL;
4766   saRoot->IOMap[tag].agContext = agNULL;
4767 
4768   SA_ASSERT((pRequest->valid), "pRequest->valid");
4769 
4770   switch(Status)
4771   {
4772 
4773     case OSSA_DIAG_SE_SUCCESS:
4774       SA_DBG3(("mpiSASDiagStartEndRsp: Status OSSA_DIAG_SE_SUCCESS 0x%X \n", Status));
4775       break;
4776     case OSSA_DIAG_SE_INVALID_PHY_ID:
4777       SA_DBG1(("mpiSASDiagStartEndRsp: Status OSSA_DIAG_SE_INVALID_PHY_ID 0x%X \n", Status));
4778       break;
4779     case OSSA_DIAG_PHY_NOT_DISABLED:
4780       SA_DBG1(("mpiSASDiagStartEndRsp: Status OSSA_DIAG_PHY_NOT_DISABLED Status 0x%X \n", Status));
4781       break;
4782     case OSSA_DIAG_OTHER_FAILURE:
4783       if(smIS_SPCV(agRoot))
4784       {
4785         SA_DBG1(("mpiSASDiagStartEndRsp: Status OSSA_DIAG_OTHER_FAILURE Status 0x%X \n", Status));
4786       }
4787       else
4788       {
4789         SA_DBG1(("mpiSASDiagStartEndRsp: Status OSSA_DIAG_OPCODE_INVALID Status 0x%X \n", Status));
4790       }
4791       break;
4792     default:
4793       SA_DBG1(("mpiSASDiagStartEndRsp:Status UNKNOWN 0x%X \n", Status));
4794       break;
4795   }
4796 
4797   ossaSASDiagStartEndCB(agRoot, agContext, Status);
4798 
4799   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
4800   pRequest->valid = agFALSE;
4801   /* return the request to free pool */
4802   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
4803   {
4804     SA_DBG1(("mpiSASDiagStartEndRsp: saving pRequest (%p) for later use\n", pRequest));
4805     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
4806   }
4807   else
4808   {
4809     /* return the request to free pool */
4810     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
4811   }
4812   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
4813 
4814   /* return value */
4815   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2F");
4816   return ret;
4817 }
4818 
4819 /******************************************************************************/
4820 /*! \brief SAS Diagnostic Execute Response
4821  *
4822  *  This routine handles the response of SAS Diagnostic Execute Command
4823  *
4824  *  \param agRoot       Handles for this instance of SAS/SATA LLL
4825  *  \param pIomb        Pointer of IOMB Mesage
4826  *
4827  *  \return sucess or fail
4828  *
4829  */
4830 /*******************************************************************************/
4831 GLOBAL bit32 mpiSASDiagExecuteRsp(
4832   agsaRoot_t               *agRoot,
4833   agsaSASDiagExecuteRsp_t  *pIomb
4834   )
4835 {
4836   bit32               ret = AGSA_RC_SUCCESS;
4837   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
4838   agsaIORequestDesc_t *pRequest;
4839   agsaContext_t       *agContext;
4840   bit32               tag, Status, CmdTypeDescPhyId, ReportData;
4841   smTraceFuncEnter(hpDBG_VERY_LOUD,"3G");
4842 
4843   SA_DBG3(("mpiSASDiagExecuteRsp: HTAG=0x%x\n", pIomb->tag));
4844 
4845   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaSASDiagExecuteRsp_t, tag));
4846   OSSA_READ_LE_32(AGROOT, &Status, pIomb, OSSA_OFFSET_OF(agsaSASDiagExecuteRsp_t, Status));
4847   OSSA_READ_LE_32(AGROOT, &CmdTypeDescPhyId, pIomb, OSSA_OFFSET_OF(agsaSASDiagExecuteRsp_t, CmdTypeDescPhyId));
4848   OSSA_READ_LE_32(AGROOT, &ReportData, pIomb, OSSA_OFFSET_OF(agsaSASDiagExecuteRsp_t, ReportData));
4849   /* get request from IOMap */
4850   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
4851   if (agNULL == pRequest)
4852   {
4853     SA_DBG1(("mpiSASDiagExecuteRsp: Bad Response IOMB!!! pRequest is NULL.TAG=0x%x STATUS=0x%x\n", tag, Status));
4854     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3G");
4855     return AGSA_RC_FAILURE;
4856   }
4857 
4858   switch(Status)
4859   {
4860 
4861     case OSSA_DIAG_SUCCESS:
4862       SA_DBG3(("mpiSASDiagExecuteRsp: Status OSSA_DIAG_SUCCESS 0x%X \n", Status));
4863       break;
4864     case OSSA_DIAG_INVALID_COMMAND:
4865       if(smIS_SPCV(agRoot))
4866       {
4867         SA_DBG1(("mpiSASDiagExecuteRsp: Status OSSA_DIAG_INVALID_COMMAND Status 0x%X \n", Status));
4868       }
4869       else
4870       {
4871         SA_DBG1(("mpiSASDiagExecuteRsp: Status OSSA_DIAG_FAIL Status 0x%X \n", Status));
4872       }
4873       break;
4874     case OSSA_REGISTER_ACCESS_TIMEOUT:
4875       SA_DBG1(("mpiSASDiagExecuteRsp: Status OSSA_REGISTER_ACCESS_TIMEOUT Status 0x%X \n", Status));
4876       break;
4877     case OSSA_DIAG_NOT_IN_DIAGNOSTIC_MODE:
4878       SA_DBG1(("mpiSASDiagExecuteRsp: Status OSSA_DIAG_NOT_IN_DIAGNOSTIC_MODE Status 0x%X \n", Status));
4879       break;
4880     case OSSA_DIAG_INVALID_PHY:
4881       SA_DBG1(("mpiSASDiagExecuteRsp: Status OSSA_DIAG_INVALID_PHY Status 0x%X \n", Status));
4882       break;
4883     case OSSA_MEMORY_ALLOC_FAILURE:
4884       SA_DBG1(("mpiSASDiagExecuteRsp: Status  Status 0x%X \n", Status));
4885       break;
4886 
4887     default:
4888       SA_DBG1(("mpiSASDiagExecuteRsp:Status UNKNOWN 0x%X \n", Status));
4889       break;
4890   }
4891 
4892 
4893   agContext = saRoot->IOMap[tag].agContext;
4894   /* remove the request from IOMap */
4895   saRoot->IOMap[tag].Tag = MARK_OFF;
4896   saRoot->IOMap[tag].IORequest = agNULL;
4897   saRoot->IOMap[tag].agContext = agNULL;
4898 
4899   SA_ASSERT((pRequest->valid), "pRequest->valid");
4900 
4901   ossaSASDiagExecuteCB(agRoot, agContext, Status, CmdTypeDescPhyId, ReportData);
4902 
4903   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
4904   pRequest->valid = agFALSE;
4905   /* return the request to free pool */
4906   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
4907   {
4908     SA_DBG1(("mpiSASDiagExecuteRsp: saving pRequest (%p) for later use\n", pRequest));
4909     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
4910   }
4911   else
4912   {
4913     /* return the request to free pool */
4914     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
4915   }
4916   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
4917 
4918   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3G");
4919 
4920   /* return value */
4921   return ret;
4922 }
4923 
4924 /******************************************************************************/
4925 /*! \brief SAS General Event Notification Response
4926  *
4927  *  This routine handles the response of Inbound IOMB Command with error case
4928  *
4929  *  \param agRoot       Handles for this instance of SAS/SATA LLL
4930  *  \param pIomb        Pointer of IOMB Mesage
4931  *
4932  *  \return sucess or fail
4933  *
4934  */
4935 /*******************************************************************************/
4936 GLOBAL bit32 mpiGeneralEventRsp(
4937   agsaRoot_t               *agRoot,
4938   agsaGeneralEventRsp_t    *pIomb
4939   )
4940 {
4941   bit32                 ret = AGSA_RC_SUCCESS;
4942   agsaLLRoot_t          *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
4943   bit32                 i;
4944   bit32                 status;
4945   bit32                 tag;
4946   agsaIORequestDesc_t   *pRequest;
4947   agsaDeviceDesc_t      *pDevice;
4948   agsaContext_t         *agContext = NULL;
4949   agsaGeneralEventRsp_t GenEventData;
4950   agsaHWEventEncrypt_t  agEvent;
4951   bit16                 OpCode = 0;
4952 
4953   smTraceFuncEnter(hpDBG_VERY_LOUD,"3H");
4954 
4955   si_memset(&GenEventData,0,sizeof(agsaGeneralEventRsp_t));
4956 
4957   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaGeneralEventRsp_t, status));
4958 
4959   SA_DBG3(("mpiGeneralEventRsp:  %p\n", pIomb));
4960 
4961   SA_DBG1(("mpiGeneralEventRsp: OpCode 0x%X status 0x%x\n",pIomb->inbIOMBpayload[0] & OPCODE_BITS, status));
4962 
4963   for (i = 0; i < GENERAL_EVENT_PAYLOAD; i++)
4964   {
4965     OSSA_READ_LE_32(AGROOT, &GenEventData.inbIOMBpayload[i], pIomb, OSSA_OFFSET_OF(agsaGeneralEventRsp_t,inbIOMBpayload[i] ));
4966   }
4967   SA_DBG1(("mpiGeneralEventRsp: inbIOMBpayload 0x%08x 0x%08x 0x%08x 0x%08x\n",
4968                                     GenEventData.inbIOMBpayload[0],GenEventData.inbIOMBpayload[1],
4969                                     GenEventData.inbIOMBpayload[2],GenEventData.inbIOMBpayload[3] ));
4970   SA_DBG1(("mpiGeneralEventRsp: inbIOMBpayload 0x%08x 0x%08x 0x%08x 0x%08x\n",
4971                                     GenEventData.inbIOMBpayload[4],GenEventData.inbIOMBpayload[8],
4972                                     GenEventData.inbIOMBpayload[6],GenEventData.inbIOMBpayload[7] ));
4973 
4974   switch (status) /*status  */
4975   {
4976 
4977     case GEN_EVENT_IOMB_V_BIT_NOT_SET:
4978       SA_DBG1(("mpiGeneralEventRsp: GEN_EVENT_IOMB_V_BIT_NOT_SET\n" ));
4979       break;
4980     case GEN_EVENT_INBOUND_IOMB_OPC_NOT_SUPPORTED:
4981       SA_DBG1(("mpiGeneralEventRsp: GEN_EVENT_INBOUND_IOMB_OPC_NOT_SUPPORTED\n" ));
4982       break;
4983     case GEN_EVENT_IOMB_INVALID_OBID:
4984       SA_DBG1(("mpiGeneralEventRsp: GEN_EVENT_IOMB_INVALID_OBID\n" ));
4985       break;
4986     case GEN_EVENT_DS_IN_NON_OPERATIONAL:
4987       SA_DBG1(("mpiGeneralEventRsp: GEN_EVENT_DS_IN_NON_OPERATIONAL\n" ));
4988       break;
4989     case GEN_EVENT_DS_IN_RECOVERY:
4990       SA_DBG1(("mpiGeneralEventRsp: GEN_EVENT_DS_IN_RECOVERY\n" ));
4991       break;
4992     case GEN_EVENT_DS_INVALID:
4993       SA_DBG1(("mpiGeneralEventRsp: GEN_EVENT_DS_INVALID\n" ));
4994       break;
4995     case GEN_EVENT_IO_XFER_READ_COMPL_ERR:
4996       SA_DBG1(("mpiGeneralEventRsp: GEN_EVENT_IO_XFER_READ_COMPL_ERR 0x%x 0x%x 0x%x\n",
4997                 GenEventData.inbIOMBpayload[0],
4998                 GenEventData.inbIOMBpayload[1],
4999                 GenEventData.inbIOMBpayload[1] ));
5000       ossaGeneralEvent(agRoot, status, agContext, GenEventData.inbIOMBpayload);
5001       smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3H");
5002       return(ret);
5003     default:
5004       SA_DBG1(("mpiGeneralEventRsp: Unknown General Event status!!! 0x%x\n", status));
5005       smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3H");
5006       return AGSA_RC_FAILURE;
5007   }
5008 
5009   OpCode = (bit16)(GenEventData.inbIOMBpayload[0] & OPCODE_BITS);
5010   tag = GenEventData.inbIOMBpayload[1];
5011   SA_DBG1(("mpiGeneralEventRsp:OpCode 0x%X [0] 0x%08x\n" ,OpCode,(bit16)(GenEventData.inbIOMBpayload[0] & OPCODE_BITS)));
5012 
5013   switch (OpCode) /* OpCode */
5014     {
5015       case OPC_INB_DEV_HANDLE_ACCEPT:
5016       case OPC_INB_ECHO:
5017       case OPC_INB_FW_FLASH_UPDATE:
5018       case OPC_INB_GET_NVMD_DATA:
5019       case OPC_INB_SET_NVMD_DATA:
5020       case OPC_INB_DEREG_DEV_HANDLE:
5021       case OPC_INB_SPC_GET_DEV_INFO:
5022       case OPC_INB_GET_DEV_HANDLE:
5023       case OPC_INB_SPC_REG_DEV:
5024       case OPC_INB_SAS_DIAG_EXECUTE:
5025       case OPC_INB_SAS_DIAG_MODE_START_END:
5026       case OPC_INB_PHYSTART:
5027       case OPC_INB_PHYSTOP:
5028       case OPC_INB_LOCAL_PHY_CONTROL:
5029       case OPC_INB_GPIO:
5030       case OPC_INB_GET_TIME_STAMP:
5031       case OPC_INB_PORT_CONTROL:
5032       case OPC_INB_SET_DEVICE_STATE:
5033       case OPC_INB_GET_DEVICE_STATE:
5034       case OPC_INB_SET_DEV_INFO:
5035 //      case OPC_INB_PCIE_DIAG_EXECUTE:
5036       case OPC_INB_SAS_HW_EVENT_ACK:
5037       case OPC_INB_SAS_RE_INITIALIZE:
5038       case OPC_INB_KEK_MANAGEMENT:
5039       case OPC_INB_SET_OPERATOR:
5040       case OPC_INB_GET_OPERATOR:
5041 //      case OPC_INB_SGPIO:
5042 
5043 #ifdef SPC_ENABLE_PROFILE
5044       case OPC_INB_FW_PROFILE:
5045 #endif
5046           /* Uses the tag table, so we have to free it up */
5047 
5048           SA_ASSERT((tag < AGSA_MAX_VALID_PORTS * saRoot->swConfig.maxActiveIOs),
5049                     "OPC_OUB_GENERAL_EVENT tag out of range");
5050           SA_ASSERT((saRoot->IOMap[ tag < (AGSA_MAX_VALID_PORTS * saRoot->swConfig.maxActiveIOs) ? tag : 0 ].Tag != MARK_OFF),
5051                     "OPC_OUB_GENERAL_EVENT tag not in use 1");
5052 
5053 #if defined(SALLSDK_DEBUG)
5054           if (tag > AGSA_MAX_VALID_PORTS * saRoot->swConfig.maxActiveIOs)
5055           {
5056             smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "3H");
5057             return AGSA_RC_FAILURE;
5058           }
5059 #endif /* SALLSDK_DEBUG */
5060 
5061           SA_DBG1(("mpiGeneralEventRsp:OpCode found 0x%x htag 0x%x\n",OpCode, tag));
5062           /* get agContext */
5063           agContext = saRoot->IOMap[tag].agContext;
5064           /* get request from IOMap */
5065           pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
5066           if(pRequest)
5067           {
5068             /* remove the request from IOMap */
5069             saRoot->IOMap[tag].Tag = MARK_OFF;
5070             saRoot->IOMap[tag].IORequest = agNULL;
5071             saRoot->IOMap[tag].agContext = agNULL;
5072 
5073             ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
5074             SA_ASSERT((pRequest->valid), "pRequest->valid");
5075             pRequest->valid = agFALSE;
5076             /* return the request to free pool */
5077             if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
5078             {
5079               SA_DBG1(("mpiGeneralEventRsp: saving pRequest (%p) for later use\n", pRequest));
5080               saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
5081             }
5082             else
5083             {
5084               /* return the request to free pool */
5085               saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
5086             }
5087             ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
5088           }
5089           else
5090           {
5091             SA_DBG1(("mpiGeneralEventRsp:pRequest (%p) NULL\n", pRequest));
5092             ret =  AGSA_RC_FAILURE;
5093           }
5094           break;
5095       /* ????  */
5096       case OPC_INB_SATA_HOST_OPSTART:
5097       case OPC_INB_SATA_ABORT:
5098       case OPC_INB_SSPINIIOSTART:
5099       case OPC_INB_SSPINITMSTART:
5100       case OPC_INB_SSPINIEXTIOSTART:
5101       case OPC_INB_SSPTGTIOSTART:
5102       case OPC_INB_SSPTGTRSPSTART:
5103       case OPC_INB_SSP_DIF_ENC_OPSTART:
5104       case OPC_INB_SATA_DIF_ENC_OPSTART:
5105 
5106       case OPC_INB_SSP_ABORT:
5107       case OPC_INB_SMP_REQUEST:
5108       case OPC_INB_SMP_ABORT:
5109       {
5110         /* Uses the tag table, so we have to free it up */
5111         SA_DBG1(("mpiGeneralEventRsp:OpCode found 0x%x htag 0x%x\n",OpCode, tag));
5112 
5113         tag = GenEventData.inbIOMBpayload[1];
5114 
5115         SA_ASSERT((tag < AGSA_MAX_VALID_PORTS * saRoot->swConfig.maxActiveIOs),
5116                   "OPC_OUB_GENERAL_EVENT tag out of range");
5117         SA_ASSERT((saRoot->IOMap[ tag < (AGSA_MAX_VALID_PORTS * saRoot->swConfig.maxActiveIOs) ? tag : 0 ].Tag != MARK_OFF),
5118                   "OPC_OUB_GENERAL_EVENT tag not in use 2");
5119 #if defined(SALLSDK_DEBUG)
5120         if (tag > AGSA_MAX_VALID_PORTS * saRoot->swConfig.maxActiveIOs)
5121         {
5122           smTraceFuncExit(hpDBG_VERY_LOUD, 'd', "3H");
5123           return AGSA_RC_FAILURE;
5124         }
5125 #endif
5126           /* get request from IOMap */
5127         pRequest  = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
5128         if(pRequest)
5129         {
5130           pDevice   = pRequest->pDevice;
5131           /* return the request to free pool */
5132           /* get IORequestContext */
5133           agContext = (agsaContext_t *)pRequest->pIORequestContext;
5134           /* remove the request from IOMap */
5135           saRoot->IOMap[tag].Tag = MARK_OFF;
5136           saRoot->IOMap[tag].IORequest = agNULL;
5137           saRoot->IOMap[tag].agContext = agNULL;
5138 
5139           ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
5140           SA_ASSERT((pRequest->valid), "pRequest->valid");
5141           pRequest->valid = agFALSE;
5142           saLlistIORemove(&(pDevice->pendingIORequests), &(pRequest->linkNode));
5143           if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
5144           {
5145             SA_DBG1(("mpiGeneralEventRsp: saving pRequest (%p) for later use\n", pRequest));
5146             saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
5147           }
5148           else
5149           {
5150             /* return the request to free pool */
5151             saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
5152           }
5153           ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
5154           break;
5155         }
5156         else
5157         {
5158           SA_DBG1(("mpiGeneralEventRsp:pRequest (%p) NULL\n", pRequest));
5159           ret =  AGSA_RC_FAILURE;
5160         }
5161       }
5162     default:
5163     {
5164         SA_DBG1(("mpiGeneralEventRsp:OpCode Not found 0x%x htag 0x%x\n",OpCode, tag));
5165         ret =  AGSA_RC_FAILURE;
5166 
5167         /* Uses the tag table, so we have to free it up */
5168         tag = GenEventData.inbIOMBpayload[1];
5169 
5170         SA_ASSERT((tag < AGSA_MAX_VALID_PORTS * saRoot->swConfig.maxActiveIOs),
5171                   "OPC_OUB_GENERAL_EVENT tag out of range");
5172         SA_ASSERT((saRoot->IOMap[ tag < (AGSA_MAX_VALID_PORTS * saRoot->swConfig.maxActiveIOs) ? tag : 0 ].Tag != MARK_OFF),
5173                   "OPC_OUB_GENERAL_EVENT tag not in use 3");
5174 
5175 #if defined(SALLSDK_DEBUG)
5176         if (tag > AGSA_MAX_VALID_PORTS * saRoot->swConfig.maxActiveIOs)
5177         {
5178           smTraceFuncExit(hpDBG_VERY_LOUD, 'e', "3H");
5179           return AGSA_RC_FAILURE;
5180         }
5181 #endif
5182         /* get agContext */
5183         agContext = saRoot->IOMap[tag].agContext;
5184         /* get request from IOMap */
5185         pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
5186         if (pRequest == agNULL)
5187         {
5188           smTraceFuncExit(hpDBG_VERY_LOUD, 'f', "3H");
5189           return AGSA_RC_FAILURE;
5190         }
5191 
5192         /* remove the request from IOMap */
5193         saRoot->IOMap[tag].Tag = MARK_OFF;
5194         saRoot->IOMap[tag].IORequest = agNULL;
5195         saRoot->IOMap[tag].agContext = agNULL;
5196 
5197         ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
5198         SA_ASSERT((pRequest->valid), "pRequest->valid");
5199         pRequest->valid = agFALSE;
5200         /* return the request to free pool */
5201         if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
5202         {
5203           SA_DBG1(("mpiGeneralEventRsp: saving pRequest (%p) for later use\n", pRequest));
5204           saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
5205         }
5206         else
5207         {
5208           /* return the request to free pool */
5209           saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
5210         }
5211         ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
5212         break;
5213       }
5214       ret =  AGSA_RC_FAILURE;
5215 
5216     }
5217 
5218   switch (OpCode) /* OpCode */
5219   {
5220 
5221     case OPC_INB_KEK_MANAGEMENT:
5222     {
5223       bit32 flags = GenEventData.inbIOMBpayload[2];
5224 
5225       SA_DBG1(("mpiGeneralEventRsp: OPC_INB_KEK_MANAGEMENT 0x%x htag 0x%x flags 0x%x\n",OpCode, tag, flags));
5226       if (flags & 0xFF00) /* update and store*/
5227       {
5228         agEvent.encryptOperation = OSSA_HW_ENCRYPT_KEK_UPDATE_AND_STORE;
5229         SA_DBG1(("mpiGeneralEventRsp: OSSA_HW_ENCRYPT_KEK_UPDATE_AND_STORE\n"));
5230       }
5231       else /* update */
5232       {
5233         agEvent.encryptOperation = OSSA_HW_ENCRYPT_KEK_UPDATE;
5234         SA_DBG1(("mpiGeneralEventRsp: OSSA_HW_ENCRYPT_KEK_UPDATE\n"));
5235       }
5236       agEvent.status = OSSA_INVALID_ENCRYPTION_SECURITY_MODE;
5237       si_memset(&agEvent, 0, sizeof(agsaHWEventEncrypt_t));
5238       agEvent.status = status;
5239 
5240       SA_DBG1(("mpiGeneralEventRsp: ossaHwCB OSSA_HW_EVENT_ENCRYPTION\n" ));
5241       ossaHwCB(agRoot, NULL, OSSA_HW_EVENT_ENCRYPTION, 0, (void*)&agEvent, agContext);
5242       break;
5243     }
5244     case OPC_INB_OPR_MGMT:
5245          si_memset(&agEvent, 0, sizeof(agsaHWEventEncrypt_t));
5246          agEvent.status = status;
5247          agEvent.encryptOperation = OSSA_HW_ENCRYPT_OPERATOR_MANAGEMENT;
5248 
5249          SA_DBG1(("mpiGeneralEventRsp: OSSA_HW_ENCRYPT_OPERATOR_MANAGEMENT\n" ));
5250          ossaOperatorManagementCB(agRoot, agContext, status, 0);
5251          break;
5252     case OPC_INB_SET_OPERATOR:
5253          SA_DBG1(("mpiGeneralEventRsp: OSSA_HW_ENCRYPT_SET_OPERATOR\n" ));
5254          ossaSetOperatorCB(agRoot,agContext,0xFF,0xFF );
5255          break;
5256     case OPC_INB_GET_OPERATOR:
5257          SA_DBG1(("mpiGeneralEventRsp: OSSA_HW_ENCRYPT_GET_OPERATOR\n" ));
5258          ossaGetOperatorCB(agRoot,agContext,0xFF,0xFF,0xFF,0xFF,agNULL );
5259          break;
5260     case OPC_INB_ENC_TEST_EXECUTE:
5261          si_memset(&agEvent, 0, sizeof(agsaHWEventEncrypt_t));
5262          agEvent.status = status;
5263          agEvent.encryptOperation = OSSA_HW_ENCRYPT_TEST_EXECUTE;
5264 
5265          SA_DBG1(("mpiGeneralEventRsp: OSSA_HW_ENCRYPT_TEST_EXECUTE\n" ));
5266          ossaHwCB(agRoot, NULL, OSSA_HW_EVENT_ENCRYPTION, 0, (void*)&agEvent, agContext);
5267          break;
5268     default:
5269          SA_DBG1(("mpiGeneralEventRsp: MGMNT OpCode Not found 0x%x\n",OpCode ));
5270          ossaGeneralEvent(agRoot, status, agContext, GenEventData.inbIOMBpayload);
5271          break;
5272   }
5273 
5274   /* return value */
5275   smTraceFuncExit(hpDBG_VERY_LOUD, 'g', "3H");
5276   return ret;
5277 }
5278 
5279 /******************************************************************************/
5280 /*! \brief SPC MPI SSP Request Received Event (target mode)
5281  *
5282  *  This function handles the SSP Request Received Event.
5283  *
5284  *  \param agRoot       Handles for this instance of SAS/SATA LLL
5285  *  \param pMsg1        pointer of Message
5286  *
5287  *  \return The read value
5288  *
5289  */
5290 /*******************************************************************************/
5291 GLOBAL bit32 mpiSSPReqReceivedNotify(
5292   agsaRoot_t *agRoot,
5293   agsaSSPReqReceivedNotify_t *pMsg1)
5294 {
5295   bit32            ret = AGSA_RC_SUCCESS;
5296   agsaLLRoot_t     *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
5297   agsaDeviceDesc_t *pDevice;
5298   bit32            deviceid, iniTagSSPIul, frameTypeHssa, TlrHdsa;
5299 
5300   smTraceFuncEnter(hpDBG_VERY_LOUD,"3J");
5301   /* convert endiness if necassary */
5302   OSSA_READ_LE_32(AGROOT, &deviceid, pMsg1, OSSA_OFFSET_OF(agsaSSPReqReceivedNotify_t, deviceId));
5303   OSSA_READ_LE_32(AGROOT, &iniTagSSPIul, pMsg1, OSSA_OFFSET_OF(agsaSSPReqReceivedNotify_t, iniTagSSPIul));
5304   OSSA_READ_LE_32(AGROOT, &frameTypeHssa, pMsg1, OSSA_OFFSET_OF(agsaSSPReqReceivedNotify_t, frameTypeHssa));
5305   OSSA_READ_LE_32(AGROOT, &TlrHdsa, pMsg1, OSSA_OFFSET_OF(agsaSSPReqReceivedNotify_t, TlrHdsa));
5306   /* deviceId -> agDeviceHandle */
5307   pDevice = (agsaDeviceDesc_t *)saRoot->DeviceMap[deviceid & DEVICE_ID_BITS].DeviceHandle;
5308 
5309   if (agNULL == pDevice)
5310   {
5311     SA_DBG1(("mpiSSPReqReceivedNotify: warning!!! no deviceHandle is found"));
5312   }
5313   else
5314   {
5315     /* type punning only safe through char *. See gcc -fstrict_aliasing. */
5316     char * safe_type_pun = (char *)&(pMsg1->SSPIu[0]);
5317     if( pDevice->initiatorDevHandle.sdkData != agNULL)
5318     {
5319       ossaSSPReqReceived(agRoot, &(pDevice->initiatorDevHandle),
5320                         (agsaFrameHandle_t *)safe_type_pun,
5321                         (bit16)((iniTagSSPIul >> SHIFT16) & INITTAG_BITS),
5322                         ((frameTypeHssa >> SHIFT24) & FRAME_TYPE) |
5323                        ((TlrHdsa >> SHIFT16) & TLR_BITS),
5324                         (iniTagSSPIul & SSPIUL_BITS));
5325     }else if( pDevice->targetDevHandle.sdkData != agNULL)
5326     {
5327       ossaSSPReqReceived(agRoot, &(pDevice->targetDevHandle),
5328                         (agsaFrameHandle_t *)safe_type_pun,
5329                         (bit16)((iniTagSSPIul >> SHIFT16) & INITTAG_BITS),
5330                         ((frameTypeHssa >> SHIFT24) & FRAME_TYPE) |
5331                        ((TlrHdsa >> SHIFT16) & TLR_BITS),
5332                         (iniTagSSPIul & SSPIUL_BITS));
5333     }else
5334     {
5335       SA_ASSERT(0, "Device handle sdkData not set");
5336     }
5337   }
5338 
5339   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3J");
5340   return ret;
5341 }
5342 
5343 /******************************************************************************/
5344 /*! \brief SPC MPI Device Handle Arrived Event (target mode)
5345  *
5346  *  This function handles the Device Handle Arrived Event.
5347  *
5348  *  \param agRoot       Handles for this instance of SAS/SATA LLL
5349  *  \param pMsg1        pointer of Message
5350  *
5351  *  \return The read value
5352  *
5353  */
5354 /*******************************************************************************/
5355 GLOBAL bit32 mpiDeviceHandleArrived(
5356   agsaRoot_t *agRoot,
5357   agsaDeviceHandleArrivedNotify_t *pMsg1)
5358 {
5359   bit32               ret = AGSA_RC_SUCCESS;
5360   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
5361   agsaDeviceDesc_t    *pDevice;
5362   agsaPort_t          *pPort;
5363   agsaSASDeviceInfo_t pDeviceInfo;
5364   agsaPortContext_t   *agPortContext;
5365   agsaSASIdentify_t   remoteIdentify;
5366   bit32               CTag;
5367   bit32               FwdDeviceId;
5368   bit32               ProtConrPortId;
5369   bit32               portId;
5370   bit32               conRate;
5371   bit8                i, protocol, dTypeSRate;
5372   bit32               HostAssignedId;
5373 
5374   if(saRoot == agNULL)
5375   {
5376     SA_ASSERT((saRoot != agNULL), "saRoot");
5377     return AGSA_RC_FAILURE;
5378   }
5379 
5380   smTraceFuncEnter(hpDBG_VERY_LOUD,"3L");
5381   /* convert endiness if necassary */
5382   OSSA_READ_LE_32(AGROOT, &CTag, pMsg1, OSSA_OFFSET_OF(agsaDeviceHandleArrivedNotify_t, CTag));
5383   OSSA_READ_LE_32(AGROOT, &FwdDeviceId, pMsg1, OSSA_OFFSET_OF(agsaDeviceHandleArrivedNotify_t, HostAssignedIdFwdDeviceId));
5384   OSSA_READ_LE_32(AGROOT, &ProtConrPortId, pMsg1, OSSA_OFFSET_OF(agsaDeviceHandleArrivedNotify_t, ProtConrPortId));
5385 
5386 
5387   if(smIS_SPCV(agRoot))
5388   {
5389     portId = ProtConrPortId & PortId_V_MASK;
5390     conRate = (ProtConrPortId & Conrate_V_MASK ) >> Conrate_V_SHIFT;
5391 
5392     HostAssignedId = (FwdDeviceId & 0xFFFF0000) >> SHIFT16;
5393     if(HostAssignedId)
5394     {
5395       SA_DBG1(("mpiDeviceHandleArrived: HostAssignedId 0x%X\n",HostAssignedId));
5396     }
5397   }
5398   else
5399   {
5400     portId = ProtConrPortId & PortId_SPC_MASK;
5401     conRate = (ProtConrPortId & Conrate_SPC_MASK ) >> Conrate_SPC_SHIFT;
5402   }
5403   protocol =(bit8)((ProtConrPortId & PROTOCOL_BITS ) >> PROTOCOL_SHIFT);
5404 
5405   SA_DBG1(("mpiDeviceHandleArrived: New Port portID %d deviceid 0x%X conRate 0x%X protocol 0x%X\n",portId, FwdDeviceId,conRate,protocol));
5406 
5407   /* Port Map */
5408   agPortContext = saRoot->PortMap[portId].PortContext;
5409   if (agNULL == agPortContext)
5410   {
5411     ossaSingleThreadedEnter(agRoot, LL_PORT_LOCK);
5412     /* new port */
5413     /* Acquire port list lock */
5414     /* Allocate a free port */
5415     pPort = (agsaPort_t *) saLlistGetHead(&(saRoot->freePorts));
5416     if (agNULL != pPort)
5417     {
5418       saLlistRemove(&(saRoot->freePorts), &(pPort->linkNode));
5419 
5420       /* setup the port data structure */
5421       pPort->portContext.osData = agNULL;
5422       pPort->portContext.sdkData = pPort;
5423       pPort->tobedeleted = agFALSE;
5424       /* Add to valid port list */
5425       saLlistAdd(&(saRoot->validPorts), &(pPort->linkNode));
5426       /* Release port list lock */
5427       ossaSingleThreadedLeave(agRoot, LL_PORT_LOCK);
5428 
5429       /* Setup portMap based on portId */
5430       saRoot->PortMap[portId].PortID = portId;
5431       saRoot->PortMap[portId].PortContext = &(pPort->portContext);
5432       saRoot->PortMap[portId].PortStatus  &= ~PORT_INVALIDATING;
5433       pPort->portId = portId;
5434 
5435       pPort->status &= ~PORT_INVALIDATING;
5436       SA_DBG3(("mpiDeviceHandleArrived: ~PORT_INVALIDATING New Port portID %d PortContext %p\n",saRoot->PortMap[pPort->portId].PortID , &pPort->portContext));
5437     }
5438     else
5439     {
5440       ossaSingleThreadedLeave(agRoot, LL_PORT_LOCK);
5441       SA_DBG2(("mpiDeviceHandleArrived:Port NULL\n"));
5442       /* pPort is agNULL*/
5443       smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3L");
5444       return AGSA_RC_FAILURE;
5445     }
5446   }
5447   else
5448   {
5449     /* exist port */
5450     pPort = (agsaPort_t *) (agPortContext->sdkData);
5451     pPort->status &= ~PORT_INVALIDATING;
5452     pPort->portId =portId;
5453     saRoot->PortMap[pPort->portId].PortStatus  &= ~PORT_INVALIDATING;
5454 
5455     SA_DBG1(("mpiDeviceHandleArrived: ~PORT_INVALIDATING Old port portID %d PortContext %p\n", portId, &pPort->portContext));
5456 
5457   }
5458   /* build Device Information structure */
5459   si_memset(&pDeviceInfo, 0, sizeof(agsaSASDeviceInfo_t));
5460   if (ProtConrPortId & PROTOCOL_BITS)
5461   {
5462     protocol = SA_IDFRM_SSP_BIT; /* SSP */
5463     pDeviceInfo.commonDevInfo.devType_S_Rate = (bit8)(conRate | 0x10);
5464 
5465   }
5466   else
5467   {
5468     protocol = SA_IDFRM_SMP_BIT; /* SMP */
5469     pDeviceInfo.commonDevInfo.devType_S_Rate = (bit8)conRate;
5470   }
5471   pDeviceInfo.initiator_ssp_stp_smp = protocol;
5472   pDeviceInfo.numOfPhys = 1;
5473   pDeviceInfo.commonDevInfo.sasAddressHi[0] = pMsg1->sasAddrHi[0];
5474   pDeviceInfo.commonDevInfo.sasAddressHi[1] = pMsg1->sasAddrHi[1];
5475   pDeviceInfo.commonDevInfo.sasAddressHi[2] = pMsg1->sasAddrHi[2];
5476   pDeviceInfo.commonDevInfo.sasAddressHi[3] = pMsg1->sasAddrHi[3];
5477   pDeviceInfo.commonDevInfo.sasAddressLo[0] = pMsg1->sasAddrLow[0];
5478   pDeviceInfo.commonDevInfo.sasAddressLo[1] = pMsg1->sasAddrLow[1];
5479   pDeviceInfo.commonDevInfo.sasAddressLo[2] = pMsg1->sasAddrLow[2];
5480   pDeviceInfo.commonDevInfo.sasAddressLo[3] = pMsg1->sasAddrLow[3];
5481   pDeviceInfo.commonDevInfo.flag = 0;
5482   pDeviceInfo.commonDevInfo.it_NexusTimeout = ITL_TO_DEFAULT;
5483 
5484   /* deviceId -> agDeviceHandle */
5485   pDevice = (agsaDeviceDesc_t *)saRoot->DeviceMap[FwdDeviceId & DEVICE_ID_BITS].DeviceHandle;
5486 
5487   if (agNULL == pDevice)
5488   {
5489     /* new device */
5490     si_memset(&remoteIdentify, 0, sizeof(agsaSASIdentify_t));
5491     for (i=0;i<4;i++)
5492     {
5493       remoteIdentify.sasAddressHi[i] = pMsg1->sasAddrHi[i];
5494       remoteIdentify.sasAddressLo[i] = pMsg1->sasAddrLow[i];
5495     }
5496     remoteIdentify.deviceType_addressFrameType = (bit8)(pDeviceInfo.commonDevInfo.devType_S_Rate & 0xC0);
5497     dTypeSRate = pDeviceInfo.commonDevInfo.devType_S_Rate;
5498     /* get Device from free Device List */
5499     pDevice = siPortSASDeviceAdd(agRoot, pPort, remoteIdentify, agTRUE, SMP_TO_DEFAULT, ITL_TO_DEFAULT, 0, dTypeSRate, 0);
5500     if (agNULL == pDevice)
5501     {
5502       SA_DBG1(("mpiDeviceHandleArrived: Device Handle is NULL, Out of Resources Error.\n"));
5503     }
5504     else
5505     {
5506       bit32 AccStatus = 0;
5507       bit32 SaveId = FwdDeviceId & 0xFFFF;
5508       /* mapping the device handle and device id */
5509       saRoot->DeviceMap[FwdDeviceId & DEVICE_ID_BITS].DeviceIdFromFW = FwdDeviceId;
5510       saRoot->DeviceMap[FwdDeviceId & DEVICE_ID_BITS].DeviceHandle = (void *)pDevice;
5511       pDevice->DeviceMapIndex = FwdDeviceId;
5512       SA_DBG2(("mpiDeviceHandleArrived: New deviceID 0x%x Device Context %p DeviceTypeSRate 0x%x\n", FwdDeviceId, pDevice, dTypeSRate));
5513 
5514       /* Call Back */
5515       AccStatus = ossaDeviceHandleAccept(agRoot, &(pDevice->initiatorDevHandle), &pDeviceInfo, agPortContext,&FwdDeviceId );
5516 
5517       HostAssignedId = (FwdDeviceId & 0xFFFF0000) >> SHIFT16;
5518       if(HostAssignedId)
5519       {
5520         if( SaveId == (FwdDeviceId & 0xFFFF)  )
5521         {
5522 
5523           saRoot->DeviceMap[FwdDeviceId & DEVICE_ID_BITS].DeviceIdFromFW = FwdDeviceId;
5524           pDevice->DeviceMapIndex = FwdDeviceId;
5525 
5526           SA_DBG1(("mpiDeviceHandleArrived:FwdDeviceId 0x%x HostAssignedId 0x%x\n",FwdDeviceId,HostAssignedId));
5527         }
5528         else
5529         {
5530           SA_DBG1(("mpiDeviceHandleArrived:Id mangled expect 0x%x Got 0x%x\n",SaveId, (FwdDeviceId & 0xFFFF)));
5531           ret = AGSA_RC_FAILURE;
5532         }
5533       }
5534 
5535       /* get AWT flag and ITLN_TMO value */
5536 
5537       if(AccStatus == OSSA_RC_ACCEPT )
5538       {
5539         /* build DEVICE_HANDLE_ACCEPT IOMB and send to SPC with action=accept */
5540         mpiDevHandleAcceptCmd(agRoot, agNULL, CTag, FwdDeviceId, 0, pDeviceInfo.commonDevInfo.flag, pDeviceInfo.commonDevInfo.it_NexusTimeout, 0);
5541       }
5542       else
5543       {
5544         mpiDevHandleAcceptCmd(agRoot, agNULL, CTag, FwdDeviceId, 1, pDeviceInfo.commonDevInfo.flag, pDeviceInfo.commonDevInfo.it_NexusTimeout, 0);
5545       }
5546     }
5547   }
5548 
5549   SA_DBG1(("mpiDeviceHandleArrived Device 0x%08X flag 0x%08X %s WWID= %02x%02x%02x%02x:%02x%02x%02x%02x, %s\n",
5550     FwdDeviceId,
5551     pDevice->devInfo.sasDeviceInfo.commonDevInfo.flag,
5552     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF0) == 0x20 ? "SATA DA" :
5553     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF0) == 0x10 ? "SSP/SMP" :
5554     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF0) == 0x0 ? "  STP  " : "Unknown",
5555 
5556     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[3],
5557     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[2],
5558     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[1],
5559     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressHi[0],
5560     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[3],
5561     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[2],
5562     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[1],
5563     pDevice->devInfo.sasDeviceInfo.commonDevInfo.sasAddressLo[0],
5564 
5565     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF) == 8  ? " 1.5G" :
5566     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF) == 9  ? " 3.0G" :
5567     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF) == 10 ? " 6.0G" :
5568     (pDevice->devInfo.sasDeviceInfo.commonDevInfo.devType_S_Rate & 0xF) == 11 ? "12.0G" : "????" ));
5569 
5570   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3L");
5571   return ret;
5572 }
5573 
5574 /******************************************************************************/
5575 /*! \brief Get Time Stamp Response
5576  *
5577  *  This routine handles the response of Get Time Stamp Command
5578  *
5579  *  \param agRoot       Handles for this instance of SAS/SATA LLL
5580  *  \param pIomb        Pointer of IOMB Mesage
5581  *
5582  *  \return sucess or fail
5583  *
5584  */
5585 /*******************************************************************************/
5586 GLOBAL bit32 mpiGetTimeStampRsp(
5587   agsaRoot_t               *agRoot,
5588   agsaGetTimeStampRsp_t    *pIomb
5589   )
5590 {
5591   bit32               ret = AGSA_RC_SUCCESS;
5592   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
5593   agsaIORequestDesc_t *pRequest;
5594   agsaContext_t       *agContext;
5595   bit32               tag, timeStampLower, timeStampUpper;
5596 
5597   smTraceFuncEnter(hpDBG_VERY_LOUD,"3M");
5598 
5599   SA_DBG3(("mpiGetTimeStampRsp: HTAG=0x%x\n", pIomb->tag));
5600 
5601   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaGetTimeStampRsp_t, tag));
5602   OSSA_READ_LE_32(AGROOT, &timeStampLower, pIomb, OSSA_OFFSET_OF(agsaGetTimeStampRsp_t, timeStampLower));
5603   OSSA_READ_LE_32(AGROOT, &timeStampUpper, pIomb, OSSA_OFFSET_OF(agsaGetTimeStampRsp_t, timeStampUpper));
5604   /* get request from IOMap */
5605   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
5606   if (agNULL == pRequest)
5607   {
5608     SA_DBG1(("mpiGetTimeStampRsp: Bad Response IOMB!!! pRequest is NULL.TAG=0x%x\n", tag));
5609     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3M");
5610     return AGSA_RC_FAILURE;
5611   }
5612 
5613   agContext = saRoot->IOMap[tag].agContext;
5614   /* remove the request from IOMap */
5615   saRoot->IOMap[tag].Tag = MARK_OFF;
5616   saRoot->IOMap[tag].IORequest = agNULL;
5617   saRoot->IOMap[tag].agContext = agNULL;
5618 
5619   SA_ASSERT((pRequest->valid), "pRequest->valid");
5620 
5621   SA_DBG3(("mpiGetTimeStampRsp: timeStampLower 0x%x timeStampUpper 0x%x\n", timeStampLower, timeStampUpper));
5622 
5623   ossaGetTimeStampCB(agRoot, agContext, timeStampLower, timeStampUpper);
5624 
5625   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
5626   pRequest->valid = agFALSE;
5627   /* return the request to free pool */
5628   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
5629   {
5630     SA_DBG1(("mpiGetTimeStampRsp: saving pRequest (%p) for later use\n", pRequest));
5631     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
5632   }
5633   else
5634   {
5635     /* return the request to free pool */
5636     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
5637   }
5638   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
5639 
5640   /* return value */
5641   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3M");
5642   return ret;
5643 }
5644 
5645 /******************************************************************************/
5646 /*! \brief SAS HW Event Ack Response
5647  *
5648  *  This routine handles the response of SAS HW Event Ack Command
5649  *
5650  *  \param agRoot       Handles for this instance of SAS/SATA LLL
5651  *  \param pIomb        Pointer of IOMB Mesage
5652  *
5653  *  \return sucess or fail
5654  *
5655  */
5656 /*******************************************************************************/
5657 GLOBAL bit32 mpiSASHwEventAckRsp(
5658   agsaRoot_t               *agRoot,
5659   agsaSASHwEventAckRsp_t   *pIomb
5660   )
5661 {
5662   bit32               ret = AGSA_RC_SUCCESS;
5663   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
5664   agsaIORequestDesc_t *pRequest;
5665   agsaContext_t       *agContext;
5666   agsaPort_t          *pPort;
5667   bit32               tag, status;
5668 
5669   smTraceFuncEnter(hpDBG_VERY_LOUD,"2N");
5670 
5671   SA_DBG2(("mpiSASHwEventAckRsp: Htag=0x%x %p\n", pIomb->tag,pIomb));
5672 
5673   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaSASHwEventAckRsp_t, tag));
5674   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaSASHwEventAckRsp_t, status));
5675   /* get request from IOMap */
5676   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
5677   if (agNULL == pRequest)
5678   {
5679     SA_DBG1(("mpiSASHwEventAckRsp: Bad Response IOMB!!! pRequest is NULL.TAG=0x%x Status=0x%x\n", tag, status));
5680     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2N");
5681     return AGSA_RC_FAILURE;
5682   }
5683 
5684   agContext = saRoot->IOMap[tag].agContext;
5685   /* remove the request from IOMap */
5686   saRoot->IOMap[tag].Tag = MARK_OFF;
5687   saRoot->IOMap[tag].IORequest = agNULL;
5688   saRoot->IOMap[tag].agContext = agNULL;
5689   SA_ASSERT((pRequest->valid), "pRequest->valid");
5690 
5691   SA_DBG1(("mpiSASHwEventAckRsp: status 0x%x Htag=0x%x HwAckType=0x%x\n",status,pIomb->tag,pRequest->HwAckType ));
5692 
5693   ossaHwEventAckCB(agRoot, agContext, status);
5694 
5695   pPort = pRequest->pPort;
5696   if (agNULL != pPort)
5697   {
5698     SA_DBG1(("mpiSASHwEventAckRsp: pPort %p tobedeleted %d\n", pPort, pPort->tobedeleted));
5699     if (pPort->status & PORT_INVALIDATING &&  pPort->tobedeleted )
5700     {
5701       SA_DBG1(("mpiSASHwEventAckRsp: PORT_INVALIDATING portInvalid portID %d pPort %p, nulling out PortContext\n", pPort->portId, pPort));
5702       /* invalid the port */
5703       siPortInvalid(agRoot, pPort);
5704       /* map out the portmap */
5705       saRoot->PortMap[pPort->portId].PortContext = agNULL;
5706       saRoot->PortMap[pPort->portId].PortID = PORT_MARK_OFF;
5707       saRoot->PortMap[pPort->portId].PortStatus  |= PORT_INVALIDATING;
5708     }
5709     else
5710     {
5711       SA_DBG1(("mpiSASHwEventAckRsp:pPort->status 0x%x Htag=0x%x %p\n",pPort->status, pIomb->tag,pIomb));
5712     }
5713   }
5714   else
5715   {
5716     SA_DBG1(("mpiSASHwEventAckRsp: pPort is NULL, no portId, HTag=0x%x\n", tag));
5717   }
5718 
5719   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
5720   pRequest->valid = agFALSE;
5721   /* return the request to free pool */
5722   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
5723   {
5724     SA_DBG1(("mpiSASHwEventAckRsp: saving pRequest (%p) for later use\n", pRequest));
5725     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
5726   }
5727   else
5728   {
5729     /* return the request to free pool */
5730     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
5731   }
5732   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
5733 
5734   /* return value */
5735   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2N");
5736   return ret;
5737 }
5738 
5739 /******************************************************************************/
5740 /*! \brief Port Control Response
5741  *
5742  *  This routine handles the response of SAS HW Event Ack Command
5743  *
5744  *  \param agRoot       Handles for this instance of SAS/SATA LLL
5745  *  \param pIomb        Pointer of IOMB Mesage
5746  *
5747  *  \return sucess or fail
5748  *
5749  */
5750 /*******************************************************************************/
5751 GLOBAL bit32 mpiPortControlRsp(
5752   agsaRoot_t           *agRoot,
5753   agsaPortControlRsp_t *pIomb
5754   )
5755 {
5756   bit32               ret = AGSA_RC_SUCCESS;
5757   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
5758   agsaIORequestDesc_t *pRequest = agNULL;
5759   agsaContext_t       *agContext = agNULL;
5760   agsaPortContext_t   *agPortContext = agNULL;
5761   bit32               tag;
5762   bit32               port =0;
5763   bit32               operation =0;
5764   bit32               status =0;
5765   bit32               portState =0;
5766   bit32               portOperation =0;
5767 
5768   smTraceFuncEnter(hpDBG_VERY_LOUD,"3O");
5769 
5770   SA_DBG2(("mpiPortControlRsp: HTag=0x%x\n", pIomb->tag));
5771 
5772   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaPortControlRsp_t, tag));
5773   OSSA_READ_LE_32(AGROOT, &operation, pIomb, OSSA_OFFSET_OF(agsaPortControlRsp_t, portOPPortId));
5774   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaPortControlRsp_t, status));
5775   OSSA_READ_LE_32(AGROOT, &portState, pIomb, OSSA_OFFSET_OF(agsaPortControlRsp_t,rsvdPortState ));
5776 
5777   /* get request from IOMap */
5778   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
5779   if (agNULL == pRequest)
5780   {
5781     SA_DBG1(("mpiPortControlRsp: Bad Response IOMB!!! pRequest is NULL.TAG=0x%x Status=0x%x\n", tag, status));
5782     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3O");
5783     return AGSA_RC_FAILURE;
5784   }
5785 
5786   agContext = saRoot->IOMap[tag].agContext;
5787   /* remove the request from IOMap */
5788   saRoot->IOMap[tag].Tag = MARK_OFF;
5789   saRoot->IOMap[tag].IORequest = agNULL;
5790   saRoot->IOMap[tag].agContext = agNULL;
5791 
5792   SA_ASSERT((pRequest->valid), "pRequest->valid");
5793 
5794   if(!pRequest->valid)
5795   {
5796     SA_DBG1(("mpiPortControlRsp: pRequest->valid %d not set\n", pRequest->valid));
5797   }
5798 
5799   SA_DBG2(("mpiPortControlRsp: pRequest->completionCB %p\n", pRequest->completionCB));
5800 
5801   port = operation & PORTID_MASK;
5802 
5803   if(port < AGSA_MAX_VALID_PORTS )
5804   {
5805     SA_DBG2(("mpiPortControlRsp: PortID 0x%x PortStatus 0x%x PortContext %p\n",
5806            saRoot->PortMap[port].PortID,
5807            saRoot->PortMap[port].PortStatus,
5808            saRoot->PortMap[port].PortContext));
5809 
5810     agPortContext = (agsaPortContext_t *)saRoot->PortMap[port].PortContext;
5811   }
5812   SA_DBG2(("mpiPortControlRsp: PortID 0x%x PortStatus 0x%x PortContext %p\n",saRoot->PortMap[operation & PORTID_MASK].PortID,saRoot->PortMap[operation & PORTID_MASK].PortStatus,saRoot->PortMap[operation & PORTID_MASK].PortContext));
5813   agPortContext = (agsaPortContext_t *)saRoot->PortMap[operation & PORTID_MASK].PortContext;
5814   SA_DBG1(("mpiPortControlRsp: agPortContext %p\n",agPortContext ));
5815 
5816 
5817   SA_DBG2(("mpiPortControlRsp: portID 0x%x status 0x%x\n", (operation & PORTID_MASK), status));
5818 
5819   SA_DBG1(("mpiPortControlRsp: portID 0x%x status 0x%x agPortContext %p\n",port, status,agPortContext));
5820 
5821   portOperation = (((operation & LOCAL_PHY_OP_BITS) >> SHIFT8) | (portState << SHIFT28) );
5822 
5823   SA_DBG1(("mpiPortControlRsp: portState 0x%x operation 0x%x portOperation 0x%x\n",portState, operation,portOperation ));
5824 
5825   switch(portOperation)
5826   {
5827     case AGSA_PORT_SET_SMP_PHY_WIDTH:
5828       SA_DBG1(("mpiPortControlRsp: AGSA_PORT_SET_SMP_PHY_WIDTH  operation 0x%x\n",operation ));
5829       break;
5830     case AGSA_PORT_SET_PORT_RECOVERY_TIME:
5831       SA_DBG1(("mpiPortControlRsp: AGSA_PORT_SET_PORT_RECOVERY_TIME  operation 0x%x\n",operation ));
5832       break;
5833     case AGSA_PORT_IO_ABORT:
5834       SA_DBG1(("mpiPortControlRsp: AGSA_PORT_IO_ABORT  operation 0x%x\n",operation ));
5835       break;
5836     case AGSA_PORT_SET_PORT_RESET_TIME:
5837       SA_DBG1(("mpiPortControlRsp: AGSA_PORT_SET_PORT_RESET_TIME  operation 0x%x\n",operation ));
5838       break;
5839     case AGSA_PORT_HARD_RESET:
5840       SA_DBG1(("mpiPortControlRsp: AGSA_PORT_HARD_RESET  operation 0x%x\n",operation ));
5841       break;
5842     case AGSA_PORT_CLEAN_UP:
5843       SA_DBG1(("mpiPortControlRsp: AGSA_PORT_CLEAN_UP  operation 0x%x\n",operation ));
5844       break;
5845     case AGSA_STOP_PORT_RECOVERY_TIMER:
5846       SA_DBG1(("mpiPortControlRsp: AGSA_STOP_PORT_RECOVERY_TIMER  operation 0x%x\n",operation ));
5847       break;
5848     default:
5849     {
5850       SA_DBG1(("mpiPortControlRsp: Unknown  operation 0x%x\n",operation ));
5851     }
5852   }
5853 
5854   ossaPortControlCB(agRoot, agContext, agPortContext, portOperation, status);
5855 
5856   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
5857   pRequest->valid = agFALSE;
5858   /* return the request to free pool */
5859   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
5860   {
5861     SA_DBG1(("mpiPortControlRsp: saving pRequest (%p) for later use\n", pRequest));
5862     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
5863   }
5864   else
5865   {
5866     /* return the request to free pool */
5867     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
5868   }
5869   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
5870 
5871   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3O");
5872   /* return value */
5873   return ret;
5874 }
5875 
5876 /******************************************************************************/
5877 /*! \brief SPC MPI SMP ABORT Response
5878  *
5879  *  This function handles the SMP Abort Response.
5880  *
5881  *  \param agRoot       Handles for this instance of SAS/SATA LLL
5882  *  \param pIomb        pointer of Message
5883  *
5884  *  \return The read value
5885  *
5886  */
5887 /*******************************************************************************/
5888 GLOBAL bit32 mpiSMPAbortRsp(
5889   agsaRoot_t         *agRoot,
5890   agsaSMPAbortRsp_t  *pIomb
5891   )
5892 {
5893   bit32               ret = AGSA_RC_SUCCESS;
5894   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
5895   agsaIORequestDesc_t *pRequest;
5896   agsaDeviceDesc_t    *pDevice;
5897   bit32               tag, scp, status;
5898 
5899   smTraceFuncEnter(hpDBG_VERY_LOUD,"3P");
5900 
5901   SA_DBG3(("mpiSMPAbortRsp: HTag=0x%x Status=0x%x\n", pIomb->tag, pIomb->status));
5902 
5903   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaSMPAbortRsp_t, tag));
5904   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaSMPAbortRsp_t, status));
5905   OSSA_READ_LE_32(AGROOT, &scp, pIomb, OSSA_OFFSET_OF(agsaSMPAbortRsp_t, scp));
5906 
5907   /* get IORequest from IOMap */
5908   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
5909 
5910   if (agNULL == pRequest)
5911   {
5912     SA_DBG1(("mpiSMPAbortRsp: pRequest is NULL, HTag=0x%x Status=0x%x\n", pIomb->tag, pIomb->status));
5913     SA_ASSERT((pRequest), "pRequest");
5914     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3P");
5915     return AGSA_RC_FAILURE;
5916   }
5917 
5918   if ( agTRUE == pRequest->valid )
5919   {
5920     pDevice = pRequest->pDevice;
5921     SA_ASSERT((pRequest->pDevice), "pRequest->pDevice");
5922 
5923     SA_DBG3(("mpiSMPAbortRsp: request abort is valid Htag 0x%x\n", tag));
5924 
5925     /* remove the SSP_ABORT or SATA_ABORT request from IOMap */
5926     saRoot->IOMap[tag].Tag = MARK_OFF;
5927     saRoot->IOMap[tag].IORequest = agNULL;
5928     saRoot->IOMap[tag].agContext = agNULL;
5929 
5930     if( pRequest->completionCB == agNULL )
5931     {
5932       SA_DBG1(("mpiSMPAbortRsp: ************************************************* Valid for Expander only tag 0x%x\n", tag));
5933       ossaSMPAbortCB(agRoot, pRequest->pIORequestContext, scp, status);
5934     }
5935     else
5936     {
5937       (*(ossaGenericAbortCB_t)(pRequest->completionCB))(agRoot, pRequest->pIORequestContext, scp, status);
5938     }
5939 
5940     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
5941 
5942     /* Delete the request from the pendingIORequests */
5943     saLlistIORemove(&(pDevice->pendingIORequests), &(pRequest->linkNode));
5944     pRequest->valid = agFALSE;
5945     /* return the request to free pool */
5946     if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
5947     {
5948       SA_DBG1(("mpiSMPAbortRsp: saving pRequest (%p) for later use\n", pRequest));
5949       saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
5950     }
5951     else
5952     {
5953       saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
5954     }
5955     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
5956 
5957   }
5958   else
5959   {
5960     ret = AGSA_RC_FAILURE;
5961     SA_DBG1(("mpiSMPAbortRsp: the request is not valid any more. Tag=%x\n", pRequest->HTag));
5962   }
5963 
5964 
5965   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3P");
5966 
5967   return ret;
5968 }
5969 
5970 /******************************************************************************/
5971 /*! \brief SPC MPI Device Handle Arrived Event (target mode)
5972  *
5973  *  This function handles the Device Handle Arrived Event.
5974  *
5975  *  \param agRoot       Handles for this instance of SAS/SATA LLL
5976  *  \param pMsg1        pointer of Message
5977  *
5978  *  \return The read value
5979  *
5980  */
5981 /*******************************************************************************/
5982 GLOBAL bit32 mpiDeviceHandleRemoval(
5983   agsaRoot_t *agRoot,
5984   agsaDeviceHandleRemoval_t *pMsg1)
5985 {
5986   bit32               ret = AGSA_RC_SUCCESS;
5987   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
5988   agsaDeviceDesc_t    *pDevice;
5989   agsaPortContext_t   *agPortContext;
5990   bit32               portId;
5991   bit32               deviceid, deviceIdx;
5992 
5993   smTraceFuncEnter(hpDBG_VERY_LOUD,"3R");
5994 
5995   /* convert endiness if necassary */
5996   OSSA_READ_LE_32(AGROOT, &portId, pMsg1, OSSA_OFFSET_OF(agsaDeviceHandleRemoval_t, portId));
5997   OSSA_READ_LE_32(AGROOT, &deviceid, pMsg1, OSSA_OFFSET_OF(agsaDeviceHandleRemoval_t, deviceId));
5998 
5999   SA_DBG3(("mpiDeviceHandleRemoval: portId=0x%x deviceId=0x%x\n", portId, deviceid));
6000 
6001   pDevice = saRoot->DeviceMap[deviceid & DEVICE_ID_BITS].DeviceHandle;
6002   SA_DBG2(("mpiDeviceHandleRemoval:PortID 0x%x PortStatus 0x%x PortContext %p\n",
6003           saRoot->PortMap[portId & PORTID_MASK].PortID,
6004           saRoot->PortMap[portId & PORTID_MASK].PortStatus,
6005           saRoot->PortMap[portId & PORTID_MASK].PortContext));
6006   agPortContext = (agsaPortContext_t *)saRoot->PortMap[portId & PORTID_MASK].PortContext;
6007 
6008   /* Call Back */
6009   SA_DBG1(("mpiDeviceHandleRemoval: portId=0x%x deviceId=0x%x autoDeregDeviceflag=0x%x\n", portId, deviceid,saRoot->autoDeregDeviceflag[portId & PORTID_MASK]));
6010   if (pDevice->targetDevHandle.sdkData)
6011   {
6012     ossaDeviceHandleRemovedEvent(agRoot, &(pDevice->targetDevHandle), agPortContext);
6013 
6014     if (saRoot->autoDeregDeviceflag[portId & PORTID_MASK])
6015     {
6016       /* remove the DeviceMap and MapIndex */
6017       deviceIdx = pDevice->DeviceMapIndex & DEVICE_ID_BITS;
6018       SA_DBG1(("mpiDeviceHandleRemoval: A  Freed portId=0x%x deviceId=0x%x\n", portId, deviceid));
6019       OS_ASSERT(deviceIdx < MAX_IO_DEVICE_ENTRIES, "deviceIdx MAX_IO_DEVICE_ENTRIES");
6020 
6021       saRoot->DeviceMap[deviceIdx].DeviceIdFromFW = 0;
6022       saRoot->DeviceMap[deviceIdx].DeviceHandle = agNULL;
6023       pDevice->DeviceMapIndex = 0;
6024 
6025       /* Reset the device data structure */
6026       pDevice->pPort = agNULL;
6027       pDevice->targetDevHandle.sdkData = agNULL;
6028       pDevice->targetDevHandle.osData = agNULL;
6029       ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6030       saLlistAdd(&(saRoot->freeDevicesList), &(pDevice->linkNode));
6031       SA_DBG1(("mpiDeviceHandleRemoval: portId=0x%x deviceId=0x%x\n", portId, deviceid));
6032 
6033       ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6034     }
6035   }
6036   else
6037   {
6038     if (pDevice->initiatorDevHandle.sdkData)
6039     {
6040       ossaDeviceHandleRemovedEvent(agRoot, &(pDevice->initiatorDevHandle), agPortContext);
6041 
6042       if (saRoot->autoDeregDeviceflag[portId & PORTID_MASK])
6043       {
6044         /* remove the DeviceMap and MapIndex */
6045         deviceIdx = pDevice->DeviceMapIndex & DEVICE_ID_BITS;
6046         SA_DBG1(("mpiDeviceHandleRemoval: A  Freed portId=0x%x deviceId=0x%x\n", portId, deviceid));
6047         OS_ASSERT(deviceIdx < MAX_IO_DEVICE_ENTRIES, "deviceIdx MAX_IO_DEVICE_ENTRIES");
6048         saRoot->DeviceMap[deviceIdx].DeviceIdFromFW = 0;
6049         saRoot->DeviceMap[deviceIdx].DeviceHandle = agNULL;
6050         pDevice->DeviceMapIndex = 0;
6051 
6052         /* Reset the device data structure */
6053         pDevice->pPort = agNULL;
6054         pDevice->initiatorDevHandle.sdkData = agNULL;
6055         pDevice->initiatorDevHandle.osData = agNULL;
6056         ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6057         saLlistAdd(&(saRoot->freeDevicesList), &(pDevice->linkNode));
6058         ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6059       }
6060     }
6061     else
6062     {
6063       /* no callback because bad device_id */
6064       SA_DBG1(("mpiDeviceHandleRemoval: Bad Device Handle, deviceId=0x%x\n", deviceid));
6065     }
6066   }
6067 
6068   smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3R");
6069   return ret;
6070 }
6071 
6072 /******************************************************************************/
6073 /*! \brief Set Device State Response
6074  *
6075  *  This routine handles the response of SET Device State Response
6076  *
6077  *  \param agRoot       Handles for this instance of SAS/SATA LLL
6078  *  \param pIomb        Pointer of IOMB Mesage
6079  *
6080  *  \return sucess or fail
6081  *
6082  */
6083 /*******************************************************************************/
6084 GLOBAL bit32 mpiSetDeviceStateRsp(
6085   agsaRoot_t             *agRoot,
6086   agsaSetDeviceStateRsp_t *pIomb
6087   )
6088 {
6089   bit32               ret = AGSA_RC_SUCCESS;
6090   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
6091   agsaIORequestDesc_t *pRequest;
6092   agsaDevHandle_t     *agDevHandle;
6093   agsaDeviceDesc_t    *pDevice;
6094   agsaContext_t       *agContext;
6095   bit32               tag, status, deviceState, deviceId;
6096 
6097   smTraceFuncEnter(hpDBG_VERY_LOUD,"3Q");
6098 
6099   SA_DBG1(("mpiSetDeviceStateRsp: HTag=0x%x, deviceId=0x%x\n", pIomb->tag, pIomb->deviceId));
6100 
6101   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaSetDeviceStateRsp_t, tag));
6102   OSSA_READ_LE_32(AGROOT, &deviceId, pIomb, OSSA_OFFSET_OF(agsaSetDeviceStateRsp_t, deviceId));
6103   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaSetDeviceStateRsp_t, status));
6104 
6105   /* get request from IOMap */
6106   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
6107   if (agNULL == pRequest)
6108   {
6109     SA_DBG1(("mpiSetDeviceStateRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
6110     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3Q");
6111     return AGSA_RC_FAILURE;
6112   }
6113 
6114   agContext = saRoot->IOMap[tag].agContext;
6115   /* remove the request from IOMap */
6116   saRoot->IOMap[tag].Tag = MARK_OFF;
6117   saRoot->IOMap[tag].IORequest = agNULL;
6118   saRoot->IOMap[tag].agContext = agNULL;
6119 
6120   SA_ASSERT((pRequest->valid), "pRequest->valid");
6121 
6122   /* status is SUCCESS */
6123   OSSA_READ_LE_32(AGROOT, &deviceState, pIomb, OSSA_OFFSET_OF(agsaSetDeviceStateRsp_t, pds_nds));
6124 
6125   /* find device handle from device index */
6126   pDevice = (agsaDeviceDesc_t *)saRoot->DeviceMap[deviceId & DEVICE_ID_BITS].DeviceHandle;
6127   if (agNULL == pDevice)
6128   {
6129     SA_DBG1(("mpiSetDeviceStateRsp: DeviceHandle is NULL!!! deviceId=0x%x TAG=0x%x STATUS=0x%x \n", deviceId, tag, status));
6130     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3Q");
6131     return AGSA_RC_FAILURE;
6132   }
6133 
6134   if (pDevice->targetDevHandle.sdkData)
6135   {
6136     agDevHandle = &(pDevice->targetDevHandle);
6137   }
6138   else
6139   {
6140     agDevHandle = &(pDevice->initiatorDevHandle);
6141   }
6142 
6143   if (agDevHandle == agNULL)
6144   {
6145     SA_DBG1(("mpiSetDeviceStateRsp: warning!!! no deviceHandle is found"));
6146     ossaSetDeviceStateCB(agRoot, agContext, agNULL, OSSA_IO_NO_DEVICE, 0, 0);
6147     smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "3Q");
6148 
6149     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6150     pRequest->valid = agFALSE;
6151     /* return the request to free pool */
6152     if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
6153     {
6154       SA_DBG1(("mpiSetDeviceStateRsp: saving pRequest (%p) for later use\n", pRequest));
6155       saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
6156     }
6157     else
6158     {
6159       /* return the request to free pool */
6160       saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
6161     }
6162     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6163 
6164     return AGSA_RC_FAILURE;
6165   }
6166 
6167   ossaSetDeviceStateCB(agRoot, agContext, agDevHandle, status, (deviceState & NDS_BITS),
6168                       (deviceState & PDS_BITS) >> SHIFT4);
6169 
6170   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6171   pRequest->valid = agFALSE;
6172   /* return the request to free pool */
6173   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
6174   {
6175     SA_DBG1(("mpiSetDeviceStateRsp: saving pRequest (%p) for later use\n", pRequest));
6176     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
6177   }
6178   else
6179   {
6180     /* return the request to free pool */
6181     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
6182   }
6183   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6184 
6185   /* return value */
6186   smTraceFuncExit(hpDBG_VERY_LOUD, 'd', "3Q");
6187   return ret;
6188 }
6189 
6190 /******************************************************************************/
6191 /*! \brief Get Device State Response
6192  *
6193  *  This routine handles the response of GET Device State Response
6194  *
6195  *  \param agRoot       Handles for this instance of SAS/SATA LLL
6196  *  \param pIomb        Pointer of IOMB Mesage
6197  *
6198  *  \return sucess or fail
6199  *
6200  */
6201 /*******************************************************************************/
6202 GLOBAL bit32 mpiGetDeviceStateRsp(
6203   agsaRoot_t             *agRoot,
6204   agsaGetDeviceStateRsp_t *pIomb
6205   )
6206 {
6207   bit32               ret = AGSA_RC_SUCCESS;
6208   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
6209   agsaIORequestDesc_t *pRequest;
6210   agsaDevHandle_t     *agDevHandle;
6211   agsaDeviceDesc_t    *pDevice;
6212   agsaContext_t       *agContext;
6213   bit32               tag, status, deviceId, deviceState;
6214 
6215   smTraceFuncEnter(hpDBG_VERY_LOUD,"3W");
6216 
6217   SA_DBG1(("mpiGetDeviceStateRsp: HTag=0x%x, deviceId=0x%x\n", pIomb->tag, pIomb->deviceId));
6218 
6219   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaGetDeviceStateRsp_t, tag));
6220   OSSA_READ_LE_32(AGROOT, &deviceId, pIomb, OSSA_OFFSET_OF(agsaGetDeviceStateRsp_t, deviceId));
6221   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaGetDeviceStateRsp_t, status));
6222 
6223   /* get request from IOMap */
6224   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
6225   if (agNULL == pRequest)
6226   {
6227     SA_DBG1(("mpiGetDeviceStateRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
6228     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3W");
6229     return AGSA_RC_FAILURE;
6230   }
6231 
6232   agContext = saRoot->IOMap[tag].agContext;
6233   /* remove the request from IOMap */
6234   saRoot->IOMap[tag].Tag = MARK_OFF;
6235   saRoot->IOMap[tag].IORequest = agNULL;
6236   saRoot->IOMap[tag].agContext = agNULL;
6237 
6238   SA_ASSERT((pRequest->valid), "pRequest->valid");
6239 
6240   /* status is SUCCESS */
6241   OSSA_READ_LE_32(AGROOT, &deviceState, pIomb, OSSA_OFFSET_OF(agsaGetDeviceStateRsp_t, ds));
6242 
6243   /* find device handle from device index */
6244   pDevice = (agsaDeviceDesc_t *)saRoot->DeviceMap[deviceId & DEVICE_ID_BITS].DeviceHandle;
6245   if (pDevice != agNULL)
6246   {
6247     if (pDevice->targetDevHandle.sdkData)
6248     {
6249       agDevHandle = &(pDevice->targetDevHandle);
6250     }
6251     else
6252     {
6253       agDevHandle = &(pDevice->initiatorDevHandle);
6254     }
6255   }
6256   else
6257   {
6258     SA_DBG1(("mpiGetDeviceStateRsp: pDevice is NULL"));
6259     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3W");
6260     return AGSA_RC_FAILURE;
6261   }
6262 
6263   if (agDevHandle == agNULL)
6264   {
6265     SA_DBG1(("mpiGetDeviceStateRsp: warning!!! no deviceHandle is found"));
6266     ossaGetDeviceStateCB(agRoot, agContext, agNULL, OSSA_IO_NO_DEVICE, 0);
6267     smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "3W");
6268 
6269     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6270     pRequest->valid = agFALSE;
6271     /* return the request to free pool */
6272     if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
6273     {
6274       SA_DBG1(("mpiGetDeviceStateRsp: saving pRequest (%p) for later use\n", pRequest));
6275       saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
6276     }
6277     else
6278     {
6279       /* return the request to free pool */
6280       saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
6281     }
6282     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6283 
6284     return AGSA_RC_FAILURE;
6285   }
6286 
6287   ossaGetDeviceStateCB(agRoot, agContext, agDevHandle, status, deviceState);
6288 
6289   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6290   pRequest->valid = agFALSE;
6291   /* return the request to free pool */
6292   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
6293   {
6294     SA_DBG1(("mpiGetDeviceStateRsp: saving pRequest (%p) for later use\n", pRequest));
6295     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
6296   }
6297   else
6298   {
6299     /* return the request to free pool */
6300     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
6301   }
6302   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6303 
6304   /* return value */
6305   smTraceFuncExit(hpDBG_VERY_LOUD, 'd', "3W");
6306   return ret;
6307 }
6308 
6309 /******************************************************************************/
6310 /*! \brief SAS ReInitialize Response
6311  *
6312  *  This routine handles the response of SAS Reinitialize Response
6313  *
6314  *  \param agRoot       Handles for this instance of SAS/SATA LLL
6315  *  \param pIomb        Pointer of IOMB Mesage
6316  *
6317  *  \return sucess or fail
6318  *
6319  */
6320 /*******************************************************************************/
6321 GLOBAL bit32 mpiSasReInitializeRsp(
6322   agsaRoot_t               *agRoot,
6323   agsaSasReInitializeRsp_t *pIomb
6324   )
6325 {
6326   bit32               ret = AGSA_RC_SUCCESS;
6327   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
6328   agsaIORequestDesc_t *pRequest;
6329   agsaContext_t       *agContext;
6330   agsaSASReconfig_t   SASReconfig;
6331   bit32               tag, status, setFlags, MaxPorts;
6332   bit32               openRejReCmdData, sataHOLTMO;
6333 
6334   smTraceFuncEnter(hpDBG_VERY_LOUD,"3X");
6335 
6336   SA_DBG1(("mpiSasReInitializeRsp: HTag=0x%x, status=0x%x\n", pIomb->tag, pIomb->status));
6337 
6338   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaSasReInitializeRsp_t, tag));
6339   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaSasReInitializeRsp_t, status));
6340   OSSA_READ_LE_32(AGROOT, &setFlags, pIomb, OSSA_OFFSET_OF(agsaSasReInitializeRsp_t, setFlags));
6341   OSSA_READ_LE_32(AGROOT, &MaxPorts, pIomb, OSSA_OFFSET_OF(agsaSasReInitializeRsp_t, MaxPorts));
6342   OSSA_READ_LE_32(AGROOT, &openRejReCmdData, pIomb, OSSA_OFFSET_OF(agsaSasReInitializeRsp_t, openRejReCmdData));
6343   OSSA_READ_LE_32(AGROOT, &sataHOLTMO, pIomb, OSSA_OFFSET_OF(agsaSasReInitializeRsp_t, sataHOLTMO));
6344 
6345   /* get request from IOMap */
6346   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
6347   if (agNULL == pRequest)
6348   {
6349     SA_DBG1(("mpiSasReInitializeRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
6350     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3X");
6351     return AGSA_RC_FAILURE;
6352   }
6353 
6354   agContext = saRoot->IOMap[tag].agContext;
6355   /* remove the request from IOMap */
6356   saRoot->IOMap[tag].Tag = MARK_OFF;
6357   saRoot->IOMap[tag].IORequest = agNULL;
6358   saRoot->IOMap[tag].agContext = agNULL;
6359 
6360   SA_ASSERT((pRequest->valid), "pRequest->valid");
6361 
6362   SASReconfig.flags = setFlags;
6363   SASReconfig.maxPorts = (bit8)(MaxPorts & 0xFF);
6364   SASReconfig.openRejectRetriesCmd = (bit16)((openRejReCmdData & 0xFFFF0000) >> SHIFT16);
6365   SASReconfig.openRejectRetriesData = (bit16)(openRejReCmdData & 0x0000FFFF);
6366   SASReconfig.sataHolTmo = (bit16)(sataHOLTMO & 0xFFFF);
6367   ossaReconfigSASParamsCB(agRoot, agContext, status, &SASReconfig);
6368 
6369   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6370   pRequest->valid = agFALSE;
6371   /* return the request to free pool */
6372   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
6373   {
6374     SA_DBG1(("mpiSasReInitializeRsp: saving pRequest (%p) for later use\n", pRequest));
6375     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
6376   }
6377   else
6378   {
6379     /* return the request to free pool */
6380     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
6381   }
6382   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6383 
6384   /* return value */
6385   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3X");
6386 
6387   return ret;
6388 }
6389 
6390 /******************************************************************************/
6391 /*! \brief serial GPIO Response
6392  *
6393  *  This routine handles the response of serial GPIO Response
6394  *
6395  *  \param agRoot       Handles for this instance of SAS/SATA LLL
6396  *  \param pIomb        Pointer of IOMB Mesage
6397  *
6398  *  \return sucess or fail
6399  *
6400  */
6401 /*******************************************************************************/
6402 GLOBAL bit32 mpiSGpioRsp(
6403   agsaRoot_t        *agRoot,
6404   agsaSGpioRsp_t    *pInIomb
6405   )
6406 {
6407   bit32                     ret = AGSA_RC_SUCCESS;
6408   agsaLLRoot_t              *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
6409   agsaIORequestDesc_t       *pRequest = NULL;
6410   agsaContext_t             *agContext = NULL;
6411   bit32                     i, tag, resultFunctionFrameType;
6412   agsaSGpioReqResponse_t    SgpioResponse = {0};
6413 
6414   smTraceFuncEnter(hpDBG_VERY_LOUD,"3Y");
6415 
6416   SA_DBG3(("mpiSGpioRsp: HTAG=0x%x\n", pInIomb->tag));
6417 
6418   OSSA_READ_LE_32(AGROOT, &tag, pInIomb, OSSA_OFFSET_OF(agsaSGpioRsp_t, tag));
6419   OSSA_READ_LE_32(AGROOT, &resultFunctionFrameType, pInIomb, OSSA_OFFSET_OF(agsaSGpioRsp_t, resultFunctionFrameType));
6420 
6421   SgpioResponse.smpFrameType = resultFunctionFrameType & 0xFF;
6422   SgpioResponse.function = (resultFunctionFrameType & 0xFF00) >> 8;
6423   SgpioResponse.functionResult = (resultFunctionFrameType & 0xFF0000) >> 16;
6424 
6425   if (SA_SAS_SMP_READ_GPIO_REGISTER == SgpioResponse.function)
6426   {
6427     for (i = 0; i < OSSA_SGPIO_MAX_READ_DATA_COUNT; i++)
6428     {
6429       OSSA_READ_LE_32(AGROOT, &SgpioResponse.readWriteData[i], pInIomb, OSSA_OFFSET_OF(agsaSGpioRsp_t, readData) + (i * 4));
6430     }
6431   }
6432 
6433   /* Get the request from IOMap */
6434   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
6435   if (agNULL == pRequest)
6436   {
6437     SA_DBG1(("mpiSGpioRsp: Bad Response IOMB!!! pRequest is NULL.TAG=0x%x STATUS=0x%x\n", tag, SgpioResponse.functionResult));
6438     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3Y");
6439     ret = AGSA_RC_FAILURE;
6440   }
6441   else
6442   {
6443     agContext = saRoot->IOMap[tag].agContext;
6444     ossaSGpioCB(agRoot, agContext, &SgpioResponse);
6445 
6446     /* Return the request to free pool */
6447     saReturnRequestToFreePool(agRoot, pRequest);
6448 
6449     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3Y");
6450   }
6451 
6452   return ret;
6453 }
6454 
6455 /******************************************************************************/
6456 /*! \brief PCIE Diagnostics Response
6457  *
6458  *  This routine handles the response of PCIE Diagnostics Response
6459  *
6460  *  \param agRoot       Handles for this instance of SAS/SATA LLL
6461  *  \param pIomb        Pointer of IOMB Mesage
6462  *
6463  *  \return sucess or fail
6464  *
6465  */
6466 /*******************************************************************************/
6467 GLOBAL bit32 mpiPCIeDiagExecuteRsp(
6468   agsaRoot_t                *agRoot,
6469   void                      *pInIomb
6470   )
6471 {
6472   bit32               ret = AGSA_RC_SUCCESS;
6473   agsaLLRoot_t        *saRoot = agNULL;
6474   agsaIORequestDesc_t *pRequest;
6475   agsaContext_t       *agContext;
6476   bit32               tag, Status, Command;
6477   agsaPCIeDiagResponse_t pciediadrsp;
6478   bit32  *pIomb = (bit32  *)pInIomb;
6479 
6480   smTraceFuncEnter(hpDBG_VERY_LOUD,"3Z");
6481 
6482   /* sanity check */
6483   SA_ASSERT((agNULL != agRoot), "");
6484   saRoot = (agsaLLRoot_t *) (agRoot->sdkData);
6485   SA_ASSERT((agNULL != saRoot), "");
6486 
6487   si_memset(&pciediadrsp, 0, sizeof(agsaPCIeDiagResponse_t));
6488 
6489   if(smIS_SPCV(agRoot))
6490   {
6491     OSSA_READ_LE_32(AGROOT, &tag,                  pIomb, OSSA_OFFSET_OF(agsaPCIeDiagExecuteRsp_t,tag));
6492     OSSA_READ_LE_32(AGROOT, &Command,              pIomb, OSSA_OFFSET_OF(agsaPCIeDiagExecuteRsp_t,CmdTypeDesc));
6493     OSSA_READ_LE_32(AGROOT, &Status,               pIomb, OSSA_OFFSET_OF(agsaPCIeDiagExecuteRsp_t,Status));
6494     OSSA_READ_LE_32(AGROOT, &pciediadrsp.ERR_BLKH, pIomb, OSSA_OFFSET_OF(agsaPCIeDiagExecuteRsp_t,ERR_BLKH ));
6495     OSSA_READ_LE_32(AGROOT, &pciediadrsp.ERR_BLKL, pIomb, OSSA_OFFSET_OF(agsaPCIeDiagExecuteRsp_t,ERR_BLKL ));
6496     OSSA_READ_LE_32(AGROOT, &pciediadrsp.DWord8,   pIomb, OSSA_OFFSET_OF(agsaPCIeDiagExecuteRsp_t,DWord8 ));
6497     OSSA_READ_LE_32(AGROOT, &pciediadrsp.DWord9,   pIomb, OSSA_OFFSET_OF(agsaPCIeDiagExecuteRsp_t,DWord9 ));
6498     OSSA_READ_LE_32(AGROOT, &pciediadrsp.DWord10,  pIomb, OSSA_OFFSET_OF(agsaPCIeDiagExecuteRsp_t,DWord10 ));
6499     OSSA_READ_LE_32(AGROOT, &pciediadrsp.DWord11,  pIomb, OSSA_OFFSET_OF(agsaPCIeDiagExecuteRsp_t,DWord11 ));
6500     OSSA_READ_LE_32(AGROOT, &pciediadrsp.DIF_ERR,  pIomb, OSSA_OFFSET_OF(agsaPCIeDiagExecuteRsp_t,DIF_ERR ));
6501     SA_DBG3(("mpiPCIeDiagExecuteRsp: HTAG=0x%x\n",tag));
6502   }
6503   else
6504   {
6505     OSSA_READ_LE_32(AGROOT, &tag,        pIomb,           OSSA_OFFSET_OF(agsa_SPC_PCIeDiagExecuteRsp_t,tag));
6506     OSSA_READ_LE_32(AGROOT, &Command,    pIomb,           OSSA_OFFSET_OF(agsa_SPC_PCIeDiagExecuteRsp_t,CmdTypeDesc));
6507     OSSA_READ_LE_32(AGROOT, &Status,     pIomb,           OSSA_OFFSET_OF(agsa_SPC_PCIeDiagExecuteRsp_t,Status));
6508     SA_DBG3(("mpiPCIeDiagExecuteRsp: SPC HTAG=0x%x\n",tag));
6509   }
6510 
6511   switch(Status)
6512   {
6513     case OSSA_PCIE_DIAG_SUCCESS:
6514       SA_DBG3(("mpiPCIeDiagExecuteRsp: OSSA_PCIE_DIAG_SUCCESS TAG=0x%x STATUS=0x%x\n", tag, Status));
6515       break;
6516     case OSSA_IO_INVALID_LENGTH:
6517       SA_DBG1(("mpiPCIeDiagExecuteRsp: OSSA_IO_INVALID_LENGTH TAG=0x%x STATUS=0x%x\n", tag, Status));
6518       break;
6519     case OSSA_PCIE_DIAG_INVALID_COMMAND:
6520       SA_DBG1(("mpiPCIeDiagExecuteRsp: OSSA_PCIE_DIAG_INVALID_COMMAND TAG=0x%x STATUS=0x%x\n", tag, Status));
6521       break;
6522     case OSSA_PCIE_DIAG_INTERNAL_FAILURE:
6523       SA_DBG1(("mpiPCIeDiagExecuteRsp: OSSA_PCIE_DIAG_INTERNAL_FAILURE TAG=0x%x STATUS=0x%x\n", tag, Status));
6524       break;
6525     case OSSA_PCIE_DIAG_INVALID_CMD_TYPE:
6526       SA_DBG1(("mpiPCIeDiagExecuteRsp: OSSA_PCIE_DIAG_INVALID_CMD_TYPE TAG=0x%x STATUS=0x%x\n", tag, Status));
6527       break;
6528     case OSSA_PCIE_DIAG_INVALID_CMD_DESC:
6529       SA_DBG1(("mpiPCIeDiagExecuteRsp: OSSA_PCIE_DIAG_INVALID_CMD_DESC TAG=0x%x STATUS=0x%x\n", tag, Status));
6530       break;
6531     case OSSA_PCIE_DIAG_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH:
6532       SA_DBG1(("mpiPCIeDiagExecuteRsp: OSSA_PCIE_DIAG_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH TAG=0x%x STATUS=0x%x\n", tag, Status));
6533       break;
6534     case OSSA_PCIE_DIAG_IO_XFR_ERROR_DIF_CRC_MISMATCH:
6535       SA_DBG1(("mpiPCIeDiagExecuteRsp: OSSA_PCIE_DIAG_IO_XFR_ERROR_DIF_CRC_MISMATCH TAG=0x%x STATUS=0x%x\n", tag, Status));
6536       break;
6537     case OSSA_PCIE_DIAG_INVALID_PCIE_ADDR:
6538       SA_DBG1(("mpiPCIeDiagExecuteRsp: OSSA_PCIE_DIAG_INVALID_PCIE_ADDR TAG=0x%x STATUS=0x%x\n", tag, Status));
6539       break;
6540     case OSSA_PCIE_DIAG_INVALID_BLOCK_SIZE:
6541       SA_DBG1(("mpiPCIeDiagExecuteRsp: OSSA_PCIE_DIAG_INVALID_BLOCK_SIZE TAG=0x%x STATUS=0x%x\n", tag, Status));
6542       break;
6543     case OSSA_PCIE_DIAG_LENGTH_NOT_BLOCK_SIZE_ALIGNED:
6544       SA_DBG1(("mpiPCIeDiagExecuteRsp: OSSA_PCIE_DIAG_LENGTH_NOT_BLOCK_SIZE_ALIGNED TAG=0x%x STATUS=0x%x\n", tag, Status));
6545       break;
6546     case OSSA_PCIE_DIAG_IO_XFR_ERROR_DIF_MISMATCH:
6547       SA_DBG1(("mpiPCIeDiagExecuteRsp: OSSA_PCIE_DIAG_IO_XFR_ERROR_DIF_MISMATCH TAG=0x%x STATUS=0x%x\n", tag, Status));
6548       break;
6549     case OSSA_PCIE_DIAG_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH:
6550       SA_DBG1(("mpiPCIeDiagExecuteRsp: OSSA_PCIE_DIAG_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH TAG=0x%x STATUS=0x%x\n", tag, Status));
6551       break;
6552     default:
6553       SA_DBG1(("mpiPCIeDiagExecuteRsp:  UNKNOWN status TAG=0x%x STATUS=0x%x\n", tag, Status));
6554       break;
6555   }
6556   /* get request from IOMap */
6557   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
6558   if (agNULL == pRequest)
6559   {
6560     SA_DBG1(("mpiPCIeDiagExecuteRsp: Bad Response IOMB!!! pRequest is NULL.TAG=0x%x STATUS=0x%x\n", tag, Status));
6561     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3Z");
6562     return AGSA_RC_FAILURE;
6563   }
6564 
6565   agContext = saRoot->IOMap[tag].agContext;
6566   /* remove the request from IOMap */
6567   saRoot->IOMap[tag].Tag = MARK_OFF;
6568   saRoot->IOMap[tag].IORequest = agNULL;
6569   saRoot->IOMap[tag].agContext = agNULL;
6570 
6571   SA_ASSERT((pRequest->valid), "pRequest->valid");
6572 
6573   ossaPCIeDiagExecuteCB(agRoot, agContext, Status, Command,&pciediadrsp);
6574 
6575   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6576   pRequest->valid = agFALSE;
6577   /* return the request to free pool */
6578   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
6579   {
6580     SA_DBG1(("mpiPCIeDiagExecuteRsp: saving pRequest (%p) for later use\n", pRequest));
6581     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
6582   }
6583   else
6584   {
6585     /* return the request to free pool */
6586     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
6587   }
6588   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6589 
6590   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3Z");
6591 
6592   /* return value */
6593   return ret;
6594 }
6595 /******************************************************************************/
6596 /*! \brief Get DFE Data command Response
6597  *
6598  *  This routine handles the response of Get DFE Data command Response
6599  *
6600  *  \param agRoot       Handles for this instance of SAS/SATA LLL
6601  *  \param pIomb        Pointer of IOMB Mesage
6602  *
6603  *  \return sucess or fail
6604  *
6605  */
6606 /*******************************************************************************/
6607 GLOBAL bit32 mpiGetDFEDataRsp(
6608   agsaRoot_t    *agRoot,
6609   void          *pIomb
6610   )
6611 {
6612   bit32               ret = AGSA_RC_SUCCESS;
6613   agsaLLRoot_t        *saRoot = agNULL;
6614   agsaIORequestDesc_t *pRequest;
6615   agsaContext_t       *agContext;
6616   bit32               tag = 0, status = 0, In_Ln = 0, MCNT = 0, NBT = 0;
6617 
6618   smTraceFuncEnter(hpDBG_VERY_LOUD,"2Y");
6619 
6620   /* sanity check */
6621   SA_ASSERT((agNULL != agRoot), "");
6622   saRoot = (agsaLLRoot_t *) (agRoot->sdkData);
6623   SA_ASSERT((agNULL != saRoot), "");
6624 
6625   if(smIS_SPCV(agRoot))
6626   {
6627     OSSA_READ_LE_32(AGROOT, &tag,                pIomb, OSSA_OFFSET_OF(agsaGetDDEFDataRsp_t,tag));
6628     OSSA_READ_LE_32(AGROOT, &status,             pIomb, OSSA_OFFSET_OF(agsaGetDDEFDataRsp_t,status));
6629     OSSA_READ_LE_32(AGROOT, &In_Ln,              pIomb, OSSA_OFFSET_OF(agsaGetDDEFDataRsp_t,reserved_In_Ln));
6630     OSSA_READ_LE_32(AGROOT, &MCNT,               pIomb, OSSA_OFFSET_OF(agsaGetDDEFDataRsp_t,MCNT));
6631     OSSA_READ_LE_32(AGROOT, &NBT,                pIomb, OSSA_OFFSET_OF(agsaGetDDEFDataRsp_t,NBT));
6632   }
6633   else
6634   {
6635     /* SPC does not support this command */
6636   }
6637 
6638   switch(status)
6639   {
6640     case OSSA_DFE_MPI_IO_SUCCESS:
6641       SA_DBG3(("mpiGetDFEDataRsp: OSSA_DFE_MPI_IO_SUCCESS TAG=0x%x STATUS=0x%x\n", tag, status));
6642       break;
6643     case OSSA_DFE_DATA_OVERFLOW:
6644       SA_DBG1(("mpiGetDFEDataRsp: OSSA_DFE_DATA_OVERFLOW TAG=0x%x STATUS=0x%x\n", tag, status));
6645       break;
6646     case OSSA_DFE_MPI_ERR_RESOURCE_UNAVAILABLE:
6647       SA_DBG1(("mpiGetDFEDataRsp: OSSA_DFE_MPI_ERR_RESOURCE_UNAVAILABLE TAG=0x%x STATUS=0x%x\n", tag, status));
6648       break;
6649     case OSSA_DFE_CHANNEL_DOWN:
6650       SA_DBG1(("mpiGetDFEDataRsp: OSSA_DFE_CHANNEL_DOWN TAG=0x%x STATUS=0x%x\n", tag, status));
6651       break;
6652     case OSSA_DFE_MEASUREMENT_IN_PROGRESS:
6653       SA_DBG1(("mpiGetDFEDataRsp: OSSA_DFE_MEASUREMENT_IN_PROGRESS TAG=0x%x STATUS=0x%x\n", tag, status));
6654       break;
6655     case OSSA_DFE_CHANNEL_INVALID:
6656       SA_DBG1(("mpiGetDFEDataRsp: OSSA_DFE_CHANNEL_INVALID TAG=0x%x STATUS=0x%x\n", tag, status));
6657       break;
6658     case OSSA_DFE_DMA_FAILURE:
6659       SA_DBG1(("mpiGetDFEDataRsp: OSSA_DFE_DMA_FAILURE TAG=0x%x STATUS=0x%x\n", tag, status));
6660       break;
6661     default:
6662       SA_DBG1(("mpiGetDFEDataRsp:  UNKNOWN status TAG=0x%x STATUS=0x%x\n", tag, status));
6663       break;
6664    }
6665 
6666   /* get request from IOMap */
6667   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
6668   if (agNULL == pRequest)
6669   {
6670     SA_DBG1(("mpiGetDFEDataRsp: Bad Response IOMB!!! pRequest is NULL.TAG=0x%x STATUS=0x%x\n", tag, status));
6671     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2Y");
6672     return AGSA_RC_FAILURE;
6673   }
6674 
6675   agContext = saRoot->IOMap[tag].agContext;
6676   /* remove the request from IOMap */
6677   saRoot->IOMap[tag].Tag = MARK_OFF;
6678   saRoot->IOMap[tag].IORequest = agNULL;
6679   saRoot->IOMap[tag].agContext = agNULL;
6680 
6681   SA_ASSERT((pRequest->valid), "pRequest->valid");
6682 
6683   ossaGetDFEDataCB(agRoot, agContext, status, NBT);
6684 
6685   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6686   pRequest->valid = agFALSE;
6687   /* return the request to free pool */
6688   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
6689   {
6690     SA_DBG1(("mpiGetDFEDataRsp: saving pRequest (%p) for later use\n", pRequest));
6691     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
6692   }
6693   else
6694   {
6695     /* return the request to free pool */
6696     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
6697   }
6698   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6699 
6700   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2Y");
6701 
6702   return ret;
6703 }
6704 
6705 
6706 /******************************************************************************/
6707 /*! \brief SAS Set Controller Config Response
6708  *
6709  *  This routine handles the response of Set Controller Config Command
6710  *
6711  *  \param agRoot       Handles for this instance of SAS/SATA LLL
6712  *  \param pIomb        Pointer of IOMB Mesage
6713  *
6714  *  \return sucess or fail
6715  *
6716  */
6717 /*******************************************************************************/
6718 GLOBAL bit32 mpiSetControllerConfigRsp(
6719   agsaRoot_t                   *agRoot,
6720   agsaSetControllerConfigRsp_t *pIomb
6721   )
6722 {
6723   agsaLLRoot_t          *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
6724   agsaIORequestDesc_t   *pRequest;
6725   agsaHWEventMode_t     agMode;
6726   bit32                 status, errorQualifierPage, tag;
6727   bit32                 errorQualifier;
6728   bit32                 pagetype;
6729 
6730   smTraceFuncEnter(hpDBG_VERY_LOUD,"3a");
6731 
6732   SA_DBG1(("mpiSetControllerConfigRsp: HTag=0x%x\n", pIomb->tag));
6733 
6734   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaSetControllerConfigRsp_t, tag));
6735   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaSetControllerConfigRsp_t, status));
6736   OSSA_READ_LE_32(AGROOT, &errorQualifierPage, pIomb, OSSA_OFFSET_OF(agsaSetControllerConfigRsp_t, errorQualifierPage));
6737 
6738   /* get request from IOMap */
6739   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
6740   if (agNULL == pRequest)
6741   {
6742     SA_DBG1(("mpiSetControllerConfigRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
6743     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3a");
6744     return AGSA_RC_FAILURE;
6745   }
6746 
6747   si_memset(&agMode, 0, sizeof(agsaHWEventMode_t));
6748   agMode.modePageOperation = agsaModePageSet;
6749   agMode.status = status;
6750   agMode.context = saRoot->IOMap[tag].agContext;
6751   errorQualifier = (errorQualifierPage & 0xFFFF0000) >> SHIFT16;
6752   pagetype = (errorQualifierPage & 0xFF);
6753 
6754   if(status )
6755   {
6756     SA_DBG1(("mpiSetControllerConfigRsp: Error detected tag 0x%x pagetype 0x%x status 0x%x errorQualifier 0x%x\n",
6757       tag, pagetype,status, errorQualifier));
6758   }
6759   else
6760   {
6761     SA_DBG1(("mpiSetControllerConfigRsp: tag 0x%x pagetype 0x%x status 0x%x\n", tag, pagetype,status ));
6762   }
6763 
6764 
6765   switch( pagetype)
6766   {
6767     case AGSA_ENCRYPTION_DEK_CONFIG_PAGE:
6768     case AGSA_SAS_PROTOCOL_TIMER_CONFIG_PAGE:
6769     case AGSA_INTERRUPT_CONFIGURATION_PAGE:
6770     case AGSA_ENCRYPTION_HMAC_CONFIG_PAGE:
6771     case AGSA_IO_GENERAL_CONFIG_PAGE:
6772     /*case AGSA_ENCRYPTION_CONTROL_PARM_PAGE:*/
6773       /* Report the event before freeing the IOMB */
6774       SA_DBG1(("mpiSetControllerConfigRsp:OSSA_HW_EVENT_MODE\n"));
6775       ossaHwCB(agRoot,agMode.context, OSSA_HW_EVENT_MODE, errorQualifierPage, (void *) &agMode, 0);
6776 
6777 
6778       break;
6779 
6780     case AGSA_ENCRYPTION_GENERAL_CONFIG_PAGE:
6781       SA_DBG1(("mpiSetControllerConfigRsp:warning!!!! GENERAL_CONFIG_PAGE is read only, cannot be set\n"));
6782       break;
6783 
6784     /* why we need to read the scrach pad register when handling ENCRYPTION_SECURITY_PARM_PAGE??? */
6785     case AGSA_ENCRYPTION_CONTROL_PARM_PAGE:
6786     {
6787       bit32 ScratchPad1 = 0;
6788       bit32 ScratchPad3 = 0;
6789       agsaEncryptInfo_t encrypt;
6790       agsaEncryptInfo_t *encryptInfo = &encrypt;
6791       SA_DBG1(("mpiSetControllerConfigRsp: AGSA_ENCRYPTION_CONTROL_PARM_PAGE\n" ));
6792 
6793       if( pRequest->modePageContext)
6794       {
6795         pRequest->modePageContext = agFALSE;
6796       }
6797 
6798       si_memset(&encrypt, 0, sizeof(agsaEncryptInfo_t));
6799       encryptInfo->status = 0;
6800       encryptInfo->encryptionCipherMode = 0;
6801       encryptInfo->encryptionSecurityMode = 0;
6802 
6803       ScratchPad1 = ossaHwRegRead(agRoot,V_Scratchpad_1_Register);
6804       ScratchPad3 = ossaHwRegRead(agRoot,V_Scratchpad_3_Register);
6805       if( ScratchPad3 & SCRATCH_PAD3_V_XTS_ENABLED)
6806       {
6807         encryptInfo->encryptionCipherMode = agsaEncryptCipherModeXTS;
6808       }
6809       if( (ScratchPad3 & SCRATCH_PAD3_V_SM_MASK ) == SCRATCH_PAD3_V_SMF_ENABLED )
6810       {
6811         encryptInfo->encryptionSecurityMode = agsaEncryptSMF;
6812       }
6813       if( (ScratchPad3 & SCRATCH_PAD3_V_SM_MASK ) == SCRATCH_PAD3_V_SMA_ENABLED)
6814       {
6815         encryptInfo->encryptionSecurityMode = agsaEncryptSMA;
6816       }
6817       if( (ScratchPad3 & SCRATCH_PAD3_V_SM_MASK ) == SCRATCH_PAD3_V_SMB_ENABLED )
6818       {
6819         encryptInfo->encryptionSecurityMode = agsaEncryptSMB;
6820       }
6821       if((ScratchPad1 & SCRATCH_PAD1_V_RAAE_MASK) ==  SCRATCH_PAD1_V_RAAE_MASK)
6822       {
6823         if((ScratchPad3 & SCRATCH_PAD3_V_ENC_MASK) == SCRATCH_PAD3_V_ENC_READY ) /* 3 */
6824         {
6825           encryptInfo->status = AGSA_RC_SUCCESS;
6826         }
6827         else if((ScratchPad3 & SCRATCH_PAD3_V_ENC_READY) == SCRATCH_PAD3_V_ENC_DISABLED) /* 0 */
6828         {
6829           encryptInfo->status = 0xFFFF;
6830           encryptInfo->encryptionCipherMode = 0;
6831           encryptInfo->encryptionSecurityMode = 0;
6832         }
6833         else if((ScratchPad3 & SCRATCH_PAD3_V_ENC_MASK ) == SCRATCH_PAD3_V_ENC_DIS_ERR) /* 1 */
6834         {
6835           encryptInfo->status = (ScratchPad3 & SCRATCH_PAD3_V_ERR_CODE ) >> SHIFT16;
6836         }
6837         else if((ScratchPad3 & SCRATCH_PAD3_V_ENC_MASK ) == SCRATCH_PAD3_V_ENC_ENA_ERR) /* 2 */
6838         {
6839           encryptInfo->status = (ScratchPad3 & SCRATCH_PAD3_V_ERR_CODE ) >> SHIFT16;
6840         }
6841       }
6842       else  if((ScratchPad1 & SCRATCH_PAD1_V_RAAE_MASK) ==  SCRATCH_PAD1_V_RAAE_ERR)
6843       {
6844         SA_DBG1(("mpiSetControllerConfigRsp, RAAE not ready SPC AGSA_RC_FAILURE\n"));
6845         encryptInfo->status = 0xFFFF;
6846         encryptInfo->encryptionCipherMode = 0;
6847         encryptInfo->encryptionSecurityMode = 0;
6848       }
6849       else  if((ScratchPad1 & SCRATCH_PAD1_V_RAAE_MASK) == 0x0 )
6850       {
6851         SA_DBG2(("mpiSetControllerConfigRsp, RAAE not ready AGSA_RC_BUSY\n"));
6852       }
6853 
6854       SA_DBG2(("mpiSetControllerConfigRsp, encryptionCipherMode 0x%x encryptionSecurityMode 0x%x status 0x%x\n",
6855                 encryptInfo->encryptionCipherMode,
6856                 encryptInfo->encryptionSecurityMode,
6857                 encryptInfo->status));
6858       SA_DBG2(("mpiSetControllerConfigRsp, ScratchPad3 0x%x\n",ScratchPad3));
6859       SA_DBG1(("mpiSetControllerConfigRsp:AGSA_ENCRYPTION_CONTROL_PARM_PAGE 0x%X\n", agMode.modePageOperation));
6860       ossaHwCB(agRoot, agNULL, OSSA_HW_EVENT_SECURITY_MODE, errorQualifier, (void *)encryptInfo, agMode.context);
6861       break;
6862     }
6863 
6864     default:
6865       SA_DBG1(("mpiSetControllerConfigRsp: Unknown page code 0x%X\n", pagetype));
6866       break;
6867   }
6868 
6869   /* remove the request from IOMap */
6870   saRoot->IOMap[tag].Tag = MARK_OFF;
6871   saRoot->IOMap[tag].IORequest = agNULL;
6872   saRoot->IOMap[tag].agContext = agNULL;
6873 
6874   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6875   SA_ASSERT((pRequest->valid), "pRequest->valid");
6876   pRequest->valid = agFALSE;
6877   /* return the request to free pool */
6878   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
6879   {
6880     SA_DBG1(("mpiSetControllerRsp: saving pRequest (%p) for later use\n", pRequest));
6881     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
6882   }
6883   else
6884   {
6885     /* return the request to free pool */
6886     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
6887   }
6888   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
6889 
6890   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3a");
6891   return AGSA_RC_SUCCESS;
6892 
6893 }
6894 
6895 /******************************************************************************/
6896 /*! \brief SAS Get Controller Config Response
6897  *
6898  *  This routine handles the response of Get Controller Config Command
6899  *
6900  *  \param agRoot       Handles for this instance of SAS/SATA LLL
6901  *  \param pIomb        Pointer of IOMB Mesage
6902  *
6903  *  \return sucess or fail
6904  *
6905  */
6906 /*******************************************************************************/
6907 GLOBAL bit32 mpiGetControllerConfigRsp(
6908   agsaRoot_t               *agRoot,
6909   agsaGetControllerConfigRsp_t *pIomb
6910   )
6911 {
6912   agsaLLRoot_t          *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
6913   agsaIORequestDesc_t   *pRequest;
6914   agsaHWEventMode_t     agMode;
6915   bit32                 status, errorQualifier, tag;
6916   bit32                 configPage[12];
6917 
6918   smTraceFuncEnter(hpDBG_VERY_LOUD,"3b");
6919 
6920   si_memset(&agMode, 0, sizeof(agsaHWEventMode_t));
6921   si_memset(configPage, 0, sizeof(configPage));
6922 
6923 
6924   SA_DBG2(("mpiGetControllerConfigRsp: HTag=0x%x\n", pIomb->tag));
6925 
6926   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaGetControllerConfigRsp_t, tag));
6927   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaGetControllerConfigRsp_t, status));
6928   OSSA_READ_LE_32(AGROOT, &errorQualifier, pIomb, OSSA_OFFSET_OF(agsaGetControllerConfigRsp_t, errorQualifier));
6929   OSSA_READ_LE_32(AGROOT, &configPage[0],  pIomb, OSSA_OFFSET_OF(agsaGetControllerConfigRsp_t,configPage[0] ));
6930   OSSA_READ_LE_32(AGROOT, &configPage[1],  pIomb, OSSA_OFFSET_OF(agsaGetControllerConfigRsp_t,configPage[1] ));
6931   OSSA_READ_LE_32(AGROOT, &configPage[2],  pIomb, OSSA_OFFSET_OF(agsaGetControllerConfigRsp_t,configPage[2] ));
6932   OSSA_READ_LE_32(AGROOT, &configPage[3],  pIomb, OSSA_OFFSET_OF(agsaGetControllerConfigRsp_t,configPage[3] ));
6933   OSSA_READ_LE_32(AGROOT, &configPage[4],  pIomb, OSSA_OFFSET_OF(agsaGetControllerConfigRsp_t,configPage[4] ));
6934   OSSA_READ_LE_32(AGROOT, &configPage[5],  pIomb, OSSA_OFFSET_OF(agsaGetControllerConfigRsp_t,configPage[5] ));
6935 
6936   /* get request from IOMap */
6937   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
6938   if (agNULL == pRequest)
6939   {
6940     SA_DBG1(("mpiGetControllerConfigRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
6941     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3b");
6942     return AGSA_RC_FAILURE;
6943   }
6944 
6945   si_memset(&agMode, 0, sizeof(agsaHWEventMode_t));
6946   agMode.modePageOperation = agsaModePageGet;
6947   agMode.status = status;
6948 
6949   SA_DBG1(("mpiGetControllerConfigRsp: page 0x%x status 0x%x errorQualifier 0x%x \n", (pIomb->configPage[0] & 0xFF),status, errorQualifier));
6950 
6951   switch (pIomb->configPage[0] & 0xFF)
6952   {
6953   case AGSA_SAS_PROTOCOL_TIMER_CONFIG_PAGE:
6954       agMode.modePageLen = sizeof(agsaSASProtocolTimerConfigurationPage_t);
6955       SA_DBG1(("mpiGetControllerConfigRsp: AGSA_SAS_PROTOCOL_TIMER_CONFIG_PAGE page len 0x%x \n",agMode.modePageLen));
6956       break;
6957   case AGSA_INTERRUPT_CONFIGURATION_PAGE:
6958       agMode.modePageLen = sizeof(agsaInterruptConfigPage_t);
6959       SA_DBG1(("mpiGetControllerConfigRsp: AGSA_INTERRUPT_CONFIGURATION_PAGE page len 0x%x \n",agMode.modePageLen));
6960       break;
6961   case AGSA_IO_GENERAL_CONFIG_PAGE:
6962       agMode.modePageLen = sizeof(agsaIoGeneralPage_t);
6963       SA_DBG1(("mpiGetControllerConfigRsp: AGSA_IO_GENERAL_CONFIG_PAGE page len 0x%x \n",agMode.modePageLen));
6964       break;
6965   case AGSA_ENCRYPTION_GENERAL_CONFIG_PAGE:
6966       agMode.modePageLen = sizeof(agsaEncryptGeneralPage_t);
6967       SA_DBG1(("mpiGetControllerConfigRsp: AGSA_ENCRYPTION_GENERAL_CONFIG_PAGE page len 0x%x \n",agMode.modePageLen));
6968 #ifdef HIALEAH_ENCRYPTION
6969       saRoot->EncGenPage.numberOfKeksPageCode = configPage[0];
6970       saRoot->EncGenPage.KeyCardIdKekIndex    = configPage[1];
6971       saRoot->EncGenPage.KeyCardId3_0         = configPage[2];
6972       saRoot->EncGenPage.KeyCardId7_4         = configPage[3];
6973       saRoot->EncGenPage.KeyCardId11_8        = configPage[4];
6974 
6975       SA_DBG1(("mpiGetControllerConfigRsp: numberOfKeksPageCode 0x%x\n",saRoot->EncGenPage.numberOfKeksPageCode));
6976       SA_DBG1(("mpiGetControllerConfigRsp: KeyCardIdKekIndex    0x%x\n",saRoot->EncGenPage.KeyCardIdKekIndex));
6977       SA_DBG1(("mpiGetControllerConfigRsp: KeyCardId3_0         0x%x\n",saRoot->EncGenPage.KeyCardId3_0));
6978       SA_DBG1(("mpiGetControllerConfigRsp: KeyCardId7_4         0x%x\n",saRoot->EncGenPage.KeyCardId7_4));
6979       SA_DBG1(("mpiGetControllerConfigRsp: KeyCardId11_8        0x%x\n",saRoot->EncGenPage.KeyCardId11_8));
6980 #endif /* HIALEAH_ENCRYPTION */
6981 
6982       break;
6983   case AGSA_ENCRYPTION_DEK_CONFIG_PAGE:
6984       agMode.modePageLen = sizeof(agsaEncryptDekConfigPage_t);
6985       SA_DBG1(("mpiGetControllerConfigRsp: AGSA_ENCRYPTION_DEK_CONFIG_PAGE page len 0x%x \n",agMode.modePageLen));
6986       break;
6987   case AGSA_ENCRYPTION_CONTROL_PARM_PAGE:
6988       agMode.modePageLen = sizeof(agsaEncryptControlParamPage_t);
6989       SA_DBG1(("mpiGetControllerConfigRsp: AGSA_ENCRYPTION_CONTROL_PARM_PAGE page len 0x%x \n",agMode.modePageLen));
6990       break;
6991   case AGSA_ENCRYPTION_HMAC_CONFIG_PAGE:
6992       agMode.modePageLen = sizeof(agsaEncryptHMACConfigPage_t);
6993       SA_DBG1(("mpiGetControllerConfigRsp: AGSA_ENCRYPTION_HMAC_CONFIG_PAGE page len 0x%x \n",agMode.modePageLen));
6994       break;
6995   default:
6996       agMode.modePageLen = 0;
6997       SA_DBG1(("mpiGetControllerConfigRsp: Unknown !!! page len 0x%x \n",agMode.modePageLen));
6998       break;
6999   }
7000 
7001   agMode.modePage = (void *) &pIomb->configPage[0];
7002   agMode.context = saRoot->IOMap[tag].agContext;
7003 
7004   /* Report the event before freeing the IOMB */
7005   ossaHwCB(agRoot, NULL, OSSA_HW_EVENT_MODE, errorQualifier, (void *) &agMode, 0);
7006 
7007   /* remove the request from IOMap */
7008   saRoot->IOMap[tag].Tag = MARK_OFF;
7009   saRoot->IOMap[tag].IORequest = agNULL;
7010   saRoot->IOMap[tag].agContext = agNULL;
7011 
7012   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7013   SA_ASSERT((pRequest->valid), "pRequest->valid");
7014   pRequest->valid = agFALSE;
7015   /* return the request to free pool */
7016   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
7017   {
7018     SA_DBG1(("mpiGetControllerRsp: saving pRequest (%p) for later use\n", pRequest));
7019     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
7020   }
7021   else
7022   {
7023     /* return the request to free pool */
7024     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
7025   }
7026   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7027 
7028   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3b");
7029   return AGSA_RC_SUCCESS;
7030 }
7031 
7032 /******************************************************************************/
7033 /*! \brief KEK Management Response
7034  *
7035  *  This routine handles the response of the KEK management message
7036  *
7037  *  \param agRoot       Handles for this instance of SAS/SATA LLL
7038  *  \param pIomb        Pointer of IOMB Mesage
7039  *
7040  *  \return sucess or fail
7041  *
7042  */
7043 /*******************************************************************************/
7044 GLOBAL bit32 mpiKekManagementRsp(
7045   agsaRoot_t               *agRoot,
7046   agsaKekManagementRsp_t *pIomb
7047   )
7048 {
7049   agsaLLRoot_t          *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
7050   agsaIORequestDesc_t   *pRequest;
7051   agsaContext_t         *agContext;
7052   agsaHWEventEncrypt_t  agEvent;
7053   bit32                 status, errorQualifier, tag, flags;
7054   smTraceFuncEnter(hpDBG_VERY_LOUD,"2A");
7055 
7056   SA_DBG1(("mpiKekManagementRsp: HTag=0x%x\n", pIomb->tag));
7057 
7058   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaKekManagementRsp_t, tag));
7059   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaKekManagementRsp_t, status));
7060   OSSA_READ_LE_32(AGROOT, &flags, pIomb, OSSA_OFFSET_OF(agsaKekManagementRsp_t, flags));
7061   OSSA_READ_LE_32(AGROOT, &errorQualifier, pIomb, OSSA_OFFSET_OF(agsaKekManagementRsp_t, errorQualifier));
7062 
7063 
7064   SA_DBG1(("mpiKekManagementRsp:status 0x%x flags 0x%x errorQualifier 0x%x\n", status, flags, errorQualifier));
7065 
7066   si_memset(&agEvent, 0, sizeof(agsaHWEventEncrypt_t));
7067   if ((flags & 0xFF) == KEK_MGMT_SUBOP_UPDATE)
7068   {
7069     SA_DBG1(("mpiKekManagementRsp:KEK_MGMT_SUBOP_UPDATE 0x%x \n", status));
7070     if (flags & 0xFF00) /* update and store*/
7071     {
7072       agEvent.encryptOperation = OSSA_HW_ENCRYPT_KEK_UPDATE_AND_STORE;
7073     }
7074     else /* update */
7075     {
7076       agEvent.encryptOperation = OSSA_HW_ENCRYPT_KEK_UPDATE;
7077     }
7078     agEvent.status = status;
7079     if (status == OSSA_MPI_ENC_ERR_ILLEGAL_KEK_PARAM)
7080     {
7081         agEvent.eq = errorQualifier;
7082     }
7083     agEvent.info = 0;
7084     /* Store the new KEK index in agEvent.handle */
7085     agEvent.handle = (void *) ((bitptr) (flags >> 24));
7086     /* Store the current KEK index in agEvent.param */
7087     agEvent.param = (void *) ((bitptr) (flags >> 16) & 0xFF);
7088 
7089   }
7090 
7091   else if ((flags & 0xFF) == KEK_MGMT_SUBOP_INVALIDATE)
7092   {
7093       agEvent.encryptOperation = OSSA_HW_ENCRYPT_KEK_INVALIDTE;
7094       agEvent.status = status;
7095       if (status == OSSA_MPI_ENC_ERR_ILLEGAL_KEK_PARAM)
7096       {
7097           agEvent.eq = errorQualifier;
7098       }
7099       agEvent.info = 0;
7100       /* Store the new KEK index in agEvent.handle */
7101       agEvent.handle = (void *) ((bitptr) (flags >> 24));
7102       /* Store the current KEK index in agEvent.param */
7103       agEvent.param = (void *) ((bitptr) (flags >> 16) & 0xFF);
7104   }
7105 
7106   else if ((flags & 0xFF) == KEK_MGMT_SUBOP_KEYCARDINVALIDATE)
7107   {
7108      agEvent.encryptOperation = OSSA_HW_ENCRYPT_KEK_UPDATE_AND_STORE;
7109       agEvent.status = status;
7110       if (status == OSSA_MPI_ENC_ERR_ILLEGAL_KEK_PARAM)
7111       {
7112           agEvent.eq = errorQualifier;
7113       }
7114       agEvent.info = 0;
7115       /* Store the new KEK index in agEvent.handle */
7116       agEvent.handle = (void *) ((bitptr) (flags >> 24));
7117       /* Store the current KEK index in agEvent.param */
7118       agEvent.param = (void *) ((bitptr) (flags >> 16) & 0xFF);
7119 
7120   }
7121 
7122   else if ((flags & 0xFF) == KEK_MGMT_SUBOP_KEYCARDUPDATE)
7123   {
7124      agEvent.encryptOperation = OSSA_HW_ENCRYPT_KEK_UPDATE;
7125       agEvent.status = status;
7126       if (status == OSSA_MPI_ENC_ERR_ILLEGAL_KEK_PARAM)
7127       {
7128           agEvent.eq = errorQualifier;
7129       }
7130       agEvent.info = 0;
7131       /* Store the new KEK index in agEvent.handle */
7132       agEvent.handle = (void *) ((bitptr) (flags >> 24));
7133       /* Store the current KEK index in agEvent.param */
7134       agEvent.param = (void *) ((bitptr) (flags >> 16) & 0xFF);
7135 
7136   }
7137   /* get request from IOMap */
7138   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
7139   if (agNULL == pRequest)
7140   {
7141     SA_DBG1(("mpiKekManagementRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
7142     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2A");
7143     return AGSA_RC_FAILURE;
7144   }
7145 
7146   agContext = saRoot->IOMap[tag].agContext;
7147   /* remove the request from IOMap */
7148   saRoot->IOMap[tag].Tag = MARK_OFF;
7149   saRoot->IOMap[tag].IORequest = agNULL;
7150   saRoot->IOMap[tag].agContext = agNULL;
7151 
7152   ossaHwCB(agRoot, NULL, OSSA_HW_EVENT_ENCRYPTION, 0, (void *) &agEvent, agContext);
7153 
7154   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7155   SA_ASSERT((pRequest->valid), "pRequest->valid");
7156   pRequest->valid = agFALSE;
7157   /* return the request to free pool */
7158   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
7159   {
7160     SA_DBG1(("mpiKekManagementRsp: saving pRequest (%p) for later use\n", pRequest));
7161     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
7162   }
7163   else
7164   {
7165     /* return the request to free pool */
7166     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
7167   }
7168   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7169 
7170   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2A");
7171 
7172   return AGSA_RC_SUCCESS;
7173 }
7174 
7175 /******************************************************************************/
7176 /*! \brief DEK Management Response
7177  *
7178  *  This routine handles the response of the DEK management message
7179  *
7180  *  \param agRoot       Handles for this instance of SAS/SATA LLL
7181  *  \param pIomb        Pointer of IOMB Mesage
7182  *
7183  *  \return sucess or fail
7184  *
7185  */
7186 /*******************************************************************************/
7187 GLOBAL bit32 mpiDekManagementRsp(
7188   agsaRoot_t               *agRoot,
7189   agsaDekManagementRsp_t   *pIomb
7190   )
7191 {
7192   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
7193   agsaIORequestDesc_t *pRequest;
7194   agsaContext_t       *agContext;
7195   agsaHWEventEncrypt_t agEvent;
7196   bit32               flags, status, errorQualifier, tag, dekIndex;
7197 
7198   smTraceFuncEnter(hpDBG_VERY_LOUD,"2B");
7199 
7200   SA_DBG1(("mpiDekManagementRsp: HTag=0x%x\n", pIomb->tag));
7201 
7202   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaDekManagementRsp_t, tag));
7203   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaDekManagementRsp_t, status));
7204   OSSA_READ_LE_32(AGROOT, &flags, pIomb, OSSA_OFFSET_OF(agsaDekManagementRsp_t, flags));
7205   OSSA_READ_LE_32(AGROOT, &errorQualifier, pIomb, OSSA_OFFSET_OF(agsaDekManagementRsp_t, errorQualifier));
7206   OSSA_READ_LE_32(AGROOT, &dekIndex, pIomb, OSSA_OFFSET_OF(agsaDekManagementRsp_t, dekIndex));
7207 
7208   SA_DBG2(("mpiDekManagementRsp:tag =0x%x\n",tag ));
7209   SA_DBG2(("mpiDekManagementRsp:status =0x%x\n", status));
7210   SA_DBG2(("mpiDekManagementRsp:flags =0x%x\n",flags ));
7211   SA_DBG2(("mpiDekManagementRsp:errorQualifier =0x%x\n", errorQualifier));
7212   SA_DBG2(("mpiDekManagementRsp:dekIndex =0x%x\n",dekIndex ));
7213 
7214   si_memset(&agEvent, 0, sizeof(agsaHWEventEncrypt_t));
7215   if ((flags & 0xFF) == DEK_MGMT_SUBOP_UPDATE)
7216   {
7217      agEvent.encryptOperation = OSSA_HW_ENCRYPT_DEK_UPDATE;
7218   }
7219   else
7220   {
7221      agEvent.encryptOperation = OSSA_HW_ENCRYPT_DEK_INVALIDTE;
7222   }
7223   agEvent.status = status;
7224   if (status == OSSA_MPI_ENC_ERR_ILLEGAL_DEK_PARAM || OSSA_MPI_ERR_DEK_MANAGEMENT_DEK_UNWRAP_FAIL)
7225   {
7226     agEvent.eq = errorQualifier;
7227   }
7228   /* Store the DEK in agEvent.info */
7229   agEvent.info = (flags >> 8) & 0xF;
7230   /* Store the KEK index in agEvent.handle */
7231   agEvent.handle = (void *) ((bitptr) (flags >> 24));
7232   /* Store the DEK index in agEvent.param */
7233   agEvent.param = (void *) (bitptr) dekIndex;
7234 
7235   /* get request from IOMap */
7236   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
7237   if (agNULL == pRequest)
7238   {
7239     SA_DBG1(("mpiDekManagementRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
7240     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "2B");
7241     return AGSA_RC_FAILURE;
7242   }
7243 
7244   agContext = saRoot->IOMap[tag].agContext;
7245   /* remove the request from IOMap */
7246   saRoot->IOMap[tag].Tag = MARK_OFF;
7247   saRoot->IOMap[tag].IORequest = agNULL;
7248   saRoot->IOMap[tag].agContext = agNULL;
7249 
7250   ossaHwCB(agRoot, NULL, OSSA_HW_EVENT_ENCRYPTION, 0, (void *) &agEvent,agContext );
7251 
7252   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7253   SA_ASSERT((pRequest->valid), "pRequest->valid");
7254   pRequest->valid = agFALSE;
7255   /* return the request to free pool */
7256   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
7257   {
7258     SA_DBG1(("mpiDekManagementRsp: saving pRequest (%p) for later use\n", pRequest));
7259     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
7260   }
7261   else
7262   {
7263     /* return the request to free pool */
7264     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
7265   }
7266 
7267   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7268 
7269   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "2B");
7270 
7271   return AGSA_RC_SUCCESS;
7272 }
7273 
7274 /******************************************************************************/
7275 /*! \brief Operator Management Response
7276  *
7277  *  This routine handles the response of the Operator management message
7278  *
7279  *  \param agRoot       Handles for this instance of SAS/SATA LLL
7280  *  \param pIomb        Pointer of IOMB Mesage
7281  *
7282  *  \return sucess or fail
7283  *
7284  */
7285 /*******************************************************************************/
7286 GLOBAL bit32 mpiOperatorManagementRsp(
7287   agsaRoot_t                *agRoot,
7288   agsaOperatorMangmenRsp_t  *pIomb
7289   )
7290 {
7291   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
7292   agsaIORequestDesc_t *pRequest;
7293   agsaContext_t       *agContext;
7294   agsaHWEventEncrypt_t agEvent;
7295   bit32               OPRIDX_AUTIDX_R_OMO,status, errorQualifier, tag;
7296 
7297   smTraceFuncEnter(hpDBG_VERY_LOUD,"36");
7298 
7299   SA_DBG1(("mpiOperatorManagementRsp: HTag=0x%x\n", pIomb->tag));
7300 
7301   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaOperatorMangmenRsp_t, tag));
7302   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaOperatorMangmenRsp_t, status));
7303   OSSA_READ_LE_32(AGROOT, &OPRIDX_AUTIDX_R_OMO, pIomb, OSSA_OFFSET_OF(agsaOperatorMangmenRsp_t, OPRIDX_AUTIDX_R_OMO));
7304   OSSA_READ_LE_32(AGROOT, &errorQualifier, pIomb, OSSA_OFFSET_OF(agsaOperatorMangmenRsp_t, errorQualifier));
7305 
7306   SA_DBG2(("mpiOperatorManagementRsp:tag =0x%x\n",tag ));
7307   SA_DBG2(("mpiOperatorManagementRsp:status =0x%x\n", status));
7308   SA_DBG2(("mpiOperatorManagementRsp:OPRIDX_AUTIDX_R_OMO =0x%x\n",OPRIDX_AUTIDX_R_OMO ));
7309   SA_DBG2(("mpiOperatorManagementRsp:errorQualifier =0x%x\n", errorQualifier));
7310 
7311   /* get request from IOMap */
7312   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
7313   if (agNULL == pRequest)
7314   {
7315     SA_DBG1(("mpiOperatorManagementRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
7316     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "36");
7317     return AGSA_RC_FAILURE;
7318   }
7319 
7320   agContext = saRoot->IOMap[tag].agContext;
7321   /* remove the request from IOMap */
7322   saRoot->IOMap[tag].Tag = MARK_OFF;
7323   saRoot->IOMap[tag].IORequest = agNULL;
7324   saRoot->IOMap[tag].agContext = agNULL;
7325 
7326   si_memset(&agEvent, 0, sizeof(agsaHWEventEncrypt_t));
7327   agEvent.status = status;
7328   agEvent.info = OPRIDX_AUTIDX_R_OMO;
7329   agEvent.encryptOperation = OSSA_HW_ENCRYPT_OPERATOR_MANAGEMENT;
7330   if (status == OPR_MGMT_MPI_ENC_ERR_OPR_PARAM_ILLEGAL)
7331   {
7332     agEvent.eq = errorQualifier;
7333   }
7334 
7335   ossaOperatorManagementCB(agRoot, agContext, status, errorQualifier);
7336 
7337   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7338   SA_ASSERT((pRequest->valid), "pRequest->valid");
7339   pRequest->valid = agFALSE;
7340   /* return the request to free pool */
7341   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
7342   {
7343     SA_DBG1(("mpiOperatorManagementRsp: saving pRequest (%p) for later use\n", pRequest));
7344     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
7345   }
7346   else
7347   {
7348     /* return the request to free pool */
7349     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
7350   }
7351 
7352   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7353 
7354   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "36");
7355 
7356   return AGSA_RC_SUCCESS;
7357 }
7358 
7359 GLOBAL bit32 mpiBistRsp(
7360   agsaRoot_t               *agRoot,
7361   agsaEncryptBistRsp_t     *pIomb
7362   )
7363 {
7364   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
7365   agsaIORequestDesc_t *pRequest;
7366   agsaContext_t       *agContext;
7367   agsaHWEventEncrypt_t agEvent;
7368   bit32               status;
7369   bit32               results[11];
7370   bit32               length;
7371   bit32               subop;
7372   bit32               tag;
7373 
7374   smTraceFuncEnter(hpDBG_VERY_LOUD,"37");
7375 
7376   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaEncryptBistRsp_t, tag));
7377   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaEncryptBistRsp_t, status));
7378   OSSA_READ_LE_32(AGROOT, &subop, pIomb, OSSA_OFFSET_OF(agsaEncryptBistRsp_t, subop));
7379   OSSA_READ_LE_32(AGROOT, &results[0], pIomb, OSSA_OFFSET_OF(agsaEncryptBistRsp_t, testResults[0]));
7380   OSSA_READ_LE_32(AGROOT, &results[1], pIomb, OSSA_OFFSET_OF(agsaEncryptBistRsp_t, testResults[1]));
7381   OSSA_READ_LE_32(AGROOT, &results[2], pIomb, OSSA_OFFSET_OF(agsaEncryptBistRsp_t, testResults[2]));
7382   OSSA_READ_LE_32(AGROOT, &results[3], pIomb, OSSA_OFFSET_OF(agsaEncryptBistRsp_t, testResults[3]));
7383   OSSA_READ_LE_32(AGROOT, &results[4], pIomb, OSSA_OFFSET_OF(agsaEncryptBistRsp_t, testResults[4]));
7384   OSSA_READ_LE_32(AGROOT, &results[5], pIomb, OSSA_OFFSET_OF(agsaEncryptBistRsp_t, testResults[5]));
7385   OSSA_READ_LE_32(AGROOT, &results[6], pIomb, OSSA_OFFSET_OF(agsaEncryptBistRsp_t, testResults[6]));
7386   OSSA_READ_LE_32(AGROOT, &results[7], pIomb, OSSA_OFFSET_OF(agsaEncryptBistRsp_t, testResults[7]));
7387   OSSA_READ_LE_32(AGROOT, &results[8], pIomb, OSSA_OFFSET_OF(agsaEncryptBistRsp_t, testResults[8]));
7388   OSSA_READ_LE_32(AGROOT, &results[9], pIomb, OSSA_OFFSET_OF(agsaEncryptBistRsp_t, testResults[9]));
7389   OSSA_READ_LE_32(AGROOT, &results[10], pIomb, OSSA_OFFSET_OF(agsaEncryptBistRsp_t, testResults[10]));
7390 
7391   subop &= 0xFF;
7392   SA_DBG1(("mpiBistRsp: HTag=0x%x subops =0x%x status =0x%x\n",pIomb->tag, subop, status));
7393 
7394   switch(subop)
7395   {
7396     case AGSA_BIST_TEST:
7397       length =  sizeof(agsaEncryptSelfTestStatusBitMap_t);
7398       break;
7399     case AGSA_SHA_TEST:
7400       length = sizeof(agsaEncryptSHATestResult_t);
7401       break;
7402     case AGSA_HMAC_TEST:
7403       length = sizeof(agsaEncryptHMACTestResult_t);
7404       break;
7405     default:
7406       length = 0;
7407       break;
7408   }
7409 
7410   si_memset(&agEvent, 0, sizeof(agsaHWEventEncrypt_t));
7411   agEvent.status = status;
7412   agEvent.encryptOperation = OSSA_HW_ENCRYPT_TEST_EXECUTE;
7413   agEvent.info = length;
7414   agEvent.eq   = subop;
7415   agEvent.handle = agNULL;
7416   agEvent.param = &results;
7417 
7418   /* get request from IOMap */
7419   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
7420   if (agNULL == pRequest)
7421   {
7422     SA_DBG1(("mpiBistRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
7423     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "37");
7424     return AGSA_RC_FAILURE;
7425   }
7426 
7427   agContext = saRoot->IOMap[tag].agContext;
7428 
7429   ossaHwCB(agRoot, NULL, OSSA_HW_EVENT_ENCRYPTION, 0, (void*)&agEvent, agContext);
7430 
7431   /* remove the request from IOMap */
7432   saRoot->IOMap[tag].Tag = MARK_OFF;
7433   saRoot->IOMap[tag].IORequest = agNULL;
7434   saRoot->IOMap[tag].agContext = agNULL;
7435 
7436   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7437   SA_ASSERT((pRequest->valid), "pRequest->valid");
7438   pRequest->valid = agFALSE;
7439   /* return the request to free pool */
7440   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
7441   {
7442     SA_DBG1(("mpiBistRsp: saving pRequest (%p) for later use\n", pRequest));
7443     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
7444   }
7445   else
7446   {
7447     /* return the request to free pool */
7448     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
7449   }
7450 
7451   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7452 
7453   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "37");
7454 
7455   return AGSA_RC_SUCCESS;
7456 }
7457 
7458 /******************************************************************************/
7459 /*! \brief Set Operator Response
7460  *
7461  *  This routine handles the response of the Operator management message
7462  *
7463  *  \param agRoot       Handles for this instance of SAS/SATA LLL
7464  *  \param pIomb        Pointer of IOMB Mesage
7465  *
7466  *  \return sucess or fail
7467  *
7468  */
7469 /*******************************************************************************/
7470 GLOBAL bit32 mpiSetOperatorRsp(
7471   agsaRoot_t               *agRoot,
7472   agsaSetOperatorRsp_t     *pIomb
7473   )
7474 {
7475   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
7476   agsaIORequestDesc_t *pRequest = agNULL;
7477   agsaContext_t       *agContext = agNULL;
7478   bit32               ERR_QLFR_OPRIDX_PIN_ACS, OPRIDX_PIN_ACS, status, errorQualifier, tag = 0;
7479 
7480   smTraceFuncEnter(hpDBG_VERY_LOUD,"38");
7481 
7482   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaSetOperatorRsp_t, tag));
7483   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaSetOperatorRsp_t, status));
7484   OSSA_READ_LE_32(AGROOT, &ERR_QLFR_OPRIDX_PIN_ACS, pIomb, OSSA_OFFSET_OF(agsaSetOperatorRsp_t, ERR_QLFR_OPRIDX_PIN_ACS));
7485 
7486   errorQualifier = ERR_QLFR_OPRIDX_PIN_ACS >> 16;
7487   OPRIDX_PIN_ACS = ERR_QLFR_OPRIDX_PIN_ACS & 0xFFFF;
7488 
7489   SA_DBG1(("mpiSetOperatorRsp: HTag=0x%x ERR_QLFR=0x%x OPRIDX_PIN_ACS=0x%x \n",tag, errorQualifier, OPRIDX_PIN_ACS));
7490 
7491   /* get request from IOMap */
7492   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
7493   if (agNULL == pRequest)
7494   {
7495     SA_DBG1(("mpiSetOperatorRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
7496     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "38");
7497     return AGSA_RC_FAILURE;
7498   }
7499 
7500   agContext = saRoot->IOMap[tag].agContext;
7501   /* remove the request from IOMap */
7502   saRoot->IOMap[tag].Tag = MARK_OFF;
7503   saRoot->IOMap[tag].IORequest = agNULL;
7504   saRoot->IOMap[tag].agContext = agNULL;
7505 
7506 
7507   ossaSetOperatorCB(agRoot,agContext,status,errorQualifier );
7508 
7509   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7510   SA_ASSERT((pRequest->valid), "pRequest->valid");
7511   pRequest->valid = agFALSE;
7512   /* return the request to free pool */
7513   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
7514   {
7515     SA_DBG1(("mpiSetOperatorRsp: saving pRequest (%p) for later use\n", pRequest));
7516     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
7517   }
7518   else
7519   {
7520     /* return the request to free pool */
7521     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
7522   }
7523 
7524   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7525 
7526   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "38");
7527 
7528   return AGSA_RC_SUCCESS;
7529 }
7530 
7531 /******************************************************************************/
7532 /*! \brief Get Operator Response
7533  *
7534  *  This routine handles the response of the Operator management message
7535  *
7536  *  \param agRoot       Handles for this instance of SAS/SATA LLL
7537  *  \param pIomb        Pointer of IOMB Mesage
7538  *
7539  *  \return sucess or fail
7540  *
7541  */
7542 /*******************************************************************************/
7543 GLOBAL bit32 mpiGetOperatorRsp(
7544   agsaRoot_t               *agRoot,
7545   agsaGetOperatorRsp_t     *pIomb
7546   )
7547 {
7548   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
7549   agsaIORequestDesc_t *pRequest;
7550   agsaContext_t       *agContext;
7551   bit32                Num_Option, NumOperators ,status, tag;
7552   bit8                 option, Role = 0;
7553   bit32                IDstr[8];
7554   bit8                *tmpIDstr = agNULL;
7555   agsaID_t            *IDString = agNULL;
7556 
7557   smTraceFuncEnter(hpDBG_VERY_LOUD,"3f");
7558 
7559   si_memset(&IDstr, 0, sizeof(IDstr));
7560   OSSA_READ_LE_32(AGROOT, &tag,         pIomb, OSSA_OFFSET_OF(agsaGetOperatorRsp_t, tag));
7561   OSSA_READ_LE_32(AGROOT, &status,      pIomb, OSSA_OFFSET_OF(agsaGetOperatorRsp_t, status));
7562   OSSA_READ_LE_32(AGROOT, &Num_Option,  pIomb, OSSA_OFFSET_OF(agsaGetOperatorRsp_t, Num_Option));
7563   OSSA_READ_LE_32(AGROOT, &IDstr[0],    pIomb, OSSA_OFFSET_OF(agsaGetOperatorRsp_t, IDString[0]));
7564   OSSA_READ_LE_32(AGROOT, &IDstr[1],    pIomb, OSSA_OFFSET_OF(agsaGetOperatorRsp_t, IDString[1]));
7565   OSSA_READ_LE_32(AGROOT, &IDstr[2],    pIomb, OSSA_OFFSET_OF(agsaGetOperatorRsp_t, IDString[2]));
7566   OSSA_READ_LE_32(AGROOT, &IDstr[3],    pIomb, OSSA_OFFSET_OF(agsaGetOperatorRsp_t, IDString[3]));
7567   OSSA_READ_LE_32(AGROOT, &IDstr[4],    pIomb, OSSA_OFFSET_OF(agsaGetOperatorRsp_t, IDString[4]));
7568   OSSA_READ_LE_32(AGROOT, &IDstr[5],    pIomb, OSSA_OFFSET_OF(agsaGetOperatorRsp_t, IDString[5]));
7569   OSSA_READ_LE_32(AGROOT, &IDstr[6],    pIomb, OSSA_OFFSET_OF(agsaGetOperatorRsp_t, IDString[6]));
7570   OSSA_READ_LE_32(AGROOT, &IDstr[7],    pIomb, OSSA_OFFSET_OF(agsaGetOperatorRsp_t, IDString[7]));
7571 
7572   SA_DBG1(("mpiGetOperatorRsp:tag=0x%x status=0x%x Num_Option=0x%x IDString_Role=0x%x\n",
7573            tag, status, Num_Option, IDstr[0]));
7574 
7575   /* get request from IOMap */
7576   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
7577   if (agNULL == pRequest)
7578   {
7579     SA_DBG1(("mpiGetOperatorRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
7580     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3f");
7581     return AGSA_RC_FAILURE;
7582   }
7583 
7584   agContext = saRoot->IOMap[tag].agContext;
7585   /* remove the request from IOMap */
7586   saRoot->IOMap[tag].Tag = MARK_OFF;
7587   saRoot->IOMap[tag].IORequest = agNULL;
7588   saRoot->IOMap[tag].agContext = agNULL;
7589   option = Num_Option & 0xFF;
7590   NumOperators = (Num_Option >> SHIFT8) & 0xFF;
7591   /* current operator's Role/ID, valid only if option == 1 */
7592   if ( option == 1)
7593   {
7594     /* extra the role value as parameter */
7595     Role = IDstr[0] & 0xFF;
7596     tmpIDstr = (bit8*)&IDstr[0];
7597     tmpIDstr++; /* skip role byte */
7598     IDString = (agsaID_t *)tmpIDstr;
7599     SA_DBG1(("mpiGetOperatorRsp: OSSA_IO_SUCCESS\n"));
7600     SA_DBG2(("mpiGetOperatorRsp: 0x%02x 0x%02x 0x%02x 0x%02x\n",IDString->ID[0], IDString->ID[1], IDString->ID[2], IDString->ID[3]));
7601     SA_DBG2(("mpiGetOperatorRsp: 0x%02x 0x%02x 0x%02x 0x%02x\n",IDString->ID[4], IDString->ID[5], IDString->ID[6], IDString->ID[7]));
7602     SA_DBG2(("mpiGetOperatorRsp: 0x%02x 0x%02x 0x%02x 0x%02x\n",IDString->ID[8], IDString->ID[9], IDString->ID[10],IDString->ID[11]));
7603     SA_DBG2(("mpiGetOperatorRsp: 0x%02x 0x%02x 0x%02x 0x%02x\n",IDString->ID[12],IDString->ID[13],IDString->ID[14],IDString->ID[15]));
7604     SA_DBG2(("mpiGetOperatorRsp: 0x%02x 0x%02x 0x%02x 0x%02x\n",IDString->ID[16],IDString->ID[17],IDString->ID[18],IDString->ID[19]));
7605     SA_DBG2(("mpiGetOperatorRsp: 0x%02x 0x%02x 0x%02x 0x%02x\n",IDString->ID[20],IDString->ID[21],IDString->ID[22],IDString->ID[23]));
7606     SA_DBG2(("mpiGetOperatorRsp: 0x%02x 0x%02x 0x%02x 0x%02x\n",IDString->ID[24],IDString->ID[25],IDString->ID[26],IDString->ID[27]));
7607     SA_DBG2(("mpiGetOperatorRsp: 0x%02x 0x%02x 0x%02x\n",       IDString->ID[28],IDString->ID[29],IDString->ID[30]));
7608   }
7609 
7610   SA_DBG1(("mpiGetOperatorRsp:status 0x%x option 0x%x Role 0x%x\n",status,option,Role ));
7611 
7612   ossaGetOperatorCB(agRoot,agContext,status,option,NumOperators ,Role,IDString );
7613 
7614   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7615   SA_ASSERT((pRequest->valid), "pRequest->valid");
7616   pRequest->valid = agFALSE;
7617   /* return the request to free pool */
7618   if(saLlistIOGetCount(&(saRoot->freeReservedRequests)) < SA_RESERVED_REQUEST_COUNT)
7619   {
7620     SA_DBG1(("mpiGetOperatorRsp: saving pRequest (%p) for later use\n", pRequest));
7621     saLlistIOAdd(&(saRoot->freeReservedRequests), &(pRequest->linkNode));
7622   }
7623   else
7624   {
7625     /* return the request to free pool */
7626     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
7627   }
7628 
7629   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7630 
7631   smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3f");
7632 
7633   return AGSA_RC_SUCCESS;
7634 }
7635 
7636 
7637 GLOBAL bit32 mpiGetVHistRsp(
7638    agsaRoot_t         *agRoot,
7639    agsaGetVHistCapRsp_t *pIomb
7640   )
7641 {
7642 
7643   bit32               ret = AGSA_RC_SUCCESS;
7644   agsaLLRoot_t        *saRoot = agNULL;
7645   agsaIORequestDesc_t *pRequest;
7646   agsaContext_t       *agContext;
7647 
7648   bit32    tag = 0;           /* 1 */
7649   bit32    status = 0;        /* 2 */
7650   bit32    channel;          /* 3 */
7651   bit32    BistLo;           /* 4 */
7652   bit32    BistHi;           /* 5 */
7653   bit32    BytesXfered = 0;  /* 6 */
7654   bit32    PciLo;            /* 7 */
7655   bit32    PciHi;            /* 8 */
7656   bit32    PciBytecount = 0;  /* 9 */
7657 
7658   smTraceFuncEnter(hpDBG_VERY_LOUD,"3K");
7659 
7660   /* sanity check */
7661   SA_ASSERT((agNULL != agRoot), "");
7662   saRoot = (agsaLLRoot_t *) (agRoot->sdkData);
7663   SA_ASSERT((agNULL != saRoot), "");
7664 
7665   if(smIS_SPC12V(agRoot))
7666   {
7667     OSSA_READ_LE_32(AGROOT, &tag,          pIomb, OSSA_OFFSET_OF(agsaGetVHistCapRsp_t,tag));
7668     OSSA_READ_LE_32(AGROOT, &status,       pIomb, OSSA_OFFSET_OF(agsaGetVHistCapRsp_t,status));
7669     OSSA_READ_LE_32(AGROOT, &channel,      pIomb, OSSA_OFFSET_OF(agsaGetVHistCapRsp_t,channel));
7670     OSSA_READ_LE_32(AGROOT, &BistLo,       pIomb, OSSA_OFFSET_OF(agsaGetVHistCapRsp_t,BistLo));
7671     OSSA_READ_LE_32(AGROOT, &BistHi,       pIomb, OSSA_OFFSET_OF(agsaGetVHistCapRsp_t,BistHi));
7672     OSSA_READ_LE_32(AGROOT, &BytesXfered,  pIomb, OSSA_OFFSET_OF(agsaGetVHistCapRsp_t,BytesXfered));
7673     OSSA_READ_LE_32(AGROOT, &PciLo,        pIomb, OSSA_OFFSET_OF(agsaGetVHistCapRsp_t,PciLo));
7674     OSSA_READ_LE_32(AGROOT, &PciHi,        pIomb, OSSA_OFFSET_OF(agsaGetVHistCapRsp_t,PciHi));
7675     OSSA_READ_LE_32(AGROOT, &PciBytecount, pIomb, OSSA_OFFSET_OF(agsaGetVHistCapRsp_t,PciBytecount));
7676   }
7677   else
7678   {
7679     /* SPC does not support this command */
7680     SA_DBG1(("mpiGetVHistRsp: smIS_SPC12V only\n"));
7681     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3K");
7682     return AGSA_RC_FAILURE;
7683   }
7684 
7685   SA_DBG3(("mpiGetVHistRsp: HTag=0x%x\n", tag));
7686 
7687   /* get request from IOMap */
7688   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
7689   if (agNULL == pRequest)
7690   {
7691     SA_DBG1(("mpiGetVHistRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
7692     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3K");
7693     return AGSA_RC_FAILURE;
7694   }
7695 
7696   agContext = saRoot->IOMap[tag].agContext;
7697 
7698   /* remove the request from IOMap */
7699   saRoot->IOMap[tag].Tag = MARK_OFF;
7700   saRoot->IOMap[tag].IORequest = agNULL;
7701   saRoot->IOMap[tag].agContext = agNULL;
7702 
7703   SA_ASSERT((pRequest->valid), "pRequest->valid");
7704 
7705   /* check status success or failure */
7706   if (status)
7707   {
7708     SA_DBG1(("mpiGetVHistRsp: status is FAILED, status = %x\n", status ));
7709 
7710     if (pRequest->completionCB == agNULL)
7711     {
7712       ossaVhistCaptureCB(agRoot, agContext, status, BytesXfered);
7713     }
7714     else
7715     {
7716       (*(ossaVhistCaptureCB_t)(pRequest->completionCB))(agRoot, agContext, status, BytesXfered);
7717     }
7718 
7719     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7720     pRequest->valid = agFALSE;
7721     /* return the request to free pool */
7722     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
7723     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7724 
7725     smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "3K");
7726     return AGSA_RC_FAILURE;
7727   }
7728 
7729   /* status is SUCCESS */
7730   SA_DBG1(("mpiGetVHistRsp: status is SUCCESS\n" ));
7731 
7732   if (pRequest->completionCB == agNULL)
7733   {
7734     ossaVhistCaptureCB(agRoot, agContext, status, BytesXfered);
7735   }
7736   else
7737   {
7738     (*(ossaVhistCaptureCB_t)(pRequest->completionCB))(agRoot, agContext, status, BytesXfered);
7739   }
7740 
7741   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7742   pRequest->valid = agFALSE;
7743   /* return the request to free pool */
7744   saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
7745   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7746 
7747   /* return value */
7748   smTraceFuncExit(hpDBG_VERY_LOUD, 'd', "3K");
7749 
7750   return ret;
7751 }
7752 
7753 
7754 
7755 /******************************************************************************/
7756 /*! \brief DifEncOffload Response
7757  *
7758  *  This routine handles the response of the DifEncOffload Response
7759  *
7760  *  \param agRoot       Handles for this instance of SAS/SATA LLL
7761  *  \param pIomb        Pointer of IOMB Mesage
7762  *
7763  *  \return sucess or fail
7764  *
7765  */
7766 /*******************************************************************************/
7767 GLOBAL bit32 mpiDifEncOffloadRsp(
7768   agsaRoot_t               *agRoot,
7769   agsaDifEncOffloadRspV_t  *pIomb
7770   )
7771 {
7772 
7773   bit32               ret = AGSA_RC_SUCCESS;
7774   agsaLLRoot_t        *saRoot = (agsaLLRoot_t *)(agRoot->sdkData);
7775   agsaIORequestDesc_t *pRequest;
7776   agsaContext_t       *agContext;
7777   bit32               tag, status;
7778   agsaOffloadDifDetails_t details;
7779 
7780   smTraceFuncEnter(hpDBG_VERY_LOUD,"3F");
7781 
7782   OSSA_READ_LE_32(AGROOT, &tag, pIomb, OSSA_OFFSET_OF(agsaDifEncOffloadRspV_t, tag));
7783   OSSA_READ_LE_32(AGROOT, &status, pIomb, OSSA_OFFSET_OF(agsaDifEncOffloadRspV_t, status));
7784   /* get TAG */
7785   SA_DBG3(("mpiDifEncOffloadRsp: HTag=0x%x\n", tag));
7786 
7787   /* get request from IOMap */
7788   pRequest = (agsaIORequestDesc_t*)saRoot->IOMap[tag].IORequest;
7789   if (agNULL == pRequest)
7790   {
7791     SA_DBG1(("mpiDifEncOffloadRsp: Bad Response IOMB!!! pRequest is NULL. TAG=0x%x STATUS=0x%x\n", tag, status));
7792     smTraceFuncExit(hpDBG_VERY_LOUD, 'a', "3F");
7793     return AGSA_RC_FAILURE;
7794   }
7795 
7796   agContext = saRoot->IOMap[tag].agContext;
7797 
7798   /* remove the request from IOMap */
7799   saRoot->IOMap[tag].Tag = MARK_OFF;
7800   saRoot->IOMap[tag].IORequest = agNULL;
7801   saRoot->IOMap[tag].agContext = agNULL;
7802 
7803   SA_ASSERT((pRequest->valid), "pRequest->valid");
7804 
7805   /* check status success or failure */
7806   if (status)
7807   {
7808     SA_DBG1(("mpiDifEncOffloadRsp: status is FAILED, status = %x\n", status ));
7809 
7810     if (status == OSSA_IO_XFR_ERROR_DIF_MISMATCH || status == OSSA_IO_XFR_ERROR_DIF_APPLICATION_TAG_MISMATCH ||
7811         status == OSSA_IO_XFR_ERROR_DIF_REFERENCE_TAG_MISMATCH || status == OSSA_IO_XFR_ERROR_DIF_CRC_MISMATCH)
7812     {
7813       si_memset(&details, 0, sizeof(agsaOffloadDifDetails_t));
7814       OSSA_READ_LE_32(AGROOT, &details.ExpectedCRCUDT01, pIomb, OSSA_OFFSET_OF(agsaDifEncOffloadRspV_t, ExpectedCRCUDT01));
7815       OSSA_READ_LE_32(AGROOT, &details.ExpectedUDT2345, pIomb, OSSA_OFFSET_OF(agsaDifEncOffloadRspV_t, ExpectedUDT2345));
7816       OSSA_READ_LE_32(AGROOT, &details.ActualCRCUDT01, pIomb, OSSA_OFFSET_OF(agsaDifEncOffloadRspV_t, ActualCRCUDT01));
7817       OSSA_READ_LE_32(AGROOT, &details.ActualUDT2345, pIomb, OSSA_OFFSET_OF(agsaDifEncOffloadRspV_t, ActualUDT2345));
7818       OSSA_READ_LE_32(AGROOT, &details.DIFErr, pIomb, OSSA_OFFSET_OF(agsaDifEncOffloadRspV_t, DIFErr));
7819       OSSA_READ_LE_32(AGROOT, &details.ErrBoffset, pIomb, OSSA_OFFSET_OF(agsaDifEncOffloadRspV_t, ErrBoffset));
7820 
7821       if (pRequest->completionCB == agNULL)
7822       {
7823         ossaDIFEncryptionOffloadStartCB(agRoot, agContext, status, &details);
7824       }
7825       else
7826       {
7827         (*(ossaDIFEncryptionOffloadStartCB_t)(pRequest->completionCB))(agRoot, agContext, status, &details);
7828       }
7829     }
7830     else
7831     {
7832       if (pRequest->completionCB == agNULL)
7833       {
7834         ossaDIFEncryptionOffloadStartCB(agRoot, agContext, status, agNULL);
7835       }
7836       else
7837       {
7838         (*(ossaDIFEncryptionOffloadStartCB_t)(pRequest->completionCB))(agRoot, agContext, status, agNULL);
7839       }
7840     }
7841 
7842     smTraceFuncExit(hpDBG_VERY_LOUD, 'b', "3F");
7843 
7844     ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7845     pRequest->valid = agFALSE;
7846     /* return the request to free pool */
7847     saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
7848     ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7849 
7850     return AGSA_RC_FAILURE;
7851   }
7852 
7853   /* status is SUCCESS */
7854   SA_DBG1(("mpiDifEncOffloadRsp: status is SUCCESS\n" ));
7855 
7856   if (pRequest->completionCB == agNULL)
7857   {
7858     ossaDIFEncryptionOffloadStartCB(agRoot, agContext, status, agNULL);
7859   }
7860   else
7861   {
7862     (*(ossaDIFEncryptionOffloadStartCB_t)(pRequest->completionCB))(agRoot, agContext, status, agNULL);
7863   }
7864 
7865   ossaSingleThreadedEnter(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7866   pRequest->valid = agFALSE;
7867   /* return the request to free pool */
7868   saLlistIOAdd(&(saRoot->freeIORequests), &(pRequest->linkNode));
7869   ossaSingleThreadedLeave(agRoot, LL_IOREQ_LOCKEQ_LOCK);
7870 
7871   /* return value */
7872   smTraceFuncExit(hpDBG_VERY_LOUD, 'c', "3F");
7873 
7874   return ret;
7875 }
7876 
7877