1 /*******************************************************************************
3 *Copyright (c) 2014 PMC-Sierra, Inc. All rights reserved.
5 *Redistribution and use in source and binary forms, with or without modification, are permitted provided
6 *that the following conditions are met:
7 *1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
9 *2. Redistributions in binary form must reproduce the above copyright notice,
10 *this list of conditions and the following disclaimer in the documentation and/or other materials provided
11 *with the distribution.
13 *THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
14 *WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15 *FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 *NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
18 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
19 *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
20 *SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
22 ********************************************************************************/
23 #include <sys/cdefs.h>
24 __FBSDID("$FreeBSD$");
25 #include <dev/pms/config.h>
27 #include <dev/pms/freebsd/driver/common/osenv.h>
28 #include <dev/pms/freebsd/driver/common/ostypes.h>
29 #include <dev/pms/freebsd/driver/common/osdebug.h>
31 #include <dev/pms/RefTisa/sallsdk/api/sa.h>
32 #include <dev/pms/RefTisa/sallsdk/api/saapi.h>
33 #include <dev/pms/RefTisa/sallsdk/api/saosapi.h>
36 #include <dev/pms/RefTisa/discovery/api/dm.h>
37 #include <dev/pms/RefTisa/discovery/api/dmapi.h>
38 #include <dev/pms/RefTisa/discovery/api/tddmapi.h>
40 #include <dev/pms/RefTisa/discovery/dm/dmdefs.h>
41 #include <dev/pms/RefTisa/discovery/dm/dmtypes.h>
42 #include <dev/pms/RefTisa/discovery/dm/dmproto.h>
44 /*****************************************************************************/
48 * Purpose: A discovery is started by this function
50 * \param dmRoot: DM context handle.
51 * \param dmPortContext: Pointer to this instance of port context
52 * \param option: Discovery option
59 /*****************************************************************************/
63 dmPortContext_t *dmPortContext,
66 dmIntPortContext_t *onePortContext = agNULL;
67 bit32 ret = DM_RC_FAILURE;
69 DM_DBG3(("dmDiscover: start\n"));
70 onePortContext = (dmIntPortContext_t *)dmPortContext->dmData;
72 if (onePortContext == agNULL)
74 DM_DBG1(("dmDiscover: onePortContext is NULL!!!\n"));
78 if (onePortContext->valid == agFALSE)
80 DM_DBG1(("dmDiscover: invalid port!!!\n"));
84 if (onePortContext->RegFailed == agTRUE)
86 DM_DBG1(("dmDiscover: Registration failed!!!\n"));
92 case DM_DISCOVERY_OPTION_FULL_START:
93 DM_DBG3(("dmDiscover: full, pid %d\n", onePortContext->id));
94 onePortContext->discovery.type = DM_DISCOVERY_OPTION_FULL_START;
95 dmDiscoveryResetMCN(dmRoot, onePortContext);
96 ret = dmFullDiscover(dmRoot, onePortContext);
98 case DM_DISCOVERY_OPTION_INCREMENTAL_START:
99 DM_DBG3(("dmDiscover: incremental, pid %d\n", onePortContext->id));
100 onePortContext->discovery.type = DM_DISCOVERY_OPTION_INCREMENTAL_START;
101 dmDiscoveryResetMCN(dmRoot, onePortContext);
102 ret = dmIncrementalDiscover(dmRoot, onePortContext, agFALSE);
104 case DM_DISCOVERY_OPTION_ABORT:
105 DM_DBG3(("dmDiscover: abort\n"));
106 if (onePortContext->DiscoveryState != DM_DSTATE_COMPLETED)
108 if (onePortContext->discovery.pendingSMP == 0)
110 dmDiscoverAbort(dmRoot, onePortContext);
113 onePortContext->dmPortContext,
119 DM_DBG3(("dmDiscover: abortInProgress\n"));
120 onePortContext->DiscoveryAbortInProgress = agTRUE;
124 dmDiscAbortInProgress
130 DM_DBG3(("dmDiscover: no discovery to abort\n"));
148 dmIntPortContext_t *onePortContext
151 dmExpander_t *oneExpander = agNULL;
152 dmSASSubID_t dmSASSubID;
153 dmDeviceData_t *oneExpDeviceData = agNULL;
155 DM_DBG1(("dmFullDiscover: start\n"));
157 if (onePortContext->valid == agFALSE)
159 DM_DBG1(("dmFullDiscover: invalid port!!!\n"));
160 return DM_RC_FAILURE;
163 if (onePortContext->DiscoveryState == DM_DSTATE_STARTED)
165 DM_DBG1(("dmFullDiscover: no two instances of discovery allowed!!!\n"));
166 return DM_RC_FAILURE;
169 onePortContext->DiscoveryState = DM_DSTATE_STARTED;
171 dmSASSubID.sasAddressHi = onePortContext->sasRemoteAddressHi;
172 dmSASSubID.sasAddressLo = onePortContext->sasRemoteAddressLo;
174 /* check OnePortContext->discovery.discoveringExpanderList */
175 oneExpander = dmExpFind(dmRoot, onePortContext, dmSASSubID.sasAddressHi, dmSASSubID.sasAddressLo);
176 if (oneExpander != agNULL)
178 oneExpDeviceData = oneExpander->dmDevice;
182 /* check dmAllShared->mainExpanderList */
183 oneExpander = dmExpMainListFind(dmRoot, onePortContext, dmSASSubID.sasAddressHi, dmSASSubID.sasAddressLo);
184 if (oneExpander != agNULL)
186 oneExpDeviceData = oneExpander->dmDevice;
190 if (oneExpDeviceData != agNULL)
192 dmSASSubID.initiator_ssp_stp_smp = oneExpDeviceData->initiator_ssp_stp_smp;
193 dmSASSubID.target_ssp_stp_smp = oneExpDeviceData->target_ssp_stp_smp;
194 oneExpDeviceData->registered = agTRUE;
195 dmAddSASToSharedcontext(dmRoot, onePortContext, &dmSASSubID, oneExpDeviceData, 0xFF);
199 DM_DBG1(("dmFullDiscover:oneExpDeviceData is NULL!!!\n"));
200 return DM_RC_FAILURE;
203 dmUpStreamDiscoverStart(dmRoot, onePortContext);
205 return DM_RC_SUCCESS;
209 dmIncrementalDiscover(
211 dmIntPortContext_t *onePortContext,
215 dmExpander_t *oneExpander = agNULL;
216 dmSASSubID_t dmSASSubID;
217 dmDeviceData_t *oneExpDeviceData = agNULL;
219 DM_DBG1(("dmIncrementalDiscover: start\n"));
221 if (onePortContext->valid == agFALSE)
223 DM_DBG1(("dmIncrementalDiscover: invalid port!!!\n"));
224 return DM_RC_FAILURE;
227 /* TDM triggerred; let go DM triggerred */
230 if (onePortContext->DiscoveryState == DM_DSTATE_STARTED)
232 DM_DBG1(("dmIncrementalDiscover: no two instances of discovery allowed!!!\n"));
233 return DM_RC_FAILURE;
237 onePortContext->DiscoveryState = DM_DSTATE_STARTED;
238 onePortContext->discovery.type = DM_DISCOVERY_OPTION_INCREMENTAL_START;
240 dmSASSubID.sasAddressHi = onePortContext->sasRemoteAddressHi;
241 dmSASSubID.sasAddressLo = onePortContext->sasRemoteAddressLo;
243 /* check OnePortContext->discovery.discoveringExpanderList */
244 oneExpander = dmExpFind(dmRoot, onePortContext, dmSASSubID.sasAddressHi, dmSASSubID.sasAddressLo);
245 if (oneExpander != agNULL)
247 oneExpDeviceData = oneExpander->dmDevice;
251 /* check dmAllShared->mainExpanderList */
252 oneExpander = dmExpMainListFind(dmRoot, onePortContext, dmSASSubID.sasAddressHi, dmSASSubID.sasAddressLo);
253 if (oneExpander != agNULL)
255 oneExpDeviceData = oneExpander->dmDevice;
259 if (oneExpDeviceData != agNULL)
261 dmSASSubID.initiator_ssp_stp_smp = oneExpDeviceData->initiator_ssp_stp_smp;
262 dmSASSubID.target_ssp_stp_smp = oneExpDeviceData->target_ssp_stp_smp;
263 oneExpDeviceData->registered = agTRUE;
264 dmAddSASToSharedcontext(dmRoot, onePortContext, &dmSASSubID, oneExpDeviceData, 0xFF);
268 DM_DBG1(("dmIncrementalDiscover:oneExpDeviceData is NULL!!!\n"));
269 return DM_RC_FAILURE;
272 dmUpStreamDiscoverStart(dmRoot, onePortContext);
274 return DM_RC_SUCCESS;
278 dmUpStreamDiscoverStart(
280 dmIntPortContext_t *onePortContext
283 // dmExpander_t *oneExpander = agNULL;
284 bit32 sasAddressHi, sasAddressLo;
285 dmDeviceData_t *oneDeviceData;
286 dmExpander_t *oneExpander = agNULL;
288 DM_DBG3(("dmUpStreamDiscoverStart: start\n"));
289 if (onePortContext->valid == agFALSE)
291 DM_DBG1(("dmUpStreamDiscoverStart: invalid port!!!\n"));
295 at this point, the 1st expander should have been registered.
296 find an expander from onePortContext
298 sasAddressHi = onePortContext->sasRemoteAddressHi;
299 sasAddressLo = onePortContext->sasRemoteAddressLo;
300 DM_DBG3(("dmUpStreamDiscoverStart: Port Remote AddrHi 0x%08x Remote AddrLo 0x%08x\n", sasAddressHi, sasAddressLo));
302 oneDeviceData = dmDeviceFind(dmRoot, onePortContext, sasAddressHi, sasAddressLo);
304 // oneDeviceData = oneExpander->dmDevice;
306 onePortContext->discovery.status = DISCOVERY_UP_STREAM;
307 if (oneDeviceData == agNULL)
309 DM_DBG1(("dmUpStreamDiscoverStart: oneExpander is NULL, wrong!!!\n"));
314 if ( (oneDeviceData->SASSpecDeviceType == SAS_EDGE_EXPANDER_DEVICE)
316 (oneDeviceData->SASSpecDeviceType == SAS_FANOUT_EXPANDER_DEVICE)
318 DEVICE_IS_SMP_TARGET(oneDeviceData)
321 #if 1 /* for incremental discovery */
322 /* start here: if not on discoveringExpanderList, alloc and add
325 oneExpander = dmExpFind(dmRoot, onePortContext, sasAddressHi, sasAddressLo);
326 if ( oneExpander == agNULL)
329 oneExpander = dmDiscoveringExpanderAlloc(dmRoot, onePortContext, oneDeviceData);
330 if ( oneExpander != agNULL)
332 dmDiscoveringExpanderAdd(dmRoot, onePortContext, oneExpander);
336 DM_DBG1(("dmUpStreamDiscoverStart: failed to allocate expander or discovey aborted!!!\n"));
342 dmUpStreamDiscovering(dmRoot, onePortContext, oneDeviceData);
346 DM_DBG1(("dmUpStreamDiscoverStart: oneDeviceData is not an Expander did %d, wrong!!!\n", oneDeviceData->id));
353 /* sends report general */
355 dmUpStreamDiscovering(
357 dmIntPortContext_t *onePortContext,
358 dmDeviceData_t *oneDeviceData
361 dmList_t *ExpanderList;
362 dmExpander_t *oneNextExpander = agNULL;
364 DM_DBG3(("dmUpStreamDiscovering: start\n"));
366 if (onePortContext->valid == agFALSE)
368 DM_DBG1(("dmUpStreamDiscovering: invalid port!!!\n"));
372 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
373 if (DMLIST_EMPTY(&(onePortContext->discovery.discoveringExpanderList)))
375 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
376 DM_DBG3(("dmUpStreamDiscovering: should be the end\n"));
377 oneNextExpander = agNULL;
381 DMLIST_DEQUEUE_FROM_HEAD(&ExpanderList, &(onePortContext->discovery.discoveringExpanderList));
382 oneNextExpander = DMLIST_OBJECT_BASE(dmExpander_t, linkNode, ExpanderList);
383 if ( oneNextExpander != agNULL)
385 DMLIST_ENQUEUE_AT_HEAD(&(oneNextExpander->linkNode), &(onePortContext->discovery.discoveringExpanderList));
386 DM_DBG3(("dmUpStreamDiscovering tdsaSASUpStreamDiscovering: dequeue head\n"));
387 DM_DBG3(("dmUpStreamDiscovering: expander id %d\n", oneNextExpander->id));
391 DM_DBG1(("dmUpStreamDiscovering: oneNextExpander is NULL!!!\n"));
393 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
397 if (oneNextExpander != agNULL)
399 dmReportGeneralSend(dmRoot, oneNextExpander->dmDevice);
403 DM_DBG3(("dmUpStreamDiscovering: No more expander list\n"));
404 dmDownStreamDiscoverStart(dmRoot, onePortContext, oneDeviceData);
411 dmDownStreamDiscoverStart(
413 dmIntPortContext_t *onePortContext,
414 dmDeviceData_t *oneDeviceData
417 dmExpander_t *UpStreamExpander;
418 dmExpander_t *oneExpander;
420 DM_DBG3(("dmDownStreamDiscoverStart: start\n"));
422 if (dmDiscoverCheck(dmRoot, onePortContext) == agTRUE)
424 DM_DBG1(("dmDownStreamDiscoverStart: invalid port or aborted discovery!!!\n"));
428 /* set discovery status */
429 onePortContext->discovery.status = DISCOVERY_DOWN_STREAM;
431 /* If it's an expander */
432 if ( (oneDeviceData->SASSpecDeviceType == SAS_EDGE_EXPANDER_DEVICE)
433 || (oneDeviceData->SASSpecDeviceType == SAS_FANOUT_EXPANDER_DEVICE)
434 || DEVICE_IS_SMP_TARGET(oneDeviceData)
437 oneExpander = oneDeviceData->dmExpander;
438 UpStreamExpander = oneExpander->dmUpStreamExpander;
440 /* If the two expanders are the root of two edge sets; sub-to-sub */
441 if ( (UpStreamExpander != agNULL) && ( UpStreamExpander->dmUpStreamExpander == oneExpander ) )
443 DM_DBG3(("dmDownStreamDiscoverStart: Root found pExpander=%p pUpStreamExpander=%p\n",
444 oneExpander, UpStreamExpander));
445 //Saves the root expander
446 onePortContext->discovery.RootExp = oneExpander;
447 DM_DBG3(("dmDownStreamDiscoverStart: Root exp addrHi 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressHi));
448 DM_DBG3(("dmDownStreamDiscoverStart: Root exp addrLo 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressLo));
450 /* reset up stream inform for pExpander */
451 oneExpander->dmUpStreamExpander = agNULL;
452 /* Add the pExpander to discovering list */
453 dmDiscoveringExpanderAdd(dmRoot, onePortContext, oneExpander);
455 /* reset up stream inform for oneExpander */
456 UpStreamExpander->dmUpStreamExpander = agNULL;
457 /* Add the UpStreamExpander to discovering list */
458 dmDiscoveringExpanderAdd(dmRoot, onePortContext, UpStreamExpander);
460 /* If the two expanders are not the root of two edge sets. eg) one root */
463 //Saves the root expander
464 onePortContext->discovery.RootExp = oneExpander;
466 DM_DBG3(("dmDownStreamDiscoverStart: NO Root pExpander=%p\n", oneExpander));
467 DM_DBG3(("dmDownStreamDiscoverStart: Root exp addrHi 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressHi));
468 DM_DBG3(("dmDownStreamDiscoverStart: Root exp addrLo 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressLo));
470 /* (2.2.2.1) Add the pExpander to discovering list */
471 dmDiscoveringExpanderAdd(dmRoot, onePortContext, oneExpander);
475 /* Continue down stream discovering */
476 dmDownStreamDiscovering(dmRoot, onePortContext, oneDeviceData);
482 dmDownStreamDiscovering(
484 dmIntPortContext_t *onePortContext,
485 dmDeviceData_t *oneDeviceData
488 dmExpander_t *NextExpander = agNULL;
489 dmList_t *ExpanderList;
491 DM_DBG3(("dmDownStreamDiscovering: start\n"));
493 if (dmDiscoverCheck(dmRoot, onePortContext) == agTRUE)
495 DM_DBG1(("dmDownStreamDiscovering: invalid port or aborted discovery!!!\n"));
499 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
500 if (DMLIST_EMPTY(&(onePortContext->discovery.discoveringExpanderList)))
502 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
503 DM_DBG3(("dmDownStreamDiscovering: should be the end\n"));
504 NextExpander = agNULL;
508 DMLIST_DEQUEUE_FROM_HEAD(&ExpanderList, &(onePortContext->discovery.discoveringExpanderList));;
509 NextExpander = DMLIST_OBJECT_BASE(dmExpander_t, linkNode, ExpanderList);
510 if ( NextExpander != agNULL)
512 DMLIST_ENQUEUE_AT_HEAD(&(NextExpander->linkNode), &(onePortContext->discovery.discoveringExpanderList));;
513 DM_DBG3(("dmDownStreamDiscovering tdsaSASDownStreamDiscovering: dequeue head\n"));
514 DM_DBG3(("dmDownStreamDiscovering: expander id %d\n", NextExpander->id));
518 DM_DBG1(("dmDownStreamDiscovering: NextExpander is NULL!!!\n"));
520 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
524 /* If there is an expander for continue discoving */
525 if ( NextExpander != agNULL)
527 DM_DBG3(("dmDownStreamDiscovering: Found pNextExpander=%p discoveryStatus=0x%x\n",
528 NextExpander, onePortContext->discovery.status));
530 switch (onePortContext->discovery.status)
532 /* If the discovery status is DISCOVERY_DOWN_STREAM */
533 case DISCOVERY_DOWN_STREAM:
534 /* Send report general for the next expander */
535 DM_DBG3(("dmDownStreamDiscovering: DownStream pNextExpander=%p\n", NextExpander));
536 DM_DBG3(("dmDownStreamDiscovering: oneDeviceData %p did %d\n", oneDeviceData, oneDeviceData->id));
537 DM_DBG3(("dmDownStreamDiscovering: oneExpander %p did %d\n", oneDeviceData->dmExpander, oneDeviceData->dmExpander->id));
539 DM_DBG3(("dmDownStreamDiscovering: 2nd oneDeviceData %p did %d\n", NextExpander->dmDevice, NextExpander->dmDevice->id));
540 DM_DBG3(("dmDownStreamDiscovering: 2nd oneExpander %p did %d\n", NextExpander, NextExpander->id));
541 DM_DBG3(("dmDownStreamDiscovering: 2nd used oneExpander %p did %d\n", NextExpander->dmDevice->dmExpander, NextExpander->dmDevice->dmExpander->id));
543 if (NextExpander != NextExpander->dmDevice->dmExpander)
545 DM_DBG3(("dmDownStreamDiscovering: wrong!!!\n"));
549 dmReportGeneralSend(dmRoot, NextExpander->dmDevice);
551 /* If the discovery status is DISCOVERY_CONFIG_ROUTING */
552 case DISCOVERY_CONFIG_ROUTING:
553 case DISCOVERY_REPORT_PHY_SATA:
555 /* set discovery status */
556 onePortContext->discovery.status = DISCOVERY_DOWN_STREAM;
558 DM_DBG3(("dmDownStreamDiscovering: pPort->discovery.status=DISCOVERY_CONFIG_ROUTING, make it DOWN_STREAM\n"));
559 /* If not the last phy */
560 if ( NextExpander->discoveringPhyId < NextExpander->dmDevice->numOfPhys )
562 DM_DBG3(("dmDownStreamDiscovering: pNextExpander->discoveringPhyId=0x%x pNextExpander->numOfPhys=0x%x. Send More Discover\n",
563 NextExpander->discoveringPhyId, NextExpander->dmDevice->numOfPhys));
564 /* Send discover for the next expander */
565 dmDiscoverSend(dmRoot, NextExpander->dmDevice);
567 /* If it's the last phy */
570 DM_DBG3(("dmDownStreamDiscovering: Last Phy, remove expander%p start DownStream=%p\n",
571 NextExpander, NextExpander->dmDevice));
572 dmDiscoveringExpanderRemove(dmRoot, onePortContext, NextExpander);
573 dmDownStreamDiscovering(dmRoot, onePortContext, NextExpander->dmDevice);
578 DM_DBG3(("dmDownStreamDiscovering: *** Unknown pPort->discovery.status=0x%x\n", onePortContext->discovery.status));
581 /* If no expander for continue discoving */
584 DM_DBG3(("dmDownStreamDiscovering: No more expander DONE\n"));
586 dmDiscoverDone(dmRoot, onePortContext, DM_RC_SUCCESS);
594 dmUpStreamDiscoverExpanderPhy(
596 dmIntPortContext_t *onePortContext,
597 dmExpander_t *oneExpander,
598 smpRespDiscover_t *pDiscoverResp
601 agsaSASIdentify_t sasIdentify;
602 dmSASSubID_t dmSASSubID;
603 bit32 attachedSasHi, attachedSasLo;
604 dmExpander_t *AttachedExpander = agNULL;
606 dmDeviceData_t *oneDeviceData = agNULL;
607 dmDeviceData_t *AttachedDevice = agNULL;
608 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
609 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
612 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: start\n"));
614 if (dmDiscoverCheck(dmRoot, onePortContext) == agTRUE)
616 DM_DBG1(("dmUpStreamDiscoverExpanderPhy: invalid port or aborted discovery!!!\n"));
620 if (oneExpander != oneExpander->dmDevice->dmExpander)
622 DM_DBG1(("dmUpStreamDiscoverExpanderPhy: wrong!!!\n"));
625 dm_memset(&sasIdentify, 0, sizeof(agsaSASIdentify_t));
627 oneDeviceData = oneExpander->dmDevice;
629 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: Phy #%d of SAS %08x-%08x\n",
630 oneExpander->discoveringPhyId,
631 oneDeviceData->SASAddressID.sasAddressHi,
632 oneDeviceData->SASAddressID.sasAddressLo));
634 DM_DBG3((" Attached device: %s\n",
635 ( DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == 0 ? "No Device" :
636 (DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == 1 ? "End Device" :
637 (DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == 2 ? "Edge Expander" : "Fanout Expander")))));
640 if ( DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) != SAS_NO_DEVICE)
642 DM_DBG3((" SAS address : %08x-%08x\n",
643 DISCRSP_GET_ATTACHED_SAS_ADDRESSHI(pDiscoverResp),
644 DISCRSP_GET_ATTACHED_SAS_ADDRESSLO(pDiscoverResp)));
645 DM_DBG3((" SSP Target : %d\n", DISCRSP_IS_SSP_TARGET(pDiscoverResp)?1:0));
646 DM_DBG3((" STP Target : %d\n", DISCRSP_IS_STP_TARGET(pDiscoverResp)?1:0));
647 DM_DBG3((" SMP Target : %d\n", DISCRSP_IS_SMP_TARGET(pDiscoverResp)?1:0));
648 DM_DBG3((" SATA DEVICE : %d\n", DISCRSP_IS_SATA_DEVICE(pDiscoverResp)?1:0));
649 DM_DBG3((" SSP Initiator : %d\n", DISCRSP_IS_SSP_INITIATOR(pDiscoverResp)?1:0));
650 DM_DBG3((" STP Initiator : %d\n", DISCRSP_IS_STP_INITIATOR(pDiscoverResp)?1:0));
651 DM_DBG3((" SMP Initiator : %d\n", DISCRSP_IS_SMP_INITIATOR(pDiscoverResp)?1:0));
652 DM_DBG3((" Phy ID : %d\n", pDiscoverResp->phyIdentifier));
653 DM_DBG3((" Attached Phy ID: %d\n", pDiscoverResp->attachedPhyIdentifier));
657 if (oneExpander->discoveringPhyId != pDiscoverResp->phyIdentifier)
659 DM_DBG1(("dmUpStreamDiscoverExpanderPhy: !!! Incorrect SMP response !!!\n"));
660 DM_DBG1(("dmUpStreamDiscoverExpanderPhy: Request PhyID #%d Response PhyID #%d !!!\n", oneExpander->discoveringPhyId, pDiscoverResp->phyIdentifier));
661 dmhexdump("NO_DEVICE", (bit8*)pDiscoverResp, sizeof(smpRespDiscover_t));
662 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
666 /* saving routing attribute for non self-configuring expanders */
667 oneExpander->routingAttribute[pDiscoverResp->phyIdentifier] = (bit8)DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp);
669 if ( oneDeviceData->SASSpecDeviceType == SAS_FANOUT_EXPANDER_DEVICE )
671 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: SA_SAS_DEV_TYPE_FANOUT_EXPANDER\n"));
672 if ( DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_SUBTRACTIVE)
674 DM_DBG1(("dmUpStreamDiscoverExpanderPhy: **** Topology Error subtractive routing on fanout expander device!!!\n"));
676 /* discovery error */
677 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
678 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
679 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
680 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
681 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
682 DM_DBG1(("dmUpStreamDiscoverExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
683 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
684 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
685 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
687 /* (2.1.3) discovery done */
688 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
694 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: SA_SAS_DEV_TYPE_EDGE_EXPANDER\n"));
695 if ( DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) != SAS_NO_DEVICE)
697 /* Setup sasIdentify for the attached device */
698 sasIdentify.phyIdentifier = pDiscoverResp->phyIdentifier;
699 sasIdentify.deviceType_addressFrameType = (bit8)(pDiscoverResp->attachedDeviceType & 0x70);
700 sasIdentify.initiator_ssp_stp_smp = pDiscoverResp->attached_Ssp_Stp_Smp_Sata_Initiator;
701 sasIdentify.target_ssp_stp_smp = pDiscoverResp->attached_SataPS_Ssp_Stp_Smp_Sata_Target;
702 *(bit32*)sasIdentify.sasAddressHi = *(bit32*)pDiscoverResp->attachedSasAddressHi;
703 *(bit32*)sasIdentify.sasAddressLo = *(bit32*)pDiscoverResp->attachedSasAddressLo;
705 /* incremental discovery */
706 dmSASSubID.sasAddressHi = SA_IDFRM_GET_SAS_ADDRESSHI(&sasIdentify);
707 dmSASSubID.sasAddressLo = SA_IDFRM_GET_SAS_ADDRESSLO(&sasIdentify);
708 dmSASSubID.initiator_ssp_stp_smp = sasIdentify.initiator_ssp_stp_smp;
709 dmSASSubID.target_ssp_stp_smp = sasIdentify.target_ssp_stp_smp;
711 attachedSasHi = DISCRSP_GET_ATTACHED_SAS_ADDRESSHI(pDiscoverResp);
712 attachedSasLo = DISCRSP_GET_ATTACHED_SAS_ADDRESSLO(pDiscoverResp);
714 /* If the phy has subtractive routing attribute */
715 if ( DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_SUBTRACTIVE)
717 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: SA_SAS_ROUTING_SUBTRACTIVE\n"));
718 /* Setup upstream phys */
719 dmExpanderUpStreamPhyAdd(dmRoot, oneExpander, (bit8) pDiscoverResp->attachedPhyIdentifier);
720 /* If the expander already has an upsteam device set up */
721 if (oneExpander->hasUpStreamDevice == agTRUE)
723 /* just to update MCN */
724 dmPortSASDeviceFind(dmRoot, onePortContext, attachedSasLo, attachedSasHi, oneDeviceData);
725 /* If the sas address doesn't match */
726 if ( ((oneExpander->upStreamSASAddressHi != attachedSasHi) ||
727 (oneExpander->upStreamSASAddressLo != attachedSasLo)) &&
728 (DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_EDGE_EXPANDER_DEVICE ||
729 DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_FANOUT_EXPANDER_DEVICE)
732 /* TODO: discovery error, callback */
733 DM_DBG1(("dmUpStreamDiscoverExpanderPhy: **** Topology Error subtractive routing error - inconsistent SAS address!!!\n"));
734 /* call back to notify discovery error */
735 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
736 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
737 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
738 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
739 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
740 DM_DBG1(("dmUpStreamDiscoverExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
741 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
742 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
743 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
745 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
750 /* Setup SAS address for up stream device */
751 oneExpander->hasUpStreamDevice = agTRUE;
752 oneExpander->upStreamSASAddressHi = attachedSasHi;
753 oneExpander->upStreamSASAddressLo = attachedSasLo;
754 if ( (onePortContext->sasLocalAddressHi != attachedSasHi)
755 || (onePortContext->sasLocalAddressLo != attachedSasLo) )
757 /* Find the device from the discovered list */
758 AttachedDevice = dmPortSASDeviceFind(dmRoot, onePortContext, attachedSasLo, attachedSasHi, oneDeviceData);
759 /* New device, If the device has been discovered before */
760 if ( AttachedDevice != agNULL) /* old device */
762 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: Seen This Device Before\n"));
763 /* If attached device is an edge expander */
764 if ( AttachedDevice->SASSpecDeviceType == SAS_EDGE_EXPANDER_DEVICE)
766 /* The attached device is an expander */
767 AttachedExpander = AttachedDevice->dmExpander;
768 /* If the two expanders are the root of the two edge expander sets */
769 if ( (AttachedExpander->upStreamSASAddressHi ==
770 DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo))
771 && (AttachedExpander->upStreamSASAddressLo ==
772 DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo)) )
774 /* Setup upstream expander for the pExpander */
775 oneExpander->dmUpStreamExpander = AttachedExpander;
777 /* If the two expanders are not the root of the two edge expander sets */
780 /* TODO: loop found, discovery error, callback */
781 DM_DBG1(("dmUpStreamDiscoverExpanderPhy: **** Topology Error loop detection!!!\n"));
782 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
783 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
784 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
785 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
786 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
787 DM_DBG1(("dmUpStreamDiscoverExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
788 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
789 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
790 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
792 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
795 /* If attached device is not an edge expander */
798 /*TODO: should not happen, ASSERT */
799 DM_DBG3(("dmUpStreamDiscoverExpanderPhy, *** Attached Device is not Edge. Confused!!!\n"));
801 } /* AttachedExpander != agNULL */
802 /* New device, If the device has not been discovered before */
803 else /* new device */
806 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: New device\n"));
807 /* read minimum rate from the configuration
808 onePortContext->LinkRate is SPC's local link rate
810 connectionRate = (bit8)MIN(onePortContext->LinkRate, DISCRSP_GET_LINKRATE(pDiscoverResp));
811 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: link rate 0x%x\n", onePortContext->LinkRate));
812 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: negotiatedPhyLinkRate 0x%x\n", DISCRSP_GET_LINKRATE(pDiscoverResp)));
813 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: connectionRate 0x%x\n", connectionRate));
814 if (DISCRSP_IS_STP_TARGET(pDiscoverResp) || DISCRSP_IS_SATA_DEVICE(pDiscoverResp))
816 /* incremental discovery */
817 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_FULL_START)
819 AttachedDevice = dmPortSASDeviceAdd(
825 dmAllShared->itNexusTimeout,
830 pDiscoverResp->phyIdentifier
835 /* incremental discovery */
836 AttachedDevice = dmFindRegNValid(
841 /* not registered and not valid; add this*/
842 if (AttachedDevice == agNULL)
844 AttachedDevice = dmPortSASDeviceAdd(
850 dmAllShared->itNexusTimeout,
855 pDiscoverResp->phyIdentifier
859 } /* DISCRSP_IS_STP_TARGET(pDiscoverResp) || DISCRSP_IS_SATA_DEVICE(pDiscoverResp) */
862 /* incremental discovery */
863 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_FULL_START)
865 AttachedDevice = dmPortSASDeviceAdd(
871 dmAllShared->itNexusTimeout,
876 pDiscoverResp->phyIdentifier
881 /* incremental discovery */
882 AttachedDevice = dmFindRegNValid(
887 /* not registered and not valid; add this*/
888 if (AttachedDevice == agNULL)
890 AttachedDevice = dmPortSASDeviceAdd(
896 dmAllShared->itNexusTimeout,
901 pDiscoverResp->phyIdentifier
906 /* If the device is added successfully */
907 if ( AttachedDevice != agNULL)
910 /* (3.1.2.3.2.3.2.1) callback about new device */
911 if ( DISCRSP_IS_SSP_TARGET(pDiscoverResp)
912 || DISCRSP_IS_SSP_INITIATOR(pDiscoverResp)
913 || DISCRSP_IS_SMP_INITIATOR(pDiscoverResp)
914 || DISCRSP_IS_SMP_INITIATOR(pDiscoverResp) )
916 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: Found SSP/SMP SAS %08x-%08x\n",
917 attachedSasHi, attachedSasLo));
921 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: Found a SAS STP device.\n"));
923 /* If the attached device is an expander */
924 if ( (DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_EDGE_EXPANDER_DEVICE)
925 || (DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_FANOUT_EXPANDER_DEVICE) )
927 /* Allocate an expander data structure */
928 AttachedExpander = dmDiscoveringExpanderAlloc(
934 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: Found expander=%p\n", AttachedExpander));
935 /* If allocate successfully */
936 if ( AttachedExpander != agNULL)
938 /* Add the pAttachedExpander to discovering list */
939 dmDiscoveringExpanderAdd(dmRoot, onePortContext, AttachedExpander);
940 /* Setup upstream expander for the pExpander */
941 oneExpander->dmUpStreamExpander = AttachedExpander;
943 /* If failed to allocate */
946 DM_DBG1(("dmUpStreamDiscoverExpanderPhy: Failed to allocate expander data structure!!!\n"));
947 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
950 /* If the attached device is an end device */
953 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: Found end device\n"));
954 /* LP2006-05-26 added upstream device to the newly found device */
955 AttachedDevice->dmExpander = oneExpander;
956 oneExpander->dmUpStreamExpander = agNULL;
961 DM_DBG1(("dmUpStreamDiscoverExpanderPhy: Failed to add a device!!!\n"));
962 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
967 } /* else, new device */
968 } /* onePortContext->sasLocalAddressLo != attachedSasLo */
970 } /* DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_SUBTRACTIVE */
971 } /* DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) != SAS_NO_DEVICE */
976 oneExpander->discoveringPhyId ++;
977 if (onePortContext->discovery.status == DISCOVERY_UP_STREAM)
979 if ( oneExpander->discoveringPhyId < oneDeviceData->numOfPhys )
981 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: DISCOVERY_UP_STREAM find more ...\n"));
982 /* continue discovery for the next phy */
983 dmDiscoverSend(dmRoot, oneDeviceData);
987 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: DISCOVERY_UP_STREAM last phy continue upstream..\n"));
990 dmUpdateAllAdjacent(dmRoot, onePortContext, oneDeviceData);
991 /* remove the expander from the discovering list */
992 dmDiscoveringExpanderRemove(dmRoot, onePortContext, oneExpander);
993 /* continue upstream discovering */
994 dmUpStreamDiscovering(dmRoot, onePortContext, oneDeviceData);
999 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: onePortContext->discovery.status not in DISCOVERY_UP_STREAM; status %d\n", onePortContext->discovery.status));
1003 DM_DBG3(("dmUpStreamDiscoverExpanderPhy: end return phyID#%d\n", oneExpander->discoveringPhyId - 1));
1009 dmUpStreamDiscover2ExpanderPhy(
1011 dmIntPortContext_t *onePortContext,
1012 dmExpander_t *oneExpander,
1013 smpRespDiscover2_t *pDiscoverResp
1016 dmDeviceData_t *oneDeviceData;
1017 dmDeviceData_t *AttachedDevice = agNULL;
1018 dmExpander_t *AttachedExpander;
1019 agsaSASIdentify_t sasIdentify;
1020 bit8 connectionRate;
1021 bit32 attachedSasHi, attachedSasLo;
1022 dmSASSubID_t dmSASSubID;
1023 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
1024 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
1026 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: start\n"));
1028 if (dmDiscoverCheck(dmRoot, onePortContext) == agTRUE)
1030 DM_DBG1(("dmUpStreamDiscover2ExpanderPhy: invalid port or aborted discovery!!!\n"));
1034 if (oneExpander != oneExpander->dmDevice->dmExpander)
1036 DM_DBG1(("dmUpStreamDiscover2ExpanderPhy: wrong!!!\n"));
1039 dm_memset(&sasIdentify, 0, sizeof(agsaSASIdentify_t));
1041 oneDeviceData = oneExpander->dmDevice;
1043 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: Phy #%d of SAS %08x-%08x\n",
1044 oneExpander->discoveringPhyId,
1045 oneDeviceData->SASAddressID.sasAddressHi,
1046 oneDeviceData->SASAddressID.sasAddressLo));
1048 DM_DBG2((" Attached device: %s\n",
1049 ( SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == 0 ? "No Device" :
1050 (SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == 1 ? "End Device" :
1051 (SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == 2 ? "Edge Expander" : "Fanout Expander")))));
1054 if ( SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) != SAS_NO_DEVICE)
1056 DM_DBG2((" SAS address : %08x-%08x\n",
1057 SAS2_DISCRSP_GET_ATTACHED_SAS_ADDRESSHI(pDiscoverResp),
1058 SAS2_DISCRSP_GET_ATTACHED_SAS_ADDRESSLO(pDiscoverResp)));
1059 DM_DBG2((" SSP Target : %d\n", SAS2_DISCRSP_IS_SSP_TARGET(pDiscoverResp)?1:0));
1060 DM_DBG2((" STP Target : %d\n", SAS2_DISCRSP_IS_STP_TARGET(pDiscoverResp)?1:0));
1061 DM_DBG2((" SMP Target : %d\n", SAS2_DISCRSP_IS_SMP_TARGET(pDiscoverResp)?1:0));
1062 DM_DBG2((" SATA DEVICE : %d\n", SAS2_DISCRSP_IS_SATA_DEVICE(pDiscoverResp)?1:0));
1063 DM_DBG2((" SSP Initiator : %d\n", SAS2_DISCRSP_IS_SSP_INITIATOR(pDiscoverResp)?1:0));
1064 DM_DBG2((" STP Initiator : %d\n", SAS2_DISCRSP_IS_STP_INITIATOR(pDiscoverResp)?1:0));
1065 DM_DBG2((" SMP Initiator : %d\n", SAS2_DISCRSP_IS_SMP_INITIATOR(pDiscoverResp)?1:0));
1066 DM_DBG2((" Phy ID : %d\n", pDiscoverResp->phyIdentifier));
1067 DM_DBG2((" Attached Phy ID: %d\n", pDiscoverResp->attachedPhyIdentifier));
1070 if (oneExpander->discoveringPhyId != pDiscoverResp->phyIdentifier)
1072 DM_DBG1(("dmUpStreamDiscover2ExpanderPhy: !!! Incorrect SMP response !!!\n"));
1073 DM_DBG1(("dmUpStreamDiscover2ExpanderPhy: Request PhyID #%d Response PhyID #%d\n", oneExpander->discoveringPhyId, pDiscoverResp->phyIdentifier));
1074 dmhexdump("NO_DEVICE", (bit8*)pDiscoverResp, sizeof(smpRespDiscover2_t));
1075 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1079 /* saving routing attribute for non self-configuring expanders */
1080 oneExpander->routingAttribute[pDiscoverResp->phyIdentifier] = SAS2_DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp);
1082 if ( oneDeviceData->SASSpecDeviceType == SAS_FANOUT_EXPANDER_DEVICE )
1084 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: SA_SAS_DEV_TYPE_FANOUT_EXPANDER\n"));
1085 if ( SAS2_DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_SUBTRACTIVE)
1087 DM_DBG1(("dmUpStreamDiscover2ExpanderPhy: **** Topology Error subtractive routing on fanout expander device!!!\n"));
1089 /* discovery error */
1090 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
1091 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
1092 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
1093 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
1094 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
1095 DM_DBG1(("dmUpStreamDiscover2ExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
1096 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
1097 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
1098 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
1100 /* (2.1.3) discovery done */
1101 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1107 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: SA_SAS_DEV_TYPE_EDGE_EXPANDER\n"));
1109 if ( SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) != SAS_NO_DEVICE)
1111 /* Setup sasIdentify for the attached device */
1112 sasIdentify.phyIdentifier = pDiscoverResp->phyIdentifier;
1113 sasIdentify.deviceType_addressFrameType = pDiscoverResp->attachedDeviceTypeReason & 0x70;
1114 sasIdentify.initiator_ssp_stp_smp = pDiscoverResp->attached_Ssp_Stp_Smp_Sata_Initiator;
1115 sasIdentify.target_ssp_stp_smp = pDiscoverResp->attached_SataPS_Ssp_Stp_Smp_Sata_Target;
1116 *(bit32*)sasIdentify.sasAddressHi = *(bit32*)pDiscoverResp->attachedSasAddressHi;
1117 *(bit32*)sasIdentify.sasAddressLo = *(bit32*)pDiscoverResp->attachedSasAddressLo;
1119 /* incremental discovery */
1120 dmSASSubID.sasAddressHi = SA_IDFRM_GET_SAS_ADDRESSHI(&sasIdentify);
1121 dmSASSubID.sasAddressLo = SA_IDFRM_GET_SAS_ADDRESSLO(&sasIdentify);
1122 dmSASSubID.initiator_ssp_stp_smp = sasIdentify.initiator_ssp_stp_smp;
1123 dmSASSubID.target_ssp_stp_smp = sasIdentify.target_ssp_stp_smp;
1125 attachedSasHi = SAS2_DISCRSP_GET_ATTACHED_SAS_ADDRESSHI(pDiscoverResp);
1126 attachedSasLo = SAS2_DISCRSP_GET_ATTACHED_SAS_ADDRESSLO(pDiscoverResp);
1128 /* If the phy has subtractive routing attribute */
1129 if ( SAS2_DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_SUBTRACTIVE)
1131 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: SA_SAS_ROUTING_SUBTRACTIVE\n"));
1132 /* Setup upstream phys */
1133 dmExpanderUpStreamPhyAdd(dmRoot, oneExpander, (bit8) pDiscoverResp->attachedPhyIdentifier);
1134 /* If the expander already has an upsteam device set up */
1135 if (oneExpander->hasUpStreamDevice == agTRUE)
1137 /* just to update MCN */
1138 dmPortSASDeviceFind(dmRoot, onePortContext, attachedSasLo, attachedSasHi, oneDeviceData);
1139 /* If the sas address doesn't match */
1140 if ( ((oneExpander->upStreamSASAddressHi != attachedSasHi) ||
1141 (oneExpander->upStreamSASAddressLo != attachedSasLo)) &&
1142 (SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_EDGE_EXPANDER_DEVICE ||
1143 SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_FANOUT_EXPANDER_DEVICE)
1146 /* TODO: discovery error, callback */
1147 DM_DBG1(("dmUpStreamDiscover2ExpanderPhy: **** Topology Error subtractive routing error - inconsistent SAS address!!!\n"));
1148 /* call back to notify discovery error */
1149 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
1150 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
1151 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
1152 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
1153 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
1154 DM_DBG1(("dmUpStreamDiscover2ExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
1155 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
1156 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
1157 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
1158 /* discovery done */
1159 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1164 /* Setup SAS address for up stream device */
1165 oneExpander->hasUpStreamDevice = agTRUE;
1166 oneExpander->upStreamSASAddressHi = attachedSasHi;
1167 oneExpander->upStreamSASAddressLo = attachedSasLo;
1169 if ( (onePortContext->sasLocalAddressHi != attachedSasHi)
1170 || (onePortContext->sasLocalAddressLo != attachedSasLo) )
1172 /* Find the device from the discovered list */
1173 AttachedDevice = dmPortSASDeviceFind(dmRoot, onePortContext, attachedSasLo, attachedSasHi, oneDeviceData);
1174 /* If the device has been discovered before */
1175 if ( AttachedDevice != agNULL)
1177 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: Seen This Device Before\n"));
1178 /* If attached device is an edge expander */
1179 if ( AttachedDevice->SASSpecDeviceType == SAS_EDGE_EXPANDER_DEVICE)
1181 /* The attached device is an expander */
1182 AttachedExpander = AttachedDevice->dmExpander;
1183 /* If the two expanders are the root of the two edge expander sets */
1184 if ( (AttachedExpander->upStreamSASAddressHi ==
1185 DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo))
1186 && (AttachedExpander->upStreamSASAddressLo ==
1187 DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo)) )
1189 /* Setup upstream expander for the pExpander */
1190 oneExpander->dmUpStreamExpander = AttachedExpander;
1192 /* If the two expanders are not the root of the two edge expander sets */
1195 /* TODO: loop found, discovery error, callback */
1196 DM_DBG1(("dmUpStreamDiscover2ExpanderPhy: **** Topology Error loop detection!!!\n"));
1197 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
1198 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
1199 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
1200 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
1201 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
1202 DM_DBG1(("dmUpStreamDiscover2ExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
1203 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
1204 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
1205 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
1206 /* discovery done */
1207 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1210 /* If attached device is not an edge expander */
1213 /*TODO: should not happen, ASSERT */
1214 DM_DBG1(("dmUpStreamDiscover2ExpanderPhy, *** Attached Device is not Edge. Confused!!!\n"));
1217 /* If the device has not been discovered before */
1220 /* Add the device */
1221 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: New device\n"));
1222 /* read minimum rate from the configuration
1223 onePortContext->LinkRate is SPC's local link rate
1225 connectionRate = MIN(onePortContext->LinkRate, SAS2_DISCRSP_GET_LOGICAL_LINKRATE(pDiscoverResp));
1226 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: link rate 0x%x\n", onePortContext->LinkRate));
1227 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: negotiatedPhyLinkRate 0x%x\n", SAS2_DISCRSP_GET_LINKRATE(pDiscoverResp)));
1228 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: connectionRate 0x%x\n", connectionRate));
1230 if (SAS2_DISCRSP_IS_STP_TARGET(pDiscoverResp) || SAS2_DISCRSP_IS_SATA_DEVICE(pDiscoverResp))
1232 /* incremental discovery */
1233 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_FULL_START)
1235 AttachedDevice = dmPortSASDeviceAdd(
1241 dmAllShared->itNexusTimeout,
1246 pDiscoverResp->phyIdentifier
1251 /* incremental discovery */
1252 AttachedDevice = dmFindRegNValid(
1257 /* not registered and not valid; add this*/
1258 if (AttachedDevice == agNULL)
1260 AttachedDevice = dmPortSASDeviceAdd(
1266 dmAllShared->itNexusTimeout,
1271 pDiscoverResp->phyIdentifier
1278 /* incremental discovery */
1279 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_FULL_START)
1281 AttachedDevice = dmPortSASDeviceAdd(
1287 dmAllShared->itNexusTimeout,
1292 pDiscoverResp->phyIdentifier
1297 /* incremental discovery */
1298 AttachedDevice = dmFindRegNValid(
1303 /* not registered and not valid; add this*/
1304 if (AttachedDevice == agNULL)
1306 AttachedDevice = dmPortSASDeviceAdd(
1312 dmAllShared->itNexusTimeout,
1317 pDiscoverResp->phyIdentifier
1322 /* If the device is added successfully */
1323 if ( AttachedDevice != agNULL)
1326 /* (3.1.2.3.2.3.2.1) callback about new device */
1327 if ( SAS2_DISCRSP_IS_SSP_TARGET(pDiscoverResp)
1328 || SAS2_DISCRSP_IS_SSP_INITIATOR(pDiscoverResp)
1329 || SAS2_DISCRSP_IS_SMP_INITIATOR(pDiscoverResp)
1330 || SAS2_DISCRSP_IS_SMP_INITIATOR(pDiscoverResp) )
1332 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: Found SSP/SMP SAS %08x-%08x\n",
1333 attachedSasHi, attachedSasLo));
1337 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: Found a SAS STP device.\n"));
1339 /* If the attached device is an expander */
1340 if ( (SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_EDGE_EXPANDER_DEVICE)
1341 || (SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_FANOUT_EXPANDER_DEVICE) )
1343 /* Allocate an expander data structure */
1344 AttachedExpander = dmDiscoveringExpanderAlloc(
1350 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: Found expander=%p\n", AttachedExpander));
1351 /* If allocate successfully */
1352 if ( AttachedExpander != agNULL)
1354 /* Add the pAttachedExpander to discovering list */
1355 dmDiscoveringExpanderAdd(dmRoot, onePortContext, AttachedExpander);
1356 /* Setup upstream expander for the pExpander */
1357 oneExpander->dmUpStreamExpander = AttachedExpander;
1359 /* If failed to allocate */
1362 DM_DBG1(("dmUpStreamDiscover2ExpanderPhy, Failed to allocate expander data structure!!!\n"));
1363 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1366 /* If the attached device is an end device */
1369 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: Found end device\n"));
1370 /* LP2006-05-26 added upstream device to the newly found device */
1371 AttachedDevice->dmExpander = oneExpander;
1372 oneExpander->dmUpStreamExpander = agNULL;
1377 DM_DBG1(("dmUpStreamDiscover2ExpanderPhy, Failed to add a device!!!\n"));
1378 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1383 } /* substractive routing */
1387 oneExpander->discoveringPhyId ++;
1388 if (onePortContext->discovery.status == DISCOVERY_UP_STREAM)
1390 if ( oneExpander->discoveringPhyId < oneDeviceData->numOfPhys )
1392 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: DISCOVERY_UP_STREAM find more ...\n"));
1393 /* continue discovery for the next phy */
1394 dmDiscoverSend(dmRoot, oneDeviceData);
1398 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: DISCOVERY_UP_STREAM last phy continue upstream..\n"));
1401 dmUpdateAllAdjacent(dmRoot, onePortContext, oneDeviceData);
1402 /* remove the expander from the discovering list */
1403 dmDiscoveringExpanderRemove(dmRoot, onePortContext, oneExpander);
1404 /* continue upstream discovering */
1405 dmUpStreamDiscovering(dmRoot, onePortContext, oneDeviceData);
1410 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: onePortContext->discovery.status not in DISCOVERY_UP_STREAM; status %d\n", onePortContext->discovery.status));
1414 DM_DBG2(("dmUpStreamDiscover2ExpanderPhy: end return phyID#%d\n", oneExpander->discoveringPhyId - 1));
1421 dmDownStreamDiscoverExpanderPhy(
1423 dmIntPortContext_t *onePortContext,
1424 dmExpander_t *oneExpander,
1425 smpRespDiscover_t *pDiscoverResp
1428 agsaSASIdentify_t sasIdentify;
1429 dmSASSubID_t dmSASSubID;
1430 bit32 attachedSasHi, attachedSasLo;
1431 dmExpander_t *AttachedExpander;
1432 dmExpander_t *UpStreamExpander;
1433 dmExpander_t *ConfigurableExpander = agNULL;
1434 bit8 connectionRate, negotiatedPhyLinkRate;
1435 bit32 configSASAddressHi;
1436 bit32 configSASAddressLo;
1437 bit32 dupConfigSASAddr = agFALSE;
1438 dmDeviceData_t *oneDeviceData;
1439 dmDeviceData_t *AttachedDevice = agNULL;
1440 bit32 SAS2SAS11Check = agFALSE;
1441 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
1442 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
1446 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: start\n"));
1447 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: exp addrHi 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressHi));
1448 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: exp addrLo 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressLo));
1450 DM_ASSERT(dmRoot, "(dmDownStreamDiscoverExpanderPhy) dmRoot NULL");
1451 DM_ASSERT(onePortContext, "(dmDownStreamDiscoverExpanderPhy) pPort NULL");
1452 DM_ASSERT(oneExpander, "(dmDownStreamDiscoverExpanderPhy) pExpander NULL");
1453 DM_ASSERT(pDiscoverResp, "(dmDownStreamDiscoverExpanderPhy) pDiscoverResp NULL");
1455 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: onePortContxt=%p oneExpander=%p\n", onePortContext, oneExpander));
1457 if (dmDiscoverCheck(dmRoot, onePortContext) == agTRUE)
1459 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: invalid port or aborted discovery!!!\n"));
1463 if (oneExpander != oneExpander->dmDevice->dmExpander)
1465 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: wrong!!!\n"));
1468 /* (1) Find the device structure of the expander */
1469 oneDeviceData = oneExpander->dmDevice;
1471 DM_ASSERT(oneDeviceData, "(dmDownStreamDiscoverExpanderPhy) pDevice NULL");
1474 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: Phy #%d of SAS %08x-%08x\n",
1475 oneExpander->discoveringPhyId,
1476 oneDeviceData->SASAddressID.sasAddressHi,
1477 oneDeviceData->SASAddressID.sasAddressLo));
1479 DM_DBG3((" Attached device: %s\n",
1480 ( DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == 0 ? "No Device" :
1481 (DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == 1 ? "End Device" :
1482 (DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == 2 ? "Edge Expander" : "Fanout Expander")))));
1486 if (oneExpander->discoveringPhyId != pDiscoverResp->phyIdentifier)
1488 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: !!! Incorrect SMP response !!!\n"));
1489 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: Request PhyID #%d Response PhyID #%d !!!\n", oneExpander->discoveringPhyId, pDiscoverResp->phyIdentifier));
1490 dmhexdump("NO_DEVICE", (bit8*)pDiscoverResp, sizeof(smpRespDiscover_t));
1491 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1495 if ( DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) != SAS_NO_DEVICE)
1497 DM_DBG3((" SAS address : %08x-%08x\n",
1498 DISCRSP_GET_ATTACHED_SAS_ADDRESSHI(pDiscoverResp),
1499 DISCRSP_GET_ATTACHED_SAS_ADDRESSLO(pDiscoverResp)));
1500 DM_DBG3((" SSP Target : %d\n", DISCRSP_IS_SSP_TARGET(pDiscoverResp)?1:0));
1501 DM_DBG3((" STP Target : %d\n", DISCRSP_IS_STP_TARGET(pDiscoverResp)?1:0));
1502 DM_DBG3((" SMP Target : %d\n", DISCRSP_IS_SMP_TARGET(pDiscoverResp)?1:0));
1503 DM_DBG3((" SATA DEVICE : %d\n", DISCRSP_IS_SATA_DEVICE(pDiscoverResp)?1:0));
1504 DM_DBG3((" SSP Initiator : %d\n", DISCRSP_IS_SSP_INITIATOR(pDiscoverResp)?1:0));
1505 DM_DBG3((" STP Initiator : %d\n", DISCRSP_IS_STP_INITIATOR(pDiscoverResp)?1:0));
1506 DM_DBG3((" SMP Initiator : %d\n", DISCRSP_IS_SMP_INITIATOR(pDiscoverResp)?1:0));
1507 DM_DBG3((" Phy ID : %d\n", pDiscoverResp->phyIdentifier));
1508 DM_DBG3((" Attached Phy ID: %d\n", pDiscoverResp->attachedPhyIdentifier));
1511 /* end for debugging */
1513 /* saving routing attribute for non self-configuring expanders */
1514 oneExpander->routingAttribute[pDiscoverResp->phyIdentifier] = DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp);
1516 oneExpander->discoverSMPAllowed = agTRUE;
1518 /* If a device is attached */
1519 if ( DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) != SAS_NO_DEVICE)
1521 /* Setup sasIdentify for the attached device */
1522 sasIdentify.phyIdentifier = pDiscoverResp->phyIdentifier;
1523 sasIdentify.deviceType_addressFrameType = pDiscoverResp->attachedDeviceType & 0x70;
1524 sasIdentify.initiator_ssp_stp_smp = pDiscoverResp->attached_Ssp_Stp_Smp_Sata_Initiator;
1525 sasIdentify.target_ssp_stp_smp = pDiscoverResp->attached_SataPS_Ssp_Stp_Smp_Sata_Target;
1526 *(bit32*)sasIdentify.sasAddressHi = *(bit32*)pDiscoverResp->attachedSasAddressHi;
1527 *(bit32*)sasIdentify.sasAddressLo = *(bit32*)pDiscoverResp->attachedSasAddressLo;
1529 /* incremental discovery */
1530 dmSASSubID.sasAddressHi = SA_IDFRM_GET_SAS_ADDRESSHI(&sasIdentify);
1531 dmSASSubID.sasAddressLo = SA_IDFRM_GET_SAS_ADDRESSLO(&sasIdentify);
1532 dmSASSubID.initiator_ssp_stp_smp = sasIdentify.initiator_ssp_stp_smp;
1533 dmSASSubID.target_ssp_stp_smp = sasIdentify.target_ssp_stp_smp;
1535 attachedSasHi = DISCRSP_GET_ATTACHED_SAS_ADDRESSHI(pDiscoverResp);
1536 attachedSasLo = DISCRSP_GET_ATTACHED_SAS_ADDRESSLO(pDiscoverResp);
1538 /* If it's a direct routing */
1539 if ( DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_DIRECT)
1541 /* If the attached device is an expander */
1542 if ( (DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_FANOUT_EXPANDER_DEVICE)
1543 || (DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_EDGE_EXPANDER_DEVICE) )
1546 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: **** Topology Error direct routing can't connect to expander!!!\n"));
1547 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
1548 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
1549 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
1550 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
1551 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
1552 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
1553 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
1554 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
1555 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
1557 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1562 /* If the expander's attached device is not myself */
1563 if ( (attachedSasHi != onePortContext->sasLocalAddressHi)
1564 || (attachedSasLo != onePortContext->sasLocalAddressLo) )
1566 /* Find the attached device from discovered list */
1567 AttachedDevice = dmPortSASDeviceFind(dmRoot, onePortContext, attachedSasLo, attachedSasHi, oneDeviceData);
1568 /* If the device has not been discovered before */
1569 if ( AttachedDevice == agNULL) //11
1571 /* If the phy has subtractive routing attribute */
1572 if ( DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_SUBTRACTIVE &&
1573 (DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_EDGE_EXPANDER_DEVICE ||
1574 DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_FANOUT_EXPANDER_DEVICE)
1577 /* TODO: discovery error, callback */
1578 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: Deferred!!! **** Topology Error subtractive routing error - inconsistent SAS address!!!\n"));
1579 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
1580 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
1581 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
1582 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
1583 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
1584 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
1585 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
1586 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
1587 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
1589 onePortContext->discovery.DeferredError = agTRUE;
1593 /* Add the device */
1594 /* read minimum rate from the configuration
1595 onePortContext->LinkRate is SPC's local link rate
1597 connectionRate = MIN(onePortContext->LinkRate, DISCRSP_GET_LINKRATE(pDiscoverResp));
1598 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: link rate 0x%x\n", DEVINFO_GET_LINKRATE(&oneDeviceData->agDeviceInfo)));
1599 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: negotiatedPhyLinkRate 0x%x\n", DISCRSP_GET_LINKRATE(pDiscoverResp)));
1600 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: connectionRate 0x%x\n", connectionRate));
1601 if (DISCRSP_IS_STP_TARGET(pDiscoverResp) || DISCRSP_IS_SATA_DEVICE(pDiscoverResp))
1603 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_FULL_START)
1605 AttachedDevice = dmPortSASDeviceAdd(
1611 dmAllShared->itNexusTimeout,
1616 pDiscoverResp->phyIdentifier
1621 /* incremental discovery */
1622 AttachedDevice = dmFindRegNValid(
1627 /* not registered and not valid; add this*/
1628 if (AttachedDevice == agNULL)
1630 AttachedDevice = dmPortSASDeviceAdd(
1636 dmAllShared->itNexusTimeout,
1641 pDiscoverResp->phyIdentifier
1645 } /* DISCRSP_IS_STP_TARGET(pDiscoverResp) || DISCRSP_IS_SATA_DEVICE(pDiscoverResp) */
1648 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_FULL_START)
1650 AttachedDevice = dmPortSASDeviceAdd(
1656 dmAllShared->itNexusTimeout,
1661 pDiscoverResp->phyIdentifier
1666 /* incremental discovery */
1667 AttachedDevice = dmFindRegNValid(
1672 /* not registered and not valid; add this*/
1673 if (AttachedDevice == agNULL)
1675 AttachedDevice = dmPortSASDeviceAdd(
1681 dmAllShared->itNexusTimeout,
1686 pDiscoverResp->phyIdentifier
1691 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: newDevice pDevice=%p\n", AttachedDevice));
1692 /* If the device is added successfully */
1693 if ( AttachedDevice != agNULL)
1695 if ( SA_IDFRM_IS_SSP_TARGET(&sasIdentify)
1696 || SA_IDFRM_IS_SMP_TARGET(&sasIdentify)
1697 || SA_IDFRM_IS_SSP_INITIATOR(&sasIdentify)
1698 || SA_IDFRM_IS_SMP_INITIATOR(&sasIdentify) )
1700 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: Report a new SAS device !!\n"));
1705 if ( SA_IDFRM_IS_STP_TARGET(&sasIdentify) ||
1706 SA_IDFRM_IS_SATA_DEVICE(&sasIdentify) )
1709 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: Found an STP or SATA device.\n"));
1713 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: Found Other type of device.\n"));
1717 /* LP2006-05-26 added upstream device to the newly found device */
1718 AttachedDevice->dmExpander = oneExpander;
1719 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: AttachedDevice %p did %d\n", AttachedDevice, AttachedDevice->id));
1720 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: Attached oneExpander %p did %d\n", AttachedDevice->dmExpander, AttachedDevice->dmExpander->id));
1722 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: oneDeviceData %p did %d\n", oneDeviceData, oneDeviceData->id));
1723 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: oneExpander %p did %d\n", oneDeviceData->dmExpander, oneDeviceData->dmExpander->id));
1725 /* If the phy has table routing attribute */
1726 if ( DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_TABLE)
1728 /* If the attached device is a fan out expander */
1729 if ( DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_FANOUT_EXPANDER_DEVICE)
1731 /* TODO: discovery error, callback */
1732 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: **** Topology Error two table routing phys are connected!!!\n"));
1733 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
1734 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
1735 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
1736 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
1737 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
1738 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
1739 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
1740 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
1741 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
1742 /* discovery done */
1743 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1745 else if ( DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_EDGE_EXPANDER_DEVICE)
1747 /* Allocate an expander data structure */
1748 AttachedExpander = dmDiscoveringExpanderAlloc(dmRoot, onePortContext, AttachedDevice);
1750 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: Found a EDGE exp device.%p\n", AttachedExpander));
1751 /* If allocate successfully */
1752 if ( AttachedExpander != agNULL)
1754 /* set up downstream information on configurable expander */
1755 dmExpanderDownStreamPhyAdd(dmRoot, oneExpander, (bit8) oneExpander->discoveringPhyId);
1756 /* Setup upstream information */
1757 dmExpanderUpStreamPhyAdd(dmRoot, AttachedExpander, (bit8) oneExpander->discoveringPhyId);
1758 AttachedExpander->hasUpStreamDevice = agTRUE;
1759 AttachedExpander->upStreamSASAddressHi
1760 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
1761 AttachedExpander->upStreamSASAddressLo
1762 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
1763 AttachedExpander->dmUpStreamExpander = oneExpander;
1764 /* (2.3.2.2.2.2.2.2.2) Add the pAttachedExpander to discovering list */
1765 dmDiscoveringExpanderAdd(dmRoot, onePortContext, AttachedExpander);
1767 /* If failed to allocate */
1770 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: Failed to allocate expander data structure!!!\n"));
1771 /* discovery done */
1772 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1775 } /* DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_TABLE */
1776 /* If status is still DISCOVERY_DOWN_STREAM */
1777 if ( onePortContext->discovery.status == DISCOVERY_DOWN_STREAM)
1779 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: 1st before\n"));
1780 dmDumpAllUpExp(dmRoot, onePortContext, oneExpander);
1781 UpStreamExpander = oneExpander->dmUpStreamExpander;
1782 ConfigurableExpander = dmFindConfigurableExp(dmRoot, onePortContext, oneExpander);
1783 configSASAddressHi = DEVINFO_GET_SAS_ADDRESSHI(&AttachedDevice->agDeviceInfo);
1784 configSASAddressLo = DEVINFO_GET_SAS_ADDRESSLO(&AttachedDevice->agDeviceInfo);
1785 if (ConfigurableExpander)
1787 if ( (ConfigurableExpander->dmDevice->SASAddressID.sasAddressHi
1788 == DEVINFO_GET_SAS_ADDRESSHI(&AttachedDevice->agDeviceInfo)) &&
1789 (ConfigurableExpander->dmDevice->SASAddressID.sasAddressLo
1790 == DEVINFO_GET_SAS_ADDRESSLO(&AttachedDevice->agDeviceInfo))
1792 { /* directly attached between oneExpander and ConfigurableExpander */
1793 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: 1st before loc 1\n"));
1794 configSASAddressHi = oneExpander->dmDevice->SASAddressID.sasAddressHi;
1795 configSASAddressLo = oneExpander->dmDevice->SASAddressID.sasAddressLo;
1799 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: 1st before loc 2\n"));
1800 configSASAddressHi = DEVINFO_GET_SAS_ADDRESSHI(&AttachedDevice->agDeviceInfo);
1801 configSASAddressLo = DEVINFO_GET_SAS_ADDRESSLO(&AttachedDevice->agDeviceInfo);
1803 } /* if !ConfigurableExpander */
1805 dupConfigSASAddr = dmDuplicateConfigSASAddr(dmRoot,
1806 ConfigurableExpander,
1811 if ( ConfigurableExpander && dupConfigSASAddr == agFALSE)
1813 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: 1st q123\n"));
1814 UpStreamExpander->dmCurrentDownStreamExpander = oneExpander;
1815 ConfigurableExpander->currentDownStreamPhyIndex =
1816 dmFindCurrentDownStreamPhyIndex(dmRoot, ConfigurableExpander);
1817 ConfigurableExpander->dmReturnginExpander = oneExpander;
1818 dmRoutingEntryAdd(dmRoot,
1819 ConfigurableExpander,
1820 ConfigurableExpander->downStreamPhys[ConfigurableExpander->currentDownStreamPhyIndex],
1825 } /* onePortContext->discovery.status == DISCOVERY_DOWN_STREAM */
1826 } /* AttachedDevice != agNULL */
1827 /* If fail to add the device */
1830 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: Failed to add a device!!!\n"));
1831 /* discovery done */
1832 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1835 } /* AttachedDevice == agNULL */
1836 /* If the device has been discovered before */
1837 else /* haha discovered before 33 */
1839 /* If the phy has subtractive routing attribute */
1840 if ( DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_SUBTRACTIVE)
1842 /* If the expander doesn't have up stream device */
1843 if ( oneExpander->hasUpStreamDevice == agFALSE)
1845 /* TODO: discovery error, callback */
1846 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: **** Topology Error loop, or end device connects to two expanders!!!\n"));
1847 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
1848 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
1849 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
1850 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
1851 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
1852 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
1853 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
1854 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
1855 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
1856 /* discovery done */
1857 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1859 /* If the expander has up stream device */
1862 /* If sas address doesn't match */
1863 if ( (oneExpander->upStreamSASAddressHi != attachedSasHi)
1864 || (oneExpander->upStreamSASAddressLo != attachedSasLo) )
1866 /* TODO: discovery error, callback */
1867 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: **** Topology Error two subtractive phys!!!\n"));
1868 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
1869 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
1870 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
1871 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
1872 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
1873 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
1874 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
1875 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
1876 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
1877 /* discovery done */
1878 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1881 } /* DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_SUBTRACTIVE */
1882 /* If the phy has table routing attribute */
1883 else if ( DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_TABLE)
1885 /* If the attached device is a fan out expander */
1886 if ( DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_FANOUT_EXPANDER_DEVICE)
1888 /* (2.3.3.2.1.1) TODO: discovery error, callback */
1889 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: **** Topology Error fan out expander to routing table phy!!!\n"));
1890 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
1891 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
1892 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
1893 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
1894 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
1895 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
1896 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
1897 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
1898 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
1899 /* discovery done */
1900 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1902 /* If the attached device is an edge expander */
1903 else if ( DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_EDGE_EXPANDER_DEVICE)
1905 /* Setup up stream inform */
1906 AttachedExpander = AttachedDevice->dmExpander;
1907 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: Found edge expander=%p\n", AttachedExpander));
1908 /* If the attached expander has up stream device */
1909 if ( AttachedExpander->hasUpStreamDevice == agTRUE)
1911 /* compare the sas address */
1912 if ( (AttachedExpander->upStreamSASAddressHi
1913 != DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo))
1914 || (AttachedExpander->upStreamSASAddressLo
1915 != DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo)))
1917 /* TODO: discovery error, callback */
1918 SAS2SAS11Check = dmSAS2SAS11ErrorCheck(dmRoot, onePortContext, AttachedExpander, oneExpander, oneExpander);
1919 if (SAS2SAS11Check == agTRUE)
1921 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: **** Topology Error SAS2 and SAS1.1!!!\n"));
1925 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: **** Topology Error two table routing phys connected (1)!!!\n"));
1927 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
1928 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
1929 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
1930 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
1931 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
1932 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
1933 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
1934 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
1935 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
1936 /* discovery done */
1937 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1941 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: Add edge expander=%p\n", AttachedExpander));
1942 /* set up downstream information on configurable expander */
1944 dmExpanderDownStreamPhyAdd(dmRoot, oneExpander, (bit8) oneExpander->discoveringPhyId);
1946 dmExpanderUpStreamPhyAdd(dmRoot, AttachedExpander, (bit8) oneExpander->discoveringPhyId);
1947 /* Add the pAttachedExpander to discovering list */
1948 dmDiscoveringExpanderAdd(dmRoot, onePortContext, AttachedExpander);
1950 } /* AttachedExpander->hasUpStreamDevice == agTRUE */
1951 /* If the attached expander doesn't have up stream device */
1954 /* TODO: discovery error, callback */
1955 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: **** Topology Error two table routing phys connected (2)!!!\n"));
1956 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
1957 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
1958 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
1959 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
1960 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
1961 DM_DBG1(("dmDownStreamDiscoverExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
1962 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
1963 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
1964 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
1965 /* discovery done */
1966 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
1968 } /* DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_EDGE_EXPANDER_DEVICE */
1969 } /* DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_TABLE */
1970 /* do this regradless of sub or table */
1971 /* If status is still DISCOVERY_DOWN_STREAM */
1972 if ( onePortContext->discovery.status == DISCOVERY_DOWN_STREAM)
1974 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: 2nd before\n"));
1975 dmDumpAllUpExp(dmRoot, onePortContext, oneExpander);
1977 UpStreamExpander = oneExpander->dmUpStreamExpander;
1978 ConfigurableExpander = dmFindConfigurableExp(dmRoot, onePortContext, oneExpander);
1979 configSASAddressHi = DEVINFO_GET_SAS_ADDRESSHI(&AttachedDevice->agDeviceInfo);
1980 configSASAddressLo = DEVINFO_GET_SAS_ADDRESSLO(&AttachedDevice->agDeviceInfo);
1981 if (ConfigurableExpander)
1983 if ( (ConfigurableExpander->dmDevice->SASAddressID.sasAddressHi
1984 == DEVINFO_GET_SAS_ADDRESSHI(&AttachedDevice->agDeviceInfo)) &&
1985 (ConfigurableExpander->dmDevice->SASAddressID.sasAddressLo
1986 == DEVINFO_GET_SAS_ADDRESSLO(&AttachedDevice->agDeviceInfo))
1988 { /* directly attached between oneExpander and ConfigurableExpander */
1989 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: 2nd before loc 1\n"));
1990 configSASAddressHi = oneExpander->dmDevice->SASAddressID.sasAddressHi;
1991 configSASAddressLo = oneExpander->dmDevice->SASAddressID.sasAddressLo;
1995 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: 2nd before loc 2\n"));
1996 configSASAddressHi = DEVINFO_GET_SAS_ADDRESSHI(&AttachedDevice->agDeviceInfo);
1997 configSASAddressLo = DEVINFO_GET_SAS_ADDRESSLO(&AttachedDevice->agDeviceInfo);
1999 } /* if !ConfigurableExpander */
2000 dupConfigSASAddr = dmDuplicateConfigSASAddr(dmRoot,
2001 ConfigurableExpander,
2005 if ( ConfigurableExpander && dupConfigSASAddr == agFALSE)
2007 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: 2nd q123 \n"));
2008 UpStreamExpander->dmCurrentDownStreamExpander = oneExpander;
2009 ConfigurableExpander->currentDownStreamPhyIndex =
2010 dmFindCurrentDownStreamPhyIndex(dmRoot, ConfigurableExpander);
2011 ConfigurableExpander->dmReturnginExpander = oneExpander;
2012 dmRoutingEntryAdd(dmRoot,
2013 ConfigurableExpander,
2014 ConfigurableExpander->downStreamPhys[ConfigurableExpander->currentDownStreamPhyIndex],
2019 } /* onePortContext->discovery.status == DISCOVERY_DOWN_STREAM */
2020 /* incremental discovery */
2021 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_INCREMENTAL_START)
2023 connectionRate = MIN(onePortContext->LinkRate, DISCRSP_GET_LINKRATE(pDiscoverResp));
2025 if (DISCRSP_IS_STP_TARGET(pDiscoverResp) || DISCRSP_IS_SATA_DEVICE(pDiscoverResp))
2027 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: incremental SATA_STP\n"));
2035 dmAllShared->itNexusTimeout,
2040 pDiscoverResp->phyIdentifier
2045 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: incremental SAS\n"));
2054 dmAllShared->itNexusTimeout,
2059 pDiscoverResp->phyIdentifier
2063 } /* onePortContext->discovery.type == DM_DISCOVERY_OPTION_INCREMENTAL_START */
2065 } /* (attachedSasLo != onePortContext->sasLocalAddressLo) */
2069 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: Found Self\n"));
2070 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: 3rd before\n"));
2071 dmDumpAllUpExp(dmRoot, onePortContext, oneExpander);
2073 UpStreamExpander = oneExpander->dmUpStreamExpander;
2074 ConfigurableExpander = dmFindConfigurableExp(dmRoot, onePortContext, oneExpander);
2075 dupConfigSASAddr = dmDuplicateConfigSASAddr(dmRoot,
2076 ConfigurableExpander,
2077 onePortContext->sasLocalAddressHi,
2078 onePortContext->sasLocalAddressLo
2081 if ( ConfigurableExpander && dupConfigSASAddr == agFALSE)
2083 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: 3rd q123 Setup routing table\n"));
2084 UpStreamExpander->dmCurrentDownStreamExpander = oneExpander;
2085 ConfigurableExpander->currentDownStreamPhyIndex =
2086 dmFindCurrentDownStreamPhyIndex(dmRoot, ConfigurableExpander);
2087 ConfigurableExpander->dmReturnginExpander = oneExpander;
2088 dmRoutingEntryAdd(dmRoot,
2089 ConfigurableExpander,
2090 ConfigurableExpander->downStreamPhys[ConfigurableExpander->currentDownStreamPhyIndex],
2091 onePortContext->sasLocalAddressHi,
2092 onePortContext->sasLocalAddressLo
2096 } /* DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) != SAS_NO_DEVICE */
2097 /* If no device is attached */
2101 DM_DBG2(("!!!!!!!!!!!!!!!!!!!!! SPIN SATA !!!!!!!!!!!!!!!!!!!!!!!!!!!\n"));
2102 negotiatedPhyLinkRate = DISCRSP_GET_LINKRATE(pDiscoverResp); // added by thenil
2104 if (negotiatedPhyLinkRate == 0x03)
2107 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: SPIN SATA sent reset\n"));
2108 dmPhyControlSend(dmRoot,
2110 SMP_PHY_CONTROL_HARD_RESET,
2111 pDiscoverResp->phyIdentifier
2119 /* Increment the discovering phy id */
2120 oneExpander->discoveringPhyId ++;
2122 /* If the discovery status is DISCOVERY_DOWN_STREAM */
2123 if ( onePortContext->discovery.status == DISCOVERY_DOWN_STREAM )
2125 /* If not the last phy */
2126 if ( oneExpander->discoveringPhyId < oneDeviceData->numOfPhys )
2128 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: More Phys to discover\n"));
2129 /* continue discovery for the next phy */
2130 dmDiscoverSend(dmRoot, oneDeviceData);
2132 /* If the last phy */
2135 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: No More Phys\n"));
2138 dmUpdateAllAdjacent(dmRoot, onePortContext, oneDeviceData);
2139 /* remove the expander from the discovering list */
2140 dmDiscoveringExpanderRemove(dmRoot, onePortContext, oneExpander);
2141 /* continue downstream discovering */
2142 dmDownStreamDiscovering(dmRoot, onePortContext, oneDeviceData);
2147 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: onePortContext->discovery.status not in DISCOVERY_DOWN_STREAM; status %d\n", onePortContext->discovery.status));
2149 DM_DBG3(("dmDownStreamDiscoverExpanderPhy: end return phyID#%d\n", oneExpander->discoveringPhyId - 1));
2155 /* works at SAS2 expander (called in dmDownStreamDiscover2ExpanderPhy())
2156 if currentExpander is SAS2, called in dmDownStreamDiscover2ExpanderPhy()
2157 if currentExpander is SAS1.1, called in dmDownStreamDiscoverExpanderPhy()
2160 dmSAS2SAS11ErrorCheck(
2162 dmIntPortContext_t *onePortContext,
2163 dmExpander_t *topExpander,
2164 dmExpander_t *bottomExpander,
2165 dmExpander_t *currentExpander
2168 bit32 result = agFALSE, i = 0;
2169 bit8 downStreamPhyID, upStreamPhyID;
2171 DM_DBG2(("dmSAS2SAS11ErrorCheck: start\n"));
2173 if (topExpander == agNULL)
2175 DM_DBG2(("dmSAS2SAS11ErrorCheck: topExpander is NULL\n"));
2178 if (bottomExpander == agNULL)
2180 DM_DBG2(("dmSAS2SAS11ErrorCheck: bottomExpander is NULL\n"));
2184 if (currentExpander == agNULL)
2186 DM_DBG2(("dmSAS2SAS11ErrorCheck: currentExpander is NULL\n"));
2190 DM_DBG2(("dmSAS2SAS11ErrorCheck: topExpander addrHi 0x%08x addrLo 0x%08x\n",
2191 topExpander->dmDevice->SASAddressID.sasAddressHi, topExpander->dmDevice->SASAddressID.sasAddressLo));
2192 DM_DBG2(("dmSAS2SAS11ErrorCheck: bottomExpander addrHi 0x%08x addrLo 0x%08x\n",
2193 bottomExpander->dmDevice->SASAddressID.sasAddressHi, bottomExpander->dmDevice->SASAddressID.sasAddressLo));
2194 DM_DBG2(("dmSAS2SAS11ErrorCheck: currentExpander addrHi 0x%08x addrLo 0x%08x\n",
2195 currentExpander->dmDevice->SASAddressID.sasAddressHi, currentExpander->dmDevice->SASAddressID.sasAddressLo));
2197 for (i=0;i<DM_MAX_EXPANDER_PHYS;i++)
2199 downStreamPhyID = topExpander->downStreamPhys[i];
2200 upStreamPhyID = bottomExpander->upStreamPhys[i];
2201 if (currentExpander->SAS2 == 1)
2203 if ( downStreamPhyID == upStreamPhyID &&
2204 topExpander->routingAttribute[downStreamPhyID] == SAS_ROUTING_TABLE &&
2205 bottomExpander->routingAttribute[i] == SAS_ROUTING_SUBTRACTIVE &&
2206 topExpander->SAS2 == 0 &&
2207 bottomExpander->SAS2 == 1
2214 else if (currentExpander->SAS2 == 0)
2216 if ( downStreamPhyID == upStreamPhyID &&
2217 topExpander->routingAttribute[downStreamPhyID] == SAS_ROUTING_SUBTRACTIVE &&
2218 bottomExpander->routingAttribute[i] == SAS_ROUTING_TABLE &&
2219 topExpander->SAS2 == 1 &&
2220 bottomExpander->SAS2 == 0
2232 dmDownStreamDiscover2ExpanderPhy(
2234 dmIntPortContext_t *onePortContext,
2235 dmExpander_t *oneExpander,
2236 smpRespDiscover2_t *pDiscoverResp
2239 dmDeviceData_t *oneDeviceData;
2240 dmExpander_t *UpStreamExpander;
2241 dmDeviceData_t *AttachedDevice = agNULL;
2242 dmExpander_t *AttachedExpander;
2243 agsaSASIdentify_t sasIdentify;
2244 bit8 connectionRate;
2245 bit32 attachedSasHi, attachedSasLo;
2246 dmSASSubID_t dmSASSubID;
2247 dmExpander_t *ConfigurableExpander = agNULL;
2248 bit32 dupConfigSASAddr = agFALSE;
2249 bit32 configSASAddressHi;
2250 bit32 configSASAddressLo;
2251 bit32 SAS2SAS11Check = agFALSE;
2252 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
2253 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
2256 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: start\n"));
2257 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: exp addrHi 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressHi));
2258 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: exp addrLo 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressLo));
2260 DM_ASSERT(dmRoot, "(dmDownStreamDiscover2ExpanderPhy) dmRoot NULL");
2261 DM_ASSERT(onePortContext, "(dmDownStreamDiscover2ExpanderPhy) pPort NULL");
2262 DM_ASSERT(oneExpander, "(dmDownStreamDiscover2ExpanderPhy) pExpander NULL");
2263 DM_ASSERT(pDiscoverResp, "(dmDownStreamDiscover2ExpanderPhy) pDiscoverResp NULL");
2265 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: onePortContxt=%p oneExpander=%p oneDeviceData=%p\n", onePortContext, oneExpander, oneExpander->dmDevice));
2267 if (dmDiscoverCheck(dmRoot, onePortContext) == agTRUE)
2269 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: invalid port or aborted discovery!!!\n"));
2273 if (oneExpander != oneExpander->dmDevice->dmExpander)
2275 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: wrong!!!\n"));
2279 /* (1) Find the device structure of the expander */
2280 oneDeviceData = oneExpander->dmDevice;
2282 DM_ASSERT(oneDeviceData, "(dmDownStreamDiscover2ExpanderPhy) pDevice NULL");
2285 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: Phy #%d of SAS %08x-%08x\n",
2286 oneExpander->discoveringPhyId,
2287 oneDeviceData->SASAddressID.sasAddressHi,
2288 oneDeviceData->SASAddressID.sasAddressLo));
2290 DM_DBG2((" Attached device: %s\n",
2291 ( SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == 0 ? "No Device" :
2292 (SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == 1 ? "End Device" :
2293 (SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == 2 ? "Edge Expander" : "Fanout Expander")))));
2297 if (oneExpander->discoveringPhyId != pDiscoverResp->phyIdentifier)
2299 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: !!! Incorrect SMP response !!!\n"));
2300 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: Request PhyID #%d Response PhyID #%d\n", oneExpander->discoveringPhyId, pDiscoverResp->phyIdentifier));
2301 dmhexdump("NO_DEVICE", (bit8*)pDiscoverResp, sizeof(smpRespDiscover2_t));
2302 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
2306 if ( SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) != SAS_NO_DEVICE)
2308 DM_DBG2((" SAS address : %08x-%08x\n",
2309 SAS2_DISCRSP_GET_ATTACHED_SAS_ADDRESSHI(pDiscoverResp),
2310 SAS2_DISCRSP_GET_ATTACHED_SAS_ADDRESSLO(pDiscoverResp)));
2311 DM_DBG2((" SSP Target : %d\n", SAS2_DISCRSP_IS_SSP_TARGET(pDiscoverResp)?1:0));
2312 DM_DBG2((" STP Target : %d\n", SAS2_DISCRSP_IS_STP_TARGET(pDiscoverResp)?1:0));
2313 DM_DBG2((" SMP Target : %d\n", SAS2_DISCRSP_IS_SMP_TARGET(pDiscoverResp)?1:0));
2314 DM_DBG2((" SATA DEVICE : %d\n", SAS2_DISCRSP_IS_SATA_DEVICE(pDiscoverResp)?1:0));
2315 DM_DBG2((" SSP Initiator : %d\n", SAS2_DISCRSP_IS_SSP_INITIATOR(pDiscoverResp)?1:0));
2316 DM_DBG2((" STP Initiator : %d\n", SAS2_DISCRSP_IS_STP_INITIATOR(pDiscoverResp)?1:0));
2317 DM_DBG2((" SMP Initiator : %d\n", SAS2_DISCRSP_IS_SMP_INITIATOR(pDiscoverResp)?1:0));
2318 DM_DBG2((" Phy ID : %d\n", pDiscoverResp->phyIdentifier));
2319 DM_DBG2((" Attached Phy ID: %d\n", pDiscoverResp->attachedPhyIdentifier));
2323 /* saving routing attribute for non self-configuring expanders */
2324 oneExpander->routingAttribute[pDiscoverResp->phyIdentifier] = SAS2_DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp);
2327 oneExpander->discoverSMPAllowed = agTRUE;
2329 /* If a device is attached */
2330 if ( SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) != SAS_NO_DEVICE)
2332 /* Setup sasIdentify for the attached device */
2333 sasIdentify.phyIdentifier = pDiscoverResp->phyIdentifier;
2334 sasIdentify.deviceType_addressFrameType = pDiscoverResp->attachedDeviceTypeReason & 0x70;
2335 sasIdentify.initiator_ssp_stp_smp = pDiscoverResp->attached_Ssp_Stp_Smp_Sata_Initiator;
2336 sasIdentify.target_ssp_stp_smp = pDiscoverResp->attached_SataPS_Ssp_Stp_Smp_Sata_Target;
2337 *(bit32*)sasIdentify.sasAddressHi = *(bit32*)pDiscoverResp->attachedSasAddressHi;
2338 *(bit32*)sasIdentify.sasAddressLo = *(bit32*)pDiscoverResp->attachedSasAddressLo;
2340 /* incremental discovery */
2341 dmSASSubID.sasAddressHi = SA_IDFRM_GET_SAS_ADDRESSHI(&sasIdentify);
2342 dmSASSubID.sasAddressLo = SA_IDFRM_GET_SAS_ADDRESSLO(&sasIdentify);
2343 dmSASSubID.initiator_ssp_stp_smp = sasIdentify.initiator_ssp_stp_smp;
2344 dmSASSubID.target_ssp_stp_smp = sasIdentify.target_ssp_stp_smp;
2346 attachedSasHi = SAS2_DISCRSP_GET_ATTACHED_SAS_ADDRESSHI(pDiscoverResp);
2347 attachedSasLo = SAS2_DISCRSP_GET_ATTACHED_SAS_ADDRESSLO(pDiscoverResp);
2349 /* If it's a direct routing */
2350 if ( SAS2_DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_DIRECT)
2352 /* If the attached device is an expander */
2353 if ( (SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_FANOUT_EXPANDER_DEVICE)
2354 || (SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_EDGE_EXPANDER_DEVICE) )
2357 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: **** Topology Error direct routing can't connect to expander!!!\n"));
2358 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
2359 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
2360 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
2361 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
2362 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
2364 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
2365 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
2366 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
2367 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
2368 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
2374 /* If the expander's attached device is not myself */
2375 if ( (attachedSasHi != onePortContext->sasLocalAddressHi)
2376 || (attachedSasLo != onePortContext->sasLocalAddressLo) )
2378 /* Find the attached device from discovered list */
2379 AttachedDevice = dmPortSASDeviceFind(dmRoot, onePortContext, attachedSasLo, attachedSasHi, oneDeviceData);
2380 /* If the device has not been discovered before */
2381 if ( AttachedDevice == agNULL) //11
2386 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: **** Topology Error subtractive routing error - inconsistent SAS address!!!\n"));
2387 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
2388 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
2389 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
2390 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
2391 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
2392 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
2393 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
2394 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
2395 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
2396 /* discovery done */
2397 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
2401 /* Add the device */
2402 /* read minimum rate from the configuration
2403 onePortContext->LinkRate is SPC's local link rate
2405 connectionRate = MIN(onePortContext->LinkRate, SAS2_DISCRSP_GET_LOGICAL_LINKRATE(pDiscoverResp));
2406 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: link rate 0x%x\n", DEVINFO_GET_LINKRATE(&oneDeviceData->agDeviceInfo)));
2407 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: negotiatedPhyLinkRate 0x%x\n", SAS2_DISCRSP_GET_LINKRATE(pDiscoverResp)));
2408 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: connectionRate 0x%x\n", connectionRate));
2410 if (SAS2_DISCRSP_IS_STP_TARGET(pDiscoverResp) || SAS2_DISCRSP_IS_SATA_DEVICE(pDiscoverResp))
2412 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_FULL_START)
2414 AttachedDevice = dmPortSASDeviceAdd(
2420 dmAllShared->itNexusTimeout,
2425 pDiscoverResp->phyIdentifier
2430 /* incremental discovery */
2431 AttachedDevice = dmFindRegNValid(
2436 /* not registered and not valid; add this*/
2437 if (AttachedDevice == agNULL)
2439 AttachedDevice = dmPortSASDeviceAdd(
2445 dmAllShared->itNexusTimeout,
2450 pDiscoverResp->phyIdentifier
2457 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_FULL_START)
2459 AttachedDevice = dmPortSASDeviceAdd(
2465 dmAllShared->itNexusTimeout,
2470 pDiscoverResp->phyIdentifier
2475 /* incremental discovery */
2476 AttachedDevice = dmFindRegNValid(
2481 /* not registered and not valid; add this*/
2482 if (AttachedDevice == agNULL)
2484 AttachedDevice = dmPortSASDeviceAdd(
2490 dmAllShared->itNexusTimeout,
2495 pDiscoverResp->phyIdentifier
2500 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: newDevice pDevice=%p\n", AttachedDevice));
2501 /* If the device is added successfully */
2502 if ( AttachedDevice != agNULL)
2504 if ( SA_IDFRM_IS_SSP_TARGET(&sasIdentify)
2505 || SA_IDFRM_IS_SMP_TARGET(&sasIdentify)
2506 || SA_IDFRM_IS_SSP_INITIATOR(&sasIdentify)
2507 || SA_IDFRM_IS_SMP_INITIATOR(&sasIdentify) )
2509 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: Report a new SAS device !!\n"));
2514 if ( SA_IDFRM_IS_STP_TARGET(&sasIdentify) ||
2515 SA_IDFRM_IS_SATA_DEVICE(&sasIdentify) )
2518 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: Found an STP or SATA device.\n"));
2522 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: Found Other type of device.\n"));
2526 /* LP2006-05-26 added upstream device to the newly found device */
2527 AttachedDevice->dmExpander = oneExpander;
2528 DM_DBG3(("dmDownStreamDiscover2ExpanderPhy: AttachedDevice %p did %d\n", AttachedDevice, AttachedDevice->id));
2529 DM_DBG3(("dmDownStreamDiscover2ExpanderPhy: Attached oneExpander %p did %d\n", AttachedDevice->dmExpander, AttachedDevice->dmExpander->id));
2531 DM_DBG3(("dmDownStreamDiscover2ExpanderPhy: oneDeviceData %p did %d\n", oneDeviceData, oneDeviceData->id));
2532 DM_DBG3(("dmDownStreamDiscover2ExpanderPhy: oneExpander %p did %d\n", oneDeviceData->dmExpander, oneDeviceData->dmExpander->id));
2534 /* If the phy has table routing attribute */
2535 if ( SAS2_DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_TABLE)
2537 /* If the attached device is a fan out expander */
2538 if ( SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_FANOUT_EXPANDER_DEVICE)
2540 /* TODO: discovery error, callback */
2541 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: **** Topology Error two table routing phys are connected!!!\n"));
2542 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
2543 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
2544 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
2545 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
2546 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
2547 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
2548 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
2549 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
2550 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
2551 /* discovery done */
2552 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
2554 else if ( SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_EDGE_EXPANDER_DEVICE)
2556 /* Allocate an expander data structure */
2557 AttachedExpander = dmDiscoveringExpanderAlloc(dmRoot, onePortContext, AttachedDevice);
2559 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: Found a EDGE exp device.%p\n", AttachedExpander));
2560 /* If allocate successfully */
2561 if ( AttachedExpander != agNULL)
2563 /* set up downstream information on configurable expander */
2565 dmExpanderDownStreamPhyAdd(dmRoot, oneExpander, (bit8) oneExpander->discoveringPhyId);
2567 /* Setup upstream information */
2568 dmExpanderUpStreamPhyAdd(dmRoot, AttachedExpander, (bit8) oneExpander->discoveringPhyId);
2570 AttachedExpander->hasUpStreamDevice = agTRUE;
2571 AttachedExpander->upStreamSASAddressHi
2572 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
2573 AttachedExpander->upStreamSASAddressLo
2574 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
2575 AttachedExpander->dmUpStreamExpander = oneExpander;
2576 /* (2.3.2.2.2.2.2.2.2) Add the pAttachedExpander to discovering list */
2577 dmDiscoveringExpanderAdd(dmRoot, onePortContext, AttachedExpander);
2579 /* If failed to allocate */
2582 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy, Failed to allocate expander data structure!!!\n"));
2583 /* discovery done */
2584 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
2589 else if ( SAS2_DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_SUBTRACTIVE &&
2590 (SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_FANOUT_EXPANDER_DEVICE ||
2591 SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_EDGE_EXPANDER_DEVICE)
2594 /* Allocate an expander data structure */
2595 AttachedExpander = dmDiscoveringExpanderAlloc(dmRoot, onePortContext, AttachedDevice);
2597 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: Found a EDGE/FANOUT exp device.%p\n", AttachedExpander));
2598 /* If allocate successfully */
2599 if ( AttachedExpander != agNULL)
2601 /* set up downstream information on configurable expander */
2602 dmExpanderDownStreamPhyAdd(dmRoot, oneExpander, (bit8) oneExpander->discoveringPhyId);
2604 /* Setup upstream information */
2605 dmExpanderUpStreamPhyAdd(dmRoot, AttachedExpander, (bit8) oneExpander->discoveringPhyId);
2606 AttachedExpander->hasUpStreamDevice = agTRUE;
2607 AttachedExpander->upStreamSASAddressHi
2608 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
2609 AttachedExpander->upStreamSASAddressLo
2610 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
2611 AttachedExpander->dmUpStreamExpander = oneExpander;
2612 /* (2.3.2.2.2.2.2.2.2) Add the pAttachedExpander to discovering list */
2613 dmDiscoveringExpanderAdd(dmRoot, onePortContext, AttachedExpander);
2615 /* If failed to allocate */
2618 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy, Failed to allocate expander data structure (2)!!!\n"));
2619 /* discovery done */
2620 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
2625 /* If status is still DISCOVERY_DOWN_STREAM */
2626 if ( onePortContext->discovery.status == DISCOVERY_DOWN_STREAM &&
2627 onePortContext->discovery.ConfiguresOthers == agFALSE)
2629 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: 1st before\n"));
2630 dmDumpAllUpExp(dmRoot, onePortContext, oneExpander);
2631 UpStreamExpander = oneExpander->dmUpStreamExpander;
2632 ConfigurableExpander = dmFindConfigurableExp(dmRoot, onePortContext, oneExpander);
2633 configSASAddressHi = DEVINFO_GET_SAS_ADDRESSHI(&AttachedDevice->agDeviceInfo);
2634 configSASAddressLo = DEVINFO_GET_SAS_ADDRESSLO(&AttachedDevice->agDeviceInfo);
2635 if (ConfigurableExpander)
2637 if ( (ConfigurableExpander->dmDevice->SASAddressID.sasAddressHi
2638 == DEVINFO_GET_SAS_ADDRESSHI(&AttachedDevice->agDeviceInfo)) &&
2639 (ConfigurableExpander->dmDevice->SASAddressID.sasAddressLo
2640 == DEVINFO_GET_SAS_ADDRESSLO(&AttachedDevice->agDeviceInfo))
2642 { /* directly attached between oneExpander and ConfigurableExpander */
2643 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: 1st before loc 1\n"));
2644 configSASAddressHi = oneExpander->dmDevice->SASAddressID.sasAddressHi;
2645 configSASAddressLo = oneExpander->dmDevice->SASAddressID.sasAddressLo;
2649 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: 1st before loc 2\n"));
2650 configSASAddressHi = DEVINFO_GET_SAS_ADDRESSHI(&AttachedDevice->agDeviceInfo);
2651 configSASAddressLo = DEVINFO_GET_SAS_ADDRESSLO(&AttachedDevice->agDeviceInfo);
2653 } /* if !ConfigurableExpander */
2654 dupConfigSASAddr = dmDuplicateConfigSASAddr(dmRoot,
2655 ConfigurableExpander,
2661 if ( ConfigurableExpander && dupConfigSASAddr == agFALSE)
2663 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: 1st q123\n"));
2664 UpStreamExpander->dmCurrentDownStreamExpander = oneExpander;
2665 ConfigurableExpander->currentDownStreamPhyIndex =
2666 dmFindCurrentDownStreamPhyIndex(dmRoot, ConfigurableExpander);
2667 ConfigurableExpander->dmReturnginExpander = oneExpander;
2668 dmRoutingEntryAdd(dmRoot,
2669 ConfigurableExpander,
2670 ConfigurableExpander->downStreamPhys[ConfigurableExpander->currentDownStreamPhyIndex],
2677 /* If fail to add the device */
2680 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy, Failed to add a device!!!\n"));
2681 /* discovery done */
2682 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
2686 /* If the device has been discovered before */
2687 else /* discovered before */
2689 /* If the phy has subtractive routing attribute */
2690 if ( SAS2_DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_SUBTRACTIVE)
2692 /* If the expander doesn't have up stream device */
2693 if ( oneExpander->hasUpStreamDevice == agFALSE)
2695 /* TODO: discovery error, callback */
2696 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: **** Topology Error loop, or end device connects to two expanders!!!\n"));
2697 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
2698 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
2699 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
2700 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
2701 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
2702 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
2703 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
2704 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
2705 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
2706 /* discovery done */
2707 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
2709 /* If the expander has up stream device */
2714 /* If sas address doesn't match */
2715 if ( (oneExpander->upStreamSASAddressHi != attachedSasHi)
2716 || (oneExpander->upStreamSASAddressLo != attachedSasLo) )
2718 /* TODO: discovery error, callback */
2719 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: **** two subtractive phys!!! Allowed in SAS2!!!\n"));
2720 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
2721 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
2722 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
2723 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
2724 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
2725 onePortContext->discovery.DeferredError = agTRUE;
2730 /* If the phy has table routing attribute */
2731 else if ( SAS2_DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_TABLE)
2733 /* If the attached device is a fan out expander */
2734 if ( SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_FANOUT_EXPANDER_DEVICE)
2736 /* (2.3.3.2.1.1) TODO: discovery error, callback */
2737 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: **** Topology Error fan out expander to routing table phy!!!\n"));
2738 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
2739 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
2740 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
2741 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
2742 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
2743 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
2744 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
2745 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
2746 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
2747 /* discovery done */
2748 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
2750 /* If the attached device is an edge expander */
2751 else if ( SAS2_DISCRSP_GET_ATTACHED_DEVTYPE(pDiscoverResp) == SAS_EDGE_EXPANDER_DEVICE)
2753 /* Setup up stream inform */
2754 AttachedExpander = AttachedDevice->dmExpander;
2755 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: Found edge expander=%p\n", AttachedExpander));
2757 /* If the attached expander has up stream device */
2758 if ( AttachedExpander->hasUpStreamDevice == agTRUE)
2760 /* compare the sas address */
2761 if ( (AttachedExpander->upStreamSASAddressHi
2762 != DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo))
2763 || (AttachedExpander->upStreamSASAddressLo
2764 != DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo)))
2766 if (AttachedExpander->TTTSupported && oneExpander->TTTSupported)
2769 needs further error checking
2770 UpstreamExpanderOfAttachedExpander = AttachedExpander->UpStreamExpander
2771 for (i=0;i<DM_MAX_EXPANDER_PHYS;i++)
2773 if (UpstreamExpanderOfAttachedExpander->downStreamPhys[i] != 0 &&
2776 SAS2SAS11Check = dmSAS2SAS11ErrorCheck(dmRoot, onePortContext, AttachedExpander->dmUpStreamExpander, AttachedExpander, oneExpander);
2777 if (SAS2SAS11Check == agTRUE)
2780 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: **** Topology Error SAS2 and SAS1.1!!!\n"));
2781 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
2782 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
2783 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
2784 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
2785 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
2786 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
2787 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
2788 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
2789 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
2790 /* discovery done */
2791 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
2795 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: Allowed Table to Table (1)\n"));
2796 /* move on to the next phys but should be not proceed after oneExpander */
2797 oneExpander->UndoDueToTTTSupported = agTRUE;
2798 onePortContext->discovery.DeferredError = agFALSE;
2803 /* TODO: discovery error, callback */
2804 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: **** Topology Error two table routing phys connected (1)!!!\n"));
2805 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
2806 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
2807 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
2808 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
2809 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
2810 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
2811 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
2812 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
2813 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
2814 /* discovery done */
2815 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
2820 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: Add edge expander=%p\n", AttachedExpander));
2821 /* set up downstream information on configurable expander */
2823 dmExpanderDownStreamPhyAdd(dmRoot, oneExpander, (bit8) oneExpander->discoveringPhyId);
2825 dmExpanderUpStreamPhyAdd(dmRoot, AttachedExpander, (bit8) oneExpander->discoveringPhyId);
2826 /* Add the pAttachedExpander to discovering list */
2827 dmDiscoveringExpanderAdd(dmRoot, onePortContext, AttachedExpander);
2830 /* If the attached expander doesn't have up stream device */
2833 if (AttachedExpander->TTTSupported && oneExpander->TTTSupported)
2835 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: Allowed Table to Table (2)\n"));
2836 /* move on to the next phys but should be not proceed after oneExpander */
2837 oneExpander->UndoDueToTTTSupported = agTRUE;
2838 onePortContext->discovery.DeferredError = agFALSE;
2842 /* TODO: discovery error, callback */
2843 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: **** Topology Error two table routing phys connected (2)!!!\n"));
2844 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo
2845 = DEVINFO_GET_SAS_ADDRESSLO(&oneDeviceData->agDeviceInfo);
2846 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi
2847 = DEVINFO_GET_SAS_ADDRESSHI(&oneDeviceData->agDeviceInfo);
2848 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier = oneExpander->discoveringPhyId;
2849 DM_DBG1(("dmDownStreamDiscover2ExpanderPhy: sasAddressHi 0x%08x sasAddressLo 0x%08x phyid 0x%x\n",
2850 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressHi,
2851 onePortContext->discovery.sasAddressIDDiscoverError.sasAddressLo,
2852 onePortContext->discovery.sasAddressIDDiscoverError.phyIdentifier));
2853 /* discovery done */
2854 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
2858 } /* for else if (SAS2_DISCRSP_GET_ROUTINGATTRIB(pDiscoverResp) == SAS_ROUTING_TABLE) */
2860 /* do this regradless of sub or table */
2861 /* If status is still DISCOVERY_DOWN_STREAM */
2862 if ( onePortContext->discovery.status == DISCOVERY_DOWN_STREAM &&
2863 onePortContext->discovery.ConfiguresOthers == agFALSE)
2865 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: 2nd before\n"));
2866 dmDumpAllUpExp(dmRoot, onePortContext, oneExpander);
2868 UpStreamExpander = oneExpander->dmUpStreamExpander;
2869 ConfigurableExpander = dmFindConfigurableExp(dmRoot, onePortContext, oneExpander);
2870 configSASAddressHi = DEVINFO_GET_SAS_ADDRESSHI(&AttachedDevice->agDeviceInfo);
2871 configSASAddressLo = DEVINFO_GET_SAS_ADDRESSLO(&AttachedDevice->agDeviceInfo);
2872 if (ConfigurableExpander)
2874 if ( (ConfigurableExpander->dmDevice->SASAddressID.sasAddressHi
2875 == DEVINFO_GET_SAS_ADDRESSHI(&AttachedDevice->agDeviceInfo)) &&
2876 (ConfigurableExpander->dmDevice->SASAddressID.sasAddressLo
2877 == DEVINFO_GET_SAS_ADDRESSLO(&AttachedDevice->agDeviceInfo))
2879 { /* directly attached between oneExpander and ConfigurableExpander */
2880 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: 2nd before loc 1\n"));
2881 configSASAddressHi = oneExpander->dmDevice->SASAddressID.sasAddressHi;
2882 configSASAddressLo = oneExpander->dmDevice->SASAddressID.sasAddressLo;
2886 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: 2nd before loc 2\n"));
2887 configSASAddressHi = DEVINFO_GET_SAS_ADDRESSHI(&AttachedDevice->agDeviceInfo);
2888 configSASAddressLo = DEVINFO_GET_SAS_ADDRESSLO(&AttachedDevice->agDeviceInfo);
2890 } /* if !ConfigurableExpander */
2891 dupConfigSASAddr = dmDuplicateConfigSASAddr(dmRoot,
2892 ConfigurableExpander,
2897 if ( ConfigurableExpander && dupConfigSASAddr == agFALSE)
2899 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: 2nd q123 \n"));
2900 UpStreamExpander->dmCurrentDownStreamExpander = oneExpander;
2901 ConfigurableExpander->currentDownStreamPhyIndex =
2902 dmFindCurrentDownStreamPhyIndex(dmRoot, ConfigurableExpander);
2903 ConfigurableExpander->dmReturnginExpander = oneExpander;
2904 dmRoutingEntryAdd(dmRoot,
2905 ConfigurableExpander,
2906 ConfigurableExpander->downStreamPhys[ConfigurableExpander->currentDownStreamPhyIndex],
2911 } /* if (onePortContext->discovery.status == DISCOVERY_DOWN_STREAM) */
2912 /* incremental discovery */
2913 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_INCREMENTAL_START)
2915 connectionRate = MIN(onePortContext->LinkRate, SAS2_DISCRSP_GET_LOGICAL_LINKRATE(pDiscoverResp));
2917 if (SAS2_DISCRSP_IS_STP_TARGET(pDiscoverResp) || SAS2_DISCRSP_IS_SATA_DEVICE(pDiscoverResp))
2919 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: incremental SATA_STP\n"));
2927 dmAllShared->itNexusTimeout,
2932 pDiscoverResp->phyIdentifier
2937 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: incremental SAS\n"));
2945 dmAllShared->itNexusTimeout,
2950 pDiscoverResp->phyIdentifier
2957 }/* else; existing devce */
2958 } /* not attached to myself */
2959 /* If the attached device is myself */
2962 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: Found Self\n"));
2963 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: 3rd before\n"));
2964 dmDumpAllUpExp(dmRoot, onePortContext, oneExpander);
2966 if (onePortContext->discovery.ConfiguresOthers == agFALSE)
2968 UpStreamExpander = oneExpander->dmUpStreamExpander;
2969 ConfigurableExpander = dmFindConfigurableExp(dmRoot, onePortContext, oneExpander);
2970 dupConfigSASAddr = dmDuplicateConfigSASAddr(dmRoot,
2971 ConfigurableExpander,
2972 onePortContext->sasLocalAddressHi,
2973 onePortContext->sasLocalAddressLo
2976 if ( ConfigurableExpander && dupConfigSASAddr == agFALSE)
2978 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: 3rd q123 Setup routing table\n"));
2979 UpStreamExpander->dmCurrentDownStreamExpander = oneExpander;
2980 ConfigurableExpander->currentDownStreamPhyIndex =
2981 dmFindCurrentDownStreamPhyIndex(dmRoot, ConfigurableExpander);
2982 ConfigurableExpander->dmReturnginExpander = oneExpander;
2983 dmRoutingEntryAdd(dmRoot,
2984 ConfigurableExpander,
2985 ConfigurableExpander->downStreamPhys[ConfigurableExpander->currentDownStreamPhyIndex],
2986 onePortContext->sasLocalAddressHi,
2987 onePortContext->sasLocalAddressLo
2993 /* If no device is attached */
2999 /* Increment the discovering phy id */
3000 oneExpander->discoveringPhyId ++;
3002 /* If the discovery status is DISCOVERY_DOWN_STREAM */
3003 if ( onePortContext->discovery.status == DISCOVERY_DOWN_STREAM )
3005 /* If not the last phy */
3006 if ( oneExpander->discoveringPhyId < oneDeviceData->numOfPhys )
3008 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: More Phys to discover\n"));
3009 /* continue discovery for the next phy */
3010 dmDiscoverSend(dmRoot, oneDeviceData);
3012 /* If the last phy */
3015 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: No More Phys\n"));
3018 dmUpdateAllAdjacent(dmRoot, onePortContext, oneDeviceData);
3019 ConfigurableExpander = dmFindConfigurableExp(dmRoot, onePortContext, oneExpander);
3020 if (oneExpander->UndoDueToTTTSupported == agTRUE && ConfigurableExpander != agNULL)
3021 // if (oneExpander->UndoDueToTTTSupported == agTRUE)
3023 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: Not sure!!!\n"));
3024 dmDiscoveringUndoAdd(dmRoot, onePortContext, oneExpander);
3025 oneExpander->UndoDueToTTTSupported = agFALSE;
3028 /* remove the expander from the discovering list */
3029 dmDiscoveringExpanderRemove(dmRoot, onePortContext, oneExpander);
3030 /* continue downstream discovering */
3031 dmDownStreamDiscovering(dmRoot, onePortContext, oneDeviceData);
3036 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: onePortContext->discovery.status not in DISCOVERY_DOWN_STREAM; status %d\n", onePortContext->discovery.status));
3038 DM_DBG2(("dmDownStreamDiscover2ExpanderPhy: end return phyID#%d\n", oneExpander->discoveringPhyId - 1));
3045 dmDiscoveringUndoAdd(
3047 dmIntPortContext_t *onePortContext,
3048 dmExpander_t *oneExpander
3051 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
3052 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
3053 dmList_t *ExpanderList;
3054 dmExpander_t *tempExpander;
3055 dmIntPortContext_t *tmpOnePortContext = onePortContext;
3057 DM_DBG2(("dmDiscoveringUndoAdd: start\n"));
3058 if (DMLIST_EMPTY(&(tmpOnePortContext->discovery.discoveringExpanderList)))
3060 DM_DBG2(("dmDiscoveringUndoAdd: empty discoveringExpanderList\n"));
3064 // DM_DBG2(("dmDiscoveringUndoAdd: before\n"));
3065 // dmDumpAllExp(dmRoot, onePortContext, oneExpander);
3067 ExpanderList = tmpOnePortContext->discovery.discoveringExpanderList.flink;
3068 while (ExpanderList != &(tmpOnePortContext->discovery.discoveringExpanderList))
3070 tempExpander = DMLIST_OBJECT_BASE(dmExpander_t, linkNode, ExpanderList);
3071 if ( tempExpander == agNULL)
3073 DM_DBG1(("dmDiscoveringUndoAdd: tempExpander is NULL!!!\n"));
3076 if (tempExpander->dmUpStreamExpander == oneExpander)
3078 DM_DBG2(("dmDiscoveringUndoAdd: match!!! expander id %d\n", tempExpander->id));
3079 DM_DBG2(("dmDiscoveringUndoAdd: exp addrHi 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressHi));
3080 DM_DBG2(("dmDiscoveringUndoAdd: exp addrLo 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressLo));
3081 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
3082 DMLIST_DEQUEUE_THIS(&(tempExpander->linkNode));
3083 // DMLIST_ENQUEUE_AT_TAIL(&(tempExpander->linkNode), &(dmAllShared->freeExpanderList));
3084 DMLIST_ENQUEUE_AT_TAIL(&(tempExpander->linkNode), &(dmAllShared->mainExpanderList));
3085 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
3086 ExpanderList = tmpOnePortContext->discovery.discoveringExpanderList.flink;
3088 if (DMLIST_EMPTY(&(tmpOnePortContext->discovery.discoveringExpanderList)))
3090 DM_DBG2(("dmDiscoveringUndoAdd: hitting break\n"));
3093 ExpanderList = ExpanderList->flink;
3096 // DM_DBG2(("dmDiscoveringUndoAdd: after\n"));
3097 // dmDumpAllExp(dmRoot, onePortContext, oneExpander);
3102 dmHandleZoneViolation(
3105 agsaIORequest_t *agIORequest,
3106 dmDeviceData_t *oneDeviceData,
3107 dmSMPFrameHeader_t *frameHeader,
3108 agsaFrameHandle_t frameHandle
3111 dmIntPortContext_t *onePortContext = agNULL;
3112 dmExpander_t *oneExpander = agNULL;
3114 DM_DBG1(("dmHandleZoneViolation: start\n"));
3115 DM_DBG1(("dmHandleZoneViolation: sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
3116 DM_DBG1(("dmHandleZoneViolation: sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
3117 onePortContext = oneDeviceData->dmPortContext;
3118 oneExpander = oneDeviceData->dmExpander;
3119 if (dmDiscoverCheck(dmRoot, onePortContext) == agTRUE)
3121 DM_DBG1(("dmHandleZoneViolation: invalid port or aborted discovery!!!\n"));
3125 dmUpdateAllAdjacent(dmRoot, onePortContext, oneDeviceData);
3126 /* remove the expander from the discovering list */
3127 dmDiscoveringExpanderRemove(dmRoot, onePortContext, oneExpander);
3128 if ( onePortContext->discovery.status == DISCOVERY_UP_STREAM)
3130 /* continue upstream discovering */
3131 dmUpStreamDiscovering(dmRoot, onePortContext, oneDeviceData);
3133 else /* DISCOVERY_DOWN_STREAM or DISCOVERY_CONFIG_ROUTING */
3135 /* continue downstream discovering */
3136 dmDownStreamDiscovering(dmRoot, onePortContext, oneDeviceData);
3143 dmUpStreamDiscoverExpanderPhySkip(
3145 dmIntPortContext_t *onePortContext,
3146 dmExpander_t *oneExpander
3150 dmDeviceData_t *oneDeviceData;
3151 DM_DBG3(("dmUpStreamDiscoverExpanderPhySkip: start\n"));
3153 oneDeviceData = oneExpander->dmDevice;
3154 DM_DBG3(("dmUpStreamDiscoverExpanderPhySkip: sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
3155 DM_DBG3(("dmUpStreamDiscoverExpanderPhySkip: sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
3157 oneExpander->discoveringPhyId++;
3158 if (onePortContext->discovery.status == DISCOVERY_UP_STREAM)
3160 if ( oneExpander->discoveringPhyId < oneDeviceData->numOfPhys )
3162 DM_DBG3(("dmUpStreamDiscoverExpanderPhySkip: More Phys to discover\n"));
3163 /* continue discovery for the next phy */
3164 dmDiscoverSend(dmRoot, oneDeviceData);
3168 DM_DBG3(("dmUpStreamDiscoverExpanderPhySkip: No More Phys\n"));
3171 dmUpdateAllAdjacent(dmRoot, onePortContext, oneDeviceData);
3172 /* remove the expander from the discovering list */
3173 dmDiscoveringExpanderRemove(dmRoot, onePortContext, oneExpander);
3174 /* continue upstream discovering */
3175 dmUpStreamDiscovering(dmRoot, onePortContext, oneDeviceData);
3180 DM_DBG3(("dmUpStreamDiscoverExpanderPhySkip: onePortContext->discovery.status not in DISCOVERY_UP_STREAM; status %d\n", onePortContext->discovery.status));
3184 DM_DBG3(("dmUpStreamDiscoverExpanderPhySkip: end return phyID#%d\n", oneExpander->discoveringPhyId - 1));
3191 dmUpStreamDiscover2ExpanderPhySkip(
3193 dmIntPortContext_t *onePortContext,
3194 dmExpander_t *oneExpander
3197 dmDeviceData_t *oneDeviceData;
3199 DM_DBG2(("dmUpStreamDiscover2ExpanderPhySkip: start\n"));
3200 oneDeviceData = oneExpander->dmDevice;
3202 oneExpander->discoveringPhyId++;
3203 if (onePortContext->discovery.status == DISCOVERY_UP_STREAM)
3205 if ( oneExpander->discoveringPhyId < oneDeviceData->numOfPhys )
3207 DM_DBG2(("dmUpStreamDiscover2ExpanderPhySkip: DISCOVERY_UP_STREAM find more ...\n"));
3208 /* continue discovery for the next phy */
3209 dmDiscoverSend(dmRoot, oneDeviceData);
3213 DM_DBG2(("dmUpStreamDiscover2ExpanderPhySkip: DISCOVERY_UP_STREAM last phy continue upstream..\n"));
3216 dmUpdateAllAdjacent(dmRoot, onePortContext, oneDeviceData);
3217 /* remove the expander from the discovering list */
3218 dmDiscoveringExpanderRemove(dmRoot, onePortContext, oneExpander);
3219 /* continue upstream discovering */
3220 dmUpStreamDiscovering(dmRoot, onePortContext, oneDeviceData);
3225 DM_DBG2(("dmUpStreamDiscover2ExpanderPhySkip: onePortContext->discovery.status not in DISCOVERY_UP_STREAM; status %d\n", onePortContext->discovery.status));
3228 DM_DBG2(("dmUpStreamDiscover2ExpanderPhySkip: end return phyID#%d\n", oneExpander->discoveringPhyId - 1));
3235 dmDownStreamDiscoverExpanderPhySkip(
3237 dmIntPortContext_t *onePortContext,
3238 dmExpander_t *oneExpander
3241 dmDeviceData_t *oneDeviceData;
3242 DM_DBG3(("dmDownStreamDiscoverExpanderPhySkip: start\n"));
3244 oneDeviceData = oneExpander->dmDevice;
3245 DM_DBG3(("dmDownStreamDiscoverExpanderPhySkip: sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
3246 DM_DBG3(("dmDownStreamDiscoverExpanderPhySkip: sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
3248 /* Increment the discovering phy id */
3249 oneExpander->discoveringPhyId ++;
3251 /* If the discovery status is DISCOVERY_DOWN_STREAM */
3252 if ( onePortContext->discovery.status == DISCOVERY_DOWN_STREAM )
3254 /* If not the last phy */
3255 if ( oneExpander->discoveringPhyId < oneDeviceData->numOfPhys )
3257 DM_DBG3(("dmDownStreamDiscoverExpanderPhySkip: More Phys to discover\n"));
3258 /* continue discovery for the next phy */
3259 dmDiscoverSend(dmRoot, oneDeviceData);
3261 /* If the last phy */
3264 DM_DBG3(("dmDownStreamDiscoverExpanderPhySkip: No More Phys\n"));
3267 dmUpdateAllAdjacent(dmRoot, onePortContext, oneDeviceData);
3268 /* remove the expander from the discovering list */
3269 dmDiscoveringExpanderRemove(dmRoot, onePortContext, oneExpander);
3270 /* continue downstream discovering */
3271 dmDownStreamDiscovering(dmRoot, onePortContext, oneDeviceData);
3276 DM_DBG3(("dmDownStreamDiscoverExpanderPhySkip: onePortContext->discovery.status not in DISCOVERY_DOWN_STREAM; status %d\n", onePortContext->discovery.status));
3278 DM_DBG3(("dmDownStreamDiscoverExpanderPhySkip: end return phyID#%d\n", oneExpander->discoveringPhyId - 1));
3285 dmDownStreamDiscover2ExpanderPhySkip(
3287 dmIntPortContext_t *onePortContext,
3288 dmExpander_t *oneExpander
3291 dmDeviceData_t *oneDeviceData;
3293 DM_DBG2(("dmDownStreamDiscover2ExpanderPhySkip: start\n"));
3295 oneDeviceData = oneExpander->dmDevice;
3296 /* Increment the discovering phy id */
3297 oneExpander->discoveringPhyId ++;
3299 /* If the discovery status is DISCOVERY_DOWN_STREAM */
3300 if ( onePortContext->discovery.status == DISCOVERY_DOWN_STREAM )
3302 /* If not the last phy */
3303 if ( oneExpander->discoveringPhyId < oneDeviceData->numOfPhys )
3305 DM_DBG2(("dmDownStreamDiscover2ExpanderPhySkip: More Phys to discover\n"));
3306 /* continue discovery for the next phy */
3307 dmDiscoverSend(dmRoot, oneDeviceData);
3309 /* If the last phy */
3312 DM_DBG2(("dmDownStreamDiscover2ExpanderPhySkip: No More Phys\n"));
3315 dmUpdateAllAdjacent(dmRoot, onePortContext, oneDeviceData);
3316 /* remove the expander from the discovering list */
3317 dmDiscoveringExpanderRemove(dmRoot, onePortContext, oneExpander);
3318 /* continue downstream discovering */
3319 dmDownStreamDiscovering(dmRoot, onePortContext, oneDeviceData);
3324 DM_DBG2(("dmDownStreamDiscover2ExpanderPhySkip: onePortContext->discovery.status not in DISCOVERY_DOWN_STREAM; status %d\n", onePortContext->discovery.status));
3326 DM_DBG2(("dmDownStreamDiscover2ExpanderPhySkip: end return phyID#%d\n", oneExpander->discoveringPhyId - 1));
3331 dmExpanderUpStreamPhyAdd(
3333 dmExpander_t *oneExpander,
3338 bit32 hasSet = agFALSE;
3340 DM_DBG3(("dmExpanderUpStreamPhyAdd: start, phyid %d\n", phyId));
3341 DM_DBG3(("dmExpanderUpStreamPhyAdd: exp addrHi 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressHi));
3342 DM_DBG3(("dmExpanderUpStreamPhyAdd: exp addrLo 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressLo));
3343 DM_DBG3(("dmExpanderUpStreamPhyAdd: phyid %d numOfUpStreamPhys %d\n", phyId, oneExpander->numOfUpStreamPhys));
3345 for ( i = 0; i < oneExpander->numOfUpStreamPhys; i ++ )
3347 if ( oneExpander->upStreamPhys[i] == phyId )
3354 if ( hasSet == agFALSE )
3356 oneExpander->upStreamPhys[oneExpander->numOfUpStreamPhys ++] = phyId;
3359 DM_DBG3(("dmExpanderUpStreamPhyAdd: AFTER phyid %d numOfUpStreamPhys %d\n", phyId, oneExpander->numOfUpStreamPhys));
3362 for ( i = 0; i < oneExpander->numOfUpStreamPhys; i ++ )
3364 DM_DBG3(("dmExpanderUpStreamPhyAdd: index %d upstream[index] %d\n", i, oneExpander->upStreamPhys[i]));
3370 dmExpanderDownStreamPhyAdd(
3372 dmExpander_t *oneExpander,
3377 bit32 hasSet = agFALSE;
3379 DM_DBG3(("dmExpanderDownStreamPhyAdd: start, phyid %d\n", phyId));
3380 DM_DBG3(("dmExpanderDownStreamPhyAdd: exp addrHi 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressHi));
3381 DM_DBG3(("dmExpanderDownStreamPhyAdd: exp addrLo 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressLo));
3382 DM_DBG3(("dmExpanderDownStreamPhyAdd: phyid %d numOfDownStreamPhys %d\n", phyId, oneExpander->numOfDownStreamPhys));
3384 for ( i = 0; i < oneExpander->numOfDownStreamPhys; i ++ )
3386 if ( oneExpander->downStreamPhys[i] == phyId )
3393 if ( hasSet == agFALSE )
3395 oneExpander->downStreamPhys[oneExpander->numOfDownStreamPhys ++] = phyId;
3398 DM_DBG3(("dmExpanderDownStreamPhyAdd: AFTER phyid %d numOfDownStreamPhys %d\n", phyId, oneExpander->numOfDownStreamPhys));
3401 for ( i = 0; i < oneExpander->numOfDownStreamPhys; i ++ )
3403 DM_DBG3(("dmExpanderDownStreamPhyAdd: index %d downstream[index] %d\n", i, oneExpander->downStreamPhys[i]));
3409 dmDiscoveryReportMCN(
3411 dmIntPortContext_t *onePortContext
3414 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
3415 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
3416 dmDeviceData_t *oneDeviceData = agNULL;
3417 dmList_t *DeviceListList;
3418 bit16 extension = 0;
3419 dmDeviceData_t *oneAttachedExpDeviceData = agNULL;
3421 DM_DBG2(("dmDiscoveryReportMCN: start\n"));
3424 if full disocvery, report all devices using MCN
3425 if incremental discovery,
3426 1. compare MCN and PrevMCN
3427 2. report the changed ones; report MCN
3428 3. set PrevMCN to MCN
3432 DeviceListList = dmAllShared->MainDeviceList.flink;
3433 while (DeviceListList != &(dmAllShared->MainDeviceList))
3435 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
3436 if ( oneDeviceData == agNULL)
3438 DM_DBG1(("dmDiscoveryReportMCN: oneDeviceData is NULL!!!\n"));
3441 DM_DBG3(("dmDiscoveryReportMCN: loop did %d\n", oneDeviceData->id));
3442 if (oneDeviceData->dmPortContext == onePortContext)
3444 DM_DBG2(("dmDiscoveryReportMCN: oneDeviceData sasAddressHi 0x%08x sasAddressLo 0x%08x\n",
3445 oneDeviceData->SASAddressID.sasAddressHi, oneDeviceData->SASAddressID.sasAddressLo));
3446 DM_DBG2(("dmDiscoveryReportMCN: MCN 0x%08x PrevMCN 0x%08x\n", oneDeviceData->MCN, oneDeviceData->PrevMCN));
3448 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_FULL_START)
3450 DM_DBG2(("dmDiscoveryReportMCN: FULL_START\n"));
3454 DM_DBG2(("dmDiscoveryReportMCN: INCREMENTAL_START\n"));
3457 if MCN is 0, the device is removed
3459 if (oneDeviceData->MCN != oneDeviceData->PrevMCN && oneDeviceData->MCN != 0)
3461 DM_DBG2(("dmDiscoveryReportMCN: reporting \n"));
3462 extension = oneDeviceData->dmDeviceInfo.ext;
3463 /* zero out MCN in extension */
3464 extension = extension & 0x7FF;
3465 /* sets MCN in extension */
3466 extension = extension | (oneDeviceData->MCN << 11);
3467 DEVINFO_PUT_EXT(&(oneDeviceData->dmDeviceInfo), extension);
3468 DM_DBG5(("dmDiscoveryReportMCN: MCN 0x%08x PrevMCN 0x%08x\n", DEVINFO_GET_EXT_MCN(&(oneDeviceData->dmDeviceInfo)), oneDeviceData->PrevMCN));
3469 if (oneDeviceData->ExpDevice != agNULL)
3471 DM_DBG2(("dmDiscoveryReportMCN: attached expander case\n"));
3472 oneAttachedExpDeviceData = oneDeviceData->ExpDevice;
3473 tddmReportDevice(dmRoot, onePortContext->dmPortContext, &oneDeviceData->dmDeviceInfo, &oneAttachedExpDeviceData->dmDeviceInfo, dmDeviceMCNChange);
3477 DM_DBG2(("dmDiscoveryReportMCN: No attached expander case\n"));
3478 tddmReportDevice(dmRoot, onePortContext->dmPortContext, &oneDeviceData->dmDeviceInfo, agNULL, dmDeviceMCNChange);
3480 oneDeviceData->PrevMCN = oneDeviceData->MCN;
3484 DM_DBG2(("dmDiscoveryReportMCN: No change; no reporting \n"));
3485 if (oneDeviceData->MCN == 0)
3487 oneDeviceData->PrevMCN = oneDeviceData->MCN;
3492 DeviceListList = DeviceListList->flink;
3501 dmIntPortContext_t *onePortContext
3504 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
3505 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
3506 dmDeviceData_t *oneDeviceData = agNULL;
3507 dmList_t *DeviceListList;
3509 DM_DBG3(("dmDiscoveryDumpMCN: start\n"));
3511 DeviceListList = dmAllShared->MainDeviceList.flink;
3512 while (DeviceListList != &(dmAllShared->MainDeviceList))
3514 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
3515 if (oneDeviceData == agNULL)
3517 DM_DBG1(("dmDiscoveryDumpMCN: oneDeviceData is NULL!!!\n"));
3520 DM_DBG3(("dmDiscoveryDumpMCN: loop did %d\n", oneDeviceData->id));
3521 if (oneDeviceData->dmPortContext == onePortContext)
3523 DM_DBG3(("dmDiscoveryDumpMCN: oneDeviceData sasAddressHi 0x%08x sasAddressLo 0x%08x\n",
3524 oneDeviceData->SASAddressID.sasAddressHi, oneDeviceData->SASAddressID.sasAddressLo));
3525 DM_DBG3(("dmDiscoveryDumpMCN: MCN 0x%08x PrevMCN 0x%08x\n", oneDeviceData->MCN, oneDeviceData->PrevMCN));
3527 DeviceListList = DeviceListList->flink;
3534 dmDiscoveryResetMCN(
3536 dmIntPortContext_t *onePortContext
3539 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
3540 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
3541 dmDeviceData_t *oneDeviceData = agNULL;
3542 dmList_t *DeviceListList;
3544 DM_DBG2(("dmDiscoveryResetMCN: start\n"));
3546 /* reinitialize the device data belonging to this portcontext */
3547 DeviceListList = dmAllShared->MainDeviceList.flink;
3548 while (DeviceListList != &(dmAllShared->MainDeviceList))
3550 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
3551 if (oneDeviceData == agNULL)
3553 DM_DBG1(("dmDiscoveryResetMCN: oneDeviceData is NULL!!!\n"));
3556 DM_DBG3(("dmDiscoveryResetMCN: loop did %d\n", oneDeviceData->id));
3557 if (oneDeviceData->dmPortContext == onePortContext)
3559 if (oneDeviceData->ExpDevice != agNULL)
3561 DM_DBG2(("dmDiscoveryResetMCN: resetting oneDeviceData->ExpDevice\n"));
3562 oneDeviceData->ExpDevice = agNULL;
3564 DM_DBG3(("dmDiscoveryResetMCN: resetting MCN and MCNdone\n"));
3565 oneDeviceData->MCN = 0;
3567 oneDeviceData->MCNDone = agFALSE;
3568 DM_DBG2(("dmDiscoveryResetMCN: oneDeviceData sasAddressHi 0x%08x sasAddressLo 0x%08x\n",
3569 oneDeviceData->SASAddressID.sasAddressHi, oneDeviceData->SASAddressID.sasAddressLo));
3571 DeviceListList = DeviceListList->flink;
3579 do min(oneDeviceData, found-one) in all upstream and downstream
3580 find ajcanent expanders and mark it done; sees only ajcacent targets
3583 dmUpdateAllAdjacent(
3585 dmIntPortContext_t *onePortContext,
3586 dmDeviceData_t *oneDeviceData /* current one */
3589 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
3590 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
3591 dmDeviceData_t *tmponeDeviceData = agNULL;
3592 dmList_t *DeviceListList;
3594 DM_DBG2(("dmUpdateAllAdjacent: start\n"));
3595 if (oneDeviceData == agNULL)
3597 DM_DBG1(("dmUpdateAllAdjacent: oneDeviceData is NULL!!!\n"));
3601 oneDeviceData->MCNDone = agTRUE;
3603 DM_DBG2(("dmUpdateAllAdjacent: oneDeviceData sasAddressHi 0x%08x sasAddressLo 0x%08x\n",
3604 oneDeviceData->SASAddressID.sasAddressHi, oneDeviceData->SASAddressID.sasAddressLo));
3607 DeviceListList = dmAllShared->MainDeviceList.flink;
3608 while (DeviceListList != &(dmAllShared->MainDeviceList))
3610 tmponeDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
3611 if ( tmponeDeviceData == agNULL)
3613 DM_DBG1(("dmUpdateAllAdjacent: tmponeDeviceData is NULL!!!\n"));
3616 DM_DBG3(("dmUpdateAllAdjacent: loop did %d\n", tmponeDeviceData->id));
3617 if (tmponeDeviceData->dmPortContext == onePortContext && tmponeDeviceData->ExpDevice == oneDeviceData)
3619 DM_DBG2(("dmUpdateAllAdjacent: setting MCN DONE\n"));
3620 DM_DBG2(("dmUpdateAllAdjacent: tmponeDeviceData sasAddressHi 0x%08x sasAddressLo 0x%08x\n",
3621 tmponeDeviceData->SASAddressID.sasAddressHi, tmponeDeviceData->SASAddressID.sasAddressLo));
3622 tmponeDeviceData->MCNDone = agTRUE;
3623 if (oneDeviceData->directlyAttached == agFALSE)
3625 DM_DBG2(("dmUpdateAllAdjacent: tmponeDeviceData MCN 0x%x\n", tmponeDeviceData->MCN));
3626 DM_DBG2(("dmUpdateAllAdjacent: oneDeviceData MCN 0x%x\n", oneDeviceData->MCN));
3627 tmponeDeviceData->MCN = MIN(oneDeviceData->MCN, tmponeDeviceData->MCN);
3631 DeviceListList = DeviceListList->flink;
3641 dmIntPortContext_t *onePortContext,
3642 dmDeviceData_t *AdjacentDeviceData, /* adjacent expander */
3643 dmDeviceData_t *oneDeviceData /* current one */
3647 DM_DBG2(("dmUpdateMCN: start\n"));
3649 if (AdjacentDeviceData == agNULL)
3651 DM_DBG1(("dmUpdateMCN: AdjacentDeviceData is NULL!!!\n"));
3655 if (oneDeviceData == agNULL)
3657 DM_DBG1(("dmUpdateMCN: oneDeviceData is NULL!!!\n"));
3661 DM_DBG2(("dmUpdateMCN: Current sasAddressHi 0x%08x sasAddressLo 0x%08x\n",
3662 oneDeviceData->SASAddressID.sasAddressHi, oneDeviceData->SASAddressID.sasAddressLo));
3664 DM_DBG2(("dmUpdateMCN: AdjacentDeviceData one sasAddressHi 0x%08x sasAddressLo 0x%08x\n",
3665 AdjacentDeviceData->SASAddressID.sasAddressHi, AdjacentDeviceData->SASAddressID.sasAddressLo));
3667 if (onePortContext->discovery.status == DISCOVERY_UP_STREAM)
3669 DM_DBG2(("dmUpdateMCN: DISCOVERY_UP_STREAM\n"));
3672 if (onePortContext->discovery.status == DISCOVERY_DOWN_STREAM)
3674 DM_DBG2(("dmUpdateMCN: DISCOVERY_DOWN_STREAM\n"));
3680 /* directly attached one does not have MCN
3681 update only adjacent device data
3684 if (oneDeviceData->directlyAttached == agTRUE && AdjacentDeviceData->MCNDone == agFALSE)
3686 AdjacentDeviceData->MCN++;
3687 DM_DBG2(("dmUpdateMCN: case 1 oneDeviceData MCN 0x%x\n", oneDeviceData->MCN));
3688 DM_DBG2(("dmUpdateMCN: case 1 AdjacentDeviceData MCN 0x%x\n", AdjacentDeviceData->MCN));
3690 else if (AdjacentDeviceData->MCNDone == agFALSE)
3692 AdjacentDeviceData->MCN++;
3693 AdjacentDeviceData->MCN = MIN(oneDeviceData->MCN, AdjacentDeviceData->MCN);
3694 DM_DBG2(("dmUpdateMCN: case 2 oneDeviceData MCN 0x%x\n", oneDeviceData->MCN));
3695 DM_DBG2(("dmUpdateMCN: case 2 AdjacentDeviceData MCN 0x%x\n", AdjacentDeviceData->MCN));
3701 /* go through expander list and device list array ??? */
3702 osGLOBAL dmDeviceData_t *
3703 dmPortSASDeviceFind(
3705 dmIntPortContext_t *onePortContext,
3708 dmDeviceData_t *CurrentDeviceData /* current expander */
3711 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
3712 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
3713 dmDeviceData_t *oneDeviceData, *RetDeviceData=agNULL;
3714 dmList_t *DeviceListList;
3716 DM_DBG3(("dmPortSASDeviceFind: start\n"));
3717 DM_DBG3(("dmPortSASDeviceFind: sasAddressHi 0x%08x sasAddressLo 0x%08x\n", sasAddrHi, sasAddrLo));
3719 DM_ASSERT((agNULL != dmRoot), "");
3720 DM_ASSERT((agNULL != onePortContext), "");
3722 tddmSingleThreadedEnter(dmRoot, DM_DEVICE_LOCK);
3724 /* find a device's existence */
3725 DeviceListList = dmAllShared->MainDeviceList.flink;
3726 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_FULL_START)
3728 DM_DBG3(("dmPortSASDeviceFind: Full discovery\n"));
3729 while (DeviceListList != &(dmAllShared->MainDeviceList))
3731 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
3732 if (oneDeviceData == agNULL)
3734 DM_DBG1(("dmPortSASDeviceFind: oneDeviceData is NULL!!!\n"));
3737 if ((oneDeviceData->SASAddressID.sasAddressHi == sasAddrHi) &&
3738 (oneDeviceData->SASAddressID.sasAddressLo == sasAddrLo) &&
3739 (oneDeviceData->valid == agTRUE) &&
3740 (oneDeviceData->dmPortContext == onePortContext)
3743 DM_DBG3(("dmPortSASDeviceFind: Found pid %d did %d\n", onePortContext->id, oneDeviceData->id));
3744 DM_DBG3(("dmPortSASDeviceFind: sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
3745 DM_DBG3(("dmPortSASDeviceFind: sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
3746 RetDeviceData = oneDeviceData;
3747 dmUpdateMCN(dmRoot, onePortContext, RetDeviceData, CurrentDeviceData);
3750 DeviceListList = DeviceListList->flink;
3755 /* incremental discovery */
3756 DM_DBG3(("dmPortSASDeviceFind: Incremental discovery\n"));
3757 while (DeviceListList != &(dmAllShared->MainDeviceList))
3759 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
3760 if (oneDeviceData == agNULL)
3762 DM_DBG1(("dmPortSASDeviceFind: oneDeviceData is NULL!!!\n"));
3765 if ((oneDeviceData->SASAddressID.sasAddressHi == sasAddrHi) &&
3766 (oneDeviceData->SASAddressID.sasAddressLo == sasAddrLo) &&
3767 (oneDeviceData->valid2 == agTRUE) &&
3768 (oneDeviceData->dmPortContext == onePortContext)
3771 DM_DBG3(("dmPortSASDeviceFind: Found pid %d did %d\n", onePortContext->id, oneDeviceData->id));
3772 DM_DBG3(("dmPortSASDeviceFind: sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
3773 DM_DBG3(("dmPortSASDeviceFind: sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
3774 RetDeviceData = oneDeviceData;
3775 dmUpdateMCN(dmRoot, onePortContext, RetDeviceData, CurrentDeviceData);
3778 DeviceListList = DeviceListList->flink;
3782 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
3784 return RetDeviceData;
3790 dmIntPortContext_t *onePortContext,
3791 dmSASSubID_t *dmSASSubID
3794 // dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
3795 // dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
3796 dmExpander_t *oneExpander = agNULL;
3797 dmList_t *ExpanderList;
3799 dmDeviceData_t *oneDeviceData = agNULL;
3801 DM_DBG3(("dmNewEXPorNot: start\n"));
3803 /* find a device's existence */
3804 ExpanderList = onePortContext->discovery.discoveringExpanderList.flink;
3805 while (ExpanderList != &(onePortContext->discovery.discoveringExpanderList))
3807 oneExpander = DMLIST_OBJECT_BASE(dmExpander_t, linkNode, ExpanderList);
3808 if ( oneExpander == agNULL)
3810 DM_DBG1(("dmNewEXPorNot: oneExpander is NULL!!!\n"));
3813 oneDeviceData = oneExpander->dmDevice;
3814 if ((oneDeviceData->SASAddressID.sasAddressHi == dmSASSubID->sasAddressHi) &&
3815 (oneDeviceData->SASAddressID.sasAddressLo == dmSASSubID->sasAddressLo) &&
3816 (oneDeviceData->dmPortContext == onePortContext)
3819 DM_DBG3(("dmNewEXPorNot: Found pid %d did %d\n", onePortContext->id, oneDeviceData->id));
3823 ExpanderList = ExpanderList->flink;
3833 dmIntPortContext_t *onePortContext,
3834 dmSASSubID_t *dmSASSubID
3837 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
3838 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
3839 dmDeviceData_t *oneDeviceData = agNULL;
3840 dmList_t *DeviceListList;
3843 DM_DBG3(("dmNewSASorNot: start\n"));
3845 /* find a device's existence */
3846 DeviceListList = dmAllShared->MainDeviceList.flink;
3847 while (DeviceListList != &(dmAllShared->MainDeviceList))
3849 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
3850 if (oneDeviceData == agNULL)
3852 DM_DBG1(("dmNewSASorNot: oneDeviceData is NULL!!!\n"));
3855 if ((oneDeviceData->SASAddressID.sasAddressHi == dmSASSubID->sasAddressHi) &&
3856 (oneDeviceData->SASAddressID.sasAddressLo == dmSASSubID->sasAddressLo) &&
3857 (oneDeviceData->dmPortContext == onePortContext) &&
3858 (oneDeviceData->registered == agTRUE)
3861 DM_DBG3(("dmNewSASorNot: Found pid %d did %d\n", onePortContext->id, oneDeviceData->id));
3865 DeviceListList = DeviceListList->flink;
3875 dmPortContext_t *dmPortContext,
3876 dmDeviceInfo_t *dmDeviceInfo
3878 if not reported, report Device to TDM
3880 osGLOBAL dmDeviceData_t *
3883 dmIntPortContext_t *onePortContext,
3884 agsaSASIdentify_t sasIdentify,
3886 bit8 connectionRate,
3887 bit32 itNexusTimeout,
3888 bit32 firstBurstSize,
3890 dmDeviceData_t *oneExpDeviceData,
3891 dmExpander_t *dmExpander,
3895 dmDeviceData_t *oneDeviceData = agNULL;
3896 bit8 dev_s_rate = 0;
3898 dmSASSubID_t dmSASSubID;
3899 bit8 ExpanderConnectionRate = connectionRate;
3900 dmDeviceData_t *oneAttachedExpDeviceData = agNULL;
3901 bit16 extension = 0;
3902 bit32 current_link_rate = 0;
3904 DM_DBG3(("dmPortSASDeviceAdd: start\n"));
3905 DM_DBG3(("dmPortSASDeviceAdd: connectionRate %d\n", connectionRate));
3907 dmSASSubID.sasAddressHi = SA_IDFRM_GET_SAS_ADDRESSHI(&sasIdentify);
3908 dmSASSubID.sasAddressLo = SA_IDFRM_GET_SAS_ADDRESSLO(&sasIdentify);
3909 dmSASSubID.initiator_ssp_stp_smp = sasIdentify.initiator_ssp_stp_smp;
3910 dmSASSubID.target_ssp_stp_smp = sasIdentify.target_ssp_stp_smp;
3912 if (oneExpDeviceData != agNULL)
3914 ExpanderConnectionRate = DEVINFO_GET_LINKRATE(&oneExpDeviceData->agDeviceInfo);
3915 DM_DBG3(("dmPortSASDeviceAdd: ExpanderConnectionRate 0x%x\n", ExpanderConnectionRate));
3917 if (oneExpDeviceData != agNULL)
3919 if (oneExpDeviceData->SASAddressID.sasAddressHi == 0x0 &&
3920 oneExpDeviceData->SASAddressID.sasAddressLo == 0x0)
3922 DM_DBG1(("dmPortSASDeviceAdd: 1st Wrong expander!!!\n"));
3925 /* old device and already reported to TDM */
3926 if ( agFALSE == dmNewSASorNot(
3933 DM_DBG3(("dmPortSASDeviceAdd: OLD qqqq initiator_ssp_stp_smp %d target_ssp_stp_smp %d\n", dmSASSubID.initiator_ssp_stp_smp, dmSASSubID.target_ssp_stp_smp));
3934 /* allocate a new device and set the valid bit */
3935 oneDeviceData = dmAddSASToSharedcontext(
3942 if (oneDeviceData == agNULL)
3944 DM_DBG1(("dmPortSASDeviceAdd: no more device, oneDeviceData is null!!!\n"));
3946 /* If a device is allocated */
3947 if ( oneDeviceData != agNULL )
3951 if (onePortContext->discovery.status == DISCOVERY_UP_STREAM)
3953 DM_DBG3(("dmPortSASDeviceAdd: OLD, UP_STREAM\n"));
3955 if (onePortContext->discovery.status == DISCOVERY_DOWN_STREAM)
3957 DM_DBG3(("dmPortSASDeviceAdd: OLD, DOWN_STREAM\n"));
3960 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_FULL_START)
3962 DM_DBG3(("dmPortSASDeviceAdd: FULL_START\n"));
3963 oneDeviceData->MCN++;
3968 DM_DBG3(("dmPortSASDeviceAdd: INCREMENTAL_START\n"));
3969 if (oneDeviceData->MCN == 0 && oneDeviceData->directlyAttached == agFALSE)
3971 oneDeviceData->MCN++;
3975 DM_DBG3(("dmPortSASDeviceAdd: oneDeviceData MCN 0x%08x\n", oneDeviceData->MCN));
3976 DM_DBG3(("dmPortSASDeviceAdd: oneDeviceData sasAddressHi 0x%08x sasAddressLo 0x%08x\n",
3977 oneDeviceData->SASAddressID.sasAddressHi, oneDeviceData->SASAddressID.sasAddressLo));
3980 DM_DBG3(("dmPortSASDeviceAdd: sasAddressHi 0x%08x\n", SA_IDFRM_GET_SAS_ADDRESSHI(&sasIdentify)));
3981 DM_DBG3(("dmPortSASDeviceAdd: sasAddressLo 0x%08x\n", SA_IDFRM_GET_SAS_ADDRESSLO(&sasIdentify)));
3983 // oneDeviceData->sasIdentify = sasIdentify;
3984 dm_memcpy(&(oneDeviceData->sasIdentify), &sasIdentify, sizeof(agsaSASIdentify_t));
3986 DM_DBG3(("dmPortSASDeviceAdd: sasAddressHi 0x%08x\n", SA_IDFRM_GET_SAS_ADDRESSHI(&oneDeviceData->sasIdentify)));
3987 DM_DBG3(("dmPortSASDeviceAdd: sasAddressLo 0x%08x\n", SA_IDFRM_GET_SAS_ADDRESSLO(&oneDeviceData->sasIdentify)));
3989 /* parse sasIDframe to fill in agDeviceInfo */
3990 DEVINFO_PUT_SMPTO(&oneDeviceData->agDeviceInfo, DEFAULT_SMP_TIMEOUT);
3991 DEVINFO_PUT_ITNEXUSTO(&oneDeviceData->agDeviceInfo, (bit16)itNexusTimeout);
3992 DEVINFO_PUT_FBS(&oneDeviceData->agDeviceInfo, (bit16)firstBurstSize);
3993 DEVINFO_PUT_FLAG(&oneDeviceData->agDeviceInfo, 1);
3995 oneDeviceData->SASSpecDeviceType = SA_IDFRM_GET_DEVICETTYPE(&sasIdentify);
3997 /* adjusting connectionRate */
3998 oneAttachedExpDeviceData = oneDeviceData->ExpDevice;
3999 if (oneAttachedExpDeviceData != agNULL)
4001 connectionRate = MIN(connectionRate, DEVINFO_GET_LINKRATE(&oneAttachedExpDeviceData->agDeviceInfo));
4002 DM_DBG3(("dmPortSASDeviceAdd: 1st connectionRate 0x%x DEVINFO_GET_LINKRATE(&oneAttachedExpDeviceData->agDeviceInfo) 0x%x\n",
4003 connectionRate, DEVINFO_GET_LINKRATE(&oneAttachedExpDeviceData->agDeviceInfo)));
4007 DM_DBG3(("dmPortSASDeviceAdd: 1st oneAttachedExpDeviceData is NULL\n"));
4010 /* Device Type, SAS or SATA, connection rate; bit7 --- bit0 */
4011 sasorsata = (bit8)deviceType;
4012 /* sTSDK spec device typ */
4013 dev_s_rate = dev_s_rate | (sasorsata << 4);
4014 dev_s_rate = dev_s_rate | MIN(connectionRate, ExpanderConnectionRate);
4015 /* detect link rate change */
4016 current_link_rate = DEVINFO_GET_LINKRATE(&oneDeviceData->agDeviceInfo);
4017 if (current_link_rate != (bit32)MIN(connectionRate, ExpanderConnectionRate))
4019 DM_DBG1(("dmPortSASDeviceAdd: link rate changed current 0x%x new 0x%x\n", current_link_rate, MIN(connectionRate, ExpanderConnectionRate)));
4020 DEVINFO_PUT_DEV_S_RATE(&oneDeviceData->dmDeviceInfo, dev_s_rate);
4021 if (oneDeviceData->ExpDevice != agNULL)
4023 oneAttachedExpDeviceData = oneDeviceData->ExpDevice;
4024 tddmReportDevice(dmRoot, onePortContext->dmPortContext, &oneDeviceData->dmDeviceInfo, &oneAttachedExpDeviceData->dmDeviceInfo, dmDeviceRateChange);
4028 tddmReportDevice(dmRoot, onePortContext->dmPortContext, &oneDeviceData->dmDeviceInfo, agNULL, dmDeviceArrival);
4032 DEVINFO_PUT_DEV_S_RATE(&oneDeviceData->agDeviceInfo, dev_s_rate);
4035 DEVINFO_PUT_SAS_ADDRESSLO(
4036 &oneDeviceData->agDeviceInfo,
4037 SA_IDFRM_GET_SAS_ADDRESSLO(&oneDeviceData->sasIdentify)
4039 DEVINFO_PUT_SAS_ADDRESSHI(
4040 &oneDeviceData->agDeviceInfo,
4041 SA_IDFRM_GET_SAS_ADDRESSHI(&oneDeviceData->sasIdentify)
4043 oneDeviceData->agContext.osData = oneDeviceData;
4044 oneDeviceData->agContext.sdkData = agNULL;
4048 return oneDeviceData;
4054 DM_DBG3(("dmPortSASDeviceAdd: NEW qqqq initiator_ssp_stp_smp %d target_ssp_stp_smp %d\n", dmSASSubID.initiator_ssp_stp_smp, dmSASSubID.target_ssp_stp_smp));
4056 /* allocate a new device and set the valid bit */
4057 oneDeviceData = dmAddSASToSharedcontext(
4064 if (oneDeviceData == agNULL)
4066 DM_DBG1(("dmPortSASDeviceAdd: no more device, oneDeviceData is null !!!\n"));
4069 /* If a device is allocated */
4070 if ( oneDeviceData != agNULL )
4073 // DM_DBG3(("dmPortSASDeviceAdd: sasAddressHi 0x%08x\n", SA_IDFRM_GET_SAS_ADDRESSHI(&sasIdentify)));
4074 // DM_DBG3(("dmPortSASDeviceAdd: sasAddressLo 0x%08x\n", SA_IDFRM_GET_SAS_ADDRESSLO(&sasIdentify)));
4076 // oneDeviceData->sasIdentify = sasIdentify;
4077 dm_memcpy(&(oneDeviceData->sasIdentify), &sasIdentify, sizeof(agsaSASIdentify_t));
4079 if (onePortContext->discovery.status == DISCOVERY_UP_STREAM)
4081 DM_DBG3(("dmPortSASDeviceAdd: NEW, UP_STREAM\n"));
4083 if (onePortContext->discovery.status == DISCOVERY_DOWN_STREAM)
4085 DM_DBG3(("dmPortSASDeviceAdd: NEW, DOWN_STREAM\n"));
4088 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_FULL_START)
4090 DM_DBG3(("dmPortSASDeviceAdd: FULL_START\n"));
4091 oneDeviceData->MCN++;
4096 DM_DBG3(("dmPortSASDeviceAdd: INCREMENTAL_START\n"));
4097 if (oneDeviceData->MCN == 0 && oneDeviceData->directlyAttached == agFALSE)
4099 oneDeviceData->MCN++;
4102 DM_DBG3(("dmPortSASDeviceAdd: oneDeviceData MCN 0x%08x\n", oneDeviceData->MCN));
4103 DM_DBG3(("dmPortSASDeviceAdd: oneDeviceData sasAddressHi 0x%08x sasAddressLo 0x%08x\n",
4104 oneDeviceData->SASAddressID.sasAddressHi, oneDeviceData->SASAddressID.sasAddressLo));
4106 DM_DBG3(("dmPortSASDeviceAdd: sasAddressHi 0x%08x\n", SA_IDFRM_GET_SAS_ADDRESSHI(&oneDeviceData->sasIdentify)));
4107 DM_DBG3(("dmPortSASDeviceAdd: sasAddressLo 0x%08x\n", SA_IDFRM_GET_SAS_ADDRESSLO(&oneDeviceData->sasIdentify)));
4109 /* parse sasIDframe to fill in agDeviceInfo */
4110 DEVINFO_PUT_SMPTO(&oneDeviceData->agDeviceInfo, DEFAULT_SMP_TIMEOUT);
4111 DEVINFO_PUT_ITNEXUSTO(&oneDeviceData->agDeviceInfo, (bit16)itNexusTimeout);
4112 DEVINFO_PUT_FBS(&oneDeviceData->agDeviceInfo, (bit16)firstBurstSize);
4113 DEVINFO_PUT_FLAG(&oneDeviceData->agDeviceInfo, 1);
4115 oneDeviceData->SASSpecDeviceType = SA_IDFRM_GET_DEVICETTYPE(&sasIdentify);
4117 /* adjusting connectionRate */
4118 oneAttachedExpDeviceData = oneDeviceData->ExpDevice;
4119 if (oneAttachedExpDeviceData != agNULL)
4121 connectionRate = MIN(connectionRate, DEVINFO_GET_LINKRATE(&oneAttachedExpDeviceData->agDeviceInfo));
4122 DM_DBG3(("dmPortSASDeviceAdd: 2nd connectionRate 0x%x DEVINFO_GET_LINKRATE(&oneAttachedExpDeviceData->agDeviceInfo) 0x%x\n",
4123 connectionRate, DEVINFO_GET_LINKRATE(&oneAttachedExpDeviceData->agDeviceInfo)));
4127 DM_DBG3(("dmPortSASDeviceAdd: 2nd oneAttachedExpDeviceData is NULL\n"));
4130 /* Device Type, SAS or SATA, connection rate; bit7 --- bit0 */
4131 sasorsata = (bit8)deviceType;
4132 dev_s_rate = dev_s_rate | (sasorsata << 4);
4133 dev_s_rate = dev_s_rate | MIN(connectionRate, ExpanderConnectionRate);
4134 DEVINFO_PUT_DEV_S_RATE(&oneDeviceData->agDeviceInfo, dev_s_rate);
4137 DEVINFO_PUT_SAS_ADDRESSLO(
4138 &oneDeviceData->agDeviceInfo,
4139 SA_IDFRM_GET_SAS_ADDRESSLO(&oneDeviceData->sasIdentify)
4141 DEVINFO_PUT_SAS_ADDRESSHI(
4142 &oneDeviceData->agDeviceInfo,
4143 SA_IDFRM_GET_SAS_ADDRESSHI(&oneDeviceData->sasIdentify)
4145 oneDeviceData->agContext.osData = oneDeviceData;
4146 oneDeviceData->agContext.sdkData = agNULL;
4148 DM_DBG3(("dmPortSASDeviceAdd: did %d\n", oneDeviceData->id));
4151 /* reporting to TDM; setting dmDeviceInfo */
4152 DEVINFO_PUT_SMPTO(&oneDeviceData->dmDeviceInfo, DEFAULT_SMP_TIMEOUT);
4153 DEVINFO_PUT_ITNEXUSTO(&oneDeviceData->dmDeviceInfo, (bit16)itNexusTimeout);
4154 DEVINFO_PUT_FBS(&oneDeviceData->dmDeviceInfo, (bit16)firstBurstSize);
4155 DEVINFO_PUT_FLAG(&oneDeviceData->dmDeviceInfo, 1);
4156 DEVINFO_PUT_INITIATOR_SSP_STP_SMP(&oneDeviceData->dmDeviceInfo, dmSASSubID.initiator_ssp_stp_smp);
4157 DEVINFO_PUT_TARGET_SSP_STP_SMP(&oneDeviceData->dmDeviceInfo, dmSASSubID.target_ssp_stp_smp);
4160 /* setting 6th bit of dev_s_rate */
4161 if (oneDeviceData->SASSpecDeviceType == SAS_EDGE_EXPANDER_DEVICE ||
4162 oneDeviceData->SASSpecDeviceType == SAS_FANOUT_EXPANDER_DEVICE )
4164 extension = (bit16)(extension | (1 << 8));
4166 DEVINFO_PUT_EXT(&oneDeviceData->dmDeviceInfo, extension);
4168 DEVINFO_PUT_DEV_S_RATE(&oneDeviceData->dmDeviceInfo, dev_s_rate);
4170 DEVINFO_PUT_SAS_ADDRESSLO(
4171 &oneDeviceData->dmDeviceInfo,
4172 SA_IDFRM_GET_SAS_ADDRESSLO(&oneDeviceData->sasIdentify)
4174 DEVINFO_PUT_SAS_ADDRESSHI(
4175 &oneDeviceData->dmDeviceInfo,
4176 SA_IDFRM_GET_SAS_ADDRESSHI(&oneDeviceData->sasIdentify)
4179 if (oneDeviceData->ExpDevice != agNULL)
4181 DM_DBG3(("dmPortSASDeviceAdd: attached expander case\n"));
4182 oneAttachedExpDeviceData = oneDeviceData->ExpDevice;
4184 Puts attached expander's SAS address into dmDeviceInfo
4186 DEVINFO_PUT_SAS_ADDRESSLO(
4187 &oneAttachedExpDeviceData->dmDeviceInfo,
4188 oneAttachedExpDeviceData->SASAddressID.sasAddressLo
4190 DEVINFO_PUT_SAS_ADDRESSHI(
4191 &oneAttachedExpDeviceData->dmDeviceInfo,
4192 oneAttachedExpDeviceData->SASAddressID.sasAddressHi
4194 DM_DBG3(("dmPortSASDeviceAdd: oneAttachedExpDeviceData addrHi 0x%08x addrLo 0x%08x PhyID 0x%x ext 0x%x\n",
4195 DM_GET_SAS_ADDRESSHI(oneAttachedExpDeviceData->dmDeviceInfo.sasAddressHi),
4196 DM_GET_SAS_ADDRESSLO(oneAttachedExpDeviceData->dmDeviceInfo.sasAddressLo),
4199 if (oneAttachedExpDeviceData->SASAddressID.sasAddressHi == 0x0 &&
4200 oneAttachedExpDeviceData->SASAddressID.sasAddressLo == 0x0)
4202 DM_DBG1(("dmPortSASDeviceAdd: 2nd Wrong expander!!!\n"));
4204 if (oneDeviceData->reported == agFALSE)
4206 oneDeviceData->registered = agTRUE;
4207 oneDeviceData->reported = agTRUE;
4208 if (deviceType == STP_DEVICE_TYPE)
4210 /*STP device, DM need send SMP Report Phy SATA to get the SATA device type */
4211 oneAttachedExpDeviceData->dmExpander->dmDeviceToProcess = oneDeviceData;
4212 dmReportPhySataSend(dmRoot, oneAttachedExpDeviceData, phyID);
4216 /* SAS or SMP device */
4217 tddmReportDevice(dmRoot, onePortContext->dmPortContext, &oneDeviceData->dmDeviceInfo, &oneAttachedExpDeviceData->dmDeviceInfo, dmDeviceArrival);
4223 DM_DBG3(("dmPortSASDeviceAdd: NO attached expander case\n"));
4224 if (oneDeviceData->reported == agFALSE)
4226 oneDeviceData->registered = agTRUE;
4227 oneDeviceData->reported = agTRUE;
4228 tddmReportDevice(dmRoot, onePortContext->dmPortContext, &oneDeviceData->dmDeviceInfo, agNULL, dmDeviceArrival);
4233 return oneDeviceData;
4236 osGLOBAL dmDeviceData_t *
4239 dmIntPortContext_t *onePortContext,
4240 dmSASSubID_t *dmSASSubID
4243 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
4244 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
4245 dmDeviceData_t *oneDeviceData = agNULL;
4246 dmList_t *DeviceListList;
4247 bit32 found = agFALSE;
4248 DM_DBG3(("dmFindRegNValid: start\n"));
4250 /* find a device's existence */
4251 DeviceListList = dmAllShared->MainDeviceList.flink;
4252 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_FULL_START)
4254 DM_DBG3(("dmFindRegNValid: Full discovery\n"));
4255 while (DeviceListList != &(dmAllShared->MainDeviceList))
4257 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
4258 if (oneDeviceData == agNULL)
4260 DM_DBG1(("dmFindRegNValid: oneDeviceData is NULL!!!\n"));
4263 if ((oneDeviceData->SASAddressID.sasAddressHi == dmSASSubID->sasAddressHi) &&
4264 (oneDeviceData->SASAddressID.sasAddressLo == dmSASSubID->sasAddressLo) &&
4265 (oneDeviceData->valid == agTRUE) &&
4266 (oneDeviceData->dmPortContext == onePortContext)
4269 DM_DBG3(("dmFindRegNValid: Found pid %d did %d\n", onePortContext->id, oneDeviceData->id));
4270 DM_DBG3(("dmFindRegNValid: sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
4271 DM_DBG3(("dmFindRegNValid: sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
4275 DeviceListList = DeviceListList->flink;
4280 /* incremental discovery */
4281 DM_DBG3(("dmFindRegNValid: Incremental discovery\n"));
4282 while (DeviceListList != &(dmAllShared->MainDeviceList))
4284 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
4285 if (oneDeviceData == agNULL)
4287 DM_DBG1(("dmFindRegNValid: oneDeviceData is NULL!!!\n"));
4290 if ((oneDeviceData->SASAddressID.sasAddressHi == dmSASSubID->sasAddressHi) &&
4291 (oneDeviceData->SASAddressID.sasAddressLo == dmSASSubID->sasAddressLo) &&
4292 (oneDeviceData->valid2 == agTRUE) &&
4293 (oneDeviceData->dmPortContext == onePortContext)
4296 DM_DBG3(("dmFindRegNValid: Found pid %d did %d\n", onePortContext->id, oneDeviceData->id));
4297 DM_DBG3(("dmFindRegNValid: sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
4298 DM_DBG3(("dmFindRegNValid: sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
4302 DeviceListList = DeviceListList->flink;
4308 if (found == agFALSE)
4310 DM_DBG3(("dmFindRegNValid: end returning NULL\n"));
4315 DM_DBG3(("dmFindRegNValid: end returning NOT NULL\n"));
4316 return oneDeviceData;
4323 dmPortContext_t *dmPortContext,
4326 dmIntPortContext_t *onePortContext = agNULL;
4328 onePortContext = (dmIntPortContext_t *)dmPortContext->dmData;
4330 DM_DBG3(("dmNotifyBC: start\n"));
4332 if (onePortContext == agNULL)
4334 DM_DBG1(("dmNotifyBC: onePortContext is NULL, wrong!!!\n"));
4338 if (type == OSSA_HW_EVENT_BROADCAST_CHANGE)
4340 if (onePortContext->DiscoveryAbortInProgress == agFALSE)
4342 if (onePortContext->DiscoveryState == DM_DSTATE_COMPLETED)
4344 DM_DBG3(("dmNotifyBC: BROADCAST_CHANGE\n"));
4345 onePortContext->DiscoveryState = DM_DSTATE_NOT_STARTED;
4346 onePortContext->discoveryOptions = DM_DISCOVERY_OPTION_INCREMENTAL_START;
4347 /* processed broadcast change */
4348 onePortContext->discovery.SeenBC = agFALSE;
4352 DM_DBG3(("dmNotifyBC: pid %d BROADCAST_CHANGE; updating SeenBC. Do nothing.\n", onePortContext->id));
4353 onePortContext->discovery.SeenBC = agTRUE;
4357 else if (type == OSSA_HW_EVENT_BROADCAST_SES)
4359 DM_DBG3(("dmNotifyBC: OSSA_HW_EVENT_BROADCAST_SES\n"));
4361 else if (type == OSSA_HW_EVENT_BROADCAST_EXP)
4363 DM_DBG3(("dmNotifyBC: OSSA_HW_EVENT_BROADCAST_EXP\n"));
4367 DM_DBG3(("dmNotifyBC: unspecified broadcast type 0x%x\n", type));
4374 /* triggers incremental discovery */
4378 dmPortContext_t *dmPortContext,
4381 dmIntPortContext_t *onePortContext = agNULL;
4383 onePortContext = (dmIntPortContext_t *)dmPortContext->dmData;
4385 DM_DBG3(("dmNotifyBC: start\n"));
4388 if (type == OSSA_HW_EVENT_BROADCAST_CHANGE)
4390 if (onePortContext->DiscoveryState == DM_DSTATE_COMPLETED)
4392 DM_DBG3(("dmNotifyBC: BROADCAST_CHANGE; does incremental discovery\n"));
4393 onePortContext->DiscoveryState = DM_DSTATE_NOT_STARTED;
4394 onePortContext->discoveryOptions = DM_DISCOVERY_OPTION_INCREMENTAL_START;
4395 /* processed broadcast change */
4396 onePortContext->discovery.SeenBC = agFALSE;
4397 if (onePortContext->discovery.ResetTriggerred == agTRUE)
4399 DM_DBG3(("dmNotifyBC: tdsaBCTimer\n"));
4400 dmBCTimer(dmRoot, onePortContext);
4407 DM_DISCOVERY_OPTION_INCREMENTAL_START
4413 DM_DBG3(("dmNotifyBC: pid %d BROADCAST_CHANGE; updating SeenBC. Do nothing.\n", onePortContext->id));
4414 onePortContext->discovery.SeenBC = agTRUE;
4417 else if (type == OSSA_HW_EVENT_BROADCAST_SES)
4419 DM_DBG3(("dmNotifyBC: OSSA_HW_EVENT_BROADCAST_SES\n"));
4421 else if (type == OSSA_HW_EVENT_BROADCAST_EXP)
4423 DM_DBG3(("dmNotifyBC: OSSA_HW_EVENT_BROADCAST_EXP\n"));
4427 DM_DBG3(("dmNotifyBC: unspecified broadcast type 0x%x\n", type));
4434 dmResetFailedDiscovery(
4436 dmPortContext_t *dmPortContext)
4438 dmIntPortContext_t *onePortContext = agNULL;
4440 DM_DBG1(("dmResetFailedDiscovery: start\n"));
4442 onePortContext = (dmIntPortContext_t *)dmPortContext->dmData;
4444 if (onePortContext == agNULL)
4446 DM_DBG1(("dmResetFailedDiscovery: onePortContext is NULL, wrong!!!\n"));
4447 return DM_RC_FAILURE;
4450 if (onePortContext->DiscoveryState == DM_DSTATE_COMPLETED_WITH_FAILURE)
4452 onePortContext->DiscoveryState = DM_DSTATE_COMPLETED;
4456 DM_DBG1(("dmResetFailedDiscovery: discovery is NOT DM_DSTATE_COMPLETED_WITH_FAILURE. It is 0x%x\n", onePortContext->DiscoveryState));
4457 return DM_RC_FAILURE;
4460 return DM_RC_SUCCESS;
4466 dmPortContext_t *dmPortContext)
4468 dmIntPortContext_t *onePortContext = agNULL;
4470 DM_DBG3(("dmQueryDiscovery: start\n"));
4472 onePortContext = (dmIntPortContext_t *)dmPortContext->dmData;
4474 if (onePortContext == agNULL)
4476 DM_DBG1(("dmQueryDiscovery: onePortContext is NULL, wrong!!!\n"));
4477 return DM_RC_FAILURE;
4480 /* call tddmQueryDiscoveryCB() */
4481 if (onePortContext->DiscoveryState == DM_DSTATE_COMPLETED)
4483 tddmQueryDiscoveryCB(dmRoot, dmPortContext, onePortContext->discoveryOptions, dmDiscCompleted);
4485 else if (onePortContext->DiscoveryState == DM_DSTATE_COMPLETED_WITH_FAILURE)
4487 tddmQueryDiscoveryCB(dmRoot, dmPortContext, onePortContext->discoveryOptions, dmDiscFailed);
4491 tddmQueryDiscoveryCB(dmRoot, dmPortContext, onePortContext->discoveryOptions, dmDiscInProgress);
4494 return DM_RC_SUCCESS;
4499 should only for an expander
4504 dmPortContext_t *dmPortContext,
4505 dmDeviceInfo_t *dmDeviceInfo,
4506 agsaDevHandle_t *agDevHandle
4510 dmIntPortContext_t *onePortContext = agNULL;
4511 dmExpander_t *oneExpander = agNULL;
4512 bit32 sasAddressHi, sasAddressLo;
4513 dmDeviceData_t *oneDeviceData = agNULL;
4514 dmSASSubID_t dmSASSubID;
4516 DM_DBG3(("dmRegisterDevice: start\n"));
4518 onePortContext = (dmIntPortContext_t *)dmPortContext->dmData;
4519 if (onePortContext == agNULL)
4521 DM_DBG1(("dmRegisterDevice: onePortContext is NULL!!!\n"));
4522 return DM_RC_FAILURE;
4525 if (onePortContext->valid == agFALSE)
4527 DM_DBG1(("dmRegisterDevice: invalid port!!!\n"));
4528 return DM_RC_FAILURE;
4531 onePortContext->RegFailed = agFALSE;
4533 /* tdssAddSASToSharedcontext() from ossaHwCB()
4535 tdssAddSASToSharedcontext(
4536 tdsaPortContext_t *tdsaPortContext_Instance,
4538 agsaDevHandle_t *agDevHandle,
4539 tdsaSASSubID_t *agSASSubID,
4545 osGLOBAL tdsaDeviceData_t *
4546 tdssNewAddSASToSharedcontext(
4548 tdsaPortContext_t *onePortContext,
4549 tdsaSASSubID_t *agSASSubID,
4550 tdsaDeviceData_t *oneExpDeviceData,
4556 dmSASSubID.sasAddressHi = DM_GET_SAS_ADDRESSHI(dmDeviceInfo->sasAddressHi);
4557 dmSASSubID.sasAddressLo = DM_GET_SAS_ADDRESSHI(dmDeviceInfo->sasAddressLo);
4558 dmSASSubID.initiator_ssp_stp_smp = dmDeviceInfo->initiator_ssp_stp_smp;
4559 dmSASSubID.target_ssp_stp_smp = dmDeviceInfo->target_ssp_stp_smp;
4561 oneDeviceData = dmAddSASToSharedcontext(dmRoot, onePortContext, &dmSASSubID, agNULL, 0xFF);
4562 if (oneDeviceData == agNULL)
4564 DM_DBG1(("dmRegisterDevice: oneDeviceData is NULL!!!\n"));
4565 return DM_RC_FAILURE;
4567 oneDeviceData->agDeviceInfo.devType_S_Rate = dmDeviceInfo->devType_S_Rate;
4568 dm_memcpy(oneDeviceData->agDeviceInfo.sasAddressHi, dmDeviceInfo->sasAddressHi, 4);
4569 dm_memcpy(oneDeviceData->agDeviceInfo.sasAddressLo, dmDeviceInfo->sasAddressLo, 4);
4570 /* finds the type of expanders */
4571 if (DEVINFO_GET_EXT_SMP(dmDeviceInfo))
4573 if (DEVINFO_GET_EXT_EXPANDER_TYPE(dmDeviceInfo) == SAS_EDGE_EXPANDER_DEVICE)
4575 oneDeviceData->SASSpecDeviceType = SAS_EDGE_EXPANDER_DEVICE;
4577 else if (DEVINFO_GET_EXT_EXPANDER_TYPE(dmDeviceInfo) == SAS_FANOUT_EXPANDER_DEVICE)
4579 oneDeviceData->SASSpecDeviceType = SAS_FANOUT_EXPANDER_DEVICE;
4584 DM_DBG4(("dmRegisterDevice: no expander type. default to edge expander\n"));
4585 oneDeviceData->SASSpecDeviceType = SAS_EDGE_EXPANDER_DEVICE;
4589 if (DEVINFO_GET_EXT_MCN(dmDeviceInfo) == 0xF)
4591 DM_DBG1(("dmRegisterDevice: directly attached expander\n"));
4592 oneDeviceData->directlyAttached = agTRUE;
4593 oneDeviceData->dmDeviceInfo.ext = (bit16)(oneDeviceData->dmDeviceInfo.ext | (0xF << 11));
4597 DM_DBG1(("dmRegisterDevice: NOT directly attached expander\n"));
4598 oneDeviceData->directlyAttached = agFALSE;
4601 if (onePortContext->DiscoveryState == DM_DSTATE_NOT_STARTED)
4603 DM_DBG3(("dmRegisterDevice: DM_DSTATE_NOT_STARTED\n"));
4604 /* before the discovery is started */
4605 oneExpander = dmDiscoveringExpanderAlloc(dmRoot, onePortContext, oneDeviceData);
4606 if ( oneExpander != agNULL)
4608 oneExpander->agDevHandle = agDevHandle;
4609 /* update SAS address field */
4610 oneExpander->dmDevice->SASAddressID.sasAddressHi = DM_GET_SAS_ADDRESSHI(dmDeviceInfo->sasAddressHi);
4611 oneExpander->dmDevice->SASAddressID.sasAddressLo = DM_GET_SAS_ADDRESSLO(dmDeviceInfo->sasAddressLo);
4612 DM_DBG3(("dmRegisterDevice: AddrHi 0x%08x AddrLo 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressHi, oneExpander->dmDevice->SASAddressID.sasAddressLo));
4613 dmDiscoveringExpanderAdd(dmRoot, onePortContext, oneExpander);
4617 DM_DBG1(("dmRegisterDevice: failed to allocate expander !!!\n"));
4618 /* remember that the registration failed so that a discovery can't be started */
4619 onePortContext->RegFailed = agTRUE;
4620 return DM_RC_FAILURE;
4626 the discovery has started. Alloc and add have been done.
4627 find an expander using dmDeviceInfo, and update the expander's agDevHandle
4630 DM_DBG3(("dmRegisterDevice: NOT DM_DSTATE_NOT_STARTED\n"));
4631 sasAddressHi = DM_GET_SAS_ADDRESSHI(dmDeviceInfo->sasAddressHi);
4632 sasAddressLo = DM_GET_SAS_ADDRESSLO(dmDeviceInfo->sasAddressLo);
4633 DM_DBG3(("dmRegisterDevice: AddrHi 0x%08x AddrLo 0x%08x\n", sasAddressHi, sasAddressLo));
4634 oneExpander = dmExpFind(dmRoot, onePortContext, sasAddressHi, sasAddressLo);
4635 if ( oneExpander != agNULL)
4637 oneExpander->agDevHandle = agDevHandle;
4641 DM_DBG1(("dmRegisterDevice: not allowed case, wrong !!!\n"));
4642 return DM_RC_FAILURE;
4646 return DM_RC_SUCCESS;
4649 osGLOBAL dmExpander_t *
4650 dmDiscoveringExpanderAlloc(
4652 dmIntPortContext_t *onePortContext,
4653 dmDeviceData_t *oneDeviceData
4656 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
4657 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
4658 dmExpander_t *oneExpander = agNULL;
4659 dmList_t *ExpanderList;
4661 DM_DBG3(("dmDiscoveringExpanderAlloc: start\n"));
4662 DM_DBG3(("dmDiscoveringExpanderAlloc: did %d\n", oneDeviceData->id));
4663 DM_DBG3(("dmDiscoveringExpanderAlloc: sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
4664 DM_DBG3(("dmDiscoveringExpanderAlloc: sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
4666 if (onePortContext->valid == agFALSE)
4668 DM_DBG1(("dmDiscoveringExpanderAlloc: invalid port!!!\n"));
4673 /* check exitence in dmAllShared->mainExpanderList */
4674 oneExpander = dmExpMainListFind(dmRoot,
4676 oneDeviceData->SASAddressID.sasAddressHi,
4677 oneDeviceData->SASAddressID.sasAddressLo);
4679 if (oneExpander == agNULL)
4681 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
4682 if (DMLIST_EMPTY(&(dmAllShared->freeExpanderList)))
4684 DM_DBG1(("dmDiscoveringExpanderAlloc: no free expanders pid %d!!!\n", onePortContext->id));
4685 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
4690 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
4693 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
4694 DMLIST_DEQUEUE_FROM_HEAD(&ExpanderList, &(dmAllShared->freeExpanderList));
4695 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
4697 oneExpander = DMLIST_OBJECT_BASE(dmExpander_t, linkNode, ExpanderList);
4700 if (oneExpander != agNULL)
4702 DM_DBG1(("dmDiscoveringExpanderAlloc: pid %d exp id %d \n", onePortContext->id, oneExpander->id));
4704 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
4705 DMLIST_DEQUEUE_THIS(&(oneExpander->linkNode));
4706 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
4708 oneExpander->dmDevice = oneDeviceData;
4709 oneExpander->dmUpStreamExpander = agNULL;
4710 oneExpander->dmCurrentDownStreamExpander = agNULL;
4711 oneExpander->dmReturnginExpander = agNULL;
4712 oneExpander->hasUpStreamDevice = agFALSE;
4713 oneExpander->numOfUpStreamPhys = 0;
4714 oneExpander->currentUpStreamPhyIndex = 0;
4715 oneExpander->discoveringPhyId = 0;
4716 oneExpander->underDiscovering = agFALSE;
4717 dm_memset( &(oneExpander->currentIndex), 0, sizeof(oneExpander->currentIndex));
4719 oneDeviceData->dmExpander = oneExpander;
4720 DM_DBG3(("dmDiscoveringExpanderAlloc: oneDeviceData %p did %d\n", oneDeviceData, oneDeviceData->id));
4721 DM_DBG3(("dmDiscoveringExpanderAlloc: oneExpander %p did %d\n", oneDeviceData->dmExpander, oneDeviceData->dmExpander->id));
4729 dmDiscoveringExpanderAdd(
4731 dmIntPortContext_t *onePortContext,
4732 dmExpander_t *oneExpander
4735 DM_DBG3(("dmDiscoveringExpanderAdd: start\n"));
4736 DM_DBG3(("dmDiscoveringExpanderAdd: expander id %d\n", oneExpander->id));
4737 DM_DBG3(("dmDiscoveringExpanderAdd: exp addrHi 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressHi));
4738 DM_DBG3(("dmDiscoveringExpanderAdd: exp addrLo 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressLo));
4740 if (onePortContext->valid == agFALSE)
4742 DM_DBG1(("dmDiscoveringExpanderAdd: invalid port!!!\n"));
4745 if (onePortContext->discovery.status == DISCOVERY_UP_STREAM)
4747 DM_DBG3(("dmDiscoveringExpanderAdd: UPSTREAM\n"));
4749 else if (onePortContext->discovery.status == DISCOVERY_DOWN_STREAM)
4751 DM_DBG3(("dmDiscoveringExpanderAdd: DOWNSTREAM\n"));
4755 DM_DBG3(("dmDiscoveringExpanderAdd: status %d\n", onePortContext->discovery.status));
4758 if ( oneExpander->underDiscovering == agFALSE)
4760 DM_DBG3(("dmDiscoveringExpanderAdd: ADDED \n"));
4762 oneExpander->underDiscovering = agTRUE;
4763 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
4764 DMLIST_ENQUEUE_AT_TAIL(&(oneExpander->linkNode), &(onePortContext->discovery.discoveringExpanderList));
4765 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
4771 osGLOBAL dmExpander_t *
4772 dmFindConfigurableExp(
4774 dmIntPortContext_t *onePortContext,
4775 dmExpander_t *oneExpander
4778 dmExpander_t *tempExpander;
4779 dmIntPortContext_t *tmpOnePortContext = onePortContext;
4780 dmExpander_t *ret = agNULL;
4781 DM_DBG3(("dmFindConfigurableExp: start\n"));
4783 if (oneExpander == agNULL)
4785 DM_DBG3(("dmFindConfigurableExp: NULL expander\n"));
4789 DM_DBG3(("dmFindConfigurableExp: exp addrHi 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressHi));
4790 DM_DBG3(("dmFindConfigurableExp: exp addrLo 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressLo));
4792 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
4793 if (DMLIST_EMPTY(&(tmpOnePortContext->discovery.discoveringExpanderList)))
4795 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
4796 DM_DBG3(("dmFindConfigurableExp: empty UpdiscoveringExpanderList\n"));
4801 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
4803 tempExpander = oneExpander->dmUpStreamExpander;
4804 while (tempExpander)
4806 DM_DBG3(("dmFindConfigurableExp: loop exp addrHi 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressHi));
4807 DM_DBG3(("dmFindConfigurableExp: loop exp addrLo 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressLo));
4808 if (tempExpander->configRouteTable)
4810 DM_DBG3(("dmFindConfigurableExp: found configurable expander\n"));
4814 tempExpander = tempExpander->dmUpStreamExpander;
4821 dmDuplicateConfigSASAddr(
4823 dmExpander_t *oneExpander,
4824 bit32 configSASAddressHi,
4825 bit32 configSASAddressLo
4829 bit32 ret = agFALSE;
4830 DM_DBG3(("dmDuplicateConfigSASAddr: start\n"));
4832 if (oneExpander == agNULL)
4834 DM_DBG3(("dmDuplicateConfigSASAddr: NULL expander\n"));
4838 if (oneExpander->dmDevice->SASAddressID.sasAddressHi == configSASAddressHi &&
4839 oneExpander->dmDevice->SASAddressID.sasAddressLo == configSASAddressLo
4842 DM_DBG3(("dmDuplicateConfigSASAddr: unnecessary\n"));
4846 DM_DBG3(("dmDuplicateConfigSASAddr: exp addrHi 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressHi));
4847 DM_DBG3(("dmDuplicateConfigSASAddr: exp addrLo 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressLo));
4848 DM_DBG3(("dmDuplicateConfigSASAddr: configsasAddressHi 0x%08x\n", configSASAddressHi));
4849 DM_DBG3(("dmDuplicateConfigSASAddr: configsasAddressLo 0x%08x\n", configSASAddressLo));
4850 DM_DBG3(("dmDuplicateConfigSASAddr: configSASAddrTableIndex %d\n", oneExpander->configSASAddrTableIndex));
4851 for(i=0;i<oneExpander->configSASAddrTableIndex;i++)
4853 if (oneExpander->configSASAddressHiTable[i] == configSASAddressHi &&
4854 oneExpander->configSASAddressLoTable[i] == configSASAddressLo
4857 DM_DBG3(("dmDuplicateConfigSASAddr: FOUND\n"));
4862 /* new one; let's add it */
4865 DM_DBG3(("dmDuplicateConfigSASAddr: adding configSAS Addr\n"));
4866 DM_DBG3(("dmDuplicateConfigSASAddr: configSASAddrTableIndex %d\n", oneExpander->configSASAddrTableIndex));
4867 oneExpander->configSASAddressHiTable[oneExpander->configSASAddrTableIndex] = configSASAddressHi;
4868 oneExpander->configSASAddressLoTable[oneExpander->configSASAddrTableIndex] = configSASAddressLo;
4869 oneExpander->configSASAddrTableIndex++;
4876 dmFindCurrentDownStreamPhyIndex(
4878 dmExpander_t *oneExpander
4881 dmExpander_t *DownStreamExpander;
4886 DM_DBG3(("dmFindCurrentDownStreamPhyIndex: start\n"));
4888 if (oneExpander == agNULL)
4890 DM_DBG1(("dmFindCurrentDownStreamPhyIndex: wrong, oneExpander is NULL!!!\n"));
4894 DownStreamExpander = oneExpander->dmCurrentDownStreamExpander;
4896 if (DownStreamExpander == agNULL)
4898 DM_DBG1(("dmFindCurrentDownStreamPhyIndex: wrong, DownStreamExpander is NULL!!!\n"));
4902 DM_DBG3(("dmFindCurrentDownStreamPhyIndex: exp addrHi 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressHi));
4903 DM_DBG3(("dmFindCurrentDownStreamPhyIndex: exp addrLo 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressLo));
4904 DM_DBG3(("dmFindCurrentDownStreamPhyIndex: downstream exp addrHi 0x%08x\n", DownStreamExpander->dmDevice->SASAddressID.sasAddressHi));
4905 DM_DBG3(("dmFindCurrentDownStreamPhyIndex: downstream exp addrLo 0x%08x\n", DownStreamExpander->dmDevice->SASAddressID.sasAddressLo));
4906 DM_DBG3(("dmFindCurrentDownStreamPhyIndex: numOfDownStreamPhys %d\n", oneExpander->numOfDownStreamPhys));
4908 phyId = DownStreamExpander->upStreamPhys[0];
4910 DM_DBG3(("dmFindCurrentDownStreamPhyIndex: phyId %d\n", phyId));
4912 for (i=0; i<oneExpander->numOfDownStreamPhys;i++)
4914 if (oneExpander->downStreamPhys[i] == phyId)
4920 DM_DBG3(("dmFindCurrentDownStreamPhyIndex: index %d\n", index));
4925 dmFindDiscoveringExpander(
4927 dmIntPortContext_t *onePortContext,
4928 dmExpander_t *oneExpander
4931 dmList_t *ExpanderList;
4932 dmExpander_t *tempExpander;
4933 dmIntPortContext_t *tmpOnePortContext = onePortContext;
4934 bit32 ret = agFALSE;
4937 DM_DBG3(("dmFindDiscoveringExpander: start\n"));
4939 DM_DBG3(("dmFindDiscoveringExpander: exp addrHi 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressHi));
4940 DM_DBG3(("dmFindDiscoveringExpander: exp addrLo 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressLo));
4942 if (DMLIST_EMPTY(&(tmpOnePortContext->discovery.discoveringExpanderList)))
4944 DM_DBG3(("dmFindDiscoveringExpander: empty discoveringExpanderList\n"));
4947 ExpanderList = tmpOnePortContext->discovery.discoveringExpanderList.flink;
4948 while (ExpanderList != &(tmpOnePortContext->discovery.discoveringExpanderList))
4950 tempExpander = DMLIST_OBJECT_BASE(dmExpander_t, linkNode, ExpanderList);
4951 if (tempExpander == oneExpander)
4953 if (tempExpander != agNULL)
4955 DM_DBG3(("dmFindDiscoveringExpander: match, expander id %d\n", tempExpander->id));
4956 DM_DBG3(("dmFindDiscoveringExpander: exp addrHi 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressHi));
4957 DM_DBG3(("dmFindDiscoveringExpander: exp addrLo 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressLo));
4963 ExpanderList = ExpanderList->flink;
4972 dmDiscoveringExpanderRemove(
4974 dmIntPortContext_t *onePortContext,
4975 dmExpander_t *oneExpander
4978 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
4979 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
4981 DM_DBG3(("dmDiscoveringExpanderRemove: start\n"));
4982 DM_DBG3(("dmDiscoveringExpanderRemove: expander id %d\n", oneExpander->id));
4983 DM_DBG3(("dmDiscoveringExpanderRemove: exp addrHi 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressHi));
4984 DM_DBG3(("dmDiscoveringExpanderRemove: exp addrLo 0x%08x\n", oneExpander->dmDevice->SASAddressID.sasAddressLo));
4986 DM_DBG3(("dmDiscoveringExpanderRemove: BEFORE\n"));
4987 dmDumpAllExp(dmRoot, onePortContext, oneExpander);
4988 dmDumpAllUpExp(dmRoot, onePortContext, oneExpander);
4989 dmDumpAllFreeExp(dmRoot);
4991 // if is temporary till smp problem is fixed
4992 if (dmFindDiscoveringExpander(dmRoot, onePortContext, oneExpander) == agTRUE)
4994 DM_DBG3(("dmDiscoveringExpanderRemove: oneDeviceData %p did %d\n", oneExpander->dmDevice, oneExpander->dmDevice->id));
4995 DM_DBG3(("dmDiscoveringExpanderRemove: oneExpander %p did %d\n", oneExpander, oneExpander->id));
4997 if (oneExpander != oneExpander->dmDevice->dmExpander)
4999 DM_DBG3(("dmDiscoveringExpanderRemove: before !!! wrong !!!\n"));
5001 oneExpander->underDiscovering = agFALSE;
5002 oneExpander->discoveringPhyId = 0;
5003 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
5004 DMLIST_DEQUEUE_THIS(&(oneExpander->linkNode));
5005 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
5007 if (onePortContext->discovery.status == DISCOVERY_UP_STREAM)
5009 DM_DBG3(("dmDiscoveringExpanderRemove: DISCOVERY_UP_STREAM\n"));
5010 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
5011 DMLIST_ENQUEUE_AT_TAIL(&(oneExpander->upNode), &(onePortContext->discovery.UpdiscoveringExpanderList));
5012 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
5013 onePortContext->discovery.NumOfUpExp++;
5017 DM_DBG3(("dmDiscoveringExpanderRemove: Status %d\n", onePortContext->discovery.status));
5018 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
5019 DMLIST_ENQUEUE_AT_TAIL(&(oneExpander->linkNode), &(dmAllShared->mainExpanderList));
5020 // DMLIST_ENQUEUE_AT_TAIL(&(oneExpander->linkNode), &(dmAllShared->freeExpanderList));
5021 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
5024 if (oneExpander != oneExpander->dmDevice->dmExpander)
5026 DM_DBG3(("dmDiscoveringExpanderRemove: after !!! wrong !!!\n"));
5032 DM_DBG1(("dmDiscoveringExpanderRemove: !!! problem !!!\n"));
5035 DM_DBG3(("dmDiscoveringExpanderRemove: AFTER\n"));
5037 dmDumpAllExp(dmRoot, onePortContext, oneExpander);
5038 dmDumpAllUpExp(dmRoot, onePortContext, oneExpander);
5039 dmDumpAllFreeExp(dmRoot);
5045 returns an expander with sasAddrLo, sasAddrHi from dmAllShared->mainExpanderList
5047 osGLOBAL dmExpander_t *
5050 dmIntPortContext_t *onePortContext,
5055 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
5056 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
5057 dmList_t *ExpanderList;
5058 dmExpander_t *tempExpander;
5060 DM_DBG3(("dmExpMainListFind: start\n"));
5062 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
5063 if (DMLIST_EMPTY(&(dmAllShared->mainExpanderList)))
5065 DM_DBG1(("dmExpMainListFind: empty mainExpanderList\n"));
5066 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
5071 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
5073 ExpanderList = dmAllShared->mainExpanderList.flink;
5074 while (ExpanderList != &(dmAllShared->mainExpanderList))
5076 tempExpander = DMLIST_OBJECT_BASE(dmExpander_t, linkNode, ExpanderList);
5077 if (tempExpander == agNULL)
5079 DM_DBG1(("dmExpMainListFind: tempExpander is NULL!!!\n"));
5082 DM_DBG3(("dmExpMainListFind: expander id %d\n", tempExpander->id));
5083 DM_DBG3(("dmExpMainListFind: exp addrHi 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressHi));
5084 DM_DBG3(("dmExpMainListFind: exp addrLo 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressLo));
5085 if ((tempExpander->dmDevice->SASAddressID.sasAddressHi == sasAddrHi) &&
5086 (tempExpander->dmDevice->SASAddressID.sasAddressLo == sasAddrLo) &&
5087 (tempExpander->dmDevice->dmPortContext == onePortContext)
5090 DM_DBG3(("dmExpMainListFind: found expander id %d\n", tempExpander->id));
5091 DM_DBG3(("dmExpMainListFind: found exp addrHi 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressHi));
5092 DM_DBG3(("dmExpMainListFind: found exp addrLo 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressLo));
5093 return tempExpander;
5095 ExpanderList = ExpanderList->flink;
5102 returns an expander with sasAddrLo, sasAddrHi from discoveringExpanderList
5104 osGLOBAL dmExpander_t *
5107 dmIntPortContext_t *onePortContext,
5112 dmList_t *ExpanderList;
5113 dmExpander_t *tempExpander;
5114 dmIntPortContext_t *tmpOnePortContext = onePortContext;
5115 DM_DBG3(("dmExpFind: start\n"));
5117 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
5118 if (DMLIST_EMPTY(&(tmpOnePortContext->discovery.discoveringExpanderList)))
5120 DM_DBG3(("dmExpFind tdsaDumpAllExp: empty discoveringExpanderList\n"));
5121 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
5126 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
5128 ExpanderList = tmpOnePortContext->discovery.discoveringExpanderList.flink;
5129 while (ExpanderList != &(tmpOnePortContext->discovery.discoveringExpanderList))
5131 tempExpander = DMLIST_OBJECT_BASE(dmExpander_t, linkNode, ExpanderList);
5132 if (tempExpander == agNULL)
5134 DM_DBG1(("dmExpFind: tempExpander is NULL!!!\n"));
5137 DM_DBG3(("dmExpFind: expander id %d\n", tempExpander->id));
5138 DM_DBG3(("dmExpFind: exp addrHi 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressHi));
5139 DM_DBG3(("dmExpFind: exp addrLo 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressLo));
5140 if ((tempExpander->dmDevice->SASAddressID.sasAddressHi == sasAddrHi) &&
5141 (tempExpander->dmDevice->SASAddressID.sasAddressLo == sasAddrLo) &&
5142 (tempExpander->dmDevice->dmPortContext == onePortContext)
5145 DM_DBG3(("dmExpFind: found\n"));
5146 return tempExpander;
5148 ExpanderList = ExpanderList->flink;
5156 dmIntPortContext_t *onePortContext
5159 DM_DBG3(("dmDiscoverCheck: start\n"));
5161 if (onePortContext == agNULL)
5163 DM_DBG1(("dmDiscoverCheck: onePortContext is NULL!!!\n"));
5166 if (onePortContext->valid == agFALSE)
5168 DM_DBG1(("dmDiscoverCheck: invalid port!!!\n"));
5171 if (onePortContext->DiscoveryState == DM_DSTATE_COMPLETED ||
5172 onePortContext->discovery.status == DISCOVERY_SAS_DONE
5175 DM_DBG1(("dmDiscoverCheck: aborted discovery!!!\n"));
5178 onePortContext->dmPortContext,
5187 /* ??? needs to handle pending SMPs
5188 move from dmAllShared->discoveringExpanderList to dmAllShared->mainExpanderList
5193 dmIntPortContext_t *onePortContext
5196 DM_DBG1(("dmDiscoverAbort: start\n"));
5198 if (onePortContext->DiscoveryState == DM_DSTATE_COMPLETED ||
5199 onePortContext->discovery.status == DISCOVERY_SAS_DONE)
5201 DM_DBG1(("dmDiscoverAbort: not allowed case!!! onePortContext->DiscoveryState 0x%x onePortContext->discovery.status 0x%x\n",
5202 onePortContext->DiscoveryState, onePortContext->discovery.status));
5206 onePortContext->DiscoveryState = DM_DSTATE_COMPLETED;
5207 onePortContext->discovery.status = DISCOVERY_SAS_DONE;
5209 /* move from dmAllShared->discoveringExpanderList to dmAllShared->mainExpanderList */
5210 dmCleanAllExp(dmRoot, onePortContext);
5218 /* move from dmAllShared->discoveringExpanderList to dmAllShared->mainExpanderList */
5222 dmIntPortContext_t *onePortContext
5225 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
5226 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
5227 dmList_t *ExpanderList;
5228 dmExpander_t *tempExpander;
5229 dmExpander_t *oneExpander = agNULL;
5230 dmIntPortContext_t *tmpOnePortContext = onePortContext;
5232 DM_DBG3(("dmCleanAllExp: start\n"));
5233 DM_DBG3(("dmCleanAllExp: pid %d\n", onePortContext->id));
5235 DM_DBG3(("dmCleanAllExp: before all clean up\n"));
5236 dmDumpAllFreeExp(dmRoot);
5238 /* clean up UpdiscoveringExpanderList*/
5239 DM_DBG3(("dmCleanAllExp: clean discoveringExpanderList\n"));
5240 if (!DMLIST_EMPTY(&(tmpOnePortContext->discovery.discoveringExpanderList)))
5242 ExpanderList = tmpOnePortContext->discovery.discoveringExpanderList.flink;
5243 while (ExpanderList != &(tmpOnePortContext->discovery.discoveringExpanderList))
5245 tempExpander = DMLIST_OBJECT_BASE(dmExpander_t, linkNode, ExpanderList);
5246 if (tempExpander == agNULL)
5248 DM_DBG1(("dmCleanAllExp: tempExpander is NULL!!!\n"));
5251 DM_DBG3(("dmCleanAllExp: exp addrHi 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressHi));
5252 DM_DBG3(("dmCleanAllExp: exp addrLo 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressLo));
5253 DM_DBG3(("dmCleanAllExp: exp id %d\n", tempExpander->id));
5255 oneExpander = dmExpMainListFind(dmRoot,
5257 tempExpander->dmDevice->SASAddressID.sasAddressHi,
5258 tempExpander->dmDevice->SASAddressID.sasAddressLo);
5259 if (oneExpander == agNULL)
5261 DM_DBG3(("dmCleanAllExp: moving\n"));
5262 DM_DBG3(("dmCleanAllExp: moving, exp id %d\n", tempExpander->id));
5263 /* putting back to the free pool */
5264 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
5265 DMLIST_DEQUEUE_THIS(&(tempExpander->linkNode));
5266 // DMLIST_ENQUEUE_AT_TAIL(&(tempExpander->linkNode), &(dmAllShared->freeExpanderList));
5267 DMLIST_ENQUEUE_AT_TAIL(&(tempExpander->linkNode), &(dmAllShared->mainExpanderList));
5269 if (DMLIST_EMPTY(&(tmpOnePortContext->discovery.discoveringExpanderList)))
5271 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
5276 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
5278 ExpanderList = tmpOnePortContext->discovery.discoveringExpanderList.flink;
5282 DM_DBG3(("dmCleanAllExp: in mainExpanderList; skippig\n"));
5283 ExpanderList = ExpanderList->flink;
5289 DM_DBG3(("dmCleanAllExp: empty discoveringExpanderList\n"));
5292 /* reset discoveringExpanderList */
5293 DMLIST_INIT_HDR(&(tmpOnePortContext->discovery.discoveringExpanderList));
5295 /* clean up UpdiscoveringExpanderList*/
5296 DM_DBG3(("dmCleanAllExp: clean UpdiscoveringExpanderList\n"));
5297 if (DMLIST_EMPTY(&(tmpOnePortContext->discovery.UpdiscoveringExpanderList)))
5299 DM_DBG3(("dmCleanAllExp: empty UpdiscoveringExpanderList\n"));
5302 ExpanderList = tmpOnePortContext->discovery.UpdiscoveringExpanderList.flink;
5303 while (ExpanderList != &(tmpOnePortContext->discovery.UpdiscoveringExpanderList))
5305 tempExpander = DMLIST_OBJECT_BASE(dmExpander_t, upNode, ExpanderList);
5306 if (tempExpander == agNULL)
5308 DM_DBG1(("dmCleanAllExp: tempExpander is NULL!!!\n"));
5311 DM_DBG3(("dmCleanAllExp: exp addrHi 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressHi));
5312 DM_DBG3(("dmCleanAllExp: exp addrLo 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressLo));
5313 DM_DBG3(("dmCleanAllExp: exp id %d\n", tempExpander->id));
5314 oneExpander = dmExpMainListFind(dmRoot,
5316 tempExpander->dmDevice->SASAddressID.sasAddressHi,
5317 tempExpander->dmDevice->SASAddressID.sasAddressLo);
5318 if (oneExpander == agNULL)
5320 DM_DBG3(("dmCleanAllExp: moving\n"));
5321 DM_DBG3(("dmCleanAllExp: moving exp id %d\n", tempExpander->id));
5322 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
5323 DMLIST_DEQUEUE_THIS(&(tempExpander->upNode));
5324 DMLIST_ENQUEUE_AT_TAIL(&(tempExpander->linkNode), &(dmAllShared->mainExpanderList));
5326 if (DMLIST_EMPTY(&(tmpOnePortContext->discovery.UpdiscoveringExpanderList)))
5328 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
5333 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
5335 ExpanderList = tmpOnePortContext->discovery.UpdiscoveringExpanderList.flink;
5339 DM_DBG3(("dmCleanAllExp: in mainExpanderList; skippig\n"));
5340 ExpanderList = ExpanderList->flink;
5344 /* reset UpdiscoveringExpanderList */
5345 DMLIST_INIT_HDR(&(tmpOnePortContext->discovery.UpdiscoveringExpanderList));
5347 DM_DBG3(("dmCleanAllExp: after all clean up\n"));
5348 dmDumpAllFreeExp(dmRoot);
5356 dmIntPortContext_t *onePortContext
5359 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
5360 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
5361 dmDeviceData_t *oneDeviceData = agNULL;
5362 dmList_t *DeviceListList;
5365 DM_DBG3(("dmInternalRemovals: start\n"));
5366 tddmSingleThreadedEnter(dmRoot, DM_DEVICE_LOCK);
5367 if (DMLIST_EMPTY(&(dmAllShared->MainDeviceList)))
5369 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
5370 DM_DBG3(("dmInternalRemovals: empty device list\n"));
5375 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
5378 DeviceListList = dmAllShared->MainDeviceList.flink;
5379 while (DeviceListList != &(dmAllShared->MainDeviceList))
5381 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
5382 if (oneDeviceData == agNULL)
5384 DM_DBG1(("dmInternalRemovals: oneDeviceData is NULL!!!\n"));
5387 DM_DBG3(("dmInternalRemovals: loop did %d\n", oneDeviceData->id));
5388 DM_DBG3(("dmInternalRemovals: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
5389 DM_DBG3(("dmInternalRemovals: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
5390 DM_DBG3(("dmInternalRemovals: valid %d\n", oneDeviceData->valid));
5391 DM_DBG3(("dmInternalRemovals: valid2 %d\n", oneDeviceData->valid2));
5392 DM_DBG3(("dmInternalRemovals: directlyAttached %d\n", oneDeviceData->directlyAttached));
5393 if ( oneDeviceData->dmPortContext == onePortContext)
5395 DM_DBG3(("dmInternalRemovals: right portcontext pid %d\n", onePortContext->id));
5396 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_INCREMENTAL_START)
5398 DM_DBG3(("dmInternalRemovals: incremental discovery\n"));
5399 oneDeviceData->valid2 = agFALSE;
5403 DM_DBG3(("dmInternalRemovals: full discovery\n"));
5404 oneDeviceData->valid = agFALSE;
5406 DeviceListList = DeviceListList->flink;
5410 if (oneDeviceData->dmPortContext != agNULL)
5412 DM_DBG3(("dmInternalRemovals: different portcontext; oneDeviceData->dmPortContext pid %d oneportcontext pid %d\n", oneDeviceData->dmPortContext->id, onePortContext->id));
5416 DM_DBG3(("dmInternalRemovals: different portcontext; oneDeviceData->dmPortContext pid NULL oneportcontext pid %d\n", onePortContext->id));
5418 DeviceListList = DeviceListList->flink;
5427 dmDiscoveryResetProcessed(
5429 dmIntPortContext_t *onePortContext
5432 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
5433 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
5434 dmDeviceData_t *oneDeviceData = agNULL;
5435 dmList_t *DeviceListList;
5437 DM_DBG3(("dmDiscoveryResetProcessed: start\n"));
5439 /* reinitialize the device data belonging to this portcontext */
5440 DeviceListList = dmAllShared->MainDeviceList.flink;
5441 while (DeviceListList != &(dmAllShared->MainDeviceList))
5443 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
5444 if (oneDeviceData == agNULL)
5446 DM_DBG1(("dmDiscoveryResetProcessed: oneDeviceData is NULL!!!\n"));
5449 DM_DBG3(("dmDiscoveryResetProcessed: loop did %d\n", oneDeviceData->id));
5450 if (oneDeviceData->dmPortContext == onePortContext)
5452 DM_DBG3(("dmDiscoveryResetProcessed: resetting procssed flag\n"));
5453 oneDeviceData->processed = agFALSE;
5455 DeviceListList = DeviceListList->flink;
5466 dmPortContext_t *dmPortContext,
5474 dmIntPortContext_t *onePortContext,
5479 DM_DBG3(("dmDiscoverDone: start\n"));
5480 DM_DBG3(("dmDiscoverDone: pid %d\n", onePortContext->id));
5482 /* Set discovery status */
5483 onePortContext->discovery.status = DISCOVERY_SAS_DONE;
5486 /* clean up expanders data strucures; move to free exp when device is cleaned */
5487 dmCleanAllExp(dmRoot, onePortContext);
5489 dmDumpAllMainExp(dmRoot, onePortContext);
5491 dmDiscoveryResetProcessed(dmRoot, onePortContext);
5493 dmDiscoveryDumpMCN(dmRoot, onePortContext);
5495 if (onePortContext->discovery.SeenBC == agTRUE)
5497 DM_DBG3(("dmDiscoverDone: broadcast change; discover again\n"));
5498 dmDiscoveryResetMCN(dmRoot, onePortContext);
5500 dmInternalRemovals(dmRoot, onePortContext);
5502 /* processed broadcast change */
5503 onePortContext->discovery.SeenBC = agFALSE;
5504 if (onePortContext->discovery.ResetTriggerred == agTRUE)
5506 DM_DBG3(("dmDiscoverDone: dmBCTimer\n"));
5507 dmBCTimer(dmRoot, onePortContext);
5512 dmIncrementalDiscover(dmRoot, onePortContext, agTRUE);
5517 onePortContext->DiscoveryState = DM_DSTATE_COMPLETED;
5519 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_FULL_START)
5521 if (flag == DM_RC_SUCCESS)
5524 dmResetReported(dmRoot,
5528 dmDiscoveryReportMCN(dmRoot,
5533 /* call tddmDiscoverCB() */
5536 onePortContext->dmPortContext,
5540 else if (flag != DM_RC_SUCCESS || onePortContext->discovery.DeferredError == agTRUE)
5542 onePortContext->DiscoveryState = DM_DSTATE_COMPLETED_WITH_FAILURE;
5543 DM_DBG1(("dmDiscoverDone: Error; clean up!!!\n"));
5545 dmDiscoveryInvalidateDevices(dmRoot,
5551 onePortContext->dmPortContext,
5558 if (flag == DM_RC_SUCCESS)
5560 dmReportChanges(dmRoot,
5563 dmDiscoveryReportMCN(dmRoot,
5568 onePortContext->dmPortContext,
5572 else if (flag != DM_RC_SUCCESS || onePortContext->discovery.DeferredError == agTRUE)
5574 onePortContext->DiscoveryState = DM_DSTATE_COMPLETED_WITH_FAILURE;
5575 dmDiscoveryInvalidateDevices(dmRoot,
5581 onePortContext->dmPortContext,
5590 /* called by dmDiscoveryErrorRemovals() or dmReportRemovals() on discovery failure */
5592 dmSubReportRemovals(
5594 dmIntPortContext_t *onePortContext,
5595 dmDeviceData_t *oneDeviceData,
5599 dmDeviceData_t *oneAttachedExpDeviceData = agNULL;
5600 DM_DBG3(("dmSubReportRemovals: start\n"));
5602 DM_DBG3(("dmSubReportRemovals: flag 0x%x\n", flag));
5603 if (flag == dmDeviceRemoval)
5605 oneDeviceData->registered = agFALSE;
5608 if (oneDeviceData->ExpDevice != agNULL)
5610 DM_DBG3(("dmSubReportRemovals: attached expander case\n"));
5611 oneAttachedExpDeviceData = oneDeviceData->ExpDevice;
5612 tddmReportDevice(dmRoot, onePortContext->dmPortContext, &oneDeviceData->dmDeviceInfo, &oneAttachedExpDeviceData->dmDeviceInfo, flag);
5616 DM_DBG3(("dmSubReportRemovals: NO attached expander case\n"));
5617 tddmReportDevice(dmRoot, onePortContext->dmPortContext, &oneDeviceData->dmDeviceInfo, agNULL, flag);
5621 /* this function is called at the end of discovery; reinitalizes oneDeviceData->reported */
5622 oneDeviceData->reported = agFALSE;
5627 /* called by dmReportChanges() on discovery success */
5631 dmIntPortContext_t *onePortContext,
5632 dmDeviceData_t *oneDeviceData,
5636 dmDeviceData_t *oneAttachedExpDeviceData = agNULL;
5637 DM_DBG3(("dmSubReportChanges: start\n"));
5639 DM_DBG3(("dmSubReportChanges: flag 0x%x\n", flag));
5640 if (flag == dmDeviceRemoval)
5642 oneDeviceData->registered = agFALSE;
5644 if (oneDeviceData->reported == agFALSE)
5646 if (oneDeviceData->ExpDevice != agNULL)
5648 DM_DBG3(("dmSubReportChanges: attached expander case\n"));
5649 oneAttachedExpDeviceData = oneDeviceData->ExpDevice;
5650 tddmReportDevice(dmRoot, onePortContext->dmPortContext, &oneDeviceData->dmDeviceInfo, &oneAttachedExpDeviceData->dmDeviceInfo, flag);
5654 DM_DBG3(("dmSubReportChanges: NO attached expander case\n"));
5655 tddmReportDevice(dmRoot, onePortContext->dmPortContext, &oneDeviceData->dmDeviceInfo, agNULL, flag);
5660 DM_DBG3(("dmSubReportChanges: skip; been reported\n"));
5664 /* this function is called at the end of discovery; reinitalizes oneDeviceData->reported */
5665 oneDeviceData->reported = agFALSE;
5670 should add or remove be reported per device???
5675 dmIntPortContext_t *onePortContext
5678 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
5679 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
5680 dmDeviceData_t *oneDeviceData = agNULL;
5681 dmList_t *DeviceListList;
5682 bit32 added = agFALSE, removed = agFALSE;
5683 // dmDeviceData_t *oneAttachedExpDeviceData = agNULL;
5685 DM_DBG3(("dmReportChanges: start\n"));
5687 tddmSingleThreadedEnter(dmRoot, DM_DEVICE_LOCK);
5688 if (DMLIST_EMPTY(&(dmAllShared->MainDeviceList)))
5690 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
5691 DM_DBG3(("dmReportChanges: empty device list\n"));
5696 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
5699 DeviceListList = dmAllShared->MainDeviceList.flink;
5700 while (DeviceListList != &(dmAllShared->MainDeviceList))
5702 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
5703 if (oneDeviceData == agNULL)
5705 DM_DBG1(("dmReportChanges: oneDeviceData is NULL!!!\n"));
5708 DM_DBG3(("dmReportChanges: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
5709 DM_DBG3(("dmReportChanges: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
5710 if ( oneDeviceData->dmPortContext == onePortContext)
5712 DM_DBG3(("dmReportChanges: right portcontext\n"));
5713 if (oneDeviceData->SASAddressID.sasAddressHi == onePortContext->sasRemoteAddressHi &&
5714 oneDeviceData->SASAddressID.sasAddressLo == onePortContext->sasRemoteAddressLo
5717 DM_DBG1(("dmReportChanges: keep, not reporting did 0x%x\n", oneDeviceData->id));
5718 oneDeviceData->valid = agTRUE;
5719 oneDeviceData->valid2 = agFALSE;
5721 else if ( (oneDeviceData->valid == agTRUE) && (oneDeviceData->valid2 == agTRUE) )
5723 DM_DBG3(("dmReportChanges: same\n"));
5724 /* reset valid bit */
5725 oneDeviceData->valid = oneDeviceData->valid2;
5726 oneDeviceData->valid2 = agFALSE;
5727 dmSubReportChanges(dmRoot, onePortContext, oneDeviceData, dmDeviceNoChange);
5729 else if ( (oneDeviceData->valid == agTRUE) && (oneDeviceData->valid2 == agFALSE) )
5731 DM_DBG3(("dmReportChanges: removed\n"));
5733 /* reset valid bit */
5734 oneDeviceData->valid = oneDeviceData->valid2;
5735 oneDeviceData->valid2 = agFALSE;
5737 onePortContext->RegisteredDevNums--;
5738 dmSubReportChanges(dmRoot, onePortContext, oneDeviceData, dmDeviceRemoval);
5740 else if ( (oneDeviceData->valid == agFALSE) && (oneDeviceData->valid2 == agTRUE) )
5742 DM_DBG3(("dmReportChanges: added\n"));
5744 /* reset valid bit */
5745 oneDeviceData->valid = oneDeviceData->valid2;
5746 oneDeviceData->valid2 = agFALSE;
5747 dmSubReportChanges(dmRoot, onePortContext, oneDeviceData, dmDeviceArrival);
5751 DM_DBG3(("dmReportChanges: else\n"));
5756 DM_DBG3(("dmReportChanges: different portcontext\n"));
5758 DeviceListList = DeviceListList->flink;
5764 dmPortContext_t *dmPortContext,
5765 dmDeviceInfo_t *dmDeviceInfo,
5766 dmDeviceInfo_t *dmExpDeviceInfo,
5773 /* arrival or removal at once */
5774 if (added == agTRUE)
5776 DM_DBG3(("dmReportChanges: added at the end\n"));
5780 onePortContext->tiPortalContext,
5782 tiIntrEventTypeDeviceChange,
5789 if (removed == agTRUE)
5791 DM_DBG3(("dmReportChanges: removed at the end\n"));
5795 onePortContext->tiPortalContext,
5797 tiIntrEventTypeDeviceChange,
5804 if (onePortContext->discovery.forcedOK == agTRUE && added == agFALSE && removed == agFALSE)
5806 DM_DBG3(("dmReportChanges: missed chance to report. forced to report OK\n"));
5807 onePortContext->discovery.forcedOK = agFALSE;
5811 onePortContext->tiPortalContext,
5813 tiIntrEventTypeDiscovery,
5820 if (added == agFALSE && removed == agFALSE)
5822 DM_DBG3(("dmReportChanges: the same\n"));
5831 dmIntPortContext_t *onePortContext,
5835 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
5836 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
5837 dmDeviceData_t *oneDeviceData = agNULL;
5838 dmList_t *DeviceListList;
5839 bit32 removed = agFALSE;
5841 DM_DBG1(("dmReportRemovals: start\n"));
5843 tddmSingleThreadedEnter(dmRoot, DM_DEVICE_LOCK);
5844 if (DMLIST_EMPTY(&(dmAllShared->MainDeviceList)))
5846 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
5847 DM_DBG3(("dmReportRemovals: empty device list\n"));
5852 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
5855 DeviceListList = dmAllShared->MainDeviceList.flink;
5856 while (DeviceListList != &(dmAllShared->MainDeviceList))
5858 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
5859 if (oneDeviceData == agNULL)
5861 DM_DBG1(("dmReportRemovals: oneDeviceData is NULL!!!\n"));
5864 DM_DBG3(("dmReportRemovals: loop did %d\n", oneDeviceData->id));
5865 DM_DBG3(("dmReportRemovals: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
5866 DM_DBG3(("dmReportRemovals: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
5867 DM_DBG3(("dmReportRemovals: valid %d\n", oneDeviceData->valid));
5868 DM_DBG3(("dmReportRemovals: valid2 %d\n", oneDeviceData->valid2));
5869 DM_DBG3(("dmReportRemovals: directlyAttached %d\n", oneDeviceData->directlyAttached));
5870 if ( oneDeviceData->dmPortContext == onePortContext)
5872 DM_DBG3(("dmReportRemovals: right portcontext pid %d\n", onePortContext->id));
5873 if (oneDeviceData->SASAddressID.sasAddressHi == onePortContext->sasRemoteAddressHi &&
5874 oneDeviceData->SASAddressID.sasAddressLo == onePortContext->sasRemoteAddressLo
5877 DM_DBG1(("dmReportRemovals: keeping\n"));
5878 oneDeviceData->valid = agTRUE;
5879 oneDeviceData->valid2 = agFALSE;
5881 else if (oneDeviceData->valid == agTRUE)
5883 DM_DBG3(("dmReportRemovals: removing\n"));
5885 /* notify only reported devices to OS layer*/
5886 if ( DEVICE_IS_SSP_TARGET(oneDeviceData) ||
5887 DEVICE_IS_STP_TARGET(oneDeviceData) ||
5888 DEVICE_IS_SATA_DEVICE(oneDeviceData)
5894 /* all targets except expanders */
5895 DM_DBG3(("dmReportRemovals: did %d\n", oneDeviceData->id));
5896 DM_DBG3(("dmReportRemovals: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
5897 DM_DBG3(("dmReportRemovals: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
5898 onePortContext->RegisteredDevNums--;
5899 dmSubReportRemovals(dmRoot, onePortContext, oneDeviceData, dmDeviceRemoval);
5902 /* reset valid bit */
5903 oneDeviceData->valid = agFALSE;
5904 oneDeviceData->valid2 = agFALSE;
5908 /* called by port invalid case */
5911 oneDeviceData->dmPortContext = agNULL;
5913 DeviceListList = DeviceListList->flink;
5917 if (oneDeviceData->dmPortContext != agNULL)
5919 DM_DBG3(("dmReportRemovals: different portcontext; oneDeviceData->dmPortContext pid %d oneportcontext pid %d\n", oneDeviceData->dmPortContext->id, onePortContext->id));
5923 DM_DBG3(("dmReportRemovals: different portcontext; oneDeviceData->dmPortContext pid NULL oneportcontext pid %d\n", onePortContext->id));
5925 DeviceListList = DeviceListList->flink;
5929 if (removed == agTRUE)
5931 DM_DBG3(("dmReportRemovals: removed at the end\n"));
5935 onePortContext->tiPortalContext,
5937 tiIntrEventTypeDeviceChange,
5950 dmIntPortContext_t *onePortContext
5953 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
5954 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
5955 dmDeviceData_t *oneDeviceData = agNULL;
5956 dmList_t *DeviceListList;
5958 DM_DBG3(("dmResetReported: start\n"));
5960 tddmSingleThreadedEnter(dmRoot, DM_DEVICE_LOCK);
5961 if (DMLIST_EMPTY(&(dmAllShared->MainDeviceList)))
5963 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
5964 DM_DBG3(("dmResetReported: empty device list\n"));
5969 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
5972 DeviceListList = dmAllShared->MainDeviceList.flink;
5973 while (DeviceListList != &(dmAllShared->MainDeviceList))
5975 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
5976 if (oneDeviceData == agNULL)
5978 DM_DBG1(("dmResetReported: oneDeviceData is NULL!!!\n"));
5981 DM_DBG3(("dmResetReported: loop did %d\n", oneDeviceData->id));
5982 DM_DBG3(("dmResetReported: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
5983 DM_DBG3(("dmResetReported: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
5984 DM_DBG3(("dmResetReported: valid %d\n", oneDeviceData->valid));
5985 DM_DBG3(("dmResetReported: valid2 %d\n", oneDeviceData->valid2));
5986 DM_DBG3(("dmResetReported: directlyAttached %d\n", oneDeviceData->directlyAttached));
5987 if ( oneDeviceData->dmPortContext == onePortContext)
5989 DM_DBG3(("dmResetReported: right portcontext pid %d\n", onePortContext->id));
5990 oneDeviceData->reported = agFALSE;
5991 DeviceListList = DeviceListList->flink;
5995 if (oneDeviceData->dmPortContext != agNULL)
5997 DM_DBG3(("dmResetReported: different portcontext; oneDeviceData->dmPortContext pid %d oneportcontext pid %d\n", oneDeviceData->dmPortContext->id, onePortContext->id));
6001 DM_DBG3(("dmResetReported: different portcontext; oneDeviceData->dmPortContext pid NULL oneportcontext pid %d\n", onePortContext->id));
6003 DeviceListList = DeviceListList->flink;
6010 /* called on discover failure */
6012 dmDiscoveryInvalidateDevices(
6014 dmIntPortContext_t *onePortContext
6017 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
6018 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
6019 dmDeviceData_t *oneDeviceData = agNULL;
6020 dmList_t *DeviceListList;
6022 DM_DBG1(("dmDiscoveryInvalidateDevices: start\n"));
6024 tddmSingleThreadedEnter(dmRoot, DM_DEVICE_LOCK);
6025 if (DMLIST_EMPTY(&(dmAllShared->MainDeviceList)))
6027 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
6028 DM_DBG3(("dmDiscoveryInvalidateDevices: empty device list\n"));
6033 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
6035 DeviceListList = dmAllShared->MainDeviceList.flink;
6036 while (DeviceListList != &(dmAllShared->MainDeviceList))
6038 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
6039 if (oneDeviceData == agNULL)
6041 DM_DBG1(("dmDiscoveryInvalidateDevices: oneDeviceData is NULL!!!\n"));
6044 DM_DBG3(("dmDiscoveryInvalidateDevices: loop did %d\n", oneDeviceData->id));
6045 DM_DBG3(("dmDiscoveryInvalidateDevices: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
6046 DM_DBG3(("dmDiscoveryInvalidateDevices: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
6047 DM_DBG3(("dmDiscoveryInvalidateDevices: valid %d\n", oneDeviceData->valid));
6048 DM_DBG3(("dmDiscoveryInvalidateDevices: valid2 %d\n", oneDeviceData->valid2));
6049 DM_DBG3(("dmDiscoveryInvalidateDevices: directlyAttached %d\n", oneDeviceData->directlyAttached));
6050 if ( oneDeviceData->dmPortContext == onePortContext)
6052 DM_DBG3(("dmDiscoveryInvalidateDevices: right portcontext pid %d\n", onePortContext->id));
6053 if (oneDeviceData->SASAddressID.sasAddressHi == onePortContext->sasRemoteAddressHi &&
6054 oneDeviceData->SASAddressID.sasAddressLo == onePortContext->sasRemoteAddressLo
6057 DM_DBG1(("dmDiscoveryInvalidateDevices: keeping\n"));
6058 oneDeviceData->valid = agTRUE;
6059 oneDeviceData->valid2 = agFALSE;
6063 oneDeviceData->valid = agFALSE;
6064 oneDeviceData->valid2 = agFALSE;
6065 oneDeviceData->registered = agFALSE;
6066 oneDeviceData->reported = agFALSE;
6067 /* all targets other than expanders */
6068 DM_DBG3(("dmDiscoveryInvalidateDevices: did %d\n", oneDeviceData->id));
6069 DM_DBG3(("dmDiscoveryInvalidateDevices: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
6070 DM_DBG3(("dmDiscoveryInvalidateDevices: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
6071 onePortContext->RegisteredDevNums--;
6073 DeviceListList = DeviceListList->flink;
6077 if (oneDeviceData->dmPortContext != agNULL)
6079 DM_DBG3(("dmDiscoveryInvalidateDevices: different portcontext; oneDeviceData->dmPortContext pid %d oneportcontext pid %d\n", oneDeviceData->dmPortContext->id, onePortContext->id));
6083 DM_DBG3(("dmDiscoveryInvalidateDevices: different portcontext; oneDeviceData->dmPortContext pid NULL oneportcontext pid %d\n", onePortContext->id));
6085 DeviceListList = DeviceListList->flink;
6094 should DM report the device removal to TDM on an error case?
6096 DM simply removes the devices
6097 For now, the second option.
6100 dmDiscoveryErrorRemovals(
6102 dmIntPortContext_t *onePortContext
6105 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
6106 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
6107 dmDeviceData_t *oneDeviceData = agNULL;
6108 dmList_t *DeviceListList;
6110 DM_DBG1(("dmDiscoveryErrorRemovals: start\n"));
6112 tddmSingleThreadedEnter(dmRoot, DM_DEVICE_LOCK);
6113 if (DMLIST_EMPTY(&(dmAllShared->MainDeviceList)))
6115 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
6116 DM_DBG3(("dmDiscoveryErrorRemovals: empty device list\n"));
6121 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
6123 DeviceListList = dmAllShared->MainDeviceList.flink;
6124 while (DeviceListList != &(dmAllShared->MainDeviceList))
6126 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
6127 if (oneDeviceData == agNULL)
6129 DM_DBG1(("dmDiscoveryErrorRemovals: oneDeviceData is NULL!!!\n"));
6132 DM_DBG3(("dmDiscoveryErrorRemovals: loop did %d\n", oneDeviceData->id));
6133 DM_DBG3(("dmDiscoveryErrorRemovals: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
6134 DM_DBG3(("dmDiscoveryErrorRemovals: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
6135 DM_DBG3(("dmDiscoveryErrorRemovals: valid %d\n", oneDeviceData->valid));
6136 DM_DBG3(("dmDiscoveryErrorRemovals: valid2 %d\n", oneDeviceData->valid2));
6137 DM_DBG3(("dmDiscoveryErrorRemovals: directlyAttached %d\n", oneDeviceData->directlyAttached));
6138 if ( oneDeviceData->dmPortContext == onePortContext)
6140 DM_DBG3(("dmDiscoveryErrorRemovals: right portcontext pid %d\n", onePortContext->id));
6141 if (oneDeviceData->SASAddressID.sasAddressHi == onePortContext->sasRemoteAddressHi &&
6142 oneDeviceData->SASAddressID.sasAddressLo == onePortContext->sasRemoteAddressLo
6145 DM_DBG1(("dmDiscoveryErrorRemovals: keeping\n"));
6146 oneDeviceData->valid = agTRUE;
6147 oneDeviceData->valid2 = agFALSE;
6151 oneDeviceData->valid = agFALSE;
6152 oneDeviceData->valid2 = agFALSE;
6154 /* all targets other than expanders */
6155 DM_DBG3(("dmDiscoveryErrorRemovals: did %d\n", oneDeviceData->id));
6156 DM_DBG3(("dmDiscoveryErrorRemovals: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
6157 DM_DBG3(("dmDiscoveryErrorRemovals: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
6158 onePortContext->RegisteredDevNums--;
6159 dmSubReportRemovals(dmRoot, onePortContext, oneDeviceData, dmDeviceRemoval);
6162 DeviceListList = DeviceListList->flink;
6166 if (oneDeviceData->dmPortContext != agNULL)
6168 DM_DBG3(("dmDiscoveryErrorRemovals: different portcontext; oneDeviceData->dmPortContext pid %d oneportcontext pid %d\n", oneDeviceData->dmPortContext->id, onePortContext->id));
6172 DM_DBG3(("dmDiscoveryErrorRemovals: different portcontext; oneDeviceData->dmPortContext pid NULL oneportcontext pid %d\n", onePortContext->id));
6174 DeviceListList = DeviceListList->flink;
6181 /* move from dmAllShared->mainExpanderList to dmAllShared->freeExpanderList */
6183 dmDiscoveryExpanderCleanUp(
6185 dmIntPortContext_t *onePortContext
6188 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
6189 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
6190 dmExpander_t *oneExpander = agNULL;
6191 dmList_t *ExpanderList = agNULL;
6192 dmDeviceData_t *oneDeviceData = agNULL;
6194 DM_DBG3(("dmDiscoveryExpanderCleanUp: start\n"));
6198 dmExpanderDeviceDataReInit(
6200 dmExpander_t *oneExpander
6205 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
6206 if (!DMLIST_EMPTY(&(dmAllShared->mainExpanderList)))
6208 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
6209 ExpanderList = dmAllShared->mainExpanderList.flink;
6210 while (ExpanderList != &(dmAllShared->mainExpanderList))
6212 oneExpander = DMLIST_OBJECT_BASE(dmExpander_t, linkNode, ExpanderList);
6213 if (oneExpander == agNULL)
6215 DM_DBG1(("dmDiscoveryExpanderCleanUp: oneExpander is NULL!!!\n"));
6218 oneDeviceData = oneExpander->dmDevice;
6219 DM_DBG3(("dmDiscoveryExpanderCleanUp: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
6220 DM_DBG3(("dmDiscoveryExpanderCleanUp: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
6221 if ( oneDeviceData->dmPortContext == onePortContext)
6223 dmExpanderDeviceDataReInit(dmRoot, oneExpander);
6224 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
6225 DMLIST_DEQUEUE_THIS(&(oneExpander->linkNode));
6226 DMLIST_ENQUEUE_AT_TAIL(&(oneExpander->linkNode), &(dmAllShared->freeExpanderList));
6228 if (DMLIST_EMPTY(&(dmAllShared->mainExpanderList)))
6230 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
6235 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
6237 ExpanderList = dmAllShared->mainExpanderList.flink;
6241 ExpanderList = ExpanderList->flink;
6247 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
6248 DM_DBG3(("dmDiscoveryExpanderCleanUp: empty mainExpanderList\n"));
6255 /* moves all devices from dmAllShared->MainDeviceList to dmAllShared->FreeDeviceList */
6257 dmDiscoveryDeviceCleanUp(
6259 dmIntPortContext_t *onePortContext
6262 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
6263 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
6264 dmDeviceData_t *oneDeviceData = agNULL;
6265 dmList_t *DeviceListList;
6267 DM_DBG3(("dmDiscoveryDeviceCleanUp: start\n"));
6269 tddmSingleThreadedEnter(dmRoot, DM_DEVICE_LOCK);
6270 if (!DMLIST_EMPTY(&(dmAllShared->MainDeviceList)))
6272 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
6273 DeviceListList = dmAllShared->MainDeviceList.flink;
6274 while (DeviceListList != &(dmAllShared->MainDeviceList))
6276 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
6277 if (oneDeviceData == agNULL)
6279 DM_DBG1(("dmDiscoveryDeviceCleanUp: oneDeviceData is NULL!!!\n"));
6282 DM_DBG3(("dmDiscoveryDeviceCleanUp: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
6283 DM_DBG3(("dmDiscoveryDeviceCleanUp: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
6284 if ( oneDeviceData->dmPortContext == onePortContext)
6286 dmDeviceDataReInit(dmRoot, oneDeviceData);
6287 tddmSingleThreadedEnter(dmRoot, DM_DEVICE_LOCK);
6288 DMLIST_DEQUEUE_THIS(&(oneDeviceData->MainLink));
6289 DMLIST_ENQUEUE_AT_TAIL(&(oneDeviceData->FreeLink), &(dmAllShared->FreeDeviceList));
6291 if (DMLIST_EMPTY(&(dmAllShared->MainDeviceList)))
6293 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
6298 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
6300 onePortContext->RegisteredDevNums--;
6301 DeviceListList = dmAllShared->MainDeviceList.flink;
6305 DeviceListList = DeviceListList->flink;
6311 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
6312 DM_DBG3(("dmDiscoveryDeviceCleanUp: empty MainDeviceList\n"));
6322 dmIntPortContext_t *onePortContext,
6323 dmExpander_t *oneExpander
6326 DM_DBG3(("dmDumpAllExp: start\n"));
6334 dmIntPortContext_t *onePortContext,
6335 dmExpander_t *oneExpander
6338 DM_DBG3(("dmDumpAllUpExp: start\n"));
6347 DM_DBG3(("dmDumpAllFreeExp: start\n"));
6354 dmIntPortContext_t *onePortContext
6357 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
6358 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
6359 dmList_t *ExpanderList;
6360 dmExpander_t *tempExpander;
6362 DM_DBG3(("dmDumpAllMainExp: start\n"));
6364 tddmSingleThreadedEnter(dmRoot, DM_EXPANDER_LOCK);
6365 if (DMLIST_EMPTY(&(dmAllShared->mainExpanderList)))
6367 DM_DBG3(("dmDumpAllMainExp: empty discoveringExpanderList\n"));
6368 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
6373 tddmSingleThreadedLeave(dmRoot, DM_EXPANDER_LOCK);
6376 ExpanderList = dmAllShared->mainExpanderList.flink;
6377 while (ExpanderList != &(dmAllShared->mainExpanderList))
6379 tempExpander = DMLIST_OBJECT_BASE(dmExpander_t, linkNode, ExpanderList);
6380 if (tempExpander == agNULL)
6382 DM_DBG1(("dmDumpAllMainExp: tempExpander is NULL!!!\n"));
6385 DM_DBG3(("dmDumpAllMainExp: expander id %d\n", tempExpander->id));
6386 DM_DBG3(("dmDumpAllMainExp: exp addrHi 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressHi));
6387 DM_DBG3(("dmDumpAllMainExp: exp addrLo 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressLo));
6388 if ((tempExpander->dmDevice->dmPortContext == onePortContext)
6391 DM_DBG3(("dmDumpAllMainExp: found expander id %d\n", tempExpander->id));
6392 DM_DBG3(("dmDumpAllMainExp: found exp addrHi 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressHi));
6393 DM_DBG3(("dmDumpAllMainExp: found exp addrLo 0x%08x\n", tempExpander->dmDevice->SASAddressID.sasAddressLo));
6395 ExpanderList = ExpanderList->flink;
6402 dmDumpAllMainDevice(
6404 dmIntPortContext_t *onePortContext
6407 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
6408 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
6409 dmDeviceData_t *oneDeviceData = agNULL;
6410 dmList_t *DeviceListList;
6411 bit32 total = 0, port_total = 0;
6413 DM_DBG3(("dmDumpAllMainDevice: start\n"));
6415 tddmSingleThreadedEnter(dmRoot, DM_DEVICE_LOCK);
6416 if (DMLIST_EMPTY(&(dmAllShared->MainDeviceList)))
6418 DM_DBG3(("dmDumpAllMainDevice: empty discoveringExpanderList\n"));
6419 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
6424 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
6427 DeviceListList = dmAllShared->MainDeviceList.flink;
6428 while (DeviceListList != &(dmAllShared->MainDeviceList))
6430 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
6431 if (oneDeviceData == agNULL)
6433 DM_DBG3(("dmDumpAllMainDevice: oneDeviceData is NULL!!!\n"));
6436 DM_DBG3(("dmDumpAllMainDevice: oneDeviceData id %d\n", oneDeviceData->id));
6437 DM_DBG3(("dmDumpAllMainDevice: addrHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
6438 DM_DBG3(("dmDumpAllMainDevice: addrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
6440 if ((oneDeviceData->dmPortContext == onePortContext)
6443 DM_DBG3(("dmDumpAllMainDevice: found oneDeviceData id %d\n", oneDeviceData->id));
6444 DM_DBG3(("dmDumpAllMainDevice: found addrHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
6445 DM_DBG3(("dmDumpAllMainDevice: found addrLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
6448 DeviceListList = DeviceListList->flink;
6450 DM_DBG3(("dmDumpAllMainDevice: total %d port_totaol %d\n", total, port_total));
6457 osGLOBAL dmDeviceData_t *
6458 dmAddSASToSharedcontext(
6460 dmIntPortContext_t *onePortContext,
6461 dmSASSubID_t *dmSASSubID,
6462 dmDeviceData_t *oneExpDeviceData,
6466 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
6467 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
6468 dmDeviceData_t *oneDeviceData = agNULL;
6469 dmList_t *DeviceListList;
6470 bit32 new_device = agTRUE;
6473 DM_DBG3(("dmAddSASToSharedcontext: start\n"));
6474 DM_DBG3(("dmAddSASToSharedcontext: oneportContext ID %d\n", onePortContext->id));
6476 if (oneExpDeviceData != agNULL)
6478 DM_DBG3(("dmAddSASToSharedcontext: oneExpDeviceData sasAddressHi 0x%08x sasAddressLo 0x%08x\n",
6479 oneExpDeviceData->SASAddressID.sasAddressHi, oneExpDeviceData->SASAddressID.sasAddressLo));
6483 DM_DBG3(("dmAddSASToSharedcontext: oneExpDeviceData is NULL\n"));
6485 /* find a device's existence */
6486 DeviceListList = dmAllShared->MainDeviceList.flink;
6487 while (DeviceListList != &(dmAllShared->MainDeviceList))
6489 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
6490 if (oneDeviceData == agNULL)
6492 DM_DBG1(("dmAddSASToSharedcontext: oneDeviceData is NULL!!!\n"));
6495 if ((oneDeviceData->SASAddressID.sasAddressHi == dmSASSubID->sasAddressHi) &&
6496 (oneDeviceData->SASAddressID.sasAddressLo == dmSASSubID->sasAddressLo) &&
6497 (oneDeviceData->dmPortContext == onePortContext)
6500 DM_DBG3(("dmAddSASToSharedcontext: pid %d did %d\n", onePortContext->id, oneDeviceData->id));
6501 new_device = agFALSE;
6504 DeviceListList = DeviceListList->flink;
6508 if (new_device == agTRUE)
6510 DM_DBG3(("dmAddSASToSharedcontext: new device\n"));
6511 DM_DBG3(("dmAddSASToSharedcontext: sasAddressHi 0x%08x sasAddressLo 0x%08x\n",
6512 dmSASSubID->sasAddressHi, dmSASSubID->sasAddressLo));
6513 tddmSingleThreadedEnter(dmRoot, DM_DEVICE_LOCK);
6514 if (!DMLIST_NOT_EMPTY(&(dmAllShared->FreeDeviceList)))
6516 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
6517 DM_DBG1(("dmAddSASToSharedcontext: empty DeviceData FreeLink\n"));
6518 dmDumpAllMainDevice(dmRoot, onePortContext);
6522 DMLIST_DEQUEUE_FROM_HEAD(&DeviceListList, &(dmAllShared->FreeDeviceList));
6523 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
6524 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, FreeLink, DeviceListList);
6526 if (oneDeviceData != agNULL)
6528 DM_DBG3(("dmAddSASToSharedcontext: oneDeviceData %p pid %d did %d\n", oneDeviceData, onePortContext->id, oneDeviceData->id));
6530 onePortContext->Count++;
6531 oneDeviceData->dmRoot = dmRoot;
6532 /* saving sas address */
6533 oneDeviceData->SASAddressID.sasAddressLo = dmSASSubID->sasAddressLo;
6534 oneDeviceData->SASAddressID.sasAddressHi = dmSASSubID->sasAddressHi;
6535 oneDeviceData->initiator_ssp_stp_smp = dmSASSubID->initiator_ssp_stp_smp;
6536 oneDeviceData->target_ssp_stp_smp = dmSASSubID->target_ssp_stp_smp;
6537 oneDeviceData->dmPortContext = onePortContext;
6538 /* handles both SAS target and STP-target, SATA-device */
6539 if (!DEVICE_IS_SATA_DEVICE(oneDeviceData) && !DEVICE_IS_STP_TARGET(oneDeviceData))
6541 oneDeviceData->DeviceType = DM_SAS_DEVICE;
6545 oneDeviceData->DeviceType = DM_SATA_DEVICE;
6548 if (oneExpDeviceData != agNULL)
6550 oneDeviceData->ExpDevice = oneExpDeviceData;
6553 /* set phyID only when it has initial value of 0xFF */
6554 if (oneDeviceData->phyID == 0xFF)
6556 oneDeviceData->phyID = phyID;
6558 /* incremental discovery */
6559 /* add device to incremental-related link. Report using this link
6560 when incremental discovery is done */
6561 if (onePortContext->DiscoveryState == DM_DSTATE_NOT_STARTED)
6563 DM_DBG3(("dmAddSASToSharedcontext: DM_DSTATE_NOT_STARTED\n"));
6564 DM_DBG3(("dmAddSASToSharedcontext: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
6565 DM_DBG3(("dmAddSASToSharedcontext: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
6566 oneDeviceData->valid = agTRUE;
6570 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_INCREMENTAL_START)
6572 DM_DBG3(("dmAddSASToSharedcontext: incremental discovery\n"));
6573 DM_DBG3(("dmAddSASToSharedcontext: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
6574 DM_DBG3(("dmAddSASToSharedcontext: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
6575 oneDeviceData->valid2 = agTRUE;
6579 DM_DBG3(("dmAddSASToSharedcontext: full discovery\n"));
6580 DM_DBG3(("dmAddSASToSharedcontext: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
6581 DM_DBG3(("dmAddSASToSharedcontext: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
6582 oneDeviceData->valid = agTRUE;
6585 /* add the devicedata to the portcontext */
6586 tddmSingleThreadedEnter(dmRoot, DM_DEVICE_LOCK);
6587 DMLIST_ENQUEUE_AT_TAIL(&(oneDeviceData->MainLink), &(dmAllShared->MainDeviceList));
6588 tddmSingleThreadedLeave(dmRoot, DM_DEVICE_LOCK);
6589 DM_DBG3(("dmAddSASToSharedcontext: one case pid %d did %d \n", onePortContext->id, oneDeviceData->id));
6590 DM_DBG3(("dmAddSASToSharedcontext: new case pid %d did %d phyID %d\n", onePortContext->id, oneDeviceData->id, oneDeviceData->phyID));
6593 else /* old device */
6595 DM_DBG3(("dmAddSASToSharedcontext: old device\n"));
6596 DM_DBG3(("dmAddSASToSharedcontext: oneDeviceData %p did %d\n", oneDeviceData, oneDeviceData->id));
6597 DM_DBG3(("dmAddSASToSharedcontext: sasAddressHi 0x%08x sasAddressLo 0x%08x\n",
6598 dmSASSubID->sasAddressHi, dmSASSubID->sasAddressLo));
6600 oneDeviceData->dmRoot = dmRoot;
6601 /* saving sas address */
6602 oneDeviceData->SASAddressID.sasAddressLo = dmSASSubID->sasAddressLo;
6603 oneDeviceData->SASAddressID.sasAddressHi = dmSASSubID->sasAddressHi;
6604 oneDeviceData->initiator_ssp_stp_smp = dmSASSubID->initiator_ssp_stp_smp;
6605 oneDeviceData->target_ssp_stp_smp = dmSASSubID->target_ssp_stp_smp;
6606 oneDeviceData->dmPortContext = onePortContext;
6607 /* handles both SAS target and STP-target, SATA-device */
6608 if (!DEVICE_IS_SATA_DEVICE(oneDeviceData) && !DEVICE_IS_STP_TARGET(oneDeviceData))
6610 oneDeviceData->DeviceType = DM_SAS_DEVICE;
6614 oneDeviceData->DeviceType = DM_SATA_DEVICE;
6617 if (oneExpDeviceData != agNULL)
6619 oneDeviceData->ExpDevice = oneExpDeviceData;
6622 /* set phyID only when it has initial value of 0xFF */
6623 if (oneDeviceData->phyID == 0xFF)
6625 oneDeviceData->phyID = phyID;
6628 if (onePortContext->DiscoveryState == DM_DSTATE_NOT_STARTED)
6630 DM_DBG3(("dmAddSASToSharedcontext: DM_DSTATE_NOT_STARTED\n"));
6631 DM_DBG3(("dmAddSASToSharedcontext: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
6632 DM_DBG3(("dmAddSASToSharedcontext: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
6633 oneDeviceData->valid = agTRUE;
6637 if (onePortContext->discovery.type == DM_DISCOVERY_OPTION_INCREMENTAL_START)
6639 DM_DBG3(("dmAddSASToSharedcontext: incremental discovery\n"));
6640 DM_DBG3(("dmAddSASToSharedcontext: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
6641 DM_DBG3(("dmAddSASToSharedcontext: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
6642 oneDeviceData->valid2 = agTRUE;
6646 DM_DBG3(("dmAddSASToSharedcontext: full discovery\n"));
6647 DM_DBG3(("dmAddSASToSharedcontext: sasAddrHi 0x%08x \n", oneDeviceData->SASAddressID.sasAddressHi));
6648 DM_DBG3(("dmAddSASToSharedcontext: sasAddrLo 0x%08x \n", oneDeviceData->SASAddressID.sasAddressLo));
6649 oneDeviceData->valid = agTRUE;
6652 DM_DBG3(("dmAddSASToSharedcontext: old case pid %d did %d phyID %d\n", onePortContext->id, oneDeviceData->id, oneDeviceData->phyID));
6655 return oneDeviceData;
6658 /* no checking of valid and valid2 */
6659 osGLOBAL dmDeviceData_t *
6662 dmIntPortContext_t *onePortContext,
6667 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
6668 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
6669 dmDeviceData_t *oneDeviceData = agNULL;
6670 dmList_t *DeviceListList;
6671 bit32 found = agFALSE;
6673 DM_DBG3(("dmDeviceFind: start\n"));
6674 /* find a device's existence */
6675 DeviceListList = dmAllShared->MainDeviceList.flink;
6677 while (DeviceListList != &(dmAllShared->MainDeviceList))
6679 oneDeviceData = DMLIST_OBJECT_BASE(dmDeviceData_t, MainLink, DeviceListList);
6680 if (oneDeviceData == agNULL)
6682 DM_DBG1(("dmDeviceFind: oneDeviceData is NULL!!!\n"));
6685 if ((oneDeviceData->SASAddressID.sasAddressHi == sasAddrHi) &&
6686 (oneDeviceData->SASAddressID.sasAddressLo == sasAddrLo) &&
6687 // (oneDeviceData->valid == agTRUE) &&
6688 (oneDeviceData->dmPortContext == onePortContext)
6691 DM_DBG3(("dmDeviceFind: Found pid %d did %d\n", onePortContext->id, oneDeviceData->id));
6692 DM_DBG3(("dmDeviceFind: sasAddressHi 0x%08x\n", oneDeviceData->SASAddressID.sasAddressHi));
6693 DM_DBG3(("dmDeviceFind: sasAddressLo 0x%08x\n", oneDeviceData->SASAddressID.sasAddressLo));
6697 DeviceListList = DeviceListList->flink;
6700 if (found == agFALSE)
6702 DM_DBG3(("dmDeviceFind: end returning NULL\n"));
6707 DM_DBG3(("dmDeviceFind: end returning NOT NULL\n"));
6708 return oneDeviceData;
6717 dmIntPortContext_t *onePortContext
6720 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
6721 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
6722 dmDiscovery_t *discovery;
6724 DM_DBG3(("dmBCTimer: start\n"));
6726 discovery = &(onePortContext->discovery);
6728 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
6729 if (discovery->BCTimer.timerRunning == agTRUE)
6731 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
6739 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
6742 if (onePortContext->valid == agTRUE)
6746 &discovery->BCTimer,
6747 BC_TIMER_VALUE/dmAllShared->usecsPerTick,
6756 &dmAllShared->timerlist,
6775 dmIntPortContext_t *onePortContext;
6776 dmDiscovery_t *discovery;
6778 DM_DBG3(("dmBCTimerCB: start\n"));
6780 onePortContext = (dmIntPortContext_t *)timerData1;
6781 discovery = &(onePortContext->discovery);
6783 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
6784 if (discovery->BCTimer.timerRunning == agTRUE)
6786 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
6794 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
6797 discovery->ResetTriggerred = agFALSE;
6799 if (onePortContext->valid == agTRUE)
6802 onePortContext->dmPortContext,
6803 DM_DISCOVERY_OPTION_INCREMENTAL_START
6809 /* discovery related SMP timers */
6811 dmDiscoverySMPTimer(dmRoot_t *dmRoot,
6812 dmIntPortContext_t *onePortContext,
6814 dmSMPRequestBody_t *dmSMPRequestBody
6817 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
6818 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
6819 dmDiscovery_t *discovery;
6821 DM_DBG3(("dmDiscoverySMPTimer: start\n"));
6822 DM_DBG3(("dmDiscoverySMPTimer: pid %d SMPFn 0x%x\n", onePortContext->id, functionCode));
6824 /* start the SMP timer which works as SMP application timer */
6825 discovery = &(onePortContext->discovery);
6827 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
6828 if (discovery->DiscoverySMPTimer.timerRunning == agTRUE)
6830 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
6833 &discovery->DiscoverySMPTimer
6838 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
6844 &discovery->DiscoverySMPTimer,
6845 SMP_TIMER_VALUE/dmAllShared->usecsPerTick,
6846 dmDiscoverySMPTimerCB,
6854 &dmAllShared->timerlist,
6855 &discovery->DiscoverySMPTimer
6863 dmDiscoverySMPTimerCB(
6871 dmIntPortContext_t *onePortContext;
6874 dmSMPFrameHeader_t *dmSMPFrameHeader;
6877 dmSMPRequestBody_t *dmSMPRequestBody;
6878 dmDiscovery_t *discovery;
6879 dmDeviceData_t *oneDeviceData;
6880 agsaIORequest_t *agAbortIORequest = agNULL;
6881 agsaIORequest_t *agToBeAbortIORequest = agNULL;
6882 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
6883 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
6884 dmExpander_t *oneExpander = agNULL;
6885 dmSMPRequestBody_t *dmAbortSMPRequestBody = agNULL;
6888 DM_DBG1(("dmDiscoverySMPTimerCB: start!!!\n"));
6890 onePortContext = (dmIntPortContext_t *)timerData1;
6891 dmSMPRequestBody = (dmSMPRequestBody_t *)timerData2;
6893 discovery = &(onePortContext->discovery);
6894 oneDeviceData = dmSMPRequestBody->dmDevice;
6895 agToBeAbortIORequest = &(dmSMPRequestBody->agIORequest);
6896 agRoot = dmAllShared->agRoot;
6899 SMPFunction = dmSMPRequestBody->smpPayload[1];
6901 saFrameReadBlock(agRoot, dmSMPRequestBody->IndirectSMP, 0, smpHeader, 4);
6902 dmSMPFrameHeader = (dmSMPFrameHeader_t *)smpHeader;
6903 SMPFunction = dmSMPFrameHeader->smpFunction;
6906 DM_DBG3(("dmDiscoverySMPTimerCB: SMP function 0x%x\n", SMPFunction));
6908 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
6909 if (discovery->DiscoverySMPTimer.timerRunning == agTRUE)
6911 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
6914 &discovery->DiscoverySMPTimer
6919 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
6923 // saGetPendingPICI(agRoot);
6925 switch (SMPFunction)
6927 case SMP_REPORT_GENERAL: /* fall through */
6928 case SMP_DISCOVER: /* fall through */
6929 case SMP_CONFIGURE_ROUTING_INFORMATION: /* fall through */
6930 DM_DBG1(("dmDiscoverySMPTimerCB: failing discovery, SMP function 0x%x !!!\n", SMPFunction));
6931 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
6932 return; /* no more things to do */
6933 case SMP_REPORT_PHY_SATA:
6934 DM_DBG1(("dmDiscoverySMPTimerCB: failing discovery, SMP function SMP_REPORT_PHY_SATA !!!\n"));
6935 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
6939 DM_DBG1(("dmDiscoverySMPTimerCB: Error, not allowed case!!!\n"));
6943 if (oneDeviceData->registered == agTRUE && (oneDeviceData->valid == agTRUE || oneDeviceData->valid2 == agTRUE) )
6945 /* call to saSMPAbort(one) */
6946 /* get an smp REQUEST from the free list */
6947 tddmSingleThreadedEnter(dmRoot, DM_SMP_LOCK);
6948 if (DMLIST_EMPTY(&(dmAllShared->freeSMPList)))
6950 DM_DBG1(("dmDiscoverySMPTimerCB: no free SMP, can't abort SMP!!!\n"));
6951 tddmSingleThreadedLeave(dmRoot, DM_SMP_LOCK);
6956 DMLIST_DEQUEUE_FROM_HEAD(&SMPList, &(dmAllShared->freeSMPList));
6957 tddmSingleThreadedLeave(dmRoot, DM_SMP_LOCK);
6958 dmAbortSMPRequestBody = DMLIST_OBJECT_BASE(dmSMPRequestBody_t, Link, SMPList);
6959 if (dmAbortSMPRequestBody == agNULL)
6961 DM_DBG1(("dmDiscoverySMPTimerCB: dmAbortSMPRequestBody is NULL!!!\n"));
6964 DM_DBG5(("dmDiscoverySMPTimerCB: SMP id %d\n", dmAbortSMPRequestBody->id));
6967 dmAbortSMPRequestBody->dmRoot = dmRoot;
6969 agAbortIORequest = &(dmAbortSMPRequestBody->agIORequest);
6970 agAbortIORequest->osData = (void *) dmAbortSMPRequestBody;
6971 agAbortIORequest->sdkData = agNULL; /* SALL takes care of this */
6973 oneExpander = oneDeviceData->dmExpander;
6975 DM_DBG1(("dmDiscoverySMPTimerCB: calling saSMPAbort!!!\n"));
6979 oneExpander->agDevHandle,
6981 agToBeAbortIORequest,
6992 dmSMPBusyTimer(dmRoot_t *dmRoot,
6993 dmIntPortContext_t *onePortContext,
6994 dmDeviceData_t *oneDeviceData,
6995 dmSMPRequestBody_t *dmSMPRequestBody
6998 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
6999 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
7000 dmDiscovery_t *discovery;
7002 DM_DBG3(("dmSMPBusyTimer: start\n"));
7003 DM_DBG3(("dmSMPBusyTimer: pid %d\n", onePortContext->id));
7005 discovery = &(onePortContext->discovery);
7007 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
7008 if (discovery->SMPBusyTimer.timerRunning == agTRUE)
7010 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7013 &discovery->SMPBusyTimer
7018 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7023 &discovery->SMPBusyTimer,
7024 SMP_BUSY_TIMER_VALUE/dmAllShared->usecsPerTick,
7033 &dmAllShared->timerlist,
7034 &discovery->SMPBusyTimer
7049 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
7050 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
7052 dmIntPortContext_t *onePortContext;
7053 dmDeviceData_t *oneDeviceData;
7054 dmSMPRequestBody_t *dmSMPRequestBody;
7055 agsaSASRequestBody_t *agSASRequestBody;
7056 agsaIORequest_t *agIORequest;
7057 agsaDevHandle_t *agDevHandle;
7058 dmDiscovery_t *discovery;
7059 bit32 status = AGSA_RC_FAILURE;
7060 dmExpander_t *oneExpander = agNULL;
7063 DM_DBG3(("dmSMPBusyTimerCB: start\n"));
7065 onePortContext = (dmIntPortContext_t *)timerData1;
7066 oneDeviceData = (dmDeviceData_t *)timerData2;
7067 dmSMPRequestBody = (dmSMPRequestBody_t *)timerData3;
7068 agRoot = dmAllShared->agRoot;
7069 agIORequest = &(dmSMPRequestBody->agIORequest);
7070 oneExpander = oneDeviceData->dmExpander;
7071 agDevHandle = oneExpander->agDevHandle;
7072 agSASRequestBody = &(dmSMPRequestBody->agSASRequestBody);
7073 discovery = &(onePortContext->discovery);
7075 discovery->SMPRetries++;
7077 if (discovery->SMPRetries < SMP_BUSY_RETRIES)
7079 status = saSMPStart(
7090 if (status == AGSA_RC_SUCCESS)
7092 discovery->SMPRetries = 0;
7093 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
7094 if (discovery->SMPBusyTimer.timerRunning == agTRUE)
7096 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7099 &discovery->SMPBusyTimer
7104 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7107 else if (status == AGSA_RC_FAILURE)
7109 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
7110 if (discovery->SMPBusyTimer.timerRunning == agTRUE)
7112 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7115 &discovery->SMPBusyTimer
7120 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7123 discovery->SMPRetries = 0;
7124 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
7126 else /* AGSA_RC_BUSY */
7128 if (discovery->SMPRetries >= SMP_BUSY_RETRIES)
7130 /* done with retris; give up */
7131 DM_DBG3(("dmSMPBusyTimerCB: retries are over\n"));
7133 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
7134 if (discovery->SMPBusyTimer.timerRunning == agTRUE)
7136 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7139 &discovery->SMPBusyTimer
7144 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7147 discovery->SMPRetries = 0;
7148 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
7154 dmSMPBusyTimer(dmRoot, onePortContext, oneDeviceData, dmSMPRequestBody);
7162 /* expander configuring timer */
7164 dmDiscoveryConfiguringTimer(dmRoot_t *dmRoot,
7165 dmIntPortContext_t *onePortContext,
7166 dmDeviceData_t *oneDeviceData
7169 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
7170 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
7171 dmDiscovery_t *discovery;
7173 DM_DBG3(("dmDiscoveryConfiguringTimer: start\n"));
7174 DM_DBG3(("dmDiscoveryConfiguringTimer: pid %d\n", onePortContext->id));
7176 discovery = &(onePortContext->discovery);
7178 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
7179 if (discovery->discoveryTimer.timerRunning == agTRUE)
7181 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7184 &discovery->discoveryTimer
7189 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7192 DM_DBG3(("dmDiscoveryConfiguringTimer: UsecsPerTick %d\n", dmAllShared->usecsPerTick));
7193 DM_DBG3(("dmDiscoveryConfiguringTimer: Timervalue %d\n", DISCOVERY_CONFIGURING_TIMER_VALUE/dmAllShared->usecsPerTick));
7197 &discovery->discoveryTimer,
7198 DISCOVERY_CONFIGURING_TIMER_VALUE/dmAllShared->usecsPerTick,
7199 dmDiscoveryConfiguringTimerCB,
7207 &dmAllShared->timerlist,
7208 &discovery->discoveryTimer
7217 dmDiscoveryConfiguringTimerCB(
7224 dmIntPortContext_t *onePortContext = agNULL;
7225 dmDiscovery_t *discovery = agNULL;
7226 dmDeviceData_t *oneDeviceData = agNULL;
7228 onePortContext = (dmIntPortContext_t *)timerData1;
7229 oneDeviceData = (dmDeviceData_t *)timerData2;
7230 discovery = &(onePortContext->discovery);
7232 DM_DBG3(("dmDiscoveryConfiguringTimerCB: start\n"));
7234 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
7235 if (discovery->discoveryTimer.timerRunning == agTRUE)
7237 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7240 &discovery->discoveryTimer
7245 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7248 if (oneDeviceData->valid == agTRUE || oneDeviceData->valid2 == agTRUE)
7250 dmReportGeneralSend(dmRoot, oneDeviceData);
7256 dmConfigureRouteTimer(dmRoot_t *dmRoot,
7257 dmIntPortContext_t *onePortContext,
7258 dmExpander_t *oneExpander,
7259 smpRespDiscover_t *pdmSMPDiscoverResp,
7260 smpRespDiscover2_t *pdmSMPDiscover2Resp
7263 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
7264 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
7265 dmDiscovery_t *discovery;
7267 DM_DBG3(("dmConfigureRouteTimer: start\n"));
7269 DM_DBG3(("dmConfigureRouteTimer: pid %d\n", onePortContext->id));
7271 discovery = &(onePortContext->discovery);
7273 DM_DBG3(("dmConfigureRouteTimer: onePortContext %p oneExpander %p pdmSMPDiscoverResp %p\n", onePortContext, oneExpander, pdmSMPDiscoverResp));
7275 DM_DBG3(("dmConfigureRouteTimer: discovery %p \n", discovery));
7277 DM_DBG3(("dmConfigureRouteTimer: pid %d configureRouteRetries %d\n", onePortContext->id, discovery->configureRouteRetries));
7279 DM_DBG3(("dmConfigureRouteTimer: discovery->status %d\n", discovery->status));
7281 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
7282 if (discovery->configureRouteTimer.timerRunning == agTRUE)
7284 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7287 &discovery->configureRouteTimer
7292 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7295 DM_DBG3(("dmConfigureRouteTimer: UsecsPerTick %d\n", dmAllShared->usecsPerTick));
7296 DM_DBG3(("dmConfigureRouteTimer: Timervalue %d\n", CONFIGURE_ROUTE_TIMER_VALUE/dmAllShared->usecsPerTick));
7298 if (oneExpander->SAS2 == 0)
7303 &discovery->configureRouteTimer,
7304 CONFIGURE_ROUTE_TIMER_VALUE/dmAllShared->usecsPerTick,
7305 dmConfigureRouteTimerCB,
7306 (void *)onePortContext,
7307 (void *)oneExpander,
7308 (void *)pdmSMPDiscoverResp
7316 &discovery->configureRouteTimer,
7317 CONFIGURE_ROUTE_TIMER_VALUE/dmAllShared->usecsPerTick,
7318 dmConfigureRouteTimerCB,
7319 (void *)onePortContext,
7320 (void *)oneExpander,
7321 (void *)pdmSMPDiscover2Resp
7326 &dmAllShared->timerlist,
7327 &discovery->configureRouteTimer
7335 dmConfigureRouteTimerCB(
7342 dmIntRoot_t *dmIntRoot = (dmIntRoot_t *)dmRoot->dmData;
7343 dmIntContext_t *dmAllShared = (dmIntContext_t *)&dmIntRoot->dmAllShared;
7344 dmIntPortContext_t *onePortContext;
7345 dmExpander_t *oneExpander;
7346 smpRespDiscover_t *pdmSMPDiscoverResp = agNULL;
7347 smpRespDiscover2_t *pdmSMPDiscover2Resp = agNULL;
7348 dmDiscovery_t *discovery;
7351 DM_DBG3(("dmConfigureRouteTimerCB: start\n"));
7353 onePortContext = (dmIntPortContext_t *)timerData1;
7354 oneExpander = (dmExpander_t *)timerData2;
7355 if (oneExpander->SAS2 == 0)
7357 pdmSMPDiscoverResp = (smpRespDiscover_t *)timerData3;
7361 pdmSMPDiscover2Resp = (smpRespDiscover2_t *)timerData3;
7363 discovery = &(onePortContext->discovery);
7365 DM_DBG3(("dmConfigureRouteTimerCB: onePortContext %p oneExpander %p pdmSMPDiscoverResp %p\n", onePortContext, oneExpander, pdmSMPDiscoverResp));
7367 DM_DBG3(("dmConfigureRouteTimerCB: discovery %p\n", discovery));
7369 DM_DBG3(("dmConfigureRouteTimerCB: pid %d configureRouteRetries %d\n", onePortContext->id, discovery->configureRouteRetries));
7371 DM_DBG3(("dmConfigureRouteTimerCB: discovery.status %d\n", discovery->status));
7373 discovery->configureRouteRetries++;
7374 if (discovery->configureRouteRetries >= dmAllShared->MaxRetryDiscovery)
7376 DM_DBG3(("dmConfigureRouteTimerCB: retries are over\n"));
7378 tddmSingleThreadedEnter(dmRoot, DM_TIMER_LOCK);
7379 if (discovery->configureRouteTimer.timerRunning == agTRUE)
7381 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7384 &discovery->configureRouteTimer
7389 tddmSingleThreadedLeave(dmRoot, DM_TIMER_LOCK);
7392 discovery->configureRouteRetries = 0;
7393 /* failed the discovery */
7394 dmDiscoverDone(dmRoot, onePortContext, DM_RC_FAILURE);
7400 if (oneExpander->SAS2 == 0)
7402 if (onePortContext->discovery.status == DISCOVERY_DOWN_STREAM)
7404 DM_DBG3(("dmConfigureRouteTimerCB: proceed by calling dmDownStreamDiscoverExpanderPhy\n"));
7405 dmhexdump("dmConfigureRouteTimerCB", (bit8*)pdmSMPDiscoverResp, sizeof(smpRespDiscover_t));
7406 discovery->configureRouteRetries = 0;
7408 dmDownStreamDiscoverExpanderPhy(dmRoot, onePortContext, oneExpander, pdmSMPDiscoverResp);
7412 DM_DBG3(("dmConfigureRouteTimerCB: setting timer again\n"));
7413 /* set the timer again */
7416 &discovery->configureRouteTimer,
7417 CONFIGURE_ROUTE_TIMER_VALUE/dmAllShared->usecsPerTick,
7418 dmConfigureRouteTimerCB,
7419 (void *)onePortContext,
7420 (void *)oneExpander,
7421 (void *)pdmSMPDiscoverResp
7426 &dmAllShared->timerlist,
7427 &discovery->configureRouteTimer
7434 if (onePortContext->discovery.status == DISCOVERY_DOWN_STREAM)
7436 DM_DBG2(("dmConfigureRouteTimerCB: proceed by calling dmDownStreamDiscover2ExpanderPhy\n"));
7437 dmhexdump("dmConfigureRouteTimerCB", (bit8*)pdmSMPDiscover2Resp, sizeof(smpRespDiscover2_t));
7439 dmDownStreamDiscover2ExpanderPhy(dmRoot, onePortContext, oneExpander, pdmSMPDiscover2Resp);
7443 DM_DBG2(("dmConfigureRouteTimerCB: setting timer again\n"));
7444 /* set the timer again */
7447 &discovery->configureRouteTimer,
7448 CONFIGURE_ROUTE_TIMER_VALUE/dmAllShared->usecsPerTick,
7449 dmConfigureRouteTimerCB,
7450 (void *)onePortContext,
7451 (void *)oneExpander,
7452 (void *)pdmSMPDiscover2Resp
7457 &dmAllShared->timerlist,
7458 &discovery->configureRouteTimer
7465 #endif /* FDS_ DM */