@@ -1381,9 +1381,129 @@ ice_devlink_enable_iw_validate(struct devlink *devlink, u32 id,
13811381 return 0 ;
13821382}
13831383
1384+ #define DEVLINK_LOCAL_FWD_DISABLED_STR "disabled"
1385+ #define DEVLINK_LOCAL_FWD_ENABLED_STR "enabled"
1386+ #define DEVLINK_LOCAL_FWD_PRIORITIZED_STR "prioritized"
1387+
1388+ /**
1389+ * ice_devlink_local_fwd_mode_to_str - Get string for local_fwd mode.
1390+ * @mode: local forwarding for mode used in port_info struct.
1391+ *
1392+ * Return: Mode respective string or "Invalid".
1393+ */
1394+ static const char *
1395+ ice_devlink_local_fwd_mode_to_str (enum ice_local_fwd_mode mode )
1396+ {
1397+ switch (mode ) {
1398+ case ICE_LOCAL_FWD_MODE_ENABLED :
1399+ return DEVLINK_LOCAL_FWD_ENABLED_STR ;
1400+ case ICE_LOCAL_FWD_MODE_PRIORITIZED :
1401+ return DEVLINK_LOCAL_FWD_PRIORITIZED_STR ;
1402+ case ICE_LOCAL_FWD_MODE_DISABLED :
1403+ return DEVLINK_LOCAL_FWD_DISABLED_STR ;
1404+ }
1405+
1406+ return "Invalid" ;
1407+ }
1408+
1409+ /**
1410+ * ice_devlink_local_fwd_str_to_mode - Get local_fwd mode from string name.
1411+ * @mode_str: local forwarding mode string.
1412+ *
1413+ * Return: Mode value or negative number if invalid.
1414+ */
1415+ static int ice_devlink_local_fwd_str_to_mode (const char * mode_str )
1416+ {
1417+ if (!strcmp (mode_str , DEVLINK_LOCAL_FWD_ENABLED_STR ))
1418+ return ICE_LOCAL_FWD_MODE_ENABLED ;
1419+ else if (!strcmp (mode_str , DEVLINK_LOCAL_FWD_PRIORITIZED_STR ))
1420+ return ICE_LOCAL_FWD_MODE_PRIORITIZED ;
1421+ else if (!strcmp (mode_str , DEVLINK_LOCAL_FWD_DISABLED_STR ))
1422+ return ICE_LOCAL_FWD_MODE_DISABLED ;
1423+
1424+ return - EINVAL ;
1425+ }
1426+
1427+ /**
1428+ * ice_devlink_local_fwd_get - Get local_fwd parameter.
1429+ * @devlink: Pointer to the devlink instance.
1430+ * @id: The parameter ID to set.
1431+ * @ctx: Context to store the parameter value.
1432+ *
1433+ * Return: Zero.
1434+ */
1435+ static int ice_devlink_local_fwd_get (struct devlink * devlink , u32 id ,
1436+ struct devlink_param_gset_ctx * ctx )
1437+ {
1438+ struct ice_pf * pf = devlink_priv (devlink );
1439+ struct ice_port_info * pi ;
1440+ const char * mode_str ;
1441+
1442+ pi = pf -> hw .port_info ;
1443+ mode_str = ice_devlink_local_fwd_mode_to_str (pi -> local_fwd_mode );
1444+ snprintf (ctx -> val .vstr , sizeof (ctx -> val .vstr ), "%s" , mode_str );
1445+
1446+ return 0 ;
1447+ }
1448+
1449+ /**
1450+ * ice_devlink_local_fwd_set - Set local_fwd parameter.
1451+ * @devlink: Pointer to the devlink instance.
1452+ * @id: The parameter ID to set.
1453+ * @ctx: Context to get the parameter value.
1454+ * @extack: Netlink extended ACK structure.
1455+ *
1456+ * Return: Zero.
1457+ */
1458+ static int ice_devlink_local_fwd_set (struct devlink * devlink , u32 id ,
1459+ struct devlink_param_gset_ctx * ctx ,
1460+ struct netlink_ext_ack * extack )
1461+ {
1462+ int new_local_fwd_mode = ice_devlink_local_fwd_str_to_mode (ctx -> val .vstr );
1463+ struct ice_pf * pf = devlink_priv (devlink );
1464+ struct device * dev = ice_pf_to_dev (pf );
1465+ struct ice_port_info * pi ;
1466+
1467+ pi = pf -> hw .port_info ;
1468+ if (pi -> local_fwd_mode != new_local_fwd_mode ) {
1469+ pi -> local_fwd_mode = new_local_fwd_mode ;
1470+ dev_info (dev , "Setting local_fwd to %s\n" , ctx -> val .vstr );
1471+ ice_schedule_reset (pf , ICE_RESET_CORER );
1472+ }
1473+
1474+ return 0 ;
1475+ }
1476+
1477+ /**
1478+ * ice_devlink_local_fwd_validate - Validate passed local_fwd parameter value.
1479+ * @devlink: Unused pointer to devlink instance.
1480+ * @id: The parameter ID to validate.
1481+ * @val: Value to validate.
1482+ * @extack: Netlink extended ACK structure.
1483+ *
1484+ * Supported values are:
1485+ * "enabled" - local_fwd is enabled, "disabled" - local_fwd is disabled
1486+ * "prioritized" - local_fwd traffic is prioritized in scheduling.
1487+ *
1488+ * Return: Zero when passed parameter value is supported. Negative value on
1489+ * error.
1490+ */
1491+ static int ice_devlink_local_fwd_validate (struct devlink * devlink , u32 id ,
1492+ union devlink_param_value val ,
1493+ struct netlink_ext_ack * extack )
1494+ {
1495+ if (ice_devlink_local_fwd_str_to_mode (val .vstr ) < 0 ) {
1496+ NL_SET_ERR_MSG_MOD (extack , "Error: Requested value is not supported." );
1497+ return - EINVAL ;
1498+ }
1499+
1500+ return 0 ;
1501+ }
1502+
13841503enum ice_param_id {
13851504 ICE_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX ,
13861505 ICE_DEVLINK_PARAM_ID_TX_SCHED_LAYERS ,
1506+ ICE_DEVLINK_PARAM_ID_LOCAL_FWD ,
13871507};
13881508
13891509static const struct devlink_param ice_dvl_rdma_params [] = {
@@ -1405,6 +1525,12 @@ static const struct devlink_param ice_dvl_sched_params[] = {
14051525 ice_devlink_tx_sched_layers_get ,
14061526 ice_devlink_tx_sched_layers_set ,
14071527 ice_devlink_tx_sched_layers_validate ),
1528+ DEVLINK_PARAM_DRIVER (ICE_DEVLINK_PARAM_ID_LOCAL_FWD ,
1529+ "local_forwarding" , DEVLINK_PARAM_TYPE_STRING ,
1530+ BIT (DEVLINK_PARAM_CMODE_RUNTIME ),
1531+ ice_devlink_local_fwd_get ,
1532+ ice_devlink_local_fwd_set ,
1533+ ice_devlink_local_fwd_validate ),
14081534};
14091535
14101536static void ice_devlink_free (void * devlink_ptr )
0 commit comments