linux/include/rdma/uverbs_ioctl.h

/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
/*
 * Copyright (c) 2017, Mellanox Technologies inc.  All rights reserved.
 */

#ifndef _UVERBS_IOCTL_
#define _UVERBS_IOCTL_

#include <rdma/uverbs_types.h>
#include <linux/uaccess.h>
#include <rdma/rdma_user_ioctl.h>
#include <rdma/ib_user_ioctl_verbs.h>
#include <rdma/ib_user_ioctl_cmds.h>

/*
 * =======================================
 *	Verbs action specifications
 * =======================================
 */

enum uverbs_attr_type {};

enum uverbs_obj_access {};

/* Specification of a single attribute inside the ioctl message */
/* good size 16 */
struct uverbs_attr_spec {};

/*
 * Information about the API is loaded into a radix tree. For IOCTL we start
 * with a tuple of:
 *  object_id, attr_id, method_id
 *
 * Which is a 48 bit value, with most of the bits guaranteed to be zero. Based
 * on the current kernel support this is compressed into 16 bit key for the
 * radix tree. Since this compression is entirely internal to the kernel the
 * below limits can be revised if the kernel gains additional data.
 *
 * With 64 leafs per node this is a 3 level radix tree.
 *
 * The tree encodes multiple types, and uses a scheme where OBJ_ID,0,0 returns
 * the object slot, and OBJ_ID,METH_ID,0 and returns the method slot.
 *
 * This also encodes the tables for the write() and write() extended commands
 * using the coding
 *   OBJ_ID,UVERBS_API_METHOD_IS_WRITE,command #
 *   OBJ_ID,UVERBS_API_METHOD_IS_WRITE_EX,command_ex #
 * ie the WRITE path is treated as a special method type in the ioctl
 * framework.
 */
enum uapi_radix_data {};

static inline __attribute_const__ u32 uapi_key_obj(u32 id)
{}

static inline __attribute_const__ bool uapi_key_is_object(u32 key)
{}

static inline __attribute_const__ u32 uapi_key_ioctl_method(u32 id)
{}

static inline __attribute_const__ u32 uapi_key_write_method(u32 id)
{}

static inline __attribute_const__ u32 uapi_key_write_ex_method(u32 id)
{}

static inline __attribute_const__ u32
uapi_key_attr_to_ioctl_method(u32 attr_key)
{}

static inline __attribute_const__ bool uapi_key_is_ioctl_method(u32 key)
{}

static inline __attribute_const__ bool uapi_key_is_write_method(u32 key)
{}

static inline __attribute_const__ bool uapi_key_is_write_ex_method(u32 key)
{}

static inline __attribute_const__ u32 uapi_key_attrs_start(u32 ioctl_method_key)
{}

static inline __attribute_const__ u32 uapi_key_attr(u32 id)
{}

/* Only true for ioctl methods */
static inline __attribute_const__ bool uapi_key_is_attr(u32 key)
{}

/*
 * This returns a value in the range [0 to UVERBS_API_ATTR_BKEY_LEN),
 * basically it undoes the reservation of 0 in the ID numbering. attr_key
 * must already be masked with UVERBS_API_ATTR_KEY_MASK, or be the output of
 * uapi_key_attr().
 */
static inline __attribute_const__ u32 uapi_bkey_attr(u32 attr_key)
{}

static inline __attribute_const__ u32 uapi_bkey_to_key_attr(u32 attr_bkey)
{}

/*
 * =======================================
 *	Verbs definitions
 * =======================================
 */

struct uverbs_attr_def {};

struct uverbs_method_def {};

struct uverbs_object_def {};

enum uapi_definition_kind {};

enum uapi_definition_scope {};

struct uapi_definition {};

/* Define things connected to object_id */
#define DECLARE_UVERBS_OBJECT(_object_id, ...)

/* Use in a var_args of DECLARE_UVERBS_OBJECT */
#define DECLARE_UVERBS_WRITE(_command_num, _func, _cmd_desc, ...)

