FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
cli.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 #include <stdint.h>
18 #include <net/if.h>
19 #include <sys/ioctl.h>
20 #include <inttypes.h>
21 
22 #include <vlib/vlib.h>
23 #include <vlib/unix/unix.h>
24 #include <vlib/pci/pci.h>
25 #include <vnet/ethernet/ethernet.h>
26 
27 #include <rdma/rdma.h>
28 
29 static clib_error_t *
31  vlib_cli_command_t * cmd)
32 {
34 
35  if (!unformat_user (input, unformat_rdma_create_if_args, &args))
36  return clib_error_return (0, "unknown input `%U'",
37  format_unformat_error, input);
38 
39  rdma_create_if (vm, &args);
40 
41  vec_free (args.ifname);
42  vec_free (args.name);
43 
44  return args.error;
45 }
46 
47 /* *INDENT-OFF* */
49  .path = "create interface rdma",
50  .short_help = "create interface rdma <host-if ifname> [name <name>]"
51  " [rx-queue-size <size>] [tx-queue-size <size>]"
52  " [num-rx-queues <size>] [mode <auto|ibv|dv]"
53  " [no-multi-seg] [no-striding]"
54  " [max-pktlen <size>]",
55  .function = rdma_create_command_fn,
56 };
57 /* *INDENT-ON* */
58 
59 static clib_error_t *
61  vlib_cli_command_t * cmd)
62 {
63  unformat_input_t _line_input, *line_input = &_line_input;
64  u32 sw_if_index = ~0;
66  rdma_main_t *rm = &rdma_main;
67  rdma_device_t *rd;
68  vnet_main_t *vnm = vnet_get_main ();
69 
70  /* Get a line of input. */
71  if (!unformat_user (input, unformat_line_input, line_input))
72  return 0;
73 
74  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
75  {
76  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
77  ;
78  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
79  vnm, &sw_if_index))
80  ;
81  else
82  return clib_error_return (0, "unknown input `%U'",
83  format_unformat_error, input);
84  }
85  unformat_free (line_input);
86 
87  if (sw_if_index == ~0)
88  return clib_error_return (0,
89  "please specify interface name or sw_if_index");
90 
92  if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
93  return clib_error_return (0, "not a RDMA interface");
94 
95  rd = pool_elt_at_index (rm->devices, hw->dev_instance);
96 
97  rdma_delete_if (vm, rd);
98 
99  return 0;
100 }
101 
102 /* *INDENT-OFF* */
104  .path = "delete interface rdma",
105  .short_help = "delete interface rdma "
106  "{<interface> | sw_if_index <sw_idx>}",
107  .function = rdma_delete_command_fn,
108 };
109 /* *INDENT-ON* */
110 
111 static clib_error_t *
113  vlib_cli_command_t * cmd)
114 {
115  unformat_input_t _line_input, *line_input = &_line_input;
116  u32 sw_if_index = ~0;
118  rdma_main_t *rm = &rdma_main;
119  rdma_device_t *rd;
120  vnet_main_t *vnm = vnet_get_main ();
121  int i;
122 
123  /* Get a line of input. */
124  if (!unformat_user (input, unformat_line_input, line_input))
125  return 0;
126 
127  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
128  {
129  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
130  ;
131  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
132  vnm, &sw_if_index))
133  ;
134  else
135  return clib_error_return (0, "unknown input `%U'",
136  format_unformat_error, input);
137  }
138  unformat_free (line_input);
139 
140  if (sw_if_index == ~0)
141  return clib_error_return (0,
142  "please specify interface name or sw_if_index");
143 
145  if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
146  return clib_error_return (0, "not a RDMA interface");
147 
148  rd = pool_elt_at_index (rm->devices, hw->dev_instance);
149 
150  if ((rd->flags & RDMA_DEVICE_F_MLX5DV) == 0)
151  return clib_error_return (0, "not a mlx5 interface");
152 
153  vlib_cli_output (vm, "netdev %s pci-addr %U lkey 0x%x",
155  &rd->lkey);
156 
157  vec_foreach_index (i, rd->rxqs)
158  {
159  vlib_cli_output (vm, "RX queue %u\n %U\n", i, format_rdma_rxq, rd, i);
160  }
161 
162  return 0;
163 }
164 
165 /* *INDENT-OFF* */
167  .path = "test rdma dump",
168  .short_help = "test rdma dump {<interface> | sw_if_index <sw_idx>}",
169  .function = test_rdma_dump_command_fn,
170 };
171 /* *INDENT-ON* */
172 
173 clib_error_t *
175 {
176  return 0;
177 }
178 
180 
181 /*
182  * fd.io coding-style-patch-verification: ON
183  *
184  * Local Variables:
185  * eval: (c-set-style "gnu")
186  * End:
187  */
vlib.h
rdma_main_t::devices
rdma_device_t * devices
Definition: rdma.h:261
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
unformat_rdma_create_if_args
unformat_function_t unformat_rdma_create_if_args
Definition: rdma.h:305
rdma_create_if
void rdma_create_if(vlib_main_t *vm, rdma_create_if_args_t *args)
Definition: device.c:881
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
rdma_delete_if
void rdma_delete_if(vlib_main_t *vm, rdma_device_t *rd)
Definition: device.c:1052
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:549
rdma_device_class
vnet_device_class_t rdma_device_class
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
rdma_device_t::flags
u32 flags
Definition: rdma.h:201
rdma_create_if_args_t::error
clib_error_t * error
Definition: rdma.h:292
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
unformat_input_t
struct _unformat_input_t unformat_input_t
vnet_hw_interface_t::dev_instance
u32 dev_instance
Definition: interface.h:660
test_rdma_mlx5dv_dump_command
static vlib_cli_command_t test_rdma_mlx5dv_dump_command
(constructor) VLIB_CLI_COMMAND (test_rdma_mlx5dv_dump_command)
Definition: cli.c:166
ethernet.h
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
rdma_create_command_fn
static clib_error_t * rdma_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:30
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
rdma_device_t::pci
vlib_pci_device_info_t * pci
Definition: rdma.h:209
rdma_main
rdma_main_t rdma_main
Definition: device.c:47
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
rdma_device_t::linux_ifname
u8 * linux_ifname
Definition: rdma.h:211
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
rdma_main_t
Definition: rdma.h:258
vnet_get_sup_hw_interface_api_visible_or_null
static vnet_hw_interface_t * vnet_get_sup_hw_interface_api_visible_or_null(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:101
rdma_device_t::lkey
u32 lkey
Definition: rdma.h:205
vec_foreach_index
#define vec_foreach_index(var, v)
Iterate over vector indices.
Definition: vec_bootstrap.h:220
vnet_hw_interface_t::dev_class_index
u32 dev_class_index
Definition: interface.h:659
rdma_create_if_args_t
Definition: rdma.h:275
rdma_device_t
Definition: rdma.h:194
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
rdma_create_command
static vlib_cli_command_t rdma_create_command
(constructor) VLIB_CLI_COMMAND (rdma_create_command)
Definition: cli.c:48
format_vlib_pci_addr
format_function_t format_vlib_pci_addr
Definition: pci.h:326
format_rdma_rxq
format_function_t format_rdma_rxq
Definition: rdma.h:304
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:462
rdma_create_if_args_t::name
u8 * name
Definition: rdma.h:278
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
test_rdma_dump_command_fn
static clib_error_t * test_rdma_dump_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:112
pci.h
rdma_create_if_args_t::ifname
u8 * ifname
Definition: rdma.h:277
vlib_main_t
Definition: main.h:102
vlib_pci_device_info::addr
vlib_pci_addr_t addr
Definition: pci.h:66
clib_error_t
Definition: clib_error.h:21
unix.h
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
i
int i
Definition: flowhash_template.h:376
rdma_cli_init
clib_error_t * rdma_cli_init(vlib_main_t *vm)
Definition: cli.c:174
vlib_cli_command_t
Definition: cli.h:92
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
rdma_delete_command
static vlib_cli_command_t rdma_delete_command
(constructor) VLIB_CLI_COMMAND (rdma_delete_command)
Definition: cli.c:103
rdma_delete_command_fn
static clib_error_t * rdma_delete_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:60
rdma.h
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
rdma_device_t::rxqs
rdma_rxq_t * rxqs
Definition: rdma.h:199