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 static struct sk_buff
*dcbnl_newmsg(int type
, u8 cmd
, u32 port
, u32 seq
,
200 u32 flags
, struct nlmsghdr
**nlhp
)
204 struct nlmsghdr
*nlh
;
206 skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
210 nlh
= nlmsg_put(skb
, port
, seq
, type
, sizeof(*dcb
), flags
);
212 /* header should always fit, allocation must be buggy */
216 dcb
= nlmsg_data(nlh
);
217 dcb
->dcb_family
= AF_UNSPEC
;
227 static int dcbnl_getstate(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
228 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
230 /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
231 if (!netdev
->dcbnl_ops
->getstate
)
234 return nla_put_u8(skb
, DCB_ATTR_STATE
,
235 netdev
->dcbnl_ops
->getstate(netdev
));
238 static int dcbnl_getpfccfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
239 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
241 struct nlattr
*data
[DCB_PFC_UP_ATTR_MAX
+ 1], *nest
;
247 if (!tb
[DCB_ATTR_PFC_CFG
])
250 if (!netdev
->dcbnl_ops
->getpfccfg
)
253 ret
= nla_parse_nested(data
, DCB_PFC_UP_ATTR_MAX
,
254 tb
[DCB_ATTR_PFC_CFG
],
259 nest
= nla_nest_start(skb
, DCB_ATTR_PFC_CFG
);
263 if (data
[DCB_PFC_UP_ATTR_ALL
])
266 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
267 if (!getall
&& !data
[i
])
270 netdev
->dcbnl_ops
->getpfccfg(netdev
, i
- DCB_PFC_UP_ATTR_0
,
272 ret
= nla_put_u8(skb
, i
, value
);
274 nla_nest_cancel(skb
, nest
);
278 nla_nest_end(skb
, nest
);
283 static int dcbnl_getperm_hwaddr(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
284 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
286 u8 perm_addr
[MAX_ADDR_LEN
];
288 if (!netdev
->dcbnl_ops
->getpermhwaddr
)
291 netdev
->dcbnl_ops
->getpermhwaddr(netdev
, perm_addr
);
293 return nla_put(skb
, DCB_ATTR_PERM_HWADDR
, sizeof(perm_addr
), perm_addr
);
296 static int dcbnl_getcap(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
297 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
299 struct nlattr
*data
[DCB_CAP_ATTR_MAX
+ 1], *nest
;
305 if (!tb
[DCB_ATTR_CAP
])
308 if (!netdev
->dcbnl_ops
->getcap
)
311 ret
= nla_parse_nested(data
, DCB_CAP_ATTR_MAX
, tb
[DCB_ATTR_CAP
],
316 nest
= nla_nest_start(skb
, DCB_ATTR_CAP
);
320 if (data
[DCB_CAP_ATTR_ALL
])
323 for (i
= DCB_CAP_ATTR_ALL
+1; i
<= DCB_CAP_ATTR_MAX
; i
++) {
324 if (!getall
&& !data
[i
])
327 if (!netdev
->dcbnl_ops
->getcap(netdev
, i
, &value
)) {
328 ret
= nla_put_u8(skb
, i
, value
);
330 nla_nest_cancel(skb
, nest
);
335 nla_nest_end(skb
, nest
);
340 static int dcbnl_getnumtcs(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
341 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
343 struct nlattr
*data
[DCB_NUMTCS_ATTR_MAX
+ 1], *nest
;
349 if (!tb
[DCB_ATTR_NUMTCS
])
352 if (!netdev
->dcbnl_ops
->getnumtcs
)
355 ret
= nla_parse_nested(data
, DCB_NUMTCS_ATTR_MAX
, tb
[DCB_ATTR_NUMTCS
],
360 nest
= nla_nest_start(skb
, DCB_ATTR_NUMTCS
);
364 if (data
[DCB_NUMTCS_ATTR_ALL
])
367 for (i
= DCB_NUMTCS_ATTR_ALL
+1; i
<= DCB_NUMTCS_ATTR_MAX
; i
++) {
368 if (!getall
&& !data
[i
])
371 ret
= netdev
->dcbnl_ops
->getnumtcs(netdev
, i
, &value
);
373 ret
= nla_put_u8(skb
, i
, value
);
375 nla_nest_cancel(skb
, nest
);
381 nla_nest_end(skb
, nest
);
386 static int dcbnl_setnumtcs(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
387 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
389 struct nlattr
*data
[DCB_NUMTCS_ATTR_MAX
+ 1];
394 if (!tb
[DCB_ATTR_NUMTCS
])
397 if (!netdev
->dcbnl_ops
->setnumtcs
)
400 ret
= nla_parse_nested(data
, DCB_NUMTCS_ATTR_MAX
, tb
[DCB_ATTR_NUMTCS
],
405 for (i
= DCB_NUMTCS_ATTR_ALL
+1; i
<= DCB_NUMTCS_ATTR_MAX
; i
++) {
409 value
= nla_get_u8(data
[i
]);
411 ret
= netdev
->dcbnl_ops
->setnumtcs(netdev
, i
, value
);
416 return nla_put_u8(skb
, DCB_ATTR_NUMTCS
, !!ret
);
419 static int dcbnl_getpfcstate(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
420 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
422 if (!netdev
->dcbnl_ops
->getpfcstate
)
425 return nla_put_u8(skb
, DCB_ATTR_PFC_STATE
,
426 netdev
->dcbnl_ops
->getpfcstate(netdev
));
429 static int dcbnl_setpfcstate(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
430 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
434 if (!tb
[DCB_ATTR_PFC_STATE
])
437 if (!netdev
->dcbnl_ops
->setpfcstate
)
440 value
= nla_get_u8(tb
[DCB_ATTR_PFC_STATE
]);
442 netdev
->dcbnl_ops
->setpfcstate(netdev
, value
);
444 return nla_put_u8(skb
, DCB_ATTR_PFC_STATE
, 0);
447 static int dcbnl_getapp(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
448 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
450 struct nlattr
*app_nest
;
451 struct nlattr
*app_tb
[DCB_APP_ATTR_MAX
+ 1];
456 if (!tb
[DCB_ATTR_APP
])
459 ret
= nla_parse_nested(app_tb
, DCB_APP_ATTR_MAX
, tb
[DCB_ATTR_APP
],
464 /* all must be non-null */
465 if ((!app_tb
[DCB_APP_ATTR_IDTYPE
]) ||
466 (!app_tb
[DCB_APP_ATTR_ID
]))
469 /* either by eth type or by socket number */
470 idtype
= nla_get_u8(app_tb
[DCB_APP_ATTR_IDTYPE
]);
471 if ((idtype
!= DCB_APP_IDTYPE_ETHTYPE
) &&
472 (idtype
!= DCB_APP_IDTYPE_PORTNUM
))
475 id
= nla_get_u16(app_tb
[DCB_APP_ATTR_ID
]);
477 if (netdev
->dcbnl_ops
->getapp
) {
478 up
= netdev
->dcbnl_ops
->getapp(netdev
, idtype
, id
);
480 struct dcb_app app
= {
484 up
= dcb_getapp(netdev
, &app
);
487 app_nest
= nla_nest_start(skb
, DCB_ATTR_APP
);
491 ret
= nla_put_u8(skb
, DCB_APP_ATTR_IDTYPE
, idtype
);
495 ret
= nla_put_u16(skb
, DCB_APP_ATTR_ID
, id
);
499 ret
= nla_put_u8(skb
, DCB_APP_ATTR_PRIORITY
, up
);
503 nla_nest_end(skb
, app_nest
);
508 nla_nest_cancel(skb
, app_nest
);
512 static int dcbnl_setapp(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
513 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
518 struct nlattr
*app_tb
[DCB_APP_ATTR_MAX
+ 1];
520 if (!tb
[DCB_ATTR_APP
])
523 ret
= nla_parse_nested(app_tb
, DCB_APP_ATTR_MAX
, tb
[DCB_ATTR_APP
],
528 /* all must be non-null */
529 if ((!app_tb
[DCB_APP_ATTR_IDTYPE
]) ||
530 (!app_tb
[DCB_APP_ATTR_ID
]) ||
531 (!app_tb
[DCB_APP_ATTR_PRIORITY
]))
534 /* either by eth type or by socket number */
535 idtype
= nla_get_u8(app_tb
[DCB_APP_ATTR_IDTYPE
]);
536 if ((idtype
!= DCB_APP_IDTYPE_ETHTYPE
) &&
537 (idtype
!= DCB_APP_IDTYPE_PORTNUM
))
540 id
= nla_get_u16(app_tb
[DCB_APP_ATTR_ID
]);
541 up
= nla_get_u8(app_tb
[DCB_APP_ATTR_PRIORITY
]);
543 if (netdev
->dcbnl_ops
->setapp
) {
544 ret
= netdev
->dcbnl_ops
->setapp(netdev
, idtype
, id
, up
);
547 app
.selector
= idtype
;
550 ret
= dcb_setapp(netdev
, &app
);
553 ret
= nla_put_u8(skb
, DCB_ATTR_APP
, ret
);
554 dcbnl_cee_notify(netdev
, RTM_SETDCB
, DCB_CMD_SAPP
, seq
, 0);
559 static int __dcbnl_pg_getcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
560 struct nlattr
**tb
, struct sk_buff
*skb
, int dir
)
562 struct nlattr
*pg_nest
, *param_nest
, *data
;
563 struct nlattr
*pg_tb
[DCB_PG_ATTR_MAX
+ 1];
564 struct nlattr
*param_tb
[DCB_TC_ATTR_PARAM_MAX
+ 1];
565 u8 prio
, pgid
, tc_pct
, up_map
;
570 if (!tb
[DCB_ATTR_PG_CFG
])
573 if (!netdev
->dcbnl_ops
->getpgtccfgtx
||
574 !netdev
->dcbnl_ops
->getpgtccfgrx
||
575 !netdev
->dcbnl_ops
->getpgbwgcfgtx
||
576 !netdev
->dcbnl_ops
->getpgbwgcfgrx
)
579 ret
= nla_parse_nested(pg_tb
, DCB_PG_ATTR_MAX
,
580 tb
[DCB_ATTR_PG_CFG
], dcbnl_pg_nest
);
584 pg_nest
= nla_nest_start(skb
, DCB_ATTR_PG_CFG
);
588 if (pg_tb
[DCB_PG_ATTR_TC_ALL
])
591 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
592 if (!getall
&& !pg_tb
[i
])
595 if (pg_tb
[DCB_PG_ATTR_TC_ALL
])
596 data
= pg_tb
[DCB_PG_ATTR_TC_ALL
];
599 ret
= nla_parse_nested(param_tb
, DCB_TC_ATTR_PARAM_MAX
,
600 data
, dcbnl_tc_param_nest
);
604 param_nest
= nla_nest_start(skb
, i
);
608 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
609 prio
= DCB_ATTR_VALUE_UNDEFINED
;
610 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
611 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
615 netdev
->dcbnl_ops
->getpgtccfgrx(netdev
,
616 i
- DCB_PG_ATTR_TC_0
, &prio
,
617 &pgid
, &tc_pct
, &up_map
);
620 netdev
->dcbnl_ops
->getpgtccfgtx(netdev
,
621 i
- DCB_PG_ATTR_TC_0
, &prio
,
622 &pgid
, &tc_pct
, &up_map
);
625 if (param_tb
[DCB_TC_ATTR_PARAM_PGID
] ||
626 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
627 ret
= nla_put_u8(skb
,
628 DCB_TC_ATTR_PARAM_PGID
, pgid
);
632 if (param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
] ||
633 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
634 ret
= nla_put_u8(skb
,
635 DCB_TC_ATTR_PARAM_UP_MAPPING
, up_map
);
639 if (param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
] ||
640 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
641 ret
= nla_put_u8(skb
,
642 DCB_TC_ATTR_PARAM_STRICT_PRIO
, prio
);
646 if (param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
] ||
647 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
648 ret
= nla_put_u8(skb
, DCB_TC_ATTR_PARAM_BW_PCT
,
653 nla_nest_end(skb
, param_nest
);
656 if (pg_tb
[DCB_PG_ATTR_BW_ID_ALL
])
661 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
662 if (!getall
&& !pg_tb
[i
])
665 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
669 netdev
->dcbnl_ops
->getpgbwgcfgrx(netdev
,
670 i
- DCB_PG_ATTR_BW_ID_0
, &tc_pct
);
673 netdev
->dcbnl_ops
->getpgbwgcfgtx(netdev
,
674 i
- DCB_PG_ATTR_BW_ID_0
, &tc_pct
);
676 ret
= nla_put_u8(skb
, i
, tc_pct
);
681 nla_nest_end(skb
, pg_nest
);
686 nla_nest_cancel(skb
, param_nest
);
688 nla_nest_cancel(skb
, pg_nest
);
693 static int dcbnl_pgtx_getcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
694 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
696 return __dcbnl_pg_getcfg(netdev
, nlh
, tb
, skb
, 0);
699 static int dcbnl_pgrx_getcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
700 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
702 return __dcbnl_pg_getcfg(netdev
, nlh
, tb
, skb
, 1);
705 static int dcbnl_setstate(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
706 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
710 if (!tb
[DCB_ATTR_STATE
])
713 if (!netdev
->dcbnl_ops
->setstate
)
716 value
= nla_get_u8(tb
[DCB_ATTR_STATE
]);
718 return nla_put_u8(skb
, DCB_ATTR_STATE
,
719 netdev
->dcbnl_ops
->setstate(netdev
, value
));
722 static int dcbnl_setpfccfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
723 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
725 struct nlattr
*data
[DCB_PFC_UP_ATTR_MAX
+ 1];
730 if (!tb
[DCB_ATTR_PFC_CFG
])
733 if (!netdev
->dcbnl_ops
->setpfccfg
)
736 ret
= nla_parse_nested(data
, DCB_PFC_UP_ATTR_MAX
,
737 tb
[DCB_ATTR_PFC_CFG
],
742 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
745 value
= nla_get_u8(data
[i
]);
746 netdev
->dcbnl_ops
->setpfccfg(netdev
,
747 data
[i
]->nla_type
- DCB_PFC_UP_ATTR_0
, value
);
750 return nla_put_u8(skb
, DCB_ATTR_PFC_CFG
, 0);
753 static int dcbnl_setall(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
754 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
758 if (!tb
[DCB_ATTR_SET_ALL
])
761 if (!netdev
->dcbnl_ops
->setall
)
764 ret
= nla_put_u8(skb
, DCB_ATTR_SET_ALL
,
765 netdev
->dcbnl_ops
->setall(netdev
));
766 dcbnl_cee_notify(netdev
, RTM_SETDCB
, DCB_CMD_SET_ALL
, seq
, 0);
771 static int __dcbnl_pg_setcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
772 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
,
775 struct nlattr
*pg_tb
[DCB_PG_ATTR_MAX
+ 1];
776 struct nlattr
*param_tb
[DCB_TC_ATTR_PARAM_MAX
+ 1];
784 if (!tb
[DCB_ATTR_PG_CFG
])
787 if (!netdev
->dcbnl_ops
->setpgtccfgtx
||
788 !netdev
->dcbnl_ops
->setpgtccfgrx
||
789 !netdev
->dcbnl_ops
->setpgbwgcfgtx
||
790 !netdev
->dcbnl_ops
->setpgbwgcfgrx
)
793 ret
= nla_parse_nested(pg_tb
, DCB_PG_ATTR_MAX
,
794 tb
[DCB_ATTR_PG_CFG
], dcbnl_pg_nest
);
798 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
802 ret
= nla_parse_nested(param_tb
, DCB_TC_ATTR_PARAM_MAX
,
803 pg_tb
[i
], dcbnl_tc_param_nest
);
807 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
808 prio
= DCB_ATTR_VALUE_UNDEFINED
;
809 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
810 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
812 if (param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
])
814 nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
]);
816 if (param_tb
[DCB_TC_ATTR_PARAM_PGID
])
817 pgid
= nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_PGID
]);
819 if (param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
])
820 tc_pct
= nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
]);
822 if (param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
])
824 nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
]);
826 /* dir: Tx = 0, Rx = 1 */
829 netdev
->dcbnl_ops
->setpgtccfgrx(netdev
,
830 i
- DCB_PG_ATTR_TC_0
,
831 prio
, pgid
, tc_pct
, up_map
);
834 netdev
->dcbnl_ops
->setpgtccfgtx(netdev
,
835 i
- DCB_PG_ATTR_TC_0
,
836 prio
, pgid
, tc_pct
, up_map
);
840 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
844 tc_pct
= nla_get_u8(pg_tb
[i
]);
846 /* dir: Tx = 0, Rx = 1 */
849 netdev
->dcbnl_ops
->setpgbwgcfgrx(netdev
,
850 i
- DCB_PG_ATTR_BW_ID_0
, tc_pct
);
853 netdev
->dcbnl_ops
->setpgbwgcfgtx(netdev
,
854 i
- DCB_PG_ATTR_BW_ID_0
, tc_pct
);
858 return nla_put_u8(skb
,
859 (dir
? DCB_CMD_PGRX_SCFG
: DCB_CMD_PGTX_SCFG
), 0);
862 static int dcbnl_pgtx_setcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
863 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
865 return __dcbnl_pg_setcfg(netdev
, nlh
, seq
, tb
, skb
, 0);
868 static int dcbnl_pgrx_setcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
869 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
871 return __dcbnl_pg_setcfg(netdev
, nlh
, seq
, tb
, skb
, 1);
874 static int dcbnl_bcn_getcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
875 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
877 struct nlattr
*bcn_nest
;
878 struct nlattr
*bcn_tb
[DCB_BCN_ATTR_MAX
+ 1];
885 if (!tb
[DCB_ATTR_BCN
])
888 if (!netdev
->dcbnl_ops
->getbcnrp
||
889 !netdev
->dcbnl_ops
->getbcncfg
)
892 ret
= nla_parse_nested(bcn_tb
, DCB_BCN_ATTR_MAX
,
893 tb
[DCB_ATTR_BCN
], dcbnl_bcn_nest
);
897 bcn_nest
= nla_nest_start(skb
, DCB_ATTR_BCN
);
901 if (bcn_tb
[DCB_BCN_ATTR_ALL
])
904 for (i
= DCB_BCN_ATTR_RP_0
; i
<= DCB_BCN_ATTR_RP_7
; i
++) {
905 if (!getall
&& !bcn_tb
[i
])
908 netdev
->dcbnl_ops
->getbcnrp(netdev
, i
- DCB_BCN_ATTR_RP_0
,
910 ret
= nla_put_u8(skb
, i
, value_byte
);
915 for (i
= DCB_BCN_ATTR_BCNA_0
; i
<= DCB_BCN_ATTR_RI
; i
++) {
916 if (!getall
&& !bcn_tb
[i
])
919 netdev
->dcbnl_ops
->getbcncfg(netdev
, i
,
921 ret
= nla_put_u32(skb
, i
, value_integer
);
926 nla_nest_end(skb
, bcn_nest
);
931 nla_nest_cancel(skb
, bcn_nest
);
935 static int dcbnl_bcn_setcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
936 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
938 struct nlattr
*data
[DCB_BCN_ATTR_MAX
+ 1];
944 if (!tb
[DCB_ATTR_BCN
])
947 if (!netdev
->dcbnl_ops
->setbcncfg
||
948 !netdev
->dcbnl_ops
->setbcnrp
)
951 ret
= nla_parse_nested(data
, DCB_BCN_ATTR_MAX
,
957 for (i
= DCB_BCN_ATTR_RP_0
; i
<= DCB_BCN_ATTR_RP_7
; i
++) {
960 value_byte
= nla_get_u8(data
[i
]);
961 netdev
->dcbnl_ops
->setbcnrp(netdev
,
962 data
[i
]->nla_type
- DCB_BCN_ATTR_RP_0
, value_byte
);
965 for (i
= DCB_BCN_ATTR_BCNA_0
; i
<= DCB_BCN_ATTR_RI
; i
++) {
968 value_int
= nla_get_u32(data
[i
]);
969 netdev
->dcbnl_ops
->setbcncfg(netdev
,
973 return nla_put_u8(skb
, DCB_ATTR_BCN
, 0);
976 static int dcbnl_build_peer_app(struct net_device
*netdev
, struct sk_buff
* skb
,
977 int app_nested_type
, int app_info_type
,
980 struct dcb_peer_app_info info
;
981 struct dcb_app
*table
= NULL
;
982 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
988 * retrieve the peer app configuration form the driver. If the driver
989 * handlers fail exit without doing anything
991 err
= ops
->peer_getappinfo(netdev
, &info
, &app_count
);
992 if (!err
&& app_count
) {
993 table
= kmalloc(sizeof(struct dcb_app
) * app_count
, GFP_KERNEL
);
997 err
= ops
->peer_getapptable(netdev
, table
);
1005 * build the message, from here on the only possible failure
1006 * is due to the skb size
1010 app
= nla_nest_start(skb
, app_nested_type
);
1012 goto nla_put_failure
;
1014 if (app_info_type
&&
1015 nla_put(skb
, app_info_type
, sizeof(info
), &info
))
1016 goto nla_put_failure
;
1018 for (i
= 0; i
< app_count
; i
++) {
1019 if (nla_put(skb
, app_entry_type
, sizeof(struct dcb_app
),
1021 goto nla_put_failure
;
1023 nla_nest_end(skb
, app
);
1032 /* Handle IEEE 802.1Qaz GET commands. */
1033 static int dcbnl_ieee_fill(struct sk_buff
*skb
, struct net_device
*netdev
)
1035 struct nlattr
*ieee
, *app
;
1036 struct dcb_app_type
*itr
;
1037 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1041 if (nla_put_string(skb
, DCB_ATTR_IFNAME
, netdev
->name
))
1044 ieee
= nla_nest_start(skb
, DCB_ATTR_IEEE
);
1048 if (ops
->ieee_getets
) {
1049 struct ieee_ets ets
;
1050 err
= ops
->ieee_getets(netdev
, &ets
);
1052 nla_put(skb
, DCB_ATTR_IEEE_ETS
, sizeof(ets
), &ets
))
1056 if (ops
->ieee_getmaxrate
) {
1057 struct ieee_maxrate maxrate
;
1058 err
= ops
->ieee_getmaxrate(netdev
, &maxrate
);
1060 err
= nla_put(skb
, DCB_ATTR_IEEE_MAXRATE
,
1061 sizeof(maxrate
), &maxrate
);
1067 if (ops
->ieee_getpfc
) {
1068 struct ieee_pfc pfc
;
1069 err
= ops
->ieee_getpfc(netdev
, &pfc
);
1071 nla_put(skb
, DCB_ATTR_IEEE_PFC
, sizeof(pfc
), &pfc
))
1075 app
= nla_nest_start(skb
, DCB_ATTR_IEEE_APP_TABLE
);
1079 spin_lock(&dcb_lock
);
1080 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1081 if (itr
->ifindex
== netdev
->ifindex
) {
1082 err
= nla_put(skb
, DCB_ATTR_IEEE_APP
, sizeof(itr
->app
),
1085 spin_unlock(&dcb_lock
);
1091 if (netdev
->dcbnl_ops
->getdcbx
)
1092 dcbx
= netdev
->dcbnl_ops
->getdcbx(netdev
);
1096 spin_unlock(&dcb_lock
);
1097 nla_nest_end(skb
, app
);
1099 /* get peer info if available */
1100 if (ops
->ieee_peer_getets
) {
1101 struct ieee_ets ets
;
1102 err
= ops
->ieee_peer_getets(netdev
, &ets
);
1104 nla_put(skb
, DCB_ATTR_IEEE_PEER_ETS
, sizeof(ets
), &ets
))
1108 if (ops
->ieee_peer_getpfc
) {
1109 struct ieee_pfc pfc
;
1110 err
= ops
->ieee_peer_getpfc(netdev
, &pfc
);
1112 nla_put(skb
, DCB_ATTR_IEEE_PEER_PFC
, sizeof(pfc
), &pfc
))
1116 if (ops
->peer_getappinfo
&& ops
->peer_getapptable
) {
1117 err
= dcbnl_build_peer_app(netdev
, skb
,
1118 DCB_ATTR_IEEE_PEER_APP
,
1119 DCB_ATTR_IEEE_APP_UNSPEC
,
1125 nla_nest_end(skb
, ieee
);
1127 err
= nla_put_u8(skb
, DCB_ATTR_DCBX
, dcbx
);
1135 static int dcbnl_cee_pg_fill(struct sk_buff
*skb
, struct net_device
*dev
,
1138 u8 pgid
, up_map
, prio
, tc_pct
;
1139 const struct dcbnl_rtnl_ops
*ops
= dev
->dcbnl_ops
;
1140 int i
= dir
? DCB_ATTR_CEE_TX_PG
: DCB_ATTR_CEE_RX_PG
;
1141 struct nlattr
*pg
= nla_nest_start(skb
, i
);
1146 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
1147 struct nlattr
*tc_nest
= nla_nest_start(skb
, i
);
1152 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
1153 prio
= DCB_ATTR_VALUE_UNDEFINED
;
1154 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
1155 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
1158 ops
->getpgtccfgrx(dev
, i
- DCB_PG_ATTR_TC_0
,
1159 &prio
, &pgid
, &tc_pct
, &up_map
);
1161 ops
->getpgtccfgtx(dev
, i
- DCB_PG_ATTR_TC_0
,
1162 &prio
, &pgid
, &tc_pct
, &up_map
);
1164 if (nla_put_u8(skb
, DCB_TC_ATTR_PARAM_PGID
, pgid
) ||
1165 nla_put_u8(skb
, DCB_TC_ATTR_PARAM_UP_MAPPING
, up_map
) ||
1166 nla_put_u8(skb
, DCB_TC_ATTR_PARAM_STRICT_PRIO
, prio
) ||
1167 nla_put_u8(skb
, DCB_TC_ATTR_PARAM_BW_PCT
, tc_pct
))
1169 nla_nest_end(skb
, tc_nest
);
1172 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
1173 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
1176 ops
->getpgbwgcfgrx(dev
, i
- DCB_PG_ATTR_BW_ID_0
,
1179 ops
->getpgbwgcfgtx(dev
, i
- DCB_PG_ATTR_BW_ID_0
,
1181 if (nla_put_u8(skb
, i
, tc_pct
))
1184 nla_nest_end(skb
, pg
);
1188 static int dcbnl_cee_fill(struct sk_buff
*skb
, struct net_device
*netdev
)
1190 struct nlattr
*cee
, *app
;
1191 struct dcb_app_type
*itr
;
1192 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1193 int dcbx
, i
, err
= -EMSGSIZE
;
1196 if (nla_put_string(skb
, DCB_ATTR_IFNAME
, netdev
->name
))
1197 goto nla_put_failure
;
1198 cee
= nla_nest_start(skb
, DCB_ATTR_CEE
);
1200 goto nla_put_failure
;
1203 if (ops
->getpgtccfgtx
&& ops
->getpgbwgcfgtx
) {
1204 err
= dcbnl_cee_pg_fill(skb
, netdev
, 1);
1206 goto nla_put_failure
;
1209 if (ops
->getpgtccfgrx
&& ops
->getpgbwgcfgrx
) {
1210 err
= dcbnl_cee_pg_fill(skb
, netdev
, 0);
1212 goto nla_put_failure
;
1216 if (ops
->getpfccfg
) {
1217 struct nlattr
*pfc_nest
= nla_nest_start(skb
, DCB_ATTR_CEE_PFC
);
1220 goto nla_put_failure
;
1222 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
1223 ops
->getpfccfg(netdev
, i
- DCB_PFC_UP_ATTR_0
, &value
);
1224 if (nla_put_u8(skb
, i
, value
))
1225 goto nla_put_failure
;
1227 nla_nest_end(skb
, pfc_nest
);
1231 spin_lock(&dcb_lock
);
1232 app
= nla_nest_start(skb
, DCB_ATTR_CEE_APP_TABLE
);
1236 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1237 if (itr
->ifindex
== netdev
->ifindex
) {
1238 struct nlattr
*app_nest
= nla_nest_start(skb
,
1243 err
= nla_put_u8(skb
, DCB_APP_ATTR_IDTYPE
,
1248 err
= nla_put_u16(skb
, DCB_APP_ATTR_ID
,
1253 err
= nla_put_u8(skb
, DCB_APP_ATTR_PRIORITY
,
1258 nla_nest_end(skb
, app_nest
);
1261 nla_nest_end(skb
, app
);
1263 if (netdev
->dcbnl_ops
->getdcbx
)
1264 dcbx
= netdev
->dcbnl_ops
->getdcbx(netdev
);
1268 spin_unlock(&dcb_lock
);
1270 /* features flags */
1271 if (ops
->getfeatcfg
) {
1272 struct nlattr
*feat
= nla_nest_start(skb
, DCB_ATTR_CEE_FEAT
);
1274 goto nla_put_failure
;
1276 for (i
= DCB_FEATCFG_ATTR_ALL
+ 1; i
<= DCB_FEATCFG_ATTR_MAX
;
1278 if (!ops
->getfeatcfg(netdev
, i
, &value
) &&
1279 nla_put_u8(skb
, i
, value
))
1280 goto nla_put_failure
;
1282 nla_nest_end(skb
, feat
);
1285 /* peer info if available */
1286 if (ops
->cee_peer_getpg
) {
1288 err
= ops
->cee_peer_getpg(netdev
, &pg
);
1290 nla_put(skb
, DCB_ATTR_CEE_PEER_PG
, sizeof(pg
), &pg
))
1291 goto nla_put_failure
;
1294 if (ops
->cee_peer_getpfc
) {
1296 err
= ops
->cee_peer_getpfc(netdev
, &pfc
);
1298 nla_put(skb
, DCB_ATTR_CEE_PEER_PFC
, sizeof(pfc
), &pfc
))
1299 goto nla_put_failure
;
1302 if (ops
->peer_getappinfo
&& ops
->peer_getapptable
) {
1303 err
= dcbnl_build_peer_app(netdev
, skb
,
1304 DCB_ATTR_CEE_PEER_APP_TABLE
,
1305 DCB_ATTR_CEE_PEER_APP_INFO
,
1306 DCB_ATTR_CEE_PEER_APP
);
1308 goto nla_put_failure
;
1310 nla_nest_end(skb
, cee
);
1314 err
= nla_put_u8(skb
, DCB_ATTR_DCBX
, dcbx
);
1316 goto nla_put_failure
;
1321 spin_unlock(&dcb_lock
);
1326 static int dcbnl_notify(struct net_device
*dev
, int event
, int cmd
,
1327 u32 seq
, u32 pid
, int dcbx_ver
)
1329 struct net
*net
= dev_net(dev
);
1330 struct sk_buff
*skb
;
1331 struct nlmsghdr
*nlh
;
1332 const struct dcbnl_rtnl_ops
*ops
= dev
->dcbnl_ops
;
1338 skb
= dcbnl_newmsg(event
, cmd
, pid
, seq
, 0, &nlh
);
1342 if (dcbx_ver
== DCB_CAP_DCBX_VER_IEEE
)
1343 err
= dcbnl_ieee_fill(skb
, dev
);
1345 err
= dcbnl_cee_fill(skb
, dev
);
1348 /* Report error to broadcast listeners */
1350 rtnl_set_sk_err(net
, RTNLGRP_DCB
, err
);
1352 /* End nlmsg and notify broadcast listeners */
1353 nlmsg_end(skb
, nlh
);
1354 rtnl_notify(skb
, net
, 0, RTNLGRP_DCB
, NULL
, GFP_KERNEL
);
1360 int dcbnl_ieee_notify(struct net_device
*dev
, int event
, int cmd
,
1363 return dcbnl_notify(dev
, event
, cmd
, seq
, pid
, DCB_CAP_DCBX_VER_IEEE
);
1365 EXPORT_SYMBOL(dcbnl_ieee_notify
);
1367 int dcbnl_cee_notify(struct net_device
*dev
, int event
, int cmd
,
1370 return dcbnl_notify(dev
, event
, cmd
, seq
, pid
, DCB_CAP_DCBX_VER_CEE
);
1372 EXPORT_SYMBOL(dcbnl_cee_notify
);
1374 /* Handle IEEE 802.1Qaz SET commands. If any requested operation can not
1375 * be completed the entire msg is aborted and error value is returned.
1376 * No attempt is made to reconcile the case where only part of the
1377 * cmd can be completed.
1379 static int dcbnl_ieee_set(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1380 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1382 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1383 struct nlattr
*ieee
[DCB_ATTR_IEEE_MAX
+ 1];
1389 if (!tb
[DCB_ATTR_IEEE
])
1392 err
= nla_parse_nested(ieee
, DCB_ATTR_IEEE_MAX
,
1393 tb
[DCB_ATTR_IEEE
], dcbnl_ieee_policy
);
1397 if (ieee
[DCB_ATTR_IEEE_ETS
] && ops
->ieee_setets
) {
1398 struct ieee_ets
*ets
= nla_data(ieee
[DCB_ATTR_IEEE_ETS
]);
1399 err
= ops
->ieee_setets(netdev
, ets
);
1404 if (ieee
[DCB_ATTR_IEEE_MAXRATE
] && ops
->ieee_setmaxrate
) {
1405 struct ieee_maxrate
*maxrate
=
1406 nla_data(ieee
[DCB_ATTR_IEEE_MAXRATE
]);
1407 err
= ops
->ieee_setmaxrate(netdev
, maxrate
);
1412 if (ieee
[DCB_ATTR_IEEE_PFC
] && ops
->ieee_setpfc
) {
1413 struct ieee_pfc
*pfc
= nla_data(ieee
[DCB_ATTR_IEEE_PFC
]);
1414 err
= ops
->ieee_setpfc(netdev
, pfc
);
1419 if (ieee
[DCB_ATTR_IEEE_APP_TABLE
]) {
1420 struct nlattr
*attr
;
1423 nla_for_each_nested(attr
, ieee
[DCB_ATTR_IEEE_APP_TABLE
], rem
) {
1424 struct dcb_app
*app_data
;
1425 if (nla_type(attr
) != DCB_ATTR_IEEE_APP
)
1427 app_data
= nla_data(attr
);
1428 if (ops
->ieee_setapp
)
1429 err
= ops
->ieee_setapp(netdev
, app_data
);
1431 err
= dcb_ieee_setapp(netdev
, app_data
);
1438 err
= nla_put_u8(skb
, DCB_ATTR_IEEE
, err
);
1439 dcbnl_ieee_notify(netdev
, RTM_SETDCB
, DCB_CMD_IEEE_SET
, seq
, 0);
1443 static int dcbnl_ieee_get(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1444 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1446 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1451 return dcbnl_ieee_fill(skb
, netdev
);
1454 static int dcbnl_ieee_del(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1455 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1457 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1458 struct nlattr
*ieee
[DCB_ATTR_IEEE_MAX
+ 1];
1464 if (!tb
[DCB_ATTR_IEEE
])
1467 err
= nla_parse_nested(ieee
, DCB_ATTR_IEEE_MAX
,
1468 tb
[DCB_ATTR_IEEE
], dcbnl_ieee_policy
);
1472 if (ieee
[DCB_ATTR_IEEE_APP_TABLE
]) {
1473 struct nlattr
*attr
;
1476 nla_for_each_nested(attr
, ieee
[DCB_ATTR_IEEE_APP_TABLE
], rem
) {
1477 struct dcb_app
*app_data
;
1479 if (nla_type(attr
) != DCB_ATTR_IEEE_APP
)
1481 app_data
= nla_data(attr
);
1482 if (ops
->ieee_delapp
)
1483 err
= ops
->ieee_delapp(netdev
, app_data
);
1485 err
= dcb_ieee_delapp(netdev
, app_data
);
1492 err
= nla_put_u8(skb
, DCB_ATTR_IEEE
, err
);
1493 dcbnl_ieee_notify(netdev
, RTM_SETDCB
, DCB_CMD_IEEE_DEL
, seq
, 0);
1498 /* DCBX configuration */
1499 static int dcbnl_getdcbx(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1500 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1502 if (!netdev
->dcbnl_ops
->getdcbx
)
1505 return nla_put_u8(skb
, DCB_ATTR_DCBX
,
1506 netdev
->dcbnl_ops
->getdcbx(netdev
));
1509 static int dcbnl_setdcbx(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1510 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1514 if (!netdev
->dcbnl_ops
->setdcbx
)
1517 if (!tb
[DCB_ATTR_DCBX
])
1520 value
= nla_get_u8(tb
[DCB_ATTR_DCBX
]);
1522 return nla_put_u8(skb
, DCB_ATTR_DCBX
,
1523 netdev
->dcbnl_ops
->setdcbx(netdev
, value
));
1526 static int dcbnl_getfeatcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1527 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1529 struct nlattr
*data
[DCB_FEATCFG_ATTR_MAX
+ 1], *nest
;
1534 if (!netdev
->dcbnl_ops
->getfeatcfg
)
1537 if (!tb
[DCB_ATTR_FEATCFG
])
1540 ret
= nla_parse_nested(data
, DCB_FEATCFG_ATTR_MAX
, tb
[DCB_ATTR_FEATCFG
],
1541 dcbnl_featcfg_nest
);
1545 nest
= nla_nest_start(skb
, DCB_ATTR_FEATCFG
);
1549 if (data
[DCB_FEATCFG_ATTR_ALL
])
1552 for (i
= DCB_FEATCFG_ATTR_ALL
+1; i
<= DCB_FEATCFG_ATTR_MAX
; i
++) {
1553 if (!getall
&& !data
[i
])
1556 ret
= netdev
->dcbnl_ops
->getfeatcfg(netdev
, i
, &value
);
1558 ret
= nla_put_u8(skb
, i
, value
);
1561 nla_nest_cancel(skb
, nest
);
1562 goto nla_put_failure
;
1565 nla_nest_end(skb
, nest
);
1571 static int dcbnl_setfeatcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1572 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1574 struct nlattr
*data
[DCB_FEATCFG_ATTR_MAX
+ 1];
1578 if (!netdev
->dcbnl_ops
->setfeatcfg
)
1581 if (!tb
[DCB_ATTR_FEATCFG
])
1584 ret
= nla_parse_nested(data
, DCB_FEATCFG_ATTR_MAX
, tb
[DCB_ATTR_FEATCFG
],
1585 dcbnl_featcfg_nest
);
1590 for (i
= DCB_FEATCFG_ATTR_ALL
+1; i
<= DCB_FEATCFG_ATTR_MAX
; i
++) {
1591 if (data
[i
] == NULL
)
1594 value
= nla_get_u8(data
[i
]);
1596 ret
= netdev
->dcbnl_ops
->setfeatcfg(netdev
, i
, value
);
1602 ret
= nla_put_u8(skb
, DCB_ATTR_FEATCFG
, ret
);
1607 /* Handle CEE DCBX GET commands. */
1608 static int dcbnl_cee_get(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1609 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1611 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1616 return dcbnl_cee_fill(skb
, netdev
);
1620 /* reply netlink message type */
1623 /* function to fill message contents */
1624 int (*cb
)(struct net_device
*, struct nlmsghdr
*, u32
,
1625 struct nlattr
**, struct sk_buff
*);
1628 static const struct reply_func reply_funcs
[DCB_CMD_MAX
+1] = {
1629 [DCB_CMD_GSTATE
] = { RTM_GETDCB
, dcbnl_getstate
},
1630 [DCB_CMD_SSTATE
] = { RTM_SETDCB
, dcbnl_setstate
},
1631 [DCB_CMD_PFC_GCFG
] = { RTM_GETDCB
, dcbnl_getpfccfg
},
1632 [DCB_CMD_PFC_SCFG
] = { RTM_SETDCB
, dcbnl_setpfccfg
},
1633 [DCB_CMD_GPERM_HWADDR
] = { RTM_GETDCB
, dcbnl_getperm_hwaddr
},
1634 [DCB_CMD_GCAP
] = { RTM_GETDCB
, dcbnl_getcap
},
1635 [DCB_CMD_GNUMTCS
] = { RTM_GETDCB
, dcbnl_getnumtcs
},
1636 [DCB_CMD_SNUMTCS
] = { RTM_SETDCB
, dcbnl_setnumtcs
},
1637 [DCB_CMD_PFC_GSTATE
] = { RTM_GETDCB
, dcbnl_getpfcstate
},
1638 [DCB_CMD_PFC_SSTATE
] = { RTM_SETDCB
, dcbnl_setpfcstate
},
1639 [DCB_CMD_GAPP
] = { RTM_GETDCB
, dcbnl_getapp
},
1640 [DCB_CMD_SAPP
] = { RTM_SETDCB
, dcbnl_setapp
},
1641 [DCB_CMD_PGTX_GCFG
] = { RTM_GETDCB
, dcbnl_pgtx_getcfg
},
1642 [DCB_CMD_PGTX_SCFG
] = { RTM_SETDCB
, dcbnl_pgtx_setcfg
},
1643 [DCB_CMD_PGRX_GCFG
] = { RTM_GETDCB
, dcbnl_pgrx_getcfg
},
1644 [DCB_CMD_PGRX_SCFG
] = { RTM_SETDCB
, dcbnl_pgrx_setcfg
},
1645 [DCB_CMD_SET_ALL
] = { RTM_SETDCB
, dcbnl_setall
},
1646 [DCB_CMD_BCN_GCFG
] = { RTM_GETDCB
, dcbnl_bcn_getcfg
},
1647 [DCB_CMD_BCN_SCFG
] = { RTM_SETDCB
, dcbnl_bcn_setcfg
},
1648 [DCB_CMD_IEEE_GET
] = { RTM_GETDCB
, dcbnl_ieee_get
},
1649 [DCB_CMD_IEEE_SET
] = { RTM_SETDCB
, dcbnl_ieee_set
},
1650 [DCB_CMD_IEEE_DEL
] = { RTM_SETDCB
, dcbnl_ieee_del
},
1651 [DCB_CMD_GDCBX
] = { RTM_GETDCB
, dcbnl_getdcbx
},
1652 [DCB_CMD_SDCBX
] = { RTM_SETDCB
, dcbnl_setdcbx
},
1653 [DCB_CMD_GFEATCFG
] = { RTM_GETDCB
, dcbnl_getfeatcfg
},
1654 [DCB_CMD_SFEATCFG
] = { RTM_SETDCB
, dcbnl_setfeatcfg
},
1655 [DCB_CMD_CEE_GET
] = { RTM_GETDCB
, dcbnl_cee_get
},
1658 static int dcb_doit(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
1660 struct net
*net
= sock_net(skb
->sk
);
1661 struct net_device
*netdev
;
1662 struct dcbmsg
*dcb
= (struct dcbmsg
*)NLMSG_DATA(nlh
);
1663 struct nlattr
*tb
[DCB_ATTR_MAX
+ 1];
1664 u32 pid
= skb
? NETLINK_CB(skb
).pid
: 0;
1666 struct sk_buff
*reply_skb
;
1667 struct nlmsghdr
*reply_nlh
;
1668 const struct reply_func
*fn
;
1670 if (!net_eq(net
, &init_net
))
1673 ret
= nlmsg_parse(nlh
, sizeof(*dcb
), tb
, DCB_ATTR_MAX
,
1678 if (dcb
->cmd
> DCB_CMD_MAX
)
1681 /* check if a reply function has been defined for the command */
1682 fn
= &reply_funcs
[dcb
->cmd
];
1686 if (!tb
[DCB_ATTR_IFNAME
])
1689 netdev
= dev_get_by_name(&init_net
, nla_data(tb
[DCB_ATTR_IFNAME
]));
1693 if (!netdev
->dcbnl_ops
) {
1698 reply_skb
= dcbnl_newmsg(fn
->type
, dcb
->cmd
, pid
, nlh
->nlmsg_seq
,
1699 nlh
->nlmsg_flags
, &reply_nlh
);
1705 ret
= fn
->cb(netdev
, nlh
, nlh
->nlmsg_seq
, tb
, reply_skb
);
1707 nlmsg_free(reply_skb
);
1711 nlmsg_end(reply_skb
, reply_nlh
);
1713 ret
= rtnl_unicast(reply_skb
, &init_net
, pid
);
1720 * dcb_getapp - retrieve the DCBX application user priority
1722 * On success returns a non-zero 802.1p user priority bitmap
1723 * otherwise returns 0 as the invalid user priority bitmap to
1724 * indicate an error.
1726 u8
dcb_getapp(struct net_device
*dev
, struct dcb_app
*app
)
1728 struct dcb_app_type
*itr
;
1731 spin_lock(&dcb_lock
);
1732 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1733 if (itr
->app
.selector
== app
->selector
&&
1734 itr
->app
.protocol
== app
->protocol
&&
1735 itr
->ifindex
== dev
->ifindex
) {
1736 prio
= itr
->app
.priority
;
1740 spin_unlock(&dcb_lock
);
1744 EXPORT_SYMBOL(dcb_getapp
);
1747 * dcb_setapp - add CEE dcb application data to app list
1749 * Priority 0 is an invalid priority in CEE spec. This routine
1750 * removes applications from the app list if the priority is
1753 int dcb_setapp(struct net_device
*dev
, struct dcb_app
*new)
1755 struct dcb_app_type
*itr
;
1756 struct dcb_app_type event
;
1758 event
.ifindex
= dev
->ifindex
;
1759 memcpy(&event
.app
, new, sizeof(event
.app
));
1760 if (dev
->dcbnl_ops
->getdcbx
)
1761 event
.dcbx
= dev
->dcbnl_ops
->getdcbx(dev
);
1763 spin_lock(&dcb_lock
);
1764 /* Search for existing match and replace */
1765 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1766 if (itr
->app
.selector
== new->selector
&&
1767 itr
->app
.protocol
== new->protocol
&&
1768 itr
->ifindex
== dev
->ifindex
) {
1770 itr
->app
.priority
= new->priority
;
1772 list_del(&itr
->list
);
1778 /* App type does not exist add new application type */
1779 if (new->priority
) {
1780 struct dcb_app_type
*entry
;
1781 entry
= kmalloc(sizeof(struct dcb_app_type
), GFP_ATOMIC
);
1783 spin_unlock(&dcb_lock
);
1787 memcpy(&entry
->app
, new, sizeof(*new));
1788 entry
->ifindex
= dev
->ifindex
;
1789 list_add(&entry
->list
, &dcb_app_list
);
1792 spin_unlock(&dcb_lock
);
1793 call_dcbevent_notifiers(DCB_APP_EVENT
, &event
);
1796 EXPORT_SYMBOL(dcb_setapp
);
1799 * dcb_ieee_getapp_mask - retrieve the IEEE DCB application priority
1801 * Helper routine which on success returns a non-zero 802.1Qaz user
1802 * priority bitmap otherwise returns 0 to indicate the dcb_app was
1803 * not found in APP list.
1805 u8
dcb_ieee_getapp_mask(struct net_device
*dev
, struct dcb_app
*app
)
1807 struct dcb_app_type
*itr
;
1810 spin_lock(&dcb_lock
);
1811 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1812 if (itr
->app
.selector
== app
->selector
&&
1813 itr
->app
.protocol
== app
->protocol
&&
1814 itr
->ifindex
== dev
->ifindex
) {
1815 prio
|= 1 << itr
->app
.priority
;
1818 spin_unlock(&dcb_lock
);
1822 EXPORT_SYMBOL(dcb_ieee_getapp_mask
);
1825 * dcb_ieee_setapp - add IEEE dcb application data to app list
1827 * This adds Application data to the list. Multiple application
1828 * entries may exists for the same selector and protocol as long
1829 * as the priorities are different.
1831 int dcb_ieee_setapp(struct net_device
*dev
, struct dcb_app
*new)
1833 struct dcb_app_type
*itr
, *entry
;
1834 struct dcb_app_type event
;
1837 event
.ifindex
= dev
->ifindex
;
1838 memcpy(&event
.app
, new, sizeof(event
.app
));
1839 if (dev
->dcbnl_ops
->getdcbx
)
1840 event
.dcbx
= dev
->dcbnl_ops
->getdcbx(dev
);
1842 spin_lock(&dcb_lock
);
1843 /* Search for existing match and abort if found */
1844 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1845 if (itr
->app
.selector
== new->selector
&&
1846 itr
->app
.protocol
== new->protocol
&&
1847 itr
->app
.priority
== new->priority
&&
1848 itr
->ifindex
== dev
->ifindex
) {
1854 /* App entry does not exist add new entry */
1855 entry
= kmalloc(sizeof(struct dcb_app_type
), GFP_ATOMIC
);
1861 memcpy(&entry
->app
, new, sizeof(*new));
1862 entry
->ifindex
= dev
->ifindex
;
1863 list_add(&entry
->list
, &dcb_app_list
);
1865 spin_unlock(&dcb_lock
);
1867 call_dcbevent_notifiers(DCB_APP_EVENT
, &event
);
1870 EXPORT_SYMBOL(dcb_ieee_setapp
);
1873 * dcb_ieee_delapp - delete IEEE dcb application data from list
1875 * This removes a matching APP data from the APP list
1877 int dcb_ieee_delapp(struct net_device
*dev
, struct dcb_app
*del
)
1879 struct dcb_app_type
*itr
;
1880 struct dcb_app_type event
;
1883 event
.ifindex
= dev
->ifindex
;
1884 memcpy(&event
.app
, del
, sizeof(event
.app
));
1885 if (dev
->dcbnl_ops
->getdcbx
)
1886 event
.dcbx
= dev
->dcbnl_ops
->getdcbx(dev
);
1888 spin_lock(&dcb_lock
);
1889 /* Search for existing match and remove it. */
1890 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1891 if (itr
->app
.selector
== del
->selector
&&
1892 itr
->app
.protocol
== del
->protocol
&&
1893 itr
->app
.priority
== del
->priority
&&
1894 itr
->ifindex
== dev
->ifindex
) {
1895 list_del(&itr
->list
);
1903 spin_unlock(&dcb_lock
);
1905 call_dcbevent_notifiers(DCB_APP_EVENT
, &event
);
1908 EXPORT_SYMBOL(dcb_ieee_delapp
);
1910 static void dcb_flushapp(void)
1912 struct dcb_app_type
*app
;
1913 struct dcb_app_type
*tmp
;
1915 spin_lock(&dcb_lock
);
1916 list_for_each_entry_safe(app
, tmp
, &dcb_app_list
, list
) {
1917 list_del(&app
->list
);
1920 spin_unlock(&dcb_lock
);
1923 static int __init
dcbnl_init(void)
1925 INIT_LIST_HEAD(&dcb_app_list
);
1927 rtnl_register(PF_UNSPEC
, RTM_GETDCB
, dcb_doit
, NULL
, NULL
);
1928 rtnl_register(PF_UNSPEC
, RTM_SETDCB
, dcb_doit
, NULL
, NULL
);
1932 module_init(dcbnl_init
);
1934 static void __exit
dcbnl_exit(void)
1936 rtnl_unregister(PF_UNSPEC
, RTM_GETDCB
);
1937 rtnl_unregister(PF_UNSPEC
, RTM_SETDCB
);
1940 module_exit(dcbnl_exit
);