blob: 4046468b219ed847b35e3d9da0ca79e1f532ff80 [file] [log] [blame]
Alexander Duyck2f90b862008-11-20 20:52:10 -08001/*
2 * Copyright (c) 2008, Intel Corporation.
3 *
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>
22#include <net/netlink.h>
23#include <net/rtnetlink.h>
24#include <linux/dcbnl.h>
25#include <linux/rtnetlink.h>
26#include <net/sock.h>
27
28/**
29 * Data Center Bridging (DCB) is a collection of Ethernet enhancements
30 * intended to allow network traffic with differing requirements
31 * (highly reliable, no drops vs. best effort vs. low latency) to operate
32 * and co-exist on Ethernet. Current DCB features are:
33 *
34 * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a
35 * framework for assigning bandwidth guarantees to traffic classes.
36 *
37 * Priority-based Flow Control (PFC) - provides a flow control mechanism which
38 * can work independently for each 802.1p priority.
39 *
40 * Congestion Notification - provides a mechanism for end-to-end congestion
41 * control for protocols which do not have built-in congestion management.
42 *
43 * More information about the emerging standards for these Ethernet features
44 * can be found at: http://www.ieee802.org/1/pages/dcbridges.html
45 *
46 * This file implements an rtnetlink interface to allow configuration of DCB
47 * features for capable devices.
48 */
49
50MODULE_AUTHOR("Lucy Liu, <lucy.liu@intel.com>");
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -080051MODULE_DESCRIPTION("Data Center Bridging netlink interface");
Alexander Duyck2f90b862008-11-20 20:52:10 -080052MODULE_LICENSE("GPL");
53
54/**************** DCB attribute policies *************************************/
55
56/* DCB netlink attributes policy */
57static struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = {
Alexander Duyck859ee3c2008-11-20 21:10:23 -080058 [DCB_ATTR_IFNAME] = {.type = NLA_NUL_STRING, .len = IFNAMSIZ - 1},
59 [DCB_ATTR_STATE] = {.type = NLA_U8},
60 [DCB_ATTR_PFC_CFG] = {.type = NLA_NESTED},
61 [DCB_ATTR_PG_CFG] = {.type = NLA_NESTED},
62 [DCB_ATTR_SET_ALL] = {.type = NLA_U8},
Alexander Duyck2f90b862008-11-20 20:52:10 -080063 [DCB_ATTR_PERM_HWADDR] = {.type = NLA_FLAG},
Alexander Duyck859ee3c2008-11-20 21:10:23 -080064 [DCB_ATTR_CAP] = {.type = NLA_NESTED},
65 [DCB_ATTR_PFC_STATE] = {.type = NLA_U8},
66 [DCB_ATTR_BCN] = {.type = NLA_NESTED},
Yi Zou6fa382a2009-08-31 12:33:20 +000067 [DCB_ATTR_APP] = {.type = NLA_NESTED},
Alexander Duyck2f90b862008-11-20 20:52:10 -080068};
69
70/* DCB priority flow control to User Priority nested attributes */
71static struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = {
72 [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8},
73 [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8},
74 [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8},
75 [DCB_PFC_UP_ATTR_3] = {.type = NLA_U8},
76 [DCB_PFC_UP_ATTR_4] = {.type = NLA_U8},
77 [DCB_PFC_UP_ATTR_5] = {.type = NLA_U8},
78 [DCB_PFC_UP_ATTR_6] = {.type = NLA_U8},
79 [DCB_PFC_UP_ATTR_7] = {.type = NLA_U8},
80 [DCB_PFC_UP_ATTR_ALL] = {.type = NLA_FLAG},
81};
82
83/* DCB priority grouping nested attributes */
84static struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = {
85 [DCB_PG_ATTR_TC_0] = {.type = NLA_NESTED},
86 [DCB_PG_ATTR_TC_1] = {.type = NLA_NESTED},
87 [DCB_PG_ATTR_TC_2] = {.type = NLA_NESTED},
88 [DCB_PG_ATTR_TC_3] = {.type = NLA_NESTED},
89 [DCB_PG_ATTR_TC_4] = {.type = NLA_NESTED},
90 [DCB_PG_ATTR_TC_5] = {.type = NLA_NESTED},
91 [DCB_PG_ATTR_TC_6] = {.type = NLA_NESTED},
92 [DCB_PG_ATTR_TC_7] = {.type = NLA_NESTED},
93 [DCB_PG_ATTR_TC_ALL] = {.type = NLA_NESTED},
94 [DCB_PG_ATTR_BW_ID_0] = {.type = NLA_U8},
95 [DCB_PG_ATTR_BW_ID_1] = {.type = NLA_U8},
96 [DCB_PG_ATTR_BW_ID_2] = {.type = NLA_U8},
97 [DCB_PG_ATTR_BW_ID_3] = {.type = NLA_U8},
98 [DCB_PG_ATTR_BW_ID_4] = {.type = NLA_U8},
99 [DCB_PG_ATTR_BW_ID_5] = {.type = NLA_U8},
100 [DCB_PG_ATTR_BW_ID_6] = {.type = NLA_U8},
101 [DCB_PG_ATTR_BW_ID_7] = {.type = NLA_U8},
102 [DCB_PG_ATTR_BW_ID_ALL] = {.type = NLA_FLAG},
103};
104
105/* DCB traffic class nested attributes. */
106static struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = {
107 [DCB_TC_ATTR_PARAM_PGID] = {.type = NLA_U8},
108 [DCB_TC_ATTR_PARAM_UP_MAPPING] = {.type = NLA_U8},
109 [DCB_TC_ATTR_PARAM_STRICT_PRIO] = {.type = NLA_U8},
110 [DCB_TC_ATTR_PARAM_BW_PCT] = {.type = NLA_U8},
111 [DCB_TC_ATTR_PARAM_ALL] = {.type = NLA_FLAG},
112};
113
Alexander Duyck46132182008-11-20 21:05:08 -0800114/* DCB capabilities nested attributes. */
115static struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = {
116 [DCB_CAP_ATTR_ALL] = {.type = NLA_FLAG},
117 [DCB_CAP_ATTR_PG] = {.type = NLA_U8},
118 [DCB_CAP_ATTR_PFC] = {.type = NLA_U8},
119 [DCB_CAP_ATTR_UP2TC] = {.type = NLA_U8},
120 [DCB_CAP_ATTR_PG_TCS] = {.type = NLA_U8},
121 [DCB_CAP_ATTR_PFC_TCS] = {.type = NLA_U8},
122 [DCB_CAP_ATTR_GSP] = {.type = NLA_U8},
123 [DCB_CAP_ATTR_BCN] = {.type = NLA_U8},
124};
Alexander Duyck2f90b862008-11-20 20:52:10 -0800125
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800126/* DCB capabilities nested attributes. */
127static struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = {
128 [DCB_NUMTCS_ATTR_ALL] = {.type = NLA_FLAG},
129 [DCB_NUMTCS_ATTR_PG] = {.type = NLA_U8},
130 [DCB_NUMTCS_ATTR_PFC] = {.type = NLA_U8},
131};
132
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800133/* DCB BCN nested attributes. */
134static struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = {
135 [DCB_BCN_ATTR_RP_0] = {.type = NLA_U8},
136 [DCB_BCN_ATTR_RP_1] = {.type = NLA_U8},
137 [DCB_BCN_ATTR_RP_2] = {.type = NLA_U8},
138 [DCB_BCN_ATTR_RP_3] = {.type = NLA_U8},
139 [DCB_BCN_ATTR_RP_4] = {.type = NLA_U8},
140 [DCB_BCN_ATTR_RP_5] = {.type = NLA_U8},
141 [DCB_BCN_ATTR_RP_6] = {.type = NLA_U8},
142 [DCB_BCN_ATTR_RP_7] = {.type = NLA_U8},
143 [DCB_BCN_ATTR_RP_ALL] = {.type = NLA_FLAG},
Don Skidmoref4314e82008-12-21 20:10:29 -0800144 [DCB_BCN_ATTR_BCNA_0] = {.type = NLA_U32},
145 [DCB_BCN_ATTR_BCNA_1] = {.type = NLA_U32},
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800146 [DCB_BCN_ATTR_ALPHA] = {.type = NLA_U32},
147 [DCB_BCN_ATTR_BETA] = {.type = NLA_U32},
148 [DCB_BCN_ATTR_GD] = {.type = NLA_U32},
149 [DCB_BCN_ATTR_GI] = {.type = NLA_U32},
150 [DCB_BCN_ATTR_TMAX] = {.type = NLA_U32},
151 [DCB_BCN_ATTR_TD] = {.type = NLA_U32},
152 [DCB_BCN_ATTR_RMIN] = {.type = NLA_U32},
153 [DCB_BCN_ATTR_W] = {.type = NLA_U32},
154 [DCB_BCN_ATTR_RD] = {.type = NLA_U32},
155 [DCB_BCN_ATTR_RU] = {.type = NLA_U32},
156 [DCB_BCN_ATTR_WRTT] = {.type = NLA_U32},
157 [DCB_BCN_ATTR_RI] = {.type = NLA_U32},
158 [DCB_BCN_ATTR_C] = {.type = NLA_U32},
159 [DCB_BCN_ATTR_ALL] = {.type = NLA_FLAG},
160};
161
Yi Zou6fa382a2009-08-31 12:33:20 +0000162/* DCB APP nested attributes. */
163static struct nla_policy dcbnl_app_nest[DCB_APP_ATTR_MAX + 1] = {
164 [DCB_APP_ATTR_IDTYPE] = {.type = NLA_U8},
165 [DCB_APP_ATTR_ID] = {.type = NLA_U16},
166 [DCB_APP_ATTR_PRIORITY] = {.type = NLA_U8},
167};
168
Alexander Duyck2f90b862008-11-20 20:52:10 -0800169/* standard netlink reply call */
170static int dcbnl_reply(u8 value, u8 event, u8 cmd, u8 attr, u32 pid,
171 u32 seq, u16 flags)
172{
173 struct sk_buff *dcbnl_skb;
174 struct dcbmsg *dcb;
175 struct nlmsghdr *nlh;
176 int ret = -EINVAL;
177
178 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
179 if (!dcbnl_skb)
180 return ret;
181
182 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, event, sizeof(*dcb), flags);
183
184 dcb = NLMSG_DATA(nlh);
185 dcb->dcb_family = AF_UNSPEC;
186 dcb->cmd = cmd;
187 dcb->dcb_pad = 0;
188
189 ret = nla_put_u8(dcbnl_skb, attr, value);
190 if (ret)
191 goto err;
192
193 /* end the message, assign the nlmsg_len. */
194 nlmsg_end(dcbnl_skb, nlh);
195 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
196 if (ret)
197 goto err;
198
199 return 0;
200nlmsg_failure:
201err:
Roel Kluin858eb712009-01-04 17:29:21 -0800202 kfree_skb(dcbnl_skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800203 return ret;
204}
205
206static int dcbnl_getstate(struct net_device *netdev, struct nlattr **tb,
207 u32 pid, u32 seq, u16 flags)
208{
209 int ret = -EINVAL;
210
211 /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
212 if (!netdev->dcbnl_ops->getstate)
213 return ret;
214
215 ret = dcbnl_reply(netdev->dcbnl_ops->getstate(netdev), RTM_GETDCB,
216 DCB_CMD_GSTATE, DCB_ATTR_STATE, pid, seq, flags);
217
218 return ret;
219}
220
221static int dcbnl_getpfccfg(struct net_device *netdev, struct nlattr **tb,
222 u32 pid, u32 seq, u16 flags)
223{
224 struct sk_buff *dcbnl_skb;
225 struct nlmsghdr *nlh;
226 struct dcbmsg *dcb;
227 struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1], *nest;
228 u8 value;
229 int ret = -EINVAL;
230 int i;
231 int getall = 0;
232
233 if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->getpfccfg)
234 return ret;
235
236 ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
237 tb[DCB_ATTR_PFC_CFG],
238 dcbnl_pfc_up_nest);
239 if (ret)
240 goto err_out;
241
242 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
243 if (!dcbnl_skb)
244 goto err_out;
245
246 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
247
248 dcb = NLMSG_DATA(nlh);
249 dcb->dcb_family = AF_UNSPEC;
250 dcb->cmd = DCB_CMD_PFC_GCFG;
251
252 nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PFC_CFG);
253 if (!nest)
254 goto err;
255
256 if (data[DCB_PFC_UP_ATTR_ALL])
257 getall = 1;
258
259 for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
260 if (!getall && !data[i])
261 continue;
262
263 netdev->dcbnl_ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0,
264 &value);
265 ret = nla_put_u8(dcbnl_skb, i, value);
266
267 if (ret) {
268 nla_nest_cancel(dcbnl_skb, nest);
269 goto err;
270 }
271 }
272 nla_nest_end(dcbnl_skb, nest);
273
274 nlmsg_end(dcbnl_skb, nlh);
275
276 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
277 if (ret)
278 goto err;
279
280 return 0;
281nlmsg_failure:
282err:
Roel Kluin858eb712009-01-04 17:29:21 -0800283 kfree_skb(dcbnl_skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800284err_out:
285 return -EINVAL;
286}
287
288static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlattr **tb,
289 u32 pid, u32 seq, u16 flags)
290{
291 struct sk_buff *dcbnl_skb;
292 struct nlmsghdr *nlh;
293 struct dcbmsg *dcb;
294 u8 perm_addr[MAX_ADDR_LEN];
295 int ret = -EINVAL;
296
297 if (!netdev->dcbnl_ops->getpermhwaddr)
298 return ret;
299
300 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
301 if (!dcbnl_skb)
302 goto err_out;
303
304 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
305
306 dcb = NLMSG_DATA(nlh);
307 dcb->dcb_family = AF_UNSPEC;
308 dcb->cmd = DCB_CMD_GPERM_HWADDR;
309
310 netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
311
312 ret = nla_put(dcbnl_skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr),
313 perm_addr);
314
315 nlmsg_end(dcbnl_skb, nlh);
316
317 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
318 if (ret)
319 goto err;
320
321 return 0;
322
323nlmsg_failure:
324err:
Roel Kluin858eb712009-01-04 17:29:21 -0800325 kfree_skb(dcbnl_skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800326err_out:
327 return -EINVAL;
328}
329
Alexander Duyck46132182008-11-20 21:05:08 -0800330static int dcbnl_getcap(struct net_device *netdev, struct nlattr **tb,
331 u32 pid, u32 seq, u16 flags)
332{
333 struct sk_buff *dcbnl_skb;
334 struct nlmsghdr *nlh;
335 struct dcbmsg *dcb;
336 struct nlattr *data[DCB_CAP_ATTR_MAX + 1], *nest;
337 u8 value;
338 int ret = -EINVAL;
339 int i;
340 int getall = 0;
341
342 if (!tb[DCB_ATTR_CAP] || !netdev->dcbnl_ops->getcap)
343 return ret;
344
345 ret = nla_parse_nested(data, DCB_CAP_ATTR_MAX, tb[DCB_ATTR_CAP],
346 dcbnl_cap_nest);
347 if (ret)
348 goto err_out;
349
350 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
351 if (!dcbnl_skb)
352 goto err_out;
353
354 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
355
356 dcb = NLMSG_DATA(nlh);
357 dcb->dcb_family = AF_UNSPEC;
358 dcb->cmd = DCB_CMD_GCAP;
359
360 nest = nla_nest_start(dcbnl_skb, DCB_ATTR_CAP);
361 if (!nest)
362 goto err;
363
364 if (data[DCB_CAP_ATTR_ALL])
365 getall = 1;
366
367 for (i = DCB_CAP_ATTR_ALL+1; i <= DCB_CAP_ATTR_MAX; i++) {
368 if (!getall && !data[i])
369 continue;
370
371 if (!netdev->dcbnl_ops->getcap(netdev, i, &value)) {
372 ret = nla_put_u8(dcbnl_skb, i, value);
373
374 if (ret) {
375 nla_nest_cancel(dcbnl_skb, nest);
376 goto err;
377 }
378 }
379 }
380 nla_nest_end(dcbnl_skb, nest);
381
382 nlmsg_end(dcbnl_skb, nlh);
383
384 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
385 if (ret)
386 goto err;
387
388 return 0;
389nlmsg_failure:
390err:
Roel Kluin858eb712009-01-04 17:29:21 -0800391 kfree_skb(dcbnl_skb);
Alexander Duyck46132182008-11-20 21:05:08 -0800392err_out:
393 return -EINVAL;
394}
395
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800396static int dcbnl_getnumtcs(struct net_device *netdev, struct nlattr **tb,
397 u32 pid, u32 seq, u16 flags)
398{
399 struct sk_buff *dcbnl_skb;
400 struct nlmsghdr *nlh;
401 struct dcbmsg *dcb;
402 struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1], *nest;
403 u8 value;
404 int ret = -EINVAL;
405 int i;
406 int getall = 0;
407
408 if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->getnumtcs)
409 return ret;
410
411 ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
412 dcbnl_numtcs_nest);
413 if (ret) {
414 ret = -EINVAL;
415 goto err_out;
416 }
417
418 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
419 if (!dcbnl_skb) {
420 ret = -EINVAL;
421 goto err_out;
422 }
423
424 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
425
426 dcb = NLMSG_DATA(nlh);
427 dcb->dcb_family = AF_UNSPEC;
428 dcb->cmd = DCB_CMD_GNUMTCS;
429
430 nest = nla_nest_start(dcbnl_skb, DCB_ATTR_NUMTCS);
431 if (!nest) {
432 ret = -EINVAL;
433 goto err;
434 }
435
436 if (data[DCB_NUMTCS_ATTR_ALL])
437 getall = 1;
438
439 for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
440 if (!getall && !data[i])
441 continue;
442
443 ret = netdev->dcbnl_ops->getnumtcs(netdev, i, &value);
444 if (!ret) {
445 ret = nla_put_u8(dcbnl_skb, i, value);
446
447 if (ret) {
448 nla_nest_cancel(dcbnl_skb, nest);
449 ret = -EINVAL;
450 goto err;
451 }
452 } else {
453 goto err;
454 }
455 }
456 nla_nest_end(dcbnl_skb, nest);
457
458 nlmsg_end(dcbnl_skb, nlh);
459
460 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
461 if (ret) {
462 ret = -EINVAL;
463 goto err;
464 }
465
466 return 0;
467nlmsg_failure:
468err:
Roel Kluin858eb712009-01-04 17:29:21 -0800469 kfree_skb(dcbnl_skb);
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800470err_out:
471 return ret;
472}
473
474static int dcbnl_setnumtcs(struct net_device *netdev, struct nlattr **tb,
475 u32 pid, u32 seq, u16 flags)
476{
477 struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1];
478 int ret = -EINVAL;
479 u8 value;
480 int i;
481
Don Skidmore8b124a82008-12-15 01:06:23 -0800482 if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->setnumtcs)
Alexander Duyck33dbabc2008-11-20 21:08:19 -0800483 return ret;
484
485 ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
486 dcbnl_numtcs_nest);
487
488 if (ret) {
489 ret = -EINVAL;
490 goto err;
491 }
492
493 for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
494 if (data[i] == NULL)
495 continue;
496
497 value = nla_get_u8(data[i]);
498
499 ret = netdev->dcbnl_ops->setnumtcs(netdev, i, value);
500
501 if (ret)
502 goto operr;
503 }
504
505operr:
506 ret = dcbnl_reply(!!ret, RTM_SETDCB, DCB_CMD_SNUMTCS,
507 DCB_ATTR_NUMTCS, pid, seq, flags);
508
509err:
510 return ret;
511}
512
Alexander Duyck0eb3aa92008-11-20 21:09:23 -0800513static int dcbnl_getpfcstate(struct net_device *netdev, struct nlattr **tb,
514 u32 pid, u32 seq, u16 flags)
515{
516 int ret = -EINVAL;
517
518 if (!netdev->dcbnl_ops->getpfcstate)
519 return ret;
520
521 ret = dcbnl_reply(netdev->dcbnl_ops->getpfcstate(netdev), RTM_GETDCB,
522 DCB_CMD_PFC_GSTATE, DCB_ATTR_PFC_STATE,
523 pid, seq, flags);
524
525 return ret;
526}
527
528static int dcbnl_setpfcstate(struct net_device *netdev, struct nlattr **tb,
529 u32 pid, u32 seq, u16 flags)
530{
531 int ret = -EINVAL;
532 u8 value;
533
534 if (!tb[DCB_ATTR_PFC_STATE] || !netdev->dcbnl_ops->setpfcstate)
535 return ret;
536
537 value = nla_get_u8(tb[DCB_ATTR_PFC_STATE]);
538
539 netdev->dcbnl_ops->setpfcstate(netdev, value);
540
541 ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SSTATE, DCB_ATTR_PFC_STATE,
542 pid, seq, flags);
543
544 return ret;
545}
546
Alexander Duyck2f90b862008-11-20 20:52:10 -0800547static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlattr **tb,
548 u32 pid, u32 seq, u16 flags, int dir)
549{
550 struct sk_buff *dcbnl_skb;
551 struct nlmsghdr *nlh;
552 struct dcbmsg *dcb;
553 struct nlattr *pg_nest, *param_nest, *data;
554 struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
555 struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
556 u8 prio, pgid, tc_pct, up_map;
557 int ret = -EINVAL;
558 int getall = 0;
559 int i;
560
561 if (!tb[DCB_ATTR_PG_CFG] ||
562 !netdev->dcbnl_ops->getpgtccfgtx ||
563 !netdev->dcbnl_ops->getpgtccfgrx ||
564 !netdev->dcbnl_ops->getpgbwgcfgtx ||
565 !netdev->dcbnl_ops->getpgbwgcfgrx)
566 return ret;
567
568 ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
569 tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
570
571 if (ret)
572 goto err_out;
573
574 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
575 if (!dcbnl_skb)
576 goto err_out;
577
578 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
579
580 dcb = NLMSG_DATA(nlh);
581 dcb->dcb_family = AF_UNSPEC;
582 dcb->cmd = (dir) ? DCB_CMD_PGRX_GCFG : DCB_CMD_PGTX_GCFG;
583
584 pg_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PG_CFG);
585 if (!pg_nest)
586 goto err;
587
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
604 param_nest = nla_nest_start(dcbnl_skb, i);
605 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]) {
627 ret = nla_put_u8(dcbnl_skb,
628 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]) {
634 ret = nla_put_u8(dcbnl_skb,
635 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]) {
641 ret = nla_put_u8(dcbnl_skb,
642 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]) {
648 ret = nla_put_u8(dcbnl_skb, DCB_TC_ATTR_PARAM_BW_PCT,
649 tc_pct);
650 if (ret)
651 goto err_param;
652 }
653 nla_nest_end(dcbnl_skb, param_nest);
654 }
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 }
676 ret = nla_put_u8(dcbnl_skb, i, tc_pct);
677
678 if (ret)
679 goto err_pg;
680 }
681
682 nla_nest_end(dcbnl_skb, pg_nest);
683
684 nlmsg_end(dcbnl_skb, nlh);
685
686 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
687 if (ret)
688 goto err;
689
690 return 0;
691
692err_param:
693 nla_nest_cancel(dcbnl_skb, param_nest);
694err_pg:
695 nla_nest_cancel(dcbnl_skb, pg_nest);
696nlmsg_failure:
697err:
Roel Kluin858eb712009-01-04 17:29:21 -0800698 kfree_skb(dcbnl_skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800699err_out:
700 ret = -EINVAL;
701 return ret;
702}
703
704static int dcbnl_pgtx_getcfg(struct net_device *netdev, struct nlattr **tb,
705 u32 pid, u32 seq, u16 flags)
706{
707 return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 0);
708}
709
710static int dcbnl_pgrx_getcfg(struct net_device *netdev, struct nlattr **tb,
711 u32 pid, u32 seq, u16 flags)
712{
713 return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 1);
714}
715
716static int dcbnl_setstate(struct net_device *netdev, struct nlattr **tb,
717 u32 pid, u32 seq, u16 flags)
718{
719 int ret = -EINVAL;
720 u8 value;
721
722 if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->setstate)
723 return ret;
724
725 value = nla_get_u8(tb[DCB_ATTR_STATE]);
726
Don Skidmore1486a612008-12-21 20:09:50 -0800727 ret = dcbnl_reply(netdev->dcbnl_ops->setstate(netdev, value),
728 RTM_SETDCB, DCB_CMD_SSTATE, DCB_ATTR_STATE,
Alexander Duyck2f90b862008-11-20 20:52:10 -0800729 pid, seq, flags);
730
731 return ret;
732}
733
734static int dcbnl_setpfccfg(struct net_device *netdev, struct nlattr **tb,
735 u32 pid, u32 seq, u16 flags)
736{
737 struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1];
738 int i;
739 int ret = -EINVAL;
740 u8 value;
741
742 if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->setpfccfg)
743 return ret;
744
745 ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
746 tb[DCB_ATTR_PFC_CFG],
747 dcbnl_pfc_up_nest);
748 if (ret)
749 goto err;
750
751 for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
752 if (data[i] == NULL)
753 continue;
754 value = nla_get_u8(data[i]);
755 netdev->dcbnl_ops->setpfccfg(netdev,
756 data[i]->nla_type - DCB_PFC_UP_ATTR_0, value);
757 }
758
759 ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SCFG, DCB_ATTR_PFC_CFG,
760 pid, seq, flags);
761err:
762 return ret;
763}
764
765static int dcbnl_setall(struct net_device *netdev, struct nlattr **tb,
766 u32 pid, u32 seq, u16 flags)
767{
768 int ret = -EINVAL;
769
770 if (!tb[DCB_ATTR_SET_ALL] || !netdev->dcbnl_ops->setall)
771 return ret;
772
773 ret = dcbnl_reply(netdev->dcbnl_ops->setall(netdev), RTM_SETDCB,
774 DCB_CMD_SET_ALL, DCB_ATTR_SET_ALL, pid, seq, flags);
775
776 return ret;
777}
778
779static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlattr **tb,
780 u32 pid, u32 seq, u16 flags, int dir)
781{
782 struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
783 struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
784 int ret = -EINVAL;
785 int i;
786 u8 pgid;
787 u8 up_map;
788 u8 prio;
789 u8 tc_pct;
790
791 if (!tb[DCB_ATTR_PG_CFG] ||
792 !netdev->dcbnl_ops->setpgtccfgtx ||
793 !netdev->dcbnl_ops->setpgtccfgrx ||
794 !netdev->dcbnl_ops->setpgbwgcfgtx ||
795 !netdev->dcbnl_ops->setpgbwgcfgrx)
796 return ret;
797
798 ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
799 tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
800 if (ret)
801 goto err;
802
803 for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
804 if (!pg_tb[i])
805 continue;
806
807 ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
808 pg_tb[i], dcbnl_tc_param_nest);
809 if (ret)
810 goto err;
811
812 pgid = DCB_ATTR_VALUE_UNDEFINED;
813 prio = DCB_ATTR_VALUE_UNDEFINED;
814 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
815 up_map = DCB_ATTR_VALUE_UNDEFINED;
816
817 if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO])
818 prio =
819 nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]);
820
821 if (param_tb[DCB_TC_ATTR_PARAM_PGID])
822 pgid = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_PGID]);
823
824 if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT])
825 tc_pct = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_BW_PCT]);
826
827 if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING])
828 up_map =
829 nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]);
830
831 /* dir: Tx = 0, Rx = 1 */
832 if (dir) {
833 /* Rx */
834 netdev->dcbnl_ops->setpgtccfgrx(netdev,
835 i - DCB_PG_ATTR_TC_0,
836 prio, pgid, tc_pct, up_map);
837 } else {
838 /* Tx */
839 netdev->dcbnl_ops->setpgtccfgtx(netdev,
840 i - DCB_PG_ATTR_TC_0,
841 prio, pgid, tc_pct, up_map);
842 }
843 }
844
845 for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
846 if (!pg_tb[i])
847 continue;
848
849 tc_pct = nla_get_u8(pg_tb[i]);
850
851 /* dir: Tx = 0, Rx = 1 */
852 if (dir) {
853 /* Rx */
854 netdev->dcbnl_ops->setpgbwgcfgrx(netdev,
855 i - DCB_PG_ATTR_BW_ID_0, tc_pct);
856 } else {
857 /* Tx */
858 netdev->dcbnl_ops->setpgbwgcfgtx(netdev,
859 i - DCB_PG_ATTR_BW_ID_0, tc_pct);
860 }
861 }
862
863 ret = dcbnl_reply(0, RTM_SETDCB,
864 (dir ? DCB_CMD_PGRX_SCFG : DCB_CMD_PGTX_SCFG),
865 DCB_ATTR_PG_CFG, pid, seq, flags);
866
867err:
868 return ret;
869}
870
871static int dcbnl_pgtx_setcfg(struct net_device *netdev, struct nlattr **tb,
872 u32 pid, u32 seq, u16 flags)
873{
874 return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 0);
875}
876
877static int dcbnl_pgrx_setcfg(struct net_device *netdev, struct nlattr **tb,
878 u32 pid, u32 seq, u16 flags)
879{
880 return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 1);
881}
882
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800883static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlattr **tb,
884 u32 pid, u32 seq, u16 flags)
885{
886 struct sk_buff *dcbnl_skb;
887 struct nlmsghdr *nlh;
888 struct dcbmsg *dcb;
889 struct nlattr *bcn_nest;
890 struct nlattr *bcn_tb[DCB_BCN_ATTR_MAX + 1];
891 u8 value_byte;
892 u32 value_integer;
893 int ret = -EINVAL;
894 bool getall = false;
895 int i;
896
897 if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->getbcnrp ||
898 !netdev->dcbnl_ops->getbcncfg)
899 return ret;
900
901 ret = nla_parse_nested(bcn_tb, DCB_BCN_ATTR_MAX,
902 tb[DCB_ATTR_BCN], dcbnl_bcn_nest);
903
904 if (ret)
905 goto err_out;
906
907 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
908 if (!dcbnl_skb)
909 goto err_out;
910
911 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
912
913 dcb = NLMSG_DATA(nlh);
914 dcb->dcb_family = AF_UNSPEC;
915 dcb->cmd = DCB_CMD_BCN_GCFG;
916
917 bcn_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_BCN);
918 if (!bcn_nest)
919 goto err;
920
921 if (bcn_tb[DCB_BCN_ATTR_ALL])
922 getall = true;
923
924 for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
925 if (!getall && !bcn_tb[i])
926 continue;
927
928 netdev->dcbnl_ops->getbcnrp(netdev, i - DCB_BCN_ATTR_RP_0,
929 &value_byte);
930 ret = nla_put_u8(dcbnl_skb, i, value_byte);
931 if (ret)
932 goto err_bcn;
933 }
934
Don Skidmoref4314e82008-12-21 20:10:29 -0800935 for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800936 if (!getall && !bcn_tb[i])
937 continue;
938
939 netdev->dcbnl_ops->getbcncfg(netdev, i,
940 &value_integer);
941 ret = nla_put_u32(dcbnl_skb, i, value_integer);
942 if (ret)
943 goto err_bcn;
944 }
945
946 nla_nest_end(dcbnl_skb, bcn_nest);
947
948 nlmsg_end(dcbnl_skb, nlh);
949
950 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
951 if (ret)
952 goto err;
953
954 return 0;
955
956err_bcn:
957 nla_nest_cancel(dcbnl_skb, bcn_nest);
958nlmsg_failure:
959err:
Roel Kluin858eb712009-01-04 17:29:21 -0800960 kfree_skb(dcbnl_skb);
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800961err_out:
962 ret = -EINVAL;
963 return ret;
964}
965
966static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlattr **tb,
967 u32 pid, u32 seq, u16 flags)
968{
969 struct nlattr *data[DCB_BCN_ATTR_MAX + 1];
970 int i;
971 int ret = -EINVAL;
972 u8 value_byte;
973 u32 value_int;
974
975 if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->setbcncfg
976 || !netdev->dcbnl_ops->setbcnrp)
977 return ret;
978
979 ret = nla_parse_nested(data, DCB_BCN_ATTR_MAX,
980 tb[DCB_ATTR_BCN],
981 dcbnl_pfc_up_nest);
982 if (ret)
983 goto err;
984
985 for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
986 if (data[i] == NULL)
987 continue;
988 value_byte = nla_get_u8(data[i]);
989 netdev->dcbnl_ops->setbcnrp(netdev,
990 data[i]->nla_type - DCB_BCN_ATTR_RP_0, value_byte);
991 }
992
Don Skidmoref4314e82008-12-21 20:10:29 -0800993 for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
Alexander Duyck859ee3c2008-11-20 21:10:23 -0800994 if (data[i] == NULL)
995 continue;
996 value_int = nla_get_u32(data[i]);
997 netdev->dcbnl_ops->setbcncfg(netdev,
998 i, value_int);
999 }
1000
1001 ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_BCN_SCFG, DCB_ATTR_BCN,
1002 pid, seq, flags);
1003err:
1004 return ret;
1005}
1006
Alexander Duyck2f90b862008-11-20 20:52:10 -08001007static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1008{
1009 struct net *net = sock_net(skb->sk);
1010 struct net_device *netdev;
1011 struct dcbmsg *dcb = (struct dcbmsg *)NLMSG_DATA(nlh);
1012 struct nlattr *tb[DCB_ATTR_MAX + 1];
1013 u32 pid = skb ? NETLINK_CB(skb).pid : 0;
1014 int ret = -EINVAL;
1015
1016 if (net != &init_net)
1017 return -EINVAL;
1018
1019 ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
1020 dcbnl_rtnl_policy);
1021 if (ret < 0)
1022 return ret;
1023
1024 if (!tb[DCB_ATTR_IFNAME])
1025 return -EINVAL;
1026
1027 netdev = dev_get_by_name(&init_net, nla_data(tb[DCB_ATTR_IFNAME]));
1028 if (!netdev)
1029 return -EINVAL;
1030
1031 if (!netdev->dcbnl_ops)
1032 goto errout;
1033
1034 switch (dcb->cmd) {
1035 case DCB_CMD_GSTATE:
1036 ret = dcbnl_getstate(netdev, tb, pid, nlh->nlmsg_seq,
1037 nlh->nlmsg_flags);
1038 goto out;
1039 case DCB_CMD_PFC_GCFG:
1040 ret = dcbnl_getpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
1041 nlh->nlmsg_flags);
1042 goto out;
1043 case DCB_CMD_GPERM_HWADDR:
1044 ret = dcbnl_getperm_hwaddr(netdev, tb, pid, nlh->nlmsg_seq,
1045 nlh->nlmsg_flags);
1046 goto out;
1047 case DCB_CMD_PGTX_GCFG:
1048 ret = dcbnl_pgtx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
1049 nlh->nlmsg_flags);
1050 goto out;
1051 case DCB_CMD_PGRX_GCFG:
1052 ret = dcbnl_pgrx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
1053 nlh->nlmsg_flags);
1054 goto out;
Alexander Duyck859ee3c2008-11-20 21:10:23 -08001055 case DCB_CMD_BCN_GCFG:
1056 ret = dcbnl_bcn_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
1057 nlh->nlmsg_flags);
1058 goto out;
Alexander Duyck2f90b862008-11-20 20:52:10 -08001059 case DCB_CMD_SSTATE:
1060 ret = dcbnl_setstate(netdev, tb, pid, nlh->nlmsg_seq,
1061 nlh->nlmsg_flags);
1062 goto out;
1063 case DCB_CMD_PFC_SCFG:
1064 ret = dcbnl_setpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
1065 nlh->nlmsg_flags);
1066 goto out;
1067
1068 case DCB_CMD_SET_ALL:
1069 ret = dcbnl_setall(netdev, tb, pid, nlh->nlmsg_seq,
1070 nlh->nlmsg_flags);
1071 goto out;
1072 case DCB_CMD_PGTX_SCFG:
1073 ret = dcbnl_pgtx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
1074 nlh->nlmsg_flags);
1075 goto out;
1076 case DCB_CMD_PGRX_SCFG:
1077 ret = dcbnl_pgrx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
1078 nlh->nlmsg_flags);
1079 goto out;
Alexander Duyck46132182008-11-20 21:05:08 -08001080 case DCB_CMD_GCAP:
1081 ret = dcbnl_getcap(netdev, tb, pid, nlh->nlmsg_seq,
1082 nlh->nlmsg_flags);
1083 goto out;
Alexander Duyck33dbabc2008-11-20 21:08:19 -08001084 case DCB_CMD_GNUMTCS:
1085 ret = dcbnl_getnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
1086 nlh->nlmsg_flags);
1087 goto out;
1088 case DCB_CMD_SNUMTCS:
1089 ret = dcbnl_setnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
1090 nlh->nlmsg_flags);
1091 goto out;
Alexander Duyck0eb3aa92008-11-20 21:09:23 -08001092 case DCB_CMD_PFC_GSTATE:
1093 ret = dcbnl_getpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
1094 nlh->nlmsg_flags);
1095 goto out;
1096 case DCB_CMD_PFC_SSTATE:
1097 ret = dcbnl_setpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
1098 nlh->nlmsg_flags);
1099 goto out;
Alexander Duyck859ee3c2008-11-20 21:10:23 -08001100 case DCB_CMD_BCN_SCFG:
1101 ret = dcbnl_bcn_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
1102 nlh->nlmsg_flags);
1103 goto out;
Alexander Duyck2f90b862008-11-20 20:52:10 -08001104 default:
1105 goto errout;
1106 }
1107errout:
1108 ret = -EINVAL;
1109out:
1110 dev_put(netdev);
1111 return ret;
1112}
1113
1114static int __init dcbnl_init(void)
1115{
1116 rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL);
1117 rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL);
1118
1119 return 0;
1120}
1121module_init(dcbnl_init);
1122
1123static void __exit dcbnl_exit(void)
1124{
1125 rtnl_unregister(PF_UNSPEC, RTM_GETDCB);
1126 rtnl_unregister(PF_UNSPEC, RTM_SETDCB);
1127}
1128module_exit(dcbnl_exit);
1129
1130