/* Use in a var_args of DECLARE_UVERBS_OBJECT */
#define DECLARE_UVERBS_WRITE_EX(_command_num, _func, _cmd_desc, ...)

/*
 * Object is only supported if the function pointer named ibdev_fn in struct
 * ib_device is not NULL.
 */
#define UAPI_DEF_OBJ_NEEDS_FN(ibdev_fn)

/*
 * Method is only supported if the function pointer named ibdev_fn in struct
 * ib_device is not NULL.
 */
#define UAPI_DEF_METHOD_NEEDS_FN(ibdev_fn)

/* Call a function to determine if the entire object is supported or not */
#define UAPI_DEF_IS_OBJ_SUPPORTED(_func)

/* Include another struct uapi_definition in this one */
#define UAPI_DEF_CHAIN(_def_var)

/* Temporary until the tree base description is replaced */
#define UAPI_DEF_CHAIN_OBJ_TREE(_object_enum, _object_ptr, ...)
#define UAPI_DEF_CHAIN_OBJ_TREE_NAMED(_object_enum, ...)

/*
 * =======================================
 *	Attribute Specifications
 * =======================================
 */

#define UVERBS_ATTR_SIZE(_min_len, _len)

#define UVERBS_ATTR_NO_DATA()

/*
 * Specifies a uapi structure that cannot be extended. The user must always
 * supply the whole structure and nothing more. The structure must be declared
 * in a header under include/uapi/rdma.
 */
#define UVERBS_ATTR_TYPE(_type)
/*
 * Specifies a uapi structure where the user must provide at least up to
 * member 'last'.  Anything after last and up until the end of the structure
 * can be non-zero, anything longer than the end of the structure must be
 * zero. The structure must be declared in a header under include/uapi/rdma.
 */
#define UVERBS_ATTR_STRUCT(_type, _last)
/*
 * Specifies at least min_len bytes must be passed in, but the amount can be
 * larger, up to the protocol maximum size. No check for zeroing is done.
 */
#define UVERBS_ATTR_MIN_SIZE(_min_len)

/* Must be used in the '...' of any UVERBS_ATTR */
#define UA_ALLOC_AND_COPY
#define UA_MANDATORY
#define UA_OPTIONAL

/*
 * min_len must be bigger than 0 and _max_len must be smaller than 4095.  Only
 * READ\WRITE accesses are supported.
 */
#define UVERBS_ATTR_IDRS_ARR(_attr_id, _idr_type, _access, _min_len, _max_len, \
			     ...)

/*
 * Only for use with UVERBS_ATTR_IDR, allows any uobject type to be accepted,
 * the user must validate the type of the uobject instead.
 */
#define UVERBS_IDR_ANY_OBJECT

#define UVERBS_ATTR_IDR(_attr_id, _idr_type, _access, ...)

#define UVERBS_ATTR_FD(_attr_id, _fd_type, _access, ...)

#define UVERBS_ATTR_RAW_FD(_attr_id, ...)

#define UVERBS_ATTR_PTR_IN(_attr_id, _type, ...)

#define UVERBS_ATTR_PTR_OUT(_attr_id, _type, ...)

/* _enum_arry should be a 'static const union uverbs_attr_spec[]' */
#define UVERBS_ATTR_ENUM_IN(_attr_id, _enum_arr, ...)

/* An input value that is a member in the enum _enum_type. */
#define UVERBS_ATTR_CONST_IN(_attr_id, _enum_type, ...)

/*
 * An input value that is a bitwise combination of values of _enum_type.
 * This permits the flag value to be passed as either a u32 or u64, it must
 * be retrieved via uverbs_get_flag().
 */
#define UVERBS_ATTR_FLAGS_IN(_attr_id, _enum_type, ...)

/*
 * This spec is used in order to pass information to the hardware driver in a
 * legacy way. Every verb that could get driver specific data should get this
 * spec.
 */
