blob: 3b217b4cca277fdfc56c60b493f166826d19d2be [file] [log] [blame]
Jiri Pirko007f7902014-11-28 14:34:17 +01001/*
2 * include/net/switchdev.h - Switch device API
3 * Copyright (c) 2014 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>
16
Scott Feldman30943332015-05-10 09:47:48 -070017#define SWITCHDEV_F_NO_RECURSE BIT(0)
18
19enum switchdev_trans {
20 SWITCHDEV_TRANS_NONE,
21 SWITCHDEV_TRANS_PREPARE,
22 SWITCHDEV_TRANS_ABORT,
23 SWITCHDEV_TRANS_COMMIT,
24};
25
26enum switchdev_attr_id {
27 SWITCHDEV_ATTR_UNDEFINED,
Scott Feldmanf8e20a92015-05-10 09:47:49 -070028 SWITCHDEV_ATTR_PORT_PARENT_ID,
Scott Feldman35636062015-05-10 09:47:51 -070029 SWITCHDEV_ATTR_PORT_STP_STATE,
Scott Feldman6004c862015-05-10 09:47:55 -070030 SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS,
Scott Feldman30943332015-05-10 09:47:48 -070031};
32
33struct switchdev_attr {
34 enum switchdev_attr_id id;
35 enum switchdev_trans trans;
36 u32 flags;
Scott Feldmanf8e20a92015-05-10 09:47:49 -070037 union {
38 struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
Scott Feldman35636062015-05-10 09:47:51 -070039 u8 stp_state; /* PORT_STP_STATE */
Scott Feldman6004c862015-05-10 09:47:55 -070040 unsigned long brport_flags; /* PORT_BRIDGE_FLAGS */
Scott Feldmanf8e20a92015-05-10 09:47:49 -070041 };
Scott Feldman30943332015-05-10 09:47:48 -070042};
43
Scott Feldman41706042015-03-15 21:07:14 -070044struct fib_info;
45
Scott Feldman491d0f12015-05-10 09:47:52 -070046enum switchdev_obj_id {
47 SWITCHDEV_OBJ_UNDEFINED,
Scott Feldman6fc30162015-05-10 09:47:53 -070048 SWITCHDEV_OBJ_PORT_VLAN,
Scott Feldman58c2cb12015-05-10 09:48:06 -070049 SWITCHDEV_OBJ_IPV4_FIB,
Scott Feldman491d0f12015-05-10 09:47:52 -070050};
51
52struct switchdev_obj {
53 enum switchdev_obj_id id;
54 enum switchdev_trans trans;
Scott Feldman6fc30162015-05-10 09:47:53 -070055 union {
56 struct switchdev_obj_vlan { /* PORT_VLAN */
57 u16 flags;
58 u16 vid_start;
59 u16 vid_end;
60 } vlan;
Scott Feldman58c2cb12015-05-10 09:48:06 -070061 struct switchdev_obj_ipv4_fib { /* IPV4_FIB */
62 u32 dst;
63 int dst_len;
64 struct fib_info *fi;
65 u8 tos;
66 u8 type;
67 u32 nlflags;
68 u32 tb_id;
69 } ipv4_fib;
Scott Feldman6fc30162015-05-10 09:47:53 -070070 };
Scott Feldman491d0f12015-05-10 09:47:52 -070071};
72
Scott Feldman41706042015-03-15 21:07:14 -070073/**
74 * struct switchdev_ops - switchdev operations
75 *
Scott Feldman30943332015-05-10 09:47:48 -070076 * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
77 *
78 * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
79 *
Scott Feldman491d0f12015-05-10 09:47:52 -070080 * @switchdev_port_obj_add: Add an object to port (see switchdev_obj).
81 *
82 * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj).
Scott Feldman41706042015-03-15 21:07:14 -070083 */
Jiri Pirko9d47c0a2015-05-10 09:47:47 -070084struct switchdev_ops {
Scott Feldman30943332015-05-10 09:47:48 -070085 int (*switchdev_port_attr_get)(struct net_device *dev,
86 struct switchdev_attr *attr);
87 int (*switchdev_port_attr_set)(struct net_device *dev,
88 struct switchdev_attr *attr);
Scott Feldman491d0f12015-05-10 09:47:52 -070089 int (*switchdev_port_obj_add)(struct net_device *dev,
90 struct switchdev_obj *obj);
91 int (*switchdev_port_obj_del)(struct net_device *dev,
92 struct switchdev_obj *obj);
Scott Feldman41706042015-03-15 21:07:14 -070093};
94
Jiri Pirkoebb9a032015-05-10 09:47:46 -070095enum switchdev_notifier_type {
96 SWITCHDEV_FDB_ADD = 1,
97 SWITCHDEV_FDB_DEL,
Jiri Pirko3aeb6612015-01-15 23:49:37 +010098};
99
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700100struct switchdev_notifier_info {
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100101 struct net_device *dev;
102};
103
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700104struct switchdev_notifier_fdb_info {
105 struct switchdev_notifier_info info; /* must be first */
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100106 const unsigned char *addr;
107 u16 vid;
108};
109
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100110static inline struct net_device *
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700111switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100112{
113 return info->dev;
114}
Jiri Pirko007f7902014-11-28 14:34:17 +0100115
116#ifdef CONFIG_NET_SWITCHDEV
117
Scott Feldman30943332015-05-10 09:47:48 -0700118int switchdev_port_attr_get(struct net_device *dev,
119 struct switchdev_attr *attr);
120int switchdev_port_attr_set(struct net_device *dev,
121 struct switchdev_attr *attr);
Scott Feldman491d0f12015-05-10 09:47:52 -0700122int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj);
123int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700124int register_switchdev_notifier(struct notifier_block *nb);
125int unregister_switchdev_notifier(struct notifier_block *nb);
126int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
127 struct switchdev_notifier_info *info);
Scott Feldman8793d0a2015-05-10 09:48:04 -0700128int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
129 struct net_device *dev, u32 filter_mask,
130 int nlflags);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700131int switchdev_port_bridge_setlink(struct net_device *dev,
132 struct nlmsghdr *nlh, u16 flags);
133int switchdev_port_bridge_dellink(struct net_device *dev,
134 struct nlmsghdr *nlh, u16 flags);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700135int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
136 u8 tos, u8 type, u32 nlflags, u32 tb_id);
137int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
138 u8 tos, u8 type, u32 tb_id);
139void switchdev_fib_ipv4_abort(struct fib_info *fi);
Scott Feldman5e8d9042015-03-05 21:21:15 -0800140
Jiri Pirko007f7902014-11-28 14:34:17 +0100141#else
142
Scott Feldman30943332015-05-10 09:47:48 -0700143static inline int switchdev_port_attr_get(struct net_device *dev,
144 struct switchdev_attr *attr)
145{
146 return -EOPNOTSUPP;
147}
148
149static inline int switchdev_port_attr_set(struct net_device *dev,
150 struct switchdev_attr *attr)
151{
152 return -EOPNOTSUPP;
153}
154
Scott Feldman491d0f12015-05-10 09:47:52 -0700155static inline int switchdev_port_obj_add(struct net_device *dev,
156 struct switchdev_obj *obj)
157{
158 return -EOPNOTSUPP;
159}
160
161static inline int switchdev_port_obj_del(struct net_device *dev,
162 struct switchdev_obj *obj)
163{
164 return -EOPNOTSUPP;
165}
166
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700167static inline int register_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100168{
169 return 0;
170}
171
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700172static inline int unregister_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100173{
174 return 0;
175}
176
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700177static inline int call_switchdev_notifiers(unsigned long val,
178 struct net_device *dev,
179 struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100180{
181 return NOTIFY_DONE;
182}
183
Scott Feldman8793d0a2015-05-10 09:48:04 -0700184static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid,
185 u32 seq, struct net_device *dev,
186 u32 filter_mask, int nlflags)
187{
188 return -EOPNOTSUPP;
189}
190
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700191static inline int switchdev_port_bridge_setlink(struct net_device *dev,
192 struct nlmsghdr *nlh,
193 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800194{
195 return -EOPNOTSUPP;
196}
197
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700198static inline int switchdev_port_bridge_dellink(struct net_device *dev,
199 struct nlmsghdr *nlh,
200 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800201{
202 return -EOPNOTSUPP;
203}
204
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700205static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
206 struct fib_info *fi,
207 u8 tos, u8 type,
208 u32 nlflags, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800209{
210 return 0;
211}
212
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700213static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
214 struct fib_info *fi,
215 u8 tos, u8 type, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800216{
217 return 0;
218}
219
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700220static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
Scott Feldman8e05fd72015-03-05 21:21:19 -0800221{
222}
223
Jiri Pirko007f7902014-11-28 14:34:17 +0100224#endif
225
226#endif /* _LINUX_SWITCHDEV_H_ */