blob: 2758d9df71ee9187ea6019855b2cfd9c929c91f1 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Leon Romanovsky6bf9d8f2020-07-19 10:25:21 +03002
Roland Dreierb2cbae22011-05-20 11:46:11 -07003#ifndef _RDMA_NETLINK_H
4#define _RDMA_NETLINK_H
5
Roland Dreierb2cbae22011-05-20 11:46:11 -07006#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
Doug Ledford34d65cd2019-06-21 17:00:44 -04009enum {
10 RDMA_NLDEV_ATTR_EMPTY_STRING = 1,
11 RDMA_NLDEV_ATTR_ENTRY_STRLEN = 16,
12 RDMA_NLDEV_ATTR_CHARDEV_TYPE_SIZE = 32,
13};
14
Leon Romanovsky3250b4d2017-06-19 18:23:45 +030015struct rdma_nl_cbs {
Leon Romanovsky1830ba22017-06-15 12:46:33 +030016 int (*doit)(struct sk_buff *skb, struct nlmsghdr *nlh,
17 struct netlink_ext_ack *extack);
Roland Dreierb2cbae22011-05-20 11:46:11 -070018 int (*dump)(struct sk_buff *skb, struct netlink_callback *nlcb);
Leon Romanovskye3a2b932017-06-12 16:00:19 +030019 u8 flags;
20};
21
22enum rdma_nl_flags {
23 /* Require CAP_NET_ADMIN */
24 RDMA_NL_ADMIN_PERM = 1 << 0,
Roland Dreierb2cbae22011-05-20 11:46:11 -070025};
26
Jason Gunthorpee3bf14b2017-08-14 14:57:39 -060027/* 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
Roland Dreierb2cbae22011-05-20 11:46:11 -070039/**
Leon Romanovskyc9901722017-06-05 10:20:11 +030040 * Register client in RDMA netlink.
Roland Dreierb2cbae22011-05-20 11:46:11 -070041 * @index: Index of the added client
Roland Dreierb2cbae22011-05-20 11:46:11 -070042 * @cb_table: A table for op->callback
Roland Dreierb2cbae22011-05-20 11:46:11 -070043 */
Leon Romanovskyc9901722017-06-05 10:20:11 +030044void rdma_nl_register(unsigned int index,
Leon Romanovsky3250b4d2017-06-19 18:23:45 +030045 const struct rdma_nl_cbs cb_table[]);
Roland Dreierb2cbae22011-05-20 11:46:11 -070046
47/**
48 * Remove a client from IB netlink.
49 * @index: Index of the removed IB client.
Roland Dreierb2cbae22011-05-20 11:46:11 -070050 */
Leon Romanovskyc9901722017-06-05 10:20:11 +030051void rdma_nl_unregister(unsigned int index);
Roland Dreierb2cbae22011-05-20 11:46:11 -070052
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 */
63void *ibnl_put_msg(struct sk_buff *skb, struct nlmsghdr **nlh, int seq,
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -050064 int len, int client, int op, int flags);
Roland Dreierb2cbae22011-05-20 11:46:11 -070065/**
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 */
74int ibnl_put_attr(struct sk_buff *skb, struct nlmsghdr *nlh,
75 int len, void *data, int type);
76
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -050077/**
78 * Send the supplied skb to a specific userspace PID.
Parav Pandit1d2fedd2019-07-23 10:02:05 +030079 * @net: Net namespace in which to send the skb
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -050080 * @skb: The netlink skb
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -050081 * @pid: Userspace netlink process ID
82 * Returns 0 on success or a negative error code.
83 */
Parav Pandit1d2fedd2019-07-23 10:02:05 +030084int rdma_nl_unicast(struct net *net, struct sk_buff *skb, u32 pid);
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -050085
86/**
Ismail, Mustafa90478112017-06-28 09:02:45 -050087 * Send, with wait/1 retry, the supplied skb to a specific userspace PID.
Parav Pandit1d2fedd2019-07-23 10:02:05 +030088 * @net: Net namespace in which to send the skb
Ismail, Mustafa90478112017-06-28 09:02:45 -050089 * @skb: The netlink skb
Ismail, Mustafa90478112017-06-28 09:02:45 -050090 * @pid: Userspace netlink process ID
91 * Returns 0 on success or a negative error code.
92 */
Parav Pandit1d2fedd2019-07-23 10:02:05 +030093int rdma_nl_unicast_wait(struct net *net, struct sk_buff *skb, __u32 pid);
Ismail, Mustafa90478112017-06-28 09:02:45 -050094
95/**
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -050096 * Send the supplied skb to a netlink group.
Parav Pandit1d2fedd2019-07-23 10:02:05 +030097 * @net: Net namespace in which to send the skb
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -050098 * @skb: The netlink skb
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -050099 * @group: Netlink group ID
100 * @flags: allocation flags
101 * Returns 0 on success or a negative error code.
102 */
Parav Pandit1d2fedd2019-07-23 10:02:05 +0300103int rdma_nl_multicast(struct net *net, struct sk_buff *skb,
104 unsigned int group, gfp_t flags);
Tatyana Nikolova30dc5e62014-03-26 17:07:35 -0500105
Leon Romanovskyff61c422017-06-18 15:51:16 +0300106/**
107 * Check if there are any listeners to the netlink group
108 * @group: the netlink group ID
Leon Romanovsky38716732018-10-02 11:49:24 +0300109 * Returns true on success or false if no listeners.
Leon Romanovskyff61c422017-06-18 15:51:16 +0300110 */
Leon Romanovsky38716732018-10-02 11:49:24 +0300111bool rdma_nl_chk_listeners(unsigned int group);
Steve Wise3856ec42019-02-15 11:03:53 -0800112
113struct 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
119void rdma_link_register(struct rdma_link_ops *ops);
120void rdma_link_unregister(struct rdma_link_ops *ops);
121
122#define MODULE_ALIAS_RDMA_LINK(type) MODULE_ALIAS("rdma-link-" type)
Jason Gunthorpe0e2d00e2019-06-13 21:38:18 -0300123#define MODULE_ALIAS_RDMA_CLIENT(type) MODULE_ALIAS("rdma-client-" type)
124
Roland Dreierb2cbae22011-05-20 11:46:11 -0700125#endif /* _RDMA_NETLINK_H */