diff options
author | Roopa Prabhu <roopa@cumulusnetworks.com> | 2015-01-30 01:40:13 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-02-02 02:16:34 -0500 |
commit | 8a44dbb202617aa66968ba74fdabf1b654dfe661 (patch) | |
tree | 4699440e3aa9dfc43f25ccddb8ccd288fea09ed4 | |
parent | add511b38266aa10c1079f9248854e6a415c4dc2 (diff) |
swdevice: add new apis to set and del bridge port attributes
This patch adds two new api's netdev_switch_port_bridge_setlink
and netdev_switch_port_bridge_dellink to offload bridge port attributes
to switch port
(The names of the apis look odd with 'switch_port_bridge',
but am more inclined to change the prefix of the api to something else.
Will take any suggestions).
The api's look at the NETIF_F_HW_SWITCH_OFFLOAD feature flag to
pass bridge port attributes to the port device.
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/switchdev.h | 37 | ||||
-rw-r--r-- | net/switchdev/switchdev.c | 110 |
2 files changed, 146 insertions, 1 deletions
diff --git a/include/net/switchdev.h b/include/net/switchdev.h index 205e63698da9..cfcdac2e5d25 100644 --- a/include/net/switchdev.h +++ b/include/net/switchdev.h | |||
@@ -43,7 +43,14 @@ int register_netdev_switch_notifier(struct notifier_block *nb); | |||
43 | int unregister_netdev_switch_notifier(struct notifier_block *nb); | 43 | int unregister_netdev_switch_notifier(struct notifier_block *nb); |
44 | int call_netdev_switch_notifiers(unsigned long val, struct net_device *dev, | 44 | int call_netdev_switch_notifiers(unsigned long val, struct net_device *dev, |
45 | struct netdev_switch_notifier_info *info); | 45 | struct netdev_switch_notifier_info *info); |
46 | 46 | int netdev_switch_port_bridge_setlink(struct net_device *dev, | |
47 | struct nlmsghdr *nlh, u16 flags); | ||
48 | int netdev_switch_port_bridge_dellink(struct net_device *dev, | ||
49 | struct nlmsghdr *nlh, u16 flags); | ||
50 | int ndo_dflt_netdev_switch_port_bridge_dellink(struct net_device *dev, | ||
51 | struct nlmsghdr *nlh, u16 flags); | ||
52 | int ndo_dflt_netdev_switch_port_bridge_setlink(struct net_device *dev, | ||
53 | struct nlmsghdr *nlh, u16 flags); | ||
47 | #else | 54 | #else |
48 | 55 | ||
49 | static inline int netdev_switch_parent_id_get(struct net_device *dev, | 56 | static inline int netdev_switch_parent_id_get(struct net_device *dev, |
@@ -74,6 +81,34 @@ static inline int call_netdev_switch_notifiers(unsigned long val, struct net_dev | |||
74 | return NOTIFY_DONE; | 81 | return NOTIFY_DONE; |
75 | } | 82 | } |
76 | 83 | ||
84 | static inline int netdev_switch_port_bridge_setlink(struct net_device *dev, | ||
85 | struct nlmsghdr *nlh, | ||
86 | u16 flags) | ||
87 | { | ||
88 | return -EOPNOTSUPP; | ||
89 | } | ||
90 | |||
91 | static inline int netdev_switch_port_bridge_dellink(struct net_device *dev, | ||
92 | struct nlmsghdr *nlh, | ||
93 | u16 flags) | ||
94 | { | ||
95 | return -EOPNOTSUPP; | ||
96 | } | ||
97 | |||
98 | static inline int ndo_dflt_netdev_switch_port_bridge_dellink(struct net_device *dev, | ||
99 | struct nlmsghdr *nlh, | ||
100 | u16 flags) | ||
101 | { | ||
102 | return 0; | ||
103 | } | ||
104 | |||
105 | static inline int ndo_dflt_netdev_switch_port_bridge_setlink(struct net_device *dev, | ||
106 | struct nlmsghdr *nlh, | ||
107 | u16 flags) | ||
108 | { | ||
109 | return 0; | ||
110 | } | ||
111 | |||
77 | #endif | 112 | #endif |
78 | 113 | ||
79 | #endif /* _LINUX_SWITCHDEV_H_ */ | 114 | #endif /* _LINUX_SWITCHDEV_H_ */ |
diff --git a/net/switchdev/switchdev.c b/net/switchdev/switchdev.c index 22e02f4edd99..8c1e558db118 100644 --- a/net/switchdev/switchdev.c +++ b/net/switchdev/switchdev.c | |||
@@ -115,3 +115,113 @@ int call_netdev_switch_notifiers(unsigned long val, struct net_device *dev, | |||
115 | return err; | 115 | return err; |
116 | } | 116 | } |
117 | EXPORT_SYMBOL(call_netdev_switch_notifiers); | 117 | EXPORT_SYMBOL(call_netdev_switch_notifiers); |
118 | |||
119 | /** | ||
120 | * netdev_switch_port_bridge_setlink - Notify switch device port of bridge | ||
121 | * port attributes | ||
122 | * | ||
123 | * @dev: port device | ||
124 | * @nlh: netlink msg with bridge port attributes | ||
125 | * @flags: bridge setlink flags | ||
126 | * | ||
127 | * Notify switch device port of bridge port attributes | ||
128 | */ | ||
129 | int netdev_switch_port_bridge_setlink(struct net_device *dev, | ||
130 | struct nlmsghdr *nlh, u16 flags) | ||
131 | { | ||
132 | const struct net_device_ops *ops = dev->netdev_ops; | ||
133 | |||
134 | if (!(dev->features & NETIF_F_HW_SWITCH_OFFLOAD)) | ||
135 | return 0; | ||
136 | |||
137 | if (!ops->ndo_bridge_setlink) | ||
138 | return -EOPNOTSUPP; | ||
139 | |||
140 | return ops->ndo_bridge_setlink(dev, nlh, flags); | ||
141 | } | ||
142 | EXPORT_SYMBOL(netdev_switch_port_bridge_setlink); | ||
143 | |||
144 | /** | ||
145 | * netdev_switch_port_bridge_dellink - Notify switch device port of bridge | ||
146 | * port attribute delete | ||
147 | * | ||
148 | * @dev: port device | ||
149 | * @nlh: netlink msg with bridge port attributes | ||
150 | * @flags: bridge setlink flags | ||
151 | * | ||
152 | * Notify switch device port of bridge port attribute delete | ||
153 | */ | ||
154 | int netdev_switch_port_bridge_dellink(struct net_device *dev, | ||
155 | struct nlmsghdr *nlh, u16 flags) | ||
156 | { | ||
157 | const struct net_device_ops *ops = dev->netdev_ops; | ||
158 | |||
159 | if (!(dev->features & NETIF_F_HW_SWITCH_OFFLOAD)) | ||
160 | return 0; | ||
161 | |||
162 | if (!ops->ndo_bridge_dellink) | ||
163 | return -EOPNOTSUPP; | ||
164 | |||
165 | return ops->ndo_bridge_dellink(dev, nlh, flags); | ||
166 | } | ||
167 | EXPORT_SYMBOL(netdev_switch_port_bridge_dellink); | ||
168 | |||
169 | /** | ||
170 | * ndo_dflt_netdev_switch_port_bridge_setlink - default ndo bridge setlink | ||
171 | * op for master devices | ||
172 | * | ||
173 | * @dev: port device | ||
174 | * @nlh: netlink msg with bridge port attributes | ||
175 | * @flags: bridge setlink flags | ||
176 | * | ||
177 | * Notify master device slaves of bridge port attributes | ||
178 | */ | ||
179 | int ndo_dflt_netdev_switch_port_bridge_setlink(struct net_device *dev, | ||
180 | struct nlmsghdr *nlh, u16 flags) | ||
181 | { | ||
182 | struct net_device *lower_dev; | ||
183 | struct list_head *iter; | ||
184 | int ret = 0, err = 0; | ||
185 | |||
186 | if (!(dev->features & NETIF_F_HW_SWITCH_OFFLOAD)) | ||
187 | return ret; | ||
188 | |||
189 | netdev_for_each_lower_dev(dev, lower_dev, iter) { | ||
190 | err = netdev_switch_port_bridge_setlink(lower_dev, nlh, flags); | ||
191 | if (err && err != -EOPNOTSUPP) | ||
192 | ret = err; | ||
193 | } | ||
194 | |||
195 | return ret; | ||
196 | } | ||
197 | EXPORT_SYMBOL(ndo_dflt_netdev_switch_port_bridge_setlink); | ||
198 | |||
199 | /** | ||
200 | * ndo_dflt_netdev_switch_port_bridge_dellink - default ndo bridge dellink | ||
201 | * op for master devices | ||
202 | * | ||
203 | * @dev: port device | ||
204 | * @nlh: netlink msg with bridge port attributes | ||
205 | * @flags: bridge dellink flags | ||
206 | * | ||
207 | * Notify master device slaves of bridge port attribute deletes | ||
208 | */ | ||
209 | int ndo_dflt_netdev_switch_port_bridge_dellink(struct net_device *dev, | ||
210 | struct nlmsghdr *nlh, u16 flags) | ||
211 | { | ||
212 | struct net_device *lower_dev; | ||
213 | struct list_head *iter; | ||
214 | int ret = 0, err = 0; | ||
215 | |||
216 | if (!(dev->features & NETIF_F_HW_SWITCH_OFFLOAD)) | ||
217 | return ret; | ||
218 | |||
219 | netdev_for_each_lower_dev(dev, lower_dev, iter) { | ||
220 | err = netdev_switch_port_bridge_dellink(lower_dev, nlh, flags); | ||
221 | if (err && err != -EOPNOTSUPP) | ||
222 | ret = err; | ||
223 | } | ||
224 | |||
225 | return ret; | ||
226 | } | ||
227 | EXPORT_SYMBOL(ndo_dflt_netdev_switch_port_bridge_dellink); | ||