rdma_netlink.h 4.0 KB

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