]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - net/dsa/tag_trailer.c
Merge tag 'drm-fixes-for-v4.15-rc2' of git://people.freedesktop.org/~airlied/linux
[mirror_ubuntu-bionic-kernel.git] / net / dsa / tag_trailer.c
CommitLineData
396138f0
LB
1/*
2 * net/dsa/tag_trailer.c - Trailer tag format handling
e84665c9 3 * Copyright (c) 2008-2009 Marvell Semiconductor
396138f0
LB
4 *
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.
9 */
10
11#include <linux/etherdevice.h>
12#include <linux/list.h>
5a0e3ad6 13#include <linux/slab.h>
ea5dd34b 14
396138f0
LB
15#include "dsa_priv.h"
16
4ed70ce9 17static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev)
396138f0 18{
d945097b 19 struct dsa_port *dp = dsa_slave_to_port(dev);
396138f0
LB
20 struct sk_buff *nskb;
21 int padlen;
22 u8 *trailer;
23
396138f0
LB
24 /*
25 * We have to make sure that the trailer ends up as the very
26 * last 4 bytes of the packet. This means that we have to pad
27 * the packet to the minimum ethernet frame size, if necessary,
28 * before adding the trailer.
29 */
30 padlen = 0;
31 if (skb->len < 60)
32 padlen = 60 - skb->len;
33
34 nskb = alloc_skb(NET_IP_ALIGN + skb->len + padlen + 4, GFP_ATOMIC);
fe47d563 35 if (!nskb)
4ed70ce9 36 return NULL;
396138f0
LB
37 skb_reserve(nskb, NET_IP_ALIGN);
38
39 skb_reset_mac_header(nskb);
40 skb_set_network_header(nskb, skb_network_header(skb) - skb->head);
41 skb_set_transport_header(nskb, skb_transport_header(skb) - skb->head);
42 skb_copy_and_csum_dev(skb, skb_put(nskb, skb->len));
2b33bc8a 43 consume_skb(skb);
396138f0
LB
44
45 if (padlen) {
b952f4df 46 skb_put_zero(nskb, padlen);
396138f0
LB
47 }
48
49 trailer = skb_put(nskb, 4);
50 trailer[0] = 0x80;
d945097b 51 trailer[1] = 1 << dp->index;
396138f0
LB
52 trailer[2] = 0x10;
53 trailer[3] = 0x00;
54
4ed70ce9 55 return nskb;
396138f0
LB
56}
57
a86d8bec 58static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
89e49506 59 struct packet_type *pt)
396138f0 60{
396138f0
LB
61 u8 *trailer;
62 int source_port;
63
396138f0 64 if (skb_linearize(skb))
54709795 65 return NULL;
396138f0
LB
66
67 trailer = skb_tail_pointer(skb) - 4;
68 if (trailer[0] != 0x80 || (trailer[1] & 0xf8) != 0x00 ||
fbd03513 69 (trailer[2] & 0xef) != 0x00 || trailer[3] != 0x00)
54709795 70 return NULL;
396138f0
LB
71
72 source_port = trailer[1] & 7;
3775b1b7 73
2231c43b 74 skb->dev = dsa_master_find_slave(dev, 0, source_port);
3775b1b7 75 if (!skb->dev)
54709795 76 return NULL;
396138f0
LB
77
78 pskb_trim_rcsum(skb, skb->len - 4);
79
a86d8bec 80 return skb;
396138f0
LB
81}
82
3e8a72d1
FF
83const struct dsa_device_ops trailer_netdev_ops = {
84 .xmit = trailer_xmit,
85 .rcv = trailer_rcv,
396138f0 86};