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