|
30 | 30 | * POSSIBILITY OF SUCH DAMAGE.
|
31 | 31 | */
|
32 | 32 |
|
| 33 | +#include <net/netlink.h> |
33 | 34 | #include <rdma/rdma_netlink.h>
|
34 | 35 |
|
35 | 36 | #include "core_priv.h"
|
36 | 37 |
|
| 38 | +static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = { |
| 39 | + [RDMA_NLDEV_ATTR_DEV_INDEX] = { .type = NLA_U32 }, |
| 40 | + [RDMA_NLDEV_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, |
| 41 | + .len = IB_DEVICE_NAME_MAX - 1}, |
| 42 | + [RDMA_NLDEV_ATTR_PORT_INDEX] = { .type = NLA_U32 }, |
| 43 | +}; |
| 44 | + |
| 45 | +static int fill_dev_info(struct sk_buff *msg, struct ib_device *device) |
| 46 | +{ |
| 47 | + if (nla_put_u32(msg, RDMA_NLDEV_ATTR_DEV_INDEX, device->index)) |
| 48 | + return -EMSGSIZE; |
| 49 | + if (nla_put_string(msg, RDMA_NLDEV_ATTR_DEV_NAME, device->name)) |
| 50 | + return -EMSGSIZE; |
| 51 | + if (nla_put_u32(msg, RDMA_NLDEV_ATTR_PORT_INDEX, rdma_end_port(device))) |
| 52 | + return -EMSGSIZE; |
| 53 | + return 0; |
| 54 | +} |
| 55 | + |
| 56 | +static int _nldev_get_dumpit(struct ib_device *device, |
| 57 | + struct sk_buff *skb, |
| 58 | + struct netlink_callback *cb, |
| 59 | + unsigned int idx) |
| 60 | +{ |
| 61 | + int start = cb->args[0]; |
| 62 | + struct nlmsghdr *nlh; |
| 63 | + |
| 64 | + if (idx < start) |
| 65 | + return 0; |
| 66 | + |
| 67 | + nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, |
| 68 | + RDMA_NL_GET_TYPE(RDMA_NL_NLDEV, RDMA_NLDEV_CMD_GET), |
| 69 | + 0, NLM_F_MULTI); |
| 70 | + |
| 71 | + if (fill_dev_info(skb, device)) { |
| 72 | + nlmsg_cancel(skb, nlh); |
| 73 | + goto out; |
| 74 | + } |
| 75 | + |
| 76 | + nlmsg_end(skb, nlh); |
| 77 | + |
| 78 | + idx++; |
| 79 | + |
| 80 | +out: cb->args[0] = idx; |
| 81 | + return skb->len; |
| 82 | +} |
| 83 | + |
| 84 | +static int nldev_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) |
| 85 | +{ |
| 86 | + /* |
| 87 | + * There is no need to take lock, because |
| 88 | + * we are relying on ib_core's lists_rwsem |
| 89 | + */ |
| 90 | + return ib_enum_all_devs(_nldev_get_dumpit, skb, cb); |
| 91 | +} |
| 92 | + |
| 93 | +static const struct rdma_nl_cbs nldev_cb_table[] = { |
| 94 | + [RDMA_NLDEV_CMD_GET] = { |
| 95 | + .dump = nldev_get_dumpit, |
| 96 | + }, |
| 97 | +}; |
| 98 | + |
37 | 99 | void __init nldev_init(void)
|
38 | 100 | {
|
39 |
| - rdma_nl_register(RDMA_NL_NLDEV, NULL); |
| 101 | + rdma_nl_register(RDMA_NL_NLDEV, nldev_cb_table); |
40 | 102 | }
|
41 | 103 |
|
42 | 104 | void __exit nldev_exit(void)
|
|
0 commit comments