cregit-Linux how code gets into the kernel

Release 4.8 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 <net/rtnetlink.h>
#include <net/switchdev.h>
#include <linux/if_bridge.h>
#include <linux/netpoll.h>
#include "dsa_priv.h"

/* 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->drv->phy_read(ds, addr, reg); return 0xffff; }

Contributors

PersonTokensPropCommitsCommitProp
lennert buytenheklennert buytenhek5498.18%150.00%
florian fainelliflorian fainelli11.82%150.00%
Total55100.00%2100.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->drv->phy_write(ds, addr, reg, val); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
lennert buytenheklennert buytenhek5998.33%150.00%
florian fainelliflorian fainelli11.67%150.00%
Total60100.00%2100.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 buytenheklennert buytenhek7077.78%120.00%
vivien didelotvivien didelot1112.22%120.00%
florian fainelliflorian fainelli88.89%240.00%
andrew lunnandrew 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->parent->dst->master_netdev->ifindex; }

Contributors

PersonTokensPropCommitsCommitProp
lennert buytenheklennert buytenhek3090.91%266.67%
nicolas dichtelnicolas dichtel39.09%133.33%
Total33100.00%3100.00%


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

Contributors

PersonTokensPropCommitsCommitProp
florian fainelliflorian fainelli19100.00%1100.00%
Total19100.00%1100.00%


static int dsa_slave_open(struct net_device *dev) { struct dsa_slave_priv *p = netdev_priv(dev); struct net_device *master = p->parent->dst->master_netdev; struct dsa_switch *ds = p->parent; u8 stp_state = dsa_port_is_bridged(p) ? 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->drv->port_enable) { err = ds->drv->port_enable(ds, p->port, p->phy); if (err) goto clear_promisc; } if (ds->drv->port_stp_state_set) ds->drv->port_stp_state_set(ds, p->port, 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 buytenheklennert buytenhek18961.76%330.00%
florian fainelliflorian fainelli10734.97%330.00%
joe perchesjoe perches41.31%110.00%
gilad ben-yossefgilad ben-yossef20.65%110.00%
vivien didelotvivien didelot20.65%110.00%
jiri pirkojiri pirko20.65%110.00%
Total306100.00%10100.00%


static int dsa_slave_close(struct net_device *dev) { struct dsa_slave_priv *p = netdev_priv(dev); struct net_device *master = p->parent->dst->master_netdev; struct dsa_switch *ds = p->parent; 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->drv->port_disable) ds->drv->port_disable(ds, p->port, p->phy); if (ds->drv->port_stp_state_set) ds->drv->port_stp_state_set(ds, p->port, BR_STATE_DISABLED); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
lennert buytenheklennert buytenhek10257.95%333.33%
florian fainelliflorian fainelli6838.64%333.33%
jiri pirkojiri pirko21.14%111.11%
vivien didelotvivien didelot21.14%111.11%
joe perchesjoe perches21.14%111.11%
Total176100.00%9100.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->parent->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 buytenheklennert buytenhek81100.00%2100.00%
Total81100.00%2100.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->parent->dst->master_netdev; dev_mc_sync(master, dev); dev_uc_sync(master, dev); }

Contributors

PersonTokensPropCommitsCommitProp
lennert buytenheklennert buytenhek4797.92%266.67%
jiri pirkojiri pirko12.08%133.33%
Total48100.00%3100.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->parent->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 buytenheklennert buytenhek10066.23%350.00%
florian fainelliflorian fainelli4831.79%116.67%
joe perchesjoe perches21.32%116.67%
jiri pirkojiri pirko10.66%116.67%
Total151100.00%6100.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_switch *ds = p->parent; if (switchdev_trans_ph_prepare(trans)) { if (!ds->drv->port_vlan_prepare || !ds->drv->port_vlan_add) return -EOPNOTSUPP; return ds->drv->port_vlan_prepare(ds, p->port, vlan, trans); } ds->drv->port_vlan_add(ds, p->port, vlan, trans); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
vivien didelotvivien didelot9789.81%457.14%
jiri pirkojiri pirko1110.19%342.86%
Total108100.00%7100.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->parent; if (!ds->drv->port_vlan_del) return -EOPNOTSUPP; return ds->drv->port_vlan_del(ds, p->port, vlan); }

Contributors

PersonTokensPropCommitsCommitProp
vivien didelotvivien didelot6498.46%375.00%
jiri pirkojiri pirko11.54%125.00%
Total65100.00%4100.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->parent; if (ds->drv->port_vlan_dump) return ds->drv->port_vlan_dump(ds, p->port, vlan, cb); return -EOPNOTSUPP; }

Contributors

PersonTokensPropCommitsCommitProp
vivien didelotvivien didelot6797.10%360.00%
jiri pirkojiri pirko22.90%240.00%
Total69100.00%5100.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->parent; if (switchdev_trans_ph_prepare(trans)) { if (!ds->drv->port_fdb_prepare || !ds->drv->port_fdb_add) return -EOPNOTSUPP; return ds->drv->port_fdb_prepare(ds, p->port, fdb, trans); } ds->drv->port_fdb_add(ds, p->port, fdb, trans); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
vivien didelotvivien didelot5147.22%763.64%
guenter roeckguenter roeck3633.33%19.09%
david s. millerdavid s. miller1513.89%19.09%
jiri pirkojiri pirko65.56%218.18%
Total108100.00%11100.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->parent; int ret = -EOPNOTSUPP; if (ds->drv->port_fdb_del) ret = ds->drv->port_fdb_del(ds, p->port, fdb); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
guenter roeckguenter roeck5984.29%120.00%
vivien didelotvivien didelot1014.29%360.00%
jiri pirkojiri pirko11.43%120.00%
Total70100.00%5100.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->parent; if (ds->drv->port_fdb_dump) return ds->drv->port_fdb_dump(ds, p->port, fdb, cb); return -EOPNOTSUPP; }

Contributors

PersonTokensPropCommitsCommitProp
guenter roeckguenter roeck3449.28%114.29%
vivien didelotvivien didelot3144.93%342.86%
david s. millerdavid s. miller22.90%114.29%
jiri pirkojiri pirko22.90%228.57%
Total69100.00%7100.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. millerdavid s. miller3158.49%150.00%
florian fainelliflorian 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->parent; if (switchdev_trans_ph_prepare(trans)) return ds->drv->port_stp_state_set ? 0 : -EOPNOTSUPP; ds->drv->port_stp_state_set(ds, p->port, attr->u.stp_state); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
florian fainelliflorian fainelli5162.20%150.00%
vivien didelotvivien didelot3137.80%150.00%
Total82100.00%2100.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->parent; /* bridge skips -EOPNOTSUPP, so skip the prepare phase */ if (switchdev_trans_ph_prepare(trans)) return 0; if (ds->drv->port_vlan_filtering) return ds->drv->port_vlan_filtering(ds, p->port, attr->u.vlan_filtering); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
vivien didelotvivien didelot83100.00%1100.00%
Total83100.00%1100.00%


