1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2016 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com>
7 #include "devl_internal.h"
9 static const struct devlink_param devlink_param_generic[] = {
11 .id = DEVLINK_PARAM_GENERIC_ID_INT_ERR_RESET,
12 .name = DEVLINK_PARAM_GENERIC_INT_ERR_RESET_NAME,
13 .type = DEVLINK_PARAM_GENERIC_INT_ERR_RESET_TYPE,
16 .id = DEVLINK_PARAM_GENERIC_ID_MAX_MACS,
17 .name = DEVLINK_PARAM_GENERIC_MAX_MACS_NAME,
18 .type = DEVLINK_PARAM_GENERIC_MAX_MACS_TYPE,
21 .id = DEVLINK_PARAM_GENERIC_ID_ENABLE_SRIOV,
22 .name = DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_NAME,
23 .type = DEVLINK_PARAM_GENERIC_ENABLE_SRIOV_TYPE,
26 .id = DEVLINK_PARAM_GENERIC_ID_REGION_SNAPSHOT,
27 .name = DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_NAME,
28 .type = DEVLINK_PARAM_GENERIC_REGION_SNAPSHOT_TYPE,
31 .id = DEVLINK_PARAM_GENERIC_ID_IGNORE_ARI,
32 .name = DEVLINK_PARAM_GENERIC_IGNORE_ARI_NAME,
33 .type = DEVLINK_PARAM_GENERIC_IGNORE_ARI_TYPE,
36 .id = DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MAX,
37 .name = DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_NAME,
38 .type = DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MAX_TYPE,
41 .id = DEVLINK_PARAM_GENERIC_ID_MSIX_VEC_PER_PF_MIN,
42 .name = DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_NAME,
43 .type = DEVLINK_PARAM_GENERIC_MSIX_VEC_PER_PF_MIN_TYPE,
46 .id = DEVLINK_PARAM_GENERIC_ID_FW_LOAD_POLICY,
47 .name = DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_NAME,
48 .type = DEVLINK_PARAM_GENERIC_FW_LOAD_POLICY_TYPE,
51 .id = DEVLINK_PARAM_GENERIC_ID_RESET_DEV_ON_DRV_PROBE,
52 .name = DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_NAME,
53 .type = DEVLINK_PARAM_GENERIC_RESET_DEV_ON_DRV_PROBE_TYPE,
56 .id = DEVLINK_PARAM_GENERIC_ID_ENABLE_ROCE,
57 .name = DEVLINK_PARAM_GENERIC_ENABLE_ROCE_NAME,
58 .type = DEVLINK_PARAM_GENERIC_ENABLE_ROCE_TYPE,
61 .id = DEVLINK_PARAM_GENERIC_ID_ENABLE_REMOTE_DEV_RESET,
62 .name = DEVLINK_PARAM_GENERIC_ENABLE_REMOTE_DEV_RESET_NAME,
63 .type = DEVLINK_PARAM_GENERIC_ENABLE_REMOTE_DEV_RESET_TYPE,
66 .id = DEVLINK_PARAM_GENERIC_ID_ENABLE_ETH,
67 .name = DEVLINK_PARAM_GENERIC_ENABLE_ETH_NAME,
68 .type = DEVLINK_PARAM_GENERIC_ENABLE_ETH_TYPE,
71 .id = DEVLINK_PARAM_GENERIC_ID_ENABLE_RDMA,
72 .name = DEVLINK_PARAM_GENERIC_ENABLE_RDMA_NAME,
73 .type = DEVLINK_PARAM_GENERIC_ENABLE_RDMA_TYPE,
76 .id = DEVLINK_PARAM_GENERIC_ID_ENABLE_VNET,
77 .name = DEVLINK_PARAM_GENERIC_ENABLE_VNET_NAME,
78 .type = DEVLINK_PARAM_GENERIC_ENABLE_VNET_TYPE,
81 .id = DEVLINK_PARAM_GENERIC_ID_ENABLE_IWARP,
82 .name = DEVLINK_PARAM_GENERIC_ENABLE_IWARP_NAME,
83 .type = DEVLINK_PARAM_GENERIC_ENABLE_IWARP_TYPE,
86 .id = DEVLINK_PARAM_GENERIC_ID_IO_EQ_SIZE,
87 .name = DEVLINK_PARAM_GENERIC_IO_EQ_SIZE_NAME,
88 .type = DEVLINK_PARAM_GENERIC_IO_EQ_SIZE_TYPE,
91 .id = DEVLINK_PARAM_GENERIC_ID_EVENT_EQ_SIZE,
92 .name = DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_NAME,
93 .type = DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_TYPE,
97 static int devlink_param_generic_verify(const struct devlink_param *param)
99 /* verify it match generic parameter by id and name */
100 if (param->id > DEVLINK_PARAM_GENERIC_ID_MAX)
102 if (strcmp(param->name, devlink_param_generic[param->id].name))
105 WARN_ON(param->type != devlink_param_generic[param->id].type);
110 static int devlink_param_driver_verify(const struct devlink_param *param)
114 if (param->id <= DEVLINK_PARAM_GENERIC_ID_MAX)
116 /* verify no such name in generic params */
117 for (i = 0; i <= DEVLINK_PARAM_GENERIC_ID_MAX; i++)
118 if (!strcmp(param->name, devlink_param_generic[i].name))
124 static struct devlink_param_item *
125 devlink_param_find_by_name(struct xarray *params, const char *param_name)
127 struct devlink_param_item *param_item;
128 unsigned long param_id;
130 xa_for_each(params, param_id, param_item) {
131 if (!strcmp(param_item->param->name, param_name))
137 static struct devlink_param_item *
138 devlink_param_find_by_id(struct xarray *params, u32 param_id)
140 return xa_load(params, param_id);
144 devlink_param_cmode_is_supported(const struct devlink_param *param,
145 enum devlink_param_cmode cmode)
147 return test_bit(cmode, ¶m->supported_cmodes);
150 static int devlink_param_get(struct devlink *devlink,
151 const struct devlink_param *param,
152 struct devlink_param_gset_ctx *ctx)
156 return param->get(devlink, param->id, ctx);
159 static int devlink_param_set(struct devlink *devlink,
160 const struct devlink_param *param,
161 struct devlink_param_gset_ctx *ctx)
165 return param->set(devlink, param->id, ctx);
169 devlink_param_type_to_nla_type(enum devlink_param_type param_type)
171 switch (param_type) {
172 case DEVLINK_PARAM_TYPE_U8:
174 case DEVLINK_PARAM_TYPE_U16:
176 case DEVLINK_PARAM_TYPE_U32:
178 case DEVLINK_PARAM_TYPE_STRING:
180 case DEVLINK_PARAM_TYPE_BOOL:
188 devlink_nl_param_value_fill_one(struct sk_buff *msg,
189 enum devlink_param_type type,
190 enum devlink_param_cmode cmode,
191 union devlink_param_value val)
193 struct nlattr *param_value_attr;
195 param_value_attr = nla_nest_start_noflag(msg,
196 DEVLINK_ATTR_PARAM_VALUE);
197 if (!param_value_attr)
198 goto nla_put_failure;
200 if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_VALUE_CMODE, cmode))
201 goto value_nest_cancel;
204 case DEVLINK_PARAM_TYPE_U8:
205 if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, val.vu8))
206 goto value_nest_cancel;
208 case DEVLINK_PARAM_TYPE_U16:
209 if (nla_put_u16(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, val.vu16))
210 goto value_nest_cancel;
212 case DEVLINK_PARAM_TYPE_U32:
213 if (nla_put_u32(msg, DEVLINK_ATTR_PARAM_VALUE_DATA, val.vu32))
214 goto value_nest_cancel;
216 case DEVLINK_PARAM_TYPE_STRING:
217 if (nla_put_string(msg, DEVLINK_ATTR_PARAM_VALUE_DATA,
219 goto value_nest_cancel;
221 case DEVLINK_PARAM_TYPE_BOOL:
223 nla_put_flag(msg, DEVLINK_ATTR_PARAM_VALUE_DATA))
224 goto value_nest_cancel;
228 nla_nest_end(msg, param_value_attr);
232 nla_nest_cancel(msg, param_value_attr);
237 static int devlink_nl_param_fill(struct sk_buff *msg, struct devlink *devlink,
238 unsigned int port_index,
239 struct devlink_param_item *param_item,
240 enum devlink_command cmd,
241 u32 portid, u32 seq, int flags)
243 union devlink_param_value param_value[DEVLINK_PARAM_CMODE_MAX + 1];
244 bool param_value_set[DEVLINK_PARAM_CMODE_MAX + 1] = {};
245 const struct devlink_param *param = param_item->param;
246 struct devlink_param_gset_ctx ctx;
247 struct nlattr *param_values_list;
248 struct nlattr *param_attr;
254 /* Get value from driver part to driverinit configuration mode */
255 for (i = 0; i <= DEVLINK_PARAM_CMODE_MAX; i++) {
256 if (!devlink_param_cmode_is_supported(param, i))
258 if (i == DEVLINK_PARAM_CMODE_DRIVERINIT) {
259 if (param_item->driverinit_value_new_valid)
260 param_value[i] = param_item->driverinit_value_new;
261 else if (param_item->driverinit_value_valid)
262 param_value[i] = param_item->driverinit_value;
267 err = devlink_param_get(devlink, param, &ctx);
270 param_value[i] = ctx.val;
272 param_value_set[i] = true;
275 hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd);
279 if (devlink_nl_put_handle(msg, devlink))
282 if (cmd == DEVLINK_CMD_PORT_PARAM_GET ||
283 cmd == DEVLINK_CMD_PORT_PARAM_NEW ||
284 cmd == DEVLINK_CMD_PORT_PARAM_DEL)
285 if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX, port_index))
288 param_attr = nla_nest_start_noflag(msg, DEVLINK_ATTR_PARAM);
291 if (nla_put_string(msg, DEVLINK_ATTR_PARAM_NAME, param->name))
292 goto param_nest_cancel;
293 if (param->generic && nla_put_flag(msg, DEVLINK_ATTR_PARAM_GENERIC))
294 goto param_nest_cancel;
296 nla_type = devlink_param_type_to_nla_type(param->type);
298 goto param_nest_cancel;
299 if (nla_put_u8(msg, DEVLINK_ATTR_PARAM_TYPE, nla_type))
300 goto param_nest_cancel;
302 param_values_list = nla_nest_start_noflag(msg,
303 DEVLINK_ATTR_PARAM_VALUES_LIST);
304 if (!param_values_list)
305 goto param_nest_cancel;
307 for (i = 0; i <= DEVLINK_PARAM_CMODE_MAX; i++) {
308 if (!param_value_set[i])
310 err = devlink_nl_param_value_fill_one(msg, param->type,
313 goto values_list_nest_cancel;
316 nla_nest_end(msg, param_values_list);
317 nla_nest_end(msg, param_attr);
318 genlmsg_end(msg, hdr);
321 values_list_nest_cancel:
322 nla_nest_end(msg, param_values_list);
324 nla_nest_cancel(msg, param_attr);
326 genlmsg_cancel(msg, hdr);
330 static void devlink_param_notify(struct devlink *devlink,
331 unsigned int port_index,
332 struct devlink_param_item *param_item,
333 enum devlink_command cmd)
338 WARN_ON(cmd != DEVLINK_CMD_PARAM_NEW && cmd != DEVLINK_CMD_PARAM_DEL &&
339 cmd != DEVLINK_CMD_PORT_PARAM_NEW &&
340 cmd != DEVLINK_CMD_PORT_PARAM_DEL);
342 /* devlink_notify_register() / devlink_notify_unregister()
343 * will replay the notifications if the params are added/removed
344 * outside of the lifetime of the instance.
346 if (!devl_is_registered(devlink))
349 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
352 err = devlink_nl_param_fill(msg, devlink, port_index, param_item, cmd,
359 genlmsg_multicast_netns(&devlink_nl_family, devlink_net(devlink),
360 msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL);
363 static void devlink_params_notify(struct devlink *devlink,
364 enum devlink_command cmd)
366 struct devlink_param_item *param_item;
367 unsigned long param_id;
369 xa_for_each(&devlink->params, param_id, param_item)
370 devlink_param_notify(devlink, 0, param_item, cmd);
373 void devlink_params_notify_register(struct devlink *devlink)
375 devlink_params_notify(devlink, DEVLINK_CMD_PARAM_NEW);
378 void devlink_params_notify_unregister(struct devlink *devlink)
380 devlink_params_notify(devlink, DEVLINK_CMD_PARAM_DEL);
383 static int devlink_nl_param_get_dump_one(struct sk_buff *msg,
384 struct devlink *devlink,
385 struct netlink_callback *cb,
388 struct devlink_nl_dump_state *state = devlink_dump_state(cb);
389 struct devlink_param_item *param_item;
390 unsigned long param_id;
393 xa_for_each_start(&devlink->params, param_id, param_item, state->idx) {
394 err = devlink_nl_param_fill(msg, devlink, 0, param_item,
395 DEVLINK_CMD_PARAM_GET,
396 NETLINK_CB(cb->skb).portid,
397 cb->nlh->nlmsg_seq, flags);
398 if (err == -EOPNOTSUPP) {
401 state->idx = param_id;
409 int devlink_nl_param_get_dumpit(struct sk_buff *skb,
410 struct netlink_callback *cb)
412 return devlink_nl_dumpit(skb, cb, devlink_nl_param_get_dump_one);
416 devlink_param_type_get_from_info(struct genl_info *info,
417 enum devlink_param_type *param_type)
419 if (GENL_REQ_ATTR_CHECK(info, DEVLINK_ATTR_PARAM_TYPE))
422 switch (nla_get_u8(info->attrs[DEVLINK_ATTR_PARAM_TYPE])) {
424 *param_type = DEVLINK_PARAM_TYPE_U8;
427 *param_type = DEVLINK_PARAM_TYPE_U16;
430 *param_type = DEVLINK_PARAM_TYPE_U32;
433 *param_type = DEVLINK_PARAM_TYPE_STRING;
436 *param_type = DEVLINK_PARAM_TYPE_BOOL;
446 devlink_param_value_get_from_info(const struct devlink_param *param,
447 struct genl_info *info,
448 union devlink_param_value *value)
450 struct nlattr *param_data;
453 param_data = info->attrs[DEVLINK_ATTR_PARAM_VALUE_DATA];
455 if (param->type != DEVLINK_PARAM_TYPE_BOOL && !param_data)
458 switch (param->type) {
459 case DEVLINK_PARAM_TYPE_U8:
460 if (nla_len(param_data) != sizeof(u8))
462 value->vu8 = nla_get_u8(param_data);
464 case DEVLINK_PARAM_TYPE_U16:
465 if (nla_len(param_data) != sizeof(u16))
467 value->vu16 = nla_get_u16(param_data);
469 case DEVLINK_PARAM_TYPE_U32:
470 if (nla_len(param_data) != sizeof(u32))
472 value->vu32 = nla_get_u32(param_data);
474 case DEVLINK_PARAM_TYPE_STRING:
475 len = strnlen(nla_data(param_data), nla_len(param_data));
476 if (len == nla_len(param_data) ||
477 len >= __DEVLINK_PARAM_MAX_STRING_VALUE)
479 strcpy(value->vstr, nla_data(param_data));
481 case DEVLINK_PARAM_TYPE_BOOL:
482 if (param_data && nla_len(param_data))
484 value->vbool = nla_get_flag(param_data);
490 static struct devlink_param_item *
491 devlink_param_get_from_info(struct xarray *params, struct genl_info *info)
495 if (GENL_REQ_ATTR_CHECK(info, DEVLINK_ATTR_PARAM_NAME))
498 param_name = nla_data(info->attrs[DEVLINK_ATTR_PARAM_NAME]);
499 return devlink_param_find_by_name(params, param_name);
502 int devlink_nl_param_get_doit(struct sk_buff *skb,
503 struct genl_info *info)
505 struct devlink *devlink = info->user_ptr[0];
506 struct devlink_param_item *param_item;
510 param_item = devlink_param_get_from_info(&devlink->params, info);
514 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
518 err = devlink_nl_param_fill(msg, devlink, 0, param_item,
519 DEVLINK_CMD_PARAM_GET,
520 info->snd_portid, info->snd_seq, 0);
526 return genlmsg_reply(msg, info);
529 static int __devlink_nl_cmd_param_set_doit(struct devlink *devlink,
530 unsigned int port_index,
531 struct xarray *params,
532 struct genl_info *info,
533 enum devlink_command cmd)
535 enum devlink_param_type param_type;
536 struct devlink_param_gset_ctx ctx;
537 enum devlink_param_cmode cmode;
538 struct devlink_param_item *param_item;
539 const struct devlink_param *param;
540 union devlink_param_value value;
543 param_item = devlink_param_get_from_info(params, info);
546 param = param_item->param;
547 err = devlink_param_type_get_from_info(info, ¶m_type);
550 if (param_type != param->type)
552 err = devlink_param_value_get_from_info(param, info, &value);
555 if (param->validate) {
556 err = param->validate(devlink, param->id, value, info->extack);
561 if (GENL_REQ_ATTR_CHECK(info, DEVLINK_ATTR_PARAM_VALUE_CMODE))
563 cmode = nla_get_u8(info->attrs[DEVLINK_ATTR_PARAM_VALUE_CMODE]);
564 if (!devlink_param_cmode_is_supported(param, cmode))
567 if (cmode == DEVLINK_PARAM_CMODE_DRIVERINIT) {
568 param_item->driverinit_value_new = value;
569 param_item->driverinit_value_new_valid = true;
575 err = devlink_param_set(devlink, param, &ctx);
580 devlink_param_notify(devlink, port_index, param_item, cmd);
584 int devlink_nl_cmd_param_set_doit(struct sk_buff *skb, struct genl_info *info)
586 struct devlink *devlink = info->user_ptr[0];
588 return __devlink_nl_cmd_param_set_doit(devlink, 0, &devlink->params,
589 info, DEVLINK_CMD_PARAM_NEW);
592 int devlink_nl_cmd_port_param_get_dumpit(struct sk_buff *msg,
593 struct netlink_callback *cb)
595 NL_SET_ERR_MSG(cb->extack, "Port params are not supported");
599 int devlink_nl_cmd_port_param_get_doit(struct sk_buff *skb,
600 struct genl_info *info)
602 NL_SET_ERR_MSG(info->extack, "Port params are not supported");
606 int devlink_nl_cmd_port_param_set_doit(struct sk_buff *skb,
607 struct genl_info *info)
609 NL_SET_ERR_MSG(info->extack, "Port params are not supported");
613 static int devlink_param_verify(const struct devlink_param *param)
615 if (!param || !param->name || !param->supported_cmodes)
618 return devlink_param_generic_verify(param);
620 return devlink_param_driver_verify(param);
623 static int devlink_param_register(struct devlink *devlink,
624 const struct devlink_param *param)
626 struct devlink_param_item *param_item;
629 WARN_ON(devlink_param_verify(param));
630 WARN_ON(devlink_param_find_by_name(&devlink->params, param->name));
632 if (param->supported_cmodes == BIT(DEVLINK_PARAM_CMODE_DRIVERINIT))
633 WARN_ON(param->get || param->set);
635 WARN_ON(!param->get || !param->set);
637 param_item = kzalloc(sizeof(*param_item), GFP_KERNEL);
641 param_item->param = param;
643 err = xa_insert(&devlink->params, param->id, param_item, GFP_KERNEL);
647 devlink_param_notify(devlink, 0, param_item, DEVLINK_CMD_PARAM_NEW);
655 static void devlink_param_unregister(struct devlink *devlink,
656 const struct devlink_param *param)
658 struct devlink_param_item *param_item;
660 param_item = devlink_param_find_by_id(&devlink->params, param->id);
661 if (WARN_ON(!param_item))
663 devlink_param_notify(devlink, 0, param_item, DEVLINK_CMD_PARAM_DEL);
664 xa_erase(&devlink->params, param->id);
669 * devl_params_register - register configuration parameters
672 * @params: configuration parameters array
673 * @params_count: number of parameters provided
675 * Register the configuration parameters supported by the driver.
677 int devl_params_register(struct devlink *devlink,
678 const struct devlink_param *params,
681 const struct devlink_param *param = params;
684 lockdep_assert_held(&devlink->lock);
686 for (i = 0; i < params_count; i++, param++) {
687 err = devlink_param_register(devlink, param);
697 for (param--; i > 0; i--, param--)
698 devlink_param_unregister(devlink, param);
701 EXPORT_SYMBOL_GPL(devl_params_register);
703 int devlink_params_register(struct devlink *devlink,
704 const struct devlink_param *params,
710 err = devl_params_register(devlink, params, params_count);
711 devl_unlock(devlink);
714 EXPORT_SYMBOL_GPL(devlink_params_register);
717 * devl_params_unregister - unregister configuration parameters
719 * @params: configuration parameters to unregister
720 * @params_count: number of parameters provided
722 void devl_params_unregister(struct devlink *devlink,
723 const struct devlink_param *params,
726 const struct devlink_param *param = params;
729 lockdep_assert_held(&devlink->lock);
731 for (i = 0; i < params_count; i++, param++)
732 devlink_param_unregister(devlink, param);
734 EXPORT_SYMBOL_GPL(devl_params_unregister);
736 void devlink_params_unregister(struct devlink *devlink,
737 const struct devlink_param *params,
741 devl_params_unregister(devlink, params, params_count);
742 devl_unlock(devlink);
744 EXPORT_SYMBOL_GPL(devlink_params_unregister);
747 * devl_param_driverinit_value_get - get configuration parameter
748 * value for driver initializing
751 * @param_id: parameter ID
752 * @val: pointer to store the value of parameter in driverinit
755 * This function should be used by the driver to get driverinit
756 * configuration for initialization after reload command.
758 * Note that lockless call of this function relies on the
759 * driver to maintain following basic sane behavior:
760 * 1) Driver ensures a call to this function cannot race with
761 * registering/unregistering the parameter with the same parameter ID.
762 * 2) Driver ensures a call to this function cannot race with
763 * devl_param_driverinit_value_set() call with the same parameter ID.
764 * 3) Driver ensures a call to this function cannot race with
766 * If the driver is not able to comply, it has to take the devlink->lock
767 * while calling this.
769 int devl_param_driverinit_value_get(struct devlink *devlink, u32 param_id,
770 union devlink_param_value *val)
772 struct devlink_param_item *param_item;
774 if (WARN_ON(!devlink_reload_supported(devlink->ops)))
777 param_item = devlink_param_find_by_id(&devlink->params, param_id);
781 if (!param_item->driverinit_value_valid)
784 if (WARN_ON(!devlink_param_cmode_is_supported(param_item->param,
785 DEVLINK_PARAM_CMODE_DRIVERINIT)))
788 *val = param_item->driverinit_value;
792 EXPORT_SYMBOL_GPL(devl_param_driverinit_value_get);
795 * devl_param_driverinit_value_set - set value of configuration
796 * parameter for driverinit
800 * @param_id: parameter ID
801 * @init_val: value of parameter to set for driverinit configuration mode
803 * This function should be used by the driver to set driverinit
804 * configuration mode default value.
806 void devl_param_driverinit_value_set(struct devlink *devlink, u32 param_id,
807 union devlink_param_value init_val)
809 struct devlink_param_item *param_item;
811 devl_assert_locked(devlink);
813 param_item = devlink_param_find_by_id(&devlink->params, param_id);
814 if (WARN_ON(!param_item))
817 if (WARN_ON(!devlink_param_cmode_is_supported(param_item->param,
818 DEVLINK_PARAM_CMODE_DRIVERINIT)))
821 param_item->driverinit_value = init_val;
822 param_item->driverinit_value_valid = true;
824 devlink_param_notify(devlink, 0, param_item, DEVLINK_CMD_PARAM_NEW);
826 EXPORT_SYMBOL_GPL(devl_param_driverinit_value_set);
828 void devlink_params_driverinit_load_new(struct devlink *devlink)
830 struct devlink_param_item *param_item;
831 unsigned long param_id;
833 xa_for_each(&devlink->params, param_id, param_item) {
834 if (!devlink_param_cmode_is_supported(param_item->param,
835 DEVLINK_PARAM_CMODE_DRIVERINIT) ||
836 !param_item->driverinit_value_new_valid)
838 param_item->driverinit_value = param_item->driverinit_value_new;
839 param_item->driverinit_value_valid = true;
840 param_item->driverinit_value_new_valid = false;
845 * devl_param_value_changed - notify devlink on a parameter's value
846 * change. Should be called by the driver
847 * right after the change.
850 * @param_id: parameter ID
852 * This function should be used by the driver to notify devlink on value
853 * change, excluding driverinit configuration mode.
854 * For driverinit configuration mode driver should use the function
856 void devl_param_value_changed(struct devlink *devlink, u32 param_id)
858 struct devlink_param_item *param_item;
860 param_item = devlink_param_find_by_id(&devlink->params, param_id);
861 WARN_ON(!param_item);
863 devlink_param_notify(devlink, 0, param_item, DEVLINK_CMD_PARAM_NEW);
865 EXPORT_SYMBOL_GPL(devl_param_value_changed);