blob: 89da8934519bb720c4d5f1f479040a889e6079fd [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 Feldman42275bd2015-05-13 11:16:50 -070041 } u;
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,
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070050 SWITCHDEV_OBJ_PORT_FDB,
Scott Feldman491d0f12015-05-10 09:47:52 -070051};
52
53struct switchdev_obj {
54 enum switchdev_obj_id id;
55 enum switchdev_trans trans;
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070056 int (*cb)(struct net_device *dev, struct switchdev_obj *obj);
Scott Feldman6fc30162015-05-10 09:47:53 -070057 union {
Scott Feldman5eb764e2015-05-12 23:03:53 -070058 struct switchdev_obj_vlan { /* PORT_VLAN */
Scott Feldman6fc30162015-05-10 09:47:53 -070059 u16 flags;
Scott Feldman3e3a78b2015-06-22 00:27:16 -070060 u16 vid_begin;
Scott Feldman6fc30162015-05-10 09:47:53 -070061 u16 vid_end;
62 } vlan;
Scott Feldman58c2cb12015-05-10 09:48:06 -070063 struct switchdev_obj_ipv4_fib { /* IPV4_FIB */
64 u32 dst;
65 int dst_len;
66 struct fib_info *fi;
67 u8 tos;
68 u8 type;
69 u32 nlflags;
70 u32 tb_id;
71 } ipv4_fib;
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070072 struct switchdev_obj_fdb { /* PORT_FDB */
73 const unsigned char *addr;
74 u16 vid;
75 } fdb;
Scott Feldman42275bd2015-05-13 11:16:50 -070076 } u;
Scott Feldman491d0f12015-05-10 09:47:52 -070077};
78
Scott Feldman41706042015-03-15 21:07:14 -070079/**
80 * struct switchdev_ops - switchdev operations
81 *
Scott Feldman30943332015-05-10 09:47:48 -070082 * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
83 *
84 * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
85 *
Scott Feldman491d0f12015-05-10 09:47:52 -070086 * @switchdev_port_obj_add: Add an object to port (see switchdev_obj).
87 *
88 * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj).
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070089 *
90 * @switchdev_port_obj_dump: Dump port objects (see switchdev_obj).
Scott Feldman41706042015-03-15 21:07:14 -070091 */
Jiri Pirko9d47c0a2015-05-10 09:47:47 -070092struct switchdev_ops {
Scott Feldman30943332015-05-10 09:47:48 -070093 int (*switchdev_port_attr_get)(struct net_device *dev,
94 struct switchdev_attr *attr);
95 int (*switchdev_port_attr_set)(struct net_device *dev,
96 struct switchdev_attr *attr);
Scott Feldman491d0f12015-05-10 09:47:52 -070097 int (*switchdev_port_obj_add)(struct net_device *dev,
98 struct switchdev_obj *obj);
99 int (*switchdev_port_obj_del)(struct net_device *dev,
100 struct switchdev_obj *obj);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700101 int (*switchdev_port_obj_dump)(struct net_device *dev,
102 struct switchdev_obj *obj);
Scott Feldman41706042015-03-15 21:07:14 -0700103};
104
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700105enum switchdev_notifier_type {
106 SWITCHDEV_FDB_ADD = 1,
107 SWITCHDEV_FDB_DEL,
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100108};
109
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700110struct switchdev_notifier_info {
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100111 struct net_device *dev;
112};
113
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700114struct switchdev_notifier_fdb_info {
115 struct switchdev_notifier_info info; /* must be first */
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100116 const unsigned char *addr;
117 u16 vid;
118};
119
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100120static inline struct net_device *
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700121switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100122{
123 return info->dev;
124}
Jiri Pirko007f7902014-11-28 14:34:17 +0100125
126#ifdef CONFIG_NET_SWITCHDEV
127
Scott Feldman30943332015-05-10 09:47:48 -0700128int switchdev_port_attr_get(struct net_device *dev,
129 struct switchdev_attr *attr);
130int switchdev_port_attr_set(struct net_device *dev,
131 struct switchdev_attr *attr);
Scott Feldman491d0f12015-05-10 09:47:52 -0700132int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj);
133int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700134int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700135int register_switchdev_notifier(struct notifier_block *nb);
136int unregister_switchdev_notifier(struct notifier_block *nb);
137int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
138 struct switchdev_notifier_info *info);
Scott Feldman8793d0a2015-05-10 09:48:04 -0700139int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
140 struct net_device *dev, u32 filter_mask,
141 int nlflags);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700142int switchdev_port_bridge_setlink(struct net_device *dev,
143 struct nlmsghdr *nlh, u16 flags);
144int switchdev_port_bridge_dellink(struct net_device *dev,
145 struct nlmsghdr *nlh, u16 flags);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700146int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
147 u8 tos, u8 type, u32 nlflags, u32 tb_id);
148int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
149 u8 tos, u8 type, u32 tb_id);
150void switchdev_fib_ipv4_abort(struct fib_info *fi);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700151int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
152 struct net_device *dev, const unsigned char *addr,
153 u16 vid, u16 nlm_flags);
154int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
155 struct net_device *dev, const unsigned char *addr,
156 u16 vid);
157int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
158 struct net_device *dev,
159 struct net_device *filter_dev, int idx);
Scott Feldman1a3b2ec2015-07-18 18:24:50 -0700160void switchdev_port_fwd_mark_set(struct net_device *dev,
161 struct net_device *group_dev,
162 bool joining);
Scott Feldman5e8d9042015-03-05 21:21:15 -0800163
Jiri Pirko007f7902014-11-28 14:34:17 +0100164#else
165
Scott Feldman30943332015-05-10 09:47:48 -0700166static inline int switchdev_port_attr_get(struct net_device *dev,
167 struct switchdev_attr *attr)
168{
169 return -EOPNOTSUPP;
170}
171
172static inline int switchdev_port_attr_set(struct net_device *dev,
173 struct switchdev_attr *attr)
174{
175 return -EOPNOTSUPP;
176}
177
Scott Feldman491d0f12015-05-10 09:47:52 -0700178static inline int switchdev_port_obj_add(struct net_device *dev,
179 struct switchdev_obj *obj)
180{
181 return -EOPNOTSUPP;
182}
183
184static inline int switchdev_port_obj_del(struct net_device *dev,
185 struct switchdev_obj *obj)
186{
187 return -EOPNOTSUPP;
188}
189
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700190static inline int switchdev_port_obj_dump(struct net_device *dev,
191 struct switchdev_obj *obj)
192{
193 return -EOPNOTSUPP;
194}
195
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700196static inline int register_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100197{
198 return 0;
199}
200
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700201static inline int unregister_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100202{
203 return 0;
204}
205
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700206static inline int call_switchdev_notifiers(unsigned long val,
207 struct net_device *dev,
208 struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100209{
210 return NOTIFY_DONE;
211}
212
Scott Feldman8793d0a2015-05-10 09:48:04 -0700213static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid,
214 u32 seq, struct net_device *dev,
215 u32 filter_mask, int nlflags)
216{
217 return -EOPNOTSUPP;
218}
219
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700220static inline int switchdev_port_bridge_setlink(struct net_device *dev,
221 struct nlmsghdr *nlh,
222 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800223{
224 return -EOPNOTSUPP;
225}
226
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700227static inline int switchdev_port_bridge_dellink(struct net_device *dev,
228 struct nlmsghdr *nlh,
229 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800230{
231 return -EOPNOTSUPP;
232}
233
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700234static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
235 struct fib_info *fi,
236 u8 tos, u8 type,
237 u32 nlflags, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800238{
239 return 0;
240}
241
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700242static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
243 struct fib_info *fi,
244 u8 tos, u8 type, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800245{
246 return 0;
247}
248
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700249static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
Scott Feldman8e05fd72015-03-05 21:21:19 -0800250{
251}
252
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700253static inline int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
254 struct net_device *dev,
255 const unsigned char *addr,
256 u16 vid, u16 nlm_flags)
257{
258 return -EOPNOTSUPP;
259}
260
261static inline int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
262 struct net_device *dev,
263 const unsigned char *addr, u16 vid)
264{
265 return -EOPNOTSUPP;
266}
267
268static inline int switchdev_port_fdb_dump(struct sk_buff *skb,
269 struct netlink_callback *cb,
270 struct net_device *dev,
271 struct net_device *filter_dev,
272 int idx)
273{
274 return -EOPNOTSUPP;
275}
276
Scott Feldman1a3b2ec2015-07-18 18:24:50 -0700277static inline void switchdev_port_fwd_mark_set(struct net_device *dev,
278 struct net_device *group_dev,
279 bool joining)
280{
281}
282
Jiri Pirko007f7902014-11-28 14:34:17 +0100283#endif
284
285#endif /* _LINUX_SWITCHDEV_H_ */