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