2 * net/dsa/tag_trailer.c - Trailer tag format handling
3 * Copyright (c) 2008 Marvell Semiconductor
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
11 #include <linux/etherdevice.h>
12 #include <linux/list.h>
13 #include <linux/netdevice.h>
16 int trailer_xmit(struct sk_buff *skb, struct net_device *dev)
18 struct dsa_slave_priv *p = netdev_priv(dev);
23 dev->stats.tx_packets++;
24 dev->stats.tx_bytes += skb->len;
27 * We have to make sure that the trailer ends up as the very
28 * last 4 bytes of the packet. This means that we have to pad
29 * the packet to the minimum ethernet frame size, if necessary,
30 * before adding the trailer.
34 padlen = 60 - skb->len;
36 nskb = alloc_skb(NET_IP_ALIGN + skb->len + padlen + 4, GFP_ATOMIC);
41 skb_reserve(nskb, NET_IP_ALIGN);
43 skb_reset_mac_header(nskb);
44 skb_set_network_header(nskb, skb_network_header(skb) - skb->head);
45 skb_set_transport_header(nskb, skb_transport_header(skb) - skb->head);
46 skb_copy_and_csum_dev(skb, skb_put(nskb, skb->len));
50 u8 *pad = skb_put(nskb, padlen);
51 memset(pad, 0, padlen);
54 trailer = skb_put(nskb, 4);
56 trailer[1] = 1 << p->port;
60 nskb->protocol = htons(ETH_P_TRAILER);
62 nskb->dev = p->parent->master_netdev;
68 static int trailer_rcv(struct sk_buff *skb, struct net_device *dev,
69 struct packet_type *pt, struct net_device *orig_dev)
71 struct dsa_switch *ds = dev->dsa_ptr;
75 if (unlikely(ds == NULL))
78 skb = skb_unshare(skb, GFP_ATOMIC);
82 if (skb_linearize(skb))
85 trailer = skb_tail_pointer(skb) - 4;
86 if (trailer[0] != 0x80 || (trailer[1] & 0xf8) != 0x00 ||
87 (trailer[3] & 0xef) != 0x00 || trailer[3] != 0x00)
90 source_port = trailer[1] & 7;
91 if (source_port >= DSA_MAX_PORTS || ds->ports[source_port] == NULL)
94 pskb_trim_rcsum(skb, skb->len - 4);
96 skb->dev = ds->ports[source_port];
97 skb_push(skb, ETH_HLEN);
98 skb->protocol = eth_type_trans(skb, skb->dev);
100 skb->dev->last_rx = jiffies;
101 skb->dev->stats.rx_packets++;
102 skb->dev->stats.rx_bytes += skb->len;
104 netif_receive_skb(skb);
114 static struct packet_type trailer_packet_type = {
115 .type = __constant_htons(ETH_P_TRAILER),
119 static int __init trailer_init_module(void)
121 dev_add_pack(&trailer_packet_type);
124 module_init(trailer_init_module);
126 static void __exit trailer_cleanup_module(void)
128 dev_remove_pack(&trailer_packet_type);
130 module_exit(trailer_cleanup_module);