Skip to content

Commit 54a4a03

Browse files
jahurleydavem330
authored andcommitted
nfp: flower: support offloading multiple rules with same cookie
When multiple netdevs are attached to a tc offload block and register for callbacks, a rule added to the block will be propogated to all netdevs. Previously these were detected as duplicates (based on cookie) and rejected. Modify the rule nfp lookup function to optionally include an ingress netdev and a host context along with the cookie value when searching for a rule. When a new rule is passed to the driver, the netdev the rule is to be attached to is considered when searching for dublicates. When a stats update is received from HW, the host context is used alongside the cookie to map to the correct host rule. Signed-off-by: John Hurley <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent dd92a7d commit 54a4a03

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
struct net_device;
4848
struct nfp_app;
4949

50+
#define NFP_FL_STATS_CTX_DONT_CARE cpu_to_be32(0xffffffff)
5051
#define NFP_FL_STATS_ENTRY_RS BIT(20)
5152
#define NFP_FL_STATS_ELEM_RS 4
5253
#define NFP_FL_REPEATED_HASH_MAX BIT(17)
@@ -189,6 +190,7 @@ struct nfp_fl_payload {
189190
spinlock_t lock; /* lock stats */
190191
struct nfp_fl_stats stats;
191192
__be32 nfp_tun_ipv4_addr;
193+
struct net_device *ingress_dev;
192194
char *unmasked_data;
193195
char *mask_data;
194196
char *action_data;
@@ -216,12 +218,14 @@ int nfp_flower_compile_action(struct tc_cls_flower_offload *flow,
216218
struct nfp_fl_payload *nfp_flow);
217219
int nfp_compile_flow_metadata(struct nfp_app *app,
218220
struct tc_cls_flower_offload *flow,
219-
struct nfp_fl_payload *nfp_flow);
221+
struct nfp_fl_payload *nfp_flow,
222+
struct net_device *netdev);
220223
int nfp_modify_flow_metadata(struct nfp_app *app,
221224
struct nfp_fl_payload *nfp_flow);
222225

223226
struct nfp_fl_payload *
224-
nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
227+
nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie,
228+
struct net_device *netdev, __be32 host_ctx);
225229
struct nfp_fl_payload *
226230
nfp_flower_remove_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie);
227231

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,18 @@ static int nfp_get_stats_entry(struct nfp_app *app, u32 *stats_context_id)
9999

