@@ -542,6 +542,25 @@ bool PortsOrch::setPortAdminStatus(sai_object_id_t id, bool up)
542
542
return true ;
543
543
}
544
544
545
+ bool PortsOrch::getPortAdminStatus (sai_object_id_t id, bool &up)
546
+ {
547
+ SWSS_LOG_ENTER ();
548
+
549
+ sai_attribute_t attr;
550
+ attr.id = SAI_PORT_ATTR_ADMIN_STATE;
551
+
552
+ sai_status_t status = sai_port_api->get_port_attribute (id, 1 , &attr);
553
+ if (status != SAI_STATUS_SUCCESS)
554
+ {
555
+ SWSS_LOG_ERROR (" Failed to get admin status for port pid:%lx" , id);
556
+ return false ;
557
+ }
558
+
559
+ up = attr.value .booldata ;
560
+
561
+ return true ;
562
+ }
563
+
545
564
bool PortsOrch::setPortMtu (sai_object_id_t id, sai_uint32_t mtu)
546
565
{
547
566
SWSS_LOG_ENTER ();
@@ -1731,45 +1750,43 @@ void PortsOrch::doPortTask(Consumer &consumer)
1731
1750
}
1732
1751
else
1733
1752
{
1734
- sai_uint32_t current_speed;
1735
-
1736
1753
if (!isSpeedSupported (alias, p.m_port_id , speed))
1737
1754
{
1738
1755
it++;
1739
1756
continue ;
1740
1757
}
1741
1758
1742
- if (getPortSpeed (p. m_port_id , current_speed) )
1759
+ if (p. m_admin_state_up )
1743
1760
{
1744
- if (speed != current_speed)
1761
+ /* Bring port down before applying speed */
1762
+ if (!setPortAdminStatus (p.m_port_id , false ))
1745
1763
{
1746
- if (setPortAdminStatus (p.m_port_id , false ))
1747
- {
1748
- if (setPortSpeed (p.m_port_id , speed))
1749
- {
1750
- SWSS_LOG_NOTICE (" Set port %s speed to %u" , alias.c_str (), speed);
1751
- }
1752
- else
1753
- {
1754
- SWSS_LOG_ERROR (" Failed to set port %s speed to %u" , alias.c_str (), speed);
1755
- it++;
1756
- continue ;
1757
- }
1758
- }
1759
- else
1760
- {
1761
- SWSS_LOG_ERROR (" Failed to set port admin status DOWN to set speed" );
1762
- it++;
1763
- continue ;
1764
- }
1764
+ SWSS_LOG_ERROR (" Failed to set port %s admin status DOWN to set speed" , alias.c_str ());
1765
+ it++;
1766
+ continue ;
1767
+ }
1768
+
1769
+ p.m_admin_state_up = false ;
1770
+ m_portList[alias] = p;
1771
+
1772
+ if (!setPortSpeed (p.m_port_id , speed))
1773
+ {
1774
+ SWSS_LOG_ERROR (" Failed to set port %s speed to %u" , alias.c_str (), speed);
1775
+ it++;
1776
+ continue ;
1765
1777
}
1766
1778
}
1767
1779
else
1768
1780
{
1769
- SWSS_LOG_ERROR (" Failed to get current speed for port %s" , alias.c_str ());
1770
- it++;
1771
- continue ;
1781
+ /* Port is already down, setting speed */
1782
+ if (!setPortSpeed (p.m_port_id , speed))
1783
+ {
1784
+ SWSS_LOG_ERROR (" Failed to set port %s speed to %u" , alias.c_str (), speed);
1785
+ it++;
1786
+ continue ;
1787
+ }
1772
1788
}
1789
+ SWSS_LOG_NOTICE (" Set port %s speed to %u" , alias.c_str (), speed);
1773
1790
}
1774
1791
m_portList[alias].m_speed = speed;
1775
1792
}
@@ -1794,20 +1811,6 @@ void PortsOrch::doPortTask(Consumer &consumer)
1794
1811
}
1795
1812
}
1796
1813
1797
- if (!admin_status.empty ())
1798
- {
1799
- if (setPortAdminStatus (p.m_port_id , admin_status == " up" ))
1800
- {
1801
- SWSS_LOG_NOTICE (" Set port %s admin status to %s" , alias.c_str (), admin_status.c_str ());
1802
- }
1803
- else
1804
- {
1805
- SWSS_LOG_ERROR (" Failed to set port %s admin status to %s" , alias.c_str (), admin_status.c_str ());
1806
- it++;
1807
- continue ;
1808
- }
1809
- }
1810
-
1811
1814
if (!fec_mode.empty ())
1812
1815
{
1813
1816
if (fec_mode_map.find (fec_mode) != fec_mode_map.end ())
@@ -1848,6 +1851,23 @@ void PortsOrch::doPortTask(Consumer &consumer)
1848
1851
continue ;
1849
1852
}
1850
1853
}
1854
+
1855
+ /* Last step set port admin status */
1856
+ if (!admin_status.empty () && (p.m_admin_state_up != (admin_status == " up" )))
1857
+ {
1858
+ if (setPortAdminStatus (p.m_port_id , admin_status == " up" ))
1859
+ {
1860
+ p.m_admin_state_up = (admin_status == " up" );
1861
+ m_portList[alias] = p;
1862
+ SWSS_LOG_NOTICE (" Set port %s admin status to %s" , alias.c_str (), admin_status.c_str ());
1863
+ }
1864
+ else
1865
+ {
1866
+ SWSS_LOG_ERROR (" Failed to set port %s admin status to %s" , alias.c_str (), admin_status.c_str ());
1867
+ it++;
1868
+ continue ;
1869
+ }
1870
+ }
1851
1871
}
1852
1872
}
1853
1873
else
@@ -2412,6 +2432,20 @@ bool PortsOrch::initializePort(Port &port)
2412
2432
port.m_oper_status = SAI_PORT_OPER_STATUS_DOWN;
2413
2433
}
2414
2434
2435
+ /* initialize port admin status */
2436
+ if (!getPortAdminStatus (port.m_port_id , port.m_admin_state_up ))
2437
+ {
2438
+ SWSS_LOG_ERROR (" Failed to get initial port admin status %s" , port.m_alias .c_str ());
2439
+ return false ;
2440
+ }
2441
+
2442
+ /* initialize port admin speed */
2443
+ if (!getPortSpeed (port.m_port_id , port.m_speed ))
2444
+ {
2445
+ SWSS_LOG_ERROR (" Failed to get initial port admin speed %d" , port.m_speed );
2446
+ return false ;
2447
+ }
2448
+
2415
2449
/*
2416
2450
* always initialize Port SAI_HOSTIF_ATTR_OPER_STATUS based on oper_status value in appDB.
2417
2451
*/
0 commit comments