@@ -1168,27 +1168,62 @@ bool PortsOrch::getPortAdminStatus(sai_object_id_t id, bool &up)
1168
1168
return true ;
1169
1169
}
1170
1170
1171
- bool PortsOrch::setPortMtu (sai_object_id_t id, sai_uint32_t mtu)
1171
+ bool PortsOrch::getPortMtu (const Port& port, sai_uint32_t &mtu)
1172
+ {
1173
+ SWSS_LOG_ENTER ();
1174
+
1175
+ sai_attribute_t attr;
1176
+ attr.id = SAI_PORT_ATTR_MTU;
1177
+
1178
+ sai_status_t status = sai_port_api->get_port_attribute (port.m_port_id , 1 , &attr);
1179
+
1180
+ if (status != SAI_STATUS_SUCCESS)
1181
+ {
1182
+ return false ;
1183
+ }
1184
+
1185
+ mtu = attr.value .u32 - (uint32_t )(sizeof (struct ether_header ) + FCS_LEN + VLAN_TAG_LEN);
1186
+
1187
+ if (isMACsecPort (port.m_port_id ))
1188
+ {
1189
+ mtu -= MAX_MACSEC_SECTAG_SIZE;
1190
+ }
1191
+
1192
+ return true ;
1193
+ }
1194
+
1195
+ bool PortsOrch::setPortMtu (const Port& port, sai_uint32_t mtu)
1172
1196
{
1173
1197
SWSS_LOG_ENTER ();
1174
1198
1175
1199
sai_attribute_t attr;
1176
1200
attr.id = SAI_PORT_ATTR_MTU;
1177
1201
/* mtu + 14 + 4 + 4 = 22 bytes */
1178
- attr.value .u32 = (uint32_t )(mtu + sizeof (struct ether_header ) + FCS_LEN + VLAN_TAG_LEN);
1202
+ mtu += (uint32_t )(sizeof (struct ether_header ) + FCS_LEN + VLAN_TAG_LEN);
1203
+ attr.value .u32 = mtu;
1179
1204
1180
- sai_status_t status = sai_port_api->set_port_attribute (id, &attr);
1205
+ if (isMACsecPort (port.m_port_id ))
1206
+ {
1207
+ attr.value .u32 += MAX_MACSEC_SECTAG_SIZE;
1208
+ }
1209
+
1210
+ sai_status_t status = sai_port_api->set_port_attribute (port.m_port_id , &attr);
1181
1211
if (status != SAI_STATUS_SUCCESS)
1182
1212
{
1183
1213
SWSS_LOG_ERROR (" Failed to set MTU %u to port pid:%" PRIx64 " , rv:%d" ,
1184
- attr.value .u32 , id , status);
1214
+ attr.value .u32 , port. m_port_id , status);
1185
1215
task_process_status handle_status = handleSaiSetStatus (SAI_API_PORT, status);
1186
1216
if (handle_status != task_success)
1187
1217
{
1188
1218
return parseHandleSaiStatusFailure (handle_status);
1189
1219
}
1190
1220
}
1191
- SWSS_LOG_INFO (" Set MTU %u to port pid:%" PRIx64, attr.value .u32 , id);
1221
+
1222
+ if (m_gearboxEnabled)
1223
+ {
1224
+ setGearboxPortsAttr (port, SAI_PORT_ATTR_MTU, &mtu);
1225
+ }
1226
+ SWSS_LOG_INFO (" Set MTU %u to port pid:%" PRIx64, attr.value .u32 , port.m_port_id );
1192
1227
return true ;
1193
1228
}
1194
1229
@@ -2144,7 +2179,7 @@ void PortsOrch::initPortSupportedFecModes(const std::string& alias, sai_object_i
2144
2179
/*
2145
2180
* If Gearbox is enabled and this is a Gearbox port then set the attributes accordingly.
2146
2181
*/
2147
- bool PortsOrch::setGearboxPortsAttr (Port &port, sai_port_attr_t id, void *value)
2182
+ bool PortsOrch::setGearboxPortsAttr (const Port &port, sai_port_attr_t id, void *value)
2148
2183
{
2149
2184
bool status = false ;
2150
2185
@@ -2162,7 +2197,7 @@ bool PortsOrch::setGearboxPortsAttr(Port &port, sai_port_attr_t id, void *value)
2162
2197
* If Gearbox is enabled and this is a Gearbox port then set the specific lane attribute.
2163
2198
* Note: the appl_db is also updated (Gearbox config_db tables are TBA).
2164
2199
*/
2165
- bool PortsOrch::setGearboxPortAttr (Port &port, dest_port_type_t port_type, sai_port_attr_t id, void *value)
2200
+ bool PortsOrch::setGearboxPortAttr (const Port &port, dest_port_type_t port_type, sai_port_attr_t id, void *value)
2166
2201
{
2167
2202
sai_status_t status = SAI_STATUS_SUCCESS;
2168
2203
sai_object_id_t dest_port_id;
@@ -2216,6 +2251,15 @@ bool PortsOrch::setGearboxPortAttr(Port &port, dest_port_type_t port_type, sai_p
2216
2251
}
2217
2252
SWSS_LOG_NOTICE (" BOX: Set %s lane %s %d" , port.m_alias .c_str (), speed_attr.c_str (), speed);
2218
2253
break ;
2254
+ case SAI_PORT_ATTR_MTU:
2255
+ attr.id = id;
2256
+ attr.value .u32 = *static_cast <sai_uint32_t *>(value);
2257
+ if (LINE_PORT_TYPE == port_type && isMACsecPort (dest_port_id))
2258
+ {
2259
+ attr.value .u32 += MAX_MACSEC_SECTAG_SIZE;
2260
+ }
2261
+ SWSS_LOG_NOTICE (" BOX: Set %s MTU %d" , port.m_alias .c_str (), attr.value .u32 );
2262
+ break ;
2219
2263
default :
2220
2264
return false ;
2221
2265
}
@@ -3565,7 +3609,7 @@ void PortsOrch::doPortTask(Consumer &consumer)
3565
3609
3566
3610
if (mtu != 0 && mtu != p.m_mtu )
3567
3611
{
3568
- if (setPortMtu (p. m_port_id , mtu))
3612
+ if (setPortMtu (p, mtu))
3569
3613
{
3570
3614
p.m_mtu = mtu;
3571
3615
m_portList[alias] = p;
@@ -4632,6 +4676,12 @@ bool PortsOrch::initializePort(Port &port)
4632
4676
return false ;
4633
4677
}
4634
4678
4679
+ /* initialize port mtu */
4680
+ if (!getPortMtu (port, port.m_mtu ))
4681
+ {
4682
+ SWSS_LOG_ERROR (" Failed to get initial port mtu %d" , port.m_mtu );
4683
+ }
4684
+
4635
4685
/*
4636
4686
* always initialize Port SAI_HOSTIF_ATTR_OPER_STATUS based on oper_status value in appDB.
4637
4687
*/
@@ -7008,6 +7058,8 @@ bool PortsOrch::initGearboxPort(Port &port)
7008
7058
SWSS_LOG_NOTICE (" BOX: Connected Gearbox ports; system-side:0x%" PRIx64 " to line-side:0x%" PRIx64, systemPort, linePort);
7009
7059
m_gearboxPortListLaneMap[port.m_port_id ] = make_tuple (systemPort, linePort);
7010
7060
port.m_line_side_id = linePort;
7061
+ saiOidToAlias[systemPort] = port.m_alias ;
7062
+ saiOidToAlias[linePort] = port.m_alias ;
7011
7063
7012
7064
/* Add gearbox system/line port name map to counter table */
7013
7065
FieldValueTuple tuple (port.m_alias + " _system" , sai_serialize_object_id (systemPort));
@@ -7510,6 +7562,39 @@ bool PortsOrch::decrFdbCount(const std::string& alias, int count)
7510
7562
return true ;
7511
7563
}
7512
7564
7565
+ void PortsOrch::setMACsecEnabledState (sai_object_id_t port_id, bool enabled)
7566
+ {
7567
+ SWSS_LOG_ENTER ();
7568
+
7569
+ Port p;
7570
+ if (!getPort (port_id, p))
7571
+ {
7572
+ SWSS_LOG_ERROR (" Failed to get port object for port id 0x%" PRIx64, port_id);
7573
+ return ;
7574
+ }
7575
+
7576
+ if (enabled)
7577
+ {
7578
+ m_macsecEnabledPorts.insert (port_id);
7579
+ }
7580
+ else
7581
+ {
7582
+ m_macsecEnabledPorts.erase (port_id);
7583
+ }
7584
+
7585
+ if (p.m_mtu )
7586
+ {
7587
+ setPortMtu (p, p.m_mtu );
7588
+ }
7589
+ }
7590
+
7591
+ bool PortsOrch::isMACsecPort (sai_object_id_t port_id) const
7592
+ {
7593
+ SWSS_LOG_ENTER ();
7594
+
7595
+ return m_macsecEnabledPorts.find (port_id) != m_macsecEnabledPorts.end ();
7596
+ }
7597
+
7513
7598
/* Refresh the per-port Auto-Negotiation operational states */
7514
7599
void PortsOrch::refreshPortStateAutoNeg (const Port &port)
7515
7600
{
@@ -7624,4 +7709,4 @@ void PortsOrch::doTask(swss::SelectableTimer &timer)
7624
7709
{
7625
7710
m_port_state_poller->stop ();
7626
7711
}
7627
- }
7712
+ }
0 commit comments