Lines Matching +full:resource +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0-or-later
10 * struct devlink_resource - devlink resource
11 * @name: name of the resource
12 * @id: id, per devlink instance
13 * @size: size of the resource
14 * @size_new: updated size of the resource, reload is needed
15 * @size_valid: valid in case the total size of the resource is valid
17 * @parent: parent resource
26 u64 id; member
40 struct devlink_resource *resource, u64 resource_id) in devlink_resource_find() argument
44 if (resource) in devlink_resource_find()
45 resource_list = &resource->resource_list; in devlink_resource_find()
47 resource_list = &devlink->resource_list; in devlink_resource_find()
49 list_for_each_entry(resource, resource_list, list) { in devlink_resource_find()
52 if (resource->id == resource_id) in devlink_resource_find()
53 return resource; in devlink_resource_find()
55 child_resource = devlink_resource_find(devlink, resource, in devlink_resource_find()
64 devlink_resource_validate_children(struct devlink_resource *resource) in devlink_resource_validate_children() argument
70 if (list_empty(&resource->resource_list)) in devlink_resource_validate_children()
73 list_for_each_entry(child_resource, &resource->resource_list, list) in devlink_resource_validate_children()
74 parts_size += child_resource->size_new; in devlink_resource_validate_children()
76 if (parts_size > resource->size_new) in devlink_resource_validate_children()
79 resource->size_valid = size_valid; in devlink_resource_validate_children()
83 devlink_resource_validate_size(struct devlink_resource *resource, u64 size, in devlink_resource_validate_size() argument
89 if (size > resource->size_params.size_max) { in devlink_resource_validate_size()
91 err = -EINVAL; in devlink_resource_validate_size()
94 if (size < resource->size_params.size_min) { in devlink_resource_validate_size()
96 err = -EINVAL; in devlink_resource_validate_size()
99 div64_u64_rem(size, resource->size_params.size_granularity, &reminder); in devlink_resource_validate_size()
102 err = -EINVAL; in devlink_resource_validate_size()
110 struct devlink *devlink = info->user_ptr[0]; in devlink_nl_resource_set_doit()
111 struct devlink_resource *resource; in devlink_nl_resource_set_doit() local
118 return -EINVAL; in devlink_nl_resource_set_doit()
119 resource_id = nla_get_u64(info->attrs[DEVLINK_ATTR_RESOURCE_ID]); in devlink_nl_resource_set_doit()
121 resource = devlink_resource_find(devlink, NULL, resource_id); in devlink_nl_resource_set_doit()
122 if (!resource) in devlink_nl_resource_set_doit()
123 return -EINVAL; in devlink_nl_resource_set_doit()
125 size = nla_get_u64(info->attrs[DEVLINK_ATTR_RESOURCE_SIZE]); in devlink_nl_resource_set_doit()
126 err = devlink_resource_validate_size(resource, size, info->extack); in devlink_nl_resource_set_doit()
130 resource->size_new = size; in devlink_nl_resource_set_doit()
131 devlink_resource_validate_children(resource); in devlink_nl_resource_set_doit()
132 if (resource->parent) in devlink_nl_resource_set_doit()
133 devlink_resource_validate_children(resource->parent); in devlink_nl_resource_set_doit()
138 devlink_resource_size_params_put(struct devlink_resource *resource, in devlink_resource_size_params_put() argument
143 size_params = &resource->size_params; in devlink_resource_size_params_put()
145 size_params->size_granularity, DEVLINK_ATTR_PAD) || in devlink_resource_size_params_put()
147 size_params->size_max, DEVLINK_ATTR_PAD) || in devlink_resource_size_params_put()
149 size_params->size_min, DEVLINK_ATTR_PAD) || in devlink_resource_size_params_put()
150 nla_put_u8(skb, DEVLINK_ATTR_RESOURCE_UNIT, size_params->unit)) in devlink_resource_size_params_put()
151 return -EMSGSIZE; in devlink_resource_size_params_put()
155 static int devlink_resource_occ_put(struct devlink_resource *resource, in devlink_resource_occ_put() argument
158 if (!resource->occ_get) in devlink_resource_occ_put()
161 resource->occ_get(resource->occ_get_priv), in devlink_resource_occ_put()
166 struct devlink_resource *resource) in devlink_resource_put() argument
174 return -EMSGSIZE; in devlink_resource_put()
176 if (nla_put_string(skb, DEVLINK_ATTR_RESOURCE_NAME, resource->name) || in devlink_resource_put()
177 nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE, resource->size, in devlink_resource_put()
179 nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_ID, resource->id, in devlink_resource_put()
182 if (resource->size != resource->size_new && in devlink_resource_put()
184 resource->size_new, DEVLINK_ATTR_PAD)) in devlink_resource_put()
186 if (devlink_resource_occ_put(resource, skb)) in devlink_resource_put()
188 if (devlink_resource_size_params_put(resource, skb)) in devlink_resource_put()
190 if (list_empty(&resource->resource_list)) in devlink_resource_put()
194 resource->size_valid)) in devlink_resource_put()
202 list_for_each_entry(child_resource, &resource->resource_list, list) { in devlink_resource_put()
216 return -EMSGSIZE; in devlink_resource_put()
222 struct devlink *devlink = info->user_ptr[0]; in devlink_resource_fill()
223 struct devlink_resource *resource; in devlink_resource_fill() local
232 resource = list_first_entry(&devlink->resource_list, in devlink_resource_fill()
239 hdr = genlmsg_put(skb, info->snd_portid, info->snd_seq, in devlink_resource_fill()
243 return -EMSGSIZE; in devlink_resource_fill()
256 list_for_each_entry_from(resource, &devlink->resource_list, list) { in devlink_resource_fill()
257 err = devlink_resource_put(devlink, skb, resource); in devlink_resource_fill()
271 nlh = nlmsg_put(skb, info->snd_portid, info->snd_seq, in devlink_resource_fill()
282 err = -EMSGSIZE; in devlink_resource_fill()
290 struct devlink *devlink = info->user_ptr[0]; in devlink_nl_resource_dump_doit()
292 if (list_empty(&devlink->resource_list)) in devlink_nl_resource_dump_doit()
293 return -EOPNOTSUPP; in devlink_nl_resource_dump_doit()
299 struct devlink_resource *resource, in devlink_resources_validate() argument
305 if (resource) in devlink_resources_validate()
306 resource_list = &resource->resource_list; in devlink_resources_validate()
308 resource_list = &devlink->resource_list; in devlink_resources_validate()
310 list_for_each_entry(resource, resource_list, list) { in devlink_resources_validate()
311 if (!resource->size_valid) in devlink_resources_validate()
312 return -EINVAL; in devlink_resources_validate()
313 err = devlink_resources_validate(devlink, resource, info); in devlink_resources_validate()
321 * devl_resource_register - devlink resource register
324 * @resource_name: resource's name
325 * @resource_size: resource's size
326 * @resource_id: resource's id
327 * @parent_resource_id: resource's parent id
332 * Documentation/networking/devlink/devlink-resource.rst
341 struct devlink_resource *resource; in devl_resource_register() local
345 lockdep_assert_held(&devlink->lock); in devl_resource_register()
349 resource = devlink_resource_find(devlink, NULL, resource_id); in devl_resource_register()
350 if (resource) in devl_resource_register()
351 return -EINVAL; in devl_resource_register()
353 resource = kzalloc(sizeof(*resource), GFP_KERNEL); in devl_resource_register()
354 if (!resource) in devl_resource_register()
355 return -ENOMEM; in devl_resource_register()
358 resource_list = &devlink->resource_list; in devl_resource_register()
365 resource_list = &parent_resource->resource_list; in devl_resource_register()
366 resource->parent = parent_resource; in devl_resource_register()
368 kfree(resource); in devl_resource_register()
369 return -EINVAL; in devl_resource_register()
373 resource->name = resource_name; in devl_resource_register()
374 resource->size = resource_size; in devl_resource_register()
375 resource->size_new = resource_size; in devl_resource_register()
376 resource->id = resource_id; in devl_resource_register()
377 resource->size_valid = true; in devl_resource_register()
378 memcpy(&resource->size_params, size_params, in devl_resource_register()
379 sizeof(resource->size_params)); in devl_resource_register()
380 INIT_LIST_HEAD(&resource->resource_list); in devl_resource_register()
381 list_add_tail(&resource->list, resource_list); in devl_resource_register()
388 * devlink_resource_register - devlink resource register
391 * @resource_name: resource's name
392 * @resource_size: resource's size
393 * @resource_id: resource's id
394 * @parent_resource_id: resource's parent id
399 * Documentation/networking/devlink/devlink-resource.rst
401 * Context: Takes and release devlink->lock <mutex>.
421 struct devlink_resource *resource) in devlink_resource_unregister() argument
425 list_for_each_entry_safe(child_resource, tmp, &resource->resource_list, in devlink_resource_unregister()
428 list_del(&child_resource->list); in devlink_resource_unregister()
434 * devl_resources_unregister - free all resources
442 lockdep_assert_held(&devlink->lock); in devl_resources_unregister()
444 list_for_each_entry_safe(child_resource, tmp, &devlink->resource_list, in devl_resources_unregister()
447 list_del(&child_resource->list); in devl_resources_unregister()
454 * devlink_resources_unregister - free all resources
458 * Context: Takes and release devlink->lock <mutex>.
469 * devl_resource_size_get - get and update size
472 * @resource_id: the requested resource id
479 struct devlink_resource *resource; in devl_resource_size_get() local
481 lockdep_assert_held(&devlink->lock); in devl_resource_size_get()
483 resource = devlink_resource_find(devlink, NULL, resource_id); in devl_resource_size_get()
484 if (!resource) in devl_resource_size_get()
485 return -EINVAL; in devl_resource_size_get()
486 *p_resource_size = resource->size_new; in devl_resource_size_get()
487 resource->size = resource->size_new; in devl_resource_size_get()
493 * devl_resource_occ_get_register - register occupancy getter
496 * @resource_id: resource id
505 struct devlink_resource *resource; in devl_resource_occ_get_register() local
507 lockdep_assert_held(&devlink->lock); in devl_resource_occ_get_register()
509 resource = devlink_resource_find(devlink, NULL, resource_id); in devl_resource_occ_get_register()
510 if (WARN_ON(!resource)) in devl_resource_occ_get_register()
512 WARN_ON(resource->occ_get); in devl_resource_occ_get_register()
514 resource->occ_get = occ_get; in devl_resource_occ_get_register()
515 resource->occ_get_priv = occ_get_priv; in devl_resource_occ_get_register()
520 * devlink_resource_occ_get_register - register occupancy getter
523 * @resource_id: resource id
527 * Context: Takes and release devlink->lock <mutex>.
542 * devl_resource_occ_get_unregister - unregister occupancy getter
545 * @resource_id: resource id
550 struct devlink_resource *resource; in devl_resource_occ_get_unregister() local
552 lockdep_assert_held(&devlink->lock); in devl_resource_occ_get_unregister()
554 resource = devlink_resource_find(devlink, NULL, resource_id); in devl_resource_occ_get_unregister()
555 if (WARN_ON(!resource)) in devl_resource_occ_get_unregister()
557 WARN_ON(!resource->occ_get); in devl_resource_occ_get_unregister()
559 resource->occ_get = NULL; in devl_resource_occ_get_unregister()
560 resource->occ_get_priv = NULL; in devl_resource_occ_get_unregister()
565 * devlink_resource_occ_get_unregister - unregister occupancy getter
568 * @resource_id: resource id
570 * Context: Takes and release devlink->lock <mutex>.