net: dsa: Refactor transmit path to eliminate duplication
authorFlorian Fainelli <f.fainelli@gmail.com>
Fri, 31 Jul 2015 18:42:56 +0000 (11:42 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 31 Jul 2015 22:45:37 +0000 (15:45 -0700)
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>
net/dsa/dsa_priv.h
net/dsa/slave.c
net/dsa/tag_brcm.c
net/dsa/tag_dsa.c
net/dsa/tag_edsa.c
net/dsa/tag_trailer.c

index d5f1f9b862ea5f4794ba2fab277e19aed8e51d2a..eeade901e67a5414bc87250b84d2313788d86e18 100644 (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);
 
        /*
index 0917123790eaf09b001c97a733039185fdb0a800..5fc87ee539052eea4c6ec3335218074c9313f76f 100644 (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
index 83d3572cdb205934e3099c258244f347d7351517..e2aadb73111d544c1ce16db13bfd99c7506642fc 100644 (file)
 #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,
index 2dab27063273d2d48d12cc13b9d73fefe92c9362..aa780e4ac0bd9653618c2b4c582d882cfb52f94a 100644 (file)
 
 #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,
index 9aeda596f7ec4ec2c30df9167e87c7719535de91..2288c8098c42800c6477068c0334d7e1874ba608 100644 (file)
 #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,
index e268f9db8893deab7c2febd26ad0aae1849b157d..d25efc93d8f120739c83c3998e77d5e9dd3cfc45 100644 (file)
 #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,
This page took 0.030465 seconds and 5 git commands to generate.