Skip to content

Commit 0d4fd02

Browse files
ummakynesdavem330
authored andcommitted
net: flow_offload: add flow_block_cb_is_busy() and use it
This patch adds a function to check if flow block callback is already in use. Call this new function from flow_block_cb_setup_simple() and from drivers. Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 722d36e commit 0d4fd02

File tree

7 files changed

+39
-0
lines changed

7 files changed

+39
-0
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,10 @@ mlx5e_rep_indr_setup_tc_block(struct net_device *netdev,
722722
if (indr_priv)
723723
return -EEXIST;
724724

725+
if (flow_block_cb_is_busy(mlx5e_rep_indr_setup_block_cb,
726+
indr_priv, &mlx5e_block_cb_list))
727+
return -EBUSY;
728+
725729
indr_priv = kmalloc(sizeof(*indr_priv), GFP_KERNEL);
726730
if (!indr_priv)
727731
return -ENOMEM;

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,10 @@ static int mlxsw_sp_setup_tc_block(struct mlxsw_sp_port *mlxsw_sp_port,
16981698

16991699
switch (f->command) {
17001700
case FLOW_BLOCK_BIND:
1701+
if (flow_block_cb_is_busy(cb, mlxsw_sp_port,
1702+
&mlxsw_sp_block_cb_list))
1703+
return -EBUSY;
1704+
17011705
block_cb = flow_block_cb_alloc(f->net, cb, mlxsw_sp_port,
17021706
mlxsw_sp_port, NULL);
17031707
if (IS_ERR(block_cb))

drivers/net/ethernet/mscc/ocelot_tc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ static int ocelot_setup_tc_block(struct ocelot_port *port,
153153

154154
switch (f->command) {
155155
case FLOW_BLOCK_BIND:
156+
if (flow_block_cb_is_busy(cb, port, &ocelot_block_cb_list))
157+
return -EBUSY;
158+
156159
block_cb = flow_block_cb_alloc(f->net, cb, port, port, NULL);
157160
if (IS_ERR(block_cb))
158161
return PTR_ERR(block_cb);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,10 @@ static int nfp_flower_setup_tc_block(struct net_device *netdev,
13201320

13211321
switch (f->command) {
13221322
case FLOW_BLOCK_BIND:
1323+
if (flow_block_cb_is_busy(nfp_flower_setup_tc_block_cb, repr,
1324+
&nfp_block_cb_list))
1325+
return -EBUSY;
1326+
13231327
block_cb = flow_block_cb_alloc(f->net,
13241328
nfp_flower_setup_tc_block_cb,
13251329
repr, repr, NULL);

include/net/flow_offload.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ static inline void flow_block_cb_remove(struct flow_block_cb *block_cb,
296296
list_move(&block_cb->list, &offload->cb_list);
297297
}
298298

299+
bool flow_block_cb_is_busy(tc_setup_cb_t *cb, void *cb_ident,
300+
struct list_head *driver_block_list);
301+
299302
int flow_block_cb_setup_simple(struct flow_block_offload *f,
300303
struct list_head *driver_list, tc_setup_cb_t *cb,
301304
void *cb_ident, void *cb_priv, bool ingress_only);

net/core/flow_offload.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,21 @@ unsigned int flow_block_cb_decref(struct flow_block_cb *block_cb)
228228
}
229229
EXPORT_SYMBOL(flow_block_cb_decref);
230230

231+
bool flow_block_cb_is_busy(tc_setup_cb_t *cb, void *cb_ident,
232+
struct list_head *driver_block_list)
233+
{
234+
struct flow_block_cb *block_cb;
235+
236+
list_for_each_entry(block_cb, driver_block_list, driver_list) {
237+
if (block_cb->cb == cb &&
238+
block_cb->cb_ident == cb_ident)
239+
return true;
240+
}
241+
242+
return false;
243+
}
244+
EXPORT_SYMBOL(flow_block_cb_is_busy);
245+
231246
int flow_block_cb_setup_simple(struct flow_block_offload *f,
232247
struct list_head *driver_block_list,
233248
tc_setup_cb_t *cb, void *cb_ident, void *cb_priv,
@@ -243,6 +258,9 @@ int flow_block_cb_setup_simple(struct flow_block_offload *f,
243258

244259
switch (f->command) {
245260
case FLOW_BLOCK_BIND:
261+
if (flow_block_cb_is_busy(cb, cb_ident, driver_block_list))
262+
return -EBUSY;
263+
246264
block_cb = flow_block_cb_alloc(f->net, cb, cb_ident,
247265
cb_priv, NULL);
248266
if (IS_ERR(block_cb))

net/dsa/slave.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,9 @@ static int dsa_slave_setup_tc_block(struct net_device *dev,
961961

962962
switch (f->command) {
963963
case FLOW_BLOCK_BIND:
964+
if (flow_block_cb_is_busy(cb, dev, &dsa_slave_block_cb_list))
965+
return -EBUSY;
966+
964967
block_cb = flow_block_cb_alloc(f->net, cb, dev, dev, NULL);
965968
if (IS_ERR(block_cb))
966969
return PTR_ERR(block_cb);

0 commit comments

Comments
 (0)