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
,
30 struct switchdev_attr
{
31 enum switchdev_attr_id id
;
32 enum switchdev_trans trans
;
39 * struct switchdev_ops - switchdev operations
41 * @switchdev_parent_id_get: Called to get an ID of the switch chip this port
42 * is part of. If driver implements this, it indicates that it
43 * represents a port of a switch chip.
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_parent_id_get
)(struct net_device
*dev
,
58 struct netdev_phys_item_id
*psid
);
59 int (*switchdev_port_attr_get
)(struct net_device
*dev
,
60 struct switchdev_attr
*attr
);
61 int (*switchdev_port_attr_set
)(struct net_device
*dev
,
62 struct switchdev_attr
*attr
);
63 int (*switchdev_port_stp_update
)(struct net_device
*dev
, u8 state
);
64 int (*switchdev_fib_ipv4_add
)(struct net_device
*dev
, __be32 dst
,
65 int dst_len
, struct fib_info
*fi
,
66 u8 tos
, u8 type
, u32 nlflags
,
68 int (*switchdev_fib_ipv4_del
)(struct net_device
*dev
, __be32 dst
,
69 int dst_len
, struct fib_info
*fi
,
70 u8 tos
, u8 type
, u32 tb_id
);
73 enum switchdev_notifier_type
{
74 SWITCHDEV_FDB_ADD
= 1,
78 struct switchdev_notifier_info
{
79 struct net_device
*dev
;
82 struct switchdev_notifier_fdb_info
{
83 struct switchdev_notifier_info info
; /* must be first */
84 const unsigned char *addr
;
88 static inline struct net_device
*
89 switchdev_notifier_info_to_dev(const struct switchdev_notifier_info
*info
)
94 #ifdef CONFIG_NET_SWITCHDEV
96 int switchdev_parent_id_get(struct net_device
*dev
,
97 struct netdev_phys_item_id
*psid
);
98 int switchdev_port_attr_get(struct net_device
*dev
,
99 struct switchdev_attr
*attr
);
100 int switchdev_port_attr_set(struct net_device
*dev
,
101 struct switchdev_attr
*attr
);
102 int switchdev_port_stp_update(struct net_device
*dev
, u8 state
);
103 int register_switchdev_notifier(struct notifier_block
*nb
);
104 int unregister_switchdev_notifier(struct notifier_block
*nb
);
105 int call_switchdev_notifiers(unsigned long val
, struct net_device
*dev
,
106 struct switchdev_notifier_info
*info
);
107 int switchdev_port_bridge_setlink(struct net_device
*dev
,
108 struct nlmsghdr
*nlh
, u16 flags
);
109 int switchdev_port_bridge_dellink(struct net_device
*dev
,
110 struct nlmsghdr
*nlh
, u16 flags
);
111 int ndo_dflt_switchdev_port_bridge_dellink(struct net_device
*dev
,
112 struct nlmsghdr
*nlh
, u16 flags
);
113 int ndo_dflt_switchdev_port_bridge_setlink(struct net_device
*dev
,
114 struct nlmsghdr
*nlh
, u16 flags
);
115 int switchdev_fib_ipv4_add(u32 dst
, int dst_len
, struct fib_info
*fi
,
116 u8 tos
, u8 type
, u32 nlflags
, u32 tb_id
);
117 int switchdev_fib_ipv4_del(u32 dst
, int dst_len
, struct fib_info
*fi
,
118 u8 tos
, u8 type
, u32 tb_id
);
119 void switchdev_fib_ipv4_abort(struct fib_info
*fi
);
123 static inline int switchdev_parent_id_get(struct net_device
*dev
,
124 struct netdev_phys_item_id
*psid
)
129 static inline int switchdev_port_attr_get(struct net_device
*dev
,
130 struct switchdev_attr
*attr
)
135 static inline int switchdev_port_attr_set(struct net_device
*dev
,
136 struct switchdev_attr
*attr
)
141 static inline int switchdev_port_stp_update(struct net_device
*dev
,
147 static inline int register_switchdev_notifier(struct notifier_block
*nb
)
152 static inline int unregister_switchdev_notifier(struct notifier_block
*nb
)
157 static inline int call_switchdev_notifiers(unsigned long val
,
158 struct net_device
*dev
,
159 struct switchdev_notifier_info
*info
)
164 static inline int switchdev_port_bridge_setlink(struct net_device
*dev
,
165 struct nlmsghdr
*nlh
,
171 static inline int switchdev_port_bridge_dellink(struct net_device
*dev
,
172 struct nlmsghdr
*nlh
,
178 static inline int ndo_dflt_switchdev_port_bridge_dellink(struct net_device
*dev
,
179 struct nlmsghdr
*nlh
,
185 static inline int ndo_dflt_switchdev_port_bridge_setlink(struct net_device
*dev
,
186 struct nlmsghdr
*nlh
,
192 static inline int switchdev_fib_ipv4_add(u32 dst
, int dst_len
,
195 u32 nlflags
, u32 tb_id
)
200 static inline int switchdev_fib_ipv4_del(u32 dst
, int dst_len
,
202 u8 tos
, u8 type
, u32 tb_id
)
207 static inline void switchdev_fib_ipv4_abort(struct fib_info
*fi
)
213 #endif /* _LINUX_SWITCHDEV_H_ */