blob: 4d9e0ef23d9fe681046d7953968e918b3de5ae3b [file] [log] [blame]
Alexander Duyck2f90b862008-11-20 20:52:10 -08001/*
Mark Rustad698e1d22011-03-14 09:01:02 +00002 * Copyright (c) 2008-2011, Intel Corporation.
Alexander Duyck2f90b862008-11-20 20:52:10 -08003 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
16 *
17 * Author: Lucy Liu <lucy.liu@intel.com>
18 */
19
20#include <linux/netdevice.h>
21#include <linux/netlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Alexander Duyck2f90b862008-11-20 20:52:10 -080023#include <net/netlink.h>
24#include <net/rtnetlink.h>
25#include <linux/dcbnl.h>
John Fastabend96b99682010-12-30 09:26:37 +000026#include <net/dcbevent.h>
Alexander Duyck2f90b862008-11-20 20:52:10 -080027#include <linux/rtnetlink.h>
Paul Gortmaker3a9a2312011-05-27 09:12:25 -040028#include <linux/module.h>
Alexander Duyck2f90b862008-11-20 20:52:10 -080029#include <net/sock.h>
30
31/**
32 * Data Center Bridging (DCB) is a collection of Ethernet enhancements
33 * intended to allow network traffic with differing requirements
34 * (highly reliable, no drops vs. best effort vs. low latency) to operate
35 * and co-exist on Ethernet. Current DCB features are:
36 *
37 * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a
38 * framework for assigning bandwidth guarantees to traffic classes.
39 *
40 * Priority-based Flow Control (PFC) - provides a flow control mechanism which
41 * can work independently for each 802.1p priority.
42 *
43 * Congestion Notification - provides a mechanism for end-to-end congestion
44 * control for protocols which do not have built-in congestion management.
45 *
46 * More information about the emerging standards for these Ethernet features
47 * can be found at: http://www.ieee802.org/1/pages/dcbridges.html
48 *
49 * This file implements an rtnetlink interface to allow configuration of DCB
50 * features for capable devices.
51 */
52
53MODULE_AUTHOR("Lucy Liu, <lucy.liu@intel.com>");
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -080054MODULE_DESCRIPTION("Data Center Bridging netlink interface");
Alexander Duyck2f90b862008-11-20 20:52:10 -080055MODULE_LICENSE("GPL");
56
57/**************** DCB attribute policies *************************************/
58
59/* DCB netlink attributes policy */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +000060static const struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = {
Alexander Duyck859ee3c2008-11-20 21:10:23 -080061 [DCB_ATTR_IFNAME] = {.type = NLA_NUL_STRING, .len = IFNAMSIZ - 1},
62 [DCB_ATTR_STATE] = {.type = NLA_U8},
63 [DCB_ATTR_PFC_CFG] = {.type = NLA_NESTED},
64 [DCB_ATTR_PG_CFG] = {.type = NLA_NESTED},
65 [DCB_ATTR_SET_ALL] = {.type = NLA_U8},
Alexander Duyck2f90b862008-11-20 20:52:10 -080066 [DCB_ATTR_PERM_HWADDR] = {.type = NLA_FLAG},
Alexander Duyck859ee3c2008-11-20 21:10:23 -080067 [DCB_ATTR_CAP] = {.type = NLA_NESTED},
68 [DCB_ATTR_PFC_STATE] = {.type = NLA_U8},
69 [DCB_ATTR_BCN] = {.type = NLA_NESTED},
Yi Zou6fa382a2009-08-31 12:33:20 +000070 [DCB_ATTR_APP] = {.type = NLA_NESTED},
John Fastabend3e290272010-12-30 09:25:46 +000071 [DCB_ATTR_IEEE] = {.type = NLA_NESTED},
Shmulik Ravid6241b622010-12-30 06:26:48 +000072 [DCB_ATTR_DCBX] = {.type = NLA_U8},
Shmulik Ravidea45fe42010-12-30 06:26:55 +000073 [DCB_ATTR_FEATCFG] = {.type = NLA_NESTED},
Alexander Duyck2f90b862008-11-20 20:52:10 -080074};
75
76/* DCB priority flow control to User Priority nested attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +000077static const struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = {
Alexander Duyck2f90b862008-11-20 20:52:10 -080078 [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8},
79 [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8},
80 [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8},
81 [DCB_PFC_UP_ATTR_3] = {.type = NLA_U8},
82 [DCB_PFC_UP_ATTR_4] = {.type = NLA_U8},
83 [DCB_PFC_UP_ATTR_5] = {.type = NLA_U8},
84 [DCB_PFC_UP_ATTR_6] = {.type = NLA_U8},
85 [DCB_PFC_UP_ATTR_7] = {.type = NLA_U8},
86 [DCB_PFC_UP_ATTR_ALL] = {.type = NLA_FLAG},
87};
88
89/* DCB priority grouping nested attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +000090static const struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = {
Alexander Duyck2f90b862008-11-20 20:52:10 -080091 [DCB_PG_ATTR_TC_0] = {.type = NLA_NESTED},
92 [DCB_PG_ATTR_TC_1] = {.type = NLA_NESTED},
93 [DCB_PG_ATTR_TC_2] = {.type = NLA_NESTED},
94 [DCB_PG_ATTR_TC_3] = {.type = NLA_NESTED},
95 [DCB_PG_ATTR_TC_4] = {.type = NLA_NESTED},
96 [DCB_PG_ATTR_TC_5] = {.type = NLA_NESTED},
97 [DCB_PG_ATTR_TC_6] = {.type = NLA_NESTED},
98 [DCB_PG_ATTR_TC_7] = {.type = NLA_NESTED},
99 [DCB_PG_ATTR_TC_ALL] = {.type = NLA_NESTED},
100 [DCB_PG_ATTR_BW_ID_0] = {.type = NLA_U8},
101 [DCB_PG_ATTR_BW_ID_1] = {.type = NLA_U8},
102 [DCB_PG_ATTR_BW_ID_2] = {.type = NLA_U8},
103 [DCB_PG_ATTR_BW_ID_3] = {.type = NLA_U8},
104 [DCB_PG_ATTR_BW_ID_4] = {.type = NLA_U8},
105 [DCB_PG_ATTR_BW_ID_5] = {.type = NLA_U8},
106 [DCB_PG_ATTR_BW_ID_6] = {.type = NLA_U8},
107 [DCB_PG_ATTR_BW_ID_7] = {.type = NLA_U8},
108 [DCB_PG_ATTR_BW_ID_ALL] = {.type = NLA_FLAG},
109};
110
111/* DCB traffic class nested attributes. */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000112static const struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = {
Alexander Duyck2f90b862008-11-20 20:52:10 -0800113 [DCB_TC_ATTR_PARAM_PGID] = {.type = NLA_U8},
114 [DCB_TC_ATTR_PARAM_UP_MAPPING] = {.type = NLA_U8},
115 [DCB_TC_ATTR_PARAM_STRICT_PRIO] = {.type = NLA_U8},
116 [DCB_TC_ATTR_PARAM_BW_PCT] = {.type = NLA_U8},
117 [DCB_TC_ATTR_PARAM_ALL] = {.type = NLA_FLAG},
118};
119
Alexander Duyck46132182008-11-20 21:05:08 -0800120/* DCB capabilities nested attributes. */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000121static const struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = {
Alexander Duyck46132182008-11-20 21:05:08 -0800122 [DCB_CAP_ATTR_ALL] = {.type = NLA_FLAG},
123 [DCB_CAP_ATTR_PG] = {.type = NLA_U8},
124 [DCB_CAP_ATTR_PFC] = {.type = NLA_U8},
125 [DCB_CAP_ATTR_UP2TC] = {.type = NLA_U8},
126 [DCB_CAP_ATTR_PG_TCS] = {.type = NLA_U8},
127 [DCB_CAP_ATTR_PFC_TCS] = {.type = NLA_U8},
128 [DCB_CAP_ATTR_GSP] = {.type = NLA_U8},
129 [DCB_CAP_ATTR_BCN] = {.type = NLA_U8},
Shmulik Ravid6241b622010-12-30 06:26:48 +0000130 [DCB_CAP_ATTR_DCBX] = {.type = NLA_U8},
Alexander Duyck46132182008-11-20 21:05:08 -0800131};
Alexander Duyck2f90b862008-11-20 20:52:10 -0800132
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800133/* DCB capabilities nested attributes. */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000134static const struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = {
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800135 [DCB_NUMTCS_ATTR_ALL] = {.type = NLA_FLAG},
136 [DCB_NUMTCS_ATTR_PG] = {.type = NLA_U8},
137 [DCB_NUMTCS_ATTR_PFC] = {.type = NLA_U8},
138};
139
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800140/* DCB BCN nested attributes. */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000141static const struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = {
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800142 [DCB_BCN_ATTR_RP_0] = {.type = NLA_U8},
143 [DCB_BCN_ATTR_RP_1] = {.type = NLA_U8},
144 [DCB_BCN_ATTR_RP_2] = {.type = NLA_U8},
145 [DCB_BCN_ATTR_RP_3] = {.type = NLA_U8},
146 [DCB_BCN_ATTR_RP_4] = {.type = NLA_U8},
147 [DCB_BCN_ATTR_RP_5] = {.type = NLA_U8},
148 [DCB_BCN_ATTR_RP_6] = {.type = NLA_U8},
149 [DCB_BCN_ATTR_RP_7] = {.type = NLA_U8},
150 [DCB_BCN_ATTR_RP_ALL] = {.type = NLA_FLAG},
Don Skidmoref4314e82008-12-21 20:10:29 -0800151 [DCB_BCN_ATTR_BCNA_0] = {.type = NLA_U32},
152 [DCB_BCN_ATTR_BCNA_1] = {.type = NLA_U32},
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800153 [DCB_BCN_ATTR_ALPHA] = {.type = NLA_U32},
154 [DCB_BCN_ATTR_BETA] = {.type = NLA_U32},
155 [DCB_BCN_ATTR_GD] = {.type = NLA_U32},
156 [DCB_BCN_ATTR_GI] = {.type = NLA_U32},
157 [DCB_BCN_ATTR_TMAX] = {.type = NLA_U32},
158 [DCB_BCN_ATTR_TD] = {.type = NLA_U32},
159 [DCB_BCN_ATTR_RMIN] = {.type = NLA_U32},
160 [DCB_BCN_ATTR_W] = {.type = NLA_U32},
161 [DCB_BCN_ATTR_RD] = {.type = NLA_U32},
162 [DCB_BCN_ATTR_RU] = {.type = NLA_U32},
163 [DCB_BCN_ATTR_WRTT] = {.type = NLA_U32},
164 [DCB_BCN_ATTR_RI] = {.type = NLA_U32},
165 [DCB_BCN_ATTR_C] = {.type = NLA_U32},
166 [DCB_BCN_ATTR_ALL] = {.type = NLA_FLAG},
167};
168
Yi Zou6fa382a2009-08-31 12:33:20 +0000169/* DCB APP nested attributes. */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000170static const struct nla_policy dcbnl_app_nest[DCB_APP_ATTR_MAX + 1] = {
Yi Zou6fa382a2009-08-31 12:33:20 +0000171 [DCB_APP_ATTR_IDTYPE] = {.type = NLA_U8},
172 [DCB_APP_ATTR_ID] = {.type = NLA_U16},
173 [DCB_APP_ATTR_PRIORITY] = {.type = NLA_U8},
174};
175
John Fastabend3e290272010-12-30 09:25:46 +0000176/* IEEE 802.1Qaz nested attributes. */
177static const struct nla_policy dcbnl_ieee_policy[DCB_ATTR_IEEE_MAX + 1] = {
178 [DCB_ATTR_IEEE_ETS] = {.len = sizeof(struct ieee_ets)},
179 [DCB_ATTR_IEEE_PFC] = {.len = sizeof(struct ieee_pfc)},
180 [DCB_ATTR_IEEE_APP_TABLE] = {.type = NLA_NESTED},
Amir Vadai08f10af2012-04-04 21:33:30 +0000181 [DCB_ATTR_IEEE_MAXRATE] = {.len = sizeof(struct ieee_maxrate)},
John Fastabend3e290272010-12-30 09:25:46 +0000182};
183
184static const struct nla_policy dcbnl_ieee_app[DCB_ATTR_IEEE_APP_MAX + 1] = {
185 [DCB_ATTR_IEEE_APP] = {.len = sizeof(struct dcb_app)},
186};
187
Shmulik Ravidea45fe42010-12-30 06:26:55 +0000188/* DCB number of traffic classes nested attributes. */
189static const struct nla_policy dcbnl_featcfg_nest[DCB_FEATCFG_ATTR_MAX + 1] = {
190 [DCB_FEATCFG_ATTR_ALL] = {.type = NLA_FLAG},
191 [DCB_FEATCFG_ATTR_PG] = {.type = NLA_U8},
192 [DCB_FEATCFG_ATTR_PFC] = {.type = NLA_U8},
193 [DCB_FEATCFG_ATTR_APP] = {.type = NLA_U8},
194};
195
John Fastabend9ab933a2010-12-30 09:26:31 +0000196static LIST_HEAD(dcb_app_list);
197static DEFINE_SPINLOCK(dcb_lock);
198
Thomas Graf33a03aa2012-06-13 02:54:54 +0000199static struct sk_buff *dcbnl_newmsg(int type, u8 cmd, u32 port, u32 seq,
200 u32 flags, struct nlmsghdr **nlhp)
201{
202 struct sk_buff *skb;
203 struct dcbmsg *dcb;
204 struct nlmsghdr *nlh;
205
206 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
207 if (!skb)
208 return NULL;
209
210 nlh = nlmsg_put(skb, port, seq, type, sizeof(*dcb), flags);
211 if (!nlh) {
212 /* header should always fit, allocation must be buggy */
213 BUG();
214 }
215
216 dcb = nlmsg_data(nlh);
217 dcb->dcb_family = AF_UNSPEC;
218 dcb->cmd = cmd;
219 dcb->dcb_pad = 0;
220
221 if (nlhp)
222 *nlhp = nlh;
223
224 return skb;
225}
226
Thomas Graf7be99412012-06-13 02:54:55 +0000227static int dcbnl_getstate(struct net_device *netdev, struct nlmsghdr *nlh,
228 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck2f90b862008-11-20 20:52:10 -0800229{
Alexander Duyck2f90b862008-11-20 20:52:10 -0800230 /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
231 if (!netdev->dcbnl_ops->getstate)
Thomas Graf7be99412012-06-13 02:54:55 +0000232 return -EINVAL;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800233
Thomas Graf7be99412012-06-13 02:54:55 +0000234 return nla_put_u8(skb, DCB_ATTR_STATE,
235 netdev->dcbnl_ops->getstate(netdev));
Alexander Duyck2f90b862008-11-20 20:52:10 -0800236}
237
Thomas Graf7be99412012-06-13 02:54:55 +0000238static int dcbnl_getpfccfg(struct net_device *netdev, struct nlmsghdr *nlh,
239 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck2f90b862008-11-20 20:52:10 -0800240{
Alexander Duyck2f90b862008-11-20 20:52:10 -0800241 struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1], *nest;
242 u8 value;
243 int ret = -EINVAL;
244 int i;
245 int getall = 0;
246
247 if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->getpfccfg)
248 return ret;
249
250 ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
251 tb[DCB_ATTR_PFC_CFG],
252 dcbnl_pfc_up_nest);
253 if (ret)
Thomas Graf7be99412012-06-13 02:54:55 +0000254 goto err;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800255
Thomas Graf7be99412012-06-13 02:54:55 +0000256 nest = nla_nest_start(skb, DCB_ATTR_PFC_CFG);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800257 if (!nest)
258 goto err;
259
260 if (data[DCB_PFC_UP_ATTR_ALL])
261 getall = 1;
262
263 for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
264 if (!getall && !data[i])
265 continue;
266
267 netdev->dcbnl_ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0,
268 &value);
Thomas Graf7be99412012-06-13 02:54:55 +0000269 ret = nla_put_u8(skb, i, value);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800270 if (ret) {
Thomas Graf7be99412012-06-13 02:54:55 +0000271 nla_nest_cancel(skb, nest);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800272 goto err;
273 }
274 }
Thomas Graf7be99412012-06-13 02:54:55 +0000275 nla_nest_end(skb, nest);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800276
277 return 0;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800278err:
Alexander Duyck2f90b862008-11-20 20:52:10 -0800279 return -EINVAL;
280}
281
Thomas Graf7be99412012-06-13 02:54:55 +0000282static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlmsghdr *nlh,
283 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck2f90b862008-11-20 20:52:10 -0800284{
Alexander Duyck2f90b862008-11-20 20:52:10 -0800285 u8 perm_addr[MAX_ADDR_LEN];
Alexander Duyck2f90b862008-11-20 20:52:10 -0800286
287 if (!netdev->dcbnl_ops->getpermhwaddr)
Thomas Graf7be99412012-06-13 02:54:55 +0000288 return -EINVAL;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800289
290 netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
291
Thomas Graf7be99412012-06-13 02:54:55 +0000292 return nla_put(skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr), perm_addr);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800293}
294
Thomas Graf7be99412012-06-13 02:54:55 +0000295static int dcbnl_getcap(struct net_device *netdev, struct nlmsghdr *nlh,
296 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck46132182008-11-20 21:05:08 -0800297{
Alexander Duyck46132182008-11-20 21:05:08 -0800298 struct nlattr *data[DCB_CAP_ATTR_MAX + 1], *nest;
299 u8 value;
300 int ret = -EINVAL;
301 int i;
302 int getall = 0;
303
304 if (!tb[DCB_ATTR_CAP] || !netdev->dcbnl_ops->getcap)
305 return ret;
306
307 ret = nla_parse_nested(data, DCB_CAP_ATTR_MAX, tb[DCB_ATTR_CAP],
308 dcbnl_cap_nest);
309 if (ret)
310 goto err_out;
311
Thomas Graf7be99412012-06-13 02:54:55 +0000312 nest = nla_nest_start(skb, DCB_ATTR_CAP);
Alexander Duyck46132182008-11-20 21:05:08 -0800313 if (!nest)
Thomas Graf7be99412012-06-13 02:54:55 +0000314 goto err_out;
Alexander Duyck46132182008-11-20 21:05:08 -0800315
316 if (data[DCB_CAP_ATTR_ALL])
317 getall = 1;
318
319 for (i = DCB_CAP_ATTR_ALL+1; i <= DCB_CAP_ATTR_MAX; i++) {
320 if (!getall && !data[i])
321 continue;
322
323 if (!netdev->dcbnl_ops->getcap(netdev, i, &value)) {
Thomas Graf7be99412012-06-13 02:54:55 +0000324 ret = nla_put_u8(skb, i, value);
Alexander Duyck46132182008-11-20 21:05:08 -0800325 if (ret) {
Thomas Graf7be99412012-06-13 02:54:55 +0000326 nla_nest_cancel(skb, nest);
327 goto err_out;
Alexander Duyck46132182008-11-20 21:05:08 -0800328 }
329 }
330 }
Thomas Graf7be99412012-06-13 02:54:55 +0000331 nla_nest_end(skb, nest);
Alexander Duyck46132182008-11-20 21:05:08 -0800332
333 return 0;
Alexander Duyck46132182008-11-20 21:05:08 -0800334err_out:
335 return -EINVAL;
336}
337
Thomas Graf7be99412012-06-13 02:54:55 +0000338static int dcbnl_getnumtcs(struct net_device *netdev, struct nlmsghdr *nlh,
339 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800340{
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800341 struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1], *nest;
342 u8 value;
343 int ret = -EINVAL;
344 int i;
345 int getall = 0;
346
347 if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->getnumtcs)
348 return ret;
349
350 ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
351 dcbnl_numtcs_nest);
352 if (ret) {
353 ret = -EINVAL;
354 goto err_out;
355 }
356
Thomas Graf7be99412012-06-13 02:54:55 +0000357 nest = nla_nest_start(skb, DCB_ATTR_NUMTCS);
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800358 if (!nest) {
359 ret = -EINVAL;
Thomas Graf7be99412012-06-13 02:54:55 +0000360 goto err_out;
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800361 }
362
363 if (data[DCB_NUMTCS_ATTR_ALL])
364 getall = 1;
365
366 for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
367 if (!getall && !data[i])
368 continue;
369
370 ret = netdev->dcbnl_ops->getnumtcs(netdev, i, &value);
371 if (!ret) {
Thomas Graf7be99412012-06-13 02:54:55 +0000372 ret = nla_put_u8(skb, i, value);
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800373 if (ret) {
Thomas Graf7be99412012-06-13 02:54:55 +0000374 nla_nest_cancel(skb, nest);
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800375 ret = -EINVAL;
Thomas Graf7be99412012-06-13 02:54:55 +0000376 goto err_out;
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800377 }
378 } else {
Thomas Graf7be99412012-06-13 02:54:55 +0000379 goto err_out;
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800380 }
381 }
Thomas Graf7be99412012-06-13 02:54:55 +0000382 nla_nest_end(skb, nest);
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800383
384 return 0;
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800385err_out:
386 return ret;
387}
388
Thomas Graf7be99412012-06-13 02:54:55 +0000389static int dcbnl_setnumtcs(struct net_device *netdev, struct nlmsghdr *nlh,
390 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800391{
392 struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1];
393 int ret = -EINVAL;
394 u8 value;
395 int i;
396
Don Skidmore8b124a82008-12-15 01:06:23 -0800397 if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->setnumtcs)
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800398 return ret;
399
400 ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
401 dcbnl_numtcs_nest);
402
Thomas Graf7be99412012-06-13 02:54:55 +0000403 if (ret)
404 return -EINVAL;
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800405
406 for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
407 if (data[i] == NULL)
408 continue;
409
410 value = nla_get_u8(data[i]);
411
412 ret = netdev->dcbnl_ops->setnumtcs(netdev, i, value);
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800413 if (ret)
Thomas Graf7be99412012-06-13 02:54:55 +0000414 break;
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800415 }
416
Thomas Graf7be99412012-06-13 02:54:55 +0000417 return nla_put_u8(skb, DCB_ATTR_NUMTCS, !!ret);
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800418}
419
Thomas Graf7be99412012-06-13 02:54:55 +0000420static int dcbnl_getpfcstate(struct net_device *netdev, struct nlmsghdr *nlh,
421 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck0eb3aa92008-11-20 21:09:23 -0800422{
Alexander Duyck0eb3aa92008-11-20 21:09:23 -0800423 if (!netdev->dcbnl_ops->getpfcstate)
Thomas Graf7be99412012-06-13 02:54:55 +0000424 return -EINVAL;
Alexander Duyck0eb3aa92008-11-20 21:09:23 -0800425
Thomas Graf7be99412012-06-13 02:54:55 +0000426 return nla_put_u8(skb, DCB_ATTR_PFC_STATE,
427 netdev->dcbnl_ops->getpfcstate(netdev));
Alexander Duyck0eb3aa92008-11-20 21:09:23 -0800428}
429
Thomas Graf7be99412012-06-13 02:54:55 +0000430static int dcbnl_setpfcstate(struct net_device *netdev, struct nlmsghdr *nlh,
431 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck0eb3aa92008-11-20 21:09:23 -0800432{
Alexander Duyck0eb3aa92008-11-20 21:09:23 -0800433 u8 value;
434
435 if (!tb[DCB_ATTR_PFC_STATE] || !netdev->dcbnl_ops->setpfcstate)
Thomas Graf7be99412012-06-13 02:54:55 +0000436 return -EINVAL;
Alexander Duyck0eb3aa92008-11-20 21:09:23 -0800437
438 value = nla_get_u8(tb[DCB_ATTR_PFC_STATE]);
439
440 netdev->dcbnl_ops->setpfcstate(netdev, value);
441
Thomas Graf7be99412012-06-13 02:54:55 +0000442 return nla_put_u8(skb, DCB_ATTR_PFC_STATE, 0);
Alexander Duyck0eb3aa92008-11-20 21:09:23 -0800443}
444
Thomas Graf7be99412012-06-13 02:54:55 +0000445static int dcbnl_getapp(struct net_device *netdev, struct nlmsghdr *nlh,
446 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Yi Zou57949682009-08-31 12:33:40 +0000447{
Yi Zou57949682009-08-31 12:33:40 +0000448 struct nlattr *app_nest;
449 struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1];
450 u16 id;
451 u8 up, idtype;
452 int ret = -EINVAL;
453
John Fastabend3dce38a2011-01-21 16:35:18 +0000454 if (!tb[DCB_ATTR_APP])
Yi Zou57949682009-08-31 12:33:40 +0000455 goto out;
456
457 ret = nla_parse_nested(app_tb, DCB_APP_ATTR_MAX, tb[DCB_ATTR_APP],
458 dcbnl_app_nest);
459 if (ret)
460 goto out;
461
462 ret = -EINVAL;
463 /* all must be non-null */
464 if ((!app_tb[DCB_APP_ATTR_IDTYPE]) ||
465 (!app_tb[DCB_APP_ATTR_ID]))
466 goto out;
467
468 /* either by eth type or by socket number */
469 idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]);
470 if ((idtype != DCB_APP_IDTYPE_ETHTYPE) &&
471 (idtype != DCB_APP_IDTYPE_PORTNUM))
472 goto out;
473
474 id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]);
John Fastabend3dce38a2011-01-21 16:35:18 +0000475
476 if (netdev->dcbnl_ops->getapp) {
477 up = netdev->dcbnl_ops->getapp(netdev, idtype, id);
478 } else {
479 struct dcb_app app = {
480 .selector = idtype,
481 .protocol = id,
482 };
483 up = dcb_getapp(netdev, &app);
484 }
Yi Zou57949682009-08-31 12:33:40 +0000485
Thomas Graf7be99412012-06-13 02:54:55 +0000486 app_nest = nla_nest_start(skb, DCB_ATTR_APP);
487 if (!app_nest)
Yi Zou57949682009-08-31 12:33:40 +0000488 goto out;
489
Thomas Graf7be99412012-06-13 02:54:55 +0000490 ret = nla_put_u8(skb, DCB_APP_ATTR_IDTYPE, idtype);
Yi Zou57949682009-08-31 12:33:40 +0000491 if (ret)
492 goto out_cancel;
493
Thomas Graf7be99412012-06-13 02:54:55 +0000494 ret = nla_put_u16(skb, DCB_APP_ATTR_ID, id);
Yi Zou57949682009-08-31 12:33:40 +0000495 if (ret)
496 goto out_cancel;
497
Thomas Graf7be99412012-06-13 02:54:55 +0000498 ret = nla_put_u8(skb, DCB_APP_ATTR_PRIORITY, up);
Yi Zou57949682009-08-31 12:33:40 +0000499 if (ret)
500 goto out_cancel;
501
Thomas Graf7be99412012-06-13 02:54:55 +0000502 nla_nest_end(skb, app_nest);
Yi Zou57949682009-08-31 12:33:40 +0000503
504 goto out;
505
506out_cancel:
Thomas Graf7be99412012-06-13 02:54:55 +0000507 nla_nest_cancel(skb, app_nest);
Yi Zou57949682009-08-31 12:33:40 +0000508out:
509 return ret;
510}
511
Thomas Graf7be99412012-06-13 02:54:55 +0000512static int dcbnl_setapp(struct net_device *netdev, struct nlmsghdr *nlh,
513 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Yi Zou57949682009-08-31 12:33:40 +0000514{
John Fastabend9ab933a2010-12-30 09:26:31 +0000515 int err, ret = -EINVAL;
Yi Zou57949682009-08-31 12:33:40 +0000516 u16 id;
517 u8 up, idtype;
518 struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1];
519
John Fastabend9ab933a2010-12-30 09:26:31 +0000520 if (!tb[DCB_ATTR_APP])
Yi Zou57949682009-08-31 12:33:40 +0000521 goto out;
522
523 ret = nla_parse_nested(app_tb, DCB_APP_ATTR_MAX, tb[DCB_ATTR_APP],
524 dcbnl_app_nest);
525 if (ret)
526 goto out;
527
528 ret = -EINVAL;
529 /* all must be non-null */
530 if ((!app_tb[DCB_APP_ATTR_IDTYPE]) ||
531 (!app_tb[DCB_APP_ATTR_ID]) ||
532 (!app_tb[DCB_APP_ATTR_PRIORITY]))
533 goto out;
534
535 /* either by eth type or by socket number */
536 idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]);
537 if ((idtype != DCB_APP_IDTYPE_ETHTYPE) &&
538 (idtype != DCB_APP_IDTYPE_PORTNUM))
539 goto out;
540
541 id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]);
542 up = nla_get_u8(app_tb[DCB_APP_ATTR_PRIORITY]);
543
John Fastabend9ab933a2010-12-30 09:26:31 +0000544 if (netdev->dcbnl_ops->setapp) {
545 err = netdev->dcbnl_ops->setapp(netdev, idtype, id, up);
546 } else {
547 struct dcb_app app;
548 app.selector = idtype;
549 app.protocol = id;
550 app.priority = up;
551 err = dcb_setapp(netdev, &app);
552 }
553
Thomas Graf7be99412012-06-13 02:54:55 +0000554 ret = nla_put_u8(skb, DCB_ATTR_APP, ret);
John Fastabend08157982012-04-20 09:49:23 +0000555 dcbnl_cee_notify(netdev, RTM_SETDCB, DCB_CMD_SAPP, seq, 0);
Yi Zou57949682009-08-31 12:33:40 +0000556out:
557 return ret;
558}
559
Thomas Graf7be99412012-06-13 02:54:55 +0000560static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlmsghdr *nlh,
561 struct nlattr **tb, struct sk_buff *skb, int dir)
Alexander Duyck2f90b862008-11-20 20:52:10 -0800562{
Alexander Duyck2f90b862008-11-20 20:52:10 -0800563 struct nlattr *pg_nest, *param_nest, *data;
564 struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
565 struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
566 u8 prio, pgid, tc_pct, up_map;
567 int ret = -EINVAL;
568 int getall = 0;
569 int i;
570
571 if (!tb[DCB_ATTR_PG_CFG] ||
572 !netdev->dcbnl_ops->getpgtccfgtx ||
573 !netdev->dcbnl_ops->getpgtccfgrx ||
574 !netdev->dcbnl_ops->getpgbwgcfgtx ||
575 !netdev->dcbnl_ops->getpgbwgcfgrx)
576 return ret;
577
578 ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
579 tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
580
581 if (ret)
582 goto err_out;
583
Thomas Graf7be99412012-06-13 02:54:55 +0000584 pg_nest = nla_nest_start(skb, DCB_ATTR_PG_CFG);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800585 if (!pg_nest)
Thomas Graf7be99412012-06-13 02:54:55 +0000586 goto err_out;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800587
588 if (pg_tb[DCB_PG_ATTR_TC_ALL])
589 getall = 1;
590
591 for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
592 if (!getall && !pg_tb[i])
593 continue;
594
595 if (pg_tb[DCB_PG_ATTR_TC_ALL])
596 data = pg_tb[DCB_PG_ATTR_TC_ALL];
597 else
598 data = pg_tb[i];
599 ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
600 data, dcbnl_tc_param_nest);
601 if (ret)
602 goto err_pg;
603
Thomas Graf7be99412012-06-13 02:54:55 +0000604 param_nest = nla_nest_start(skb, i);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800605 if (!param_nest)
606 goto err_pg;
607
608 pgid = DCB_ATTR_VALUE_UNDEFINED;
609 prio = DCB_ATTR_VALUE_UNDEFINED;
610 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
611 up_map = DCB_ATTR_VALUE_UNDEFINED;
612
613 if (dir) {
614 /* Rx */
615 netdev->dcbnl_ops->getpgtccfgrx(netdev,
616 i - DCB_PG_ATTR_TC_0, &prio,
617 &pgid, &tc_pct, &up_map);
618 } else {
619 /* Tx */
620 netdev->dcbnl_ops->getpgtccfgtx(netdev,
621 i - DCB_PG_ATTR_TC_0, &prio,
622 &pgid, &tc_pct, &up_map);
623 }
624
625 if (param_tb[DCB_TC_ATTR_PARAM_PGID] ||
626 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
Thomas Graf7be99412012-06-13 02:54:55 +0000627 ret = nla_put_u8(skb,
Alexander Duyck2f90b862008-11-20 20:52:10 -0800628 DCB_TC_ATTR_PARAM_PGID, pgid);
629 if (ret)
630 goto err_param;
631 }
632 if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING] ||
633 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
Thomas Graf7be99412012-06-13 02:54:55 +0000634 ret = nla_put_u8(skb,
Alexander Duyck2f90b862008-11-20 20:52:10 -0800635 DCB_TC_ATTR_PARAM_UP_MAPPING, up_map);
636 if (ret)
637 goto err_param;
638 }
639 if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO] ||
640 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
Thomas Graf7be99412012-06-13 02:54:55 +0000641 ret = nla_put_u8(skb,
Alexander Duyck2f90b862008-11-20 20:52:10 -0800642 DCB_TC_ATTR_PARAM_STRICT_PRIO, prio);
643 if (ret)
644 goto err_param;
645 }
646 if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT] ||
647 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
Thomas Graf7be99412012-06-13 02:54:55 +0000648 ret = nla_put_u8(skb, DCB_TC_ATTR_PARAM_BW_PCT,
Alexander Duyck2f90b862008-11-20 20:52:10 -0800649 tc_pct);
650 if (ret)
651 goto err_param;
652 }
Thomas Graf7be99412012-06-13 02:54:55 +0000653 nla_nest_end(skb, param_nest);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800654 }
655
656 if (pg_tb[DCB_PG_ATTR_BW_ID_ALL])
657 getall = 1;
658 else
659 getall = 0;
660
661 for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
662 if (!getall && !pg_tb[i])
663 continue;
664
665 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
666
667 if (dir) {
668 /* Rx */
669 netdev->dcbnl_ops->getpgbwgcfgrx(netdev,
670 i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
671 } else {
672 /* Tx */
673 netdev->dcbnl_ops->getpgbwgcfgtx(netdev,
674 i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
675 }
Thomas Graf7be99412012-06-13 02:54:55 +0000676 ret = nla_put_u8(skb, i, tc_pct);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800677
678 if (ret)
679 goto err_pg;
680 }
681
Thomas Graf7be99412012-06-13 02:54:55 +0000682 nla_nest_end(skb, pg_nest);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800683
684 return 0;
685
686err_param:
Thomas Graf7be99412012-06-13 02:54:55 +0000687 nla_nest_cancel(skb, param_nest);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800688err_pg:
Thomas Graf7be99412012-06-13 02:54:55 +0000689 nla_nest_cancel(skb, pg_nest);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800690err_out:
691 ret = -EINVAL;
692 return ret;
693}
694
Thomas Graf7be99412012-06-13 02:54:55 +0000695static int dcbnl_pgtx_getcfg(struct net_device *netdev, struct nlmsghdr *nlh,
696 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck2f90b862008-11-20 20:52:10 -0800697{
Thomas Graf7be99412012-06-13 02:54:55 +0000698 return __dcbnl_pg_getcfg(netdev, nlh, tb, skb, 0);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800699}
700
Thomas Graf7be99412012-06-13 02:54:55 +0000701static int dcbnl_pgrx_getcfg(struct net_device *netdev, struct nlmsghdr *nlh,
702 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck2f90b862008-11-20 20:52:10 -0800703{
Thomas Graf7be99412012-06-13 02:54:55 +0000704 return __dcbnl_pg_getcfg(netdev, nlh, tb, skb, 1);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800705}
706
Thomas Graf7be99412012-06-13 02:54:55 +0000707static int dcbnl_setstate(struct net_device *netdev, struct nlmsghdr *nlh,
708 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck2f90b862008-11-20 20:52:10 -0800709{
Alexander Duyck2f90b862008-11-20 20:52:10 -0800710 u8 value;
711
712 if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->setstate)
Thomas Graf7be99412012-06-13 02:54:55 +0000713 return -EINVAL;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800714
715 value = nla_get_u8(tb[DCB_ATTR_STATE]);
716
Thomas Graf7be99412012-06-13 02:54:55 +0000717 return nla_put_u8(skb, DCB_ATTR_STATE,
718 netdev->dcbnl_ops->setstate(netdev, value));
Alexander Duyck2f90b862008-11-20 20:52:10 -0800719}
720
Thomas Graf7be99412012-06-13 02:54:55 +0000721static int dcbnl_setpfccfg(struct net_device *netdev, struct nlmsghdr *nlh,
722 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck2f90b862008-11-20 20:52:10 -0800723{
724 struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1];
725 int i;
726 int ret = -EINVAL;
727 u8 value;
728
729 if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->setpfccfg)
730 return ret;
731
732 ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
733 tb[DCB_ATTR_PFC_CFG],
734 dcbnl_pfc_up_nest);
735 if (ret)
736 goto err;
737
738 for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
739 if (data[i] == NULL)
740 continue;
741 value = nla_get_u8(data[i]);
742 netdev->dcbnl_ops->setpfccfg(netdev,
743 data[i]->nla_type - DCB_PFC_UP_ATTR_0, value);
744 }
745
Thomas Graf7be99412012-06-13 02:54:55 +0000746 return nla_put_u8(skb, DCB_ATTR_PFC_CFG, 0);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800747err:
748 return ret;
749}
750
Thomas Graf7be99412012-06-13 02:54:55 +0000751static int dcbnl_setall(struct net_device *netdev, struct nlmsghdr *nlh,
752 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck2f90b862008-11-20 20:52:10 -0800753{
754 int ret = -EINVAL;
755
756 if (!tb[DCB_ATTR_SET_ALL] || !netdev->dcbnl_ops->setall)
757 return ret;
758
Thomas Graf7be99412012-06-13 02:54:55 +0000759 ret = nla_put_u8(skb, DCB_ATTR_SET_ALL,
760 netdev->dcbnl_ops->setall(netdev));
John Fastabend08157982012-04-20 09:49:23 +0000761 dcbnl_cee_notify(netdev, RTM_SETDCB, DCB_CMD_SET_ALL, seq, 0);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800762
763 return ret;
764}
765
Thomas Graf7be99412012-06-13 02:54:55 +0000766static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
767 u32 seq, struct nlattr **tb, struct sk_buff *skb,
768 int dir)
Alexander Duyck2f90b862008-11-20 20:52:10 -0800769{
770 struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
771 struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
772 int ret = -EINVAL;
773 int i;
774 u8 pgid;
775 u8 up_map;
776 u8 prio;
777 u8 tc_pct;
778
779 if (!tb[DCB_ATTR_PG_CFG] ||
780 !netdev->dcbnl_ops->setpgtccfgtx ||
781 !netdev->dcbnl_ops->setpgtccfgrx ||
782 !netdev->dcbnl_ops->setpgbwgcfgtx ||
783 !netdev->dcbnl_ops->setpgbwgcfgrx)
784 return ret;
785
786 ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
787 tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
788 if (ret)
789 goto err;
790
791 for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
792 if (!pg_tb[i])
793 continue;
794
795 ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
796 pg_tb[i], dcbnl_tc_param_nest);
797 if (ret)
798 goto err;
799
800 pgid = DCB_ATTR_VALUE_UNDEFINED;
801 prio = DCB_ATTR_VALUE_UNDEFINED;
802 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
803 up_map = DCB_ATTR_VALUE_UNDEFINED;
804
805 if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO])
806 prio =
807 nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]);
808
809 if (param_tb[DCB_TC_ATTR_PARAM_PGID])
810 pgid = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_PGID]);
811
812 if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT])
813 tc_pct = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_BW_PCT]);
814
815 if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING])
816 up_map =
817 nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]);
818
819 /* dir: Tx = 0, Rx = 1 */
820 if (dir) {
821 /* Rx */
822 netdev->dcbnl_ops->setpgtccfgrx(netdev,
823 i - DCB_PG_ATTR_TC_0,
824 prio, pgid, tc_pct, up_map);
825 } else {
826 /* Tx */
827 netdev->dcbnl_ops->setpgtccfgtx(netdev,
828 i - DCB_PG_ATTR_TC_0,
829 prio, pgid, tc_pct, up_map);
830 }
831 }
832
833 for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
834 if (!pg_tb[i])
835 continue;
836
837 tc_pct = nla_get_u8(pg_tb[i]);
838
839 /* dir: Tx = 0, Rx = 1 */
840 if (dir) {
841 /* Rx */
842 netdev->dcbnl_ops->setpgbwgcfgrx(netdev,
843 i - DCB_PG_ATTR_BW_ID_0, tc_pct);
844 } else {
845 /* Tx */
846 netdev->dcbnl_ops->setpgbwgcfgtx(netdev,
847 i - DCB_PG_ATTR_BW_ID_0, tc_pct);
848 }
849 }
850
Thomas Graf7be99412012-06-13 02:54:55 +0000851 ret = nla_put_u8(skb, (dir ? DCB_CMD_PGRX_SCFG : DCB_CMD_PGTX_SCFG), 0);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800852
853err:
854 return ret;
855}
856
Thomas Graf7be99412012-06-13 02:54:55 +0000857static int dcbnl_pgtx_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
858 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck2f90b862008-11-20 20:52:10 -0800859{
Thomas Graf7be99412012-06-13 02:54:55 +0000860 return __dcbnl_pg_setcfg(netdev, nlh, seq, tb, skb, 0);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800861}
862
Thomas Graf7be99412012-06-13 02:54:55 +0000863static int dcbnl_pgrx_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
864 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck2f90b862008-11-20 20:52:10 -0800865{
Thomas Graf7be99412012-06-13 02:54:55 +0000866 return __dcbnl_pg_setcfg(netdev, nlh, seq, tb, skb, 1);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800867}
868
Thomas Graf7be99412012-06-13 02:54:55 +0000869static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlmsghdr *nlh,
870 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800871{
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800872 struct nlattr *bcn_nest;
873 struct nlattr *bcn_tb[DCB_BCN_ATTR_MAX + 1];
874 u8 value_byte;
875 u32 value_integer;
876 int ret = -EINVAL;
877 bool getall = false;
878 int i;
879
880 if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->getbcnrp ||
881 !netdev->dcbnl_ops->getbcncfg)
882 return ret;
883
884 ret = nla_parse_nested(bcn_tb, DCB_BCN_ATTR_MAX,
885 tb[DCB_ATTR_BCN], dcbnl_bcn_nest);
886
887 if (ret)
888 goto err_out;
889
Thomas Graf7be99412012-06-13 02:54:55 +0000890 bcn_nest = nla_nest_start(skb, DCB_ATTR_BCN);
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800891 if (!bcn_nest)
Thomas Graf7be99412012-06-13 02:54:55 +0000892 goto err_out;
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800893
894 if (bcn_tb[DCB_BCN_ATTR_ALL])
895 getall = true;
896
897 for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
898 if (!getall && !bcn_tb[i])
899 continue;
900
901 netdev->dcbnl_ops->getbcnrp(netdev, i - DCB_BCN_ATTR_RP_0,
902 &value_byte);
Thomas Graf7be99412012-06-13 02:54:55 +0000903 ret = nla_put_u8(skb, i, value_byte);
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800904 if (ret)
905 goto err_bcn;
906 }
907
Don Skidmoref4314e82008-12-21 20:10:29 -0800908 for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800909 if (!getall && !bcn_tb[i])
910 continue;
911
912 netdev->dcbnl_ops->getbcncfg(netdev, i,
913 &value_integer);
Thomas Graf7be99412012-06-13 02:54:55 +0000914 ret = nla_put_u32(skb, i, value_integer);
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800915 if (ret)
916 goto err_bcn;
917 }
918
Thomas Graf7be99412012-06-13 02:54:55 +0000919 nla_nest_end(skb, bcn_nest);
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800920
921 return 0;
922
923err_bcn:
Thomas Graf7be99412012-06-13 02:54:55 +0000924 nla_nest_cancel(skb, bcn_nest);
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800925err_out:
926 ret = -EINVAL;
927 return ret;
928}
929
Thomas Graf7be99412012-06-13 02:54:55 +0000930static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
931 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800932{
933 struct nlattr *data[DCB_BCN_ATTR_MAX + 1];
934 int i;
935 int ret = -EINVAL;
936 u8 value_byte;
937 u32 value_int;
938
Joe Perchesf64f9e72009-11-29 16:55:45 -0800939 if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->setbcncfg ||
940 !netdev->dcbnl_ops->setbcnrp)
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800941 return ret;
942
943 ret = nla_parse_nested(data, DCB_BCN_ATTR_MAX,
944 tb[DCB_ATTR_BCN],
945 dcbnl_pfc_up_nest);
946 if (ret)
947 goto err;
948
949 for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
950 if (data[i] == NULL)
951 continue;
952 value_byte = nla_get_u8(data[i]);
953 netdev->dcbnl_ops->setbcnrp(netdev,
954 data[i]->nla_type - DCB_BCN_ATTR_RP_0, value_byte);
955 }
956
Don Skidmoref4314e82008-12-21 20:10:29 -0800957 for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800958 if (data[i] == NULL)
959 continue;
960 value_int = nla_get_u32(data[i]);
961 netdev->dcbnl_ops->setbcncfg(netdev,
962 i, value_int);
963 }
964
Thomas Graf7be99412012-06-13 02:54:55 +0000965 ret = nla_put_u8(skb, DCB_ATTR_BCN, 0);
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800966err:
967 return ret;
968}
969
Shmulik Raviddc6ed1d2011-02-27 05:04:38 +0000970static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,
971 int app_nested_type, int app_info_type,
972 int app_entry_type)
Shmulik Ravideed84712011-02-27 05:04:31 +0000973{
974 struct dcb_peer_app_info info;
975 struct dcb_app *table = NULL;
976 const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
977 u16 app_count;
978 int err;
979
980
981 /**
982 * retrieve the peer app configuration form the driver. If the driver
983 * handlers fail exit without doing anything
984 */
985 err = ops->peer_getappinfo(netdev, &info, &app_count);
986 if (!err && app_count) {
987 table = kmalloc(sizeof(struct dcb_app) * app_count, GFP_KERNEL);
988 if (!table)
989 return -ENOMEM;
990
991 err = ops->peer_getapptable(netdev, table);
992 }
993
994 if (!err) {
995 u16 i;
996 struct nlattr *app;
997
998 /**
999 * build the message, from here on the only possible failure
1000 * is due to the skb size
1001 */
1002 err = -EMSGSIZE;
1003
Shmulik Raviddc6ed1d2011-02-27 05:04:38 +00001004 app = nla_nest_start(skb, app_nested_type);
Shmulik Ravideed84712011-02-27 05:04:31 +00001005 if (!app)
1006 goto nla_put_failure;
1007
David S. Miller1eb4c972012-04-01 20:03:01 -04001008 if (app_info_type &&
1009 nla_put(skb, app_info_type, sizeof(info), &info))
1010 goto nla_put_failure;
Shmulik Raviddc6ed1d2011-02-27 05:04:38 +00001011
David S. Miller1eb4c972012-04-01 20:03:01 -04001012 for (i = 0; i < app_count; i++) {
1013 if (nla_put(skb, app_entry_type, sizeof(struct dcb_app),
1014 &table[i]))
1015 goto nla_put_failure;
1016 }
Shmulik Ravideed84712011-02-27 05:04:31 +00001017 nla_nest_end(skb, app);
1018 }
1019 err = 0;
1020
1021nla_put_failure:
1022 kfree(table);
1023 return err;
1024}
John Fastabend3e290272010-12-30 09:25:46 +00001025
1026/* Handle IEEE 802.1Qaz GET commands. */
John Fastabend314b4772011-06-21 07:34:37 +00001027static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
John Fastabend3e290272010-12-30 09:25:46 +00001028{
John Fastabend9ab933a2010-12-30 09:26:31 +00001029 struct nlattr *ieee, *app;
1030 struct dcb_app_type *itr;
John Fastabend3e290272010-12-30 09:25:46 +00001031 const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
John Fastabendc7797ba2011-06-21 07:34:31 +00001032 int dcbx;
John Fastabend314b4772011-06-21 07:34:37 +00001033 int err = -EMSGSIZE;
John Fastabend3e290272010-12-30 09:25:46 +00001034
David S. Miller1eb4c972012-04-01 20:03:01 -04001035 if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name))
1036 goto nla_put_failure;
John Fastabend3e290272010-12-30 09:25:46 +00001037 ieee = nla_nest_start(skb, DCB_ATTR_IEEE);
1038 if (!ieee)
1039 goto nla_put_failure;
1040
1041 if (ops->ieee_getets) {
1042 struct ieee_ets ets;
1043 err = ops->ieee_getets(netdev, &ets);
David S. Miller1eb4c972012-04-01 20:03:01 -04001044 if (!err &&
1045 nla_put(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets))
1046 goto nla_put_failure;
John Fastabend3e290272010-12-30 09:25:46 +00001047 }
1048
Amir Vadai08f10af2012-04-04 21:33:30 +00001049 if (ops->ieee_getmaxrate) {
1050 struct ieee_maxrate maxrate;
1051 err = ops->ieee_getmaxrate(netdev, &maxrate);
1052 if (!err) {
1053 err = nla_put(skb, DCB_ATTR_IEEE_MAXRATE,
1054 sizeof(maxrate), &maxrate);
1055 if (err)
1056 goto nla_put_failure;
1057 }
1058 }
1059
John Fastabend3e290272010-12-30 09:25:46 +00001060 if (ops->ieee_getpfc) {
1061 struct ieee_pfc pfc;
1062 err = ops->ieee_getpfc(netdev, &pfc);
David S. Miller1eb4c972012-04-01 20:03:01 -04001063 if (!err &&
1064 nla_put(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc))
1065 goto nla_put_failure;
John Fastabend3e290272010-12-30 09:25:46 +00001066 }
1067
John Fastabend9ab933a2010-12-30 09:26:31 +00001068 app = nla_nest_start(skb, DCB_ATTR_IEEE_APP_TABLE);
1069 if (!app)
1070 goto nla_put_failure;
1071
1072 spin_lock(&dcb_lock);
1073 list_for_each_entry(itr, &dcb_app_list, list) {
Mark Rustade290ed82011-10-06 08:52:33 +00001074 if (itr->ifindex == netdev->ifindex) {
Dan Carpenter70bfa2d2011-01-04 21:03:12 +00001075 err = nla_put(skb, DCB_ATTR_IEEE_APP, sizeof(itr->app),
1076 &itr->app);
1077 if (err) {
1078 spin_unlock(&dcb_lock);
1079 goto nla_put_failure;
1080 }
1081 }
John Fastabend9ab933a2010-12-30 09:26:31 +00001082 }
John Fastabendc7797ba2011-06-21 07:34:31 +00001083
1084 if (netdev->dcbnl_ops->getdcbx)
1085 dcbx = netdev->dcbnl_ops->getdcbx(netdev);
1086 else
1087 dcbx = -EOPNOTSUPP;
1088
John Fastabend9ab933a2010-12-30 09:26:31 +00001089 spin_unlock(&dcb_lock);
1090 nla_nest_end(skb, app);
1091
Shmulik Ravideed84712011-02-27 05:04:31 +00001092 /* get peer info if available */
1093 if (ops->ieee_peer_getets) {
1094 struct ieee_ets ets;
1095 err = ops->ieee_peer_getets(netdev, &ets);
David S. Miller1eb4c972012-04-01 20:03:01 -04001096 if (!err &&
1097 nla_put(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets))
1098 goto nla_put_failure;
Shmulik Ravideed84712011-02-27 05:04:31 +00001099 }
1100
1101 if (ops->ieee_peer_getpfc) {
1102 struct ieee_pfc pfc;
1103 err = ops->ieee_peer_getpfc(netdev, &pfc);
David S. Miller1eb4c972012-04-01 20:03:01 -04001104 if (!err &&
1105 nla_put(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc))
1106 goto nla_put_failure;
Shmulik Ravideed84712011-02-27 05:04:31 +00001107 }
1108
1109 if (ops->peer_getappinfo && ops->peer_getapptable) {
Shmulik Raviddc6ed1d2011-02-27 05:04:38 +00001110 err = dcbnl_build_peer_app(netdev, skb,
1111 DCB_ATTR_IEEE_PEER_APP,
1112 DCB_ATTR_IEEE_APP_UNSPEC,
1113 DCB_ATTR_IEEE_APP);
Shmulik Ravideed84712011-02-27 05:04:31 +00001114 if (err)
1115 goto nla_put_failure;
1116 }
1117
John Fastabend3e290272010-12-30 09:25:46 +00001118 nla_nest_end(skb, ieee);
John Fastabendc7797ba2011-06-21 07:34:31 +00001119 if (dcbx >= 0) {
1120 err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx);
1121 if (err)
1122 goto nla_put_failure;
1123 }
John Fastabend3e290272010-12-30 09:25:46 +00001124
John Fastabend314b4772011-06-21 07:34:37 +00001125 return 0;
1126
John Fastabend3e290272010-12-30 09:25:46 +00001127nla_put_failure:
John Fastabend314b4772011-06-21 07:34:37 +00001128 return err;
John Fastabend3e290272010-12-30 09:25:46 +00001129}
1130
Shmulik Ravid5b7f7622011-07-05 06:16:25 +00001131static int dcbnl_cee_pg_fill(struct sk_buff *skb, struct net_device *dev,
1132 int dir)
1133{
1134 u8 pgid, up_map, prio, tc_pct;
1135 const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops;
1136 int i = dir ? DCB_ATTR_CEE_TX_PG : DCB_ATTR_CEE_RX_PG;
1137 struct nlattr *pg = nla_nest_start(skb, i);
1138
1139 if (!pg)
1140 goto nla_put_failure;
1141
1142 for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
1143 struct nlattr *tc_nest = nla_nest_start(skb, i);
1144
1145 if (!tc_nest)
1146 goto nla_put_failure;
1147
1148 pgid = DCB_ATTR_VALUE_UNDEFINED;
1149 prio = DCB_ATTR_VALUE_UNDEFINED;
1150 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
1151 up_map = DCB_ATTR_VALUE_UNDEFINED;
1152
1153 if (!dir)
1154 ops->getpgtccfgrx(dev, i - DCB_PG_ATTR_TC_0,
1155 &prio, &pgid, &tc_pct, &up_map);
1156 else
1157 ops->getpgtccfgtx(dev, i - DCB_PG_ATTR_TC_0,
1158 &prio, &pgid, &tc_pct, &up_map);
1159
David S. Miller1eb4c972012-04-01 20:03:01 -04001160 if (nla_put_u8(skb, DCB_TC_ATTR_PARAM_PGID, pgid) ||
1161 nla_put_u8(skb, DCB_TC_ATTR_PARAM_UP_MAPPING, up_map) ||
1162 nla_put_u8(skb, DCB_TC_ATTR_PARAM_STRICT_PRIO, prio) ||
1163 nla_put_u8(skb, DCB_TC_ATTR_PARAM_BW_PCT, tc_pct))
1164 goto nla_put_failure;
Shmulik Ravid5b7f7622011-07-05 06:16:25 +00001165 nla_nest_end(skb, tc_nest);
1166 }
1167
1168 for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
1169 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
1170
1171 if (!dir)
1172 ops->getpgbwgcfgrx(dev, i - DCB_PG_ATTR_BW_ID_0,
1173 &tc_pct);
1174 else
1175 ops->getpgbwgcfgtx(dev, i - DCB_PG_ATTR_BW_ID_0,
1176 &tc_pct);
David S. Miller1eb4c972012-04-01 20:03:01 -04001177 if (nla_put_u8(skb, i, tc_pct))
1178 goto nla_put_failure;
Shmulik Ravid5b7f7622011-07-05 06:16:25 +00001179 }
1180 nla_nest_end(skb, pg);
1181 return 0;
1182
1183nla_put_failure:
1184 return -EMSGSIZE;
1185}
1186
1187static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
1188{
1189 struct nlattr *cee, *app;
1190 struct dcb_app_type *itr;
1191 const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
1192 int dcbx, i, err = -EMSGSIZE;
1193 u8 value;
1194
David S. Miller1eb4c972012-04-01 20:03:01 -04001195 if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name))
1196 goto nla_put_failure;
Shmulik Ravid5b7f7622011-07-05 06:16:25 +00001197 cee = nla_nest_start(skb, DCB_ATTR_CEE);
1198 if (!cee)
1199 goto nla_put_failure;
1200
1201 /* local pg */
1202 if (ops->getpgtccfgtx && ops->getpgbwgcfgtx) {
1203 err = dcbnl_cee_pg_fill(skb, netdev, 1);
1204 if (err)
1205 goto nla_put_failure;
1206 }
1207
1208 if (ops->getpgtccfgrx && ops->getpgbwgcfgrx) {
1209 err = dcbnl_cee_pg_fill(skb, netdev, 0);
1210 if (err)
1211 goto nla_put_failure;
1212 }
1213
1214 /* local pfc */
1215 if (ops->getpfccfg) {
1216 struct nlattr *pfc_nest = nla_nest_start(skb, DCB_ATTR_CEE_PFC);
1217
1218 if (!pfc_nest)
1219 goto nla_put_failure;
1220
1221 for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
1222 ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0, &value);
David S. Miller1eb4c972012-04-01 20:03:01 -04001223 if (nla_put_u8(skb, i, value))
1224 goto nla_put_failure;
Shmulik Ravid5b7f7622011-07-05 06:16:25 +00001225 }
1226 nla_nest_end(skb, pfc_nest);
1227 }
1228
1229 /* local app */
1230 spin_lock(&dcb_lock);
1231 app = nla_nest_start(skb, DCB_ATTR_CEE_APP_TABLE);
1232 if (!app)
Dan Carpenter40f5d722011-07-07 21:27:24 +00001233 goto dcb_unlock;
Shmulik Ravid5b7f7622011-07-05 06:16:25 +00001234
1235 list_for_each_entry(itr, &dcb_app_list, list) {
Mark Rustade290ed82011-10-06 08:52:33 +00001236 if (itr->ifindex == netdev->ifindex) {
Shmulik Ravid5b7f7622011-07-05 06:16:25 +00001237 struct nlattr *app_nest = nla_nest_start(skb,
1238 DCB_ATTR_APP);
1239 if (!app_nest)
1240 goto dcb_unlock;
1241
1242 err = nla_put_u8(skb, DCB_APP_ATTR_IDTYPE,
1243 itr->app.selector);
1244 if (err)
1245 goto dcb_unlock;
1246
1247 err = nla_put_u16(skb, DCB_APP_ATTR_ID,
1248 itr->app.protocol);
1249 if (err)
1250 goto dcb_unlock;
1251
1252 err = nla_put_u8(skb, DCB_APP_ATTR_PRIORITY,
1253 itr->app.priority);
1254 if (err)
1255 goto dcb_unlock;
1256
1257 nla_nest_end(skb, app_nest);
1258 }
1259 }
1260 nla_nest_end(skb, app);
1261
1262 if (netdev->dcbnl_ops->getdcbx)
1263 dcbx = netdev->dcbnl_ops->getdcbx(netdev);
1264 else
1265 dcbx = -EOPNOTSUPP;
1266
1267 spin_unlock(&dcb_lock);
1268
1269 /* features flags */
1270 if (ops->getfeatcfg) {
1271 struct nlattr *feat = nla_nest_start(skb, DCB_ATTR_CEE_FEAT);
1272 if (!feat)
1273 goto nla_put_failure;
1274
1275 for (i = DCB_FEATCFG_ATTR_ALL + 1; i <= DCB_FEATCFG_ATTR_MAX;
1276 i++)
David S. Miller1eb4c972012-04-01 20:03:01 -04001277 if (!ops->getfeatcfg(netdev, i, &value) &&
1278 nla_put_u8(skb, i, value))
1279 goto nla_put_failure;
Shmulik Ravid5b7f7622011-07-05 06:16:25 +00001280
1281 nla_nest_end(skb, feat);
1282 }
1283
1284 /* peer info if available */
1285 if (ops->cee_peer_getpg) {
1286 struct cee_pg pg;
1287 err = ops->cee_peer_getpg(netdev, &pg);
David S. Miller1eb4c972012-04-01 20:03:01 -04001288 if (!err &&
1289 nla_put(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg))
1290 goto nla_put_failure;
Shmulik Ravid5b7f7622011-07-05 06:16:25 +00001291 }
1292
1293 if (ops->cee_peer_getpfc) {
1294 struct cee_pfc pfc;
1295 err = ops->cee_peer_getpfc(netdev, &pfc);
David S. Miller1eb4c972012-04-01 20:03:01 -04001296 if (!err &&
1297 nla_put(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc))
1298 goto nla_put_failure;
Shmulik Ravid5b7f7622011-07-05 06:16:25 +00001299 }
1300
1301 if (ops->peer_getappinfo && ops->peer_getapptable) {
1302 err = dcbnl_build_peer_app(netdev, skb,
1303 DCB_ATTR_CEE_PEER_APP_TABLE,
1304 DCB_ATTR_CEE_PEER_APP_INFO,
1305 DCB_ATTR_CEE_PEER_APP);
1306 if (err)
1307 goto nla_put_failure;
1308 }
1309 nla_nest_end(skb, cee);
1310
1311 /* DCBX state */
1312 if (dcbx >= 0) {
1313 err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx);
1314 if (err)
1315 goto nla_put_failure;
1316 }
1317 return 0;
1318
1319dcb_unlock:
1320 spin_unlock(&dcb_lock);
1321nla_put_failure:
1322 return err;
1323}
1324
1325static int dcbnl_notify(struct net_device *dev, int event, int cmd,
1326 u32 seq, u32 pid, int dcbx_ver)
John Fastabend314b4772011-06-21 07:34:37 +00001327{
1328 struct net *net = dev_net(dev);
1329 struct sk_buff *skb;
1330 struct nlmsghdr *nlh;
John Fastabend314b4772011-06-21 07:34:37 +00001331 const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops;
1332 int err;
1333
1334 if (!ops)
1335 return -EOPNOTSUPP;
1336
Thomas Grafab6d4702012-06-13 02:54:57 +00001337 skb = dcbnl_newmsg(event, cmd, pid, seq, 0, &nlh);
John Fastabend314b4772011-06-21 07:34:37 +00001338 if (!skb)
1339 return -ENOBUFS;
1340
Shmulik Ravid5b7f7622011-07-05 06:16:25 +00001341 if (dcbx_ver == DCB_CAP_DCBX_VER_IEEE)
1342 err = dcbnl_ieee_fill(skb, dev);
1343 else
1344 err = dcbnl_cee_fill(skb, dev);
1345
John Fastabend314b4772011-06-21 07:34:37 +00001346 if (err < 0) {
1347 /* Report error to broadcast listeners */
Thomas Grafab6d4702012-06-13 02:54:57 +00001348 nlmsg_free(skb);
John Fastabend314b4772011-06-21 07:34:37 +00001349 rtnl_set_sk_err(net, RTNLGRP_DCB, err);
1350 } else {
1351 /* End nlmsg and notify broadcast listeners */
1352 nlmsg_end(skb, nlh);
1353 rtnl_notify(skb, net, 0, RTNLGRP_DCB, NULL, GFP_KERNEL);
1354 }
1355
1356 return err;
1357}
Shmulik Ravid5b7f7622011-07-05 06:16:25 +00001358
1359int dcbnl_ieee_notify(struct net_device *dev, int event, int cmd,
1360 u32 seq, u32 pid)
1361{
1362 return dcbnl_notify(dev, event, cmd, seq, pid, DCB_CAP_DCBX_VER_IEEE);
1363}
1364EXPORT_SYMBOL(dcbnl_ieee_notify);
1365
1366int dcbnl_cee_notify(struct net_device *dev, int event, int cmd,
1367 u32 seq, u32 pid)
1368{
1369 return dcbnl_notify(dev, event, cmd, seq, pid, DCB_CAP_DCBX_VER_CEE);
1370}
1371EXPORT_SYMBOL(dcbnl_cee_notify);
John Fastabend314b4772011-06-21 07:34:37 +00001372
1373/* Handle IEEE 802.1Qaz SET commands. If any requested operation can not
1374 * be completed the entire msg is aborted and error value is returned.
1375 * No attempt is made to reconcile the case where only part of the
1376 * cmd can be completed.
1377 */
Thomas Graf7be99412012-06-13 02:54:55 +00001378static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh,
1379 u32 seq, struct nlattr **tb, struct sk_buff *skb)
John Fastabend314b4772011-06-21 07:34:37 +00001380{
1381 const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
1382 struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
1383 int err = -EOPNOTSUPP;
1384
1385 if (!ops)
1386 return err;
1387
John Fastabend4003b652011-06-21 07:35:04 +00001388 if (!tb[DCB_ATTR_IEEE])
1389 return -EINVAL;
1390
John Fastabend314b4772011-06-21 07:34:37 +00001391 err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX,
1392 tb[DCB_ATTR_IEEE], dcbnl_ieee_policy);
1393 if (err)
1394 return err;
1395
1396 if (ieee[DCB_ATTR_IEEE_ETS] && ops->ieee_setets) {
1397 struct ieee_ets *ets = nla_data(ieee[DCB_ATTR_IEEE_ETS]);
1398 err = ops->ieee_setets(netdev, ets);
1399 if (err)
1400 goto err;
1401 }
1402
Amir Vadai08f10af2012-04-04 21:33:30 +00001403 if (ieee[DCB_ATTR_IEEE_MAXRATE] && ops->ieee_setmaxrate) {
1404 struct ieee_maxrate *maxrate =
1405 nla_data(ieee[DCB_ATTR_IEEE_MAXRATE]);
1406 err = ops->ieee_setmaxrate(netdev, maxrate);
1407 if (err)
1408 goto err;
1409 }
1410
John Fastabend314b4772011-06-21 07:34:37 +00001411 if (ieee[DCB_ATTR_IEEE_PFC] && ops->ieee_setpfc) {
1412 struct ieee_pfc *pfc = nla_data(ieee[DCB_ATTR_IEEE_PFC]);
1413 err = ops->ieee_setpfc(netdev, pfc);
1414 if (err)
1415 goto err;
1416 }
1417
1418 if (ieee[DCB_ATTR_IEEE_APP_TABLE]) {
1419 struct nlattr *attr;
1420 int rem;
1421
1422 nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) {
1423 struct dcb_app *app_data;
1424 if (nla_type(attr) != DCB_ATTR_IEEE_APP)
1425 continue;
1426 app_data = nla_data(attr);
1427 if (ops->ieee_setapp)
1428 err = ops->ieee_setapp(netdev, app_data);
1429 else
John Fastabendb6db2172011-06-21 07:34:42 +00001430 err = dcb_ieee_setapp(netdev, app_data);
John Fastabend314b4772011-06-21 07:34:37 +00001431 if (err)
1432 goto err;
1433 }
1434 }
1435
1436err:
Thomas Graf7be99412012-06-13 02:54:55 +00001437 err = nla_put_u8(skb, DCB_ATTR_IEEE, err);
Shmulik Ravid5b7f7622011-07-05 06:16:25 +00001438 dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_SET, seq, 0);
John Fastabend314b4772011-06-21 07:34:37 +00001439 return err;
1440}
1441
Thomas Graf7be99412012-06-13 02:54:55 +00001442static int dcbnl_ieee_get(struct net_device *netdev, struct nlmsghdr *nlh,
1443 u32 seq, struct nlattr **tb, struct sk_buff *skb)
John Fastabend314b4772011-06-21 07:34:37 +00001444{
John Fastabend314b4772011-06-21 07:34:37 +00001445 const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
John Fastabend314b4772011-06-21 07:34:37 +00001446
1447 if (!ops)
1448 return -EOPNOTSUPP;
1449
Thomas Graf7be99412012-06-13 02:54:55 +00001450 return dcbnl_ieee_fill(skb, netdev);
John Fastabend314b4772011-06-21 07:34:37 +00001451}
John Fastabendf9ae7e42011-06-21 07:34:48 +00001452
Thomas Graf7be99412012-06-13 02:54:55 +00001453static int dcbnl_ieee_del(struct net_device *netdev, struct nlmsghdr *nlh,
1454 u32 seq, struct nlattr **tb, struct sk_buff *skb)
John Fastabendf9ae7e42011-06-21 07:34:48 +00001455{
1456 const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
1457 struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
1458 int err = -EOPNOTSUPP;
1459
1460 if (!ops)
1461 return -EOPNOTSUPP;
1462
1463 if (!tb[DCB_ATTR_IEEE])
1464 return -EINVAL;
1465
1466 err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX,
1467 tb[DCB_ATTR_IEEE], dcbnl_ieee_policy);
1468 if (err)
1469 return err;
1470
1471 if (ieee[DCB_ATTR_IEEE_APP_TABLE]) {
1472 struct nlattr *attr;
1473 int rem;
1474
1475 nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) {
1476 struct dcb_app *app_data;
1477
1478 if (nla_type(attr) != DCB_ATTR_IEEE_APP)
1479 continue;
1480 app_data = nla_data(attr);
1481 if (ops->ieee_delapp)
1482 err = ops->ieee_delapp(netdev, app_data);
1483 else
1484 err = dcb_ieee_delapp(netdev, app_data);
1485 if (err)
1486 goto err;
1487 }
1488 }
1489
1490err:
Thomas Graf7be99412012-06-13 02:54:55 +00001491 err = nla_put_u8(skb, DCB_ATTR_IEEE, err);
Shmulik Ravid5b7f7622011-07-05 06:16:25 +00001492 dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_DEL, seq, 0);
John Fastabendf9ae7e42011-06-21 07:34:48 +00001493 return err;
1494}
1495
1496
Shmulik Ravid6241b622010-12-30 06:26:48 +00001497/* DCBX configuration */
Thomas Graf7be99412012-06-13 02:54:55 +00001498static int dcbnl_getdcbx(struct net_device *netdev, struct nlmsghdr *nlh,
1499 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Shmulik Ravid6241b622010-12-30 06:26:48 +00001500{
Shmulik Ravid6241b622010-12-30 06:26:48 +00001501 if (!netdev->dcbnl_ops->getdcbx)
Shmulik Ravid7f891cf2011-01-03 08:04:59 +00001502 return -EOPNOTSUPP;
Shmulik Ravid6241b622010-12-30 06:26:48 +00001503
Thomas Graf7be99412012-06-13 02:54:55 +00001504 return nla_put_u8(skb, DCB_ATTR_DCBX,
1505 netdev->dcbnl_ops->getdcbx(netdev));
Shmulik Ravid6241b622010-12-30 06:26:48 +00001506}
1507
Thomas Graf7be99412012-06-13 02:54:55 +00001508static int dcbnl_setdcbx(struct net_device *netdev, struct nlmsghdr *nlh,
1509 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Shmulik Ravid6241b622010-12-30 06:26:48 +00001510{
Shmulik Ravid6241b622010-12-30 06:26:48 +00001511 u8 value;
1512
Shmulik Ravid7f891cf2011-01-03 08:04:59 +00001513 if (!netdev->dcbnl_ops->setdcbx)
1514 return -EOPNOTSUPP;
1515
1516 if (!tb[DCB_ATTR_DCBX])
1517 return -EINVAL;
Shmulik Ravid6241b622010-12-30 06:26:48 +00001518
1519 value = nla_get_u8(tb[DCB_ATTR_DCBX]);
1520
Thomas Graf7be99412012-06-13 02:54:55 +00001521 return nla_put_u8(skb, DCB_ATTR_DCBX,
1522 netdev->dcbnl_ops->setdcbx(netdev, value));
Shmulik Ravid6241b622010-12-30 06:26:48 +00001523}
1524
Thomas Graf7be99412012-06-13 02:54:55 +00001525static int dcbnl_getfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh,
1526 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001527{
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001528 struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1], *nest;
1529 u8 value;
Shmulik Ravid7f891cf2011-01-03 08:04:59 +00001530 int ret, i;
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001531 int getall = 0;
1532
Shmulik Ravid7f891cf2011-01-03 08:04:59 +00001533 if (!netdev->dcbnl_ops->getfeatcfg)
1534 return -EOPNOTSUPP;
1535
1536 if (!tb[DCB_ATTR_FEATCFG])
1537 return -EINVAL;
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001538
1539 ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG],
1540 dcbnl_featcfg_nest);
Shmulik Ravid7f891cf2011-01-03 08:04:59 +00001541 if (ret)
Thomas Graf7be99412012-06-13 02:54:55 +00001542 return ret;
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001543
Thomas Graf7be99412012-06-13 02:54:55 +00001544 nest = nla_nest_start(skb, DCB_ATTR_FEATCFG);
1545 if (!nest)
1546 return -EMSGSIZE;
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001547
1548 if (data[DCB_FEATCFG_ATTR_ALL])
1549 getall = 1;
1550
1551 for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
1552 if (!getall && !data[i])
1553 continue;
1554
1555 ret = netdev->dcbnl_ops->getfeatcfg(netdev, i, &value);
Shmulik Ravid7f891cf2011-01-03 08:04:59 +00001556 if (!ret)
Thomas Graf7be99412012-06-13 02:54:55 +00001557 ret = nla_put_u8(skb, i, value);
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001558
Shmulik Ravid7f891cf2011-01-03 08:04:59 +00001559 if (ret) {
Thomas Graf7be99412012-06-13 02:54:55 +00001560 nla_nest_cancel(skb, nest);
Shmulik Ravid7f891cf2011-01-03 08:04:59 +00001561 goto nla_put_failure;
1562 }
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001563 }
Thomas Graf7be99412012-06-13 02:54:55 +00001564 nla_nest_end(skb, nest);
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001565
Shmulik Ravid7f891cf2011-01-03 08:04:59 +00001566nla_put_failure:
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001567 return ret;
1568}
1569
Thomas Graf7be99412012-06-13 02:54:55 +00001570static int dcbnl_setfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh,
1571 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001572{
1573 struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1];
Shmulik Ravid7f891cf2011-01-03 08:04:59 +00001574 int ret, i;
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001575 u8 value;
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001576
Shmulik Ravid7f891cf2011-01-03 08:04:59 +00001577 if (!netdev->dcbnl_ops->setfeatcfg)
1578 return -ENOTSUPP;
1579
1580 if (!tb[DCB_ATTR_FEATCFG])
1581 return -EINVAL;
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001582
1583 ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG],
1584 dcbnl_featcfg_nest);
1585
Shmulik Ravid7f891cf2011-01-03 08:04:59 +00001586 if (ret)
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001587 goto err;
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001588
1589 for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
1590 if (data[i] == NULL)
1591 continue;
1592
1593 value = nla_get_u8(data[i]);
1594
1595 ret = netdev->dcbnl_ops->setfeatcfg(netdev, i, value);
1596
1597 if (ret)
Shmulik Ravid7f891cf2011-01-03 08:04:59 +00001598 goto err;
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001599 }
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001600err:
Thomas Graf7be99412012-06-13 02:54:55 +00001601 ret = nla_put_u8(skb, DCB_ATTR_FEATCFG, ret);
Shmulik Ravid7f891cf2011-01-03 08:04:59 +00001602
Shmulik Ravidea45fe42010-12-30 06:26:55 +00001603 return ret;
1604}
1605
Shmulik Raviddc6ed1d2011-02-27 05:04:38 +00001606/* Handle CEE DCBX GET commands. */
Thomas Graf7be99412012-06-13 02:54:55 +00001607static int dcbnl_cee_get(struct net_device *netdev, struct nlmsghdr *nlh,
1608 u32 seq, struct nlattr **tb, struct sk_buff *skb)
Shmulik Raviddc6ed1d2011-02-27 05:04:38 +00001609{
Shmulik Raviddc6ed1d2011-02-27 05:04:38 +00001610 const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
Shmulik Raviddc6ed1d2011-02-27 05:04:38 +00001611
1612 if (!ops)
1613 return -EOPNOTSUPP;
1614
Thomas Graf7be99412012-06-13 02:54:55 +00001615 return dcbnl_cee_fill(skb, netdev);
Shmulik Raviddc6ed1d2011-02-27 05:04:38 +00001616}
1617
Thomas Graf33a03aa2012-06-13 02:54:54 +00001618struct reply_func {
1619 /* reply netlink message type */
1620 int type;
1621
1622 /* function to fill message contents */
1623 int (*cb)(struct net_device *, struct nlmsghdr *, u32,
1624 struct nlattr **, struct sk_buff *);
1625};
1626
1627static const struct reply_func reply_funcs[DCB_CMD_MAX+1] = {
Thomas Graf7be99412012-06-13 02:54:55 +00001628 [DCB_CMD_GSTATE] = { RTM_GETDCB, dcbnl_getstate },
1629 [DCB_CMD_SSTATE] = { RTM_SETDCB, dcbnl_setstate },
1630 [DCB_CMD_PFC_GCFG] = { RTM_GETDCB, dcbnl_getpfccfg },
1631 [DCB_CMD_PFC_SCFG] = { RTM_SETDCB, dcbnl_setpfccfg },
1632 [DCB_CMD_GPERM_HWADDR] = { RTM_GETDCB, dcbnl_getperm_hwaddr },
1633 [DCB_CMD_GCAP] = { RTM_GETDCB, dcbnl_getcap },
1634 [DCB_CMD_GNUMTCS] = { RTM_GETDCB, dcbnl_getnumtcs },
1635 [DCB_CMD_SNUMTCS] = { RTM_SETDCB, dcbnl_setnumtcs },
1636 [DCB_CMD_PFC_GSTATE] = { RTM_GETDCB, dcbnl_getpfcstate },
1637 [DCB_CMD_PFC_SSTATE] = { RTM_SETDCB, dcbnl_setpfcstate },
1638 [DCB_CMD_GAPP] = { RTM_GETDCB, dcbnl_getapp },
1639 [DCB_CMD_SAPP] = { RTM_SETDCB, dcbnl_setapp },
1640 [DCB_CMD_PGTX_GCFG] = { RTM_GETDCB, dcbnl_pgtx_getcfg },
1641 [DCB_CMD_PGTX_SCFG] = { RTM_SETDCB, dcbnl_pgtx_setcfg },
1642 [DCB_CMD_PGRX_GCFG] = { RTM_GETDCB, dcbnl_pgrx_getcfg },
1643 [DCB_CMD_PGRX_SCFG] = { RTM_SETDCB, dcbnl_pgrx_setcfg },
1644 [DCB_CMD_SET_ALL] = { RTM_SETDCB, dcbnl_setall },
1645 [DCB_CMD_BCN_GCFG] = { RTM_GETDCB, dcbnl_bcn_getcfg },
1646 [DCB_CMD_BCN_SCFG] = { RTM_SETDCB, dcbnl_bcn_setcfg },
1647 [DCB_CMD_IEEE_GET] = { RTM_GETDCB, dcbnl_ieee_get },
1648 [DCB_CMD_IEEE_SET] = { RTM_SETDCB, dcbnl_ieee_set },
1649 [DCB_CMD_IEEE_DEL] = { RTM_SETDCB, dcbnl_ieee_del },
1650 [DCB_CMD_GDCBX] = { RTM_GETDCB, dcbnl_getdcbx },
1651 [DCB_CMD_SDCBX] = { RTM_SETDCB, dcbnl_setdcbx },
1652 [DCB_CMD_GFEATCFG] = { RTM_GETDCB, dcbnl_getfeatcfg },
1653 [DCB_CMD_SFEATCFG] = { RTM_SETDCB, dcbnl_setfeatcfg },
1654 [DCB_CMD_CEE_GET] = { RTM_GETDCB, dcbnl_cee_get },
Thomas Graf33a03aa2012-06-13 02:54:54 +00001655};
1656
Alexander Duyck2f90b862008-11-20 20:52:10 -08001657static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1658{
1659 struct net *net = sock_net(skb->sk);
1660 struct net_device *netdev;
1661 struct dcbmsg *dcb = (struct dcbmsg *)NLMSG_DATA(nlh);
1662 struct nlattr *tb[DCB_ATTR_MAX + 1];
1663 u32 pid = skb ? NETLINK_CB(skb).pid : 0;
1664 int ret = -EINVAL;
Thomas Graf33a03aa2012-06-13 02:54:54 +00001665 struct sk_buff *reply_skb;
1666 struct nlmsghdr *reply_nlh;
1667 const struct reply_func *fn;
Alexander Duyck2f90b862008-11-20 20:52:10 -08001668
Octavian Purdila09ad9bc2009-11-25 15:14:13 -08001669 if (!net_eq(net, &init_net))
Alexander Duyck2f90b862008-11-20 20:52:10 -08001670 return -EINVAL;
1671
1672 ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
1673 dcbnl_rtnl_policy);
1674 if (ret < 0)
1675 return ret;
1676
Thomas Graf33a03aa2012-06-13 02:54:54 +00001677 if (dcb->cmd > DCB_CMD_MAX)
1678 return -EINVAL;
1679
1680 /* check if a reply function has been defined for the command */
1681 fn = &reply_funcs[dcb->cmd];
1682 if (!fn->cb)
1683 return -EOPNOTSUPP;
1684
Alexander Duyck2f90b862008-11-20 20:52:10 -08001685 if (!tb[DCB_ATTR_IFNAME])
1686 return -EINVAL;
1687
1688 netdev = dev_get_by_name(&init_net, nla_data(tb[DCB_ATTR_IFNAME]));
1689 if (!netdev)
1690 return -EINVAL;
1691
1692 if (!netdev->dcbnl_ops)
1693 goto errout;
1694
Thomas Graf33a03aa2012-06-13 02:54:54 +00001695 reply_skb = dcbnl_newmsg(fn->type, dcb->cmd, pid, nlh->nlmsg_seq,
1696 nlh->nlmsg_flags, &reply_nlh);
1697 if (!reply_skb) {
1698 ret = -ENOBUFS;
1699 goto out;
1700 }
1701
1702 ret = fn->cb(netdev, nlh, nlh->nlmsg_seq, tb, reply_skb);
1703 if (ret < 0) {
1704 nlmsg_free(reply_skb);
1705 goto out;
1706 }
1707
1708 nlmsg_end(reply_skb, reply_nlh);
1709
1710 ret = rtnl_unicast(reply_skb, &init_net, pid);
Alexander Duyck2f90b862008-11-20 20:52:10 -08001711out:
1712 dev_put(netdev);
1713 return ret;
1714}
1715
John Fastabend9ab933a2010-12-30 09:26:31 +00001716/**
1717 * dcb_getapp - retrieve the DCBX application user priority
1718 *
1719 * On success returns a non-zero 802.1p user priority bitmap
1720 * otherwise returns 0 as the invalid user priority bitmap to
1721 * indicate an error.
1722 */
1723u8 dcb_getapp(struct net_device *dev, struct dcb_app *app)
1724{
1725 struct dcb_app_type *itr;
1726 u8 prio = 0;
1727
1728 spin_lock(&dcb_lock);
1729 list_for_each_entry(itr, &dcb_app_list, list) {
1730 if (itr->app.selector == app->selector &&
1731 itr->app.protocol == app->protocol &&
Mark Rustade290ed82011-10-06 08:52:33 +00001732 itr->ifindex == dev->ifindex) {
John Fastabend9ab933a2010-12-30 09:26:31 +00001733 prio = itr->app.priority;
1734 break;
1735 }
1736 }
1737 spin_unlock(&dcb_lock);
1738
1739 return prio;
1740}
1741EXPORT_SYMBOL(dcb_getapp);
1742
1743/**
John Fastabendb6db2172011-06-21 07:34:42 +00001744 * dcb_setapp - add CEE dcb application data to app list
John Fastabend9ab933a2010-12-30 09:26:31 +00001745 *
John Fastabendb6db2172011-06-21 07:34:42 +00001746 * Priority 0 is an invalid priority in CEE spec. This routine
1747 * removes applications from the app list if the priority is
1748 * set to zero.
John Fastabend9ab933a2010-12-30 09:26:31 +00001749 */
John Fastabendab6baf92011-06-21 07:34:58 +00001750int dcb_setapp(struct net_device *dev, struct dcb_app *new)
John Fastabend9ab933a2010-12-30 09:26:31 +00001751{
1752 struct dcb_app_type *itr;
John Fastabend7ec79272011-01-31 12:00:59 +00001753 struct dcb_app_type event;
1754
Mark Rustade290ed82011-10-06 08:52:33 +00001755 event.ifindex = dev->ifindex;
John Fastabend7ec79272011-01-31 12:00:59 +00001756 memcpy(&event.app, new, sizeof(event.app));
John Fastabend6bd0e1c2011-10-06 08:52:38 +00001757 if (dev->dcbnl_ops->getdcbx)
1758 event.dcbx = dev->dcbnl_ops->getdcbx(dev);
John Fastabend9ab933a2010-12-30 09:26:31 +00001759
1760 spin_lock(&dcb_lock);
1761 /* Search for existing match and replace */
1762 list_for_each_entry(itr, &dcb_app_list, list) {
1763 if (itr->app.selector == new->selector &&
1764 itr->app.protocol == new->protocol &&
Mark Rustade290ed82011-10-06 08:52:33 +00001765 itr->ifindex == dev->ifindex) {
John Fastabend9ab933a2010-12-30 09:26:31 +00001766 if (new->priority)
1767 itr->app.priority = new->priority;
1768 else {
1769 list_del(&itr->list);
1770 kfree(itr);
1771 }
1772 goto out;
1773 }
1774 }
1775 /* App type does not exist add new application type */
1776 if (new->priority) {
1777 struct dcb_app_type *entry;
1778 entry = kmalloc(sizeof(struct dcb_app_type), GFP_ATOMIC);
1779 if (!entry) {
1780 spin_unlock(&dcb_lock);
1781 return -ENOMEM;
1782 }
1783
1784 memcpy(&entry->app, new, sizeof(*new));
Mark Rustade290ed82011-10-06 08:52:33 +00001785 entry->ifindex = dev->ifindex;
John Fastabend9ab933a2010-12-30 09:26:31 +00001786 list_add(&entry->list, &dcb_app_list);
1787 }
1788out:
1789 spin_unlock(&dcb_lock);
John Fastabend7ec79272011-01-31 12:00:59 +00001790 call_dcbevent_notifiers(DCB_APP_EVENT, &event);
John Fastabend9ab933a2010-12-30 09:26:31 +00001791 return 0;
1792}
1793EXPORT_SYMBOL(dcb_setapp);
1794
John Fastabendb6db2172011-06-21 07:34:42 +00001795/**
John Fastabenda364c8c2011-06-21 07:34:53 +00001796 * dcb_ieee_getapp_mask - retrieve the IEEE DCB application priority
1797 *
1798 * Helper routine which on success returns a non-zero 802.1Qaz user
1799 * priority bitmap otherwise returns 0 to indicate the dcb_app was
1800 * not found in APP list.
1801 */
1802u8 dcb_ieee_getapp_mask(struct net_device *dev, struct dcb_app *app)
1803{
1804 struct dcb_app_type *itr;
1805 u8 prio = 0;
1806
1807 spin_lock(&dcb_lock);
1808 list_for_each_entry(itr, &dcb_app_list, list) {
1809 if (itr->app.selector == app->selector &&
1810 itr->app.protocol == app->protocol &&
Mark Rustade290ed82011-10-06 08:52:33 +00001811 itr->ifindex == dev->ifindex) {
John Fastabenda364c8c2011-06-21 07:34:53 +00001812 prio |= 1 << itr->app.priority;
1813 }
1814 }
1815 spin_unlock(&dcb_lock);
1816
1817 return prio;
1818}
1819EXPORT_SYMBOL(dcb_ieee_getapp_mask);
1820
1821/**
John Fastabendb6db2172011-06-21 07:34:42 +00001822 * dcb_ieee_setapp - add IEEE dcb application data to app list
1823 *
1824 * This adds Application data to the list. Multiple application
1825 * entries may exists for the same selector and protocol as long
1826 * as the priorities are different.
1827 */
1828int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new)
1829{
1830 struct dcb_app_type *itr, *entry;
1831 struct dcb_app_type event;
1832 int err = 0;
1833
Mark Rustade290ed82011-10-06 08:52:33 +00001834 event.ifindex = dev->ifindex;
John Fastabendb6db2172011-06-21 07:34:42 +00001835 memcpy(&event.app, new, sizeof(event.app));
John Fastabend6bd0e1c2011-10-06 08:52:38 +00001836 if (dev->dcbnl_ops->getdcbx)
1837 event.dcbx = dev->dcbnl_ops->getdcbx(dev);
John Fastabendb6db2172011-06-21 07:34:42 +00001838
1839 spin_lock(&dcb_lock);
1840 /* Search for existing match and abort if found */
1841 list_for_each_entry(itr, &dcb_app_list, list) {
1842 if (itr->app.selector == new->selector &&
1843 itr->app.protocol == new->protocol &&
1844 itr->app.priority == new->priority &&
Mark Rustade290ed82011-10-06 08:52:33 +00001845 itr->ifindex == dev->ifindex) {
John Fastabendb6db2172011-06-21 07:34:42 +00001846 err = -EEXIST;
1847 goto out;
1848 }
1849 }
1850
1851 /* App entry does not exist add new entry */
1852 entry = kmalloc(sizeof(struct dcb_app_type), GFP_ATOMIC);
1853 if (!entry) {
1854 err = -ENOMEM;
1855 goto out;
1856 }
1857
1858 memcpy(&entry->app, new, sizeof(*new));
Mark Rustade290ed82011-10-06 08:52:33 +00001859 entry->ifindex = dev->ifindex;
John Fastabendb6db2172011-06-21 07:34:42 +00001860 list_add(&entry->list, &dcb_app_list);
1861out:
1862 spin_unlock(&dcb_lock);
1863 if (!err)
1864 call_dcbevent_notifiers(DCB_APP_EVENT, &event);
1865 return err;
1866}
1867EXPORT_SYMBOL(dcb_ieee_setapp);
1868
John Fastabendf9ae7e42011-06-21 07:34:48 +00001869/**
1870 * dcb_ieee_delapp - delete IEEE dcb application data from list
1871 *
1872 * This removes a matching APP data from the APP list
1873 */
1874int dcb_ieee_delapp(struct net_device *dev, struct dcb_app *del)
1875{
1876 struct dcb_app_type *itr;
1877 struct dcb_app_type event;
1878 int err = -ENOENT;
1879
Mark Rustade290ed82011-10-06 08:52:33 +00001880 event.ifindex = dev->ifindex;
John Fastabendf9ae7e42011-06-21 07:34:48 +00001881 memcpy(&event.app, del, sizeof(event.app));
John Fastabend6bd0e1c2011-10-06 08:52:38 +00001882 if (dev->dcbnl_ops->getdcbx)
1883 event.dcbx = dev->dcbnl_ops->getdcbx(dev);
John Fastabendf9ae7e42011-06-21 07:34:48 +00001884
1885 spin_lock(&dcb_lock);
1886 /* Search for existing match and remove it. */
1887 list_for_each_entry(itr, &dcb_app_list, list) {
1888 if (itr->app.selector == del->selector &&
1889 itr->app.protocol == del->protocol &&
1890 itr->app.priority == del->priority &&
Mark Rustade290ed82011-10-06 08:52:33 +00001891 itr->ifindex == dev->ifindex) {
John Fastabendf9ae7e42011-06-21 07:34:48 +00001892 list_del(&itr->list);
1893 kfree(itr);
1894 err = 0;
1895 goto out;
1896 }
1897 }
1898
1899out:
1900 spin_unlock(&dcb_lock);
1901 if (!err)
1902 call_dcbevent_notifiers(DCB_APP_EVENT, &event);
1903 return err;
1904}
1905EXPORT_SYMBOL(dcb_ieee_delapp);
1906
Shmulik Ravid7c14c3f2010-12-30 06:27:10 +00001907static void dcb_flushapp(void)
John Fastabend9ab933a2010-12-30 09:26:31 +00001908{
1909 struct dcb_app_type *app;
Dan Carpenter2a8fe002011-01-04 21:03:44 +00001910 struct dcb_app_type *tmp;
John Fastabend9ab933a2010-12-30 09:26:31 +00001911
1912 spin_lock(&dcb_lock);
Dan Carpenter2a8fe002011-01-04 21:03:44 +00001913 list_for_each_entry_safe(app, tmp, &dcb_app_list, list) {
John Fastabend9ab933a2010-12-30 09:26:31 +00001914 list_del(&app->list);
1915 kfree(app);
1916 }
1917 spin_unlock(&dcb_lock);
1918}
1919
Alexander Duyck2f90b862008-11-20 20:52:10 -08001920static int __init dcbnl_init(void)
1921{
John Fastabend9ab933a2010-12-30 09:26:31 +00001922 INIT_LIST_HEAD(&dcb_app_list);
1923
Greg Rosec7ac8672011-06-10 01:27:09 +00001924 rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL, NULL);
1925 rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL, NULL);
Alexander Duyck2f90b862008-11-20 20:52:10 -08001926
1927 return 0;
1928}
1929module_init(dcbnl_init);
1930
1931static void __exit dcbnl_exit(void)
1932{
1933 rtnl_unregister(PF_UNSPEC, RTM_GETDCB);
1934 rtnl_unregister(PF_UNSPEC, RTM_SETDCB);
John Fastabend9ab933a2010-12-30 09:26:31 +00001935 dcb_flushapp();
Alexander Duyck2f90b862008-11-20 20:52:10 -08001936}
1937module_exit(dcbnl_exit);