Add offloading for packet duplication supported by the YT921x switches.
Signed-off-by: David Yang <mmyangfl@gmail.com>
---
drivers/net/dsa/yt921x.c | 24 ++++++++++++++++++++++++
net/dsa/tag_yt921x.c | 4 ++++
2 files changed, 28 insertions(+)
diff --git a/drivers/net/dsa/yt921x.c b/drivers/net/dsa/yt921x.c
index e88b4037ee80..e7b416719b58 100644
--- a/drivers/net/dsa/yt921x.c
+++ b/drivers/net/dsa/yt921x.c
@@ -1038,6 +1038,27 @@ static int yt921x_dsa_port_max_mtu(struct dsa_switch *ds, int port)
return YT921X_FRAME_SIZE_MAX - ETH_HLEN - ETH_FCS_LEN - YT921X_TAG_LEN;
}
+static int
+yt921x_dsa_port_hsr_leave(struct dsa_switch *ds, int port,
+ struct net_device *hsr)
+{
+ return 0;
+}
+
+static int
+yt921x_dsa_port_hsr_join(struct dsa_switch *ds, int port,
+ struct net_device *hsr, struct netlink_ext_ack *extack)
+{
+ struct dsa_port *dp = dsa_to_port(ds, port);
+ struct net_device *user = dp->user;
+
+ /* Nothing special here; we natively support tx packet duplication */
+
+ user->features |= NETIF_F_HW_HSR_DUP;
+
+ return 0;
+}
+
static int
yt921x_mirror_del(struct yt921x_priv *priv, int port, bool ingress)
{
@@ -2880,6 +2901,9 @@ static const struct dsa_switch_ops yt921x_dsa_switch_ops = {
/* mtu */
.port_change_mtu = yt921x_dsa_port_change_mtu,
.port_max_mtu = yt921x_dsa_port_max_mtu,
+ /* hsr */
+ .port_hsr_leave = yt921x_dsa_port_hsr_leave,
+ .port_hsr_join = yt921x_dsa_port_hsr_join,
/* mirror */
.port_mirror_del = yt921x_dsa_port_mirror_del,
.port_mirror_add = yt921x_dsa_port_mirror_add,
diff --git a/net/dsa/tag_yt921x.c b/net/dsa/tag_yt921x.c
index 995da44f0a2a..0ad83924fda1 100644
--- a/net/dsa/tag_yt921x.c
+++ b/net/dsa/tag_yt921x.c
@@ -46,6 +46,7 @@ yt921x_tag_xmit(struct sk_buff *skb, struct net_device *netdev)
{
struct dsa_port *dp = dsa_user_to_port(netdev);
unsigned int port = dp->index;
+ struct dsa_port *partner;
__be16 *tag;
u16 tx;
@@ -59,6 +60,9 @@ yt921x_tag_xmit(struct sk_buff *skb, struct net_device *netdev)
tag[1] = 0;
tag[2] = 0;
tx = YT921X_TAG_PORT_EN | YT921X_TAG_TX_PORTn(port);
+ if (dp->hsr_dev)
+ dsa_hsr_foreach_port(partner, dp->ds, dp->hsr_dev)
+ tx |= YT921X_TAG_TX_PORTn(partner->index);
tag[3] = htons(tx);
return skb;
--
2.51.0