blob: 93316e7ab372f523ae41a06b90fc0f099778d7ee [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 Feldman30943332015-05-10 09:47:48 -070029};
30
31struct switchdev_attr {
32 enum switchdev_attr_id id;
33 enum switchdev_trans trans;
34 u32 flags;
Scott Feldmanf8e20a92015-05-10 09:47:49 -070035 union {
36 struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
37 };
Scott Feldman30943332015-05-10 09:47:48 -070038};
39
Scott Feldman41706042015-03-15 21:07:14 -070040struct fib_info;
41
42/**
43 * struct switchdev_ops - switchdev operations
44 *
Scott Feldman30943332015-05-10 09:47:48 -070045 * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
46 *
47 * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
48 *
Jiri Pirko9d47c0a2015-05-10 09:47:47 -070049 * @switchdev_port_stp_update: Called to notify switch device port of bridge
Scott Feldman13bb8e22015-03-20 17:42:46 -070050 * port STP state change.
Scott Feldman41706042015-03-15 21:07:14 -070051 *
Jiri Pirko9d47c0a2015-05-10 09:47:47 -070052 * @switchdev_fib_ipv4_add: Called to add/modify IPv4 route to switch device.
Scott Feldman41706042015-03-15 21:07:14 -070053 *
Jiri Pirko9d47c0a2015-05-10 09:47:47 -070054 * @switchdev_fib_ipv4_del: Called to delete IPv4 route from switch device.
Scott Feldman41706042015-03-15 21:07:14 -070055 */
Jiri Pirko9d47c0a2015-05-10 09:47:47 -070056struct switchdev_ops {
Scott Feldman30943332015-05-10 09:47:48 -070057 int (*switchdev_port_attr_get)(struct net_device *dev,
58 struct switchdev_attr *attr);
59 int (*switchdev_port_attr_set)(struct net_device *dev,
60 struct switchdev_attr *attr);
Jiri Pirko9d47c0a2015-05-10 09:47:47 -070061 int (*switchdev_port_stp_update)(struct net_device *dev, u8 state);
62 int (*switchdev_fib_ipv4_add)(struct net_device *dev, __be32 dst,
63 int dst_len, struct fib_info *fi,
64 u8 tos, u8 type, u32 nlflags,
65 u32 tb_id);
66 int (*switchdev_fib_ipv4_del)(struct net_device *dev, __be32 dst,
67 int dst_len, struct fib_info *fi,
68 u8 tos, u8 type, u32 tb_id);
Scott Feldman41706042015-03-15 21:07:14 -070069};
70
Jiri Pirkoebb9a032015-05-10 09:47:46 -070071enum switchdev_notifier_type {
72 SWITCHDEV_FDB_ADD = 1,
73 SWITCHDEV_FDB_DEL,
Jiri Pirko3aeb6612015-01-15 23:49:37 +010074};
75
Jiri Pirkoebb9a032015-05-10 09:47:46 -070076struct switchdev_notifier_info {
Jiri Pirko03bf0c22015-01-15 23:49:36 +010077 struct net_device *dev;
78};
79
Jiri Pirkoebb9a032015-05-10 09:47:46 -070080struct switchdev_notifier_fdb_info {
81 struct switchdev_notifier_info info; /* must be first */
Jiri Pirko3aeb6612015-01-15 23:49:37 +010082 const unsigned char *addr;
83 u16 vid;
84};
85
Jiri Pirko03bf0c22015-01-15 23:49:36 +010086static inline struct net_device *
Jiri Pirkoebb9a032015-05-10 09:47:46 -070087switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +010088{
89 return info->dev;
90}
Jiri Pirko007f7902014-11-28 14:34:17 +010091
92#ifdef CONFIG_NET_SWITCHDEV
93
Scott Feldman30943332015-05-10 09:47:48 -070094int switchdev_port_attr_get(struct net_device *dev,
95 struct switchdev_attr *attr);
96int switchdev_port_attr_set(struct net_device *dev,
97 struct switchdev_attr *attr);
Jiri Pirkoebb9a032015-05-10 09:47:46 -070098int switchdev_port_stp_update(struct net_device *dev, u8 state);
99int register_switchdev_notifier(struct notifier_block *nb);
100int unregister_switchdev_notifier(struct notifier_block *nb);
101int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
102 struct switchdev_notifier_info *info);
103int switchdev_port_bridge_setlink(struct net_device *dev,
104 struct nlmsghdr *nlh, u16 flags);
105int switchdev_port_bridge_dellink(struct net_device *dev,
106 struct nlmsghdr *nlh, u16 flags);
107int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
108 struct nlmsghdr *nlh, u16 flags);
109int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
110 struct nlmsghdr *nlh, u16 flags);
111int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
112 u8 tos, u8 type, u32 nlflags, u32 tb_id);
113int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
114 u8 tos, u8 type, u32 tb_id);
115void switchdev_fib_ipv4_abort(struct fib_info *fi);
Scott Feldman5e8d9042015-03-05 21:21:15 -0800116
Jiri Pirko007f7902014-11-28 14:34:17 +0100117#else
118
Scott Feldman30943332015-05-10 09:47:48 -0700119static inline int switchdev_port_attr_get(struct net_device *dev,
120 struct switchdev_attr *attr)
121{
122 return -EOPNOTSUPP;
123}
124
125static inline int switchdev_port_attr_set(struct net_device *dev,
126 struct switchdev_attr *attr)
127{
128 return -EOPNOTSUPP;
129}
130
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700131static inline int switchdev_port_stp_update(struct net_device *dev,
132 u8 state)
Scott Feldman38dcf352014-11-28 14:34:20 +0100133{
134 return -EOPNOTSUPP;
135}
136
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700137static inline int register_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100138{
139 return 0;
140}
141
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700142static inline int unregister_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100143{
144 return 0;
145}
146
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700147static inline int call_switchdev_notifiers(unsigned long val,
148 struct net_device *dev,
149 struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100150{
151 return NOTIFY_DONE;
152}
153
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700154static inline int switchdev_port_bridge_setlink(struct net_device *dev,
155 struct nlmsghdr *nlh,
156 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800157{
158 return -EOPNOTSUPP;
159}
160
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700161static inline int switchdev_port_bridge_dellink(struct net_device *dev,
162 struct nlmsghdr *nlh,
163 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800164{
165 return -EOPNOTSUPP;
166}
167
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700168static inline int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
169 struct nlmsghdr *nlh,
170 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800171{
172 return 0;
173}
174
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700175static inline int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
176 struct nlmsghdr *nlh,
177 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800178{
179 return 0;
180}
181
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700182static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
183 struct fib_info *fi,
184 u8 tos, u8 type,
185 u32 nlflags, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800186{
187 return 0;
188}
189
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700190static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
191 struct fib_info *fi,
192 u8 tos, u8 type, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800193{
194 return 0;
195}
196
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700197static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
Scott Feldman8e05fd72015-03-05 21:21:19 -0800198{
199}
200
Jiri Pirko007f7902014-11-28 14:34:17 +0100201#endif
202
203#endif /* _LINUX_SWITCHDEV_H_ */