📄 core_init.c
字号:
pExpander->Device_Number--; FreeDeviceToPool(pCore, pDevice); } Remained--; }}void UpdateTargetDevices(PDomain_Port pPort, MV_PVOID pDiscoveryExtension, PDomain_Expander pExpander, MV_U8 i){ PCore_Driver_Extension pCore = pPort->Core_Extension; MV_U8 j; MV_U8 data[512]; pTarget_Dev_Map pTgtMap; DISC_GetTgtDevMap(pDiscoveryExtension, pPort, MAP_TGT_INFO, i, data); pTgtMap=(pTarget_Dev_Map)data; CheckDeviceChange(pExpander, pDiscoveryExtension, i ); for(j=0;j<pTgtMap->Info.TotalDevCounts;j++) { PDomain_Device pDevice = NULL; LIST_FOR_EACH_ENTRY_TYPE(pDevice, &pExpander->Device_List, Domain_Device, Exp_Queue_Pointer) { if(MV_Equals((MV_U8 *)&pDevice->SASAddr,pTgtMap->TgtDev[j].DevSASAddr,8)) break; } if(&pDevice->Exp_Queue_Pointer==&pExpander->Device_List) {/* New Device */ pDevice = GetDeviceFromPool( pCore ); if( pDevice == NULL ) return; pPort->Device_Number++; pDevice->State=DEVICE_STATE_RESET_DONE; pDevice->Error_Handling_State=EH_NONE; pDevice->Status=DEVICE_STATUS_FUNCTIONAL; // TBD: for now assume functional U32_ASSIGN_U64(pDevice->Max_LBA, 0x50000); pDevice->Connection = pTgtMap->TgtDev[j].Connection; pDevice->Dev_Type = pTgtMap->TgtDev[j].DevType; pDevice->pPort=pPort; pDevice->NegotiatedLinkRate=pTgtMap->TgtDev[j].NegotiatedLinkRate&0x0f;/* update max linkrate information */ pDevice->Capacity&=~DEVICE_CAPACITY_RATE_3G; pDevice->Capacity|=DEVICE_CAPACITY_RATE_1_5G; if(pTgtMap->TgtDev[j].MaxLinkRateCapability==PHY_LINKRATE_3) pDevice->Capacity|=DEVICE_CAPACITY_RATE_3G; pDevice->pExpander=pExpander; if (pCore->State == CORE_STATE_STARTED) pDevice->Need_Notify = MV_TRUE; pDevice->Phy_Id = pTgtMap->TgtDev[j].PhyId; MV_CopyMemory((MV_U8 *)&pDevice->SASAddr,pTgtMap->TgtDev[j].DevSASAddr,8); MV_CopyMemory( &pDevice->WWN, &pDevice->SASAddr, 8 ); pExpander->Device_Number++; List_AddTail( &pDevice->Queue_Pointer, &pPort->Device_List ); List_AddTail( &pDevice->Exp_Queue_Pointer, &pExpander->Device_List ); if( IS_STP(pDevice) ) Expander_SMPRequest_ReportPHYSATA( pPort, pExpander, pDevice->Phy_Id, pDevice ); else if( IS_SSP(pDevice) ) SAS_DeviceStateMachine( pCore, pDevice ); } }}void CheckTargetChange(PDomain_Port pPort, MV_PVOID pDiscoveryExtension ){ PCore_Driver_Extension pCore = pPort->Core_Extension; PDomain_Expander pExpander; MV_U8 Remained; Remained=pPort->Expander_Number; while( (!List_Empty(&pPort->Expander_List))&&(Remained>0) ) { MV_U8 i,TgtCount; pExpander = List_GetFirstEntry(&pPort->Expander_List, Domain_Expander, Queue_Pointer); TgtCount = DISC_GetTgtDevMap(pDiscoveryExtension, pPort, MAP_TGT_COUNT, 0, NULL); for(i=0;i<TgtCount;i++) { MV_U16 j; MV_U8 data[512]; pTarget_Dev_Map pTgtMap; j=DISC_GetTgtDevMap(pDiscoveryExtension, pPort, MAP_TGT_INFO, i, NULL); if((sizeof(Target_Dev_Map)+j*sizeof(Target_Dev))>512) continue; DISC_GetTgtDevMap(pDiscoveryExtension, pPort, MAP_TGT_INFO, i, data); pTgtMap=(pTarget_Dev_Map)data; if (MV_Equals(pTgtMap->Info.SASAddr, (MV_U8 *)&pExpander->SASAddr, 8)) { MV_U8 index; List_AddTail(&pExpander->Queue_Pointer, &pPort->Expander_List);/* Found, Update Target info */ pExpander->Phy_Count=pTgtMap->Info.PhyCount; index=Port_FindTgtNo(pPort,pTgtMap->Info.ParentSASAddr); if(index!=ID_NOT_MAPPED) pExpander->pParent=&pCore->Expanders[index];/* Ignore First target which is given by us */ if(i!=0) { pExpander->SMP_TRGT=(pTgtMap->Info.TargetBits&0x02)?1:0; pExpander->SSP_TRGT=(pTgtMap->Info.TargetBits&0x08)?1:0; pExpander->STP_TRGT=(pTgtMap->Info.TargetBits&0x04)?1:0;/* update exp linkrate info in case it is changed */ pExpander->NegotiatedLinkRate=pTgtMap->Info.NegotiatedLinkRate; } else { pExpander->Phy_Count=pTgtMap->Info.PhyCount; pExpander->pPort = pPort; pExpander->NegotiatedLinkRate=pTgtMap->Info.NegotiatedLinkRate; /* These were updated during PortReset time and should not be overwritten MV_CopyMemory ( pExpander->ParentPhyId, pTgtMap->Info.ParentPhyId, MAX_WIDEPORT_PHYS ); pExpander->ParentPhyCount = pTgtMap->Info.ParentPhyCount; */ pExpander->Route_Index_Count = pTgtMap->Info.MaxRouteIndexes; pExpander->ComponentID = pTgtMap->Info.ComponentID; pExpander->ComponentRevisionID = pTgtMap->Info.ComponentRevisionID; MV_CopyMemory ( pExpander->ComponentVendorID, pTgtMap->Info.ComponentVendorID, 16 ); MV_CopyMemory ( pExpander->VendorID, pTgtMap->Info.VendorID, 16 ); MV_CopyMemory ( pExpander->ProductID, pTgtMap->Info.ProductID, 24 ); MV_CopyMemory ( pExpander->ProductRev, pTgtMap->Info.ProductRev, 8 ); } UpdateTargetDevices(pPort, pDiscoveryExtension, pExpander, i); break; } } if(i>=TgtCount) {/* Not found, Target is removed */ PDomain_Device pDevice = NULL; while( !List_Empty(&pExpander->Device_List) ) { pDevice = List_GetFirstEntry(&pExpander->Device_List, Domain_Device, Exp_Queue_Pointer); core_notify_device_hotplug(pCore, EVENT_DEVICE_REMOVAL, pDevice->Id); Port_AbortRequests(pPort,REQ_STATUS_NO_DEVICE,pDevice); List_Del( &pDevice->Queue_Pointer ); pPort->Device_Number--; pExpander->Device_Number--; FreeDeviceToPool(pCore, pDevice); } pPort->Expander_Number--; FreeExpanderToPool(pCore, pExpander); } Remained--; }}void UpdateTgtDevMap( IN MV_PVOID pDiscoveryExtension, IN MV_PVOID This ){ PDomain_Port pPort=(PDomain_Port)This; PCore_Driver_Extension pCore = pPort->Core_Extension; MV_U8 i,TgtCount; CheckTargetChange(pPort, pDiscoveryExtension ); TgtCount = DISC_GetTgtDevMap(pDiscoveryExtension, This, MAP_TGT_COUNT, 0, NULL); for(i=0;i<TgtCount;i++) { MV_U16 j; MV_U8 data[512]; pTarget_Dev_Map pTgtMap; j=DISC_GetTgtDevMap(pDiscoveryExtension, This, MAP_TGT_INFO, i, NULL); if((sizeof(Target_Dev_Map)+j*sizeof(Target_Dev))>512) continue; DISC_GetTgtDevMap(pDiscoveryExtension, This, MAP_TGT_INFO, i, data); pTgtMap=(pTarget_Dev_Map)data; if(Port_FindTgtNo(This,pTgtMap->Info.SASAddr)==ID_NOT_MAPPED) {/*New Target*/ PDomain_Expander pExpander; MV_U8 index; pExpander = GetExpanderFromPool( pCore ); if(pExpander==NULL) return; pPort->Expander_Number++; pExpander->Device_Number=0; MV_CopyMemory((MV_U8 *)&pExpander->SASAddr, pTgtMap->Info.SASAddr, 8); index=Port_FindTgtNo(This,pTgtMap->Info.ParentSASAddr); if(index!=ID_NOT_MAPPED) pExpander->pParent=&pCore->Expanders[index]; pExpander->Phy_Count=pTgtMap->Info.PhyCount; pExpander->SMP_TRGT=(pTgtMap->Info.TargetBits&0x02)?1:0; pExpander->SSP_TRGT=(pTgtMap->Info.TargetBits&0x08)?1:0; pExpander->STP_TRGT=(pTgtMap->Info.TargetBits&0x04)?1:0; pExpander->pPort = pPort; pExpander->NegotiatedLinkRate=pTgtMap->Info.NegotiatedLinkRate; MV_CopyMemory( pExpander->ParentPhyId, pTgtMap->Info.ParentPhyId, MAX_WIDEPORT_PHYS ); pExpander->ParentPhyCount = pTgtMap->Info.ParentPhyCount; pExpander->Route_Index_Count = pTgtMap->Info.MaxRouteIndexes; pExpander->ComponentID = pTgtMap->Info.ComponentID; pExpander->ComponentRevisionID = pTgtMap->Info.ComponentRevisionID; MV_CopyMemory( pExpander->ComponentVendorID, pTgtMap->Info.ComponentVendorID, 16 ); MV_CopyMemory( pExpander->VendorID, pTgtMap->Info.VendorID, 16 ); MV_CopyMemory( pExpander->ProductID, pTgtMap->Info.ProductID, 24 ); MV_CopyMemory( pExpander->ProductRev, pTgtMap->Info.ProductRev, 8 ); List_AddTail( &pExpander->Queue_Pointer, &pPort->Expander_List ); for(j=0;j<pTgtMap->Info.TotalDevCounts;j++) { PDomain_Device pDevice; pDevice = GetDeviceFromPool( pCore ); if( pDevice == NULL ) return; pPort->Device_Number++; pDevice->State=DEVICE_STATE_RESET_DONE; pDevice->Error_Handling_State=EH_NONE; pDevice->Status=DEVICE_STATUS_FUNCTIONAL; // TBD: for now assume functional U32_ASSIGN_U64(pDevice->Max_LBA, 0x50000); pDevice->Connection = pTgtMap->TgtDev[j].Connection; pDevice->Dev_Type = pTgtMap->TgtDev[j].DevType; pDevice->pPort=pPort; pDevice->pExpander=pExpander; if (pCore->State == CORE_STATE_STARTED) pDevice->Need_Notify = MV_TRUE; pDevice->Phy_Id = pTgtMap->TgtDev[j].PhyId; pDevice->NegotiatedLinkRate=pTgtMap->TgtDev[j].NegotiatedLinkRate&0x0f; pDevice->Capacity&=~DEVICE_CAPACITY_RATE_3G; pDevice->Capacity|=DEVICE_CAPACITY_RATE_1_5G; if(pTgtMap->TgtDev[j].MaxLinkRateCapability==PHY_LINKRATE_3) pDevice->Capacity|=DEVICE_CAPACITY_RATE_3G; MV_CopyMemory((MV_U8 *)&pDevice->SASAddr,pTgtMap->TgtDev[j].DevSASAddr,8); MV_CopyMemory( &pDevice->WWN, &pDevice->SASAddr, 8 ); pExpander->Device_Number++; List_AddTail( &pDevice->Queue_Pointer, &pPort->Device_List ); List_AddTail( &pDevice->Exp_Queue_Pointer, &pExpander->Device_List ); if( IS_STP(pDevice) ) Expander_SMPRequest_ReportPHYSATA( pPort, pExpander, pDevice->Phy_Id, pDevice ); else if( IS_SSP(pDevice) ) SAS_DeviceStateMachine( pCore, pDevice ); } } } if(pPort->Device_Number==0) { pPort->Port_State = PORT_STATE_INIT_DONE; mvChannelStateMachine(pCore, pPort); }}void DiscoveryCallBack( IN MV_PVOID pDiscoveryExtension, IN MV_PVOID This ){ PDomain_Port pPort=(PDomain_Port)This; MV_U8 DiscState; MV_U8 i,TgtCount; TgtCount = DISC_GetTgtDevMap(pDiscoveryExtension, This, MAP_TGT_COUNT, 0, NULL); for(i=0;i<TgtCount;i++) { DISC_CheckDiscoverState(pDiscoveryExtension, pPort, i, &DiscState); if(DiscState!=0xfe) return; } pPort->DiscoveryInstance--; if ( pPort->DiscoveryInstance > 0 ) { /* redo discovery if there were broadcast changes during first discovery */ PDomain_Expander pExpander; PCore_Driver_Extension pCore = pPort->Core_Extension; /* reset DiscoveryInstance */ pPort->DiscoveryInstance = 0; LIST_FOR_EACH_ENTRY_TYPE(pExpander, &pPort->Expander_List, Domain_Expander, Queue_Pointer) { if(pExpander->pParent==NULL) { pPort->DiscoveryInstance++; DISC_CancelDiscover(pDiscoveryExtension,This); DISC_DoDiscover(pCore->pDiscoverBuffer, pPort, (MV_U8 *)&pExpander->SASAddr, pExpander->NegotiatedLinkRate, DiscoveryCallBack); break; } } } else { MV_PRINT("Discovery found 0x%x targets\n", TgtCount); UpdateTgtDevMap(pDiscoveryExtension,This); DISC_CancelDiscover(pDiscoveryExtension,This); }}MV_U8 GetMinNegotiatedLinkRate( PDomain_Port pPort){ PCore_Driver_Extension pCore = pPort->Core_Extension; MV_U8 i, minLinkRate; minLinkRate=PHY_LINKRATE_3; for(i=0;i<pCore->Phy_Num;i++) { if(pPort->MemberPhyMap&MV_BIT(i)) { if( ((pCore->Phy[i].PhyStatus&MV_NEG_SPP_PHYS_LINK_RATE_MASK)>>MV_NEG_SPP_PHYS_LINK_RATE_MASK_OFFSET) < minLinkRate) minLinkRate = (MV_U8)((pCore->Phy[i].PhyStatus&MV_NEG_SPP_PHYS_LINK_RATE_MASK)>>MV_NEG_SPP_PHYS_LINK_RATE_MASK_OFFSET); } } return minLinkRate;}MV_U8 GetMaxNegotiatedLinkRate( PDomain_Port pPort){ PCore_Driver_Extension pCore = pPort->Core_Extension; MV_U8 i, maxLinkRate; maxLinkRate=PHY_LINKRATE_1_5; for(i=0;i<pCore->Phy_Num;i++) { if(pPort->MemberPhyMap&MV_BIT(i)) { if( ((pCore->Phy[i].PhyStatus&MV_NEG_SPP_PHYS_LINK_RATE_MASK)>>MV_NEG_SPP_PHYS_LINK_RATE_MASK_OFFSET) > maxLinkRate) maxLinkRate = (MV_U8)((pCore->Phy[i].PhyStatus&MV_NEG_SPP_PHYS_LINK_RATE_MASK)>>MV_NEG_SPP_PHYS_LINK_RATE_MASK_OFFSET); } } return maxLinkRate;}MV_VOID SAS_PortReset( IN PDomain_Port pPort, IN MV_BOOLEAN hardReset ){ PCore_Driver_Extension pCore = pPort->Core_Extension; PDomain_Device pDevice = NULL; PDomain_Expander pExpander = NULL; MV_U8 i, j, phyId=0; if (pPort->MemberPhyMap) { i = 0; while (0 == (pPort->MemberPhyMap & (1 << i))) i++; if (pCore->Phy[i].AttDevInfo & PORT_DEV_STP_TRGT) { pCore->Phy[i].AttDevInfo |= PORT_DEV_SMP_TRGT; pCore->Phy[i].AttDevInfo &= ~PORT_DEV_STP_TRGT; } if (pCore->Phy[i].AttDevInfo & PORT_DEV_SMP_TRGT) { pExpander = GetExpanderFromPool( pCore ); if (pCore->Phy[i].AttDevInfo & PORT_DEV_SMP_INIT) pExpander->SMP_INIT = 1; if (pCore->Phy[i].AttDevInfo & PORT_DEV_SMP_TRGT) pExpander->SMP_TRGT = 1; if (pCore->Phy[i].AttDevInfo & PORT_DEV_SSP_INIT) pExpander->SSP_INIT = 1; if (pCore->Phy[i].AttDevInfo & PORT_DEV_SSP_TRGT) pExpander->SSP_TRGT = 1; if (pCore->Phy[i].AttDevInfo & PORT_DEV_STP_INIT) pExpander->STP_INIT = 1; if (pCore->Phy[i].AttDevInfo & PORT_DEV_STP_TRGT) pExpander->STP_TRGT = 1; pExpander->Device_Number = 0; pExpander->SASAddr = pCore->Phy[i].AttDevSASAddr; pExpander->pPort = pPort; pExpander->NegotiatedLinkRate=GetMinNegotiatedLinkRate(pPort); pPort->Expander_Number++; for( j=0; j<pCore->Phy_Num; j++ ) { if( pPort->MemberPhyMap & MV_BIT(j) ) { pExpander->ParentPhyId[phyId] = j; pExpander->ParentPhyCount++; phyId++; } } List_AddTail(&pExpander->Queue_Pointer, &pPort->Expander_List ); pPort->DiscoveryInstance++; DISC_DoDiscover(pCore->pDiscoverBuffer, pPort, (MV_U8 *)&pExpander->SASAddr, pExpander->NegotiatedLinkRate, DiscoveryCallBack); } else if (pCore->Phy[i].AttDevInfo & PORT_DEV_SSP_TRGT) { pDevice = GetDeviceFromPool( pCore ); if ( pDevice == NULL ) return; /* is it a bit early to declare it FUNCTIONAL? */ pDevice->Status = DEVICE_STATUS_EXISTING | DEVICE_STATUS_FUNCTIONAL; pDevice->State = DEVICE_STATE_RESET_DONE; pDevice->Connection = DC_SCSI | DC_SERIAL; pDevice->Dev_Type = DT_DIRECT_ACCESS_BLOCK; U32_ASSIGN_U64(pDevice->Max_LBA, 0x50000); if (pCore->State == CORE_STATE_STARTED) pDevice->Need_Notify = MV_TRUE; pDevice->SASAddr = pCore->Phy[i].AttDevSASAddr; MV_CopyMemory( &pDevice->WWN, &pDevice->SASAddr, 8 ); pDevice->pPort = pPort; pDevice->NegotiatedLinkRate=GetMinNegotiatedLinkRate(pPort); pDevice->Capacity |= DEVICE_CAPACITY_RATE_1_5G; if ( GetMaxNegotiatedLinkRate(pPort)>=PHY_LINKRATE_3 ) pDevice->Capacity |= DEVICE_CAPACITY_RATE_3G ; pPort->Device_Number=1; List_AddTail(&pDevice->Queue_Pointer, &pPort->Device_List ); SAS_DeviceStateMachine( pCore, pDevice ); } }}MV_VOID SwapDeviceID( IN PCore_Driver_Extension pCore, IN MV_U8 MapIndexA, IN MV_U8 MapIndexB){ MV_U8 Index; pCore->Devices[MapDeviceId(pCore,MapIndexA)].Id=MapIndexB; pCore->Devices[MapDeviceId(pCore,MapIndexB)].Id=MapIndexA; Index = MapDeviceId(pCore,MapIndexA);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -