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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
|
/* SPDX-License-Identifier: Apache-2.0
* Copyright (c) 2023 Cisco Systems, Inc.
*/
#include <vnet/vnet.h>
#include <vnet/dev/dev.h>
#include <vnet/dev/counters.h>
#include <vnet/ethernet/ethernet.h>
u8 *
format_vnet_dev_rv (u8 *s, va_list *args)
{
vnet_dev_rv_t rv = va_arg (*args, vnet_dev_rv_t);
u32 index = -rv;
char *strings[] = { [0] = "OK",
#define _(n, d) [-VNET_DEV_ERR_##n] = d,
foreach_vnet_dev_rv_type
#undef _
};
if (index >= ARRAY_LEN (strings))
return format (s, "unknown return value (%d)", rv);
return format (s, "%s", strings[index]);
}
u8 *
format_vnet_dev_addr (u8 *s, va_list *args)
{
vnet_dev_main_t *dm = &vnet_dev_main;
vnet_dev_t *dev = va_arg (*args, vnet_dev_t *);
vnet_dev_bus_t *bus;
if (dev == 0)
return 0;
bus = pool_elt_at_index (dm->buses, dev->bus_index);
s = format (s, "%U", bus->ops.format_device_addr, dev);
return s;
}
u8 *
format_vnet_dev_interface_name (u8 *s, va_list *args)
{
u32 i = va_arg (*args, u32);
vnet_dev_port_t *port = vnet_dev_get_port_from_dev_instance (i);
return format (s, "%s", port->intf.name);
}
u8 *
format_vnet_dev_info (u8 *s, va_list *args)
{
vnet_dev_format_args_t *a = va_arg (*args, vnet_dev_format_args_t *);
vlib_main_t *vm = vlib_get_main ();
vnet_dev_main_t *dm = &vnet_dev_main;
vnet_dev_t *dev = va_arg (*args, vnet_dev_t *);
vnet_dev_driver_t *dr = pool_elt_at_index (dm->drivers, dev->driver_index);
vnet_dev_bus_t *bus = pool_elt_at_index (dm->buses, dev->bus_index);
u32 indent = format_get_indent (s);
s = format (s, "Driver is '%s', bus is '%s'", dr->registration->name,
bus->registration->name);
if (dev->description)
s = format (s, ", description is '%v'", dev->description);
if (bus->ops.format_device_info)
s = format (s, "\n%U%U", format_white_space, indent,
bus->ops.format_device_info, a, dev);
s = format (s, "\n%UAssigned process node is '%U'", format_white_space,
indent, format_vlib_node_name, vm, dev->process_node_index);
if (dev->args)
s = format (s, "\n%UDevice Specific Arguments:\n%U%U", format_white_space,
indent, format_white_space, indent + 2, format_vnet_dev_args,
dev->args);
if (dev->ops.format_info)
s =
format (s, "\n%UDevice Specific Info:\n%U%U", format_white_space, indent,
format_white_space, indent + 2, dev->ops.format_info, a, dev);
return s;
}
u8 *
format_vnet_dev_hw_addr (u8 *s, va_list *args)
{
vnet_dev_hw_addr_t *addr = va_arg (*args, vnet_dev_hw_addr_t *);
return format (s, "%U", format_ethernet_address, addr->eth_mac);
}
u8 *
format_vnet_dev_port_info (u8 *s, va_list *args)
{
vnet_dev_format_args_t *a = va_arg (*args, vnet_dev_format_args_t *);
vlib_main_t *vm = vlib_get_main ();
vnet_main_t *vnm = vnet_get_main ();
vnet_dev_port_t *port = va_arg (*args, vnet_dev_port_t *);
u32 indent = format_get_indent (s);
s = format (s, "Hardware Address is %U", format_vnet_dev_hw_addr,
&port->attr.hw_addr);
s = format (s, ", %u RX queues (max %u), %u TX queues (max %u)",
pool_elts (port->rx_queues), port->attr.max_rx_queues,
pool_elts (port->tx_queues), port->attr.max_tx_queues);
if (pool_elts (port->secondary_hw_addr))
{
u32 i = 0;
vnet_dev_hw_addr_t *a;
s = format (s, "\n%USecondary Hardware Address%s:", format_white_space,
indent,
pool_elts (port->secondary_hw_addr) > 1 ? "es are" : " is");
pool_foreach (a, port->secondary_hw_addr)
{
if (i++ % 6 == 0)
s = format (s, "\n%U", format_white_space, indent + 1);
s = format (s, " %U", format_vnet_dev_hw_addr, a);
}
}
s = format (s, "\n%UMax RX frame size is %u (max supported %u)",
format_white_space, indent, port->max_rx_frame_size,
port->attr.max_supported_rx_frame_size);
s = format (s, "\n%UCaps: %U", format_white_space, indent,
format_vnet_dev_port_caps, &port->attr.caps);
s = format (s, "\n%URX Offloads: %U", format_white_space, indent,
format_vnet_dev_port_rx_offloads, &port->attr.rx_offloads);
s = format (s, "\n%UTX Offloads: %U", format_white_space, indent,
format_vnet_dev_port_tx_offloads, &port->attr.tx_offloads);
if (port->port_ops.format_status)
s = format (s, "\n%UDevice Specific Port Status:\n%U%U",
format_white_space, indent, format_white_space, indent + 2,
port->port_ops.format_status, a, port);
if (port->args)
s = format (s, "\n%UDevice Specific Port Arguments:\n%U%U",
format_white_space, indent, format_white_space, indent + 2,
format_vnet_dev_args, port->args);
s = format (s, "\n%UInterface ", format_white_space, indent);
if (port->interface_created)
{
s = format (s, "assigned, interface name is '%U', RX node is '%U'",
format_vnet_sw_if_index_name, vnm, port->intf.sw_if_index,
format_vlib_node_name, vm, port->intf.rx_node_index);
}
else
s = format (s, "not assigned");
return s;
}
u8 *
format_vnet_dev_rx_queue_info (u8 *s, va_list *args)
{
vnet_dev_format_args_t __clib_unused *a =
va_arg (*args, vnet_dev_format_args_t *);
vnet_dev_rx_queue_t *rxq = va_arg (*args, vnet_dev_rx_queue_t *);
u32 indent = format_get_indent (s);
s = format (s, "Size is %u, buffer pool index is %u", rxq->size,
vnet_dev_get_rx_queue_buffer_pool_index (rxq));
s = format (s, "\n%UPolling thread is %u, %sabled, %sstarted, %s mode",
format_white_space, indent, rxq->rx_thread_index,
rxq->enabled ? "en" : "dis", rxq->started ? "" : "not-",
rxq->interrupt_mode ? "interrupt" : "polling");
return s;
}
u8 *
format_vnet_dev_tx_queue_info (u8 *s, va_list *args)
{
vnet_dev_format_args_t __clib_unused *a =
va_arg (*args, vnet_dev_format_args_t *);
vnet_dev_tx_queue_t *txq = va_arg (*args, vnet_dev_tx_queue_t *);
u32 indent = format_get_indent (s);
u32 n;
s = format (s, "Size is %u", txq->size);
s = format (s, "\n%U", format_white_space, indent);
n = clib_bitmap_count_set_bits (txq->assigned_threads);
if (n == 0)
s = format (s, "Not used by any thread");
else
s = format (s, "Used by thread%s %U", n > 1 ? "s" : "", format_bitmap_list,
txq->assigned_threads);
return s;
}
u8 *
format_vnet_dev_interface_info (u8 *s, va_list *args)
{
u32 i = va_arg (*args, u32);
vnet_dev_format_args_t fa = {}, *a = &fa;
vnet_dev_port_t *port = vnet_dev_get_port_from_dev_instance (i);
vnet_dev_t *dev = port->dev;
u32 indent = format_get_indent (s);
s = format (s, "Device:");
s = format (s, "\n%U%U", format_white_space, indent + 2,
format_vnet_dev_info, a, dev);
s = format (s, "\n%UPort %u:", format_white_space, indent, port->port_id);
s = format (s, "\n%U%U", format_white_space, indent + 2,
format_vnet_dev_port_info, a, port);
foreach_vnet_dev_port_rx_queue (q, port)
{
s = format (s, "\n%URX queue %u:", format_white_space, indent + 2,
q->queue_id);
s = format (s, "\n%U%U", format_white_space, indent + 4,
format_vnet_dev_rx_queue_info, a, q);
}
foreach_vnet_dev_port_tx_queue (q, port)
{
s = format (s, "\n%UTX queue %u:", format_white_space, indent + 2,
q->queue_id);
s = format (s, "\n%U%U", format_white_space, indent + 4,
format_vnet_dev_tx_queue_info, a, q);
}
return s;
}
static u64
unformat_flags (unformat_input_t *input, char *names[], u64 val[], u32 n_flags)
{
u64 rv = 0;
uword c = 0;
u8 *s = 0;
while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
{
switch (c)
{
case 'a' ... 'z':
c -= 'a' - 'A';
case '0' ... '9':
case 'A' ... 'Z':
vec_add1 (s, c);
break;
case '-':
vec_add1 (s, '_');
break;
case ',':
vec_add1 (s, 0);
break;
default:
goto end_of_string;
}
}
end_of_string:
if (s == 0)
return 0;
vec_add1 (s, 0);
for (u8 *p = s, *end = vec_end (s); p < end; p += strlen ((char *) p) + 1)
{
for (c = 0; c < n_flags; c++)
if (strcmp (names[c], (char *) p) == 0)
{
rv |= val[c];
break;
}
if (c == n_flags)
goto done;
}
done:
vec_free (s);
return rv;
}
uword
unformat_vnet_dev_flags (unformat_input_t *input, va_list *args)
{
vnet_dev_flags_t *fp = va_arg (*args, vnet_dev_flags_t *);
u64 val;
char *names[] = {
#define _(b, n, d) #n,
foreach_vnet_dev_flag
#undef _
};
u64 vals[] = {
#define _(b, n, d) 1ull << (b)
foreach_vnet_dev_flag
#undef _
};
val = unformat_flags (input, names, vals, ARRAY_LEN (names));
if (!val)
return 0;
fp->n = val;
return 1;
}
uword
unformat_vnet_dev_port_flags (unformat_input_t *input, va_list *args)
{
vnet_dev_port_flags_t *fp = va_arg (*args, vnet_dev_port_flags_t *);
u64 val;
char *flag_names[] = {
#define _(b, n, d) #n,
foreach_vnet_dev_port_flag
#undef _
};
u64 flag_values[] = {
#define _(b, n, d) 1ull << (b)
foreach_vnet_dev_port_flag
#undef _
};
val =
unformat_flags (input, flag_names, flag_values, ARRAY_LEN (flag_names));
if (!val)
return 0;
fp->n = val;
return 1;
}
static u8 *
format_flags (u8 *s, u64 val, char *flag_names[], u64 flag_values[],
u32 n_flags)
{
u32 n = 0;
for (int i = 0; i < n_flags; i++)
{
if ((val & flag_values[i]) == 0)
continue;
if (n++)
vec_add1 (s, ' ');
for (char *c = flag_names[i]; c[0] != 0; c++)
{
switch (c[0])
{
case 'A' ... 'Z':
vec_add1 (s, c[0] + 'a' - 'A');
break;
case '_':
vec_add1 (s, '-');
break;
default:
vec_add1 (s, c[0]);
}
}
}
return s;
}
u8 *
format_vnet_dev_flags (u8 *s, va_list *args)
{
vnet_dev_flags_t *fp = va_arg (*args, vnet_dev_flags_t *);
char *flag_names[] = {
#define _(b, n, d) #n,
foreach_vnet_dev_flag
#undef _
};
u64 flag_values[] = {
#define _(b, n, d) 1ull << (b)
foreach_vnet_dev_flag
#undef _
};
return format_flags (s, fp->n, flag_names, flag_values,
ARRAY_LEN (flag_names));
}
u8 *
format_vnet_dev_port_flags (u8 *s, va_list *args)
{
vnet_dev_port_flags_t *fp = va_arg (*args, vnet_dev_port_flags_t *);
char *flag_names[] = {
#define _(b, n, d) #n,
foreach_vnet_dev_port_flag
#undef _
};
u64 flag_values[] = {
#define _(b, n, d) 1ull << (b)
foreach_vnet_dev_port_flag
#undef _
};
return format_flags (s, fp->n, flag_names, flag_values,
ARRAY_LEN (flag_names));
}
u8 *
format_vnet_dev_log (u8 *s, va_list *args)
{
vnet_dev_t *dev = va_arg (*args, vnet_dev_t *);
char *func = va_arg (*args, char *);
if (dev)
s = format (s, "%U", format_vnet_dev_addr, dev);
if (dev && func)
vec_add1 (s, ' ');
if (func)
s = format (s, "%s", func);
vec_add1 (s, ':');
vec_add1 (s, ' ');
return s;
}
u8 *
format_vnet_dev_port_caps (u8 *s, va_list *args)
{
vnet_dev_port_caps_t *c = va_arg (*args, vnet_dev_port_caps_t *);
u32 line = 0;
if (c->as_number == 0)
return s;
#define _(n) \
if (c->n) \
{ \
if (line++) \
vec_add1 (s, ' '); \
for (char *str = #n; *str; str++) \
vec_add1 (s, *str == '_' ? '-' : *str); \
}
foreach_vnet_dev_port_caps;
#undef _
return s;
}
u8 *
format_vnet_dev_port_rx_offloads (u8 *s, va_list *args)
{
vnet_dev_port_rx_offloads_t *c =
va_arg (*args, vnet_dev_port_rx_offloads_t *);
u32 line = 0;
if (c->as_number == 0)
return s;
#define _(n) \
if (c->n) \
{ \
if (line++) \
vec_add1 (s, ' '); \
for (char *str = #n; *str; str++) \
vec_add1 (s, *str == '_' ? '-' : *str); \
}
foreach_vnet_dev_port_rx_offloads;
#undef _
return s;
}
u8 *
format_vnet_dev_port_tx_offloads (u8 *s, va_list *args)
{
vnet_dev_port_tx_offloads_t *c =
va_arg (*args, vnet_dev_port_tx_offloads_t *);
u32 line = 0;
if (c->as_number == 0)
return s;
#define _(n) \
if (c->n) \
{ \
if (line++) \
vec_add1 (s, ' '); \
for (char *str = #n; *str; str++) \
vec_add1 (s, *str == '_' ? '-' : *str); \
}
foreach_vnet_dev_port_tx_offloads;
#undef _
return s;
}
|