]> git.proxmox.com Git - mirror_iproute2.git/blame_incremental - rdma/rdma.h
rdma: Perform single .doit call to query specific objects
[mirror_iproute2.git] / rdma / rdma.h
... / ...
CommitLineData
1/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2/*
3 * rdma.c RDMA tool
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>
13#include <netinet/in.h>
14#include <libmnl/libmnl.h>
15#include <rdma/rdma_netlink.h>
16#include <rdma/rdma_user_cm.h>
17#include <time.h>
18#include <net/if_arp.h>
19
20#include "list.h"
21#include "utils.h"
22#include "json_writer.h"
23
24#define pr_err(args...) fprintf(stderr, ##args)
25#define pr_out(args...) fprintf(stdout, ##args)
26
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
30#define MAX_NUMBER_OF_FILTERS 64
31struct filters {
32 const char *name;
33 uint8_t is_number:1;
34 uint8_t is_doit:1;
35};
36
37struct filter_entry {
38 struct list_head list;
39 char *key;
40 char *value;
41 /*
42 * This field menas that we can try to issue .doit calback
43 * on value above. This value can be converted to integer
44 * with simple atoi(). Otherwise "is_doit" will be false.
45 */
46 uint8_t is_doit:1;
47};
48
49struct dev_map {
50 struct list_head list;
51 char *dev_name;
52 uint32_t num_ports;
53 uint32_t idx;
54};
55
56struct rd {
57 int argc;
58 char **argv;
59 char *filename;
60 bool show_details;
61 bool show_driver_details;
62 struct list_head dev_map_list;
63 uint32_t dev_idx;
64 uint32_t port_idx;
65 struct mnl_socket *nl;
66 struct nlmsghdr *nlh;
67 char *buff;
68 json_writer_t *jw;
69 bool json_output;
70 bool pretty_output;
71 struct list_head filter_list;
72};
73
74struct rd_cmd {
75 const char *cmd;
76 int (*func)(struct rd *rd);
77};
78
79/*
80 * Parser interface
81 */
82bool rd_no_arg(struct rd *rd);
83void rd_arg_inc(struct rd *rd);
84
85char *rd_argv(struct rd *rd);
86
87/*
88 * Commands interface
89 */
90int cmd_dev(struct rd *rd);
91int cmd_link(struct rd *rd);
92int cmd_res(struct rd *rd);
93int rd_exec_cmd(struct rd *rd, const struct rd_cmd *c, const char *str);
94int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd));
95int rd_exec_require_dev(struct rd *rd, int (*cb)(struct rd *rd));
96int rd_exec_link(struct rd *rd, int (*cb)(struct rd *rd), bool strict_port);
97void rd_free(struct rd *rd);
98int rd_set_arg_to_devname(struct rd *rd);
99int rd_argc(struct rd *rd);
100
101int strcmpx(const char *str1, const char *str2);
102
103/*
104 * Device manipulation
105 */
106struct dev_map *dev_map_lookup(struct rd *rd, bool allow_port_index);
107
108/*
109 * Filter manipulation
110 */
111bool rd_doit_index(struct rd *rd, uint32_t *idx);
112int rd_build_filter(struct rd *rd, const struct filters valid_filters[]);
113bool rd_check_is_filtered(struct rd *rd, const char *key, uint32_t val);
114bool rd_check_is_string_filtered(struct rd *rd, const char *key, const char *val);
115bool rd_check_is_key_exist(struct rd *rd, const char *key);
116/*
117 * Netlink
118 */
119int rd_send_msg(struct rd *rd);
120int rd_recv_msg(struct rd *rd, mnl_cb_t callback, void *data, uint32_t seq);
121void rd_prepare_msg(struct rd *rd, uint32_t cmd, uint32_t *seq, uint16_t flags);
122int rd_dev_init_cb(const struct nlmsghdr *nlh, void *data);
123int rd_attr_cb(const struct nlattr *attr, void *data);
124int rd_attr_check(const struct nlattr *attr, int *typep);
125
126/*
127 * Print helpers
128 */
129void print_driver_table(struct rd *rd, struct nlattr *tb);
130void newline(struct rd *rd);
131void newline_indent(struct rd *rd);
132#define MAX_LINE_LENGTH 80
133
134#endif /* _RDMA_TOOL_H_ */