Skip to content

Commit 4e95bc2

Browse files
ummakynesdavem330
authored andcommitted
net: flow_offload: add flow_block_cb_setup_simple()
Most drivers do the same thing to set up the flow block callbacks, this patch adds a helper function to do this. This preparation patch reduces the number of changes to adapt the existing drivers to use the flow block callback API. This new helper function takes a flow block list per-driver, which is set to NULL until this driver list is used. This patch also introduces the flow_block_command and flow_block_binder_type enumerations, which are renamed to use FLOW_BLOCK_* in follow up patches. There are three definitions (aliases) in order to reduce the number of updates in this patch, which go away once drivers are fully adapted to use this flow block API. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2bb295f commit 4e95bc2

17 files changed

Lines changed: 117 additions & 317 deletions

File tree

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9907,32 +9907,16 @@ static int bnxt_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
99079907
}
99089908
}
99099909

9910-
static int bnxt_setup_tc_block(struct net_device *dev,
9911-
struct tc_block_offload *f)
9912-
{
9913-
struct bnxt *bp = netdev_priv(dev);
9914-
9915-
if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
9916-
return -EOPNOTSUPP;
9917-
9918-
switch (f->command) {
9919-
case TC_BLOCK_BIND:
9920-
return tcf_block_cb_register(f->block, bnxt_setup_tc_block_cb,
9921-
bp, bp, f->extack);
9922-
case TC_BLOCK_UNBIND:
9923-
tcf_block_cb_unregister(f->block, bnxt_setup_tc_block_cb, bp);
9924-
return 0;
9925-
default:
9926-
return -EOPNOTSUPP;
9927-
}
9928-
}
9929-
99309910
static int bnxt_setup_tc(struct net_device *dev, enum tc_setup_type type,
99319911
void *type_data)
99329912
{
9913+
struct bnxt *bp = netdev_priv(dev);
9914+
99339915
switch (type) {
99349916
case TC_SETUP_BLOCK:
9935-
return bnxt_setup_tc_block(dev, type_data);
9917+
return flow_block_cb_setup_simple(type_data, NULL,
9918+
bnxt_setup_tc_block_cb,
9919+
bp, bp, true);
99369920
case TC_SETUP_QDISC_MQPRIO: {
99379921
struct tc_mqprio_qopt *mqprio = type_data;
99389922

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

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -161,34 +161,16 @@ static int bnxt_vf_rep_setup_tc_block_cb(enum tc_setup_type type,
161161
}
162162
}
163163

164-
static int bnxt_vf_rep_setup_tc_block(struct net_device *dev,
165-
struct tc_block_offload *f)
166-
{
167-
struct bnxt_vf_rep *vf_rep = netdev_priv(dev);
168-
169-
if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
170-
return -EOPNOTSUPP;
171-
172-
switch (f->command) {
173-
case TC_BLOCK_BIND:
174-
return tcf_block_cb_register(f->block,
175-
bnxt_vf_rep_setup_tc_block_cb,
176-
vf_rep, vf_rep, f->extack);
177-
case TC_BLOCK_UNBIND:
178-
tcf_block_cb_unregister(f->block,
179-
bnxt_vf_rep_setup_tc_block_cb, vf_rep);
180-
return 0;
181-
default:
182-
return -EOPNOTSUPP;
183-
}
184-
}
185-
186164
static int bnxt_vf_rep_setup_tc(struct net_device *dev, enum tc_setup_type type,
187165
void *type_data)
188166
{
167+
struct bnxt_vf_rep *vf_rep = netdev_priv(dev);
168+
189169
switch (type) {
190170
case TC_SETUP_BLOCK:
191-
return bnxt_vf_rep_setup_tc_block(dev, type_data);
171+
return flow_block_cb_setup_simple(type_data, NULL,
172+
bnxt_vf_rep_setup_tc_block_cb,
173+
vf_rep, vf_rep, true);
192174
default:
193175
return -EOPNOTSUPP;
194176
}

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,32 +3190,16 @@ static int cxgb_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
31903190
}
31913191
}
31923192

3193-
static int cxgb_setup_tc_block(struct net_device *dev,
3194-
struct tc_block_offload *f)
3195-
{
3196-
struct port_info *pi = netdev2pinfo(dev);
3197-
3198-
if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
3199-
return -EOPNOTSUPP;
3200-
3201-
switch (f->command) {
3202-
case TC_BLOCK_BIND:
3203-
return tcf_block_cb_register(f->block, cxgb_setup_tc_block_cb,
3204-
pi, dev, f->extack);
3205-
case TC_BLOCK_UNBIND:
3206-
tcf_block_cb_unregister(f->block, cxgb_setup_tc_block_cb, pi);
3207-
return 0;
3208-
default:
3209-
return -EOPNOTSUPP;
3210-
}
3211-
}
3212-
32133193
static int cxgb_setup_tc(struct net_device *dev, enum tc_setup_type type,
32143194
void *type_data)
32153195
{
3196+
struct port_info *pi = netdev2pinfo(dev);
3197+
32163198
switch (type) {
32173199
case TC_SETUP_BLOCK:
3218-
return cxgb_setup_tc_block(dev, type_data);
3200+
return flow_block_cb_setup_simple(type_data, NULL,
3201+
cxgb_setup_tc_block_cb,
3202+
pi, dev, true);
32193203
default:
32203204
return -EOPNOTSUPP;
32213205
}

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8177,34 +8177,18 @@ static int i40e_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
81778177
}
81788178
}
81798179

