Skip to content

Commit

Permalink
Support setting tx taps on gearbox ports
Browse files Browse the repository at this point in the history
  • Loading branch information
byu343 committed Feb 24, 2022
1 parent 7d2942f commit 1b7b466
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 6 deletions.
24 changes: 23 additions & 1 deletion gearsyncd/gearboxparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include "gearboxparser.h"
#include "gearboxutils.h"
#include "phyparser.h"
#include <vector>

Expand Down Expand Up @@ -42,7 +43,7 @@ bool GearboxParser::parse()
return false;
}

json phys, phy, interfaces, interface, val, lanes;
json phys, phy, interfaces, interface, val, lanes, txFir;

std::vector<swss::FieldValueTuple> attrs;

Expand Down Expand Up @@ -285,6 +286,27 @@ bool GearboxParser::parse()
SWSS_LOG_ERROR("missing 'line_lanes' field in 'interfaces' item %d in gearbox configuration", iter);
return false;
}

for (std::string txFirKey: swss::tx_fir_strings)
{
if (interface.find(txFirKey) != interface.end())
{
txFir = interface[txFirKey]; // vec
std::string txFirValuesStr("");
for (uint32_t iter2 = 0; iter2 < txFir.size(); iter2++)
{
val = txFir[iter2];
if (txFirValuesStr.length() > 0)
{
txFirValuesStr += ",";
}
txFirValuesStr += std::to_string(val.get<int>());
}
attr = std::make_pair(txFirKey, txFirValuesStr);
attrs.push_back(attr);
}
}

std::string key;
key = "interface:" + std::to_string(index);
if (getWriteToDb() == true)
Expand Down
5 changes: 5 additions & 0 deletions lib/gearboxutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ std::map<int, gearbox_interface_t> GearboxUtils::loadInterfaceMap(Table *gearbox
}
}
}
else if (tx_fir_strings.find(val.first) != tx_fir_strings.end())
{
SWSS_LOG_DEBUG("Parsed key:%s, val:%s", val.first.c_str(), val.second.c_str());
interface.tx_firs[val.first] = val.second;
}
}
gearboxInterfaceMap[interface.index] = interface;
}
Expand Down
19 changes: 19 additions & 0 deletions lib/gearboxutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@

