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