Commit 2a367002 authored by Daniel Zahka's avatar Daniel Zahka Committed by Jakub Kicinski
Browse files

devlink: support default values for param-get and param-set



Support querying and resetting to default param values.

Introduce two new devlink netlink attrs:
DEVLINK_ATTR_PARAM_VALUE_DEFAULT and
DEVLINK_ATTR_PARAM_RESET_DEFAULT. The former is used to contain an
optional parameter value inside of the param_value nested
attribute. The latter is used in param-set requests from userspace to
indicate that the driver should reset the param to its default value.

To implement this, two new functions are added to the devlink driver
api: devlink_param::get_default() and
devlink_param::reset_default(). These callbacks allow drivers to
implement default param actions for runtime and permanent cmodes. For
driverinit params, the core latches the last value set by a driver via
devl_param_driverinit_value_set(), and uses that as the default value
for a param.

Because default parameter values are optional, it would be impossible
to discern whether or not a param of type bool has default value of
false or not provided if the default value is encoded using a netlink
flag type. For this reason, when a DEVLINK_PARAM_TYPE_BOOL has an
associated default value, the default value is encoded using a u8
type.

Signed-off-by: default avatarDaniel Zahka <daniel.zahka@gmail.com>
Link: https://patch.msgid.link/20251119025038.651131-4-daniel.zahka@gmail.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 17a42aa4
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -859,6 +859,14 @@ attribute-sets:
        name: health-reporter-burst-period
        type: u64
        doc: Time (in msec) for recoveries before starting the grace period.

      # TODO: fill in the attributes in between

      -
        name: param-reset-default
        type: flag
        doc: Request restoring parameter to its default value.
        value: 183
  -
    name: dl-dev-stats
    subset-of: devlink
@@ -1793,6 +1801,7 @@ operations:
            - param-type
            # param-value-data is missing here as the type is variable
            - param-value-cmode
            - param-reset-default

    -
      name: region-get
+10 −0
Original line number Diff line number Diff line
@@ -41,6 +41,16 @@ In order for ``driverinit`` parameters to take effect, the driver must
support reloading via the ``devlink-reload`` command. This command will
request a reload of the device driver.

Default parameter values
=========================

Drivers may optionally export default values for parameters of cmode
``runtime`` and ``permanent``. For ``driverinit`` parameters, the last
value set by the driver will be used as the default value. Drivers can
also support resetting params with cmode ``runtime`` and ``permanent``
to their default values. Resetting ``driverinit`` params is supported
by devlink core without additional driver support needed.

.. _devlink_params_generic:

Generic configuration parameters
+42 −0
Original line number Diff line number Diff line
@@ -479,6 +479,10 @@ struct devlink_flash_notify {
 * @set: set parameter value, used for runtime and permanent
 *       configuration modes
 * @validate: validate input value is applicable (within value range, etc.)
 * @get_default: get parameter default value, used for runtime and permanent
 *               configuration modes
 * @reset_default: reset parameter to default value, used for runtime and permanent
 *                 configuration modes
 *
 * This struct should be used by the driver to fill the data for
 * a parameter it registers.
@@ -498,6 +502,12 @@ struct devlink_param {
	int (*validate)(struct devlink *devlink, u32 id,
			union devlink_param_value val,
			struct netlink_ext_ack *extack);
	int (*get_default)(struct devlink *devlink, u32 id,
			   struct devlink_param_gset_ctx *ctx,
			   struct netlink_ext_ack *extack);
	int (*reset_default)(struct devlink *devlink, u32 id,
			     enum devlink_param_cmode cmode,
			     struct netlink_ext_ack *extack);
};

struct devlink_param_item {
@@ -509,6 +519,7 @@ struct devlink_param_item {
							 * until reload.
							 */
	bool driverinit_value_new_valid;
	union devlink_param_value driverinit_default;
};

enum devlink_param_generic_id {
@@ -630,6 +641,37 @@ enum devlink_param_generic_id {
	.validate = _validate,						\
}

#define DEVLINK_PARAM_GENERIC_WITH_DEFAULTS(_id, _cmodes, _get, _set,	      \
					    _validate, _get_default,	      \
					    _reset_default)		      \
{									      \
	.id = DEVLINK_PARAM_GENERIC_ID_##_id,				      \
	.name = DEVLINK_PARAM_GENERIC_##_id##_NAME,			      \
	.type = DEVLINK_PARAM_GENERIC_##_id##_TYPE,			      \
	.generic = true,						      \
	.supported_cmodes = _cmodes,					      \
	.get = _get,							      \
	.set = _set,							      \
	.validate = _validate,						      \
	.get_default = _get_default,					      \
	.reset_default = _reset_default,				      \
}

#define DEVLINK_PARAM_DRIVER_WITH_DEFAULTS(_id, _name, _type, _cmodes,	      \
					   _get, _set, _validate,	      \
					   _get_default, _reset_default)      \
{									      \
	.id = _id,							      \
	.name = _name,							      \
	.type = _type,							      \
	.supported_cmodes = _cmodes,					      \
	.get = _get,							      \
	.set = _set,							      \
	.validate = _validate,						      \
	.get_default = _get_default,					      \
	.reset_default = _reset_default,				      \
}

/* Identifier of board design */
#define DEVLINK_INFO_VERSION_GENERIC_BOARD_ID	"board.id"
/* Revision of board design */
+3 −0
Original line number Diff line number Diff line
@@ -639,6 +639,9 @@ enum devlink_attr {

	DEVLINK_ATTR_HEALTH_REPORTER_BURST_PERIOD,	/* u64 */

	DEVLINK_ATTR_PARAM_VALUE_DEFAULT,	/* dynamic */
	DEVLINK_ATTR_PARAM_RESET_DEFAULT,	/* flag */

	/* Add new attributes above here, update the spec in
	 * Documentation/netlink/specs/devlink.yaml and re-generate
	 * net/devlink/netlink_gen.c.
+3 −2
Original line number Diff line number Diff line
@@ -301,12 +301,13 @@ static const struct nla_policy devlink_param_get_dump_nl_policy[DEVLINK_ATTR_DEV
};

/* DEVLINK_CMD_PARAM_SET - do */
static const struct nla_policy devlink_param_set_nl_policy[DEVLINK_ATTR_PARAM_VALUE_CMODE + 1] = {
static const struct nla_policy devlink_param_set_nl_policy[DEVLINK_ATTR_PARAM_RESET_DEFAULT + 1] = {
	[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
	[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
	[DEVLINK_ATTR_PARAM_NAME] = { .type = NLA_NUL_STRING, },
	[DEVLINK_ATTR_PARAM_TYPE] = NLA_POLICY_VALIDATE_FN(NLA_U8, &devlink_attr_param_type_validate),
	[DEVLINK_ATTR_PARAM_VALUE_CMODE] = NLA_POLICY_MAX(NLA_U8, 2),
	[DEVLINK_ATTR_PARAM_RESET_DEFAULT] = { .type = NLA_FLAG, },
};

/* DEVLINK_CMD_REGION_GET - do */
@@ -919,7 +920,7 @@ const struct genl_split_ops devlink_nl_ops[74] = {
		.doit		= devlink_nl_param_set_doit,
		.post_doit	= devlink_nl_post_doit,
		.policy		= devlink_param_set_nl_policy,
		.maxattr	= DEVLINK_ATTR_PARAM_VALUE_CMODE,
		.maxattr	= DEVLINK_ATTR_PARAM_RESET_DEFAULT,
		.flags		= GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
	},
	{
Loading