mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-03 17:40:04 +00:00
![Steve Wise](/assets/img/avatar_default.png)
Add support for new LINK messages to allow adding and deleting rdma interfaces. This will be used initially for soft rdma drivers which instantiate device instances dynamically by the admin specifying a netdev device to use. The rdma_rxe module will be the first user of these messages. The design is modeled after RTNL_NEWLINK/DELLINK: rdma drivers register with the rdma core if they provide link add/delete functions. Each driver registers with a unique "type" string, that is used to dispatch messages coming from user space. A new RDMA_NLDEV_ATTR is defined for the "type" string. User mode will pass 3 attributes in a NEWLINK message: RDMA_NLDEV_ATTR_DEV_NAME for the desired rdma device name to be created, RDMA_NLDEV_ATTR_LINK_TYPE for the "type" of link being added, and RDMA_NLDEV_ATTR_NDEV_NAME for the net_device interface to use for this link. The DELLINK message will contain the RDMA_NLDEV_ATTR_DEV_INDEX of the device to delete. Signed-off-by: Steve Wise <swise@opengridcomputing.com> Reviewed-by: Leon Romanovsky <leonro@mellanox.com> Reviewed-by: Michael J. Ruhl <michael.j.ruhl@intel.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
113 lines
3.6 KiB
C
113 lines
3.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _RDMA_NETLINK_H
|
|
#define _RDMA_NETLINK_H
|
|
|
|
|
|
#include <linux/netlink.h>
|
|
#include <uapi/rdma/rdma_netlink.h>
|
|
|
|
struct rdma_nl_cbs {
|
|
int (*doit)(struct sk_buff *skb, struct nlmsghdr *nlh,
|
|
struct netlink_ext_ack *extack);
|
|
int (*dump)(struct sk_buff *skb, struct netlink_callback *nlcb);
|
|
u8 flags;
|
|
};
|
|
|
|
enum rdma_nl_flags {
|
|
/* Require CAP_NET_ADMIN */
|
|
RDMA_NL_ADMIN_PERM = 1 << 0,
|
|
};
|
|
|
|
/* Define this module as providing netlink services for NETLINK_RDMA, with
|
|
* index _index. Since the client indexes were setup in a uapi header as an
|
|
* enum and we do no want to change that, the user must supply the expanded
|
|
* constant as well and the compiler checks they are the same.
|
|
*/
|
|
#define MODULE_ALIAS_RDMA_NETLINK(_index, _val) \
|
|
static inline void __chk_##_index(void) \
|
|
{ \
|
|
BUILD_BUG_ON(_index != _val); \
|
|
} \
|
|
MODULE_ALIAS("rdma-netlink-subsys-" __stringify(_val))
|
|
|
|
/**
|
|
* Register client in RDMA netlink.
|
|
* @index: Index of the added client
|
|
* @cb_table: A table for op->callback
|
|
*/
|
|
void rdma_nl_register(unsigned int index,
|
|
const struct rdma_nl_cbs cb_table[]);
|
|
|
|
/**
|
|
* Remove a client from IB netlink.
|
|
* @index: Index of the removed IB client.
|
|
*/
|
|
void rdma_nl_unregister(unsigned int index);
|
|
|
|
/**
|
|
* Put a new message in a supplied skb.
|
|
* @skb: The netlink skb.
|
|
* @nlh: Pointer to put the header of the new netlink message.
|
|
* @seq: The message sequence number.
|
|
* @len: The requested message length to allocate.
|
|
* @client: Calling IB netlink client.
|
|
* @op: message content op.
|
|
* Returns the allocated buffer on success and NULL on failure.
|
|
*/
|
|
void *ibnl_put_msg(struct sk_buff *skb, struct nlmsghdr **nlh, int seq,
|
|
int len, int client, int op, int flags);
|
|
/**
|
|
* Put a new attribute in a supplied skb.
|
|
* @skb: The netlink skb.
|
|
* @nlh: Header of the netlink message to append the attribute to.
|
|
* @len: The length of the attribute data.
|
|
* @data: The attribute data to put.
|
|
* @type: The attribute type.
|
|
* Returns the 0 and a negative error code on failure.
|
|
*/
|
|
int ibnl_put_attr(struct sk_buff *skb, struct nlmsghdr *nlh,
|
|
int len, void *data, int type);
|
|
|
|
/**
|
|
* Send the supplied skb to a specific userspace PID.
|
|
* @skb: The netlink skb
|
|
* @pid: Userspace netlink process ID
|
|
* Returns 0 on success or a negative error code.
|
|
*/
|
|
int rdma_nl_unicast(struct sk_buff *skb, u32 pid);
|
|
|
|
/**
|
|
* Send, with wait/1 retry, the supplied skb to a specific userspace PID.
|
|
* @skb: The netlink skb
|
|
* @pid: Userspace netlink process ID
|
|
* Returns 0 on success or a negative error code.
|
|
*/
|
|
int rdma_nl_unicast_wait(struct sk_buff *skb, __u32 pid);
|
|
|
|
/**
|
|
* Send the supplied skb to a netlink group.
|
|
* @skb: The netlink skb
|
|
* @group: Netlink group ID
|
|
* @flags: allocation flags
|
|
* Returns 0 on success or a negative error code.
|
|
*/
|
|
int rdma_nl_multicast(struct sk_buff *skb, unsigned int group, gfp_t flags);
|
|
|
|
/**
|
|
* Check if there are any listeners to the netlink group
|
|
* @group: the netlink group ID
|
|
* Returns true on success or false if no listeners.
|
|
*/
|
|
bool rdma_nl_chk_listeners(unsigned int group);
|
|
|
|
struct rdma_link_ops {
|
|
struct list_head list;
|
|
const char *type;
|
|
int (*newlink)(const char *ibdev_name, struct net_device *ndev);
|
|
};
|
|
|
|
void rdma_link_register(struct rdma_link_ops *ops);
|
|
void rdma_link_unregister(struct rdma_link_ops *ops);
|
|
|
|
#define MODULE_ALIAS_RDMA_LINK(type) MODULE_ALIAS("rdma-link-" type)
|
|
#endif /* _RDMA_NETLINK_H */
|