]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/net/switchdev.h
switchdev: convert parent_id_get to switchdev attr get
[karo-tx-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         SWITCHDEV_ATTR_PORT_PARENT_ID,
29 };
30
31 struct switchdev_attr {
32         enum switchdev_attr_id id;
33         enum switchdev_trans trans;
34         u32 flags;
35         union {
36                 struct netdev_phys_item_id ppid;        /* PORT_PARENT_ID */
37         };
38 };
39
40 struct fib_info;
41
42 /**
43  * struct switchdev_ops - switchdev operations
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_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);
61         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);
69 };
70
71 enum switchdev_notifier_type {
72         SWITCHDEV_FDB_ADD = 1,
73         SWITCHDEV_FDB_DEL,
74 };
75
76 struct switchdev_notifier_info {
77         struct net_device *dev;
78 };
79
80 struct switchdev_notifier_fdb_info {
81         struct switchdev_notifier_info info; /* must be first */
82         const unsigned char *addr;
83         u16 vid;
84 };
85
86 static inline struct net_device *
87 switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
88 {
89         return info->dev;
90 }
91
92 #ifdef CONFIG_NET_SWITCHDEV
93
94 int switchdev_port_attr_get(struct net_device *dev,
95                             struct switchdev_attr *attr);
96 int switchdev_port_attr_set(struct net_device *dev,
97                             struct switchdev_attr *attr);
98 int switchdev_port_stp_update(struct net_device *dev, u8 state);
99 int register_switchdev_notifier(struct notifier_block *nb);
100 int unregister_switchdev_notifier(struct notifier_block *nb);
101 int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
102                              struct switchdev_notifier_info *info);
103 int switchdev_port_bridge_setlink(struct net_device *dev,
104                                   struct nlmsghdr *nlh, u16 flags);
105 int switchdev_port_bridge_dellink(struct net_device *dev,
106                                   struct nlmsghdr *nlh, u16 flags);
107 int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
108                                            struct nlmsghdr *nlh, u16 flags);
109 int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
110                                            struct nlmsghdr *nlh, u16 flags);
111 int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
112                            u8 tos, u8 type, u32 nlflags, u32 tb_id);
113 int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
114                            u8 tos, u8 type, u32 tb_id);
115 void switchdev_fib_ipv4_abort(struct fib_info *fi);
116
117 #else
118
119 static inline int switchdev_port_attr_get(struct net_device *dev,
120                                           struct switchdev_attr *attr)
121 {
122         return -EOPNOTSUPP;
123 }
124
125 static inline int switchdev_port_attr_set(struct net_device *dev,
126                                           struct switchdev_attr *attr)
127 {
128         return -EOPNOTSUPP;
129 }
130
131 static inline int switchdev_port_stp_update(struct net_device *dev,
132                                             u8 state)
133 {
134         return -EOPNOTSUPP;
135 }
136
137 static inline int register_switchdev_notifier(struct notifier_block *nb)
138 {
139         return 0;
140 }
141
142 static inline int unregister_switchdev_notifier(struct notifier_block *nb)
143 {
144         return 0;
145 }
146
147 static inline int call_switchdev_notifiers(unsigned long val,
148                                            struct net_device *dev,
149                                            struct switchdev_notifier_info *info)
150 {
151         return NOTIFY_DONE;
152 }
153
154 static inline int switchdev_port_bridge_setlink(struct net_device *dev,
155                                                 struct nlmsghdr *nlh,
156                                                 u16 flags)
157 {
158         return -EOPNOTSUPP;
159 }
160
161 static inline int switchdev_port_bridge_dellink(struct net_device *dev,
162                                                 struct nlmsghdr *nlh,
163                                                 u16 flags)
164 {
165         return -EOPNOTSUPP;
166 }
167
168 static inline int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
169                                                          struct nlmsghdr *nlh,
170                                                          u16 flags)
171 {
172         return 0;
173 }
174
175 static inline int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
176                                                          struct nlmsghdr *nlh,
177                                                          u16 flags)
178 {
179         return 0;
180 }
181
182 static 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)
186 {
187         return 0;
188 }
189
190 static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
191                                          struct fib_info *fi,
192                                          u8 tos, u8 type, u32 tb_id)
193 {
194         return 0;
195 }
196
197 static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
198 {
199 }
200
201 #endif
202
203 #endif /* _LINUX_SWITCHDEV_H_ */