Skip to content

Commit 0e75bfe

Browse files
vladimirolteankuba-moo
authored andcommitted
net: dsa: add simple HSR offload helpers
It turns out that HSR offloads are so fine-grained that many DSA switches can do a small part even though they weren't specifically designed for the protocols supported by that driver (HSR and PRP). Specifically NETIF_F_HW_HSR_DUP - it is simple packet duplication on transmit, towards all (aka 2) ports members of the HSR device. For many DSA switches, we know how to duplicate a packet, even though we never typically use that feature. The transmit port mask from the tagging protocol can have multiple bits set, and the switch should send the packet once to every port with a bit set from that mask. Nonetheless, not all tagging protocols are like this, and sometimes the port is a single numeric value rather than a bit mask. For that reason, and also because switches can sometimes change tagging protocols for different ones, we need to make HSR offload helpers opt-in. For devices that can do nothing else HSR-specific, we introduce dsa_port_simple_hsr_join() and dsa_port_simple_hsr_leave(). These functions monitor when two user ports of the same switch are part of the same HSR device, and when that condition is true, they toggle the NETIF_F_HW_HSR_DUP feature flag of both net devices. Normally only dsa_port_simple_hsr_join() and dsa_port_simple_hsr_leave() are needed. The dsa_port_simple_hsr_validate() helper is just to see what kind of configuration could be offloadable using the generic helpers. This is used by switch drivers which are not currently using the right tagging protocol to offload this HSR ring, but could in principle offload it after changing the tagger. Suggested-by: David Yang <mmyangfl@gmail.com> Cc: "Alvin Šipraga" <alsi@bang-olufsen.dk> Cc: Chester A. Unal" <chester.a.unal@arinc9.com> Cc: "Clément Léger" <clement.leger@bootlin.com> Cc: Daniel Golle <daniel@makrotopia.org> Cc: DENG Qingfang <dqfext@gmail.com> Cc: Florian Fainelli <florian.fainelli@broadcom.com> Cc: George McCollister <george.mccollister@gmail.com> Cc: Hauke Mehrtens <hauke@hauke-m.de> Cc: Jonas Gorski <jonas.gorski@gmail.com> Cc: Kurt Kanzenbach <kurt@linutronix.de> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: Sean Wang <sean.wang@mediatek.com> Cc: UNGLinuxDriver@microchip.com Cc: Woojung Huh <woojung.huh@microchip.com> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Link: https://patch.msgid.link/20251130131657.65080-6-vladimir.oltean@nxp.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 30296ac commit 0e75bfe

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

include/net/dsa.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,15 @@ bool dsa_mdb_present_in_other_db(struct dsa_switch *ds, int port,
13221322
const struct switchdev_obj_port_mdb *mdb,
13231323
struct dsa_db db);
13241324

1325+
int dsa_port_simple_hsr_validate(struct dsa_switch *ds, int port,
1326+
struct net_device *hsr,
1327+
struct netlink_ext_ack *extack);
1328+
int dsa_port_simple_hsr_join(struct dsa_switch *ds, int port,
1329+
struct net_device *hsr,
1330+
struct netlink_ext_ack *extack);
1331+
int dsa_port_simple_hsr_leave(struct dsa_switch *ds, int port,
1332+
struct net_device *hsr);
1333+
13251334
/* Keep inline for faster access in hot path */
13261335
static inline bool netdev_uses_dsa(const struct net_device *dev)
13271336
{

net/dsa/dsa.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <linux/device.h>
1111
#include <linux/err.h>
12+
#include <linux/if_hsr.h>
1213
#include <linux/list.h>
1314
#include <linux/module.h>
1415
#include <linux/netdevice.h>
@@ -1766,6 +1767,70 @@ bool dsa_mdb_present_in_other_db(struct dsa_switch *ds, int port,
17661767
}
17671768
EXPORT_SYMBOL_GPL(dsa_mdb_present_in_other_db);
17681769

1770+
/* Helpers for switches without specific HSR offloads, but which can implement
1771+
* NETIF_F_HW_HSR_DUP because their tagger uses dsa_xmit_port_mask()
1772+
*/
1773+
int dsa_port_simple_hsr_validate(struct dsa_switch *ds, int port,
1774+
struct net_device *hsr,
1775+
struct netlink_ext_ack *extack)
1776+
{
1777+
enum hsr_port_type type;
1778+
int err;
1779+
1780+
err = hsr_get_port_type(hsr, dsa_to_port(ds, port)->user, &type);
1781+
if (err)
1782+
return err;
1783+
1784+
if (type != HSR_PT_SLAVE_A && type != HSR_PT_SLAVE_B) {
1785+
NL_SET_ERR_MSG_MOD(extack,
1786+
"Only HSR slave ports can be offloaded");
1787+
return -EOPNOTSUPP;
1788+
}
1789+
1790+
return 0;
1791+
}
1792+
EXPORT_SYMBOL_GPL(dsa_port_simple_hsr_validate);
1793+
1794+
int dsa_port_simple_hsr_join(struct dsa_switch *ds, int port,
1795+
struct net_device *hsr,
1796+
struct netlink_ext_ack *extack)
1797+
{
1798+
struct dsa_port *dp = dsa_to_port(ds, port), *other_dp;
1799+
int err;
1800+
1801+
err = dsa_port_simple_hsr_validate(ds, port, hsr, extack);
1802+
if (err)
1803+
return err;
1804+
1805+
dsa_hsr_foreach_port(other_dp, ds, hsr) {
1806+
if (other_dp != dp) {
1807+
dp->user->features |= NETIF_F_HW_HSR_DUP;
1808+
other_dp->user->features |= NETIF_F_HW_HSR_DUP;
1809+
break;
1810+
}
1811+
}
1812+
1813+
return 0;
1814+
}
1815+
EXPORT_SYMBOL_GPL(dsa_port_simple_hsr_join);
1816+
1817+
int dsa_port_simple_hsr_leave(struct dsa_switch *ds, int port,
1818+
struct net_device *hsr)
1819+
{
1820+
struct dsa_port *dp = dsa_to_port(ds, port), *other_dp;
1821+
1822+
dsa_hsr_foreach_port(other_dp, ds, hsr) {
1823+
if (other_dp != dp) {
1824+
dp->user->features &= ~NETIF_F_HW_HSR_DUP;
1825+
other_dp->user->features &= ~NETIF_F_HW_HSR_DUP;
1826+
break;
1827+
}
1828+
}
1829+
1830+
return 0;
1831+
}
1832+
EXPORT_SYMBOL_GPL(dsa_port_simple_hsr_leave);
1833+
17691834
static const struct dsa_stubs __dsa_stubs = {
17701835
.conduit_hwtstamp_validate = __dsa_conduit_hwtstamp_validate,
17711836
};

0 commit comments

Comments
 (0)