switchdev: introduce get/set attrs ops
[deliverable/linux.git] / include / net / switchdev.h
CommitLineData
007f790c
JP
1/*
2 * include/net/switchdev.h - Switch device API
3 * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us>
f8f21471 4 * Copyright (c) 2014-2015 Scott Feldman <sfeldma@gmail.com>
007f790c
JP
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>
03bf0c28
JP
15#include <linux/notifier.h>
16
3094333d
SF
17#define SWITCHDEV_F_NO_RECURSE BIT(0)
18
19enum switchdev_trans {
20 SWITCHDEV_TRANS_NONE,
21 SWITCHDEV_TRANS_PREPARE,
22 SWITCHDEV_TRANS_ABORT,
23 SWITCHDEV_TRANS_COMMIT,
24};
25
26enum switchdev_attr_id {
27 SWITCHDEV_ATTR_UNDEFINED,
28};
29
30struct switchdev_attr {
31 enum switchdev_attr_id id;
32 enum switchdev_trans trans;
33 u32 flags;
34};
35
4170604f
SF
36struct fib_info;
37
38/**
39 * struct switchdev_ops - switchdev operations
40 *
9d47c0a2 41 * @switchdev_parent_id_get: Called to get an ID of the switch chip this port
13bb8e2e
SF
42 * is part of. If driver implements this, it indicates that it
43 * represents a port of a switch chip.
4170604f 44 *
3094333d
SF
45 * @switchdev_port_attr_get: Get a port attribute (see switchdev_attr).
46 *
47 * @switchdev_port_attr_set: Set a port attribute (see switchdev_attr).
48 *
9d47c0a2 49 * @switchdev_port_stp_update: Called to notify switch device port of bridge
13bb8e2e 50 * port STP state change.
4170604f 51 *
9d47c0a2 52 * @switchdev_fib_ipv4_add: Called to add/modify IPv4 route to switch device.
4170604f 53 *
9d47c0a2 54 * @switchdev_fib_ipv4_del: Called to delete IPv4 route from switch device.
4170604f 55 */
9d47c0a2
JP
56struct switchdev_ops {
57 int (*switchdev_parent_id_get)(struct net_device *dev,
58 struct netdev_phys_item_id *psid);
3094333d
SF
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);
9d47c0a2
JP
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,
67 u32 tb_id);
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);
4170604f
SF
71};
72
ebb9a03a
JP
73enum switchdev_notifier_type {
74 SWITCHDEV_FDB_ADD = 1,
75 SWITCHDEV_FDB_DEL,
3aeb6617
JP
76};
77
ebb9a03a 78struct switchdev_notifier_info {
03bf0c28
JP
79 struct net_device *dev;
80};
81
ebb9a03a
JP
82struct switchdev_notifier_fdb_info {
83 struct switchdev_notifier_info info; /* must be first */
3aeb6617
JP
84 const unsigned char *addr;
85 u16 vid;
86};
87
03bf0c28 88static inline struct net_device *
ebb9a03a 89switchdev_notifier_info_to_dev(const struct switchdev_notifier_info *info)
03bf0c28
JP
90{
91 return info->dev;
92}
007f790c
JP
93
94#ifdef CONFIG_NET_SWITCHDEV
95
ebb9a03a
JP
96int switchdev_parent_id_get(struct net_device *dev,
97 struct netdev_phys_item_id *psid);
3094333d
SF
98int switchdev_port_attr_get(struct net_device *dev,
99 struct switchdev_attr *attr);
100int switchdev_port_attr_set(struct net_device *dev,
101 struct switchdev_attr *attr);
ebb9a03a
JP
102int switchdev_port_stp_update(struct net_device *dev, u8 state);
103int register_switchdev_notifier(struct notifier_block *nb);
104int unregister_switchdev_notifier(struct notifier_block *nb);
105int call_switchdev_notifiers(unsigned long val, struct net_device *dev,
106 struct switchdev_notifier_info *info);
107int switchdev_port_bridge_setlink(struct net_device *dev,
108 struct nlmsghdr *nlh, u16 flags);
109int switchdev_port_bridge_dellink(struct net_device *dev,
110 struct nlmsghdr *nlh, u16 flags);
111int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
112 struct nlmsghdr *nlh, u16 flags);
113int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
114 struct nlmsghdr *nlh, u16 flags);
115int switchdev_fib_ipv4_add(u32 dst, int dst_len, struct fib_info *fi,
116 u8 tos, u8 type, u32 nlflags, u32 tb_id);
117int switchdev_fib_ipv4_del(u32 dst, int dst_len, struct fib_info *fi,
118 u8 tos, u8 type, u32 tb_id);
119void switchdev_fib_ipv4_abort(struct fib_info *fi);
5e8d9049 120
007f790c
JP
121#else
122
ebb9a03a
JP
123static inline int switchdev_parent_id_get(struct net_device *dev,
124 struct netdev_phys_item_id *psid)
007f790c
JP
125{
126 return -EOPNOTSUPP;
127}
128
3094333d
SF
129static inline int switchdev_port_attr_get(struct net_device *dev,
130 struct switchdev_attr *attr)
131{
132 return -EOPNOTSUPP;
133}
134
135static inline int switchdev_port_attr_set(struct net_device *dev,
136 struct switchdev_attr *attr)
137{
138 return -EOPNOTSUPP;
139}
140
ebb9a03a
JP
141static inline int switchdev_port_stp_update(struct net_device *dev,
142 u8 state)
38dcf357
SF
143{
144 return -EOPNOTSUPP;
145}
146
ebb9a03a 147static inline int register_switchdev_notifier(struct notifier_block *nb)
03bf0c28
JP
148{
149 return 0;
150}
151
ebb9a03a 152static inline int unregister_switchdev_notifier(struct notifier_block *nb)
03bf0c28
JP
153{
154 return 0;
155}
156
ebb9a03a
JP
157static inline int call_switchdev_notifiers(unsigned long val,
158 struct net_device *dev,
159 struct switchdev_notifier_info *info)
03bf0c28
JP
160{
161 return NOTIFY_DONE;
162}
163
ebb9a03a
JP
164static inline int switchdev_port_bridge_setlink(struct net_device *dev,
165 struct nlmsghdr *nlh,
166 u16 flags)
8a44dbb2
RP
167{
168 return -EOPNOTSUPP;
169}
170
ebb9a03a
JP
171static inline int switchdev_port_bridge_dellink(struct net_device *dev,
172 struct nlmsghdr *nlh,
173 u16 flags)
8a44dbb2
RP
174{
175 return -EOPNOTSUPP;
176}
177
ebb9a03a
JP
178static inline int ndo_dflt_switchdev_port_bridge_dellink(struct net_device *dev,
179 struct nlmsghdr *nlh,
180 u16 flags)
8a44dbb2
RP
181{
182 return 0;
183}
184
ebb9a03a
JP
185static inline int ndo_dflt_switchdev_port_bridge_setlink(struct net_device *dev,
186 struct nlmsghdr *nlh,
187 u16 flags)
8a44dbb2
RP
188{
189 return 0;
190}
191
ebb9a03a
JP
192static inline int switchdev_fib_ipv4_add(u32 dst, int dst_len,
193 struct fib_info *fi,
194 u8 tos, u8 type,
195 u32 nlflags, u32 tb_id)
5e8d9049
SF
196{
197 return 0;
198}
199
ebb9a03a
JP
200static inline int switchdev_fib_ipv4_del(u32 dst, int dst_len,
201 struct fib_info *fi,
202 u8 tos, u8 type, u32 tb_id)
5e8d9049
SF
203{
204 return 0;
205}
206
ebb9a03a 207static inline void switchdev_fib_ipv4_abort(struct fib_info *fi)
8e05fd71
SF
208{
209}
210
007f790c
JP
211#endif
212
213#endif /* _LINUX_SWITCHDEV_H_ */
This page took 0.058809 seconds and 5 git commands to generate.