Commit 3aa475e197f44ae401502b61aa341d3e40aa045a

Authored by Andrew Lunn
Committed by David S. Miller
1 parent f81a43e8da

dsa: tag_brcm: Avoid unused symbols

It is possible that the driver is compiled with both
CONFIG_NET_DSA_TAG_BRCM and CONFIG_NET_DSA_TAG_BRCM_PREPEND disabled.
This results in warnings about unused symbols. Add some conditional
compilation to avoid this.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>

v2
Reorder patch to before tag drivers can be modules

Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 6 additions and 2 deletions Inline Diff

1 // SPDX-License-Identifier: GPL-2.0+ 1 // SPDX-License-Identifier: GPL-2.0+
2 /* 2 /*
3 * Broadcom tag support 3 * Broadcom tag support
4 * 4 *
5 * Copyright (C) 2014 Broadcom Corporation 5 * Copyright (C) 2014 Broadcom Corporation
6 */ 6 */
7 7
8 #include <linux/etherdevice.h> 8 #include <linux/etherdevice.h>
9 #include <linux/list.h> 9 #include <linux/list.h>
10 #include <linux/slab.h> 10 #include <linux/slab.h>
11 11
12 #include "dsa_priv.h" 12 #include "dsa_priv.h"
13 13
14 /* This tag length is 4 bytes, older ones were 6 bytes, we do not 14 /* This tag length is 4 bytes, older ones were 6 bytes, we do not
15 * handle them 15 * handle them
16 */ 16 */
17 #define BRCM_TAG_LEN 4 17 #define BRCM_TAG_LEN 4
18 18
19 /* Tag is constructed and desconstructed using byte by byte access 19 /* Tag is constructed and desconstructed using byte by byte access
20 * because the tag is placed after the MAC Source Address, which does 20 * because the tag is placed after the MAC Source Address, which does
21 * not make it 4-bytes aligned, so this might cause unaligned accesses 21 * not make it 4-bytes aligned, so this might cause unaligned accesses
22 * on most systems where this is used. 22 * on most systems where this is used.
23 */ 23 */
24 24
25 /* Ingress and egress opcodes */ 25 /* Ingress and egress opcodes */
26 #define BRCM_OPCODE_SHIFT 5 26 #define BRCM_OPCODE_SHIFT 5
27 #define BRCM_OPCODE_MASK 0x7 27 #define BRCM_OPCODE_MASK 0x7
28 28
29 /* Ingress fields */ 29 /* Ingress fields */
30 /* 1st byte in the tag */ 30 /* 1st byte in the tag */
31 #define BRCM_IG_TC_SHIFT 2 31 #define BRCM_IG_TC_SHIFT 2
32 #define BRCM_IG_TC_MASK 0x7 32 #define BRCM_IG_TC_MASK 0x7
33 /* 2nd byte in the tag */ 33 /* 2nd byte in the tag */
34 #define BRCM_IG_TE_MASK 0x3 34 #define BRCM_IG_TE_MASK 0x3
35 #define BRCM_IG_TS_SHIFT 7 35 #define BRCM_IG_TS_SHIFT 7
36 /* 3rd byte in the tag */ 36 /* 3rd byte in the tag */
37 #define BRCM_IG_DSTMAP2_MASK 1 37 #define BRCM_IG_DSTMAP2_MASK 1
38 #define BRCM_IG_DSTMAP1_MASK 0xff 38 #define BRCM_IG_DSTMAP1_MASK 0xff
39 39
40 /* Egress fields */ 40 /* Egress fields */
41 41
42 /* 2nd byte in the tag */ 42 /* 2nd byte in the tag */
43 #define BRCM_EG_CID_MASK 0xff 43 #define BRCM_EG_CID_MASK 0xff
44 44
45 /* 3rd byte in the tag */ 45 /* 3rd byte in the tag */
46 #define BRCM_EG_RC_MASK 0xff 46 #define BRCM_EG_RC_MASK 0xff
47 #define BRCM_EG_RC_RSVD (3 << 6) 47 #define BRCM_EG_RC_RSVD (3 << 6)
48 #define BRCM_EG_RC_EXCEPTION (1 << 5) 48 #define BRCM_EG_RC_EXCEPTION (1 << 5)
49 #define BRCM_EG_RC_PROT_SNOOP (1 << 4) 49 #define BRCM_EG_RC_PROT_SNOOP (1 << 4)
50 #define BRCM_EG_RC_PROT_TERM (1 << 3) 50 #define BRCM_EG_RC_PROT_TERM (1 << 3)
51 #define BRCM_EG_RC_SWITCH (1 << 2) 51 #define BRCM_EG_RC_SWITCH (1 << 2)
52 #define BRCM_EG_RC_MAC_LEARN (1 << 1) 52 #define BRCM_EG_RC_MAC_LEARN (1 << 1)
53 #define BRCM_EG_RC_MIRROR (1 << 0) 53 #define BRCM_EG_RC_MIRROR (1 << 0)
54 #define BRCM_EG_TC_SHIFT 5 54 #define BRCM_EG_TC_SHIFT 5
55 #define BRCM_EG_TC_MASK 0x7 55 #define BRCM_EG_TC_MASK 0x7
56 #define BRCM_EG_PID_MASK 0x1f 56 #define BRCM_EG_PID_MASK 0x1f
57 57
58 #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM) || \
59 IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND)
60
58 static struct sk_buff *brcm_tag_xmit_ll(struct sk_buff *skb, 61 static struct sk_buff *brcm_tag_xmit_ll(struct sk_buff *skb,
59 struct net_device *dev, 62 struct net_device *dev,
60 unsigned int offset) 63 unsigned int offset)
61 { 64 {
62 struct dsa_port *dp = dsa_slave_to_port(dev); 65 struct dsa_port *dp = dsa_slave_to_port(dev);
63 u16 queue = skb_get_queue_mapping(skb); 66 u16 queue = skb_get_queue_mapping(skb);
64 u8 *brcm_tag; 67 u8 *brcm_tag;
65 68
66 if (skb_cow_head(skb, BRCM_TAG_LEN) < 0) 69 if (skb_cow_head(skb, BRCM_TAG_LEN) < 0)
67 return NULL; 70 return NULL;
68 71
69 /* The Ethernet switch we are interfaced with needs packets to be at 72 /* The Ethernet switch we are interfaced with needs packets to be at
70 * least 64 bytes (including FCS) otherwise they will be discarded when 73 * least 64 bytes (including FCS) otherwise they will be discarded when
71 * they enter the switch port logic. When Broadcom tags are enabled, we 74 * they enter the switch port logic. When Broadcom tags are enabled, we
72 * need to make sure that packets are at least 68 bytes 75 * need to make sure that packets are at least 68 bytes
73 * (including FCS and tag) because the length verification is done after 76 * (including FCS and tag) because the length verification is done after
74 * the Broadcom tag is stripped off the ingress packet. 77 * the Broadcom tag is stripped off the ingress packet.
75 * 78 *
76 * Let dsa_slave_xmit() free the SKB 79 * Let dsa_slave_xmit() free the SKB
77 */ 80 */
78 if (__skb_put_padto(skb, ETH_ZLEN + BRCM_TAG_LEN, false)) 81 if (__skb_put_padto(skb, ETH_ZLEN + BRCM_TAG_LEN, false))
79 return NULL; 82 return NULL;
80 83
81 skb_push(skb, BRCM_TAG_LEN); 84 skb_push(skb, BRCM_TAG_LEN);
82 85
83 if (offset) 86 if (offset)
84 memmove(skb->data, skb->data + BRCM_TAG_LEN, offset); 87 memmove(skb->data, skb->data + BRCM_TAG_LEN, offset);
85 88
86 brcm_tag = skb->data + offset; 89 brcm_tag = skb->data + offset;
87 90
88 /* Set the ingress opcode, traffic class, tag enforcment is 91 /* Set the ingress opcode, traffic class, tag enforcment is
89 * deprecated 92 * deprecated
90 */ 93 */
91 brcm_tag[0] = (1 << BRCM_OPCODE_SHIFT) | 94 brcm_tag[0] = (1 << BRCM_OPCODE_SHIFT) |
92 ((queue & BRCM_IG_TC_MASK) << BRCM_IG_TC_SHIFT); 95 ((queue & BRCM_IG_TC_MASK) << BRCM_IG_TC_SHIFT);
93 brcm_tag[1] = 0; 96 brcm_tag[1] = 0;
94 brcm_tag[2] = 0; 97 brcm_tag[2] = 0;
95 if (dp->index == 8) 98 if (dp->index == 8)
96 brcm_tag[2] = BRCM_IG_DSTMAP2_MASK; 99 brcm_tag[2] = BRCM_IG_DSTMAP2_MASK;
97 brcm_tag[3] = (1 << dp->index) & BRCM_IG_DSTMAP1_MASK; 100 brcm_tag[3] = (1 << dp->index) & BRCM_IG_DSTMAP1_MASK;
98 101
99 /* Now tell the master network device about the desired output queue 102 /* Now tell the master network device about the desired output queue
100 * as well 103 * as well
101 */ 104 */
102 skb_set_queue_mapping(skb, BRCM_TAG_SET_PORT_QUEUE(dp->index, queue)); 105 skb_set_queue_mapping(skb, BRCM_TAG_SET_PORT_QUEUE(dp->index, queue));
103 106
104 return skb; 107 return skb;
105 } 108 }
106 109
107 static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb, 110 static struct sk_buff *brcm_tag_rcv_ll(struct sk_buff *skb,
108 struct net_device *dev, 111 struct net_device *dev,
109 struct packet_type *pt, 112 struct packet_type *pt,
110 unsigned int offset) 113 unsigned int offset)
111 { 114 {
112 int source_port; 115 int source_port;
113 u8 *brcm_tag; 116 u8 *brcm_tag;
114 117
115 if (unlikely(!pskb_may_pull(skb, BRCM_TAG_LEN))) 118 if (unlikely(!pskb_may_pull(skb, BRCM_TAG_LEN)))
116 return NULL; 119 return NULL;
117 120
118 brcm_tag = skb->data - offset; 121 brcm_tag = skb->data - offset;
119 122
120 /* The opcode should never be different than 0b000 */ 123 /* The opcode should never be different than 0b000 */
121 if (unlikely((brcm_tag[0] >> BRCM_OPCODE_SHIFT) & BRCM_OPCODE_MASK)) 124 if (unlikely((brcm_tag[0] >> BRCM_OPCODE_SHIFT) & BRCM_OPCODE_MASK))
122 return NULL; 125 return NULL;
123 126
124 /* We should never see a reserved reason code without knowing how to 127 /* We should never see a reserved reason code without knowing how to
125 * handle it 128 * handle it
126 */ 129 */
127 if (unlikely(brcm_tag[2] & BRCM_EG_RC_RSVD)) 130 if (unlikely(brcm_tag[2] & BRCM_EG_RC_RSVD))
128 return NULL; 131 return NULL;
129 132
130 /* Locate which port this is coming from */ 133 /* Locate which port this is coming from */
131 source_port = brcm_tag[3] & BRCM_EG_PID_MASK; 134 source_port = brcm_tag[3] & BRCM_EG_PID_MASK;
132 135
133 skb->dev = dsa_master_find_slave(dev, 0, source_port); 136 skb->dev = dsa_master_find_slave(dev, 0, source_port);
134 if (!skb->dev) 137 if (!skb->dev)
135 return NULL; 138 return NULL;
136 139
137 /* Remove Broadcom tag and update checksum */ 140 /* Remove Broadcom tag and update checksum */
138 skb_pull_rcsum(skb, BRCM_TAG_LEN); 141 skb_pull_rcsum(skb, BRCM_TAG_LEN);
139 142
140 return skb; 143 return skb;
141 } 144 }
145 #endif
142 146
143 #ifdef CONFIG_NET_DSA_TAG_BRCM 147 #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM)
144 static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb, 148 static struct sk_buff *brcm_tag_xmit(struct sk_buff *skb,
145 struct net_device *dev) 149 struct net_device *dev)
146 { 150 {
147 /* Build the tag after the MAC Source Address */ 151 /* Build the tag after the MAC Source Address */
148 return brcm_tag_xmit_ll(skb, dev, 2 * ETH_ALEN); 152 return brcm_tag_xmit_ll(skb, dev, 2 * ETH_ALEN);
149 } 153 }
150 154
151 155
152 static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev, 156 static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
153 struct packet_type *pt) 157 struct packet_type *pt)
154 { 158 {
155 struct sk_buff *nskb; 159 struct sk_buff *nskb;
156 160
157 /* skb->data points to the EtherType, the tag is right before it */ 161 /* skb->data points to the EtherType, the tag is right before it */
158 nskb = brcm_tag_rcv_ll(skb, dev, pt, 2); 162 nskb = brcm_tag_rcv_ll(skb, dev, pt, 2);
159 if (!nskb) 163 if (!nskb)
160 return nskb; 164 return nskb;
161 165
162 /* Move the Ethernet DA and SA */ 166 /* Move the Ethernet DA and SA */
163 memmove(nskb->data - ETH_HLEN, 167 memmove(nskb->data - ETH_HLEN,
164 nskb->data - ETH_HLEN - BRCM_TAG_LEN, 168 nskb->data - ETH_HLEN - BRCM_TAG_LEN,
165 2 * ETH_ALEN); 169 2 * ETH_ALEN);
166 170
167 return nskb; 171 return nskb;
168 } 172 }
169 173
170 static const struct dsa_device_ops brcm_netdev_ops = { 174 static const struct dsa_device_ops brcm_netdev_ops = {
171 .name = "brcm", 175 .name = "brcm",
172 .proto = DSA_TAG_PROTO_BRCM, 176 .proto = DSA_TAG_PROTO_BRCM,
173 .xmit = brcm_tag_xmit, 177 .xmit = brcm_tag_xmit,
174 .rcv = brcm_tag_rcv, 178 .rcv = brcm_tag_rcv,
175 .overhead = BRCM_TAG_LEN, 179 .overhead = BRCM_TAG_LEN,
176 }; 180 };
177 181
178 DSA_TAG_DRIVER(brcm_netdev_ops); 182 DSA_TAG_DRIVER(brcm_netdev_ops);
179 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM); 183 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM);
180 #endif 184 #endif
181 185
182 #ifdef CONFIG_NET_DSA_TAG_BRCM_PREPEND 186 #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND)
183 static struct sk_buff *brcm_tag_xmit_prepend(struct sk_buff *skb, 187 static struct sk_buff *brcm_tag_xmit_prepend(struct sk_buff *skb,
184 struct net_device *dev) 188 struct net_device *dev)
185 { 189 {
186 /* tag is prepended to the packet */ 190 /* tag is prepended to the packet */
187 return brcm_tag_xmit_ll(skb, dev, 0); 191 return brcm_tag_xmit_ll(skb, dev, 0);
188 } 192 }
189 193
190 static struct sk_buff *brcm_tag_rcv_prepend(struct sk_buff *skb, 194 static struct sk_buff *brcm_tag_rcv_prepend(struct sk_buff *skb,
191 struct net_device *dev, 195 struct net_device *dev,
192 struct packet_type *pt) 196 struct packet_type *pt)
193 { 197 {
194 /* tag is prepended to the packet */ 198 /* tag is prepended to the packet */
195 return brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN); 199 return brcm_tag_rcv_ll(skb, dev, pt, ETH_HLEN);
196 } 200 }
197 201
198 static const struct dsa_device_ops brcm_prepend_netdev_ops = { 202 static const struct dsa_device_ops brcm_prepend_netdev_ops = {
199 .name = "brcm-prepend", 203 .name = "brcm-prepend",
200 .proto = DSA_TAG_PROTO_BRCM_PREPEND, 204 .proto = DSA_TAG_PROTO_BRCM_PREPEND,
201 .xmit = brcm_tag_xmit_prepend, 205 .xmit = brcm_tag_xmit_prepend,
202 .rcv = brcm_tag_rcv_prepend, 206 .rcv = brcm_tag_rcv_prepend,
203 .overhead = BRCM_TAG_LEN, 207 .overhead = BRCM_TAG_LEN,
204 }; 208 };
205 #endif 209 #endif
206 210
207 DSA_TAG_DRIVER(brcm_prepend_netdev_ops); 211 DSA_TAG_DRIVER(brcm_prepend_netdev_ops);
208 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM_PREPEND); 212 MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM_PREPEND);
209 213
210 static struct dsa_tag_driver *dsa_tag_driver_array[] = { 214 static struct dsa_tag_driver *dsa_tag_driver_array[] = {
211 #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM) 215 #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM)
212 &DSA_TAG_DRIVER_NAME(brcm_netdev_ops), 216 &DSA_TAG_DRIVER_NAME(brcm_netdev_ops),
213 #endif 217 #endif
214 #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND) 218 #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND)
215 &DSA_TAG_DRIVER_NAME(brcm_prepend_netdev_ops), 219 &DSA_TAG_DRIVER_NAME(brcm_prepend_netdev_ops),
216 #endif 220 #endif
217 }; 221 };
218 222
219 module_dsa_tag_drivers(dsa_tag_driver_array); 223 module_dsa_tag_drivers(dsa_tag_driver_array);
220 224
221 MODULE_LICENSE("GPL"); 225 MODULE_LICENSE("GPL");
222 226