[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210410133454.4768-4-ansuelsmth@gmail.com>
Date: Sat, 10 Apr 2021 15:34:49 +0200
From: Ansuel Smith <ansuelsmth@...il.com>
To: netdev@...r.kernel.org
Cc: Ansuel Smith <ansuelsmth@...il.com>,
Marek Behún <marek.behun@....cz>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>, Andrew Lunn <andrew@...n.ch>,
Vivien Didelot <vivien.didelot@...il.com>,
Florian Fainelli <f.fainelli@...il.com>,
Vladimir Oltean <olteanv@...il.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andriin@...com>,
Eric Dumazet <edumazet@...gle.com>,
Wei Wang <weiwan@...gle.com>,
Cong Wang <cong.wang@...edance.com>,
Taehee Yoo <ap420073@...il.com>,
Björn Töpel <bjorn@...nel.org>,
Francis Laniel <laniel_francis@...vacyrequired.com>,
zhang kai <zhangkaiheb@....com>, Di Zhu <zhudi21@...wei.com>,
Roopa Prabhu <roopa@...ulusnetworks.com>,
linux-kernel@...r.kernel.org
Subject: [PATCH RFC net-next 3/3] net: dsa: implement ndo_set_netlink for chaning port's CPU port
Implement ndo_set_iflink for DSA slave device. In multi-CPU port setup
this should be used to change to which CPU destination port a given port
should be connected. On CPU port change, the mac address is updated with
the new value, if not set to a custom value.
Signed-off-by: Marek Behún <marek.behun@....cz>
Signed-off-by: Ansuel Smith <ansuelsmth@...il.com>
---
net/dsa/slave.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 992fcab4b552..c68dbd3ab21a 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -63,6 +63,36 @@ static int dsa_slave_get_iflink(const struct net_device *dev)
return dsa_slave_to_master(dev)->ifindex;
}
+static int dsa_slave_set_iflink(struct net_device *dev, int iflink)
+{
+ struct net_device *master = dsa_slave_to_master(dev);
+ struct dsa_port *dp = dsa_slave_to_port(dev);
+ struct dsa_slave_priv *p = netdev_priv(dev);
+ struct net_device *cpu_dev;
+ struct dsa_port *cpu_dp;
+
+ cpu_dev = dev_get_by_index(dev_net(dev), iflink);
+ if (!cpu_dev)
+ return -ENODEV;
+
+ cpu_dp = cpu_dev->dsa_ptr;
+ if (!cpu_dp)
+ return -EINVAL;
+
+ /* new CPU port has to be on the same switch tree */
+ if (cpu_dp->dst != dp->cpu_dp->dst)
+ return -EINVAL;
+
+ if (ether_addr_equal(dev->dev_addr, master->dev_addr))
+ eth_hw_addr_inherit(dev, cpu_dev);
+
+ /* should this be done atomically? */
+ dp->cpu_dp = cpu_dp;
+ p->xmit = cpu_dp->tag_ops->xmit;
+
+ return 0;
+}
+
static int dsa_slave_open(struct net_device *dev)
{
struct net_device *master = dsa_slave_to_master(dev);
@@ -1666,6 +1696,7 @@ static const struct net_device_ops dsa_slave_netdev_ops = {
.ndo_fdb_dump = dsa_slave_fdb_dump,
.ndo_do_ioctl = dsa_slave_ioctl,
.ndo_get_iflink = dsa_slave_get_iflink,
+ .ndo_set_iflink = dsa_slave_set_iflink,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_netpoll_setup = dsa_slave_netpoll_setup,
.ndo_netpoll_cleanup = dsa_slave_netpoll_cleanup,
--
2.30.2
Powered by blists - more mailing lists