Commit 39e6160e authored by Vasundhara Volam's avatar Vasundhara Volam Committed by David S. Miller

devlink: Add devlink_param for port register and unregister

Add functions to register and unregister for the driver supported
configuration parameters table per port.

v7->v8:
- Order the definitions following way as suggested by Jiri.
__devlink_params_register
__devlink_params_unregister
devlink_params_register
devlink_params_unregister
devlink_port_params_register
devlink_port_params_unregister
- Append with Acked-by: Jiri Pirko <jiri@mellanox.com>.

v2->v3:
- Add a helper __devlink_params_register() with common code used by
  both devlink_params_register() and devlink_port_params_register().

Cc: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarVasundhara Volam <vasundhara-v.volam@broadcom.com>
Acked-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent eaf2a47f
...@@ -48,6 +48,7 @@ struct devlink_port_attrs { ...@@ -48,6 +48,7 @@ struct devlink_port_attrs {
struct devlink_port { struct devlink_port {
struct list_head list; struct list_head list;
struct list_head param_list;
struct devlink *devlink; struct devlink *devlink;
unsigned index; unsigned index;
bool registered; bool registered;
...@@ -567,6 +568,12 @@ int devlink_params_register(struct devlink *devlink, ...@@ -567,6 +568,12 @@ int devlink_params_register(struct devlink *devlink,
void devlink_params_unregister(struct devlink *devlink, void devlink_params_unregister(struct devlink *devlink,
const struct devlink_param *params, const struct devlink_param *params,
size_t params_count); size_t params_count);
int devlink_port_params_register(struct devlink_port *devlink_port,
const struct devlink_param *params,
size_t params_count);
void devlink_port_params_unregister(struct devlink_port *devlink_port,
const struct devlink_param *params,
size_t params_count);
int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id, int devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
union devlink_param_value *init_val); union devlink_param_value *init_val);
int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id, int devlink_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
...@@ -791,6 +798,21 @@ devlink_params_unregister(struct devlink *devlink, ...@@ -791,6 +798,21 @@ devlink_params_unregister(struct devlink *devlink,
} }
static inline int
devlink_port_params_register(struct devlink_port *devlink_port,
const struct devlink_param *params,
size_t params_count)
{
return 0;
}
static inline void
devlink_port_params_unregister(struct devlink_port *devlink_port,
const struct devlink_param *params,
size_t params_count)
{
}
static inline int static inline int
devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id, devlink_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
union devlink_param_value *init_val) union devlink_param_value *init_val)
......
...@@ -3147,12 +3147,12 @@ static int devlink_nl_cmd_param_set_doit(struct sk_buff *skb, ...@@ -3147,12 +3147,12 @@ static int devlink_nl_cmd_param_set_doit(struct sk_buff *skb,
} }
static int devlink_param_register_one(struct devlink *devlink, static int devlink_param_register_one(struct devlink *devlink,
struct list_head *param_list,
const struct devlink_param *param) const struct devlink_param *param)
{ {
struct devlink_param_item *param_item; struct devlink_param_item *param_item;
if (devlink_param_find_by_name(&devlink->param_list, if (devlink_param_find_by_name(param_list, param->name))
param->name))
return -EEXIST; return -EEXIST;
if (param->supported_cmodes == BIT(DEVLINK_PARAM_CMODE_DRIVERINIT)) if (param->supported_cmodes == BIT(DEVLINK_PARAM_CMODE_DRIVERINIT))
...@@ -3165,18 +3165,18 @@ static int devlink_param_register_one(struct devlink *devlink, ...@@ -3165,18 +3165,18 @@ static int devlink_param_register_one(struct devlink *devlink,
return -ENOMEM; return -ENOMEM;
param_item->param = param; param_item->param = param;
list_add_tail(&param_item->list, &devlink->param_list); list_add_tail(&param_item->list, param_list);
devlink_param_notify(devlink, param_item, DEVLINK_CMD_PARAM_NEW); devlink_param_notify(devlink, param_item, DEVLINK_CMD_PARAM_NEW);
return 0; return 0;
} }
static void devlink_param_unregister_one(struct devlink *devlink, static void devlink_param_unregister_one(struct devlink *devlink,
struct list_head *param_list,
const struct devlink_param *param) const struct devlink_param *param)
{ {
struct devlink_param_item *param_item; struct devlink_param_item *param_item;
param_item = devlink_param_find_by_name(&devlink->param_list, param_item = devlink_param_find_by_name(param_list, param->name);
param->name);
WARN_ON(!param_item); WARN_ON(!param_item);
devlink_param_notify(devlink, param_item, DEVLINK_CMD_PARAM_DEL); devlink_param_notify(devlink, param_item, DEVLINK_CMD_PARAM_DEL);
list_del(&param_item->list); list_del(&param_item->list);
...@@ -3954,6 +3954,7 @@ int devlink_port_register(struct devlink *devlink, ...@@ -3954,6 +3954,7 @@ int devlink_port_register(struct devlink *devlink,
devlink_port->index = port_index; devlink_port->index = port_index;
devlink_port->registered = true; devlink_port->registered = true;
list_add_tail(&devlink_port->list, &devlink->port_list); list_add_tail(&devlink_port->list, &devlink->port_list);
INIT_LIST_HEAD(&devlink_port->param_list);
mutex_unlock(&devlink->lock); mutex_unlock(&devlink->lock);
devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW); devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW);
return 0; return 0;
...@@ -4471,16 +4472,18 @@ void devlink_resource_occ_get_unregister(struct devlink *devlink, ...@@ -4471,16 +4472,18 @@ void devlink_resource_occ_get_unregister(struct devlink *devlink,
} }
EXPORT_SYMBOL_GPL(devlink_resource_occ_get_unregister); EXPORT_SYMBOL_GPL(devlink_resource_occ_get_unregister);
/** static int devlink_param_verify(const struct devlink_param *param)
* devlink_params_register - register configuration parameters {
* if (!param || !param->name || !param->supported_cmodes)
* @devlink: devlink return -EINVAL;
* @params: configuration parameters array if (param->generic)
* @params_count: number of parameters provided return devlink_param_generic_verify(param);
* else
* Register the configuration parameters supported by the driver. return devlink_param_driver_verify(param);
*/ }
int devlink_params_register(struct devlink *devlink,
static int __devlink_params_register(struct devlink *devlink,
struct list_head *param_list,
const struct devlink_param *params, const struct devlink_param *params,
size_t params_count) size_t params_count)
{ {
...@@ -4490,20 +4493,11 @@ int devlink_params_register(struct devlink *devlink, ...@@ -4490,20 +4493,11 @@ int devlink_params_register(struct devlink *devlink,
mutex_lock(&devlink->lock); mutex_lock(&devlink->lock);
for (i = 0; i < params_count; i++, param++) { for (i = 0; i < params_count; i++, param++) {
if (!param || !param->name || !param->supported_cmodes) { err = devlink_param_verify(param);
err = -EINVAL;
goto rollback;
}
if (param->generic) {
err = devlink_param_generic_verify(param);
if (err) if (err)
goto rollback; goto rollback;
} else {
err = devlink_param_driver_verify(param); err = devlink_param_register_one(devlink, param_list, param);
if (err)
goto rollback;
}
err = devlink_param_register_one(devlink, param);
if (err) if (err)
goto rollback; goto rollback;
} }
...@@ -4515,11 +4509,42 @@ int devlink_params_register(struct devlink *devlink, ...@@ -4515,11 +4509,42 @@ int devlink_params_register(struct devlink *devlink,
if (!i) if (!i)
goto unlock; goto unlock;
for (param--; i > 0; i--, param--) for (param--; i > 0; i--, param--)
devlink_param_unregister_one(devlink, param); devlink_param_unregister_one(devlink, param_list, param);
unlock: unlock:
mutex_unlock(&devlink->lock); mutex_unlock(&devlink->lock);
return err; return err;
} }
static void __devlink_params_unregister(struct devlink *devlink,
struct list_head *param_list,
const struct devlink_param *params,
size_t params_count)
{
const struct devlink_param *param = params;
int i;
mutex_lock(&devlink->lock);
for (i = 0; i < params_count; i++, param++)
devlink_param_unregister_one(devlink, param_list, param);
mutex_unlock(&devlink->lock);
}
/**
* devlink_params_register - register configuration parameters
*
* @devlink: devlink
* @params: configuration parameters array
* @params_count: number of parameters provided
*
* Register the configuration parameters supported by the driver.
*/
int devlink_params_register(struct devlink *devlink,
const struct devlink_param *params,
size_t params_count)
{
return __devlink_params_register(devlink, &devlink->param_list, params,
params_count);
}
EXPORT_SYMBOL_GPL(devlink_params_register); EXPORT_SYMBOL_GPL(devlink_params_register);
/** /**
...@@ -4532,16 +4557,48 @@ void devlink_params_unregister(struct devlink *devlink, ...@@ -4532,16 +4557,48 @@ void devlink_params_unregister(struct devlink *devlink,
const struct devlink_param *params, const struct devlink_param *params,
size_t params_count) size_t params_count)
{ {
const struct devlink_param *param = params; return __devlink_params_unregister(devlink, &devlink->param_list,
int i; params, params_count);
mutex_lock(&devlink->lock);
for (i = 0; i < params_count; i++, param++)
devlink_param_unregister_one(devlink, param);
mutex_unlock(&devlink->lock);
} }
EXPORT_SYMBOL_GPL(devlink_params_unregister); EXPORT_SYMBOL_GPL(devlink_params_unregister);
/**
* devlink_port_params_register - register port configuration parameters
*
* @devlink_port: devlink port
* @params: configuration parameters array
* @params_count: number of parameters provided
*
* Register the configuration parameters supported by the port.
*/
int devlink_port_params_register(struct devlink_port *devlink_port,
const struct devlink_param *params,
size_t params_count)
{
return __devlink_params_register(devlink_port->devlink,
&devlink_port->param_list, params,
params_count);
}
EXPORT_SYMBOL_GPL(devlink_port_params_register);
/**
* devlink_port_params_unregister - unregister port configuration
* parameters
*
* @devlink_port: devlink port
* @params: configuration parameters array
* @params_count: number of parameters provided
*/
void devlink_port_params_unregister(struct devlink_port *devlink_port,
const struct devlink_param *params,
size_t params_count)
{
return __devlink_params_unregister(devlink_port->devlink,
&devlink_port->param_list,
params, params_count);
}
EXPORT_SYMBOL_GPL(devlink_port_params_unregister);
/** /**
* devlink_param_driverinit_value_get - get configuration parameter * devlink_param_driverinit_value_get - get configuration parameter
* value for driver initializing * value for driver initializing
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment