uverbs_named_ioctl.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2018, Mellanox Technologies inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #ifndef _UVERBS_NAMED_IOCTL_
  33. #define _UVERBS_NAMED_IOCTL_
  34. #include <rdma/uverbs_ioctl.h>
  35. #ifndef UVERBS_MODULE_NAME
  36. #error "Please #define UVERBS_MODULE_NAME before including rdma/uverbs_named_ioctl.h"
  37. #endif
  38. #define _UVERBS_PASTE(x, y) x ## y
  39. #define _UVERBS_NAME(x, y) _UVERBS_PASTE(x, y)
  40. #define UVERBS_METHOD(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _method_##id)
  41. #define UVERBS_HANDLER(id) _UVERBS_NAME(UVERBS_MODULE_NAME, _handler_##id)
  42. #define DECLARE_UVERBS_NAMED_METHOD(id, ...) \
  43. DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, UVERBS_HANDLER(id), ##__VA_ARGS__)
  44. #define DECLARE_UVERBS_NAMED_METHOD_WITH_HANDLER(id, handler, ...) \
  45. DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, handler, ##__VA_ARGS__)
  46. #define DECLARE_UVERBS_NAMED_METHOD_NO_OVERRIDE(id, handler, ...) \
  47. DECLARE_UVERBS_METHOD(UVERBS_METHOD(id), id, NULL, ##__VA_ARGS__)
  48. #define DECLARE_UVERBS_NAMED_OBJECT(id, ...) \
  49. DECLARE_UVERBS_OBJECT(UVERBS_OBJECT(id), id, ##__VA_ARGS__)
  50. #define _UVERBS_COMP_NAME(x, y, z) _UVERBS_NAME(_UVERBS_NAME(x, y), z)
  51. #define UVERBS_NO_OVERRIDE NULL
  52. /* This declares a parsing tree with one object and one method. This is usually
  53. * used for merging driver attributes to the common attributes. The driver has
  54. * a chance to override the handler and type attrs of the original object.
  55. * The __VA_ARGS__ just contains a list of attributes.
  56. */
  57. #define ADD_UVERBS_ATTRIBUTES(_name, _object, _method, _type_attrs, _handler, ...) \
  58. static DECLARE_UVERBS_METHOD(_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \
  59. _method_, _name), \
  60. _method, _handler, ##__VA_ARGS__); \
  61. \
  62. static DECLARE_UVERBS_OBJECT(_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \
  63. _object_, _name), \
  64. _object, _type_attrs, \
  65. &_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \
  66. _method_, _name)); \
  67. \
  68. static DECLARE_UVERBS_OBJECT_TREE(_name, \
  69. &_UVERBS_COMP_NAME(UVERBS_MODULE_NAME, \
  70. _object_, _name))
  71. /* A very common use case is that the driver doesn't override the handler and
  72. * type_attrs. Therefore, we provide a simplified macro for this common case.
  73. */
  74. #define ADD_UVERBS_ATTRIBUTES_SIMPLE(_name, _object, _method, ...) \
  75. ADD_UVERBS_ATTRIBUTES(_name, _object, _method, UVERBS_NO_OVERRIDE, \
  76. UVERBS_NO_OVERRIDE, ##__VA_ARGS__)
  77. #endif