Skip to content

Commit

Permalink
Merge branch 'dsa-tagger-simplification'
Browse files Browse the repository at this point in the history
Vivien Didelot says:

====================
net: dsa: tagger simplification

This series clarifies the hot path, removes the labels in tagging
implementations, and frees the original SKB in the xmit caller.

Changes in v3:
  - drop removal of usused rcv arguments because they will be used later
  - include the new ksz tagging implementation
  - add reviewers' tags

Changes in v2:
  - do not remove tagger function copies
  - document hot path requirements
  - make netdev_uses_dsa simpler
  - add reviewers' tags
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jun 1, 2017
2 parents 0266f79 + fe47d56 commit 0c34ca4
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 90 deletions.
11 changes: 4 additions & 7 deletions include/net/dsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ struct dsa_switch_tree {
* protocol to use.
*/
struct net_device *master_netdev;

/* Copy of tag_ops->rcv for faster access in hot path */
struct sk_buff * (*rcv)(struct sk_buff *skb,
struct net_device *dev,
struct packet_type *pt,
Expand Down Expand Up @@ -465,16 +467,11 @@ struct mii_bus *dsa_host_dev_to_mii_bus(struct device *dev);

struct net_device *dsa_dev_to_net_device(struct device *dev);

static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
{
return dst->rcv != NULL;
}

/* Keep inline for faster access in hot path */
static inline bool netdev_uses_dsa(struct net_device *dev)
{
#if IS_ENABLED(CONFIG_NET_DSA)
if (dev->dsa_ptr != NULL)
return dsa_uses_tagged_protocol(dev->dsa_ptr);
return dev->dsa_ptr && dev->dsa_ptr->rcv;
#endif
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion net/dsa/dsa2.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ static int dsa_dst_apply(struct dsa_switch_tree *dst)
* sent to the tag format's receive function.
*/
wmb();
dst->master_netdev->dsa_ptr = (void *)dst;
dst->master_netdev->dsa_ptr = dst;
dst->applied = true;

return 0;
Expand Down
1 change: 1 addition & 0 deletions net/dsa/dsa_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct dsa_device_ops {
};

struct dsa_slave_priv {
/* Copy of dp->ds->dst->tag_ops->xmit for faster access in hot path */
struct sk_buff * (*xmit)(struct sk_buff *skb,
struct net_device *dev);

Expand Down
2 changes: 1 addition & 1 deletion net/dsa/legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ static int dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
* sent to the tag format's receive function.
*/
wmb();
dev->dsa_ptr = (void *)dst;
dev->dsa_ptr = dst;

return 0;
}
Expand Down
8 changes: 6 additions & 2 deletions net/dsa/slave.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,14 @@ static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev)
dev->stats.tx_packets++;
dev->stats.tx_bytes += skb->len;

/* Transmit function may have to reallocate the original SKB */
/* Transmit function may have to reallocate the original SKB,
* in which case it must have freed it. Only free it here on error.
*/
nskb = p->xmit(skb, dev);
if (!nskb)
if (!nskb) {
kfree_skb(skb);
return NETDEV_TX_OK;
}

/* SKB for netpoll still need to be mangled with the protocol-specific
* tag to be successfully transmitted
Expand Down
17 changes: 5 additions & 12 deletions net/dsa/tag_brcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev
u8 *brcm_tag;

if (skb_cow_head(skb, BRCM_TAG_LEN) < 0)
goto out_free;
return NULL;

skb_push(skb, BRCM_TAG_LEN);

Expand All @@ -86,10 +86,6 @@ static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev
brcm_tag[3] = (1 << p->dp->index) & BRCM_IG_DSTMAP1_MASK;

return skb;

out_free:
kfree_skb(skb);
return NULL;
}

static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
Expand All @@ -104,27 +100,27 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
ds = dst->cpu_dp->ds;

if (unlikely(!pskb_may_pull(skb, BRCM_TAG_LEN)))
goto out_drop;
return NULL;

/* skb->data points to the EtherType, the tag is right before it */
brcm_tag = skb->data - 2;

/* The opcode should never be different than 0b000 */
if (unlikely((brcm_tag[0] >> BRCM_OPCODE_SHIFT) & BRCM_OPCODE_MASK))
goto out_drop;
return NULL;

/* We should never see a reserved reason code without knowing how to
* handle it
*/
if (unlikely(brcm_tag[2] & BRCM_EG_RC_RSVD))
goto out_drop;
return NULL;

/* Locate which port this is coming from */
source_port = brcm_tag[3] & BRCM_EG_PID_MASK;

/* Validate port against switch setup, either the port is totally */
if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
goto out_drop;
return NULL;

/* Remove Broadcom tag and update checksum */
skb_pull_rcsum(skb, BRCM_TAG_LEN);
Expand All @@ -137,9 +133,6 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
skb->dev = ds->ports[source_port].netdev;

return skb;

out_drop:
return NULL;
}

const struct dsa_device_ops brcm_netdev_ops = {
Expand Down
21 changes: 7 additions & 14 deletions net/dsa/tag_dsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev)
*/
if (skb->protocol == htons(ETH_P_8021Q)) {
if (skb_cow_head(skb, 0) < 0)
goto out_free;
return NULL;

/*
* Construct tagged FROM_CPU DSA tag from 802.1q tag.
Expand All @@ -46,7 +46,7 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev)
}
} else {
if (skb_cow_head(skb, DSA_HLEN) < 0)
goto out_free;
return NULL;
skb_push(skb, DSA_HLEN);

memmove(skb->data, skb->data + DSA_HLEN, 2 * ETH_ALEN);
Expand All @@ -62,10 +62,6 @@ static struct sk_buff *dsa_xmit(struct sk_buff *skb, struct net_device *dev)
}

return skb;

out_free:
kfree_skb(skb);
return NULL;
}

static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev,
Expand All @@ -79,7 +75,7 @@ static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev,
int source_port;

if (unlikely(!pskb_may_pull(skb, DSA_HLEN)))
goto out_drop;
return NULL;

/*
* The ethertype field is part of the DSA header.
Expand All @@ -90,7 +86,7 @@ static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev,
* Check that frame type is either TO_CPU or FORWARD.
*/
if ((dsa_header[0] & 0xc0) != 0x00 && (dsa_header[0] & 0xc0) != 0xc0)
goto out_drop;
return NULL;

/*
* Determine source device and port.
Expand All @@ -103,14 +99,14 @@ static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev,
* port is a registered DSA port.
*/
if (source_device >= DSA_MAX_SWITCHES)
goto out_drop;
return NULL;

ds = dst->ds[source_device];
if (!ds)
goto out_drop;
return NULL;

if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
goto out_drop;
return NULL;

/*
* Convert the DSA header to an 802.1q header if the 'tagged'
Expand Down Expand Up @@ -161,9 +157,6 @@ static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev,
skb->dev = ds->ports[source_port].netdev;

return skb;

out_drop:
return NULL;
}

const struct dsa_device_ops dsa_netdev_ops = {
Expand Down
21 changes: 7 additions & 14 deletions net/dsa/tag_edsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev)
*/
if (skb->protocol == htons(ETH_P_8021Q)) {
if (skb_cow_head(skb, DSA_HLEN) < 0)
goto out_free;
return NULL;
skb_push(skb, DSA_HLEN);

memmove(skb->data, skb->data + DSA_HLEN, 2 * ETH_ALEN);
Expand All @@ -55,7 +55,7 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev)
}
} else {
if (skb_cow_head(skb, EDSA_HLEN) < 0)
goto out_free;
return NULL;
skb_push(skb, EDSA_HLEN);

memmove(skb->data, skb->data + EDSA_HLEN, 2 * ETH_ALEN);
Expand All @@ -75,10 +75,6 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev)
}

