18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2017, Mellanox Technologies inc. All rights reserved. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef _UVERBS_IOCTL_ 78c2ecf20Sopenharmony_ci#define _UVERBS_IOCTL_ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <rdma/uverbs_types.h> 108c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 118c2ecf20Sopenharmony_ci#include <rdma/rdma_user_ioctl.h> 128c2ecf20Sopenharmony_ci#include <rdma/ib_user_ioctl_verbs.h> 138c2ecf20Sopenharmony_ci#include <rdma/ib_user_ioctl_cmds.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/* 168c2ecf20Sopenharmony_ci * ======================================= 178c2ecf20Sopenharmony_ci * Verbs action specifications 188c2ecf20Sopenharmony_ci * ======================================= 198c2ecf20Sopenharmony_ci */ 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cienum uverbs_attr_type { 228c2ecf20Sopenharmony_ci UVERBS_ATTR_TYPE_NA, 238c2ecf20Sopenharmony_ci UVERBS_ATTR_TYPE_PTR_IN, 248c2ecf20Sopenharmony_ci UVERBS_ATTR_TYPE_PTR_OUT, 258c2ecf20Sopenharmony_ci UVERBS_ATTR_TYPE_IDR, 268c2ecf20Sopenharmony_ci UVERBS_ATTR_TYPE_FD, 278c2ecf20Sopenharmony_ci UVERBS_ATTR_TYPE_ENUM_IN, 288c2ecf20Sopenharmony_ci UVERBS_ATTR_TYPE_IDRS_ARRAY, 298c2ecf20Sopenharmony_ci}; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cienum uverbs_obj_access { 328c2ecf20Sopenharmony_ci UVERBS_ACCESS_READ, 338c2ecf20Sopenharmony_ci UVERBS_ACCESS_WRITE, 348c2ecf20Sopenharmony_ci UVERBS_ACCESS_NEW, 358c2ecf20Sopenharmony_ci UVERBS_ACCESS_DESTROY 368c2ecf20Sopenharmony_ci}; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/* Specification of a single attribute inside the ioctl message */ 398c2ecf20Sopenharmony_ci/* good size 16 */ 408c2ecf20Sopenharmony_cistruct uverbs_attr_spec { 418c2ecf20Sopenharmony_ci u8 type; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci /* 448c2ecf20Sopenharmony_ci * Support extending attributes by length. Allow the user to provide 458c2ecf20Sopenharmony_ci * more bytes than ptr.len, but check that everything after is zero'd 468c2ecf20Sopenharmony_ci * by the user. 478c2ecf20Sopenharmony_ci */ 488c2ecf20Sopenharmony_ci u8 zero_trailing:1; 498c2ecf20Sopenharmony_ci /* 508c2ecf20Sopenharmony_ci * Valid only for PTR_IN. Allocate and copy the data inside 518c2ecf20Sopenharmony_ci * the parser 528c2ecf20Sopenharmony_ci */ 538c2ecf20Sopenharmony_ci u8 alloc_and_copy:1; 548c2ecf20Sopenharmony_ci u8 mandatory:1; 558c2ecf20Sopenharmony_ci /* True if this is from UVERBS_ATTR_UHW */ 568c2ecf20Sopenharmony_ci u8 is_udata:1; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci union { 598c2ecf20Sopenharmony_ci struct { 608c2ecf20Sopenharmony_ci /* Current known size to kernel */ 618c2ecf20Sopenharmony_ci u16 len; 628c2ecf20Sopenharmony_ci /* User isn't allowed to provide something < min_len */ 638c2ecf20Sopenharmony_ci u16 min_len; 648c2ecf20Sopenharmony_ci } ptr; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci struct { 678c2ecf20Sopenharmony_ci /* 688c2ecf20Sopenharmony_ci * higher bits mean the namespace and lower bits mean 698c2ecf20Sopenharmony_ci * the type id within the namespace. 708c2ecf20Sopenharmony_ci */ 718c2ecf20Sopenharmony_ci u16 obj_type; 728c2ecf20Sopenharmony_ci u8 access; 738c2ecf20Sopenharmony_ci } obj; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci struct { 768c2ecf20Sopenharmony_ci u8 num_elems; 778c2ecf20Sopenharmony_ci } enum_def; 788c2ecf20Sopenharmony_ci } u; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci /* This weird split lets us remove some padding */ 818c2ecf20Sopenharmony_ci union { 828c2ecf20Sopenharmony_ci struct { 838c2ecf20Sopenharmony_ci /* 848c2ecf20Sopenharmony_ci * The enum attribute can select one of the attributes 858c2ecf20Sopenharmony_ci * contained in the ids array. Currently only PTR_IN 868c2ecf20Sopenharmony_ci * attributes are supported in the ids array. 878c2ecf20Sopenharmony_ci */ 888c2ecf20Sopenharmony_ci const struct uverbs_attr_spec *ids; 898c2ecf20Sopenharmony_ci } enum_def; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci struct { 928c2ecf20Sopenharmony_ci /* 938c2ecf20Sopenharmony_ci * higher bits mean the namespace and lower bits mean 948c2ecf20Sopenharmony_ci * the type id within the namespace. 958c2ecf20Sopenharmony_ci */ 968c2ecf20Sopenharmony_ci u16 obj_type; 978c2ecf20Sopenharmony_ci u16 min_len; 988c2ecf20Sopenharmony_ci u16 max_len; 998c2ecf20Sopenharmony_ci u8 access; 1008c2ecf20Sopenharmony_ci } objs_arr; 1018c2ecf20Sopenharmony_ci } u2; 1028c2ecf20Sopenharmony_ci}; 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci/* 1058c2ecf20Sopenharmony_ci * Information about the API is loaded into a radix tree. For IOCTL we start 1068c2ecf20Sopenharmony_ci * with a tuple of: 1078c2ecf20Sopenharmony_ci * object_id, attr_id, method_id 1088c2ecf20Sopenharmony_ci * 1098c2ecf20Sopenharmony_ci * Which is a 48 bit value, with most of the bits guaranteed to be zero. Based 1108c2ecf20Sopenharmony_ci * on the current kernel support this is compressed into 16 bit key for the 1118c2ecf20Sopenharmony_ci * radix tree. Since this compression is entirely internal to the kernel the 1128c2ecf20Sopenharmony_ci * below limits can be revised if the kernel gains additional data. 1138c2ecf20Sopenharmony_ci * 1148c2ecf20Sopenharmony_ci * With 64 leafs per node this is a 3 level radix tree. 1158c2ecf20Sopenharmony_ci * 1168c2ecf20Sopenharmony_ci * The tree encodes multiple types, and uses a scheme where OBJ_ID,0,0 returns 1178c2ecf20Sopenharmony_ci * the object slot, and OBJ_ID,METH_ID,0 and returns the method slot. 1188c2ecf20Sopenharmony_ci * 1198c2ecf20Sopenharmony_ci * This also encodes the tables for the write() and write() extended commands 1208c2ecf20Sopenharmony_ci * using the coding 1218c2ecf20Sopenharmony_ci * OBJ_ID,UVERBS_API_METHOD_IS_WRITE,command # 1228c2ecf20Sopenharmony_ci * OBJ_ID,UVERBS_API_METHOD_IS_WRITE_EX,command_ex # 1238c2ecf20Sopenharmony_ci * ie the WRITE path is treated as a special method type in the ioctl 1248c2ecf20Sopenharmony_ci * framework. 1258c2ecf20Sopenharmony_ci */ 1268c2ecf20Sopenharmony_cienum uapi_radix_data { 1278c2ecf20Sopenharmony_ci UVERBS_API_NS_FLAG = 1U << UVERBS_ID_NS_SHIFT, 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci UVERBS_API_ATTR_KEY_BITS = 6, 1308c2ecf20Sopenharmony_ci UVERBS_API_ATTR_KEY_MASK = GENMASK(UVERBS_API_ATTR_KEY_BITS - 1, 0), 1318c2ecf20Sopenharmony_ci UVERBS_API_ATTR_BKEY_LEN = (1 << UVERBS_API_ATTR_KEY_BITS) - 1, 1328c2ecf20Sopenharmony_ci UVERBS_API_WRITE_KEY_NUM = 1 << UVERBS_API_ATTR_KEY_BITS, 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci UVERBS_API_METHOD_KEY_BITS = 5, 1358c2ecf20Sopenharmony_ci UVERBS_API_METHOD_KEY_SHIFT = UVERBS_API_ATTR_KEY_BITS, 1368c2ecf20Sopenharmony_ci UVERBS_API_METHOD_KEY_NUM_CORE = 22, 1378c2ecf20Sopenharmony_ci UVERBS_API_METHOD_IS_WRITE = 30 << UVERBS_API_METHOD_KEY_SHIFT, 1388c2ecf20Sopenharmony_ci UVERBS_API_METHOD_IS_WRITE_EX = 31 << UVERBS_API_METHOD_KEY_SHIFT, 1398c2ecf20Sopenharmony_ci UVERBS_API_METHOD_KEY_NUM_DRIVER = 1408c2ecf20Sopenharmony_ci (UVERBS_API_METHOD_IS_WRITE >> UVERBS_API_METHOD_KEY_SHIFT) - 1418c2ecf20Sopenharmony_ci UVERBS_API_METHOD_KEY_NUM_CORE, 1428c2ecf20Sopenharmony_ci UVERBS_API_METHOD_KEY_MASK = GENMASK( 1438c2ecf20Sopenharmony_ci UVERBS_API_METHOD_KEY_BITS + UVERBS_API_METHOD_KEY_SHIFT - 1, 1448c2ecf20Sopenharmony_ci UVERBS_API_METHOD_KEY_SHIFT), 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci UVERBS_API_OBJ_KEY_BITS = 5, 1478c2ecf20Sopenharmony_ci UVERBS_API_OBJ_KEY_SHIFT = 1488c2ecf20Sopenharmony_ci UVERBS_API_METHOD_KEY_BITS + UVERBS_API_METHOD_KEY_SHIFT, 1498c2ecf20Sopenharmony_ci UVERBS_API_OBJ_KEY_NUM_CORE = 20, 1508c2ecf20Sopenharmony_ci UVERBS_API_OBJ_KEY_NUM_DRIVER = 1518c2ecf20Sopenharmony_ci (1 << UVERBS_API_OBJ_KEY_BITS) - UVERBS_API_OBJ_KEY_NUM_CORE, 1528c2ecf20Sopenharmony_ci UVERBS_API_OBJ_KEY_MASK = GENMASK(31, UVERBS_API_OBJ_KEY_SHIFT), 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci /* This id guaranteed to not exist in the radix tree */ 1558c2ecf20Sopenharmony_ci UVERBS_API_KEY_ERR = 0xFFFFFFFF, 1568c2ecf20Sopenharmony_ci}; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_cistatic inline __attribute_const__ u32 uapi_key_obj(u32 id) 1598c2ecf20Sopenharmony_ci{ 1608c2ecf20Sopenharmony_ci if (id & UVERBS_API_NS_FLAG) { 1618c2ecf20Sopenharmony_ci id &= ~UVERBS_API_NS_FLAG; 1628c2ecf20Sopenharmony_ci if (id >= UVERBS_API_OBJ_KEY_NUM_DRIVER) 1638c2ecf20Sopenharmony_ci return UVERBS_API_KEY_ERR; 1648c2ecf20Sopenharmony_ci id = id + UVERBS_API_OBJ_KEY_NUM_CORE; 1658c2ecf20Sopenharmony_ci } else { 1668c2ecf20Sopenharmony_ci if (id >= UVERBS_API_OBJ_KEY_NUM_CORE) 1678c2ecf20Sopenharmony_ci return UVERBS_API_KEY_ERR; 1688c2ecf20Sopenharmony_ci } 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci return id << UVERBS_API_OBJ_KEY_SHIFT; 1718c2ecf20Sopenharmony_ci} 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_cistatic inline __attribute_const__ bool uapi_key_is_object(u32 key) 1748c2ecf20Sopenharmony_ci{ 1758c2ecf20Sopenharmony_ci return (key & ~UVERBS_API_OBJ_KEY_MASK) == 0; 1768c2ecf20Sopenharmony_ci} 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_cistatic inline __attribute_const__ u32 uapi_key_ioctl_method(u32 id) 1798c2ecf20Sopenharmony_ci{ 1808c2ecf20Sopenharmony_ci if (id & UVERBS_API_NS_FLAG) { 1818c2ecf20Sopenharmony_ci id &= ~UVERBS_API_NS_FLAG; 1828c2ecf20Sopenharmony_ci if (id >= UVERBS_API_METHOD_KEY_NUM_DRIVER) 1838c2ecf20Sopenharmony_ci return UVERBS_API_KEY_ERR; 1848c2ecf20Sopenharmony_ci id = id + UVERBS_API_METHOD_KEY_NUM_CORE; 1858c2ecf20Sopenharmony_ci } else { 1868c2ecf20Sopenharmony_ci id++; 1878c2ecf20Sopenharmony_ci if (id >= UVERBS_API_METHOD_KEY_NUM_CORE) 1888c2ecf20Sopenharmony_ci return UVERBS_API_KEY_ERR; 1898c2ecf20Sopenharmony_ci } 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci return id << UVERBS_API_METHOD_KEY_SHIFT; 1928c2ecf20Sopenharmony_ci} 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_cistatic inline __attribute_const__ u32 uapi_key_write_method(u32 id) 1958c2ecf20Sopenharmony_ci{ 1968c2ecf20Sopenharmony_ci if (id >= UVERBS_API_WRITE_KEY_NUM) 1978c2ecf20Sopenharmony_ci return UVERBS_API_KEY_ERR; 1988c2ecf20Sopenharmony_ci return UVERBS_API_METHOD_IS_WRITE | id; 1998c2ecf20Sopenharmony_ci} 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_cistatic inline __attribute_const__ u32 uapi_key_write_ex_method(u32 id) 2028c2ecf20Sopenharmony_ci{ 2038c2ecf20Sopenharmony_ci if (id >= UVERBS_API_WRITE_KEY_NUM) 2048c2ecf20Sopenharmony_ci return UVERBS_API_KEY_ERR; 2058c2ecf20Sopenharmony_ci return UVERBS_API_METHOD_IS_WRITE_EX | id; 2068c2ecf20Sopenharmony_ci} 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_cistatic inline __attribute_const__ u32 2098c2ecf20Sopenharmony_ciuapi_key_attr_to_ioctl_method(u32 attr_key) 2108c2ecf20Sopenharmony_ci{ 2118c2ecf20Sopenharmony_ci return attr_key & 2128c2ecf20Sopenharmony_ci (UVERBS_API_OBJ_KEY_MASK | UVERBS_API_METHOD_KEY_MASK); 2138c2ecf20Sopenharmony_ci} 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_cistatic inline __attribute_const__ bool uapi_key_is_ioctl_method(u32 key) 2168c2ecf20Sopenharmony_ci{ 2178c2ecf20Sopenharmony_ci unsigned int method = key & UVERBS_API_METHOD_KEY_MASK; 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci return method != 0 && method < UVERBS_API_METHOD_IS_WRITE && 2208c2ecf20Sopenharmony_ci (key & UVERBS_API_ATTR_KEY_MASK) == 0; 2218c2ecf20Sopenharmony_ci} 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_cistatic inline __attribute_const__ bool uapi_key_is_write_method(u32 key) 2248c2ecf20Sopenharmony_ci{ 2258c2ecf20Sopenharmony_ci return (key & UVERBS_API_METHOD_KEY_MASK) == UVERBS_API_METHOD_IS_WRITE; 2268c2ecf20Sopenharmony_ci} 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_cistatic inline __attribute_const__ bool uapi_key_is_write_ex_method(u32 key) 2298c2ecf20Sopenharmony_ci{ 2308c2ecf20Sopenharmony_ci return (key & UVERBS_API_METHOD_KEY_MASK) == 2318c2ecf20Sopenharmony_ci UVERBS_API_METHOD_IS_WRITE_EX; 2328c2ecf20Sopenharmony_ci} 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_cistatic inline __attribute_const__ u32 uapi_key_attrs_start(u32 ioctl_method_key) 2358c2ecf20Sopenharmony_ci{ 2368c2ecf20Sopenharmony_ci /* 0 is the method slot itself */ 2378c2ecf20Sopenharmony_ci return ioctl_method_key + 1; 2388c2ecf20Sopenharmony_ci} 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_cistatic inline __attribute_const__ u32 uapi_key_attr(u32 id) 2418c2ecf20Sopenharmony_ci{ 2428c2ecf20Sopenharmony_ci /* 2438c2ecf20Sopenharmony_ci * The attr is designed to fit in the typical single radix tree node 2448c2ecf20Sopenharmony_ci * of 64 entries. Since allmost all methods have driver attributes we 2458c2ecf20Sopenharmony_ci * organize things so that the driver and core attributes interleave to 2468c2ecf20Sopenharmony_ci * reduce the length of the attributes array in typical cases. 2478c2ecf20Sopenharmony_ci */ 2488c2ecf20Sopenharmony_ci if (id & UVERBS_API_NS_FLAG) { 2498c2ecf20Sopenharmony_ci id &= ~UVERBS_API_NS_FLAG; 2508c2ecf20Sopenharmony_ci id++; 2518c2ecf20Sopenharmony_ci if (id >= 1 << (UVERBS_API_ATTR_KEY_BITS - 1)) 2528c2ecf20Sopenharmony_ci return UVERBS_API_KEY_ERR; 2538c2ecf20Sopenharmony_ci id = (id << 1) | 0; 2548c2ecf20Sopenharmony_ci } else { 2558c2ecf20Sopenharmony_ci if (id >= 1 << (UVERBS_API_ATTR_KEY_BITS - 1)) 2568c2ecf20Sopenharmony_ci return UVERBS_API_KEY_ERR; 2578c2ecf20Sopenharmony_ci id = (id << 1) | 1; 2588c2ecf20Sopenharmony_ci } 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci return id; 2618c2ecf20Sopenharmony_ci} 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci/* Only true for ioctl methods */ 2648c2ecf20Sopenharmony_cistatic inline __attribute_const__ bool uapi_key_is_attr(u32 key) 2658c2ecf20Sopenharmony_ci{ 2668c2ecf20Sopenharmony_ci unsigned int method = key & UVERBS_API_METHOD_KEY_MASK; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci return method != 0 && method < UVERBS_API_METHOD_IS_WRITE && 2698c2ecf20Sopenharmony_ci (key & UVERBS_API_ATTR_KEY_MASK) != 0; 2708c2ecf20Sopenharmony_ci} 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci/* 2738c2ecf20Sopenharmony_ci * This returns a value in the range [0 to UVERBS_API_ATTR_BKEY_LEN), 2748c2ecf20Sopenharmony_ci * basically it undoes the reservation of 0 in the ID numbering. attr_key 2758c2ecf20Sopenharmony_ci * must already be masked with UVERBS_API_ATTR_KEY_MASK, or be the output of 2768c2ecf20Sopenharmony_ci * uapi_key_attr(). 2778c2ecf20Sopenharmony_ci */ 2788c2ecf20Sopenharmony_cistatic inline __attribute_const__ u32 uapi_bkey_attr(u32 attr_key) 2798c2ecf20Sopenharmony_ci{ 2808c2ecf20Sopenharmony_ci return attr_key - 1; 2818c2ecf20Sopenharmony_ci} 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_cistatic inline __attribute_const__ u32 uapi_bkey_to_key_attr(u32 attr_bkey) 2848c2ecf20Sopenharmony_ci{ 2858c2ecf20Sopenharmony_ci return attr_bkey + 1; 2868c2ecf20Sopenharmony_ci} 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci/* 2898c2ecf20Sopenharmony_ci * ======================================= 2908c2ecf20Sopenharmony_ci * Verbs definitions 2918c2ecf20Sopenharmony_ci * ======================================= 2928c2ecf20Sopenharmony_ci */ 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_cistruct uverbs_attr_def { 2958c2ecf20Sopenharmony_ci u16 id; 2968c2ecf20Sopenharmony_ci struct uverbs_attr_spec attr; 2978c2ecf20Sopenharmony_ci}; 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_cistruct uverbs_method_def { 3008c2ecf20Sopenharmony_ci u16 id; 3018c2ecf20Sopenharmony_ci /* Combination of bits from enum UVERBS_ACTION_FLAG_XXXX */ 3028c2ecf20Sopenharmony_ci u32 flags; 3038c2ecf20Sopenharmony_ci size_t num_attrs; 3048c2ecf20Sopenharmony_ci const struct uverbs_attr_def * const (*attrs)[]; 3058c2ecf20Sopenharmony_ci int (*handler)(struct uverbs_attr_bundle *attrs); 3068c2ecf20Sopenharmony_ci}; 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_cistruct uverbs_object_def { 3098c2ecf20Sopenharmony_ci u16 id; 3108c2ecf20Sopenharmony_ci const struct uverbs_obj_type *type_attrs; 3118c2ecf20Sopenharmony_ci size_t num_methods; 3128c2ecf20Sopenharmony_ci const struct uverbs_method_def * const (*methods)[]; 3138c2ecf20Sopenharmony_ci}; 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_cienum uapi_definition_kind { 3168c2ecf20Sopenharmony_ci UAPI_DEF_END = 0, 3178c2ecf20Sopenharmony_ci UAPI_DEF_OBJECT_START, 3188c2ecf20Sopenharmony_ci UAPI_DEF_WRITE, 3198c2ecf20Sopenharmony_ci UAPI_DEF_CHAIN_OBJ_TREE, 3208c2ecf20Sopenharmony_ci UAPI_DEF_CHAIN, 3218c2ecf20Sopenharmony_ci UAPI_DEF_IS_SUPPORTED_FUNC, 3228c2ecf20Sopenharmony_ci UAPI_DEF_IS_SUPPORTED_DEV_FN, 3238c2ecf20Sopenharmony_ci}; 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_cienum uapi_definition_scope { 3268c2ecf20Sopenharmony_ci UAPI_SCOPE_OBJECT = 1, 3278c2ecf20Sopenharmony_ci UAPI_SCOPE_METHOD = 2, 3288c2ecf20Sopenharmony_ci}; 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_cistruct uapi_definition { 3318c2ecf20Sopenharmony_ci u8 kind; 3328c2ecf20Sopenharmony_ci u8 scope; 3338c2ecf20Sopenharmony_ci union { 3348c2ecf20Sopenharmony_ci struct { 3358c2ecf20Sopenharmony_ci u16 object_id; 3368c2ecf20Sopenharmony_ci } object_start; 3378c2ecf20Sopenharmony_ci struct { 3388c2ecf20Sopenharmony_ci u16 command_num; 3398c2ecf20Sopenharmony_ci u8 is_ex:1; 3408c2ecf20Sopenharmony_ci u8 has_udata:1; 3418c2ecf20Sopenharmony_ci u8 has_resp:1; 3428c2ecf20Sopenharmony_ci u8 req_size; 3438c2ecf20Sopenharmony_ci u8 resp_size; 3448c2ecf20Sopenharmony_ci } write; 3458c2ecf20Sopenharmony_ci }; 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci union { 3488c2ecf20Sopenharmony_ci bool (*func_is_supported)(struct ib_device *device); 3498c2ecf20Sopenharmony_ci int (*func_write)(struct uverbs_attr_bundle *attrs); 3508c2ecf20Sopenharmony_ci const struct uapi_definition *chain; 3518c2ecf20Sopenharmony_ci const struct uverbs_object_def *chain_obj_tree; 3528c2ecf20Sopenharmony_ci size_t needs_fn_offset; 3538c2ecf20Sopenharmony_ci }; 3548c2ecf20Sopenharmony_ci}; 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci/* Define things connected to object_id */ 3578c2ecf20Sopenharmony_ci#define DECLARE_UVERBS_OBJECT(_object_id, ...) \ 3588c2ecf20Sopenharmony_ci { \ 3598c2ecf20Sopenharmony_ci .kind = UAPI_DEF_OBJECT_START, \ 3608c2ecf20Sopenharmony_ci .object_start = { .object_id = _object_id }, \ 3618c2ecf20Sopenharmony_ci }, \ 3628c2ecf20Sopenharmony_ci ##__VA_ARGS__ 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci/* Use in a var_args of DECLARE_UVERBS_OBJECT */ 3658c2ecf20Sopenharmony_ci#define DECLARE_UVERBS_WRITE(_command_num, _func, _cmd_desc, ...) \ 3668c2ecf20Sopenharmony_ci { \ 3678c2ecf20Sopenharmony_ci .kind = UAPI_DEF_WRITE, \ 3688c2ecf20Sopenharmony_ci .scope = UAPI_SCOPE_OBJECT, \ 3698c2ecf20Sopenharmony_ci .write = { .is_ex = 0, .command_num = _command_num }, \ 3708c2ecf20Sopenharmony_ci .func_write = _func, \ 3718c2ecf20Sopenharmony_ci _cmd_desc, \ 3728c2ecf20Sopenharmony_ci }, \ 3738c2ecf20Sopenharmony_ci ##__VA_ARGS__ 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci/* Use in a var_args of DECLARE_UVERBS_OBJECT */ 3768c2ecf20Sopenharmony_ci#define DECLARE_UVERBS_WRITE_EX(_command_num, _func, _cmd_desc, ...) \ 3778c2ecf20Sopenharmony_ci { \ 3788c2ecf20Sopenharmony_ci .kind = UAPI_DEF_WRITE, \ 3798c2ecf20Sopenharmony_ci .scope = UAPI_SCOPE_OBJECT, \ 3808c2ecf20Sopenharmony_ci .write = { .is_ex = 1, .command_num = _command_num }, \ 3818c2ecf20Sopenharmony_ci .func_write = _func, \ 3828c2ecf20Sopenharmony_ci _cmd_desc, \ 3838c2ecf20Sopenharmony_ci }, \ 3848c2ecf20Sopenharmony_ci ##__VA_ARGS__ 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ci/* 3878c2ecf20Sopenharmony_ci * Object is only supported if the function pointer named ibdev_fn in struct 3888c2ecf20Sopenharmony_ci * ib_device is not NULL. 3898c2ecf20Sopenharmony_ci */ 3908c2ecf20Sopenharmony_ci#define UAPI_DEF_OBJ_NEEDS_FN(ibdev_fn) \ 3918c2ecf20Sopenharmony_ci { \ 3928c2ecf20Sopenharmony_ci .kind = UAPI_DEF_IS_SUPPORTED_DEV_FN, \ 3938c2ecf20Sopenharmony_ci .scope = UAPI_SCOPE_OBJECT, \ 3948c2ecf20Sopenharmony_ci .needs_fn_offset = \ 3958c2ecf20Sopenharmony_ci offsetof(struct ib_device_ops, ibdev_fn) + \ 3968c2ecf20Sopenharmony_ci BUILD_BUG_ON_ZERO(sizeof_field(struct ib_device_ops, \ 3978c2ecf20Sopenharmony_ci ibdev_fn) != \ 3988c2ecf20Sopenharmony_ci sizeof(void *)), \ 3998c2ecf20Sopenharmony_ci } 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci/* 4028c2ecf20Sopenharmony_ci * Method is only supported if the function pointer named ibdev_fn in struct 4038c2ecf20Sopenharmony_ci * ib_device is not NULL. 4048c2ecf20Sopenharmony_ci */ 4058c2ecf20Sopenharmony_ci#define UAPI_DEF_METHOD_NEEDS_FN(ibdev_fn) \ 4068c2ecf20Sopenharmony_ci { \ 4078c2ecf20Sopenharmony_ci .kind = UAPI_DEF_IS_SUPPORTED_DEV_FN, \ 4088c2ecf20Sopenharmony_ci .scope = UAPI_SCOPE_METHOD, \ 4098c2ecf20Sopenharmony_ci .needs_fn_offset = \ 4108c2ecf20Sopenharmony_ci offsetof(struct ib_device_ops, ibdev_fn) + \ 4118c2ecf20Sopenharmony_ci BUILD_BUG_ON_ZERO(sizeof_field(struct ib_device_ops, \ 4128c2ecf20Sopenharmony_ci ibdev_fn) != \ 4138c2ecf20Sopenharmony_ci sizeof(void *)), \ 4148c2ecf20Sopenharmony_ci } 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci/* Call a function to determine if the entire object is supported or not */ 4178c2ecf20Sopenharmony_ci#define UAPI_DEF_IS_OBJ_SUPPORTED(_func) \ 4188c2ecf20Sopenharmony_ci { \ 4198c2ecf20Sopenharmony_ci .kind = UAPI_DEF_IS_SUPPORTED_FUNC, \ 4208c2ecf20Sopenharmony_ci .scope = UAPI_SCOPE_OBJECT, .func_is_supported = _func, \ 4218c2ecf20Sopenharmony_ci } 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci/* Include another struct uapi_definition in this one */ 4248c2ecf20Sopenharmony_ci#define UAPI_DEF_CHAIN(_def_var) \ 4258c2ecf20Sopenharmony_ci { \ 4268c2ecf20Sopenharmony_ci .kind = UAPI_DEF_CHAIN, .chain = _def_var, \ 4278c2ecf20Sopenharmony_ci } 4288c2ecf20Sopenharmony_ci 4298c2ecf20Sopenharmony_ci/* Temporary until the tree base description is replaced */ 4308c2ecf20Sopenharmony_ci#define UAPI_DEF_CHAIN_OBJ_TREE(_object_enum, _object_ptr, ...) \ 4318c2ecf20Sopenharmony_ci { \ 4328c2ecf20Sopenharmony_ci .kind = UAPI_DEF_CHAIN_OBJ_TREE, \ 4338c2ecf20Sopenharmony_ci .object_start = { .object_id = _object_enum }, \ 4348c2ecf20Sopenharmony_ci .chain_obj_tree = _object_ptr, \ 4358c2ecf20Sopenharmony_ci }, \ 4368c2ecf20Sopenharmony_ci ##__VA_ARGS__ 4378c2ecf20Sopenharmony_ci#define UAPI_DEF_CHAIN_OBJ_TREE_NAMED(_object_enum, ...) \ 4388c2ecf20Sopenharmony_ci UAPI_DEF_CHAIN_OBJ_TREE(_object_enum, &UVERBS_OBJECT(_object_enum), \ 4398c2ecf20Sopenharmony_ci ##__VA_ARGS__) 4408c2ecf20Sopenharmony_ci 4418c2ecf20Sopenharmony_ci/* 4428c2ecf20Sopenharmony_ci * ======================================= 4438c2ecf20Sopenharmony_ci * Attribute Specifications 4448c2ecf20Sopenharmony_ci * ======================================= 4458c2ecf20Sopenharmony_ci */ 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_ci#define UVERBS_ATTR_SIZE(_min_len, _len) \ 4488c2ecf20Sopenharmony_ci .u.ptr.min_len = _min_len, .u.ptr.len = _len 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci#define UVERBS_ATTR_NO_DATA() UVERBS_ATTR_SIZE(0, 0) 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci/* 4538c2ecf20Sopenharmony_ci * Specifies a uapi structure that cannot be extended. The user must always 4548c2ecf20Sopenharmony_ci * supply the whole structure and nothing more. The structure must be declared 4558c2ecf20Sopenharmony_ci * in a header under include/uapi/rdma. 4568c2ecf20Sopenharmony_ci */ 4578c2ecf20Sopenharmony_ci#define UVERBS_ATTR_TYPE(_type) \ 4588c2ecf20Sopenharmony_ci .u.ptr.min_len = sizeof(_type), .u.ptr.len = sizeof(_type) 4598c2ecf20Sopenharmony_ci/* 4608c2ecf20Sopenharmony_ci * Specifies a uapi structure where the user must provide at least up to 4618c2ecf20Sopenharmony_ci * member 'last'. Anything after last and up until the end of the structure 4628c2ecf20Sopenharmony_ci * can be non-zero, anything longer than the end of the structure must be 4638c2ecf20Sopenharmony_ci * zero. The structure must be declared in a header under include/uapi/rdma. 4648c2ecf20Sopenharmony_ci */ 4658c2ecf20Sopenharmony_ci#define UVERBS_ATTR_STRUCT(_type, _last) \ 4668c2ecf20Sopenharmony_ci .zero_trailing = 1, \ 4678c2ecf20Sopenharmony_ci UVERBS_ATTR_SIZE(offsetofend(_type, _last), sizeof(_type)) 4688c2ecf20Sopenharmony_ci/* 4698c2ecf20Sopenharmony_ci * Specifies at least min_len bytes must be passed in, but the amount can be 4708c2ecf20Sopenharmony_ci * larger, up to the protocol maximum size. No check for zeroing is done. 4718c2ecf20Sopenharmony_ci */ 4728c2ecf20Sopenharmony_ci#define UVERBS_ATTR_MIN_SIZE(_min_len) UVERBS_ATTR_SIZE(_min_len, USHRT_MAX) 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci/* Must be used in the '...' of any UVERBS_ATTR */ 4758c2ecf20Sopenharmony_ci#define UA_ALLOC_AND_COPY .alloc_and_copy = 1 4768c2ecf20Sopenharmony_ci#define UA_MANDATORY .mandatory = 1 4778c2ecf20Sopenharmony_ci#define UA_OPTIONAL .mandatory = 0 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci/* 4808c2ecf20Sopenharmony_ci * min_len must be bigger than 0 and _max_len must be smaller than 4095. Only 4818c2ecf20Sopenharmony_ci * READ\WRITE accesses are supported. 4828c2ecf20Sopenharmony_ci */ 4838c2ecf20Sopenharmony_ci#define UVERBS_ATTR_IDRS_ARR(_attr_id, _idr_type, _access, _min_len, _max_len, \ 4848c2ecf20Sopenharmony_ci ...) \ 4858c2ecf20Sopenharmony_ci (&(const struct uverbs_attr_def){ \ 4868c2ecf20Sopenharmony_ci .id = (_attr_id) + \ 4878c2ecf20Sopenharmony_ci BUILD_BUG_ON_ZERO((_min_len) == 0 || \ 4888c2ecf20Sopenharmony_ci (_max_len) > \ 4898c2ecf20Sopenharmony_ci PAGE_SIZE / sizeof(void *) || \ 4908c2ecf20Sopenharmony_ci (_min_len) > (_max_len) || \ 4918c2ecf20Sopenharmony_ci (_access) == UVERBS_ACCESS_NEW || \ 4928c2ecf20Sopenharmony_ci (_access) == UVERBS_ACCESS_DESTROY), \ 4938c2ecf20Sopenharmony_ci .attr = { .type = UVERBS_ATTR_TYPE_IDRS_ARRAY, \ 4948c2ecf20Sopenharmony_ci .u2.objs_arr.obj_type = _idr_type, \ 4958c2ecf20Sopenharmony_ci .u2.objs_arr.access = _access, \ 4968c2ecf20Sopenharmony_ci .u2.objs_arr.min_len = _min_len, \ 4978c2ecf20Sopenharmony_ci .u2.objs_arr.max_len = _max_len, \ 4988c2ecf20Sopenharmony_ci __VA_ARGS__ } }) 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_ci/* 5018c2ecf20Sopenharmony_ci * Only for use with UVERBS_ATTR_IDR, allows any uobject type to be accepted, 5028c2ecf20Sopenharmony_ci * the user must validate the type of the uobject instead. 5038c2ecf20Sopenharmony_ci */ 5048c2ecf20Sopenharmony_ci#define UVERBS_IDR_ANY_OBJECT 0xFFFF 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci#define UVERBS_ATTR_IDR(_attr_id, _idr_type, _access, ...) \ 5078c2ecf20Sopenharmony_ci (&(const struct uverbs_attr_def){ \ 5088c2ecf20Sopenharmony_ci .id = _attr_id, \ 5098c2ecf20Sopenharmony_ci .attr = { .type = UVERBS_ATTR_TYPE_IDR, \ 5108c2ecf20Sopenharmony_ci .u.obj.obj_type = _idr_type, \ 5118c2ecf20Sopenharmony_ci .u.obj.access = _access, \ 5128c2ecf20Sopenharmony_ci __VA_ARGS__ } }) 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci#define UVERBS_ATTR_FD(_attr_id, _fd_type, _access, ...) \ 5158c2ecf20Sopenharmony_ci (&(const struct uverbs_attr_def){ \ 5168c2ecf20Sopenharmony_ci .id = (_attr_id) + \ 5178c2ecf20Sopenharmony_ci BUILD_BUG_ON_ZERO((_access) != UVERBS_ACCESS_NEW && \ 5188c2ecf20Sopenharmony_ci (_access) != UVERBS_ACCESS_READ), \ 5198c2ecf20Sopenharmony_ci .attr = { .type = UVERBS_ATTR_TYPE_FD, \ 5208c2ecf20Sopenharmony_ci .u.obj.obj_type = _fd_type, \ 5218c2ecf20Sopenharmony_ci .u.obj.access = _access, \ 5228c2ecf20Sopenharmony_ci __VA_ARGS__ } }) 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ci#define UVERBS_ATTR_PTR_IN(_attr_id, _type, ...) \ 5258c2ecf20Sopenharmony_ci (&(const struct uverbs_attr_def){ \ 5268c2ecf20Sopenharmony_ci .id = _attr_id, \ 5278c2ecf20Sopenharmony_ci .attr = { .type = UVERBS_ATTR_TYPE_PTR_IN, \ 5288c2ecf20Sopenharmony_ci _type, \ 5298c2ecf20Sopenharmony_ci __VA_ARGS__ } }) 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci#define UVERBS_ATTR_PTR_OUT(_attr_id, _type, ...) \ 5328c2ecf20Sopenharmony_ci (&(const struct uverbs_attr_def){ \ 5338c2ecf20Sopenharmony_ci .id = _attr_id, \ 5348c2ecf20Sopenharmony_ci .attr = { .type = UVERBS_ATTR_TYPE_PTR_OUT, \ 5358c2ecf20Sopenharmony_ci _type, \ 5368c2ecf20Sopenharmony_ci __VA_ARGS__ } }) 5378c2ecf20Sopenharmony_ci 5388c2ecf20Sopenharmony_ci/* _enum_arry should be a 'static const union uverbs_attr_spec[]' */ 5398c2ecf20Sopenharmony_ci#define UVERBS_ATTR_ENUM_IN(_attr_id, _enum_arr, ...) \ 5408c2ecf20Sopenharmony_ci (&(const struct uverbs_attr_def){ \ 5418c2ecf20Sopenharmony_ci .id = _attr_id, \ 5428c2ecf20Sopenharmony_ci .attr = { .type = UVERBS_ATTR_TYPE_ENUM_IN, \ 5438c2ecf20Sopenharmony_ci .u2.enum_def.ids = _enum_arr, \ 5448c2ecf20Sopenharmony_ci .u.enum_def.num_elems = ARRAY_SIZE(_enum_arr), \ 5458c2ecf20Sopenharmony_ci __VA_ARGS__ }, \ 5468c2ecf20Sopenharmony_ci }) 5478c2ecf20Sopenharmony_ci 5488c2ecf20Sopenharmony_ci/* An input value that is a member in the enum _enum_type. */ 5498c2ecf20Sopenharmony_ci#define UVERBS_ATTR_CONST_IN(_attr_id, _enum_type, ...) \ 5508c2ecf20Sopenharmony_ci UVERBS_ATTR_PTR_IN( \ 5518c2ecf20Sopenharmony_ci _attr_id, \ 5528c2ecf20Sopenharmony_ci UVERBS_ATTR_SIZE( \ 5538c2ecf20Sopenharmony_ci sizeof(u64) + BUILD_BUG_ON_ZERO(!sizeof(_enum_type)), \ 5548c2ecf20Sopenharmony_ci sizeof(u64)), \ 5558c2ecf20Sopenharmony_ci __VA_ARGS__) 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci/* 5588c2ecf20Sopenharmony_ci * An input value that is a bitwise combination of values of _enum_type. 5598c2ecf20Sopenharmony_ci * This permits the flag value to be passed as either a u32 or u64, it must 5608c2ecf20Sopenharmony_ci * be retrieved via uverbs_get_flag(). 5618c2ecf20Sopenharmony_ci */ 5628c2ecf20Sopenharmony_ci#define UVERBS_ATTR_FLAGS_IN(_attr_id, _enum_type, ...) \ 5638c2ecf20Sopenharmony_ci UVERBS_ATTR_PTR_IN( \ 5648c2ecf20Sopenharmony_ci _attr_id, \ 5658c2ecf20Sopenharmony_ci UVERBS_ATTR_SIZE(sizeof(u32) + BUILD_BUG_ON_ZERO( \ 5668c2ecf20Sopenharmony_ci !sizeof(_enum_type *)), \ 5678c2ecf20Sopenharmony_ci sizeof(u64)), \ 5688c2ecf20Sopenharmony_ci __VA_ARGS__) 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_ci/* 5718c2ecf20Sopenharmony_ci * This spec is used in order to pass information to the hardware driver in a 5728c2ecf20Sopenharmony_ci * legacy way. Every verb that could get driver specific data should get this 5738c2ecf20Sopenharmony_ci * spec. 5748c2ecf20Sopenharmony_ci */ 5758c2ecf20Sopenharmony_ci#define UVERBS_ATTR_UHW() \ 5768c2ecf20Sopenharmony_ci UVERBS_ATTR_PTR_IN(UVERBS_ATTR_UHW_IN, \ 5778c2ecf20Sopenharmony_ci UVERBS_ATTR_MIN_SIZE(0), \ 5788c2ecf20Sopenharmony_ci UA_OPTIONAL, \ 5798c2ecf20Sopenharmony_ci .is_udata = 1), \ 5808c2ecf20Sopenharmony_ci UVERBS_ATTR_PTR_OUT(UVERBS_ATTR_UHW_OUT, \ 5818c2ecf20Sopenharmony_ci UVERBS_ATTR_MIN_SIZE(0), \ 5828c2ecf20Sopenharmony_ci UA_OPTIONAL, \ 5838c2ecf20Sopenharmony_ci .is_udata = 1) 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci/* ================================================= 5868c2ecf20Sopenharmony_ci * Parsing infrastructure 5878c2ecf20Sopenharmony_ci * ================================================= 5888c2ecf20Sopenharmony_ci */ 5898c2ecf20Sopenharmony_ci 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_cistruct uverbs_ptr_attr { 5928c2ecf20Sopenharmony_ci /* 5938c2ecf20Sopenharmony_ci * If UVERBS_ATTR_SPEC_F_ALLOC_AND_COPY is set then the 'ptr' is 5948c2ecf20Sopenharmony_ci * used. 5958c2ecf20Sopenharmony_ci */ 5968c2ecf20Sopenharmony_ci union { 5978c2ecf20Sopenharmony_ci void *ptr; 5988c2ecf20Sopenharmony_ci u64 data; 5998c2ecf20Sopenharmony_ci }; 6008c2ecf20Sopenharmony_ci u16 len; 6018c2ecf20Sopenharmony_ci u16 uattr_idx; 6028c2ecf20Sopenharmony_ci u8 enum_id; 6038c2ecf20Sopenharmony_ci}; 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_cistruct uverbs_obj_attr { 6068c2ecf20Sopenharmony_ci struct ib_uobject *uobject; 6078c2ecf20Sopenharmony_ci const struct uverbs_api_attr *attr_elm; 6088c2ecf20Sopenharmony_ci}; 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_cistruct uverbs_objs_arr_attr { 6118c2ecf20Sopenharmony_ci struct ib_uobject **uobjects; 6128c2ecf20Sopenharmony_ci u16 len; 6138c2ecf20Sopenharmony_ci}; 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_cistruct uverbs_attr { 6168c2ecf20Sopenharmony_ci union { 6178c2ecf20Sopenharmony_ci struct uverbs_ptr_attr ptr_attr; 6188c2ecf20Sopenharmony_ci struct uverbs_obj_attr obj_attr; 6198c2ecf20Sopenharmony_ci struct uverbs_objs_arr_attr objs_arr_attr; 6208c2ecf20Sopenharmony_ci }; 6218c2ecf20Sopenharmony_ci}; 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_cistruct uverbs_attr_bundle { 6248c2ecf20Sopenharmony_ci struct ib_udata driver_udata; 6258c2ecf20Sopenharmony_ci struct ib_udata ucore; 6268c2ecf20Sopenharmony_ci struct ib_uverbs_file *ufile; 6278c2ecf20Sopenharmony_ci struct ib_ucontext *context; 6288c2ecf20Sopenharmony_ci struct ib_uobject *uobject; 6298c2ecf20Sopenharmony_ci DECLARE_BITMAP(attr_present, UVERBS_API_ATTR_BKEY_LEN); 6308c2ecf20Sopenharmony_ci struct uverbs_attr attrs[]; 6318c2ecf20Sopenharmony_ci}; 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_cistatic inline bool uverbs_attr_is_valid(const struct uverbs_attr_bundle *attrs_bundle, 6348c2ecf20Sopenharmony_ci unsigned int idx) 6358c2ecf20Sopenharmony_ci{ 6368c2ecf20Sopenharmony_ci return test_bit(uapi_bkey_attr(uapi_key_attr(idx)), 6378c2ecf20Sopenharmony_ci attrs_bundle->attr_present); 6388c2ecf20Sopenharmony_ci} 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci/** 6418c2ecf20Sopenharmony_ci * rdma_udata_to_drv_context - Helper macro to get the driver's context out of 6428c2ecf20Sopenharmony_ci * ib_udata which is embedded in uverbs_attr_bundle. 6438c2ecf20Sopenharmony_ci * 6448c2ecf20Sopenharmony_ci * If udata is not NULL this cannot fail. Otherwise a NULL udata will result 6458c2ecf20Sopenharmony_ci * in a NULL ucontext pointer, as a safety precaution. Callers should be using 6468c2ecf20Sopenharmony_ci * 'udata' to determine if the driver call is in user or kernel mode, not 6478c2ecf20Sopenharmony_ci * 'ucontext'. 6488c2ecf20Sopenharmony_ci * 6498c2ecf20Sopenharmony_ci */ 6508c2ecf20Sopenharmony_ci#define rdma_udata_to_drv_context(udata, drv_dev_struct, member) \ 6518c2ecf20Sopenharmony_ci (udata ? container_of(container_of(udata, struct uverbs_attr_bundle, \ 6528c2ecf20Sopenharmony_ci driver_udata) \ 6538c2ecf20Sopenharmony_ci ->context, \ 6548c2ecf20Sopenharmony_ci drv_dev_struct, member) : \ 6558c2ecf20Sopenharmony_ci (drv_dev_struct *)NULL) 6568c2ecf20Sopenharmony_ci 6578c2ecf20Sopenharmony_ci#define IS_UVERBS_COPY_ERR(_ret) ((_ret) && (_ret) != -ENOENT) 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_cistatic inline const struct uverbs_attr *uverbs_attr_get(const struct uverbs_attr_bundle *attrs_bundle, 6608c2ecf20Sopenharmony_ci u16 idx) 6618c2ecf20Sopenharmony_ci{ 6628c2ecf20Sopenharmony_ci if (!uverbs_attr_is_valid(attrs_bundle, idx)) 6638c2ecf20Sopenharmony_ci return ERR_PTR(-ENOENT); 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci return &attrs_bundle->attrs[uapi_bkey_attr(uapi_key_attr(idx))]; 6668c2ecf20Sopenharmony_ci} 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_cistatic inline int uverbs_attr_get_enum_id(const struct uverbs_attr_bundle *attrs_bundle, 6698c2ecf20Sopenharmony_ci u16 idx) 6708c2ecf20Sopenharmony_ci{ 6718c2ecf20Sopenharmony_ci const struct uverbs_attr *attr = uverbs_attr_get(attrs_bundle, idx); 6728c2ecf20Sopenharmony_ci 6738c2ecf20Sopenharmony_ci if (IS_ERR(attr)) 6748c2ecf20Sopenharmony_ci return PTR_ERR(attr); 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci return attr->ptr_attr.enum_id; 6778c2ecf20Sopenharmony_ci} 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_cistatic inline void *uverbs_attr_get_obj(const struct uverbs_attr_bundle *attrs_bundle, 6808c2ecf20Sopenharmony_ci u16 idx) 6818c2ecf20Sopenharmony_ci{ 6828c2ecf20Sopenharmony_ci const struct uverbs_attr *attr; 6838c2ecf20Sopenharmony_ci 6848c2ecf20Sopenharmony_ci attr = uverbs_attr_get(attrs_bundle, idx); 6858c2ecf20Sopenharmony_ci if (IS_ERR(attr)) 6868c2ecf20Sopenharmony_ci return ERR_CAST(attr); 6878c2ecf20Sopenharmony_ci 6888c2ecf20Sopenharmony_ci return attr->obj_attr.uobject->object; 6898c2ecf20Sopenharmony_ci} 6908c2ecf20Sopenharmony_ci 6918c2ecf20Sopenharmony_cistatic inline struct ib_uobject *uverbs_attr_get_uobject(const struct uverbs_attr_bundle *attrs_bundle, 6928c2ecf20Sopenharmony_ci u16 idx) 6938c2ecf20Sopenharmony_ci{ 6948c2ecf20Sopenharmony_ci const struct uverbs_attr *attr = uverbs_attr_get(attrs_bundle, idx); 6958c2ecf20Sopenharmony_ci 6968c2ecf20Sopenharmony_ci if (IS_ERR(attr)) 6978c2ecf20Sopenharmony_ci return ERR_CAST(attr); 6988c2ecf20Sopenharmony_ci 6998c2ecf20Sopenharmony_ci return attr->obj_attr.uobject; 7008c2ecf20Sopenharmony_ci} 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_cistatic inline int 7038c2ecf20Sopenharmony_ciuverbs_attr_get_len(const struct uverbs_attr_bundle *attrs_bundle, u16 idx) 7048c2ecf20Sopenharmony_ci{ 7058c2ecf20Sopenharmony_ci const struct uverbs_attr *attr = uverbs_attr_get(attrs_bundle, idx); 7068c2ecf20Sopenharmony_ci 7078c2ecf20Sopenharmony_ci if (IS_ERR(attr)) 7088c2ecf20Sopenharmony_ci return PTR_ERR(attr); 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ci return attr->ptr_attr.len; 7118c2ecf20Sopenharmony_ci} 7128c2ecf20Sopenharmony_ci 7138c2ecf20Sopenharmony_civoid uverbs_finalize_uobj_create(const struct uverbs_attr_bundle *attrs_bundle, 7148c2ecf20Sopenharmony_ci u16 idx); 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_ci/* 7178c2ecf20Sopenharmony_ci * uverbs_attr_ptr_get_array_size() - Get array size pointer by a ptr 7188c2ecf20Sopenharmony_ci * attribute. 7198c2ecf20Sopenharmony_ci * @attrs: The attribute bundle 7208c2ecf20Sopenharmony_ci * @idx: The ID of the attribute 7218c2ecf20Sopenharmony_ci * @elem_size: The size of the element in the array 7228c2ecf20Sopenharmony_ci */ 7238c2ecf20Sopenharmony_cistatic inline int 7248c2ecf20Sopenharmony_ciuverbs_attr_ptr_get_array_size(struct uverbs_attr_bundle *attrs, u16 idx, 7258c2ecf20Sopenharmony_ci size_t elem_size) 7268c2ecf20Sopenharmony_ci{ 7278c2ecf20Sopenharmony_ci int size = uverbs_attr_get_len(attrs, idx); 7288c2ecf20Sopenharmony_ci 7298c2ecf20Sopenharmony_ci if (size < 0) 7308c2ecf20Sopenharmony_ci return size; 7318c2ecf20Sopenharmony_ci 7328c2ecf20Sopenharmony_ci if (size % elem_size) 7338c2ecf20Sopenharmony_ci return -EINVAL; 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_ci return size / elem_size; 7368c2ecf20Sopenharmony_ci} 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci/** 7398c2ecf20Sopenharmony_ci * uverbs_attr_get_uobjs_arr() - Provides array's properties for attribute for 7408c2ecf20Sopenharmony_ci * UVERBS_ATTR_TYPE_IDRS_ARRAY. 7418c2ecf20Sopenharmony_ci * @arr: Returned pointer to array of pointers for uobjects or NULL if 7428c2ecf20Sopenharmony_ci * the attribute isn't provided. 7438c2ecf20Sopenharmony_ci * 7448c2ecf20Sopenharmony_ci * Return: The array length or 0 if no attribute was provided. 7458c2ecf20Sopenharmony_ci */ 7468c2ecf20Sopenharmony_cistatic inline int uverbs_attr_get_uobjs_arr( 7478c2ecf20Sopenharmony_ci const struct uverbs_attr_bundle *attrs_bundle, u16 attr_idx, 7488c2ecf20Sopenharmony_ci struct ib_uobject ***arr) 7498c2ecf20Sopenharmony_ci{ 7508c2ecf20Sopenharmony_ci const struct uverbs_attr *attr = 7518c2ecf20Sopenharmony_ci uverbs_attr_get(attrs_bundle, attr_idx); 7528c2ecf20Sopenharmony_ci 7538c2ecf20Sopenharmony_ci if (IS_ERR(attr)) { 7548c2ecf20Sopenharmony_ci *arr = NULL; 7558c2ecf20Sopenharmony_ci return 0; 7568c2ecf20Sopenharmony_ci } 7578c2ecf20Sopenharmony_ci 7588c2ecf20Sopenharmony_ci *arr = attr->objs_arr_attr.uobjects; 7598c2ecf20Sopenharmony_ci 7608c2ecf20Sopenharmony_ci return attr->objs_arr_attr.len; 7618c2ecf20Sopenharmony_ci} 7628c2ecf20Sopenharmony_ci 7638c2ecf20Sopenharmony_cistatic inline bool uverbs_attr_ptr_is_inline(const struct uverbs_attr *attr) 7648c2ecf20Sopenharmony_ci{ 7658c2ecf20Sopenharmony_ci return attr->ptr_attr.len <= sizeof(attr->ptr_attr.data); 7668c2ecf20Sopenharmony_ci} 7678c2ecf20Sopenharmony_ci 7688c2ecf20Sopenharmony_cistatic inline void *uverbs_attr_get_alloced_ptr( 7698c2ecf20Sopenharmony_ci const struct uverbs_attr_bundle *attrs_bundle, u16 idx) 7708c2ecf20Sopenharmony_ci{ 7718c2ecf20Sopenharmony_ci const struct uverbs_attr *attr = uverbs_attr_get(attrs_bundle, idx); 7728c2ecf20Sopenharmony_ci 7738c2ecf20Sopenharmony_ci if (IS_ERR(attr)) 7748c2ecf20Sopenharmony_ci return (void *)attr; 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_ci return uverbs_attr_ptr_is_inline(attr) ? (void *)&attr->ptr_attr.data : 7778c2ecf20Sopenharmony_ci attr->ptr_attr.ptr; 7788c2ecf20Sopenharmony_ci} 7798c2ecf20Sopenharmony_ci 7808c2ecf20Sopenharmony_cistatic inline int _uverbs_copy_from(void *to, 7818c2ecf20Sopenharmony_ci const struct uverbs_attr_bundle *attrs_bundle, 7828c2ecf20Sopenharmony_ci size_t idx, 7838c2ecf20Sopenharmony_ci size_t size) 7848c2ecf20Sopenharmony_ci{ 7858c2ecf20Sopenharmony_ci const struct uverbs_attr *attr = uverbs_attr_get(attrs_bundle, idx); 7868c2ecf20Sopenharmony_ci 7878c2ecf20Sopenharmony_ci if (IS_ERR(attr)) 7888c2ecf20Sopenharmony_ci return PTR_ERR(attr); 7898c2ecf20Sopenharmony_ci 7908c2ecf20Sopenharmony_ci /* 7918c2ecf20Sopenharmony_ci * Validation ensures attr->ptr_attr.len >= size. If the caller is 7928c2ecf20Sopenharmony_ci * using UVERBS_ATTR_SPEC_F_MIN_SZ_OR_ZERO then it must call 7938c2ecf20Sopenharmony_ci * uverbs_copy_from_or_zero. 7948c2ecf20Sopenharmony_ci */ 7958c2ecf20Sopenharmony_ci if (unlikely(size < attr->ptr_attr.len)) 7968c2ecf20Sopenharmony_ci return -EINVAL; 7978c2ecf20Sopenharmony_ci 7988c2ecf20Sopenharmony_ci if (uverbs_attr_ptr_is_inline(attr)) 7998c2ecf20Sopenharmony_ci memcpy(to, &attr->ptr_attr.data, attr->ptr_attr.len); 8008c2ecf20Sopenharmony_ci else if (copy_from_user(to, u64_to_user_ptr(attr->ptr_attr.data), 8018c2ecf20Sopenharmony_ci attr->ptr_attr.len)) 8028c2ecf20Sopenharmony_ci return -EFAULT; 8038c2ecf20Sopenharmony_ci 8048c2ecf20Sopenharmony_ci return 0; 8058c2ecf20Sopenharmony_ci} 8068c2ecf20Sopenharmony_ci 8078c2ecf20Sopenharmony_cistatic inline int _uverbs_copy_from_or_zero(void *to, 8088c2ecf20Sopenharmony_ci const struct uverbs_attr_bundle *attrs_bundle, 8098c2ecf20Sopenharmony_ci size_t idx, 8108c2ecf20Sopenharmony_ci size_t size) 8118c2ecf20Sopenharmony_ci{ 8128c2ecf20Sopenharmony_ci const struct uverbs_attr *attr = uverbs_attr_get(attrs_bundle, idx); 8138c2ecf20Sopenharmony_ci size_t min_size; 8148c2ecf20Sopenharmony_ci 8158c2ecf20Sopenharmony_ci if (IS_ERR(attr)) 8168c2ecf20Sopenharmony_ci return PTR_ERR(attr); 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_ci min_size = min_t(size_t, size, attr->ptr_attr.len); 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_ci if (uverbs_attr_ptr_is_inline(attr)) 8218c2ecf20Sopenharmony_ci memcpy(to, &attr->ptr_attr.data, min_size); 8228c2ecf20Sopenharmony_ci else if (copy_from_user(to, u64_to_user_ptr(attr->ptr_attr.data), 8238c2ecf20Sopenharmony_ci min_size)) 8248c2ecf20Sopenharmony_ci return -EFAULT; 8258c2ecf20Sopenharmony_ci 8268c2ecf20Sopenharmony_ci if (size > min_size) 8278c2ecf20Sopenharmony_ci memset(to + min_size, 0, size - min_size); 8288c2ecf20Sopenharmony_ci 8298c2ecf20Sopenharmony_ci return 0; 8308c2ecf20Sopenharmony_ci} 8318c2ecf20Sopenharmony_ci 8328c2ecf20Sopenharmony_ci#define uverbs_copy_from(to, attrs_bundle, idx) \ 8338c2ecf20Sopenharmony_ci _uverbs_copy_from(to, attrs_bundle, idx, sizeof(*to)) 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ci#define uverbs_copy_from_or_zero(to, attrs_bundle, idx) \ 8368c2ecf20Sopenharmony_ci _uverbs_copy_from_or_zero(to, attrs_bundle, idx, sizeof(*to)) 8378c2ecf20Sopenharmony_ci 8388c2ecf20Sopenharmony_cistatic inline struct ib_ucontext * 8398c2ecf20Sopenharmony_ciib_uverbs_get_ucontext(const struct uverbs_attr_bundle *attrs) 8408c2ecf20Sopenharmony_ci{ 8418c2ecf20Sopenharmony_ci return ib_uverbs_get_ucontext_file(attrs->ufile); 8428c2ecf20Sopenharmony_ci} 8438c2ecf20Sopenharmony_ci 8448c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS) 8458c2ecf20Sopenharmony_ciint uverbs_get_flags64(u64 *to, const struct uverbs_attr_bundle *attrs_bundle, 8468c2ecf20Sopenharmony_ci size_t idx, u64 allowed_bits); 8478c2ecf20Sopenharmony_ciint uverbs_get_flags32(u32 *to, const struct uverbs_attr_bundle *attrs_bundle, 8488c2ecf20Sopenharmony_ci size_t idx, u64 allowed_bits); 8498c2ecf20Sopenharmony_ciint uverbs_copy_to(const struct uverbs_attr_bundle *attrs_bundle, size_t idx, 8508c2ecf20Sopenharmony_ci const void *from, size_t size); 8518c2ecf20Sopenharmony_ci__malloc void *_uverbs_alloc(struct uverbs_attr_bundle *bundle, size_t size, 8528c2ecf20Sopenharmony_ci gfp_t flags); 8538c2ecf20Sopenharmony_ci 8548c2ecf20Sopenharmony_cistatic inline __malloc void *uverbs_alloc(struct uverbs_attr_bundle *bundle, 8558c2ecf20Sopenharmony_ci size_t size) 8568c2ecf20Sopenharmony_ci{ 8578c2ecf20Sopenharmony_ci return _uverbs_alloc(bundle, size, GFP_KERNEL); 8588c2ecf20Sopenharmony_ci} 8598c2ecf20Sopenharmony_ci 8608c2ecf20Sopenharmony_cistatic inline __malloc void *uverbs_zalloc(struct uverbs_attr_bundle *bundle, 8618c2ecf20Sopenharmony_ci size_t size) 8628c2ecf20Sopenharmony_ci{ 8638c2ecf20Sopenharmony_ci return _uverbs_alloc(bundle, size, GFP_KERNEL | __GFP_ZERO); 8648c2ecf20Sopenharmony_ci} 8658c2ecf20Sopenharmony_ci 8668c2ecf20Sopenharmony_cistatic inline __malloc void *uverbs_kcalloc(struct uverbs_attr_bundle *bundle, 8678c2ecf20Sopenharmony_ci size_t n, size_t size) 8688c2ecf20Sopenharmony_ci{ 8698c2ecf20Sopenharmony_ci size_t bytes; 8708c2ecf20Sopenharmony_ci 8718c2ecf20Sopenharmony_ci if (unlikely(check_mul_overflow(n, size, &bytes))) 8728c2ecf20Sopenharmony_ci return ERR_PTR(-EOVERFLOW); 8738c2ecf20Sopenharmony_ci return uverbs_zalloc(bundle, bytes); 8748c2ecf20Sopenharmony_ci} 8758c2ecf20Sopenharmony_ciint _uverbs_get_const(s64 *to, const struct uverbs_attr_bundle *attrs_bundle, 8768c2ecf20Sopenharmony_ci size_t idx, s64 lower_bound, u64 upper_bound, 8778c2ecf20Sopenharmony_ci s64 *def_val); 8788c2ecf20Sopenharmony_ciint uverbs_copy_to_struct_or_zero(const struct uverbs_attr_bundle *bundle, 8798c2ecf20Sopenharmony_ci size_t idx, const void *from, size_t size); 8808c2ecf20Sopenharmony_ci#else 8818c2ecf20Sopenharmony_cistatic inline int 8828c2ecf20Sopenharmony_ciuverbs_get_flags64(u64 *to, const struct uverbs_attr_bundle *attrs_bundle, 8838c2ecf20Sopenharmony_ci size_t idx, u64 allowed_bits) 8848c2ecf20Sopenharmony_ci{ 8858c2ecf20Sopenharmony_ci return -EINVAL; 8868c2ecf20Sopenharmony_ci} 8878c2ecf20Sopenharmony_cistatic inline int 8888c2ecf20Sopenharmony_ciuverbs_get_flags32(u32 *to, const struct uverbs_attr_bundle *attrs_bundle, 8898c2ecf20Sopenharmony_ci size_t idx, u64 allowed_bits) 8908c2ecf20Sopenharmony_ci{ 8918c2ecf20Sopenharmony_ci return -EINVAL; 8928c2ecf20Sopenharmony_ci} 8938c2ecf20Sopenharmony_cistatic inline int uverbs_copy_to(const struct uverbs_attr_bundle *attrs_bundle, 8948c2ecf20Sopenharmony_ci size_t idx, const void *from, size_t size) 8958c2ecf20Sopenharmony_ci{ 8968c2ecf20Sopenharmony_ci return -EINVAL; 8978c2ecf20Sopenharmony_ci} 8988c2ecf20Sopenharmony_cistatic inline __malloc void *uverbs_alloc(struct uverbs_attr_bundle *bundle, 8998c2ecf20Sopenharmony_ci size_t size) 9008c2ecf20Sopenharmony_ci{ 9018c2ecf20Sopenharmony_ci return ERR_PTR(-EINVAL); 9028c2ecf20Sopenharmony_ci} 9038c2ecf20Sopenharmony_cistatic inline __malloc void *uverbs_zalloc(struct uverbs_attr_bundle *bundle, 9048c2ecf20Sopenharmony_ci size_t size) 9058c2ecf20Sopenharmony_ci{ 9068c2ecf20Sopenharmony_ci return ERR_PTR(-EINVAL); 9078c2ecf20Sopenharmony_ci} 9088c2ecf20Sopenharmony_cistatic inline int 9098c2ecf20Sopenharmony_ci_uverbs_get_const(s64 *to, const struct uverbs_attr_bundle *attrs_bundle, 9108c2ecf20Sopenharmony_ci size_t idx, s64 lower_bound, u64 upper_bound, 9118c2ecf20Sopenharmony_ci s64 *def_val) 9128c2ecf20Sopenharmony_ci{ 9138c2ecf20Sopenharmony_ci return -EINVAL; 9148c2ecf20Sopenharmony_ci} 9158c2ecf20Sopenharmony_cistatic inline int 9168c2ecf20Sopenharmony_ciuverbs_copy_to_struct_or_zero(const struct uverbs_attr_bundle *bundle, 9178c2ecf20Sopenharmony_ci size_t idx, const void *from, size_t size) 9188c2ecf20Sopenharmony_ci{ 9198c2ecf20Sopenharmony_ci return -EINVAL; 9208c2ecf20Sopenharmony_ci} 9218c2ecf20Sopenharmony_ci#endif 9228c2ecf20Sopenharmony_ci 9238c2ecf20Sopenharmony_ci#define uverbs_get_const(_to, _attrs_bundle, _idx) \ 9248c2ecf20Sopenharmony_ci ({ \ 9258c2ecf20Sopenharmony_ci s64 _val; \ 9268c2ecf20Sopenharmony_ci int _ret = _uverbs_get_const(&_val, _attrs_bundle, _idx, \ 9278c2ecf20Sopenharmony_ci type_min(typeof(*_to)), \ 9288c2ecf20Sopenharmony_ci type_max(typeof(*_to)), NULL); \ 9298c2ecf20Sopenharmony_ci (*_to) = _val; \ 9308c2ecf20Sopenharmony_ci _ret; \ 9318c2ecf20Sopenharmony_ci }) 9328c2ecf20Sopenharmony_ci 9338c2ecf20Sopenharmony_ci#define uverbs_get_const_default(_to, _attrs_bundle, _idx, _default) \ 9348c2ecf20Sopenharmony_ci ({ \ 9358c2ecf20Sopenharmony_ci s64 _val; \ 9368c2ecf20Sopenharmony_ci s64 _def_val = _default; \ 9378c2ecf20Sopenharmony_ci int _ret = \ 9388c2ecf20Sopenharmony_ci _uverbs_get_const(&_val, _attrs_bundle, _idx, \ 9398c2ecf20Sopenharmony_ci type_min(typeof(*_to)), \ 9408c2ecf20Sopenharmony_ci type_max(typeof(*_to)), &_def_val); \ 9418c2ecf20Sopenharmony_ci (*_to) = _val; \ 9428c2ecf20Sopenharmony_ci _ret; \ 9438c2ecf20Sopenharmony_ci }) 9448c2ecf20Sopenharmony_ci#endif 945