.. | .. |
---|
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. */ |
---|
33 | 3 | |
---|
34 | 4 | #include <linux/ethtool.h> |
---|
35 | 5 | #include <linux/vmalloc.h> |
---|
.. | .. |
---|
66 | 36 | struct nfp_dump_tl { |
---|
67 | 37 | __be32 type; |
---|
68 | 38 | __be32 length; /* chunk length to follow, aligned to 8 bytes */ |
---|
69 | | - char data[0]; |
---|
| 39 | + char data[]; |
---|
70 | 40 | }; |
---|
71 | 41 | |
---|
72 | 42 | /* NFP CPP parameters */ |
---|
.. | .. |
---|
92 | 62 | |
---|
93 | 63 | struct nfp_dumpspec_rtsym { |
---|
94 | 64 | struct nfp_dump_tl tl; |
---|
95 | | - char rtsym[0]; |
---|
| 65 | + char rtsym[]; |
---|
96 | 66 | }; |
---|
97 | 67 | |
---|
98 | 68 | /* header for register dumpable */ |
---|
.. | .. |
---|
109 | 79 | struct nfp_dump_common_cpp cpp; |
---|
110 | 80 | __be32 error; /* error code encountered while reading */ |
---|
111 | 81 | u8 padded_name_length; /* pad so data starts at 8 byte boundary */ |
---|
112 | | - char rtsym[0]; |
---|
| 82 | + char rtsym[]; |
---|
113 | 83 | /* after padded_name_length, there is dump_length data */ |
---|
114 | 84 | }; |
---|
115 | 85 | |
---|
.. | .. |
---|
122 | 92 | struct nfp_dump_tl tl; |
---|
123 | 93 | __be32 error; |
---|
124 | 94 | char padding[4]; |
---|
125 | | - char spec[0]; |
---|
| 95 | + char spec[]; |
---|
126 | 96 | }; |
---|
127 | 97 | |
---|
128 | 98 | /* to track state through debug size calculation TLV traversal */ |
---|
.. | .. |
---|
188 | 158 | const struct nfp_rtsym *specsym; |
---|
189 | 159 | struct nfp_dumpspec *dumpspec; |
---|
190 | 160 | int bytes_read; |
---|
191 | | - u32 cpp_id; |
---|
| 161 | + u64 sym_size; |
---|
192 | 162 | |
---|
193 | 163 | specsym = nfp_rtsym_lookup(rtbl, NFP_DUMP_SPEC_RTSYM); |
---|
194 | 164 | if (!specsym) |
---|
195 | 165 | return NULL; |
---|
| 166 | + sym_size = nfp_rtsym_size(specsym); |
---|
196 | 167 | |
---|
197 | 168 | /* 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); |
---|
199 | 170 | if (!dumpspec) |
---|
200 | 171 | return NULL; |
---|
| 172 | + dumpspec->size = sym_size; |
---|
201 | 173 | |
---|
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) { |
---|
210 | 176 | vfree(dumpspec); |
---|
211 | 177 | nfp_warn(cpp, "Debug dump specification read failed.\n"); |
---|
212 | 178 | return NULL; |
---|
.. | .. |
---|
266 | 232 | struct nfp_dumpspec_rtsym *spec_rtsym; |
---|
267 | 233 | const struct nfp_rtsym *sym; |
---|
268 | 234 | u32 tl_len, key_len; |
---|
269 | | - u32 size; |
---|
270 | 235 | |
---|
271 | 236 | spec_rtsym = (struct nfp_dumpspec_rtsym *)spec; |
---|
272 | 237 | tl_len = be32_to_cpu(spec->length); |
---|
.. | .. |
---|
278 | 243 | if (!sym) |
---|
279 | 244 | return nfp_dump_error_tlv_size(spec); |
---|
280 | 245 | |
---|
281 | | - if (sym->type == NFP_RTSYM_TYPE_ABS) |
---|
282 | | - size = sizeof(sym->addr); |
---|
283 | | - else |
---|
284 | | - size = sym->size; |
---|
285 | | - |
---|
286 | 246 | return ALIGN8(offsetof(struct nfp_dump_rtsym, rtsym) + key_len + 1) + |
---|
287 | | - ALIGN8(size); |
---|
| 247 | + ALIGN8(nfp_rtsym_size(sym)); |
---|
288 | 248 | } |
---|
289 | 249 | |
---|
290 | 250 | static int |
---|
.. | .. |
---|
644 | 604 | const struct nfp_rtsym *sym; |
---|
645 | 605 | u32 tl_len, key_len; |
---|
646 | 606 | int bytes_read; |
---|
647 | | - u32 cpp_id; |
---|
648 | 607 | void *dest; |
---|
649 | 608 | int err; |
---|
650 | 609 | |
---|
.. | .. |
---|
657 | 616 | if (!sym) |
---|
658 | 617 | return nfp_dump_error_tlv(&spec->tl, -ENOENT, dump); |
---|
659 | 618 | |
---|
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); |
---|
665 | 620 | header_size = |
---|
666 | 621 | ALIGN8(offsetof(struct nfp_dump_rtsym, rtsym) + key_len + 1); |
---|
667 | 622 | total_size = header_size + ALIGN8(sym_size); |
---|
.. | .. |
---|
676 | 631 | memcpy(dump_header->rtsym, spec->rtsym, key_len + 1); |
---|
677 | 632 | dump_header->cpp.dump_length = cpu_to_be32(sym_size); |
---|
678 | 633 | |
---|
679 | | - if (sym->type == NFP_RTSYM_TYPE_ABS) { |
---|
680 | | - *(u64 *)dest = sym->addr; |
---|
681 | | - } else { |
---|
| 634 | + if (sym->type != NFP_RTSYM_TYPE_ABS) { |
---|
682 | 635 | cpp_params.target = sym->target; |
---|
683 | 636 | cpp_params.action = NFP_CPP_ACTION_RW; |
---|
684 | 637 | cpp_params.token = 0; |
---|
685 | 638 | cpp_params.island = sym->domain; |
---|
686 | | - cpp_id = nfp_get_numeric_cpp_id(&cpp_params); |
---|
687 | 639 | dump_header->cpp.cpp_id = cpp_params; |
---|
688 | 640 | 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); |
---|
696 | 648 | } |
---|
697 | 649 | |
---|
698 | 650 | return 0; |
---|