return skb;

out_free:
kfree_skb(skb);
return NULL;
}

static struct sk_buff *edsa_rcv(struct sk_buff *skb, struct net_device *dev,
Expand All @@ -92,7 +88,7 @@ static struct sk_buff *edsa_rcv(struct sk_buff *skb, struct net_device *dev,
int source_port;

if (unlikely(!pskb_may_pull(skb, EDSA_HLEN)))
goto out_drop;
return NULL;

/*
* Skip the two null bytes after the ethertype.
Expand All @@ -103,7 +99,7 @@ static struct sk_buff *edsa_rcv(struct sk_buff *skb, struct net_device *dev,
* Check that frame type is either TO_CPU or FORWARD.
*/
if ((edsa_header[0] & 0xc0) != 0x00 && (edsa_header[0] & 0xc0) != 0xc0)
goto out_drop;
return NULL;

/*
* Determine source device and port.
Expand All @@ -116,14 +112,14 @@ static struct sk_buff *edsa_rcv(struct sk_buff *skb, struct net_device *dev,
* port is a registered DSA port.
*/
if (source_device >= DSA_MAX_SWITCHES)
goto out_drop;
return NULL;

ds = dst->ds[source_device];
if (!ds)
goto out_drop;
return NULL;

if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
goto out_drop;
return NULL;

/*
* If the 'tagged' bit is set, convert the DSA tag to a 802.1q
Expand Down Expand Up @@ -180,9 +176,6 @@ static struct sk_buff *edsa_rcv(struct sk_buff *skb, struct net_device *dev,
skb->dev = ds->ports[source_port].netdev;

return skb;

out_drop:
return NULL;
}

const struct dsa_device_ops edsa_netdev_ops = {
Expand Down
4 changes: 1 addition & 3 deletions net/dsa/tag_ksz.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ static struct sk_buff *ksz_xmit(struct sk_buff *skb, struct net_device *dev)
} else {
nskb = alloc_skb(NET_IP_ALIGN + skb->len +
padlen + KSZ_INGRESS_TAG_LEN, GFP_ATOMIC);
if (!nskb) {
kfree_skb(skb);
if (!nskb)
return NULL;
}
skb_reserve(nskb, NET_IP_ALIGN);

skb_reset_mac_header(nskb);
Expand Down
5 changes: 1 addition & 4 deletions net/dsa/tag_lan9303.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev)
if (skb_cow_head(skb, LAN9303_TAG_LEN) < 0) {
dev_dbg(&dev->dev,
"Cannot make room for the special tag. Dropping packet\n");
goto out_free;
return NULL;
}

/* provide 'LAN9303_TAG_LEN' bytes additional space */
Expand All @@ -66,9 +66,6 @@ static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev)
lan9303_tag[1] = htons(p->dp->index | BIT(4));

return skb;
out_free:
kfree_skb(skb);
return NULL;
}

