]>
Commit | Line | Data |
---|---|---|
835d8321 | 1 | /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ |
74bd75c2 LR |
2 | /* |
3 | * rdma.c RDMA tool | |
74bd75c2 LR |
4 | * Authors: Leon Romanovsky <leonro@mellanox.com> |
5 | */ | |
6 | #ifndef _RDMA_TOOL_H_ | |
7 | #define _RDMA_TOOL_H_ | |
8 | ||
9 | #include <stdlib.h> | |
10 | #include <string.h> | |
11 | #include <errno.h> | |
12 | #include <getopt.h> | |
5887ff09 | 13 | #include <netinet/in.h> |
74bd75c2 LR |
14 | #include <libmnl/libmnl.h> |
15 | #include <rdma/rdma_netlink.h> | |
9a362cc7 | 16 | #include <rdma/rdma_user_cm.h> |
74bd75c2 | 17 | #include <time.h> |
9a362cc7 | 18 | #include <net/if_arp.h> |
74bd75c2 LR |
19 | |
20 | #include "list.h" | |
40df8263 | 21 | #include "utils.h" |
ab6e2b7b | 22 | #include "json_writer.h" |
74bd75c2 LR |
23 | |
24 | #define pr_err(args...) fprintf(stderr, ##args) | |
25 | #define pr_out(args...) fprintf(stdout, ##args) | |
26 | ||
40df8263 LR |
27 | #define RDMA_BITMAP_ENUM(name, bit_no) RDMA_BITMAP_##name = BIT(bit_no), |
28 | #define RDMA_BITMAP_NAMES(name, bit_no) [bit_no] = #name, | |
29 | ||
1174be72 LR |
30 | #define MAX_NUMBER_OF_FILTERS 64 |
31 | struct filters { | |
3b0070f6 | 32 | const char *name; |
1174be72 LR |
33 | bool is_number; |
34 | }; | |
35 | ||
36 | struct filter_entry { | |
37 | struct list_head list; | |
38 | char *key; | |
39 | char *value; | |
40 | }; | |
41 | ||
74bd75c2 LR |
42 | struct dev_map { |
43 | struct list_head list; | |
44 | char *dev_name; | |
45 | uint32_t num_ports; | |
46 | uint32_t idx; | |
47 | }; | |
48 | ||
49 | struct rd { | |
50 | int argc; | |
51 | char **argv; | |
52 | char *filename; | |
53 | bool show_details; | |
33115275 | 54 | bool show_driver_details; |
74bd75c2 | 55 | struct list_head dev_map_list; |
40df8263 LR |
56 | uint32_t dev_idx; |
57 | uint32_t port_idx; | |
74bd75c2 LR |
58 | struct mnl_socket *nl; |
59 | struct nlmsghdr *nlh; | |
60 | char *buff; | |
ab6e2b7b LR |
61 | json_writer_t *jw; |
62 | bool json_output; | |
63 | bool pretty_output; | |
1174be72 | 64 | struct list_head filter_list; |
74bd75c2 LR |
65 | }; |
66 | ||
67 | struct rd_cmd { | |
68 | const char *cmd; | |
69 | int (*func)(struct rd *rd); | |
70 | }; | |
71 | ||
6ae54b13 DA |
72 | /* |
73 | * Parser interface | |
74 | */ | |
75 | bool rd_no_arg(struct rd *rd); | |
76 | void rd_arg_inc(struct rd *rd); | |
77 | ||
78 | char *rd_argv(struct rd *rd); | |
40df8263 | 79 | |
40df8263 LR |
80 | /* |
81 | * Commands interface | |
82 | */ | |
83 | int cmd_dev(struct rd *rd); | |
84 | int cmd_link(struct rd *rd); | |
923aa825 | 85 | int cmd_res(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)); |
a14ceed3 | 88 | int rd_exec_require_dev(struct rd *rd, int (*cb)(struct rd *rd)); |
6416d1a0 | 89 | int rd_exec_link(struct rd *rd, int (*cb)(struct rd *rd), bool strict_port); |
5fc17280 | 90 | void rd_free(struct rd *rd); |
6e0de6e8 | 91 | int rd_set_arg_to_devname(struct rd *rd); |
5f4892e2 | 92 | int rd_argc(struct rd *rd); |
74bd75c2 | 93 | |
6ae54b13 DA |
94 | int strcmpx(const char *str1, const char *str2); |
95 | ||
74bd75c2 LR |
96 | /* |
97 | * Device manipulation | |
98 | */ | |
40df8263 | 99 | struct dev_map *dev_map_lookup(struct rd *rd, bool allow_port_index); |
74bd75c2 | 100 | |
1174be72 LR |
101 | /* |
102 | * Filter manipulation | |
103 | */ | |
104 | int rd_build_filter(struct rd *rd, const struct filters valid_filters[]); | |
105 | bool rd_check_is_filtered(struct rd *rd, const char *key, uint32_t val); | |
106 | bool rd_check_is_string_filtered(struct rd *rd, const char *key, const char *val); | |
107 | bool rd_check_is_key_exist(struct rd *rd, const char *key); | |
74bd75c2 LR |
108 | /* |
109 | * Netlink | |
110 | */ | |
111 | int rd_send_msg(struct rd *rd); | |
112 | int rd_recv_msg(struct rd *rd, mnl_cb_t callback, void *data, uint32_t seq); | |
113 | void rd_prepare_msg(struct rd *rd, uint32_t cmd, uint32_t *seq, uint16_t flags); | |
114 | int rd_dev_init_cb(const struct nlmsghdr *nlh, void *data); | |
115 | int rd_attr_cb(const struct nlattr *attr, void *data); | |
6ae54b13 | 116 | int rd_attr_check(const struct nlattr *attr, int *typep); |
33115275 SW |
117 | |
118 | /* | |
119 | * Print helpers | |
120 | */ | |
121 | void print_driver_table(struct rd *rd, struct nlattr *tb); | |
122 | void newline(struct rd *rd); | |
6ae54b13 | 123 | void newline_indent(struct rd *rd); |
33115275 SW |
124 | #define MAX_LINE_LENGTH 80 |
125 | ||
74bd75c2 | 126 | #endif /* _RDMA_TOOL_H_ */ |