2 * Copyright (c) 2008-2011, Intel Corporation.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, see <http://www.gnu.org/licenses/>.
16 * Author: Lucy Liu <lucy.liu@intel.com>
19 #include <linux/netdevice.h>
20 #include <linux/netlink.h>
21 #include <linux/slab.h>
22 #include <net/netlink.h>
23 #include <net/rtnetlink.h>
24 #include <linux/dcbnl.h>
25 #include <net/dcbevent.h>
26 #include <linux/rtnetlink.h>
27 #include <linux/module.h>
30 /* Data Center Bridging (DCB) is a collection of Ethernet enhancements
31 * intended to allow network traffic with differing requirements
32 * (highly reliable, no drops vs. best effort vs. low latency) to operate
33 * and co-exist on Ethernet. Current DCB features are:
35 * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a
36 * framework for assigning bandwidth guarantees to traffic classes.
38 * Priority-based Flow Control (PFC) - provides a flow control mechanism which
39 * can work independently for each 802.1p priority.
41 * Congestion Notification - provides a mechanism for end-to-end congestion
42 * control for protocols which do not have built-in congestion management.
44 * More information about the emerging standards for these Ethernet features
45 * can be found at: http://www.ieee802.org/1/pages/dcbridges.html
47 * This file implements an rtnetlink interface to allow configuration of DCB
48 * features for capable devices.
51 MODULE_AUTHOR("Lucy Liu, <lucy.liu@intel.com>");
52 MODULE_DESCRIPTION("Data Center Bridging netlink interface");
53 MODULE_LICENSE("GPL");
55 /**************** DCB attribute policies *************************************/
57 /* DCB netlink attributes policy */
58 static const struct nla_policy dcbnl_rtnl_policy
[DCB_ATTR_MAX
+ 1] = {
59 [DCB_ATTR_IFNAME
] = {.type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
- 1},
60 [DCB_ATTR_STATE
] = {.type
= NLA_U8
},
61 [DCB_ATTR_PFC_CFG
] = {.type
= NLA_NESTED
},
62 [DCB_ATTR_PG_CFG
] = {.type
= NLA_NESTED
},
63 [DCB_ATTR_SET_ALL
] = {.type
= NLA_U8
},
64 [DCB_ATTR_PERM_HWADDR
] = {.type
= NLA_FLAG
},
65 [DCB_ATTR_CAP
] = {.type
= NLA_NESTED
},
66 [DCB_ATTR_PFC_STATE
] = {.type
= NLA_U8
},
67 [DCB_ATTR_BCN
] = {.type
= NLA_NESTED
},
68 [DCB_ATTR_APP
] = {.type
= NLA_NESTED
},
69 [DCB_ATTR_IEEE
] = {.type
= NLA_NESTED
},
70 [DCB_ATTR_DCBX
] = {.type
= NLA_U8
},
71 [DCB_ATTR_FEATCFG
] = {.type
= NLA_NESTED
},
74 /* DCB priority flow control to User Priority nested attributes */
75 static const struct nla_policy dcbnl_pfc_up_nest
[DCB_PFC_UP_ATTR_MAX
+ 1] = {
76 [DCB_PFC_UP_ATTR_0
] = {.type
= NLA_U8
},
77 [DCB_PFC_UP_ATTR_1
] = {.type
= NLA_U8
},
78 [DCB_PFC_UP_ATTR_2
] = {.type
= NLA_U8
},
79 [DCB_PFC_UP_ATTR_3
] = {.type
= NLA_U8
},
80 [DCB_PFC_UP_ATTR_4
] = {.type
= NLA_U8
},
81 [DCB_PFC_UP_ATTR_5
] = {.type
= NLA_U8
},
82 [DCB_PFC_UP_ATTR_6
] = {.type
= NLA_U8
},
83 [DCB_PFC_UP_ATTR_7
] = {.type
= NLA_U8
},
84 [DCB_PFC_UP_ATTR_ALL
] = {.type
= NLA_FLAG
},
87 /* DCB priority grouping nested attributes */
88 static const struct nla_policy dcbnl_pg_nest
[DCB_PG_ATTR_MAX
+ 1] = {
89 [DCB_PG_ATTR_TC_0
] = {.type
= NLA_NESTED
},
90 [DCB_PG_ATTR_TC_1
] = {.type
= NLA_NESTED
},
91 [DCB_PG_ATTR_TC_2
] = {.type
= NLA_NESTED
},
92 [DCB_PG_ATTR_TC_3
] = {.type
= NLA_NESTED
},
93 [DCB_PG_ATTR_TC_4
] = {.type
= NLA_NESTED
},
94 [DCB_PG_ATTR_TC_5
] = {.type
= NLA_NESTED
},
95 [DCB_PG_ATTR_TC_6
] = {.type
= NLA_NESTED
},
96 [DCB_PG_ATTR_TC_7
] = {.type
= NLA_NESTED
},
97 [DCB_PG_ATTR_TC_ALL
] = {.type
= NLA_NESTED
},
98 [DCB_PG_ATTR_BW_ID_0
] = {.type
= NLA_U8
},
99 [DCB_PG_ATTR_BW_ID_1
] = {.type
= NLA_U8
},
100 [DCB_PG_ATTR_BW_ID_2
] = {.type
= NLA_U8
},
101 [DCB_PG_ATTR_BW_ID_3
] = {.type
= NLA_U8
},
102 [DCB_PG_ATTR_BW_ID_4
] = {.type
= NLA_U8
},
103 [DCB_PG_ATTR_BW_ID_5
] = {.type
= NLA_U8
},
104 [DCB_PG_ATTR_BW_ID_6
] = {.type
= NLA_U8
},
105 [DCB_PG_ATTR_BW_ID_7
] = {.type
= NLA_U8
},
106 [DCB_PG_ATTR_BW_ID_ALL
] = {.type
= NLA_FLAG
},
109 /* DCB traffic class nested attributes. */
110 static const struct nla_policy dcbnl_tc_param_nest
[DCB_TC_ATTR_PARAM_MAX
+ 1] = {
111 [DCB_TC_ATTR_PARAM_PGID
] = {.type
= NLA_U8
},
112 [DCB_TC_ATTR_PARAM_UP_MAPPING
] = {.type
= NLA_U8
},
113 [DCB_TC_ATTR_PARAM_STRICT_PRIO
] = {.type
= NLA_U8
},
114 [DCB_TC_ATTR_PARAM_BW_PCT
] = {.type
= NLA_U8
},
115 [DCB_TC_ATTR_PARAM_ALL
] = {.type
= NLA_FLAG
},
118 /* DCB capabilities nested attributes. */
119 static const struct nla_policy dcbnl_cap_nest
[DCB_CAP_ATTR_MAX
+ 1] = {
120 [DCB_CAP_ATTR_ALL
] = {.type
= NLA_FLAG
},
121 [DCB_CAP_ATTR_PG
] = {.type
= NLA_U8
},
122 [DCB_CAP_ATTR_PFC
] = {.type
= NLA_U8
},
123 [DCB_CAP_ATTR_UP2TC
] = {.type
= NLA_U8
},
124 [DCB_CAP_ATTR_PG_TCS
] = {.type
= NLA_U8
},
125 [DCB_CAP_ATTR_PFC_TCS
] = {.type
= NLA_U8
},
126 [DCB_CAP_ATTR_GSP
] = {.type
= NLA_U8
},
127 [DCB_CAP_ATTR_BCN
] = {.type
= NLA_U8
},
128 [DCB_CAP_ATTR_DCBX
] = {.type
= NLA_U8
},
131 /* DCB capabilities nested attributes. */
132 static const struct nla_policy dcbnl_numtcs_nest
[DCB_NUMTCS_ATTR_MAX
+ 1] = {
133 [DCB_NUMTCS_ATTR_ALL
] = {.type
= NLA_FLAG
},
134 [DCB_NUMTCS_ATTR_PG
] = {.type
= NLA_U8
},
135 [DCB_NUMTCS_ATTR_PFC
] = {.type
= NLA_U8
},
138 /* DCB BCN nested attributes. */
139 static const struct nla_policy dcbnl_bcn_nest
[DCB_BCN_ATTR_MAX
+ 1] = {
140 [DCB_BCN_ATTR_RP_0
] = {.type
= NLA_U8
},
141 [DCB_BCN_ATTR_RP_1
] = {.type
= NLA_U8
},
142 [DCB_BCN_ATTR_RP_2
] = {.type
= NLA_U8
},
143 [DCB_BCN_ATTR_RP_3
] = {.type
= NLA_U8
},
144 [DCB_BCN_ATTR_RP_4
] = {.type
= NLA_U8
},
145 [DCB_BCN_ATTR_RP_5
] = {.type
= NLA_U8
},
146 [DCB_BCN_ATTR_RP_6
] = {.type
= NLA_U8
},
147 [DCB_BCN_ATTR_RP_7
] = {.type
= NLA_U8
},
148 [DCB_BCN_ATTR_RP_ALL
] = {.type
= NLA_FLAG
},
149 [DCB_BCN_ATTR_BCNA_0
] = {.type
= NLA_U32
},
150 [DCB_BCN_ATTR_BCNA_1
] = {.type
= NLA_U32
},
151 [DCB_BCN_ATTR_ALPHA
] = {.type
= NLA_U32
},
152 [DCB_BCN_ATTR_BETA
] = {.type
= NLA_U32
},
153 [DCB_BCN_ATTR_GD
] = {.type
= NLA_U32
},
154 [DCB_BCN_ATTR_GI
] = {.type
= NLA_U32
},
155 [DCB_BCN_ATTR_TMAX
] = {.type
= NLA_U32
},
156 [DCB_BCN_ATTR_TD
] = {.type
= NLA_U32
},
157 [DCB_BCN_ATTR_RMIN
] = {.type
= NLA_U32
},
158 [DCB_BCN_ATTR_W
] = {.type
= NLA_U32
},
159 [DCB_BCN_ATTR_RD
] = {.type
= NLA_U32
},
160 [DCB_BCN_ATTR_RU
] = {.type
= NLA_U32
},
161 [DCB_BCN_ATTR_WRTT
] = {.type
= NLA_U32
},
162 [DCB_BCN_ATTR_RI
] = {.type
= NLA_U32
},
163 [DCB_BCN_ATTR_C
] = {.type
= NLA_U32
},
164 [DCB_BCN_ATTR_ALL
] = {.type
= NLA_FLAG
},
167 /* DCB APP nested attributes. */
168 static const struct nla_policy dcbnl_app_nest
[DCB_APP_ATTR_MAX
+ 1] = {
169 [DCB_APP_ATTR_IDTYPE
] = {.type
= NLA_U8
},
170 [DCB_APP_ATTR_ID
] = {.type
= NLA_U16
},
171 [DCB_APP_ATTR_PRIORITY
] = {.type
= NLA_U8
},
174 /* IEEE 802.1Qaz nested attributes. */
175 static const struct nla_policy dcbnl_ieee_policy
[DCB_ATTR_IEEE_MAX
+ 1] = {
176 [DCB_ATTR_IEEE_ETS
] = {.len
= sizeof(struct ieee_ets
)},
177 [DCB_ATTR_IEEE_PFC
] = {.len
= sizeof(struct ieee_pfc
)},
178 [DCB_ATTR_IEEE_APP_TABLE
] = {.type
= NLA_NESTED
},
179 [DCB_ATTR_IEEE_MAXRATE
] = {.len
= sizeof(struct ieee_maxrate
)},
180 [DCB_ATTR_IEEE_QCN
] = {.len
= sizeof(struct ieee_qcn
)},
181 [DCB_ATTR_IEEE_QCN_STATS
] = {.len
= sizeof(struct ieee_qcn_stats
)},
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
);
213 dcb
= nlmsg_data(nlh
);
214 dcb
->dcb_family
= AF_UNSPEC
;
224 static int dcbnl_getstate(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
225 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
227 /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
228 if (!netdev
->dcbnl_ops
->getstate
)
231 return nla_put_u8(skb
, DCB_ATTR_STATE
,
232 netdev
->dcbnl_ops
->getstate(netdev
));
235 static int dcbnl_getpfccfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
236 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
238 struct nlattr
*data
[DCB_PFC_UP_ATTR_MAX
+ 1], *nest
;
244 if (!tb
[DCB_ATTR_PFC_CFG
])
247 if (!netdev
->dcbnl_ops
->getpfccfg
)
250 ret
= nla_parse_nested(data
, DCB_PFC_UP_ATTR_MAX
,
251 tb
[DCB_ATTR_PFC_CFG
],
256 nest
= nla_nest_start(skb
, DCB_ATTR_PFC_CFG
);
260 if (data
[DCB_PFC_UP_ATTR_ALL
])
263 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
264 if (!getall
&& !data
[i
])
267 netdev
->dcbnl_ops
->getpfccfg(netdev
, i
- DCB_PFC_UP_ATTR_0
,
269 ret
= nla_put_u8(skb
, i
, value
);
271 nla_nest_cancel(skb
, nest
);
275 nla_nest_end(skb
, nest
);
280 static int dcbnl_getperm_hwaddr(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
281 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
283 u8 perm_addr
[MAX_ADDR_LEN
];
285 if (!netdev
->dcbnl_ops
->getpermhwaddr
)
288 memset(perm_addr
, 0, sizeof(perm_addr
));
289 netdev
->dcbnl_ops
->getpermhwaddr(netdev
, perm_addr
);
291 return nla_put(skb
, DCB_ATTR_PERM_HWADDR
, sizeof(perm_addr
), perm_addr
);
294 static int dcbnl_getcap(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
295 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
297 struct nlattr
*data
[DCB_CAP_ATTR_MAX
+ 1], *nest
;
303 if (!tb
[DCB_ATTR_CAP
])
306 if (!netdev
->dcbnl_ops
->getcap
)
309 ret
= nla_parse_nested(data
, DCB_CAP_ATTR_MAX
, tb
[DCB_ATTR_CAP
],
314 nest
= nla_nest_start(skb
, DCB_ATTR_CAP
);
318 if (data
[DCB_CAP_ATTR_ALL
])
321 for (i
= DCB_CAP_ATTR_ALL
+1; i
<= DCB_CAP_ATTR_MAX
; i
++) {
322 if (!getall
&& !data
[i
])
325 if (!netdev
->dcbnl_ops
->getcap(netdev
, i
, &value
)) {
326 ret
= nla_put_u8(skb
, i
, value
);
328 nla_nest_cancel(skb
, nest
);
333 nla_nest_end(skb
, nest
);
338 static int dcbnl_getnumtcs(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
339 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
341 struct nlattr
*data
[DCB_NUMTCS_ATTR_MAX
+ 1], *nest
;
347 if (!tb
[DCB_ATTR_NUMTCS
])
350 if (!netdev
->dcbnl_ops
->getnumtcs
)
353 ret
= nla_parse_nested(data
, DCB_NUMTCS_ATTR_MAX
, tb
[DCB_ATTR_NUMTCS
],
358 nest
= nla_nest_start(skb
, DCB_ATTR_NUMTCS
);
362 if (data
[DCB_NUMTCS_ATTR_ALL
])
365 for (i
= DCB_NUMTCS_ATTR_ALL
+1; i
<= DCB_NUMTCS_ATTR_MAX
; i
++) {
366 if (!getall
&& !data
[i
])
369 ret
= netdev
->dcbnl_ops
->getnumtcs(netdev
, i
, &value
);
371 ret
= nla_put_u8(skb
, i
, value
);
373 nla_nest_cancel(skb
, nest
);
379 nla_nest_end(skb
, nest
);
384 static int dcbnl_setnumtcs(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
385 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
387 struct nlattr
*data
[DCB_NUMTCS_ATTR_MAX
+ 1];
392 if (!tb
[DCB_ATTR_NUMTCS
])
395 if (!netdev
->dcbnl_ops
->setnumtcs
)
398 ret
= nla_parse_nested(data
, DCB_NUMTCS_ATTR_MAX
, tb
[DCB_ATTR_NUMTCS
],
403 for (i
= DCB_NUMTCS_ATTR_ALL
+1; i
<= DCB_NUMTCS_ATTR_MAX
; i
++) {
407 value
= nla_get_u8(data
[i
]);
409 ret
= netdev
->dcbnl_ops
->setnumtcs(netdev
, i
, value
);
414 return nla_put_u8(skb
, DCB_ATTR_NUMTCS
, !!ret
);
417 static int dcbnl_getpfcstate(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
418 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
420 if (!netdev
->dcbnl_ops
->getpfcstate
)
423 return nla_put_u8(skb
, DCB_ATTR_PFC_STATE
,
424 netdev
->dcbnl_ops
->getpfcstate(netdev
));
427 static int dcbnl_setpfcstate(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
428 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
432 if (!tb
[DCB_ATTR_PFC_STATE
])
435 if (!netdev
->dcbnl_ops
->setpfcstate
)
438 value
= nla_get_u8(tb
[DCB_ATTR_PFC_STATE
]);
440 netdev
->dcbnl_ops
->setpfcstate(netdev
, value
);
442 return nla_put_u8(skb
, DCB_ATTR_PFC_STATE
, 0);
445 static int dcbnl_getapp(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
446 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
448 struct nlattr
*app_nest
;
449 struct nlattr
*app_tb
[DCB_APP_ATTR_MAX
+ 1];
454 if (!tb
[DCB_ATTR_APP
])
457 ret
= nla_parse_nested(app_tb
, DCB_APP_ATTR_MAX
, tb
[DCB_ATTR_APP
],
462 /* all must be non-null */
463 if ((!app_tb
[DCB_APP_ATTR_IDTYPE
]) ||
464 (!app_tb
[DCB_APP_ATTR_ID
]))
467 /* either by eth type or by socket number */
468 idtype
= nla_get_u8(app_tb
[DCB_APP_ATTR_IDTYPE
]);
469 if ((idtype
!= DCB_APP_IDTYPE_ETHTYPE
) &&
470 (idtype
!= DCB_APP_IDTYPE_PORTNUM
))
473 id
= nla_get_u16(app_tb
[DCB_APP_ATTR_ID
]);
475 if (netdev
->dcbnl_ops
->getapp
) {
476 ret
= netdev
->dcbnl_ops
->getapp(netdev
, idtype
, id
);
482 struct dcb_app app
= {
486 up
= dcb_getapp(netdev
, &app
);
489 app_nest
= nla_nest_start(skb
, DCB_ATTR_APP
);
493 ret
= nla_put_u8(skb
, DCB_APP_ATTR_IDTYPE
, idtype
);
497 ret
= nla_put_u16(skb
, DCB_APP_ATTR_ID
, id
);
501 ret
= nla_put_u8(skb
, DCB_APP_ATTR_PRIORITY
, up
);
505 nla_nest_end(skb
, app_nest
);
510 nla_nest_cancel(skb
, app_nest
);
514 static int dcbnl_setapp(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
515 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
520 struct nlattr
*app_tb
[DCB_APP_ATTR_MAX
+ 1];
522 if (!tb
[DCB_ATTR_APP
])
525 ret
= nla_parse_nested(app_tb
, DCB_APP_ATTR_MAX
, tb
[DCB_ATTR_APP
],
530 /* all must be non-null */
531 if ((!app_tb
[DCB_APP_ATTR_IDTYPE
]) ||
532 (!app_tb
[DCB_APP_ATTR_ID
]) ||
533 (!app_tb
[DCB_APP_ATTR_PRIORITY
]))
536 /* either by eth type or by socket number */
537 idtype
= nla_get_u8(app_tb
[DCB_APP_ATTR_IDTYPE
]);
538 if ((idtype
!= DCB_APP_IDTYPE_ETHTYPE
) &&
539 (idtype
!= DCB_APP_IDTYPE_PORTNUM
))
542 id
= nla_get_u16(app_tb
[DCB_APP_ATTR_ID
]);
543 up
= nla_get_u8(app_tb
[DCB_APP_ATTR_PRIORITY
]);
545 if (netdev
->dcbnl_ops
->setapp
) {
546 ret
= netdev
->dcbnl_ops
->setapp(netdev
, idtype
, id
, up
);
551 app
.selector
= idtype
;
554 ret
= dcb_setapp(netdev
, &app
);
557 ret
= nla_put_u8(skb
, DCB_ATTR_APP
, ret
);
558 dcbnl_cee_notify(netdev
, RTM_SETDCB
, DCB_CMD_SAPP
, seq
, 0);
563 static int __dcbnl_pg_getcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
564 struct nlattr
**tb
, struct sk_buff
*skb
, int dir
)
566 struct nlattr
*pg_nest
, *param_nest
, *data
;
567 struct nlattr
*pg_tb
[DCB_PG_ATTR_MAX
+ 1];
568 struct nlattr
*param_tb
[DCB_TC_ATTR_PARAM_MAX
+ 1];
569 u8 prio
, pgid
, tc_pct
, up_map
;
574 if (!tb
[DCB_ATTR_PG_CFG
])
577 if (!netdev
->dcbnl_ops
->getpgtccfgtx
||
578 !netdev
->dcbnl_ops
->getpgtccfgrx
||
579 !netdev
->dcbnl_ops
->getpgbwgcfgtx
||
580 !netdev
->dcbnl_ops
->getpgbwgcfgrx
)
583 ret
= nla_parse_nested(pg_tb
, DCB_PG_ATTR_MAX
,
584 tb
[DCB_ATTR_PG_CFG
], dcbnl_pg_nest
);
588 pg_nest
= nla_nest_start(skb
, DCB_ATTR_PG_CFG
);
592 if (pg_tb
[DCB_PG_ATTR_TC_ALL
])
595 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
596 if (!getall
&& !pg_tb
[i
])
599 if (pg_tb
[DCB_PG_ATTR_TC_ALL
])
600 data
= pg_tb
[DCB_PG_ATTR_TC_ALL
];
603 ret
= nla_parse_nested(param_tb
, DCB_TC_ATTR_PARAM_MAX
,
604 data
, dcbnl_tc_param_nest
);
608 param_nest
= nla_nest_start(skb
, i
);
612 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
613 prio
= DCB_ATTR_VALUE_UNDEFINED
;
614 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
615 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
619 netdev
->dcbnl_ops
->getpgtccfgrx(netdev
,
620 i
- DCB_PG_ATTR_TC_0
, &prio
,
621 &pgid
, &tc_pct
, &up_map
);
624 netdev
->dcbnl_ops
->getpgtccfgtx(netdev
,
625 i
- DCB_PG_ATTR_TC_0
, &prio
,
626 &pgid
, &tc_pct
, &up_map
);
629 if (param_tb
[DCB_TC_ATTR_PARAM_PGID
] ||
630 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
631 ret
= nla_put_u8(skb
,
632 DCB_TC_ATTR_PARAM_PGID
, pgid
);
636 if (param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
] ||
637 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
638 ret
= nla_put_u8(skb
,
639 DCB_TC_ATTR_PARAM_UP_MAPPING
, up_map
);
643 if (param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
] ||
644 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
645 ret
= nla_put_u8(skb
,
646 DCB_TC_ATTR_PARAM_STRICT_PRIO
, prio
);
650 if (param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
] ||
651 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
652 ret
= nla_put_u8(skb
, DCB_TC_ATTR_PARAM_BW_PCT
,
657 nla_nest_end(skb
, param_nest
);
660 if (pg_tb
[DCB_PG_ATTR_BW_ID_ALL
])
665 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
666 if (!getall
&& !pg_tb
[i
])
669 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
673 netdev
->dcbnl_ops
->getpgbwgcfgrx(netdev
,
674 i
- DCB_PG_ATTR_BW_ID_0
, &tc_pct
);
677 netdev
->dcbnl_ops
->getpgbwgcfgtx(netdev
,
678 i
- DCB_PG_ATTR_BW_ID_0
, &tc_pct
);
680 ret
= nla_put_u8(skb
, i
, tc_pct
);
685 nla_nest_end(skb
, pg_nest
);
690 nla_nest_cancel(skb
, param_nest
);
692 nla_nest_cancel(skb
, pg_nest
);
697 static int dcbnl_pgtx_getcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
698 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
700 return __dcbnl_pg_getcfg(netdev
, nlh
, tb
, skb
, 0);
703 static int dcbnl_pgrx_getcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
704 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
706 return __dcbnl_pg_getcfg(netdev
, nlh
, tb
, skb
, 1);
709 static int dcbnl_setstate(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
710 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
714 if (!tb
[DCB_ATTR_STATE
])
717 if (!netdev
->dcbnl_ops
->setstate
)
720 value
= nla_get_u8(tb
[DCB_ATTR_STATE
]);
722 return nla_put_u8(skb
, DCB_ATTR_STATE
,
723 netdev
->dcbnl_ops
->setstate(netdev
, value
));
726 static int dcbnl_setpfccfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
727 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
729 struct nlattr
*data
[DCB_PFC_UP_ATTR_MAX
+ 1];
734 if (!tb
[DCB_ATTR_PFC_CFG
])
737 if (!netdev
->dcbnl_ops
->setpfccfg
)
740 ret
= nla_parse_nested(data
, DCB_PFC_UP_ATTR_MAX
,
741 tb
[DCB_ATTR_PFC_CFG
],
746 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
749 value
= nla_get_u8(data
[i
]);
750 netdev
->dcbnl_ops
->setpfccfg(netdev
,
751 data
[i
]->nla_type
- DCB_PFC_UP_ATTR_0
, value
);
754 return nla_put_u8(skb
, DCB_ATTR_PFC_CFG
, 0);
757 static int dcbnl_setall(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
758 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
762 if (!tb
[DCB_ATTR_SET_ALL
])
765 if (!netdev
->dcbnl_ops
->setall
)
768 ret
= nla_put_u8(skb
, DCB_ATTR_SET_ALL
,
769 netdev
->dcbnl_ops
->setall(netdev
));
770 dcbnl_cee_notify(netdev
, RTM_SETDCB
, DCB_CMD_SET_ALL
, seq
, 0);
775 static int __dcbnl_pg_setcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
776 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
,
779 struct nlattr
*pg_tb
[DCB_PG_ATTR_MAX
+ 1];
780 struct nlattr
*param_tb
[DCB_TC_ATTR_PARAM_MAX
+ 1];
788 if (!tb
[DCB_ATTR_PG_CFG
])
791 if (!netdev
->dcbnl_ops
->setpgtccfgtx
||
792 !netdev
->dcbnl_ops
->setpgtccfgrx
||
793 !netdev
->dcbnl_ops
->setpgbwgcfgtx
||
794 !netdev
->dcbnl_ops
->setpgbwgcfgrx
)
797 ret
= nla_parse_nested(pg_tb
, DCB_PG_ATTR_MAX
,
798 tb
[DCB_ATTR_PG_CFG
], dcbnl_pg_nest
);
802 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
806 ret
= nla_parse_nested(param_tb
, DCB_TC_ATTR_PARAM_MAX
,
807 pg_tb
[i
], dcbnl_tc_param_nest
);
811 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
812 prio
= DCB_ATTR_VALUE_UNDEFINED
;
813 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
814 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
816 if (param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
])
818 nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
]);
820 if (param_tb
[DCB_TC_ATTR_PARAM_PGID
])
821 pgid
= nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_PGID
]);
823 if (param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
])
824 tc_pct
= nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
]);
826 if (param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
])
828 nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
]);
830 /* dir: Tx = 0, Rx = 1 */
833 netdev
->dcbnl_ops
->setpgtccfgrx(netdev
,
834 i
- DCB_PG_ATTR_TC_0
,
835 prio
, pgid
, tc_pct
, up_map
);
838 netdev
->dcbnl_ops
->setpgtccfgtx(netdev
,
839 i
- DCB_PG_ATTR_TC_0
,
840 prio
, pgid
, tc_pct
, up_map
);
844 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
848 tc_pct
= nla_get_u8(pg_tb
[i
]);
850 /* dir: Tx = 0, Rx = 1 */
853 netdev
->dcbnl_ops
->setpgbwgcfgrx(netdev
,
854 i
- DCB_PG_ATTR_BW_ID_0
, tc_pct
);
857 netdev
->dcbnl_ops
->setpgbwgcfgtx(netdev
,
858 i
- DCB_PG_ATTR_BW_ID_0
, tc_pct
);
862 return nla_put_u8(skb
, DCB_ATTR_PG_CFG
, 0);
865 static int dcbnl_pgtx_setcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
866 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
868 return __dcbnl_pg_setcfg(netdev
, nlh
, seq
, tb
, skb
, 0);
871 static int dcbnl_pgrx_setcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
872 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
874 return __dcbnl_pg_setcfg(netdev
, nlh
, seq
, tb
, skb
, 1);
877 static int dcbnl_bcn_getcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
878 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
880 struct nlattr
*bcn_nest
;
881 struct nlattr
*bcn_tb
[DCB_BCN_ATTR_MAX
+ 1];
888 if (!tb
[DCB_ATTR_BCN
])
891 if (!netdev
->dcbnl_ops
->getbcnrp
||
892 !netdev
->dcbnl_ops
->getbcncfg
)
895 ret
= nla_parse_nested(bcn_tb
, DCB_BCN_ATTR_MAX
,
896 tb
[DCB_ATTR_BCN
], dcbnl_bcn_nest
);
900 bcn_nest
= nla_nest_start(skb
, DCB_ATTR_BCN
);
904 if (bcn_tb
[DCB_BCN_ATTR_ALL
])
907 for (i
= DCB_BCN_ATTR_RP_0
; i
<= DCB_BCN_ATTR_RP_7
; i
++) {
908 if (!getall
&& !bcn_tb
[i
])
911 netdev
->dcbnl_ops
->getbcnrp(netdev
, i
- DCB_BCN_ATTR_RP_0
,
913 ret
= nla_put_u8(skb
, i
, value_byte
);
918 for (i
= DCB_BCN_ATTR_BCNA_0
; i
<= DCB_BCN_ATTR_RI
; i
++) {
919 if (!getall
&& !bcn_tb
[i
])
922 netdev
->dcbnl_ops
->getbcncfg(netdev
, i
,
924 ret
= nla_put_u32(skb
, i
, value_integer
);
929 nla_nest_end(skb
, bcn_nest
);
934 nla_nest_cancel(skb
, bcn_nest
);
938 static int dcbnl_bcn_setcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
939 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
941 struct nlattr
*data
[DCB_BCN_ATTR_MAX
+ 1];
947 if (!tb
[DCB_ATTR_BCN
])
950 if (!netdev
->dcbnl_ops
->setbcncfg
||
951 !netdev
->dcbnl_ops
->setbcnrp
)
954 ret
= nla_parse_nested(data
, DCB_BCN_ATTR_MAX
,
960 for (i
= DCB_BCN_ATTR_RP_0
; i
<= DCB_BCN_ATTR_RP_7
; i
++) {
963 value_byte
= nla_get_u8(data
[i
]);
964 netdev
->dcbnl_ops
->setbcnrp(netdev
,
965 data
[i
]->nla_type
- DCB_BCN_ATTR_RP_0
, value_byte
);
968 for (i
= DCB_BCN_ATTR_BCNA_0
; i
<= DCB_BCN_ATTR_RI
; i
++) {
971 value_int
= nla_get_u32(data
[i
]);
972 netdev
->dcbnl_ops
->setbcncfg(netdev
,
976 return nla_put_u8(skb
, DCB_ATTR_BCN
, 0);
979 static int dcbnl_build_peer_app(struct net_device
*netdev
, struct sk_buff
* skb
,
980 int app_nested_type
, int app_info_type
,
983 struct dcb_peer_app_info info
;
984 struct dcb_app
*table
= NULL
;
985 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
991 * retrieve the peer app configuration form the driver. If the driver
992 * handlers fail exit without doing anything
994 err
= ops
->peer_getappinfo(netdev
, &info
, &app_count
);
995 if (!err
&& app_count
) {
996 table
= kmalloc(sizeof(struct dcb_app
) * app_count
, GFP_KERNEL
);
1000 err
= ops
->peer_getapptable(netdev
, table
);
1008 * build the message, from here on the only possible failure
1009 * is due to the skb size
1013 app
= nla_nest_start(skb
, app_nested_type
);
1015 goto nla_put_failure
;
1017 if (app_info_type
&&
1018 nla_put(skb
, app_info_type
, sizeof(info
), &info
))
1019 goto nla_put_failure
;
1021 for (i
= 0; i
< app_count
; i
++) {
1022 if (nla_put(skb
, app_entry_type
, sizeof(struct dcb_app
),
1024 goto nla_put_failure
;
1026 nla_nest_end(skb
, app
);
1035 /* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb GET commands. */
1036 static int dcbnl_ieee_fill(struct sk_buff
*skb
, struct net_device
*netdev
)
1038 struct nlattr
*ieee
, *app
;
1039 struct dcb_app_type
*itr
;
1040 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1044 if (nla_put_string(skb
, DCB_ATTR_IFNAME
, netdev
->name
))
1047 ieee
= nla_nest_start(skb
, DCB_ATTR_IEEE
);
1051 if (ops
->ieee_getets
) {
1052 struct ieee_ets ets
;
1053 memset(&ets
, 0, sizeof(ets
));
1054 err
= ops
->ieee_getets(netdev
, &ets
);
1056 nla_put(skb
, DCB_ATTR_IEEE_ETS
, sizeof(ets
), &ets
))
1060 if (ops
->ieee_getmaxrate
) {
1061 struct ieee_maxrate maxrate
;
1062 memset(&maxrate
, 0, sizeof(maxrate
));
1063 err
= ops
->ieee_getmaxrate(netdev
, &maxrate
);
1065 err
= nla_put(skb
, DCB_ATTR_IEEE_MAXRATE
,
1066 sizeof(maxrate
), &maxrate
);
1072 if (ops
->ieee_getqcn
) {
1073 struct ieee_qcn qcn
;
1075 memset(&qcn
, 0, sizeof(qcn
));
1076 err
= ops
->ieee_getqcn(netdev
, &qcn
);
1078 err
= nla_put(skb
, DCB_ATTR_IEEE_QCN
,
1085 if (ops
->ieee_getqcnstats
) {
1086 struct ieee_qcn_stats qcn_stats
;
1088 memset(&qcn_stats
, 0, sizeof(qcn_stats
));
1089 err
= ops
->ieee_getqcnstats(netdev
, &qcn_stats
);
1091 err
= nla_put(skb
, DCB_ATTR_IEEE_QCN_STATS
,
1092 sizeof(qcn_stats
), &qcn_stats
);
1098 if (ops
->ieee_getpfc
) {
1099 struct ieee_pfc pfc
;
1100 memset(&pfc
, 0, sizeof(pfc
));
1101 err
= ops
->ieee_getpfc(netdev
, &pfc
);
1103 nla_put(skb
, DCB_ATTR_IEEE_PFC
, sizeof(pfc
), &pfc
))
1107 app
= nla_nest_start(skb
, DCB_ATTR_IEEE_APP_TABLE
);
1111 spin_lock_bh(&dcb_lock
);
1112 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1113 if (itr
->ifindex
== netdev
->ifindex
) {
1114 err
= nla_put(skb
, DCB_ATTR_IEEE_APP
, sizeof(itr
->app
),
1117 spin_unlock_bh(&dcb_lock
);
1123 if (netdev
->dcbnl_ops
->getdcbx
)
1124 dcbx
= netdev
->dcbnl_ops
->getdcbx(netdev
);
1128 spin_unlock_bh(&dcb_lock
);
1129 nla_nest_end(skb
, app
);
1131 /* get peer info if available */
1132 if (ops
->ieee_peer_getets
) {
1133 struct ieee_ets ets
;
1134 memset(&ets
, 0, sizeof(ets
));
1135 err
= ops
->ieee_peer_getets(netdev
, &ets
);
1137 nla_put(skb
, DCB_ATTR_IEEE_PEER_ETS
, sizeof(ets
), &ets
))
1141 if (ops
->ieee_peer_getpfc
) {
1142 struct ieee_pfc pfc
;
1143 memset(&pfc
, 0, sizeof(pfc
));
1144 err
= ops
->ieee_peer_getpfc(netdev
, &pfc
);
1146 nla_put(skb
, DCB_ATTR_IEEE_PEER_PFC
, sizeof(pfc
), &pfc
))
1150 if (ops
->peer_getappinfo
&& ops
->peer_getapptable
) {
1151 err
= dcbnl_build_peer_app(netdev
, skb
,
1152 DCB_ATTR_IEEE_PEER_APP
,
1153 DCB_ATTR_IEEE_APP_UNSPEC
,
1159 nla_nest_end(skb
, ieee
);
1161 err
= nla_put_u8(skb
, DCB_ATTR_DCBX
, dcbx
);
1169 static int dcbnl_cee_pg_fill(struct sk_buff
*skb
, struct net_device
*dev
,
1172 u8 pgid
, up_map
, prio
, tc_pct
;
1173 const struct dcbnl_rtnl_ops
*ops
= dev
->dcbnl_ops
;
1174 int i
= dir
? DCB_ATTR_CEE_TX_PG
: DCB_ATTR_CEE_RX_PG
;
1175 struct nlattr
*pg
= nla_nest_start(skb
, i
);
1180 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
1181 struct nlattr
*tc_nest
= nla_nest_start(skb
, i
);
1186 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
1187 prio
= DCB_ATTR_VALUE_UNDEFINED
;
1188 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
1189 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
1192 ops
->getpgtccfgrx(dev
, i
- DCB_PG_ATTR_TC_0
,
1193 &prio
, &pgid
, &tc_pct
, &up_map
);
1195 ops
->getpgtccfgtx(dev
, i
- DCB_PG_ATTR_TC_0
,
1196 &prio
, &pgid
, &tc_pct
, &up_map
);
1198 if (nla_put_u8(skb
, DCB_TC_ATTR_PARAM_PGID
, pgid
) ||
1199 nla_put_u8(skb
, DCB_TC_ATTR_PARAM_UP_MAPPING
, up_map
) ||
1200 nla_put_u8(skb
, DCB_TC_ATTR_PARAM_STRICT_PRIO
, prio
) ||
1201 nla_put_u8(skb
, DCB_TC_ATTR_PARAM_BW_PCT
, tc_pct
))
1203 nla_nest_end(skb
, tc_nest
);
1206 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
1207 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
1210 ops
->getpgbwgcfgrx(dev
, i
- DCB_PG_ATTR_BW_ID_0
,
1213 ops
->getpgbwgcfgtx(dev
, i
- DCB_PG_ATTR_BW_ID_0
,
1215 if (nla_put_u8(skb
, i
, tc_pct
))
1218 nla_nest_end(skb
, pg
);
1222 static int dcbnl_cee_fill(struct sk_buff
*skb
, struct net_device
*netdev
)
1224 struct nlattr
*cee
, *app
;
1225 struct dcb_app_type
*itr
;
1226 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1227 int dcbx
, i
, err
= -EMSGSIZE
;
1230 if (nla_put_string(skb
, DCB_ATTR_IFNAME
, netdev
->name
))
1231 goto nla_put_failure
;
1232 cee
= nla_nest_start(skb
, DCB_ATTR_CEE
);
1234 goto nla_put_failure
;
1237 if (ops
->getpgtccfgtx
&& ops
->getpgbwgcfgtx
) {
1238 err
= dcbnl_cee_pg_fill(skb
, netdev
, 1);
1240 goto nla_put_failure
;
1243 if (ops
->getpgtccfgrx
&& ops
->getpgbwgcfgrx
) {
1244 err
= dcbnl_cee_pg_fill(skb
, netdev
, 0);
1246 goto nla_put_failure
;
1250 if (ops
->getpfccfg
) {
1251 struct nlattr
*pfc_nest
= nla_nest_start(skb
, DCB_ATTR_CEE_PFC
);
1254 goto nla_put_failure
;
1256 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
1257 ops
->getpfccfg(netdev
, i
- DCB_PFC_UP_ATTR_0
, &value
);
1258 if (nla_put_u8(skb
, i
, value
))
1259 goto nla_put_failure
;
1261 nla_nest_end(skb
, pfc_nest
);
1265 spin_lock_bh(&dcb_lock
);
1266 app
= nla_nest_start(skb
, DCB_ATTR_CEE_APP_TABLE
);
1270 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1271 if (itr
->ifindex
== netdev
->ifindex
) {
1272 struct nlattr
*app_nest
= nla_nest_start(skb
,
1277 err
= nla_put_u8(skb
, DCB_APP_ATTR_IDTYPE
,
1282 err
= nla_put_u16(skb
, DCB_APP_ATTR_ID
,
1287 err
= nla_put_u8(skb
, DCB_APP_ATTR_PRIORITY
,
1292 nla_nest_end(skb
, app_nest
);
1295 nla_nest_end(skb
, app
);
1297 if (netdev
->dcbnl_ops
->getdcbx
)
1298 dcbx
= netdev
->dcbnl_ops
->getdcbx(netdev
);
1302 spin_unlock_bh(&dcb_lock
);
1304 /* features flags */
1305 if (ops
->getfeatcfg
) {
1306 struct nlattr
*feat
= nla_nest_start(skb
, DCB_ATTR_CEE_FEAT
);
1308 goto nla_put_failure
;
1310 for (i
= DCB_FEATCFG_ATTR_ALL
+ 1; i
<= DCB_FEATCFG_ATTR_MAX
;
1312 if (!ops
->getfeatcfg(netdev
, i
, &value
) &&
1313 nla_put_u8(skb
, i
, value
))
1314 goto nla_put_failure
;
1316 nla_nest_end(skb
, feat
);
1319 /* peer info if available */
1320 if (ops
->cee_peer_getpg
) {
1322 memset(&pg
, 0, sizeof(pg
));
1323 err
= ops
->cee_peer_getpg(netdev
, &pg
);
1325 nla_put(skb
, DCB_ATTR_CEE_PEER_PG
, sizeof(pg
), &pg
))
1326 goto nla_put_failure
;
1329 if (ops
->cee_peer_getpfc
) {
1331 memset(&pfc
, 0, sizeof(pfc
));
1332 err
= ops
->cee_peer_getpfc(netdev
, &pfc
);
1334 nla_put(skb
, DCB_ATTR_CEE_PEER_PFC
, sizeof(pfc
), &pfc
))
1335 goto nla_put_failure
;
1338 if (ops
->peer_getappinfo
&& ops
->peer_getapptable
) {
1339 err
= dcbnl_build_peer_app(netdev
, skb
,
1340 DCB_ATTR_CEE_PEER_APP_TABLE
,
1341 DCB_ATTR_CEE_PEER_APP_INFO
,
1342 DCB_ATTR_CEE_PEER_APP
);
1344 goto nla_put_failure
;
1346 nla_nest_end(skb
, cee
);
1350 err
= nla_put_u8(skb
, DCB_ATTR_DCBX
, dcbx
);
1352 goto nla_put_failure
;
1357 spin_unlock_bh(&dcb_lock
);
1362 static int dcbnl_notify(struct net_device
*dev
, int event
, int cmd
,
1363 u32 seq
, u32 portid
, int dcbx_ver
)
1365 struct net
*net
= dev_net(dev
);
1366 struct sk_buff
*skb
;
1367 struct nlmsghdr
*nlh
;
1368 const struct dcbnl_rtnl_ops
*ops
= dev
->dcbnl_ops
;
1374 skb
= dcbnl_newmsg(event
, cmd
, portid
, seq
, 0, &nlh
);
1378 if (dcbx_ver
== DCB_CAP_DCBX_VER_IEEE
)
1379 err
= dcbnl_ieee_fill(skb
, dev
);
1381 err
= dcbnl_cee_fill(skb
, dev
);
1384 /* Report error to broadcast listeners */
1386 rtnl_set_sk_err(net
, RTNLGRP_DCB
, err
);
1388 /* End nlmsg and notify broadcast listeners */
1389 nlmsg_end(skb
, nlh
);
1390 rtnl_notify(skb
, net
, 0, RTNLGRP_DCB
, NULL
, GFP_KERNEL
);
1396 int dcbnl_ieee_notify(struct net_device
*dev
, int event
, int cmd
,
1397 u32 seq
, u32 portid
)
1399 return dcbnl_notify(dev
, event
, cmd
, seq
, portid
, DCB_CAP_DCBX_VER_IEEE
);
1401 EXPORT_SYMBOL(dcbnl_ieee_notify
);
1403 int dcbnl_cee_notify(struct net_device
*dev
, int event
, int cmd
,
1404 u32 seq
, u32 portid
)
1406 return dcbnl_notify(dev
, event
, cmd
, seq
, portid
, DCB_CAP_DCBX_VER_CEE
);
1408 EXPORT_SYMBOL(dcbnl_cee_notify
);
1410 /* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb SET commands.
1411 * If any requested operation can not be completed
1412 * the entire msg is aborted and error value is returned.
1413 * No attempt is made to reconcile the case where only part of the
1414 * cmd can be completed.
1416 static int dcbnl_ieee_set(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1417 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1419 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1420 struct nlattr
*ieee
[DCB_ATTR_IEEE_MAX
+ 1];
1426 if (!tb
[DCB_ATTR_IEEE
])
1429 err
= nla_parse_nested(ieee
, DCB_ATTR_IEEE_MAX
,
1430 tb
[DCB_ATTR_IEEE
], dcbnl_ieee_policy
);
1434 if (ieee
[DCB_ATTR_IEEE_ETS
] && ops
->ieee_setets
) {
1435 struct ieee_ets
*ets
= nla_data(ieee
[DCB_ATTR_IEEE_ETS
]);
1436 err
= ops
->ieee_setets(netdev
, ets
);
1441 if (ieee
[DCB_ATTR_IEEE_MAXRATE
] && ops
->ieee_setmaxrate
) {
1442 struct ieee_maxrate
*maxrate
=
1443 nla_data(ieee
[DCB_ATTR_IEEE_MAXRATE
]);
1444 err
= ops
->ieee_setmaxrate(netdev
, maxrate
);
1449 if (ieee
[DCB_ATTR_IEEE_QCN
] && ops
->ieee_setqcn
) {
1450 struct ieee_qcn
*qcn
=
1451 nla_data(ieee
[DCB_ATTR_IEEE_QCN
]);
1453 err
= ops
->ieee_setqcn(netdev
, qcn
);
1458 if (ieee
[DCB_ATTR_IEEE_PFC
] && ops
->ieee_setpfc
) {
1459 struct ieee_pfc
*pfc
= nla_data(ieee
[DCB_ATTR_IEEE_PFC
]);
1460 err
= ops
->ieee_setpfc(netdev
, pfc
);
1465 if (ieee
[DCB_ATTR_IEEE_APP_TABLE
]) {
1466 struct nlattr
*attr
;
1469 nla_for_each_nested(attr
, ieee
[DCB_ATTR_IEEE_APP_TABLE
], rem
) {
1470 struct dcb_app
*app_data
;
1471 if (nla_type(attr
) != DCB_ATTR_IEEE_APP
)
1473 app_data
= nla_data(attr
);
1474 if (ops
->ieee_setapp
)
1475 err
= ops
->ieee_setapp(netdev
, app_data
);
1477 err
= dcb_ieee_setapp(netdev
, app_data
);
1484 err
= nla_put_u8(skb
, DCB_ATTR_IEEE
, err
);
1485 dcbnl_ieee_notify(netdev
, RTM_SETDCB
, DCB_CMD_IEEE_SET
, seq
, 0);
1489 static int dcbnl_ieee_get(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1490 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1492 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1497 return dcbnl_ieee_fill(skb
, netdev
);
1500 static int dcbnl_ieee_del(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1501 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1503 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1504 struct nlattr
*ieee
[DCB_ATTR_IEEE_MAX
+ 1];
1510 if (!tb
[DCB_ATTR_IEEE
])
1513 err
= nla_parse_nested(ieee
, DCB_ATTR_IEEE_MAX
,
1514 tb
[DCB_ATTR_IEEE
], dcbnl_ieee_policy
);
1518 if (ieee
[DCB_ATTR_IEEE_APP_TABLE
]) {
1519 struct nlattr
*attr
;
1522 nla_for_each_nested(attr
, ieee
[DCB_ATTR_IEEE_APP_TABLE
], rem
) {
1523 struct dcb_app
*app_data
;
1525 if (nla_type(attr
) != DCB_ATTR_IEEE_APP
)
1527 app_data
= nla_data(attr
);
1528 if (ops
->ieee_delapp
)
1529 err
= ops
->ieee_delapp(netdev
, app_data
);
1531 err
= dcb_ieee_delapp(netdev
, app_data
);
1538 err
= nla_put_u8(skb
, DCB_ATTR_IEEE
, err
);
1539 dcbnl_ieee_notify(netdev
, RTM_SETDCB
, DCB_CMD_IEEE_DEL
, seq
, 0);
1544 /* DCBX configuration */
1545 static int dcbnl_getdcbx(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1546 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1548 if (!netdev
->dcbnl_ops
->getdcbx
)
1551 return nla_put_u8(skb
, DCB_ATTR_DCBX
,
1552 netdev
->dcbnl_ops
->getdcbx(netdev
));
1555 static int dcbnl_setdcbx(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1556 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1560 if (!netdev
->dcbnl_ops
->setdcbx
)
1563 if (!tb
[DCB_ATTR_DCBX
])
1566 value
= nla_get_u8(tb
[DCB_ATTR_DCBX
]);
1568 return nla_put_u8(skb
, DCB_ATTR_DCBX
,
1569 netdev
->dcbnl_ops
->setdcbx(netdev
, value
));
1572 static int dcbnl_getfeatcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1573 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1575 struct nlattr
*data
[DCB_FEATCFG_ATTR_MAX
+ 1], *nest
;
1580 if (!netdev
->dcbnl_ops
->getfeatcfg
)
1583 if (!tb
[DCB_ATTR_FEATCFG
])
1586 ret
= nla_parse_nested(data
, DCB_FEATCFG_ATTR_MAX
, tb
[DCB_ATTR_FEATCFG
],
1587 dcbnl_featcfg_nest
);
1591 nest
= nla_nest_start(skb
, DCB_ATTR_FEATCFG
);
1595 if (data
[DCB_FEATCFG_ATTR_ALL
])
1598 for (i
= DCB_FEATCFG_ATTR_ALL
+1; i
<= DCB_FEATCFG_ATTR_MAX
; i
++) {
1599 if (!getall
&& !data
[i
])
1602 ret
= netdev
->dcbnl_ops
->getfeatcfg(netdev
, i
, &value
);
1604 ret
= nla_put_u8(skb
, i
, value
);
1607 nla_nest_cancel(skb
, nest
);
1608 goto nla_put_failure
;
1611 nla_nest_end(skb
, nest
);
1617 static int dcbnl_setfeatcfg(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1618 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1620 struct nlattr
*data
[DCB_FEATCFG_ATTR_MAX
+ 1];
1624 if (!netdev
->dcbnl_ops
->setfeatcfg
)
1627 if (!tb
[DCB_ATTR_FEATCFG
])
1630 ret
= nla_parse_nested(data
, DCB_FEATCFG_ATTR_MAX
, tb
[DCB_ATTR_FEATCFG
],
1631 dcbnl_featcfg_nest
);
1636 for (i
= DCB_FEATCFG_ATTR_ALL
+1; i
<= DCB_FEATCFG_ATTR_MAX
; i
++) {
1637 if (data
[i
] == NULL
)
1640 value
= nla_get_u8(data
[i
]);
1642 ret
= netdev
->dcbnl_ops
->setfeatcfg(netdev
, i
, value
);
1648 ret
= nla_put_u8(skb
, DCB_ATTR_FEATCFG
, ret
);
1653 /* Handle CEE DCBX GET commands. */
1654 static int dcbnl_cee_get(struct net_device
*netdev
, struct nlmsghdr
*nlh
,
1655 u32 seq
, struct nlattr
**tb
, struct sk_buff
*skb
)
1657 const struct dcbnl_rtnl_ops
*ops
= netdev
->dcbnl_ops
;
1662 return dcbnl_cee_fill(skb
, netdev
);
1666 /* reply netlink message type */
1669 /* function to fill message contents */
1670 int (*cb
)(struct net_device
*, struct nlmsghdr
*, u32
,
1671 struct nlattr
**, struct sk_buff
*);
1674 static const struct reply_func reply_funcs
[DCB_CMD_MAX
+1] = {
1675 [DCB_CMD_GSTATE
] = { RTM_GETDCB
, dcbnl_getstate
},
1676 [DCB_CMD_SSTATE
] = { RTM_SETDCB
, dcbnl_setstate
},
1677 [DCB_CMD_PFC_GCFG
] = { RTM_GETDCB
, dcbnl_getpfccfg
},
1678 [DCB_CMD_PFC_SCFG
] = { RTM_SETDCB
, dcbnl_setpfccfg
},
1679 [DCB_CMD_GPERM_HWADDR
] = { RTM_GETDCB
, dcbnl_getperm_hwaddr
},
1680 [DCB_CMD_GCAP
] = { RTM_GETDCB
, dcbnl_getcap
},
1681 [DCB_CMD_GNUMTCS
] = { RTM_GETDCB
, dcbnl_getnumtcs
},
1682 [DCB_CMD_SNUMTCS
] = { RTM_SETDCB
, dcbnl_setnumtcs
},
1683 [DCB_CMD_PFC_GSTATE
] = { RTM_GETDCB
, dcbnl_getpfcstate
},
1684 [DCB_CMD_PFC_SSTATE
] = { RTM_SETDCB
, dcbnl_setpfcstate
},
1685 [DCB_CMD_GAPP
] = { RTM_GETDCB
, dcbnl_getapp
},
1686 [DCB_CMD_SAPP
] = { RTM_SETDCB
, dcbnl_setapp
},
1687 [DCB_CMD_PGTX_GCFG
] = { RTM_GETDCB
, dcbnl_pgtx_getcfg
},
1688 [DCB_CMD_PGTX_SCFG
] = { RTM_SETDCB
, dcbnl_pgtx_setcfg
},
1689 [DCB_CMD_PGRX_GCFG
] = { RTM_GETDCB
, dcbnl_pgrx_getcfg
},
1690 [DCB_CMD_PGRX_SCFG
] = { RTM_SETDCB
, dcbnl_pgrx_setcfg
},
1691 [DCB_CMD_SET_ALL
] = { RTM_SETDCB
, dcbnl_setall
},
1692 [DCB_CMD_BCN_GCFG
] = { RTM_GETDCB
, dcbnl_bcn_getcfg
},
1693 [DCB_CMD_BCN_SCFG
] = { RTM_SETDCB
, dcbnl_bcn_setcfg
},
1694 [DCB_CMD_IEEE_GET
] = { RTM_GETDCB
, dcbnl_ieee_get
},
1695 [DCB_CMD_IEEE_SET
] = { RTM_SETDCB
, dcbnl_ieee_set
},
1696 [DCB_CMD_IEEE_DEL
] = { RTM_SETDCB
, dcbnl_ieee_del
},
1697 [DCB_CMD_GDCBX
] = { RTM_GETDCB
, dcbnl_getdcbx
},
1698 [DCB_CMD_SDCBX
] = { RTM_SETDCB
, dcbnl_setdcbx
},
1699 [DCB_CMD_GFEATCFG
] = { RTM_GETDCB
, dcbnl_getfeatcfg
},
1700 [DCB_CMD_SFEATCFG
] = { RTM_SETDCB
, dcbnl_setfeatcfg
},
1701 [DCB_CMD_CEE_GET
] = { RTM_GETDCB
, dcbnl_cee_get
},
1704 static int dcb_doit(struct sk_buff
*skb
, struct nlmsghdr
*nlh
)
1706 struct net
*net
= sock_net(skb
->sk
);
1707 struct net_device
*netdev
;
1708 struct dcbmsg
*dcb
= nlmsg_data(nlh
);
1709 struct nlattr
*tb
[DCB_ATTR_MAX
+ 1];
1710 u32 portid
= skb
? NETLINK_CB(skb
).portid
: 0;
1712 struct sk_buff
*reply_skb
;
1713 struct nlmsghdr
*reply_nlh
= NULL
;
1714 const struct reply_func
*fn
;
1716 if ((nlh
->nlmsg_type
== RTM_SETDCB
) && !netlink_capable(skb
, CAP_NET_ADMIN
))
1719 ret
= nlmsg_parse(nlh
, sizeof(*dcb
), tb
, DCB_ATTR_MAX
,
1724 if (dcb
->cmd
> DCB_CMD_MAX
)
1727 /* check if a reply function has been defined for the command */
1728 fn
= &reply_funcs
[dcb
->cmd
];
1732 if (!tb
[DCB_ATTR_IFNAME
])
1735 netdev
= __dev_get_by_name(net
, nla_data(tb
[DCB_ATTR_IFNAME
]));
1739 if (!netdev
->dcbnl_ops
)
1742 reply_skb
= dcbnl_newmsg(fn
->type
, dcb
->cmd
, portid
, nlh
->nlmsg_seq
,
1743 nlh
->nlmsg_flags
, &reply_nlh
);
1747 ret
= fn
->cb(netdev
, nlh
, nlh
->nlmsg_seq
, tb
, reply_skb
);
1749 nlmsg_free(reply_skb
);
1753 nlmsg_end(reply_skb
, reply_nlh
);
1755 ret
= rtnl_unicast(reply_skb
, net
, portid
);
1760 static struct dcb_app_type
*dcb_app_lookup(const struct dcb_app
*app
,
1761 int ifindex
, int prio
)
1763 struct dcb_app_type
*itr
;
1765 list_for_each_entry(itr
, &dcb_app_list
, list
) {
1766 if (itr
->app
.selector
== app
->selector
&&
1767 itr
->app
.protocol
== app
->protocol
&&
1768 itr
->ifindex
== ifindex
&&
1769 (!prio
|| itr
->app
.priority
== prio
))
1776 static int dcb_app_add(const struct dcb_app
*app
, int ifindex
)
1778 struct dcb_app_type
*entry
;
1780 entry
= kmalloc(sizeof(*entry
), GFP_ATOMIC
);
1784 memcpy(&entry
->app
, app
, sizeof(*app
));
1785 entry
->ifindex
= ifindex
;
1786 list_add(&entry
->list
, &dcb_app_list
);
1792 * dcb_getapp - retrieve the DCBX application user priority
1794 * On success returns a non-zero 802.1p user priority bitmap
1795 * otherwise returns 0 as the invalid user priority bitmap to
1796 * indicate an error.
1798 u8
dcb_getapp(struct net_device
*dev
, struct dcb_app
*app
)
1800 struct dcb_app_type
*itr
;
1803 spin_lock_bh(&dcb_lock
);
1804 if ((itr
= dcb_app_lookup(app
, dev
->ifindex
, 0)))
1805 prio
= itr
->app
.priority
;
1806 spin_unlock_bh(&dcb_lock
);
1810 EXPORT_SYMBOL(dcb_getapp
);
1813 * dcb_setapp - add CEE dcb application data to app list
1815 * Priority 0 is an invalid priority in CEE spec. This routine
1816 * removes applications from the app list if the priority is
1817 * set to zero. Priority is expected to be 8-bit 802.1p user priority bitmap
1819 int dcb_setapp(struct net_device
*dev
, struct dcb_app
*new)
1821 struct dcb_app_type
*itr
;
1822 struct dcb_app_type event
;
1825 event
.ifindex
= dev
->ifindex
;
1826 memcpy(&event
.app
, new, sizeof(event
.app
));
1827 if (dev
->dcbnl_ops
->getdcbx
)
1828 event
.dcbx
= dev
->dcbnl_ops
->getdcbx(dev
);
1830 spin_lock_bh(&dcb_lock
);
1831 /* Search for existing match and replace */
1832 if ((itr
= dcb_app_lookup(new, dev
->ifindex
, 0))) {
1834 itr
->app
.priority
= new->priority
;
1836 list_del(&itr
->list
);
1841 /* App type does not exist add new application type */
1843 err
= dcb_app_add(new, dev
->ifindex
);
1845 spin_unlock_bh(&dcb_lock
);
1847 call_dcbevent_notifiers(DCB_APP_EVENT
, &event
);
1850 EXPORT_SYMBOL(dcb_setapp
);
1853 * dcb_ieee_getapp_mask - retrieve the IEEE DCB application priority
1855 * Helper routine which on success returns a non-zero 802.1Qaz user
1856 * priority bitmap otherwise returns 0 to indicate the dcb_app was
1857 * not found in APP list.
1859 u8
dcb_ieee_getapp_mask(struct net_device
*dev
, struct dcb_app
*app
)
1861 struct dcb_app_type
*itr
;
1864 spin_lock_bh(&dcb_lock
);
1865 if ((itr
= dcb_app_lookup(app
, dev
->ifindex
, 0)))
1866 prio
|= 1 << itr
->app
.priority
;
1867 spin_unlock_bh(&dcb_lock
);
1871 EXPORT_SYMBOL(dcb_ieee_getapp_mask
);
1874 * dcb_ieee_setapp - add IEEE dcb application data to app list
1876 * This adds Application data to the list. Multiple application
1877 * entries may exists for the same selector and protocol as long
1878 * as the priorities are different. Priority is expected to be a
1879 * 3-bit unsigned integer
1881 int dcb_ieee_setapp(struct net_device
*dev
, struct dcb_app
*new)
1883 struct dcb_app_type event
;
1886 event
.ifindex
= dev
->ifindex
;
1887 memcpy(&event
.app
, new, sizeof(event
.app
));
1888 if (dev
->dcbnl_ops
->getdcbx
)
1889 event
.dcbx
= dev
->dcbnl_ops
->getdcbx(dev
);
1891 spin_lock_bh(&dcb_lock
);
1892 /* Search for existing match and abort if found */
1893 if (dcb_app_lookup(new, dev
->ifindex
, new->priority
)) {
1898 err
= dcb_app_add(new, dev
->ifindex
);
1900 spin_unlock_bh(&dcb_lock
);
1902 call_dcbevent_notifiers(DCB_APP_EVENT
, &event
);
1905 EXPORT_SYMBOL(dcb_ieee_setapp
);
1908 * dcb_ieee_delapp - delete IEEE dcb application data from list
1910 * This removes a matching APP data from the APP list
1912 int dcb_ieee_delapp(struct net_device
*dev
, struct dcb_app
*del
)
1914 struct dcb_app_type
*itr
;
1915 struct dcb_app_type event
;
1918 event
.ifindex
= dev
->ifindex
;
1919 memcpy(&event
.app
, del
, sizeof(event
.app
));
1920 if (dev
->dcbnl_ops
->getdcbx
)
1921 event
.dcbx
= dev
->dcbnl_ops
->getdcbx(dev
);
1923 spin_lock_bh(&dcb_lock
);
1924 /* Search for existing match and remove it. */
1925 if ((itr
= dcb_app_lookup(del
, dev
->ifindex
, del
->priority
))) {
1926 list_del(&itr
->list
);
1931 spin_unlock_bh(&dcb_lock
);
1933 call_dcbevent_notifiers(DCB_APP_EVENT
, &event
);
1936 EXPORT_SYMBOL(dcb_ieee_delapp
);
1938 static void dcb_flushapp(void)
1940 struct dcb_app_type
*app
;
1941 struct dcb_app_type
*tmp
;
1943 spin_lock_bh(&dcb_lock
);
1944 list_for_each_entry_safe(app
, tmp
, &dcb_app_list
, list
) {
1945 list_del(&app
->list
);
1948 spin_unlock_bh(&dcb_lock
);
1951 static int __init
dcbnl_init(void)
1953 INIT_LIST_HEAD(&dcb_app_list
);
1955 rtnl_register(PF_UNSPEC
, RTM_GETDCB
, dcb_doit
, NULL
, NULL
);
1956 rtnl_register(PF_UNSPEC
, RTM_SETDCB
, dcb_doit
, NULL
, NULL
);
1960 module_init(dcbnl_init
);
1962 static void __exit
dcbnl_exit(void)
1964 rtnl_unregister(PF_UNSPEC
, RTM_GETDCB
);
1965 rtnl_unregister(PF_UNSPEC
, RTM_SETDCB
);
1968 module_exit(dcbnl_exit
);