rdma_core.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (c) 2005 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
  4. * Copyright (c) 2005-2017 Mellanox Technologies. All rights reserved.
  5. * Copyright (c) 2005 Voltaire, Inc. All rights reserved.
  6. * Copyright (c) 2005 PathScale, Inc. All rights reserved.
  7. *
  8. * This software is available to you under a choice of one of two
  9. * licenses. You may choose to be licensed under the terms of the GNU
  10. * General Public License (GPL) Version 2, available from the file
  11. * COPYING in the main directory of this source tree, or the
  12. * OpenIB.org BSD license below:
  13. *
  14. * Redistribution and use in source and binary forms, with or
  15. * without modification, are permitted provided that the following
  16. * conditions are met:
  17. *
  18. * - Redistributions of source code must retain the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer.
  21. *
  22. * - Redistributions in binary form must reproduce the above
  23. * copyright notice, this list of conditions and the following
  24. * disclaimer in the documentation and/or other materials
  25. * provided with the distribution.
  26. *
  27. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  28. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  29. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  30. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  31. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  32. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  33. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  34. * SOFTWARE.
  35. */
  36. #ifndef RDMA_CORE_H
  37. #define RDMA_CORE_H
  38. #include <linux/idr.h>
  39. #include <rdma/uverbs_types.h>
  40. #include <rdma/uverbs_ioctl.h>
  41. #include <rdma/ib_verbs.h>
  42. #include <linux/mutex.h>
  43. struct ib_uverbs_device;
  44. void uverbs_destroy_ufile_hw(struct ib_uverbs_file *ufile,
  45. enum rdma_remove_reason reason);
  46. int uobj_destroy(struct ib_uobject *uobj);
  47. /*
  48. * uverbs_uobject_get is called in order to increase the reference count on
  49. * an uobject. This is useful when a handler wants to keep the uobject's memory
  50. * alive, regardless if this uobject is still alive in the context's objects
  51. * repository. Objects are put via uverbs_uobject_put.
  52. */
  53. void uverbs_uobject_get(struct ib_uobject *uobject);
  54. /*
  55. * In order to indicate we no longer needs this uobject, uverbs_uobject_put
  56. * is called. When the reference count is decreased, the uobject is freed.
  57. * For example, this is used when attaching a completion channel to a CQ.
  58. */
  59. void uverbs_uobject_put(struct ib_uobject *uobject);
  60. /* Indicate this fd is no longer used by this consumer, but its memory isn't
  61. * necessarily released yet. When the last reference is put, we release the
  62. * memory. After this call is executed, calling uverbs_uobject_get isn't
  63. * allowed.
  64. * This must be called from the release file_operations of the file!
  65. */
  66. void uverbs_close_fd(struct file *f);
  67. /*
  68. * Get an ib_uobject that corresponds to the given id from ufile, assuming
  69. * the object is from the given type. Lock it to the required access when
  70. * applicable.
  71. * This function could create (access == NEW), destroy (access == DESTROY)
  72. * or unlock (access == READ || access == WRITE) objects if required.
  73. * The action will be finalized only when uverbs_finalize_object or
  74. * uverbs_finalize_objects are called.
  75. */
  76. struct ib_uobject *
  77. uverbs_get_uobject_from_file(u16 object_id,
  78. struct ib_uverbs_file *ufile,
  79. enum uverbs_obj_access access, s64 id);
  80. /*
  81. * Note that certain finalize stages could return a status:
  82. * (a) alloc_commit could return a failure if the object is committed at the
  83. * same time when the context is destroyed.
  84. * (b) remove_commit could fail if the object wasn't destroyed successfully.
  85. * Since multiple objects could be finalized in one transaction, it is very NOT
  86. * recommended to have several finalize actions which have side effects.
  87. * For example, it's NOT recommended to have a certain action which has both
  88. * a commit action and a destroy action or two destroy objects in the same
  89. * action. The rule of thumb is to have one destroy or commit action with
  90. * multiple lookups.
  91. * The first non zero return value of finalize_object is returned from this
  92. * function. For example, this could happen when we couldn't destroy an
  93. * object.
  94. */
  95. int uverbs_finalize_object(struct ib_uobject *uobj,
  96. enum uverbs_obj_access access,
  97. bool commit);
  98. void setup_ufile_idr_uobject(struct ib_uverbs_file *ufile);
  99. void release_ufile_idr_uobject(struct ib_uverbs_file *ufile);
  100. /*
  101. * This is the runtime description of the uverbs API, used by the syscall
  102. * machinery to validate and dispatch calls.
  103. */
  104. /*
  105. * Depending on ID the slot pointer in the radix tree points at one of these
  106. * structs.
  107. */
  108. struct uverbs_api_object {
  109. const struct uverbs_obj_type *type_attrs;
  110. const struct uverbs_obj_type_class *type_class;
  111. };
  112. struct uverbs_api_ioctl_method {
  113. int (__rcu *handler)(struct ib_uverbs_file *ufile,
  114. struct uverbs_attr_bundle *ctx);
  115. DECLARE_BITMAP(attr_mandatory, UVERBS_API_ATTR_BKEY_LEN);
  116. u16 bundle_size;
  117. u8 use_stack:1;
  118. u8 driver_method:1;
  119. u8 key_bitmap_len;
  120. u8 destroy_bkey;
  121. };
  122. struct uverbs_api_attr {
  123. struct uverbs_attr_spec spec;
  124. };
  125. struct uverbs_api_object;
  126. struct uverbs_api {
  127. /* radix tree contains struct uverbs_api_* pointers */
  128. struct radix_tree_root radix;
  129. enum rdma_driver_id driver_id;
  130. };
  131. static inline const struct uverbs_api_object *
  132. uapi_get_object(struct uverbs_api *uapi, u16 object_id)
  133. {
  134. return radix_tree_lookup(&uapi->radix, uapi_key_obj(object_id));
  135. }
  136. char *uapi_key_format(char *S, unsigned int key);
  137. struct uverbs_api *uverbs_alloc_api(
  138. const struct uverbs_object_tree_def *const *driver_specs,
  139. enum rdma_driver_id driver_id);
  140. void uverbs_disassociate_api_pre(struct ib_uverbs_device *uverbs_dev);
  141. void uverbs_disassociate_api(struct uverbs_api *uapi);
  142. void uverbs_destroy_api(struct uverbs_api *uapi);
  143. void uapi_compute_bundle_size(struct uverbs_api_ioctl_method *method_elm,
  144. unsigned int num_attrs);
  145. #endif /* RDMA_CORE_H */