static int dsa_fastest_ageing_time(struct dsa_switch *ds, unsigned int ageing_time) { int i; for (i = 0; i < DSA_MAX_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 didelotvivien didelot69100.00%1100.00%
Total69100.00%1100.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->parent; 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 */ ds->ports[p->port].ageing_time = ageing_time; ageing_time = dsa_fastest_ageing_time(ds, ageing_time); if (ds->drv->set_ageing_time) return ds->drv->set_ageing_time(ds, ageing_time); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
vivien didelotvivien didelot120100.00%1100.00%
Total120100.00%1100.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 feldmanscott feldman3742.05%111.11%
vivien didelotvivien didelot3640.91%444.44%
david s. millerdavid s. miller89.09%111.11%
jiri pirkojiri 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_VLAN: err = dsa_slave_port_vlan_add(dev, SWITCHDEV_OBJ_PORT_VLAN(obj), trans); break; default: err = -EOPNOTSUPP; break; } return err; }

Contributors

PersonTokensPropCommitsCommitProp
vivien didelotvivien didelot5973.75%337.50%
jiri pirkojiri pirko2126.25%562.50%
Total80100.00%8100.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_VLAN: err = dsa_slave_port_vlan_del(dev, SWITCHDEV_OBJ_PORT_VLAN(obj)); break; default: err = -EOPNOTSUPP; break; } return err; }

Contributors

PersonTokensPropCommitsCommitProp
vivien didelotvivien didelot5882.86%350.00%
jiri pirkojiri pirko1217.14%350.00%
Total70100.00%6100.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_VLAN: err = dsa_slave_port_vlan_dump(dev, SWITCHDEV_OBJ_PORT_VLAN(obj), cb); break; default: err = -EOPNOTSUPP; break; } return err; }

Contributors

