Commit 9d490b4e authored by Vivien Didelot's avatar Vivien Didelot Committed by David S. Miller

net: dsa: rename switch operations structure

Now that the dsa_switch_driver structure contains only function pointers
as it is supposed to, rename it to the more appropriate dsa_switch_ops,
uniformly to any other operations structure in the kernel.

No functional changes here, basically just the result of something like:
s/dsa_switch_driver *drv/dsa_switch_ops *ops/g

However keep the {un,}register_switch_driver functions and their
dsa_switch_drivers list as is, since they represent the -- likely to be
deprecated soon -- legacy DSA registration framework.

In the meantime, also fix the following checks from checkpatch.pl to
make it happy with this patch:

    CHECK: Comparison to NULL could be written "!ops"
    #403: FILE: net/dsa/dsa.c:470:
    +	if (ops == NULL) {

    CHECK: Comparison to NULL could be written "ds->ops->get_strings"
    #773: FILE: net/dsa/slave.c:697:
    +		if (ds->ops->get_strings != NULL)

    CHECK: Comparison to NULL could be written "ds->ops->get_ethtool_stats"
    #824: FILE: net/dsa/slave.c:785:
    +	if (ds->ops->get_ethtool_stats != NULL)

    CHECK: Comparison to NULL could be written "ds->ops->get_sset_count"
    #835: FILE: net/dsa/slave.c:798:
    +		if (ds->ops->get_sset_count != NULL)

    total: 0 errors, 0 warnings, 4 checks, 784 lines checked
Signed-off-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Acked-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c7b7b483
......@@ -227,9 +227,9 @@ to address individual switches in the tree.
dsa_switch: structure describing a switch device in the tree, referencing a
dsa_switch_tree as a backpointer, slave network devices, master network device,
and a reference to the backing dsa_switch_driver
and a reference to the backing dsa_switch_ops
dsa_switch_driver: structure referencing function pointers, see below for a full
dsa_switch_ops: structure referencing function pointers, see below for a full
description.
Design limitations
......@@ -357,10 +357,10 @@ regular HWMON devices in /sys/class/hwmon/.
Driver development
==================
DSA switch drivers need to implement a dsa_switch_driver structure which will
DSA switch drivers need to implement a dsa_switch_ops structure which will
contain the various members described below.
register_switch_driver() registers this dsa_switch_driver in its internal list
register_switch_driver() registers this dsa_switch_ops in its internal list
of drivers to probe for. unregister_switch_driver() does the exact opposite.
Unless requested differently by setting the priv_size member accordingly, DSA
......@@ -379,7 +379,7 @@ Switch configuration
buses, return a non-NULL string
- setup: setup function for the switch, this function is responsible for setting
up the dsa_switch_driver private structure with all it needs: register maps,
up the dsa_switch_ops private structure with all it needs: register maps,
interrupts, mutexes, locks etc.. This function is also expected to properly
configure the switch to separate all network interfaces from each other, that
is, they should be isolated by the switch hardware itself, typically by creating
......
......@@ -1378,7 +1378,7 @@ static enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds)
return DSA_TAG_PROTO_NONE;
}
static struct dsa_switch_driver b53_switch_ops = {
static struct dsa_switch_ops b53_switch_ops = {
.get_tag_protocol = b53_get_tag_protocol,
.setup = b53_setup,
.set_addr = b53_set_addr,
......@@ -1618,7 +1618,7 @@ static int b53_switch_init(struct b53_device *dev)
dev->vta_regs[1] = chip->vta_regs[1];
dev->vta_regs[2] = chip->vta_regs[2];
dev->jumbo_pm_reg = chip->jumbo_pm_reg;
ds->drv = &b53_switch_ops;
ds->ops = &b53_switch_ops;
dev->cpu_port = chip->cpu_port;
dev->num_vlans = chip->vlans;
dev->num_arl_entries = chip->arl_entries;
......
......@@ -1581,7 +1581,7 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds)
return 0;
}
static struct dsa_switch_driver bcm_sf2_switch_driver = {
static struct dsa_switch_ops bcm_sf2_switch_ops = {
.setup = bcm_sf2_sw_setup,
.get_tag_protocol = bcm_sf2_sw_get_tag_protocol,
.set_addr = bcm_sf2_sw_set_addr,
......@@ -1632,7 +1632,7 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev)
priv = (struct bcm_sf2_priv *)(ds + 1);
ds->priv = priv;
ds->dev = &pdev->dev;
ds->drv = &bcm_sf2_switch_driver;
ds->ops = &bcm_sf2_switch_ops;
dev_set_drvdata(&pdev->dev, ds);
......
......@@ -252,7 +252,7 @@ mv88e6060_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val)
return reg_write(ds, addr, regnum, val);
}
static struct dsa_switch_driver mv88e6060_switch_driver = {
static struct dsa_switch_ops mv88e6060_switch_ops = {
.get_tag_protocol = mv88e6060_get_tag_protocol,
.probe = mv88e6060_drv_probe,
.setup = mv88e6060_setup,
......@@ -263,14 +263,14 @@ static struct dsa_switch_driver mv88e6060_switch_driver = {
static int __init mv88e6060_init(void)
{
register_switch_driver(&mv88e6060_switch_driver);
register_switch_driver(&mv88e6060_switch_ops);
return 0;
}
module_init(mv88e6060_init);
static void __exit mv88e6060_cleanup(void)
{
unregister_switch_driver(&mv88e6060_switch_driver);
unregister_switch_driver(&mv88e6060_switch_ops);
}
module_exit(mv88e6060_cleanup);
......
......@@ -3976,7 +3976,7 @@ static const char *mv88e6xxx_drv_probe(struct device *dsa_dev,
return NULL;
}
static struct dsa_switch_driver mv88e6xxx_switch_driver = {
static struct dsa_switch_ops mv88e6xxx_switch_ops = {
.probe = mv88e6xxx_drv_probe,
.get_tag_protocol = mv88e6xxx_get_tag_protocol,
.setup = mv88e6xxx_setup,
......@@ -4025,7 +4025,7 @@ static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip,
ds->dev = dev;
ds->priv = chip;
ds->drv = &mv88e6xxx_switch_driver;
ds->ops = &mv88e6xxx_switch_ops;
dev_set_drvdata(dev, ds);
......@@ -4118,7 +4118,7 @@ static struct mdio_driver mv88e6xxx_driver = {
static int __init mv88e6xxx_init(void)
{
register_switch_driver(&mv88e6xxx_switch_driver);
register_switch_driver(&mv88e6xxx_switch_ops);
return mdio_driver_register(&mv88e6xxx_driver);
}
module_init(mv88e6xxx_init);
......@@ -4126,7 +4126,7 @@ module_init(mv88e6xxx_init);
static void __exit mv88e6xxx_cleanup(void)
{
mdio_driver_unregister(&mv88e6xxx_driver);
unregister_switch_driver(&mv88e6xxx_switch_driver);
unregister_switch_driver(&mv88e6xxx_switch_ops);
}
module_exit(mv88e6xxx_cleanup);
......
......@@ -165,9 +165,9 @@ struct dsa_switch {
struct dsa_chip_data *cd;
/*
* The used switch driver.
* The switch operations.
*/
struct dsa_switch_driver *drv;
struct dsa_switch_ops *ops;
/*
* An array of which element [a] indicates which port on this
......@@ -236,7 +236,7 @@ struct switchdev_obj;
struct switchdev_obj_port_fdb;
struct switchdev_obj_port_vlan;
struct dsa_switch_driver {
struct dsa_switch_ops {
struct list_head list;
/*
......@@ -371,8 +371,8 @@ struct dsa_switch_driver {
int (*cb)(struct switchdev_obj *obj));
};
void register_switch_driver(struct dsa_switch_driver *type);
void unregister_switch_driver(struct dsa_switch_driver *type);
void register_switch_driver(struct dsa_switch_ops *type);
void unregister_switch_driver(struct dsa_switch_ops *type);
struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev);
static inline void *ds_to_priv(struct dsa_switch *ds)
......
......@@ -61,27 +61,27 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = {
static DEFINE_MUTEX(dsa_switch_drivers_mutex);
static LIST_HEAD(dsa_switch_drivers);
void register_switch_driver(struct dsa_switch_driver *drv)
void register_switch_driver(struct dsa_switch_ops *ops)
{
mutex_lock(&dsa_switch_drivers_mutex);
list_add_tail(&drv->list, &dsa_switch_drivers);
list_add_tail(&ops->list, &dsa_switch_drivers);
mutex_unlock(&dsa_switch_drivers_mutex);
}
EXPORT_SYMBOL_GPL(register_switch_driver);
void unregister_switch_driver(struct dsa_switch_driver *drv)
void unregister_switch_driver(struct dsa_switch_ops *ops)
{
mutex_lock(&dsa_switch_drivers_mutex);
list_del_init(&drv->list);
list_del_init(&ops->list);
mutex_unlock(&dsa_switch_drivers_mutex);
}
EXPORT_SYMBOL_GPL(unregister_switch_driver);
static struct dsa_switch_driver *
static struct dsa_switch_ops *
dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
const char **_name, void **priv)
{
struct dsa_switch_driver *ret;
struct dsa_switch_ops *ret;
struct list_head *list;
const char *name;
......@@ -90,13 +90,13 @@ dsa_switch_probe(struct device *parent, struct device *host_dev, int sw_addr,
mutex_lock(&dsa_switch_drivers_mutex);
list_for_each(list, &dsa_switch_drivers) {
struct dsa_switch_driver *drv;
struct dsa_switch_ops *ops;
drv = list_entry(list, struct dsa_switch_driver, list);
ops = list_entry(list, struct dsa_switch_ops, list);
name = drv->probe(parent, host_dev, sw_addr, priv);
name = ops->probe(parent, host_dev, sw_addr, priv);
if (name != NULL) {
ret = drv;
ret = ops;
break;
}
}
......@@ -117,7 +117,7 @@ static ssize_t temp1_input_show(struct device *dev,
struct dsa_switch *ds = dev_get_drvdata(dev);
int temp, ret;
ret = ds->drv->get_temp(ds, &temp);
ret = ds->ops->get_temp(ds, &temp);
if (ret < 0)
return ret;
......@@ -131,7 +131,7 @@ static ssize_t temp1_max_show(struct device *dev,
struct dsa_switch *ds = dev_get_drvdata(dev);
int temp, ret;
ret = ds->drv->get_temp_limit(ds, &temp);
ret = ds->ops->get_temp_limit(ds, &temp);
if (ret < 0)
return ret;
......@@ -149,7 +149,7 @@ static ssize_t temp1_max_store(struct device *dev,
if (ret < 0)
return ret;
ret = ds->drv->set_temp_limit(ds, DIV_ROUND_CLOSEST(temp, 1000));
ret = ds->ops->set_temp_limit(ds, DIV_ROUND_CLOSEST(temp, 1000));
if (ret < 0)
return ret;
......@@ -164,7 +164,7 @@ static ssize_t temp1_max_alarm_show(struct device *dev,
bool alarm;
int ret;
ret = ds->drv->get_temp_alarm(ds, &alarm);
ret = ds->ops->get_temp_alarm(ds, &alarm);
if (ret < 0)
return ret;
......@@ -184,15 +184,15 @@ static umode_t dsa_hwmon_attrs_visible(struct kobject *kobj,
{
struct device *dev = container_of(kobj, struct device, kobj);
struct dsa_switch *ds = dev_get_drvdata(dev);
struct dsa_switch_driver *drv = ds->drv;
struct dsa_switch_ops *ops = ds->ops;
umode_t mode = attr->mode;
if (index == 1) {
if (!drv->get_temp_limit)
if (!ops->get_temp_limit)
mode = 0;
else if (!drv->set_temp_limit)
else if (!ops->set_temp_limit)
mode &= ~S_IWUSR;
} else if (index == 2 && !drv->get_temp_alarm) {
} else if (index == 2 && !ops->get_temp_alarm) {
mode = 0;
}
return mode;
......@@ -228,8 +228,8 @@ int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
genphy_config_init(phydev);
genphy_read_status(phydev);
if (ds->drv->adjust_link)
ds->drv->adjust_link(ds, port, phydev);
if (ds->ops->adjust_link)
ds->ops->adjust_link(ds, port, phydev);
}
return 0;
......@@ -303,7 +303,7 @@ void dsa_cpu_port_ethtool_restore(struct dsa_switch *ds)
static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
{
struct dsa_switch_driver *drv = ds->drv;
struct dsa_switch_ops *ops = ds->ops;
struct dsa_switch_tree *dst = ds->dst;
struct dsa_chip_data *cd = ds->cd;
bool valid_name_found = false;
......@@ -356,7 +356,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
if (dst->cpu_switch == index) {
enum dsa_tag_protocol tag_protocol;
tag_protocol = drv->get_tag_protocol(ds);
tag_protocol = ops->get_tag_protocol(ds);
dst->tag_ops = dsa_resolve_tag_protocol(tag_protocol);
if (IS_ERR(dst->tag_ops)) {
ret = PTR_ERR(dst->tag_ops);
......@@ -371,15 +371,15 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
/*
* Do basic register setup.
*/
ret = drv->setup(ds);
ret = ops->setup(ds);
if (ret < 0)
goto out;
ret = drv->set_addr(ds, dst->master_netdev->dev_addr);
ret = ops->set_addr(ds, dst->master_netdev->dev_addr);
if (ret < 0)
goto out;
if (!ds->slave_mii_bus && drv->phy_read) {
if (!ds->slave_mii_bus && ops->phy_read) {
ds->slave_mii_bus = devm_mdiobus_alloc(parent);
if (!ds->slave_mii_bus) {
ret = -ENOMEM;
......@@ -426,7 +426,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
* register with hardware monitoring subsystem.
* Treat registration error as non-fatal and ignore it.
*/
if (drv->get_temp) {
if (ops->get_temp) {
const char *netname = netdev_name(dst->master_netdev);
char hname[IFNAMSIZ + 1];
int i, j;
......@@ -457,7 +457,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
struct device *parent, struct device *host_dev)
{
struct dsa_chip_data *cd = dst->pd->chip + index;
struct dsa_switch_driver *drv;
struct dsa_switch_ops *ops;
struct dsa_switch *ds;
int ret;
const char *name;
......@@ -466,8 +466,8 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
/*
* Probe for switch model.
*/
drv = dsa_switch_probe(parent, host_dev, cd->sw_addr, &name, &priv);
if (drv == NULL) {
ops = dsa_switch_probe(parent, host_dev, cd->sw_addr, &name, &priv);
if (!ops) {
netdev_err(dst->master_netdev, "[%d]: could not detect attached switch\n",
index);
return ERR_PTR(-EINVAL);
......@@ -486,7 +486,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
ds->dst = dst;
ds->index = index;
ds->cd = cd;
ds->drv = drv;
ds->ops = ops;
ds->priv = priv;
ds->dev = parent;
......@@ -541,7 +541,7 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
ds->dsa_port_mask |= ~(1 << port);
}
if (ds->slave_mii_bus && ds->drv->phy_read)
if (ds->slave_mii_bus && ds->ops->phy_read)
mdiobus_unregister(ds->slave_mii_bus);
}
......@@ -560,8 +560,8 @@ int dsa_switch_suspend(struct dsa_switch *ds)
return ret;
}
if (ds->drv->suspend)
ret = ds->drv->suspend(ds);
if (ds->ops->suspend)
ret = ds->ops->suspend(ds);
return ret;
}
......@@ -571,8 +571,8 @@ int dsa_switch_resume(struct dsa_switch *ds)
{
int i, ret = 0;
if (ds->drv->resume)
ret = ds->drv->resume(ds);
if (ds->ops->resume)
ret = ds->ops->resume(ds);
if (ret)
return ret;
......
......@@ -294,25 +294,25 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
int err;
/* Initialize ds->phys_mii_mask before registering the slave MDIO bus
* driver and before drv->setup() has run, since the switch drivers and
* driver and before ops->setup() has run, since the switch drivers and
* the slave MDIO bus driver rely on these values for probing PHY
* devices or not
*/
ds->phys_mii_mask = ds->enabled_port_mask;
err = ds->drv->setup(ds);
err = ds->ops->setup(ds);
if (err < 0)
return err;
err = ds->drv->set_addr(ds, dst->master_netdev->dev_addr);
err = ds->ops->set_addr(ds, dst->master_netdev->dev_addr);
if (err < 0)
return err;
err = ds->drv->set_addr(ds, dst->master_netdev->dev_addr);
err = ds->ops->set_addr(ds, dst->master_netdev->dev_addr);
if (err < 0)
return err;
if (!ds->slave_mii_bus && ds->drv->phy_read) {
if (!ds->slave_mii_bus && ds->ops->phy_read) {
ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev);
if (!ds->slave_mii_bus)
return -ENOMEM;
......@@ -374,7 +374,7 @@ static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
dsa_user_port_unapply(port, index, ds);
}
if (ds->slave_mii_bus && ds->drv->phy_read)
if (ds->slave_mii_bus && ds->ops->phy_read)
mdiobus_unregister(ds->slave_mii_bus);
}
......@@ -466,7 +466,7 @@ static int dsa_cpu_parse(struct device_node *port, u32 index,
dst->cpu_port = index;
}
tag_protocol = ds->drv->get_tag_protocol(ds);
tag_protocol = ds->ops->get_tag_protocol(ds);
dst->tag_ops = dsa_resolve_tag_protocol(tag_protocol);
if (IS_ERR(dst->tag_ops)) {
dev_warn(ds->dev, "No tagger for this switch\n");
......@@ -543,7 +543,7 @@ static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds)
ds->ports[reg].dn = port;
/* Initialize enabled_port_mask now for drv->setup()
/* Initialize enabled_port_mask now for ops->setup()
* to have access to a correct value, just like what
* net/dsa/dsa.c::dsa_switch_setup_one does.
*/
......
This diff is collapsed.
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