blob: c369703fcd69cd8636f6b2fda8957ac644b28f76 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Roland Dreierb2cbae22011-05-20 11:46:11 -07002#ifndef _RDMA_NETLINK_H
3#define _RDMA_NETLINK_H
4
Roland Dreierb2cbae22011-05-20 11:46:11 -07005
6#include <linux/netlink.h>
David Howells7235aa72012-11-21 15:47:40 +00007#include <uapi/rdma/rdma_netlink.h>
Roland Dreierb2cbae22011-05-20 11:46:11 -07008
Leon Romanovsky3250b4d2017-06-19 18:23:45 +03009struct rdma_nl_cbs {
Leon Romanovsky1830ba22017-06-15 12:46:33 +030010 int (*doit)(struct sk_buff *skb, struct nlmsghdr *nlh,
11 struct netlink_ext_ack *extack);
Roland Dreierb2cbae22011-05-20 11:46:11 -070012 int (*dump)(struct sk_buff *skb, struct netlink_callback *nlcb);
Leon Romanovskye3a2b932017-06-12 16:00:19 +030013 u8 flags;
14};
15
16enum rdma_nl_flags {
17 /* Require CAP_NET_ADMIN */
18 RDMA_NL_ADMIN_PERM = 1 << 0,
Roland Dreierb2cbae22011-05-20 11:46:11 -070019};
20
Jason Gunthorpee3bf14b2017-08-14 14:57:39 -060021/* 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 __chk_##_index(void) \
28 { \
29 BUILD_BUG_ON(_index != _val); \
30 } \
31 MODULE_ALIAS("rdma-netlink-subsys-" __stringify(_val))
32
Roland Dreierb2cbae22011-05-20 11:46:11 -070033/**
Leon Romanovskyc9901722017-06-05 10:20:11 +030034 * Register client in RDMA netlink.
Roland Dreierb2cbae22011-05-20 11:46:11 -070035 * @index: Index of the added client
Roland Dreierb2cbae22011-05-20 11:46:11 -070036 * @cb_table: A table for op->callback
Roland Dreierb2cbae22011-05-20 11:46:11 -070037 */
Leon Romanovskyc9901722017-06-05 10:20:11 +030038void rdma_nl_register(unsigned int index,
Leon Romanovsky3250b4d2017-06-19 18:23:45 +030039 const struct rdma_nl_cbs cb_table[]);
Roland Dreierb2cbae22011-05-20 11:46:11 -070040
41/**
42 * Remove a client from IB netlink.
43 * @index: Index of the removed IB client.
Roland Dreierb2cbae22011-05-20 11:46:11 -070044 */
Leon Romanovskyc9901722017-06-05 10:20:11 +030045void rdma_nl_unregister(unsigned int index);
Roland Dreierb2cbae22011-05-20 11:46:11 -070046
47/**
48 * Put a new message in a supplied skb.
49 * @skb: The netlink skb.
50 * @nlh: Pointer to put the header of the new netlink message.
51 * @seq: The message sequence number.
52 * @len: The requested message length to allocate.
53 * @client: Calling IB netlink client.
54 * @op: message content op.
55 * Returns the allocated buffer on success and NULL on failure.
56 */
57void *ibnl_put_msg(struct sk_buff *skb, struct nlmsghdr **nlh, int seq,
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -050058 int len, int client, int op, int flags);
Roland Dreierb2cbae22011-05-20 11:46:11 -070059/**
60 * Put a new attribute in a supplied skb.
61 * @skb: The netlink skb.
62 * @nlh: Header of the netlink message to append the attribute to.
63 * @len: The length of the attribute data.
64 * @data: The attribute data to put.
65 * @type: The attribute type.
66 * Returns the 0 and a negative error code on failure.
67 */
68int ibnl_put_attr(struct sk_buff *skb, struct nlmsghdr *nlh,
69 int len, void *data, int type);
70
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -050071/**
72 * Send the supplied skb to a specific userspace PID.
73 * @skb: The netlink skb
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -050074 * @pid: Userspace netlink process ID
75 * Returns 0 on success or a negative error code.
76 */
Leon Romanovskyf00e6462017-06-18 15:35:20 +030077int rdma_nl_unicast(struct sk_buff *skb, u32 pid);
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -050078
79/**
Ismail, Mustafa90478112017-06-28 09:02:45 -050080 * Send, with wait/1 retry, the supplied skb to a specific userspace PID.
81 * @skb: The netlink skb
Ismail, Mustafa90478112017-06-28 09:02:45 -050082 * @pid: Userspace netlink process ID
83 * Returns 0 on success or a negative error code.
84 */
Leon Romanovskyf00e6462017-06-18 15:35:20 +030085int rdma_nl_unicast_wait(struct sk_buff *skb, __u32 pid);
Ismail, Mustafa90478112017-06-28 09:02:45 -050086
87/**
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -050088 * Send the supplied skb to a netlink group.
89 * @skb: The netlink skb
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -050090 * @group: Netlink group ID
91 * @flags: allocation flags
92 * Returns 0 on success or a negative error code.
93 */
Leon Romanovsky4d7f6932017-06-18 15:44:32 +030094int rdma_nl_multicast(struct sk_buff *skb, unsigned int group, gfp_t flags);
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -050095
Leon Romanovskyff61c422017-06-18 15:51:16 +030096/**
97 * Check if there are any listeners to the netlink group
98 * @group: the netlink group ID
99 * Returns 0 on success or a negative for no listeners.
100 */
101int rdma_nl_chk_listeners(unsigned int group);
Roland Dreierb2cbae22011-05-20 11:46:11 -0700102#endif /* _RDMA_NETLINK_H */