blob: 3e1bd14cc0ab391effc1c6403088df4fe32bbd3a [file] [log] [blame]
Jiri Pirko007f7902014-11-28 14:34:17 +01001/*
2 * include/net/switchdev.h - Switch device API
Jiri Pirko7ea6eb32015-09-24 10:02:41 +02003 * Copyright (c) 2014-2015 Jiri Pirko <jiri@resnulli.us>
Scott Feldmanf8f21472015-03-09 13:59:09 -07004 * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com>
Jiri Pirko007f7902014-11-28 14:34:17 +01005 *
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>
Jiri Pirko03bf0c22015-01-15 23:49:36 +010015#include <linux/notifier.h>
Jiri Pirko7ea6eb32015-09-24 10:02:41 +020016#include <linux/list.h>
Jiri Pirko03bf0c22015-01-15 23:49:36 +010017
Scott Feldman30943332015-05-10 09:47:48 -070018#define SWITCHDEV_F_NO_RECURSE BIT(0)
19
Jiri Pirko7ea6eb32015-09-24 10:02:41 +020020struct switchdev_trans_item {
21 struct list_head list;
22 void *data;
23 void (*destructor)(const void *data);
24};
25
26struct switchdev_trans {
27 struct list_head item_list;
Jiri Pirkof623ab72015-09-24 10:02:49 +020028 bool ph_prepare;
Jiri Pirko7ea6eb32015-09-24 10:02:41 +020029};
30
Jiri Pirko8bdb4272015-09-24 10:02:43 +020031static inline bool switchdev_trans_ph_prepare(struct switchdev_trans *trans)
32{
Jiri Pirkof623ab72015-09-24 10:02:49 +020033 return trans && trans->ph_prepare;
Jiri Pirko8bdb4272015-09-24 10:02:43 +020034}
35
36static inline bool switchdev_trans_ph_commit(struct switchdev_trans *trans)
37{
Jiri Pirkof623ab72015-09-24 10:02:49 +020038 return trans && !trans->ph_prepare;
Jiri Pirko8bdb4272015-09-24 10:02:43 +020039}
40
Scott Feldman30943332015-05-10 09:47:48 -070041enum switchdev_attr_id {
Jiri Pirko1f868392015-10-01 11:03:42 +020042 SWITCHDEV_ATTR_ID_UNDEFINED,
43 SWITCHDEV_ATTR_ID_PORT_PARENT_ID,
44 SWITCHDEV_ATTR_ID_PORT_STP_STATE,
45 SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS,
Scott Feldman30943332015-05-10 09:47:48 -070046};
47
48struct switchdev_attr {
49 enum switchdev_attr_id id;
Scott Feldman30943332015-05-10 09:47:48 -070050 u32 flags;
Scott Feldmanf8e20a92015-05-10 09:47:49 -070051 union {
52 struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
Scott Feldman35636062015-05-10 09:47:51 -070053 u8 stp_state; /* PORT_STP_STATE */
Scott Feldman6004c862015-05-10 09:47:55 -070054 unsigned long brport_flags; /* PORT_BRIDGE_FLAGS */
Scott Feldman42275bd2015-05-13 11:16:50 -070055 } u;
Scott Feldman30943332015-05-10 09:47:48 -070056};
57
Scott Feldman41706042015-03-15 21:07:14 -070058struct fib_info;
59
Scott Feldman491d0f12015-05-10 09:47:52 -070060enum switchdev_obj_id {
Jiri Pirko57d80832015-10-01 11:03:41 +020061 SWITCHDEV_OBJ_ID_UNDEFINED,
62 SWITCHDEV_OBJ_ID_PORT_VLAN,
63 SWITCHDEV_OBJ_ID_IPV4_FIB,
64 SWITCHDEV_OBJ_ID_PORT_FDB,
Scott Feldman491d0f12015-05-10 09:47:52 -070065};
66
Jiri Pirko648b4a92015-10-01 11:03:45 +020067struct switchdev_obj {
68};
69
Jiri Pirko57d80832015-10-01 11:03:41 +020070/* SWITCHDEV_OBJ_ID_PORT_VLAN */
Jiri Pirko8f24f302015-10-01 11:03:43 +020071struct switchdev_obj_port_vlan {
Jiri Pirko648b4a92015-10-01 11:03:45 +020072 struct switchdev_obj obj;
Vivien Didelot44bbcf52015-09-29 12:07:18 -040073 u16 flags;
74 u16 vid_begin;
75 u16 vid_end;
76};
77
Jiri Pirko648b4a92015-10-01 11:03:45 +020078#define SWITCHDEV_OBJ_PORT_VLAN(obj) \
79 container_of(obj, struct switchdev_obj_port_vlan, obj)
80
Jiri Pirko57d80832015-10-01 11:03:41 +020081/* SWITCHDEV_OBJ_ID_IPV4_FIB */
Vivien Didelot44bbcf52015-09-29 12:07:18 -040082struct switchdev_obj_ipv4_fib {
Jiri Pirko648b4a92015-10-01 11:03:45 +020083 struct switchdev_obj obj;
Vivien Didelot44bbcf52015-09-29 12:07:18 -040084 u32 dst;
85 int dst_len;
86 struct fib_info *fi;
87 u8 tos;
88 u8 type;
89 u32 nlflags;
90 u32 tb_id;
91};
92
Jiri Pirko648b4a92015-10-01 11:03:45 +020093#define SWITCHDEV_OBJ_IPV4_FIB(obj) \
94 container_of(obj, struct switchdev_obj_ipv4_fib, obj)
95
Jiri Pirko57d80832015-10-01 11:03:41 +020096/* SWITCHDEV_OBJ_ID_PORT_FDB */
Jiri Pirko52ba57c2015-10-01 11:03:44 +020097struct switchdev_obj_port_fdb {
Jiri Pirko648b4a92015-10-01 11:03:45 +020098 struct switchdev_obj obj;
Vivien Didelot44bbcf52015-09-29 12:07:18 -040099 const unsigned char *addr;
100 u16 vid;
101 u16 ndm_state;
Scott Feldman491d0f12015-05-10 09:47:52 -0700102};
103
Jiri Pirko648b4a92015-10-01 11:03:45 +0200104#define SWITCHDEV_OBJ_PORT_FDB(obj) \
105 container_of(obj, struct switchdev_obj_port_fdb, obj)
106
Jiri Pirko7ea6eb32015-09-24 10:02:41 +0200107void switchdev_trans_item_enqueue(struct switchdev_trans *trans,
108 void *data, void (*destructor)(void const *),
109 struct switchdev_trans_item *tritem);
110void *switchdev_trans_item_dequeue(struct switchdev_trans *trans);
111
Jiri Pirko648b4a92015-10-01 11:03:45 +0200112typedef int switchdev_obj_dump_cb_t(struct switchdev_obj *obj);
113
Scott Feldman41706042015-03-15 21:07:14 -0700114/**
115 * struct switchdev_ops - switchdev operations
116 *
Scott Feldman30943332015-05-10 09:47:48 -0700117 * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
118 *
119 * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
120 *
Vivien Didelot44bbcf52015-09-29 12:07:18 -0400121 * @switchdev_port_obj_add: Add an object to port (see switchdev_obj_*).
Scott Feldman491d0f12015-05-10 09:47:52 -0700122 *
Vivien Didelot44bbcf52015-09-29 12:07:18 -0400123 * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj_*).
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700124 *
Vivien Didelot44bbcf52015-09-29 12:07:18 -0400125 * @switchdev_port_obj_dump: Dump port objects (see switchdev_obj_*).
Scott Feldman41706042015-03-15 21:07:14 -0700126 */
Jiri Pirko9d47c0a2015-05-10 09:47:47 -0700127struct switchdev_ops {
Scott Feldman30943332015-05-10 09:47:48 -0700128 int (*switchdev_port_attr_get)(struct net_device *dev,
129 struct switchdev_attr *attr);
130 int (*switchdev_port_attr_set)(struct net_device *dev,
Jiri Pirko7ea6eb32015-09-24 10:02:41 +0200131 struct switchdev_attr *attr,
132 struct switchdev_trans *trans);
Scott Feldman491d0f12015-05-10 09:47:52 -0700133 int (*switchdev_port_obj_add)(struct net_device *dev,
Vivien Didelotab069002015-09-29 12:07:17 -0400134 enum switchdev_obj_id id,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200135 const struct switchdev_obj *obj,
Jiri Pirko7ea6eb32015-09-24 10:02:41 +0200136 struct switchdev_trans *trans);
Scott Feldman491d0f12015-05-10 09:47:52 -0700137 int (*switchdev_port_obj_del)(struct net_device *dev,
Vivien Didelotab069002015-09-29 12:07:17 -0400138 enum switchdev_obj_id id,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200139 const struct switchdev_obj *obj);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700140 int (*switchdev_port_obj_dump)(struct net_device *dev,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200141 enum switchdev_obj_id id,
142 struct switchdev_obj *obj,
143 switchdev_obj_dump_cb_t *cb);
Scott Feldman41706042015-03-15 21:07:14 -0700144};
145
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700146enum switchdev_notifier_type {
147 SWITCHDEV_FDB_ADD = 1,
148 SWITCHDEV_FDB_DEL,
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100149};
150
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700151struct switchdev_notifier_info {
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100152 struct net_device *dev;
153};
154
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700155struct switchdev_notifier_fdb_info {
156 struct switchdev_notifier_info info; /* must be first */
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100157 const unsigned char *addr;
158 u16 vid;
159};
160
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100161static inline struct net_device *
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700162switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100163{
164 return info->dev;
165}
Jiri Pirko007f7902014-11-28 14:34:17 +0100166
167#ifdef CONFIG_NET_SWITCHDEV
168
Scott Feldman30943332015-05-10 09:47:48 -0700169int switchdev_port_attr_get(struct net_device *dev,
170 struct switchdev_attr *attr);
171int switchdev_port_attr_set(struct net_device *dev,
172 struct switchdev_attr *attr);
Vivien Didelotab069002015-09-29 12:07:17 -0400173int switchdev_port_obj_add(struct net_device *dev, enum switchdev_obj_id id,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200174 const struct switchdev_obj *obj);
Vivien Didelotab069002015-09-29 12:07:17 -0400175int switchdev_port_obj_del(struct net_device *dev, enum switchdev_obj_id id,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200176 const struct switchdev_obj *obj);
Vivien Didelot25f07ad2015-09-29 12:07:16 -0400177int switchdev_port_obj_dump(struct net_device *dev, enum switchdev_obj_id id,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200178 struct switchdev_obj *obj,
179 switchdev_obj_dump_cb_t *cb);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700180int register_switchdev_notifier(struct notifier_block *nb);
181int unregister_switchdev_notifier(struct notifier_block *nb);
182int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
183 struct switchdev_notifier_info *info);
Scott Feldman8793d0a2015-05-10 09:48:04 -0700184int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
185 struct net_device *dev, u32 filter_mask,
186 int nlflags);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700187int switchdev_port_bridge_setlink(struct net_device *dev,
188 struct nlmsghdr *nlh, u16 flags);
189int switchdev_port_bridge_dellink(struct net_device *dev,
190 struct nlmsghdr *nlh, u16 flags);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700191int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
192 u8 tos, u8 type, u32 nlflags, u32 tb_id);
193int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
194 u8 tos, u8 type, u32 tb_id);
195void switchdev_fib_ipv4_abort(struct fib_info *fi);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700196int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
197 struct net_device *dev, const unsigned char *addr,
198 u16 vid, u16 nlm_flags);
199int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
200 struct net_device *dev, const unsigned char *addr,
201 u16 vid);
202int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
203 struct net_device *dev,
204 struct net_device *filter_dev, int idx);
Scott Feldman1a3b2ec2015-07-18 18:24:50 -0700205void switchdev_port_fwd_mark_set(struct net_device *dev,
206 struct net_device *group_dev,
207 bool joining);
Scott Feldman5e8d9042015-03-05 21:21:15 -0800208
Jiri Pirko007f7902014-11-28 14:34:17 +0100209#else
210
Scott Feldman30943332015-05-10 09:47:48 -0700211static inline int switchdev_port_attr_get(struct net_device *dev,
212 struct switchdev_attr *attr)
213{
214 return -EOPNOTSUPP;
215}
216
217static inline int switchdev_port_attr_set(struct net_device *dev,
218 struct switchdev_attr *attr)
219{
220 return -EOPNOTSUPP;
221}
222
Scott Feldman491d0f12015-05-10 09:47:52 -0700223static inline int switchdev_port_obj_add(struct net_device *dev,
Vivien Didelotab069002015-09-29 12:07:17 -0400224 enum switchdev_obj_id id,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200225 const struct switchdev_obj *obj)
Scott Feldman491d0f12015-05-10 09:47:52 -0700226{
227 return -EOPNOTSUPP;
228}
229
230static inline int switchdev_port_obj_del(struct net_device *dev,
Vivien Didelotab069002015-09-29 12:07:17 -0400231 enum switchdev_obj_id id,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200232 const struct switchdev_obj *obj)
Scott Feldman491d0f12015-05-10 09:47:52 -0700233{
234 return -EOPNOTSUPP;
235}
236
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700237static inline int switchdev_port_obj_dump(struct net_device *dev,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200238 enum switchdev_obj_id id,
239 const struct switchdev_obj *obj,
240 switchdev_obj_dump_cb_t *cb)
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700241{
242 return -EOPNOTSUPP;
243}
244
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700245static inline int register_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100246{
247 return 0;
248}
249
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700250static inline int unregister_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100251{
252 return 0;
253}
254
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700255static inline int call_switchdev_notifiers(unsigned long val,
256 struct net_device *dev,
257 struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100258{
259 return NOTIFY_DONE;
260}
261
Scott Feldman8793d0a2015-05-10 09:48:04 -0700262static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid,
263 u32 seq, struct net_device *dev,
264 u32 filter_mask, int nlflags)
265{
266 return -EOPNOTSUPP;
267}
268
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700269static inline int switchdev_port_bridge_setlink(struct net_device *dev,
270 struct nlmsghdr *nlh,
271 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800272{
273 return -EOPNOTSUPP;
274}
275
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700276static inline int switchdev_port_bridge_dellink(struct net_device *dev,
277 struct nlmsghdr *nlh,
278 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800279{
280 return -EOPNOTSUPP;
281}
282
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700283static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
284 struct fib_info *fi,
285 u8 tos, u8 type,
286 u32 nlflags, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800287{
288 return 0;
289}
290
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700291static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
292 struct fib_info *fi,
293 u8 tos, u8 type, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800294{
295 return 0;
296}
297
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700298static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
Scott Feldman8e05fd72015-03-05 21:21:19 -0800299{
300}
301
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700302static inline int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
303 struct net_device *dev,
304 const unsigned char *addr,
305 u16 vid, u16 nlm_flags)
306{
307 return -EOPNOTSUPP;
308}
309
310static inline int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
311 struct net_device *dev,
312 const unsigned char *addr, u16 vid)
313{
314 return -EOPNOTSUPP;
315}
316
317static inline int switchdev_port_fdb_dump(struct sk_buff *skb,
318 struct netlink_callback *cb,
319 struct net_device *dev,
320 struct net_device *filter_dev,
321 int idx)
322{
323 return -EOPNOTSUPP;
324}
325
Scott Feldman1a3b2ec2015-07-18 18:24:50 -0700326static inline void switchdev_port_fwd_mark_set(struct net_device *dev,
327 struct net_device *group_dev,
328 bool joining)
329{
330}
331
Jiri Pirko007f7902014-11-28 14:34:17 +0100332#endif
333
334#endif /* _LINUX_SWITCHDEV_H_ */