18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci#ifndef _RDMA_NETLINK_H 48c2ecf20Sopenharmony_ci#define _RDMA_NETLINK_H 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#include <linux/netlink.h> 78c2ecf20Sopenharmony_ci#include <uapi/rdma/rdma_netlink.h> 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_cienum { 108c2ecf20Sopenharmony_ci RDMA_NLDEV_ATTR_EMPTY_STRING = 1, 118c2ecf20Sopenharmony_ci RDMA_NLDEV_ATTR_ENTRY_STRLEN = 16, 128c2ecf20Sopenharmony_ci RDMA_NLDEV_ATTR_CHARDEV_TYPE_SIZE = 32, 138c2ecf20Sopenharmony_ci}; 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cistruct rdma_nl_cbs { 168c2ecf20Sopenharmony_ci int (*doit)(struct sk_buff *skb, struct nlmsghdr *nlh, 178c2ecf20Sopenharmony_ci struct netlink_ext_ack *extack); 188c2ecf20Sopenharmony_ci int (*dump)(struct sk_buff *skb, struct netlink_callback *nlcb); 198c2ecf20Sopenharmony_ci u8 flags; 208c2ecf20Sopenharmony_ci}; 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cienum rdma_nl_flags { 238c2ecf20Sopenharmony_ci /* Require CAP_NET_ADMIN */ 248c2ecf20Sopenharmony_ci RDMA_NL_ADMIN_PERM = 1 << 0, 258c2ecf20Sopenharmony_ci}; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* Define this module as providing netlink services for NETLINK_RDMA, with 288c2ecf20Sopenharmony_ci * index _index. Since the client indexes were setup in a uapi header as an 298c2ecf20Sopenharmony_ci * enum and we do no want to change that, the user must supply the expanded 308c2ecf20Sopenharmony_ci * constant as well and the compiler checks they are the same. 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci#define MODULE_ALIAS_RDMA_NETLINK(_index, _val) \ 338c2ecf20Sopenharmony_ci static inline void __maybe_unused __chk_##_index(void) \ 348c2ecf20Sopenharmony_ci { \ 358c2ecf20Sopenharmony_ci BUILD_BUG_ON(_index != _val); \ 368c2ecf20Sopenharmony_ci } \ 378c2ecf20Sopenharmony_ci MODULE_ALIAS("rdma-netlink-subsys-" __stringify(_val)) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/** 408c2ecf20Sopenharmony_ci * Register client in RDMA netlink. 418c2ecf20Sopenharmony_ci * @index: Index of the added client 428c2ecf20Sopenharmony_ci * @cb_table: A table for op->callback 438c2ecf20Sopenharmony_ci */ 448c2ecf20Sopenharmony_civoid rdma_nl_register(unsigned int index, 458c2ecf20Sopenharmony_ci const struct rdma_nl_cbs cb_table[]); 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/** 488c2ecf20Sopenharmony_ci * Remove a client from IB netlink. 498c2ecf20Sopenharmony_ci * @index: Index of the removed IB client. 508c2ecf20Sopenharmony_ci */ 518c2ecf20Sopenharmony_civoid rdma_nl_unregister(unsigned int index); 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci/** 548c2ecf20Sopenharmony_ci * Put a new message in a supplied skb. 558c2ecf20Sopenharmony_ci * @skb: The netlink skb. 568c2ecf20Sopenharmony_ci * @nlh: Pointer to put the header of the new netlink message. 578c2ecf20Sopenharmony_ci * @seq: The message sequence number. 588c2ecf20Sopenharmony_ci * @len: The requested message length to allocate. 598c2ecf20Sopenharmony_ci * @client: Calling IB netlink client. 608c2ecf20Sopenharmony_ci * @op: message content op. 618c2ecf20Sopenharmony_ci * Returns the allocated buffer on success and NULL on failure. 628c2ecf20Sopenharmony_ci */ 638c2ecf20Sopenharmony_civoid *ibnl_put_msg(struct sk_buff *skb, struct nlmsghdr **nlh, int seq, 648c2ecf20Sopenharmony_ci int len, int client, int op, int flags); 658c2ecf20Sopenharmony_ci/** 668c2ecf20Sopenharmony_ci * Put a new attribute in a supplied skb. 678c2ecf20Sopenharmony_ci * @skb: The netlink skb. 688c2ecf20Sopenharmony_ci * @nlh: Header of the netlink message to append the attribute to. 698c2ecf20Sopenharmony_ci * @len: The length of the attribute data. 708c2ecf20Sopenharmony_ci * @data: The attribute data to put. 718c2ecf20Sopenharmony_ci * @type: The attribute type. 728c2ecf20Sopenharmony_ci * Returns the 0 and a negative error code on failure. 738c2ecf20Sopenharmony_ci */ 748c2ecf20Sopenharmony_ciint ibnl_put_attr(struct sk_buff *skb, struct nlmsghdr *nlh, 758c2ecf20Sopenharmony_ci int len, void *data, int type); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/** 788c2ecf20Sopenharmony_ci * Send the supplied skb to a specific userspace PID. 798c2ecf20Sopenharmony_ci * @net: Net namespace in which to send the skb 808c2ecf20Sopenharmony_ci * @skb: The netlink skb 818c2ecf20Sopenharmony_ci * @pid: Userspace netlink process ID 828c2ecf20Sopenharmony_ci * Returns 0 on success or a negative error code. 838c2ecf20Sopenharmony_ci */ 848c2ecf20Sopenharmony_ciint rdma_nl_unicast(struct net *net, struct sk_buff *skb, u32 pid); 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/** 878c2ecf20Sopenharmony_ci * Send, with wait/1 retry, the supplied skb to a specific userspace PID. 888c2ecf20Sopenharmony_ci * @net: Net namespace in which to send the skb 898c2ecf20Sopenharmony_ci * @skb: The netlink skb 908c2ecf20Sopenharmony_ci * @pid: Userspace netlink process ID 918c2ecf20Sopenharmony_ci * Returns 0 on success or a negative error code. 928c2ecf20Sopenharmony_ci */ 938c2ecf20Sopenharmony_ciint rdma_nl_unicast_wait(struct net *net, struct sk_buff *skb, __u32 pid); 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci/** 968c2ecf20Sopenharmony_ci * Send the supplied skb to a netlink group. 978c2ecf20Sopenharmony_ci * @net: Net namespace in which to send the skb 988c2ecf20Sopenharmony_ci * @skb: The netlink skb 998c2ecf20Sopenharmony_ci * @group: Netlink group ID 1008c2ecf20Sopenharmony_ci * @flags: allocation flags 1018c2ecf20Sopenharmony_ci * Returns 0 on success or a negative error code. 1028c2ecf20Sopenharmony_ci */ 1038c2ecf20Sopenharmony_ciint rdma_nl_multicast(struct net *net, struct sk_buff *skb, 1048c2ecf20Sopenharmony_ci unsigned int group, gfp_t flags); 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci/** 1078c2ecf20Sopenharmony_ci * Check if there are any listeners to the netlink group 1088c2ecf20Sopenharmony_ci * @group: the netlink group ID 1098c2ecf20Sopenharmony_ci * Returns true on success or false if no listeners. 1108c2ecf20Sopenharmony_ci */ 1118c2ecf20Sopenharmony_cibool rdma_nl_chk_listeners(unsigned int group); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistruct rdma_link_ops { 1148c2ecf20Sopenharmony_ci struct list_head list; 1158c2ecf20Sopenharmony_ci const char *type; 1168c2ecf20Sopenharmony_ci int (*newlink)(const char *ibdev_name, struct net_device *ndev); 1178c2ecf20Sopenharmony_ci}; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_civoid rdma_link_register(struct rdma_link_ops *ops); 1208c2ecf20Sopenharmony_civoid rdma_link_unregister(struct rdma_link_ops *ops); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci#define MODULE_ALIAS_RDMA_LINK(type) MODULE_ALIAS("rdma-link-" type) 1238c2ecf20Sopenharmony_ci#define MODULE_ALIAS_RDMA_CLIENT(type) MODULE_ALIAS("rdma-client-" type) 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci#endif /* _RDMA_NETLINK_H */ 126