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 | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 17 | struct fib_info; |
| 18 | |
| 19 | /** |
| 20 | * struct switchdev_ops - switchdev operations |
| 21 | * |
Jiri Pirko | 9d47c0a | 2015-05-10 09:47:47 -0700 | [diff] [blame^] | 22 | * @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] | 23 | * is part of. If driver implements this, it indicates that it |
| 24 | * represents a port of a switch chip. |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 25 | * |
Jiri Pirko | 9d47c0a | 2015-05-10 09:47:47 -0700 | [diff] [blame^] | 26 | * @switchdev_port_stp_update: Called to notify switch device port of bridge |
Scott Feldman | 13bb8e2 | 2015-03-20 17:42:46 -0700 | [diff] [blame] | 27 | * port STP state change. |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 28 | * |
Jiri Pirko | 9d47c0a | 2015-05-10 09:47:47 -0700 | [diff] [blame^] | 29 | * @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] | 30 | * |
Jiri Pirko | 9d47c0a | 2015-05-10 09:47:47 -0700 | [diff] [blame^] | 31 | * @switchdev_fib_ipv4_del: Called to delete IPv4 route from switch device. |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 32 | */ |
Jiri Pirko | 9d47c0a | 2015-05-10 09:47:47 -0700 | [diff] [blame^] | 33 | struct switchdev_ops { |
| 34 | int (*switchdev_parent_id_get)(struct net_device *dev, |
| 35 | struct netdev_phys_item_id *psid); |
| 36 | int (*switchdev_port_stp_update)(struct net_device *dev, u8 state); |
| 37 | int (*switchdev_fib_ipv4_add)(struct net_device *dev, __be32 dst, |
| 38 | int dst_len, struct fib_info *fi, |
| 39 | u8 tos, u8 type, u32 nlflags, |
| 40 | u32 tb_id); |
| 41 | int (*switchdev_fib_ipv4_del)(struct net_device *dev, __be32 dst, |
| 42 | int dst_len, struct fib_info *fi, |
| 43 | u8 tos, u8 type, u32 tb_id); |
Scott Feldman | 4170604 | 2015-03-15 21:07:14 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 46 | enum switchdev_notifier_type { |
| 47 | SWITCHDEV_FDB_ADD = 1, |
| 48 | SWITCHDEV_FDB_DEL, |
Jiri Pirko | 3aeb661 | 2015-01-15 23:49:37 +0100 | [diff] [blame] | 49 | }; |
| 50 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 51 | struct switchdev_notifier_info { |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 52 | struct net_device *dev; |
| 53 | }; |
| 54 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 55 | struct switchdev_notifier_fdb_info { |
| 56 | struct switchdev_notifier_info info; /* must be first */ |
Jiri Pirko | 3aeb661 | 2015-01-15 23:49:37 +0100 | [diff] [blame] | 57 | const unsigned char *addr; |
| 58 | u16 vid; |
| 59 | }; |
| 60 | |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 61 | static inline struct net_device * |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 62 | switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 63 | { |
| 64 | return info->dev; |
| 65 | } |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 66 | |
| 67 | #ifdef CONFIG_NET_SWITCHDEV |
| 68 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 69 | int switchdev_parent_id_get(struct net_device *dev, |
| 70 | struct netdev_phys_item_id *psid); |
| 71 | int switchdev_port_stp_update(struct net_device *dev, u8 state); |
| 72 | int register_switchdev_notifier(struct notifier_block *nb); |
| 73 | int unregister_switchdev_notifier(struct notifier_block *nb); |
| 74 | int call_switchdev_notifiers(unsigned long val, struct net_device *dev, |
| 75 | struct switchdev_notifier_info *info); |
| 76 | int switchdev_port_bridge_setlink(struct net_device *dev, |
| 77 | struct nlmsghdr *nlh, u16 flags); |
| 78 | int switchdev_port_bridge_dellink(struct net_device *dev, |
| 79 | struct nlmsghdr *nlh, u16 flags); |
| 80 | int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev, |
| 81 | struct nlmsghdr *nlh, u16 flags); |
| 82 | int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev, |
| 83 | struct nlmsghdr *nlh, u16 flags); |
| 84 | int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, |
| 85 | u8 tos, u8 type, u32 nlflags, u32 tb_id); |
| 86 | int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, |
| 87 | u8 tos, u8 type, u32 tb_id); |
| 88 | void switchdev_fib_ipv4_abort(struct fib_info *fi); |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 89 | |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 90 | #else |
| 91 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 92 | static inline int switchdev_parent_id_get(struct net_device *dev, |
| 93 | struct netdev_phys_item_id *psid) |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 94 | { |
| 95 | return -EOPNOTSUPP; |
| 96 | } |
| 97 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 98 | static inline int switchdev_port_stp_update(struct net_device *dev, |
| 99 | u8 state) |
Scott Feldman | 38dcf35 | 2014-11-28 14:34:20 +0100 | [diff] [blame] | 100 | { |
| 101 | return -EOPNOTSUPP; |
| 102 | } |
| 103 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 104 | static inline int register_switchdev_notifier(struct notifier_block *nb) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 105 | { |
| 106 | return 0; |
| 107 | } |
| 108 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 109 | static inline int unregister_switchdev_notifier(struct notifier_block *nb) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 110 | { |
| 111 | return 0; |
| 112 | } |
| 113 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 114 | static inline int call_switchdev_notifiers(unsigned long val, |
| 115 | struct net_device *dev, |
| 116 | struct switchdev_notifier_info *info) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 117 | { |
| 118 | return NOTIFY_DONE; |
| 119 | } |
| 120 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 121 | static inline int switchdev_port_bridge_setlink(struct net_device *dev, |
| 122 | struct nlmsghdr *nlh, |
| 123 | u16 flags) |
Roopa Prabhu | 8a44dbb | 2015-01-29 22:40:13 -0800 | [diff] [blame] | 124 | { |
| 125 | return -EOPNOTSUPP; |
| 126 | } |
| 127 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 128 | static inline int switchdev_port_bridge_dellink(struct net_device *dev, |
| 129 | struct nlmsghdr *nlh, |
| 130 | u16 flags) |
Roopa Prabhu | 8a44dbb | 2015-01-29 22:40:13 -0800 | [diff] [blame] | 131 | { |
| 132 | return -EOPNOTSUPP; |
| 133 | } |
| 134 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 135 | static inline int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev, |
| 136 | struct nlmsghdr *nlh, |
| 137 | u16 flags) |
Roopa Prabhu | 8a44dbb | 2015-01-29 22:40:13 -0800 | [diff] [blame] | 138 | { |
| 139 | return 0; |
| 140 | } |
| 141 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 142 | static inline int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev, |
| 143 | struct nlmsghdr *nlh, |
| 144 | u16 flags) |
Roopa Prabhu | 8a44dbb | 2015-01-29 22:40:13 -0800 | [diff] [blame] | 145 | { |
| 146 | return 0; |
| 147 | } |
| 148 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 149 | static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len, |
| 150 | struct fib_info *fi, |
| 151 | u8 tos, u8 type, |
| 152 | u32 nlflags, u32 tb_id) |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 153 | { |
| 154 | return 0; |
| 155 | } |
| 156 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 157 | static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len, |
| 158 | struct fib_info *fi, |
| 159 | u8 tos, u8 type, u32 tb_id) |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 160 | { |
| 161 | return 0; |
| 162 | } |
| 163 | |
Jiri Pirko | ebb9a03 | 2015-05-10 09:47:46 -0700 | [diff] [blame] | 164 | static inline void switchdev_fib_ipv4_abort(struct fib_info *fi) |
Scott Feldman | 8e05fd7 | 2015-03-05 21:21:19 -0800 | [diff] [blame] | 165 | { |
| 166 | } |
| 167 | |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 168 | #endif |
| 169 | |
| 170 | #endif /* _LINUX_SWITCHDEV_H_ */ |