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/netdevice.h>
14 #include <linux/slab.h>
17 netdev_tx_t
trailer_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
19 struct dsa_slave_priv
*p
= netdev_priv(dev
);
24 dev
->stats
.tx_packets
++;
25 dev
->stats
.tx_bytes
+= skb
->len
;
28 * We have to make sure that the trailer ends up as the very
29 * last 4 bytes of the packet. This means that we have to pad
30 * the packet to the minimum ethernet frame size, if necessary,
31 * before adding the trailer.
35 padlen
= 60 - skb
->len
;
37 nskb
= alloc_skb(NET_IP_ALIGN
+ skb
->len
+ padlen
+ 4, GFP_ATOMIC
);
42 skb_reserve(nskb
, NET_IP_ALIGN
);
44 skb_reset_mac_header(nskb
);
45 skb_set_network_header(nskb
, skb_network_header(skb
) - skb
->head
);
46 skb_set_transport_header(nskb
, skb_transport_header(skb
) - skb
->head
);
47 skb_copy_and_csum_dev(skb
, skb_put(nskb
, skb
->len
));
51 u8
*pad
= skb_put(nskb
, padlen
);
52 memset(pad
, 0, padlen
);
55 trailer
= skb_put(nskb
, 4);
57 trailer
[1] = 1 << p
->port
;
61 nskb
->protocol
= htons(ETH_P_TRAILER
);
63 nskb
->dev
= p
->parent
->dst
->master_netdev
;
69 static int trailer_rcv(struct sk_buff
*skb
, struct net_device
*dev
,
70 struct packet_type
*pt
, struct net_device
*orig_dev
)
72 struct dsa_switch_tree
*dst
= dev
->dsa_ptr
;
73 struct dsa_switch
*ds
;
77 if (unlikely(dst
== NULL
))
81 skb
= skb_unshare(skb
, GFP_ATOMIC
);
85 if (skb_linearize(skb
))
88 trailer
= skb_tail_pointer(skb
) - 4;
89 if (trailer
[0] != 0x80 || (trailer
[1] & 0xf8) != 0x00 ||
90 (trailer
[3] & 0xef) != 0x00 || trailer
[3] != 0x00)
93 source_port
= trailer
[1] & 7;
94 if (source_port
>= DSA_MAX_PORTS
|| ds
->ports
[source_port
] == NULL
)
97 pskb_trim_rcsum(skb
, skb
->len
- 4);
99 skb
->dev
= ds
->ports
[source_port
];
100 skb_push(skb
, ETH_HLEN
);
101 skb
->pkt_type
= PACKET_HOST
;
102 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
104 skb
->dev
->stats
.rx_packets
++;
105 skb
->dev
->stats
.rx_bytes
+= skb
->len
;
107 netif_receive_skb(skb
);
117 static struct packet_type trailer_packet_type __read_mostly
= {
118 .type
= cpu_to_be16(ETH_P_TRAILER
),
122 static int __init
trailer_init_module(void)
124 dev_add_pack(&trailer_packet_type
);
127 module_init(trailer_init_module
);
129 static void __exit
trailer_cleanup_module(void)
131 dev_remove_pack(&trailer_packet_type
);
133 module_exit(trailer_cleanup_module
);