forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/drivers/net/ethernet/netronome/nfp/nfp_net_ctrl.c
....@@ -1,35 +1,5 @@
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. */
333
344 #include <linux/bitfield.h>
355 #include <linux/device.h>
....@@ -45,6 +15,30 @@
4515 caps->me_freq_mhz = 1200;
4616 caps->mbox_off = NFP_NET_CFG_MBOX_BASE;
4717 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;
4842 }
4943
5044 int nfp_net_tlv_caps_parse(struct device *dev, u8 __iomem *ctrl_mem,
....@@ -71,8 +65,8 @@
7165 data += 4;
7266
7367 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);
7670 return -EINVAL;
7771 }
7872 if (data + length > end) {
....@@ -91,14 +85,14 @@
9185 if (!length)
9286 return 0;
9387
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);
9690 return -EINVAL;
9791 case NFP_NET_CFG_TLV_TYPE_ME_FREQ:
9892 if (length != 4) {
9993 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);
10296 return -EINVAL;
10397 }
10498
....@@ -113,6 +107,47 @@
113107 caps->mbox_len = length;
114108 }
115109 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;
116151 default:
117152 if (!FIELD_GET(NFP_NET_CFG_TLV_HEADER_REQUIRED, hdr))
118153 break;