xref: /freebsd/sys/dev/pms/RefTisa/tisa/sassata/common/tdport.c (revision 7ab1a32cd43cbae61ad4dd435d6a482bbf61cb52)
1 /*******************************************************************************
2 *Copyright (c) 2014 PMC-Sierra, Inc.  All rights reserved.
3 *
4 *Redistribution and use in source and binary forms, with or without modification, are permitted provided
5 *that the following conditions are met:
6 *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
7 *following disclaimer.
8 *2. Redistributions in binary form must reproduce the above copyright notice,
9 *this list of conditions and the following disclaimer in the documentation and/or other materials provided
10 *with the distribution.
11 *
12 *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 *WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 *FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
15 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16 *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
17 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
18 *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19 *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
20 
21 ********************************************************************************/
22 /*******************************************************************************/
23 /** \file
24  *
25  * tdport.c
26  * This file contains port realted functions such as tiCOMPortStart()
27  *
28  */
29 #include <sys/cdefs.h>
30 #include <dev/pms/config.h>
31 
32 #include <dev/pms/freebsd/driver/common/osenv.h>
33 #include <dev/pms/freebsd/driver/common/ostypes.h>
34 #include <dev/pms/freebsd/driver/common/osdebug.h>
35 
36 #include <dev/pms/RefTisa/sallsdk/api/sa.h>
37 #include <dev/pms/RefTisa/sallsdk/api/saapi.h>
38 #include <dev/pms/RefTisa/sallsdk/spc/sadefs.h>
39 #include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
40 
41 #include <dev/pms/RefTisa/tisa/api/titypes.h>
42 #include <dev/pms/RefTisa/tisa/api/ostiapi.h>
43 #include <dev/pms/RefTisa/tisa/api/tiapi.h>
44 #include <dev/pms/RefTisa/tisa/api/tiglobal.h>
45 
46 #ifdef FDS_SM
47 #include <dev/pms/RefTisa/sat/api/sm.h>
48 #include <dev/pms/RefTisa/sat/api/smapi.h>
49 #include <dev/pms/RefTisa/sat/api/tdsmapi.h>
50 #endif
51 
52 #ifdef FDS_DM
53 #include <dev/pms/RefTisa/discovery/api/dm.h>
54 #include <dev/pms/RefTisa/discovery/api/dmapi.h>
55 #include <dev/pms/RefTisa/discovery/api/tddmapi.h>
56 #endif
57 
58 #include <dev/pms/RefTisa/tisa/sassata/sas/common/tdtypes.h>
59 #include <dev/pms/freebsd/driver/common/osstring.h>
60 #include <dev/pms/RefTisa/tisa/sassata/common/tdutil.h>
61 
62 #ifdef INITIATOR_DRIVER
63 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdtypes.h>
64 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itddefs.h>
65 #include <dev/pms/RefTisa/tisa/sassata/sas/ini/itdglobl.h>
66 #endif
67 
68 #ifdef TARGET_DRIVER
69 #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdglobl.h>
70 #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdxchg.h>
71 #include <dev/pms/RefTisa/tisa/sassata/sas/tgt/ttdtypes.h>
72 #endif
73 
74 #include <dev/pms/RefTisa/tisa/sassata/common/tdsatypes.h>
75 #include <dev/pms/RefTisa/tisa/sassata/common/tdproto.h>
76 
77 #ifndef TURN_OFF_HDA
78 #include <dev/pms/RefTisa/sallsdk/hda/64k/aap1img.h> /* SPC HDA */
79 #include <dev/pms/RefTisa/sallsdk/hda/64k/ilaimg.h>
80 #include <dev/pms/RefTisa/sallsdk/hda/64k/iopimg.h>
81 #include <dev/pms/RefTisa/sallsdk/hda/64k/istrimg.h>
82 
83 #include <dev/pms/RefTisa/sallsdk/hda/64k/aap18008.h>	/* SPCv HDA */
84 #include <dev/pms/RefTisa/sallsdk/hda/64k/iop8008.h>
85 
86 #include <dev/pms/RefTisa/sallsdk/hda/64k/ila8008.h> /* Ila common to SPCv SPCvp versions */
87 
88 #include <dev/pms/RefTisa/sallsdk/hda/64k/raae8070.h>	/* SPCv 12g HDA */
89 #include <dev/pms/RefTisa/sallsdk/hda/64k/iop8070.h>
90 #include <dev/pms/RefTisa/sallsdk/hda/64k/ila8070.h> /* Ila 12g  SPCv SPCvp versions */
91 
92 #endif /* TURN_OFF_HDA */
93 
94 
95 bit32 gSSC_Disable = 0;
96 bit32 volatile sgpioResponseSet = 0;
97 
98 #ifdef ECHO_TESTING
99 /* temporary to test saEchoCommand() */
100 bit8 gEcho;
101 #endif
102 bit32 tiCOMConfigureSgpio(
103                         tiRoot_t    *tiRoot,
104                         bit8        enableSgpio
105                         );
106 
107 
108 /*****************************************************************************
109 *! \brief tdsaGetSwConfigParams
110 *
111 *  Purpose:  This function reads software configuration parameters from the
112 *            configuration file
113 *
114 *  \param  tiRoot:            Pointer to driver/port instance.
115 *
116 *  \return: None
117 *
118 *  \note -
119 *
120 *****************************************************************************/
121 osGLOBAL void
122 tdsaGetSwConfigParams(
123                       tiRoot_t *tiRoot
124                       )
125 {
126   tdsaRoot_t     *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
127   tdsaContext_t  *tdsaAllShared = (tdsaContext_t *)&(tdsaRoot->tdsaAllShared);
128   agsaSwConfig_t *SwConfig;
129   agsaQueueConfig_t   *QueueConfig;
130   char           *buffer;
131   bit32          buffLen;
132   bit32          lenRecv = 0;
133   char           *pLastUsedChar = agNULL;
134   char           tmpBuffer[DEFAULT_KEY_BUFFER_SIZE];
135   char           globalStr[]     = "Global";
136   char           iniParmsStr[]   = "InitiatorParms";
137   char           SwParmsStr[]   = "SWParms";
138   char           OBQueueProps[] = "OBQueueProps";
139   char           IBQueueProps[] = "IBQueueProps";
140   char           IBQueueSize[40];
141   char           OBQueueSize[40];
142   char           IBQueueEleSize[40];
143   char           OBQueueEleSize[40];
144   char           OBQueueInterruptCount[40];
145   char           OBQueueInterruptDelay[40];
146   char           OBQueueInterruptEnable[40];
147   char           IBQueuePriority[40];
148   char           *cardNum = tdsaAllShared->CardIDString;
149   bit32          i;
150   bit32          enableDIF;
151   bit32          enableEncryption;
152 #ifdef SA_CONFIG_MDFD_REGISTRY
153   bit32          disableMDF;
154 #endif
155 
156 #ifdef FDS_DM
157   dmSwConfig_t   *dmSwConfig;
158 #endif
159 #ifdef FDS_SM
160   smSwConfig_t   *smSwConfig;
161 #endif
162 
163   TI_DBG6(("tdsaGetSwConfigParams: start\n"));
164   TI_DBG6(("tdsaGetSwConfigParams: tdsaRoot %p tdsaAllShared %p \n",tdsaRoot, tdsaAllShared));
165 
166   buffer = tmpBuffer;
167   buffLen = sizeof(tmpBuffer);
168 
169   osti_memset(buffer, 0, buffLen);
170 
171   /* the followings are the default values */
172   SwConfig = (agsaSwConfig_t *)&(tdsaAllShared->SwConfig);
173   QueueConfig = (agsaQueueConfig_t *)&(tdsaAllShared->QueueConfig);
174 
175 #ifdef FDS_DM
176   dmSwConfig = (dmSwConfig_t *)&(tdsaAllShared->dmSwConfig);
177 #endif
178 #ifdef FDS_SM
179   smSwConfig = (smSwConfig_t *)&(tdsaAllShared->smSwConfig);
180 #endif
181 
182   /*
183     just default values
184     and are overwritten later by the configuration file contents
185   */
186   SwConfig->numDevHandles = DEFAULT_MAX_DEV;
187 
188   SwConfig->maxActiveIOs = DEFAULT_MAX_ACTIVE_IOS;
189   SwConfig->smpReqTimeout = DEFAULT_SMP_TIMEOUT; /* DEFAULT_VALUE; */
190   SwConfig->numberOfEventRegClients = DEFAULT_NUM_REG_CLIENTS;
191   SwConfig->sizefEventLog1 = HOST_EVENT_LOG_SIZE;
192   SwConfig->sizefEventLog2 = HOST_EVENT_LOG_SIZE;
193   SwConfig->eventLog1Option = DEFAULT_EVENT_LOG_OPTION;
194   SwConfig->eventLog2Option = DEFAULT_EVENT_LOG_OPTION;
195   SwConfig->fatalErrorInterruptEnable = 1;
196   SwConfig->fatalErrorInterruptVector = 0; /* Was 1 */
197   SwConfig->hostDirectAccessSupport = 0;
198   SwConfig->hostDirectAccessMode = 0;
199   SwConfig->FWConfig = 0;
200   SwConfig->enableDIF = agFALSE;
201   SwConfig->enableEncryption = agFALSE;
202 
203 #ifdef SA_CONFIG_MDFD_REGISTRY
204   SwConfig->disableMDF = agFALSE;
205 #endif
206 
207   SwConfig->param1 = tdsaAllShared->tdDeviceIdVendId;
208   SwConfig->param2 = tdsaAllShared->tdSubVendorId;
209 
210 
211 #if defined(SALLSDK_DEBUG)
212   SwConfig->sallDebugLevel = 1; /* DEFAULT_VALUE; */
213 #endif
214 #if defined(DM_DEBUG)
215   dmSwConfig->DMDebugLevel = 1; /* DEFAULT_VALUE; */
216 #endif
217 #if defined(SM_DEBUG)
218   smSwConfig->SMDebugLevel = 1; /* DEFAULT_VALUE; */
219 #endif
220 
221   tdsaAllShared->portTMO = PORT_RECOVERY_TIMEOUT;   /* default 5 sec */
222   tdsaAllShared->stp_idle_time = STP_IDLE_TIME;     /* default 5 us */
223   tdsaAllShared->itNexusTimeout = IT_NEXUS_TIMEOUT; /* default 2000 ms */
224 
225   osti_memset(buffer, 0, buffLen);
226   lenRecv = 0;
227 
228   if ((ostiGetTransportParam(
229                              tiRoot,
230                              globalStr,
231                              iniParmsStr,
232                              agNULL,
233                              agNULL,
234                              agNULL,
235                              agNULL,
236                              "MaxTargets",
237                              buffer,
238                              buffLen,
239                              &lenRecv
240                              ) == tiSuccess) && (lenRecv != 0))
241   {
242     if (osti_strncmp(buffer, "0x", 2) == 0)
243     {
244       SwConfig->numDevHandles = osti_strtoul (buffer, &pLastUsedChar, 0);
245     }
246     else
247     {
248       SwConfig->numDevHandles = osti_strtoul (buffer, &pLastUsedChar, 10);
249     }
250     TI_DBG2(("tdsaGetSwConfigParams: MaxTargets  %d\n",SwConfig->numDevHandles  ));
251   }
252 
253   /*
254    * read the NumInboundQueue parameter
255    */
256   osti_memset(buffer, 0, buffLen);
257   lenRecv = 0;
258 
259   QueueConfig->numInboundQueues = DEFAULT_NUM_INBOUND_QUEUE;  /* default 1 Inbound queue */
260 
261   if ((ostiGetTransportParam(
262                              tiRoot,
263                              globalStr,   /* key */
264                              SwParmsStr,  /* subkey1 */
265                              agNULL,      /* subkey2 */
266                              agNULL,
267                              agNULL,
268                              agNULL,      /* subkey5 */
269                              "NumInboundQueues", /* valueName */
270                              buffer,
271                              buffLen,
272                              &lenRecv
273                              ) == tiSuccess) && (lenRecv != 0))
274   {
275     if (osti_strncmp(buffer, "0x", 2) == 0)
276     {
277       QueueConfig->numInboundQueues = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
278     }
279     else
280     {
281       QueueConfig->numInboundQueues = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
282     }
283 
284     if (QueueConfig->numInboundQueues > AGSA_MAX_INBOUND_Q)
285     {
286       QueueConfig->numInboundQueues = AGSA_MAX_INBOUND_Q;
287     }
288   }
289 
290   /*
291    * read the NumOutboundQueue parameter
292    */
293   osti_memset(buffer, 0, buffLen);
294   lenRecv = 0;
295 
296   QueueConfig->numOutboundQueues = DEFAULT_NUM_OUTBOUND_QUEUE;  /* default 1 Outbound queue */
297 
298   if ((ostiGetTransportParam(
299                              tiRoot,
300                              globalStr,   /* key */
301                              SwParmsStr,  /* subkey1 */
302                              agNULL,      /* subkey2 */
303                              agNULL,
304                              agNULL,
305                              agNULL,      /* subkey5 */
306                              "NumOutboundQueues", /* valueName */
307                              buffer,
308                              buffLen,
309                              &lenRecv
310                              ) == tiSuccess) && (lenRecv != 0))
311   {
312     if (osti_strncmp(buffer, "0x", 2) == 0)
313     {
314       QueueConfig->numOutboundQueues = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
315     }
316     else
317     {
318       QueueConfig->numOutboundQueues = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
319     }
320 
321     if (QueueConfig->numOutboundQueues > AGSA_MAX_OUTBOUND_Q)
322     {
323       QueueConfig->numOutboundQueues = AGSA_MAX_OUTBOUND_Q;
324     }
325   }
326 
327   /*
328    * read the outbound queue option
329    */
330 
331   osti_memset(buffer, 0, buffLen);
332   lenRecv = 0;
333 
334   tdsaAllShared->QueueOption = DEFAULT_QUEUE_OPTION;  /* default 0 Outbound queue element */
335 
336   if ((ostiGetTransportParam(
337                              tiRoot,
338                              globalStr,   /* key */
339                              SwParmsStr,  /* subkey1 */
340                              agNULL,      /* subkey2 */
341                              agNULL,
342                              agNULL,
343                              agNULL,      /* subkey5 */
344                              "QueueOption", /* valueName */
345                              buffer,
346                              buffLen,
347                              &lenRecv
348                              ) == tiSuccess) && (lenRecv != 0))
349   {
350     if (osti_strncmp(buffer, "0x", 2) == 0)
351     {
352       tdsaAllShared->QueueOption = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
353     }
354     else
355     {
356       tdsaAllShared->QueueOption = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
357     }
358   }
359 
360   /*
361    * read the MaxActiveIO parameter
362    */
363 
364   osti_memset(buffer, 0, buffLen);
365   lenRecv = 0;
366 
367   if ((ostiGetTransportParam(
368                              tiRoot,
369                              globalStr,   /* key */
370                              SwParmsStr,  /* subkey1 */
371                              agNULL,      /* subkey2 */
372                              agNULL,
373                              agNULL,
374                              agNULL,      /* subkey5 */
375                              "MaxActiveIO", /* valueName */
376                              buffer,
377                              buffLen,
378                              &lenRecv
379                              ) == tiSuccess) && (lenRecv != 0))
380   {
381     if (osti_strncmp(buffer, "0x", 2) == 0)
382     {
383       SwConfig->maxActiveIOs = osti_strtoul (buffer, &pLastUsedChar, 0);
384       TI_DBG6(("tdsaGetSwConfigParams: maxactiveio 1 !!!\n"));
385     }
386     else
387     {
388       SwConfig->maxActiveIOs = osti_strtoul (buffer, &pLastUsedChar, 10);
389       TI_DBG6(("tdsaGetSwConfigParams: maxactiveio 2 !!!\n"));
390     }
391     TI_DBG6(("tdsaGetSwConfigParams: maxactiveio 3 !!!\n"));
392   }
393 
394 
395 
396   /*
397    * read the SMPTO parameter (SMP Timeout)
398    */
399   osti_memset(buffer, 0, buffLen);
400   lenRecv = 0;
401 
402   if ((ostiGetTransportParam(
403                              tiRoot,
404                              globalStr,   /* key */
405                              SwParmsStr,  /* subkey1 */
406                              agNULL,      /* subkey2 */
407                              agNULL,
408                              agNULL,
409                              agNULL,      /* subkey5 */
410                              "SMPTO", /* valueName */
411                              buffer,
412                              buffLen,
413                              &lenRecv
414                              ) == tiSuccess) && (lenRecv != 0))
415   {
416     if (osti_strncmp(buffer, "0x", 2) == 0)
417     {
418       SwConfig->smpReqTimeout = osti_strtoul (buffer, &pLastUsedChar, 0);
419     }
420     else
421     {
422       SwConfig->smpReqTimeout = osti_strtoul (buffer, &pLastUsedChar, 10);
423     }
424   }
425 
426 
427   /*
428    * read the NumRegClients parameter (SMP Timeout)
429    */
430   osti_memset(buffer, 0, buffLen);
431   lenRecv = 0;
432 
433   if ((ostiGetTransportParam(
434                              tiRoot,
435                              globalStr,   /* key */
436                              SwParmsStr,  /* subkey1 */
437                              agNULL,      /* subkey2 */
438                              agNULL,
439                              agNULL,
440                              agNULL,      /* subkey5 */
441                              "NumRegClients", /* valueName */
442                              buffer,
443                              buffLen,
444                              &lenRecv
445                              ) == tiSuccess) && (lenRecv != 0))
446   {
447     if (osti_strncmp(buffer, "0x", 2) == 0)
448     {
449       SwConfig->numberOfEventRegClients = osti_strtoul (buffer, &pLastUsedChar, 0);
450     }
451     else
452     {
453       SwConfig->numberOfEventRegClients = osti_strtoul (buffer, &pLastUsedChar, 10);
454     }
455   }
456 
457 #if defined(SALLSDK_DEBUG)
458   osti_memset(buffer, 0, buffLen);
459   lenRecv = 0;
460 
461   if ((ostiGetTransportParam(
462                              tiRoot,
463                              globalStr,   /* key */
464                              SwParmsStr,  /* subkey1 */
465                              agNULL,      /* subkey2 */
466                              agNULL,
467                              agNULL,
468                              agNULL,      /* subkey5 */
469                              "LLDebugLevel", /* valueName */
470                              buffer,
471                              buffLen,
472                              &lenRecv
473                              ) == tiSuccess) && (lenRecv != 0))
474   {
475     if (osti_strncmp(buffer, "0x", 2) == 0)
476     {
477       SwConfig->sallDebugLevel = osti_strtoul (buffer, &pLastUsedChar, 0);
478     }
479     else
480     {
481       SwConfig->sallDebugLevel = osti_strtoul (buffer, &pLastUsedChar, 10);
482     }
483   }
484 #endif
485 
486 #if defined(DM_DEBUG)
487   osti_memset(buffer, 0, buffLen);
488   lenRecv = 0;
489 
490   if ((ostiGetTransportParam(
491                              tiRoot,
492                              globalStr,   /* key */
493                              SwParmsStr,  /* subkey1 */
494                              agNULL,      /* subkey2 */
495                              agNULL,
496                              agNULL,
497                              agNULL,      /* subkey5 */
498                              "DMDebugLevel", /* valueName */
499                              buffer,
500                              buffLen,
501                              &lenRecv
502                              ) == tiSuccess) && (lenRecv != 0))
503   {
504     if (osti_strncmp(buffer, "0x", 2) == 0)
505     {
506       dmSwConfig->DMDebugLevel = osti_strtoul (buffer, &pLastUsedChar, 0);
507     }
508     else
509     {
510       dmSwConfig->DMDebugLevel = osti_strtoul (buffer, &pLastUsedChar, 10);
511     }
512   }
513 #endif
514 
515 #if defined(SM_DEBUG)
516   osti_memset(buffer, 0, buffLen);
517   lenRecv = 0;
518 
519   if ((ostiGetTransportParam(
520                              tiRoot,
521                              globalStr,   /* key */
522                              SwParmsStr,  /* subkey1 */
523                              agNULL,      /* subkey2 */
524                              agNULL,
525                              agNULL,
526                              agNULL,      /* subkey5 */
527                              "SMDebugLevel", /* valueName */
528                              buffer,
529                              buffLen,
530                              &lenRecv
531                              ) == tiSuccess) && (lenRecv != 0))
532   {
533     if (osti_strncmp(buffer, "0x", 2) == 0)
534     {
535       smSwConfig->SMDebugLevel = osti_strtoul (buffer, &pLastUsedChar, 0);
536     }
537     else
538     {
539       smSwConfig->SMDebugLevel = osti_strtoul (buffer, &pLastUsedChar, 10);
540     }
541   }
542 #endif
543 
544   osti_memset(buffer, 0, buffLen);
545   lenRecv = 0;
546 
547   for (i=0;i<QueueConfig->numInboundQueues;i++)
548   {
549     osti_sprintf(IBQueueSize,"IBQueueNumElements%d", i);
550     osti_sprintf(IBQueueEleSize,"IBQueueElementSize%d", i);
551     osti_sprintf(IBQueuePriority,"IBQueuePriority%d", i);
552 
553     /*
554      * read the IBQueueSize
555      */
556 
557     osti_memset(buffer, 0, buffLen);
558     lenRecv = 0;
559 
560     tdsaAllShared->InboundQueueSize[i] = DEFAULT_INBOUND_QUEUE_SIZE;  /* default 256 Inbound queue size */
561 
562     if ((ostiGetTransportParam(
563                              tiRoot,
564                              globalStr,   /* key */
565                              SwParmsStr,  /* subkey1 */
566                              IBQueueProps,/* subkey2 */
567                              agNULL,
568                              agNULL,
569                              agNULL,      /* subkey5 */
570                              IBQueueSize, /* valueName */
571                              buffer,
572                              buffLen,
573                              &lenRecv
574                              ) == tiSuccess) && (lenRecv != 0))
575     {
576       if (osti_strncmp(buffer, "0x", 2) == 0)
577       {
578         tdsaAllShared->InboundQueueSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
579       }
580       else
581       {
582         tdsaAllShared->InboundQueueSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
583         TI_DBG6(("tdsaGetSwConfigParams: queue number %d IB queue size %d\n", i, tdsaAllShared->InboundQueueSize[i]));
584       }
585     }
586 
587 
588     /*
589      * read the IBQueueEleSize
590      */
591 
592     osti_memset(buffer, 0, buffLen);
593     lenRecv = 0;
594 
595     tdsaAllShared->InboundQueueEleSize[i] = DEFAULT_INBOUND_QUEUE_ELE_SIZE;  /* default 128 Inbound queue element */
596 
597     if ((ostiGetTransportParam(
598                              tiRoot,
599                              globalStr,   /* key */
600                              SwParmsStr,  /* subkey1 */
601                              IBQueueProps,/* subkey2 */
602                              agNULL,
603                              agNULL,
604                              agNULL,      /* subkey5 */
605                              IBQueueEleSize, /* valueName */
606                              buffer,
607                              buffLen,
608                              &lenRecv
609                              ) == tiSuccess) && (lenRecv != 0))
610     {
611       if (osti_strncmp(buffer, "0x", 2) == 0)
612       {
613         tdsaAllShared->InboundQueueEleSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
614       }
615       else
616       {
617         tdsaAllShared->InboundQueueEleSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
618         TI_DBG6(("tdsaGetSwConfigParams: queue number %d IB queue ele size %d\n", i, tdsaAllShared->InboundQueueEleSize[i]));
619       }
620     }
621 
622     /*
623      * read the IBQueuePriority
624      */
625 
626     osti_memset(buffer, 0, buffLen);
627     lenRecv = 0;
628 
629     tdsaAllShared->InboundQueuePriority[i] = DEFAULT_INBOUND_QUEUE_PRIORITY; /* default 0 Inbound queue priority */
630 
631     if ((ostiGetTransportParam(
632                              tiRoot,
633                              globalStr,   /* key */
634                              SwParmsStr,  /* subkey1 */
635                              IBQueueProps,/* subkey2 */
636                              agNULL,
637                              agNULL,
638                              agNULL,      /* subkey5 */
639                              IBQueuePriority, /* valueName */
640                              buffer,
641                              buffLen,
642                              &lenRecv
643                              ) == tiSuccess) && (lenRecv != 0))
644     {
645       if (osti_strncmp(buffer, "0x", 2) == 0)
646       {
647         tdsaAllShared->InboundQueuePriority[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
648       }
649       else
650       {
651         tdsaAllShared->InboundQueuePriority[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
652         TI_DBG6(("tdsaGetSwConfigParams: queue number %d priority %d\n", i, tdsaAllShared->InboundQueuePriority[i]));
653       }
654     }
655 
656     /**********************************************/
657     osti_memset(buffer, 0, buffLen);
658     lenRecv = 0;
659   }/* end of loop */
660 
661 
662 
663   osti_memset(buffer, 0, buffLen);
664   lenRecv = 0;
665 
666   for (i=0;i<QueueConfig->numOutboundQueues;i++)
667   {
668     osti_sprintf(OBQueueSize,"OBQueueNumElements%d", i);
669     osti_sprintf(OBQueueEleSize,"OBQueueElementSize%d", i);
670     osti_sprintf(OBQueueInterruptDelay,"OBQueueInterruptDelay%d", i);
671     osti_sprintf(OBQueueInterruptCount,"OBQueueInterruptCount%d", i);
672     osti_sprintf(OBQueueInterruptEnable,"OBQueueInterruptEnable%d", i);
673 
674     /*
675      * read the OBQueueSize
676      */
677     osti_memset(buffer, 0, buffLen);
678     lenRecv = 0;
679 
680 
681     tdsaAllShared->OutboundQueueSize[i] = DEFAULT_OUTBOUND_QUEUE_SIZE;  /* default 256 Outbound queue size */
682 
683     if ((ostiGetTransportParam(
684                              tiRoot,
685                              globalStr,   /* key */
686                              SwParmsStr,  /* subkey1 */
687                              OBQueueProps,      /* subkey2 */
688                              agNULL,
689                              agNULL,
690                              agNULL,      /* subkey5 */
691                              OBQueueSize, /* valueName */
692                              buffer,
693                              buffLen,
694                              &lenRecv
695                              ) == tiSuccess) && (lenRecv != 0))
696     {
697       if (osti_strncmp(buffer, "0x", 2) == 0)
698       {
699         tdsaAllShared->OutboundQueueSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
700       }
701       else
702       {
703         tdsaAllShared->OutboundQueueSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
704         TI_DBG6(("tdsaGetSwConfigParams: queue number %d OB queue size %d\n", i, tdsaAllShared->OutboundQueueSize[i]));
705 
706       }
707     }
708 
709 
710     /*
711      * read the OBQueueEleSize
712      */
713     osti_memset(buffer, 0, buffLen);
714     lenRecv = 0;
715 
716 
717     tdsaAllShared->OutboundQueueEleSize[i] = DEFAULT_OUTBOUND_QUEUE_ELE_SIZE;  /* default 128 Outbound queue element */
718 
719     if ((ostiGetTransportParam(
720                              tiRoot,
721                              globalStr,   /* key */
722                              SwParmsStr,  /* subkey1 */
723                              OBQueueProps,      /* subkey2 */
724                              agNULL,
725                              agNULL,
726                              agNULL,      /* subkey5 */
727                              OBQueueEleSize, /* valueName */
728                              buffer,
729                              buffLen,
730                              &lenRecv
731                              ) == tiSuccess) && (lenRecv != 0))
732     {
733       if (osti_strncmp(buffer, "0x", 2) == 0)
734       {
735         tdsaAllShared->OutboundQueueEleSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
736       }
737       else
738       {
739         tdsaAllShared->OutboundQueueEleSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
740         TI_DBG6(("tdsaGetSwConfigParams: queue number %d OB queue ele size %d\n", i, tdsaAllShared->OutboundQueueEleSize[i]));
741 
742       }
743     }
744 
745 
746     /*
747      * read the OBQueueInterruptDelay
748      */
749     osti_memset(buffer, 0, buffLen);
750     lenRecv = 0;
751 
752 
753     tdsaAllShared->OutboundQueueInterruptDelay[i] = DEFAULT_OUTBOUND_QUEUE_INTERRUPT_DELAY;  /* default 1 Outbound interrupt delay */
754 
755     if ((ostiGetTransportParam(
756                              tiRoot,
757                              globalStr,   /* key */
758                              SwParmsStr,  /* subkey1 */
759                              OBQueueProps,      /* subkey2 */
760                              agNULL,
761                              agNULL,
762                              agNULL,      /* subkey5 */
763                              OBQueueInterruptDelay, /* valueName */
764                              buffer,
765                              buffLen,
766                              &lenRecv
767                              ) == tiSuccess) && (lenRecv != 0))
768     {
769       if (osti_strncmp(buffer, "0x", 2) == 0)
770       {
771         tdsaAllShared->OutboundQueueInterruptDelay[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
772       }
773       else
774       {
775         tdsaAllShared->OutboundQueueInterruptDelay[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
776         TI_DBG6(("tdsaGetSwConfigParams: queue number %d interrupt delay %d\n", i, tdsaAllShared->OutboundQueueInterruptDelay[i]));
777 
778       }
779     }
780 
781     /*
782      * read the OBQueueInterruptCount
783      */
784 
785     osti_memset(buffer, 0, buffLen);
786     lenRecv = 0;
787 
788     tdsaAllShared->OutboundQueueInterruptCount[i] = DEFAULT_OUTBOUND_QUEUE_INTERRUPT_COUNT;  /* default 1 Outbound interrupt count */
789 
790     if ((ostiGetTransportParam(
791                              tiRoot,
792                              globalStr,   /* key */
793                              SwParmsStr,  /* subkey1 */
794                              OBQueueProps,      /* subkey2 */
795                              agNULL,
796                              agNULL,
797                              agNULL,      /* subkey5 */
798                              OBQueueInterruptCount, /* valueName */
799                              buffer,
800                              buffLen,
801                              &lenRecv
802                              ) == tiSuccess) && (lenRecv != 0))
803     {
804       if (osti_strncmp(buffer, "0x", 2) == 0)
805       {
806         tdsaAllShared->OutboundQueueInterruptCount[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
807       }
808       else
809       {
810         tdsaAllShared->OutboundQueueInterruptCount[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
811         TI_DBG6(("tdsaGetSwConfigParams: queue number %d interrupt count %d\n", i, tdsaAllShared->OutboundQueueInterruptCount[i]));
812       }
813     }
814 
815 
816     /*
817      * read the OBQueueInterruptEnable
818      */
819 
820     osti_memset(buffer, 0, buffLen);
821     lenRecv = 0;
822 
823     tdsaAllShared->OutboundQueueInterruptEnable[i] = DEFAULT_OUTBOUND_INTERRUPT_ENABLE;  /* default 1 Outbound interrupt is enabled */
824 
825     if ((ostiGetTransportParam(
826                              tiRoot,
827                              globalStr,   /* key */
828                              SwParmsStr,  /* subkey1 */
829                              OBQueueProps,      /* subkey2 */
830                              agNULL,
831                              agNULL,
832                              agNULL,      /* subkey5 */
833                              OBQueueInterruptEnable, /* valueName */
834                              buffer,
835                              buffLen,
836                              &lenRecv
837                              ) == tiSuccess) && (lenRecv != 0))
838     {
839       if (osti_strncmp(buffer, "0x", 2) == 0)
840       {
841         tdsaAllShared->OutboundQueueInterruptEnable[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
842       }
843       else
844       {
845         tdsaAllShared->OutboundQueueInterruptEnable[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
846         TI_DBG6(("tdsaGetSwConfigParams: queue number %d interrupt enable %d\n", i, tdsaAllShared->OutboundQueueInterruptEnable[i]));
847       }
848     }
849 
850     /**********************************************/
851     osti_memset(buffer, 0, buffLen);
852     lenRecv = 0;
853 
854   }/* end of loop */
855 
856 
857 
858   /********************READ CARD SPECIFIC *******************************************************/
859 
860   osti_memset(buffer, 0, buffLen);
861   lenRecv = 0;
862 
863   for (i=0;i<QueueConfig->numInboundQueues;i++)
864   {
865     osti_sprintf(IBQueueSize,"IBQueueNumElements%d", i);
866     osti_sprintf(IBQueueEleSize,"IBQueueElementSize%d", i);
867     osti_sprintf(IBQueuePriority,"IBQueuePriority%d", i);
868 
869     /*
870      * read the IBQueueSize
871      */
872 
873     osti_memset(buffer, 0, buffLen);
874     lenRecv = 0;
875 
876     if ((ostiGetTransportParam(
877                              tiRoot,
878                              cardNum,   /* key */
879                              SwParmsStr,  /* subkey1 */
880                              IBQueueProps,/* subkey2 */
881                              agNULL,
882                              agNULL,
883                              agNULL,      /* subkey5 */
884                              IBQueueSize, /* valueName */
885                              buffer,
886                              buffLen,
887                              &lenRecv
888                              ) == tiSuccess) && (lenRecv != 0))
889     {
890       if (osti_strncmp(buffer, "0x", 2) == 0)
891       {
892         tdsaAllShared->InboundQueueSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
893       }
894       else
895       {
896         tdsaAllShared->InboundQueueSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
897         TI_DBG6(("tdsaGetSwConfigParams: queue number %d IB queue size %d\n", i, tdsaAllShared->InboundQueueSize[i]));
898       }
899     }
900 
901     /*
902      * read the IBQueueEleSize
903      */
904 
905     osti_memset(buffer, 0, buffLen);
906     lenRecv = 0;
907 
908     if ((ostiGetTransportParam(
909                              tiRoot,
910                              cardNum,   /* key */
911                              SwParmsStr,  /* subkey1 */
912                              IBQueueProps,/* subkey2 */
913                              agNULL,
914                              agNULL,
915                              agNULL,      /* subkey5 */
916                              IBQueueEleSize, /* valueName */
917                              buffer,
918                              buffLen,
919                              &lenRecv
920                              ) == tiSuccess) && (lenRecv != 0))
921     {
922       if (osti_strncmp(buffer, "0x", 2) == 0)
923       {
924         tdsaAllShared->InboundQueueEleSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
925       }
926       else
927       {
928         tdsaAllShared->InboundQueueEleSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
929         TI_DBG6(("tdsaGetSwConfigParams: queue number %d IB queue ele size %d\n", i, tdsaAllShared->InboundQueueEleSize[i]));
930       }
931     }
932 
933     /*
934      * read the IBQueuePriority
935      */
936 
937     osti_memset(buffer, 0, buffLen);
938     lenRecv = 0;
939 
940     if ((ostiGetTransportParam(
941                              tiRoot,
942                              cardNum,   /* key */
943                              SwParmsStr,  /* subkey1 */
944                              IBQueueProps,/* subkey2 */
945                              agNULL,
946                              agNULL,
947                              agNULL,      /* subkey5 */
948                              IBQueuePriority, /* valueName */
949                              buffer,
950                              buffLen,
951                              &lenRecv
952                              ) == tiSuccess) && (lenRecv != 0))
953     {
954       if (osti_strncmp(buffer, "0x", 2) == 0)
955       {
956         tdsaAllShared->InboundQueuePriority[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
957       }
958       else
959       {
960         tdsaAllShared->InboundQueuePriority[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
961         TI_DBG6(("tdsaGetSwConfigParams: card number %s queue number %d priority %d\n", cardNum, i, tdsaAllShared->InboundQueuePriority[i]));
962       }
963     }
964 
965     /**********************************************/
966     osti_memset(buffer, 0, buffLen);
967     lenRecv = 0;
968   }/* end of loop */
969 
970 
971 
972   osti_memset(buffer, 0, buffLen);
973   lenRecv = 0;
974 
975   for (i=0;i<QueueConfig->numOutboundQueues;i++)
976   {
977     osti_sprintf(OBQueueSize,"OBQueueNumElements%d", i);
978     osti_sprintf(OBQueueEleSize,"OBQueueElementSize%d", i);
979     osti_sprintf(OBQueueInterruptDelay,"OBQueueInterruptDelay%d", i);
980     osti_sprintf(OBQueueInterruptCount,"OBQueueInterruptCount%d", i);
981     osti_sprintf(OBQueueInterruptEnable,"OBQueueInterruptEnable%d", i);
982 
983     /*
984      * read the OBQueueSize
985      */
986     osti_memset(buffer, 0, buffLen);
987     lenRecv = 0;
988 
989     if ((ostiGetTransportParam(
990                              tiRoot,
991                              cardNum,   /* key */
992                              SwParmsStr,  /* subkey1 */
993                              OBQueueProps,      /* subkey2 */
994                              agNULL,
995                              agNULL,
996                              agNULL,      /* subkey5 */
997                              OBQueueSize, /* valueName */
998                              buffer,
999                              buffLen,
1000                              &lenRecv
1001                              ) == tiSuccess) && (lenRecv != 0))
1002     {
1003       if (osti_strncmp(buffer, "0x", 2) == 0)
1004       {
1005         tdsaAllShared->OutboundQueueSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
1006       }
1007       else
1008       {
1009         tdsaAllShared->OutboundQueueSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
1010         TI_DBG6(("tdsaGetSwConfigParams: queue number %d OB queue size %d\n", i, tdsaAllShared->OutboundQueueSize[i]));
1011 
1012       }
1013     }
1014 
1015     /*
1016      * read the OBQueueEleSize
1017      */
1018     osti_memset(buffer, 0, buffLen);
1019     lenRecv = 0;
1020 
1021 
1022     if ((ostiGetTransportParam(
1023                              tiRoot,
1024                              cardNum,   /* key */
1025                              SwParmsStr,  /* subkey1 */
1026                              OBQueueProps,      /* subkey2 */
1027                              agNULL,
1028                              agNULL,
1029                              agNULL,      /* subkey5 */
1030                              OBQueueEleSize, /* valueName */
1031                              buffer,
1032                              buffLen,
1033                              &lenRecv
1034                              ) == tiSuccess) && (lenRecv != 0))
1035     {
1036       if (osti_strncmp(buffer, "0x", 2) == 0)
1037       {
1038         tdsaAllShared->OutboundQueueEleSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
1039       }
1040       else
1041       {
1042         tdsaAllShared->OutboundQueueEleSize[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
1043         TI_DBG6(("tdsaGetSwConfigParams: queue number %d OB queue ele size %d\n", i, tdsaAllShared->OutboundQueueEleSize[i]));
1044 
1045       }
1046     }
1047 
1048     /*
1049      * read the OBQueueInterruptDelay
1050      */
1051     osti_memset(buffer, 0, buffLen);
1052     lenRecv = 0;
1053 
1054 
1055     if ((ostiGetTransportParam(
1056                              tiRoot,
1057                              cardNum,   /* key */
1058                              SwParmsStr,  /* subkey1 */
1059                              OBQueueProps,      /* subkey2 */
1060                              agNULL,
1061                              agNULL,
1062                              agNULL,      /* subkey5 */
1063                              OBQueueInterruptDelay, /* valueName */
1064                              buffer,
1065                              buffLen,
1066                              &lenRecv
1067                              ) == tiSuccess) && (lenRecv != 0))
1068     {
1069       if (osti_strncmp(buffer, "0x", 2) == 0)
1070       {
1071         tdsaAllShared->OutboundQueueInterruptDelay[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
1072       }
1073       else
1074       {
1075         tdsaAllShared->OutboundQueueInterruptDelay[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
1076         TI_DBG6(("tdsaGetSwConfigParams: card number %s queue number %d interrupt delay %d\n", cardNum, i, tdsaAllShared->OutboundQueueInterruptDelay[i]));
1077 
1078       }
1079     }
1080 
1081     /*
1082      * read the OBQueueInterruptCount
1083      */
1084 
1085     osti_memset(buffer, 0, buffLen);
1086     lenRecv = 0;
1087 
1088     if ((ostiGetTransportParam(
1089                              tiRoot,
1090                              cardNum,   /* key */
1091                              SwParmsStr,  /* subkey1 */
1092                              OBQueueProps,      /* subkey2 */
1093                              agNULL,
1094                              agNULL,
1095                              agNULL,      /* subkey5 */
1096                              OBQueueInterruptCount, /* valueName */
1097                              buffer,
1098                              buffLen,
1099                              &lenRecv
1100                              ) == tiSuccess) && (lenRecv != 0))
1101     {
1102       if (osti_strncmp(buffer, "0x", 2) == 0)
1103       {
1104         tdsaAllShared->OutboundQueueInterruptCount[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
1105       }
1106       else
1107       {
1108         tdsaAllShared->OutboundQueueInterruptCount[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
1109         TI_DBG6(("tdsaGetSwConfigParams: card number %s queue number %d interrupt count %d\n", cardNum, i, tdsaAllShared->OutboundQueueInterruptCount[i]));
1110       }
1111     }
1112 
1113 
1114     /*
1115      * read the OBQueueInterruptEnable
1116      */
1117 
1118     osti_memset(buffer, 0, buffLen);
1119     lenRecv = 0;
1120 
1121     if ((ostiGetTransportParam(
1122                              tiRoot,
1123                              cardNum,   /* key */
1124                              SwParmsStr,  /* subkey1 */
1125                              OBQueueProps,      /* subkey2 */
1126                              agNULL,
1127                              agNULL,
1128                              agNULL,      /* subkey5 */
1129                              OBQueueInterruptEnable, /* valueName */
1130                              buffer,
1131                              buffLen,
1132                              &lenRecv
1133                              ) == tiSuccess) && (lenRecv != 0))
1134     {
1135       if (osti_strncmp(buffer, "0x", 2) == 0)
1136       {
1137         tdsaAllShared->OutboundQueueInterruptEnable[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 0);
1138       }
1139       else
1140       {
1141         tdsaAllShared->OutboundQueueInterruptEnable[i] = (bit16) osti_strtoul (buffer, &pLastUsedChar, 10);
1142         TI_DBG6(("tdsaGetSwConfigParams: card number %s queue number %d interrupt enable %d\n", cardNum, i, tdsaAllShared->OutboundQueueInterruptEnable[i]));
1143       }
1144     }
1145 
1146 
1147     /**********************************************/
1148     osti_memset(buffer, 0, buffLen);
1149     lenRecv = 0;
1150 
1151   }/* end of loop */
1152 
1153   /* process event log related parameters */
1154   osti_memset(buffer, 0, buffLen);
1155   lenRecv = 0;
1156 
1157   if ((ostiGetTransportParam(
1158                              tiRoot,
1159                              globalStr,   /* key */
1160                              SwParmsStr,  /* subkey1 */
1161                              agNULL,      /* subkey2 */
1162                              agNULL,
1163                              agNULL,
1164                              agNULL,      /* subkey5 */
1165                              "EventLogSize1", /* valueName */
1166                              buffer,
1167                              buffLen,
1168                              &lenRecv
1169                              ) == tiSuccess) && (lenRecv != 0))
1170   {
1171     if (osti_strncmp(buffer, "0x", 2) == 0)
1172     {
1173       SwConfig->sizefEventLog1 = osti_strtoul (buffer, &pLastUsedChar, 0);
1174     }
1175     else
1176     {
1177       SwConfig->sizefEventLog1 = osti_strtoul (buffer, &pLastUsedChar, 10);
1178     }
1179   }
1180 
1181   osti_memset(buffer, 0, buffLen);
1182   lenRecv = 0;
1183 
1184   if ((ostiGetTransportParam(
1185                              tiRoot,
1186                              globalStr,   /* key */
1187                              SwParmsStr,  /* subkey1 */
1188                              agNULL,      /* subkey2 */
1189                              agNULL,
1190                              agNULL,
1191                              agNULL,      /* subkey5 */
1192                              "EventLogOption1", /* valueName */
1193                              buffer,
1194                              buffLen,
1195                              &lenRecv
1196                              ) == tiSuccess) && (lenRecv != 0))
1197   {
1198     if (osti_strncmp(buffer, "0x", 2) == 0)
1199     {
1200       SwConfig->eventLog1Option = osti_strtoul (buffer, &pLastUsedChar, 0);
1201     }
1202     else
1203     {
1204       SwConfig->eventLog1Option = osti_strtoul (buffer, &pLastUsedChar, 10);
1205     }
1206   }
1207 
1208   osti_memset(buffer, 0, buffLen);
1209   lenRecv = 0;
1210 
1211   if ((ostiGetTransportParam(
1212                              tiRoot,
1213                              globalStr,   /* key */
1214                              SwParmsStr,  /* subkey1 */
1215                              agNULL,      /* subkey2 */
1216                              agNULL,
1217                              agNULL,
1218                              agNULL,      /* subkey5 */
1219                              "EventLogSize2", /* valueName *//* IOP size in K dWords   */
1220                              buffer,
1221                              buffLen,
1222                              &lenRecv
1223                              ) == tiSuccess) && (lenRecv != 0))
1224   {
1225     if (osti_strncmp(buffer, "0x", 2) == 0)
1226     {
1227       SwConfig->sizefEventLog2 = osti_strtoul (buffer, &pLastUsedChar, 0);
1228     }
1229     else
1230     {
1231       SwConfig->sizefEventLog2 = osti_strtoul (buffer, &pLastUsedChar, 10);
1232     }
1233   }
1234 
1235   osti_memset(buffer, 0, buffLen);
1236   lenRecv = 0;
1237 
1238   if ((ostiGetTransportParam(
1239                              tiRoot,
1240                              globalStr,   /* key */
1241                              SwParmsStr,  /* subkey1 */
1242                              agNULL,      /* subkey2 */
1243                              agNULL,
1244                              agNULL,
1245                              agNULL,      /* subkey5 */
1246                              "EventLogOption2", /* valueName */
1247                              buffer,
1248                              buffLen,
1249                              &lenRecv
1250                              ) == tiSuccess) && (lenRecv != 0))
1251   {
1252     if (osti_strncmp(buffer, "0x", 2) == 0)
1253     {
1254       SwConfig->eventLog2Option = osti_strtoul (buffer, &pLastUsedChar, 0);
1255     }
1256     else
1257     {
1258       SwConfig->eventLog2Option = osti_strtoul (buffer, &pLastUsedChar, 10);
1259     }
1260   }
1261   /* end of event log related parameters */
1262 
1263   /*
1264     HDA parameters
1265   */
1266   osti_memset(buffer, 0, buffLen);
1267   lenRecv = 0;
1268 
1269   if ((ostiGetTransportParam(
1270                              tiRoot,
1271                              globalStr,   /* key */
1272                              SwParmsStr,  /* subkey1 */
1273                              agNULL,      /* subkey2 */
1274                              agNULL,
1275                              agNULL,
1276                              agNULL,      /* subkey5 */
1277                              "HDASupport", /* valueName */
1278                              buffer,
1279                              buffLen,
1280                              &lenRecv
1281                              ) == tiSuccess) && (lenRecv != 0))
1282   {
1283     if (osti_strncmp(buffer, "0x", 2) == 0)
1284     {
1285       SwConfig->hostDirectAccessSupport = osti_strtoul (buffer, &pLastUsedChar, 0);
1286     }
1287     else
1288     {
1289       SwConfig->hostDirectAccessSupport = osti_strtoul (buffer, &pLastUsedChar, 10);
1290     }
1291   }
1292 
1293   osti_memset(buffer, 0, buffLen);
1294   lenRecv = 0;
1295 
1296   if ((ostiGetTransportParam(
1297                              tiRoot,
1298                              globalStr,   /* key */
1299                              SwParmsStr,  /* subkey1 */
1300                              agNULL,      /* subkey2 */
1301                              agNULL,
1302                              agNULL,
1303                              agNULL,      /* subkey5 */
1304                              "HDAMode", /* valueName */
1305                              buffer,
1306                              buffLen,
1307                              &lenRecv
1308                              ) == tiSuccess) && (lenRecv != 0))
1309   {
1310     if (osti_strncmp(buffer, "0x", 2) == 0)
1311     {
1312       SwConfig->hostDirectAccessMode = osti_strtoul (buffer, &pLastUsedChar, 0);
1313     }
1314     else
1315     {
1316       SwConfig->hostDirectAccessMode = osti_strtoul (buffer, &pLastUsedChar, 10);
1317     }
1318   }
1319   /* the end of HDA parameters */
1320 
1321   /* FW configuration */
1322   osti_memset(buffer, 0, buffLen);
1323   lenRecv = 0;
1324 
1325   if ((ostiGetTransportParam(
1326                              tiRoot,
1327                              globalStr,   /* key */
1328                              SwParmsStr,  /* subkey1 */
1329                              agNULL,      /* subkey2 */
1330                              agNULL,
1331                              agNULL,
1332                              agNULL,      /* subkey5 */
1333                              "FWConfig", /* valueName */
1334                              buffer,
1335                              buffLen,
1336                              &lenRecv
1337                              ) == tiSuccess) && (lenRecv != 0))
1338   {
1339     if (osti_strncmp(buffer, "0x", 2) == 0)
1340     {
1341       SwConfig->FWConfig = osti_strtoul (buffer, &pLastUsedChar, 0);
1342     }
1343     else
1344     {
1345       SwConfig->FWConfig = osti_strtoul (buffer, &pLastUsedChar, 10);
1346     }
1347   }
1348   /* The end of FW configuration */
1349 
1350   /* IQ Normal priority and High priority */
1351   osti_memset(buffer, 0, buffLen);
1352   lenRecv = 0;
1353 
1354   if ((ostiGetTransportParam(
1355                              tiRoot,
1356                              globalStr,   /* key */
1357                              SwParmsStr,  /* subkey1 */
1358                              IBQueueProps,/* subkey2 */
1359                              agNULL,
1360                              agNULL,
1361                              agNULL,      /* subkey5 */
1362                              "IQNQDepth", /* valueName */
1363                              buffer,
1364                              buffLen,
1365                              &lenRecv
1366                              ) == tiSuccess) && (lenRecv != 0))
1367     {
1368       if (osti_strncmp(buffer, "0x", 2) == 0)
1369       {
1370         QueueConfig->iqNormalPriorityProcessingDepth = (bit8) osti_strtoul (buffer, &pLastUsedChar, 0);
1371       }
1372       else
1373       {
1374         QueueConfig->iqNormalPriorityProcessingDepth = (bit8) osti_strtoul (buffer, &pLastUsedChar, 10);
1375       }
1376     }
1377 
1378   osti_memset(buffer, 0, buffLen);
1379   lenRecv = 0;
1380 
1381   if ((ostiGetTransportParam(
1382                              tiRoot,
1383                              globalStr,   /* key */
1384                              SwParmsStr,  /* subkey1 */
1385                              IBQueueProps,/* subkey2 */
1386                              agNULL,
1387                              agNULL,
1388                              agNULL,      /* subkey5 */
1389                              "IQHQDepth", /* valueName */
1390                              buffer,
1391                              buffLen,
1392                              &lenRecv
1393                              ) == tiSuccess) && (lenRecv != 0))
1394     {
1395       if (osti_strncmp(buffer, "0x", 2) == 0)
1396       {
1397         QueueConfig->iqHighPriorityProcessingDepth = (bit8) osti_strtoul (buffer, &pLastUsedChar, 0);
1398       }
1399       else
1400       {
1401         QueueConfig->iqHighPriorityProcessingDepth = (bit8) osti_strtoul (buffer, &pLastUsedChar, 10);
1402       }
1403     }
1404   /* End IQ Normal priority and High priority */
1405 
1406   /* Start port timeout value */
1407   osti_memset(buffer, 0, buffLen);
1408   lenRecv = 0;
1409 
1410   if ((ostiGetTransportParam(
1411                              tiRoot,
1412                              globalStr,   /* key */
1413                              SwParmsStr,  /* subkey1 */
1414                              agNULL,/* subkey2 */
1415                              agNULL,
1416                              agNULL,
1417                              agNULL,      /* subkey5 */
1418                              "PortTMO", /* valueName */
1419                              buffer,
1420                              buffLen,
1421                              &lenRecv
1422                              ) == tiSuccess) && (lenRecv != 0))
1423     {
1424       if (osti_strncmp(buffer, "0x", 2) == 0)
1425       {
1426         tdsaAllShared->portTMO = osti_strtoul (buffer, &pLastUsedChar, 0);
1427       }
1428       else
1429       {
1430         tdsaAllShared->portTMO = osti_strtoul (buffer, &pLastUsedChar, 10);
1431       }
1432     }
1433   /* End port timeout value */
1434 
1435 #ifdef SA_ENABLE_TRACE_FUNCTIONS
1436   osti_memset(buffer, 0, buffLen);
1437   lenRecv = 0;
1438   if ((ostiGetTransportParam(
1439                              tiRoot,
1440                              globalStr,   /* key */
1441                              SwParmsStr,  /* subkey1 */
1442                              agNULL,      /* subkey2 */
1443                              agNULL,
1444                              agNULL,
1445                              agNULL,      /* subkey5 */
1446                              "TraceDestination", /* valueName */
1447                              buffer,
1448                              buffLen,
1449                              &lenRecv
1450                              ) == tiSuccess) && (lenRecv != 0))
1451   {
1452     if (osti_strncmp(buffer, "0x", 2) == 0)
1453     {
1454       SwConfig->TraceDestination = osti_strtoul (buffer, &pLastUsedChar, 0);
1455     }
1456     else
1457     {
1458       SwConfig->TraceDestination = osti_strtoul (buffer, &pLastUsedChar, 10);
1459     }
1460     TI_DBG2(("tdsaGetSwConfigParams: SwConfig->TraceDestination %d\n",SwConfig->TraceDestination));
1461   }
1462 
1463   osti_memset(buffer, 0, buffLen);
1464   lenRecv = 0;
1465   if ((ostiGetTransportParam(
1466                              tiRoot,
1467                              globalStr,   /* key */
1468                              SwParmsStr,  /* subkey1 */
1469                              agNULL,      /* subkey2 */
1470                              agNULL,
1471                              agNULL,
1472                              agNULL,      /* subkey5 */
1473                              "TraceMask", /* valueName */
1474                              buffer,
1475                              buffLen,
1476                              &lenRecv
1477                              ) == tiSuccess) && (lenRecv != 0))
1478   {
1479     if (osti_strncmp(buffer, "0x", 2) == 0)
1480     {
1481       SwConfig->TraceMask = osti_strtoul (buffer, &pLastUsedChar, 0);
1482     }
1483     else
1484     {
1485       SwConfig->TraceMask = osti_strtoul (buffer, &pLastUsedChar, 10);
1486     }
1487     TI_DBG2(("tdsaGetSwConfigParams: SwConfig->TraceMask %d %X\n",SwConfig->TraceMask,SwConfig->TraceMask));
1488   }
1489 #endif /*# SA_ENABLE_TRACE_FUNCTIONS */
1490 
1491 #ifdef AGTIAPI_CTL
1492   /*
1493    * read the SAS Connection Time Limit parameter
1494    */
1495   osti_memset(buffer, 0, buffLen);
1496   lenRecv = 0;
1497   tdsaAllShared->SASConnectTimeLimit = 0;
1498 
1499   if ((ostiGetTransportParam(
1500                              tiRoot,
1501                              globalStr,   /* key */
1502                              SwParmsStr,  /* subkey1 */
1503                              agNULL,      /* subkey2 */
1504                              agNULL,
1505                              agNULL,
1506                              agNULL,      /* subkey5 */
1507                              "SASCTL",    /* valueName */
1508                              buffer,
1509                              buffLen,
1510                              &lenRecv
1511                              ) == tiSuccess) && (lenRecv != 0))
1512   {
1513     if (osti_strncmp(buffer, "0x", 2) == 0)
1514       tdsaAllShared->SASConnectTimeLimit = osti_strtoul (buffer, &pLastUsedChar, 0);
1515     else
1516       tdsaAllShared->SASConnectTimeLimit = osti_strtoul (buffer, &pLastUsedChar, 10);
1517   }
1518 #endif
1519 
1520   /* Start FCA value */
1521   osti_memset(buffer, 0, buffLen);
1522   lenRecv = 0;
1523 
1524   tdsaAllShared->FCA = 1; /* No FCA by default */
1525 
1526   if ((ostiGetTransportParam(
1527                              tiRoot,
1528                              globalStr,   /* key */
1529                              "InitiatorParms",  /* subkey1 */
1530                              agNULL,/* subkey2 */
1531                              agNULL,
1532                              agNULL,
1533                              agNULL,      /* subkey5 */
1534                              "FCA", /* valueName */
1535                              buffer,
1536                              buffLen,
1537                              &lenRecv
1538                              ) == tiSuccess) && (lenRecv != 0))
1539     {
1540       if (osti_strncmp(buffer, "0x", 2) == 0)
1541       {
1542         tdsaAllShared->FCA = osti_strtoul (buffer, &pLastUsedChar, 0);
1543       }
1544       else
1545       {
1546         tdsaAllShared->FCA = osti_strtoul (buffer, &pLastUsedChar, 10);
1547       }
1548     }
1549   /* End FCA value */
1550 
1551   /* Start ResetInDiscovery value */
1552   osti_memset(buffer, 0, buffLen);
1553   lenRecv = 0;
1554 
1555   tdsaAllShared->ResetInDiscovery = 0; /* No ResetInDiscovery by default */
1556 
1557   if ((ostiGetTransportParam(
1558                              tiRoot,
1559                              globalStr,   /* key */
1560                              "InitiatorParms",  /* subkey1 */
1561                              agNULL,/* subkey2 */
1562                              agNULL,
1563                              agNULL,
1564                              agNULL,      /* subkey5 */
1565                              "ResetInDiscovery", /* valueName */
1566                              buffer,
1567                              buffLen,
1568                              &lenRecv
1569                              ) == tiSuccess) && (lenRecv != 0))
1570     {
1571       if (osti_strncmp(buffer, "0x", 2) == 0)
1572       {
1573         tdsaAllShared->ResetInDiscovery = osti_strtoul (buffer, &pLastUsedChar, 0);
1574       }
1575       else
1576       {
1577         tdsaAllShared->ResetInDiscovery = osti_strtoul (buffer, &pLastUsedChar, 10);
1578       }
1579     }
1580   /* End ResetInDiscovery value */
1581 
1582   /* Start MCN value */
1583   osti_memset(buffer, 0, buffLen);
1584   lenRecv = 0;
1585 
1586   tdsaAllShared->MCN = 1; /* default MCN */
1587 
1588   if ((ostiGetTransportParam(
1589                              tiRoot,
1590                              globalStr,   /* key */
1591                              SwParmsStr,  /* subkey1 */
1592                              agNULL,/* subkey2 */
1593                              agNULL,
1594                              agNULL,
1595                              agNULL,      /* subkey5 */
1596                              "MCN", /* valueName */
1597                              buffer,
1598                              buffLen,
1599                              &lenRecv
1600                              ) == tiSuccess) && (lenRecv != 0))
1601   {
1602     if (osti_strncmp(buffer, "0x", 2) == 0)
1603     {
1604       tdsaAllShared->MCN = osti_strtoul (buffer, &pLastUsedChar, 0);
1605     }
1606     else
1607     {
1608       tdsaAllShared->MCN = osti_strtoul (buffer, &pLastUsedChar, 10);
1609     }
1610     TI_DBG6(("tdsaGetSwConfigParams: MCN %d\n", tdsaAllShared->MCN));
1611   }
1612   /* End MCN value */
1613 
1614   /* Start sflag value */
1615   osti_memset(buffer, 0, buffLen);
1616   lenRecv = 0;
1617 
1618   tdsaAllShared->sflag = 0; /* default sflag */
1619 
1620   if ((ostiGetTransportParam(
1621                              tiRoot,
1622                              globalStr,   /* key */
1623                              SwParmsStr,  /* subkey1 */
1624                              agNULL,      /* subkey2 */
1625                              agNULL,
1626                              agNULL,
1627                              agNULL,      /* subkey5 */
1628                              "Sflag",     /* valueName */
1629                              buffer,
1630                              buffLen,
1631                              &lenRecv
1632                              ) == tiSuccess) && (lenRecv != 0))
1633   {
1634     if (osti_strncmp(buffer, "0x", 2) == 0)
1635     {
1636       tdsaAllShared->sflag = osti_strtoul (buffer, &pLastUsedChar, 0);
1637     }
1638     else
1639     {
1640       tdsaAllShared->sflag = osti_strtoul (buffer, &pLastUsedChar, 10);
1641     }
1642     TI_DBG1(("tdsaGetSwConfigParams: sflag %d\n", tdsaAllShared->sflag));
1643   }
1644   /* End sflag value */
1645 
1646   /* Start enable DIF */
1647   osti_memset(buffer, 0, buffLen);
1648   lenRecv = 0;
1649 
1650   if ((ostiGetTransportParam(
1651                              tiRoot,
1652                              globalStr,   /* key */
1653                              SwParmsStr,  /* subkey1 */
1654                              agNULL,/* subkey2 */
1655                              agNULL,
1656                              agNULL,
1657                              agNULL,      /* subkey5 */
1658                              "enableDIF", /* valueName */
1659                              buffer,
1660                              buffLen,
1661                              &lenRecv
1662                              ) == tiSuccess) && (lenRecv != 0))
1663   {
1664     if (osti_strncmp(buffer, "0x", 2) == 0)
1665     {
1666       enableDIF = osti_strtoul (buffer, &pLastUsedChar, 0);
1667     }
1668     else
1669     {
1670       enableDIF = osti_strtoul (buffer, &pLastUsedChar, 10);
1671     }
1672     TI_DBG6(("tdsaGetSwConfigParams: enableDIF %d\n", enableDIF));
1673     if (enableDIF)
1674     {
1675       SwConfig->enableDIF = agTRUE;
1676     }
1677     else
1678     {
1679       SwConfig->enableDIF = agFALSE;
1680     }
1681     TI_DBG6(("tdsaGetSwConfigParams: SwConfig->enableDIF %d\n", SwConfig->enableDIF));
1682   }
1683   /* End enable DIF */
1684 
1685 
1686   /* Start enable Encryption */
1687   osti_memset(buffer, 0, buffLen);
1688   lenRecv = 0;
1689 
1690   if ((ostiGetTransportParam(
1691                              tiRoot,
1692                              globalStr,   /* key */
1693                              SwParmsStr,  /* subkey1 */
1694                              agNULL,/* subkey2 */
1695                              agNULL,
1696                              agNULL,
1697                              agNULL,      /* subkey5 */
1698                              "enableEncryption", /* valueName */
1699                              buffer,
1700                              buffLen,
1701                              &lenRecv
1702                              ) == tiSuccess) && (lenRecv != 0))
1703   {
1704     if (osti_strncmp(buffer, "0x", 2) == 0)
1705     {
1706       enableEncryption = osti_strtoul (buffer, &pLastUsedChar, 0);
1707     }
1708     else
1709     {
1710       enableEncryption = osti_strtoul (buffer, &pLastUsedChar, 10);
1711     }
1712     TI_DBG6(("tdsaGetSwConfigParams: enableEncryption %d\n", enableEncryption));
1713     if (enableEncryption)
1714     {
1715       SwConfig->enableEncryption = agTRUE;
1716     }
1717     else
1718     {
1719       SwConfig->enableEncryption = agFALSE;
1720     }
1721     TI_DBG6(("tdsaGetSwConfigParams: SwConfig->enableEncryption %d\n", SwConfig->enableEncryption));
1722   }
1723   /* End enable Encryption */
1724 
1725   /* Start allow connection rate change */
1726   osti_memset(buffer, 0, buffLen);
1727   lenRecv = 0;
1728   tdsaAllShared->RateAdjust = 0; /* No rate adjust by default */
1729   if ((ostiGetTransportParam(
1730                              tiRoot,
1731                              globalStr,   /* key */
1732                              SwParmsStr,  /* subkey1 */
1733                              agNULL,/* subkey2 */
1734                              agNULL,
1735                              agNULL,
1736                              agNULL,      /* subkey5 */
1737                              "RateAdjust", /* valueName */
1738                              buffer,
1739                              buffLen,
1740                              &lenRecv
1741                              ) == tiSuccess) && (lenRecv != 0))
1742   {
1743     if (osti_strncmp(buffer, "0x", 2) == 0)
1744     {
1745       tdsaAllShared->RateAdjust = osti_strtoul (buffer, &pLastUsedChar, 0);
1746     }
1747     else
1748     {
1749       tdsaAllShared->RateAdjust = osti_strtoul (buffer, &pLastUsedChar, 10);
1750     }
1751     TI_DBG6(("tdsaGetSwConfigParams: tdsaAllShared->RateAdjust %d\n", tdsaAllShared->RateAdjust));
1752   }
1753   /* End allow connection rate change */
1754 
1755 
1756 #ifdef SA_CONFIG_MDFD_REGISTRY
1757   /* Start disable MDF */
1758   osti_memset(buffer, 0, buffLen);
1759   lenRecv = 0;
1760 
1761   if ((ostiGetTransportParam(
1762                              tiRoot,
1763                              globalStr,   /* key */
1764                              SwParmsStr,  /* subkey1 */
1765                              agNULL,/* subkey2 */
1766                              agNULL,
1767                              agNULL,
1768                              agNULL,      /* subkey5 */
1769                              "disableMDF", /* valueName */
1770                              buffer,
1771                              buffLen,
1772                              &lenRecv
1773                              ) == tiSuccess) && (lenRecv != 0))
1774   {
1775     if (osti_strncmp(buffer, "0x", 2) == 0)
1776     {
1777       disableMDF = osti_strtoul (buffer, &pLastUsedChar, 0);
1778     }
1779     else
1780     {
1781       disableMDF = osti_strtoul (buffer, &pLastUsedChar, 10);
1782     }
1783     TI_DBG6(("tdsaGetSwConfigParams: disableMDF %d\n", disableMDF));
1784     if (disableMDF)
1785     {
1786       SwConfig->disableMDF = agTRUE;
1787     }
1788     else
1789     {
1790       SwConfig->disableMDF = agFALSE;
1791     }
1792     TI_DBG6(("tdsaGetSwConfigParams: SwConfig->disableMDF %d\n", SwConfig->disableMDF));
1793   }
1794   /* End disable MDF */
1795 #endif /*SA_CONFIG_MDFD_REGISTRY*/
1796 
1797   /* Start IT_NEXUS_TIMEOUT */
1798   osti_memset(buffer, 0, buffLen);
1799   lenRecv = 0;
1800 
1801   if ((ostiGetTransportParam(
1802                              tiRoot,
1803                              globalStr,   /* key */
1804                              SwParmsStr,  /* subkey1 */
1805                              agNULL,/* subkey2 */
1806                              agNULL,
1807                              agNULL,
1808                              agNULL,      /* subkey5 */
1809                              "IT_NEXUS_TIMEOUT", /* valueName */
1810                              buffer,
1811                              buffLen,
1812                              &lenRecv
1813                              ) == tiSuccess) && (lenRecv != 0))
1814   {
1815     if (osti_strncmp(buffer, "0x", 2) == 0)
1816     {
1817       tdsaAllShared->itNexusTimeout = osti_strtoul (buffer, &pLastUsedChar, 0);
1818     }
1819     else
1820     {
1821       tdsaAllShared->itNexusTimeout = osti_strtoul (buffer, &pLastUsedChar, 10);
1822     }
1823     TI_DBG1(("tdsaGetSwConfigParams: tdsaAllShared->itNexusTimeout %d\n", tdsaAllShared->itNexusTimeout));
1824   }
1825   /* End IT_NEXUS_TIMEOUT */
1826 
1827   /* Start stp idle time */
1828   osti_memset(buffer, 0, buffLen);
1829   lenRecv = 0;
1830 
1831   if ((ostiGetTransportParam(
1832                              tiRoot,
1833                              globalStr,   /* key */
1834                              SwParmsStr,  /* subkey1 */
1835                              agNULL,/* subkey2 */
1836                              agNULL,
1837                              agNULL,
1838                              agNULL,      /* subkey5 */
1839                              "STPIdleTime", /* valueName */
1840                              buffer,
1841                              buffLen,
1842                              &lenRecv
1843                              ) == tiSuccess) && (lenRecv != 0))
1844   {
1845     if (osti_strncmp(buffer, "0x", 2) == 0)
1846     {
1847       tdsaAllShared->stp_idle_time = osti_strtoul (buffer, &pLastUsedChar, 0);
1848     }
1849     else
1850     {
1851       tdsaAllShared->stp_idle_time = osti_strtoul (buffer, &pLastUsedChar, 10);
1852     }
1853     TI_DBG2(("tdsaGetSwConfigParams: STPIdleTime %d\n", tdsaAllShared->stp_idle_time));
1854   }
1855   /* End stp idle time */
1856 
1857   /* Start STP_MCT_TMO */
1858   osti_memset(buffer, 0, buffLen);
1859   lenRecv = 0;
1860 
1861   tdsaAllShared->STP_MCT_TMO = 32;
1862   if ((ostiGetTransportParam(
1863                              tiRoot,
1864                              globalStr,   /* key */
1865                              SwParmsStr,  /* subkey1 */
1866                              agNULL,/* subkey2 */
1867                              agNULL,
1868                              agNULL,
1869                              agNULL,      /* subkey5 */
1870                              "SAS_STP_MCT_TMO", /* valueName */
1871                              buffer,
1872                              buffLen,
1873                              &lenRecv
1874                              ) == tiSuccess) && (lenRecv != 0))
1875   {
1876     if (osti_strncmp(buffer, "0x", 2) == 0)
1877     {
1878       tdsaAllShared->STP_MCT_TMO = osti_strtoul (buffer, &pLastUsedChar, 0);
1879     }
1880     else
1881     {
1882       tdsaAllShared->STP_MCT_TMO = osti_strtoul (buffer, &pLastUsedChar, 10);
1883     }
1884     TI_DBG2(("tdsaGetSwConfigParams: STP_MCT_TMO %d\n", tdsaAllShared->STP_MCT_TMO));
1885   }
1886   /* End  STP_MCT_TMO */
1887 
1888   /* Start SSP_MCT_TMO */
1889   osti_memset(buffer, 0, buffLen);
1890   lenRecv = 0;
1891   tdsaAllShared->SSP_MCT_TMO = 32;
1892   if ((ostiGetTransportParam(
1893                              tiRoot,
1894                              globalStr,   /* key */
1895                              SwParmsStr,  /* subkey1 */
1896                              agNULL,/* subkey2 */
1897                              agNULL,
1898                              agNULL,
1899                              agNULL,      /* subkey5 */
1900                              "SAS_SSP_MCT_TMO", /* valueName */
1901                              buffer,
1902                              buffLen,
1903                              &lenRecv
1904                              ) == tiSuccess) && (lenRecv != 0))
1905   {
1906     if (osti_strncmp(buffer, "0x", 2) == 0)
1907     {
1908       tdsaAllShared->SSP_MCT_TMO = osti_strtoul (buffer, &pLastUsedChar, 0);
1909     }
1910     else
1911     {
1912       tdsaAllShared->SSP_MCT_TMO = osti_strtoul (buffer, &pLastUsedChar, 10);
1913     }
1914     TI_DBG2(("tdsaGetSwConfigParams: SSP_MCT_TMO %d\n", tdsaAllShared->SSP_MCT_TMO));
1915   }
1916   /* End  SSP_MCT_TMO */
1917 
1918 
1919   /* Start MAX_OPEN_TIME */
1920   osti_memset(buffer, 0, buffLen);
1921   lenRecv = 0;
1922   tdsaAllShared->MAX_OPEN_TIME = 5;
1923   if ((ostiGetTransportParam(
1924                              tiRoot,
1925                              globalStr,   /* key */
1926                              SwParmsStr,  /* subkey1 */
1927                              agNULL,/* subkey2 */
1928                              agNULL,
1929                              agNULL,
1930                              agNULL,      /* subkey5 */
1931                              "SAS_MAX_OPEN_TIME", /* valueName */
1932                              buffer,
1933                              buffLen,
1934                              &lenRecv
1935                              ) == tiSuccess) && (lenRecv != 0))
1936   {
1937     if (osti_strncmp(buffer, "0x", 2) == 0)
1938     {
1939       tdsaAllShared->MAX_OPEN_TIME = osti_strtoul (buffer, &pLastUsedChar, 0);
1940     }
1941     else
1942     {
1943       tdsaAllShared->MAX_OPEN_TIME = osti_strtoul (buffer, &pLastUsedChar, 10);
1944     }
1945     TI_DBG2(("tdsaGetSwConfigParams: MAX_OPEN_TIME %d\n", tdsaAllShared->MAX_OPEN_TIME));
1946   }
1947   /* End  MAX_OPEN_TIME */
1948 
1949 
1950   /* Start SMP_MAX_CONN_TIMER */
1951   osti_memset(buffer, 0, buffLen);
1952   lenRecv = 0;
1953   tdsaAllShared->SMP_MAX_CONN_TIMER = 0xFF;
1954   if ((ostiGetTransportParam(
1955                              tiRoot,
1956                              globalStr,   /* key */
1957                              SwParmsStr,  /* subkey1 */
1958                              agNULL,/* subkey2 */
1959                              agNULL,
1960                              agNULL,
1961                              agNULL,      /* subkey5 */
1962                              "SAS_SMP_MAX_CONN_TIMER", /* valueName */
1963                              buffer,
1964                              buffLen,
1965                              &lenRecv
1966                              ) == tiSuccess) && (lenRecv != 0))
1967   {
1968     if (osti_strncmp(buffer, "0x", 2) == 0)
1969     {
1970       tdsaAllShared->SMP_MAX_CONN_TIMER = osti_strtoul (buffer, &pLastUsedChar, 0);
1971     }
1972     else
1973     {
1974       tdsaAllShared->SMP_MAX_CONN_TIMER = osti_strtoul (buffer, &pLastUsedChar, 10);
1975     }
1976     TI_DBG2(("tdsaGetSwConfigParams: SMP_MAX_CONN_TIMER %d\n", tdsaAllShared->SMP_MAX_CONN_TIMER));
1977   }
1978   /* End  SMP_MAX_CONN_TIMER */
1979 
1980   /* Start STP_FRM_TMO */
1981   osti_memset(buffer, 0, buffLen);
1982   lenRecv = 0;
1983   tdsaAllShared->STP_FRM_TMO = 0;
1984   if ((ostiGetTransportParam(
1985                              tiRoot,
1986                              globalStr,   /* key */
1987                              SwParmsStr,  /* subkey1 */
1988                              agNULL,/* subkey2 */
1989                              agNULL,
1990                              agNULL,
1991                              agNULL,      /* subkey5 */
1992                              "SAS_STP_FRM_TMO", /* valueName */
1993                              buffer,
1994                              buffLen,
1995                              &lenRecv
1996                              ) == tiSuccess) && (lenRecv != 0))
1997   {
1998     if (osti_strncmp(buffer, "0x", 2) == 0)
1999     {
2000       tdsaAllShared->STP_FRM_TMO = osti_strtoul (buffer, &pLastUsedChar, 0);
2001     }
2002     else
2003     {
2004       tdsaAllShared->STP_FRM_TMO = osti_strtoul (buffer, &pLastUsedChar, 10);
2005     }
2006     TI_DBG2(("tdsaGetSwConfigParams: STP_FRM_TMO %d\n", tdsaAllShared->STP_FRM_TMO));
2007   }
2008   /* End  STP_FRM_TMO */
2009 
2010   /* Start MFD_OPNRJT_RTRY_INTVL */
2011   osti_memset(buffer, 0, buffLen);
2012   lenRecv = 0;
2013   tdsaAllShared->MFD = 1; /* disabled  by default */
2014   if ((ostiGetTransportParam(
2015                              tiRoot,
2016                              globalStr,   /* key */
2017                              SwParmsStr,  /* subkey1 */
2018                              agNULL,/* subkey2 */
2019                              agNULL,
2020                              agNULL,
2021                              agNULL,      /* subkey5 */
2022                              "SAS_MFD", /* valueName */
2023                              buffer,
2024                              buffLen,
2025                              &lenRecv
2026                              ) == tiSuccess) && (lenRecv != 0))
2027   {
2028     if (osti_strncmp(buffer, "0x", 2) == 0)
2029     {
2030       tdsaAllShared->MFD = osti_strtoul (buffer, &pLastUsedChar, 0);
2031     }
2032     else
2033     {
2034       tdsaAllShared->MFD = osti_strtoul (buffer, &pLastUsedChar, 10);
2035     }
2036     TI_DBG2(("tdsaGetSwConfigParams: MFD %d\n", tdsaAllShared->MFD));
2037   }
2038   /* End  MFD_OPNRJT_RTRY_INTVL */
2039 
2040   /* Start MFD_OPNRJT_RTRY_INTVL */
2041   osti_memset(buffer, 0, buffLen);
2042   lenRecv = 0;
2043   tdsaAllShared->OPNRJT_RTRY_INTVL = 2;
2044   if ((ostiGetTransportParam(
2045                              tiRoot,
2046                              globalStr,   /* key */
2047                              SwParmsStr,  /* subkey1 */
2048                              agNULL,/* subkey2 */
2049                              agNULL,
2050                              agNULL,
2051                              agNULL,      /* subkey5 */
2052                              "SAS_OPNRJT_RTRY_INTVL", /* valueName */
2053                              buffer,
2054                              buffLen,
2055                              &lenRecv
2056                              ) == tiSuccess) && (lenRecv != 0))
2057   {
2058     if (osti_strncmp(buffer, "0x", 2) == 0)
2059     {
2060       tdsaAllShared->OPNRJT_RTRY_INTVL = osti_strtoul (buffer, &pLastUsedChar, 0);
2061     }
2062     else
2063     {
2064       tdsaAllShared->OPNRJT_RTRY_INTVL = osti_strtoul (buffer, &pLastUsedChar, 10);
2065     }
2066     TI_DBG2(("tdsaGetSwConfigParams: OPNRJT_RTRY_INTVL %d\n", tdsaAllShared->OPNRJT_RTRY_INTVL));
2067   }
2068   /* End  MFD_OPNRJT_RTRY_INTVL */
2069 
2070   /* Start DOPNRJT_RTRY_TMO */
2071   osti_memset(buffer, 0, buffLen);
2072   lenRecv = 0;
2073   tdsaAllShared->DOPNRJT_RTRY_TMO = 128;
2074   if ((ostiGetTransportParam(
2075                              tiRoot,
2076                              globalStr,   /* key */
2077                              SwParmsStr,  /* subkey1 */
2078                              agNULL,/* subkey2 */
2079                              agNULL,
2080                              agNULL,
2081                              agNULL,      /* subkey5 */
2082                              "SAS_DOPNRJT_RTRY_TMO", /* valueName */
2083                              buffer,
2084                              buffLen,
2085                              &lenRecv
2086                              ) == tiSuccess) && (lenRecv != 0))
2087   {
2088     if (osti_strncmp(buffer, "0x", 2) == 0)
2089     {
2090       tdsaAllShared->DOPNRJT_RTRY_TMO = osti_strtoul (buffer, &pLastUsedChar, 0);
2091     }
2092     else
2093     {
2094       tdsaAllShared->DOPNRJT_RTRY_TMO = osti_strtoul (buffer, &pLastUsedChar, 10);
2095     }
2096     TI_DBG2(("tdsaGetSwConfigParams: DOPNRJT_RTRY_TMO %d\n", tdsaAllShared->DOPNRJT_RTRY_TMO));
2097   }
2098   /* End  DOPNRJT_RTRY_TMO */
2099 
2100   /* Start COPNRJT_RTRY_TMO */
2101   osti_memset(buffer, 0, buffLen);
2102   lenRecv = 0;
2103 //  tdsaAllShared->COPNRJT_RTRY_TMO = 32;
2104   tdsaAllShared->COPNRJT_RTRY_TMO = 128;
2105   if ((ostiGetTransportParam(
2106                              tiRoot,
2107                              globalStr,   /* key */
2108                              SwParmsStr,  /* subkey1 */
2109                              agNULL,/* subkey2 */
2110                              agNULL,
2111                              agNULL,
2112                              agNULL,      /* subkey5 */
2113                              "SAS_COPNRJT_RTRY_TMO", /* valueName */
2114                              buffer,
2115                              buffLen,
2116                              &lenRecv
2117                              ) == tiSuccess) && (lenRecv != 0))
2118   {
2119     if (osti_strncmp(buffer, "0x", 2) == 0)
2120     {
2121       tdsaAllShared->COPNRJT_RTRY_TMO = osti_strtoul (buffer, &pLastUsedChar, 0);
2122     }
2123     else
2124     {
2125       tdsaAllShared->COPNRJT_RTRY_TMO = osti_strtoul (buffer, &pLastUsedChar, 10);
2126     }
2127     TI_DBG2(("tdsaGetSwConfigParams: COPNRJT_RTRY_TMO %d\n", tdsaAllShared->COPNRJT_RTRY_TMO));
2128   }
2129   /* End  COPNRJT_RTRY_TMO */
2130 
2131   /* Start DOPNRJT_RTRY_THR */
2132   osti_memset(buffer, 0, buffLen);
2133   lenRecv = 0;
2134 //  tdsaAllShared->DOPNRJT_RTRY_THR = 16; /* FW default */
2135   /*
2136     Making ORR bigger than IT NEXUS LOSS which is 2000000us = 2 second.
2137     Assuming a bigger value 3 second, 3000000/128 = 23437.5 where 128 is tdsaAllShared->DOPNRJT_RTRY_TMO
2138   */
2139   tdsaAllShared->DOPNRJT_RTRY_THR = 23438;
2140   if ((ostiGetTransportParam(
2141                              tiRoot,
2142                              globalStr,   /* key */
2143                              SwParmsStr,  /* subkey1 */
2144                              agNULL,/* subkey2 */
2145                              agNULL,
2146                              agNULL,
2147                              agNULL,      /* subkey5 */
2148                              "SAS_DOPNRJT_RTRY_THR", /* valueName */
2149                              buffer,
2150                              buffLen,
2151                              &lenRecv
2152                              ) == tiSuccess) && (lenRecv != 0))
2153   {
2154     if (osti_strncmp(buffer, "0x", 2) == 0)
2155     {
2156       tdsaAllShared->DOPNRJT_RTRY_THR = osti_strtoul (buffer, &pLastUsedChar, 0);
2157     }
2158     else
2159     {
2160       tdsaAllShared->DOPNRJT_RTRY_THR = osti_strtoul (buffer, &pLastUsedChar, 10);
2161     }
2162     TI_DBG2(("tdsaGetSwConfigParams: DOPNRJT_RTRY_THR %d\n", tdsaAllShared->DOPNRJT_RTRY_THR));
2163   }
2164   /* End  DOPNRJT_RTRY_THR */
2165 
2166   /* Start COPNRJT_RTRY_THR */
2167   osti_memset(buffer, 0, buffLen);
2168   lenRecv = 0;
2169 //  tdsaAllShared->COPNRJT_RTRY_THR = 1024; /* FW default */
2170   /*
2171     Making ORR bigger than IT NEXUS LOSS which is 2000000us = 2 second.
2172     Assuming a bigger value 3 second, 3000000/128 =  23437.5 where 128 is tdsaAllShared->COPNRJT_RTRY_TMO
2173   */
2174   tdsaAllShared->COPNRJT_RTRY_THR = 23438;
2175   if ((ostiGetTransportParam(
2176                              tiRoot,
2177                              globalStr,   /* key */
2178                              SwParmsStr,  /* subkey1 */
2179                              agNULL,/* subkey2 */
2180                              agNULL,
2181                              agNULL,
2182                              agNULL,      /* subkey5 */
2183                              "SAS_COPNRJT_RTRY_THR", /* valueName */
2184                              buffer,
2185                              buffLen,
2186                              &lenRecv
2187                              ) == tiSuccess) && (lenRecv != 0))
2188   {
2189     if (osti_strncmp(buffer, "0x", 2) == 0)
2190     {
2191       tdsaAllShared->COPNRJT_RTRY_THR = osti_strtoul (buffer, &pLastUsedChar, 0);
2192     }
2193     else
2194     {
2195       tdsaAllShared->COPNRJT_RTRY_THR = osti_strtoul (buffer, &pLastUsedChar, 10);
2196     }
2197     TI_DBG2(("tdsaGetSwConfigParams: COPNRJT_RTRY_THR %d\n", tdsaAllShared->COPNRJT_RTRY_THR));
2198   }
2199   /* End  COPNRJT_RTRY_THR */
2200 
2201   /* Start MAX_AIP */
2202   osti_memset(buffer, 0, buffLen);
2203   lenRecv = 0;
2204   tdsaAllShared->MAX_AIP = 0x200000;
2205   if ((ostiGetTransportParam(
2206                              tiRoot,
2207                              globalStr,   /* key */
2208                              SwParmsStr,  /* subkey1 */
2209                              agNULL,/* subkey2 */
2210                              agNULL,
2211                              agNULL,
2212                              agNULL,      /* subkey5 */
2213                              "SAS_MAX_AIP", /* valueName */
2214                              buffer,
2215                              buffLen,
2216                              &lenRecv
2217                              ) == tiSuccess) && (lenRecv != 0))
2218   {
2219     if (osti_strncmp(buffer, "0x", 2) == 0)
2220     {
2221       tdsaAllShared->MAX_AIP = osti_strtoul (buffer, &pLastUsedChar, 0);
2222     }
2223     else
2224     {
2225       tdsaAllShared->MAX_AIP = osti_strtoul (buffer, &pLastUsedChar, 10);
2226     }
2227     TI_DBG2(("tdsaGetSwConfigParams: MAX_AIP %d\n", tdsaAllShared->MAX_AIP));
2228   }
2229   /* End  MAX_AIP */
2230 
2231   /***********************************************************************/
2232   osti_memset(buffer, 0, buffLen);
2233   lenRecv = 0;
2234 
2235 
2236     /*
2237     typedef struct agsaMPIContext_s
2238     {
2239       bit32   MPITableType;
2240       bit32   offset;
2241       bit32   value;
2242     } agsaMPIContext_t;
2243     */
2244 
2245   {
2246     bit32 MpiContextvalue  = 0;
2247     SwConfig->mpiContextTable = agNULL;
2248     SwConfig->mpiContextTablelen = 0;
2249 
2250     if ((ostiGetTransportParam(
2251                                tiRoot,
2252                                globalStr,   /* key */
2253                                SwParmsStr,  /* subkey1 */
2254                                agNULL,      /* subkey2 */
2255                                agNULL,
2256                                agNULL,
2257                                agNULL,      /* subkey5 */
2258                                "MpiContext", /* valueName */
2259                                buffer,
2260                                buffLen,
2261                                &lenRecv
2262                                ) == tiSuccess) && (lenRecv != 0))
2263     {
2264 
2265       if (osti_strncmp(buffer, "0x", 2) == 0)
2266       {
2267         MpiContextvalue = osti_strtoul (buffer, &pLastUsedChar, 0);
2268       }
2269       else
2270       {
2271         MpiContextvalue =  osti_strtoul (buffer, &pLastUsedChar, 10);
2272       }
2273 
2274 
2275       if (MpiContextvalue  == 0)
2276       {
2277         SwConfig->mpiContextTable = agNULL;
2278         SwConfig->mpiContextTablelen = 0;
2279       }
2280       else
2281       {
2282         tdsaRoot_t    *tdsaRoot = (tdsaRoot_t *)tiRoot->tdData;
2283         if(agNULL != tdsaRoot)
2284         {
2285           tdsaRoot->tdsaAllShared.MpiOverride.MPITableType = 0xFF;
2286           tdsaRoot->tdsaAllShared.MpiOverride.offset = 0;
2287           tdsaRoot->tdsaAllShared.MpiOverride.value = 0;
2288 
2289           SwConfig->mpiContextTable = &(tdsaRoot->tdsaAllShared.MpiOverride);
2290           SwConfig->mpiContextTablelen = sizeof(agsaMPIContext_t);
2291         }
2292 
2293         TI_DBG1(("tdsaGetSwConfigParams: MpiContext %p Len %d\n", SwConfig->mpiContextTable, SwConfig->mpiContextTablelen));
2294 
2295       }
2296     }
2297 
2298     if(SwConfig->mpiContextTable != agNULL )
2299     {
2300       tdsaRoot_t    *tdsaRoot = (tdsaRoot_t *)tiRoot->tdData;
2301       if(agNULL != tdsaRoot)
2302       {
2303         if ((ostiGetTransportParam(
2304                                    tiRoot,
2305                                    globalStr,   /* key */
2306                                    SwParmsStr,  /* subkey1 */
2307                                    agNULL,      /* subkey2 */
2308                                    agNULL,
2309                                    agNULL,
2310                                    agNULL,      /* subkey5 */
2311                                    "MpiTableType", /* valueName */
2312                                    buffer,
2313                                    buffLen,
2314                                    &lenRecv
2315                                    ) == tiSuccess) && (lenRecv != 0))
2316         {
2317           if (osti_strncmp(buffer, "0x", 2) == 0)
2318           {
2319             tdsaRoot->tdsaAllShared.MpiOverride.MPITableType = osti_strtoul (buffer, &pLastUsedChar, 0);
2320           }
2321           else
2322           {
2323             tdsaRoot->tdsaAllShared.MpiOverride.MPITableType =  osti_strtoul (buffer, &pLastUsedChar, 10);
2324           }
2325         TI_DBG1(("tdsaGetSwConfigParams: MpiOverride.MPITableType  0x%X\n",tdsaRoot->tdsaAllShared.MpiOverride.MPITableType ));
2326         }
2327 
2328         if ((ostiGetTransportParam(
2329                                    tiRoot,
2330                                    globalStr,   /* key */
2331                                    SwParmsStr,  /* subkey1 */
2332                                    agNULL,      /* subkey2 */
2333                                    agNULL,
2334                                    agNULL,
2335                                    agNULL,      /* subkey5 */
2336                                    "MpiTableOffset", /* valueName */
2337                                    buffer,
2338                                    buffLen,
2339                                    &lenRecv
2340                                    ) == tiSuccess) && (lenRecv != 0))
2341         {
2342           if (osti_strncmp(buffer, "0x", 2) == 0)
2343           {
2344             tdsaRoot->tdsaAllShared.MpiOverride.offset = osti_strtoul (buffer, &pLastUsedChar, 0);
2345           }
2346           else
2347           {
2348             tdsaRoot->tdsaAllShared.MpiOverride.offset =  osti_strtoul (buffer, &pLastUsedChar, 10);
2349           }
2350 
2351         TI_DBG1(("tdsaGetSwConfigParams: MpiOverride.offset 0x%X\n",tdsaRoot->tdsaAllShared.MpiOverride.offset ));
2352         }
2353 
2354         if ((ostiGetTransportParam(
2355                                    tiRoot,
2356                                    globalStr,   /* key */
2357                                    SwParmsStr,  /* subkey1 */
2358                                    agNULL,      /* subkey2 */
2359                                    agNULL,
2360                                    agNULL,
2361                                    agNULL,      /* subkey5 */
2362                                    "MpiTableValue", /* valueName */
2363                                    buffer,
2364                                    buffLen,
2365                                    &lenRecv
2366                                    ) == tiSuccess) && (lenRecv != 0))
2367         {
2368           if (osti_strncmp(buffer, "0x", 2) == 0)
2369           {
2370             tdsaRoot->tdsaAllShared.MpiOverride.value = osti_strtoul (buffer, &pLastUsedChar, 0);
2371           }
2372           else
2373           {
2374             tdsaRoot->tdsaAllShared.MpiOverride.value =  osti_strtoul (buffer, &pLastUsedChar, 10);
2375           }
2376           TI_DBG1(("tdsaGetSwConfigParams: MpiOverride.value 0x%X\n",tdsaRoot->tdsaAllShared.MpiOverride.value ));
2377         }
2378       }
2379     }
2380   }
2381   /***********************************************************************/
2382 
2383 #ifdef SA_ENABLE_PCI_TRIGGER
2384 
2385   osti_memset(buffer, 0, buffLen);
2386   lenRecv = 0;
2387 
2388   if ((ostiGetTransportParam(
2389                              tiRoot,
2390                              globalStr,   /* key */
2391                              SwParmsStr,  /* subkey1 */
2392                              agNULL,      /* subkey2 */
2393                              agNULL,
2394                              agNULL,
2395                              agNULL,      /* subkey5 */
2396                              "PciTrigger", /* valueName */
2397                              buffer,
2398                              buffLen,
2399                              &lenRecv
2400                              ) == tiSuccess) && (lenRecv != 0))
2401   {
2402 
2403     if (osti_strncmp(buffer, "0x", 2) == 0)
2404     {
2405       SwConfig->PCI_trigger = osti_strtoul (buffer, &pLastUsedChar, 0);
2406     }
2407     else
2408     {
2409       SwConfig->PCI_trigger = osti_strtoul (buffer, &pLastUsedChar, 10);
2410     }
2411     TI_DBG1(("tdsaGetSwConfigParams: PciTrigger %d\n",SwConfig->PCI_trigger));
2412   }
2413 #endif /* SA_ENABLE_PCI_TRIGGER */
2414 
2415 
2416   TI_DBG6(("tdsaGetSwConfigParams: $$$$$$$$$$$$$$$$$ merge $$$$$$$$$$$$$\n"));
2417 #if defined(SALLSDK_DEBUG)
2418   TI_DBG2(("tdsaGetSwConfigParams: SwConfig->sallDebugLevel %d\n", SwConfig->sallDebugLevel));
2419 #endif
2420 
2421 #ifdef SA_ENABLE_PCI_TRIGGER
2422   TI_DBG1(("tdsaGetSwConfigParams: SwConfig->PCI_trigger  0x%x   0x%x\n",SwConfig->PCI_trigger, tdsaRoot->itdsaIni->tdsaAllShared->SwConfig.PCI_trigger));
2423 #endif /* SA_ENABLE_PCI_TRIGGER */
2424 
2425 
2426 #ifdef AGTIAPI_CTL
2427   TI_DBG6(("tdsaLoLevelGetResource: SASConnectTimeLimit 0x%x\n",
2428            tdsaAllShared->SASConnectTimeLimit));
2429 #endif
2430 
2431   return;
2432 }
2433 
2434 /*****************************************************************************
2435 *! \brief  tdsaParseLinkRateMode
2436 *
2437 *  Purpose:  This function parses link rate and mode.
2438 *
2439 *  \param   LinkRate: Link rate specified by user.
2440 *  \param   Mode: Link rate specified by user.
2441 *
2442 *  \return:
2443 *           Value combined with Linkrate and Mode
2444 *
2445 *   \note:
2446 *
2447 *****************************************************************************/
2448 osGLOBAL void
2449 tdsaParseLinkRateMode(
2450                       tiRoot_t *tiRoot,
2451                       bit32 index,
2452                       bit32 LinkRateRead,
2453                       bit32 ModeRead,
2454                       bit32 OpticalModeRead,
2455                       bit32 LinkRate,
2456                       bit32 Mode,
2457                       bit32 OpticalMode
2458                       )
2459 {
2460   tdsaRoot_t     *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
2461   tdsaContext_t  *tdsaAllShared = (tdsaContext_t *)&(tdsaRoot->tdsaAllShared);
2462 
2463   TI_DBG3(("tdsaParseLinkRateMode: index 0x%X\n",index));
2464   TI_DBG3(("tdsaParseLinkRateMode: LinkRateRead 0x%X    LinkRate 0x%X\n",LinkRateRead,LinkRate));
2465   TI_DBG3(("tdsaParseLinkRateMode: ModeRead 0x%X        Mode 0x%X\n",ModeRead,Mode));
2466   TI_DBG3(("tdsaParseLinkRateMode: OpticalModeRead 0x%X OpticalMode 0x%X\n",OpticalModeRead,OpticalMode));
2467 
2468 
2469   if (LinkRateRead == agTRUE)
2470   {
2471     /* link rate */
2472     if (LinkRate & 0x1)
2473     {
2474       tdsaAllShared->Ports[index].agPhyConfig.phyProperties = tdsaAllShared->Ports[index].agPhyConfig.phyProperties | 0x1;
2475     }
2476     if (LinkRate & 0x2)
2477     {
2478       tdsaAllShared->Ports[index].agPhyConfig.phyProperties = tdsaAllShared->Ports[index].agPhyConfig.phyProperties | 0x2;
2479     }
2480     if (LinkRate & 0x4)
2481     {
2482       tdsaAllShared->Ports[index].agPhyConfig.phyProperties = tdsaAllShared->Ports[index].agPhyConfig.phyProperties | 0x4;
2483     }
2484     if (LinkRate & 0x8)
2485     {
2486       tdsaAllShared->Ports[index].agPhyConfig.phyProperties = tdsaAllShared->Ports[index].agPhyConfig.phyProperties | 0x8;
2487     }
2488     if (LinkRate == 0 || LinkRate > 0xF )
2489     {
2490       /* not allowed, set the rate to default 1.5 G */
2491       tdsaAllShared->Ports[index].agPhyConfig.phyProperties = 0;
2492       tdsaAllShared->Ports[index].agPhyConfig.phyProperties = tdsaAllShared->Ports[index].agPhyConfig.phyProperties | 0x1;
2493       TI_DBG1(("tdsaParseLinkRateMode:  LinkRate == 0 || LinkRate >= 0x%x\n",tdsaAllShared->Ports[index].agPhyConfig.phyProperties));
2494     }
2495     TI_DBG2(("tdsaParseLinkRateMode:A index 0x%x LinkRate 0x%x Mode 0x%x\n",index,LinkRate,Mode));
2496 
2497   }
2498 
2499   if ( ModeRead == agTRUE)
2500   {
2501     /* mode */
2502     if (Mode & 0x1)
2503     {
2504       tdsaAllShared->Ports[index].agPhyConfig.phyProperties = tdsaAllShared->Ports[index].agPhyConfig.phyProperties | 0x10;
2505     }
2506     if (Mode & 0x2)
2507     {
2508       tdsaAllShared->Ports[index].agPhyConfig.phyProperties = tdsaAllShared->Ports[index].agPhyConfig.phyProperties | 0x20;
2509     }
2510     if (Mode == 0 || Mode >= 4 )
2511     {
2512       /* not allowed, set the mode to default SAS/SATA */
2513       tdsaAllShared->Ports[index].agPhyConfig.phyProperties = tdsaAllShared->Ports[index].agPhyConfig.phyProperties & 0xf;
2514       tdsaAllShared->Ports[index].agPhyConfig.phyProperties = tdsaAllShared->Ports[index].agPhyConfig.phyProperties | 0x30;
2515     }
2516     TI_DBG2(("tdsaParseLinkRateMode:1 index 0x%x Mode 0x%x\n",index,tdsaAllShared->Ports[index].agPhyConfig.phyProperties));
2517   }
2518 
2519   if ( OpticalModeRead == agTRUE)
2520   {
2521     /* setting bit20 */
2522     agsaRoot_t     *agRoot = &tdsaAllShared->agRootInt;
2523 
2524     if (OpticalMode == 0)
2525     {
2526       TI_DBG1(("tdsaParseLinkRateMode: OpticalMode 0  phy %d phyProperties 0x%x\n",index,tdsaAllShared->Ports[index].agPhyConfig.phyProperties));
2527     }
2528     else if(OpticalMode == 1)
2529     {
2530       if(tIsSPCV12or6G(agRoot))
2531       {
2532         TI_DBG1(("tdsaParseLinkRateMode: OpticalMode 1  phy %d phyProperties 0x%x\n",index,tdsaAllShared->Ports[index].agPhyConfig.phyProperties));
2533         tdsaAllShared->Ports[index].agPhyConfig.phyProperties = tdsaAllShared->Ports[index].agPhyConfig.phyProperties | (1 << 22);
2534       }
2535       else
2536       {
2537         tdsaAllShared->Ports[index].agPhyConfig.phyProperties = tdsaAllShared->Ports[index].agPhyConfig.phyProperties | (1 << 22);
2538         tdsaAllShared->Ports[index].agPhyConfig.phyProperties &= 0xFFFFFFF0;
2539         tdsaAllShared->Ports[index].agPhyConfig.phyProperties |= 0x4;
2540       }
2541     }
2542     else if(OpticalMode == 2 )
2543     {
2544       if(tIsSPCV12or6G(agRoot))
2545       {
2546         TI_DBG1(("tdsaParseLinkRateMode: OpticalMode 2  phy %d phyProperties 0x%x\n",index,tdsaAllShared->Ports[index].agPhyConfig.phyProperties));
2547         tdsaAllShared->Ports[index].agPhyConfig.phyProperties = tdsaAllShared->Ports[index].agPhyConfig.phyProperties | (1 << 20);
2548       }
2549       else
2550       {
2551         TD_ASSERT(0, "SPC optical mode 2");
2552       }
2553 
2554       TI_DBG1(("tdsaParseLinkRateMode: OpticalMode %d phy %d phyProperties 0x%x\n",OpticalMode,index,tdsaAllShared->Ports[index].agPhyConfig.phyProperties));
2555     }
2556     else
2557     {
2558        TI_DBG1(("tdsaParseLinkRateMode: OpticalMode unknown %d  phy %d phyProperties 0x%x\n",OpticalMode,index,tdsaAllShared->Ports[index].agPhyConfig.phyProperties));
2559     }
2560   }
2561   else
2562   {
2563     TI_DBG1(("tdsaParseLinkRateMode: OpticalMode off phy %d phyProperties 0x%x\n",index,tdsaAllShared->Ports[index].agPhyConfig.phyProperties));
2564   }
2565 
2566   TI_DBG1(("tdsaParseLinkRateMode: phy %d phyProperties 0x%x\n",index,tdsaAllShared->Ports[index].agPhyConfig.phyProperties));
2567 
2568 
2569   return;
2570 }
2571 
2572 
2573 /*****************************************************************************
2574 *! \brief tdsaGetHwConfigParams
2575 *
2576 *  Purpose:  This function reads hardware configuration parameters from the
2577 *            configuration file
2578 *
2579 *  \param  tiRoot:            Pointer to driver/port instance.
2580 *
2581 *  \return: None
2582 *
2583 *  \note -
2584 *
2585 *****************************************************************************/
2586 osGLOBAL void
2587 tdsaGetHwConfigParams(
2588                       tiRoot_t *tiRoot
2589                       )
2590 {
2591   tdsaRoot_t     *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
2592   tdsaContext_t  *tdsaAllShared = (tdsaContext_t *)&(tdsaRoot->tdsaAllShared);
2593   agsaHwConfig_t *HwConfig;
2594   char           *buffer;
2595   bit32          buffLen;
2596   bit32          lenRecv = 0;
2597   char           *pLastUsedChar = agNULL;
2598   char           tmpBuffer[DEFAULT_KEY_BUFFER_SIZE];
2599   char           globalStr[]     = "Global";
2600   char           HwParmsStr[]   = "HWParms";
2601   char           phyReg[10];
2602   int            i,j;
2603   agsaPhyAnalogSetupTable_t *phyRegTable;
2604 
2605   TI_DBG6(("tdsaGetHwConfigParams: start\n"));
2606   TI_DBG6(("tdsaGetHwConfigParams: tdsaRoot %p tdsaAllShared %p \n",tdsaRoot, tdsaAllShared));
2607 
2608   buffer = tmpBuffer;
2609   buffLen = sizeof(tmpBuffer);
2610 
2611   osti_memset(buffer, 0, buffLen);
2612 
2613   HwConfig = (agsaHwConfig_t *)&(tdsaAllShared->HwConfig);
2614   phyRegTable = (agsaPhyAnalogSetupTable_t *)&(HwConfig->phyAnalogConfig);
2615 
2616   osti_memset(HwConfig, 0, sizeof(agsaHwConfig_t));
2617 
2618   /*
2619     just default values
2620     and are overwritten later by the configuration file contents
2621     turning off hw control interrupt coalescing
2622   */
2623   tdsaAllShared->FWMaxPorts = DEFAULT_FW_MAX_PORTS; /* 8, applicable only to SPC not to SPCv */
2624   HwConfig->phyCount = TD_MAX_NUM_PHYS;
2625   HwConfig->hwInterruptCoalescingTimer = 1;
2626   HwConfig->hwInterruptCoalescingControl = 0;
2627   tdsaAllShared->phyCalibration = 0;
2628   HwConfig->hwOption = 0; /* default: PI/CI addresses are 32-bit */
2629 
2630   osti_memset(buffer, 0, buffLen);
2631   lenRecv = 0;
2632 
2633   if ((ostiGetTransportParam(
2634                              tiRoot,
2635                              globalStr,   /* key */
2636                              HwParmsStr,  /* subkey1 */
2637                              agNULL,      /* subkey2 */
2638                              agNULL,
2639                              agNULL,
2640                              agNULL,      /* subkey5 */
2641                              "HwIntCoalTimer", /* valueName */
2642                              buffer,
2643                              buffLen,
2644                              &lenRecv
2645                              ) == tiSuccess) && (lenRecv != 0))
2646   {
2647     if (osti_strncmp(buffer, "0x", 2) == 0)
2648     {
2649       HwConfig->hwInterruptCoalescingTimer = osti_strtoul (buffer, &pLastUsedChar, 0);
2650     }
2651     else
2652     {
2653       HwConfig->hwInterruptCoalescingTimer = osti_strtoul (buffer, &pLastUsedChar, 10);
2654     }
2655   }
2656 
2657   osti_memset(buffer, 0, buffLen);
2658   lenRecv = 0;
2659 
2660   if ((ostiGetTransportParam(
2661                              tiRoot,
2662                              globalStr,   /* key */
2663                              HwParmsStr,  /* subkey1 */
2664                              agNULL,      /* subkey2 */
2665                              agNULL,
2666                              agNULL,
2667                              agNULL,      /* subkey5 */
2668                              "HwIntCoalControl", /* valueName */
2669                              buffer,
2670                              buffLen,
2671                              &lenRecv
2672                              ) == tiSuccess) && (lenRecv != 0))
2673   {
2674     if (osti_strncmp(buffer, "0x", 2) == 0)
2675     {
2676       HwConfig->hwInterruptCoalescingControl = osti_strtoul (buffer, &pLastUsedChar, 0);
2677     }
2678     else
2679     {
2680       HwConfig->hwInterruptCoalescingControl = osti_strtoul (buffer, &pLastUsedChar, 10);
2681     }
2682   }
2683 
2684   /* For hwInterruptCoalescingTimer, 0 disables interrrupt, not allowed */
2685   if (HwConfig->hwInterruptCoalescingControl == 1 && HwConfig->hwInterruptCoalescingTimer == 0)
2686   {
2687     HwConfig->hwInterruptCoalescingTimer = 1;
2688   }
2689 
2690   osti_memset(buffer, 0, buffLen);
2691   lenRecv = 0;
2692 
2693   /* interrupt reassetion field*/
2694   if ((ostiGetTransportParam(
2695                              tiRoot,
2696                              globalStr,   /* key */
2697                              HwParmsStr,  /* subkey1 */
2698                              agNULL,      /* subkey2 */
2699                              agNULL,
2700                              agNULL,
2701                              agNULL,      /* subkey5 */
2702                              "IntReassertionOpt", /* valueName */
2703                              buffer,
2704                              buffLen,
2705                              &lenRecv
2706                              ) == tiSuccess) && (lenRecv != 0))
2707   {
2708     if (osti_strncmp(buffer, "0x", 2) == 0)
2709     {
2710       HwConfig->intReassertionOption = osti_strtoul (buffer, &pLastUsedChar, 0);
2711     }
2712     else
2713     {
2714       HwConfig->intReassertionOption = osti_strtoul (buffer, &pLastUsedChar, 10);
2715     }
2716   }
2717 
2718   osti_memset(buffer, 0, buffLen);
2719   lenRecv = 0;
2720 
2721   /* interrupt reassetion field*/
2722   if ((ostiGetTransportParam(
2723                              tiRoot,
2724                              globalStr,   /* key */
2725                              HwParmsStr,  /* subkey1 */
2726                              agNULL,      /* subkey2 */
2727                              agNULL,
2728                              agNULL,
2729                              agNULL,      /* subkey5 */
2730                              "HwOption", /* valueName */
2731                              buffer,
2732                              buffLen,
2733                              &lenRecv
2734                              ) == tiSuccess) && (lenRecv != 0))
2735   {
2736     if (osti_strncmp(buffer, "0x", 2) == 0)
2737     {
2738       HwConfig->hwOption = osti_strtoul (buffer, &pLastUsedChar, 0);
2739     }
2740     else
2741     {
2742       HwConfig->hwOption = osti_strtoul (buffer, &pLastUsedChar, 10);
2743     }
2744   }
2745 
2746   osti_memset(buffer, 0, buffLen);
2747   lenRecv = 0;
2748 
2749   /* interrupt reassetion field*/
2750   if ((ostiGetTransportParam(
2751                              tiRoot,
2752                              globalStr,   /* key */
2753                              HwParmsStr,  /* subkey1 */
2754                              agNULL,      /* subkey2 */
2755                              agNULL,
2756                              agNULL,
2757                              agNULL,      /* subkey5 */
2758                              "MaxFWPorts", /* valueName */
2759                              buffer,
2760                              buffLen,
2761                              &lenRecv
2762                              ) == tiSuccess) && (lenRecv != 0))
2763   {
2764     if (osti_strncmp(buffer, "0x", 2) == 0)
2765     {
2766       tdsaAllShared->FWMaxPorts = osti_strtoul (buffer, &pLastUsedChar, 0);
2767     }
2768     else
2769     {
2770       tdsaAllShared->FWMaxPorts = osti_strtoul (buffer, &pLastUsedChar, 10);
2771     }
2772   }
2773 
2774   osti_memset(buffer, 0, buffLen);
2775   lenRecv = 0;
2776 
2777   if ((ostiGetTransportParam(
2778                              tiRoot,
2779                              globalStr,   /* key */
2780                              HwParmsStr,  /* subkey1 */
2781                              agNULL,      /* subkey2 */
2782                              agNULL,
2783                              agNULL,
2784                              agNULL,      /* subkey5 */
2785                              "phyCalibration", /* valueName */
2786                              buffer,
2787                              buffLen,
2788                              &lenRecv
2789                              ) == tiSuccess) && (lenRecv != 0))
2790   {
2791     if (osti_strncmp(buffer, "0x", 2) == 0)
2792     {
2793       tdsaAllShared->phyCalibration = osti_strtoul (buffer, &pLastUsedChar, 0);
2794     }
2795     else
2796     {
2797       tdsaAllShared->phyCalibration = osti_strtoul (buffer, &pLastUsedChar, 10);
2798     }
2799   }
2800 
2801   osti_memset(buffer, 0, buffLen);
2802   lenRecv = 0;
2803 
2804 
2805   /* phy calibration */
2806   for (i=0;i<MAX_INDEX;i++)
2807   {
2808     for(j=0;j<10;j++)
2809     {
2810       osti_sprintf(phyReg,"spaReg%d%d",i,j);
2811       TI_DBG6(("tdsaGetHwConfigParams: phyReg %s\n", phyReg));
2812 
2813       if (j == 0)
2814       {
2815         if ((ostiGetTransportParam(
2816                                tiRoot,
2817                                globalStr,   /* key */
2818                                HwParmsStr,  /* subkey1 */
2819                                agNULL,      /* subkey2 */
2820                                agNULL,
2821                                agNULL,
2822                                agNULL,      /* subkey5 */
2823                                phyReg, /* valueName */
2824                                buffer,
2825                                buffLen,
2826                                &lenRecv
2827                                ) == tiSuccess) && (lenRecv != 0))
2828       {
2829         if (osti_strncmp(buffer, "0x", 2) == 0)
2830         {
2831           phyRegTable->phyAnalogSetupRegisters[i].spaRegister0 = osti_strtoul (buffer, &pLastUsedChar, 0);
2832         }
2833         else
2834         {
2835           phyRegTable->phyAnalogSetupRegisters[i].spaRegister0 = osti_strtoul (buffer, &pLastUsedChar, 10);
2836         }
2837       }
2838 
2839       osti_memset(buffer, 0, buffLen);
2840       lenRecv = 0;
2841       }
2842       else if (j == 1)
2843       {
2844         if ((ostiGetTransportParam(
2845                                tiRoot,
2846                                globalStr,   /* key */
2847                                HwParmsStr,  /* subkey1 */
2848                                agNULL,      /* subkey2 */
2849                                agNULL,
2850                                agNULL,
2851                                agNULL,      /* subkey5 */
2852                                phyReg, /* valueName */
2853                                buffer,
2854                                buffLen,
2855                                &lenRecv
2856                                ) == tiSuccess) && (lenRecv != 0))
2857       {
2858         if (osti_strncmp(buffer, "0x", 2) == 0)
2859         {
2860           phyRegTable->phyAnalogSetupRegisters[i].spaRegister1 = osti_strtoul (buffer, &pLastUsedChar, 0);
2861         }
2862         else
2863         {
2864           phyRegTable->phyAnalogSetupRegisters[i].spaRegister1 = osti_strtoul (buffer, &pLastUsedChar, 10);
2865         }
2866       }
2867 
2868       osti_memset(buffer, 0, buffLen);
2869       lenRecv = 0;
2870       }
2871       else if (j == 2)
2872       {
2873         if ((ostiGetTransportParam(
2874                                tiRoot,
2875                                globalStr,   /* key */
2876                                HwParmsStr,  /* subkey1 */
2877                                agNULL,      /* subkey2 */
2878                                agNULL,
2879                                agNULL,
2880                                agNULL,      /* subkey5 */
2881                                phyReg, /* valueName */
2882                                buffer,
2883                                buffLen,
2884                                &lenRecv
2885                                ) == tiSuccess) && (lenRecv != 0))
2886       {
2887         if (osti_strncmp(buffer, "0x", 2) == 0)
2888         {
2889           phyRegTable->phyAnalogSetupRegisters[i].spaRegister2 = osti_strtoul (buffer, &pLastUsedChar, 0);
2890         }
2891         else
2892         {
2893           phyRegTable->phyAnalogSetupRegisters[i].spaRegister2 = osti_strtoul (buffer, &pLastUsedChar, 10);
2894         }
2895       }
2896 
2897       osti_memset(buffer, 0, buffLen);
2898       lenRecv = 0;
2899       }
2900       else if (j == 3)
2901       {
2902         if ((ostiGetTransportParam(
2903                                tiRoot,
2904                                globalStr,   /* key */
2905                                HwParmsStr,  /* subkey1 */
2906                                agNULL,      /* subkey2 */
2907                                agNULL,
2908                                agNULL,
2909                                agNULL,      /* subkey5 */
2910                                phyReg, /* valueName */
2911                                buffer,
2912                                buffLen,
2913                                &lenRecv
2914                                ) == tiSuccess) && (lenRecv != 0))
2915       {
2916         if (osti_strncmp(buffer, "0x", 2) == 0)
2917         {
2918           phyRegTable->phyAnalogSetupRegisters[i].spaRegister3 = osti_strtoul (buffer, &pLastUsedChar, 0);
2919         }
2920         else
2921         {
2922           phyRegTable->phyAnalogSetupRegisters[i].spaRegister3 = osti_strtoul (buffer, &pLastUsedChar, 10);
2923         }
2924       }
2925 
2926       osti_memset(buffer, 0, buffLen);
2927       lenRecv = 0;
2928       }
2929       else if (j == 4)
2930       {
2931         if ((ostiGetTransportParam(
2932                                tiRoot,
2933                                globalStr,   /* key */
2934                                HwParmsStr,  /* subkey1 */
2935                                agNULL,      /* subkey2 */
2936                                agNULL,
2937                                agNULL,
2938                                agNULL,      /* subkey5 */
2939                                phyReg, /* valueName */
2940                                buffer,
2941                                buffLen,
2942                                &lenRecv
2943                                ) == tiSuccess) && (lenRecv != 0))
2944       {
2945         if (osti_strncmp(buffer, "0x", 2) == 0)
2946         {
2947           phyRegTable->phyAnalogSetupRegisters[i].spaRegister4 = osti_strtoul (buffer, &pLastUsedChar, 0);
2948         }
2949         else
2950         {
2951           phyRegTable->phyAnalogSetupRegisters[i].spaRegister4 = osti_strtoul (buffer, &pLastUsedChar, 10);
2952         }
2953       }
2954 
2955       osti_memset(buffer, 0, buffLen);
2956       lenRecv = 0;
2957       }
2958       else if (j == 5)
2959       {
2960         if ((ostiGetTransportParam(
2961                                tiRoot,
2962                                globalStr,   /* key */
2963                                HwParmsStr,  /* subkey1 */
2964                                agNULL,      /* subkey2 */
2965                                agNULL,
2966                                agNULL,
2967                                agNULL,      /* subkey5 */
2968                                phyReg, /* valueName */
2969                                buffer,
2970                                buffLen,
2971                                &lenRecv
2972                                ) == tiSuccess) && (lenRecv != 0))
2973       {
2974         if (osti_strncmp(buffer, "0x", 2) == 0)
2975         {
2976           phyRegTable->phyAnalogSetupRegisters[i].spaRegister5 = osti_strtoul (buffer, &pLastUsedChar, 0);
2977         }
2978         else
2979         {
2980           phyRegTable->phyAnalogSetupRegisters[i].spaRegister5 = osti_strtoul (buffer, &pLastUsedChar, 10);
2981         }
2982       }
2983 
2984       osti_memset(buffer, 0, buffLen);
2985       lenRecv = 0;
2986       }
2987       else if (j == 6)
2988       {
2989         if ((ostiGetTransportParam(
2990                                tiRoot,
2991                                globalStr,   /* key */
2992                                HwParmsStr,  /* subkey1 */
2993                                agNULL,      /* subkey2 */
2994                                agNULL,
2995                                agNULL,
2996                                agNULL,      /* subkey5 */
2997                                phyReg, /* valueName */
2998                                buffer,
2999                                buffLen,
3000                                &lenRecv
3001                                ) == tiSuccess) && (lenRecv != 0))
3002       {
3003         if (osti_strncmp(buffer, "0x", 2) == 0)
3004         {
3005           phyRegTable->phyAnalogSetupRegisters[i].spaRegister6 = osti_strtoul (buffer, &pLastUsedChar, 0);
3006         }
3007         else
3008         {
3009           phyRegTable->phyAnalogSetupRegisters[i].spaRegister6 = osti_strtoul (buffer, &pLastUsedChar, 10);
3010         }
3011       }
3012 
3013       osti_memset(buffer, 0, buffLen);
3014       lenRecv = 0;
3015       }
3016       else if (j == 7)
3017       {
3018         if ((ostiGetTransportParam(
3019                                tiRoot,
3020                                globalStr,   /* key */
3021                                HwParmsStr,  /* subkey1 */
3022                                agNULL,      /* subkey2 */
3023                                agNULL,
3024                                agNULL,
3025                                agNULL,      /* subkey5 */
3026                                phyReg, /* valueName */
3027                                buffer,
3028                                buffLen,
3029                                &lenRecv
3030                                ) == tiSuccess) && (lenRecv != 0))
3031       {
3032         if (osti_strncmp(buffer, "0x", 2) == 0)
3033         {
3034           phyRegTable->phyAnalogSetupRegisters[i].spaRegister7 = osti_strtoul (buffer, &pLastUsedChar, 0);
3035         }
3036         else
3037         {
3038           phyRegTable->phyAnalogSetupRegisters[i].spaRegister7 = osti_strtoul (buffer, &pLastUsedChar, 10);
3039         }
3040       }
3041 
3042       osti_memset(buffer, 0, buffLen);
3043       lenRecv = 0;
3044       }
3045       else if (j == 8)
3046       {
3047         if ((ostiGetTransportParam(
3048                                tiRoot,
3049                                globalStr,   /* key */
3050                                HwParmsStr,  /* subkey1 */
3051                                agNULL,      /* subkey2 */
3052                                agNULL,
3053                                agNULL,
3054                                agNULL,      /* subkey5 */
3055                                phyReg, /* valueName */
3056                                buffer,
3057                                buffLen,
3058                                &lenRecv
3059                                ) == tiSuccess) && (lenRecv != 0))
3060       {
3061         if (osti_strncmp(buffer, "0x", 2) == 0)
3062         {
3063           phyRegTable->phyAnalogSetupRegisters[i].spaRegister8 = osti_strtoul (buffer, &pLastUsedChar, 0);
3064         }
3065         else
3066         {
3067           phyRegTable->phyAnalogSetupRegisters[i].spaRegister8 = osti_strtoul (buffer, &pLastUsedChar, 10);
3068         }
3069       }
3070 
3071       osti_memset(buffer, 0, buffLen);
3072       lenRecv = 0;
3073       }
3074       else if (j == 9)
3075       {
3076         if ((ostiGetTransportParam(
3077                                tiRoot,
3078                                globalStr,   /* key */
3079                                HwParmsStr,  /* subkey1 */
3080                                agNULL,      /* subkey2 */
3081                                agNULL,
3082                                agNULL,
3083                                agNULL,      /* subkey5 */
3084                                phyReg, /* valueName */
3085                                buffer,
3086                                buffLen,
3087                                &lenRecv
3088                                ) == tiSuccess) && (lenRecv != 0))
3089       {
3090         if (osti_strncmp(buffer, "0x", 2) == 0)
3091         {
3092           phyRegTable->phyAnalogSetupRegisters[i].spaRegister9 = osti_strtoul (buffer, &pLastUsedChar, 0);
3093         }
3094         else
3095         {
3096           phyRegTable->phyAnalogSetupRegisters[i].spaRegister9 = osti_strtoul (buffer, &pLastUsedChar, 10);
3097         }
3098       }
3099 
3100       osti_memset(buffer, 0, buffLen);
3101       lenRecv = 0;
3102       }
3103 
3104     } /* inner loop */
3105   } /* outer loop */
3106   return;
3107 }
3108 /*****************************************************************************
3109 *! \brief tdsaGetCardPhyParams
3110 *
3111 *  Purpose:  This function reads phy-related configuration parameters from the
3112 *            configuration file
3113 *
3114 *  \param  tiRoot:            Pointer to driver/port instance.
3115 *
3116 *  \return: None
3117 *
3118 *  \note - just a place holder for now
3119 *
3120 *****************************************************************************/
3121 osGLOBAL void
3122 tdsaGetCardPhyParams(
3123                  tiRoot_t *tiRoot
3124                  )
3125 {
3126   tdsaRoot_t     *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
3127   tdsaContext_t  *tdsaAllShared = (tdsaContext_t *)&(tdsaRoot->tdsaAllShared);
3128   agsaRoot_t     *agRoot = &tdsaAllShared->agRootInt;
3129   char           *buffer;
3130   bit32          buffLen;
3131   bit32          lenRecv = 0;
3132   char           *pLastUsedChar = agNULL;
3133   char           tmpBuffer[DEFAULT_KEY_BUFFER_SIZE];
3134   char           *globalStr = tdsaAllShared->CardIDString;
3135   char           phyParmsStr[12];
3136   int            i;
3137   bit32          LinkRate = 15, Mode = 3, OpticalMode = 0; //VG
3138   bit32          LinkRateRead = agTRUE, ModeRead = agFALSE, OpticalModeRead = agFALSE;
3139   bit32          flag = agFALSE; /* true only for PM8008 or PM8009 (SPCv and SPCve) controller */
3140 
3141   TI_DBG6(("tdsaGetCardPhyParams: start \n"));
3142   TI_DBG6(("tdsaGetCardPhyParams: tdsaRoot %p tdsaAllShared %p \n", tdsaRoot,tdsaAllShared));
3143 
3144   if (tiIS_8PHY(agRoot))
3145   {
3146     TI_DBG6(("tdsaGetCardPhyParams: SPCv or SPCve \n"));
3147     flag = agTRUE;
3148   }
3149   TI_DBG6(("tdsaGetCardPhyParams: flag %d\n", flag));
3150 
3151 #ifdef REMOVED
3152 #ifdef FPGA_CARD
3153   for (i=0;i<TD_MAX_NUM_PHYS;i++)
3154   {
3155     /* setting default phy properties */
3156     OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01020304);
3157     OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x05060708);
3158     /* 1.5G only, SAS/SATA, no spin-up control */
3159     tdsaAllShared->Ports[i].agPhyConfig.phyProperties = 0x31; /* 49 */
3160   }
3161 #else
3162 #ifdef INITIATOR_DRIVER
3163   /* ASIC */
3164   for (i=0;i<TD_MAX_NUM_PHYS;i++)
3165   {
3166     /* setting default phy properties */
3167     OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01020304);
3168     OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x05060708);
3169     /* 1.5G/3G , SAS/SATA, no spin-up control */
3170     tdsaAllShared->Ports[i].agPhyConfig.phyProperties = 0x37; /* 55 */
3171     TI_DBG6(("tdsaGetCardPhyParams: phy %d hi 0x%x lo 0x%x\n", i, SA_IDFRM_GET_SAS_ADDRESSHI(&(tdsaAllShared->Ports[i].SASID)), SA_IDFRM_GET_SAS_ADDRESSLO(&(tdsaAllShared->Ports[i].SASID))));
3172   }
3173 #endif
3174 
3175 #ifdef TARGET_DRIVER
3176   /* ASIC */
3177   for (i=0;i<TD_MAX_NUM_PHYS;i++)
3178   {
3179     /* setting default phy properties */
3180     OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01020304);
3181     OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x05050500+i);
3182     /* 1.5G/3G , SAS/SATA, no spin-up control */
3183     tdsaAllShared->Ports[i].agPhyConfig.phyProperties = 0x37; /* 55 */
3184     TI_DBG6(("tdsaGetCardPhyParams: phy %d hi 0x%x lo 0x%x\n", i, SA_IDFRM_GET_SAS_ADDRESSHI(&(tdsaAllShared->Ports[i].SASID)), SA_IDFRM_GET_SAS_ADDRESSLO(&(tdsaAllShared->Ports[i].SASID))));
3185   }
3186 #endif
3187 
3188 #endif
3189 #endif /* REMOVED */
3190 
3191 
3192   buffer = tmpBuffer;
3193   buffLen = sizeof(tmpBuffer);
3194 
3195   osti_memset(buffer, 0, buffLen);
3196   lenRecv = 0;
3197 
3198   for (i=0;i<TD_MAX_NUM_PHYS;i++)
3199   {
3200     if (flag == agFALSE)
3201     {
3202       osti_sprintf(phyParmsStr,"PhyParms%d", i);
3203     }
3204     else
3205     {
3206       if (i >= 4)
3207       {
3208         osti_sprintf(phyParmsStr,"PhyParms%d", i+4);
3209       }
3210       else
3211       {
3212         osti_sprintf(phyParmsStr,"PhyParms%d", i);
3213       }
3214     }
3215 
3216     TI_DBG6(("tdsaGetCardPhyParams: i %d PhyParms %s\n", i, phyParmsStr));
3217 
3218     TI_DBG2(("tdsaGetCardPhyParams: phy %d phyProperties %d\n", i, tdsaAllShared->Ports[i].agPhyConfig.phyProperties));
3219 
3220 
3221     if ((ostiGetTransportParam (
3222                                 tiRoot,
3223                                 globalStr,
3224                                 phyParmsStr,
3225                                 agNULL,
3226                                 agNULL,
3227                                 agNULL,
3228                                 agNULL,
3229                                 "AddrHi",
3230                                 buffer,
3231                                 buffLen,
3232                                 &lenRecv
3233                                 ) == tiSuccess) && (lenRecv != 0))
3234     {
3235       if (osti_strncmp(buffer, "0x", 2) == 0)
3236       {
3237         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, osti_strtoul(buffer, &pLastUsedChar, 0));
3238         TI_DBG6(("tdsaGetCardPhyParams: phy %d hi 0x%x \n", i, SA_IDFRM_GET_SAS_ADDRESSHI(&(tdsaAllShared->Ports[i].SASID))));
3239       }
3240       else
3241       {
3242         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, osti_strtoul(buffer, &pLastUsedChar, 10));
3243         TI_DBG6(("tdsaGetCardPhyParams: phy %d hi %d \n", i, SA_IDFRM_GET_SAS_ADDRESSHI(&(tdsaAllShared->Ports[i].SASID))));
3244       }
3245     }
3246 
3247 
3248     osti_memset(buffer, 0, buffLen);
3249     lenRecv = 0;
3250 
3251     if ((ostiGetTransportParam (
3252                                 tiRoot,
3253                                 globalStr,
3254                                 phyParmsStr,
3255                                 agNULL,
3256                                 agNULL,
3257                                 agNULL,
3258                                 agNULL,
3259                                 "AddrLow",
3260                                 buffer,
3261                                 buffLen,
3262                                 &lenRecv
3263                                 ) == tiSuccess) && (lenRecv != 0))
3264     {
3265       if (osti_strncmp(buffer, "0x", 2) == 0)
3266       {
3267         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, osti_strtoul(buffer, &pLastUsedChar, 0));
3268         TI_DBG6(("tdsaGetCardPhyParams: phy %d lo 0x%x\n", i, SA_IDFRM_GET_SAS_ADDRESSLO(&(tdsaAllShared->Ports[i].SASID))));
3269       }
3270       else
3271       {
3272         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, osti_strtoul(buffer, &pLastUsedChar, 10));
3273         TI_DBG6(("tdsaGetCardPhyParams: phy %d lo %d\n", i, SA_IDFRM_GET_SAS_ADDRESSLO(&(tdsaAllShared->Ports[i].SASID))));
3274       }
3275     }
3276     TI_DBG6(("tdsaGetCardPhyParams: loop phy %d hi 0x%x lo 0x%x\n", i, SA_IDFRM_GET_SAS_ADDRESSHI(&(tdsaAllShared->Ports[i].SASID)), SA_IDFRM_GET_SAS_ADDRESSLO(&(tdsaAllShared->Ports[i].SASID))));
3277 
3278     /* phy properties */
3279     osti_memset(buffer, 0, buffLen);
3280     lenRecv = 0;
3281 /*
3282     if ((ostiGetTransportParam (
3283                                 tiRoot,
3284                                 globalStr,
3285                                 phyParmsStr,
3286                                 agNULL,
3287                                 agNULL,
3288                                 agNULL,
3289                                 agNULL,
3290                                 "LinkRate",
3291                                 buffer,
3292                                 buffLen,
3293                                 &lenRecv
3294                                 ) == tiSuccess) && (lenRecv != 0))
3295     {
3296       LinkRateRead = agTRUE;
3297       if (osti_strncmp(buffer, "0x", 2) == 0)
3298       {
3299         LinkRate = osti_strtoul(buffer, &pLastUsedChar, 0);
3300         TI_DBG6(("tdsaGetCardPhyParams: phy %d linkrate 0x%x \n", i, LinkRate));
3301       }
3302       else
3303       {
3304         LinkRate = osti_strtoul(buffer, &pLastUsedChar, 10);
3305         TI_DBG6(("tdsaGetCardPhyParams: phy %d linkrate %d \n", i, LinkRate));
3306       }
3307     }
3308 
3309     TI_DBG2(("tdsaGetCardPhyParams: phy %d linkrate %d \n", i, LinkRate));
3310 */
3311 
3312     osti_memset(buffer, 0, buffLen);
3313     lenRecv = 0;
3314 
3315     if ((ostiGetTransportParam (
3316                                 tiRoot,
3317                                 globalStr,
3318                                 phyParmsStr,
3319                                 agNULL,
3320                                 agNULL,
3321                                 agNULL,
3322                                 agNULL,
3323                                 "Mode",
3324                                 buffer,
3325                                 buffLen,
3326                                 &lenRecv
3327                                 ) == tiSuccess) && (lenRecv != 0))
3328     {
3329       ModeRead = agTRUE;
3330       if (osti_strncmp(buffer, "0x", 2) == 0)
3331       {
3332         Mode = osti_strtoul(buffer, &pLastUsedChar, 0);
3333         TI_DBG6(("tdsaGetCardPhyParams: phy %d Mode 0x%x \n", i, Mode));
3334       }
3335       else
3336       {
3337         Mode = osti_strtoul(buffer, &pLastUsedChar, 10);
3338         TI_DBG6(("tdsaGetCardPhyParams: phy %d Mode %d \n", i, Mode));
3339       }
3340     }
3341 
3342     osti_memset(buffer, 0, buffLen);
3343     lenRecv = 0;
3344 
3345     if ((ostiGetTransportParam (
3346                                 tiRoot,
3347                                 globalStr,
3348                                 phyParmsStr,
3349                                 agNULL,
3350                                 agNULL,
3351                                 agNULL,
3352                                 agNULL,
3353                                 "OpticalMode",
3354                                 buffer,
3355                                 buffLen,
3356                                 &lenRecv
3357                                 ) == tiSuccess) && (lenRecv != 0))
3358     {
3359       OpticalModeRead = agTRUE;
3360       if (osti_strncmp(buffer, "0x", 2) == 0)
3361       {
3362         OpticalMode = osti_strtoul(buffer, &pLastUsedChar, 0);
3363         TI_DBG6(("tdsaGetCardPhyParams: phy %d OpticalMode 0x%x \n", i, OpticalMode));
3364       }
3365       else
3366       {
3367         OpticalMode = osti_strtoul(buffer, &pLastUsedChar, 10);
3368         TI_DBG6(("tdsaGetCardPhyParams: phy %d OpticalMode %d \n", i, OpticalMode));
3369       }
3370     }
3371 
3372     tdsaParseLinkRateMode(tiRoot, i, LinkRateRead, ModeRead, OpticalModeRead, LinkRate, Mode, OpticalMode);
3373 
3374     TI_DBG2(("tdsaGetCardPhyParams: phy %d phyProperties %d\n", i, tdsaAllShared->Ports[i].agPhyConfig.phyProperties));
3375 
3376 
3377     /**********************************************/
3378     osti_memset(buffer, 0, buffLen);
3379     lenRecv = 0;
3380     LinkRateRead = agTRUE;//VG
3381     ModeRead = agFALSE;
3382     OpticalModeRead = agFALSE;
3383 
3384   } /* end for */
3385   return;
3386 }
3387 
3388 
3389 
3390 
3391 
3392 /*****************************************************************************
3393 *! \brief tdsaGetGlobalPhyParams
3394 *
3395 *  Purpose:  This function reads phy-related configuration parameters from the
3396 *            configuration file
3397 *
3398 *  \param  tiRoot:            Pointer to driver/port instance.
3399 *
3400 *  \return: None
3401 *
3402 *  \note - just a place holder for now
3403 *
3404 *****************************************************************************/
3405 osGLOBAL void
3406 tdsaGetGlobalPhyParams(
3407                  tiRoot_t *tiRoot
3408                  )
3409 {
3410   tdsaRoot_t     *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
3411   tdsaContext_t  *tdsaAllShared = (tdsaContext_t *)&(tdsaRoot->tdsaAllShared);
3412   agsaRoot_t     *agRoot = &tdsaAllShared->agRootInt;
3413   char           *buffer;
3414   bit32          buffLen;
3415   bit32          lenRecv = 0;
3416   char           *pLastUsedChar = agNULL;
3417   char           tmpBuffer[DEFAULT_KEY_BUFFER_SIZE];
3418   char           globalStr[]     = "Global";
3419   char           phyParmsStr[12];
3420   int            i;
3421   bit32          LinkRate = 15/*7*/, Mode = 3, OpticalMode = 0;
3422   bit32          LinkRateRead = agFALSE, ModeRead = agFALSE, OpticalModeRead = agFALSE;
3423   bit32          flag = agFALSE; /* true only for PM8008 or PM8009 (SPCv and SPCve) controller */
3424 
3425   TI_DBG6(("tdsaGetGlobalPhyParams: start \n"));
3426   TI_DBG6(("tdsaGetGlobalPhyParams: tdsaRoot %p tdsaAllShared %p \n", tdsaRoot,tdsaAllShared));
3427 
3428   if (tiIS_8PHY(agRoot) )
3429   {
3430     TI_DBG6(("tdsaGetGlobalPhyParams: SPCv or SPCve \n"));
3431     flag = agTRUE;
3432   }
3433 
3434   TI_DBG6(("tdsaGetGlobalPhyParams: flag %d\n", flag));
3435 
3436 #ifdef FPGA_CARD
3437   for (i=0;i<TD_MAX_NUM_PHYS;i++)
3438   {
3439     /* setting default phy properties */
3440     OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01020304);
3441     OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x05060708);
3442     /* 1.5G only, SAS/SATA, no spin-up control */
3443     tdsaAllShared->Ports[i].agPhyConfig.phyProperties = 0x31; /* 49 */
3444   }
3445 #else
3446   /* ASIC */
3447 #ifdef INITIATOR_DRIVER
3448   for (i=0;i<TD_MAX_NUM_PHYS;i++)
3449   {
3450     /* setting default phy properties */
3451     if (flag == agFALSE) /* SPC or SPCv+ */
3452     {
3453       if (0 <= i && i <= 7)
3454       {
3455         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01020304);
3456         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x05060708);
3457       }
3458       else
3459       {
3460         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01010101);
3461         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x02020202);
3462       }
3463     }
3464     else /* SPCv or SPCve */
3465     {
3466       if (0 <= i && i <= 3)
3467       {
3468         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01020304);
3469         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x05060708);
3470       }
3471       else if (4 <= i && i <= 7)
3472       {
3473         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01020304);
3474         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x02020202);
3475       }
3476       else /* don't care */
3477       {
3478         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01010101);
3479         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x0f0f0f0f);
3480       }
3481 
3482     }
3483     /* 1.5G/3G , SAS/SATA, no spin-up control */
3484     tdsaAllShared->Ports[i].agPhyConfig.phyProperties = 0x31; /* 55 */
3485     TI_DBG6(("tdsaGetGlobalPhyParams: phy %d hi 0x%x lo 0x%x\n", i, SA_IDFRM_GET_SAS_ADDRESSHI(&(tdsaAllShared->Ports[i].SASID)), SA_IDFRM_GET_SAS_ADDRESSLO(&(tdsaAllShared->Ports[i].SASID))));
3486 
3487   }
3488 #endif
3489 #ifdef TARGET_DRIVER
3490    for (i=0;i<TD_MAX_NUM_PHYS;i++)
3491   {
3492     /* setting default phy properties */
3493     /* SPC; narrow ports; 8 ports
3494        SPCv, SPCve wide port; 8 ports
3495        SPCv+ wide port; 16 ports
3496     */
3497     if (tiIS_SPC(agRoot))
3498     {
3499        if (0 <= i && i <= 7)
3500       {
3501         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01020304);
3502         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x05050500+i);
3503       }
3504       else
3505       {
3506         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01020304);
3507         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x06060600+i);
3508       }
3509     }
3510     else if (tiIS_16PHY(agRoot))
3511     {
3512        if (0 <= i && i <= 7)
3513       {
3514         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01020304);
3515         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x05050500+i);
3516       }
3517       else
3518       {
3519         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01020304);
3520         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x06060600+i);
3521       }
3522     }
3523     else
3524     {
3525       if (0 <= i && i <= 3)
3526       {
3527         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01020304);
3528         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x05050500+i);
3529       }
3530       else if (4 <= i && i <= 7)
3531       {
3532         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01020304);
3533         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x06060600+i);
3534       }
3535       else /* don't care */
3536       {
3537         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, 0x01020304);
3538         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, 0x0f0f0f0f+i);
3539       }
3540     }
3541     /* 1.5G/3G , SAS/SATA, no spin-up control */
3542     tdsaAllShared->Ports[i].agPhyConfig.phyProperties = 0x31; /* 49 The default is 1.5G and will be changed based on the registry value */
3543     TI_DBG6(("tdsaGetGlobalPhyParams: phy %d hi 0x%x lo 0x%x\n", i, SA_IDFRM_GET_SAS_ADDRESSHI(&(tdsaAllShared->Ports[i].SASID)), SA_IDFRM_GET_SAS_ADDRESSLO(&(tdsaAllShared->Ports[i].SASID))));
3544 
3545   }
3546 #endif
3547 #endif
3548 
3549 
3550   buffer = tmpBuffer;
3551   buffLen = sizeof(tmpBuffer);
3552 
3553   osti_memset(buffer, 0, buffLen);
3554   lenRecv = 0;
3555 
3556   /* needs to read Phy's id frame */
3557   for (i=0;i<TD_MAX_NUM_PHYS;i++)
3558   {
3559     if (flag == agFALSE)
3560     {
3561       osti_sprintf(phyParmsStr,"PhyParms%d", i);
3562     }
3563     else
3564     {
3565       if (i >= 4)
3566       {
3567         osti_sprintf(phyParmsStr,"PhyParms%d", i+4);
3568       }
3569       else
3570       {
3571         osti_sprintf(phyParmsStr,"PhyParms%d", i);
3572       }
3573     }
3574 
3575     TI_DBG6(("tdsaGetGlobalPhyParams: i %d PhyParms %s\n", i, phyParmsStr));
3576 
3577 
3578     if ((ostiGetTransportParam (
3579                                 tiRoot,
3580                                 globalStr,
3581                                 phyParmsStr,
3582                                 agNULL,
3583                                 agNULL,
3584                                 agNULL,
3585                                 agNULL,
3586                                 "AddrHi",
3587                                 buffer,
3588                                 buffLen,
3589                                 &lenRecv
3590                                 ) == tiSuccess) && (lenRecv != 0))
3591     {
3592       if (osti_strncmp(buffer, "0x", 2) == 0)
3593       {
3594         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, osti_strtoul(buffer, &pLastUsedChar, 0));
3595         TI_DBG6(("tdsaGetGlobalPhyParams: phy %d hi 0x%x \n", i, SA_IDFRM_GET_SAS_ADDRESSHI(&(tdsaAllShared->Ports[i].SASID))));
3596       }
3597       else
3598       {
3599         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressHi, 0, osti_strtoul(buffer, &pLastUsedChar, 10));
3600         TI_DBG6(("tdsaGetGlobalPhyParams: phy %d hi %d \n", i, SA_IDFRM_GET_SAS_ADDRESSHI(&(tdsaAllShared->Ports[i].SASID))));
3601 
3602       }
3603     }
3604 
3605 
3606     osti_memset(buffer, 0, buffLen);
3607     lenRecv = 0;
3608 
3609     if ((ostiGetTransportParam (
3610                                 tiRoot,
3611                                 globalStr,
3612                                 phyParmsStr,
3613                                 agNULL,
3614                                 agNULL,
3615                                 agNULL,
3616                                 agNULL,
3617                                 "AddrLow",
3618                                 buffer,
3619                                 buffLen,
3620                                 &lenRecv
3621                                 ) == tiSuccess) && (lenRecv != 0))
3622     {
3623       if (osti_strncmp(buffer, "0x", 2) == 0)
3624       {
3625         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, osti_strtoul(buffer, &pLastUsedChar, 0));
3626         TI_DBG6(("tdsaGetGlobalPhyParams: phy %d lo 0x%x\n", i, SA_IDFRM_GET_SAS_ADDRESSLO(&(tdsaAllShared->Ports[i].SASID))));
3627       }
3628       else
3629       {
3630         OSSA_WRITE_BE_32(agRoot, tdsaAllShared->Ports[i].SASID.sasAddressLo, 0, osti_strtoul(buffer, &pLastUsedChar, 10));
3631         TI_DBG6(("tdsaGetGlobalPhyParams: phy %d lo %d\n", i, SA_IDFRM_GET_SAS_ADDRESSLO(&(tdsaAllShared->Ports[i].SASID))));
3632 
3633       }
3634     }
3635     TI_DBG6(("tdsaGetGlobalPhyParams: loop phy %d hi 0x%x lo 0x%x\n", i, SA_IDFRM_GET_SAS_ADDRESSHI(&(tdsaAllShared->Ports[i].SASID)), SA_IDFRM_GET_SAS_ADDRESSLO(&(tdsaAllShared->Ports[i].SASID))));
3636 
3637     /* phy properties */
3638     osti_memset(buffer, 0, buffLen);
3639     lenRecv = 0;
3640 /*
3641     if ((ostiGetTransportParam (
3642                                 tiRoot,
3643                                 globalStr,
3644                                 phyParmsStr,
3645                                 agNULL,
3646                                 agNULL,
3647                                 agNULL,
3648                                 agNULL,
3649                                 "LinkRate",
3650                                 buffer,
3651                                 buffLen,
3652                                 &lenRecv
3653                                 ) == tiSuccess) && (lenRecv != 0))
3654     {
3655       LinkRateRead = agTRUE;
3656       if (osti_strncmp(buffer, "0x", 2) == 0)
3657       {
3658         LinkRate = osti_strtoul(buffer, &pLastUsedChar, 0);
3659         TI_DBG2(("tdsaGetGlobalPhyParams: phy %d linkrate 0x%x \n", i, LinkRate));
3660       }
3661       else
3662       {
3663         LinkRate = osti_strtoul(buffer, &pLastUsedChar, 10);
3664         TI_DBG2(("tdsaGetGlobalPhyParams: phy %d linkrate %d \n", i, LinkRate));
3665       }
3666     }
3667 */
3668 
3669     osti_memset(buffer, 0, buffLen);
3670     lenRecv = 0;
3671 
3672     if ((ostiGetTransportParam (
3673                                 tiRoot,
3674                                 globalStr,
3675                                 phyParmsStr,
3676                                 agNULL,
3677                                 agNULL,
3678                                 agNULL,
3679                                 agNULL,
3680                                 "Mode",
3681                                 buffer,
3682                                 buffLen,
3683                                 &lenRecv
3684                                 ) == tiSuccess) && (lenRecv != 0))
3685     {
3686       ModeRead = agTRUE;
3687       if (osti_strncmp(buffer, "0x", 2) == 0)
3688       {
3689         Mode = osti_strtoul(buffer, &pLastUsedChar, 0);
3690         TI_DBG2(("tdsaGetGlobalPhyParams: phy %d Mode 0x%x \n", i, Mode));
3691       }
3692       else
3693       {
3694         Mode = osti_strtoul(buffer, &pLastUsedChar, 10);
3695         TI_DBG2(("tdsaGetGlobalPhyParams: phy %d Mode %d \n", i, Mode));
3696       }
3697     }
3698 
3699     osti_memset(buffer, 0, buffLen);
3700     lenRecv = 0;
3701 
3702     if ((ostiGetTransportParam (
3703                                 tiRoot,
3704                                 globalStr,
3705                                 phyParmsStr,
3706                                 agNULL,
3707                                 agNULL,
3708                                 agNULL,
3709                                 agNULL,
3710                                 "OpticalMode",
3711                                 buffer,
3712                                 buffLen,
3713                                 &lenRecv
3714                                 ) == tiSuccess) && (lenRecv != 0))
3715     {
3716       OpticalModeRead = agTRUE;
3717       if (osti_strncmp(buffer, "0x", 2) == 0)
3718       {
3719         OpticalMode = osti_strtoul(buffer, &pLastUsedChar, 0);
3720         TI_DBG2(("tdsaGetGlobalPhyParams: phy %d OpticalMode 0x%x \n", i, OpticalMode));
3721       }
3722       else
3723       {
3724         OpticalMode = osti_strtoul(buffer, &pLastUsedChar, 10);
3725         TI_DBG2(("tdsaGetGlobalPhyParams: phy %d OpticalMode %d \n", i, OpticalMode));
3726       }
3727     }
3728 
3729     TI_DBG2(("tdsaGetGlobalPhyParams:A phy %d phyProperties %d\n", i, tdsaAllShared->Ports[i].agPhyConfig.phyProperties));
3730     tdsaParseLinkRateMode(tiRoot, i, LinkRateRead, ModeRead, OpticalModeRead, LinkRate, Mode, OpticalMode);
3731 
3732     TI_DBG2(("tdsaGetGlobalPhyParams:B phy %d phyProperties %d\n", i, tdsaAllShared->Ports[i].agPhyConfig.phyProperties));
3733 
3734 
3735 
3736     /**********************************************/
3737     osti_memset(buffer, 0, buffLen);
3738     lenRecv = 0;
3739     /* restore default */
3740     LinkRate = 15;
3741     Mode = 3;
3742     OpticalMode = 0;
3743     LinkRateRead = agTRUE;//VG
3744     ModeRead = agFALSE;
3745     OpticalModeRead = agFALSE;
3746 
3747 
3748   } /* end for */
3749 
3750   return;
3751 }
3752 
3753 /*****************************************************************************
3754 *! \brief  tdsaGetPortParams
3755 *
3756 *  Purpose:  This function reads port-related configuration parameters from the
3757 *            configuration file
3758 *
3759 *  \param  tiRoot:            Pointer to driver/port instance.
3760 *
3761 *  \return:     None
3762 *
3763 *  \note - just a place holder for now
3764 *
3765 *****************************************************************************/
3766 osGLOBAL void
3767 tdsaGetPortParams(
3768                   tiRoot_t *tiRoot
3769                   )
3770 {
3771   tdsaRoot_t     *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
3772   tdsaContext_t  *tdsaAllShared = (tdsaContext_t *)&(tdsaRoot->tdsaAllShared);
3773 
3774 
3775   char    *buffer;
3776   bit32   buffLen;
3777   bit32   lenRecv = 0;
3778   char    *pLastUsedChar = agNULL;
3779   char    tmpBuffer[DEFAULT_KEY_BUFFER_SIZE];
3780   char    globalStr[]     = "Global";
3781   char    portParmsStr[] = "PortParms";
3782 
3783   TI_DBG6(("tdsaGetPortParams: start \n"));
3784   TI_DBG6(("tdsaGetPortParams: tdsaRoot %p tdsaAllShared %p \n", tdsaRoot,tdsaAllShared));
3785 
3786   buffer = tmpBuffer;
3787   buffLen = sizeof(tmpBuffer);
3788   osti_memset(buffer, 0, buffLen);
3789 
3790   if ((ostiGetTransportParam (
3791                               tiRoot,
3792                               globalStr,
3793                               portParmsStr,
3794                               agNULL,
3795                               agNULL,
3796                               agNULL,
3797                               agNULL,
3798                               "InterruptDelay",
3799                               buffer,
3800                               buffLen,
3801                               &lenRecv
3802                               ) == tiSuccess) && (lenRecv != 0))
3803   {
3804     if (osti_strncmp(buffer, "0x", 2) == 0)
3805     {
3806       tdsaAllShared->currentInterruptDelay = osti_strtoul (buffer, &pLastUsedChar, 0);
3807     }
3808     else
3809     {
3810       tdsaAllShared->currentInterruptDelay = osti_strtoul (buffer, &pLastUsedChar, 10);
3811     }
3812     TI_DBG6(("tdsaGetPortParams: in \n"));
3813   }
3814   osti_memset(buffer, 0, buffLen);
3815   lenRecv = 0;
3816 
3817   TI_DBG6(("tdsaGetPortParams: out \n"));
3818 
3819   /* and more .... */
3820 
3821 
3822   return;
3823 }
3824 
3825 #ifdef FW_EVT_LOG_TST
3826 void saLogDump(agsaRoot_t *agRoot,
3827                U32    *eventLogSize,
3828                U32   **eventLogAddress);
3829 
3830 void tiLogDump(tiRoot_t *tiRoot, U32 *size, U32 **addr)
3831 {
3832   tdsaRoot_t    *tdsaRoot;
3833   tdsaContext_t *tdsaAllShared;
3834 
3835   tdsaRoot = (tdsaRoot_t*)tiRoot->tdData;
3836   tdsaAllShared = (tdsaContext_t*)&(tdsaRoot->tdsaAllShared);
3837   saLogDump(&tdsaAllShared->agRootNonInt, size, addr);
3838 }
3839 #endif
3840 
3841 
3842 
3843 /*****************************************************************************
3844 *! \brief  tiCOMPortInit
3845 *
3846 *  Purpose: This function is called to initialize the port hardware.
3847 *           This call could only be called until after the successful
3848 *           completion tiCOMInit().
3849 *
3850 *  \param   tiRoot:         Pointer to root data structure.
3851 *  \param   sysIntsActive:  system interrupt flag
3852 *
3853 *  \return:
3854 *           tiSuccess:      Successful.
3855 *           Others:             Fail.
3856 *
3857 *  \note -
3858 *
3859 *****************************************************************************/
3860 osGLOBAL bit32
3861 tiCOMPortInit(
3862               tiRoot_t      *tiRoot,
3863               bit32         sysIntsActive
3864               )
3865 {
3866   tdsaRoot_t          *tdsaRoot;
3867   tdsaContext_t       *tdsaAllShared;
3868   agsaRoot_t          *agRoot;
3869   tiLoLevelResource_t *loResource;
3870   bit32                status = tiError;
3871   bit32                i;
3872 
3873   agsaQueueConfig_t   *QueueConfig;
3874 
3875 #ifdef CONTROLLER_STATUS_TESTING
3876   static agsaControllerStatus_t  agcontrollerStatus;
3877 #endif /* CONTROLLER_STATUS_TESTING */
3878 
3879 #ifdef CONTROLLER_INFO_TESTING
3880   static agsaControllerInfo_t  agcontrollerInfo;
3881 #endif /* CONTROLLER_INFO_TESTING */
3882 
3883 #ifdef CONTROLLER_ENCRYPT_TESTING
3884   static  agsaEncryptInfo_t       agsaEncryptInfo;
3885 #endif /* CONTROLLER_INFO_TESTING */
3886 
3887   static agsaMemoryRequirement_t agMemoryRequirement;
3888 #ifdef ECHO_TESTING
3889   /* temp */
3890   static   bit8                     payload[56];
3891 #endif
3892 
3893 #if defined(FDS_DM) || defined(FDS_SM)
3894   static agsaMemoryRequirement_t memRequirement;
3895   bit32                          maxQueueSets = 0;
3896   bit32                          LLMemCount = 0;
3897   bit32                          usecsPerTick = 0;
3898   static agsaSwConfig_t          tmpLLSwConfig;
3899 #endif
3900 
3901 #ifdef FDS_DM
3902    static  dmRoot_t                       *dmRoot = agNULL;
3903 #ifdef FDS_SM
3904    static dmSwConfig_t                   dmSwConfig;
3905 #endif
3906   static dmMemoryRequirement_t   dmMemRequirement;
3907   bit32                          DMMemCount = 0;
3908 #endif
3909 
3910 #if defined(FDS_DM) && defined(FDS_SM)
3911   bit32                          dmUsecsPerTick = 0;
3912   bit32                          dmMaxNumLocks = 0;
3913 #endif
3914 
3915 #ifdef FDS_SM
3916   smRoot_t                       *smRoot = agNULL;
3917 //  smSwConfig_t                   smSwConfig;
3918   static smMemoryRequirement_t   smMemRequirement;
3919   bit32                          SMMemCount = 0;
3920 #endif
3921 
3922 #ifndef TURN_OFF_HDA
3923   static agsaFwImg_t                    HDAImg;
3924 #endif /*  TURN_OFF_HDA */
3925 
3926   TI_DBG3(("tiCOMPortInit: start\n"));
3927   TI_DBG6(("tiCOMPortInit: sizeof agsaMemoryRequirement_t %d\n", (int)sizeof(agsaMemoryRequirement_t)));
3928 
3929   tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
3930   tdsaAllShared = (tdsaContext_t *)&(tdsaRoot->tdsaAllShared);
3931 
3932   osti_memset(&agMemoryRequirement, 0, sizeof(agsaMemoryRequirement_t));
3933   /*
3934    * don't do anything if reset is in progress
3935    */
3936   if (tdsaAllShared->flags.resetInProgress == agTRUE)
3937   {
3938     TI_DBG1(("tiCOMPortInit: resetinProgress error\n"));
3939     return tiError;
3940   }
3941 
3942   loResource = &(tdsaAllShared->loResource);
3943 
3944   agRoot = &(tdsaAllShared->agRootNonInt);
3945   tdsaAllShared->flags.sysIntsActive    = sysIntsActive;
3946 
3947   /*
3948      gets port-related parameters; not in use for now
3949      tdsaGetPortParams(tiRoot);
3950    */
3951 
3952   /* call these before agroot is created  for testing */
3953 
3954 
3955 #ifdef CONTROLLER_STATUS_TESTING
3956   TI_DBG1(("tiCOMPortInit: saGetControllerStatus returns 0x%X\n",saGetControllerStatus(agRoot,&agcontrollerStatus ) ));
3957 #endif /* CONTROLLER_INFO_TESTING */
3958 
3959 #ifdef CONTROLLER_INFO_TESTING
3960   TI_DBG1(("tiCOMPortInit: saGetControllerInfo returns 0x%X\n",saGetControllerInfo(agRoot,&agcontrollerInfo ) ));
3961 #endif /* CONTROLLER_INFO_TESTING */
3962 
3963 #ifdef CONTROLLER_ENCRYPT_TESTING
3964   TI_DBG1(("tiCOMPortInit: saEncryptGetMode returns 0x%X\n",saEncryptGetMode(agRoot,agNULL, &agsaEncryptInfo ) ));
3965 #endif /* CONTROLLER_INFO_TESTING */
3966 
3967 
3968   tdsaGetSwConfigParams(tiRoot);
3969   tdsaPrintSwConfig(&(tdsaAllShared->SwConfig));
3970 
3971   /* setting interrupt requirements */
3972   tdsaAllShared->SwConfig.max_MSIX_InterruptVectors = loResource->loLevelOption.maxInterruptVectors;
3973   tdsaAllShared->SwConfig.max_MSI_InterruptVectors = loResource->loLevelOption.max_MSI_InterruptVectors;
3974   tdsaAllShared->SwConfig.legacyInt_X = loResource->loLevelOption.flag;
3975   TI_DBG2(("tiCOMPortInit: got max_MSIX_InterruptVectors %d \n", tdsaAllShared->SwConfig.max_MSIX_InterruptVectors));
3976   TI_DBG2(("tiCOMPortInit: got max_MSI_InterruptVectors %d \n", tdsaAllShared->SwConfig.max_MSI_InterruptVectors));
3977   TI_DBG2(("tiCOMPortInit: got flag - legacyInt_X %d \n", tdsaAllShared->SwConfig.legacyInt_X));
3978 
3979   /* error checking for interrupt types */
3980   if (
3981       ((tdsaAllShared->SwConfig.max_MSIX_InterruptVectors == 0) &&
3982        (tdsaAllShared->SwConfig.max_MSI_InterruptVectors == 0)  &&
3983        (tdsaAllShared->SwConfig.legacyInt_X == 0))
3984       ||
3985       ((tdsaAllShared->SwConfig.max_MSIX_InterruptVectors != 0) &&
3986        (tdsaAllShared->SwConfig.max_MSI_InterruptVectors == 0)  &&
3987        (tdsaAllShared->SwConfig.legacyInt_X == 0))
3988       ||
3989       ((tdsaAllShared->SwConfig.max_MSIX_InterruptVectors == 0) &&
3990        (tdsaAllShared->SwConfig.max_MSI_InterruptVectors != 0)  &&
3991        (tdsaAllShared->SwConfig.legacyInt_X == 0))
3992       ||
3993       ((tdsaAllShared->SwConfig.max_MSIX_InterruptVectors == 0) &&
3994        (tdsaAllShared->SwConfig.max_MSI_InterruptVectors == 0)  &&
3995        (tdsaAllShared->SwConfig.legacyInt_X != 0))
3996      )
3997   {
3998     /* do nothing */
3999   }
4000   else
4001   {
4002     TI_DBG1(("tiCOMPortInit: incorrect interrupt\n"));
4003     return tiError;
4004   }
4005 
4006   QueueConfig = &tdsaAllShared->QueueConfig;
4007 
4008   for(i=0;i<QueueConfig->numInboundQueues;i++)
4009   {
4010     QueueConfig->inboundQueues[i].elementCount = tdsaAllShared->InboundQueueSize[i];
4011     QueueConfig->inboundQueues[i].elementSize = tdsaAllShared->InboundQueueEleSize[i];
4012     QueueConfig->inboundQueues[i].priority = tdsaAllShared->InboundQueuePriority[i];
4013     QueueConfig->inboundQueues[i].reserved = 0;
4014     TI_DBG6(("tiCOMPortInit: InboundQueuePriroity %d \n", tdsaAllShared->InboundQueuePriority[i]));
4015   }
4016   for(i=0;i<QueueConfig->numOutboundQueues;i++)
4017   {
4018     QueueConfig->outboundQueues[i].elementCount = tdsaAllShared->OutboundQueueSize[i];
4019     QueueConfig->outboundQueues[i].elementSize = tdsaAllShared->OutboundQueueEleSize[i];
4020     QueueConfig->outboundQueues[i].interruptDelay = tdsaAllShared->OutboundQueueInterruptDelay[i]; /* default 0; no interrupt delay */
4021     QueueConfig->outboundQueues[i].interruptCount = tdsaAllShared->OutboundQueueInterruptCount[i]; /* default 1 */
4022     QueueConfig->outboundQueues[i].interruptEnable = tdsaAllShared->OutboundQueueInterruptEnable[i]; /* default 1 */
4023     QueueConfig->outboundQueues[i].interruptVectorIndex = 0;
4024     if (tdsaAllShared->SwConfig.max_MSIX_InterruptVectors != 0)
4025     {
4026       QueueConfig->outboundQueues[i].interruptVectorIndex = i % tdsaAllShared->SwConfig.max_MSIX_InterruptVectors;
4027     }
4028     else if (tdsaAllShared->SwConfig.max_MSI_InterruptVectors != 0)
4029     {
4030       QueueConfig->outboundQueues[i].interruptVectorIndex = i % tdsaAllShared->SwConfig.max_MSI_InterruptVectors;
4031     }
4032     else
4033     {
4034       QueueConfig->outboundQueues[i].interruptVectorIndex = 0;
4035     }
4036     TI_DBG6(("tiCOMPortInit: OutboundQueueInterruptDelay %d OutboundQueueInterruptCount %d OutboundQueueInterruptEnable %d\n", tdsaAllShared->OutboundQueueInterruptDelay[i], tdsaAllShared->OutboundQueueInterruptCount[i], tdsaAllShared->OutboundQueueInterruptEnable[i]));
4037 
4038   }
4039   /* queue option */
4040   QueueConfig->queueOption = tdsaAllShared->QueueOption;
4041 
4042   tdsaAllShared->SwConfig.param3 = (void *)QueueConfig;
4043   tdsaAllShared->SwConfig.stallUsec = 10;
4044 
4045   /* finds a first high priority queue for SMP */
4046   tdsaAllShared->SMPQNum = 0; /* default */
4047   for(i=0;i<QueueConfig->numInboundQueues;i++)
4048   {
4049     if (QueueConfig->inboundQueues[i].priority != DEFAULT_INBOUND_QUEUE_PRIORITY) /* 0 */
4050     {
4051       tdsaAllShared->SMPQNum = i;
4052       break;
4053     }
4054   }
4055 
4056   tdsaGetHwConfigParams(tiRoot);
4057 
4058   tdsaPrintHwConfig(&(tdsaAllShared->HwConfig));
4059 
4060 #ifdef TARGET_DRIVER
4061   /* target, not yet */
4062   if (tdsaAllShared->currentOperation & TD_OPERATION_TARGET)
4063   {
4064     ttdssGetTargetParams(tiRoot);
4065   }
4066 #endif
4067 
4068 #if defined(FDS_DM) && defined(FDS_SM)
4069   /*
4070     needs to call saGetRequirements() to find out agMemoryRequirement.count requested by LL
4071   */
4072   osti_memcpy(&tmpLLSwConfig, &(tdsaAllShared->SwConfig), sizeof(agsaSwConfig_t));
4073 
4074   saGetRequirements(agRoot,
4075                     &tmpLLSwConfig,
4076                     &memRequirement,
4077                     &usecsPerTick,
4078                     &maxQueueSets
4079                     );
4080   TI_DBG1(("tiCOMPortInit: usecsPerTick %d\n", usecsPerTick));
4081 
4082   TI_DBG1(("tiCOMPortInit: LL memRequirement.count %d\n", memRequirement.count));
4083   TI_DBG1(("tiCOMPortInit: loResource->loLevelMem.count %d\n", loResource->loLevelMem.count));
4084   LLMemCount = memRequirement.count;
4085 
4086   /*
4087     needs to call dmGetRequirements() to find out dmMemoryRequirement.count requested by DM
4088   */
4089 
4090   dmGetRequirements(dmRoot,
4091                     &dmSwConfig,
4092                     &dmMemRequirement,
4093                     &dmUsecsPerTick,
4094                     &dmMaxNumLocks
4095                     );
4096 
4097   TI_DBG1(("tiCOMPortInit: DM dmmemRequirement.count %d\n", dmMemRequirement.count));
4098   TI_DBG1(("tiCOMPortInit: loResource->loLevelMem.count %d\n", loResource->loLevelMem.count));
4099 
4100   DMMemCount = dmMemRequirement.count;
4101   SMMemCount = loResource->loLevelMem.count - LLMemCount - DMMemCount;
4102   agMemoryRequirement.count =  LLMemCount;
4103 
4104   TI_DBG1(("tiCOMPortInit: SMMemCount %d\n", SMMemCount));
4105 
4106 
4107 #elif defined(FDS_DM)
4108   /*
4109     needs to call saGetRequirements() to find out agMemoryRequirement.count requested by LL
4110   */
4111   osti_memcpy(&tmpLLSwConfig, &(tdsaAllShared->SwConfig), sizeof(agsaSwConfig_t));
4112 
4113   saGetRequirements(agRoot,
4114                     &tmpLLSwConfig,
4115                     &memRequirement,
4116                     &usecsPerTick,
4117                     &maxQueueSets
4118                     );
4119 
4120   TI_DBG1(("tiCOMPortInit: memRequirement.count %d\n", memRequirement.count));
4121   TI_DBG1(("tiCOMPortInit: loResource->loLevelMem.count %d\n", loResource->loLevelMem.count));
4122 
4123   LLMemCount = memRequirement.count;
4124   DMMemCount = loResource->loLevelMem.count - LLMemCount;
4125 
4126   agMemoryRequirement.count =  LLMemCount;
4127 
4128 #elif defined(FDS_SM)
4129   osti_memcpy(&tmpLLSwConfig, &(tdsaAllShared->SwConfig), sizeof(agsaSwConfig_t));
4130 
4131   saGetRequirements(agRoot,
4132                     &tmpLLSwConfig,
4133                     &memRequirement,
4134                     &usecsPerTick,
4135                     &maxQueueSets
4136                     );
4137 
4138   TI_DBG1(("tiCOMPortInit: memRequirement.count %d\n", memRequirement.count));
4139   TI_DBG1(("tiCOMPortInit: loResource->loLevelMem.count %d\n", loResource->loLevelMem.count));
4140 
4141   LLMemCount = memRequirement.count;
4142   SMMemCount = loResource->loLevelMem.count - LLMemCount;
4143 
4144   agMemoryRequirement.count =  LLMemCount;
4145 
4146 #else
4147 
4148   agMemoryRequirement.count = loResource->loLevelMem.count;
4149 
4150 #endif
4151 
4152 #if defined(FDS_DM) && defined(FDS_SM)
4153   /* for debugging */
4154   for(i=0;i<(int)(LLMemCount + DMMemCount + SMMemCount);i++)
4155   {
4156     TI_DBG2(("tiCOMPortInit: index %d phyAddrUpper 0x%x phyAddrLower 0x%x totalLength %d alignment %d\n", i, loResource->loLevelMem.mem[i].physAddrUpper, loResource->loLevelMem.mem[i].physAddrLower, loResource->loLevelMem.mem[i].totalLength, loResource->loLevelMem.mem[i].alignment));
4157     TI_DBG2(("tiCOMPortInit: index %d virtPtr %p\n",i, loResource->loLevelMem.mem[i].virtPtr));
4158   }
4159 #endif
4160 
4161   /* initialize */
4162   TI_DBG6(("tiCOMPortInit: AGSA_NUM_MEM_CHUNKS %d\n", AGSA_NUM_MEM_CHUNKS));
4163   for(i=0;i<AGSA_NUM_MEM_CHUNKS;i++)
4164   {
4165     agMemoryRequirement.agMemory[i].virtPtr = agNULL;
4166     agMemoryRequirement.agMemory[i].osHandle = agNULL;
4167     agMemoryRequirement.agMemory[i].phyAddrUpper = 0;
4168     agMemoryRequirement.agMemory[i].phyAddrLower = 0;
4169     agMemoryRequirement.agMemory[i].totalLength = 0;
4170     agMemoryRequirement.agMemory[i].numElements = 0;
4171     agMemoryRequirement.agMemory[i].singleElementLength = 0;
4172     agMemoryRequirement.agMemory[i].alignment = 0;
4173     agMemoryRequirement.agMemory[i].type = 0;
4174     agMemoryRequirement.agMemory[i].reserved = 0;
4175   }
4176 
4177   for(i=0;i<(int)agMemoryRequirement.count;i++)
4178   {
4179     TI_DBG2(("tiCOMPortInit: LL copying loResource.loLevelMem to agsaMemoryRequirement_t index %d\n", i));
4180     agMemoryRequirement.agMemory[i].virtPtr = loResource->loLevelMem.mem[i].virtPtr;
4181     agMemoryRequirement.agMemory[i].osHandle = loResource->loLevelMem.mem[i].osHandle;
4182     agMemoryRequirement.agMemory[i].phyAddrUpper = loResource->loLevelMem.mem[i].physAddrUpper;
4183     agMemoryRequirement.agMemory[i].phyAddrLower = loResource->loLevelMem.mem[i].physAddrLower;
4184     agMemoryRequirement.agMemory[i].totalLength = loResource->loLevelMem.mem[i].totalLength;
4185     agMemoryRequirement.agMemory[i].numElements = loResource->loLevelMem.mem[i].numElements;
4186     agMemoryRequirement.agMemory[i].singleElementLength = loResource->loLevelMem.mem[i].singleElementLength;
4187     agMemoryRequirement.agMemory[i].alignment = loResource->loLevelMem.mem[i].alignment;
4188     if (loResource->loLevelMem.mem[i].type == TI_DMA_MEM)
4189     {
4190       agMemoryRequirement.agMemory[i].type = AGSA_DMA_MEM;
4191     }
4192     else if (loResource->loLevelMem.mem[i].type == TI_CACHED_MEM)
4193     {
4194       agMemoryRequirement.agMemory[i].type = AGSA_CACHED_MEM;
4195 
4196     }
4197     else if (loResource->loLevelMem.mem[i].type == TI_CACHED_DMA_MEM)
4198     {
4199       agMemoryRequirement.agMemory[i].type = AGSA_CACHED_DMA_MEM;
4200     }
4201 
4202     agMemoryRequirement.agMemory[i].reserved = loResource->loLevelMem.mem[i].reserved;
4203     TI_DBG2(("tiCOMPortInit: index %d virtPtr %p osHandle %p\n",i, loResource->loLevelMem.mem[i].virtPtr, loResource->loLevelMem.mem[i].osHandle));
4204     TI_DBG2(("tiCOMPortInit: index %d phyAddrUpper 0x%x phyAddrLower 0x%x totalLength %d numElements %d\n", i,
4205     loResource->loLevelMem.mem[i].physAddrUpper,
4206     loResource->loLevelMem.mem[i].physAddrLower,
4207     loResource->loLevelMem.mem[i].totalLength,
4208     loResource->loLevelMem.mem[i].numElements));
4209     TI_DBG2(("tiCOMPortInit: index %d singleElementLength 0x%x alignment 0x%x type %d reserved %d\n", i,
4210     loResource->loLevelMem.mem[i].singleElementLength,
4211     loResource->loLevelMem.mem[i].alignment,
4212     loResource->loLevelMem.mem[i].type,
4213     loResource->loLevelMem.mem[i].reserved));
4214 
4215   }
4216   osti_memset(&(tdsaAllShared->tdFWControlEx), 0, sizeof(tdFWControlEx_t));
4217 
4218   /*
4219    * Note: Be sure to call this only once since sallsdk does initialization only once
4220    * saInitialize(IN, IN, IN, IN, IN);
4221    */
4222 
4223   TI_DBG1(("tiCOMPortInit: tdsaAllShared->tdDeviceIdVendId %x\n",tdsaAllShared->tdDeviceIdVendId));
4224   TI_DBG1(("tiCOMPortInit: tdsaAllShared->tdSubVendorId= SUB_VEN_ID %x\n",tdsaAllShared->tdSubVendorId));
4225 
4226   TI_DBG1(("tiCOMPortInit: swConfig->param1 hwDEVICE_ID_VENDID %x\n", tdsaAllShared->SwConfig.param1 ));
4227   TI_DBG1(("tiCOMPortInit: swConfig->param2 hwSVID             %x\n", tdsaAllShared->SwConfig.param2));
4228 
4229   /*
4230     1. Read hostDirectAccessSupport
4231     2. If set, read HDA images based on chip ID
4232  */
4233 
4234   t_MacroCheck(agRoot);
4235 
4236 #ifndef TURN_OFF_HDA
4237   if (tdsaAllShared->SwConfig.hostDirectAccessSupport != 0)
4238   {
4239     osti_memset(&HDAImg, 0, sizeof(HDAImg));
4240     if (tiIS_SPC(agRoot))
4241     {
4242       TI_DBG1(("tiCOMPortInit: SPC HDA\n"));
4243       HDAImg.aap1Img = (bit8*)(&aap1array);
4244       HDAImg.aap1Len = sizeof( aap1array);
4245       HDAImg.iopImg  = (bit8*)(&ioparray);
4246       HDAImg.iopLen  = sizeof(  ioparray);
4247       HDAImg.istrImg = (bit8*)(&istrarray);
4248       HDAImg.istrLen = sizeof( istrarray);
4249 
4250       HDAImg.ilaImg  = (bit8*)(&ilaarray);
4251       HDAImg.ilaLen  = sizeof(ilaarray);
4252     }
4253     else if (tiIS_SPC6V(agRoot))
4254     {
4255       TI_DBG1(("tiCOMPortInit: SPCv HDA\n"));
4256       HDAImg.aap1Img = (bit8*)(&spcv_aap1array);
4257       HDAImg.aap1Len =  sizeof( spcv_aap1array);
4258       HDAImg.iopImg  = (bit8*)(&spcv_ioparray);
4259       HDAImg.iopLen  = sizeof(  spcv_ioparray);
4260 
4261       HDAImg.ilaImg  = (bit8*)(&spcv_ilaarray);
4262       HDAImg.ilaLen  = sizeof(spcv_ilaarray);
4263     }
4264     else if (tIsSPCV12G(agRoot))
4265     {
4266       TI_DBG1(("tiCOMPortInit: SPCv12G HDA\n"));
4267       HDAImg.aap1Img = (bit8*)(&spcv12g_raaearray);
4268       HDAImg.aap1Len =  sizeof( spcv12g_raaearray);
4269       HDAImg.iopImg  = (bit8*)(&spcv12g_ioparray);
4270       HDAImg.iopLen  = sizeof(  spcv12g_ioparray);
4271 
4272       HDAImg.ilaImg  = (bit8*)(&spcv12g_ilaarray);
4273       HDAImg.ilaLen  = sizeof(spcv12g_ilaarray);
4274     }
4275     else
4276     {
4277       TI_DBG1(("tiCOMPortInit: HDA Mode Unknown chip type 0x%08x\n",ossaHwRegReadConfig32(agRoot,0 )));
4278       return tiError;
4279     }
4280     TI_DBG1(("tiCOMPortInit: HDA aap1Len 0x%08x iopLen 0x%08x ilaLen 0x%08x\n",HDAImg.aap1Len,HDAImg.iopLen,HDAImg.ilaLen ));
4281     tdsaAllShared->SwConfig.param4 = &(HDAImg);
4282   }
4283   else
4284   {
4285     TI_DBG1(("tiCOMPortInit: HDA off\n"));
4286     tdsaAllShared->SwConfig.param4 = agNULL;
4287   }
4288 #endif /*  TURN_OFF_HDA */
4289 
4290   if (tiIS_SPC(agRoot))
4291   {
4292     /* FW config is only for SPC */
4293     tdsaAllShared->SwConfig.FWConfig = 0;
4294     /* default port recovery timer 0x32 = 50 = 5000ms and port reset timer 3 (300 ms)*/
4295     tdsaAllShared->SwConfig.PortRecoveryResetTimer = 0x30032;
4296     TI_DBG1(("tiCOMPortInit:only for SPC FWConfig set\n"));
4297   }
4298 
4299   tdsaAllShared->SwConfig.fatalErrorInterruptVector = loResource->loLevelOption.maxInterruptVectors > 31 ? 31 : loResource->loLevelOption.maxInterruptVectors -1;
4300 
4301   TI_DBG1(("tiCOMPortInit: SwConfig->FWConfig 0x%x\n", tdsaAllShared->SwConfig.FWConfig));
4302   TI_DBG1(("tiCOMPortInit: SwConfig->fatalErrorInterruptVector 0x%x\n", tdsaAllShared->SwConfig.fatalErrorInterruptVector));
4303   TI_DBG1(("tiCOMPortInit: loResource->loLevelOption.usecsPerTick %d\n", loResource->loLevelOption.usecsPerTick));
4304 
4305   status = saInitialize(agRoot,
4306                         &agMemoryRequirement,
4307                         &(tdsaAllShared->HwConfig),
4308                         /* &temp_HwConfig, */
4309                         &(tdsaAllShared->SwConfig),
4310                         loResource->loLevelOption.usecsPerTick);
4311 
4312   TI_DBG6(("tiCOMPortInit: loResource->loLevelOption.usecsPerTick %d 0x%x\n", loResource->loLevelOption.usecsPerTick, loResource->loLevelOption.usecsPerTick));
4313 
4314   /*TI_DBG6(("tiCOMPortInit: tdsaAllShared->SwConfig.enableDIF %d\n", tdsaAllShared->SwConfig.enableDIF)); */
4315   /*TI_DBG6(("tiCOMPortInit: tdsaAllShared->SwConfig.enableEncryption %d\n", tdsaAllShared->SwConfig.enableEncryption)); */
4316 
4317   if(status == AGSA_RC_FAILURE )
4318   {
4319     TI_DBG1(("tiCOMPortInit: saInitialize AGSA_RC_FAILURE, status 0x%x\n", status));
4320     return tiError;
4321   }
4322 
4323   if( status == AGSA_RC_VERSION_INCOMPATIBLE)
4324   {
4325     TI_DBG1(("tiCOMPortInit: saInitialize AGSA_RC_VERSION_INCOMPATIBLE, status 0x%x\n", status));
4326     return tiError;
4327   }
4328 
4329   /* let's make sdkData same for Int and Non-int agRoots */
4330   tdsaAllShared->agRootInt.sdkData = tdsaAllShared->agRootNonInt.sdkData;
4331 
4332 
4333   /* mark the port as initialized */
4334   for(i=0;i<TD_MAX_NUM_PHYS;i++)
4335   {
4336     tdsaAllShared->Ports[i].flags.portInitialized = agTRUE;
4337   }
4338 
4339 #ifdef INITIATOR_DRIVER                 //ini. only in stsdkll spec (TP)
4340   /* register device registration callback function */
4341   TI_DBG6(("tiCOMPortInit: calling saRegisterEventCallback for device registration\n"));
4342   status = saRegisterEventCallback(agRoot, OSSA_EVENT_SOURCE_DEVICE_HANDLE_ADDED, (void *)ossaDeviceRegistrationCB);
4343   if (status == AGSA_RC_FAILURE)
4344   {
4345     TI_DBG6(("tiCOMPortInit: saRegisterEventCallback Device Register failed\n"));
4346   }
4347   else
4348   {
4349     TI_DBG6(("tiCOMPortInit: saRegisterEventCallback Device Register succeeded\n"));
4350   }
4351 #endif
4352 
4353   /* register device deregistration callback function */
4354   TI_DBG6(("tiCOMPortInit: calling saRegisterEventCallback for device de-registration\n"));
4355   status = saRegisterEventCallback(agRoot, OSSA_EVENT_SOURCE_DEVICE_HANDLE_REMOVED, (void *)ossaDeregisterDeviceHandleCB);
4356   if (status == AGSA_RC_FAILURE)
4357   {
4358     TI_DBG6(("tiCOMPortInit: saRegisterEventCallback Device Deregister failed\n"));
4359   }
4360   else
4361   {
4362     TI_DBG6(("tiCOMPortInit: saRegisterEventCallback Device Deregister succeeded\n"));
4363   }
4364 
4365 #ifdef ECHO_TESTING
4366   /* temporary to test saEchoCommand() */
4367   /*
4368     send echo
4369   */
4370   payload[0] = gEcho;
4371   payload[55] = gEcho;
4372   TI_DBG2(("tiCOMPortInit: calling saEchoCommand gEcho %d\n", gEcho));
4373   saEchoCommand(agRoot, agNULL, tdsaRotateQnumber(tiRoot, agNULL), (void *)&payload);
4374   gEcho++;
4375 #endif
4376 
4377 #ifdef CONTROLLER_STATUS_TESTING
4378   TI_DBG1(("tiCOMPortInit: saGetControllerStatus returns 0x%X\n",saGetControllerStatus(agRoot,&agcontrollerStatus ) ));
4379 #endif /* CONTROLLER_INFO_TESTING */
4380 
4381 #ifdef CONTROLLER_INFO_TESTING
4382   TI_DBG1(("tiCOMPortInit: saGetControllerInfo returns 0x%X\n",saGetControllerInfo(agRoot,&agcontrollerInfo ) ));
4383 #endif /* CONTROLLER_INFO_TESTING */
4384 
4385 #ifdef CONTROLLER_ENCRYPT_TESTING
4386   TI_DBG1(("tiCOMPortInit: saEncryptGetMode returns 0x%X\n",saEncryptGetMode(agRoot,agNULL,&agsaEncryptInfo ) ));
4387 #endif /* CONTROLLER_INFO_TESTING */
4388 
4389 
4390 #ifdef VPD_TESTING
4391   /* temporary to test saSetVPDCommand() and saGetVPDCommand */
4392   tdsaVPDSet(tiRoot);
4393 #endif /* VPD_TESTING */
4394 
4395 #if defined(FDS_DM) && defined(FDS_SM)
4396   /* initialize DM then SM */
4397   /* DM */
4398   dmRoot = &(tdsaAllShared->dmRoot);
4399   osti_memset(&dmMemRequirement, 0, sizeof(dmMemoryRequirement_t));
4400 
4401   dmMemRequirement.count = DMMemCount;
4402 
4403   for(i=LLMemCount;i<(int)(LLMemCount + DMMemCount);i++)
4404   {
4405     TI_DBG2(("tiCOMPortInit: DM copying loResource.loLevelMem to agsaMemoryRequirement_t index %d\n", i));
4406     dmMemRequirement.dmMemory[i-LLMemCount].virtPtr = loResource->loLevelMem.mem[i].virtPtr;
4407     dmMemRequirement.dmMemory[i-LLMemCount].osHandle = loResource->loLevelMem.mem[i].osHandle;
4408     dmMemRequirement.dmMemory[i-LLMemCount].physAddrUpper = loResource->loLevelMem.mem[i].physAddrUpper;
4409     dmMemRequirement.dmMemory[i-LLMemCount].physAddrLower = loResource->loLevelMem.mem[i].physAddrLower;
4410     dmMemRequirement.dmMemory[i-LLMemCount].totalLength = loResource->loLevelMem.mem[i].totalLength;
4411     dmMemRequirement.dmMemory[i-LLMemCount].numElements = loResource->loLevelMem.mem[i].numElements;
4412     dmMemRequirement.dmMemory[i-LLMemCount].singleElementLength = loResource->loLevelMem.mem[i].singleElementLength;
4413     dmMemRequirement.dmMemory[i-LLMemCount].alignment = loResource->loLevelMem.mem[i].alignment;
4414     dmMemRequirement.dmMemory[i-LLMemCount].type = loResource->loLevelMem.mem[i].type;
4415     dmMemRequirement.dmMemory[i-LLMemCount].reserved = loResource->loLevelMem.mem[i].reserved;
4416     TI_DBG2(("tiCOMPortInit: index %d virtPtr %p osHandle %p\n",i, loResource->loLevelMem.mem[i].virtPtr, loResource->loLevelMem.mem[i].osHandle));
4417     TI_DBG2(("tiCOMPortInit: index %d phyAddrUpper 0x%x phyAddrLower 0x%x totalLength %d numElements %d\n", i,
4418     loResource->loLevelMem.mem[i].physAddrUpper,
4419     loResource->loLevelMem.mem[i].physAddrLower,
4420     loResource->loLevelMem.mem[i].totalLength,
4421     loResource->loLevelMem.mem[i].numElements));
4422     TI_DBG2(("tiCOMPortInit: index %d singleElementLength 0x%x alignment 0x%x type %d reserved %d\n", i,
4423     loResource->loLevelMem.mem[i].singleElementLength,
4424     loResource->loLevelMem.mem[i].alignment,
4425     loResource->loLevelMem.mem[i].type,
4426     loResource->loLevelMem.mem[i].reserved));
4427 
4428   }
4429 
4430   status = dmInitialize(dmRoot,
4431                         agRoot,
4432                         &dmMemRequirement,
4433                         &(tdsaAllShared->dmSwConfig), //&dmSwConfig, /* start here */
4434                         loResource->loLevelOption.usecsPerTick);
4435 
4436   if(status == DM_RC_FAILURE || status == DM_RC_VERSION_INCOMPATIBLE)
4437   {
4438     TI_DBG1(("tiCOMPortInit: dmInitialize FAILED, status 0x%x\n", status));
4439     return tiError;
4440   }
4441 
4442   /* SM */
4443   smRoot = &(tdsaAllShared->smRoot);
4444   osti_memset(&smMemRequirement, 0, sizeof(smMemoryRequirement_t));
4445 
4446   smMemRequirement.count = SMMemCount;
4447 
4448   for(i=(LLMemCount + DMMemCount);i<(int)(LLMemCount + DMMemCount + SMMemCount);i++)
4449   {
4450     TI_DBG1(("tiCOMPortInit: SM copying loResource.loLevelMem to agsaMemoryRequirement_t index %d\n", i));
4451     smMemRequirement.smMemory[i-LLMemCount-DMMemCount].virtPtr = loResource->loLevelMem.mem[i].virtPtr;
4452     smMemRequirement.smMemory[i-LLMemCount-DMMemCount].osHandle = loResource->loLevelMem.mem[i].osHandle;
4453     smMemRequirement.smMemory[i-LLMemCount-DMMemCount].physAddrUpper = loResource->loLevelMem.mem[i].physAddrUpper;
4454     smMemRequirement.smMemory[i-LLMemCount-DMMemCount].physAddrLower = loResource->loLevelMem.mem[i].physAddrLower;
4455     smMemRequirement.smMemory[i-LLMemCount-DMMemCount].totalLength = loResource->loLevelMem.mem[i].totalLength;
4456     smMemRequirement.smMemory[i-LLMemCount-DMMemCount].numElements = loResource->loLevelMem.mem[i].numElements;
4457     smMemRequirement.smMemory[i-LLMemCount-DMMemCount].singleElementLength = loResource->loLevelMem.mem[i].singleElementLength;
4458     smMemRequirement.smMemory[i-LLMemCount-DMMemCount].alignment = loResource->loLevelMem.mem[i].alignment;
4459     smMemRequirement.smMemory[i-LLMemCount-DMMemCount].type = loResource->loLevelMem.mem[i].type;
4460     smMemRequirement.smMemory[i-LLMemCount-DMMemCount].reserved = loResource->loLevelMem.mem[i].reserved;
4461     TI_DBG2(("tiCOMPortInit: index %d virtPtr %p osHandle %p\n",i, loResource->loLevelMem.mem[i].virtPtr, loResource->loLevelMem.mem[i].osHandle));
4462     TI_DBG2(("tiCOMPortInit: index %d phyAddrUpper 0x%x phyAddrLower 0x%x totalLength %d numElements %d\n", i,
4463     loResource->loLevelMem.mem[i].physAddrUpper,
4464     loResource->loLevelMem.mem[i].physAddrLower,
4465     loResource->loLevelMem.mem[i].totalLength,
4466     loResource->loLevelMem.mem[i].numElements));
4467     TI_DBG2(("tiCOMPortInit: index %d singleElementLength 0x%x alignment 0x%x type %d reserved %d\n", i,
4468     loResource->loLevelMem.mem[i].singleElementLength,
4469     loResource->loLevelMem.mem[i].alignment,
4470     loResource->loLevelMem.mem[i].type,
4471     loResource->loLevelMem.mem[i].reserved));
4472 
4473   }
4474 
4475   status = smInitialize(smRoot,
4476                         agRoot,
4477                         &smMemRequirement,
4478                         &(tdsaAllShared->smSwConfig), //&smSwConfig, /* start here */
4479                         loResource->loLevelOption.usecsPerTick);
4480 
4481   if(status == SM_RC_FAILURE || status == SM_RC_VERSION_INCOMPATIBLE)
4482   {
4483     TI_DBG1(("tiCOMPortInit: smInitialize FAILED, status 0x%x\n", status));
4484     return tiError;
4485   }
4486 
4487 #elif defined(FDS_DM)
4488   dmRoot = &(tdsaAllShared->dmRoot);
4489   osti_memset(&dmMemRequirement, 0, sizeof(dmMemoryRequirement_t));
4490 
4491   dmMemRequirement.count = DMMemCount;
4492 
4493   for(i=LLMemCount;i<(int)(LLMemCount + DMMemCount);i++)
4494   {
4495     TI_DBG6(("tiCOMPortInit: copying loResource.loLevelMem to agsaMemoryRequirement_t index %d\n", i));
4496     dmMemRequirement.dmMemory[i-LLMemCount].virtPtr = loResource->loLevelMem.mem[i].virtPtr;
4497     dmMemRequirement.dmMemory[i-LLMemCount].osHandle = loResource->loLevelMem.mem[i].osHandle;
4498     dmMemRequirement.dmMemory[i-LLMemCount].physAddrUpper = loResource->loLevelMem.mem[i].physAddrUpper;
4499     dmMemRequirement.dmMemory[i-LLMemCount].physAddrLower = loResource->loLevelMem.mem[i].physAddrLower;
4500     dmMemRequirement.dmMemory[i-LLMemCount].totalLength = loResource->loLevelMem.mem[i].totalLength;
4501     dmMemRequirement.dmMemory[i-LLMemCount].numElements = loResource->loLevelMem.mem[i].numElements;
4502     dmMemRequirement.dmMemory[i-LLMemCount].singleElementLength = loResource->loLevelMem.mem[i].singleElementLength;
4503     dmMemRequirement.dmMemory[i-LLMemCount].alignment = loResource->loLevelMem.mem[i].alignment;
4504     dmMemRequirement.dmMemory[i-LLMemCount].type = loResource->loLevelMem.mem[i].type;
4505     dmMemRequirement.dmMemory[i-LLMemCount].reserved = loResource->loLevelMem.mem[i].reserved;
4506     TI_DBG6(("tiCOMPortInit: index %d phyAddrUpper 0x%x phyAddrLower 0x%x totalLength %d alignment %d\n", i, loResource->loLevelMem.mem[i].physAddrUpper, loResource->loLevelMem.mem[i].physAddrLower, loResource->loLevelMem.mem[i].totalLength, loResource->loLevelMem.mem[i].alignment));
4507     TI_DBG6(("tiCOMPortInit: index %d virtPtr %p\n",i, loResource->loLevelMem.mem[i].virtPtr));
4508 
4509   }
4510 
4511   status = dmInitialize(dmRoot,
4512                         agRoot,
4513                         &dmMemRequirement,
4514                         &(tdsaAllShared->dmSwConfig), //&dmSwConfig, /* start here */
4515                         loResource->loLevelOption.usecsPerTick);
4516 
4517   if(status == DM_RC_FAILURE || status == DM_RC_VERSION_INCOMPATIBLE)
4518   {
4519     TI_DBG1(("tiCOMPortInit: dmInitialize FAILED, status 0x%x\n", status));
4520     return tiError;
4521   }
4522 
4523 #elif defined(FDS_SM)
4524   smRoot = &(tdsaAllShared->smRoot);
4525   osti_memset(&smMemRequirement, 0, sizeof(smMemoryRequirement_t));
4526 
4527   smMemRequirement.count = SMMemCount;
4528 
4529   for(i=LLMemCount;i<(int)(LLMemCount + SMMemCount);i++)
4530   {
4531     TI_DBG6(("tiCOMPortInit: copying loResource.loLevelMem to agsaMemoryRequirement_t index %d\n", i));
4532     smMemRequirement.smMemory[i-LLMemCount].virtPtr = loResource->loLevelMem.mem[i].virtPtr;
4533     smMemRequirement.smMemory[i-LLMemCount].osHandle = loResource->loLevelMem.mem[i].osHandle;
4534     smMemRequirement.smMemory[i-LLMemCount].physAddrUpper = loResource->loLevelMem.mem[i].physAddrUpper;
4535     smMemRequirement.smMemory[i-LLMemCount].physAddrLower = loResource->loLevelMem.mem[i].physAddrLower;
4536     smMemRequirement.smMemory[i-LLMemCount].totalLength = loResource->loLevelMem.mem[i].totalLength;
4537     smMemRequirement.smMemory[i-LLMemCount].numElements = loResource->loLevelMem.mem[i].numElements;
4538     smMemRequirement.smMemory[i-LLMemCount].singleElementLength = loResource->loLevelMem.mem[i].singleElementLength;
4539     smMemRequirement.smMemory[i-LLMemCount].alignment = loResource->loLevelMem.mem[i].alignment;
4540     smMemRequirement.smMemory[i-LLMemCount].type = loResource->loLevelMem.mem[i].type;
4541     smMemRequirement.smMemory[i-LLMemCount].reserved = loResource->loLevelMem.mem[i].reserved;
4542     TI_DBG6(("tiCOMPortInit: index %d phyAddrUpper 0x%x phyAddrLower 0x%x totalLength %d alignment %d\n", i, loResource->loLevelMem.mem[i].physAddrUpper, loResource->loLevelMem.mem[i].physAddrLower, loResource->loLevelMem.mem[i].totalLength, loResource->loLevelMem.mem[i].alignment));
4543     TI_DBG6(("tiCOMPortInit: index %d virtPtr %p\n",i, loResource->loLevelMem.mem[i].virtPtr));
4544 
4545   }
4546 
4547   status = smInitialize(smRoot,
4548                         agRoot,
4549                         &smMemRequirement,
4550                         &(tdsaAllShared->smSwConfig), //&smSwConfig, /* start here */
4551                         loResource->loLevelOption.usecsPerTick);
4552 
4553   if(status == SM_RC_FAILURE || status == SM_RC_VERSION_INCOMPATIBLE)
4554   {
4555     TI_DBG1(("tiCOMPortInit: smInitialize FAILED, status 0x%x\n", status));
4556     return tiError;
4557   }
4558 #else
4559   /* nothing */
4560 #endif /* FDS_DM && FDS_SM */
4561 
4562   /* call these again after agroot is created  for testing */
4563 #ifdef CONTROLLER_STATUS_TESTING
4564   TI_DBG1(("tiCOMPortInit:again saGetControllerStatus returns 0x%X\n",saGetControllerStatus(agRoot,&agcontrollerStatus ) ));
4565 #endif /* CONTROLLER_INFO_TESTING */
4566 
4567 #ifdef CONTROLLER_INFO_TESTING
4568   TI_DBG1(("tiCOMPortInit:again saGetControllerInfo returns 0x%X\n",saGetControllerInfo(agRoot,&agcontrollerInfo ) ));
4569 #endif /* CONTROLLER_INFO_TESTING */
4570 
4571 #ifdef CONTROLLER_ENCRYPT_TESTING
4572   TI_DBG1(("tiCOMPortInit:again saEncryptGetMode returns 0x%X\n",saEncryptGetMode(agRoot,agNULL,&agsaEncryptInfo ) ));
4573 #endif /* CONTROLLER_INFO_TESTING */
4574 
4575 /* Enable SGPIO */
4576   if (tiSuccess == tiCOMConfigureSgpio(tiRoot, agTRUE))
4577   {
4578     TI_DBG2(("tiCOMPortInit: Successfully sent request to enable SGPIO\n"));
4579   }
4580   else
4581   {
4582     TI_DBG1(("tiCOMPortInit: Failed to enable SGPIO\n"));
4583   }
4584 
4585   return tiSuccess;
4586 }
4587 
4588 /*****************************************************************************
4589 *! \brief SendSgpioRequest
4590 *
4591 *  Purpose: This function is used to send SGPIO request during initialization
4592 *
4593 *  \param   tiRoot: Pointer to the OS Specific module allocated tiRoot_t
4594 *                   instance.
4595 *  \param   regType: Register Type
4596 *  \param   regIndex: Register Index
4597 *  \param   regCount: Register Count
4598 *  \param   writeData: Part of the request
4599 *
4600 *  \return:
4601 *           tiSuccess on success
4602 *           Other status on failure
4603 *
4604 *****************************************************************************/
4605 static bit32 SendSgpioRequest(
4606                             tiRoot_t    *tiRoot,
4607                             bit8        regType,
4608                             bit8        regIndex,
4609                             bit8        regCount,
4610                             bit32       *writeData
4611                             )
4612 {
4613     static bit32            buffer[128] = {0};
4614     bit32                   status = tiError;
4615     bit32		    retVal = IOCTL_CALL_FAIL;
4616     tiIOCTLPayload_t        *agIOCTLPayload = (tiIOCTLPayload_t *) buffer;
4617     agsaSGpioReqResponse_t  *pSGpioReq = (agsaSGpioReqResponse_t *) &agIOCTLPayload->FunctionSpecificArea[0];
4618     agsaSGpioReqResponse_t  *pSgpioResponse = (agsaSGpioReqResponse_t *) &agIOCTLPayload->FunctionSpecificArea[0];
4619 
4620     do{
4621 
4622     /* Frame the Ioctl payload */
4623     agIOCTLPayload->MajorFunction = IOCTL_MJ_SGPIO;
4624     agIOCTLPayload->Length = sizeof(agsaSGpioReqResponse_t);
4625 
4626     /* Frame the SGPIO request */
4627     pSGpioReq->smpFrameType = SMP_REQUEST;
4628     pSGpioReq->function = AGSA_WRITE_SGPIO_REGISTER;
4629     pSGpioReq->registerType = regType;
4630     pSGpioReq->registerIndex = regIndex;
4631     pSGpioReq->registerCount = regCount;
4632     memcpy(pSGpioReq->readWriteData, writeData, regCount * 4);
4633 
4634     /* Send the SGPIO request */
4635     sgpioResponseSet = 0;
4636     retVal = tdsaSGpioIoctlSetup(tiRoot, agNULL, agIOCTLPayload, agNULL, agNULL);
4637     if (retVal != IOCTL_CALL_PENDING)
4638     {
4639 	break;
4640     }
4641     /* Waiting for SGPIO Response */
4642     while(!sgpioResponseSet)
4643     {
4644 	tiCOMDelayedInterruptHandler(tiRoot, 0, 1, tiNonInterruptContext);
4645     }
4646     sgpioResponseSet = 0;
4647     /* Check the ioctl result */
4648     if(agIOCTLPayload->Status != IOCTL_ERR_STATUS_OK)
4649     {
4650 	break;
4651     }
4652     /* Check the sgpio function result */
4653     if(pSgpioResponse->functionResult != 0x00)
4654     {
4655 	break;
4656     }
4657 
4658     status = tiSuccess;
4659 
4660   }while(0);
4661 
4662     return status;
4663 }
4664 
4665 /*****************************************************************************
4666 *! \brief tiCOMConfigureSgpio
4667 *
4668 *  Purpose: This function is used to configure SGPIO during initialization
4669 *
4670 *  \param   tiRoot: Pointer to the OS Specific module allocated tiRoot_t
4671 *                   instance.
4672 *  \param   enableSgpio: Enable / Disable SGPIO
4673 *
4674 *  \return:
4675 *           tiSuccess on success
4676 *           Other status on failure
4677 *
4678 *****************************************************************************/
4679 bit32 tiCOMConfigureSgpio(
4680                         tiRoot_t    *tiRoot,
4681                         bit8        enableSgpio
4682                         )
4683 {
4684     bit32	    status = tiError;
4685     bit32	    i;
4686     bit8            regCount;
4687     bit32           writeData[OSSA_SGPIO_MAX_READ_DATA_COUNT] = {0};
4688     agsaSGpioCfg0_t *pCfg0 = (agsaSGpioCfg0_t *) &writeData[0];
4689     agsaSGpioCfg1_t *pCfg1 = (agsaSGpioCfg1_t *) &writeData[1];
4690     tdsaRoot_t	    *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
4691     tdsaContext_t   *tdsaAllShared = (tdsaContext_t *) &tdsaRoot->tdsaAllShared;
4692     bit32	    phyCount = tdsaAllShared->phyCount;
4693 
4694     if (enableSgpio)
4695     {
4696         /* Configure both CFG[0] and CFG[1] */
4697         regCount = 2;
4698 
4699         /* Enable SGPIO */
4700         pCfg0->gpioEnable = 1;
4701 
4702         /* The following are the default values for CFG[1] suggested by SFF-8485 spec */
4703         /* Maximum Activity ON: 2 */
4704         /* Forced Activity OFF: 1 */
4705         pCfg1->maxActOn = 2;
4706         pCfg1->forceActOff = 1;
4707     }
4708     else
4709     {
4710         /* Configure CFG[0] only */
4711         regCount = 1;
4712 
4713         /* Disable SGPIO */
4714         pCfg0->gpioEnable = 0;
4715     }
4716 
4717     status = SendSgpioRequest(tiRoot, AGSA_SGPIO_CONFIG_REG, 0, regCount, writeData);
4718     if((tiSuccess == status) && (enableSgpio))
4719     {
4720 	 /* Write default values to transmit registers */
4721 	 /* RegisterCount = Number of phys present in HBA / 4 */
4722 	 regCount = phyCount / 4;
4723          for(i = 0; i < regCount; i++)
4724 	 {
4725 	   /* Following are the default values specified in SFF-8485 spec */
4726 	   /* Activity: 5 */
4727 	   /* Locate: 0 */
4728 	   /* Error: 0 */
4729 	   writeData[i] = 0xA0A0A0A0;
4730   	}
4731 	status = SendSgpioRequest(tiRoot, AGSA_SGPIO_DRIVE_BY_DRIVE_TRANSMIT_REG, 0, regCount, writeData);
4732    }
4733 
4734    return status;
4735 }
4736 
4737 
4738 /*****************************************************************************
4739 *! \brief  tiCOMPortStart
4740 *
4741 *  Purpose: This function is called to bring the port hardware online. This
4742 *           call could only be called until after the successful completion
4743 *           tiCOMPortInit().
4744 *
4745 *  \param  tiRoot:          Pointer to root data structure.
4746 *  \param  portID:          A ID for this portal to be used by the TD Layer
4747 *                           to get the portal configuration information.
4748 *  \param  portalContext:   Pointer to the context for this portal.
4749 *  \param  option:          An option for starting a port
4750 *
4751 *  \return:
4752 *          tiSuccess:      Successful.
4753 *          Others:             Fail.
4754 *
4755 *  \note -
4756 *   If sas or sata initiator, this will be called 8 (the number of phys) times.
4757 *   If both sas and sata initiator, this will be called 16 times
4758 *
4759 *****************************************************************************/
4760 /* portID is used as PhyID
4761    Should return always tiSuccess. PortStarted is returned in ossaHwCB()
4762 */
4763 osGLOBAL bit32
4764 tiCOMPortStart(
4765                tiRoot_t          * tiRoot,
4766                bit32               portID,
4767                tiPortalContext_t * portalContext,
4768                bit32               option
4769                )
4770 {
4771   tdsaRoot_t    *tdsaRoot = (tdsaRoot_t *) tiRoot->tdData;
4772   tdsaContext_t *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
4773   agsaRoot_t *agRoot = &tdsaAllShared->agRootInt;
4774   agsaSASProtocolTimerConfigurationPage_t SASConfigPage;
4775   bit32 status = AGSA_RC_FAILURE;
4776   static bit32 IsSendSASConfigPage = agFALSE;
4777 
4778 
4779   TI_DBG3(("tiCOMPortStart: start portID %d\n", portID));
4780 
4781   /*
4782    * return error if reset is in progress
4783    */
4784   if (tdsaAllShared->flags.resetInProgress == agTRUE)
4785   {
4786     TI_DBG1(("tiCOMPortStart: reset error\n"));
4787     return tiError;
4788   }
4789 
4790   /*
4791    *
4792    * port is not initialized, return error
4793    */
4794   if (tdsaAllShared->Ports[portID].flags.portInitialized == agFALSE)
4795   {
4796     TI_DBG1(("tiCOMPortStart: not intialized error\n"));
4797     return tiError;
4798   }
4799 
4800   /* portal has been started. */
4801   if (portalContext->tdData != NULL)
4802   {
4803     if (tdsaAllShared->Ports[portID].flags.portStarted == agTRUE)
4804     {
4805       TI_DBG3 (("tiCOMPortStart : Cannot start port again: Port has already been started\n"));
4806       ostiPortEvent (
4807                      tiRoot,
4808                      tiPortStarted,
4809                      tiSuccess,
4810                      (void *) tdsaAllShared->Ports[portID].tiPortalContext
4811                      );
4812       return tiSuccess;
4813     }
4814   }
4815 
4816   portalContext->tdData =  &(tdsaAllShared->Ports[portID]);
4817   TI_DBG4 (("tiCOMPortStart : saving portalconext portID %d tdsaAllShared %p\n", portID, tdsaAllShared));
4818   /* saving tiportalContext_t */
4819   tdsaAllShared->Ports[portID].tiPortalContext = portalContext;
4820   TI_DBG4(("tiCOMPortStart : portID/phyID %d tiPortalContext %p\n", portID, tdsaAllShared->Ports[portID].tiPortalContext));
4821 
4822   /*
4823     where is "tdsaAllShared->Ports[0].portContext" set?
4824     in ossaHWCB
4825   */
4826   if (tdsaAllShared->Ports[portID].flags.portStarted == agTRUE)
4827   {
4828     TI_DBG1(("tiCOMPortStart: port already has been started \n"));
4829     return tiSuccess;
4830   }
4831 
4832 
4833   /*
4834     hardcode sasID frame. It should be read by ostigettransportparams later from configuration file
4835   */
4836 #ifdef INITIATOR_DRIVER
4837 
4838   tdsaAllShared->Ports[portID].SASID.target_ssp_stp_smp = 0;
4839   tdsaAllShared->Ports[portID].SASID.initiator_ssp_stp_smp
4840       = SA_IDFRM_SSP_BIT | SA_IDFRM_STP_BIT | SA_IDFRM_SMP_BIT;
4841   tdsaAllShared->Ports[portID].SASID.deviceType_addressFrameType = AGSA_DEV_TYPE_END_DEVICE;
4842 
4843   tdsaAllShared->Ports[portID].SASID.phyIdentifier = (bit8)portID;
4844 
4845 #endif
4846 
4847 #ifdef TARGET_DRIVER
4848 
4849   tdsaAllShared->Ports[portID].SASID.target_ssp_stp_smp = SA_IDFRM_SSP_BIT;
4850   tdsaAllShared->Ports[portID].SASID.initiator_ssp_stp_smp = 0;
4851   tdsaAllShared->Ports[portID].SASID.deviceType_addressFrameType = AGSA_DEV_TYPE_END_DEVICE;
4852   tdsaAllShared->Ports[portID].SASID.phyIdentifier = (bit8)portID;
4853 
4854 #endif
4855 
4856 #if defined (INITIATOR_DRIVER) && defined (TARGET_DRIVER)
4857 
4858   /* for combo testing */
4859   tdsaAllShared->Ports[portID].SASID.target_ssp_stp_smp = SA_IDFRM_SSP_BIT;
4860   tdsaAllShared->Ports[portID].SASID.initiator_ssp_stp_smp
4861       = SA_IDFRM_SSP_BIT | SA_IDFRM_STP_BIT | SA_IDFRM_SMP_BIT;
4862   tdsaAllShared->Ports[portID].SASID.deviceType_addressFrameType = AGSA_DEV_TYPE_END_DEVICE;
4863 
4864   tdsaAllShared->Ports[portID].SASID.phyIdentifier = (bit8)portID;
4865 
4866 #endif
4867 
4868 
4869   TI_DBG6(("tiCOMPortStart: before pid %d\n", portID));
4870   tdssPrintSASIdentify(&(tdsaAllShared->Ports[portID].SASID));
4871 
4872   TI_DBG6(("tiCOMPortStart: sysIntsActive %s\n",
4873            (tdsaAllShared->flags.sysIntsActive == agTRUE) ? "agTRUE" : "agFALSE"));
4874 
4875   /* Read global configuration first then card-specific configuration */
4876 
4877   /* the following must be processed only once */
4878   if ( tdsaAllShared->first_process == agFALSE)
4879   {
4880     tdsaGetGlobalPhyParams(tiRoot);
4881     tdsaGetCardPhyParams(tiRoot);
4882     tdsaAllShared->first_process = agTRUE;
4883   }
4884 
4885   TI_DBG6(("tiCOMPortStart: after pid %d\n", portID));
4886   tdssPrintSASIdentify(&(tdsaAllShared->Ports[portID].SASID));
4887 
4888   /*
4889      Phy Calibration
4890   */
4891   if (tdsaAllShared->phyCalibration)
4892   {
4893     /* Change default phy calibration */
4894     tdsaAllShared->Ports[portID].agPhyConfig.phyProperties =
4895       (tdsaAllShared->Ports[portID].agPhyConfig.phyProperties) | 0x80;
4896     /* Setting index of phy calibration table index
4897        portID is used as phy calibration table index
4898     */
4899     tdsaAllShared->Ports[portID].agPhyConfig.phyProperties =
4900       (tdsaAllShared->Ports[portID].agPhyConfig.phyProperties) | (portID << 8);
4901   }
4902   TI_DBG2(("tiCOMPortStart: tdsaAllShared->Ports[0x%x].agPhyConfig.phyProperties 0x%x\n",
4903     portID, tdsaAllShared->Ports[portID].agPhyConfig.phyProperties));
4904 
4905 
4906   if(gSSC_Disable)
4907   {
4908     tdsaAllShared->Ports[portID].agPhyConfig.phyProperties = tdsaAllShared->Ports[portID].agPhyConfig.phyProperties | 0x40000;
4909     TI_DBG1(("tiCOMPortStart:gSSC_Disable tdsaAllShared->Ports[portID].agPhyConfig.phyProperties 0x%x\n", tdsaAllShared->Ports[portID].agPhyConfig.phyProperties));
4910 
4911   }
4912 
4913   if(tIsSPCV12or6G(agRoot) && !IsSendSASConfigPage) /* Not SPC */
4914   {
4915     /* call saSetControllerConfig() to set STP_IDLE_TIME; All others are the defaults */
4916     osti_memset(&SASConfigPage, 0, sizeof(agsaSASProtocolTimerConfigurationPage_t));
4917     SASConfigPage.pageCode        =  AGSA_SAS_PROTOCOL_TIMER_CONFIG_PAGE;
4918     SASConfigPage.MST_MSI         =  3 << 15; /* enables both MCT for SSP target and initiator */
4919     SASConfigPage.STP_SSP_MCT_TMO =  (tdsaAllShared->STP_MCT_TMO << 16) | tdsaAllShared->SSP_MCT_TMO; /* default of 3200 us for STP and SSP maximum connection time */
4920     SASConfigPage.STP_FRM_TMO     = (tdsaAllShared->MAX_OPEN_TIME << 24) | (tdsaAllShared->SMP_MAX_CONN_TIMER << 16) | tdsaAllShared->STP_FRM_TMO; /* MAX_OPEN_TIME, SMP_MAX_CONN_TIMER, STP frame timeout */
4921     SASConfigPage.STP_IDLE_TMO    =  tdsaAllShared->stp_idle_time;
4922     if (SASConfigPage.STP_IDLE_TMO > 0x3FFFFFF)
4923     {
4924       SASConfigPage.STP_IDLE_TMO = 0x3FFFFFF;
4925     }
4926     SASConfigPage.OPNRJT_RTRY_INTVL =         (tdsaAllShared->MFD << 16)              | tdsaAllShared->OPNRJT_RTRY_INTVL; /* Multi Data Fetach enabled and 2 us for Open Reject Retry interval */
4927     SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO =  (tdsaAllShared->DOPNRJT_RTRY_TMO << 16) | tdsaAllShared->COPNRJT_RTRY_TMO; /* 128 us for ORR Timeout for DATA phase and 32 us for ORR Timeout for command phase */
4928     SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR =  (tdsaAllShared->DOPNRJT_RTRY_THR << 16) | tdsaAllShared->COPNRJT_RTRY_THR; /* 16 for ORR backoff threshold for DATA phase and 1024 for ORR backoff threshold for command phase */
4929     SASConfigPage.MAX_AIP =  tdsaAllShared->MAX_AIP; /* MAX AIP. Default is  0x200000 */
4930 
4931     TI_DBG1(("tiCOMPortStart: saSetControllerConfig SASConfigPage.pageCode                 0x%08x\n",SASConfigPage.pageCode));
4932     TI_DBG1(("tiCOMPortStart: saSetControllerConfig SASConfigPage.MST_MSI                  0x%08x\n",SASConfigPage.MST_MSI));
4933     TI_DBG1(("tiCOMPortStart: saSetControllerConfig SASConfigPage.STP_SSP_MCT_TMO          0x%08x\n",SASConfigPage.STP_SSP_MCT_TMO));
4934     TI_DBG1(("tiCOMPortStart: saSetControllerConfig SASConfigPage.STP_FRM_TMO              0x%08x\n",SASConfigPage.STP_FRM_TMO));
4935     TI_DBG1(("tiCOMPortStart: saSetControllerConfig SASConfigPage.STP_IDLE_TMO             0x%08x\n",SASConfigPage.STP_IDLE_TMO));
4936     TI_DBG1(("tiCOMPortStart: saSetControllerConfig SASConfigPage.OPNRJT_RTRY_INTVL        0x%08x\n",SASConfigPage.OPNRJT_RTRY_INTVL));
4937     TI_DBG1(("tiCOMPortStart: saSetControllerConfig SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO 0x%08x\n",SASConfigPage.Data_Cmd_OPNRJT_RTRY_TMO));
4938     TI_DBG1(("tiCOMPortStart: saSetControllerConfig SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR 0x%08x\n",SASConfigPage.Data_Cmd_OPNRJT_RTRY_THR));
4939     TI_DBG1(("tiCOMPortStart: saSetControllerConfig SASConfigPage.MAX_AIP                  0x%08x\n",SASConfigPage.MAX_AIP));
4940 
4941     status = saSetControllerConfig(agRoot,
4942                                     0,
4943                                     AGSA_SAS_PROTOCOL_TIMER_CONFIG_PAGE,
4944                                     sizeof(agsaSASProtocolTimerConfigurationPage_t),
4945                                     &SASConfigPage,
4946                                     agNULL);
4947     if (status != AGSA_RC_SUCCESS)
4948     {
4949       TI_DBG1(("tiCOMPortStart: calling saSetControllerConfig() failed\n"));
4950     }
4951     else
4952     {
4953       TI_DBG2(("tiCOMPortStart: calling saSetControllerConfig() is OK\n"));
4954     }
4955     IsSendSASConfigPage = agTRUE;
4956   }
4957   else
4958   {
4959     TI_DBG1(("tiCOMPortStart: saSetControllerConfig not called tIsSPCV12or6G %d IsSendSASConfigPage %d\n",tIsSPCV12or6G(agRoot),IsSendSASConfigPage));
4960   }
4961 
4962   /* maps portID to phyID */
4963   status = saPhyStart(agRoot,
4964                       agNULL,
4965                       0,
4966                       portID,
4967                       &(tdsaAllShared->Ports[portID].agPhyConfig),
4968                       &(tdsaAllShared->Ports[portID].SASID)
4969                       );
4970 
4971   TI_DBG6(("tiCOMPortStart: saPhyStart status %d\n", status));
4972 
4973   if (status == AGSA_RC_SUCCESS)
4974   {
4975     TI_DBG3(("tiCOMPortStart : calling portstarted\n"));
4976     ostiPortEvent(
4977                   tiRoot,
4978                   tiPortStarted,
4979                   tiSuccess,
4980                   (void *) tdsaAllShared->Ports[portID].tiPortalContext
4981                   );
4982     return tiSuccess;
4983   }
4984   else
4985   {
4986     TI_DBG3(("tiCOMPortStart : cant' start port\n"));
4987     return tiError;
4988   }
4989 
4990 }
4991 
4992 /*****************************************************************************
4993 *! \brief  tiCOMPortStop
4994 *
4995 *  Purpose: This function is called to bring the port hardware down.
4996 *
4997 *  \param  tiRoot:          Pointer to root data structure.
4998 *  \param  portalContext:   Pointer to the context for this portal.
4999 *
5000 *  \return:
5001 *          tiSuccess:      Successful.
5002 *          Others:             Fail.
5003 *
5004 *  \note -
5005 *
5006 *****************************************************************************/
5007 osGLOBAL bit32
5008 tiCOMPortStop (
5009   tiRoot_t          *tiRoot,
5010   tiPortalContext_t *portalContext
5011   )
5012 {
5013   tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
5014   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
5015   tdList_t          *PortContextList;
5016   tdsaPortContext_t *onePortContext = agNULL;
5017   agsaRoot_t        *agRoot = agNULL;
5018   bit32             i;
5019   bit32             found = agFALSE;
5020 
5021 #ifdef CONTROLLER_STATUS_TESTING
5022   agsaControllerStatus_t  agcontrollerStatus;
5023 #endif /* CONTROLLER_STATUS_TESTING */
5024 
5025 
5026   TI_DBG3(("tiCOMPortStop: start\n"));
5027   /*
5028     find the portcontext
5029     find phys belonging to that portcotext
5030     call saPhyStop for all those phys
5031     call saPhyStop()
5032     remove the portcontext from the portcontext list
5033   */
5034 
5035   agRoot = &(tdsaAllShared->agRootNonInt);
5036 
5037 #ifdef CONTROLLER_STATUS_TESTING
5038   TI_DBG1(("tiCOMPortStop: saGetControllerStatus returns 0x%X\n",saGetControllerStatus(agRoot,&agcontrollerStatus ) ));
5039 #endif /* CONTROLLER_INFO_TESTING */
5040 
5041   if (TDLIST_EMPTY(&(tdsaAllShared->MainPortContextList)))
5042   {
5043     TI_DBG1(("tiCOMPortStop: empty tdsaPortContext\n"));
5044     return tiError;
5045   }
5046 
5047   /* find a right portcontext */
5048   PortContextList = tdsaAllShared->MainPortContextList.flink;
5049   while (PortContextList != &(tdsaAllShared->MainPortContextList))
5050   {
5051     onePortContext = TDLIST_OBJECT_BASE(tdsaPortContext_t, MainLink, PortContextList);
5052     if (onePortContext == agNULL)
5053     {
5054       TI_DBG1(("tiCOMPortStop: onePortContext is NULL!!!\n"));
5055       return tiError;
5056     }
5057     if (onePortContext->tiPortalContext == portalContext)
5058     {
5059       TI_DBG6(("tiCOMPortStop: found; oneportContext ID %d\n", onePortContext->id));
5060       found = agTRUE;
5061       break;
5062     }
5063     PortContextList = PortContextList->flink;
5064   }
5065 
5066   if (found == agFALSE)
5067   {
5068     TI_DBG1(("tiCOMPortStop: No corressponding tdsaPortContext\n"));
5069     return tiError;
5070   }
5071 
5072 #ifdef INITIATOR_DRIVER
5073   /* reset the fields of portcontext */
5074   onePortContext->DiscoveryState = ITD_DSTATE_NOT_STARTED;
5075   onePortContext->discoveryOptions = AG_SA_DISCOVERY_OPTION_FULL_START;
5076 #endif /* INITIATOR_DRIVER */
5077 
5078   onePortContext->Count = 0;
5079   onePortContext->agContext.osData = onePortContext;
5080   for(i=0;i<TD_MAX_NUM_PHYS;i++)
5081   {
5082     if (onePortContext->PhyIDList[i] == agTRUE)
5083     {
5084       tdsaAllShared->Ports[i].portContext = agNULL;
5085 #ifdef CCFLAGS_PHYCONTROL_COUNTS
5086       if( tiIS_SPC(agRoot) )
5087       {
5088 
5089         saLocalPhyControl(agRoot,&onePortContext->agContext,0 , i, AGSA_PHY_GET_ERROR_COUNTS, agNULL);
5090         saLocalPhyControl(agRoot,&onePortContext->agContext,0 , i, AGSA_PHY_CLEAR_ERROR_COUNTS, agNULL);
5091         saLocalPhyControl(agRoot,&onePortContext->agContext,0 , i, AGSA_PHY_GET_BW_COUNTS, agNULL);
5092       }
5093       else
5094       {
5095         TI_DBG1(("\ntiCOMPortStop: CCFLAGS_PHYCONTROL_COUNTS PHY %d\n",i));
5096         saGetPhyProfile( agRoot,&onePortContext->agContext,0, AGSA_SAS_PHY_ERR_COUNTERS_PAGE, i);
5097         saGetPhyProfile( agRoot,&onePortContext->agContext,0, AGSA_SAS_PHY_BW_COUNTERS_PAGE,i);
5098         saGetPhyProfile( agRoot,&onePortContext->agContext,0, AGSA_SAS_PHY_ANALOG_SETTINGS_PAGE,i);
5099         saGetPhyProfile( agRoot,&onePortContext->agContext,0, AGSA_SAS_PHY_GENERAL_STATUS_PAGE,i);
5100         saGetPhyProfile( agRoot,&onePortContext->agContext,0, AGSA_SAS_PHY_ERR_COUNTERS_CLR_PAGE,i);
5101 
5102         TI_DBG1(("tiCOMPortStop: CCFLAGS_PHYCONTROL_COUNTS PHY %d\n",i));
5103 
5104       }
5105 
5106 #endif /* CCFLAGS_PHYCONTROL_COUNTS */
5107       saPhyStop(agRoot, &onePortContext->agContext, 0, i);
5108     }
5109   }
5110 
5111   return tiSuccess;
5112 }
5113 
5114 
5115 /*****************************************************************************
5116 *! \brief tiCOMGetPortInfo
5117 *
5118 *  Purpose:  This function is called to return information about the specific
5119 *            port instant
5120 *
5121 *
5122 *  \param   tiRoot:        Pointer to driver/port instance.
5123 *  \param   portalContext  Pointer to the context for this portal.
5124 *  \param   tiPortInfo:    Pointer to port information structure.
5125 *
5126 *  \Return: tiSuccess
5127 *
5128 *****************************************************************************/
5129 /*
5130   can't find tdsaportcontext in this function
5131   since discovery has not been called by OS layer yet
5132   Therefore, hardcoded value are being returned for now
5133 */
5134 osGLOBAL bit32 tiCOMGetPortInfo(
5135                                 tiRoot_t            *tiRoot,
5136                                 tiPortalContext_t   *portalContext,
5137                                 tiPortInfo_t        *tiPortInfo
5138                                 )
5139 
5140 {
5141   tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
5142   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
5143   tdList_t          *PortContextList;
5144   tdsaPortContext_t *onePortContext = agNULL;
5145   bit32             found = agFALSE;
5146   static bit8       localname[68], remotename[68];
5147 
5148   TI_DBG6(("tiCOMGetPortInfo: start\n"));
5149 
5150 
5151   tdsaSingleThreadedEnter(tiRoot, TD_PORT_LOCK);
5152   if (TDLIST_EMPTY(&(tdsaAllShared->MainPortContextList)))
5153   {
5154     tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
5155     TI_DBG1(("tiCOMGetPortInfo: No tdsaPortContext\n"));
5156     return tiError;
5157   }
5158   else
5159   {
5160     tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
5161   }
5162 
5163   /* find a corresponding portcontext */
5164   PortContextList = tdsaAllShared->MainPortContextList.flink;
5165   while (PortContextList != &(tdsaAllShared->MainPortContextList))
5166   {
5167     onePortContext = TDLIST_OBJECT_BASE(tdsaPortContext_t, MainLink, PortContextList);
5168     TI_DBG3(("tiCOMGetPortInfo: oneportContext pid %d\n", onePortContext->id));
5169     if (onePortContext->tiPortalContext == portalContext && onePortContext->valid == agTRUE)
5170     {
5171       TI_DBG3(("tiCOMGetPortInfo: found; oneportContext pid %d\n", onePortContext->id));
5172       found = agTRUE;
5173       break;
5174     }
5175     PortContextList = PortContextList->flink;
5176   }
5177 
5178   if (found == agFALSE)
5179   {
5180     TI_DBG1(("tiCOMGetPortInfo: First, No corresponding tdsaPortContext\n"));
5181     return tiError;
5182   }
5183 
5184   if (onePortContext == agNULL)
5185   {
5186     TI_DBG1(("tiCOMGetPortInfo: Second, No corressponding tdsaPortContext\n"));
5187     return tiError;
5188   }
5189 
5190   osti_memset(localname, 0, sizeof(localname));
5191   osti_memset(remotename, 0, sizeof(remotename));
5192 
5193   /*
5194     Parse the type of port then fill in the information
5195   */
5196   if ( onePortContext->sasRemoteAddressHi == 0xFFFFFFFF && onePortContext->sasRemoteAddressLo == 0xFFFFFFFF)
5197   {
5198     /* directly attached SATA port */
5199     osti_memcpy(localname, &(onePortContext->sasLocalAddressHi), 4);
5200     osti_memcpy(&(localname[4]), &(onePortContext->sasLocalAddressLo), 4);
5201     tiPortInfo->localNameLen = 8;
5202     /* information is from SATA ID device data. remoteName is serial number, firmware version, model number */
5203     osti_memcpy(remotename, onePortContext->remoteName, 68);
5204     tiPortInfo->remoteNameLen = 68;
5205   }
5206   else
5207   {
5208     /* copy hi address and low address */
5209     osti_memcpy(localname, &(onePortContext->sasLocalAddressHi), 4);
5210     osti_memcpy(&(localname[4]), &(onePortContext->sasLocalAddressLo), 4);
5211     tiPortInfo->localNameLen = 8;
5212     osti_memcpy(remotename, &(onePortContext->sasRemoteAddressHi), 4);
5213     osti_memcpy(&(remotename[4]), &(onePortContext->sasRemoteAddressLo), 4);
5214     tiPortInfo->remoteNameLen = 8;
5215   }
5216 
5217   tiPortInfo->localName = (char *)&localname;
5218   tiPortInfo->remoteName = (char *)&remotename;
5219 
5220 
5221   return tiSuccess;
5222 
5223 }
5224 
5225 /*****************************************************************************
5226 *
5227 * tiCOMSetControllerConfig
5228 *
5229 *  Purpose:  This function is called to set the controller's advanced configuration.
5230 *            The status is reported via ostiPortEvent().
5231 *
5232 *  Parameters:
5233 *
5234 *    tiRoot:        Pointer to driver/port instance.
5235 *
5236 *  Return:
5237 *     tiSuccess:  The setting controller configuration was started.
5238 *     tiError:    The setting controller configuration was not started.
5239 *
5240 *****************************************************************************/
5241 osGLOBAL bit32  tiCOMSetControllerConfig (
5242          tiRoot_t    *tiRoot,
5243          bit32       modePage,
5244          bit32       length,
5245          void        *buffer,
5246          void        *context)
5247 {
5248    agsaRoot_t      *agRoot;
5249    bit32           returnCode = AGSA_RC_BUSY;
5250    bit32           tiStatus = tiSuccess;
5251    tdsaRoot_t      *tdsaRoot ;
5252    tdsaContext_t   *tdsaAllShared ;
5253 
5254    TD_ASSERT(tiRoot, "tiRoot");
5255    tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
5256    TD_ASSERT(tdsaRoot, "tdsaRoot");
5257 
5258    tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
5259    TD_ASSERT(tdsaAllShared, "tdsaAllShared");
5260    agRoot = &(tdsaAllShared->agRootNonInt);
5261    TD_ASSERT(agRoot, "agRoot");
5262 
5263    agRoot = &(tdsaAllShared->agRootNonInt);
5264 
5265    TI_DBG1(("tiCOMSetControllerConfig:\n" ));
5266 
5267    /*do some sanity checking */
5268    if ( ((modePage == TI_INTERRUPT_CONFIGURATION_PAGE)   && (length != sizeof(tiInterruptConfigPage_t )))   ||
5269         ((modePage == TI_ENCRYPTION_GENERAL_CONFIG_PAGE) && (length != sizeof(tiEncryptGeneralPage_t  )))    ||
5270         ((modePage == TI_ENCRYPTION_DEK_CONFIG_PAGE)     && (length != sizeof(tiEncryptDekConfigPage_t)))    ||
5271         ((modePage == TI_ENCRYPTION_CONTROL_PARM_PAGE)  && (length != sizeof(tiEncryptControlParamPage_t ))) ||
5272         ((modePage == TI_ENCRYPTION_HMAC_CONFIG_PAGE)  && (length != sizeof(tiEncryptHMACConfigPage_t )))    ||
5273         ((modePage == TI_SAS_PROTOCOL_TIMER_CONFIG_PAGE) && (length != sizeof(tiSASProtocolTimerConfigurationPage_t )))  )
5274    {
5275        tiStatus = tiError;
5276    }
5277    else
5278    {
5279        returnCode = saSetControllerConfig(agRoot, 0, modePage, length, buffer, context);
5280 
5281        if (returnCode == AGSA_RC_SUCCESS)
5282        {
5283            tiStatus = tiSuccess;
5284        }
5285        else if (returnCode == AGSA_RC_BUSY)
5286        {
5287            tiStatus = tiBusy;
5288        }
5289        else
5290        {
5291            tiStatus = tiError;
5292        }
5293    }
5294    return(tiStatus);
5295 }
5296 
5297 /*****************************************************************************
5298 *
5299 * tiCOMGetControllerConfig
5300 *
5301 *  Purpose:  This function is called to get the controller's advanced configuration.
5302 *            The status is reported via ostiPortEvent().
5303 *
5304 *  Parameters:
5305 *
5306 *    tiRoot:        Pointer to driver/port instance.
5307 *    flag:          Interrupt  Vector Mask
5308 *                   This parameter is valid only when modePage is set to TI_INTERRUPT_CONFIGURATION_PAGE.
5309 *                   When the modePage field is set to TI_INTERRUPT_CONFIGURATION_PAGE,
5310 *                   this field contains a bitmap of interrupt vectors for which interrupt coalescing parameters are retrieved.
5311 *  Return:
5312 *     tiSuccess:  The controller configuration retrival was started.
5313 *     tiError:    The controller configuration retrival was not started.
5314 *
5315 *****************************************************************************/
5316 osGLOBAL bit32  tiCOMGetControllerConfig (
5317          tiRoot_t    *tiRoot,
5318          bit32       modePage,
5319          bit32       flag,
5320          void        *context)
5321 
5322 {
5323   agsaRoot_t      *agRoot;
5324   bit32           returnCode = AGSA_RC_BUSY;
5325   bit32           tiStatus = tiSuccess;
5326   tdsaRoot_t      *tdsaRoot ;
5327   tdsaContext_t   *tdsaAllShared ;
5328 
5329   TD_ASSERT(tiRoot, "tiRoot");
5330   tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
5331   TD_ASSERT(tdsaRoot, "tdsaRoot");
5332 
5333   tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
5334   TD_ASSERT(tdsaAllShared, "tdsaAllShared");
5335   agRoot = &(tdsaAllShared->agRootNonInt);
5336   TD_ASSERT(agRoot, "agRoot");
5337 
5338   agRoot = &(tdsaAllShared->agRootNonInt);
5339 
5340   TI_DBG1(("tiCOMGetControllerConfig: modePage 0x%x context %p\n",modePage,context ));
5341 
5342   returnCode = saGetControllerConfig(agRoot, 0, modePage, flag, 0, context);
5343 
5344   if (returnCode == AGSA_RC_SUCCESS)
5345   {
5346     tiStatus = tiSuccess;
5347     TI_DBG1(("tiCOMGetControllerConfig:modePage 0x%x tiSuccess\n",modePage ));
5348   }
5349   else if (returnCode == AGSA_RC_BUSY)
5350   {
5351     tiStatus = tiBusy;
5352     TI_DBG1(("tiCOMGetControllerConfig:modePage 0x%x tiBusy\n",modePage ));
5353   }
5354   else
5355   {
5356     tiStatus = tiError;
5357     TI_DBG1(("tiCOMGetControllerConfig:modePage 0x%x tiError\n",modePage ));
5358   }
5359 
5360    return(tiStatus);
5361 }
5362 
5363 /*****************************************************************************
5364 *
5365 * tiCOMEncryptGetInfo
5366 *
5367 *  Purpose:  This function is called to return information about the encryption
5368 *            engine for the specified port.
5369 *
5370 *  Parameters:
5371 *
5372 *    tiRoot:        Pointer to driver/port instance.
5373 *
5374 *  Return:
5375 *   tiSuccess       The request is being processed
5376 *   tiNotSupported  Encryption is not supported
5377 *
5378 *****************************************************************************/
5379 osGLOBAL bit32 tiCOMEncryptGetInfo(tiRoot_t *tiRoot)
5380 {
5381   tiEncryptInfo_t tiEncryptInfo;
5382   agsaEncryptInfo_t agsaEncryptInfo;
5383   tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
5384   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
5385   agsaRoot_t      *agRoot;
5386   tiEncryptPort_t tiEncryptPort;
5387   bit32           returnCode;
5388   bit32           tiStatus;
5389 
5390   agRoot = &(tdsaAllShared->agRootNonInt);
5391 
5392   returnCode = saEncryptGetMode(agRoot,agNULL, &agsaEncryptInfo);
5393   TI_DBG1(("tiCOMEncryptGetInfo: returnCode 0x%x\n", returnCode));
5394 
5395   if (returnCode == AGSA_RC_SUCCESS)
5396   {
5397       tiStatus = tiSuccess;
5398 
5399       /*
5400        * The data encoded in the agsaEncryptInfo must be converted
5401        * to match the fields of the tiEncryptInfo structure.
5402        *
5403        * No sector information is currently available.
5404        */
5405       osti_memset(&tiEncryptInfo, 0x0, sizeof(tiEncryptInfo_t));
5406 
5407       /* cipher mode */
5408       if (agsaEncryptInfo.encryptionCipherMode == agsaEncryptCipherModeXTS)
5409       {
5410          tiEncryptInfo.securityCipherMode = TI_ENCRYPT_ATTRIB_CIPHER_XTS;
5411       }
5412       /* security mode */
5413       if (agsaEncryptInfo.encryptionSecurityMode == agsaEncryptSMF)
5414       {
5415          tiEncryptInfo.securityCipherMode |= TI_ENCRYPT_SEC_MODE_FACT_INIT;
5416       }
5417       else if (agsaEncryptInfo.encryptionSecurityMode == agsaEncryptSMA)
5418       {
5419          tiEncryptInfo.securityCipherMode |= TI_ENCRYPT_SEC_MODE_A;
5420       }
5421       else if (agsaEncryptInfo.encryptionSecurityMode == agsaEncryptSMB)
5422       {
5423          tiEncryptInfo.securityCipherMode |= TI_ENCRYPT_SEC_MODE_B;
5424       }
5425 
5426       tiEncryptInfo.status = agsaEncryptInfo.status;
5427 
5428       tiEncryptPort.pData = &tiEncryptInfo;
5429 
5430       /* The low level returns synchronously, so fake a port event now.*/
5431       tiEncryptPort.encryptEvent = tiEncryptGetInfo;
5432       tiEncryptPort.subEvent = 0;
5433 
5434       ostiPortEvent(tiRoot,tiEncryptOperation,tiStatus,&tiEncryptPort);
5435   }
5436   else
5437   {
5438     if (returnCode == AGSA_RC_NOT_SUPPORTED)
5439     {
5440       tiStatus = tiNotSupported;
5441       TI_DBG1(("tiCOMEncryptGetInfo: tiNotSupported\n"));
5442     }
5443     else
5444     {
5445       TI_DBG1(("tiCOMEncryptGetInfo: tiError returnCode 0x%x\n",returnCode));
5446       tiStatus = tiError;
5447     }
5448 
5449     tiEncryptPort.pData = NULL;
5450   }
5451 
5452   return(tiStatus);
5453 }
5454 
5455 /*****************************************************************************
5456 *
5457 * tiCOMEncryptSetMode
5458 *
5459 *  Purpose:  This function is called to set the encryption security and cipher modes
5460 *            for the encryption engine.
5461 *
5462 *  Parameters:
5463 *
5464 *    tiRoot:        Pointer to driver/port instance.
5465 *
5466 *  Return:
5467 *   tiSuccess       The request is being processed
5468 *   tiError         The encryption engine is not in factory init mode or multiple
5469 *                   security modes were specified.
5470 *
5471 *****************************************************************************/
5472 
5473 osGLOBAL bit32 tiCOMEncryptSetMode(tiRoot_t            *tiRoot,
5474                                    bit32               securityCipherMode)
5475 {
5476   bit32                         returnCode;
5477   bit32                         tiStatus;
5478   agsaEncryptInfo_t mode;
5479   agsaEncryptInfo_t *pmode = &mode;
5480 
5481   tdsaRoot_t        *tdsaRoot ;
5482   tdsaContext_t     *tdsaAllShared;
5483   agsaRoot_t        *agRoot;
5484 
5485   TD_ASSERT(tiRoot, "tiRoot");
5486   tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
5487   TD_ASSERT(tdsaRoot, "tdsaRoot");
5488 
5489   tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
5490   TD_ASSERT(tdsaAllShared, "tdsaAllShared");
5491   agRoot = &(tdsaAllShared->agRootNonInt);
5492   TD_ASSERT(agRoot, "agRoot");
5493 
5494   pmode->encryptionSecurityMode = 0;
5495   pmode->encryptionCipherMode = 0;
5496   pmode->status = 0;
5497 
5498   TI_DBG1(("tiCOMEncryptSetMode:\n"));
5499 
5500 
5501   if(( securityCipherMode & TI_ENCRYPT_SEC_MODE_A ) == TI_ENCRYPT_SEC_MODE_A)
5502   {
5503     pmode->encryptionSecurityMode = agsaEncryptSMA;
5504   }
5505 
5506   if(( securityCipherMode & TI_ENCRYPT_SEC_MODE_B ) == TI_ENCRYPT_SEC_MODE_B)
5507   {
5508     pmode->encryptionSecurityMode = agsaEncryptSMB;
5509   }
5510 
5511   if( (securityCipherMode & TI_ENCRYPT_ATTRIB_CIPHER_XTS)  == TI_ENCRYPT_ATTRIB_CIPHER_XTS)
5512   {
5513     pmode->encryptionCipherMode |= agsaEncryptCipherModeXTS;
5514   }
5515 
5516   /* ECB is not supported in SPCv */
5517   if(( securityCipherMode & TI_ENCRYPT_ATTRIB_CIPHER_ECB)  == TI_ENCRYPT_ATTRIB_CIPHER_ECB)
5518   {
5519     return tiError;
5520   }
5521 
5522   returnCode = saEncryptSetMode(agRoot,agNULL, 0, pmode );
5523 
5524   if (returnCode == AGSA_RC_SUCCESS)
5525   {
5526     tiStatus = tiSuccess;
5527   }
5528   else if (returnCode == AGSA_RC_BUSY)
5529   {
5530     TI_DBG1(("tiCOMEncryptSetMode:tiBusy\n"));
5531     tiStatus = tiBusy;
5532   }
5533   else
5534   {
5535     TI_DBG1(("tiCOMEncryptSetMode:tiError\n"));
5536     tiStatus = tiError;
5537   }
5538 
5539   return(tiStatus);
5540 }
5541 
5542 /*****************************************************************************
5543 *
5544 * tiCOMEncryptDekAdd
5545 *
5546 *  Purpose:  This function is called to add a DEK to the controller cache.
5547 *
5548 *  Parameters:
5549 *
5550 *    tiRoot:          Pointer to driver/port instance.
5551 *    kekIndext:         Index of the KEK table
5552 *    dekTableSelect:  Number of the DEK table receiving a new entry
5553 *    dekAddrHi:       Upper 32-bits of the DEK table physical address
5554 *    dekAddrLo:       Lower 32-bits of the DEK table physical address
5555 *    dekIndex:        Number of the first entry in the DEK table that will inserted in the cache
5556 *    dekNumberOfEntries: Number of entries to be inserted in the cache
5557 *    dekBlobFormat:     Specifies the DEK blob format
5558 *    dekTableKeyEntrySize: Encoded value for DEK Entry Size in the DEK Table
5559 *
5560 *  Return:
5561 *   tiSuccess       The request is being processed
5562 *   tiError         An invalid parameter was specified
5563 *
5564 *****************************************************************************/
5565 osGLOBAL bit32 tiCOMEncryptDekAdd(tiRoot_t            *tiRoot,
5566                                   bit32               kekIndex,
5567                                   bit32               dekTableSelect,
5568                                   bit32               dekAddrHi,
5569                                   bit32               dekAddrLo,
5570                                   bit32               dekIndex,
5571                                   bit32               dekNumberOfEntries,
5572                                   bit32               dekBlobFormat,
5573                                   bit32               dekTableKeyEntrySize
5574 
5575                                   )
5576 {
5577     agsaRoot_t        *agRoot;
5578     bit32           returnCode;
5579     bit32           tiStatus;
5580     tdsaRoot_t        *tdsaRoot ;
5581     tdsaContext_t     *tdsaAllShared ;
5582 
5583     TD_ASSERT(tiRoot, "tiRoot");
5584     tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
5585     TD_ASSERT(tdsaRoot, "tdsaRoot");
5586 
5587     tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
5588     TD_ASSERT(tdsaAllShared, "tdsaAllShared");
5589     agRoot = &(tdsaAllShared->agRootNonInt);
5590     TD_ASSERT(agRoot, "agRoot");
5591 
5592 
5593     agRoot = &(tdsaAllShared->agRootNonInt);
5594 
5595 
5596     TI_DBG1(("tiCOMEncryptDekAdd:\n" ));
5597 
5598     returnCode = saEncryptDekCacheUpdate(agRoot,
5599                                     agNULL,
5600                                     0,
5601                                     kekIndex,
5602                                     dekTableSelect,
5603                                     dekAddrHi,
5604                                     dekAddrLo,
5605                                     dekIndex,
5606                                     dekNumberOfEntries,
5607                                     dekBlobFormat,
5608                                     dekTableKeyEntrySize
5609                                     );
5610 
5611     if (returnCode == AGSA_RC_SUCCESS)
5612     {
5613         tiStatus = tiSuccess;
5614     }
5615     else if (returnCode == AGSA_RC_BUSY)
5616     {
5617         tiStatus = tiBusy;
5618     }
5619     else
5620     {
5621         tiStatus = tiError;
5622     }
5623 
5624     return(tiStatus);
5625 }
5626 
5627 /*****************************************************************************
5628 *
5629 * tiCOMEncryptDekInvalidate
5630 *
5631 *  Purpose:  This function is called to remove a DEK entry from the hardware cache.
5632 *
5633 *  Parameters:
5634 *
5635 *    tiRoot:        Pointer to driver/port instance.
5636 *    dekTable       DEK table that will be affected
5637 *    dekIndex:      DEK table entry that will be affected. The value 0xfffffff clears the cache.
5638 *
5639 *  Return:
5640 *   tiSuccess       The request is being processed
5641 *   tiError         An invalid parameter was specified
5642 *   tiBusy          An operation is already in progress
5643 *
5644 *****************************************************************************/
5645 
5646 osGLOBAL bit32 tiCOMEncryptDekInvalidate(tiRoot_t            *tiRoot,
5647                                          bit32               dekTable,
5648                                          bit32               dekIndex)
5649 {
5650 
5651     tdsaRoot_t        *tdsaRoot;
5652     tdsaContext_t     *tdsaAllShared;
5653 
5654     agsaRoot_t        *agRoot;
5655     tiEncryptPort_t tiEncryptPort;
5656     tiEncryptDek_t  tiEncryptDek;
5657     bit32           returnCode;
5658     bit32           tiStatus;
5659 
5660     TD_ASSERT(tiRoot, "tiRoot");
5661     tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
5662     TD_ASSERT(tdsaRoot, "tdsaRoot");
5663 
5664     tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
5665     TD_ASSERT(tdsaAllShared, "tdsaAllShared");
5666     agRoot = &(tdsaAllShared->agRootNonInt);
5667     TD_ASSERT(agRoot, "agRoot");
5668 
5669     TI_DBG1(("tiCOMEncryptDekInvalidate:dekTable 0x%x dekIndex 0x%x\n", dekTable, dekIndex));
5670 
5671     returnCode = saEncryptDekCacheInvalidate(agRoot, agNULL, 0, dekTable, dekIndex);
5672 
5673     if (returnCode == AGSA_RC_SUCCESS)
5674     {
5675         tiStatus = tiSuccess;
5676     }
5677     else
5678     {
5679         if (returnCode == AGSA_RC_NOT_SUPPORTED)
5680         {
5681             tiStatus = tiNotSupported;
5682         }
5683         else if (returnCode == AGSA_RC_BUSY)
5684         {
5685             tiStatus = tiBusy;
5686         }
5687         else
5688         {
5689             tiStatus = tiError;
5690         }
5691 
5692         tiEncryptDek.dekTable = dekTable;
5693         tiEncryptDek.dekIndex = dekIndex;
5694 
5695         tiEncryptPort.encryptEvent = tiEncryptDekInvalidate;
5696         tiEncryptPort.subEvent = 0;
5697         tiEncryptPort.pData = (void *) &tiEncryptDek;
5698 
5699         ostiPortEvent(tiRoot,tiEncryptOperation,tiStatus,&tiEncryptPort);
5700     }
5701 
5702     return(tiStatus);
5703 }
5704 
5705 /*****************************************************************************
5706 *
5707 * tiCOMEncryptKekAdd
5708 *
5709 *  Purpose:  This function is called to add a KEK in the register specified by
5710 *            the index parameter.
5711 *
5712 *  Parameters:
5713 *
5714 *    tiRoot:           Pointer to driver/port instance.
5715 *    kekIndex:         KEK table entry that will be affected
5716 *    wrapperKekIndex   KEK table entry that encrypt the KEK blob
5717 *    encryptKekBlob    KEK blob that will be added
5718 *
5719 *  Return:
5720 *   tiSuccess       The request is being processed
5721 *   tiError         An invalid parameter was specified
5722 *   tiBusy          A KEK operation is already in progress
5723 *
5724 *****************************************************************************/
5725 
5726 osGLOBAL bit32 tiCOMEncryptKekAdd(tiRoot_t            *tiRoot,
5727                                   bit32               kekIndex,
5728                                   bit32               wrapperKekIndex,
5729                                   bit32               blobFormat,
5730                                   tiEncryptKekBlob_t *encryptKekBlob)
5731 {
5732   tdsaRoot_t        *tdsaRoot;
5733   tdsaContext_t     *tdsaAllShared;
5734   agsaRoot_t        *agRoot;
5735 
5736   bit32           returnCode= AGSA_RC_BUSY;
5737   bit32           tiStatus= tiError;
5738 
5739   tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
5740   tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
5741 
5742   agRoot = &(tdsaAllShared->agRootNonInt);
5743 
5744   TI_DBG1(("tiCOMEncryptDekInvalidate: kekIndex 0x%x wrapperKekIndex 0x%x\n", kekIndex , wrapperKekIndex));
5745 
5746   returnCode = saEncryptKekUpdate(agRoot,
5747                                   agNULL,
5748                                   0,
5749                                   AGSA_ENCRYPT_STORE_NVRAM,
5750                                   kekIndex,
5751                                   wrapperKekIndex,
5752                                   blobFormat,
5753                                   (agsaEncryptKekBlob_t *) encryptKekBlob);
5754 
5755   if (returnCode == AGSA_RC_SUCCESS)
5756   {
5757     tiStatus = tiSuccess;
5758   }
5759   else if (returnCode == AGSA_RC_BUSY)
5760   {
5761     tiStatus = tiBusy;
5762   }
5763   else
5764   {
5765     tiStatus = tiError;
5766   }
5767 
5768   return(tiStatus);
5769 }
5770 #ifdef HIALEAH_ENCRYPTION
5771 
5772 osGLOBAL bit32 tiCOMEncryptHilSet(tiRoot_t            *tiRoot )
5773 {
5774   tdsaRoot_t        *tdsaRoot;
5775   tdsaContext_t     *tdsaAllShared;
5776   agsaRoot_t        *agRoot;
5777   agsaEncryptInfo_t agsaEncryptInfo;
5778 
5779   bit32           returnCode= tiBusy;
5780   bit32           tiStatus= tiError;
5781 
5782   tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
5783   tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
5784 
5785   agRoot = &(tdsaAllShared->agRootNonInt);
5786 
5787 
5788   returnCode = saEncryptGetMode(agRoot,agNULL, &agsaEncryptInfo);
5789   TI_DBG1(("tiCOMEncryptHilSet: saEncryptGetMode returnCode 0x%x agsaEncryptInfo status 0x%x Smode 0x%x CMode 0x%x\n",
5790           returnCode,
5791           agsaEncryptInfo.status,
5792           agsaEncryptInfo.encryptionSecurityMode,
5793           agsaEncryptInfo.encryptionCipherMode ));
5794 
5795   if (returnCode == AGSA_RC_FAILURE)
5796   {
5797    TI_DBG1(("tiCOMEncryptHilSet:agsaEncryptInfo.status 0x%x\n",agsaEncryptInfo.status ));
5798     if(agsaEncryptInfo.status == 0x81)
5799     {
5800    	  TI_DBG1(("tiCOMEncryptHilSet: status 0x80 KEY CARD MISMATCH agsaEncryptInfo.status 0x%x\n",agsaEncryptInfo.status ));
5801       returnCode = saEncryptHilUpdate(agRoot,
5802                                       agNULL,
5803                                       0 );
5804       if (returnCode == AGSA_RC_SUCCESS)
5805       {
5806         TI_DBG1(("tiCOMEncryptHilSet:AGSA_RC_SUCCESS\n"));
5807       }
5808     }
5809 	else if(agsaEncryptInfo.status == 0x80)
5810     {
5811    		ostidisableEncryption(tiRoot);
5812 		TI_DBG1(("tiCOMEncryptHilSet: status 0x80 KEY CARD MISSING agsaEncryptInfo.status 0x%x\n",agsaEncryptInfo.status ));
5813     	returnCode = AGSA_RC_SUCCESS;
5814 	}
5815     else
5816     {
5817       TI_DBG1(("tiCOMEncryptHilSet: not status 0x81 agsaEncryptInfo.status 0x%x\n",agsaEncryptInfo.status ));
5818       returnCode = AGSA_RC_FAILURE;
5819     }
5820   }
5821 
5822   if (returnCode == AGSA_RC_SUCCESS)
5823   {
5824     tiStatus = tiSuccess;
5825   }
5826   else if (returnCode == AGSA_RC_BUSY)
5827   {
5828     TI_DBG1(("tiCOMEncryptHilSet:AGSA_RC_BUSY\n"));
5829     tiStatus = tiBusy;
5830   }
5831   else
5832   {
5833     TI_DBG1(("tiCOMEncryptHilSet:tiError\n"));
5834     tiStatus = tiError;
5835   }
5836 
5837   return(tiStatus);
5838 }
5839 #endif /* HIALEAH_ENCRYPTION */
5840 
5841 /*****************************************************************************
5842 *
5843 * tiCOMEncryptKekStore
5844 *
5845 *  Purpose:  This function is called to store a KEK in NVRAM. If -1 is specified
5846 *            as the KEK index, then all KEKs will be stored.
5847 *
5848 *  Parameters:
5849 *
5850 *    tiRoot:        Pointer to driver/port instance.
5851 *    kekIndex:      The KEK to be stored in NVRAM
5852 *
5853 *  Return:
5854 *   tiSuccess       The request is being processed
5855 *   tiError         An invalid parameter was specified
5856 *   tiBusy          A KEK operation is already in progress
5857 *
5858 *****************************************************************************/
5859 
5860 osGLOBAL bit32 tiCOMEncryptKekStore(tiRoot_t  *tiRoot,
5861                                     bit32      kekIndex)
5862 {
5863 #ifdef NOT_YET
5864     tdsaRoot_t        *tdsaRoot;
5865     tdsaContext_t     *tdsaAllShared;
5866     agsaRoot_t        *agRoot;
5867 #endif
5868 /*
5869     bit32           returnCode= AGSA_RC_BUSY;
5870 */
5871     bit32           tiStatus = tiError;
5872 
5873 #ifdef NOT_YET
5874     tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
5875     tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
5876 
5877     agRoot = &(tdsaAllShared->agRootNonInt);
5878 #endif
5879 
5880     TI_DBG1(("tiCOMEncryptKekStore: Needs code !!!! kekIndex 0x%x\n", kekIndex ));
5881 /*
5882     returnCode = fcEncryptKekStore(agRoot, kekIndex);
5883 
5884     if (returnCode == AGSA_RC_SUCCESS)
5885     {
5886         tiStatus = tiSuccess;
5887     }
5888     else if (returnCode == AGSA_RC_BUSY)
5889     {
5890         tiStatus = tiBusy;
5891     }
5892     else
5893     {
5894         tiStatus;
5895     }
5896 */
5897     return(tiStatus);
5898 }
5899 
5900 /*****************************************************************************
5901 *
5902 * tiCOMEncryptKekLoad
5903 *
5904 *  Purpose:  This function is called to load a KEK from NVRAM. If -1 is specified
5905 *            as the KEK index, then all KEKs will be loaded.
5906 *
5907 *  Parameters:
5908 *
5909 *    tiRoot:        Pointer to driver/port instance.
5910 *    kekIndex:      The KEK to be loaded in NVRAM
5911 *
5912 *  Return:
5913 *   tiSuccess       The request is being processed
5914 *   tiError         An invalid parameter was specified
5915 *   tiBusy          A KEK operation is already in progress
5916 *
5917 *****************************************************************************/
5918 
5919 osGLOBAL bit32 tiCOMEncryptKekLoad(tiRoot_t            *tiRoot,
5920                                    bit32               kekIndex)
5921 {
5922 #ifdef NOT_YET
5923     tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
5924     tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
5925     agsaRoot_t      *agRoot;
5926     //bit32           returnCode;
5927 #endif
5928     bit32           tiStatus = tiError;
5929 
5930 #ifdef NOT_YET
5931     agRoot = &(tdsaAllShared->agRootNonInt);
5932 #endif
5933 /*
5934     returnCode = fcEncryptKekLoad(agRoot, kekIndex);
5935 
5936     if (returnCode == AGSA_RC_SUCCESS)
5937     {
5938         tiStatus = tiSuccess;
5939     }
5940     else if (returnCode == AGSA_RC_BUSY)
5941     {
5942         tiStatus = tiBusy;
5943     }
5944     else
5945     {
5946         tiStatus = tiError;
5947     }
5948 */
5949     return(tiStatus);
5950 }
5951 
5952 /*****************************************************************************
5953 *
5954 * tiCOMEncryptSelfTest
5955 *
5956 *  Purpose:  This function starts the encryption self test. For the encryption self test, IOs must be quiesced.
5957 *                The completion of this function is via ostiPortEvent().
5958 *
5959 *  Parameters:
5960 *
5961 *    tiRoot:      Pointer to driver/port instance.
5962 *    type:        Types of test
5963                       0x1: tiBISTTest
5964                       0x2: tiHMACTest
5965                       Others are reserved.
5966 *    length:
5967                    Size of the test descriptor in bytes, e.g.,
5968                    Sizeof(tiEncryptSelfTestDescriptor_t)
5969                    Sizeof(tiEncryptHMACTestDescriptor_t)
5970 *    TestDescriptor       address of the test descriptor structure.
5971 *
5972 *  Return:
5973 *   tiSuccess     The request is being processed
5974 *   tiError          An invalid parameter was specified
5975 *   tiBusy          A encrytion operation is already in progress
5976 *
5977 *****************************************************************************/
5978 osGLOBAL bit32 tiCOMEncryptSelfTest(
5979                         tiRoot_t  *tiRoot,
5980                         bit32      type,
5981                         bit32      length,
5982                         void      *TestDescriptor
5983                         )
5984 {
5985   tdsaRoot_t     *tdsaRoot       = agNULL;
5986   tdsaContext_t  *tdsaAllShared  = agNULL;
5987   agsaRoot_t     *agRoot         = agNULL;
5988 
5989   bit32           returnCode     = AGSA_RC_BUSY;
5990   bit32           tiStatus       = tiError;
5991 
5992   tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
5993   TD_ASSERT(tdsaRoot != agNULL, "tdsaRoot is NULL !!!");
5994 
5995   tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
5996   TD_ASSERT(tdsaAllShared != agNULL, "tdsaAllShared is NULL !!!");
5997 
5998   agRoot = &(tdsaAllShared->agRootNonInt);
5999   TD_ASSERT(agRoot != agNULL, "agRoot is NULL !!!");
6000 
6001   TI_DBG1(("tiCOMEncryptSelfTest: type =  0x%x length = 0x%x\n", type, length));
6002 
6003   /*do some sanity checking */
6004   if ( ((type == TI_ENCRYPTION_TEST_TYPE_BIST) && (length != sizeof(tiEncryptSelfTestDescriptor_t )))  ||
6005        ((type == TI_ENCRYPTION_TEST_TYPE_HMAC) && (length != sizeof(tiEncryptHMACTestDescriptor_t))) )
6006   {
6007     TI_DBG1(("tiCOMEncryptSelfTest: type or length error, type 0x%x length 0x%x\n", type, length));
6008     tiStatus = tiError;
6009   }
6010   else
6011   {
6012     returnCode = saEncryptSelftestExecute(agRoot,
6013                                       agNULL,
6014                                       0,
6015                                       type,
6016                                       length,
6017                                       TestDescriptor
6018                                       );
6019 
6020     if (returnCode == AGSA_RC_SUCCESS)
6021     {
6022       tiStatus = tiSuccess;
6023     }
6024     else if (returnCode == AGSA_RC_BUSY)
6025     {
6026       tiStatus = tiBusy;
6027     }
6028     else
6029     {
6030       tiStatus = tiError;
6031     }
6032   }
6033 
6034   return(tiStatus);
6035 }
6036 
6037 /*****************************************************************************
6038 *
6039 * tiCOMSetOperator
6040 *
6041 *  Purpose:  This function is called to login to or logout out from the controller by an operator.
6042                   The status is reported via ostiPortEvent().
6043 *
6044 *  Parameters:
6045 *
6046 *    tiRoot:      Pointer to driver/port instance.
6047 *    flag:         operator flag.
6048                      Bits 0-3: Access type (ACS)
6049                        0x1: Login
6050                        0x2: Logout
6051                        All others are reserved.
6052                      Bit 4: KEYopr pinned in the KEK table (PIN)
6053                        0: Not pinned. Operator ID table will be searched during authentication.
6054                        1: Pinned. OPRIDX is referenced to unwrap the certificate.
6055                      Bits 5-7: Reserved
6056                      Bits 8-15: KEKopr Index in the KEK Table (OPRIDX). If KEKopr is pinned in the KEK table, OPRIDX is to reference the KEK for authentication
6057                      Bits 16-31: Reserved.
6058 
6059      cert:         The pointer to the operator's certificate. The size of the certificate is 40 bytes.
6060 *
6061 *  Return:
6062 *   tiSuccess     Log in or log out was started.
6063 *   tiError          Log in or log out was not started.
6064 *   tiBusy          A operator management operation is already in progress
6065 *
6066 *****************************************************************************/
6067 osGLOBAL bit32 tiCOMSetOperator(
6068                         tiRoot_t      *tiRoot,
6069                         bit32          flag,
6070                         void          *cert
6071                         )
6072 {
6073   tdsaRoot_t     *tdsaRoot       = agNULL;
6074   tdsaContext_t  *tdsaAllShared  = agNULL;
6075   agsaRoot_t     *agRoot         = agNULL;
6076 
6077   bit32           returnCode     = AGSA_RC_FAILURE;
6078   bit32           tiStatus       = tiError;
6079 
6080   tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
6081   TD_ASSERT(tdsaRoot != agNULL, "tdsaRoot is NULL !!!");
6082 
6083   tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
6084   TD_ASSERT(tdsaAllShared != agNULL, "tdsaAllShared is NULL !!!");
6085 
6086   agRoot = &(tdsaAllShared->agRootNonInt);
6087   TD_ASSERT(agRoot != agNULL, "agRoot is NULL !!!");
6088 
6089   TI_DBG1(("tiCOMSetOperator: flag =  0x%x \n", flag));
6090 
6091   returnCode = saSetOperator(agRoot,
6092                              agNULL,
6093                              0,
6094                              flag,
6095                              cert);
6096 
6097   if (returnCode == AGSA_RC_SUCCESS)
6098   {
6099     tiStatus = tiSuccess;
6100   }
6101   else if (returnCode == AGSA_RC_BUSY)
6102   {
6103     tiStatus = tiBusy;
6104   }
6105   else
6106   {
6107     tiStatus = tiError;
6108   }
6109 
6110   return(tiStatus);
6111 }
6112 
6113 /*****************************************************************************
6114 *
6115 * tiCOMGetOperator
6116 *
6117 *  Purpose:  This function is used to retrieve the role and ID of the current operator or all operators.
6118                   The status is reported via ostiPortEvent().
6119 *
6120 *  Parameters:
6121 *
6122 *    tiRoot:      Pointer to driver/port instance.
6123 *    option:     Types of get operations
6124                        0x1: Current operator only
6125                        0x2: All operators
6126                        All others are reserved.
6127       AddrHi      Upper 32-bit host physical address to store operator certificates.
6128                     This field is used only when option is 0x2
6129       AddrLo     Lower 32-bit host physical address to store operator certificates.
6130                     This field is used only when option is 0x2
6131 *
6132 *  Return:
6133 *   tiSuccess     The operation was started..
6134 *   tiError          The operation was not started.
6135 *   tiBusy          A operator management operation is already in progress
6136 *
6137 *****************************************************************************/
6138 osGLOBAL bit32 tiCOMGetOperator(
6139                            tiRoot_t   *tiRoot,
6140                            bit32       option,
6141                            bit32       AddrHi,
6142                            bit32       AddrLo
6143                            )
6144 {
6145   tdsaRoot_t     *tdsaRoot       = agNULL;
6146   tdsaContext_t  *tdsaAllShared  = agNULL;
6147   agsaRoot_t     *agRoot         = agNULL;
6148 
6149   bit32           returnCode     = AGSA_RC_FAILURE;
6150   bit32           tiStatus       = tiError;
6151 
6152   tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
6153   TD_ASSERT(tdsaRoot != agNULL, "tdsaRoot is NULL !!!");
6154 
6155   tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
6156   TD_ASSERT(tdsaAllShared != agNULL, "tdsaAllShared is NULL !!!");
6157 
6158   agRoot = &(tdsaAllShared->agRootNonInt);
6159   TD_ASSERT(agRoot != agNULL, "agRoot is NULL !!!");
6160 
6161   TI_DBG1(("tiCOMGetOperator: option = 0x%x \n", option));
6162 
6163   returnCode = saGetOperator(agRoot,
6164                              agNULL,
6165                              0,
6166                              option,
6167                              AddrHi,
6168                              AddrLo);
6169 
6170   if (returnCode == AGSA_RC_SUCCESS)
6171   {
6172     tiStatus = tiSuccess;
6173   }
6174   else if (returnCode == AGSA_RC_BUSY)
6175   {
6176     tiStatus = tiBusy;
6177   }
6178   else
6179   {
6180     tiStatus = tiError;
6181   }
6182 
6183   return(tiStatus);
6184 }
6185 
6186 /*****************************************************************************
6187 *
6188 * tiCOMOperationManagement
6189 *
6190 *  Purpose:  this function is used to manage operators,  e.g. adding or deleting an operator..
6191 *
6192 *  Parameters:
6193 *
6194 *   tiRoot:      Pointer to driver/port instance.
6195 *   flag:         operation flag.
6196                     Bits 0-7: Operator Management Operation(OMO)
6197                        0: Add an operator.
6198                        1: Delete an operator.
6199                        2: Delete all operators.
6200                        Others are reserved.
6201                     Bit 8: Pinned to KEK RAM (PKR)
6202                       0: Operator's KEK is stored in the operator ID table(OID_TLB) only.
6203                       1: Operator's KEK is pinned to the internal KEK RAM (1 of the 16 entries) and is also stored in OID_TLB.
6204                     Bits 9-10: KEKopr blob format (KBF)
6205                       00b: Reserved.
6206                       01b: AGSA_ENCRYPTED_KEK_PMCA.
6207                       10b: AGSA_ENCRYPTED_KEK_PMCB.
6208                       11b: Reserved.
6209                     Bits 11-15: Reserved
6210                     Bits 16-23: KEKauth Index in the KEK Table (AUTIDX)
6211                     Bits 24-31: KEKopr Index in the KEK Table (OPRIDX). This field is valid only when PKR is 1.
6212 
6213        role        Role
6214                        01b: Crypto officer role.
6215                        10b: User role.
6216                        All others are reserved.
6217 
6218 *    idString:         Pointer to the tiID_t structure describing the ID string
6219 *    kekBlob          Pointer to the tiEncryptKekBlob_t structure describing KBLOB.
6220 *
6221 *  Return:
6222 *   tiSuccess     The request is being processed
6223 *   tiError          An invalid parameter was specified
6224 *   tiBusy          A operator management operation is already in progress
6225 *
6226 *****************************************************************************/
6227 osGLOBAL bit32 tiCOMOperatorManagement(
6228                         tiRoot_t            *tiRoot,
6229                         bit32                flag,
6230                         bit8                 role,
6231                         tiID_t              *idString,
6232                         tiEncryptKekBlob_t  *kekBlob
6233                         )
6234 {
6235   tdsaRoot_t     *tdsaRoot       = agNULL;
6236   tdsaContext_t  *tdsaAllShared  = agNULL;
6237   agsaRoot_t     *agRoot         = agNULL;
6238 
6239   bit32           returnCode     = AGSA_RC_BUSY;
6240   bit32           tiStatus       = tiError;
6241 
6242   tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
6243   TD_ASSERT(tdsaRoot != agNULL, "tdsaRoot is NULL !!!");
6244 
6245   tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
6246   TD_ASSERT(tdsaAllShared != agNULL, "tdsaAllShared is NULL !!!");
6247 
6248   agRoot = &(tdsaAllShared->agRootNonInt);
6249   TD_ASSERT(agRoot != agNULL, "agRoot is NULL !!!");
6250 
6251   TI_DBG1(("tiCOMOperatorManagement: flag =  0x%x role = 0x%x\n", flag, role));
6252 
6253   returnCode = saOperatorManagement(agRoot,
6254                                     agNULL,
6255                                     0,
6256                                     flag,
6257                                     role,
6258                                     (agsaID_t*)idString,
6259                                     (agsaEncryptKekBlob_t *)kekBlob
6260                                     );
6261 
6262   if (returnCode == AGSA_RC_SUCCESS)
6263   {
6264     tiStatus = tiSuccess;
6265   }
6266   else if (returnCode == AGSA_RC_BUSY)
6267   {
6268     tiStatus = tiBusy;
6269   }
6270   else
6271   {
6272     tiStatus = tiError;
6273   }
6274 
6275   return(tiStatus);
6276 }
6277 
6278 /*****************************************************************************
6279 *! \brief tdssRemoveSASSATAFromSharedcontext
6280 *
6281 *  Purpose:  This function removes all discovered devices belonging to
6282 *            a given portcontext from device list
6283 *
6284 *
6285 *  \param   agRoot                   Pointer to the root data structure of
6286 *                                    TD and Lower layer
6287 *  \param   tsddPortContext_Instance Pointer to the target port context
6288 *
6289 *  \Return: none
6290 *
6291 *****************************************************************************/
6292 #ifdef INITIATOR_DRIVER                     /*TBD: added to compile tgt_drv. (TP)*/
6293 osGLOBAL void
6294 tdssRemoveSASSATAFromSharedcontext(
6295                           agsaRoot_t           *agRoot,
6296                           tdsaPortContext_t    *PortContext_Instance
6297                           )
6298 {
6299   tdsaDeviceData_t  *oneDeviceData = agNULL;
6300   tdList_t          *DeviceListList;
6301   tdsaRootOsData_t  *osData = (tdsaRootOsData_t *)agRoot->osData;
6302   tiRoot_t          *tiRoot = (tiRoot_t *)osData->tiRoot;
6303   tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
6304   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
6305 
6306   TI_DBG1(("tdssRemoveSASSATAFromSharedcontext: start\n"));
6307   TI_DBG1(("tdssRemoveSASSATAFromSharedcontext: pid %d\n", PortContext_Instance->id));
6308 
6309   /* find oneDeviceData belonging to the portcontext */
6310   DeviceListList = tdsaAllShared->MainDeviceList.flink;
6311   while (DeviceListList != &(tdsaAllShared->MainDeviceList))
6312   {
6313     oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
6314     if (oneDeviceData == agNULL)
6315     {
6316       TI_DBG1(("tdssRemoveSASSATAFromSharedcontext: oneDeviceData is NULL!!!\n"));
6317       return;
6318     }
6319     if (oneDeviceData->tdPortContext == PortContext_Instance)
6320     {
6321       TI_DBG1(("tdssRemoveSASSATAFromSharedcontext: pid %d did %d\n", PortContext_Instance->id, oneDeviceData->id));
6322       TI_DBG1(("tdssRemoveSASSATAFromSharedcontext: sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
6323       TI_DBG1(("tdssRemoveSASSATAFromSharedcontext: sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
6324 
6325       /* reset valid bit */
6326       oneDeviceData->valid = agFALSE;
6327       oneDeviceData->valid2 = agFALSE;
6328       oneDeviceData->registered = agFALSE;
6329       /* notify only reported devices to OS layer*/
6330       if ( DEVICE_IS_SSP_TARGET(oneDeviceData) ||
6331            DEVICE_IS_STP_TARGET(oneDeviceData) ||
6332            DEVICE_IS_SATA_DEVICE(oneDeviceData)
6333         )
6334       {
6335         ostiInitiatorEvent(
6336                          tiRoot,
6337                          PortContext_Instance->tiPortalContext,
6338                          &(oneDeviceData->tiDeviceHandle),
6339                          tiIntrEventTypeDeviceChange,
6340                          tiDeviceRemoval,
6341                          agNULL
6342                          );
6343       }
6344       DeviceListList = DeviceListList->flink;
6345     /* to-do: deregister */
6346 #ifdef REMOVED  /* don't remove device from the device list. May screw up ordering */
6347       TDLIST_DEQUEUE_THIS(&(oneDeviceData->MainLink));
6348       TDLIST_ENQUEUE_AT_TAIL(&(oneDeviceData->FreeLink), &(tdsaAllShared->FreeDeviceList));
6349 #endif
6350     }
6351     else
6352     {
6353       TI_DBG6(("tdssRemoveSASSATAFromSharedcontext: move to the next\n"));
6354       DeviceListList = DeviceListList->flink;
6355     }
6356   } /* while */
6357 
6358   return;
6359 }
6360 
6361 /*****************************************************************************
6362 *! \brief tdssRemoveSASSATAFromSharedcontextByReset
6363 *
6364 *  Purpose:  This function removes all ports and discovered devices
6365 *
6366 *
6367 *  \param   agRoot                   Pointer to the root data structure of
6368 *                                    TD and Lower layer
6369 *
6370 *  \Return: none
6371 *
6372 *****************************************************************************/
6373 osGLOBAL void
6374 tdssRemoveSASSATAFromSharedcontextByReset(
6375                                           agsaRoot_t           *agRoot
6376                                           )
6377 {
6378   tdsaPortContext_t *onePortContext = agNULL;
6379   tdsaDeviceData_t  *oneDeviceData = agNULL;
6380   tdList_t          *PortContextList;
6381   tdList_t          *DeviceListList;
6382   tdsaRootOsData_t  *osData = (tdsaRootOsData_t *)agRoot->osData;
6383   tiRoot_t          *tiRoot = (tiRoot_t *)osData->tiRoot;
6384   tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
6385   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
6386 #ifdef FDS_DM
6387   dmRoot_t          *dmRoot = agNULL;
6388   dmPortContext_t   *dmPortContext = agNULL;
6389   dmPortInfo_t      dmPortInfo;
6390 #endif
6391 #ifdef FDS_SM
6392   smRoot_t          *smRoot = &(tdsaAllShared->smRoot);
6393   smDeviceHandle_t  *smDeviceHandle = agNULL;
6394   agsaDevHandle_t   *agDevHandle = agNULL;
6395 #endif
6396 
6397   TI_DBG1(("tdssRemoveSASSATAFromSharedcontextByReset: start\n"));
6398 
6399 #ifdef FDS_DM
6400   dmRoot = &(tdsaAllShared->dmRoot);
6401 #endif
6402   /* looping throuhg all portcontext */
6403   PortContextList = tdsaAllShared->MainPortContextList.flink;
6404   while (PortContextList != &(tdsaAllShared->MainPortContextList))
6405   {
6406     onePortContext = TDLIST_OBJECT_BASE(tdsaPortContext_t, MainLink, PortContextList);
6407     if (onePortContext == agNULL)
6408     {
6409       TI_DBG1(("tdssRemoveSASSATAFromSharedcontextByReset: onePortContext is NULL!!!\n"));
6410       return;
6411     }
6412     TI_DBG1(("tdssRemoveSASSATAFromSharedcontextByReset: oneportContext pid %d\n", onePortContext->id));
6413     TI_DBG3(("tdssRemoveSASSATAFromSharedcontextByReset: sasAddressHi 0x%08x\n", onePortContext->sasLocalAddressHi));
6414     TI_DBG3(("tdssRemoveSASSATAFromSharedcontextByReset: sasAddressLo 0x%08x\n", onePortContext->sasLocalAddressLo));
6415 #ifdef FDS_DM
6416     if (onePortContext->UseDM == agTRUE)
6417     {
6418       dmPortContext = &(onePortContext->dmPortContext);
6419       dmDestroyPort(dmRoot, dmPortContext, &dmPortInfo);
6420     }
6421 #endif
6422 
6423     tdsaPortContextReInit(tiRoot, onePortContext);
6424 
6425     PortContextList = PortContextList->flink;
6426     tdsaSingleThreadedEnter(tiRoot, TD_PORT_LOCK);
6427     TDLIST_DEQUEUE_THIS(&(onePortContext->MainLink));
6428     TDLIST_ENQUEUE_AT_TAIL(&(onePortContext->FreeLink), &(tdsaAllShared->FreePortContextList));
6429     tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
6430   }
6431 
6432   /* reinitialize the device data belonging to this portcontext */
6433   DeviceListList = tdsaAllShared->MainDeviceList.flink;
6434   while (DeviceListList != &(tdsaAllShared->MainDeviceList))
6435   {
6436     oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
6437     if (oneDeviceData == agNULL)
6438     {
6439       TI_DBG1(("tdssRemoveSASSATAFromSharedcontextByReset: oneDeviceData is NULL!!!\n"));
6440       return;
6441     }
6442 
6443     TI_DBG1(("tdssRemoveSASSATAFromSharedcontextByReset: did %d\n", oneDeviceData->id));
6444     TI_DBG1(("tdssRemoveSASSATAFromSharedcontextByReset: sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
6445     TI_DBG1(("tdssRemoveSASSATAFromSharedcontextByReset: sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
6446 
6447 #ifdef FDS_SM
6448     agDevHandle = oneDeviceData->agDevHandle;
6449     smDeviceHandle = (smDeviceHandle_t *)&(oneDeviceData->smDeviceHandle);
6450     smDeregisterDevice(smRoot, agDevHandle, smDeviceHandle);
6451 #endif
6452 
6453     tdsaDeviceDataReInit(tiRoot, oneDeviceData);
6454 
6455     DeviceListList = DeviceListList->flink;
6456     tdsaSingleThreadedEnter(tiRoot, TD_DEVICE_LOCK);
6457     osti_memset(&(oneDeviceData->satDevData.satIdentifyData), 0xFF, sizeof(agsaSATAIdentifyData_t));
6458     TDLIST_DEQUEUE_THIS(&(oneDeviceData->MainLink));
6459     TDLIST_ENQUEUE_AT_TAIL(&(oneDeviceData->FreeLink), &(tdsaAllShared->FreeDeviceList));
6460     tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
6461     /* no dequeue from Mainlink for consistant ordering of devices */
6462   }
6463 
6464 
6465   return;
6466 }
6467 
6468 #endif
6469 
6470 
6471 /*****************************************************************************
6472 *! \brief tdssAddSASToSharedcontext
6473 *
6474 *  Purpose:  This function adds a discovered device to a device list of
6475 *            a shared context
6476 *
6477 *  \param   tsddPortContext_Instance Pointer to the target port context
6478 *  \param   agRoot                   Pointer to the root data structure of
6479 *                                    TD and Lower layer
6480 *  \param   agDevHandle              Pointer to a device handle
6481 *
6482 *  \Return: none
6483 *
6484 *****************************************************************************/
6485 osGLOBAL void
6486 tdssAddSASToSharedcontext(
6487                           tdsaPortContext_t    *tdsaPortContext_Instance,
6488                           agsaRoot_t           *agRoot,
6489                           agsaDevHandle_t      *agDevHandle, /* this is NULL */
6490                           tdsaSASSubID_t       *agSASSubID,
6491                           bit32                 registered, /* no longer in use */
6492                           bit8                  phyID,
6493                           bit32                 flag
6494                           )
6495 {
6496 
6497   tdsaPortContext_t *onePortContext = agNULL;
6498   tdList_t          *PortContextList;
6499   tdsaDeviceData_t  *oneDeviceData = agNULL;
6500   tdList_t          *DeviceListList;
6501   tdsaRootOsData_t  *osData = (tdsaRootOsData_t *)agRoot->osData;
6502   tiRoot_t          *tiRoot = (tiRoot_t *)osData->tiRoot;
6503   tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
6504   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
6505   bit32             new_device = agTRUE;
6506   bit32             Indenom = tdsaAllShared->QueueConfig.numInboundQueues;
6507   bit32             Outdenom = tdsaAllShared->QueueConfig.numOutboundQueues;
6508   bit8              dev_s_rate = 0;
6509   bit8              sasorsata = 1;
6510   bit8              connectionRate;
6511   bit32             found = agFALSE;
6512 
6513   TI_DBG3(("tdssAddSASToSharedcontext: start\n"));
6514   /*
6515     find a right portcontext
6516     then, get devicedata from FreeLink in DeviceList
6517     then, do pointer operations
6518     then, add the devicedata to the portcontext
6519   */
6520 
6521   /* find a right portcontext */
6522   PortContextList = tdsaAllShared->MainPortContextList.flink;
6523   while (PortContextList != &(tdsaAllShared->MainPortContextList))
6524   {
6525     onePortContext = TDLIST_OBJECT_BASE(tdsaPortContext_t, MainLink, PortContextList);
6526     if (onePortContext == tdsaPortContext_Instance)
6527     {
6528       TI_DBG3(("tdssAddSASToSharedContext: found; oneportContext ID %d\n", onePortContext->id));
6529       found = agTRUE;
6530       break;
6531     }
6532     PortContextList = PortContextList->flink;
6533   }
6534 
6535   if (found == agTRUE)
6536   {
6537     TI_DBG3(("tdssAddSASToSharedcontext: found pid %d\n", onePortContext->id));
6538   }
6539   else
6540   {
6541     TI_DBG1(("tdssAddSASToSharedcontext: Error!!! no portcontext found!!!\n"));
6542     return;
6543   }
6544 
6545   /* find a device's existence */
6546   DeviceListList = tdsaAllShared->MainDeviceList.flink;
6547   while (DeviceListList != &(tdsaAllShared->MainDeviceList))
6548   {
6549     oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
6550     if (oneDeviceData == agNULL)
6551     {
6552       TI_DBG1(("tdssAddSASToSharedcontext: oneDeviceData is NULL!!!\n"));
6553       return;
6554     }
6555     if ((oneDeviceData->SASAddressID.sasAddressHi == agSASSubID->sasAddressHi) &&
6556         (oneDeviceData->SASAddressID.sasAddressLo == agSASSubID->sasAddressLo) &&
6557         (oneDeviceData->tdPortContext == onePortContext)
6558          )
6559     {
6560       TI_DBG1(("tdssAddSASToSharedcontext: pid %d did %d\n", onePortContext->id, oneDeviceData->id));
6561       new_device = agFALSE;
6562       break;
6563     }
6564     DeviceListList = DeviceListList->flink;
6565   }
6566 
6567   /* new device */
6568   if (new_device == agTRUE)
6569   {
6570     TI_DBG3(("tdssAddSASToSharedcontext: new device\n"));
6571 
6572     tdsaSingleThreadedEnter(tiRoot, TD_DEVICE_LOCK);
6573     if (!TDLIST_NOT_EMPTY(&(tdsaAllShared->FreeDeviceList)))
6574     {
6575       tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
6576       TI_DBG1(("tdssAddSASToSharedContext: empty DeviceData FreeLink\n"));
6577       return;
6578     }
6579 
6580     TDLIST_DEQUEUE_FROM_HEAD(&DeviceListList, &(tdsaAllShared->FreeDeviceList));
6581     tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
6582     oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, FreeLink, DeviceListList);
6583 
6584     TI_DBG3(("tdssAddSASToSharedcontext: oneDeviceData %p\n", oneDeviceData));
6585 
6586     onePortContext->Count++;
6587     oneDeviceData->DeviceType = TD_SAS_DEVICE;
6588     oneDeviceData->agRoot = agRoot;
6589 
6590     if (flag == TD_OPERATION_TARGET)
6591     {
6592       oneDeviceData->agDevHandle = agDevHandle;
6593       agDevHandle->osData = oneDeviceData; /* TD layer */
6594     }
6595 
6596     /* saving sas address */
6597     oneDeviceData->SASAddressID.sasAddressLo = agSASSubID->sasAddressLo;
6598     oneDeviceData->SASAddressID.sasAddressHi = agSASSubID->sasAddressHi;
6599     oneDeviceData->initiator_ssp_stp_smp = agSASSubID->initiator_ssp_stp_smp;
6600     oneDeviceData->target_ssp_stp_smp = agSASSubID->target_ssp_stp_smp;
6601 
6602     oneDeviceData->tdPortContext = onePortContext;
6603     oneDeviceData->valid = agTRUE;
6604 
6605     /* new */
6606     oneDeviceData->directlyAttached = agTRUE;
6607     /* parse sasIDframe to fill in agDeviceInfo */
6608     DEVINFO_PUT_SMPTO(&oneDeviceData->agDeviceInfo, DEFAULT_SMP_TIMEOUT);
6609     DEVINFO_PUT_ITNEXUSTO(&oneDeviceData->agDeviceInfo, (bit16)tdsaAllShared->itNexusTimeout);
6610     DEVINFO_PUT_FBS(&oneDeviceData->agDeviceInfo, 0);
6611     /* enable TLR */
6612     DEVINFO_PUT_FLAG(&oneDeviceData->agDeviceInfo, 1);
6613 
6614     sasorsata = SAS_DEVICE_TYPE; /* SAS target (SAS disk or expander) */
6615     connectionRate = onePortContext->LinkRate;
6616     dev_s_rate = (bit8)(dev_s_rate | (sasorsata << 4));
6617     dev_s_rate = (bit8)(dev_s_rate | connectionRate);
6618     DEVINFO_PUT_DEV_S_RATE(&oneDeviceData->agDeviceInfo, dev_s_rate);
6619 
6620 
6621     DEVINFO_PUT_SAS_ADDRESSLO(
6622                               &oneDeviceData->agDeviceInfo,
6623                               agSASSubID->sasAddressLo
6624                               );
6625     DEVINFO_PUT_SAS_ADDRESSHI(
6626                               &oneDeviceData->agDeviceInfo,
6627                               agSASSubID->sasAddressHi
6628                               );
6629 
6630     oneDeviceData->agContext.osData = oneDeviceData;
6631     oneDeviceData->agContext.sdkData = agNULL;
6632 
6633     if (flag == TD_OPERATION_INITIATOR)
6634     {
6635       if (oneDeviceData->registered == agFALSE )
6636       {
6637         if( tdsaAllShared->sflag )
6638         {
6639           if( ! DEVICE_IS_SMP_TARGET(oneDeviceData))
6640           {
6641             TI_DBG1(("tdssAddSASToSharedcontext: First, saRegisterNewDevice sflag %d\n", tdsaAllShared->sflag));
6642             oneDeviceData->agDeviceInfo.flag = oneDeviceData->agDeviceInfo.flag | TD_XFER_RDY_PRIORTY_DEVICE_FLAG;
6643           }
6644         }
6645 
6646         saRegisterNewDevice( /* tdssAddSASToSharedcontext */
6647                             agRoot,
6648                             &oneDeviceData->agContext,
6649                             0,
6650                             &oneDeviceData->agDeviceInfo,
6651                             onePortContext->agPortContext,
6652                             0
6653                            );
6654       }
6655     }
6656     oneDeviceData->phyID = phyID;
6657     oneDeviceData->InQID = oneDeviceData->id % Indenom;
6658 
6659 #ifdef TARGET_DRIVER
6660     {
6661       bit32 localId = oneDeviceData->id;
6662       localId += 1;
6663       oneDeviceData->OutQID = localId % Outdenom;
6664       TI_DBG1(("tdssAddSASToSharedcontext: OutQID %d\n", oneDeviceData->OutQID)); /* tdsaRotateQnumber for tgt*/
6665 
6666     }
6667 #endif /* TARGET_DRIVER */
6668 
6669     TI_DBG4(("tdssAddSASToSharedcontext: SSP target %d STP target %d SATA device %d\n", DEVICE_IS_SSP_TARGET(oneDeviceData), DEVICE_IS_STP_TARGET(oneDeviceData), DEVICE_IS_SATA_DEVICE(oneDeviceData)));
6670     /* add the devicedata to the portcontext */
6671     tdsaSingleThreadedEnter(tiRoot, TD_DEVICE_LOCK);
6672     TDLIST_ENQUEUE_AT_TAIL(&(oneDeviceData->MainLink), &(tdsaAllShared->MainDeviceList));
6673     tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
6674     TI_DBG4(("tdssAddSASToSharedContext: one case pid %d did %d \n", onePortContext->id, oneDeviceData->id));
6675     TI_DBG4(("tdssAddSASToSharedContext: new case pid %d did %d phyID %d\n", onePortContext->id, oneDeviceData->id, oneDeviceData->phyID));
6676 
6677   }
6678   else /* old device */
6679   {
6680     TI_DBG3(("tdssAddSASToSharedcontext: old device\n"));
6681     TI_DBG3(("tdssAddSASToSharedcontext: oneDeviceData %p\n", oneDeviceData));
6682 
6683     oneDeviceData->DeviceType = TD_SAS_DEVICE;
6684     oneDeviceData->agRoot = agRoot;
6685 
6686     if (flag == TD_OPERATION_TARGET)
6687     {
6688       oneDeviceData->agDevHandle = agDevHandle;
6689       agDevHandle->osData = oneDeviceData; /* TD layer */
6690     }
6691 
6692     /* saving sas address */
6693     oneDeviceData->SASAddressID.sasAddressLo = agSASSubID->sasAddressLo;
6694     oneDeviceData->SASAddressID.sasAddressHi = agSASSubID->sasAddressHi;
6695     oneDeviceData->initiator_ssp_stp_smp = agSASSubID->initiator_ssp_stp_smp;
6696     oneDeviceData->target_ssp_stp_smp = agSASSubID->target_ssp_stp_smp;
6697 
6698 
6699     oneDeviceData->tdPortContext = onePortContext;
6700     oneDeviceData->valid = agTRUE;
6701 
6702     oneDeviceData->directlyAttached = agTRUE;
6703     /* new */
6704     if (oneDeviceData->registered == agFALSE)
6705     {
6706       TI_DBG1(("tdssAddSASToSharedcontext: registering\n"));
6707       /* parse sasIDframe to fill in agDeviceInfo */
6708       DEVINFO_PUT_SMPTO(&oneDeviceData->agDeviceInfo, DEFAULT_SMP_TIMEOUT);
6709       DEVINFO_PUT_ITNEXUSTO(&oneDeviceData->agDeviceInfo, (bit16)tdsaAllShared->itNexusTimeout);
6710       DEVINFO_PUT_FBS(&oneDeviceData->agDeviceInfo, 0);
6711       DEVINFO_PUT_FLAG(&oneDeviceData->agDeviceInfo, 1);
6712 
6713       sasorsata = SAS_DEVICE_TYPE; /* SAS target (SAS disk or expander) */
6714       connectionRate = onePortContext->LinkRate;
6715       dev_s_rate = (bit8)(dev_s_rate | (sasorsata << 4));
6716       dev_s_rate = (bit8)(dev_s_rate | connectionRate);
6717       DEVINFO_PUT_DEV_S_RATE(&oneDeviceData->agDeviceInfo, dev_s_rate);
6718 
6719 
6720       DEVINFO_PUT_SAS_ADDRESSLO(
6721                                 &oneDeviceData->agDeviceInfo,
6722                                 agSASSubID->sasAddressLo
6723                                 );
6724       DEVINFO_PUT_SAS_ADDRESSHI(
6725                                 &oneDeviceData->agDeviceInfo,
6726                                 agSASSubID->sasAddressHi
6727                                 );
6728 
6729       oneDeviceData->agContext.osData = oneDeviceData;
6730       oneDeviceData->agContext.sdkData = agNULL;
6731 
6732       if (flag == TD_OPERATION_INITIATOR)
6733       {
6734         if( tdsaAllShared->sflag )
6735         {
6736           if( ! DEVICE_IS_SMP_TARGET(oneDeviceData))
6737           {
6738             TI_DBG1(("tdssAddSASToSharedcontext: Second, saRegisterNewDevice sflag %d\n", tdsaAllShared->sflag));
6739             oneDeviceData->agDeviceInfo.flag = oneDeviceData->agDeviceInfo.flag | TD_XFER_RDY_PRIORTY_DEVICE_FLAG;
6740           }
6741         }
6742         saRegisterNewDevice( /* tdssAddSASToSharedcontext */
6743                             agRoot,
6744                             &oneDeviceData->agContext,
6745                             0,
6746                             &oneDeviceData->agDeviceInfo,
6747                             onePortContext->agPortContext,
6748                             0
6749                             );
6750       }
6751     }
6752 
6753 
6754 
6755 
6756 
6757 
6758     oneDeviceData->phyID = phyID;
6759     oneDeviceData->InQID = oneDeviceData->id % Indenom;
6760     oneDeviceData->OutQID = oneDeviceData->id % Outdenom;
6761 
6762     TI_DBG1(("tdssAddSASToSharedcontext: A OutQID %d\n", oneDeviceData->OutQID));
6763     TI_DBG4(("tdssAddSASToSharedcontext: SSP target %d STP target %d SATA device %d\n", DEVICE_IS_SSP_TARGET(oneDeviceData), DEVICE_IS_STP_TARGET(oneDeviceData), DEVICE_IS_SATA_DEVICE(oneDeviceData)));
6764     TI_DBG4(("tdssAddSASToSharedContext: old case pid %d did %d phyID %d\n", onePortContext->id, oneDeviceData->id, oneDeviceData->phyID));
6765   }
6766 
6767   return;
6768 }
6769 
6770 
6771 
6772 
6773 /*****************************************************************************
6774 *! \brief tdssRemoveDevicedataFromSharedcontext
6775 *
6776 *  Purpose:  This function removes a discovered device from a device list of
6777 *            a port context
6778 *
6779 *  \param   tsddPortContext_Ins      Pointer to the target port context
6780 *  \param   tdsaDeviceData_Ins       Pointer to the target device
6781 *  \param   agRoot                   Pointer to the root data structure of
6782 *                                    TD and Lower layer
6783 
6784 *
6785 *  \Return: none
6786 *
6787 *****************************************************************************/
6788 osGLOBAL void
6789 tdssRemoveSASFromSharedcontext(
6790                                tdsaPortContext_t *tdsaPortContext_Ins,
6791                                tdsaDeviceData_t  *tdsaDeviceData_Ins,
6792                                agsaRoot_t        *agRoot
6793                                )
6794 {
6795   tdsaRootOsData_t  *osData = (tdsaRootOsData_t *)agRoot->osData;
6796   tiRoot_t          *tiRoot = (tiRoot_t *)osData->tiRoot;
6797   tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
6798   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
6799   tdsaPortContext_t *onePortContext = agNULL;
6800   tdList_t          *PortContextList;
6801   tdsaDeviceData_t  *oneDeviceData = agNULL;
6802   tdList_t          *DeviceListList;
6803   bit32             found = agTRUE;
6804 
6805   TI_DBG3(("tdssRemoveSASFromSharedcontext: start\n"));
6806   /* find a right portcontext */
6807   PortContextList = tdsaAllShared->MainPortContextList.flink;
6808   while (PortContextList != &(tdsaAllShared->MainPortContextList))
6809   {
6810     onePortContext = TDLIST_OBJECT_BASE(tdsaPortContext_t, MainLink, PortContextList);
6811     if (onePortContext == agNULL)
6812     {
6813       TI_DBG1(("tdssRemoveDevicedataFromSharedcontext: onePortContext is NULL!!!\n"));
6814       return;
6815     }
6816     if (onePortContext == tdsaPortContext_Ins)
6817     {
6818       TI_DBG4(("tdssRemoveDevicedataFromSharedcontext: found; oneportContext ID %d\n", onePortContext->id));
6819       break;
6820     }
6821     PortContextList = PortContextList->flink;
6822   }
6823 
6824   /* find a device's existence */
6825   DeviceListList = tdsaAllShared->MainDeviceList.flink;
6826   while (DeviceListList != &(tdsaAllShared->MainDeviceList))
6827   {
6828     oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
6829     if (oneDeviceData == agNULL)
6830     {
6831       TI_DBG1(("tdssRemoveDevicedataFromSharedcontext: oneDeviceData is NULL!!!\n"));
6832       return;
6833     }
6834     if ((oneDeviceData->SASAddressID.sasAddressHi
6835          == SA_DEVINFO_GET_SAS_ADDRESSHI(&tdsaDeviceData_Ins->agDeviceInfo))
6836         &&
6837         (oneDeviceData->SASAddressID.sasAddressLo ==
6838          SA_DEVINFO_GET_SAS_ADDRESSLO(&tdsaDeviceData_Ins->agDeviceInfo)))
6839     {
6840       TI_DBG4(("tdssRemoveDevicedataFromSharedcontext: pid %d did %d\n", onePortContext->id, oneDeviceData->id));
6841       found = agFALSE;
6842       break;
6843     }
6844     DeviceListList = DeviceListList->flink;
6845   }
6846 
6847   if (found == agFALSE)
6848   {
6849     TI_DBG6(("tdssRemoveDevicedataFromSharedcontext: can't find the right devicedata in MainLink\n"));
6850     return;
6851   }
6852 
6853   /* remove it and put it back to FreeLink of Devicedata */
6854   TI_DBG6(("tdssRemoveDevicedataFromSharedcontext: removing ... pid %d did %d\n", onePortContext->id, oneDeviceData->id));
6855 
6856   /* invalidate the device but keep it on the list for persistency */
6857   oneDeviceData->valid = agFALSE;
6858 
6859   return;
6860 }
6861 
6862 /*****************************************************************************
6863 *! \brief tdssRemoveAllDevicedataFromPortcontext
6864 *
6865 *  Purpose:  This function removes all discovered devices from a device list of
6866 *            a port context
6867 *
6868 *  \param   tdsaDeviceData           Pointer to a device header
6869 *
6870 *  \Return: none
6871 *
6872 *****************************************************************************/
6873 osGLOBAL void
6874 tdssRemoveAllDevicelistFromPortcontext(
6875                                        tdsaPortContext_t *PortContext_Ins,
6876                                        agsaRoot_t        *agRoot
6877                                        )
6878 {
6879 
6880   tdsaRootOsData_t  *osData = (tdsaRootOsData_t *)agRoot->osData;
6881   tiRoot_t          *tiRoot = (tiRoot_t *)osData->tiRoot;
6882   tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
6883   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
6884   tdsaDeviceData_t  *oneDeviceData = agNULL;
6885   tdList_t          *DeviceListList;
6886 
6887   TI_DBG6(("tdssRemoveAllDevicedataFromPortcontext: start\n"));
6888 
6889   /*
6890     loop through device list and find the matching portcontext. Then invalidate the
6891     matching devices
6892   */
6893   DeviceListList = tdsaAllShared->MainDeviceList.flink;
6894   while (DeviceListList != &(tdsaAllShared->MainDeviceList))
6895   {
6896     oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
6897     if (oneDeviceData == agNULL)
6898     {
6899       TI_DBG1(("tdssRemoveAllDevicelistFromPortcontext: oneDeviceData is NULL!!!\n"));
6900       return;
6901     }
6902     if (oneDeviceData->tdPortContext == PortContext_Ins)
6903     {
6904       TI_DBG4(("tdssRemoveAllDevicelistFromPortcontext: pid %d did %d\n", PortContext_Ins->id, oneDeviceData->id));
6905       PortContext_Ins->Count--;
6906       oneDeviceData->valid = agFALSE;
6907     }
6908     DeviceListList = DeviceListList->flink;
6909   }
6910 
6911   return;
6912 }
6913 
6914 
6915 #ifdef INITIATOR_DRIVER
6916 #ifdef TD_DISCOVER
6917 /*****************************************************************************
6918 *! \brief tdssNewAddSASToSharedcontext
6919 *
6920 *  Purpose:  This function adds a discovered SAS device to a device list of
6921 *            a shared context. Used only in discovery.
6922 *
6923 *  \param   agRoot          Pointer to chip/driver Instance.
6924 *  \param   onePortContext  Pointer to the target port context
6925 *  \param   agSASSubID      Pointer to the SAS identification.
6926 *
6927 *  \Return:
6928 *           Pointer to the device data
6929 *
6930 *****************************************************************************/
6931 osGLOBAL tdsaDeviceData_t *
6932 tdssNewAddSASToSharedcontext(
6933                              agsaRoot_t           *agRoot,
6934                              tdsaPortContext_t    *onePortContext,
6935                              tdsaSASSubID_t       *agSASSubID,
6936                              tdsaDeviceData_t     *oneExpDeviceData,
6937                              bit8                 phyID
6938                              )
6939 {
6940   tdsaDeviceData_t  *oneDeviceData = agNULL;
6941   tdList_t          *DeviceListList;
6942   tdsaRootOsData_t  *osData = (tdsaRootOsData_t *)agRoot->osData;
6943   tiRoot_t          *tiRoot = (tiRoot_t *)osData->tiRoot;
6944   tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
6945   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
6946   bit32             new_device = agTRUE;
6947 
6948   TI_DBG3(("tdssNewAddSASToSharedcontext: start\n"));
6949   /*
6950     find a right portcontext
6951     then, get devicedata from FreeLink in DeviceList
6952     then, do pointer operations
6953     then, add the devicedata to the portcontext
6954   */
6955 
6956 
6957   TI_DBG3(("tdssNewAddSASToSharedcontext: oneportContext ID %d\n", onePortContext->id));
6958   /* find a device's existence */
6959   DeviceListList = tdsaAllShared->MainDeviceList.flink;
6960   while (DeviceListList != &(tdsaAllShared->MainDeviceList))
6961   {
6962     oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
6963     if (oneDeviceData == agNULL)
6964     {
6965       TI_DBG1(("tdssNewAddSASToSharedcontext: oneDeviceData is NULL!!!\n"));
6966       return agNULL;
6967     }
6968     if ((oneDeviceData->SASAddressID.sasAddressHi == agSASSubID->sasAddressHi) &&
6969         (oneDeviceData->SASAddressID.sasAddressLo == agSASSubID->sasAddressLo) &&
6970         (oneDeviceData->tdPortContext == onePortContext)
6971         )
6972     {
6973       TI_DBG3(("tdssNewAddSASToSharedcontext: pid %d did %d\n", onePortContext->id, oneDeviceData->id));
6974       new_device = agFALSE;
6975       break;
6976     }
6977     DeviceListList = DeviceListList->flink;
6978   }
6979 
6980   /* new device */
6981   if (new_device == agTRUE)
6982   {
6983     TI_DBG3(("tdssNewAddSASToSharedcontext: new device\n"));
6984     tdsaSingleThreadedEnter(tiRoot, TD_DEVICE_LOCK);
6985     if (!TDLIST_NOT_EMPTY(&(tdsaAllShared->FreeDeviceList)))
6986     {
6987       tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
6988       TI_DBG1(("tdssNewAddSASToSharedcontext: empty DeviceData FreeLink\n"));
6989       return agNULL;
6990     }
6991 
6992     TDLIST_DEQUEUE_FROM_HEAD(&DeviceListList, &(tdsaAllShared->FreeDeviceList));
6993     tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
6994     oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, FreeLink, DeviceListList);
6995 
6996     TI_DBG3(("tdssNewAddSASToSharedcontext: oneDeviceData %p did %d\n", oneDeviceData, oneDeviceData->id));
6997 
6998     onePortContext->Count++;
6999     oneDeviceData->agRoot = agRoot;
7000     /* saving sas address */
7001     oneDeviceData->SASAddressID.sasAddressLo = agSASSubID->sasAddressLo;
7002     oneDeviceData->SASAddressID.sasAddressHi = agSASSubID->sasAddressHi;
7003     oneDeviceData->initiator_ssp_stp_smp = agSASSubID->initiator_ssp_stp_smp;
7004     oneDeviceData->target_ssp_stp_smp = agSASSubID->target_ssp_stp_smp;
7005     oneDeviceData->tdPortContext = onePortContext;
7006     /* handles both SAS target and STP-target, SATA-device */
7007     if (!DEVICE_IS_SATA_DEVICE(oneDeviceData) && !DEVICE_IS_STP_TARGET(oneDeviceData))
7008     {
7009       oneDeviceData->DeviceType = TD_SAS_DEVICE;
7010     }
7011     else
7012     {
7013       oneDeviceData->DeviceType = TD_SATA_DEVICE;
7014     }
7015 
7016     oneDeviceData->ExpDevice = oneExpDeviceData;
7017     /* set phyID only when it has initial value of 0xFF */
7018     if (oneDeviceData->phyID == 0xFF)
7019     {
7020       oneDeviceData->phyID = phyID;
7021     }
7022 #ifdef FDS_DM
7023     oneDeviceData->valid = agTRUE;
7024 #else
7025 
7026     /* incremental discovery */
7027     /* add device to incremental-related link. Report using this link
7028        when incremental discovery is done */
7029     if (onePortContext->discovery.type == TDSA_DISCOVERY_OPTION_INCREMENTAL_START)
7030     {
7031       TI_DBG3(("tdssNewAddSASToSharedcontext: incremental discovery\n"));
7032       TI_DBG3(("tdssNewAddSASToSharedcontext: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
7033       TI_DBG3(("tdssNewAddSASToSharedcontext: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
7034       oneDeviceData->valid2 = agTRUE;
7035     }
7036     else
7037     {
7038       TI_DBG3(("tdssNewAddSASToSharedcontext: full discovery\n"));
7039       TI_DBG3(("tdssNewAddSASToSharedcontext: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
7040       TI_DBG3(("tdssNewAddSASToSharedcontext: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
7041       oneDeviceData->valid = agTRUE;
7042     }
7043 #endif
7044     /* add the devicedata to the portcontext */
7045     tdsaSingleThreadedEnter(tiRoot, TD_DEVICE_LOCK);
7046     TDLIST_ENQUEUE_AT_TAIL(&(oneDeviceData->MainLink), &(tdsaAllShared->MainDeviceList));
7047     tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
7048     TI_DBG4(("tdssNewAddSASToSharedcontext: one case pid %d did %d \n", onePortContext->id, oneDeviceData->id));
7049     TI_DBG4(("tdssNewAddSASToSharedcontext: new case pid %d did %d phyID %d\n", onePortContext->id, oneDeviceData->id, oneDeviceData->phyID));
7050   }
7051   else /* old device */
7052   {
7053     TI_DBG3(("tdssNewAddSASToSharedcontext: old device\n"));
7054     TI_DBG3(("tdssNewAddSASToSharedcontext: oneDeviceData %p did %d\n", oneDeviceData, oneDeviceData->id));
7055 
7056     oneDeviceData->agRoot = agRoot;
7057     /* saving sas address */
7058     oneDeviceData->SASAddressID.sasAddressLo = agSASSubID->sasAddressLo;
7059     oneDeviceData->SASAddressID.sasAddressHi = agSASSubID->sasAddressHi;
7060     oneDeviceData->initiator_ssp_stp_smp = agSASSubID->initiator_ssp_stp_smp;
7061     oneDeviceData->target_ssp_stp_smp = agSASSubID->target_ssp_stp_smp;
7062     oneDeviceData->tdPortContext = onePortContext;
7063     /* handles both SAS target and STP-target, SATA-device */
7064     if (!DEVICE_IS_SATA_DEVICE(oneDeviceData) && !DEVICE_IS_STP_TARGET(oneDeviceData))
7065     {
7066       oneDeviceData->DeviceType = TD_SAS_DEVICE;
7067     }
7068     else
7069     {
7070       oneDeviceData->DeviceType = TD_SATA_DEVICE;
7071     }
7072 
7073     oneDeviceData->ExpDevice = oneExpDeviceData;
7074     /* set phyID only when it has initial value of 0xFF */
7075     if (oneDeviceData->phyID == 0xFF)
7076     {
7077       oneDeviceData->phyID = phyID;
7078     }
7079 
7080 #ifdef FDS_DM
7081     oneDeviceData->valid = agTRUE;
7082 #else
7083     if (onePortContext->discovery.type == TDSA_DISCOVERY_OPTION_INCREMENTAL_START)
7084     {
7085       TI_DBG3(("tdssNewAddSASToSharedcontext: incremental discovery\n"));
7086       TI_DBG3(("tdssNewAddSASToSharedcontext: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
7087       TI_DBG3(("tdssNewAddSASToSharedcontext: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
7088       oneDeviceData->valid2 = agTRUE;
7089     }
7090     else
7091     {
7092       TI_DBG3(("tdssNewAddSASToSharedcontext: full discovery\n"));
7093       TI_DBG3(("tdssNewAddSASToSharedcontext: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
7094       TI_DBG3(("tdssNewAddSASToSharedcontext: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
7095       oneDeviceData->valid = agTRUE;
7096     }
7097 #endif
7098     TI_DBG4(("tdssNewAddSASToSharedcontext: old case pid %d did %d phyID %d\n", onePortContext->id, oneDeviceData->id, oneDeviceData->phyID));
7099 
7100   }
7101   return oneDeviceData;
7102 }
7103 
7104 /*****************************************************************************
7105 *! \brief tdsaFindRegNValid
7106 *
7107 *  Purpose:  This function finds a device which is registered and valid in
7108 *            the device list. Used only in incremental discovery.
7109 *
7110 *  \param   agRoot          Pointer to chip/driver Instance.
7111 *  \param   onePortContext  Pointer to the target port context
7112 *  \param   tdsaDeviceData  Pointer to a device list header
7113 *  \param   agSASSubID      Pointer to the SAS identification.
7114 *
7115 *  \Return:
7116 *           Pointer to the device data
7117 *
7118 *****************************************************************************/
7119 osGLOBAL tdsaDeviceData_t *
7120 tdsaFindRegNValid(
7121                   agsaRoot_t           *agRoot,
7122                   tdsaPortContext_t    *onePortContext,
7123                   tdsaSASSubID_t       *agSASSubID
7124                   )
7125 {
7126   tdsaRootOsData_t  *osData = (tdsaRootOsData_t *)agRoot->osData;
7127   tiRoot_t          *tiRoot = (tiRoot_t *)osData->tiRoot;
7128   tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
7129   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
7130   tdsaDeviceData_t  *oneDeviceData = agNULL;
7131   tdList_t          *DeviceListList;
7132   bit32             found = agFALSE;
7133 
7134   TI_DBG3(("tdsaFindRegNValid: start\n"));
7135 
7136   /* find a device's existence */
7137   DeviceListList = tdsaAllShared->MainDeviceList.flink;
7138   if (onePortContext->discovery.type == TDSA_DISCOVERY_OPTION_FULL_START)
7139   {
7140     TI_DBG3(("tdsaFindRegNValid: Full discovery\n"));
7141     while (DeviceListList != &(tdsaAllShared->MainDeviceList))
7142     {
7143       oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
7144       if (oneDeviceData == agNULL)
7145       {
7146         TI_DBG1(("tdsaFindRegNValid: oneDeviceData is NULL!!!\n"));
7147         return agNULL;
7148       }
7149       if ((oneDeviceData->SASAddressID.sasAddressHi == agSASSubID->sasAddressHi) &&
7150           (oneDeviceData->SASAddressID.sasAddressLo == agSASSubID->sasAddressLo) &&
7151           (oneDeviceData->registered == agTRUE) &&
7152           (oneDeviceData->valid == agTRUE) &&
7153           (oneDeviceData->tdPortContext == onePortContext)
7154           )
7155       {
7156         TI_DBG3(("tdsaFindRegNValid: Found pid %d did %d\n", onePortContext->id, oneDeviceData->id));
7157         TI_DBG3(("tdsaFindRegNValid: sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
7158         TI_DBG3(("tdsaFindRegNValid: sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
7159         found = agTRUE;
7160         break;
7161       }
7162       DeviceListList = DeviceListList->flink;
7163     }
7164   }
7165   else
7166   {
7167     /* incremental discovery */
7168     TI_DBG3(("tdsaFindRegNValid: Incremental discovery\n"));
7169     while (DeviceListList != &(tdsaAllShared->MainDeviceList))
7170     {
7171       oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
7172       if (oneDeviceData == agNULL)
7173       {
7174         TI_DBG1(("tdsaFindRegNValid: oneDeviceData is NULL!!!\n"));
7175         return agNULL;
7176       }
7177       if ((oneDeviceData->SASAddressID.sasAddressHi == agSASSubID->sasAddressHi) &&
7178           (oneDeviceData->SASAddressID.sasAddressLo == agSASSubID->sasAddressLo) &&
7179           (oneDeviceData->registered == agTRUE) &&
7180           (oneDeviceData->valid2 == agTRUE) &&
7181           (oneDeviceData->tdPortContext == onePortContext)
7182           )
7183       {
7184         TI_DBG3(("tdsaFindRegNValid: Found pid %d did %d\n", onePortContext->id, oneDeviceData->id));
7185         TI_DBG3(("tdsaFindRegNValid: sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
7186         TI_DBG3(("tdsaFindRegNValid: sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
7187         found = agTRUE;
7188         break;
7189       }
7190       DeviceListList = DeviceListList->flink;
7191     }
7192   }
7193 
7194 
7195 
7196   if (found == agFALSE)
7197   {
7198     TI_DBG3(("tdsaFindRegNValid: end returning NULL\n"));
7199     return agNULL;
7200   }
7201   else
7202   {
7203     TI_DBG3(("tdsaFindRegNValid: end returning NOT NULL\n"));
7204     return oneDeviceData;
7205   }
7206 
7207 }
7208 
7209 //registered to LL or not
7210 /*****************************************************************************
7211 *! \brief tdssNewSASorNot
7212 *
7213 *  Purpose:  This function finds whether a device is registered or not
7214 *
7215 *  \param   agRoot          Pointer to chip/driver Instance.
7216 *  \param   onePortContext  Pointer to the target port context
7217 *  \param   agSASSubID      Pointer to the SAS identification.
7218 *
7219 *  \Return:
7220 *           agTRUE   Device is not registered (New device).
7221 *           agFALSE  Device is registered (Old device).
7222 *
7223 *****************************************************************************/
7224 bit32
7225 tdssNewSASorNot(
7226                                  agsaRoot_t           *agRoot,
7227                                  tdsaPortContext_t    *onePortContext,
7228                                  tdsaSASSubID_t       *agSASSubID
7229                                  )
7230 {
7231   tdsaRootOsData_t  *osData = (tdsaRootOsData_t *)agRoot->osData;
7232   tiRoot_t          *tiRoot = (tiRoot_t *)osData->tiRoot;
7233   tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
7234   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
7235   tdsaDeviceData_t  *oneDeviceData = agNULL;
7236   tdList_t          *DeviceListList;
7237   bit32             ret = agTRUE;
7238 
7239   TI_DBG3(("tdssNewSASorNot: start\n"));
7240 
7241   /* find a device's existence */
7242   DeviceListList = tdsaAllShared->MainDeviceList.flink;
7243   while (DeviceListList != &(tdsaAllShared->MainDeviceList))
7244   {
7245     oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
7246     if ((oneDeviceData->SASAddressID.sasAddressHi == agSASSubID->sasAddressHi) &&
7247         (oneDeviceData->SASAddressID.sasAddressLo == agSASSubID->sasAddressLo) &&
7248         (oneDeviceData->registered == agTRUE) &&
7249         (oneDeviceData->tdPortContext == onePortContext)
7250         )
7251     {
7252       TI_DBG3(("tdssNewSASorNot: Found pid %d did %d\n", onePortContext->id, oneDeviceData->id));
7253       ret = agFALSE;
7254       break;
7255     }
7256     DeviceListList = DeviceListList->flink;
7257   }
7258 
7259 
7260 
7261   TI_DBG3(("tdssNewSASorNot: end\n"));
7262 
7263   return ret;
7264 }
7265 
7266 
7267 
7268 /*****************************************************************************
7269 *! \brief  tdssSASDiscoveringExpanderAlloc
7270 *
7271 *  Purpose:  This function allocates an expander from the pre-allocated memory
7272 *            pool.
7273 *
7274 *  \param   tiRoot: Pointer to the OS Specific module allocated tiRoot_t
7275 *                   instance.
7276 *  \param   onePortContext: Pointer to the portal context instance.
7277 *  \param   oneDeviceData:  Pointer to the device data.
7278 *
7279 *  \return:
7280 *           Pointer to expander on success
7281 *           agNULL              on failure
7282 *
7283 *   \note:
7284 *
7285 *****************************************************************************/
7286 osGLOBAL tdsaExpander_t *
7287 tdssSASDiscoveringExpanderAlloc(
7288                                 tiRoot_t                 *tiRoot,
7289                                 tdsaPortContext_t        *onePortContext,
7290                                 tdsaDeviceData_t         *oneDeviceData
7291                                 )
7292 {
7293   tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
7294   tdsaContext_t     *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
7295   tdsaExpander_t    *oneExpander = agNULL;
7296   tdList_t          *ExpanderList;
7297 
7298   /*
7299     move the expander from freeExpanderList
7300     and ground the expander by TDLIST_DEQUEUE_THIS
7301   */
7302 
7303 
7304   TI_DBG3(("tdssSASDiscoveringExpanderAlloc: start\n"));
7305   TI_DBG3(("tdssSASDiscoveringExpanderAlloc: did %d\n", oneDeviceData->id));
7306   TI_DBG3(("tdssSASDiscoveringExpanderAlloc: sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
7307   TI_DBG3(("tdssSASDiscoveringExpanderAlloc: sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
7308 
7309   if (onePortContext->valid == agFALSE)
7310   {
7311     TI_DBG1(("tdssSASDiscoveringExpanderAlloc: aborting discovery\n"));
7312     tdsaSASDiscoverAbort(tiRoot, onePortContext);
7313     return agNULL;
7314   }
7315 
7316   tdsaDumpAllFreeExp(tiRoot);
7317 
7318   if (TDLIST_EMPTY(&(tdsaAllShared->freeExpanderList)))
7319   {
7320     TI_DBG1(("tdssSASDiscoveringExpanderAlloc: no free expanders\n"));
7321     return agNULL;
7322   }
7323 
7324   tdsaSingleThreadedEnter(tiRoot, TD_DISC_LOCK);
7325   TDLIST_DEQUEUE_FROM_HEAD(&ExpanderList, &(tdsaAllShared->freeExpanderList));
7326   tdsaSingleThreadedLeave(tiRoot, TD_DISC_LOCK);
7327   //  oneExpander = TDLIST_OBJECT_BASE(tdsaContext_t, freeExpanderList, ExpanderList);
7328   oneExpander = TDLIST_OBJECT_BASE(tdsaExpander_t, linkNode, ExpanderList);
7329 
7330   if (oneExpander != agNULL)
7331   {
7332     TI_DBG3(("tdssSASDiscoveringExpanderAlloc: expander id %d\n", oneExpander->id));
7333 
7334     tdsaSingleThreadedEnter(tiRoot, TD_DISC_LOCK);
7335     TDLIST_DEQUEUE_THIS(&(oneExpander->linkNode));
7336     tdsaSingleThreadedLeave(tiRoot, TD_DISC_LOCK);
7337 
7338     oneExpander->tdDevice = oneDeviceData;
7339     oneExpander->tdUpStreamExpander = agNULL;
7340     oneExpander->tdCurrentDownStreamExpander = agNULL;
7341     oneExpander->tdReturnginExpander = agNULL;
7342     oneExpander->hasUpStreamDevice = agFALSE;
7343     oneExpander->numOfUpStreamPhys = 0;
7344     oneExpander->currentUpStreamPhyIndex = 0;
7345     oneExpander->discoveringPhyId = 0;
7346     oneExpander->underDiscovering = agFALSE;
7347     osti_memset( &(oneExpander->currentIndex), 0, sizeof(oneExpander->currentIndex));
7348 
7349     oneDeviceData->tdExpander = oneExpander;
7350   }
7351 
7352   return oneExpander;
7353 }
7354 
7355 /*****************************************************************************
7356 *! \brief  tdssSASDiscoveringExpanderAdd
7357 *
7358 *  Purpose:  This function adds an expander to the expander list.
7359 *
7360 *  \param   tiRoot: Pointer to the OS Specific module allocated tiRoot_t
7361 *                   instance.
7362 *  \param   onePortContext: Pointer to the portal context instance.
7363 *  \param   oneExpander: Pointer to the expander data.
7364 *
7365 *  \return:
7366 *           None
7367 *
7368 *   \note:
7369 *
7370 *****************************************************************************/
7371 osGLOBAL void
7372 tdssSASDiscoveringExpanderAdd(
7373                               tiRoot_t                 *tiRoot,
7374                               tdsaPortContext_t        *onePortContext,
7375                               tdsaExpander_t           *oneExpander
7376                               )
7377 {
7378 #ifdef TD_INTERNAL_DEBUG
7379   tdList_t          *ExpanderList;
7380   tdsaExpander_t    *tempExpander;
7381 #endif
7382 
7383   /* move the expander to discoveringExpanderList */
7384 
7385   TI_DBG3(("tdssSASDiscoveringExpanderAdd: start\n"));
7386   TI_DBG3(("tdssSASDiscoveringExpanderAdd: expander id %d\n", oneExpander->id));
7387   TI_DBG3(("tdssSASDiscoveringExpanderAdd: exp addrHi 0x%08x\n", oneExpander->tdDevice->SASAddressID.sasAddressHi));
7388   TI_DBG3(("tdssSASDiscoveringExpanderAdd: exp addrLo 0x%08x\n", oneExpander->tdDevice->SASAddressID.sasAddressLo));
7389 
7390   if (onePortContext->valid == agFALSE)
7391   {
7392     TI_DBG1(("tdssSASDiscoveringExpanderAdd: aborting discovery\n"));
7393     tdsaSASDiscoverAbort(tiRoot, onePortContext);
7394     return;
7395   }
7396 
7397 
7398   if (onePortContext->discovery.status == DISCOVERY_UP_STREAM)
7399   {
7400     TI_DBG3(("tdssSASDiscoveringExpanderAdd: UPSTREAM\n"));
7401   }
7402   else if (onePortContext->discovery.status == DISCOVERY_DOWN_STREAM)
7403   {
7404     TI_DBG3(("tdssSASDiscoveringExpanderAdd: DOWNSTREAM\n"));
7405   }
7406   else
7407   {
7408     TI_DBG3(("tdssSASDiscoveringExpanderAdd: status %d\n", onePortContext->discovery.status));
7409   }
7410 
7411   TI_DBG3(("tdssSASDiscoveringExpanderAdd: BEFORE\n"));
7412   tdsaDumpAllExp(tiRoot, onePortContext, oneExpander);
7413 
7414 
7415   if ( oneExpander->underDiscovering == agFALSE)
7416   {
7417     TI_DBG3(("tdssSASDiscoveringExpanderAdd: ADDED \n"));
7418 
7419     oneExpander->underDiscovering = agTRUE;
7420     tdsaSingleThreadedEnter(tiRoot, TD_DISC_LOCK);
7421     TDLIST_ENQUEUE_AT_TAIL(&(oneExpander->linkNode), &(onePortContext->discovery.discoveringExpanderList));
7422     tdsaSingleThreadedLeave(tiRoot, TD_DISC_LOCK);
7423   }
7424 
7425   TI_DBG3(("tdssSASDiscoveringExpanderAdd: AFTER\n"));
7426   tdsaDumpAllExp(tiRoot, onePortContext, oneExpander);
7427 
7428 #ifdef TD_INTERNAL_DEBUG
7429   /* debugging */
7430   if (TDLIST_EMPTY(&(onePortContext->discovery.discoveringExpanderList)))
7431   {
7432     TI_DBG3(("tdssSASDiscoveringExpanderAdd: empty discoveringExpanderList\n"));
7433     return;
7434   }
7435   ExpanderList = onePortContext->discovery.discoveringExpanderList.flink;
7436   while (ExpanderList != &(onePortContext->discovery.discoveringExpanderList))
7437   {
7438     tempExpander = TDLIST_OBJECT_BASE(tdsaExpander_t, linkNode, ExpanderList);
7439     TI_DBG3(("tdssSASDiscoveringExpanderAdd: expander id %d\n", tempExpander->id));
7440     ExpanderList = ExpanderList->flink;
7441   }
7442 #endif
7443 
7444   return;
7445 }
7446 
7447 /* temp */
7448 osGLOBAL bit32
7449 tdssSASFindDiscoveringExpander(
7450                tiRoot_t                 *tiRoot,
7451                tdsaPortContext_t        *onePortContext,
7452                tdsaExpander_t           *oneExpander
7453               )
7454 {
7455   tdList_t          *ExpanderList;
7456   tdsaExpander_t    *tempExpander;
7457   tdsaPortContext_t *tmpOnePortContext = onePortContext;
7458   bit32             ret = agFALSE;
7459 
7460   TI_DBG3(("tdssSASFindDiscoveringExpander: exp addrHi 0x%08x\n", oneExpander->tdDevice->SASAddressID.sasAddressHi));
7461   TI_DBG3(("tdssSASFindDiscoveringExpander: exp addrLo 0x%08x\n", oneExpander->tdDevice->SASAddressID.sasAddressLo));
7462 
7463   if (TDLIST_EMPTY(&(tmpOnePortContext->discovery.discoveringExpanderList)))
7464   {
7465     TI_DBG1(("tdssSASFindDiscoveringExpander: empty discoveringExpanderList\n"));
7466     return ret;
7467   }
7468   ExpanderList = tmpOnePortContext->discovery.discoveringExpanderList.flink;
7469   while (ExpanderList != &(tmpOnePortContext->discovery.discoveringExpanderList))
7470   {
7471     tempExpander = TDLIST_OBJECT_BASE(tdsaExpander_t, linkNode, ExpanderList);
7472     if (tempExpander == oneExpander)
7473     {
7474       TI_DBG3(("tdssSASFindDiscoveringExpander: match!!! expander id %d\n", tempExpander->id));
7475       TI_DBG3(("tdssSASFindDiscoveringExpander: exp addrHi 0x%08x\n", tempExpander->tdDevice->SASAddressID.sasAddressHi));
7476       TI_DBG3(("tdssSASFindDiscoveringExpander: exp addrLo 0x%08x\n", tempExpander->tdDevice->SASAddressID.sasAddressLo));
7477       ret = agTRUE;
7478       break;
7479     }
7480 
7481     ExpanderList = ExpanderList->flink;
7482   }
7483 
7484 
7485   return ret;
7486 
7487 }
7488 /* to be tested */
7489 /* move the expander to freeExpanderList */
7490 /*****************************************************************************
7491 *! \brief  tdssSASDiscoveringExpanderRemove
7492 *
7493 *  Purpose:  This function removes an expander from the expander list.
7494 *
7495 *  \param   tiRoot: Pointer to the OS Specific module allocated tiRoot_t
7496 *                   instance.
7497 *  \param   onePortContext: Pointer to the portal context instance.
7498 *  \param   oneExpander: Pointer to the expander data.
7499 *
7500 *  \return:
7501 *           None
7502 *
7503 *   \note:
7504 *
7505 *****************************************************************************/
7506 osGLOBAL void
7507 tdssSASDiscoveringExpanderRemove(
7508                                  tiRoot_t                 *tiRoot,
7509                                  tdsaPortContext_t        *onePortContext,
7510                                  tdsaExpander_t           *oneExpander
7511                                  )
7512 {
7513   tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
7514   tdsaContext_t     *tdsaAllShared   = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
7515 #ifdef TD_INTERNAL_DEBUG
7516   tdList_t          *ExpanderList;
7517   tdsaExpander_t    *tempExpander;
7518 #endif
7519 
7520   TI_DBG3(("tdssSASDiscoveringExpanderRemove: start\n"));
7521   TI_DBG3(("tdssSASDiscoveringExpanderRemove: expander id %d\n", oneExpander->id));
7522   TI_DBG3(("tdssSASDiscoveringExpanderRemove: exp addrHi 0x%08x\n", oneExpander->tdDevice->SASAddressID.sasAddressHi));
7523   TI_DBG3(("tdssSASDiscoveringExpanderRemove: exp addrLo 0x%08x\n", oneExpander->tdDevice->SASAddressID.sasAddressLo));
7524 
7525 
7526   TI_DBG3(("tdssSASDiscoveringExpanderRemove: BEFORE\n"));
7527   tdsaDumpAllExp(tiRoot, onePortContext, oneExpander);
7528   tdsaDumpAllUpExp(tiRoot, onePortContext, oneExpander);
7529   tdsaDumpAllFreeExp(tiRoot);
7530 
7531 #ifdef TD_INTERNAL_DEBUG
7532   /* debugging */
7533   TI_DBG3(("tdssSASDiscoveringExpanderRemove: BEFORE\n"));
7534   if (TDLIST_EMPTY(&(onePortContext->discovery.discoveringExpanderList)))
7535   {
7536     TI_DBG3(("tdssSASDiscoveringExpanderRemove: empty discoveringExpanderList\n"));
7537   }
7538   ExpanderList = onePortContext->discovery.discoveringExpanderList.flink;
7539   while (ExpanderList != &(onePortContext->discovery.discoveringExpanderList))
7540   {
7541     tempExpander = TDLIST_OBJECT_BASE(tdsaExpander_t, linkNode, ExpanderList);
7542     TI_DBG3(("tdssSASDiscoveringExpanderRemove: expander id %d\n", tempExpander->id));
7543     ExpanderList = ExpanderList->flink;
7544   }
7545 #endif
7546 
7547   // if is temporary till smp problem is fixed
7548   if (tdssSASFindDiscoveringExpander(tiRoot, onePortContext, oneExpander) == agTRUE)
7549   {
7550     oneExpander->underDiscovering = agFALSE;
7551     oneExpander->discoveringPhyId = 0;
7552     tdsaSingleThreadedEnter(tiRoot, TD_DISC_LOCK);
7553     TDLIST_DEQUEUE_THIS(&(oneExpander->linkNode));
7554 
7555     if (onePortContext->discovery.status == DISCOVERY_UP_STREAM)
7556     {
7557       TI_DBG3(("tdssSASDiscoveringExpanderRemove: DISCOVERY_UP_STREAM\n"));
7558       TDLIST_ENQUEUE_AT_TAIL(&(oneExpander->upNode), &(onePortContext->discovery.UpdiscoveringExpanderList));
7559       onePortContext->discovery.NumOfUpExp++;
7560     }
7561     else
7562     {
7563       TI_DBG3(("tdssSASDiscoveringExpanderRemove: Status %d\n", onePortContext->discovery.status));
7564       TDLIST_ENQUEUE_AT_TAIL(&(oneExpander->linkNode), &(tdsaAllShared->freeExpanderList));
7565     }
7566 
7567     tdsaSingleThreadedLeave(tiRoot, TD_DISC_LOCK);
7568   } //end temp if
7569   else
7570   {
7571     TI_DBG1(("tdssSASDiscoveringExpanderRemove: !!! problem !!!\n"));
7572   }
7573 
7574   TI_DBG3(("tdssSASDiscoveringExpanderRemove: AFTER\n"));
7575   tdsaDumpAllExp(tiRoot, onePortContext, oneExpander);
7576   tdsaDumpAllUpExp(tiRoot, onePortContext, oneExpander);
7577 
7578   tdsaDumpAllFreeExp(tiRoot);
7579 
7580 #ifdef TD_INTERNAL_DEBUG
7581   /* debugging */
7582   TI_DBG3(("tdssSASDiscoveringExpanderRemove: AFTER\n"));
7583   if (TDLIST_EMPTY(&(onePortContext->discovery.discoveringExpanderList)))
7584   {
7585     TI_DBG3(("tdssSASDiscoveringExpanderRemove: empty discoveringExpanderList\n"));
7586   }
7587   ExpanderList = onePortContext->discovery.discoveringExpanderList.flink;
7588   while (ExpanderList != &(onePortContext->discovery.discoveringExpanderList))
7589   {
7590     tempExpander = TDLIST_OBJECT_BASE(tdsaExpander_t, linkNode, ExpanderList);
7591     TI_DBG3(("tdssSASDiscoveringExpanderRemove: expander id %d\n", tempExpander->id));
7592     ExpanderList = ExpanderList->flink;
7593   }
7594 #endif
7595 
7596   return;
7597 }
7598 
7599 #ifdef SATA_ENABLE
7600 
7601 /*****************************************************************************
7602 *! \brief tdssNewAddSATAToSharedcontext
7603 *
7604 *  Purpose:  This function adds a discovered SATA device to a device list of
7605 *            a shared context. Used only in discovery.
7606 *
7607 *  \param   tiRoot  Pointer to the OS Specific module allocated tiRoot_t
7608 *                   instance.
7609 *  \param   agRoot          Pointer to chip/driver Instance.
7610 *  \param   onePortContext  Pointer to the target port context
7611 *  \param   tdsaDeviceData  Pointer to a device list header
7612 *  \param   agSATADeviceInfo      Pointer to the SATA device information.
7613 *  \param   Signature       Pointer to SATA signature
7614 *  \param   pm              Port multiplier
7615 *  \param   pmField         Port multiplier field
7616 *  \param   connectionRate  Connection rate
7617 *
7618 *  \Return:
7619 *           Pointer to the device data
7620 *
7621 *****************************************************************************/
7622 osGLOBAL tdsaDeviceData_t *
7623 tdssNewAddSATAToSharedcontext(tiRoot_t             *tiRoot,
7624                               agsaRoot_t           *agRoot,
7625                               tdsaPortContext_t    *onePortContext,
7626                               agsaSATADeviceInfo_t *agSATADeviceInfo,
7627                               bit8                    *Signature,
7628                               bit8                    pm,
7629                               bit8                    pmField,
7630                               bit32                   connectionRate,
7631                               tdsaDeviceData_t        *oneExpDeviceData,
7632                               bit8                    phyID
7633                               )
7634 {
7635   tdsaDeviceData_t  *oneDeviceData = agNULL;
7636   tdList_t          *DeviceListList;
7637   tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
7638   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
7639   int               new_device = agTRUE;
7640 
7641   TI_DBG5(("tdssNewAddSATAToSharedcontext: start\n"));
7642 
7643 
7644 
7645   TI_DBG5(("tdssNewAddSATAToSharedcontext: oneportContext ID %d\n", onePortContext->id));
7646 
7647 
7648 #ifdef RPM_SOC
7649   /* Find a device's existence */
7650   DeviceListList = tdsaAllShared->MainDeviceList.flink;
7651   while (DeviceListList != &(tdsaAllShared->MainDeviceList))
7652   {
7653     oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
7654 
7655     if ((osti_memcmp (((char *)&oneDeviceData->satDevData.satIdentifyData),
7656                       ((char *)&agSATADeviceInfo->sataIdentifyData),
7657                       sizeof(agsaSATAIdentifyData_t)) == 0))
7658     {
7659       TI_DBG5(("tdssNewAddSATAToSharedcontext: pid %d did %d\n",
7660         onePortContext->id, oneDeviceData->id));
7661       new_device = agFALSE;
7662       break;
7663     }
7664     DeviceListList = DeviceListList->flink;
7665   }
7666 #else
7667 
7668 
7669 #endif
7670 
7671   /* New device */
7672   if (new_device == agTRUE)
7673   {
7674     TI_DBG5(("tdssNewAddSATAToSharedcontext: new device\n"));
7675 
7676     tdsaSingleThreadedEnter(tiRoot, TD_DEVICE_LOCK);
7677     if (!TDLIST_NOT_EMPTY(&(tdsaAllShared->FreeDeviceList)))
7678     {
7679       tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
7680       TI_DBG1(("tdssNewAddSATAToSharedcontext: ERROR empty DeviceData FreeLink\n"));
7681       return oneDeviceData;
7682     }
7683 
7684     TDLIST_DEQUEUE_FROM_HEAD(&DeviceListList, &(tdsaAllShared->FreeDeviceList));
7685     tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
7686     oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, FreeLink, DeviceListList);
7687 
7688     onePortContext->Count++;
7689     oneDeviceData->DeviceType = TD_SATA_DEVICE;
7690     oneDeviceData->agRoot = agRoot;
7691     TI_DBG5(("tdssNewAddSATAToSharedcontext: oneDeviceData %p\n", oneDeviceData));
7692     TI_DBG5(("tdssNewAddSATAToSharedcontext: pSatDevData=%p\n", &oneDeviceData->satDevData));
7693 
7694 
7695     /* saving PortMultiplier(PM) field */
7696     oneDeviceData->satDevData.satPMField = pmField;
7697 
7698     /* saving signature */
7699     osti_memcpy(&(oneDeviceData->satDevData.satSignature), Signature, 8);
7700 
7701     /*
7702       saving device type
7703       ATA device type; here should be either ATA_ATA_DEVICE or ATA_ATAPI_DEVICE
7704     */
7705      oneDeviceData->satDevData.satDeviceType = tdssSATADeviceTypeDecode(agSATADeviceInfo->signature);
7706      TI_DBG3(("tdssNewAddSATAToSharedcontext: device type %d\n",  oneDeviceData->satDevData.satDeviceType));
7707 
7708 #ifdef RPM_SOC_REMOVED
7709     /* print device signature - Word8 */
7710     TI_DBG3(("tdssNewAddSATAToSharedcontext: Word8 %x signature: %x %x %x %x %x %x %x %x\n",
7711              agSATADeviceInfo->sataIdentifyData.word1_9[7],
7712              agSATADeviceInfo->signature[0], agSATADeviceInfo->signature[1],
7713              agSATADeviceInfo->signature[2], agSATADeviceInfo->signature[3],
7714              agSATADeviceInfo->signature[4], agSATADeviceInfo->signature[5],
7715              agSATADeviceInfo->signature[6], agSATADeviceInfo->signature[7] ));
7716 #endif
7717 
7718 
7719 
7720     oneDeviceData->tdPortContext = onePortContext;
7721     oneDeviceData->valid = agTRUE;
7722 
7723     oneDeviceData->ExpDevice = oneExpDeviceData;
7724     oneDeviceData->phyID = phyID;
7725 
7726     /* Add the devicedata to the portcontext */
7727     tdsaSingleThreadedEnter(tiRoot, TD_DEVICE_LOCK);
7728     TDLIST_ENQUEUE_AT_TAIL(&(oneDeviceData->MainLink), &(tdsaAllShared->MainDeviceList));
7729     tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
7730     TI_DBG5(("tdssNewAddSATAToSharedcontext: one case pid %d did %d \n",
7731       onePortContext->id, oneDeviceData->id));
7732   }
7733   else /* old device */
7734   {
7735     TI_DBG5(("tdssNewAddSATAToSharedcontext: old device\n"));
7736 
7737     onePortContext->Count++;
7738 
7739     oneDeviceData->DeviceType = TD_SATA_DEVICE;
7740     oneDeviceData->agRoot = agRoot;
7741 
7742     oneDeviceData->tdPortContext = onePortContext;
7743     oneDeviceData->valid = agTRUE;
7744 
7745     oneDeviceData->ExpDevice = oneExpDeviceData;
7746     oneDeviceData->phyID = phyID;
7747 
7748   }
7749 
7750   return oneDeviceData;
7751 
7752 }
7753 #endif /* SATA_ENABLE */
7754 #endif /* TD_DISCOVER */
7755 #endif /* INITIATOR_DRIVER */
7756 
7757 #ifdef TARGET_DRIVER
7758 /*****************************************************************************
7759 *! \brief  tdssReportRemovals
7760 *
7761 *  Purpose:  This function goes through device list and removes all devices
7762 *            belong to the portcontext. This function also deregiters those
7763 *            devices. This function is called in case of incremental discovery
7764 *            failure.
7765 *
7766 *  \param   agRoot        :  Pointer to chip/driver Instance.
7767 *  \param   onePortContext: Pointer to the portal context instance.
7768 *  \param   oneDeviceData: Pointer to the device data.
7769 *
7770 *  \return:
7771 *           None
7772 *
7773 *   \note:
7774 *
7775 *****************************************************************************/
7776 osGLOBAL void
7777 ttdssReportRemovals(
7778                   agsaRoot_t           *agRoot,
7779                   tdsaPortContext_t    *onePortContext,
7780                   bit32                flag
7781                   )
7782 {
7783   tdsaDeviceData_t  *oneDeviceData = agNULL;
7784   tdList_t          *DeviceListList;
7785   tdsaRootOsData_t  *osData = (tdsaRootOsData_t *)agRoot->osData;
7786   tiRoot_t          *tiRoot = (tiRoot_t *)osData->tiRoot;
7787   tdsaRoot_t        *tdsaRoot        = (tdsaRoot_t *) tiRoot->tdData;
7788   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
7789   bit32             removed = agFALSE;
7790   agsaEventSource_t *eventSource;
7791   bit32             PhyID;
7792   bit32             HwAckSatus;
7793   tdsaDeviceData_t  *tmpDeviceData = agNULL;
7794 
7795   TI_DBG1(("ttdssReportRemovals: start\n"));
7796   /* in case nothing was registered */
7797   PhyID = onePortContext->eventPhyID;
7798   if (tdsaAllShared->eventSource[PhyID].EventValid == agTRUE &&
7799       onePortContext->RegisteredDevNums == 0 &&
7800       PhyID != 0xFF
7801       )
7802   {
7803     TI_DBG1(("ttdssReportRemovals: calling saHwEventAck\n"));
7804     eventSource = &(tdsaAllShared->eventSource[PhyID].Source);
7805     HwAckSatus = saHwEventAck(
7806                               agRoot,
7807                               agNULL, /* agContext */
7808                               0,
7809                               eventSource, /* agsaEventSource_t */
7810                               0,
7811                               0
7812                               );
7813     if ( HwAckSatus != AGSA_RC_SUCCESS)
7814     {
7815       TI_DBG1(("ttdssReportRemovals: failing in saHwEventAck; status %d\n", HwAckSatus));
7816     }
7817 
7818     /* toggle */
7819     tdsaAllShared->eventSource[PhyID].EventValid = agFALSE;
7820     if (onePortContext->valid == agFALSE)
7821     {
7822       tdsaPortContextReInit(tiRoot, onePortContext);
7823       /*
7824         put all devices belonging to the onePortContext
7825         back to the free link
7826        */
7827       tdsaSingleThreadedEnter(tiRoot, TD_PORT_LOCK);
7828       TDLIST_DEQUEUE_THIS(&(onePortContext->MainLink));
7829       TDLIST_ENQUEUE_AT_TAIL(&(onePortContext->FreeLink), &(tdsaAllShared->FreePortContextList));
7830       tdsaSingleThreadedLeave(tiRoot, TD_PORT_LOCK);
7831     }
7832   }
7833   else
7834   {
7835     if (TDLIST_EMPTY(&(tdsaAllShared->MainDeviceList)))
7836     {
7837       TI_DBG1(("ttdssReportRemovals: empty device list\n"));
7838       return;
7839     }
7840 
7841     DeviceListList = tdsaAllShared->MainDeviceList.flink;
7842     while (DeviceListList != &(tdsaAllShared->MainDeviceList))
7843     {
7844       oneDeviceData = TDLIST_OBJECT_BASE(tdsaDeviceData_t, MainLink, DeviceListList);
7845       if( oneDeviceData == agNULL )
7846       {
7847         break;
7848       }
7849       TI_DBG1(("ttdssReportRemovals: loop did %d\n", oneDeviceData->id));
7850       TI_DBG1(("ttdssReportRemovals: sasAddrHi 0x%08x sasAddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi, oneDeviceData->SASAddressID.sasAddressLo));
7851       TI_DBG1(("ttdssReportRemovals: valid %d valid2 %d\n", oneDeviceData->valid, oneDeviceData->valid2));
7852       TI_DBG1(("ttdssReportRemovals: directlyAttached %d registered %d\n", oneDeviceData->directlyAttached, oneDeviceData->registered));
7853       if ( oneDeviceData->tdPortContext == onePortContext)
7854       {
7855         TI_DBG1(("ttdssReportRemovals: right portcontext pid %d\n", onePortContext->id));
7856         if (oneDeviceData->valid == agTRUE && oneDeviceData->registered == agTRUE)
7857         {
7858           TI_DBG1(("ttdssReportRemovals: removing\n"));
7859 
7860           /* notify only reported devices to OS layer*/
7861           removed = agTRUE;
7862 
7863           /* all targets except expanders */
7864           TI_DBG1(("ttdssReportRemovals: calling tdsaAbortAll\n"));
7865           TI_DBG1(("ttdssReportRemovals: did %d\n", oneDeviceData->id));
7866           TI_DBG1(("ttdssReportRemovals: sasAddrHi 0x%08x sasAddrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi, oneDeviceData->SASAddressID.sasAddressLo));
7867           tmpDeviceData = oneDeviceData;
7868           ttdsaAbortAll(tiRoot, agRoot, oneDeviceData);
7869 
7870 
7871           /* reset valid bit */
7872           oneDeviceData->valid = agFALSE;
7873           oneDeviceData->valid2 = agFALSE;
7874           oneDeviceData->registered = agFALSE;
7875         }
7876         /* called by port invalid case */
7877         if (flag == agTRUE)
7878         {
7879           oneDeviceData->tdPortContext = agNULL;
7880         }
7881 #ifdef REMOVED /* removed */
7882         /* directly attached SATA -> always remove it */
7883         if (oneDeviceData->DeviceType == TD_SATA_DEVICE &&
7884             oneDeviceData->directlyAttached == agTRUE)
7885         {
7886           TI_DBG1(("ttdssReportRemovals: device did %d\n", oneDeviceData->id));
7887           tdsaSingleThreadedEnter(tiRoot, TD_DEVICE_LOCK);
7888           TDLIST_DEQUEUE_THIS(&(oneDeviceData->MainLink));
7889           TDLIST_ENQUEUE_AT_TAIL(&(oneDeviceData->FreeLink), &(tdsaAllShared->FreeDeviceLis));
7890           DeviceListList = tdsaAllShared->MainDeviceList.flink;
7891           if (TDLIST_EMPTY(&(tdsaAllShared->MainDeviceList)))
7892           {
7893             tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
7894             break;
7895           }
7896           else
7897           {
7898             tdsaSingleThreadedLeave(tiRoot, TD_DEVICE_LOCK);
7899           }
7900         }
7901         else
7902         {
7903           DeviceListList = DeviceListList->flink;
7904         }
7905 #endif /* REMOVED */
7906         DeviceListList = DeviceListList->flink;
7907       }
7908       else
7909       {
7910         if (oneDeviceData->tdPortContext != agNULL)
7911         {
7912           TI_DBG1(("ttdssReportRemovals: different portcontext; oneDeviceData->tdPortContext pid %d oneportcontext pid %d\n", oneDeviceData->tdPortContext->id, onePortContext->id));
7913         }
7914         else
7915         {
7916           TI_DBG1(("ttdssReportRemovals: different portcontext; oneDeviceData->tdPortContext pid NULL oneportcontext pid %d\n", onePortContext->id));
7917         }
7918         DeviceListList = DeviceListList->flink;
7919       }
7920     }
7921 
7922     if (removed == agTRUE)
7923     {
7924       TI_DBG1(("ttdssReportRemovals: removed at the end\n"));
7925       ostiTargetEvent(
7926                       tiRoot,
7927                       onePortContext->tiPortalContext,
7928                       &(tmpDeviceData->tiDeviceHandle),
7929                       tiTgtEventTypeDeviceChange,
7930                       tiDeviceRemoval,
7931                       agNULL
7932                       );
7933     }
7934   } /* big else */
7935   return;
7936 }
7937 #endif /* TARGET_DRIVER */
7938 
7939 
7940 /*****************************************************************************
7941 *! \brief  tdsaRotateQnumber
7942 *
7943 *  Purpose:  This function generates inbound queue number.
7944 *
7945 *  \param   tiRoot: Pointer to the OS Specific module allocated tiRoot_t
7946 *                   instance.
7947 *
7948 *  \return:
7949 *           Queue number
7950 *
7951 *   \note:
7952 *
7953 *****************************************************************************/
7954 FORCEINLINE bit32
7955 tdsaRotateQnumber(tiRoot_t                *tiRoot,
7956                   tdsaDeviceData_t        *oneDeviceData )
7957 {
7958   bit32             ret = 0;
7959 
7960   TI_DBG6(("tdsaRotateQnumber: start\n"));
7961   if (oneDeviceData == agNULL)
7962   {
7963     return 0;
7964   }
7965   ret = (oneDeviceData->OutQID << 16) | oneDeviceData->InQID;
7966   return ret;
7967 }
7968 
7969 osGLOBAL bit32
7970 tdsaRotateQnumber1(tiRoot_t                *tiRoot,
7971                   tdsaDeviceData_t        *oneDeviceData )
7972 {
7973   tdsaRoot_t        *tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
7974   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
7975 //  static int Last_Q;
7976 //  bit32             denom = tdsaAllShared->QueueConfig.numOutboundQueues;
7977   bit32             ret = 0;
7978   if (oneDeviceData == agNULL)
7979   {
7980 //    Last_Q= 0;
7981     return 0;
7982   }
7983 
7984 /* alway use highest Q number */
7985   ret = ((tdsaAllShared->QueueConfig.numOutboundQueues-1) << 16) | (tdsaAllShared->QueueConfig.numInboundQueues-1);
7986 
7987   return(ret);
7988 }
7989 
7990 #ifdef REMOVED
7991 osGLOBAL bit32
7992 tdsaRotateQnumber(tiRoot_t                *tiRoot,
7993                   tdsaDeviceData_t        *oneDeviceData )
7994 {
7995   tdsaRoot_t        *tdsaRoot      = (tdsaRoot_t *) tiRoot->tdData;
7996   tdsaContext_t     *tdsaAllShared = (tdsaContext_t *)&tdsaRoot->tdsaAllShared;
7997   bit32             denom = tdsaAllShared->QueueConfig.numInboundQueues;
7998   bit32             ret = 0;
7999 
8000   /* inbound queue number */
8001   tdsaAllShared->IBQnumber++;
8002   if (tdsaAllShared->IBQnumber % denom == 0) /* % Qnumber*/
8003   {
8004     tdsaAllShared->IBQnumber = 0;
8005   }
8006   TI_DBG6(("tdsaRotateQnumber: IBQnumber %d\n", tdsaAllShared->IBQnumber));
8007 
8008 
8009   /* outbound queue number */
8010   tdsaAllShared->OBQnumber++;
8011   denom = tdsaAllShared->QueueConfig.numOutboundQueues;
8012   if (tdsaAllShared->OBQnumber % denom == 0) /* % Qnumber*/
8013   {
8014     tdsaAllShared->OBQnumber = 0;
8015   }
8016   TI_DBG6(("tdsaRotateQnumber: OBQnumber %d\n", tdsaAllShared->OBQnumber));
8017 
8018   ret = (tdsaAllShared->OBQnumber << 16) | tdsaAllShared->IBQnumber;
8019   return ret;
8020 }
8021 #endif
8022 
8023 
8024 void t_MacroCheck(  agsaRoot_t       *agRoot)
8025 {
8026   TI_DBG1(("t_MacroCheck:tIsSPC           %d\n",tIsSPC(agRoot)));
8027   TI_DBG1(("t_MacroCheck:tIsSPCHIL        %d\n",tIsSPCHIL(agRoot)));
8028   TI_DBG1(("t_MacroCheck:tIsSPCv          %d\n",tIsSPCv(agRoot)));
8029   TI_DBG1(("t_MacroCheck:tIsSPCve         %d\n",tIsSPCve(agRoot)));
8030   TI_DBG1(("t_MacroCheck:tIsSPCvplus      %d\n",tIsSPCvplus(agRoot)));
8031   TI_DBG1(("t_MacroCheck:tIsSPCveplus     %d\n",tIsSPCveplus(agRoot)));
8032   TI_DBG1(("t_MacroCheck:tIsSPCADAPvplus  %d\n",tIsSPCADAPvplus(agRoot)));
8033   TI_DBG1(("t_MacroCheck:tIsSPCADAPveplus %d\n",tIsSPCADAPveplus(agRoot)));
8034   TI_DBG1(("t_MacroCheck:tIsSPC12Gv       %d\n",tIsSPC12Gv(agRoot)));
8035   TI_DBG1(("t_MacroCheck:tIsSPC12Gve      %d\n",tIsSPC12Gve(agRoot)));
8036   TI_DBG1(("t_MacroCheck:tIsSPC12Gvplus   %d\n",tIsSPC12Gvplus(agRoot)));
8037   TI_DBG1(("t_MacroCheck:tIsSPC12Gveplus  %d\n",tIsSPC12Gveplus(agRoot)));
8038   TI_DBG1(("t_MacroCheck:tiIS_SPC         %d\n",tiIS_SPC(agRoot)   ));
8039   TI_DBG1(("t_MacroCheck:tiIS_HIL         %d\n",tiIS_HIL(agRoot)   ));
8040   TI_DBG1(("t_MacroCheck:tiIS_SPC6V       %d\n",tiIS_SPC6V(agRoot) ));
8041   TI_DBG1(("t_MacroCheck:tiIS_SPC_ENC     %d\n",tiIS_SPC_ENC(agRoot) ));
8042   TI_DBG1(("t_MacroCheck:tIsSPCV12G       %d\n",tIsSPCV12G(agRoot) ));
8043 }
8044