Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 1 | /* |
| 2 | * include/net/switchdev.h - Switch device API |
| 3 | * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us> |
Scott Feldman | f8f2147 | 2015-03-09 13:59:09 -0700 | [diff] [blame] | 4 | * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com> |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 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> |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 15 | #include <linux/notifier.h> |
| 16 | |
Scott Feldman | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 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, |
Scott Feldman | f8e20a9 | 2015-05-10 09:47:49 -0700 | [diff] [blame] | 28 | SWITCHDEV_ATTR_PORT_PARENT_ID, |
Scott Feldman | 3563606 | 2015-05-10 09:47:51 -0700 | [diff] [blame] | 29 | SWITCHDEV_ATTR_PORT_STP_STATE, |
Scott Feldman | 6004c86 | 2015-05-10 09:47:55 -0700 | [diff] [blame] | 30 | SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS, |
Scott Feldman | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | struct switchdev_attr { |
| 34 | enum switchdev_attr_id id; |
| 35 | enum switchdev_trans trans; |
| 36 | u32 flags; |
Scott Feldman | f8e20a9 | 2015-05-10 09:47:49 -0700 | [diff] [blame] | 37 | union { |
| 38 | struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */ |
Scott Feldman | 3563606 | 2015-05-10 09:47:51 -0700 | [diff] [blame] | 39 | u8 stp_state; /* PORT_STP_STATE */ |
Scott Feldman | 6004c86 | 2015-05-10 09:47:55 -0700 | [diff] [blame] | 40 | unsigned long brport_flags; /* PORT_BRIDGE_FLAGS */ |
Scott Feldman | 42275bd | 2015-05-13 11:16:50 -0700 | [diff] [blame] | 41 | } u; |
Scott Feldman | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 44 | struct fib_info; |
| 45 | |
Scott Feldman | 491d0f1 | 2015-05-10 09:47:52 -0700 | [diff] [blame] | 46 | enum switchdev_obj_id { |
| 47 | SWITCHDEV_OBJ_UNDEFINED, |
Scott Feldman | 6fc3016 | 2015-05-10 09:47:53 -0700 | [diff] [blame] | 48 | SWITCHDEV_OBJ_PORT_VLAN, |
Scott Feldman | 58c2cb1 | 2015-05-10 09:48:06 -0700 | [diff] [blame] | 49 | SWITCHDEV_OBJ_IPV4_FIB, |
Samudrala, Sridhar | 45d4122 | 2015-05-13 21:55:43 -0700 | [diff] [blame] | 50 | SWITCHDEV_OBJ_PORT_FDB, |
Scott Feldman | 491d0f1 | 2015-05-10 09:47:52 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | struct switchdev_obj { |
| 54 | enum switchdev_obj_id id; |
| 55 | enum switchdev_trans trans; |
Samudrala, Sridhar | 45d4122 | 2015-05-13 21:55:43 -0700 | [diff] [blame] | 56 | int (*cb)(struct net_device *dev, struct switchdev_obj *obj); |
Scott Feldman | 6fc3016 | 2015-05-10 09:47:53 -0700 | [diff] [blame] | 57 | union { |
Scott Feldman | 5eb764e | 2015-05-12 23:03:53 -0700 | [diff] [blame] | 58 | struct switchdev_obj_vlan { /* PORT_VLAN */ |
Scott Feldman | 6fc3016 | 2015-05-10 09:47:53 -0700 | [diff] [blame] | 59 | u16 flags; |
Scott Feldman | 3e3a78b | 2015-06-22 00:27:16 -0700 | [diff] [blame] | 60 | u16 vid_begin; |
Scott Feldman | 6fc3016 | 2015-05-10 09:47:53 -0700 | [diff] [blame] | 61 | u16 vid_end; |
| 62 | } vlan; |
Scott Feldman | 58c2cb1 | 2015-05-10 09:48:06 -0700 | [diff] [blame] | 63 | struct switchdev_obj_ipv4_fib { /* IPV4_FIB */ |
| 64 | u32 dst; |
| 65 | int dst_len; |
| 66 | struct fib_info *fi; |
| 67 | u8 tos; |
| 68 | u8 type; |
| 69 | u32 nlflags; |
| 70 | u32 tb_id; |
| 71 | } ipv4_fib; |
Samudrala, Sridhar | 45d4122 | 2015-05-13 21:55:43 -0700 | [diff] [blame] | 72 | struct switchdev_obj_fdb { /* PORT_FDB */ |
David S. Miller | cdf0969 | 2015-08-11 12:00:37 -0700 | [diff] [blame] | 73 | const unsigned char *addr; |
Samudrala, Sridhar | 45d4122 | 2015-05-13 21:55:43 -0700 | [diff] [blame] | 74 | u16 vid; |
Vivien Didelot | ce80e7b | 2015-08-10 09:09:52 -0400 | [diff] [blame] | 75 | u16 ndm_state; |
Samudrala, Sridhar | 45d4122 | 2015-05-13 21:55:43 -0700 | [diff] [blame] | 76 | } fdb; |
Scott Feldman | 42275bd | 2015-05-13 11:16:50 -0700 | [diff] [blame] | 77 | } u; |
Scott Feldman | 491d0f1 | 2015-05-10 09:47:52 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 80 | /** |
| 81 | * struct switchdev_ops - switchdev operations |
| 82 | * |
Scott Feldman | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 83 | * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr). |
| 84 | * |
| 85 | * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr). |
| 86 | * |
Scott Feldman | 491d0f1 | 2015-05-10 09:47:52 -0700 | [diff] [blame] | 87 | * @switchdev_port_obj_add: Add an object to port (see switchdev_obj). |
| 88 | * |
| 89 | * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj). |
Samudrala, Sridhar | 45d4122 | 2015-05-13 21:55:43 -0700 | [diff] [blame] | 90 | * |
| 91 | * @switchdev_port_obj_dump: Dump port objects (see switchdev_obj). |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 92 | */ |
Jiri Pirko | 9d47c0a | 2015-05-10 09:47:47 -0700 | [diff] [blame] | 93 | struct switchdev_ops { |
Scott Feldman | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 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); |
Scott Feldman | 491d0f1 | 2015-05-10 09:47:52 -0700 | [diff] [blame] | 98 | int (*switchdev_port_obj_add)(struct net_device *dev, |
| 99 | struct switchdev_obj *obj); |
| 100 | int (*switchdev_port_obj_del)(struct net_device *dev, |
| 101 | struct switchdev_obj *obj); |
Samudrala, Sridhar | 45d4122 | 2015-05-13 21:55:43 -0700 | [diff] [blame] | 102 | int (*switchdev_port_obj_dump)(struct net_device *dev, |
| 103 | struct switchdev_obj *obj); |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 106 | enum switchdev_notifier_type { |
| 107 | SWITCHDEV_FDB_ADD = 1, |
| 108 | SWITCHDEV_FDB_DEL, |
Jiri Pirko | 3aeb661 | 2015-01-15 23:49:37 +0100 | [diff] [blame] | 109 | }; |
| 110 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 111 | struct switchdev_notifier_info { |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 112 | struct net_device *dev; |
| 113 | }; |
| 114 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 115 | struct switchdev_notifier_fdb_info { |
| 116 | struct switchdev_notifier_info info; /* must be first */ |
Jiri Pirko | 3aeb661 | 2015-01-15 23:49:37 +0100 | [diff] [blame] | 117 | const unsigned char *addr; |
| 118 | u16 vid; |
| 119 | }; |
| 120 | |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 121 | static inline struct net_device * |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 122 | switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 123 | { |
| 124 | return info->dev; |
| 125 | } |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 126 | |
| 127 | #ifdef CONFIG_NET_SWITCHDEV |
| 128 | |
Scott Feldman | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 129 | int switchdev_port_attr_get(struct net_device *dev, |
| 130 | struct switchdev_attr *attr); |
| 131 | int switchdev_port_attr_set(struct net_device *dev, |
| 132 | struct switchdev_attr *attr); |
Scott Feldman | 491d0f1 | 2015-05-10 09:47:52 -0700 | [diff] [blame] | 133 | int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj); |
| 134 | int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj); |
Samudrala, Sridhar | 45d4122 | 2015-05-13 21:55:43 -0700 | [diff] [blame] | 135 | int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj); |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 136 | int register_switchdev_notifier(struct notifier_block *nb); |
| 137 | int unregister_switchdev_notifier(struct notifier_block *nb); |
| 138 | int call_switchdev_notifiers(unsigned long val, struct net_device *dev, |
| 139 | struct switchdev_notifier_info *info); |
Scott Feldman | 8793d0a | 2015-05-10 09:48:04 -0700 | [diff] [blame] | 140 | int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 141 | struct net_device *dev, u32 filter_mask, |
| 142 | int nlflags); |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 143 | int switchdev_port_bridge_setlink(struct net_device *dev, |
| 144 | struct nlmsghdr *nlh, u16 flags); |
| 145 | int switchdev_port_bridge_dellink(struct net_device *dev, |
| 146 | struct nlmsghdr *nlh, u16 flags); |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 147 | int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, |
| 148 | u8 tos, u8 type, u32 nlflags, u32 tb_id); |
| 149 | int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, |
| 150 | u8 tos, u8 type, u32 tb_id); |
| 151 | void switchdev_fib_ipv4_abort(struct fib_info *fi); |
Samudrala, Sridhar | 45d4122 | 2015-05-13 21:55:43 -0700 | [diff] [blame] | 152 | int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 153 | struct net_device *dev, const unsigned char *addr, |
| 154 | u16 vid, u16 nlm_flags); |
| 155 | int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], |
| 156 | struct net_device *dev, const unsigned char *addr, |
| 157 | u16 vid); |
| 158 | int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, |
| 159 | struct net_device *dev, |
| 160 | struct net_device *filter_dev, int idx); |
Scott Feldman | 1a3b2ec | 2015-07-18 18:24:50 -0700 | [diff] [blame] | 161 | void switchdev_port_fwd_mark_set(struct net_device *dev, |
| 162 | struct net_device *group_dev, |
| 163 | bool joining); |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 164 | |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 165 | #else |
| 166 | |
Scott Feldman | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 167 | static inline int switchdev_port_attr_get(struct net_device *dev, |
| 168 | struct switchdev_attr *attr) |
| 169 | { |
| 170 | return -EOPNOTSUPP; |
| 171 | } |
| 172 | |
| 173 | static inline int switchdev_port_attr_set(struct net_device *dev, |
| 174 | struct switchdev_attr *attr) |
| 175 | { |
| 176 | return -EOPNOTSUPP; |
| 177 | } |
| 178 | |
Scott Feldman | 491d0f1 | 2015-05-10 09:47:52 -0700 | [diff] [blame] | 179 | static inline int switchdev_port_obj_add(struct net_device *dev, |
| 180 | struct switchdev_obj *obj) |
| 181 | { |
| 182 | return -EOPNOTSUPP; |
| 183 | } |
| 184 | |
| 185 | static inline int switchdev_port_obj_del(struct net_device *dev, |
| 186 | struct switchdev_obj *obj) |
| 187 | { |
| 188 | return -EOPNOTSUPP; |
| 189 | } |
| 190 | |
Samudrala, Sridhar | 45d4122 | 2015-05-13 21:55:43 -0700 | [diff] [blame] | 191 | static inline int switchdev_port_obj_dump(struct net_device *dev, |
| 192 | struct switchdev_obj *obj) |
| 193 | { |
| 194 | return -EOPNOTSUPP; |
| 195 | } |
| 196 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 197 | static inline int register_switchdev_notifier(struct notifier_block *nb) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 198 | { |
| 199 | return 0; |
| 200 | } |
| 201 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 202 | static inline int unregister_switchdev_notifier(struct notifier_block *nb) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 203 | { |
| 204 | return 0; |
| 205 | } |
| 206 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 207 | static inline int call_switchdev_notifiers(unsigned long val, |
| 208 | struct net_device *dev, |
| 209 | struct switchdev_notifier_info *info) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 210 | { |
| 211 | return NOTIFY_DONE; |
| 212 | } |
| 213 | |
Scott Feldman | 8793d0a | 2015-05-10 09:48:04 -0700 | [diff] [blame] | 214 | static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, |
| 215 | u32 seq, struct net_device *dev, |
| 216 | u32 filter_mask, int nlflags) |
| 217 | { |
| 218 | return -EOPNOTSUPP; |
| 219 | } |
| 220 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 221 | static inline int switchdev_port_bridge_setlink(struct net_device *dev, |
| 222 | struct nlmsghdr *nlh, |
| 223 | u16 flags) |
Roopa Prabhu | 8a44dbb | 2015-01-29 22:40:13 -0800 | [diff] [blame] | 224 | { |
| 225 | return -EOPNOTSUPP; |
| 226 | } |
| 227 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 228 | static inline int switchdev_port_bridge_dellink(struct net_device *dev, |
| 229 | struct nlmsghdr *nlh, |
| 230 | u16 flags) |
Roopa Prabhu | 8a44dbb | 2015-01-29 22:40:13 -0800 | [diff] [blame] | 231 | { |
| 232 | return -EOPNOTSUPP; |
| 233 | } |
| 234 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 235 | static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len, |
| 236 | struct fib_info *fi, |
| 237 | u8 tos, u8 type, |
| 238 | u32 nlflags, u32 tb_id) |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 239 | { |
| 240 | return 0; |
| 241 | } |
| 242 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 243 | static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len, |
| 244 | struct fib_info *fi, |
| 245 | u8 tos, u8 type, u32 tb_id) |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 246 | { |
| 247 | return 0; |
| 248 | } |
| 249 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 250 | static inline void switchdev_fib_ipv4_abort(struct fib_info *fi) |
Scott Feldman | 8e05fd7 | 2015-03-05 21:21:19 -0800 | [diff] [blame] | 251 | { |
| 252 | } |
| 253 | |
Samudrala, Sridhar | 45d4122 | 2015-05-13 21:55:43 -0700 | [diff] [blame] | 254 | static inline int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 255 | struct net_device *dev, |
| 256 | const unsigned char *addr, |
| 257 | u16 vid, u16 nlm_flags) |
| 258 | { |
| 259 | return -EOPNOTSUPP; |
| 260 | } |
| 261 | |
| 262 | static inline int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], |
| 263 | struct net_device *dev, |
| 264 | const unsigned char *addr, u16 vid) |
| 265 | { |
| 266 | return -EOPNOTSUPP; |
| 267 | } |
| 268 | |
| 269 | static inline int switchdev_port_fdb_dump(struct sk_buff *skb, |
| 270 | struct netlink_callback *cb, |
| 271 | struct net_device *dev, |
| 272 | struct net_device *filter_dev, |
| 273 | int idx) |
| 274 | { |
| 275 | return -EOPNOTSUPP; |
| 276 | } |
| 277 | |
Scott Feldman | 1a3b2ec | 2015-07-18 18:24:50 -0700 | [diff] [blame] | 278 | static inline void switchdev_port_fwd_mark_set(struct net_device *dev, |
| 279 | struct net_device *group_dev, |
| 280 | bool joining) |
| 281 | { |
| 282 | } |
| 283 | |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 284 | #endif |
| 285 | |
| 286 | #endif /* _LINUX_SWITCHDEV_H_ */ |