2 * net/dsa/tag_trailer.c - Trailer tag format handling
3 * Copyright (c) 2008-2009 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/slab.h>
16 static struct sk_buff
*trailer_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
18 struct dsa_slave_priv
*p
= netdev_priv(dev
);
24 * We have to make sure that the trailer ends up as the very
25 * last 4 bytes of the packet. This means that we have to pad
26 * the packet to the minimum ethernet frame size, if necessary,
27 * before adding the trailer.
31 padlen
= 60 - skb
->len
;
33 nskb
= alloc_skb(NET_IP_ALIGN
+ skb
->len
+ padlen
+ 4, GFP_ATOMIC
);
38 skb_reserve(nskb
, NET_IP_ALIGN
);
40 skb_reset_mac_header(nskb
);
41 skb_set_network_header(nskb
, skb_network_header(skb
) - skb
->head
);
42 skb_set_transport_header(nskb
, skb_transport_header(skb
) - skb
->head
);
43 skb_copy_and_csum_dev(skb
, skb_put(nskb
, skb
->len
));
47 u8
*pad
= skb_put(nskb
, padlen
);
48 memset(pad
, 0, padlen
);
51 trailer
= skb_put(nskb
, 4);
53 trailer
[1] = 1 << p
->port
;
60 static int trailer_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
61 struct packet_type
*pt
, struct net_device
*orig_dev
)
63 struct dsa_switch_tree
*dst
= dev
->dsa_ptr
;
64 struct dsa_switch
*ds
;
68 if (unlikely(dst
== NULL
))
72 skb
= skb_unshare(skb
, GFP_ATOMIC
);
76 if (skb_linearize(skb
))
79 trailer
= skb_tail_pointer(skb
) - 4;
80 if (trailer
[0] != 0x80 || (trailer
[1] & 0xf8) != 0x00 ||
81 (trailer
[2] & 0xef) != 0x00 || trailer
[3] != 0x00)
84 source_port
= trailer
[1] & 7;
85 if (source_port
>= DSA_MAX_PORTS
|| ds
->ports
[source_port
] == NULL
)
88 pskb_trim_rcsum(skb
, skb
->len
- 4);
90 skb
->dev
= ds
->ports
[source_port
];
91 skb_push(skb
, ETH_HLEN
);
92 skb
->pkt_type
= PACKET_HOST
;
93 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
95 skb
->dev
->stats
.rx_packets
++;
96 skb
->dev
->stats
.rx_bytes
+= skb
->len
;
98 netif_receive_skb(skb
);
108 const struct dsa_device_ops trailer_netdev_ops
= {
109 .xmit
= trailer_xmit
,