Skip to content

Commit 4721119

Browse files
wkzdavem330
authored andcommitted
net: bridge: switchdev: allow the TX data plane forwarding to be offloaded
Allow switchdevs to forward frames from the CPU in accordance with the bridge configuration in the same way as is done between bridge ports. This means that the bridge will only send a single skb towards one of the ports under the switchdev's control, and expects the driver to deliver the packet to all eligible ports in its domain. Primarily this improves the performance of multicast flows with multiple subscribers, as it allows the hardware to perform the frame replication. The basic flow between the driver and the bridge is as follows: - When joining a bridge port, the switchdev driver calls switchdev_bridge_port_offload() with tx_fwd_offload = true. - The bridge sends offloadable skbs to one of the ports under the switchdev's control using skb->offload_fwd_mark = true. - The switchdev driver checks the skb->offload_fwd_mark field and lets its FDB lookup select the destination port mask for this packet. v1->v2: - convert br_input_skb_cb::fwd_hwdoms to a plain unsigned long - introduce a static key "br_switchdev_fwd_offload_used" to minimize the impact of the newly introduced feature on all the setups which don't have hardware that can make use of it - introduce a check for nbp->flags & BR_FWD_OFFLOAD to optimize cache line access - reorder nbp_switchdev_frame_mark_accel() and br_handle_vlan() in __br_forward() - do not strip VLAN on egress if forwarding offload on VLAN-aware bridge is being used - propagate errors from .ndo_dfwd_add_station() if not EOPNOTSUPP v2->v3: - replace the solution based on .ndo_dfwd_add_station with a solution based on switchdev_bridge_port_offload - rename BR_FWD_OFFLOAD to BR_TX_FWD_OFFLOAD v3->v4: rebase v4->v5: - make sure the static key is decremented on bridge port unoffload - more function and variable renaming and comments for them: br_switchdev_fwd_offload_used to br_switchdev_tx_fwd_offload br_switchdev_accels_skb to br_switchdev_frame_uses_tx_fwd_offload nbp_switchdev_frame_mark_tx_fwd to nbp_switchdev_frame_mark_tx_fwd_to_hwdom nbp_switchdev_frame_mark_accel to nbp_switchdev_frame_mark_tx_fwd_offload fwd_accel to tx_fwd_offload Signed-off-by: Tobias Waldekranz <[email protected]> Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5af84df commit 4721119

File tree

14 files changed

+125
-14
lines changed

14 files changed

+125
-14
lines changed

drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ static int dpaa2_switch_port_bridge_join(struct net_device *netdev,
19361936
err = switchdev_bridge_port_offload(netdev, netdev, NULL,
19371937
&dpaa2_switch_port_switchdev_nb,
19381938
&dpaa2_switch_port_switchdev_blocking_nb,
1939-
extack);
1939+
false, extack);
19401940
if (err)
19411941
goto err_switchdev_offload;
19421942

drivers/net/ethernet/marvell/prestera/prestera_switchdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ int prestera_bridge_port_join(struct net_device *br_dev,
502502
}
503503

504504
err = switchdev_bridge_port_offload(br_port->dev, port->dev, NULL,
505-
NULL, NULL, extack);
505+
NULL, NULL, false, extack);
506506
if (err)
507507
goto err_switchdev_offload;
508508

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ mlxsw_sp_bridge_port_create(struct mlxsw_sp_bridge_device *bridge_device,
362362
bridge_port->ref_count = 1;
363363

364364
err = switchdev_bridge_port_offload(brport_dev, mlxsw_sp_port->dev,
365-
NULL, NULL, NULL, extack);
365+
NULL, NULL, NULL, false, extack);
366366
if (err)
367367
goto err_switchdev_offload;
368368

drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static int sparx5_port_bridge_join(struct sparx5_port *port,
113113
set_bit(port->portno, sparx5->bridge_mask);
114114

115115
err = switchdev_bridge_port_offload(ndev, ndev, NULL, NULL, NULL,
116-
extack);
116+
false, extack);
117117
if (err)
118118
goto err_switchdev_offload;
119119

