blob: f84ecf4e5d77d4d38511303fd361efabfc206ec6 [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;
Jiri Pirkof8db8342015-09-24 10:02:42 +020035 enum switchdev_trans_ph ph;
Jiri Pirko7ea6eb32015-09-24 10:02:41 +020036};
37
Jiri Pirko8bdb4272015-09-24 10:02:43 +020038static inline bool switchdev_trans_ph_prepare(struct switchdev_trans *trans)
39{
40 return trans && trans->ph == SWITCHDEV_TRANS_PREPARE;
41}
42
43static inline bool switchdev_trans_ph_commit(struct switchdev_trans *trans)
44{
45 return trans && trans->ph == SWITCHDEV_TRANS_COMMIT;
46}
47
Scott Feldman30943332015-05-10 09:47:48 -070048enum switchdev_attr_id {
49 SWITCHDEV_ATTR_UNDEFINED,
Scott Feldmanf8e20a92015-05-10 09:47:49 -070050 SWITCHDEV_ATTR_PORT_PARENT_ID,
Scott Feldman35636062015-05-10 09:47:51 -070051 SWITCHDEV_ATTR_PORT_STP_STATE,
Scott Feldman6004c862015-05-10 09:47:55 -070052 SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS,
Scott Feldman30943332015-05-10 09:47:48 -070053};
54
55struct switchdev_attr {
56 enum switchdev_attr_id id;
Scott Feldman30943332015-05-10 09:47:48 -070057 u32 flags;
Scott Feldmanf8e20a92015-05-10 09:47:49 -070058 union {
59 struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
Scott Feldman35636062015-05-10 09:47:51 -070060 u8 stp_state; /* PORT_STP_STATE */
Scott Feldman6004c862015-05-10 09:47:55 -070061 unsigned long brport_flags; /* PORT_BRIDGE_FLAGS */
Scott Feldman42275bd2015-05-13 11:16:50 -070062 } u;
Scott Feldman30943332015-05-10 09:47:48 -070063};
64
Scott Feldman41706042015-03-15 21:07:14 -070065struct fib_info;
66
Scott Feldman491d0f12015-05-10 09:47:52 -070067enum switchdev_obj_id {
68 SWITCHDEV_OBJ_UNDEFINED,
Scott Feldman6fc30162015-05-10 09:47:53 -070069 SWITCHDEV_OBJ_PORT_VLAN,
Scott Feldman58c2cb12015-05-10 09:48:06 -070070 SWITCHDEV_OBJ_IPV4_FIB,
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070071 SWITCHDEV_OBJ_PORT_FDB,
Scott Feldman491d0f12015-05-10 09:47:52 -070072};
73
74struct switchdev_obj {
75 enum switchdev_obj_id id;
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070076 int (*cb)(struct net_device *dev, struct switchdev_obj *obj);
Scott Feldman6fc30162015-05-10 09:47:53 -070077 union {
Scott Feldman5eb764e2015-05-12 23:03:53 -070078 struct switchdev_obj_vlan { /* PORT_VLAN */
Scott Feldman6fc30162015-05-10 09:47:53 -070079 u16 flags;
Scott Feldman3e3a78b2015-06-22 00:27:16 -070080 u16 vid_begin;
Scott Feldman6fc30162015-05-10 09:47:53 -070081 u16 vid_end;
82 } vlan;
Scott Feldman58c2cb12015-05-10 09:48:06 -070083 struct switchdev_obj_ipv4_fib { /* IPV4_FIB */
84 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 } ipv4_fib;
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070092 struct switchdev_obj_fdb { /* PORT_FDB */
David S. Millercdf09692015-08-11 12:00:37 -070093 const unsigned char *addr;
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070094 u16 vid;
Vivien Didelotce80e7b2015-08-10 09:09:52 -040095 u16 ndm_state;
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070096 } fdb;
Scott Feldman42275bd2015-05-13 11:16:50 -070097 } u;
Scott Feldman491d0f12015-05-10 09:47:52 -070098};
99
Jiri Pirko7ea6eb32015-09-24 10:02:41 +0200100void switchdev_trans_item_enqueue(struct switchdev_trans *trans,
101 void *data, void (*destructor)(void const *),
102 struct switchdev_trans_item *tritem);
103void *switchdev_trans_item_dequeue(struct switchdev_trans *trans);
104
Scott Feldman41706042015-03-15 21:07:14 -0700105/**
106 * struct switchdev_ops - switchdev operations
107 *
Scott Feldman30943332015-05-10 09:47:48 -0700108 * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
109 *
110 * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
111 *
Scott Feldman491d0f12015-05-10 09:47:52 -0700112 * @switchdev_port_obj_add: Add an object to port (see switchdev_obj).
113 *
114 * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj).
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700115 *
116 * @switchdev_port_obj_dump: Dump port objects (see switchdev_obj).
Scott Feldman41706042015-03-15 21:07:14 -0700117 */
Jiri Pirko9d47c0a2015-05-10 09:47:47 -0700118struct switchdev_ops {
Scott Feldman30943332015-05-10 09:47:48 -0700119 int (*switchdev_port_attr_get)(struct net_device *dev,
120 struct switchdev_attr *attr);
121 int (*switchdev_port_attr_set)(struct net_device *dev,
Jiri Pirko7ea6eb32015-09-24 10:02:41 +0200122 struct switchdev_attr *attr,
123 struct switchdev_trans *trans);
Scott Feldman491d0f12015-05-10 09:47:52 -0700124 int (*switchdev_port_obj_add)(struct net_device *dev,
Jiri Pirko7ea6eb32015-09-24 10:02:41 +0200125 struct switchdev_obj *obj,
126 struct switchdev_trans *trans);
Scott Feldman491d0f12015-05-10 09:47:52 -0700127 int (*switchdev_port_obj_del)(struct net_device *dev,
128 struct switchdev_obj *obj);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700129 int (*switchdev_port_obj_dump)(struct net_device *dev,
130 struct switchdev_obj *obj);
Scott Feldman41706042015-03-15 21:07:14 -0700131};
132
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700133enum switchdev_notifier_type {
134 SWITCHDEV_FDB_ADD = 1,
135 SWITCHDEV_FDB_DEL,
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100136};
137
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700138struct switchdev_notifier_info {
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100139 struct net_device *dev;
140};
141
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700142struct switchdev_notifier_fdb_info {
143 struct switchdev_notifier_info info; /* must be first */
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100144 const unsigned char *addr;
145 u16 vid;
146};
147
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100148static inline struct net_device *
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700149switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100150{
151 return info->dev;
152}
Jiri Pirko007f7902014-11-28 14:34:17 +0100153
154#ifdef CONFIG_NET_SWITCHDEV
155
Scott Feldman30943332015-05-10 09:47:48 -0700156int switchdev_port_attr_get(struct net_device *dev,
157 struct switchdev_attr *attr);
158int switchdev_port_attr_set(struct net_device *dev,
159 struct switchdev_attr *attr);
Scott Feldman491d0f12015-05-10 09:47:52 -0700160int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj);
161int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700162int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700163int register_switchdev_notifier(struct notifier_block *nb);
164int unregister_switchdev_notifier(struct notifier_block *nb);
165int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
166 struct switchdev_notifier_info *info);
Scott Feldman8793d0a2015-05-10 09:48:04 -0700167int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
168 struct net_device *dev, u32 filter_mask,
169 int nlflags);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700170int switchdev_port_bridge_setlink(struct net_device *dev,
171 struct nlmsghdr *nlh, u16 flags);
172int switchdev_port_bridge_dellink(struct net_device *dev,
173 struct nlmsghdr *nlh, u16 flags);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700174int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
175 u8 tos, u8 type, u32 nlflags, u32 tb_id);
176int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
177 u8 tos, u8 type, u32 tb_id);
178void switchdev_fib_ipv4_abort(struct fib_info *fi);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700179int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
180 struct net_device *dev, const unsigned char *addr,
181 u16 vid, u16 nlm_flags);
182int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
183 struct net_device *dev, const unsigned char *addr,
184 u16 vid);
185int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
186 struct net_device *dev,
187 struct net_device *filter_dev, int idx);
Scott Feldman1a3b2ec2015-07-18 18:24:50 -0700188void switchdev_port_fwd_mark_set(struct net_device *dev,
189 struct net_device *group_dev,
190 bool joining);
Scott Feldman5e8d9042015-03-05 21:21:15 -0800191
Jiri Pirko007f7902014-11-28 14:34:17 +0100192#else
193
Scott Feldman30943332015-05-10 09:47:48 -0700194static inline int switchdev_port_attr_get(struct net_device *dev,
195 struct switchdev_attr *attr)
196{
197 return -EOPNOTSUPP;
198}
199
200static inline int switchdev_port_attr_set(struct net_device *dev,
201 struct switchdev_attr *attr)
202{
203 return -EOPNOTSUPP;
204}
205
Scott Feldman491d0f12015-05-10 09:47:52 -0700206static inline int switchdev_port_obj_add(struct net_device *dev,
207 struct switchdev_obj *obj)
208{
209 return -EOPNOTSUPP;
210}
211
212static inline int switchdev_port_obj_del(struct net_device *dev,
213 struct switchdev_obj *obj)
214{
215 return -EOPNOTSUPP;
216}
217
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700218static inline int switchdev_port_obj_dump(struct net_device *dev,
219 struct switchdev_obj *obj)
220{
221 return -EOPNOTSUPP;
222}
223
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700224static inline int register_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100225{
226 return 0;
227}
228
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700229static inline int unregister_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100230{
231 return 0;
232}
233
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700234static inline int call_switchdev_notifiers(unsigned long val,
235 struct net_device *dev,
236 struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100237{
238 return NOTIFY_DONE;
239}
240
Scott Feldman8793d0a2015-05-10 09:48:04 -0700241static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid,
242 u32 seq, struct net_device *dev,
243 u32 filter_mask, int nlflags)
244{
245 return -EOPNOTSUPP;
246}
247
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700248static inline int switchdev_port_bridge_setlink(struct net_device *dev,
249 struct nlmsghdr *nlh,
250 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800251{
252 return -EOPNOTSUPP;
253}
254
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700255static inline int switchdev_port_bridge_dellink(struct net_device *dev,
256 struct nlmsghdr *nlh,
257 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800258{
259 return -EOPNOTSUPP;
260}
261
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700262static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
263 struct fib_info *fi,
264 u8 tos, u8 type,
265 u32 nlflags, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800266{
267 return 0;
268}
269
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700270static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
271 struct fib_info *fi,
272 u8 tos, u8 type, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800273{
274 return 0;
275}
276
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700277static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
Scott Feldman8e05fd72015-03-05 21:21:19 -0800278{
279}
280
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700281static inline int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
282 struct net_device *dev,
283 const unsigned char *addr,
284 u16 vid, u16 nlm_flags)
285{
286 return -EOPNOTSUPP;
287}
288
289static inline int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
290 struct net_device *dev,
291 const unsigned char *addr, u16 vid)
292{
293 return -EOPNOTSUPP;
294}
295
296static inline int switchdev_port_fdb_dump(struct sk_buff *skb,
297 struct netlink_callback *cb,
298 struct net_device *dev,
299 struct net_device *filter_dev,
300 int idx)
301{
302 return -EOPNOTSUPP;
303}
304
Scott Feldman1a3b2ec2015-07-18 18:24:50 -0700305static inline void switchdev_port_fwd_mark_set(struct net_device *dev,
306 struct net_device *group_dev,
307 bool joining)
308{
309}
310
Jiri Pirko007f7902014-11-28 14:34:17 +0100311#endif
312
313#endif /* _LINUX_SWITCHDEV_H_ */