]>
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" |
ab6e2b7b | 24 | #include "json_writer.h" |
74bd75c2 LR |
25 | |
26 | #define pr_err(args...) fprintf(stderr, ##args) | |
27 | #define pr_out(args...) fprintf(stdout, ##args) | |
28 | ||
40df8263 LR |
29 | #define RDMA_BITMAP_ENUM(name, bit_no) RDMA_BITMAP_##name = BIT(bit_no), |
30 | #define RDMA_BITMAP_NAMES(name, bit_no) [bit_no] = #name, | |
31 | ||
1174be72 LR |
32 | #define MAX_NUMBER_OF_FILTERS 64 |
33 | struct filters { | |
34 | char name[32]; | |
35 | bool is_number; | |
36 | }; | |
37 | ||
38 | struct filter_entry { | |
39 | struct list_head list; | |
40 | char *key; | |
41 | char *value; | |
42 | }; | |
43 | ||
74bd75c2 LR |
44 | struct dev_map { |
45 | struct list_head list; | |
46 | char *dev_name; | |
47 | uint32_t num_ports; | |
48 | uint32_t idx; | |
49 | }; | |
50 | ||
51 | struct rd { | |
52 | int argc; | |
53 | char **argv; | |
54 | char *filename; | |
55 | bool show_details; | |
56 | struct list_head dev_map_list; | |
40df8263 LR |
57 | uint32_t dev_idx; |
58 | uint32_t port_idx; | |
74bd75c2 LR |
59 | struct mnl_socket *nl; |
60 | struct nlmsghdr *nlh; | |
61 | char *buff; | |
ab6e2b7b LR |
62 | json_writer_t *jw; |
63 | bool json_output; | |
64 | bool pretty_output; | |
1174be72 | 65 | struct list_head filter_list; |
74bd75c2 LR |
66 | }; |
67 | ||
68 | struct rd_cmd { | |
69 | const char *cmd; | |
70 | int (*func)(struct rd *rd); | |
71 | }; | |
72 | ||
73 | /* | |
74 | * Parser interface | |
75 | */ | |
76 | bool rd_no_arg(struct rd *rd); | |
77 | void rd_arg_inc(struct rd *rd); | |
78 | ||
40df8263 | 79 | char *rd_argv(struct rd *rd); |
40df8263 | 80 | |
40df8263 LR |
81 | /* |
82 | * Commands interface | |
83 | */ | |
84 | int cmd_dev(struct rd *rd); | |
85 | int cmd_link(struct rd *rd); | |
74bd75c2 | 86 | int rd_exec_cmd(struct rd *rd, const struct rd_cmd *c, const char *str); |
8b92a2c9 | 87 | int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd)); |
6416d1a0 | 88 | int rd_exec_link(struct rd *rd, int (*cb)(struct rd *rd), bool strict_port); |
5fc17280 | 89 | void rd_free(struct rd *rd); |
6e0de6e8 | 90 | int rd_set_arg_to_devname(struct rd *rd); |
5f4892e2 | 91 | int rd_argc(struct rd *rd); |
74bd75c2 LR |
92 | |
93 | /* | |
94 | * Device manipulation | |
95 | */ | |
40df8263 | 96 | struct dev_map *dev_map_lookup(struct rd *rd, bool allow_port_index); |
74bd75c2 | 97 | |
1174be72 LR |
98 | /* |
99 | * Filter manipulation | |
100 | */ | |
101 | int rd_build_filter(struct rd *rd, const struct filters valid_filters[]); | |
102 | bool rd_check_is_filtered(struct rd *rd, const char *key, uint32_t val); | |
103 | bool rd_check_is_string_filtered(struct rd *rd, const char *key, const char *val); | |
104 | bool rd_check_is_key_exist(struct rd *rd, const char *key); | |
74bd75c2 LR |
105 | /* |
106 | * Netlink | |
107 | */ | |
108 | int rd_send_msg(struct rd *rd); | |
109 | int rd_recv_msg(struct rd *rd, mnl_cb_t callback, void *data, uint32_t seq); | |
110 | void rd_prepare_msg(struct rd *rd, uint32_t cmd, uint32_t *seq, uint16_t flags); | |
111 | int rd_dev_init_cb(const struct nlmsghdr *nlh, void *data); | |
112 | int rd_attr_cb(const struct nlattr *attr, void *data); | |
113 | #endif /* _RDMA_TOOL_H_ */ |