@@ -325,7 +325,6 @@ static bool isValidPortTypeForLagMember(const Port& port)
325
325
PortsOrch::PortsOrch (DBConnector *db, DBConnector *stateDb, vector<table_name_with_pri_t > &tableNames, DBConnector *chassisAppDb) :
326
326
Orch(db, tableNames),
327
327
m_portStateTable(stateDb, STATE_PORT_TABLE_NAME),
328
- m_stateLinkTrainingTable(stateDb, STATE_LINK_TRAINING_TABLE_NAME),
329
328
port_stat_manager(PORT_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false ),
330
329
port_buffer_drop_stat_manager(PORT_BUFFER_DROP_STAT_FLEX_COUNTER_GROUP, StatsMode::READ, PORT_BUFFER_DROP_STAT_POLLING_INTERVAL_MS, false ),
331
330
queue_stat_manager(QUEUE_STAT_COUNTER_FLEX_COUNTER_GROUP, StatsMode::READ, QUEUE_STAT_FLEX_COUNTER_POLLING_INTERVAL_MS, false ),
@@ -1932,7 +1931,7 @@ void PortsOrch::initPortSupportedSpeeds(const std::string& alias, sai_object_id_
1932
1931
m_portStateTable.set (alias, v);
1933
1932
}
1934
1933
1935
- void PortsOrch::initPortCapabilityLinkTraining ( const Port &port)
1934
+ void PortsOrch::initPortCapLinkTraining ( Port &port)
1936
1935
{
1937
1936
sai_status_t status;
1938
1937
sai_attribute_t attr;
@@ -1941,11 +1940,11 @@ void PortsOrch::initPortCapabilityLinkTraining(const Port &port)
1941
1940
status = sai_port_api->set_port_attribute (port.m_port_id , &attr);
1942
1941
if (status == SAI_STATUS_SUCCESS)
1943
1942
{
1944
- string supp = attr.value .booldata ? " yes" : " no" ;
1945
- m_stateLinkTrainingTable.hset (port.m_alias , " supported" , supp);
1943
+ port.m_port_cap_lt = attr.value .booldata ;
1946
1944
}
1947
1945
else
1948
1946
{
1947
+ port.m_port_cap_lt = true ; /* This is for vstest */
1949
1948
SWSS_LOG_NOTICE (" Unable to get %s LT capability" , port.m_alias .c_str ());
1950
1949
}
1951
1950
}
@@ -2218,17 +2217,6 @@ task_process_status PortsOrch::setPortAutoNeg(sai_object_id_t id, int an)
2218
2217
return task_success;
2219
2218
}
2220
2219
2221
- bool PortsOrch::getPortCapabilityLinkTraining (const Port& port)
2222
- {
2223
- string supp;
2224
-
2225
- if (m_stateLinkTrainingTable.hget (port.m_alias , " supported" , supp))
2226
- {
2227
- return (supp == " yes" ) ? true : false ;
2228
- }
2229
- return false ;
2230
- }
2231
-
2232
2220
task_process_status PortsOrch::setPortLinkTraining (const Port &port, bool state)
2233
2221
{
2234
2222
SWSS_LOG_ENTER ();
@@ -2480,7 +2468,7 @@ bool PortsOrch::initPort(const string &alias, const string &role, const int inde
2480
2468
initGearboxPort (p);
2481
2469
2482
2470
/* Initialize port capabilities */
2483
- initPortCapabilityLinkTraining (p);
2471
+ initPortCapLinkTraining (p);
2484
2472
2485
2473
/* Add port to port list */
2486
2474
m_portList[alias] = p;
@@ -3081,7 +3069,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
3081
3069
lt = link_training_mode_map[lt_str];
3082
3070
if (lt != p.m_link_training )
3083
3071
{
3084
- if (!getPortCapabilityLinkTraining (p) )
3072
+ if (!p. m_port_cap_lt )
3085
3073
{
3086
3074
SWSS_LOG_ERROR (" %s: LT is not supported by the ASIC" , alias.c_str ());
3087
3075
// Don't retry
@@ -3103,10 +3091,11 @@ void PortsOrch::doPortTask(Consumer &consumer)
3103
3091
}
3104
3092
continue ;
3105
3093
}
3106
- m_stateLinkTrainingTable .hset (p. m_alias , " status " , lt > 0 ? " on " : " off " );
3094
+ m_portStateTable .hset (alias , " link_training_status " , lt_str );
3107
3095
SWSS_LOG_NOTICE (" Set port %s LT from %d to %d" , alias.c_str (), p.m_link_training , lt);
3108
3096
p.m_link_training = lt;
3109
3097
m_portList[alias] = p;
3098
+ updatePortStatePoll (p, PORT_STATE_POLL_LT, (lt > 0 ));
3110
3099
}
3111
3100
}
3112
3101
@@ -5938,6 +5927,19 @@ void PortsOrch::updatePortOperStatus(Port &port, sai_port_oper_status_t status)
5938
5927
if (port.m_type == Port::PHY)
5939
5928
{
5940
5929
updateDbPortOperStatus (port, status);
5930
+ if (port.m_admin_state_up && port.m_link_training > 0 )
5931
+ {
5932
+ updatePortStateLinkTraining (port);
5933
+ if (status == SAI_PORT_OPER_STATUS_UP)
5934
+ {
5935
+ updatePortStatePoll (port, PORT_STATE_POLL_LT, false );
5936
+ }
5937
+ else
5938
+ {
5939
+ /* Restart port state polling upon link down event */
5940
+ updatePortStatePoll (port, PORT_STATE_POLL_LT, true );
5941
+ }
5942
+ }
5941
5943
}
5942
5944
port.m_oper_status = status;
5943
5945
@@ -7127,7 +7129,7 @@ bool PortsOrch::decrFdbCount(const std::string& alias, int count)
7127
7129
return true ;
7128
7130
}
7129
7131
7130
- void PortsOrch::updatePortLinkTrainingStatus (const Port &port)
7132
+ void PortsOrch::updatePortStateLinkTraining (const Port &port)
7131
7133
{
7132
7134
SWSS_LOG_ENTER ();
7133
7135
@@ -7138,7 +7140,7 @@ void PortsOrch::updatePortLinkTrainingStatus(const Port &port)
7138
7140
7139
7141
string status = " off" ;
7140
7142
7141
- if ((port.m_link_training > 0 ) && getPortCapabilityLinkTraining ( port) )
7143
+ if ((port.m_link_training > 0 ) && port. m_port_cap_lt )
7142
7144
{
7143
7145
sai_port_link_training_rx_status_t rx_status;
7144
7146
sai_port_link_training_failure_status_t failure;
@@ -7164,15 +7166,45 @@ void PortsOrch::updatePortLinkTrainingStatus(const Port &port)
7164
7166
}
7165
7167
}
7166
7168
}
7167
- m_stateLinkTrainingTable.hset (port.m_alias , " status" , status);
7169
+
7170
+ m_portStateTable.hset (port.m_alias , " link_training_status" , status);
7171
+ }
7172
+
7173
+ void PortsOrch::updatePortStatePoll (const Port &port, port_state_poll_t type, bool set)
7174
+ {
7175
+ if (type == PORT_STATE_POLL_NONE)
7176
+ {
7177
+ return ;
7178
+ }
7179
+ if (set)
7180
+ {
7181
+ m_port_state_poll[port.m_alias ] |= type;
7182
+ m_timer->start ();
7183
+ }
7184
+ else
7185
+ {
7186
+ m_port_state_poll[port.m_alias ] &= ~type;
7187
+ }
7168
7188
}
7169
7189
7170
7190
void PortsOrch::doTask (swss::SelectableTimer &timer)
7171
7191
{
7172
- SWSS_LOG_ENTER () ;
7192
+ Port port ;
7173
7193
7174
- for (auto it = m_portList.begin (); it != m_portList.end (); ++it)
7194
+ for (auto it = m_port_state_poll.begin (); it != m_port_state_poll.end (); ++it)
7195
+ {
7196
+ if ((it->second == 0 ) || !getPort (it->first , port))
7197
+ {
7198
+ m_port_state_poll.erase (it);
7199
+ continue ;
7200
+ }
7201
+ if (port.m_admin_state_up && (it->second & PORT_STATE_POLL_LT))
7202
+ {
7203
+ updatePortStateLinkTraining (port);
7204
+ }
7205
+ }
7206
+ if (m_port_state_poll.size () == 0 )
7175
7207
{
7176
- updatePortLinkTrainingStatus (it-> second );
7208
+ m_timer-> stop ( );
7177
7209
}
7178
7210
}
0 commit comments