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