Skip to content

Commit

Permalink
Merge branch 'dsa_swqitch_ops-const'
Browse files Browse the repository at this point in the history
Florian Fainelli says:

====================
net: dsa: Make dsa_switch_ops const

This patch series allows us to annotate dsa_switch_ops with a const
qualifier.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jan 9, 2017
2 parents 1940075 + a82f67a commit 7351788
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 79 deletions.
81 changes: 47 additions & 34 deletions drivers/net/dsa/b53/b53_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ static unsigned int b53_get_mib_size(struct b53_device *dev)
return B53_MIBS_SIZE;
}

static void b53_get_strings(struct dsa_switch *ds, int port, uint8_t *data)
void b53_get_strings(struct dsa_switch *ds, int port, uint8_t *data)
{
struct b53_device *dev = ds->priv;
const struct b53_mib_desc *mibs = b53_get_mib(dev);
Expand All @@ -723,9 +723,9 @@ static void b53_get_strings(struct dsa_switch *ds, int port, uint8_t *data)
memcpy(data + i * ETH_GSTRING_LEN,
mibs[i].name, ETH_GSTRING_LEN);
}
EXPORT_SYMBOL(b53_get_strings);

static void b53_get_ethtool_stats(struct dsa_switch *ds, int port,
uint64_t *data)
void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data)
{
struct b53_device *dev = ds->priv;
const struct b53_mib_desc *mibs = b53_get_mib(dev);
Expand Down Expand Up @@ -756,13 +756,15 @@ static void b53_get_ethtool_stats(struct dsa_switch *ds, int port,

mutex_unlock(&dev->stats_mutex);
}
EXPORT_SYMBOL(b53_get_ethtool_stats);

static int b53_get_sset_count(struct dsa_switch *ds)
int b53_get_sset_count(struct dsa_switch *ds)
{
struct b53_device *dev = ds->priv;

return b53_get_mib_size(dev);
}
EXPORT_SYMBOL(b53_get_sset_count);

static int b53_setup(struct dsa_switch *ds)
{
Expand Down Expand Up @@ -921,15 +923,15 @@ static void b53_adjust_link(struct dsa_switch *ds, int port,
}
}

static int b53_vlan_filtering(struct dsa_switch *ds, int port,
bool vlan_filtering)
int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering)
{
return 0;
}
EXPORT_SYMBOL(b53_vlan_filtering);

static int b53_vlan_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan,
struct switchdev_trans *trans)
int b53_vlan_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan,
struct switchdev_trans *trans)
{
struct b53_device *dev = ds->priv;

Expand All @@ -943,10 +945,11 @@ static int b53_vlan_prepare(struct dsa_switch *ds, int port,

return 0;
}
EXPORT_SYMBOL(b53_vlan_prepare);

static void b53_vlan_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan,
struct switchdev_trans *trans)
void b53_vlan_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan,
struct switchdev_trans *trans)
{
struct b53_device *dev = ds->priv;
bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
Expand Down Expand Up @@ -977,9 +980,10 @@ static void b53_vlan_add(struct dsa_switch *ds, int port,
b53_fast_age_vlan(dev, vid);
}
}
EXPORT_SYMBOL(b53_vlan_add);

static int b53_vlan_del(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan)
int b53_vlan_del(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan)
{
struct b53_device *dev = ds->priv;
bool untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
Expand Down Expand Up @@ -1015,10 +1019,11 @@ static int b53_vlan_del(struct dsa_switch *ds, int port,

return 0;
}
EXPORT_SYMBOL(b53_vlan_del);

static int b53_vlan_dump(struct dsa_switch *ds, int port,
struct switchdev_obj_port_vlan *vlan,
int (*cb)(struct switchdev_obj *obj))
int b53_vlan_dump(struct dsa_switch *ds, int port,
struct switchdev_obj_port_vlan *vlan,
int (*cb)(struct switchdev_obj *obj))
{
struct b53_device *dev = ds->priv;
u16 vid, vid_start = 0, pvid;
Expand Down Expand Up @@ -1057,6 +1062,7 @@ static int b53_vlan_dump(struct dsa_switch *ds, int port,

return err;
}
EXPORT_SYMBOL(b53_vlan_dump);

/* Address Resolution Logic routines */
static int b53_arl_op_wait(struct b53_device *dev)
Expand Down Expand Up @@ -1175,9 +1181,9 @@ static int b53_arl_op(struct b53_device *dev, int op, int port,
return b53_arl_rw_op(dev, 0);
}

static int b53_fdb_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb,
struct switchdev_trans *trans)
int b53_fdb_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb,
struct switchdev_trans *trans)
{
struct b53_device *priv = ds->priv;

Expand All @@ -1189,24 +1195,27 @@ static int b53_fdb_prepare(struct dsa_switch *ds, int port,

return 0;
}
EXPORT_SYMBOL(b53_fdb_prepare);

static void b53_fdb_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb,
struct switchdev_trans *trans)
void b53_fdb_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb,
struct switchdev_trans *trans)
{
struct b53_device *priv = ds->priv;

if (b53_arl_op(priv, 0, port, fdb->addr, fdb->vid, true))
pr_err("%s: failed to add MAC address\n", __func__);
}
EXPORT_SYMBOL(b53_fdb_add);

