1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB 2 /* 3 * Copyright (c) 2019, Mellanox Technologies inc. All rights reserved. 4 */ 5 6 #include <rdma/uverbs_std_types.h> 7 #include <rdma/uverbs_ioctl.h> 8 #include "rdma_core.h" 9 #include "uverbs.h" 10 11 #include <sys/fcntl.h> 12 13 static int UVERBS_HANDLER(UVERBS_METHOD_ASYNC_EVENT_ALLOC)( 14 struct uverbs_attr_bundle *attrs) 15 { 16 struct ib_uobject *uobj = 17 uverbs_attr_get_uobject(attrs, UVERBS_METHOD_ASYNC_EVENT_ALLOC); 18 19 ib_uverbs_init_async_event_file( 20 container_of(uobj, struct ib_uverbs_async_event_file, uobj)); 21 return 0; 22 } 23 24 static int uverbs_async_event_destroy_uobj(struct ib_uobject *uobj, 25 enum rdma_remove_reason why) 26 { 27 struct ib_uverbs_async_event_file *event_file = 28 container_of(uobj, struct ib_uverbs_async_event_file, uobj); 29 30 ib_unregister_event_handler(&event_file->event_handler); 31 ib_uverbs_free_event_queue(&event_file->ev_queue); 32 return 0; 33 } 34 35 DECLARE_UVERBS_NAMED_METHOD( 36 UVERBS_METHOD_ASYNC_EVENT_ALLOC, 37 UVERBS_ATTR_FD(UVERBS_ATTR_ASYNC_EVENT_ALLOC_FD_HANDLE, 38 UVERBS_OBJECT_ASYNC_EVENT, 39 UVERBS_ACCESS_NEW, 40 UA_MANDATORY)); 41 42 DECLARE_UVERBS_NAMED_OBJECT( 43 UVERBS_OBJECT_ASYNC_EVENT, 44 UVERBS_TYPE_ALLOC_FD(sizeof(struct ib_uverbs_async_event_file), 45 uverbs_async_event_destroy_uobj, 46 &uverbs_async_event_fops, 47 "[infinibandevent]", 48 FMODE_READ), 49 &UVERBS_METHOD(UVERBS_METHOD_ASYNC_EVENT_ALLOC)); 50 51 const struct uapi_definition uverbs_def_obj_async_fd[] = { 52 UAPI_DEF_CHAIN_OBJ_TREE_NAMED(UVERBS_OBJECT_ASYNC_EVENT), 53 {} 54 }; 55