Skip to content

Commit ec104c1

Browse files
authored
[gearbox] Set context for phys based on configs (sonic-net#1826)
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.
1 parent 7f80f06 commit ec104c1

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

gearsyncd/gearboxparser.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ bool GearboxParser::parse()
143143
val = phy["bus_id"];
144144
attr = std::make_pair("bus_id", std::to_string(val.get<int>()));
145145
attrs.push_back(attr);
146+
if (phy.find("context_id") == phy.end())
147+
{
148+
SWSS_LOG_ERROR("missing 'context_id' field in 'phys' item %d in gearbox configuration", iter);
149+
return false;
150+
}
151+
val = phy["context_id"];
152+
attr = std::make_pair("context_id", std::to_string(val.get<int>()));
153+
attrs.push_back(attr);
146154
if (phy.find("hwinfo") == phy.end())
147155
{
148156
SWSS_LOG_ERROR("missing 'hwinfo' field in 'phys' item %d in gearbox configuration", iter);

lib/gearboxutils.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ std::map<int, gearbox_phy_t> GearboxUtils::loadPhyMap(Table *gearboxTable)
185185
{
186186
phy.bus_id = std::stoi(val.second);
187187
}
188+
else if (val.first == "context_id")
189+
{
190+
phy.context_id = std::stoi(val.second);
191+
}
188192
}
189193
gearboxPhyMap[phy.phy_id] = phy;
190194
}

lib/gearboxutils.h

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ typedef struct
4444
std::string hwinfo;
4545
uint32_t address;
4646
uint32_t bus_id;
47+
uint32_t context_id;
4748
} gearbox_phy_t;
4849

4950
typedef struct

orchagent/saihelper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ sai_status_t initSaiPhyApi(swss::gearbox_phy_t *phy)
418418

419419
/* Must be last Attribute */
420420
attr.id = SAI_REDIS_SWITCH_ATTR_CONTEXT;
421-
attr.value.u64 = phy->phy_id;
421+
attr.value.u64 = phy->context_id;
422422
attrs.push_back(attr);
423423

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

0 commit comments

Comments
 (0)