]> git.proxmox.com Git - mirror_iproute2.git/blob - rdma/rdma.h
rdma: Move resource QP logic to separate file
[mirror_iproute2.git] / rdma / rdma.h
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 <netinet/in.h>
19 #include <libmnl/libmnl.h>
20 #include <rdma/rdma_netlink.h>
21 #include <rdma/rdma_user_cm.h>
22 #include <time.h>
23 #include <net/if_arp.h>
24
25 #include "list.h"
26 #include "utils.h"
27 #include "json_writer.h"
28
29 #define pr_err(args...) fprintf(stderr, ##args)
30 #define pr_out(args...) fprintf(stdout, ##args)
31
32 #define RDMA_BITMAP_ENUM(name, bit_no) RDMA_BITMAP_##name = BIT(bit_no),
33 #define RDMA_BITMAP_NAMES(name, bit_no) [bit_no] = #name,
34
35 #define MAX_NUMBER_OF_FILTERS 64
36 struct filters {
37 const char *name;
38 bool is_number;
39 };
40
41 struct filter_entry {
42 struct list_head list;
43 char *key;
44 char *value;
45 };
46
47 struct dev_map {
48 struct list_head list;
49 char *dev_name;
50 uint32_t num_ports;
51 uint32_t idx;
52 };
53
54 struct rd {
55 int argc;
56 char **argv;
57 char *filename;
58 bool show_details;
59 bool show_driver_details;
60 struct list_head dev_map_list;
61 uint32_t dev_idx;
62 uint32_t port_idx;
63 struct mnl_socket *nl;
64 struct nlmsghdr *nlh;
65 char *buff;
66 json_writer_t *jw;
67 bool json_output;
68 bool pretty_output;
69 struct list_head filter_list;
70 };
71
72 struct rd_cmd {
73 const char *cmd;
74 int (*func)(struct rd *rd);
75 };
76
77 /*
78 * Parser interface
79 */
80 bool rd_no_arg(struct rd *rd);
81 void rd_arg_inc(struct rd *rd);
82
83 char *rd_argv(struct rd *rd);
84
85 /*
86 * Commands interface
87 */
88 int cmd_dev(struct rd *rd);
89 int cmd_link(struct rd *rd);
90 int cmd_res(struct rd *rd);
91 int rd_exec_cmd(struct rd *rd, const struct rd_cmd *c, const char *str);
92 int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd));
93 int rd_exec_require_dev(struct rd *rd, int (*cb)(struct rd *rd));
94 int rd_exec_link(struct rd *rd, int (*cb)(struct rd *rd), bool strict_port);
95 void rd_free(struct rd *rd);
96 int rd_set_arg_to_devname(struct rd *rd);
97 int rd_argc(struct rd *rd);
98
99 int strcmpx(const char *str1, const char *str2);
100
101 /*
102 * Device manipulation
103 */
104 struct dev_map *dev_map_lookup(struct rd *rd, bool allow_port_index);
105
106 /*
107 * Filter manipulation
108 */
109 int rd_build_filter(struct rd *rd, const struct filters valid_filters[]);
110 bool rd_check_is_filtered(struct rd *rd, const char *key, uint32_t val);
111 bool rd_check_is_string_filtered(struct rd *rd, const char *key, const char *val);
112 bool rd_check_is_key_exist(struct rd *rd, const char *key);
113 /*
114 * Netlink
115 */
116 int rd_send_msg(struct rd *rd);
117 int rd_recv_msg(struct rd *rd, mnl_cb_t callback, void *data, uint32_t seq);
118 void rd_prepare_msg(struct rd *rd, uint32_t cmd, uint32_t *seq, uint16_t flags);
119 int rd_dev_init_cb(const struct nlmsghdr *nlh, void *data);
120 int rd_attr_cb(const struct nlattr *attr, void *data);
121 int rd_attr_check(const struct nlattr *attr, int *typep);
122
123 /*
124 * Print helpers
125 */
126 void print_driver_table(struct rd *rd, struct nlattr *tb);
127 void newline(struct rd *rd);
128 void newline_indent(struct rd *rd);
129 #define MAX_LINE_LENGTH 80
130
131 #endif /* _RDMA_TOOL_H_ */