libibverbs: Add per-buffer UMEM helper The new umem UAPI gives every dmabuf-backed buffer (CQ ring, QP main/RQ/SQ, mlx5 doorbell record) its own ioctl attribute of type UVERBS_ATTR_UMEM whose payload is a single struct ib_uverbs_buffer_desc. Add a per-attribute helper, fill_attr_in_buf_umem(), that providers call once per buffer they want to register through the kernel. Signed-off-by: Jiri Pirko <jiri@nvidia.com>
diff --git a/libibverbs/driver.h b/libibverbs/driver.h index e7f420b..d6ad390 100644 --- a/libibverbs/driver.h +++ b/libibverbs/driver.h
@@ -44,6 +44,7 @@ #include <config.h> #include <stdbool.h> #include <rdma/rdma_user_ioctl_cmds.h> +#include <rdma/ib_user_ioctl_verbs.h> #include <infiniband/cmd_ioctl.h> #include <sys/types.h> @@ -830,4 +831,25 @@ parent_domain->handle = contained_pd->handle; } +/** + * In case the length is 0, the buffer size is used. + */ +static inline void +fill_attr_in_buf_umem(struct ibv_command_buffer *cmdb, uint16_t attr_id, + struct ib_uverbs_buffer_desc *storage, + struct ibv_buf *buf, void *addr, size_t length) +{ + if (!buf || buf->dmabuf_fd == -1) + return; + + *storage = (struct ib_uverbs_buffer_desc){ + .type = IB_UVERBS_BUFFER_TYPE_DMABUF, + .fd = buf->dmabuf_fd, + .addr = addr ? (uintptr_t)addr - (uintptr_t)buf->addr : 0, + .length = length ? length : buf->size, + }; + fill_attr_in_ptr(cmdb, attr_id, storage); + cmdb->fallback_ioctl_only = 1; +} + #endif /* INFINIBAND_DRIVER_H */