| 1 |
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ |
| 2 |
/* |
| 3 |
* rdma.c RDMA tool |
| 4 |
* Authors: Leon Romanovsky <[email protected]> |
| 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 <time.h> |
| 14 |
#include <libgen.h> |
| 15 |
#include <netinet/in.h> |
| 16 |
#include <libmnl/libmnl.h> |
| 17 |
#include <rdma/rdma_netlink.h> |
| 18 |
#include <rdma/rdma_user_cm.h> |
| 19 |
#include <net/if_arp.h> |
| 20 |
|
| 21 |
#include "list.h" |
| 22 |
#include "utils.h" |
| 23 |
#include "mnl_utils.h" |
| 24 |
#include "json_print.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 |
|
| 32 |
#define MAX_NUMBER_OF_FILTERS 64 |
| 33 |
struct filters { |
| 34 |
const char *name; |
| 35 |
uint8_t is_number:1; |
| 36 |
uint8_t is_doit:1; |
| 37 |
}; |
| 38 |
|
| 39 |
struct filter_entry { |
| 40 |
struct list_head list; |
| 41 |
char *key; |
| 42 |
char *value; |
| 43 |
/* |
| 44 |
* This field means that we can try to issue .doit callback |
| 45 |
* on value above. This value can be converted to integer |
| 46 |
* with simple atoi(). Otherwise "is_doit" will be false. |
| 47 |
*/ |
| 48 |
uint8_t is_doit:1; |
| 49 |
}; |
| 50 |
|
| 51 |
struct dev_map { |
| 52 |
struct list_head list; |
| 53 |
char *dev_name; |
| 54 |
uint32_t num_ports; |
| 55 |
uint32_t idx; |
| 56 |
}; |
| 57 |
|
| 58 |
struct rd { |
| 59 |
int argc; |
| 60 |
char **argv; |
| 61 |
char *filename; |
| 62 |
uint8_t show_details:1; |
| 63 |
uint8_t show_driver_details:1; |
| 64 |
uint8_t show_raw:1; |
| 65 |
uint8_t suppress_errors:1; |
| 66 |
struct list_head dev_map_list; |
| 67 |
uint32_t dev_idx; |
| 68 |
uint32_t port_idx; |
| 69 |
struct mnl_socket *nl; |
| 70 |
struct nlmsghdr *nlh; |
| 71 |
char *buff; |
| 72 |
json_writer_t *jw; |
| 73 |
struct list_head filter_list; |
| 74 |
char *link_name; |
| 75 |
char *link_type; |
| 76 |
char *dev_name; |
| 77 |
int dev_type; |
| 78 |
}; |
| 79 |
|
| 80 |
struct rd_cmd { |
| 81 |
const char *cmd; |
| 82 |
int (*func)(struct rd *rd); |
| 83 |
}; |
| 84 |
|
| 85 |
/* |
| 86 |
* Parser interface |
| 87 |
*/ |
| 88 |
bool rd_no_arg(struct rd *rd); |
| 89 |
bool rd_is_multiarg(struct rd *rd); |
| 90 |
void rd_arg_inc(struct rd *rd); |
| 91 |
|
| 92 |
char *rd_argv(struct rd *rd); |
| 93 |
|
| 94 |
/* |
| 95 |
* Commands interface |
| 96 |
*/ |
| 97 |
int cmd_dev(struct rd *rd); |
| 98 |
int cmd_link(struct rd *rd); |
| 99 |
int cmd_res(struct rd *rd); |
| 100 |
int cmd_sys(struct rd *rd); |
| 101 |
int cmd_stat(struct rd *rd); |
| 102 |
int cmd_mon(struct rd* rd); |
| 103 |
int rd_exec_cmd(struct rd *rd, const struct rd_cmd *c, const char *str); |
| 104 |
int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd)); |
| 105 |
int rd_exec_require_dev(struct rd *rd, int (*cb)(struct rd *rd)); |
| 106 |
int rd_exec_link(struct rd *rd, int (*cb)(struct rd *rd), bool strict_port); |
| 107 |
void rd_free(struct rd *rd); |
| 108 |
int rd_set_arg_to_devname(struct rd *rd); |
| 109 |
int rd_argc(struct rd *rd); |
| 110 |
|
| 111 |
int strcmpx(const char *str1, const char *str2); |
| 112 |
|
| 113 |
/* |
| 114 |
* Device manipulation |
| 115 |
*/ |
| 116 |
struct dev_map *dev_map_lookup(struct rd *rd, bool allow_port_index); |
| 117 |
|
| 118 |
/* |
| 119 |
* Filter manipulation |
| 120 |
*/ |
| 121 |
bool rd_doit_index(struct rd *rd, uint32_t *idx); |
| 122 |
int rd_build_filter(struct rd *rd, const struct filters valid_filters[]); |
| 123 |
bool rd_is_filtered_attr(struct rd *rd, const char *key, uint32_t val, |
| 124 |
struct nlattr *attr); |
| 125 |
bool rd_is_string_filtered_attr(struct rd *rd, const char *key, const char *val, |
| 126 |
struct nlattr *attr); |
| 127 |
/* |
| 128 |
* Netlink |
| 129 |
*/ |
| 130 |
int rd_send_msg(struct rd *rd); |
| 131 |
int rd_recv_msg(struct rd *rd, mnl_cb_t callback, void *data, uint32_t seq); |
| 132 |
int rd_sendrecv_msg(struct rd *rd, unsigned int seq); |
| 133 |
void rd_prepare_msg(struct rd *rd, uint32_t cmd, uint32_t *seq, uint16_t flags); |
| 134 |
int rd_dev_init_cb(const struct nlmsghdr *nlh, void *data); |
| 135 |
int rd_attr_cb(const struct nlattr *attr, void *data); |
| 136 |
|
| 137 |
/* |
| 138 |
* Print helpers |
| 139 |
*/ |
| 140 |
void print_driver_table(struct rd *rd, struct nlattr *tb); |
| 141 |
void print_raw_data(struct rd *rd, struct nlattr **nla_line); |
| 142 |
void newline_indent(void); |
| 143 |
void newline(void); |
| 144 |
|
| 145 |
#define MAX_LINE_LENGTH 80 |
| 146 |
|
| 147 |
|
| 148 |
#endif /* _RDMA_TOOL_H_ */ |