xref: /kernel/linux/linux-5.10/net/dcb/dcbnl.c (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2008-2011, Intel Corporation.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Description: Data Center Bridging netlink interface
68c2ecf20Sopenharmony_ci * Author: Lucy Liu <lucy.liu@intel.com>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
108c2ecf20Sopenharmony_ci#include <linux/netlink.h>
118c2ecf20Sopenharmony_ci#include <linux/slab.h>
128c2ecf20Sopenharmony_ci#include <net/netlink.h>
138c2ecf20Sopenharmony_ci#include <net/rtnetlink.h>
148c2ecf20Sopenharmony_ci#include <linux/dcbnl.h>
158c2ecf20Sopenharmony_ci#include <net/dcbevent.h>
168c2ecf20Sopenharmony_ci#include <linux/rtnetlink.h>
178c2ecf20Sopenharmony_ci#include <linux/init.h>
188c2ecf20Sopenharmony_ci#include <net/sock.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci/* Data Center Bridging (DCB) is a collection of Ethernet enhancements
218c2ecf20Sopenharmony_ci * intended to allow network traffic with differing requirements
228c2ecf20Sopenharmony_ci * (highly reliable, no drops vs. best effort vs. low latency) to operate
238c2ecf20Sopenharmony_ci * and co-exist on Ethernet.  Current DCB features are:
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a
268c2ecf20Sopenharmony_ci *   framework for assigning bandwidth guarantees to traffic classes.
278c2ecf20Sopenharmony_ci *
288c2ecf20Sopenharmony_ci * Priority-based Flow Control (PFC) - provides a flow control mechanism which
298c2ecf20Sopenharmony_ci *   can work independently for each 802.1p priority.
308c2ecf20Sopenharmony_ci *
318c2ecf20Sopenharmony_ci * Congestion Notification - provides a mechanism for end-to-end congestion
328c2ecf20Sopenharmony_ci *   control for protocols which do not have built-in congestion management.
338c2ecf20Sopenharmony_ci *
348c2ecf20Sopenharmony_ci * More information about the emerging standards for these Ethernet features
358c2ecf20Sopenharmony_ci * can be found at: http://www.ieee802.org/1/pages/dcbridges.html
368c2ecf20Sopenharmony_ci *
378c2ecf20Sopenharmony_ci * This file implements an rtnetlink interface to allow configuration of DCB
388c2ecf20Sopenharmony_ci * features for capable devices.
398c2ecf20Sopenharmony_ci */
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/**************** DCB attribute policies *************************************/
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci/* DCB netlink attributes policy */
448c2ecf20Sopenharmony_cistatic const struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = {
458c2ecf20Sopenharmony_ci	[DCB_ATTR_IFNAME]      = {.type = NLA_NUL_STRING, .len = IFNAMSIZ - 1},
468c2ecf20Sopenharmony_ci	[DCB_ATTR_STATE]       = {.type = NLA_U8},
478c2ecf20Sopenharmony_ci	[DCB_ATTR_PFC_CFG]     = {.type = NLA_NESTED},
488c2ecf20Sopenharmony_ci	[DCB_ATTR_PG_CFG]      = {.type = NLA_NESTED},
498c2ecf20Sopenharmony_ci	[DCB_ATTR_SET_ALL]     = {.type = NLA_U8},
508c2ecf20Sopenharmony_ci	[DCB_ATTR_PERM_HWADDR] = {.type = NLA_FLAG},
518c2ecf20Sopenharmony_ci	[DCB_ATTR_CAP]         = {.type = NLA_NESTED},
528c2ecf20Sopenharmony_ci	[DCB_ATTR_PFC_STATE]   = {.type = NLA_U8},
538c2ecf20Sopenharmony_ci	[DCB_ATTR_BCN]         = {.type = NLA_NESTED},
548c2ecf20Sopenharmony_ci	[DCB_ATTR_APP]         = {.type = NLA_NESTED},
558c2ecf20Sopenharmony_ci	[DCB_ATTR_IEEE]	       = {.type = NLA_NESTED},
568c2ecf20Sopenharmony_ci	[DCB_ATTR_DCBX]        = {.type = NLA_U8},
578c2ecf20Sopenharmony_ci	[DCB_ATTR_FEATCFG]     = {.type = NLA_NESTED},
588c2ecf20Sopenharmony_ci};
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci/* DCB priority flow control to User Priority nested attributes */
618c2ecf20Sopenharmony_cistatic const struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = {
628c2ecf20Sopenharmony_ci	[DCB_PFC_UP_ATTR_0]   = {.type = NLA_U8},
638c2ecf20Sopenharmony_ci	[DCB_PFC_UP_ATTR_1]   = {.type = NLA_U8},
648c2ecf20Sopenharmony_ci	[DCB_PFC_UP_ATTR_2]   = {.type = NLA_U8},
658c2ecf20Sopenharmony_ci	[DCB_PFC_UP_ATTR_3]   = {.type = NLA_U8},
668c2ecf20Sopenharmony_ci	[DCB_PFC_UP_ATTR_4]   = {.type = NLA_U8},
678c2ecf20Sopenharmony_ci	[DCB_PFC_UP_ATTR_5]   = {.type = NLA_U8},
688c2ecf20Sopenharmony_ci	[DCB_PFC_UP_ATTR_6]   = {.type = NLA_U8},
698c2ecf20Sopenharmony_ci	[DCB_PFC_UP_ATTR_7]   = {.type = NLA_U8},
708c2ecf20Sopenharmony_ci	[DCB_PFC_UP_ATTR_ALL] = {.type = NLA_FLAG},
718c2ecf20Sopenharmony_ci};
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/* DCB priority grouping nested attributes */
748c2ecf20Sopenharmony_cistatic const struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = {
758c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_TC_0]      = {.type = NLA_NESTED},
768c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_TC_1]      = {.type = NLA_NESTED},
778c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_TC_2]      = {.type = NLA_NESTED},
788c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_TC_3]      = {.type = NLA_NESTED},
798c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_TC_4]      = {.type = NLA_NESTED},
808c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_TC_5]      = {.type = NLA_NESTED},
818c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_TC_6]      = {.type = NLA_NESTED},
828c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_TC_7]      = {.type = NLA_NESTED},
838c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_TC_ALL]    = {.type = NLA_NESTED},
848c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_BW_ID_0]   = {.type = NLA_U8},
858c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_BW_ID_1]   = {.type = NLA_U8},
868c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_BW_ID_2]   = {.type = NLA_U8},
878c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_BW_ID_3]   = {.type = NLA_U8},
888c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_BW_ID_4]   = {.type = NLA_U8},
898c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_BW_ID_5]   = {.type = NLA_U8},
908c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_BW_ID_6]   = {.type = NLA_U8},
918c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_BW_ID_7]   = {.type = NLA_U8},
928c2ecf20Sopenharmony_ci	[DCB_PG_ATTR_BW_ID_ALL] = {.type = NLA_FLAG},
938c2ecf20Sopenharmony_ci};
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci/* DCB traffic class nested attributes. */
968c2ecf20Sopenharmony_cistatic const struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = {
978c2ecf20Sopenharmony_ci	[DCB_TC_ATTR_PARAM_PGID]            = {.type = NLA_U8},
988c2ecf20Sopenharmony_ci	[DCB_TC_ATTR_PARAM_UP_MAPPING]      = {.type = NLA_U8},
998c2ecf20Sopenharmony_ci	[DCB_TC_ATTR_PARAM_STRICT_PRIO]     = {.type = NLA_U8},
1008c2ecf20Sopenharmony_ci	[DCB_TC_ATTR_PARAM_BW_PCT]          = {.type = NLA_U8},
1018c2ecf20Sopenharmony_ci	[DCB_TC_ATTR_PARAM_ALL]             = {.type = NLA_FLAG},
1028c2ecf20Sopenharmony_ci};
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/* DCB capabilities nested attributes. */
1058c2ecf20Sopenharmony_cistatic const struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = {
1068c2ecf20Sopenharmony_ci	[DCB_CAP_ATTR_ALL]     = {.type = NLA_FLAG},
1078c2ecf20Sopenharmony_ci	[DCB_CAP_ATTR_PG]      = {.type = NLA_U8},
1088c2ecf20Sopenharmony_ci	[DCB_CAP_ATTR_PFC]     = {.type = NLA_U8},
1098c2ecf20Sopenharmony_ci	[DCB_CAP_ATTR_UP2TC]   = {.type = NLA_U8},
1108c2ecf20Sopenharmony_ci	[DCB_CAP_ATTR_PG_TCS]  = {.type = NLA_U8},
1118c2ecf20Sopenharmony_ci	[DCB_CAP_ATTR_PFC_TCS] = {.type = NLA_U8},
1128c2ecf20Sopenharmony_ci	[DCB_CAP_ATTR_GSP]     = {.type = NLA_U8},
1138c2ecf20Sopenharmony_ci	[DCB_CAP_ATTR_BCN]     = {.type = NLA_U8},
1148c2ecf20Sopenharmony_ci	[DCB_CAP_ATTR_DCBX]    = {.type = NLA_U8},
1158c2ecf20Sopenharmony_ci};
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci/* DCB capabilities nested attributes. */
1188c2ecf20Sopenharmony_cistatic const struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = {
1198c2ecf20Sopenharmony_ci	[DCB_NUMTCS_ATTR_ALL]     = {.type = NLA_FLAG},
1208c2ecf20Sopenharmony_ci	[DCB_NUMTCS_ATTR_PG]      = {.type = NLA_U8},
1218c2ecf20Sopenharmony_ci	[DCB_NUMTCS_ATTR_PFC]     = {.type = NLA_U8},
1228c2ecf20Sopenharmony_ci};
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci/* DCB BCN nested attributes. */
1258c2ecf20Sopenharmony_cistatic const struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = {
1268c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_RP_0]         = {.type = NLA_U8},
1278c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_RP_1]         = {.type = NLA_U8},
1288c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_RP_2]         = {.type = NLA_U8},
1298c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_RP_3]         = {.type = NLA_U8},
1308c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_RP_4]         = {.type = NLA_U8},
1318c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_RP_5]         = {.type = NLA_U8},
1328c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_RP_6]         = {.type = NLA_U8},
1338c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_RP_7]         = {.type = NLA_U8},
1348c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_RP_ALL]       = {.type = NLA_FLAG},
1358c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_BCNA_0]       = {.type = NLA_U32},
1368c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_BCNA_1]       = {.type = NLA_U32},
1378c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_ALPHA]        = {.type = NLA_U32},
1388c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_BETA]         = {.type = NLA_U32},
1398c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_GD]           = {.type = NLA_U32},
1408c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_GI]           = {.type = NLA_U32},
1418c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_TMAX]         = {.type = NLA_U32},
1428c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_TD]           = {.type = NLA_U32},
1438c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_RMIN]         = {.type = NLA_U32},
1448c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_W]            = {.type = NLA_U32},
1458c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_RD]           = {.type = NLA_U32},
1468c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_RU]           = {.type = NLA_U32},
1478c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_WRTT]         = {.type = NLA_U32},
1488c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_RI]           = {.type = NLA_U32},
1498c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_C]            = {.type = NLA_U32},
1508c2ecf20Sopenharmony_ci	[DCB_BCN_ATTR_ALL]          = {.type = NLA_FLAG},
1518c2ecf20Sopenharmony_ci};
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci/* DCB APP nested attributes. */
1548c2ecf20Sopenharmony_cistatic const struct nla_policy dcbnl_app_nest[DCB_APP_ATTR_MAX + 1] = {
1558c2ecf20Sopenharmony_ci	[DCB_APP_ATTR_IDTYPE]       = {.type = NLA_U8},
1568c2ecf20Sopenharmony_ci	[DCB_APP_ATTR_ID]           = {.type = NLA_U16},
1578c2ecf20Sopenharmony_ci	[DCB_APP_ATTR_PRIORITY]     = {.type = NLA_U8},
1588c2ecf20Sopenharmony_ci};
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci/* IEEE 802.1Qaz nested attributes. */
1618c2ecf20Sopenharmony_cistatic const struct nla_policy dcbnl_ieee_policy[DCB_ATTR_IEEE_MAX + 1] = {
1628c2ecf20Sopenharmony_ci	[DCB_ATTR_IEEE_ETS]	    = {.len = sizeof(struct ieee_ets)},
1638c2ecf20Sopenharmony_ci	[DCB_ATTR_IEEE_PFC]	    = {.len = sizeof(struct ieee_pfc)},
1648c2ecf20Sopenharmony_ci	[DCB_ATTR_IEEE_APP_TABLE]   = {.type = NLA_NESTED},
1658c2ecf20Sopenharmony_ci	[DCB_ATTR_IEEE_MAXRATE]   = {.len = sizeof(struct ieee_maxrate)},
1668c2ecf20Sopenharmony_ci	[DCB_ATTR_IEEE_QCN]         = {.len = sizeof(struct ieee_qcn)},
1678c2ecf20Sopenharmony_ci	[DCB_ATTR_IEEE_QCN_STATS]   = {.len = sizeof(struct ieee_qcn_stats)},
1688c2ecf20Sopenharmony_ci	[DCB_ATTR_DCB_BUFFER]       = {.len = sizeof(struct dcbnl_buffer)},
1698c2ecf20Sopenharmony_ci};
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci/* DCB number of traffic classes nested attributes. */
1728c2ecf20Sopenharmony_cistatic const struct nla_policy dcbnl_featcfg_nest[DCB_FEATCFG_ATTR_MAX + 1] = {
1738c2ecf20Sopenharmony_ci	[DCB_FEATCFG_ATTR_ALL]      = {.type = NLA_FLAG},
1748c2ecf20Sopenharmony_ci	[DCB_FEATCFG_ATTR_PG]       = {.type = NLA_U8},
1758c2ecf20Sopenharmony_ci	[DCB_FEATCFG_ATTR_PFC]      = {.type = NLA_U8},
1768c2ecf20Sopenharmony_ci	[DCB_FEATCFG_ATTR_APP]      = {.type = NLA_U8},
1778c2ecf20Sopenharmony_ci};
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_cistatic LIST_HEAD(dcb_app_list);
1808c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(dcb_lock);
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_cistatic struct sk_buff *dcbnl_newmsg(int type, u8 cmd, u32 port, u32 seq,
1838c2ecf20Sopenharmony_ci				    u32 flags, struct nlmsghdr **nlhp)
1848c2ecf20Sopenharmony_ci{
1858c2ecf20Sopenharmony_ci	struct sk_buff *skb;
1868c2ecf20Sopenharmony_ci	struct dcbmsg *dcb;
1878c2ecf20Sopenharmony_ci	struct nlmsghdr *nlh;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1908c2ecf20Sopenharmony_ci	if (!skb)
1918c2ecf20Sopenharmony_ci		return NULL;
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci	nlh = nlmsg_put(skb, port, seq, type, sizeof(*dcb), flags);
1948c2ecf20Sopenharmony_ci	BUG_ON(!nlh);
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	dcb = nlmsg_data(nlh);
1978c2ecf20Sopenharmony_ci	dcb->dcb_family = AF_UNSPEC;
1988c2ecf20Sopenharmony_ci	dcb->cmd = cmd;
1998c2ecf20Sopenharmony_ci	dcb->dcb_pad = 0;
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci	if (nlhp)
2028c2ecf20Sopenharmony_ci		*nlhp = nlh;
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	return skb;
2058c2ecf20Sopenharmony_ci}
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_cistatic int dcbnl_getstate(struct net_device *netdev, struct nlmsghdr *nlh,
2088c2ecf20Sopenharmony_ci			  u32 seq, struct nlattr **tb, struct sk_buff *skb)
2098c2ecf20Sopenharmony_ci{
2108c2ecf20Sopenharmony_ci	/* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
2118c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->getstate)
2128c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci	return nla_put_u8(skb, DCB_ATTR_STATE,
2158c2ecf20Sopenharmony_ci			  netdev->dcbnl_ops->getstate(netdev));
2168c2ecf20Sopenharmony_ci}
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_cistatic int dcbnl_getpfccfg(struct net_device *netdev, struct nlmsghdr *nlh,
2198c2ecf20Sopenharmony_ci			   u32 seq, struct nlattr **tb, struct sk_buff *skb)
2208c2ecf20Sopenharmony_ci{
2218c2ecf20Sopenharmony_ci	struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1], *nest;
2228c2ecf20Sopenharmony_ci	u8 value;
2238c2ecf20Sopenharmony_ci	int ret;
2248c2ecf20Sopenharmony_ci	int i;
2258c2ecf20Sopenharmony_ci	int getall = 0;
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_PFC_CFG])
2288c2ecf20Sopenharmony_ci		return -EINVAL;
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->getpfccfg)
2318c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci	ret = nla_parse_nested_deprecated(data, DCB_PFC_UP_ATTR_MAX,
2348c2ecf20Sopenharmony_ci					  tb[DCB_ATTR_PFC_CFG],
2358c2ecf20Sopenharmony_ci					  dcbnl_pfc_up_nest, NULL);
2368c2ecf20Sopenharmony_ci	if (ret)
2378c2ecf20Sopenharmony_ci		return ret;
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci	nest = nla_nest_start_noflag(skb, DCB_ATTR_PFC_CFG);
2408c2ecf20Sopenharmony_ci	if (!nest)
2418c2ecf20Sopenharmony_ci		return -EMSGSIZE;
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci	if (data[DCB_PFC_UP_ATTR_ALL])
2448c2ecf20Sopenharmony_ci		getall = 1;
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci	for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
2478c2ecf20Sopenharmony_ci		if (!getall && !data[i])
2488c2ecf20Sopenharmony_ci			continue;
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci		netdev->dcbnl_ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0,
2518c2ecf20Sopenharmony_ci		                             &value);
2528c2ecf20Sopenharmony_ci		ret = nla_put_u8(skb, i, value);
2538c2ecf20Sopenharmony_ci		if (ret) {
2548c2ecf20Sopenharmony_ci			nla_nest_cancel(skb, nest);
2558c2ecf20Sopenharmony_ci			return ret;
2568c2ecf20Sopenharmony_ci		}
2578c2ecf20Sopenharmony_ci	}
2588c2ecf20Sopenharmony_ci	nla_nest_end(skb, nest);
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci	return 0;
2618c2ecf20Sopenharmony_ci}
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_cistatic int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlmsghdr *nlh,
2648c2ecf20Sopenharmony_ci				u32 seq, struct nlattr **tb, struct sk_buff *skb)
2658c2ecf20Sopenharmony_ci{
2668c2ecf20Sopenharmony_ci	u8 perm_addr[MAX_ADDR_LEN];
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->getpermhwaddr)
2698c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci	memset(perm_addr, 0, sizeof(perm_addr));
2728c2ecf20Sopenharmony_ci	netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci	return nla_put(skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr), perm_addr);
2758c2ecf20Sopenharmony_ci}
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_cistatic int dcbnl_getcap(struct net_device *netdev, struct nlmsghdr *nlh,
2788c2ecf20Sopenharmony_ci			u32 seq, struct nlattr **tb, struct sk_buff *skb)
2798c2ecf20Sopenharmony_ci{
2808c2ecf20Sopenharmony_ci	struct nlattr *data[DCB_CAP_ATTR_MAX + 1], *nest;
2818c2ecf20Sopenharmony_ci	u8 value;
2828c2ecf20Sopenharmony_ci	int ret;
2838c2ecf20Sopenharmony_ci	int i;
2848c2ecf20Sopenharmony_ci	int getall = 0;
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_CAP])
2878c2ecf20Sopenharmony_ci		return -EINVAL;
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->getcap)
2908c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci	ret = nla_parse_nested_deprecated(data, DCB_CAP_ATTR_MAX,
2938c2ecf20Sopenharmony_ci					  tb[DCB_ATTR_CAP], dcbnl_cap_nest,
2948c2ecf20Sopenharmony_ci					  NULL);
2958c2ecf20Sopenharmony_ci	if (ret)
2968c2ecf20Sopenharmony_ci		return ret;
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci	nest = nla_nest_start_noflag(skb, DCB_ATTR_CAP);
2998c2ecf20Sopenharmony_ci	if (!nest)
3008c2ecf20Sopenharmony_ci		return -EMSGSIZE;
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci	if (data[DCB_CAP_ATTR_ALL])
3038c2ecf20Sopenharmony_ci		getall = 1;
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci	for (i = DCB_CAP_ATTR_ALL+1; i <= DCB_CAP_ATTR_MAX; i++) {
3068c2ecf20Sopenharmony_ci		if (!getall && !data[i])
3078c2ecf20Sopenharmony_ci			continue;
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci		if (!netdev->dcbnl_ops->getcap(netdev, i, &value)) {
3108c2ecf20Sopenharmony_ci			ret = nla_put_u8(skb, i, value);
3118c2ecf20Sopenharmony_ci			if (ret) {
3128c2ecf20Sopenharmony_ci				nla_nest_cancel(skb, nest);
3138c2ecf20Sopenharmony_ci				return ret;
3148c2ecf20Sopenharmony_ci			}
3158c2ecf20Sopenharmony_ci		}
3168c2ecf20Sopenharmony_ci	}
3178c2ecf20Sopenharmony_ci	nla_nest_end(skb, nest);
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci	return 0;
3208c2ecf20Sopenharmony_ci}
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_cistatic int dcbnl_getnumtcs(struct net_device *netdev, struct nlmsghdr *nlh,
3238c2ecf20Sopenharmony_ci			   u32 seq, struct nlattr **tb, struct sk_buff *skb)
3248c2ecf20Sopenharmony_ci{
3258c2ecf20Sopenharmony_ci	struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1], *nest;
3268c2ecf20Sopenharmony_ci	u8 value;
3278c2ecf20Sopenharmony_ci	int ret;
3288c2ecf20Sopenharmony_ci	int i;
3298c2ecf20Sopenharmony_ci	int getall = 0;
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_NUMTCS])
3328c2ecf20Sopenharmony_ci		return -EINVAL;
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->getnumtcs)
3358c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	ret = nla_parse_nested_deprecated(data, DCB_NUMTCS_ATTR_MAX,
3388c2ecf20Sopenharmony_ci					  tb[DCB_ATTR_NUMTCS],
3398c2ecf20Sopenharmony_ci					  dcbnl_numtcs_nest, NULL);
3408c2ecf20Sopenharmony_ci	if (ret)
3418c2ecf20Sopenharmony_ci		return ret;
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	nest = nla_nest_start_noflag(skb, DCB_ATTR_NUMTCS);
3448c2ecf20Sopenharmony_ci	if (!nest)
3458c2ecf20Sopenharmony_ci		return -EMSGSIZE;
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	if (data[DCB_NUMTCS_ATTR_ALL])
3488c2ecf20Sopenharmony_ci		getall = 1;
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci	for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
3518c2ecf20Sopenharmony_ci		if (!getall && !data[i])
3528c2ecf20Sopenharmony_ci			continue;
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci		ret = netdev->dcbnl_ops->getnumtcs(netdev, i, &value);
3558c2ecf20Sopenharmony_ci		if (!ret) {
3568c2ecf20Sopenharmony_ci			ret = nla_put_u8(skb, i, value);
3578c2ecf20Sopenharmony_ci			if (ret) {
3588c2ecf20Sopenharmony_ci				nla_nest_cancel(skb, nest);
3598c2ecf20Sopenharmony_ci				return ret;
3608c2ecf20Sopenharmony_ci			}
3618c2ecf20Sopenharmony_ci		} else
3628c2ecf20Sopenharmony_ci			return -EINVAL;
3638c2ecf20Sopenharmony_ci	}
3648c2ecf20Sopenharmony_ci	nla_nest_end(skb, nest);
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_ci	return 0;
3678c2ecf20Sopenharmony_ci}
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_cistatic int dcbnl_setnumtcs(struct net_device *netdev, struct nlmsghdr *nlh,
3708c2ecf20Sopenharmony_ci			   u32 seq, struct nlattr **tb, struct sk_buff *skb)
3718c2ecf20Sopenharmony_ci{
3728c2ecf20Sopenharmony_ci	struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1];
3738c2ecf20Sopenharmony_ci	int ret;
3748c2ecf20Sopenharmony_ci	u8 value;
3758c2ecf20Sopenharmony_ci	int i;
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_NUMTCS])
3788c2ecf20Sopenharmony_ci		return -EINVAL;
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->setnumtcs)
3818c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci	ret = nla_parse_nested_deprecated(data, DCB_NUMTCS_ATTR_MAX,
3848c2ecf20Sopenharmony_ci					  tb[DCB_ATTR_NUMTCS],
3858c2ecf20Sopenharmony_ci					  dcbnl_numtcs_nest, NULL);
3868c2ecf20Sopenharmony_ci	if (ret)
3878c2ecf20Sopenharmony_ci		return ret;
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
3908c2ecf20Sopenharmony_ci		if (data[i] == NULL)
3918c2ecf20Sopenharmony_ci			continue;
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci		value = nla_get_u8(data[i]);
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci		ret = netdev->dcbnl_ops->setnumtcs(netdev, i, value);
3968c2ecf20Sopenharmony_ci		if (ret)
3978c2ecf20Sopenharmony_ci			break;
3988c2ecf20Sopenharmony_ci	}
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci	return nla_put_u8(skb, DCB_ATTR_NUMTCS, !!ret);
4018c2ecf20Sopenharmony_ci}
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_cistatic int dcbnl_getpfcstate(struct net_device *netdev, struct nlmsghdr *nlh,
4048c2ecf20Sopenharmony_ci			     u32 seq, struct nlattr **tb, struct sk_buff *skb)
4058c2ecf20Sopenharmony_ci{
4068c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->getpfcstate)
4078c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ci	return nla_put_u8(skb, DCB_ATTR_PFC_STATE,
4108c2ecf20Sopenharmony_ci			  netdev->dcbnl_ops->getpfcstate(netdev));
4118c2ecf20Sopenharmony_ci}
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_cistatic int dcbnl_setpfcstate(struct net_device *netdev, struct nlmsghdr *nlh,
4148c2ecf20Sopenharmony_ci			     u32 seq, struct nlattr **tb, struct sk_buff *skb)
4158c2ecf20Sopenharmony_ci{
4168c2ecf20Sopenharmony_ci	u8 value;
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_PFC_STATE])
4198c2ecf20Sopenharmony_ci		return -EINVAL;
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->setpfcstate)
4228c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci	value = nla_get_u8(tb[DCB_ATTR_PFC_STATE]);
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_ci	netdev->dcbnl_ops->setpfcstate(netdev, value);
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci	return nla_put_u8(skb, DCB_ATTR_PFC_STATE, 0);
4298c2ecf20Sopenharmony_ci}
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_cistatic int dcbnl_getapp(struct net_device *netdev, struct nlmsghdr *nlh,
4328c2ecf20Sopenharmony_ci			u32 seq, struct nlattr **tb, struct sk_buff *skb)
4338c2ecf20Sopenharmony_ci{
4348c2ecf20Sopenharmony_ci	struct nlattr *app_nest;
4358c2ecf20Sopenharmony_ci	struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1];
4368c2ecf20Sopenharmony_ci	u16 id;
4378c2ecf20Sopenharmony_ci	u8 up, idtype;
4388c2ecf20Sopenharmony_ci	int ret;
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_APP])
4418c2ecf20Sopenharmony_ci		return -EINVAL;
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci	ret = nla_parse_nested_deprecated(app_tb, DCB_APP_ATTR_MAX,
4448c2ecf20Sopenharmony_ci					  tb[DCB_ATTR_APP], dcbnl_app_nest,
4458c2ecf20Sopenharmony_ci					  NULL);
4468c2ecf20Sopenharmony_ci	if (ret)
4478c2ecf20Sopenharmony_ci		return ret;
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci	/* all must be non-null */
4508c2ecf20Sopenharmony_ci	if ((!app_tb[DCB_APP_ATTR_IDTYPE]) ||
4518c2ecf20Sopenharmony_ci	    (!app_tb[DCB_APP_ATTR_ID]))
4528c2ecf20Sopenharmony_ci		return -EINVAL;
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci	/* either by eth type or by socket number */
4558c2ecf20Sopenharmony_ci	idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]);
4568c2ecf20Sopenharmony_ci	if ((idtype != DCB_APP_IDTYPE_ETHTYPE) &&
4578c2ecf20Sopenharmony_ci	    (idtype != DCB_APP_IDTYPE_PORTNUM))
4588c2ecf20Sopenharmony_ci		return -EINVAL;
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci	id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]);
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci	if (netdev->dcbnl_ops->getapp) {
4638c2ecf20Sopenharmony_ci		ret = netdev->dcbnl_ops->getapp(netdev, idtype, id);
4648c2ecf20Sopenharmony_ci		if (ret < 0)
4658c2ecf20Sopenharmony_ci			return ret;
4668c2ecf20Sopenharmony_ci		else
4678c2ecf20Sopenharmony_ci			up = ret;
4688c2ecf20Sopenharmony_ci	} else {
4698c2ecf20Sopenharmony_ci		struct dcb_app app = {
4708c2ecf20Sopenharmony_ci					.selector = idtype,
4718c2ecf20Sopenharmony_ci					.protocol = id,
4728c2ecf20Sopenharmony_ci				     };
4738c2ecf20Sopenharmony_ci		up = dcb_getapp(netdev, &app);
4748c2ecf20Sopenharmony_ci	}
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci	app_nest = nla_nest_start_noflag(skb, DCB_ATTR_APP);
4778c2ecf20Sopenharmony_ci	if (!app_nest)
4788c2ecf20Sopenharmony_ci		return -EMSGSIZE;
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ci	ret = nla_put_u8(skb, DCB_APP_ATTR_IDTYPE, idtype);
4818c2ecf20Sopenharmony_ci	if (ret)
4828c2ecf20Sopenharmony_ci		goto out_cancel;
4838c2ecf20Sopenharmony_ci
4848c2ecf20Sopenharmony_ci	ret = nla_put_u16(skb, DCB_APP_ATTR_ID, id);
4858c2ecf20Sopenharmony_ci	if (ret)
4868c2ecf20Sopenharmony_ci		goto out_cancel;
4878c2ecf20Sopenharmony_ci
4888c2ecf20Sopenharmony_ci	ret = nla_put_u8(skb, DCB_APP_ATTR_PRIORITY, up);
4898c2ecf20Sopenharmony_ci	if (ret)
4908c2ecf20Sopenharmony_ci		goto out_cancel;
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci	nla_nest_end(skb, app_nest);
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci	return 0;
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ciout_cancel:
4978c2ecf20Sopenharmony_ci	nla_nest_cancel(skb, app_nest);
4988c2ecf20Sopenharmony_ci	return ret;
4998c2ecf20Sopenharmony_ci}
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_cistatic int dcbnl_setapp(struct net_device *netdev, struct nlmsghdr *nlh,
5028c2ecf20Sopenharmony_ci			u32 seq, struct nlattr **tb, struct sk_buff *skb)
5038c2ecf20Sopenharmony_ci{
5048c2ecf20Sopenharmony_ci	int ret;
5058c2ecf20Sopenharmony_ci	u16 id;
5068c2ecf20Sopenharmony_ci	u8 up, idtype;
5078c2ecf20Sopenharmony_ci	struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1];
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_APP])
5108c2ecf20Sopenharmony_ci		return -EINVAL;
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci	ret = nla_parse_nested_deprecated(app_tb, DCB_APP_ATTR_MAX,
5138c2ecf20Sopenharmony_ci					  tb[DCB_ATTR_APP], dcbnl_app_nest,
5148c2ecf20Sopenharmony_ci					  NULL);
5158c2ecf20Sopenharmony_ci	if (ret)
5168c2ecf20Sopenharmony_ci		return ret;
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ci	/* all must be non-null */
5198c2ecf20Sopenharmony_ci	if ((!app_tb[DCB_APP_ATTR_IDTYPE]) ||
5208c2ecf20Sopenharmony_ci	    (!app_tb[DCB_APP_ATTR_ID]) ||
5218c2ecf20Sopenharmony_ci	    (!app_tb[DCB_APP_ATTR_PRIORITY]))
5228c2ecf20Sopenharmony_ci		return -EINVAL;
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ci	/* either by eth type or by socket number */
5258c2ecf20Sopenharmony_ci	idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]);
5268c2ecf20Sopenharmony_ci	if ((idtype != DCB_APP_IDTYPE_ETHTYPE) &&
5278c2ecf20Sopenharmony_ci	    (idtype != DCB_APP_IDTYPE_PORTNUM))
5288c2ecf20Sopenharmony_ci		return -EINVAL;
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_ci	id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]);
5318c2ecf20Sopenharmony_ci	up = nla_get_u8(app_tb[DCB_APP_ATTR_PRIORITY]);
5328c2ecf20Sopenharmony_ci
5338c2ecf20Sopenharmony_ci	if (netdev->dcbnl_ops->setapp) {
5348c2ecf20Sopenharmony_ci		ret = netdev->dcbnl_ops->setapp(netdev, idtype, id, up);
5358c2ecf20Sopenharmony_ci		if (ret < 0)
5368c2ecf20Sopenharmony_ci			return ret;
5378c2ecf20Sopenharmony_ci	} else {
5388c2ecf20Sopenharmony_ci		struct dcb_app app;
5398c2ecf20Sopenharmony_ci		app.selector = idtype;
5408c2ecf20Sopenharmony_ci		app.protocol = id;
5418c2ecf20Sopenharmony_ci		app.priority = up;
5428c2ecf20Sopenharmony_ci		ret = dcb_setapp(netdev, &app);
5438c2ecf20Sopenharmony_ci	}
5448c2ecf20Sopenharmony_ci
5458c2ecf20Sopenharmony_ci	ret = nla_put_u8(skb, DCB_ATTR_APP, ret);
5468c2ecf20Sopenharmony_ci	dcbnl_cee_notify(netdev, RTM_SETDCB, DCB_CMD_SAPP, seq, 0);
5478c2ecf20Sopenharmony_ci
5488c2ecf20Sopenharmony_ci	return ret;
5498c2ecf20Sopenharmony_ci}
5508c2ecf20Sopenharmony_ci
5518c2ecf20Sopenharmony_cistatic int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlmsghdr *nlh,
5528c2ecf20Sopenharmony_ci			     struct nlattr **tb, struct sk_buff *skb, int dir)
5538c2ecf20Sopenharmony_ci{
5548c2ecf20Sopenharmony_ci	struct nlattr *pg_nest, *param_nest, *data;
5558c2ecf20Sopenharmony_ci	struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
5568c2ecf20Sopenharmony_ci	struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
5578c2ecf20Sopenharmony_ci	u8 prio, pgid, tc_pct, up_map;
5588c2ecf20Sopenharmony_ci	int ret;
5598c2ecf20Sopenharmony_ci	int getall = 0;
5608c2ecf20Sopenharmony_ci	int i;
5618c2ecf20Sopenharmony_ci
5628c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_PG_CFG])
5638c2ecf20Sopenharmony_ci		return -EINVAL;
5648c2ecf20Sopenharmony_ci
5658c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->getpgtccfgtx ||
5668c2ecf20Sopenharmony_ci	    !netdev->dcbnl_ops->getpgtccfgrx ||
5678c2ecf20Sopenharmony_ci	    !netdev->dcbnl_ops->getpgbwgcfgtx ||
5688c2ecf20Sopenharmony_ci	    !netdev->dcbnl_ops->getpgbwgcfgrx)
5698c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
5708c2ecf20Sopenharmony_ci
5718c2ecf20Sopenharmony_ci	ret = nla_parse_nested_deprecated(pg_tb, DCB_PG_ATTR_MAX,
5728c2ecf20Sopenharmony_ci					  tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest,
5738c2ecf20Sopenharmony_ci					  NULL);
5748c2ecf20Sopenharmony_ci	if (ret)
5758c2ecf20Sopenharmony_ci		return ret;
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_ci	pg_nest = nla_nest_start_noflag(skb, DCB_ATTR_PG_CFG);
5788c2ecf20Sopenharmony_ci	if (!pg_nest)
5798c2ecf20Sopenharmony_ci		return -EMSGSIZE;
5808c2ecf20Sopenharmony_ci
5818c2ecf20Sopenharmony_ci	if (pg_tb[DCB_PG_ATTR_TC_ALL])
5828c2ecf20Sopenharmony_ci		getall = 1;
5838c2ecf20Sopenharmony_ci
5848c2ecf20Sopenharmony_ci	for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
5858c2ecf20Sopenharmony_ci		if (!getall && !pg_tb[i])
5868c2ecf20Sopenharmony_ci			continue;
5878c2ecf20Sopenharmony_ci
5888c2ecf20Sopenharmony_ci		if (pg_tb[DCB_PG_ATTR_TC_ALL])
5898c2ecf20Sopenharmony_ci			data = pg_tb[DCB_PG_ATTR_TC_ALL];
5908c2ecf20Sopenharmony_ci		else
5918c2ecf20Sopenharmony_ci			data = pg_tb[i];
5928c2ecf20Sopenharmony_ci		ret = nla_parse_nested_deprecated(param_tb,
5938c2ecf20Sopenharmony_ci						  DCB_TC_ATTR_PARAM_MAX, data,
5948c2ecf20Sopenharmony_ci						  dcbnl_tc_param_nest, NULL);
5958c2ecf20Sopenharmony_ci		if (ret)
5968c2ecf20Sopenharmony_ci			goto err_pg;
5978c2ecf20Sopenharmony_ci
5988c2ecf20Sopenharmony_ci		param_nest = nla_nest_start_noflag(skb, i);
5998c2ecf20Sopenharmony_ci		if (!param_nest)
6008c2ecf20Sopenharmony_ci			goto err_pg;
6018c2ecf20Sopenharmony_ci
6028c2ecf20Sopenharmony_ci		pgid = DCB_ATTR_VALUE_UNDEFINED;
6038c2ecf20Sopenharmony_ci		prio = DCB_ATTR_VALUE_UNDEFINED;
6048c2ecf20Sopenharmony_ci		tc_pct = DCB_ATTR_VALUE_UNDEFINED;
6058c2ecf20Sopenharmony_ci		up_map = DCB_ATTR_VALUE_UNDEFINED;
6068c2ecf20Sopenharmony_ci
6078c2ecf20Sopenharmony_ci		if (dir) {
6088c2ecf20Sopenharmony_ci			/* Rx */
6098c2ecf20Sopenharmony_ci			netdev->dcbnl_ops->getpgtccfgrx(netdev,
6108c2ecf20Sopenharmony_ci						i - DCB_PG_ATTR_TC_0, &prio,
6118c2ecf20Sopenharmony_ci						&pgid, &tc_pct, &up_map);
6128c2ecf20Sopenharmony_ci		} else {
6138c2ecf20Sopenharmony_ci			/* Tx */
6148c2ecf20Sopenharmony_ci			netdev->dcbnl_ops->getpgtccfgtx(netdev,
6158c2ecf20Sopenharmony_ci						i - DCB_PG_ATTR_TC_0, &prio,
6168c2ecf20Sopenharmony_ci						&pgid, &tc_pct, &up_map);
6178c2ecf20Sopenharmony_ci		}
6188c2ecf20Sopenharmony_ci
6198c2ecf20Sopenharmony_ci		if (param_tb[DCB_TC_ATTR_PARAM_PGID] ||
6208c2ecf20Sopenharmony_ci		    param_tb[DCB_TC_ATTR_PARAM_ALL]) {
6218c2ecf20Sopenharmony_ci			ret = nla_put_u8(skb,
6228c2ecf20Sopenharmony_ci			                 DCB_TC_ATTR_PARAM_PGID, pgid);
6238c2ecf20Sopenharmony_ci			if (ret)
6248c2ecf20Sopenharmony_ci				goto err_param;
6258c2ecf20Sopenharmony_ci		}
6268c2ecf20Sopenharmony_ci		if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING] ||
6278c2ecf20Sopenharmony_ci		    param_tb[DCB_TC_ATTR_PARAM_ALL]) {
6288c2ecf20Sopenharmony_ci			ret = nla_put_u8(skb,
6298c2ecf20Sopenharmony_ci			                 DCB_TC_ATTR_PARAM_UP_MAPPING, up_map);
6308c2ecf20Sopenharmony_ci			if (ret)
6318c2ecf20Sopenharmony_ci				goto err_param;
6328c2ecf20Sopenharmony_ci		}
6338c2ecf20Sopenharmony_ci		if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO] ||
6348c2ecf20Sopenharmony_ci		    param_tb[DCB_TC_ATTR_PARAM_ALL]) {
6358c2ecf20Sopenharmony_ci			ret = nla_put_u8(skb,
6368c2ecf20Sopenharmony_ci			                 DCB_TC_ATTR_PARAM_STRICT_PRIO, prio);
6378c2ecf20Sopenharmony_ci			if (ret)
6388c2ecf20Sopenharmony_ci				goto err_param;
6398c2ecf20Sopenharmony_ci		}
6408c2ecf20Sopenharmony_ci		if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT] ||
6418c2ecf20Sopenharmony_ci		    param_tb[DCB_TC_ATTR_PARAM_ALL]) {
6428c2ecf20Sopenharmony_ci			ret = nla_put_u8(skb, DCB_TC_ATTR_PARAM_BW_PCT,
6438c2ecf20Sopenharmony_ci			                 tc_pct);
6448c2ecf20Sopenharmony_ci			if (ret)
6458c2ecf20Sopenharmony_ci				goto err_param;
6468c2ecf20Sopenharmony_ci		}
6478c2ecf20Sopenharmony_ci		nla_nest_end(skb, param_nest);
6488c2ecf20Sopenharmony_ci	}
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci	if (pg_tb[DCB_PG_ATTR_BW_ID_ALL])
6518c2ecf20Sopenharmony_ci		getall = 1;
6528c2ecf20Sopenharmony_ci	else
6538c2ecf20Sopenharmony_ci		getall = 0;
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_ci	for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
6568c2ecf20Sopenharmony_ci		if (!getall && !pg_tb[i])
6578c2ecf20Sopenharmony_ci			continue;
6588c2ecf20Sopenharmony_ci
6598c2ecf20Sopenharmony_ci		tc_pct = DCB_ATTR_VALUE_UNDEFINED;
6608c2ecf20Sopenharmony_ci
6618c2ecf20Sopenharmony_ci		if (dir) {
6628c2ecf20Sopenharmony_ci			/* Rx */
6638c2ecf20Sopenharmony_ci			netdev->dcbnl_ops->getpgbwgcfgrx(netdev,
6648c2ecf20Sopenharmony_ci					i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
6658c2ecf20Sopenharmony_ci		} else {
6668c2ecf20Sopenharmony_ci			/* Tx */
6678c2ecf20Sopenharmony_ci			netdev->dcbnl_ops->getpgbwgcfgtx(netdev,
6688c2ecf20Sopenharmony_ci					i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
6698c2ecf20Sopenharmony_ci		}
6708c2ecf20Sopenharmony_ci		ret = nla_put_u8(skb, i, tc_pct);
6718c2ecf20Sopenharmony_ci		if (ret)
6728c2ecf20Sopenharmony_ci			goto err_pg;
6738c2ecf20Sopenharmony_ci	}
6748c2ecf20Sopenharmony_ci
6758c2ecf20Sopenharmony_ci	nla_nest_end(skb, pg_nest);
6768c2ecf20Sopenharmony_ci
6778c2ecf20Sopenharmony_ci	return 0;
6788c2ecf20Sopenharmony_ci
6798c2ecf20Sopenharmony_cierr_param:
6808c2ecf20Sopenharmony_ci	nla_nest_cancel(skb, param_nest);
6818c2ecf20Sopenharmony_cierr_pg:
6828c2ecf20Sopenharmony_ci	nla_nest_cancel(skb, pg_nest);
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_ci	return -EMSGSIZE;
6858c2ecf20Sopenharmony_ci}
6868c2ecf20Sopenharmony_ci
6878c2ecf20Sopenharmony_cistatic int dcbnl_pgtx_getcfg(struct net_device *netdev, struct nlmsghdr *nlh,
6888c2ecf20Sopenharmony_ci			     u32 seq, struct nlattr **tb, struct sk_buff *skb)
6898c2ecf20Sopenharmony_ci{
6908c2ecf20Sopenharmony_ci	return __dcbnl_pg_getcfg(netdev, nlh, tb, skb, 0);
6918c2ecf20Sopenharmony_ci}
6928c2ecf20Sopenharmony_ci
6938c2ecf20Sopenharmony_cistatic int dcbnl_pgrx_getcfg(struct net_device *netdev, struct nlmsghdr *nlh,
6948c2ecf20Sopenharmony_ci			     u32 seq, struct nlattr **tb, struct sk_buff *skb)
6958c2ecf20Sopenharmony_ci{
6968c2ecf20Sopenharmony_ci	return __dcbnl_pg_getcfg(netdev, nlh, tb, skb, 1);
6978c2ecf20Sopenharmony_ci}
6988c2ecf20Sopenharmony_ci
6998c2ecf20Sopenharmony_cistatic int dcbnl_setstate(struct net_device *netdev, struct nlmsghdr *nlh,
7008c2ecf20Sopenharmony_ci			  u32 seq, struct nlattr **tb, struct sk_buff *skb)
7018c2ecf20Sopenharmony_ci{
7028c2ecf20Sopenharmony_ci	u8 value;
7038c2ecf20Sopenharmony_ci
7048c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_STATE])
7058c2ecf20Sopenharmony_ci		return -EINVAL;
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->setstate)
7088c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_ci	value = nla_get_u8(tb[DCB_ATTR_STATE]);
7118c2ecf20Sopenharmony_ci
7128c2ecf20Sopenharmony_ci	return nla_put_u8(skb, DCB_ATTR_STATE,
7138c2ecf20Sopenharmony_ci			  netdev->dcbnl_ops->setstate(netdev, value));
7148c2ecf20Sopenharmony_ci}
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_cistatic int dcbnl_setpfccfg(struct net_device *netdev, struct nlmsghdr *nlh,
7178c2ecf20Sopenharmony_ci			   u32 seq, struct nlattr **tb, struct sk_buff *skb)
7188c2ecf20Sopenharmony_ci{
7198c2ecf20Sopenharmony_ci	struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1];
7208c2ecf20Sopenharmony_ci	int i;
7218c2ecf20Sopenharmony_ci	int ret;
7228c2ecf20Sopenharmony_ci	u8 value;
7238c2ecf20Sopenharmony_ci
7248c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_PFC_CFG])
7258c2ecf20Sopenharmony_ci		return -EINVAL;
7268c2ecf20Sopenharmony_ci
7278c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->setpfccfg)
7288c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
7298c2ecf20Sopenharmony_ci
7308c2ecf20Sopenharmony_ci	ret = nla_parse_nested_deprecated(data, DCB_PFC_UP_ATTR_MAX,
7318c2ecf20Sopenharmony_ci					  tb[DCB_ATTR_PFC_CFG],
7328c2ecf20Sopenharmony_ci					  dcbnl_pfc_up_nest, NULL);
7338c2ecf20Sopenharmony_ci	if (ret)
7348c2ecf20Sopenharmony_ci		return ret;
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_ci	for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
7378c2ecf20Sopenharmony_ci		if (data[i] == NULL)
7388c2ecf20Sopenharmony_ci			continue;
7398c2ecf20Sopenharmony_ci		value = nla_get_u8(data[i]);
7408c2ecf20Sopenharmony_ci		netdev->dcbnl_ops->setpfccfg(netdev,
7418c2ecf20Sopenharmony_ci			data[i]->nla_type - DCB_PFC_UP_ATTR_0, value);
7428c2ecf20Sopenharmony_ci	}
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_ci	return nla_put_u8(skb, DCB_ATTR_PFC_CFG, 0);
7458c2ecf20Sopenharmony_ci}
7468c2ecf20Sopenharmony_ci
7478c2ecf20Sopenharmony_cistatic int dcbnl_setall(struct net_device *netdev, struct nlmsghdr *nlh,
7488c2ecf20Sopenharmony_ci			u32 seq, struct nlattr **tb, struct sk_buff *skb)
7498c2ecf20Sopenharmony_ci{
7508c2ecf20Sopenharmony_ci	int ret;
7518c2ecf20Sopenharmony_ci
7528c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_SET_ALL])
7538c2ecf20Sopenharmony_ci		return -EINVAL;
7548c2ecf20Sopenharmony_ci
7558c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->setall)
7568c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
7578c2ecf20Sopenharmony_ci
7588c2ecf20Sopenharmony_ci	ret = nla_put_u8(skb, DCB_ATTR_SET_ALL,
7598c2ecf20Sopenharmony_ci			 netdev->dcbnl_ops->setall(netdev));
7608c2ecf20Sopenharmony_ci	dcbnl_cee_notify(netdev, RTM_SETDCB, DCB_CMD_SET_ALL, seq, 0);
7618c2ecf20Sopenharmony_ci
7628c2ecf20Sopenharmony_ci	return ret;
7638c2ecf20Sopenharmony_ci}
7648c2ecf20Sopenharmony_ci
7658c2ecf20Sopenharmony_cistatic int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
7668c2ecf20Sopenharmony_ci			     u32 seq, struct nlattr **tb, struct sk_buff *skb,
7678c2ecf20Sopenharmony_ci			     int dir)
7688c2ecf20Sopenharmony_ci{
7698c2ecf20Sopenharmony_ci	struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
7708c2ecf20Sopenharmony_ci	struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
7718c2ecf20Sopenharmony_ci	int ret;
7728c2ecf20Sopenharmony_ci	int i;
7738c2ecf20Sopenharmony_ci	u8 pgid;
7748c2ecf20Sopenharmony_ci	u8 up_map;
7758c2ecf20Sopenharmony_ci	u8 prio;
7768c2ecf20Sopenharmony_ci	u8 tc_pct;
7778c2ecf20Sopenharmony_ci
7788c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_PG_CFG])
7798c2ecf20Sopenharmony_ci		return -EINVAL;
7808c2ecf20Sopenharmony_ci
7818c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->setpgtccfgtx ||
7828c2ecf20Sopenharmony_ci	    !netdev->dcbnl_ops->setpgtccfgrx ||
7838c2ecf20Sopenharmony_ci	    !netdev->dcbnl_ops->setpgbwgcfgtx ||
7848c2ecf20Sopenharmony_ci	    !netdev->dcbnl_ops->setpgbwgcfgrx)
7858c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
7868c2ecf20Sopenharmony_ci
7878c2ecf20Sopenharmony_ci	ret = nla_parse_nested_deprecated(pg_tb, DCB_PG_ATTR_MAX,
7888c2ecf20Sopenharmony_ci					  tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest,
7898c2ecf20Sopenharmony_ci					  NULL);
7908c2ecf20Sopenharmony_ci	if (ret)
7918c2ecf20Sopenharmony_ci		return ret;
7928c2ecf20Sopenharmony_ci
7938c2ecf20Sopenharmony_ci	for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
7948c2ecf20Sopenharmony_ci		if (!pg_tb[i])
7958c2ecf20Sopenharmony_ci			continue;
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ci		ret = nla_parse_nested_deprecated(param_tb,
7988c2ecf20Sopenharmony_ci						  DCB_TC_ATTR_PARAM_MAX,
7998c2ecf20Sopenharmony_ci						  pg_tb[i],
8008c2ecf20Sopenharmony_ci						  dcbnl_tc_param_nest, NULL);
8018c2ecf20Sopenharmony_ci		if (ret)
8028c2ecf20Sopenharmony_ci			return ret;
8038c2ecf20Sopenharmony_ci
8048c2ecf20Sopenharmony_ci		pgid = DCB_ATTR_VALUE_UNDEFINED;
8058c2ecf20Sopenharmony_ci		prio = DCB_ATTR_VALUE_UNDEFINED;
8068c2ecf20Sopenharmony_ci		tc_pct = DCB_ATTR_VALUE_UNDEFINED;
8078c2ecf20Sopenharmony_ci		up_map = DCB_ATTR_VALUE_UNDEFINED;
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_ci		if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO])
8108c2ecf20Sopenharmony_ci			prio =
8118c2ecf20Sopenharmony_ci			    nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]);
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ci		if (param_tb[DCB_TC_ATTR_PARAM_PGID])
8148c2ecf20Sopenharmony_ci			pgid = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_PGID]);
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci		if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT])
8178c2ecf20Sopenharmony_ci			tc_pct = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_BW_PCT]);
8188c2ecf20Sopenharmony_ci
8198c2ecf20Sopenharmony_ci		if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING])
8208c2ecf20Sopenharmony_ci			up_map =
8218c2ecf20Sopenharmony_ci			     nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]);
8228c2ecf20Sopenharmony_ci
8238c2ecf20Sopenharmony_ci		/* dir: Tx = 0, Rx = 1 */
8248c2ecf20Sopenharmony_ci		if (dir) {
8258c2ecf20Sopenharmony_ci			/* Rx */
8268c2ecf20Sopenharmony_ci			netdev->dcbnl_ops->setpgtccfgrx(netdev,
8278c2ecf20Sopenharmony_ci				i - DCB_PG_ATTR_TC_0,
8288c2ecf20Sopenharmony_ci				prio, pgid, tc_pct, up_map);
8298c2ecf20Sopenharmony_ci		} else {
8308c2ecf20Sopenharmony_ci			/* Tx */
8318c2ecf20Sopenharmony_ci			netdev->dcbnl_ops->setpgtccfgtx(netdev,
8328c2ecf20Sopenharmony_ci				i - DCB_PG_ATTR_TC_0,
8338c2ecf20Sopenharmony_ci				prio, pgid, tc_pct, up_map);
8348c2ecf20Sopenharmony_ci		}
8358c2ecf20Sopenharmony_ci	}
8368c2ecf20Sopenharmony_ci
8378c2ecf20Sopenharmony_ci	for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
8388c2ecf20Sopenharmony_ci		if (!pg_tb[i])
8398c2ecf20Sopenharmony_ci			continue;
8408c2ecf20Sopenharmony_ci
8418c2ecf20Sopenharmony_ci		tc_pct = nla_get_u8(pg_tb[i]);
8428c2ecf20Sopenharmony_ci
8438c2ecf20Sopenharmony_ci		/* dir: Tx = 0, Rx = 1 */
8448c2ecf20Sopenharmony_ci		if (dir) {
8458c2ecf20Sopenharmony_ci			/* Rx */
8468c2ecf20Sopenharmony_ci			netdev->dcbnl_ops->setpgbwgcfgrx(netdev,
8478c2ecf20Sopenharmony_ci					 i - DCB_PG_ATTR_BW_ID_0, tc_pct);
8488c2ecf20Sopenharmony_ci		} else {
8498c2ecf20Sopenharmony_ci			/* Tx */
8508c2ecf20Sopenharmony_ci			netdev->dcbnl_ops->setpgbwgcfgtx(netdev,
8518c2ecf20Sopenharmony_ci					 i - DCB_PG_ATTR_BW_ID_0, tc_pct);
8528c2ecf20Sopenharmony_ci		}
8538c2ecf20Sopenharmony_ci	}
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_ci	return nla_put_u8(skb, DCB_ATTR_PG_CFG, 0);
8568c2ecf20Sopenharmony_ci}
8578c2ecf20Sopenharmony_ci
8588c2ecf20Sopenharmony_cistatic int dcbnl_pgtx_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
8598c2ecf20Sopenharmony_ci			     u32 seq, struct nlattr **tb, struct sk_buff *skb)
8608c2ecf20Sopenharmony_ci{
8618c2ecf20Sopenharmony_ci	return __dcbnl_pg_setcfg(netdev, nlh, seq, tb, skb, 0);
8628c2ecf20Sopenharmony_ci}
8638c2ecf20Sopenharmony_ci
8648c2ecf20Sopenharmony_cistatic int dcbnl_pgrx_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
8658c2ecf20Sopenharmony_ci			     u32 seq, struct nlattr **tb, struct sk_buff *skb)
8668c2ecf20Sopenharmony_ci{
8678c2ecf20Sopenharmony_ci	return __dcbnl_pg_setcfg(netdev, nlh, seq, tb, skb, 1);
8688c2ecf20Sopenharmony_ci}
8698c2ecf20Sopenharmony_ci
8708c2ecf20Sopenharmony_cistatic int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlmsghdr *nlh,
8718c2ecf20Sopenharmony_ci			    u32 seq, struct nlattr **tb, struct sk_buff *skb)
8728c2ecf20Sopenharmony_ci{
8738c2ecf20Sopenharmony_ci	struct nlattr *bcn_nest;
8748c2ecf20Sopenharmony_ci	struct nlattr *bcn_tb[DCB_BCN_ATTR_MAX + 1];
8758c2ecf20Sopenharmony_ci	u8 value_byte;
8768c2ecf20Sopenharmony_ci	u32 value_integer;
8778c2ecf20Sopenharmony_ci	int ret;
8788c2ecf20Sopenharmony_ci	bool getall = false;
8798c2ecf20Sopenharmony_ci	int i;
8808c2ecf20Sopenharmony_ci
8818c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_BCN])
8828c2ecf20Sopenharmony_ci		return -EINVAL;
8838c2ecf20Sopenharmony_ci
8848c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->getbcnrp ||
8858c2ecf20Sopenharmony_ci	    !netdev->dcbnl_ops->getbcncfg)
8868c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
8878c2ecf20Sopenharmony_ci
8888c2ecf20Sopenharmony_ci	ret = nla_parse_nested_deprecated(bcn_tb, DCB_BCN_ATTR_MAX,
8898c2ecf20Sopenharmony_ci					  tb[DCB_ATTR_BCN], dcbnl_bcn_nest,
8908c2ecf20Sopenharmony_ci					  NULL);
8918c2ecf20Sopenharmony_ci	if (ret)
8928c2ecf20Sopenharmony_ci		return ret;
8938c2ecf20Sopenharmony_ci
8948c2ecf20Sopenharmony_ci	bcn_nest = nla_nest_start_noflag(skb, DCB_ATTR_BCN);
8958c2ecf20Sopenharmony_ci	if (!bcn_nest)
8968c2ecf20Sopenharmony_ci		return -EMSGSIZE;
8978c2ecf20Sopenharmony_ci
8988c2ecf20Sopenharmony_ci	if (bcn_tb[DCB_BCN_ATTR_ALL])
8998c2ecf20Sopenharmony_ci		getall = true;
9008c2ecf20Sopenharmony_ci
9018c2ecf20Sopenharmony_ci	for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
9028c2ecf20Sopenharmony_ci		if (!getall && !bcn_tb[i])
9038c2ecf20Sopenharmony_ci			continue;
9048c2ecf20Sopenharmony_ci
9058c2ecf20Sopenharmony_ci		netdev->dcbnl_ops->getbcnrp(netdev, i - DCB_BCN_ATTR_RP_0,
9068c2ecf20Sopenharmony_ci		                            &value_byte);
9078c2ecf20Sopenharmony_ci		ret = nla_put_u8(skb, i, value_byte);
9088c2ecf20Sopenharmony_ci		if (ret)
9098c2ecf20Sopenharmony_ci			goto err_bcn;
9108c2ecf20Sopenharmony_ci	}
9118c2ecf20Sopenharmony_ci
9128c2ecf20Sopenharmony_ci	for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
9138c2ecf20Sopenharmony_ci		if (!getall && !bcn_tb[i])
9148c2ecf20Sopenharmony_ci			continue;
9158c2ecf20Sopenharmony_ci
9168c2ecf20Sopenharmony_ci		netdev->dcbnl_ops->getbcncfg(netdev, i,
9178c2ecf20Sopenharmony_ci		                             &value_integer);
9188c2ecf20Sopenharmony_ci		ret = nla_put_u32(skb, i, value_integer);
9198c2ecf20Sopenharmony_ci		if (ret)
9208c2ecf20Sopenharmony_ci			goto err_bcn;
9218c2ecf20Sopenharmony_ci	}
9228c2ecf20Sopenharmony_ci
9238c2ecf20Sopenharmony_ci	nla_nest_end(skb, bcn_nest);
9248c2ecf20Sopenharmony_ci
9258c2ecf20Sopenharmony_ci	return 0;
9268c2ecf20Sopenharmony_ci
9278c2ecf20Sopenharmony_cierr_bcn:
9288c2ecf20Sopenharmony_ci	nla_nest_cancel(skb, bcn_nest);
9298c2ecf20Sopenharmony_ci	return ret;
9308c2ecf20Sopenharmony_ci}
9318c2ecf20Sopenharmony_ci
9328c2ecf20Sopenharmony_cistatic int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlmsghdr *nlh,
9338c2ecf20Sopenharmony_ci			    u32 seq, struct nlattr **tb, struct sk_buff *skb)
9348c2ecf20Sopenharmony_ci{
9358c2ecf20Sopenharmony_ci	struct nlattr *data[DCB_BCN_ATTR_MAX + 1];
9368c2ecf20Sopenharmony_ci	int i;
9378c2ecf20Sopenharmony_ci	int ret;
9388c2ecf20Sopenharmony_ci	u8 value_byte;
9398c2ecf20Sopenharmony_ci	u32 value_int;
9408c2ecf20Sopenharmony_ci
9418c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_BCN])
9428c2ecf20Sopenharmony_ci		return -EINVAL;
9438c2ecf20Sopenharmony_ci
9448c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->setbcncfg ||
9458c2ecf20Sopenharmony_ci	    !netdev->dcbnl_ops->setbcnrp)
9468c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
9478c2ecf20Sopenharmony_ci
9488c2ecf20Sopenharmony_ci	ret = nla_parse_nested_deprecated(data, DCB_BCN_ATTR_MAX,
9498c2ecf20Sopenharmony_ci					  tb[DCB_ATTR_BCN], dcbnl_bcn_nest,
9508c2ecf20Sopenharmony_ci					  NULL);
9518c2ecf20Sopenharmony_ci	if (ret)
9528c2ecf20Sopenharmony_ci		return ret;
9538c2ecf20Sopenharmony_ci
9548c2ecf20Sopenharmony_ci	for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
9558c2ecf20Sopenharmony_ci		if (data[i] == NULL)
9568c2ecf20Sopenharmony_ci			continue;
9578c2ecf20Sopenharmony_ci		value_byte = nla_get_u8(data[i]);
9588c2ecf20Sopenharmony_ci		netdev->dcbnl_ops->setbcnrp(netdev,
9598c2ecf20Sopenharmony_ci			data[i]->nla_type - DCB_BCN_ATTR_RP_0, value_byte);
9608c2ecf20Sopenharmony_ci	}
9618c2ecf20Sopenharmony_ci
9628c2ecf20Sopenharmony_ci	for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
9638c2ecf20Sopenharmony_ci		if (data[i] == NULL)
9648c2ecf20Sopenharmony_ci			continue;
9658c2ecf20Sopenharmony_ci		value_int = nla_get_u32(data[i]);
9668c2ecf20Sopenharmony_ci		netdev->dcbnl_ops->setbcncfg(netdev,
9678c2ecf20Sopenharmony_ci	                                     i, value_int);
9688c2ecf20Sopenharmony_ci	}
9698c2ecf20Sopenharmony_ci
9708c2ecf20Sopenharmony_ci	return nla_put_u8(skb, DCB_ATTR_BCN, 0);
9718c2ecf20Sopenharmony_ci}
9728c2ecf20Sopenharmony_ci
9738c2ecf20Sopenharmony_cistatic int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,
9748c2ecf20Sopenharmony_ci				int app_nested_type, int app_info_type,
9758c2ecf20Sopenharmony_ci				int app_entry_type)
9768c2ecf20Sopenharmony_ci{
9778c2ecf20Sopenharmony_ci	struct dcb_peer_app_info info;
9788c2ecf20Sopenharmony_ci	struct dcb_app *table = NULL;
9798c2ecf20Sopenharmony_ci	const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
9808c2ecf20Sopenharmony_ci	u16 app_count;
9818c2ecf20Sopenharmony_ci	int err;
9828c2ecf20Sopenharmony_ci
9838c2ecf20Sopenharmony_ci
9848c2ecf20Sopenharmony_ci	/**
9858c2ecf20Sopenharmony_ci	 * retrieve the peer app configuration form the driver. If the driver
9868c2ecf20Sopenharmony_ci	 * handlers fail exit without doing anything
9878c2ecf20Sopenharmony_ci	 */
9888c2ecf20Sopenharmony_ci	err = ops->peer_getappinfo(netdev, &info, &app_count);
9898c2ecf20Sopenharmony_ci	if (!err && app_count) {
9908c2ecf20Sopenharmony_ci		table = kmalloc_array(app_count, sizeof(struct dcb_app),
9918c2ecf20Sopenharmony_ci				      GFP_KERNEL);
9928c2ecf20Sopenharmony_ci		if (!table)
9938c2ecf20Sopenharmony_ci			return -ENOMEM;
9948c2ecf20Sopenharmony_ci
9958c2ecf20Sopenharmony_ci		err = ops->peer_getapptable(netdev, table);
9968c2ecf20Sopenharmony_ci	}
9978c2ecf20Sopenharmony_ci
9988c2ecf20Sopenharmony_ci	if (!err) {
9998c2ecf20Sopenharmony_ci		u16 i;
10008c2ecf20Sopenharmony_ci		struct nlattr *app;
10018c2ecf20Sopenharmony_ci
10028c2ecf20Sopenharmony_ci		/**
10038c2ecf20Sopenharmony_ci		 * build the message, from here on the only possible failure
10048c2ecf20Sopenharmony_ci		 * is due to the skb size
10058c2ecf20Sopenharmony_ci		 */
10068c2ecf20Sopenharmony_ci		err = -EMSGSIZE;
10078c2ecf20Sopenharmony_ci
10088c2ecf20Sopenharmony_ci		app = nla_nest_start_noflag(skb, app_nested_type);
10098c2ecf20Sopenharmony_ci		if (!app)
10108c2ecf20Sopenharmony_ci			goto nla_put_failure;
10118c2ecf20Sopenharmony_ci
10128c2ecf20Sopenharmony_ci		if (app_info_type &&
10138c2ecf20Sopenharmony_ci		    nla_put(skb, app_info_type, sizeof(info), &info))
10148c2ecf20Sopenharmony_ci			goto nla_put_failure;
10158c2ecf20Sopenharmony_ci
10168c2ecf20Sopenharmony_ci		for (i = 0; i < app_count; i++) {
10178c2ecf20Sopenharmony_ci			if (nla_put(skb, app_entry_type, sizeof(struct dcb_app),
10188c2ecf20Sopenharmony_ci				    &table[i]))
10198c2ecf20Sopenharmony_ci				goto nla_put_failure;
10208c2ecf20Sopenharmony_ci		}
10218c2ecf20Sopenharmony_ci		nla_nest_end(skb, app);
10228c2ecf20Sopenharmony_ci	}
10238c2ecf20Sopenharmony_ci	err = 0;
10248c2ecf20Sopenharmony_ci
10258c2ecf20Sopenharmony_cinla_put_failure:
10268c2ecf20Sopenharmony_ci	kfree(table);
10278c2ecf20Sopenharmony_ci	return err;
10288c2ecf20Sopenharmony_ci}
10298c2ecf20Sopenharmony_ci
10308c2ecf20Sopenharmony_ci/* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb GET commands. */
10318c2ecf20Sopenharmony_cistatic int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
10328c2ecf20Sopenharmony_ci{
10338c2ecf20Sopenharmony_ci	struct nlattr *ieee, *app;
10348c2ecf20Sopenharmony_ci	struct dcb_app_type *itr;
10358c2ecf20Sopenharmony_ci	const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
10368c2ecf20Sopenharmony_ci	int dcbx;
10378c2ecf20Sopenharmony_ci	int err;
10388c2ecf20Sopenharmony_ci
10398c2ecf20Sopenharmony_ci	if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name))
10408c2ecf20Sopenharmony_ci		return -EMSGSIZE;
10418c2ecf20Sopenharmony_ci
10428c2ecf20Sopenharmony_ci	ieee = nla_nest_start_noflag(skb, DCB_ATTR_IEEE);
10438c2ecf20Sopenharmony_ci	if (!ieee)
10448c2ecf20Sopenharmony_ci		return -EMSGSIZE;
10458c2ecf20Sopenharmony_ci
10468c2ecf20Sopenharmony_ci	if (ops->ieee_getets) {
10478c2ecf20Sopenharmony_ci		struct ieee_ets ets;
10488c2ecf20Sopenharmony_ci		memset(&ets, 0, sizeof(ets));
10498c2ecf20Sopenharmony_ci		err = ops->ieee_getets(netdev, &ets);
10508c2ecf20Sopenharmony_ci		if (!err &&
10518c2ecf20Sopenharmony_ci		    nla_put(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets))
10528c2ecf20Sopenharmony_ci			return -EMSGSIZE;
10538c2ecf20Sopenharmony_ci	}
10548c2ecf20Sopenharmony_ci
10558c2ecf20Sopenharmony_ci	if (ops->ieee_getmaxrate) {
10568c2ecf20Sopenharmony_ci		struct ieee_maxrate maxrate;
10578c2ecf20Sopenharmony_ci		memset(&maxrate, 0, sizeof(maxrate));
10588c2ecf20Sopenharmony_ci		err = ops->ieee_getmaxrate(netdev, &maxrate);
10598c2ecf20Sopenharmony_ci		if (!err) {
10608c2ecf20Sopenharmony_ci			err = nla_put(skb, DCB_ATTR_IEEE_MAXRATE,
10618c2ecf20Sopenharmony_ci				      sizeof(maxrate), &maxrate);
10628c2ecf20Sopenharmony_ci			if (err)
10638c2ecf20Sopenharmony_ci				return -EMSGSIZE;
10648c2ecf20Sopenharmony_ci		}
10658c2ecf20Sopenharmony_ci	}
10668c2ecf20Sopenharmony_ci
10678c2ecf20Sopenharmony_ci	if (ops->ieee_getqcn) {
10688c2ecf20Sopenharmony_ci		struct ieee_qcn qcn;
10698c2ecf20Sopenharmony_ci
10708c2ecf20Sopenharmony_ci		memset(&qcn, 0, sizeof(qcn));
10718c2ecf20Sopenharmony_ci		err = ops->ieee_getqcn(netdev, &qcn);
10728c2ecf20Sopenharmony_ci		if (!err) {
10738c2ecf20Sopenharmony_ci			err = nla_put(skb, DCB_ATTR_IEEE_QCN,
10748c2ecf20Sopenharmony_ci				      sizeof(qcn), &qcn);
10758c2ecf20Sopenharmony_ci			if (err)
10768c2ecf20Sopenharmony_ci				return -EMSGSIZE;
10778c2ecf20Sopenharmony_ci		}
10788c2ecf20Sopenharmony_ci	}
10798c2ecf20Sopenharmony_ci
10808c2ecf20Sopenharmony_ci	if (ops->ieee_getqcnstats) {
10818c2ecf20Sopenharmony_ci		struct ieee_qcn_stats qcn_stats;
10828c2ecf20Sopenharmony_ci
10838c2ecf20Sopenharmony_ci		memset(&qcn_stats, 0, sizeof(qcn_stats));
10848c2ecf20Sopenharmony_ci		err = ops->ieee_getqcnstats(netdev, &qcn_stats);
10858c2ecf20Sopenharmony_ci		if (!err) {
10868c2ecf20Sopenharmony_ci			err = nla_put(skb, DCB_ATTR_IEEE_QCN_STATS,
10878c2ecf20Sopenharmony_ci				      sizeof(qcn_stats), &qcn_stats);
10888c2ecf20Sopenharmony_ci			if (err)
10898c2ecf20Sopenharmony_ci				return -EMSGSIZE;
10908c2ecf20Sopenharmony_ci		}
10918c2ecf20Sopenharmony_ci	}
10928c2ecf20Sopenharmony_ci
10938c2ecf20Sopenharmony_ci	if (ops->ieee_getpfc) {
10948c2ecf20Sopenharmony_ci		struct ieee_pfc pfc;
10958c2ecf20Sopenharmony_ci		memset(&pfc, 0, sizeof(pfc));
10968c2ecf20Sopenharmony_ci		err = ops->ieee_getpfc(netdev, &pfc);
10978c2ecf20Sopenharmony_ci		if (!err &&
10988c2ecf20Sopenharmony_ci		    nla_put(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc))
10998c2ecf20Sopenharmony_ci			return -EMSGSIZE;
11008c2ecf20Sopenharmony_ci	}
11018c2ecf20Sopenharmony_ci
11028c2ecf20Sopenharmony_ci	if (ops->dcbnl_getbuffer) {
11038c2ecf20Sopenharmony_ci		struct dcbnl_buffer buffer;
11048c2ecf20Sopenharmony_ci
11058c2ecf20Sopenharmony_ci		memset(&buffer, 0, sizeof(buffer));
11068c2ecf20Sopenharmony_ci		err = ops->dcbnl_getbuffer(netdev, &buffer);
11078c2ecf20Sopenharmony_ci		if (!err &&
11088c2ecf20Sopenharmony_ci		    nla_put(skb, DCB_ATTR_DCB_BUFFER, sizeof(buffer), &buffer))
11098c2ecf20Sopenharmony_ci			return -EMSGSIZE;
11108c2ecf20Sopenharmony_ci	}
11118c2ecf20Sopenharmony_ci
11128c2ecf20Sopenharmony_ci	app = nla_nest_start_noflag(skb, DCB_ATTR_IEEE_APP_TABLE);
11138c2ecf20Sopenharmony_ci	if (!app)
11148c2ecf20Sopenharmony_ci		return -EMSGSIZE;
11158c2ecf20Sopenharmony_ci
11168c2ecf20Sopenharmony_ci	spin_lock_bh(&dcb_lock);
11178c2ecf20Sopenharmony_ci	list_for_each_entry(itr, &dcb_app_list, list) {
11188c2ecf20Sopenharmony_ci		if (itr->ifindex == netdev->ifindex) {
11198c2ecf20Sopenharmony_ci			err = nla_put(skb, DCB_ATTR_IEEE_APP, sizeof(itr->app),
11208c2ecf20Sopenharmony_ci					 &itr->app);
11218c2ecf20Sopenharmony_ci			if (err) {
11228c2ecf20Sopenharmony_ci				spin_unlock_bh(&dcb_lock);
11238c2ecf20Sopenharmony_ci				return -EMSGSIZE;
11248c2ecf20Sopenharmony_ci			}
11258c2ecf20Sopenharmony_ci		}
11268c2ecf20Sopenharmony_ci	}
11278c2ecf20Sopenharmony_ci
11288c2ecf20Sopenharmony_ci	if (netdev->dcbnl_ops->getdcbx)
11298c2ecf20Sopenharmony_ci		dcbx = netdev->dcbnl_ops->getdcbx(netdev);
11308c2ecf20Sopenharmony_ci	else
11318c2ecf20Sopenharmony_ci		dcbx = -EOPNOTSUPP;
11328c2ecf20Sopenharmony_ci
11338c2ecf20Sopenharmony_ci	spin_unlock_bh(&dcb_lock);
11348c2ecf20Sopenharmony_ci	nla_nest_end(skb, app);
11358c2ecf20Sopenharmony_ci
11368c2ecf20Sopenharmony_ci	/* get peer info if available */
11378c2ecf20Sopenharmony_ci	if (ops->ieee_peer_getets) {
11388c2ecf20Sopenharmony_ci		struct ieee_ets ets;
11398c2ecf20Sopenharmony_ci		memset(&ets, 0, sizeof(ets));
11408c2ecf20Sopenharmony_ci		err = ops->ieee_peer_getets(netdev, &ets);
11418c2ecf20Sopenharmony_ci		if (!err &&
11428c2ecf20Sopenharmony_ci		    nla_put(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets))
11438c2ecf20Sopenharmony_ci			return -EMSGSIZE;
11448c2ecf20Sopenharmony_ci	}
11458c2ecf20Sopenharmony_ci
11468c2ecf20Sopenharmony_ci	if (ops->ieee_peer_getpfc) {
11478c2ecf20Sopenharmony_ci		struct ieee_pfc pfc;
11488c2ecf20Sopenharmony_ci		memset(&pfc, 0, sizeof(pfc));
11498c2ecf20Sopenharmony_ci		err = ops->ieee_peer_getpfc(netdev, &pfc);
11508c2ecf20Sopenharmony_ci		if (!err &&
11518c2ecf20Sopenharmony_ci		    nla_put(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc))
11528c2ecf20Sopenharmony_ci			return -EMSGSIZE;
11538c2ecf20Sopenharmony_ci	}
11548c2ecf20Sopenharmony_ci
11558c2ecf20Sopenharmony_ci	if (ops->peer_getappinfo && ops->peer_getapptable) {
11568c2ecf20Sopenharmony_ci		err = dcbnl_build_peer_app(netdev, skb,
11578c2ecf20Sopenharmony_ci					   DCB_ATTR_IEEE_PEER_APP,
11588c2ecf20Sopenharmony_ci					   DCB_ATTR_IEEE_APP_UNSPEC,
11598c2ecf20Sopenharmony_ci					   DCB_ATTR_IEEE_APP);
11608c2ecf20Sopenharmony_ci		if (err)
11618c2ecf20Sopenharmony_ci			return -EMSGSIZE;
11628c2ecf20Sopenharmony_ci	}
11638c2ecf20Sopenharmony_ci
11648c2ecf20Sopenharmony_ci	nla_nest_end(skb, ieee);
11658c2ecf20Sopenharmony_ci	if (dcbx >= 0) {
11668c2ecf20Sopenharmony_ci		err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx);
11678c2ecf20Sopenharmony_ci		if (err)
11688c2ecf20Sopenharmony_ci			return -EMSGSIZE;
11698c2ecf20Sopenharmony_ci	}
11708c2ecf20Sopenharmony_ci
11718c2ecf20Sopenharmony_ci	return 0;
11728c2ecf20Sopenharmony_ci}
11738c2ecf20Sopenharmony_ci
11748c2ecf20Sopenharmony_cistatic int dcbnl_cee_pg_fill(struct sk_buff *skb, struct net_device *dev,
11758c2ecf20Sopenharmony_ci			     int dir)
11768c2ecf20Sopenharmony_ci{
11778c2ecf20Sopenharmony_ci	u8 pgid, up_map, prio, tc_pct;
11788c2ecf20Sopenharmony_ci	const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops;
11798c2ecf20Sopenharmony_ci	int i = dir ? DCB_ATTR_CEE_TX_PG : DCB_ATTR_CEE_RX_PG;
11808c2ecf20Sopenharmony_ci	struct nlattr *pg = nla_nest_start_noflag(skb, i);
11818c2ecf20Sopenharmony_ci
11828c2ecf20Sopenharmony_ci	if (!pg)
11838c2ecf20Sopenharmony_ci		return -EMSGSIZE;
11848c2ecf20Sopenharmony_ci
11858c2ecf20Sopenharmony_ci	for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
11868c2ecf20Sopenharmony_ci		struct nlattr *tc_nest = nla_nest_start_noflag(skb, i);
11878c2ecf20Sopenharmony_ci
11888c2ecf20Sopenharmony_ci		if (!tc_nest)
11898c2ecf20Sopenharmony_ci			return -EMSGSIZE;
11908c2ecf20Sopenharmony_ci
11918c2ecf20Sopenharmony_ci		pgid = DCB_ATTR_VALUE_UNDEFINED;
11928c2ecf20Sopenharmony_ci		prio = DCB_ATTR_VALUE_UNDEFINED;
11938c2ecf20Sopenharmony_ci		tc_pct = DCB_ATTR_VALUE_UNDEFINED;
11948c2ecf20Sopenharmony_ci		up_map = DCB_ATTR_VALUE_UNDEFINED;
11958c2ecf20Sopenharmony_ci
11968c2ecf20Sopenharmony_ci		if (!dir)
11978c2ecf20Sopenharmony_ci			ops->getpgtccfgrx(dev, i - DCB_PG_ATTR_TC_0,
11988c2ecf20Sopenharmony_ci					  &prio, &pgid, &tc_pct, &up_map);
11998c2ecf20Sopenharmony_ci		else
12008c2ecf20Sopenharmony_ci			ops->getpgtccfgtx(dev, i - DCB_PG_ATTR_TC_0,
12018c2ecf20Sopenharmony_ci					  &prio, &pgid, &tc_pct, &up_map);
12028c2ecf20Sopenharmony_ci
12038c2ecf20Sopenharmony_ci		if (nla_put_u8(skb, DCB_TC_ATTR_PARAM_PGID, pgid) ||
12048c2ecf20Sopenharmony_ci		    nla_put_u8(skb, DCB_TC_ATTR_PARAM_UP_MAPPING, up_map) ||
12058c2ecf20Sopenharmony_ci		    nla_put_u8(skb, DCB_TC_ATTR_PARAM_STRICT_PRIO, prio) ||
12068c2ecf20Sopenharmony_ci		    nla_put_u8(skb, DCB_TC_ATTR_PARAM_BW_PCT, tc_pct))
12078c2ecf20Sopenharmony_ci			return -EMSGSIZE;
12088c2ecf20Sopenharmony_ci		nla_nest_end(skb, tc_nest);
12098c2ecf20Sopenharmony_ci	}
12108c2ecf20Sopenharmony_ci
12118c2ecf20Sopenharmony_ci	for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
12128c2ecf20Sopenharmony_ci		tc_pct = DCB_ATTR_VALUE_UNDEFINED;
12138c2ecf20Sopenharmony_ci
12148c2ecf20Sopenharmony_ci		if (!dir)
12158c2ecf20Sopenharmony_ci			ops->getpgbwgcfgrx(dev, i - DCB_PG_ATTR_BW_ID_0,
12168c2ecf20Sopenharmony_ci					   &tc_pct);
12178c2ecf20Sopenharmony_ci		else
12188c2ecf20Sopenharmony_ci			ops->getpgbwgcfgtx(dev, i - DCB_PG_ATTR_BW_ID_0,
12198c2ecf20Sopenharmony_ci					   &tc_pct);
12208c2ecf20Sopenharmony_ci		if (nla_put_u8(skb, i, tc_pct))
12218c2ecf20Sopenharmony_ci			return -EMSGSIZE;
12228c2ecf20Sopenharmony_ci	}
12238c2ecf20Sopenharmony_ci	nla_nest_end(skb, pg);
12248c2ecf20Sopenharmony_ci	return 0;
12258c2ecf20Sopenharmony_ci}
12268c2ecf20Sopenharmony_ci
12278c2ecf20Sopenharmony_cistatic int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
12288c2ecf20Sopenharmony_ci{
12298c2ecf20Sopenharmony_ci	struct nlattr *cee, *app;
12308c2ecf20Sopenharmony_ci	struct dcb_app_type *itr;
12318c2ecf20Sopenharmony_ci	const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
12328c2ecf20Sopenharmony_ci	int dcbx, i, err = -EMSGSIZE;
12338c2ecf20Sopenharmony_ci	u8 value;
12348c2ecf20Sopenharmony_ci
12358c2ecf20Sopenharmony_ci	if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name))
12368c2ecf20Sopenharmony_ci		goto nla_put_failure;
12378c2ecf20Sopenharmony_ci	cee = nla_nest_start_noflag(skb, DCB_ATTR_CEE);
12388c2ecf20Sopenharmony_ci	if (!cee)
12398c2ecf20Sopenharmony_ci		goto nla_put_failure;
12408c2ecf20Sopenharmony_ci
12418c2ecf20Sopenharmony_ci	/* local pg */
12428c2ecf20Sopenharmony_ci	if (ops->getpgtccfgtx && ops->getpgbwgcfgtx) {
12438c2ecf20Sopenharmony_ci		err = dcbnl_cee_pg_fill(skb, netdev, 1);
12448c2ecf20Sopenharmony_ci		if (err)
12458c2ecf20Sopenharmony_ci			goto nla_put_failure;
12468c2ecf20Sopenharmony_ci	}
12478c2ecf20Sopenharmony_ci
12488c2ecf20Sopenharmony_ci	if (ops->getpgtccfgrx && ops->getpgbwgcfgrx) {
12498c2ecf20Sopenharmony_ci		err = dcbnl_cee_pg_fill(skb, netdev, 0);
12508c2ecf20Sopenharmony_ci		if (err)
12518c2ecf20Sopenharmony_ci			goto nla_put_failure;
12528c2ecf20Sopenharmony_ci	}
12538c2ecf20Sopenharmony_ci
12548c2ecf20Sopenharmony_ci	/* local pfc */
12558c2ecf20Sopenharmony_ci	if (ops->getpfccfg) {
12568c2ecf20Sopenharmony_ci		struct nlattr *pfc_nest = nla_nest_start_noflag(skb,
12578c2ecf20Sopenharmony_ci								DCB_ATTR_CEE_PFC);
12588c2ecf20Sopenharmony_ci
12598c2ecf20Sopenharmony_ci		if (!pfc_nest)
12608c2ecf20Sopenharmony_ci			goto nla_put_failure;
12618c2ecf20Sopenharmony_ci
12628c2ecf20Sopenharmony_ci		for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
12638c2ecf20Sopenharmony_ci			ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0, &value);
12648c2ecf20Sopenharmony_ci			if (nla_put_u8(skb, i, value))
12658c2ecf20Sopenharmony_ci				goto nla_put_failure;
12668c2ecf20Sopenharmony_ci		}
12678c2ecf20Sopenharmony_ci		nla_nest_end(skb, pfc_nest);
12688c2ecf20Sopenharmony_ci	}
12698c2ecf20Sopenharmony_ci
12708c2ecf20Sopenharmony_ci	/* local app */
12718c2ecf20Sopenharmony_ci	spin_lock_bh(&dcb_lock);
12728c2ecf20Sopenharmony_ci	app = nla_nest_start_noflag(skb, DCB_ATTR_CEE_APP_TABLE);
12738c2ecf20Sopenharmony_ci	if (!app)
12748c2ecf20Sopenharmony_ci		goto dcb_unlock;
12758c2ecf20Sopenharmony_ci
12768c2ecf20Sopenharmony_ci	list_for_each_entry(itr, &dcb_app_list, list) {
12778c2ecf20Sopenharmony_ci		if (itr->ifindex == netdev->ifindex) {
12788c2ecf20Sopenharmony_ci			struct nlattr *app_nest = nla_nest_start_noflag(skb,
12798c2ecf20Sopenharmony_ci									DCB_ATTR_APP);
12808c2ecf20Sopenharmony_ci			if (!app_nest)
12818c2ecf20Sopenharmony_ci				goto dcb_unlock;
12828c2ecf20Sopenharmony_ci
12838c2ecf20Sopenharmony_ci			err = nla_put_u8(skb, DCB_APP_ATTR_IDTYPE,
12848c2ecf20Sopenharmony_ci					 itr->app.selector);
12858c2ecf20Sopenharmony_ci			if (err)
12868c2ecf20Sopenharmony_ci				goto dcb_unlock;
12878c2ecf20Sopenharmony_ci
12888c2ecf20Sopenharmony_ci			err = nla_put_u16(skb, DCB_APP_ATTR_ID,
12898c2ecf20Sopenharmony_ci					  itr->app.protocol);
12908c2ecf20Sopenharmony_ci			if (err)
12918c2ecf20Sopenharmony_ci				goto dcb_unlock;
12928c2ecf20Sopenharmony_ci
12938c2ecf20Sopenharmony_ci			err = nla_put_u8(skb, DCB_APP_ATTR_PRIORITY,
12948c2ecf20Sopenharmony_ci					 itr->app.priority);
12958c2ecf20Sopenharmony_ci			if (err)
12968c2ecf20Sopenharmony_ci				goto dcb_unlock;
12978c2ecf20Sopenharmony_ci
12988c2ecf20Sopenharmony_ci			nla_nest_end(skb, app_nest);
12998c2ecf20Sopenharmony_ci		}
13008c2ecf20Sopenharmony_ci	}
13018c2ecf20Sopenharmony_ci	nla_nest_end(skb, app);
13028c2ecf20Sopenharmony_ci
13038c2ecf20Sopenharmony_ci	if (netdev->dcbnl_ops->getdcbx)
13048c2ecf20Sopenharmony_ci		dcbx = netdev->dcbnl_ops->getdcbx(netdev);
13058c2ecf20Sopenharmony_ci	else
13068c2ecf20Sopenharmony_ci		dcbx = -EOPNOTSUPP;
13078c2ecf20Sopenharmony_ci
13088c2ecf20Sopenharmony_ci	spin_unlock_bh(&dcb_lock);
13098c2ecf20Sopenharmony_ci
13108c2ecf20Sopenharmony_ci	/* features flags */
13118c2ecf20Sopenharmony_ci	if (ops->getfeatcfg) {
13128c2ecf20Sopenharmony_ci		struct nlattr *feat = nla_nest_start_noflag(skb,
13138c2ecf20Sopenharmony_ci							    DCB_ATTR_CEE_FEAT);
13148c2ecf20Sopenharmony_ci		if (!feat)
13158c2ecf20Sopenharmony_ci			goto nla_put_failure;
13168c2ecf20Sopenharmony_ci
13178c2ecf20Sopenharmony_ci		for (i = DCB_FEATCFG_ATTR_ALL + 1; i <= DCB_FEATCFG_ATTR_MAX;
13188c2ecf20Sopenharmony_ci		     i++)
13198c2ecf20Sopenharmony_ci			if (!ops->getfeatcfg(netdev, i, &value) &&
13208c2ecf20Sopenharmony_ci			    nla_put_u8(skb, i, value))
13218c2ecf20Sopenharmony_ci				goto nla_put_failure;
13228c2ecf20Sopenharmony_ci
13238c2ecf20Sopenharmony_ci		nla_nest_end(skb, feat);
13248c2ecf20Sopenharmony_ci	}
13258c2ecf20Sopenharmony_ci
13268c2ecf20Sopenharmony_ci	/* peer info if available */
13278c2ecf20Sopenharmony_ci	if (ops->cee_peer_getpg) {
13288c2ecf20Sopenharmony_ci		struct cee_pg pg;
13298c2ecf20Sopenharmony_ci		memset(&pg, 0, sizeof(pg));
13308c2ecf20Sopenharmony_ci		err = ops->cee_peer_getpg(netdev, &pg);
13318c2ecf20Sopenharmony_ci		if (!err &&
13328c2ecf20Sopenharmony_ci		    nla_put(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg))
13338c2ecf20Sopenharmony_ci			goto nla_put_failure;
13348c2ecf20Sopenharmony_ci	}
13358c2ecf20Sopenharmony_ci
13368c2ecf20Sopenharmony_ci	if (ops->cee_peer_getpfc) {
13378c2ecf20Sopenharmony_ci		struct cee_pfc pfc;
13388c2ecf20Sopenharmony_ci		memset(&pfc, 0, sizeof(pfc));
13398c2ecf20Sopenharmony_ci		err = ops->cee_peer_getpfc(netdev, &pfc);
13408c2ecf20Sopenharmony_ci		if (!err &&
13418c2ecf20Sopenharmony_ci		    nla_put(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc))
13428c2ecf20Sopenharmony_ci			goto nla_put_failure;
13438c2ecf20Sopenharmony_ci	}
13448c2ecf20Sopenharmony_ci
13458c2ecf20Sopenharmony_ci	if (ops->peer_getappinfo && ops->peer_getapptable) {
13468c2ecf20Sopenharmony_ci		err = dcbnl_build_peer_app(netdev, skb,
13478c2ecf20Sopenharmony_ci					   DCB_ATTR_CEE_PEER_APP_TABLE,
13488c2ecf20Sopenharmony_ci					   DCB_ATTR_CEE_PEER_APP_INFO,
13498c2ecf20Sopenharmony_ci					   DCB_ATTR_CEE_PEER_APP);
13508c2ecf20Sopenharmony_ci		if (err)
13518c2ecf20Sopenharmony_ci			goto nla_put_failure;
13528c2ecf20Sopenharmony_ci	}
13538c2ecf20Sopenharmony_ci	nla_nest_end(skb, cee);
13548c2ecf20Sopenharmony_ci
13558c2ecf20Sopenharmony_ci	/* DCBX state */
13568c2ecf20Sopenharmony_ci	if (dcbx >= 0) {
13578c2ecf20Sopenharmony_ci		err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx);
13588c2ecf20Sopenharmony_ci		if (err)
13598c2ecf20Sopenharmony_ci			goto nla_put_failure;
13608c2ecf20Sopenharmony_ci	}
13618c2ecf20Sopenharmony_ci	return 0;
13628c2ecf20Sopenharmony_ci
13638c2ecf20Sopenharmony_cidcb_unlock:
13648c2ecf20Sopenharmony_ci	spin_unlock_bh(&dcb_lock);
13658c2ecf20Sopenharmony_cinla_put_failure:
13668c2ecf20Sopenharmony_ci	err = -EMSGSIZE;
13678c2ecf20Sopenharmony_ci	return err;
13688c2ecf20Sopenharmony_ci}
13698c2ecf20Sopenharmony_ci
13708c2ecf20Sopenharmony_cistatic int dcbnl_notify(struct net_device *dev, int event, int cmd,
13718c2ecf20Sopenharmony_ci			u32 seq, u32 portid, int dcbx_ver)
13728c2ecf20Sopenharmony_ci{
13738c2ecf20Sopenharmony_ci	struct net *net = dev_net(dev);
13748c2ecf20Sopenharmony_ci	struct sk_buff *skb;
13758c2ecf20Sopenharmony_ci	struct nlmsghdr *nlh;
13768c2ecf20Sopenharmony_ci	const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops;
13778c2ecf20Sopenharmony_ci	int err;
13788c2ecf20Sopenharmony_ci
13798c2ecf20Sopenharmony_ci	if (!ops)
13808c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
13818c2ecf20Sopenharmony_ci
13828c2ecf20Sopenharmony_ci	skb = dcbnl_newmsg(event, cmd, portid, seq, 0, &nlh);
13838c2ecf20Sopenharmony_ci	if (!skb)
13848c2ecf20Sopenharmony_ci		return -ENOBUFS;
13858c2ecf20Sopenharmony_ci
13868c2ecf20Sopenharmony_ci	if (dcbx_ver == DCB_CAP_DCBX_VER_IEEE)
13878c2ecf20Sopenharmony_ci		err = dcbnl_ieee_fill(skb, dev);
13888c2ecf20Sopenharmony_ci	else
13898c2ecf20Sopenharmony_ci		err = dcbnl_cee_fill(skb, dev);
13908c2ecf20Sopenharmony_ci
13918c2ecf20Sopenharmony_ci	if (err < 0) {
13928c2ecf20Sopenharmony_ci		/* Report error to broadcast listeners */
13938c2ecf20Sopenharmony_ci		nlmsg_free(skb);
13948c2ecf20Sopenharmony_ci		rtnl_set_sk_err(net, RTNLGRP_DCB, err);
13958c2ecf20Sopenharmony_ci	} else {
13968c2ecf20Sopenharmony_ci		/* End nlmsg and notify broadcast listeners */
13978c2ecf20Sopenharmony_ci		nlmsg_end(skb, nlh);
13988c2ecf20Sopenharmony_ci		rtnl_notify(skb, net, 0, RTNLGRP_DCB, NULL, GFP_KERNEL);
13998c2ecf20Sopenharmony_ci	}
14008c2ecf20Sopenharmony_ci
14018c2ecf20Sopenharmony_ci	return err;
14028c2ecf20Sopenharmony_ci}
14038c2ecf20Sopenharmony_ci
14048c2ecf20Sopenharmony_ciint dcbnl_ieee_notify(struct net_device *dev, int event, int cmd,
14058c2ecf20Sopenharmony_ci		      u32 seq, u32 portid)
14068c2ecf20Sopenharmony_ci{
14078c2ecf20Sopenharmony_ci	return dcbnl_notify(dev, event, cmd, seq, portid, DCB_CAP_DCBX_VER_IEEE);
14088c2ecf20Sopenharmony_ci}
14098c2ecf20Sopenharmony_ciEXPORT_SYMBOL(dcbnl_ieee_notify);
14108c2ecf20Sopenharmony_ci
14118c2ecf20Sopenharmony_ciint dcbnl_cee_notify(struct net_device *dev, int event, int cmd,
14128c2ecf20Sopenharmony_ci		     u32 seq, u32 portid)
14138c2ecf20Sopenharmony_ci{
14148c2ecf20Sopenharmony_ci	return dcbnl_notify(dev, event, cmd, seq, portid, DCB_CAP_DCBX_VER_CEE);
14158c2ecf20Sopenharmony_ci}
14168c2ecf20Sopenharmony_ciEXPORT_SYMBOL(dcbnl_cee_notify);
14178c2ecf20Sopenharmony_ci
14188c2ecf20Sopenharmony_ci/* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb SET commands.
14198c2ecf20Sopenharmony_ci * If any requested operation can not be completed
14208c2ecf20Sopenharmony_ci * the entire msg is aborted and error value is returned.
14218c2ecf20Sopenharmony_ci * No attempt is made to reconcile the case where only part of the
14228c2ecf20Sopenharmony_ci * cmd can be completed.
14238c2ecf20Sopenharmony_ci */
14248c2ecf20Sopenharmony_cistatic int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh,
14258c2ecf20Sopenharmony_ci			  u32 seq, struct nlattr **tb, struct sk_buff *skb)
14268c2ecf20Sopenharmony_ci{
14278c2ecf20Sopenharmony_ci	const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
14288c2ecf20Sopenharmony_ci	struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
14298c2ecf20Sopenharmony_ci	int prio;
14308c2ecf20Sopenharmony_ci	int err;
14318c2ecf20Sopenharmony_ci
14328c2ecf20Sopenharmony_ci	if (!ops)
14338c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
14348c2ecf20Sopenharmony_ci
14358c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_IEEE])
14368c2ecf20Sopenharmony_ci		return -EINVAL;
14378c2ecf20Sopenharmony_ci
14388c2ecf20Sopenharmony_ci	err = nla_parse_nested_deprecated(ieee, DCB_ATTR_IEEE_MAX,
14398c2ecf20Sopenharmony_ci					  tb[DCB_ATTR_IEEE],
14408c2ecf20Sopenharmony_ci					  dcbnl_ieee_policy, NULL);
14418c2ecf20Sopenharmony_ci	if (err)
14428c2ecf20Sopenharmony_ci		return err;
14438c2ecf20Sopenharmony_ci
14448c2ecf20Sopenharmony_ci	if (ieee[DCB_ATTR_IEEE_ETS] && ops->ieee_setets) {
14458c2ecf20Sopenharmony_ci		struct ieee_ets *ets = nla_data(ieee[DCB_ATTR_IEEE_ETS]);
14468c2ecf20Sopenharmony_ci		err = ops->ieee_setets(netdev, ets);
14478c2ecf20Sopenharmony_ci		if (err)
14488c2ecf20Sopenharmony_ci			goto err;
14498c2ecf20Sopenharmony_ci	}
14508c2ecf20Sopenharmony_ci
14518c2ecf20Sopenharmony_ci	if (ieee[DCB_ATTR_IEEE_MAXRATE] && ops->ieee_setmaxrate) {
14528c2ecf20Sopenharmony_ci		struct ieee_maxrate *maxrate =
14538c2ecf20Sopenharmony_ci			nla_data(ieee[DCB_ATTR_IEEE_MAXRATE]);
14548c2ecf20Sopenharmony_ci		err = ops->ieee_setmaxrate(netdev, maxrate);
14558c2ecf20Sopenharmony_ci		if (err)
14568c2ecf20Sopenharmony_ci			goto err;
14578c2ecf20Sopenharmony_ci	}
14588c2ecf20Sopenharmony_ci
14598c2ecf20Sopenharmony_ci	if (ieee[DCB_ATTR_IEEE_QCN] && ops->ieee_setqcn) {
14608c2ecf20Sopenharmony_ci		struct ieee_qcn *qcn =
14618c2ecf20Sopenharmony_ci			nla_data(ieee[DCB_ATTR_IEEE_QCN]);
14628c2ecf20Sopenharmony_ci
14638c2ecf20Sopenharmony_ci		err = ops->ieee_setqcn(netdev, qcn);
14648c2ecf20Sopenharmony_ci		if (err)
14658c2ecf20Sopenharmony_ci			goto err;
14668c2ecf20Sopenharmony_ci	}
14678c2ecf20Sopenharmony_ci
14688c2ecf20Sopenharmony_ci	if (ieee[DCB_ATTR_IEEE_PFC] && ops->ieee_setpfc) {
14698c2ecf20Sopenharmony_ci		struct ieee_pfc *pfc = nla_data(ieee[DCB_ATTR_IEEE_PFC]);
14708c2ecf20Sopenharmony_ci		err = ops->ieee_setpfc(netdev, pfc);
14718c2ecf20Sopenharmony_ci		if (err)
14728c2ecf20Sopenharmony_ci			goto err;
14738c2ecf20Sopenharmony_ci	}
14748c2ecf20Sopenharmony_ci
14758c2ecf20Sopenharmony_ci	if (ieee[DCB_ATTR_DCB_BUFFER] && ops->dcbnl_setbuffer) {
14768c2ecf20Sopenharmony_ci		struct dcbnl_buffer *buffer =
14778c2ecf20Sopenharmony_ci			nla_data(ieee[DCB_ATTR_DCB_BUFFER]);
14788c2ecf20Sopenharmony_ci
14798c2ecf20Sopenharmony_ci		for (prio = 0; prio < ARRAY_SIZE(buffer->prio2buffer); prio++) {
14808c2ecf20Sopenharmony_ci			if (buffer->prio2buffer[prio] >= DCBX_MAX_BUFFERS) {
14818c2ecf20Sopenharmony_ci				err = -EINVAL;
14828c2ecf20Sopenharmony_ci				goto err;
14838c2ecf20Sopenharmony_ci			}
14848c2ecf20Sopenharmony_ci		}
14858c2ecf20Sopenharmony_ci
14868c2ecf20Sopenharmony_ci		err = ops->dcbnl_setbuffer(netdev, buffer);
14878c2ecf20Sopenharmony_ci		if (err)
14888c2ecf20Sopenharmony_ci			goto err;
14898c2ecf20Sopenharmony_ci	}
14908c2ecf20Sopenharmony_ci
14918c2ecf20Sopenharmony_ci	if (ieee[DCB_ATTR_IEEE_APP_TABLE]) {
14928c2ecf20Sopenharmony_ci		struct nlattr *attr;
14938c2ecf20Sopenharmony_ci		int rem;
14948c2ecf20Sopenharmony_ci
14958c2ecf20Sopenharmony_ci		nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) {
14968c2ecf20Sopenharmony_ci			struct dcb_app *app_data;
14978c2ecf20Sopenharmony_ci
14988c2ecf20Sopenharmony_ci			if (nla_type(attr) != DCB_ATTR_IEEE_APP)
14998c2ecf20Sopenharmony_ci				continue;
15008c2ecf20Sopenharmony_ci
15018c2ecf20Sopenharmony_ci			if (nla_len(attr) < sizeof(struct dcb_app)) {
15028c2ecf20Sopenharmony_ci				err = -ERANGE;
15038c2ecf20Sopenharmony_ci				goto err;
15048c2ecf20Sopenharmony_ci			}
15058c2ecf20Sopenharmony_ci
15068c2ecf20Sopenharmony_ci			app_data = nla_data(attr);
15078c2ecf20Sopenharmony_ci			if (ops->ieee_setapp)
15088c2ecf20Sopenharmony_ci				err = ops->ieee_setapp(netdev, app_data);
15098c2ecf20Sopenharmony_ci			else
15108c2ecf20Sopenharmony_ci				err = dcb_ieee_setapp(netdev, app_data);
15118c2ecf20Sopenharmony_ci			if (err)
15128c2ecf20Sopenharmony_ci				goto err;
15138c2ecf20Sopenharmony_ci		}
15148c2ecf20Sopenharmony_ci	}
15158c2ecf20Sopenharmony_ci
15168c2ecf20Sopenharmony_cierr:
15178c2ecf20Sopenharmony_ci	err = nla_put_u8(skb, DCB_ATTR_IEEE, err);
15188c2ecf20Sopenharmony_ci	dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_SET, seq, 0);
15198c2ecf20Sopenharmony_ci	return err;
15208c2ecf20Sopenharmony_ci}
15218c2ecf20Sopenharmony_ci
15228c2ecf20Sopenharmony_cistatic int dcbnl_ieee_get(struct net_device *netdev, struct nlmsghdr *nlh,
15238c2ecf20Sopenharmony_ci			  u32 seq, struct nlattr **tb, struct sk_buff *skb)
15248c2ecf20Sopenharmony_ci{
15258c2ecf20Sopenharmony_ci	const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
15268c2ecf20Sopenharmony_ci
15278c2ecf20Sopenharmony_ci	if (!ops)
15288c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
15298c2ecf20Sopenharmony_ci
15308c2ecf20Sopenharmony_ci	return dcbnl_ieee_fill(skb, netdev);
15318c2ecf20Sopenharmony_ci}
15328c2ecf20Sopenharmony_ci
15338c2ecf20Sopenharmony_cistatic int dcbnl_ieee_del(struct net_device *netdev, struct nlmsghdr *nlh,
15348c2ecf20Sopenharmony_ci			  u32 seq, struct nlattr **tb, struct sk_buff *skb)
15358c2ecf20Sopenharmony_ci{
15368c2ecf20Sopenharmony_ci	const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
15378c2ecf20Sopenharmony_ci	struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
15388c2ecf20Sopenharmony_ci	int err;
15398c2ecf20Sopenharmony_ci
15408c2ecf20Sopenharmony_ci	if (!ops)
15418c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
15428c2ecf20Sopenharmony_ci
15438c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_IEEE])
15448c2ecf20Sopenharmony_ci		return -EINVAL;
15458c2ecf20Sopenharmony_ci
15468c2ecf20Sopenharmony_ci	err = nla_parse_nested_deprecated(ieee, DCB_ATTR_IEEE_MAX,
15478c2ecf20Sopenharmony_ci					  tb[DCB_ATTR_IEEE],
15488c2ecf20Sopenharmony_ci					  dcbnl_ieee_policy, NULL);
15498c2ecf20Sopenharmony_ci	if (err)
15508c2ecf20Sopenharmony_ci		return err;
15518c2ecf20Sopenharmony_ci
15528c2ecf20Sopenharmony_ci	if (ieee[DCB_ATTR_IEEE_APP_TABLE]) {
15538c2ecf20Sopenharmony_ci		struct nlattr *attr;
15548c2ecf20Sopenharmony_ci		int rem;
15558c2ecf20Sopenharmony_ci
15568c2ecf20Sopenharmony_ci		nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) {
15578c2ecf20Sopenharmony_ci			struct dcb_app *app_data;
15588c2ecf20Sopenharmony_ci
15598c2ecf20Sopenharmony_ci			if (nla_type(attr) != DCB_ATTR_IEEE_APP)
15608c2ecf20Sopenharmony_ci				continue;
15618c2ecf20Sopenharmony_ci			app_data = nla_data(attr);
15628c2ecf20Sopenharmony_ci			if (ops->ieee_delapp)
15638c2ecf20Sopenharmony_ci				err = ops->ieee_delapp(netdev, app_data);
15648c2ecf20Sopenharmony_ci			else
15658c2ecf20Sopenharmony_ci				err = dcb_ieee_delapp(netdev, app_data);
15668c2ecf20Sopenharmony_ci			if (err)
15678c2ecf20Sopenharmony_ci				goto err;
15688c2ecf20Sopenharmony_ci		}
15698c2ecf20Sopenharmony_ci	}
15708c2ecf20Sopenharmony_ci
15718c2ecf20Sopenharmony_cierr:
15728c2ecf20Sopenharmony_ci	err = nla_put_u8(skb, DCB_ATTR_IEEE, err);
15738c2ecf20Sopenharmony_ci	dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_DEL, seq, 0);
15748c2ecf20Sopenharmony_ci	return err;
15758c2ecf20Sopenharmony_ci}
15768c2ecf20Sopenharmony_ci
15778c2ecf20Sopenharmony_ci
15788c2ecf20Sopenharmony_ci/* DCBX configuration */
15798c2ecf20Sopenharmony_cistatic int dcbnl_getdcbx(struct net_device *netdev, struct nlmsghdr *nlh,
15808c2ecf20Sopenharmony_ci			 u32 seq, struct nlattr **tb, struct sk_buff *skb)
15818c2ecf20Sopenharmony_ci{
15828c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->getdcbx)
15838c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
15848c2ecf20Sopenharmony_ci
15858c2ecf20Sopenharmony_ci	return nla_put_u8(skb, DCB_ATTR_DCBX,
15868c2ecf20Sopenharmony_ci			  netdev->dcbnl_ops->getdcbx(netdev));
15878c2ecf20Sopenharmony_ci}
15888c2ecf20Sopenharmony_ci
15898c2ecf20Sopenharmony_cistatic int dcbnl_setdcbx(struct net_device *netdev, struct nlmsghdr *nlh,
15908c2ecf20Sopenharmony_ci			 u32 seq, struct nlattr **tb, struct sk_buff *skb)
15918c2ecf20Sopenharmony_ci{
15928c2ecf20Sopenharmony_ci	u8 value;
15938c2ecf20Sopenharmony_ci
15948c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->setdcbx)
15958c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
15968c2ecf20Sopenharmony_ci
15978c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_DCBX])
15988c2ecf20Sopenharmony_ci		return -EINVAL;
15998c2ecf20Sopenharmony_ci
16008c2ecf20Sopenharmony_ci	value = nla_get_u8(tb[DCB_ATTR_DCBX]);
16018c2ecf20Sopenharmony_ci
16028c2ecf20Sopenharmony_ci	return nla_put_u8(skb, DCB_ATTR_DCBX,
16038c2ecf20Sopenharmony_ci			  netdev->dcbnl_ops->setdcbx(netdev, value));
16048c2ecf20Sopenharmony_ci}
16058c2ecf20Sopenharmony_ci
16068c2ecf20Sopenharmony_cistatic int dcbnl_getfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh,
16078c2ecf20Sopenharmony_ci			    u32 seq, struct nlattr **tb, struct sk_buff *skb)
16088c2ecf20Sopenharmony_ci{
16098c2ecf20Sopenharmony_ci	struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1], *nest;
16108c2ecf20Sopenharmony_ci	u8 value;
16118c2ecf20Sopenharmony_ci	int ret, i;
16128c2ecf20Sopenharmony_ci	int getall = 0;
16138c2ecf20Sopenharmony_ci
16148c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->getfeatcfg)
16158c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
16168c2ecf20Sopenharmony_ci
16178c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_FEATCFG])
16188c2ecf20Sopenharmony_ci		return -EINVAL;
16198c2ecf20Sopenharmony_ci
16208c2ecf20Sopenharmony_ci	ret = nla_parse_nested_deprecated(data, DCB_FEATCFG_ATTR_MAX,
16218c2ecf20Sopenharmony_ci					  tb[DCB_ATTR_FEATCFG],
16228c2ecf20Sopenharmony_ci					  dcbnl_featcfg_nest, NULL);
16238c2ecf20Sopenharmony_ci	if (ret)
16248c2ecf20Sopenharmony_ci		return ret;
16258c2ecf20Sopenharmony_ci
16268c2ecf20Sopenharmony_ci	nest = nla_nest_start_noflag(skb, DCB_ATTR_FEATCFG);
16278c2ecf20Sopenharmony_ci	if (!nest)
16288c2ecf20Sopenharmony_ci		return -EMSGSIZE;
16298c2ecf20Sopenharmony_ci
16308c2ecf20Sopenharmony_ci	if (data[DCB_FEATCFG_ATTR_ALL])
16318c2ecf20Sopenharmony_ci		getall = 1;
16328c2ecf20Sopenharmony_ci
16338c2ecf20Sopenharmony_ci	for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
16348c2ecf20Sopenharmony_ci		if (!getall && !data[i])
16358c2ecf20Sopenharmony_ci			continue;
16368c2ecf20Sopenharmony_ci
16378c2ecf20Sopenharmony_ci		ret = netdev->dcbnl_ops->getfeatcfg(netdev, i, &value);
16388c2ecf20Sopenharmony_ci		if (!ret)
16398c2ecf20Sopenharmony_ci			ret = nla_put_u8(skb, i, value);
16408c2ecf20Sopenharmony_ci
16418c2ecf20Sopenharmony_ci		if (ret) {
16428c2ecf20Sopenharmony_ci			nla_nest_cancel(skb, nest);
16438c2ecf20Sopenharmony_ci			goto nla_put_failure;
16448c2ecf20Sopenharmony_ci		}
16458c2ecf20Sopenharmony_ci	}
16468c2ecf20Sopenharmony_ci	nla_nest_end(skb, nest);
16478c2ecf20Sopenharmony_ci
16488c2ecf20Sopenharmony_cinla_put_failure:
16498c2ecf20Sopenharmony_ci	return ret;
16508c2ecf20Sopenharmony_ci}
16518c2ecf20Sopenharmony_ci
16528c2ecf20Sopenharmony_cistatic int dcbnl_setfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh,
16538c2ecf20Sopenharmony_ci			    u32 seq, struct nlattr **tb, struct sk_buff *skb)
16548c2ecf20Sopenharmony_ci{
16558c2ecf20Sopenharmony_ci	struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1];
16568c2ecf20Sopenharmony_ci	int ret, i;
16578c2ecf20Sopenharmony_ci	u8 value;
16588c2ecf20Sopenharmony_ci
16598c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops->setfeatcfg)
16608c2ecf20Sopenharmony_ci		return -ENOTSUPP;
16618c2ecf20Sopenharmony_ci
16628c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_FEATCFG])
16638c2ecf20Sopenharmony_ci		return -EINVAL;
16648c2ecf20Sopenharmony_ci
16658c2ecf20Sopenharmony_ci	ret = nla_parse_nested_deprecated(data, DCB_FEATCFG_ATTR_MAX,
16668c2ecf20Sopenharmony_ci					  tb[DCB_ATTR_FEATCFG],
16678c2ecf20Sopenharmony_ci					  dcbnl_featcfg_nest, NULL);
16688c2ecf20Sopenharmony_ci
16698c2ecf20Sopenharmony_ci	if (ret)
16708c2ecf20Sopenharmony_ci		goto err;
16718c2ecf20Sopenharmony_ci
16728c2ecf20Sopenharmony_ci	for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
16738c2ecf20Sopenharmony_ci		if (data[i] == NULL)
16748c2ecf20Sopenharmony_ci			continue;
16758c2ecf20Sopenharmony_ci
16768c2ecf20Sopenharmony_ci		value = nla_get_u8(data[i]);
16778c2ecf20Sopenharmony_ci
16788c2ecf20Sopenharmony_ci		ret = netdev->dcbnl_ops->setfeatcfg(netdev, i, value);
16798c2ecf20Sopenharmony_ci
16808c2ecf20Sopenharmony_ci		if (ret)
16818c2ecf20Sopenharmony_ci			goto err;
16828c2ecf20Sopenharmony_ci	}
16838c2ecf20Sopenharmony_cierr:
16848c2ecf20Sopenharmony_ci	ret = nla_put_u8(skb, DCB_ATTR_FEATCFG, ret);
16858c2ecf20Sopenharmony_ci
16868c2ecf20Sopenharmony_ci	return ret;
16878c2ecf20Sopenharmony_ci}
16888c2ecf20Sopenharmony_ci
16898c2ecf20Sopenharmony_ci/* Handle CEE DCBX GET commands. */
16908c2ecf20Sopenharmony_cistatic int dcbnl_cee_get(struct net_device *netdev, struct nlmsghdr *nlh,
16918c2ecf20Sopenharmony_ci			 u32 seq, struct nlattr **tb, struct sk_buff *skb)
16928c2ecf20Sopenharmony_ci{
16938c2ecf20Sopenharmony_ci	const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
16948c2ecf20Sopenharmony_ci
16958c2ecf20Sopenharmony_ci	if (!ops)
16968c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
16978c2ecf20Sopenharmony_ci
16988c2ecf20Sopenharmony_ci	return dcbnl_cee_fill(skb, netdev);
16998c2ecf20Sopenharmony_ci}
17008c2ecf20Sopenharmony_ci
17018c2ecf20Sopenharmony_cistruct reply_func {
17028c2ecf20Sopenharmony_ci	/* reply netlink message type */
17038c2ecf20Sopenharmony_ci	int	type;
17048c2ecf20Sopenharmony_ci
17058c2ecf20Sopenharmony_ci	/* function to fill message contents */
17068c2ecf20Sopenharmony_ci	int   (*cb)(struct net_device *, struct nlmsghdr *, u32,
17078c2ecf20Sopenharmony_ci		    struct nlattr **, struct sk_buff *);
17088c2ecf20Sopenharmony_ci};
17098c2ecf20Sopenharmony_ci
17108c2ecf20Sopenharmony_cistatic const struct reply_func reply_funcs[DCB_CMD_MAX+1] = {
17118c2ecf20Sopenharmony_ci	[DCB_CMD_GSTATE]	= { RTM_GETDCB, dcbnl_getstate },
17128c2ecf20Sopenharmony_ci	[DCB_CMD_SSTATE]	= { RTM_SETDCB, dcbnl_setstate },
17138c2ecf20Sopenharmony_ci	[DCB_CMD_PFC_GCFG]	= { RTM_GETDCB, dcbnl_getpfccfg },
17148c2ecf20Sopenharmony_ci	[DCB_CMD_PFC_SCFG]	= { RTM_SETDCB, dcbnl_setpfccfg },
17158c2ecf20Sopenharmony_ci	[DCB_CMD_GPERM_HWADDR]	= { RTM_GETDCB, dcbnl_getperm_hwaddr },
17168c2ecf20Sopenharmony_ci	[DCB_CMD_GCAP]		= { RTM_GETDCB, dcbnl_getcap },
17178c2ecf20Sopenharmony_ci	[DCB_CMD_GNUMTCS]	= { RTM_GETDCB, dcbnl_getnumtcs },
17188c2ecf20Sopenharmony_ci	[DCB_CMD_SNUMTCS]	= { RTM_SETDCB, dcbnl_setnumtcs },
17198c2ecf20Sopenharmony_ci	[DCB_CMD_PFC_GSTATE]	= { RTM_GETDCB, dcbnl_getpfcstate },
17208c2ecf20Sopenharmony_ci	[DCB_CMD_PFC_SSTATE]	= { RTM_SETDCB, dcbnl_setpfcstate },
17218c2ecf20Sopenharmony_ci	[DCB_CMD_GAPP]		= { RTM_GETDCB, dcbnl_getapp },
17228c2ecf20Sopenharmony_ci	[DCB_CMD_SAPP]		= { RTM_SETDCB, dcbnl_setapp },
17238c2ecf20Sopenharmony_ci	[DCB_CMD_PGTX_GCFG]	= { RTM_GETDCB, dcbnl_pgtx_getcfg },
17248c2ecf20Sopenharmony_ci	[DCB_CMD_PGTX_SCFG]	= { RTM_SETDCB, dcbnl_pgtx_setcfg },
17258c2ecf20Sopenharmony_ci	[DCB_CMD_PGRX_GCFG]	= { RTM_GETDCB, dcbnl_pgrx_getcfg },
17268c2ecf20Sopenharmony_ci	[DCB_CMD_PGRX_SCFG]	= { RTM_SETDCB, dcbnl_pgrx_setcfg },
17278c2ecf20Sopenharmony_ci	[DCB_CMD_SET_ALL]	= { RTM_SETDCB, dcbnl_setall },
17288c2ecf20Sopenharmony_ci	[DCB_CMD_BCN_GCFG]	= { RTM_GETDCB, dcbnl_bcn_getcfg },
17298c2ecf20Sopenharmony_ci	[DCB_CMD_BCN_SCFG]	= { RTM_SETDCB, dcbnl_bcn_setcfg },
17308c2ecf20Sopenharmony_ci	[DCB_CMD_IEEE_GET]	= { RTM_GETDCB, dcbnl_ieee_get },
17318c2ecf20Sopenharmony_ci	[DCB_CMD_IEEE_SET]	= { RTM_SETDCB, dcbnl_ieee_set },
17328c2ecf20Sopenharmony_ci	[DCB_CMD_IEEE_DEL]	= { RTM_SETDCB, dcbnl_ieee_del },
17338c2ecf20Sopenharmony_ci	[DCB_CMD_GDCBX]		= { RTM_GETDCB, dcbnl_getdcbx },
17348c2ecf20Sopenharmony_ci	[DCB_CMD_SDCBX]		= { RTM_SETDCB, dcbnl_setdcbx },
17358c2ecf20Sopenharmony_ci	[DCB_CMD_GFEATCFG]	= { RTM_GETDCB, dcbnl_getfeatcfg },
17368c2ecf20Sopenharmony_ci	[DCB_CMD_SFEATCFG]	= { RTM_SETDCB, dcbnl_setfeatcfg },
17378c2ecf20Sopenharmony_ci	[DCB_CMD_CEE_GET]	= { RTM_GETDCB, dcbnl_cee_get },
17388c2ecf20Sopenharmony_ci};
17398c2ecf20Sopenharmony_ci
17408c2ecf20Sopenharmony_cistatic int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
17418c2ecf20Sopenharmony_ci		    struct netlink_ext_ack *extack)
17428c2ecf20Sopenharmony_ci{
17438c2ecf20Sopenharmony_ci	struct net *net = sock_net(skb->sk);
17448c2ecf20Sopenharmony_ci	struct net_device *netdev;
17458c2ecf20Sopenharmony_ci	struct dcbmsg *dcb = nlmsg_data(nlh);
17468c2ecf20Sopenharmony_ci	struct nlattr *tb[DCB_ATTR_MAX + 1];
17478c2ecf20Sopenharmony_ci	u32 portid = NETLINK_CB(skb).portid;
17488c2ecf20Sopenharmony_ci	int ret = -EINVAL;
17498c2ecf20Sopenharmony_ci	struct sk_buff *reply_skb;
17508c2ecf20Sopenharmony_ci	struct nlmsghdr *reply_nlh = NULL;
17518c2ecf20Sopenharmony_ci	const struct reply_func *fn;
17528c2ecf20Sopenharmony_ci
17538c2ecf20Sopenharmony_ci	if ((nlh->nlmsg_type == RTM_SETDCB) && !netlink_capable(skb, CAP_NET_ADMIN))
17548c2ecf20Sopenharmony_ci		return -EPERM;
17558c2ecf20Sopenharmony_ci
17568c2ecf20Sopenharmony_ci	ret = nlmsg_parse_deprecated(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
17578c2ecf20Sopenharmony_ci				     dcbnl_rtnl_policy, extack);
17588c2ecf20Sopenharmony_ci	if (ret < 0)
17598c2ecf20Sopenharmony_ci		return ret;
17608c2ecf20Sopenharmony_ci
17618c2ecf20Sopenharmony_ci	if (dcb->cmd > DCB_CMD_MAX)
17628c2ecf20Sopenharmony_ci		return -EINVAL;
17638c2ecf20Sopenharmony_ci
17648c2ecf20Sopenharmony_ci	/* check if a reply function has been defined for the command */
17658c2ecf20Sopenharmony_ci	fn = &reply_funcs[dcb->cmd];
17668c2ecf20Sopenharmony_ci	if (!fn->cb)
17678c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
17688c2ecf20Sopenharmony_ci	if (fn->type == RTM_SETDCB && !netlink_capable(skb, CAP_NET_ADMIN))
17698c2ecf20Sopenharmony_ci		return -EPERM;
17708c2ecf20Sopenharmony_ci
17718c2ecf20Sopenharmony_ci	if (!tb[DCB_ATTR_IFNAME])
17728c2ecf20Sopenharmony_ci		return -EINVAL;
17738c2ecf20Sopenharmony_ci
17748c2ecf20Sopenharmony_ci	netdev = __dev_get_by_name(net, nla_data(tb[DCB_ATTR_IFNAME]));
17758c2ecf20Sopenharmony_ci	if (!netdev)
17768c2ecf20Sopenharmony_ci		return -ENODEV;
17778c2ecf20Sopenharmony_ci
17788c2ecf20Sopenharmony_ci	if (!netdev->dcbnl_ops)
17798c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
17808c2ecf20Sopenharmony_ci
17818c2ecf20Sopenharmony_ci	reply_skb = dcbnl_newmsg(fn->type, dcb->cmd, portid, nlh->nlmsg_seq,
17828c2ecf20Sopenharmony_ci				 nlh->nlmsg_flags, &reply_nlh);
17838c2ecf20Sopenharmony_ci	if (!reply_skb)
17848c2ecf20Sopenharmony_ci		return -ENOBUFS;
17858c2ecf20Sopenharmony_ci
17868c2ecf20Sopenharmony_ci	ret = fn->cb(netdev, nlh, nlh->nlmsg_seq, tb, reply_skb);
17878c2ecf20Sopenharmony_ci	if (ret < 0) {
17888c2ecf20Sopenharmony_ci		nlmsg_free(reply_skb);
17898c2ecf20Sopenharmony_ci		goto out;
17908c2ecf20Sopenharmony_ci	}
17918c2ecf20Sopenharmony_ci
17928c2ecf20Sopenharmony_ci	nlmsg_end(reply_skb, reply_nlh);
17938c2ecf20Sopenharmony_ci
17948c2ecf20Sopenharmony_ci	ret = rtnl_unicast(reply_skb, net, portid);
17958c2ecf20Sopenharmony_ciout:
17968c2ecf20Sopenharmony_ci	return ret;
17978c2ecf20Sopenharmony_ci}
17988c2ecf20Sopenharmony_ci
17998c2ecf20Sopenharmony_cistatic struct dcb_app_type *dcb_app_lookup(const struct dcb_app *app,
18008c2ecf20Sopenharmony_ci					   int ifindex, int prio)
18018c2ecf20Sopenharmony_ci{
18028c2ecf20Sopenharmony_ci	struct dcb_app_type *itr;
18038c2ecf20Sopenharmony_ci
18048c2ecf20Sopenharmony_ci	list_for_each_entry(itr, &dcb_app_list, list) {
18058c2ecf20Sopenharmony_ci		if (itr->app.selector == app->selector &&
18068c2ecf20Sopenharmony_ci		    itr->app.protocol == app->protocol &&
18078c2ecf20Sopenharmony_ci		    itr->ifindex == ifindex &&
18088c2ecf20Sopenharmony_ci		    ((prio == -1) || itr->app.priority == prio))
18098c2ecf20Sopenharmony_ci			return itr;
18108c2ecf20Sopenharmony_ci	}
18118c2ecf20Sopenharmony_ci
18128c2ecf20Sopenharmony_ci	return NULL;
18138c2ecf20Sopenharmony_ci}
18148c2ecf20Sopenharmony_ci
18158c2ecf20Sopenharmony_cistatic int dcb_app_add(const struct dcb_app *app, int ifindex)
18168c2ecf20Sopenharmony_ci{
18178c2ecf20Sopenharmony_ci	struct dcb_app_type *entry;
18188c2ecf20Sopenharmony_ci
18198c2ecf20Sopenharmony_ci	entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
18208c2ecf20Sopenharmony_ci	if (!entry)
18218c2ecf20Sopenharmony_ci		return -ENOMEM;
18228c2ecf20Sopenharmony_ci
18238c2ecf20Sopenharmony_ci	memcpy(&entry->app, app, sizeof(*app));
18248c2ecf20Sopenharmony_ci	entry->ifindex = ifindex;
18258c2ecf20Sopenharmony_ci	list_add(&entry->list, &dcb_app_list);
18268c2ecf20Sopenharmony_ci
18278c2ecf20Sopenharmony_ci	return 0;
18288c2ecf20Sopenharmony_ci}
18298c2ecf20Sopenharmony_ci
18308c2ecf20Sopenharmony_ci/**
18318c2ecf20Sopenharmony_ci * dcb_getapp - retrieve the DCBX application user priority
18328c2ecf20Sopenharmony_ci *
18338c2ecf20Sopenharmony_ci * On success returns a non-zero 802.1p user priority bitmap
18348c2ecf20Sopenharmony_ci * otherwise returns 0 as the invalid user priority bitmap to
18358c2ecf20Sopenharmony_ci * indicate an error.
18368c2ecf20Sopenharmony_ci */
18378c2ecf20Sopenharmony_ciu8 dcb_getapp(struct net_device *dev, struct dcb_app *app)
18388c2ecf20Sopenharmony_ci{
18398c2ecf20Sopenharmony_ci	struct dcb_app_type *itr;
18408c2ecf20Sopenharmony_ci	u8 prio = 0;
18418c2ecf20Sopenharmony_ci
18428c2ecf20Sopenharmony_ci	spin_lock_bh(&dcb_lock);
18438c2ecf20Sopenharmony_ci	itr = dcb_app_lookup(app, dev->ifindex, -1);
18448c2ecf20Sopenharmony_ci	if (itr)
18458c2ecf20Sopenharmony_ci		prio = itr->app.priority;
18468c2ecf20Sopenharmony_ci	spin_unlock_bh(&dcb_lock);
18478c2ecf20Sopenharmony_ci
18488c2ecf20Sopenharmony_ci	return prio;
18498c2ecf20Sopenharmony_ci}
18508c2ecf20Sopenharmony_ciEXPORT_SYMBOL(dcb_getapp);
18518c2ecf20Sopenharmony_ci
18528c2ecf20Sopenharmony_ci/**
18538c2ecf20Sopenharmony_ci * dcb_setapp - add CEE dcb application data to app list
18548c2ecf20Sopenharmony_ci *
18558c2ecf20Sopenharmony_ci * Priority 0 is an invalid priority in CEE spec. This routine
18568c2ecf20Sopenharmony_ci * removes applications from the app list if the priority is
18578c2ecf20Sopenharmony_ci * set to zero. Priority is expected to be 8-bit 802.1p user priority bitmap
18588c2ecf20Sopenharmony_ci */
18598c2ecf20Sopenharmony_ciint dcb_setapp(struct net_device *dev, struct dcb_app *new)
18608c2ecf20Sopenharmony_ci{
18618c2ecf20Sopenharmony_ci	struct dcb_app_type *itr;
18628c2ecf20Sopenharmony_ci	struct dcb_app_type event;
18638c2ecf20Sopenharmony_ci	int err = 0;
18648c2ecf20Sopenharmony_ci
18658c2ecf20Sopenharmony_ci	event.ifindex = dev->ifindex;
18668c2ecf20Sopenharmony_ci	memcpy(&event.app, new, sizeof(event.app));
18678c2ecf20Sopenharmony_ci	if (dev->dcbnl_ops->getdcbx)
18688c2ecf20Sopenharmony_ci		event.dcbx = dev->dcbnl_ops->getdcbx(dev);
18698c2ecf20Sopenharmony_ci
18708c2ecf20Sopenharmony_ci	spin_lock_bh(&dcb_lock);
18718c2ecf20Sopenharmony_ci	/* Search for existing match and replace */
18728c2ecf20Sopenharmony_ci	itr = dcb_app_lookup(new, dev->ifindex, -1);
18738c2ecf20Sopenharmony_ci	if (itr) {
18748c2ecf20Sopenharmony_ci		if (new->priority)
18758c2ecf20Sopenharmony_ci			itr->app.priority = new->priority;
18768c2ecf20Sopenharmony_ci		else {
18778c2ecf20Sopenharmony_ci			list_del(&itr->list);
18788c2ecf20Sopenharmony_ci			kfree(itr);
18798c2ecf20Sopenharmony_ci		}
18808c2ecf20Sopenharmony_ci		goto out;
18818c2ecf20Sopenharmony_ci	}
18828c2ecf20Sopenharmony_ci	/* App type does not exist add new application type */
18838c2ecf20Sopenharmony_ci	if (new->priority)
18848c2ecf20Sopenharmony_ci		err = dcb_app_add(new, dev->ifindex);
18858c2ecf20Sopenharmony_ciout:
18868c2ecf20Sopenharmony_ci	spin_unlock_bh(&dcb_lock);
18878c2ecf20Sopenharmony_ci	if (!err)
18888c2ecf20Sopenharmony_ci		call_dcbevent_notifiers(DCB_APP_EVENT, &event);
18898c2ecf20Sopenharmony_ci	return err;
18908c2ecf20Sopenharmony_ci}
18918c2ecf20Sopenharmony_ciEXPORT_SYMBOL(dcb_setapp);
18928c2ecf20Sopenharmony_ci
18938c2ecf20Sopenharmony_ci/**
18948c2ecf20Sopenharmony_ci * dcb_ieee_getapp_mask - retrieve the IEEE DCB application priority
18958c2ecf20Sopenharmony_ci *
18968c2ecf20Sopenharmony_ci * Helper routine which on success returns a non-zero 802.1Qaz user
18978c2ecf20Sopenharmony_ci * priority bitmap otherwise returns 0 to indicate the dcb_app was
18988c2ecf20Sopenharmony_ci * not found in APP list.
18998c2ecf20Sopenharmony_ci */
19008c2ecf20Sopenharmony_ciu8 dcb_ieee_getapp_mask(struct net_device *dev, struct dcb_app *app)
19018c2ecf20Sopenharmony_ci{
19028c2ecf20Sopenharmony_ci	struct dcb_app_type *itr;
19038c2ecf20Sopenharmony_ci	u8 prio = 0;
19048c2ecf20Sopenharmony_ci
19058c2ecf20Sopenharmony_ci	spin_lock_bh(&dcb_lock);
19068c2ecf20Sopenharmony_ci	itr = dcb_app_lookup(app, dev->ifindex, -1);
19078c2ecf20Sopenharmony_ci	if (itr)
19088c2ecf20Sopenharmony_ci		prio |= 1 << itr->app.priority;
19098c2ecf20Sopenharmony_ci	spin_unlock_bh(&dcb_lock);
19108c2ecf20Sopenharmony_ci
19118c2ecf20Sopenharmony_ci	return prio;
19128c2ecf20Sopenharmony_ci}
19138c2ecf20Sopenharmony_ciEXPORT_SYMBOL(dcb_ieee_getapp_mask);
19148c2ecf20Sopenharmony_ci
19158c2ecf20Sopenharmony_ci/**
19168c2ecf20Sopenharmony_ci * dcb_ieee_setapp - add IEEE dcb application data to app list
19178c2ecf20Sopenharmony_ci *
19188c2ecf20Sopenharmony_ci * This adds Application data to the list. Multiple application
19198c2ecf20Sopenharmony_ci * entries may exists for the same selector and protocol as long
19208c2ecf20Sopenharmony_ci * as the priorities are different. Priority is expected to be a
19218c2ecf20Sopenharmony_ci * 3-bit unsigned integer
19228c2ecf20Sopenharmony_ci */
19238c2ecf20Sopenharmony_ciint dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new)
19248c2ecf20Sopenharmony_ci{
19258c2ecf20Sopenharmony_ci	struct dcb_app_type event;
19268c2ecf20Sopenharmony_ci	int err = 0;
19278c2ecf20Sopenharmony_ci
19288c2ecf20Sopenharmony_ci	event.ifindex = dev->ifindex;
19298c2ecf20Sopenharmony_ci	memcpy(&event.app, new, sizeof(event.app));
19308c2ecf20Sopenharmony_ci	if (dev->dcbnl_ops->getdcbx)
19318c2ecf20Sopenharmony_ci		event.dcbx = dev->dcbnl_ops->getdcbx(dev);
19328c2ecf20Sopenharmony_ci
19338c2ecf20Sopenharmony_ci	spin_lock_bh(&dcb_lock);
19348c2ecf20Sopenharmony_ci	/* Search for existing match and abort if found */
19358c2ecf20Sopenharmony_ci	if (dcb_app_lookup(new, dev->ifindex, new->priority)) {
19368c2ecf20Sopenharmony_ci		err = -EEXIST;
19378c2ecf20Sopenharmony_ci		goto out;
19388c2ecf20Sopenharmony_ci	}
19398c2ecf20Sopenharmony_ci
19408c2ecf20Sopenharmony_ci	err = dcb_app_add(new, dev->ifindex);
19418c2ecf20Sopenharmony_ciout:
19428c2ecf20Sopenharmony_ci	spin_unlock_bh(&dcb_lock);
19438c2ecf20Sopenharmony_ci	if (!err)
19448c2ecf20Sopenharmony_ci		call_dcbevent_notifiers(DCB_APP_EVENT, &event);
19458c2ecf20Sopenharmony_ci	return err;
19468c2ecf20Sopenharmony_ci}
19478c2ecf20Sopenharmony_ciEXPORT_SYMBOL(dcb_ieee_setapp);
19488c2ecf20Sopenharmony_ci
19498c2ecf20Sopenharmony_ci/**
19508c2ecf20Sopenharmony_ci * dcb_ieee_delapp - delete IEEE dcb application data from list
19518c2ecf20Sopenharmony_ci *
19528c2ecf20Sopenharmony_ci * This removes a matching APP data from the APP list
19538c2ecf20Sopenharmony_ci */
19548c2ecf20Sopenharmony_ciint dcb_ieee_delapp(struct net_device *dev, struct dcb_app *del)
19558c2ecf20Sopenharmony_ci{
19568c2ecf20Sopenharmony_ci	struct dcb_app_type *itr;
19578c2ecf20Sopenharmony_ci	struct dcb_app_type event;
19588c2ecf20Sopenharmony_ci	int err = -ENOENT;
19598c2ecf20Sopenharmony_ci
19608c2ecf20Sopenharmony_ci	event.ifindex = dev->ifindex;
19618c2ecf20Sopenharmony_ci	memcpy(&event.app, del, sizeof(event.app));
19628c2ecf20Sopenharmony_ci	if (dev->dcbnl_ops->getdcbx)
19638c2ecf20Sopenharmony_ci		event.dcbx = dev->dcbnl_ops->getdcbx(dev);
19648c2ecf20Sopenharmony_ci
19658c2ecf20Sopenharmony_ci	spin_lock_bh(&dcb_lock);
19668c2ecf20Sopenharmony_ci	/* Search for existing match and remove it. */
19678c2ecf20Sopenharmony_ci	if ((itr = dcb_app_lookup(del, dev->ifindex, del->priority))) {
19688c2ecf20Sopenharmony_ci		list_del(&itr->list);
19698c2ecf20Sopenharmony_ci		kfree(itr);
19708c2ecf20Sopenharmony_ci		err = 0;
19718c2ecf20Sopenharmony_ci	}
19728c2ecf20Sopenharmony_ci
19738c2ecf20Sopenharmony_ci	spin_unlock_bh(&dcb_lock);
19748c2ecf20Sopenharmony_ci	if (!err)
19758c2ecf20Sopenharmony_ci		call_dcbevent_notifiers(DCB_APP_EVENT, &event);
19768c2ecf20Sopenharmony_ci	return err;
19778c2ecf20Sopenharmony_ci}
19788c2ecf20Sopenharmony_ciEXPORT_SYMBOL(dcb_ieee_delapp);
19798c2ecf20Sopenharmony_ci
19808c2ecf20Sopenharmony_ci/**
19818c2ecf20Sopenharmony_ci * dcb_ieee_getapp_prio_dscp_mask_map - For a given device, find mapping from
19828c2ecf20Sopenharmony_ci * priorities to the DSCP values assigned to that priority. Initialize p_map
19838c2ecf20Sopenharmony_ci * such that each map element holds a bit mask of DSCP values configured for
19848c2ecf20Sopenharmony_ci * that priority by APP entries.
19858c2ecf20Sopenharmony_ci */
19868c2ecf20Sopenharmony_civoid dcb_ieee_getapp_prio_dscp_mask_map(const struct net_device *dev,
19878c2ecf20Sopenharmony_ci					struct dcb_ieee_app_prio_map *p_map)
19888c2ecf20Sopenharmony_ci{
19898c2ecf20Sopenharmony_ci	int ifindex = dev->ifindex;
19908c2ecf20Sopenharmony_ci	struct dcb_app_type *itr;
19918c2ecf20Sopenharmony_ci	u8 prio;
19928c2ecf20Sopenharmony_ci
19938c2ecf20Sopenharmony_ci	memset(p_map->map, 0, sizeof(p_map->map));
19948c2ecf20Sopenharmony_ci
19958c2ecf20Sopenharmony_ci	spin_lock_bh(&dcb_lock);
19968c2ecf20Sopenharmony_ci	list_for_each_entry(itr, &dcb_app_list, list) {
19978c2ecf20Sopenharmony_ci		if (itr->ifindex == ifindex &&
19988c2ecf20Sopenharmony_ci		    itr->app.selector == IEEE_8021QAZ_APP_SEL_DSCP &&
19998c2ecf20Sopenharmony_ci		    itr->app.protocol < 64 &&
20008c2ecf20Sopenharmony_ci		    itr->app.priority < IEEE_8021QAZ_MAX_TCS) {
20018c2ecf20Sopenharmony_ci			prio = itr->app.priority;
20028c2ecf20Sopenharmony_ci			p_map->map[prio] |= 1ULL << itr->app.protocol;
20038c2ecf20Sopenharmony_ci		}
20048c2ecf20Sopenharmony_ci	}
20058c2ecf20Sopenharmony_ci	spin_unlock_bh(&dcb_lock);
20068c2ecf20Sopenharmony_ci}
20078c2ecf20Sopenharmony_ciEXPORT_SYMBOL(dcb_ieee_getapp_prio_dscp_mask_map);
20088c2ecf20Sopenharmony_ci
20098c2ecf20Sopenharmony_ci/**
20108c2ecf20Sopenharmony_ci * dcb_ieee_getapp_dscp_prio_mask_map - For a given device, find mapping from
20118c2ecf20Sopenharmony_ci * DSCP values to the priorities assigned to that DSCP value. Initialize p_map
20128c2ecf20Sopenharmony_ci * such that each map element holds a bit mask of priorities configured for a
20138c2ecf20Sopenharmony_ci * given DSCP value by APP entries.
20148c2ecf20Sopenharmony_ci */
20158c2ecf20Sopenharmony_civoid
20168c2ecf20Sopenharmony_cidcb_ieee_getapp_dscp_prio_mask_map(const struct net_device *dev,
20178c2ecf20Sopenharmony_ci				   struct dcb_ieee_app_dscp_map *p_map)
20188c2ecf20Sopenharmony_ci{
20198c2ecf20Sopenharmony_ci	int ifindex = dev->ifindex;
20208c2ecf20Sopenharmony_ci	struct dcb_app_type *itr;
20218c2ecf20Sopenharmony_ci
20228c2ecf20Sopenharmony_ci	memset(p_map->map, 0, sizeof(p_map->map));
20238c2ecf20Sopenharmony_ci
20248c2ecf20Sopenharmony_ci	spin_lock_bh(&dcb_lock);
20258c2ecf20Sopenharmony_ci	list_for_each_entry(itr, &dcb_app_list, list) {
20268c2ecf20Sopenharmony_ci		if (itr->ifindex == ifindex &&
20278c2ecf20Sopenharmony_ci		    itr->app.selector == IEEE_8021QAZ_APP_SEL_DSCP &&
20288c2ecf20Sopenharmony_ci		    itr->app.protocol < 64 &&
20298c2ecf20Sopenharmony_ci		    itr->app.priority < IEEE_8021QAZ_MAX_TCS)
20308c2ecf20Sopenharmony_ci			p_map->map[itr->app.protocol] |= 1 << itr->app.priority;
20318c2ecf20Sopenharmony_ci	}
20328c2ecf20Sopenharmony_ci	spin_unlock_bh(&dcb_lock);
20338c2ecf20Sopenharmony_ci}
20348c2ecf20Sopenharmony_ciEXPORT_SYMBOL(dcb_ieee_getapp_dscp_prio_mask_map);
20358c2ecf20Sopenharmony_ci
20368c2ecf20Sopenharmony_ci/**
20378c2ecf20Sopenharmony_ci * Per 802.1Q-2014, the selector value of 1 is used for matching on Ethernet
20388c2ecf20Sopenharmony_ci * type, with valid PID values >= 1536. A special meaning is then assigned to
20398c2ecf20Sopenharmony_ci * protocol value of 0: "default priority. For use when priority is not
20408c2ecf20Sopenharmony_ci * otherwise specified".
20418c2ecf20Sopenharmony_ci *
20428c2ecf20Sopenharmony_ci * dcb_ieee_getapp_default_prio_mask - For a given device, find all APP entries
20438c2ecf20Sopenharmony_ci * of the form {$PRIO, ETHERTYPE, 0} and construct a bit mask of all default
20448c2ecf20Sopenharmony_ci * priorities set by these entries.
20458c2ecf20Sopenharmony_ci */
20468c2ecf20Sopenharmony_ciu8 dcb_ieee_getapp_default_prio_mask(const struct net_device *dev)
20478c2ecf20Sopenharmony_ci{
20488c2ecf20Sopenharmony_ci	int ifindex = dev->ifindex;
20498c2ecf20Sopenharmony_ci	struct dcb_app_type *itr;
20508c2ecf20Sopenharmony_ci	u8 mask = 0;
20518c2ecf20Sopenharmony_ci
20528c2ecf20Sopenharmony_ci	spin_lock_bh(&dcb_lock);
20538c2ecf20Sopenharmony_ci	list_for_each_entry(itr, &dcb_app_list, list) {
20548c2ecf20Sopenharmony_ci		if (itr->ifindex == ifindex &&
20558c2ecf20Sopenharmony_ci		    itr->app.selector == IEEE_8021QAZ_APP_SEL_ETHERTYPE &&
20568c2ecf20Sopenharmony_ci		    itr->app.protocol == 0 &&
20578c2ecf20Sopenharmony_ci		    itr->app.priority < IEEE_8021QAZ_MAX_TCS)
20588c2ecf20Sopenharmony_ci			mask |= 1 << itr->app.priority;
20598c2ecf20Sopenharmony_ci	}
20608c2ecf20Sopenharmony_ci	spin_unlock_bh(&dcb_lock);
20618c2ecf20Sopenharmony_ci
20628c2ecf20Sopenharmony_ci	return mask;
20638c2ecf20Sopenharmony_ci}
20648c2ecf20Sopenharmony_ciEXPORT_SYMBOL(dcb_ieee_getapp_default_prio_mask);
20658c2ecf20Sopenharmony_ci
20668c2ecf20Sopenharmony_cistatic void dcbnl_flush_dev(struct net_device *dev)
20678c2ecf20Sopenharmony_ci{
20688c2ecf20Sopenharmony_ci	struct dcb_app_type *itr, *tmp;
20698c2ecf20Sopenharmony_ci
20708c2ecf20Sopenharmony_ci	spin_lock_bh(&dcb_lock);
20718c2ecf20Sopenharmony_ci
20728c2ecf20Sopenharmony_ci	list_for_each_entry_safe(itr, tmp, &dcb_app_list, list) {
20738c2ecf20Sopenharmony_ci		if (itr->ifindex == dev->ifindex) {
20748c2ecf20Sopenharmony_ci			list_del(&itr->list);
20758c2ecf20Sopenharmony_ci			kfree(itr);
20768c2ecf20Sopenharmony_ci		}
20778c2ecf20Sopenharmony_ci	}
20788c2ecf20Sopenharmony_ci
20798c2ecf20Sopenharmony_ci	spin_unlock_bh(&dcb_lock);
20808c2ecf20Sopenharmony_ci}
20818c2ecf20Sopenharmony_ci
20828c2ecf20Sopenharmony_cistatic int dcbnl_netdevice_event(struct notifier_block *nb,
20838c2ecf20Sopenharmony_ci				 unsigned long event, void *ptr)
20848c2ecf20Sopenharmony_ci{
20858c2ecf20Sopenharmony_ci	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
20868c2ecf20Sopenharmony_ci
20878c2ecf20Sopenharmony_ci	switch (event) {
20888c2ecf20Sopenharmony_ci	case NETDEV_UNREGISTER:
20898c2ecf20Sopenharmony_ci		if (!dev->dcbnl_ops)
20908c2ecf20Sopenharmony_ci			return NOTIFY_DONE;
20918c2ecf20Sopenharmony_ci
20928c2ecf20Sopenharmony_ci		dcbnl_flush_dev(dev);
20938c2ecf20Sopenharmony_ci
20948c2ecf20Sopenharmony_ci		return NOTIFY_OK;
20958c2ecf20Sopenharmony_ci	default:
20968c2ecf20Sopenharmony_ci		return NOTIFY_DONE;
20978c2ecf20Sopenharmony_ci	}
20988c2ecf20Sopenharmony_ci}
20998c2ecf20Sopenharmony_ci
21008c2ecf20Sopenharmony_cistatic struct notifier_block dcbnl_nb __read_mostly = {
21018c2ecf20Sopenharmony_ci	.notifier_call  = dcbnl_netdevice_event,
21028c2ecf20Sopenharmony_ci};
21038c2ecf20Sopenharmony_ci
21048c2ecf20Sopenharmony_cistatic int __init dcbnl_init(void)
21058c2ecf20Sopenharmony_ci{
21068c2ecf20Sopenharmony_ci	int err;
21078c2ecf20Sopenharmony_ci
21088c2ecf20Sopenharmony_ci	INIT_LIST_HEAD(&dcb_app_list);
21098c2ecf20Sopenharmony_ci
21108c2ecf20Sopenharmony_ci	err = register_netdevice_notifier(&dcbnl_nb);
21118c2ecf20Sopenharmony_ci	if (err)
21128c2ecf20Sopenharmony_ci		return err;
21138c2ecf20Sopenharmony_ci
21148c2ecf20Sopenharmony_ci	rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL, 0);
21158c2ecf20Sopenharmony_ci	rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL, 0);
21168c2ecf20Sopenharmony_ci
21178c2ecf20Sopenharmony_ci	return 0;
21188c2ecf20Sopenharmony_ci}
21198c2ecf20Sopenharmony_cidevice_initcall(dcbnl_init);
2120