Skip to content

Commit bb5e6a8

Browse files
committed
Merge branch 'net-sched-indirect-tc-block-cb-registration'
Jakub Kicinski says: ==================== net: sched: indirect tc block cb registration John says: This patchset introduces an alternative to egdev offload by allowing a driver to register for block updates when an external device (e.g. tunnel netdev) is bound to a TC block. Drivers can track new netdevs or register to existing ones to receive information on such events. Based on this, they may register for block offload rules using already existing functions. The patchset also implements this new indirect block registration in the NFP driver to allow the offloading of tunnel rules. The use of egdev offload (which is currently only used for tunnel offload) is subsequently removed. RFC v2 -> PATCH - removed embedded tracking function from indir block register (now up to driver to clean up after itself) - refactored NFP code due to recent submissions - removed priv list clean function in NFP (list should be cleared by indirect block unregisters) RFC v1->v2: - free allocated owner struct in block_owner_clean function - add geneve type helper function - move test stub in NFP (v1 patch 2) to full tunnel offload implementation via indirect blocks (v2 patches 3-8) ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents d1ce011 + d4b69ba commit bb5e6a8

File tree

11 files changed

+531
-161
lines changed

11 files changed

+531
-161
lines changed

drivers/net/ethernet/netronome/nfp/flower/action.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/* Copyright (C) 2017-2018 Netronome Systems, Inc. */
33

44
#include <linux/bitfield.h>
5-
#include <net/geneve.h>
65
#include <net/pkt_cls.h>
76
#include <net/switchdev.h>
87
#include <net/tc_act/tc_csum.h>
@@ -11,7 +10,6 @@
1110
#include <net/tc_act/tc_pedit.h>
1211
#include <net/tc_act/tc_vlan.h>
1312
#include <net/tc_act/tc_tunnel_key.h>
14-
#include <net/vxlan.h>
1513

1614
#include "cmsg.h"
1715
#include "main.h"
@@ -92,18 +90,6 @@ nfp_fl_pre_lag(struct nfp_app *app, const struct tc_action *action,
9290
return act_size;
9391
}
9492

95-
static bool nfp_fl_netdev_is_tunnel_type(struct net_device *out_dev,
96-
enum nfp_flower_tun_type tun_type)
97-
{
98-
if (netif_is_vxlan(out_dev))
99-
return tun_type == NFP_FL_TUNNEL_VXLAN;
100-
101-
if (netif_is_geneve(out_dev))
102-
return tun_type == NFP_FL_TUNNEL_GENEVE;
103-
104-
return false;
105-
}
106-
10793
static int
10894
nfp_fl_output(struct nfp_app *app, struct nfp_fl_output *output,
10995
const struct tc_action *action, struct nfp_fl_payload *nfp_flow,
@@ -149,11 +135,12 @@ nfp_fl_output(struct nfp_app *app, struct nfp_fl_output *output,
149135
/* Set action output parameters. */
150136
output->flags = cpu_to_be16(tmp_flags);
151137

152-
/* Only offload if egress ports are on the same device as the
153-
* ingress port.
154-
*/
155-
if (!switchdev_port_same_parent_id(in_dev, out_dev))
156-
return -EOPNOTSUPP;
138+
if (nfp_netdev_is_nfp_repr(in_dev)) {
139+
/* Confirm ingress and egress are on same device. */
140+
if (!switchdev_port_same_parent_id(in_dev, out_dev))
141+
return -EOPNOTSUPP;
142+
}
143+
157144
if (!nfp_netdev_is_nfp_repr(out_dev))
158145
return -EOPNOTSUPP;
159146

@@ -840,9 +827,8 @@ nfp_flower_loop_action(struct nfp_app *app, const struct tc_action *a,
840827
*a_len += sizeof(struct nfp_fl_push_vlan);
841828
} else if (is_tcf_tunnel_set(a)) {
842829
struct ip_tunnel_info *ip_tun = tcf_tunnel_info(a);
843-
struct nfp_repr *repr = netdev_priv(netdev);
844830

845-
*tun_type = nfp_fl_get_tun_from_act_l4_port(repr->app, a);
831+
*tun_type = nfp_fl_get_tun_from_act_l4_port(app, a);
846832
if (*tun_type == NFP_FL_TUNNEL_NONE)
847833
return -EOPNOTSUPP;
848834

drivers/net/ethernet/netronome/nfp/flower/cmsg.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/skbuff.h>
99
#include <linux/types.h>
1010
#include <net/geneve.h>
11+
#include <net/vxlan.h>
1112

1213
#include "../nfp_app.h"
1314
#include "../nfpcore/nfp_cpp.h"
@@ -499,6 +500,32 @@ static inline int nfp_flower_cmsg_get_data_len(struct sk_buff *skb)
499500
return skb->len - NFP_FLOWER_CMSG_HLEN;
500501
}
501502

503+
static inline bool
504+
nfp_fl_netdev_is_tunnel_type(struct net_device *netdev,
505+
enum nfp_flower_tun_type tun_type)
506+
{
507+
if (netif_is_vxlan(netdev))
508+
return tun_type == NFP_FL_TUNNEL_VXLAN;
509+
if (netif_is_geneve(netdev))
510+
return tun_type == NFP_FL_TUNNEL_GENEVE;
511+
512+
return false;
513+
}
514+
515+
static inline bool nfp_fl_is_netdev_to_offload(struct net_device *netdev)
516+
{
517+
if (!netdev->rtnl_link_ops)
518+
return false;
519+
if (!strcmp(netdev->rtnl_link_ops->kind, "openvswitch"))
520+
return true;
521+
if (netif_is_vxlan(netdev))
522+
return true;
523+
if (netif_is_geneve(netdev))
524+
return true;
525+
526+
return false;
527+
}
528+
502529
struct sk_buff *
503530
nfp_flower_cmsg_mac_repr_start(struct nfp_app *app, unsigned int num_ports);
504531
void

drivers/net/ethernet/netronome/nfp/flower/main.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,23 +146,12 @@ nfp_flower_repr_netdev_stop(struct nfp_app *app, struct nfp_repr *repr)
146146
return nfp_flower_cmsg_portmod(repr, false, repr->netdev->mtu, false);
147147
}
148148

149-
static int
150-
nfp_flower_repr_netdev_init(struct nfp_app *app, struct net_device *netdev)
151-
{
152-
return tc_setup_cb_egdev_register(netdev,
153-
nfp_flower_setup_tc_egress_cb,
154-
netdev_priv(netdev));
155-
}
156-
157149
static void
158150
nfp_flower_repr_netdev_clean(struct nfp_app *app, struct net_device *netdev)
159151
{
160152
struct nfp_repr *repr = netdev_priv(netdev);
161153

162154
kfree(repr->app_priv);
163-
164-
tc_setup_cb_egdev_unregister(netdev, nfp_flower_setup_tc_egress_cb,
165-
netdev_priv(netdev));
166155
}
167156

168157
static void
@@ -568,6 +557,8 @@ static int nfp_flower_init(struct nfp_app *app)
568557
goto err_cleanup_metadata;
569558
}
570559

