2 * Copyright (c) 2008-2011, 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, see <http://www.gnu.org/licenses/>.
16 * Description: Data Center Bridging netlink interface
20 #include <linux/netdevice.h>
21 #include <linux/netlink.h>
22 #include <linux/slab.h>
23 #include <net/netlink.h>
24 #include <net/rtnetlink.h>
25 #include <linux/dcbnl.h>
26 #include <net/dcbevent.h>
27 #include <linux/rtnetlink.h>
28 #include <linux/init.h>
31 /* Data Center Bridging (DCB) is a collection of Ethernet enhancements
32 * intended to allow network traffic with differing requirements
33 * (highly reliable, no drops vs. best effort vs. low latency) to operate
34 * and co-exist on Ethernet. Current DCB features are:
36 * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a
37 * framework for assigning bandwidth guarantees to traffic classes.
39 * Priority-based Flow Control (PFC) - provides a flow control mechanism which
40 * can work independently for each 802.1p priority.
42 * Congestion Notification - provides a mechanism for end-to-end congestion
43 * control for protocols which do not have built-in congestion management.
45 * More information about the emerging standards for these Ethernet features
46 * can be found at: http://www.ieee802.org/1/pages/dcbridges.html
48 * This file implements an rtnetlink interface to allow configuration of DCB
49 * features for capable devices.
52 /**************** DCB attribute policies *************************************/
54 /* DCB netlink attributes policy */
55 static const struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = {
56 [DCB_ATTR_IFNAME] = {.type = NLA_NUL_STRING, .len = IFNAMSIZ - 1},
57 [DCB_ATTR_STATE] = {.type = NLA_U8},
58 [DCB_ATTR_PFC_CFG] = {.type = NLA_NESTED},
59 [DCB_ATTR_PG_CFG] = {.type = NLA_NESTED},
60 [DCB_ATTR_SET_ALL] = {.type = NLA_U8},
61 [DCB_ATTR_PERM_HWADDR] = {.type = NLA_FLAG},
62 [DCB_ATTR_CAP] = {.type = NLA_NESTED},
63 [DCB_ATTR_PFC_STATE] = {.type = NLA_U8},
64 [DCB_ATTR_BCN] = {.type = NLA_NESTED},
65 [DCB_ATTR_APP] = {.type = NLA_NESTED},
66 [DCB_ATTR_IEEE] = {.type = NLA_NESTED},
67 [DCB_ATTR_DCBX] = {.type = NLA_U8},
68 [DCB_ATTR_FEATCFG] = {.type = NLA_NESTED},
71 /* DCB priority flow control to User Priority nested attributes */
72 static const struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = {
73 [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8},
74 [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8},
75 [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8},
76 [DCB_PFC_UP_ATTR_3] = {.type = NLA_U8},
77 [DCB_PFC_UP_ATTR_4] = {.type = NLA_U8},
78 [DCB_PFC_UP_ATTR_5] = {.type = NLA_U8},
79 [DCB_PFC_UP_ATTR_6] = {.type = NLA_U8},
80 [DCB_PFC_UP_ATTR_7] = {.type = NLA_U8},
81 [DCB_PFC_UP_ATTR_ALL] = {.type = NLA_FLAG},
84 /* DCB priority grouping nested attributes */
85 static const struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = {
86 [DCB_PG_ATTR_TC_0] = {.type = NLA_NESTED},
87 [DCB_PG_ATTR_TC_1] = {.type = NLA_NESTED},
88 [DCB_PG_ATTR_TC_2] = {.type = NLA_NESTED},
89 [DCB_PG_ATTR_TC_3] = {.type = NLA_NESTED},
90 [DCB_PG_ATTR_TC_4] = {.type = NLA_NESTED},
91 [DCB_PG_ATTR_TC_5] = {.type = NLA_NESTED},
92 [DCB_PG_ATTR_TC_6] = {.type = NLA_NESTED},
93 [DCB_PG_ATTR_TC_7] = {.type = NLA_NESTED},
94 [DCB_PG_ATTR_TC_ALL] = {.type = NLA_NESTED},
95 [DCB_PG_ATTR_BW_ID_0] = {.type = NLA_U8},
96 [DCB_PG_ATTR_BW_ID_1] = {.type = NLA_U8},
97 [DCB_PG_ATTR_BW_ID_2] = {.type = NLA_U8},
98 [DCB_PG_ATTR_BW_ID_3] = {.type = NLA_U8},
99 [DCB_PG_ATTR_BW_ID_4] = {.type = NLA_U8},
100 [DCB_PG_ATTR_BW_ID_5] = {.type = NLA_U8},
101 [DCB_PG_ATTR_BW_ID_6] = {.type = NLA_U8},
102 [DCB_PG_ATTR_BW_ID_7] = {.type = NLA_U8},
103 [DCB_PG_ATTR_BW_ID_ALL] = {.type = NLA_FLAG},
106 /* DCB traffic class nested attributes. */
107 static const struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = {
108 [DCB_TC_ATTR_PARAM_PGID] = {.type = NLA_U8},
109 [DCB_TC_ATTR_PARAM_UP_MAPPING] = {.type = NLA_U8},
110 [DCB_TC_ATTR_PARAM_STRICT_PRIO] = {.type = NLA_U8},
111 [DCB_TC_ATTR_PARAM_BW_PCT] = {.type = NLA_U8},
112 [DCB_TC_ATTR_PARAM_ALL] = {.type = NLA_FLAG},
115 /* DCB capabilities nested attributes. */
116 static const struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = {
117 [DCB_CAP_ATTR_ALL] = {.type = NLA_FLAG},
118 [DCB_CAP_ATTR_PG] = {.type = NLA_U8},
119 [DCB_CAP_ATTR_PFC] = {.type = NLA_U8},
120 [DCB_CAP_ATTR_UP2TC] = {.type = NLA_U8},
121 [DCB_CAP_ATTR_PG_TCS] = {.type = NLA_U8},
122 [DCB_CAP_ATTR_PFC_TCS] = {.type = NLA_U8},
123 [DCB_CAP_ATTR_GSP] = {.type = NLA_U8},
124 [DCB_CAP_ATTR_BCN] = {.type = NLA_U8},
125 [DCB_CAP_ATTR_DCBX] = {.type = NLA_U8},
128 /* DCB capabilities nested attributes. */
129 static const struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = {
130 [DCB_NUMTCS_ATTR_ALL] = {.type = NLA_FLAG},
131 [DCB_NUMTCS_ATTR_PG] = {.type = NLA_U8},
132 [DCB_NUMTCS_ATTR_PFC] = {.type = NLA_U8},
135 /* DCB BCN nested attributes. */
136 static const struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = {
137 [DCB_BCN_ATTR_RP_0] = {.type = NLA_U8},
138 [DCB_BCN_ATTR_RP_1] = {.type = NLA_U8},
139 [DCB_BCN_ATTR_RP_2] = {.type = NLA_U8},
140 [DCB_BCN_ATTR_RP_3] = {.type = NLA_U8},
141 [DCB_BCN_ATTR_RP_4] = {.type = NLA_U8},
142 [DCB_BCN_ATTR_RP_5] = {.type = NLA_U8},
143 [DCB_BCN_ATTR_RP_6] = {.type = NLA_U8},
144 [DCB_BCN_ATTR_RP_7] = {.type = NLA_U8},
145 [DCB_BCN_ATTR_RP_ALL] = {.type = NLA_FLAG},
146 [DCB_BCN_ATTR_BCNA_0] = {.type = NLA_U32},
147 [DCB_BCN_ATTR_BCNA_1] = {.type = NLA_U32},
148 [DCB_BCN_ATTR_ALPHA] = {.type = NLA_U32},
149 [DCB_BCN_ATTR_BETA] = {.type = NLA_U32},
150 [DCB_BCN_ATTR_GD] = {.type = NLA_U32},
151 [DCB_BCN_ATTR_GI] = {.type = NLA_U32},
152 [DCB_BCN_ATTR_TMAX] = {.type = NLA_U32},
153 [DCB_BCN_ATTR_TD] = {.type = NLA_U32},
154 [DCB_BCN_ATTR_RMIN] = {.type = NLA_U32},
155 [DCB_BCN_ATTR_W] = {.type = NLA_U32},
156 [DCB_BCN_ATTR_RD] = {.type = NLA_U32},
157 [DCB_BCN_ATTR_RU] = {.type = NLA_U32},
158 [DCB_BCN_ATTR_WRTT] = {.type = NLA_U32},
159 [DCB_BCN_ATTR_RI] = {.type = NLA_U32},
160 [DCB_BCN_ATTR_C] = {.type = NLA_U32},
161 [DCB_BCN_ATTR_ALL] = {.type = NLA_FLAG},
164 /* DCB APP nested attributes. */
165 static const struct nla_policy dcbnl_app_nest[DCB_APP_ATTR_MAX + 1] = {
166 [DCB_APP_ATTR_IDTYPE] = {.type = NLA_U8},
167 [DCB_APP_ATTR_ID] = {.type = NLA_U16},
168 [DCB_APP_ATTR_PRIORITY] = {.type = NLA_U8},
171 /* IEEE 802.1Qaz nested attributes. */
172 static const struct nla_policy dcbnl_ieee_policy[DCB_ATTR_IEEE_MAX + 1] = {
173 [DCB_ATTR_IEEE_ETS] = {.len = sizeof(struct ieee_ets)},
174 [DCB_ATTR_IEEE_PFC] = {.len = sizeof(struct ieee_pfc)},
175 [DCB_ATTR_IEEE_APP_TABLE] = {.type = NLA_NESTED},
176 [DCB_ATTR_IEEE_MAXRATE] = {.len = sizeof(struct ieee_maxrate)},
177 [DCB_ATTR_IEEE_QCN] = {.len = sizeof(struct ieee_qcn)},
178 [DCB_ATTR_IEEE_QCN_STATS] = {.len = sizeof(struct ieee_qcn_stats)},
179 [DCB_ATTR_DCB_BUFFER] = {.len = sizeof(struct dcbnl_buffer)},
182 /* DCB number of traffic classes nested attributes. */
183 static const struct nla_policy dcbnl_featcfg_nest[DCB_FEATCFG_ATTR_MAX + 1] = {
184 [DCB_FEATCFG_ATTR_ALL] = {.type = NLA_FLAG},
185 [DCB_FEATCFG_ATTR_PG] = {.type = NLA_U8},
186 [DCB_FEATCFG_ATTR_PFC] = {.type = NLA_U8},
187 [DCB_FEATCFG_ATTR_APP] = {.type = NLA_U8},
190 static LIST_HEAD(dcb_app_list);
191 static DEFINE_SPINLOCK(dcb_lock);
193 static struct sk_buff *dcbnl_newmsg(int type, u8 cmd, u32 port, u32 seq,
194 u32 flags, struct nlmsghdr **nlhp)
198 struct nlmsghdr *nlh;
200 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
204 nlh = nlmsg_put(skb, port, seq, type, sizeof(*dcb), flags);
207 dcb = nlmsg_data(nlh);
208 dcb->dcb_family = AF_UNSPEC;
218 static int dcbnl_getstate(struct net_device *netdev, struct nlmsghdr *nlh,
219 u32 seq, struct nlattr **tb, struct sk_buff *skb)
221 /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
222 if (!netdev->dcbnl_ops->getstate)
225 return nla_put_u8(skb, DCB_ATTR_STATE,
226 netdev->dcbnl_ops->getstate(netdev));
229 static int dcbnl_getpfccfg(struct net_device *netdev, struct nlmsghdr *nlh,
230 u32 seq, struct nlattr **tb, struct sk_buff *skb)
232 struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1], *nest;
238 if (!tb[DCB_ATTR_PFC_CFG])
241 if (!netdev->dcbnl_ops->getpfccfg)
244 ret = nla_parse_nested_deprecated(data, DCB_PFC_UP_ATTR_MAX,
245 tb[DCB_ATTR_PFC_CFG],
246 dcbnl_pfc_up_nest, NULL);
250 nest = nla_nest_start_noflag(skb, DCB_ATTR_PFC_CFG);
254 if (data[DCB_PFC_UP_ATTR_ALL])
257 for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
258 if (!getall && !data[i])
261 netdev->dcbnl_ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0,
263 ret = nla_put_u8(skb, i, value);
265 nla_nest_cancel(skb, nest);
269 nla_nest_end(skb, nest);
274 static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlmsghdr *nlh,
275 u32 seq, struct nlattr **tb, struct sk_buff *skb)
277 u8 perm_addr[MAX_ADDR_LEN];
279 if (!netdev->dcbnl_ops->getpermhwaddr)
282 memset(perm_addr, 0, sizeof(perm_addr));
283 netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
285 return nla_put(skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr), perm_addr);
288 static int dcbnl_getcap(struct net_device *netdev, struct nlmsghdr *nlh,
289 u32 seq, struct nlattr **tb, struct sk_buff *skb)
291 struct nlattr *data[DCB_CAP_ATTR_MAX + 1], *nest;
297 if (!tb[DCB_ATTR_CAP])
300 if (!netdev->dcbnl_ops->getcap)
303 ret = nla_parse_nested_deprecated(data, DCB_CAP_ATTR_MAX,
304 tb[DCB_ATTR_CAP], dcbnl_cap_nest,
309 nest = nla_nest_start_noflag(skb, DCB_ATTR_CAP);
313 if (data[DCB_CAP_ATTR_ALL])
316 for (i = DCB_CAP_ATTR_ALL+1; i <= DCB_CAP_ATTR_MAX; i++) {
317 if (!getall && !data[i])
320 if (!netdev->dcbnl_ops->getcap(netdev, i, &value)) {
321 ret = nla_put_u8(skb, i, value);
323 nla_nest_cancel(skb, nest);
328 nla_nest_end(skb, nest);
333 static int dcbnl_getnumtcs(struct net_device *netdev, struct nlmsghdr *nlh,
334 u32 seq, struct nlattr **tb, struct sk_buff *skb)
336 struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1], *nest;
342 if (!tb[DCB_ATTR_NUMTCS])
345 if (!netdev->dcbnl_ops->getnumtcs)
348 ret = nla_parse_nested_deprecated(data, DCB_NUMTCS_ATTR_MAX,
350 dcbnl_numtcs_nest, NULL);
354 nest = nla_nest_start_noflag(skb, DCB_ATTR_NUMTCS);
358 if (data[DCB_NUMTCS_ATTR_ALL])
361 for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
362 if (!getall && !data[i])
365 ret = netdev->dcbnl_ops->getnumtcs(netdev, i, &value);
367 ret = nla_put_u8(skb, i, value);
369 nla_nest_cancel(skb, nest);
375 nla_nest_end(skb, nest);
380 static int dcbnl_setnumtcs(struct net_device *netdev, struct nlmsghdr *nlh,
381 u32 seq, struct nlattr **tb, struct sk_buff *skb)
383 struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1];
388 if (!tb[DCB_ATTR_NUMTCS])
391 if (!netdev->dcbnl_ops->setnumtcs)
394 ret = nla_parse_nested_deprecated(data, DCB_NUMTCS_ATTR_MAX,
396 dcbnl_numtcs_nest, NULL);
400 for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
404 value = nla_get_u8(data[i]);
406 ret = netdev->dcbnl_ops->setnumtcs(netdev, i, value);
411 return nla_put_u8(skb, DCB_ATTR_NUMTCS, !!ret);
414 static int dcbnl_getpfcstate(struct net_device *netdev, struct nlmsghdr *nlh,
415 u32 seq, struct nlattr **tb, struct sk_buff *skb)
417 if (!netdev->dcbnl_ops->getpfcstate)
420 return nla_put_u8(skb, DCB_ATTR_PFC_STATE,
421 netdev->dcbnl_ops->getpfcstate(netdev));
424 static int dcbnl_setpfcstate(struct net_device *netdev, struct nlmsghdr *nlh,
425 u32 seq, struct nlattr **tb, struct sk_buff *skb)
429 if (!tb[DCB_ATTR_PFC_STATE])
432 if (!netdev->dcbnl_ops->setpfcstate)
435 value = nla_get_u8(tb[DCB_ATTR_PFC_STATE]);
437 netdev->dcbnl_ops->setpfcstate(netdev, value);
439 return nla_put_u8(skb, DCB_ATTR_PFC_STATE, 0);
442 static int dcbnl_getapp(struct net_device *netdev, struct nlmsghdr *nlh,
443 u32 seq, struct nlattr **tb, struct sk_buff *skb)
445 struct nlattr *app_nest;
446 struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1];
451 if (!tb[DCB_ATTR_APP])
454 ret = nla_parse_nested_deprecated(app_tb, DCB_APP_ATTR_MAX,
455 tb[DCB_ATTR_APP], dcbnl_app_nest,
460 /* all must be non-null */
461 if ((!app_tb[DCB_APP_ATTR_IDTYPE]) ||
462 (!app_tb[DCB_APP_ATTR_ID]))
465 /* either by eth type or by socket number */
466 idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]);
467 if ((idtype != DCB_APP_IDTYPE_ETHTYPE) &&
468 (idtype != DCB_APP_IDTYPE_PORTNUM))
471 id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]);
473 if (netdev->dcbnl_ops->getapp) {
474 ret = netdev->dcbnl_ops->getapp(netdev, idtype, id);
480 struct dcb_app app = {
484 up = dcb_getapp(netdev, &app);
487 app_nest = nla_nest_start_noflag(skb, DCB_ATTR_APP);
491 ret = nla_put_u8(skb, DCB_APP_ATTR_IDTYPE, idtype);
495 ret = nla_put_u16(skb, DCB_APP_ATTR_ID, id);
499 ret = nla_put_u8(skb, DCB_APP_ATTR_PRIORITY, up);
503 nla_nest_end(skb, app_nest);
508 nla_nest_cancel(skb, app_nest);
512 static int dcbnl_setapp(struct net_device *netdev, struct nlmsghdr *nlh,
513 u32 seq, struct nlattr **tb, struct sk_buff *skb)
518 struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1];
520 if (!tb[DCB_ATTR_APP])
523 ret = nla_parse_nested_deprecated(app_tb, DCB_APP_ATTR_MAX,
524 tb[DCB_ATTR_APP], dcbnl_app_nest,
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]))
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))
541 id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]);
542 up = nla_get_u8(app_tb[DCB_APP_ATTR_PRIORITY]);
544 if (netdev->dcbnl_ops->setapp) {
545 ret = netdev->dcbnl_ops->setapp(netdev, idtype, id, up);
550 app.selector = idtype;
553 ret = dcb_setapp(netdev, &app);
556 ret = nla_put_u8(skb, DCB_ATTR_APP, ret);
557 dcbnl_cee_notify(netdev, RTM_SETDCB, DCB_CMD_SAPP, seq, 0);
562 static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlmsghdr *nlh,
563 struct nlattr **tb, struct sk_buff *skb, int dir)
565 struct nlattr *pg_nest, *param_nest, *data;
566 struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
567 struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
568 u8 prio, pgid, tc_pct, up_map;
573 if (!tb[DCB_ATTR_PG_CFG])
576 if (!netdev->dcbnl_ops->getpgtccfgtx ||
577 !netdev->dcbnl_ops->getpgtccfgrx ||
578 !netdev->dcbnl_ops->getpgbwgcfgtx ||
579 !netdev->dcbnl_ops->getpgbwgcfgrx)
582 ret = nla_parse_nested_deprecated(pg_tb, DCB_PG_ATTR_MAX,
583 tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest,
588 pg_nest = nla_nest_start_noflag(skb, DCB_ATTR_PG_CFG);
592 if (pg_tb[DCB_PG_ATTR_TC_ALL])
595 for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
596 if (!getall && !pg_tb[i])
599 if (pg_tb[DCB_PG_ATTR_TC_ALL])
600 data = pg_tb[DCB_PG_ATTR_TC_ALL];
603 ret = nla_parse_nested_deprecated(param_tb,
604 DCB_TC_ATTR_PARAM_MAX, data,
605 dcbnl_tc_param_nest, NULL);
609 param_nest = nla_nest_start_noflag(skb, i);
613 pgid = DCB_ATTR_VALUE_UNDEFINED;
614 prio = DCB_ATTR_VALUE_UNDEFINED;
615 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
616 up_map = DCB_ATTR_VALUE_UNDEFINED;
620 netdev->dcbnl_ops->getpgtccfgrx(netdev,
621 i - DCB_PG_ATTR_TC_0, &prio,
622 &pgid, &tc_pct, &up_map);
625 netdev->dcbnl_ops->getpgtccfgtx(netdev,
626 i - DCB_PG_ATTR_TC_0, &prio,
627 &pgid, &tc_pct, &up_map);
630 if (param_tb[DCB_TC_ATTR_PARAM_PGID] ||
631 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
632 ret = nla_put_u8(skb,
633 DCB_TC_ATTR_PARAM_PGID, pgid);
637 if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING] ||
638 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
639 ret = nla_put_u8(skb,
640 DCB_TC_ATTR_PARAM_UP_MAPPING, up_map);
644 if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO] ||
645 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
646 ret = nla_put_u8(skb,
647 DCB_TC_ATTR_PARAM_STRICT_PRIO, prio);
651 if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT] ||
652 param_tb[DCB_TC_ATTR_PARAM_ALL]) {
653 ret = nla_put_u8(skb, DCB_TC_ATTR_PARAM_BW_PCT,
658 nla_nest_end(skb, param_nest);
661 if (pg_tb[DCB_PG_ATTR_BW_ID_ALL])
666 for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
667 if (!getall && !pg_tb[i])
670 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
674 netdev->dcbnl_ops->getpgbwgcfgrx(netdev,
675 i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
678 netdev->dcbnl_ops->getpgbwgcfgtx(netdev,
679 i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
681 ret = nla_put_u8(skb, i, tc_pct);
686 nla_nest_end(skb, pg_nest);
691 nla_nest_cancel(skb, param_nest);
693 nla_nest_cancel(skb, pg_nest);
698 static int dcbnl_pgtx_getcfg(struct net_device *netdev, struct nlmsghdr *nlh,
699 u32 seq, struct nlattr **tb, struct sk_buff *skb)
701 return __dcbnl_pg_getcfg(netdev, nlh, tb, skb, 0);
704 static int dcbnl_pgrx_getcfg(struct net_device *netdev, struct nlmsghdr *nlh,
705 u32 seq, struct nlattr **tb, struct sk_buff *skb)
707 return __dcbnl_pg_getcfg(netdev, nlh, tb, skb, 1);
710 static int dcbnl_setstate(struct net_device *netdev, struct nlmsghdr *nlh,
711 u32 seq, struct nlattr **tb, struct sk_buff *skb)
715 if (!tb[DCB_ATTR_STATE])
718 if (!netdev->dcbnl_ops->setstate)
721 value = nla_get_u8(tb[DCB_ATTR_STATE]);
723 return nla_put_u8(skb, DCB_ATTR_STATE,
724 netdev->dcbnl_ops->setstate(netdev, value));
727 static int dcbnl_setpfccfg(struct net_device *netdev, struct nlmsghdr *nlh,
728 u32 seq, struct nlattr **tb, struct sk_buff *skb)
730 struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1];
735 if (!tb[DCB_ATTR_PFC_CFG])
738 if (!netdev->dcbnl_ops->setpfccfg)
741 ret = nla_parse_nested_deprecated(data, DCB_PFC_UP_ATTR_MAX,
742 tb[DCB_ATTR_PFC_CFG],
743 dcbnl_pfc_up_nest, NULL);
747 for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
750 value = nla_get_u8(data[i]);
751 netdev->dcbnl_ops->setpfccfg(netdev,
752 data[i]->nla_type - DCB_PFC_UP_ATTR_0, value);
755 return nla_put_u8(skb, DCB_ATTR_PFC_CFG, 0);
758 static int dcbnl_setall(struct net_device *netdev, struct nlmsghdr *nlh,
759 u32 seq, struct nlattr **tb, struct sk_buff *skb)
763 if (!tb[DCB_ATTR_SET_ALL])
766 if (!netdev->dcbnl_ops->setall)
769 ret = nla_put_u8(skb, DCB_ATTR_SET_ALL,
770 netdev->dcbnl_ops->setall(netdev));
771 dcbnl_cee_notify(netdev, RTM_SETDCB, DCB_CMD_SET_ALL, seq, 0);
776 static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
777 u32 seq, struct nlattr **tb, struct sk_buff *skb,
780 struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
781 struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
789 if (!tb[DCB_ATTR_PG_CFG])
792 if (!netdev->dcbnl_ops->setpgtccfgtx ||
793 !netdev->dcbnl_ops->setpgtccfgrx ||
794 !netdev->dcbnl_ops->setpgbwgcfgtx ||
795 !netdev->dcbnl_ops->setpgbwgcfgrx)
798 ret = nla_parse_nested_deprecated(pg_tb, DCB_PG_ATTR_MAX,
799 tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest,
804 for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
808 ret = nla_parse_nested_deprecated(param_tb,
809 DCB_TC_ATTR_PARAM_MAX,
811 dcbnl_tc_param_nest, NULL);
815 pgid = DCB_ATTR_VALUE_UNDEFINED;
816 prio = DCB_ATTR_VALUE_UNDEFINED;
817 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
818 up_map = DCB_ATTR_VALUE_UNDEFINED;
820 if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO])
822 nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]);
824 if (param_tb[DCB_TC_ATTR_PARAM_PGID])
825 pgid = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_PGID]);
827 if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT])
828 tc_pct = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_BW_PCT]);
830 if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING])
832 nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]);
834 /* dir: Tx = 0, Rx = 1 */
837 netdev->dcbnl_ops->setpgtccfgrx(netdev,
838 i - DCB_PG_ATTR_TC_0,
839 prio, pgid, tc_pct, up_map);
842 netdev->dcbnl_ops->setpgtccfgtx(netdev,
843 i - DCB_PG_ATTR_TC_0,
844 prio, pgid, tc_pct, up_map);
848 for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
852 tc_pct = nla_get_u8(pg_tb[i]);
854 /* dir: Tx = 0, Rx = 1 */
857 netdev->dcbnl_ops->setpgbwgcfgrx(netdev,
858 i - DCB_PG_ATTR_BW_ID_0, tc_pct);
861 netdev->dcbnl_ops->setpgbwgcfgtx(netdev,
862 i - DCB_PG_ATTR_BW_ID_0, tc_pct);
866 return nla_put_u8(skb, DCB_ATTR_PG_CFG, 0);
869 static int dcbnl_pgtx_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
870 u32 seq, struct nlattr **tb, struct sk_buff *skb)
872 return __dcbnl_pg_setcfg(netdev, nlh, seq, tb, skb, 0);
875 static int dcbnl_pgrx_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
876 u32 seq, struct nlattr **tb, struct sk_buff *skb)
878 return __dcbnl_pg_setcfg(netdev, nlh, seq, tb, skb, 1);
881 static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlmsghdr *nlh,
882 u32 seq, struct nlattr **tb, struct sk_buff *skb)
884 struct nlattr *bcn_nest;
885 struct nlattr *bcn_tb[DCB_BCN_ATTR_MAX + 1];
892 if (!tb[DCB_ATTR_BCN])
895 if (!netdev->dcbnl_ops->getbcnrp ||
896 !netdev->dcbnl_ops->getbcncfg)
899 ret = nla_parse_nested_deprecated(bcn_tb, DCB_BCN_ATTR_MAX,
900 tb[DCB_ATTR_BCN], dcbnl_bcn_nest,
905 bcn_nest = nla_nest_start_noflag(skb, DCB_ATTR_BCN);
909 if (bcn_tb[DCB_BCN_ATTR_ALL])
912 for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
913 if (!getall && !bcn_tb[i])
916 netdev->dcbnl_ops->getbcnrp(netdev, i - DCB_BCN_ATTR_RP_0,
918 ret = nla_put_u8(skb, i, value_byte);
923 for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
924 if (!getall && !bcn_tb[i])
927 netdev->dcbnl_ops->getbcncfg(netdev, i,
929 ret = nla_put_u32(skb, i, value_integer);
934 nla_nest_end(skb, bcn_nest);
939 nla_nest_cancel(skb, bcn_nest);
943 static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
944 u32 seq, struct nlattr **tb, struct sk_buff *skb)
946 struct nlattr *data[DCB_BCN_ATTR_MAX + 1];
952 if (!tb[DCB_ATTR_BCN])
955 if (!netdev->dcbnl_ops->setbcncfg ||
956 !netdev->dcbnl_ops->setbcnrp)
959 ret = nla_parse_nested_deprecated(data, DCB_BCN_ATTR_MAX,
960 tb[DCB_ATTR_BCN], dcbnl_pfc_up_nest,
965 for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
968 value_byte = nla_get_u8(data[i]);
969 netdev->dcbnl_ops->setbcnrp(netdev,
970 data[i]->nla_type - DCB_BCN_ATTR_RP_0, value_byte);
973 for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
976 value_int = nla_get_u32(data[i]);
977 netdev->dcbnl_ops->setbcncfg(netdev,
981 return nla_put_u8(skb, DCB_ATTR_BCN, 0);
984 static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,
985 int app_nested_type, int app_info_type,
988 struct dcb_peer_app_info info;
989 struct dcb_app *table = NULL;
990 const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
996 * retrieve the peer app configuration form the driver. If the driver
997 * handlers fail exit without doing anything
999 err = ops->peer_getappinfo(netdev, &info, &app_count);
1000 if (!err && app_count) {
1001 table = kmalloc_array(app_count, sizeof(struct dcb_app),
1006 err = ops->peer_getapptable(netdev, table);
1014 * build the message, from here on the only possible failure
1015 * is due to the skb size
1019 app = nla_nest_start_noflag(skb, app_nested_type);
1021 goto nla_put_failure;
1023 if (app_info_type &&
1024 nla_put(skb, app_info_type, sizeof(info), &info))
1025 goto nla_put_failure;
1027 for (i = 0; i < app_count; i++) {
1028 if (nla_put(skb, app_entry_type, sizeof(struct dcb_app),
1030 goto nla_put_failure;
1032 nla_nest_end(skb, app);
1041 /* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb GET commands. */
1042 static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
1044 struct nlattr *ieee, *app;
1045 struct dcb_app_type *itr;
1046 const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
1050 if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name))
1053 ieee = nla_nest_start_noflag(skb, DCB_ATTR_IEEE);
1057 if (ops->ieee_getets) {
1058 struct ieee_ets ets;
1059 memset(&ets, 0, sizeof(ets));
1060 err = ops->ieee_getets(netdev, &ets);
1062 nla_put(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets))
1066 if (ops->ieee_getmaxrate) {
1067 struct ieee_maxrate maxrate;
1068 memset(&maxrate, 0, sizeof(maxrate));
1069 err = ops->ieee_getmaxrate(netdev, &maxrate);
1071 err = nla_put(skb, DCB_ATTR_IEEE_MAXRATE,
1072 sizeof(maxrate), &maxrate);
1078 if (ops->ieee_getqcn) {
1079 struct ieee_qcn qcn;
1081 memset(&qcn, 0, sizeof(qcn));
1082 err = ops->ieee_getqcn(netdev, &qcn);
1084 err = nla_put(skb, DCB_ATTR_IEEE_QCN,
1091 if (ops->ieee_getqcnstats) {
1092 struct ieee_qcn_stats qcn_stats;
1094 memset(&qcn_stats, 0, sizeof(qcn_stats));
1095 err = ops->ieee_getqcnstats(netdev, &qcn_stats);
1097 err = nla_put(skb, DCB_ATTR_IEEE_QCN_STATS,
1098 sizeof(qcn_stats), &qcn_stats);
1104 if (ops->ieee_getpfc) {
1105 struct ieee_pfc pfc;
1106 memset(&pfc, 0, sizeof(pfc));
1107 err = ops->ieee_getpfc(netdev, &pfc);
1109 nla_put(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc))
1113 if (ops->dcbnl_getbuffer) {
1114 struct dcbnl_buffer buffer;
1116 memset(&buffer, 0, sizeof(buffer));
1117 err = ops->dcbnl_getbuffer(netdev, &buffer);
1119 nla_put(skb, DCB_ATTR_DCB_BUFFER, sizeof(buffer), &buffer))
1123 app = nla_nest_start_noflag(skb, DCB_ATTR_IEEE_APP_TABLE);
1127 spin_lock_bh(&dcb_lock);
1128 list_for_each_entry(itr, &dcb_app_list, list) {
1129 if (itr->ifindex == netdev->ifindex) {
1130 err = nla_put(skb, DCB_ATTR_IEEE_APP, sizeof(itr->app),
1133 spin_unlock_bh(&dcb_lock);
1139 if (netdev->dcbnl_ops->getdcbx)
1140 dcbx = netdev->dcbnl_ops->getdcbx(netdev);
1144 spin_unlock_bh(&dcb_lock);
1145 nla_nest_end(skb, app);
1147 /* get peer info if available */
1148 if (ops->ieee_peer_getets) {
1149 struct ieee_ets ets;
1150 memset(&ets, 0, sizeof(ets));
1151 err = ops->ieee_peer_getets(netdev, &ets);
1153 nla_put(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets))
1157 if (ops->ieee_peer_getpfc) {
1158 struct ieee_pfc pfc;
1159 memset(&pfc, 0, sizeof(pfc));
1160 err = ops->ieee_peer_getpfc(netdev, &pfc);
1162 nla_put(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc))
1166 if (ops->peer_getappinfo && ops->peer_getapptable) {
1167 err = dcbnl_build_peer_app(netdev, skb,
1168 DCB_ATTR_IEEE_PEER_APP,
1169 DCB_ATTR_IEEE_APP_UNSPEC,
1175 nla_nest_end(skb, ieee);
1177 err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx);
1185 static int dcbnl_cee_pg_fill(struct sk_buff *skb, struct net_device *dev,
1188 u8 pgid, up_map, prio, tc_pct;
1189 const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops;
1190 int i = dir ? DCB_ATTR_CEE_TX_PG : DCB_ATTR_CEE_RX_PG;
1191 struct nlattr *pg = nla_nest_start_noflag(skb, i);
1196 for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
1197 struct nlattr *tc_nest = nla_nest_start_noflag(skb, i);
1202 pgid = DCB_ATTR_VALUE_UNDEFINED;
1203 prio = DCB_ATTR_VALUE_UNDEFINED;
1204 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
1205 up_map = DCB_ATTR_VALUE_UNDEFINED;
1208 ops->getpgtccfgrx(dev, i - DCB_PG_ATTR_TC_0,
1209 &prio, &pgid, &tc_pct, &up_map);
1211 ops->getpgtccfgtx(dev, i - DCB_PG_ATTR_TC_0,
1212 &prio, &pgid, &tc_pct, &up_map);
1214 if (nla_put_u8(skb, DCB_TC_ATTR_PARAM_PGID, pgid) ||
1215 nla_put_u8(skb, DCB_TC_ATTR_PARAM_UP_MAPPING, up_map) ||
1216 nla_put_u8(skb, DCB_TC_ATTR_PARAM_STRICT_PRIO, prio) ||
1217 nla_put_u8(skb, DCB_TC_ATTR_PARAM_BW_PCT, tc_pct))
1219 nla_nest_end(skb, tc_nest);
1222 for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
1223 tc_pct = DCB_ATTR_VALUE_UNDEFINED;
1226 ops->getpgbwgcfgrx(dev, i - DCB_PG_ATTR_BW_ID_0,
1229 ops->getpgbwgcfgtx(dev, i - DCB_PG_ATTR_BW_ID_0,
1231 if (nla_put_u8(skb, i, tc_pct))
1234 nla_nest_end(skb, pg);
1238 static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
1240 struct nlattr *cee, *app;
1241 struct dcb_app_type *itr;
1242 const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
1243 int dcbx, i, err = -EMSGSIZE;
1246 if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name))
1247 goto nla_put_failure;
1248 cee = nla_nest_start_noflag(skb, DCB_ATTR_CEE);
1250 goto nla_put_failure;
1253 if (ops->getpgtccfgtx && ops->getpgbwgcfgtx) {
1254 err = dcbnl_cee_pg_fill(skb, netdev, 1);
1256 goto nla_put_failure;
1259 if (ops->getpgtccfgrx && ops->getpgbwgcfgrx) {
1260 err = dcbnl_cee_pg_fill(skb, netdev, 0);
1262 goto nla_put_failure;
1266 if (ops->getpfccfg) {
1267 struct nlattr *pfc_nest = nla_nest_start_noflag(skb,
1271 goto nla_put_failure;
1273 for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
1274 ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0, &value);
1275 if (nla_put_u8(skb, i, value))
1276 goto nla_put_failure;
1278 nla_nest_end(skb, pfc_nest);
1282 spin_lock_bh(&dcb_lock);
1283 app = nla_nest_start_noflag(skb, DCB_ATTR_CEE_APP_TABLE);
1287 list_for_each_entry(itr, &dcb_app_list, list) {
1288 if (itr->ifindex == netdev->ifindex) {
1289 struct nlattr *app_nest = nla_nest_start_noflag(skb,
1294 err = nla_put_u8(skb, DCB_APP_ATTR_IDTYPE,
1299 err = nla_put_u16(skb, DCB_APP_ATTR_ID,
1304 err = nla_put_u8(skb, DCB_APP_ATTR_PRIORITY,
1309 nla_nest_end(skb, app_nest);
1312 nla_nest_end(skb, app);
1314 if (netdev->dcbnl_ops->getdcbx)
1315 dcbx = netdev->dcbnl_ops->getdcbx(netdev);
1319 spin_unlock_bh(&dcb_lock);
1321 /* features flags */
1322 if (ops->getfeatcfg) {
1323 struct nlattr *feat = nla_nest_start_noflag(skb,
1326 goto nla_put_failure;
1328 for (i = DCB_FEATCFG_ATTR_ALL + 1; i <= DCB_FEATCFG_ATTR_MAX;
1330 if (!ops->getfeatcfg(netdev, i, &value) &&
1331 nla_put_u8(skb, i, value))
1332 goto nla_put_failure;
1334 nla_nest_end(skb, feat);
1337 /* peer info if available */
1338 if (ops->cee_peer_getpg) {
1340 memset(&pg, 0, sizeof(pg));
1341 err = ops->cee_peer_getpg(netdev, &pg);
1343 nla_put(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg))
1344 goto nla_put_failure;
1347 if (ops->cee_peer_getpfc) {
1349 memset(&pfc, 0, sizeof(pfc));
1350 err = ops->cee_peer_getpfc(netdev, &pfc);
1352 nla_put(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc))
1353 goto nla_put_failure;
1356 if (ops->peer_getappinfo && ops->peer_getapptable) {
1357 err = dcbnl_build_peer_app(netdev, skb,
1358 DCB_ATTR_CEE_PEER_APP_TABLE,
1359 DCB_ATTR_CEE_PEER_APP_INFO,
1360 DCB_ATTR_CEE_PEER_APP);
1362 goto nla_put_failure;
1364 nla_nest_end(skb, cee);
1368 err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx);
1370 goto nla_put_failure;
1375 spin_unlock_bh(&dcb_lock);
1381 static int dcbnl_notify(struct net_device *dev, int event, int cmd,
1382 u32 seq, u32 portid, int dcbx_ver)
1384 struct net *net = dev_net(dev);
1385 struct sk_buff *skb;
1386 struct nlmsghdr *nlh;
1387 const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops;
1393 skb = dcbnl_newmsg(event, cmd, portid, seq, 0, &nlh);
1397 if (dcbx_ver == DCB_CAP_DCBX_VER_IEEE)
1398 err = dcbnl_ieee_fill(skb, dev);
1400 err = dcbnl_cee_fill(skb, dev);
1403 /* Report error to broadcast listeners */
1405 rtnl_set_sk_err(net, RTNLGRP_DCB, err);
1407 /* End nlmsg and notify broadcast listeners */
1408 nlmsg_end(skb, nlh);
1409 rtnl_notify(skb, net, 0, RTNLGRP_DCB, NULL, GFP_KERNEL);
1415 int dcbnl_ieee_notify(struct net_device *dev, int event, int cmd,
1416 u32 seq, u32 portid)
1418 return dcbnl_notify(dev, event, cmd, seq, portid, DCB_CAP_DCBX_VER_IEEE);
1420 EXPORT_SYMBOL(dcbnl_ieee_notify);
1422 int dcbnl_cee_notify(struct net_device *dev, int event, int cmd,
1423 u32 seq, u32 portid)
1425 return dcbnl_notify(dev, event, cmd, seq, portid, DCB_CAP_DCBX_VER_CEE);
1427 EXPORT_SYMBOL(dcbnl_cee_notify);
1429 /* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb SET commands.
1430 * If any requested operation can not be completed
1431 * the entire msg is aborted and error value is returned.
1432 * No attempt is made to reconcile the case where only part of the
1433 * cmd can be completed.
1435 static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh,
1436 u32 seq, struct nlattr **tb, struct sk_buff *skb)
1438 const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
1439 struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
1445 if (!tb[DCB_ATTR_IEEE])
1448 err = nla_parse_nested_deprecated(ieee, DCB_ATTR_IEEE_MAX,
1450 dcbnl_ieee_policy, NULL);
1454 if (ieee[DCB_ATTR_IEEE_ETS] && ops->ieee_setets) {
1455 struct ieee_ets *ets = nla_data(ieee[DCB_ATTR_IEEE_ETS]);
1456 err = ops->ieee_setets(netdev, ets);
1461 if (ieee[DCB_ATTR_IEEE_MAXRATE] && ops->ieee_setmaxrate) {
1462 struct ieee_maxrate *maxrate =
1463 nla_data(ieee[DCB_ATTR_IEEE_MAXRATE]);
1464 err = ops->ieee_setmaxrate(netdev, maxrate);
1469 if (ieee[DCB_ATTR_IEEE_QCN] && ops->ieee_setqcn) {
1470 struct ieee_qcn *qcn =
1471 nla_data(ieee[DCB_ATTR_IEEE_QCN]);
1473 err = ops->ieee_setqcn(netdev, qcn);
1478 if (ieee[DCB_ATTR_IEEE_PFC] && ops->ieee_setpfc) {
1479 struct ieee_pfc *pfc = nla_data(ieee[DCB_ATTR_IEEE_PFC]);
1480 err = ops->ieee_setpfc(netdev, pfc);
1485 if (ieee[DCB_ATTR_DCB_BUFFER] && ops->dcbnl_setbuffer) {
1486 struct dcbnl_buffer *buffer =
1487 nla_data(ieee[DCB_ATTR_DCB_BUFFER]);
1489 err = ops->dcbnl_setbuffer(netdev, buffer);
1494 if (ieee[DCB_ATTR_IEEE_APP_TABLE]) {
1495 struct nlattr *attr;
1498 nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) {
1499 struct dcb_app *app_data;
1501 if (nla_type(attr) != DCB_ATTR_IEEE_APP)
1504 if (nla_len(attr) < sizeof(struct dcb_app)) {
1509 app_data = nla_data(attr);
1510 if (ops->ieee_setapp)
1511 err = ops->ieee_setapp(netdev, app_data);
1513 err = dcb_ieee_setapp(netdev, app_data);
1520 err = nla_put_u8(skb, DCB_ATTR_IEEE, err);
1521 dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_SET, seq, 0);
1525 static int dcbnl_ieee_get(struct net_device *netdev, struct nlmsghdr *nlh,
1526 u32 seq, struct nlattr **tb, struct sk_buff *skb)
1528 const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
1533 return dcbnl_ieee_fill(skb, netdev);
1536 static int dcbnl_ieee_del(struct net_device *netdev, struct nlmsghdr *nlh,
1537 u32 seq, struct nlattr **tb, struct sk_buff *skb)
1539 const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
1540 struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
1546 if (!tb[DCB_ATTR_IEEE])
1549 err = nla_parse_nested_deprecated(ieee, DCB_ATTR_IEEE_MAX,
1551 dcbnl_ieee_policy, NULL);
1555 if (ieee[DCB_ATTR_IEEE_APP_TABLE]) {
1556 struct nlattr *attr;
1559 nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) {
1560 struct dcb_app *app_data;
1562 if (nla_type(attr) != DCB_ATTR_IEEE_APP)
1564 app_data = nla_data(attr);
1565 if (ops->ieee_delapp)
1566 err = ops->ieee_delapp(netdev, app_data);
1568 err = dcb_ieee_delapp(netdev, app_data);
1575 err = nla_put_u8(skb, DCB_ATTR_IEEE, err);
1576 dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_DEL, seq, 0);
1581 /* DCBX configuration */
1582 static int dcbnl_getdcbx(struct net_device *netdev, struct nlmsghdr *nlh,
1583 u32 seq, struct nlattr **tb, struct sk_buff *skb)
1585 if (!netdev->dcbnl_ops->getdcbx)
1588 return nla_put_u8(skb, DCB_ATTR_DCBX,
1589 netdev->dcbnl_ops->getdcbx(netdev));
1592 static int dcbnl_setdcbx(struct net_device *netdev, struct nlmsghdr *nlh,
1593 u32 seq, struct nlattr **tb, struct sk_buff *skb)
1597 if (!netdev->dcbnl_ops->setdcbx)
1600 if (!tb[DCB_ATTR_DCBX])
1603 value = nla_get_u8(tb[DCB_ATTR_DCBX]);
1605 return nla_put_u8(skb, DCB_ATTR_DCBX,
1606 netdev->dcbnl_ops->setdcbx(netdev, value));
1609 static int dcbnl_getfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh,
1610 u32 seq, struct nlattr **tb, struct sk_buff *skb)
1612 struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1], *nest;
1617 if (!netdev->dcbnl_ops->getfeatcfg)
1620 if (!tb[DCB_ATTR_FEATCFG])
1623 ret = nla_parse_nested_deprecated(data, DCB_FEATCFG_ATTR_MAX,
1624 tb[DCB_ATTR_FEATCFG],
1625 dcbnl_featcfg_nest, NULL);
1629 nest = nla_nest_start_noflag(skb, DCB_ATTR_FEATCFG);
1633 if (data[DCB_FEATCFG_ATTR_ALL])
1636 for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
1637 if (!getall && !data[i])
1640 ret = netdev->dcbnl_ops->getfeatcfg(netdev, i, &value);
1642 ret = nla_put_u8(skb, i, value);
1645 nla_nest_cancel(skb, nest);
1646 goto nla_put_failure;
1649 nla_nest_end(skb, nest);
1655 static int dcbnl_setfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh,
1656 u32 seq, struct nlattr **tb, struct sk_buff *skb)
1658 struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1];
1662 if (!netdev->dcbnl_ops->setfeatcfg)
1665 if (!tb[DCB_ATTR_FEATCFG])
1668 ret = nla_parse_nested_deprecated(data, DCB_FEATCFG_ATTR_MAX,
1669 tb[DCB_ATTR_FEATCFG],
1670 dcbnl_featcfg_nest, NULL);
1675 for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
1676 if (data[i] == NULL)
1679 value = nla_get_u8(data[i]);
1681 ret = netdev->dcbnl_ops->setfeatcfg(netdev, i, value);
1687 ret = nla_put_u8(skb, DCB_ATTR_FEATCFG, ret);
1692 /* Handle CEE DCBX GET commands. */
1693 static int dcbnl_cee_get(struct net_device *netdev, struct nlmsghdr *nlh,
1694 u32 seq, struct nlattr **tb, struct sk_buff *skb)
1696 const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
1701 return dcbnl_cee_fill(skb, netdev);
1705 /* reply netlink message type */
1708 /* function to fill message contents */
1709 int (*cb)(struct net_device *, struct nlmsghdr *, u32,
1710 struct nlattr **, struct sk_buff *);
1713 static const struct reply_func reply_funcs[DCB_CMD_MAX+1] = {
1714 [DCB_CMD_GSTATE] = { RTM_GETDCB, dcbnl_getstate },
1715 [DCB_CMD_SSTATE] = { RTM_SETDCB, dcbnl_setstate },
1716 [DCB_CMD_PFC_GCFG] = { RTM_GETDCB, dcbnl_getpfccfg },
1717 [DCB_CMD_PFC_SCFG] = { RTM_SETDCB, dcbnl_setpfccfg },
1718 [DCB_CMD_GPERM_HWADDR] = { RTM_GETDCB, dcbnl_getperm_hwaddr },
1719 [DCB_CMD_GCAP] = { RTM_GETDCB, dcbnl_getcap },
1720 [DCB_CMD_GNUMTCS] = { RTM_GETDCB, dcbnl_getnumtcs },
1721 [DCB_CMD_SNUMTCS] = { RTM_SETDCB, dcbnl_setnumtcs },
1722 [DCB_CMD_PFC_GSTATE] = { RTM_GETDCB, dcbnl_getpfcstate },
1723 [DCB_CMD_PFC_SSTATE] = { RTM_SETDCB, dcbnl_setpfcstate },
1724 [DCB_CMD_GAPP] = { RTM_GETDCB, dcbnl_getapp },
1725 [DCB_CMD_SAPP] = { RTM_SETDCB, dcbnl_setapp },
1726 [DCB_CMD_PGTX_GCFG] = { RTM_GETDCB, dcbnl_pgtx_getcfg },
1727 [DCB_CMD_PGTX_SCFG] = { RTM_SETDCB, dcbnl_pgtx_setcfg },
1728 [DCB_CMD_PGRX_GCFG] = { RTM_GETDCB, dcbnl_pgrx_getcfg },
1729 [DCB_CMD_PGRX_SCFG] = { RTM_SETDCB, dcbnl_pgrx_setcfg },
1730 [DCB_CMD_SET_ALL] = { RTM_SETDCB, dcbnl_setall },
1731 [DCB_CMD_BCN_GCFG] = { RTM_GETDCB, dcbnl_bcn_getcfg },
1732 [DCB_CMD_BCN_SCFG] = { RTM_SETDCB, dcbnl_bcn_setcfg },
1733 [DCB_CMD_IEEE_GET] = { RTM_GETDCB, dcbnl_ieee_get },
1734 [DCB_CMD_IEEE_SET] = { RTM_SETDCB, dcbnl_ieee_set },
1735 [DCB_CMD_IEEE_DEL] = { RTM_SETDCB, dcbnl_ieee_del },
1736 [DCB_CMD_GDCBX] = { RTM_GETDCB, dcbnl_getdcbx },
1737 [DCB_CMD_SDCBX] = { RTM_SETDCB, dcbnl_setdcbx },
1738 [DCB_CMD_GFEATCFG] = { RTM_GETDCB, dcbnl_getfeatcfg },
1739 [DCB_CMD_SFEATCFG] = { RTM_SETDCB, dcbnl_setfeatcfg },
1740 [DCB_CMD_CEE_GET] = { RTM_GETDCB, dcbnl_cee_get },
1743 static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
1744 struct netlink_ext_ack *extack)
1746 struct net *net = sock_net(skb->sk);
1747 struct net_device *netdev;
1748 struct dcbmsg *dcb = nlmsg_data(nlh);
1749 struct nlattr *tb[DCB_ATTR_MAX + 1];
1750 u32 portid = skb ? NETLINK_CB(skb).portid : 0;
1752 struct sk_buff *reply_skb;
1753 struct nlmsghdr *reply_nlh = NULL;
1754 const struct reply_func *fn;
1756 if ((nlh->nlmsg_type == RTM_SETDCB) && !netlink_capable(skb, CAP_NET_ADMIN))
1759 ret = nlmsg_parse_deprecated(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
1760 dcbnl_rtnl_policy, extack);
1764 if (dcb->cmd > DCB_CMD_MAX)
1767 /* check if a reply function has been defined for the command */
1768 fn = &reply_funcs[dcb->cmd];
1772 if (!tb[DCB_ATTR_IFNAME])
1775 netdev = __dev_get_by_name(net, nla_data(tb[DCB_ATTR_IFNAME]));
1779 if (!netdev->dcbnl_ops)
1782 reply_skb = dcbnl_newmsg(fn->type, dcb->cmd, portid, nlh->nlmsg_seq,
1783 nlh->nlmsg_flags, &reply_nlh);
1787 ret = fn->cb(netdev, nlh, nlh->nlmsg_seq, tb, reply_skb);
1789 nlmsg_free(reply_skb);
1793 nlmsg_end(reply_skb, reply_nlh);
1795 ret = rtnl_unicast(reply_skb, net, portid);
1800 static struct dcb_app_type *dcb_app_lookup(const struct dcb_app *app,
1801 int ifindex, int prio)
1803 struct dcb_app_type *itr;
1805 list_for_each_entry(itr, &dcb_app_list, list) {
1806 if (itr->app.selector == app->selector &&
1807 itr->app.protocol == app->protocol &&
1808 itr->ifindex == ifindex &&
1809 ((prio == -1) || itr->app.priority == prio))
1816 static int dcb_app_add(const struct dcb_app *app, int ifindex)
1818 struct dcb_app_type *entry;
1820 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
1824 memcpy(&entry->app, app, sizeof(*app));
1825 entry->ifindex = ifindex;
1826 list_add(&entry->list, &dcb_app_list);
1832 * dcb_getapp - retrieve the DCBX application user priority
1834 * On success returns a non-zero 802.1p user priority bitmap
1835 * otherwise returns 0 as the invalid user priority bitmap to
1836 * indicate an error.
1838 u8 dcb_getapp(struct net_device *dev, struct dcb_app *app)
1840 struct dcb_app_type *itr;
1843 spin_lock_bh(&dcb_lock);
1844 itr = dcb_app_lookup(app, dev->ifindex, -1);
1846 prio = itr->app.priority;
1847 spin_unlock_bh(&dcb_lock);
1851 EXPORT_SYMBOL(dcb_getapp);
1854 * dcb_setapp - add CEE dcb application data to app list
1856 * Priority 0 is an invalid priority in CEE spec. This routine
1857 * removes applications from the app list if the priority is
1858 * set to zero. Priority is expected to be 8-bit 802.1p user priority bitmap
1860 int dcb_setapp(struct net_device *dev, struct dcb_app *new)
1862 struct dcb_app_type *itr;
1863 struct dcb_app_type event;
1866 event.ifindex = dev->ifindex;
1867 memcpy(&event.app, new, sizeof(event.app));
1868 if (dev->dcbnl_ops->getdcbx)
1869 event.dcbx = dev->dcbnl_ops->getdcbx(dev);
1871 spin_lock_bh(&dcb_lock);
1872 /* Search for existing match and replace */
1873 itr = dcb_app_lookup(new, dev->ifindex, -1);
1876 itr->app.priority = new->priority;
1878 list_del(&itr->list);
1883 /* App type does not exist add new application type */
1885 err = dcb_app_add(new, dev->ifindex);
1887 spin_unlock_bh(&dcb_lock);
1889 call_dcbevent_notifiers(DCB_APP_EVENT, &event);
1892 EXPORT_SYMBOL(dcb_setapp);
1895 * dcb_ieee_getapp_mask - retrieve the IEEE DCB application priority
1897 * Helper routine which on success returns a non-zero 802.1Qaz user
1898 * priority bitmap otherwise returns 0 to indicate the dcb_app was
1899 * not found in APP list.
1901 u8 dcb_ieee_getapp_mask(struct net_device *dev, struct dcb_app *app)
1903 struct dcb_app_type *itr;
1906 spin_lock_bh(&dcb_lock);
1907 itr = dcb_app_lookup(app, dev->ifindex, -1);
1909 prio |= 1 << itr->app.priority;
1910 spin_unlock_bh(&dcb_lock);
1914 EXPORT_SYMBOL(dcb_ieee_getapp_mask);
1917 * dcb_ieee_setapp - add IEEE dcb application data to app list
1919 * This adds Application data to the list. Multiple application
1920 * entries may exists for the same selector and protocol as long
1921 * as the priorities are different. Priority is expected to be a
1922 * 3-bit unsigned integer
1924 int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new)
1926 struct dcb_app_type event;
1929 event.ifindex = dev->ifindex;
1930 memcpy(&event.app, new, sizeof(event.app));
1931 if (dev->dcbnl_ops->getdcbx)
1932 event.dcbx = dev->dcbnl_ops->getdcbx(dev);
1934 spin_lock_bh(&dcb_lock);
1935 /* Search for existing match and abort if found */
1936 if (dcb_app_lookup(new, dev->ifindex, new->priority)) {
1941 err = dcb_app_add(new, dev->ifindex);
1943 spin_unlock_bh(&dcb_lock);
1945 call_dcbevent_notifiers(DCB_APP_EVENT, &event);
1948 EXPORT_SYMBOL(dcb_ieee_setapp);
1951 * dcb_ieee_delapp - delete IEEE dcb application data from list
1953 * This removes a matching APP data from the APP list
1955 int dcb_ieee_delapp(struct net_device *dev, struct dcb_app *del)
1957 struct dcb_app_type *itr;
1958 struct dcb_app_type event;
1961 event.ifindex = dev->ifindex;
1962 memcpy(&event.app, del, sizeof(event.app));
1963 if (dev->dcbnl_ops->getdcbx)
1964 event.dcbx = dev->dcbnl_ops->getdcbx(dev);
1966 spin_lock_bh(&dcb_lock);
1967 /* Search for existing match and remove it. */
1968 if ((itr = dcb_app_lookup(del, dev->ifindex, del->priority))) {
1969 list_del(&itr->list);
1974 spin_unlock_bh(&dcb_lock);
1976 call_dcbevent_notifiers(DCB_APP_EVENT, &event);
1979 EXPORT_SYMBOL(dcb_ieee_delapp);
1982 * dcb_ieee_getapp_prio_dscp_mask_map - For a given device, find mapping from
1983 * priorities to the DSCP values assigned to that priority. Initialize p_map
1984 * such that each map element holds a bit mask of DSCP values configured for
1985 * that priority by APP entries.
1987 void dcb_ieee_getapp_prio_dscp_mask_map(const struct net_device *dev,
1988 struct dcb_ieee_app_prio_map *p_map)
1990 int ifindex = dev->ifindex;
1991 struct dcb_app_type *itr;
1994 memset(p_map->map, 0, sizeof(p_map->map));
1996 spin_lock_bh(&dcb_lock);
1997 list_for_each_entry(itr, &dcb_app_list, list) {
1998 if (itr->ifindex == ifindex &&
1999 itr->app.selector == IEEE_8021QAZ_APP_SEL_DSCP &&
2000 itr->app.protocol < 64 &&
2001 itr->app.priority < IEEE_8021QAZ_MAX_TCS) {
2002 prio = itr->app.priority;
2003 p_map->map[prio] |= 1ULL << itr->app.protocol;
2006 spin_unlock_bh(&dcb_lock);
2008 EXPORT_SYMBOL(dcb_ieee_getapp_prio_dscp_mask_map);
2011 * dcb_ieee_getapp_dscp_prio_mask_map - For a given device, find mapping from
2012 * DSCP values to the priorities assigned to that DSCP value. Initialize p_map
2013 * such that each map element holds a bit mask of priorities configured for a
2014 * given DSCP value by APP entries.
2017 dcb_ieee_getapp_dscp_prio_mask_map(const struct net_device *dev,
2018 struct dcb_ieee_app_dscp_map *p_map)
2020 int ifindex = dev->ifindex;
2021 struct dcb_app_type *itr;
2023 memset(p_map->map, 0, sizeof(p_map->map));
2025 spin_lock_bh(&dcb_lock);
2026 list_for_each_entry(itr, &dcb_app_list, list) {
2027 if (itr->ifindex == ifindex &&
2028 itr->app.selector == IEEE_8021QAZ_APP_SEL_DSCP &&
2029 itr->app.protocol < 64 &&
2030 itr->app.priority < IEEE_8021QAZ_MAX_TCS)
2031 p_map->map[itr->app.protocol] |= 1 << itr->app.priority;
2033 spin_unlock_bh(&dcb_lock);
2035 EXPORT_SYMBOL(dcb_ieee_getapp_dscp_prio_mask_map);
2038 * Per 802.1Q-2014, the selector value of 1 is used for matching on Ethernet
2039 * type, with valid PID values >= 1536. A special meaning is then assigned to
2040 * protocol value of 0: "default priority. For use when priority is not
2041 * otherwise specified".
2043 * dcb_ieee_getapp_default_prio_mask - For a given device, find all APP entries
2044 * of the form {$PRIO, ETHERTYPE, 0} and construct a bit mask of all default
2045 * priorities set by these entries.
2047 u8 dcb_ieee_getapp_default_prio_mask(const struct net_device *dev)
2049 int ifindex = dev->ifindex;
2050 struct dcb_app_type *itr;
2053 spin_lock_bh(&dcb_lock);
2054 list_for_each_entry(itr, &dcb_app_list, list) {
2055 if (itr->ifindex == ifindex &&
2056 itr->app.selector == IEEE_8021QAZ_APP_SEL_ETHERTYPE &&
2057 itr->app.protocol == 0 &&
2058 itr->app.priority < IEEE_8021QAZ_MAX_TCS)
2059 mask |= 1 << itr->app.priority;
2061 spin_unlock_bh(&dcb_lock);
2065 EXPORT_SYMBOL(dcb_ieee_getapp_default_prio_mask);
2067 static int __init dcbnl_init(void)
2069 INIT_LIST_HEAD(&dcb_app_list);
2071 rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL, 0);
2072 rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL, 0);
2076 device_initcall(dcbnl_init);