xref: /linux/include/rdma/rdma_netlink.h (revision 83dde749)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
26bf9d8f6SLeon Romanovsky 
3b2cbae2cSRoland Dreier #ifndef _RDMA_NETLINK_H
4b2cbae2cSRoland Dreier #define _RDMA_NETLINK_H
5b2cbae2cSRoland Dreier 
6b2cbae2cSRoland Dreier #include <linux/netlink.h>
77235aa79SDavid Howells #include <uapi/rdma/rdma_netlink.h>
8b2cbae2cSRoland Dreier 
934d65cd8SDoug Ledford enum {
1034d65cd8SDoug Ledford 	RDMA_NLDEV_ATTR_EMPTY_STRING = 1,
1134d65cd8SDoug Ledford 	RDMA_NLDEV_ATTR_ENTRY_STRLEN = 16,
1234d65cd8SDoug Ledford 	RDMA_NLDEV_ATTR_CHARDEV_TYPE_SIZE = 32,
1334d65cd8SDoug Ledford };
1434d65cd8SDoug Ledford 
153250b4dbSLeon Romanovsky struct rdma_nl_cbs {
161830ba21SLeon Romanovsky 	int (*doit)(struct sk_buff *skb, struct nlmsghdr *nlh,
171830ba21SLeon Romanovsky 		    struct netlink_ext_ack *extack);
18b2cbae2cSRoland Dreier 	int (*dump)(struct sk_buff *skb, struct netlink_callback *nlcb);
19e3a2b93dSLeon Romanovsky 	u8 flags;
20e3a2b93dSLeon Romanovsky };
21e3a2b93dSLeon Romanovsky 
22e3a2b93dSLeon Romanovsky enum rdma_nl_flags {
23e3a2b93dSLeon Romanovsky 	/* Require CAP_NET_ADMIN */
24e3a2b93dSLeon Romanovsky 	RDMA_NL_ADMIN_PERM	= 1 << 0,
25b2cbae2cSRoland Dreier };
26b2cbae2cSRoland Dreier 
27e3bf14bdSJason Gunthorpe /* Define this module as providing netlink services for NETLINK_RDMA, with
28e3bf14bdSJason Gunthorpe  * index _index.  Since the client indexes were setup in a uapi header as an
29e3bf14bdSJason Gunthorpe  * enum and we do no want to change that, the user must supply the expanded
30e3bf14bdSJason Gunthorpe  * constant as well and the compiler checks they are the same.
31e3bf14bdSJason Gunthorpe  */
32e3bf14bdSJason Gunthorpe #define MODULE_ALIAS_RDMA_NETLINK(_index, _val)                                \
33*83dde749SLeon Romanovsky 	static inline void __maybe_unused __chk_##_index(void)                 \
34e3bf14bdSJason Gunthorpe 	{                                                                      \
35e3bf14bdSJason Gunthorpe 		BUILD_BUG_ON(_index != _val);                                  \
36e3bf14bdSJason Gunthorpe 	}                                                                      \
37e3bf14bdSJason Gunthorpe 	MODULE_ALIAS("rdma-netlink-subsys-" __stringify(_val))
38e3bf14bdSJason Gunthorpe 
39b2cbae2cSRoland Dreier /**
40c9901724SLeon Romanovsky  * Register client in RDMA netlink.
41b2cbae2cSRoland Dreier  * @index: Index of the added client
42b2cbae2cSRoland Dreier  * @cb_table: A table for op->callback
43b2cbae2cSRoland Dreier  */
44c9901724SLeon Romanovsky void rdma_nl_register(unsigned int index,
453250b4dbSLeon Romanovsky 		      const struct rdma_nl_cbs cb_table[]);
46b2cbae2cSRoland Dreier 
47b2cbae2cSRoland Dreier /**
48b2cbae2cSRoland Dreier  * Remove a client from IB netlink.
49b2cbae2cSRoland Dreier  * @index: Index of the removed IB client.
50b2cbae2cSRoland Dreier  */
51c9901724SLeon Romanovsky void rdma_nl_unregister(unsigned int index);
52b2cbae2cSRoland Dreier 
53b2cbae2cSRoland Dreier /**
54b2cbae2cSRoland Dreier  * Put a new message in a supplied skb.
55b2cbae2cSRoland Dreier  * @skb: The netlink skb.
56b2cbae2cSRoland Dreier  * @nlh: Pointer to put the header of the new netlink message.
57b2cbae2cSRoland Dreier  * @seq: The message sequence number.
58b2cbae2cSRoland Dreier  * @len: The requested message length to allocate.
59b2cbae2cSRoland Dreier  * @client: Calling IB netlink client.
60b2cbae2cSRoland Dreier  * @op: message content op.
61b2cbae2cSRoland Dreier  * Returns the allocated buffer on success and NULL on failure.
62b2cbae2cSRoland Dreier  */
63b2cbae2cSRoland Dreier void *ibnl_put_msg(struct sk_buff *skb, struct nlmsghdr **nlh, int seq,
6430dc5e63STatyana Nikolova 		   int len, int client, int op, int flags);
65b2cbae2cSRoland Dreier /**
66b2cbae2cSRoland Dreier  * Put a new attribute in a supplied skb.
67b2cbae2cSRoland Dreier  * @skb: The netlink skb.
68b2cbae2cSRoland Dreier  * @nlh: Header of the netlink message to append the attribute to.
69b2cbae2cSRoland Dreier  * @len: The length of the attribute data.
70b2cbae2cSRoland Dreier  * @data: The attribute data to put.
71b2cbae2cSRoland Dreier  * @type: The attribute type.
72b2cbae2cSRoland Dreier  * Returns the 0 and a negative error code on failure.
73b2cbae2cSRoland Dreier  */
74b2cbae2cSRoland Dreier int ibnl_put_attr(struct sk_buff *skb, struct nlmsghdr *nlh,
75b2cbae2cSRoland Dreier 		  int len, void *data, int type);
76b2cbae2cSRoland Dreier 
7730dc5e63STatyana Nikolova /**
7830dc5e63STatyana Nikolova  * Send the supplied skb to a specific userspace PID.
791d2fedd8SParav Pandit  * @net: Net namespace in which to send the skb
8030dc5e63STatyana Nikolova  * @skb: The netlink skb
8130dc5e63STatyana Nikolova  * @pid: Userspace netlink process ID
8230dc5e63STatyana Nikolova  * Returns 0 on success or a negative error code.
8330dc5e63STatyana Nikolova  */
841d2fedd8SParav Pandit int rdma_nl_unicast(struct net *net, struct sk_buff *skb, u32 pid);
8530dc5e63STatyana Nikolova 
8630dc5e63STatyana Nikolova /**
879047811bSIsmail, Mustafa  * Send, with wait/1 retry, the supplied skb to a specific userspace PID.
881d2fedd8SParav Pandit  * @net: Net namespace in which to send the skb
899047811bSIsmail, Mustafa  * @skb: The netlink skb
909047811bSIsmail, Mustafa  * @pid: Userspace netlink process ID
919047811bSIsmail, Mustafa  * Returns 0 on success or a negative error code.
929047811bSIsmail, Mustafa  */
931d2fedd8SParav Pandit int rdma_nl_unicast_wait(struct net *net, struct sk_buff *skb, __u32 pid);
949047811bSIsmail, Mustafa 
959047811bSIsmail, Mustafa /**
9630dc5e63STatyana Nikolova  * Send the supplied skb to a netlink group.
971d2fedd8SParav Pandit  * @net: Net namespace in which to send the skb
9830dc5e63STatyana Nikolova  * @skb: The netlink skb
9930dc5e63STatyana Nikolova  * @group: Netlink group ID
10030dc5e63STatyana Nikolova  * @flags: allocation flags
10130dc5e63STatyana Nikolova  * Returns 0 on success or a negative error code.
10230dc5e63STatyana Nikolova  */
1031d2fedd8SParav Pandit int rdma_nl_multicast(struct net *net, struct sk_buff *skb,
1041d2fedd8SParav Pandit 		      unsigned int group, gfp_t flags);
10530dc5e63STatyana Nikolova 
106ff61c425SLeon Romanovsky /**
107ff61c425SLeon Romanovsky  * Check if there are any listeners to the netlink group
108ff61c425SLeon Romanovsky  * @group: the netlink group ID
10938716732SLeon Romanovsky  * Returns true on success or false if no listeners.
110ff61c425SLeon Romanovsky  */
11138716732SLeon Romanovsky bool rdma_nl_chk_listeners(unsigned int group);
1123856ec4bSSteve Wise 
1133856ec4bSSteve Wise struct rdma_link_ops {
1143856ec4bSSteve Wise 	struct list_head list;
1153856ec4bSSteve Wise 	const char *type;
1163856ec4bSSteve Wise 	int (*newlink)(const char *ibdev_name, struct net_device *ndev);
1173856ec4bSSteve Wise };
1183856ec4bSSteve Wise 
1193856ec4bSSteve Wise void rdma_link_register(struct rdma_link_ops *ops);
1203856ec4bSSteve Wise void rdma_link_unregister(struct rdma_link_ops *ops);
1213856ec4bSSteve Wise 
1223856ec4bSSteve Wise #define MODULE_ALIAS_RDMA_LINK(type) MODULE_ALIAS("rdma-link-" type)
1230e2d00ebSJason Gunthorpe #define MODULE_ALIAS_RDMA_CLIENT(type) MODULE_ALIAS("rdma-client-" type)
1240e2d00ebSJason Gunthorpe 
125b2cbae2cSRoland Dreier #endif /* _RDMA_NETLINK_H */
126