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,
29 SWITCHDEV_ATTR_PORT_STP_STATE,
32 struct switchdev_attr {
33 enum switchdev_attr_id id;
34 enum switchdev_trans trans;
37 struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
38 u8 stp_state; /* PORT_STP_STATE */
44 enum switchdev_obj_id {
45 SWITCHDEV_OBJ_UNDEFINED,
48 struct switchdev_obj {
49 enum switchdev_obj_id id;
50 enum switchdev_trans trans;
54 * struct switchdev_ops - switchdev operations
56 * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
58 * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
60 * @switchdev_port_obj_add: Add an object to port (see switchdev_obj).
62 * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj).
64 * @switchdev_fib_ipv4_add: Called to add/modify IPv4 route to switch device.
66 * @switchdev_fib_ipv4_del: Called to delete IPv4 route from switch device.
68 struct switchdev_ops {
69 int (*switchdev_port_attr_get)(struct net_device *dev,
70 struct switchdev_attr *attr);
71 int (*switchdev_port_attr_set)(struct net_device *dev,
72 struct switchdev_attr *attr);
73 int (*switchdev_port_obj_add)(struct net_device *dev,
74 struct switchdev_obj *obj);
75 int (*switchdev_port_obj_del)(struct net_device *dev,
76 struct switchdev_obj *obj);
77 int (*switchdev_fib_ipv4_add)(struct net_device *dev, __be32 dst,
78 int dst_len, struct fib_info *fi,
79 u8 tos, u8 type, u32 nlflags,
81 int (*switchdev_fib_ipv4_del)(struct net_device *dev, __be32 dst,
82 int dst_len, struct fib_info *fi,
83 u8 tos, u8 type, u32 tb_id);
86 enum switchdev_notifier_type {
87 SWITCHDEV_FDB_ADD = 1,
91 struct switchdev_notifier_info {
92 struct net_device *dev;
95 struct switchdev_notifier_fdb_info {
96 struct switchdev_notifier_info info; /* must be first */
97 const unsigned char *addr;
101 static inline struct net_device *
102 switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
107 #ifdef CONFIG_NET_SWITCHDEV
109 int switchdev_port_attr_get(struct net_device *dev,
110 struct switchdev_attr *attr);
111 int switchdev_port_attr_set(struct net_device *dev,
112 struct switchdev_attr *attr);
113 int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj);
114 int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj);
115 int register_switchdev_notifier(struct notifier_block *nb);
116 int unregister_switchdev_notifier(struct notifier_block *nb);
117 int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
118 struct switchdev_notifier_info *info);
119 int switchdev_port_bridge_setlink(struct net_device *dev,
120 struct nlmsghdr *nlh, u16 flags);
121 int switchdev_port_bridge_dellink(struct net_device *dev,
122 struct nlmsghdr *nlh, u16 flags);
123 int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
124 struct nlmsghdr *nlh, u16 flags);
125 int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
126 struct nlmsghdr *nlh, u16 flags);
127 int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
128 u8 tos, u8 type, u32 nlflags, u32 tb_id);
129 int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
130 u8 tos, u8 type, u32 tb_id);
131 void switchdev_fib_ipv4_abort(struct fib_info *fi);
135 static inline int switchdev_port_attr_get(struct net_device *dev,
136 struct switchdev_attr *attr)
141 static inline int switchdev_port_attr_set(struct net_device *dev,
142 struct switchdev_attr *attr)
147 static inline int switchdev_port_obj_add(struct net_device *dev,
148 struct switchdev_obj *obj)
153 static inline int switchdev_port_obj_del(struct net_device *dev,
154 struct switchdev_obj *obj)
159 static inline int register_switchdev_notifier(struct notifier_block *nb)
164 static inline int unregister_switchdev_notifier(struct notifier_block *nb)
169 static inline int call_switchdev_notifiers(unsigned long val,
170 struct net_device *dev,
171 struct switchdev_notifier_info *info)
176 static inline int switchdev_port_bridge_setlink(struct net_device *dev,
177 struct nlmsghdr *nlh,
183 static inline int switchdev_port_bridge_dellink(struct net_device *dev,
184 struct nlmsghdr *nlh,
190 static inline int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
191 struct nlmsghdr *nlh,
197 static inline int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
198 struct nlmsghdr *nlh,
204 static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
207 u32 nlflags, u32 tb_id)
212 static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
214 u8 tos, u8 type, u32 tb_id)
219 static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
225 #endif /* _LINUX_SWITCHDEV_H_ */