8180-
static int i40e_setup_tc_block(struct net_device *dev,
8181-
struct tc_block_offload *f)
8182-
{
8183-
struct i40e_netdev_priv *np = netdev_priv(dev);
8184-
8185-
if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
8186-
return -EOPNOTSUPP;
8187-
8188-
switch (f->command) {
8189-
case TC_BLOCK_BIND:
8190-
return tcf_block_cb_register(f->block, i40e_setup_tc_block_cb,
8191-
np, np, f->extack);
8192-
case TC_BLOCK_UNBIND:
8193-
tcf_block_cb_unregister(f->block, i40e_setup_tc_block_cb, np);
8194-
return 0;
8195-
default:
8196-
return -EOPNOTSUPP;
8197-
}
8198-
}
8199-
82008180
static int __i40e_setup_tc(struct net_device *netdev, enum tc_setup_type type,
82018181
void *type_data)
82028182
{
8183+
struct i40e_netdev_priv *np = netdev_priv(netdev);
8184+
82038185
switch (type) {
82048186
case TC_SETUP_QDISC_MQPRIO:
82058187
return i40e_setup_tc(netdev, type_data);
82068188
case TC_SETUP_BLOCK:
8207-
return i40e_setup_tc_block(netdev, type_data);
8189+
return flow_block_cb_setup_simple(type_data, NULL,
8190+
i40e_setup_tc_block_cb,
8191+
np, np, true);
82088192
default:
82098193
return -EOPNOTSUPP;
82108194
}

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

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3113,35 +3113,6 @@ static int iavf_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
31133113
}
31143114
}
31153115