static int b53_fdb_del(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb)
int b53_fdb_del(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb)
{
struct b53_device *priv = ds->priv;

return b53_arl_op(priv, 0, port, fdb->addr, fdb->vid, false);
}
EXPORT_SYMBOL(b53_fdb_del);

static int b53_arl_search_wait(struct b53_device *dev)
{
Expand Down Expand Up @@ -1258,9 +1267,9 @@ static int b53_fdb_copy(struct net_device *dev, int port,
return cb(&fdb->obj);
}

static int b53_fdb_dump(struct dsa_switch *ds, int port,
struct switchdev_obj_port_fdb *fdb,
int (*cb)(struct switchdev_obj *obj))
int b53_fdb_dump(struct dsa_switch *ds, int port,
struct switchdev_obj_port_fdb *fdb,
int (*cb)(struct switchdev_obj *obj))
{
struct b53_device *priv = ds->priv;
struct net_device *dev = ds->ports[port].netdev;
Expand Down Expand Up @@ -1297,9 +1306,9 @@ static int b53_fdb_dump(struct dsa_switch *ds, int port,

return 0;
}
EXPORT_SYMBOL(b53_fdb_dump);

static int b53_br_join(struct dsa_switch *ds, int port,
struct net_device *bridge)
int b53_br_join(struct dsa_switch *ds, int port, struct net_device *bridge)
{
struct b53_device *dev = ds->priv;
s8 cpu_port = ds->dst->cpu_port;
Expand Down Expand Up @@ -1343,8 +1352,9 @@ static int b53_br_join(struct dsa_switch *ds, int port,

return 0;
}
EXPORT_SYMBOL(b53_br_join);

static void b53_br_leave(struct dsa_switch *ds, int port)
void b53_br_leave(struct dsa_switch *ds, int port)
{
struct b53_device *dev = ds->priv;
struct net_device *bridge = dev->ports[port].bridge_dev;
Expand Down Expand Up @@ -1393,8 +1403,9 @@ static void b53_br_leave(struct dsa_switch *ds, int port)
b53_set_vlan_entry(dev, pvid, vl);
}
}
EXPORT_SYMBOL(b53_br_leave);

static void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state)
void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state)
{
struct b53_device *dev = ds->priv;
u8 hw_state;
Expand Down Expand Up @@ -1426,21 +1437,23 @@ static void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state)
reg |= hw_state;
b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg);
}
EXPORT_SYMBOL(b53_br_set_stp_state);

static void b53_br_fast_age(struct dsa_switch *ds, int port)
void b53_br_fast_age(struct dsa_switch *ds, int port)
{
struct b53_device *dev = ds->priv;

if (b53_fast_age_port(dev, port))
dev_err(ds->dev, "fast ageing failed\n");
}
EXPORT_SYMBOL(b53_br_fast_age);

static enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds)
{
return DSA_TAG_PROTO_NONE;
}

static struct dsa_switch_ops b53_switch_ops = {
static const struct dsa_switch_ops b53_switch_ops = {
.get_tag_protocol = b53_get_tag_protocol,
.setup = b53_setup,
.get_strings = b53_get_strings,
Expand Down
33 changes: 33 additions & 0 deletions drivers/net/dsa/b53/b53_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,37 @@ static inline int b53_switch_get_reset_gpio(struct b53_device *dev)
return -ENOENT;
}
#endif

/* Exported functions towards other drivers */
void b53_get_strings(struct dsa_switch *ds, int port, uint8_t *data);
void b53_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data);
int b53_get_sset_count(struct dsa_switch *ds);
int b53_br_join(struct dsa_switch *ds, int port, struct net_device *bridge);
void b53_br_leave(struct dsa_switch *ds, int port);
void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state);
void b53_br_fast_age(struct dsa_switch *ds, int port);
int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering);
int b53_vlan_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan,
struct switchdev_trans *trans);
void b53_vlan_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan,
struct switchdev_trans *trans);
int b53_vlan_del(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan);
int b53_vlan_dump(struct dsa_switch *ds, int port,
struct switchdev_obj_port_vlan *vlan,
int (*cb)(struct switchdev_obj *obj));
int b53_fdb_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb,
struct switchdev_trans *trans);
void b53_fdb_add(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb,
struct switchdev_trans *trans);
int b53_fdb_del(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_fdb *fdb);
int b53_fdb_dump(struct dsa_switch *ds, int port,
struct switchdev_obj_port_fdb *fdb,
int (*cb)(struct switchdev_obj *obj));

