Merge remote-tracking branches 'asoc/topic/fsl-spdif', 'asoc/topic/hdmi', 'asoc/topic...
[linux-2.6-block.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
JP
45 SWITCHDEV_ATTR_ID_UNDEFINED,
46 SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
47 SWITCHDEV_ATTR_ID_PORT_STP_STATE,
48 SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS,
f55ac58a 49 SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME,
81435c33 50 SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING,
3094333d
SF
51};
52
53struct switchdev_attr {
6ff64f6f 54 struct net_device *orig_dev;
3094333d 55 enum switchdev_attr_id id;
3094333d 56 u32 flags;
7ceb2afb
ER
57 void *complete_priv;
58 void (*complete)(struct net_device *dev, int err, void *priv);
f8e20a9f
SF
59 union {
60 struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
35636062 61 u8 stp_state; /* PORT_STP_STATE */
6004c867 62 unsigned long brport_flags; /* PORT_BRIDGE_FLAGS */
eabfdda9 63 clock_t ageing_time; /* BRIDGE_AGEING_TIME */
81435c33 64 bool vlan_filtering; /* BRIDGE_VLAN_FILTERING */
42275bd8 65 } u;
3094333d
SF
66};
67
491d0f15 68enum switchdev_obj_id {
57d80838
JP
69 SWITCHDEV_OBJ_ID_UNDEFINED,
70 SWITCHDEV_OBJ_ID_PORT_VLAN,
71 SWITCHDEV_OBJ_ID_IPV4_FIB,
72 SWITCHDEV_OBJ_ID_PORT_FDB,
4d41e125 73 SWITCHDEV_OBJ_ID_PORT_MDB,
491d0f15
SF
74};
75
648b4a99 76struct switchdev_obj {
6ff64f6f 77 struct net_device *orig_dev;
9e8f4a54 78 enum switchdev_obj_id id;
4d429c5d 79 u32 flags;
7ceb2afb
ER
80 void *complete_priv;
81 void (*complete)(struct net_device *dev, int err, void *priv);
648b4a99
JP
82};
83
57d80838 84/* SWITCHDEV_OBJ_ID_PORT_VLAN */
8f24f309 85struct switchdev_obj_port_vlan {
648b4a99 86 struct switchdev_obj obj;
44bbcf5c
VD
87 u16 flags;
88 u16 vid_begin;
89 u16 vid_end;
90};
91
648b4a99
JP
92#define SWITCHDEV_OBJ_PORT_VLAN(obj) \
93 container_of(obj, struct switchdev_obj_port_vlan, obj)
94
57d80838 95/* SWITCHDEV_OBJ_ID_IPV4_FIB */
44bbcf5c 96struct switchdev_obj_ipv4_fib {
648b4a99 97 struct switchdev_obj obj;
44bbcf5c
VD
98 u32 dst;
99 int dst_len;
da4ed551 100 struct fib_info *fi;
44bbcf5c
VD
101 u8 tos;
102 u8 type;
103 u32 nlflags;
104 u32 tb_id;
105};
106
648b4a99
JP
107#define SWITCHDEV_OBJ_IPV4_FIB(obj) \
108 container_of(obj, struct switchdev_obj_ipv4_fib, obj)
109
57d80838 110/* SWITCHDEV_OBJ_ID_PORT_FDB */
52ba57cf 111struct switchdev_obj_port_fdb {
648b4a99 112 struct switchdev_obj obj;
850d0cbc 113 unsigned char addr[ETH_ALEN];
44bbcf5c
VD
114 u16 vid;
115 u16 ndm_state;
491d0f15
SF
116};
117
648b4a99
JP
118#define SWITCHDEV_OBJ_PORT_FDB(obj) \
119 container_of(obj, struct switchdev_obj_port_fdb, obj)
120
4d41e125
ER
121/* SWITCHDEV_OBJ_ID_PORT_MDB */
122struct switchdev_obj_port_mdb {
123 struct switchdev_obj obj;
124 unsigned char addr[ETH_ALEN];
125 u16 vid;
126};
127
128#define SWITCHDEV_OBJ_PORT_MDB(obj) \
129 container_of(obj, struct switchdev_obj_port_mdb, obj)
130
7ea6eb3f
JP
131void switchdev_trans_item_enqueue(struct switchdev_trans *trans,
132 void *data, void (*destructor)(void const *),
133 struct switchdev_trans_item *tritem);
134void *switchdev_trans_item_dequeue(struct switchdev_trans *trans);
135
648b4a99
JP
136typedef int switchdev_obj_dump_cb_t(struct switchdev_obj *obj);
137
4170604f
SF
138/**
139 * struct switchdev_ops - switchdev operations
140 *
3094333d
SF
141 * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
142 *
143 * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
144 *
44bbcf5c 145 * @switchdev_port_obj_add: Add an object to port (see switchdev_obj_*).
491d0f15 146 *
44bbcf5c 147 * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj_*).
45d4122c 148 *
44bbcf5c 149 * @switchdev_port_obj_dump: Dump port objects (see switchdev_obj_*).
4170604f 150 */
9d47c0a2 151struct switchdev_ops {
3094333d
SF
152 int (*switchdev_port_attr_get)(struct net_device *dev,
153 struct switchdev_attr *attr);
154 int (*switchdev_port_attr_set)(struct net_device *dev,
f7fadf30 155 const struct switchdev_attr *attr,
7ea6eb3f 156 struct switchdev_trans *trans);
491d0f15 157 int (*switchdev_port_obj_add)(struct net_device *dev,
648b4a99 158 const struct switchdev_obj *obj,
7ea6eb3f 159 struct switchdev_trans *trans);
491d0f15 160 int (*switchdev_port_obj_del)(struct net_device *dev,
648b4a99 161 const struct switchdev_obj *obj);
45d4122c 162 int (*switchdev_port_obj_dump)(struct net_device *dev,
648b4a99
JP
163 struct switchdev_obj *obj,
164 switchdev_obj_dump_cb_t *cb);
4170604f
SF
165};
166
ebb9a03a
JP
167enum switchdev_notifier_type {
168 SWITCHDEV_FDB_ADD = 1,
169 SWITCHDEV_FDB_DEL,
3aeb6617
JP
170};
171
ebb9a03a 172struct switchdev_notifier_info {
03bf0c28
JP
173 struct net_device *dev;
174};
175
ebb9a03a
JP
176struct switchdev_notifier_fdb_info {
177 struct switchdev_notifier_info info; /* must be first */
3aeb6617
JP
178 const unsigned char *addr;
179 u16 vid;
180};
181
03bf0c28 182static inline struct net_device *
ebb9a03a 183switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
03bf0c28
JP
184{
185 return info->dev;
186}
007f790c
JP
187
188#ifdef CONFIG_NET_SWITCHDEV
189
793f4014 190void switchdev_deferred_process(void);
3094333d
SF
191int switchdev_port_attr_get(struct net_device *dev,
192 struct switchdev_attr *attr);
193int switchdev_port_attr_set(struct net_device *dev,
f7fadf30 194 const struct switchdev_attr *attr);
9e8f4a54 195int switchdev_port_obj_add(struct net_device *dev,
648b4a99 196 const struct switchdev_obj *obj);
9e8f4a54 197int switchdev_port_obj_del(struct net_device *dev,
648b4a99 198 const struct switchdev_obj *obj);
9e8f4a54 199int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj,
648b4a99 200 switchdev_obj_dump_cb_t *cb);
ebb9a03a
JP
201int register_switchdev_notifier(struct notifier_block *nb);
202int unregister_switchdev_notifier(struct notifier_block *nb);
203int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
204 struct switchdev_notifier_info *info);
8793d0a6
SF
205int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
206 struct net_device *dev, u32 filter_mask,
207 int nlflags);
ebb9a03a
JP
208int switchdev_port_bridge_setlink(struct net_device *dev,
209 struct nlmsghdr *nlh, u16 flags);
210int switchdev_port_bridge_dellink(struct net_device *dev,
211 struct nlmsghdr *nlh, u16 flags);
ebb9a03a
JP
212int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
213 u8 tos, u8 type, u32 nlflags, u32 tb_id);
214int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
215 u8 tos, u8 type, u32 tb_id);
216void switchdev_fib_ipv4_abort(struct fib_info *fi);
45d4122c
SS
217int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
218 struct net_device *dev, const unsigned char *addr,
219 u16 vid, u16 nlm_flags);
220int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
221 struct net_device *dev, const unsigned char *addr,
222 u16 vid);
223int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
224 struct net_device *dev,
225 struct net_device *filter_dev, int idx);
1a3b2ec9
SF
226void switchdev_port_fwd_mark_set(struct net_device *dev,
227 struct net_device *group_dev,
228 bool joining);
5e8d9049 229
007f790c
JP
230#else
231
793f4014
JP
232static inline void switchdev_deferred_process(void)
233{
234}
235
3094333d
SF
236static inline int switchdev_port_attr_get(struct net_device *dev,
237 struct switchdev_attr *attr)
238{
239 return -EOPNOTSUPP;
240}
241
242static inline int switchdev_port_attr_set(struct net_device *dev,
f7fadf30 243 const struct switchdev_attr *attr)
3094333d
SF
244{
245 return -EOPNOTSUPP;
246}
247
491d0f15 248static inline int switchdev_port_obj_add(struct net_device *dev,
648b4a99 249 const struct switchdev_obj *obj)
491d0f15
SF
250{
251 return -EOPNOTSUPP;
252}
253
254static inline int switchdev_port_obj_del(struct net_device *dev,
648b4a99 255 const struct switchdev_obj *obj)
491d0f15
SF
256{
257 return -EOPNOTSUPP;
258}
259
45d4122c 260static inline int switchdev_port_obj_dump(struct net_device *dev,
648b4a99
JP
261 const struct switchdev_obj *obj,
262 switchdev_obj_dump_cb_t *cb)
45d4122c
SS
263{
264 return -EOPNOTSUPP;
265}
266
ebb9a03a 267static inline int register_switchdev_notifier(struct notifier_block *nb)
03bf0c28
JP
268{
269 return 0;
270}
271
ebb9a03a 272static inline int unregister_switchdev_notifier(struct notifier_block *nb)
03bf0c28
JP
273{
274 return 0;
275}
276
ebb9a03a
JP
277static inline int call_switchdev_notifiers(unsigned long val,
278 struct net_device *dev,
279 struct switchdev_notifier_info *info)
03bf0c28
JP
280{
281 return NOTIFY_DONE;
282}
283
8793d0a6
SF
284static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid,
285 u32 seq, struct net_device *dev,
286 u32 filter_mask, int nlflags)
287{
288 return -EOPNOTSUPP;
289}
290
ebb9a03a
JP
291static inline int switchdev_port_bridge_setlink(struct net_device *dev,
292 struct nlmsghdr *nlh,
293 u16 flags)
8a44dbb2
RP
294{
295 return -EOPNOTSUPP;
296}
297
ebb9a03a
JP
298static inline int switchdev_port_bridge_dellink(struct net_device *dev,
299 struct nlmsghdr *nlh,
300 u16 flags)
8a44dbb2
RP
301{
302 return -EOPNOTSUPP;
303}
304
ebb9a03a
JP
305static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
306 struct fib_info *fi,
307 u8 tos, u8 type,
308 u32 nlflags, u32 tb_id)
5e8d9049
SF
309{
310 return 0;
311}
312
ebb9a03a
JP
313static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
314 struct fib_info *fi,
315 u8 tos, u8 type, u32 tb_id)
5e8d9049
SF
316{
317 return 0;
318}
319
ebb9a03a 320static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
8e05fd71
SF
321{
322}
323
45d4122c
SS
324static inline int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
325 struct net_device *dev,
326 const unsigned char *addr,
327 u16 vid, u16 nlm_flags)
328{
329 return -EOPNOTSUPP;
330}
331
332static inline int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
333 struct net_device *dev,
334 const unsigned char *addr, u16 vid)
335{
336 return -EOPNOTSUPP;
337}
338
339static inline int switchdev_port_fdb_dump(struct sk_buff *skb,
340 struct netlink_callback *cb,
341 struct net_device *dev,
342 struct net_device *filter_dev,
343 int idx)
344{
24cb7055 345 return idx;
45d4122c
SS
346}
347
1a3b2ec9
SF
348static inline void switchdev_port_fwd_mark_set(struct net_device *dev,
349 struct net_device *group_dev,
350 bool joining)
351{
352}
353
007f790c
JP
354#endif
355
356#endif /* _LINUX_SWITCHDEV_H_ */