cregit-Linux how code gets into the kernel

Release 4.11 net/dsa/slave.c

Directory: net/dsa
/*
 * net/dsa/slave.c - Slave device handling
 * Copyright (c) 2008-2009 Marvell Semiconductor
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#include <linux/list.h>
#include <linux/etherdevice.h>
#include <linux/netdevice.h>
#include <linux/phy.h>
#include <linux/phy_fixed.h>
#include <linux/of_net.h>
#include <linux/of_mdio.h>
#include <linux/mdio.h>
#include <linux/list.h>
#include <net/rtnetlink.h>
#include <net/switchdev.h>
#include <net/pkt_cls.h>
#include <net/tc_act/tc_mirred.h>
#include <linux/if_bridge.h>
#include <linux/netpoll.h>
#include "dsa_priv.h"

static bool dsa_slave_dev_check(struct net_device *dev);


static int dsa_slave_notify(struct net_device *dev, unsigned long e, void *v) { struct dsa_slave_priv *p = netdev_priv(dev); struct raw_notifier_head *nh = &p->dp->ds->dst->nh; int err; err = raw_notifier_call_chain(nh, e, v); return notifier_to_errno(err); }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot65100.00%1100.00%
Total65100.00%1100.00%

/* slave mii_bus handling ***************************************************/
static int dsa_slave_phy_read(struct mii_bus *bus, int addr, int reg) { struct dsa_switch *ds = bus->priv; if (ds->phys_mii_mask & (1 << addr)) return ds->ops->phy_read(ds, addr, reg); return 0xffff; }

Contributors

PersonTokensPropCommitsCommitProp
Lennert Buytenhek5396.36%133.33%
Vivien Didelot11.82%133.33%
Florian Fainelli11.82%133.33%
Total55100.00%3100.00%


static int dsa_slave_phy_write(struct mii_bus *bus, int addr, int reg, u16 val) { struct dsa_switch *ds = bus->priv; if (ds->phys_mii_mask & (1 << addr)) return ds->ops->phy_write(ds, addr, reg, val); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Lennert Buytenhek5896.67%133.33%
Florian Fainelli11.67%133.33%
Vivien Didelot11.67%133.33%
Total60100.00%3100.00%


void dsa_slave_mii_bus_init(struct dsa_switch *ds) { ds->slave_mii_bus->priv = (void *)ds; ds->slave_mii_bus->name = "dsa slave smi"; ds->slave_mii_bus->read = dsa_slave_phy_read; ds->slave_mii_bus->write = dsa_slave_phy_write; snprintf(ds->slave_mii_bus->id, MII_BUS_ID_SIZE, "dsa-%d.%d", ds->dst->tree, ds->index); ds->slave_mii_bus->parent = ds->dev; ds->slave_mii_bus->phy_mask = ~ds->phys_mii_mask; }

Contributors

PersonTokensPropCommitsCommitProp
Lennert Buytenhek7077.78%120.00%
Vivien Didelot1112.22%120.00%
Florian Fainelli88.89%240.00%
Andrew Lunn11.11%120.00%
Total90100.00%5100.00%

/* slave device handling ****************************************************/
static int dsa_slave_get_iflink(const struct net_device *dev) { struct dsa_slave_priv *p = netdev_priv(dev); return p->dp->ds->dst->master_netdev->ifindex; }

Contributors

PersonTokensPropCommitsCommitProp
Lennert Buytenhek2982.86%250.00%
Nicolas Dichtel38.57%125.00%
Vivien Didelot38.57%125.00%
Total35100.00%4100.00%


static inline bool dsa_port_is_bridged(struct dsa_port *dp) { return !!dp->bridge_dev; }

Contributors

PersonTokensPropCommitsCommitProp
Florian Fainelli1684.21%150.00%
Vivien Didelot315.79%150.00%
Total19100.00%2100.00%


static void dsa_slave_set_state(struct net_device *dev, u8 state) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_port *dp = p->dp; struct dsa_switch *ds = dp->ds; int port = dp->index; if (ds->ops->port_stp_state_set) ds->ops->port_stp_state_set(ds, port, state); if (ds->ops->port_fast_age) { /* Fast age FDB entries or flush appropriate forwarding database * for the given port, if we are moving it from Learning or * Forwarding state, to Disabled or Blocking or Listening state. */ if ((dp->stp_state == BR_STATE_LEARNING || dp->stp_state == BR_STATE_FORWARDING) && (state == BR_STATE_DISABLED || state == BR_STATE_BLOCKING || state == BR_STATE_LISTENING)) ds->ops->port_fast_age(ds, port); } dp->stp_state = state; }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot128100.00%3100.00%
Total128100.00%3100.00%


