forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/drivers/net/ethernet/netronome/nfp/nfp_net_debugdump.c
....@@ -1,35 +1,5 @@
1
-/*
2
- * Copyright (C) 2017 Netronome Systems, Inc.
3
- *
4
- * This software is dual licensed under the GNU General License Version 2,
5
- * June 1991 as shown in the file COPYING in the top-level directory of this
6
- * source tree or the BSD 2-Clause License provided below. You have the
7
- * option to license this software under the complete terms of either license.
8
- *
9
- * The BSD 2-Clause License:
10
- *
11
- * Redistribution and use in source and binary forms, with or
12
- * without modification, are permitted provided that the following
13
- * conditions are met:
14
- *
15
- * 1. Redistributions of source code must retain the above
16
- * copyright notice, this list of conditions and the following
17
- * disclaimer.
18
- *
19
- * 2. Redistributions in binary form must reproduce the above
20
- * copyright notice, this list of conditions and the following
21
- * disclaimer in the documentation and/or other materials
22
- * provided with the distribution.
23
- *
24
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
- * SOFTWARE.
32
- */
1
+// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2
+/* Copyright (C) 2017-2018 Netronome Systems, Inc. */
333
344 #include <linux/ethtool.h>
355 #include <linux/vmalloc.h>
....@@ -66,7 +36,7 @@
6636 struct nfp_dump_tl {
6737 __be32 type;
6838 __be32 length; /* chunk length to follow, aligned to 8 bytes */
69
- char data[0];
39
+ char data[];
7040 };
7141
7242 /* NFP CPP parameters */
....@@ -92,7 +62,7 @@
9262
9363 struct nfp_dumpspec_rtsym {
9464 struct nfp_dump_tl tl;
95
- char rtsym[0];
65
+ char rtsym[];
9666 };
9767
9868 /* header for register dumpable */
....@@ -109,7 +79,7 @@
10979 struct nfp_dump_common_cpp cpp;
11080 __be32 error; /* error code encountered while reading */
11181 u8 padded_name_length; /* pad so data starts at 8 byte boundary */
112
- char rtsym[0];
82
+ char rtsym[];
11383 /* after padded_name_length, there is dump_length data */
11484 };
11585
....@@ -122,7 +92,7 @@
12292 struct nfp_dump_tl tl;
12393 __be32 error;
12494 char padding[4];
125
- char spec[0];
95
+ char spec[];
12696 };
12797
12898 /* to track state through debug size calculation TLV traversal */
....@@ -188,25 +158,21 @@
188158 const struct nfp_rtsym *specsym;
189159 struct nfp_dumpspec *dumpspec;
190160 int bytes_read;
191
- u32 cpp_id;
161
+ u64 sym_size;
192162
193163 specsym = nfp_rtsym_lookup(rtbl, NFP_DUMP_SPEC_RTSYM);
194164 if (!specsym)
195165 return NULL;
166
+ sym_size = nfp_rtsym_size(specsym);
196167
197168 /* expected size of this buffer is in the order of tens of kilobytes */
198
- dumpspec = vmalloc(sizeof(*dumpspec) + specsym->size);
169
+ dumpspec = vmalloc(sizeof(*dumpspec) + sym_size);
199170 if (!dumpspec)
200171 return NULL;
172
+ dumpspec->size = sym_size;
201173
202
- dumpspec->size = specsym->size;
203
-
204
- cpp_id = NFP_CPP_ISLAND_ID(specsym->target, NFP_CPP_ACTION_RW, 0,
205
- specsym->domain);
206
-
207
- bytes_read = nfp_cpp_read(cpp, cpp_id, specsym->addr, dumpspec->data,
208
- specsym->size);
209
- if (bytes_read != specsym->size) {
174
+ bytes_read = nfp_rtsym_read(cpp, specsym, 0, dumpspec->data, sym_size);
175
+ if (bytes_read != sym_size) {
210176 vfree(dumpspec);
211177 nfp_warn(cpp, "Debug dump specification read failed.\n");
212178 return NULL;
....@@ -266,7 +232,6 @@
266232 struct nfp_dumpspec_rtsym *spec_rtsym;
267233 const struct nfp_rtsym *sym;
268234 u32 tl_len, key_len;
269
- u32 size;
270235
271236 spec_rtsym = (struct nfp_dumpspec_rtsym *)spec;
272237 tl_len = be32_to_cpu(spec->length);
....@@ -278,13 +243,8 @@
278243 if (!sym)
279244 return nfp_dump_error_tlv_size(spec);
280245
281
- if (sym->type == NFP_RTSYM_TYPE_ABS)
282
- size = sizeof(sym->addr);
283
- else
284
- size = sym->size;
285
-
286246 return ALIGN8(offsetof(struct nfp_dump_rtsym, rtsym) + key_len + 1) +
287
- ALIGN8(size);
247
+ ALIGN8(nfp_rtsym_size(sym));
288248 }
289249
290250 static int
....@@ -644,7 +604,6 @@
644604 const struct nfp_rtsym *sym;
645605 u32 tl_len, key_len;
646606 int bytes_read;
647
- u32 cpp_id;
648607 void *dest;
649608 int err;
650609
....@@ -657,11 +616,7 @@
657616 if (!sym)
658617 return nfp_dump_error_tlv(&spec->tl, -ENOENT, dump);
659618
660
- if (sym->type == NFP_RTSYM_TYPE_ABS)
661
- sym_size = sizeof(sym->addr);
662
- else
663
- sym_size = sym->size;
664
-
619
+ sym_size = nfp_rtsym_size(sym);
665620 header_size =
666621 ALIGN8(offsetof(struct nfp_dump_rtsym, rtsym) + key_len + 1);
667622 total_size = header_size + ALIGN8(sym_size);
....@@ -676,23 +631,20 @@
676631 memcpy(dump_header->rtsym, spec->rtsym, key_len + 1);
677632 dump_header->cpp.dump_length = cpu_to_be32(sym_size);
678633
679
- if (sym->type == NFP_RTSYM_TYPE_ABS) {
680
- *(u64 *)dest = sym->addr;
681
- } else {
634
+ if (sym->type != NFP_RTSYM_TYPE_ABS) {
682635 cpp_params.target = sym->target;
683636 cpp_params.action = NFP_CPP_ACTION_RW;
684637 cpp_params.token = 0;
685638 cpp_params.island = sym->domain;
686
- cpp_id = nfp_get_numeric_cpp_id(&cpp_params);
687639 dump_header->cpp.cpp_id = cpp_params;
688640 dump_header->cpp.offset = cpu_to_be32(sym->addr);
689
- bytes_read = nfp_cpp_read(pf->cpp, cpp_id, sym->addr, dest,
690
- sym_size);
691
- if (bytes_read != sym_size) {
692
- if (bytes_read >= 0)
693
- bytes_read = -EIO;
694
- dump_header->error = cpu_to_be32(bytes_read);
695
- }
641
+ }
642
+
643
+ bytes_read = nfp_rtsym_read(pf->cpp, sym, 0, dest, sym_size);
644
+ if (bytes_read != sym_size) {
645
+ if (bytes_read >= 0)
646
+ bytes_read = -EIO;
647
+ dump_header->error = cpu_to_be32(bytes_read);
696648 }
697649
698650 return 0;