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
|
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/* Copyright (C) 2017-2018 Netronome Systems, Inc. */
#include <linux/ethtool.h>
#include <linux/vmalloc.h>
#include "nfp_asm.h"
#include "nfp_main.h"
#include "nfpcore/nfp.h"
#include "nfpcore/nfp_nffw.h"
#include "nfpcore/nfp6000/nfp6000.h"
#define NFP_DUMP_SPEC_RTSYM "_abi_dump_spec"
#define ALIGN8(x) ALIGN(x, 8)
enum nfp_dumpspec_type {
NFP_DUMPSPEC_TYPE_CPP_CSR = 0,
NFP_DUMPSPEC_TYPE_XPB_CSR = 1,
NFP_DUMPSPEC_TYPE_ME_CSR = 2,
NFP_DUMPSPEC_TYPE_INDIRECT_ME_CSR = 3,
NFP_DUMPSPEC_TYPE_RTSYM = 4,
NFP_DUMPSPEC_TYPE_HWINFO = 5,
NFP_DUMPSPEC_TYPE_FWNAME = 6,
NFP_DUMPSPEC_TYPE_HWINFO_FIELD = 7,
NFP_DUMPSPEC_TYPE_PROLOG = 10000,
NFP_DUMPSPEC_TYPE_ERROR = 10001,
};
/* The following structs must be carefully aligned so that they can be used to
* interpret the binary dumpspec and populate the dump data in a deterministic
* way.
*/
/* generic type plus length */
struct nfp_dump_tl {
__be32 type;
__be32 length; /* chunk length to follow, aligned to 8 bytes */
char data[0];
};
/* NFP CPP parameters */
struct nfp_dumpspec_cpp_isl_id {
u8 target;
u8 action;
u8 token;
u8 island;
};
struct nfp_dump_common_cpp {
struct nfp_dumpspec_cpp_isl_id cpp_id;
__be32 offset; /* address to start dump */
__be32 dump_length; /* total bytes to dump, aligned to reg size */
};
/* CSR dumpables */
struct nfp_dumpspec_csr {
struct nfp_dump_tl tl;
struct nfp_dump_common_cpp cpp;
__be32 register_width; /* in bits */
};
struct nfp_dumpspec_rtsym {
struct nfp_dump_tl tl;
char rtsym[0];
};
/* header for register dumpable */
struct nfp_dump_csr {
struct nfp_dump_tl tl;
struct nfp_dump_common_cpp cpp;
__be32 register_width; /* in bits */
__be32 error; /* error code encountered while reading */
__be32 error_offset; /* offset being read when error occurred */
};
struct nfp_dump_rtsym {
struct nfp_dump_tl tl;
struct nfp_dump_common_cpp cpp;
__be32 error; /* error code encountered while reading */
u8 padded_name_length; /* pad so data starts at 8 byte boundary */
char rtsym[0];
/* after padded_name_length, there is dump_length data */
};
struct nfp_dump_prolog {
struct nfp_dump_tl tl;
__be32 dump_level;
};
struct nfp_dump_error {
struct nfp_dump_tl tl;
__be32 error;
char padding[4];
char spec[0];
};
/* to track state through debug size calculation TLV traversal */
struct nfp_level_size {
__be32 requested_level; /* input */
u32 total_size; /* output */
};
/* to track state during debug dump creation TLV traversal */
struct nfp_dump_state {
__be32 requested_level; /* input param */
u32 dumped_size; /* adds up to size of dumped data */
u32 buf_size; /* size of buffer pointer to by p */
void *p; /* current point in dump buffer */
};
typedef int (*nfp_tlv_visit)(struct nfp_pf *pf, struct nfp_dump_tl *tl,
void *param);
static int
nfp_traverse_tlvs(struct nfp_pf *pf, void *data, u32 data_length, void *param,
nfp_tlv_visit tlv_visit)
{
long long remaining = data_length;
struct nfp_dump_tl *tl;
u32 total_tlv_size;
void *p = data;
int err;
while (remaining >= sizeof(*tl)) {
tl = p;
if (!tl->type && !tl->length)
break;
if (be32_to_cpu(tl->length) > remaining - sizeof(*tl))
return -EINVAL;
total_tlv_size = sizeof(*tl) + be32_to_cpu(tl->length);
/* Spec TLVs should be aligned to 4 bytes. */
if (total_tlv_size % 4 != 0)
return -EINVAL;
p += total_tlv_size;
remaining -= total_tlv_size;
err = tlv_visit(pf, tl, param);
if (err)
return err;
}
return 0;
}
static u32 nfp_get_numeric_cpp_id(struct nfp_dumpspec_cpp_isl_id *cpp_id)
{
return NFP_CPP_ISLAND_ID(cpp_id->target, cpp_id->action, cpp_id->token,
cpp_id->island);
}
struct nfp_dumpspec *
nfp_net_dump_load_dumpspec(struct nfp_cpp *cpp, struct nfp_rtsym_table *rtbl)
{
const struct nfp_rtsym *specsym;
struct nfp_dumpspec *dumpspec;
int bytes_read;
u64 sym_size;
specsym = nfp_rtsym_lookup(rtbl, NFP_DUMP_SPEC_RTSYM);
if (!specsym)
return NULL;
sym_size = nfp_rtsym_size(specsym);
/* expected size of this buffer is in the order of tens of kilobytes */
dumpspec = vmalloc(sizeof(*dumpspec) + sym_size);
if (!dumpspec)
return NULL;
dumpspec->size = sym_size;
bytes_read = nfp_rtsym_read(cpp, specsym, 0, dumpspec->data, sym_size);
if (bytes_read != sym_size) {
vfree(dumpspec);
nfp_warn(cpp, "Debug dump specification read failed.\n");
return NULL;
}
return dumpspec;
}
static int nfp_dump_error_tlv_size(struct nfp_dump_tl *spec)
{
return ALIGN8(sizeof(struct nfp_dump_error) + sizeof(*spec) +
be32_to_cpu(spec->length));
}
static int nfp_calc_fwname_tlv_size(struct nfp_pf *pf)
{
u32 fwname_len = strlen(nfp_mip_name(pf->mip));
return sizeof(struct nfp_dump_tl) + ALIGN8(fwname_len + 1);
}
static int nfp_calc_hwinfo_field_sz(struct nfp_pf *pf, struct nfp_dump_tl *spec)
{
u32 tl_len, key_len;
const char *value;
tl_len = be32_to_cpu(spec->length);
key_len = strnlen(spec->data, tl_len);
if (key_len == tl_len)
return nfp_dump_error_tlv_size(spec);
value = nfp_hwinfo_lookup
|