static int dsa_slave_open(struct net_device *dev) { struct dsa_slave_priv *p = netdev_priv(dev); struct net_device *master = p->dp->ds->dst->master_netdev; struct dsa_switch *ds = p->dp->ds; u8 stp_state = dsa_port_is_bridged(p->dp) ? BR_STATE_BLOCKING : BR_STATE_FORWARDING; int err; if (!(master->flags & IFF_UP)) return -ENETDOWN; if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) { err = dev_uc_add(master, dev->dev_addr); if (err < 0) goto out; } if (dev->flags & IFF_ALLMULTI) { err = dev_set_allmulti(master, 1); if (err < 0) goto del_unicast; } if (dev->flags & IFF_PROMISC) { err = dev_set_promiscuity(master, 1); if (err < 0) goto clear_allmulti; } if (ds->ops->port_enable) { err = ds->ops->port_enable(ds, p->dp->index, p->phy); if (err) goto clear_promisc; } dsa_slave_set_state(dev, stp_state); if (p->phy) phy_start(p->phy); return 0; clear_promisc: if (dev->flags & IFF_PROMISC) dev_set_promiscuity(master, -1); clear_allmulti: if (dev->flags & IFF_ALLMULTI) dev_set_allmulti(master, -1); del_unicast: if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) dev_uc_del(master, dev->dev_addr); out: return err; }

Contributors

PersonTokensPropCommitsCommitProp
Lennert Buytenhek18863.09%323.08%
Florian Fainelli8729.19%323.08%
Vivien Didelot155.03%430.77%
Joe Perches41.34%17.69%
Gilad Ben-Yossef20.67%17.69%
Jiri Pirko20.67%17.69%
Total298100.00%13100.00%


static int dsa_slave_close(struct net_device *dev) { struct dsa_slave_priv *p = netdev_priv(dev); struct net_device *master = p->dp->ds->dst->master_netdev; struct dsa_switch *ds = p->dp->ds; if (p->phy) phy_stop(p->phy); dev_mc_unsync(master, dev); dev_uc_unsync(master, dev); if (dev->flags & IFF_ALLMULTI) dev_set_allmulti(master, -1); if (dev->flags & IFF_PROMISC) dev_set_promiscuity(master, -1); if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) dev_uc_del(master, dev->dev_addr); if (ds->ops->port_disable) ds->ops->port_disable(ds, p->dp->index, p->phy); dsa_slave_set_state(dev, BR_STATE_DISABLED); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Lennert Buytenhek10160.84%327.27%
Florian Fainelli4828.92%327.27%
Vivien Didelot137.83%327.27%
Jiri Pirko21.20%19.09%
Joe Perches21.20%19.09%
Total166100.00%11100.00%


static void dsa_slave_change_rx_flags(struct net_device *dev, int change) { struct dsa_slave_priv *p = netdev_priv(dev); struct net_device *master = p->dp->ds->dst->master_netdev; if (change & IFF_ALLMULTI) dev_set_allmulti(master, dev->flags & IFF_ALLMULTI ? 1 : -1); if (change & IFF_PROMISC) dev_set_promiscuity(master, dev->flags & IFF_PROMISC ? 1 : -1); }

Contributors

PersonTokensPropCommitsCommitProp
Lennert Buytenhek8096.39%266.67%
Vivien Didelot33.61%133.33%
Total83100.00%3100.00%


static void dsa_slave_set_rx_mode(struct net_device *dev) { struct dsa_slave_priv *p = netdev_priv(dev); struct net_device *master = p->dp->ds->dst->master_netdev; dev_mc_sync(master, dev); dev_uc_sync(master, dev); }

Contributors

PersonTokensPropCommitsCommitProp
Lennert Buytenhek4692.00%250.00%
Vivien Didelot36.00%125.00%
Jiri Pirko12.00%125.00%
Total50100.00%4100.00%


