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
},
183 static const struct nla_policy dcbnl_ieee_app
[DCB_ATTR_IEEE_APP_MAX
+ 1] = {
184 [DCB_ATTR_IEEE_APP
] = {.len
= sizeof(struct dcb_app
)},
187 /* DCB number of traffic classes nested attributes. */
188 static const struct nla_policy dcbnl_featcfg_nest
[DCB_FEATCFG_ATTR_MAX
+ 1] = {
189 [DCB_FEATCFG_ATTR_ALL
] = {.type
= NLA_FLAG
},
190 [DCB_FEATCFG_ATTR_PG
] = {.type
= NLA_U8
},
191 [DCB_FEATCFG_ATTR_PFC
] = {.type
= NLA_U8
},
192 [DCB_FEATCFG_ATTR_APP
] = {.type
= NLA_U8
},
195 static LIST_HEAD(dcb_app_list
);
196 static DEFINE_SPINLOCK(dcb_lock
);
198 /* standard netlink reply call */
199 static int dcbnl_reply(u8 value
, u8 event
, u8 cmd
, u8 attr
, u32 pid
,
202 struct sk_buff
*dcbnl_skb
;
204 struct nlmsghdr
*nlh
;
207 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
211 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, event
, sizeof(*dcb
), flags
);
213 dcb
= NLMSG_DATA(nlh
);
214 dcb
->dcb_family
= AF_UNSPEC
;
218 ret
= nla_put_u8(dcbnl_skb
, attr
, value
);
222 /* end the message, assign the nlmsg_len. */
223 nlmsg_end(dcbnl_skb
, nlh
);
224 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
231 kfree_skb(dcbnl_skb
);
235 static int dcbnl_getstate(struct net_device
*netdev
, struct nlattr
**tb
,
236 u32 pid
, u32 seq
, u16 flags
)
240 /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
241 if (!netdev
->dcbnl_ops
->getstate
)
244 ret
= dcbnl_reply(netdev
->dcbnl_ops
->getstate(netdev
), RTM_GETDCB
,
245 DCB_CMD_GSTATE
, DCB_ATTR_STATE
, pid
, seq
, flags
);
250 static int dcbnl_getpfccfg(struct net_device
*netdev
, struct nlattr
**tb
,
251 u32 pid
, u32 seq
, u16 flags
)
253 struct sk_buff
*dcbnl_skb
;
254 struct nlmsghdr
*nlh
;
256 struct nlattr
*data
[DCB_PFC_UP_ATTR_MAX
+ 1], *nest
;
262 if (!tb
[DCB_ATTR_PFC_CFG
] || !netdev
->dcbnl_ops
->getpfccfg
)
265 ret
= nla_parse_nested(data
, DCB_PFC_UP_ATTR_MAX
,
266 tb
[DCB_ATTR_PFC_CFG
],
271 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
275 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
277 dcb
= NLMSG_DATA(nlh
);
278 dcb
->dcb_family
= AF_UNSPEC
;
279 dcb
->cmd
= DCB_CMD_PFC_GCFG
;
281 nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_PFC_CFG
);
285 if (data
[DCB_PFC_UP_ATTR_ALL
])
288 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
289 if (!getall
&& !data
[i
])
292 netdev
->dcbnl_ops
->getpfccfg(netdev
, i
- DCB_PFC_UP_ATTR_0
,
294 ret
= nla_put_u8(dcbnl_skb
, i
, value
);
297 nla_nest_cancel(dcbnl_skb
, nest
);
301 nla_nest_end(dcbnl_skb
, nest
);
303 nlmsg_end(dcbnl_skb
, nlh
);
305 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
312 kfree_skb(dcbnl_skb
);
317 static int dcbnl_getperm_hwaddr(struct net_device
*netdev
, struct nlattr
**tb
,
318 u32 pid
, u32 seq
, u16 flags
)
320 struct sk_buff
*dcbnl_skb
;
321 struct nlmsghdr
*nlh
;
323 u8 perm_addr
[MAX_ADDR_LEN
];
326 if (!netdev
->dcbnl_ops
->getpermhwaddr
)
329 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
333 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
335 dcb
= NLMSG_DATA(nlh
);
336 dcb
->dcb_family
= AF_UNSPEC
;
337 dcb
->cmd
= DCB_CMD_GPERM_HWADDR
;
339 netdev
->dcbnl_ops
->getpermhwaddr(netdev
, perm_addr
);
341 ret
= nla_put(dcbnl_skb
, DCB_ATTR_PERM_HWADDR
, sizeof(perm_addr
),
344 nlmsg_end(dcbnl_skb
, nlh
);
346 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
353 kfree_skb(dcbnl_skb
);
358 static int dcbnl_getcap(struct net_device
*netdev
, struct nlattr
**tb
,
359 u32 pid
, u32 seq
, u16 flags
)
361 struct sk_buff
*dcbnl_skb
;
362 struct nlmsghdr
*nlh
;
364 struct nlattr
*data
[DCB_CAP_ATTR_MAX
+ 1], *nest
;
370 if (!tb
[DCB_ATTR_CAP
] || !netdev
->dcbnl_ops
->getcap
)
373 ret
= nla_parse_nested(data
, DCB_CAP_ATTR_MAX
, tb
[DCB_ATTR_CAP
],
378 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
382 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
384 dcb
= NLMSG_DATA(nlh
);
385 dcb
->dcb_family
= AF_UNSPEC
;
386 dcb
->cmd
= DCB_CMD_GCAP
;
388 nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_CAP
);
392 if (data
[DCB_CAP_ATTR_ALL
])
395 for (i
= DCB_CAP_ATTR_ALL
+1; i
<= DCB_CAP_ATTR_MAX
; i
++) {
396 if (!getall
&& !data
[i
])
399 if (!netdev
->dcbnl_ops
->getcap(netdev
, i
, &value
)) {
400 ret
= nla_put_u8(dcbnl_skb
, i
, value
);
403 nla_nest_cancel(dcbnl_skb
, nest
);
408 nla_nest_end(dcbnl_skb
, nest
);
410 nlmsg_end(dcbnl_skb
, nlh
);
412 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
419 kfree_skb(dcbnl_skb
);
424 static int dcbnl_getnumtcs(struct net_device
*netdev
, struct nlattr
**tb
,
425 u32 pid
, u32 seq
, u16 flags
)
427 struct sk_buff
*dcbnl_skb
;
428 struct nlmsghdr
*nlh
;
430 struct nlattr
*data
[DCB_NUMTCS_ATTR_MAX
+ 1], *nest
;
436 if (!tb
[DCB_ATTR_NUMTCS
] || !netdev
->dcbnl_ops
->getnumtcs
)
439 ret
= nla_parse_nested(data
, DCB_NUMTCS_ATTR_MAX
, tb
[DCB_ATTR_NUMTCS
],
446 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
452 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
454 dcb
= NLMSG_DATA(nlh
);
455 dcb
->dcb_family
= AF_UNSPEC
;
456 dcb
->cmd
= DCB_CMD_GNUMTCS
;
458 nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_NUMTCS
);
464 if (data
[DCB_NUMTCS_ATTR_ALL
])
467 for (i
= DCB_NUMTCS_ATTR_ALL
+1; i
<= DCB_NUMTCS_ATTR_MAX
; i
++) {
468 if (!getall
&& !data
[i
])
471 ret
= netdev
->dcbnl_ops
->getnumtcs(netdev
, i
, &value
);
473 ret
= nla_put_u8(dcbnl_skb
, i
, value
);
476 nla_nest_cancel(dcbnl_skb
, nest
);
484 nla_nest_end(dcbnl_skb
, nest
);
486 nlmsg_end(dcbnl_skb
, nlh
);
488 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
497 kfree_skb(dcbnl_skb
);
502 static int dcbnl_setnumtcs(struct net_device
*netdev
, struct nlattr
**tb
,
503 u32 pid
, u32 seq
, u16 flags
)
505 struct nlattr
*data
[DCB_NUMTCS_ATTR_MAX
+ 1];
510 if (!tb
[DCB_ATTR_NUMTCS
] || !netdev
->dcbnl_ops
->setnumtcs
)
513 ret
= nla_parse_nested(data
, DCB_NUMTCS_ATTR_MAX
, tb
[DCB_ATTR_NUMTCS
],
521 for (i
= DCB_NUMTCS_ATTR_ALL
+1; i
<= DCB_NUMTCS_ATTR_MAX
; i
++) {
525 value
= nla_get_u8(data
[i
]);
527 ret
= netdev
->dcbnl_ops
->setnumtcs(netdev
, i
, value
);
534 ret
= dcbnl_reply(!!ret
, RTM_SETDCB
, DCB_CMD_SNUMTCS
,
535 DCB_ATTR_NUMTCS
, pid
, seq
, flags
);
541 static int dcbnl_getpfcstate(struct net_device
*netdev
, struct nlattr
**tb
,
542 u32 pid
, u32 seq
, u16 flags
)
546 if (!netdev
->dcbnl_ops
->getpfcstate
)
549 ret
= dcbnl_reply(netdev
->dcbnl_ops
->getpfcstate(netdev
), RTM_GETDCB
,
550 DCB_CMD_PFC_GSTATE
, DCB_ATTR_PFC_STATE
,
556 static int dcbnl_setpfcstate(struct net_device
*netdev
, struct nlattr
**tb
,
557 u32 pid
, u32 seq
, u16 flags
)
562 if (!tb
[DCB_ATTR_PFC_STATE
] || !netdev
->dcbnl_ops
->setpfcstate
)
565 value
= nla_get_u8(tb
[DCB_ATTR_PFC_STATE
]);
567 netdev
->dcbnl_ops
->setpfcstate(netdev
, value
);
569 ret
= dcbnl_reply(0, RTM_SETDCB
, DCB_CMD_PFC_SSTATE
, DCB_ATTR_PFC_STATE
,
575 static int dcbnl_getapp(struct net_device
*netdev
, struct nlattr
**tb
,
576 u32 pid
, u32 seq
, u16 flags
)
578 struct sk_buff
*dcbnl_skb
;
579 struct nlmsghdr
*nlh
;
581 struct nlattr
*app_nest
;
582 struct nlattr
*app_tb
[DCB_APP_ATTR_MAX
+ 1];
587 if (!tb
[DCB_ATTR_APP
])
590 ret
= nla_parse_nested(app_tb
, DCB_APP_ATTR_MAX
, tb
[DCB_ATTR_APP
],
596 /* all must be non-null */
597 if ((!app_tb
[DCB_APP_ATTR_IDTYPE
]) ||
598 (!app_tb
[DCB_APP_ATTR_ID
]))
601 /* either by eth type or by socket number */
602 idtype
= nla_get_u8(app_tb
[DCB_APP_ATTR_IDTYPE
]);
603 if ((idtype
!= DCB_APP_IDTYPE_ETHTYPE
) &&
604 (idtype
!= DCB_APP_IDTYPE_PORTNUM
))
607 id
= nla_get_u16(app_tb
[DCB_APP_ATTR_ID
]);
609 if (netdev
->dcbnl_ops
->getapp
) {
610 up
= netdev
->dcbnl_ops
->getapp(netdev
, idtype
, id
);
612 struct dcb_app app
= {
616 up
= dcb_getapp(netdev
, &app
);
620 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
624 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
625 dcb
= NLMSG_DATA(nlh
);
626 dcb
->dcb_family
= AF_UNSPEC
;
627 dcb
->cmd
= DCB_CMD_GAPP
;
629 app_nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_APP
);
633 ret
= nla_put_u8(dcbnl_skb
, DCB_APP_ATTR_IDTYPE
, idtype
);
637 ret
= nla_put_u16(dcbnl_skb
, DCB_APP_ATTR_ID
, id
);
641 ret
= nla_put_u8(dcbnl_skb
, DCB_APP_ATTR_PRIORITY
, up
);
645 nla_nest_end(dcbnl_skb
, app_nest
);
646 nlmsg_end(dcbnl_skb
, nlh
);
648 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
655 nla_nest_cancel(dcbnl_skb
, app_nest
);
657 kfree_skb(dcbnl_skb
);
662 static int dcbnl_setapp(struct net_device
*netdev
, struct nlattr
**tb
,
663 u32 pid
, u32 seq
, u16 flags
)
665 int err
, ret
= -EINVAL
;
668 struct nlattr
*app_tb
[DCB_APP_ATTR_MAX
+ 1];
670 if (!tb
[DCB_ATTR_APP
])
673 ret
= nla_parse_nested(app_tb
, DCB_APP_ATTR_MAX
, tb
[DCB_ATTR_APP
],
679 /* all must be non-null */
680 if ((!app_tb
[DCB_APP_ATTR_IDTYPE
]) ||
681 (!app_tb
[DCB_APP_ATTR_ID
]) ||
682 (!app_tb
[DCB_APP_ATTR_PRIORITY
]))
685 /* either by eth type or by socket number */
686 idtype
= nla_get_u8(app_tb
[DCB_APP_ATTR_IDTYPE
]);
687 if ((idtype
!= DCB_APP_IDTYPE_ETHTYPE
) &&
688 (idtype
!= DCB_APP_IDTYPE_PORTNUM
))
691 id
= nla_get_u16(app_tb
[DCB_APP_ATTR_ID
]);
692 up
= nla_get_u8(app_tb
[DCB_APP_ATTR_PRIORITY
]);
694 if (netdev
->dcbnl_ops
->setapp
) {
695 err
= netdev
->dcbnl_ops
->setapp(netdev
, idtype
, id
, up
);
698 app
.selector
= idtype
;
701 err
= dcb_setapp(netdev
, &app
);
704 ret
= dcbnl_reply(err
, RTM_SETDCB
, DCB_CMD_SAPP
, DCB_ATTR_APP
,
710 static int __dcbnl_pg_getcfg(struct net_device
*netdev
, struct nlattr
**tb
,
711 u32 pid
, u32 seq
, u16 flags
, int dir
)
713 struct sk_buff
*dcbnl_skb
;
714 struct nlmsghdr
*nlh
;
716 struct nlattr
*pg_nest
, *param_nest
, *data
;
717 struct nlattr
*pg_tb
[DCB_PG_ATTR_MAX
+ 1];
718 struct nlattr
*param_tb
[DCB_TC_ATTR_PARAM_MAX
+ 1];
719 u8 prio
, pgid
, tc_pct
, up_map
;
724 if (!tb
[DCB_ATTR_PG_CFG
] ||
725 !netdev
->dcbnl_ops
->getpgtccfgtx
||
726 !netdev
->dcbnl_ops
->getpgtccfgrx
||
727 !netdev
->dcbnl_ops
->getpgbwgcfgtx
||
728 !netdev
->dcbnl_ops
->getpgbwgcfgrx
)
731 ret
= nla_parse_nested(pg_tb
, DCB_PG_ATTR_MAX
,
732 tb
[DCB_ATTR_PG_CFG
], dcbnl_pg_nest
);
737 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
741 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
743 dcb
= NLMSG_DATA(nlh
);
744 dcb
->dcb_family
= AF_UNSPEC
;
745 dcb
->cmd
= (dir
) ? DCB_CMD_PGRX_GCFG
: DCB_CMD_PGTX_GCFG
;
747 pg_nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_PG_CFG
);
751 if (pg_tb
[DCB_PG_ATTR_TC_ALL
])
754 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
755 if (!getall
&& !pg_tb
[i
])
758 if (pg_tb
[DCB_PG_ATTR_TC_ALL
])
759 data
= pg_tb
[DCB_PG_ATTR_TC_ALL
];
762 ret
= nla_parse_nested(param_tb
, DCB_TC_ATTR_PARAM_MAX
,
763 data
, dcbnl_tc_param_nest
);
767 param_nest
= nla_nest_start(dcbnl_skb
, i
);
771 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
772 prio
= DCB_ATTR_VALUE_UNDEFINED
;
773 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
774 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
778 netdev
->dcbnl_ops
->getpgtccfgrx(netdev
,
779 i
- DCB_PG_ATTR_TC_0
, &prio
,
780 &pgid
, &tc_pct
, &up_map
);
783 netdev
->dcbnl_ops
->getpgtccfgtx(netdev
,
784 i
- DCB_PG_ATTR_TC_0
, &prio
,
785 &pgid
, &tc_pct
, &up_map
);
788 if (param_tb
[DCB_TC_ATTR_PARAM_PGID
] ||
789 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
790 ret
= nla_put_u8(dcbnl_skb
,
791 DCB_TC_ATTR_PARAM_PGID
, pgid
);
795 if (param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
] ||
796 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
797 ret
= nla_put_u8(dcbnl_skb
,
798 DCB_TC_ATTR_PARAM_UP_MAPPING
, up_map
);
802 if (param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
] ||
803 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
804 ret
= nla_put_u8(dcbnl_skb
,
805 DCB_TC_ATTR_PARAM_STRICT_PRIO
, prio
);
809 if (param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
] ||
810 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
811 ret
= nla_put_u8(dcbnl_skb
, DCB_TC_ATTR_PARAM_BW_PCT
,
816 nla_nest_end(dcbnl_skb
, param_nest
);
819 if (pg_tb
[DCB_PG_ATTR_BW_ID_ALL
])
824 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
825 if (!getall
&& !pg_tb
[i
])
828 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
832 netdev
->dcbnl_ops
->getpgbwgcfgrx(netdev
,
833 i
- DCB_PG_ATTR_BW_ID_0
, &tc_pct
);
836 netdev
->dcbnl_ops
->getpgbwgcfgtx(netdev
,
837 i
- DCB_PG_ATTR_BW_ID_0
, &tc_pct
);
839 ret
= nla_put_u8(dcbnl_skb
, i
, tc_pct
);
845 nla_nest_end(dcbnl_skb
, pg_nest
);
847 nlmsg_end(dcbnl_skb
, nlh
);
849 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
856 nla_nest_cancel(dcbnl_skb
, param_nest
);
858 nla_nest_cancel(dcbnl_skb
, pg_nest
);
861 kfree_skb(dcbnl_skb
);
867 static int dcbnl_pgtx_getcfg(struct net_device
*netdev
, struct nlattr
**tb
,
868 u32 pid
, u32 seq
, u16 flags
)
870 return __dcbnl_pg_getcfg(netdev
, tb
, pid
, seq
, flags
, 0);
873 static int dcbnl_pgrx_getcfg(struct net_device
*netdev
, struct nlattr
**tb
,
874 u32 pid
, u32 seq
, u16 flags
)
876 return __dcbnl_pg_getcfg(netdev
, tb
, pid
, seq
, flags
, 1);
879 static int dcbnl_setstate(struct net_device
*netdev
, struct nlattr
**tb
,
880 u32 pid
, u32 seq
, u16 flags
)
885 if (!tb
[DCB_ATTR_STATE
] || !netdev
->dcbnl_ops
->setstate
)
888 value
= nla_get_u8(tb
[DCB_ATTR_STATE
]);
890 ret
= dcbnl_reply(netdev
->dcbnl_ops
->setstate(netdev
, value
),
891 RTM_SETDCB
, DCB_CMD_SSTATE
, DCB_ATTR_STATE
,
897 static int dcbnl_setpfccfg(struct net_device
*netdev
, struct nlattr
**tb
,
898 u32 pid
, u32 seq
, u16 flags
)
900 struct nlattr
*data
[DCB_PFC_UP_ATTR_MAX
+ 1];
905 if (!tb
[DCB_ATTR_PFC_CFG
] || !netdev
->dcbnl_ops
->setpfccfg
)
908 ret
= nla_parse_nested(data
, DCB_PFC_UP_ATTR_MAX
,
909 tb
[DCB_ATTR_PFC_CFG
],
914 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
917 value
= nla_get_u8(data
[i
]);
918 netdev
->dcbnl_ops
->setpfccfg(netdev
,
919 data
[i
]->nla_type
- DCB_PFC_UP_ATTR_0
, value
);
922 ret
= dcbnl_reply(0, RTM_SETDCB
, DCB_CMD_PFC_SCFG
, DCB_ATTR_PFC_CFG
,
928 static int dcbnl_setall(struct net_device
*netdev
, struct nlattr
**tb
,
929 u32 pid
, u32 seq
, u16 flags
)
933 if (!tb
[DCB_ATTR_SET_ALL
] || !netdev
->dcbnl_ops
->setall
)
936 ret
= dcbnl_reply(netdev
->dcbnl_ops
->setall(netdev
), RTM_SETDCB
,
937 DCB_CMD_SET_ALL
, DCB_ATTR_SET_ALL
, pid
, seq
, flags
);
942 static int __dcbnl_pg_setcfg(struct net_device
*netdev
, struct nlattr
**tb
,
943 u32 pid
, u32 seq
, u16 flags
, int dir
)
945 struct nlattr
*pg_tb
[DCB_PG_ATTR_MAX
+ 1];
946 struct nlattr
*param_tb
[DCB_TC_ATTR_PARAM_MAX
+ 1];
954 if (!tb
[DCB_ATTR_PG_CFG
] ||
955 !netdev
->dcbnl_ops
->setpgtccfgtx
||
956 !netdev
->dcbnl_ops
->setpgtccfgrx
||
957 !netdev
->dcbnl_ops
->setpgbwgcfgtx
||
958 !netdev
->dcbnl_ops
->setpgbwgcfgrx
)
961 ret
= nla_parse_nested(pg_tb
, DCB_PG_ATTR_MAX
,
962 tb
[DCB_ATTR_PG_CFG
], dcbnl_pg_nest
);
966 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
970 ret
= nla_parse_nested(param_tb
, DCB_TC_ATTR_PARAM_MAX
,
971 pg_tb
[i
], dcbnl_tc_param_nest
);
975 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
976 prio
= DCB_ATTR_VALUE_UNDEFINED
;
977 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
978 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
980 if (param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
])
982 nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
]);
984 if (param_tb
[DCB_TC_ATTR_PARAM_PGID
])
985 pgid
= nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_PGID
]);
987 if (param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
])
988 tc_pct
= nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
]);
990 if (param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
])
992 nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
]);
994 /* dir: Tx = 0, Rx = 1 */
997 netdev
->dcbnl_ops
->setpgtccfgrx(netdev
,
998 i
- DCB_PG_ATTR_TC_0
,
999 prio
, pgid
, tc_pct
, up_map
);
1002 netdev
->dcbnl_ops
->setpgtccfgtx(netdev
,
1003 i
- DCB_PG_ATTR_TC_0
,
1004 prio
, pgid
, tc_pct
, up_map
);
1008 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
1012 tc_pct
= nla_get_u8(pg_tb
[i
]);
1014 /* dir: Tx = 0, Rx = 1 */
1017 netdev
->dcbnl_ops
->setpgbwgcfgrx(netdev
,
1018 i
- DCB_PG_ATTR_BW_ID_0
, tc_pct
);
1021 netdev
->dcbnl_ops
->setpgbwgcfgtx(netdev
,
1022 i
- DCB_PG_ATTR_BW_ID_0
, tc_pct
);
1026 ret
= dcbnl_reply(0, RTM_SETDCB
,
1027 (dir
? DCB_CMD_PGRX_SCFG
: DCB_CMD_PGTX_SCFG
),
1028 DCB_ATTR_PG_CFG
, pid
, seq
, flags
);
1034 static int dcbnl_pgtx_setcfg(struct net_device
*netdev
, struct nlattr
**tb
,
1035 u32 pid
, u32 seq
, u16 flags
)
1037 return __dcbnl_pg_setcfg(netdev
, tb
, pid
, seq
, flags
, 0);
1040 static int dcbnl_pgrx_setcfg(struct net_device
*netdev
, struct nlattr
**tb
,
1041 u32 pid
, u32 seq
, u16 flags
)
1043 return __dcbnl_pg_setcfg(netdev
, tb
, pid
, seq
, flags
, 1);
1046 static int dcbnl_bcn_getcfg(struct net_device
*netdev
, struct nlattr
**tb
,
1047 u32 pid
, u32 seq
, u16 flags
)
1049 struct sk_buff
*dcbnl_skb
;
1050 struct nlmsghdr
*nlh
;
1052 struct nlattr
*bcn_nest
;
1053 struct nlattr
*bcn_tb
[DCB_BCN_ATTR_MAX
+ 1];
1057 bool getall
= false;
1060 if (!tb
[DCB_ATTR_BCN
] || !netdev
->dcbnl_ops
->getbcnrp
||
1061 !netdev
->dcbnl_ops
->getbcncfg
)
1064 ret
= nla_parse_nested(bcn_tb
, DCB_BCN_ATTR_MAX
,
1065 tb
[DCB_ATTR_BCN
], dcbnl_bcn_nest
);
1070 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1074 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
1076 dcb
= NLMSG_DATA(nlh
);
1077 dcb
->dcb_family
= AF_UNSPEC
;
1078 dcb
->cmd
= DCB_CMD_BCN_GCFG
;
1080 bcn_nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_BCN
);
1084 if (bcn_tb
[DCB_BCN_ATTR_ALL
])
1087 for (i
= DCB_BCN_ATTR_RP_0
; i
<= DCB_BCN_ATTR_RP_7
; i
++) {
1088 if (!getall
&& !bcn_tb
[i
])
1091 netdev
->dcbnl_ops
->getbcnrp(netdev
, i
- DCB_BCN_ATTR_RP_0
,
1093 ret
= nla_put_u8(dcbnl_skb
, i
, value_byte
);
1098 for (i
= DCB_BCN_ATTR_BCNA_0
; i
<= DCB_BCN_ATTR_RI
; i
++) {
1099 if (!getall
&& !bcn_tb
[i
])
1102 netdev
->dcbnl_ops
->getbcncfg(netdev
, i
,
1104 ret
= nla_put_u32(dcbnl_skb
, i
, value_integer
);
1109 nla_nest_end(dcbnl_skb
, bcn_nest
);
1111 nlmsg_end(dcbnl_skb
, nlh
);
1113 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
1120 nla_nest_cancel(dcbnl_skb
, bcn_nest
);
1123 kfree_skb(dcbnl_skb
);
1129 static int dcbnl_bcn_setcfg(struct net_device
*netdev
, struct nlattr
**tb
,
1130 u32 pid
, u32 seq
, u16 flags
)
1132 struct nlattr
*data
[DCB_BCN_ATTR_MAX
+ 1];
1138 if (!tb
[DCB_ATTR_BCN
] || !netdev
->dcbnl_ops
->setbcncfg
||
1139 !netdev
->dcbnl_ops
->setbcnrp
)
1142 ret
= nla_parse_nested(data
, DCB_BCN_ATTR_MAX
,
1148 for (i
= DCB_BCN_ATTR_RP_0
; i
<= DCB_BCN_ATTR_RP_7
; i
++) {
1149 if (data
[i
] == NULL
)
1151 value_byte
= nla_get_u8(data
[i
]);
1152 netdev
->dcbnl_ops
->setbcnrp(netdev
,
1153 data
[i
]->nla_type
- DCB_BCN_ATTR_RP_0
, value_byte
);
1156 for (i
= DCB_BCN_ATTR_BCNA_0
; i
<= DCB_BCN_ATTR_RI
; i
++) {
1157 if (data
[i
] == NULL
)
1159 value_int
= nla_get_u32(data
[i
]);
1160 netdev
->dcbnl_ops
->setbcncfg(netdev
,
1164 ret
= dcbnl_reply(0, RTM_SETDCB
, DCB_CMD_BCN_SCFG
, DCB_ATTR_BCN
,
1170 static int dcbnl_build_peer_app(struct net_device
*netdev
, struct sk_buff
* skb
,
1171 int app_nested_type
, int app_info_type
,
1174 struct dcb_peer_app_info info
;
1175 struct dcb_app
*table
= NULL
;
1176 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1182 * retrieve the peer app configuration form the driver. If the driver
1183 * handlers fail exit without doing anything
1185 err
= ops
->peer_getappinfo(netdev
, &info
, &app_count
);
1186 if (!err
&& app_count
) {
1187 table
= kmalloc(sizeof(struct dcb_app
) * app_count
, GFP_KERNEL
);
1191 err
= ops
->peer_getapptable(netdev
, table
);
1199 * build the message, from here on the only possible failure
1200 * is due to the skb size
1204 app
= nla_nest_start(skb
, app_nested_type
);
1206 goto nla_put_failure
;
1209 NLA_PUT(skb
, app_info_type
, sizeof(info
), &info
);
1211 for (i
= 0; i
< app_count
; i
++)
1212 NLA_PUT(skb
, app_entry_type
, sizeof(struct dcb_app
),
1215 nla_nest_end(skb
, app
);
1224 /* Handle IEEE 802.1Qaz GET commands. */
1225 static int dcbnl_ieee_fill(struct sk_buff
*skb
, struct net_device
*netdev
)
1227 struct nlattr
*ieee
, *app
;
1228 struct dcb_app_type
*itr
;
1229 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1231 int err
= -EMSGSIZE
;
1233 NLA_PUT_STRING(skb
, DCB_ATTR_IFNAME
, netdev
->name
);
1235 ieee
= nla_nest_start(skb
, DCB_ATTR_IEEE
);
1237 goto nla_put_failure
;
1239 if (ops
->ieee_getets
) {
1240 struct ieee_ets ets
;
1241 err
= ops
->ieee_getets(netdev
, &ets
);
1243 NLA_PUT(skb
, DCB_ATTR_IEEE_ETS
, sizeof(ets
), &ets
);
1246 if (ops
->ieee_getpfc
) {
1247 struct ieee_pfc pfc
;
1248 err
= ops
->ieee_getpfc(netdev
, &pfc
);
1250 NLA_PUT(skb
, DCB_ATTR_IEEE_PFC
, sizeof(pfc
), &pfc
);
1253 app
= nla_nest_start(skb
, DCB_ATTR_IEEE_APP_TABLE
);
1255 goto nla_put_failure
;
1257 spin_lock(&dcb_lock
);
1258 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1259 if (itr
->ifindex
== netdev
->ifindex
) {
1260 err
= nla_put(skb
, DCB_ATTR_IEEE_APP
, sizeof(itr
->app
),
1263 spin_unlock(&dcb_lock
);
1264 goto nla_put_failure
;
1269 if (netdev
->dcbnl_ops
->getdcbx
)
1270 dcbx
= netdev
->dcbnl_ops
->getdcbx(netdev
);
1274 spin_unlock(&dcb_lock
);
1275 nla_nest_end(skb
, app
);
1277 /* get peer info if available */
1278 if (ops
->ieee_peer_getets
) {
1279 struct ieee_ets ets
;
1280 err
= ops
->ieee_peer_getets(netdev
, &ets
);
1282 NLA_PUT(skb
, DCB_ATTR_IEEE_PEER_ETS
, sizeof(ets
), &ets
);
1285 if (ops
->ieee_peer_getpfc
) {
1286 struct ieee_pfc pfc
;
1287 err
= ops
->ieee_peer_getpfc(netdev
, &pfc
);
1289 NLA_PUT(skb
, DCB_ATTR_IEEE_PEER_PFC
, sizeof(pfc
), &pfc
);
1292 if (ops
->peer_getappinfo
&& ops
->peer_getapptable
) {
1293 err
= dcbnl_build_peer_app(netdev
, skb
,
1294 DCB_ATTR_IEEE_PEER_APP
,
1295 DCB_ATTR_IEEE_APP_UNSPEC
,
1298 goto nla_put_failure
;
1301 nla_nest_end(skb
, ieee
);
1303 err
= nla_put_u8(skb
, DCB_ATTR_DCBX
, dcbx
);
1305 goto nla_put_failure
;
1314 static int dcbnl_cee_pg_fill(struct sk_buff
*skb
, struct net_device
*dev
,
1317 u8 pgid
, up_map
, prio
, tc_pct
;
1318 const struct dcbnl_rtnl_ops
*ops
= dev
->dcbnl_ops
;
1319 int i
= dir
? DCB_ATTR_CEE_TX_PG
: DCB_ATTR_CEE_RX_PG
;
1320 struct nlattr
*pg
= nla_nest_start(skb
, i
);
1323 goto nla_put_failure
;
1325 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
1326 struct nlattr
*tc_nest
= nla_nest_start(skb
, i
);
1329 goto nla_put_failure
;
1331 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
1332 prio
= DCB_ATTR_VALUE_UNDEFINED
;
1333 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
1334 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
1337 ops
->getpgtccfgrx(dev
, i
- DCB_PG_ATTR_TC_0
,
1338 &prio
, &pgid
, &tc_pct
, &up_map
);
1340 ops
->getpgtccfgtx(dev
, i
- DCB_PG_ATTR_TC_0
,
1341 &prio
, &pgid
, &tc_pct
, &up_map
);
1343 NLA_PUT_U8(skb
, DCB_TC_ATTR_PARAM_PGID
, pgid
);
1344 NLA_PUT_U8(skb
, DCB_TC_ATTR_PARAM_UP_MAPPING
, up_map
);
1345 NLA_PUT_U8(skb
, DCB_TC_ATTR_PARAM_STRICT_PRIO
, prio
);
1346 NLA_PUT_U8(skb
, DCB_TC_ATTR_PARAM_BW_PCT
, tc_pct
);
1347 nla_nest_end(skb
, tc_nest
);
1350 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
1351 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
1354 ops
->getpgbwgcfgrx(dev
, i
- DCB_PG_ATTR_BW_ID_0
,
1357 ops
->getpgbwgcfgtx(dev
, i
- DCB_PG_ATTR_BW_ID_0
,
1359 NLA_PUT_U8(skb
, i
, tc_pct
);
1361 nla_nest_end(skb
, pg
);
1368 static int dcbnl_cee_fill(struct sk_buff
*skb
, struct net_device
*netdev
)
1370 struct nlattr
*cee
, *app
;
1371 struct dcb_app_type
*itr
;
1372 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1373 int dcbx
, i
, err
= -EMSGSIZE
;
1376 NLA_PUT_STRING(skb
, DCB_ATTR_IFNAME
, netdev
->name
);
1378 cee
= nla_nest_start(skb
, DCB_ATTR_CEE
);
1380 goto nla_put_failure
;
1383 if (ops
->getpgtccfgtx
&& ops
->getpgbwgcfgtx
) {
1384 err
= dcbnl_cee_pg_fill(skb
, netdev
, 1);
1386 goto nla_put_failure
;
1389 if (ops
->getpgtccfgrx
&& ops
->getpgbwgcfgrx
) {
1390 err
= dcbnl_cee_pg_fill(skb
, netdev
, 0);
1392 goto nla_put_failure
;
1396 if (ops
->getpfccfg
) {
1397 struct nlattr
*pfc_nest
= nla_nest_start(skb
, DCB_ATTR_CEE_PFC
);
1400 goto nla_put_failure
;
1402 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
1403 ops
->getpfccfg(netdev
, i
- DCB_PFC_UP_ATTR_0
, &value
);
1404 NLA_PUT_U8(skb
, i
, value
);
1406 nla_nest_end(skb
, pfc_nest
);
1410 spin_lock(&dcb_lock
);
1411 app
= nla_nest_start(skb
, DCB_ATTR_CEE_APP_TABLE
);
1415 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1416 if (itr
->ifindex
== netdev
->ifindex
) {
1417 struct nlattr
*app_nest
= nla_nest_start(skb
,
1422 err
= nla_put_u8(skb
, DCB_APP_ATTR_IDTYPE
,
1427 err
= nla_put_u16(skb
, DCB_APP_ATTR_ID
,
1432 err
= nla_put_u8(skb
, DCB_APP_ATTR_PRIORITY
,
1437 nla_nest_end(skb
, app_nest
);
1440 nla_nest_end(skb
, app
);
1442 if (netdev
->dcbnl_ops
->getdcbx
)
1443 dcbx
= netdev
->dcbnl_ops
->getdcbx(netdev
);
1447 spin_unlock(&dcb_lock
);
1449 /* features flags */
1450 if (ops
->getfeatcfg
) {
1451 struct nlattr
*feat
= nla_nest_start(skb
, DCB_ATTR_CEE_FEAT
);
1453 goto nla_put_failure
;
1455 for (i
= DCB_FEATCFG_ATTR_ALL
+ 1; i
<= DCB_FEATCFG_ATTR_MAX
;
1457 if (!ops
->getfeatcfg(netdev
, i
, &value
))
1458 NLA_PUT_U8(skb
, i
, value
);
1460 nla_nest_end(skb
, feat
);
1463 /* peer info if available */
1464 if (ops
->cee_peer_getpg
) {
1466 err
= ops
->cee_peer_getpg(netdev
, &pg
);
1468 NLA_PUT(skb
, DCB_ATTR_CEE_PEER_PG
, sizeof(pg
), &pg
);
1471 if (ops
->cee_peer_getpfc
) {
1473 err
= ops
->cee_peer_getpfc(netdev
, &pfc
);
1475 NLA_PUT(skb
, DCB_ATTR_CEE_PEER_PFC
, sizeof(pfc
), &pfc
);
1478 if (ops
->peer_getappinfo
&& ops
->peer_getapptable
) {
1479 err
= dcbnl_build_peer_app(netdev
, skb
,
1480 DCB_ATTR_CEE_PEER_APP_TABLE
,
1481 DCB_ATTR_CEE_PEER_APP_INFO
,
1482 DCB_ATTR_CEE_PEER_APP
);
1484 goto nla_put_failure
;
1486 nla_nest_end(skb
, cee
);
1490 err
= nla_put_u8(skb
, DCB_ATTR_DCBX
, dcbx
);
1492 goto nla_put_failure
;
1497 spin_unlock(&dcb_lock
);
1502 static int dcbnl_notify(struct net_device
*dev
, int event
, int cmd
,
1503 u32 seq
, u32 pid
, int dcbx_ver
)
1505 struct net
*net
= dev_net(dev
);
1506 struct sk_buff
*skb
;
1507 struct nlmsghdr
*nlh
;
1509 const struct dcbnl_rtnl_ops
*ops
= dev
->dcbnl_ops
;
1515 skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1519 nlh
= nlmsg_put(skb
, pid
, 0, event
, sizeof(*dcb
), 0);
1525 dcb
= NLMSG_DATA(nlh
);
1526 dcb
->dcb_family
= AF_UNSPEC
;
1529 if (dcbx_ver
== DCB_CAP_DCBX_VER_IEEE
)
1530 err
= dcbnl_ieee_fill(skb
, dev
);
1532 err
= dcbnl_cee_fill(skb
, dev
);
1535 /* Report error to broadcast listeners */
1536 nlmsg_cancel(skb
, nlh
);
1538 rtnl_set_sk_err(net
, RTNLGRP_DCB
, err
);
1540 /* End nlmsg and notify broadcast listeners */
1541 nlmsg_end(skb
, nlh
);
1542 rtnl_notify(skb
, net
, 0, RTNLGRP_DCB
, NULL
, GFP_KERNEL
);
1548 int dcbnl_ieee_notify(struct net_device
*dev
, int event
, int cmd
,
1551 return dcbnl_notify(dev
, event
, cmd
, seq
, pid
, DCB_CAP_DCBX_VER_IEEE
);
1553 EXPORT_SYMBOL(dcbnl_ieee_notify
);
1555 int dcbnl_cee_notify(struct net_device
*dev
, int event
, int cmd
,
1558 return dcbnl_notify(dev
, event
, cmd
, seq
, pid
, DCB_CAP_DCBX_VER_CEE
);
1560 EXPORT_SYMBOL(dcbnl_cee_notify
);
1562 /* Handle IEEE 802.1Qaz SET commands. If any requested operation can not
1563 * be completed the entire msg is aborted and error value is returned.
1564 * No attempt is made to reconcile the case where only part of the
1565 * cmd can be completed.
1567 static int dcbnl_ieee_set(struct net_device
*netdev
, struct nlattr
**tb
,
1568 u32 pid
, u32 seq
, u16 flags
)
1570 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1571 struct nlattr
*ieee
[DCB_ATTR_IEEE_MAX
+ 1];
1572 int err
= -EOPNOTSUPP
;
1577 if (!tb
[DCB_ATTR_IEEE
])
1580 err
= nla_parse_nested(ieee
, DCB_ATTR_IEEE_MAX
,
1581 tb
[DCB_ATTR_IEEE
], dcbnl_ieee_policy
);
1585 if (ieee
[DCB_ATTR_IEEE_ETS
] && ops
->ieee_setets
) {
1586 struct ieee_ets
*ets
= nla_data(ieee
[DCB_ATTR_IEEE_ETS
]);
1587 err
= ops
->ieee_setets(netdev
, ets
);
1592 if (ieee
[DCB_ATTR_IEEE_PFC
] && ops
->ieee_setpfc
) {
1593 struct ieee_pfc
*pfc
= nla_data(ieee
[DCB_ATTR_IEEE_PFC
]);
1594 err
= ops
->ieee_setpfc(netdev
, pfc
);
1599 if (ieee
[DCB_ATTR_IEEE_APP_TABLE
]) {
1600 struct nlattr
*attr
;
1603 nla_for_each_nested(attr
, ieee
[DCB_ATTR_IEEE_APP_TABLE
], rem
) {
1604 struct dcb_app
*app_data
;
1605 if (nla_type(attr
) != DCB_ATTR_IEEE_APP
)
1607 app_data
= nla_data(attr
);
1608 if (ops
->ieee_setapp
)
1609 err
= ops
->ieee_setapp(netdev
, app_data
);
1611 err
= dcb_ieee_setapp(netdev
, app_data
);
1618 dcbnl_reply(err
, RTM_SETDCB
, DCB_CMD_IEEE_SET
, DCB_ATTR_IEEE
,
1620 dcbnl_ieee_notify(netdev
, RTM_SETDCB
, DCB_CMD_IEEE_SET
, seq
, 0);
1624 static int dcbnl_ieee_get(struct net_device
*netdev
, struct nlattr
**tb
,
1625 u32 pid
, u32 seq
, u16 flags
)
1627 struct net
*net
= dev_net(netdev
);
1628 struct sk_buff
*skb
;
1629 struct nlmsghdr
*nlh
;
1631 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1637 skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1641 nlh
= nlmsg_put(skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
1647 dcb
= NLMSG_DATA(nlh
);
1648 dcb
->dcb_family
= AF_UNSPEC
;
1649 dcb
->cmd
= DCB_CMD_IEEE_GET
;
1651 err
= dcbnl_ieee_fill(skb
, netdev
);
1654 nlmsg_cancel(skb
, nlh
);
1657 nlmsg_end(skb
, nlh
);
1658 err
= rtnl_unicast(skb
, net
, pid
);
1664 static int dcbnl_ieee_del(struct net_device
*netdev
, struct nlattr
**tb
,
1665 u32 pid
, u32 seq
, u16 flags
)
1667 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1668 struct nlattr
*ieee
[DCB_ATTR_IEEE_MAX
+ 1];
1669 int err
= -EOPNOTSUPP
;
1674 if (!tb
[DCB_ATTR_IEEE
])
1677 err
= nla_parse_nested(ieee
, DCB_ATTR_IEEE_MAX
,
1678 tb
[DCB_ATTR_IEEE
], dcbnl_ieee_policy
);
1682 if (ieee
[DCB_ATTR_IEEE_APP_TABLE
]) {
1683 struct nlattr
*attr
;
1686 nla_for_each_nested(attr
, ieee
[DCB_ATTR_IEEE_APP_TABLE
], rem
) {
1687 struct dcb_app
*app_data
;
1689 if (nla_type(attr
) != DCB_ATTR_IEEE_APP
)
1691 app_data
= nla_data(attr
);
1692 if (ops
->ieee_delapp
)
1693 err
= ops
->ieee_delapp(netdev
, app_data
);
1695 err
= dcb_ieee_delapp(netdev
, app_data
);
1702 dcbnl_reply(err
, RTM_SETDCB
, DCB_CMD_IEEE_DEL
, DCB_ATTR_IEEE
,
1704 dcbnl_ieee_notify(netdev
, RTM_SETDCB
, DCB_CMD_IEEE_DEL
, seq
, 0);
1709 /* DCBX configuration */
1710 static int dcbnl_getdcbx(struct net_device
*netdev
, struct nlattr
**tb
,
1711 u32 pid
, u32 seq
, u16 flags
)
1715 if (!netdev
->dcbnl_ops
->getdcbx
)
1718 ret
= dcbnl_reply(netdev
->dcbnl_ops
->getdcbx(netdev
), RTM_GETDCB
,
1719 DCB_CMD_GDCBX
, DCB_ATTR_DCBX
, pid
, seq
, flags
);
1724 static int dcbnl_setdcbx(struct net_device
*netdev
, struct nlattr
**tb
,
1725 u32 pid
, u32 seq
, u16 flags
)
1730 if (!netdev
->dcbnl_ops
->setdcbx
)
1733 if (!tb
[DCB_ATTR_DCBX
])
1736 value
= nla_get_u8(tb
[DCB_ATTR_DCBX
]);
1738 ret
= dcbnl_reply(netdev
->dcbnl_ops
->setdcbx(netdev
, value
),
1739 RTM_SETDCB
, DCB_CMD_SDCBX
, DCB_ATTR_DCBX
,
1745 static int dcbnl_getfeatcfg(struct net_device
*netdev
, struct nlattr
**tb
,
1746 u32 pid
, u32 seq
, u16 flags
)
1748 struct sk_buff
*dcbnl_skb
;
1749 struct nlmsghdr
*nlh
;
1751 struct nlattr
*data
[DCB_FEATCFG_ATTR_MAX
+ 1], *nest
;
1756 if (!netdev
->dcbnl_ops
->getfeatcfg
)
1759 if (!tb
[DCB_ATTR_FEATCFG
])
1762 ret
= nla_parse_nested(data
, DCB_FEATCFG_ATTR_MAX
, tb
[DCB_ATTR_FEATCFG
],
1763 dcbnl_featcfg_nest
);
1767 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1773 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
1775 dcb
= NLMSG_DATA(nlh
);
1776 dcb
->dcb_family
= AF_UNSPEC
;
1777 dcb
->cmd
= DCB_CMD_GFEATCFG
;
1779 nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_FEATCFG
);
1782 goto nla_put_failure
;
1785 if (data
[DCB_FEATCFG_ATTR_ALL
])
1788 for (i
= DCB_FEATCFG_ATTR_ALL
+1; i
<= DCB_FEATCFG_ATTR_MAX
; i
++) {
1789 if (!getall
&& !data
[i
])
1792 ret
= netdev
->dcbnl_ops
->getfeatcfg(netdev
, i
, &value
);
1794 ret
= nla_put_u8(dcbnl_skb
, i
, value
);
1797 nla_nest_cancel(dcbnl_skb
, nest
);
1798 goto nla_put_failure
;
1801 nla_nest_end(dcbnl_skb
, nest
);
1803 nlmsg_end(dcbnl_skb
, nlh
);
1805 return rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
1807 nlmsg_cancel(dcbnl_skb
, nlh
);
1809 kfree_skb(dcbnl_skb
);
1814 static int dcbnl_setfeatcfg(struct net_device
*netdev
, struct nlattr
**tb
,
1815 u32 pid
, u32 seq
, u16 flags
)
1817 struct nlattr
*data
[DCB_FEATCFG_ATTR_MAX
+ 1];
1821 if (!netdev
->dcbnl_ops
->setfeatcfg
)
1824 if (!tb
[DCB_ATTR_FEATCFG
])
1827 ret
= nla_parse_nested(data
, DCB_FEATCFG_ATTR_MAX
, tb
[DCB_ATTR_FEATCFG
],
1828 dcbnl_featcfg_nest
);
1833 for (i
= DCB_FEATCFG_ATTR_ALL
+1; i
<= DCB_FEATCFG_ATTR_MAX
; i
++) {
1834 if (data
[i
] == NULL
)
1837 value
= nla_get_u8(data
[i
]);
1839 ret
= netdev
->dcbnl_ops
->setfeatcfg(netdev
, i
, value
);
1845 dcbnl_reply(ret
, RTM_SETDCB
, DCB_CMD_SFEATCFG
, DCB_ATTR_FEATCFG
,
1851 /* Handle CEE DCBX GET commands. */
1852 static int dcbnl_cee_get(struct net_device
*netdev
, struct nlattr
**tb
,
1853 u32 pid
, u32 seq
, u16 flags
)
1855 struct net
*net
= dev_net(netdev
);
1856 struct sk_buff
*skb
;
1857 struct nlmsghdr
*nlh
;
1859 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1865 skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1869 nlh
= nlmsg_put(skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
1875 dcb
= NLMSG_DATA(nlh
);
1876 dcb
->dcb_family
= AF_UNSPEC
;
1877 dcb
->cmd
= DCB_CMD_CEE_GET
;
1879 err
= dcbnl_cee_fill(skb
, netdev
);
1882 nlmsg_cancel(skb
, nlh
);
1885 nlmsg_end(skb
, nlh
);
1886 err
= rtnl_unicast(skb
, net
, pid
);
1891 static int dcb_doit(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
1893 struct net
*net
= sock_net(skb
->sk
);
1894 struct net_device
*netdev
;
1895 struct dcbmsg
*dcb
= (struct dcbmsg
*)NLMSG_DATA(nlh
);
1896 struct nlattr
*tb
[DCB_ATTR_MAX
+ 1];
1897 u32 pid
= skb
? NETLINK_CB(skb
).pid
: 0;
1900 if (!net_eq(net
, &init_net
))
1903 ret
= nlmsg_parse(nlh
, sizeof(*dcb
), tb
, DCB_ATTR_MAX
,
1908 if (!tb
[DCB_ATTR_IFNAME
])
1911 netdev
= dev_get_by_name(&init_net
, nla_data(tb
[DCB_ATTR_IFNAME
]));
1915 if (!netdev
->dcbnl_ops
)
1919 case DCB_CMD_GSTATE
:
1920 ret
= dcbnl_getstate(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1923 case DCB_CMD_PFC_GCFG
:
1924 ret
= dcbnl_getpfccfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1927 case DCB_CMD_GPERM_HWADDR
:
1928 ret
= dcbnl_getperm_hwaddr(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1931 case DCB_CMD_PGTX_GCFG
:
1932 ret
= dcbnl_pgtx_getcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1935 case DCB_CMD_PGRX_GCFG
:
1936 ret
= dcbnl_pgrx_getcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1939 case DCB_CMD_BCN_GCFG
:
1940 ret
= dcbnl_bcn_getcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1943 case DCB_CMD_SSTATE
:
1944 ret
= dcbnl_setstate(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1947 case DCB_CMD_PFC_SCFG
:
1948 ret
= dcbnl_setpfccfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1952 case DCB_CMD_SET_ALL
:
1953 ret
= dcbnl_setall(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1956 case DCB_CMD_PGTX_SCFG
:
1957 ret
= dcbnl_pgtx_setcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1960 case DCB_CMD_PGRX_SCFG
:
1961 ret
= dcbnl_pgrx_setcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1965 ret
= dcbnl_getcap(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1968 case DCB_CMD_GNUMTCS
:
1969 ret
= dcbnl_getnumtcs(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1972 case DCB_CMD_SNUMTCS
:
1973 ret
= dcbnl_setnumtcs(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1976 case DCB_CMD_PFC_GSTATE
:
1977 ret
= dcbnl_getpfcstate(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1980 case DCB_CMD_PFC_SSTATE
:
1981 ret
= dcbnl_setpfcstate(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1984 case DCB_CMD_BCN_SCFG
:
1985 ret
= dcbnl_bcn_setcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1989 ret
= dcbnl_getapp(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1993 ret
= dcbnl_setapp(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1996 case DCB_CMD_IEEE_SET
:
1997 ret
= dcbnl_ieee_set(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2000 case DCB_CMD_IEEE_GET
:
2001 ret
= dcbnl_ieee_get(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2004 case DCB_CMD_IEEE_DEL
:
2005 ret
= dcbnl_ieee_del(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2009 ret
= dcbnl_getdcbx(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2013 ret
= dcbnl_setdcbx(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2016 case DCB_CMD_GFEATCFG
:
2017 ret
= dcbnl_getfeatcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2020 case DCB_CMD_SFEATCFG
:
2021 ret
= dcbnl_setfeatcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2024 case DCB_CMD_CEE_GET
:
2025 ret
= dcbnl_cee_get(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
2039 * dcb_getapp - retrieve the DCBX application user priority
2041 * On success returns a non-zero 802.1p user priority bitmap
2042 * otherwise returns 0 as the invalid user priority bitmap to
2043 * indicate an error.
2045 u8
dcb_getapp(struct net_device
*dev
, struct dcb_app
*app
)
2047 struct dcb_app_type
*itr
;
2050 spin_lock(&dcb_lock
);
2051 list_for_each_entry(itr
, &dcb_app_list
, list
) {
2052 if (itr
->app
.selector
== app
->selector
&&
2053 itr
->app
.protocol
== app
->protocol
&&
2054 itr
->ifindex
== dev
->ifindex
) {
2055 prio
= itr
->app
.priority
;
2059 spin_unlock(&dcb_lock
);
2063 EXPORT_SYMBOL(dcb_getapp
);
2066 * dcb_setapp - add CEE dcb application data to app list
2068 * Priority 0 is an invalid priority in CEE spec. This routine
2069 * removes applications from the app list if the priority is
2072 int dcb_setapp(struct net_device
*dev
, struct dcb_app
*new)
2074 struct dcb_app_type
*itr
;
2075 struct dcb_app_type event
;
2077 event
.ifindex
= dev
->ifindex
;
2078 memcpy(&event
.app
, new, sizeof(event
.app
));
2079 if (dev
->dcbnl_ops
->getdcbx
)
2080 event
.dcbx
= dev
->dcbnl_ops
->getdcbx(dev
);
2082 spin_lock(&dcb_lock
);
2083 /* Search for existing match and replace */
2084 list_for_each_entry(itr
, &dcb_app_list
, list
) {
2085 if (itr
->app
.selector
== new->selector
&&
2086 itr
->app
.protocol
== new->protocol
&&
2087 itr
->ifindex
== dev
->ifindex
) {
2089 itr
->app
.priority
= new->priority
;
2091 list_del(&itr
->list
);
2097 /* App type does not exist add new application type */
2098 if (new->priority
) {
2099 struct dcb_app_type
*entry
;
2100 entry
= kmalloc(sizeof(struct dcb_app_type
), GFP_ATOMIC
);
2102 spin_unlock(&dcb_lock
);
2106 memcpy(&entry
->app
, new, sizeof(*new));
2107 entry
->ifindex
= dev
->ifindex
;
2108 list_add(&entry
->list
, &dcb_app_list
);
2111 spin_unlock(&dcb_lock
);
2112 call_dcbevent_notifiers(DCB_APP_EVENT
, &event
);
2115 EXPORT_SYMBOL(dcb_setapp
);
2118 * dcb_ieee_getapp_mask - retrieve the IEEE DCB application priority
2120 * Helper routine which on success returns a non-zero 802.1Qaz user
2121 * priority bitmap otherwise returns 0 to indicate the dcb_app was
2122 * not found in APP list.
2124 u8
dcb_ieee_getapp_mask(struct net_device
*dev
, struct dcb_app
*app
)
2126 struct dcb_app_type
*itr
;
2129 spin_lock(&dcb_lock
);
2130 list_for_each_entry(itr
, &dcb_app_list
, list
) {
2131 if (itr
->app
.selector
== app
->selector
&&
2132 itr
->app
.protocol
== app
->protocol
&&
2133 itr
->ifindex
== dev
->ifindex
) {
2134 prio
|= 1 << itr
->app
.priority
;
2137 spin_unlock(&dcb_lock
);
2141 EXPORT_SYMBOL(dcb_ieee_getapp_mask
);
2144 * dcb_ieee_setapp - add IEEE dcb application data to app list
2146 * This adds Application data to the list. Multiple application
2147 * entries may exists for the same selector and protocol as long
2148 * as the priorities are different.
2150 int dcb_ieee_setapp(struct net_device
*dev
, struct dcb_app
*new)
2152 struct dcb_app_type
*itr
, *entry
;
2153 struct dcb_app_type event
;
2156 event
.ifindex
= dev
->ifindex
;
2157 memcpy(&event
.app
, new, sizeof(event
.app
));
2158 if (dev
->dcbnl_ops
->getdcbx
)
2159 event
.dcbx
= dev
->dcbnl_ops
->getdcbx(dev
);
2161 spin_lock(&dcb_lock
);
2162 /* Search for existing match and abort if found */
2163 list_for_each_entry(itr
, &dcb_app_list
, list
) {
2164 if (itr
->app
.selector
== new->selector
&&
2165 itr
->app
.protocol
== new->protocol
&&
2166 itr
->app
.priority
== new->priority
&&
2167 itr
->ifindex
== dev
->ifindex
) {
2173 /* App entry does not exist add new entry */
2174 entry
= kmalloc(sizeof(struct dcb_app_type
), GFP_ATOMIC
);
2180 memcpy(&entry
->app
, new, sizeof(*new));
2181 entry
->ifindex
= dev
->ifindex
;
2182 list_add(&entry
->list
, &dcb_app_list
);
2184 spin_unlock(&dcb_lock
);
2186 call_dcbevent_notifiers(DCB_APP_EVENT
, &event
);
2189 EXPORT_SYMBOL(dcb_ieee_setapp
);
2192 * dcb_ieee_delapp - delete IEEE dcb application data from list
2194 * This removes a matching APP data from the APP list
2196 int dcb_ieee_delapp(struct net_device
*dev
, struct dcb_app
*del
)
2198 struct dcb_app_type
*itr
;
2199 struct dcb_app_type event
;
2202 event
.ifindex
= dev
->ifindex
;
2203 memcpy(&event
.app
, del
, sizeof(event
.app
));
2204 if (dev
->dcbnl_ops
->getdcbx
)
2205 event
.dcbx
= dev
->dcbnl_ops
->getdcbx(dev
);
2207 spin_lock(&dcb_lock
);
2208 /* Search for existing match and remove it. */
2209 list_for_each_entry(itr
, &dcb_app_list
, list
) {
2210 if (itr
->app
.selector
== del
->selector
&&
2211 itr
->app
.protocol
== del
->protocol
&&
2212 itr
->app
.priority
== del
->priority
&&
2213 itr
->ifindex
== dev
->ifindex
) {
2214 list_del(&itr
->list
);
2222 spin_unlock(&dcb_lock
);
2224 call_dcbevent_notifiers(DCB_APP_EVENT
, &event
);
2227 EXPORT_SYMBOL(dcb_ieee_delapp
);
2229 static void dcb_flushapp(void)
2231 struct dcb_app_type
*app
;
2232 struct dcb_app_type
*tmp
;
2234 spin_lock(&dcb_lock
);
2235 list_for_each_entry_safe(app
, tmp
, &dcb_app_list
, list
) {
2236 list_del(&app
->list
);
2239 spin_unlock(&dcb_lock
);
2242 static int __init
dcbnl_init(void)
2244 INIT_LIST_HEAD(&dcb_app_list
);
2246 rtnl_register(PF_UNSPEC
, RTM_GETDCB
, dcb_doit
, NULL
, NULL
);
2247 rtnl_register(PF_UNSPEC
, RTM_SETDCB
, dcb_doit
, NULL
, NULL
);
2251 module_init(dcbnl_init
);
2253 static void __exit
dcbnl_exit(void)
2255 rtnl_unregister(PF_UNSPEC
, RTM_GETDCB
);
2256 rtnl_unregister(PF_UNSPEC
, RTM_SETDCB
);
2259 module_exit(dcbnl_exit
);