blob: 1e394f1176b6516bee4be2cd23b6c9069aca8a38 [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 Pirko69f5df42015-09-24 10:02:40 +020020enum switchdev_trans_ph {
Scott Feldman30943332015-05-10 09:47:48 -070021 SWITCHDEV_TRANS_NONE,
22 SWITCHDEV_TRANS_PREPARE,
23 SWITCHDEV_TRANS_ABORT,
24 SWITCHDEV_TRANS_COMMIT,
25};
26
Jiri Pirko7ea6eb32015-09-24 10:02:41 +020027struct switchdev_trans_item {
28 struct list_head list;
29 void *data;
30 void (*destructor)(const void *data);
31};
32
33struct switchdev_trans {
34 struct list_head item_list;
35};
36
Scott Feldman30943332015-05-10 09:47:48 -070037enum switchdev_attr_id {
38 SWITCHDEV_ATTR_UNDEFINED,
Scott Feldmanf8e20a92015-05-10 09:47:49 -070039 SWITCHDEV_ATTR_PORT_PARENT_ID,
Scott Feldman35636062015-05-10 09:47:51 -070040 SWITCHDEV_ATTR_PORT_STP_STATE,
Scott Feldman6004c862015-05-10 09:47:55 -070041 SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS,
Scott Feldman30943332015-05-10 09:47:48 -070042};
43
44struct switchdev_attr {
45 enum switchdev_attr_id id;
Jiri Pirko69f5df42015-09-24 10:02:40 +020046 enum switchdev_trans_ph trans_ph;
Scott Feldman30943332015-05-10 09:47:48 -070047 u32 flags;
Scott Feldmanf8e20a92015-05-10 09:47:49 -070048 union {
49 struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
Scott Feldman35636062015-05-10 09:47:51 -070050 u8 stp_state; /* PORT_STP_STATE */
Scott Feldman6004c862015-05-10 09:47:55 -070051 unsigned long brport_flags; /* PORT_BRIDGE_FLAGS */
Scott Feldman42275bd2015-05-13 11:16:50 -070052 } u;
Scott Feldman30943332015-05-10 09:47:48 -070053};
54
Scott Feldman41706042015-03-15 21:07:14 -070055struct fib_info;
56
Scott Feldman491d0f12015-05-10 09:47:52 -070057enum switchdev_obj_id {
58 SWITCHDEV_OBJ_UNDEFINED,
Scott Feldman6fc30162015-05-10 09:47:53 -070059 SWITCHDEV_OBJ_PORT_VLAN,
Scott Feldman58c2cb12015-05-10 09:48:06 -070060 SWITCHDEV_OBJ_IPV4_FIB,
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070061 SWITCHDEV_OBJ_PORT_FDB,
Scott Feldman491d0f12015-05-10 09:47:52 -070062};
63
64struct switchdev_obj {
65 enum switchdev_obj_id id;
Jiri Pirko69f5df42015-09-24 10:02:40 +020066 enum switchdev_trans_ph trans_ph;
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070067 int (*cb)(struct net_device *dev, struct switchdev_obj *obj);
Scott Feldman6fc30162015-05-10 09:47:53 -070068 union {
Scott Feldman5eb764e2015-05-12 23:03:53 -070069 struct switchdev_obj_vlan { /* PORT_VLAN */
Scott Feldman6fc30162015-05-10 09:47:53 -070070 u16 flags;
Scott Feldman3e3a78b2015-06-22 00:27:16 -070071 u16 vid_begin;
Scott Feldman6fc30162015-05-10 09:47:53 -070072 u16 vid_end;
73 } vlan;
Scott Feldman58c2cb12015-05-10 09:48:06 -070074 struct switchdev_obj_ipv4_fib { /* IPV4_FIB */
75 u32 dst;
76 int dst_len;
77 struct fib_info *fi;
78 u8 tos;
79 u8 type;
80 u32 nlflags;
81 u32 tb_id;
82 } ipv4_fib;
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070083 struct switchdev_obj_fdb { /* PORT_FDB */
David S. Millercdf09692015-08-11 12:00:37 -070084 const unsigned char *addr;
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070085 u16 vid;
Vivien Didelotce80e7b2015-08-10 09:09:52 -040086 u16 ndm_state;
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070087 } fdb;
Scott Feldman42275bd2015-05-13 11:16:50 -070088 } u;
Scott Feldman491d0f12015-05-10 09:47:52 -070089};
90
Jiri Pirko7ea6eb32015-09-24 10:02:41 +020091void switchdev_trans_item_enqueue(struct switchdev_trans *trans,
92 void *data, void (*destructor)(void const *),
93 struct switchdev_trans_item *tritem);
94void *switchdev_trans_item_dequeue(struct switchdev_trans *trans);
95
Scott Feldman41706042015-03-15 21:07:14 -070096/**
97 * struct switchdev_ops - switchdev operations
98 *
Scott Feldman30943332015-05-10 09:47:48 -070099 * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
100 *
101 * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
102 *
Scott Feldman491d0f12015-05-10 09:47:52 -0700103 * @switchdev_port_obj_add: Add an object to port (see switchdev_obj).
104 *
105 * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj).
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700106 *
107 * @switchdev_port_obj_dump: Dump port objects (see switchdev_obj).
Scott Feldman41706042015-03-15 21:07:14 -0700108 */
Jiri Pirko9d47c0a2015-05-10 09:47:47 -0700109struct switchdev_ops {
Scott Feldman30943332015-05-10 09:47:48 -0700110 int (*switchdev_port_attr_get)(struct net_device *dev,
111 struct switchdev_attr *attr);
112 int (*switchdev_port_attr_set)(struct net_device *dev,
Jiri Pirko7ea6eb32015-09-24 10:02:41 +0200113 struct switchdev_attr *attr,
114 struct switchdev_trans *trans);
Scott Feldman491d0f12015-05-10 09:47:52 -0700115 int (*switchdev_port_obj_add)(struct net_device *dev,
Jiri Pirko7ea6eb32015-09-24 10:02:41 +0200116 struct switchdev_obj *obj,
117 struct switchdev_trans *trans);
Scott Feldman491d0f12015-05-10 09:47:52 -0700118 int (*switchdev_port_obj_del)(struct net_device *dev,
119 struct switchdev_obj *obj);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700120 int (*switchdev_port_obj_dump)(struct net_device *dev,
121 struct switchdev_obj *obj);
Scott Feldman41706042015-03-15 21:07:14 -0700122};
123
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700124enum switchdev_notifier_type {
125 SWITCHDEV_FDB_ADD = 1,
126 SWITCHDEV_FDB_DEL,
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100127};
128
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700129struct switchdev_notifier_info {
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100130 struct net_device *dev;
131};
132
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700133struct switchdev_notifier_fdb_info {
134 struct switchdev_notifier_info info; /* must be first */
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100135 const unsigned char *addr;
136 u16 vid;
137};
138
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100139static inline struct net_device *
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700140switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100141{
142 return info->dev;
143}
Jiri Pirko007f7902014-11-28 14:34:17 +0100144
145#ifdef CONFIG_NET_SWITCHDEV
146
Scott Feldman30943332015-05-10 09:47:48 -0700147int switchdev_port_attr_get(struct net_device *dev,
148 struct switchdev_attr *attr);
149int switchdev_port_attr_set(struct net_device *dev,
150 struct switchdev_attr *attr);
Scott Feldman491d0f12015-05-10 09:47:52 -0700151int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj);
152int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700153int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700154int register_switchdev_notifier(struct notifier_block *nb);
155int unregister_switchdev_notifier(struct notifier_block *nb);
156int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
157 struct switchdev_notifier_info *info);
Scott Feldman8793d0a2015-05-10 09:48:04 -0700158int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
159 struct net_device *dev, u32 filter_mask,
160 int nlflags);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700161int switchdev_port_bridge_setlink(struct net_device *dev,
162 struct nlmsghdr *nlh, u16 flags);
163int switchdev_port_bridge_dellink(struct net_device *dev,
164 struct nlmsghdr *nlh, u16 flags);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700165int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
166 u8 tos, u8 type, u32 nlflags, u32 tb_id);
167int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
168 u8 tos, u8 type, u32 tb_id);
169void switchdev_fib_ipv4_abort(struct fib_info *fi);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700170int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
171 struct net_device *dev, const unsigned char *addr,
172 u16 vid, u16 nlm_flags);
173int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
174 struct net_device *dev, const unsigned char *addr,
175 u16 vid);
176int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
177 struct net_device *dev,
178 struct net_device *filter_dev, int idx);
Scott Feldman1a3b2ec2015-07-18 18:24:50 -0700179void switchdev_port_fwd_mark_set(struct net_device *dev,
180 struct net_device *group_dev,
181 bool joining);
Scott Feldman5e8d9042015-03-05 21:21:15 -0800182
Jiri Pirko007f7902014-11-28 14:34:17 +0100183#else
184
Scott Feldman30943332015-05-10 09:47:48 -0700185static inline int switchdev_port_attr_get(struct net_device *dev,
186 struct switchdev_attr *attr)
187{
188 return -EOPNOTSUPP;
189}
190
191static inline int switchdev_port_attr_set(struct net_device *dev,
192 struct switchdev_attr *attr)
193{
194 return -EOPNOTSUPP;
195}
196
Scott Feldman491d0f12015-05-10 09:47:52 -0700197static inline int switchdev_port_obj_add(struct net_device *dev,
198 struct switchdev_obj *obj)
199{
200 return -EOPNOTSUPP;
201}
202
203static inline int switchdev_port_obj_del(struct net_device *dev,
204 struct switchdev_obj *obj)
205{
206 return -EOPNOTSUPP;
207}
208
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700209static inline int switchdev_port_obj_dump(struct net_device *dev,
210 struct switchdev_obj *obj)
211{
212 return -EOPNOTSUPP;
213}
214
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700215static inline int register_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100216{
217 return 0;
218}
219
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700220static inline int unregister_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100221{
222 return 0;
223}
224
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700225static inline int call_switchdev_notifiers(unsigned long val,
226 struct net_device *dev,
227 struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100228{
229 return NOTIFY_DONE;
230}
231
Scott Feldman8793d0a2015-05-10 09:48:04 -0700232static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid,
233 u32 seq, struct net_device *dev,
234 u32 filter_mask, int nlflags)
235{
236 return -EOPNOTSUPP;
237}
238
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700239static inline int switchdev_port_bridge_setlink(struct net_device *dev,
240 struct nlmsghdr *nlh,
241 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800242{
243 return -EOPNOTSUPP;
244}
245
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700246static inline int switchdev_port_bridge_dellink(struct net_device *dev,
247 struct nlmsghdr *nlh,
248 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800249{
250 return -EOPNOTSUPP;
251}
252
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700253static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
254 struct fib_info *fi,
255 u8 tos, u8 type,
256 u32 nlflags, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800257{
258 return 0;
259}
260
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700261static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
262 struct fib_info *fi,
263 u8 tos, u8 type, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800264{
265 return 0;
266}
267
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700268static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
Scott Feldman8e05fd72015-03-05 21:21:19 -0800269{
270}
271
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700272static inline int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
273 struct net_device *dev,
274 const unsigned char *addr,
275 u16 vid, u16 nlm_flags)
276{
277 return -EOPNOTSUPP;
278}
279
280static inline int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
281 struct net_device *dev,
282 const unsigned char *addr, u16 vid)
283{
284 return -EOPNOTSUPP;
285}
286
287static inline int switchdev_port_fdb_dump(struct sk_buff *skb,
288 struct netlink_callback *cb,
289 struct net_device *dev,
290 struct net_device *filter_dev,
291 int idx)
292{
293 return -EOPNOTSUPP;
294}
295
Scott Feldman1a3b2ec2015-07-18 18:24:50 -0700296static inline void switchdev_port_fwd_mark_set(struct net_device *dev,
297 struct net_device *group_dev,
298 bool joining)
299{
300}
301
Jiri Pirko007f7902014-11-28 14:34:17 +0100302#endif
303
304#endif /* _LINUX_SWITCHDEV_H_ */