Skip to content

Commit 6695113

Browse files
authored
[gearbox] Support setting tx taps on gearbox ports (sonic-net#2158)
What I did This change adds support for setting tx tap or tuning values on gearbox ports. It uses the SAI attributes such as SAI_PORT_SERDES_ATTR_TX_FIR_PRE1 to communicate with SAI-based gearbox drivers. For the values, they are provided in the format like "system_tx_fir_pre2": [1,1] for an interface from gearbox_config.json. Why I did it How I verified it We verified that values provided in sonic-net#10084 are set to the chip with this change. Added test to tests/test_gearbox.py. The added test will not pass until the following two changes (which should be merged first) are merged: Support SAI_PORT_ATTR_PORT_SERDES_ID on vs gearbox: sonic-net/sonic-sairedis#1082 Add gearbox taps to vs gearbox_config.json: sonic-net#11480
1 parent 872f7bf commit 6695113

File tree

7 files changed

+145
-9
lines changed

7 files changed

+145
-9
lines changed

gearsyncd/gearboxparser.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#include "gearboxparser.h"
18+
#include "gearboxutils.h"
1819
#include "phyparser.h"
1920
#include <vector>
2021

@@ -42,7 +43,7 @@ bool GearboxParser::parse()
4243
return false;
4344
}
4445

45-
json phys, phy, interfaces, interface, val, lanes;
46+
json phys, phy, interfaces, interface, val, lanes, txFir;
4647

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

@@ -285,6 +286,27 @@ bool GearboxParser::parse()
285286
SWSS_LOG_ERROR("missing 'line_lanes' field in 'interfaces' item %d in gearbox configuration", iter);
286287
return false;
287288
}
289+
290+
for (std::string txFirKey: swss::tx_fir_strings)
291+
{
292+
if (interface.find(txFirKey) != interface.end())
293+
{
294+
txFir = interface[txFirKey]; // vec
295+
std::string txFirValuesStr("");
296+
for (uint32_t iter2 = 0; iter2 < txFir.size(); iter2++)
297+
{
298+
val = txFir[iter2];
299+
if (txFirValuesStr.length() > 0)
300+
{
301+
txFirValuesStr += ",";
302+
}
303+
txFirValuesStr += std::to_string(val.get<int>());
304+
}
305+
attr = std::make_pair(txFirKey, txFirValuesStr);
306+
attrs.push_back(attr);
307+
}
308+
}
309+
288310
std::string key;
289311
key = "interface:" + std::to_string(index);
290312
if (getWriteToDb() == true)

lib/gearboxutils.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ std::map<int, gearbox_interface_t> GearboxUtils::loadInterfaceMap(Table *gearbox
266266
}
267267
}
268268
}
269+
else if (tx_fir_strings.find(val.first) != tx_fir_strings.end())
270+
{
271+
SWSS_LOG_DEBUG("Parsed key:%s, val:%s", val.first.c_str(), val.second.c_str());
272+
interface.tx_firs[val.first] = val.second;
273+
}
269274
}
270275
gearboxInterfaceMap[interface.index] = interface;
271276
}

lib/gearboxutils.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@
3030

