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