1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * include/net/switchdev.h - Switch device API
4 * Copyright (c) 2014-2015 Jiri Pirko <jiri@resnulli.us>
5 * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com>
7 #ifndef _LINUX_SWITCHDEV_H_
8 #define _LINUX_SWITCHDEV_H_
10 #include <linux/netdevice.h>
11 #include <linux/notifier.h>
12 #include <linux/list.h>
13 #include <net/ip_fib.h>
15 #define SWITCHDEV_F_NO_RECURSE BIT(0)
16 #define SWITCHDEV_F_SKIP_EOPNOTSUPP BIT(1)
17 #define SWITCHDEV_F_DEFER BIT(2)
19 enum switchdev_attr_id {
20 SWITCHDEV_ATTR_ID_UNDEFINED,
21 SWITCHDEV_ATTR_ID_PORT_STP_STATE,
22 SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS,
23 SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS,
24 SWITCHDEV_ATTR_ID_PORT_MROUTER,
25 SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME,
26 SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING,
27 SWITCHDEV_ATTR_ID_BRIDGE_VLAN_PROTOCOL,
28 SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED,
29 SWITCHDEV_ATTR_ID_BRIDGE_MROUTER,
30 SWITCHDEV_ATTR_ID_MRP_PORT_ROLE,
33 struct switchdev_brport_flags {
38 struct switchdev_attr {
39 struct net_device *orig_dev;
40 enum switchdev_attr_id id;
43 void (*complete)(struct net_device *dev, int err, void *priv);
45 u8 stp_state; /* PORT_STP_STATE */
46 struct switchdev_brport_flags brport_flags; /* PORT_BRIDGE_FLAGS */
47 bool mrouter; /* PORT_MROUTER */
48 clock_t ageing_time; /* BRIDGE_AGEING_TIME */
49 bool vlan_filtering; /* BRIDGE_VLAN_FILTERING */
50 u16 vlan_protocol; /* BRIDGE_VLAN_PROTOCOL */
51 bool mc_disabled; /* MC_DISABLED */
52 u8 mrp_port_role; /* MRP_PORT_ROLE */
56 enum switchdev_obj_id {
57 SWITCHDEV_OBJ_ID_UNDEFINED,
58 SWITCHDEV_OBJ_ID_PORT_VLAN,
59 SWITCHDEV_OBJ_ID_PORT_MDB,
60 SWITCHDEV_OBJ_ID_HOST_MDB,
62 SWITCHDEV_OBJ_ID_RING_TEST_MRP,
63 SWITCHDEV_OBJ_ID_RING_ROLE_MRP,
64 SWITCHDEV_OBJ_ID_RING_STATE_MRP,
65 SWITCHDEV_OBJ_ID_IN_TEST_MRP,
66 SWITCHDEV_OBJ_ID_IN_ROLE_MRP,
67 SWITCHDEV_OBJ_ID_IN_STATE_MRP,
70 struct switchdev_obj {
71 struct net_device *orig_dev;
72 enum switchdev_obj_id id;
75 void (*complete)(struct net_device *dev, int err, void *priv);
78 /* SWITCHDEV_OBJ_ID_PORT_VLAN */
79 struct switchdev_obj_port_vlan {
80 struct switchdev_obj obj;
85 #define SWITCHDEV_OBJ_PORT_VLAN(OBJ) \
86 container_of((OBJ), struct switchdev_obj_port_vlan, obj)
88 /* SWITCHDEV_OBJ_ID_PORT_MDB */
89 struct switchdev_obj_port_mdb {
90 struct switchdev_obj obj;
91 unsigned char addr[ETH_ALEN];
95 #define SWITCHDEV_OBJ_PORT_MDB(OBJ) \
96 container_of((OBJ), struct switchdev_obj_port_mdb, obj)
99 /* SWITCHDEV_OBJ_ID_MRP */
100 struct switchdev_obj_mrp {
101 struct switchdev_obj obj;
102 struct net_device *p_port;
103 struct net_device *s_port;
108 #define SWITCHDEV_OBJ_MRP(OBJ) \
109 container_of((OBJ), struct switchdev_obj_mrp, obj)
111 /* SWITCHDEV_OBJ_ID_RING_TEST_MRP */
112 struct switchdev_obj_ring_test_mrp {
113 struct switchdev_obj obj;
114 /* The value is in us and a value of 0 represents to stop */
122 #define SWITCHDEV_OBJ_RING_TEST_MRP(OBJ) \
123 container_of((OBJ), struct switchdev_obj_ring_test_mrp, obj)
125 /* SWICHDEV_OBJ_ID_RING_ROLE_MRP */
126 struct switchdev_obj_ring_role_mrp {
127 struct switchdev_obj obj;
133 #define SWITCHDEV_OBJ_RING_ROLE_MRP(OBJ) \
134 container_of((OBJ), struct switchdev_obj_ring_role_mrp, obj)
136 struct switchdev_obj_ring_state_mrp {
137 struct switchdev_obj obj;
142 #define SWITCHDEV_OBJ_RING_STATE_MRP(OBJ) \
143 container_of((OBJ), struct switchdev_obj_ring_state_mrp, obj)
145 /* SWITCHDEV_OBJ_ID_IN_TEST_MRP */
146 struct switchdev_obj_in_test_mrp {
147 struct switchdev_obj obj;
148 /* The value is in us and a value of 0 represents to stop */
155 #define SWITCHDEV_OBJ_IN_TEST_MRP(OBJ) \
156 container_of((OBJ), struct switchdev_obj_in_test_mrp, obj)
158 /* SWICHDEV_OBJ_ID_IN_ROLE_MRP */
159 struct switchdev_obj_in_role_mrp {
160 struct switchdev_obj obj;
161 struct net_device *i_port;
168 #define SWITCHDEV_OBJ_IN_ROLE_MRP(OBJ) \
169 container_of((OBJ), struct switchdev_obj_in_role_mrp, obj)
171 struct switchdev_obj_in_state_mrp {
172 struct switchdev_obj obj;
177 #define SWITCHDEV_OBJ_IN_STATE_MRP(OBJ) \
178 container_of((OBJ), struct switchdev_obj_in_state_mrp, obj)
180 typedef int switchdev_obj_dump_cb_t(struct switchdev_obj *obj);
182 enum switchdev_notifier_type {
183 SWITCHDEV_FDB_ADD_TO_BRIDGE = 1,
184 SWITCHDEV_FDB_DEL_TO_BRIDGE,
185 SWITCHDEV_FDB_ADD_TO_DEVICE,
186 SWITCHDEV_FDB_DEL_TO_DEVICE,
187 SWITCHDEV_FDB_OFFLOADED,
188 SWITCHDEV_FDB_FLUSH_TO_BRIDGE,
190 SWITCHDEV_PORT_OBJ_ADD, /* Blocking. */
191 SWITCHDEV_PORT_OBJ_DEL, /* Blocking. */
192 SWITCHDEV_PORT_ATTR_SET, /* May be blocking . */
194 SWITCHDEV_VXLAN_FDB_ADD_TO_BRIDGE,
195 SWITCHDEV_VXLAN_FDB_DEL_TO_BRIDGE,
196 SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE,
197 SWITCHDEV_VXLAN_FDB_DEL_TO_DEVICE,
198 SWITCHDEV_VXLAN_FDB_OFFLOADED,
201 struct switchdev_notifier_info {
202 struct net_device *dev;
203 struct netlink_ext_ack *extack;
206 struct switchdev_notifier_fdb_info {
207 struct switchdev_notifier_info info; /* must be first */
208 const unsigned char *addr;
214 struct switchdev_notifier_port_obj_info {
215 struct switchdev_notifier_info info; /* must be first */
216 const struct switchdev_obj *obj;
220 struct switchdev_notifier_port_attr_info {
221 struct switchdev_notifier_info info; /* must be first */
222 const struct switchdev_attr *attr;
226 static inline struct net_device *
227 switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
232 static inline struct netlink_ext_ack *
233 switchdev_notifier_info_to_extack(const struct switchdev_notifier_info *info)
238 #ifdef CONFIG_NET_SWITCHDEV
240 void switchdev_deferred_process(void);
241 int switchdev_port_attr_set(struct net_device *dev,
242 const struct switchdev_attr *attr,
243 struct netlink_ext_ack *extack);
244 int switchdev_port_obj_add(struct net_device *dev,
245 const struct switchdev_obj *obj,
246 struct netlink_ext_ack *extack);
247 int switchdev_port_obj_del(struct net_device *dev,
248 const struct switchdev_obj *obj);
250 int register_switchdev_notifier(struct notifier_block *nb);
251 int unregister_switchdev_notifier(struct notifier_block *nb);
252 int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
253 struct switchdev_notifier_info *info,
254 struct netlink_ext_ack *extack);
256 int register_switchdev_blocking_notifier(struct notifier_block *nb);
257 int unregister_switchdev_blocking_notifier(struct notifier_block *nb);
258 int call_switchdev_blocking_notifiers(unsigned long val, struct net_device *dev,
259 struct switchdev_notifier_info *info,
260 struct netlink_ext_ack *extack);
262 void switchdev_port_fwd_mark_set(struct net_device *dev,
263 struct net_device *group_dev,
266 int switchdev_handle_port_obj_add(struct net_device *dev,
267 struct switchdev_notifier_port_obj_info *port_obj_info,
268 bool (*check_cb)(const struct net_device *dev),
269 int (*add_cb)(struct net_device *dev,
270 const struct switchdev_obj *obj,
271 struct netlink_ext_ack *extack));
272 int switchdev_handle_port_obj_del(struct net_device *dev,
273 struct switchdev_notifier_port_obj_info *port_obj_info,
274 bool (*check_cb)(const struct net_device *dev),
275 int (*del_cb)(struct net_device *dev,
276 const struct switchdev_obj *obj));
278 int switchdev_handle_port_attr_set(struct net_device *dev,
279 struct switchdev_notifier_port_attr_info *port_attr_info,
280 bool (*check_cb)(const struct net_device *dev),
281 int (*set_cb)(struct net_device *dev,
282 const struct switchdev_attr *attr,
283 struct netlink_ext_ack *extack));
286 static inline void switchdev_deferred_process(void)
290 static inline int switchdev_port_attr_set(struct net_device *dev,
291 const struct switchdev_attr *attr,
292 struct netlink_ext_ack *extack)
297 static inline int switchdev_port_obj_add(struct net_device *dev,
298 const struct switchdev_obj *obj,
299 struct netlink_ext_ack *extack)
304 static inline int switchdev_port_obj_del(struct net_device *dev,
305 const struct switchdev_obj *obj)
310 static inline int register_switchdev_notifier(struct notifier_block *nb)
315 static inline int unregister_switchdev_notifier(struct notifier_block *nb)
320 static inline int call_switchdev_notifiers(unsigned long val,
321 struct net_device *dev,
322 struct switchdev_notifier_info *info,
323 struct netlink_ext_ack *extack)
329 register_switchdev_blocking_notifier(struct notifier_block *nb)
335 unregister_switchdev_blocking_notifier(struct notifier_block *nb)
341 call_switchdev_blocking_notifiers(unsigned long val,
342 struct net_device *dev,
343 struct switchdev_notifier_info *info,
344 struct netlink_ext_ack *extack)
350 switchdev_handle_port_obj_add(struct net_device *dev,
351 struct switchdev_notifier_port_obj_info *port_obj_info,
352 bool (*check_cb)(const struct net_device *dev),
353 int (*add_cb)(struct net_device *dev,
354 const struct switchdev_obj *obj,
355 struct netlink_ext_ack *extack))
361 switchdev_handle_port_obj_del(struct net_device *dev,
362 struct switchdev_notifier_port_obj_info *port_obj_info,
363 bool (*check_cb)(const struct net_device *dev),
364 int (*del_cb)(struct net_device *dev,
365 const struct switchdev_obj *obj))
371 switchdev_handle_port_attr_set(struct net_device *dev,
372 struct switchdev_notifier_port_attr_info *port_attr_info,
373 bool (*check_cb)(const struct net_device *dev),
374 int (*set_cb)(struct net_device *dev,
375 const struct switchdev_attr *attr,
376 struct netlink_ext_ack *extack))
382 #endif /* _LINUX_SWITCHDEV_H_ */