namespace swss {

static const std::set<std::string> tx_fir_strings =
{
"system_tx_fir_pre1",
"system_tx_fir_pre2",
"system_tx_fir_pre3",
"system_tx_fir_post1",
"system_tx_fir_post2",
"system_tx_fir_post3",
"system_tx_fir_main",
"line_tx_fir_pre1",
"line_tx_fir_pre2",
"line_tx_fir_pre3",
"line_tx_fir_post1",
"line_tx_fir_post2",
"line_tx_fir_post3",
"line_tx_fir_main"
};

typedef struct
{
int phy_id;
Expand All @@ -54,6 +72,7 @@ typedef struct
int phy_id;
std::set<int> line_lanes;
std::set<int> system_lanes;
std::map<std::string, std::string> tx_firs;
} gearbox_interface_t;

typedef struct
Expand Down
2 changes: 1 addition & 1 deletion orchagent/mplsrouteorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ bool RouteOrch::addLabelRoute(LabelRouteBulkContext& ctx, const NextHopGroupKey
Label& label = ctx.label;

/* next_hop_id indicates the next hop id or next hop group id of this route */
sai_object_id_t next_hop_id;
sai_object_id_t next_hop_id = 0;
bool blackhole = false;

if (m_syncdLabelRoutes.find(vrf_id) == m_syncdLabelRoutes.end())
Expand Down
66 changes: 63 additions & 3 deletions orchagent/portsorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3240,7 +3240,7 @@ void PortsOrch::doPortTask(Consumer &consumer)

if (serdes_attr.size() != 0)
{
if (setPortSerdesAttribute(p.m_port_id, serdes_attr))
if (setPortSerdesAttribute(p.m_port_id, gSwitchId, serdes_attr))
{
SWSS_LOG_NOTICE("Set port %s preemphasis is success", alias.c_str());
}
Expand Down Expand Up @@ -5865,7 +5865,7 @@ bool PortsOrch::removeAclTableGroup(const Port &p)
return true;
}

bool PortsOrch::setPortSerdesAttribute(sai_object_id_t port_id,
bool PortsOrch::setPortSerdesAttribute(sai_object_id_t port_id, sai_object_id_t switch_id,
map<sai_port_serdes_attr_t, vector<uint32_t>> &serdes_attr)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -5917,7 +5917,7 @@ bool PortsOrch::setPortSerdesAttribute(sai_object_id_t port_id,
port_serdes_attr.value.u32list.list = it->second.data();
attr_list.emplace_back(port_serdes_attr);
}
status = sai_port_api->create_port_serdes(&port_serdes_id, gSwitchId,
status = sai_port_api->create_port_serdes(&port_serdes_id, switch_id,
static_cast<uint32_t>(serdes_attr.size()+1),
attr_list.data());

Expand Down Expand Up @@ -5983,6 +5983,22 @@ void PortsOrch::getPortSerdesVal(const std::string& val_str,
}
}

void PortsOrch::getPortSerdesValBase10(const std::string& val_str,
std::vector<uint32_t> &lane_values)
{
SWSS_LOG_ENTER();

uint32_t lane_val;
std::string lane_str;
std::istringstream iss(val_str);

while (std::getline(iss, lane_str, ','))
{
lane_val = (uint32_t)std::stoul(lane_str, NULL, 10);
lane_values.push_back(lane_val);
}
}

bool PortsOrch::getPortAdvSpeedsVal(const std::string &val_str,
std::vector<uint32_t> &speed_values)
{
Expand Down Expand Up @@ -6339,6 +6355,50 @@ bool PortsOrch::initGearboxPort(Port &port)
SWSS_LOG_NOTICE("BOX: Connected Gearbox ports; system-side:0x%" PRIx64 " to line-side:0x%" PRIx64, systemPort, linePort);
m_gearboxPortListLaneMap[port.m_port_id] = make_tuple(systemPort, linePort);
port.m_line_side_id = linePort;

/* Set serdes tx taps on system and line side */
map<sai_port_serdes_attr_t, vector<uint32_t>> serdes_attr;
typedef pair<sai_port_serdes_attr_t, vector<uint32_t>> serdes_attr_pair;
vector<uint32_t> attr_val;
for (auto pair: tx_fir_strings_system_side) {
if (m_gearboxInterfaceMap[port.m_index].tx_firs.find(pair.first) != m_gearboxInterfaceMap[port.m_index].tx_firs.end() ) {
attr_val.clear();
getPortSerdesValBase10(m_gearboxInterfaceMap[port.m_index].tx_firs[pair.first], attr_val);
serdes_attr.insert(serdes_attr_pair(pair.second, attr_val));
}
}
if (serdes_attr.size() != 0)
{
if (setPortSerdesAttribute(systemPort, phyOid, serdes_attr))
{
SWSS_LOG_NOTICE("Set port %s system side preemphasis is success", port.m_alias.c_str());
}
else
{
SWSS_LOG_ERROR("Failed to set port %s system side pre-emphasis", port.m_alias.c_str());
return false;
}
}
serdes_attr.clear();
for (auto pair: tx_fir_strings_line_side) {
if (m_gearboxInterfaceMap[port.m_index].tx_firs.find(pair.first) != m_gearboxInterfaceMap[port.m_index].tx_firs.end() ) {
attr_val.clear();
getPortSerdesValBase10(m_gearboxInterfaceMap[port.m_index].tx_firs[pair.first], attr_val);
serdes_attr.insert(serdes_attr_pair(pair.second, attr_val));
}
}
if (serdes_attr.size() != 0)
{
if (setPortSerdesAttribute(linePort, phyOid, serdes_attr))
{
SWSS_LOG_NOTICE("Set port %s line side preemphasis is success", port.m_alias.c_str());
}
else
{
SWSS_LOG_ERROR("Failed to set port %s line side pre-emphasis", port.m_alias.c_str());
return false;
}
}
}
}

Expand Down
25 changes: 24 additions & 1 deletion orchagent/portsorch.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ static const unordered_map<string, sai_port_oper_status_t> string_oper_status =
{ "not present", SAI_PORT_OPER_STATUS_NOT_PRESENT }
};

static const std::map<std::string, sai_port_serdes_attr_t> tx_fir_strings_system_side =
{
{"system_tx_fir_pre1", SAI_PORT_SERDES_ATTR_TX_FIR_PRE1},
{"system_tx_fir_pre2", SAI_PORT_SERDES_ATTR_TX_FIR_PRE2},
{"system_tx_fir_pre3", SAI_PORT_SERDES_ATTR_TX_FIR_PRE3},
{"system_tx_fir_post1", SAI_PORT_SERDES_ATTR_TX_FIR_POST1},
{"system_tx_fir_post2", SAI_PORT_SERDES_ATTR_TX_FIR_POST2},
{"system_tx_fir_post3", SAI_PORT_SERDES_ATTR_TX_FIR_POST3},
{"system_tx_fir_main", SAI_PORT_SERDES_ATTR_TX_FIR_MAIN}
};

static const std::map<std::string, sai_port_serdes_attr_t> tx_fir_strings_line_side =
{
{"line_tx_fir_pre1", SAI_PORT_SERDES_ATTR_TX_FIR_PRE1},
{"line_tx_fir_pre2", SAI_PORT_SERDES_ATTR_TX_FIR_PRE2},
{"line_tx_fir_pre3", SAI_PORT_SERDES_ATTR_TX_FIR_PRE3},
{"line_tx_fir_post1", SAI_PORT_SERDES_ATTR_TX_FIR_POST1},
{"line_tx_fir_post2", SAI_PORT_SERDES_ATTR_TX_FIR_POST2},
{"line_tx_fir_post3", SAI_PORT_SERDES_ATTR_TX_FIR_POST3},
{"line_tx_fir_main", SAI_PORT_SERDES_ATTR_TX_FIR_MAIN}
};

struct PortUpdate
{
Port port;
Expand Down Expand Up @@ -330,11 +352,12 @@ class PortsOrch : public Orch, public Subject
void updateDbPortOperSpeed(Port &port, sai_uint32_t speed);

void getPortSerdesVal(const std::string& s, std::vector<uint32_t> &lane_values);
void getPortSerdesValBase10(const std::string& s, std::vector<uint32_t> &lane_values);
bool getPortAdvSpeedsVal(const std::string &s, std::vector<uint32_t> &speed_values);
bool getPortInterfaceTypeVal(const std::string &s, sai_port_interface_type_t &interface_type);
bool getPortAdvInterfaceTypesVal(const std::string &s, std::vector<uint32_t> &type_values);

bool setPortSerdesAttribute(sai_object_id_t port_id,
bool setPortSerdesAttribute(sai_object_id_t port_id, sai_object_id_t switch_id,
std::map<sai_port_serdes_attr_t, std::vector<uint32_t>> &serdes_attr);


Expand Down

0 comments on commit 1b7b466

Please sign in to comment.