#define UVERBS_ATTR_UHW()

/* =================================================
 *              Parsing infrastructure
 * =================================================
 */


struct uverbs_ptr_attr {};

struct uverbs_obj_attr {};

struct uverbs_objs_arr_attr {};

struct uverbs_attr {};

struct uverbs_attr_bundle {};

static inline bool uverbs_attr_is_valid(const struct uverbs_attr_bundle *attrs_bundle,
					unsigned int idx)
{}

/**
 * rdma_udata_to_drv_context - Helper macro to get the driver's context out of
 *                             ib_udata which is embedded in uverbs_attr_bundle.
 *
 * If udata is not NULL this cannot fail. Otherwise a NULL udata will result
 * in a NULL ucontext pointer, as a safety precaution. Callers should be using
 * 'udata' to determine if the driver call is in user or kernel mode, not
 * 'ucontext'.
 *
 */
static inline struct uverbs_attr_bundle *
rdma_udata_to_uverbs_attr_bundle(struct ib_udata *udata)
{}

#define rdma_udata_to_drv_context(udata, drv_dev_struct, member)

#define IS_UVERBS_COPY_ERR(_ret)

static inline const struct uverbs_attr *uverbs_attr_get(const struct uverbs_attr_bundle *attrs_bundle,
							u16 idx)
{}

static inline int uverbs_attr_get_enum_id(const struct uverbs_attr_bundle *attrs_bundle,
					  u16 idx)
{}

static inline void *uverbs_attr_get_obj(const struct uverbs_attr_bundle *attrs_bundle,
					u16 idx)
{}

static inline struct ib_uobject *uverbs_attr_get_uobject(const struct uverbs_attr_bundle *attrs_bundle,
							 u16 idx)
{}

static inline int
uverbs_attr_get_len(const struct uverbs_attr_bundle *attrs_bundle, u16 idx)
{}

void uverbs_finalize_uobj_create(const struct uverbs_attr_bundle *attrs_bundle,
				 u16 idx);

/*
 * uverbs_attr_ptr_get_array_size() - Get array size pointer by a ptr
 * attribute.
 * @attrs: The attribute bundle
 * @idx: The ID of the attribute
 * @elem_size: The size of the element in the array
 */
static inline int
uverbs_attr_ptr_get_array_size(struct uverbs_attr_bundle *attrs, u16 idx,
			       size_t elem_size)
{}

/**
 * uverbs_attr_get_uobjs_arr() - Provides array's properties for attribute for
 * UVERBS_ATTR_TYPE_IDRS_ARRAY.
 * @arr: Returned pointer to array of pointers for uobjects or NULL if
 *       the attribute isn't provided.
 *
 * Return: The array length or 0 if no attribute was provided.
 */
static inline int uverbs_attr_get_uobjs_arr(
	const struct uverbs_attr_bundle *attrs_bundle, u16 attr_idx,
	struct ib_uobject ***arr)
{}

static inline bool uverbs_attr_ptr_is_inline(const struct uverbs_attr *attr)
{}

static inline void *uverbs_attr_get_alloced_ptr(
	const struct uverbs_attr_bundle *attrs_bundle, u16 idx)
{}

static inline int _uverbs_copy_from(void *to,
				    const struct uverbs_attr_bundle *attrs_bundle,
				    size_t idx,
				    size_t size)
{}

static inline int _uverbs_copy_from_or_zero(void *to,
					    const struct uverbs_attr_bundle *attrs_bundle,
					    size_t idx,
					    size_t size)
{}

#define uverbs_copy_from(to, attrs_bundle, idx)

#define uverbs_copy_from_or_zero(to, attrs_bundle, idx)

static inline struct ib_ucontext *
ib_uverbs_get_ucontext(const struct uverbs_attr_bundle *attrs)
{}

#if IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS)
int uverbs_get_flags64(u64 *to, const struct uverbs_attr_bundle *attrs_bundle,
		       size_t idx, u64 allowed_bits);