3131
namespace swss {
3232

33+
static const std::set<std::string> tx_fir_strings =
34+
{
35+
"system_tx_fir_pre1",
36+
"system_tx_fir_pre2",
37+
"system_tx_fir_pre3",
38+
"system_tx_fir_post1",
39+
"system_tx_fir_post2",
40+
"system_tx_fir_post3",
41+
"system_tx_fir_main",
42+
"line_tx_fir_pre1",
43+
"line_tx_fir_pre2",
44+
"line_tx_fir_pre3",
45+
"line_tx_fir_post1",
46+
"line_tx_fir_post2",
47+
"line_tx_fir_post3",
48+
"line_tx_fir_main"
49+
};
50+
3351
typedef struct
3452
{
3553
int phy_id;
@@ -54,6 +72,7 @@ typedef struct
5472
int phy_id;
5573
std::set<int> line_lanes;
5674
std::set<int> system_lanes;
75+
std::map<std::string, std::string> tx_firs;
5776
} gearbox_interface_t;
5877

5978
typedef struct

orchagent/p4orch/tests/fake_portorch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ void PortsOrch::updateDbPortOperSpeed(Port &port, sai_uint32_t speed)
644644
{
645645
}
646646

647-
void PortsOrch::getPortSerdesVal(const std::string &s, std::vector<uint32_t> &lane_values)
647+
void PortsOrch::getPortSerdesVal(const std::string &s, std::vector<uint32_t> &lane_values, int base)
648648
{
649649
}
650650

orchagent/portsorch.cpp

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3761,7 +3761,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
37613761
p.m_preemphasis = serdes_attr;
37623762
m_portList[alias] = p;
37633763
}
3764-
else if (setPortSerdesAttribute(p.m_port_id, serdes_attr))
3764+
else if (setPortSerdesAttribute(p.m_port_id, gSwitchId, serdes_attr))
37653765
{
37663766
SWSS_LOG_NOTICE("Set port %s preemphasis is success", alias.c_str());
37673767
p.m_preemphasis = serdes_attr;
@@ -6923,7 +6923,7 @@ bool PortsOrch::removeAclTableGroup(const Port &p)
69236923
return true;
69246924
}
69256925

6926-
bool PortsOrch::setPortSerdesAttribute(sai_object_id_t port_id,
6926+
bool PortsOrch::setPortSerdesAttribute(sai_object_id_t port_id, sai_object_id_t switch_id,
69276927
map<sai_port_serdes_attr_t, vector<uint32_t>> &serdes_attr)
69286928
{
69296929
SWSS_LOG_ENTER();
@@ -6975,7 +6975,7 @@ bool PortsOrch::setPortSerdesAttribute(sai_object_id_t port_id,
69756975
port_serdes_attr.value.u32list.list = it->second.data();
69766976
attr_list.emplace_back(port_serdes_attr);
69776977
}
6978-
status = sai_port_api->create_port_serdes(&port_serdes_id, gSwitchId,
6978+
status = sai_port_api->create_port_serdes(&port_serdes_id, switch_id,
69796979
static_cast<uint32_t>(serdes_attr.size()+1),
69806980
attr_list.data());
69816981

@@ -7026,7 +7026,8 @@ void PortsOrch::removePortSerdesAttribute(sai_object_id_t port_id)
70267026
}
70277027

70287028
void PortsOrch::getPortSerdesVal(const std::string& val_str,
7029-
std::vector<uint32_t> &lane_values)
7029+
std::vector<uint32_t> &lane_values,
7030+
int base)
70307031
{
70317032
SWSS_LOG_ENTER();
70327033

@@ -7036,7 +7037,7 @@ void PortsOrch::getPortSerdesVal(const std::string& val_str,
70367037

70377038
while (std::getline(iss, lane_str, ','))
70387039
{
7039-
lane_val = (uint32_t)std::stoul(lane_str, NULL, 16);
7040+
lane_val = (uint32_t)std::stoul(lane_str, NULL, base);
70407041
lane_values.push_back(lane_val);
70417042
}
70427043
}
@@ -7412,6 +7413,50 @@ bool PortsOrch::initGearboxPort(Port &port)
74127413

74137414
fields[0] = FieldValueTuple(port.m_alias + "_line", sai_serialize_object_id(linePort));
74147415
m_gbcounterTable->set("", fields);
7416+
7417+
/* Set serdes tx taps on system and line side */
7418+
map<sai_port_serdes_attr_t, vector<uint32_t>> serdes_attr;
7419+
typedef pair<sai_port_serdes_attr_t, vector<uint32_t>> serdes_attr_pair;
7420+
vector<uint32_t> attr_val;
7421+
for (auto pair: tx_fir_strings_system_side) {
7422+
if (m_gearboxInterfaceMap[port.m_index].tx_firs.find(pair.first) != m_gearboxInterfaceMap[port.m_index].tx_firs.end() ) {
7423+
attr_val.clear();
7424+
getPortSerdesVal(m_gearboxInterfaceMap[port.m_index].tx_firs[pair.first], attr_val, 10);
7425+
serdes_attr.insert(serdes_attr_pair(pair.second, attr_val));
7426+
}
7427+
}
7428+
if (serdes_attr.size() != 0)
7429+
{
7430+
if (setPortSerdesAttribute(systemPort, phyOid, serdes_attr))
7431+
{
7432+
SWSS_LOG_NOTICE("Set port %s system side preemphasis is success", port.m_alias.c_str());
7433+
}
7434+
else
7435+
{
7436+
SWSS_LOG_ERROR("Failed to set port %s system side pre-emphasis", port.m_alias.c_str());
7437+
return false;
7438+
}
7439+
}
7440+
serdes_attr.clear();
7441+
for (auto pair: tx_fir_strings_line_side) {
7442+
if (m_gearboxInterfaceMap[port.m_index].tx_firs.find(pair.first) != m_gearboxInterfaceMap[port.m_index].tx_firs.end() ) {
7443+
attr_val.clear();
7444+
getPortSerdesVal(m_gearboxInterfaceMap[port.m_index].tx_firs[pair.first], attr_val, 10);
7445+
serdes_attr.insert(serdes_attr_pair(pair.second, attr_val));
7446+
}
7447+
}
7448+
if (serdes_attr.size() != 0)
7449+
{
7450+
if (setPortSerdesAttribute(linePort, phyOid, serdes_attr))
7451+
{
7452+
SWSS_LOG_NOTICE("Set port %s line side preemphasis is success", port.m_alias.c_str());
7453+
}
7454+
else
7455+
{
7456+
SWSS_LOG_ERROR("Failed to set port %s line side pre-emphasis", port.m_alias.c_str());
7457+
return false;
7458+
}
7459+
}
74157460
}
74167461
}
74177462

