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 | * |
| 22 | * int (*swdev_parent_id_get)(struct net_device *dev, |
| 23 | * struct netdev_phys_item_id *psid); |
| 24 | * Called to get an ID of the switch chip this port is part of. |
| 25 | * If driver implements this, it indicates that it represents a port |
| 26 | * of a switch chip. |
| 27 | * |
| 28 | * int (*swdev_port_stp_update)(struct net_device *dev, u8 state); |
| 29 | * Called to notify switch device port of bridge port STP |
| 30 | * state change. |
| 31 | * |
| 32 | * int (*swdev_fib_ipv4_add)(struct net_device *dev, __be32 dst, |
| 33 | * int dst_len, struct fib_info *fi, |
| 34 | * u8 tos, u8 type, u32 nlflags, u32 tb_id); |
| 35 | * Called to add/modify IPv4 route to switch device. |
| 36 | * |
| 37 | * int (*swdev_fib_ipv4_del)(struct net_device *dev, __be32 dst, |
| 38 | * int dst_len, struct fib_info *fi, |
| 39 | * u8 tos, u8 type, u32 tb_id); |
| 40 | * Called to delete IPv4 route from switch device. |
| 41 | */ |
| 42 | struct swdev_ops { |
| 43 | int (*swdev_parent_id_get)(struct net_device *dev, |
| 44 | struct netdev_phys_item_id *psid); |
| 45 | int (*swdev_port_stp_update)(struct net_device *dev, u8 state); |
| 46 | int (*swdev_fib_ipv4_add)(struct net_device *dev, __be32 dst, |
| 47 | int dst_len, struct fib_info *fi, |
| 48 | u8 tos, u8 type, u32 nlflags, |
| 49 | u32 tb_id); |
| 50 | int (*swdev_fib_ipv4_del)(struct net_device *dev, __be32 dst, |
| 51 | int dst_len, struct fib_info *fi, |
| 52 | u8 tos, u8 type, u32 tb_id); |
| 53 | }; |
| 54 | |
Jiri Pirko | 3aeb661 | 2015-01-15 23:49:37 +0100 | [diff] [blame] | 55 | enum netdev_switch_notifier_type { |
| 56 | NETDEV_SWITCH_FDB_ADD = 1, |
| 57 | NETDEV_SWITCH_FDB_DEL, |
| 58 | }; |
| 59 | |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 60 | struct netdev_switch_notifier_info { |
| 61 | struct net_device *dev; |
| 62 | }; |
| 63 | |
Jiri Pirko | 3aeb661 | 2015-01-15 23:49:37 +0100 | [diff] [blame] | 64 | struct netdev_switch_notifier_fdb_info { |
| 65 | struct netdev_switch_notifier_info info; /* must be first */ |
| 66 | const unsigned char *addr; |
| 67 | u16 vid; |
| 68 | }; |
| 69 | |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 70 | static inline struct net_device * |
| 71 | netdev_switch_notifier_info_to_dev(const struct netdev_switch_notifier_info *info) |
| 72 | { |
| 73 | return info->dev; |
| 74 | } |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 75 | |
| 76 | #ifdef CONFIG_NET_SWITCHDEV |
| 77 | |
| 78 | int netdev_switch_parent_id_get(struct net_device *dev, |
| 79 | struct netdev_phys_item_id *psid); |
Scott Feldman | 38dcf35 | 2014-11-28 14:34:20 +0100 | [diff] [blame] | 80 | int netdev_switch_port_stp_update(struct net_device *dev, u8 state); |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 81 | int register_netdev_switch_notifier(struct notifier_block *nb); |
| 82 | int unregister_netdev_switch_notifier(struct notifier_block *nb); |
| 83 | int call_netdev_switch_notifiers(unsigned long val, struct net_device *dev, |
| 84 | struct netdev_switch_notifier_info *info); |
Roopa Prabhu | 8a44dbb | 2015-01-29 22:40:13 -0800 | [diff] [blame] | 85 | int netdev_switch_port_bridge_setlink(struct net_device *dev, |
| 86 | struct nlmsghdr *nlh, u16 flags); |
| 87 | int netdev_switch_port_bridge_dellink(struct net_device *dev, |
| 88 | struct nlmsghdr *nlh, u16 flags); |
| 89 | int ndo_dflt_netdev_switch_port_bridge_dellink(struct net_device *dev, |
| 90 | struct nlmsghdr *nlh, u16 flags); |
| 91 | int ndo_dflt_netdev_switch_port_bridge_setlink(struct net_device *dev, |
| 92 | struct nlmsghdr *nlh, u16 flags); |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 93 | int netdev_switch_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi, |
Scott Feldman | f8f2147 | 2015-03-09 13:59:09 -0700 | [diff] [blame] | 94 | u8 tos, u8 type, u32 nlflags, u32 tb_id); |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 95 | int netdev_switch_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi, |
| 96 | u8 tos, u8 type, u32 tb_id); |
Scott Feldman | 8e05fd7 | 2015-03-05 21:21:19 -0800 | [diff] [blame] | 97 | void netdev_switch_fib_ipv4_abort(struct fib_info *fi); |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 98 | |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 99 | #else |
| 100 | |
| 101 | static inline int netdev_switch_parent_id_get(struct net_device *dev, |
| 102 | struct netdev_phys_item_id *psid) |
| 103 | { |
| 104 | return -EOPNOTSUPP; |
| 105 | } |
| 106 | |
Scott Feldman | 38dcf35 | 2014-11-28 14:34:20 +0100 | [diff] [blame] | 107 | static inline int netdev_switch_port_stp_update(struct net_device *dev, |
| 108 | u8 state) |
| 109 | { |
| 110 | return -EOPNOTSUPP; |
| 111 | } |
| 112 | |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 113 | static inline int register_netdev_switch_notifier(struct notifier_block *nb) |
| 114 | { |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | static inline int unregister_netdev_switch_notifier(struct notifier_block *nb) |
| 119 | { |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | static inline int call_netdev_switch_notifiers(unsigned long val, struct net_device *dev, |
Jiri Pirko | 27c0013 | 2015-01-18 10:25:56 +0100 | [diff] [blame] | 124 | struct netdev_switch_notifier_info *info) |
Jiri Pirko | 03bf0c2 | 2015-01-15 23:49:36 +0100 | [diff] [blame] | 125 | { |
| 126 | return NOTIFY_DONE; |
| 127 | } |
| 128 | |
Roopa Prabhu | 8a44dbb | 2015-01-29 22:40:13 -0800 | [diff] [blame] | 129 | static inline int netdev_switch_port_bridge_setlink(struct net_device *dev, |
| 130 | struct nlmsghdr *nlh, |
| 131 | u16 flags) |
| 132 | { |
| 133 | return -EOPNOTSUPP; |
| 134 | } |
| 135 | |
| 136 | static inline int netdev_switch_port_bridge_dellink(struct net_device *dev, |
| 137 | struct nlmsghdr *nlh, |
| 138 | u16 flags) |
| 139 | { |
| 140 | return -EOPNOTSUPP; |
| 141 | } |
| 142 | |
| 143 | static inline int ndo_dflt_netdev_switch_port_bridge_dellink(struct net_device *dev, |
| 144 | struct nlmsghdr *nlh, |
| 145 | u16 flags) |
| 146 | { |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | static inline int ndo_dflt_netdev_switch_port_bridge_setlink(struct net_device *dev, |
| 151 | struct nlmsghdr *nlh, |
| 152 | u16 flags) |
| 153 | { |
| 154 | return 0; |
| 155 | } |
| 156 | |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 157 | static inline int netdev_switch_fib_ipv4_add(u32 dst, int dst_len, |
| 158 | struct fib_info *fi, |
Scott Feldman | f8f2147 | 2015-03-09 13:59:09 -0700 | [diff] [blame] | 159 | u8 tos, u8 type, |
| 160 | u32 nlflags, u32 tb_id) |
Scott Feldman | 5e8d904 | 2015-03-05 21:21:15 -0800 | [diff] [blame] | 161 | { |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | static inline int netdev_switch_fib_ipv4_del(u32 dst, int dst_len, |
| 166 | struct fib_info *fi, |
| 167 | u8 tos, u8 type, u32 tb_id) |
| 168 | { |
| 169 | return 0; |
| 170 | } |
| 171 | |
Willem de Bruijn | 89650ad | 2015-03-06 11:44:28 -0500 | [diff] [blame] | 172 | static inline void netdev_switch_fib_ipv4_abort(struct fib_info *fi) |
Scott Feldman | 8e05fd7 | 2015-03-05 21:21:19 -0800 | [diff] [blame] | 173 | { |
| 174 | } |
| 175 | |
Jiri Pirko | 007f790 | 2014-11-28 14:34:17 +0100 | [diff] [blame] | 176 | #endif |
| 177 | |
| 178 | #endif /* _LINUX_SWITCHDEV_H_ */ |