xref: /linux/net/devlink/netlink.c (revision f26b118031205135c23b43a311712fe8f34febf9)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2016 Mellanox Technologies. All rights reserved.
4  * Copyright (c) 2016 Jiri Pirko <jiri@mellanox.com>
5  */
6 
7 #include <net/genetlink.h>
8 #include <net/sock.h>
9 
10 #include "devl_internal.h"
11 
12 static const struct genl_multicast_group devlink_nl_mcgrps[] = {
13 	[DEVLINK_MCGRP_CONFIG] = { .name = DEVLINK_GENL_MCGRP_CONFIG_NAME },
14 };
15 
16 static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
17 	[DEVLINK_ATTR_UNSPEC] = { .strict_start_type =
18 		DEVLINK_ATTR_TRAP_POLICER_ID },
19 	[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING },
20 	[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING },
21 	[DEVLINK_ATTR_PORT_INDEX] = { .type = NLA_U32 },
22 	[DEVLINK_ATTR_PORT_TYPE] = NLA_POLICY_RANGE(NLA_U16, DEVLINK_PORT_TYPE_AUTO,
23 						    DEVLINK_PORT_TYPE_IB),
24 	[DEVLINK_ATTR_PORT_SPLIT_COUNT] = { .type = NLA_U32 },
25 	[DEVLINK_ATTR_SB_INDEX] = { .type = NLA_U32 },
26 	[DEVLINK_ATTR_SB_POOL_INDEX] = { .type = NLA_U16 },
27 	[DEVLINK_ATTR_SB_POOL_TYPE] = { .type = NLA_U8 },
28 	[DEVLINK_ATTR_SB_POOL_SIZE] = { .type = NLA_U32 },
29 	[DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE] = { .type = NLA_U8 },
30 	[DEVLINK_ATTR_SB_THRESHOLD] = { .type = NLA_U32 },
31 	[DEVLINK_ATTR_SB_TC_INDEX] = { .type = NLA_U16 },
32 	[DEVLINK_ATTR_ESWITCH_MODE] = NLA_POLICY_RANGE(NLA_U16, DEVLINK_ESWITCH_MODE_LEGACY,
33 						       DEVLINK_ESWITCH_MODE_SWITCHDEV),
34 	[DEVLINK_ATTR_ESWITCH_INLINE_MODE] = { .type = NLA_U8 },
35 	[DEVLINK_ATTR_ESWITCH_ENCAP_MODE] = { .type = NLA_U8 },
36 	[DEVLINK_ATTR_DPIPE_TABLE_NAME] = { .type = NLA_NUL_STRING },
37 	[DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED] = { .type = NLA_U8 },
38 	[DEVLINK_ATTR_RESOURCE_ID] = { .type = NLA_U64},
39 	[DEVLINK_ATTR_RESOURCE_SIZE] = { .type = NLA_U64},
40 	[DEVLINK_ATTR_PARAM_NAME] = { .type = NLA_NUL_STRING },
41 	[DEVLINK_ATTR_PARAM_TYPE] = { .type = NLA_U8 },
42 	[DEVLINK_ATTR_PARAM_VALUE_CMODE] = { .type = NLA_U8 },
43 	[DEVLINK_ATTR_REGION_NAME] = { .type = NLA_NUL_STRING },
44 	[DEVLINK_ATTR_REGION_SNAPSHOT_ID] = { .type = NLA_U32 },
45 	[DEVLINK_ATTR_REGION_CHUNK_ADDR] = { .type = NLA_U64 },
46 	[DEVLINK_ATTR_REGION_CHUNK_LEN] = { .type = NLA_U64 },
47 	[DEVLINK_ATTR_HEALTH_REPORTER_NAME] = { .type = NLA_NUL_STRING },
48 	[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD] = { .type = NLA_U64 },
49 	[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_RECOVER] = { .type = NLA_U8 },
50 	[DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME] = { .type = NLA_NUL_STRING },
51 	[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT] = { .type = NLA_NUL_STRING },
52 	[DEVLINK_ATTR_FLASH_UPDATE_OVERWRITE_MASK] =
53 		NLA_POLICY_BITFIELD32(DEVLINK_SUPPORTED_FLASH_OVERWRITE_SECTIONS),
54 	[DEVLINK_ATTR_TRAP_NAME] = { .type = NLA_NUL_STRING },
55 	[DEVLINK_ATTR_TRAP_ACTION] = { .type = NLA_U8 },
56 	[DEVLINK_ATTR_TRAP_GROUP_NAME] = { .type = NLA_NUL_STRING },
57 	[DEVLINK_ATTR_NETNS_PID] = { .type = NLA_U32 },
58 	[DEVLINK_ATTR_NETNS_FD] = { .type = NLA_U32 },
59 	[DEVLINK_ATTR_NETNS_ID] = { .type = NLA_U32 },
60 	[DEVLINK_ATTR_HEALTH_REPORTER_AUTO_DUMP] = { .type = NLA_U8 },
61 	[DEVLINK_ATTR_TRAP_POLICER_ID] = { .type = NLA_U32 },
62 	[DEVLINK_ATTR_TRAP_POLICER_RATE] = { .type = NLA_U64 },
63 	[DEVLINK_ATTR_TRAP_POLICER_BURST] = { .type = NLA_U64 },
64 	[DEVLINK_ATTR_PORT_FUNCTION] = { .type = NLA_NESTED },
65 	[DEVLINK_ATTR_RELOAD_ACTION] = NLA_POLICY_RANGE(NLA_U8, DEVLINK_RELOAD_ACTION_DRIVER_REINIT,
66 							DEVLINK_RELOAD_ACTION_MAX),
67 	[DEVLINK_ATTR_RELOAD_LIMITS] = NLA_POLICY_BITFIELD32(DEVLINK_RELOAD_LIMITS_VALID_MASK),
68 	[DEVLINK_ATTR_PORT_FLAVOUR] = { .type = NLA_U16 },
69 	[DEVLINK_ATTR_PORT_PCI_PF_NUMBER] = { .type = NLA_U16 },
70 	[DEVLINK_ATTR_PORT_PCI_SF_NUMBER] = { .type = NLA_U32 },
71 	[DEVLINK_ATTR_PORT_CONTROLLER_NUMBER] = { .type = NLA_U32 },
72 	[DEVLINK_ATTR_RATE_TYPE] = { .type = NLA_U16 },
73 	[DEVLINK_ATTR_RATE_TX_SHARE] = { .type = NLA_U64 },
74 	[DEVLINK_ATTR_RATE_TX_MAX] = { .type = NLA_U64 },
75 	[DEVLINK_ATTR_RATE_NODE_NAME] = { .type = NLA_NUL_STRING },
76 	[DEVLINK_ATTR_RATE_PARENT_NODE_NAME] = { .type = NLA_NUL_STRING },
77 	[DEVLINK_ATTR_LINECARD_INDEX] = { .type = NLA_U32 },
78 	[DEVLINK_ATTR_LINECARD_TYPE] = { .type = NLA_NUL_STRING },
79 	[DEVLINK_ATTR_SELFTESTS] = { .type = NLA_NESTED },
80 	[DEVLINK_ATTR_RATE_TX_PRIORITY] = { .type = NLA_U32 },
81 	[DEVLINK_ATTR_RATE_TX_WEIGHT] = { .type = NLA_U32 },
82 	[DEVLINK_ATTR_REGION_DIRECT] = { .type = NLA_FLAG },
83 };
84 
85 int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net,
86 				 struct devlink *devlink, int attrtype)
87 {
88 	struct nlattr *nested_attr;
89 
90 	nested_attr = nla_nest_start(msg, attrtype);
91 	if (!nested_attr)
92 		return -EMSGSIZE;
93 	if (devlink_nl_put_handle(msg, devlink))
94 		goto nla_put_failure;
95 	if (!net_eq(net, devlink_net(devlink))) {
96 		int id = peernet2id_alloc(net, devlink_net(devlink),
97 					  GFP_KERNEL);
98 
99 		if (nla_put_s32(msg, DEVLINK_ATTR_NETNS_ID, id))
100 			return -EMSGSIZE;
101 	}
102 
103 	nla_nest_end(msg, nested_attr);
104 	return 0;
105 
106 nla_put_failure:
107 	nla_nest_cancel(msg, nested_attr);
108 	return -EMSGSIZE;
109 }
110 
111 int devlink_nl_msg_reply_and_new(struct sk_buff **msg, struct genl_info *info)
112 {
113 	int err;
114 
115 	if (*msg) {
116 		err = genlmsg_reply(*msg, info);
117 		if (err)
118 			return err;
119 	}
120 	*msg = genlmsg_new(GENLMSG_DEFAULT_SIZE, GFP_KERNEL);
121 	if (!*msg)
122 		return -ENOMEM;
123 	return 0;
124 }
125 
126 struct devlink *
127 devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs)
128 {
129 	struct devlink *devlink;
130 	unsigned long index;
131 	char *busname;
132 	char *devname;
133 
134 	if (!attrs[DEVLINK_ATTR_BUS_NAME] || !attrs[DEVLINK_ATTR_DEV_NAME])
135 		return ERR_PTR(-EINVAL);
136 
137 	busname = nla_data(attrs[DEVLINK_ATTR_BUS_NAME]);
138 	devname = nla_data(attrs[DEVLINK_ATTR_DEV_NAME]);
139 
140 	devlinks_xa_for_each_registered_get(net, index, devlink) {
141 		devl_lock(devlink);
142 		if (devl_is_registered(devlink) &&
143 		    strcmp(devlink->dev->bus->name, busname) == 0 &&
144 		    strcmp(dev_name(devlink->dev), devname) == 0)
145 			return devlink;
146 		devl_unlock(devlink);
147 		devlink_put(devlink);
148 	}
149 
150 	return ERR_PTR(-ENODEV);
151 }
152 
153 static int __devlink_nl_pre_doit(struct sk_buff *skb, struct genl_info *info,
154 				 u8 flags)
155 {
156 	struct devlink_port *devlink_port;
157 	struct devlink *devlink;
158 	int err;
159 
160 	devlink = devlink_get_from_attrs_lock(genl_info_net(info), info->attrs);
161 	if (IS_ERR(devlink))
162 		return PTR_ERR(devlink);
163 
164 	info->user_ptr[0] = devlink;
165 	if (flags & DEVLINK_NL_FLAG_NEED_PORT) {
166 		devlink_port = devlink_port_get_from_info(devlink, info);
167 		if (IS_ERR(devlink_port)) {
168 			err = PTR_ERR(devlink_port);
169 			goto unlock;
170 		}
171 		info->user_ptr[1] = devlink_port;
172 	} else if (flags & DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT) {
173 		devlink_port = devlink_port_get_from_info(devlink, info);
174 		if (!IS_ERR(devlink_port))
175 			info->user_ptr[1] = devlink_port;
176 	}
177 	return 0;
178 
179 unlock:
180 	devl_unlock(devlink);
181 	devlink_put(devlink);
182 	return err;
183 }
184 
185 int devlink_nl_pre_doit(const struct genl_split_ops *ops,
186 			struct sk_buff *skb, struct genl_info *info)
187 {
188 	return __devlink_nl_pre_doit(skb, info, ops->internal_flags);
189 }
190 
191 int devlink_nl_pre_doit_port(const struct genl_split_ops *ops,
192 			     struct sk_buff *skb, struct genl_info *info)
193 {
194 	return __devlink_nl_pre_doit(skb, info, DEVLINK_NL_FLAG_NEED_PORT);
195 }
196 
197 int devlink_nl_pre_doit_port_optional(const struct genl_split_ops *ops,
198 				      struct sk_buff *skb,
199 				      struct genl_info *info)
200 {
201 	return __devlink_nl_pre_doit(skb, info, DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT);
202 }
203 
204 void devlink_nl_post_doit(const struct genl_split_ops *ops,
205 			  struct sk_buff *skb, struct genl_info *info)
206 {
207 	struct devlink *devlink;
208 
209 	devlink = info->user_ptr[0];
210 	devl_unlock(devlink);
211 	devlink_put(devlink);
212 }
213 
214 static int devlink_nl_inst_single_dumpit(struct sk_buff *msg,
215 					 struct netlink_callback *cb, int flags,
216 					 devlink_nl_dump_one_func_t *dump_one,
217 					 struct nlattr **attrs)
218 {
219 	struct devlink *devlink;
220 	int err;
221 
222 	devlink = devlink_get_from_attrs_lock(sock_net(msg->sk), attrs);
223 	if (IS_ERR(devlink))
224 		return PTR_ERR(devlink);
225 	err = dump_one(msg, devlink, cb, flags | NLM_F_DUMP_FILTERED);
226 
227 	devl_unlock(devlink);
228 	devlink_put(devlink);
229 
230 	if (err != -EMSGSIZE)
231 		return err;
232 	return msg->len;
233 }
234 
235 static int devlink_nl_inst_iter_dumpit(struct sk_buff *msg,
236 				       struct netlink_callback *cb, int flags,
237 				       devlink_nl_dump_one_func_t *dump_one)
238 {
239 	struct devlink_nl_dump_state *state = devlink_dump_state(cb);
240 	struct devlink *devlink;
241 	int err = 0;
242 
243 	while ((devlink = devlinks_xa_find_get(sock_net(msg->sk),
244 					       &state->instance))) {
245 		devl_lock(devlink);
246 
247 		if (devl_is_registered(devlink))
248 			err = dump_one(msg, devlink, cb, flags);
249 		else
250 			err = 0;
251 
252 		devl_unlock(devlink);
253 		devlink_put(devlink);
254 
255 		if (err)
256 			break;
257 
258 		state->instance++;
259 
260 		/* restart sub-object walk for the next instance */
261 		state->idx = 0;
262 	}
263 
264 	if (err != -EMSGSIZE)
265 		return err;
266 	return msg->len;
267 }
268 
269 int devlink_nl_dumpit(struct sk_buff *msg, struct netlink_callback *cb,
270 		      devlink_nl_dump_one_func_t *dump_one)
271 {
272 	const struct genl_info *info = genl_info_dump(cb);
273 	struct nlattr **attrs = info->attrs;
274 	int flags = NLM_F_MULTI;
275 
276 	if (attrs &&
277 	    (attrs[DEVLINK_ATTR_BUS_NAME] || attrs[DEVLINK_ATTR_DEV_NAME]))
278 		return devlink_nl_inst_single_dumpit(msg, cb, flags, dump_one,
279 						     attrs);
280 	else
281 		return devlink_nl_inst_iter_dumpit(msg, cb, flags, dump_one);
282 }
283 
284 static const struct genl_small_ops devlink_nl_small_ops[40] = {
285 	{
286 		.cmd = DEVLINK_CMD_PORT_SET,
287 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
288 		.doit = devlink_nl_cmd_port_set_doit,
289 		.flags = GENL_ADMIN_PERM,
290 		.internal_flags = DEVLINK_NL_FLAG_NEED_PORT,
291 	},
292 	{
293 		.cmd = DEVLINK_CMD_RATE_SET,
294 		.doit = devlink_nl_cmd_rate_set_doit,
295 		.flags = GENL_ADMIN_PERM,
296 	},
297 	{
298 		.cmd = DEVLINK_CMD_RATE_NEW,
299 		.doit = devlink_nl_cmd_rate_new_doit,
300 		.flags = GENL_ADMIN_PERM,
301 	},
302 	{
303 		.cmd = DEVLINK_CMD_RATE_DEL,
304 		.doit = devlink_nl_cmd_rate_del_doit,
305 		.flags = GENL_ADMIN_PERM,
306 	},
307 	{
308 		.cmd = DEVLINK_CMD_PORT_SPLIT,
309 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
310 		.doit = devlink_nl_cmd_port_split_doit,
311 		.flags = GENL_ADMIN_PERM,
312 		.internal_flags = DEVLINK_NL_FLAG_NEED_PORT,
313 	},
314 	{
315 		.cmd = DEVLINK_CMD_PORT_UNSPLIT,
316 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
317 		.doit = devlink_nl_cmd_port_unsplit_doit,
318 		.flags = GENL_ADMIN_PERM,
319 		.internal_flags = DEVLINK_NL_FLAG_NEED_PORT,
320 	},
321 	{
322 		.cmd = DEVLINK_CMD_PORT_NEW,
323 		.doit = devlink_nl_cmd_port_new_doit,
324 		.flags = GENL_ADMIN_PERM,
325 	},
326 	{
327 		.cmd = DEVLINK_CMD_PORT_DEL,
328 		.doit = devlink_nl_cmd_port_del_doit,
329 		.flags = GENL_ADMIN_PERM,
330 		.internal_flags = DEVLINK_NL_FLAG_NEED_PORT,
331 	},
332 
333 	{
334 		.cmd = DEVLINK_CMD_LINECARD_SET,
335 		.doit = devlink_nl_cmd_linecard_set_doit,
336 		.flags = GENL_ADMIN_PERM,
337 	},
338 	{
339 		.cmd = DEVLINK_CMD_SB_POOL_SET,
340 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
341 		.doit = devlink_nl_cmd_sb_pool_set_doit,
342 		.flags = GENL_ADMIN_PERM,
343 	},
344 	{
345 		.cmd = DEVLINK_CMD_SB_PORT_POOL_SET,
346 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
347 		.doit = devlink_nl_cmd_sb_port_pool_set_doit,
348 		.flags = GENL_ADMIN_PERM,
349 		.internal_flags = DEVLINK_NL_FLAG_NEED_PORT,
350 	},
351 	{
352 		.cmd = DEVLINK_CMD_SB_TC_POOL_BIND_SET,
353 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
354 		.doit = devlink_nl_cmd_sb_tc_pool_bind_set_doit,
355 		.flags = GENL_ADMIN_PERM,
356 		.internal_flags = DEVLINK_NL_FLAG_NEED_PORT,
357 	},
358 	{
359 		.cmd = DEVLINK_CMD_SB_OCC_SNAPSHOT,
360 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
361 		.doit = devlink_nl_cmd_sb_occ_snapshot_doit,
362 		.flags = GENL_ADMIN_PERM,
363 	},
364 	{
365 		.cmd = DEVLINK_CMD_SB_OCC_MAX_CLEAR,
366 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
367 		.doit = devlink_nl_cmd_sb_occ_max_clear_doit,
368 		.flags = GENL_ADMIN_PERM,
369 	},
370 	{
371 		.cmd = DEVLINK_CMD_ESWITCH_GET,
372 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
373 		.doit = devlink_nl_cmd_eswitch_get_doit,
374 		.flags = GENL_ADMIN_PERM,
375 	},
376 	{
377 		.cmd = DEVLINK_CMD_ESWITCH_SET,
378 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
379 		.doit = devlink_nl_cmd_eswitch_set_doit,
380 		.flags = GENL_ADMIN_PERM,
381 	},
382 	{
383 		.cmd = DEVLINK_CMD_DPIPE_TABLE_GET,
384 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
385 		.doit = devlink_nl_cmd_dpipe_table_get,
386 		/* can be retrieved by unprivileged users */
387 	},
388 	{
389 		.cmd = DEVLINK_CMD_DPIPE_ENTRIES_GET,
390 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
391 		.doit = devlink_nl_cmd_dpipe_entries_get,
392 		/* can be retrieved by unprivileged users */
393 	},
394 	{
395 		.cmd = DEVLINK_CMD_DPIPE_HEADERS_GET,
396 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
397 		.doit = devlink_nl_cmd_dpipe_headers_get,
398 		/* can be retrieved by unprivileged users */
399 	},
400 	{
401 		.cmd = DEVLINK_CMD_DPIPE_TABLE_COUNTERS_SET,
402 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
403 		.doit = devlink_nl_cmd_dpipe_table_counters_set,
404 		.flags = GENL_ADMIN_PERM,
405 	},
406 	{
407 		.cmd = DEVLINK_CMD_RESOURCE_SET,
408 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
409 		.doit = devlink_nl_cmd_resource_set,
410 		.flags = GENL_ADMIN_PERM,
411 	},
412 	{
413 		.cmd = DEVLINK_CMD_RESOURCE_DUMP,
414 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
415 		.doit = devlink_nl_cmd_resource_dump,
416 		/* can be retrieved by unprivileged users */
417 	},
418 	{
419 		.cmd = DEVLINK_CMD_RELOAD,
420 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
421 		.doit = devlink_nl_cmd_reload,
422 		.flags = GENL_ADMIN_PERM,
423 	},
424 	{
425 		.cmd = DEVLINK_CMD_PARAM_SET,
426 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
427 		.doit = devlink_nl_cmd_param_set_doit,
428 		.flags = GENL_ADMIN_PERM,
429 	},
430 	{
431 		.cmd = DEVLINK_CMD_PORT_PARAM_GET,
432 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
433 		.doit = devlink_nl_cmd_port_param_get_doit,
434 		.dumpit = devlink_nl_cmd_port_param_get_dumpit,
435 		.internal_flags = DEVLINK_NL_FLAG_NEED_PORT,
436 		/* can be retrieved by unprivileged users */
437 	},
438 	{
439 		.cmd = DEVLINK_CMD_PORT_PARAM_SET,
440 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
441 		.doit = devlink_nl_cmd_port_param_set_doit,
442 		.flags = GENL_ADMIN_PERM,
443 		.internal_flags = DEVLINK_NL_FLAG_NEED_PORT,
444 	},
445 	{
446 		.cmd = DEVLINK_CMD_REGION_NEW,
447 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
448 		.doit = devlink_nl_cmd_region_new,
449 		.flags = GENL_ADMIN_PERM,
450 	},
451 	{
452 		.cmd = DEVLINK_CMD_REGION_DEL,
453 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
454 		.doit = devlink_nl_cmd_region_del,
455 		.flags = GENL_ADMIN_PERM,
456 	},
457 	{
458 		.cmd = DEVLINK_CMD_REGION_READ,
459 		.validate = GENL_DONT_VALIDATE_STRICT |
460 			    GENL_DONT_VALIDATE_DUMP_STRICT,
461 		.dumpit = devlink_nl_cmd_region_read_dumpit,
462 		.flags = GENL_ADMIN_PERM,
463 	},
464 	{
465 		.cmd = DEVLINK_CMD_HEALTH_REPORTER_SET,
466 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
467 		.doit = devlink_nl_cmd_health_reporter_set_doit,
468 		.flags = GENL_ADMIN_PERM,
469 		.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT,
470 	},
471 	{
472 		.cmd = DEVLINK_CMD_HEALTH_REPORTER_RECOVER,
473 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
474 		.doit = devlink_nl_cmd_health_reporter_recover_doit,
475 		.flags = GENL_ADMIN_PERM,
476 		.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT,
477 	},
478 	{
479 		.cmd = DEVLINK_CMD_HEALTH_REPORTER_DIAGNOSE,
480 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
481 		.doit = devlink_nl_cmd_health_reporter_diagnose_doit,
482 		.flags = GENL_ADMIN_PERM,
483 		.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT,
484 	},
485 	{
486 		.cmd = DEVLINK_CMD_HEALTH_REPORTER_DUMP_GET,
487 		.validate = GENL_DONT_VALIDATE_STRICT |
488 			    GENL_DONT_VALIDATE_DUMP_STRICT,
489 		.dumpit = devlink_nl_cmd_health_reporter_dump_get_dumpit,
490 		.flags = GENL_ADMIN_PERM,
491 	},
492 	{
493 		.cmd = DEVLINK_CMD_HEALTH_REPORTER_DUMP_CLEAR,
494 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
495 		.doit = devlink_nl_cmd_health_reporter_dump_clear_doit,
496 		.flags = GENL_ADMIN_PERM,
497 		.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT,
498 	},
499 	{
500 		.cmd = DEVLINK_CMD_HEALTH_REPORTER_TEST,
501 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
502 		.doit = devlink_nl_cmd_health_reporter_test_doit,
503 		.flags = GENL_ADMIN_PERM,
504 		.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT,
505 	},
506 	{
507 		.cmd = DEVLINK_CMD_FLASH_UPDATE,
508 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
509 		.doit = devlink_nl_cmd_flash_update,
510 		.flags = GENL_ADMIN_PERM,
511 	},
512 	{
513 		.cmd = DEVLINK_CMD_TRAP_SET,
514 		.doit = devlink_nl_cmd_trap_set_doit,
515 		.flags = GENL_ADMIN_PERM,
516 	},
517 	{
518 		.cmd = DEVLINK_CMD_TRAP_GROUP_SET,
519 		.doit = devlink_nl_cmd_trap_group_set_doit,
520 		.flags = GENL_ADMIN_PERM,
521 	},
522 	{
523 		.cmd = DEVLINK_CMD_TRAP_POLICER_SET,
524 		.doit = devlink_nl_cmd_trap_policer_set_doit,
525 		.flags = GENL_ADMIN_PERM,
526 	},
527 	{
528 		.cmd = DEVLINK_CMD_SELFTESTS_RUN,
529 		.doit = devlink_nl_cmd_selftests_run,
530 		.flags = GENL_ADMIN_PERM,
531 	},
532 	/* -- No new ops here! Use split ops going forward! -- */
533 };
534 
535 struct genl_family devlink_nl_family __ro_after_init = {
536 	.name		= DEVLINK_GENL_NAME,
537 	.version	= DEVLINK_GENL_VERSION,
538 	.maxattr	= DEVLINK_ATTR_MAX,
539 	.policy		= devlink_nl_policy,
540 	.netnsok	= true,
541 	.parallel_ops	= true,
542 	.pre_doit	= devlink_nl_pre_doit,
543 	.post_doit	= devlink_nl_post_doit,
544 	.module		= THIS_MODULE,
545 	.small_ops	= devlink_nl_small_ops,
546 	.n_small_ops	= ARRAY_SIZE(devlink_nl_small_ops),
547 	.split_ops	= devlink_nl_ops,
548 	.n_split_ops	= ARRAY_SIZE(devlink_nl_ops),
549 	.resv_start_op	= DEVLINK_CMD_SELFTESTS_RUN + 1,
550 	.mcgrps		= devlink_nl_mcgrps,
551 	.n_mcgrps	= ARRAY_SIZE(devlink_nl_mcgrps),
552 };
553