fboss/lib/phy/SaiPhyManager.cpp
/*
 * programOnePort
 *
 * This function programs one port in the PHY. The port and profile Id is
 * passed to SaiPortManager which in turn uses platform mapping to get the
 * system and line side lane list, speed, fec values. The SaiPortManager
 * will create system port, line port, port connector and return the Sai
 * object for line port. The called function also enables the sys/line port
 */
programOnePort
This function programs one port in the PHY. The port and profile Id is
passed to SaiPortManager which in turn uses platform mapping to get the
system and line side lane list, speed, fec values. The SaiPortManager
will create system port, line port, port connector and return the Sai
object for line port. The called function also enables the sys/line port
programOnePort This function programs one port in the PHY . The port and profile Id is passed to SaiPortManager which in turn uses platform mapping to get the system and line side lane list speed fec values . The SaiPortManager will create system port line port port connector and return the Sai object for line port . The called function also enables the sys / line port
void SaiPhyManager::programOnePort(
    PortID portId,
    cfg::PortProfileID portProfileId,
    std::optional<TransceiverInfo> transceiverInfo) {
  const auto& wLockedCache = getWLockedCache(portId);
  auto globalPhyID = getGlobalXphyIDbyPortIDLocked(wLockedCache);
  auto saiPlatform = getSaiPlatform(globalPhyID);
  auto saiSwitch = static_cast<SaiSwitch*>(saiPlatform->getHwSwitch());
  const auto& desiredPhyPortConfig =
      getDesiredPhyPortConfig(portId, portProfileId, transceiverInfo);
  if (!(wLockedCache->systemLanes.empty() || wLockedCache->lineLanes.empty())) {
    const auto& actualPhyPortConfig =
        getHwPhyPortConfigLocked(wLockedCache, portId);
    if (actualPhyPortConfig == desiredPhyPortConfig) {
      XLOG(DBG2) << "External phy config match. Skip reprogramming for port:"
                 << portId << " with profile:"
                 << apache::thrift::util::enumNameSafe(portProfileId);
      return;
    } else {
      XLOG(DBG2) << "External phy config mismatch. Port:" << portId
                 << " with profile:"
                 << apache::thrift::util::enumNameSafe(portProfileId)
                 << " current config:" << actualPhyPortConfig.toDynamic()
                 << ", desired config:" << desiredPhyPortConfig.toDynamic();
    }
  }
  auto portObj = std::make_shared<Port>(
      PortID(portId),
      saiPlatform->getPlatformPort(PortID(portId))
          ->getPlatformPortEntry()
          .mapping_ref()
          ->name_ref()
          .value());
  portObj->setProfileId(portProfileId);
  portObj->setAdminState(cfg::PortState::ENABLED);
  PortSaiId saiPort = saiSwitch->managerTable()->portManager().addPort(portObj);
  XLOG(INFO) << "Created Sai port " << saiPort << " for id=" << portId;
  setPortToLanesInfoLocked(wLockedCache, portId, desiredPhyPortConfig);
  if (getExternalPhyLocked(wLockedCache)
          ->isSupported(phy::ExternalPhy::Feature::PORT_STATS)) {
    setPortToExternalPhyPortStatsLocked(
        wLockedCache, createExternalPhyPortStats(PortID(portId)));
  }
}
void SaiPhyManager :: programOnePort ( PortID portId , cfg :: PortProfileID portProfileId , std :: optional < TransceiverInfo > transceiverInfo ) { const auto & wLockedCache = getWLockedCache ( portId ) ; auto globalPhyID = getGlobalXphyIDbyPortIDLocked ( wLockedCache ) ; auto saiPlatform = getSaiPlatform ( globalPhyID ) ; auto saiSwitch = static_cast < SaiSwitch * > ( saiPlatform -> getHwSwitch ( ) ) ; const auto & desiredPhyPortConfig = getDesiredPhyPortConfig ( portId , portProfileId , transceiverInfo ) ; if ( ! ( wLockedCache -> systemLanes . empty ( ) || wLockedCache -> lineLanes . empty ( ) ) ) { const auto & actualPhyPortConfig = getHwPhyPortConfigLocked ( wLockedCache , portId ) ; if ( actualPhyPortConfig == desiredPhyPortConfig ) { XLOG ( DBG2 ) << " " << portId << " " << apache :: thrift :: util :: enumNameSafe ( portProfileId ) ; return ; } else { XLOG ( DBG2 ) << " " << portId << " " << apache :: thrift :: util :: enumNameSafe ( portProfileId ) << " " << actualPhyPortConfig . toDynamic ( ) << " " << desiredPhyPortConfig . toDynamic ( ) ; } } auto portObj = std :: make_shared < Port > ( PortID ( portId ) , saiPlatform -> getPlatformPort ( PortID ( portId ) ) -> getPlatformPortEntry ( ) . mapping_ref ( ) -> name_ref ( ) . value ( ) ) ; portObj -> setProfileId ( portProfileId ) ; portObj -> setAdminState ( cfg :: PortState :: ENABLED ) ; PortSaiId saiPort = saiSwitch -> managerTable ( ) -> portManager ( ) . addPort ( portObj ) ; XLOG ( INFO ) << " " << saiPort << " " << portId ; setPortToLanesInfoLocked ( wLockedCache , portId , desiredPhyPortConfig ) ; if ( getExternalPhyLocked ( wLockedCache ) -> isSupported ( phy :: ExternalPhy :: Feature :: PORT_STATS ) ) { setPortToExternalPhyPortStatsLocked ( wLockedCache , createExternalPhyPortStats ( PortID ( portId ) ) ) ; } }
programOnePort
 This function programs one port in the PHY.
programOnePort This function programs one port in the PHY .
// Get phy platform // Before actually calling sai sdk to program the port again, we should check // whether the port has been programmed in HW with the same config. // Temporary object to pass port and profile id to SaiPortManager // Finally adding the port (sysport, lineport and port connector). // Return value is line port // Once the port is programmed successfully, update the portToLanesInfo_