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, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
17 * Author: Lucy Liu <lucy.liu@intel.com>
20 #include <linux/netdevice.h>
21 #include <linux/netlink.h>
22 #include <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/module.h>
32 * Data Center Bridging (DCB) is a collection of Ethernet enhancements
33 * intended to allow network traffic with differing requirements
34 * (highly reliable, no drops vs. best effort vs. low latency) to operate
35 * and co-exist on Ethernet. Current DCB features are:
37 * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a
38 * framework for assigning bandwidth guarantees to traffic classes.
40 * Priority-based Flow Control (PFC) - provides a flow control mechanism which
41 * can work independently for each 802.1p priority.
43 * Congestion Notification - provides a mechanism for end-to-end congestion
44 * control for protocols which do not have built-in congestion management.
46 * More information about the emerging standards for these Ethernet features
47 * can be found at: http://www.ieee802.org/1/pages/dcbridges.html
49 * This file implements an rtnetlink interface to allow configuration of DCB
50 * features for capable devices.
53 MODULE_AUTHOR("Lucy Liu, <lucy.liu@intel.com>");
54 MODULE_DESCRIPTION("Data Center Bridging netlink interface");
55 MODULE_LICENSE("GPL");
57 /**************** DCB attribute policies *************************************/
59 /* DCB netlink attributes policy */
60 static const struct nla_policy dcbnl_rtnl_policy
[DCB_ATTR_MAX
+ 1] = {
61 [DCB_ATTR_IFNAME
] = {.type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
- 1},
62 [DCB_ATTR_STATE
] = {.type
= NLA_U8
},
63 [DCB_ATTR_PFC_CFG
] = {.type
= NLA_NESTED
},
64 [DCB_ATTR_PG_CFG
] = {.type
= NLA_NESTED
},
65 [DCB_ATTR_SET_ALL
] = {.type
= NLA_U8
},
66 [DCB_ATTR_PERM_HWADDR
] = {.type
= NLA_FLAG
},
67 [DCB_ATTR_CAP
] = {.type
= NLA_NESTED
},
68 [DCB_ATTR_PFC_STATE
] = {.type
= NLA_U8
},
69 [DCB_ATTR_BCN
] = {.type
= NLA_NESTED
},
70 [DCB_ATTR_APP
] = {.type
= NLA_NESTED
},
71 [DCB_ATTR_IEEE
] = {.type
= NLA_NESTED
},
72 [DCB_ATTR_DCBX
] = {.type
= NLA_U8
},
73 [DCB_ATTR_FEATCFG
] = {.type
= NLA_NESTED
},
76 /* DCB priority flow control to User Priority nested attributes */
77 static const struct nla_policy dcbnl_pfc_up_nest
[DCB_PFC_UP_ATTR_MAX
+ 1] = {
78 [DCB_PFC_UP_ATTR_0
] = {.type
= NLA_U8
},
79 [DCB_PFC_UP_ATTR_1
] = {.type
= NLA_U8
},
80 [DCB_PFC_UP_ATTR_2
] = {.type
= NLA_U8
},
81 [DCB_PFC_UP_ATTR_3
] = {.type
= NLA_U8
},
82 [DCB_PFC_UP_ATTR_4
] = {.type
= NLA_U8
},
83 [DCB_PFC_UP_ATTR_5
] = {.type
= NLA_U8
},
84 [DCB_PFC_UP_ATTR_6
] = {.type
= NLA_U8
},
85 [DCB_PFC_UP_ATTR_7
] = {.type
= NLA_U8
},
86 [DCB_PFC_UP_ATTR_ALL
] = {.type
= NLA_FLAG
},
89 /* DCB priority grouping nested attributes */
90 static const struct nla_policy dcbnl_pg_nest
[DCB_PG_ATTR_MAX
+ 1] = {
91 [DCB_PG_ATTR_TC_0
] = {.type
= NLA_NESTED
},
92 [DCB_PG_ATTR_TC_1
] = {.type
= NLA_NESTED
},
93 [DCB_PG_ATTR_TC_2
] = {.type
= NLA_NESTED
},
94 [DCB_PG_ATTR_TC_3
] = {.type
= NLA_NESTED
},
95 [DCB_PG_ATTR_TC_4
] = {.type
= NLA_NESTED
},
96 [DCB_PG_ATTR_TC_5
] = {.type
= NLA_NESTED
},
97 [DCB_PG_ATTR_TC_6
] = {.type
= NLA_NESTED
},
98 [DCB_PG_ATTR_TC_7
] = {.type
= NLA_NESTED
},
99 [DCB_PG_ATTR_TC_ALL
] = {.type
= NLA_NESTED
},
100 [DCB_PG_ATTR_BW_ID_0
] = {.type
= NLA_U8
},
101 [DCB_PG_ATTR_BW_ID_1
] = {.type
= NLA_U8
},
102 [DCB_PG_ATTR_BW_ID_2
] = {.type
= NLA_U8
},
103 [DCB_PG_ATTR_BW_ID_3
] = {.type
= NLA_U8
},
104 [DCB_PG_ATTR_BW_ID_4
] = {.type
= NLA_U8
},
105 [DCB_PG_ATTR_BW_ID_5
] = {.type
= NLA_U8
},
106 [DCB_PG_ATTR_BW_ID_6
] = {.type
= NLA_U8
},
107 [DCB_PG_ATTR_BW_ID_7
] = {.type
= NLA_U8
},
108 [DCB_PG_ATTR_BW_ID_ALL
] = {.type
= NLA_FLAG
},
111 /* DCB traffic class nested attributes. */
112 static const struct nla_policy dcbnl_tc_param_nest
[DCB_TC_ATTR_PARAM_MAX
+ 1] = {
113 [DCB_TC_ATTR_PARAM_PGID
] = {.type
= NLA_U8
},
114 [DCB_TC_ATTR_PARAM_UP_MAPPING
] = {.type
= NLA_U8
},
115 [DCB_TC_ATTR_PARAM_STRICT_PRIO
] = {.type
= NLA_U8
},
116 [DCB_TC_ATTR_PARAM_BW_PCT
] = {.type
= NLA_U8
},
117 [DCB_TC_ATTR_PARAM_ALL
] = {.type
= NLA_FLAG
},
120 /* DCB capabilities nested attributes. */
121 static const struct nla_policy dcbnl_cap_nest
[DCB_CAP_ATTR_MAX
+ 1] = {
122 [DCB_CAP_ATTR_ALL
] = {.type
= NLA_FLAG
},
123 [DCB_CAP_ATTR_PG
] = {.type
= NLA_U8
},
124 [DCB_CAP_ATTR_PFC
] = {.type
= NLA_U8
},
125 [DCB_CAP_ATTR_UP2TC
] = {.type
= NLA_U8
},
126 [DCB_CAP_ATTR_PG_TCS
] = {.type
= NLA_U8
},
127 [DCB_CAP_ATTR_PFC_TCS
] = {.type
= NLA_U8
},
128 [DCB_CAP_ATTR_GSP
] = {.type
= NLA_U8
},
129 [DCB_CAP_ATTR_BCN
] = {.type
= NLA_U8
},
130 [DCB_CAP_ATTR_DCBX
] = {.type
= NLA_U8
},
133 /* DCB capabilities nested attributes. */
134 static const struct nla_policy dcbnl_numtcs_nest
[DCB_NUMTCS_ATTR_MAX
+ 1] = {
135 [DCB_NUMTCS_ATTR_ALL
] = {.type
= NLA_FLAG
},
136 [DCB_NUMTCS_ATTR_PG
] = {.type
= NLA_U8
},
137 [DCB_NUMTCS_ATTR_PFC
] = {.type
= NLA_U8
},
140 /* DCB BCN nested attributes. */
141 static const struct nla_policy dcbnl_bcn_nest
[DCB_BCN_ATTR_MAX
+ 1] = {
142 [DCB_BCN_ATTR_RP_0
] = {.type
= NLA_U8
},
143 [DCB_BCN_ATTR_RP_1
] = {.type
= NLA_U8
},
144 [DCB_BCN_ATTR_RP_2
] = {.type
= NLA_U8
},
145 [DCB_BCN_ATTR_RP_3
] = {.type
= NLA_U8
},
146 [DCB_BCN_ATTR_RP_4
] = {.type
= NLA_U8
},
147 [DCB_BCN_ATTR_RP_5
] = {.type
= NLA_U8
},
148 [DCB_BCN_ATTR_RP_6
] = {.type
= NLA_U8
},
149 [DCB_BCN_ATTR_RP_7
] = {.type
= NLA_U8
},
150 [DCB_BCN_ATTR_RP_ALL
] = {.type
= NLA_FLAG
},
151 [DCB_BCN_ATTR_BCNA_0
] = {.type
= NLA_U32
},
152 [DCB_BCN_ATTR_BCNA_1
] = {.type
= NLA_U32
},
153 [DCB_BCN_ATTR_ALPHA
] = {.type
= NLA_U32
},
154 [DCB_BCN_ATTR_BETA
] = {.type
= NLA_U32
},
155 [DCB_BCN_ATTR_GD
] = {.type
= NLA_U32
},
156 [DCB_BCN_ATTR_GI
] = {.type
= NLA_U32
},
157 [DCB_BCN_ATTR_TMAX
] = {.type
= NLA_U32
},
158 [DCB_BCN_ATTR_TD
] = {.type
= NLA_U32
},
159 [DCB_BCN_ATTR_RMIN
] = {.type
= NLA_U32
},
160 [DCB_BCN_ATTR_W
] = {.type
= NLA_U32
},
161 [DCB_BCN_ATTR_RD
] = {.type
= NLA_U32
},
162 [DCB_BCN_ATTR_RU
] = {.type
= NLA_U32
},
163 [DCB_BCN_ATTR_WRTT
] = {.type
= NLA_U32
},
164 [DCB_BCN_ATTR_RI
] = {.type
= NLA_U32
},
165 [DCB_BCN_ATTR_C
] = {.type
= NLA_U32
},
166 [DCB_BCN_ATTR_ALL
] = {.type
= NLA_FLAG
},
169 /* DCB APP nested attributes. */
170 static const struct nla_policy dcbnl_app_nest
[DCB_APP_ATTR_MAX
+ 1] = {
171 [DCB_APP_ATTR_IDTYPE
] = {.type
= NLA_U8
},
172 [DCB_APP_ATTR_ID
] = {.type
= NLA_U16
},
173 [DCB_APP_ATTR_PRIORITY
] = {.type
= NLA_U8
},
176 /* IEEE 802.1Qaz nested attributes. */
177 static const struct nla_policy dcbnl_ieee_policy
[DCB_ATTR_IEEE_MAX
+ 1] = {
178 [DCB_ATTR_IEEE_ETS
] = {.len
= sizeof(struct ieee_ets
)},
179 [DCB_ATTR_IEEE_PFC
] = {.len
= sizeof(struct ieee_pfc
)},
180 [DCB_ATTR_IEEE_APP_TABLE
] = {.type
= NLA_NESTED
},
181 [DCB_ATTR_IEEE_MAXRATE
] = {.len
= sizeof(struct ieee_maxrate
)},
184 static const struct nla_policy dcbnl_ieee_app
[DCB_ATTR_IEEE_APP_MAX
+ 1] = {
185 [DCB_ATTR_IEEE_APP
] = {.len
= sizeof(struct dcb_app
)},
188 /* DCB number of traffic classes nested attributes. */
189 static const struct nla_policy dcbnl_featcfg_nest
[DCB_FEATCFG_ATTR_MAX
+ 1] = {
190 [DCB_FEATCFG_ATTR_ALL
] = {.type
= NLA_FLAG
},
191 [DCB_FEATCFG_ATTR_PG
] = {.type
= NLA_U8
},
192 [DCB_FEATCFG_ATTR_PFC
] = {.type
= NLA_U8
},
193 [DCB_FEATCFG_ATTR_APP
] = {.type
= NLA_U8
},
196 static LIST_HEAD(dcb_app_list
);
197 static DEFINE_SPINLOCK(dcb_lock
);
199 /* standard netlink reply call */
200 static int dcbnl_reply(u8 value
, u8 event
, u8 cmd
, u8 attr
, u32 pid
,
203 struct sk_buff
*dcbnl_skb
;
205 struct nlmsghdr
*nlh
;
208 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
212 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, event
, sizeof(*dcb
), flags
);
214 dcb
= NLMSG_DATA(nlh
);
215 dcb
->dcb_family
= AF_UNSPEC
;
219 ret
= nla_put_u8(dcbnl_skb
, attr
, value
);
223 /* end the message, assign the nlmsg_len. */
224 nlmsg_end(dcbnl_skb
, nlh
);
225 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
232 kfree_skb(dcbnl_skb
);
236 static int dcbnl_getstate(struct net_device
*netdev
, struct nlattr
**tb
,
237 u32 pid
, u32 seq
, u16 flags
)
241 /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
242 if (!netdev
->dcbnl_ops
->getstate
)
245 ret
= dcbnl_reply(netdev
->dcbnl_ops
->getstate(netdev
), RTM_GETDCB
,
246 DCB_CMD_GSTATE
, DCB_ATTR_STATE
, pid
, seq
, flags
);
251 static int dcbnl_getpfccfg(struct net_device
*netdev
, struct nlattr
**tb
,
252 u32 pid
, u32 seq
, u16 flags
)
254 struct sk_buff
*dcbnl_skb
;
255 struct nlmsghdr
*nlh
;
257 struct nlattr
*data
[DCB_PFC_UP_ATTR_MAX
+ 1], *nest
;
263 if (!tb
[DCB_ATTR_PFC_CFG
] || !netdev
->dcbnl_ops
->getpfccfg
)
266 ret
= nla_parse_nested(data
, DCB_PFC_UP_ATTR_MAX
,
267 tb
[DCB_ATTR_PFC_CFG
],
272 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
276 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
278 dcb
= NLMSG_DATA(nlh
);
279 dcb
->dcb_family
= AF_UNSPEC
;
280 dcb
->cmd
= DCB_CMD_PFC_GCFG
;
282 nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_PFC_CFG
);
286 if (data
[DCB_PFC_UP_ATTR_ALL
])
289 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
290 if (!getall
&& !data
[i
])
293 netdev
->dcbnl_ops
->getpfccfg(netdev
, i
- DCB_PFC_UP_ATTR_0
,
295 ret
= nla_put_u8(dcbnl_skb
, i
, value
);
298 nla_nest_cancel(dcbnl_skb
, nest
);
302 nla_nest_end(dcbnl_skb
, nest
);
304 nlmsg_end(dcbnl_skb
, nlh
);
306 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
313 kfree_skb(dcbnl_skb
);
318 static int dcbnl_getperm_hwaddr(struct net_device
*netdev
, struct nlattr
**tb
,
319 u32 pid
, u32 seq
, u16 flags
)
321 struct sk_buff
*dcbnl_skb
;
322 struct nlmsghdr
*nlh
;
324 u8 perm_addr
[MAX_ADDR_LEN
];
327 if (!netdev
->dcbnl_ops
->getpermhwaddr
)
330 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
334 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
336 dcb
= NLMSG_DATA(nlh
);
337 dcb
->dcb_family
= AF_UNSPEC
;
338 dcb
->cmd
= DCB_CMD_GPERM_HWADDR
;
340 netdev
->dcbnl_ops
->getpermhwaddr(netdev
, perm_addr
);
342 ret
= nla_put(dcbnl_skb
, DCB_ATTR_PERM_HWADDR
, sizeof(perm_addr
),
345 nlmsg_end(dcbnl_skb
, nlh
);
347 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
354 kfree_skb(dcbnl_skb
);
359 static int dcbnl_getcap(struct net_device
*netdev
, struct nlattr
**tb
,
360 u32 pid
, u32 seq
, u16 flags
)
362 struct sk_buff
*dcbnl_skb
;
363 struct nlmsghdr
*nlh
;
365 struct nlattr
*data
[DCB_CAP_ATTR_MAX
+ 1], *nest
;
371 if (!tb
[DCB_ATTR_CAP
] || !netdev
->dcbnl_ops
->getcap
)
374 ret
= nla_parse_nested(data
, DCB_CAP_ATTR_MAX
, tb
[DCB_ATTR_CAP
],
379 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
383 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
385 dcb
= NLMSG_DATA(nlh
);
386 dcb
->dcb_family
= AF_UNSPEC
;
387 dcb
->cmd
= DCB_CMD_GCAP
;
389 nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_CAP
);
393 if (data
[DCB_CAP_ATTR_ALL
])
396 for (i
= DCB_CAP_ATTR_ALL
+1; i
<= DCB_CAP_ATTR_MAX
; i
++) {
397 if (!getall
&& !data
[i
])
400 if (!netdev
->dcbnl_ops
->getcap(netdev
, i
, &value
)) {
401 ret
= nla_put_u8(dcbnl_skb
, i
, value
);
404 nla_nest_cancel(dcbnl_skb
, nest
);
409 nla_nest_end(dcbnl_skb
, nest
);
411 nlmsg_end(dcbnl_skb
, nlh
);
413 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
420 kfree_skb(dcbnl_skb
);
425 static int dcbnl_getnumtcs(struct net_device
*netdev
, struct nlattr
**tb
,
426 u32 pid
, u32 seq
, u16 flags
)
428 struct sk_buff
*dcbnl_skb
;
429 struct nlmsghdr
*nlh
;
431 struct nlattr
*data
[DCB_NUMTCS_ATTR_MAX
+ 1], *nest
;
437 if (!tb
[DCB_ATTR_NUMTCS
] || !netdev
->dcbnl_ops
->getnumtcs
)
440 ret
= nla_parse_nested(data
, DCB_NUMTCS_ATTR_MAX
, tb
[DCB_ATTR_NUMTCS
],
447 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
453 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
455 dcb
= NLMSG_DATA(nlh
);
456 dcb
->dcb_family
= AF_UNSPEC
;
457 dcb
->cmd
= DCB_CMD_GNUMTCS
;
459 nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_NUMTCS
);
465 if (data
[DCB_NUMTCS_ATTR_ALL
])
468 for (i
= DCB_NUMTCS_ATTR_ALL
+1; i
<= DCB_NUMTCS_ATTR_MAX
; i
++) {
469 if (!getall
&& !data
[i
])
472 ret
= netdev
->dcbnl_ops
->getnumtcs(netdev
, i
, &value
);
474 ret
= nla_put_u8(dcbnl_skb
, i
, value
);
477 nla_nest_cancel(dcbnl_skb
, nest
);
485 nla_nest_end(dcbnl_skb
, nest
);
487 nlmsg_end(dcbnl_skb
, nlh
);
489 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
498 kfree_skb(dcbnl_skb
);
503 static int dcbnl_setnumtcs(struct net_device
*netdev
, struct nlattr
**tb
,
504 u32 pid
, u32 seq
, u16 flags
)
506 struct nlattr
*data
[DCB_NUMTCS_ATTR_MAX
+ 1];
511 if (!tb
[DCB_ATTR_NUMTCS
] || !netdev
->dcbnl_ops
->setnumtcs
)
514 ret
= nla_parse_nested(data
, DCB_NUMTCS_ATTR_MAX
, tb
[DCB_ATTR_NUMTCS
],
522 for (i
= DCB_NUMTCS_ATTR_ALL
+1; i
<= DCB_NUMTCS_ATTR_MAX
; i
++) {
526 value
= nla_get_u8(data
[i
]);
528 ret
= netdev
->dcbnl_ops
->setnumtcs(netdev
, i
, value
);
535 ret
= dcbnl_reply(!!ret
, RTM_SETDCB
, DCB_CMD_SNUMTCS
,
536 DCB_ATTR_NUMTCS
, pid
, seq
, flags
);
542 static int dcbnl_getpfcstate(struct net_device
*netdev
, struct nlattr
**tb
,
543 u32 pid
, u32 seq
, u16 flags
)
547 if (!netdev
->dcbnl_ops
->getpfcstate
)
550 ret
= dcbnl_reply(netdev
->dcbnl_ops
->getpfcstate(netdev
), RTM_GETDCB
,
551 DCB_CMD_PFC_GSTATE
, DCB_ATTR_PFC_STATE
,
557 static int dcbnl_setpfcstate(struct net_device
*netdev
, struct nlattr
**tb
,
558 u32 pid
, u32 seq
, u16 flags
)
563 if (!tb
[DCB_ATTR_PFC_STATE
] || !netdev
->dcbnl_ops
->setpfcstate
)
566 value
= nla_get_u8(tb
[DCB_ATTR_PFC_STATE
]);
568 netdev
->dcbnl_ops
->setpfcstate(netdev
, value
);
570 ret
= dcbnl_reply(0, RTM_SETDCB
, DCB_CMD_PFC_SSTATE
, DCB_ATTR_PFC_STATE
,
576 static int dcbnl_getapp(struct net_device
*netdev
, struct nlattr
**tb
,
577 u32 pid
, u32 seq
, u16 flags
)
579 struct sk_buff
*dcbnl_skb
;
580 struct nlmsghdr
*nlh
;
582 struct nlattr
*app_nest
;
583 struct nlattr
*app_tb
[DCB_APP_ATTR_MAX
+ 1];
588 if (!tb
[DCB_ATTR_APP
])
591 ret
= nla_parse_nested(app_tb
, DCB_APP_ATTR_MAX
, tb
[DCB_ATTR_APP
],
597 /* all must be non-null */
598 if ((!app_tb
[DCB_APP_ATTR_IDTYPE
]) ||
599 (!app_tb
[DCB_APP_ATTR_ID
]))
602 /* either by eth type or by socket number */
603 idtype
= nla_get_u8(app_tb
[DCB_APP_ATTR_IDTYPE
]);
604 if ((idtype
!= DCB_APP_IDTYPE_ETHTYPE
) &&
605 (idtype
!= DCB_APP_IDTYPE_PORTNUM
))
608 id
= nla_get_u16(app_tb
[DCB_APP_ATTR_ID
]);
610 if (netdev
->dcbnl_ops
->getapp
) {
611 up
= netdev
->dcbnl_ops
->getapp(netdev
, idtype
, id
);
613 struct dcb_app app
= {
617 up
= dcb_getapp(netdev
, &app
);
621 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
625 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
626 dcb
= NLMSG_DATA(nlh
);
627 dcb
->dcb_family
= AF_UNSPEC
;
628 dcb
->cmd
= DCB_CMD_GAPP
;
630 app_nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_APP
);
634 ret
= nla_put_u8(dcbnl_skb
, DCB_APP_ATTR_IDTYPE
, idtype
);
638 ret
= nla_put_u16(dcbnl_skb
, DCB_APP_ATTR_ID
, id
);
642 ret
= nla_put_u8(dcbnl_skb
, DCB_APP_ATTR_PRIORITY
, up
);
646 nla_nest_end(dcbnl_skb
, app_nest
);
647 nlmsg_end(dcbnl_skb
, nlh
);
649 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
656 nla_nest_cancel(dcbnl_skb
, app_nest
);
658 kfree_skb(dcbnl_skb
);
663 static int dcbnl_setapp(struct net_device
*netdev
, struct nlattr
**tb
,
664 u32 pid
, u32 seq
, u16 flags
)
666 int err
, ret
= -EINVAL
;
669 struct nlattr
*app_tb
[DCB_APP_ATTR_MAX
+ 1];
671 if (!tb
[DCB_ATTR_APP
])
674 ret
= nla_parse_nested(app_tb
, DCB_APP_ATTR_MAX
, tb
[DCB_ATTR_APP
],
680 /* all must be non-null */
681 if ((!app_tb
[DCB_APP_ATTR_IDTYPE
]) ||
682 (!app_tb
[DCB_APP_ATTR_ID
]) ||
683 (!app_tb
[DCB_APP_ATTR_PRIORITY
]))
686 /* either by eth type or by socket number */
687 idtype
= nla_get_u8(app_tb
[DCB_APP_ATTR_IDTYPE
]);
688 if ((idtype
!= DCB_APP_IDTYPE_ETHTYPE
) &&
689 (idtype
!= DCB_APP_IDTYPE_PORTNUM
))
692 id
= nla_get_u16(app_tb
[DCB_APP_ATTR_ID
]);
693 up
= nla_get_u8(app_tb
[DCB_APP_ATTR_PRIORITY
]);
695 if (netdev
->dcbnl_ops
->setapp
) {
696 err
= netdev
->dcbnl_ops
->setapp(netdev
, idtype
, id
, up
);
699 app
.selector
= idtype
;
702 err
= dcb_setapp(netdev
, &app
);
705 ret
= dcbnl_reply(err
, RTM_SETDCB
, DCB_CMD_SAPP
, DCB_ATTR_APP
,
707 dcbnl_cee_notify(netdev
, RTM_SETDCB
, DCB_CMD_SAPP
, seq
, 0);
712 static int __dcbnl_pg_getcfg(struct net_device
*netdev
, struct nlattr
**tb
,
713 u32 pid
, u32 seq
, u16 flags
, int dir
)
715 struct sk_buff
*dcbnl_skb
;
716 struct nlmsghdr
*nlh
;
718 struct nlattr
*pg_nest
, *param_nest
, *data
;
719 struct nlattr
*pg_tb
[DCB_PG_ATTR_MAX
+ 1];
720 struct nlattr
*param_tb
[DCB_TC_ATTR_PARAM_MAX
+ 1];
721 u8 prio
, pgid
, tc_pct
, up_map
;
726 if (!tb
[DCB_ATTR_PG_CFG
] ||
727 !netdev
->dcbnl_ops
->getpgtccfgtx
||
728 !netdev
->dcbnl_ops
->getpgtccfgrx
||
729 !netdev
->dcbnl_ops
->getpgbwgcfgtx
||
730 !netdev
->dcbnl_ops
->getpgbwgcfgrx
)
733 ret
= nla_parse_nested(pg_tb
, DCB_PG_ATTR_MAX
,
734 tb
[DCB_ATTR_PG_CFG
], dcbnl_pg_nest
);
739 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
743 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
745 dcb
= NLMSG_DATA(nlh
);
746 dcb
->dcb_family
= AF_UNSPEC
;
747 dcb
->cmd
= (dir
) ? DCB_CMD_PGRX_GCFG
: DCB_CMD_PGTX_GCFG
;
749 pg_nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_PG_CFG
);
753 if (pg_tb
[DCB_PG_ATTR_TC_ALL
])
756 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
757 if (!getall
&& !pg_tb
[i
])
760 if (pg_tb
[DCB_PG_ATTR_TC_ALL
])
761 data
= pg_tb
[DCB_PG_ATTR_TC_ALL
];
764 ret
= nla_parse_nested(param_tb
, DCB_TC_ATTR_PARAM_MAX
,
765 data
, dcbnl_tc_param_nest
);
769 param_nest
= nla_nest_start(dcbnl_skb
, i
);
773 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
774 prio
= DCB_ATTR_VALUE_UNDEFINED
;
775 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
776 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
780 netdev
->dcbnl_ops
->getpgtccfgrx(netdev
,
781 i
- DCB_PG_ATTR_TC_0
, &prio
,
782 &pgid
, &tc_pct
, &up_map
);
785 netdev
->dcbnl_ops
->getpgtccfgtx(netdev
,
786 i
- DCB_PG_ATTR_TC_0
, &prio
,
787 &pgid
, &tc_pct
, &up_map
);
790 if (param_tb
[DCB_TC_ATTR_PARAM_PGID
] ||
791 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
792 ret
= nla_put_u8(dcbnl_skb
,
793 DCB_TC_ATTR_PARAM_PGID
, pgid
);
797 if (param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
] ||
798 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
799 ret
= nla_put_u8(dcbnl_skb
,
800 DCB_TC_ATTR_PARAM_UP_MAPPING
, up_map
);
804 if (param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
] ||
805 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
806 ret
= nla_put_u8(dcbnl_skb
,
807 DCB_TC_ATTR_PARAM_STRICT_PRIO
, prio
);
811 if (param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
] ||
812 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
813 ret
= nla_put_u8(dcbnl_skb
, DCB_TC_ATTR_PARAM_BW_PCT
,
818 nla_nest_end(dcbnl_skb
, param_nest
);
821 if (pg_tb
[DCB_PG_ATTR_BW_ID_ALL
])
826 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
827 if (!getall
&& !pg_tb
[i
])
830 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
834 netdev
->dcbnl_ops
->getpgbwgcfgrx(netdev
,
835 i
- DCB_PG_ATTR_BW_ID_0
, &tc_pct
);
838 netdev
->dcbnl_ops
->getpgbwgcfgtx(netdev
,
839 i
- DCB_PG_ATTR_BW_ID_0
, &tc_pct
);
841 ret
= nla_put_u8(dcbnl_skb
, i
, tc_pct
);
847 nla_nest_end(dcbnl_skb
, pg_nest
);
849 nlmsg_end(dcbnl_skb
, nlh
);
851 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
858 nla_nest_cancel(dcbnl_skb
, param_nest
);
860 nla_nest_cancel(dcbnl_skb
, pg_nest
);
863 kfree_skb(dcbnl_skb
);
869 static int dcbnl_pgtx_getcfg(struct net_device
*netdev
, struct nlattr
**tb
,
870 u32 pid
, u32 seq
, u16 flags
)
872 return __dcbnl_pg_getcfg(netdev
, tb
, pid
, seq
, flags
, 0);
875 static int dcbnl_pgrx_getcfg(struct net_device
*netdev
, struct nlattr
**tb
,
876 u32 pid
, u32 seq
, u16 flags
)
878 return __dcbnl_pg_getcfg(netdev
, tb
, pid
, seq
, flags
, 1);
881 static int dcbnl_setstate(struct net_device
*netdev
, struct nlattr
**tb
,
882 u32 pid
, u32 seq
, u16 flags
)
887 if (!tb
[DCB_ATTR_STATE
] || !netdev
->dcbnl_ops
->setstate
)
890 value
= nla_get_u8(tb
[DCB_ATTR_STATE
]);
892 ret
= dcbnl_reply(netdev
->dcbnl_ops
->setstate(netdev
, value
),
893 RTM_SETDCB
, DCB_CMD_SSTATE
, DCB_ATTR_STATE
,
899 static int dcbnl_setpfccfg(struct net_device
*netdev
, struct nlattr
**tb
,
900 u32 pid
, u32 seq
, u16 flags
)
902 struct nlattr
*data
[DCB_PFC_UP_ATTR_MAX
+ 1];
907 if (!tb
[DCB_ATTR_PFC_CFG
] || !netdev
->dcbnl_ops
->setpfccfg
)
910 ret
= nla_parse_nested(data
, DCB_PFC_UP_ATTR_MAX
,
911 tb
[DCB_ATTR_PFC_CFG
],
916 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
919 value
= nla_get_u8(data
[i
]);
920 netdev
->dcbnl_ops
->setpfccfg(netdev
,
921 data
[i
]->nla_type
- DCB_PFC_UP_ATTR_0
, value
);
924 ret
= dcbnl_reply(0, RTM_SETDCB
, DCB_CMD_PFC_SCFG
, DCB_ATTR_PFC_CFG
,
930 static int dcbnl_setall(struct net_device
*netdev
, struct nlattr
**tb
,
931 u32 pid
, u32 seq
, u16 flags
)
935 if (!tb
[DCB_ATTR_SET_ALL
] || !netdev
->dcbnl_ops
->setall
)
938 ret
= dcbnl_reply(netdev
->dcbnl_ops
->setall(netdev
), RTM_SETDCB
,
939 DCB_CMD_SET_ALL
, DCB_ATTR_SET_ALL
, pid
, seq
, flags
);
940 dcbnl_cee_notify(netdev
, RTM_SETDCB
, DCB_CMD_SET_ALL
, seq
, 0);
945 static int __dcbnl_pg_setcfg(struct net_device
*netdev
, struct nlattr
**tb
,
946 u32 pid
, u32 seq
, u16 flags
, int dir
)
948 struct nlattr
*pg_tb
[DCB_PG_ATTR_MAX
+ 1];
949 struct nlattr
*param_tb
[DCB_TC_ATTR_PARAM_MAX
+ 1];
957 if (!tb
[DCB_ATTR_PG_CFG
] ||
958 !netdev
->dcbnl_ops
->setpgtccfgtx
||
959 !netdev
->dcbnl_ops
->setpgtccfgrx
||
960 !netdev
->dcbnl_ops
->setpgbwgcfgtx
||
961 !netdev
->dcbnl_ops
->setpgbwgcfgrx
)
964 ret
= nla_parse_nested(pg_tb
, DCB_PG_ATTR_MAX
,
965 tb
[DCB_ATTR_PG_CFG
], dcbnl_pg_nest
);
969 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
973 ret
= nla_parse_nested(param_tb
, DCB_TC_ATTR_PARAM_MAX
,
974 pg_tb
[i
], dcbnl_tc_param_nest
);
978 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
979 prio
= DCB_ATTR_VALUE_UNDEFINED
;
980 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
981 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
983 if (param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
])
985 nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
]);
987 if (param_tb
[DCB_TC_ATTR_PARAM_PGID
])
988 pgid
= nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_PGID
]);
990 if (param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
])
991 tc_pct
= nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
]);
993 if (param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
])
995 nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
]);
997 /* dir: Tx = 0, Rx = 1 */
1000 netdev
->dcbnl_ops
->setpgtccfgrx(netdev
,
1001 i
- DCB_PG_ATTR_TC_0
,
1002 prio
, pgid
, tc_pct
, up_map
);
1005 netdev
->dcbnl_ops
->setpgtccfgtx(netdev
,
1006 i
- DCB_PG_ATTR_TC_0
,
1007 prio
, pgid
, tc_pct
, up_map
);
1011 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
1015 tc_pct
= nla_get_u8(pg_tb
[i
]);
1017 /* dir: Tx = 0, Rx = 1 */
1020 netdev
->dcbnl_ops
->setpgbwgcfgrx(netdev
,
1021 i
- DCB_PG_ATTR_BW_ID_0
, tc_pct
);
1024 netdev
->dcbnl_ops
->setpgbwgcfgtx(netdev
,
1025 i
- DCB_PG_ATTR_BW_ID_0
, tc_pct
);
1029 ret
= dcbnl_reply(0, RTM_SETDCB
,
1030 (dir
? DCB_CMD_PGRX_SCFG
: DCB_CMD_PGTX_SCFG
),
1031 DCB_ATTR_PG_CFG
, pid
, seq
, flags
);
1037 static int dcbnl_pgtx_setcfg(struct net_device
*netdev
, struct nlattr
**tb
,
1038 u32 pid
, u32 seq
, u16 flags
)
1040 return __dcbnl_pg_setcfg(netdev
, tb
, pid
, seq
, flags
, 0);
1043 static int dcbnl_pgrx_setcfg(struct net_device
*netdev
, struct nlattr
**tb
,
1044 u32 pid
, u32 seq
, u16 flags
)
1046 return __dcbnl_pg_setcfg(netdev
, tb
, pid
, seq
, flags
, 1);
1049 static int dcbnl_bcn_getcfg(struct net_device
*netdev
, struct nlattr
**tb
,
1050 u32 pid
, u32 seq
, u16 flags
)
1052 struct sk_buff
*dcbnl_skb
;
1053 struct nlmsghdr
*nlh
;
1055 struct nlattr
*bcn_nest
;
1056 struct nlattr
*bcn_tb
[DCB_BCN_ATTR_MAX
+ 1];
1060 bool getall
= false;
1063 if (!tb
[DCB_ATTR_BCN
] || !netdev
->dcbnl_ops
->getbcnrp
||
1064 !netdev
->dcbnl_ops
->getbcncfg
)
1067 ret
= nla_parse_nested(bcn_tb
, DCB_BCN_ATTR_MAX
,
1068 tb
[DCB_ATTR_BCN
], dcbnl_bcn_nest
);
1073 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1077 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
1079 dcb
= NLMSG_DATA(nlh
);
1080 dcb
->dcb_family
= AF_UNSPEC
;
1081 dcb
->cmd
= DCB_CMD_BCN_GCFG
;
1083 bcn_nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_BCN
);
1087 if (bcn_tb
[DCB_BCN_ATTR_ALL
])
1090 for (i
= DCB_BCN_ATTR_RP_0
; i
<= DCB_BCN_ATTR_RP_7
; i
++) {
1091 if (!getall
&& !bcn_tb
[i
])
1094 netdev
->dcbnl_ops
->getbcnrp(netdev
, i
- DCB_BCN_ATTR_RP_0
,
1096 ret
= nla_put_u8(dcbnl_skb
, i
, value_byte
);
1101 for (i
= DCB_BCN_ATTR_BCNA_0
; i
<= DCB_BCN_ATTR_RI
; i
++) {
1102 if (!getall
&& !bcn_tb
[i
])
1105 netdev
->dcbnl_ops
->getbcncfg(netdev
, i
,
1107 ret
= nla_put_u32(dcbnl_skb
, i
, value_integer
);
1112 nla_nest_end(dcbnl_skb
, bcn_nest
);
1114 nlmsg_end(dcbnl_skb
, nlh
);
1116 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
1123 nla_nest_cancel(dcbnl_skb
, bcn_nest
);
1126 kfree_skb(dcbnl_skb
);
1132 static int dcbnl_bcn_setcfg(struct net_device
*netdev
, struct nlattr
**tb
,
1133 u32 pid
, u32 seq
, u16 flags
)
1135 struct nlattr
*data
[DCB_BCN_ATTR_MAX
+ 1];
1141 if (!tb
[DCB_ATTR_BCN
] || !netdev
->dcbnl_ops
->setbcncfg
||
1142 !netdev
->dcbnl_ops
->setbcnrp
)
1145 ret
= nla_parse_nested(data
, DCB_BCN_ATTR_MAX
,
1151 for (i
= DCB_BCN_ATTR_RP_0
; i
<= DCB_BCN_ATTR_RP_7
; i
++) {
1152 if (data
[i
] == NULL
)
1154 value_byte
= nla_get_u8(data
[i
]);
1155 netdev
->dcbnl_ops
->setbcnrp(netdev
,
1156 data
[i
]->nla_type
- DCB_BCN_ATTR_RP_0
, value_byte
);
1159 for (i
= DCB_BCN_ATTR_BCNA_0
; i
<= DCB_BCN_ATTR_RI
; i
++) {
1160 if (data
[i
] == NULL
)
1162 value_int
= nla_get_u32(data
[i
]);
1163 netdev
->dcbnl_ops
->setbcncfg(netdev
,
1167 ret
= dcbnl_reply(0, RTM_SETDCB
, DCB_CMD_BCN_SCFG
, DCB_ATTR_BCN
,
1173 static int dcbnl_build_peer_app(struct net_device
*netdev
, struct sk_buff
* skb
,
1174 int app_nested_type
, int app_info_type
,
1177 struct dcb_peer_app_info info
;
1178 struct dcb_app
*table
= NULL
;
1179 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1185 * retrieve the peer app configuration form the driver. If the driver
1186 * handlers fail exit without doing anything
1188 err
= ops
->peer_getappinfo(netdev
, &info
, &app_count
);
1189 if (!err
&& app_count
) {
1190 table
= kmalloc(sizeof(struct dcb_app
) * app_count
, GFP_KERNEL
);
1194 err
= ops
->peer_getapptable(netdev
, table
);
1202 * build the message, from here on the only possible failure
1203 * is due to the skb size
1207 app
= nla_nest_start(skb
, app_nested_type
);
1209 goto nla_put_failure
;
1211 if (app_info_type
&&
1212 nla_put(skb
, app_info_type
, sizeof(info
), &info
))
1213 goto nla_put_failure
;
1215 for (i
= 0; i
< app_count
; i
++) {
1216 if (nla_put(skb
, app_entry_type
, sizeof(struct dcb_app
),
1218 goto nla_put_failure
;
1220 nla_nest_end(skb
, app
);
1229 /* Handle IEEE 802.1Qaz GET commands. */
1230 static int dcbnl_ieee_fill(struct sk_buff
*skb
, struct net_device
*netdev
)
1232 struct nlattr
*ieee
, *app
;
1233 struct dcb_app_type
*itr
;
1234 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1236 int err
= -EMSGSIZE
;
1238 if (nla_put_string(skb
, DCB_ATTR_IFNAME
, netdev
->name
))
1239 goto nla_put_failure
;
1240 ieee
= nla_nest_start(skb
, DCB_ATTR_IEEE
);
1242 goto nla_put_failure
;
1244 if (ops
->ieee_getets
) {
1245 struct ieee_ets ets
;
1246 err
= ops
->ieee_getets(netdev
, &ets
);
1248 nla_put(skb
, DCB_ATTR_IEEE_ETS
, sizeof(ets
), &ets
))
1249 goto nla_put_failure
;
1252 if (ops
->ieee_getmaxrate
) {
1253 struct ieee_maxrate maxrate
;
1254 err
= ops
->ieee_getmaxrate(netdev
, &maxrate
);
1256 err
= nla_put(skb
, DCB_ATTR_IEEE_MAXRATE
,
1257 sizeof(maxrate
), &maxrate
);
1259 goto nla_put_failure
;
1263 if (ops
->ieee_getpfc
) {
1264 struct ieee_pfc pfc
;
1265 err
= ops
->ieee_getpfc(netdev
, &pfc
);
1267 nla_put(skb
, DCB_ATTR_IEEE_PFC
, sizeof(pfc
), &pfc
))
1268 goto nla_put_failure
;
1271 app
= nla_nest_start(skb
, DCB_ATTR_IEEE_APP_TABLE
);
1273 goto nla_put_failure
;
1275 spin_lock(&dcb_lock
);
1276 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1277 if (itr
->ifindex
== netdev
->ifindex
) {
1278 err
= nla_put(skb
, DCB_ATTR_IEEE_APP
, sizeof(itr
->app
),
1281 spin_unlock(&dcb_lock
);
1282 goto nla_put_failure
;
1287 if (netdev
->dcbnl_ops
->getdcbx
)
1288 dcbx
= netdev
->dcbnl_ops
->getdcbx(netdev
);
1292 spin_unlock(&dcb_lock
);
1293 nla_nest_end(skb
, app
);
1295 /* get peer info if available */
1296 if (ops
->ieee_peer_getets
) {
1297 struct ieee_ets ets
;
1298 err
= ops
->ieee_peer_getets(netdev
, &ets
);
1300 nla_put(skb
, DCB_ATTR_IEEE_PEER_ETS
, sizeof(ets
), &ets
))
1301 goto nla_put_failure
;
1304 if (ops
->ieee_peer_getpfc
) {
1305 struct ieee_pfc pfc
;
1306 err
= ops
->ieee_peer_getpfc(netdev
, &pfc
);
1308 nla_put(skb
, DCB_ATTR_IEEE_PEER_PFC
, sizeof(pfc
), &pfc
))
1309 goto nla_put_failure
;
1312 if (ops
->peer_getappinfo
&& ops
->peer_getapptable
) {
1313 err
= dcbnl_build_peer_app(netdev
, skb
,
1314 DCB_ATTR_IEEE_PEER_APP
,
1315 DCB_ATTR_IEEE_APP_UNSPEC
,
1318 goto nla_put_failure
;
1321 nla_nest_end(skb
, ieee
);
1323 err
= nla_put_u8(skb
, DCB_ATTR_DCBX
, dcbx
);
1325 goto nla_put_failure
;
1334 static int dcbnl_cee_pg_fill(struct sk_buff
*skb
, struct net_device
*dev
,
1337 u8 pgid
, up_map
, prio
, tc_pct
;
1338 const struct dcbnl_rtnl_ops
*ops
= dev
->dcbnl_ops
;
1339 int i
= dir
? DCB_ATTR_CEE_TX_PG
: DCB_ATTR_CEE_RX_PG
;
1340 struct nlattr
*pg
= nla_nest_start(skb
, i
);
1343 goto nla_put_failure
;
1345 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
1346 struct nlattr
*tc_nest
= nla_nest_start(skb
, i
);
1349 goto nla_put_failure
;
1351 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
1352 prio
= DCB_ATTR_VALUE_UNDEFINED
;
1353 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
1354 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
1357 ops
->getpgtccfgrx(dev
, i
- DCB_PG_ATTR_TC_0
,
1358 &prio
, &pgid
, &tc_pct
, &up_map
);
1360 ops
->getpgtccfgtx(dev
, i
- DCB_PG_ATTR_TC_0
,
1361 &prio
, &pgid
, &tc_pct
, &up_map
);
1363 if (nla_put_u8(skb
, DCB_TC_ATTR_PARAM_PGID
, pgid
) ||
1364 nla_put_u8(skb
, DCB_TC_ATTR_PARAM_UP_MAPPING
, up_map
) ||
1365 nla_put_u8(skb
, DCB_TC_ATTR_PARAM_STRICT_PRIO
, prio
) ||
1366 nla_put_u8(skb
, DCB_TC_ATTR_PARAM_BW_PCT
, tc_pct
))
1367 goto nla_put_failure
;
1368 nla_nest_end(skb
, tc_nest
);
1371 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
1372 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
1375 ops
->getpgbwgcfgrx(dev
, i
- DCB_PG_ATTR_BW_ID_0
,
1378 ops
->getpgbwgcfgtx(dev
, i
- DCB_PG_ATTR_BW_ID_0
,
1380 if (nla_put_u8(skb
, i
, tc_pct
))
1381 goto nla_put_failure
;
1383 nla_nest_end(skb
, pg
);
1390 static int dcbnl_cee_fill(struct sk_buff
*skb
, struct net_device
*netdev
)
1392 struct nlattr
*cee
, *app
;
1393 struct dcb_app_type
*itr
;
1394 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1395 int dcbx
, i
, err
= -EMSGSIZE
;
1398 if (nla_put_string(skb
, DCB_ATTR_IFNAME
, netdev
->name
))
1399 goto nla_put_failure
;
1400 cee
= nla_nest_start(skb
, DCB_ATTR_CEE
);
1402 goto nla_put_failure
;
1405 if (ops
->getpgtccfgtx
&& ops
->getpgbwgcfgtx
) {
1406 err
= dcbnl_cee_pg_fill(skb
, netdev
, 1);
1408 goto nla_put_failure
;
1411 if (ops
->getpgtccfgrx
&& ops
->getpgbwgcfgrx
) {
1412 err
= dcbnl_cee_pg_fill(skb
, netdev
, 0);
1414 goto nla_put_failure
;
1418 if (ops
->getpfccfg
) {
1419 struct nlattr
*pfc_nest
= nla_nest_start(skb
, DCB_ATTR_CEE_PFC
);
1422 goto nla_put_failure
;
1424 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
1425 ops
->getpfccfg(netdev
, i
- DCB_PFC_UP_ATTR_0
, &value
);
1426 if (nla_put_u8(skb
, i
, value
))
1427 goto nla_put_failure
;
1429 nla_nest_end(skb
, pfc_nest
);
1433 spin_lock(&dcb_lock
);
1434 app
= nla_nest_start(skb
, DCB_ATTR_CEE_APP_TABLE
);
1438 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1439 if (itr
->ifindex
== netdev
->ifindex
) {
1440 struct nlattr
*app_nest
= nla_nest_start(skb
,
1445 err
= nla_put_u8(skb
, DCB_APP_ATTR_IDTYPE
,
1450 err
= nla_put_u16(skb
, DCB_APP_ATTR_ID
,
1455 err
= nla_put_u8(skb
, DCB_APP_ATTR_PRIORITY
,
1460 nla_nest_end(skb
, app_nest
);
1463 nla_nest_end(skb
, app
);
1465 if (netdev
->dcbnl_ops
->getdcbx
)
1466 dcbx
= netdev
->dcbnl_ops
->getdcbx(netdev
);
1470 spin_unlock(&dcb_lock
);
1472 /* features flags */
1473 if (ops
->getfeatcfg
) {
1474 struct nlattr
*feat
= nla_nest_start(skb
, DCB_ATTR_CEE_FEAT
);
1476 goto nla_put_failure
;
1478 for (i
= DCB_FEATCFG_ATTR_ALL
+ 1; i
<= DCB_FEATCFG_ATTR_MAX
;
1480 if (!ops
->getfeatcfg(netdev
, i
, &value
) &&
1481 nla_put_u8(skb
, i
, value
))
1482 goto nla_put_failure
;
1484 nla_nest_end(skb
, feat
);
1487 /* peer info if available */
1488 if (ops
->cee_peer_getpg
) {
1490 err
= ops
->cee_peer_getpg(netdev
, &pg
);
1492 nla_put(skb
, DCB_ATTR_CEE_PEER_PG
, sizeof(pg
), &pg
))
1493 goto nla_put_failure
;
1496 if (ops
->cee_peer_getpfc
) {
1498 err
= ops
->cee_peer_getpfc(netdev
, &pfc
);
1500 nla_put(skb
, DCB_ATTR_CEE_PEER_PFC
, sizeof(pfc
), &pfc
))
1501 goto nla_put_failure
;
1504 if (ops
->peer_getappinfo
&& ops
->peer_getapptable
) {
1505 err
= dcbnl_build_peer_app(netdev
, skb
,
1506 DCB_ATTR_CEE_PEER_APP_TABLE
,
1507 DCB_ATTR_CEE_PEER_APP_INFO
,
1508 DCB_ATTR_CEE_PEER_APP
);
1510 goto nla_put_failure
;
1512 nla_nest_end(skb
, cee
);
1516 err
= nla_put_u8(skb
, DCB_ATTR_DCBX
, dcbx
);
1518 goto nla_put_failure
;
1523 spin_unlock(&dcb_lock
);
1528 static int dcbnl_notify(struct net_device
*dev
, int event
, int cmd
,
1529 u32 seq
, u32 pid
, int dcbx_ver
)
1531 struct net
*net
= dev_net(dev
);
1532 struct sk_buff
*skb
;
1533 struct nlmsghdr
*nlh
;
1535 const struct dcbnl_rtnl_ops
*ops
= dev
->dcbnl_ops
;
1541 skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1545 nlh
= nlmsg_put(skb
, pid
, 0, event
, sizeof(*dcb
), 0);
1551 dcb
= NLMSG_DATA(nlh
);
1552 dcb
->dcb_family
= AF_UNSPEC
;
1555 if (dcbx_ver
== DCB_CAP_DCBX_VER_IEEE
)
1556 err
= dcbnl_ieee_fill(skb
, dev
);
1558 err
= dcbnl_cee_fill(skb
, dev
);
1561 /* Report error to broadcast listeners */
1562 nlmsg_cancel(skb
, nlh
);
1564 rtnl_set_sk_err(net
, RTNLGRP_DCB
, err
);
1566 /* End nlmsg and notify broadcast listeners */
1567 nlmsg_end(skb
, nlh
);
1568 rtnl_notify(skb
, net
, 0, RTNLGRP_DCB
, NULL
, GFP_KERNEL
);
1574 int dcbnl_ieee_notify(struct net_device
*dev
, int event
, int cmd
,
1577 return dcbnl_notify(dev
, event
, cmd
, seq
, pid
, DCB_CAP_DCBX_VER_IEEE
);
1579 EXPORT_SYMBOL(dcbnl_ieee_notify
);
1581 int dcbnl_cee_notify(struct net_device
*dev
, int event
, int cmd
,
1584 return dcbnl_notify(dev
, event
, cmd
, seq
, pid
, DCB_CAP_DCBX_VER_CEE
);
1586 EXPORT_SYMBOL(dcbnl_cee_notify
);
1588 /* Handle IEEE 802.1Qaz SET commands. If any requested operation can not
1589 * be completed the entire msg is aborted and error value is returned.
1590 * No attempt is made to reconcile the case where only part of the
1591 * cmd can be completed.
1593 static int dcbnl_ieee_set(struct net_device
*netdev
, struct nlattr
**tb
,
1594 u32 pid
, u32 seq
, u16 flags
)
1596 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1597 struct nlattr
*ieee
[DCB_ATTR_IEEE_MAX
+ 1];
1598 int err
= -EOPNOTSUPP
;
1603 if (!tb
[DCB_ATTR_IEEE
])
1606 err
= nla_parse_nested(ieee
, DCB_ATTR_IEEE_MAX
,
1607 tb
[DCB_ATTR_IEEE
], dcbnl_ieee_policy
);
1611 if (ieee
[DCB_ATTR_IEEE_ETS
] && ops
->ieee_setets
) {
1612 struct ieee_ets
*ets
= nla_data(ieee
[DCB_ATTR_IEEE_ETS
]);
1613 err
= ops
->ieee_setets(netdev
, ets
);
1618 if (ieee
[DCB_ATTR_IEEE_MAXRATE
] && ops
->ieee_setmaxrate
) {
1619 struct ieee_maxrate
*maxrate
=
1620 nla_data(ieee
[DCB_ATTR_IEEE_MAXRATE
]);
1621 err
= ops
->ieee_setmaxrate(netdev
, maxrate
);
1626 if (ieee
[DCB_ATTR_IEEE_PFC
] && ops
->ieee_setpfc
) {
1627 struct ieee_pfc
*pfc
= nla_data(ieee
[DCB_ATTR_IEEE_PFC
]);
1628 err
= ops
->ieee_setpfc(netdev
, pfc
);
1633 if (ieee
[DCB_ATTR_IEEE_APP_TABLE
]) {
1634 struct nlattr
*attr
;
1637 nla_for_each_nested(attr
, ieee
[DCB_ATTR_IEEE_APP_TABLE
], rem
) {
1638 struct dcb_app
*app_data
;
1639 if (nla_type(attr
) != DCB_ATTR_IEEE_APP
)
1641 app_data
= nla_data(attr
);
1642 if (ops
->ieee_setapp
)
1643 err
= ops
->ieee_setapp(netdev
, app_data
);
1645 err
= dcb_ieee_setapp(netdev
, app_data
);
1652 dcbnl_reply(err
, RTM_SETDCB
, DCB_CMD_IEEE_SET
, DCB_ATTR_IEEE
,
1654 dcbnl_ieee_notify(netdev
, RTM_SETDCB
, DCB_CMD_IEEE_SET
, seq
, 0);
1658 static int dcbnl_ieee_get(struct net_device
*netdev
, struct nlattr
**tb
,
1659 u32 pid
, u32 seq
, u16 flags
)
1661 struct net
*net
= dev_net(netdev
);
1662 struct sk_buff
*skb
;
1663 struct nlmsghdr
*nlh
;
1665 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1671 skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1675 nlh
= nlmsg_put(skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
1681 dcb
= NLMSG_DATA(nlh
);
1682 dcb
->dcb_family
= AF_UNSPEC
;
1683 dcb
->cmd
= DCB_CMD_IEEE_GET
;
1685 err
= dcbnl_ieee_fill(skb
, netdev
);
1688 nlmsg_cancel(skb
, nlh
);
1691 nlmsg_end(skb
, nlh
);
1692 err
= rtnl_unicast(skb
, net
, pid
);
1698 static int dcbnl_ieee_del(struct net_device
*netdev
, struct nlattr
**tb
,
1699 u32 pid
, u32 seq
, u16 flags
)
1701 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1702 struct nlattr
*ieee
[DCB_ATTR_IEEE_MAX
+ 1];
1703 int err
= -EOPNOTSUPP
;
1708 if (!tb
[DCB_ATTR_IEEE
])
1711 err
= nla_parse_nested(ieee
, DCB_ATTR_IEEE_MAX
,
1712 tb
[DCB_ATTR_IEEE
], dcbnl_ieee_policy
);
1716 if (ieee
[DCB_ATTR_IEEE_APP_TABLE
]) {
1717 struct nlattr
*attr
;
1720 nla_for_each_nested(attr
, ieee
[DCB_ATTR_IEEE_APP_TABLE
], rem
) {
1721 struct dcb_app
*app_data
;
1723 if (nla_type(attr
) != DCB_ATTR_IEEE_APP
)
1725 app_data
= nla_data(attr
);
1726 if (ops
->ieee_delapp
)
1727 err
= ops
->ieee_delapp(netdev
, app_data
);
1729 err
= dcb_ieee_delapp(netdev
, app_data
);
1736 dcbnl_reply(err
, RTM_SETDCB
, DCB_CMD_IEEE_DEL
, DCB_ATTR_IEEE
,
1738 dcbnl_ieee_notify(netdev
, RTM_SETDCB
, DCB_CMD_IEEE_DEL
, seq
, 0);
1743 /* DCBX configuration */
1744 static int dcbnl_getdcbx(struct net_device
*netdev
, struct nlattr
**tb
,
1745 u32 pid
, u32 seq
, u16 flags
)
1749 if (!netdev
->dcbnl_ops
->getdcbx
)
1752 ret
= dcbnl_reply(netdev
->dcbnl_ops
->getdcbx(netdev
), RTM_GETDCB
,
1753 DCB_CMD_GDCBX
, DCB_ATTR_DCBX
, pid
, seq
, flags
);
1758 static int dcbnl_setdcbx(struct net_device
*netdev
, struct nlattr
**tb
,
1759 u32 pid
, u32 seq
, u16 flags
)
1764 if (!netdev
->dcbnl_ops
->setdcbx
)
1767 if (!tb
[DCB_ATTR_DCBX
])
1770 value
= nla_get_u8(tb
[DCB_ATTR_DCBX
]);
1772 ret
= dcbnl_reply(netdev
->dcbnl_ops
->setdcbx(netdev
, value
),
1773 RTM_SETDCB
, DCB_CMD_SDCBX
, DCB_ATTR_DCBX
,
1779 static int dcbnl_getfeatcfg(struct net_device
*netdev
, struct nlattr
**tb
,
1780 u32 pid
, u32 seq
, u16 flags
)
1782 struct sk_buff
*dcbnl_skb
;
1783 struct nlmsghdr
*nlh
;
1785 struct nlattr
*data
[DCB_FEATCFG_ATTR_MAX
+ 1], *nest
;
1790 if (!netdev
->dcbnl_ops
->getfeatcfg
)
1793 if (!tb
[DCB_ATTR_FEATCFG
])
1796 ret
= nla_parse_nested(data
, DCB_FEATCFG_ATTR_MAX
, tb
[DCB_ATTR_FEATCFG
],
1797 dcbnl_featcfg_nest
);
1801 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1807 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
1809 dcb
= NLMSG_DATA(nlh
);
1810 dcb
->dcb_family
= AF_UNSPEC
;
1811 dcb
->cmd
= DCB_CMD_GFEATCFG
;
1813 nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_FEATCFG
);
1816 goto nla_put_failure
;
1819 if (data
[DCB_FEATCFG_ATTR_ALL
])
1822 for (i
= DCB_FEATCFG_ATTR_ALL
+1; i
<= DCB_FEATCFG_ATTR_MAX
; i
++) {
1823 if (!getall
&& !data
[i
])
1826 ret
= netdev
->dcbnl_ops
->getfeatcfg(netdev
, i
, &value
);
1828 ret
= nla_put_u8(dcbnl_skb
, i
, value
);
1831 nla_nest_cancel(dcbnl_skb
, nest
);
1832 goto nla_put_failure
;
1835 nla_nest_end(dcbnl_skb
, nest
);
1837 nlmsg_end(dcbnl_skb
, nlh
);
1839 return rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
1841 nlmsg_cancel(dcbnl_skb
, nlh
);
1843 kfree_skb(dcbnl_skb
);
1848 static int dcbnl_setfeatcfg(struct net_device
*netdev
, struct nlattr
**tb
,
1849 u32 pid
, u32 seq
, u16 flags
)
1851 struct nlattr
*data
[DCB_FEATCFG_ATTR_MAX
+ 1];
1855 if (!netdev
->dcbnl_ops
->setfeatcfg
)
1858 if (!tb
[DCB_ATTR_FEATCFG
])
1861 ret
= nla_parse_nested(data
, DCB_FEATCFG_ATTR_MAX
, tb
[DCB_ATTR_FEATCFG
],
1862 dcbnl_featcfg_nest
);
1867 for (i
= DCB_FEATCFG_ATTR_ALL
+1; i
<= DCB_FEATCFG_ATTR_MAX
; i
++) {
1868 if (data
[i
] == NULL
)
1871 value
= nla_get_u8(data
[i
]);
1873 ret
= netdev
->dcbnl_ops
->setfeatcfg(netdev
, i
, value
);
1879 dcbnl_reply(ret
, RTM_SETDCB
, DCB_CMD_SFEATCFG
, DCB_ATTR_FEATCFG
,
1885 /* Handle CEE DCBX GET commands. */
1886 static int dcbnl_cee_get(struct net_device
*netdev
, struct nlattr
**tb
,
1887 u32 pid
, u32 seq
, u16 flags
)
1889 struct net
*net
= dev_net(netdev
);
1890 struct sk_buff
*skb
;
1891 struct nlmsghdr
*nlh
;
1893 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1899 skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1903 nlh
= nlmsg_put(skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
1909 dcb
= NLMSG_DATA(nlh
);
1910 dcb
->dcb_family
= AF_UNSPEC
;
1911 dcb
->cmd
= DCB_CMD_CEE_GET
;
1913 err
= dcbnl_cee_fill(skb
, netdev
);
1916 nlmsg_cancel(skb
, nlh
);
1919 nlmsg_end(skb
, nlh
);
1920 err
= rtnl_unicast(skb
, net
, pid
);
1925 static int dcb_doit(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
1927 struct net
*net
= sock_net(skb
->sk
);
1928 struct net_device
*netdev
;
1929 struct dcbmsg
*dcb
= (struct dcbmsg
*)NLMSG_DATA(nlh
);
1930 struct nlattr
*tb
[DCB_ATTR_MAX
+ 1];
1931 u32 pid
= skb
? NETLINK_CB(skb
).pid
: 0;
1934 if (!net_eq(net
, &init_net
))
1937 ret
= nlmsg_parse(nlh
, sizeof(*dcb
), tb
, DCB_ATTR_MAX
,
1942 if (!tb
[DCB_ATTR_IFNAME
])
1945 netdev
= dev_get_by_name(&init_net
, nla_data(tb
[DCB_ATTR_IFNAME
]));
1949 if (!netdev
->dcbnl_ops
)
1953 case DCB_CMD_GSTATE
:
1954 ret
= dcbnl_getstate(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1957 case DCB_CMD_PFC_GCFG
:
1958 ret
= dcbnl_getpfccfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1961 case DCB_CMD_GPERM_HWADDR
:
1962 ret
= dcbnl_getperm_hwaddr(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1965 case DCB_CMD_PGTX_GCFG
:
1966 ret
= dcbnl_pgtx_getcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1969 case DCB_CMD_PGRX_GCFG
:
1970 ret
= dcbnl_pgrx_getcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1973 case DCB_CMD_BCN_GCFG
:
1974 ret
= dcbnl_bcn_getcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1977 case DCB_CMD_SSTATE
:
1978 ret
= dcbnl_setstate(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1981 case DCB_CMD_PFC_SCFG
:
1982 ret
= dcbnl_setpfccfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1986 case DCB_CMD_SET_ALL
:
1987 ret
= dcbnl_setall(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1990 case DCB_CMD_PGTX_SCFG
:
1991 ret
= dcbnl_pgtx_setcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1994 case DCB_CMD_PGRX_SCFG
:
1995 ret
= dcbnl_pgrx_setcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1999 ret
= dcbnl_getcap(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2002 case DCB_CMD_GNUMTCS
:
2003 ret
= dcbnl_getnumtcs(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2006 case DCB_CMD_SNUMTCS
:
2007 ret
= dcbnl_setnumtcs(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2010 case DCB_CMD_PFC_GSTATE
:
2011 ret
= dcbnl_getpfcstate(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2014 case DCB_CMD_PFC_SSTATE
:
2015 ret
= dcbnl_setpfcstate(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2018 case DCB_CMD_BCN_SCFG
:
2019 ret
= dcbnl_bcn_setcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2023 ret
= dcbnl_getapp(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2027 ret
= dcbnl_setapp(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2030 case DCB_CMD_IEEE_SET
:
2031 ret
= dcbnl_ieee_set(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2034 case DCB_CMD_IEEE_GET
:
2035 ret
= dcbnl_ieee_get(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2038 case DCB_CMD_IEEE_DEL
:
2039 ret
= dcbnl_ieee_del(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2043 ret
= dcbnl_getdcbx(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2047 ret
= dcbnl_setdcbx(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2050 case DCB_CMD_GFEATCFG
:
2051 ret
= dcbnl_getfeatcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2054 case DCB_CMD_SFEATCFG
:
2055 ret
= dcbnl_setfeatcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2058 case DCB_CMD_CEE_GET
:
2059 ret
= dcbnl_cee_get(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2073 * dcb_getapp - retrieve the DCBX application user priority
2075 * On success returns a non-zero 802.1p user priority bitmap
2076 * otherwise returns 0 as the invalid user priority bitmap to
2077 * indicate an error.
2079 u8
dcb_getapp(struct net_device
*dev
, struct dcb_app
*app
)
2081 struct dcb_app_type
*itr
;
2084 spin_lock(&dcb_lock
);
2085 list_for_each_entry(itr
, &dcb_app_list
, list
) {
2086 if (itr
->app
.selector
== app
->selector
&&
2087 itr
->app
.protocol
== app
->protocol
&&
2088 itr
->ifindex
== dev
->ifindex
) {
2089 prio
= itr
->app
.priority
;
2093 spin_unlock(&dcb_lock
);
2097 EXPORT_SYMBOL(dcb_getapp
);
2100 * dcb_setapp - add CEE dcb application data to app list
2102 * Priority 0 is an invalid priority in CEE spec. This routine
2103 * removes applications from the app list if the priority is
2106 int dcb_setapp(struct net_device
*dev
, struct dcb_app
*new)
2108 struct dcb_app_type
*itr
;
2109 struct dcb_app_type event
;
2111 event
.ifindex
= dev
->ifindex
;
2112 memcpy(&event
.app
, new, sizeof(event
.app
));
2113 if (dev
->dcbnl_ops
->getdcbx
)
2114 event
.dcbx
= dev
->dcbnl_ops
->getdcbx(dev
);
2116 spin_lock(&dcb_lock
);
2117 /* Search for existing match and replace */
2118 list_for_each_entry(itr
, &dcb_app_list
, list
) {
2119 if (itr
->app
.selector
== new->selector
&&
2120 itr
->app
.protocol
== new->protocol
&&
2121 itr
->ifindex
== dev
->ifindex
) {
2123 itr
->app
.priority
= new->priority
;
2125 list_del(&itr
->list
);
2131 /* App type does not exist add new application type */
2132 if (new->priority
) {
2133 struct dcb_app_type
*entry
;
2134 entry
= kmalloc(sizeof(struct dcb_app_type
), GFP_ATOMIC
);
2136 spin_unlock(&dcb_lock
);
2140 memcpy(&entry
->app
, new, sizeof(*new));
2141 entry
->ifindex
= dev
->ifindex
;
2142 list_add(&entry
->list
, &dcb_app_list
);
2145 spin_unlock(&dcb_lock
);
2146 call_dcbevent_notifiers(DCB_APP_EVENT
, &event
);
2149 EXPORT_SYMBOL(dcb_setapp
);
2152 * dcb_ieee_getapp_mask - retrieve the IEEE DCB application priority
2154 * Helper routine which on success returns a non-zero 802.1Qaz user
2155 * priority bitmap otherwise returns 0 to indicate the dcb_app was
2156 * not found in APP list.
2158 u8
dcb_ieee_getapp_mask(struct net_device
*dev
, struct dcb_app
*app
)
2160 struct dcb_app_type
*itr
;
2163 spin_lock(&dcb_lock
);
2164 list_for_each_entry(itr
, &dcb_app_list
, list
) {
2165 if (itr
->app
.selector
== app
->selector
&&
2166 itr
->app
.protocol
== app
->protocol
&&
2167 itr
->ifindex
== dev
->ifindex
) {
2168 prio
|= 1 << itr
->app
.priority
;
2171 spin_unlock(&dcb_lock
);
2175 EXPORT_SYMBOL(dcb_ieee_getapp_mask
);
2178 * dcb_ieee_setapp - add IEEE dcb application data to app list
2180 * This adds Application data to the list. Multiple application
2181 * entries may exists for the same selector and protocol as long
2182 * as the priorities are different.
2184 int dcb_ieee_setapp(struct net_device
*dev
, struct dcb_app
*new)
2186 struct dcb_app_type
*itr
, *entry
;
2187 struct dcb_app_type event
;
2190 event
.ifindex
= dev
->ifindex
;
2191 memcpy(&event
.app
, new, sizeof(event
.app
));
2192 if (dev
->dcbnl_ops
->getdcbx
)
2193 event
.dcbx
= dev
->dcbnl_ops
->getdcbx(dev
);
2195 spin_lock(&dcb_lock
);
2196 /* Search for existing match and abort if found */
2197 list_for_each_entry(itr
, &dcb_app_list
, list
) {
2198 if (itr
->app
.selector
== new->selector
&&
2199 itr
->app
.protocol
== new->protocol
&&
2200 itr
->app
.priority
== new->priority
&&
2201 itr
->ifindex
== dev
->ifindex
) {
2207 /* App entry does not exist add new entry */
2208 entry
= kmalloc(sizeof(struct dcb_app_type
), GFP_ATOMIC
);
2214 memcpy(&entry
->app
, new, sizeof(*new));
2215 entry
->ifindex
= dev
->ifindex
;
2216 list_add(&entry
->list
, &dcb_app_list
);
2218 spin_unlock(&dcb_lock
);
2220 call_dcbevent_notifiers(DCB_APP_EVENT
, &event
);
2223 EXPORT_SYMBOL(dcb_ieee_setapp
);
2226 * dcb_ieee_delapp - delete IEEE dcb application data from list
2228 * This removes a matching APP data from the APP list
2230 int dcb_ieee_delapp(struct net_device
*dev
, struct dcb_app
*del
)
2232 struct dcb_app_type
*itr
;
2233 struct dcb_app_type event
;
2236 event
.ifindex
= dev
->ifindex
;
2237 memcpy(&event
.app
, del
, sizeof(event
.app
));
2238 if (dev
->dcbnl_ops
->getdcbx
)
2239 event
.dcbx
= dev
->dcbnl_ops
->getdcbx(dev
);
2241 spin_lock(&dcb_lock
);
2242 /* Search for existing match and remove it. */
2243 list_for_each_entry(itr
, &dcb_app_list
, list
) {
2244 if (itr
->app
.selector
== del
->selector
&&
2245 itr
->app
.protocol
== del
->protocol
&&
2246 itr
->app
.priority
== del
->priority
&&
2247 itr
->ifindex
== dev
->ifindex
) {
2248 list_del(&itr
->list
);
2256 spin_unlock(&dcb_lock
);
2258 call_dcbevent_notifiers(DCB_APP_EVENT
, &event
);
2261 EXPORT_SYMBOL(dcb_ieee_delapp
);
2263 static void dcb_flushapp(void)
2265 struct dcb_app_type
*app
;
2266 struct dcb_app_type
*tmp
;
2268 spin_lock(&dcb_lock
);
2269 list_for_each_entry_safe(app
, tmp
, &dcb_app_list
, list
) {
2270 list_del(&app
->list
);
2273 spin_unlock(&dcb_lock
);
2276 static int __init
dcbnl_init(void)
2278 INIT_LIST_HEAD(&dcb_app_list
);
2280 rtnl_register(PF_UNSPEC
, RTM_GETDCB
, dcb_doit
, NULL
, NULL
);
2281 rtnl_register(PF_UNSPEC
, RTM_SETDCB
, dcb_doit
, NULL
, NULL
);
2285 module_init(dcbnl_init
);
2287 static void __exit
dcbnl_exit(void)
2289 rtnl_unregister(PF_UNSPEC
, RTM_GETDCB
);
2290 rtnl_unregister(PF_UNSPEC
, RTM_SETDCB
);
2293 module_exit(dcbnl_exit
);