Skip to content

Commit

Permalink
[gearbox] Set context for phys based on configs (sonic-net#1826)
Browse files Browse the repository at this point in the history
SAI_REDIS_SWITCH_ATTR_CONTEXT was set according to the phy_id
in gearbox_config.json. This change will set it based on the
context_id provided in that json file. The reason behind it is
to support the case of multiple phys sharing the same context.
  • Loading branch information
byu343 authored Jul 26, 2021
1 parent 7f80f06 commit ec104c1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions gearsyncd/gearboxparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ bool GearboxParser::parse()
val = phy["bus_id"];
attr = std::make_pair("bus_id", std::to_string(val.get<int>()));
attrs.push_back(attr);
if (phy.find("context_id") == phy.end())
{
SWSS_LOG_ERROR("missing 'context_id' field in 'phys' item %d in gearbox configuration", iter);
return false;
}
val = phy["context_id"];
attr = std::make_pair("context_id", std::to_string(val.get<int>()));
attrs.push_back(attr);
if (phy.find("hwinfo") == phy.end())
{
SWSS_LOG_ERROR("missing 'hwinfo' field in 'phys' item %d in gearbox configuration", iter);
Expand Down
4 changes: 4 additions & 0 deletions lib/gearboxutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ std::map<int, gearbox_phy_t> GearboxUtils::loadPhyMap(Table *gearboxTable)
{
phy.bus_id = std::stoi(val.second);
}
else if (val.first == "context_id")
{
phy.context_id = std::stoi(val.second);
}
}
gearboxPhyMap[phy.phy_id] = phy;
}
Expand Down
1 change: 1 addition & 0 deletions lib/gearboxutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef struct
std::string hwinfo;
uint32_t address;
uint32_t bus_id;
uint32_t context_id;
} gearbox_phy_t;

typedef struct
Expand Down
2 changes: 1 addition & 1 deletion orchagent/saihelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy)

/* Must be last Attribute */
attr.id = SAI_REDIS_SWITCH_ATTR_CONTEXT;
attr.value.u64 = phy->phy_id;
attr.value.u64 = phy->context_id;
attrs.push_back(attr);

status = sai_switch_api->create_switch(&phyOid, (uint32_t)attrs.size(), attrs.data());
Expand Down

0 comments on commit ec104c1

Please sign in to comment.