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