static int dsa_slave_set_mac_address(struct net_device *dev, void *a) { struct dsa_slave_priv *p = netdev_priv(dev); struct net_device *master = p->dp->ds->dst->master_netdev; struct sockaddr *addr = a; int err; if (!is_valid_ether_addr(addr->sa_data)) return -EADDRNOTAVAIL; if (!(dev->flags & IFF_UP)) goto out; if (!ether_addr_equal(addr->sa_data, master->dev_addr)) { err = dev_uc_add(master, addr->sa_data); if (err < 0) return err; } if (!ether_addr_equal(dev->dev_addr, master->dev_addr)) dev_uc_del(master, dev->dev_addr); out: ether_addr_copy(dev->dev_addr, addr->sa_data); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Lennert Buytenhek9964.71%342.86%
Florian Fainelli4831.37%114.29%
Vivien Didelot31.96%114.29%
Joe Perches21.31%114.29%
Jiri Pirko10.65%114.29%
Total153100.00%7100.00%


static int dsa_slave_port_vlan_add(struct net_device *dev, const struct switchdev_obj_port_vlan *vlan, struct switchdev_trans *trans) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_port *dp = p->dp; struct dsa_switch *ds = dp->ds; if (switchdev_trans_ph_prepare(trans)) { if (!ds->ops->port_vlan_prepare || !ds->ops->port_vlan_add) return -EOPNOTSUPP; return ds->ops->port_vlan_prepare(ds, dp->index, vlan, trans); } ds->ops->port_vlan_add(ds, dp->index, vlan, trans); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot10690.60%666.67%
Jiri Pirko119.40%333.33%
Total117100.00%9100.00%


static int dsa_slave_port_vlan_del(struct net_device *dev, const struct switchdev_obj_port_vlan *vlan) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_switch *ds = p->dp->ds; if (!ds->ops->port_vlan_del) return -EOPNOTSUPP; return ds->ops->port_vlan_del(ds, p->dp->index, vlan); }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot6898.55%583.33%
Jiri Pirko11.45%116.67%
Total69100.00%6100.00%


static int dsa_slave_port_vlan_dump(struct net_device *dev, struct switchdev_obj_port_vlan *vlan, switchdev_obj_dump_cb_t *cb) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_switch *ds = p->dp->ds; if (ds->ops->port_vlan_dump) return ds->ops->port_vlan_dump(ds, p->dp->index, vlan, cb); return -EOPNOTSUPP; }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot7197.26%571.43%
Jiri Pirko22.74%228.57%
Total73100.00%7100.00%


static int dsa_slave_port_fdb_add(struct net_device *dev, const struct switchdev_obj_port_fdb *fdb, struct switchdev_trans *trans) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_switch *ds = p->dp->ds; if (switchdev_trans_ph_prepare(trans)) { if (!ds->ops->port_fdb_prepare || !ds->ops->port_fdb_add) return -EOPNOTSUPP; return ds->ops->port_fdb_prepare(ds, p->dp->index, fdb, trans); } ds->ops->port_fdb_add(ds, p->dp->index, fdb, trans); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot6153.51%969.23%
Guenter Roeck3530.70%17.69%
David S. Miller1210.53%17.69%
Jiri Pirko65.26%215.38%
Total114100.00%13100.00%


static int dsa_slave_port_fdb_del(struct net_device *dev, const struct switchdev_obj_port_fdb *fdb) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_switch *ds = p->dp->ds; int ret = -EOPNOTSUPP; if (ds->ops->port_fdb_del) ret = ds->ops->port_fdb_del(ds, p->dp->index, fdb); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Guenter Roeck5574.32%114.29%
Vivien Didelot1824.32%571.43%
Jiri Pirko11.35%114.29%
Total74100.00%7100.00%


static int dsa_slave_port_fdb_dump(struct net_device *dev, struct switchdev_obj_port_fdb *fdb, switchdev_obj_dump_cb_t *cb) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_switch *ds = p->dp->ds; if (ds->ops->port_fdb_dump) return ds->ops->port_fdb_dump(ds, p->dp->index, fdb, cb); return -EOPNOTSUPP; }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot3649.32%555.56%
Guenter Roeck3345.21%111.11%
Jiri Pirko22.74%222.22%
David S. Miller22.74%111.11%
Total73100.00%9100.00%


