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