1 /*******************************************************************************
2 **
3 *Copyright (c) 2014 PMC-Sierra, Inc. All rights reserved.
4 *
5 *Redistribution and use in source and binary forms, with or without modification, are permitted provided
6 *that the following conditions are met:
7 *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8 *following disclaimer.
9 *2. Redistributions in binary form must reproduce the above copyright notice,
10 *this list of conditions and the following disclaimer in the documentation and/or other materials provided
11 *with the distribution.
12 *
13 *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
14 *WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15 *FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
18 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
19 *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
20 *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
21
22 ********************************************************************************/
23 #include <sys/cdefs.h>
24 #include <dev/pms/config.h>
25
26 #include <dev/pms/freebsd/driver/common/osenv.h>
27 #include <dev/pms/freebsd/driver/common/ostypes.h>
28 #include <dev/pms/freebsd/driver/common/osdebug.h>
29
30 #include <dev/pms/RefTisa/sallsdk/api/sa.h>
31 #include <dev/pms/RefTisa/sallsdk/api/saapi.h>
32 #include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
33
34 #ifdef FDS_DM
35 #include <dev/pms/RefTisa/discovery/api/dm.h>
36 #include <dev/pms/RefTisa/discovery/api/dmapi.h>
37 #include <dev/pms/RefTisa/discovery/api/tddmapi.h>
38
39 #include <dev/pms/RefTisa/discovery/dm/dmdefs.h>
40 #include <dev/pms/RefTisa/discovery/dm/dmtypes.h>
41 #include <dev/pms/RefTisa/discovery/dm/dmproto.h>
42
43 #ifdef DM_DEBUG
44 bit32 gDMDebugLevel = 1;
45 #endif
46
47 osGLOBAL void
dmGetRequirements(dmRoot_t * dmRoot,dmSwConfig_t * swConfig,dmMemoryRequirement_t * memoryRequirement,bit32 * usecsPerTick,bit32 * maxNumLocks)48 dmGetRequirements(
49 dmRoot_t *dmRoot,
50 dmSwConfig_t *swConfig,
51 dmMemoryRequirement_t *memoryRequirement,
52 bit32 *usecsPerTick,
53 bit32 *maxNumLocks)
54 {
55 bit32 memoryReqCount = 0;
56 bit32 max_expander = DM_MAX_EXPANDER_DEV;
57 char *buffer;
58 bit32 buffLen;
59 bit32 lenRecv = 0;
60 static char tmpBuffer[DEFAULT_KEY_BUFFER_SIZE];
61 char *pLastUsedChar = agNULL;
62 char globalStr[] = "Global";
63 char iniParmsStr[] = "InitiatorParms";
64 char SwParmsStr[] = "SWParms";
65
66 DM_DBG3(("dmGetRequirements: start\n"));
67 /* sanity check */
68 DM_ASSERT((agNULL != swConfig), "");
69 DM_ASSERT((agNULL != memoryRequirement), "");
70 DM_ASSERT((agNULL != usecsPerTick), "");
71 DM_ASSERT((agNULL != maxNumLocks), "");
72
73 /* memory requirement for dmRoot, CACHE memory */
74 memoryRequirement->dmMemory[DM_ROOT_MEM_INDEX].singleElementLength = sizeof(dmIntRoot_t);
75 memoryRequirement->dmMemory[DM_ROOT_MEM_INDEX].numElements = 1;
76 memoryRequirement->dmMemory[DM_ROOT_MEM_INDEX].totalLength =
77 (memoryRequirement->dmMemory[DM_ROOT_MEM_INDEX].singleElementLength) * (memoryRequirement->dmMemory[DM_ROOT_MEM_INDEX].numElements);
78 memoryRequirement->dmMemory[DM_ROOT_MEM_INDEX].alignment = 4;
79 memoryRequirement->dmMemory[DM_ROOT_MEM_INDEX].type = DM_CACHED_MEM;
80 memoryReqCount++;
81
82 /* memory requirement for Port Context Links, CACHE memory */
83 memoryRequirement->dmMemory[DM_PORT_MEM_INDEX].singleElementLength = sizeof(dmIntPortContext_t);
84 memoryRequirement->dmMemory[DM_PORT_MEM_INDEX].numElements = DM_MAX_PORT_CONTEXT;
85 memoryRequirement->dmMemory[DM_PORT_MEM_INDEX].totalLength =
86 (memoryRequirement->dmMemory[DM_PORT_MEM_INDEX].singleElementLength) * (memoryRequirement->dmMemory[DM_PORT_MEM_INDEX].numElements);
87 memoryRequirement->dmMemory[DM_PORT_MEM_INDEX].alignment = 4;
88 memoryRequirement->dmMemory[DM_PORT_MEM_INDEX].type = DM_CACHED_MEM;
89 memoryReqCount++;
90
91 /* memory requirement for Device Links, CACHE memory */
92 memoryRequirement->dmMemory[DM_DEVICE_MEM_INDEX].singleElementLength = sizeof(dmDeviceData_t);
93 memoryRequirement->dmMemory[DM_DEVICE_MEM_INDEX].numElements = DM_MAX_DEV;
94 memoryRequirement->dmMemory[DM_DEVICE_MEM_INDEX].totalLength =
95 (memoryRequirement->dmMemory[DM_DEVICE_MEM_INDEX].singleElementLength) * (memoryRequirement->dmMemory[DM_DEVICE_MEM_INDEX].numElements);
96 memoryRequirement->dmMemory[DM_DEVICE_MEM_INDEX].alignment = 4;
97 memoryRequirement->dmMemory[DM_DEVICE_MEM_INDEX].type = DM_CACHED_MEM;
98 memoryReqCount++;
99
100 /* memory requirement for Expander Device Links, CACHE memory */
101 /*
102 Maximum number of expanders are configurable
103 The default is DM_MAX_EXPANDER_DEV
104 */
105 buffer = tmpBuffer;
106 buffLen = sizeof(tmpBuffer);
107
108 dm_memset(buffer, 0, buffLen);
109 lenRecv = 0;
110
111 if ((tddmGetTransportParam(
112 dmRoot,
113 globalStr,
114 iniParmsStr,
115 agNULL,
116 agNULL,
117 agNULL,
118 agNULL,
119 "MaxExpanders",
120 buffer,
121 buffLen,
122 &lenRecv
123 ) == DM_RC_SUCCESS) && (lenRecv != 0))
124 {
125 if (osti_strncmp(buffer, "0x", 2) == 0)
126 {
127 max_expander = osti_strtoul (buffer, &pLastUsedChar, 0);
128 }
129 else
130 {
131 max_expander = osti_strtoul (buffer, &pLastUsedChar, 10);
132 }
133 }
134 DM_DBG3(("dmGetRequirements: max_expander %d\n", max_expander));
135
136
137 memoryRequirement->dmMemory[DM_EXPANDER_MEM_INDEX].singleElementLength = sizeof(dmExpander_t);
138 memoryRequirement->dmMemory[DM_EXPANDER_MEM_INDEX].numElements = max_expander;
139 memoryRequirement->dmMemory[DM_EXPANDER_MEM_INDEX].totalLength =
140 (memoryRequirement->dmMemory[DM_EXPANDER_MEM_INDEX].singleElementLength) * (memoryRequirement->dmMemory[DM_EXPANDER_MEM_INDEX].numElements);
141 memoryRequirement->dmMemory[DM_EXPANDER_MEM_INDEX].alignment = 4;
142 memoryRequirement->dmMemory[DM_EXPANDER_MEM_INDEX].type = DM_CACHED_MEM;
143 memoryReqCount++;
144
145 /* memory requirement for SMP command Links, CACHE memory */
146 memoryRequirement->dmMemory[DM_SMP_MEM_INDEX].singleElementLength = sizeof(dmSMPRequestBody_t);
147 memoryRequirement->dmMemory[DM_SMP_MEM_INDEX].numElements = DM_MAX_SMP;
148 memoryRequirement->dmMemory[DM_SMP_MEM_INDEX].totalLength =
149 (memoryRequirement->dmMemory[DM_SMP_MEM_INDEX].singleElementLength) * (memoryRequirement->dmMemory[DM_SMP_MEM_INDEX].numElements);
150 memoryRequirement->dmMemory[DM_SMP_MEM_INDEX].alignment = 4;
151 memoryRequirement->dmMemory[DM_SMP_MEM_INDEX].type = DM_CACHED_MEM;
152 memoryReqCount++;
153
154 /* memory requirement for INDIRECT SMP command/response Links, DMA memory */
155 memoryRequirement->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].singleElementLength = SMP_INDIRECT_PAYLOAD; /* 512 */
156 memoryRequirement->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].numElements = DM_MAX_INDIRECT_SMP;
157 memoryRequirement->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].totalLength =
158 (memoryRequirement->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].singleElementLength) * (memoryRequirement->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].numElements);
159 memoryRequirement->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].alignment = 4;
160 memoryRequirement->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].type = DM_DMA_MEM;
161 memoryReqCount++;
162
163
164 /* set up memory requirement count */
165 memoryRequirement->count = memoryReqCount;
166
167 /* requirement for locks */
168 *maxNumLocks = DM_MAX_LOCKS;
169
170 /* setup the time tick */
171 *usecsPerTick = DM_USECS_PER_TICK;
172
173
174 /* set up the number of Expander device handles */
175 swConfig->numDevHandles = DM_MAX_DEV;
176 swConfig->itNexusTimeout = IT_NEXUS_TIMEOUT; /* default is 2000 ms*/
177
178 dm_memset(buffer, 0, buffLen);
179 lenRecv = 0;
180
181 if ((tddmGetTransportParam(
182 dmRoot,
183 globalStr,
184 SwParmsStr,
185 agNULL,
186 agNULL,
187 agNULL,
188 agNULL,
189 "IT_NEXUS_TIMEOUT",
190 buffer,
191 buffLen,
192 &lenRecv
193 ) == DM_RC_SUCCESS) && (lenRecv != 0))
194 {
195 if (osti_strncmp(buffer, "0x", 2) == 0)
196 {
197 swConfig->itNexusTimeout = osti_strtoul (buffer, &pLastUsedChar, 0);
198 }
199 else
200 {
201 swConfig->itNexusTimeout = osti_strtoul (buffer, &pLastUsedChar, 10);
202 }
203 }
204
205 DM_DBG1(("dmGetRequirements: swConfig->itNexusTimeout 0x%X\n", swConfig->itNexusTimeout));
206
207 DM_DBG3(("dmGetRequirements: memoryReqCount %d\n", memoryRequirement->count));
208
209 return;
210 }
211 /*
212 ??? processing swConfig
213 */
214 osGLOBAL bit32
dmInitialize(dmRoot_t * dmRoot,agsaRoot_t * agRoot,dmMemoryRequirement_t * memoryAllocated,dmSwConfig_t * swConfig,bit32 usecsPerTick)215 dmInitialize(
216 dmRoot_t *dmRoot,
217 agsaRoot_t *agRoot,
218 dmMemoryRequirement_t *memoryAllocated,
219 dmSwConfig_t *swConfig,
220 bit32 usecsPerTick )
221 {
222 dmIntRoot_t *dmIntRoot;
223 dmIntPortContext_t *dmIntPortContext;
224 dmDeviceData_t *dmDevice;
225 dmExpander_t *dmExpander;
226 dmSMPRequestBody_t *dmSMPRequest;
227 bit8 *dmIndirectSMPRequest;
228 dmIntContext_t *dmAllShared;
229 bit32 i;
230 bit32 max_expander = DM_MAX_EXPANDER_DEV;
231 char *buffer;
232 bit32 buffLen;
233 bit32 lenRecv = 0;
234 static char tmpBuffer[DEFAULT_KEY_BUFFER_SIZE];
235 char *pLastUsedChar = agNULL;
236 char globalStr[] = "Global";
237 char iniParmsStr[] = "InitiatorParms";
238 char SwParmsStr[] = "SWParms";
239
240 DM_DBG3(("dmInitialize: start\n"));
241 /* sanity check */
242 DM_ASSERT((agNULL != dmRoot), "");
243 DM_ASSERT((agNULL != agRoot), "");
244 DM_ASSERT((agNULL != memoryAllocated), "");
245 DM_ASSERT((agNULL != swConfig), "");
246 DM_ASSERT((DM_ROOT_MEM_INDEX < memoryAllocated->count), "");
247 DM_ASSERT((DM_PORT_MEM_INDEX < memoryAllocated->count), "");
248 DM_ASSERT((DM_DEVICE_MEM_INDEX < memoryAllocated->count), "");
249 DM_ASSERT((DM_EXPANDER_MEM_INDEX < memoryAllocated->count), "");
250 DM_ASSERT((DM_SMP_MEM_INDEX < memoryAllocated->count), "");
251 DM_ASSERT((DM_INDIRECT_SMP_MEM_INDEX < memoryAllocated->count), "");
252
253 /* Check the memory allocated */
254 for ( i = 0; i < memoryAllocated->count; i ++ )
255 {
256 /* If memory allocatation failed */
257 if (memoryAllocated->dmMemory[i].singleElementLength &&
258 memoryAllocated->dmMemory[i].numElements)
259 {
260 if ( (0 != memoryAllocated->dmMemory[i].numElements)
261 && (0 == memoryAllocated->dmMemory[i].totalLength) )
262 {
263 /* return failure */
264 DM_DBG1(("dmInitialize: Memory[%d] singleElementLength = 0x%0x numElements = 0x%x NOT allocated!!!\n",
265 i,
266 memoryAllocated->dmMemory[i].singleElementLength,
267 memoryAllocated->dmMemory[i].numElements));
268 return DM_RC_FAILURE;
269 }
270 }
271 }
272
273 /* DM's internal root */
274 dmIntRoot = (dmIntRoot_t *) (memoryAllocated->dmMemory[DM_ROOT_MEM_INDEX].virtPtr);
275 dmRoot->dmData = (void *) dmIntRoot;
276
277 dmAllShared = (dmIntContext_t *)&(dmIntRoot->dmAllShared);
278 /**< Initialize the TDM data part of the interrupt context */
279 dmAllShared->dmRootOsData.dmRoot = dmRoot;
280 dmAllShared->dmRootOsData.dmAllShared = (void *) dmAllShared;
281
282 /* Port Contexts */
283 dmIntPortContext = (dmIntPortContext_t *) (memoryAllocated->dmMemory[DM_PORT_MEM_INDEX].virtPtr);
284 dmAllShared->PortContextMem = (dmIntPortContext_t *)dmIntPortContext;
285
286 /* Devices */
287 dmDevice = (dmDeviceData_t *) (memoryAllocated->dmMemory[DM_DEVICE_MEM_INDEX].virtPtr);
288 dmAllShared->DeviceMem = (dmDeviceData_t *)dmDevice;
289
290 /* Expanders */
291 dmExpander = (dmExpander_t *) (memoryAllocated->dmMemory[DM_EXPANDER_MEM_INDEX].virtPtr);
292 dmAllShared->ExpanderMem = (dmExpander_t *)dmExpander;
293
294 /* SMP commands */
295 dmSMPRequest = (dmSMPRequestBody_t *) (memoryAllocated->dmMemory[DM_SMP_MEM_INDEX].virtPtr);
296 dmAllShared->SMPMem = (dmSMPRequestBody_t *)dmSMPRequest;
297
298 /* DMAable SMP request/reponse pointed by dmSMPRequestBody_t */
299 dmIndirectSMPRequest = (bit8 *) (memoryAllocated->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].virtPtr);
300 dmAllShared->IndirectSMPMem = (bit8 *)dmIndirectSMPRequest;
301 dmAllShared->IndirectSMPUpper32 = memoryAllocated->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].physAddrUpper;
302 dmAllShared->IndirectSMPLower32 = memoryAllocated->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].physAddrLower;
303
304 dmAllShared->agRoot = agRoot;
305
306
307 dmAllShared->usecsPerTick = usecsPerTick;
308 dmAllShared->itNexusTimeout = IT_NEXUS_TIMEOUT;/*swConfig->itNexusTimeout;*/
309 dmAllShared->MaxRetryDiscovery = DISCOVERY_RETRIES;
310 dmAllShared->RateAdjust = 0;
311 /**< initializes timers */
312 dmInitTimers(dmRoot);
313
314 /**< initializes port contexts */
315 dmPortContextInit(dmRoot);
316
317 /**< initializes devices */
318 dmDeviceDataInit(dmRoot);
319
320 /**< initializes expander devices */
321 buffer = tmpBuffer;
322 buffLen = sizeof(tmpBuffer);
323
324 dm_memset(buffer, 0, buffLen);
325 lenRecv = 0;
326
327 if ((tddmGetTransportParam(
328 dmRoot,
329 globalStr,
330 iniParmsStr,
331 agNULL,
332 agNULL,
333 agNULL,
334 agNULL,
335 "MaxExpanders",
336 buffer,
337 buffLen,
338 &lenRecv
339 ) == DM_RC_SUCCESS) && (lenRecv != 0))
340 {
341 if (osti_strncmp(buffer, "0x", 2) == 0)
342 {
343 max_expander = osti_strtoul (buffer, &pLastUsedChar, 0);
344 }
345 else
346 {
347 max_expander = osti_strtoul (buffer, &pLastUsedChar, 10);
348 }
349 }
350
351 dm_memset(buffer, 0, buffLen);
352 lenRecv = 0;
353
354 if ((tddmGetTransportParam(
355 dmRoot,
356 globalStr,
357 SwParmsStr,
358 agNULL,
359 agNULL,
360 agNULL,
361 agNULL,
362 "IT_NEXUS_TIMEOUT",
363 buffer,
364 buffLen,
365 &lenRecv
366 ) == DM_RC_SUCCESS) && (lenRecv != 0))
367 {
368 if (osti_strncmp(buffer, "0x", 2) == 0)
369 {
370 dmAllShared->itNexusTimeout = osti_strtoul (buffer, &pLastUsedChar, 0);
371 }
372 else
373 {
374 dmAllShared->itNexusTimeout = osti_strtoul (buffer, &pLastUsedChar, 10);
375 }
376 }
377
378 DM_DBG1(("dmAllShared->itNexusTimeout %d \n", dmAllShared->itNexusTimeout));
379
380 dm_memset(buffer, 0, buffLen);
381 lenRecv = 0;
382
383 if ((tddmGetTransportParam(
384 dmRoot,
385 globalStr,
386 SwParmsStr,
387 agNULL,
388 agNULL,
389 agNULL,
390 agNULL,
391 "MaxRetryDiscovery",
392 buffer,
393 buffLen,
394 &lenRecv
395 ) == DM_RC_SUCCESS) && (lenRecv != 0))
396 {
397 if (osti_strncmp(buffer, "0x", 2) == 0)
398 {
399 dmAllShared->MaxRetryDiscovery = osti_strtoul (buffer, &pLastUsedChar, 0);
400 }
401 else
402 {
403 dmAllShared->MaxRetryDiscovery = osti_strtoul (buffer, &pLastUsedChar, 10);
404 }
405 }
406
407 DM_DBG1(("dmAllShared->MaxRetryDiscovery %d \n", dmAllShared->MaxRetryDiscovery));
408
409 dm_memset(buffer, 0, buffLen);
410 lenRecv = 0;
411 if ((tddmGetTransportParam(
412 dmRoot,
413 globalStr,
414 SwParmsStr,
415 agNULL,
416 agNULL,
417 agNULL,
418 agNULL,
419 "RateAdjust",
420 buffer,
421 buffLen,
422 &lenRecv
423 ) == DM_RC_SUCCESS) && (lenRecv != 0))
424 {
425 if (osti_strncmp(buffer, "0x", 2) == 0)
426 {
427 dmAllShared->RateAdjust = osti_strtoul (buffer, &pLastUsedChar, 0);
428 }
429 else
430 {
431 dmAllShared->RateAdjust = osti_strtoul (buffer, &pLastUsedChar, 10);
432 }
433 }
434 DM_DBG1(("dmAllShared->RateAdjust %d \n", dmAllShared->RateAdjust));
435
436 dmExpanderDeviceDataInit(dmRoot, max_expander);
437
438 /**< initializes SMP commands */
439 dmSMPInit(dmRoot);
440
441 #ifdef DM_DEBUG
442 gDMDebugLevel = swConfig->DMDebugLevel;
443 #endif
444 return DM_RC_SUCCESS;
445 }
446
447 osGLOBAL void
dmSMPInit(dmRoot_t * dmRoot)448 dmSMPInit(
449 dmRoot_t *dmRoot
450 )
451 {
452 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
453 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
454 dmSMPRequestBody_t *dmSMPCommand = (dmSMPRequestBody_t *)dmAllShared->SMPMem;
455 bit8 *dmIndirectSMPReqRsp = (bit8 *)dmAllShared->IndirectSMPMem;
456 bit32 prev_PhysAddrLower;
457
458 int i = 0;
459 DM_DBG3(("dmSMPInit: start \n"));
460
461 DMLIST_INIT_HDR(&(dmAllShared->freeSMPList));
462
463 for(i=0;i<DM_MAX_SMP;i++)
464 {
465 DMLIST_INIT_ELEMENT(&(dmSMPCommand[i].Link));
466 /* initialize expander fields */
467 dmSMPCommand[i].dmRoot = agNULL;
468 dmSMPCommand[i].dmDevice = agNULL;
469 dmSMPCommand[i].dmPortContext = agNULL;
470 dmSMPCommand[i].retries = 0;
471 dmSMPCommand[i].id = i;
472 dm_memset( &(dmSMPCommand[i].smpPayload), 0, sizeof(dmSMPCommand[i].smpPayload));
473 /* indirect SMP related */
474 dmSMPCommand[i].IndirectSMPResponse = agNULL;
475 dmSMPCommand[i].IndirectSMP = ((bit8 *)dmIndirectSMPReqRsp) + (i*SMP_INDIRECT_PAYLOAD);
476 dmSMPCommand[i].IndirectSMPUpper32 = dmAllShared->IndirectSMPUpper32;
477 dmSMPCommand[i].IndirectSMPLower32 = dmAllShared->IndirectSMPLower32;
478
479 prev_PhysAddrLower = dmAllShared->IndirectSMPLower32;
480 dmAllShared->IndirectSMPLower32 = dmAllShared->IndirectSMPLower32 + SMP_INDIRECT_PAYLOAD;
481 if (dmAllShared->IndirectSMPLower32 <= prev_PhysAddrLower)
482 {
483 dmAllShared->IndirectSMPUpper32++;
484 }
485
486 DMLIST_ENQUEUE_AT_TAIL(&(dmSMPCommand[i].Link), &(dmAllShared->freeSMPList));
487 }
488 return;
489
490 }
491
492 osGLOBAL void
dmDeviceDataInit(dmRoot_t * dmRoot)493 dmDeviceDataInit(
494 dmRoot_t *dmRoot
495 )
496 {
497 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
498 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
499 dmDeviceData_t *dmDeviceData = (dmDeviceData_t *)dmAllShared->DeviceMem;
500 int i;
501
502 DM_DBG3(("dmDeviceDataInit: start \n"));
503
504 DMLIST_INIT_HDR(&(dmAllShared->MainDeviceList));
505 DMLIST_INIT_HDR(&(dmAllShared->FreeDeviceList));
506
507 for(i=0;i<DM_MAX_DEV;i++)
508 {
509 DMLIST_INIT_ELEMENT(&(dmDeviceData[i].FreeLink));
510 DMLIST_INIT_ELEMENT(&(dmDeviceData[i].MainLink));
511 DMLIST_INIT_ELEMENT(&(dmDeviceData[i].IncDisLink));
512 dmDeviceData[i].id = i;
513 dmDeviceData[i].DeviceType = DM_DEFAULT_DEVICE;
514 dmDeviceData[i].dmRoot = agNULL;
515 // dmDeviceData[i].agDevHandle = agNULL;
516
517 dmDeviceData[i].dmPortContext = agNULL;
518 dmDeviceData[i].dmExpander = agNULL;
519 dmDeviceData[i].ExpDevice = agNULL;
520 dmDeviceData[i].phyID = 0xFF;
521 dmDeviceData[i].SASAddressID.sasAddressHi = 0;
522 dmDeviceData[i].SASAddressID.sasAddressLo = 0;
523 dmDeviceData[i].valid = agFALSE;
524 dmDeviceData[i].valid2 = agFALSE;
525 dmDeviceData[i].processed = agFALSE;
526 dmDeviceData[i].initiator_ssp_stp_smp = 0;
527 dmDeviceData[i].target_ssp_stp_smp = 0;
528 dmDeviceData[i].numOfPhys = 0;
529 // dmDeviceData[i].registered = agFALSE;
530 dmDeviceData[i].directlyAttached = agFALSE;
531 dmDeviceData[i].SASSpecDeviceType = 0xFF;
532 dmDeviceData[i].IOStart = 0;
533 dmDeviceData[i].IOResponse = 0;
534 dmDeviceData[i].agDeviceResetContext.osData = agNULL;
535 dmDeviceData[i].agDeviceResetContext.sdkData = agNULL;
536 dmDeviceData[i].TRflag = agFALSE;
537 dmDeviceData[i].ResetCnt = 0;
538 dmDeviceData[i].registered = agFALSE;
539 dmDeviceData[i].reported = agFALSE;
540
541 dmDeviceData[i].MCN = 0;
542 dmDeviceData[i].MCNDone = agFALSE;
543 dmDeviceData[i].PrevMCN = 0;
544
545 dm_memset( &(dmDeviceData[i].dmDeviceInfo), 0, sizeof(dmDeviceInfo_t));
546 /* some other variables */
547 DMLIST_ENQUEUE_AT_TAIL(&(dmDeviceData[i].FreeLink), &(dmAllShared->FreeDeviceList));
548 }
549
550 return;
551 }
552 osGLOBAL void
dmDeviceDataReInit(dmRoot_t * dmRoot,dmDeviceData_t * oneDeviceData)553 dmDeviceDataReInit(
554 dmRoot_t *dmRoot,
555 dmDeviceData_t *oneDeviceData
556 )
557 {
558 DM_DBG3(("dmDeviceDataReInit: start \n"));
559
560 oneDeviceData->DeviceType = DM_DEFAULT_DEVICE;
561 // oneDeviceData->agDevHandle = agNULL;
562
563 oneDeviceData->dmPortContext = agNULL;
564 oneDeviceData->dmExpander = agNULL;
565 oneDeviceData->ExpDevice = agNULL;
566 oneDeviceData->phyID = 0xFF;
567 oneDeviceData->SASAddressID.sasAddressHi = 0;
568 oneDeviceData->SASAddressID.sasAddressLo = 0;
569 oneDeviceData->valid = agFALSE;
570 oneDeviceData->valid2 = agFALSE;
571 oneDeviceData->processed = agFALSE;
572 oneDeviceData->initiator_ssp_stp_smp = 0;
573 oneDeviceData->target_ssp_stp_smp = 0;
574 oneDeviceData->numOfPhys = 0;
575 // oneDeviceData->registered = agFALSE;
576 oneDeviceData->directlyAttached = agFALSE;
577 oneDeviceData->SASSpecDeviceType = 0xFF;
578 oneDeviceData->IOStart = 0;
579 oneDeviceData->IOResponse = 0;
580 oneDeviceData->agDeviceResetContext.osData = agNULL;
581 oneDeviceData->agDeviceResetContext.sdkData = agNULL;
582 oneDeviceData->TRflag = agFALSE;
583 oneDeviceData->ResetCnt = 0;
584 oneDeviceData->registered = agFALSE;
585 oneDeviceData->reported = agFALSE;
586
587 oneDeviceData->MCN = 0;
588 oneDeviceData->MCNDone = agFALSE;
589 oneDeviceData->PrevMCN = 0;
590
591 dm_memset( &(oneDeviceData->dmDeviceInfo), 0, sizeof(dmDeviceInfo_t));
592
593 return;
594 }
595
596
597 osGLOBAL void
dmExpanderDeviceDataInit(dmRoot_t * dmRoot,bit32 max_exp)598 dmExpanderDeviceDataInit(
599 dmRoot_t *dmRoot,
600 bit32 max_exp
601 )
602 {
603 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
604 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
605 dmExpander_t *dmExpData = (dmExpander_t *)dmAllShared->ExpanderMem;
606 bit32 i = 0;
607 DM_DBG3(("dmExpanderDeviceDataInit: start \n"));
608
609 DMLIST_INIT_HDR(&(dmAllShared->freeExpanderList));
610 DMLIST_INIT_HDR(&(dmAllShared->mainExpanderList));
611
612 for(i=0;i<max_exp;i++)
613 {
614 DMLIST_INIT_ELEMENT(&(dmExpData[i].linkNode));
615 DMLIST_INIT_ELEMENT(&(dmExpData[i].upNode));
616 /* initialize expander fields */
617 dmExpData[i].dmRoot = agNULL;
618 dmExpData[i].agDevHandle = agNULL;
619 dmExpData[i].dmDevice = agNULL;
620 dmExpData[i].dmUpStreamExpander = agNULL;
621 dmExpData[i].dmCurrentDownStreamExpander = agNULL;
622 dmExpData[i].hasUpStreamDevice = agFALSE;
623 dmExpData[i].numOfUpStreamPhys = 0;
624 dmExpData[i].currentUpStreamPhyIndex = 0;
625 dmExpData[i].numOfDownStreamPhys = 0;
626 dmExpData[i].currentDownStreamPhyIndex = 0;
627 dmExpData[i].discoveringPhyId = 0;
628 dmExpData[i].underDiscovering = agFALSE;
629 dmExpData[i].id = i;
630 DM_DBG3(("dmExpanderDeviceDataInit: exp id %d\n", i));
631
632 dmExpData[i].dmReturnginExpander = agNULL;
633 dmExpData[i].discoverSMPAllowed = agTRUE;
634 dm_memset( &(dmExpData[i].currentIndex), 0, sizeof(dmExpData[i].currentIndex));
635 dm_memset( &(dmExpData[i].upStreamPhys), 0, sizeof(dmExpData[i].upStreamPhys));
636 dm_memset( &(dmExpData[i].downStreamPhys), 0, sizeof(dmExpData[i].downStreamPhys));
637 dm_memset( &(dmExpData[i].routingAttribute), 0, sizeof(dmExpData[i].routingAttribute));
638 dmExpData[i].configSASAddrTableIndex = 0;
639 dm_memset( &(dmExpData[i].configSASAddressHiTable), 0, sizeof(dmExpData[i].configSASAddressHiTable));
640 dm_memset( &(dmExpData[i].configSASAddressLoTable), 0, sizeof(dmExpData[i].configSASAddressLoTable));
641 dmExpData[i].SAS2 = 0; /* default is SAS 1.1 spec */
642 dmExpData[i].TTTSupported = agFALSE; /* Table to Table is supported */
643 dmExpData[i].UndoDueToTTTSupported = agFALSE;
644
645
646 DMLIST_ENQUEUE_AT_TAIL(&(dmExpData[i].linkNode), &(dmAllShared->freeExpanderList));
647 }
648 return;
649 }
650
651 /* re-intialize an expander */
652 osGLOBAL void
dmExpanderDeviceDataReInit(dmRoot_t * dmRoot,dmExpander_t * oneExpander)653 dmExpanderDeviceDataReInit(
654 dmRoot_t *dmRoot,
655 dmExpander_t *oneExpander
656 )
657 {
658 DM_DBG3(("dmExpanderDeviceDataReInit: start \n"));
659 oneExpander->dmRoot = agNULL;
660 oneExpander->agDevHandle = agNULL;
661 oneExpander->dmDevice = agNULL;
662 oneExpander->dmUpStreamExpander = agNULL;
663 oneExpander->dmCurrentDownStreamExpander = agNULL;
664 oneExpander->hasUpStreamDevice = agFALSE;
665 oneExpander->numOfUpStreamPhys = 0;
666 oneExpander->currentUpStreamPhyIndex = 0;
667 oneExpander->numOfDownStreamPhys = 0;
668 oneExpander->currentDownStreamPhyIndex = 0;
669 oneExpander->discoveringPhyId = 0;
670 oneExpander->underDiscovering = agFALSE;
671 oneExpander->dmReturnginExpander = agNULL;
672 oneExpander->discoverSMPAllowed = agTRUE;
673 dm_memset( &(oneExpander->currentIndex), 0, sizeof(oneExpander->currentIndex));
674 dm_memset( &(oneExpander->upStreamPhys), 0, sizeof(oneExpander->upStreamPhys));
675 dm_memset( &(oneExpander->downStreamPhys), 0, sizeof(oneExpander->downStreamPhys));
676 dm_memset( &(oneExpander->routingAttribute), 0, sizeof(oneExpander->routingAttribute));
677 oneExpander->configSASAddrTableIndex = 0;
678 dm_memset( &(oneExpander->configSASAddressHiTable), 0, sizeof(oneExpander->configSASAddressHiTable));
679 dm_memset( &(oneExpander->configSASAddressLoTable), 0, sizeof(oneExpander->configSASAddressLoTable));
680 oneExpander->SAS2 = 0; /* default is SAS 1.1 spec */
681 oneExpander->TTTSupported = agFALSE; /* Table to Table is supported */
682 oneExpander->UndoDueToTTTSupported = agFALSE;
683
684 return;
685 }
686
687 osGLOBAL void
dmPortContextInit(dmRoot_t * dmRoot)688 dmPortContextInit(
689 dmRoot_t *dmRoot
690 )
691 {
692 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
693 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
694 dmIntPortContext_t *dmPortContext = (dmIntPortContext_t *)dmAllShared->PortContextMem;
695 int i = 0;
696 #ifdef TBD
697 int j = 0;
698 #endif
699
700 DM_DBG3(("dmPortContextInit: start \n"));
701
702 DMLIST_INIT_HDR(&(dmAllShared->MainPortContextList));
703 DMLIST_INIT_HDR(&(dmAllShared->FreePortContextList));
704 for(i=0;i<DM_MAX_PORT_CONTEXT;i++)
705 {
706 DMLIST_INIT_ELEMENT(&(dmPortContext[i].FreeLink));
707 DMLIST_INIT_ELEMENT(&(dmPortContext[i].MainLink));
708
709 DMLIST_INIT_HDR(&(dmPortContext[i].discovery.discoveringExpanderList));
710 DMLIST_INIT_HDR(&(dmPortContext[i].discovery.UpdiscoveringExpanderList));
711 dmPortContext[i].discovery.type = DM_DISCOVERY_OPTION_FULL_START;
712 dmInitTimerRequest(dmRoot, &(dmPortContext[i].discovery.discoveryTimer));
713 dmInitTimerRequest(dmRoot, &(dmPortContext[i].discovery.configureRouteTimer));
714 dmInitTimerRequest(dmRoot, &(dmPortContext[i].discovery.deviceRegistrationTimer));
715 dmInitTimerRequest(dmRoot, &(dmPortContext[i].discovery.SMPBusyTimer));
716 dmInitTimerRequest(dmRoot, &(dmPortContext[i].discovery.BCTimer));
717 dmInitTimerRequest(dmRoot, &(dmPortContext[i].discovery.DiscoverySMPTimer));
718 dmPortContext[i].discovery.retries = 0;
719 dmPortContext[i].discovery.configureRouteRetries = 0;
720 dmPortContext[i].discovery.deviceRetistrationRetries = 0;
721 dmPortContext[i].discovery.pendingSMP = 0;
722 dmPortContext[i].discovery.SeenBC = agFALSE;
723 dmPortContext[i].discovery.forcedOK = agFALSE;
724 dmPortContext[i].discovery.SMPRetries = 0;
725 dmPortContext[i].discovery.DeferredError = agFALSE;
726 dmPortContext[i].discovery.ConfiguresOthers = agFALSE;
727 dmPortContext[i].discovery.ResetTriggerred = agFALSE;
728
729 #ifdef INITIATOR_DRIVER
730 dmPortContext[i].DiscoveryState = DM_DSTATE_NOT_STARTED;
731 dmPortContext[i].DiscoveryAbortInProgress = agFALSE;
732 dmPortContext[i].directAttatchedSAS = agFALSE;
733 dmPortContext[i].DiscoveryRdyGiven = agFALSE;
734 dmPortContext[i].SeenLinkUp = agFALSE;
735
736 #endif
737 dmPortContext[i].id = i;
738 #ifdef TBD
739 dmPortContext[i].agPortContext = agNULL;
740 #endif
741 dmPortContext[i].LinkRate = 0;
742 dmPortContext[i].Count = 0;
743 dmPortContext[i].valid = agFALSE;
744 dmPortContext[i].RegFailed = agFALSE;
745
746 #ifdef TBD
747 for (j=0;j<DM_MAX_NUM_PHYS;j++)
748 {
749 dmPortContext[i].PhyIDList[j] = agFALSE;
750 }
751 #endif
752 dmPortContext[i].RegisteredDevNums = 0;
753 dmPortContext[i].eventPhyID = 0xFF;
754 dmPortContext[i].Transient = agFALSE;
755
756 /* add more variables later */
757 DMLIST_ENQUEUE_AT_TAIL(&(dmPortContext[i].FreeLink), &(dmAllShared->FreePortContextList));
758 }
759
760 #ifdef DM_INTERNAL_DEBUG /* for debugging only */
761 for(i=0;i<DM_MAX_PORT_CONTEXT;i++)
762 {
763 DM_DBG6(("dmPortContextInit: index %d &tdsaPortContext[] %p\n", i, &(dmPortContext[i])));
764 }
765 DM_DBG6(("dmPortContextInit: sizeof(tdsaPortContext_t) %d 0x%x\n", sizeof(dmIntPortContext_t), sizeof(dmIntPortContext_t)));
766 #endif
767
768 return;
769 }
770
771 osGLOBAL void
dmPortContextReInit(dmRoot_t * dmRoot,dmIntPortContext_t * onePortContext)772 dmPortContextReInit(
773 dmRoot_t *dmRoot,
774 dmIntPortContext_t *onePortContext
775 )
776 {
777 dmDiscovery_t *discovery;
778
779 DM_DBG3(("dmPortContextReInit: start \n"));
780
781 discovery = &(onePortContext->discovery);
782
783 onePortContext->discovery.type = DM_DISCOVERY_OPTION_FULL_START;
784 onePortContext->discovery.retries = 0;
785 onePortContext->discovery.configureRouteRetries = 0;
786 onePortContext->discovery.deviceRetistrationRetries = 0;
787 onePortContext->discovery.pendingSMP = 0;
788 onePortContext->discovery.SeenBC = agFALSE;
789 onePortContext->discovery.forcedOK = agFALSE;
790 onePortContext->discovery.SMPRetries = 0;
791 onePortContext->discovery.DeferredError = agFALSE;
792 onePortContext->discovery.ConfiguresOthers = agFALSE;
793 onePortContext->discovery.ResetTriggerred = agFALSE;
794
795 /* free expander lists */
796 dmCleanAllExp(dmRoot, onePortContext);
797
798 /* kill the discovery-related timers if they are running */
799 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
800 if (discovery->discoveryTimer.timerRunning == agTRUE)
801 {
802 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
803 dmKillTimer(
804 dmRoot,
805 &discovery->discoveryTimer
806 );
807 }
808 else
809 {
810 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
811 }
812
813
814 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
815 if (discovery->configureRouteTimer.timerRunning == agTRUE)
816 {
817 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
818 dmKillTimer(
819 dmRoot,
820 &discovery->configureRouteTimer
821 );
822 }
823 else
824 {
825 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
826 }
827
828
829 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
830 if (discovery->deviceRegistrationTimer.timerRunning == agTRUE)
831 {
832 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
833 dmKillTimer(
834 dmRoot,
835 &discovery->deviceRegistrationTimer
836 );
837 }
838 else
839 {
840 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
841 }
842
843
844 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
845 if (discovery->BCTimer.timerRunning == agTRUE)
846 {
847 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
848 dmKillTimer(
849 dmRoot,
850 &discovery->BCTimer
851 );
852 }
853 else
854 {
855 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
856 }
857
858
859 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
860 if (discovery->SMPBusyTimer.timerRunning == agTRUE)
861 {
862 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
863 dmKillTimer(
864 dmRoot,
865 &discovery->SMPBusyTimer
866 );
867 }
868 else
869 {
870 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
871 }
872
873
874 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
875 if (discovery->DiscoverySMPTimer.timerRunning == agTRUE)
876 {
877 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
878 dmKillTimer(
879 dmRoot,
880 &discovery->DiscoverySMPTimer
881 );
882 }
883 else
884 {
885 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
886 }
887
888 onePortContext->DiscoveryState = DM_DSTATE_NOT_STARTED;
889 onePortContext->DiscoveryAbortInProgress = agFALSE;
890 onePortContext->directAttatchedSAS = agFALSE;
891 onePortContext->DiscoveryRdyGiven = agFALSE;
892 onePortContext->SeenLinkUp = agFALSE;
893
894 onePortContext->dmPortContext->dmData = agNULL;
895 onePortContext->dmPortContext = agNULL;
896 onePortContext->dmRoot = agNULL;
897
898 onePortContext->LinkRate = 0;
899 onePortContext->Count = 0;
900 onePortContext->valid = agFALSE;
901 onePortContext->RegisteredDevNums = 0;
902 onePortContext->eventPhyID = 0xFF;
903 onePortContext->Transient = agFALSE;
904
905 return;
906 }
907
908
909 osGLOBAL void
dmInitTimers(dmRoot_t * dmRoot)910 dmInitTimers(
911 dmRoot_t *dmRoot
912 )
913 {
914 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
915 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
916
917 #ifdef DM_DEBUG_ENABLE
918 dmIntPortContext_t *dmPortContext = (dmIntPortContext_t *)dmAllShared->PortContextMem;
919
920 DM_DBG6(("dmInitTimers: start \n"));
921 DM_DBG6(("dmInitTimers: ******* tdsaRoot %p \n", dmIntRoot));
922 DM_DBG6(("dmInitTimers: ******* tdsaPortContext %p \n",dmPortContext));
923 #endif
924
925 /* initialize the timerlist */
926 DMLIST_INIT_HDR(&(dmAllShared->timerlist));
927
928 return;
929 }
930 #endif /* FDS_ DM */
931
932
933