static int dsa_slave_port_mdb_add(struct net_device *dev, const struct switchdev_obj_port_mdb *mdb, struct switchdev_trans *trans) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_switch *ds = p->dp->ds; if (switchdev_trans_ph_prepare(trans)) { if (!ds->ops->port_mdb_prepare || !ds->ops->port_mdb_add) return -EOPNOTSUPP; return ds->ops->port_mdb_prepare(ds, p->dp->index, mdb, trans); } ds->ops->port_mdb_add(ds, p->dp->index, mdb, trans); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot114100.00%2100.00%
Total114100.00%2100.00%


static int dsa_slave_port_mdb_del(struct net_device *dev, const struct switchdev_obj_port_mdb *mdb) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_switch *ds = p->dp->ds; if (ds->ops->port_mdb_del) return ds->ops->port_mdb_del(ds, p->dp->index, mdb); return -EOPNOTSUPP; }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot68100.00%2100.00%
Total68100.00%2100.00%


static int dsa_slave_port_mdb_dump(struct net_device *dev, struct switchdev_obj_port_mdb *mdb, switchdev_obj_dump_cb_t *cb) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_switch *ds = p->dp->ds; if (ds->ops->port_mdb_dump) return ds->ops->port_mdb_dump(ds, p->dp->index, mdb, cb); return -EOPNOTSUPP; }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot73100.00%2100.00%
Total73100.00%2100.00%


static int dsa_slave_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) { struct dsa_slave_priv *p = netdev_priv(dev); if (p->phy != NULL) return phy_mii_ioctl(p->phy, ifr, cmd); return -EOPNOTSUPP; }

Contributors

PersonTokensPropCommitsCommitProp
David S. Miller3158.49%150.00%
Florian Fainelli2241.51%150.00%
Total53100.00%2100.00%


static int dsa_slave_stp_state_set(struct net_device *dev, const struct switchdev_attr *attr, struct switchdev_trans *trans) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_switch *ds = p->dp->ds; if (switchdev_trans_ph_prepare(trans)) return ds->ops->port_stp_state_set ? 0 : -EOPNOTSUPP; dsa_slave_set_state(dev, attr->u.stp_state); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Florian Fainelli4052.63%120.00%
Vivien Didelot3647.37%480.00%
Total76100.00%5100.00%


static int dsa_slave_vlan_filtering(struct net_device *dev, const struct switchdev_attr *attr, struct switchdev_trans *trans) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_switch *ds = p->dp->ds; /* bridge skips -EOPNOTSUPP, so skip the prepare phase */ if (switchdev_trans_ph_prepare(trans)) return 0; if (ds->ops->port_vlan_filtering) return ds->ops->port_vlan_filtering(ds, p->dp->index, attr->u.vlan_filtering); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot87100.00%3100.00%
Total87100.00%3100.00%


static int dsa_fastest_ageing_time(struct dsa_switch *ds, unsigned int ageing_time) { int i; for (i = 0; i < ds->num_ports; ++i) { struct dsa_port *dp = &ds->ports[i]; if (dp && dp->ageing_time && dp->ageing_time < ageing_time) ageing_time = dp->ageing_time; } return ageing_time; }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot71100.00%2100.00%
Total71100.00%2100.00%


static int dsa_slave_ageing_time(struct net_device *dev, const struct switchdev_attr *attr, struct switchdev_trans *trans) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_switch *ds = p->dp->ds; unsigned long ageing_jiffies = clock_t_to_jiffies(attr->u.ageing_time); unsigned int ageing_time = jiffies_to_msecs(ageing_jiffies); /* bridge skips -EOPNOTSUPP, so skip the prepare phase */ if (switchdev_trans_ph_prepare(trans)) return 0; /* Keep the fastest ageing time in case of multiple bridges */ p->dp->ageing_time = ageing_time; ageing_time = dsa_fastest_ageing_time(ds, ageing_time); if (ds->ops->set_ageing_time) return ds->ops->set_ageing_time(ds, ageing_time); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot117100.00%3100.00%
Total117100.00%3100.00%


