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
17 * Author: Lucy Liu <lucy.liu@intel.com>
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(data
, DCB_PFC_UP_ATTR_MAX
,
245 tb
[DCB_ATTR_PFC_CFG
], dcbnl_pfc_up_nest
, NULL
);
249 nest
= nla_nest_start(skb
, DCB_ATTR_PFC_CFG
);
253 if (data
[DCB_PFC_UP_ATTR_ALL
])
256 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
257 if (!getall
&& !data
[i
])
260 netdev
->dcbnl_ops
->getpfccfg(netdev
, i
- DCB_PFC_UP_ATTR_0
,
262 ret
= nla_put_u8(skb
, i
, value
);
264 nla_nest_cancel(skb
, nest
);
268 nla_nest_end(skb
, nest
);
273 static int dcbnl_getperm_hwaddr(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
274 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
276 u8 perm_addr
[MAX_ADDR_LEN
];
278 if (!netdev
->dcbnl_ops
->getpermhwaddr
)
281 memset(perm_addr
, 0, sizeof(perm_addr
));
282 netdev
->dcbnl_ops
->getpermhwaddr(netdev
, perm_addr
);
284 return nla_put(skb
, DCB_ATTR_PERM_HWADDR
, sizeof(perm_addr
), perm_addr
);
287 static int dcbnl_getcap(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
288 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
290 struct nlattr
*data
[DCB_CAP_ATTR_MAX
+ 1], *nest
;
296 if (!tb
[DCB_ATTR_CAP
])
299 if (!netdev
->dcbnl_ops
->getcap
)
302 ret
= nla_parse_nested(data
, DCB_CAP_ATTR_MAX
, tb
[DCB_ATTR_CAP
],
303 dcbnl_cap_nest
, NULL
);
307 nest
= nla_nest_start(skb
, DCB_ATTR_CAP
);
311 if (data
[DCB_CAP_ATTR_ALL
])
314 for (i
= DCB_CAP_ATTR_ALL
+1; i
<= DCB_CAP_ATTR_MAX
; i
++) {
315 if (!getall
&& !data
[i
])
318 if (!netdev
->dcbnl_ops
->getcap(netdev
, i
, &value
)) {
319 ret
= nla_put_u8(skb
, i
, value
);
321 nla_nest_cancel(skb
, nest
);
326 nla_nest_end(skb
, nest
);
331 static int dcbnl_getnumtcs(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
332 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
334 struct nlattr
*data
[DCB_NUMTCS_ATTR_MAX
+ 1], *nest
;
340 if (!tb
[DCB_ATTR_NUMTCS
])
343 if (!netdev
->dcbnl_ops
->getnumtcs
)
346 ret
= nla_parse_nested(data
, DCB_NUMTCS_ATTR_MAX
, tb
[DCB_ATTR_NUMTCS
],
347 dcbnl_numtcs_nest
, NULL
);
351 nest
= nla_nest_start(skb
, DCB_ATTR_NUMTCS
);
355 if (data
[DCB_NUMTCS_ATTR_ALL
])
358 for (i
= DCB_NUMTCS_ATTR_ALL
+1; i
<= DCB_NUMTCS_ATTR_MAX
; i
++) {
359 if (!getall
&& !data
[i
])
362 ret
= netdev
->dcbnl_ops
->getnumtcs(netdev
, i
, &value
);
364 ret
= nla_put_u8(skb
, i
, value
);
366 nla_nest_cancel(skb
, nest
);
372 nla_nest_end(skb
, nest
);
377 static int dcbnl_setnumtcs(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
378 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
380 struct nlattr
*data
[DCB_NUMTCS_ATTR_MAX
+ 1];
385 if (!tb
[DCB_ATTR_NUMTCS
])
388 if (!netdev
->dcbnl_ops
->setnumtcs
)
391 ret
= nla_parse_nested(data
, DCB_NUMTCS_ATTR_MAX
, tb
[DCB_ATTR_NUMTCS
],
392 dcbnl_numtcs_nest
, NULL
);
396 for (i
= DCB_NUMTCS_ATTR_ALL
+1; i
<= DCB_NUMTCS_ATTR_MAX
; i
++) {
400 value
= nla_get_u8(data
[i
]);
402 ret
= netdev
->dcbnl_ops
->setnumtcs(netdev
, i
, value
);
407 return nla_put_u8(skb
, DCB_ATTR_NUMTCS
, !!ret
);
410 static int dcbnl_getpfcstate(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
411 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
413 if (!netdev
->dcbnl_ops
->getpfcstate
)
416 return nla_put_u8(skb
, DCB_ATTR_PFC_STATE
,
417 netdev
->dcbnl_ops
->getpfcstate(netdev
));
420 static int dcbnl_setpfcstate(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
421 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
425 if (!tb
[DCB_ATTR_PFC_STATE
])
428 if (!netdev
->dcbnl_ops
->setpfcstate
)
431 value
= nla_get_u8(tb
[DCB_ATTR_PFC_STATE
]);
433 netdev
->dcbnl_ops
->setpfcstate(netdev
, value
);
435 return nla_put_u8(skb
, DCB_ATTR_PFC_STATE
, 0);
438 static int dcbnl_getapp(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
439 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
441 struct nlattr
*app_nest
;
442 struct nlattr
*app_tb
[DCB_APP_ATTR_MAX
+ 1];
447 if (!tb
[DCB_ATTR_APP
])
450 ret
= nla_parse_nested(app_tb
, DCB_APP_ATTR_MAX
, tb
[DCB_ATTR_APP
],
451 dcbnl_app_nest
, NULL
);
455 /* all must be non-null */
456 if ((!app_tb
[DCB_APP_ATTR_IDTYPE
]) ||
457 (!app_tb
[DCB_APP_ATTR_ID
]))
460 /* either by eth type or by socket number */
461 idtype
= nla_get_u8(app_tb
[DCB_APP_ATTR_IDTYPE
]);
462 if ((idtype
!= DCB_APP_IDTYPE_ETHTYPE
) &&
463 (idtype
!= DCB_APP_IDTYPE_PORTNUM
))
466 id
= nla_get_u16(app_tb
[DCB_APP_ATTR_ID
]);
468 if (netdev
->dcbnl_ops
->getapp
) {
469 ret
= netdev
->dcbnl_ops
->getapp(netdev
, idtype
, id
);
475 struct dcb_app app
= {
479 up
= dcb_getapp(netdev
, &app
);
482 app_nest
= nla_nest_start(skb
, DCB_ATTR_APP
);
486 ret
= nla_put_u8(skb
, DCB_APP_ATTR_IDTYPE
, idtype
);
490 ret
= nla_put_u16(skb
, DCB_APP_ATTR_ID
, id
);
494 ret
= nla_put_u8(skb
, DCB_APP_ATTR_PRIORITY
, up
);
498 nla_nest_end(skb
, app_nest
);
503 nla_nest_cancel(skb
, app_nest
);
507 static int dcbnl_setapp(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
508 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
513 struct nlattr
*app_tb
[DCB_APP_ATTR_MAX
+ 1];
515 if (!tb
[DCB_ATTR_APP
])
518 ret
= nla_parse_nested(app_tb
, DCB_APP_ATTR_MAX
, tb
[DCB_ATTR_APP
],
519 dcbnl_app_nest
, NULL
);
523 /* all must be non-null */
524 if ((!app_tb
[DCB_APP_ATTR_IDTYPE
]) ||
525 (!app_tb
[DCB_APP_ATTR_ID
]) ||
526 (!app_tb
[DCB_APP_ATTR_PRIORITY
]))
529 /* either by eth type or by socket number */
530 idtype
= nla_get_u8(app_tb
[DCB_APP_ATTR_IDTYPE
]);
531 if ((idtype
!= DCB_APP_IDTYPE_ETHTYPE
) &&
532 (idtype
!= DCB_APP_IDTYPE_PORTNUM
))
535 id
= nla_get_u16(app_tb
[DCB_APP_ATTR_ID
]);
536 up
= nla_get_u8(app_tb
[DCB_APP_ATTR_PRIORITY
]);
538 if (netdev
->dcbnl_ops
->setapp
) {
539 ret
= netdev
->dcbnl_ops
->setapp(netdev
, idtype
, id
, up
);
544 app
.selector
= idtype
;
547 ret
= dcb_setapp(netdev
, &app
);
550 ret
= nla_put_u8(skb
, DCB_ATTR_APP
, ret
);
551 dcbnl_cee_notify(netdev
, RTM_SETDCB
, DCB_CMD_SAPP
, seq
, 0);
556 static int __dcbnl_pg_getcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
557 struct nlattr
**tb
, struct sk_buff
*skb
, int dir
)
559 struct nlattr
*pg_nest
, *param_nest
, *data
;
560 struct nlattr
*pg_tb
[DCB_PG_ATTR_MAX
+ 1];
561 struct nlattr
*param_tb
[DCB_TC_ATTR_PARAM_MAX
+ 1];
562 u8 prio
, pgid
, tc_pct
, up_map
;
567 if (!tb
[DCB_ATTR_PG_CFG
])
570 if (!netdev
->dcbnl_ops
->getpgtccfgtx
||
571 !netdev
->dcbnl_ops
->getpgtccfgrx
||
572 !netdev
->dcbnl_ops
->getpgbwgcfgtx
||
573 !netdev
->dcbnl_ops
->getpgbwgcfgrx
)
576 ret
= nla_parse_nested(pg_tb
, DCB_PG_ATTR_MAX
, tb
[DCB_ATTR_PG_CFG
],
577 dcbnl_pg_nest
, NULL
);
581 pg_nest
= nla_nest_start(skb
, DCB_ATTR_PG_CFG
);
585 if (pg_tb
[DCB_PG_ATTR_TC_ALL
])
588 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
589 if (!getall
&& !pg_tb
[i
])
592 if (pg_tb
[DCB_PG_ATTR_TC_ALL
])
593 data
= pg_tb
[DCB_PG_ATTR_TC_ALL
];
596 ret
= nla_parse_nested(param_tb
, DCB_TC_ATTR_PARAM_MAX
, data
,
597 dcbnl_tc_param_nest
, NULL
);
601 param_nest
= nla_nest_start(skb
, i
);
605 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
606 prio
= DCB_ATTR_VALUE_UNDEFINED
;
607 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
608 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
612 netdev
->dcbnl_ops
->getpgtccfgrx(netdev
,
613 i
- DCB_PG_ATTR_TC_0
, &prio
,
614 &pgid
, &tc_pct
, &up_map
);
617 netdev
->dcbnl_ops
->getpgtccfgtx(netdev
,
618 i
- DCB_PG_ATTR_TC_0
, &prio
,
619 &pgid
, &tc_pct
, &up_map
);
622 if (param_tb
[DCB_TC_ATTR_PARAM_PGID
] ||
623 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
624 ret
= nla_put_u8(skb
,
625 DCB_TC_ATTR_PARAM_PGID
, pgid
);
629 if (param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
] ||
630 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
631 ret
= nla_put_u8(skb
,
632 DCB_TC_ATTR_PARAM_UP_MAPPING
, up_map
);
636 if (param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
] ||
637 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
638 ret
= nla_put_u8(skb
,
639 DCB_TC_ATTR_PARAM_STRICT_PRIO
, prio
);
643 if (param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
] ||
644 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
645 ret
= nla_put_u8(skb
, DCB_TC_ATTR_PARAM_BW_PCT
,
650 nla_nest_end(skb
, param_nest
);
653 if (pg_tb
[DCB_PG_ATTR_BW_ID_ALL
])
658 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
659 if (!getall
&& !pg_tb
[i
])
662 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
666 netdev
->dcbnl_ops
->getpgbwgcfgrx(netdev
,
667 i
- DCB_PG_ATTR_BW_ID_0
, &tc_pct
);
670 netdev
->dcbnl_ops
->getpgbwgcfgtx(netdev
,
671 i
- DCB_PG_ATTR_BW_ID_0
, &tc_pct
);
673 ret
= nla_put_u8(skb
, i
, tc_pct
);
678 nla_nest_end(skb
, pg_nest
);
683 nla_nest_cancel(skb
, param_nest
);
685 nla_nest_cancel(skb
, pg_nest
);
690 static int dcbnl_pgtx_getcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
691 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
693 return __dcbnl_pg_getcfg(netdev
, nlh
, tb
, skb
, 0);
696 static int dcbnl_pgrx_getcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
697 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
699 return __dcbnl_pg_getcfg(netdev
, nlh
, tb
, skb
, 1);
702 static int dcbnl_setstate(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
703 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
707 if (!tb
[DCB_ATTR_STATE
])
710 if (!netdev
->dcbnl_ops
->setstate
)
713 value
= nla_get_u8(tb
[DCB_ATTR_STATE
]);
715 return nla_put_u8(skb
, DCB_ATTR_STATE
,
716 netdev
->dcbnl_ops
->setstate(netdev
, value
));
719 static int dcbnl_setpfccfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
720 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
722 struct nlattr
*data
[DCB_PFC_UP_ATTR_MAX
+ 1];
727 if (!tb
[DCB_ATTR_PFC_CFG
])
730 if (!netdev
->dcbnl_ops
->setpfccfg
)
733 ret
= nla_parse_nested(data
, DCB_PFC_UP_ATTR_MAX
,
734 tb
[DCB_ATTR_PFC_CFG
], dcbnl_pfc_up_nest
, NULL
);
738 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
741 value
= nla_get_u8(data
[i
]);
742 netdev
->dcbnl_ops
->setpfccfg(netdev
,
743 data
[i
]->nla_type
- DCB_PFC_UP_ATTR_0
, value
);
746 return nla_put_u8(skb
, DCB_ATTR_PFC_CFG
, 0);
749 static int dcbnl_setall(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
750 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
754 if (!tb
[DCB_ATTR_SET_ALL
])
757 if (!netdev
->dcbnl_ops
->setall
)
760 ret
= nla_put_u8(skb
, DCB_ATTR_SET_ALL
,
761 netdev
->dcbnl_ops
->setall(netdev
));
762 dcbnl_cee_notify(netdev
, RTM_SETDCB
, DCB_CMD_SET_ALL
, seq
, 0);
767 static int __dcbnl_pg_setcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
768 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
,
771 struct nlattr
*pg_tb
[DCB_PG_ATTR_MAX
+ 1];
772 struct nlattr
*param_tb
[DCB_TC_ATTR_PARAM_MAX
+ 1];
780 if (!tb
[DCB_ATTR_PG_CFG
])
783 if (!netdev
->dcbnl_ops
->setpgtccfgtx
||
784 !netdev
->dcbnl_ops
->setpgtccfgrx
||
785 !netdev
->dcbnl_ops
->setpgbwgcfgtx
||
786 !netdev
->dcbnl_ops
->setpgbwgcfgrx
)
789 ret
= nla_parse_nested(pg_tb
, DCB_PG_ATTR_MAX
, tb
[DCB_ATTR_PG_CFG
],
790 dcbnl_pg_nest
, NULL
);
794 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
798 ret
= nla_parse_nested(param_tb
, DCB_TC_ATTR_PARAM_MAX
,
799 pg_tb
[i
], dcbnl_tc_param_nest
, NULL
);
803 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
804 prio
= DCB_ATTR_VALUE_UNDEFINED
;
805 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
806 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
808 if (param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
])
810 nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
]);
812 if (param_tb
[DCB_TC_ATTR_PARAM_PGID
])
813 pgid
= nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_PGID
]);
815 if (param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
])
816 tc_pct
= nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
]);
818 if (param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
])
820 nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
]);
822 /* dir: Tx = 0, Rx = 1 */
825 netdev
->dcbnl_ops
->setpgtccfgrx(netdev
,
826 i
- DCB_PG_ATTR_TC_0
,
827 prio
, pgid
, tc_pct
, up_map
);
830 netdev
->dcbnl_ops
->setpgtccfgtx(netdev
,
831 i
- DCB_PG_ATTR_TC_0
,
832 prio
, pgid
, tc_pct
, up_map
);
836 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
840 tc_pct
= nla_get_u8(pg_tb
[i
]);
842 /* dir: Tx = 0, Rx = 1 */
845 netdev
->dcbnl_ops
->setpgbwgcfgrx(netdev
,
846 i
- DCB_PG_ATTR_BW_ID_0
, tc_pct
);
849 netdev
->dcbnl_ops
->setpgbwgcfgtx(netdev
,
850 i
- DCB_PG_ATTR_BW_ID_0
, tc_pct
);
854 return nla_put_u8(skb
, DCB_ATTR_PG_CFG
, 0);
857 static int dcbnl_pgtx_setcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
858 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
860 return __dcbnl_pg_setcfg(netdev
, nlh
, seq
, tb
, skb
, 0);
863 static int dcbnl_pgrx_setcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
864 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
866 return __dcbnl_pg_setcfg(netdev
, nlh
, seq
, tb
, skb
, 1);
869 static int dcbnl_bcn_getcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
870 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
872 struct nlattr
*bcn_nest
;
873 struct nlattr
*bcn_tb
[DCB_BCN_ATTR_MAX
+ 1];
880 if (!tb
[DCB_ATTR_BCN
])
883 if (!netdev
->dcbnl_ops
->getbcnrp
||
884 !netdev
->dcbnl_ops
->getbcncfg
)
887 ret
= nla_parse_nested(bcn_tb
, DCB_BCN_ATTR_MAX
, tb
[DCB_ATTR_BCN
],
888 dcbnl_bcn_nest
, NULL
);
892 bcn_nest
= nla_nest_start(skb
, DCB_ATTR_BCN
);
896 if (bcn_tb
[DCB_BCN_ATTR_ALL
])
899 for (i
= DCB_BCN_ATTR_RP_0
; i
<= DCB_BCN_ATTR_RP_7
; i
++) {
900 if (!getall
&& !bcn_tb
[i
])
903 netdev
->dcbnl_ops
->getbcnrp(netdev
, i
- DCB_BCN_ATTR_RP_0
,
905 ret
= nla_put_u8(skb
, i
, value_byte
);
910 for (i
= DCB_BCN_ATTR_BCNA_0
; i
<= DCB_BCN_ATTR_RI
; i
++) {
911 if (!getall
&& !bcn_tb
[i
])
914 netdev
->dcbnl_ops
->getbcncfg(netdev
, i
,
916 ret
= nla_put_u32(skb
, i
, value_integer
);
921 nla_nest_end(skb
, bcn_nest
);
926 nla_nest_cancel(skb
, bcn_nest
);
930 static int dcbnl_bcn_setcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
931 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
933 struct nlattr
*data
[DCB_BCN_ATTR_MAX
+ 1];
939 if (!tb
[DCB_ATTR_BCN
])
942 if (!netdev
->dcbnl_ops
->setbcncfg
||
943 !netdev
->dcbnl_ops
->setbcnrp
)
946 ret
= nla_parse_nested(data
, DCB_BCN_ATTR_MAX
, tb
[DCB_ATTR_BCN
],
947 dcbnl_pfc_up_nest
, NULL
);
951 for (i
= DCB_BCN_ATTR_RP_0
; i
<= DCB_BCN_ATTR_RP_7
; i
++) {
954 value_byte
= nla_get_u8(data
[i
]);
955 netdev
->dcbnl_ops
->setbcnrp(netdev
,
956 data
[i
]->nla_type
- DCB_BCN_ATTR_RP_0
, value_byte
);
959 for (i
= DCB_BCN_ATTR_BCNA_0
; i
<= DCB_BCN_ATTR_RI
; i
++) {
962 value_int
= nla_get_u32(data
[i
]);
963 netdev
->dcbnl_ops
->setbcncfg(netdev
,
967 return nla_put_u8(skb
, DCB_ATTR_BCN
, 0);
970 static int dcbnl_build_peer_app(struct net_device
*netdev
, struct sk_buff
* skb
,
971 int app_nested_type
, int app_info_type
,
974 struct dcb_peer_app_info info
;
975 struct dcb_app
*table
= NULL
;
976 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
982 * retrieve the peer app configuration form the driver. If the driver
983 * handlers fail exit without doing anything
985 err
= ops
->peer_getappinfo(netdev
, &info
, &app_count
);
986 if (!err
&& app_count
) {
987 table
= kmalloc_array(app_count
, sizeof(struct dcb_app
),
992 err
= ops
->peer_getapptable(netdev
, table
);
1000 * build the message, from here on the only possible failure
1001 * is due to the skb size
1005 app
= nla_nest_start(skb
, app_nested_type
);
1007 goto nla_put_failure
;
1009 if (app_info_type
&&
1010 nla_put(skb
, app_info_type
, sizeof(info
), &info
))
1011 goto nla_put_failure
;
1013 for (i
= 0; i
< app_count
; i
++) {
1014 if (nla_put(skb
, app_entry_type
, sizeof(struct dcb_app
),
1016 goto nla_put_failure
;
1018 nla_nest_end(skb
, app
);
1027 /* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb GET commands. */
1028 static int dcbnl_ieee_fill(struct sk_buff
*skb
, struct net_device
*netdev
)
1030 struct nlattr
*ieee
, *app
;
1031 struct dcb_app_type
*itr
;
1032 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1036 if (nla_put_string(skb
, DCB_ATTR_IFNAME
, netdev
->name
))
1039 ieee
= nla_nest_start(skb
, DCB_ATTR_IEEE
);
1043 if (ops
->ieee_getets
) {
1044 struct ieee_ets ets
;
1045 memset(&ets
, 0, sizeof(ets
));
1046 err
= ops
->ieee_getets(netdev
, &ets
);
1048 nla_put(skb
, DCB_ATTR_IEEE_ETS
, sizeof(ets
), &ets
))
1052 if (ops
->ieee_getmaxrate
) {
1053 struct ieee_maxrate maxrate
;
1054 memset(&maxrate
, 0, sizeof(maxrate
));
1055 err
= ops
->ieee_getmaxrate(netdev
, &maxrate
);
1057 err
= nla_put(skb
, DCB_ATTR_IEEE_MAXRATE
,
1058 sizeof(maxrate
), &maxrate
);
1064 if (ops
->ieee_getqcn
) {
1065 struct ieee_qcn qcn
;
1067 memset(&qcn
, 0, sizeof(qcn
));
1068 err
= ops
->ieee_getqcn(netdev
, &qcn
);
1070 err
= nla_put(skb
, DCB_ATTR_IEEE_QCN
,
1077 if (ops
->ieee_getqcnstats
) {
1078 struct ieee_qcn_stats qcn_stats
;
1080 memset(&qcn_stats
, 0, sizeof(qcn_stats
));
1081 err
= ops
->ieee_getqcnstats(netdev
, &qcn_stats
);
1083 err
= nla_put(skb
, DCB_ATTR_IEEE_QCN_STATS
,
1084 sizeof(qcn_stats
), &qcn_stats
);
1090 if (ops
->ieee_getpfc
) {
1091 struct ieee_pfc pfc
;
1092 memset(&pfc
, 0, sizeof(pfc
));
1093 err
= ops
->ieee_getpfc(netdev
, &pfc
);
1095 nla_put(skb
, DCB_ATTR_IEEE_PFC
, sizeof(pfc
), &pfc
))
1099 if (ops
->dcbnl_getbuffer
) {
1100 struct dcbnl_buffer buffer
;
1102 memset(&buffer
, 0, sizeof(buffer
));
1103 err
= ops
->dcbnl_getbuffer(netdev
, &buffer
);
1105 nla_put(skb
, DCB_ATTR_DCB_BUFFER
, sizeof(buffer
), &buffer
))
1109 app
= nla_nest_start(skb
, DCB_ATTR_IEEE_APP_TABLE
);
1113 spin_lock_bh(&dcb_lock
);
1114 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1115 if (itr
->ifindex
== netdev
->ifindex
) {
1116 err
= nla_put(skb
, DCB_ATTR_IEEE_APP
, sizeof(itr
->app
),
1119 spin_unlock_bh(&dcb_lock
);
1125 if (netdev
->dcbnl_ops
->getdcbx
)
1126 dcbx
= netdev
->dcbnl_ops
->getdcbx(netdev
);
1130 spin_unlock_bh(&dcb_lock
);
1131 nla_nest_end(skb
, app
);
1133 /* get peer info if available */
1134 if (ops
->ieee_peer_getets
) {
1135 struct ieee_ets ets
;
1136 memset(&ets
, 0, sizeof(ets
));
1137 err
= ops
->ieee_peer_getets(netdev
, &ets
);
1139 nla_put(skb
, DCB_ATTR_IEEE_PEER_ETS
, sizeof(ets
), &ets
))
1143 if (ops
->ieee_peer_getpfc
) {
1144 struct ieee_pfc pfc
;
1145 memset(&pfc
, 0, sizeof(pfc
));
1146 err
= ops
->ieee_peer_getpfc(netdev
, &pfc
);
1148 nla_put(skb
, DCB_ATTR_IEEE_PEER_PFC
, sizeof(pfc
), &pfc
))
1152 if (ops
->peer_getappinfo
&& ops
->peer_getapptable
) {
1153 err
= dcbnl_build_peer_app(netdev
, skb
,
1154 DCB_ATTR_IEEE_PEER_APP
,
1155 DCB_ATTR_IEEE_APP_UNSPEC
,
1161 nla_nest_end(skb
, ieee
);
1163 err
= nla_put_u8(skb
, DCB_ATTR_DCBX
, dcbx
);
1171 static int dcbnl_cee_pg_fill(struct sk_buff
*skb
, struct net_device
*dev
,
1174 u8 pgid
, up_map
, prio
, tc_pct
;
1175 const struct dcbnl_rtnl_ops
*ops
= dev
->dcbnl_ops
;
1176 int i
= dir
? DCB_ATTR_CEE_TX_PG
: DCB_ATTR_CEE_RX_PG
;
1177 struct nlattr
*pg
= nla_nest_start(skb
, i
);
1182 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
1183 struct nlattr
*tc_nest
= nla_nest_start(skb
, i
);
1188 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
1189 prio
= DCB_ATTR_VALUE_UNDEFINED
;
1190 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
1191 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
1194 ops
->getpgtccfgrx(dev
, i
- DCB_PG_ATTR_TC_0
,
1195 &prio
, &pgid
, &tc_pct
, &up_map
);
1197 ops
->getpgtccfgtx(dev
, i
- DCB_PG_ATTR_TC_0
,
1198 &prio
, &pgid
, &tc_pct
, &up_map
);
1200 if (nla_put_u8(skb
, DCB_TC_ATTR_PARAM_PGID
, pgid
) ||
1201 nla_put_u8(skb
, DCB_TC_ATTR_PARAM_UP_MAPPING
, up_map
) ||
1202 nla_put_u8(skb
, DCB_TC_ATTR_PARAM_STRICT_PRIO
, prio
) ||
1203 nla_put_u8(skb
, DCB_TC_ATTR_PARAM_BW_PCT
, tc_pct
))
1205 nla_nest_end(skb
, tc_nest
);
1208 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
1209 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
1212 ops
->getpgbwgcfgrx(dev
, i
- DCB_PG_ATTR_BW_ID_0
,
1215 ops
->getpgbwgcfgtx(dev
, i
- DCB_PG_ATTR_BW_ID_0
,
1217 if (nla_put_u8(skb
, i
, tc_pct
))
1220 nla_nest_end(skb
, pg
);
1224 static int dcbnl_cee_fill(struct sk_buff
*skb
, struct net_device
*netdev
)
1226 struct nlattr
*cee
, *app
;
1227 struct dcb_app_type
*itr
;
1228 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1229 int dcbx
, i
, err
= -EMSGSIZE
;
1232 if (nla_put_string(skb
, DCB_ATTR_IFNAME
, netdev
->name
))
1233 goto nla_put_failure
;
1234 cee
= nla_nest_start(skb
, DCB_ATTR_CEE
);
1236 goto nla_put_failure
;
1239 if (ops
->getpgtccfgtx
&& ops
->getpgbwgcfgtx
) {
1240 err
= dcbnl_cee_pg_fill(skb
, netdev
, 1);
1242 goto nla_put_failure
;
1245 if (ops
->getpgtccfgrx
&& ops
->getpgbwgcfgrx
) {
1246 err
= dcbnl_cee_pg_fill(skb
, netdev
, 0);
1248 goto nla_put_failure
;
1252 if (ops
->getpfccfg
) {
1253 struct nlattr
*pfc_nest
= nla_nest_start(skb
, DCB_ATTR_CEE_PFC
);
1256 goto nla_put_failure
;
1258 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
1259 ops
->getpfccfg(netdev
, i
- DCB_PFC_UP_ATTR_0
, &value
);
1260 if (nla_put_u8(skb
, i
, value
))
1261 goto nla_put_failure
;
1263 nla_nest_end(skb
, pfc_nest
);
1267 spin_lock_bh(&dcb_lock
);
1268 app
= nla_nest_start(skb
, DCB_ATTR_CEE_APP_TABLE
);
1272 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1273 if (itr
->ifindex
== netdev
->ifindex
) {
1274 struct nlattr
*app_nest
= nla_nest_start(skb
,
1279 err
= nla_put_u8(skb
, DCB_APP_ATTR_IDTYPE
,
1284 err
= nla_put_u16(skb
, DCB_APP_ATTR_ID
,
1289 err
= nla_put_u8(skb
, DCB_APP_ATTR_PRIORITY
,
1294 nla_nest_end(skb
, app_nest
);
1297 nla_nest_end(skb
, app
);
1299 if (netdev
->dcbnl_ops
->getdcbx
)
1300 dcbx
= netdev
->dcbnl_ops
->getdcbx(netdev
);
1304 spin_unlock_bh(&dcb_lock
);
1306 /* features flags */
1307 if (ops
->getfeatcfg
) {
1308 struct nlattr
*feat
= nla_nest_start(skb
, DCB_ATTR_CEE_FEAT
);
1310 goto nla_put_failure
;
1312 for (i
= DCB_FEATCFG_ATTR_ALL
+ 1; i
<= DCB_FEATCFG_ATTR_MAX
;
1314 if (!ops
->getfeatcfg(netdev
, i
, &value
) &&
1315 nla_put_u8(skb
, i
, value
))
1316 goto nla_put_failure
;
1318 nla_nest_end(skb
, feat
);
1321 /* peer info if available */
1322 if (ops
->cee_peer_getpg
) {
1324 memset(&pg
, 0, sizeof(pg
));
1325 err
= ops
->cee_peer_getpg(netdev
, &pg
);
1327 nla_put(skb
, DCB_ATTR_CEE_PEER_PG
, sizeof(pg
), &pg
))
1328 goto nla_put_failure
;
1331 if (ops
->cee_peer_getpfc
) {
1333 memset(&pfc
, 0, sizeof(pfc
));
1334 err
= ops
->cee_peer_getpfc(netdev
, &pfc
);
1336 nla_put(skb
, DCB_ATTR_CEE_PEER_PFC
, sizeof(pfc
), &pfc
))
1337 goto nla_put_failure
;
1340 if (ops
->peer_getappinfo
&& ops
->peer_getapptable
) {
1341 err
= dcbnl_build_peer_app(netdev
, skb
,
1342 DCB_ATTR_CEE_PEER_APP_TABLE
,
1343 DCB_ATTR_CEE_PEER_APP_INFO
,
1344 DCB_ATTR_CEE_PEER_APP
);
1346 goto nla_put_failure
;
1348 nla_nest_end(skb
, cee
);
1352 err
= nla_put_u8(skb
, DCB_ATTR_DCBX
, dcbx
);
1354 goto nla_put_failure
;
1359 spin_unlock_bh(&dcb_lock
);
1365 static int dcbnl_notify(struct net_device
*dev
, int event
, int cmd
,
1366 u32 seq
, u32 portid
, int dcbx_ver
)
1368 struct net
*net
= dev_net(dev
);
1369 struct sk_buff
*skb
;
1370 struct nlmsghdr
*nlh
;
1371 const struct dcbnl_rtnl_ops
*ops
= dev
->dcbnl_ops
;
1377 skb
= dcbnl_newmsg(event
, cmd
, portid
, seq
, 0, &nlh
);
1381 if (dcbx_ver
== DCB_CAP_DCBX_VER_IEEE
)
1382 err
= dcbnl_ieee_fill(skb
, dev
);
1384 err
= dcbnl_cee_fill(skb
, dev
);
1387 /* Report error to broadcast listeners */
1389 rtnl_set_sk_err(net
, RTNLGRP_DCB
, err
);
1391 /* End nlmsg and notify broadcast listeners */
1392 nlmsg_end(skb
, nlh
);
1393 rtnl_notify(skb
, net
, 0, RTNLGRP_DCB
, NULL
, GFP_KERNEL
);
1399 int dcbnl_ieee_notify(struct net_device
*dev
, int event
, int cmd
,
1400 u32 seq
, u32 portid
)
1402 return dcbnl_notify(dev
, event
, cmd
, seq
, portid
, DCB_CAP_DCBX_VER_IEEE
);
1404 EXPORT_SYMBOL(dcbnl_ieee_notify
);
1406 int dcbnl_cee_notify(struct net_device
*dev
, int event
, int cmd
,
1407 u32 seq
, u32 portid
)
1409 return dcbnl_notify(dev
, event
, cmd
, seq
, portid
, DCB_CAP_DCBX_VER_CEE
);
1411 EXPORT_SYMBOL(dcbnl_cee_notify
);
1413 /* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb SET commands.
1414 * If any requested operation can not be completed
1415 * the entire msg is aborted and error value is returned.
1416 * No attempt is made to reconcile the case where only part of the
1417 * cmd can be completed.
1419 static int dcbnl_ieee_set(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1420 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1422 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1423 struct nlattr
*ieee
[DCB_ATTR_IEEE_MAX
+ 1];
1429 if (!tb
[DCB_ATTR_IEEE
])
1432 err
= nla_parse_nested(ieee
, DCB_ATTR_IEEE_MAX
, tb
[DCB_ATTR_IEEE
],
1433 dcbnl_ieee_policy
, NULL
);
1437 if (ieee
[DCB_ATTR_IEEE_ETS
] && ops
->ieee_setets
) {
1438 struct ieee_ets
*ets
= nla_data(ieee
[DCB_ATTR_IEEE_ETS
]);
1439 err
= ops
->ieee_setets(netdev
, ets
);
1444 if (ieee
[DCB_ATTR_IEEE_MAXRATE
] && ops
->ieee_setmaxrate
) {
1445 struct ieee_maxrate
*maxrate
=
1446 nla_data(ieee
[DCB_ATTR_IEEE_MAXRATE
]);
1447 err
= ops
->ieee_setmaxrate(netdev
, maxrate
);
1452 if (ieee
[DCB_ATTR_IEEE_QCN
] && ops
->ieee_setqcn
) {
1453 struct ieee_qcn
*qcn
=
1454 nla_data(ieee
[DCB_ATTR_IEEE_QCN
]);
1456 err
= ops
->ieee_setqcn(netdev
, qcn
);
1461 if (ieee
[DCB_ATTR_IEEE_PFC
] && ops
->ieee_setpfc
) {
1462 struct ieee_pfc
*pfc
= nla_data(ieee
[DCB_ATTR_IEEE_PFC
]);
1463 err
= ops
->ieee_setpfc(netdev
, pfc
);
1468 if (ieee
[DCB_ATTR_DCB_BUFFER
] && ops
->dcbnl_setbuffer
) {
1469 struct dcbnl_buffer
*buffer
=
1470 nla_data(ieee
[DCB_ATTR_DCB_BUFFER
]);
1472 err
= ops
->dcbnl_setbuffer(netdev
, buffer
);
1477 if (ieee
[DCB_ATTR_IEEE_APP_TABLE
]) {
1478 struct nlattr
*attr
;
1481 nla_for_each_nested(attr
, ieee
[DCB_ATTR_IEEE_APP_TABLE
], rem
) {
1482 struct dcb_app
*app_data
;
1484 if (nla_type(attr
) != DCB_ATTR_IEEE_APP
)
1487 if (nla_len(attr
) < sizeof(struct dcb_app
)) {
1492 app_data
= nla_data(attr
);
1493 if (ops
->ieee_setapp
)
1494 err
= ops
->ieee_setapp(netdev
, app_data
);
1496 err
= dcb_ieee_setapp(netdev
, app_data
);
1503 err
= nla_put_u8(skb
, DCB_ATTR_IEEE
, err
);
1504 dcbnl_ieee_notify(netdev
, RTM_SETDCB
, DCB_CMD_IEEE_SET
, seq
, 0);
1508 static int dcbnl_ieee_get(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1509 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1511 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1516 return dcbnl_ieee_fill(skb
, netdev
);
1519 static int dcbnl_ieee_del(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1520 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1522 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1523 struct nlattr
*ieee
[DCB_ATTR_IEEE_MAX
+ 1];
1529 if (!tb
[DCB_ATTR_IEEE
])
1532 err
= nla_parse_nested(ieee
, DCB_ATTR_IEEE_MAX
, tb
[DCB_ATTR_IEEE
],
1533 dcbnl_ieee_policy
, NULL
);
1537 if (ieee
[DCB_ATTR_IEEE_APP_TABLE
]) {
1538 struct nlattr
*attr
;
1541 nla_for_each_nested(attr
, ieee
[DCB_ATTR_IEEE_APP_TABLE
], rem
) {
1542 struct dcb_app
*app_data
;
1544 if (nla_type(attr
) != DCB_ATTR_IEEE_APP
)
1546 app_data
= nla_data(attr
);
1547 if (ops
->ieee_delapp
)
1548 err
= ops
->ieee_delapp(netdev
, app_data
);
1550 err
= dcb_ieee_delapp(netdev
, app_data
);
1557 err
= nla_put_u8(skb
, DCB_ATTR_IEEE
, err
);
1558 dcbnl_ieee_notify(netdev
, RTM_SETDCB
, DCB_CMD_IEEE_DEL
, seq
, 0);
1563 /* DCBX configuration */
1564 static int dcbnl_getdcbx(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1565 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1567 if (!netdev
->dcbnl_ops
->getdcbx
)
1570 return nla_put_u8(skb
, DCB_ATTR_DCBX
,
1571 netdev
->dcbnl_ops
->getdcbx(netdev
));
1574 static int dcbnl_setdcbx(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1575 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1579 if (!netdev
->dcbnl_ops
->setdcbx
)
1582 if (!tb
[DCB_ATTR_DCBX
])
1585 value
= nla_get_u8(tb
[DCB_ATTR_DCBX
]);
1587 return nla_put_u8(skb
, DCB_ATTR_DCBX
,
1588 netdev
->dcbnl_ops
->setdcbx(netdev
, value
));
1591 static int dcbnl_getfeatcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1592 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1594 struct nlattr
*data
[DCB_FEATCFG_ATTR_MAX
+ 1], *nest
;
1599 if (!netdev
->dcbnl_ops
->getfeatcfg
)
1602 if (!tb
[DCB_ATTR_FEATCFG
])
1605 ret
= nla_parse_nested(data
, DCB_FEATCFG_ATTR_MAX
,
1606 tb
[DCB_ATTR_FEATCFG
], dcbnl_featcfg_nest
, NULL
);
1610 nest
= nla_nest_start(skb
, DCB_ATTR_FEATCFG
);
1614 if (data
[DCB_FEATCFG_ATTR_ALL
])
1617 for (i
= DCB_FEATCFG_ATTR_ALL
+1; i
<= DCB_FEATCFG_ATTR_MAX
; i
++) {
1618 if (!getall
&& !data
[i
])
1621 ret
= netdev
->dcbnl_ops
->getfeatcfg(netdev
, i
, &value
);
1623 ret
= nla_put_u8(skb
, i
, value
);
1626 nla_nest_cancel(skb
, nest
);
1627 goto nla_put_failure
;
1630 nla_nest_end(skb
, nest
);
1636 static int dcbnl_setfeatcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1637 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1639 struct nlattr
*data
[DCB_FEATCFG_ATTR_MAX
+ 1];
1643 if (!netdev
->dcbnl_ops
->setfeatcfg
)
1646 if (!tb
[DCB_ATTR_FEATCFG
])
1649 ret
= nla_parse_nested(data
, DCB_FEATCFG_ATTR_MAX
,
1650 tb
[DCB_ATTR_FEATCFG
], dcbnl_featcfg_nest
, NULL
);
1655 for (i
= DCB_FEATCFG_ATTR_ALL
+1; i
<= DCB_FEATCFG_ATTR_MAX
; i
++) {
1656 if (data
[i
] == NULL
)
1659 value
= nla_get_u8(data
[i
]);
1661 ret
= netdev
->dcbnl_ops
->setfeatcfg(netdev
, i
, value
);
1667 ret
= nla_put_u8(skb
, DCB_ATTR_FEATCFG
, ret
);
1672 /* Handle CEE DCBX GET commands. */
1673 static int dcbnl_cee_get(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1674 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1676 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1681 return dcbnl_cee_fill(skb
, netdev
);
1685 /* reply netlink message type */
1688 /* function to fill message contents */
1689 int (*cb
)(struct net_device
*, struct nlmsghdr
*, u32
,
1690 struct nlattr
**, struct sk_buff
*);
1693 static const struct reply_func reply_funcs
[DCB_CMD_MAX
+1] = {
1694 [DCB_CMD_GSTATE
] = { RTM_GETDCB
, dcbnl_getstate
},
1695 [DCB_CMD_SSTATE
] = { RTM_SETDCB
, dcbnl_setstate
},
1696 [DCB_CMD_PFC_GCFG
] = { RTM_GETDCB
, dcbnl_getpfccfg
},
1697 [DCB_CMD_PFC_SCFG
] = { RTM_SETDCB
, dcbnl_setpfccfg
},
1698 [DCB_CMD_GPERM_HWADDR
] = { RTM_GETDCB
, dcbnl_getperm_hwaddr
},
1699 [DCB_CMD_GCAP
] = { RTM_GETDCB
, dcbnl_getcap
},
1700 [DCB_CMD_GNUMTCS
] = { RTM_GETDCB
, dcbnl_getnumtcs
},
1701 [DCB_CMD_SNUMTCS
] = { RTM_SETDCB
, dcbnl_setnumtcs
},
1702 [DCB_CMD_PFC_GSTATE
] = { RTM_GETDCB
, dcbnl_getpfcstate
},
1703 [DCB_CMD_PFC_SSTATE
] = { RTM_SETDCB
, dcbnl_setpfcstate
},
1704 [DCB_CMD_GAPP
] = { RTM_GETDCB
, dcbnl_getapp
},
1705 [DCB_CMD_SAPP
] = { RTM_SETDCB
, dcbnl_setapp
},
1706 [DCB_CMD_PGTX_GCFG
] = { RTM_GETDCB
, dcbnl_pgtx_getcfg
},
1707 [DCB_CMD_PGTX_SCFG
] = { RTM_SETDCB
, dcbnl_pgtx_setcfg
},
1708 [DCB_CMD_PGRX_GCFG
] = { RTM_GETDCB
, dcbnl_pgrx_getcfg
},
1709 [DCB_CMD_PGRX_SCFG
] = { RTM_SETDCB
, dcbnl_pgrx_setcfg
},
1710 [DCB_CMD_SET_ALL
] = { RTM_SETDCB
, dcbnl_setall
},
1711 [DCB_CMD_BCN_GCFG
] = { RTM_GETDCB
, dcbnl_bcn_getcfg
},
1712 [DCB_CMD_BCN_SCFG
] = { RTM_SETDCB
, dcbnl_bcn_setcfg
},
1713 [DCB_CMD_IEEE_GET
] = { RTM_GETDCB
, dcbnl_ieee_get
},
1714 [DCB_CMD_IEEE_SET
] = { RTM_SETDCB
, dcbnl_ieee_set
},
1715 [DCB_CMD_IEEE_DEL
] = { RTM_SETDCB
, dcbnl_ieee_del
},
1716 [DCB_CMD_GDCBX
] = { RTM_GETDCB
, dcbnl_getdcbx
},
1717 [DCB_CMD_SDCBX
] = { RTM_SETDCB
, dcbnl_setdcbx
},
1718 [DCB_CMD_GFEATCFG
] = { RTM_GETDCB
, dcbnl_getfeatcfg
},
1719 [DCB_CMD_SFEATCFG
] = { RTM_SETDCB
, dcbnl_setfeatcfg
},
1720 [DCB_CMD_CEE_GET
] = { RTM_GETDCB
, dcbnl_cee_get
},
1723 static int dcb_doit(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
1724 struct netlink_ext_ack
*extack
)
1726 struct net
*net
= sock_net(skb
->sk
);
1727 struct net_device
*netdev
;
1728 struct dcbmsg
*dcb
= nlmsg_data(nlh
);
1729 struct nlattr
*tb
[DCB_ATTR_MAX
+ 1];
1730 u32 portid
= skb
? NETLINK_CB(skb
).portid
: 0;
1732 struct sk_buff
*reply_skb
;
1733 struct nlmsghdr
*reply_nlh
= NULL
;
1734 const struct reply_func
*fn
;
1736 if ((nlh
->nlmsg_type
== RTM_SETDCB
) && !netlink_capable(skb
, CAP_NET_ADMIN
))
1739 ret
= nlmsg_parse(nlh
, sizeof(*dcb
), tb
, DCB_ATTR_MAX
,
1740 dcbnl_rtnl_policy
, extack
);
1744 if (dcb
->cmd
> DCB_CMD_MAX
)
1747 /* check if a reply function has been defined for the command */
1748 fn
= &reply_funcs
[dcb
->cmd
];
1752 if (!tb
[DCB_ATTR_IFNAME
])
1755 netdev
= __dev_get_by_name(net
, nla_data(tb
[DCB_ATTR_IFNAME
]));
1759 if (!netdev
->dcbnl_ops
)
1762 reply_skb
= dcbnl_newmsg(fn
->type
, dcb
->cmd
, portid
, nlh
->nlmsg_seq
,
1763 nlh
->nlmsg_flags
, &reply_nlh
);
1767 ret
= fn
->cb(netdev
, nlh
, nlh
->nlmsg_seq
, tb
, reply_skb
);
1769 nlmsg_free(reply_skb
);
1773 nlmsg_end(reply_skb
, reply_nlh
);
1775 ret
= rtnl_unicast(reply_skb
, net
, portid
);
1780 static struct dcb_app_type
*dcb_app_lookup(const struct dcb_app
*app
,
1781 int ifindex
, int prio
)
1783 struct dcb_app_type
*itr
;
1785 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1786 if (itr
->app
.selector
== app
->selector
&&
1787 itr
->app
.protocol
== app
->protocol
&&
1788 itr
->ifindex
== ifindex
&&
1789 (!prio
|| itr
->app
.priority
== prio
))
1796 static int dcb_app_add(const struct dcb_app
*app
, int ifindex
)
1798 struct dcb_app_type
*entry
;
1800 entry
= kmalloc(sizeof(*entry
), GFP_ATOMIC
);
1804 memcpy(&entry
->app
, app
, sizeof(*app
));
1805 entry
->ifindex
= ifindex
;
1806 list_add(&entry
->list
, &dcb_app_list
);
1812 * dcb_getapp - retrieve the DCBX application user priority
1814 * On success returns a non-zero 802.1p user priority bitmap
1815 * otherwise returns 0 as the invalid user priority bitmap to
1816 * indicate an error.
1818 u8
dcb_getapp(struct net_device
*dev
, struct dcb_app
*app
)
1820 struct dcb_app_type
*itr
;
1823 spin_lock_bh(&dcb_lock
);
1824 if ((itr
= dcb_app_lookup(app
, dev
->ifindex
, 0)))
1825 prio
= itr
->app
.priority
;
1826 spin_unlock_bh(&dcb_lock
);
1830 EXPORT_SYMBOL(dcb_getapp
);
1833 * dcb_setapp - add CEE dcb application data to app list
1835 * Priority 0 is an invalid priority in CEE spec. This routine
1836 * removes applications from the app list if the priority is
1837 * set to zero. Priority is expected to be 8-bit 802.1p user priority bitmap
1839 int dcb_setapp(struct net_device
*dev
, struct dcb_app
*new)
1841 struct dcb_app_type
*itr
;
1842 struct dcb_app_type event
;
1845 event
.ifindex
= dev
->ifindex
;
1846 memcpy(&event
.app
, new, sizeof(event
.app
));
1847 if (dev
->dcbnl_ops
->getdcbx
)
1848 event
.dcbx
= dev
->dcbnl_ops
->getdcbx(dev
);
1850 spin_lock_bh(&dcb_lock
);
1851 /* Search for existing match and replace */
1852 if ((itr
= dcb_app_lookup(new, dev
->ifindex
, 0))) {
1854 itr
->app
.priority
= new->priority
;
1856 list_del(&itr
->list
);
1861 /* App type does not exist add new application type */
1863 err
= dcb_app_add(new, dev
->ifindex
);
1865 spin_unlock_bh(&dcb_lock
);
1867 call_dcbevent_notifiers(DCB_APP_EVENT
, &event
);
1870 EXPORT_SYMBOL(dcb_setapp
);
1873 * dcb_ieee_getapp_mask - retrieve the IEEE DCB application priority
1875 * Helper routine which on success returns a non-zero 802.1Qaz user
1876 * priority bitmap otherwise returns 0 to indicate the dcb_app was
1877 * not found in APP list.
1879 u8
dcb_ieee_getapp_mask(struct net_device
*dev
, struct dcb_app
*app
)
1881 struct dcb_app_type
*itr
;
1884 spin_lock_bh(&dcb_lock
);
1885 if ((itr
= dcb_app_lookup(app
, dev
->ifindex
, 0)))
1886 prio
|= 1 << itr
->app
.priority
;
1887 spin_unlock_bh(&dcb_lock
);
1891 EXPORT_SYMBOL(dcb_ieee_getapp_mask
);
1894 * dcb_ieee_setapp - add IEEE dcb application data to app list
1896 * This adds Application data to the list. Multiple application
1897 * entries may exists for the same selector and protocol as long
1898 * as the priorities are different. Priority is expected to be a
1899 * 3-bit unsigned integer
1901 int dcb_ieee_setapp(struct net_device
*dev
, struct dcb_app
*new)
1903 struct dcb_app_type event
;
1906 event
.ifindex
= dev
->ifindex
;
1907 memcpy(&event
.app
, new, sizeof(event
.app
));
1908 if (dev
->dcbnl_ops
->getdcbx
)
1909 event
.dcbx
= dev
->dcbnl_ops
->getdcbx(dev
);
1911 spin_lock_bh(&dcb_lock
);
1912 /* Search for existing match and abort if found */
1913 if (dcb_app_lookup(new, dev
->ifindex
, new->priority
)) {
1918 err
= dcb_app_add(new, dev
->ifindex
);
1920 spin_unlock_bh(&dcb_lock
);
1922 call_dcbevent_notifiers(DCB_APP_EVENT
, &event
);
1925 EXPORT_SYMBOL(dcb_ieee_setapp
);
1928 * dcb_ieee_delapp - delete IEEE dcb application data from list
1930 * This removes a matching APP data from the APP list
1932 int dcb_ieee_delapp(struct net_device
*dev
, struct dcb_app
*del
)
1934 struct dcb_app_type
*itr
;
1935 struct dcb_app_type event
;
1938 event
.ifindex
= dev
->ifindex
;
1939 memcpy(&event
.app
, del
, sizeof(event
.app
));
1940 if (dev
->dcbnl_ops
->getdcbx
)
1941 event
.dcbx
= dev
->dcbnl_ops
->getdcbx(dev
);
1943 spin_lock_bh(&dcb_lock
);
1944 /* Search for existing match and remove it. */
1945 if ((itr
= dcb_app_lookup(del
, dev
->ifindex
, del
->priority
))) {
1946 list_del(&itr
->list
);
1951 spin_unlock_bh(&dcb_lock
);
1953 call_dcbevent_notifiers(DCB_APP_EVENT
, &event
);
1956 EXPORT_SYMBOL(dcb_ieee_delapp
);
1958 static int __init
dcbnl_init(void)
1960 INIT_LIST_HEAD(&dcb_app_list
);
1962 rtnl_register(PF_UNSPEC
, RTM_GETDCB
, dcb_doit
, NULL
, 0);
1963 rtnl_register(PF_UNSPEC
, RTM_SETDCB
, dcb_doit
, NULL
, 0);
1967 device_initcall(dcbnl_init
);