]>
Commit | Line | Data |
---|---|---|
2874c5fd | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
91da11f8 LB |
2 | /* |
3 | * net/dsa/dsa_priv.h - Hardware switch handling | |
e84665c9 | 4 | * Copyright (c) 2008-2009 Marvell Semiconductor |
91da11f8 LB |
5 | */ |
6 | ||
7 | #ifndef __DSA_PRIV_H | |
8 | #define __DSA_PRIV_H | |
9 | ||
412a1526 | 10 | #include <linux/if_bridge.h> |
91da11f8 | 11 | #include <linux/phy.h> |
5075314e | 12 | #include <linux/netdevice.h> |
04ff53f9 | 13 | #include <linux/netpoll.h> |
ea5dd34b | 14 | #include <net/dsa.h> |
e131a563 | 15 | #include <net/gro_cells.h> |
5075314e | 16 | |
52c96f9d | 17 | enum { |
1faabf74 | 18 | DSA_NOTIFIER_AGEING_TIME, |
52c96f9d VD |
19 | DSA_NOTIFIER_BRIDGE_JOIN, |
20 | DSA_NOTIFIER_BRIDGE_LEAVE, | |
685fb6a4 VD |
21 | DSA_NOTIFIER_FDB_ADD, |
22 | DSA_NOTIFIER_FDB_DEL, | |
8ae5bcdc VD |
23 | DSA_NOTIFIER_MDB_ADD, |
24 | DSA_NOTIFIER_MDB_DEL, | |
d0c627b8 VD |
25 | DSA_NOTIFIER_VLAN_ADD, |
26 | DSA_NOTIFIER_VLAN_DEL, | |
bfcb8132 | 27 | DSA_NOTIFIER_MTU, |
52c96f9d VD |
28 | }; |
29 | ||
1faabf74 VD |
30 | /* DSA_NOTIFIER_AGEING_TIME */ |
31 | struct dsa_notifier_ageing_time_info { | |
32 | struct switchdev_trans *trans; | |
33 | unsigned int ageing_time; | |
1faabf74 VD |
34 | }; |
35 | ||
52c96f9d VD |
36 | /* DSA_NOTIFIER_BRIDGE_* */ |
37 | struct dsa_notifier_bridge_info { | |
38 | struct net_device *br; | |
f66a6a69 | 39 | int tree_index; |
52c96f9d VD |
40 | int sw_index; |
41 | int port; | |
42 | }; | |
43 | ||
685fb6a4 VD |
44 | /* DSA_NOTIFIER_FDB_* */ |
45 | struct dsa_notifier_fdb_info { | |
685fb6a4 VD |
46 | int sw_index; |
47 | int port; | |
2acf4e6a AS |
48 | const unsigned char *addr; |
49 | u16 vid; | |
685fb6a4 VD |
50 | }; |
51 | ||
8ae5bcdc VD |
52 | /* DSA_NOTIFIER_MDB_* */ |
53 | struct dsa_notifier_mdb_info { | |
54 | const struct switchdev_obj_port_mdb *mdb; | |
55 | struct switchdev_trans *trans; | |
56 | int sw_index; | |
57 | int port; | |
58 | }; | |
59 | ||
d0c627b8 VD |
60 | /* DSA_NOTIFIER_VLAN_* */ |
61 | struct dsa_notifier_vlan_info { | |
62 | const struct switchdev_obj_port_vlan *vlan; | |
63 | struct switchdev_trans *trans; | |
64 | int sw_index; | |
65 | int port; | |
66 | }; | |
67 | ||
bfcb8132 VO |
68 | /* DSA_NOTIFIER_MTU */ |
69 | struct dsa_notifier_mtu_info { | |
70 | bool propagate_upstream; | |
71 | int sw_index; | |
72 | int port; | |
73 | int mtu; | |
74 | }; | |
75 | ||
91da11f8 | 76 | struct dsa_slave_priv { |
15240248 | 77 | /* Copy of CPU port xmit for faster access in slave transmit hot path */ |
4ed70ce9 | 78 | struct sk_buff * (*xmit)(struct sk_buff *skb, |
5075314e | 79 | struct net_device *dev); |
e84665c9 | 80 | |
a61bf208 | 81 | struct pcpu_sw_netstats __percpu *stats64; |
f613ed66 | 82 | |
e131a563 AL |
83 | struct gro_cells gcells; |
84 | ||
afdcf151 VD |
85 | /* DSA port data, such as switch, port index, etc. */ |
86 | struct dsa_port *dp; | |
e84665c9 | 87 | |
04ff53f9 FF |
88 | #ifdef CONFIG_NET_POLL_CONTROLLER |
89 | struct netpoll *netpoll; | |
90 | #endif | |
f50f2127 FF |
91 | |
92 | /* TC context */ | |
93 | struct list_head mall_tc_list; | |
91da11f8 LB |
94 | }; |
95 | ||
91da11f8 | 96 | /* dsa.c */ |
c39e2a1d | 97 | const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol); |
4dad81ee | 98 | void dsa_tag_driver_put(const struct dsa_device_ops *ops); |
c39e2a1d | 99 | |
c9eb3e0f | 100 | bool dsa_schedule_work(struct work_struct *work); |
98cdb480 | 101 | const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops); |
91da11f8 | 102 | |
37b8da1a AS |
103 | int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
104 | struct net_device *dev, | |
105 | const unsigned char *addr, u16 vid, | |
87b0984e PM |
106 | u16 flags, |
107 | struct netlink_ext_ack *extack); | |
37b8da1a AS |
108 | int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], |
109 | struct net_device *dev, | |
110 | const unsigned char *addr, u16 vid); | |
a6a71f19 | 111 | |
f2f23566 | 112 | /* master.c */ |
17a22fcf VD |
113 | int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp); |
114 | void dsa_master_teardown(struct net_device *dev); | |
f2f23566 | 115 | |
2231c43b VD |
116 | static inline struct net_device *dsa_master_find_slave(struct net_device *dev, |
117 | int device, int port) | |
3775b1b7 | 118 | { |
2f657a60 VD |
119 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
120 | struct dsa_switch_tree *dst = cpu_dp->dst; | |
7b9a2f4b | 121 | struct dsa_port *dp; |
3775b1b7 | 122 | |
7b9a2f4b VD |
123 | list_for_each_entry(dp, &dst->ports, list) |
124 | if (dp->ds->index == device && dp->index == port && | |
125 | dp->type == DSA_PORT_TYPE_USER) | |
126 | return dp->slave; | |
3775b1b7 | 127 | |
7b9a2f4b | 128 | return NULL; |
3775b1b7 VD |
129 | } |
130 | ||
a40c175b VD |
131 | /* port.c */ |
132 | int dsa_port_set_state(struct dsa_port *dp, u8 state, | |
133 | struct switchdev_trans *trans); | |
8640f8dc | 134 | int dsa_port_enable_rt(struct dsa_port *dp, struct phy_device *phy); |
fb8a6a2b | 135 | int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy); |
8640f8dc | 136 | void dsa_port_disable_rt(struct dsa_port *dp); |
75104db0 | 137 | void dsa_port_disable(struct dsa_port *dp); |
cfbed329 VD |
138 | int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br); |
139 | void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br); | |
4d61d304 VD |
140 | int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering, |
141 | struct switchdev_trans *trans); | |
54a0ed0d | 142 | bool dsa_port_skip_vlan_configuration(struct dsa_port *dp); |
d87bd94e VD |
143 | int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock, |
144 | struct switchdev_trans *trans); | |
bfcb8132 VO |
145 | int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu, |
146 | bool propagate_upstream); | |
2acf4e6a AS |
147 | int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr, |
148 | u16 vid); | |
149 | int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr, | |
150 | u16 vid); | |
de40fc5d | 151 | int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data); |
bb9f6031 | 152 | int dsa_port_mdb_add(const struct dsa_port *dp, |
3a9afea3 VD |
153 | const struct switchdev_obj_port_mdb *mdb, |
154 | struct switchdev_trans *trans); | |
bb9f6031 | 155 | int dsa_port_mdb_del(const struct dsa_port *dp, |
3a9afea3 | 156 | const struct switchdev_obj_port_mdb *mdb); |
ea87005a FF |
157 | int dsa_port_pre_bridge_flags(const struct dsa_port *dp, unsigned long flags, |
158 | struct switchdev_trans *trans); | |
57652796 RK |
159 | int dsa_port_bridge_flags(const struct dsa_port *dp, unsigned long flags, |
160 | struct switchdev_trans *trans); | |
08cc83cc VD |
161 | int dsa_port_mrouter(struct dsa_port *dp, bool mrouter, |
162 | struct switchdev_trans *trans); | |
076e7133 VD |
163 | int dsa_port_vlan_add(struct dsa_port *dp, |
164 | const struct switchdev_obj_port_vlan *vlan, | |
165 | struct switchdev_trans *trans); | |
166 | int dsa_port_vlan_del(struct dsa_port *dp, | |
167 | const struct switchdev_obj_port_vlan *vlan); | |
33615367 SR |
168 | int dsa_port_link_register_of(struct dsa_port *dp); |
169 | void dsa_port_link_unregister_of(struct dsa_port *dp); | |
77373d49 | 170 | extern const struct phylink_mac_ops dsa_port_phylink_mac_ops; |
57ab1ca2 | 171 | |
91da11f8 | 172 | /* slave.c */ |
5075314e | 173 | extern const struct dsa_device_ops notag_netdev_ops; |
91da11f8 | 174 | void dsa_slave_mii_bus_init(struct dsa_switch *ds); |
951259aa | 175 | int dsa_slave_create(struct dsa_port *dp); |
cda5c15b | 176 | void dsa_slave_destroy(struct net_device *slave_dev); |
4d776482 | 177 | bool dsa_slave_dev_check(const struct net_device *dev); |
24462549 FF |
178 | int dsa_slave_suspend(struct net_device *slave_dev); |
179 | int dsa_slave_resume(struct net_device *slave_dev); | |
88e4f0ca VD |
180 | int dsa_slave_register_notifier(void); |
181 | void dsa_slave_unregister_notifier(void); | |
91da11f8 | 182 | |
d945097b VD |
183 | static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev) |
184 | { | |
185 | struct dsa_slave_priv *p = netdev_priv(dev); | |
186 | ||
187 | return p->dp; | |
188 | } | |
189 | ||
d0006b00 VD |
190 | static inline struct net_device * |
191 | dsa_slave_to_master(const struct net_device *dev) | |
192 | { | |
193 | struct dsa_port *dp = dsa_slave_to_port(dev); | |
194 | ||
f8b8b1cd | 195 | return dp->cpu_dp->master; |
d0006b00 VD |
196 | } |
197 | ||
412a1526 VO |
198 | /* If under a bridge with vlan_filtering=0, make sure to send pvid-tagged |
199 | * frames as untagged, since the bridge will not untag them. | |
200 | */ | |
201 | static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb) | |
202 | { | |
203 | struct dsa_port *dp = dsa_slave_to_port(skb->dev); | |
204 | struct vlan_ethhdr *hdr = vlan_eth_hdr(skb); | |
205 | struct net_device *br = dp->bridge_dev; | |
206 | struct net_device *dev = skb->dev; | |
207 | struct net_device *upper_dev; | |
208 | struct list_head *iter; | |
209 | u16 vid, pvid, proto; | |
210 | int err; | |
211 | ||
212 | if (!br || br_vlan_enabled(br)) | |
213 | return skb; | |
214 | ||
215 | err = br_vlan_get_proto(br, &proto); | |
216 | if (err) | |
217 | return skb; | |
218 | ||
219 | /* Move VLAN tag from data to hwaccel */ | |
220 | if (!skb_vlan_tag_present(skb) && hdr->h_vlan_proto == htons(proto)) { | |
221 | skb = skb_vlan_untag(skb); | |
222 | if (!skb) | |
223 | return NULL; | |
224 | } | |
225 | ||
226 | if (!skb_vlan_tag_present(skb)) | |
227 | return skb; | |
228 | ||
229 | vid = skb_vlan_tag_get_id(skb); | |
230 | ||
231 | /* We already run under an RCU read-side critical section since | |
232 | * we are called from netif_receive_skb_list_internal(). | |
233 | */ | |
234 | err = br_vlan_get_pvid_rcu(dev, &pvid); | |
235 | if (err) | |
236 | return skb; | |
237 | ||
238 | if (vid != pvid) | |
239 | return skb; | |
240 | ||
241 | /* The sad part about attempting to untag from DSA is that we | |
242 | * don't know, unless we check, if the skb will end up in | |
243 | * the bridge's data path - br_allowed_ingress() - or not. | |
244 | * For example, there might be an 8021q upper for the | |
245 | * default_pvid of the bridge, which will steal VLAN-tagged traffic | |
246 | * from the bridge's data path. This is a configuration that DSA | |
247 | * supports because vlan_filtering is 0. In that case, we should | |
248 | * definitely keep the tag, to make sure it keeps working. | |
249 | */ | |
250 | netdev_for_each_upper_dev_rcu(dev, upper_dev, iter) { | |
251 | if (!is_vlan_dev(upper_dev)) | |
252 | continue; | |
253 | ||
254 | if (vid == vlan_dev_vlan_id(upper_dev)) | |
255 | return skb; | |
256 | } | |
257 | ||
258 | __vlan_hwaccel_clear_tag(skb); | |
259 | ||
260 | return skb; | |
261 | } | |
262 | ||
f515f192 VD |
263 | /* switch.c */ |
264 | int dsa_switch_register_notifier(struct dsa_switch *ds); | |
265 | void dsa_switch_unregister_notifier(struct dsa_switch *ds); | |
bff33f7e VO |
266 | |
267 | /* dsa2.c */ | |
268 | extern struct list_head dsa_tree_list; | |
269 | ||
91da11f8 | 270 | #endif |