100100
/* Must be called with either RTNL or rcu_read_lock */
101101
struct nfp_fl_payload *
102-
nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie)
102+
nfp_flower_search_fl_table(struct nfp_app *app, unsigned long tc_flower_cookie,
103+
struct net_device *netdev, __be32 host_ctx)
103104
{
104105
struct nfp_flower_priv *priv = app->priv;
105106
struct nfp_fl_payload *flower_entry;
106107

107108
hash_for_each_possible_rcu(priv->flow_table, flower_entry, link,
108109
tc_flower_cookie)
109-
if (flower_entry->tc_flower_cookie == tc_flower_cookie)
110+
if (flower_entry->tc_flower_cookie == tc_flower_cookie &&
111+
(!netdev || flower_entry->ingress_dev == netdev) &&
112+
(host_ctx == NFP_FL_STATS_CTX_DONT_CARE ||
113+
flower_entry->meta.host_ctx_id == host_ctx))
110114
return flower_entry;
111115

112116
return NULL;
@@ -121,13 +125,11 @@ nfp_flower_update_stats(struct nfp_app *app, struct nfp_fl_stats_frame *stats)
121125
flower_cookie = be64_to_cpu(stats->stats_cookie);
122126

123127
rcu_read_lock();
124-
nfp_flow = nfp_flower_search_fl_table(app, flower_cookie);
128+
nfp_flow = nfp_flower_search_fl_table(app, flower_cookie, NULL,
129+
stats->stats_con_id);
125130
if (!nfp_flow)
126131
goto exit_rcu_unlock;
127132

128-
if (nfp_flow->meta.host_ctx_id != stats->stats_con_id)
129-
goto exit_rcu_unlock;
130-
131133
spin_lock(&nfp_flow->lock);
132134
nfp_flow->stats.pkts += be32_to_cpu(stats->pkt_count);
133135
nfp_flow->stats.bytes += be64_to_cpu(stats->byte_count);
@@ -317,7 +319,8 @@ nfp_check_mask_remove(struct nfp_app *app, char *mask_data, u32 mask_len,
317319

318320
int nfp_compile_flow_metadata(struct nfp_app *app,
319321
struct tc_cls_flower_offload *flow,
320-
struct nfp_fl_payload *nfp_flow)
322+
struct nfp_fl_payload *nfp_flow,
323+
struct net_device *netdev)
321324
{
322325
struct nfp_flower_priv *priv = app->priv;
323326
struct nfp_fl_payload *check_entry;
@@ -348,7 +351,8 @@ int nfp_compile_flow_metadata(struct nfp_app *app,
348351
nfp_flow->stats.bytes = 0;
349352
nfp_flow->stats.used = jiffies;
350353

351-
check_entry = nfp_flower_search_fl_table(app, flow->cookie);
354+
check_entry = nfp_flower_search_fl_table(app, flow->cookie, netdev,
355+
NFP_FL_STATS_CTX_DONT_CARE);
352356
if (check_entry) {
353357
if (nfp_release_stats_entry(app, stats_cxt))
354358
return -EINVAL;

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ nfp_flower_add_offload(struct nfp_app *app, struct net_device *netdev,
419419
goto err_free_key_ls;
420420
}
421421

422+
flow_pay->ingress_dev = egress ? NULL : netdev;
423+
422424
err = nfp_flower_compile_flow_match(flow, key_layer, netdev, flow_pay,
423425
tun_type);
424426
if (err)
@@ -428,7 +430,8 @@ nfp_flower_add_offload(struct nfp_app *app, struct net_device *netdev,
428430
if (err)
429431
goto err_destroy_flow;
430432

431-
err = nfp_compile_flow_metadata(app, flow, flow_pay);
433+
err = nfp_compile_flow_metadata(app, flow, flow_pay,
434+
flow_pay->ingress_dev);
432435
if (err)
433436
goto err_destroy_flow;
434437

@@ -462,6 +465,7 @@ nfp_flower_add_offload(struct nfp_app *app, struct net_device *netdev,
462465
* @app: Pointer to the APP handle
463466
* @netdev: netdev structure.
464467
* @flow: TC flower classifier offload structure
468+
* @egress: Netdev is the egress dev.
465469
*
466470
* Removes a flow from the repeated hash structure and clears the
467471
* action payload.
@@ -470,13 +474,16 @@ nfp_flower_add_offload(struct nfp_app *app, struct net_device *netdev,
470474
*/
471475
static int
472476
nfp_flower_del_offload(struct nfp_app *app, struct net_device *netdev,
473-
struct tc_cls_flower_offload *flow)
477+
struct tc_cls_flower_offload *flow, bool egress)
474478
{
475479
struct nfp_port *port = nfp_port_from_netdev(netdev);
476480
struct nfp_fl_payload *nfp_flow;
481+
struct net_device *ingr_dev;
477482
int err;
478483

479-
nfp_flow = nfp_flower_search_fl_table(app, flow->cookie);
484+
ingr_dev = egress ? NULL : netdev;
485+
nfp_flow = nfp_flower_search_fl_table(app, flow->cookie, ingr_dev,
486+
NFP_FL_STATS_CTX_DONT_CARE);
480487
if (!nfp_flow)
481488
return -ENOENT;
482489

@@ -505,19 +512,25 @@ nfp_flower_del_offload(struct nfp_app *app, struct net_device *netdev,
505512
/**
506513
* nfp_flower_get_stats() - Populates flow stats obtained from hardware.
507514
* @app: Pointer to the APP handle
515+
* @netdev: Netdev structure.
508516
* @flow: TC flower classifier offload structure
517+
* @egress: Netdev is the egress dev.
509518
*
510519
* Populates a flow statistics structure which which corresponds to a
511520
* specific flow.
512521
*
513522
* Return: negative value on error, 0 if stats populated successfully.
514523
*/
515524
static int
516-
nfp_flower_get_stats(struct nfp_app *app, struct tc_cls_flower_offload *flow)
525+
nfp_flower_get_stats(struct nfp_app *app, struct net_device *netdev,
526+
struct tc_cls_flower_offload *flow, bool egress)
517527
{
518528
struct nfp_fl_payload *nfp_flow;
529+
struct net_device *ingr_dev;
519530

520-
nfp_flow = nfp_flower_search_fl_table(app, flow->cookie);
531+
ingr_dev = egress ? NULL : netdev;
532+
nfp_flow = nfp_flower_search_fl_table(app, flow->cookie, ingr_dev,
533+
NFP_FL_STATS_CTX_DONT_CARE);
521534
if (!nfp_flow)
522535
return -EINVAL;
523536

@@ -543,9 +556,9 @@ nfp_flower_repr_offload(struct nfp_app *app, struct net_device *netdev,
543556
case TC_CLSFLOWER_REPLACE:
544557
return nfp_flower_add_offload(app, netdev, flower, egress);
545558
case TC_CLSFLOWER_DESTROY:
546-
return nfp_flower_del_offload(app, netdev, flower);
559+
return nfp_flower_del_offload(app, netdev, flower, egress);
547560
case TC_CLSFLOWER_STATS:
548-
return nfp_flower_get_stats(app, flower);
561+
return nfp_flower_get_stats(app, netdev, flower, egress);
549562
}
550563

551564
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)