]>
Commit | Line | Data |
---|---|---|
007f790c JP |
1 | /* |
2 | * include/net/switchdev.h - Switch device API | |
7ea6eb3f | 3 | * Copyright (c) 2014-2015 Jiri Pirko <jiri@resnulli.us> |
f8f21471 | 4 | * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com> |
007f790c JP |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | */ | |
11 | #ifndef _LINUX_SWITCHDEV_H_ | |
12 | #define _LINUX_SWITCHDEV_H_ | |
13 | ||
14 | #include <linux/netdevice.h> | |
03bf0c28 | 15 | #include <linux/notifier.h> |
7ea6eb3f | 16 | #include <linux/list.h> |
850d0cbc | 17 | #include <net/ip_fib.h> |
03bf0c28 | 18 | |
3094333d | 19 | #define SWITCHDEV_F_NO_RECURSE BIT(0) |
464314ea | 20 | #define SWITCHDEV_F_SKIP_EOPNOTSUPP BIT(1) |
0bc05d58 | 21 | #define SWITCHDEV_F_DEFER BIT(2) |
3094333d | 22 | |
7ea6eb3f | 23 | struct switchdev_trans { |
f623ab7f | 24 | bool ph_prepare; |
7ea6eb3f JP |
25 | }; |
26 | ||
8bdb4272 JP |
27 | static inline bool switchdev_trans_ph_prepare(struct switchdev_trans *trans) |
28 | { | |
f623ab7f | 29 | return trans && trans->ph_prepare; |
8bdb4272 JP |
30 | } |
31 | ||
32 | static inline bool switchdev_trans_ph_commit(struct switchdev_trans *trans) | |
33 | { | |
f623ab7f | 34 | return trans && !trans->ph_prepare; |
8bdb4272 JP |
35 | } |
36 | ||
3094333d | 37 | enum switchdev_attr_id { |
1f868398 | 38 | SWITCHDEV_ATTR_ID_UNDEFINED, |
1f868398 JP |
39 | SWITCHDEV_ATTR_ID_PORT_STP_STATE, |
40 | SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS, | |
746dc184 | 41 | SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS, |
6d549648 | 42 | SWITCHDEV_ATTR_ID_PORT_MROUTER, |
f55ac58a | 43 | SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME, |
81435c33 | 44 | SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING, |
147c1e9b | 45 | SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED, |
77041420 | 46 | SWITCHDEV_ATTR_ID_BRIDGE_MROUTER, |
3094333d SF |
47 | }; |
48 | ||
49 | struct switchdev_attr { | |
6ff64f6f | 50 | struct net_device *orig_dev; |
3094333d | 51 | enum switchdev_attr_id id; |
3094333d | 52 | u32 flags; |
7ceb2afb ER |
53 | void *complete_priv; |
54 | void (*complete)(struct net_device *dev, int err, void *priv); | |
f8e20a9f | 55 | union { |
35636062 | 56 | u8 stp_state; /* PORT_STP_STATE */ |
746dc184 | 57 | unsigned long brport_flags; /* PORT_{PRE}_BRIDGE_FLAGS */ |
6d549648 | 58 | bool mrouter; /* PORT_MROUTER */ |
eabfdda9 | 59 | clock_t ageing_time; /* BRIDGE_AGEING_TIME */ |
81435c33 | 60 | bool vlan_filtering; /* BRIDGE_VLAN_FILTERING */ |
147c1e9b | 61 | bool mc_disabled; /* MC_DISABLED */ |
42275bd8 | 62 | } u; |
3094333d SF |
63 | }; |
64 | ||
491d0f15 | 65 | enum switchdev_obj_id { |
57d80838 JP |
66 | SWITCHDEV_OBJ_ID_UNDEFINED, |
67 | SWITCHDEV_OBJ_ID_PORT_VLAN, | |
4d41e125 | 68 | SWITCHDEV_OBJ_ID_PORT_MDB, |
47d5b6db | 69 | SWITCHDEV_OBJ_ID_HOST_MDB, |
491d0f15 SF |
70 | }; |
71 | ||
648b4a99 | 72 | struct switchdev_obj { |
6ff64f6f | 73 | struct net_device *orig_dev; |
9e8f4a54 | 74 | enum switchdev_obj_id id; |
4d429c5d | 75 | u32 flags; |
7ceb2afb ER |
76 | void *complete_priv; |
77 | void (*complete)(struct net_device *dev, int err, void *priv); | |
648b4a99 JP |
78 | }; |
79 | ||
57d80838 | 80 | /* SWITCHDEV_OBJ_ID_PORT_VLAN */ |
8f24f309 | 81 | struct switchdev_obj_port_vlan { |
648b4a99 | 82 | struct switchdev_obj obj; |
44bbcf5c VD |
83 | u16 flags; |
84 | u16 vid_begin; | |
85 | u16 vid_end; | |
86 | }; | |
87 | ||
ec394af5 PM |
88 | #define SWITCHDEV_OBJ_PORT_VLAN(OBJ) \ |
89 | container_of((OBJ), struct switchdev_obj_port_vlan, obj) | |
648b4a99 | 90 | |
4d41e125 ER |
91 | /* SWITCHDEV_OBJ_ID_PORT_MDB */ |
92 | struct switchdev_obj_port_mdb { | |
93 | struct switchdev_obj obj; | |
94 | unsigned char addr[ETH_ALEN]; | |
95 | u16 vid; | |
96 | }; | |
97 | ||
ec394af5 PM |
98 | #define SWITCHDEV_OBJ_PORT_MDB(OBJ) \ |
99 | container_of((OBJ), struct switchdev_obj_port_mdb, obj) | |
4d41e125 | 100 | |
648b4a99 JP |
101 | typedef int switchdev_obj_dump_cb_t(struct switchdev_obj *obj); |
102 | ||
ebb9a03a | 103 | enum switchdev_notifier_type { |
6b26b51b AS |
104 | SWITCHDEV_FDB_ADD_TO_BRIDGE = 1, |
105 | SWITCHDEV_FDB_DEL_TO_BRIDGE, | |
106 | SWITCHDEV_FDB_ADD_TO_DEVICE, | |
107 | SWITCHDEV_FDB_DEL_TO_DEVICE, | |
9fe8bcec | 108 | SWITCHDEV_FDB_OFFLOADED, |
9a997353 | 109 | |
aa4efe21 PM |
110 | SWITCHDEV_PORT_OBJ_ADD, /* Blocking. */ |
111 | SWITCHDEV_PORT_OBJ_DEL, /* Blocking. */ | |
1cb33af1 | 112 | SWITCHDEV_PORT_ATTR_SET, /* May be blocking . */ |
aa4efe21 | 113 | |
5728ae0d PM |
114 | SWITCHDEV_VXLAN_FDB_ADD_TO_BRIDGE, |
115 | SWITCHDEV_VXLAN_FDB_DEL_TO_BRIDGE, | |
9a997353 PM |
116 | SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE, |
117 | SWITCHDEV_VXLAN_FDB_DEL_TO_DEVICE, | |
0efe1173 | 118 | SWITCHDEV_VXLAN_FDB_OFFLOADED, |
3aeb6617 JP |
119 | }; |
120 | ||
ebb9a03a | 121 | struct switchdev_notifier_info { |
03bf0c28 | 122 | struct net_device *dev; |
479c86dc | 123 | struct netlink_ext_ack *extack; |
03bf0c28 JP |
124 | }; |
125 | ||
ebb9a03a JP |
126 | struct switchdev_notifier_fdb_info { |
127 | struct switchdev_notifier_info info; /* must be first */ | |
3aeb6617 JP |
128 | const unsigned char *addr; |
129 | u16 vid; | |
e9ba0fbc IS |
130 | u8 added_by_user:1, |
131 | offloaded:1; | |
3aeb6617 JP |
132 | }; |
133 | ||
aa4efe21 PM |
134 | struct switchdev_notifier_port_obj_info { |
135 | struct switchdev_notifier_info info; /* must be first */ | |
136 | const struct switchdev_obj *obj; | |
137 | struct switchdev_trans *trans; | |
138 | bool handled; | |
139 | }; | |
140 | ||
1cb33af1 FF |
141 | struct switchdev_notifier_port_attr_info { |
142 | struct switchdev_notifier_info info; /* must be first */ | |
143 | const struct switchdev_attr *attr; | |
144 | struct switchdev_trans *trans; | |
145 | bool handled; | |
146 | }; | |
147 | ||
03bf0c28 | 148 | static inline struct net_device * |
ebb9a03a | 149 | switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info) |
03bf0c28 JP |
150 | { |
151 | return info->dev; | |
152 | } | |
007f790c | 153 | |
479c86dc PM |
154 | static inline struct netlink_ext_ack * |
155 | switchdev_notifier_info_to_extack(const struct switchdev_notifier_info *info) | |
156 | { | |
157 | return info->extack; | |
158 | } | |
159 | ||
007f790c JP |
160 | #ifdef CONFIG_NET_SWITCHDEV |
161 | ||
793f4014 | 162 | void switchdev_deferred_process(void); |
3094333d | 163 | int switchdev_port_attr_set(struct net_device *dev, |
f7fadf30 | 164 | const struct switchdev_attr *attr); |
9e8f4a54 | 165 | int switchdev_port_obj_add(struct net_device *dev, |
69b7320e PM |
166 | const struct switchdev_obj *obj, |
167 | struct netlink_ext_ack *extack); | |
9e8f4a54 | 168 | int switchdev_port_obj_del(struct net_device *dev, |
648b4a99 | 169 | const struct switchdev_obj *obj); |
a93e3b17 | 170 | |
ebb9a03a JP |
171 | int register_switchdev_notifier(struct notifier_block *nb); |
172 | int unregister_switchdev_notifier(struct notifier_block *nb); | |
173 | int call_switchdev_notifiers(unsigned long val, struct net_device *dev, | |
6685987c PM |
174 | struct switchdev_notifier_info *info, |
175 | struct netlink_ext_ack *extack); | |
a93e3b17 PM |
176 | |
177 | int register_switchdev_blocking_notifier(struct notifier_block *nb); | |
178 | int unregister_switchdev_blocking_notifier(struct notifier_block *nb); | |
179 | int call_switchdev_blocking_notifiers(unsigned long val, struct net_device *dev, | |
479c86dc PM |
180 | struct switchdev_notifier_info *info, |
181 | struct netlink_ext_ack *extack); | |
a93e3b17 | 182 | |
1a3b2ec9 SF |
183 | void switchdev_port_fwd_mark_set(struct net_device *dev, |
184 | struct net_device *group_dev, | |
185 | bool joining); | |
5e8d9049 | 186 | |
f30f0601 PM |
187 | int switchdev_handle_port_obj_add(struct net_device *dev, |
188 | struct switchdev_notifier_port_obj_info *port_obj_info, | |
189 | bool (*check_cb)(const struct net_device *dev), | |
190 | int (*add_cb)(struct net_device *dev, | |
191 | const struct switchdev_obj *obj, | |
69213513 PM |
192 | struct switchdev_trans *trans, |
193 | struct netlink_ext_ack *extack)); | |
f30f0601 PM |
194 | int switchdev_handle_port_obj_del(struct net_device *dev, |
195 | struct switchdev_notifier_port_obj_info *port_obj_info, | |
196 | bool (*check_cb)(const struct net_device *dev), | |
197 | int (*del_cb)(struct net_device *dev, | |
198 | const struct switchdev_obj *obj)); | |
199 | ||
1cb33af1 FF |
200 | int switchdev_handle_port_attr_set(struct net_device *dev, |
201 | struct switchdev_notifier_port_attr_info *port_attr_info, | |
202 | bool (*check_cb)(const struct net_device *dev), | |
203 | int (*set_cb)(struct net_device *dev, | |
204 | const struct switchdev_attr *attr, | |
205 | struct switchdev_trans *trans)); | |
007f790c JP |
206 | #else |
207 | ||
793f4014 JP |
208 | static inline void switchdev_deferred_process(void) |
209 | { | |
210 | } | |
211 | ||
3094333d | 212 | static inline int switchdev_port_attr_set(struct net_device *dev, |
f7fadf30 | 213 | const struct switchdev_attr *attr) |
3094333d SF |
214 | { |
215 | return -EOPNOTSUPP; | |
216 | } | |
217 | ||
491d0f15 | 218 | static inline int switchdev_port_obj_add(struct net_device *dev, |
69b7320e PM |
219 | const struct switchdev_obj *obj, |
220 | struct netlink_ext_ack *extack) | |
491d0f15 SF |
221 | { |
222 | return -EOPNOTSUPP; | |
223 | } | |
224 | ||
225 | static inline int switchdev_port_obj_del(struct net_device *dev, | |
648b4a99 | 226 | const struct switchdev_obj *obj) |
491d0f15 SF |
227 | { |
228 | return -EOPNOTSUPP; | |
229 | } | |
230 | ||
ebb9a03a | 231 | static inline int register_switchdev_notifier(struct notifier_block *nb) |
03bf0c28 JP |
232 | { |
233 | return 0; | |
234 | } | |
235 | ||
ebb9a03a | 236 | static inline int unregister_switchdev_notifier(struct notifier_block *nb) |
03bf0c28 JP |
237 | { |
238 | return 0; | |
239 | } | |
240 | ||
ebb9a03a JP |
241 | static inline int call_switchdev_notifiers(unsigned long val, |
242 | struct net_device *dev, | |
6685987c PM |
243 | struct switchdev_notifier_info *info, |
244 | struct netlink_ext_ack *extack) | |
03bf0c28 JP |
245 | { |
246 | return NOTIFY_DONE; | |
247 | } | |
248 | ||
a93e3b17 PM |
249 | static inline int |
250 | register_switchdev_blocking_notifier(struct notifier_block *nb) | |
251 | { | |
252 | return 0; | |
253 | } | |
254 | ||
255 | static inline int | |
256 | unregister_switchdev_blocking_notifier(struct notifier_block *nb) | |
257 | { | |
258 | return 0; | |
259 | } | |
260 | ||
261 | static inline int | |
262 | call_switchdev_blocking_notifiers(unsigned long val, | |
263 | struct net_device *dev, | |
479c86dc PM |
264 | struct switchdev_notifier_info *info, |
265 | struct netlink_ext_ack *extack) | |
a93e3b17 PM |
266 | { |
267 | return NOTIFY_DONE; | |
268 | } | |
269 | ||
f30f0601 PM |
270 | static inline int |
271 | switchdev_handle_port_obj_add(struct net_device *dev, | |
272 | struct switchdev_notifier_port_obj_info *port_obj_info, | |
273 | bool (*check_cb)(const struct net_device *dev), | |
274 | int (*add_cb)(struct net_device *dev, | |
275 | const struct switchdev_obj *obj, | |
69213513 PM |
276 | struct switchdev_trans *trans, |
277 | struct netlink_ext_ack *extack)) | |
f30f0601 PM |
278 | { |
279 | return 0; | |
280 | } | |
281 | ||
282 | static inline int | |
283 | switchdev_handle_port_obj_del(struct net_device *dev, | |
284 | struct switchdev_notifier_port_obj_info *port_obj_info, | |
285 | bool (*check_cb)(const struct net_device *dev), | |
286 | int (*del_cb)(struct net_device *dev, | |
287 | const struct switchdev_obj *obj)) | |
288 | { | |
289 | return 0; | |
290 | } | |
291 | ||
1cb33af1 FF |
292 | static inline int |
293 | switchdev_handle_port_attr_set(struct net_device *dev, | |
294 | struct switchdev_notifier_port_attr_info *port_attr_info, | |
295 | bool (*check_cb)(const struct net_device *dev), | |
296 | int (*set_cb)(struct net_device *dev, | |
297 | const struct switchdev_attr *attr, | |
298 | struct switchdev_trans *trans)) | |
299 | { | |
300 | return 0; | |
301 | } | |
007f790c JP |
302 | #endif |
303 | ||
304 | #endif /* _LINUX_SWITCHDEV_H_ */ |