orchagent/portsorch.h

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,28 @@ static const unordered_map<string, sai_port_oper_status_t> string_oper_status =
4949
{ "not present", SAI_PORT_OPER_STATUS_NOT_PRESENT }
5050
};
5151

52+
static const std::map<std::string, sai_port_serdes_attr_t> tx_fir_strings_system_side =
53+
{
54+
{"system_tx_fir_pre1", SAI_PORT_SERDES_ATTR_TX_FIR_PRE1},
55+
{"system_tx_fir_pre2", SAI_PORT_SERDES_ATTR_TX_FIR_PRE2},
56+
{"system_tx_fir_pre3", SAI_PORT_SERDES_ATTR_TX_FIR_PRE3},
57+
{"system_tx_fir_post1", SAI_PORT_SERDES_ATTR_TX_FIR_POST1},
58+
{"system_tx_fir_post2", SAI_PORT_SERDES_ATTR_TX_FIR_POST2},
59+
{"system_tx_fir_post3", SAI_PORT_SERDES_ATTR_TX_FIR_POST3},
60+
{"system_tx_fir_main", SAI_PORT_SERDES_ATTR_TX_FIR_MAIN}
61+
};
62+
63+
static const std::map<std::string, sai_port_serdes_attr_t> tx_fir_strings_line_side =
64+
{
65+
{"line_tx_fir_pre1", SAI_PORT_SERDES_ATTR_TX_FIR_PRE1},
66+
{"line_tx_fir_pre2", SAI_PORT_SERDES_ATTR_TX_FIR_PRE2},
67+
{"line_tx_fir_pre3", SAI_PORT_SERDES_ATTR_TX_FIR_PRE3},
68+
{"line_tx_fir_post1", SAI_PORT_SERDES_ATTR_TX_FIR_POST1},
69+
{"line_tx_fir_post2", SAI_PORT_SERDES_ATTR_TX_FIR_POST2},
70+
{"line_tx_fir_post3", SAI_PORT_SERDES_ATTR_TX_FIR_POST3},
71+
{"line_tx_fir_main", SAI_PORT_SERDES_ATTR_TX_FIR_MAIN}
72+
};
73+
5274
struct PortUpdate
5375
{
5476
Port port;
@@ -389,12 +411,12 @@ class PortsOrch : public Orch, public Subject
389411
void refreshPortStateAutoNeg(const Port &port);
390412
void refreshPortStateLinkTraining(const Port &port);
391413

392-
void getPortSerdesVal(const std::string& s, std::vector<uint32_t> &lane_values);
414+
void getPortSerdesVal(const std::string& s, std::vector<uint32_t> &lane_values, int base = 16);
393415
bool getPortAdvSpeedsVal(const std::string &s, std::vector<uint32_t> &speed_values);
394416
bool getPortInterfaceTypeVal(const std::string &s, sai_port_interface_type_t &interface_type);
395417
bool getPortAdvInterfaceTypesVal(const std::string &s, std::vector<uint32_t> &type_values);
396418

397-
bool setPortSerdesAttribute(sai_object_id_t port_id,
419+
bool setPortSerdesAttribute(sai_object_id_t port_id, sai_object_id_t switch_id,
398420
std::map<sai_port_serdes_attr_t, std::vector<uint32_t>> &serdes_attr);
399421

400422

tests/test_gearbox.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def __init__(self, db_id: int, connector: str, gearbox: Gearbox):
7070
DVSDatabase.__init__(self, db_id, connector)
7171
self.gearbox = gearbox
7272
self.ports = {}
73+
self.port_oid_to_intf_idx = {}
7374
self._wait_for_gb_asic_db_to_initialize()
7475

7576
for connector in self.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT_CONNECTOR"):
@@ -88,9 +89,31 @@ def __init__(self, db_id: int, connector: str, gearbox: Gearbox):
8889
if intf["system_lanes"] == system_lanes:
8990
assert intf["line_lanes"] == line_lanes
9091
self.ports[intf["index"]] = (system_port_oid, line_port_oid)
92+
self.port_oid_to_intf_idx[system_port_oid] = (i, True)
93+
self.port_oid_to_intf_idx[line_port_oid] = (i, False)
9194

9295
assert len(self.ports) == len(self.gearbox.interfaces)
9396

97+
for serdes in self.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_PORT_SERDES"):
98+
fvs = self.get_entry("ASIC_STATE:SAI_OBJECT_TYPE_PORT_SERDES", serdes)
99+
port_oid = fvs.get("SAI_PORT_SERDES_ATTR_PORT_ID")
100+
intf_idx, is_system = self.port_oid_to_intf_idx[port_oid]
101+
intf = self.gearbox.interfaces[ intf_idx ]
102+
appl_db_key_prefix = 'system_' if is_system else 'line_'
103+
for asic_db_key, appl_db_key_suffix in [
104+
("SAI_PORT_SERDES_ATTR_TX_FIR_MAIN", "tx_fir_main"),
105+
("SAI_PORT_SERDES_ATTR_TX_FIR_PRE1", "tx_fir_pre1"),
106+
("SAI_PORT_SERDES_ATTR_TX_FIR_PRE2", "tx_fir_pre2"),
107+
("SAI_PORT_SERDES_ATTR_TX_FIR_PRE3", "tx_fir_pre3"),
108+
("SAI_PORT_SERDES_ATTR_TX_FIR_POST1", "tx_fir_post1"),
109+
("SAI_PORT_SERDES_ATTR_TX_FIR_POST2", "tx_fir_post2"),
110+
("SAI_PORT_SERDES_ATTR_TX_FIR_POST3", "tx_fir_post3"),
111+
]:
112+
if asic_db_key not in fvs:
113+
continue
114+
asic_db_value = fvs.get(asic_db_key).split(":")[-1]
115+
assert intf[appl_db_key_prefix + appl_db_key_suffix] == asic_db_value
116+
94117
def _wait_for_gb_asic_db_to_initialize(self) -> None:
95118
"""Wait up to 30 seconds for the default fields to appear in ASIC DB."""
96119
def _verify_db_contents():

0 commit comments

Comments
 (0)