#endif
55 changes: 33 additions & 22 deletions drivers/net/dsa/bcm_sf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,38 @@ static struct b53_io_ops bcm_sf2_io_ops = {
.write64 = bcm_sf2_core_write64,
};

static const struct dsa_switch_ops bcm_sf2_ops = {
.get_tag_protocol = bcm_sf2_sw_get_tag_protocol,
.setup = bcm_sf2_sw_setup,
.get_strings = b53_get_strings,
.get_ethtool_stats = b53_get_ethtool_stats,
.get_sset_count = b53_get_sset_count,
.get_phy_flags = bcm_sf2_sw_get_phy_flags,
.adjust_link = bcm_sf2_sw_adjust_link,
.fixed_link_update = bcm_sf2_sw_fixed_link_update,
.suspend = bcm_sf2_sw_suspend,
.resume = bcm_sf2_sw_resume,
.get_wol = bcm_sf2_sw_get_wol,
.set_wol = bcm_sf2_sw_set_wol,
.port_enable = bcm_sf2_port_setup,
.port_disable = bcm_sf2_port_disable,
.get_eee = bcm_sf2_sw_get_eee,
.set_eee = bcm_sf2_sw_set_eee,
.port_bridge_join = b53_br_join,
.port_bridge_leave = b53_br_leave,
.port_stp_state_set = b53_br_set_stp_state,
.port_fast_age = b53_br_fast_age,
.port_vlan_filtering = b53_vlan_filtering,
.port_vlan_prepare = b53_vlan_prepare,
.port_vlan_add = b53_vlan_add,
.port_vlan_del = b53_vlan_del,
.port_vlan_dump = b53_vlan_dump,
.port_fdb_prepare = b53_fdb_prepare,
.port_fdb_dump = b53_fdb_dump,
.port_fdb_add = b53_fdb_add,
.port_fdb_del = b53_fdb_del,
};

static int bcm_sf2_sw_probe(struct platform_device *pdev)
{
const char *reg_names[BCM_SF2_REGS_NUM] = BCM_SF2_REGS_NAME;
Expand Down Expand Up @@ -1017,28 +1049,7 @@ static int bcm_sf2_sw_probe(struct platform_device *pdev)

priv->dev = dev;
ds = dev->ds;

/* Override the parts that are non-standard wrt. normal b53 devices */
memcpy(ops, ds->ops, sizeof(*ops));
ds->ops = ops;
ds->ops->get_tag_protocol = bcm_sf2_sw_get_tag_protocol;
ds->ops->setup = bcm_sf2_sw_setup;
ds->ops->get_phy_flags = bcm_sf2_sw_get_phy_flags;
ds->ops->adjust_link = bcm_sf2_sw_adjust_link;
ds->ops->fixed_link_update = bcm_sf2_sw_fixed_link_update;
ds->ops->suspend = bcm_sf2_sw_suspend;
ds->ops->resume = bcm_sf2_sw_resume;
ds->ops->get_wol = bcm_sf2_sw_get_wol;
ds->ops->set_wol = bcm_sf2_sw_set_wol;
ds->ops->port_enable = bcm_sf2_port_setup;
ds->ops->port_disable = bcm_sf2_port_disable;
ds->ops->get_eee = bcm_sf2_sw_get_eee;
ds->ops->set_eee = bcm_sf2_sw_set_eee;

/* Avoid having DSA free our slave MDIO bus (checking for
* ds->slave_mii_bus and ds->ops->phy_read being non-NULL)
*/
ds->ops->phy_read = NULL;
ds->ops = &bcm_sf2_ops;

dev_set_drvdata(&pdev->dev, priv);

Expand Down
10 changes: 7 additions & 3 deletions drivers/net/dsa/mv88e6060.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_ops mv88e6060_switch_ops = {
static const struct dsa_switch_ops mv88e6060_switch_ops = {
.get_tag_protocol = mv88e6060_get_tag_protocol,
.probe = mv88e6060_drv_probe,
.setup = mv88e6060_setup,
Expand All @@ -261,16 +261,20 @@ static struct dsa_switch_ops mv88e6060_switch_ops = {
.phy_write = mv88e6060_phy_write,
};

static struct dsa_switch_driver mv88e6060_switch_drv = {
.ops = &mv88e6060_switch_ops,
};

static int __init mv88e6060_init(void)
{
register_switch_driver(&mv88e6060_switch_ops);
register_switch_driver(&mv88e6060_switch_drv);
return 0;
}
module_init(mv88e6060_init);

static void __exit mv88e6060_cleanup(void)
{
unregister_switch_driver(&mv88e6060_switch_ops);
unregister_switch_driver(&mv88e6060_switch_drv);
}
module_exit(mv88e6060_cleanup);

Expand Down
Loading

0 comments on commit 7351788

Please sign in to comment.