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,
30 SWITCHDEV_ATTR_PORT_BRIDGE_FLAGS,
33 struct switchdev_attr {
34 enum switchdev_attr_id id;
35 enum switchdev_trans trans;
38 struct netdev_phys_item_id ppid; /* PORT_PARENT_ID */
39 u8 stp_state; /* PORT_STP_STATE */
40 unsigned long brport_flags; /* PORT_BRIDGE_FLAGS */
46 enum switchdev_obj_id {
47 SWITCHDEV_OBJ_UNDEFINED,
48 SWITCHDEV_OBJ_PORT_VLAN,
49 SWITCHDEV_OBJ_IPV4_FIB,
52 struct switchdev_obj {
53 enum switchdev_obj_id id;
54 enum switchdev_trans trans;
56 struct switchdev_obj_vlan { /* PORT_VLAN */
61 struct switchdev_obj_ipv4_fib { /* IPV4_FIB */
74 * struct switchdev_ops - switchdev operations
76 * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
78 * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
80 * @switchdev_port_obj_add: Add an object to port (see switchdev_obj).
82 * @switchdev_port_obj_del: Delete an object from port (see switchdev_obj).
84 struct switchdev_ops {
85 int (*switchdev_port_attr_get)(struct net_device *dev,
86 struct switchdev_attr *attr);
87 int (*switchdev_port_attr_set)(struct net_device *dev,
88 struct switchdev_attr *attr);
89 int (*switchdev_port_obj_add)(struct net_device *dev,
90 struct switchdev_obj *obj);
91 int (*switchdev_port_obj_del)(struct net_device *dev,
92 struct switchdev_obj *obj);
95 enum switchdev_notifier_type {
96 SWITCHDEV_FDB_ADD = 1,
100 struct switchdev_notifier_info {
101 struct net_device *dev;
104 struct switchdev_notifier_fdb_info {
105 struct switchdev_notifier_info info; /* must be first */
106 const unsigned char *addr;
110 static inline struct net_device *
111 switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
116 #ifdef CONFIG_NET_SWITCHDEV
118 int switchdev_port_attr_get(struct net_device *dev,
119 struct switchdev_attr *attr);
120 int switchdev_port_attr_set(struct net_device *dev,
121 struct switchdev_attr *attr);
122 int switchdev_port_obj_add(struct net_device *dev, struct switchdev_obj *obj);
123 int switchdev_port_obj_del(struct net_device *dev, struct switchdev_obj *obj);
124 int register_switchdev_notifier(struct notifier_block *nb);
125 int unregister_switchdev_notifier(struct notifier_block *nb);
126 int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
127 struct switchdev_notifier_info *info);
128 int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
129 struct net_device *dev, u32 filter_mask,
131 int switchdev_port_bridge_setlink(struct net_device *dev,
132 struct nlmsghdr *nlh, u16 flags);
133 int switchdev_port_bridge_dellink(struct net_device *dev,
134 struct nlmsghdr *nlh, u16 flags);
135 int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
136 u8 tos, u8 type, u32 nlflags, u32 tb_id);
137 int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
138 u8 tos, u8 type, u32 tb_id);
139 void switchdev_fib_ipv4_abort(struct fib_info *fi);
143 static inline int switchdev_port_attr_get(struct net_device *dev,
144 struct switchdev_attr *attr)
149 static inline int switchdev_port_attr_set(struct net_device *dev,
150 struct switchdev_attr *attr)
155 static inline int switchdev_port_obj_add(struct net_device *dev,
156 struct switchdev_obj *obj)
161 static inline int switchdev_port_obj_del(struct net_device *dev,
162 struct switchdev_obj *obj)
167 static inline int register_switchdev_notifier(struct notifier_block *nb)
172 static inline int unregister_switchdev_notifier(struct notifier_block *nb)
177 static inline int call_switchdev_notifiers(unsigned long val,
178 struct net_device *dev,
179 struct switchdev_notifier_info *info)
184 static inline int switchdev_port_bridge_getlink(struct sk_buff *skb, u32 pid,
185 u32 seq, struct net_device *dev,
186 u32 filter_mask, int nlflags)
191 static inline int switchdev_port_bridge_setlink(struct net_device *dev,
192 struct nlmsghdr *nlh,
198 static inline int switchdev_port_bridge_dellink(struct net_device *dev,
199 struct nlmsghdr *nlh,
205 static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
208 u32 nlflags, u32 tb_id)
213 static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
215 u8 tos, u8 type, u32 tb_id)
220 static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
226 #endif /* _LINUX_SWITCHDEV_H_ */