static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev,
Expand Down
15 changes: 4 additions & 11 deletions net/dsa/tag_mtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb,
u8 *mtk_tag;

if (skb_cow_head(skb, MTK_HDR_LEN) < 0)
goto out_free;
return NULL;

skb_push(skb, MTK_HDR_LEN);

Expand All @@ -41,10 +41,6 @@ static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb,
mtk_tag[3] = 0;

return skb;

out_free:
kfree_skb(skb);
return NULL;
}

static struct sk_buff *mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev,
Expand All @@ -57,7 +53,7 @@ static struct sk_buff *mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev,
__be16 *phdr, hdr;

if (unlikely(!pskb_may_pull(skb, MTK_HDR_LEN)))
goto out_drop;
return NULL;

/* The MTK header is added by the switch between src addr
* and ethertype at this point, skb->data points to 2 bytes
Expand All @@ -79,19 +75,16 @@ static struct sk_buff *mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev,
*/
ds = dst->ds[0];
if (!ds)
goto out_drop;
return NULL;

/* Get source port information */
port = (hdr & MTK_HDR_RECV_SOURCE_PORT_MASK);
if (!ds->ports[port].netdev)
goto out_drop;
return NULL;

skb->dev = ds->ports[port].netdev;

return skb;

out_drop:
return NULL;
}

const struct dsa_device_ops mtk_netdev_ops = {
Expand Down
Loading

0 comments on commit 0c34ca4

Please sign in to comment.