2 * include/net/switchdev.h - Switch device API
3 * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
4 * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com>
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.
11 #ifndef _LINUX_SWITCHDEV_H_
12 #define _LINUX_SWITCHDEV_H_
14 #include <linux/netdevice.h>
15 #include <linux/notifier.h>
17 #define SWITCHDEV_F_NO_RECURSE BIT(0)
19 enum switchdev_trans {
21 SWITCHDEV_TRANS_PREPARE,
22 SWITCHDEV_TRANS_ABORT,
23 SWITCHDEV_TRANS_COMMIT,
26 enum switchdev_attr_id {
27 SWITCHDEV_ATTR_UNDEFINED,
28 SWITCHDEV_ATTR_PORT_PARENT_ID,
31 struct switchdev_attr {
32 enum switchdev_attr_id id;
33 enum switchdev_trans trans;
36 struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
43 * struct switchdev_ops - switchdev operations
45 * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
47 * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
49 * @switchdev_port_stp_update: Called to notify switch device port of bridge
50 * port STP state change.
52 * @switchdev_fib_ipv4_add: Called to add/modify IPv4 route to switch device.
54 * @switchdev_fib_ipv4_del: Called to delete IPv4 route from switch device.
56 struct switchdev_ops {
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);
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,
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);
71 enum switchdev_notifier_type {
72 SWITCHDEV_FDB_ADD = 1,
76 struct switchdev_notifier_info {
77 struct net_device *dev;
80 struct switchdev_notifier_fdb_info {
81 struct switchdev_notifier_info info; /* must be first */
82 const unsigned char *addr;
86 static inline struct net_device *
87 switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
92 #ifdef CONFIG_NET_SWITCHDEV
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);
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);
119 static inline int switchdev_port_attr_get(struct net_device *dev,
120 struct switchdev_attr *attr)
125 static inline int switchdev_port_attr_set(struct net_device *dev,
126 struct switchdev_attr *attr)
131 static inline int switchdev_port_stp_update(struct net_device *dev,
137 static inline int register_switchdev_notifier(struct notifier_block *nb)
142 static inline int unregister_switchdev_notifier(struct notifier_block *nb)
147 static inline int call_switchdev_notifiers(unsigned long val,
148 struct net_device *dev,
149 struct switchdev_notifier_info *info)
154 static inline int switchdev_port_bridge_setlink(struct net_device *dev,
155 struct nlmsghdr *nlh,
161 static inline int switchdev_port_bridge_dellink(struct net_device *dev,
162 struct nlmsghdr *nlh,
168 static inline int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
169 struct nlmsghdr *nlh,
175 static inline int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
176 struct nlmsghdr *nlh,
182 static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
185 u32 nlflags, u32 tb_id)
190 static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
192 u8 tos, u8 type, u32 tb_id)
197 static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
203 #endif /* _LINUX_SWITCHDEV_H_ */