@@ -1161,6 +1161,34 @@ bool PortsOrch::getPortAdminStatus(sai_object_id_t id, bool &up)
1161
1161
return true ;
1162
1162
}
1163
1163
1164
+ bool PortsOrch::getPortMtu (const Port& port, sai_uint32_t &mtu)
1165
+ {
1166
+ SWSS_LOG_ENTER ();
1167
+
1168
+ sai_attribute_t attr;
1169
+ attr.id = SAI_PORT_ATTR_MTU;
1170
+
1171
+ sai_status_t status = sai_port_api->get_port_attribute (port.m_port_id , 1 , &attr);
1172
+
1173
+ if (status != SAI_STATUS_SUCCESS)
1174
+ {
1175
+ task_process_status handle_status = handleSaiGetStatus (SAI_API_PORT, status);
1176
+ if (handle_status != task_success)
1177
+ {
1178
+ return false ;
1179
+ }
1180
+ }
1181
+
1182
+ mtu = attr.value .u32 - (uint32_t )(sizeof (struct ether_header ) + FCS_LEN + VLAN_TAG_LEN);
1183
+
1184
+ if (isMACsecPort (port.m_port_id ))
1185
+ {
1186
+ mtu -= MAX_MACSEC_SECTAG_SIZE;
1187
+ }
1188
+
1189
+ return true ;
1190
+ }
1191
+
1164
1192
bool PortsOrch::setPortMtu (const Port& port, sai_uint32_t mtu)
1165
1193
{
1166
1194
SWSS_LOG_ENTER ();
@@ -1188,7 +1216,10 @@ bool PortsOrch::setPortMtu(const Port& port, sai_uint32_t mtu)
1188
1216
}
1189
1217
}
1190
1218
1191
- setGearboxPortsAttr (port, SAI_PORT_ATTR_MTU, &mtu);
1219
+ if (m_gearboxEnabled)
1220
+ {
1221
+ setGearboxPortsAttr (port, SAI_PORT_ATTR_MTU, &mtu);
1222
+ }
1192
1223
SWSS_LOG_INFO (" Set MTU %u to port pid:%" PRIx64, attr.value .u32 , port.m_port_id );
1193
1224
return true ;
1194
1225
}
@@ -4551,6 +4582,13 @@ bool PortsOrch::initializePort(Port &port)
4551
4582
return false ;
4552
4583
}
4553
4584
4585
+ /* initialize port mtu */
4586
+ if (!getPortMtu (port, port.m_mtu ))
4587
+ {
4588
+ SWSS_LOG_ERROR (" Failed to get initial port mtu %d" , port.m_mtu );
4589
+ return false ;
4590
+ }
4591
+
4554
4592
/*
4555
4593
* always initialize Port SAI_HOSTIF_ATTR_OPER_STATUS based on oper_status value in appDB.
4556
4594
*/
0 commit comments