Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gearbox] Set port speed to SAI_PORT_ATTR_SPEED for gearbox #1785

Merged
merged 2 commits into from
Aug 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 31 additions & 40 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1800,9 +1800,7 @@ bool PortsOrch::setGearboxPortAttr(Port &port, dest_port_type_t port_type, sai_p
sai_object_id_t dest_port_id;
sai_attribute_t attr;
string speed_attr;
uint32_t lane_speed = 0;
sai_uint32_t speed = 0;
uint32_t lanes = 0;

SWSS_LOG_ENTER();

Expand All @@ -1826,36 +1824,29 @@ bool PortsOrch::setGearboxPortAttr(Port &port, dest_port_type_t port_type, sai_p
switch (port_type)
{
case PHY_PORT_TYPE:
lanes = static_cast<uint32_t>(m_gearboxInterfaceMap[port.m_index].system_lanes.size());
speed_attr = "system_speed";
break;
case LINE_PORT_TYPE:
lanes = static_cast<uint32_t>(m_gearboxInterfaceMap[port.m_index].line_lanes.size());
speed_attr = "line_speed";
break;
default:
return false;
}

// Gearbox expects speed per lane
speed = *static_cast<sai_int32_t*>(value);
if (speed % lanes == 0)
{
lane_speed = speed / lanes;
}
if (isSpeedSupported(port.m_alias, dest_port_id, lane_speed))
if (isSpeedSupported(port.m_alias, dest_port_id, speed))
{
// Gearbox may not implement speed check, so
// invalidate speed if it doesn't make sense.
if (to_string(lane_speed).size() < 5)
if (to_string(speed).size() < 5)
{
lane_speed = 0;
speed = 0;
}

attr.id = SAI_PORT_ATTR_SPEED;
attr.value.u32 = lane_speed;
attr.value.u32 = speed;
}
SWSS_LOG_NOTICE("BOX: Set %s lane %s %d", port.m_alias.c_str(), speed_attr.c_str(), lane_speed);
SWSS_LOG_NOTICE("BOX: Set %s lane %s %d", port.m_alias.c_str(), speed_attr.c_str(), speed);
break;
default:
return false;
Expand All @@ -1867,8 +1858,8 @@ bool PortsOrch::setGearboxPortAttr(Port &port, dest_port_type_t port_type, sai_p
if (id == SAI_PORT_ATTR_SPEED)
{
string key = "phy:"+to_string(m_gearboxInterfaceMap[port.m_index].phy_id)+":ports:"+to_string(port.m_index);
m_gearboxTable->hset(key, speed_attr, to_string(lane_speed));
SWSS_LOG_NOTICE("BOX: Updated APPL_DB key:%s %s %d", key.c_str(), speed_attr.c_str(), lane_speed);
m_gearboxTable->hset(key, speed_attr, to_string(speed));
SWSS_LOG_NOTICE("BOX: Updated APPL_DB key:%s %s %d", key.c_str(), speed_attr.c_str(), speed);
}
}
else
Expand Down Expand Up @@ -5657,8 +5648,19 @@ bool PortsOrch::initGearboxPort(Port &port)
attr.value.booldata = port.m_admin_state_up;
attrs.push_back(attr);

attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
lanes.assign(m_gearboxInterfaceMap[port.m_index].system_lanes.begin(), m_gearboxInterfaceMap[port.m_index].system_lanes.end());
attr.value.u32list.list = lanes.data();
attr.value.u32list.count = static_cast<uint32_t>(lanes.size());
attrs.push_back(attr);

for (uint32_t i = 0; i < attr.value.u32list.count; i++)
{
SWSS_LOG_DEBUG("BOX: list[%d] = %d", i, attr.value.u32list.list[i]);
}

attr.id = SAI_PORT_ATTR_SPEED;
attr.value.u32 = (uint32_t) m_gearboxPortMap[port.m_index].system_speed;
attr.value.u32 = (uint32_t) m_gearboxPortMap[port.m_index].system_speed * (uint32_t) lanes.size();
if (isSpeedSupported(port.m_alias, port.m_port_id, attr.value.u32))
{
attrs.push_back(attr);
Expand All @@ -5680,17 +5682,6 @@ bool PortsOrch::initGearboxPort(Port &port)
attr.value.booldata = m_gearboxPortMap[port.m_index].system_training;
attrs.push_back(attr);

attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
lanes.assign(m_gearboxInterfaceMap[port.m_index].system_lanes.begin(), m_gearboxInterfaceMap[port.m_index].system_lanes.end());
attr.value.u32list.list = lanes.data();
attr.value.u32list.count = static_cast<uint32_t>(lanes.size());
attrs.push_back(attr);

for (uint32_t i = 0; i < attr.value.u32list.count; i++)
{
SWSS_LOG_DEBUG("BOX: list[%d] = %d", i, attr.value.u32list.list[i]);
}

status = sai_port_api->create_port(&systemPort, phyOid, static_cast<uint32_t>(attrs.size()), attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
Expand All @@ -5712,8 +5703,19 @@ bool PortsOrch::initGearboxPort(Port &port)
attr.value.booldata = port.m_admin_state_up;
attrs.push_back(attr);

attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
lanes.assign(m_gearboxInterfaceMap[port.m_index].line_lanes.begin(), m_gearboxInterfaceMap[port.m_index].line_lanes.end());
attr.value.u32list.list = lanes.data();
attr.value.u32list.count = static_cast<uint32_t>(lanes.size());
attrs.push_back(attr);

for (uint32_t i = 0; i < attr.value.u32list.count; i++)
{
SWSS_LOG_DEBUG("BOX: list[%d] = %d", i, attr.value.u32list.list[i]);
}

attr.id = SAI_PORT_ATTR_SPEED;
attr.value.u32 = (uint32_t) m_gearboxPortMap[port.m_index].line_speed;
attr.value.u32 = (uint32_t) m_gearboxPortMap[port.m_index].line_speed * (uint32_t) lanes.size();
if (isSpeedSupported(port.m_alias, port.m_port_id, attr.value.u32))
{
attrs.push_back(attr);
Expand Down Expand Up @@ -5767,17 +5769,6 @@ bool PortsOrch::initGearboxPort(Port &port)
attr.value.u32 = media_type_map[m_gearboxPortMap[port.m_index].line_adver_media_type];
attrs.push_back(attr);

attr.id = SAI_PORT_ATTR_HW_LANE_LIST;
lanes.assign(m_gearboxInterfaceMap[port.m_index].line_lanes.begin(), m_gearboxInterfaceMap[port.m_index].line_lanes.end());
attr.value.u32list.list = lanes.data();
attr.value.u32list.count = static_cast<uint32_t>(lanes.size());
attrs.push_back(attr);

for (uint32_t i = 0; i < attr.value.u32list.count; i++)
{
SWSS_LOG_DEBUG("BOX: list[%d] = %d", i, attr.value.u32list.list[i]);
}

status = sai_port_api->create_port(&linePort, phyOid, static_cast<uint32_t>(attrs.size()), attrs.data());
if (status != SAI_STATUS_SUCCESS)
{
Expand Down