2 * Copyright (c) 2008, 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 <net/netlink.h>
23 #include <net/rtnetlink.h>
24 #include <linux/dcbnl.h>
25 #include <linux/rtnetlink.h>
29 * Data Center Bridging (DCB) is a collection of Ethernet enhancements
30 * intended to allow network traffic with differing requirements
31 * (highly reliable, no drops vs. best effort vs. low latency) to operate
32 * and co-exist on Ethernet. Current DCB features are:
34 * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a
35 * framework for assigning bandwidth guarantees to traffic classes.
37 * Priority-based Flow Control (PFC) - provides a flow control mechanism which
38 * can work independently for each 802.1p priority.
40 * Congestion Notification - provides a mechanism for end-to-end congestion
41 * control for protocols which do not have built-in congestion management.
43 * More information about the emerging standards for these Ethernet features
44 * can be found at: http://www.ieee802.org/1/pages/dcbridges.html
46 * This file implements an rtnetlink interface to allow configuration of DCB
47 * features for capable devices.
50 MODULE_AUTHOR("Lucy Liu, <lucy.liu@intel.com>");
51 MODULE_DESCRIPTION("Data Center Bridging netlink interface");
52 MODULE_LICENSE("GPL");
54 /**************** DCB attribute policies *************************************/
56 /* DCB netlink attributes policy */
57 static struct nla_policy dcbnl_rtnl_policy
[DCB_ATTR_MAX
+ 1] = {
58 [DCB_ATTR_IFNAME
] = {.type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
- 1},
59 [DCB_ATTR_STATE
] = {.type
= NLA_U8
},
60 [DCB_ATTR_PFC_CFG
] = {.type
= NLA_NESTED
},
61 [DCB_ATTR_PG_CFG
] = {.type
= NLA_NESTED
},
62 [DCB_ATTR_SET_ALL
] = {.type
= NLA_U8
},
63 [DCB_ATTR_PERM_HWADDR
] = {.type
= NLA_FLAG
},
64 [DCB_ATTR_CAP
] = {.type
= NLA_NESTED
},
65 [DCB_ATTR_PFC_STATE
] = {.type
= NLA_U8
},
66 [DCB_ATTR_BCN
] = {.type
= NLA_NESTED
},
67 [DCB_ATTR_APP
] = {.type
= NLA_NESTED
},
70 /* DCB priority flow control to User Priority nested attributes */
71 static struct nla_policy dcbnl_pfc_up_nest
[DCB_PFC_UP_ATTR_MAX
+ 1] = {
72 [DCB_PFC_UP_ATTR_0
] = {.type
= NLA_U8
},
73 [DCB_PFC_UP_ATTR_1
] = {.type
= NLA_U8
},
74 [DCB_PFC_UP_ATTR_2
] = {.type
= NLA_U8
},
75 [DCB_PFC_UP_ATTR_3
] = {.type
= NLA_U8
},
76 [DCB_PFC_UP_ATTR_4
] = {.type
= NLA_U8
},
77 [DCB_PFC_UP_ATTR_5
] = {.type
= NLA_U8
},
78 [DCB_PFC_UP_ATTR_6
] = {.type
= NLA_U8
},
79 [DCB_PFC_UP_ATTR_7
] = {.type
= NLA_U8
},
80 [DCB_PFC_UP_ATTR_ALL
] = {.type
= NLA_FLAG
},
83 /* DCB priority grouping nested attributes */
84 static struct nla_policy dcbnl_pg_nest
[DCB_PG_ATTR_MAX
+ 1] = {
85 [DCB_PG_ATTR_TC_0
] = {.type
= NLA_NESTED
},
86 [DCB_PG_ATTR_TC_1
] = {.type
= NLA_NESTED
},
87 [DCB_PG_ATTR_TC_2
] = {.type
= NLA_NESTED
},
88 [DCB_PG_ATTR_TC_3
] = {.type
= NLA_NESTED
},
89 [DCB_PG_ATTR_TC_4
] = {.type
= NLA_NESTED
},
90 [DCB_PG_ATTR_TC_5
] = {.type
= NLA_NESTED
},
91 [DCB_PG_ATTR_TC_6
] = {.type
= NLA_NESTED
},
92 [DCB_PG_ATTR_TC_7
] = {.type
= NLA_NESTED
},
93 [DCB_PG_ATTR_TC_ALL
] = {.type
= NLA_NESTED
},
94 [DCB_PG_ATTR_BW_ID_0
] = {.type
= NLA_U8
},
95 [DCB_PG_ATTR_BW_ID_1
] = {.type
= NLA_U8
},
96 [DCB_PG_ATTR_BW_ID_2
] = {.type
= NLA_U8
},
97 [DCB_PG_ATTR_BW_ID_3
] = {.type
= NLA_U8
},
98 [DCB_PG_ATTR_BW_ID_4
] = {.type
= NLA_U8
},
99 [DCB_PG_ATTR_BW_ID_5
] = {.type
= NLA_U8
},
100 [DCB_PG_ATTR_BW_ID_6
] = {.type
= NLA_U8
},
101 [DCB_PG_ATTR_BW_ID_7
] = {.type
= NLA_U8
},
102 [DCB_PG_ATTR_BW_ID_ALL
] = {.type
= NLA_FLAG
},
105 /* DCB traffic class nested attributes. */
106 static struct nla_policy dcbnl_tc_param_nest
[DCB_TC_ATTR_PARAM_MAX
+ 1] = {
107 [DCB_TC_ATTR_PARAM_PGID
] = {.type
= NLA_U8
},
108 [DCB_TC_ATTR_PARAM_UP_MAPPING
] = {.type
= NLA_U8
},
109 [DCB_TC_ATTR_PARAM_STRICT_PRIO
] = {.type
= NLA_U8
},
110 [DCB_TC_ATTR_PARAM_BW_PCT
] = {.type
= NLA_U8
},
111 [DCB_TC_ATTR_PARAM_ALL
] = {.type
= NLA_FLAG
},
114 /* DCB capabilities nested attributes. */
115 static struct nla_policy dcbnl_cap_nest
[DCB_CAP_ATTR_MAX
+ 1] = {
116 [DCB_CAP_ATTR_ALL
] = {.type
= NLA_FLAG
},
117 [DCB_CAP_ATTR_PG
] = {.type
= NLA_U8
},
118 [DCB_CAP_ATTR_PFC
] = {.type
= NLA_U8
},
119 [DCB_CAP_ATTR_UP2TC
] = {.type
= NLA_U8
},
120 [DCB_CAP_ATTR_PG_TCS
] = {.type
= NLA_U8
},
121 [DCB_CAP_ATTR_PFC_TCS
] = {.type
= NLA_U8
},
122 [DCB_CAP_ATTR_GSP
] = {.type
= NLA_U8
},
123 [DCB_CAP_ATTR_BCN
] = {.type
= NLA_U8
},
126 /* DCB capabilities nested attributes. */
127 static struct nla_policy dcbnl_numtcs_nest
[DCB_NUMTCS_ATTR_MAX
+ 1] = {
128 [DCB_NUMTCS_ATTR_ALL
] = {.type
= NLA_FLAG
},
129 [DCB_NUMTCS_ATTR_PG
] = {.type
= NLA_U8
},
130 [DCB_NUMTCS_ATTR_PFC
] = {.type
= NLA_U8
},
133 /* DCB BCN nested attributes. */
134 static struct nla_policy dcbnl_bcn_nest
[DCB_BCN_ATTR_MAX
+ 1] = {
135 [DCB_BCN_ATTR_RP_0
] = {.type
= NLA_U8
},
136 [DCB_BCN_ATTR_RP_1
] = {.type
= NLA_U8
},
137 [DCB_BCN_ATTR_RP_2
] = {.type
= NLA_U8
},
138 [DCB_BCN_ATTR_RP_3
] = {.type
= NLA_U8
},
139 [DCB_BCN_ATTR_RP_4
] = {.type
= NLA_U8
},
140 [DCB_BCN_ATTR_RP_5
] = {.type
= NLA_U8
},
141 [DCB_BCN_ATTR_RP_6
] = {.type
= NLA_U8
},
142 [DCB_BCN_ATTR_RP_7
] = {.type
= NLA_U8
},
143 [DCB_BCN_ATTR_RP_ALL
] = {.type
= NLA_FLAG
},
144 [DCB_BCN_ATTR_BCNA_0
] = {.type
= NLA_U32
},
145 [DCB_BCN_ATTR_BCNA_1
] = {.type
= NLA_U32
},
146 [DCB_BCN_ATTR_ALPHA
] = {.type
= NLA_U32
},
147 [DCB_BCN_ATTR_BETA
] = {.type
= NLA_U32
},
148 [DCB_BCN_ATTR_GD
] = {.type
= NLA_U32
},
149 [DCB_BCN_ATTR_GI
] = {.type
= NLA_U32
},
150 [DCB_BCN_ATTR_TMAX
] = {.type
= NLA_U32
},
151 [DCB_BCN_ATTR_TD
] = {.type
= NLA_U32
},
152 [DCB_BCN_ATTR_RMIN
] = {.type
= NLA_U32
},
153 [DCB_BCN_ATTR_W
] = {.type
= NLA_U32
},
154 [DCB_BCN_ATTR_RD
] = {.type
= NLA_U32
},
155 [DCB_BCN_ATTR_RU
] = {.type
= NLA_U32
},
156 [DCB_BCN_ATTR_WRTT
] = {.type
= NLA_U32
},
157 [DCB_BCN_ATTR_RI
] = {.type
= NLA_U32
},
158 [DCB_BCN_ATTR_C
] = {.type
= NLA_U32
},
159 [DCB_BCN_ATTR_ALL
] = {.type
= NLA_FLAG
},
162 /* DCB APP nested attributes. */
163 static struct nla_policy dcbnl_app_nest
[DCB_APP_ATTR_MAX
+ 1] = {
164 [DCB_APP_ATTR_IDTYPE
] = {.type
= NLA_U8
},
165 [DCB_APP_ATTR_ID
] = {.type
= NLA_U16
},
166 [DCB_APP_ATTR_PRIORITY
] = {.type
= NLA_U8
},
169 /* standard netlink reply call */
170 static int dcbnl_reply(u8 value
, u8 event
, u8 cmd
, u8 attr
, u32 pid
,
173 struct sk_buff
*dcbnl_skb
;
175 struct nlmsghdr
*nlh
;
178 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
182 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, event
, sizeof(*dcb
), flags
);
184 dcb
= NLMSG_DATA(nlh
);
185 dcb
->dcb_family
= AF_UNSPEC
;
189 ret
= nla_put_u8(dcbnl_skb
, attr
, value
);
193 /* end the message, assign the nlmsg_len. */
194 nlmsg_end(dcbnl_skb
, nlh
);
195 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
202 kfree_skb(dcbnl_skb
);
206 static int dcbnl_getstate(struct net_device
*netdev
, struct nlattr
**tb
,
207 u32 pid
, u32 seq
, u16 flags
)
211 /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
212 if (!netdev
->dcbnl_ops
->getstate
)
215 ret
= dcbnl_reply(netdev
->dcbnl_ops
->getstate(netdev
), RTM_GETDCB
,
216 DCB_CMD_GSTATE
, DCB_ATTR_STATE
, pid
, seq
, flags
);
221 static int dcbnl_getpfccfg(struct net_device
*netdev
, struct nlattr
**tb
,
222 u32 pid
, u32 seq
, u16 flags
)
224 struct sk_buff
*dcbnl_skb
;
225 struct nlmsghdr
*nlh
;
227 struct nlattr
*data
[DCB_PFC_UP_ATTR_MAX
+ 1], *nest
;
233 if (!tb
[DCB_ATTR_PFC_CFG
] || !netdev
->dcbnl_ops
->getpfccfg
)
236 ret
= nla_parse_nested(data
, DCB_PFC_UP_ATTR_MAX
,
237 tb
[DCB_ATTR_PFC_CFG
],
242 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
246 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
248 dcb
= NLMSG_DATA(nlh
);
249 dcb
->dcb_family
= AF_UNSPEC
;
250 dcb
->cmd
= DCB_CMD_PFC_GCFG
;
252 nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_PFC_CFG
);
256 if (data
[DCB_PFC_UP_ATTR_ALL
])
259 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
260 if (!getall
&& !data
[i
])
263 netdev
->dcbnl_ops
->getpfccfg(netdev
, i
- DCB_PFC_UP_ATTR_0
,
265 ret
= nla_put_u8(dcbnl_skb
, i
, value
);
268 nla_nest_cancel(dcbnl_skb
, nest
);
272 nla_nest_end(dcbnl_skb
, nest
);
274 nlmsg_end(dcbnl_skb
, nlh
);
276 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
283 kfree_skb(dcbnl_skb
);
288 static int dcbnl_getperm_hwaddr(struct net_device
*netdev
, struct nlattr
**tb
,
289 u32 pid
, u32 seq
, u16 flags
)
291 struct sk_buff
*dcbnl_skb
;
292 struct nlmsghdr
*nlh
;
294 u8 perm_addr
[MAX_ADDR_LEN
];
297 if (!netdev
->dcbnl_ops
->getpermhwaddr
)
300 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
304 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
306 dcb
= NLMSG_DATA(nlh
);
307 dcb
->dcb_family
= AF_UNSPEC
;
308 dcb
->cmd
= DCB_CMD_GPERM_HWADDR
;
310 netdev
->dcbnl_ops
->getpermhwaddr(netdev
, perm_addr
);
312 ret
= nla_put(dcbnl_skb
, DCB_ATTR_PERM_HWADDR
, sizeof(perm_addr
),
315 nlmsg_end(dcbnl_skb
, nlh
);
317 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
324 kfree_skb(dcbnl_skb
);
329 static int dcbnl_getcap(struct net_device
*netdev
, struct nlattr
**tb
,
330 u32 pid
, u32 seq
, u16 flags
)
332 struct sk_buff
*dcbnl_skb
;
333 struct nlmsghdr
*nlh
;
335 struct nlattr
*data
[DCB_CAP_ATTR_MAX
+ 1], *nest
;
341 if (!tb
[DCB_ATTR_CAP
] || !netdev
->dcbnl_ops
->getcap
)
344 ret
= nla_parse_nested(data
, DCB_CAP_ATTR_MAX
, tb
[DCB_ATTR_CAP
],
349 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
353 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
355 dcb
= NLMSG_DATA(nlh
);
356 dcb
->dcb_family
= AF_UNSPEC
;
357 dcb
->cmd
= DCB_CMD_GCAP
;
359 nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_CAP
);
363 if (data
[DCB_CAP_ATTR_ALL
])
366 for (i
= DCB_CAP_ATTR_ALL
+1; i
<= DCB_CAP_ATTR_MAX
; i
++) {
367 if (!getall
&& !data
[i
])
370 if (!netdev
->dcbnl_ops
->getcap(netdev
, i
, &value
)) {
371 ret
= nla_put_u8(dcbnl_skb
, i
, value
);
374 nla_nest_cancel(dcbnl_skb
, nest
);
379 nla_nest_end(dcbnl_skb
, nest
);
381 nlmsg_end(dcbnl_skb
, nlh
);
383 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
390 kfree_skb(dcbnl_skb
);
395 static int dcbnl_getnumtcs(struct net_device
*netdev
, struct nlattr
**tb
,
396 u32 pid
, u32 seq
, u16 flags
)
398 struct sk_buff
*dcbnl_skb
;
399 struct nlmsghdr
*nlh
;
401 struct nlattr
*data
[DCB_NUMTCS_ATTR_MAX
+ 1], *nest
;
407 if (!tb
[DCB_ATTR_NUMTCS
] || !netdev
->dcbnl_ops
->getnumtcs
)
410 ret
= nla_parse_nested(data
, DCB_NUMTCS_ATTR_MAX
, tb
[DCB_ATTR_NUMTCS
],
417 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
423 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
425 dcb
= NLMSG_DATA(nlh
);
426 dcb
->dcb_family
= AF_UNSPEC
;
427 dcb
->cmd
= DCB_CMD_GNUMTCS
;
429 nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_NUMTCS
);
435 if (data
[DCB_NUMTCS_ATTR_ALL
])
438 for (i
= DCB_NUMTCS_ATTR_ALL
+1; i
<= DCB_NUMTCS_ATTR_MAX
; i
++) {
439 if (!getall
&& !data
[i
])
442 ret
= netdev
->dcbnl_ops
->getnumtcs(netdev
, i
, &value
);
444 ret
= nla_put_u8(dcbnl_skb
, i
, value
);
447 nla_nest_cancel(dcbnl_skb
, nest
);
455 nla_nest_end(dcbnl_skb
, nest
);
457 nlmsg_end(dcbnl_skb
, nlh
);
459 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
468 kfree_skb(dcbnl_skb
);
473 static int dcbnl_setnumtcs(struct net_device
*netdev
, struct nlattr
**tb
,
474 u32 pid
, u32 seq
, u16 flags
)
476 struct nlattr
*data
[DCB_NUMTCS_ATTR_MAX
+ 1];
481 if (!tb
[DCB_ATTR_NUMTCS
] || !netdev
->dcbnl_ops
->setnumtcs
)
484 ret
= nla_parse_nested(data
, DCB_NUMTCS_ATTR_MAX
, tb
[DCB_ATTR_NUMTCS
],
492 for (i
= DCB_NUMTCS_ATTR_ALL
+1; i
<= DCB_NUMTCS_ATTR_MAX
; i
++) {
496 value
= nla_get_u8(data
[i
]);
498 ret
= netdev
->dcbnl_ops
->setnumtcs(netdev
, i
, value
);
505 ret
= dcbnl_reply(!!ret
, RTM_SETDCB
, DCB_CMD_SNUMTCS
,
506 DCB_ATTR_NUMTCS
, pid
, seq
, flags
);
512 static int dcbnl_getpfcstate(struct net_device
*netdev
, struct nlattr
**tb
,
513 u32 pid
, u32 seq
, u16 flags
)
517 if (!netdev
->dcbnl_ops
->getpfcstate
)
520 ret
= dcbnl_reply(netdev
->dcbnl_ops
->getpfcstate(netdev
), RTM_GETDCB
,
521 DCB_CMD_PFC_GSTATE
, DCB_ATTR_PFC_STATE
,
527 static int dcbnl_setpfcstate(struct net_device
*netdev
, struct nlattr
**tb
,
528 u32 pid
, u32 seq
, u16 flags
)
533 if (!tb
[DCB_ATTR_PFC_STATE
] || !netdev
->dcbnl_ops
->setpfcstate
)
536 value
= nla_get_u8(tb
[DCB_ATTR_PFC_STATE
]);
538 netdev
->dcbnl_ops
->setpfcstate(netdev
, value
);
540 ret
= dcbnl_reply(0, RTM_SETDCB
, DCB_CMD_PFC_SSTATE
, DCB_ATTR_PFC_STATE
,
546 static int dcbnl_getapp(struct net_device
*netdev
, struct nlattr
**tb
,
547 u32 pid
, u32 seq
, u16 flags
)
549 struct sk_buff
*dcbnl_skb
;
550 struct nlmsghdr
*nlh
;
552 struct nlattr
*app_nest
;
553 struct nlattr
*app_tb
[DCB_APP_ATTR_MAX
+ 1];
558 if (!tb
[DCB_ATTR_APP
] || !netdev
->dcbnl_ops
->getapp
)
561 ret
= nla_parse_nested(app_tb
, DCB_APP_ATTR_MAX
, tb
[DCB_ATTR_APP
],
567 /* all must be non-null */
568 if ((!app_tb
[DCB_APP_ATTR_IDTYPE
]) ||
569 (!app_tb
[DCB_APP_ATTR_ID
]))
572 /* either by eth type or by socket number */
573 idtype
= nla_get_u8(app_tb
[DCB_APP_ATTR_IDTYPE
]);
574 if ((idtype
!= DCB_APP_IDTYPE_ETHTYPE
) &&
575 (idtype
!= DCB_APP_IDTYPE_PORTNUM
))
578 id
= nla_get_u16(app_tb
[DCB_APP_ATTR_ID
]);
579 up
= netdev
->dcbnl_ops
->getapp(netdev
, idtype
, id
);
582 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
586 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
587 dcb
= NLMSG_DATA(nlh
);
588 dcb
->dcb_family
= AF_UNSPEC
;
589 dcb
->cmd
= DCB_CMD_GAPP
;
591 app_nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_APP
);
592 ret
= nla_put_u8(dcbnl_skb
, DCB_APP_ATTR_IDTYPE
, idtype
);
596 ret
= nla_put_u16(dcbnl_skb
, DCB_APP_ATTR_ID
, id
);
600 ret
= nla_put_u8(dcbnl_skb
, DCB_APP_ATTR_PRIORITY
, up
);
604 nla_nest_end(dcbnl_skb
, app_nest
);
605 nlmsg_end(dcbnl_skb
, nlh
);
607 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
614 nla_nest_cancel(dcbnl_skb
, app_nest
);
616 kfree_skb(dcbnl_skb
);
621 static int dcbnl_setapp(struct net_device
*netdev
, struct nlattr
**tb
,
622 u32 pid
, u32 seq
, u16 flags
)
627 struct nlattr
*app_tb
[DCB_APP_ATTR_MAX
+ 1];
629 if (!tb
[DCB_ATTR_APP
] || !netdev
->dcbnl_ops
->setapp
)
632 ret
= nla_parse_nested(app_tb
, DCB_APP_ATTR_MAX
, tb
[DCB_ATTR_APP
],
638 /* all must be non-null */
639 if ((!app_tb
[DCB_APP_ATTR_IDTYPE
]) ||
640 (!app_tb
[DCB_APP_ATTR_ID
]) ||
641 (!app_tb
[DCB_APP_ATTR_PRIORITY
]))
644 /* either by eth type or by socket number */
645 idtype
= nla_get_u8(app_tb
[DCB_APP_ATTR_IDTYPE
]);
646 if ((idtype
!= DCB_APP_IDTYPE_ETHTYPE
) &&
647 (idtype
!= DCB_APP_IDTYPE_PORTNUM
))
650 id
= nla_get_u16(app_tb
[DCB_APP_ATTR_ID
]);
651 up
= nla_get_u8(app_tb
[DCB_APP_ATTR_PRIORITY
]);
653 ret
= dcbnl_reply(netdev
->dcbnl_ops
->setapp(netdev
, idtype
, id
, up
),
654 RTM_SETDCB
, DCB_CMD_SAPP
, DCB_ATTR_APP
,
660 static int __dcbnl_pg_getcfg(struct net_device
*netdev
, struct nlattr
**tb
,
661 u32 pid
, u32 seq
, u16 flags
, int dir
)
663 struct sk_buff
*dcbnl_skb
;
664 struct nlmsghdr
*nlh
;
666 struct nlattr
*pg_nest
, *param_nest
, *data
;
667 struct nlattr
*pg_tb
[DCB_PG_ATTR_MAX
+ 1];
668 struct nlattr
*param_tb
[DCB_TC_ATTR_PARAM_MAX
+ 1];
669 u8 prio
, pgid
, tc_pct
, up_map
;
674 if (!tb
[DCB_ATTR_PG_CFG
] ||
675 !netdev
->dcbnl_ops
->getpgtccfgtx
||
676 !netdev
->dcbnl_ops
->getpgtccfgrx
||
677 !netdev
->dcbnl_ops
->getpgbwgcfgtx
||
678 !netdev
->dcbnl_ops
->getpgbwgcfgrx
)
681 ret
= nla_parse_nested(pg_tb
, DCB_PG_ATTR_MAX
,
682 tb
[DCB_ATTR_PG_CFG
], dcbnl_pg_nest
);
687 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
691 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
693 dcb
= NLMSG_DATA(nlh
);
694 dcb
->dcb_family
= AF_UNSPEC
;
695 dcb
->cmd
= (dir
) ? DCB_CMD_PGRX_GCFG
: DCB_CMD_PGTX_GCFG
;
697 pg_nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_PG_CFG
);
701 if (pg_tb
[DCB_PG_ATTR_TC_ALL
])
704 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
705 if (!getall
&& !pg_tb
[i
])
708 if (pg_tb
[DCB_PG_ATTR_TC_ALL
])
709 data
= pg_tb
[DCB_PG_ATTR_TC_ALL
];
712 ret
= nla_parse_nested(param_tb
, DCB_TC_ATTR_PARAM_MAX
,
713 data
, dcbnl_tc_param_nest
);
717 param_nest
= nla_nest_start(dcbnl_skb
, i
);
721 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
722 prio
= DCB_ATTR_VALUE_UNDEFINED
;
723 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
724 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
728 netdev
->dcbnl_ops
->getpgtccfgrx(netdev
,
729 i
- DCB_PG_ATTR_TC_0
, &prio
,
730 &pgid
, &tc_pct
, &up_map
);
733 netdev
->dcbnl_ops
->getpgtccfgtx(netdev
,
734 i
- DCB_PG_ATTR_TC_0
, &prio
,
735 &pgid
, &tc_pct
, &up_map
);
738 if (param_tb
[DCB_TC_ATTR_PARAM_PGID
] ||
739 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
740 ret
= nla_put_u8(dcbnl_skb
,
741 DCB_TC_ATTR_PARAM_PGID
, pgid
);
745 if (param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
] ||
746 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
747 ret
= nla_put_u8(dcbnl_skb
,
748 DCB_TC_ATTR_PARAM_UP_MAPPING
, up_map
);
752 if (param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
] ||
753 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
754 ret
= nla_put_u8(dcbnl_skb
,
755 DCB_TC_ATTR_PARAM_STRICT_PRIO
, prio
);
759 if (param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
] ||
760 param_tb
[DCB_TC_ATTR_PARAM_ALL
]) {
761 ret
= nla_put_u8(dcbnl_skb
, DCB_TC_ATTR_PARAM_BW_PCT
,
766 nla_nest_end(dcbnl_skb
, param_nest
);
769 if (pg_tb
[DCB_PG_ATTR_BW_ID_ALL
])
774 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
775 if (!getall
&& !pg_tb
[i
])
778 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
782 netdev
->dcbnl_ops
->getpgbwgcfgrx(netdev
,
783 i
- DCB_PG_ATTR_BW_ID_0
, &tc_pct
);
786 netdev
->dcbnl_ops
->getpgbwgcfgtx(netdev
,
787 i
- DCB_PG_ATTR_BW_ID_0
, &tc_pct
);
789 ret
= nla_put_u8(dcbnl_skb
, i
, tc_pct
);
795 nla_nest_end(dcbnl_skb
, pg_nest
);
797 nlmsg_end(dcbnl_skb
, nlh
);
799 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
806 nla_nest_cancel(dcbnl_skb
, param_nest
);
808 nla_nest_cancel(dcbnl_skb
, pg_nest
);
811 kfree_skb(dcbnl_skb
);
817 static int dcbnl_pgtx_getcfg(struct net_device
*netdev
, struct nlattr
**tb
,
818 u32 pid
, u32 seq
, u16 flags
)
820 return __dcbnl_pg_getcfg(netdev
, tb
, pid
, seq
, flags
, 0);
823 static int dcbnl_pgrx_getcfg(struct net_device
*netdev
, struct nlattr
**tb
,
824 u32 pid
, u32 seq
, u16 flags
)
826 return __dcbnl_pg_getcfg(netdev
, tb
, pid
, seq
, flags
, 1);
829 static int dcbnl_setstate(struct net_device
*netdev
, struct nlattr
**tb
,
830 u32 pid
, u32 seq
, u16 flags
)
835 if (!tb
[DCB_ATTR_STATE
] || !netdev
->dcbnl_ops
->setstate
)
838 value
= nla_get_u8(tb
[DCB_ATTR_STATE
]);
840 ret
= dcbnl_reply(netdev
->dcbnl_ops
->setstate(netdev
, value
),
841 RTM_SETDCB
, DCB_CMD_SSTATE
, DCB_ATTR_STATE
,
847 static int dcbnl_setpfccfg(struct net_device
*netdev
, struct nlattr
**tb
,
848 u32 pid
, u32 seq
, u16 flags
)
850 struct nlattr
*data
[DCB_PFC_UP_ATTR_MAX
+ 1];
855 if (!tb
[DCB_ATTR_PFC_CFG
] || !netdev
->dcbnl_ops
->setpfccfg
)
858 ret
= nla_parse_nested(data
, DCB_PFC_UP_ATTR_MAX
,
859 tb
[DCB_ATTR_PFC_CFG
],
864 for (i
= DCB_PFC_UP_ATTR_0
; i
<= DCB_PFC_UP_ATTR_7
; i
++) {
867 value
= nla_get_u8(data
[i
]);
868 netdev
->dcbnl_ops
->setpfccfg(netdev
,
869 data
[i
]->nla_type
- DCB_PFC_UP_ATTR_0
, value
);
872 ret
= dcbnl_reply(0, RTM_SETDCB
, DCB_CMD_PFC_SCFG
, DCB_ATTR_PFC_CFG
,
878 static int dcbnl_setall(struct net_device
*netdev
, struct nlattr
**tb
,
879 u32 pid
, u32 seq
, u16 flags
)
883 if (!tb
[DCB_ATTR_SET_ALL
] || !netdev
->dcbnl_ops
->setall
)
886 ret
= dcbnl_reply(netdev
->dcbnl_ops
->setall(netdev
), RTM_SETDCB
,
887 DCB_CMD_SET_ALL
, DCB_ATTR_SET_ALL
, pid
, seq
, flags
);
892 static int __dcbnl_pg_setcfg(struct net_device
*netdev
, struct nlattr
**tb
,
893 u32 pid
, u32 seq
, u16 flags
, int dir
)
895 struct nlattr
*pg_tb
[DCB_PG_ATTR_MAX
+ 1];
896 struct nlattr
*param_tb
[DCB_TC_ATTR_PARAM_MAX
+ 1];
904 if (!tb
[DCB_ATTR_PG_CFG
] ||
905 !netdev
->dcbnl_ops
->setpgtccfgtx
||
906 !netdev
->dcbnl_ops
->setpgtccfgrx
||
907 !netdev
->dcbnl_ops
->setpgbwgcfgtx
||
908 !netdev
->dcbnl_ops
->setpgbwgcfgrx
)
911 ret
= nla_parse_nested(pg_tb
, DCB_PG_ATTR_MAX
,
912 tb
[DCB_ATTR_PG_CFG
], dcbnl_pg_nest
);
916 for (i
= DCB_PG_ATTR_TC_0
; i
<= DCB_PG_ATTR_TC_7
; i
++) {
920 ret
= nla_parse_nested(param_tb
, DCB_TC_ATTR_PARAM_MAX
,
921 pg_tb
[i
], dcbnl_tc_param_nest
);
925 pgid
= DCB_ATTR_VALUE_UNDEFINED
;
926 prio
= DCB_ATTR_VALUE_UNDEFINED
;
927 tc_pct
= DCB_ATTR_VALUE_UNDEFINED
;
928 up_map
= DCB_ATTR_VALUE_UNDEFINED
;
930 if (param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
])
932 nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_STRICT_PRIO
]);
934 if (param_tb
[DCB_TC_ATTR_PARAM_PGID
])
935 pgid
= nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_PGID
]);
937 if (param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
])
938 tc_pct
= nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_BW_PCT
]);
940 if (param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
])
942 nla_get_u8(param_tb
[DCB_TC_ATTR_PARAM_UP_MAPPING
]);
944 /* dir: Tx = 0, Rx = 1 */
947 netdev
->dcbnl_ops
->setpgtccfgrx(netdev
,
948 i
- DCB_PG_ATTR_TC_0
,
949 prio
, pgid
, tc_pct
, up_map
);
952 netdev
->dcbnl_ops
->setpgtccfgtx(netdev
,
953 i
- DCB_PG_ATTR_TC_0
,
954 prio
, pgid
, tc_pct
, up_map
);
958 for (i
= DCB_PG_ATTR_BW_ID_0
; i
<= DCB_PG_ATTR_BW_ID_7
; i
++) {
962 tc_pct
= nla_get_u8(pg_tb
[i
]);
964 /* dir: Tx = 0, Rx = 1 */
967 netdev
->dcbnl_ops
->setpgbwgcfgrx(netdev
,
968 i
- DCB_PG_ATTR_BW_ID_0
, tc_pct
);
971 netdev
->dcbnl_ops
->setpgbwgcfgtx(netdev
,
972 i
- DCB_PG_ATTR_BW_ID_0
, tc_pct
);
976 ret
= dcbnl_reply(0, RTM_SETDCB
,
977 (dir
? DCB_CMD_PGRX_SCFG
: DCB_CMD_PGTX_SCFG
),
978 DCB_ATTR_PG_CFG
, pid
, seq
, flags
);
984 static int dcbnl_pgtx_setcfg(struct net_device
*netdev
, struct nlattr
**tb
,
985 u32 pid
, u32 seq
, u16 flags
)
987 return __dcbnl_pg_setcfg(netdev
, tb
, pid
, seq
, flags
, 0);
990 static int dcbnl_pgrx_setcfg(struct net_device
*netdev
, struct nlattr
**tb
,
991 u32 pid
, u32 seq
, u16 flags
)
993 return __dcbnl_pg_setcfg(netdev
, tb
, pid
, seq
, flags
, 1);
996 static int dcbnl_bcn_getcfg(struct net_device
*netdev
, struct nlattr
**tb
,
997 u32 pid
, u32 seq
, u16 flags
)
999 struct sk_buff
*dcbnl_skb
;
1000 struct nlmsghdr
*nlh
;
1002 struct nlattr
*bcn_nest
;
1003 struct nlattr
*bcn_tb
[DCB_BCN_ATTR_MAX
+ 1];
1007 bool getall
= false;
1010 if (!tb
[DCB_ATTR_BCN
] || !netdev
->dcbnl_ops
->getbcnrp
||
1011 !netdev
->dcbnl_ops
->getbcncfg
)
1014 ret
= nla_parse_nested(bcn_tb
, DCB_BCN_ATTR_MAX
,
1015 tb
[DCB_ATTR_BCN
], dcbnl_bcn_nest
);
1020 dcbnl_skb
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1024 nlh
= NLMSG_NEW(dcbnl_skb
, pid
, seq
, RTM_GETDCB
, sizeof(*dcb
), flags
);
1026 dcb
= NLMSG_DATA(nlh
);
1027 dcb
->dcb_family
= AF_UNSPEC
;
1028 dcb
->cmd
= DCB_CMD_BCN_GCFG
;
1030 bcn_nest
= nla_nest_start(dcbnl_skb
, DCB_ATTR_BCN
);
1034 if (bcn_tb
[DCB_BCN_ATTR_ALL
])
1037 for (i
= DCB_BCN_ATTR_RP_0
; i
<= DCB_BCN_ATTR_RP_7
; i
++) {
1038 if (!getall
&& !bcn_tb
[i
])
1041 netdev
->dcbnl_ops
->getbcnrp(netdev
, i
- DCB_BCN_ATTR_RP_0
,
1043 ret
= nla_put_u8(dcbnl_skb
, i
, value_byte
);
1048 for (i
= DCB_BCN_ATTR_BCNA_0
; i
<= DCB_BCN_ATTR_RI
; i
++) {
1049 if (!getall
&& !bcn_tb
[i
])
1052 netdev
->dcbnl_ops
->getbcncfg(netdev
, i
,
1054 ret
= nla_put_u32(dcbnl_skb
, i
, value_integer
);
1059 nla_nest_end(dcbnl_skb
, bcn_nest
);
1061 nlmsg_end(dcbnl_skb
, nlh
);
1063 ret
= rtnl_unicast(dcbnl_skb
, &init_net
, pid
);
1070 nla_nest_cancel(dcbnl_skb
, bcn_nest
);
1073 kfree_skb(dcbnl_skb
);
1079 static int dcbnl_bcn_setcfg(struct net_device
*netdev
, struct nlattr
**tb
,
1080 u32 pid
, u32 seq
, u16 flags
)
1082 struct nlattr
*data
[DCB_BCN_ATTR_MAX
+ 1];
1088 if (!tb
[DCB_ATTR_BCN
] || !netdev
->dcbnl_ops
->setbcncfg
||
1089 !netdev
->dcbnl_ops
->setbcnrp
)
1092 ret
= nla_parse_nested(data
, DCB_BCN_ATTR_MAX
,
1098 for (i
= DCB_BCN_ATTR_RP_0
; i
<= DCB_BCN_ATTR_RP_7
; i
++) {
1099 if (data
[i
] == NULL
)
1101 value_byte
= nla_get_u8(data
[i
]);
1102 netdev
->dcbnl_ops
->setbcnrp(netdev
,
1103 data
[i
]->nla_type
- DCB_BCN_ATTR_RP_0
, value_byte
);
1106 for (i
= DCB_BCN_ATTR_BCNA_0
; i
<= DCB_BCN_ATTR_RI
; i
++) {
1107 if (data
[i
] == NULL
)
1109 value_int
= nla_get_u32(data
[i
]);
1110 netdev
->dcbnl_ops
->setbcncfg(netdev
,
1114 ret
= dcbnl_reply(0, RTM_SETDCB
, DCB_CMD_BCN_SCFG
, DCB_ATTR_BCN
,
1120 static int dcb_doit(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
1122 struct net
*net
= sock_net(skb
->sk
);
1123 struct net_device
*netdev
;
1124 struct dcbmsg
*dcb
= (struct dcbmsg
*)NLMSG_DATA(nlh
);
1125 struct nlattr
*tb
[DCB_ATTR_MAX
+ 1];
1126 u32 pid
= skb
? NETLINK_CB(skb
).pid
: 0;
1129 if (!net_eq(net
, &init_net
))
1132 ret
= nlmsg_parse(nlh
, sizeof(*dcb
), tb
, DCB_ATTR_MAX
,
1137 if (!tb
[DCB_ATTR_IFNAME
])
1140 netdev
= dev_get_by_name(&init_net
, nla_data(tb
[DCB_ATTR_IFNAME
]));
1144 if (!netdev
->dcbnl_ops
)
1148 case DCB_CMD_GSTATE
:
1149 ret
= dcbnl_getstate(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1152 case DCB_CMD_PFC_GCFG
:
1153 ret
= dcbnl_getpfccfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1156 case DCB_CMD_GPERM_HWADDR
:
1157 ret
= dcbnl_getperm_hwaddr(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1160 case DCB_CMD_PGTX_GCFG
:
1161 ret
= dcbnl_pgtx_getcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1164 case DCB_CMD_PGRX_GCFG
:
1165 ret
= dcbnl_pgrx_getcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1168 case DCB_CMD_BCN_GCFG
:
1169 ret
= dcbnl_bcn_getcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1172 case DCB_CMD_SSTATE
:
1173 ret
= dcbnl_setstate(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1176 case DCB_CMD_PFC_SCFG
:
1177 ret
= dcbnl_setpfccfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1181 case DCB_CMD_SET_ALL
:
1182 ret
= dcbnl_setall(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1185 case DCB_CMD_PGTX_SCFG
:
1186 ret
= dcbnl_pgtx_setcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1189 case DCB_CMD_PGRX_SCFG
:
1190 ret
= dcbnl_pgrx_setcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1194 ret
= dcbnl_getcap(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1197 case DCB_CMD_GNUMTCS
:
1198 ret
= dcbnl_getnumtcs(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1201 case DCB_CMD_SNUMTCS
:
1202 ret
= dcbnl_setnumtcs(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1205 case DCB_CMD_PFC_GSTATE
:
1206 ret
= dcbnl_getpfcstate(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1209 case DCB_CMD_PFC_SSTATE
:
1210 ret
= dcbnl_setpfcstate(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1213 case DCB_CMD_BCN_SCFG
:
1214 ret
= dcbnl_bcn_setcfg(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1218 ret
= dcbnl_getapp(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1222 ret
= dcbnl_setapp(netdev
, tb
, pid
, nlh
->nlmsg_seq
,
1235 static int __init
dcbnl_init(void)
1237 rtnl_register(PF_UNSPEC
, RTM_GETDCB
, dcb_doit
, NULL
);
1238 rtnl_register(PF_UNSPEC
, RTM_SETDCB
, dcb_doit
, NULL
);
1242 module_init(dcbnl_init
);
1244 static void __exit
dcbnl_exit(void)
1246 rtnl_unregister(PF_UNSPEC
, RTM_GETDCB
);
1247 rtnl_unregister(PF_UNSPEC
, RTM_SETDCB
);
1249 module_exit(dcbnl_exit
);