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"
23#include "utils.h"
24#include "json_writer.h"
25
26#define pr_err(args...) fprintf(stderr, ##args)
27#define pr_out(args...) fprintf(stdout, ##args)
28
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
32struct dev_map {
33	struct list_head list;
34	char *dev_name;
35	uint32_t num_ports;
36	uint32_t idx;
37};
38
39struct rd {
40	int argc;
41	char **argv;
42	char *filename;
43	bool show_details;
44	struct list_head dev_map_list;
45	uint32_t dev_idx;
46	uint32_t port_idx;
47	struct mnl_socket *nl;
48	struct nlmsghdr *nlh;
49	char *buff;
50	json_writer_t *jw;
51	bool json_output;
52	bool pretty_output;
53};
54
55struct rd_cmd {
56	const char *cmd;
57	int (*func)(struct rd *rd);
58};
59
60/*
61 * Parser interface
62 */
63bool rd_no_arg(struct rd *rd);
64void rd_arg_inc(struct rd *rd);
65
66char *rd_argv(struct rd *rd);
67uint32_t get_port_from_argv(struct rd *rd);
68
69/*
70 * Commands interface
71 */
72int cmd_dev(struct rd *rd);
73int cmd_link(struct rd *rd);
74int rd_exec_cmd(struct rd *rd, const struct rd_cmd *c, const char *str);
75
76/*
77 * Device manipulation
78 */
79void rd_free_devmap(struct rd *rd);
80struct dev_map *dev_map_lookup(struct rd *rd, bool allow_port_index);
81struct dev_map *_dev_map_lookup(struct rd *rd, const char *dev_name);
82
83/*
84 * Netlink
85 */
86int rd_send_msg(struct rd *rd);
87int rd_recv_msg(struct rd *rd, mnl_cb_t callback, void *data, uint32_t seq);
88void rd_prepare_msg(struct rd *rd, uint32_t cmd, uint32_t *seq, uint16_t flags);
89int rd_dev_init_cb(const struct nlmsghdr *nlh, void *data);
90int rd_attr_cb(const struct nlattr *attr, void *data);
91#endif /* _RDMA_TOOL_H_ */
92