int uverbs_get_flags32(u32 *to, const struct uverbs_attr_bundle *attrs_bundle,
		       size_t idx, u64 allowed_bits);
int uverbs_copy_to(const struct uverbs_attr_bundle *attrs_bundle, size_t idx,
		   const void *from, size_t size);
__malloc void *_uverbs_alloc(struct uverbs_attr_bundle *bundle, size_t size,
			     gfp_t flags);

static inline __malloc void *uverbs_alloc(struct uverbs_attr_bundle *bundle,
					  size_t size)
{}

static inline __malloc void *uverbs_zalloc(struct uverbs_attr_bundle *bundle,
					   size_t size)
{}

static inline __malloc void *uverbs_kcalloc(struct uverbs_attr_bundle *bundle,
					    size_t n, size_t size)
{}

int _uverbs_get_const_signed(s64 *to,
			     const struct uverbs_attr_bundle *attrs_bundle,
			     size_t idx, s64 lower_bound, u64 upper_bound,
			     s64 *def_val);
int _uverbs_get_const_unsigned(u64 *to,
			       const struct uverbs_attr_bundle *attrs_bundle,
			       size_t idx, u64 upper_bound, u64 *def_val);
int uverbs_copy_to_struct_or_zero(const struct uverbs_attr_bundle *bundle,
				  size_t idx, const void *from, size_t size);
#else
static inline int
uverbs_get_flags64(u64 *to, const struct uverbs_attr_bundle *attrs_bundle,
		   size_t idx, u64 allowed_bits)
{
	return -EINVAL;
}
static inline int
uverbs_get_flags32(u32 *to, const struct uverbs_attr_bundle *attrs_bundle,
		   size_t idx, u64 allowed_bits)
{
	return -EINVAL;
}
static inline int uverbs_copy_to(const struct uverbs_attr_bundle *attrs_bundle,
				 size_t idx, const void *from, size_t size)
{
	return -EINVAL;
}
static inline __malloc void *uverbs_alloc(struct uverbs_attr_bundle *bundle,
					  size_t size)
{
	return ERR_PTR(-EINVAL);
}
static inline __malloc void *uverbs_zalloc(struct uverbs_attr_bundle *bundle,
					   size_t size)
{
	return ERR_PTR(-EINVAL);
}
static inline int
_uverbs_get_const(s64 *to, const struct uverbs_attr_bundle *attrs_bundle,
		  size_t idx, s64 lower_bound, u64 upper_bound,
		  s64 *def_val)
{
	return -EINVAL;
}
static inline int
uverbs_copy_to_struct_or_zero(const struct uverbs_attr_bundle *bundle,
			      size_t idx, const void *from, size_t size)
{
	return -EINVAL;
}
static inline int
_uverbs_get_const_signed(s64 *to,
			 const struct uverbs_attr_bundle *attrs_bundle,
			 size_t idx, s64 lower_bound, u64 upper_bound,
			 s64 *def_val)
{
	return -EINVAL;
}
static inline int
_uverbs_get_const_unsigned(u64 *to,
			   const struct uverbs_attr_bundle *attrs_bundle,
			   size_t idx, u64 upper_bound, u64 *def_val)
{
	return -EINVAL;
}
#endif

#define uverbs_get_const_signed(_to, _attrs_bundle, _idx)

#define uverbs_get_const_unsigned(_to, _attrs_bundle, _idx)

#define uverbs_get_const_default_signed(_to, _attrs_bundle, _idx, _default)

#define uverbs_get_const_default_unsigned(_to, _attrs_bundle, _idx, _default)

#define uverbs_get_const(_to, _attrs_bundle, _idx)          \

#define uverbs_get_const_default(_to, _attrs_bundle, _idx, _default)

static inline int
uverbs_get_raw_fd(int *to, const struct uverbs_attr_bundle *attrs_bundle,
		  size_t idx)
{}

#endif