2 * include/net/switchdev.h - Switch device API
3 * Copyright (c) 2014-2015 Jiri Pirko <jiri@resnulli.us>
4 * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com>
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.
11 #ifndef _LINUX_SWITCHDEV_H_
12 #define _LINUX_SWITCHDEV_H_
14 #include <linux/netdevice.h>
15 #include <linux/notifier.h>
16 #include <linux/list.h>
17 #include <net/ip_fib.h>
19 #define SWITCHDEV_F_NO_RECURSE BIT(0)
20 #define SWITCHDEV_F_SKIP_EOPNOTSUPP BIT(1)
21 #define SWITCHDEV_F_DEFER BIT(2)
23 struct switchdev_trans {
27 static inline bool switchdev_trans_ph_prepare(struct switchdev_trans *trans)
29 return trans && trans->ph_prepare;
32 static inline bool switchdev_trans_ph_commit(struct switchdev_trans *trans)
34 return trans && !trans->ph_prepare;
37 enum switchdev_attr_id {
38 SWITCHDEV_ATTR_ID_UNDEFINED,
39 SWITCHDEV_ATTR_ID_PORT_STP_STATE,
40 SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS,
41 SWITCHDEV_ATTR_ID_PORT_PRE_BRIDGE_FLAGS,
42 SWITCHDEV_ATTR_ID_PORT_MROUTER,
43 SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME,
44 SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING,
45 SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED,
46 SWITCHDEV_ATTR_ID_BRIDGE_MROUTER,
49 struct switchdev_attr {
50 struct net_device *orig_dev;
51 enum switchdev_attr_id id;
54 void (*complete)(struct net_device *dev, int err, void *priv);
56 u8 stp_state; /* PORT_STP_STATE */
57 unsigned long brport_flags; /* PORT_{PRE}_BRIDGE_FLAGS */
58 bool mrouter; /* PORT_MROUTER */
59 clock_t ageing_time; /* BRIDGE_AGEING_TIME */
60 bool vlan_filtering; /* BRIDGE_VLAN_FILTERING */
61 bool mc_disabled; /* MC_DISABLED */
65 enum switchdev_obj_id {
66 SWITCHDEV_OBJ_ID_UNDEFINED,
67 SWITCHDEV_OBJ_ID_PORT_VLAN,
68 SWITCHDEV_OBJ_ID_PORT_MDB,
69 SWITCHDEV_OBJ_ID_HOST_MDB,
72 struct switchdev_obj {
73 struct net_device *orig_dev;
74 enum switchdev_obj_id id;
77 void (*complete)(struct net_device *dev, int err, void *priv);
80 /* SWITCHDEV_OBJ_ID_PORT_VLAN */
81 struct switchdev_obj_port_vlan {
82 struct switchdev_obj obj;
88 #define SWITCHDEV_OBJ_PORT_VLAN(OBJ) \
89 container_of((OBJ), struct switchdev_obj_port_vlan, obj)
91 /* SWITCHDEV_OBJ_ID_PORT_MDB */
92 struct switchdev_obj_port_mdb {
93 struct switchdev_obj obj;
94 unsigned char addr[ETH_ALEN];
98 #define SWITCHDEV_OBJ_PORT_MDB(OBJ) \
99 container_of((OBJ), struct switchdev_obj_port_mdb, obj)
101 typedef int switchdev_obj_dump_cb_t(struct switchdev_obj *obj);
103 enum switchdev_notifier_type {
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,
108 SWITCHDEV_FDB_OFFLOADED,
110 SWITCHDEV_PORT_OBJ_ADD, /* Blocking. */
111 SWITCHDEV_PORT_OBJ_DEL, /* Blocking. */
112 SWITCHDEV_PORT_ATTR_SET, /* May be blocking . */
114 SWITCHDEV_VXLAN_FDB_ADD_TO_BRIDGE,
115 SWITCHDEV_VXLAN_FDB_DEL_TO_BRIDGE,
116 SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE,
117 SWITCHDEV_VXLAN_FDB_DEL_TO_DEVICE,
118 SWITCHDEV_VXLAN_FDB_OFFLOADED,
121 struct switchdev_notifier_info {
122 struct net_device *dev;
123 struct netlink_ext_ack *extack;
126 struct switchdev_notifier_fdb_info {
127 struct switchdev_notifier_info info; /* must be first */
128 const unsigned char *addr;
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;
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;
148 static inline struct net_device *
149 switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
154 static inline struct netlink_ext_ack *
155 switchdev_notifier_info_to_extack(const struct switchdev_notifier_info *info)
160 #ifdef CONFIG_NET_SWITCHDEV
162 void switchdev_deferred_process(void);
163 int switchdev_port_attr_set(struct net_device *dev,
164 const struct switchdev_attr *attr);
165 int switchdev_port_obj_add(struct net_device *dev,
166 const struct switchdev_obj *obj,
167 struct netlink_ext_ack *extack);
168 int switchdev_port_obj_del(struct net_device *dev,
169 const struct switchdev_obj *obj);
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,
174 struct switchdev_notifier_info *info,
175 struct netlink_ext_ack *extack);
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,
180 struct switchdev_notifier_info *info,
181 struct netlink_ext_ack *extack);
183 void switchdev_port_fwd_mark_set(struct net_device *dev,
184 struct net_device *group_dev,
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,
192 struct switchdev_trans *trans,
193 struct netlink_ext_ack *extack));
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));
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));
208 static inline void switchdev_deferred_process(void)
212 static inline int switchdev_port_attr_set(struct net_device *dev,
213 const struct switchdev_attr *attr)
218 static inline int switchdev_port_obj_add(struct net_device *dev,
219 const struct switchdev_obj *obj,
220 struct netlink_ext_ack *extack)
225 static inline int switchdev_port_obj_del(struct net_device *dev,
226 const struct switchdev_obj *obj)
231 static inline int register_switchdev_notifier(struct notifier_block *nb)
236 static inline int unregister_switchdev_notifier(struct notifier_block *nb)
241 static inline int call_switchdev_notifiers(unsigned long val,
242 struct net_device *dev,
243 struct switchdev_notifier_info *info,
244 struct netlink_ext_ack *extack)
250 register_switchdev_blocking_notifier(struct notifier_block *nb)
256 unregister_switchdev_blocking_notifier(struct notifier_block *nb)
262 call_switchdev_blocking_notifiers(unsigned long val,
263 struct net_device *dev,
264 struct switchdev_notifier_info *info,
265 struct netlink_ext_ack *extack)
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,
276 struct switchdev_trans *trans,
277 struct netlink_ext_ack *extack))
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))
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))
304 #endif /* _LINUX_SWITCHDEV_H_ */