Commit 9c0c7014 authored by Florian Fainelli's avatar Florian Fainelli Committed by David S. Miller

net: dsa: Setup dsa_netdev_ops

Now that we have all the infrastructure in place for calling into the
dsa_ptr->netdev_ops function pointers, install them when we configure
the DSA CPU/management interface and tear them down. The flow is
unchanged from before, but now we preserve equality of tests when
network device drivers do tests like dev->netdev_ops == &foo_ops which
was not the case before since we were allocating an entirely new
structure.
Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3369afba
...@@ -230,7 +230,6 @@ struct dsa_port { ...@@ -230,7 +230,6 @@ struct dsa_port {
* Original copy of the master netdev net_device_ops * Original copy of the master netdev net_device_ops
*/ */
const struct dsa_netdevice_ops *netdev_ops; const struct dsa_netdevice_ops *netdev_ops;
const struct net_device_ops *orig_ndo_ops;
bool setup; bool setup;
}; };
......
...@@ -220,12 +220,17 @@ static int dsa_master_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) ...@@ -220,12 +220,17 @@ static int dsa_master_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
break; break;
} }
if (cpu_dp->orig_ndo_ops && cpu_dp->orig_ndo_ops->ndo_do_ioctl) if (dev->netdev_ops->ndo_do_ioctl)
err = cpu_dp->orig_ndo_ops->ndo_do_ioctl(dev, ifr, cmd); err = dev->netdev_ops->ndo_do_ioctl(dev, ifr, cmd);
return err; return err;
} }
static const struct dsa_netdevice_ops dsa_netdev_ops = {
.ndo_do_ioctl = dsa_master_ioctl,
.ndo_get_phys_port_name = dsa_master_get_phys_port_name,
};
static int dsa_master_ethtool_setup(struct net_device *dev) static int dsa_master_ethtool_setup(struct net_device *dev)
{ {
struct dsa_port *cpu_dp = dev->dsa_ptr; struct dsa_port *cpu_dp = dev->dsa_ptr;
...@@ -260,38 +265,10 @@ static void dsa_master_ethtool_teardown(struct net_device *dev) ...@@ -260,38 +265,10 @@ static void dsa_master_ethtool_teardown(struct net_device *dev)
cpu_dp->orig_ethtool_ops = NULL; cpu_dp->orig_ethtool_ops = NULL;
} }
static int dsa_master_ndo_setup(struct net_device *dev) static void dsa_netdev_ops_set(struct net_device *dev,
const struct dsa_netdevice_ops *ops)
{ {
struct dsa_port *cpu_dp = dev->dsa_ptr; dev->dsa_ptr->netdev_ops = ops;
struct dsa_switch *ds = cpu_dp->ds;
struct net_device_ops *ops;
if (dev->netdev_ops->ndo_get_phys_port_name)
return 0;
ops = devm_kzalloc(ds->dev, sizeof(*ops), GFP_KERNEL);
if (!ops)
return -ENOMEM;
cpu_dp->orig_ndo_ops = dev->netdev_ops;
if (cpu_dp->orig_ndo_ops)
memcpy(ops, cpu_dp->orig_ndo_ops, sizeof(*ops));
ops->ndo_get_phys_port_name = dsa_master_get_phys_port_name;
ops->ndo_do_ioctl = dsa_master_ioctl;
dev->netdev_ops = ops;
return 0;
}
static void dsa_master_ndo_teardown(struct net_device *dev)
{
struct dsa_port *cpu_dp = dev->dsa_ptr;
if (cpu_dp->orig_ndo_ops)
dev->netdev_ops = cpu_dp->orig_ndo_ops;
cpu_dp->orig_ndo_ops = NULL;
} }
static ssize_t tagging_show(struct device *d, struct device_attribute *attr, static ssize_t tagging_show(struct device *d, struct device_attribute *attr,
...@@ -353,9 +330,7 @@ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp) ...@@ -353,9 +330,7 @@ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp)
if (ret) if (ret)
return ret; return ret;
ret = dsa_master_ndo_setup(dev); dsa_netdev_ops_set(dev, &dsa_netdev_ops);
if (ret)
goto out_err_ethtool_teardown;
ret = sysfs_create_group(&dev->dev.kobj, &dsa_group); ret = sysfs_create_group(&dev->dev.kobj, &dsa_group);
if (ret) if (ret)
...@@ -364,8 +339,7 @@ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp) ...@@ -364,8 +339,7 @@ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp)
return ret; return ret;
out_err_ndo_teardown: out_err_ndo_teardown:
dsa_master_ndo_teardown(dev); dsa_netdev_ops_set(dev, NULL);
out_err_ethtool_teardown:
dsa_master_ethtool_teardown(dev); dsa_master_ethtool_teardown(dev);
return ret; return ret;
} }
...@@ -373,7 +347,7 @@ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp) ...@@ -373,7 +347,7 @@ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp)
void dsa_master_teardown(struct net_device *dev) void dsa_master_teardown(struct net_device *dev)
{ {
sysfs_remove_group(&dev->dev.kobj, &dsa_group); sysfs_remove_group(&dev->dev.kobj, &dsa_group);
dsa_master_ndo_teardown(dev); dsa_netdev_ops_set(dev, NULL);
dsa_master_ethtool_teardown(dev); dsa_master_ethtool_teardown(dev);
dsa_master_reset_mtu(dev); dsa_master_reset_mtu(dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment