2 * Copyright (c) 2015, The Linux Foundation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <linux/etherdevice.h>
19 #define QCA_HDR_VERSION 0x2
21 #define QCA_HDR_RECV_VERSION_MASK GENMASK(15, 14)
22 #define QCA_HDR_RECV_VERSION_S 14
23 #define QCA_HDR_RECV_PRIORITY_MASK GENMASK(13, 11)
24 #define QCA_HDR_RECV_PRIORITY_S 11
25 #define QCA_HDR_RECV_TYPE_MASK GENMASK(10, 6)
26 #define QCA_HDR_RECV_TYPE_S 6
27 #define QCA_HDR_RECV_FRAME_IS_TAGGED BIT(3)
28 #define QCA_HDR_RECV_SOURCE_PORT_MASK GENMASK(2, 0)
30 #define QCA_HDR_XMIT_VERSION_MASK GENMASK(15, 14)
31 #define QCA_HDR_XMIT_VERSION_S 14
32 #define QCA_HDR_XMIT_PRIORITY_MASK GENMASK(13, 11)
33 #define QCA_HDR_XMIT_PRIORITY_S 11
34 #define QCA_HDR_XMIT_CONTROL_MASK GENMASK(10, 8)
35 #define QCA_HDR_XMIT_CONTROL_S 8
36 #define QCA_HDR_XMIT_FROM_CPU BIT(7)
37 #define QCA_HDR_XMIT_DP_BIT_MASK GENMASK(6, 0)
39 static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
41 struct dsa_port *dp = dsa_slave_to_port(dev);
44 if (skb_cow_head(skb, QCA_HDR_LEN) < 0)
47 skb_push(skb, QCA_HDR_LEN);
49 memmove(skb->data, skb->data + QCA_HDR_LEN, 2 * ETH_ALEN);
50 phdr = (u16 *)(skb->data + 2 * ETH_ALEN);
52 /* Set the version field, and set destination port information */
53 hdr = QCA_HDR_VERSION << QCA_HDR_XMIT_VERSION_S |
54 QCA_HDR_XMIT_FROM_CPU | BIT(dp->index);
61 static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev,
62 struct packet_type *pt)
68 if (unlikely(!pskb_may_pull(skb, QCA_HDR_LEN)))
71 /* The QCA header is added by the switch between src addr and Ethertype
72 * At this point, skb->data points to ethertype so header should be
75 phdr = (__be16 *)(skb->data - 2);
78 /* Make sure the version is correct */
79 ver = (hdr & QCA_HDR_RECV_VERSION_MASK) >> QCA_HDR_RECV_VERSION_S;
80 if (unlikely(ver != QCA_HDR_VERSION))
83 /* Remove QCA tag and recalculate checksum */
84 skb_pull_rcsum(skb, QCA_HDR_LEN);
85 memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - QCA_HDR_LEN,
86 ETH_HLEN - QCA_HDR_LEN);
88 /* Get source port information */
89 port = (hdr & QCA_HDR_RECV_SOURCE_PORT_MASK);
91 skb->dev = dsa_master_find_slave(dev, 0, port);
98 const struct dsa_device_ops qca_netdev_ops = {