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

net: dsa: add slave to port helper

Many portions of DSA core code require to get the dsa_port structure
corresponding to a slave net_device. For this purpose, introduce a
dsa_slave_to_port() helper.
Signed-off-by: default avatarVivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6158eaa7
...@@ -169,6 +169,13 @@ int dsa_slave_resume(struct net_device *slave_dev); ...@@ -169,6 +169,13 @@ int dsa_slave_resume(struct net_device *slave_dev);
int dsa_slave_register_notifier(void); int dsa_slave_register_notifier(void);
void dsa_slave_unregister_notifier(void); void dsa_slave_unregister_notifier(void);
static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev)
{
struct dsa_slave_priv *p = netdev_priv(dev);
return p->dp;
}
/* switch.c */ /* switch.c */
int dsa_switch_register_notifier(struct dsa_switch *ds); int dsa_switch_register_notifier(struct dsa_switch *ds);
void dsa_switch_unregister_notifier(struct dsa_switch *ds); void dsa_switch_unregister_notifier(struct dsa_switch *ds);
......
...@@ -740,8 +740,7 @@ int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], ...@@ -740,8 +740,7 @@ int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
const unsigned char *addr, u16 vid, const unsigned char *addr, u16 vid,
u16 flags) u16 flags)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_port *dp = dsa_slave_to_port(dev);
struct dsa_port *dp = p->dp;
return dsa_port_fdb_add(dp, addr, vid); return dsa_port_fdb_add(dp, addr, vid);
} }
...@@ -750,8 +749,7 @@ int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], ...@@ -750,8 +749,7 @@ int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
struct net_device *dev, struct net_device *dev,
const unsigned char *addr, u16 vid) const unsigned char *addr, u16 vid)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_port *dp = dsa_slave_to_port(dev);
struct dsa_port *dp = p->dp;
return dsa_port_fdb_del(dp, addr, vid); return dsa_port_fdb_del(dp, addr, vid);
} }
......
This diff is collapsed.
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev) static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_port *dp = dsa_slave_to_port(dev);
u16 queue = skb_get_queue_mapping(skb); u16 queue = skb_get_queue_mapping(skb);
u8 *brcm_tag; u8 *brcm_tag;
...@@ -82,15 +82,14 @@ static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev ...@@ -82,15 +82,14 @@ static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev
((queue & BRCM_IG_TC_MASK) << BRCM_IG_TC_SHIFT); ((queue & BRCM_IG_TC_MASK) << BRCM_IG_TC_SHIFT);
brcm_tag[1] = 0; brcm_tag[1] = 0;
brcm_tag[2] = 0; brcm_tag[2] = 0;
if (p->dp->index == 8) if (dp->index == 8)
brcm_tag[2] = BRCM_IG_DSTMAP2_MASK; brcm_tag[2] = BRCM_IG_DSTMAP2_MASK;
brcm_tag[3] = (1 << p->dp->index) & BRCM_IG_DSTMAP1_MASK; brcm_tag[3] = (1 << dp->index) & BRCM_IG_DSTMAP1_MASK;
/* Now tell the master network device about the desired output queue /* Now tell the master network device about the desired output queue
* as well * as well
*/ */
skb_set_queue_mapping(skb, BRCM_TAG_SET_PORT_QUEUE(p->dp->index, skb_set_queue_mapping(skb, BRCM_TAG_SET_PORT_QUEUE(dp->index, queue));
queue));
return skb; return skb;
} }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev) static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_port *dp = dsa_slave_to_port(dev);
u8 *dsa_header; u8 *dsa_header;
/* /*
...@@ -34,8 +34,8 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -34,8 +34,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->dp->ds->index; dsa_header[0] = 0x60 | dp->ds->index;
dsa_header[1] = p->dp->index << 3; dsa_header[1] = dp->index << 3;
/* /*
* Move CFI field from byte 2 to byte 1. * Move CFI field from byte 2 to byte 1.
...@@ -55,8 +55,8 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -55,8 +55,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->dp->ds->index; dsa_header[0] = 0x40 | dp->ds->index;
dsa_header[1] = p->dp->index << 3; dsa_header[1] = dp->index << 3;
dsa_header[2] = 0x00; dsa_header[2] = 0x00;
dsa_header[3] = 0x00; dsa_header[3] = 0x00;
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev) static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_port *dp = dsa_slave_to_port(dev);
u8 *edsa_header; u8 *edsa_header;
/* /*
...@@ -43,8 +43,8 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -43,8 +43,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->dp->ds->index; edsa_header[4] = 0x60 | dp->ds->index;
edsa_header[5] = p->dp->index << 3; edsa_header[5] = dp->index << 3;
/* /*
* Move CFI field from byte 6 to byte 5. * Move CFI field from byte 6 to byte 5.
...@@ -68,8 +68,8 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -68,8 +68,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->dp->ds->index; edsa_header[4] = 0x40 | dp->ds->index;
edsa_header[5] = p->dp->index << 3; edsa_header[5] = dp->index << 3;
edsa_header[6] = 0x00; edsa_header[6] = 0x00;
edsa_header[7] = 0x00; edsa_header[7] = 0x00;
} }
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev) static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_port *dp = dsa_slave_to_port(dev);
struct sk_buff *nskb; struct sk_buff *nskb;
int padlen; int padlen;
u8 *tag; u8 *tag;
...@@ -72,7 +72,7 @@ static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -72,7 +72,7 @@ static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)
tag = skb_put(nskb, KSZ_INGRESS_TAG_LEN); tag = skb_put(nskb, KSZ_INGRESS_TAG_LEN);
tag[0] = 0; tag[0] = 0;
tag[1] = 1 << p->dp->index; /* destination port */ tag[1] = 1 << dp->index; /* destination port */
return nskb; return nskb;
} }
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev) static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_port *dp = dsa_slave_to_port(dev);
u16 *lan9303_tag; u16 *lan9303_tag;
/* insert a special VLAN tag between the MAC addresses /* insert a special VLAN tag between the MAC addresses
...@@ -62,7 +62,7 @@ static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -62,7 +62,7 @@ static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev)
lan9303_tag = (u16 *)(skb->data + 2 * ETH_ALEN); lan9303_tag = (u16 *)(skb->data + 2 * ETH_ALEN);
lan9303_tag[0] = htons(ETH_P_8021Q); lan9303_tag[0] = htons(ETH_P_8021Q);
lan9303_tag[1] = htons(p->dp->index | BIT(4)); lan9303_tag[1] = htons(dp->index | BIT(4));
return skb; return skb;
} }
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb, static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb,
struct net_device *dev) struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_port *dp = dsa_slave_to_port(dev);
u8 *mtk_tag; u8 *mtk_tag;
if (skb_cow_head(skb, MTK_HDR_LEN) < 0) if (skb_cow_head(skb, MTK_HDR_LEN) < 0)
...@@ -36,7 +36,7 @@ static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb, ...@@ -36,7 +36,7 @@ static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb,
/* Build the tag after the MAC Source Address */ /* Build the tag after the MAC Source Address */
mtk_tag = skb->data + 2 * ETH_ALEN; mtk_tag = skb->data + 2 * ETH_ALEN;
mtk_tag[0] = 0; mtk_tag[0] = 0;
mtk_tag[1] = (1 << p->dp->index) & MTK_HDR_XMIT_DP_BIT_MASK; mtk_tag[1] = (1 << dp->index) & MTK_HDR_XMIT_DP_BIT_MASK;
mtk_tag[2] = 0; mtk_tag[2] = 0;
mtk_tag[3] = 0; mtk_tag[3] = 0;
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev) static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_port *dp = dsa_slave_to_port(dev);
u16 *phdr, hdr; u16 *phdr, hdr;
dev->stats.tx_packets++; dev->stats.tx_packets++;
...@@ -54,8 +54,7 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -54,8 +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(dp->index);
BIT(p->dp->index);
*phdr = htons(hdr); *phdr = htons(hdr);
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev) static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev)
{ {
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_port *dp = dsa_slave_to_port(dev);
struct sk_buff *nskb; struct sk_buff *nskb;
int padlen; int padlen;
u8 *trailer; u8 *trailer;
...@@ -48,7 +48,7 @@ static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -48,7 +48,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->dp->index; trailer[1] = 1 << 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