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