@@ -1944,8 +1944,37 @@ void PortsOrch::initPortCapAutoNeg(Port &port)
19441944 }
19451945 else
19461946 {
1947- port.m_cap_an = 0 ;
1948- SWSS_LOG_NOTICE (" Unable to get %s AN capability" , port.m_alias .c_str ());
1947+ // To avoid breakage on the existing platforms, AN should be 1 by default
1948+ port.m_cap_an = 1 ;
1949+ SWSS_LOG_WARN (" Unable to get %s AN capability, assumming it's supported" ,
1950+ port.m_alias .c_str ());
1951+ }
1952+ }
1953+
1954+ void PortsOrch::initPortCapLinkTraining (Port &port)
1955+ {
1956+ sai_status_t status;
1957+ sai_attribute_t attr;
1958+
1959+ // TODO: Use SAI_PORT_ATTR_SUPPORTED_LINK_TRAINING_MODE for the query
1960+ //
1961+ // While SAI_PORT_ATTR_SUPPORTED_LINK_TRAINING_MODE is available at SAI master,
1962+ // it's not available in SAI v1.10 paried with SONiC.202205.
1963+ // And given that LT is part of AN, it should be okay to use
1964+ // SAI_PORT_ATTR_SUPPORTED_AUTO_NEG_MODE as a fallback plan.
1965+ attr.id = SAI_PORT_ATTR_SUPPORTED_AUTO_NEG_MODE ;
1966+ status = sai_port_api->get_port_attribute (port.m_port_id , 1 , &attr);
1967+ if (status == SAI_STATUS_SUCCESS )
1968+ {
1969+ port.m_cap_lt = attr.value .booldata ? 1 : 0 ;
1970+ }
1971+ else
1972+ {
1973+ // This is a new feature, hence none of breakage should be observed by
1974+ // having the LT capability flagged as NOT SUPPORTED upon a get failure
1975+ port.m_cap_lt = 0 ;
1976+ SWSS_LOG_WARN (" Unable to get %s LT capability, assumming it's NOT supported" ,
1977+ port.m_alias .c_str ());
19491978 }
19501979}
19511980
@@ -3118,6 +3147,19 @@ void PortsOrch::doPortTask(Consumer &consumer)
31183147 lt = link_training_mode_map[lt_str];
31193148 if (lt != p.m_link_training )
31203149 {
3150+ if (p.m_cap_lt < 0 )
3151+ {
3152+ initPortCapLinkTraining (p);
3153+ m_portList[alias] = p;
3154+ }
3155+ if (p.m_cap_lt < 1 )
3156+ {
3157+ SWSS_LOG_WARN (" %s: LT is not supported by the ASIC" , alias.c_str ());
3158+ // Don't retry
3159+ it = consumer.m_toSync .erase (it);
3160+ continue ;
3161+ }
3162+
31213163 auto status = setPortLinkTraining (p, lt > 0 ? true : false );
31223164 if (status != task_success)
31233165 {
@@ -5985,7 +6027,9 @@ void PortsOrch::updatePortOperStatus(Port &port, sai_port_oper_status_t status)
59856027 {
59866028 if (status == SAI_PORT_OPER_STATUS_UP )
59876029 {
6030+ /* Refresh AN port states */
59886031 updatePortStateAutoNeg (port);
6032+ /* Stop port state polling for AN */
59896033 updatePortStatePoll (port, PORT_STATE_POLL_AN , false );
59906034 }
59916035 else
@@ -5997,9 +6041,11 @@ void PortsOrch::updatePortOperStatus(Port &port, sai_port_oper_status_t status)
59976041 }
59986042 if (port.m_admin_state_up && port.m_link_training > 0 )
59996043 {
6044+ /* Refresh LT port states for both link up and down */
60006045 updatePortStateLinkTraining (port);
60016046 if (status == SAI_PORT_OPER_STATUS_UP )
60026047 {
6048+ /* Stop port state polling for LT */
60036049 updatePortStatePoll (port, PORT_STATE_POLL_LT , false );
60046050 }
60056051 else
@@ -7193,6 +7239,7 @@ bool PortsOrch::decrFdbCount(const std::string& alias, int count)
71937239 return true ;
71947240}
71957241
7242+ /* Refresh the per-port Auto-Negotiation operational states */
71967243void PortsOrch::updatePortStateAutoNeg (const Port &port)
71977244{
71987245 SWSS_LOG_ENTER ();
@@ -7215,6 +7262,7 @@ void PortsOrch::updatePortStateAutoNeg(const Port &port)
72157262 }
72167263}
72177264
7265+ /* Refresh the per-port Link-Training operational states */
72187266void PortsOrch::updatePortStateLinkTraining (const Port &port)
72197267{
72207268 SWSS_LOG_ENTER ();
@@ -7226,7 +7274,7 @@ void PortsOrch::updatePortStateLinkTraining(const Port &port)
72267274
72277275 string status = " off" ;
72287276
7229- if (port.m_link_training > 0 )
7277+ if (( port.m_link_training > 0 ) && (port. m_cap_lt > 0 ) )
72307278 {
72317279 sai_port_link_training_rx_status_t rx_status;
72327280 sai_port_link_training_failure_status_t failure;
@@ -7256,6 +7304,7 @@ void PortsOrch::updatePortStateLinkTraining(const Port &port)
72567304 m_portStateTable.hset (port.m_alias , " link_training_status" , status);
72577305}
72587306
7307+ /* Activate/De-activate a specific port state poller task */
72597308void PortsOrch::updatePortStatePoll (const Port &port, port_state_poll_t type, bool active)
72607309{
72617310 if (type == PORT_STATE_POLL_NONE )
0 commit comments