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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
19 #include <sys/ioctl.h>
22 #include <vlib/vlib.h>
23 #include <vlib/unix/unix.h>
24 #include <vlib/pci/pci.h>
25 #include <vnet/ethernet/ethernet.h>
27 #include <rdma/rdma.h>
30 rdma_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
31 vlib_cli_command_t * cmd)
33 rdma_create_if_args_t args;
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);
39 rdma_create_if (vm, &args);
41 vec_free (args.ifname);
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 " [no-multi-seg] [no-striding]"
54 " [max-pktlen <size>]",
55 .function = rdma_create_command_fn,
60 rdma_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
61 vlib_cli_command_t * cmd)
63 unformat_input_t _line_input, *line_input = &_line_input;
65 vnet_hw_interface_t *hw;
66 rdma_main_t *rm = &rdma_main;
68 vnet_main_t *vnm = vnet_get_main ();
70 /* Get a line of input. */
71 if (!unformat_user (input, unformat_line_input, line_input))
74 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
76 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
78 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
82 return clib_error_return (0, "unknown input `%U'",
83 format_unformat_error, input);
85 unformat_free (line_input);
87 if (sw_if_index == ~0)
88 return clib_error_return (0,
89 "please specify interface name or sw_if_index");
91 hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
92 if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
93 return clib_error_return (0, "not a RDMA interface");
95 rd = pool_elt_at_index (rm->devices, hw->dev_instance);
97 rdma_delete_if (vm, rd);
103 VLIB_CLI_COMMAND (rdma_delete_command, static) = {
104 .path = "delete interface rdma",
105 .short_help = "delete interface rdma "
106 "{<interface> | sw_if_index <sw_idx>}",
107 .function = rdma_delete_command_fn,
111 static clib_error_t *
112 test_rdma_dump_command_fn (vlib_main_t * vm, unformat_input_t * input,
113 vlib_cli_command_t * cmd)
115 unformat_input_t _line_input, *line_input = &_line_input;
116 u32 sw_if_index = ~0;
117 vnet_hw_interface_t *hw;
118 rdma_main_t *rm = &rdma_main;
120 vnet_main_t *vnm = vnet_get_main ();
123 /* Get a line of input. */
124 if (!unformat_user (input, unformat_line_input, line_input))
127 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
129 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
131 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
135 return clib_error_return (0, "unknown input `%U'",
136 format_unformat_error, input);
138 unformat_free (line_input);
140 if (sw_if_index == ~0)
141 return clib_error_return (0,
142 "please specify interface name or sw_if_index");
144 hw = vnet_get_sup_hw_interface_api_visible_or_null (vnm, sw_if_index);
145 if (hw == NULL || rdma_device_class.index != hw->dev_class_index)
146 return clib_error_return (0, "not a RDMA interface");
148 rd = pool_elt_at_index (rm->devices, hw->dev_instance);
150 if ((rd->flags & RDMA_DEVICE_F_MLX5DV) == 0)
151 return clib_error_return (0, "not a mlx5 interface");
153 vlib_cli_output (vm, "netdev %s pci-addr %U lkey 0x%x",
154 rd->linux_ifname, format_vlib_pci_addr, &rd->pci->addr,
157 vec_foreach_index (i, rd->rxqs)
159 vlib_cli_output (vm, "RX queue %u\n %U\n", i, format_rdma_rxq, rd, i);
166 VLIB_CLI_COMMAND (test_rdma_mlx5dv_dump_command, static) = {
167 .path = "test rdma dump",
168 .short_help = "test rdma dump {<interface> | sw_if_index <sw_idx>}",
169 .function = test_rdma_dump_command_fn,
174 rdma_cli_init (vlib_main_t * vm)
179 VLIB_INIT_FUNCTION (rdma_cli_init);
182 * fd.io coding-style-patch-verification: ON
185 * eval: (c-set-style "gnu")