| 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 | SWITCHDEV_ATTR_PORT_STP_STATE, |
| 30 | SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS, |
| 31 | }; |
| 32 | |
| 33 | struct switchdev_attr { |
| 34 | enum switchdev_attr_id id; |
| 35 | enum switchdev_trans trans; |
| 36 | u32 flags; |
| 37 | union { |
| 38 | struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */ |
| 39 | u8 stp_state; /* PORT_STP_STATE */ |
| 40 | unsigned long brport_flags; /* PORT_BRIDGE_FLAGS */ |
| 41 | } u; |
| 42 | }; |
| 43 | |
| 44 | struct fib_info; |
| 45 | |
| 46 | enum switchdev_obj_id { |
| 47 | SWITCHDEV_OBJ_UNDEFINED, |
| 48 | SWITCHDEV_OBJ_PORT_VLAN, |
| 49 | SWITCHDEV_OBJ_IPV4_FIB, |
| 50 | SWITCHDEV_OBJ_PORT_FDB, |
| 51 | }; |
| 52 | |
| 53 | struct switchdev_obj { |
| 54 | enum switchdev_obj_id id; |
| 55 | enum switchdev_trans trans; |
| 56 | int (*cb)(struct net_device *dev, struct switchdev_obj *obj); |
| 57 | union { |
| 58 | struct switchdev_obj_vlan { /* PORT_VLAN */ |
| 59 | u16 flags; |
| 60 | u16 vid_begin; |
| 61 | u16 vid_end; |
| 62 | } vlan; |
| 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; |
| 72 | struct switchdev_obj_fdb { /* PORT_FDB */ |
| 73 | const unsigned char *addr; |
| 74 | u16 vid; |
| 75 | } fdb; |
| 76 | } u; |
| 77 | }; |
| 78 | |
| 79 | /** |
| 80 | * struct switchdev_ops - switchdev operations |
| 81 | * |
| 82 | * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr). |
| 83 | * |
| 84 | * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr). |
| 85 | * |
| 86 | * @switchdev_port_obj_add: Add an object to port (see switchdev_obj). |
| 87 | * |
| 88 | * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj). |
| 89 | * |
| 90 | * @switchdev_port_obj_dump: Dump port objects (see switchdev_obj). |
| 91 | */ |
| 92 | struct switchdev_ops { |
| 93 | int (*switchdev_port_attr_get)(struct net_device *dev, |
| 94 | struct switchdev_attr *attr); |
| 95 | int (*switchdev_port_attr_set)(struct net_device *dev, |
| 96 | struct switchdev_attr *attr); |
| 97 | int (*switchdev_port_obj_add)(struct net_device *dev, |
| 98 | struct switchdev_obj *obj); |
| 99 | int (*switchdev_port_obj_del)(struct net_device *dev, |
| 100 | struct switchdev_obj *obj); |
| 101 | int (*switchdev_port_obj_dump)(struct net_device *dev, |
| 102 | struct switchdev_obj *obj); |
| 103 | }; |
| 104 | |
| 105 | enum switchdev_notifier_type { |
| 106 | SWITCHDEV_FDB_ADD = 1, |
| 107 | SWITCHDEV_FDB_DEL, |
| 108 | }; |
| 109 | |
| 110 | struct switchdev_notifier_info { |
| 111 | struct net_device *dev; |
| 112 | }; |
| 113 | |
| 114 | struct switchdev_notifier_fdb_info { |
| 115 | struct switchdev_notifier_info info; /* must be first */ |
| 116 | const unsigned char *addr; |
| 117 | u16 vid; |
| 118 | }; |
| 119 | |
| 120 | static inline struct net_device * |
| 121 | switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info) |
| 122 | { |
| 123 | return info->dev; |
| 124 | } |
| 125 | |
| 126 | #ifdef CONFIG_NET_SWITCHDEV |
| 127 | |
| 128 | int switchdev_port_attr_get(struct net_device *dev, |
| 129 | struct switchdev_attr *attr); |
| 130 | int switchdev_port_attr_set(struct net_device *dev, |
| 131 | struct switchdev_attr *attr); |
| 132 | int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj); |
| 133 | int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj); |
| 134 | int switchdev_port_obj_dump(struct net_device *dev, struct switchdev_obj *obj); |
| 135 | int register_switchdev_notifier(struct notifier_block *nb); |
| 136 | int unregister_switchdev_notifier(struct notifier_block *nb); |
| 137 | int call_switchdev_notifiers(unsigned long val, struct net_device *dev, |
| 138 | struct switchdev_notifier_info *info); |
| 139 | int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 140 | struct net_device *dev, u32 filter_mask, |
| 141 | int nlflags); |
| 142 | int switchdev_port_bridge_setlink(struct net_device *dev, |
| 143 | struct nlmsghdr *nlh, u16 flags); |
| 144 | int switchdev_port_bridge_dellink(struct net_device *dev, |
| 145 | struct nlmsghdr *nlh, u16 flags); |
| 146 | int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, |
| 147 | u8 tos, u8 type, u32 nlflags, u32 tb_id); |
| 148 | int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, |
| 149 | u8 tos, u8 type, u32 tb_id); |
| 150 | void switchdev_fib_ipv4_abort(struct fib_info *fi); |
| 151 | int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 152 | struct net_device *dev, const unsigned char *addr, |
| 153 | u16 vid, u16 nlm_flags); |
| 154 | int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], |
| 155 | struct net_device *dev, const unsigned char *addr, |
| 156 | u16 vid); |
| 157 | int switchdev_port_fdb_dump(struct sk_buff *skb, struct netlink_callback *cb, |
| 158 | struct net_device *dev, |
| 159 | struct net_device *filter_dev, int idx); |
| 160 | |
| 161 | #else |
| 162 | |
| 163 | static inline int switchdev_port_attr_get(struct net_device *dev, |
| 164 | struct switchdev_attr *attr) |
| 165 | { |
| 166 | return -EOPNOTSUPP; |
| 167 | } |
| 168 | |
| 169 | static inline int switchdev_port_attr_set(struct net_device *dev, |
| 170 | struct switchdev_attr *attr) |
| 171 | { |
| 172 | return -EOPNOTSUPP; |
| 173 | } |
| 174 | |
| 175 | static inline int switchdev_port_obj_add(struct net_device *dev, |
| 176 | struct switchdev_obj *obj) |
| 177 | { |
| 178 | return -EOPNOTSUPP; |
| 179 | } |
| 180 | |
| 181 | static inline int switchdev_port_obj_del(struct net_device *dev, |
| 182 | struct switchdev_obj *obj) |
| 183 | { |
| 184 | return -EOPNOTSUPP; |
| 185 | } |
| 186 | |
| 187 | static inline int switchdev_port_obj_dump(struct net_device *dev, |
| 188 | struct switchdev_obj *obj) |
| 189 | { |
| 190 | return -EOPNOTSUPP; |
| 191 | } |
| 192 | |
| 193 | static inline int register_switchdev_notifier(struct notifier_block *nb) |
| 194 | { |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | static inline int unregister_switchdev_notifier(struct notifier_block *nb) |
| 199 | { |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | static inline int call_switchdev_notifiers(unsigned long val, |
| 204 | struct net_device *dev, |
| 205 | struct switchdev_notifier_info *info) |
| 206 | { |
| 207 | return NOTIFY_DONE; |
| 208 | } |
| 209 | |
| 210 | static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, |
| 211 | u32 seq, struct net_device *dev, |
| 212 | u32 filter_mask, int nlflags) |
| 213 | { |
| 214 | return -EOPNOTSUPP; |
| 215 | } |
| 216 | |
| 217 | static inline int switchdev_port_bridge_setlink(struct net_device *dev, |
| 218 | struct nlmsghdr *nlh, |
| 219 | u16 flags) |
| 220 | { |
| 221 | return -EOPNOTSUPP; |
| 222 | } |
| 223 | |
| 224 | static inline int switchdev_port_bridge_dellink(struct net_device *dev, |
| 225 | struct nlmsghdr *nlh, |
| 226 | u16 flags) |
| 227 | { |
| 228 | return -EOPNOTSUPP; |
| 229 | } |
| 230 | |
| 231 | static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len, |
| 232 | struct fib_info *fi, |
| 233 | u8 tos, u8 type, |
| 234 | u32 nlflags, u32 tb_id) |
| 235 | { |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len, |
| 240 | struct fib_info *fi, |
| 241 | u8 tos, u8 type, u32 tb_id) |
| 242 | { |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | static inline void switchdev_fib_ipv4_abort(struct fib_info *fi) |
| 247 | { |
| 248 | } |
| 249 | |
| 250 | static inline int switchdev_port_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 251 | struct net_device *dev, |
| 252 | const unsigned char *addr, |
| 253 | u16 vid, u16 nlm_flags) |
| 254 | { |
| 255 | return -EOPNOTSUPP; |
| 256 | } |
| 257 | |
| 258 | static inline int switchdev_port_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], |
| 259 | struct net_device *dev, |
| 260 | const unsigned char *addr, u16 vid) |
| 261 | { |
| 262 | return -EOPNOTSUPP; |
| 263 | } |
| 264 | |
| 265 | static inline int switchdev_port_fdb_dump(struct sk_buff *skb, |
| 266 | struct netlink_callback *cb, |
| 267 | struct net_device *dev, |
| 268 | struct net_device *filter_dev, |
| 269 | int idx) |
| 270 | { |
| 271 | return -EOPNOTSUPP; |
| 272 | } |
| 273 | |
| 274 | #endif |
| 275 | |
| 276 | #endif /* _LINUX_SWITCHDEV_H_ */ |