]>
Commit | Line | Data |
---|---|---|
74bd75c2 LR |
1 | /* |
2 | * rdma.c RDMA tool | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License | |
6 | * as published by the Free Software Foundation; either version | |
7 | * 2 of the License, or (at your option) any later version. | |
8 | * | |
9 | * Authors: Leon Romanovsky <leonro@mellanox.com> | |
10 | */ | |
11 | #ifndef _RDMA_TOOL_H_ | |
12 | #define _RDMA_TOOL_H_ | |
13 | ||
14 | #include <stdlib.h> | |
15 | #include <string.h> | |
16 | #include <errno.h> | |
17 | #include <getopt.h> | |
18 | #include <libmnl/libmnl.h> | |
19 | #include <rdma/rdma_netlink.h> | |
20 | #include <time.h> | |
21 | ||
22 | #include "list.h" | |
40df8263 | 23 | #include "utils.h" |
74bd75c2 LR |
24 | |
25 | #define pr_err(args...) fprintf(stderr, ##args) | |
26 | #define pr_out(args...) fprintf(stdout, ##args) | |
27 | ||
40df8263 LR |
28 | #define RDMA_BITMAP_ENUM(name, bit_no) RDMA_BITMAP_##name = BIT(bit_no), |
29 | #define RDMA_BITMAP_NAMES(name, bit_no) [bit_no] = #name, | |
30 | ||
74bd75c2 LR |
31 | struct dev_map { |
32 | struct list_head list; | |
33 | char *dev_name; | |
34 | uint32_t num_ports; | |
35 | uint32_t idx; | |
36 | }; | |
37 | ||
38 | struct rd { | |
39 | int argc; | |
40 | char **argv; | |
41 | char *filename; | |
42 | bool show_details; | |
43 | struct list_head dev_map_list; | |
40df8263 LR |
44 | uint32_t dev_idx; |
45 | uint32_t port_idx; | |
74bd75c2 LR |
46 | struct mnl_socket *nl; |
47 | struct nlmsghdr *nlh; | |
48 | char *buff; | |
49 | }; | |
50 | ||
51 | struct rd_cmd { | |
52 | const char *cmd; | |
53 | int (*func)(struct rd *rd); | |
54 | }; | |
55 | ||
56 | /* | |
57 | * Parser interface | |
58 | */ | |
59 | bool rd_no_arg(struct rd *rd); | |
60 | void rd_arg_inc(struct rd *rd); | |
61 | ||
40df8263 LR |
62 | char *rd_argv(struct rd *rd); |
63 | uint32_t get_port_from_argv(struct rd *rd); | |
64 | ||
65 | void rd_print_u64(char *name, uint64_t val); | |
66 | /* | |
67 | * Commands interface | |
68 | */ | |
69 | int cmd_dev(struct rd *rd); | |
70 | int cmd_link(struct rd *rd); | |
74bd75c2 LR |
71 | int rd_exec_cmd(struct rd *rd, const struct rd_cmd *c, const char *str); |
72 | ||
73 | /* | |
74 | * Device manipulation | |
75 | */ | |
76 | void rd_free_devmap(struct rd *rd); | |
40df8263 LR |
77 | struct dev_map *dev_map_lookup(struct rd *rd, bool allow_port_index); |
78 | struct dev_map *_dev_map_lookup(struct rd *rd, const char *dev_name); | |
74bd75c2 LR |
79 | |
80 | /* | |
81 | * Netlink | |
82 | */ | |
83 | int rd_send_msg(struct rd *rd); | |
84 | int rd_recv_msg(struct rd *rd, mnl_cb_t callback, void *data, uint32_t seq); | |
85 | void rd_prepare_msg(struct rd *rd, uint32_t cmd, uint32_t *seq, uint16_t flags); | |
86 | int rd_dev_init_cb(const struct nlmsghdr *nlh, void *data); | |
87 | int rd_attr_cb(const struct nlattr *attr, void *data); | |
88 | #endif /* _RDMA_TOOL_H_ */ |