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 | f8e20a9 | 2015-05-10 09:47:49 -0700 | [diff] [blame] | 41 | }; |
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 | 491d0f1 | 2015-05-10 09:47:52 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | struct switchdev_obj { |
| 52 | enum switchdev_obj_id id; |
| 53 | enum switchdev_trans trans; |
Scott Feldman | 6fc3016 | 2015-05-10 09:47:53 -0700 | [diff] [blame] | 54 | union { |
| 55 | struct switchdev_obj_vlan { /* PORT_VLAN */ |
| 56 | u16 flags; |
| 57 | u16 vid_start; |
| 58 | u16 vid_end; |
| 59 | } vlan; |
| 60 | }; |
Scott Feldman | 491d0f1 | 2015-05-10 09:47:52 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 63 | /** |
| 64 | * struct switchdev_ops - switchdev operations |
| 65 | * |
Scott Feldman | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 66 | * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr). |
| 67 | * |
| 68 | * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr). |
| 69 | * |
Scott Feldman | 491d0f1 | 2015-05-10 09:47:52 -0700 | [diff] [blame] | 70 | * @switchdev_port_obj_add: Add an object to port (see switchdev_obj). |
| 71 | * |
| 72 | * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj). |
| 73 | * |
Jiri Pirko | 9d47c0a | 2015-05-10 09:47:47 -0700 | [diff] [blame] | 74 | * @switchdev_fib_ipv4_add: Called to add/modify IPv4 route to switch device. |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 75 | * |
Jiri Pirko | 9d47c0a | 2015-05-10 09:47:47 -0700 | [diff] [blame] | 76 | * @switchdev_fib_ipv4_del: Called to delete IPv4 route from switch device. |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 77 | */ |
Jiri Pirko | 9d47c0a | 2015-05-10 09:47:47 -0700 | [diff] [blame] | 78 | struct switchdev_ops { |
Scott Feldman | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 79 | int (*switchdev_port_attr_get)(struct net_device *dev, |
| 80 | struct switchdev_attr *attr); |
| 81 | int (*switchdev_port_attr_set)(struct net_device *dev, |
| 82 | struct switchdev_attr *attr); |
Scott Feldman | 491d0f1 | 2015-05-10 09:47:52 -0700 | [diff] [blame] | 83 | int (*switchdev_port_obj_add)(struct net_device *dev, |
| 84 | struct switchdev_obj *obj); |
| 85 | int (*switchdev_port_obj_del)(struct net_device *dev, |
| 86 | struct switchdev_obj *obj); |
Jiri Pirko | 9d47c0a | 2015-05-10 09:47:47 -0700 | [diff] [blame] | 87 | int (*switchdev_fib_ipv4_add)(struct net_device *dev, __be32 dst, |
| 88 | int dst_len, struct fib_info *fi, |
| 89 | u8 tos, u8 type, u32 nlflags, |
| 90 | u32 tb_id); |
| 91 | int (*switchdev_fib_ipv4_del)(struct net_device *dev, __be32 dst, |
| 92 | int dst_len, struct fib_info *fi, |
| 93 | u8 tos, u8 type, u32 tb_id); |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 96 | enum switchdev_notifier_type { |
| 97 | SWITCHDEV_FDB_ADD = 1, |
| 98 | SWITCHDEV_FDB_DEL, |
Jiri Pirko | 3aeb661 | 2015-01-15 23:49:37 +0100 | [diff] [blame] | 99 | }; |
| 100 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 101 | struct switchdev_notifier_info { |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 102 | struct net_device *dev; |
| 103 | }; |
| 104 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 105 | struct switchdev_notifier_fdb_info { |
| 106 | struct switchdev_notifier_info info; /* must be first */ |
Jiri Pirko | 3aeb661 | 2015-01-15 23:49:37 +0100 | [diff] [blame] | 107 | const unsigned char *addr; |
| 108 | u16 vid; |
| 109 | }; |
| 110 | |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 111 | static inline struct net_device * |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 112 | switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 113 | { |
| 114 | return info->dev; |
| 115 | } |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 116 | |
| 117 | #ifdef CONFIG_NET_SWITCHDEV |
| 118 | |
Scott Feldman | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 119 | int switchdev_port_attr_get(struct net_device *dev, |
| 120 | struct switchdev_attr *attr); |
| 121 | int switchdev_port_attr_set(struct net_device *dev, |
| 122 | struct switchdev_attr *attr); |
Scott Feldman | 491d0f1 | 2015-05-10 09:47:52 -0700 | [diff] [blame] | 123 | int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj); |
| 124 | int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj); |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 125 | int register_switchdev_notifier(struct notifier_block *nb); |
| 126 | int unregister_switchdev_notifier(struct notifier_block *nb); |
| 127 | int call_switchdev_notifiers(unsigned long val, struct net_device *dev, |
| 128 | struct switchdev_notifier_info *info); |
Scott Feldman | 8793d0a | 2015-05-10 09:48:04 -0700 | [diff] [blame^] | 129 | int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 130 | struct net_device *dev, u32 filter_mask, |
| 131 | int nlflags); |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 132 | int switchdev_port_bridge_setlink(struct net_device *dev, |
| 133 | struct nlmsghdr *nlh, u16 flags); |
| 134 | int switchdev_port_bridge_dellink(struct net_device *dev, |
| 135 | struct nlmsghdr *nlh, u16 flags); |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 136 | int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, |
| 137 | u8 tos, u8 type, u32 nlflags, u32 tb_id); |
| 138 | int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, |
| 139 | u8 tos, u8 type, u32 tb_id); |
| 140 | void switchdev_fib_ipv4_abort(struct fib_info *fi); |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 141 | |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 142 | #else |
| 143 | |
Scott Feldman | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 144 | static inline int switchdev_port_attr_get(struct net_device *dev, |
| 145 | struct switchdev_attr *attr) |
| 146 | { |
| 147 | return -EOPNOTSUPP; |
| 148 | } |
| 149 | |
| 150 | static inline int switchdev_port_attr_set(struct net_device *dev, |
| 151 | struct switchdev_attr *attr) |
| 152 | { |
| 153 | return -EOPNOTSUPP; |
| 154 | } |
| 155 | |
Scott Feldman | 491d0f1 | 2015-05-10 09:47:52 -0700 | [diff] [blame] | 156 | static inline int switchdev_port_obj_add(struct net_device *dev, |
| 157 | struct switchdev_obj *obj) |
| 158 | { |
| 159 | return -EOPNOTSUPP; |
| 160 | } |
| 161 | |
| 162 | static inline int switchdev_port_obj_del(struct net_device *dev, |
| 163 | struct switchdev_obj *obj) |
| 164 | { |
| 165 | return -EOPNOTSUPP; |
| 166 | } |
| 167 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 168 | static inline int register_switchdev_notifier(struct notifier_block *nb) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 169 | { |
| 170 | return 0; |
| 171 | } |
| 172 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 173 | static inline int unregister_switchdev_notifier(struct notifier_block *nb) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 174 | { |
| 175 | return 0; |
| 176 | } |
| 177 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 178 | static inline int call_switchdev_notifiers(unsigned long val, |
| 179 | struct net_device *dev, |
| 180 | struct switchdev_notifier_info *info) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 181 | { |
| 182 | return NOTIFY_DONE; |
| 183 | } |
| 184 | |
Scott Feldman | 8793d0a | 2015-05-10 09:48:04 -0700 | [diff] [blame^] | 185 | static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, |
| 186 | u32 seq, struct net_device *dev, |
| 187 | u32 filter_mask, int nlflags) |
| 188 | { |
| 189 | return -EOPNOTSUPP; |
| 190 | } |
| 191 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 192 | static inline int switchdev_port_bridge_setlink(struct net_device *dev, |
| 193 | struct nlmsghdr *nlh, |
| 194 | u16 flags) |
Roopa Prabhu | 8a44dbb | 2015-01-29 22:40:13 -0800 | [diff] [blame] | 195 | { |
| 196 | return -EOPNOTSUPP; |
| 197 | } |
| 198 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 199 | static inline int switchdev_port_bridge_dellink(struct net_device *dev, |
| 200 | struct nlmsghdr *nlh, |
| 201 | u16 flags) |
Roopa Prabhu | 8a44dbb | 2015-01-29 22:40:13 -0800 | [diff] [blame] | 202 | { |
| 203 | return -EOPNOTSUPP; |
| 204 | } |
| 205 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 206 | static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len, |
| 207 | struct fib_info *fi, |
| 208 | u8 tos, u8 type, |
| 209 | u32 nlflags, u32 tb_id) |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 210 | { |
| 211 | return 0; |
| 212 | } |
| 213 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 214 | static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len, |
| 215 | struct fib_info *fi, |
| 216 | u8 tos, u8 type, u32 tb_id) |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 217 | { |
| 218 | return 0; |
| 219 | } |
| 220 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 221 | static inline void switchdev_fib_ipv4_abort(struct fib_info *fi) |
Scott Feldman | 8e05fd7 | 2015-03-05 21:21:19 -0800 | [diff] [blame] | 222 | { |
| 223 | } |
| 224 | |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 225 | #endif |
| 226 | |
| 227 | #endif /* _LINUX_SWITCHDEV_H_ */ |