net: dsa: Refactor transmit path to eliminate duplication

All tagging protocols do the same thing: increment device statistics,
make room for the tag to be inserted, create the tag, invoke the parent
network device transmit function.

In order to prepare for adding netpoll support, which requires the tag
creation, but not using the parent network device transmit function, do
some little refactoring which eliminates duplication between the 4
tagging protocols supported.

We need to return a sk_buff pointer back to the caller because the tag
specific transmit function may have to reallocate the original skb (e.g:
tag_trailer.c) and this is the one we should be transmitting, not the
original sk_buff we were passed.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Florian Fainelli 2015-07-31 11:42:56 -07:00 committed by David S. Miller
parent 6cec4f5e00
commit 4ed70ce9f0
6 changed files with 33 additions and 49 deletions

View File

@ -15,7 +15,7 @@
#include <linux/netdevice.h>
struct dsa_device_ops {
netdev_tx_t (*xmit)(struct sk_buff *skb, struct net_device *dev);
struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev);
int (*rcv)(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt, struct net_device *orig_dev);
};
@ -26,7 +26,7 @@ struct dsa_slave_priv {
* switch port.
*/
struct net_device *dev;
netdev_tx_t (*xmit)(struct sk_buff *skb,
struct sk_buff * (*xmit)(struct sk_buff *skb,
struct net_device *dev);
/*

View File

@ -421,21 +421,32 @@ static int dsa_slave_port_attr_get(struct net_device *dev,
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;
return p->xmit(skb, dev);
}
dev->stats.tx_packets++;
dev->stats.tx_bytes += skb->len;
static netdev_tx_t dsa_slave_notag_xmit(struct sk_buff *skb,
struct net_device *dev)
{
struct dsa_slave_priv *p = netdev_priv(dev);
/* Transmit function may have to reallocate the original SKB */
nskb = p->xmit(skb, dev);
if (!nskb)
return NETDEV_TX_OK;
skb->dev = p->parent->dst->master_netdev;
dev_queue_xmit(skb);
/* 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;
}
static struct sk_buff *dsa_slave_notag_xmit(struct sk_buff *skb,
struct net_device *dev)
{
/* Just return the original SKB */
return skb;
}
/* ethtool operations *******************************************************/
static int

View File

@ -58,14 +58,11 @@
#define BRCM_EG_TC_MASK 0x7
#define BRCM_EG_PID_MASK 0x1f
static netdev_tx_t 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);
u8 *brcm_tag;
dev->stats.tx_packets++;
dev->stats.tx_bytes += skb->len;
if (skb_cow_head(skb, BRCM_TAG_LEN) < 0)
goto out_free;
@ -87,17 +84,11 @@ static netdev_tx_t brcm_tag_xmit(struct sk_buff *skb, struct net_device *dev)
brcm_tag[2] = BRCM_IG_DSTMAP2_MASK;
brcm_tag[3] = (1 << p->port) & BRCM_IG_DSTMAP1_MASK;
/* Queue the SKB for transmission on the parent interface, but
* do not modify its EtherType
*/
skb->dev = p->parent->dst->master_netdev;
dev_queue_xmit(skb);
return NETDEV_TX_OK;
return skb;
out_free:
kfree_skb(skb);
return NETDEV_TX_OK;
return NULL;
}
static int brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,

View File

@ -15,14 +15,11 @@
#define DSA_HLEN 4
static netdev_tx_t 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);
u8 *dsa_header;
dev->stats.tx_packets++;
dev->stats.tx_bytes += skb->len;
/*
* Convert the outermost 802.1q tag to a DSA tag for tagged
* packets, or insert a DSA tag between the addresses and
@ -63,14 +60,11 @@ static netdev_tx_t dsa_xmit(struct sk_buff *skb, struct net_device *dev)
dsa_header[3] = 0x00;
}
skb->dev = p->parent->dst->master_netdev;
dev_queue_xmit(skb);
return NETDEV_TX_OK;
return skb;
out_free:
kfree_skb(skb);
return NETDEV_TX_OK;
return NULL;
}
static int dsa_rcv(struct sk_buff *skb, struct net_device *dev,

View File

@ -16,14 +16,11 @@
#define DSA_HLEN 4
#define EDSA_HLEN 8
static netdev_tx_t 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);
u8 *edsa_header;
dev->stats.tx_packets++;
dev->stats.tx_bytes += skb->len;
/*
* Convert the outermost 802.1q tag to a DSA tag and prepend
* a DSA ethertype field is the packet is tagged, or insert
@ -76,14 +73,11 @@ static netdev_tx_t edsa_xmit(struct sk_buff *skb, struct net_device *dev)
edsa_header[7] = 0x00;
}
skb->dev = p->parent->dst->master_netdev;
dev_queue_xmit(skb);
return NETDEV_TX_OK;
return skb;
out_free:
kfree_skb(skb);
return NETDEV_TX_OK;
return NULL;
}
static int edsa_rcv(struct sk_buff *skb, struct net_device *dev,

View File

@ -13,16 +13,13 @@
#include <linux/slab.h>
#include "dsa_priv.h"
static netdev_tx_t 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 sk_buff *nskb;
int padlen;
u8 *trailer;
dev->stats.tx_packets++;
dev->stats.tx_bytes += skb->len;
/*
* We have to make sure that the trailer ends up as the very
* last 4 bytes of the packet. This means that we have to pad
@ -36,7 +33,7 @@ static netdev_tx_t trailer_xmit(struct sk_buff *skb, struct net_device *dev)
nskb = alloc_skb(NET_IP_ALIGN + skb->len + padlen + 4, GFP_ATOMIC);
if (nskb == NULL) {
kfree_skb(skb);
return NETDEV_TX_OK;
return NULL;
}
skb_reserve(nskb, NET_IP_ALIGN);
@ -57,10 +54,7 @@ static netdev_tx_t trailer_xmit(struct sk_buff *skb, struct net_device *dev)
trailer[2] = 0x10;
trailer[3] = 0x00;
nskb->dev = p->parent->dst->master_netdev;
dev_queue_xmit(nskb);
return NETDEV_TX_OK;
return nskb;
}
static int trailer_rcv(struct sk_buff *skb, struct net_device *dev,