12f90b865SAlexander Duyck /* 2698e1d23SMark Rustad * Copyright (c) 2008-2011, Intel Corporation. 32f90b865SAlexander Duyck * 42f90b865SAlexander Duyck * This program is free software; you can redistribute it and/or modify it 52f90b865SAlexander Duyck * under the terms and conditions of the GNU General Public License, 62f90b865SAlexander Duyck * version 2, as published by the Free Software Foundation. 72f90b865SAlexander Duyck * 82f90b865SAlexander Duyck * This program is distributed in the hope it will be useful, but WITHOUT 92f90b865SAlexander Duyck * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 102f90b865SAlexander Duyck * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 112f90b865SAlexander Duyck * more details. 122f90b865SAlexander Duyck * 132f90b865SAlexander Duyck * You should have received a copy of the GNU General Public License along with 14c057b190SJeff Kirsher * this program; if not, see <http://www.gnu.org/licenses/>. 152f90b865SAlexander Duyck * 1636b9ad80SPaul Gortmaker * Description: Data Center Bridging netlink interface 172f90b865SAlexander Duyck * Author: Lucy Liu <lucy.liu@intel.com> 182f90b865SAlexander Duyck */ 192f90b865SAlexander Duyck 202f90b865SAlexander Duyck #include <linux/netdevice.h> 212f90b865SAlexander Duyck #include <linux/netlink.h> 225a0e3ad6STejun Heo #include <linux/slab.h> 232f90b865SAlexander Duyck #include <net/netlink.h> 242f90b865SAlexander Duyck #include <net/rtnetlink.h> 252f90b865SAlexander Duyck #include <linux/dcbnl.h> 2696b99684SJohn Fastabend #include <net/dcbevent.h> 272f90b865SAlexander Duyck #include <linux/rtnetlink.h> 2836b9ad80SPaul Gortmaker #include <linux/init.h> 292f90b865SAlexander Duyck #include <net/sock.h> 302f90b865SAlexander Duyck 31ae86b9e3SBen Hutchings /* Data Center Bridging (DCB) is a collection of Ethernet enhancements 322f90b865SAlexander Duyck * intended to allow network traffic with differing requirements 332f90b865SAlexander Duyck * (highly reliable, no drops vs. best effort vs. low latency) to operate 342f90b865SAlexander Duyck * and co-exist on Ethernet. Current DCB features are: 352f90b865SAlexander Duyck * 362f90b865SAlexander Duyck * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a 372f90b865SAlexander Duyck * framework for assigning bandwidth guarantees to traffic classes. 382f90b865SAlexander Duyck * 392f90b865SAlexander Duyck * Priority-based Flow Control (PFC) - provides a flow control mechanism which 402f90b865SAlexander Duyck * can work independently for each 802.1p priority. 412f90b865SAlexander Duyck * 422f90b865SAlexander Duyck * Congestion Notification - provides a mechanism for end-to-end congestion 432f90b865SAlexander Duyck * control for protocols which do not have built-in congestion management. 442f90b865SAlexander Duyck * 452f90b865SAlexander Duyck * More information about the emerging standards for these Ethernet features 462f90b865SAlexander Duyck * can be found at: http://www.ieee802.org/1/pages/dcbridges.html 472f90b865SAlexander Duyck * 482f90b865SAlexander Duyck * This file implements an rtnetlink interface to allow configuration of DCB 492f90b865SAlexander Duyck * features for capable devices. 502f90b865SAlexander Duyck */ 512f90b865SAlexander Duyck 522f90b865SAlexander Duyck /**************** DCB attribute policies *************************************/ 532f90b865SAlexander Duyck 542f90b865SAlexander Duyck /* DCB netlink attributes policy */ 55b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = { 56859ee3c4SAlexander Duyck [DCB_ATTR_IFNAME] = {.type = NLA_NUL_STRING, .len = IFNAMSIZ - 1}, 572f90b865SAlexander Duyck [DCB_ATTR_STATE] = {.type = NLA_U8}, 582f90b865SAlexander Duyck [DCB_ATTR_PFC_CFG] = {.type = NLA_NESTED}, 592f90b865SAlexander Duyck [DCB_ATTR_PG_CFG] = {.type = NLA_NESTED}, 602f90b865SAlexander Duyck [DCB_ATTR_SET_ALL] = {.type = NLA_U8}, 612f90b865SAlexander Duyck [DCB_ATTR_PERM_HWADDR] = {.type = NLA_FLAG}, 6246132188SAlexander Duyck [DCB_ATTR_CAP] = {.type = NLA_NESTED}, 630eb3aa9bSAlexander Duyck [DCB_ATTR_PFC_STATE] = {.type = NLA_U8}, 64859ee3c4SAlexander Duyck [DCB_ATTR_BCN] = {.type = NLA_NESTED}, 656fa382afSYi Zou [DCB_ATTR_APP] = {.type = NLA_NESTED}, 663e29027aSJohn Fastabend [DCB_ATTR_IEEE] = {.type = NLA_NESTED}, 676241b625SShmulik Ravid [DCB_ATTR_DCBX] = {.type = NLA_U8}, 68ea45fe4eSShmulik Ravid [DCB_ATTR_FEATCFG] = {.type = NLA_NESTED}, 692f90b865SAlexander Duyck }; 702f90b865SAlexander Duyck 712f90b865SAlexander Duyck /* DCB priority flow control to User Priority nested attributes */ 72b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = { 732f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8}, 742f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8}, 752f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8}, 762f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_3] = {.type = NLA_U8}, 772f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_4] = {.type = NLA_U8}, 782f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_5] = {.type = NLA_U8}, 792f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_6] = {.type = NLA_U8}, 802f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_7] = {.type = NLA_U8}, 812f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_ALL] = {.type = NLA_FLAG}, 822f90b865SAlexander Duyck }; 832f90b865SAlexander Duyck 842f90b865SAlexander Duyck /* DCB priority grouping nested attributes */ 85b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = { 862f90b865SAlexander Duyck [DCB_PG_ATTR_TC_0] = {.type = NLA_NESTED}, 872f90b865SAlexander Duyck [DCB_PG_ATTR_TC_1] = {.type = NLA_NESTED}, 882f90b865SAlexander Duyck [DCB_PG_ATTR_TC_2] = {.type = NLA_NESTED}, 892f90b865SAlexander Duyck [DCB_PG_ATTR_TC_3] = {.type = NLA_NESTED}, 902f90b865SAlexander Duyck [DCB_PG_ATTR_TC_4] = {.type = NLA_NESTED}, 912f90b865SAlexander Duyck [DCB_PG_ATTR_TC_5] = {.type = NLA_NESTED}, 922f90b865SAlexander Duyck [DCB_PG_ATTR_TC_6] = {.type = NLA_NESTED}, 932f90b865SAlexander Duyck [DCB_PG_ATTR_TC_7] = {.type = NLA_NESTED}, 942f90b865SAlexander Duyck [DCB_PG_ATTR_TC_ALL] = {.type = NLA_NESTED}, 952f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_0] = {.type = NLA_U8}, 962f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_1] = {.type = NLA_U8}, 972f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_2] = {.type = NLA_U8}, 982f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_3] = {.type = NLA_U8}, 992f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_4] = {.type = NLA_U8}, 1002f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_5] = {.type = NLA_U8}, 1012f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_6] = {.type = NLA_U8}, 1022f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_7] = {.type = NLA_U8}, 1032f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_ALL] = {.type = NLA_FLAG}, 1042f90b865SAlexander Duyck }; 1052f90b865SAlexander Duyck 1062f90b865SAlexander Duyck /* DCB traffic class nested attributes. */ 107b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = { 1082f90b865SAlexander Duyck [DCB_TC_ATTR_PARAM_PGID] = {.type = NLA_U8}, 1092f90b865SAlexander Duyck [DCB_TC_ATTR_PARAM_UP_MAPPING] = {.type = NLA_U8}, 1102f90b865SAlexander Duyck [DCB_TC_ATTR_PARAM_STRICT_PRIO] = {.type = NLA_U8}, 1112f90b865SAlexander Duyck [DCB_TC_ATTR_PARAM_BW_PCT] = {.type = NLA_U8}, 1122f90b865SAlexander Duyck [DCB_TC_ATTR_PARAM_ALL] = {.type = NLA_FLAG}, 1132f90b865SAlexander Duyck }; 1142f90b865SAlexander Duyck 11546132188SAlexander Duyck /* DCB capabilities nested attributes. */ 116b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = { 11746132188SAlexander Duyck [DCB_CAP_ATTR_ALL] = {.type = NLA_FLAG}, 11846132188SAlexander Duyck [DCB_CAP_ATTR_PG] = {.type = NLA_U8}, 11946132188SAlexander Duyck [DCB_CAP_ATTR_PFC] = {.type = NLA_U8}, 12046132188SAlexander Duyck [DCB_CAP_ATTR_UP2TC] = {.type = NLA_U8}, 12146132188SAlexander Duyck [DCB_CAP_ATTR_PG_TCS] = {.type = NLA_U8}, 12246132188SAlexander Duyck [DCB_CAP_ATTR_PFC_TCS] = {.type = NLA_U8}, 12346132188SAlexander Duyck [DCB_CAP_ATTR_GSP] = {.type = NLA_U8}, 12446132188SAlexander Duyck [DCB_CAP_ATTR_BCN] = {.type = NLA_U8}, 1256241b625SShmulik Ravid [DCB_CAP_ATTR_DCBX] = {.type = NLA_U8}, 12646132188SAlexander Duyck }; 1272f90b865SAlexander Duyck 12833dbabc4SAlexander Duyck /* DCB capabilities nested attributes. */ 129b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = { 13033dbabc4SAlexander Duyck [DCB_NUMTCS_ATTR_ALL] = {.type = NLA_FLAG}, 13133dbabc4SAlexander Duyck [DCB_NUMTCS_ATTR_PG] = {.type = NLA_U8}, 13233dbabc4SAlexander Duyck [DCB_NUMTCS_ATTR_PFC] = {.type = NLA_U8}, 13333dbabc4SAlexander Duyck }; 13433dbabc4SAlexander Duyck 135859ee3c4SAlexander Duyck /* DCB BCN nested attributes. */ 136b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = { 137859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_0] = {.type = NLA_U8}, 138859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_1] = {.type = NLA_U8}, 139859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_2] = {.type = NLA_U8}, 140859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_3] = {.type = NLA_U8}, 141859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_4] = {.type = NLA_U8}, 142859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_5] = {.type = NLA_U8}, 143859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_6] = {.type = NLA_U8}, 144859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_7] = {.type = NLA_U8}, 145859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_ALL] = {.type = NLA_FLAG}, 146f4314e81SDon Skidmore [DCB_BCN_ATTR_BCNA_0] = {.type = NLA_U32}, 147f4314e81SDon Skidmore [DCB_BCN_ATTR_BCNA_1] = {.type = NLA_U32}, 148859ee3c4SAlexander Duyck [DCB_BCN_ATTR_ALPHA] = {.type = NLA_U32}, 149859ee3c4SAlexander Duyck [DCB_BCN_ATTR_BETA] = {.type = NLA_U32}, 150859ee3c4SAlexander Duyck [DCB_BCN_ATTR_GD] = {.type = NLA_U32}, 151859ee3c4SAlexander Duyck [DCB_BCN_ATTR_GI] = {.type = NLA_U32}, 152859ee3c4SAlexander Duyck [DCB_BCN_ATTR_TMAX] = {.type = NLA_U32}, 153859ee3c4SAlexander Duyck [DCB_BCN_ATTR_TD] = {.type = NLA_U32}, 154859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RMIN] = {.type = NLA_U32}, 155859ee3c4SAlexander Duyck [DCB_BCN_ATTR_W] = {.type = NLA_U32}, 156859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RD] = {.type = NLA_U32}, 157859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RU] = {.type = NLA_U32}, 158859ee3c4SAlexander Duyck [DCB_BCN_ATTR_WRTT] = {.type = NLA_U32}, 159859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RI] = {.type = NLA_U32}, 160859ee3c4SAlexander Duyck [DCB_BCN_ATTR_C] = {.type = NLA_U32}, 161859ee3c4SAlexander Duyck [DCB_BCN_ATTR_ALL] = {.type = NLA_FLAG}, 162859ee3c4SAlexander Duyck }; 163859ee3c4SAlexander Duyck 1646fa382afSYi Zou /* DCB APP nested attributes. */ 165b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_app_nest[DCB_APP_ATTR_MAX + 1] = { 1666fa382afSYi Zou [DCB_APP_ATTR_IDTYPE] = {.type = NLA_U8}, 1676fa382afSYi Zou [DCB_APP_ATTR_ID] = {.type = NLA_U16}, 1686fa382afSYi Zou [DCB_APP_ATTR_PRIORITY] = {.type = NLA_U8}, 1696fa382afSYi Zou }; 1706fa382afSYi Zou 1713e29027aSJohn Fastabend /* IEEE 802.1Qaz nested attributes. */ 1723e29027aSJohn Fastabend static const struct nla_policy dcbnl_ieee_policy[DCB_ATTR_IEEE_MAX + 1] = { 1733e29027aSJohn Fastabend [DCB_ATTR_IEEE_ETS] = {.len = sizeof(struct ieee_ets)}, 1743e29027aSJohn Fastabend [DCB_ATTR_IEEE_PFC] = {.len = sizeof(struct ieee_pfc)}, 1753e29027aSJohn Fastabend [DCB_ATTR_IEEE_APP_TABLE] = {.type = NLA_NESTED}, 17608f10affSAmir Vadai [DCB_ATTR_IEEE_MAXRATE] = {.len = sizeof(struct ieee_maxrate)}, 177c9368247SShani Michaeli [DCB_ATTR_IEEE_QCN] = {.len = sizeof(struct ieee_qcn)}, 178c9368247SShani Michaeli [DCB_ATTR_IEEE_QCN_STATS] = {.len = sizeof(struct ieee_qcn_stats)}, 179e549f6f9SHuy Nguyen [DCB_ATTR_DCB_BUFFER] = {.len = sizeof(struct dcbnl_buffer)}, 1803e29027aSJohn Fastabend }; 1813e29027aSJohn Fastabend 182ea45fe4eSShmulik Ravid /* DCB number of traffic classes nested attributes. */ 183ea45fe4eSShmulik Ravid static const struct nla_policy dcbnl_featcfg_nest[DCB_FEATCFG_ATTR_MAX + 1] = { 184ea45fe4eSShmulik Ravid [DCB_FEATCFG_ATTR_ALL] = {.type = NLA_FLAG}, 185ea45fe4eSShmulik Ravid [DCB_FEATCFG_ATTR_PG] = {.type = NLA_U8}, 186ea45fe4eSShmulik Ravid [DCB_FEATCFG_ATTR_PFC] = {.type = NLA_U8}, 187ea45fe4eSShmulik Ravid [DCB_FEATCFG_ATTR_APP] = {.type = NLA_U8}, 188ea45fe4eSShmulik Ravid }; 189ea45fe4eSShmulik Ravid 1909ab933abSJohn Fastabend static LIST_HEAD(dcb_app_list); 1919ab933abSJohn Fastabend static DEFINE_SPINLOCK(dcb_lock); 1929ab933abSJohn Fastabend 19333a03aadSThomas Graf static struct sk_buff *dcbnl_newmsg(int type, u8 cmd, u32 port, u32 seq, 19433a03aadSThomas Graf u32 flags, struct nlmsghdr **nlhp) 19533a03aadSThomas Graf { 19633a03aadSThomas Graf struct sk_buff *skb; 19733a03aadSThomas Graf struct dcbmsg *dcb; 19833a03aadSThomas Graf struct nlmsghdr *nlh; 19933a03aadSThomas Graf 20033a03aadSThomas Graf skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 20133a03aadSThomas Graf if (!skb) 20233a03aadSThomas Graf return NULL; 20333a03aadSThomas Graf 20433a03aadSThomas Graf nlh = nlmsg_put(skb, port, seq, type, sizeof(*dcb), flags); 205b3908e22SThomas Graf BUG_ON(!nlh); 20633a03aadSThomas Graf 20733a03aadSThomas Graf dcb = nlmsg_data(nlh); 20833a03aadSThomas Graf dcb->dcb_family = AF_UNSPEC; 20933a03aadSThomas Graf dcb->cmd = cmd; 21033a03aadSThomas Graf dcb->dcb_pad = 0; 21133a03aadSThomas Graf 21233a03aadSThomas Graf if (nlhp) 21333a03aadSThomas Graf *nlhp = nlh; 21433a03aadSThomas Graf 21533a03aadSThomas Graf return skb; 21633a03aadSThomas Graf } 21733a03aadSThomas Graf 2187be99413SThomas Graf static int dcbnl_getstate(struct net_device *netdev, struct nlmsghdr *nlh, 2197be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 2202f90b865SAlexander Duyck { 2212f90b865SAlexander Duyck /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */ 2222f90b865SAlexander Duyck if (!netdev->dcbnl_ops->getstate) 2233d1f4869SThomas Graf return -EOPNOTSUPP; 2242f90b865SAlexander Duyck 2257be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_STATE, 2267be99413SThomas Graf netdev->dcbnl_ops->getstate(netdev)); 2272f90b865SAlexander Duyck } 2282f90b865SAlexander Duyck 2297be99413SThomas Graf static int dcbnl_getpfccfg(struct net_device *netdev, struct nlmsghdr *nlh, 2307be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 2312f90b865SAlexander Duyck { 2322f90b865SAlexander Duyck struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1], *nest; 2332f90b865SAlexander Duyck u8 value; 2343d1f4869SThomas Graf int ret; 2352f90b865SAlexander Duyck int i; 2362f90b865SAlexander Duyck int getall = 0; 2372f90b865SAlexander Duyck 2383d1f4869SThomas Graf if (!tb[DCB_ATTR_PFC_CFG]) 2393d1f4869SThomas Graf return -EINVAL; 2403d1f4869SThomas Graf 2413d1f4869SThomas Graf if (!netdev->dcbnl_ops->getpfccfg) 2423d1f4869SThomas Graf return -EOPNOTSUPP; 2432f90b865SAlexander Duyck 2448cb08174SJohannes Berg ret = nla_parse_nested_deprecated(data, DCB_PFC_UP_ATTR_MAX, 2458cb08174SJohannes Berg tb[DCB_ATTR_PFC_CFG], 2468cb08174SJohannes Berg dcbnl_pfc_up_nest, NULL); 2472f90b865SAlexander Duyck if (ret) 2483d1f4869SThomas Graf return ret; 2492f90b865SAlexander Duyck 250ae0be8deSMichal Kubecek nest = nla_nest_start_noflag(skb, DCB_ATTR_PFC_CFG); 2512f90b865SAlexander Duyck if (!nest) 2523d1f4869SThomas Graf return -EMSGSIZE; 2532f90b865SAlexander Duyck 2542f90b865SAlexander Duyck if (data[DCB_PFC_UP_ATTR_ALL]) 2552f90b865SAlexander Duyck getall = 1; 2562f90b865SAlexander Duyck 2572f90b865SAlexander Duyck for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) { 2582f90b865SAlexander Duyck if (!getall && !data[i]) 2592f90b865SAlexander Duyck continue; 2602f90b865SAlexander Duyck 2612f90b865SAlexander Duyck netdev->dcbnl_ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0, 2622f90b865SAlexander Duyck &value); 2637be99413SThomas Graf ret = nla_put_u8(skb, i, value); 2642f90b865SAlexander Duyck if (ret) { 2657be99413SThomas Graf nla_nest_cancel(skb, nest); 2663d1f4869SThomas Graf return ret; 2672f90b865SAlexander Duyck } 2682f90b865SAlexander Duyck } 2697be99413SThomas Graf nla_nest_end(skb, nest); 2702f90b865SAlexander Duyck 2712f90b865SAlexander Duyck return 0; 2722f90b865SAlexander Duyck } 2732f90b865SAlexander Duyck 2747be99413SThomas Graf static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlmsghdr *nlh, 2757be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 2762f90b865SAlexander Duyck { 2772f90b865SAlexander Duyck u8 perm_addr[MAX_ADDR_LEN]; 2782f90b865SAlexander Duyck 2792f90b865SAlexander Duyck if (!netdev->dcbnl_ops->getpermhwaddr) 2803d1f4869SThomas Graf return -EOPNOTSUPP; 2812f90b865SAlexander Duyck 28229cd8ae0SMathias Krause memset(perm_addr, 0, sizeof(perm_addr)); 2832f90b865SAlexander Duyck netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr); 2842f90b865SAlexander Duyck 2857be99413SThomas Graf return nla_put(skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr), perm_addr); 2862f90b865SAlexander Duyck } 2872f90b865SAlexander Duyck 2887be99413SThomas Graf static int dcbnl_getcap(struct net_device *netdev, struct nlmsghdr *nlh, 2897be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 29046132188SAlexander Duyck { 29146132188SAlexander Duyck struct nlattr *data[DCB_CAP_ATTR_MAX + 1], *nest; 29246132188SAlexander Duyck u8 value; 2933d1f4869SThomas Graf int ret; 29446132188SAlexander Duyck int i; 29546132188SAlexander Duyck int getall = 0; 29646132188SAlexander Duyck 2973d1f4869SThomas Graf if (!tb[DCB_ATTR_CAP]) 2983d1f4869SThomas Graf return -EINVAL; 2993d1f4869SThomas Graf 3003d1f4869SThomas Graf if (!netdev->dcbnl_ops->getcap) 3013d1f4869SThomas Graf return -EOPNOTSUPP; 30246132188SAlexander Duyck 3038cb08174SJohannes Berg ret = nla_parse_nested_deprecated(data, DCB_CAP_ATTR_MAX, 3048cb08174SJohannes Berg tb[DCB_ATTR_CAP], dcbnl_cap_nest, 3058cb08174SJohannes Berg NULL); 30646132188SAlexander Duyck if (ret) 3073d1f4869SThomas Graf return ret; 30846132188SAlexander Duyck 309ae0be8deSMichal Kubecek nest = nla_nest_start_noflag(skb, DCB_ATTR_CAP); 31046132188SAlexander Duyck if (!nest) 3113d1f4869SThomas Graf return -EMSGSIZE; 31246132188SAlexander Duyck 31346132188SAlexander Duyck if (data[DCB_CAP_ATTR_ALL]) 31446132188SAlexander Duyck getall = 1; 31546132188SAlexander Duyck 31646132188SAlexander Duyck for (i = DCB_CAP_ATTR_ALL+1; i <= DCB_CAP_ATTR_MAX; i++) { 31746132188SAlexander Duyck if (!getall && !data[i]) 31846132188SAlexander Duyck continue; 31946132188SAlexander Duyck 32046132188SAlexander Duyck if (!netdev->dcbnl_ops->getcap(netdev, i, &value)) { 3217be99413SThomas Graf ret = nla_put_u8(skb, i, value); 32246132188SAlexander Duyck if (ret) { 3237be99413SThomas Graf nla_nest_cancel(skb, nest); 3243d1f4869SThomas Graf return ret; 3257be99413SThomas Graf } 3267be99413SThomas Graf } 3277be99413SThomas Graf } 3287be99413SThomas Graf nla_nest_end(skb, nest); 32946132188SAlexander Duyck 33046132188SAlexander Duyck return 0; 33146132188SAlexander Duyck } 33246132188SAlexander Duyck 3337be99413SThomas Graf static int dcbnl_getnumtcs(struct net_device *netdev, struct nlmsghdr *nlh, 3347be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 33533dbabc4SAlexander Duyck { 33633dbabc4SAlexander Duyck struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1], *nest; 33733dbabc4SAlexander Duyck u8 value; 3383d1f4869SThomas Graf int ret; 33933dbabc4SAlexander Duyck int i; 34033dbabc4SAlexander Duyck int getall = 0; 34133dbabc4SAlexander Duyck 3423d1f4869SThomas Graf if (!tb[DCB_ATTR_NUMTCS]) 3433d1f4869SThomas Graf return -EINVAL; 3443d1f4869SThomas Graf 3453d1f4869SThomas Graf if (!netdev->dcbnl_ops->getnumtcs) 3463d1f4869SThomas Graf return -EOPNOTSUPP; 34733dbabc4SAlexander Duyck 3488cb08174SJohannes Berg ret = nla_parse_nested_deprecated(data, DCB_NUMTCS_ATTR_MAX, 3498cb08174SJohannes Berg tb[DCB_ATTR_NUMTCS], 350fceb6435SJohannes Berg dcbnl_numtcs_nest, NULL); 3513d1f4869SThomas Graf if (ret) 3523d1f4869SThomas Graf return ret; 35333dbabc4SAlexander Duyck 354ae0be8deSMichal Kubecek nest = nla_nest_start_noflag(skb, DCB_ATTR_NUMTCS); 3553d1f4869SThomas Graf if (!nest) 3563d1f4869SThomas Graf return -EMSGSIZE; 35733dbabc4SAlexander Duyck 35833dbabc4SAlexander Duyck if (data[DCB_NUMTCS_ATTR_ALL]) 35933dbabc4SAlexander Duyck getall = 1; 36033dbabc4SAlexander Duyck 36133dbabc4SAlexander Duyck for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) { 36233dbabc4SAlexander Duyck if (!getall && !data[i]) 36333dbabc4SAlexander Duyck continue; 36433dbabc4SAlexander Duyck 36533dbabc4SAlexander Duyck ret = netdev->dcbnl_ops->getnumtcs(netdev, i, &value); 36633dbabc4SAlexander Duyck if (!ret) { 3677be99413SThomas Graf ret = nla_put_u8(skb, i, value); 36833dbabc4SAlexander Duyck if (ret) { 3697be99413SThomas Graf nla_nest_cancel(skb, nest); 3703d1f4869SThomas Graf return ret; 37133dbabc4SAlexander Duyck } 3723d1f4869SThomas Graf } else 3733d1f4869SThomas Graf return -EINVAL; 3747be99413SThomas Graf } 3757be99413SThomas Graf nla_nest_end(skb, nest); 37633dbabc4SAlexander Duyck 37733dbabc4SAlexander Duyck return 0; 37833dbabc4SAlexander Duyck } 37933dbabc4SAlexander Duyck 3807be99413SThomas Graf static int dcbnl_setnumtcs(struct net_device *netdev, struct nlmsghdr *nlh, 3817be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 38233dbabc4SAlexander Duyck { 38333dbabc4SAlexander Duyck struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1]; 3843d1f4869SThomas Graf int ret; 38533dbabc4SAlexander Duyck u8 value; 38633dbabc4SAlexander Duyck int i; 38733dbabc4SAlexander Duyck 3883d1f4869SThomas Graf if (!tb[DCB_ATTR_NUMTCS]) 3893d1f4869SThomas Graf return -EINVAL; 3903d1f4869SThomas Graf 3913d1f4869SThomas Graf if (!netdev->dcbnl_ops->setnumtcs) 3923d1f4869SThomas Graf return -EOPNOTSUPP; 39333dbabc4SAlexander Duyck 3948cb08174SJohannes Berg ret = nla_parse_nested_deprecated(data, DCB_NUMTCS_ATTR_MAX, 3958cb08174SJohannes Berg tb[DCB_ATTR_NUMTCS], 396fceb6435SJohannes Berg dcbnl_numtcs_nest, NULL); 3977be99413SThomas Graf if (ret) 3983d1f4869SThomas Graf return ret; 39933dbabc4SAlexander Duyck 40033dbabc4SAlexander Duyck for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) { 40133dbabc4SAlexander Duyck if (data[i] == NULL) 40233dbabc4SAlexander Duyck continue; 40333dbabc4SAlexander Duyck 40433dbabc4SAlexander Duyck value = nla_get_u8(data[i]); 40533dbabc4SAlexander Duyck 40633dbabc4SAlexander Duyck ret = netdev->dcbnl_ops->setnumtcs(netdev, i, value); 40733dbabc4SAlexander Duyck if (ret) 4087be99413SThomas Graf break; 40933dbabc4SAlexander Duyck } 41033dbabc4SAlexander Duyck 4117be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_NUMTCS, !!ret); 41233dbabc4SAlexander Duyck } 41333dbabc4SAlexander Duyck 4147be99413SThomas Graf static int dcbnl_getpfcstate(struct net_device *netdev, struct nlmsghdr *nlh, 4157be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 4160eb3aa9bSAlexander Duyck { 4170eb3aa9bSAlexander Duyck if (!netdev->dcbnl_ops->getpfcstate) 4183d1f4869SThomas Graf return -EOPNOTSUPP; 4190eb3aa9bSAlexander Duyck 4207be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_PFC_STATE, 4217be99413SThomas Graf netdev->dcbnl_ops->getpfcstate(netdev)); 4220eb3aa9bSAlexander Duyck } 4230eb3aa9bSAlexander Duyck 4247be99413SThomas Graf static int dcbnl_setpfcstate(struct net_device *netdev, struct nlmsghdr *nlh, 4257be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 4260eb3aa9bSAlexander Duyck { 4270eb3aa9bSAlexander Duyck u8 value; 4280eb3aa9bSAlexander Duyck 4293d1f4869SThomas Graf if (!tb[DCB_ATTR_PFC_STATE]) 4307be99413SThomas Graf return -EINVAL; 4310eb3aa9bSAlexander Duyck 4323d1f4869SThomas Graf if (!netdev->dcbnl_ops->setpfcstate) 4333d1f4869SThomas Graf return -EOPNOTSUPP; 4343d1f4869SThomas Graf 4350eb3aa9bSAlexander Duyck value = nla_get_u8(tb[DCB_ATTR_PFC_STATE]); 4360eb3aa9bSAlexander Duyck 4370eb3aa9bSAlexander Duyck netdev->dcbnl_ops->setpfcstate(netdev, value); 4380eb3aa9bSAlexander Duyck 4397be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_PFC_STATE, 0); 4400eb3aa9bSAlexander Duyck } 4410eb3aa9bSAlexander Duyck 4427be99413SThomas Graf static int dcbnl_getapp(struct net_device *netdev, struct nlmsghdr *nlh, 4437be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 44457949686SYi Zou { 44557949686SYi Zou struct nlattr *app_nest; 44657949686SYi Zou struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1]; 44757949686SYi Zou u16 id; 44857949686SYi Zou u8 up, idtype; 4493d1f4869SThomas Graf int ret; 45057949686SYi Zou 4513dce38a0SJohn Fastabend if (!tb[DCB_ATTR_APP]) 4523d1f4869SThomas Graf return -EINVAL; 45357949686SYi Zou 4548cb08174SJohannes Berg ret = nla_parse_nested_deprecated(app_tb, DCB_APP_ATTR_MAX, 4558cb08174SJohannes Berg tb[DCB_ATTR_APP], dcbnl_app_nest, 4568cb08174SJohannes Berg NULL); 45757949686SYi Zou if (ret) 4583d1f4869SThomas Graf return ret; 45957949686SYi Zou 46057949686SYi Zou /* all must be non-null */ 46157949686SYi Zou if ((!app_tb[DCB_APP_ATTR_IDTYPE]) || 46257949686SYi Zou (!app_tb[DCB_APP_ATTR_ID])) 4633d1f4869SThomas Graf return -EINVAL; 46457949686SYi Zou 46557949686SYi Zou /* either by eth type or by socket number */ 46657949686SYi Zou idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]); 46757949686SYi Zou if ((idtype != DCB_APP_IDTYPE_ETHTYPE) && 46857949686SYi Zou (idtype != DCB_APP_IDTYPE_PORTNUM)) 4693d1f4869SThomas Graf return -EINVAL; 47057949686SYi Zou 47157949686SYi Zou id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]); 4723dce38a0SJohn Fastabend 4733dce38a0SJohn Fastabend if (netdev->dcbnl_ops->getapp) { 474c2659479SAnish Bhatt ret = netdev->dcbnl_ops->getapp(netdev, idtype, id); 475c2659479SAnish Bhatt if (ret < 0) 476c2659479SAnish Bhatt return ret; 477c2659479SAnish Bhatt else 478c2659479SAnish Bhatt up = ret; 4793dce38a0SJohn Fastabend } else { 4803dce38a0SJohn Fastabend struct dcb_app app = { 4813dce38a0SJohn Fastabend .selector = idtype, 4823dce38a0SJohn Fastabend .protocol = id, 4833dce38a0SJohn Fastabend }; 4843dce38a0SJohn Fastabend up = dcb_getapp(netdev, &app); 4853dce38a0SJohn Fastabend } 48657949686SYi Zou 487ae0be8deSMichal Kubecek app_nest = nla_nest_start_noflag(skb, DCB_ATTR_APP); 4887be99413SThomas Graf if (!app_nest) 4893d1f4869SThomas Graf return -EMSGSIZE; 49057949686SYi Zou 4917be99413SThomas Graf ret = nla_put_u8(skb, DCB_APP_ATTR_IDTYPE, idtype); 49257949686SYi Zou if (ret) 49357949686SYi Zou goto out_cancel; 49457949686SYi Zou 4957be99413SThomas Graf ret = nla_put_u16(skb, DCB_APP_ATTR_ID, id); 49657949686SYi Zou if (ret) 49757949686SYi Zou goto out_cancel; 49857949686SYi Zou 4997be99413SThomas Graf ret = nla_put_u8(skb, DCB_APP_ATTR_PRIORITY, up); 50057949686SYi Zou if (ret) 50157949686SYi Zou goto out_cancel; 50257949686SYi Zou 5037be99413SThomas Graf nla_nest_end(skb, app_nest); 50457949686SYi Zou 5053d1f4869SThomas Graf return 0; 50657949686SYi Zou 50757949686SYi Zou out_cancel: 5087be99413SThomas Graf nla_nest_cancel(skb, app_nest); 50957949686SYi Zou return ret; 51057949686SYi Zou } 51157949686SYi Zou 5127be99413SThomas Graf static int dcbnl_setapp(struct net_device *netdev, struct nlmsghdr *nlh, 5137be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 51457949686SYi Zou { 5153d1f4869SThomas Graf int ret; 51657949686SYi Zou u16 id; 51757949686SYi Zou u8 up, idtype; 51857949686SYi Zou struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1]; 51957949686SYi Zou 5209ab933abSJohn Fastabend if (!tb[DCB_ATTR_APP]) 5213d1f4869SThomas Graf return -EINVAL; 52257949686SYi Zou 5238cb08174SJohannes Berg ret = nla_parse_nested_deprecated(app_tb, DCB_APP_ATTR_MAX, 5248cb08174SJohannes Berg tb[DCB_ATTR_APP], dcbnl_app_nest, 5258cb08174SJohannes Berg NULL); 52657949686SYi Zou if (ret) 5273d1f4869SThomas Graf return ret; 52857949686SYi Zou 52957949686SYi Zou /* all must be non-null */ 53057949686SYi Zou if ((!app_tb[DCB_APP_ATTR_IDTYPE]) || 53157949686SYi Zou (!app_tb[DCB_APP_ATTR_ID]) || 53257949686SYi Zou (!app_tb[DCB_APP_ATTR_PRIORITY])) 5333d1f4869SThomas Graf return -EINVAL; 53457949686SYi Zou 53557949686SYi Zou /* either by eth type or by socket number */ 53657949686SYi Zou idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]); 53757949686SYi Zou if ((idtype != DCB_APP_IDTYPE_ETHTYPE) && 53857949686SYi Zou (idtype != DCB_APP_IDTYPE_PORTNUM)) 5393d1f4869SThomas Graf return -EINVAL; 54057949686SYi Zou 54157949686SYi Zou id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]); 54257949686SYi Zou up = nla_get_u8(app_tb[DCB_APP_ATTR_PRIORITY]); 54357949686SYi Zou 5449ab933abSJohn Fastabend if (netdev->dcbnl_ops->setapp) { 5453d1f4869SThomas Graf ret = netdev->dcbnl_ops->setapp(netdev, idtype, id, up); 546c2659479SAnish Bhatt if (ret < 0) 547c2659479SAnish Bhatt return ret; 5489ab933abSJohn Fastabend } else { 5499ab933abSJohn Fastabend struct dcb_app app; 5509ab933abSJohn Fastabend app.selector = idtype; 5519ab933abSJohn Fastabend app.protocol = id; 5529ab933abSJohn Fastabend app.priority = up; 5533d1f4869SThomas Graf ret = dcb_setapp(netdev, &app); 5549ab933abSJohn Fastabend } 5559ab933abSJohn Fastabend 5567be99413SThomas Graf ret = nla_put_u8(skb, DCB_ATTR_APP, ret); 55708157984SJohn Fastabend dcbnl_cee_notify(netdev, RTM_SETDCB, DCB_CMD_SAPP, seq, 0); 5583d1f4869SThomas Graf 55957949686SYi Zou return ret; 56057949686SYi Zou } 56157949686SYi Zou 5627be99413SThomas Graf static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlmsghdr *nlh, 5637be99413SThomas Graf struct nlattr **tb, struct sk_buff *skb, int dir) 5642f90b865SAlexander Duyck { 5652f90b865SAlexander Duyck struct nlattr *pg_nest, *param_nest, *data; 5662f90b865SAlexander Duyck struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1]; 5672f90b865SAlexander Duyck struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1]; 5682f90b865SAlexander Duyck u8 prio, pgid, tc_pct, up_map; 5693d1f4869SThomas Graf int ret; 5702f90b865SAlexander Duyck int getall = 0; 5712f90b865SAlexander Duyck int i; 5722f90b865SAlexander Duyck 5733d1f4869SThomas Graf if (!tb[DCB_ATTR_PG_CFG]) 5743d1f4869SThomas Graf return -EINVAL; 5753d1f4869SThomas Graf 5763d1f4869SThomas Graf if (!netdev->dcbnl_ops->getpgtccfgtx || 5772f90b865SAlexander Duyck !netdev->dcbnl_ops->getpgtccfgrx || 5782f90b865SAlexander Duyck !netdev->dcbnl_ops->getpgbwgcfgtx || 5792f90b865SAlexander Duyck !netdev->dcbnl_ops->getpgbwgcfgrx) 5803d1f4869SThomas Graf return -EOPNOTSUPP; 5812f90b865SAlexander Duyck 5828cb08174SJohannes Berg ret = nla_parse_nested_deprecated(pg_tb, DCB_PG_ATTR_MAX, 5838cb08174SJohannes Berg tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest, 5848cb08174SJohannes Berg NULL); 5852f90b865SAlexander Duyck if (ret) 5863d1f4869SThomas Graf return ret; 5872f90b865SAlexander Duyck 588ae0be8deSMichal Kubecek pg_nest = nla_nest_start_noflag(skb, DCB_ATTR_PG_CFG); 5892f90b865SAlexander Duyck if (!pg_nest) 5903d1f4869SThomas Graf return -EMSGSIZE; 5912f90b865SAlexander Duyck 5922f90b865SAlexander Duyck if (pg_tb[DCB_PG_ATTR_TC_ALL]) 5932f90b865SAlexander Duyck getall = 1; 5942f90b865SAlexander Duyck 5952f90b865SAlexander Duyck for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) { 5962f90b865SAlexander Duyck if (!getall && !pg_tb[i]) 5972f90b865SAlexander Duyck continue; 5982f90b865SAlexander Duyck 5992f90b865SAlexander Duyck if (pg_tb[DCB_PG_ATTR_TC_ALL]) 6002f90b865SAlexander Duyck data = pg_tb[DCB_PG_ATTR_TC_ALL]; 6012f90b865SAlexander Duyck else 6022f90b865SAlexander Duyck data = pg_tb[i]; 6038cb08174SJohannes Berg ret = nla_parse_nested_deprecated(param_tb, 6048cb08174SJohannes Berg DCB_TC_ATTR_PARAM_MAX, data, 605fceb6435SJohannes Berg dcbnl_tc_param_nest, NULL); 6062f90b865SAlexander Duyck if (ret) 6072f90b865SAlexander Duyck goto err_pg; 6082f90b865SAlexander Duyck 609ae0be8deSMichal Kubecek param_nest = nla_nest_start_noflag(skb, i); 6102f90b865SAlexander Duyck if (!param_nest) 6112f90b865SAlexander Duyck goto err_pg; 6122f90b865SAlexander Duyck 6132f90b865SAlexander Duyck pgid = DCB_ATTR_VALUE_UNDEFINED; 6142f90b865SAlexander Duyck prio = DCB_ATTR_VALUE_UNDEFINED; 6152f90b865SAlexander Duyck tc_pct = DCB_ATTR_VALUE_UNDEFINED; 6162f90b865SAlexander Duyck up_map = DCB_ATTR_VALUE_UNDEFINED; 6172f90b865SAlexander Duyck 6182f90b865SAlexander Duyck if (dir) { 6192f90b865SAlexander Duyck /* Rx */ 6202f90b865SAlexander Duyck netdev->dcbnl_ops->getpgtccfgrx(netdev, 6212f90b865SAlexander Duyck i - DCB_PG_ATTR_TC_0, &prio, 6222f90b865SAlexander Duyck &pgid, &tc_pct, &up_map); 6232f90b865SAlexander Duyck } else { 6242f90b865SAlexander Duyck /* Tx */ 6252f90b865SAlexander Duyck netdev->dcbnl_ops->getpgtccfgtx(netdev, 6262f90b865SAlexander Duyck i - DCB_PG_ATTR_TC_0, &prio, 6272f90b865SAlexander Duyck &pgid, &tc_pct, &up_map); 6282f90b865SAlexander Duyck } 6292f90b865SAlexander Duyck 6302f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_PGID] || 6312f90b865SAlexander Duyck param_tb[DCB_TC_ATTR_PARAM_ALL]) { 6327be99413SThomas Graf ret = nla_put_u8(skb, 6332f90b865SAlexander Duyck DCB_TC_ATTR_PARAM_PGID, pgid); 6342f90b865SAlexander Duyck if (ret) 6352f90b865SAlexander Duyck goto err_param; 6362f90b865SAlexander Duyck } 6372f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING] || 6382f90b865SAlexander Duyck param_tb[DCB_TC_ATTR_PARAM_ALL]) { 6397be99413SThomas Graf ret = nla_put_u8(skb, 6402f90b865SAlexander Duyck DCB_TC_ATTR_PARAM_UP_MAPPING, up_map); 6412f90b865SAlexander Duyck if (ret) 6422f90b865SAlexander Duyck goto err_param; 6432f90b865SAlexander Duyck } 6442f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO] || 6452f90b865SAlexander Duyck param_tb[DCB_TC_ATTR_PARAM_ALL]) { 6467be99413SThomas Graf ret = nla_put_u8(skb, 6472f90b865SAlexander Duyck DCB_TC_ATTR_PARAM_STRICT_PRIO, prio); 6482f90b865SAlexander Duyck if (ret) 6492f90b865SAlexander Duyck goto err_param; 6502f90b865SAlexander Duyck } 6512f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT] || 6522f90b865SAlexander Duyck param_tb[DCB_TC_ATTR_PARAM_ALL]) { 6537be99413SThomas Graf ret = nla_put_u8(skb, DCB_TC_ATTR_PARAM_BW_PCT, 6542f90b865SAlexander Duyck tc_pct); 6552f90b865SAlexander Duyck if (ret) 6562f90b865SAlexander Duyck goto err_param; 6572f90b865SAlexander Duyck } 6587be99413SThomas Graf nla_nest_end(skb, param_nest); 6592f90b865SAlexander Duyck } 6602f90b865SAlexander Duyck 6612f90b865SAlexander Duyck if (pg_tb[DCB_PG_ATTR_BW_ID_ALL]) 6622f90b865SAlexander Duyck getall = 1; 6632f90b865SAlexander Duyck else 6642f90b865SAlexander Duyck getall = 0; 6652f90b865SAlexander Duyck 6662f90b865SAlexander Duyck for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) { 6672f90b865SAlexander Duyck if (!getall && !pg_tb[i]) 6682f90b865SAlexander Duyck continue; 6692f90b865SAlexander Duyck 6702f90b865SAlexander Duyck tc_pct = DCB_ATTR_VALUE_UNDEFINED; 6712f90b865SAlexander Duyck 6722f90b865SAlexander Duyck if (dir) { 6732f90b865SAlexander Duyck /* Rx */ 6742f90b865SAlexander Duyck netdev->dcbnl_ops->getpgbwgcfgrx(netdev, 6752f90b865SAlexander Duyck i - DCB_PG_ATTR_BW_ID_0, &tc_pct); 6762f90b865SAlexander Duyck } else { 6772f90b865SAlexander Duyck /* Tx */ 6782f90b865SAlexander Duyck netdev->dcbnl_ops->getpgbwgcfgtx(netdev, 6792f90b865SAlexander Duyck i - DCB_PG_ATTR_BW_ID_0, &tc_pct); 6802f90b865SAlexander Duyck } 6817be99413SThomas Graf ret = nla_put_u8(skb, i, tc_pct); 6822f90b865SAlexander Duyck if (ret) 6832f90b865SAlexander Duyck goto err_pg; 6842f90b865SAlexander Duyck } 6852f90b865SAlexander Duyck 6867be99413SThomas Graf nla_nest_end(skb, pg_nest); 6872f90b865SAlexander Duyck 6882f90b865SAlexander Duyck return 0; 6892f90b865SAlexander Duyck 6902f90b865SAlexander Duyck err_param: 6917be99413SThomas Graf nla_nest_cancel(skb, param_nest); 6922f90b865SAlexander Duyck err_pg: 6937be99413SThomas Graf nla_nest_cancel(skb, pg_nest); 6943d1f4869SThomas Graf 6953d1f4869SThomas Graf return -EMSGSIZE; 6962f90b865SAlexander Duyck } 6972f90b865SAlexander Duyck 6987be99413SThomas Graf static int dcbnl_pgtx_getcfg(struct net_device *netdev, struct nlmsghdr *nlh, 6997be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 7002f90b865SAlexander Duyck { 7017be99413SThomas Graf return __dcbnl_pg_getcfg(netdev, nlh, tb, skb, 0); 7022f90b865SAlexander Duyck } 7032f90b865SAlexander Duyck 7047be99413SThomas Graf static int dcbnl_pgrx_getcfg(struct net_device *netdev, struct nlmsghdr *nlh, 7057be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 7062f90b865SAlexander Duyck { 7077be99413SThomas Graf return __dcbnl_pg_getcfg(netdev, nlh, tb, skb, 1); 7082f90b865SAlexander Duyck } 7092f90b865SAlexander Duyck 7107be99413SThomas Graf static int dcbnl_setstate(struct net_device *netdev, struct nlmsghdr *nlh, 7117be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 7122f90b865SAlexander Duyck { 7132f90b865SAlexander Duyck u8 value; 7142f90b865SAlexander Duyck 7153d1f4869SThomas Graf if (!tb[DCB_ATTR_STATE]) 7167be99413SThomas Graf return -EINVAL; 7172f90b865SAlexander Duyck 7183d1f4869SThomas Graf if (!netdev->dcbnl_ops->setstate) 7193d1f4869SThomas Graf return -EOPNOTSUPP; 7203d1f4869SThomas Graf 7212f90b865SAlexander Duyck value = nla_get_u8(tb[DCB_ATTR_STATE]); 7222f90b865SAlexander Duyck 7237be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_STATE, 7247be99413SThomas Graf netdev->dcbnl_ops->setstate(netdev, value)); 7252f90b865SAlexander Duyck } 7262f90b865SAlexander Duyck 7277be99413SThomas Graf static int dcbnl_setpfccfg(struct net_device *netdev, struct nlmsghdr *nlh, 7287be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 7292f90b865SAlexander Duyck { 7302f90b865SAlexander Duyck struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1]; 7312f90b865SAlexander Duyck int i; 7323d1f4869SThomas Graf int ret; 7332f90b865SAlexander Duyck u8 value; 7342f90b865SAlexander Duyck 7353d1f4869SThomas Graf if (!tb[DCB_ATTR_PFC_CFG]) 7363d1f4869SThomas Graf return -EINVAL; 7373d1f4869SThomas Graf 7383d1f4869SThomas Graf if (!netdev->dcbnl_ops->setpfccfg) 7393d1f4869SThomas Graf return -EOPNOTSUPP; 7402f90b865SAlexander Duyck 7418cb08174SJohannes Berg ret = nla_parse_nested_deprecated(data, DCB_PFC_UP_ATTR_MAX, 7428cb08174SJohannes Berg tb[DCB_ATTR_PFC_CFG], 7438cb08174SJohannes Berg dcbnl_pfc_up_nest, NULL); 7442f90b865SAlexander Duyck if (ret) 7453d1f4869SThomas Graf return ret; 7462f90b865SAlexander Duyck 7472f90b865SAlexander Duyck for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) { 7482f90b865SAlexander Duyck if (data[i] == NULL) 7492f90b865SAlexander Duyck continue; 7502f90b865SAlexander Duyck value = nla_get_u8(data[i]); 7512f90b865SAlexander Duyck netdev->dcbnl_ops->setpfccfg(netdev, 7522f90b865SAlexander Duyck data[i]->nla_type - DCB_PFC_UP_ATTR_0, value); 7532f90b865SAlexander Duyck } 7542f90b865SAlexander Duyck 7557be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_PFC_CFG, 0); 7562f90b865SAlexander Duyck } 7572f90b865SAlexander Duyck 7587be99413SThomas Graf static int dcbnl_setall(struct net_device *netdev, struct nlmsghdr *nlh, 7597be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 7602f90b865SAlexander Duyck { 7613d1f4869SThomas Graf int ret; 7622f90b865SAlexander Duyck 7633d1f4869SThomas Graf if (!tb[DCB_ATTR_SET_ALL]) 7643d1f4869SThomas Graf return -EINVAL; 7653d1f4869SThomas Graf 7663d1f4869SThomas Graf if (!netdev->dcbnl_ops->setall) 7673d1f4869SThomas Graf return -EOPNOTSUPP; 7682f90b865SAlexander Duyck 7697be99413SThomas Graf ret = nla_put_u8(skb, DCB_ATTR_SET_ALL, 7707be99413SThomas Graf netdev->dcbnl_ops->setall(netdev)); 77108157984SJohn Fastabend dcbnl_cee_notify(netdev, RTM_SETDCB, DCB_CMD_SET_ALL, seq, 0); 7722f90b865SAlexander Duyck 7732f90b865SAlexander Duyck return ret; 7742f90b865SAlexander Duyck } 7752f90b865SAlexander Duyck 7767be99413SThomas Graf static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlmsghdr *nlh, 7777be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb, 7787be99413SThomas Graf int dir) 7792f90b865SAlexander Duyck { 7802f90b865SAlexander Duyck struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1]; 7812f90b865SAlexander Duyck struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1]; 7823d1f4869SThomas Graf int ret; 7832f90b865SAlexander Duyck int i; 7842f90b865SAlexander Duyck u8 pgid; 7852f90b865SAlexander Duyck u8 up_map; 7862f90b865SAlexander Duyck u8 prio; 7872f90b865SAlexander Duyck u8 tc_pct; 7882f90b865SAlexander Duyck 7893d1f4869SThomas Graf if (!tb[DCB_ATTR_PG_CFG]) 7903d1f4869SThomas Graf return -EINVAL; 7913d1f4869SThomas Graf 7923d1f4869SThomas Graf if (!netdev->dcbnl_ops->setpgtccfgtx || 7932f90b865SAlexander Duyck !netdev->dcbnl_ops->setpgtccfgrx || 7942f90b865SAlexander Duyck !netdev->dcbnl_ops->setpgbwgcfgtx || 7952f90b865SAlexander Duyck !netdev->dcbnl_ops->setpgbwgcfgrx) 7963d1f4869SThomas Graf return -EOPNOTSUPP; 7972f90b865SAlexander Duyck 7988cb08174SJohannes Berg ret = nla_parse_nested_deprecated(pg_tb, DCB_PG_ATTR_MAX, 7998cb08174SJohannes Berg tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest, 8008cb08174SJohannes Berg NULL); 8012f90b865SAlexander Duyck if (ret) 8023d1f4869SThomas Graf return ret; 8032f90b865SAlexander Duyck 8042f90b865SAlexander Duyck for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) { 8052f90b865SAlexander Duyck if (!pg_tb[i]) 8062f90b865SAlexander Duyck continue; 8072f90b865SAlexander Duyck 8088cb08174SJohannes Berg ret = nla_parse_nested_deprecated(param_tb, 8098cb08174SJohannes Berg DCB_TC_ATTR_PARAM_MAX, 8108cb08174SJohannes Berg pg_tb[i], 8118cb08174SJohannes Berg dcbnl_tc_param_nest, NULL); 8122f90b865SAlexander Duyck if (ret) 8133d1f4869SThomas Graf return ret; 8142f90b865SAlexander Duyck 8152f90b865SAlexander Duyck pgid = DCB_ATTR_VALUE_UNDEFINED; 8162f90b865SAlexander Duyck prio = DCB_ATTR_VALUE_UNDEFINED; 8172f90b865SAlexander Duyck tc_pct = DCB_ATTR_VALUE_UNDEFINED; 8182f90b865SAlexander Duyck up_map = DCB_ATTR_VALUE_UNDEFINED; 8192f90b865SAlexander Duyck 8202f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]) 8212f90b865SAlexander Duyck prio = 8222f90b865SAlexander Duyck nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]); 8232f90b865SAlexander Duyck 8242f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_PGID]) 8252f90b865SAlexander Duyck pgid = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_PGID]); 8262f90b865SAlexander Duyck 8272f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT]) 8282f90b865SAlexander Duyck tc_pct = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_BW_PCT]); 8292f90b865SAlexander Duyck 8302f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]) 8312f90b865SAlexander Duyck up_map = 8322f90b865SAlexander Duyck nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]); 8332f90b865SAlexander Duyck 8342f90b865SAlexander Duyck /* dir: Tx = 0, Rx = 1 */ 8352f90b865SAlexander Duyck if (dir) { 8362f90b865SAlexander Duyck /* Rx */ 8372f90b865SAlexander Duyck netdev->dcbnl_ops->setpgtccfgrx(netdev, 8382f90b865SAlexander Duyck i - DCB_PG_ATTR_TC_0, 8392f90b865SAlexander Duyck prio, pgid, tc_pct, up_map); 8402f90b865SAlexander Duyck } else { 8412f90b865SAlexander Duyck /* Tx */ 8422f90b865SAlexander Duyck netdev->dcbnl_ops->setpgtccfgtx(netdev, 8432f90b865SAlexander Duyck i - DCB_PG_ATTR_TC_0, 8442f90b865SAlexander Duyck prio, pgid, tc_pct, up_map); 8452f90b865SAlexander Duyck } 8462f90b865SAlexander Duyck } 8472f90b865SAlexander Duyck 8482f90b865SAlexander Duyck for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) { 8492f90b865SAlexander Duyck if (!pg_tb[i]) 8502f90b865SAlexander Duyck continue; 8512f90b865SAlexander Duyck 8522f90b865SAlexander Duyck tc_pct = nla_get_u8(pg_tb[i]); 8532f90b865SAlexander Duyck 8542f90b865SAlexander Duyck /* dir: Tx = 0, Rx = 1 */ 8552f90b865SAlexander Duyck if (dir) { 8562f90b865SAlexander Duyck /* Rx */ 8572f90b865SAlexander Duyck netdev->dcbnl_ops->setpgbwgcfgrx(netdev, 8582f90b865SAlexander Duyck i - DCB_PG_ATTR_BW_ID_0, tc_pct); 8592f90b865SAlexander Duyck } else { 8602f90b865SAlexander Duyck /* Tx */ 8612f90b865SAlexander Duyck netdev->dcbnl_ops->setpgbwgcfgtx(netdev, 8622f90b865SAlexander Duyck i - DCB_PG_ATTR_BW_ID_0, tc_pct); 8632f90b865SAlexander Duyck } 8642f90b865SAlexander Duyck } 8652f90b865SAlexander Duyck 866bb1dfefdSJohn Fastabend return nla_put_u8(skb, DCB_ATTR_PG_CFG, 0); 8672f90b865SAlexander Duyck } 8682f90b865SAlexander Duyck 8697be99413SThomas Graf static int dcbnl_pgtx_setcfg(struct net_device *netdev, struct nlmsghdr *nlh, 8707be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 8712f90b865SAlexander Duyck { 8727be99413SThomas Graf return __dcbnl_pg_setcfg(netdev, nlh, seq, tb, skb, 0); 8732f90b865SAlexander Duyck } 8742f90b865SAlexander Duyck 8757be99413SThomas Graf static int dcbnl_pgrx_setcfg(struct net_device *netdev, struct nlmsghdr *nlh, 8767be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 8772f90b865SAlexander Duyck { 8787be99413SThomas Graf return __dcbnl_pg_setcfg(netdev, nlh, seq, tb, skb, 1); 8792f90b865SAlexander Duyck } 8802f90b865SAlexander Duyck 8817be99413SThomas Graf static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlmsghdr *nlh, 8827be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 883859ee3c4SAlexander Duyck { 884859ee3c4SAlexander Duyck struct nlattr *bcn_nest; 885859ee3c4SAlexander Duyck struct nlattr *bcn_tb[DCB_BCN_ATTR_MAX + 1]; 886859ee3c4SAlexander Duyck u8 value_byte; 887859ee3c4SAlexander Duyck u32 value_integer; 8883d1f4869SThomas Graf int ret; 889859ee3c4SAlexander Duyck bool getall = false; 890859ee3c4SAlexander Duyck int i; 891859ee3c4SAlexander Duyck 8923d1f4869SThomas Graf if (!tb[DCB_ATTR_BCN]) 8933d1f4869SThomas Graf return -EINVAL; 8943d1f4869SThomas Graf 8953d1f4869SThomas Graf if (!netdev->dcbnl_ops->getbcnrp || 896859ee3c4SAlexander Duyck !netdev->dcbnl_ops->getbcncfg) 8973d1f4869SThomas Graf return -EOPNOTSUPP; 898859ee3c4SAlexander Duyck 8998cb08174SJohannes Berg ret = nla_parse_nested_deprecated(bcn_tb, DCB_BCN_ATTR_MAX, 9008cb08174SJohannes Berg tb[DCB_ATTR_BCN], dcbnl_bcn_nest, 9018cb08174SJohannes Berg NULL); 902859ee3c4SAlexander Duyck if (ret) 9033d1f4869SThomas Graf return ret; 904859ee3c4SAlexander Duyck 905ae0be8deSMichal Kubecek bcn_nest = nla_nest_start_noflag(skb, DCB_ATTR_BCN); 906859ee3c4SAlexander Duyck if (!bcn_nest) 9073d1f4869SThomas Graf return -EMSGSIZE; 908859ee3c4SAlexander Duyck 909859ee3c4SAlexander Duyck if (bcn_tb[DCB_BCN_ATTR_ALL]) 910859ee3c4SAlexander Duyck getall = true; 911859ee3c4SAlexander Duyck 912859ee3c4SAlexander Duyck for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) { 913859ee3c4SAlexander Duyck if (!getall && !bcn_tb[i]) 914859ee3c4SAlexander Duyck continue; 915859ee3c4SAlexander Duyck 916859ee3c4SAlexander Duyck netdev->dcbnl_ops->getbcnrp(netdev, i - DCB_BCN_ATTR_RP_0, 917859ee3c4SAlexander Duyck &value_byte); 9187be99413SThomas Graf ret = nla_put_u8(skb, i, value_byte); 919859ee3c4SAlexander Duyck if (ret) 920859ee3c4SAlexander Duyck goto err_bcn; 921859ee3c4SAlexander Duyck } 922859ee3c4SAlexander Duyck 923f4314e81SDon Skidmore for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) { 924859ee3c4SAlexander Duyck if (!getall && !bcn_tb[i]) 925859ee3c4SAlexander Duyck continue; 926859ee3c4SAlexander Duyck 927859ee3c4SAlexander Duyck netdev->dcbnl_ops->getbcncfg(netdev, i, 928859ee3c4SAlexander Duyck &value_integer); 9297be99413SThomas Graf ret = nla_put_u32(skb, i, value_integer); 930859ee3c4SAlexander Duyck if (ret) 931859ee3c4SAlexander Duyck goto err_bcn; 932859ee3c4SAlexander Duyck } 933859ee3c4SAlexander Duyck 9347be99413SThomas Graf nla_nest_end(skb, bcn_nest); 935859ee3c4SAlexander Duyck 936859ee3c4SAlexander Duyck return 0; 937859ee3c4SAlexander Duyck 938859ee3c4SAlexander Duyck err_bcn: 9397be99413SThomas Graf nla_nest_cancel(skb, bcn_nest); 940859ee3c4SAlexander Duyck return ret; 941859ee3c4SAlexander Duyck } 942859ee3c4SAlexander Duyck 9437be99413SThomas Graf static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlmsghdr *nlh, 9447be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 945859ee3c4SAlexander Duyck { 946859ee3c4SAlexander Duyck struct nlattr *data[DCB_BCN_ATTR_MAX + 1]; 947859ee3c4SAlexander Duyck int i; 9483d1f4869SThomas Graf int ret; 949859ee3c4SAlexander Duyck u8 value_byte; 950859ee3c4SAlexander Duyck u32 value_int; 951859ee3c4SAlexander Duyck 9523d1f4869SThomas Graf if (!tb[DCB_ATTR_BCN]) 9533d1f4869SThomas Graf return -EINVAL; 9543d1f4869SThomas Graf 9553d1f4869SThomas Graf if (!netdev->dcbnl_ops->setbcncfg || 956f64f9e71SJoe Perches !netdev->dcbnl_ops->setbcnrp) 9573d1f4869SThomas Graf return -EOPNOTSUPP; 958859ee3c4SAlexander Duyck 9598cb08174SJohannes Berg ret = nla_parse_nested_deprecated(data, DCB_BCN_ATTR_MAX, 9608cb08174SJohannes Berg tb[DCB_ATTR_BCN], dcbnl_pfc_up_nest, 9618cb08174SJohannes Berg NULL); 962859ee3c4SAlexander Duyck if (ret) 9633d1f4869SThomas Graf return ret; 964859ee3c4SAlexander Duyck 965859ee3c4SAlexander Duyck for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) { 966859ee3c4SAlexander Duyck if (data[i] == NULL) 967859ee3c4SAlexander Duyck continue; 968859ee3c4SAlexander Duyck value_byte = nla_get_u8(data[i]); 969859ee3c4SAlexander Duyck netdev->dcbnl_ops->setbcnrp(netdev, 970859ee3c4SAlexander Duyck data[i]->nla_type - DCB_BCN_ATTR_RP_0, value_byte); 971859ee3c4SAlexander Duyck } 972859ee3c4SAlexander Duyck 973f4314e81SDon Skidmore for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) { 974859ee3c4SAlexander Duyck if (data[i] == NULL) 975859ee3c4SAlexander Duyck continue; 976859ee3c4SAlexander Duyck value_int = nla_get_u32(data[i]); 977859ee3c4SAlexander Duyck netdev->dcbnl_ops->setbcncfg(netdev, 978859ee3c4SAlexander Duyck i, value_int); 979859ee3c4SAlexander Duyck } 980859ee3c4SAlexander Duyck 9813d1f4869SThomas Graf return nla_put_u8(skb, DCB_ATTR_BCN, 0); 982859ee3c4SAlexander Duyck } 983859ee3c4SAlexander Duyck 984dc6ed1dfSShmulik Ravid static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb, 985dc6ed1dfSShmulik Ravid int app_nested_type, int app_info_type, 986dc6ed1dfSShmulik Ravid int app_entry_type) 987eed84713SShmulik Ravid { 988eed84713SShmulik Ravid struct dcb_peer_app_info info; 989eed84713SShmulik Ravid struct dcb_app *table = NULL; 990eed84713SShmulik Ravid const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; 991eed84713SShmulik Ravid u16 app_count; 992eed84713SShmulik Ravid int err; 993eed84713SShmulik Ravid 994eed84713SShmulik Ravid 995eed84713SShmulik Ravid /** 996eed84713SShmulik Ravid * retrieve the peer app configuration form the driver. If the driver 997eed84713SShmulik Ravid * handlers fail exit without doing anything 998eed84713SShmulik Ravid */ 999eed84713SShmulik Ravid err = ops->peer_getappinfo(netdev, &info, &app_count); 1000eed84713SShmulik Ravid if (!err && app_count) { 10016da2ec56SKees Cook table = kmalloc_array(app_count, sizeof(struct dcb_app), 10026da2ec56SKees Cook GFP_KERNEL); 1003eed84713SShmulik Ravid if (!table) 1004eed84713SShmulik Ravid return -ENOMEM; 1005eed84713SShmulik Ravid 1006eed84713SShmulik Ravid err = ops->peer_getapptable(netdev, table); 1007eed84713SShmulik Ravid } 1008eed84713SShmulik Ravid 1009eed84713SShmulik Ravid if (!err) { 1010eed84713SShmulik Ravid u16 i; 1011eed84713SShmulik Ravid struct nlattr *app; 1012eed84713SShmulik Ravid 1013eed84713SShmulik Ravid /** 1014eed84713SShmulik Ravid * build the message, from here on the only possible failure 1015eed84713SShmulik Ravid * is due to the skb size 1016eed84713SShmulik Ravid */ 1017eed84713SShmulik Ravid err = -EMSGSIZE; 1018eed84713SShmulik Ravid 1019ae0be8deSMichal Kubecek app = nla_nest_start_noflag(skb, app_nested_type); 1020eed84713SShmulik Ravid if (!app) 1021eed84713SShmulik Ravid goto nla_put_failure; 1022eed84713SShmulik Ravid 10231eb4c977SDavid S. Miller if (app_info_type && 10241eb4c977SDavid S. Miller nla_put(skb, app_info_type, sizeof(info), &info)) 10251eb4c977SDavid S. Miller goto nla_put_failure; 1026dc6ed1dfSShmulik Ravid 10271eb4c977SDavid S. Miller for (i = 0; i < app_count; i++) { 10281eb4c977SDavid S. Miller if (nla_put(skb, app_entry_type, sizeof(struct dcb_app), 10291eb4c977SDavid S. Miller &table[i])) 10301eb4c977SDavid S. Miller goto nla_put_failure; 10311eb4c977SDavid S. Miller } 1032eed84713SShmulik Ravid nla_nest_end(skb, app); 1033eed84713SShmulik Ravid } 1034eed84713SShmulik Ravid err = 0; 1035eed84713SShmulik Ravid 1036eed84713SShmulik Ravid nla_put_failure: 1037eed84713SShmulik Ravid kfree(table); 1038eed84713SShmulik Ravid return err; 1039eed84713SShmulik Ravid } 10403e29027aSJohn Fastabend 1041c9368247SShani Michaeli /* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb GET commands. */ 1042314b4778SJohn Fastabend static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) 10433e29027aSJohn Fastabend { 10449ab933abSJohn Fastabend struct nlattr *ieee, *app; 10459ab933abSJohn Fastabend struct dcb_app_type *itr; 10463e29027aSJohn Fastabend const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; 1047c7797bafSJohn Fastabend int dcbx; 10483d1f4869SThomas Graf int err; 10493e29027aSJohn Fastabend 10501eb4c977SDavid S. Miller if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name)) 10513d1f4869SThomas Graf return -EMSGSIZE; 10523d1f4869SThomas Graf 1053ae0be8deSMichal Kubecek ieee = nla_nest_start_noflag(skb, DCB_ATTR_IEEE); 10543e29027aSJohn Fastabend if (!ieee) 10553d1f4869SThomas Graf return -EMSGSIZE; 10563e29027aSJohn Fastabend 10573e29027aSJohn Fastabend if (ops->ieee_getets) { 10583e29027aSJohn Fastabend struct ieee_ets ets; 105929cd8ae0SMathias Krause memset(&ets, 0, sizeof(ets)); 10603e29027aSJohn Fastabend err = ops->ieee_getets(netdev, &ets); 10611eb4c977SDavid S. Miller if (!err && 10621eb4c977SDavid S. Miller nla_put(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets)) 10633d1f4869SThomas Graf return -EMSGSIZE; 10643e29027aSJohn Fastabend } 10653e29027aSJohn Fastabend 106608f10affSAmir Vadai if (ops->ieee_getmaxrate) { 106708f10affSAmir Vadai struct ieee_maxrate maxrate; 106829cd8ae0SMathias Krause memset(&maxrate, 0, sizeof(maxrate)); 106908f10affSAmir Vadai err = ops->ieee_getmaxrate(netdev, &maxrate); 107008f10affSAmir Vadai if (!err) { 107108f10affSAmir Vadai err = nla_put(skb, DCB_ATTR_IEEE_MAXRATE, 107208f10affSAmir Vadai sizeof(maxrate), &maxrate); 107308f10affSAmir Vadai if (err) 10743d1f4869SThomas Graf return -EMSGSIZE; 107508f10affSAmir Vadai } 107608f10affSAmir Vadai } 107708f10affSAmir Vadai 1078c9368247SShani Michaeli if (ops->ieee_getqcn) { 1079c9368247SShani Michaeli struct ieee_qcn qcn; 1080c9368247SShani Michaeli 1081c9368247SShani Michaeli memset(&qcn, 0, sizeof(qcn)); 1082c9368247SShani Michaeli err = ops->ieee_getqcn(netdev, &qcn); 1083c9368247SShani Michaeli if (!err) { 1084c9368247SShani Michaeli err = nla_put(skb, DCB_ATTR_IEEE_QCN, 1085c9368247SShani Michaeli sizeof(qcn), &qcn); 1086c9368247SShani Michaeli if (err) 1087c9368247SShani Michaeli return -EMSGSIZE; 1088c9368247SShani Michaeli } 1089c9368247SShani Michaeli } 1090c9368247SShani Michaeli 1091c9368247SShani Michaeli if (ops->ieee_getqcnstats) { 1092c9368247SShani Michaeli struct ieee_qcn_stats qcn_stats; 1093c9368247SShani Michaeli 1094c9368247SShani Michaeli memset(&qcn_stats, 0, sizeof(qcn_stats)); 1095c9368247SShani Michaeli err = ops->ieee_getqcnstats(netdev, &qcn_stats); 1096c9368247SShani Michaeli if (!err) { 1097c9368247SShani Michaeli err = nla_put(skb, DCB_ATTR_IEEE_QCN_STATS, 1098c9368247SShani Michaeli sizeof(qcn_stats), &qcn_stats); 1099c9368247SShani Michaeli if (err) 1100c9368247SShani Michaeli return -EMSGSIZE; 1101c9368247SShani Michaeli } 1102c9368247SShani Michaeli } 1103c9368247SShani Michaeli 11043e29027aSJohn Fastabend if (ops->ieee_getpfc) { 11053e29027aSJohn Fastabend struct ieee_pfc pfc; 110629cd8ae0SMathias Krause memset(&pfc, 0, sizeof(pfc)); 11073e29027aSJohn Fastabend err = ops->ieee_getpfc(netdev, &pfc); 11081eb4c977SDavid S. Miller if (!err && 11091eb4c977SDavid S. Miller nla_put(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc)) 11103d1f4869SThomas Graf return -EMSGSIZE; 11113e29027aSJohn Fastabend } 11123e29027aSJohn Fastabend 1113e549f6f9SHuy Nguyen if (ops->dcbnl_getbuffer) { 1114e549f6f9SHuy Nguyen struct dcbnl_buffer buffer; 1115e549f6f9SHuy Nguyen 1116e549f6f9SHuy Nguyen memset(&buffer, 0, sizeof(buffer)); 1117e549f6f9SHuy Nguyen err = ops->dcbnl_getbuffer(netdev, &buffer); 1118e549f6f9SHuy Nguyen if (!err && 1119e549f6f9SHuy Nguyen nla_put(skb, DCB_ATTR_DCB_BUFFER, sizeof(buffer), &buffer)) 1120e549f6f9SHuy Nguyen return -EMSGSIZE; 1121e549f6f9SHuy Nguyen } 1122e549f6f9SHuy Nguyen 1123ae0be8deSMichal Kubecek app = nla_nest_start_noflag(skb, DCB_ATTR_IEEE_APP_TABLE); 11249ab933abSJohn Fastabend if (!app) 11253d1f4869SThomas Graf return -EMSGSIZE; 11269ab933abSJohn Fastabend 112752cff74eSAnish Bhatt spin_lock_bh(&dcb_lock); 11289ab933abSJohn Fastabend list_for_each_entry(itr, &dcb_app_list, list) { 1129e290ed81SMark Rustad if (itr->ifindex == netdev->ifindex) { 113070bfa2d2SDan Carpenter err = nla_put(skb, DCB_ATTR_IEEE_APP, sizeof(itr->app), 113170bfa2d2SDan Carpenter &itr->app); 113270bfa2d2SDan Carpenter if (err) { 113352cff74eSAnish Bhatt spin_unlock_bh(&dcb_lock); 11343d1f4869SThomas Graf return -EMSGSIZE; 113570bfa2d2SDan Carpenter } 113670bfa2d2SDan Carpenter } 11379ab933abSJohn Fastabend } 1138c7797bafSJohn Fastabend 1139c7797bafSJohn Fastabend if (netdev->dcbnl_ops->getdcbx) 1140c7797bafSJohn Fastabend dcbx = netdev->dcbnl_ops->getdcbx(netdev); 1141c7797bafSJohn Fastabend else 1142c7797bafSJohn Fastabend dcbx = -EOPNOTSUPP; 1143c7797bafSJohn Fastabend 114452cff74eSAnish Bhatt spin_unlock_bh(&dcb_lock); 11459ab933abSJohn Fastabend nla_nest_end(skb, app); 11469ab933abSJohn Fastabend 1147eed84713SShmulik Ravid /* get peer info if available */ 1148eed84713SShmulik Ravid if (ops->ieee_peer_getets) { 1149eed84713SShmulik Ravid struct ieee_ets ets; 115029cd8ae0SMathias Krause memset(&ets, 0, sizeof(ets)); 1151eed84713SShmulik Ravid err = ops->ieee_peer_getets(netdev, &ets); 11521eb4c977SDavid S. Miller if (!err && 11531eb4c977SDavid S. Miller nla_put(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets)) 11543d1f4869SThomas Graf return -EMSGSIZE; 1155eed84713SShmulik Ravid } 1156eed84713SShmulik Ravid 1157eed84713SShmulik Ravid if (ops->ieee_peer_getpfc) { 1158eed84713SShmulik Ravid struct ieee_pfc pfc; 115929cd8ae0SMathias Krause memset(&pfc, 0, sizeof(pfc)); 1160eed84713SShmulik Ravid err = ops->ieee_peer_getpfc(netdev, &pfc); 11611eb4c977SDavid S. Miller if (!err && 11621eb4c977SDavid S. Miller nla_put(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc)) 11633d1f4869SThomas Graf return -EMSGSIZE; 1164eed84713SShmulik Ravid } 1165eed84713SShmulik Ravid 1166eed84713SShmulik Ravid if (ops->peer_getappinfo && ops->peer_getapptable) { 1167dc6ed1dfSShmulik Ravid err = dcbnl_build_peer_app(netdev, skb, 1168dc6ed1dfSShmulik Ravid DCB_ATTR_IEEE_PEER_APP, 1169dc6ed1dfSShmulik Ravid DCB_ATTR_IEEE_APP_UNSPEC, 1170dc6ed1dfSShmulik Ravid DCB_ATTR_IEEE_APP); 1171eed84713SShmulik Ravid if (err) 11723d1f4869SThomas Graf return -EMSGSIZE; 1173eed84713SShmulik Ravid } 1174eed84713SShmulik Ravid 11753e29027aSJohn Fastabend nla_nest_end(skb, ieee); 1176c7797bafSJohn Fastabend if (dcbx >= 0) { 1177c7797bafSJohn Fastabend err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx); 1178c7797bafSJohn Fastabend if (err) 11793d1f4869SThomas Graf return -EMSGSIZE; 1180c7797bafSJohn Fastabend } 11813e29027aSJohn Fastabend 1182314b4778SJohn Fastabend return 0; 11833e29027aSJohn Fastabend } 11843e29027aSJohn Fastabend 11855b7f7626SShmulik Ravid static int dcbnl_cee_pg_fill(struct sk_buff *skb, struct net_device *dev, 11865b7f7626SShmulik Ravid int dir) 11875b7f7626SShmulik Ravid { 11885b7f7626SShmulik Ravid u8 pgid, up_map, prio, tc_pct; 11895b7f7626SShmulik Ravid const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops; 11905b7f7626SShmulik Ravid int i = dir ? DCB_ATTR_CEE_TX_PG : DCB_ATTR_CEE_RX_PG; 1191ae0be8deSMichal Kubecek struct nlattr *pg = nla_nest_start_noflag(skb, i); 11925b7f7626SShmulik Ravid 11935b7f7626SShmulik Ravid if (!pg) 11943d1f4869SThomas Graf return -EMSGSIZE; 11955b7f7626SShmulik Ravid 11965b7f7626SShmulik Ravid for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) { 1197ae0be8deSMichal Kubecek struct nlattr *tc_nest = nla_nest_start_noflag(skb, i); 11985b7f7626SShmulik Ravid 11995b7f7626SShmulik Ravid if (!tc_nest) 12003d1f4869SThomas Graf return -EMSGSIZE; 12015b7f7626SShmulik Ravid 12025b7f7626SShmulik Ravid pgid = DCB_ATTR_VALUE_UNDEFINED; 12035b7f7626SShmulik Ravid prio = DCB_ATTR_VALUE_UNDEFINED; 12045b7f7626SShmulik Ravid tc_pct = DCB_ATTR_VALUE_UNDEFINED; 12055b7f7626SShmulik Ravid up_map = DCB_ATTR_VALUE_UNDEFINED; 12065b7f7626SShmulik Ravid 12075b7f7626SShmulik Ravid if (!dir) 12085b7f7626SShmulik Ravid ops->getpgtccfgrx(dev, i - DCB_PG_ATTR_TC_0, 12095b7f7626SShmulik Ravid &prio, &pgid, &tc_pct, &up_map); 12105b7f7626SShmulik Ravid else 12115b7f7626SShmulik Ravid ops->getpgtccfgtx(dev, i - DCB_PG_ATTR_TC_0, 12125b7f7626SShmulik Ravid &prio, &pgid, &tc_pct, &up_map); 12135b7f7626SShmulik Ravid 12141eb4c977SDavid S. Miller if (nla_put_u8(skb, DCB_TC_ATTR_PARAM_PGID, pgid) || 12151eb4c977SDavid S. Miller nla_put_u8(skb, DCB_TC_ATTR_PARAM_UP_MAPPING, up_map) || 12161eb4c977SDavid S. Miller nla_put_u8(skb, DCB_TC_ATTR_PARAM_STRICT_PRIO, prio) || 12171eb4c977SDavid S. Miller nla_put_u8(skb, DCB_TC_ATTR_PARAM_BW_PCT, tc_pct)) 12183d1f4869SThomas Graf return -EMSGSIZE; 12195b7f7626SShmulik Ravid nla_nest_end(skb, tc_nest); 12205b7f7626SShmulik Ravid } 12215b7f7626SShmulik Ravid 12225b7f7626SShmulik Ravid for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) { 12235b7f7626SShmulik Ravid tc_pct = DCB_ATTR_VALUE_UNDEFINED; 12245b7f7626SShmulik Ravid 12255b7f7626SShmulik Ravid if (!dir) 12265b7f7626SShmulik Ravid ops->getpgbwgcfgrx(dev, i - DCB_PG_ATTR_BW_ID_0, 12275b7f7626SShmulik Ravid &tc_pct); 12285b7f7626SShmulik Ravid else 12295b7f7626SShmulik Ravid ops->getpgbwgcfgtx(dev, i - DCB_PG_ATTR_BW_ID_0, 12305b7f7626SShmulik Ravid &tc_pct); 12311eb4c977SDavid S. Miller if (nla_put_u8(skb, i, tc_pct)) 12323d1f4869SThomas Graf return -EMSGSIZE; 12335b7f7626SShmulik Ravid } 12345b7f7626SShmulik Ravid nla_nest_end(skb, pg); 12355b7f7626SShmulik Ravid return 0; 12365b7f7626SShmulik Ravid } 12375b7f7626SShmulik Ravid 12385b7f7626SShmulik Ravid static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev) 12395b7f7626SShmulik Ravid { 12405b7f7626SShmulik Ravid struct nlattr *cee, *app; 12415b7f7626SShmulik Ravid struct dcb_app_type *itr; 12425b7f7626SShmulik Ravid const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; 12435b7f7626SShmulik Ravid int dcbx, i, err = -EMSGSIZE; 12445b7f7626SShmulik Ravid u8 value; 12455b7f7626SShmulik Ravid 12461eb4c977SDavid S. Miller if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name)) 12471eb4c977SDavid S. Miller goto nla_put_failure; 1248ae0be8deSMichal Kubecek cee = nla_nest_start_noflag(skb, DCB_ATTR_CEE); 12495b7f7626SShmulik Ravid if (!cee) 12505b7f7626SShmulik Ravid goto nla_put_failure; 12515b7f7626SShmulik Ravid 12525b7f7626SShmulik Ravid /* local pg */ 12535b7f7626SShmulik Ravid if (ops->getpgtccfgtx && ops->getpgbwgcfgtx) { 12545b7f7626SShmulik Ravid err = dcbnl_cee_pg_fill(skb, netdev, 1); 12555b7f7626SShmulik Ravid if (err) 12565b7f7626SShmulik Ravid goto nla_put_failure; 12575b7f7626SShmulik Ravid } 12585b7f7626SShmulik Ravid 12595b7f7626SShmulik Ravid if (ops->getpgtccfgrx && ops->getpgbwgcfgrx) { 12605b7f7626SShmulik Ravid err = dcbnl_cee_pg_fill(skb, netdev, 0); 12615b7f7626SShmulik Ravid if (err) 12625b7f7626SShmulik Ravid goto nla_put_failure; 12635b7f7626SShmulik Ravid } 12645b7f7626SShmulik Ravid 12655b7f7626SShmulik Ravid /* local pfc */ 12665b7f7626SShmulik Ravid if (ops->getpfccfg) { 1267ae0be8deSMichal Kubecek struct nlattr *pfc_nest = nla_nest_start_noflag(skb, 1268ae0be8deSMichal Kubecek DCB_ATTR_CEE_PFC); 12695b7f7626SShmulik Ravid 12705b7f7626SShmulik Ravid if (!pfc_nest) 12715b7f7626SShmulik Ravid goto nla_put_failure; 12725b7f7626SShmulik Ravid 12735b7f7626SShmulik Ravid for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) { 12745b7f7626SShmulik Ravid ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0, &value); 12751eb4c977SDavid S. Miller if (nla_put_u8(skb, i, value)) 12761eb4c977SDavid S. Miller goto nla_put_failure; 12775b7f7626SShmulik Ravid } 12785b7f7626SShmulik Ravid nla_nest_end(skb, pfc_nest); 12795b7f7626SShmulik Ravid } 12805b7f7626SShmulik Ravid 12815b7f7626SShmulik Ravid /* local app */ 128252cff74eSAnish Bhatt spin_lock_bh(&dcb_lock); 1283ae0be8deSMichal Kubecek app = nla_nest_start_noflag(skb, DCB_ATTR_CEE_APP_TABLE); 12845b7f7626SShmulik Ravid if (!app) 128540f5d72aSDan Carpenter goto dcb_unlock; 12865b7f7626SShmulik Ravid 12875b7f7626SShmulik Ravid list_for_each_entry(itr, &dcb_app_list, list) { 1288e290ed81SMark Rustad if (itr->ifindex == netdev->ifindex) { 1289ae0be8deSMichal Kubecek struct nlattr *app_nest = nla_nest_start_noflag(skb, 12905b7f7626SShmulik Ravid DCB_ATTR_APP); 12915b7f7626SShmulik Ravid if (!app_nest) 12925b7f7626SShmulik Ravid goto dcb_unlock; 12935b7f7626SShmulik Ravid 12945b7f7626SShmulik Ravid err = nla_put_u8(skb, DCB_APP_ATTR_IDTYPE, 12955b7f7626SShmulik Ravid itr->app.selector); 12965b7f7626SShmulik Ravid if (err) 12975b7f7626SShmulik Ravid goto dcb_unlock; 12985b7f7626SShmulik Ravid 12995b7f7626SShmulik Ravid err = nla_put_u16(skb, DCB_APP_ATTR_ID, 13005b7f7626SShmulik Ravid itr->app.protocol); 13015b7f7626SShmulik Ravid if (err) 13025b7f7626SShmulik Ravid goto dcb_unlock; 13035b7f7626SShmulik Ravid 13045b7f7626SShmulik Ravid err = nla_put_u8(skb, DCB_APP_ATTR_PRIORITY, 13055b7f7626SShmulik Ravid itr->app.priority); 13065b7f7626SShmulik Ravid if (err) 13075b7f7626SShmulik Ravid goto dcb_unlock; 13085b7f7626SShmulik Ravid 13095b7f7626SShmulik Ravid nla_nest_end(skb, app_nest); 13105b7f7626SShmulik Ravid } 13115b7f7626SShmulik Ravid } 13125b7f7626SShmulik Ravid nla_nest_end(skb, app); 13135b7f7626SShmulik Ravid 13145b7f7626SShmulik Ravid if (netdev->dcbnl_ops->getdcbx) 13155b7f7626SShmulik Ravid dcbx = netdev->dcbnl_ops->getdcbx(netdev); 13165b7f7626SShmulik Ravid else 13175b7f7626SShmulik Ravid dcbx = -EOPNOTSUPP; 13185b7f7626SShmulik Ravid 131952cff74eSAnish Bhatt spin_unlock_bh(&dcb_lock); 13205b7f7626SShmulik Ravid 13215b7f7626SShmulik Ravid /* features flags */ 13225b7f7626SShmulik Ravid if (ops->getfeatcfg) { 1323ae0be8deSMichal Kubecek struct nlattr *feat = nla_nest_start_noflag(skb, 1324ae0be8deSMichal Kubecek DCB_ATTR_CEE_FEAT); 13255b7f7626SShmulik Ravid if (!feat) 13265b7f7626SShmulik Ravid goto nla_put_failure; 13275b7f7626SShmulik Ravid 13285b7f7626SShmulik Ravid for (i = DCB_FEATCFG_ATTR_ALL + 1; i <= DCB_FEATCFG_ATTR_MAX; 13295b7f7626SShmulik Ravid i++) 13301eb4c977SDavid S. Miller if (!ops->getfeatcfg(netdev, i, &value) && 13311eb4c977SDavid S. Miller nla_put_u8(skb, i, value)) 13321eb4c977SDavid S. Miller goto nla_put_failure; 13335b7f7626SShmulik Ravid 13345b7f7626SShmulik Ravid nla_nest_end(skb, feat); 13355b7f7626SShmulik Ravid } 13365b7f7626SShmulik Ravid 13375b7f7626SShmulik Ravid /* peer info if available */ 13385b7f7626SShmulik Ravid if (ops->cee_peer_getpg) { 13395b7f7626SShmulik Ravid struct cee_pg pg; 134029cd8ae0SMathias Krause memset(&pg, 0, sizeof(pg)); 13415b7f7626SShmulik Ravid err = ops->cee_peer_getpg(netdev, &pg); 13421eb4c977SDavid S. Miller if (!err && 13431eb4c977SDavid S. Miller nla_put(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg)) 13441eb4c977SDavid S. Miller goto nla_put_failure; 13455b7f7626SShmulik Ravid } 13465b7f7626SShmulik Ravid 13475b7f7626SShmulik Ravid if (ops->cee_peer_getpfc) { 13485b7f7626SShmulik Ravid struct cee_pfc pfc; 134929cd8ae0SMathias Krause memset(&pfc, 0, sizeof(pfc)); 13505b7f7626SShmulik Ravid err = ops->cee_peer_getpfc(netdev, &pfc); 13511eb4c977SDavid S. Miller if (!err && 13521eb4c977SDavid S. Miller nla_put(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc)) 13531eb4c977SDavid S. Miller goto nla_put_failure; 13545b7f7626SShmulik Ravid } 13555b7f7626SShmulik Ravid 13565b7f7626SShmulik Ravid if (ops->peer_getappinfo && ops->peer_getapptable) { 13575b7f7626SShmulik Ravid err = dcbnl_build_peer_app(netdev, skb, 13585b7f7626SShmulik Ravid DCB_ATTR_CEE_PEER_APP_TABLE, 13595b7f7626SShmulik Ravid DCB_ATTR_CEE_PEER_APP_INFO, 13605b7f7626SShmulik Ravid DCB_ATTR_CEE_PEER_APP); 13615b7f7626SShmulik Ravid if (err) 13625b7f7626SShmulik Ravid goto nla_put_failure; 13635b7f7626SShmulik Ravid } 13645b7f7626SShmulik Ravid nla_nest_end(skb, cee); 13655b7f7626SShmulik Ravid 13665b7f7626SShmulik Ravid /* DCBX state */ 13675b7f7626SShmulik Ravid if (dcbx >= 0) { 13685b7f7626SShmulik Ravid err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx); 13695b7f7626SShmulik Ravid if (err) 13705b7f7626SShmulik Ravid goto nla_put_failure; 13715b7f7626SShmulik Ravid } 13725b7f7626SShmulik Ravid return 0; 13735b7f7626SShmulik Ravid 13745b7f7626SShmulik Ravid dcb_unlock: 137552cff74eSAnish Bhatt spin_unlock_bh(&dcb_lock); 13765b7f7626SShmulik Ravid nla_put_failure: 1377c66ebf2dSPan Bian err = -EMSGSIZE; 13785b7f7626SShmulik Ravid return err; 13795b7f7626SShmulik Ravid } 13805b7f7626SShmulik Ravid 13815b7f7626SShmulik Ravid static int dcbnl_notify(struct net_device *dev, int event, int cmd, 138215e47304SEric W. Biederman u32 seq, u32 portid, int dcbx_ver) 1383314b4778SJohn Fastabend { 1384314b4778SJohn Fastabend struct net *net = dev_net(dev); 1385314b4778SJohn Fastabend struct sk_buff *skb; 1386314b4778SJohn Fastabend struct nlmsghdr *nlh; 1387314b4778SJohn Fastabend const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops; 1388314b4778SJohn Fastabend int err; 1389314b4778SJohn Fastabend 1390314b4778SJohn Fastabend if (!ops) 1391314b4778SJohn Fastabend return -EOPNOTSUPP; 1392314b4778SJohn Fastabend 139315e47304SEric W. Biederman skb = dcbnl_newmsg(event, cmd, portid, seq, 0, &nlh); 1394314b4778SJohn Fastabend if (!skb) 1395314b4778SJohn Fastabend return -ENOBUFS; 1396314b4778SJohn Fastabend 13975b7f7626SShmulik Ravid if (dcbx_ver == DCB_CAP_DCBX_VER_IEEE) 1398314b4778SJohn Fastabend err = dcbnl_ieee_fill(skb, dev); 13995b7f7626SShmulik Ravid else 14005b7f7626SShmulik Ravid err = dcbnl_cee_fill(skb, dev); 14015b7f7626SShmulik Ravid 1402314b4778SJohn Fastabend if (err < 0) { 1403314b4778SJohn Fastabend /* Report error to broadcast listeners */ 1404ab6d4707SThomas Graf nlmsg_free(skb); 1405314b4778SJohn Fastabend rtnl_set_sk_err(net, RTNLGRP_DCB, err); 1406314b4778SJohn Fastabend } else { 1407314b4778SJohn Fastabend /* End nlmsg and notify broadcast listeners */ 1408314b4778SJohn Fastabend nlmsg_end(skb, nlh); 1409314b4778SJohn Fastabend rtnl_notify(skb, net, 0, RTNLGRP_DCB, NULL, GFP_KERNEL); 1410314b4778SJohn Fastabend } 1411314b4778SJohn Fastabend 1412314b4778SJohn Fastabend return err; 1413314b4778SJohn Fastabend } 14145b7f7626SShmulik Ravid 14155b7f7626SShmulik Ravid int dcbnl_ieee_notify(struct net_device *dev, int event, int cmd, 141615e47304SEric W. Biederman u32 seq, u32 portid) 14175b7f7626SShmulik Ravid { 141815e47304SEric W. Biederman return dcbnl_notify(dev, event, cmd, seq, portid, DCB_CAP_DCBX_VER_IEEE); 14195b7f7626SShmulik Ravid } 14205b7f7626SShmulik Ravid EXPORT_SYMBOL(dcbnl_ieee_notify); 14215b7f7626SShmulik Ravid 14225b7f7626SShmulik Ravid int dcbnl_cee_notify(struct net_device *dev, int event, int cmd, 142315e47304SEric W. Biederman u32 seq, u32 portid) 14245b7f7626SShmulik Ravid { 142515e47304SEric W. Biederman return dcbnl_notify(dev, event, cmd, seq, portid, DCB_CAP_DCBX_VER_CEE); 14265b7f7626SShmulik Ravid } 14275b7f7626SShmulik Ravid EXPORT_SYMBOL(dcbnl_cee_notify); 1428314b4778SJohn Fastabend 1429c9368247SShani Michaeli /* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb SET commands. 1430c9368247SShani Michaeli * If any requested operation can not be completed 1431c9368247SShani Michaeli * the entire msg is aborted and error value is returned. 1432314b4778SJohn Fastabend * No attempt is made to reconcile the case where only part of the 1433314b4778SJohn Fastabend * cmd can be completed. 1434314b4778SJohn Fastabend */ 14357be99413SThomas Graf static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh, 14367be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 1437314b4778SJohn Fastabend { 1438314b4778SJohn Fastabend const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; 1439314b4778SJohn Fastabend struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1]; 14403d1f4869SThomas Graf int err; 1441314b4778SJohn Fastabend 1442314b4778SJohn Fastabend if (!ops) 14433d1f4869SThomas Graf return -EOPNOTSUPP; 1444314b4778SJohn Fastabend 14454003b658SJohn Fastabend if (!tb[DCB_ATTR_IEEE]) 14464003b658SJohn Fastabend return -EINVAL; 14474003b658SJohn Fastabend 14488cb08174SJohannes Berg err = nla_parse_nested_deprecated(ieee, DCB_ATTR_IEEE_MAX, 14498cb08174SJohannes Berg tb[DCB_ATTR_IEEE], 1450fceb6435SJohannes Berg dcbnl_ieee_policy, NULL); 1451314b4778SJohn Fastabend if (err) 1452314b4778SJohn Fastabend return err; 1453314b4778SJohn Fastabend 1454314b4778SJohn Fastabend if (ieee[DCB_ATTR_IEEE_ETS] && ops->ieee_setets) { 1455314b4778SJohn Fastabend struct ieee_ets *ets = nla_data(ieee[DCB_ATTR_IEEE_ETS]); 1456314b4778SJohn Fastabend err = ops->ieee_setets(netdev, ets); 1457314b4778SJohn Fastabend if (err) 1458314b4778SJohn Fastabend goto err; 1459314b4778SJohn Fastabend } 1460314b4778SJohn Fastabend 146108f10affSAmir Vadai if (ieee[DCB_ATTR_IEEE_MAXRATE] && ops->ieee_setmaxrate) { 146208f10affSAmir Vadai struct ieee_maxrate *maxrate = 146308f10affSAmir Vadai nla_data(ieee[DCB_ATTR_IEEE_MAXRATE]); 146408f10affSAmir Vadai err = ops->ieee_setmaxrate(netdev, maxrate); 146508f10affSAmir Vadai if (err) 146608f10affSAmir Vadai goto err; 146708f10affSAmir Vadai } 146808f10affSAmir Vadai 1469c9368247SShani Michaeli if (ieee[DCB_ATTR_IEEE_QCN] && ops->ieee_setqcn) { 1470c9368247SShani Michaeli struct ieee_qcn *qcn = 1471c9368247SShani Michaeli nla_data(ieee[DCB_ATTR_IEEE_QCN]); 1472c9368247SShani Michaeli 1473c9368247SShani Michaeli err = ops->ieee_setqcn(netdev, qcn); 1474c9368247SShani Michaeli if (err) 1475c9368247SShani Michaeli goto err; 1476c9368247SShani Michaeli } 1477c9368247SShani Michaeli 1478314b4778SJohn Fastabend if (ieee[DCB_ATTR_IEEE_PFC] && ops->ieee_setpfc) { 1479314b4778SJohn Fastabend struct ieee_pfc *pfc = nla_data(ieee[DCB_ATTR_IEEE_PFC]); 1480314b4778SJohn Fastabend err = ops->ieee_setpfc(netdev, pfc); 1481314b4778SJohn Fastabend if (err) 1482314b4778SJohn Fastabend goto err; 1483314b4778SJohn Fastabend } 1484314b4778SJohn Fastabend 1485e549f6f9SHuy Nguyen if (ieee[DCB_ATTR_DCB_BUFFER] && ops->dcbnl_setbuffer) { 1486e549f6f9SHuy Nguyen struct dcbnl_buffer *buffer = 1487e549f6f9SHuy Nguyen nla_data(ieee[DCB_ATTR_DCB_BUFFER]); 1488e549f6f9SHuy Nguyen 1489e549f6f9SHuy Nguyen err = ops->dcbnl_setbuffer(netdev, buffer); 1490e549f6f9SHuy Nguyen if (err) 1491e549f6f9SHuy Nguyen goto err; 1492e549f6f9SHuy Nguyen } 1493e549f6f9SHuy Nguyen 1494314b4778SJohn Fastabend if (ieee[DCB_ATTR_IEEE_APP_TABLE]) { 1495314b4778SJohn Fastabend struct nlattr *attr; 1496314b4778SJohn Fastabend int rem; 1497314b4778SJohn Fastabend 1498314b4778SJohn Fastabend nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) { 1499314b4778SJohn Fastabend struct dcb_app *app_data; 1500332b4fc8Sstephen hemminger 1501314b4778SJohn Fastabend if (nla_type(attr) != DCB_ATTR_IEEE_APP) 1502314b4778SJohn Fastabend continue; 1503332b4fc8Sstephen hemminger 1504332b4fc8Sstephen hemminger if (nla_len(attr) < sizeof(struct dcb_app)) { 1505332b4fc8Sstephen hemminger err = -ERANGE; 1506332b4fc8Sstephen hemminger goto err; 1507332b4fc8Sstephen hemminger } 1508332b4fc8Sstephen hemminger 1509314b4778SJohn Fastabend app_data = nla_data(attr); 1510314b4778SJohn Fastabend if (ops->ieee_setapp) 1511314b4778SJohn Fastabend err = ops->ieee_setapp(netdev, app_data); 1512314b4778SJohn Fastabend else 1513b6db2174SJohn Fastabend err = dcb_ieee_setapp(netdev, app_data); 1514314b4778SJohn Fastabend if (err) 1515314b4778SJohn Fastabend goto err; 1516314b4778SJohn Fastabend } 1517314b4778SJohn Fastabend } 1518314b4778SJohn Fastabend 1519314b4778SJohn Fastabend err: 15207be99413SThomas Graf err = nla_put_u8(skb, DCB_ATTR_IEEE, err); 15215b7f7626SShmulik Ravid dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_SET, seq, 0); 1522314b4778SJohn Fastabend return err; 1523314b4778SJohn Fastabend } 1524314b4778SJohn Fastabend 15257be99413SThomas Graf static int dcbnl_ieee_get(struct net_device *netdev, struct nlmsghdr *nlh, 15267be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 1527314b4778SJohn Fastabend { 1528314b4778SJohn Fastabend const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; 1529314b4778SJohn Fastabend 1530314b4778SJohn Fastabend if (!ops) 1531314b4778SJohn Fastabend return -EOPNOTSUPP; 1532314b4778SJohn Fastabend 15337be99413SThomas Graf return dcbnl_ieee_fill(skb, netdev); 1534314b4778SJohn Fastabend } 1535314b4778SJohn Fastabend 15367be99413SThomas Graf static int dcbnl_ieee_del(struct net_device *netdev, struct nlmsghdr *nlh, 15377be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 1538f9ae7e4bSJohn Fastabend { 1539f9ae7e4bSJohn Fastabend const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; 1540f9ae7e4bSJohn Fastabend struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1]; 15413d1f4869SThomas Graf int err; 1542f9ae7e4bSJohn Fastabend 1543f9ae7e4bSJohn Fastabend if (!ops) 1544f9ae7e4bSJohn Fastabend return -EOPNOTSUPP; 1545f9ae7e4bSJohn Fastabend 1546f9ae7e4bSJohn Fastabend if (!tb[DCB_ATTR_IEEE]) 1547f9ae7e4bSJohn Fastabend return -EINVAL; 1548f9ae7e4bSJohn Fastabend 15498cb08174SJohannes Berg err = nla_parse_nested_deprecated(ieee, DCB_ATTR_IEEE_MAX, 15508cb08174SJohannes Berg tb[DCB_ATTR_IEEE], 1551fceb6435SJohannes Berg dcbnl_ieee_policy, NULL); 1552f9ae7e4bSJohn Fastabend if (err) 1553f9ae7e4bSJohn Fastabend return err; 1554f9ae7e4bSJohn Fastabend 1555f9ae7e4bSJohn Fastabend if (ieee[DCB_ATTR_IEEE_APP_TABLE]) { 1556f9ae7e4bSJohn Fastabend struct nlattr *attr; 1557f9ae7e4bSJohn Fastabend int rem; 1558f9ae7e4bSJohn Fastabend 1559f9ae7e4bSJohn Fastabend nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) { 1560f9ae7e4bSJohn Fastabend struct dcb_app *app_data; 1561f9ae7e4bSJohn Fastabend 1562f9ae7e4bSJohn Fastabend if (nla_type(attr) != DCB_ATTR_IEEE_APP) 1563f9ae7e4bSJohn Fastabend continue; 1564f9ae7e4bSJohn Fastabend app_data = nla_data(attr); 1565f9ae7e4bSJohn Fastabend if (ops->ieee_delapp) 1566f9ae7e4bSJohn Fastabend err = ops->ieee_delapp(netdev, app_data); 1567f9ae7e4bSJohn Fastabend else 1568f9ae7e4bSJohn Fastabend err = dcb_ieee_delapp(netdev, app_data); 1569f9ae7e4bSJohn Fastabend if (err) 1570f9ae7e4bSJohn Fastabend goto err; 1571f9ae7e4bSJohn Fastabend } 1572f9ae7e4bSJohn Fastabend } 1573f9ae7e4bSJohn Fastabend 1574f9ae7e4bSJohn Fastabend err: 15757be99413SThomas Graf err = nla_put_u8(skb, DCB_ATTR_IEEE, err); 15765b7f7626SShmulik Ravid dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_DEL, seq, 0); 1577f9ae7e4bSJohn Fastabend return err; 1578f9ae7e4bSJohn Fastabend } 1579f9ae7e4bSJohn Fastabend 1580f9ae7e4bSJohn Fastabend 15816241b625SShmulik Ravid /* DCBX configuration */ 15827be99413SThomas Graf static int dcbnl_getdcbx(struct net_device *netdev, struct nlmsghdr *nlh, 15837be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 15846241b625SShmulik Ravid { 15856241b625SShmulik Ravid if (!netdev->dcbnl_ops->getdcbx) 15867f891cf1SShmulik Ravid return -EOPNOTSUPP; 15876241b625SShmulik Ravid 15887be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_DCBX, 15897be99413SThomas Graf netdev->dcbnl_ops->getdcbx(netdev)); 15906241b625SShmulik Ravid } 15916241b625SShmulik Ravid 15927be99413SThomas Graf static int dcbnl_setdcbx(struct net_device *netdev, struct nlmsghdr *nlh, 15937be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 15946241b625SShmulik Ravid { 15956241b625SShmulik Ravid u8 value; 15966241b625SShmulik Ravid 15977f891cf1SShmulik Ravid if (!netdev->dcbnl_ops->setdcbx) 15987f891cf1SShmulik Ravid return -EOPNOTSUPP; 15997f891cf1SShmulik Ravid 16007f891cf1SShmulik Ravid if (!tb[DCB_ATTR_DCBX]) 16017f891cf1SShmulik Ravid return -EINVAL; 16026241b625SShmulik Ravid 16036241b625SShmulik Ravid value = nla_get_u8(tb[DCB_ATTR_DCBX]); 16046241b625SShmulik Ravid 16057be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_DCBX, 16067be99413SThomas Graf netdev->dcbnl_ops->setdcbx(netdev, value)); 16076241b625SShmulik Ravid } 16086241b625SShmulik Ravid 16097be99413SThomas Graf static int dcbnl_getfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh, 16107be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 1611ea45fe4eSShmulik Ravid { 1612ea45fe4eSShmulik Ravid struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1], *nest; 1613ea45fe4eSShmulik Ravid u8 value; 16147f891cf1SShmulik Ravid int ret, i; 1615ea45fe4eSShmulik Ravid int getall = 0; 1616ea45fe4eSShmulik Ravid 16177f891cf1SShmulik Ravid if (!netdev->dcbnl_ops->getfeatcfg) 16187f891cf1SShmulik Ravid return -EOPNOTSUPP; 16197f891cf1SShmulik Ravid 16207f891cf1SShmulik Ravid if (!tb[DCB_ATTR_FEATCFG]) 16217f891cf1SShmulik Ravid return -EINVAL; 1622ea45fe4eSShmulik Ravid 16238cb08174SJohannes Berg ret = nla_parse_nested_deprecated(data, DCB_FEATCFG_ATTR_MAX, 16248cb08174SJohannes Berg tb[DCB_ATTR_FEATCFG], 16258cb08174SJohannes Berg dcbnl_featcfg_nest, NULL); 16267f891cf1SShmulik Ravid if (ret) 16277be99413SThomas Graf return ret; 1628ea45fe4eSShmulik Ravid 1629ae0be8deSMichal Kubecek nest = nla_nest_start_noflag(skb, DCB_ATTR_FEATCFG); 16307be99413SThomas Graf if (!nest) 16317be99413SThomas Graf return -EMSGSIZE; 1632ea45fe4eSShmulik Ravid 1633ea45fe4eSShmulik Ravid if (data[DCB_FEATCFG_ATTR_ALL]) 1634ea45fe4eSShmulik Ravid getall = 1; 1635ea45fe4eSShmulik Ravid 1636ea45fe4eSShmulik Ravid for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) { 1637ea45fe4eSShmulik Ravid if (!getall && !data[i]) 1638ea45fe4eSShmulik Ravid continue; 1639ea45fe4eSShmulik Ravid 1640ea45fe4eSShmulik Ravid ret = netdev->dcbnl_ops->getfeatcfg(netdev, i, &value); 16417f891cf1SShmulik Ravid if (!ret) 16427be99413SThomas Graf ret = nla_put_u8(skb, i, value); 1643ea45fe4eSShmulik Ravid 1644ea45fe4eSShmulik Ravid if (ret) { 16457be99413SThomas Graf nla_nest_cancel(skb, nest); 16467f891cf1SShmulik Ravid goto nla_put_failure; 1647ea45fe4eSShmulik Ravid } 1648ea45fe4eSShmulik Ravid } 16497be99413SThomas Graf nla_nest_end(skb, nest); 1650ea45fe4eSShmulik Ravid 16517f891cf1SShmulik Ravid nla_put_failure: 1652ea45fe4eSShmulik Ravid return ret; 1653ea45fe4eSShmulik Ravid } 1654ea45fe4eSShmulik Ravid 16557be99413SThomas Graf static int dcbnl_setfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh, 16567be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 1657ea45fe4eSShmulik Ravid { 1658ea45fe4eSShmulik Ravid struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1]; 16597f891cf1SShmulik Ravid int ret, i; 1660ea45fe4eSShmulik Ravid u8 value; 1661ea45fe4eSShmulik Ravid 16627f891cf1SShmulik Ravid if (!netdev->dcbnl_ops->setfeatcfg) 16637f891cf1SShmulik Ravid return -ENOTSUPP; 16647f891cf1SShmulik Ravid 16657f891cf1SShmulik Ravid if (!tb[DCB_ATTR_FEATCFG]) 16667f891cf1SShmulik Ravid return -EINVAL; 1667ea45fe4eSShmulik Ravid 16688cb08174SJohannes Berg ret = nla_parse_nested_deprecated(data, DCB_FEATCFG_ATTR_MAX, 16698cb08174SJohannes Berg tb[DCB_ATTR_FEATCFG], 16708cb08174SJohannes Berg dcbnl_featcfg_nest, NULL); 1671ea45fe4eSShmulik Ravid 16727f891cf1SShmulik Ravid if (ret) 1673ea45fe4eSShmulik Ravid goto err; 1674ea45fe4eSShmulik Ravid 1675ea45fe4eSShmulik Ravid for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) { 1676ea45fe4eSShmulik Ravid if (data[i] == NULL) 1677ea45fe4eSShmulik Ravid continue; 1678ea45fe4eSShmulik Ravid 1679ea45fe4eSShmulik Ravid value = nla_get_u8(data[i]); 1680ea45fe4eSShmulik Ravid 1681ea45fe4eSShmulik Ravid ret = netdev->dcbnl_ops->setfeatcfg(netdev, i, value); 1682ea45fe4eSShmulik Ravid 1683ea45fe4eSShmulik Ravid if (ret) 16847f891cf1SShmulik Ravid goto err; 1685ea45fe4eSShmulik Ravid } 1686ea45fe4eSShmulik Ravid err: 16877be99413SThomas Graf ret = nla_put_u8(skb, DCB_ATTR_FEATCFG, ret); 16887f891cf1SShmulik Ravid 1689ea45fe4eSShmulik Ravid return ret; 1690ea45fe4eSShmulik Ravid } 1691ea45fe4eSShmulik Ravid 1692dc6ed1dfSShmulik Ravid /* Handle CEE DCBX GET commands. */ 16937be99413SThomas Graf static int dcbnl_cee_get(struct net_device *netdev, struct nlmsghdr *nlh, 16947be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 1695dc6ed1dfSShmulik Ravid { 1696dc6ed1dfSShmulik Ravid const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; 1697dc6ed1dfSShmulik Ravid 1698dc6ed1dfSShmulik Ravid if (!ops) 1699dc6ed1dfSShmulik Ravid return -EOPNOTSUPP; 1700dc6ed1dfSShmulik Ravid 17017be99413SThomas Graf return dcbnl_cee_fill(skb, netdev); 1702dc6ed1dfSShmulik Ravid } 1703dc6ed1dfSShmulik Ravid 170433a03aadSThomas Graf struct reply_func { 170533a03aadSThomas Graf /* reply netlink message type */ 170633a03aadSThomas Graf int type; 170733a03aadSThomas Graf 170833a03aadSThomas Graf /* function to fill message contents */ 170933a03aadSThomas Graf int (*cb)(struct net_device *, struct nlmsghdr *, u32, 171033a03aadSThomas Graf struct nlattr **, struct sk_buff *); 171133a03aadSThomas Graf }; 171233a03aadSThomas Graf 171333a03aadSThomas Graf static const struct reply_func reply_funcs[DCB_CMD_MAX+1] = { 17147be99413SThomas Graf [DCB_CMD_GSTATE] = { RTM_GETDCB, dcbnl_getstate }, 17157be99413SThomas Graf [DCB_CMD_SSTATE] = { RTM_SETDCB, dcbnl_setstate }, 17167be99413SThomas Graf [DCB_CMD_PFC_GCFG] = { RTM_GETDCB, dcbnl_getpfccfg }, 17177be99413SThomas Graf [DCB_CMD_PFC_SCFG] = { RTM_SETDCB, dcbnl_setpfccfg }, 17187be99413SThomas Graf [DCB_CMD_GPERM_HWADDR] = { RTM_GETDCB, dcbnl_getperm_hwaddr }, 17197be99413SThomas Graf [DCB_CMD_GCAP] = { RTM_GETDCB, dcbnl_getcap }, 17207be99413SThomas Graf [DCB_CMD_GNUMTCS] = { RTM_GETDCB, dcbnl_getnumtcs }, 17217be99413SThomas Graf [DCB_CMD_SNUMTCS] = { RTM_SETDCB, dcbnl_setnumtcs }, 17227be99413SThomas Graf [DCB_CMD_PFC_GSTATE] = { RTM_GETDCB, dcbnl_getpfcstate }, 17237be99413SThomas Graf [DCB_CMD_PFC_SSTATE] = { RTM_SETDCB, dcbnl_setpfcstate }, 17247be99413SThomas Graf [DCB_CMD_GAPP] = { RTM_GETDCB, dcbnl_getapp }, 17257be99413SThomas Graf [DCB_CMD_SAPP] = { RTM_SETDCB, dcbnl_setapp }, 17267be99413SThomas Graf [DCB_CMD_PGTX_GCFG] = { RTM_GETDCB, dcbnl_pgtx_getcfg }, 17277be99413SThomas Graf [DCB_CMD_PGTX_SCFG] = { RTM_SETDCB, dcbnl_pgtx_setcfg }, 17287be99413SThomas Graf [DCB_CMD_PGRX_GCFG] = { RTM_GETDCB, dcbnl_pgrx_getcfg }, 17297be99413SThomas Graf [DCB_CMD_PGRX_SCFG] = { RTM_SETDCB, dcbnl_pgrx_setcfg }, 17307be99413SThomas Graf [DCB_CMD_SET_ALL] = { RTM_SETDCB, dcbnl_setall }, 17317be99413SThomas Graf [DCB_CMD_BCN_GCFG] = { RTM_GETDCB, dcbnl_bcn_getcfg }, 17327be99413SThomas Graf [DCB_CMD_BCN_SCFG] = { RTM_SETDCB, dcbnl_bcn_setcfg }, 17337be99413SThomas Graf [DCB_CMD_IEEE_GET] = { RTM_GETDCB, dcbnl_ieee_get }, 17347be99413SThomas Graf [DCB_CMD_IEEE_SET] = { RTM_SETDCB, dcbnl_ieee_set }, 17357be99413SThomas Graf [DCB_CMD_IEEE_DEL] = { RTM_SETDCB, dcbnl_ieee_del }, 17367be99413SThomas Graf [DCB_CMD_GDCBX] = { RTM_GETDCB, dcbnl_getdcbx }, 17377be99413SThomas Graf [DCB_CMD_SDCBX] = { RTM_SETDCB, dcbnl_setdcbx }, 17387be99413SThomas Graf [DCB_CMD_GFEATCFG] = { RTM_GETDCB, dcbnl_getfeatcfg }, 17397be99413SThomas Graf [DCB_CMD_SFEATCFG] = { RTM_SETDCB, dcbnl_setfeatcfg }, 17407be99413SThomas Graf [DCB_CMD_CEE_GET] = { RTM_GETDCB, dcbnl_cee_get }, 174133a03aadSThomas Graf }; 174233a03aadSThomas Graf 1743c21ef3e3SDavid Ahern static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, 1744c21ef3e3SDavid Ahern struct netlink_ext_ack *extack) 17452f90b865SAlexander Duyck { 17462f90b865SAlexander Duyck struct net *net = sock_net(skb->sk); 17472f90b865SAlexander Duyck struct net_device *netdev; 17487a282bc3SThomas Graf struct dcbmsg *dcb = nlmsg_data(nlh); 17492f90b865SAlexander Duyck struct nlattr *tb[DCB_ATTR_MAX + 1]; 175015e47304SEric W. Biederman u32 portid = skb ? NETLINK_CB(skb).portid : 0; 17512f90b865SAlexander Duyck int ret = -EINVAL; 175233a03aadSThomas Graf struct sk_buff *reply_skb; 175339912f9cSThomas Graf struct nlmsghdr *reply_nlh = NULL; 175433a03aadSThomas Graf const struct reply_func *fn; 17552f90b865SAlexander Duyck 175690f62cf3SEric W. Biederman if ((nlh->nlmsg_type == RTM_SETDCB) && !netlink_capable(skb, CAP_NET_ADMIN)) 1757dfc47ef8SEric W. Biederman return -EPERM; 1758dfc47ef8SEric W. Biederman 17598cb08174SJohannes Berg ret = nlmsg_parse_deprecated(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX, 1760c21ef3e3SDavid Ahern dcbnl_rtnl_policy, extack); 17612f90b865SAlexander Duyck if (ret < 0) 17622f90b865SAlexander Duyck return ret; 17632f90b865SAlexander Duyck 176433a03aadSThomas Graf if (dcb->cmd > DCB_CMD_MAX) 176533a03aadSThomas Graf return -EINVAL; 176633a03aadSThomas Graf 176733a03aadSThomas Graf /* check if a reply function has been defined for the command */ 176833a03aadSThomas Graf fn = &reply_funcs[dcb->cmd]; 176933a03aadSThomas Graf if (!fn->cb) 177033a03aadSThomas Graf return -EOPNOTSUPP; 177133a03aadSThomas Graf 17722f90b865SAlexander Duyck if (!tb[DCB_ATTR_IFNAME]) 17732f90b865SAlexander Duyck return -EINVAL; 17742f90b865SAlexander Duyck 1775d9ac62beSYing Xue netdev = __dev_get_by_name(net, nla_data(tb[DCB_ATTR_IFNAME])); 17762f90b865SAlexander Duyck if (!netdev) 17773d1f4869SThomas Graf return -ENODEV; 17782f90b865SAlexander Duyck 1779d9ac62beSYing Xue if (!netdev->dcbnl_ops) 1780d9ac62beSYing Xue return -EOPNOTSUPP; 17812f90b865SAlexander Duyck 178215e47304SEric W. Biederman reply_skb = dcbnl_newmsg(fn->type, dcb->cmd, portid, nlh->nlmsg_seq, 178333a03aadSThomas Graf nlh->nlmsg_flags, &reply_nlh); 1784d9ac62beSYing Xue if (!reply_skb) 1785d9ac62beSYing Xue return -ENOBUFS; 178633a03aadSThomas Graf 178733a03aadSThomas Graf ret = fn->cb(netdev, nlh, nlh->nlmsg_seq, tb, reply_skb); 178833a03aadSThomas Graf if (ret < 0) { 178933a03aadSThomas Graf nlmsg_free(reply_skb); 179033a03aadSThomas Graf goto out; 179133a03aadSThomas Graf } 179233a03aadSThomas Graf 179333a03aadSThomas Graf nlmsg_end(reply_skb, reply_nlh); 179433a03aadSThomas Graf 17957c77ab24SJohn Fastabend ret = rtnl_unicast(reply_skb, net, portid); 17962f90b865SAlexander Duyck out: 17972f90b865SAlexander Duyck return ret; 17982f90b865SAlexander Duyck } 17992f90b865SAlexander Duyck 1800716b31abSThomas Graf static struct dcb_app_type *dcb_app_lookup(const struct dcb_app *app, 1801716b31abSThomas Graf int ifindex, int prio) 1802716b31abSThomas Graf { 1803716b31abSThomas Graf struct dcb_app_type *itr; 1804716b31abSThomas Graf 1805716b31abSThomas Graf list_for_each_entry(itr, &dcb_app_list, list) { 1806716b31abSThomas Graf if (itr->app.selector == app->selector && 1807716b31abSThomas Graf itr->app.protocol == app->protocol && 1808716b31abSThomas Graf itr->ifindex == ifindex && 180908193d1aSPetr Machata ((prio == -1) || itr->app.priority == prio)) 1810716b31abSThomas Graf return itr; 1811716b31abSThomas Graf } 1812716b31abSThomas Graf 1813716b31abSThomas Graf return NULL; 1814716b31abSThomas Graf } 1815716b31abSThomas Graf 18164e4f2f69SThomas Graf static int dcb_app_add(const struct dcb_app *app, int ifindex) 18174e4f2f69SThomas Graf { 18184e4f2f69SThomas Graf struct dcb_app_type *entry; 18194e4f2f69SThomas Graf 18204e4f2f69SThomas Graf entry = kmalloc(sizeof(*entry), GFP_ATOMIC); 18214e4f2f69SThomas Graf if (!entry) 18224e4f2f69SThomas Graf return -ENOMEM; 18234e4f2f69SThomas Graf 18244e4f2f69SThomas Graf memcpy(&entry->app, app, sizeof(*app)); 18254e4f2f69SThomas Graf entry->ifindex = ifindex; 18264e4f2f69SThomas Graf list_add(&entry->list, &dcb_app_list); 18274e4f2f69SThomas Graf 18284e4f2f69SThomas Graf return 0; 18294e4f2f69SThomas Graf } 18304e4f2f69SThomas Graf 18319ab933abSJohn Fastabend /** 18329ab933abSJohn Fastabend * dcb_getapp - retrieve the DCBX application user priority 18339ab933abSJohn Fastabend * 18349ab933abSJohn Fastabend * On success returns a non-zero 802.1p user priority bitmap 18359ab933abSJohn Fastabend * otherwise returns 0 as the invalid user priority bitmap to 18369ab933abSJohn Fastabend * indicate an error. 18379ab933abSJohn Fastabend */ 18389ab933abSJohn Fastabend u8 dcb_getapp(struct net_device *dev, struct dcb_app *app) 18399ab933abSJohn Fastabend { 18409ab933abSJohn Fastabend struct dcb_app_type *itr; 18419ab933abSJohn Fastabend u8 prio = 0; 18429ab933abSJohn Fastabend 184352cff74eSAnish Bhatt spin_lock_bh(&dcb_lock); 184408193d1aSPetr Machata itr = dcb_app_lookup(app, dev->ifindex, -1); 184508193d1aSPetr Machata if (itr) 18469ab933abSJohn Fastabend prio = itr->app.priority; 184752cff74eSAnish Bhatt spin_unlock_bh(&dcb_lock); 18489ab933abSJohn Fastabend 18499ab933abSJohn Fastabend return prio; 18509ab933abSJohn Fastabend } 18519ab933abSJohn Fastabend EXPORT_SYMBOL(dcb_getapp); 18529ab933abSJohn Fastabend 18539ab933abSJohn Fastabend /** 1854b6db2174SJohn Fastabend * dcb_setapp - add CEE dcb application data to app list 18559ab933abSJohn Fastabend * 1856b6db2174SJohn Fastabend * Priority 0 is an invalid priority in CEE spec. This routine 1857b6db2174SJohn Fastabend * removes applications from the app list if the priority is 185816eecd9bSAnish Bhatt * set to zero. Priority is expected to be 8-bit 802.1p user priority bitmap 18599ab933abSJohn Fastabend */ 1860ab6baf98SJohn Fastabend int dcb_setapp(struct net_device *dev, struct dcb_app *new) 18619ab933abSJohn Fastabend { 18629ab933abSJohn Fastabend struct dcb_app_type *itr; 18637ec79270SJohn Fastabend struct dcb_app_type event; 18644e4f2f69SThomas Graf int err = 0; 18657ec79270SJohn Fastabend 1866e290ed81SMark Rustad event.ifindex = dev->ifindex; 18677ec79270SJohn Fastabend memcpy(&event.app, new, sizeof(event.app)); 18686bd0e1cbSJohn Fastabend if (dev->dcbnl_ops->getdcbx) 18696bd0e1cbSJohn Fastabend event.dcbx = dev->dcbnl_ops->getdcbx(dev); 18709ab933abSJohn Fastabend 187152cff74eSAnish Bhatt spin_lock_bh(&dcb_lock); 18729ab933abSJohn Fastabend /* Search for existing match and replace */ 187308193d1aSPetr Machata itr = dcb_app_lookup(new, dev->ifindex, -1); 187408193d1aSPetr Machata if (itr) { 18759ab933abSJohn Fastabend if (new->priority) 18769ab933abSJohn Fastabend itr->app.priority = new->priority; 18779ab933abSJohn Fastabend else { 18789ab933abSJohn Fastabend list_del(&itr->list); 18799ab933abSJohn Fastabend kfree(itr); 18809ab933abSJohn Fastabend } 18819ab933abSJohn Fastabend goto out; 18829ab933abSJohn Fastabend } 18839ab933abSJohn Fastabend /* App type does not exist add new application type */ 18844e4f2f69SThomas Graf if (new->priority) 18854e4f2f69SThomas Graf err = dcb_app_add(new, dev->ifindex); 18869ab933abSJohn Fastabend out: 188752cff74eSAnish Bhatt spin_unlock_bh(&dcb_lock); 18884e4f2f69SThomas Graf if (!err) 18897ec79270SJohn Fastabend call_dcbevent_notifiers(DCB_APP_EVENT, &event); 18904e4f2f69SThomas Graf return err; 18919ab933abSJohn Fastabend } 18929ab933abSJohn Fastabend EXPORT_SYMBOL(dcb_setapp); 18939ab933abSJohn Fastabend 1894b6db2174SJohn Fastabend /** 1895a364c8cfSJohn Fastabend * dcb_ieee_getapp_mask - retrieve the IEEE DCB application priority 1896a364c8cfSJohn Fastabend * 1897a364c8cfSJohn Fastabend * Helper routine which on success returns a non-zero 802.1Qaz user 1898a364c8cfSJohn Fastabend * priority bitmap otherwise returns 0 to indicate the dcb_app was 1899a364c8cfSJohn Fastabend * not found in APP list. 1900a364c8cfSJohn Fastabend */ 1901a364c8cfSJohn Fastabend u8 dcb_ieee_getapp_mask(struct net_device *dev, struct dcb_app *app) 1902a364c8cfSJohn Fastabend { 1903a364c8cfSJohn Fastabend struct dcb_app_type *itr; 1904a364c8cfSJohn Fastabend u8 prio = 0; 1905a364c8cfSJohn Fastabend 190652cff74eSAnish Bhatt spin_lock_bh(&dcb_lock); 190708193d1aSPetr Machata itr = dcb_app_lookup(app, dev->ifindex, -1); 190808193d1aSPetr Machata if (itr) 1909a364c8cfSJohn Fastabend prio |= 1 << itr->app.priority; 191052cff74eSAnish Bhatt spin_unlock_bh(&dcb_lock); 1911a364c8cfSJohn Fastabend 1912a364c8cfSJohn Fastabend return prio; 1913a364c8cfSJohn Fastabend } 1914a364c8cfSJohn Fastabend EXPORT_SYMBOL(dcb_ieee_getapp_mask); 1915a364c8cfSJohn Fastabend 1916a364c8cfSJohn Fastabend /** 1917b6db2174SJohn Fastabend * dcb_ieee_setapp - add IEEE dcb application data to app list 1918b6db2174SJohn Fastabend * 1919b6db2174SJohn Fastabend * This adds Application data to the list. Multiple application 1920b6db2174SJohn Fastabend * entries may exists for the same selector and protocol as long 192116eecd9bSAnish Bhatt * as the priorities are different. Priority is expected to be a 192216eecd9bSAnish Bhatt * 3-bit unsigned integer 1923b6db2174SJohn Fastabend */ 1924b6db2174SJohn Fastabend int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new) 1925b6db2174SJohn Fastabend { 1926b6db2174SJohn Fastabend struct dcb_app_type event; 1927b6db2174SJohn Fastabend int err = 0; 1928b6db2174SJohn Fastabend 1929e290ed81SMark Rustad event.ifindex = dev->ifindex; 1930b6db2174SJohn Fastabend memcpy(&event.app, new, sizeof(event.app)); 19316bd0e1cbSJohn Fastabend if (dev->dcbnl_ops->getdcbx) 19326bd0e1cbSJohn Fastabend event.dcbx = dev->dcbnl_ops->getdcbx(dev); 1933b6db2174SJohn Fastabend 193452cff74eSAnish Bhatt spin_lock_bh(&dcb_lock); 1935b6db2174SJohn Fastabend /* Search for existing match and abort if found */ 1936716b31abSThomas Graf if (dcb_app_lookup(new, dev->ifindex, new->priority)) { 1937b6db2174SJohn Fastabend err = -EEXIST; 1938b6db2174SJohn Fastabend goto out; 1939b6db2174SJohn Fastabend } 1940b6db2174SJohn Fastabend 19414e4f2f69SThomas Graf err = dcb_app_add(new, dev->ifindex); 1942b6db2174SJohn Fastabend out: 194352cff74eSAnish Bhatt spin_unlock_bh(&dcb_lock); 1944b6db2174SJohn Fastabend if (!err) 1945b6db2174SJohn Fastabend call_dcbevent_notifiers(DCB_APP_EVENT, &event); 1946b6db2174SJohn Fastabend return err; 1947b6db2174SJohn Fastabend } 1948b6db2174SJohn Fastabend EXPORT_SYMBOL(dcb_ieee_setapp); 1949b6db2174SJohn Fastabend 1950f9ae7e4bSJohn Fastabend /** 1951f9ae7e4bSJohn Fastabend * dcb_ieee_delapp - delete IEEE dcb application data from list 1952f9ae7e4bSJohn Fastabend * 1953f9ae7e4bSJohn Fastabend * This removes a matching APP data from the APP list 1954f9ae7e4bSJohn Fastabend */ 1955f9ae7e4bSJohn Fastabend int dcb_ieee_delapp(struct net_device *dev, struct dcb_app *del) 1956f9ae7e4bSJohn Fastabend { 1957f9ae7e4bSJohn Fastabend struct dcb_app_type *itr; 1958f9ae7e4bSJohn Fastabend struct dcb_app_type event; 1959f9ae7e4bSJohn Fastabend int err = -ENOENT; 1960f9ae7e4bSJohn Fastabend 1961e290ed81SMark Rustad event.ifindex = dev->ifindex; 1962f9ae7e4bSJohn Fastabend memcpy(&event.app, del, sizeof(event.app)); 19636bd0e1cbSJohn Fastabend if (dev->dcbnl_ops->getdcbx) 19646bd0e1cbSJohn Fastabend event.dcbx = dev->dcbnl_ops->getdcbx(dev); 1965f9ae7e4bSJohn Fastabend 196652cff74eSAnish Bhatt spin_lock_bh(&dcb_lock); 1967f9ae7e4bSJohn Fastabend /* Search for existing match and remove it. */ 1968716b31abSThomas Graf if ((itr = dcb_app_lookup(del, dev->ifindex, del->priority))) { 1969f9ae7e4bSJohn Fastabend list_del(&itr->list); 1970f9ae7e4bSJohn Fastabend kfree(itr); 1971f9ae7e4bSJohn Fastabend err = 0; 1972f9ae7e4bSJohn Fastabend } 1973f9ae7e4bSJohn Fastabend 197452cff74eSAnish Bhatt spin_unlock_bh(&dcb_lock); 1975f9ae7e4bSJohn Fastabend if (!err) 1976f9ae7e4bSJohn Fastabend call_dcbevent_notifiers(DCB_APP_EVENT, &event); 1977f9ae7e4bSJohn Fastabend return err; 1978f9ae7e4bSJohn Fastabend } 1979f9ae7e4bSJohn Fastabend EXPORT_SYMBOL(dcb_ieee_delapp); 1980f9ae7e4bSJohn Fastabend 1981b67c540bSPetr Machata /** 1982b67c540bSPetr Machata * dcb_ieee_getapp_prio_dscp_mask_map - For a given device, find mapping from 1983b67c540bSPetr Machata * priorities to the DSCP values assigned to that priority. Initialize p_map 1984b67c540bSPetr Machata * such that each map element holds a bit mask of DSCP values configured for 1985b67c540bSPetr Machata * that priority by APP entries. 1986b67c540bSPetr Machata */ 1987b67c540bSPetr Machata void dcb_ieee_getapp_prio_dscp_mask_map(const struct net_device *dev, 1988b67c540bSPetr Machata struct dcb_ieee_app_prio_map *p_map) 1989b67c540bSPetr Machata { 1990b67c540bSPetr Machata int ifindex = dev->ifindex; 1991b67c540bSPetr Machata struct dcb_app_type *itr; 1992b67c540bSPetr Machata u8 prio; 1993b67c540bSPetr Machata 1994b67c540bSPetr Machata memset(p_map->map, 0, sizeof(p_map->map)); 1995b67c540bSPetr Machata 1996b67c540bSPetr Machata spin_lock_bh(&dcb_lock); 1997b67c540bSPetr Machata list_for_each_entry(itr, &dcb_app_list, list) { 1998b67c540bSPetr Machata if (itr->ifindex == ifindex && 1999b67c540bSPetr Machata itr->app.selector == IEEE_8021QAZ_APP_SEL_DSCP && 2000b67c540bSPetr Machata itr->app.protocol < 64 && 2001b67c540bSPetr Machata itr->app.priority < IEEE_8021QAZ_MAX_TCS) { 2002b67c540bSPetr Machata prio = itr->app.priority; 2003b67c540bSPetr Machata p_map->map[prio] |= 1ULL << itr->app.protocol; 2004b67c540bSPetr Machata } 2005b67c540bSPetr Machata } 2006b67c540bSPetr Machata spin_unlock_bh(&dcb_lock); 2007b67c540bSPetr Machata } 2008b67c540bSPetr Machata EXPORT_SYMBOL(dcb_ieee_getapp_prio_dscp_mask_map); 2009b67c540bSPetr Machata 2010b67c540bSPetr Machata /** 2011b67c540bSPetr Machata * dcb_ieee_getapp_dscp_prio_mask_map - For a given device, find mapping from 2012b67c540bSPetr Machata * DSCP values to the priorities assigned to that DSCP value. Initialize p_map 2013b67c540bSPetr Machata * such that each map element holds a bit mask of priorities configured for a 2014b67c540bSPetr Machata * given DSCP value by APP entries. 2015b67c540bSPetr Machata */ 2016b67c540bSPetr Machata void 2017b67c540bSPetr Machata dcb_ieee_getapp_dscp_prio_mask_map(const struct net_device *dev, 2018b67c540bSPetr Machata struct dcb_ieee_app_dscp_map *p_map) 2019b67c540bSPetr Machata { 2020b67c540bSPetr Machata int ifindex = dev->ifindex; 2021b67c540bSPetr Machata struct dcb_app_type *itr; 2022b67c540bSPetr Machata 2023b67c540bSPetr Machata memset(p_map->map, 0, sizeof(p_map->map)); 2024b67c540bSPetr Machata 2025b67c540bSPetr Machata spin_lock_bh(&dcb_lock); 2026b67c540bSPetr Machata list_for_each_entry(itr, &dcb_app_list, list) { 2027b67c540bSPetr Machata if (itr->ifindex == ifindex && 2028b67c540bSPetr Machata itr->app.selector == IEEE_8021QAZ_APP_SEL_DSCP && 2029b67c540bSPetr Machata itr->app.protocol < 64 && 2030b67c540bSPetr Machata itr->app.priority < IEEE_8021QAZ_MAX_TCS) 2031b67c540bSPetr Machata p_map->map[itr->app.protocol] |= 1 << itr->app.priority; 2032b67c540bSPetr Machata } 2033b67c540bSPetr Machata spin_unlock_bh(&dcb_lock); 2034b67c540bSPetr Machata } 2035b67c540bSPetr Machata EXPORT_SYMBOL(dcb_ieee_getapp_dscp_prio_mask_map); 2036b67c540bSPetr Machata 2037b67c540bSPetr Machata /** 2038b67c540bSPetr Machata * Per 802.1Q-2014, the selector value of 1 is used for matching on Ethernet 2039b67c540bSPetr Machata * type, with valid PID values >= 1536. A special meaning is then assigned to 2040b67c540bSPetr Machata * protocol value of 0: "default priority. For use when priority is not 2041b67c540bSPetr Machata * otherwise specified". 2042b67c540bSPetr Machata * 2043b67c540bSPetr Machata * dcb_ieee_getapp_default_prio_mask - For a given device, find all APP entries 2044b67c540bSPetr Machata * of the form {$PRIO, ETHERTYPE, 0} and construct a bit mask of all default 2045b67c540bSPetr Machata * priorities set by these entries. 2046b67c540bSPetr Machata */ 2047b67c540bSPetr Machata u8 dcb_ieee_getapp_default_prio_mask(const struct net_device *dev) 2048b67c540bSPetr Machata { 2049b67c540bSPetr Machata int ifindex = dev->ifindex; 2050b67c540bSPetr Machata struct dcb_app_type *itr; 2051b67c540bSPetr Machata u8 mask = 0; 2052b67c540bSPetr Machata 2053b67c540bSPetr Machata spin_lock_bh(&dcb_lock); 2054b67c540bSPetr Machata list_for_each_entry(itr, &dcb_app_list, list) { 2055b67c540bSPetr Machata if (itr->ifindex == ifindex && 2056b67c540bSPetr Machata itr->app.selector == IEEE_8021QAZ_APP_SEL_ETHERTYPE && 2057b67c540bSPetr Machata itr->app.protocol == 0 && 2058b67c540bSPetr Machata itr->app.priority < IEEE_8021QAZ_MAX_TCS) 2059b67c540bSPetr Machata mask |= 1 << itr->app.priority; 2060b67c540bSPetr Machata } 2061b67c540bSPetr Machata spin_unlock_bh(&dcb_lock); 2062b67c540bSPetr Machata 2063b67c540bSPetr Machata return mask; 2064b67c540bSPetr Machata } 2065b67c540bSPetr Machata EXPORT_SYMBOL(dcb_ieee_getapp_default_prio_mask); 2066b67c540bSPetr Machata 20672f90b865SAlexander Duyck static int __init dcbnl_init(void) 20682f90b865SAlexander Duyck { 20699ab933abSJohn Fastabend INIT_LIST_HEAD(&dcb_app_list); 20709ab933abSJohn Fastabend 2071b97bac64SFlorian Westphal rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL, 0); 2072b97bac64SFlorian Westphal rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL, 0); 20732f90b865SAlexander Duyck 20742f90b865SAlexander Duyck return 0; 20752f90b865SAlexander Duyck } 207636b9ad80SPaul Gortmaker device_initcall(dcbnl_init); 2077