PersonTokensPropCommitsCommitProp
vivien didelotvivien didelot6483.12%350.00%
jiri pirkojiri pirko1316.88%350.00%
Total77100.00%6100.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_switch *ds = p->parent; int ret = -EOPNOTSUPP; p->bridge_dev = br; if (ds->drv->port_bridge_join) ret = ds->drv->port_bridge_join(ds, p->port, br); return ret == -EOPNOTSUPP ? 0 : ret; }

Contributors

PersonTokensPropCommitsCommitProp
florian fainelliflorian fainelli7389.02%133.33%
vivien didelotvivien didelot910.98%266.67%
Total82100.00%3100.00%


static void dsa_slave_bridge_port_leave(struct net_device *dev) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_switch *ds = p->parent; if (ds->drv->port_bridge_leave) ds->drv->port_bridge_leave(ds, p->port); p->bridge_dev = NULL; /* Port left the bridge, put in BR_STATE_DISABLED by the bridge layer, * so allow it to be in BR_STATE_FORWARDING to be kept functional */ if (ds->drv->port_stp_state_set) ds->drv->port_stp_state_set(ds, p->port, BR_STATE_FORWARDING); }

Contributors

PersonTokensPropCommitsCommitProp
florian fainelliflorian fainelli4960.49%116.67%
vivien didelotvivien didelot2125.93%350.00%
lennert buytenheklennert buytenhek1113.58%233.33%
Total81100.00%6100.00%


static int dsa_slave_port_attr_get(struct net_device *dev, struct switchdev_attr *attr) { struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_switch *ds = p->parent; switch (attr->id) { case SWITCHDEV_ATTR_ID_PORT_PARENT_ID: attr->u.ppid.id_len = sizeof(ds->index); memcpy(&attr->u.ppid.id, &ds->index, attr->u.ppid.id_len); break; default: return -EOPNOTSUPP; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
scott feldmanscott feldman3435.79%240.00%
lennert buytenheklennert buytenhek3233.68%120.00%
florian fainelliflorian fainelli2829.47%120.00%
jiri pirkojiri pirko11.05%120.00%
Total95100.00%5100.00%


static inline netdev_tx_t dsa_netpoll_send_skb(struct dsa_slave_priv *p, struct sk_buff *skb) { #ifdef CONFIG_NET_POLL_CONTROLLER if (p->netpoll) netpoll_send_skb(p->netpoll, skb); #else BUG(); #endif return NETDEV_TX_OK; }

Contributors

PersonTokensPropCommitsCommitProp
florian fainelliflorian fainelli45100.00%1100.00%
Total45100.00%1100.00%


static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev) { struct dsa_slave_priv *p = netdev_priv(dev); struct sk_buff *nskb; dev->stats.tx_packets++; dev->stats.tx_bytes += skb->len; /* Transmit function may have to reallocate the original SKB */ nskb = p->xmit(skb, dev); if (!nskb) return NETDEV_TX_OK; /* SKB for netpoll still need to be mangled with the protocol-specific * tag to be successfully transmitted */ if (unlikely(netpoll_tx_running(dev))) return dsa_netpoll_send_skb(p, nskb); /* Queue the SKB for transmission on the parent interface, but * do not modify its EtherType */ nskb->dev = p->parent->dst->master_netdev; dev_queue_xmit(nskb); return NETDEV_TX_OK; }

Contributors

PersonTokensPropCommitsCommitProp
florian fainelliflorian fainelli10799.07%375.00%
alexander duyckalexander duyck10.93%125.00%
Total108100.00%4100.00%

/* ethtool operations *******************************************************/
static int dsa_slave_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) { struct dsa_slave_priv *p = netdev_priv(dev); int err; err = -EOPNOTSUPP; if (p->phy != NULL) { err = phy_read_status(p->phy); if (err == 0) err = phy_ethtool_gset(p->phy, cmd); } return err; }

Contributors

PersonTokensPropCommitsCommitProp
lennert buytenheklennert buytenhek73100.00%1100.00%
Total73100.00%1100.00%


static int dsa_slave_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) { struct dsa_slave_priv *p = netdev_priv(dev); if (p->phy != NULL) return phy_ethtool_sset(p->phy, cmd); return -EOPNOTSUPP; }

Contributors

PersonTokensPropCommitsCommitProp
lennert buytenheklennert buytenhek48100.00%1100.00%
Total48100.00%1100.00%


static void dsa_slave_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo) { strlcpy(drvinfo->driver, "dsa", sizeof(drvinfo->driver)); strlcpy(drvinfo