1285809Sscottl/*******************************************************************************
2285809Sscottl**
3285809Sscottl*Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
4285809Sscottl*
5285809Sscottl*Redistribution and use in source and binary forms, with or without modification, are permitted provided
6285809Sscottl*that the following conditions are met:
7285809Sscottl*1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8285809Sscottl*following disclaimer.
9285809Sscottl*2. Redistributions in binary form must reproduce the above copyright notice,
10285809Sscottl*this list of conditions and the following disclaimer in the documentation and/or other materials provided
11285809Sscottl*with the distribution.
12285809Sscottl*
13285809Sscottl*THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
14285809Sscottl*WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15285809Sscottl*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16285809Sscottl*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17285809Sscottl*NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
18285809Sscottl*BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
19285809Sscottl*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
20285809Sscottl*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
21285809Sscottl
22285809Sscottl********************************************************************************/
23285809Sscottl#include <sys/cdefs.h>
24285809Sscottl__FBSDID("$FreeBSD$");
25285809Sscottl#include <dev/pms/config.h>
26285809Sscottl
27285809Sscottl#include <dev/pms/freebsd/driver/common/osenv.h>
28285809Sscottl#include <dev/pms/freebsd/driver/common/ostypes.h>
29285809Sscottl#include <dev/pms/freebsd/driver/common/osdebug.h>
30285809Sscottl
31285809Sscottl#include <dev/pms/RefTisa/sallsdk/api/sa.h>
32285809Sscottl#include <dev/pms/RefTisa/sallsdk/api/saapi.h>
33285809Sscottl#include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
34285809Sscottl
35285809Sscottl#ifdef FDS_DM
36285809Sscottl#include <dev/pms/RefTisa/discovery/api/dm.h>
37285809Sscottl#include <dev/pms/RefTisa/discovery/api/dmapi.h>
38285809Sscottl#include <dev/pms/RefTisa/discovery/api/tddmapi.h>
39285809Sscottl
40285809Sscottl#include <dev/pms/RefTisa/discovery/dm/dmdefs.h>
41285809Sscottl#include <dev/pms/RefTisa/discovery/dm/dmtypes.h>
42285809Sscottl#include <dev/pms/RefTisa/discovery/dm/dmproto.h>
43285809Sscottl
44285809Sscottl#ifdef DM_DEBUG
45285809Sscottlbit32 gDMDebugLevel = 1;
46285809Sscottl#endif
47285809Sscottl
48285809SscottlosGLOBAL void
49285809SscottldmGetRequirements(
50285809Sscottl                  dmRoot_t 	  		*dmRoot,
51285809Sscottl                  dmSwConfig_t			*swConfig,
52285809Sscottl                  dmMemoryRequirement_t		*memoryRequirement,
53285809Sscottl                  bit32 			*usecsPerTick,
54285809Sscottl                  bit32				*maxNumLocks)
55285809Sscottl{
56285809Sscottl  bit32               memoryReqCount = 0;
57285809Sscottl  bit32               max_expander = DM_MAX_EXPANDER_DEV;
58285809Sscottl  char    *buffer;
59285809Sscottl  bit32   buffLen;
60285809Sscottl  bit32   lenRecv = 0;
61285809Sscottl  static char    tmpBuffer[DEFAULT_KEY_BUFFER_SIZE];
62285809Sscottl  char    *pLastUsedChar = agNULL;
63285809Sscottl  char    globalStr[]     = "Global";
64285809Sscottl  char    iniParmsStr[]   = "InitiatorParms";
65285809Sscottl  char    SwParmsStr[]    = "SWParms";
66285809Sscottl
67285809Sscottl  DM_DBG3(("dmGetRequirements: start\n"));
68285809Sscottl  /* sanity check */
69285809Sscottl  DM_ASSERT((agNULL != swConfig), "");
70285809Sscottl  DM_ASSERT((agNULL != memoryRequirement), "");
71285809Sscottl  DM_ASSERT((agNULL != usecsPerTick), "");
72285809Sscottl  DM_ASSERT((agNULL != maxNumLocks), "");
73285809Sscottl
74285809Sscottl  /* memory requirement for dmRoot, CACHE memory */
75285809Sscottl  memoryRequirement->dmMemory[DM_ROOT_MEM_INDEX].singleElementLength = sizeof(dmIntRoot_t);
76285809Sscottl  memoryRequirement->dmMemory[DM_ROOT_MEM_INDEX].numElements = 1;
77285809Sscottl  memoryRequirement->dmMemory[DM_ROOT_MEM_INDEX].totalLength =
78285809Sscottl      (memoryRequirement->dmMemory[DM_ROOT_MEM_INDEX].singleElementLength) * (memoryRequirement->dmMemory[DM_ROOT_MEM_INDEX].numElements);
79285809Sscottl  memoryRequirement->dmMemory[DM_ROOT_MEM_INDEX].alignment = 4;
80285809Sscottl  memoryRequirement->dmMemory[DM_ROOT_MEM_INDEX].type = DM_CACHED_MEM;
81285809Sscottl  memoryReqCount++;
82285809Sscottl
83285809Sscottl  /* memory requirement for Port Context Links, CACHE memory */
84285809Sscottl  memoryRequirement->dmMemory[DM_PORT_MEM_INDEX].singleElementLength = sizeof(dmIntPortContext_t);
85285809Sscottl  memoryRequirement->dmMemory[DM_PORT_MEM_INDEX].numElements = DM_MAX_PORT_CONTEXT;
86285809Sscottl  memoryRequirement->dmMemory[DM_PORT_MEM_INDEX].totalLength =
87285809Sscottl      (memoryRequirement->dmMemory[DM_PORT_MEM_INDEX].singleElementLength) * (memoryRequirement->dmMemory[DM_PORT_MEM_INDEX].numElements);
88285809Sscottl  memoryRequirement->dmMemory[DM_PORT_MEM_INDEX].alignment = 4;
89285809Sscottl  memoryRequirement->dmMemory[DM_PORT_MEM_INDEX].type = DM_CACHED_MEM;
90285809Sscottl  memoryReqCount++;
91285809Sscottl
92285809Sscottl  /* memory requirement for Device Links, CACHE memory */
93285809Sscottl  memoryRequirement->dmMemory[DM_DEVICE_MEM_INDEX].singleElementLength = sizeof(dmDeviceData_t);
94285809Sscottl  memoryRequirement->dmMemory[DM_DEVICE_MEM_INDEX].numElements = DM_MAX_DEV;
95285809Sscottl  memoryRequirement->dmMemory[DM_DEVICE_MEM_INDEX].totalLength =
96285809Sscottl      (memoryRequirement->dmMemory[DM_DEVICE_MEM_INDEX].singleElementLength) * (memoryRequirement->dmMemory[DM_DEVICE_MEM_INDEX].numElements);
97285809Sscottl  memoryRequirement->dmMemory[DM_DEVICE_MEM_INDEX].alignment = 4;
98285809Sscottl  memoryRequirement->dmMemory[DM_DEVICE_MEM_INDEX].type = DM_CACHED_MEM;
99285809Sscottl  memoryReqCount++;
100285809Sscottl
101285809Sscottl  /* memory requirement for Expander Device Links, CACHE memory */
102285809Sscottl  /*
103285809Sscottl     Maximum number of expanders are configurable
104285809Sscottl     The default is DM_MAX_EXPANDER_DEV
105285809Sscottl  */
106285809Sscottl  buffer = tmpBuffer;
107285809Sscottl  buffLen = sizeof(tmpBuffer);
108285809Sscottl
109285809Sscottl  dm_memset(buffer, 0, buffLen);
110285809Sscottl  lenRecv = 0;
111285809Sscottl
112285809Sscottl  if ((tddmGetTransportParam(
113285809Sscottl                             dmRoot,
114285809Sscottl                             globalStr,
115285809Sscottl                             iniParmsStr,
116285809Sscottl                             agNULL,
117285809Sscottl                             agNULL,
118285809Sscottl                             agNULL,
119285809Sscottl                             agNULL,
120285809Sscottl                             "MaxExpanders",
121285809Sscottl                             buffer,
122285809Sscottl                             buffLen,
123285809Sscottl                             &lenRecv
124285809Sscottl                             ) == DM_RC_SUCCESS) && (lenRecv != 0))
125285809Sscottl  {
126285809Sscottl    if (osti_strncmp(buffer, "0x", 2) == 0)
127285809Sscottl    {
128285809Sscottl      max_expander = osti_strtoul (buffer, &pLastUsedChar, 0);
129285809Sscottl    }
130285809Sscottl    else
131285809Sscottl    {
132285809Sscottl      max_expander = osti_strtoul (buffer, &pLastUsedChar, 10);
133285809Sscottl    }
134285809Sscottl  }
135285809Sscottl  DM_DBG3(("dmGetRequirements: max_expander %d\n", max_expander));
136285809Sscottl
137285809Sscottl
138285809Sscottl  memoryRequirement->dmMemory[DM_EXPANDER_MEM_INDEX].singleElementLength = sizeof(dmExpander_t);
139285809Sscottl  memoryRequirement->dmMemory[DM_EXPANDER_MEM_INDEX].numElements = max_expander;
140285809Sscottl  memoryRequirement->dmMemory[DM_EXPANDER_MEM_INDEX].totalLength =
141285809Sscottl      (memoryRequirement->dmMemory[DM_EXPANDER_MEM_INDEX].singleElementLength) * (memoryRequirement->dmMemory[DM_EXPANDER_MEM_INDEX].numElements);
142285809Sscottl  memoryRequirement->dmMemory[DM_EXPANDER_MEM_INDEX].alignment = 4;
143285809Sscottl  memoryRequirement->dmMemory[DM_EXPANDER_MEM_INDEX].type = DM_CACHED_MEM;
144285809Sscottl  memoryReqCount++;
145285809Sscottl
146285809Sscottl  /* memory requirement for SMP command Links, CACHE memory */
147285809Sscottl  memoryRequirement->dmMemory[DM_SMP_MEM_INDEX].singleElementLength = sizeof(dmSMPRequestBody_t);
148285809Sscottl  memoryRequirement->dmMemory[DM_SMP_MEM_INDEX].numElements = DM_MAX_SMP;
149285809Sscottl  memoryRequirement->dmMemory[DM_SMP_MEM_INDEX].totalLength =
150285809Sscottl      (memoryRequirement->dmMemory[DM_SMP_MEM_INDEX].singleElementLength) * (memoryRequirement->dmMemory[DM_SMP_MEM_INDEX].numElements);
151285809Sscottl  memoryRequirement->dmMemory[DM_SMP_MEM_INDEX].alignment = 4;
152285809Sscottl  memoryRequirement->dmMemory[DM_SMP_MEM_INDEX].type = DM_CACHED_MEM;
153285809Sscottl  memoryReqCount++;
154285809Sscottl
155285809Sscottl  /* memory requirement for INDIRECT SMP command/response Links, DMA memory */
156285809Sscottl  memoryRequirement->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].singleElementLength = SMP_INDIRECT_PAYLOAD; /* 512 */
157285809Sscottl  memoryRequirement->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].numElements = DM_MAX_INDIRECT_SMP;
158285809Sscottl  memoryRequirement->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].totalLength =
159285809Sscottl      (memoryRequirement->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].singleElementLength) * (memoryRequirement->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].numElements);
160285809Sscottl  memoryRequirement->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].alignment = 4;
161285809Sscottl  memoryRequirement->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].type = DM_DMA_MEM;
162285809Sscottl  memoryReqCount++;
163285809Sscottl
164285809Sscottl
165285809Sscottl  /* set up memory requirement count */
166285809Sscottl  memoryRequirement->count = memoryReqCount;
167285809Sscottl
168285809Sscottl  /* requirement for locks */
169285809Sscottl  *maxNumLocks = DM_MAX_LOCKS;
170285809Sscottl
171285809Sscottl  /* setup the time tick */
172285809Sscottl  *usecsPerTick = DM_USECS_PER_TICK;
173285809Sscottl
174285809Sscottl
175285809Sscottl  /* set up the number of Expander device handles */
176285809Sscottl  swConfig->numDevHandles = DM_MAX_DEV;
177285809Sscottl  swConfig->itNexusTimeout = IT_NEXUS_TIMEOUT;   /* default is 2000 ms*/
178285809Sscottl
179285809Sscottl  dm_memset(buffer, 0, buffLen);
180285809Sscottl  lenRecv = 0;
181285809Sscottl
182285809Sscottl  if ((tddmGetTransportParam(
183285809Sscottl                             dmRoot,
184285809Sscottl                             globalStr,
185285809Sscottl                             SwParmsStr,
186285809Sscottl                             agNULL,
187285809Sscottl                             agNULL,
188285809Sscottl                             agNULL,
189285809Sscottl                             agNULL,
190285809Sscottl                             "IT_NEXUS_TIMEOUT",
191285809Sscottl                             buffer,
192285809Sscottl                             buffLen,
193285809Sscottl                             &lenRecv
194285809Sscottl                             ) == DM_RC_SUCCESS) && (lenRecv != 0))
195285809Sscottl  {
196285809Sscottl    if (osti_strncmp(buffer, "0x", 2) == 0)
197285809Sscottl    {
198285809Sscottl      swConfig->itNexusTimeout = osti_strtoul (buffer, &pLastUsedChar, 0);
199285809Sscottl    }
200285809Sscottl    else
201285809Sscottl    {
202285809Sscottl      swConfig->itNexusTimeout = osti_strtoul (buffer, &pLastUsedChar, 10);
203285809Sscottl    }
204285809Sscottl  }
205285809Sscottl
206285809Sscottl  DM_DBG1(("dmGetRequirements: swConfig->itNexusTimeout 0x%X\n", swConfig->itNexusTimeout));
207285809Sscottl
208285809Sscottl  DM_DBG3(("dmGetRequirements: memoryReqCount %d\n", memoryRequirement->count));
209285809Sscottl
210285809Sscottl  return;
211285809Sscottl}
212285809Sscottl/*
213285809Sscottl  ??? processing swConfig
214285809Sscottl*/
215285809SscottlosGLOBAL bit32
216285809SscottldmInitialize(
217285809Sscottl             dmRoot_t			*dmRoot,
218285809Sscottl             agsaRoot_t                 *agRoot,
219285809Sscottl             dmMemoryRequirement_t	*memoryAllocated,
220285809Sscottl             dmSwConfig_t		*swConfig,
221285809Sscottl             bit32			usecsPerTick )
222285809Sscottl{
223285809Sscottl  dmIntRoot_t               *dmIntRoot;
224285809Sscottl  dmIntPortContext_t        *dmIntPortContext;
225285809Sscottl  dmDeviceData_t            *dmDevice;
226285809Sscottl  dmExpander_t              *dmExpander;
227285809Sscottl  dmSMPRequestBody_t        *dmSMPRequest;
228285809Sscottl  bit8                      *dmIndirectSMPRequest;
229285809Sscottl  dmIntContext_t            *dmAllShared;
230285809Sscottl  bit32              i;
231285809Sscottl  bit32               max_expander = DM_MAX_EXPANDER_DEV;
232285809Sscottl  char    *buffer;
233285809Sscottl  bit32   buffLen;
234285809Sscottl  bit32   lenRecv = 0;
235285809Sscottl  static char    tmpBuffer[DEFAULT_KEY_BUFFER_SIZE];
236285809Sscottl  char    *pLastUsedChar = agNULL;
237285809Sscottl  char    globalStr[]     = "Global";
238285809Sscottl  char    iniParmsStr[]   = "InitiatorParms";
239285809Sscottl  char    SwParmsStr[]    = "SWParms";
240285809Sscottl
241285809Sscottl  DM_DBG3(("dmInitialize: start\n"));
242285809Sscottl  /* sanity check */
243285809Sscottl  DM_ASSERT((agNULL != dmRoot), "");
244285809Sscottl  DM_ASSERT((agNULL != agRoot), "");
245285809Sscottl  DM_ASSERT((agNULL != memoryAllocated), "");
246285809Sscottl  DM_ASSERT((agNULL != swConfig), "");
247285809Sscottl  DM_ASSERT((DM_ROOT_MEM_INDEX < memoryAllocated->count), "");
248285809Sscottl  DM_ASSERT((DM_PORT_MEM_INDEX < memoryAllocated->count), "");
249285809Sscottl  DM_ASSERT((DM_DEVICE_MEM_INDEX < memoryAllocated->count), "");
250285809Sscottl  DM_ASSERT((DM_EXPANDER_MEM_INDEX < memoryAllocated->count), "");
251285809Sscottl  DM_ASSERT((DM_SMP_MEM_INDEX < memoryAllocated->count), "");
252285809Sscottl  DM_ASSERT((DM_INDIRECT_SMP_MEM_INDEX < memoryAllocated->count), "");
253285809Sscottl
254285809Sscottl  /* Check the memory allocated */
255285809Sscottl  for ( i = 0; i < memoryAllocated->count; i ++ )
256285809Sscottl  {
257285809Sscottl    /* If memory allocatation failed  */
258285809Sscottl    if (memoryAllocated->dmMemory[i].singleElementLength &&
259285809Sscottl        memoryAllocated->dmMemory[i].numElements)
260285809Sscottl    {
261285809Sscottl      if ( (0 != memoryAllocated->dmMemory[i].numElements)
262285809Sscottl          && (0 == memoryAllocated->dmMemory[i].totalLength) )
263285809Sscottl      {
264285809Sscottl        /* return failure */
265285809Sscottl        DM_DBG1(("dmInitialize: Memory[%d]  singleElementLength = 0x%0x  numElements = 0x%x NOT allocated!!!\n",
266285809Sscottl          i,
267285809Sscottl          memoryAllocated->dmMemory[i].singleElementLength,
268285809Sscottl          memoryAllocated->dmMemory[i].numElements));
269285809Sscottl        return DM_RC_FAILURE;
270285809Sscottl      }
271285809Sscottl    }
272285809Sscottl  }
273285809Sscottl
274285809Sscottl  /* DM's internal root */
275285809Sscottl  dmIntRoot  = (dmIntRoot_t *) (memoryAllocated->dmMemory[DM_ROOT_MEM_INDEX].virtPtr);
276285809Sscottl  dmRoot->dmData = (void *) dmIntRoot;
277285809Sscottl
278285809Sscottl  dmAllShared = (dmIntContext_t *)&(dmIntRoot->dmAllShared);
279285809Sscottl  /**<  Initialize the TDM data part of the interrupt context */
280285809Sscottl  dmAllShared->dmRootOsData.dmRoot     = dmRoot;
281285809Sscottl  dmAllShared->dmRootOsData.dmAllShared   = (void *) dmAllShared;
282285809Sscottl
283285809Sscottl  /* Port Contexts */
284285809Sscottl  dmIntPortContext = (dmIntPortContext_t *) (memoryAllocated->dmMemory[DM_PORT_MEM_INDEX].virtPtr);
285285809Sscottl  dmAllShared->PortContextMem = (dmIntPortContext_t *)dmIntPortContext;
286285809Sscottl
287285809Sscottl  /* Devices */
288285809Sscottl  dmDevice = (dmDeviceData_t *) (memoryAllocated->dmMemory[DM_DEVICE_MEM_INDEX].virtPtr);
289285809Sscottl  dmAllShared->DeviceMem = (dmDeviceData_t *)dmDevice;
290285809Sscottl
291285809Sscottl  /* Expanders */
292285809Sscottl  dmExpander = (dmExpander_t *) (memoryAllocated->dmMemory[DM_EXPANDER_MEM_INDEX].virtPtr);
293285809Sscottl  dmAllShared->ExpanderMem = (dmExpander_t *)dmExpander;
294285809Sscottl
295285809Sscottl  /* SMP commands */
296285809Sscottl  dmSMPRequest = (dmSMPRequestBody_t *) (memoryAllocated->dmMemory[DM_SMP_MEM_INDEX].virtPtr);
297285809Sscottl  dmAllShared->SMPMem = (dmSMPRequestBody_t *)dmSMPRequest;
298285809Sscottl
299285809Sscottl  /* DMAable SMP request/reponse pointed by dmSMPRequestBody_t */
300285809Sscottl  dmIndirectSMPRequest = (bit8 *) (memoryAllocated->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].virtPtr);
301285809Sscottl  dmAllShared->IndirectSMPMem = (bit8 *)dmIndirectSMPRequest;
302285809Sscottl  dmAllShared->IndirectSMPUpper32 = memoryAllocated->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].physAddrUpper;
303285809Sscottl  dmAllShared->IndirectSMPLower32 = memoryAllocated->dmMemory[DM_INDIRECT_SMP_MEM_INDEX].physAddrLower;
304285809Sscottl
305285809Sscottl  dmAllShared->agRoot = agRoot;
306285809Sscottl
307285809Sscottl
308285809Sscottl  dmAllShared->usecsPerTick = usecsPerTick;
309285809Sscottl  dmAllShared->itNexusTimeout = IT_NEXUS_TIMEOUT;/*swConfig->itNexusTimeout;*/
310285809Sscottl  dmAllShared->MaxRetryDiscovery = DISCOVERY_RETRIES;
311285809Sscottl  dmAllShared->RateAdjust = 0;
312285809Sscottl  /**< initializes timers */
313285809Sscottl  dmInitTimers(dmRoot);
314285809Sscottl
315285809Sscottl  /**< initializes port contexts */
316285809Sscottl  dmPortContextInit(dmRoot);
317285809Sscottl
318285809Sscottl  /**< initializes devices */
319285809Sscottl  dmDeviceDataInit(dmRoot);
320285809Sscottl
321285809Sscottl  /**< initializes expander devices */
322285809Sscottl  buffer = tmpBuffer;
323285809Sscottl  buffLen = sizeof(tmpBuffer);
324285809Sscottl
325285809Sscottl  dm_memset(buffer, 0, buffLen);
326285809Sscottl  lenRecv = 0;
327285809Sscottl
328285809Sscottl  if ((tddmGetTransportParam(
329285809Sscottl                             dmRoot,
330285809Sscottl                             globalStr,
331285809Sscottl                             iniParmsStr,
332285809Sscottl                             agNULL,
333285809Sscottl                             agNULL,
334285809Sscottl                             agNULL,
335285809Sscottl                             agNULL,
336285809Sscottl                             "MaxExpanders",
337285809Sscottl                             buffer,
338285809Sscottl                             buffLen,
339285809Sscottl                             &lenRecv
340285809Sscottl                             ) == DM_RC_SUCCESS) && (lenRecv != 0))
341285809Sscottl  {
342285809Sscottl    if (osti_strncmp(buffer, "0x", 2) == 0)
343285809Sscottl    {
344285809Sscottl      max_expander = osti_strtoul (buffer, &pLastUsedChar, 0);
345285809Sscottl    }
346285809Sscottl    else
347285809Sscottl    {
348285809Sscottl      max_expander = osti_strtoul (buffer, &pLastUsedChar, 10);
349285809Sscottl    }
350285809Sscottl  }
351285809Sscottl
352285809Sscottl  dm_memset(buffer, 0, buffLen);
353285809Sscottl  lenRecv = 0;
354285809Sscottl
355285809Sscottl  if ((tddmGetTransportParam(
356285809Sscottl                             dmRoot,
357285809Sscottl                             globalStr,
358285809Sscottl                             SwParmsStr,
359285809Sscottl                             agNULL,
360285809Sscottl                             agNULL,
361285809Sscottl                             agNULL,
362285809Sscottl                             agNULL,
363285809Sscottl                             "IT_NEXUS_TIMEOUT",
364285809Sscottl                             buffer,
365285809Sscottl                             buffLen,
366285809Sscottl                             &lenRecv
367285809Sscottl                             ) == DM_RC_SUCCESS) && (lenRecv != 0))
368285809Sscottl  {
369285809Sscottl    if (osti_strncmp(buffer, "0x", 2) == 0)
370285809Sscottl    {
371285809Sscottl      dmAllShared->itNexusTimeout = osti_strtoul (buffer, &pLastUsedChar, 0);
372285809Sscottl    }
373285809Sscottl    else
374285809Sscottl    {
375285809Sscottl      dmAllShared->itNexusTimeout = osti_strtoul (buffer, &pLastUsedChar, 10);
376285809Sscottl    }
377285809Sscottl  }
378285809Sscottl
379285809Sscottl  DM_DBG1(("dmAllShared->itNexusTimeout %d \n", dmAllShared->itNexusTimeout));
380285809Sscottl
381285809Sscottl  dm_memset(buffer, 0, buffLen);
382285809Sscottl  lenRecv = 0;
383285809Sscottl
384285809Sscottl  if ((tddmGetTransportParam(
385285809Sscottl                             dmRoot,
386285809Sscottl                             globalStr,
387285809Sscottl                             SwParmsStr,
388285809Sscottl                             agNULL,
389285809Sscottl                             agNULL,
390285809Sscottl                             agNULL,
391285809Sscottl                             agNULL,
392285809Sscottl                             "MaxRetryDiscovery",
393285809Sscottl                             buffer,
394285809Sscottl                             buffLen,
395285809Sscottl                             &lenRecv
396285809Sscottl                             ) == DM_RC_SUCCESS) && (lenRecv != 0))
397285809Sscottl  {
398285809Sscottl    if (osti_strncmp(buffer, "0x", 2) == 0)
399285809Sscottl    {
400285809Sscottl      dmAllShared->MaxRetryDiscovery = osti_strtoul (buffer, &pLastUsedChar, 0);
401285809Sscottl    }
402285809Sscottl    else
403285809Sscottl    {
404285809Sscottl      dmAllShared->MaxRetryDiscovery = osti_strtoul (buffer, &pLastUsedChar, 10);
405285809Sscottl    }
406285809Sscottl  }
407285809Sscottl
408285809Sscottl  DM_DBG1(("dmAllShared->MaxRetryDiscovery %d \n", dmAllShared->MaxRetryDiscovery));
409285809Sscottl
410285809Sscottl  dm_memset(buffer, 0, buffLen);
411285809Sscottl  lenRecv = 0;
412285809Sscottl  if ((tddmGetTransportParam(
413285809Sscottl                             dmRoot,
414285809Sscottl                             globalStr,
415285809Sscottl                             SwParmsStr,
416285809Sscottl                             agNULL,
417285809Sscottl                             agNULL,
418285809Sscottl                             agNULL,
419285809Sscottl                             agNULL,
420285809Sscottl                             "RateAdjust",
421285809Sscottl                             buffer,
422285809Sscottl                             buffLen,
423285809Sscottl                             &lenRecv
424285809Sscottl                             ) == DM_RC_SUCCESS) && (lenRecv != 0))
425285809Sscottl  {
426285809Sscottl    if (osti_strncmp(buffer, "0x", 2) == 0)
427285809Sscottl    {
428285809Sscottl      dmAllShared->RateAdjust = osti_strtoul (buffer, &pLastUsedChar, 0);
429285809Sscottl    }
430285809Sscottl    else
431285809Sscottl    {
432285809Sscottl      dmAllShared->RateAdjust = osti_strtoul (buffer, &pLastUsedChar, 10);
433285809Sscottl    }
434285809Sscottl  }
435285809Sscottl  DM_DBG1(("dmAllShared->RateAdjust %d \n", dmAllShared->RateAdjust));
436285809Sscottl
437285809Sscottl  dmExpanderDeviceDataInit(dmRoot, max_expander);
438285809Sscottl
439285809Sscottl  /**< initializes SMP commands */
440285809Sscottl  dmSMPInit(dmRoot);
441285809Sscottl
442285809Sscottl#ifdef DM_DEBUG
443285809Sscottl  gDMDebugLevel = swConfig->DMDebugLevel;
444285809Sscottl#endif
445285809Sscottl  return DM_RC_SUCCESS;
446285809Sscottl}
447285809Sscottl
448285809SscottlosGLOBAL void
449285809SscottldmSMPInit(
450285809Sscottl          dmRoot_t *dmRoot
451285809Sscottl         )
452285809Sscottl{
453285809Sscottl  dmIntRoot_t               *dmIntRoot    = (dmIntRoot_t *)dmRoot->dmData;
454285809Sscottl  dmIntContext_t            *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
455285809Sscottl  dmSMPRequestBody_t        *dmSMPCommand = (dmSMPRequestBody_t *)dmAllShared->SMPMem;
456285809Sscottl  bit8                      *dmIndirectSMPReqRsp = (bit8 *)dmAllShared->IndirectSMPMem;
457285809Sscottl  bit32                     prev_PhysAddrLower;
458285809Sscottl
459285809Sscottl  int i = 0;
460285809Sscottl  DM_DBG3(("dmSMPInit: start \n"));
461285809Sscottl
462285809Sscottl  DMLIST_INIT_HDR(&(dmAllShared->freeSMPList));
463285809Sscottl
464285809Sscottl  for(i=0;i<DM_MAX_SMP;i++)
465285809Sscottl  {
466285809Sscottl    DMLIST_INIT_ELEMENT(&(dmSMPCommand[i].Link));
467285809Sscottl    /* initialize expander fields */
468285809Sscottl    dmSMPCommand[i].dmRoot = agNULL;
469285809Sscottl    dmSMPCommand[i].dmDevice = agNULL;
470285809Sscottl    dmSMPCommand[i].dmPortContext = agNULL;
471285809Sscottl    dmSMPCommand[i].retries = 0;
472285809Sscottl    dmSMPCommand[i].id = i;
473285809Sscottl    dm_memset( &(dmSMPCommand[i].smpPayload), 0, sizeof(dmSMPCommand[i].smpPayload));
474285809Sscottl    /* indirect SMP related */
475285809Sscottl    dmSMPCommand[i].IndirectSMPResponse = agNULL;
476285809Sscottl    dmSMPCommand[i].IndirectSMP = ((bit8 *)dmIndirectSMPReqRsp) + (i*SMP_INDIRECT_PAYLOAD);
477285809Sscottl    dmSMPCommand[i].IndirectSMPUpper32 = dmAllShared->IndirectSMPUpper32;
478285809Sscottl    dmSMPCommand[i].IndirectSMPLower32 = dmAllShared->IndirectSMPLower32;
479285809Sscottl
480285809Sscottl    prev_PhysAddrLower = dmAllShared->IndirectSMPLower32;
481285809Sscottl    dmAllShared->IndirectSMPLower32 = dmAllShared->IndirectSMPLower32 + SMP_INDIRECT_PAYLOAD;
482285809Sscottl    if (dmAllShared->IndirectSMPLower32 <= prev_PhysAddrLower)
483285809Sscottl    {
484285809Sscottl      dmAllShared->IndirectSMPUpper32++;
485285809Sscottl    }
486285809Sscottl
487285809Sscottl    DMLIST_ENQUEUE_AT_TAIL(&(dmSMPCommand[i].Link), &(dmAllShared->freeSMPList));
488285809Sscottl  }
489285809Sscottl  return;
490285809Sscottl
491285809Sscottl}
492285809Sscottl
493285809SscottlosGLOBAL void
494285809SscottldmDeviceDataInit(
495285809Sscottl                 dmRoot_t *dmRoot
496285809Sscottl                )
497285809Sscottl{
498285809Sscottl  dmIntRoot_t               *dmIntRoot    = (dmIntRoot_t *)dmRoot->dmData;
499285809Sscottl  dmIntContext_t            *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
500285809Sscottl  dmDeviceData_t            *dmDeviceData = (dmDeviceData_t *)dmAllShared->DeviceMem;
501285809Sscottl  int i;
502285809Sscottl
503285809Sscottl  DM_DBG3(("dmDeviceDataInit: start \n"));
504285809Sscottl
505285809Sscottl  DMLIST_INIT_HDR(&(dmAllShared->MainDeviceList));
506285809Sscottl  DMLIST_INIT_HDR(&(dmAllShared->FreeDeviceList));
507285809Sscottl
508285809Sscottl  for(i=0;i<DM_MAX_DEV;i++)
509285809Sscottl  {
510285809Sscottl    DMLIST_INIT_ELEMENT(&(dmDeviceData[i].FreeLink));
511285809Sscottl    DMLIST_INIT_ELEMENT(&(dmDeviceData[i].MainLink));
512285809Sscottl    DMLIST_INIT_ELEMENT(&(dmDeviceData[i].IncDisLink));
513285809Sscottl    dmDeviceData[i].id = i;
514285809Sscottl    dmDeviceData[i].DeviceType = DM_DEFAULT_DEVICE;
515285809Sscottl    dmDeviceData[i].dmRoot = agNULL;
516285809Sscottl//    dmDeviceData[i].agDevHandle = agNULL;
517285809Sscottl
518285809Sscottl    dmDeviceData[i].dmPortContext = agNULL;
519285809Sscottl    dmDeviceData[i].dmExpander = agNULL;
520285809Sscottl    dmDeviceData[i].ExpDevice = agNULL;
521285809Sscottl    dmDeviceData[i].phyID = 0xFF;
522285809Sscottl    dmDeviceData[i].SASAddressID.sasAddressHi = 0;
523285809Sscottl    dmDeviceData[i].SASAddressID.sasAddressLo = 0;
524285809Sscottl    dmDeviceData[i].valid = agFALSE;
525285809Sscottl    dmDeviceData[i].valid2 = agFALSE;
526285809Sscottl    dmDeviceData[i].processed = agFALSE;
527285809Sscottl    dmDeviceData[i].initiator_ssp_stp_smp = 0;
528285809Sscottl    dmDeviceData[i].target_ssp_stp_smp = 0;
529285809Sscottl    dmDeviceData[i].numOfPhys = 0;
530285809Sscottl//    dmDeviceData[i].registered = agFALSE;
531285809Sscottl    dmDeviceData[i].directlyAttached = agFALSE;
532285809Sscottl    dmDeviceData[i].SASSpecDeviceType = 0xFF;
533285809Sscottl    dmDeviceData[i].IOStart = 0;
534285809Sscottl    dmDeviceData[i].IOResponse = 0;
535285809Sscottl    dmDeviceData[i].agDeviceResetContext.osData = agNULL;
536285809Sscottl    dmDeviceData[i].agDeviceResetContext.sdkData = agNULL;
537285809Sscottl    dmDeviceData[i].TRflag = agFALSE;
538285809Sscottl    dmDeviceData[i].ResetCnt = 0;
539285809Sscottl    dmDeviceData[i].registered = agFALSE;
540285809Sscottl    dmDeviceData[i].reported = agFALSE;
541285809Sscottl
542285809Sscottl    dmDeviceData[i].MCN = 0;
543285809Sscottl    dmDeviceData[i].MCNDone = agFALSE;
544285809Sscottl    dmDeviceData[i].PrevMCN = 0;
545285809Sscottl
546285809Sscottl    dm_memset( &(dmDeviceData[i].dmDeviceInfo), 0, sizeof(dmDeviceInfo_t));
547285809Sscottl    /* some other variables */
548285809Sscottl    DMLIST_ENQUEUE_AT_TAIL(&(dmDeviceData[i].FreeLink), &(dmAllShared->FreeDeviceList));
549285809Sscottl  }
550285809Sscottl
551285809Sscottl  return;
552285809Sscottl}
553285809SscottlosGLOBAL void
554285809SscottldmDeviceDataReInit(
555285809Sscottl                   dmRoot_t		  *dmRoot,
556285809Sscottl                   dmDeviceData_t         *oneDeviceData
557285809Sscottl                  )
558285809Sscottl{
559285809Sscottl  DM_DBG3(("dmDeviceDataReInit: start \n"));
560285809Sscottl
561285809Sscottl  oneDeviceData->DeviceType = DM_DEFAULT_DEVICE;
562285809Sscottl//  oneDeviceData->agDevHandle = agNULL;
563285809Sscottl
564285809Sscottl  oneDeviceData->dmPortContext = agNULL;
565285809Sscottl  oneDeviceData->dmExpander = agNULL;
566285809Sscottl  oneDeviceData->ExpDevice = agNULL;
567285809Sscottl  oneDeviceData->phyID = 0xFF;
568285809Sscottl  oneDeviceData->SASAddressID.sasAddressHi = 0;
569285809Sscottl  oneDeviceData->SASAddressID.sasAddressLo = 0;
570285809Sscottl  oneDeviceData->valid = agFALSE;
571285809Sscottl  oneDeviceData->valid2 = agFALSE;
572285809Sscottl  oneDeviceData->processed = agFALSE;
573285809Sscottl  oneDeviceData->initiator_ssp_stp_smp = 0;
574285809Sscottl  oneDeviceData->target_ssp_stp_smp = 0;
575285809Sscottl  oneDeviceData->numOfPhys = 0;
576285809Sscottl//  oneDeviceData->registered = agFALSE;
577285809Sscottl  oneDeviceData->directlyAttached = agFALSE;
578285809Sscottl  oneDeviceData->SASSpecDeviceType = 0xFF;
579285809Sscottl  oneDeviceData->IOStart = 0;
580285809Sscottl  oneDeviceData->IOResponse = 0;
581285809Sscottl  oneDeviceData->agDeviceResetContext.osData = agNULL;
582285809Sscottl  oneDeviceData->agDeviceResetContext.sdkData = agNULL;
583285809Sscottl  oneDeviceData->TRflag = agFALSE;
584285809Sscottl  oneDeviceData->ResetCnt = 0;
585285809Sscottl  oneDeviceData->registered = agFALSE;
586285809Sscottl  oneDeviceData->reported = agFALSE;
587285809Sscottl
588285809Sscottl  oneDeviceData->MCN = 0;
589285809Sscottl  oneDeviceData->MCNDone = agFALSE;
590285809Sscottl  oneDeviceData->PrevMCN = 0;
591285809Sscottl
592285809Sscottl  dm_memset( &(oneDeviceData->dmDeviceInfo), 0, sizeof(dmDeviceInfo_t));
593285809Sscottl
594285809Sscottl  return;
595285809Sscottl}
596285809Sscottl
597285809Sscottl
598285809SscottlosGLOBAL void
599285809SscottldmExpanderDeviceDataInit(
600285809Sscottl                         dmRoot_t *dmRoot,
601285809Sscottl                         bit32    max_exp
602285809Sscottl                        )
603285809Sscottl{
604285809Sscottl  dmIntRoot_t               *dmIntRoot    = (dmIntRoot_t *)dmRoot->dmData;
605285809Sscottl  dmIntContext_t            *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
606285809Sscottl  dmExpander_t              *dmExpData = (dmExpander_t *)dmAllShared->ExpanderMem;
607285809Sscottl  bit32 i = 0;
608285809Sscottl  DM_DBG3(("dmExpanderDeviceDataInit: start \n"));
609285809Sscottl
610285809Sscottl  DMLIST_INIT_HDR(&(dmAllShared->freeExpanderList));
611285809Sscottl  DMLIST_INIT_HDR(&(dmAllShared->mainExpanderList));
612285809Sscottl
613285809Sscottl  for(i=0;i<max_exp;i++)
614285809Sscottl  {
615285809Sscottl    DMLIST_INIT_ELEMENT(&(dmExpData[i].linkNode));
616285809Sscottl    DMLIST_INIT_ELEMENT(&(dmExpData[i].upNode));
617285809Sscottl    /* initialize expander fields */
618285809Sscottl    dmExpData[i].dmRoot = agNULL;
619285809Sscottl    dmExpData[i].agDevHandle = agNULL;
620285809Sscottl    dmExpData[i].dmDevice = agNULL;
621285809Sscottl    dmExpData[i].dmUpStreamExpander = agNULL;
622285809Sscottl    dmExpData[i].dmCurrentDownStreamExpander = agNULL;
623285809Sscottl    dmExpData[i].hasUpStreamDevice = agFALSE;
624285809Sscottl    dmExpData[i].numOfUpStreamPhys = 0;
625285809Sscottl    dmExpData[i].currentUpStreamPhyIndex = 0;
626285809Sscottl    dmExpData[i].numOfDownStreamPhys = 0;
627285809Sscottl    dmExpData[i].currentDownStreamPhyIndex = 0;
628285809Sscottl    dmExpData[i].discoveringPhyId = 0;
629285809Sscottl    dmExpData[i].underDiscovering = agFALSE;
630285809Sscottl    dmExpData[i].id = i;
631285809Sscottl    DM_DBG3(("dmExpanderDeviceDataInit: exp id %d\n", i));
632285809Sscottl
633285809Sscottl    dmExpData[i].dmReturnginExpander = agNULL;
634285809Sscottl    dmExpData[i].discoverSMPAllowed = agTRUE;
635285809Sscottl    dm_memset( &(dmExpData[i].currentIndex), 0, sizeof(dmExpData[i].currentIndex));
636285809Sscottl    dm_memset( &(dmExpData[i].upStreamPhys), 0, sizeof(dmExpData[i].upStreamPhys));
637285809Sscottl    dm_memset( &(dmExpData[i].downStreamPhys), 0, sizeof(dmExpData[i].downStreamPhys));
638285809Sscottl    dm_memset( &(dmExpData[i].routingAttribute), 0, sizeof(dmExpData[i].routingAttribute));
639285809Sscottl    dmExpData[i].configSASAddrTableIndex = 0;
640285809Sscottl    dm_memset( &(dmExpData[i].configSASAddressHiTable), 0, sizeof(dmExpData[i].configSASAddressHiTable));
641285809Sscottl    dm_memset( &(dmExpData[i].configSASAddressLoTable), 0, sizeof(dmExpData[i].configSASAddressLoTable));
642285809Sscottl    dmExpData[i].SAS2 = 0;  /* default is SAS 1.1 spec */
643285809Sscottl    dmExpData[i].TTTSupported = agFALSE;  /* Table to Table is supported */
644285809Sscottl    dmExpData[i].UndoDueToTTTSupported = agFALSE;
645285809Sscottl
646285809Sscottl
647285809Sscottl    DMLIST_ENQUEUE_AT_TAIL(&(dmExpData[i].linkNode), &(dmAllShared->freeExpanderList));
648285809Sscottl  }
649285809Sscottl  return;
650285809Sscottl}
651285809Sscottl
652285809Sscottl/* re-intialize an expander */
653285809SscottlosGLOBAL void
654285809SscottldmExpanderDeviceDataReInit(
655285809Sscottl                           dmRoot_t         *dmRoot,
656285809Sscottl                           dmExpander_t     *oneExpander
657285809Sscottl                          )
658285809Sscottl{
659285809Sscottl  DM_DBG3(("dmExpanderDeviceDataReInit: start \n"));
660285809Sscottl  oneExpander->dmRoot = agNULL;
661285809Sscottl  oneExpander->agDevHandle = agNULL;
662285809Sscottl  oneExpander->dmDevice = agNULL;
663285809Sscottl  oneExpander->dmUpStreamExpander = agNULL;
664285809Sscottl  oneExpander->dmCurrentDownStreamExpander = agNULL;
665285809Sscottl  oneExpander->hasUpStreamDevice = agFALSE;
666285809Sscottl  oneExpander->numOfUpStreamPhys = 0;
667285809Sscottl  oneExpander->currentUpStreamPhyIndex = 0;
668285809Sscottl  oneExpander->numOfDownStreamPhys = 0;
669285809Sscottl  oneExpander->currentDownStreamPhyIndex = 0;
670285809Sscottl  oneExpander->discoveringPhyId = 0;
671285809Sscottl  oneExpander->underDiscovering = agFALSE;
672285809Sscottl  oneExpander->dmReturnginExpander = agNULL;
673285809Sscottl  oneExpander->discoverSMPAllowed = agTRUE;
674285809Sscottl  dm_memset( &(oneExpander->currentIndex), 0, sizeof(oneExpander->currentIndex));
675285809Sscottl  dm_memset( &(oneExpander->upStreamPhys), 0, sizeof(oneExpander->upStreamPhys));
676285809Sscottl  dm_memset( &(oneExpander->downStreamPhys), 0, sizeof(oneExpander->downStreamPhys));
677285809Sscottl  dm_memset( &(oneExpander->routingAttribute), 0, sizeof(oneExpander->routingAttribute));
678285809Sscottl  oneExpander->configSASAddrTableIndex = 0;
679285809Sscottl  dm_memset( &(oneExpander->configSASAddressHiTable), 0, sizeof(oneExpander->configSASAddressHiTable));
680285809Sscottl  dm_memset( &(oneExpander->configSASAddressLoTable), 0, sizeof(oneExpander->configSASAddressLoTable));
681285809Sscottl  oneExpander->SAS2 = 0;  /* default is SAS 1.1 spec */
682285809Sscottl  oneExpander->TTTSupported = agFALSE;  /* Table to Table is supported */
683285809Sscottl  oneExpander->UndoDueToTTTSupported = agFALSE;
684285809Sscottl
685285809Sscottl  return;
686285809Sscottl}
687285809Sscottl
688285809SscottlosGLOBAL void
689285809SscottldmPortContextInit(
690285809Sscottl                  dmRoot_t *dmRoot
691285809Sscottl                 )
692285809Sscottl{
693285809Sscottl  dmIntRoot_t               *dmIntRoot    = (dmIntRoot_t *)dmRoot->dmData;
694285809Sscottl  dmIntContext_t            *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
695285809Sscottl  dmIntPortContext_t        *dmPortContext = (dmIntPortContext_t *)dmAllShared->PortContextMem;
696285809Sscottl  int i = 0;
697285809Sscottl#ifdef TBD
698285809Sscottl  int j = 0;
699285809Sscottl#endif
700285809Sscottl
701285809Sscottl  DM_DBG3(("dmPortContextInit: start \n"));
702285809Sscottl
703285809Sscottl  DMLIST_INIT_HDR(&(dmAllShared->MainPortContextList));
704285809Sscottl  DMLIST_INIT_HDR(&(dmAllShared->FreePortContextList));
705285809Sscottl  for(i=0;i<DM_MAX_PORT_CONTEXT;i++)
706285809Sscottl  {
707285809Sscottl    DMLIST_INIT_ELEMENT(&(dmPortContext[i].FreeLink));
708285809Sscottl    DMLIST_INIT_ELEMENT(&(dmPortContext[i].MainLink));
709285809Sscottl
710285809Sscottl    DMLIST_INIT_HDR(&(dmPortContext[i].discovery.discoveringExpanderList));
711285809Sscottl    DMLIST_INIT_HDR(&(dmPortContext[i].discovery.UpdiscoveringExpanderList));
712285809Sscottl    dmPortContext[i].discovery.type = DM_DISCOVERY_OPTION_FULL_START;
713285809Sscottl    dmInitTimerRequest(dmRoot, &(dmPortContext[i].discovery.discoveryTimer));
714285809Sscottl    dmInitTimerRequest(dmRoot, &(dmPortContext[i].discovery.configureRouteTimer));
715285809Sscottl    dmInitTimerRequest(dmRoot, &(dmPortContext[i].discovery.deviceRegistrationTimer));
716285809Sscottl    dmInitTimerRequest(dmRoot, &(dmPortContext[i].discovery.SMPBusyTimer));
717285809Sscottl    dmInitTimerRequest(dmRoot, &(dmPortContext[i].discovery.BCTimer));
718285809Sscottl    dmInitTimerRequest(dmRoot, &(dmPortContext[i].discovery.DiscoverySMPTimer));
719285809Sscottl    dmPortContext[i].discovery.retries = 0;
720285809Sscottl    dmPortContext[i].discovery.configureRouteRetries = 0;
721285809Sscottl    dmPortContext[i].discovery.deviceRetistrationRetries = 0;
722285809Sscottl    dmPortContext[i].discovery.pendingSMP = 0;
723285809Sscottl    dmPortContext[i].discovery.SeenBC = agFALSE;
724285809Sscottl    dmPortContext[i].discovery.forcedOK = agFALSE;
725285809Sscottl    dmPortContext[i].discovery.SMPRetries = 0;
726285809Sscottl    dmPortContext[i].discovery.DeferredError = agFALSE;
727285809Sscottl    dmPortContext[i].discovery.ConfiguresOthers = agFALSE;
728285809Sscottl    dmPortContext[i].discovery.ResetTriggerred = agFALSE;
729285809Sscottl
730285809Sscottl#ifdef INITIATOR_DRIVER
731285809Sscottl    dmPortContext[i].DiscoveryState = DM_DSTATE_NOT_STARTED;
732285809Sscottl    dmPortContext[i].DiscoveryAbortInProgress = agFALSE;
733285809Sscottl    dmPortContext[i].directAttatchedSAS = agFALSE;
734285809Sscottl    dmPortContext[i].DiscoveryRdyGiven = agFALSE;
735285809Sscottl    dmPortContext[i].SeenLinkUp = agFALSE;
736285809Sscottl
737285809Sscottl#endif
738285809Sscottl    dmPortContext[i].id = i;
739285809Sscottl#ifdef TBD
740285809Sscottl    dmPortContext[i].agPortContext = agNULL;
741285809Sscottl#endif
742285809Sscottl    dmPortContext[i].LinkRate = 0;
743285809Sscottl    dmPortContext[i].Count = 0;
744285809Sscottl    dmPortContext[i].valid = agFALSE;
745285809Sscottl    dmPortContext[i].RegFailed = agFALSE;
746285809Sscottl
747285809Sscottl#ifdef TBD
748285809Sscottl    for (j=0;j<DM_MAX_NUM_PHYS;j++)
749285809Sscottl    {
750285809Sscottl      dmPortContext[i].PhyIDList[j] = agFALSE;
751285809Sscottl    }
752285809Sscottl#endif
753285809Sscottl    dmPortContext[i].RegisteredDevNums = 0;
754285809Sscottl    dmPortContext[i].eventPhyID = 0xFF;
755285809Sscottl    dmPortContext[i].Transient = agFALSE;
756285809Sscottl
757285809Sscottl    /* add more variables later */
758285809Sscottl    DMLIST_ENQUEUE_AT_TAIL(&(dmPortContext[i].FreeLink), &(dmAllShared->FreePortContextList));
759285809Sscottl  }
760285809Sscottl
761285809Sscottl#ifdef DM_INTERNAL_DEBUG  /* for debugging only */
762285809Sscottl  for(i=0;i<DM_MAX_PORT_CONTEXT;i++)
763285809Sscottl  {
764285809Sscottl    DM_DBG6(("dmPortContextInit: index %d  &tdsaPortContext[] %p\n", i, &(dmPortContext[i])));
765285809Sscottl  }
766285809Sscottl  DM_DBG6(("dmPortContextInit: sizeof(tdsaPortContext_t) %d 0x%x\n", sizeof(dmIntPortContext_t), sizeof(dmIntPortContext_t)));
767285809Sscottl#endif
768285809Sscottl
769285809Sscottl  return;
770285809Sscottl}
771285809Sscottl
772285809SscottlosGLOBAL void
773285809SscottldmPortContextReInit(
774285809Sscottl                    dmRoot_t		  *dmRoot,
775285809Sscottl                    dmIntPortContext_t    *onePortContext
776285809Sscottl                    )
777285809Sscottl{
778285809Sscottl  dmDiscovery_t   *discovery;
779285809Sscottl
780285809Sscottl  DM_DBG3(("dmPortContextReInit: start \n"));
781285809Sscottl
782285809Sscottl  discovery = &(onePortContext->discovery);
783285809Sscottl
784285809Sscottl  onePortContext->discovery.type = DM_DISCOVERY_OPTION_FULL_START;
785285809Sscottl  onePortContext->discovery.retries = 0;
786285809Sscottl  onePortContext->discovery.configureRouteRetries = 0;
787285809Sscottl  onePortContext->discovery.deviceRetistrationRetries = 0;
788285809Sscottl  onePortContext->discovery.pendingSMP = 0;
789285809Sscottl  onePortContext->discovery.SeenBC = agFALSE;
790285809Sscottl  onePortContext->discovery.forcedOK = agFALSE;
791285809Sscottl  onePortContext->discovery.SMPRetries = 0;
792285809Sscottl  onePortContext->discovery.DeferredError = agFALSE;
793285809Sscottl  onePortContext->discovery.ConfiguresOthers = agFALSE;
794285809Sscottl  onePortContext->discovery.ResetTriggerred = agFALSE;
795285809Sscottl
796285809Sscottl  /* free expander lists */
797285809Sscottl  dmCleanAllExp(dmRoot, onePortContext);
798285809Sscottl
799285809Sscottl  /* kill the discovery-related timers if they are running */
800285809Sscottl  tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
801285809Sscottl  if (discovery->discoveryTimer.timerRunning == agTRUE)
802285809Sscottl  {
803285809Sscottl    tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
804285809Sscottl    dmKillTimer(
805285809Sscottl                dmRoot,
806285809Sscottl                &discovery->discoveryTimer
807285809Sscottl               );
808285809Sscottl  }
809285809Sscottl  else
810285809Sscottl  {
811285809Sscottl    tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
812285809Sscottl  }
813285809Sscottl
814285809Sscottl
815285809Sscottl  tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
816285809Sscottl  if (discovery->configureRouteTimer.timerRunning == agTRUE)
817285809Sscottl  {
818285809Sscottl    tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
819285809Sscottl    dmKillTimer(
820285809Sscottl                dmRoot,
821285809Sscottl                &discovery->configureRouteTimer
822285809Sscottl               );
823285809Sscottl  }
824285809Sscottl  else
825285809Sscottl  {
826285809Sscottl    tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
827285809Sscottl  }
828285809Sscottl
829285809Sscottl
830285809Sscottl  tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
831285809Sscottl  if (discovery->deviceRegistrationTimer.timerRunning == agTRUE)
832285809Sscottl  {
833285809Sscottl    tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
834285809Sscottl    dmKillTimer(
835285809Sscottl                dmRoot,
836285809Sscottl                &discovery->deviceRegistrationTimer
837285809Sscottl               );
838285809Sscottl  }
839285809Sscottl  else
840285809Sscottl  {
841285809Sscottl    tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
842285809Sscottl  }
843285809Sscottl
844285809Sscottl
845285809Sscottl  tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
846285809Sscottl  if (discovery->BCTimer.timerRunning == agTRUE)
847285809Sscottl  {
848285809Sscottl    tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
849285809Sscottl    dmKillTimer(
850285809Sscottl                dmRoot,
851285809Sscottl                &discovery->BCTimer
852285809Sscottl               );
853285809Sscottl  }
854285809Sscottl  else
855285809Sscottl  {
856285809Sscottl    tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
857285809Sscottl  }
858285809Sscottl
859285809Sscottl
860285809Sscottl  tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
861285809Sscottl  if (discovery->SMPBusyTimer.timerRunning == agTRUE)
862285809Sscottl  {
863285809Sscottl    tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
864285809Sscottl    dmKillTimer(
865285809Sscottl                dmRoot,
866285809Sscottl                &discovery->SMPBusyTimer
867285809Sscottl               );
868285809Sscottl  }
869285809Sscottl  else
870285809Sscottl  {
871285809Sscottl    tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
872285809Sscottl  }
873285809Sscottl
874285809Sscottl
875285809Sscottl  tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
876285809Sscottl  if (discovery->DiscoverySMPTimer.timerRunning == agTRUE)
877285809Sscottl  {
878285809Sscottl    tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
879285809Sscottl    dmKillTimer(
880285809Sscottl                dmRoot,
881285809Sscottl                &discovery->DiscoverySMPTimer
882285809Sscottl               );
883285809Sscottl  }
884285809Sscottl  else
885285809Sscottl  {
886285809Sscottl    tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
887285809Sscottl  }
888285809Sscottl
889285809Sscottl  onePortContext->DiscoveryState = DM_DSTATE_NOT_STARTED;
890285809Sscottl  onePortContext->DiscoveryAbortInProgress = agFALSE;
891285809Sscottl  onePortContext->directAttatchedSAS = agFALSE;
892285809Sscottl  onePortContext->DiscoveryRdyGiven = agFALSE;
893285809Sscottl  onePortContext->SeenLinkUp = agFALSE;
894285809Sscottl
895285809Sscottl  onePortContext->dmPortContext->dmData = agNULL;
896285809Sscottl  onePortContext->dmPortContext = agNULL;
897285809Sscottl  onePortContext->dmRoot = agNULL;
898285809Sscottl
899285809Sscottl  onePortContext->LinkRate = 0;
900285809Sscottl  onePortContext->Count = 0;
901285809Sscottl  onePortContext->valid = agFALSE;
902285809Sscottl  onePortContext->RegisteredDevNums = 0;
903285809Sscottl  onePortContext->eventPhyID = 0xFF;
904285809Sscottl  onePortContext->Transient = agFALSE;
905285809Sscottl
906285809Sscottl  return;
907285809Sscottl}
908285809Sscottl
909285809Sscottl
910285809SscottlosGLOBAL void
911285809SscottldmInitTimers(
912285809Sscottl               dmRoot_t *dmRoot
913285809Sscottl               )
914285809Sscottl{
915285809Sscottl  dmIntRoot_t               *dmIntRoot    = (dmIntRoot_t *)dmRoot->dmData;
916285809Sscottl  dmIntContext_t            *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
917285809Sscottl
918285809Sscottl#ifdef DM_DEBUG_ENABLE
919285809Sscottl  dmIntPortContext_t *dmPortContext = (dmIntPortContext_t *)dmAllShared->PortContextMem;
920285809Sscottl
921285809Sscottl  DM_DBG6(("dmInitTimers: start \n"));
922285809Sscottl  DM_DBG6(("dmInitTimers: ******* tdsaRoot %p \n", dmIntRoot));
923285809Sscottl  DM_DBG6(("dmInitTimers: ******* tdsaPortContext %p \n",dmPortContext));
924285809Sscottl#endif
925285809Sscottl
926285809Sscottl  /* initialize the timerlist */
927285809Sscottl  DMLIST_INIT_HDR(&(dmAllShared->timerlist));
928285809Sscottl
929285809Sscottl  return;
930285809Sscottl}
931285809Sscottl#endif /* FDS_ DM */
932285809Sscottl
933285809Sscottl
934