mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-27 03:10:12 +00:00
devlink: Add support for get/set driverinit value
"driverinit" configuration mode value is held by devlink to enable the driver query the value after reload. Two additional functions added to help the driver get/set the value from/to devlink: devlink_param_driverinit_value_set() and devlink_param_driverinit_value_get(). Signed-off-by: Moshe Shemesh <moshe@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
e3b7ca18ad
commit
ec01aeb180
2 changed files with 95 additions and 0 deletions
|
@ -503,6 +503,10 @@ int devlink_params_register(struct devlink *devlink,
|
|||
void devlink_params_unregister(struct devlink *devlink,
|
||||
const struct devlink_param *params,
|
||||
size_t params_count);
|
||||
int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
|
||||
union devlink_param_value *init_val);
|
||||
int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
|
||||
union devlink_param_value init_val);
|
||||
|
||||
#else
|
||||
|
||||
|
@ -711,6 +715,20 @@ devlink_params_unregister(struct devlink *devlink,
|
|||
|
||||
}
|
||||
|
||||
static inline int
|
||||
devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
|
||||
union devlink_param_value *init_val)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static inline int
|
||||
devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
|
||||
union devlink_param_value init_val)
|
||||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _NET_DEVLINK_H_ */
|
||||
|
|
|
@ -2645,6 +2645,17 @@ devlink_param_find_by_name(struct list_head *param_list,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static struct devlink_param_item *
|
||||
devlink_param_find_by_id(struct list_head *param_list, u32 param_id)
|
||||
{
|
||||
struct devlink_param_item *param_item;
|
||||
|
||||
list_for_each_entry(param_item, param_list, list)
|
||||
if (param_item->param->id == param_id)
|
||||
return param_item;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool
|
||||
devlink_param_cmode_is_supported(const struct devlink_param *param,
|
||||
enum devlink_param_cmode cmode)
|
||||
|
@ -3966,6 +3977,72 @@ void devlink_params_unregister(struct devlink *devlink,
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(devlink_params_unregister);
|
||||
|
||||
/**
|
||||
* devlink_param_driverinit_value_get - get configuration parameter
|
||||
* value for driver initializing
|
||||
*
|
||||
* @devlink: devlink
|
||||
* @param_id: parameter ID
|
||||
* @init_val: value of parameter in driverinit configuration mode
|
||||
*
|
||||
* This function should be used by the driver to get driverinit
|
||||
* configuration for initialization after reload command.
|
||||
*/
|
||||
int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
|
||||
union devlink_param_value *init_val)
|
||||
{
|
||||
struct devlink_param_item *param_item;
|
||||
|
||||
if (!devlink->ops || !devlink->ops->reload)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
param_item = devlink_param_find_by_id(&devlink->param_list, param_id);
|
||||
if (!param_item)
|
||||
return -EINVAL;
|
||||
|
||||
if (!param_item->driverinit_value_valid ||
|
||||
!devlink_param_cmode_is_supported(param_item->param,
|
||||
DEVLINK_PARAM_CMODE_DRIVERINIT))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
*init_val = param_item->driverinit_value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(devlink_param_driverinit_value_get);
|
||||
|
||||
/**
|
||||
* devlink_param_driverinit_value_set - set value of configuration
|
||||
* parameter for driverinit
|
||||
* configuration mode
|
||||
*
|
||||
* @devlink: devlink
|
||||
* @param_id: parameter ID
|
||||
* @init_val: value of parameter to set for driverinit configuration mode
|
||||
*
|
||||
* This function should be used by the driver to set driverinit
|
||||
* configuration mode default value.
|
||||
*/
|
||||
int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
|
||||
union devlink_param_value init_val)
|
||||
{
|
||||
struct devlink_param_item *param_item;
|
||||
|
||||
param_item = devlink_param_find_by_id(&devlink->param_list, param_id);
|
||||
if (!param_item)
|
||||
return -EINVAL;
|
||||
|
||||
if (!devlink_param_cmode_is_supported(param_item->param,
|
||||
DEVLINK_PARAM_CMODE_DRIVERINIT))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
param_item->driverinit_value = init_val;
|
||||
param_item->driverinit_value_valid = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(devlink_param_driverinit_value_set);
|
||||
|
||||
static int __init devlink_module_init(void)
|
||||
{
|
||||
return genl_register_family(&devlink_nl_family);
|
||||
|
|
Loading…
Reference in a new issue