3116-
/**
3117-
* iavf_setup_tc_block - register callbacks for tc
3118-
* @netdev: network interface device structure
3119-
* @f: tc offload data
3120-
*
3121-
* This function registers block callbacks for tc
3122-
* offloads
3123-
**/
3124-
static int iavf_setup_tc_block(struct net_device *dev,
3125-
struct tc_block_offload *f)
3126-
{
3127-
struct iavf_adapter *adapter = netdev_priv(dev);
3128-
3129-
if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
3130-
return -EOPNOTSUPP;
3131-
3132-
switch (f->command) {
3133-
case TC_BLOCK_BIND:
3134-
return tcf_block_cb_register(f->block, iavf_setup_tc_block_cb,
3135-
adapter, adapter, f->extack);
3136-
case TC_BLOCK_UNBIND:
3137-
tcf_block_cb_unregister(f->block, iavf_setup_tc_block_cb,
3138-
adapter);
3139-
return 0;
3140-
default:
3141-
return -EOPNOTSUPP;
3142-
}
3143-
}
3144-
31453116
/**
31463117
* iavf_setup_tc - configure multiple traffic classes
31473118
* @netdev: network interface device structure
@@ -3156,11 +3127,15 @@ static int iavf_setup_tc_block(struct net_device *dev,
31563127
static int iavf_setup_tc(struct net_device *netdev, enum tc_setup_type type,
31573128
void *type_data)
31583129
{
3130+
struct iavf_adapter *adapter = netdev_priv(netdev);
3131+
31593132
switch (type) {
31603133
case TC_SETUP_QDISC_MQPRIO:
31613134
return __iavf_setup_tc(netdev, type_data);
31623135
case TC_SETUP_BLOCK:
3163-
return iavf_setup_tc_block(netdev, type_data);
3136+
return flow_block_cb_setup_simple(type_data, NULL,
3137+
iavf_setup_tc_block_cb,
3138+
adapter, adapter, true);
31643139
default:
31653140
return -EOPNOTSUPP;
31663141
}

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

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,25 +2783,6 @@ static int igb_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
27832783
}
27842784
}
27852785

2786-
static int igb_setup_tc_block(struct igb_adapter *adapter,
2787-
struct tc_block_offload *f)
2788-
{
2789-
if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
2790-
return -EOPNOTSUPP;
2791-
2792-
switch (f->command) {
2793-
case TC_BLOCK_BIND:
2794-
return tcf_block_cb_register(f->block, igb_setup_tc_block_cb,
2795-
adapter, adapter, f->extack);
2796-
case TC_BLOCK_UNBIND:
2797-
tcf_block_cb_unregister(f->block, igb_setup_tc_block_cb,
2798-
adapter);
2799-
return 0;
2800-
default:
2801-
return -EOPNOTSUPP;
2802-
}
2803-
}
2804-
28052786
static int igb_offload_txtime(struct igb_adapter *adapter,
28062787
struct tc_etf_qopt_offload *qopt)
28072788
{
@@ -2834,7 +2815,10 @@ static int igb_setup_tc(struct net_device *dev, enum tc_setup_type type,
28342815
case TC_SETUP_QDISC_CBS:
28352816
return igb_offload_cbs(adapter, type_data);
28362817
case TC_SETUP_BLOCK:
2837-
return igb_setup_tc_block(adapter, type_data);
2818+
return flow_block_cb_setup_simple(type_data, NULL,
2819+
igb_setup_tc_block_cb,
2820+
adapter, adapter, true);
2821+
28382822
case TC_SETUP_QDISC_ETF:
28392823
return igb_offload_txtime(adapter, type_data);
28402824

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

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9607,27 +9607,6 @@ static int ixgbe_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
96079607
}
96089608
}
96099609

9610-
static int ixgbe_setup_tc_block(struct net_device *dev,
9611-
struct tc_block_offload *f)
9612-
{
9613-
struct ixgbe_adapter *adapter = netdev_priv(dev);
9614-
9615-
if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
9616-
return -EOPNOTSUPP;
9617-
9618-
switch (f->command) {
9619-
case TC_BLOCK_BIND:
9620-
return tcf_block_cb_register(f->block, ixgbe_setup_tc_block_cb,
9621-
adapter, adapter, f->extack);
9622-
case TC_BLOCK_UNBIND:
9623-
tcf_block_cb_unregister(f->block, ixgbe_setup_tc_block_cb,
9624-
adapter);
9625-
return 0;
9626-
default:
9627-
return -EOPNOTSUPP;
9628-
}
9629-
}
9630-
96319610
static int ixgbe_setup_tc_mqprio(struct net_device *dev,
96329611
struct tc_mqprio_qopt *mqprio)
96339612
{
@@ -9638,9 +9617,13 @@ static int ixgbe_setup_tc_mqprio(struct net_device *dev,
96389617
static int __ixgbe_setup_tc(struct net_device *dev, enum tc_setup_type type,
96399618
void *type_data)
96409619
{
9620+
struct ixgbe_adapter *adapter = netdev_priv(dev);
9621+
96419622
switch (type) {
96429623
case TC_SETUP_BLOCK:
9643-
return ixgbe_setup_tc_block(dev, type_data);
9624+
return flow_block_cb_setup_simple(type_data, NULL,
9625+
ixgbe_setup_tc_block_cb,
9626+
adapter, adapter, true);
96449627
case TC_SETUP_QDISC_MQPRIO:
96459628
return ixgbe_setup_tc_mqprio(dev, type_data);
96469629
default:

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

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3457,36 +3457,19 @@ static int mlx5e_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
34573457
return -EOPNOTSUPP;
34583458
}
34593459
}
3460-
3461-
static int mlx5e_setup_tc_block(struct net_device *dev,
3462-
struct tc_block_offload *f)
3463-
{
3464-
struct mlx5e_priv *priv = netdev_priv(dev);
3465-
3466-
if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
3467-
return -EOPNOTSUPP;
3468-
3469-
switch (f->command) {
3470-
case TC_BLOCK_BIND:
3471-
return tcf_block_cb_register(f->block, mlx5e_setup_tc_block_cb,
3472-
priv, priv, f->extack);
3473-
case TC_BLOCK_UNBIND:
3474-
tcf_block_cb_unregister(f->block, mlx5e_setup_tc_block_cb,
3475-
priv);
3476-
return 0;
3477-
default:
3478-
return -EOPNOTSUPP;
3479-
}
3480-
}
34813460
#endif
34823461

34833462
static int mlx5e_setup_tc(struct net_device *dev, enum tc_setup_type type,
34843463
void *type_data)
34853464
{
3465+
struct mlx5e_priv *priv = netdev_priv(dev);
3466+
34863467
switch (type) {
34873468
#ifdef CONFIG_MLX5_ESWITCH
34883469
case TC_SETUP_BLOCK:
3489-
return mlx5e_setup_tc_block(dev, type_data);
3470+
return flow_block_cb_setup_simple(type_data, NULL,
3471+
mlx5e_setup_tc_block_cb,
3472+
priv, priv, true);
34903473
#endif
34913474
case TC_SETUP_QDISC_MQPRIO:
34923475
return mlx5e_setup_tc_mqprio(dev, type_data);

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,32 +1153,16 @@ static int mlx5e_rep_setup_tc_cb(enum tc_setup_type type, void *type_data,
11531153
}
11541154
}
11551155

1156-
static int mlx5e_rep_setup_tc_block(struct net_device *dev,
1157-
struct tc_block_offload *f)
1158-
{
1159-
struct mlx5e_priv *priv = netdev_priv(dev);
1160-
1161-
if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
1162-
return -EOPNOTSUPP;
1163-
1164-
switch (f->command) {
1165-
case TC_BLOCK_BIND:
1166-
return tcf_block_cb_register(f->block, mlx5e_rep_setup_tc_cb,
1167-
priv, priv, f->extack);
1168-
case TC_BLOCK_UNBIND:
1169-
tcf_block_cb_unregister(f->block, mlx5e_rep_setup_tc_cb, priv);
1170-
return 0;
1171-
default:
1172-
return -EOPNOTSUPP;
1173-
}
1174-
}
1175-
11761156
static int mlx5e_rep_setup_tc(struct net_device *dev, enum tc_setup_type type,
11771157
void *type_data)
11781158
{
1159+
struct mlx5e_priv *priv = netdev_priv(dev);
1160+
11791161
switch (type) {
11801162
case TC_SETUP_BLOCK:
1181-
return mlx5e_rep_setup_tc_block(dev, type_data);
1163+
return flow_block_cb_setup_simple(type_data, NULL,
1164+
mlx5e_rep_setup_tc_cb,
1165+
priv, priv, true);
11821166
default:
11831167
return -EOPNOTSUPP;
11841168
}

‎drivers/net/ethernet/netronome/nfp/abm/cls.c‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -265,19 +265,6 @@ static int nfp_abm_setup_tc_block_cb(enum tc_setup_type type,
265265
int nfp_abm_setup_cls_block(struct net_device *netdev, struct nfp_repr *repr,
266266
struct tc_block_offload *f)
267267
{
268-
if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_EGRESS)
269-
return -EOPNOTSUPP;
270-
271-
switch (f->command) {
272-
case TC_BLOCK_BIND:
273-
return tcf_block_cb_register(f->block,
274-
nfp_abm_setup_tc_block_cb,
275-
repr, repr, f->extack);
276-
case TC_BLOCK_UNBIND:
277-
tcf_block_cb_unregister(f->block, nfp_abm_setup_tc_block_cb,
278-
repr);
279-
return 0;
280-
default:
281-
return -EOPNOTSUPP;
282-
}
268+
return flow_block_cb_setup_simple(f, NULL, nfp_abm_setup_tc_block_cb,
269+
repr, repr, true);
283270
}

0 commit comments

Comments
 (0)