rdma_netlink.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _RDMA_NETLINK_H
  3. #define _RDMA_NETLINK_H
  4. #include <linux/netlink.h>
  5. #include <uapi/rdma/rdma_netlink.h>
  6. struct ib_device;
  7. enum {
  8. RDMA_NLDEV_ATTR_EMPTY_STRING = 1,
  9. RDMA_NLDEV_ATTR_ENTRY_STRLEN = 16,
  10. RDMA_NLDEV_ATTR_CHARDEV_TYPE_SIZE = 32,
  11. };
  12. struct rdma_nl_cbs {
  13. int (*doit)(struct sk_buff *skb, struct nlmsghdr *nlh,
  14. struct netlink_ext_ack *extack);
  15. int (*dump)(struct sk_buff *skb, struct netlink_callback *nlcb);
  16. u8 flags;
  17. };
  18. enum rdma_nl_flags {
  19. /* Require CAP_NET_ADMIN */
  20. RDMA_NL_ADMIN_PERM = 1 << 0,
  21. };
  22. /* Define this module as providing netlink services for NETLINK_RDMA, with
  23. * index _index. Since the client indexes were setup in a uapi header as an
  24. * enum and we do no want to change that, the user must supply the expanded
  25. * constant as well and the compiler checks they are the same.
  26. */
  27. #define MODULE_ALIAS_RDMA_NETLINK(_index, _val) \
  28. static inline void __maybe_unused __chk_##_index(void) \
  29. { \
  30. BUILD_BUG_ON(_index != _val); \
  31. } \
  32. MODULE_ALIAS("rdma-netlink-subsys-" __stringify(_val))
  33. /**
  34. * Register client in RDMA netlink.
  35. * @index: Index of the added client
  36. * @cb_table: A table for op->callback
  37. */
  38. void rdma_nl_register(unsigned int index,
  39. const struct rdma_nl_cbs cb_table[]);
  40. /**
  41. * Remove a client from IB netlink.
  42. * @index: Index of the removed IB client.
  43. */
  44. void rdma_nl_unregister(unsigned int index);
  45. /**
  46. * Put a new message in a supplied skb.
  47. * @skb: The netlink skb.
  48. * @nlh: Pointer to put the header of the new netlink message.
  49. * @seq: The message sequence number.
  50. * @len: The requested message length to allocate.
  51. * @client: Calling IB netlink client.
  52. * @op: message content op.
  53. * Returns the allocated buffer on success and NULL on failure.
  54. */
  55. void *ibnl_put_msg(struct sk_buff *skb, struct nlmsghdr **nlh, int seq,
  56. int len, int client, int op, int flags);
  57. /**
  58. * Put a new attribute in a supplied skb.
  59. * @skb: The netlink skb.
  60. * @nlh: Header of the netlink message to append the attribute to.
  61. * @len: The length of the attribute data.
  62. * @data: The attribute data to put.
  63. * @type: The attribute type.
  64. * Returns the 0 and a negative error code on failure.
  65. */
  66. int ibnl_put_attr(struct sk_buff *skb, struct nlmsghdr *nlh,
  67. int len, void *data, int type);
  68. /**
  69. * Send the supplied skb to a specific userspace PID.
  70. * @net: Net namespace in which to send the skb
  71. * @skb: The netlink skb
  72. * @pid: Userspace netlink process ID
  73. * Returns 0 on success or a negative error code.
  74. */
  75. int rdma_nl_unicast(struct net *net, struct sk_buff *skb, u32 pid);
  76. /**
  77. * Send, with wait/1 retry, the supplied skb to a specific userspace PID.
  78. * @net: Net namespace in which to send the skb
  79. * @skb: The netlink skb
  80. * @pid: Userspace netlink process ID
  81. * Returns 0 on success or a negative error code.
  82. */
  83. int rdma_nl_unicast_wait(struct net *net, struct sk_buff *skb, __u32 pid);
  84. /**
  85. * Send the supplied skb to a netlink group.
  86. * @net: Net namespace in which to send the skb
  87. * @skb: The netlink skb
  88. * @group: Netlink group ID
  89. * @flags: allocation flags
  90. * Returns 0 on success or a negative error code.
  91. */
  92. int rdma_nl_multicast(struct net *net, struct sk_buff *skb,
  93. unsigned int group, gfp_t flags);
  94. /**
  95. * Check if there are any listeners to the netlink group
  96. * @group: the netlink group ID
  97. * Returns true on success or false if no listeners.
  98. */
  99. bool rdma_nl_chk_listeners(unsigned int group);
  100. /**
  101. * Prepare and send an event message
  102. * @ib: the IB device which triggered the event
  103. * @port_num: the port number which triggered the event - 0 if unused
  104. * @type: the event type
  105. * Returns 0 on success or a negative error code
  106. */
  107. int rdma_nl_notify_event(struct ib_device *ib, u32 port_num,
  108. enum rdma_nl_notify_event_type type);
  109. struct rdma_link_ops {
  110. struct list_head list;
  111. const char *type;
  112. int (*newlink)(const char *ibdev_name, struct net_device *ndev);
  113. };
  114. void rdma_link_register(struct rdma_link_ops *ops);
  115. void rdma_link_unregister(struct rdma_link_ops *ops);
  116. #define MODULE_ALIAS_RDMA_LINK(type) MODULE_ALIAS("rdma-link-" type)
  117. #define MODULE_ALIAS_RDMA_CLIENT(type) MODULE_ALIAS("rdma-client-" type)
  118. #endif /* _RDMA_NETLINK_H */