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 | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | struct switchdev_attr { |
| 32 | enum switchdev_attr_id id; |
| 33 | enum switchdev_trans trans; |
| 34 | u32 flags; |
Scott Feldman | f8e20a9 | 2015-05-10 09:47:49 -0700 | [diff] [blame^] | 35 | union { |
| 36 | struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */ |
| 37 | }; |
Scott Feldman | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 40 | struct fib_info; |
| 41 | |
| 42 | /** |
| 43 | * struct switchdev_ops - switchdev operations |
| 44 | * |
Scott Feldman | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 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 | * |
Jiri Pirko | 9d47c0a | 2015-05-10 09:47:47 -0700 | [diff] [blame] | 49 | * @switchdev_port_stp_update: Called to notify switch device port of bridge |
Scott Feldman | 13bb8e2 | 2015-03-20 17:42:46 -0700 | [diff] [blame] | 50 | * port STP state change. |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 51 | * |
Jiri Pirko | 9d47c0a | 2015-05-10 09:47:47 -0700 | [diff] [blame] | 52 | * @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] | 53 | * |
Jiri Pirko | 9d47c0a | 2015-05-10 09:47:47 -0700 | [diff] [blame] | 54 | * @switchdev_fib_ipv4_del: Called to delete IPv4 route from switch device. |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 55 | */ |
Jiri Pirko | 9d47c0a | 2015-05-10 09:47:47 -0700 | [diff] [blame] | 56 | struct switchdev_ops { |
Scott Feldman | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 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); |
Jiri Pirko | 9d47c0a | 2015-05-10 09:47:47 -0700 | [diff] [blame] | 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); |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 71 | enum switchdev_notifier_type { |
| 72 | SWITCHDEV_FDB_ADD = 1, |
| 73 | SWITCHDEV_FDB_DEL, |
Jiri Pirko | 3aeb661 | 2015-01-15 23:49:37 +0100 | [diff] [blame] | 74 | }; |
| 75 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 76 | struct switchdev_notifier_info { |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 77 | struct net_device *dev; |
| 78 | }; |
| 79 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 80 | struct switchdev_notifier_fdb_info { |
| 81 | struct switchdev_notifier_info info; /* must be first */ |
Jiri Pirko | 3aeb661 | 2015-01-15 23:49:37 +0100 | [diff] [blame] | 82 | const unsigned char *addr; |
| 83 | u16 vid; |
| 84 | }; |
| 85 | |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 86 | static inline struct net_device * |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 87 | switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 88 | { |
| 89 | return info->dev; |
| 90 | } |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 91 | |
| 92 | #ifdef CONFIG_NET_SWITCHDEV |
| 93 | |
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); |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 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); |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 116 | |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 117 | #else |
| 118 | |
Scott Feldman | 3094333 | 2015-05-10 09:47:48 -0700 | [diff] [blame] | 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 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 131 | static inline int switchdev_port_stp_update(struct net_device *dev, |
| 132 | u8 state) |
Scott Feldman | 38dcf35 | 2014-11-28 14:34:20 +0100 | [diff] [blame] | 133 | { |
| 134 | return -EOPNOTSUPP; |
| 135 | } |
| 136 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 137 | static inline int register_switchdev_notifier(struct notifier_block *nb) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 138 | { |
| 139 | return 0; |
| 140 | } |
| 141 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 142 | static inline int unregister_switchdev_notifier(struct notifier_block *nb) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 143 | { |
| 144 | return 0; |
| 145 | } |
| 146 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 147 | static inline int call_switchdev_notifiers(unsigned long val, |
| 148 | struct net_device *dev, |
| 149 | struct switchdev_notifier_info *info) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 150 | { |
| 151 | return NOTIFY_DONE; |
| 152 | } |
| 153 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 154 | static inline int switchdev_port_bridge_setlink(struct net_device *dev, |
| 155 | struct nlmsghdr *nlh, |
| 156 | u16 flags) |
Roopa Prabhu | 8a44dbb | 2015-01-29 22:40:13 -0800 | [diff] [blame] | 157 | { |
| 158 | return -EOPNOTSUPP; |
| 159 | } |
| 160 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 161 | static inline int switchdev_port_bridge_dellink(struct net_device *dev, |
| 162 | struct nlmsghdr *nlh, |
| 163 | u16 flags) |
Roopa Prabhu | 8a44dbb | 2015-01-29 22:40:13 -0800 | [diff] [blame] | 164 | { |
| 165 | return -EOPNOTSUPP; |
| 166 | } |
| 167 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 168 | static inline int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev, |
| 169 | struct nlmsghdr *nlh, |
| 170 | u16 flags) |
Roopa Prabhu | 8a44dbb | 2015-01-29 22:40:13 -0800 | [diff] [blame] | 171 | { |
| 172 | return 0; |
| 173 | } |
| 174 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 175 | static inline int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev, |
| 176 | struct nlmsghdr *nlh, |
| 177 | u16 flags) |
Roopa Prabhu | 8a44dbb | 2015-01-29 22:40:13 -0800 | [diff] [blame] | 178 | { |
| 179 | return 0; |
| 180 | } |
| 181 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 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) |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 186 | { |
| 187 | return 0; |
| 188 | } |
| 189 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 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) |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 193 | { |
| 194 | return 0; |
| 195 | } |
| 196 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 197 | static inline void switchdev_fib_ipv4_abort(struct fib_info *fi) |
Scott Feldman | 8e05fd7 | 2015-03-05 21:21:19 -0800 | [diff] [blame] | 198 | { |
| 199 | } |
| 200 | |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 201 | #endif |
| 202 | |
| 203 | #endif /* _LINUX_SWITCHDEV_H_ */ |