drivers/net/ethernet/mscc/ocelot_net.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ static int ocelot_netdevice_bridge_join(struct net_device *dev,
12001200
err = switchdev_bridge_port_offload(brport_dev, dev, priv,
12011201
&ocelot_netdevice_nb,
12021202
&ocelot_switchdev_blocking_nb,
1203-
extack);
1203+
false, extack);
12041204
if (err)
12051205
goto err_switchdev_offload;
12061206

drivers/net/ethernet/rocker/rocker_ofdpa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2599,7 +2599,7 @@ static int ofdpa_port_bridge_join(struct ofdpa_port *ofdpa_port,
25992599
return err;
26002600

26012601
return switchdev_bridge_port_offload(dev, dev, NULL, NULL, NULL,
2602-
extack);
2602+
false, extack);
26032603
}
26042604

26052605
static int ofdpa_port_bridge_leave(struct ofdpa_port *ofdpa_port)

drivers/net/ethernet/ti/am65-cpsw-nuss.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,7 @@ static int am65_cpsw_netdevice_port_link(struct net_device *ndev,
20972097
}
20982098

20992099
err = switchdev_bridge_port_offload(ndev, ndev, NULL, NULL, NULL,
2100-
extack);
2100+
false, extack);
21012101
if (err)
21022102
return err;
21032103

drivers/net/ethernet/ti/cpsw_new.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ static int cpsw_netdevice_port_link(struct net_device *ndev,
15181518
}
15191519

15201520
err = switchdev_bridge_port_offload(ndev, ndev, NULL, NULL, NULL,
1521-
extack);
1521+
false, extack);
15221522
if (err)
15231523
return err;
15241524

include/linux/if_bridge.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct br_ip_list {
5757
#define BR_MRP_AWARE BIT(17)
5858
#define BR_MRP_LOST_CONT BIT(18)
5959
#define BR_MRP_LOST_IN_CONT BIT(19)
60+
#define BR_TX_FWD_OFFLOAD BIT(20)
6061

6162
#define BR_DEFAULT_AGEING_TIME (300 * HZ)
6263

@@ -182,6 +183,7 @@ int switchdev_bridge_port_offload(struct net_device *brport_dev,
182183
struct net_device *dev, const void *ctx,
183184
struct notifier_block *atomic_nb,
184185
struct notifier_block *blocking_nb,
186+
bool tx_fwd_offload,
185187
struct netlink_ext_ack *extack);
186188
void switchdev_bridge_port_unoffload(struct net_device *brport_dev,
187189
const void *ctx,
@@ -195,6 +197,7 @@ switchdev_bridge_port_offload(struct net_device *brport_dev,
195197
struct net_device *dev, const void *ctx,
196198
struct notifier_block *atomic_nb,
197199
struct notifier_block *blocking_nb,
200+
bool tx_fwd_offload,
198201
struct netlink_ext_ack *extack)
199202
{
200203
return -EINVAL;

net/bridge/br_forward.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb
4848
skb_set_network_header(skb, depth);
4949
}
5050

51+
skb->offload_fwd_mark = br_switchdev_frame_uses_tx_fwd_offload(skb);
52+
5153
dev_queue_xmit(skb);
5254

5355
return 0;
@@ -76,6 +78,11 @@ static void __br_forward(const struct net_bridge_port *to,
7678
struct net *net;
7779
int br_hook;
7880

81+
/* Mark the skb for forwarding offload early so that br_handle_vlan()
82+
* can know whether to pop the VLAN header on egress or keep it.
83+
*/
84+
nbp_switchdev_frame_mark_tx_fwd_offload(to, skb);
85+
7986
vg = nbp_vlan_group_rcu(to);
8087
skb = br_handle_vlan(to->br, to, vg, skb);
8188
if (!skb)
@@ -174,6 +181,8 @@ static struct net_bridge_port *maybe_deliver(
174181
if (!should_deliver(p, skb))
175182
return prev;
176183

184+
nbp_switchdev_frame_mark_tx_fwd_to_hwdom(p, skb);
185+
177186
if (!prev)
178187
goto out;
179188

0 commit comments

Comments
 (0)