Merge remote-tracking branch 'iommu/next'
[deliverable/linux.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,
d297653d 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
8438884d
OG
230bool switchdev_port_same_parent_id(struct net_device *a,
231 struct net_device *b);
007f790c
JP
232#else
233
793f4014
JP
234static inline void switchdev_deferred_process(void)
235{
236}
237
3094333d
SF
238static inline int switchdev_port_attr_get(struct net_device *dev,
239 struct switchdev_attr *attr)
240{
241 return -EOPNOTSUPP;
242}
243
244static inline int switchdev_port_attr_set(struct net_device *dev,
f7fadf30 245 const struct switchdev_attr *attr)
3094333d
SF
246{
247 return -EOPNOTSUPP;
248}
249
491d0f15 250static inline int switchdev_port_obj_add(struct net_device *dev,
648b4a99 251 const struct switchdev_obj *obj)
491d0f15
SF
252{
253 return -EOPNOTSUPP;
254}
255
256static inline int switchdev_port_obj_del(struct net_device *dev,
648b4a99 257 const struct switchdev_obj *obj)
491d0f15
SF
258{
259 return -EOPNOTSUPP;
260}
261
45d4122c 262static inline int switchdev_port_obj_dump(struct net_device *dev,
648b4a99
JP
263 const struct switchdev_obj *obj,
264 switchdev_obj_dump_cb_t *cb)
45d4122c
SS
265{
266 return -EOPNOTSUPP;
267}
268
ebb9a03a 269static inline int register_switchdev_notifier(struct notifier_block *nb)
03bf0c28
JP
270{
271 return 0;
272}
273
ebb9a03a 274static inline int unregister_switchdev_notifier(struct notifier_block *nb)
03bf0c28
JP
275{
276 return 0;
277}
278
ebb9a03a
JP
279static inline int call_switchdev_notifiers(unsigned long val,
280 struct net_device *dev,
281 struct switchdev_notifier_info *info)
03bf0c28
JP
282{
283 return NOTIFY_DONE;
284}
285
8793d0a6
SF
286static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid,
287 u32 seq, struct net_device *dev,
288 u32 filter_mask, int nlflags)
289{
290 return -EOPNOTSUPP;
291}
292
ebb9a03a
JP
293static inline int switchdev_port_bridge_setlink(struct net_device *dev,
294 struct nlmsghdr *nlh,
295 u16 flags)
8a44dbb2
RP
296{
297 return -EOPNOTSUPP;
298}
299
ebb9a03a
JP
300static inline int switchdev_port_bridge_dellink(struct net_device *dev,
301 struct nlmsghdr *nlh,
302 u16 flags)
8a44dbb2
RP
303{
304 return -EOPNOTSUPP;
305}
306
ebb9a03a
JP
307static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
308 struct fib_info *fi,
309 u8 tos, u8 type,
310 u32 nlflags, u32 tb_id)
5e8d9049
SF
311{
312 return 0;
313}
314
ebb9a03a
JP
315static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
316 struct fib_info *fi,
317 u8 tos, u8 type, u32 tb_id)
5e8d9049
SF
318{
319 return 0;
320}
321
ebb9a03a 322static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
8e05fd71
SF
323{
324}
325
45d4122c
SS
326static inline int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
327 struct net_device *dev,
328 const unsigned char *addr,
329 u16 vid, u16 nlm_flags)
330{
331 return -EOPNOTSUPP;
332}
333
334static inline int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
335 struct net_device *dev,
336 const unsigned char *addr, u16 vid)
337{
338 return -EOPNOTSUPP;
339}
340
341static inline int switchdev_port_fdb_dump(struct sk_buff *skb,
342 struct netlink_callback *cb,
343 struct net_device *dev,
344 struct net_device *filter_dev,
d297653d 345 int *idx)
45d4122c 346{
dd19bde3 347 return *idx;
45d4122c
SS
348}
349
8438884d
OG
350static inline bool switchdev_port_same_parent_id(struct net_device *a,
351 struct net_device *b)
352{
353 return false;
354}
355
007f790c
JP
356#endif
357
358#endif /* _LINUX_SWITCHDEV_H_ */
This page took 0.158582 seconds and 5 git commands to generate.