blob: 61f129bd74b237129fc67d120a794037e3500951 [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 Feldmanf55ac582015-10-08 19:23:17 -070046 SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME,
Scott Feldman30943332015-05-10 09:47:48 -070047};
48
49struct switchdev_attr {
50 enum switchdev_attr_id id;
Scott Feldman30943332015-05-10 09:47:48 -070051 u32 flags;
Scott Feldmanf8e20a92015-05-10 09:47:49 -070052 union {
53 struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
Scott Feldman35636062015-05-10 09:47:51 -070054 u8 stp_state; /* PORT_STP_STATE */
Scott Feldman6004c862015-05-10 09:47:55 -070055 unsigned long brport_flags; /* PORT_BRIDGE_FLAGS */
Scott Feldmanf55ac582015-10-08 19:23:17 -070056 u32 ageing_time; /* BRIDGE_AGEING_TIME */
Scott Feldman42275bd2015-05-13 11:16:50 -070057 } u;
Scott Feldman30943332015-05-10 09:47:48 -070058};
59
Scott Feldman41706042015-03-15 21:07:14 -070060struct fib_info;
61
Scott Feldman491d0f12015-05-10 09:47:52 -070062enum switchdev_obj_id {
Jiri Pirko57d80832015-10-01 11:03:41 +020063 SWITCHDEV_OBJ_ID_UNDEFINED,
64 SWITCHDEV_OBJ_ID_PORT_VLAN,
65 SWITCHDEV_OBJ_ID_IPV4_FIB,
66 SWITCHDEV_OBJ_ID_PORT_FDB,
Scott Feldman491d0f12015-05-10 09:47:52 -070067};
68
Jiri Pirko648b4a92015-10-01 11:03:45 +020069struct switchdev_obj {
Jiri Pirko9e8f4a52015-10-01 11:03:46 +020070 enum switchdev_obj_id id;
Jiri Pirko648b4a92015-10-01 11:03:45 +020071};
72
Jiri Pirko57d80832015-10-01 11:03:41 +020073/* SWITCHDEV_OBJ_ID_PORT_VLAN */
Jiri Pirko8f24f302015-10-01 11:03:43 +020074struct switchdev_obj_port_vlan {
Jiri Pirko648b4a92015-10-01 11:03:45 +020075 struct switchdev_obj obj;
Vivien Didelot44bbcf52015-09-29 12:07:18 -040076 u16 flags;
77 u16 vid_begin;
78 u16 vid_end;
79};
80
Jiri Pirko648b4a92015-10-01 11:03:45 +020081#define SWITCHDEV_OBJ_PORT_VLAN(obj) \
82 container_of(obj, struct switchdev_obj_port_vlan, obj)
83
Jiri Pirko57d80832015-10-01 11:03:41 +020084/* SWITCHDEV_OBJ_ID_IPV4_FIB */
Vivien Didelot44bbcf52015-09-29 12:07:18 -040085struct switchdev_obj_ipv4_fib {
Jiri Pirko648b4a92015-10-01 11:03:45 +020086 struct switchdev_obj obj;
Vivien Didelot44bbcf52015-09-29 12:07:18 -040087 u32 dst;
88 int dst_len;
89 struct fib_info *fi;
90 u8 tos;
91 u8 type;
92 u32 nlflags;
93 u32 tb_id;
94};
95
Jiri Pirko648b4a92015-10-01 11:03:45 +020096#define SWITCHDEV_OBJ_IPV4_FIB(obj) \
97 container_of(obj, struct switchdev_obj_ipv4_fib, obj)
98
Jiri Pirko57d80832015-10-01 11:03:41 +020099/* SWITCHDEV_OBJ_ID_PORT_FDB */
Jiri Pirko52ba57c2015-10-01 11:03:44 +0200100struct switchdev_obj_port_fdb {
Jiri Pirko648b4a92015-10-01 11:03:45 +0200101 struct switchdev_obj obj;
Vivien Didelot44bbcf52015-09-29 12:07:18 -0400102 const unsigned char *addr;
103 u16 vid;
104 u16 ndm_state;
Scott Feldman491d0f12015-05-10 09:47:52 -0700105};
106
Jiri Pirko648b4a92015-10-01 11:03:45 +0200107#define SWITCHDEV_OBJ_PORT_FDB(obj) \
108 container_of(obj, struct switchdev_obj_port_fdb, obj)
109
Jiri Pirko7ea6eb32015-09-24 10:02:41 +0200110void switchdev_trans_item_enqueue(struct switchdev_trans *trans,
111 void *data, void (*destructor)(void const *),
112 struct switchdev_trans_item *tritem);
113void *switchdev_trans_item_dequeue(struct switchdev_trans *trans);
114
Jiri Pirko648b4a92015-10-01 11:03:45 +0200115typedef int switchdev_obj_dump_cb_t(struct switchdev_obj *obj);
116
Scott Feldman41706042015-03-15 21:07:14 -0700117/**
118 * struct switchdev_ops - switchdev operations
119 *
Scott Feldman30943332015-05-10 09:47:48 -0700120 * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
121 *
122 * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
123 *
Vivien Didelot44bbcf52015-09-29 12:07:18 -0400124 * @switchdev_port_obj_add: Add an object to port (see switchdev_obj_*).
Scott Feldman491d0f12015-05-10 09:47:52 -0700125 *
Vivien Didelot44bbcf52015-09-29 12:07:18 -0400126 * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj_*).
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700127 *
Vivien Didelot44bbcf52015-09-29 12:07:18 -0400128 * @switchdev_port_obj_dump: Dump port objects (see switchdev_obj_*).
Scott Feldman41706042015-03-15 21:07:14 -0700129 */
Jiri Pirko9d47c0a2015-05-10 09:47:47 -0700130struct switchdev_ops {
Scott Feldman30943332015-05-10 09:47:48 -0700131 int (*switchdev_port_attr_get)(struct net_device *dev,
132 struct switchdev_attr *attr);
133 int (*switchdev_port_attr_set)(struct net_device *dev,
Jiri Pirko7ea6eb32015-09-24 10:02:41 +0200134 struct switchdev_attr *attr,
135 struct switchdev_trans *trans);
Scott Feldman491d0f12015-05-10 09:47:52 -0700136 int (*switchdev_port_obj_add)(struct net_device *dev,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200137 const struct switchdev_obj *obj,
Jiri Pirko7ea6eb32015-09-24 10:02:41 +0200138 struct switchdev_trans *trans);
Scott Feldman491d0f12015-05-10 09:47:52 -0700139 int (*switchdev_port_obj_del)(struct net_device *dev,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200140 const struct switchdev_obj *obj);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700141 int (*switchdev_port_obj_dump)(struct net_device *dev,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200142 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);
Jiri Pirko9e8f4a52015-10-01 11:03:46 +0200173int switchdev_port_obj_add(struct net_device *dev,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200174 const struct switchdev_obj *obj);
Jiri Pirko9e8f4a52015-10-01 11:03:46 +0200175int switchdev_port_obj_del(struct net_device *dev,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200176 const struct switchdev_obj *obj);
Jiri Pirko9e8f4a52015-10-01 11:03:46 +0200177int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200178 switchdev_obj_dump_cb_t *cb);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700179int register_switchdev_notifier(struct notifier_block *nb);
180int unregister_switchdev_notifier(struct notifier_block *nb);
181int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
182 struct switchdev_notifier_info *info);
Scott Feldman8793d0a2015-05-10 09:48:04 -0700183int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
184 struct net_device *dev, u32 filter_mask,
185 int nlflags);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700186int switchdev_port_bridge_setlink(struct net_device *dev,
187 struct nlmsghdr *nlh, u16 flags);
188int switchdev_port_bridge_dellink(struct net_device *dev,
189 struct nlmsghdr *nlh, u16 flags);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700190int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
191 u8 tos, u8 type, u32 nlflags, u32 tb_id);
192int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
193 u8 tos, u8 type, u32 tb_id);
194void switchdev_fib_ipv4_abort(struct fib_info *fi);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700195int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
196 struct net_device *dev, const unsigned char *addr,
197 u16 vid, u16 nlm_flags);
198int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
199 struct net_device *dev, const unsigned char *addr,
200 u16 vid);
201int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
202 struct net_device *dev,
203 struct net_device *filter_dev, int idx);
Scott Feldman1a3b2ec2015-07-18 18:24:50 -0700204void switchdev_port_fwd_mark_set(struct net_device *dev,
205 struct net_device *group_dev,
206 bool joining);
Scott Feldman5e8d9042015-03-05 21:21:15 -0800207
Jiri Pirko007f7902014-11-28 14:34:17 +0100208#else
209
Scott Feldman30943332015-05-10 09:47:48 -0700210static inline int switchdev_port_attr_get(struct net_device *dev,
211 struct switchdev_attr *attr)
212{
213 return -EOPNOTSUPP;
214}
215
216static inline int switchdev_port_attr_set(struct net_device *dev,
217 struct switchdev_attr *attr)
218{
219 return -EOPNOTSUPP;
220}
221
Scott Feldman491d0f12015-05-10 09:47:52 -0700222static inline int switchdev_port_obj_add(struct net_device *dev,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200223 const struct switchdev_obj *obj)
Scott Feldman491d0f12015-05-10 09:47:52 -0700224{
225 return -EOPNOTSUPP;
226}
227
228static inline int switchdev_port_obj_del(struct net_device *dev,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200229 const struct switchdev_obj *obj)
Scott Feldman491d0f12015-05-10 09:47:52 -0700230{
231 return -EOPNOTSUPP;
232}
233
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700234static inline int switchdev_port_obj_dump(struct net_device *dev,
Jiri Pirko648b4a92015-10-01 11:03:45 +0200235 const struct switchdev_obj *obj,
236 switchdev_obj_dump_cb_t *cb)
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700237{
238 return -EOPNOTSUPP;
239}
240
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700241static inline int register_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100242{
243 return 0;
244}
245
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700246static inline int unregister_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100247{
248 return 0;
249}
250
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700251static inline int call_switchdev_notifiers(unsigned long val,
252 struct net_device *dev,
253 struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100254{
255 return NOTIFY_DONE;
256}
257
Scott Feldman8793d0a2015-05-10 09:48:04 -0700258static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid,
259 u32 seq, struct net_device *dev,
260 u32 filter_mask, int nlflags)
261{
262 return -EOPNOTSUPP;
263}
264
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700265static inline int switchdev_port_bridge_setlink(struct net_device *dev,
266 struct nlmsghdr *nlh,
267 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800268{
269 return -EOPNOTSUPP;
270}
271
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700272static inline int switchdev_port_bridge_dellink(struct net_device *dev,
273 struct nlmsghdr *nlh,
274 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800275{
276 return -EOPNOTSUPP;
277}
278
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700279static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
280 struct fib_info *fi,
281 u8 tos, u8 type,
282 u32 nlflags, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800283{
284 return 0;
285}
286
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700287static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
288 struct fib_info *fi,
289 u8 tos, u8 type, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800290{
291 return 0;
292}
293
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700294static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
Scott Feldman8e05fd72015-03-05 21:21:19 -0800295{
296}
297
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700298static inline int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
299 struct net_device *dev,
300 const unsigned char *addr,
301 u16 vid, u16 nlm_flags)
302{
303 return -EOPNOTSUPP;
304}
305
306static inline int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
307 struct net_device *dev,
308 const unsigned char *addr, u16 vid)
309{
310 return -EOPNOTSUPP;
311}
312
313static inline int switchdev_port_fdb_dump(struct sk_buff *skb,
314 struct netlink_callback *cb,
315 struct net_device *dev,
316 struct net_device *filter_dev,
317 int idx)
318{
319 return -EOPNOTSUPP;
320}
321
Scott Feldman1a3b2ec2015-07-18 18:24:50 -0700322static inline void switchdev_port_fwd_mark_set(struct net_device *dev,
323 struct net_device *group_dev,
324 bool joining)
325{
326}
327
Jiri Pirko007f7902014-11-28 14:34:17 +0100328#endif
329
330#endif /* _LINUX_SWITCHDEV_H_ */