All DSA tag receive functions do strictly the same thing after they have located
the originating source port from their tag specific protocol:
- push ETH_HLEN bytes
- set pkt_type to PACKET_HOST
- call eth_type_trans()
- bump up counters
- call netif_receive_skb()
Factor all of that into dsa_switch_rcv(). This also makes us return a pointer to
a sk_buff, which makes us symetric with the xmit function.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
         * protocol to use.
         */
        struct net_device       *master_netdev;
-       int                     (*rcv)(struct sk_buff *skb,
+       struct sk_buff *        (*rcv)(struct sk_buff *skb,
                                       struct net_device *dev,
                                       struct packet_type *pt,
                                       struct net_device *orig_dev);
 
 #include <linux/sysfs.h>
 #include <linux/phy_fixed.h>
 #include <linux/gpio/consumer.h>
+#include <linux/etherdevice.h>
 #include <net/dsa.h>
 #include "dsa_priv.h"
 
                          struct packet_type *pt, struct net_device *orig_dev)
 {
        struct dsa_switch_tree *dst = dev->dsa_ptr;
+       struct sk_buff *nskb = NULL;
 
        if (unlikely(dst == NULL)) {
                kfree_skb(skb);
        if (!skb)
                return 0;
 
-       return dst->rcv(skb, dev, pt, orig_dev);
+       nskb = dst->rcv(skb, dev, pt, orig_dev);
+       if (!nskb) {
+               kfree_skb(skb);
+               return 0;
+       }
+
+       skb = nskb;
+       skb_push(skb, ETH_HLEN);
+       skb->pkt_type = PACKET_HOST;
+       skb->protocol = eth_type_trans(skb, skb->dev);
+
+       skb->dev->stats.rx_packets++;
+       skb->dev->stats.rx_bytes += skb->len;
+
+       netif_receive_skb(skb);
+
+       return 0;
 }
 
 static struct packet_type dsa_pack_type __read_mostly = {
 
 
 struct dsa_device_ops {
        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);
+       struct sk_buff *(*rcv)(struct sk_buff *skb, struct net_device *dev,
+                              struct packet_type *pt,
+                              struct net_device *orig_dev);
 };
 
 struct dsa_slave_priv {
 
        return NULL;
 }
 
-static int brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
-                       struct packet_type *pt, struct net_device *orig_dev)
+static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
+                                   struct packet_type *pt,
+                                   struct net_device *orig_dev)
 {
        struct dsa_switch_tree *dst = dev->dsa_ptr;
        struct dsa_switch *ds;
                skb->data - ETH_HLEN - BRCM_TAG_LEN,
                2 * ETH_ALEN);
 
-       skb_push(skb, ETH_HLEN);
-       skb->pkt_type = PACKET_HOST;
        skb->dev = ds->ports[source_port].netdev;
-       skb->protocol = eth_type_trans(skb, skb->dev);
 
-       skb->dev->stats.rx_packets++;
-       skb->dev->stats.rx_bytes += skb->len;
-
-       netif_receive_skb(skb);
-
-       return 0;
+       return skb;
 
 out_drop:
-       kfree_skb(skb);
-       return 0;
+       return NULL;
 }
 
 const struct dsa_device_ops brcm_netdev_ops = {
 
        return NULL;
 }
 
-static int dsa_rcv(struct sk_buff *skb, struct net_device *dev,
-                  struct packet_type *pt, struct net_device *orig_dev)
+static struct sk_buff *dsa_rcv(struct sk_buff *skb, struct net_device *dev,
+                              struct packet_type *pt,
+                              struct net_device *orig_dev)
 {
        struct dsa_switch_tree *dst = dev->dsa_ptr;
        struct dsa_switch *ds;
        }
 
        skb->dev = ds->ports[source_port].netdev;
-       skb_push(skb, ETH_HLEN);
-       skb->pkt_type = PACKET_HOST;
-       skb->protocol = eth_type_trans(skb, skb->dev);
 
-       skb->dev->stats.rx_packets++;
-       skb->dev->stats.rx_bytes += skb->len;
-
-       netif_receive_skb(skb);
-
-       return 0;
+       return skb;
 
 out_drop:
-       kfree_skb(skb);
-       return 0;
+       return NULL;
 }
 
 const struct dsa_device_ops dsa_netdev_ops = {
 
        return NULL;
 }
 
