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 142f90b865SAlexander Duyck * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 152f90b865SAlexander Duyck * Place - Suite 330, Boston, MA 02111-1307 USA. 162f90b865SAlexander Duyck * 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> 283a9a231dSPaul Gortmaker #include <linux/module.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 MODULE_AUTHOR("Lucy Liu, <lucy.liu@intel.com>"); 537a6b6f51SJeff Kirsher MODULE_DESCRIPTION("Data Center Bridging netlink interface"); 542f90b865SAlexander Duyck MODULE_LICENSE("GPL"); 552f90b865SAlexander Duyck 562f90b865SAlexander Duyck /**************** DCB attribute policies *************************************/ 572f90b865SAlexander Duyck 582f90b865SAlexander Duyck /* DCB netlink attributes policy */ 59b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = { 60859ee3c4SAlexander Duyck [DCB_ATTR_IFNAME] = {.type = NLA_NUL_STRING, .len = IFNAMSIZ - 1}, 612f90b865SAlexander Duyck [DCB_ATTR_STATE] = {.type = NLA_U8}, 622f90b865SAlexander Duyck [DCB_ATTR_PFC_CFG] = {.type = NLA_NESTED}, 632f90b865SAlexander Duyck [DCB_ATTR_PG_CFG] = {.type = NLA_NESTED}, 642f90b865SAlexander Duyck [DCB_ATTR_SET_ALL] = {.type = NLA_U8}, 652f90b865SAlexander Duyck [DCB_ATTR_PERM_HWADDR] = {.type = NLA_FLAG}, 6646132188SAlexander Duyck [DCB_ATTR_CAP] = {.type = NLA_NESTED}, 670eb3aa9bSAlexander Duyck [DCB_ATTR_PFC_STATE] = {.type = NLA_U8}, 68859ee3c4SAlexander Duyck [DCB_ATTR_BCN] = {.type = NLA_NESTED}, 696fa382afSYi Zou [DCB_ATTR_APP] = {.type = NLA_NESTED}, 703e29027aSJohn Fastabend [DCB_ATTR_IEEE] = {.type = NLA_NESTED}, 716241b625SShmulik Ravid [DCB_ATTR_DCBX] = {.type = NLA_U8}, 72ea45fe4eSShmulik Ravid [DCB_ATTR_FEATCFG] = {.type = NLA_NESTED}, 732f90b865SAlexander Duyck }; 742f90b865SAlexander Duyck 752f90b865SAlexander Duyck /* DCB priority flow control to User Priority nested attributes */ 76b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = { 772f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8}, 782f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8}, 792f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8}, 802f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_3] = {.type = NLA_U8}, 812f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_4] = {.type = NLA_U8}, 822f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_5] = {.type = NLA_U8}, 832f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_6] = {.type = NLA_U8}, 842f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_7] = {.type = NLA_U8}, 852f90b865SAlexander Duyck [DCB_PFC_UP_ATTR_ALL] = {.type = NLA_FLAG}, 862f90b865SAlexander Duyck }; 872f90b865SAlexander Duyck 882f90b865SAlexander Duyck /* DCB priority grouping nested attributes */ 89b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = { 902f90b865SAlexander Duyck [DCB_PG_ATTR_TC_0] = {.type = NLA_NESTED}, 912f90b865SAlexander Duyck [DCB_PG_ATTR_TC_1] = {.type = NLA_NESTED}, 922f90b865SAlexander Duyck [DCB_PG_ATTR_TC_2] = {.type = NLA_NESTED}, 932f90b865SAlexander Duyck [DCB_PG_ATTR_TC_3] = {.type = NLA_NESTED}, 942f90b865SAlexander Duyck [DCB_PG_ATTR_TC_4] = {.type = NLA_NESTED}, 952f90b865SAlexander Duyck [DCB_PG_ATTR_TC_5] = {.type = NLA_NESTED}, 962f90b865SAlexander Duyck [DCB_PG_ATTR_TC_6] = {.type = NLA_NESTED}, 972f90b865SAlexander Duyck [DCB_PG_ATTR_TC_7] = {.type = NLA_NESTED}, 982f90b865SAlexander Duyck [DCB_PG_ATTR_TC_ALL] = {.type = NLA_NESTED}, 992f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_0] = {.type = NLA_U8}, 1002f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_1] = {.type = NLA_U8}, 1012f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_2] = {.type = NLA_U8}, 1022f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_3] = {.type = NLA_U8}, 1032f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_4] = {.type = NLA_U8}, 1042f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_5] = {.type = NLA_U8}, 1052f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_6] = {.type = NLA_U8}, 1062f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_7] = {.type = NLA_U8}, 1072f90b865SAlexander Duyck [DCB_PG_ATTR_BW_ID_ALL] = {.type = NLA_FLAG}, 1082f90b865SAlexander Duyck }; 1092f90b865SAlexander Duyck 1102f90b865SAlexander Duyck /* DCB traffic class nested attributes. */ 111b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = { 1122f90b865SAlexander Duyck [DCB_TC_ATTR_PARAM_PGID] = {.type = NLA_U8}, 1132f90b865SAlexander Duyck [DCB_TC_ATTR_PARAM_UP_MAPPING] = {.type = NLA_U8}, 1142f90b865SAlexander Duyck [DCB_TC_ATTR_PARAM_STRICT_PRIO] = {.type = NLA_U8}, 1152f90b865SAlexander Duyck [DCB_TC_ATTR_PARAM_BW_PCT] = {.type = NLA_U8}, 1162f90b865SAlexander Duyck [DCB_TC_ATTR_PARAM_ALL] = {.type = NLA_FLAG}, 1172f90b865SAlexander Duyck }; 1182f90b865SAlexander Duyck 11946132188SAlexander Duyck /* DCB capabilities nested attributes. */ 120b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = { 12146132188SAlexander Duyck [DCB_CAP_ATTR_ALL] = {.type = NLA_FLAG}, 12246132188SAlexander Duyck [DCB_CAP_ATTR_PG] = {.type = NLA_U8}, 12346132188SAlexander Duyck [DCB_CAP_ATTR_PFC] = {.type = NLA_U8}, 12446132188SAlexander Duyck [DCB_CAP_ATTR_UP2TC] = {.type = NLA_U8}, 12546132188SAlexander Duyck [DCB_CAP_ATTR_PG_TCS] = {.type = NLA_U8}, 12646132188SAlexander Duyck [DCB_CAP_ATTR_PFC_TCS] = {.type = NLA_U8}, 12746132188SAlexander Duyck [DCB_CAP_ATTR_GSP] = {.type = NLA_U8}, 12846132188SAlexander Duyck [DCB_CAP_ATTR_BCN] = {.type = NLA_U8}, 1296241b625SShmulik Ravid [DCB_CAP_ATTR_DCBX] = {.type = NLA_U8}, 13046132188SAlexander Duyck }; 1312f90b865SAlexander Duyck 13233dbabc4SAlexander Duyck /* DCB capabilities nested attributes. */ 133b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = { 13433dbabc4SAlexander Duyck [DCB_NUMTCS_ATTR_ALL] = {.type = NLA_FLAG}, 13533dbabc4SAlexander Duyck [DCB_NUMTCS_ATTR_PG] = {.type = NLA_U8}, 13633dbabc4SAlexander Duyck [DCB_NUMTCS_ATTR_PFC] = {.type = NLA_U8}, 13733dbabc4SAlexander Duyck }; 13833dbabc4SAlexander Duyck 139859ee3c4SAlexander Duyck /* DCB BCN nested attributes. */ 140b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = { 141859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_0] = {.type = NLA_U8}, 142859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_1] = {.type = NLA_U8}, 143859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_2] = {.type = NLA_U8}, 144859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_3] = {.type = NLA_U8}, 145859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_4] = {.type = NLA_U8}, 146859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_5] = {.type = NLA_U8}, 147859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_6] = {.type = NLA_U8}, 148859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_7] = {.type = NLA_U8}, 149859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RP_ALL] = {.type = NLA_FLAG}, 150f4314e81SDon Skidmore [DCB_BCN_ATTR_BCNA_0] = {.type = NLA_U32}, 151f4314e81SDon Skidmore [DCB_BCN_ATTR_BCNA_1] = {.type = NLA_U32}, 152859ee3c4SAlexander Duyck [DCB_BCN_ATTR_ALPHA] = {.type = NLA_U32}, 153859ee3c4SAlexander Duyck [DCB_BCN_ATTR_BETA] = {.type = NLA_U32}, 154859ee3c4SAlexander Duyck [DCB_BCN_ATTR_GD] = {.type = NLA_U32}, 155859ee3c4SAlexander Duyck [DCB_BCN_ATTR_GI] = {.type = NLA_U32}, 156859ee3c4SAlexander Duyck [DCB_BCN_ATTR_TMAX] = {.type = NLA_U32}, 157859ee3c4SAlexander Duyck [DCB_BCN_ATTR_TD] = {.type = NLA_U32}, 158859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RMIN] = {.type = NLA_U32}, 159859ee3c4SAlexander Duyck [DCB_BCN_ATTR_W] = {.type = NLA_U32}, 160859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RD] = {.type = NLA_U32}, 161859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RU] = {.type = NLA_U32}, 162859ee3c4SAlexander Duyck [DCB_BCN_ATTR_WRTT] = {.type = NLA_U32}, 163859ee3c4SAlexander Duyck [DCB_BCN_ATTR_RI] = {.type = NLA_U32}, 164859ee3c4SAlexander Duyck [DCB_BCN_ATTR_C] = {.type = NLA_U32}, 165859ee3c4SAlexander Duyck [DCB_BCN_ATTR_ALL] = {.type = NLA_FLAG}, 166859ee3c4SAlexander Duyck }; 167859ee3c4SAlexander Duyck 1686fa382afSYi Zou /* DCB APP nested attributes. */ 169b54452b0SAlexey Dobriyan static const struct nla_policy dcbnl_app_nest[DCB_APP_ATTR_MAX + 1] = { 1706fa382afSYi Zou [DCB_APP_ATTR_IDTYPE] = {.type = NLA_U8}, 1716fa382afSYi Zou [DCB_APP_ATTR_ID] = {.type = NLA_U16}, 1726fa382afSYi Zou [DCB_APP_ATTR_PRIORITY] = {.type = NLA_U8}, 1736fa382afSYi Zou }; 1746fa382afSYi Zou 1753e29027aSJohn Fastabend /* IEEE 802.1Qaz nested attributes. */ 1763e29027aSJohn Fastabend static const struct nla_policy dcbnl_ieee_policy[DCB_ATTR_IEEE_MAX + 1] = { 1773e29027aSJohn Fastabend [DCB_ATTR_IEEE_ETS] = {.len = sizeof(struct ieee_ets)}, 1783e29027aSJohn Fastabend [DCB_ATTR_IEEE_PFC] = {.len = sizeof(struct ieee_pfc)}, 1793e29027aSJohn Fastabend [DCB_ATTR_IEEE_APP_TABLE] = {.type = NLA_NESTED}, 18008f10affSAmir Vadai [DCB_ATTR_IEEE_MAXRATE] = {.len = sizeof(struct ieee_maxrate)}, 1813e29027aSJohn Fastabend }; 1823e29027aSJohn Fastabend 1833e29027aSJohn Fastabend static const struct nla_policy dcbnl_ieee_app[DCB_ATTR_IEEE_APP_MAX + 1] = { 1843e29027aSJohn Fastabend [DCB_ATTR_IEEE_APP] = {.len = sizeof(struct dcb_app)}, 1853e29027aSJohn Fastabend }; 1863e29027aSJohn Fastabend 187ea45fe4eSShmulik Ravid /* DCB number of traffic classes nested attributes. */ 188ea45fe4eSShmulik Ravid static const struct nla_policy dcbnl_featcfg_nest[DCB_FEATCFG_ATTR_MAX + 1] = { 189ea45fe4eSShmulik Ravid [DCB_FEATCFG_ATTR_ALL] = {.type = NLA_FLAG}, 190ea45fe4eSShmulik Ravid [DCB_FEATCFG_ATTR_PG] = {.type = NLA_U8}, 191ea45fe4eSShmulik Ravid [DCB_FEATCFG_ATTR_PFC] = {.type = NLA_U8}, 192ea45fe4eSShmulik Ravid [DCB_FEATCFG_ATTR_APP] = {.type = NLA_U8}, 193ea45fe4eSShmulik Ravid }; 194ea45fe4eSShmulik Ravid 1959ab933abSJohn Fastabend static LIST_HEAD(dcb_app_list); 1969ab933abSJohn Fastabend static DEFINE_SPINLOCK(dcb_lock); 1979ab933abSJohn Fastabend 19833a03aadSThomas Graf static struct sk_buff *dcbnl_newmsg(int type, u8 cmd, u32 port, u32 seq, 19933a03aadSThomas Graf u32 flags, struct nlmsghdr **nlhp) 20033a03aadSThomas Graf { 20133a03aadSThomas Graf struct sk_buff *skb; 20233a03aadSThomas Graf struct dcbmsg *dcb; 20333a03aadSThomas Graf struct nlmsghdr *nlh; 20433a03aadSThomas Graf 20533a03aadSThomas Graf skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 20633a03aadSThomas Graf if (!skb) 20733a03aadSThomas Graf return NULL; 20833a03aadSThomas Graf 20933a03aadSThomas Graf nlh = nlmsg_put(skb, port, seq, type, sizeof(*dcb), flags); 210b3908e22SThomas Graf BUG_ON(!nlh); 21133a03aadSThomas Graf 21233a03aadSThomas Graf dcb = nlmsg_data(nlh); 21333a03aadSThomas Graf dcb->dcb_family = AF_UNSPEC; 21433a03aadSThomas Graf dcb->cmd = cmd; 21533a03aadSThomas Graf dcb->dcb_pad = 0; 21633a03aadSThomas Graf 21733a03aadSThomas Graf if (nlhp) 21833a03aadSThomas Graf *nlhp = nlh; 21933a03aadSThomas Graf 22033a03aadSThomas Graf return skb; 22133a03aadSThomas Graf } 22233a03aadSThomas Graf 2237be99413SThomas Graf static int dcbnl_getstate(struct net_device *netdev, struct nlmsghdr *nlh, 2247be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 2252f90b865SAlexander Duyck { 2262f90b865SAlexander Duyck /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */ 2272f90b865SAlexander Duyck if (!netdev->dcbnl_ops->getstate) 2283d1f4869SThomas Graf return -EOPNOTSUPP; 2292f90b865SAlexander Duyck 2307be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_STATE, 2317be99413SThomas Graf netdev->dcbnl_ops->getstate(netdev)); 2322f90b865SAlexander Duyck } 2332f90b865SAlexander Duyck 2347be99413SThomas Graf static int dcbnl_getpfccfg(struct net_device *netdev, struct nlmsghdr *nlh, 2357be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 2362f90b865SAlexander Duyck { 2372f90b865SAlexander Duyck struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1], *nest; 2382f90b865SAlexander Duyck u8 value; 2393d1f4869SThomas Graf int ret; 2402f90b865SAlexander Duyck int i; 2412f90b865SAlexander Duyck int getall = 0; 2422f90b865SAlexander Duyck 2433d1f4869SThomas Graf if (!tb[DCB_ATTR_PFC_CFG]) 2443d1f4869SThomas Graf return -EINVAL; 2453d1f4869SThomas Graf 2463d1f4869SThomas Graf if (!netdev->dcbnl_ops->getpfccfg) 2473d1f4869SThomas Graf return -EOPNOTSUPP; 2482f90b865SAlexander Duyck 2492f90b865SAlexander Duyck ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX, 2502f90b865SAlexander Duyck tb[DCB_ATTR_PFC_CFG], 2512f90b865SAlexander Duyck dcbnl_pfc_up_nest); 2522f90b865SAlexander Duyck if (ret) 2533d1f4869SThomas Graf return ret; 2542f90b865SAlexander Duyck 2557be99413SThomas Graf nest = nla_nest_start(skb, DCB_ATTR_PFC_CFG); 2562f90b865SAlexander Duyck if (!nest) 2573d1f4869SThomas Graf return -EMSGSIZE; 2582f90b865SAlexander Duyck 2592f90b865SAlexander Duyck if (data[DCB_PFC_UP_ATTR_ALL]) 2602f90b865SAlexander Duyck getall = 1; 2612f90b865SAlexander Duyck 2622f90b865SAlexander Duyck for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) { 2632f90b865SAlexander Duyck if (!getall && !data[i]) 2642f90b865SAlexander Duyck continue; 2652f90b865SAlexander Duyck 2662f90b865SAlexander Duyck netdev->dcbnl_ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0, 2672f90b865SAlexander Duyck &value); 2687be99413SThomas Graf ret = nla_put_u8(skb, i, value); 2692f90b865SAlexander Duyck if (ret) { 2707be99413SThomas Graf nla_nest_cancel(skb, nest); 2713d1f4869SThomas Graf return ret; 2722f90b865SAlexander Duyck } 2732f90b865SAlexander Duyck } 2747be99413SThomas Graf nla_nest_end(skb, nest); 2752f90b865SAlexander Duyck 2762f90b865SAlexander Duyck return 0; 2772f90b865SAlexander Duyck } 2782f90b865SAlexander Duyck 2797be99413SThomas Graf static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlmsghdr *nlh, 2807be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 2812f90b865SAlexander Duyck { 2822f90b865SAlexander Duyck u8 perm_addr[MAX_ADDR_LEN]; 2832f90b865SAlexander Duyck 2842f90b865SAlexander Duyck if (!netdev->dcbnl_ops->getpermhwaddr) 2853d1f4869SThomas Graf return -EOPNOTSUPP; 2862f90b865SAlexander Duyck 2872f90b865SAlexander Duyck netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr); 2882f90b865SAlexander Duyck 2897be99413SThomas Graf return nla_put(skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr), perm_addr); 2902f90b865SAlexander Duyck } 2912f90b865SAlexander Duyck 2927be99413SThomas Graf static int dcbnl_getcap(struct net_device *netdev, struct nlmsghdr *nlh, 2937be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 29446132188SAlexander Duyck { 29546132188SAlexander Duyck struct nlattr *data[DCB_CAP_ATTR_MAX + 1], *nest; 29646132188SAlexander Duyck u8 value; 2973d1f4869SThomas Graf int ret; 29846132188SAlexander Duyck int i; 29946132188SAlexander Duyck int getall = 0; 30046132188SAlexander Duyck 3013d1f4869SThomas Graf if (!tb[DCB_ATTR_CAP]) 3023d1f4869SThomas Graf return -EINVAL; 3033d1f4869SThomas Graf 3043d1f4869SThomas Graf if (!netdev->dcbnl_ops->getcap) 3053d1f4869SThomas Graf return -EOPNOTSUPP; 30646132188SAlexander Duyck 30746132188SAlexander Duyck ret = nla_parse_nested(data, DCB_CAP_ATTR_MAX, tb[DCB_ATTR_CAP], 30846132188SAlexander Duyck dcbnl_cap_nest); 30946132188SAlexander Duyck if (ret) 3103d1f4869SThomas Graf return ret; 31146132188SAlexander Duyck 3127be99413SThomas Graf nest = nla_nest_start(skb, DCB_ATTR_CAP); 31346132188SAlexander Duyck if (!nest) 3143d1f4869SThomas Graf return -EMSGSIZE; 31546132188SAlexander Duyck 31646132188SAlexander Duyck if (data[DCB_CAP_ATTR_ALL]) 31746132188SAlexander Duyck getall = 1; 31846132188SAlexander Duyck 31946132188SAlexander Duyck for (i = DCB_CAP_ATTR_ALL+1; i <= DCB_CAP_ATTR_MAX; i++) { 32046132188SAlexander Duyck if (!getall && !data[i]) 32146132188SAlexander Duyck continue; 32246132188SAlexander Duyck 32346132188SAlexander Duyck if (!netdev->dcbnl_ops->getcap(netdev, i, &value)) { 3247be99413SThomas Graf ret = nla_put_u8(skb, i, value); 32546132188SAlexander Duyck if (ret) { 3267be99413SThomas Graf nla_nest_cancel(skb, nest); 3273d1f4869SThomas Graf return ret; 3287be99413SThomas Graf } 3297be99413SThomas Graf } 3307be99413SThomas Graf } 3317be99413SThomas Graf nla_nest_end(skb, nest); 33246132188SAlexander Duyck 33346132188SAlexander Duyck return 0; 33446132188SAlexander Duyck } 33546132188SAlexander Duyck 3367be99413SThomas Graf static int dcbnl_getnumtcs(struct net_device *netdev, struct nlmsghdr *nlh, 3377be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 33833dbabc4SAlexander Duyck { 33933dbabc4SAlexander Duyck struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1], *nest; 34033dbabc4SAlexander Duyck u8 value; 3413d1f4869SThomas Graf int ret; 34233dbabc4SAlexander Duyck int i; 34333dbabc4SAlexander Duyck int getall = 0; 34433dbabc4SAlexander Duyck 3453d1f4869SThomas Graf if (!tb[DCB_ATTR_NUMTCS]) 3463d1f4869SThomas Graf return -EINVAL; 3473d1f4869SThomas Graf 3483d1f4869SThomas Graf if (!netdev->dcbnl_ops->getnumtcs) 3493d1f4869SThomas Graf return -EOPNOTSUPP; 35033dbabc4SAlexander Duyck 35133dbabc4SAlexander Duyck ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS], 35233dbabc4SAlexander Duyck dcbnl_numtcs_nest); 3533d1f4869SThomas Graf if (ret) 3543d1f4869SThomas Graf return ret; 35533dbabc4SAlexander Duyck 3567be99413SThomas Graf nest = nla_nest_start(skb, DCB_ATTR_NUMTCS); 3573d1f4869SThomas Graf if (!nest) 3583d1f4869SThomas Graf return -EMSGSIZE; 35933dbabc4SAlexander Duyck 36033dbabc4SAlexander Duyck if (data[DCB_NUMTCS_ATTR_ALL]) 36133dbabc4SAlexander Duyck getall = 1; 36233dbabc4SAlexander Duyck 36333dbabc4SAlexander Duyck for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) { 36433dbabc4SAlexander Duyck if (!getall && !data[i]) 36533dbabc4SAlexander Duyck continue; 36633dbabc4SAlexander Duyck 36733dbabc4SAlexander Duyck ret = netdev->dcbnl_ops->getnumtcs(netdev, i, &value); 36833dbabc4SAlexander Duyck if (!ret) { 3697be99413SThomas Graf ret = nla_put_u8(skb, i, value); 37033dbabc4SAlexander Duyck if (ret) { 3717be99413SThomas Graf nla_nest_cancel(skb, nest); 3723d1f4869SThomas Graf return ret; 37333dbabc4SAlexander Duyck } 3743d1f4869SThomas Graf } else 3753d1f4869SThomas Graf return -EINVAL; 3767be99413SThomas Graf } 3777be99413SThomas Graf nla_nest_end(skb, nest); 37833dbabc4SAlexander Duyck 37933dbabc4SAlexander Duyck return 0; 38033dbabc4SAlexander Duyck } 38133dbabc4SAlexander Duyck 3827be99413SThomas Graf static int dcbnl_setnumtcs(struct net_device *netdev, struct nlmsghdr *nlh, 3837be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 38433dbabc4SAlexander Duyck { 38533dbabc4SAlexander Duyck struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1]; 3863d1f4869SThomas Graf int ret; 38733dbabc4SAlexander Duyck u8 value; 38833dbabc4SAlexander Duyck int i; 38933dbabc4SAlexander Duyck 3903d1f4869SThomas Graf if (!tb[DCB_ATTR_NUMTCS]) 3913d1f4869SThomas Graf return -EINVAL; 3923d1f4869SThomas Graf 3933d1f4869SThomas Graf if (!netdev->dcbnl_ops->setnumtcs) 3943d1f4869SThomas Graf return -EOPNOTSUPP; 39533dbabc4SAlexander Duyck 39633dbabc4SAlexander Duyck ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS], 39733dbabc4SAlexander Duyck dcbnl_numtcs_nest); 3987be99413SThomas Graf if (ret) 3993d1f4869SThomas Graf return ret; 40033dbabc4SAlexander Duyck 40133dbabc4SAlexander Duyck for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) { 40233dbabc4SAlexander Duyck if (data[i] == NULL) 40333dbabc4SAlexander Duyck continue; 40433dbabc4SAlexander Duyck 40533dbabc4SAlexander Duyck value = nla_get_u8(data[i]); 40633dbabc4SAlexander Duyck 40733dbabc4SAlexander Duyck ret = netdev->dcbnl_ops->setnumtcs(netdev, i, value); 40833dbabc4SAlexander Duyck if (ret) 4097be99413SThomas Graf break; 41033dbabc4SAlexander Duyck } 41133dbabc4SAlexander Duyck 4127be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_NUMTCS, !!ret); 41333dbabc4SAlexander Duyck } 41433dbabc4SAlexander Duyck 4157be99413SThomas Graf static int dcbnl_getpfcstate(struct net_device *netdev, struct nlmsghdr *nlh, 4167be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 4170eb3aa9bSAlexander Duyck { 4180eb3aa9bSAlexander Duyck if (!netdev->dcbnl_ops->getpfcstate) 4193d1f4869SThomas Graf return -EOPNOTSUPP; 4200eb3aa9bSAlexander Duyck 4217be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_PFC_STATE, 4227be99413SThomas Graf netdev->dcbnl_ops->getpfcstate(netdev)); 4230eb3aa9bSAlexander Duyck } 4240eb3aa9bSAlexander Duyck 4257be99413SThomas Graf static int dcbnl_setpfcstate(struct net_device *netdev, struct nlmsghdr *nlh, 4267be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 4270eb3aa9bSAlexander Duyck { 4280eb3aa9bSAlexander Duyck u8 value; 4290eb3aa9bSAlexander Duyck 4303d1f4869SThomas Graf if (!tb[DCB_ATTR_PFC_STATE]) 4317be99413SThomas Graf return -EINVAL; 4320eb3aa9bSAlexander Duyck 4333d1f4869SThomas Graf if (!netdev->dcbnl_ops->setpfcstate) 4343d1f4869SThomas Graf return -EOPNOTSUPP; 4353d1f4869SThomas Graf 4360eb3aa9bSAlexander Duyck value = nla_get_u8(tb[DCB_ATTR_PFC_STATE]); 4370eb3aa9bSAlexander Duyck 4380eb3aa9bSAlexander Duyck netdev->dcbnl_ops->setpfcstate(netdev, value); 4390eb3aa9bSAlexander Duyck 4407be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_PFC_STATE, 0); 4410eb3aa9bSAlexander Duyck } 4420eb3aa9bSAlexander Duyck 4437be99413SThomas Graf static int dcbnl_getapp(struct net_device *netdev, struct nlmsghdr *nlh, 4447be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 44557949686SYi Zou { 44657949686SYi Zou struct nlattr *app_nest; 44757949686SYi Zou struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1]; 44857949686SYi Zou u16 id; 44957949686SYi Zou u8 up, idtype; 4503d1f4869SThomas Graf int ret; 45157949686SYi Zou 4523dce38a0SJohn Fastabend if (!tb[DCB_ATTR_APP]) 4533d1f4869SThomas Graf return -EINVAL; 45457949686SYi Zou 45557949686SYi Zou ret = nla_parse_nested(app_tb, DCB_APP_ATTR_MAX, tb[DCB_ATTR_APP], 45657949686SYi Zou dcbnl_app_nest); 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) { 47457949686SYi Zou up = netdev->dcbnl_ops->getapp(netdev, idtype, id); 4753dce38a0SJohn Fastabend } else { 4763dce38a0SJohn Fastabend struct dcb_app app = { 4773dce38a0SJohn Fastabend .selector = idtype, 4783dce38a0SJohn Fastabend .protocol = id, 4793dce38a0SJohn Fastabend }; 4803dce38a0SJohn Fastabend up = dcb_getapp(netdev, &app); 4813dce38a0SJohn Fastabend } 48257949686SYi Zou 4837be99413SThomas Graf app_nest = nla_nest_start(skb, DCB_ATTR_APP); 4847be99413SThomas Graf if (!app_nest) 4853d1f4869SThomas Graf return -EMSGSIZE; 48657949686SYi Zou 4877be99413SThomas Graf ret = nla_put_u8(skb, DCB_APP_ATTR_IDTYPE, idtype); 48857949686SYi Zou if (ret) 48957949686SYi Zou goto out_cancel; 49057949686SYi Zou 4917be99413SThomas Graf ret = nla_put_u16(skb, DCB_APP_ATTR_ID, id); 49257949686SYi Zou if (ret) 49357949686SYi Zou goto out_cancel; 49457949686SYi Zou 4957be99413SThomas Graf ret = nla_put_u8(skb, DCB_APP_ATTR_PRIORITY, up); 49657949686SYi Zou if (ret) 49757949686SYi Zou goto out_cancel; 49857949686SYi Zou 4997be99413SThomas Graf nla_nest_end(skb, app_nest); 50057949686SYi Zou 5013d1f4869SThomas Graf return 0; 50257949686SYi Zou 50357949686SYi Zou out_cancel: 5047be99413SThomas Graf nla_nest_cancel(skb, app_nest); 50557949686SYi Zou return ret; 50657949686SYi Zou } 50757949686SYi Zou 5087be99413SThomas Graf static int dcbnl_setapp(struct net_device *netdev, struct nlmsghdr *nlh, 5097be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 51057949686SYi Zou { 5113d1f4869SThomas Graf int ret; 51257949686SYi Zou u16 id; 51357949686SYi Zou u8 up, idtype; 51457949686SYi Zou struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1]; 51557949686SYi Zou 5169ab933abSJohn Fastabend if (!tb[DCB_ATTR_APP]) 5173d1f4869SThomas Graf return -EINVAL; 51857949686SYi Zou 51957949686SYi Zou ret = nla_parse_nested(app_tb, DCB_APP_ATTR_MAX, tb[DCB_ATTR_APP], 52057949686SYi Zou dcbnl_app_nest); 52157949686SYi Zou if (ret) 5223d1f4869SThomas Graf return ret; 52357949686SYi Zou 52457949686SYi Zou /* all must be non-null */ 52557949686SYi Zou if ((!app_tb[DCB_APP_ATTR_IDTYPE]) || 52657949686SYi Zou (!app_tb[DCB_APP_ATTR_ID]) || 52757949686SYi Zou (!app_tb[DCB_APP_ATTR_PRIORITY])) 5283d1f4869SThomas Graf return -EINVAL; 52957949686SYi Zou 53057949686SYi Zou /* either by eth type or by socket number */ 53157949686SYi Zou idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]); 53257949686SYi Zou if ((idtype != DCB_APP_IDTYPE_ETHTYPE) && 53357949686SYi Zou (idtype != DCB_APP_IDTYPE_PORTNUM)) 5343d1f4869SThomas Graf return -EINVAL; 53557949686SYi Zou 53657949686SYi Zou id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]); 53757949686SYi Zou up = nla_get_u8(app_tb[DCB_APP_ATTR_PRIORITY]); 53857949686SYi Zou 5399ab933abSJohn Fastabend if (netdev->dcbnl_ops->setapp) { 5403d1f4869SThomas Graf ret = netdev->dcbnl_ops->setapp(netdev, idtype, id, up); 5419ab933abSJohn Fastabend } else { 5429ab933abSJohn Fastabend struct dcb_app app; 5439ab933abSJohn Fastabend app.selector = idtype; 5449ab933abSJohn Fastabend app.protocol = id; 5459ab933abSJohn Fastabend app.priority = up; 5463d1f4869SThomas Graf ret = dcb_setapp(netdev, &app); 5479ab933abSJohn Fastabend } 5489ab933abSJohn Fastabend 5497be99413SThomas Graf ret = nla_put_u8(skb, DCB_ATTR_APP, ret); 55008157984SJohn Fastabend dcbnl_cee_notify(netdev, RTM_SETDCB, DCB_CMD_SAPP, seq, 0); 5513d1f4869SThomas Graf 55257949686SYi Zou return ret; 55357949686SYi Zou } 55457949686SYi Zou 5557be99413SThomas Graf static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlmsghdr *nlh, 5567be99413SThomas Graf struct nlattr **tb, struct sk_buff *skb, int dir) 5572f90b865SAlexander Duyck { 5582f90b865SAlexander Duyck struct nlattr *pg_nest, *param_nest, *data; 5592f90b865SAlexander Duyck struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1]; 5602f90b865SAlexander Duyck struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1]; 5612f90b865SAlexander Duyck u8 prio, pgid, tc_pct, up_map; 5623d1f4869SThomas Graf int ret; 5632f90b865SAlexander Duyck int getall = 0; 5642f90b865SAlexander Duyck int i; 5652f90b865SAlexander Duyck 5663d1f4869SThomas Graf if (!tb[DCB_ATTR_PG_CFG]) 5673d1f4869SThomas Graf return -EINVAL; 5683d1f4869SThomas Graf 5693d1f4869SThomas Graf if (!netdev->dcbnl_ops->getpgtccfgtx || 5702f90b865SAlexander Duyck !netdev->dcbnl_ops->getpgtccfgrx || 5712f90b865SAlexander Duyck !netdev->dcbnl_ops->getpgbwgcfgtx || 5722f90b865SAlexander Duyck !netdev->dcbnl_ops->getpgbwgcfgrx) 5733d1f4869SThomas Graf return -EOPNOTSUPP; 5742f90b865SAlexander Duyck 5752f90b865SAlexander Duyck ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX, 5762f90b865SAlexander Duyck tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest); 5772f90b865SAlexander Duyck if (ret) 5783d1f4869SThomas Graf return ret; 5792f90b865SAlexander Duyck 5807be99413SThomas Graf pg_nest = nla_nest_start(skb, DCB_ATTR_PG_CFG); 5812f90b865SAlexander Duyck if (!pg_nest) 5823d1f4869SThomas Graf return -EMSGSIZE; 5832f90b865SAlexander Duyck 5842f90b865SAlexander Duyck if (pg_tb[DCB_PG_ATTR_TC_ALL]) 5852f90b865SAlexander Duyck getall = 1; 5862f90b865SAlexander Duyck 5872f90b865SAlexander Duyck for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) { 5882f90b865SAlexander Duyck if (!getall && !pg_tb[i]) 5892f90b865SAlexander Duyck continue; 5902f90b865SAlexander Duyck 5912f90b865SAlexander Duyck if (pg_tb[DCB_PG_ATTR_TC_ALL]) 5922f90b865SAlexander Duyck data = pg_tb[DCB_PG_ATTR_TC_ALL]; 5932f90b865SAlexander Duyck else 5942f90b865SAlexander Duyck data = pg_tb[i]; 5952f90b865SAlexander Duyck ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX, 5962f90b865SAlexander Duyck data, dcbnl_tc_param_nest); 5972f90b865SAlexander Duyck if (ret) 5982f90b865SAlexander Duyck goto err_pg; 5992f90b865SAlexander Duyck 6007be99413SThomas Graf param_nest = nla_nest_start(skb, i); 6012f90b865SAlexander Duyck if (!param_nest) 6022f90b865SAlexander Duyck goto err_pg; 6032f90b865SAlexander Duyck 6042f90b865SAlexander Duyck pgid = DCB_ATTR_VALUE_UNDEFINED; 6052f90b865SAlexander Duyck prio = DCB_ATTR_VALUE_UNDEFINED; 6062f90b865SAlexander Duyck tc_pct = DCB_ATTR_VALUE_UNDEFINED; 6072f90b865SAlexander Duyck up_map = DCB_ATTR_VALUE_UNDEFINED; 6082f90b865SAlexander Duyck 6092f90b865SAlexander Duyck if (dir) { 6102f90b865SAlexander Duyck /* Rx */ 6112f90b865SAlexander Duyck netdev->dcbnl_ops->getpgtccfgrx(netdev, 6122f90b865SAlexander Duyck i - DCB_PG_ATTR_TC_0, &prio, 6132f90b865SAlexander Duyck &pgid, &tc_pct, &up_map); 6142f90b865SAlexander Duyck } else { 6152f90b865SAlexander Duyck /* Tx */ 6162f90b865SAlexander Duyck netdev->dcbnl_ops->getpgtccfgtx(netdev, 6172f90b865SAlexander Duyck i - DCB_PG_ATTR_TC_0, &prio, 6182f90b865SAlexander Duyck &pgid, &tc_pct, &up_map); 6192f90b865SAlexander Duyck } 6202f90b865SAlexander Duyck 6212f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_PGID] || 6222f90b865SAlexander Duyck param_tb[DCB_TC_ATTR_PARAM_ALL]) { 6237be99413SThomas Graf ret = nla_put_u8(skb, 6242f90b865SAlexander Duyck DCB_TC_ATTR_PARAM_PGID, pgid); 6252f90b865SAlexander Duyck if (ret) 6262f90b865SAlexander Duyck goto err_param; 6272f90b865SAlexander Duyck } 6282f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING] || 6292f90b865SAlexander Duyck param_tb[DCB_TC_ATTR_PARAM_ALL]) { 6307be99413SThomas Graf ret = nla_put_u8(skb, 6312f90b865SAlexander Duyck DCB_TC_ATTR_PARAM_UP_MAPPING, up_map); 6322f90b865SAlexander Duyck if (ret) 6332f90b865SAlexander Duyck goto err_param; 6342f90b865SAlexander Duyck } 6352f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO] || 6362f90b865SAlexander Duyck param_tb[DCB_TC_ATTR_PARAM_ALL]) { 6377be99413SThomas Graf ret = nla_put_u8(skb, 6382f90b865SAlexander Duyck DCB_TC_ATTR_PARAM_STRICT_PRIO, prio); 6392f90b865SAlexander Duyck if (ret) 6402f90b865SAlexander Duyck goto err_param; 6412f90b865SAlexander Duyck } 6422f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT] || 6432f90b865SAlexander Duyck param_tb[DCB_TC_ATTR_PARAM_ALL]) { 6447be99413SThomas Graf ret = nla_put_u8(skb, DCB_TC_ATTR_PARAM_BW_PCT, 6452f90b865SAlexander Duyck tc_pct); 6462f90b865SAlexander Duyck if (ret) 6472f90b865SAlexander Duyck goto err_param; 6482f90b865SAlexander Duyck } 6497be99413SThomas Graf nla_nest_end(skb, param_nest); 6502f90b865SAlexander Duyck } 6512f90b865SAlexander Duyck 6522f90b865SAlexander Duyck if (pg_tb[DCB_PG_ATTR_BW_ID_ALL]) 6532f90b865SAlexander Duyck getall = 1; 6542f90b865SAlexander Duyck else 6552f90b865SAlexander Duyck getall = 0; 6562f90b865SAlexander Duyck 6572f90b865SAlexander Duyck for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) { 6582f90b865SAlexander Duyck if (!getall && !pg_tb[i]) 6592f90b865SAlexander Duyck continue; 6602f90b865SAlexander Duyck 6612f90b865SAlexander Duyck tc_pct = DCB_ATTR_VALUE_UNDEFINED; 6622f90b865SAlexander Duyck 6632f90b865SAlexander Duyck if (dir) { 6642f90b865SAlexander Duyck /* Rx */ 6652f90b865SAlexander Duyck netdev->dcbnl_ops->getpgbwgcfgrx(netdev, 6662f90b865SAlexander Duyck i - DCB_PG_ATTR_BW_ID_0, &tc_pct); 6672f90b865SAlexander Duyck } else { 6682f90b865SAlexander Duyck /* Tx */ 6692f90b865SAlexander Duyck netdev->dcbnl_ops->getpgbwgcfgtx(netdev, 6702f90b865SAlexander Duyck i - DCB_PG_ATTR_BW_ID_0, &tc_pct); 6712f90b865SAlexander Duyck } 6727be99413SThomas Graf ret = nla_put_u8(skb, i, tc_pct); 6732f90b865SAlexander Duyck if (ret) 6742f90b865SAlexander Duyck goto err_pg; 6752f90b865SAlexander Duyck } 6762f90b865SAlexander Duyck 6777be99413SThomas Graf nla_nest_end(skb, pg_nest); 6782f90b865SAlexander Duyck 6792f90b865SAlexander Duyck return 0; 6802f90b865SAlexander Duyck 6812f90b865SAlexander Duyck err_param: 6827be99413SThomas Graf nla_nest_cancel(skb, param_nest); 6832f90b865SAlexander Duyck err_pg: 6847be99413SThomas Graf nla_nest_cancel(skb, pg_nest); 6853d1f4869SThomas Graf 6863d1f4869SThomas Graf return -EMSGSIZE; 6872f90b865SAlexander Duyck } 6882f90b865SAlexander Duyck 6897be99413SThomas Graf static int dcbnl_pgtx_getcfg(struct net_device *netdev, struct nlmsghdr *nlh, 6907be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 6912f90b865SAlexander Duyck { 6927be99413SThomas Graf return __dcbnl_pg_getcfg(netdev, nlh, tb, skb, 0); 6932f90b865SAlexander Duyck } 6942f90b865SAlexander Duyck 6957be99413SThomas Graf static int dcbnl_pgrx_getcfg(struct net_device *netdev, struct nlmsghdr *nlh, 6967be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 6972f90b865SAlexander Duyck { 6987be99413SThomas Graf return __dcbnl_pg_getcfg(netdev, nlh, tb, skb, 1); 6992f90b865SAlexander Duyck } 7002f90b865SAlexander Duyck 7017be99413SThomas Graf static int dcbnl_setstate(struct net_device *netdev, struct nlmsghdr *nlh, 7027be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 7032f90b865SAlexander Duyck { 7042f90b865SAlexander Duyck u8 value; 7052f90b865SAlexander Duyck 7063d1f4869SThomas Graf if (!tb[DCB_ATTR_STATE]) 7077be99413SThomas Graf return -EINVAL; 7082f90b865SAlexander Duyck 7093d1f4869SThomas Graf if (!netdev->dcbnl_ops->setstate) 7103d1f4869SThomas Graf return -EOPNOTSUPP; 7113d1f4869SThomas Graf 7122f90b865SAlexander Duyck value = nla_get_u8(tb[DCB_ATTR_STATE]); 7132f90b865SAlexander Duyck 7147be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_STATE, 7157be99413SThomas Graf netdev->dcbnl_ops->setstate(netdev, value)); 7162f90b865SAlexander Duyck } 7172f90b865SAlexander Duyck 7187be99413SThomas Graf static int dcbnl_setpfccfg(struct net_device *netdev, struct nlmsghdr *nlh, 7197be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 7202f90b865SAlexander Duyck { 7212f90b865SAlexander Duyck struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1]; 7222f90b865SAlexander Duyck int i; 7233d1f4869SThomas Graf int ret; 7242f90b865SAlexander Duyck u8 value; 7252f90b865SAlexander Duyck 7263d1f4869SThomas Graf if (!tb[DCB_ATTR_PFC_CFG]) 7273d1f4869SThomas Graf return -EINVAL; 7283d1f4869SThomas Graf 7293d1f4869SThomas Graf if (!netdev->dcbnl_ops->setpfccfg) 7303d1f4869SThomas Graf return -EOPNOTSUPP; 7312f90b865SAlexander Duyck 7322f90b865SAlexander Duyck ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX, 7332f90b865SAlexander Duyck tb[DCB_ATTR_PFC_CFG], 7342f90b865SAlexander Duyck dcbnl_pfc_up_nest); 7352f90b865SAlexander Duyck if (ret) 7363d1f4869SThomas Graf return ret; 7372f90b865SAlexander Duyck 7382f90b865SAlexander Duyck for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) { 7392f90b865SAlexander Duyck if (data[i] == NULL) 7402f90b865SAlexander Duyck continue; 7412f90b865SAlexander Duyck value = nla_get_u8(data[i]); 7422f90b865SAlexander Duyck netdev->dcbnl_ops->setpfccfg(netdev, 7432f90b865SAlexander Duyck data[i]->nla_type - DCB_PFC_UP_ATTR_0, value); 7442f90b865SAlexander Duyck } 7452f90b865SAlexander Duyck 7467be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_PFC_CFG, 0); 7472f90b865SAlexander Duyck } 7482f90b865SAlexander Duyck 7497be99413SThomas Graf static int dcbnl_setall(struct net_device *netdev, struct nlmsghdr *nlh, 7507be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 7512f90b865SAlexander Duyck { 7523d1f4869SThomas Graf int ret; 7532f90b865SAlexander Duyck 7543d1f4869SThomas Graf if (!tb[DCB_ATTR_SET_ALL]) 7553d1f4869SThomas Graf return -EINVAL; 7563d1f4869SThomas Graf 7573d1f4869SThomas Graf if (!netdev->dcbnl_ops->setall) 7583d1f4869SThomas Graf return -EOPNOTSUPP; 7592f90b865SAlexander Duyck 7607be99413SThomas Graf ret = nla_put_u8(skb, DCB_ATTR_SET_ALL, 7617be99413SThomas Graf netdev->dcbnl_ops->setall(netdev)); 76208157984SJohn Fastabend dcbnl_cee_notify(netdev, RTM_SETDCB, DCB_CMD_SET_ALL, seq, 0); 7632f90b865SAlexander Duyck 7642f90b865SAlexander Duyck return ret; 7652f90b865SAlexander Duyck } 7662f90b865SAlexander Duyck 7677be99413SThomas Graf static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlmsghdr *nlh, 7687be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb, 7697be99413SThomas Graf int dir) 7702f90b865SAlexander Duyck { 7712f90b865SAlexander Duyck struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1]; 7722f90b865SAlexander Duyck struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1]; 7733d1f4869SThomas Graf int ret; 7742f90b865SAlexander Duyck int i; 7752f90b865SAlexander Duyck u8 pgid; 7762f90b865SAlexander Duyck u8 up_map; 7772f90b865SAlexander Duyck u8 prio; 7782f90b865SAlexander Duyck u8 tc_pct; 7792f90b865SAlexander Duyck 7803d1f4869SThomas Graf if (!tb[DCB_ATTR_PG_CFG]) 7813d1f4869SThomas Graf return -EINVAL; 7823d1f4869SThomas Graf 7833d1f4869SThomas Graf if (!netdev->dcbnl_ops->setpgtccfgtx || 7842f90b865SAlexander Duyck !netdev->dcbnl_ops->setpgtccfgrx || 7852f90b865SAlexander Duyck !netdev->dcbnl_ops->setpgbwgcfgtx || 7862f90b865SAlexander Duyck !netdev->dcbnl_ops->setpgbwgcfgrx) 7873d1f4869SThomas Graf return -EOPNOTSUPP; 7882f90b865SAlexander Duyck 7892f90b865SAlexander Duyck ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX, 7902f90b865SAlexander Duyck tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest); 7912f90b865SAlexander Duyck if (ret) 7923d1f4869SThomas Graf return ret; 7932f90b865SAlexander Duyck 7942f90b865SAlexander Duyck for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) { 7952f90b865SAlexander Duyck if (!pg_tb[i]) 7962f90b865SAlexander Duyck continue; 7972f90b865SAlexander Duyck 7982f90b865SAlexander Duyck ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX, 7992f90b865SAlexander Duyck pg_tb[i], dcbnl_tc_param_nest); 8002f90b865SAlexander Duyck if (ret) 8013d1f4869SThomas Graf return ret; 8022f90b865SAlexander Duyck 8032f90b865SAlexander Duyck pgid = DCB_ATTR_VALUE_UNDEFINED; 8042f90b865SAlexander Duyck prio = DCB_ATTR_VALUE_UNDEFINED; 8052f90b865SAlexander Duyck tc_pct = DCB_ATTR_VALUE_UNDEFINED; 8062f90b865SAlexander Duyck up_map = DCB_ATTR_VALUE_UNDEFINED; 8072f90b865SAlexander Duyck 8082f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]) 8092f90b865SAlexander Duyck prio = 8102f90b865SAlexander Duyck nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]); 8112f90b865SAlexander Duyck 8122f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_PGID]) 8132f90b865SAlexander Duyck pgid = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_PGID]); 8142f90b865SAlexander Duyck 8152f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT]) 8162f90b865SAlexander Duyck tc_pct = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_BW_PCT]); 8172f90b865SAlexander Duyck 8182f90b865SAlexander Duyck if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]) 8192f90b865SAlexander Duyck up_map = 8202f90b865SAlexander Duyck nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]); 8212f90b865SAlexander Duyck 8222f90b865SAlexander Duyck /* dir: Tx = 0, Rx = 1 */ 8232f90b865SAlexander Duyck if (dir) { 8242f90b865SAlexander Duyck /* Rx */ 8252f90b865SAlexander Duyck netdev->dcbnl_ops->setpgtccfgrx(netdev, 8262f90b865SAlexander Duyck i - DCB_PG_ATTR_TC_0, 8272f90b865SAlexander Duyck prio, pgid, tc_pct, up_map); 8282f90b865SAlexander Duyck } else { 8292f90b865SAlexander Duyck /* Tx */ 8302f90b865SAlexander Duyck netdev->dcbnl_ops->setpgtccfgtx(netdev, 8312f90b865SAlexander Duyck i - DCB_PG_ATTR_TC_0, 8322f90b865SAlexander Duyck prio, pgid, tc_pct, up_map); 8332f90b865SAlexander Duyck } 8342f90b865SAlexander Duyck } 8352f90b865SAlexander Duyck 8362f90b865SAlexander Duyck for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) { 8372f90b865SAlexander Duyck if (!pg_tb[i]) 8382f90b865SAlexander Duyck continue; 8392f90b865SAlexander Duyck 8402f90b865SAlexander Duyck tc_pct = nla_get_u8(pg_tb[i]); 8412f90b865SAlexander Duyck 8422f90b865SAlexander Duyck /* dir: Tx = 0, Rx = 1 */ 8432f90b865SAlexander Duyck if (dir) { 8442f90b865SAlexander Duyck /* Rx */ 8452f90b865SAlexander Duyck netdev->dcbnl_ops->setpgbwgcfgrx(netdev, 8462f90b865SAlexander Duyck i - DCB_PG_ATTR_BW_ID_0, tc_pct); 8472f90b865SAlexander Duyck } else { 8482f90b865SAlexander Duyck /* Tx */ 8492f90b865SAlexander Duyck netdev->dcbnl_ops->setpgbwgcfgtx(netdev, 8502f90b865SAlexander Duyck i - DCB_PG_ATTR_BW_ID_0, tc_pct); 8512f90b865SAlexander Duyck } 8522f90b865SAlexander Duyck } 8532f90b865SAlexander Duyck 854bb1dfefdSJohn Fastabend return nla_put_u8(skb, DCB_ATTR_PG_CFG, 0); 8552f90b865SAlexander Duyck } 8562f90b865SAlexander Duyck 8577be99413SThomas Graf static int dcbnl_pgtx_setcfg(struct net_device *netdev, struct nlmsghdr *nlh, 8587be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 8592f90b865SAlexander Duyck { 8607be99413SThomas Graf return __dcbnl_pg_setcfg(netdev, nlh, seq, tb, skb, 0); 8612f90b865SAlexander Duyck } 8622f90b865SAlexander Duyck 8637be99413SThomas Graf static int dcbnl_pgrx_setcfg(struct net_device *netdev, struct nlmsghdr *nlh, 8647be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 8652f90b865SAlexander Duyck { 8667be99413SThomas Graf return __dcbnl_pg_setcfg(netdev, nlh, seq, tb, skb, 1); 8672f90b865SAlexander Duyck } 8682f90b865SAlexander Duyck 8697be99413SThomas Graf static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlmsghdr *nlh, 8707be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 871859ee3c4SAlexander Duyck { 872859ee3c4SAlexander Duyck struct nlattr *bcn_nest; 873859ee3c4SAlexander Duyck struct nlattr *bcn_tb[DCB_BCN_ATTR_MAX + 1]; 874859ee3c4SAlexander Duyck u8 value_byte; 875859ee3c4SAlexander Duyck u32 value_integer; 8763d1f4869SThomas Graf int ret; 877859ee3c4SAlexander Duyck bool getall = false; 878859ee3c4SAlexander Duyck int i; 879859ee3c4SAlexander Duyck 8803d1f4869SThomas Graf if (!tb[DCB_ATTR_BCN]) 8813d1f4869SThomas Graf return -EINVAL; 8823d1f4869SThomas Graf 8833d1f4869SThomas Graf if (!netdev->dcbnl_ops->getbcnrp || 884859ee3c4SAlexander Duyck !netdev->dcbnl_ops->getbcncfg) 8853d1f4869SThomas Graf return -EOPNOTSUPP; 886859ee3c4SAlexander Duyck 887859ee3c4SAlexander Duyck ret = nla_parse_nested(bcn_tb, DCB_BCN_ATTR_MAX, 888859ee3c4SAlexander Duyck tb[DCB_ATTR_BCN], dcbnl_bcn_nest); 889859ee3c4SAlexander Duyck if (ret) 8903d1f4869SThomas Graf return ret; 891859ee3c4SAlexander Duyck 8927be99413SThomas Graf bcn_nest = nla_nest_start(skb, DCB_ATTR_BCN); 893859ee3c4SAlexander Duyck if (!bcn_nest) 8943d1f4869SThomas Graf return -EMSGSIZE; 895859ee3c4SAlexander Duyck 896859ee3c4SAlexander Duyck if (bcn_tb[DCB_BCN_ATTR_ALL]) 897859ee3c4SAlexander Duyck getall = true; 898859ee3c4SAlexander Duyck 899859ee3c4SAlexander Duyck for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) { 900859ee3c4SAlexander Duyck if (!getall && !bcn_tb[i]) 901859ee3c4SAlexander Duyck continue; 902859ee3c4SAlexander Duyck 903859ee3c4SAlexander Duyck netdev->dcbnl_ops->getbcnrp(netdev, i - DCB_BCN_ATTR_RP_0, 904859ee3c4SAlexander Duyck &value_byte); 9057be99413SThomas Graf ret = nla_put_u8(skb, i, value_byte); 906859ee3c4SAlexander Duyck if (ret) 907859ee3c4SAlexander Duyck goto err_bcn; 908859ee3c4SAlexander Duyck } 909859ee3c4SAlexander Duyck 910f4314e81SDon Skidmore for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) { 911859ee3c4SAlexander Duyck if (!getall && !bcn_tb[i]) 912859ee3c4SAlexander Duyck continue; 913859ee3c4SAlexander Duyck 914859ee3c4SAlexander Duyck netdev->dcbnl_ops->getbcncfg(netdev, i, 915859ee3c4SAlexander Duyck &value_integer); 9167be99413SThomas Graf ret = nla_put_u32(skb, i, value_integer); 917859ee3c4SAlexander Duyck if (ret) 918859ee3c4SAlexander Duyck goto err_bcn; 919859ee3c4SAlexander Duyck } 920859ee3c4SAlexander Duyck 9217be99413SThomas Graf nla_nest_end(skb, bcn_nest); 922859ee3c4SAlexander Duyck 923859ee3c4SAlexander Duyck return 0; 924859ee3c4SAlexander Duyck 925859ee3c4SAlexander Duyck err_bcn: 9267be99413SThomas Graf nla_nest_cancel(skb, bcn_nest); 927859ee3c4SAlexander Duyck return ret; 928859ee3c4SAlexander Duyck } 929859ee3c4SAlexander Duyck 9307be99413SThomas Graf static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlmsghdr *nlh, 9317be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 932859ee3c4SAlexander Duyck { 933859ee3c4SAlexander Duyck struct nlattr *data[DCB_BCN_ATTR_MAX + 1]; 934859ee3c4SAlexander Duyck int i; 9353d1f4869SThomas Graf int ret; 936859ee3c4SAlexander Duyck u8 value_byte; 937859ee3c4SAlexander Duyck u32 value_int; 938859ee3c4SAlexander Duyck 9393d1f4869SThomas Graf if (!tb[DCB_ATTR_BCN]) 9403d1f4869SThomas Graf return -EINVAL; 9413d1f4869SThomas Graf 9423d1f4869SThomas Graf if (!netdev->dcbnl_ops->setbcncfg || 943f64f9e71SJoe Perches !netdev->dcbnl_ops->setbcnrp) 9443d1f4869SThomas Graf return -EOPNOTSUPP; 945859ee3c4SAlexander Duyck 946859ee3c4SAlexander Duyck ret = nla_parse_nested(data, DCB_BCN_ATTR_MAX, 947859ee3c4SAlexander Duyck tb[DCB_ATTR_BCN], 948859ee3c4SAlexander Duyck dcbnl_pfc_up_nest); 949859ee3c4SAlexander Duyck if (ret) 9503d1f4869SThomas Graf return ret; 951859ee3c4SAlexander Duyck 952859ee3c4SAlexander Duyck for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) { 953859ee3c4SAlexander Duyck if (data[i] == NULL) 954859ee3c4SAlexander Duyck continue; 955859ee3c4SAlexander Duyck value_byte = nla_get_u8(data[i]); 956859ee3c4SAlexander Duyck netdev->dcbnl_ops->setbcnrp(netdev, 957859ee3c4SAlexander Duyck data[i]->nla_type - DCB_BCN_ATTR_RP_0, value_byte); 958859ee3c4SAlexander Duyck } 959859ee3c4SAlexander Duyck 960f4314e81SDon Skidmore for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) { 961859ee3c4SAlexander Duyck if (data[i] == NULL) 962859ee3c4SAlexander Duyck continue; 963859ee3c4SAlexander Duyck value_int = nla_get_u32(data[i]); 964859ee3c4SAlexander Duyck netdev->dcbnl_ops->setbcncfg(netdev, 965859ee3c4SAlexander Duyck i, value_int); 966859ee3c4SAlexander Duyck } 967859ee3c4SAlexander Duyck 9683d1f4869SThomas Graf return nla_put_u8(skb, DCB_ATTR_BCN, 0); 969859ee3c4SAlexander Duyck } 970859ee3c4SAlexander Duyck 971dc6ed1dfSShmulik Ravid static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb, 972dc6ed1dfSShmulik Ravid int app_nested_type, int app_info_type, 973dc6ed1dfSShmulik Ravid int app_entry_type) 974eed84713SShmulik Ravid { 975eed84713SShmulik Ravid struct dcb_peer_app_info info; 976eed84713SShmulik Ravid struct dcb_app *table = NULL; 977eed84713SShmulik Ravid const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; 978eed84713SShmulik Ravid u16 app_count; 979eed84713SShmulik Ravid int err; 980eed84713SShmulik Ravid 981eed84713SShmulik Ravid 982eed84713SShmulik Ravid /** 983eed84713SShmulik Ravid * retrieve the peer app configuration form the driver. If the driver 984eed84713SShmulik Ravid * handlers fail exit without doing anything 985eed84713SShmulik Ravid */ 986eed84713SShmulik Ravid err = ops->peer_getappinfo(netdev, &info, &app_count); 987eed84713SShmulik Ravid if (!err && app_count) { 988eed84713SShmulik Ravid table = kmalloc(sizeof(struct dcb_app) * app_count, GFP_KERNEL); 989eed84713SShmulik Ravid if (!table) 990eed84713SShmulik Ravid return -ENOMEM; 991eed84713SShmulik Ravid 992eed84713SShmulik Ravid err = ops->peer_getapptable(netdev, table); 993eed84713SShmulik Ravid } 994eed84713SShmulik Ravid 995eed84713SShmulik Ravid if (!err) { 996eed84713SShmulik Ravid u16 i; 997eed84713SShmulik Ravid struct nlattr *app; 998eed84713SShmulik Ravid 999eed84713SShmulik Ravid /** 1000eed84713SShmulik Ravid * build the message, from here on the only possible failure 1001eed84713SShmulik Ravid * is due to the skb size 1002eed84713SShmulik Ravid */ 1003eed84713SShmulik Ravid err = -EMSGSIZE; 1004eed84713SShmulik Ravid 1005dc6ed1dfSShmulik Ravid app = nla_nest_start(skb, app_nested_type); 1006eed84713SShmulik Ravid if (!app) 1007eed84713SShmulik Ravid goto nla_put_failure; 1008eed84713SShmulik Ravid 10091eb4c977SDavid S. Miller if (app_info_type && 10101eb4c977SDavid S. Miller nla_put(skb, app_info_type, sizeof(info), &info)) 10111eb4c977SDavid S. Miller goto nla_put_failure; 1012dc6ed1dfSShmulik Ravid 10131eb4c977SDavid S. Miller for (i = 0; i < app_count; i++) { 10141eb4c977SDavid S. Miller if (nla_put(skb, app_entry_type, sizeof(struct dcb_app), 10151eb4c977SDavid S. Miller &table[i])) 10161eb4c977SDavid S. Miller goto nla_put_failure; 10171eb4c977SDavid S. Miller } 1018eed84713SShmulik Ravid nla_nest_end(skb, app); 1019eed84713SShmulik Ravid } 1020eed84713SShmulik Ravid err = 0; 1021eed84713SShmulik Ravid 1022eed84713SShmulik Ravid nla_put_failure: 1023eed84713SShmulik Ravid kfree(table); 1024eed84713SShmulik Ravid return err; 1025eed84713SShmulik Ravid } 10263e29027aSJohn Fastabend 10273e29027aSJohn Fastabend /* Handle IEEE 802.1Qaz GET commands. */ 1028314b4778SJohn Fastabend static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) 10293e29027aSJohn Fastabend { 10309ab933abSJohn Fastabend struct nlattr *ieee, *app; 10319ab933abSJohn Fastabend struct dcb_app_type *itr; 10323e29027aSJohn Fastabend const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; 1033c7797bafSJohn Fastabend int dcbx; 10343d1f4869SThomas Graf int err; 10353e29027aSJohn Fastabend 10361eb4c977SDavid S. Miller if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name)) 10373d1f4869SThomas Graf return -EMSGSIZE; 10383d1f4869SThomas Graf 10393e29027aSJohn Fastabend ieee = nla_nest_start(skb, DCB_ATTR_IEEE); 10403e29027aSJohn Fastabend if (!ieee) 10413d1f4869SThomas Graf return -EMSGSIZE; 10423e29027aSJohn Fastabend 10433e29027aSJohn Fastabend if (ops->ieee_getets) { 10443e29027aSJohn Fastabend struct ieee_ets ets; 10453e29027aSJohn Fastabend err = ops->ieee_getets(netdev, &ets); 10461eb4c977SDavid S. Miller if (!err && 10471eb4c977SDavid S. Miller nla_put(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets)) 10483d1f4869SThomas Graf return -EMSGSIZE; 10493e29027aSJohn Fastabend } 10503e29027aSJohn Fastabend 105108f10affSAmir Vadai if (ops->ieee_getmaxrate) { 105208f10affSAmir Vadai struct ieee_maxrate maxrate; 105308f10affSAmir Vadai err = ops->ieee_getmaxrate(netdev, &maxrate); 105408f10affSAmir Vadai if (!err) { 105508f10affSAmir Vadai err = nla_put(skb, DCB_ATTR_IEEE_MAXRATE, 105608f10affSAmir Vadai sizeof(maxrate), &maxrate); 105708f10affSAmir Vadai if (err) 10583d1f4869SThomas Graf return -EMSGSIZE; 105908f10affSAmir Vadai } 106008f10affSAmir Vadai } 106108f10affSAmir Vadai 10623e29027aSJohn Fastabend if (ops->ieee_getpfc) { 10633e29027aSJohn Fastabend struct ieee_pfc pfc; 10643e29027aSJohn Fastabend err = ops->ieee_getpfc(netdev, &pfc); 10651eb4c977SDavid S. Miller if (!err && 10661eb4c977SDavid S. Miller nla_put(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc)) 10673d1f4869SThomas Graf return -EMSGSIZE; 10683e29027aSJohn Fastabend } 10693e29027aSJohn Fastabend 10709ab933abSJohn Fastabend app = nla_nest_start(skb, DCB_ATTR_IEEE_APP_TABLE); 10719ab933abSJohn Fastabend if (!app) 10723d1f4869SThomas Graf return -EMSGSIZE; 10739ab933abSJohn Fastabend 10749ab933abSJohn Fastabend spin_lock(&dcb_lock); 10759ab933abSJohn Fastabend list_for_each_entry(itr, &dcb_app_list, list) { 1076e290ed81SMark Rustad if (itr->ifindex == netdev->ifindex) { 107770bfa2d2SDan Carpenter err = nla_put(skb, DCB_ATTR_IEEE_APP, sizeof(itr->app), 107870bfa2d2SDan Carpenter &itr->app); 107970bfa2d2SDan Carpenter if (err) { 108070bfa2d2SDan Carpenter spin_unlock(&dcb_lock); 10813d1f4869SThomas Graf return -EMSGSIZE; 108270bfa2d2SDan Carpenter } 108370bfa2d2SDan Carpenter } 10849ab933abSJohn Fastabend } 1085c7797bafSJohn Fastabend 1086c7797bafSJohn Fastabend if (netdev->dcbnl_ops->getdcbx) 1087c7797bafSJohn Fastabend dcbx = netdev->dcbnl_ops->getdcbx(netdev); 1088c7797bafSJohn Fastabend else 1089c7797bafSJohn Fastabend dcbx = -EOPNOTSUPP; 1090c7797bafSJohn Fastabend 10919ab933abSJohn Fastabend spin_unlock(&dcb_lock); 10929ab933abSJohn Fastabend nla_nest_end(skb, app); 10939ab933abSJohn Fastabend 1094eed84713SShmulik Ravid /* get peer info if available */ 1095eed84713SShmulik Ravid if (ops->ieee_peer_getets) { 1096eed84713SShmulik Ravid struct ieee_ets ets; 1097eed84713SShmulik Ravid err = ops->ieee_peer_getets(netdev, &ets); 10981eb4c977SDavid S. Miller if (!err && 10991eb4c977SDavid S. Miller nla_put(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets)) 11003d1f4869SThomas Graf return -EMSGSIZE; 1101eed84713SShmulik Ravid } 1102eed84713SShmulik Ravid 1103eed84713SShmulik Ravid if (ops->ieee_peer_getpfc) { 1104eed84713SShmulik Ravid struct ieee_pfc pfc; 1105eed84713SShmulik Ravid err = ops->ieee_peer_getpfc(netdev, &pfc); 11061eb4c977SDavid S. Miller if (!err && 11071eb4c977SDavid S. Miller nla_put(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc)) 11083d1f4869SThomas Graf return -EMSGSIZE; 1109eed84713SShmulik Ravid } 1110eed84713SShmulik Ravid 1111eed84713SShmulik Ravid if (ops->peer_getappinfo && ops->peer_getapptable) { 1112dc6ed1dfSShmulik Ravid err = dcbnl_build_peer_app(netdev, skb, 1113dc6ed1dfSShmulik Ravid DCB_ATTR_IEEE_PEER_APP, 1114dc6ed1dfSShmulik Ravid DCB_ATTR_IEEE_APP_UNSPEC, 1115dc6ed1dfSShmulik Ravid DCB_ATTR_IEEE_APP); 1116eed84713SShmulik Ravid if (err) 11173d1f4869SThomas Graf return -EMSGSIZE; 1118eed84713SShmulik Ravid } 1119eed84713SShmulik Ravid 11203e29027aSJohn Fastabend nla_nest_end(skb, ieee); 1121c7797bafSJohn Fastabend if (dcbx >= 0) { 1122c7797bafSJohn Fastabend err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx); 1123c7797bafSJohn Fastabend if (err) 11243d1f4869SThomas Graf return -EMSGSIZE; 1125c7797bafSJohn Fastabend } 11263e29027aSJohn Fastabend 1127314b4778SJohn Fastabend return 0; 11283e29027aSJohn Fastabend } 11293e29027aSJohn Fastabend 11305b7f7626SShmulik Ravid static int dcbnl_cee_pg_fill(struct sk_buff *skb, struct net_device *dev, 11315b7f7626SShmulik Ravid int dir) 11325b7f7626SShmulik Ravid { 11335b7f7626SShmulik Ravid u8 pgid, up_map, prio, tc_pct; 11345b7f7626SShmulik Ravid const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops; 11355b7f7626SShmulik Ravid int i = dir ? DCB_ATTR_CEE_TX_PG : DCB_ATTR_CEE_RX_PG; 11365b7f7626SShmulik Ravid struct nlattr *pg = nla_nest_start(skb, i); 11375b7f7626SShmulik Ravid 11385b7f7626SShmulik Ravid if (!pg) 11393d1f4869SThomas Graf return -EMSGSIZE; 11405b7f7626SShmulik Ravid 11415b7f7626SShmulik Ravid for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) { 11425b7f7626SShmulik Ravid struct nlattr *tc_nest = nla_nest_start(skb, i); 11435b7f7626SShmulik Ravid 11445b7f7626SShmulik Ravid if (!tc_nest) 11453d1f4869SThomas Graf return -EMSGSIZE; 11465b7f7626SShmulik Ravid 11475b7f7626SShmulik Ravid pgid = DCB_ATTR_VALUE_UNDEFINED; 11485b7f7626SShmulik Ravid prio = DCB_ATTR_VALUE_UNDEFINED; 11495b7f7626SShmulik Ravid tc_pct = DCB_ATTR_VALUE_UNDEFINED; 11505b7f7626SShmulik Ravid up_map = DCB_ATTR_VALUE_UNDEFINED; 11515b7f7626SShmulik Ravid 11525b7f7626SShmulik Ravid if (!dir) 11535b7f7626SShmulik Ravid ops->getpgtccfgrx(dev, i - DCB_PG_ATTR_TC_0, 11545b7f7626SShmulik Ravid &prio, &pgid, &tc_pct, &up_map); 11555b7f7626SShmulik Ravid else 11565b7f7626SShmulik Ravid ops->getpgtccfgtx(dev, i - DCB_PG_ATTR_TC_0, 11575b7f7626SShmulik Ravid &prio, &pgid, &tc_pct, &up_map); 11585b7f7626SShmulik Ravid 11591eb4c977SDavid S. Miller if (nla_put_u8(skb, DCB_TC_ATTR_PARAM_PGID, pgid) || 11601eb4c977SDavid S. Miller nla_put_u8(skb, DCB_TC_ATTR_PARAM_UP_MAPPING, up_map) || 11611eb4c977SDavid S. Miller nla_put_u8(skb, DCB_TC_ATTR_PARAM_STRICT_PRIO, prio) || 11621eb4c977SDavid S. Miller nla_put_u8(skb, DCB_TC_ATTR_PARAM_BW_PCT, tc_pct)) 11633d1f4869SThomas Graf return -EMSGSIZE; 11645b7f7626SShmulik Ravid nla_nest_end(skb, tc_nest); 11655b7f7626SShmulik Ravid } 11665b7f7626SShmulik Ravid 11675b7f7626SShmulik Ravid for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) { 11685b7f7626SShmulik Ravid tc_pct = DCB_ATTR_VALUE_UNDEFINED; 11695b7f7626SShmulik Ravid 11705b7f7626SShmulik Ravid if (!dir) 11715b7f7626SShmulik Ravid ops->getpgbwgcfgrx(dev, i - DCB_PG_ATTR_BW_ID_0, 11725b7f7626SShmulik Ravid &tc_pct); 11735b7f7626SShmulik Ravid else 11745b7f7626SShmulik Ravid ops->getpgbwgcfgtx(dev, i - DCB_PG_ATTR_BW_ID_0, 11755b7f7626SShmulik Ravid &tc_pct); 11761eb4c977SDavid S. Miller if (nla_put_u8(skb, i, tc_pct)) 11773d1f4869SThomas Graf return -EMSGSIZE; 11785b7f7626SShmulik Ravid } 11795b7f7626SShmulik Ravid nla_nest_end(skb, pg); 11805b7f7626SShmulik Ravid return 0; 11815b7f7626SShmulik Ravid } 11825b7f7626SShmulik Ravid 11835b7f7626SShmulik Ravid static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev) 11845b7f7626SShmulik Ravid { 11855b7f7626SShmulik Ravid struct nlattr *cee, *app; 11865b7f7626SShmulik Ravid struct dcb_app_type *itr; 11875b7f7626SShmulik Ravid const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; 11885b7f7626SShmulik Ravid int dcbx, i, err = -EMSGSIZE; 11895b7f7626SShmulik Ravid u8 value; 11905b7f7626SShmulik Ravid 11911eb4c977SDavid S. Miller if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name)) 11921eb4c977SDavid S. Miller goto nla_put_failure; 11935b7f7626SShmulik Ravid cee = nla_nest_start(skb, DCB_ATTR_CEE); 11945b7f7626SShmulik Ravid if (!cee) 11955b7f7626SShmulik Ravid goto nla_put_failure; 11965b7f7626SShmulik Ravid 11975b7f7626SShmulik Ravid /* local pg */ 11985b7f7626SShmulik Ravid if (ops->getpgtccfgtx && ops->getpgbwgcfgtx) { 11995b7f7626SShmulik Ravid err = dcbnl_cee_pg_fill(skb, netdev, 1); 12005b7f7626SShmulik Ravid if (err) 12015b7f7626SShmulik Ravid goto nla_put_failure; 12025b7f7626SShmulik Ravid } 12035b7f7626SShmulik Ravid 12045b7f7626SShmulik Ravid if (ops->getpgtccfgrx && ops->getpgbwgcfgrx) { 12055b7f7626SShmulik Ravid err = dcbnl_cee_pg_fill(skb, netdev, 0); 12065b7f7626SShmulik Ravid if (err) 12075b7f7626SShmulik Ravid goto nla_put_failure; 12085b7f7626SShmulik Ravid } 12095b7f7626SShmulik Ravid 12105b7f7626SShmulik Ravid /* local pfc */ 12115b7f7626SShmulik Ravid if (ops->getpfccfg) { 12125b7f7626SShmulik Ravid struct nlattr *pfc_nest = nla_nest_start(skb, DCB_ATTR_CEE_PFC); 12135b7f7626SShmulik Ravid 12145b7f7626SShmulik Ravid if (!pfc_nest) 12155b7f7626SShmulik Ravid goto nla_put_failure; 12165b7f7626SShmulik Ravid 12175b7f7626SShmulik Ravid for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) { 12185b7f7626SShmulik Ravid ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0, &value); 12191eb4c977SDavid S. Miller if (nla_put_u8(skb, i, value)) 12201eb4c977SDavid S. Miller goto nla_put_failure; 12215b7f7626SShmulik Ravid } 12225b7f7626SShmulik Ravid nla_nest_end(skb, pfc_nest); 12235b7f7626SShmulik Ravid } 12245b7f7626SShmulik Ravid 12255b7f7626SShmulik Ravid /* local app */ 12265b7f7626SShmulik Ravid spin_lock(&dcb_lock); 12275b7f7626SShmulik Ravid app = nla_nest_start(skb, DCB_ATTR_CEE_APP_TABLE); 12285b7f7626SShmulik Ravid if (!app) 122940f5d72aSDan Carpenter goto dcb_unlock; 12305b7f7626SShmulik Ravid 12315b7f7626SShmulik Ravid list_for_each_entry(itr, &dcb_app_list, list) { 1232e290ed81SMark Rustad if (itr->ifindex == netdev->ifindex) { 12335b7f7626SShmulik Ravid struct nlattr *app_nest = nla_nest_start(skb, 12345b7f7626SShmulik Ravid DCB_ATTR_APP); 12355b7f7626SShmulik Ravid if (!app_nest) 12365b7f7626SShmulik Ravid goto dcb_unlock; 12375b7f7626SShmulik Ravid 12385b7f7626SShmulik Ravid err = nla_put_u8(skb, DCB_APP_ATTR_IDTYPE, 12395b7f7626SShmulik Ravid itr->app.selector); 12405b7f7626SShmulik Ravid if (err) 12415b7f7626SShmulik Ravid goto dcb_unlock; 12425b7f7626SShmulik Ravid 12435b7f7626SShmulik Ravid err = nla_put_u16(skb, DCB_APP_ATTR_ID, 12445b7f7626SShmulik Ravid itr->app.protocol); 12455b7f7626SShmulik Ravid if (err) 12465b7f7626SShmulik Ravid goto dcb_unlock; 12475b7f7626SShmulik Ravid 12485b7f7626SShmulik Ravid err = nla_put_u8(skb, DCB_APP_ATTR_PRIORITY, 12495b7f7626SShmulik Ravid itr->app.priority); 12505b7f7626SShmulik Ravid if (err) 12515b7f7626SShmulik Ravid goto dcb_unlock; 12525b7f7626SShmulik Ravid 12535b7f7626SShmulik Ravid nla_nest_end(skb, app_nest); 12545b7f7626SShmulik Ravid } 12555b7f7626SShmulik Ravid } 12565b7f7626SShmulik Ravid nla_nest_end(skb, app); 12575b7f7626SShmulik Ravid 12585b7f7626SShmulik Ravid if (netdev->dcbnl_ops->getdcbx) 12595b7f7626SShmulik Ravid dcbx = netdev->dcbnl_ops->getdcbx(netdev); 12605b7f7626SShmulik Ravid else 12615b7f7626SShmulik Ravid dcbx = -EOPNOTSUPP; 12625b7f7626SShmulik Ravid 12635b7f7626SShmulik Ravid spin_unlock(&dcb_lock); 12645b7f7626SShmulik Ravid 12655b7f7626SShmulik Ravid /* features flags */ 12665b7f7626SShmulik Ravid if (ops->getfeatcfg) { 12675b7f7626SShmulik Ravid struct nlattr *feat = nla_nest_start(skb, DCB_ATTR_CEE_FEAT); 12685b7f7626SShmulik Ravid if (!feat) 12695b7f7626SShmulik Ravid goto nla_put_failure; 12705b7f7626SShmulik Ravid 12715b7f7626SShmulik Ravid for (i = DCB_FEATCFG_ATTR_ALL + 1; i <= DCB_FEATCFG_ATTR_MAX; 12725b7f7626SShmulik Ravid i++) 12731eb4c977SDavid S. Miller if (!ops->getfeatcfg(netdev, i, &value) && 12741eb4c977SDavid S. Miller nla_put_u8(skb, i, value)) 12751eb4c977SDavid S. Miller goto nla_put_failure; 12765b7f7626SShmulik Ravid 12775b7f7626SShmulik Ravid nla_nest_end(skb, feat); 12785b7f7626SShmulik Ravid } 12795b7f7626SShmulik Ravid 12805b7f7626SShmulik Ravid /* peer info if available */ 12815b7f7626SShmulik Ravid if (ops->cee_peer_getpg) { 12825b7f7626SShmulik Ravid struct cee_pg pg; 12835b7f7626SShmulik Ravid err = ops->cee_peer_getpg(netdev, &pg); 12841eb4c977SDavid S. Miller if (!err && 12851eb4c977SDavid S. Miller nla_put(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg)) 12861eb4c977SDavid S. Miller goto nla_put_failure; 12875b7f7626SShmulik Ravid } 12885b7f7626SShmulik Ravid 12895b7f7626SShmulik Ravid if (ops->cee_peer_getpfc) { 12905b7f7626SShmulik Ravid struct cee_pfc pfc; 12915b7f7626SShmulik Ravid err = ops->cee_peer_getpfc(netdev, &pfc); 12921eb4c977SDavid S. Miller if (!err && 12931eb4c977SDavid S. Miller nla_put(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc)) 12941eb4c977SDavid S. Miller goto nla_put_failure; 12955b7f7626SShmulik Ravid } 12965b7f7626SShmulik Ravid 12975b7f7626SShmulik Ravid if (ops->peer_getappinfo && ops->peer_getapptable) { 12985b7f7626SShmulik Ravid err = dcbnl_build_peer_app(netdev, skb, 12995b7f7626SShmulik Ravid DCB_ATTR_CEE_PEER_APP_TABLE, 13005b7f7626SShmulik Ravid DCB_ATTR_CEE_PEER_APP_INFO, 13015b7f7626SShmulik Ravid DCB_ATTR_CEE_PEER_APP); 13025b7f7626SShmulik Ravid if (err) 13035b7f7626SShmulik Ravid goto nla_put_failure; 13045b7f7626SShmulik Ravid } 13055b7f7626SShmulik Ravid nla_nest_end(skb, cee); 13065b7f7626SShmulik Ravid 13075b7f7626SShmulik Ravid /* DCBX state */ 13085b7f7626SShmulik Ravid if (dcbx >= 0) { 13095b7f7626SShmulik Ravid err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx); 13105b7f7626SShmulik Ravid if (err) 13115b7f7626SShmulik Ravid goto nla_put_failure; 13125b7f7626SShmulik Ravid } 13135b7f7626SShmulik Ravid return 0; 13145b7f7626SShmulik Ravid 13155b7f7626SShmulik Ravid dcb_unlock: 13165b7f7626SShmulik Ravid spin_unlock(&dcb_lock); 13175b7f7626SShmulik Ravid nla_put_failure: 13185b7f7626SShmulik Ravid return err; 13195b7f7626SShmulik Ravid } 13205b7f7626SShmulik Ravid 13215b7f7626SShmulik Ravid static int dcbnl_notify(struct net_device *dev, int event, int cmd, 132215e47304SEric W. Biederman u32 seq, u32 portid, int dcbx_ver) 1323314b4778SJohn Fastabend { 1324314b4778SJohn Fastabend struct net *net = dev_net(dev); 1325314b4778SJohn Fastabend struct sk_buff *skb; 1326314b4778SJohn Fastabend struct nlmsghdr *nlh; 1327314b4778SJohn Fastabend const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops; 1328314b4778SJohn Fastabend int err; 1329314b4778SJohn Fastabend 1330314b4778SJohn Fastabend if (!ops) 1331314b4778SJohn Fastabend return -EOPNOTSUPP; 1332314b4778SJohn Fastabend 133315e47304SEric W. Biederman skb = dcbnl_newmsg(event, cmd, portid, seq, 0, &nlh); 1334314b4778SJohn Fastabend if (!skb) 1335314b4778SJohn Fastabend return -ENOBUFS; 1336314b4778SJohn Fastabend 13375b7f7626SShmulik Ravid if (dcbx_ver == DCB_CAP_DCBX_VER_IEEE) 1338314b4778SJohn Fastabend err = dcbnl_ieee_fill(skb, dev); 13395b7f7626SShmulik Ravid else 13405b7f7626SShmulik Ravid err = dcbnl_cee_fill(skb, dev); 13415b7f7626SShmulik Ravid 1342314b4778SJohn Fastabend if (err < 0) { 1343314b4778SJohn Fastabend /* Report error to broadcast listeners */ 1344ab6d4707SThomas Graf nlmsg_free(skb); 1345314b4778SJohn Fastabend rtnl_set_sk_err(net, RTNLGRP_DCB, err); 1346314b4778SJohn Fastabend } else { 1347314b4778SJohn Fastabend /* End nlmsg and notify broadcast listeners */ 1348314b4778SJohn Fastabend nlmsg_end(skb, nlh); 1349314b4778SJohn Fastabend rtnl_notify(skb, net, 0, RTNLGRP_DCB, NULL, GFP_KERNEL); 1350314b4778SJohn Fastabend } 1351314b4778SJohn Fastabend 1352314b4778SJohn Fastabend return err; 1353314b4778SJohn Fastabend } 13545b7f7626SShmulik Ravid 13555b7f7626SShmulik Ravid int dcbnl_ieee_notify(struct net_device *dev, int event, int cmd, 135615e47304SEric W. Biederman u32 seq, u32 portid) 13575b7f7626SShmulik Ravid { 135815e47304SEric W. Biederman return dcbnl_notify(dev, event, cmd, seq, portid, DCB_CAP_DCBX_VER_IEEE); 13595b7f7626SShmulik Ravid } 13605b7f7626SShmulik Ravid EXPORT_SYMBOL(dcbnl_ieee_notify); 13615b7f7626SShmulik Ravid 13625b7f7626SShmulik Ravid int dcbnl_cee_notify(struct net_device *dev, int event, int cmd, 136315e47304SEric W. Biederman u32 seq, u32 portid) 13645b7f7626SShmulik Ravid { 136515e47304SEric W. Biederman return dcbnl_notify(dev, event, cmd, seq, portid, DCB_CAP_DCBX_VER_CEE); 13665b7f7626SShmulik Ravid } 13675b7f7626SShmulik Ravid EXPORT_SYMBOL(dcbnl_cee_notify); 1368314b4778SJohn Fastabend 1369314b4778SJohn Fastabend /* Handle IEEE 802.1Qaz SET commands. If any requested operation can not 1370314b4778SJohn Fastabend * be completed the entire msg is aborted and error value is returned. 1371314b4778SJohn Fastabend * No attempt is made to reconcile the case where only part of the 1372314b4778SJohn Fastabend * cmd can be completed. 1373314b4778SJohn Fastabend */ 13747be99413SThomas Graf static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh, 13757be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 1376314b4778SJohn Fastabend { 1377314b4778SJohn Fastabend const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; 1378314b4778SJohn Fastabend struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1]; 13793d1f4869SThomas Graf int err; 1380314b4778SJohn Fastabend 1381314b4778SJohn Fastabend if (!ops) 13823d1f4869SThomas Graf return -EOPNOTSUPP; 1383314b4778SJohn Fastabend 13844003b658SJohn Fastabend if (!tb[DCB_ATTR_IEEE]) 13854003b658SJohn Fastabend return -EINVAL; 13864003b658SJohn Fastabend 1387314b4778SJohn Fastabend err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX, 1388314b4778SJohn Fastabend tb[DCB_ATTR_IEEE], dcbnl_ieee_policy); 1389314b4778SJohn Fastabend if (err) 1390314b4778SJohn Fastabend return err; 1391314b4778SJohn Fastabend 1392314b4778SJohn Fastabend if (ieee[DCB_ATTR_IEEE_ETS] && ops->ieee_setets) { 1393314b4778SJohn Fastabend struct ieee_ets *ets = nla_data(ieee[DCB_ATTR_IEEE_ETS]); 1394314b4778SJohn Fastabend err = ops->ieee_setets(netdev, ets); 1395314b4778SJohn Fastabend if (err) 1396314b4778SJohn Fastabend goto err; 1397314b4778SJohn Fastabend } 1398314b4778SJohn Fastabend 139908f10affSAmir Vadai if (ieee[DCB_ATTR_IEEE_MAXRATE] && ops->ieee_setmaxrate) { 140008f10affSAmir Vadai struct ieee_maxrate *maxrate = 140108f10affSAmir Vadai nla_data(ieee[DCB_ATTR_IEEE_MAXRATE]); 140208f10affSAmir Vadai err = ops->ieee_setmaxrate(netdev, maxrate); 140308f10affSAmir Vadai if (err) 140408f10affSAmir Vadai goto err; 140508f10affSAmir Vadai } 140608f10affSAmir Vadai 1407314b4778SJohn Fastabend if (ieee[DCB_ATTR_IEEE_PFC] && ops->ieee_setpfc) { 1408314b4778SJohn Fastabend struct ieee_pfc *pfc = nla_data(ieee[DCB_ATTR_IEEE_PFC]); 1409314b4778SJohn Fastabend err = ops->ieee_setpfc(netdev, pfc); 1410314b4778SJohn Fastabend if (err) 1411314b4778SJohn Fastabend goto err; 1412314b4778SJohn Fastabend } 1413314b4778SJohn Fastabend 1414314b4778SJohn Fastabend if (ieee[DCB_ATTR_IEEE_APP_TABLE]) { 1415314b4778SJohn Fastabend struct nlattr *attr; 1416314b4778SJohn Fastabend int rem; 1417314b4778SJohn Fastabend 1418314b4778SJohn Fastabend nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) { 1419314b4778SJohn Fastabend struct dcb_app *app_data; 1420314b4778SJohn Fastabend if (nla_type(attr) != DCB_ATTR_IEEE_APP) 1421314b4778SJohn Fastabend continue; 1422314b4778SJohn Fastabend app_data = nla_data(attr); 1423314b4778SJohn Fastabend if (ops->ieee_setapp) 1424314b4778SJohn Fastabend err = ops->ieee_setapp(netdev, app_data); 1425314b4778SJohn Fastabend else 1426b6db2174SJohn Fastabend err = dcb_ieee_setapp(netdev, app_data); 1427314b4778SJohn Fastabend if (err) 1428314b4778SJohn Fastabend goto err; 1429314b4778SJohn Fastabend } 1430314b4778SJohn Fastabend } 1431314b4778SJohn Fastabend 1432314b4778SJohn Fastabend err: 14337be99413SThomas Graf err = nla_put_u8(skb, DCB_ATTR_IEEE, err); 14345b7f7626SShmulik Ravid dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_SET, seq, 0); 1435314b4778SJohn Fastabend return err; 1436314b4778SJohn Fastabend } 1437314b4778SJohn Fastabend 14387be99413SThomas Graf static int dcbnl_ieee_get(struct net_device *netdev, struct nlmsghdr *nlh, 14397be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 1440314b4778SJohn Fastabend { 1441314b4778SJohn Fastabend const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; 1442314b4778SJohn Fastabend 1443314b4778SJohn Fastabend if (!ops) 1444314b4778SJohn Fastabend return -EOPNOTSUPP; 1445314b4778SJohn Fastabend 14467be99413SThomas Graf return dcbnl_ieee_fill(skb, netdev); 1447314b4778SJohn Fastabend } 1448314b4778SJohn Fastabend 14497be99413SThomas Graf static int dcbnl_ieee_del(struct net_device *netdev, struct nlmsghdr *nlh, 14507be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 1451f9ae7e4bSJohn Fastabend { 1452f9ae7e4bSJohn Fastabend const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; 1453f9ae7e4bSJohn Fastabend struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1]; 14543d1f4869SThomas Graf int err; 1455f9ae7e4bSJohn Fastabend 1456f9ae7e4bSJohn Fastabend if (!ops) 1457f9ae7e4bSJohn Fastabend return -EOPNOTSUPP; 1458f9ae7e4bSJohn Fastabend 1459f9ae7e4bSJohn Fastabend if (!tb[DCB_ATTR_IEEE]) 1460f9ae7e4bSJohn Fastabend return -EINVAL; 1461f9ae7e4bSJohn Fastabend 1462f9ae7e4bSJohn Fastabend err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX, 1463f9ae7e4bSJohn Fastabend tb[DCB_ATTR_IEEE], dcbnl_ieee_policy); 1464f9ae7e4bSJohn Fastabend if (err) 1465f9ae7e4bSJohn Fastabend return err; 1466f9ae7e4bSJohn Fastabend 1467f9ae7e4bSJohn Fastabend if (ieee[DCB_ATTR_IEEE_APP_TABLE]) { 1468f9ae7e4bSJohn Fastabend struct nlattr *attr; 1469f9ae7e4bSJohn Fastabend int rem; 1470f9ae7e4bSJohn Fastabend 1471f9ae7e4bSJohn Fastabend nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) { 1472f9ae7e4bSJohn Fastabend struct dcb_app *app_data; 1473f9ae7e4bSJohn Fastabend 1474f9ae7e4bSJohn Fastabend if (nla_type(attr) != DCB_ATTR_IEEE_APP) 1475f9ae7e4bSJohn Fastabend continue; 1476f9ae7e4bSJohn Fastabend app_data = nla_data(attr); 1477f9ae7e4bSJohn Fastabend if (ops->ieee_delapp) 1478f9ae7e4bSJohn Fastabend err = ops->ieee_delapp(netdev, app_data); 1479f9ae7e4bSJohn Fastabend else 1480f9ae7e4bSJohn Fastabend err = dcb_ieee_delapp(netdev, app_data); 1481f9ae7e4bSJohn Fastabend if (err) 1482f9ae7e4bSJohn Fastabend goto err; 1483f9ae7e4bSJohn Fastabend } 1484f9ae7e4bSJohn Fastabend } 1485f9ae7e4bSJohn Fastabend 1486f9ae7e4bSJohn Fastabend err: 14877be99413SThomas Graf err = nla_put_u8(skb, DCB_ATTR_IEEE, err); 14885b7f7626SShmulik Ravid dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_DEL, seq, 0); 1489f9ae7e4bSJohn Fastabend return err; 1490f9ae7e4bSJohn Fastabend } 1491f9ae7e4bSJohn Fastabend 1492f9ae7e4bSJohn Fastabend 14936241b625SShmulik Ravid /* DCBX configuration */ 14947be99413SThomas Graf static int dcbnl_getdcbx(struct net_device *netdev, struct nlmsghdr *nlh, 14957be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 14966241b625SShmulik Ravid { 14976241b625SShmulik Ravid if (!netdev->dcbnl_ops->getdcbx) 14987f891cf1SShmulik Ravid return -EOPNOTSUPP; 14996241b625SShmulik Ravid 15007be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_DCBX, 15017be99413SThomas Graf netdev->dcbnl_ops->getdcbx(netdev)); 15026241b625SShmulik Ravid } 15036241b625SShmulik Ravid 15047be99413SThomas Graf static int dcbnl_setdcbx(struct net_device *netdev, struct nlmsghdr *nlh, 15057be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 15066241b625SShmulik Ravid { 15076241b625SShmulik Ravid u8 value; 15086241b625SShmulik Ravid 15097f891cf1SShmulik Ravid if (!netdev->dcbnl_ops->setdcbx) 15107f891cf1SShmulik Ravid return -EOPNOTSUPP; 15117f891cf1SShmulik Ravid 15127f891cf1SShmulik Ravid if (!tb[DCB_ATTR_DCBX]) 15137f891cf1SShmulik Ravid return -EINVAL; 15146241b625SShmulik Ravid 15156241b625SShmulik Ravid value = nla_get_u8(tb[DCB_ATTR_DCBX]); 15166241b625SShmulik Ravid 15177be99413SThomas Graf return nla_put_u8(skb, DCB_ATTR_DCBX, 15187be99413SThomas Graf netdev->dcbnl_ops->setdcbx(netdev, value)); 15196241b625SShmulik Ravid } 15206241b625SShmulik Ravid 15217be99413SThomas Graf static int dcbnl_getfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh, 15227be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 1523ea45fe4eSShmulik Ravid { 1524ea45fe4eSShmulik Ravid struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1], *nest; 1525ea45fe4eSShmulik Ravid u8 value; 15267f891cf1SShmulik Ravid int ret, i; 1527ea45fe4eSShmulik Ravid int getall = 0; 1528ea45fe4eSShmulik Ravid 15297f891cf1SShmulik Ravid if (!netdev->dcbnl_ops->getfeatcfg) 15307f891cf1SShmulik Ravid return -EOPNOTSUPP; 15317f891cf1SShmulik Ravid 15327f891cf1SShmulik Ravid if (!tb[DCB_ATTR_FEATCFG]) 15337f891cf1SShmulik Ravid return -EINVAL; 1534ea45fe4eSShmulik Ravid 1535ea45fe4eSShmulik Ravid ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG], 1536ea45fe4eSShmulik Ravid dcbnl_featcfg_nest); 15377f891cf1SShmulik Ravid if (ret) 15387be99413SThomas Graf return ret; 1539ea45fe4eSShmulik Ravid 15407be99413SThomas Graf nest = nla_nest_start(skb, DCB_ATTR_FEATCFG); 15417be99413SThomas Graf if (!nest) 15427be99413SThomas Graf return -EMSGSIZE; 1543ea45fe4eSShmulik Ravid 1544ea45fe4eSShmulik Ravid if (data[DCB_FEATCFG_ATTR_ALL]) 1545ea45fe4eSShmulik Ravid getall = 1; 1546ea45fe4eSShmulik Ravid 1547ea45fe4eSShmulik Ravid for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) { 1548ea45fe4eSShmulik Ravid if (!getall && !data[i]) 1549ea45fe4eSShmulik Ravid continue; 1550ea45fe4eSShmulik Ravid 1551ea45fe4eSShmulik Ravid ret = netdev->dcbnl_ops->getfeatcfg(netdev, i, &value); 15527f891cf1SShmulik Ravid if (!ret) 15537be99413SThomas Graf ret = nla_put_u8(skb, i, value); 1554ea45fe4eSShmulik Ravid 1555ea45fe4eSShmulik Ravid if (ret) { 15567be99413SThomas Graf nla_nest_cancel(skb, nest); 15577f891cf1SShmulik Ravid goto nla_put_failure; 1558ea45fe4eSShmulik Ravid } 1559ea45fe4eSShmulik Ravid } 15607be99413SThomas Graf nla_nest_end(skb, nest); 1561ea45fe4eSShmulik Ravid 15627f891cf1SShmulik Ravid nla_put_failure: 1563ea45fe4eSShmulik Ravid return ret; 1564ea45fe4eSShmulik Ravid } 1565ea45fe4eSShmulik Ravid 15667be99413SThomas Graf static int dcbnl_setfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh, 15677be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 1568ea45fe4eSShmulik Ravid { 1569ea45fe4eSShmulik Ravid struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1]; 15707f891cf1SShmulik Ravid int ret, i; 1571ea45fe4eSShmulik Ravid u8 value; 1572ea45fe4eSShmulik Ravid 15737f891cf1SShmulik Ravid if (!netdev->dcbnl_ops->setfeatcfg) 15747f891cf1SShmulik Ravid return -ENOTSUPP; 15757f891cf1SShmulik Ravid 15767f891cf1SShmulik Ravid if (!tb[DCB_ATTR_FEATCFG]) 15777f891cf1SShmulik Ravid return -EINVAL; 1578ea45fe4eSShmulik Ravid 1579ea45fe4eSShmulik Ravid ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG], 1580ea45fe4eSShmulik Ravid dcbnl_featcfg_nest); 1581ea45fe4eSShmulik Ravid 15827f891cf1SShmulik Ravid if (ret) 1583ea45fe4eSShmulik Ravid goto err; 1584ea45fe4eSShmulik Ravid 1585ea45fe4eSShmulik Ravid for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) { 1586ea45fe4eSShmulik Ravid if (data[i] == NULL) 1587ea45fe4eSShmulik Ravid continue; 1588ea45fe4eSShmulik Ravid 1589ea45fe4eSShmulik Ravid value = nla_get_u8(data[i]); 1590ea45fe4eSShmulik Ravid 1591ea45fe4eSShmulik Ravid ret = netdev->dcbnl_ops->setfeatcfg(netdev, i, value); 1592ea45fe4eSShmulik Ravid 1593ea45fe4eSShmulik Ravid if (ret) 15947f891cf1SShmulik Ravid goto err; 1595ea45fe4eSShmulik Ravid } 1596ea45fe4eSShmulik Ravid err: 15977be99413SThomas Graf ret = nla_put_u8(skb, DCB_ATTR_FEATCFG, ret); 15987f891cf1SShmulik Ravid 1599ea45fe4eSShmulik Ravid return ret; 1600ea45fe4eSShmulik Ravid } 1601ea45fe4eSShmulik Ravid 1602dc6ed1dfSShmulik Ravid /* Handle CEE DCBX GET commands. */ 16037be99413SThomas Graf static int dcbnl_cee_get(struct net_device *netdev, struct nlmsghdr *nlh, 16047be99413SThomas Graf u32 seq, struct nlattr **tb, struct sk_buff *skb) 1605dc6ed1dfSShmulik Ravid { 1606dc6ed1dfSShmulik Ravid const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; 1607dc6ed1dfSShmulik Ravid 1608dc6ed1dfSShmulik Ravid if (!ops) 1609dc6ed1dfSShmulik Ravid return -EOPNOTSUPP; 1610dc6ed1dfSShmulik Ravid 16117be99413SThomas Graf return dcbnl_cee_fill(skb, netdev); 1612dc6ed1dfSShmulik Ravid } 1613dc6ed1dfSShmulik Ravid 161433a03aadSThomas Graf struct reply_func { 161533a03aadSThomas Graf /* reply netlink message type */ 161633a03aadSThomas Graf int type; 161733a03aadSThomas Graf 161833a03aadSThomas Graf /* function to fill message contents */ 161933a03aadSThomas Graf int (*cb)(struct net_device *, struct nlmsghdr *, u32, 162033a03aadSThomas Graf struct nlattr **, struct sk_buff *); 162133a03aadSThomas Graf }; 162233a03aadSThomas Graf 162333a03aadSThomas Graf static const struct reply_func reply_funcs[DCB_CMD_MAX+1] = { 16247be99413SThomas Graf [DCB_CMD_GSTATE] = { RTM_GETDCB, dcbnl_getstate }, 16257be99413SThomas Graf [DCB_CMD_SSTATE] = { RTM_SETDCB, dcbnl_setstate }, 16267be99413SThomas Graf [DCB_CMD_PFC_GCFG] = { RTM_GETDCB, dcbnl_getpfccfg }, 16277be99413SThomas Graf [DCB_CMD_PFC_SCFG] = { RTM_SETDCB, dcbnl_setpfccfg }, 16287be99413SThomas Graf [DCB_CMD_GPERM_HWADDR] = { RTM_GETDCB, dcbnl_getperm_hwaddr }, 16297be99413SThomas Graf [DCB_CMD_GCAP] = { RTM_GETDCB, dcbnl_getcap }, 16307be99413SThomas Graf [DCB_CMD_GNUMTCS] = { RTM_GETDCB, dcbnl_getnumtcs }, 16317be99413SThomas Graf [DCB_CMD_SNUMTCS] = { RTM_SETDCB, dcbnl_setnumtcs }, 16327be99413SThomas Graf [DCB_CMD_PFC_GSTATE] = { RTM_GETDCB, dcbnl_getpfcstate }, 16337be99413SThomas Graf [DCB_CMD_PFC_SSTATE] = { RTM_SETDCB, dcbnl_setpfcstate }, 16347be99413SThomas Graf [DCB_CMD_GAPP] = { RTM_GETDCB, dcbnl_getapp }, 16357be99413SThomas Graf [DCB_CMD_SAPP] = { RTM_SETDCB, dcbnl_setapp }, 16367be99413SThomas Graf [DCB_CMD_PGTX_GCFG] = { RTM_GETDCB, dcbnl_pgtx_getcfg }, 16377be99413SThomas Graf [DCB_CMD_PGTX_SCFG] = { RTM_SETDCB, dcbnl_pgtx_setcfg }, 16387be99413SThomas Graf [DCB_CMD_PGRX_GCFG] = { RTM_GETDCB, dcbnl_pgrx_getcfg }, 16397be99413SThomas Graf [DCB_CMD_PGRX_SCFG] = { RTM_SETDCB, dcbnl_pgrx_setcfg }, 16407be99413SThomas Graf [DCB_CMD_SET_ALL] = { RTM_SETDCB, dcbnl_setall }, 16417be99413SThomas Graf [DCB_CMD_BCN_GCFG] = { RTM_GETDCB, dcbnl_bcn_getcfg }, 16427be99413SThomas Graf [DCB_CMD_BCN_SCFG] = { RTM_SETDCB, dcbnl_bcn_setcfg }, 16437be99413SThomas Graf [DCB_CMD_IEEE_GET] = { RTM_GETDCB, dcbnl_ieee_get }, 16447be99413SThomas Graf [DCB_CMD_IEEE_SET] = { RTM_SETDCB, dcbnl_ieee_set }, 16457be99413SThomas Graf [DCB_CMD_IEEE_DEL] = { RTM_SETDCB, dcbnl_ieee_del }, 16467be99413SThomas Graf [DCB_CMD_GDCBX] = { RTM_GETDCB, dcbnl_getdcbx }, 16477be99413SThomas Graf [DCB_CMD_SDCBX] = { RTM_SETDCB, dcbnl_setdcbx }, 16487be99413SThomas Graf [DCB_CMD_GFEATCFG] = { RTM_GETDCB, dcbnl_getfeatcfg }, 16497be99413SThomas Graf [DCB_CMD_SFEATCFG] = { RTM_SETDCB, dcbnl_setfeatcfg }, 16507be99413SThomas Graf [DCB_CMD_CEE_GET] = { RTM_GETDCB, dcbnl_cee_get }, 165133a03aadSThomas Graf }; 165233a03aadSThomas Graf 16532f90b865SAlexander Duyck static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) 16542f90b865SAlexander Duyck { 16552f90b865SAlexander Duyck struct net *net = sock_net(skb->sk); 16562f90b865SAlexander Duyck struct net_device *netdev; 16577a282bc3SThomas Graf struct dcbmsg *dcb = nlmsg_data(nlh); 16582f90b865SAlexander Duyck struct nlattr *tb[DCB_ATTR_MAX + 1]; 165915e47304SEric W. Biederman u32 portid = skb ? NETLINK_CB(skb).portid : 0; 16602f90b865SAlexander Duyck int ret = -EINVAL; 166133a03aadSThomas Graf struct sk_buff *reply_skb; 166239912f9cSThomas Graf struct nlmsghdr *reply_nlh = NULL; 166333a03aadSThomas Graf const struct reply_func *fn; 16642f90b865SAlexander Duyck 1665dfc47ef8SEric W. Biederman if ((nlh->nlmsg_type == RTM_SETDCB) && !capable(CAP_NET_ADMIN)) 1666dfc47ef8SEric W. Biederman return -EPERM; 1667dfc47ef8SEric W. Biederman 16682f90b865SAlexander Duyck ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX, 16692f90b865SAlexander Duyck dcbnl_rtnl_policy); 16702f90b865SAlexander Duyck if (ret < 0) 16712f90b865SAlexander Duyck return ret; 16722f90b865SAlexander Duyck 167333a03aadSThomas Graf if (dcb->cmd > DCB_CMD_MAX) 167433a03aadSThomas Graf return -EINVAL; 167533a03aadSThomas Graf 167633a03aadSThomas Graf /* check if a reply function has been defined for the command */ 167733a03aadSThomas Graf fn = &reply_funcs[dcb->cmd]; 167833a03aadSThomas Graf if (!fn->cb) 167933a03aadSThomas Graf return -EOPNOTSUPP; 168033a03aadSThomas Graf 16812f90b865SAlexander Duyck if (!tb[DCB_ATTR_IFNAME]) 16822f90b865SAlexander Duyck return -EINVAL; 16832f90b865SAlexander Duyck 16847c77ab24SJohn Fastabend netdev = dev_get_by_name(net, nla_data(tb[DCB_ATTR_IFNAME])); 16852f90b865SAlexander Duyck if (!netdev) 16863d1f4869SThomas Graf return -ENODEV; 16872f90b865SAlexander Duyck 16883d1f4869SThomas Graf if (!netdev->dcbnl_ops) { 16893d1f4869SThomas Graf ret = -EOPNOTSUPP; 16903d1f4869SThomas Graf goto out; 16913d1f4869SThomas Graf } 16922f90b865SAlexander Duyck 169315e47304SEric W. Biederman reply_skb = dcbnl_newmsg(fn->type, dcb->cmd, portid, nlh->nlmsg_seq, 169433a03aadSThomas Graf nlh->nlmsg_flags, &reply_nlh); 169533a03aadSThomas Graf if (!reply_skb) { 169633a03aadSThomas Graf ret = -ENOBUFS; 169733a03aadSThomas Graf goto out; 169833a03aadSThomas Graf } 169933a03aadSThomas Graf 170033a03aadSThomas Graf ret = fn->cb(netdev, nlh, nlh->nlmsg_seq, tb, reply_skb); 170133a03aadSThomas Graf if (ret < 0) { 170233a03aadSThomas Graf nlmsg_free(reply_skb); 170333a03aadSThomas Graf goto out; 170433a03aadSThomas Graf } 170533a03aadSThomas Graf 170633a03aadSThomas Graf nlmsg_end(reply_skb, reply_nlh); 170733a03aadSThomas Graf 17087c77ab24SJohn Fastabend ret = rtnl_unicast(reply_skb, net, portid); 17092f90b865SAlexander Duyck out: 17102f90b865SAlexander Duyck dev_put(netdev); 17112f90b865SAlexander Duyck return ret; 17122f90b865SAlexander Duyck } 17132f90b865SAlexander Duyck 1714716b31abSThomas Graf static struct dcb_app_type *dcb_app_lookup(const struct dcb_app *app, 1715716b31abSThomas Graf int ifindex, int prio) 1716716b31abSThomas Graf { 1717716b31abSThomas Graf struct dcb_app_type *itr; 1718716b31abSThomas Graf 1719716b31abSThomas Graf list_for_each_entry(itr, &dcb_app_list, list) { 1720716b31abSThomas Graf if (itr->app.selector == app->selector && 1721716b31abSThomas Graf itr->app.protocol == app->protocol && 1722716b31abSThomas Graf itr->ifindex == ifindex && 1723716b31abSThomas Graf (!prio || itr->app.priority == prio)) 1724716b31abSThomas Graf return itr; 1725716b31abSThomas Graf } 1726716b31abSThomas Graf 1727716b31abSThomas Graf return NULL; 1728716b31abSThomas Graf } 1729716b31abSThomas Graf 17304e4f2f69SThomas Graf static int dcb_app_add(const struct dcb_app *app, int ifindex) 17314e4f2f69SThomas Graf { 17324e4f2f69SThomas Graf struct dcb_app_type *entry; 17334e4f2f69SThomas Graf 17344e4f2f69SThomas Graf entry = kmalloc(sizeof(*entry), GFP_ATOMIC); 17354e4f2f69SThomas Graf if (!entry) 17364e4f2f69SThomas Graf return -ENOMEM; 17374e4f2f69SThomas Graf 17384e4f2f69SThomas Graf memcpy(&entry->app, app, sizeof(*app)); 17394e4f2f69SThomas Graf entry->ifindex = ifindex; 17404e4f2f69SThomas Graf list_add(&entry->list, &dcb_app_list); 17414e4f2f69SThomas Graf 17424e4f2f69SThomas Graf return 0; 17434e4f2f69SThomas Graf } 17444e4f2f69SThomas Graf 17459ab933abSJohn Fastabend /** 17469ab933abSJohn Fastabend * dcb_getapp - retrieve the DCBX application user priority 17479ab933abSJohn Fastabend * 17489ab933abSJohn Fastabend * On success returns a non-zero 802.1p user priority bitmap 17499ab933abSJohn Fastabend * otherwise returns 0 as the invalid user priority bitmap to 17509ab933abSJohn Fastabend * indicate an error. 17519ab933abSJohn Fastabend */ 17529ab933abSJohn Fastabend u8 dcb_getapp(struct net_device *dev, struct dcb_app *app) 17539ab933abSJohn Fastabend { 17549ab933abSJohn Fastabend struct dcb_app_type *itr; 17559ab933abSJohn Fastabend u8 prio = 0; 17569ab933abSJohn Fastabend 17579ab933abSJohn Fastabend spin_lock(&dcb_lock); 1758716b31abSThomas Graf if ((itr = dcb_app_lookup(app, dev->ifindex, 0))) 17599ab933abSJohn Fastabend prio = itr->app.priority; 17609ab933abSJohn Fastabend spin_unlock(&dcb_lock); 17619ab933abSJohn Fastabend 17629ab933abSJohn Fastabend return prio; 17639ab933abSJohn Fastabend } 17649ab933abSJohn Fastabend EXPORT_SYMBOL(dcb_getapp); 17659ab933abSJohn Fastabend 17669ab933abSJohn Fastabend /** 1767b6db2174SJohn Fastabend * dcb_setapp - add CEE dcb application data to app list 17689ab933abSJohn Fastabend * 1769b6db2174SJohn Fastabend * Priority 0 is an invalid priority in CEE spec. This routine 1770b6db2174SJohn Fastabend * removes applications from the app list if the priority is 1771b6db2174SJohn Fastabend * set to zero. 17729ab933abSJohn Fastabend */ 1773ab6baf98SJohn Fastabend int dcb_setapp(struct net_device *dev, struct dcb_app *new) 17749ab933abSJohn Fastabend { 17759ab933abSJohn Fastabend struct dcb_app_type *itr; 17767ec79270SJohn Fastabend struct dcb_app_type event; 17774e4f2f69SThomas Graf int err = 0; 17787ec79270SJohn Fastabend 1779e290ed81SMark Rustad event.ifindex = dev->ifindex; 17807ec79270SJohn Fastabend memcpy(&event.app, new, sizeof(event.app)); 17816bd0e1cbSJohn Fastabend if (dev->dcbnl_ops->getdcbx) 17826bd0e1cbSJohn Fastabend event.dcbx = dev->dcbnl_ops->getdcbx(dev); 17839ab933abSJohn Fastabend 17849ab933abSJohn Fastabend spin_lock(&dcb_lock); 17859ab933abSJohn Fastabend /* Search for existing match and replace */ 1786716b31abSThomas Graf if ((itr = dcb_app_lookup(new, dev->ifindex, 0))) { 17879ab933abSJohn Fastabend if (new->priority) 17889ab933abSJohn Fastabend itr->app.priority = new->priority; 17899ab933abSJohn Fastabend else { 17909ab933abSJohn Fastabend list_del(&itr->list); 17919ab933abSJohn Fastabend kfree(itr); 17929ab933abSJohn Fastabend } 17939ab933abSJohn Fastabend goto out; 17949ab933abSJohn Fastabend } 17959ab933abSJohn Fastabend /* App type does not exist add new application type */ 17964e4f2f69SThomas Graf if (new->priority) 17974e4f2f69SThomas Graf err = dcb_app_add(new, dev->ifindex); 17989ab933abSJohn Fastabend out: 17999ab933abSJohn Fastabend spin_unlock(&dcb_lock); 18004e4f2f69SThomas Graf if (!err) 18017ec79270SJohn Fastabend call_dcbevent_notifiers(DCB_APP_EVENT, &event); 18024e4f2f69SThomas Graf return err; 18039ab933abSJohn Fastabend } 18049ab933abSJohn Fastabend EXPORT_SYMBOL(dcb_setapp); 18059ab933abSJohn Fastabend 1806b6db2174SJohn Fastabend /** 1807a364c8cfSJohn Fastabend * dcb_ieee_getapp_mask - retrieve the IEEE DCB application priority 1808a364c8cfSJohn Fastabend * 1809a364c8cfSJohn Fastabend * Helper routine which on success returns a non-zero 802.1Qaz user 1810a364c8cfSJohn Fastabend * priority bitmap otherwise returns 0 to indicate the dcb_app was 1811a364c8cfSJohn Fastabend * not found in APP list. 1812a364c8cfSJohn Fastabend */ 1813a364c8cfSJohn Fastabend u8 dcb_ieee_getapp_mask(struct net_device *dev, struct dcb_app *app) 1814a364c8cfSJohn Fastabend { 1815a364c8cfSJohn Fastabend struct dcb_app_type *itr; 1816a364c8cfSJohn Fastabend u8 prio = 0; 1817a364c8cfSJohn Fastabend 1818a364c8cfSJohn Fastabend spin_lock(&dcb_lock); 1819716b31abSThomas Graf if ((itr = dcb_app_lookup(app, dev->ifindex, 0))) 1820a364c8cfSJohn Fastabend prio |= 1 << itr->app.priority; 1821a364c8cfSJohn Fastabend spin_unlock(&dcb_lock); 1822a364c8cfSJohn Fastabend 1823a364c8cfSJohn Fastabend return prio; 1824a364c8cfSJohn Fastabend } 1825a364c8cfSJohn Fastabend EXPORT_SYMBOL(dcb_ieee_getapp_mask); 1826a364c8cfSJohn Fastabend 1827a364c8cfSJohn Fastabend /** 1828b6db2174SJohn Fastabend * dcb_ieee_setapp - add IEEE dcb application data to app list 1829b6db2174SJohn Fastabend * 1830b6db2174SJohn Fastabend * This adds Application data to the list. Multiple application 1831b6db2174SJohn Fastabend * entries may exists for the same selector and protocol as long 1832b6db2174SJohn Fastabend * as the priorities are different. 1833b6db2174SJohn Fastabend */ 1834b6db2174SJohn Fastabend int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new) 1835b6db2174SJohn Fastabend { 1836b6db2174SJohn Fastabend struct dcb_app_type event; 1837b6db2174SJohn Fastabend int err = 0; 1838b6db2174SJohn Fastabend 1839e290ed81SMark Rustad event.ifindex = dev->ifindex; 1840b6db2174SJohn Fastabend memcpy(&event.app, new, sizeof(event.app)); 18416bd0e1cbSJohn Fastabend if (dev->dcbnl_ops->getdcbx) 18426bd0e1cbSJohn Fastabend event.dcbx = dev->dcbnl_ops->getdcbx(dev); 1843b6db2174SJohn Fastabend 1844b6db2174SJohn Fastabend spin_lock(&dcb_lock); 1845b6db2174SJohn Fastabend /* Search for existing match and abort if found */ 1846716b31abSThomas Graf if (dcb_app_lookup(new, dev->ifindex, new->priority)) { 1847b6db2174SJohn Fastabend err = -EEXIST; 1848b6db2174SJohn Fastabend goto out; 1849b6db2174SJohn Fastabend } 1850b6db2174SJohn Fastabend 18514e4f2f69SThomas Graf err = dcb_app_add(new, dev->ifindex); 1852b6db2174SJohn Fastabend out: 1853b6db2174SJohn Fastabend spin_unlock(&dcb_lock); 1854b6db2174SJohn Fastabend if (!err) 1855b6db2174SJohn Fastabend call_dcbevent_notifiers(DCB_APP_EVENT, &event); 1856b6db2174SJohn Fastabend return err; 1857b6db2174SJohn Fastabend } 1858b6db2174SJohn Fastabend EXPORT_SYMBOL(dcb_ieee_setapp); 1859b6db2174SJohn Fastabend 1860f9ae7e4bSJohn Fastabend /** 1861f9ae7e4bSJohn Fastabend * dcb_ieee_delapp - delete IEEE dcb application data from list 1862f9ae7e4bSJohn Fastabend * 1863f9ae7e4bSJohn Fastabend * This removes a matching APP data from the APP list 1864f9ae7e4bSJohn Fastabend */ 1865f9ae7e4bSJohn Fastabend int dcb_ieee_delapp(struct net_device *dev, struct dcb_app *del) 1866f9ae7e4bSJohn Fastabend { 1867f9ae7e4bSJohn Fastabend struct dcb_app_type *itr; 1868f9ae7e4bSJohn Fastabend struct dcb_app_type event; 1869f9ae7e4bSJohn Fastabend int err = -ENOENT; 1870f9ae7e4bSJohn Fastabend 1871e290ed81SMark Rustad event.ifindex = dev->ifindex; 1872f9ae7e4bSJohn Fastabend memcpy(&event.app, del, sizeof(event.app)); 18736bd0e1cbSJohn Fastabend if (dev->dcbnl_ops->getdcbx) 18746bd0e1cbSJohn Fastabend event.dcbx = dev->dcbnl_ops->getdcbx(dev); 1875f9ae7e4bSJohn Fastabend 1876f9ae7e4bSJohn Fastabend spin_lock(&dcb_lock); 1877f9ae7e4bSJohn Fastabend /* Search for existing match and remove it. */ 1878716b31abSThomas Graf if ((itr = dcb_app_lookup(del, dev->ifindex, del->priority))) { 1879f9ae7e4bSJohn Fastabend list_del(&itr->list); 1880f9ae7e4bSJohn Fastabend kfree(itr); 1881f9ae7e4bSJohn Fastabend err = 0; 1882f9ae7e4bSJohn Fastabend } 1883f9ae7e4bSJohn Fastabend 1884f9ae7e4bSJohn Fastabend spin_unlock(&dcb_lock); 1885f9ae7e4bSJohn Fastabend if (!err) 1886f9ae7e4bSJohn Fastabend call_dcbevent_notifiers(DCB_APP_EVENT, &event); 1887f9ae7e4bSJohn Fastabend return err; 1888f9ae7e4bSJohn Fastabend } 1889f9ae7e4bSJohn Fastabend EXPORT_SYMBOL(dcb_ieee_delapp); 1890f9ae7e4bSJohn Fastabend 18917c14c3f1SShmulik Ravid static void dcb_flushapp(void) 18929ab933abSJohn Fastabend { 18939ab933abSJohn Fastabend struct dcb_app_type *app; 18942a8fe003SDan Carpenter struct dcb_app_type *tmp; 18959ab933abSJohn Fastabend 18969ab933abSJohn Fastabend spin_lock(&dcb_lock); 18972a8fe003SDan Carpenter list_for_each_entry_safe(app, tmp, &dcb_app_list, list) { 18989ab933abSJohn Fastabend list_del(&app->list); 18999ab933abSJohn Fastabend kfree(app); 19009ab933abSJohn Fastabend } 19019ab933abSJohn Fastabend spin_unlock(&dcb_lock); 19029ab933abSJohn Fastabend } 19039ab933abSJohn Fastabend 19042f90b865SAlexander Duyck static int __init dcbnl_init(void) 19052f90b865SAlexander Duyck { 19069ab933abSJohn Fastabend INIT_LIST_HEAD(&dcb_app_list); 19079ab933abSJohn Fastabend 1908c7ac8679SGreg Rose rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL, NULL); 1909c7ac8679SGreg Rose rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL, NULL); 19102f90b865SAlexander Duyck 19112f90b865SAlexander Duyck return 0; 19122f90b865SAlexander Duyck } 19132f90b865SAlexander Duyck module_init(dcbnl_init); 19142f90b865SAlexander Duyck 19152f90b865SAlexander Duyck static void __exit dcbnl_exit(void) 19162f90b865SAlexander Duyck { 19172f90b865SAlexander Duyck rtnl_unregister(PF_UNSPEC, RTM_GETDCB); 19182f90b865SAlexander Duyck rtnl_unregister(PF_UNSPEC, RTM_SETDCB); 19199ab933abSJohn Fastabend dcb_flushapp(); 19202f90b865SAlexander Duyck } 19212f90b865SAlexander Duyck module_exit(dcbnl_exit); 1922