core_ibcd.c

来自「6440linuxDriver的源代码」· C语言 代码 · 共 1,050 行 · 第 1/3 页

C
1,050
字号
        }        else if ( pResp->Response.Discover.TargetBits & FRAME_ATT_DEV_TYPE_SMP )        {          ExistTgt = FindTgtNo ( pDisc,(MV_U8 *)&SasAddr );          if ( ExistTgt==0xff )          {            for ( NewTgt=0; NewTgt<pDisc->NumberOfMaxTarget; NewTgt++)            {              if ( (pDisc->Target[NewTgt].DiscoveryState == 0xff) ||                   (pDisc->Target[NewTgt].DiscoveryState == 0xfd) )              {                /* Find a free unused Target structure to save this NewTgt */                break;              }            }            MV_ZeroMemory ( &pDisc->Target[NewTgt], sizeof(Target_Dev_Map) );            pDisc->Target[NewTgt].pParent=&pDisc->Target[nTgt];            MV_CopyMemory ( pDisc->Target[NewTgt].Info.ParentSASAddr,pDisc->Target[nTgt].Info.SASAddr,8 );            pDisc->Target[NewTgt].PortExtension = PortExtension;            pDisc->Target[NewTgt].PCallBack=pDisc->Target[nTgt].PCallBack;            pDisc->Target[NewTgt].DiscoveryState=0xff;            pDisc->Target[NewTgt].Info.ParentPhyId[pDisc->Target[NewTgt].Info.ParentPhyCount] =              pResp->Response.Discover.PhyIdentifier;            pDisc->Target[NewTgt].Info.ParentPhyCount++;            pDisc->Target[NewTgt].Info.NegotiatedLinkRate=              MV_MIN ( pResp->Response.Discover.NegotiatedPhysicalLinkRate,pDisc->Target[nTgt].Info.NegotiatedLinkRate );            MV_CopyMemory ( pDisc->Target[NewTgt].Info.SASAddr,&SasAddr,8 );            pDisc->Target[NewTgt].Info.TargetBits=pResp->Response.Discover.TargetBits;            if ( pDisc->TargetNumber == pDisc->NumberOfMaxTarget )              pDisc->TargetNumber = 0;            pDisc->TargetNumber++;          }          else if(pDisc->Target[nTgt].pParent!=&pDisc->Target[ExistTgt])          {            // a target with this SAS address already exists - wide port            pDisc->Target[ExistTgt].Info.ParentPhyId[pDisc->Target[ExistTgt].Info.ParentPhyCount] =              pResp->Response.Discover.PhyIdentifier;            pDisc->Target[ExistTgt].Info.ParentPhyCount++;          }        }         if ( pResp->Response.Discover.TargetBits & FRAME_ATT_DEV_TYPE_SMP )        {          if ( ExistTgt==0xff )          {            MV_DPRINT(( "DISC: Calling DiscoverySM for Tgt 0x%x\n", NewTgt));            DiscoverySM ( pDISC_Extension, PortExtension, NewTgt, 0xff, 0, NULL );            context=pDisc->Target[NewTgt].Info.ParentPhyId[pDisc->Target[NewTgt].Info.ParentPhyCount-1];          }        }      }      for ( i = 1; i<MAXIMUM_DISCOVER_REQUESTS; i++ )      {        if ( (pDisc->SMPContext[i].nTgt == nTgt) &&             (pDisc->SMPContext[i].phyId == pResp->Response.Discover.PhyIdentifier) )        {          pDisc->SMPContext[i].isBufferFree = 1;          MV_DPRINT (( "DISC: Buffer Id 0x%x is free\n", i));          break;        }      }      if ( pDisc->Target[nTgt].Info.phyIdToContinueDisc )      {        if ( pDisc->numOfOutstandingReq == (MAXIMUM_DISCOVER_REQUESTS-1) )        {          /* wait for completion of atleast one request */          return;        }        while ( pDisc->Target[nTgt].Info.phyIdToContinueDisc < pDisc->Target[nTgt].Info.PhyCount )        {          /* we have atleast one buffer available */          pDisc->Target[nTgt].DiscoveryState=DISCOVER;          Issue_Discover ( pDISC_Extension, PortExtension, nTgt, pDisc->Target[nTgt].Info.phyIdToContinueDisc );          if ( (pDisc->Target[nTgt].Info.phyIdToContinueDisc+1) == pDisc->Target[nTgt].Info.PhyCount )          {            pDisc->Target[nTgt].Info.phyIdToContinueDisc = 0;            break;          }          else          {            pDisc->Target[nTgt].Info.phyIdToContinueDisc++;          }          if ( pDisc->numOfOutstandingReq == (MAXIMUM_DISCOVER_REQUESTS-1) )          {            /* save phyId to come back and continue discovery from there */            break;          }        }      }      else if ( pDisc->numOfOutstandingReq )      {        /* do not do anything. let the pending requests complete. */        return;      }      else      {        void (*pCallBack)(MV_PVOID pDiscoveryExtension,MV_PVOID pPortExtension);        for ( i=0; i<pDisc->NumberOfMaxTarget; i++ )        {		if ((pDisc->Target[i].DiscoveryState != 0xfd) &&		    (pDisc->Target[i].DiscoveryState != 0xff))			pDisc->Target[i].DiscoveryState=0xfe;        }        for ( i=1; i < MAXIMUM_DISCOVER_REQUESTS; i++ )        {          pDisc->SMPContext[i].isBufferFree = 1;          pDisc->SMPContext[i].BufferIndex = i;        }        pCallBack=(void (*)(MV_PVOID pDiscoveryExtension,MV_PVOID pPortExtension))(pDisc->Target[nTgt].PCallBack);        for ( i=0; i<MAX_PHYSICAL_PORT_NUMBER; i++ )        {          if ( pDisc->PortInfo[i].DiscoveryReturn == 1 )          {            pDisc->PortInfo[i].DiscoveryReturn = 0;            MV_DPRINT (( "DISC: Completing Discovery on Port 0x%x \n", i));            pCallBack ( pDISC_Extension, pDisc->PortInfo[i].PortExtension );                      }        }      }    }      break;    case CONFIGURE_ROUTE_INFORMATION:    {      MV_U8 i;      void (*pCallBack)(MV_PVOID pDiscoveryExtension,MV_PVOID pPortExtension);      if ( pDisc->numOfOutstandingReq == 0 )      {        for ( i=0; i<pDisc->NumberOfMaxTarget; i++ )        {          if ( (pDisc->Target[i].DiscoveryState != 0xfd)&&(pDisc->Target[i].DiscoveryState != 0xff) )            pDisc->Target[i].DiscoveryState=0xfe;        }        for ( i=1; i < MAXIMUM_DISCOVER_REQUESTS; i++ )        {          pDisc->SMPContext[i].isBufferFree = 1;          pDisc->SMPContext[i].BufferIndex = i;        }        pCallBack=(void (*)(MV_PVOID pDiscoveryExtension,MV_PVOID pPortExtension))(pDisc->Target[nTgt].PCallBack);       for ( i=0; i<MAX_PHYSICAL_PORT_NUMBER; i++ )        {          if ( pDisc->PortInfo[i].DiscoveryReturn == 1 )          {            pDisc->PortInfo[i].DiscoveryReturn = 0;            MV_DPRINT (( "DISC: Completing Discovery on Port 0x%x \n", i));            pCallBack ( pDISC_Extension, pDisc->PortInfo[i].PortExtension );                      }        }      }      else      {        /* do not do anything. let the pending requests complete. */        return;       }           break;    }    case FINDBOUNDARY:    {      break;    }    case 0xfd:    {      MV_DPRINT (( "DISC: Tgt 0x%x Discovery Aborted\n",nTgt ));    }      break;  }}/* Check a discover progress behind a dedicated expander from a dedicated port */MV_VOID DISC_CheckDiscoverState(IN MV_PVOID pDISC_Extension, IN MV_PVOID PortExtension, IN MV_U8 TgtId, MV_U8 *State){  PDiscover_Extension pDisc=(PDiscover_Extension)pDISC_Extension;  MV_U8 i,nTgt;  *State=0xfe;  for(i=0,nTgt=0;i<pDisc->NumberOfMaxTarget;i++)  {    if(pDisc->Target[i].PortExtension==PortExtension)    {      if(nTgt==TgtId)      {        *State=pDisc->Target[i].DiscoveryState;        return;      }      nTgt++;    }  }}		 /* Do a discover behind a dedicated expander from a dedicated port */MV_VOID DISC_DoDiscover(IN MV_PVOID pDISC_Extension, 			                  IN MV_PVOID PortExtension, 			                  IN MV_U8 *SasAddr, 			                  IN MV_U8 NegotiatedLinkRate,			                  IN void (*pCallBack)(MV_PVOID pDiscoveryExtension,					                                   MV_PVOID This)){  MV_U8 i, j;  PDiscover_Extension pDisc=(PDiscover_Extension)pDISC_Extension;  if ( pDisc->TargetNumber == pDisc->NumberOfMaxTarget )  {    pDisc->TargetNumber = 0;  }  j = pDisc->TargetNumber;    for ( i=0; i<MAX_PHYSICAL_PORT_NUMBER; i++)  {    if ( pDisc->PortInfo[i].PortExtension == PortExtension )    {      /* Found an already existing PortInfo sturcture for this Port          - Have to restart discovery for this Port */      pDisc->PortInfo[i].DiscoveryReturn = 1;      for ( j=0; j<pDisc->NumberOfMaxTarget; j++ )      {        if ( (pDisc->Target[j].PortExtension == PortExtension) &&             ( (pDisc->Target[j].DiscoveryState == 0xfe) ||               (pDisc->Target[j].DiscoveryState == 0xfd) ) )        {          /* j is the selected index from which Targets will be added */          break;                          }      }      break;    }    else if ( pDisc->PortInfo[i].PortExtension == 0 )    {      pDisc->PortInfo[i].PortExtension = PortExtension;      pDisc->PortInfo[i].DiscoveryReturn = 1;      break;    }  }  pDisc->PortExtensionsTBD[j] = PortExtension;  MV_ZeroMemory ( &pDisc->Target[j], sizeof(Target_Dev_Map) );  pDisc->Target[j].PortExtension = PortExtension;  pDisc->Target[j].PCallBack=(MV_PVOID)pCallBack;  pDisc->Target[j].DiscoveryState=0xff;  MV_CopyMemory ( &pDisc->Target[j].Info.SASAddr, SasAddr, 8 );  pDisc->Target[j].Info.NegotiatedLinkRate=NegotiatedLinkRate;  MV_DPRINT (( "DISC: DISC_DoDiscover on TGT SasAddress 0x%02x%02x%02x%02x%02x%02x%02x%02x Started\n",              SasAddr[7],              SasAddr[6],              SasAddr[5],              SasAddr[4],              SasAddr[3],              SasAddr[2],              SasAddr[1],              SasAddr[0] ));  DiscoverySM ( pDISC_Extension, PortExtension, j, 0xff, 0, NULL );  pDisc->TargetNumber++;}/* Cancel a discover behind a dedicated expander from a dedicated port */MV_VOID DISC_CancelDiscover(IN MV_PVOID pDISC_Extension, IN MV_PVOID PortExtension){  PDiscover_Extension pDisc=(PDiscover_Extension)pDISC_Extension;  MV_U8 i, j;  /* pDisc->numOfOutstandingReq = 0; */  for ( i=0; i<pDisc->NumberOfMaxTarget; i++ )  {     if ( pDisc->Target[i].PortExtension == PortExtension )     {       for ( j=1; j < MAXIMUM_DISCOVER_REQUESTS; j++ )       {         if(pDisc->SMPContext[j].nTgt==i)           pDisc->SMPContext[j].isBufferFree = 1;       }       pDisc->Target[i].PortExtension=0; 	  MV_ZeroMemory(&pDisc->Target[i].Info,sizeof(Target_Info));       pDisc->Target[i].DiscoveryState=0xfd;       pDisc->TargetNumber--;     }    if ( pDisc->Target[i].PortExtension == PortExtension )          pDisc->Target[i].DiscoveryState=0xfd;  }  for ( i=0; i<MAX_PHYSICAL_PORT_NUMBER; i++)  {     if ( pDisc->PortInfo[i].PortExtension == PortExtension )     {       pDisc->PortInfo[i].PortExtension=0;       pDisc->PortInfo[i].DiscoveryReturn=0;     }  }  MV_DPRINT (( "DISC: DISC_CancelDiscover Invoked\n" ));}/* return a short form of device map behind a dedicated port/expander for the core driver use */ MV_U8 DISC_GetTgtDevMap(IN MV_PVOID pDISC_Extension,                         IN MV_PVOID PortExtension,                         IN MV_U8 Code,                         IN MV_U8 TgtIndex,                         OUT MV_PVOID pTgtDevMap){  PDiscover_Extension pDisc=(PDiscover_Extension)pDISC_Extension;  MV_U8 i, j = 0, expandersInPort=0;  switch ( Code )  {    case MAP_TGT_INFO:      if ( pTgtDevMap!=NULL )      {        pTarget_Dev_Map pTgtMap=(pTarget_Dev_Map)pTgtDevMap;        for ( j=0; j< pDisc->NumberOfMaxTarget; j++)        {          if ( pDisc->Target[j].PortExtension == PortExtension )          {            if ( expandersInPort == TgtIndex )              break;            else              expandersInPort++;          }        }        MV_CopyMemory ( pTgtMap, &pDisc->Target[j].Info, sizeof(Target_Dev_Map) );        for ( i=0;i<pDisc->Target[j].Info.TotalDevCounts;i++ )          MV_CopyMemory ( &pTgtMap->TgtDev[i], &pDisc->Target[j].TgtDev[i], sizeof(Target_Dev) );      }      return pDisc->Target[j].Info.TotalDevCounts;    case MAP_TGT_COUNT:    default:      j=0;      for ( i=0; i< pDisc->NumberOfMaxTarget; i++)      {        if ( pDisc->Target[i].PortExtension == PortExtension )          j++;      }      return j;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?