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