Lines Matching +full:elm +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
13 return -EOPNOTSUPP; in ib_uverbs_notsupp()
18 void *elm; in uapi_add_elm() local
22 return ERR_PTR(-EOVERFLOW); in uapi_add_elm()
24 elm = kzalloc(alloc_size, GFP_KERNEL); in uapi_add_elm()
25 if (!elm) in uapi_add_elm()
26 return ERR_PTR(-ENOMEM); in uapi_add_elm()
27 rc = radix_tree_insert(&uapi->radix, key, elm); in uapi_add_elm()
29 kfree(elm); in uapi_add_elm()
33 return elm; in uapi_add_elm()
39 void *elm; in uapi_add_get_elm() local
41 elm = uapi_add_elm(uapi, key, alloc_size); in uapi_add_get_elm()
42 if (!IS_ERR(elm)) { in uapi_add_get_elm()
44 return elm; in uapi_add_get_elm()
47 if (elm != ERR_PTR(-EEXIST)) in uapi_add_get_elm()
48 return elm; in uapi_add_get_elm()
50 elm = radix_tree_lookup(&uapi->radix, key); in uapi_add_get_elm()
51 if (WARN_ON(!elm)) in uapi_add_get_elm()
52 return ERR_PTR(-EINVAL); in uapi_add_get_elm()
54 return elm; in uapi_add_get_elm()
67 if (def->write.is_ex) in uapi_create_write()
68 method_key |= uapi_key_write_ex_method(def->write.command_num); in uapi_create_write()
70 method_key |= uapi_key_write_method(def->write.command_num); in uapi_create_write()
77 if (WARN_ON(exists && (def->write.is_ex != method_elm->is_ex))) in uapi_create_write()
78 return -EINVAL; in uapi_create_write()
80 method_elm->is_ex = def->write.is_ex; in uapi_create_write()
81 method_elm->handler = def->func_write; in uapi_create_write()
82 if (!def->write.is_ex) in uapi_create_write()
83 method_elm->disabled = !(ibdev->uverbs_cmd_mask & in uapi_create_write()
84 BIT_ULL(def->write.command_num)); in uapi_create_write()
86 if (!def->write.is_ex && def->func_write) { in uapi_create_write()
87 method_elm->has_udata = def->write.has_udata; in uapi_create_write()
88 method_elm->has_resp = def->write.has_resp; in uapi_create_write()
89 method_elm->req_size = def->write.req_size; in uapi_create_write()
90 method_elm->resp_size = def->write.resp_size; in uapi_create_write()
102 u32 method_key = obj_key | uapi_key_ioctl_method(method->id); in uapi_merge_method()
107 if (!method->attrs) in uapi_merge_method()
118 if (WARN_ON(method->handler)) in uapi_merge_method()
119 return -EINVAL; in uapi_merge_method()
121 WARN_ON(!method->handler); in uapi_merge_method()
122 rcu_assign_pointer(method_elm->handler, method->handler); in uapi_merge_method()
123 if (method->handler != uverbs_destroy_def_handler) in uapi_merge_method()
124 method_elm->driver_method = is_driver; in uapi_merge_method()
127 for (i = 0; i != method->num_attrs; i++) { in uapi_merge_method()
128 const struct uverbs_attr_def *attr = (*method->attrs)[i]; in uapi_merge_method()
139 if (attr->attr.type == UVERBS_ATTR_TYPE_ENUM_IN) in uapi_merge_method()
140 method_elm->driver_method |= is_driver; in uapi_merge_method()
146 if (attr->attr.type == UVERBS_ATTR_TYPE_IDRS_ARRAY) { in uapi_merge_method()
147 u8 access = attr->attr.u2.objs_arr.access; in uapi_merge_method()
151 return -EINVAL; in uapi_merge_method()
155 uapi_add_elm(uapi, method_key | uapi_key_attr(attr->id), in uapi_merge_method()
161 attr_slot->spec = attr->attr; in uapi_merge_method()
177 obj_key = uapi_key_obj(obj->id); in uapi_merge_obj_tree()
182 if (obj->type_attrs) { in uapi_merge_obj_tree()
183 if (WARN_ON(obj_elm->type_attrs)) in uapi_merge_obj_tree()
184 return -EINVAL; in uapi_merge_obj_tree()
186 obj_elm->id = obj->id; in uapi_merge_obj_tree()
187 obj_elm->type_attrs = obj->type_attrs; in uapi_merge_obj_tree()
188 obj_elm->type_class = obj->type_attrs->type_class; in uapi_merge_obj_tree()
200 obj->type_attrs->type_class != &uverbs_idr_class && in uapi_merge_obj_tree()
201 obj->type_attrs->type_class != &uverbs_fd_class)) in uapi_merge_obj_tree()
202 return -EINVAL; in uapi_merge_obj_tree()
205 if (!obj->methods) in uapi_merge_obj_tree()
208 for (i = 0; i != obj->num_methods; i++) { in uapi_merge_obj_tree()
209 const struct uverbs_method_def *method = (*obj->methods)[i]; in uapi_merge_obj_tree()
230 if (def->scope == UAPI_SCOPE_OBJECT) { in uapi_disable_elm()
237 obj_elm->disabled = 1; in uapi_disable_elm()
241 if (def->scope == UAPI_SCOPE_METHOD && in uapi_disable_elm()
249 method_elm->disabled = 1; in uapi_disable_elm()
253 if (def->scope == UAPI_SCOPE_METHOD && in uapi_disable_elm()
262 write_elm->disabled = 1; in uapi_disable_elm()
267 return -EINVAL; in uapi_disable_elm()
284 switch ((enum uapi_definition_kind)def->kind) { in uapi_merge_def()
286 rc = uapi_merge_def(uapi, ibdev, def->chain, is_driver); in uapi_merge_def()
292 if (WARN_ON(def->object_start.object_id != in uapi_merge_def()
293 def->chain_obj_tree->id)) in uapi_merge_def()
294 return -EINVAL; in uapi_merge_def()
296 cur_obj_key = uapi_key_obj(def->object_start.object_id); in uapi_merge_def()
297 rc = uapi_merge_obj_tree(uapi, def->chain_obj_tree, in uapi_merge_def()
308 (void *)(&ibdev->ops) + def->needs_fn_offset; in uapi_merge_def()
320 if (def->func_is_supported(ibdev)) in uapi_merge_def()
331 cur_obj_key = uapi_key_obj(def->object_start.object_id); in uapi_merge_def()
347 return -EINVAL; in uapi_merge_def()
362 method_elm->destroy_bkey = UVERBS_API_ATTR_BKEY_LEN; in uapi_finalize_ioctl_method()
363 radix_tree_for_each_slot (slot, &uapi->radix, &iter, in uapi_finalize_ioctl_method()
365 struct uverbs_api_attr *elm = in uapi_finalize_ioctl_method() local
369 u8 type = elm->spec.type; in uapi_finalize_ioctl_method()
375 if (elm->spec.mandatory) in uapi_finalize_ioctl_method()
376 __set_bit(attr_bkey, method_elm->attr_mandatory); in uapi_finalize_ioctl_method()
378 if (elm->spec.is_udata) in uapi_finalize_ioctl_method()
379 method_elm->has_udata = true; in uapi_finalize_ioctl_method()
383 u8 access = elm->spec.u.obj.access; in uapi_finalize_ioctl_method()
393 return -EINVAL; in uapi_finalize_ioctl_method()
396 if (WARN_ON(!elm->spec.mandatory)) in uapi_finalize_ioctl_method()
397 return -EINVAL; in uapi_finalize_ioctl_method()
401 method_elm->destroy_bkey = attr_bkey; in uapi_finalize_ioctl_method()
408 method_elm->key_bitmap_len = max_bkey + 1; in uapi_finalize_ioctl_method()
409 WARN_ON(method_elm->key_bitmap_len > UVERBS_API_ATTR_BKEY_LEN); in uapi_finalize_ioctl_method()
425 radix_tree_for_each_slot (slot, &uapi->radix, &iter, 0) { in uapi_finalize()
445 uapi->notsupp_method.handler = ib_uverbs_notsupp; in uapi_finalize()
446 uapi->num_write = max_write + 1; in uapi_finalize()
447 uapi->num_write_ex = max_write_ex + 1; in uapi_finalize()
448 data = kmalloc_array(uapi->num_write + uapi->num_write_ex, in uapi_finalize()
449 sizeof(*uapi->write_methods), GFP_KERNEL); in uapi_finalize()
451 return -ENOMEM; in uapi_finalize()
453 for (i = 0; i != uapi->num_write + uapi->num_write_ex; i++) in uapi_finalize()
454 data[i] = &uapi->notsupp_method; in uapi_finalize()
455 uapi->write_methods = data; in uapi_finalize()
456 uapi->write_ex_methods = data + uapi->num_write; in uapi_finalize()
458 radix_tree_for_each_slot (slot, &uapi->radix, &iter, 0) { in uapi_finalize()
460 uapi->write_methods[iter.index & in uapi_finalize()
464 uapi->write_ex_methods[iter.index & in uapi_finalize()
477 radix_tree_for_each_slot (slot, &uapi->radix, &iter, start) { in uapi_remove_range()
481 radix_tree_iter_delete(&uapi->radix, &iter, slot); in uapi_remove_range()
501 if (spec->type == UVERBS_ATTR_TYPE_IDR || in uapi_get_obj_id()
502 spec->type == UVERBS_ATTR_TYPE_FD) in uapi_get_obj_id()
503 return spec->u.obj.obj_type; in uapi_get_obj_id()
504 if (spec->type == UVERBS_ATTR_TYPE_IDRS_ARRAY) in uapi_get_obj_id()
505 return spec->u2.objs_arr.obj_type; in uapi_get_obj_id()
534 radix_tree_for_each_slot (slot, &uapi->radix, &iter, starting_key) { in uapi_finalize_disable()
541 if (obj_elm->disabled) { in uapi_finalize_disable()
555 if (method_elm->disabled) { in uapi_finalize_disable()
568 if (method_elm->disabled) { in uapi_finalize_disable()
570 radix_tree_iter_delete(&uapi->radix, &iter, slot); in uapi_finalize_disable()
586 if (!attr_elm->spec.mandatory) in uapi_finalize_disable()
588 obj_key = uapi_get_obj_id(&attr_elm->spec); in uapi_finalize_disable()
593 if (PTR_ERR(tmp_obj) == -ENOMSG) in uapi_finalize_disable()
596 if (!tmp_obj->disabled) in uapi_finalize_disable()
624 kfree(uapi->write_methods); in uverbs_destroy_api()
651 return ERR_PTR(-ENOMEM); in uverbs_alloc_api()
653 INIT_RADIX_TREE(&uapi->radix, GFP_KERNEL); in uverbs_alloc_api()
654 uapi->driver_id = ibdev->ops.driver_id; in uverbs_alloc_api()
659 rc = uapi_merge_def(uapi, ibdev, ibdev->driver_def, true); in uverbs_alloc_api()
670 if (rc != -ENOMEM) in uverbs_alloc_api()
671 dev_err(&ibdev->dev, in uverbs_alloc_api()
686 struct uverbs_api *uapi = uverbs_dev->uapi; in uverbs_disassociate_api_pre()
690 rcu_assign_pointer(uverbs_dev->ib_dev, NULL); in uverbs_disassociate_api_pre()
692 radix_tree_for_each_slot (slot, &uapi->radix, &iter, 0) { in uverbs_disassociate_api_pre()
697 if (method_elm->driver_method) in uverbs_disassociate_api_pre()
698 rcu_assign_pointer(method_elm->handler, NULL); in uverbs_disassociate_api_pre()
702 synchronize_srcu(&uverbs_dev->disassociate_srcu); in uverbs_disassociate_api_pre()
715 radix_tree_for_each_slot (slot, &uapi->radix, &iter, 0) { in uverbs_disassociate_api()
725 object_elm->type_attrs = NULL; in uverbs_disassociate_api()
727 struct uverbs_api_attr *elm = in uverbs_disassociate_api() local
730 if (elm->spec.type == UVERBS_ATTR_TYPE_ENUM_IN) in uverbs_disassociate_api()
731 elm->spec.u2.enum_def.ids = NULL; in uverbs_disassociate_api()