FD.io VPP  v20.05.1-6-gf53edbc3b
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* */
48 VLIB_CLI_COMMAND (rdma_create_command, static) = {
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  .function = rdma_create_command_fn,
54 };
55 /* *INDENT-ON* */
56 
57 static clib_error_t *
59  vlib_cli_command_t * cmd)
60 {
61  unformat_input_t _line_input, *line_input = &_line_input;
62  u32 sw_if_index = ~0;
64  rdma_main_t *rm = &rdma_main;
65  rdma_device_t *rd;
66  vnet_main_t *vnm = vnet_get_main ();
67 
68  /* Get a line of input. */
69  if (!unformat_user (input, unformat_line_input, line_input))
70  return 0;
71 
72  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
73  {
74  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
75  ;
76  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
77  vnm, &sw_if_index))
78  ;
79  else
80  return clib_error_return (0, "unknown input `%U'",
81  format_unformat_error, input);
82  }
83  unformat_free (line_input);
84 
85  if (sw_if_index == ~0)
86  return clib_error_return (0,
87  "please specify interface name or sw_if_index");
88 
89  hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
90  if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
91  return clib_error_return (0, "not a RDMA interface");
92 
93  rd = pool_elt_at_index (rm->devices, hw->dev_instance);
94 
95  rdma_delete_if (vm, rd);
96 
97  return 0;
98 }
99 
100 /* *INDENT-OFF* */
101 VLIB_CLI_COMMAND (rdma_delete_command, static) = {
102  .path = "delete interface rdma",
103  .short_help = "delete interface rdma "
104  "{<interface> | sw_if_index <sw_idx>}",
105  .function = rdma_delete_command_fn,
106 };
107 /* *INDENT-ON* */
108 
109 static clib_error_t *
111  vlib_cli_command_t * cmd)
112 {
113  unformat_input_t _line_input, *line_input = &_line_input;
114  u32 sw_if_index = ~0;
116  rdma_main_t *rm = &rdma_main;
117  rdma_device_t *rd;
118  vnet_main_t *vnm = vnet_get_main ();
119  int i;
120 
121  /* Get a line of input. */
122  if (!unformat_user (input, unformat_line_input, line_input))
123  return 0;
124 
125  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
126  {
127  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
128  ;
129  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
130  vnm, &sw_if_index))
131  ;
132  else
133  return clib_error_return (0, "unknown input `%U'",
134  format_unformat_error, input);
135  }
136  unformat_free (line_input);
137 
138  if (sw_if_index == ~0)
139  return clib_error_return (0,
140  "please specify interface name or sw_if_index");
141 
142  hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
143  if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
144  return clib_error_return (0, "not a RDMA interface");
145 
146  rd = pool_elt_at_index (rm->devices, hw->dev_instance);
147 
148  if ((rd->flags & RDMA_DEVICE_F_MLX5DV) == 0)
149  return clib_error_return (0, "not a mlx5 interface");
150 
151  vlib_cli_output (vm, "netdev %s pci-addr %U lkey 0x%x",
153  &rd->lkey);
154 
155  vec_foreach_index (i, rd->rxqs)
156  {
157  vlib_cli_output (vm, "RX queue %u\n %U\n", i, format_rdma_rxq, rd, i);
158  }
159 
160  return 0;
161 }
162 
163 /* *INDENT-OFF* */
164 VLIB_CLI_COMMAND (test_rdma_mlx5dv_dump_command, static) = {
165  .path = "test rdma dump",
166  .short_help = "test rdma dump {<interface> | sw_if_index <sw_idx>}",
167  .function = test_rdma_dump_command_fn,
168 };
169 /* *INDENT-ON* */
170 
171 clib_error_t *
173 {
174  return 0;
175 }
176 
178 
179 /*
180  * fd.io coding-style-patch-verification: ON
181  *
182  * Local Variables:
183  * eval: (c-set-style "gnu")
184  * End:
185  */
#define vec_foreach_index(var, v)
Iterate over vector indices.
u8 * linux_ifname
Definition: rdma.h:167
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
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:110
vlib_pci_device_info_t * pci
Definition: rdma.h:165
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
rdma_main_t rdma_main
Definition: device.c:46
unformat_function_t unformat_vnet_sw_interface
static clib_error_t * rdma_delete_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:58
vl_api_interface_index_t sw_if_index
Definition: gre.api:53
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
rdma_device_t * devices
Definition: rdma.h:198
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned int u32
Definition: types.h:88
unformat_function_t unformat_rdma_create_if_args
Definition: rdma.h:237
u32 flags
Definition: rdma.h:157
unformat_function_t unformat_line_input
Definition: format.h:283
format_function_t format_rdma_rxq
Definition: rdma.h:236
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
struct _unformat_input_t unformat_input_t
vlib_main_t * vm
Definition: in2out_ed.c:1599
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
clib_error_t * rdma_cli_init(vlib_main_t *vm)
Definition: cli.c:172
clib_error_t * error
Definition: rdma.h:224
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
static vnet_hw_interface_t * vnet_get_sup_hw_interface_api_visible_or_null(vnet_main_t *vnm, u32 sw_if_index)
u32 lkey
Definition: rdma.h:161
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:152
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:689
vlib_pci_addr_t addr
Definition: pci.h:66
rdma_rxq_t * rxqs
Definition: rdma.h:155
vnet_device_class_t rdma_device_class
static void unformat_free(unformat_input_t *i)
Definition: format.h:163
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
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
void rdma_delete_if(vlib_main_t *vm, rdma_device_t *rd)
Definition: device.c:861
void rdma_create_if(vlib_main_t *vm, rdma_create_if_args_t *args)
Definition: device.c:703
format_function_t format_vlib_pci_addr
Definition: pci.h:324
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171