-
Notifications
You must be signed in to change notification settings - Fork 0
/
ethtool.c
6447 lines (5764 loc) · 157 KB
/
ethtool.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
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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* ethtool.c: Linux ethernet device configuration tool.
*
* Copyright (C) 1998 David S. Miller ([email protected])
* Portions Copyright 2001 Sun Microsystems
* Kernel 2.4 update Copyright 2001 Jeff Garzik <[email protected]>
* Wake-on-LAN,natsemi,misc support by Tim Hockin <[email protected]>
* Portions Copyright 2002 Intel
* Portions Copyright (C) Sun Microsystems 2008
* do_test support by Eli Kupermann <[email protected]>
* ETHTOOL_PHYS_ID support by Chris Leech <[email protected]>
* e1000 support by Scott Feldman <[email protected]>
* e100 support by Wen Tao <[email protected]>
* ixgb support by Nicholas Nunley <[email protected]>
* amd8111e support by Reeja John <[email protected]>
* long arguments by Andi Kleen.
* SMSC LAN911x support by Steve Glendinning <[email protected]>
* Rx Network Flow Control configuration support <[email protected]>
* Various features by Ben Hutchings <[email protected]>;
* Copyright 2009, 2010 Solarflare Communications
* MDI-X set support by Jesse Brandeburg <[email protected]>
* Copyright 2012 Intel Corporation
* vmxnet3 support by Shrikrishna Khare <[email protected]>
* Various features by Ben Hutchings <[email protected]>;
* Copyright 2008-2010, 2013-2016 Ben Hutchings
* QSFP+/QSFP28 DOM support by Vidya Sagar Ravipati <[email protected]>
*
* TODO:
* * show settings for all devices
*/
#include "internal.h"
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stddef.h>
#include <stdbool.h>
#include <errno.h>
#include <sys/utsname.h>
#include <limits.h>
#include <ctype.h>
#include <inttypes.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/ioctl.h>
#include <linux/sockios.h>
#include <linux/netlink.h>
#include "common.h"
#include "netlink/extapi.h"
#ifndef MAX_ADDR_LEN
#define MAX_ADDR_LEN 32
#endif
#ifndef NETLINK_GENERIC
#define NETLINK_GENERIC 16
#endif
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
static void exit_bad_args(void) __attribute__((noreturn));
static void exit_bad_args(void)
{
fprintf(stderr,
"ethtool: bad command line argument(s)\n"
"For more information run ethtool -h\n");
exit(1);
}
static void exit_nlonly_param(const char *name) __attribute__((noreturn));
static void exit_nlonly_param(const char *name)
{
fprintf(stderr,
"ethtool: parameter '%s' can be used only with netlink\n",
name);
exit(1);
}
typedef enum {
CMDL_NONE,
CMDL_BOOL,
CMDL_S32,
CMDL_U8,
CMDL_U16,
CMDL_U32,
CMDL_U64,
CMDL_BE16,
CMDL_IP4,
CMDL_STR,
CMDL_FLAG,
CMDL_MAC,
} cmdline_type_t;
struct cmdline_info {
const char *name;
cmdline_type_t type;
/* Points to int (BOOL), s32, u16, u32 (U32/FLAG/IP4), u64,
* char * (STR) or u8[6] (MAC). For FLAG, the value accumulates
* all flags to be set. */
void *wanted_val;
void *ioctl_val;
/* For FLAG, the flag value to be set/cleared */
u32 flag_val;
/* For FLAG, points to u32 and accumulates all flags seen.
* For anything else, points to int and is set if the option is
* seen. */
void *seen_val;
};
struct feature_def {
char name[ETH_GSTRING_LEN];
int off_flag_index; /* index in off_flag_def; negative if none match */
};
struct feature_defs {
size_t n_features;
/* Number of features each offload flag is associated with */
unsigned int off_flag_matched[OFF_FLAG_DEF_SIZE];
/* Name and offload flag index for each feature */
struct feature_def def[0];
};
#define FEATURE_BITS_TO_BLOCKS(n_bits) DIV_ROUND_UP(n_bits, 32U)
#define FEATURE_WORD(blocks, index, field) ((blocks)[(index) / 32U].field)
#define FEATURE_FIELD_FLAG(index) (1U << (index) % 32U)
#define FEATURE_BIT_SET(blocks, index, field) \
(FEATURE_WORD(blocks, index, field) |= FEATURE_FIELD_FLAG(index))
#define FEATURE_BIT_CLEAR(blocks, index, field) \
(FEATURE_WORD(blocks, index, filed) &= ~FEATURE_FIELD_FLAG(index))
#define FEATURE_BIT_IS_SET(blocks, index, field) \
(FEATURE_WORD(blocks, index, field) & FEATURE_FIELD_FLAG(index))
static long long
get_int_range(char *str, int base, long long min, long long max)
{
long long v;
char *endp;
if (!str)
exit_bad_args();
errno = 0;
v = strtoll(str, &endp, base);
if (errno || *endp || v < min || v > max)
exit_bad_args();
return v;
}
static unsigned long long
get_uint_range(char *str, int base, unsigned long long max)
{
unsigned long long v;
char *endp;
if (!str)
exit_bad_args();
errno = 0;
v = strtoull(str, &endp, base);
if (errno || *endp || v > max)
exit_bad_args();
return v;
}
static int get_int(char *str, int base)
{
return get_int_range(str, base, INT_MIN, INT_MAX);
}
static u32 get_u32(char *str, int base)
{
return get_uint_range(str, base, 0xffffffff);
}
static void get_mac_addr(char *src, unsigned char *dest)
{
int count;
int i;
int buf[ETH_ALEN];
count = sscanf(src, "%2x:%2x:%2x:%2x:%2x:%2x",
&buf[0], &buf[1], &buf[2], &buf[3], &buf[4], &buf[5]);
if (count != ETH_ALEN)
exit_bad_args();
for (i = 0; i < count; i++)
dest[i] = buf[i];
}
static int parse_hex_u32_bitmap(const char *s,
unsigned int nbits, u32 *result)
{
const unsigned int nwords = __KERNEL_DIV_ROUND_UP(nbits, 32);
size_t slen = strlen(s);
size_t i;
/* ignore optional '0x' prefix */
if ((slen > 2) && (strncasecmp(s, "0x", 2) == 0)) {
slen -= 2;
s += 2;
}
if (slen > 8 * nwords) /* up to 2 digits per byte */
return -1;
memset(result, 0, 4 * nwords);
for (i = 0; i < slen; ++i) {
const unsigned int shift = (slen - 1 - i) * 4;
u32 *dest = &result[shift / 32];
u32 nibble;
if ('a' <= s[i] && s[i] <= 'f')
nibble = 0xa + (s[i] - 'a');
else if ('A' <= s[i] && s[i] <= 'F')
nibble = 0xa + (s[i] - 'A');
else if ('0' <= s[i] && s[i] <= '9')
nibble = (s[i] - '0');
else
return -1;
*dest |= (nibble << (shift % 32));
}
return 0;
}
static void parse_generic_cmdline(struct cmd_context *ctx,
int *changed,
struct cmdline_info *info,
unsigned int n_info)
{
unsigned int argc = ctx->argc;
char **argp = ctx->argp;
unsigned int i, idx;
int found;
for (i = 0; i < argc; i++) {
found = 0;
for (idx = 0; idx < n_info; idx++) {
if (!strcmp(info[idx].name, argp[i])) {
found = 1;
*changed = 1;
if (info[idx].type != CMDL_FLAG &&
info[idx].seen_val)
*(int *)info[idx].seen_val = 1;
i += 1;
if (i >= argc)
exit_bad_args();
switch (info[idx].type) {
case CMDL_BOOL: {
int *p = info[idx].wanted_val;
if (!strcmp(argp[i], "on"))
*p = 1;
else if (!strcmp(argp[i], "off"))
*p = 0;
else
exit_bad_args();
break;
}
case CMDL_S32: {
s32 *p = info[idx].wanted_val;
*p = get_int_range(argp[i], 0,
-0x80000000LL,
0x7fffffff);
break;
}
case CMDL_U8: {
u8 *p = info[idx].wanted_val;
*p = get_uint_range(argp[i], 0, 0xff);
break;
}
case CMDL_U16: {
u16 *p = info[idx].wanted_val;
*p = get_uint_range(argp[i], 0, 0xffff);
break;
}
case CMDL_U32: {
u32 *p = info[idx].wanted_val;
*p = get_uint_range(argp[i], 0,
0xffffffff);
break;
}
case CMDL_U64: {
u64 *p = info[idx].wanted_val;
*p = get_uint_range(
argp[i], 0,
0xffffffffffffffffLL);
break;
}
case CMDL_BE16: {
u16 *p = info[idx].wanted_val;
*p = cpu_to_be16(
get_uint_range(argp[i], 0,
0xffff));
break;
}
case CMDL_IP4: {
u32 *p = info[idx].wanted_val;
struct in_addr in;
if (!inet_pton(AF_INET, argp[i], &in))
exit_bad_args();
*p = in.s_addr;
break;
}
case CMDL_MAC:
get_mac_addr(argp[i],
info[idx].wanted_val);
break;
case CMDL_FLAG: {
u32 *p;
p = info[idx].seen_val;
*p |= info[idx].flag_val;
if (!strcmp(argp[i], "on")) {
p = info[idx].wanted_val;
*p |= info[idx].flag_val;
} else if (strcmp(argp[i], "off")) {
exit_bad_args();
}
break;
}
case CMDL_STR: {
char **s = info[idx].wanted_val;
*s = strdup(argp[i]);
break;
}
default:
exit_bad_args();
}
break;
}
}
if (!found)
exit_bad_args();
}
}
static void flag_to_cmdline_info(const char *name, u32 value,
u32 *wanted, u32 *mask,
struct cmdline_info *cli)
{
memset(cli, 0, sizeof(*cli));
cli->name = name;
cli->type = CMDL_FLAG;
cli->flag_val = value;
cli->wanted_val = wanted;
cli->seen_val = mask;
}
static int rxflow_str_to_type(const char *str)
{
int flow_type = 0;
if (!strcmp(str, "tcp4"))
flow_type = TCP_V4_FLOW;
else if (!strcmp(str, "udp4"))
flow_type = UDP_V4_FLOW;
else if (!strcmp(str, "ah4") || !strcmp(str, "esp4"))
flow_type = AH_ESP_V4_FLOW;
else if (!strcmp(str, "sctp4"))
flow_type = SCTP_V4_FLOW;
else if (!strcmp(str, "tcp6"))
flow_type = TCP_V6_FLOW;
else if (!strcmp(str, "udp6"))
flow_type = UDP_V6_FLOW;
else if (!strcmp(str, "ah6") || !strcmp(str, "esp6"))
flow_type = AH_ESP_V6_FLOW;
else if (!strcmp(str, "sctp6"))
flow_type = SCTP_V6_FLOW;
else if (!strcmp(str, "ether"))
flow_type = ETHER_FLOW;
return flow_type;
}
static int do_version(struct cmd_context *ctx __maybe_unused)
{
fprintf(stdout,
PACKAGE " version " VERSION
#ifndef ETHTOOL_ENABLE_PRETTY_DUMP
" (pretty dumps disabled)"
#endif
"\n");
return 0;
}
/* link mode routines */
static ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_modes);
static ETHTOOL_DECLARE_LINK_MODE_MASK(all_advertised_flags);
static void init_global_link_mode_masks(void)
{
static const enum ethtool_link_mode_bit_indices
all_advertised_modes_bits[] = {
ETHTOOL_LINK_MODE_10baseT_Half_BIT,
ETHTOOL_LINK_MODE_10baseT_Full_BIT,
ETHTOOL_LINK_MODE_100baseT_Half_BIT,
ETHTOOL_LINK_MODE_100baseT_Full_BIT,
ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
ETHTOOL_LINK_MODE_2500baseX_Full_BIT,
ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,
ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
ETHTOOL_LINK_MODE_10000baseR_FEC_BIT,
ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT,
ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT,
ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT,
ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT,
ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT,
ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT,
ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT,
ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT,
ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT,
ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT,
ETHTOOL_LINK_MODE_25000baseCR_Full_BIT,
ETHTOOL_LINK_MODE_25000baseKR_Full_BIT,
ETHTOOL_LINK_MODE_25000baseSR_Full_BIT,
ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT,
ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT,
ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT,
ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT,
ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT,
ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT,
ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT,
ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
ETHTOOL_LINK_MODE_10000baseCR_Full_BIT,
ETHTOOL_LINK_MODE_10000baseSR_Full_BIT,
ETHTOOL_LINK_MODE_10000baseLR_Full_BIT,
ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT,
ETHTOOL_LINK_MODE_10000baseER_Full_BIT,
ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
ETHTOOL_LINK_MODE_50000baseKR_Full_BIT,
ETHTOOL_LINK_MODE_50000baseSR_Full_BIT,
ETHTOOL_LINK_MODE_50000baseCR_Full_BIT,
ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT,
ETHTOOL_LINK_MODE_50000baseDR_Full_BIT,
ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT,
ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT,
ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT,
ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT,
ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT,
ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT,
ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT,
ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT,
ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT,
ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT,
ETHTOOL_LINK_MODE_100baseT1_Full_BIT,
ETHTOOL_LINK_MODE_1000baseT1_Full_BIT,
ETHTOOL_LINK_MODE_400000baseKR8_Full_BIT,
ETHTOOL_LINK_MODE_400000baseSR8_Full_BIT,
ETHTOOL_LINK_MODE_400000baseLR8_ER8_FR8_Full_BIT,
ETHTOOL_LINK_MODE_400000baseDR8_Full_BIT,
ETHTOOL_LINK_MODE_400000baseCR8_Full_BIT,
ETHTOOL_LINK_MODE_100000baseKR_Full_BIT,
ETHTOOL_LINK_MODE_100000baseSR_Full_BIT,
ETHTOOL_LINK_MODE_100000baseLR_ER_FR_Full_BIT,
ETHTOOL_LINK_MODE_100000baseCR_Full_BIT,
ETHTOOL_LINK_MODE_100000baseDR_Full_BIT,
ETHTOOL_LINK_MODE_200000baseKR2_Full_BIT,
ETHTOOL_LINK_MODE_200000baseSR2_Full_BIT,
ETHTOOL_LINK_MODE_200000baseLR2_ER2_FR2_Full_BIT,
ETHTOOL_LINK_MODE_200000baseDR2_Full_BIT,
ETHTOOL_LINK_MODE_200000baseCR2_Full_BIT,
ETHTOOL_LINK_MODE_400000baseKR4_Full_BIT,
ETHTOOL_LINK_MODE_400000baseSR4_Full_BIT,
ETHTOOL_LINK_MODE_400000baseLR4_ER4_FR4_Full_BIT,
ETHTOOL_LINK_MODE_400000baseDR4_Full_BIT,
ETHTOOL_LINK_MODE_400000baseCR4_Full_BIT,
ETHTOOL_LINK_MODE_100baseFX_Half_BIT,
ETHTOOL_LINK_MODE_100baseFX_Full_BIT,
ETHTOOL_LINK_MODE_10baseT1L_Full_BIT,
ETHTOOL_LINK_MODE_800000baseCR8_Full_BIT,
ETHTOOL_LINK_MODE_800000baseKR8_Full_BIT,
ETHTOOL_LINK_MODE_800000baseDR8_Full_BIT,
ETHTOOL_LINK_MODE_800000baseDR8_2_Full_BIT,
ETHTOOL_LINK_MODE_800000baseSR8_Full_BIT,
ETHTOOL_LINK_MODE_800000baseVR8_Full_BIT,
};
static const enum ethtool_link_mode_bit_indices
additional_advertised_flags_bits[] = {
ETHTOOL_LINK_MODE_Autoneg_BIT,
ETHTOOL_LINK_MODE_TP_BIT,
ETHTOOL_LINK_MODE_AUI_BIT,
ETHTOOL_LINK_MODE_MII_BIT,
ETHTOOL_LINK_MODE_FIBRE_BIT,
ETHTOOL_LINK_MODE_BNC_BIT,
ETHTOOL_LINK_MODE_Pause_BIT,
ETHTOOL_LINK_MODE_Asym_Pause_BIT,
ETHTOOL_LINK_MODE_Backplane_BIT,
ETHTOOL_LINK_MODE_FEC_NONE_BIT,
ETHTOOL_LINK_MODE_FEC_RS_BIT,
ETHTOOL_LINK_MODE_FEC_BASER_BIT,
ETHTOOL_LINK_MODE_FEC_LLRS_BIT,
};
unsigned int i;
ethtool_link_mode_zero(all_advertised_modes);
ethtool_link_mode_zero(all_advertised_flags);
for (i = 0; i < ARRAY_SIZE(all_advertised_modes_bits); ++i) {
ethtool_link_mode_set_bit(all_advertised_modes_bits[i],
all_advertised_modes);
ethtool_link_mode_set_bit(all_advertised_modes_bits[i],
all_advertised_flags);
}
for (i = 0; i < ARRAY_SIZE(additional_advertised_flags_bits); ++i) {
ethtool_link_mode_set_bit(
additional_advertised_flags_bits[i],
all_advertised_flags);
}
}
static void dump_link_caps(const char *prefix, const char *an_prefix,
const u32 *mask, int link_mode_only);
static void dump_supported(const struct ethtool_link_usettings *link_usettings)
{
fprintf(stdout, " Supported ports: [ ");
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_TP_BIT,
link_usettings->link_modes.supported))
fprintf(stdout, "TP ");
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_AUI_BIT,
link_usettings->link_modes.supported))
fprintf(stdout, "AUI ");
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_BNC_BIT,
link_usettings->link_modes.supported))
fprintf(stdout, "BNC ");
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_MII_BIT,
link_usettings->link_modes.supported))
fprintf(stdout, "MII ");
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_FIBRE_BIT,
link_usettings->link_modes.supported))
fprintf(stdout, "FIBRE ");
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_Backplane_BIT,
link_usettings->link_modes.supported))
fprintf(stdout, "Backplane ");
fprintf(stdout, "]\n");
dump_link_caps("Supported", "Supports",
link_usettings->link_modes.supported, 0);
}
/* Print link capability flags (supported, advertised or lp_advertised).
* Assumes that the corresponding SUPPORTED and ADVERTISED flags are equal.
*/
static void dump_link_caps(const char *prefix, const char *an_prefix,
const u32 *mask, int link_mode_only)
{
static const struct {
int same_line; /* print on same line as previous */
unsigned int bit_index;
const char *name;
} mode_defs[] = {
{ 0, ETHTOOL_LINK_MODE_10baseT_Half_BIT,
"10baseT/Half" },
{ 1, ETHTOOL_LINK_MODE_10baseT_Full_BIT,
"10baseT/Full" },
{ 0, ETHTOOL_LINK_MODE_100baseT_Half_BIT,
"100baseT/Half" },
{ 1, ETHTOOL_LINK_MODE_100baseT_Full_BIT,
"100baseT/Full" },
{ 0, ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
"1000baseT/Half" },
{ 1, ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
"1000baseT/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
"10000baseT/Full" },
{ 0, ETHTOOL_LINK_MODE_2500baseX_Full_BIT,
"2500baseX/Full" },
{ 0, ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
"1000baseKX/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,
"10000baseKX4/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
"10000baseKR/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseR_FEC_BIT,
"10000baseR_FEC" },
{ 0, ETHTOOL_LINK_MODE_20000baseMLD2_Full_BIT,
"20000baseMLD2/Full" },
{ 0, ETHTOOL_LINK_MODE_20000baseKR2_Full_BIT,
"20000baseKR2/Full" },
{ 0, ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT,
"40000baseKR4/Full" },
{ 0, ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT,
"40000baseCR4/Full" },
{ 0, ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT,
"40000baseSR4/Full" },
{ 0, ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT,
"40000baseLR4/Full" },
{ 0, ETHTOOL_LINK_MODE_56000baseKR4_Full_BIT,
"56000baseKR4/Full" },
{ 0, ETHTOOL_LINK_MODE_56000baseCR4_Full_BIT,
"56000baseCR4/Full" },
{ 0, ETHTOOL_LINK_MODE_56000baseSR4_Full_BIT,
"56000baseSR4/Full" },
{ 0, ETHTOOL_LINK_MODE_56000baseLR4_Full_BIT,
"56000baseLR4/Full" },
{ 0, ETHTOOL_LINK_MODE_25000baseCR_Full_BIT,
"25000baseCR/Full" },
{ 0, ETHTOOL_LINK_MODE_25000baseKR_Full_BIT,
"25000baseKR/Full" },
{ 0, ETHTOOL_LINK_MODE_25000baseSR_Full_BIT,
"25000baseSR/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT,
"50000baseCR2/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseKR2_Full_BIT,
"50000baseKR2/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT,
"100000baseKR4/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT,
"100000baseSR4/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT,
"100000baseCR4/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT,
"100000baseLR4_ER4/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseSR2_Full_BIT,
"50000baseSR2/Full" },
{ 0, ETHTOOL_LINK_MODE_1000baseX_Full_BIT,
"1000baseX/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseCR_Full_BIT,
"10000baseCR/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseSR_Full_BIT,
"10000baseSR/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseLR_Full_BIT,
"10000baseLR/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseLRM_Full_BIT,
"10000baseLRM/Full" },
{ 0, ETHTOOL_LINK_MODE_10000baseER_Full_BIT,
"10000baseER/Full" },
{ 0, ETHTOOL_LINK_MODE_2500baseT_Full_BIT,
"2500baseT/Full" },
{ 0, ETHTOOL_LINK_MODE_5000baseT_Full_BIT,
"5000baseT/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseKR_Full_BIT,
"50000baseKR/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseSR_Full_BIT,
"50000baseSR/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseCR_Full_BIT,
"50000baseCR/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT,
"50000baseLR_ER_FR/Full" },
{ 0, ETHTOOL_LINK_MODE_50000baseDR_Full_BIT,
"50000baseDR/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseKR2_Full_BIT,
"100000baseKR2/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseSR2_Full_BIT,
"100000baseSR2/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseCR2_Full_BIT,
"100000baseCR2/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseLR2_ER2_FR2_Full_BIT,
"100000baseLR2_ER2_FR2/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseDR2_Full_BIT,
"100000baseDR2/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseKR4_Full_BIT,
"200000baseKR4/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseSR4_Full_BIT,
"200000baseSR4/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseLR4_ER4_FR4_Full_BIT,
"200000baseLR4_ER4_FR4/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseDR4_Full_BIT,
"200000baseDR4/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT,
"200000baseCR4/Full" },
{ 0, ETHTOOL_LINK_MODE_100baseT1_Full_BIT,
"100baseT1/Full" },
{ 0, ETHTOOL_LINK_MODE_1000baseT1_Full_BIT,
"1000baseT1/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseKR8_Full_BIT,
"400000baseKR8/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseSR8_Full_BIT,
"400000baseSR8/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseLR8_ER8_FR8_Full_BIT,
"400000baseLR8_ER8_FR8/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseDR8_Full_BIT,
"400000baseDR8/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseCR8_Full_BIT,
"400000baseCR8/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseKR_Full_BIT,
"100000baseKR/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseSR_Full_BIT,
"100000baseSR/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseLR_ER_FR_Full_BIT,
"100000baseLR_ER_FR/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseDR_Full_BIT,
"100000baseDR/Full" },
{ 0, ETHTOOL_LINK_MODE_100000baseCR_Full_BIT,
"100000baseCR/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseKR2_Full_BIT,
"200000baseKR2/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseSR2_Full_BIT,
"200000baseSR2/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseLR2_ER2_FR2_Full_BIT,
"200000baseLR2_ER2_FR2/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseDR2_Full_BIT,
"200000baseDR2/Full" },
{ 0, ETHTOOL_LINK_MODE_200000baseCR2_Full_BIT,
"200000baseCR2/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseKR4_Full_BIT,
"400000baseKR4/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseSR4_Full_BIT,
"400000baseSR4/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseLR4_ER4_FR4_Full_BIT,
"400000baseLR4_ER4_FR4/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseDR4_Full_BIT,
"400000baseDR4/Full" },
{ 0, ETHTOOL_LINK_MODE_400000baseCR4_Full_BIT,
"400000baseCR4/Full" },
{ 0, ETHTOOL_LINK_MODE_100baseFX_Half_BIT,
"100baseFX/Half" },
{ 1, ETHTOOL_LINK_MODE_100baseFX_Full_BIT,
"100baseFX/Full" },
{ 0, ETHTOOL_LINK_MODE_10baseT1L_Full_BIT,
"10baseT1L/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseCR8_Full_BIT,
"800000baseCR8/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseKR8_Full_BIT,
"800000baseKR8/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseDR8_Full_BIT,
"800000baseDR8/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseDR8_2_Full_BIT,
"800000baseDR8_2/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseSR8_Full_BIT,
"800000baseSR8/Full" },
{ 0, ETHTOOL_LINK_MODE_800000baseVR8_Full_BIT,
"800000baseVR8/Full" },
};
int indent;
int did1, new_line_pend;
int fecreported = 0;
unsigned int i;
/* Indent just like the separate functions used to */
indent = strlen(prefix) + 14;
if (indent < 24)
indent = 24;
fprintf(stdout, " %s link modes:%*s", prefix,
indent - (int)strlen(prefix) - 12, "");
did1 = 0;
new_line_pend = 0;
for (i = 0; i < ARRAY_SIZE(mode_defs); i++) {
if (did1 && !mode_defs[i].same_line)
new_line_pend = 1;
if (ethtool_link_mode_test_bit(mode_defs[i].bit_index,
mask)) {
if (new_line_pend) {
fprintf(stdout, "\n");
fprintf(stdout, " %*s", indent, "");
new_line_pend = 0;
}
did1++;
fprintf(stdout, "%s ", mode_defs[i].name);
}
}
if (did1 == 0)
fprintf(stdout, "Not reported");
fprintf(stdout, "\n");
if (!link_mode_only) {
fprintf(stdout, " %s pause frame use: ", prefix);
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_Pause_BIT, mask)) {
fprintf(stdout, "Symmetric");
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_Asym_Pause_BIT, mask))
fprintf(stdout, " Receive-only");
fprintf(stdout, "\n");
} else {
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_Asym_Pause_BIT, mask))
fprintf(stdout, "Transmit-only\n");
else
fprintf(stdout, "No\n");
}
fprintf(stdout, " %s auto-negotiation: ", an_prefix);
if (ethtool_link_mode_test_bit(
ETHTOOL_LINK_MODE_Autoneg_BIT, mask))
fprintf(stdout, "Yes\n");
else
fprintf(stdout, "No\n");
fprintf(stdout, " %s FEC modes:", prefix);
if (ethtool_link_mode_test_bit(ETHTOOL_LINK_MODE_FEC_NONE_BIT,
mask)) {
fprintf(stdout, " None");
fecreported = 1;
}
if (ethtool_link_mode_test_bit(ETHTOOL_LINK_MODE_FEC_BASER_BIT,
mask)) {
fprintf(stdout, " BaseR");
fecreported = 1;
}
if (ethtool_link_mode_test_bit(ETHTOOL_LINK_MODE_FEC_RS_BIT,
mask)) {
fprintf(stdout, " RS");
fecreported = 1;
}
if (ethtool_link_mode_test_bit(ETHTOOL_LINK_MODE_FEC_LLRS_BIT,
mask)) {
fprintf(stdout, " LLRS");
fecreported = 1;
}
if (!fecreported)
fprintf(stdout, " Not reported");
fprintf(stdout, "\n");
}
}
static int
dump_link_usettings(const struct ethtool_link_usettings *link_usettings)
{
dump_supported(link_usettings);
dump_link_caps("Advertised", "Advertised",
link_usettings->link_modes.advertising, 0);
if (!ethtool_link_mode_is_empty(
link_usettings->link_modes.lp_advertising))
dump_link_caps("Link partner advertised",
"Link partner advertised",
link_usettings->link_modes.lp_advertising, 0);
fprintf(stdout, " Speed: ");
if (link_usettings->base.speed == 0
|| link_usettings->base.speed == (u16)(-1)
|| link_usettings->base.speed == (u32)(-1))
fprintf(stdout, "Unknown!\n");
else
fprintf(stdout, "%uMb/s\n", link_usettings->base.speed);
fprintf(stdout, " Duplex: ");
switch (link_usettings->base.duplex) {
case DUPLEX_HALF:
fprintf(stdout, "Half\n");
break;
case DUPLEX_FULL:
fprintf(stdout, "Full\n");
break;
default:
fprintf(stdout, "Unknown! (%i)\n", link_usettings->base.duplex);
break;
};
fprintf(stdout, " Port: ");
switch (link_usettings->base.port) {
case PORT_TP:
fprintf(stdout, "Twisted Pair\n");
break;
case PORT_AUI:
fprintf(stdout, "AUI\n");
break;
case PORT_BNC:
fprintf(stdout, "BNC\n");
break;
case PORT_MII:
fprintf(stdout, "MII\n");
break;
case PORT_FIBRE:
fprintf(stdout, "FIBRE\n");
break;
case PORT_DA:
fprintf(stdout, "Direct Attach Copper\n");
break;
case PORT_NONE:
fprintf(stdout, "None\n");
break;
case PORT_OTHER:
fprintf(stdout, "Other\n");
break;
default:
fprintf(stdout, "Unknown! (%i)\n", link_usettings->base.port);
break;
};
fprintf(stdout, " PHYAD: %d\n", link_usettings->base.phy_address);
fprintf(stdout, " Transceiver: ");
switch (link_usettings->deprecated.transceiver) {
case XCVR_INTERNAL:
fprintf(stdout, "internal\n");
break;
case XCVR_EXTERNAL:
fprintf(stdout, "external\n");
break;
default:
fprintf(stdout, "Unknown!\n");
break;
};
fprintf(stdout, " Auto-negotiation: %s\n",
(link_usettings->base.autoneg == AUTONEG_DISABLE) ?
"off" : "on");
if (link_usettings->base.port == PORT_TP)
dump_mdix(link_usettings->base.eth_tp_mdix,
link_usettings->base.eth_tp_mdix_ctrl);
return 0;
}
static int dump_drvinfo(struct ethtool_drvinfo *info)
{
fprintf(stdout,
"driver: %.*s\n"
"version: %.*s\n"
"firmware-version: %.*s\n"
"expansion-rom-version: %.*s\n"
"bus-info: %.*s\n"
"supports-statistics: %s\n"
"supports-test: %s\n"
"supports-eeprom-access: %s\n"
"supports-register-dump: %s\n"
"supports-priv-flags: %s\n",
(int)sizeof(info->driver), info->driver,
(int)sizeof(info->version), info->version,
(int)sizeof(info->fw_version), info->fw_version,
(int)sizeof(info->erom_version), info->erom_version,
(int)sizeof(info->bus_info), info->bus_info,
info->n_stats ? "yes" : "no",
info->testinfo_len ? "yes" : "no",
info->eedump_len ? "yes" : "no",
info->regdump_len ? "yes" : "no",
info->n_priv_flags ? "yes" : "no");
return 0;
}
static int parse_wolopts(char *optstr, u32 *data)
{
*data = 0;
while (*optstr) {
switch (*optstr) {
case 'p':
*data |= WAKE_PHY;
break;
case 'u':
*data |= WAKE_UCAST;
break;
case 'm':
*data |= WAKE_MCAST;
break;
case 'b':
*data |= WAKE_BCAST;
break;
case 'a':
*data |= WAKE_ARP;
break;
case 'g':
*data |= WAKE_MAGIC;
break;
case 's':
*data |= WAKE_MAGICSECURE;
break;
case 'f':
*data |= WAKE_FILTER;
break;
case 'd':
*data = 0;
break;
default:
return -1;
}
optstr++;
}
return 0;
}
static int parse_rxfhashopts(char *optstr, u32 *data)
{
*data = 0;
while (*optstr) {
switch (*optstr) {
case 'm':
*data |= RXH_L2DA;
break;
case 'v':
*data |= RXH_VLAN;
break;
case 't':
*data |= RXH_L3_PROTO;
break;
case 's':
*data |= RXH_IP_SRC;
break;
case 'd':
*data |= RXH_IP_DST;