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

net: dsa: store a dsa_port in dsa_slave_priv

Store a pointer to the dsa_port structure in the dsa_slave_priv
structure, instead of the switch/port index.

This will allow to store more information such as the bridge device,
needed in DSA drivers for multi-chip configuration.
Signed-off-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 818be848
...@@ -25,12 +25,8 @@ struct dsa_slave_priv { ...@@ -25,12 +25,8 @@ struct dsa_slave_priv {
struct sk_buff * (*xmit)(struct sk_buff *skb, struct sk_buff * (*xmit)(struct sk_buff *skb,
struct net_device *dev); struct net_device *dev);
/* /* DSA port data, such as switch, port index, etc. */
* Which switch this port is a part of, and the port index struct dsa_port *dp;
* for this port.
*/
struct dsa_switch *parent;
u8 port;
/* /*
* The phylib phy_device pointer for the PHY connected * The phylib phy_device pointer for the PHY connected
......
...@@ -61,7 +61,7 @@ static int dsa_slave_get_iflink(const struct net_device *dev) ...@@ -61,7 +61,7 @@ static int dsa_slave_get_iflink(const struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
return p->parent->dst->master_netdev->ifindex; return p->dp->ds->dst->master_netdev->ifindex;
} }
static inline bool dsa_port_is_bridged(struct dsa_slave_priv *p) static inline bool dsa_port_is_bridged(struct dsa_slave_priv *p)
...@@ -96,8 +96,8 @@ static void dsa_port_set_stp_state(struct dsa_switch *ds, int port, u8 state) ...@@ -96,8 +96,8 @@ static void dsa_port_set_stp_state(struct dsa_switch *ds, int port, u8 state)
static int dsa_slave_open(struct net_device *dev) static int dsa_slave_open(struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct net_device *master = p->parent->dst->master_netdev; struct net_device *master = p->dp->ds->dst->master_netdev;
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
u8 stp_state = dsa_port_is_bridged(p) ? u8 stp_state = dsa_port_is_bridged(p) ?
BR_STATE_BLOCKING : BR_STATE_FORWARDING; BR_STATE_BLOCKING : BR_STATE_FORWARDING;
int err; int err;
...@@ -123,12 +123,12 @@ static int dsa_slave_open(struct net_device *dev) ...@@ -123,12 +123,12 @@ static int dsa_slave_open(struct net_device *dev)
} }
if (ds->ops->port_enable) { if (ds->ops->port_enable) {
err = ds->ops->port_enable(ds, p->port, p->phy); err = ds->ops->port_enable(ds, p->dp->index, p->phy);
if (err) if (err)
goto clear_promisc; goto clear_promisc;
} }
dsa_port_set_stp_state(ds, p->port, stp_state); dsa_port_set_stp_state(ds, p->dp->index, stp_state);
if (p->phy) if (p->phy)
phy_start(p->phy); phy_start(p->phy);
...@@ -151,8 +151,8 @@ static int dsa_slave_open(struct net_device *dev) ...@@ -151,8 +151,8 @@ static int dsa_slave_open(struct net_device *dev)
static int dsa_slave_close(struct net_device *dev) static int dsa_slave_close(struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct net_device *master = p->parent->dst->master_netdev; struct net_device *master = p->dp->ds->dst->master_netdev;
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (p->phy) if (p->phy)
phy_stop(p->phy); phy_stop(p->phy);
...@@ -168,9 +168,9 @@ static int dsa_slave_close(struct net_device *dev) ...@@ -168,9 +168,9 @@ static int dsa_slave_close(struct net_device *dev)
dev_uc_del(master, dev->dev_addr); dev_uc_del(master, dev->dev_addr);
if (ds->ops->port_disable) if (ds->ops->port_disable)
ds->ops->port_disable(ds, p->port, p->phy); ds->ops->port_disable(ds, p->dp->index, p->phy);
dsa_port_set_stp_state(ds, p->port, BR_STATE_DISABLED); dsa_port_set_stp_state(ds, p->dp->index, BR_STATE_DISABLED);
return 0; return 0;
} }
...@@ -178,7 +178,7 @@ static int dsa_slave_close(struct net_device *dev) ...@@ -178,7 +178,7 @@ static int dsa_slave_close(struct net_device *dev)
static void dsa_slave_change_rx_flags(struct net_device *dev, int change) static void dsa_slave_change_rx_flags(struct net_device *dev, int change)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct net_device *master = p->parent->dst->master_netdev; struct net_device *master = p->dp->ds->dst->master_netdev;
if (change & IFF_ALLMULTI) if (change & IFF_ALLMULTI)
dev_set_allmulti(master, dev->flags & IFF_ALLMULTI ? 1 : -1); dev_set_allmulti(master, dev->flags & IFF_ALLMULTI ? 1 : -1);
...@@ -189,7 +189,7 @@ static void dsa_slave_change_rx_flags(struct net_device *dev, int change) ...@@ -189,7 +189,7 @@ static void dsa_slave_change_rx_flags(struct net_device *dev, int change)
static void dsa_slave_set_rx_mode(struct net_device *dev) static void dsa_slave_set_rx_mode(struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct net_device *master = p->parent->dst->master_netdev; struct net_device *master = p->dp->ds->dst->master_netdev;
dev_mc_sync(master, dev); dev_mc_sync(master, dev);
dev_uc_sync(master, dev); dev_uc_sync(master, dev);
...@@ -198,7 +198,7 @@ static void dsa_slave_set_rx_mode(struct net_device *dev) ...@@ -198,7 +198,7 @@ static void dsa_slave_set_rx_mode(struct net_device *dev)
static int dsa_slave_set_mac_address(struct net_device *dev, void *a) static int dsa_slave_set_mac_address(struct net_device *dev, void *a)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct net_device *master = p->parent->dst->master_netdev; struct net_device *master = p->dp->ds->dst->master_netdev;
struct sockaddr *addr = a; struct sockaddr *addr = a;
int err; int err;
...@@ -228,16 +228,17 @@ static int dsa_slave_port_vlan_add(struct net_device *dev, ...@@ -228,16 +228,17 @@ static int dsa_slave_port_vlan_add(struct net_device *dev,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_port *dp = p->dp;
struct dsa_switch *ds = dp->ds;
if (switchdev_trans_ph_prepare(trans)) { if (switchdev_trans_ph_prepare(trans)) {
if (!ds->ops->port_vlan_prepare || !ds->ops->port_vlan_add) if (!ds->ops->port_vlan_prepare || !ds->ops->port_vlan_add)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return ds->ops->port_vlan_prepare(ds, p->port, vlan, trans); return ds->ops->port_vlan_prepare(ds, dp->index, vlan, trans);
} }
ds->ops->port_vlan_add(ds, p->port, vlan, trans); ds->ops->port_vlan_add(ds, dp->index, vlan, trans);
return 0; return 0;
} }
...@@ -246,12 +247,12 @@ static int dsa_slave_port_vlan_del(struct net_device *dev, ...@@ -246,12 +247,12 @@ static int dsa_slave_port_vlan_del(struct net_device *dev,
const struct switchdev_obj_port_vlan *vlan) const struct switchdev_obj_port_vlan *vlan)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (!ds->ops->port_vlan_del) if (!ds->ops->port_vlan_del)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return ds->ops->port_vlan_del(ds, p->port, vlan); return ds->ops->port_vlan_del(ds, p->dp->index, vlan);
} }
static int dsa_slave_port_vlan_dump(struct net_device *dev, static int dsa_slave_port_vlan_dump(struct net_device *dev,
...@@ -259,10 +260,10 @@ static int dsa_slave_port_vlan_dump(struct net_device *dev, ...@@ -259,10 +260,10 @@ static int dsa_slave_port_vlan_dump(struct net_device *dev,
switchdev_obj_dump_cb_t *cb) switchdev_obj_dump_cb_t *cb)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (ds->ops->port_vlan_dump) if (ds->ops->port_vlan_dump)
return ds->ops->port_vlan_dump(ds, p->port, vlan, cb); return ds->ops->port_vlan_dump(ds, p->dp->index, vlan, cb);
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -272,16 +273,16 @@ static int dsa_slave_port_fdb_add(struct net_device *dev, ...@@ -272,16 +273,16 @@ static int dsa_slave_port_fdb_add(struct net_device *dev,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (switchdev_trans_ph_prepare(trans)) { if (switchdev_trans_ph_prepare(trans)) {
if (!ds->ops->port_fdb_prepare || !ds->ops->port_fdb_add) if (!ds->ops->port_fdb_prepare || !ds->ops->port_fdb_add)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return ds->ops->port_fdb_prepare(ds, p->port, fdb, trans); return ds->ops->port_fdb_prepare(ds, p->dp->index, fdb, trans);
} }
ds->ops->port_fdb_add(ds, p->port, fdb, trans); ds->ops->port_fdb_add(ds, p->dp->index, fdb, trans);
return 0; return 0;
} }
...@@ -290,11 +291,11 @@ static int dsa_slave_port_fdb_del(struct net_device *dev, ...@@ -290,11 +291,11 @@ static int dsa_slave_port_fdb_del(struct net_device *dev,
const struct switchdev_obj_port_fdb *fdb) const struct switchdev_obj_port_fdb *fdb)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
int ret = -EOPNOTSUPP; int ret = -EOPNOTSUPP;
if (ds->ops->port_fdb_del) if (ds->ops->port_fdb_del)
ret = ds->ops->port_fdb_del(ds, p->port, fdb); ret = ds->ops->port_fdb_del(ds, p->dp->index, fdb);
return ret; return ret;
} }
...@@ -304,10 +305,10 @@ static int dsa_slave_port_fdb_dump(struct net_device *dev, ...@@ -304,10 +305,10 @@ static int dsa_slave_port_fdb_dump(struct net_device *dev,
switchdev_obj_dump_cb_t *cb) switchdev_obj_dump_cb_t *cb)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (ds->ops->port_fdb_dump) if (ds->ops->port_fdb_dump)
return ds->ops->port_fdb_dump(ds, p->port, fdb, cb); return ds->ops->port_fdb_dump(ds, p->dp->index, fdb, cb);
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -317,16 +318,16 @@ static int dsa_slave_port_mdb_add(struct net_device *dev, ...@@ -317,16 +318,16 @@ static int dsa_slave_port_mdb_add(struct net_device *dev,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (switchdev_trans_ph_prepare(trans)) { if (switchdev_trans_ph_prepare(trans)) {
if (!ds->ops->port_mdb_prepare || !ds->ops->port_mdb_add) if (!ds->ops->port_mdb_prepare || !ds->ops->port_mdb_add)
return -EOPNOTSUPP; return -EOPNOTSUPP;
return ds->ops->port_mdb_prepare(ds, p->port, mdb, trans); return ds->ops->port_mdb_prepare(ds, p->dp->index, mdb, trans);
} }
ds->ops->port_mdb_add(ds, p->port, mdb, trans); ds->ops->port_mdb_add(ds, p->dp->index, mdb, trans);
return 0; return 0;
} }
...@@ -335,10 +336,10 @@ static int dsa_slave_port_mdb_del(struct net_device *dev, ...@@ -335,10 +336,10 @@ static int dsa_slave_port_mdb_del(struct net_device *dev,
const struct switchdev_obj_port_mdb *mdb) const struct switchdev_obj_port_mdb *mdb)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (ds->ops->port_mdb_del) if (ds->ops->port_mdb_del)
return ds->ops->port_mdb_del(ds, p->port, mdb); return ds->ops->port_mdb_del(ds, p->dp->index, mdb);
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -348,10 +349,10 @@ static int dsa_slave_port_mdb_dump(struct net_device *dev, ...@@ -348,10 +349,10 @@ static int dsa_slave_port_mdb_dump(struct net_device *dev,
switchdev_obj_dump_cb_t *cb) switchdev_obj_dump_cb_t *cb)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (ds->ops->port_mdb_dump) if (ds->ops->port_mdb_dump)
return ds->ops->port_mdb_dump(ds, p->port, mdb, cb); return ds->ops->port_mdb_dump(ds, p->dp->index, mdb, cb);
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -371,12 +372,12 @@ static int dsa_slave_stp_state_set(struct net_device *dev, ...@@ -371,12 +372,12 @@ static int dsa_slave_stp_state_set(struct net_device *dev,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (switchdev_trans_ph_prepare(trans)) if (switchdev_trans_ph_prepare(trans))
return ds->ops->port_stp_state_set ? 0 : -EOPNOTSUPP; return ds->ops->port_stp_state_set ? 0 : -EOPNOTSUPP;
dsa_port_set_stp_state(ds, p->port, attr->u.stp_state); dsa_port_set_stp_state(ds, p->dp->index, attr->u.stp_state);
return 0; return 0;
} }
...@@ -386,14 +387,14 @@ static int dsa_slave_vlan_filtering(struct net_device *dev, ...@@ -386,14 +387,14 @@ static int dsa_slave_vlan_filtering(struct net_device *dev,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
/* bridge skips -EOPNOTSUPP, so skip the prepare phase */ /* bridge skips -EOPNOTSUPP, so skip the prepare phase */
if (switchdev_trans_ph_prepare(trans)) if (switchdev_trans_ph_prepare(trans))
return 0; return 0;
if (ds->ops->port_vlan_filtering) if (ds->ops->port_vlan_filtering)
return ds->ops->port_vlan_filtering(ds, p->port, return ds->ops->port_vlan_filtering(ds, p->dp->index,
attr->u.vlan_filtering); attr->u.vlan_filtering);
return 0; return 0;
...@@ -419,7 +420,7 @@ static int dsa_slave_ageing_time(struct net_device *dev, ...@@ -419,7 +420,7 @@ static int dsa_slave_ageing_time(struct net_device *dev,
struct switchdev_trans *trans) struct switchdev_trans *trans)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
unsigned long ageing_jiffies = clock_t_to_jiffies(attr->u.ageing_time); unsigned long ageing_jiffies = clock_t_to_jiffies(attr->u.ageing_time);
unsigned int ageing_time = jiffies_to_msecs(ageing_jiffies); unsigned int ageing_time = jiffies_to_msecs(ageing_jiffies);
...@@ -428,7 +429,7 @@ static int dsa_slave_ageing_time(struct net_device *dev, ...@@ -428,7 +429,7 @@ static int dsa_slave_ageing_time(struct net_device *dev,
return 0; return 0;
/* Keep the fastest ageing time in case of multiple bridges */ /* Keep the fastest ageing time in case of multiple bridges */
ds->ports[p->port].ageing_time = ageing_time; p->dp->ageing_time = ageing_time;
ageing_time = dsa_fastest_ageing_time(ds, ageing_time); ageing_time = dsa_fastest_ageing_time(ds, ageing_time);
if (ds->ops->set_ageing_time) if (ds->ops->set_ageing_time)
...@@ -553,13 +554,13 @@ static int dsa_slave_bridge_port_join(struct net_device *dev, ...@@ -553,13 +554,13 @@ static int dsa_slave_bridge_port_join(struct net_device *dev,
struct net_device *br) struct net_device *br)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
int ret = -EOPNOTSUPP; int ret = -EOPNOTSUPP;
p->bridge_dev = br; p->bridge_dev = br;
if (ds->ops->port_bridge_join) if (ds->ops->port_bridge_join)
ret = ds->ops->port_bridge_join(ds, p->port, br); ret = ds->ops->port_bridge_join(ds, p->dp->index, br);
return ret == -EOPNOTSUPP ? 0 : ret; return ret == -EOPNOTSUPP ? 0 : ret;
} }
...@@ -567,25 +568,25 @@ static int dsa_slave_bridge_port_join(struct net_device *dev, ...@@ -567,25 +568,25 @@ static int dsa_slave_bridge_port_join(struct net_device *dev,
static void dsa_slave_bridge_port_leave(struct net_device *dev) static void dsa_slave_bridge_port_leave(struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (ds->ops->port_bridge_leave) if (ds->ops->port_bridge_leave)
ds->ops->port_bridge_leave(ds, p->port); ds->ops->port_bridge_leave(ds, p->dp->index);
p->bridge_dev = NULL; p->bridge_dev = NULL;
/* Port left the bridge, put in BR_STATE_DISABLED by the bridge layer, /* 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 * so allow it to be in BR_STATE_FORWARDING to be kept functional
*/ */
dsa_port_set_stp_state(ds, p->port, BR_STATE_FORWARDING); dsa_port_set_stp_state(ds, p->dp->index, BR_STATE_FORWARDING);
} }
static int dsa_slave_port_attr_get(struct net_device *dev, static int dsa_slave_port_attr_get(struct net_device *dev,
struct switchdev_attr *attr) struct switchdev_attr *attr)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
switch (attr->id) { switch (attr->id) {
case SWITCHDEV_ATTR_ID_PORT_PARENT_ID: case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
...@@ -633,7 +634,7 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -633,7 +634,7 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
/* Queue the SKB for transmission on the parent interface, but /* Queue the SKB for transmission on the parent interface, but
* do not modify its EtherType * do not modify its EtherType
*/ */
nskb->dev = p->parent->dst->master_netdev; nskb->dev = p->dp->ds->dst->master_netdev;
dev_queue_xmit(nskb); dev_queue_xmit(nskb);
return NETDEV_TX_OK; return NETDEV_TX_OK;
...@@ -680,10 +681,10 @@ static void dsa_slave_get_drvinfo(struct net_device *dev, ...@@ -680,10 +681,10 @@ static void dsa_slave_get_drvinfo(struct net_device *dev,
static int dsa_slave_get_regs_len(struct net_device *dev) static int dsa_slave_get_regs_len(struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (ds->ops->get_regs_len) if (ds->ops->get_regs_len)
return ds->ops->get_regs_len(ds, p->port); return ds->ops->get_regs_len(ds, p->dp->index);
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -692,10 +693,10 @@ static void ...@@ -692,10 +693,10 @@ static void
dsa_slave_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p) dsa_slave_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (ds->ops->get_regs) if (ds->ops->get_regs)
ds->ops->get_regs(ds, p->port, regs, _p); ds->ops->get_regs(ds, p->dp->index, regs, _p);
} }
static int dsa_slave_nway_reset(struct net_device *dev) static int dsa_slave_nway_reset(struct net_device *dev)
...@@ -723,7 +724,7 @@ static u32 dsa_slave_get_link(struct net_device *dev) ...@@ -723,7 +724,7 @@ static u32 dsa_slave_get_link(struct net_device *dev)
static int dsa_slave_get_eeprom_len(struct net_device *dev) static int dsa_slave_get_eeprom_len(struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (ds->cd && ds->cd->eeprom_len) if (ds->cd && ds->cd->eeprom_len)
return ds->cd->eeprom_len; return ds->cd->eeprom_len;
...@@ -738,7 +739,7 @@ static int dsa_slave_get_eeprom(struct net_device *dev, ...@@ -738,7 +739,7 @@ static int dsa_slave_get_eeprom(struct net_device *dev,
struct ethtool_eeprom *eeprom, u8 *data) struct ethtool_eeprom *eeprom, u8 *data)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (ds->ops->get_eeprom) if (ds->ops->get_eeprom)
return ds->ops->get_eeprom(ds, eeprom, data); return ds->ops->get_eeprom(ds, eeprom, data);
...@@ -750,7 +751,7 @@ static int dsa_slave_set_eeprom(struct net_device *dev, ...@@ -750,7 +751,7 @@ static int dsa_slave_set_eeprom(struct net_device *dev,
struct ethtool_eeprom *eeprom, u8 *data) struct ethtool_eeprom *eeprom, u8 *data)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (ds->ops->set_eeprom) if (ds->ops->set_eeprom)
return ds->ops->set_eeprom(ds, eeprom, data); return ds->ops->set_eeprom(ds, eeprom, data);
...@@ -762,7 +763,7 @@ static void dsa_slave_get_strings(struct net_device *dev, ...@@ -762,7 +763,7 @@ static void dsa_slave_get_strings(struct net_device *dev,
uint32_t stringset, uint8_t *data) uint32_t stringset, uint8_t *data)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (stringset == ETH_SS_STATS) { if (stringset == ETH_SS_STATS) {
int len = ETH_GSTRING_LEN; int len = ETH_GSTRING_LEN;
...@@ -772,7 +773,7 @@ static void dsa_slave_get_strings(struct net_device *dev, ...@@ -772,7 +773,7 @@ static void dsa_slave_get_strings(struct net_device *dev,
strncpy(data + 2 * len, "rx_packets", len); strncpy(data + 2 * len, "rx_packets", len);
strncpy(data + 3 * len, "rx_bytes", len); strncpy(data + 3 * len, "rx_bytes", len);
if (ds->ops->get_strings) if (ds->ops->get_strings)
ds->ops->get_strings(ds, p->port, data + 4 * len); ds->ops->get_strings(ds, p->dp->index, data + 4 * len);
} }
} }
...@@ -853,20 +854,20 @@ static void dsa_slave_get_ethtool_stats(struct net_device *dev, ...@@ -853,20 +854,20 @@ static void dsa_slave_get_ethtool_stats(struct net_device *dev,
uint64_t *data) uint64_t *data)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
data[0] = dev->stats.tx_packets; data[0] = dev->stats.tx_packets;
data[1] = dev->stats.tx_bytes; data[1] = dev->stats.tx_bytes;
data[2] = dev->stats.rx_packets; data[2] = dev->stats.rx_packets;
data[3] = dev->stats.rx_bytes; data[3] = dev->stats.rx_bytes;
if (ds->ops->get_ethtool_stats) if (ds->ops->get_ethtool_stats)
ds->ops->get_ethtool_stats(ds, p->port, data + 4); ds->ops->get_ethtool_stats(ds, p->dp->index, data + 4);
} }
static int dsa_slave_get_sset_count(struct net_device *dev, int sset) static int dsa_slave_get_sset_count(struct net_device *dev, int sset)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (sset == ETH_SS_STATS) { if (sset == ETH_SS_STATS) {
int count; int count;
...@@ -884,20 +885,20 @@ static int dsa_slave_get_sset_count(struct net_device *dev, int sset) ...@@ -884,20 +885,20 @@ static int dsa_slave_get_sset_count(struct net_device *dev, int sset)
static void dsa_slave_get_wol(struct net_device *dev, struct ethtool_wolinfo *w) static void dsa_slave_get_wol(struct net_device *dev, struct ethtool_wolinfo *w)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
if (ds->ops->get_wol) if (ds->ops->get_wol)
ds->ops->get_wol(ds, p->port, w); ds->ops->get_wol(ds, p->dp->index, w);
} }
static int dsa_slave_set_wol(struct net_device *dev, struct ethtool_wolinfo *w) static int dsa_slave_set_wol(struct net_device *dev, struct ethtool_wolinfo *w)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
int ret = -EOPNOTSUPP; int ret = -EOPNOTSUPP;
if (ds->ops->set_wol) if (ds->ops->set_wol)
ret = ds->ops->set_wol(ds, p->port, w); ret = ds->ops->set_wol(ds, p->dp->index, w);
return ret; return ret;
} }
...@@ -905,13 +906,13 @@ static int dsa_slave_set_wol(struct net_device *dev, struct ethtool_wolinfo *w) ...@@ -905,13 +906,13 @@ static int dsa_slave_set_wol(struct net_device *dev, struct ethtool_wolinfo *w)
static int dsa_slave_set_eee(struct net_device *dev, struct ethtool_eee *e) static int dsa_slave_set_eee(struct net_device *dev, struct ethtool_eee *e)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
int ret; int ret;
if (!ds->ops->set_eee) if (!ds->ops->set_eee)
return -EOPNOTSUPP; return -EOPNOTSUPP;
ret = ds->ops->set_eee(ds, p->port, p->phy, e); ret = ds->ops->set_eee(ds, p->dp->index, p->phy, e);
if (ret) if (ret)
return ret; return ret;
...@@ -924,13 +925,13 @@ static int dsa_slave_set_eee(struct net_device *dev, struct ethtool_eee *e) ...@@ -924,13 +925,13 @@ static int dsa_slave_set_eee(struct net_device *dev, struct ethtool_eee *e)
static int dsa_slave_get_eee(struct net_device *dev, struct ethtool_eee *e) static int dsa_slave_get_eee(struct net_device *dev, struct ethtool_eee *e)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
int ret; int ret;
if (!ds->ops->get_eee) if (!ds->ops->get_eee)
return -EOPNOTSUPP; return -EOPNOTSUPP;
ret = ds->ops->get_eee(ds, p->port, e); ret = ds->ops->get_eee(ds, p->dp->index, e);
if (ret) if (ret)
return ret; return ret;
...@@ -945,7 +946,7 @@ static int dsa_slave_netpoll_setup(struct net_device *dev, ...@@ -945,7 +946,7 @@ static int dsa_slave_netpoll_setup(struct net_device *dev,
struct netpoll_info *ni) struct netpoll_info *ni)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
struct net_device *master = ds->dst->master_netdev; struct net_device *master = ds->dst->master_netdev;
struct netpoll *netpoll; struct netpoll *netpoll;
int err = 0; int err = 0;
...@@ -988,7 +989,7 @@ static int dsa_slave_get_phys_port_name(struct net_device *dev, ...@@ -988,7 +989,7 @@ static int dsa_slave_get_phys_port_name(struct net_device *dev,
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
if (snprintf(name, len, "p%d", p->port) >= len) if (snprintf(name, len, "p%d", p->dp->index) >= len)
return -EINVAL; return -EINVAL;
return 0; return 0;
...@@ -1059,7 +1060,7 @@ static struct device_type dsa_type = { ...@@ -1059,7 +1060,7 @@ static struct device_type dsa_type = {
static void dsa_slave_adjust_link(struct net_device *dev) static void dsa_slave_adjust_link(struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
unsigned int status_changed = 0; unsigned int status_changed = 0;
if (p->old_link != p->phy->link) { if (p->old_link != p->phy->link) {
...@@ -1078,7 +1079,7 @@ static void dsa_slave_adjust_link(struct net_device *dev) ...@@ -1078,7 +1079,7 @@ static void dsa_slave_adjust_link(struct net_device *dev)
} }
if (ds->ops->adjust_link && status_changed) if (ds->ops->adjust_link && status_changed)
ds->ops->adjust_link(ds, p->port, p->phy); ds->ops->adjust_link(ds, p->dp->index, p->phy);
if (status_changed) if (status_changed)
phy_print_status(p->phy); phy_print_status(p->phy);
...@@ -1092,9 +1093,9 @@ static int dsa_slave_fixed_link_update(struct net_device *dev, ...@@ -1092,9 +1093,9 @@ static int dsa_slave_fixed_link_update(struct net_device *dev,
if (dev) { if (dev) {
p = netdev_priv(dev); p = netdev_priv(dev);
ds = p->parent; ds = p->dp->ds;
if (ds->ops->fixed_link_update) if (ds->ops->fixed_link_update)
ds->ops->fixed_link_update(ds, p->port, status); ds->ops->fixed_link_update(ds, p->dp->index, status);
} }
return 0; return 0;
...@@ -1105,7 +1106,7 @@ static int dsa_slave_phy_connect(struct dsa_slave_priv *p, ...@@ -1105,7 +1106,7 @@ static int dsa_slave_phy_connect(struct dsa_slave_priv *p,
struct net_device *slave_dev, struct net_device *slave_dev,
int addr) int addr)
{ {
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
p->phy = mdiobus_get_phy(ds->slave_mii_bus, addr); p->phy = mdiobus_get_phy(ds->slave_mii_bus, addr);
if (!p->phy) { if (!p->phy) {
...@@ -1123,13 +1124,13 @@ static int dsa_slave_phy_connect(struct dsa_slave_priv *p, ...@@ -1123,13 +1124,13 @@ static int dsa_slave_phy_connect(struct dsa_slave_priv *p,
static int dsa_slave_phy_setup(struct dsa_slave_priv *p, static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
struct net_device *slave_dev) struct net_device *slave_dev)
{ {
struct dsa_switch *ds = p->parent; struct dsa_switch *ds = p->dp->ds;
struct device_node *phy_dn, *port_dn; struct device_node *phy_dn, *port_dn;
bool phy_is_fixed = false; bool phy_is_fixed = false;
u32 phy_flags = 0; u32 phy_flags = 0;
int mode, ret; int mode, ret;
port_dn = ds->ports[p->port].dn; port_dn = p->dp->dn;
mode = of_get_phy_mode(port_dn); mode = of_get_phy_mode(port_dn);
if (mode < 0) if (mode < 0)
mode = PHY_INTERFACE_MODE_NA; mode = PHY_INTERFACE_MODE_NA;
...@@ -1150,7 +1151,7 @@ static int dsa_slave_phy_setup(struct dsa_slave_priv *p, ...@@ -1150,7 +1151,7 @@ static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
} }
if (ds->ops->get_phy_flags) if (ds->ops->get_phy_flags)
phy_flags = ds->ops->get_phy_flags(ds, p->port); phy_flags = ds->ops->get_phy_flags(ds, p->dp->index);
if (phy_dn) { if (phy_dn) {
int phy_id = of_mdio_parse_addr(&slave_dev->dev, phy_dn); int phy_id = of_mdio_parse_addr(&slave_dev->dev, phy_dn);
...@@ -1185,9 +1186,10 @@ static int dsa_slave_phy_setup(struct dsa_slave_priv *p, ...@@ -1185,9 +1186,10 @@ static int dsa_slave_phy_setup(struct dsa_slave_priv *p,
* MDIO bus instead * MDIO bus instead
*/ */
if (!p->phy) { if (!p->phy) {
ret = dsa_slave_phy_connect(p, slave_dev, p->port); ret = dsa_slave_phy_connect(p, slave_dev, p->dp->index);
if (ret) { if (ret) {
netdev_err(slave_dev, "failed to connect to port %d: %d\n", p->port, ret); netdev_err(slave_dev, "failed to connect to port %d: %d\n",
p->dp->index, ret);
if (phy_is_fixed) if (phy_is_fixed)
of_phy_deregister_fixed_link(port_dn); of_phy_deregister_fixed_link(port_dn);
return ret; return ret;
...@@ -1275,8 +1277,7 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent, ...@@ -1275,8 +1277,7 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
slave_dev->vlan_features = master->vlan_features; slave_dev->vlan_features = master->vlan_features;
p = netdev_priv(slave_dev); p = netdev_priv(slave_dev);
p->parent = ds; p->dp = &ds->ports[port];
p->port = port;
p->xmit = dst->tag_ops->xmit; p->xmit = dst->tag_ops->xmit;
p->old_pause = -1; p->old_pause = -1;
...@@ -1309,10 +1310,9 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent, ...@@ -1309,10 +1310,9 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
void dsa_slave_destroy(struct net_device *slave_dev) void dsa_slave_destroy(struct net_device *slave_dev)
{ {
struct dsa_slave_priv *p = netdev_priv(slave_dev); struct dsa_slave_priv *p = netdev_priv(slave_dev);
struct dsa_switch *ds = p->parent;
struct device_node *port_dn; struct device_node *port_dn;
port_dn = ds->ports[p->port].dn; port_dn = p->dp->dn;
netif_carrier_off(slave_dev); netif_carrier_off(slave_dev);
if (p->phy) { if (p->phy) {
......
...@@ -80,9 +80,9 @@ static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev ...@@ -80,9 +80,9 @@ static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev
((skb->priority << BRCM_IG_TC_SHIFT) & BRCM_IG_TC_MASK); ((skb->priority << BRCM_IG_TC_SHIFT) & BRCM_IG_TC_MASK);
brcm_tag[1] = 0; brcm_tag[1] = 0;
brcm_tag[2] = 0; brcm_tag[2] = 0;
if (p->port == 8) if (p->dp->index == 8)
brcm_tag[2] = BRCM_IG_DSTMAP2_MASK; brcm_tag[2] = BRCM_IG_DSTMAP2_MASK;
brcm_tag[3] = (1 << p->port) & BRCM_IG_DSTMAP1_MASK; brcm_tag[3] = (1 << p->dp->index) & BRCM_IG_DSTMAP1_MASK;
return skb; return skb;
......
...@@ -33,8 +33,8 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -33,8 +33,8 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev)
* Construct tagged FROM_CPU DSA tag from 802.1q tag. * Construct tagged FROM_CPU DSA tag from 802.1q tag.
*/ */
dsa_header = skb->data + 2 * ETH_ALEN; dsa_header = skb->data + 2 * ETH_ALEN;
dsa_header[0] = 0x60 | p->parent->index; dsa_header[0] = 0x60 | p->dp->ds->index;
dsa_header[1] = p->port << 3; dsa_header[1] = p->dp->index << 3;
/* /*
* Move CFI field from byte 2 to byte 1. * Move CFI field from byte 2 to byte 1.
...@@ -54,8 +54,8 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -54,8 +54,8 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev)
* Construct untagged FROM_CPU DSA tag. * Construct untagged FROM_CPU DSA tag.
*/ */
dsa_header = skb->data + 2 * ETH_ALEN; dsa_header = skb->data + 2 * ETH_ALEN;
dsa_header[0] = 0x40 | p->parent->index; dsa_header[0] = 0x40 | p->dp->ds->index;
dsa_header[1] = p->port << 3; dsa_header[1] = p->dp->index << 3;
dsa_header[2] = 0x00; dsa_header[2] = 0x00;
dsa_header[3] = 0x00; dsa_header[3] = 0x00;
} }
......
...@@ -42,8 +42,8 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -42,8 +42,8 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev)
edsa_header[1] = ETH_P_EDSA & 0xff; edsa_header[1] = ETH_P_EDSA & 0xff;
edsa_header[2] = 0x00; edsa_header[2] = 0x00;
edsa_header[3] = 0x00; edsa_header[3] = 0x00;
edsa_header[4] = 0x60 | p->parent->index; edsa_header[4] = 0x60 | p->dp->ds->index;
edsa_header[5] = p->port << 3; edsa_header[5] = p->dp->index << 3;
/* /*
* Move CFI field from byte 6 to byte 5. * Move CFI field from byte 6 to byte 5.
...@@ -67,8 +67,8 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -67,8 +67,8 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev)
edsa_header[1] = ETH_P_EDSA & 0xff; edsa_header[1] = ETH_P_EDSA & 0xff;
edsa_header[2] = 0x00; edsa_header[2] = 0x00;
edsa_header[3] = 0x00; edsa_header[3] = 0x00;
edsa_header[4] = 0x40 | p->parent->index; edsa_header[4] = 0x40 | p->dp->ds->index;
edsa_header[5] = p->port << 3; edsa_header[5] = p->dp->index << 3;
edsa_header[6] = 0x00; edsa_header[6] = 0x00;
edsa_header[7] = 0x00; edsa_header[7] = 0x00;
} }
......
...@@ -54,7 +54,7 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -54,7 +54,7 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
/* Set the version field, and set destination port information */ /* Set the version field, and set destination port information */
hdr = QCA_HDR_VERSION << QCA_HDR_XMIT_VERSION_S | hdr = QCA_HDR_VERSION << QCA_HDR_XMIT_VERSION_S |
QCA_HDR_XMIT_FROM_CPU | QCA_HDR_XMIT_FROM_CPU |
BIT(p->port); BIT(p->dp->index);
*phdr = htons(hdr); *phdr = htons(hdr);
......
...@@ -50,7 +50,7 @@ static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -50,7 +50,7 @@ static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev)
trailer = skb_put(nskb, 4); trailer = skb_put(nskb, 4);
trailer[0] = 0x80; trailer[0] = 0x80;
trailer[1] = 1 << p->port; trailer[1] = 1 << p->dp->index;
trailer[2] = 0x10; trailer[2] = 0x10;
trailer[3] = 0x00; trailer[3] = 0x00;
......
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