xref: /freebsd/sys/dev/pms/RefTisa/sat/src/sminit.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
1*4e1bc9a0SAchim Leubner /*******************************************************************************
2*4e1bc9a0SAchim Leubner *Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3*4e1bc9a0SAchim Leubner *
4*4e1bc9a0SAchim Leubner *Redistribution and use in source and binary forms, with or without modification, are permitted provided
5*4e1bc9a0SAchim Leubner *that the following conditions are met:
6*4e1bc9a0SAchim Leubner *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7*4e1bc9a0SAchim Leubner *following disclaimer.
8*4e1bc9a0SAchim Leubner *2. Redistributions in binary form must reproduce the above copyright notice,
9*4e1bc9a0SAchim Leubner *this list of conditions and the following disclaimer in the documentation and/or other materials provided
10*4e1bc9a0SAchim Leubner *with the distribution.
11*4e1bc9a0SAchim Leubner *
12*4e1bc9a0SAchim Leubner *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13*4e1bc9a0SAchim Leubner *WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14*4e1bc9a0SAchim Leubner *FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15*4e1bc9a0SAchim Leubner *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16*4e1bc9a0SAchim Leubner *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17*4e1bc9a0SAchim Leubner *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18*4e1bc9a0SAchim Leubner *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19*4e1bc9a0SAchim Leubner *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20*4e1bc9a0SAchim Leubner 
21*4e1bc9a0SAchim Leubner ********************************************************************************/
22*4e1bc9a0SAchim Leubner #include <sys/cdefs.h>
23*4e1bc9a0SAchim Leubner #include <dev/pms/config.h>
24*4e1bc9a0SAchim Leubner 
25*4e1bc9a0SAchim Leubner #include <dev/pms/freebsd/driver/common/osenv.h>
26*4e1bc9a0SAchim Leubner #include <dev/pms/freebsd/driver/common/ostypes.h>
27*4e1bc9a0SAchim Leubner #include <dev/pms/freebsd/driver/common/osdebug.h>
28*4e1bc9a0SAchim Leubner 
29*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/tisa/api/titypes.h>
30*4e1bc9a0SAchim Leubner 
31*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/sallsdk/api/sa.h>
32*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/sallsdk/api/saapi.h>
33*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
34*4e1bc9a0SAchim Leubner 
35*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/sat/api/sm.h>
36*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/sat/api/smapi.h>
37*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/sat/api/tdsmapi.h>
38*4e1bc9a0SAchim Leubner 
39*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/sat/src/smdefs.h>
40*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/sat/src/smproto.h>
41*4e1bc9a0SAchim Leubner #include <dev/pms/RefTisa/sat/src/smtypes.h>
42*4e1bc9a0SAchim Leubner 
43*4e1bc9a0SAchim Leubner #ifdef SM_DEBUG
44*4e1bc9a0SAchim Leubner bit32 gSMDebugLevel = 1;
45*4e1bc9a0SAchim Leubner #endif
46*4e1bc9a0SAchim Leubner smRoot_t *gsmRoot = agNULL;
47*4e1bc9a0SAchim Leubner 
48*4e1bc9a0SAchim Leubner /* start smapi defined APIS */
49*4e1bc9a0SAchim Leubner osGLOBAL void
smGetRequirements(smRoot_t * smRoot,smSwConfig_t * swConfig,smMemoryRequirement_t * memoryRequirement,bit32 * usecsPerTick,bit32 * maxNumLocks)50*4e1bc9a0SAchim Leubner smGetRequirements(
51*4e1bc9a0SAchim Leubner                   smRoot_t 	  		*smRoot,
52*4e1bc9a0SAchim Leubner                   smSwConfig_t			*swConfig,
53*4e1bc9a0SAchim Leubner                   smMemoryRequirement_t		*memoryRequirement,
54*4e1bc9a0SAchim Leubner                   bit32                         *usecsPerTick,
55*4e1bc9a0SAchim Leubner                   bit32				*maxNumLocks
56*4e1bc9a0SAchim Leubner                  )
57*4e1bc9a0SAchim Leubner {
58*4e1bc9a0SAchim Leubner   bit32               memoryReqCount = 0;
59*4e1bc9a0SAchim Leubner   bit32               i;
60*4e1bc9a0SAchim Leubner   bit32               max_dev = SM_MAX_DEV;
61*4e1bc9a0SAchim Leubner   char                *buffer;
62*4e1bc9a0SAchim Leubner   bit32               buffLen;
63*4e1bc9a0SAchim Leubner   bit32               lenRecv = 0;
64*4e1bc9a0SAchim Leubner   static char         tmpBuffer[DEFAULT_KEY_BUFFER_SIZE];
65*4e1bc9a0SAchim Leubner   char                *pLastUsedChar = agNULL;
66*4e1bc9a0SAchim Leubner   char                globalStr[]     = "Global";
67*4e1bc9a0SAchim Leubner   char                iniParmsStr[]   = "InitiatorParms";
68*4e1bc9a0SAchim Leubner   SM_DBG2(("smGetRequirements: start\n"));
69*4e1bc9a0SAchim Leubner 
70*4e1bc9a0SAchim Leubner   /* sanity check */
71*4e1bc9a0SAchim Leubner   SM_ASSERT((agNULL != swConfig), "");
72*4e1bc9a0SAchim Leubner   SM_ASSERT((agNULL != memoryRequirement), "");
73*4e1bc9a0SAchim Leubner   SM_ASSERT((agNULL != usecsPerTick), "");
74*4e1bc9a0SAchim Leubner   SM_ASSERT((agNULL != maxNumLocks), "");
75*4e1bc9a0SAchim Leubner 
76*4e1bc9a0SAchim Leubner   /* memory requirement for smRoot, CACHE memory */
77*4e1bc9a0SAchim Leubner   memoryRequirement->smMemory[SM_ROOT_MEM_INDEX].singleElementLength = sizeof(smIntRoot_t);
78*4e1bc9a0SAchim Leubner   memoryRequirement->smMemory[SM_ROOT_MEM_INDEX].numElements = 1;
79*4e1bc9a0SAchim Leubner   memoryRequirement->smMemory[SM_ROOT_MEM_INDEX].totalLength =
80*4e1bc9a0SAchim Leubner       (memoryRequirement->smMemory[SM_ROOT_MEM_INDEX].singleElementLength) * (memoryRequirement->smMemory[SM_ROOT_MEM_INDEX].numElements);
81*4e1bc9a0SAchim Leubner   memoryRequirement->smMemory[SM_ROOT_MEM_INDEX].alignment = 4;
82*4e1bc9a0SAchim Leubner   memoryRequirement->smMemory[SM_ROOT_MEM_INDEX].type = SM_CACHED_MEM;
83*4e1bc9a0SAchim Leubner   memoryReqCount++;
84*4e1bc9a0SAchim Leubner 
85*4e1bc9a0SAchim Leubner   /* reading the configurable parameter of MaxTargets */
86*4e1bc9a0SAchim Leubner   buffer = tmpBuffer;
87*4e1bc9a0SAchim Leubner   buffLen = sizeof(tmpBuffer);
88*4e1bc9a0SAchim Leubner   sm_memset(buffer, 0, buffLen);
89*4e1bc9a0SAchim Leubner   lenRecv = 0;
90*4e1bc9a0SAchim Leubner   if ((tdsmGetTransportParam(
91*4e1bc9a0SAchim Leubner                              smRoot,
92*4e1bc9a0SAchim Leubner                              globalStr,
93*4e1bc9a0SAchim Leubner                              iniParmsStr,
94*4e1bc9a0SAchim Leubner                              agNULL,
95*4e1bc9a0SAchim Leubner                              agNULL,
96*4e1bc9a0SAchim Leubner                              agNULL,
97*4e1bc9a0SAchim Leubner                              agNULL,
98*4e1bc9a0SAchim Leubner                              "MaxTargets",
99*4e1bc9a0SAchim Leubner                              buffer,
100*4e1bc9a0SAchim Leubner                              buffLen,
101*4e1bc9a0SAchim Leubner                              &lenRecv
102*4e1bc9a0SAchim Leubner                              ) == SM_RC_SUCCESS) && (lenRecv != 0))
103*4e1bc9a0SAchim Leubner   {
104*4e1bc9a0SAchim Leubner     if (osti_strncmp(buffer, "0x", 2) == 0)
105*4e1bc9a0SAchim Leubner     {
106*4e1bc9a0SAchim Leubner       max_dev = osti_strtoul (buffer, &pLastUsedChar, 0);
107*4e1bc9a0SAchim Leubner     }
108*4e1bc9a0SAchim Leubner     else
109*4e1bc9a0SAchim Leubner     {
110*4e1bc9a0SAchim Leubner       max_dev = osti_strtoul (buffer, &pLastUsedChar, 10);
111*4e1bc9a0SAchim Leubner     }
112*4e1bc9a0SAchim Leubner   }
113*4e1bc9a0SAchim Leubner   SM_DBG3(("smGetRequirements: max_expander %d\n", max_dev));
114*4e1bc9a0SAchim Leubner   /* memory requirement for Device Links, CACHE memory */
115*4e1bc9a0SAchim Leubner   memoryRequirement->smMemory[SM_DEVICE_MEM_INDEX].singleElementLength = sizeof(smDeviceData_t);
116*4e1bc9a0SAchim Leubner   memoryRequirement->smMemory[SM_DEVICE_MEM_INDEX].numElements = max_dev;
117*4e1bc9a0SAchim Leubner   memoryRequirement->smMemory[SM_DEVICE_MEM_INDEX].totalLength =
118*4e1bc9a0SAchim Leubner       (memoryRequirement->smMemory[SM_DEVICE_MEM_INDEX].singleElementLength) * (memoryRequirement->smMemory[SM_DEVICE_MEM_INDEX].numElements);
119*4e1bc9a0SAchim Leubner   memoryRequirement->smMemory[SM_DEVICE_MEM_INDEX].alignment = 4;
120*4e1bc9a0SAchim Leubner   memoryRequirement->smMemory[SM_DEVICE_MEM_INDEX].type = SM_CACHED_MEM;
121*4e1bc9a0SAchim Leubner   memoryReqCount++;
122*4e1bc9a0SAchim Leubner 
123*4e1bc9a0SAchim Leubner   /* memory requirement for IO inks, CACHE memory */
124*4e1bc9a0SAchim Leubner   memoryRequirement->smMemory[SM_IO_MEM_INDEX].singleElementLength = sizeof(smIORequestBody_t);
125*4e1bc9a0SAchim Leubner   memoryRequirement->smMemory[SM_IO_MEM_INDEX].numElements = SM_MAX_IO;
126*4e1bc9a0SAchim Leubner   memoryRequirement->smMemory[SM_IO_MEM_INDEX].totalLength =
127*4e1bc9a0SAchim Leubner       (memoryRequirement->smMemory[SM_IO_MEM_INDEX].singleElementLength) * (memoryRequirement->smMemory[SM_IO_MEM_INDEX].numElements);
128*4e1bc9a0SAchim Leubner   memoryRequirement->smMemory[SM_IO_MEM_INDEX].alignment = 4;
129*4e1bc9a0SAchim Leubner   memoryRequirement->smMemory[SM_IO_MEM_INDEX].type = SM_CACHED_MEM;
130*4e1bc9a0SAchim Leubner   memoryReqCount++;
131*4e1bc9a0SAchim Leubner 
132*4e1bc9a0SAchim Leubner   /* for debugging */
133*4e1bc9a0SAchim Leubner   for (i=0;i< memoryReqCount;i++)
134*4e1bc9a0SAchim Leubner   {
135*4e1bc9a0SAchim Leubner     SM_DBG3(("smGetRequirements: index %d numElements %d totalLength %d singleElementLength %d alignment %d\n", i
136*4e1bc9a0SAchim Leubner     , memoryRequirement->smMemory[i].numElements, memoryRequirement->smMemory[i].totalLength,
137*4e1bc9a0SAchim Leubner     memoryRequirement->smMemory[i].singleElementLength,memoryRequirement->smMemory[i].alignment ));
138*4e1bc9a0SAchim Leubner   }
139*4e1bc9a0SAchim Leubner   /* set up memory requirement count */
140*4e1bc9a0SAchim Leubner   memoryRequirement->count = memoryReqCount;
141*4e1bc9a0SAchim Leubner 
142*4e1bc9a0SAchim Leubner   /* requirement for locks */
143*4e1bc9a0SAchim Leubner   *maxNumLocks = SM_MAX_LOCKS;
144*4e1bc9a0SAchim Leubner 
145*4e1bc9a0SAchim Leubner   /* setup the time tick */
146*4e1bc9a0SAchim Leubner   *usecsPerTick = SM_USECS_PER_TICK;
147*4e1bc9a0SAchim Leubner 
148*4e1bc9a0SAchim Leubner   /* set up the number of active IOs */
149*4e1bc9a0SAchim Leubner   swConfig->maxActiveIOs = SM_MAX_IO;
150*4e1bc9a0SAchim Leubner 
151*4e1bc9a0SAchim Leubner   /* set up the number of device handles */
152*4e1bc9a0SAchim Leubner   swConfig->numDevHandles = SM_MAX_DEV;
153*4e1bc9a0SAchim Leubner 
154*4e1bc9a0SAchim Leubner 
155*4e1bc9a0SAchim Leubner   return;
156*4e1bc9a0SAchim Leubner }
157*4e1bc9a0SAchim Leubner 
158*4e1bc9a0SAchim Leubner osGLOBAL bit32
smInitialize(smRoot_t * smRoot,agsaRoot_t * agRoot,smMemoryRequirement_t * memoryAllocated,smSwConfig_t * swConfig,bit32 usecsPerTick)159*4e1bc9a0SAchim Leubner smInitialize(
160*4e1bc9a0SAchim Leubner              smRoot_t				*smRoot,
161*4e1bc9a0SAchim Leubner              agsaRoot_t                         *agRoot,
162*4e1bc9a0SAchim Leubner              smMemoryRequirement_t		*memoryAllocated,
163*4e1bc9a0SAchim Leubner              smSwConfig_t			*swConfig,
164*4e1bc9a0SAchim Leubner              bit32				usecsPerTick
165*4e1bc9a0SAchim Leubner             )
166*4e1bc9a0SAchim Leubner {
167*4e1bc9a0SAchim Leubner   smIntRoot_t               *smIntRoot;
168*4e1bc9a0SAchim Leubner   smDeviceData_t            *smDevice;
169*4e1bc9a0SAchim Leubner   smIORequestBody_t         *smIORequest;
170*4e1bc9a0SAchim Leubner   smIntContext_t            *smAllShared;
171*4e1bc9a0SAchim Leubner   bit32                     i;
172*4e1bc9a0SAchim Leubner   bit32                     max_dev = SM_MAX_DEV;
173*4e1bc9a0SAchim Leubner   char                      *buffer;
174*4e1bc9a0SAchim Leubner   bit32                     buffLen;
175*4e1bc9a0SAchim Leubner   bit32                     lenRecv = 0;
176*4e1bc9a0SAchim Leubner   static char               tmpBuffer[DEFAULT_KEY_BUFFER_SIZE];
177*4e1bc9a0SAchim Leubner   char                      *pLastUsedChar = agNULL;
178*4e1bc9a0SAchim Leubner   char                      globalStr[]     = "Global";
179*4e1bc9a0SAchim Leubner   char                      iniParmsStr[]   = "InitiatorParms";
180*4e1bc9a0SAchim Leubner 
181*4e1bc9a0SAchim Leubner   SM_DBG2(("smInitialize: start\n"));
182*4e1bc9a0SAchim Leubner 
183*4e1bc9a0SAchim Leubner   /* sanity check */
184*4e1bc9a0SAchim Leubner   SM_ASSERT((agNULL != smRoot), "");
185*4e1bc9a0SAchim Leubner   SM_ASSERT((agNULL != agRoot), "");
186*4e1bc9a0SAchim Leubner   SM_ASSERT((agNULL != memoryAllocated), "");
187*4e1bc9a0SAchim Leubner   SM_ASSERT((agNULL != swConfig), "");
188*4e1bc9a0SAchim Leubner   SM_ASSERT((SM_ROOT_MEM_INDEX < memoryAllocated->count), "");
189*4e1bc9a0SAchim Leubner   SM_ASSERT((SM_DEVICE_MEM_INDEX < memoryAllocated->count), "");
190*4e1bc9a0SAchim Leubner   SM_ASSERT((SM_IO_MEM_INDEX < memoryAllocated->count), "");
191*4e1bc9a0SAchim Leubner 
192*4e1bc9a0SAchim Leubner   /* Check the memory allocated */
193*4e1bc9a0SAchim Leubner   for ( i = 0; i < memoryAllocated->count; i ++ )
194*4e1bc9a0SAchim Leubner   {
195*4e1bc9a0SAchim Leubner     /* If memory allocatation failed  */
196*4e1bc9a0SAchim Leubner     if (memoryAllocated->smMemory[i].singleElementLength &&
197*4e1bc9a0SAchim Leubner         memoryAllocated->smMemory[i].numElements)
198*4e1bc9a0SAchim Leubner     {
199*4e1bc9a0SAchim Leubner       if ( (0 != memoryAllocated->smMemory[i].numElements)
200*4e1bc9a0SAchim Leubner           && (0 == memoryAllocated->smMemory[i].totalLength) )
201*4e1bc9a0SAchim Leubner       {
202*4e1bc9a0SAchim Leubner         /* return failure */
203*4e1bc9a0SAchim Leubner         SM_DBG1(("smInitialize: Memory[%d]  singleElementLength = 0x%x  numElements = 0x%x NOT allocated!!!\n",
204*4e1bc9a0SAchim Leubner           i,
205*4e1bc9a0SAchim Leubner           memoryAllocated->smMemory[i].singleElementLength,
206*4e1bc9a0SAchim Leubner           memoryAllocated->smMemory[i].numElements));
207*4e1bc9a0SAchim Leubner         return SM_RC_FAILURE;
208*4e1bc9a0SAchim Leubner       }
209*4e1bc9a0SAchim Leubner     }
210*4e1bc9a0SAchim Leubner   }
211*4e1bc9a0SAchim Leubner 
212*4e1bc9a0SAchim Leubner   /* for debugging */
213*4e1bc9a0SAchim Leubner   for ( i = 0; i < memoryAllocated->count; i ++ )
214*4e1bc9a0SAchim Leubner   {
215*4e1bc9a0SAchim Leubner     SM_DBG3(("smInitialize: index %d virtPtr %p osHandle%p\n",i, memoryAllocated->smMemory[i].virtPtr, memoryAllocated->smMemory[i].osHandle));
216*4e1bc9a0SAchim Leubner     SM_DBG3(("smInitialize: index %d phyAddrUpper 0x%x phyAddrLower 0x%x totalLength %d numElements %d\n", i,
217*4e1bc9a0SAchim Leubner     memoryAllocated->smMemory[i].physAddrUpper,
218*4e1bc9a0SAchim Leubner     memoryAllocated->smMemory[i].physAddrLower,
219*4e1bc9a0SAchim Leubner     memoryAllocated->smMemory[i].totalLength,
220*4e1bc9a0SAchim Leubner     memoryAllocated->smMemory[i].numElements));
221*4e1bc9a0SAchim Leubner     SM_DBG3(("smInitialize: index %d singleElementLength 0x%x alignment 0x%x type %d reserved %d\n", i,
222*4e1bc9a0SAchim Leubner     memoryAllocated->smMemory[i].singleElementLength,
223*4e1bc9a0SAchim Leubner     memoryAllocated->smMemory[i].alignment,
224*4e1bc9a0SAchim Leubner     memoryAllocated->smMemory[i].type,
225*4e1bc9a0SAchim Leubner     memoryAllocated->smMemory[i].reserved));
226*4e1bc9a0SAchim Leubner   }
227*4e1bc9a0SAchim Leubner 
228*4e1bc9a0SAchim Leubner   /* SM's internal root */
229*4e1bc9a0SAchim Leubner   smIntRoot  = (smIntRoot_t *) (memoryAllocated->smMemory[SM_ROOT_MEM_INDEX].virtPtr);
230*4e1bc9a0SAchim Leubner   smRoot->smData = (void *) smIntRoot;
231*4e1bc9a0SAchim Leubner 
232*4e1bc9a0SAchim Leubner   smAllShared = (smIntContext_t *)&(smIntRoot->smAllShared);
233*4e1bc9a0SAchim Leubner   /**<  Initialize the TDM data part of the interrupt context */
234*4e1bc9a0SAchim Leubner   smAllShared->smRootOsData.smRoot     = smRoot;
235*4e1bc9a0SAchim Leubner   smAllShared->smRootOsData.smAllShared   = (void *) smAllShared;
236*4e1bc9a0SAchim Leubner   gsmRoot = smRoot;
237*4e1bc9a0SAchim Leubner   smAllShared->FCA = agTRUE;
238*4e1bc9a0SAchim Leubner 
239*4e1bc9a0SAchim Leubner   /* Devices */
240*4e1bc9a0SAchim Leubner   smDevice = (smDeviceData_t *) (memoryAllocated->smMemory[SM_DEVICE_MEM_INDEX].virtPtr);
241*4e1bc9a0SAchim Leubner   smAllShared->DeviceMem = (smDeviceData_t *)smDevice;
242*4e1bc9a0SAchim Leubner 
243*4e1bc9a0SAchim Leubner   /* IOs */
244*4e1bc9a0SAchim Leubner   smIORequest = (smIORequestBody_t *) (memoryAllocated->smMemory[SM_IO_MEM_INDEX].virtPtr);
245*4e1bc9a0SAchim Leubner   smAllShared->IOMem = (smIORequestBody_t *)smIORequest;
246*4e1bc9a0SAchim Leubner 
247*4e1bc9a0SAchim Leubner   smAllShared->agRoot = agRoot;
248*4e1bc9a0SAchim Leubner 
249*4e1bc9a0SAchim Leubner   smAllShared->usecsPerTick = usecsPerTick;
250*4e1bc9a0SAchim Leubner 
251*4e1bc9a0SAchim Leubner   /**< initializes timers */
252*4e1bc9a0SAchim Leubner   smInitTimers(smRoot);
253*4e1bc9a0SAchim Leubner 
254*4e1bc9a0SAchim Leubner   /**< initializes devices */
255*4e1bc9a0SAchim Leubner   buffer = tmpBuffer;
256*4e1bc9a0SAchim Leubner   buffLen = sizeof(tmpBuffer);
257*4e1bc9a0SAchim Leubner   sm_memset(buffer, 0, buffLen);
258*4e1bc9a0SAchim Leubner   lenRecv = 0;
259*4e1bc9a0SAchim Leubner   if ((tdsmGetTransportParam(
260*4e1bc9a0SAchim Leubner                              smRoot,
261*4e1bc9a0SAchim Leubner                              globalStr,
262*4e1bc9a0SAchim Leubner                              iniParmsStr,
263*4e1bc9a0SAchim Leubner                              agNULL,
264*4e1bc9a0SAchim Leubner                              agNULL,
265*4e1bc9a0SAchim Leubner                              agNULL,
266*4e1bc9a0SAchim Leubner                              agNULL,
267*4e1bc9a0SAchim Leubner                              "MaxTargets",
268*4e1bc9a0SAchim Leubner                              buffer,
269*4e1bc9a0SAchim Leubner                              buffLen,
270*4e1bc9a0SAchim Leubner                              &lenRecv
271*4e1bc9a0SAchim Leubner                              ) == SM_RC_SUCCESS) && (lenRecv != 0))
272*4e1bc9a0SAchim Leubner   {
273*4e1bc9a0SAchim Leubner     if (osti_strncmp(buffer, "0x", 2) == 0)
274*4e1bc9a0SAchim Leubner     {
275*4e1bc9a0SAchim Leubner       max_dev = osti_strtoul (buffer, &pLastUsedChar, 0);
276*4e1bc9a0SAchim Leubner     }
277*4e1bc9a0SAchim Leubner     else
278*4e1bc9a0SAchim Leubner     {
279*4e1bc9a0SAchim Leubner       max_dev = osti_strtoul (buffer, &pLastUsedChar, 10);
280*4e1bc9a0SAchim Leubner     }
281*4e1bc9a0SAchim Leubner    SM_DBG1(("smInitialize: MaxTargets %d\n", max_dev));
282*4e1bc9a0SAchim Leubner  }
283*4e1bc9a0SAchim Leubner 
284*4e1bc9a0SAchim Leubner   smDeviceDataInit(smRoot, max_dev);
285*4e1bc9a0SAchim Leubner 
286*4e1bc9a0SAchim Leubner   /**< initializes IOs */
287*4e1bc9a0SAchim Leubner   smIOInit(smRoot);
288*4e1bc9a0SAchim Leubner 
289*4e1bc9a0SAchim Leubner #ifdef SM_DEBUG
290*4e1bc9a0SAchim Leubner   gSMDebugLevel = swConfig->SMDebugLevel;
291*4e1bc9a0SAchim Leubner #endif
292*4e1bc9a0SAchim Leubner 
293*4e1bc9a0SAchim Leubner   return SM_RC_SUCCESS;
294*4e1bc9a0SAchim Leubner }
295*4e1bc9a0SAchim Leubner 
296*4e1bc9a0SAchim Leubner osGLOBAL void
smInitTimers(smRoot_t * smRoot)297*4e1bc9a0SAchim Leubner smInitTimers(
298*4e1bc9a0SAchim Leubner              smRoot_t *smRoot
299*4e1bc9a0SAchim Leubner             )
300*4e1bc9a0SAchim Leubner {
301*4e1bc9a0SAchim Leubner   smIntRoot_t               *smIntRoot    = (smIntRoot_t *)smRoot->smData;
302*4e1bc9a0SAchim Leubner   smIntContext_t            *smAllShared = (smIntContext_t *)&smIntRoot->smAllShared;
303*4e1bc9a0SAchim Leubner 
304*4e1bc9a0SAchim Leubner   SM_DBG2(("smInitTimers: start\n"));
305*4e1bc9a0SAchim Leubner 
306*4e1bc9a0SAchim Leubner   /* initialize the timerlist */
307*4e1bc9a0SAchim Leubner   SMLIST_INIT_HDR(&(smAllShared->timerlist));
308*4e1bc9a0SAchim Leubner 
309*4e1bc9a0SAchim Leubner   return;
310*4e1bc9a0SAchim Leubner }
311*4e1bc9a0SAchim Leubner 
312*4e1bc9a0SAchim Leubner osGLOBAL void
smDeviceDataReInit(smRoot_t * smRoot,smDeviceData_t * oneDeviceData)313*4e1bc9a0SAchim Leubner smDeviceDataReInit(
314*4e1bc9a0SAchim Leubner                    smRoot_t		  *smRoot,
315*4e1bc9a0SAchim Leubner                    smDeviceData_t         *oneDeviceData
316*4e1bc9a0SAchim Leubner                   )
317*4e1bc9a0SAchim Leubner {
318*4e1bc9a0SAchim Leubner   int               j=0;
319*4e1bc9a0SAchim Leubner   smSatInternalIo_t   *satIntIO;
320*4e1bc9a0SAchim Leubner 
321*4e1bc9a0SAchim Leubner   SM_DBG2(("smDeviceDataReInit: start \n"));
322*4e1bc9a0SAchim Leubner 
323*4e1bc9a0SAchim Leubner   if (oneDeviceData->satPendingIO != 0)
324*4e1bc9a0SAchim Leubner   {
325*4e1bc9a0SAchim Leubner     SM_DBG1(("smDeviceDataReInit: did %d\n", oneDeviceData->id));
326*4e1bc9a0SAchim Leubner     SM_DBG1(("smDeviceDataReInit: satPendingIO %d satNCQMaxIO %d!!!\n", oneDeviceData->satPendingIO, oneDeviceData->satNCQMaxIO ));
327*4e1bc9a0SAchim Leubner     SM_DBG1(("smDeviceDataReInit: satPendingNCQIO %d satPendingNONNCQIO %d!!!\n", oneDeviceData->satPendingNCQIO, oneDeviceData->satPendingNONNCQIO));
328*4e1bc9a0SAchim Leubner   }
329*4e1bc9a0SAchim Leubner 
330*4e1bc9a0SAchim Leubner //  oneDeviceData->smRoot = agNULL;
331*4e1bc9a0SAchim Leubner   oneDeviceData->agDevHandle = agNULL;
332*4e1bc9a0SAchim Leubner   oneDeviceData->valid = agFALSE;
333*4e1bc9a0SAchim Leubner   oneDeviceData->SMAbortAll = agFALSE;
334*4e1bc9a0SAchim Leubner   oneDeviceData->smDevHandle = agNULL;
335*4e1bc9a0SAchim Leubner   oneDeviceData->directlyAttached = agFALSE;
336*4e1bc9a0SAchim Leubner   oneDeviceData->agExpDevHandle = agNULL;
337*4e1bc9a0SAchim Leubner   oneDeviceData->phyID = 0xFF;
338*4e1bc9a0SAchim Leubner   oneDeviceData->SMNumOfFCA = 0;
339*4e1bc9a0SAchim Leubner 
340*4e1bc9a0SAchim Leubner   /* default */
341*4e1bc9a0SAchim Leubner   oneDeviceData->satDriveState = SAT_DEV_STATE_NORMAL;
342*4e1bc9a0SAchim Leubner   oneDeviceData->satNCQMaxIO =SAT_NCQ_MAX;
343*4e1bc9a0SAchim Leubner   oneDeviceData->satPendingIO = 0;
344*4e1bc9a0SAchim Leubner   oneDeviceData->satPendingNCQIO = 0;
345*4e1bc9a0SAchim Leubner   oneDeviceData->satPendingNONNCQIO = 0;
346*4e1bc9a0SAchim Leubner   oneDeviceData->IDDeviceValid = agFALSE;
347*4e1bc9a0SAchim Leubner   oneDeviceData->freeSATAFDMATagBitmap = 0;
348*4e1bc9a0SAchim Leubner   oneDeviceData->NumOfFCA = 0;
349*4e1bc9a0SAchim Leubner   oneDeviceData->NumOfIDRetries = 0;
350*4e1bc9a0SAchim Leubner   oneDeviceData->ID_Retries = 0;
351*4e1bc9a0SAchim Leubner   oneDeviceData->OSAbortAll = agFALSE;
352*4e1bc9a0SAchim Leubner 
353*4e1bc9a0SAchim Leubner   sm_memset(oneDeviceData->satMaxLBA, 0, sizeof(oneDeviceData->satMaxLBA));
354*4e1bc9a0SAchim Leubner   sm_memset(&(oneDeviceData->satIdentifyData), 0xFF, sizeof(agsaSATAIdentifyData_t));
355*4e1bc9a0SAchim Leubner 
356*4e1bc9a0SAchim Leubner   oneDeviceData->satSaDeviceData = oneDeviceData;
357*4e1bc9a0SAchim Leubner 
358*4e1bc9a0SAchim Leubner   satIntIO = (smSatInternalIo_t *)&(oneDeviceData->satIntIo[0]);
359*4e1bc9a0SAchim Leubner   for (j = 0; j < SAT_MAX_INT_IO; j++)
360*4e1bc9a0SAchim Leubner   {
361*4e1bc9a0SAchim Leubner     SM_DBG2(("tdsaDeviceDataReInit: in loop of internal io free, id %d\n", satIntIO->id));
362*4e1bc9a0SAchim Leubner     smsatFreeIntIoResource(smRoot, oneDeviceData, satIntIO);
363*4e1bc9a0SAchim Leubner     satIntIO = satIntIO + 1;
364*4e1bc9a0SAchim Leubner   }
365*4e1bc9a0SAchim Leubner 
366*4e1bc9a0SAchim Leubner   return;
367*4e1bc9a0SAchim Leubner }
368*4e1bc9a0SAchim Leubner osGLOBAL void
smDeviceDataInit(smRoot_t * smRoot,bit32 max_dev)369*4e1bc9a0SAchim Leubner smDeviceDataInit(
370*4e1bc9a0SAchim Leubner                  smRoot_t *smRoot,
371*4e1bc9a0SAchim Leubner                  bit32    max_dev
372*4e1bc9a0SAchim Leubner                 )
373*4e1bc9a0SAchim Leubner {
374*4e1bc9a0SAchim Leubner   smIntRoot_t               *smIntRoot    = (smIntRoot_t *)smRoot->smData;
375*4e1bc9a0SAchim Leubner   smIntContext_t            *smAllShared = (smIntContext_t *)&smIntRoot->smAllShared;
376*4e1bc9a0SAchim Leubner   smDeviceData_t            *smDeviceData = (smDeviceData_t *)smAllShared->DeviceMem;
377*4e1bc9a0SAchim Leubner   int                       i,j;
378*4e1bc9a0SAchim Leubner   smSatInternalIo_t           *satIntIO;
379*4e1bc9a0SAchim Leubner 
380*4e1bc9a0SAchim Leubner   SM_DBG2(("smDeviceDataInit: start \n"));
381*4e1bc9a0SAchim Leubner 
382*4e1bc9a0SAchim Leubner   SMLIST_INIT_HDR(&(smAllShared->MainDeviceList));
383*4e1bc9a0SAchim Leubner   SMLIST_INIT_HDR(&(smAllShared->FreeDeviceList));
384*4e1bc9a0SAchim Leubner 
385*4e1bc9a0SAchim Leubner   for(i=0;i<(int)max_dev;i++)
386*4e1bc9a0SAchim Leubner   {
387*4e1bc9a0SAchim Leubner     SMLIST_INIT_ELEMENT(&(smDeviceData[i].FreeLink));
388*4e1bc9a0SAchim Leubner     SMLIST_INIT_ELEMENT(&(smDeviceData[i].MainLink));
389*4e1bc9a0SAchim Leubner     smDeviceData[i].id = i;
390*4e1bc9a0SAchim Leubner     smDeviceData[i].smRoot = agNULL;
391*4e1bc9a0SAchim Leubner     smDeviceData[i].agDevHandle = agNULL;
392*4e1bc9a0SAchim Leubner     smDeviceData[i].valid = agFALSE;
393*4e1bc9a0SAchim Leubner     smDeviceData[i].SMAbortAll = agFALSE;
394*4e1bc9a0SAchim Leubner     smDeviceData[i].smDevHandle = agNULL;
395*4e1bc9a0SAchim Leubner     smDeviceData[i].directlyAttached = agFALSE;
396*4e1bc9a0SAchim Leubner     smDeviceData[i].agExpDevHandle = agNULL;
397*4e1bc9a0SAchim Leubner     smDeviceData[i].phyID = 0xFF;
398*4e1bc9a0SAchim Leubner     smDeviceData[i].SMNumOfFCA = 0;
399*4e1bc9a0SAchim Leubner 
400*4e1bc9a0SAchim Leubner 
401*4e1bc9a0SAchim Leubner     SMLIST_INIT_HDR(&(smDeviceData[i].satIoLinkList));
402*4e1bc9a0SAchim Leubner     SMLIST_INIT_HDR(&(smDeviceData[i].satFreeIntIoLinkList));
403*4e1bc9a0SAchim Leubner     SMLIST_INIT_HDR(&(smDeviceData[i].satActiveIntIoLinkList));
404*4e1bc9a0SAchim Leubner 
405*4e1bc9a0SAchim Leubner     /* default */
406*4e1bc9a0SAchim Leubner     smDeviceData[i].satDriveState = SAT_DEV_STATE_NORMAL;
407*4e1bc9a0SAchim Leubner     smDeviceData[i].satNCQMaxIO =SAT_NCQ_MAX;
408*4e1bc9a0SAchim Leubner     smDeviceData[i].satPendingIO = 0;
409*4e1bc9a0SAchim Leubner     smDeviceData[i].satPendingNCQIO = 0;
410*4e1bc9a0SAchim Leubner     smDeviceData[i].satPendingNONNCQIO = 0;
411*4e1bc9a0SAchim Leubner     smDeviceData[i].IDDeviceValid = agFALSE;
412*4e1bc9a0SAchim Leubner     smDeviceData[i].freeSATAFDMATagBitmap = 0;
413*4e1bc9a0SAchim Leubner     smDeviceData[i].NumOfFCA = 0;
414*4e1bc9a0SAchim Leubner     smDeviceData[i].NumOfIDRetries = 0;
415*4e1bc9a0SAchim Leubner     smDeviceData[i].ID_Retries = 0;
416*4e1bc9a0SAchim Leubner     smDeviceData[i].OSAbortAll = agFALSE;
417*4e1bc9a0SAchim Leubner     smInitTimerRequest(smRoot, &(smDeviceData[i].SATAIDDeviceTimer));
418*4e1bc9a0SAchim Leubner 
419*4e1bc9a0SAchim Leubner     sm_memset(&(smDeviceData[i].satIdentifyData), 0xFF, sizeof(agsaSATAIdentifyData_t));
420*4e1bc9a0SAchim Leubner     sm_memset(smDeviceData[i].satMaxLBA, 0, sizeof(smDeviceData[i].satMaxLBA));
421*4e1bc9a0SAchim Leubner 
422*4e1bc9a0SAchim Leubner     smDeviceData[i].satSaDeviceData = &smDeviceData[i];
423*4e1bc9a0SAchim Leubner 
424*4e1bc9a0SAchim Leubner #if 1
425*4e1bc9a0SAchim Leubner     satIntIO = &smDeviceData[i].satIntIo[0];
426*4e1bc9a0SAchim Leubner     for (j = 0; j < SAT_MAX_INT_IO; j++)
427*4e1bc9a0SAchim Leubner     {
428*4e1bc9a0SAchim Leubner       SMLIST_INIT_ELEMENT (&satIntIO->satIntIoLink);
429*4e1bc9a0SAchim Leubner       SMLIST_ENQUEUE_AT_TAIL (&satIntIO->satIntIoLink,
430*4e1bc9a0SAchim Leubner                               &smDeviceData[i].satFreeIntIoLinkList);
431*4e1bc9a0SAchim Leubner       satIntIO->satOrgSmIORequest = agNULL;
432*4e1bc9a0SAchim Leubner       satIntIO->id = j;
433*4e1bc9a0SAchim Leubner       satIntIO = satIntIO + 1;
434*4e1bc9a0SAchim Leubner     }
435*4e1bc9a0SAchim Leubner #endif
436*4e1bc9a0SAchim Leubner 
437*4e1bc9a0SAchim Leubner     /* some other variables */
438*4e1bc9a0SAchim Leubner     SMLIST_ENQUEUE_AT_TAIL(&(smDeviceData[i].FreeLink), &(smAllShared->FreeDeviceList));
439*4e1bc9a0SAchim Leubner   }
440*4e1bc9a0SAchim Leubner 
441*4e1bc9a0SAchim Leubner   return;
442*4e1bc9a0SAchim Leubner }
443*4e1bc9a0SAchim Leubner 
444*4e1bc9a0SAchim Leubner osGLOBAL void
smIOInit(smRoot_t * smRoot)445*4e1bc9a0SAchim Leubner smIOInit(
446*4e1bc9a0SAchim Leubner          smRoot_t *smRoot
447*4e1bc9a0SAchim Leubner         )
448*4e1bc9a0SAchim Leubner {
449*4e1bc9a0SAchim Leubner   smIntRoot_t               *smIntRoot    = (smIntRoot_t *)smRoot->smData;
450*4e1bc9a0SAchim Leubner   smIntContext_t            *smAllShared = (smIntContext_t *)&smIntRoot->smAllShared;
451*4e1bc9a0SAchim Leubner   smIORequestBody_t         *smIOCommand = (smIORequestBody_t *)smAllShared->IOMem;
452*4e1bc9a0SAchim Leubner   int                       i = 0;
453*4e1bc9a0SAchim Leubner 
454*4e1bc9a0SAchim Leubner   SM_DBG3(("smIOInit: start\n"));
455*4e1bc9a0SAchim Leubner 
456*4e1bc9a0SAchim Leubner   SMLIST_INIT_HDR(&(smAllShared->freeIOList));
457*4e1bc9a0SAchim Leubner   SMLIST_INIT_HDR(&(smAllShared->mainIOList));
458*4e1bc9a0SAchim Leubner 
459*4e1bc9a0SAchim Leubner   for(i=0;i<SM_MAX_IO;i++)
460*4e1bc9a0SAchim Leubner   {
461*4e1bc9a0SAchim Leubner     SMLIST_INIT_ELEMENT(&(smIOCommand[i].satIoBodyLink));
462*4e1bc9a0SAchim Leubner     smIOCommand[i].id = i;
463*4e1bc9a0SAchim Leubner     smIOCommand[i].InUse = agFALSE;
464*4e1bc9a0SAchim Leubner     smIOCommand[i].ioStarted = agFALSE;
465*4e1bc9a0SAchim Leubner     smIOCommand[i].ioCompleted = agFALSE;
466*4e1bc9a0SAchim Leubner     smIOCommand[i].reTries = 0;
467*4e1bc9a0SAchim Leubner 
468*4e1bc9a0SAchim Leubner     smIOCommand[i].smDevHandle = agNULL;
469*4e1bc9a0SAchim Leubner     smIOCommand[i].smIORequest = agNULL;
470*4e1bc9a0SAchim Leubner     smIOCommand[i].smIOToBeAbortedRequest = agNULL;
471*4e1bc9a0SAchim Leubner     smIOCommand[i].transport.SATA.satIOContext.satOrgIOContext = agNULL;
472*4e1bc9a0SAchim Leubner 
473*4e1bc9a0SAchim Leubner     sm_memset(&(smIOCommand[i].transport.SATA.agSATARequestBody), 0, sizeof(agsaSATAInitiatorRequest_t));
474*4e1bc9a0SAchim Leubner 
475*4e1bc9a0SAchim Leubner 
476*4e1bc9a0SAchim Leubner     SMLIST_ENQUEUE_AT_TAIL(&(smIOCommand[i].satIoBodyLink), &(smAllShared->freeIOList));
477*4e1bc9a0SAchim Leubner   }
478*4e1bc9a0SAchim Leubner 
479*4e1bc9a0SAchim Leubner   return;
480*4e1bc9a0SAchim Leubner }
481*4e1bc9a0SAchim Leubner 
482*4e1bc9a0SAchim Leubner FORCEINLINE void
smIOReInit(smRoot_t * smRoot,smIORequestBody_t * smIORequestBody)483*4e1bc9a0SAchim Leubner smIOReInit(
484*4e1bc9a0SAchim Leubner           smRoot_t          *smRoot,
485*4e1bc9a0SAchim Leubner           smIORequestBody_t *smIORequestBody
486*4e1bc9a0SAchim Leubner           )
487*4e1bc9a0SAchim Leubner {
488*4e1bc9a0SAchim Leubner   SM_DBG3(("smIOReInit: start\n"));
489*4e1bc9a0SAchim Leubner   smIORequestBody->InUse = agTRUE;
490*4e1bc9a0SAchim Leubner   smIORequestBody->ioStarted = agFALSE;
491*4e1bc9a0SAchim Leubner   smIORequestBody->ioCompleted = agFALSE;
492*4e1bc9a0SAchim Leubner   smIORequestBody->reTries = 0;
493*4e1bc9a0SAchim Leubner   smIORequestBody->smDevHandle = agNULL;
494*4e1bc9a0SAchim Leubner   smIORequestBody->smIORequest = agNULL;
495*4e1bc9a0SAchim Leubner   smIORequestBody->smIOToBeAbortedRequest = agNULL;
496*4e1bc9a0SAchim Leubner   smIORequestBody->transport.SATA.satIOContext.satOrgIOContext = agNULL;
497*4e1bc9a0SAchim Leubner   /*sm_memset(&(smIORequestBody->transport.SATA.agSATARequestBody), 0, sizeof(agsaSATAInitiatorRequest_t));*/
498*4e1bc9a0SAchim Leubner   return;
499*4e1bc9a0SAchim Leubner }
500*4e1bc9a0SAchim Leubner 
501*4e1bc9a0SAchim Leubner /* end smapi defined APIS */
502*4e1bc9a0SAchim Leubner 
503