blob: 282043844bcfb09661244b72a0e7a36652c46532 [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,
28};
29
30struct switchdev_attr {
31 enum switchdev_attr_id id;
32 enum switchdev_trans trans;
33 u32 flags;
34};
35
Scott Feldman41706042015-03-15 21:07:14 -070036struct fib_info;
37
38/**
39 * struct switchdev_ops - switchdev operations
40 *
Jiri Pirko9d47c0a2015-05-10 09:47:47 -070041 * @switchdev_parent_id_get: Called to get an ID of the switch chip this port
Scott Feldman13bb8e22015-03-20 17:42:46 -070042 * is part of. If driver implements this, it indicates that it
43 * represents a port of a switch chip.
Scott Feldman41706042015-03-15 21:07:14 -070044 *
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 {
57 int (*switchdev_parent_id_get)(struct net_device *dev,
58 struct netdev_phys_item_id *psid);
Scott Feldman30943332015-05-10 09:47:48 -070059 int (*switchdev_port_attr_get)(struct net_device *dev,
60 struct switchdev_attr *attr);
61 int (*switchdev_port_attr_set)(struct net_device *dev,
62 struct switchdev_attr *attr);
Jiri Pirko9d47c0a2015-05-10 09:47:47 -070063 int (*switchdev_port_stp_update)(struct net_device *dev, u8 state);
64 int (*switchdev_fib_ipv4_add)(struct net_device *dev, __be32 dst,
65 int dst_len, struct fib_info *fi,
66 u8 tos, u8 type, u32 nlflags,
67 u32 tb_id);
68 int (*switchdev_fib_ipv4_del)(struct net_device *dev, __be32 dst,
69 int dst_len, struct fib_info *fi,
70 u8 tos, u8 type, u32 tb_id);
Scott Feldman41706042015-03-15 21:07:14 -070071};
72
Jiri Pirkoebb9a032015-05-10 09:47:46 -070073enum switchdev_notifier_type {
74 SWITCHDEV_FDB_ADD = 1,
75 SWITCHDEV_FDB_DEL,
Jiri Pirko3aeb6612015-01-15 23:49:37 +010076};
77
Jiri Pirkoebb9a032015-05-10 09:47:46 -070078struct switchdev_notifier_info {
Jiri Pirko03bf0c22015-01-15 23:49:36 +010079 struct net_device *dev;
80};
81
Jiri Pirkoebb9a032015-05-10 09:47:46 -070082struct switchdev_notifier_fdb_info {
83 struct switchdev_notifier_info info; /* must be first */
Jiri Pirko3aeb6612015-01-15 23:49:37 +010084 const unsigned char *addr;
85 u16 vid;
86};
87
Jiri Pirko03bf0c22015-01-15 23:49:36 +010088static inline struct net_device *
Jiri Pirkoebb9a032015-05-10 09:47:46 -070089switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +010090{
91 return info->dev;
92}
Jiri Pirko007f7902014-11-28 14:34:17 +010093
94#ifdef CONFIG_NET_SWITCHDEV
95
Jiri Pirkoebb9a032015-05-10 09:47:46 -070096int switchdev_parent_id_get(struct net_device *dev,
97 struct netdev_phys_item_id *psid);
Scott Feldman30943332015-05-10 09:47:48 -070098int switchdev_port_attr_get(struct net_device *dev,
99 struct switchdev_attr *attr);
100int switchdev_port_attr_set(struct net_device *dev,
101 struct switchdev_attr *attr);
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700102int switchdev_port_stp_update(struct net_device *dev, u8 state);
103int register_switchdev_notifier(struct notifier_block *nb);
104int unregister_switchdev_notifier(struct notifier_block *nb);
105int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
106 struct switchdev_notifier_info *info);
107int switchdev_port_bridge_setlink(struct net_device *dev,
108 struct nlmsghdr *nlh, u16 flags);
109int switchdev_port_bridge_dellink(struct net_device *dev,
110 struct nlmsghdr *nlh, u16 flags);
111int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
112 struct nlmsghdr *nlh, u16 flags);
113int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
114 struct nlmsghdr *nlh, u16 flags);
115int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
116 u8 tos, u8 type, u32 nlflags, u32 tb_id);
117int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
118 u8 tos, u8 type, u32 tb_id);
119void switchdev_fib_ipv4_abort(struct fib_info *fi);
Scott Feldman5e8d9042015-03-05 21:21:15 -0800120
Jiri Pirko007f7902014-11-28 14:34:17 +0100121#else
122
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700123static inline int switchdev_parent_id_get(struct net_device *dev,
124 struct netdev_phys_item_id *psid)
Jiri Pirko007f7902014-11-28 14:34:17 +0100125{
126 return -EOPNOTSUPP;
127}
128
Scott Feldman30943332015-05-10 09:47:48 -0700129static inline int switchdev_port_attr_get(struct net_device *dev,
130 struct switchdev_attr *attr)
131{
132 return -EOPNOTSUPP;
133}
134
135static inline int switchdev_port_attr_set(struct net_device *dev,
136 struct switchdev_attr *attr)
137{
138 return -EOPNOTSUPP;
139}
140
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700141static inline int switchdev_port_stp_update(struct net_device *dev,
142 u8 state)
Scott Feldman38dcf352014-11-28 14:34:20 +0100143{
144 return -EOPNOTSUPP;
145}
146
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700147static inline int register_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100148{
149 return 0;
150}
151
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700152static inline int unregister_switchdev_notifier(struct notifier_block *nb)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100153{
154 return 0;
155}
156
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700157static inline int call_switchdev_notifiers(unsigned long val,
158 struct net_device *dev,
159 struct switchdev_notifier_info *info)
Jiri Pirko03bf0c22015-01-15 23:49:36 +0100160{
161 return NOTIFY_DONE;
162}
163
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700164static inline int switchdev_port_bridge_setlink(struct net_device *dev,
165 struct nlmsghdr *nlh,
166 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800167{
168 return -EOPNOTSUPP;
169}
170
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700171static inline int switchdev_port_bridge_dellink(struct net_device *dev,
172 struct nlmsghdr *nlh,
173 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800174{
175 return -EOPNOTSUPP;
176}
177
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700178static inline int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
179 struct nlmsghdr *nlh,
180 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800181{
182 return 0;
183}
184
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700185static inline int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
186 struct nlmsghdr *nlh,
187 u16 flags)
Roopa Prabhu8a44dbb2015-01-29 22:40:13 -0800188{
189 return 0;
190}
191
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700192static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
193 struct fib_info *fi,
194 u8 tos, u8 type,
195 u32 nlflags, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800196{
197 return 0;
198}
199
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700200static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
201 struct fib_info *fi,
202 u8 tos, u8 type, u32 tb_id)
Scott Feldman5e8d9042015-03-05 21:21:15 -0800203{
204 return 0;
205}
206
Jiri Pirkoebb9a032015-05-10 09:47:46 -0700207static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
Scott Feldman8e05fd72015-03-05 21:21:19 -0800208{
209}
210
Jiri Pirko007f7902014-11-28 14:34:17 +0100211#endif
212
213#endif /* _LINUX_SWITCHDEV_H_ */