.. | .. |
---|
1 | | -/* |
---|
2 | | - * Copyright (C) 2018 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) 2018 Netronome Systems, Inc. */ |
---|
33 | 3 | |
---|
34 | 4 | #include <linux/bitfield.h> |
---|
35 | 5 | #include <linux/device.h> |
---|
.. | .. |
---|
45 | 15 | caps->me_freq_mhz = 1200; |
---|
46 | 16 | caps->mbox_off = NFP_NET_CFG_MBOX_BASE; |
---|
47 | 17 | caps->mbox_len = NFP_NET_CFG_MBOX_VAL_MAX_SZ; |
---|
| 18 | +} |
---|
| 19 | + |
---|
| 20 | +static bool |
---|
| 21 | +nfp_net_tls_parse_crypto_ops(struct device *dev, struct nfp_net_tlv_caps *caps, |
---|
| 22 | + u8 __iomem *ctrl_mem, u8 __iomem *data, |
---|
| 23 | + unsigned int length, unsigned int offset, |
---|
| 24 | + bool rx_stream_scan) |
---|
| 25 | +{ |
---|
| 26 | + /* Ignore the legacy TLV if new one was already parsed */ |
---|
| 27 | + if (caps->tls_resync_ss && !rx_stream_scan) |
---|
| 28 | + return true; |
---|
| 29 | + |
---|
| 30 | + if (length < 32) { |
---|
| 31 | + dev_err(dev, |
---|
| 32 | + "CRYPTO OPS TLV should be at least 32B, is %dB offset:%u\n", |
---|
| 33 | + length, offset); |
---|
| 34 | + return false; |
---|
| 35 | + } |
---|
| 36 | + |
---|
| 37 | + caps->crypto_ops = readl(data); |
---|
| 38 | + caps->crypto_enable_off = data - ctrl_mem + 16; |
---|
| 39 | + caps->tls_resync_ss = rx_stream_scan; |
---|
| 40 | + |
---|
| 41 | + return true; |
---|
48 | 42 | } |
---|
49 | 43 | |
---|
50 | 44 | int nfp_net_tlv_caps_parse(struct device *dev, u8 __iomem *ctrl_mem, |
---|
.. | .. |
---|
71 | 65 | data += 4; |
---|
72 | 66 | |
---|
73 | 67 | if (length % NFP_NET_CFG_TLV_LENGTH_INC) { |
---|
74 | | - dev_err(dev, "TLV size not multiple of %u len:%u\n", |
---|
75 | | - NFP_NET_CFG_TLV_LENGTH_INC, length); |
---|
| 68 | + dev_err(dev, "TLV size not multiple of %u offset:%u len:%u\n", |
---|
| 69 | + NFP_NET_CFG_TLV_LENGTH_INC, offset, length); |
---|
76 | 70 | return -EINVAL; |
---|
77 | 71 | } |
---|
78 | 72 | if (data + length > end) { |
---|
.. | .. |
---|
91 | 85 | if (!length) |
---|
92 | 86 | return 0; |
---|
93 | 87 | |
---|
94 | | - dev_err(dev, "END TLV should be empty, has len:%d\n", |
---|
95 | | - length); |
---|
| 88 | + dev_err(dev, "END TLV should be empty, has offset:%u len:%d\n", |
---|
| 89 | + offset, length); |
---|
96 | 90 | return -EINVAL; |
---|
97 | 91 | case NFP_NET_CFG_TLV_TYPE_ME_FREQ: |
---|
98 | 92 | if (length != 4) { |
---|
99 | 93 | dev_err(dev, |
---|
100 | | - "ME FREQ TLV should be 4B, is %dB\n", |
---|
101 | | - length); |
---|
| 94 | + "ME FREQ TLV should be 4B, is %dB offset:%u\n", |
---|
| 95 | + length, offset); |
---|
102 | 96 | return -EINVAL; |
---|
103 | 97 | } |
---|
104 | 98 | |
---|
.. | .. |
---|
113 | 107 | caps->mbox_len = length; |
---|
114 | 108 | } |
---|
115 | 109 | break; |
---|
| 110 | + case NFP_NET_CFG_TLV_TYPE_EXPERIMENTAL0: |
---|
| 111 | + case NFP_NET_CFG_TLV_TYPE_EXPERIMENTAL1: |
---|
| 112 | + dev_warn(dev, |
---|
| 113 | + "experimental TLV type:%u offset:%u len:%u\n", |
---|
| 114 | + FIELD_GET(NFP_NET_CFG_TLV_HEADER_TYPE, hdr), |
---|
| 115 | + offset, length); |
---|
| 116 | + break; |
---|
| 117 | + case NFP_NET_CFG_TLV_TYPE_REPR_CAP: |
---|
| 118 | + if (length < 4) { |
---|
| 119 | + dev_err(dev, "REPR CAP TLV short %dB < 4B offset:%u\n", |
---|
| 120 | + length, offset); |
---|
| 121 | + return -EINVAL; |
---|
| 122 | + } |
---|
| 123 | + |
---|
| 124 | + caps->repr_cap = readl(data); |
---|
| 125 | + break; |
---|
| 126 | + case NFP_NET_CFG_TLV_TYPE_MBOX_CMSG_TYPES: |
---|
| 127 | + if (length >= 4) |
---|
| 128 | + caps->mbox_cmsg_types = readl(data); |
---|
| 129 | + break; |
---|
| 130 | + case NFP_NET_CFG_TLV_TYPE_CRYPTO_OPS: |
---|
| 131 | + if (!nfp_net_tls_parse_crypto_ops(dev, caps, ctrl_mem, |
---|
| 132 | + data, length, offset, |
---|
| 133 | + false)) |
---|
| 134 | + return -EINVAL; |
---|
| 135 | + break; |
---|
| 136 | + case NFP_NET_CFG_TLV_TYPE_VNIC_STATS: |
---|
| 137 | + if ((data - ctrl_mem) % 8) { |
---|
| 138 | + dev_warn(dev, "VNIC STATS TLV misaligned, ignoring offset:%u len:%u\n", |
---|
| 139 | + offset, length); |
---|
| 140 | + break; |
---|
| 141 | + } |
---|
| 142 | + caps->vnic_stats_off = data - ctrl_mem; |
---|
| 143 | + caps->vnic_stats_cnt = length / 10; |
---|
| 144 | + break; |
---|
| 145 | + case NFP_NET_CFG_TLV_TYPE_CRYPTO_OPS_RX_SCAN: |
---|
| 146 | + if (!nfp_net_tls_parse_crypto_ops(dev, caps, ctrl_mem, |
---|
| 147 | + data, length, offset, |
---|
| 148 | + true)) |
---|
| 149 | + return -EINVAL; |
---|
| 150 | + break; |
---|
116 | 151 | default: |
---|
117 | 152 | if (!FIELD_GET(NFP_NET_CFG_TLV_HEADER_REQUIRED, hdr)) |
---|
118 | 153 | break; |
---|