2 * Copyright (c) 2008, Intel Corporation.
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.
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
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.
17 * Author: Lucy Liu <lucy.liu@intel.com>
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>
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:
34 * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a
35 * framework for assigning bandwidth guarantees to traffic classes.
37 * Priority-based Flow Control (PFC) - provides a flow control mechanism which
38 * can work independently for each 802.1p priority.
40 * Congestion Notification - provides a mechanism for end-to-end congestion
41 * control for protocols which do not have built-in congestion management.
43 * More information about the emerging standards for these Ethernet features
44 * can be found at: http://www.ieee802.org/1/pages/dcbridges.html
46 * This file implements an rtnetlink interface to allow configuration of DCB
47 * features for capable devices.
50 MODULE_AUTHOR("Lucy Liu, <lucy.liu@intel.com>");
51 MODULE_DESCRIPTION("Data Center Bridging generic netlink interface");
52 MODULE_LICENSE("GPL");
54 /**************** DCB attribute policies *************************************/
56 /* DCB netlink attributes policy */
57 static struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = {
58 [DCB_ATTR_IFNAME] = {.type = NLA_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},
63 [DCB_ATTR_PERM_HWADDR] = {.type = NLA_FLAG},
64 [DCB_ATTR_CAP] = {.type = NLA_NESTED},
67 /* DCB priority flow control to User Priority nested attributes */
68 static struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = {
69 [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8},
70 [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8},
71 [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8},
72 [DCB_PFC_UP_ATTR_3] = {.type = NLA_U8},
73 [DCB_PFC_UP_ATTR_4] = {.type = NLA_U8},
74 [DCB_PFC_UP_ATTR_5] = {.type = NLA_U8},
75 [DCB_PFC_UP_ATTR_6] = {.type = NLA_U8},
76 [DCB_PFC_UP_ATTR_7] = {.type = NLA_U8},
77 [DCB_PFC_UP_ATTR_ALL] = {.type = NLA_FLAG},
80 /* DCB priority grouping nested attributes */
81 static struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = {
82 [DCB_PG_ATTR_TC_0] = {.type = NLA_NESTED},
83 [DCB_PG_ATTR_TC_1] = {.type = NLA_NESTED},
84 [DCB_PG_ATTR_TC_2] = {.type = NLA_NESTED},
85 [DCB_PG_ATTR_TC_3] = {.type = NLA_NESTED},
86 [DCB_PG_ATTR_TC_4] = {.type = NLA_NESTED},
87 [DCB_PG_ATTR_TC_5] = {.type = NLA_NESTED},
88 [DCB_PG_ATTR_TC_6] = {.type = NLA_NESTED},
89 [DCB_PG_ATTR_TC_7] = {.type = NLA_NESTED},
90 [DCB_PG_ATTR_TC_ALL] = {.type = NLA_NESTED},
91 [DCB_PG_ATTR_BW_ID_0] = {.type = NLA_U8},
92 [DCB_PG_ATTR_BW_ID_1] = {.type = NLA_U8},
93 [DCB_PG_ATTR_BW_ID_2] = {.type = NLA_U8},
94 [DCB_PG_ATTR_BW_ID_3] = {.type = NLA_U8},
95 [DCB_PG_ATTR_BW_ID_4] = {.type = NLA_U8},
96 [DCB_PG_ATTR_BW_ID_5] = {.type = NLA_U8},
97 [DCB_PG_ATTR_BW_ID_6] = {.type = NLA_U8},
98 [DCB_PG_ATTR_BW_ID_7] = {.type = NLA_U8},
99 [DCB_PG_ATTR_BW_ID_ALL] = {.type = NLA_FLAG},
102 /* DCB traffic class nested attributes. */
103 static struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = {
104 [DCB_TC_ATTR_PARAM_PGID] = {.type = NLA_U8},
105 [DCB_TC_ATTR_PARAM_UP_MAPPING] = {.type = NLA_U8},
106 [DCB_TC_ATTR_PARAM_STRICT_PRIO] = {.type = NLA_U8},
107 [DCB_TC_ATTR_PARAM_BW_PCT] = {.type = NLA_U8},
108 [DCB_TC_ATTR_PARAM_ALL] = {.type = NLA_FLAG},
111 /* DCB capabilities nested attributes. */
112 static struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = {
113 [DCB_CAP_ATTR_ALL] = {.type = NLA_FLAG},
114 [DCB_CAP_ATTR_PG] = {.type = NLA_U8},
115 [DCB_CAP_ATTR_PFC] = {.type = NLA_U8},
116 [DCB_CAP_ATTR_UP2TC] = {.type = NLA_U8},
117 [DCB_CAP_ATTR_PG_TCS] = {.type = NLA_U8},
118 [DCB_CAP_ATTR_PFC_TCS] = {.type = NLA_U8},
119 [DCB_CAP_ATTR_GSP] = {.type = NLA_U8},
120 [DCB_CAP_ATTR_BCN] = {.type = NLA_U8},
123 /* DCB capabilities nested attributes. */
124 static struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = {
125 [DCB_NUMTCS_ATTR_ALL] = {.type = NLA_FLAG},
126 [DCB_NUMTCS_ATTR_PG] = {.type = NLA_U8},
127 [DCB_NUMTCS_ATTR_PFC] = {.type = NLA_U8},
130 /* standard netlink reply call */
131 static int dcbnl_reply(u8 value, u8 event, u8 cmd, u8 attr, u32 pid,
134 struct sk_buff *dcbnl_skb;
136 struct nlmsghdr *nlh;
139 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
143 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, event, sizeof(*dcb), flags);
145 dcb = NLMSG_DATA(nlh);
146 dcb->dcb_family = AF_UNSPEC;
150 ret = nla_put_u8(dcbnl_skb, attr, value);
154 /* end the message, assign the nlmsg_len. */
155 nlmsg_end(dcbnl_skb, nlh);
156 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
167 static int dcbnl_getstate(struct net_device *netdev, struct nlattr **tb,
168 u32 pid, u32 seq, u16 flags)
172 /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
173 if (!netdev->dcbnl_ops->getstate)
176 ret = dcbnl_reply(netdev->dcbnl_ops->getstate(netdev), RTM_GETDCB,
177 DCB_CMD_GSTATE, DCB_ATTR_STATE, pid, seq, flags);
182 static int dcbnl_getpfccfg(struct net_device *netdev, struct nlattr **tb,
183 u32 pid, u32 seq, u16 flags)
185 struct sk_buff *dcbnl_skb;
186 struct nlmsghdr *nlh;
188 struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1], *nest;
194 if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->getpfccfg)
197 ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
198 tb[DCB_ATTR_PFC_CFG],
203 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
207 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
209 dcb = NLMSG_DATA(nlh);
210 dcb->dcb_family = AF_UNSPEC;
211 dcb->cmd = DCB_CMD_PFC_GCFG;
213 nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PFC_CFG);
217 if (data[DCB_PFC_UP_ATTR_ALL])
220 for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
221 if (!getall && !data[i])
224 netdev->dcbnl_ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0,
226 ret = nla_put_u8(dcbnl_skb, i, value);
229 nla_nest_cancel(dcbnl_skb, nest);
233 nla_nest_end(dcbnl_skb, nest);
235 nlmsg_end(dcbnl_skb, nlh);
237 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
249 static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlattr **tb,
250 u32 pid, u32 seq, u16 flags)
252 struct sk_buff *dcbnl_skb;
253 struct nlmsghdr *nlh;
255 u8 perm_addr[MAX_ADDR_LEN];
258 if (!netdev->dcbnl_ops->getpermhwaddr)
261 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
265 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
267 dcb = NLMSG_DATA(nlh);
268 dcb->dcb_family = AF_UNSPEC;
269 dcb->cmd = DCB_CMD_GPERM_HWADDR;
271 netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
273 ret = nla_put(dcbnl_skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr),
276 nlmsg_end(dcbnl_skb, nlh);
278 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
291 static int dcbnl_getcap(struct net_device *netdev, struct nlattr **tb,
292 u32 pid, u32 seq, u16 flags)
294 struct sk_buff *dcbnl_skb;
295 struct nlmsghdr *nlh;
297 struct nlattr *data[DCB_CAP_ATTR_MAX + 1], *nest;
303 if (!tb[DCB_ATTR_CAP] || !netdev->dcbnl_ops->getcap)
306 ret = nla_parse_nested(data, DCB_CAP_ATTR_MAX, tb[DCB_ATTR_CAP],
311 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
315 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
317 dcb = NLMSG_DATA(nlh);
318 dcb->dcb_family = AF_UNSPEC;
319 dcb->cmd = DCB_CMD_GCAP;
321 nest = nla_nest_start(dcbnl_skb, DCB_ATTR_CAP);
325 if (data[DCB_CAP_ATTR_ALL])
328 for (i = DCB_CAP_ATTR_ALL+1; i <= DCB_CAP_ATTR_MAX; i++) {
329 if (!getall && !data[i])
332 if (!netdev->dcbnl_ops->getcap(netdev, i, &value)) {
333 ret = nla_put_u8(dcbnl_skb, i, value);
336 nla_nest_cancel(dcbnl_skb, nest);
341 nla_nest_end(dcbnl_skb, nest);
343 nlmsg_end(dcbnl_skb, nlh);
345 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
357 static int dcbnl_getnumtcs(struct net_device *netdev, struct nlattr **tb,
358 u32 pid, u32 seq, u16 flags)
360 struct sk_buff *dcbnl_skb;
361 struct nlmsghdr *nlh;
363 struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1], *nest;
369 if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->getnumtcs)
372 ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
379 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
385 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
387 dcb = NLMSG_DATA(nlh);
388 dcb->dcb_family = AF_UNSPEC;
389 dcb->cmd = DCB_CMD_GNUMTCS;
391 nest = nla_nest_start(dcbnl_skb, DCB_ATTR_NUMTCS);
397 if (data[DCB_NUMTCS_ATTR_ALL])
400 for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
401 if (!getall && !data[i])
404 ret = netdev->dcbnl_ops->getnumtcs(netdev, i, &value);
406 ret = nla_put_u8(dcbnl_skb, i, value);
409 nla_nest_cancel(dcbnl_skb, nest);
417 nla_nest_end(dcbnl_skb, nest);
419 nlmsg_end(dcbnl_skb, nlh);
421 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
435 static int dcbnl_setnumtcs(struct net_device *netdev, struct nlattr **tb,
436 u32 pid, u32 seq, u16 flags)
438 struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1];
443 if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->setstate)
446 ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
454 for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
458 value = nla_get_u8(data[i]);
460 ret = netdev->dcbnl_ops->setnumtcs(netdev, i, value);
467 ret = dcbnl_reply(!!ret, RTM_SETDCB, DCB_CMD_SNUMTCS,
468 DCB_ATTR_NUMTCS, pid, seq, flags);
474 static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlattr **tb,
475 u32 pid, u32 seq, u16 flags, int dir)
477 struct sk_buff *dcbnl_skb;
478 struct nlmsghdr *nlh;
480 struct nlattr *pg_nest, *param_nest, *data;
481 struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
482 struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
483 u8 prio, pgid, tc_pct, up_map;
488 if (!tb[DCB_ATTR_PG_CFG] ||
489 !netdev->dcbnl_ops->getpgtccfgtx ||
490 !netdev->dcbnl_ops->getpgtccfgrx ||
491 !netdev->dcbnl_ops->getpgbwgcfgtx ||
492 !netdev->dcbnl_ops->getpgbwgcfgrx)
495 ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
496 tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
501 dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
505 nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
507 dcb = NLMSG_DATA(nlh);
508 dcb->dcb_family = AF_UNSPEC;
509 dcb->cmd = (dir) ? DCB_CMD_PGRX_GCFG : DCB_CMD_PGTX_GCFG;
511 pg_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PG_CFG);
515 if (pg_tb[DCB_PG_ATTR_TC_ALL])
518 for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
519 if (!getall && !pg_tb[i])
522 if (pg_tb[DCB_PG_ATTR_TC_ALL])
523 data = pg_tb[DCB_PG_ATTR_TC_ALL];
526 ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
527 data, dcbnl_tc_param_nest);
531 param_nest = nla_nest_start(dcbnl_skb, i);
535 pgid = DCB_ATTR_VALUE_UNDEFINED;
536 prio = DCB_ATTR_VALUE_UNDEFINED;
537 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
538 up_map = DCB_ATTR_VALUE_UNDEFINED;
542 netdev->dcbnl_ops->getpgtccfgrx(netdev,
543 i - DCB_PG_ATTR_TC_0, &prio,
544 &pgid, &tc_pct, &up_map);
547 netdev->dcbnl_ops->getpgtccfgtx(netdev,
548 i - DCB_PG_ATTR_TC_0, &prio,
549 &pgid, &tc_pct, &up_map);
552 if (param_tb[DCB_TC_ATTR_PARAM_PGID] ||
553 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
554 ret = nla_put_u8(dcbnl_skb,
555 DCB_TC_ATTR_PARAM_PGID, pgid);
559 if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING] ||
560 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
561 ret = nla_put_u8(dcbnl_skb,
562 DCB_TC_ATTR_PARAM_UP_MAPPING, up_map);
566 if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO] ||
567 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
568 ret = nla_put_u8(dcbnl_skb,
569 DCB_TC_ATTR_PARAM_STRICT_PRIO, prio);
573 if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT] ||
574 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
575 ret = nla_put_u8(dcbnl_skb, DCB_TC_ATTR_PARAM_BW_PCT,
580 nla_nest_end(dcbnl_skb, param_nest);
583 if (pg_tb[DCB_PG_ATTR_BW_ID_ALL])
588 for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
589 if (!getall && !pg_tb[i])
592 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
596 netdev->dcbnl_ops->getpgbwgcfgrx(netdev,
597 i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
600 netdev->dcbnl_ops->getpgbwgcfgtx(netdev,
601 i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
603 ret = nla_put_u8(dcbnl_skb, i, tc_pct);
609 nla_nest_end(dcbnl_skb, pg_nest);
611 nlmsg_end(dcbnl_skb, nlh);
613 ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
620 nla_nest_cancel(dcbnl_skb, param_nest);
622 nla_nest_cancel(dcbnl_skb, pg_nest);
631 static int dcbnl_pgtx_getcfg(struct net_device *netdev, struct nlattr **tb,
632 u32 pid, u32 seq, u16 flags)
634 return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 0);
637 static int dcbnl_pgrx_getcfg(struct net_device *netdev, struct nlattr **tb,
638 u32 pid, u32 seq, u16 flags)
640 return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 1);
643 static int dcbnl_setstate(struct net_device *netdev, struct nlattr **tb,
644 u32 pid, u32 seq, u16 flags)
649 if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->setstate)
652 value = nla_get_u8(tb[DCB_ATTR_STATE]);
654 netdev->dcbnl_ops->setstate(netdev, value);
656 ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_SSTATE, DCB_ATTR_STATE,
662 static int dcbnl_setpfccfg(struct net_device *netdev, struct nlattr **tb,
663 u32 pid, u32 seq, u16 flags)
665 struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1];
670 if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->setpfccfg)
673 ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
674 tb[DCB_ATTR_PFC_CFG],
679 for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
682 value = nla_get_u8(data[i]);
683 netdev->dcbnl_ops->setpfccfg(netdev,
684 data[i]->nla_type - DCB_PFC_UP_ATTR_0, value);
687 ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SCFG, DCB_ATTR_PFC_CFG,
693 static int dcbnl_setall(struct net_device *netdev, struct nlattr **tb,
694 u32 pid, u32 seq, u16 flags)
698 if (!tb[DCB_ATTR_SET_ALL] || !netdev->dcbnl_ops->setall)
701 ret = dcbnl_reply(netdev->dcbnl_ops->setall(netdev), RTM_SETDCB,
702 DCB_CMD_SET_ALL, DCB_ATTR_SET_ALL, pid, seq, flags);
707 static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlattr **tb,
708 u32 pid, u32 seq, u16 flags, int dir)
710 struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
711 struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
719 if (!tb[DCB_ATTR_PG_CFG] ||
720 !netdev->dcbnl_ops->setpgtccfgtx ||
721 !netdev->dcbnl_ops->setpgtccfgrx ||
722 !netdev->dcbnl_ops->setpgbwgcfgtx ||
723 !netdev->dcbnl_ops->setpgbwgcfgrx)
726 ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
727 tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
731 for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
735 ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
736 pg_tb[i], dcbnl_tc_param_nest);
740 pgid = DCB_ATTR_VALUE_UNDEFINED;
741 prio = DCB_ATTR_VALUE_UNDEFINED;
742 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
743 up_map = DCB_ATTR_VALUE_UNDEFINED;
745 if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO])
747 nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]);
749 if (param_tb[DCB_TC_ATTR_PARAM_PGID])
750 pgid = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_PGID]);
752 if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT])
753 tc_pct = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_BW_PCT]);
755 if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING])
757 nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]);
759 /* dir: Tx = 0, Rx = 1 */
762 netdev->dcbnl_ops->setpgtccfgrx(netdev,
763 i - DCB_PG_ATTR_TC_0,
764 prio, pgid, tc_pct, up_map);
767 netdev->dcbnl_ops->setpgtccfgtx(netdev,
768 i - DCB_PG_ATTR_TC_0,
769 prio, pgid, tc_pct, up_map);
773 for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
777 tc_pct = nla_get_u8(pg_tb[i]);
779 /* dir: Tx = 0, Rx = 1 */
782 netdev->dcbnl_ops->setpgbwgcfgrx(netdev,
783 i - DCB_PG_ATTR_BW_ID_0, tc_pct);
786 netdev->dcbnl_ops->setpgbwgcfgtx(netdev,
787 i - DCB_PG_ATTR_BW_ID_0, tc_pct);
791 ret = dcbnl_reply(0, RTM_SETDCB,
792 (dir ? DCB_CMD_PGRX_SCFG : DCB_CMD_PGTX_SCFG),
793 DCB_ATTR_PG_CFG, pid, seq, flags);
799 static int dcbnl_pgtx_setcfg(struct net_device *netdev, struct nlattr **tb,
800 u32 pid, u32 seq, u16 flags)
802 return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 0);
805 static int dcbnl_pgrx_setcfg(struct net_device *netdev, struct nlattr **tb,
806 u32 pid, u32 seq, u16 flags)
808 return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 1);
811 static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
813 struct net *net = sock_net(skb->sk);
814 struct net_device *netdev;
815 struct dcbmsg *dcb = (struct dcbmsg *)NLMSG_DATA(nlh);
816 struct nlattr *tb[DCB_ATTR_MAX + 1];
817 u32 pid = skb ? NETLINK_CB(skb).pid : 0;
820 if (net != &init_net)
823 ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
828 if (!tb[DCB_ATTR_IFNAME])
831 netdev = dev_get_by_name(&init_net, nla_data(tb[DCB_ATTR_IFNAME]));
835 if (!netdev->dcbnl_ops)
840 ret = dcbnl_getstate(netdev, tb, pid, nlh->nlmsg_seq,
843 case DCB_CMD_PFC_GCFG:
844 ret = dcbnl_getpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
847 case DCB_CMD_GPERM_HWADDR:
848 ret = dcbnl_getperm_hwaddr(netdev, tb, pid, nlh->nlmsg_seq,
851 case DCB_CMD_PGTX_GCFG:
852 ret = dcbnl_pgtx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
855 case DCB_CMD_PGRX_GCFG:
856 ret = dcbnl_pgrx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
860 ret = dcbnl_setstate(netdev, tb, pid, nlh->nlmsg_seq,
863 case DCB_CMD_PFC_SCFG:
864 ret = dcbnl_setpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
868 case DCB_CMD_SET_ALL:
869 ret = dcbnl_setall(netdev, tb, pid, nlh->nlmsg_seq,
872 case DCB_CMD_PGTX_SCFG:
873 ret = dcbnl_pgtx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
876 case DCB_CMD_PGRX_SCFG:
877 ret = dcbnl_pgrx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
881 ret = dcbnl_getcap(netdev, tb, pid, nlh->nlmsg_seq,
884 case DCB_CMD_GNUMTCS:
885 ret = dcbnl_getnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
888 case DCB_CMD_SNUMTCS:
889 ret = dcbnl_setnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
902 static int __init dcbnl_init(void)
904 rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL);
905 rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL);
909 module_init(dcbnl_init);
911 static void __exit dcbnl_exit(void)
913 rtnl_unregister(PF_UNSPEC, RTM_GETDCB);
914 rtnl_unregister(PF_UNSPEC, RTM_SETDCB);
916 module_exit(dcbnl_exit);