forked from lunn/mv88e6xxx_dump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmv88e6xxx_dump.c
2312 lines (2096 loc) · 59 KB
/
mv88e6xxx_dump.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
#include <errno.h>
#include <getopt.h>
#include <linux/devlink.h>
#include <linux/genetlink.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mnlg.h"
#include "utils.h"
/* All single snapshots used by this program have this ID. */
#define SNAPSHOT_ID 42
#define MAX_SNAPSHOT_DATA 128 * 1024
#define MV88E6085 6085
#define MV88E6095 6095
#define MV88E6097 6097
#define MV88E6131 6131
#define MV88E6320 6320
#define MV88E6123 6123
#define MV88E6161 6161
#define MV88E6165 6165
#define MV88E6171 6171
#define MV88E6172 6172
#define MV88E6175 6175
#define MV88E6176 6176
#define MV88E6190 6190
#define MV88E6191 6191
#define MV88E6185 6185
#define MV88E6220 6220
#define MV88E6240 6240
#define MV88E6250 6250
#define MV88E6290 6290
#define MV88E6321 6321
#define MV88E6141 6141
#define MV88E6341 6341
#define MV88E6352 6352
#define MV88E6350 6350
#define MV88E6351 6351
#define MV88E6390 6390
#define MAX_PORTS 11
struct mv88e6xxx_ctx
{
struct mnlg_socket *nlg;
const char *bus_name;
const char *dev_name;
unsigned int chip;
int ports;
bool repeat;
uint8_t snapshot_data[MAX_SNAPSHOT_DATA];
size_t data_len;
bool port_enabled[MAX_PORTS];
uint16_t port_regs[MAX_PORTS][32];
};
struct mv88e6xxx_devlink_atu_entry {
/* The FID is scattered over multiple registers. */
uint16_t fid;
uint16_t atu_op;
uint16_t atu_data;
uint16_t atu_01;
uint16_t atu_23;
uint16_t atu_45;
};
struct mv88e6xxx_devlink_vtu_entry {
uint16_t fid;
uint16_t sid;
uint16_t op;
uint16_t vid;
uint16_t data[3];
uint16_t resvd;
};
void usage(const char *progname)
{
printf("%s [OPTIONs]\n", progname);
printf(" --debug/-d\tExtra debug output\n");
printf(" --list/-l\tList the mv88e6xxx devices\n");
printf(" --device/-d\tDump this device\n");
printf(" --atu\t\tDump the ATU\n");
printf(" --vtu\t\tDump the VTU\n");
printf(" --ports\tDump all ports in a table\n");
printf(" --global1\tDump global1 registers\n");
printf(" --global2\tDump globAL2 registers\n");
exit(EXIT_FAILURE);
}
static int _mnlg_socket_recv_run(struct mnlg_socket *nlg,
mnl_cb_t data_cb, void *data)
{
int err;
err = mnlg_socket_recv_run(nlg, data_cb, data);
if (err < 0) {
printf("devlink answers: %s\n", strerror(errno));
return -errno;
}
return 0;
}
static int _mnlg_socket_send(struct mnlg_socket *nlg,
const struct nlmsghdr *nlh)
{
int err;
err = mnlg_socket_send(nlg, nlh);
if (err < 0) {
printf("Failed to call mnlg_socket_send\n");
return -errno;
}
return 0;
}
static int _mnlg_socket_sndrcv(struct mnlg_socket *nlg,
const struct nlmsghdr *nlh,
mnl_cb_t data_cb, void *data)
{
int err;
err = _mnlg_socket_send(nlg, nlh);
if (err)
return err;
return _mnlg_socket_recv_run(nlg, data_cb, data);
}
static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
[DEVLINK_ATTR_BUS_NAME] = MNL_TYPE_NUL_STRING,
[DEVLINK_ATTR_DEV_NAME] = MNL_TYPE_NUL_STRING,
[DEVLINK_ATTR_PORT_INDEX] = MNL_TYPE_U32,
[DEVLINK_ATTR_PORT_TYPE] = MNL_TYPE_U16,
[DEVLINK_ATTR_PORT_DESIRED_TYPE] = MNL_TYPE_U16,
[DEVLINK_ATTR_PORT_NETDEV_IFINDEX] = MNL_TYPE_U32,
[DEVLINK_ATTR_PORT_NETDEV_NAME] = MNL_TYPE_NUL_STRING,
[DEVLINK_ATTR_PORT_IBDEV_NAME] = MNL_TYPE_NUL_STRING,
[DEVLINK_ATTR_SB_INDEX] = MNL_TYPE_U32,
[DEVLINK_ATTR_SB_SIZE] = MNL_TYPE_U32,
[DEVLINK_ATTR_SB_INGRESS_POOL_COUNT] = MNL_TYPE_U16,
[DEVLINK_ATTR_SB_EGRESS_POOL_COUNT] = MNL_TYPE_U16,
[DEVLINK_ATTR_SB_INGRESS_TC_COUNT] = MNL_TYPE_U16,
[DEVLINK_ATTR_SB_EGRESS_TC_COUNT] = MNL_TYPE_U16,
[DEVLINK_ATTR_SB_POOL_INDEX] = MNL_TYPE_U16,
[DEVLINK_ATTR_SB_POOL_TYPE] = MNL_TYPE_U8,
[DEVLINK_ATTR_SB_POOL_SIZE] = MNL_TYPE_U32,
[DEVLINK_ATTR_SB_POOL_THRESHOLD_TYPE] = MNL_TYPE_U8,
[DEVLINK_ATTR_SB_THRESHOLD] = MNL_TYPE_U32,
[DEVLINK_ATTR_SB_TC_INDEX] = MNL_TYPE_U16,
[DEVLINK_ATTR_SB_OCC_CUR] = MNL_TYPE_U32,
[DEVLINK_ATTR_SB_OCC_MAX] = MNL_TYPE_U32,
[DEVLINK_ATTR_ESWITCH_MODE] = MNL_TYPE_U16,
[DEVLINK_ATTR_ESWITCH_INLINE_MODE] = MNL_TYPE_U8,
[DEVLINK_ATTR_ESWITCH_ENCAP_MODE] = MNL_TYPE_U8,
[DEVLINK_ATTR_DPIPE_TABLES] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_TABLE] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_TABLE_NAME] = MNL_TYPE_STRING,
[DEVLINK_ATTR_DPIPE_TABLE_SIZE] = MNL_TYPE_U64,
[DEVLINK_ATTR_DPIPE_TABLE_MATCHES] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_TABLE_ACTIONS] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED] = MNL_TYPE_U8,
[DEVLINK_ATTR_DPIPE_ENTRIES] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_ENTRY] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_ENTRY_INDEX] = MNL_TYPE_U64,
[DEVLINK_ATTR_DPIPE_ENTRY_MATCH_VALUES] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_ENTRY_ACTION_VALUES] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_ENTRY_COUNTER] = MNL_TYPE_U64,
[DEVLINK_ATTR_DPIPE_MATCH] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_MATCH_VALUE] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_MATCH_TYPE] = MNL_TYPE_U32,
[DEVLINK_ATTR_DPIPE_ACTION] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_ACTION_VALUE] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_ACTION_TYPE] = MNL_TYPE_U32,
[DEVLINK_ATTR_DPIPE_VALUE_MAPPING] = MNL_TYPE_U32,
[DEVLINK_ATTR_DPIPE_HEADERS] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_HEADER] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_HEADER_NAME] = MNL_TYPE_STRING,
[DEVLINK_ATTR_DPIPE_HEADER_ID] = MNL_TYPE_U32,
[DEVLINK_ATTR_DPIPE_HEADER_FIELDS] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_HEADER_GLOBAL] = MNL_TYPE_U8,
[DEVLINK_ATTR_DPIPE_HEADER_INDEX] = MNL_TYPE_U32,
[DEVLINK_ATTR_DPIPE_FIELD] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_DPIPE_FIELD_NAME] = MNL_TYPE_STRING,
[DEVLINK_ATTR_DPIPE_FIELD_ID] = MNL_TYPE_U32,
[DEVLINK_ATTR_DPIPE_FIELD_BITWIDTH] = MNL_TYPE_U32,
[DEVLINK_ATTR_DPIPE_FIELD_MAPPING_TYPE] = MNL_TYPE_U32,
[DEVLINK_ATTR_PARAM] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_PARAM_NAME] = MNL_TYPE_STRING,
[DEVLINK_ATTR_PARAM_TYPE] = MNL_TYPE_U8,
[DEVLINK_ATTR_PARAM_VALUES_LIST] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_PARAM_VALUE] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_PARAM_VALUE_CMODE] = MNL_TYPE_U8,
[DEVLINK_ATTR_REGION_NAME] = MNL_TYPE_STRING,
[DEVLINK_ATTR_REGION_SIZE] = MNL_TYPE_U64,
[DEVLINK_ATTR_REGION_SNAPSHOTS] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_REGION_SNAPSHOT] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_REGION_SNAPSHOT_ID] = MNL_TYPE_U32,
[DEVLINK_ATTR_REGION_CHUNKS] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_REGION_CHUNK] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_REGION_CHUNK_DATA] = MNL_TYPE_BINARY,
[DEVLINK_ATTR_REGION_CHUNK_ADDR] = MNL_TYPE_U64,
[DEVLINK_ATTR_REGION_CHUNK_LEN] = MNL_TYPE_U64,
[DEVLINK_ATTR_INFO_DRIVER_NAME] = MNL_TYPE_STRING,
[DEVLINK_ATTR_INFO_SERIAL_NUMBER] = MNL_TYPE_STRING,
[DEVLINK_ATTR_INFO_VERSION_FIXED] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_INFO_VERSION_RUNNING] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_INFO_VERSION_STORED] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_INFO_VERSION_NAME] = MNL_TYPE_STRING,
[DEVLINK_ATTR_INFO_VERSION_VALUE] = MNL_TYPE_STRING,
[DEVLINK_ATTR_HEALTH_REPORTER] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_HEALTH_REPORTER_NAME] = MNL_TYPE_STRING,
[DEVLINK_ATTR_HEALTH_REPORTER_STATE] = MNL_TYPE_U8,
[DEVLINK_ATTR_HEALTH_REPORTER_ERR_COUNT] = MNL_TYPE_U64,
[DEVLINK_ATTR_HEALTH_REPORTER_RECOVER_COUNT] = MNL_TYPE_U64,
[DEVLINK_ATTR_HEALTH_REPORTER_DUMP_TS] = MNL_TYPE_U64,
[DEVLINK_ATTR_HEALTH_REPORTER_GRACEFUL_PERIOD] = MNL_TYPE_U64,
[DEVLINK_ATTR_FLASH_UPDATE_COMPONENT] = MNL_TYPE_STRING,
[DEVLINK_ATTR_FLASH_UPDATE_STATUS_MSG] = MNL_TYPE_STRING,
[DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE] = MNL_TYPE_U64,
[DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL] = MNL_TYPE_U64,
[DEVLINK_ATTR_STATS] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_TRAP_NAME] = MNL_TYPE_STRING,
[DEVLINK_ATTR_TRAP_ACTION] = MNL_TYPE_U8,
[DEVLINK_ATTR_TRAP_TYPE] = MNL_TYPE_U8,
[DEVLINK_ATTR_TRAP_GENERIC] = MNL_TYPE_FLAG,
[DEVLINK_ATTR_TRAP_METADATA] = MNL_TYPE_NESTED,
[DEVLINK_ATTR_TRAP_GROUP_NAME] = MNL_TYPE_STRING,
[DEVLINK_ATTR_RELOAD_FAILED] = MNL_TYPE_U8,
};
static int attr_cb(const struct nlattr *attr, void *data)
{
const struct nlattr **tb = data;
int type;
if (mnl_attr_type_valid(attr, DEVLINK_ATTR_MAX) < 0)
return MNL_CB_OK;
type = mnl_attr_get_type(attr);
if (mnl_attr_validate(attr, devlink_policy[type]) < 0)
return MNL_CB_ERROR;
tb[type] = attr;
return MNL_CB_OK;
}
static int list_cb(const struct nlmsghdr *nlh, void *data)
{
struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
return MNL_CB_ERROR;
printf("%s/%s\n",
mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]),
mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]));
return MNL_CB_OK;
}
static void list(struct mv88e6xxx_ctx *ctx)
{
struct nlmsghdr *nlh;
uint16_t flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP;
nlh = mnlg_msg_prepare(ctx->nlg, DEVLINK_CMD_GET, flags);
_mnlg_socket_sndrcv(ctx->nlg, nlh, list_cb, ctx);
}
static int first_device_cb(const struct nlmsghdr *nlh, void *data)
{
struct mv88e6xxx_ctx *ctx = data;
struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
return MNL_CB_ERROR;
if (!ctx->bus_name) {
ctx->bus_name = strdup(mnl_attr_get_str(
tb[DEVLINK_ATTR_BUS_NAME]));
ctx->dev_name = strdup(mnl_attr_get_str(
tb[DEVLINK_ATTR_DEV_NAME]));
}
/* TODO Check this actually is an mv88e6xxx device */
return MNL_CB_OK;
}
static void first_device(struct mv88e6xxx_ctx *ctx)
{
struct nlmsghdr *nlh;
uint16_t flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP;
int err;
nlh = mnlg_msg_prepare(ctx->nlg, DEVLINK_CMD_GET, flags);
err = _mnlg_socket_sndrcv(ctx->nlg, nlh, first_device_cb, ctx);
if (err) {
printf("Error determining first device");
exit(EXIT_FAILURE);
}
if (!ctx->bus_name || !ctx->dev_name) {
printf("No devlink devices found\n");
exit(EXIT_FAILURE);
}
}
static void delete_snapshot_port_id(struct mv88e6xxx_ctx *ctx,
uint32_t port, const char *region_name,
uint32_t id)
{
struct nlmsghdr *nlh;
nlh = mnlg_msg_prepare(ctx->nlg, DEVLINK_CMD_REGION_DEL,
NLM_F_REQUEST | NLM_F_ACK);
mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, ctx->bus_name);
mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, ctx->dev_name);
if (port != ~0)
mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, port);
mnl_attr_put_strz(nlh, DEVLINK_ATTR_REGION_NAME, region_name);
mnl_attr_put_u32(nlh, DEVLINK_ATTR_REGION_SNAPSHOT_ID, id);
_mnlg_socket_sndrcv(ctx->nlg, nlh, NULL, NULL);
ctx->repeat = true;
}
static void delete_snapshot(struct mv88e6xxx_ctx *ctx, struct nlattr **tb)
{
struct nlattr *tb_snapshot[DEVLINK_ATTR_MAX + 1] = {};
struct nlattr *nla_sanpshot;
const char * region_name;
uint32_t snapshot_id;
uint32_t port = ~0;
int err;
region_name = mnl_attr_get_str(tb[DEVLINK_ATTR_REGION_NAME]);
if (tb[DEVLINK_ATTR_PORT_INDEX])
port = mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_INDEX]);
mnl_attr_for_each_nested(nla_sanpshot,
tb[DEVLINK_ATTR_REGION_SNAPSHOTS]) {
err = mnl_attr_parse_nested(nla_sanpshot, attr_cb, tb_snapshot);
if (err != MNL_CB_OK)
return;
if (!tb_snapshot[DEVLINK_ATTR_REGION_SNAPSHOT_ID])
return;
snapshot_id = mnl_attr_get_u32(
tb_snapshot[DEVLINK_ATTR_REGION_SNAPSHOT_ID]);
delete_snapshot_port_id(ctx, port, region_name, snapshot_id);
}
}
static int delete_snapshots_cb(const struct nlmsghdr *nlh, void *data)
{
struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
struct mv88e6xxx_ctx *ctx = data;
const char * region_name;
int port;
mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
!tb[DEVLINK_ATTR_REGION_NAME] || !tb[DEVLINK_ATTR_REGION_SIZE])
return MNL_CB_ERROR;
region_name = mnl_attr_get_str(tb[DEVLINK_ATTR_REGION_NAME]);
if (!strcmp(region_name, "port") && tb[DEVLINK_ATTR_PORT_INDEX]) {
port = mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_INDEX]);
ctx->port_enabled[port] = true;
if (port > ctx->ports)
ctx->ports = port;
}
if (tb[DEVLINK_ATTR_REGION_SNAPSHOTS])
delete_snapshot(ctx, tb);
return MNL_CB_OK;
}
static void delete_snapshots(struct mv88e6xxx_ctx *ctx)
{
struct nlmsghdr *nlh;
uint16_t flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP;
/* Sending a new message while decoding an older message
* results in problems. So keep repeating until all regions
* snapshots are gone. */
do {
ctx->repeat = false;
nlh = mnlg_msg_prepare(ctx->nlg, DEVLINK_CMD_REGION_GET, flags);
mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, ctx->bus_name);
mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, ctx->dev_name);
_mnlg_socket_sndrcv(ctx->nlg, nlh, delete_snapshots_cb, ctx);
} while (ctx->repeat);
}
static int new_snapshot_port_id(struct mv88e6xxx_ctx *ctx,
uint32_t port, const char *region_name,
uint32_t id)
{
struct nlmsghdr *nlh;
int err;
nlh = mnlg_msg_prepare(ctx->nlg, DEVLINK_CMD_REGION_NEW,
NLM_F_REQUEST | NLM_F_ACK);
mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, ctx->bus_name);
mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, ctx->dev_name);
mnl_attr_put_strz(nlh, DEVLINK_ATTR_REGION_NAME, region_name);
if (port != ~0)
mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, port);
mnl_attr_put_u32(nlh, DEVLINK_ATTR_REGION_SNAPSHOT_ID, id);
err = _mnlg_socket_sndrcv(ctx->nlg, nlh, NULL, NULL);
if (err)
printf("Unable to snapshot %s\n", region_name);
return err;
}
static int new_snapshot_id(struct mv88e6xxx_ctx *ctx, const char *region_name,
uint32_t id)
{
return new_snapshot_port_id(ctx, ~0, region_name, id);
}
static int new_snapshot(struct mv88e6xxx_ctx *ctx, const char *region_name)
{
return new_snapshot_id(ctx, region_name, SNAPSHOT_ID);
}
void dump_snapshot_add_data(struct mv88e6xxx_ctx *ctx,
const uint8_t *data, size_t len,
uint64_t addr)
{
if (addr > MAX_SNAPSHOT_DATA) {
printf("Data ignored, start address outside buffer\n");
return;
}
if (addr + len > MAX_SNAPSHOT_DATA) {
printf("Data truncated\n");
len = MAX_SNAPSHOT_DATA - addr;
}
memcpy(ctx->snapshot_data + addr, data, len);
ctx->data_len = addr + len;
}
static int dump_snapshot_cb(const struct nlmsghdr *nlh, void *data)
{
struct nlattr *nla_entry, *nla_chunk_data, *nla_chunk_addr;
struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
struct nlattr *tb_field[DEVLINK_ATTR_MAX + 1] = {};
struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
struct mv88e6xxx_ctx *ctx = data;
int err;
mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
!tb[DEVLINK_ATTR_REGION_CHUNKS])
return MNL_CB_ERROR;
mnl_attr_for_each_nested(nla_entry, tb[DEVLINK_ATTR_REGION_CHUNKS]) {
err = mnl_attr_parse_nested(nla_entry, attr_cb, tb_field);
if (err != MNL_CB_OK)
return MNL_CB_ERROR;
nla_chunk_data = tb_field[DEVLINK_ATTR_REGION_CHUNK_DATA];
if (!nla_chunk_data)
continue;
nla_chunk_addr = tb_field[DEVLINK_ATTR_REGION_CHUNK_ADDR];
if (!nla_chunk_addr)
continue;
dump_snapshot_add_data(ctx,
mnl_attr_get_payload(nla_chunk_data),
mnl_attr_get_payload_len(nla_chunk_data),
mnl_attr_get_u64(nla_chunk_addr));
}
return MNL_CB_OK;
}
static int dump_snapshot_port_id(struct mv88e6xxx_ctx *ctx,
uint32_t port, const char *region_name,
uint32_t id)
{
struct nlmsghdr *nlh;
int err;
nlh = mnlg_msg_prepare(ctx->nlg, DEVLINK_CMD_REGION_READ,
NLM_F_REQUEST | NLM_F_ACK | NLM_F_DUMP);
mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, ctx->bus_name);
mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, ctx->dev_name);
if (port != ~0)
mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, port);
mnl_attr_put_strz(nlh, DEVLINK_ATTR_REGION_NAME, region_name);
mnl_attr_put_u32(nlh, DEVLINK_ATTR_REGION_SNAPSHOT_ID, id);
err = _mnlg_socket_sndrcv(ctx->nlg, nlh, dump_snapshot_cb, ctx);
if (err)
printf("Unable to dump snapshot %s\n", region_name);
return err;
}
static int dump_snapshot_id(struct mv88e6xxx_ctx *ctx,
const char *region_name, uint32_t id)
{
return dump_snapshot_port_id(ctx, ~0, region_name, id);
}
static int dump_snapshot(struct mv88e6xxx_ctx *ctx, const char *region_name)
{
return dump_snapshot_id(ctx, region_name, SNAPSHOT_ID);
}
static int port_dump(struct mv88e6xxx_ctx *ctx, int port)
{
char region_name[32];
int err, reg;
uint16_t *p;
sprintf(region_name, "port", port);
err = new_snapshot_port_id(ctx, port, "port", SNAPSHOT_ID + port);
if (err) {
return err;
}
err = dump_snapshot_port_id(ctx, port, "port", SNAPSHOT_ID + port);
if (err)
return err;
p = (uint16_t *)ctx->snapshot_data;
for (reg = 0; reg < 32; reg++)
ctx->port_regs[port][reg] = p[reg];
return 0;
}
#define FIELD(_name, _fmt, ...) \
printf(" %-36.36s " _fmt "\n", _name, ##__VA_ARGS__)
#define FIELD_BITMAP(_name, _val) \
FIELD(_name, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", \
((_val) & 0x0001) ? "0 " : "", \
((_val) & 0x0002) ? "1 " : "", \
((_val) & 0x0004) ? "2 " : "", \
((_val) & 0x0008) ? "3 " : "", \
((_val) & 0x0010) ? "4 " : "", \
((_val) & 0x0020) ? "5 " : "", \
((_val) & 0x0040) ? "6 " : "", \
((_val) & 0x0080) ? "7 " : "", \
((_val) & 0x0100) ? "8 " : "", \
((_val) & 0x0200) ? "9 " : "", \
((_val) & 0x0400) ? "10 " : "", \
((_val) & 0x0800) ? "11 " : "", \
((_val) & 0x1000) ? "12 " : "", \
((_val) & 0x2000) ? "13 " : "", \
((_val) & 0x4000) ? "14 " : "", \
((_val) & 0x8000) ? "15 " : "")
static void port_6161(int reg, uint16_t val)
{
switch (reg) {
case 0:
FIELD("Pause Enabled", "%u", !!(val & 0x8000));
FIELD("My Pause", "%u", !!(val & 0x4000));
FIELD("Half-duplex Flow Control", "%u", !!(val & 0x2000));
FIELD("802.3 PHY Detected", "%u", !!(val & 0x1000));
FIELD("Link Status", "%s", val & 0x0800 ? "Up" : "Down");
FIELD("Duplex", "%s", val & 0x0400 ? "Full" : "Half");
FIELD("Speed", "%s",
(val & 0x0300) == 0x0000 ? "10 Mbps" :
(val & 0x0300) == 0x0100 ? "100 Mbps" :
(val & 0x0300) == 0x0200 ? "1000 Mbps" :
(val & 0x0300) == 0x0300 ? "Reserved" : "?");
FIELD("Auto-Media Detect Disable", "%u", !!(val & 0x0040));
FIELD("Transmitter Paused", "%u", !!(val & 0x0020));
FIELD("Flow Control", "%u", !!(val & 0x0010));
FIELD("Config Duplex", "%s", val & 0x0008 ? "Full" : "Half");
FIELD("Config Mode", "0x%x", val & 0x0007);
break;
case 1:
FIELD("Flow Control's Forced value", "%u", !!(val & 0x0080));
FIELD("Force Flow Control", "%u", !!(val & 0x0040));
FIELD("Link's Forced value", "%s", val & 0x0020 ? "Up" : "Down");
FIELD("Force Link", "%u", !!(val & 0x0010));
FIELD("Duplex's Forced value", "%s", val & 0x0008 ? "Full" :
"Half");
FIELD("Force Duplex", "%u", !!(val & 0x0004));
FIELD("Force Speed", "%s",
(val & 0x0003) == 0x0000 ? "10 Mbps" :
(val & 0x0003) == 0x0001 ? "100 Mbps" :
(val & 0x0003) == 0x0002 ? "1000 Mbps" :
(val & 0x0003) == 0x0003 ? "Not forced" : "?");
break;
case 4:
FIELD("Source Address Filtering controls", "%s",
(val & 0xc000) == 0x0000 ? "Disabled" :
(val & 0xc000) == 0x4000 ? "Drop On Lock" :
(val & 0xc000) == 0x8000 ? "Drop On Unlock" :
(val & 0xc000) == 0xc000 ? "Drop to CPU" : "?");
FIELD("Egress Mode", "%s",
(val & 0x3000) == 0x0000 ? "Unmodified" :
(val & 0x3000) == 0x1000 ? "Untagged" :
(val & 0x3000) == 0x2000 ? "Tagged" :
(val & 0x3000) == 0x3000 ? "Reserved" : "?");
FIELD("Ingress & Egress Header Mode", "%u", !!(val & 0x0800));
FIELD("IGMP and MLD Snooping", "%u", !!(val & 0x0400));
FIELD("Frame Mode", "%s",
(val & 0x0300) == 0x0000 ? "Normal" :
(val & 0x0300) == 0x0100 ? "DSA" :
(val & 0x0300) == 0x0200 ? "Provider" :
(val & 0x0300) == 0x0300 ? "Ether Type DSA" : "?");
FIELD("VLAN Tunnel", "%u", !!(val & 0x0080));
FIELD("TagIfBoth", "%u", !!(val & 0x0040));
FIELD("Initial Priority assignment", "%s",
(val & 0x0030) == 0x0000 ? "Defaults" :
(val & 0x0030) == 0x0010 ? "Tag Priority" :
(val & 0x0030) == 0x0020 ? "IP Priority" :
(val & 0x0030) == 0x0030 ? "Tag & IP Priority" : "?");
FIELD("Egress Flooding mode", "%s",
(val & 0x000c) == 0x0000 ? "No unknown DA" :
(val & 0x000c) == 0x0004 ? "No unknown multicast DA" :
(val & 0x000c) == 0x0008 ? "No unknown unicast DA" :
(val & 0x000c) == 0x000c ? "Allow unknown DA" : "?");
FIELD("Port State", "%s",
(val & 0x0003) == 0x0000 ? "Disabled" :
(val & 0x0003) == 0x0001 ? "Blocking/Listening" :
(val & 0x0003) == 0x0002 ? "Learning" :
(val & 0x0003) == 0x0003 ? "Forwarding" : "?");
break;
case 5:
FIELD("Message Port", "%u", !!(val & 0x8000));
FIELD("Trunk Port", "%u", !!(val & 0x4000));
FIELD("Trunk ID", "%u", (val & 0x0f00) >> 8);
FIELD("FID[5:4]", "0x%.2x", (val & 0x0003) << 4);
break;
case 6:
FIELD("FID[3:0]", "0x%.2x", (val & 0xf000) >> 12);
FIELD_BITMAP("VLANTable", val & 0x003f);
break;
case 7:
FIELD("Default Priority", "0x%x", (val & 0xe000) >> 13);
FIELD("Force to use Default VID", "%u", !!(val & 0x1000));
FIELD("Default VLAN Identifier", "%u", val & 0x0fff);
break;
case 8:
FIELD("Force good FCS in the frame", "%u", !!(val & 0x8000));
FIELD("Jumbo Mode", "%s",
(val & 0x3000) == 0x0000 ? "1522" :
(val & 0x3000) == 0x1000 ? "2048" :
(val & 0x3000) == 0x2000 ? "10240" :
(val & 0x3000) == 0x3000 ? "Reserved" : "?");
FIELD("802.1QMode", "%s",
(val & 0x0c00) == 0x0000 ? "Disabled" :
(val & 0x0c00) == 0x0400 ? "Fallback" :
(val & 0x0c00) == 0x0800 ? "Check" :
(val & 0x0c00) == 0x0c00 ? "Secure" : "?");
FIELD("Discard Tagged Frames", "%u", !!(val & 0x0200));
FIELD("Discard Untagged Frames", "%u", !!(val & 0x0100));
FIELD("Map using DA hits", "%u", !!(val & 0x0080));
FIELD("ARP Mirror enable", "%u", !!(val & 0x0040));
FIELD("Egress Monitor Source Port", "%u", !!(val & 0x0020));
FIELD("Ingress Monitor Source Port", "%u", !!(val & 0x0010));
break;
}
}
static void port_6352(int reg, uint16_t val)
{
switch (reg) {
case 0:
FIELD("Pause Enabled", "%u", !!(val & 0x8000));
FIELD("My Pause", "%u", !!(val & 0x4000));
FIELD("802.3 PHY Detected", "%u", !!(val & 0x1000));
FIELD("Link Status", "%s", val & 0x0800 ? "Up" : "Down");
FIELD("Duplex", "%s", val & 0x0400 ? "Full" : "Half");
FIELD("Speed", "%s",
(val & 0x0300) == 0x0000 ? "10 Mbps" :
(val & 0x0300) == 0x0100 ? "100 or 200 Mbps" :
(val & 0x0300) == 0x0200 ? "1000 Mbps" :
(val & 0x0300) == 0x0300 ? "Reserved" : "?");
FIELD("EEE Enabled", "%u", !!(val & 0x0040));
FIELD("Transmitter Paused", "%u", !!(val & 0x0020));
FIELD("Flow Control", "%u", !!(val & 0x0010));
FIELD("Config Mode", "0x%x", val & 0x000f);
break;
case 1:
FIELD("RGMII Receive Timing Control", "%s", val & 0x8000 ?
"Delay" : "Default");
FIELD("RGMII Transmit Timing Control", "%s", val & 0x4000 ?
"Delay" : "Default");
FIELD("200 BASE Mode", "%s", val & 0x1000 ? "200" : "100");
FIELD("Flow Control's Forced value", "%u", !!(val & 0x0080));
FIELD("Force Flow Control", "%u", !!(val & 0x0040));
FIELD("Link's Forced value", "%s", val & 0x0020 ? "Up" : "Down");
FIELD("Force Link", "%u", !!(val & 0x0010));
FIELD("Duplex's Forced value", "%s", val & 0x0008 ?
"Full" : "Half");
FIELD("Force Duplex", "%u", !!(val & 0x0004));
FIELD("Force Speed", "%s",
(val & 0x0003) == 0x0000 ? "10 Mbps" :
(val & 0x0003) == 0x0001 ? "100 or 200 Mbps" :
(val & 0x0003) == 0x0002 ? "1000 Mbps" :
(val & 0x0003) == 0x0003 ? "Not forced" : "?");
break;
case 4:
FIELD("Source Address Filtering controls", "%s",
(val & 0xc000) == 0x0000 ? "Disabled" :
(val & 0xc000) == 0x4000 ? "Drop On Lock" :
(val & 0xc000) == 0x8000 ? "Drop On Unlock" :
(val & 0xc000) == 0xc000 ? "Drop to CPU" : "?");
FIELD("Egress Mode", "%s",
(val & 0x3000) == 0x0000 ? "Unmodified" :
(val & 0x3000) == 0x1000 ? "Untagged" :
(val & 0x3000) == 0x2000 ? "Tagged" :
(val & 0x3000) == 0x3000 ? "Reserved" : "?");
FIELD("Ingress & Egress Header Mode", "%u", !!(val & 0x0800));
FIELD("IGMP and MLD Snooping", "%u", !!(val & 0x0400));
FIELD("Frame Mode", "%s",
(val & 0x0300) == 0x0000 ? "Normal" :
(val & 0x0300) == 0x0100 ? "DSA" :
(val & 0x0300) == 0x0200 ? "Provider" :
(val & 0x0300) == 0x0300 ? "Ether Type DSA" : "?");
FIELD("VLAN Tunnel", "%u", !!(val & 0x0080));
FIELD("TagIfBoth", "%u", !!(val & 0x0040));
FIELD("Initial Priority assignment", "%s",
(val & 0x0030) == 0x0000 ? "Defaults" :
(val & 0x0030) == 0x0010 ? "Tag Priority" :
(val & 0x0030) == 0x0020 ? "IP Priority" :
(val & 0x0030) == 0x0030 ? "Tag & IP Priority" : "?");
FIELD("Egress Flooding mode", "%s",
(val & 0x000c) == 0x0000 ? "No unknown DA" :
(val & 0x000c) == 0x0004 ? "No unknown multicast DA" :
(val & 0x000c) == 0x0008 ? "No unknown unicast DA" :
(val & 0x000c) == 0x000c ? "Allow unknown DA" : "?");
FIELD("Port State", "%s",
(val & 0x0003) == 0x0000 ? "Disabled" :
(val & 0x0003) == 0x0001 ? "Blocking/Listening" :
(val & 0x0003) == 0x0002 ? "Learning" :
(val & 0x0003) == 0x0003 ? "Forwarding" : "?");
break;
case 5:
FIELD("Message Port", "%u", !!(val & 0x8000));
FIELD("Trunk Port", "%u", !!(val & 0x4000));
FIELD("Trunk ID", "%u", (val & 0x0f00) >> 8);
FIELD("FID[11:4]", "0x%.3x", (val & 0x00ff) << 4);
break;
case 6:
FIELD("FID[3:0]", "0x%.3x", (val & 0xf000) >> 12);
FIELD_BITMAP("VLANTable", val & 0x007f);
break;
case 7:
FIELD("Default Priority", "0x%x", (val & 0xe000) >> 13);
FIELD("Force to use Default VID", "%u", !!(val & 0x1000));
FIELD("Default VLAN Identifier", "%u", val & 0x0fff);
break;
case 8:
FIELD("Force good FCS in the frame", "%u", !!(val & 0x8000));
FIELD("Jumbo Mode", "%s",
(val & 0x3000) == 0x0000 ? "1522" :
(val & 0x3000) == 0x1000 ? "2048" :
(val & 0x3000) == 0x2000 ? "10240" :
(val & 0x3000) == 0x3000 ? "Reserved" : "?");
FIELD("802.1QMode", "%s",
(val & 0x0c00) == 0x0000 ? "Disabled" :
(val & 0x0c00) == 0x0400 ? "Fallback" :
(val & 0x0c00) == 0x0800 ? "Check" :
(val & 0x0c00) == 0x0c00 ? "Secure" : "?");
FIELD("Discard Tagged Frames", "%u", !!(val & 0x0200));
FIELD("Discard Untagged Frames", "%u", !!(val & 0x0100));
FIELD("Map using DA hits", "%u", !!(val & 0x0080));
FIELD("ARP Mirror enable", "%u", !!(val & 0x0040));
FIELD("Egress Monitor Source Port", "%u", !!(val & 0x0020));
FIELD("Ingress Monitor Source Port", "%u", !!(val & 0x0010));
FIELD("Use Default Queue Priority", "%u", !!(val & 0x0008));
FIELD("Default Queue Priority", "0x%x", (val & 0x0006) >> 1);
break;
}
};
static void port_6390(int reg, uint16_t val)
{
switch (reg) {
case 0:
FIELD("Transmit Pause Enable bit", "%u", !!(val & 0x8000));
FIELD("Receive Pause Enable bit", "%u", !!(val & 0x4000));
FIELD("802.3 PHY Detected", "%u", !!(val & 0x1000));
FIELD("Link Status", "%s", val & 0x0800 ? "Up" : "Down");
FIELD("Duplex", "%s", val & 0x0400 ? "Full" : "Half");
FIELD("Speed", "%s",
(val & 0x0300) == 0x0000 ? "10 Mbps" :
(val & 0x0300) == 0x0100 ? "100 or 200 Mbps" :
(val & 0x0300) == 0x0200 ? "1000 Mbps" :
(val & 0x0300) == 0x0300 ? "10 Gb or 2500 Mbps" : "?");
FIELD("Duplex Fixed", "%u", !!(val & 0x0080));
FIELD("EEE Enabled", "%u", !!(val & 0x0040));
FIELD("Transmitter Paused", "%u", !!(val & 0x0020));
FIELD("Flow Control", "%u", !!(val & 0x0010));
FIELD("Config Mode", "0x%x", val & 0x000f);
break;
case 1:
FIELD("RGMII Receive Timing Control", "%s", val & 0x8000 ?
"Delay" : "Default");
FIELD("RGMII Transmit Timing Control", "%s", val & 0x4000 ?
"Delay" : "Default");
FIELD("Force Speed", "%u", !!(val & 0x2000));
FIELD("Alternate Speed Mode", "%s", val & 0x1000 ?
"Alternate" : "Normal");
FIELD("MII PHY Mode", "%s", val & 0x0800 ? "PHY" : "MAC");
FIELD("EEE force value", "%u", !!(val & 0x0200));
FIELD("Force EEE", "%u", !!(val & 0x0100));
FIELD("Link's Forced value", "%s", val & 0x0020 ? "Up" : "Down");
FIELD("Force Link", "%u", !!(val & 0x0010));
FIELD("Duplex's Forced value", "%s", val & 0x0008 ? "Full" :
"Half");
FIELD("Force Duplex", "%u", !!(val & 0x0004));
FIELD("Force Speed", "%s",
(val & 0x0003) == 0x0000 ? "10 Mbps" :
(val & 0x0003) == 0x0001 ? "100 or 200 Mbps" :
(val & 0x0003) == 0x0002 ? "1000 Mbps" :
(val & 0x0003) == 0x0003 ? "10 Gb or 2500 Mbps" : "?");
break;
case 4:
FIELD("Source Address Filtering controls", "%s",
(val & 0xc000) == 0x0000 ? "Disabled" :
(val & 0xc000) == 0x4000 ? "Drop On Lock" :
(val & 0xc000) == 0x8000 ? "Drop On Unlock" :
(val & 0xc000) == 0xc000 ? "Drop to CPU" : "?");
FIELD("Egress Mode", "%s",
(val & 0x3000) == 0x0000 ? "Unmodified" :
(val & 0x3000) == 0x1000 ? "Untagged" :
(val & 0x3000) == 0x2000 ? "Tagged" :
(val & 0x3000) == 0x3000 ? "Reserved" : "?");
FIELD("Ingress & Egress Header Mode", "%u", !!(val & 0x0800));
FIELD("IGMP and MLD Snooping", "%u", !!(val & 0x0400));
FIELD("Frame Mode", "%s",
(val & 0x0300) == 0x0000 ? "Normal" :
(val & 0x0300) == 0x0100 ? "DSA" :
(val & 0x0300) == 0x0200 ? "Provider" :
(val & 0x0300) == 0x0300 ? "Ether Type DSA" : "?");
FIELD("VLAN Tunnel", "%u", !!(val & 0x0080));
FIELD("TagIfBoth", "%u", !!(val & 0x0040));
FIELD("Initial Priority assignment", "%s",
(val & 0x0030) == 0x0000 ? "Defaults" :
(val & 0x0030) == 0x0010 ? "Tag Priority" :
(val & 0x0030) == 0x0020 ? "IP Priority" :
(val & 0x0030) == 0x0030 ? "Tag & IP Priority" : "?");
FIELD("Egress Flooding mode", "%s",
(val & 0x000c) == 0x0000 ? "No unknown DA" :
(val & 0x000c) == 0x0004 ? "No unknown multicast DA" :
(val & 0x000c) == 0x0008 ? "No unknown unicast DA" :
(val & 0x000c) == 0x000c ? "Allow unknown DA" : "?");
FIELD("Port State", "%s",
(val & 0x0003) == 0x0000 ? "Disabled" :
(val & 0x0003) == 0x0001 ? "Blocking/Listening" :
(val & 0x0003) == 0x0002 ? "Learning" :
(val & 0x0003) == 0x0003 ? "Forwarding" : "?");
break;
case 5:
FIELD("Message Port", "%u", !!(val & 0x8000));
FIELD("LAG Port", "%u", !!(val & 0x4000));
FIELD("VTU Page", "%u", !!(val & 0x2000));
FIELD("LAG ID", "%u", (val & 0x0f00) >> 8);
FIELD("FID[11:4]", "0x%.3x", (val & 0x00ff) << 4);
break;
case 6:
FIELD("FID[3:0]", "0x%.3x", (val & 0xf000) >> 12);
FIELD("Force Mapping", "%u", !!(val & 0x0800));
FIELD_BITMAP("VLANTable", val & 0x007ff);
break;
case 7:
FIELD("Default Priority", "0x%x", (val & 0xe000) >> 13);
FIELD("Force to use Default VID", "%u", !!(val & 0x1000));
FIELD("Default VLAN Identifier", "%u", val & 0x0fff);
break;
case 8:
FIELD("Force good FCS in the frame", "%u", !!(val & 0x8000));
FIELD("Allow bad FCS", "%u", !!(val & 0x4000));
FIELD("Jumbo Mode", "%s",
(val & 0x3000) == 0x0000 ? "1522" :
(val & 0x3000) == 0x1000 ? "2048" :
(val & 0x3000) == 0x2000 ? "10240" :
(val & 0x3000) == 0x3000 ? "Reserved" : "?");
FIELD("802.1QMode", "%s",
(val & 0x0c00) == 0x0000 ? "Disabled" :
(val & 0x0c00) == 0x0400 ? "Fallback" :
(val & 0x0c00) == 0x0800 ? "Check" :
(val & 0x0c00) == 0x0c00 ? "Secure" : "?");
FIELD("Discard Tagged Frames", "%u", !!(val & 0x0200));
FIELD("Discard Untagged Frames", "%u", !!(val & 0x0100));
FIELD("Map using DA hits", "%u", !!(val & 0x0080));
FIELD("ARP Mirror enable", "%u", !!(val & 0x0040));
FIELD("Egress Monitor Source Port", "%u", !!(val & 0x0020));
FIELD("Ingress Monitor Source Port", "%u", !!(val & 0x0010));
FIELD("Allow VID of Zero", "%u", !!(val & 0x0008));
FIELD("Default Queue Priority", "0x%x", val & 0x0007);
break;
}
};
static const char *mv88e6161_port_reg_names[32] = {
"Port status",
"Physical control",
"Reserved",
"Switch ID",
"Port control",
"Port control 1",
"Port base VLAN map",
"Def VLAN ID & Prio",
"Port control 2",
"Egress rate control",
"Egress rate control 2",
"Port association vec",
"Port ATU control",
"Override",
"Reserved",
"Port ether type",
"In discard low",
"In discard high",
"In filtered",
"Out filtered",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Tag remap low",
"Tag remap high",
"Reserved",
"Queue counters",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
};
static const char *mv88e6165_port_reg_names[32] = {
"Port status",
"Physical control",
"Reserved",
"Switch ID",
"Port control",
"Port control 1",
"Port base VLAN map",
"Def VLAN ID & Prio",
"Port control 2",
"Rate control",
"Rate control 2",
"Port association vec",
"Port ATU control",
"Override",
"Policy control",
"Port ether type",
"In discard low",
"In discard high",
"In filtered",
"Out filtered",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
"Tag remap low",
"Tag remap high",
"Reserved",
"Queue counters",
"Reserved",
"Reserved",
"Reserved",
"Reserved",
};
static const char *mv88e6185_port_reg_names[32] = {
"Port status",
"Physical control",
"Reserved",
"Switch ID",
"Port control",
"Port control 1",
"Port base VLAN map",
"Def VLAN ID & Prio",