hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/net/ethernet/netronome/nfp/flower/cmsg.c
....@@ -1,35 +1,5 @@
1
-/*
2
- * Copyright (C) 2015-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) 2015-2018 Netronome Systems, Inc. */
333
344 #include <linux/bitfield.h>
355 #include <linux/netdevice.h>
....@@ -75,11 +45,9 @@
7545 {
7646 struct nfp_flower_cmsg_mac_repr *msg;
7747 struct sk_buff *skb;
78
- unsigned int size;
7948
80
- size = sizeof(*msg) + num_ports * sizeof(msg->ports[0]);
81
- skb = nfp_flower_cmsg_alloc(app, size, NFP_FLOWER_CMSG_TYPE_MAC_REPR,
82
- GFP_KERNEL);
49
+ skb = nfp_flower_cmsg_alloc(app, struct_size(msg, ports, num_ports),
50
+ NFP_FLOWER_CMSG_TYPE_MAC_REPR, GFP_KERNEL);
8351 if (!skb)
8452 return NULL;
8553
....@@ -191,7 +159,7 @@
191159
192160 rtnl_lock();
193161 rcu_read_lock();
194
- netdev = nfp_app_repr_get(app, be32_to_cpu(msg->portnum));
162
+ netdev = nfp_app_dev_get(app, be32_to_cpu(msg->portnum), NULL);
195163 rcu_read_unlock();
196164 if (!netdev) {
197165 nfp_flower_cmsg_warn(app, "ctrl msg for unknown port 0x%08x\n",
....@@ -224,7 +192,7 @@
224192 msg = nfp_flower_cmsg_get_data(skb);
225193
226194 rcu_read_lock();
227
- exists = !!nfp_app_repr_get(app, be32_to_cpu(msg->portnum));
195
+ exists = !!nfp_app_dev_get(app, be32_to_cpu(msg->portnum), NULL);
228196 rcu_read_unlock();
229197 if (!exists) {
230198 nfp_flower_cmsg_warn(app, "ctrl msg for unknown port 0x%08x\n",
....@@ -233,7 +201,51 @@
233201 }
234202
235203 atomic_inc(&priv->reify_replies);
236
- wake_up_interruptible(&priv->reify_wait_queue);
204
+ wake_up(&priv->reify_wait_queue);
205
+}
206
+
207
+static void
208
+nfp_flower_cmsg_merge_hint_rx(struct nfp_app *app, struct sk_buff *skb)
209
+{
210
+ unsigned int msg_len = nfp_flower_cmsg_get_data_len(skb);
211
+ struct nfp_flower_cmsg_merge_hint *msg;
212
+ struct nfp_fl_payload *sub_flows[2];
213
+ int err, i, flow_cnt;
214
+
215
+ msg = nfp_flower_cmsg_get_data(skb);
216
+ /* msg->count starts at 0 and always assumes at least 1 entry. */
217
+ flow_cnt = msg->count + 1;
218
+
219
+ if (msg_len < struct_size(msg, flow, flow_cnt)) {
220
+ nfp_flower_cmsg_warn(app, "Merge hint ctrl msg too short - %d bytes but expect %zd\n",
221
+ msg_len, struct_size(msg, flow, flow_cnt));
222
+ return;
223
+ }
224
+
225
+ if (flow_cnt != 2) {
226
+ nfp_flower_cmsg_warn(app, "Merge hint contains %d flows - two are expected\n",
227
+ flow_cnt);
228
+ return;
229
+ }
230
+
231
+ rtnl_lock();
232
+ for (i = 0; i < flow_cnt; i++) {
233
+ u32 ctx = be32_to_cpu(msg->flow[i].host_ctx);
234
+
235
+ sub_flows[i] = nfp_flower_get_fl_payload_from_ctx(app, ctx);
236
+ if (!sub_flows[i]) {
237
+ nfp_flower_cmsg_warn(app, "Invalid flow in merge hint\n");
238
+ goto err_rtnl_unlock;
239
+ }
240
+ }
241
+
242
+ err = nfp_flower_merge_offloaded_flows(app, sub_flows[0], sub_flows[1]);
243
+ /* Only warn on memory fail. Hint veto will not break functionality. */
244
+ if (err == -ENOMEM)
245
+ nfp_flower_cmsg_warn(app, "Flow merge memory fail.\n");
246
+
247
+err_rtnl_unlock:
248
+ rtnl_unlock();
237249 }
238250
239251 static void
....@@ -248,25 +260,38 @@
248260
249261 type = cmsg_hdr->type;
250262 switch (type) {
251
- case NFP_FLOWER_CMSG_TYPE_PORT_REIFY:
252
- nfp_flower_cmsg_portreify_rx(app, skb);
253
- break;
254263 case NFP_FLOWER_CMSG_TYPE_PORT_MOD:
255264 nfp_flower_cmsg_portmod_rx(app, skb);
256265 break;
266
+ case NFP_FLOWER_CMSG_TYPE_MERGE_HINT:
267
+ if (app_priv->flower_en_feats & NFP_FL_ENABLE_FLOW_MERGE) {
268
+ nfp_flower_cmsg_merge_hint_rx(app, skb);
269
+ break;
270
+ }
271
+ goto err_default;
257272 case NFP_FLOWER_CMSG_TYPE_NO_NEIGH:
258
- nfp_tunnel_request_route(app, skb);
273
+ nfp_tunnel_request_route_v4(app, skb);
274
+ break;
275
+ case NFP_FLOWER_CMSG_TYPE_NO_NEIGH_V6:
276
+ nfp_tunnel_request_route_v6(app, skb);
259277 break;
260278 case NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS:
261279 nfp_tunnel_keep_alive(app, skb);
262280 break;
281
+ case NFP_FLOWER_CMSG_TYPE_ACTIVE_TUNS_V6:
282
+ nfp_tunnel_keep_alive_v6(app, skb);
283
+ break;
284
+ case NFP_FLOWER_CMSG_TYPE_QOS_STATS:
285
+ nfp_flower_stats_rlim_reply(app, skb);
286
+ break;
263287 case NFP_FLOWER_CMSG_TYPE_LAG_CONFIG:
264
- if (app_priv->flower_ext_feats & NFP_FL_FEATS_LAG) {
288
+ if (app_priv->flower_en_feats & NFP_FL_ENABLE_LAG) {
265289 skb_stored = nfp_flower_lag_unprocessed_msg(app, skb);
266290 break;
267291 }
268
- /* fall through */
292
+ fallthrough;
269293 default:
294
+err_default:
270295 nfp_flower_cmsg_warn(app, "Cannot handle invalid repr control type %u\n",
271296 type);
272297 goto out;
....@@ -306,8 +331,7 @@
306331 struct nfp_flower_priv *priv = app->priv;
307332 struct sk_buff_head *skb_head;
308333
309
- if (type == NFP_FLOWER_CMSG_TYPE_PORT_REIFY ||
310
- type == NFP_FLOWER_CMSG_TYPE_PORT_MOD)
334
+ if (type == NFP_FLOWER_CMSG_TYPE_PORT_MOD)
311335 skb_head = &priv->cmsg_skbs_high;
312336 else
313337 skb_head = &priv->cmsg_skbs_low;
....@@ -343,9 +367,14 @@
343367 nfp_flower_process_mtu_ack(app, skb)) {
344368 /* Handle MTU acks outside wq to prevent RTNL conflict. */
345369 dev_consume_skb_any(skb);
346
- } else if (cmsg_hdr->type == NFP_FLOWER_CMSG_TYPE_TUN_NEIGH) {
370
+ } else if (cmsg_hdr->type == NFP_FLOWER_CMSG_TYPE_TUN_NEIGH ||
371
+ cmsg_hdr->type == NFP_FLOWER_CMSG_TYPE_TUN_NEIGH_V6) {
347372 /* Acks from the NFP that the route is added - ignore. */
348373 dev_consume_skb_any(skb);
374
+ } else if (cmsg_hdr->type == NFP_FLOWER_CMSG_TYPE_PORT_REIFY) {
375
+ /* Handle REIFY acks outside wq to prevent RTNL conflict. */
376
+ nfp_flower_cmsg_portreify_rx(app, skb);
377
+ dev_consume_skb_any(skb);
349378 } else {
350379 nfp_flower_queue_ctl_msg(app, skb, cmsg_hdr->type);
351380 }