-static int edsa_rcv(struct sk_buff *skb, struct net_device *dev,
-                   struct packet_type *pt, struct net_device *orig_dev)
+static struct sk_buff *edsa_rcv(struct sk_buff *skb, struct net_device *dev,
+                               struct packet_type *pt,
+                               struct net_device *orig_dev)
 {
        struct dsa_switch_tree *dst = dev->dsa_ptr;
        struct dsa_switch *ds;
        }
 
        skb->dev = ds->ports[source_port].netdev;
-       skb_push(skb, ETH_HLEN);
-       skb->pkt_type = PACKET_HOST;
-       skb->protocol = eth_type_trans(skb, skb->dev);
 
-       skb->dev->stats.rx_packets++;
-       skb->dev->stats.rx_bytes += skb->len;
-
-       netif_receive_skb(skb);
-
-       return 0;
+       return skb;
 
 out_drop:
-       kfree_skb(skb);
-       return 0;
+       return NULL;
 }
 
 const struct dsa_device_ops edsa_netdev_ops = {
 
        return NULL;
 }
 
-static int mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev,
-                      struct packet_type *pt, struct net_device *orig_dev)
+static struct sk_buff *mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev,
+                                  struct packet_type *pt,
+                                  struct net_device *orig_dev)
 {
        struct dsa_switch_tree *dst = dev->dsa_ptr;
        struct dsa_switch *ds;
        if (!ds->ports[port].netdev)
                goto out_drop;
 
-       /* Update skb & forward the frame accordingly */
-       skb_push(skb, ETH_HLEN);
-
-       skb->pkt_type = PACKET_HOST;
        skb->dev = ds->ports[port].netdev;
-       skb->protocol = eth_type_trans(skb, skb->dev);
-
-       skb->dev->stats.rx_packets++;
-       skb->dev->stats.rx_bytes += skb->len;
-
-       netif_receive_skb(skb);
 
-       return 0;
+       return skb;
 
 out_drop:
-       kfree_skb(skb);
-       return 0;
+       return NULL;
 }
 
 const struct dsa_device_ops mtk_netdev_ops = {
 
        return NULL;
 }
 
-static int qca_tag_rcv(struct sk_buff *skb, struct net_device *dev,
-                      struct packet_type *pt, struct net_device *orig_dev)
+static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev,
+                                  struct packet_type *pt,
+                                  struct net_device *orig_dev)
 {
        struct dsa_switch_tree *dst = dev->dsa_ptr;
        struct dsa_switch *ds;
                goto out_drop;
 
        /* Update skb & forward the frame accordingly */
-       skb_push(skb, ETH_HLEN);
-       skb->pkt_type = PACKET_HOST;
        skb->dev = ds->ports[port].netdev;
-       skb->protocol = eth_type_trans(skb, skb->dev);
 
-       skb->dev->stats.rx_packets++;
-       skb->dev->stats.rx_bytes += skb->len;
-
-       netif_receive_skb(skb);
-
-       return 0;
+       return skb;
 
 out_drop:
-       kfree_skb(skb);
-       return 0;
+       return NULL;
 }
 
 const struct dsa_device_ops qca_netdev_ops = {
 
        return nskb;
 }
 
-static int trailer_rcv(struct sk_buff *skb, struct net_device *dev,
-                      struct packet_type *pt, struct net_device *orig_dev)
+static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
+                                  struct packet_type *pt,
+                                  struct net_device *orig_dev)
 {
        struct dsa_switch_tree *dst = dev->dsa_ptr;
        struct dsa_switch *ds;
        pskb_trim_rcsum(skb, skb->len - 4);
 
        skb->dev = ds->ports[source_port].netdev;
-       skb_push(skb, ETH_HLEN);
-       skb->pkt_type = PACKET_HOST;
-       skb->protocol = eth_type_trans(skb, skb->dev);
 
-       skb->dev->stats.rx_packets++;
-       skb->dev->stats.rx_bytes += skb->len;
-
-       netif_receive_skb(skb);
-
-       return 0;
+       return skb;
 
 out_drop:
-       kfree_skb(skb);
-       return 0;
+       return NULL;
 }
 
 const struct dsa_device_ops trailer_netdev_ops = {