blob: 368a6429198db8bdb09f7d1d8a72142a8fd3fa3e [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
Scott Feldman30943332015-05-10 09:47:48 -070038enum switchdev_attr_id {
39 SWITCHDEV_ATTR_UNDEFINED,
Scott Feldmanf8e20a92015-05-10 09:47:49 -070040 SWITCHDEV_ATTR_PORT_PARENT_ID,
Scott Feldman35636062015-05-10 09:47:51 -070041 SWITCHDEV_ATTR_PORT_STP_STATE,
Scott Feldman6004c862015-05-10 09:47:55 -070042 SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS,
Scott Feldman30943332015-05-10 09:47:48 -070043};
44
45struct switchdev_attr {
46 enum switchdev_attr_id id;
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;
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070066 int (*cb)(struct net_device *dev, struct switchdev_obj *obj);
Scott Feldman6fc30162015-05-10 09:47:53 -070067 union {
Scott Feldman5eb764e2015-05-12 23:03:53 -070068 struct switchdev_obj_vlan { /* PORT_VLAN */
Scott Feldman6fc30162015-05-10 09:47:53 -070069 u16 flags;
Scott Feldman3e3a78b2015-06-22 00:27:16 -070070 u16 vid_begin;
Scott Feldman6fc30162015-05-10 09:47:53 -070071 u16 vid_end;
72 } vlan;
Scott Feldman58c2cb12015-05-10 09:48:06 -070073 struct switchdev_obj_ipv4_fib { /* IPV4_FIB */
74 u32 dst;
75 int dst_len;
76 struct fib_info *fi;
77 u8 tos;
78 u8 type;
79 u32 nlflags;
80 u32 tb_id;
81 } ipv4_fib;
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070082 struct switchdev_obj_fdb { /* PORT_FDB */
David S. Millercdf09692015-08-11 12:00:37 -070083 const unsigned char *addr;
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070084 u16 vid;
Vivien Didelotce80e7b2015-08-10 09:09:52 -040085 u16 ndm_state;
Samudrala, Sridhar45d41222015-05-13 21:55:43 -070086 } fdb;
Scott Feldman42275bd2015-05-13 11:16:50 -070087 } u;
Scott Feldman491d0f12015-05-10 09:47:52 -070088};
89
Jiri Pirko7ea6eb32015-09-24 10:02:41 +020090void switchdev_trans_item_enqueue(struct switchdev_trans *trans,
91 void *data, void (*destructor)(void const *),
92 struct switchdev_trans_item *tritem);
93void *switchdev_trans_item_dequeue(struct switchdev_trans *trans);
94
Scott Feldman41706042015-03-15 21:07:14 -070095/**
96 * struct switchdev_ops - switchdev operations
97 *
Scott Feldman30943332015-05-10 09:47:48 -070098 * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
99 *
100 * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
101 *
Scott Feldman491d0f12015-05-10 09:47:52 -0700102 * @switchdev_port_obj_add: Add an object to port (see switchdev_obj).
103 *
104 * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj).
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700105 *
106 * @switchdev_port_obj_dump: Dump port objects (see switchdev_obj).
Scott Feldman41706042015-03-15 21:07:14 -0700107 */
Jiri Pirko9d47c0a2015-05-10 09:47:47 -0700108struct switchdev_ops {
Scott Feldman30943332015-05-10 09:47:48 -0700109 int (*switchdev_port_attr_get)(struct net_device *dev,
110 struct switchdev_attr *attr);
111 int (*switchdev_port_attr_set)(struct net_device *dev,
Jiri Pirko7ea6eb32015-09-24 10:02:41 +0200112 struct switchdev_attr *attr,
113 struct switchdev_trans *trans);
Scott Feldman491d0f12015-05-10 09:47:52 -0700114 int (*switchdev_port_obj_add)(struct net_device *dev,
Jiri Pirko7ea6eb32015-09-24 10:02:41 +0200115 struct switchdev_obj *obj,
116 struct switchdev_trans *trans);
Scott Feldman491d0f12015-05-10 09:47:52 -0700117 int (*switchdev_port_obj_del)(struct net_device *dev,
118 struct switchdev_obj *obj);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700119 int (*switchdev_port_obj_dump)(struct net_device *dev,
120 struct switchdev_obj *obj);
Scott Feldman41706042015-03-15 21:07:14 -0700121};
122
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700123enum switchdev_notifier_type {
124 SWITCHDEV_FDB_ADD = 1,
125 SWITCHDEV_FDB_DEL,
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100126};
127
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700128struct switchdev_notifier_info {
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100129 struct net_device *dev;
130};
131
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700132struct switchdev_notifier_fdb_info {
133 struct switchdev_notifier_info info; /* must be first */
Jiri Pirko3aeb6612015-01-15 23:49:37 +0100134 const unsigned char *addr;
135 u16 vid;
136};
137
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100138static inline struct net_device *
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700139switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100140{
141 return info->dev;
142}
Jiri Pirko007f7902014-11-28 14:34:17 +0100143
144#ifdef CONFIG_NET_SWITCHDEV
145
Scott Feldman30943332015-05-10 09:47:48 -0700146int switchdev_port_attr_get(struct net_device *dev,
147 struct switchdev_attr *attr);
148int switchdev_port_attr_set(struct net_device *dev,
149 struct switchdev_attr *attr);
Scott Feldman491d0f12015-05-10 09:47:52 -0700150int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj);
151int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700152int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700153int register_switchdev_notifier(struct notifier_block *nb);
154int unregister_switchdev_notifier(struct notifier_block *nb);
155int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
156 struct switchdev_notifier_info *info);
Scott Feldman8793d0a2015-05-10 09:48:04 -0700157int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
158 struct net_device *dev, u32 filter_mask,
159 int nlflags);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700160int switchdev_port_bridge_setlink(struct net_device *dev,
161 struct nlmsghdr *nlh, u16 flags);
162int switchdev_port_bridge_dellink(struct net_device *dev,
163 struct nlmsghdr *nlh, u16 flags);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700164int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
165 u8 tos, u8 type, u32 nlflags, u32 tb_id);
166int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
167 u8 tos, u8 type, u32 tb_id);
168void switchdev_fib_ipv4_abort(struct fib_info *fi);
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700169int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
170 struct net_device *dev, const unsigned char *addr,
171 u16 vid, u16 nlm_flags);
172int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
173 struct net_device *dev, const unsigned char *addr,
174 u16 vid);
175int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb,
176 struct net_device *dev,
177 struct net_device *filter_dev, int idx);
Scott Feldman1a3b2ec2015-07-18 18:24:50 -0700178void switchdev_port_fwd_mark_set(struct net_device *dev,
179 struct net_device *group_dev,
180 bool joining);
Scott Feldman5e8d9042015-03-05 21:21:15 -0800181
Jiri Pirko007f7902014-11-28 14:34:17 +0100182#else
183
Scott Feldman30943332015-05-10 09:47:48 -0700184static inline int switchdev_port_attr_get(struct net_device *dev,
185 struct switchdev_attr *attr)
186{
187 return -EOPNOTSUPP;
188}
189
190static inline int switchdev_port_attr_set(struct net_device *dev,
191 struct switchdev_attr *attr)
192{
193 return -EOPNOTSUPP;
194}
195
Scott Feldman491d0f12015-05-10 09:47:52 -0700196static inline int switchdev_port_obj_add(struct net_device *dev,
197 struct switchdev_obj *obj)
198{
199 return -EOPNOTSUPP;
200}
201
202static inline int switchdev_port_obj_del(struct net_device *dev,
203 struct switchdev_obj *obj)
204{
205 return -EOPNOTSUPP;
206}
207
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700208static inline int switchdev_port_obj_dump(struct net_device *dev,
209 struct switchdev_obj *obj)
210{
211 return -EOPNOTSUPP;
212}
213
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700214static inline int register_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100215{
216 return 0;
217}
218
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700219static inline int unregister_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100220{
221 return 0;
222}
223
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700224static inline int call_switchdev_notifiers(unsigned long val,
225 struct net_device *dev,
226 struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100227{
228 return NOTIFY_DONE;
229}
230
Scott Feldman8793d0a2015-05-10 09:48:04 -0700231static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid,
232 u32 seq, struct net_device *dev,
233 u32 filter_mask, int nlflags)
234{
235 return -EOPNOTSUPP;
236}
237
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700238static inline int switchdev_port_bridge_setlink(struct net_device *dev,
239 struct nlmsghdr *nlh,
240 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800241{
242 return -EOPNOTSUPP;
243}
244
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700245static inline int switchdev_port_bridge_dellink(struct net_device *dev,
246 struct nlmsghdr *nlh,
247 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800248{
249 return -EOPNOTSUPP;
250}
251
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700252static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
253 struct fib_info *fi,
254 u8 tos, u8 type,
255 u32 nlflags, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800256{
257 return 0;
258}
259
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700260static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
261 struct fib_info *fi,
262 u8 tos, u8 type, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800263{
264 return 0;
265}
266
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700267static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
Scott Feldman8e05fd72015-03-05 21:21:19 -0800268{
269}
270
Samudrala, Sridhar45d41222015-05-13 21:55:43 -0700271static inline int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
272 struct net_device *dev,
273 const unsigned char *addr,
274 u16 vid, u16 nlm_flags)
275{
276 return -EOPNOTSUPP;
277}
278
279static inline int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
280 struct net_device *dev,
281 const unsigned char *addr, u16 vid)
282{
283 return -EOPNOTSUPP;
284}
285
286static inline int switchdev_port_fdb_dump(struct sk_buff *skb,
287 struct netlink_callback *cb,
288 struct net_device *dev,
289 struct net_device *filter_dev,
290 int idx)
291{
292 return -EOPNOTSUPP;
293}
294
Scott Feldman1a3b2ec2015-07-18 18:24:50 -0700295static inline void switchdev_port_fwd_mark_set(struct net_device *dev,
296 struct net_device *group_dev,
297 bool joining)
298{
299}
300
Jiri Pirko007f7902014-11-28 14:34:17 +0100301#endif
302
303#endif /* _LINUX_SWITCHDEV_H_ */