1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 2 3 #ifndef _RDMA_NETLINK_H 3 #ifndef _RDMA_NETLINK_H 4 #define _RDMA_NETLINK_H 4 #define _RDMA_NETLINK_H 5 5 6 #include <linux/netlink.h> 6 #include <linux/netlink.h> 7 #include <uapi/rdma/rdma_netlink.h> 7 #include <uapi/rdma/rdma_netlink.h> 8 8 9 struct ib_device; << 10 << 11 enum { 9 enum { 12 RDMA_NLDEV_ATTR_EMPTY_STRING = 1, 10 RDMA_NLDEV_ATTR_EMPTY_STRING = 1, 13 RDMA_NLDEV_ATTR_ENTRY_STRLEN = 16, 11 RDMA_NLDEV_ATTR_ENTRY_STRLEN = 16, 14 RDMA_NLDEV_ATTR_CHARDEV_TYPE_SIZE = 32 12 RDMA_NLDEV_ATTR_CHARDEV_TYPE_SIZE = 32, 15 }; 13 }; 16 14 17 struct rdma_nl_cbs { 15 struct rdma_nl_cbs { 18 int (*doit)(struct sk_buff *skb, struc 16 int (*doit)(struct sk_buff *skb, struct nlmsghdr *nlh, 19 struct netlink_ext_ack *ex 17 struct netlink_ext_ack *extack); 20 int (*dump)(struct sk_buff *skb, struc 18 int (*dump)(struct sk_buff *skb, struct netlink_callback *nlcb); 21 u8 flags; 19 u8 flags; 22 }; 20 }; 23 21 24 enum rdma_nl_flags { 22 enum rdma_nl_flags { 25 /* Require CAP_NET_ADMIN */ 23 /* Require CAP_NET_ADMIN */ 26 RDMA_NL_ADMIN_PERM = 1 << 0, 24 RDMA_NL_ADMIN_PERM = 1 << 0, 27 }; 25 }; 28 26 29 /* Define this module as providing netlink ser 27 /* Define this module as providing netlink services for NETLINK_RDMA, with 30 * index _index. Since the client indexes wer 28 * index _index. Since the client indexes were setup in a uapi header as an 31 * enum and we do no want to change that, the 29 * enum and we do no want to change that, the user must supply the expanded 32 * constant as well and the compiler checks th 30 * constant as well and the compiler checks they are the same. 33 */ 31 */ 34 #define MODULE_ALIAS_RDMA_NETLINK(_index, _val 32 #define MODULE_ALIAS_RDMA_NETLINK(_index, _val) \ 35 static inline void __maybe_unused __ch 33 static inline void __maybe_unused __chk_##_index(void) \ 36 { 34 { \ 37 BUILD_BUG_ON(_index != _val); 35 BUILD_BUG_ON(_index != _val); \ 38 } 36 } \ 39 MODULE_ALIAS("rdma-netlink-subsys-" __ 37 MODULE_ALIAS("rdma-netlink-subsys-" __stringify(_val)) 40 38 41 /** 39 /** 42 * Register client in RDMA netlink. 40 * Register client in RDMA netlink. 43 * @index: Index of the added client 41 * @index: Index of the added client 44 * @cb_table: A table for op->callback 42 * @cb_table: A table for op->callback 45 */ 43 */ 46 void rdma_nl_register(unsigned int index, 44 void rdma_nl_register(unsigned int index, 47 const struct rdma_nl_cbs 45 const struct rdma_nl_cbs cb_table[]); 48 46 49 /** 47 /** 50 * Remove a client from IB netlink. 48 * Remove a client from IB netlink. 51 * @index: Index of the removed IB client. 49 * @index: Index of the removed IB client. 52 */ 50 */ 53 void rdma_nl_unregister(unsigned int index); 51 void rdma_nl_unregister(unsigned int index); 54 52 55 /** 53 /** 56 * Put a new message in a supplied skb. 54 * Put a new message in a supplied skb. 57 * @skb: The netlink skb. 55 * @skb: The netlink skb. 58 * @nlh: Pointer to put the header of the new 56 * @nlh: Pointer to put the header of the new netlink message. 59 * @seq: The message sequence number. 57 * @seq: The message sequence number. 60 * @len: The requested message length to alloc 58 * @len: The requested message length to allocate. 61 * @client: Calling IB netlink client. 59 * @client: Calling IB netlink client. 62 * @op: message content op. 60 * @op: message content op. 63 * Returns the allocated buffer on success and 61 * Returns the allocated buffer on success and NULL on failure. 64 */ 62 */ 65 void *ibnl_put_msg(struct sk_buff *skb, struct 63 void *ibnl_put_msg(struct sk_buff *skb, struct nlmsghdr **nlh, int seq, 66 int len, int client, int op 64 int len, int client, int op, int flags); 67 /** 65 /** 68 * Put a new attribute in a supplied skb. 66 * Put a new attribute in a supplied skb. 69 * @skb: The netlink skb. 67 * @skb: The netlink skb. 70 * @nlh: Header of the netlink message to appe 68 * @nlh: Header of the netlink message to append the attribute to. 71 * @len: The length of the attribute data. 69 * @len: The length of the attribute data. 72 * @data: The attribute data to put. 70 * @data: The attribute data to put. 73 * @type: The attribute type. 71 * @type: The attribute type. 74 * Returns the 0 and a negative error code on 72 * Returns the 0 and a negative error code on failure. 75 */ 73 */ 76 int ibnl_put_attr(struct sk_buff *skb, struct 74 int ibnl_put_attr(struct sk_buff *skb, struct nlmsghdr *nlh, 77 int len, void *data, int typ 75 int len, void *data, int type); 78 76 79 /** 77 /** 80 * Send the supplied skb to a specific userspa 78 * Send the supplied skb to a specific userspace PID. 81 * @net: Net namespace in which to send the sk 79 * @net: Net namespace in which to send the skb 82 * @skb: The netlink skb 80 * @skb: The netlink skb 83 * @pid: Userspace netlink process ID 81 * @pid: Userspace netlink process ID 84 * Returns 0 on success or a negative error co 82 * Returns 0 on success or a negative error code. 85 */ 83 */ 86 int rdma_nl_unicast(struct net *net, struct sk 84 int rdma_nl_unicast(struct net *net, struct sk_buff *skb, u32 pid); 87 85 88 /** 86 /** 89 * Send, with wait/1 retry, the supplied skb t 87 * Send, with wait/1 retry, the supplied skb to a specific userspace PID. 90 * @net: Net namespace in which to send the sk 88 * @net: Net namespace in which to send the skb 91 * @skb: The netlink skb 89 * @skb: The netlink skb 92 * @pid: Userspace netlink process ID 90 * @pid: Userspace netlink process ID 93 * Returns 0 on success or a negative error co 91 * Returns 0 on success or a negative error code. 94 */ 92 */ 95 int rdma_nl_unicast_wait(struct net *net, stru 93 int rdma_nl_unicast_wait(struct net *net, struct sk_buff *skb, __u32 pid); 96 94 97 /** 95 /** 98 * Send the supplied skb to a netlink group. 96 * Send the supplied skb to a netlink group. 99 * @net: Net namespace in which to send the sk 97 * @net: Net namespace in which to send the skb 100 * @skb: The netlink skb 98 * @skb: The netlink skb 101 * @group: Netlink group ID 99 * @group: Netlink group ID 102 * @flags: allocation flags 100 * @flags: allocation flags 103 * Returns 0 on success or a negative error co 101 * Returns 0 on success or a negative error code. 104 */ 102 */ 105 int rdma_nl_multicast(struct net *net, struct 103 int rdma_nl_multicast(struct net *net, struct sk_buff *skb, 106 unsigned int group, gfp_ 104 unsigned int group, gfp_t flags); 107 105 108 /** 106 /** 109 * Check if there are any listeners to the net 107 * Check if there are any listeners to the netlink group 110 * @group: the netlink group ID 108 * @group: the netlink group ID 111 * Returns true on success or false if no list 109 * Returns true on success or false if no listeners. 112 */ 110 */ 113 bool rdma_nl_chk_listeners(unsigned int group) 111 bool rdma_nl_chk_listeners(unsigned int group); 114 << 115 /** << 116 * Prepare and send an event message << 117 * @ib: the IB device which triggered the even << 118 * @port_num: the port number which triggered << 119 * @type: the event type << 120 * Returns 0 on success or a negative error co << 121 */ << 122 int rdma_nl_notify_event(struct ib_device *ib, << 123 enum rdma_nl_notify_e << 124 112 125 struct rdma_link_ops { 113 struct rdma_link_ops { 126 struct list_head list; 114 struct list_head list; 127 const char *type; 115 const char *type; 128 int (*newlink)(const char *ibdev_name, 116 int (*newlink)(const char *ibdev_name, struct net_device *ndev); 129 }; 117 }; 130 118 131 void rdma_link_register(struct rdma_link_ops * 119 void rdma_link_register(struct rdma_link_ops *ops); 132 void rdma_link_unregister(struct rdma_link_ops 120 void rdma_link_unregister(struct rdma_link_ops *ops); 133 121 134 #define MODULE_ALIAS_RDMA_LINK(type) MODULE_AL 122 #define MODULE_ALIAS_RDMA_LINK(type) MODULE_ALIAS("rdma-link-" type) 135 #define MODULE_ALIAS_RDMA_CLIENT(type) MODULE_ 123 #define MODULE_ALIAS_RDMA_CLIENT(type) MODULE_ALIAS("rdma-client-" type) 136 124 137 #endif /* _RDMA_NETLINK_H */ 125 #endif /* _RDMA_NETLINK_H */ 138 126
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.