@@ -1161,6 +1161,30 @@ 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
+ return false ;
1176
+ }
1177
+
1178
+ mtu = attr.value .u32 - (uint32_t )(sizeof (struct ether_header ) + FCS_LEN + VLAN_TAG_LEN);
1179
+
1180
+ if (isMACsecPort (port.m_port_id ))
1181
+ {
1182
+ mtu -= MAX_MACSEC_SECTAG_SIZE;
1183
+ }
1184
+
1185
+ return true ;
1186
+ }
1187
+
1164
1188
bool PortsOrch::setPortMtu (const Port& port, sai_uint32_t mtu)
1165
1189
{
1166
1190
SWSS_LOG_ENTER ();
@@ -1188,7 +1212,10 @@ bool PortsOrch::setPortMtu(const Port& port, sai_uint32_t mtu)
1188
1212
}
1189
1213
}
1190
1214
1191
- setGearboxPortsAttr (port, SAI_PORT_ATTR_MTU, &mtu);
1215
+ if (m_gearboxEnabled)
1216
+ {
1217
+ setGearboxPortsAttr (port, SAI_PORT_ATTR_MTU, &mtu);
1218
+ }
1192
1219
SWSS_LOG_INFO (" Set MTU %u to port pid:%" PRIx64, attr.value .u32 , port.m_port_id );
1193
1220
return true ;
1194
1221
}
@@ -4551,6 +4578,13 @@ bool PortsOrch::initializePort(Port &port)
4551
4578
return false ;
4552
4579
}
4553
4580
4581
+ /* initialize port mtu */
4582
+ if (!getPortMtu (port, port.m_mtu ))
4583
+ {
4584
+ SWSS_LOG_ERROR (" Failed to get initial port mtu %d" , port.m_mtu );
4585
+ return false ;
4586
+ }
4587
+
4554
4588
/*
4555
4589
* always initialize Port SAI_HOSTIF_ATTR_OPER_STATUS based on oper_status value in appDB.
4556
4590
*/
@@ -7451,7 +7485,10 @@ void PortsOrch::setMACsecEnabledState(sai_object_id_t port_id, bool enabled)
7451
7485
m_macsecEnabledPorts.erase (port_id);
7452
7486
}
7453
7487
7454
- setPortMtu (p, p.m_mtu );
7488
+ if (p.m_mtu )
7489
+ {
7490
+ setPortMtu (p, p.m_mtu );
7491
+ }
7455
7492
}
7456
7493
7457
7494
bool PortsOrch::isMACsecPort (sai_object_id_t port_id) const
0 commit comments