Skip to content

Commit 955bcb6

Browse files
ummakynesdavem330
authored andcommitted
drivers: net: use flow block API
This patch updates flow_block_cb_setup_simple() to use the flow block API. Several drivers are also adjusted to use it. This patch introduces the per-driver list of flow blocks to account for blocks that are already in use. Remove tc_block_offload alias. Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 59094b1 commit 955bcb6

File tree

25 files changed

+286
-130
lines changed

25 files changed

+286
-130
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9907,14 +9907,17 @@ static int bnxt_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
99079907
}
99089908
}
99099909

9910+
static LIST_HEAD(bnxt_block_cb_list);
9911+
99109912
static int bnxt_setup_tc(struct net_device *dev, enum tc_setup_type type,
99119913
void *type_data)
99129914
{
99139915
struct bnxt *bp = netdev_priv(dev);
99149916

99159917
switch (type) {
99169918
case TC_SETUP_BLOCK:
9917-
return flow_block_cb_setup_simple(type_data, NULL,
9919+
return flow_block_cb_setup_simple(type_data,
9920+
&bnxt_block_cb_list,
99189921
bnxt_setup_tc_block_cb,
99199922
bp, bp, true);
99209923
case TC_SETUP_QDISC_MQPRIO: {

drivers/net/ethernet/broadcom/bnxt/bnxt_vfr.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,17 @@ static int bnxt_vf_rep_setup_tc_block_cb(enum tc_setup_type type,
161161
}
162162
}
163163

164+
static LIST_HEAD(bnxt_vf_block_cb_list);
165+
164166
static int bnxt_vf_rep_setup_tc(struct net_device *dev, enum tc_setup_type type,
165167
void *type_data)
166168
{
167169
struct bnxt_vf_rep *vf_rep = netdev_priv(dev);
168170

169171
switch (type) {
170172
case TC_SETUP_BLOCK:
171-
return flow_block_cb_setup_simple(type_data, NULL,
173+
return flow_block_cb_setup_simple(type_data,
174+
&bnxt_vf_block_cb_list,
172175
bnxt_vf_rep_setup_tc_block_cb,
173176
vf_rep, vf_rep, true);
174177
default:

drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3190,14 +3190,17 @@ static int cxgb_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
31903190
}
31913191
}
31923192

3193+
static LIST_HEAD(cxgb_block_cb_list);
3194+
31933195
static int cxgb_setup_tc(struct net_device *dev, enum tc_setup_type type,
31943196
void *type_data)
31953197
{
31963198
struct port_info *pi = netdev2pinfo(dev);
31973199

31983200
switch (type) {
31993201
case TC_SETUP_BLOCK:
3200-
return flow_block_cb_setup_simple(type_data, NULL,
3202+
return flow_block_cb_setup_simple(type_data,
3203+
&cxgb_block_cb_list,
32013204
cxgb_setup_tc_block_cb,
32023205
pi, dev, true);
32033206
default:

drivers/net/ethernet/intel/i40e/i40e_main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8177,6 +8177,8 @@ static int i40e_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
81778177
}
81788178
}
81798179

8180+
static LIST_HEAD(i40e_block_cb_list);
8181+
81808182
static int __i40e_setup_tc(struct net_device *netdev, enum tc_setup_type type,
81818183
void *type_data)
81828184
{
@@ -8186,7 +8188,8 @@ static int __i40e_setup_tc(struct net_device *netdev, enum tc_setup_type type,
81868188
case TC_SETUP_QDISC_MQPRIO:
81878189
return i40e_setup_tc(netdev, type_data);
81888190
case TC_SETUP_BLOCK:
8189-
return flow_block_cb_setup_simple(type_data, NULL,
8191+
return flow_block_cb_setup_simple(type_data,
8192+
&i40e_block_cb_list,
81908193
i40e_setup_tc_block_cb,
81918194
np, np, true);
81928195
default:

drivers/net/ethernet/intel/iavf/iavf_main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3113,6 +3113,8 @@ static int iavf_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
31133113
}
31143114
}
31153115

3116+
static LIST_HEAD(iavf_block_cb_list);
3117+
31163118
/**
31173119
* iavf_setup_tc - configure multiple traffic classes
31183120
* @netdev: network interface device structure
@@ -3133,7 +3135,8 @@ static int iavf_setup_tc(struct net_device *netdev, enum tc_setup_type type,
31333135
case TC_SETUP_QDISC_MQPRIO:
31343136
return __iavf_setup_tc(netdev, type_data);
31353137
case TC_SETUP_BLOCK:
3136-
return flow_block_cb_setup_simple(type_data, NULL,
3138+
return flow_block_cb_setup_simple(type_data,
3139+
&iavf_block_cb_list,
31373140
iavf_setup_tc_block_cb,
31383141
adapter, adapter, true);
31393142
default:

drivers/net/ethernet/intel/igb/igb_main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2806,6 +2806,8 @@ static int igb_offload_txtime(struct igb_adapter *adapter,
28062806
return 0;
28072807
}
28082808

2809+
static LIST_HEAD(igb_block_cb_list);
2810+
28092811
static int igb_setup_tc(struct net_device *dev, enum tc_setup_type type,
28102812
void *type_data)
28112813
{
@@ -2815,7 +2817,8 @@ static int igb_setup_tc(struct net_device *dev, enum tc_setup_type type,
28152817
case TC_SETUP_QDISC_CBS:
28162818
return igb_offload_cbs(adapter, type_data);
28172819
case TC_SETUP_BLOCK:
2818-
return flow_block_cb_setup_simple(type_data, NULL,
2820+
return flow_block_cb_setup_simple(type_data,
2821+
&igb_block_cb_list,
28192822
igb_setup_tc_block_cb,
28202823
adapter, adapter, true);
28212824

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9614,14 +9614,17 @@ static int ixgbe_setup_tc_mqprio(struct net_device *dev,
96149614
return ixgbe_setup_tc(dev, mqprio->num_tc);
96159615
}
96169616

9617+
static LIST_HEAD(ixgbe_block_cb_list);
9618+
96179619
static int __ixgbe_setup_tc(struct net_device *dev, enum tc_setup_type type,
96189620
void *type_data)
96199621
{
96209622
struct ixgbe_adapter *adapter = netdev_priv(dev);
96219623

96229624
switch (type) {
96239625
case TC_SETUP_BLOCK:
9624-
return flow_block_cb_setup_simple(type_data, NULL,
9626+
return flow_block_cb_setup_simple(type_data,
9627+
&ixgbe_block_cb_list,
96259628
ixgbe_setup_tc_block_cb,
96269629
adapter, adapter, true);
96279630
case TC_SETUP_QDISC_MQPRIO:

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3459,6 +3459,8 @@ static int mlx5e_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
34593459
}
34603460
#endif
34613461

3462+
static LIST_HEAD(mlx5e_block_cb_list);
3463+
34623464
static int mlx5e_setup_tc(struct net_device *dev, enum tc_setup_type type,
34633465
void *type_data)
34643466
{
@@ -3467,7 +3469,8 @@ static int mlx5e_setup_tc(struct net_device *dev, enum tc_setup_type type,
34673469
switch (type) {
34683470
#ifdef CONFIG_MLX5_ESWITCH
34693471
case TC_SETUP_BLOCK:
3470-
return flow_block_cb_setup_simple(type_data, NULL,
3472+
return flow_block_cb_setup_simple(type_data,
3473+
&mlx5e_block_cb_list,
34713474
mlx5e_setup_tc_block_cb,
34723475
priv, priv, true);
34733476
#endif

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

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -693,17 +693,29 @@ static int mlx5e_rep_indr_setup_block_cb(enum tc_setup_type type,
693693
}
694694
}
695695

696+
static void mlx5e_rep_indr_tc_block_unbind(void *cb_priv)
697+
{
698+
struct mlx5e_rep_indr_block_priv *indr_priv = cb_priv;
699+
700+
list_del(&indr_priv->list);
701+
kfree(indr_priv);
702+
}
703+
704+
static LIST_HEAD(mlx5e_block_cb_list);
705+
696706
static int
697707
mlx5e_rep_indr_setup_tc_block(struct net_device *netdev,
698708
struct mlx5e_rep_priv *rpriv,
699-
struct tc_block_offload *f)
709+
struct flow_block_offload *f)
700710
{
701711
struct mlx5e_rep_indr_block_priv *indr_priv;
702-
int err = 0;
712+
struct flow_block_cb *block_cb;
703713

704714
if (f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
705715
return -EOPNOTSUPP;
706716

717+
f->driver_block_list = &mlx5e_block_cb_list;
718+
707719
switch (f->command) {
708720
case FLOW_BLOCK_BIND:
709721
indr_priv = mlx5e_rep_indr_block_priv_lookup(rpriv, netdev);
@@ -719,26 +731,32 @@ mlx5e_rep_indr_setup_tc_block(struct net_device *netdev,
719731
list_add(&indr_priv->list,
720732
&rpriv->uplink_priv.tc_indr_block_priv_list);
721733

722-
err = tcf_block_cb_register(f->block,
723-
mlx5e_rep_indr_setup_block_cb,
724-
indr_priv, indr_priv, f->extack);
725-
if (err) {
734+
block_cb = flow_block_cb_alloc(f->net,
735+
mlx5e_rep_indr_setup_block_cb,
736+
indr_priv, indr_priv,
737+
mlx5e_rep_indr_tc_block_unbind);
738+
if (IS_ERR(block_cb)) {
726739
list_del(&indr_priv->list);
727740
kfree(indr_priv);
741+
return PTR_ERR(block_cb);
728742
}
743+
flow_block_cb_add(block_cb, f);
744+
list_add_tail(&block_cb->driver_list, &mlx5e_block_cb_list);
729745

730-
return err;
746+
return 0;
731747
case FLOW_BLOCK_UNBIND:
732748
indr_priv = mlx5e_rep_indr_block_priv_lookup(rpriv, netdev);
733749
if (!indr_priv)
734750
return -ENOENT;
735751

736-
tcf_block_cb_unregister(f->block,
737-
mlx5e_rep_indr_setup_block_cb,
738-
indr_priv);
739-
list_del(&indr_priv->list);
740-
kfree(indr_priv);
752+
block_cb = flow_block_cb_lookup(f,
753+
mlx5e_rep_indr_setup_block_cb,
754+
indr_priv);
755+
if (!block_cb)
756+
return -ENOENT;
741757

758+
flow_block_cb_remove(block_cb, f);
759+
list_del(&block_cb->driver_list);
742760
return 0;
743761
default:
744762
return -EOPNOTSUPP;

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

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,33 +1585,45 @@ static int mlxsw_sp_setup_tc_block_cb_flower(enum tc_setup_type type,
15851585
}
15861586
}
15871587

1588+
static void mlxsw_sp_tc_block_flower_release(void *cb_priv)
1589+
{
1590+
struct mlxsw_sp_acl_block *acl_block = cb_priv;
1591+
1592+
mlxsw_sp_acl_block_destroy(acl_block);
1593+
}
1594+
1595+
static LIST_HEAD(mlxsw_sp_block_cb_list);
1596+
15881597
static int
15891598
mlxsw_sp_setup_tc_block_flower_bind(struct mlxsw_sp_port *mlxsw_sp_port,
1590-
struct tcf_block *block, bool ingress,
1591-
struct netlink_ext_ack *extack)
1599+
struct flow_block_offload *f, bool ingress)
15921600
{
15931601
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
15941602
struct mlxsw_sp_acl_block *acl_block;
1595-
struct tcf_block_cb *block_cb;
1603+
struct flow_block_cb *block_cb;
1604+
bool register_block = false;
15961605
int err;
15971606

1598-
block_cb = tcf_block_cb_lookup(block, mlxsw_sp_setup_tc_block_cb_flower,
1599-
mlxsw_sp);
1607+
block_cb = flow_block_cb_lookup(f, mlxsw_sp_setup_tc_block_cb_flower,
1608+
mlxsw_sp);
16001609
if (!block_cb) {
1601-
acl_block = mlxsw_sp_acl_block_create(mlxsw_sp, block->net);
1610+
acl_block = mlxsw_sp_acl_block_create(mlxsw_sp, f->net);
16021611
if (!acl_block)
16031612
return -ENOMEM;
1604-
block_cb = __tcf_block_cb_register(block,
1605-
mlxsw_sp_setup_tc_block_cb_flower,
1606-
mlxsw_sp, acl_block, extack);
1613+
block_cb = flow_block_cb_alloc(f->net,
1614+
mlxsw_sp_setup_tc_block_cb_flower,
1615+
mlxsw_sp, acl_block,
1616+
mlxsw_sp_tc_block_flower_release);
16071617
if (IS_ERR(block_cb)) {
1618+
mlxsw_sp_acl_block_destroy(acl_block);
16081619
err = PTR_ERR(block_cb);
16091620
goto err_cb_register;
16101621
}
1622+
register_block = true;
16111623
} else {
1612-
acl_block = tcf_block_cb_priv(block_cb);
1624+
acl_block = flow_block_cb_priv(block_cb);
16131625
}
1614-
tcf_block_cb_incref(block_cb);
1626+
flow_block_cb_incref(block_cb);
16151627
err = mlxsw_sp_acl_block_bind(mlxsw_sp, acl_block,
16161628
mlxsw_sp_port, ingress);
16171629
if (err)
@@ -1622,28 +1634,31 @@ mlxsw_sp_setup_tc_block_flower_bind(struct mlxsw_sp_port *mlxsw_sp_port,
16221634
else
16231635
mlxsw_sp_port->eg_acl_block = acl_block;
16241636

1637+
if (register_block) {
1638+
flow_block_cb_add(block_cb, f);
1639+
list_add_tail(&block_cb->driver_list, &mlxsw_sp_block_cb_list);
1640+
}
1641+
16251642
return 0;
16261643

16271644
err_block_bind:
1628-
if (!tcf_block_cb_decref(block_cb)) {
1629-
__tcf_block_cb_unregister(block, block_cb);
1645+
if (!flow_block_cb_decref(block_cb))
1646+
flow_block_cb_free(block_cb);
16301647
err_cb_register:
1631-
mlxsw_sp_acl_block_destroy(acl_block);
1632-
}
16331648
return err;
16341649
}
16351650

16361651
static void
16371652
mlxsw_sp_setup_tc_block_flower_unbind(struct mlxsw_sp_port *mlxsw_sp_port,
1638-
struct tcf_block *block, bool ingress)
1653+
struct flow_block_offload *f, bool ingress)
16391654
{
16401655
struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
16411656
struct mlxsw_sp_acl_block *acl_block;
1642-
struct tcf_block_cb *block_cb;
1657+
struct flow_block_cb *block_cb;
16431658
int err;
16441659

1645-
block_cb = tcf_block_cb_lookup(block, mlxsw_sp_setup_tc_block_cb_flower,
1646-
mlxsw_sp);
1660+
block_cb = flow_block_cb_lookup(f, mlxsw_sp_setup_tc_block_cb_flower,
1661+
mlxsw_sp);
16471662
if (!block_cb)
16481663
return;
16491664

@@ -1652,18 +1667,19 @@ mlxsw_sp_setup_tc_block_flower_unbind(struct mlxsw_sp_port *mlxsw_sp_port,
16521667
else
16531668
mlxsw_sp_port->eg_acl_block = NULL;
16541669

1655-
acl_block = tcf_block_cb_priv(block_cb);
1670+
acl_block = flow_block_cb_priv(block_cb);
16561671
err = mlxsw_sp_acl_block_unbind(mlxsw_sp, acl_block,
16571672
mlxsw_sp_port, ingress);
1658-
if (!err && !tcf_block_cb_decref(block_cb)) {
1659-
__tcf_block_cb_unregister(block, block_cb);
1660-
mlxsw_sp_acl_block_destroy(acl_block);
1673+
if (!err && !flow_block_cb_decref(block_cb)) {
1674+
flow_block_cb_remove(block_cb, f);
1675+
list_del(&block_cb->driver_list);
16611676
}
16621677
}
16631678

16641679
static int mlxsw_sp_setup_tc_block(struct mlxsw_sp_port *mlxsw_sp_port,
1665-
struct tc_block_offload *f)
1680+
struct flow_block_offload *f)
16661681
{
1682+
struct flow_block_cb *block_cb;
16671683
tc_setup_cb_t *cb;
16681684
bool ingress;
16691685
int err;
@@ -1678,24 +1694,32 @@ static int mlxsw_sp_setup_tc_block(struct mlxsw_sp_port *mlxsw_sp_port,
16781694
return -EOPNOTSUPP;
16791695
}
16801696

1697+
f->driver_block_list = &mlxsw_sp_block_cb_list;
1698+
16811699
switch (f->command) {
16821700
case FLOW_BLOCK_BIND:
1683-
err = tcf_block_cb_register(f->block, cb, mlxsw_sp_port,
1684-
mlxsw_sp_port, f->extack);
1685-
if (err)
1686-
return err;
1687-
err = mlxsw_sp_setup_tc_block_flower_bind(mlxsw_sp_port,
1688-
f->block, ingress,
1689-
f->extack);
1701+
block_cb = flow_block_cb_alloc(f->net, cb, mlxsw_sp_port,
1702+
mlxsw_sp_port, NULL);
1703+
if (IS_ERR(block_cb))
1704+
return PTR_ERR(block_cb);
1705+
err = mlxsw_sp_setup_tc_block_flower_bind(mlxsw_sp_port, f,
1706+
ingress);
16901707
if (err) {
1691-
tcf_block_cb_unregister(f->block, cb, mlxsw_sp_port);
1708+
flow_block_cb_free(block_cb);
16921709
return err;
16931710
}
1711+
flow_block_cb_add(block_cb, f);
1712+
list_add_tail(&block_cb->driver_list, &mlxsw_sp_block_cb_list);
16941713
return 0;
16951714
case FLOW_BLOCK_UNBIND:
16961715
mlxsw_sp_setup_tc_block_flower_unbind(mlxsw_sp_port,
1697-
f->block, ingress);
1698-
tcf_block_cb_unregister(f->block, cb, mlxsw_sp_port);
1716+
f, ingress);
1717+
block_cb = flow_block_cb_lookup(f, cb, mlxsw_sp_port);
1718+
if (!block_cb)
1719+
return -ENOENT;
1720+
1721+
flow_block_cb_remove(block_cb, f);
1722+
list_del(&block_cb->driver_list);
16991723
return 0;
17001724
default:
17011725
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)