switchdev: introduce get/set attrs ops
[deliverable/linux.git] / include / net / switchdev.h
1 /*
2 * include/net/switchdev.h - Switch device API
3 * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
4 * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com>
5 *
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>
15 #include <linux/notifier.h>
16
17 #define SWITCHDEV_F_NO_RECURSE BIT(0)
18
19 enum switchdev_trans {
20 SWITCHDEV_TRANS_NONE,
21 SWITCHDEV_TRANS_PREPARE,
22 SWITCHDEV_TRANS_ABORT,
23 SWITCHDEV_TRANS_COMMIT,
24 };
25
26 enum switchdev_attr_id {
27 SWITCHDEV_ATTR_UNDEFINED,
28 };
29
30 struct switchdev_attr {
31 enum switchdev_attr_id id;
32 enum switchdev_trans trans;
33 u32 flags;
34 };
35
36 struct fib_info;
37
38 /**
39 * struct switchdev_ops - switchdev operations
40 *
41 * @switchdev_parent_id_get: Called to get an ID of the switch chip this port
42 * is part of. If driver implements this, it indicates that it
43 * represents a port of a switch chip.
44 *
45 * @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 *
49 * @switchdev_port_stp_update: Called to notify switch device port of bridge
50 * port STP state change.
51 *
52 * @switchdev_fib_ipv4_add: Called to add/modify IPv4 route to switch device.
53 *
54 * @switchdev_fib_ipv4_del: Called to delete IPv4 route from switch device.
55 */
56 struct switchdev_ops {
57 int (*switchdev_parent_id_get)(struct net_device *dev,
58 struct netdev_phys_item_id *psid);
59 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);
63 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);
71 };
72
73 enum switchdev_notifier_type {
74 SWITCHDEV_FDB_ADD = 1,
75 SWITCHDEV_FDB_DEL,
76 };
77
78 struct switchdev_notifier_info {
79 struct net_device *dev;
80 };
81
82 struct switchdev_notifier_fdb_info {
83 struct switchdev_notifier_info info; /* must be first */
84 const unsigned char *addr;
85 u16 vid;
86 };
87
88 static inline struct net_device *
89 switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
90 {
91 return info->dev;
92 }
93
94 #ifdef CONFIG_NET_SWITCHDEV
95
96 int switchdev_parent_id_get(struct net_device *dev,
97 struct netdev_phys_item_id *psid);
98 int switchdev_port_attr_get(struct net_device *dev,
99 struct switchdev_attr *attr);
100 int switchdev_port_attr_set(struct net_device *dev,
101 struct switchdev_attr *attr);
102 int switchdev_port_stp_update(struct net_device *dev, u8 state);
103 int register_switchdev_notifier(struct notifier_block *nb);
104 int unregister_switchdev_notifier(struct notifier_block *nb);
105 int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
106 struct switchdev_notifier_info *info);
107 int switchdev_port_bridge_setlink(struct net_device *dev,
108 struct nlmsghdr *nlh, u16 flags);
109 int switchdev_port_bridge_dellink(struct net_device *dev,
110 struct nlmsghdr *nlh, u16 flags);
111 int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
112 struct nlmsghdr *nlh, u16 flags);
113 int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
114 struct nlmsghdr *nlh, u16 flags);
115 int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
116 u8 tos, u8 type, u32 nlflags, u32 tb_id);
117 int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
118 u8 tos, u8 type, u32 tb_id);
119 void switchdev_fib_ipv4_abort(struct fib_info *fi);
120
121 #else
122
123 static inline int switchdev_parent_id_get(struct net_device *dev,
124 struct netdev_phys_item_id *psid)
125 {
126 return -EOPNOTSUPP;
127 }
128
129 static inline int switchdev_port_attr_get(struct net_device *dev,
130 struct switchdev_attr *attr)
131 {
132 return -EOPNOTSUPP;
133 }
134
135 static inline int switchdev_port_attr_set(struct net_device *dev,
136 struct switchdev_attr *attr)
137 {
138 return -EOPNOTSUPP;
139 }
140
141 static inline int switchdev_port_stp_update(struct net_device *dev,
142 u8 state)
143 {
144 return -EOPNOTSUPP;
145 }
146
147 static inline int register_switchdev_notifier(struct notifier_block *nb)
148 {
149 return 0;
150 }
151
152 static inline int unregister_switchdev_notifier(struct notifier_block *nb)
153 {
154 return 0;
155 }
156
157 static inline int call_switchdev_notifiers(unsigned long val,
158 struct net_device *dev,
159 struct switchdev_notifier_info *info)
160 {
161 return NOTIFY_DONE;
162 }
163
164 static inline int switchdev_port_bridge_setlink(struct net_device *dev,
165 struct nlmsghdr *nlh,
166 u16 flags)
167 {
168 return -EOPNOTSUPP;
169 }
170
171 static inline int switchdev_port_bridge_dellink(struct net_device *dev,
172 struct nlmsghdr *nlh,
173 u16 flags)
174 {
175 return -EOPNOTSUPP;
176 }
177
178 static inline int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
179 struct nlmsghdr *nlh,
180 u16 flags)
181 {
182 return 0;
183 }
184
185 static inline int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
186 struct nlmsghdr *nlh,
187 u16 flags)
188 {
189 return 0;
190 }
191
192 static 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)
196 {
197 return 0;
198 }
199
200 static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
201 struct fib_info *fi,
202 u8 tos, u8 type, u32 tb_id)
203 {
204 return 0;
205 }
206
207 static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
208 {
209 }
210
211 #endif
212
213 #endif /* _LINUX_SWITCHDEV_H_ */
This page took 0.041693 seconds and 6 git commands to generate.