-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathusnic_devinfo.c
302 lines (262 loc) · 8.69 KB
/
usnic_devinfo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
* Copyright (c) 2016, Cisco Systems, Inc. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or the
* BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <ctype.h>
#include <rdma/fabric.h>
#include <rdma/fi_ext_usnic.h>
#include <rdma/fi_errno.h>
#include <string.h>
#include <arpa/inet.h>
#include <getopt.h>
#include <stdlib.h>
static int devinfo(struct fi_usnic_info *finfo, int brief)
{
int padding;
struct fi_usnic_info_v2 *info = &finfo->ui.v2;
struct fi_usnic_cap **cap;
struct in_addr in;
const char *desc;
in.s_addr = info->ui_ipaddr_be;
if (brief) {
printf("%8s: ", info->ui_devname);
printf("%5s ", info->ui_ifname);
printf("%02x:%02x:%02x:%02x:%02x:%02x ",
info->ui_mac_addr[0], info->ui_mac_addr[1],
info->ui_mac_addr[2], info->ui_mac_addr[3],
info->ui_mac_addr[4], info->ui_mac_addr[5]);
if (info->ui_ipaddr_be != 0) {
printf("%14s/%-2d ", inet_ntoa(in), info->ui_prefixlen);
} else {
printf("<IP not set> ");
}
if (info->ui_nicname != NULL && *info->ui_nicname != '\0')
printf("%10s ", info->ui_nicname);
else
printf("%10s ", info->ui_pid);
printf("%10s ", info->ui_firmware);
printf("%4s ", (info->ui_link_up) ? "UP" : "DOWN");
printf("\n");
return 0;
}
printf("%s:\n", info->ui_devname);
printf("\tInterface: %s\n", info->ui_ifname);
printf("\tMAC Address: %02x:%02x:%02x:%02x:%02x:%02x\n",
info->ui_mac_addr[0], info->ui_mac_addr[1],
info->ui_mac_addr[2], info->ui_mac_addr[3],
info->ui_mac_addr[4], info->ui_mac_addr[5]);
printf("\tIP Address: %s\n", (info->ui_ipaddr_be != 0) ?
inet_ntoa(in) : "<IP not set>");
in.s_addr = info->ui_netmask_be;
printf("\tNetmask: %s\n", (info->ui_netmask_be != 0) ?
inet_ntoa(in) : "<netmask not set>");
printf("\tPrefix len: %u\n", info->ui_prefixlen);
printf("\tMTU: %u\n", info->ui_mtu);
printf("\tLink State: %s\n",
(info->ui_link_up) ? "UP" : "DOWN");
printf("\tBandwidth: %u Gb/s\n",
info->ui_link_speed / 1000);
printf("\tDevice ID: %s ", info->ui_pid);
if (info->ui_nicname != NULL && *info->ui_nicname != '\0')
printf("[%s] ", info->ui_nicname);
printf("[0x%04x]\n", info->ui_device_id);
printf("\tVendor ID: %u\n", info->ui_vendor_id);
printf("\tVendor Part ID: %u\n", info->ui_vendor_part_id);
printf("\tFirmware: %s\n", info->ui_firmware);
printf("\tVFs: %u\n", info->ui_num_vf);
printf("\tCQ per VF: %u\n", info->ui_cq_per_vf);
printf("\tQP per VF: %u\n", info->ui_qp_per_vf);
printf("\tInterrupts per VF: %u\n", info->ui_intr_per_vf);
printf("\tMax CQ: %u\n", info->ui_max_cq);
printf("\tMax CQ Entries: %u\n", info->ui_max_cqe);
printf("\tMax QP: %u\n", info->ui_max_qp);
printf("\tMax Send Credits: %u\n", info->ui_max_send_credits);
printf("\tMax Recv Credits: %u\n", info->ui_max_recv_credits);
printf("\tCapabilities:\n");
for (cap = info->ui_caps; *cap; cap++) {
if (strcmp((*cap)->uc_capability, "USD_CAP_CQ_SHARING")
== 0) {
// This capability was never released to customers
continue;
} else if (strcmp((*cap)->uc_capability, "USD_CAP_MAP_PER_RES")
== 0) {
desc = "Map per res";
} else if (strcmp((*cap)->uc_capability, "USD_CAP_PIO")
== 0) {
desc = "PIO sends";
} else if (strcmp((*cap)->uc_capability, "USD_CAP_CQ_INTR")
== 0) {
// This capability was never released to customers
continue;
} else if (strcmp((*cap)->uc_capability, "USD_CAP_GRP_INTR")
== 0) {
desc = "CQ interrupts";
} else {
desc = (*cap)->uc_capability;
}
// 25 is the indenting level of all the other printf's
padding = 25 - 3 - (int) strlen(desc);
padding = (padding < 0) ? 0 : padding;
printf("\t %s:%*s%s\n", desc, padding, "",
(*cap)->uc_present ? "yes" : "no");
}
return 0;
}
static long parse_long(char *str)
{
long ret;
char *end;
/* If usnic_ is given, then strtol will not perform conversion and this
* function will return 0. Instead special case it as an error.
*/
if (strlen(str) == 0) {
fprintf(stderr, "error: Invalid device name given\n");
return -EINVAL;
}
errno = 0;
ret = strtol(str, &end, 10);
if (*end != '\0' || errno != 0) {
ret = (errno == 0) ? -EINVAL : -errno;
fprintf(stderr, "error: Couldn't parse \"%s\": %s\n", str,
strerror(-ret));
return ret;
}
/* If for some reason usnic_-1 or something is given, then this will be
* confusing since this function reserves negative return values for
* errors.
*/
if (ret < 0) {
fprintf(stderr, "error: Invalid device name given\n");
return -EINVAL;
}
return ret;
}
static void show_help(const char *argv0)
{
printf("Usage: %s [-b] [-d device]\n", argv0);
printf("\n");
printf("-b - Brief output\n");
printf("-d device - Specify the local device (e.g., -d 0 or -d usnic_0)\n");
}
int main(int argc, char *argv[]) {
struct fi_info *hints;
struct fi_info *info;
struct fi_info *info_list;
struct fi_usnic_info usnic_info;
struct fi_usnic_ops_fabric *usnic_fabric_ops;
struct fid_fabric *fabric;
struct fi_usnic_cap **cap;
int c;
char name[32];
int brief = 0;
long devno = -1;
int ret;
while ((c = getopt(argc, argv, "bd:h")) != -1) {
switch (c) {
case 'b':
brief = 1;
break;
case 'd':
if (isdigit(optarg[0])) {
devno = parse_long(optarg);
} else if (strncmp(optarg, "usnic_", 6) == 0) {
devno = parse_long(optarg + 6);
} else {
fprintf(stderr, "error: %s: Bad device\n",
optarg);
}
if (devno < 0)
return EXIT_FAILURE;
break;
case 'h':
show_help(argv[0]);
return EXIT_SUCCESS;
default:
show_help(argv[0]);
return EXIT_FAILURE;
}
}
hints = fi_allocinfo();
hints->fabric_attr->prov_name = strdup("usnic");
hints->ep_attr->type = FI_EP_DGRAM;
hints->caps = FI_MSG;
#if FI_MAJOR_VERSION < 2
hints->mode = FI_LOCAL_MR;
#endif
hints->addr_format = FI_SOCKADDR;
if (devno != -1) {
sprintf(name, "usnic_%ld", devno);
hints->fabric_attr->name = strdup(name);
}
ret = fi_getinfo(FI_VERSION(1, 2), NULL, 0, 0, hints, &info_list);
if (ret) {
fprintf(stderr, "getinfo: %s\n", fi_strerror(-ret));
return -ret;
}
for (info = info_list; info; info = info->next) {
ret = fi_fabric(info->fabric_attr, &fabric, NULL);
if (ret) {
fprintf(stderr, "fabric: %s\n", fi_strerror(-ret));
return -ret;
}
ret = fi_open_ops(&fabric->fid, FI_USNIC_FABRIC_OPS_1, 0,
(void **) &usnic_fabric_ops, NULL);
if (ret) {
fprintf(stderr, "fi_open_ops: %s\n", fi_strerror(-ret));
return -ret;
}
ret = usnic_fabric_ops->getinfo(FI_EXT_USNIC_INFO_VERSION,
fabric, &usnic_info);
if (ret) {
fprintf(stderr, "usnic_getinfo: %s\n", fi_strerror(-ret));
return -ret;
}
ret = devinfo(&usnic_info, brief);
if (ret)
return ret;
for (cap = usnic_info.ui.v2.ui_caps; *cap; cap++) {
free(*cap);
}
free(usnic_info.ui.v2.ui_caps);
ret = fi_close(&fabric->fid);
if (ret) {
fprintf(stderr, "fi_close: %s\n", fi_strerror(-ret));
return -ret;
}
}
fi_freeinfo(info_list);
fi_freeinfo(hints);
return 0;
}