560+
INIT_LIST_HEAD(&app_priv->indr_block_cb_priv);
561+
571562
return 0;
572563

573564
err_cleanup_metadata:
@@ -684,6 +675,10 @@ nfp_flower_netdev_event(struct nfp_app *app, struct net_device *netdev,
684675
return ret;
685676
}
686677

678+
ret = nfp_flower_reg_indir_block_handler(app, netdev, event);
679+
if (ret & NOTIFY_STOP_MASK)
680+
return ret;
681+
687682
return nfp_tunnel_mac_event_handler(app, netdev, event, ptr);
688683
}
689684

@@ -705,7 +700,6 @@ const struct nfp_app_type app_flower = {
705700
.vnic_init = nfp_flower_vnic_init,
706701
.vnic_clean = nfp_flower_vnic_clean,
707702

708-
.repr_init = nfp_flower_repr_netdev_init,
709703
.repr_preclean = nfp_flower_repr_netdev_preclean,
710704
.repr_clean = nfp_flower_repr_netdev_clean,
711705

drivers/net/ethernet/netronome/nfp/flower/main.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct nfp_fl_pre_lag;
2020
struct net_device;
2121
struct nfp_app;
2222

23-
#define NFP_FL_STATS_CTX_DONT_CARE cpu_to_be32(0xffffffff)
2423
#define NFP_FL_STATS_ELEM_RS FIELD_SIZEOF(struct nfp_fl_stats_id, \
2524
init_unalloc)
2625
#define NFP_FLOWER_MASK_ENTRY_RS 256
@@ -130,6 +129,7 @@ struct nfp_fl_lag {
130129
* @reify_wait_queue: wait queue for repr reify response counting
131130
* @mtu_conf: Configuration of repr MTU value
132131
* @nfp_lag: Link aggregation data block
132+
* @indr_block_cb_priv: List of priv data passed to indirect block cbs
133133
*/
134134
struct nfp_flower_priv {
135135
struct nfp_app *app;
@@ -162,6 +162,7 @@ struct nfp_flower_priv {
162162
wait_queue_head_t reify_wait_queue;
163163
struct nfp_mtu_conf mtu_conf;
164164
struct nfp_fl_lag nfp_lag;
165+
struct list_head indr_block_cb_priv;
165166
};
166167

167168
/**
@@ -205,7 +206,6 @@ struct nfp_fl_payload {
205206
char *unmasked_data;
206207
char *mask_data;
207208
char *action_data;
208-
bool ingress_offload;
209209
};
210210

211211
extern const struct rhashtable_params nfp_flower_table_params;
@@ -222,7 +222,8 @@ void nfp_flower_metadata_cleanup(struct nfp_app *app);
222222

223223
int nfp_flower_setup_tc(struct nfp_app *app, struct net_device *netdev,
224224
enum tc_setup_type type, void *type_data);
225-
int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
225+
int nfp_flower_compile_flow_match(struct nfp_app *app,
226+
struct tc_cls_flower_offload *flow,
226227
struct nfp_fl_key_ls *key_ls,
227228
struct net_device *netdev,
228229
struct nfp_fl_payload *nfp_flow,
@@ -240,7 +241,7 @@ int nfp_modify_flow_metadata(struct nfp_app *app,
240241

241242
struct nfp_fl_payload *
242243
nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie,
243-
struct net_device *netdev, __be32 host_ctx);
244+
struct net_device *netdev);
244245
struct nfp_fl_payload *
245246
nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
246247

@@ -256,8 +257,6 @@ void nfp_tunnel_del_ipv4_off(struct nfp_app *app, __be32 ipv4);
256257
void nfp_tunnel_add_ipv4_off(struct nfp_app *app, __be32 ipv4);
257258
void nfp_tunnel_request_route(struct nfp_app *app, struct sk_buff *skb);
258259
void nfp_tunnel_keep_alive(struct nfp_app *app, struct sk_buff *skb);
259-
int nfp_flower_setup_tc_egress_cb(enum tc_setup_type type, void *type_data,
260-
void *cb_priv);
261260
void nfp_flower_lag_init(struct nfp_fl_lag *lag);
262261
void nfp_flower_lag_cleanup(struct nfp_fl_lag *lag);
263262
int nfp_flower_lag_reset(struct nfp_fl_lag *lag);
@@ -270,5 +269,8 @@ int nfp_flower_lag_populate_pre_action(struct nfp_app *app,
270269
struct nfp_fl_pre_lag *pre_act);
271270
int nfp_flower_lag_get_output_id(struct nfp_app *app,
272271
struct net_device *master);
272+
int nfp_flower_reg_indir_block_handler(struct nfp_app *app,
273+
struct net_device *netdev,
274+
unsigned long event);
273275

274276
#endif

drivers/net/ethernet/netronome/nfp/flower/match.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ nfp_flower_compile_port(struct nfp_flower_in_port *frame, u32 cmsg_port,
5252
return 0;
5353
}
5454

55-
if (tun_type)
55+
if (tun_type) {
5656
frame->in_port = cpu_to_be32(NFP_FL_PORT_TYPE_TUN | tun_type);
57-
else
57+
} else {
58+
if (!cmsg_port)
59+
return -EOPNOTSUPP;
5860
frame->in_port = cpu_to_be32(cmsg_port);
61+
}
5962

6063
return 0;
6164
}
@@ -289,17 +292,21 @@ nfp_flower_compile_ipv4_udp_tun(struct nfp_flower_ipv4_udp_tun *frame,
289292
}
290293
}
291294

292-
int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
295+
int nfp_flower_compile_flow_match(struct nfp_app *app,
296+
struct tc_cls_flower_offload *flow,
293297
struct nfp_fl_key_ls *key_ls,
294298
struct net_device *netdev,
295299
struct nfp_fl_payload *nfp_flow,
296300
enum nfp_flower_tun_type tun_type)
297301
{
298-
struct nfp_repr *netdev_repr;
302+
u32 cmsg_port = 0;
299303
int err;
300304
u8 *ext;
301305
u8 *msk;
302306

307+
if (nfp_netdev_is_nfp_repr(netdev))
308+
cmsg_port = nfp_repr_get_port_id(netdev);
309+
303310
memset(nfp_flow->unmasked_data, 0, key_ls->key_size);
304311
memset(nfp_flow->mask_data, 0, key_ls->key_size);
305312

@@ -327,15 +334,13 @@ int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
327334

328335
/* Populate Exact Port data. */
329336
err = nfp_flower_compile_port((struct nfp_flower_in_port *)ext,
330-
nfp_repr_get_port_id(netdev),
331-
false, tun_type);
337+
cmsg_port, false, tun_type);
332338
if (err)
333339
return err;
334340

335341
/* Populate Mask Port Data. */
336342
err = nfp_flower_compile_port((struct nfp_flower_in_port *)msk,
337-
nfp_repr_get_port_id(netdev),
338-
true, tun_type);
343+
cmsg_port, true, tun_type);
339344
if (err)
340345
return err;
341346

