/* SPDX-License-Identifier: GPL-2.0 */12#ifndef _RDMA_NETLINK_H3#define _RDMA_NETLINK_H45#include <linux/netlink.h>6#include <uapi/rdma/rdma_netlink.h>78struct ib_device;910enum {11RDMA_NLDEV_ATTR_EMPTY_STRING = 1,12RDMA_NLDEV_ATTR_ENTRY_STRLEN = 16,13RDMA_NLDEV_ATTR_CHARDEV_TYPE_SIZE = 32,14};1516struct rdma_nl_cbs {17int (*doit)(struct sk_buff *skb, struct nlmsghdr *nlh,18struct netlink_ext_ack *extack);19int (*dump)(struct sk_buff *skb, struct netlink_callback *nlcb);20u8 flags;21};2223enum rdma_nl_flags {24/* Require CAP_NET_ADMIN */25RDMA_NL_ADMIN_PERM = 1 << 0,26};2728/* Define this module as providing netlink services for NETLINK_RDMA, with29* index _index. Since the client indexes were setup in a uapi header as an30* enum and we do no want to change that, the user must supply the expanded31* constant as well and the compiler checks they are the same.32*/33#define MODULE_ALIAS_RDMA_NETLINK(_index, _val) \34static inline void __maybe_unused __chk_##_index(void) \35{ \36BUILD_BUG_ON(_index != _val); \37} \38MODULE_ALIAS("rdma-netlink-subsys-" __stringify(_val))3940/**41* Register client in RDMA netlink.42* @index: Index of the added client43* @cb_table: A table for op->callback44*/45void rdma_nl_register(unsigned int index,46const struct rdma_nl_cbs cb_table[]);4748/**49* Remove a client from IB netlink.50* @index: Index of the removed IB client.51*/52void rdma_nl_unregister(unsigned int index);5354/**55* Put a new message in a supplied skb.56* @skb: The netlink skb.57* @nlh: Pointer to put the header of the new netlink message.58* @seq: The message sequence number.59* @len: The requested message length to allocate.60* @client: Calling IB netlink client.61* @op: message content op.62* Returns the allocated buffer on success and NULL on failure.63*/64void *ibnl_put_msg(struct sk_buff *skb, struct nlmsghdr **nlh, int seq,65int len, int client, int op, int flags);66/**67* Put a new attribute in a supplied skb.68* @skb: The netlink skb.69* @nlh: Header of the netlink message to append the attribute to.70* @len: The length of the attribute data.71* @data: The attribute data to put.72* @type: The attribute type.73* Returns the 0 and a negative error code on failure.74*/75int ibnl_put_attr(struct sk_buff *skb, struct nlmsghdr *nlh,76int len, void *data, int type);7778/**79* Send the supplied skb to a specific userspace PID.80* @net: Net namespace in which to send the skb81* @skb: The netlink skb82* @pid: Userspace netlink process ID83* Returns 0 on success or a negative error code.84*/85int rdma_nl_unicast(struct net *net, struct sk_buff *skb, u32 pid);8687/**88* Send, with wait/1 retry, the supplied skb to a specific userspace PID.89* @net: Net namespace in which to send the skb90* @skb: The netlink skb91* @pid: Userspace netlink process ID92* Returns 0 on success or a negative error code.93*/94int rdma_nl_unicast_wait(struct net *net, struct sk_buff *skb, __u32 pid);9596/**97* Send the supplied skb to a netlink group.98* @net: Net namespace in which to send the skb99* @skb: The netlink skb100* @group: Netlink group ID101* @flags: allocation flags102* Returns 0 on success or a negative error code.103*/104int rdma_nl_multicast(struct net *net, struct sk_buff *skb,105unsigned int group, gfp_t flags);106107/**108* Check if there are any listeners to the netlink group109* @group: the netlink group ID110* Returns true on success or false if no listeners.111*/112bool rdma_nl_chk_listeners(unsigned int group);113114/**115* Prepare and send an event message116* @ib: the IB device which triggered the event117* @port_num: the port number which triggered the event - 0 if unused118* @type: the event type119* Returns 0 on success or a negative error code120*/121int rdma_nl_notify_event(struct ib_device *ib, u32 port_num,122enum rdma_nl_notify_event_type type);123124struct rdma_link_ops {125struct list_head list;126const char *type;127int (*newlink)(const char *ibdev_name, struct net_device *ndev);128};129130void rdma_link_register(struct rdma_link_ops *ops);131void rdma_link_unregister(struct rdma_link_ops *ops);132133#define MODULE_ALIAS_RDMA_LINK(type) MODULE_ALIAS("rdma-link-" type)134#define MODULE_ALIAS_RDMA_CLIENT(type) MODULE_ALIAS("rdma-client-" type)135136#endif /* _RDMA_NETLINK_H */137138139