1
2
3
4
5
6
7
8
9
10
11
12#include <linux/etherdevice.h>
13#include <linux/list.h>
14#include <linux/slab.h>
15
16#include "dsa_priv.h"
17
18
19
20
21#define BRCM_TAG_LEN 4
22
23
24
25
26
27
28
29
30#define BRCM_OPCODE_SHIFT 5
31#define BRCM_OPCODE_MASK 0x7
32
33
34
35#define BRCM_IG_TC_SHIFT 2
36#define BRCM_IG_TC_MASK 0x7
37
38#define BRCM_IG_TE_MASK 0x3
39#define BRCM_IG_TS_SHIFT 7
40
41#define BRCM_IG_DSTMAP2_MASK 1
42#define BRCM_IG_DSTMAP1_MASK 0xff
43
44
45
46
47#define BRCM_EG_CID_MASK 0xff
48
49
50#define BRCM_EG_RC_MASK 0xff
51#define BRCM_EG_RC_RSVD (3 << 6)
52#define BRCM_EG_RC_EXCEPTION (1 << 5)
53#define BRCM_EG_RC_PROT_SNOOP (1 << 4)
54#define BRCM_EG_RC_PROT_TERM (1 << 3)
55#define BRCM_EG_RC_SWITCH (1 << 2)
56#define BRCM_EG_RC_MAC_LEARN (1 << 1)
57#define BRCM_EG_RC_MIRROR (1 << 0)
58#define BRCM_EG_TC_SHIFT 5
59#define BRCM_EG_TC_MASK 0x7
60#define BRCM_EG_PID_MASK 0x1f
61
62static struct sk_buff *brcm_tag_xmit_ll(struct sk_buff *skb,
63 struct net_device *dev,
64 unsigned int offset)
65{
66 struct dsa_port *dp = dsa_slave_to_port(dev);
67 u16 queue = skb_get_queue_mapping(skb);
68 u8 *brcm_tag;
69
70 if (skb_cow_head(skb, BRCM_TAG_LEN) < 0)
71 return NULL;
72
73 skb_push(skb, BRCM_TAG_LEN);
74
75 if (offset)
76 memmove(skb->data, skb->data + BRCM_TAG_LEN, offset);
77
78 brcm_tag = skb->data + offset;
79
80
81
82
83 brcm_tag[0] = (1 << BRCM_OPCODE_SHIFT) |
84 ((queue & BRCM_IG_TC_MASK) << BRCM_IG_TC_SHIFT);
85 brcm_tag[1] = 0;
86 brcm_tag[2] = 0;
87 if (dp->index == 8)
88 brcm_tag[2] = BRCM_IG_DSTMAP2_MASK;
89 brcm_tag[3] = (1 << dp->index) & BRCM_IG_DSTMAP1_MASK;
90
91
92
93
94 skb_set_queue_mapping(skb, BRCM_TAG_SET_PORT_QUEUE(dp->index, queue));
95
96 return skb;
97}
98
99static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,
100 struct net_device *dev,
101 struct packet_type *pt,
102 unsigned int offset)
103{
104 int source_port;
105 u8 *brcm_tag;
106
107 if (unlikely(!pskb_may_pull(skb, BRCM_TAG_LEN)))
108 return NULL;
109
110 brcm_tag = skb->data - offset;
111
112
113 if (unlikely((brcm_tag[0] >> BRCM_OPCODE_SHIFT) & BRCM_OPCODE_MASK))
114 return NULL;
115
116
117
118
119 if (unlikely(brcm_tag[2] & BRCM_EG_RC_RSVD))
120 return NULL;
121
122
123 source_port = brcm_tag[3] & BRCM_EG_PID_MASK;
124
125 skb->dev = dsa_master_find_slave(dev, 0, source_port);
126 if (!skb->dev)
127 return NULL;
128
129
130 skb_pull_rcsum(skb, BRCM_TAG_LEN);
131
132 return skb;
133}
134
135#ifdef CONFIG_NET_DSA_TAG_BRCM
136static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb,
137 struct net_device *dev)
138{
139
140 return brcm_tag_xmit_ll(skb, dev, 2 * ETH_ALEN);
141}
142
143
144static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
145 struct packet_type *pt)
146{
147 struct sk_buff *nskb;
148
149
150 nskb = brcm_tag_rcv_ll(skb, dev, pt, 2);
151 if (!nskb)
152 return nskb;
153
154
155 memmove(nskb->data - ETH_HLEN,
156 nskb->data - ETH_HLEN - BRCM_TAG_LEN,
157 2 * ETH_ALEN);
158
159 return nskb;
160}
161
162const struct dsa_device_ops brcm_netdev_ops = {
163 .xmit = brcm_tag_xmit,
164 .rcv = brcm_tag_rcv,
165};
166#endif
167
168#ifdef CONFIG_NET_DSA_TAG_BRCM_PREPEND
169static struct sk_buff *brcm_tag_xmit_prepend(struct sk_buff *skb,
170 struct net_device *dev)
171{
172
173 return brcm_tag_xmit_ll(skb, dev, 0);
174}
175
176static struct sk_buff *brcm_tag_rcv_prepend(struct sk_buff *skb,
177 struct net_device *dev,
178 struct packet_type *pt)
179{
180
181 return brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN);
182}
183
184const struct dsa_device_ops brcm_prepend_netdev_ops = {
185 .xmit = brcm_tag_xmit_prepend,
186 .rcv = brcm_tag_rcv_prepend,
187};
188#endif
189