@@ -399,16 +404,13 @@ int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
399404
msk += sizeof(struct nfp_flower_ipv4_udp_tun);
400405

401406
/* Configure tunnel end point MAC. */
402-
if (nfp_netdev_is_nfp_repr(netdev)) {
403-
netdev_repr = netdev_priv(netdev);
404-
nfp_tunnel_write_macs(netdev_repr->app);
405-
406-
/* Store the tunnel destination in the rule data.
407-
* This must be present and be an exact match.
408-
*/
409-
nfp_flow->nfp_tun_ipv4_addr = tun_dst;
410-
nfp_tunnel_add_ipv4_off(netdev_repr->app, tun_dst);
411-
}
407+
nfp_tunnel_write_macs(app);
408+
409+
/* Store the tunnel destination in the rule data.
410+
* This must be present and be an exact match.
411+
*/
412+
nfp_flow->nfp_tun_ipv4_addr = tun_dst;
413+
nfp_tunnel_add_ipv4_off(app, tun_dst);
412414

413415
if (key_ls->key_layer_two & NFP_FLOWER_LAYER2_GENEVE_OP) {
414416
err = nfp_flower_compile_geneve_opt(ext, flow, false);

drivers/net/ethernet/netronome/nfp/flower/metadata.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ struct nfp_mask_id_table {
2121
struct nfp_fl_flow_table_cmp_arg {
2222
struct net_device *netdev;
2323
unsigned long cookie;
24-
__be32 host_ctx;
2524
};
2625

2726
static int nfp_release_stats_entry(struct nfp_app *app, u32 stats_context_id)
@@ -76,14 +75,13 @@ static int nfp_get_stats_entry(struct nfp_app *app, u32 *stats_context_id)
7675
/* Must be called with either RTNL or rcu_read_lock */
7776
struct nfp_fl_payload *
7877
nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie,
79-
struct net_device *netdev, __be32 host_ctx)
78+
struct net_device *netdev)
8079
{
8180
struct nfp_fl_flow_table_cmp_arg flower_cmp_arg;
8281
struct nfp_flower_priv *priv = app->priv;
8382

8483
flower_cmp_arg.netdev = netdev;
8584
flower_cmp_arg.cookie = tc_flower_cookie;
86-
flower_cmp_arg.host_ctx = host_ctx;
8785

8886
return rhashtable_lookup_fast(&priv->flow_table, &flower_cmp_arg,
8987
nfp_flower_table_params);
@@ -287,6 +285,7 @@ int nfp_compile_flow_metadata(struct nfp_app *app,
287285

288286
nfp_flow->meta.host_ctx_id = cpu_to_be32(stats_cxt);
289287
nfp_flow->meta.host_cookie = cpu_to_be64(flow->cookie);
288+
nfp_flow->ingress_dev = netdev;
290289

291290
new_mask_id = 0;
292291
if (!nfp_check_mask_add(app, nfp_flow->mask_data,
@@ -306,8 +305,7 @@ int nfp_compile_flow_metadata(struct nfp_app *app,
306305
priv->stats[stats_cxt].bytes = 0;
307306
priv->stats[stats_cxt].used = jiffies;
308307

309-
check_entry = nfp_flower_search_fl_table(app, flow->cookie, netdev,
310-
NFP_FL_STATS_CTX_DONT_CARE);
308+
check_entry = nfp_flower_search_fl_table(app, flow->cookie, netdev);
311309
if (check_entry) {
312310
if (nfp_release_stats_entry(app, stats_cxt))
313311
return -EINVAL;
@@ -352,9 +350,7 @@ static int nfp_fl_obj_cmpfn(struct rhashtable_compare_arg *arg,
352350
const struct nfp_fl_flow_table_cmp_arg *cmp_arg = arg->key;
353351
const struct nfp_fl_payload *flow_entry = obj;
354352

355-
if ((!cmp_arg->netdev || flow_entry->ingress_dev == cmp_arg->netdev) &&
356-
(cmp_arg->host_ctx == NFP_FL_STATS_CTX_DONT_CARE ||
357-
flow_entry->meta.host_ctx_id == cmp_arg->host_ctx))
353+
if (flow_entry->ingress_dev == cmp_arg->netdev)
358354
return flow_entry->tc_flower_cookie != cmp_arg->cookie;
359355

360356
return 1;

0 commit comments

Comments
 (0)