static int dsa_slave_port_attr_set(struct net_device *dev, const struct switchdev_attr *attr, struct switchdev_trans *trans) { int ret; switch (attr->id) { case SWITCHDEV_ATTR_ID_PORT_STP_STATE: ret = dsa_slave_stp_state_set(dev, attr, trans); break; case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING: ret = dsa_slave_vlan_filtering(dev, attr, trans); break; case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME: ret = dsa_slave_ageing_time(dev, attr, trans); break; default: ret = -EOPNOTSUPP; break; } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Scott Feldman3742.05%111.11%
Vivien Didelot3640.91%444.44%
David S. Miller89.09%111.11%
Jiri Pirko77.95%333.33%
Total88100.00%9100.00%


static int dsa_slave_port_obj_add(struct net_device *dev, const struct switchdev_obj *obj, struct switchdev_trans *trans) { int err; /* For the prepare phase, ensure the full set of changes is feasable in * one go in order to signal a failure properly. If an operation is not * supported, return -EOPNOTSUPP. */ switch (obj->id) { case SWITCHDEV_OBJ_ID_PORT_FDB: err = dsa_slave_port_fdb_add(dev, SWITCHDEV_OBJ_PORT_FDB(obj), trans); break; case SWITCHDEV_OBJ_ID_PORT_MDB: err = dsa_slave_port_mdb_add(dev, SWITCHDEV_OBJ_PORT_MDB(obj), trans); break; case SWITCHDEV_OBJ_ID_PORT_VLAN: err = dsa_slave_port_vlan_add(dev, SWITCHDEV_OBJ_PORT_VLAN(obj), trans); break; default: err = -EOPNOTSUPP; break; } return err; }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot7778.57%444.44%
Jiri Pirko2121.43%555.56%
Total98100.00%9100.00%


static int dsa_slave_port_obj_del(struct net_device *dev, const struct switchdev_obj *obj) { int err; switch (obj->id) { case SWITCHDEV_OBJ_ID_PORT_FDB: err = dsa_slave_port_fdb_del(dev, SWITCHDEV_OBJ_PORT_FDB(obj)); break; case SWITCHDEV_OBJ_ID_PORT_MDB: err = dsa_slave_port_mdb_del(dev, SWITCHDEV_OBJ_PORT_MDB(obj)); break; case SWITCHDEV_OBJ_ID_PORT_VLAN: err = dsa_slave_port_vlan_del(dev, SWITCHDEV_OBJ_PORT_VLAN(obj)); break; default: err = -EOPNOTSUPP; break; } return err; }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot7486.05%457.14%
Jiri Pirko1213.95%342.86%
Total86100.00%7100.00%


static int dsa_slave_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj, switchdev_obj_dump_cb_t *cb) { int err; switch (obj->id) { case SWITCHDEV_OBJ_ID_PORT_FDB: err = dsa_slave_port_fdb_dump(dev, SWITCHDEV_OBJ_PORT_FDB(obj), cb); break; case SWITCHDEV_OBJ_ID_PORT_MDB: err = dsa_slave_port_mdb_dump(dev, SWITCHDEV_OBJ_PORT_MDB(obj), cb); break; case SWITCHDEV_OBJ_ID_PORT_VLAN: err = dsa_slave_port_vlan_dump(dev, SWITCHDEV_OBJ_PORT_VLAN(obj), cb); break; default: err = -EOPNOTSUPP; break; } return err; }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot8286.32%457.14%
Jiri Pirko1313.68%342.86%
Total95100.00%7100.00%


static int dsa_slave_bridge_port_join(struct net_device *dev, struct net_device *br) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_notifier_bridge_info info = { .sw_index = p->dp->ds->index, .port = p->dp->index, .br = br, }; int err; /* Here the port is already bridged. Reflect the current configuration * so that drivers can program their chips accordingly. */ p->dp->bridge_dev = br; err = dsa_slave_notify(dev, DSA_NOTIFIER_BRIDGE_JOIN, &info); /* The bridging is rolled back on error */ if (err) p->dp->bridge_dev = NULL; return err; }

Contributors

PersonTokensPropCommitsCommitProp
Vivien Didelot5354.64%480.00%
Florian Fainelli4445.36%120.00%
Total97100.00%5100.00%


static void dsa_slave_bridge_port_leave(struct net_device *dev, struct net_device *br) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_notifier_bridge_info info = { .sw_index = p->dp->ds->index, .port = p->dp->index, .br = br, }; int err; /* Here the port is already unbridged. Reflect the current configuration * so that drivers can program their chips accordingly. */ p->dp->bridge_dev = NULL; err =