Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 
0003 #ifndef _RDMA_NETLINK_H
0004 #define _RDMA_NETLINK_H
0005 
0006 #include <linux/netlink.h>
0007 #include <uapi/rdma/rdma_netlink.h>
0008 
0009 enum {
0010     RDMA_NLDEV_ATTR_EMPTY_STRING = 1,
0011     RDMA_NLDEV_ATTR_ENTRY_STRLEN = 16,
0012     RDMA_NLDEV_ATTR_CHARDEV_TYPE_SIZE = 32,
0013 };
0014 
0015 struct rdma_nl_cbs {
0016     int (*doit)(struct sk_buff *skb, struct nlmsghdr *nlh,
0017             struct netlink_ext_ack *extack);
0018     int (*dump)(struct sk_buff *skb, struct netlink_callback *nlcb);
0019     u8 flags;
0020 };
0021 
0022 enum rdma_nl_flags {
0023     /* Require CAP_NET_ADMIN */
0024     RDMA_NL_ADMIN_PERM  = 1 << 0,
0025 };
0026 
0027 /* Define this module as providing netlink services for NETLINK_RDMA, with
0028  * index _index.  Since the client indexes were setup in a uapi header as an
0029  * enum and we do no want to change that, the user must supply the expanded
0030  * constant as well and the compiler checks they are the same.
0031  */
0032 #define MODULE_ALIAS_RDMA_NETLINK(_index, _val)                                \
0033     static inline void __maybe_unused __chk_##_index(void)                 \
0034     {                                                                      \
0035         BUILD_BUG_ON(_index != _val);                                  \
0036     }                                                                      \
0037     MODULE_ALIAS("rdma-netlink-subsys-" __stringify(_val))
0038 
0039 /**
0040  * Register client in RDMA netlink.
0041  * @index: Index of the added client
0042  * @cb_table: A table for op->callback
0043  */
0044 void rdma_nl_register(unsigned int index,
0045               const struct rdma_nl_cbs cb_table[]);
0046 
0047 /**
0048  * Remove a client from IB netlink.
0049  * @index: Index of the removed IB client.
0050  */
0051 void rdma_nl_unregister(unsigned int index);
0052 
0053 /**
0054  * Put a new message in a supplied skb.
0055  * @skb: The netlink skb.
0056  * @nlh: Pointer to put the header of the new netlink message.
0057  * @seq: The message sequence number.
0058  * @len: The requested message length to allocate.
0059  * @client: Calling IB netlink client.
0060  * @op: message content op.
0061  * Returns the allocated buffer on success and NULL on failure.
0062  */
0063 void *ibnl_put_msg(struct sk_buff *skb, struct nlmsghdr **nlh, int seq,
0064            int len, int client, int op, int flags);
0065 /**
0066  * Put a new attribute in a supplied skb.
0067  * @skb: The netlink skb.
0068  * @nlh: Header of the netlink message to append the attribute to.
0069  * @len: The length of the attribute data.
0070  * @data: The attribute data to put.
0071  * @type: The attribute type.
0072  * Returns the 0 and a negative error code on failure.
0073  */
0074 int ibnl_put_attr(struct sk_buff *skb, struct nlmsghdr *nlh,
0075           int len, void *data, int type);
0076 
0077 /**
0078  * Send the supplied skb to a specific userspace PID.
0079  * @net: Net namespace in which to send the skb
0080  * @skb: The netlink skb
0081  * @pid: Userspace netlink process ID
0082  * Returns 0 on success or a negative error code.
0083  */
0084 int rdma_nl_unicast(struct net *net, struct sk_buff *skb, u32 pid);
0085 
0086 /**
0087  * Send, with wait/1 retry, the supplied skb to a specific userspace PID.
0088  * @net: Net namespace in which to send the skb
0089  * @skb: The netlink skb
0090  * @pid: Userspace netlink process ID
0091  * Returns 0 on success or a negative error code.
0092  */
0093 int rdma_nl_unicast_wait(struct net *net, struct sk_buff *skb, __u32 pid);
0094 
0095 /**
0096  * Send the supplied skb to a netlink group.
0097  * @net: Net namespace in which to send the skb
0098  * @skb: The netlink skb
0099  * @group: Netlink group ID
0100  * @flags: allocation flags
0101  * Returns 0 on success or a negative error code.
0102  */
0103 int rdma_nl_multicast(struct net *net, struct sk_buff *skb,
0104               unsigned int group, gfp_t flags);
0105 
0106 /**
0107  * Check if there are any listeners to the netlink group
0108  * @group: the netlink group ID
0109  * Returns true on success or false if no listeners.
0110  */
0111 bool rdma_nl_chk_listeners(unsigned int group);
0112 
0113 struct rdma_link_ops {
0114     struct list_head list;
0115     const char *type;
0116     int (*newlink)(const char *ibdev_name, struct net_device *ndev);
0117 };
0118 
0119 void rdma_link_register(struct rdma_link_ops *ops);
0120 void rdma_link_unregister(struct rdma_link_ops *ops);
0121 
0122 #define MODULE_ALIAS_RDMA_LINK(type) MODULE_ALIAS("rdma-link-" type)
0123 #define MODULE_ALIAS_RDMA_CLIENT(type) MODULE_ALIAS("rdma-client-" type)
0124 
0125 #endif /* _RDMA_NETLINK_H */