Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1 | /* |
Mark Rustad | 698e1d2 | 2011-03-14 09:01:02 +0000 | [diff] [blame] | 2 | * Copyright (c) 2008-2011, Intel Corporation. |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
Jeff Kirsher | c057b19 | 2013-12-06 09:13:44 -0800 | [diff] [blame] | 14 | * this program; if not, see <http://www.gnu.org/licenses/>. |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 15 | * |
Paul Gortmaker | 36b9ad80 | 2015-10-07 17:27:44 -0400 | [diff] [blame] | 16 | * Description: Data Center Bridging netlink interface |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 17 | * Author: Lucy Liu <lucy.liu@intel.com> |
| 18 | */ |
| 19 | |
| 20 | #include <linux/netdevice.h> |
| 21 | #include <linux/netlink.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 23 | #include <net/netlink.h> |
| 24 | #include <net/rtnetlink.h> |
| 25 | #include <linux/dcbnl.h> |
John Fastabend | 96b9968 | 2010-12-30 09:26:37 +0000 | [diff] [blame] | 26 | #include <net/dcbevent.h> |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 27 | #include <linux/rtnetlink.h> |
Paul Gortmaker | 36b9ad80 | 2015-10-07 17:27:44 -0400 | [diff] [blame] | 28 | #include <linux/init.h> |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 29 | #include <net/sock.h> |
| 30 | |
Ben Hutchings | ae86b9e | 2012-07-10 10:55:35 +0000 | [diff] [blame] | 31 | /* Data Center Bridging (DCB) is a collection of Ethernet enhancements |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 32 | * intended to allow network traffic with differing requirements |
| 33 | * (highly reliable, no drops vs. best effort vs. low latency) to operate |
| 34 | * and co-exist on Ethernet. Current DCB features are: |
| 35 | * |
| 36 | * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a |
| 37 | * framework for assigning bandwidth guarantees to traffic classes. |
| 38 | * |
| 39 | * Priority-based Flow Control (PFC) - provides a flow control mechanism which |
| 40 | * can work independently for each 802.1p priority. |
| 41 | * |
| 42 | * Congestion Notification - provides a mechanism for end-to-end congestion |
| 43 | * control for protocols which do not have built-in congestion management. |
| 44 | * |
| 45 | * More information about the emerging standards for these Ethernet features |
| 46 | * can be found at: http://www.ieee802.org/1/pages/dcbridges.html |
| 47 | * |
| 48 | * This file implements an rtnetlink interface to allow configuration of DCB |
| 49 | * features for capable devices. |
| 50 | */ |
| 51 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 52 | /**************** DCB attribute policies *************************************/ |
| 53 | |
| 54 | /* DCB netlink attributes policy */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 55 | static const struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = { |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 56 | [DCB_ATTR_IFNAME] = {.type = NLA_NUL_STRING, .len = IFNAMSIZ - 1}, |
| 57 | [DCB_ATTR_STATE] = {.type = NLA_U8}, |
| 58 | [DCB_ATTR_PFC_CFG] = {.type = NLA_NESTED}, |
| 59 | [DCB_ATTR_PG_CFG] = {.type = NLA_NESTED}, |
| 60 | [DCB_ATTR_SET_ALL] = {.type = NLA_U8}, |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 61 | [DCB_ATTR_PERM_HWADDR] = {.type = NLA_FLAG}, |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 62 | [DCB_ATTR_CAP] = {.type = NLA_NESTED}, |
| 63 | [DCB_ATTR_PFC_STATE] = {.type = NLA_U8}, |
| 64 | [DCB_ATTR_BCN] = {.type = NLA_NESTED}, |
Yi Zou | 6fa382a | 2009-08-31 12:33:20 +0000 | [diff] [blame] | 65 | [DCB_ATTR_APP] = {.type = NLA_NESTED}, |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 66 | [DCB_ATTR_IEEE] = {.type = NLA_NESTED}, |
Shmulik Ravid | 6241b62 | 2010-12-30 06:26:48 +0000 | [diff] [blame] | 67 | [DCB_ATTR_DCBX] = {.type = NLA_U8}, |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 68 | [DCB_ATTR_FEATCFG] = {.type = NLA_NESTED}, |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | /* DCB priority flow control to User Priority nested attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 72 | static const struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 73 | [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8}, |
| 74 | [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8}, |
| 75 | [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8}, |
| 76 | [DCB_PFC_UP_ATTR_3] = {.type = NLA_U8}, |
| 77 | [DCB_PFC_UP_ATTR_4] = {.type = NLA_U8}, |
| 78 | [DCB_PFC_UP_ATTR_5] = {.type = NLA_U8}, |
| 79 | [DCB_PFC_UP_ATTR_6] = {.type = NLA_U8}, |
| 80 | [DCB_PFC_UP_ATTR_7] = {.type = NLA_U8}, |
| 81 | [DCB_PFC_UP_ATTR_ALL] = {.type = NLA_FLAG}, |
| 82 | }; |
| 83 | |
| 84 | /* DCB priority grouping nested attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 85 | static const struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 86 | [DCB_PG_ATTR_TC_0] = {.type = NLA_NESTED}, |
| 87 | [DCB_PG_ATTR_TC_1] = {.type = NLA_NESTED}, |
| 88 | [DCB_PG_ATTR_TC_2] = {.type = NLA_NESTED}, |
| 89 | [DCB_PG_ATTR_TC_3] = {.type = NLA_NESTED}, |
| 90 | [DCB_PG_ATTR_TC_4] = {.type = NLA_NESTED}, |
| 91 | [DCB_PG_ATTR_TC_5] = {.type = NLA_NESTED}, |
| 92 | [DCB_PG_ATTR_TC_6] = {.type = NLA_NESTED}, |
| 93 | [DCB_PG_ATTR_TC_7] = {.type = NLA_NESTED}, |
| 94 | [DCB_PG_ATTR_TC_ALL] = {.type = NLA_NESTED}, |
| 95 | [DCB_PG_ATTR_BW_ID_0] = {.type = NLA_U8}, |
| 96 | [DCB_PG_ATTR_BW_ID_1] = {.type = NLA_U8}, |
| 97 | [DCB_PG_ATTR_BW_ID_2] = {.type = NLA_U8}, |
| 98 | [DCB_PG_ATTR_BW_ID_3] = {.type = NLA_U8}, |
| 99 | [DCB_PG_ATTR_BW_ID_4] = {.type = NLA_U8}, |
| 100 | [DCB_PG_ATTR_BW_ID_5] = {.type = NLA_U8}, |
| 101 | [DCB_PG_ATTR_BW_ID_6] = {.type = NLA_U8}, |
| 102 | [DCB_PG_ATTR_BW_ID_7] = {.type = NLA_U8}, |
| 103 | [DCB_PG_ATTR_BW_ID_ALL] = {.type = NLA_FLAG}, |
| 104 | }; |
| 105 | |
| 106 | /* DCB traffic class nested attributes. */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 107 | static const struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 108 | [DCB_TC_ATTR_PARAM_PGID] = {.type = NLA_U8}, |
| 109 | [DCB_TC_ATTR_PARAM_UP_MAPPING] = {.type = NLA_U8}, |
| 110 | [DCB_TC_ATTR_PARAM_STRICT_PRIO] = {.type = NLA_U8}, |
| 111 | [DCB_TC_ATTR_PARAM_BW_PCT] = {.type = NLA_U8}, |
| 112 | [DCB_TC_ATTR_PARAM_ALL] = {.type = NLA_FLAG}, |
| 113 | }; |
| 114 | |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 115 | /* DCB capabilities nested attributes. */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 116 | static const struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = { |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 117 | [DCB_CAP_ATTR_ALL] = {.type = NLA_FLAG}, |
| 118 | [DCB_CAP_ATTR_PG] = {.type = NLA_U8}, |
| 119 | [DCB_CAP_ATTR_PFC] = {.type = NLA_U8}, |
| 120 | [DCB_CAP_ATTR_UP2TC] = {.type = NLA_U8}, |
| 121 | [DCB_CAP_ATTR_PG_TCS] = {.type = NLA_U8}, |
| 122 | [DCB_CAP_ATTR_PFC_TCS] = {.type = NLA_U8}, |
| 123 | [DCB_CAP_ATTR_GSP] = {.type = NLA_U8}, |
| 124 | [DCB_CAP_ATTR_BCN] = {.type = NLA_U8}, |
Shmulik Ravid | 6241b62 | 2010-12-30 06:26:48 +0000 | [diff] [blame] | 125 | [DCB_CAP_ATTR_DCBX] = {.type = NLA_U8}, |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 126 | }; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 127 | |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 128 | /* DCB capabilities nested attributes. */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 129 | static const struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = { |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 130 | [DCB_NUMTCS_ATTR_ALL] = {.type = NLA_FLAG}, |
| 131 | [DCB_NUMTCS_ATTR_PG] = {.type = NLA_U8}, |
| 132 | [DCB_NUMTCS_ATTR_PFC] = {.type = NLA_U8}, |
| 133 | }; |
| 134 | |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 135 | /* DCB BCN nested attributes. */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 136 | static const struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = { |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 137 | [DCB_BCN_ATTR_RP_0] = {.type = NLA_U8}, |
| 138 | [DCB_BCN_ATTR_RP_1] = {.type = NLA_U8}, |
| 139 | [DCB_BCN_ATTR_RP_2] = {.type = NLA_U8}, |
| 140 | [DCB_BCN_ATTR_RP_3] = {.type = NLA_U8}, |
| 141 | [DCB_BCN_ATTR_RP_4] = {.type = NLA_U8}, |
| 142 | [DCB_BCN_ATTR_RP_5] = {.type = NLA_U8}, |
| 143 | [DCB_BCN_ATTR_RP_6] = {.type = NLA_U8}, |
| 144 | [DCB_BCN_ATTR_RP_7] = {.type = NLA_U8}, |
| 145 | [DCB_BCN_ATTR_RP_ALL] = {.type = NLA_FLAG}, |
Don Skidmore | f4314e8 | 2008-12-21 20:10:29 -0800 | [diff] [blame] | 146 | [DCB_BCN_ATTR_BCNA_0] = {.type = NLA_U32}, |
| 147 | [DCB_BCN_ATTR_BCNA_1] = {.type = NLA_U32}, |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 148 | [DCB_BCN_ATTR_ALPHA] = {.type = NLA_U32}, |
| 149 | [DCB_BCN_ATTR_BETA] = {.type = NLA_U32}, |
| 150 | [DCB_BCN_ATTR_GD] = {.type = NLA_U32}, |
| 151 | [DCB_BCN_ATTR_GI] = {.type = NLA_U32}, |
| 152 | [DCB_BCN_ATTR_TMAX] = {.type = NLA_U32}, |
| 153 | [DCB_BCN_ATTR_TD] = {.type = NLA_U32}, |
| 154 | [DCB_BCN_ATTR_RMIN] = {.type = NLA_U32}, |
| 155 | [DCB_BCN_ATTR_W] = {.type = NLA_U32}, |
| 156 | [DCB_BCN_ATTR_RD] = {.type = NLA_U32}, |
| 157 | [DCB_BCN_ATTR_RU] = {.type = NLA_U32}, |
| 158 | [DCB_BCN_ATTR_WRTT] = {.type = NLA_U32}, |
| 159 | [DCB_BCN_ATTR_RI] = {.type = NLA_U32}, |
| 160 | [DCB_BCN_ATTR_C] = {.type = NLA_U32}, |
| 161 | [DCB_BCN_ATTR_ALL] = {.type = NLA_FLAG}, |
| 162 | }; |
| 163 | |
Yi Zou | 6fa382a | 2009-08-31 12:33:20 +0000 | [diff] [blame] | 164 | /* DCB APP nested attributes. */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 165 | static const struct nla_policy dcbnl_app_nest[DCB_APP_ATTR_MAX + 1] = { |
Yi Zou | 6fa382a | 2009-08-31 12:33:20 +0000 | [diff] [blame] | 166 | [DCB_APP_ATTR_IDTYPE] = {.type = NLA_U8}, |
| 167 | [DCB_APP_ATTR_ID] = {.type = NLA_U16}, |
| 168 | [DCB_APP_ATTR_PRIORITY] = {.type = NLA_U8}, |
| 169 | }; |
| 170 | |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 171 | /* IEEE 802.1Qaz nested attributes. */ |
| 172 | static const struct nla_policy dcbnl_ieee_policy[DCB_ATTR_IEEE_MAX + 1] = { |
| 173 | [DCB_ATTR_IEEE_ETS] = {.len = sizeof(struct ieee_ets)}, |
| 174 | [DCB_ATTR_IEEE_PFC] = {.len = sizeof(struct ieee_pfc)}, |
| 175 | [DCB_ATTR_IEEE_APP_TABLE] = {.type = NLA_NESTED}, |
Amir Vadai | 08f10af | 2012-04-04 21:33:30 +0000 | [diff] [blame] | 176 | [DCB_ATTR_IEEE_MAXRATE] = {.len = sizeof(struct ieee_maxrate)}, |
Shani Michaeli | c9368247 | 2015-03-05 20:16:11 +0200 | [diff] [blame] | 177 | [DCB_ATTR_IEEE_QCN] = {.len = sizeof(struct ieee_qcn)}, |
| 178 | [DCB_ATTR_IEEE_QCN_STATS] = {.len = sizeof(struct ieee_qcn_stats)}, |
Huy Nguyen | e549f6f | 2018-02-22 11:57:10 -0600 | [diff] [blame] | 179 | [DCB_ATTR_DCB_BUFFER] = {.len = sizeof(struct dcbnl_buffer)}, |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 180 | }; |
| 181 | |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 182 | /* DCB number of traffic classes nested attributes. */ |
| 183 | static const struct nla_policy dcbnl_featcfg_nest[DCB_FEATCFG_ATTR_MAX + 1] = { |
| 184 | [DCB_FEATCFG_ATTR_ALL] = {.type = NLA_FLAG}, |
| 185 | [DCB_FEATCFG_ATTR_PG] = {.type = NLA_U8}, |
| 186 | [DCB_FEATCFG_ATTR_PFC] = {.type = NLA_U8}, |
| 187 | [DCB_FEATCFG_ATTR_APP] = {.type = NLA_U8}, |
| 188 | }; |
| 189 | |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 190 | static LIST_HEAD(dcb_app_list); |
| 191 | static DEFINE_SPINLOCK(dcb_lock); |
| 192 | |
Thomas Graf | 33a03aa | 2012-06-13 02:54:54 +0000 | [diff] [blame] | 193 | static struct sk_buff *dcbnl_newmsg(int type, u8 cmd, u32 port, u32 seq, |
| 194 | u32 flags, struct nlmsghdr **nlhp) |
| 195 | { |
| 196 | struct sk_buff *skb; |
| 197 | struct dcbmsg *dcb; |
| 198 | struct nlmsghdr *nlh; |
| 199 | |
| 200 | skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 201 | if (!skb) |
| 202 | return NULL; |
| 203 | |
| 204 | nlh = nlmsg_put(skb, port, seq, type, sizeof(*dcb), flags); |
Thomas Graf | b3908e2 | 2012-06-13 22:40:15 +0000 | [diff] [blame] | 205 | BUG_ON(!nlh); |
Thomas Graf | 33a03aa | 2012-06-13 02:54:54 +0000 | [diff] [blame] | 206 | |
| 207 | dcb = nlmsg_data(nlh); |
| 208 | dcb->dcb_family = AF_UNSPEC; |
| 209 | dcb->cmd = cmd; |
| 210 | dcb->dcb_pad = 0; |
| 211 | |
| 212 | if (nlhp) |
| 213 | *nlhp = nlh; |
| 214 | |
| 215 | return skb; |
| 216 | } |
| 217 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 218 | static int dcbnl_getstate(struct net_device *netdev, struct nlmsghdr *nlh, |
| 219 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 220 | { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 221 | /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */ |
| 222 | if (!netdev->dcbnl_ops->getstate) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 223 | return -EOPNOTSUPP; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 224 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 225 | return nla_put_u8(skb, DCB_ATTR_STATE, |
| 226 | netdev->dcbnl_ops->getstate(netdev)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 227 | } |
| 228 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 229 | static int dcbnl_getpfccfg(struct net_device *netdev, struct nlmsghdr *nlh, |
| 230 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 231 | { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 232 | struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1], *nest; |
| 233 | u8 value; |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 234 | int ret; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 235 | int i; |
| 236 | int getall = 0; |
| 237 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 238 | if (!tb[DCB_ATTR_PFC_CFG]) |
| 239 | return -EINVAL; |
| 240 | |
| 241 | if (!netdev->dcbnl_ops->getpfccfg) |
| 242 | return -EOPNOTSUPP; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 243 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 244 | ret = nla_parse_nested_deprecated(data, DCB_PFC_UP_ATTR_MAX, |
| 245 | tb[DCB_ATTR_PFC_CFG], |
| 246 | dcbnl_pfc_up_nest, NULL); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 247 | if (ret) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 248 | return ret; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 249 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 250 | nest = nla_nest_start_noflag(skb, DCB_ATTR_PFC_CFG); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 251 | if (!nest) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 252 | return -EMSGSIZE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 253 | |
| 254 | if (data[DCB_PFC_UP_ATTR_ALL]) |
| 255 | getall = 1; |
| 256 | |
| 257 | for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) { |
| 258 | if (!getall && !data[i]) |
| 259 | continue; |
| 260 | |
| 261 | netdev->dcbnl_ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0, |
| 262 | &value); |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 263 | ret = nla_put_u8(skb, i, value); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 264 | if (ret) { |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 265 | nla_nest_cancel(skb, nest); |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 266 | return ret; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 267 | } |
| 268 | } |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 269 | nla_nest_end(skb, nest); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 270 | |
| 271 | return 0; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 272 | } |
| 273 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 274 | static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlmsghdr *nlh, |
| 275 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 276 | { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 277 | u8 perm_addr[MAX_ADDR_LEN]; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 278 | |
| 279 | if (!netdev->dcbnl_ops->getpermhwaddr) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 280 | return -EOPNOTSUPP; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 281 | |
Mathias Krause | 29cd8ae | 2013-03-09 05:52:21 +0000 | [diff] [blame] | 282 | memset(perm_addr, 0, sizeof(perm_addr)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 283 | netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr); |
| 284 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 285 | return nla_put(skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr), perm_addr); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 286 | } |
| 287 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 288 | static int dcbnl_getcap(struct net_device *netdev, struct nlmsghdr *nlh, |
| 289 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 290 | { |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 291 | struct nlattr *data[DCB_CAP_ATTR_MAX + 1], *nest; |
| 292 | u8 value; |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 293 | int ret; |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 294 | int i; |
| 295 | int getall = 0; |
| 296 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 297 | if (!tb[DCB_ATTR_CAP]) |
| 298 | return -EINVAL; |
| 299 | |
| 300 | if (!netdev->dcbnl_ops->getcap) |
| 301 | return -EOPNOTSUPP; |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 302 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 303 | ret = nla_parse_nested_deprecated(data, DCB_CAP_ATTR_MAX, |
| 304 | tb[DCB_ATTR_CAP], dcbnl_cap_nest, |
| 305 | NULL); |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 306 | if (ret) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 307 | return ret; |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 308 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 309 | nest = nla_nest_start_noflag(skb, DCB_ATTR_CAP); |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 310 | if (!nest) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 311 | return -EMSGSIZE; |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 312 | |
| 313 | if (data[DCB_CAP_ATTR_ALL]) |
| 314 | getall = 1; |
| 315 | |
| 316 | for (i = DCB_CAP_ATTR_ALL+1; i <= DCB_CAP_ATTR_MAX; i++) { |
| 317 | if (!getall && !data[i]) |
| 318 | continue; |
| 319 | |
| 320 | if (!netdev->dcbnl_ops->getcap(netdev, i, &value)) { |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 321 | ret = nla_put_u8(skb, i, value); |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 322 | if (ret) { |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 323 | nla_nest_cancel(skb, nest); |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 324 | return ret; |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | } |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 328 | nla_nest_end(skb, nest); |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 329 | |
| 330 | return 0; |
Alexander Duyck | 4613218 | 2008-11-20 21:05:08 -0800 | [diff] [blame] | 331 | } |
| 332 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 333 | static int dcbnl_getnumtcs(struct net_device *netdev, struct nlmsghdr *nlh, |
| 334 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 335 | { |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 336 | struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1], *nest; |
| 337 | u8 value; |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 338 | int ret; |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 339 | int i; |
| 340 | int getall = 0; |
| 341 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 342 | if (!tb[DCB_ATTR_NUMTCS]) |
| 343 | return -EINVAL; |
| 344 | |
| 345 | if (!netdev->dcbnl_ops->getnumtcs) |
| 346 | return -EOPNOTSUPP; |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 347 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 348 | ret = nla_parse_nested_deprecated(data, DCB_NUMTCS_ATTR_MAX, |
| 349 | tb[DCB_ATTR_NUMTCS], |
| 350 | dcbnl_numtcs_nest, NULL); |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 351 | if (ret) |
| 352 | return ret; |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 353 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 354 | nest = nla_nest_start_noflag(skb, DCB_ATTR_NUMTCS); |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 355 | if (!nest) |
| 356 | return -EMSGSIZE; |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 357 | |
| 358 | if (data[DCB_NUMTCS_ATTR_ALL]) |
| 359 | getall = 1; |
| 360 | |
| 361 | for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) { |
| 362 | if (!getall && !data[i]) |
| 363 | continue; |
| 364 | |
| 365 | ret = netdev->dcbnl_ops->getnumtcs(netdev, i, &value); |
| 366 | if (!ret) { |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 367 | ret = nla_put_u8(skb, i, value); |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 368 | if (ret) { |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 369 | nla_nest_cancel(skb, nest); |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 370 | return ret; |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 371 | } |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 372 | } else |
| 373 | return -EINVAL; |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 374 | } |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 375 | nla_nest_end(skb, nest); |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 376 | |
| 377 | return 0; |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 378 | } |
| 379 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 380 | static int dcbnl_setnumtcs(struct net_device *netdev, struct nlmsghdr *nlh, |
| 381 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 382 | { |
| 383 | struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1]; |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 384 | int ret; |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 385 | u8 value; |
| 386 | int i; |
| 387 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 388 | if (!tb[DCB_ATTR_NUMTCS]) |
| 389 | return -EINVAL; |
| 390 | |
| 391 | if (!netdev->dcbnl_ops->setnumtcs) |
| 392 | return -EOPNOTSUPP; |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 393 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 394 | ret = nla_parse_nested_deprecated(data, DCB_NUMTCS_ATTR_MAX, |
| 395 | tb[DCB_ATTR_NUMTCS], |
| 396 | dcbnl_numtcs_nest, NULL); |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 397 | if (ret) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 398 | return ret; |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 399 | |
| 400 | for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) { |
| 401 | if (data[i] == NULL) |
| 402 | continue; |
| 403 | |
| 404 | value = nla_get_u8(data[i]); |
| 405 | |
| 406 | ret = netdev->dcbnl_ops->setnumtcs(netdev, i, value); |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 407 | if (ret) |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 408 | break; |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 409 | } |
| 410 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 411 | return nla_put_u8(skb, DCB_ATTR_NUMTCS, !!ret); |
Alexander Duyck | 33dbabc | 2008-11-20 21:08:19 -0800 | [diff] [blame] | 412 | } |
| 413 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 414 | static int dcbnl_getpfcstate(struct net_device *netdev, struct nlmsghdr *nlh, |
| 415 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 416 | { |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 417 | if (!netdev->dcbnl_ops->getpfcstate) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 418 | return -EOPNOTSUPP; |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 419 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 420 | return nla_put_u8(skb, DCB_ATTR_PFC_STATE, |
| 421 | netdev->dcbnl_ops->getpfcstate(netdev)); |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 422 | } |
| 423 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 424 | static int dcbnl_setpfcstate(struct net_device *netdev, struct nlmsghdr *nlh, |
| 425 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 426 | { |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 427 | u8 value; |
| 428 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 429 | if (!tb[DCB_ATTR_PFC_STATE]) |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 430 | return -EINVAL; |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 431 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 432 | if (!netdev->dcbnl_ops->setpfcstate) |
| 433 | return -EOPNOTSUPP; |
| 434 | |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 435 | value = nla_get_u8(tb[DCB_ATTR_PFC_STATE]); |
| 436 | |
| 437 | netdev->dcbnl_ops->setpfcstate(netdev, value); |
| 438 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 439 | return nla_put_u8(skb, DCB_ATTR_PFC_STATE, 0); |
Alexander Duyck | 0eb3aa9 | 2008-11-20 21:09:23 -0800 | [diff] [blame] | 440 | } |
| 441 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 442 | static int dcbnl_getapp(struct net_device *netdev, struct nlmsghdr *nlh, |
| 443 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 444 | { |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 445 | struct nlattr *app_nest; |
| 446 | struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1]; |
| 447 | u16 id; |
| 448 | u8 up, idtype; |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 449 | int ret; |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 450 | |
John Fastabend | 3dce38a | 2011-01-21 16:35:18 +0000 | [diff] [blame] | 451 | if (!tb[DCB_ATTR_APP]) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 452 | return -EINVAL; |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 453 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 454 | ret = nla_parse_nested_deprecated(app_tb, DCB_APP_ATTR_MAX, |
| 455 | tb[DCB_ATTR_APP], dcbnl_app_nest, |
| 456 | NULL); |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 457 | if (ret) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 458 | return ret; |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 459 | |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 460 | /* all must be non-null */ |
| 461 | if ((!app_tb[DCB_APP_ATTR_IDTYPE]) || |
| 462 | (!app_tb[DCB_APP_ATTR_ID])) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 463 | return -EINVAL; |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 464 | |
| 465 | /* either by eth type or by socket number */ |
| 466 | idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]); |
| 467 | if ((idtype != DCB_APP_IDTYPE_ETHTYPE) && |
| 468 | (idtype != DCB_APP_IDTYPE_PORTNUM)) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 469 | return -EINVAL; |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 470 | |
| 471 | id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]); |
John Fastabend | 3dce38a | 2011-01-21 16:35:18 +0000 | [diff] [blame] | 472 | |
| 473 | if (netdev->dcbnl_ops->getapp) { |
Anish Bhatt | c265947 | 2014-07-16 22:32:39 -0700 | [diff] [blame] | 474 | ret = netdev->dcbnl_ops->getapp(netdev, idtype, id); |
| 475 | if (ret < 0) |
| 476 | return ret; |
| 477 | else |
| 478 | up = ret; |
John Fastabend | 3dce38a | 2011-01-21 16:35:18 +0000 | [diff] [blame] | 479 | } else { |
| 480 | struct dcb_app app = { |
| 481 | .selector = idtype, |
| 482 | .protocol = id, |
| 483 | }; |
| 484 | up = dcb_getapp(netdev, &app); |
| 485 | } |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 486 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 487 | app_nest = nla_nest_start_noflag(skb, DCB_ATTR_APP); |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 488 | if (!app_nest) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 489 | return -EMSGSIZE; |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 490 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 491 | ret = nla_put_u8(skb, DCB_APP_ATTR_IDTYPE, idtype); |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 492 | if (ret) |
| 493 | goto out_cancel; |
| 494 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 495 | ret = nla_put_u16(skb, DCB_APP_ATTR_ID, id); |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 496 | if (ret) |
| 497 | goto out_cancel; |
| 498 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 499 | ret = nla_put_u8(skb, DCB_APP_ATTR_PRIORITY, up); |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 500 | if (ret) |
| 501 | goto out_cancel; |
| 502 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 503 | nla_nest_end(skb, app_nest); |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 504 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 505 | return 0; |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 506 | |
| 507 | out_cancel: |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 508 | nla_nest_cancel(skb, app_nest); |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 509 | return ret; |
| 510 | } |
| 511 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 512 | static int dcbnl_setapp(struct net_device *netdev, struct nlmsghdr *nlh, |
| 513 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 514 | { |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 515 | int ret; |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 516 | u16 id; |
| 517 | u8 up, idtype; |
| 518 | struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1]; |
| 519 | |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 520 | if (!tb[DCB_ATTR_APP]) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 521 | return -EINVAL; |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 522 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 523 | ret = nla_parse_nested_deprecated(app_tb, DCB_APP_ATTR_MAX, |
| 524 | tb[DCB_ATTR_APP], dcbnl_app_nest, |
| 525 | NULL); |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 526 | if (ret) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 527 | return ret; |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 528 | |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 529 | /* all must be non-null */ |
| 530 | if ((!app_tb[DCB_APP_ATTR_IDTYPE]) || |
| 531 | (!app_tb[DCB_APP_ATTR_ID]) || |
| 532 | (!app_tb[DCB_APP_ATTR_PRIORITY])) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 533 | return -EINVAL; |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 534 | |
| 535 | /* either by eth type or by socket number */ |
| 536 | idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]); |
| 537 | if ((idtype != DCB_APP_IDTYPE_ETHTYPE) && |
| 538 | (idtype != DCB_APP_IDTYPE_PORTNUM)) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 539 | return -EINVAL; |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 540 | |
| 541 | id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]); |
| 542 | up = nla_get_u8(app_tb[DCB_APP_ATTR_PRIORITY]); |
| 543 | |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 544 | if (netdev->dcbnl_ops->setapp) { |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 545 | ret = netdev->dcbnl_ops->setapp(netdev, idtype, id, up); |
Anish Bhatt | c265947 | 2014-07-16 22:32:39 -0700 | [diff] [blame] | 546 | if (ret < 0) |
| 547 | return ret; |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 548 | } else { |
| 549 | struct dcb_app app; |
| 550 | app.selector = idtype; |
| 551 | app.protocol = id; |
| 552 | app.priority = up; |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 553 | ret = dcb_setapp(netdev, &app); |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 556 | ret = nla_put_u8(skb, DCB_ATTR_APP, ret); |
John Fastabend | 0815798 | 2012-04-20 09:49:23 +0000 | [diff] [blame] | 557 | dcbnl_cee_notify(netdev, RTM_SETDCB, DCB_CMD_SAPP, seq, 0); |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 558 | |
Yi Zou | 5794968 | 2009-08-31 12:33:40 +0000 | [diff] [blame] | 559 | return ret; |
| 560 | } |
| 561 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 562 | static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlmsghdr *nlh, |
| 563 | struct nlattr **tb, struct sk_buff *skb, int dir) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 564 | { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 565 | struct nlattr *pg_nest, *param_nest, *data; |
| 566 | struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1]; |
| 567 | struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1]; |
| 568 | u8 prio, pgid, tc_pct, up_map; |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 569 | int ret; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 570 | int getall = 0; |
| 571 | int i; |
| 572 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 573 | if (!tb[DCB_ATTR_PG_CFG]) |
| 574 | return -EINVAL; |
| 575 | |
| 576 | if (!netdev->dcbnl_ops->getpgtccfgtx || |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 577 | !netdev->dcbnl_ops->getpgtccfgrx || |
| 578 | !netdev->dcbnl_ops->getpgbwgcfgtx || |
| 579 | !netdev->dcbnl_ops->getpgbwgcfgrx) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 580 | return -EOPNOTSUPP; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 581 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 582 | ret = nla_parse_nested_deprecated(pg_tb, DCB_PG_ATTR_MAX, |
| 583 | tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest, |
| 584 | NULL); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 585 | if (ret) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 586 | return ret; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 587 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 588 | pg_nest = nla_nest_start_noflag(skb, DCB_ATTR_PG_CFG); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 589 | if (!pg_nest) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 590 | return -EMSGSIZE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 591 | |
| 592 | if (pg_tb[DCB_PG_ATTR_TC_ALL]) |
| 593 | getall = 1; |
| 594 | |
| 595 | for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) { |
| 596 | if (!getall && !pg_tb[i]) |
| 597 | continue; |
| 598 | |
| 599 | if (pg_tb[DCB_PG_ATTR_TC_ALL]) |
| 600 | data = pg_tb[DCB_PG_ATTR_TC_ALL]; |
| 601 | else |
| 602 | data = pg_tb[i]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 603 | ret = nla_parse_nested_deprecated(param_tb, |
| 604 | DCB_TC_ATTR_PARAM_MAX, data, |
| 605 | dcbnl_tc_param_nest, NULL); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 606 | if (ret) |
| 607 | goto err_pg; |
| 608 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 609 | param_nest = nla_nest_start_noflag(skb, i); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 610 | if (!param_nest) |
| 611 | goto err_pg; |
| 612 | |
| 613 | pgid = DCB_ATTR_VALUE_UNDEFINED; |
| 614 | prio = DCB_ATTR_VALUE_UNDEFINED; |
| 615 | tc_pct = DCB_ATTR_VALUE_UNDEFINED; |
| 616 | up_map = DCB_ATTR_VALUE_UNDEFINED; |
| 617 | |
| 618 | if (dir) { |
| 619 | /* Rx */ |
| 620 | netdev->dcbnl_ops->getpgtccfgrx(netdev, |
| 621 | i - DCB_PG_ATTR_TC_0, &prio, |
| 622 | &pgid, &tc_pct, &up_map); |
| 623 | } else { |
| 624 | /* Tx */ |
| 625 | netdev->dcbnl_ops->getpgtccfgtx(netdev, |
| 626 | i - DCB_PG_ATTR_TC_0, &prio, |
| 627 | &pgid, &tc_pct, &up_map); |
| 628 | } |
| 629 | |
| 630 | if (param_tb[DCB_TC_ATTR_PARAM_PGID] || |
| 631 | param_tb[DCB_TC_ATTR_PARAM_ALL]) { |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 632 | ret = nla_put_u8(skb, |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 633 | DCB_TC_ATTR_PARAM_PGID, pgid); |
| 634 | if (ret) |
| 635 | goto err_param; |
| 636 | } |
| 637 | if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING] || |
| 638 | param_tb[DCB_TC_ATTR_PARAM_ALL]) { |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 639 | ret = nla_put_u8(skb, |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 640 | DCB_TC_ATTR_PARAM_UP_MAPPING, up_map); |
| 641 | if (ret) |
| 642 | goto err_param; |
| 643 | } |
| 644 | if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO] || |
| 645 | param_tb[DCB_TC_ATTR_PARAM_ALL]) { |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 646 | ret = nla_put_u8(skb, |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 647 | DCB_TC_ATTR_PARAM_STRICT_PRIO, prio); |
| 648 | if (ret) |
| 649 | goto err_param; |
| 650 | } |
| 651 | if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT] || |
| 652 | param_tb[DCB_TC_ATTR_PARAM_ALL]) { |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 653 | ret = nla_put_u8(skb, DCB_TC_ATTR_PARAM_BW_PCT, |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 654 | tc_pct); |
| 655 | if (ret) |
| 656 | goto err_param; |
| 657 | } |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 658 | nla_nest_end(skb, param_nest); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | if (pg_tb[DCB_PG_ATTR_BW_ID_ALL]) |
| 662 | getall = 1; |
| 663 | else |
| 664 | getall = 0; |
| 665 | |
| 666 | for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) { |
| 667 | if (!getall && !pg_tb[i]) |
| 668 | continue; |
| 669 | |
| 670 | tc_pct = DCB_ATTR_VALUE_UNDEFINED; |
| 671 | |
| 672 | if (dir) { |
| 673 | /* Rx */ |
| 674 | netdev->dcbnl_ops->getpgbwgcfgrx(netdev, |
| 675 | i - DCB_PG_ATTR_BW_ID_0, &tc_pct); |
| 676 | } else { |
| 677 | /* Tx */ |
| 678 | netdev->dcbnl_ops->getpgbwgcfgtx(netdev, |
| 679 | i - DCB_PG_ATTR_BW_ID_0, &tc_pct); |
| 680 | } |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 681 | ret = nla_put_u8(skb, i, tc_pct); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 682 | if (ret) |
| 683 | goto err_pg; |
| 684 | } |
| 685 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 686 | nla_nest_end(skb, pg_nest); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 687 | |
| 688 | return 0; |
| 689 | |
| 690 | err_param: |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 691 | nla_nest_cancel(skb, param_nest); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 692 | err_pg: |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 693 | nla_nest_cancel(skb, pg_nest); |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 694 | |
| 695 | return -EMSGSIZE; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 696 | } |
| 697 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 698 | static int dcbnl_pgtx_getcfg(struct net_device *netdev, struct nlmsghdr *nlh, |
| 699 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 700 | { |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 701 | return __dcbnl_pg_getcfg(netdev, nlh, tb, skb, 0); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 702 | } |
| 703 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 704 | static int dcbnl_pgrx_getcfg(struct net_device *netdev, struct nlmsghdr *nlh, |
| 705 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 706 | { |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 707 | return __dcbnl_pg_getcfg(netdev, nlh, tb, skb, 1); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 708 | } |
| 709 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 710 | static int dcbnl_setstate(struct net_device *netdev, struct nlmsghdr *nlh, |
| 711 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 712 | { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 713 | u8 value; |
| 714 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 715 | if (!tb[DCB_ATTR_STATE]) |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 716 | return -EINVAL; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 717 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 718 | if (!netdev->dcbnl_ops->setstate) |
| 719 | return -EOPNOTSUPP; |
| 720 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 721 | value = nla_get_u8(tb[DCB_ATTR_STATE]); |
| 722 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 723 | return nla_put_u8(skb, DCB_ATTR_STATE, |
| 724 | netdev->dcbnl_ops->setstate(netdev, value)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 725 | } |
| 726 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 727 | static int dcbnl_setpfccfg(struct net_device *netdev, struct nlmsghdr *nlh, |
| 728 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 729 | { |
| 730 | struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1]; |
| 731 | int i; |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 732 | int ret; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 733 | u8 value; |
| 734 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 735 | if (!tb[DCB_ATTR_PFC_CFG]) |
| 736 | return -EINVAL; |
| 737 | |
| 738 | if (!netdev->dcbnl_ops->setpfccfg) |
| 739 | return -EOPNOTSUPP; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 740 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 741 | ret = nla_parse_nested_deprecated(data, DCB_PFC_UP_ATTR_MAX, |
| 742 | tb[DCB_ATTR_PFC_CFG], |
| 743 | dcbnl_pfc_up_nest, NULL); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 744 | if (ret) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 745 | return ret; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 746 | |
| 747 | for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) { |
| 748 | if (data[i] == NULL) |
| 749 | continue; |
| 750 | value = nla_get_u8(data[i]); |
| 751 | netdev->dcbnl_ops->setpfccfg(netdev, |
| 752 | data[i]->nla_type - DCB_PFC_UP_ATTR_0, value); |
| 753 | } |
| 754 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 755 | return nla_put_u8(skb, DCB_ATTR_PFC_CFG, 0); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 756 | } |
| 757 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 758 | static int dcbnl_setall(struct net_device *netdev, struct nlmsghdr *nlh, |
| 759 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 760 | { |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 761 | int ret; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 762 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 763 | if (!tb[DCB_ATTR_SET_ALL]) |
| 764 | return -EINVAL; |
| 765 | |
| 766 | if (!netdev->dcbnl_ops->setall) |
| 767 | return -EOPNOTSUPP; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 768 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 769 | ret = nla_put_u8(skb, DCB_ATTR_SET_ALL, |
| 770 | netdev->dcbnl_ops->setall(netdev)); |
John Fastabend | 0815798 | 2012-04-20 09:49:23 +0000 | [diff] [blame] | 771 | dcbnl_cee_notify(netdev, RTM_SETDCB, DCB_CMD_SET_ALL, seq, 0); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 772 | |
| 773 | return ret; |
| 774 | } |
| 775 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 776 | static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlmsghdr *nlh, |
| 777 | u32 seq, struct nlattr **tb, struct sk_buff *skb, |
| 778 | int dir) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 779 | { |
| 780 | struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1]; |
| 781 | struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1]; |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 782 | int ret; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 783 | int i; |
| 784 | u8 pgid; |
| 785 | u8 up_map; |
| 786 | u8 prio; |
| 787 | u8 tc_pct; |
| 788 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 789 | if (!tb[DCB_ATTR_PG_CFG]) |
| 790 | return -EINVAL; |
| 791 | |
| 792 | if (!netdev->dcbnl_ops->setpgtccfgtx || |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 793 | !netdev->dcbnl_ops->setpgtccfgrx || |
| 794 | !netdev->dcbnl_ops->setpgbwgcfgtx || |
| 795 | !netdev->dcbnl_ops->setpgbwgcfgrx) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 796 | return -EOPNOTSUPP; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 797 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 798 | ret = nla_parse_nested_deprecated(pg_tb, DCB_PG_ATTR_MAX, |
| 799 | tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest, |
| 800 | NULL); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 801 | if (ret) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 802 | return ret; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 803 | |
| 804 | for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) { |
| 805 | if (!pg_tb[i]) |
| 806 | continue; |
| 807 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 808 | ret = nla_parse_nested_deprecated(param_tb, |
| 809 | DCB_TC_ATTR_PARAM_MAX, |
| 810 | pg_tb[i], |
| 811 | dcbnl_tc_param_nest, NULL); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 812 | if (ret) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 813 | return ret; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 814 | |
| 815 | pgid = DCB_ATTR_VALUE_UNDEFINED; |
| 816 | prio = DCB_ATTR_VALUE_UNDEFINED; |
| 817 | tc_pct = DCB_ATTR_VALUE_UNDEFINED; |
| 818 | up_map = DCB_ATTR_VALUE_UNDEFINED; |
| 819 | |
| 820 | if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]) |
| 821 | prio = |
| 822 | nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]); |
| 823 | |
| 824 | if (param_tb[DCB_TC_ATTR_PARAM_PGID]) |
| 825 | pgid = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_PGID]); |
| 826 | |
| 827 | if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT]) |
| 828 | tc_pct = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_BW_PCT]); |
| 829 | |
| 830 | if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]) |
| 831 | up_map = |
| 832 | nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]); |
| 833 | |
| 834 | /* dir: Tx = 0, Rx = 1 */ |
| 835 | if (dir) { |
| 836 | /* Rx */ |
| 837 | netdev->dcbnl_ops->setpgtccfgrx(netdev, |
| 838 | i - DCB_PG_ATTR_TC_0, |
| 839 | prio, pgid, tc_pct, up_map); |
| 840 | } else { |
| 841 | /* Tx */ |
| 842 | netdev->dcbnl_ops->setpgtccfgtx(netdev, |
| 843 | i - DCB_PG_ATTR_TC_0, |
| 844 | prio, pgid, tc_pct, up_map); |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) { |
| 849 | if (!pg_tb[i]) |
| 850 | continue; |
| 851 | |
| 852 | tc_pct = nla_get_u8(pg_tb[i]); |
| 853 | |
| 854 | /* dir: Tx = 0, Rx = 1 */ |
| 855 | if (dir) { |
| 856 | /* Rx */ |
| 857 | netdev->dcbnl_ops->setpgbwgcfgrx(netdev, |
| 858 | i - DCB_PG_ATTR_BW_ID_0, tc_pct); |
| 859 | } else { |
| 860 | /* Tx */ |
| 861 | netdev->dcbnl_ops->setpgbwgcfgtx(netdev, |
| 862 | i - DCB_PG_ATTR_BW_ID_0, tc_pct); |
| 863 | } |
| 864 | } |
| 865 | |
John Fastabend | bb1dfef | 2012-06-20 19:56:21 +0000 | [diff] [blame] | 866 | return nla_put_u8(skb, DCB_ATTR_PG_CFG, 0); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 867 | } |
| 868 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 869 | static int dcbnl_pgtx_setcfg(struct net_device *netdev, struct nlmsghdr *nlh, |
| 870 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 871 | { |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 872 | return __dcbnl_pg_setcfg(netdev, nlh, seq, tb, skb, 0); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 873 | } |
| 874 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 875 | static int dcbnl_pgrx_setcfg(struct net_device *netdev, struct nlmsghdr *nlh, |
| 876 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 877 | { |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 878 | return __dcbnl_pg_setcfg(netdev, nlh, seq, tb, skb, 1); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 879 | } |
| 880 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 881 | static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlmsghdr *nlh, |
| 882 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 883 | { |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 884 | struct nlattr *bcn_nest; |
| 885 | struct nlattr *bcn_tb[DCB_BCN_ATTR_MAX + 1]; |
| 886 | u8 value_byte; |
| 887 | u32 value_integer; |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 888 | int ret; |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 889 | bool getall = false; |
| 890 | int i; |
| 891 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 892 | if (!tb[DCB_ATTR_BCN]) |
| 893 | return -EINVAL; |
| 894 | |
| 895 | if (!netdev->dcbnl_ops->getbcnrp || |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 896 | !netdev->dcbnl_ops->getbcncfg) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 897 | return -EOPNOTSUPP; |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 898 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 899 | ret = nla_parse_nested_deprecated(bcn_tb, DCB_BCN_ATTR_MAX, |
| 900 | tb[DCB_ATTR_BCN], dcbnl_bcn_nest, |
| 901 | NULL); |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 902 | if (ret) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 903 | return ret; |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 904 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 905 | bcn_nest = nla_nest_start_noflag(skb, DCB_ATTR_BCN); |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 906 | if (!bcn_nest) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 907 | return -EMSGSIZE; |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 908 | |
| 909 | if (bcn_tb[DCB_BCN_ATTR_ALL]) |
| 910 | getall = true; |
| 911 | |
| 912 | for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) { |
| 913 | if (!getall && !bcn_tb[i]) |
| 914 | continue; |
| 915 | |
| 916 | netdev->dcbnl_ops->getbcnrp(netdev, i - DCB_BCN_ATTR_RP_0, |
| 917 | &value_byte); |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 918 | ret = nla_put_u8(skb, i, value_byte); |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 919 | if (ret) |
| 920 | goto err_bcn; |
| 921 | } |
| 922 | |
Don Skidmore | f4314e8 | 2008-12-21 20:10:29 -0800 | [diff] [blame] | 923 | for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) { |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 924 | if (!getall && !bcn_tb[i]) |
| 925 | continue; |
| 926 | |
| 927 | netdev->dcbnl_ops->getbcncfg(netdev, i, |
| 928 | &value_integer); |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 929 | ret = nla_put_u32(skb, i, value_integer); |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 930 | if (ret) |
| 931 | goto err_bcn; |
| 932 | } |
| 933 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 934 | nla_nest_end(skb, bcn_nest); |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 935 | |
| 936 | return 0; |
| 937 | |
| 938 | err_bcn: |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 939 | nla_nest_cancel(skb, bcn_nest); |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 940 | return ret; |
| 941 | } |
| 942 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 943 | static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlmsghdr *nlh, |
| 944 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 945 | { |
| 946 | struct nlattr *data[DCB_BCN_ATTR_MAX + 1]; |
| 947 | int i; |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 948 | int ret; |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 949 | u8 value_byte; |
| 950 | u32 value_int; |
| 951 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 952 | if (!tb[DCB_ATTR_BCN]) |
| 953 | return -EINVAL; |
| 954 | |
| 955 | if (!netdev->dcbnl_ops->setbcncfg || |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 956 | !netdev->dcbnl_ops->setbcnrp) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 957 | return -EOPNOTSUPP; |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 958 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 959 | ret = nla_parse_nested_deprecated(data, DCB_BCN_ATTR_MAX, |
| 960 | tb[DCB_ATTR_BCN], dcbnl_pfc_up_nest, |
| 961 | NULL); |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 962 | if (ret) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 963 | return ret; |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 964 | |
| 965 | for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) { |
| 966 | if (data[i] == NULL) |
| 967 | continue; |
| 968 | value_byte = nla_get_u8(data[i]); |
| 969 | netdev->dcbnl_ops->setbcnrp(netdev, |
| 970 | data[i]->nla_type - DCB_BCN_ATTR_RP_0, value_byte); |
| 971 | } |
| 972 | |
Don Skidmore | f4314e8 | 2008-12-21 20:10:29 -0800 | [diff] [blame] | 973 | for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) { |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 974 | if (data[i] == NULL) |
| 975 | continue; |
| 976 | value_int = nla_get_u32(data[i]); |
| 977 | netdev->dcbnl_ops->setbcncfg(netdev, |
| 978 | i, value_int); |
| 979 | } |
| 980 | |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 981 | return nla_put_u8(skb, DCB_ATTR_BCN, 0); |
Alexander Duyck | 859ee3c | 2008-11-20 21:10:23 -0800 | [diff] [blame] | 982 | } |
| 983 | |
Shmulik Ravid | dc6ed1d | 2011-02-27 05:04:38 +0000 | [diff] [blame] | 984 | static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb, |
| 985 | int app_nested_type, int app_info_type, |
| 986 | int app_entry_type) |
Shmulik Ravid | eed8471 | 2011-02-27 05:04:31 +0000 | [diff] [blame] | 987 | { |
| 988 | struct dcb_peer_app_info info; |
| 989 | struct dcb_app *table = NULL; |
| 990 | const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; |
| 991 | u16 app_count; |
| 992 | int err; |
| 993 | |
| 994 | |
| 995 | /** |
| 996 | * retrieve the peer app configuration form the driver. If the driver |
| 997 | * handlers fail exit without doing anything |
| 998 | */ |
| 999 | err = ops->peer_getappinfo(netdev, &info, &app_count); |
| 1000 | if (!err && app_count) { |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 1001 | table = kmalloc_array(app_count, sizeof(struct dcb_app), |
| 1002 | GFP_KERNEL); |
Shmulik Ravid | eed8471 | 2011-02-27 05:04:31 +0000 | [diff] [blame] | 1003 | if (!table) |
| 1004 | return -ENOMEM; |
| 1005 | |
| 1006 | err = ops->peer_getapptable(netdev, table); |
| 1007 | } |
| 1008 | |
| 1009 | if (!err) { |
| 1010 | u16 i; |
| 1011 | struct nlattr *app; |
| 1012 | |
| 1013 | /** |
| 1014 | * build the message, from here on the only possible failure |
| 1015 | * is due to the skb size |
| 1016 | */ |
| 1017 | err = -EMSGSIZE; |
| 1018 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1019 | app = nla_nest_start_noflag(skb, app_nested_type); |
Shmulik Ravid | eed8471 | 2011-02-27 05:04:31 +0000 | [diff] [blame] | 1020 | if (!app) |
| 1021 | goto nla_put_failure; |
| 1022 | |
David S. Miller | 1eb4c97 | 2012-04-01 20:03:01 -0400 | [diff] [blame] | 1023 | if (app_info_type && |
| 1024 | nla_put(skb, app_info_type, sizeof(info), &info)) |
| 1025 | goto nla_put_failure; |
Shmulik Ravid | dc6ed1d | 2011-02-27 05:04:38 +0000 | [diff] [blame] | 1026 | |
David S. Miller | 1eb4c97 | 2012-04-01 20:03:01 -0400 | [diff] [blame] | 1027 | for (i = 0; i < app_count; i++) { |
| 1028 | if (nla_put(skb, app_entry_type, sizeof(struct dcb_app), |
| 1029 | &table[i])) |
| 1030 | goto nla_put_failure; |
| 1031 | } |
Shmulik Ravid | eed8471 | 2011-02-27 05:04:31 +0000 | [diff] [blame] | 1032 | nla_nest_end(skb, app); |
| 1033 | } |
| 1034 | err = 0; |
| 1035 | |
| 1036 | nla_put_failure: |
| 1037 | kfree(table); |
| 1038 | return err; |
| 1039 | } |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 1040 | |
Shani Michaeli | c9368247 | 2015-03-05 20:16:11 +0200 | [diff] [blame] | 1041 | /* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb GET commands. */ |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1042 | static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev) |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 1043 | { |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1044 | struct nlattr *ieee, *app; |
| 1045 | struct dcb_app_type *itr; |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 1046 | const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; |
John Fastabend | c7797ba | 2011-06-21 07:34:31 +0000 | [diff] [blame] | 1047 | int dcbx; |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1048 | int err; |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 1049 | |
David S. Miller | 1eb4c97 | 2012-04-01 20:03:01 -0400 | [diff] [blame] | 1050 | if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name)) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1051 | return -EMSGSIZE; |
| 1052 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1053 | ieee = nla_nest_start_noflag(skb, DCB_ATTR_IEEE); |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 1054 | if (!ieee) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1055 | return -EMSGSIZE; |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 1056 | |
| 1057 | if (ops->ieee_getets) { |
| 1058 | struct ieee_ets ets; |
Mathias Krause | 29cd8ae | 2013-03-09 05:52:21 +0000 | [diff] [blame] | 1059 | memset(&ets, 0, sizeof(ets)); |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 1060 | err = ops->ieee_getets(netdev, &ets); |
David S. Miller | 1eb4c97 | 2012-04-01 20:03:01 -0400 | [diff] [blame] | 1061 | if (!err && |
| 1062 | nla_put(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets)) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1063 | return -EMSGSIZE; |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
Amir Vadai | 08f10af | 2012-04-04 21:33:30 +0000 | [diff] [blame] | 1066 | if (ops->ieee_getmaxrate) { |
| 1067 | struct ieee_maxrate maxrate; |
Mathias Krause | 29cd8ae | 2013-03-09 05:52:21 +0000 | [diff] [blame] | 1068 | memset(&maxrate, 0, sizeof(maxrate)); |
Amir Vadai | 08f10af | 2012-04-04 21:33:30 +0000 | [diff] [blame] | 1069 | err = ops->ieee_getmaxrate(netdev, &maxrate); |
| 1070 | if (!err) { |
| 1071 | err = nla_put(skb, DCB_ATTR_IEEE_MAXRATE, |
| 1072 | sizeof(maxrate), &maxrate); |
| 1073 | if (err) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1074 | return -EMSGSIZE; |
Amir Vadai | 08f10af | 2012-04-04 21:33:30 +0000 | [diff] [blame] | 1075 | } |
| 1076 | } |
| 1077 | |
Shani Michaeli | c9368247 | 2015-03-05 20:16:11 +0200 | [diff] [blame] | 1078 | if (ops->ieee_getqcn) { |
| 1079 | struct ieee_qcn qcn; |
| 1080 | |
| 1081 | memset(&qcn, 0, sizeof(qcn)); |
| 1082 | err = ops->ieee_getqcn(netdev, &qcn); |
| 1083 | if (!err) { |
| 1084 | err = nla_put(skb, DCB_ATTR_IEEE_QCN, |
| 1085 | sizeof(qcn), &qcn); |
| 1086 | if (err) |
| 1087 | return -EMSGSIZE; |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | if (ops->ieee_getqcnstats) { |
| 1092 | struct ieee_qcn_stats qcn_stats; |
| 1093 | |
| 1094 | memset(&qcn_stats, 0, sizeof(qcn_stats)); |
| 1095 | err = ops->ieee_getqcnstats(netdev, &qcn_stats); |
| 1096 | if (!err) { |
| 1097 | err = nla_put(skb, DCB_ATTR_IEEE_QCN_STATS, |
| 1098 | sizeof(qcn_stats), &qcn_stats); |
| 1099 | if (err) |
| 1100 | return -EMSGSIZE; |
| 1101 | } |
| 1102 | } |
| 1103 | |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 1104 | if (ops->ieee_getpfc) { |
| 1105 | struct ieee_pfc pfc; |
Mathias Krause | 29cd8ae | 2013-03-09 05:52:21 +0000 | [diff] [blame] | 1106 | memset(&pfc, 0, sizeof(pfc)); |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 1107 | err = ops->ieee_getpfc(netdev, &pfc); |
David S. Miller | 1eb4c97 | 2012-04-01 20:03:01 -0400 | [diff] [blame] | 1108 | if (!err && |
| 1109 | nla_put(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc)) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1110 | return -EMSGSIZE; |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Huy Nguyen | e549f6f | 2018-02-22 11:57:10 -0600 | [diff] [blame] | 1113 | if (ops->dcbnl_getbuffer) { |
| 1114 | struct dcbnl_buffer buffer; |
| 1115 | |
| 1116 | memset(&buffer, 0, sizeof(buffer)); |
| 1117 | err = ops->dcbnl_getbuffer(netdev, &buffer); |
| 1118 | if (!err && |
| 1119 | nla_put(skb, DCB_ATTR_DCB_BUFFER, sizeof(buffer), &buffer)) |
| 1120 | return -EMSGSIZE; |
| 1121 | } |
| 1122 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1123 | app = nla_nest_start_noflag(skb, DCB_ATTR_IEEE_APP_TABLE); |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1124 | if (!app) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1125 | return -EMSGSIZE; |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1126 | |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1127 | spin_lock_bh(&dcb_lock); |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1128 | list_for_each_entry(itr, &dcb_app_list, list) { |
Mark Rustad | e290ed8 | 2011-10-06 08:52:33 +0000 | [diff] [blame] | 1129 | if (itr->ifindex == netdev->ifindex) { |
Dan Carpenter | 70bfa2d | 2011-01-04 21:03:12 +0000 | [diff] [blame] | 1130 | err = nla_put(skb, DCB_ATTR_IEEE_APP, sizeof(itr->app), |
| 1131 | &itr->app); |
| 1132 | if (err) { |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1133 | spin_unlock_bh(&dcb_lock); |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1134 | return -EMSGSIZE; |
Dan Carpenter | 70bfa2d | 2011-01-04 21:03:12 +0000 | [diff] [blame] | 1135 | } |
| 1136 | } |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1137 | } |
John Fastabend | c7797ba | 2011-06-21 07:34:31 +0000 | [diff] [blame] | 1138 | |
| 1139 | if (netdev->dcbnl_ops->getdcbx) |
| 1140 | dcbx = netdev->dcbnl_ops->getdcbx(netdev); |
| 1141 | else |
| 1142 | dcbx = -EOPNOTSUPP; |
| 1143 | |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1144 | spin_unlock_bh(&dcb_lock); |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1145 | nla_nest_end(skb, app); |
| 1146 | |
Shmulik Ravid | eed8471 | 2011-02-27 05:04:31 +0000 | [diff] [blame] | 1147 | /* get peer info if available */ |
| 1148 | if (ops->ieee_peer_getets) { |
| 1149 | struct ieee_ets ets; |
Mathias Krause | 29cd8ae | 2013-03-09 05:52:21 +0000 | [diff] [blame] | 1150 | memset(&ets, 0, sizeof(ets)); |
Shmulik Ravid | eed8471 | 2011-02-27 05:04:31 +0000 | [diff] [blame] | 1151 | err = ops->ieee_peer_getets(netdev, &ets); |
David S. Miller | 1eb4c97 | 2012-04-01 20:03:01 -0400 | [diff] [blame] | 1152 | if (!err && |
| 1153 | nla_put(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets)) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1154 | return -EMSGSIZE; |
Shmulik Ravid | eed8471 | 2011-02-27 05:04:31 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | if (ops->ieee_peer_getpfc) { |
| 1158 | struct ieee_pfc pfc; |
Mathias Krause | 29cd8ae | 2013-03-09 05:52:21 +0000 | [diff] [blame] | 1159 | memset(&pfc, 0, sizeof(pfc)); |
Shmulik Ravid | eed8471 | 2011-02-27 05:04:31 +0000 | [diff] [blame] | 1160 | err = ops->ieee_peer_getpfc(netdev, &pfc); |
David S. Miller | 1eb4c97 | 2012-04-01 20:03:01 -0400 | [diff] [blame] | 1161 | if (!err && |
| 1162 | nla_put(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc)) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1163 | return -EMSGSIZE; |
Shmulik Ravid | eed8471 | 2011-02-27 05:04:31 +0000 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | if (ops->peer_getappinfo && ops->peer_getapptable) { |
Shmulik Ravid | dc6ed1d | 2011-02-27 05:04:38 +0000 | [diff] [blame] | 1167 | err = dcbnl_build_peer_app(netdev, skb, |
| 1168 | DCB_ATTR_IEEE_PEER_APP, |
| 1169 | DCB_ATTR_IEEE_APP_UNSPEC, |
| 1170 | DCB_ATTR_IEEE_APP); |
Shmulik Ravid | eed8471 | 2011-02-27 05:04:31 +0000 | [diff] [blame] | 1171 | if (err) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1172 | return -EMSGSIZE; |
Shmulik Ravid | eed8471 | 2011-02-27 05:04:31 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 1175 | nla_nest_end(skb, ieee); |
John Fastabend | c7797ba | 2011-06-21 07:34:31 +0000 | [diff] [blame] | 1176 | if (dcbx >= 0) { |
| 1177 | err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx); |
| 1178 | if (err) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1179 | return -EMSGSIZE; |
John Fastabend | c7797ba | 2011-06-21 07:34:31 +0000 | [diff] [blame] | 1180 | } |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 1181 | |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1182 | return 0; |
John Fastabend | 3e29027 | 2010-12-30 09:25:46 +0000 | [diff] [blame] | 1183 | } |
| 1184 | |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1185 | static int dcbnl_cee_pg_fill(struct sk_buff *skb, struct net_device *dev, |
| 1186 | int dir) |
| 1187 | { |
| 1188 | u8 pgid, up_map, prio, tc_pct; |
| 1189 | const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops; |
| 1190 | int i = dir ? DCB_ATTR_CEE_TX_PG : DCB_ATTR_CEE_RX_PG; |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1191 | struct nlattr *pg = nla_nest_start_noflag(skb, i); |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1192 | |
| 1193 | if (!pg) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1194 | return -EMSGSIZE; |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1195 | |
| 1196 | for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1197 | struct nlattr *tc_nest = nla_nest_start_noflag(skb, i); |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1198 | |
| 1199 | if (!tc_nest) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1200 | return -EMSGSIZE; |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1201 | |
| 1202 | pgid = DCB_ATTR_VALUE_UNDEFINED; |
| 1203 | prio = DCB_ATTR_VALUE_UNDEFINED; |
| 1204 | tc_pct = DCB_ATTR_VALUE_UNDEFINED; |
| 1205 | up_map = DCB_ATTR_VALUE_UNDEFINED; |
| 1206 | |
| 1207 | if (!dir) |
| 1208 | ops->getpgtccfgrx(dev, i - DCB_PG_ATTR_TC_0, |
| 1209 | &prio, &pgid, &tc_pct, &up_map); |
| 1210 | else |
| 1211 | ops->getpgtccfgtx(dev, i - DCB_PG_ATTR_TC_0, |
| 1212 | &prio, &pgid, &tc_pct, &up_map); |
| 1213 | |
David S. Miller | 1eb4c97 | 2012-04-01 20:03:01 -0400 | [diff] [blame] | 1214 | if (nla_put_u8(skb, DCB_TC_ATTR_PARAM_PGID, pgid) || |
| 1215 | nla_put_u8(skb, DCB_TC_ATTR_PARAM_UP_MAPPING, up_map) || |
| 1216 | nla_put_u8(skb, DCB_TC_ATTR_PARAM_STRICT_PRIO, prio) || |
| 1217 | nla_put_u8(skb, DCB_TC_ATTR_PARAM_BW_PCT, tc_pct)) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1218 | return -EMSGSIZE; |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1219 | nla_nest_end(skb, tc_nest); |
| 1220 | } |
| 1221 | |
| 1222 | for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) { |
| 1223 | tc_pct = DCB_ATTR_VALUE_UNDEFINED; |
| 1224 | |
| 1225 | if (!dir) |
| 1226 | ops->getpgbwgcfgrx(dev, i - DCB_PG_ATTR_BW_ID_0, |
| 1227 | &tc_pct); |
| 1228 | else |
| 1229 | ops->getpgbwgcfgtx(dev, i - DCB_PG_ATTR_BW_ID_0, |
| 1230 | &tc_pct); |
David S. Miller | 1eb4c97 | 2012-04-01 20:03:01 -0400 | [diff] [blame] | 1231 | if (nla_put_u8(skb, i, tc_pct)) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1232 | return -EMSGSIZE; |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1233 | } |
| 1234 | nla_nest_end(skb, pg); |
| 1235 | return 0; |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev) |
| 1239 | { |
| 1240 | struct nlattr *cee, *app; |
| 1241 | struct dcb_app_type *itr; |
| 1242 | const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; |
| 1243 | int dcbx, i, err = -EMSGSIZE; |
| 1244 | u8 value; |
| 1245 | |
David S. Miller | 1eb4c97 | 2012-04-01 20:03:01 -0400 | [diff] [blame] | 1246 | if (nla_put_string(skb, DCB_ATTR_IFNAME, netdev->name)) |
| 1247 | goto nla_put_failure; |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1248 | cee = nla_nest_start_noflag(skb, DCB_ATTR_CEE); |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1249 | if (!cee) |
| 1250 | goto nla_put_failure; |
| 1251 | |
| 1252 | /* local pg */ |
| 1253 | if (ops->getpgtccfgtx && ops->getpgbwgcfgtx) { |
| 1254 | err = dcbnl_cee_pg_fill(skb, netdev, 1); |
| 1255 | if (err) |
| 1256 | goto nla_put_failure; |
| 1257 | } |
| 1258 | |
| 1259 | if (ops->getpgtccfgrx && ops->getpgbwgcfgrx) { |
| 1260 | err = dcbnl_cee_pg_fill(skb, netdev, 0); |
| 1261 | if (err) |
| 1262 | goto nla_put_failure; |
| 1263 | } |
| 1264 | |
| 1265 | /* local pfc */ |
| 1266 | if (ops->getpfccfg) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1267 | struct nlattr *pfc_nest = nla_nest_start_noflag(skb, |
| 1268 | DCB_ATTR_CEE_PFC); |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1269 | |
| 1270 | if (!pfc_nest) |
| 1271 | goto nla_put_failure; |
| 1272 | |
| 1273 | for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) { |
| 1274 | ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0, &value); |
David S. Miller | 1eb4c97 | 2012-04-01 20:03:01 -0400 | [diff] [blame] | 1275 | if (nla_put_u8(skb, i, value)) |
| 1276 | goto nla_put_failure; |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1277 | } |
| 1278 | nla_nest_end(skb, pfc_nest); |
| 1279 | } |
| 1280 | |
| 1281 | /* local app */ |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1282 | spin_lock_bh(&dcb_lock); |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1283 | app = nla_nest_start_noflag(skb, DCB_ATTR_CEE_APP_TABLE); |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1284 | if (!app) |
Dan Carpenter | 40f5d72 | 2011-07-07 21:27:24 +0000 | [diff] [blame] | 1285 | goto dcb_unlock; |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1286 | |
| 1287 | list_for_each_entry(itr, &dcb_app_list, list) { |
Mark Rustad | e290ed8 | 2011-10-06 08:52:33 +0000 | [diff] [blame] | 1288 | if (itr->ifindex == netdev->ifindex) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1289 | struct nlattr *app_nest = nla_nest_start_noflag(skb, |
| 1290 | DCB_ATTR_APP); |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1291 | if (!app_nest) |
| 1292 | goto dcb_unlock; |
| 1293 | |
| 1294 | err = nla_put_u8(skb, DCB_APP_ATTR_IDTYPE, |
| 1295 | itr->app.selector); |
| 1296 | if (err) |
| 1297 | goto dcb_unlock; |
| 1298 | |
| 1299 | err = nla_put_u16(skb, DCB_APP_ATTR_ID, |
| 1300 | itr->app.protocol); |
| 1301 | if (err) |
| 1302 | goto dcb_unlock; |
| 1303 | |
| 1304 | err = nla_put_u8(skb, DCB_APP_ATTR_PRIORITY, |
| 1305 | itr->app.priority); |
| 1306 | if (err) |
| 1307 | goto dcb_unlock; |
| 1308 | |
| 1309 | nla_nest_end(skb, app_nest); |
| 1310 | } |
| 1311 | } |
| 1312 | nla_nest_end(skb, app); |
| 1313 | |
| 1314 | if (netdev->dcbnl_ops->getdcbx) |
| 1315 | dcbx = netdev->dcbnl_ops->getdcbx(netdev); |
| 1316 | else |
| 1317 | dcbx = -EOPNOTSUPP; |
| 1318 | |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1319 | spin_unlock_bh(&dcb_lock); |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1320 | |
| 1321 | /* features flags */ |
| 1322 | if (ops->getfeatcfg) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1323 | struct nlattr *feat = nla_nest_start_noflag(skb, |
| 1324 | DCB_ATTR_CEE_FEAT); |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1325 | if (!feat) |
| 1326 | goto nla_put_failure; |
| 1327 | |
| 1328 | for (i = DCB_FEATCFG_ATTR_ALL + 1; i <= DCB_FEATCFG_ATTR_MAX; |
| 1329 | i++) |
David S. Miller | 1eb4c97 | 2012-04-01 20:03:01 -0400 | [diff] [blame] | 1330 | if (!ops->getfeatcfg(netdev, i, &value) && |
| 1331 | nla_put_u8(skb, i, value)) |
| 1332 | goto nla_put_failure; |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1333 | |
| 1334 | nla_nest_end(skb, feat); |
| 1335 | } |
| 1336 | |
| 1337 | /* peer info if available */ |
| 1338 | if (ops->cee_peer_getpg) { |
| 1339 | struct cee_pg pg; |
Mathias Krause | 29cd8ae | 2013-03-09 05:52:21 +0000 | [diff] [blame] | 1340 | memset(&pg, 0, sizeof(pg)); |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1341 | err = ops->cee_peer_getpg(netdev, &pg); |
David S. Miller | 1eb4c97 | 2012-04-01 20:03:01 -0400 | [diff] [blame] | 1342 | if (!err && |
| 1343 | nla_put(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg)) |
| 1344 | goto nla_put_failure; |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | if (ops->cee_peer_getpfc) { |
| 1348 | struct cee_pfc pfc; |
Mathias Krause | 29cd8ae | 2013-03-09 05:52:21 +0000 | [diff] [blame] | 1349 | memset(&pfc, 0, sizeof(pfc)); |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1350 | err = ops->cee_peer_getpfc(netdev, &pfc); |
David S. Miller | 1eb4c97 | 2012-04-01 20:03:01 -0400 | [diff] [blame] | 1351 | if (!err && |
| 1352 | nla_put(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc)) |
| 1353 | goto nla_put_failure; |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | if (ops->peer_getappinfo && ops->peer_getapptable) { |
| 1357 | err = dcbnl_build_peer_app(netdev, skb, |
| 1358 | DCB_ATTR_CEE_PEER_APP_TABLE, |
| 1359 | DCB_ATTR_CEE_PEER_APP_INFO, |
| 1360 | DCB_ATTR_CEE_PEER_APP); |
| 1361 | if (err) |
| 1362 | goto nla_put_failure; |
| 1363 | } |
| 1364 | nla_nest_end(skb, cee); |
| 1365 | |
| 1366 | /* DCBX state */ |
| 1367 | if (dcbx >= 0) { |
| 1368 | err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx); |
| 1369 | if (err) |
| 1370 | goto nla_put_failure; |
| 1371 | } |
| 1372 | return 0; |
| 1373 | |
| 1374 | dcb_unlock: |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1375 | spin_unlock_bh(&dcb_lock); |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1376 | nla_put_failure: |
Pan Bian | c66ebf2 | 2016-12-03 21:49:08 +0800 | [diff] [blame] | 1377 | err = -EMSGSIZE; |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1378 | return err; |
| 1379 | } |
| 1380 | |
| 1381 | static int dcbnl_notify(struct net_device *dev, int event, int cmd, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1382 | u32 seq, u32 portid, int dcbx_ver) |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1383 | { |
| 1384 | struct net *net = dev_net(dev); |
| 1385 | struct sk_buff *skb; |
| 1386 | struct nlmsghdr *nlh; |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1387 | const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops; |
| 1388 | int err; |
| 1389 | |
| 1390 | if (!ops) |
| 1391 | return -EOPNOTSUPP; |
| 1392 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1393 | skb = dcbnl_newmsg(event, cmd, portid, seq, 0, &nlh); |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1394 | if (!skb) |
| 1395 | return -ENOBUFS; |
| 1396 | |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1397 | if (dcbx_ver == DCB_CAP_DCBX_VER_IEEE) |
| 1398 | err = dcbnl_ieee_fill(skb, dev); |
| 1399 | else |
| 1400 | err = dcbnl_cee_fill(skb, dev); |
| 1401 | |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1402 | if (err < 0) { |
| 1403 | /* Report error to broadcast listeners */ |
Thomas Graf | ab6d470 | 2012-06-13 02:54:57 +0000 | [diff] [blame] | 1404 | nlmsg_free(skb); |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1405 | rtnl_set_sk_err(net, RTNLGRP_DCB, err); |
| 1406 | } else { |
| 1407 | /* End nlmsg and notify broadcast listeners */ |
| 1408 | nlmsg_end(skb, nlh); |
| 1409 | rtnl_notify(skb, net, 0, RTNLGRP_DCB, NULL, GFP_KERNEL); |
| 1410 | } |
| 1411 | |
| 1412 | return err; |
| 1413 | } |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1414 | |
| 1415 | int dcbnl_ieee_notify(struct net_device *dev, int event, int cmd, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1416 | u32 seq, u32 portid) |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1417 | { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1418 | return dcbnl_notify(dev, event, cmd, seq, portid, DCB_CAP_DCBX_VER_IEEE); |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1419 | } |
| 1420 | EXPORT_SYMBOL(dcbnl_ieee_notify); |
| 1421 | |
| 1422 | int dcbnl_cee_notify(struct net_device *dev, int event, int cmd, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1423 | u32 seq, u32 portid) |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1424 | { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1425 | return dcbnl_notify(dev, event, cmd, seq, portid, DCB_CAP_DCBX_VER_CEE); |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1426 | } |
| 1427 | EXPORT_SYMBOL(dcbnl_cee_notify); |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1428 | |
Shani Michaeli | c9368247 | 2015-03-05 20:16:11 +0200 | [diff] [blame] | 1429 | /* Handle IEEE 802.1Qaz/802.1Qau/802.1Qbb SET commands. |
| 1430 | * If any requested operation can not be completed |
| 1431 | * the entire msg is aborted and error value is returned. |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1432 | * No attempt is made to reconcile the case where only part of the |
| 1433 | * cmd can be completed. |
| 1434 | */ |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1435 | static int dcbnl_ieee_set(struct net_device *netdev, struct nlmsghdr *nlh, |
| 1436 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1437 | { |
| 1438 | const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; |
| 1439 | struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1]; |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1440 | int err; |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1441 | |
| 1442 | if (!ops) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1443 | return -EOPNOTSUPP; |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1444 | |
John Fastabend | 4003b65 | 2011-06-21 07:35:04 +0000 | [diff] [blame] | 1445 | if (!tb[DCB_ATTR_IEEE]) |
| 1446 | return -EINVAL; |
| 1447 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1448 | err = nla_parse_nested_deprecated(ieee, DCB_ATTR_IEEE_MAX, |
| 1449 | tb[DCB_ATTR_IEEE], |
| 1450 | dcbnl_ieee_policy, NULL); |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1451 | if (err) |
| 1452 | return err; |
| 1453 | |
| 1454 | if (ieee[DCB_ATTR_IEEE_ETS] && ops->ieee_setets) { |
| 1455 | struct ieee_ets *ets = nla_data(ieee[DCB_ATTR_IEEE_ETS]); |
| 1456 | err = ops->ieee_setets(netdev, ets); |
| 1457 | if (err) |
| 1458 | goto err; |
| 1459 | } |
| 1460 | |
Amir Vadai | 08f10af | 2012-04-04 21:33:30 +0000 | [diff] [blame] | 1461 | if (ieee[DCB_ATTR_IEEE_MAXRATE] && ops->ieee_setmaxrate) { |
| 1462 | struct ieee_maxrate *maxrate = |
| 1463 | nla_data(ieee[DCB_ATTR_IEEE_MAXRATE]); |
| 1464 | err = ops->ieee_setmaxrate(netdev, maxrate); |
| 1465 | if (err) |
| 1466 | goto err; |
| 1467 | } |
| 1468 | |
Shani Michaeli | c9368247 | 2015-03-05 20:16:11 +0200 | [diff] [blame] | 1469 | if (ieee[DCB_ATTR_IEEE_QCN] && ops->ieee_setqcn) { |
| 1470 | struct ieee_qcn *qcn = |
| 1471 | nla_data(ieee[DCB_ATTR_IEEE_QCN]); |
| 1472 | |
| 1473 | err = ops->ieee_setqcn(netdev, qcn); |
| 1474 | if (err) |
| 1475 | goto err; |
| 1476 | } |
| 1477 | |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1478 | if (ieee[DCB_ATTR_IEEE_PFC] && ops->ieee_setpfc) { |
| 1479 | struct ieee_pfc *pfc = nla_data(ieee[DCB_ATTR_IEEE_PFC]); |
| 1480 | err = ops->ieee_setpfc(netdev, pfc); |
| 1481 | if (err) |
| 1482 | goto err; |
| 1483 | } |
| 1484 | |
Huy Nguyen | e549f6f | 2018-02-22 11:57:10 -0600 | [diff] [blame] | 1485 | if (ieee[DCB_ATTR_DCB_BUFFER] && ops->dcbnl_setbuffer) { |
| 1486 | struct dcbnl_buffer *buffer = |
| 1487 | nla_data(ieee[DCB_ATTR_DCB_BUFFER]); |
| 1488 | |
| 1489 | err = ops->dcbnl_setbuffer(netdev, buffer); |
| 1490 | if (err) |
| 1491 | goto err; |
| 1492 | } |
| 1493 | |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1494 | if (ieee[DCB_ATTR_IEEE_APP_TABLE]) { |
| 1495 | struct nlattr *attr; |
| 1496 | int rem; |
| 1497 | |
| 1498 | nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) { |
| 1499 | struct dcb_app *app_data; |
stephen hemminger | 332b4fc | 2017-05-19 09:55:48 -0700 | [diff] [blame] | 1500 | |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1501 | if (nla_type(attr) != DCB_ATTR_IEEE_APP) |
| 1502 | continue; |
stephen hemminger | 332b4fc | 2017-05-19 09:55:48 -0700 | [diff] [blame] | 1503 | |
| 1504 | if (nla_len(attr) < sizeof(struct dcb_app)) { |
| 1505 | err = -ERANGE; |
| 1506 | goto err; |
| 1507 | } |
| 1508 | |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1509 | app_data = nla_data(attr); |
| 1510 | if (ops->ieee_setapp) |
| 1511 | err = ops->ieee_setapp(netdev, app_data); |
| 1512 | else |
John Fastabend | b6db217 | 2011-06-21 07:34:42 +0000 | [diff] [blame] | 1513 | err = dcb_ieee_setapp(netdev, app_data); |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1514 | if (err) |
| 1515 | goto err; |
| 1516 | } |
| 1517 | } |
| 1518 | |
| 1519 | err: |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1520 | err = nla_put_u8(skb, DCB_ATTR_IEEE, err); |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1521 | dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_SET, seq, 0); |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1522 | return err; |
| 1523 | } |
| 1524 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1525 | static int dcbnl_ieee_get(struct net_device *netdev, struct nlmsghdr *nlh, |
| 1526 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1527 | { |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1528 | const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1529 | |
| 1530 | if (!ops) |
| 1531 | return -EOPNOTSUPP; |
| 1532 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1533 | return dcbnl_ieee_fill(skb, netdev); |
John Fastabend | 314b477 | 2011-06-21 07:34:37 +0000 | [diff] [blame] | 1534 | } |
John Fastabend | f9ae7e4 | 2011-06-21 07:34:48 +0000 | [diff] [blame] | 1535 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1536 | static int dcbnl_ieee_del(struct net_device *netdev, struct nlmsghdr *nlh, |
| 1537 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
John Fastabend | f9ae7e4 | 2011-06-21 07:34:48 +0000 | [diff] [blame] | 1538 | { |
| 1539 | const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; |
| 1540 | struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1]; |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1541 | int err; |
John Fastabend | f9ae7e4 | 2011-06-21 07:34:48 +0000 | [diff] [blame] | 1542 | |
| 1543 | if (!ops) |
| 1544 | return -EOPNOTSUPP; |
| 1545 | |
| 1546 | if (!tb[DCB_ATTR_IEEE]) |
| 1547 | return -EINVAL; |
| 1548 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1549 | err = nla_parse_nested_deprecated(ieee, DCB_ATTR_IEEE_MAX, |
| 1550 | tb[DCB_ATTR_IEEE], |
| 1551 | dcbnl_ieee_policy, NULL); |
John Fastabend | f9ae7e4 | 2011-06-21 07:34:48 +0000 | [diff] [blame] | 1552 | if (err) |
| 1553 | return err; |
| 1554 | |
| 1555 | if (ieee[DCB_ATTR_IEEE_APP_TABLE]) { |
| 1556 | struct nlattr *attr; |
| 1557 | int rem; |
| 1558 | |
| 1559 | nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) { |
| 1560 | struct dcb_app *app_data; |
| 1561 | |
| 1562 | if (nla_type(attr) != DCB_ATTR_IEEE_APP) |
| 1563 | continue; |
| 1564 | app_data = nla_data(attr); |
| 1565 | if (ops->ieee_delapp) |
| 1566 | err = ops->ieee_delapp(netdev, app_data); |
| 1567 | else |
| 1568 | err = dcb_ieee_delapp(netdev, app_data); |
| 1569 | if (err) |
| 1570 | goto err; |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | err: |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1575 | err = nla_put_u8(skb, DCB_ATTR_IEEE, err); |
Shmulik Ravid | 5b7f762 | 2011-07-05 06:16:25 +0000 | [diff] [blame] | 1576 | dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_DEL, seq, 0); |
John Fastabend | f9ae7e4 | 2011-06-21 07:34:48 +0000 | [diff] [blame] | 1577 | return err; |
| 1578 | } |
| 1579 | |
| 1580 | |
Shmulik Ravid | 6241b62 | 2010-12-30 06:26:48 +0000 | [diff] [blame] | 1581 | /* DCBX configuration */ |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1582 | static int dcbnl_getdcbx(struct net_device *netdev, struct nlmsghdr *nlh, |
| 1583 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Shmulik Ravid | 6241b62 | 2010-12-30 06:26:48 +0000 | [diff] [blame] | 1584 | { |
Shmulik Ravid | 6241b62 | 2010-12-30 06:26:48 +0000 | [diff] [blame] | 1585 | if (!netdev->dcbnl_ops->getdcbx) |
Shmulik Ravid | 7f891cf | 2011-01-03 08:04:59 +0000 | [diff] [blame] | 1586 | return -EOPNOTSUPP; |
Shmulik Ravid | 6241b62 | 2010-12-30 06:26:48 +0000 | [diff] [blame] | 1587 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1588 | return nla_put_u8(skb, DCB_ATTR_DCBX, |
| 1589 | netdev->dcbnl_ops->getdcbx(netdev)); |
Shmulik Ravid | 6241b62 | 2010-12-30 06:26:48 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1592 | static int dcbnl_setdcbx(struct net_device *netdev, struct nlmsghdr *nlh, |
| 1593 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Shmulik Ravid | 6241b62 | 2010-12-30 06:26:48 +0000 | [diff] [blame] | 1594 | { |
Shmulik Ravid | 6241b62 | 2010-12-30 06:26:48 +0000 | [diff] [blame] | 1595 | u8 value; |
| 1596 | |
Shmulik Ravid | 7f891cf | 2011-01-03 08:04:59 +0000 | [diff] [blame] | 1597 | if (!netdev->dcbnl_ops->setdcbx) |
| 1598 | return -EOPNOTSUPP; |
| 1599 | |
| 1600 | if (!tb[DCB_ATTR_DCBX]) |
| 1601 | return -EINVAL; |
Shmulik Ravid | 6241b62 | 2010-12-30 06:26:48 +0000 | [diff] [blame] | 1602 | |
| 1603 | value = nla_get_u8(tb[DCB_ATTR_DCBX]); |
| 1604 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1605 | return nla_put_u8(skb, DCB_ATTR_DCBX, |
| 1606 | netdev->dcbnl_ops->setdcbx(netdev, value)); |
Shmulik Ravid | 6241b62 | 2010-12-30 06:26:48 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1609 | static int dcbnl_getfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh, |
| 1610 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1611 | { |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1612 | struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1], *nest; |
| 1613 | u8 value; |
Shmulik Ravid | 7f891cf | 2011-01-03 08:04:59 +0000 | [diff] [blame] | 1614 | int ret, i; |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1615 | int getall = 0; |
| 1616 | |
Shmulik Ravid | 7f891cf | 2011-01-03 08:04:59 +0000 | [diff] [blame] | 1617 | if (!netdev->dcbnl_ops->getfeatcfg) |
| 1618 | return -EOPNOTSUPP; |
| 1619 | |
| 1620 | if (!tb[DCB_ATTR_FEATCFG]) |
| 1621 | return -EINVAL; |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1622 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1623 | ret = nla_parse_nested_deprecated(data, DCB_FEATCFG_ATTR_MAX, |
| 1624 | tb[DCB_ATTR_FEATCFG], |
| 1625 | dcbnl_featcfg_nest, NULL); |
Shmulik Ravid | 7f891cf | 2011-01-03 08:04:59 +0000 | [diff] [blame] | 1626 | if (ret) |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1627 | return ret; |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1628 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1629 | nest = nla_nest_start_noflag(skb, DCB_ATTR_FEATCFG); |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1630 | if (!nest) |
| 1631 | return -EMSGSIZE; |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1632 | |
| 1633 | if (data[DCB_FEATCFG_ATTR_ALL]) |
| 1634 | getall = 1; |
| 1635 | |
| 1636 | for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) { |
| 1637 | if (!getall && !data[i]) |
| 1638 | continue; |
| 1639 | |
| 1640 | ret = netdev->dcbnl_ops->getfeatcfg(netdev, i, &value); |
Shmulik Ravid | 7f891cf | 2011-01-03 08:04:59 +0000 | [diff] [blame] | 1641 | if (!ret) |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1642 | ret = nla_put_u8(skb, i, value); |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1643 | |
Shmulik Ravid | 7f891cf | 2011-01-03 08:04:59 +0000 | [diff] [blame] | 1644 | if (ret) { |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1645 | nla_nest_cancel(skb, nest); |
Shmulik Ravid | 7f891cf | 2011-01-03 08:04:59 +0000 | [diff] [blame] | 1646 | goto nla_put_failure; |
| 1647 | } |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1648 | } |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1649 | nla_nest_end(skb, nest); |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1650 | |
Shmulik Ravid | 7f891cf | 2011-01-03 08:04:59 +0000 | [diff] [blame] | 1651 | nla_put_failure: |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1652 | return ret; |
| 1653 | } |
| 1654 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1655 | static int dcbnl_setfeatcfg(struct net_device *netdev, struct nlmsghdr *nlh, |
| 1656 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1657 | { |
| 1658 | struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1]; |
Shmulik Ravid | 7f891cf | 2011-01-03 08:04:59 +0000 | [diff] [blame] | 1659 | int ret, i; |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1660 | u8 value; |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1661 | |
Shmulik Ravid | 7f891cf | 2011-01-03 08:04:59 +0000 | [diff] [blame] | 1662 | if (!netdev->dcbnl_ops->setfeatcfg) |
| 1663 | return -ENOTSUPP; |
| 1664 | |
| 1665 | if (!tb[DCB_ATTR_FEATCFG]) |
| 1666 | return -EINVAL; |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1667 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1668 | ret = nla_parse_nested_deprecated(data, DCB_FEATCFG_ATTR_MAX, |
| 1669 | tb[DCB_ATTR_FEATCFG], |
| 1670 | dcbnl_featcfg_nest, NULL); |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1671 | |
Shmulik Ravid | 7f891cf | 2011-01-03 08:04:59 +0000 | [diff] [blame] | 1672 | if (ret) |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1673 | goto err; |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1674 | |
| 1675 | for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) { |
| 1676 | if (data[i] == NULL) |
| 1677 | continue; |
| 1678 | |
| 1679 | value = nla_get_u8(data[i]); |
| 1680 | |
| 1681 | ret = netdev->dcbnl_ops->setfeatcfg(netdev, i, value); |
| 1682 | |
| 1683 | if (ret) |
Shmulik Ravid | 7f891cf | 2011-01-03 08:04:59 +0000 | [diff] [blame] | 1684 | goto err; |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1685 | } |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1686 | err: |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1687 | ret = nla_put_u8(skb, DCB_ATTR_FEATCFG, ret); |
Shmulik Ravid | 7f891cf | 2011-01-03 08:04:59 +0000 | [diff] [blame] | 1688 | |
Shmulik Ravid | ea45fe4 | 2010-12-30 06:26:55 +0000 | [diff] [blame] | 1689 | return ret; |
| 1690 | } |
| 1691 | |
Shmulik Ravid | dc6ed1d | 2011-02-27 05:04:38 +0000 | [diff] [blame] | 1692 | /* Handle CEE DCBX GET commands. */ |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1693 | static int dcbnl_cee_get(struct net_device *netdev, struct nlmsghdr *nlh, |
| 1694 | u32 seq, struct nlattr **tb, struct sk_buff *skb) |
Shmulik Ravid | dc6ed1d | 2011-02-27 05:04:38 +0000 | [diff] [blame] | 1695 | { |
Shmulik Ravid | dc6ed1d | 2011-02-27 05:04:38 +0000 | [diff] [blame] | 1696 | const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops; |
Shmulik Ravid | dc6ed1d | 2011-02-27 05:04:38 +0000 | [diff] [blame] | 1697 | |
| 1698 | if (!ops) |
| 1699 | return -EOPNOTSUPP; |
| 1700 | |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1701 | return dcbnl_cee_fill(skb, netdev); |
Shmulik Ravid | dc6ed1d | 2011-02-27 05:04:38 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
Thomas Graf | 33a03aa | 2012-06-13 02:54:54 +0000 | [diff] [blame] | 1704 | struct reply_func { |
| 1705 | /* reply netlink message type */ |
| 1706 | int type; |
| 1707 | |
| 1708 | /* function to fill message contents */ |
| 1709 | int (*cb)(struct net_device *, struct nlmsghdr *, u32, |
| 1710 | struct nlattr **, struct sk_buff *); |
| 1711 | }; |
| 1712 | |
| 1713 | static const struct reply_func reply_funcs[DCB_CMD_MAX+1] = { |
Thomas Graf | 7be9941 | 2012-06-13 02:54:55 +0000 | [diff] [blame] | 1714 | [DCB_CMD_GSTATE] = { RTM_GETDCB, dcbnl_getstate }, |
| 1715 | [DCB_CMD_SSTATE] = { RTM_SETDCB, dcbnl_setstate }, |
| 1716 | [DCB_CMD_PFC_GCFG] = { RTM_GETDCB, dcbnl_getpfccfg }, |
| 1717 | [DCB_CMD_PFC_SCFG] = { RTM_SETDCB, dcbnl_setpfccfg }, |
| 1718 | [DCB_CMD_GPERM_HWADDR] = { RTM_GETDCB, dcbnl_getperm_hwaddr }, |
| 1719 | [DCB_CMD_GCAP] = { RTM_GETDCB, dcbnl_getcap }, |
| 1720 | [DCB_CMD_GNUMTCS] = { RTM_GETDCB, dcbnl_getnumtcs }, |
| 1721 | [DCB_CMD_SNUMTCS] = { RTM_SETDCB, dcbnl_setnumtcs }, |
| 1722 | [DCB_CMD_PFC_GSTATE] = { RTM_GETDCB, dcbnl_getpfcstate }, |
| 1723 | [DCB_CMD_PFC_SSTATE] = { RTM_SETDCB, dcbnl_setpfcstate }, |
| 1724 | [DCB_CMD_GAPP] = { RTM_GETDCB, dcbnl_getapp }, |
| 1725 | [DCB_CMD_SAPP] = { RTM_SETDCB, dcbnl_setapp }, |
| 1726 | [DCB_CMD_PGTX_GCFG] = { RTM_GETDCB, dcbnl_pgtx_getcfg }, |
| 1727 | [DCB_CMD_PGTX_SCFG] = { RTM_SETDCB, dcbnl_pgtx_setcfg }, |
| 1728 | [DCB_CMD_PGRX_GCFG] = { RTM_GETDCB, dcbnl_pgrx_getcfg }, |
| 1729 | [DCB_CMD_PGRX_SCFG] = { RTM_SETDCB, dcbnl_pgrx_setcfg }, |
| 1730 | [DCB_CMD_SET_ALL] = { RTM_SETDCB, dcbnl_setall }, |
| 1731 | [DCB_CMD_BCN_GCFG] = { RTM_GETDCB, dcbnl_bcn_getcfg }, |
| 1732 | [DCB_CMD_BCN_SCFG] = { RTM_SETDCB, dcbnl_bcn_setcfg }, |
| 1733 | [DCB_CMD_IEEE_GET] = { RTM_GETDCB, dcbnl_ieee_get }, |
| 1734 | [DCB_CMD_IEEE_SET] = { RTM_SETDCB, dcbnl_ieee_set }, |
| 1735 | [DCB_CMD_IEEE_DEL] = { RTM_SETDCB, dcbnl_ieee_del }, |
| 1736 | [DCB_CMD_GDCBX] = { RTM_GETDCB, dcbnl_getdcbx }, |
| 1737 | [DCB_CMD_SDCBX] = { RTM_SETDCB, dcbnl_setdcbx }, |
| 1738 | [DCB_CMD_GFEATCFG] = { RTM_GETDCB, dcbnl_getfeatcfg }, |
| 1739 | [DCB_CMD_SFEATCFG] = { RTM_SETDCB, dcbnl_setfeatcfg }, |
| 1740 | [DCB_CMD_CEE_GET] = { RTM_GETDCB, dcbnl_cee_get }, |
Thomas Graf | 33a03aa | 2012-06-13 02:54:54 +0000 | [diff] [blame] | 1741 | }; |
| 1742 | |
David Ahern | c21ef3e | 2017-04-16 09:48:24 -0700 | [diff] [blame] | 1743 | static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, |
| 1744 | struct netlink_ext_ack *extack) |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1745 | { |
| 1746 | struct net *net = sock_net(skb->sk); |
| 1747 | struct net_device *netdev; |
Thomas Graf | 7a282bc | 2012-06-13 02:55:01 +0000 | [diff] [blame] | 1748 | struct dcbmsg *dcb = nlmsg_data(nlh); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1749 | struct nlattr *tb[DCB_ATTR_MAX + 1]; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1750 | u32 portid = skb ? NETLINK_CB(skb).portid : 0; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1751 | int ret = -EINVAL; |
Thomas Graf | 33a03aa | 2012-06-13 02:54:54 +0000 | [diff] [blame] | 1752 | struct sk_buff *reply_skb; |
Thomas Graf | 39912f9 | 2012-06-13 22:34:03 +0000 | [diff] [blame] | 1753 | struct nlmsghdr *reply_nlh = NULL; |
Thomas Graf | 33a03aa | 2012-06-13 02:54:54 +0000 | [diff] [blame] | 1754 | const struct reply_func *fn; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1755 | |
Eric W. Biederman | 90f62cf | 2014-04-23 14:29:27 -0700 | [diff] [blame] | 1756 | if ((nlh->nlmsg_type == RTM_SETDCB) && !netlink_capable(skb, CAP_NET_ADMIN)) |
Eric W. Biederman | dfc47ef | 2012-11-16 03:03:00 +0000 | [diff] [blame] | 1757 | return -EPERM; |
| 1758 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1759 | ret = nlmsg_parse_deprecated(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX, |
| 1760 | dcbnl_rtnl_policy, extack); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1761 | if (ret < 0) |
| 1762 | return ret; |
| 1763 | |
Thomas Graf | 33a03aa | 2012-06-13 02:54:54 +0000 | [diff] [blame] | 1764 | if (dcb->cmd > DCB_CMD_MAX) |
| 1765 | return -EINVAL; |
| 1766 | |
| 1767 | /* check if a reply function has been defined for the command */ |
| 1768 | fn = &reply_funcs[dcb->cmd]; |
| 1769 | if (!fn->cb) |
| 1770 | return -EOPNOTSUPP; |
| 1771 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1772 | if (!tb[DCB_ATTR_IFNAME]) |
| 1773 | return -EINVAL; |
| 1774 | |
Ying Xue | d9ac62b | 2014-01-15 10:23:39 +0800 | [diff] [blame] | 1775 | netdev = __dev_get_by_name(net, nla_data(tb[DCB_ATTR_IFNAME])); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1776 | if (!netdev) |
Thomas Graf | 3d1f486 | 2012-06-13 02:54:58 +0000 | [diff] [blame] | 1777 | return -ENODEV; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1778 | |
Ying Xue | d9ac62b | 2014-01-15 10:23:39 +0800 | [diff] [blame] | 1779 | if (!netdev->dcbnl_ops) |
| 1780 | return -EOPNOTSUPP; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1781 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1782 | reply_skb = dcbnl_newmsg(fn->type, dcb->cmd, portid, nlh->nlmsg_seq, |
Thomas Graf | 33a03aa | 2012-06-13 02:54:54 +0000 | [diff] [blame] | 1783 | nlh->nlmsg_flags, &reply_nlh); |
Ying Xue | d9ac62b | 2014-01-15 10:23:39 +0800 | [diff] [blame] | 1784 | if (!reply_skb) |
| 1785 | return -ENOBUFS; |
Thomas Graf | 33a03aa | 2012-06-13 02:54:54 +0000 | [diff] [blame] | 1786 | |
| 1787 | ret = fn->cb(netdev, nlh, nlh->nlmsg_seq, tb, reply_skb); |
| 1788 | if (ret < 0) { |
| 1789 | nlmsg_free(reply_skb); |
| 1790 | goto out; |
| 1791 | } |
| 1792 | |
| 1793 | nlmsg_end(reply_skb, reply_nlh); |
| 1794 | |
John Fastabend | 7c77ab2 | 2012-12-09 20:48:13 +0000 | [diff] [blame] | 1795 | ret = rtnl_unicast(reply_skb, net, portid); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1796 | out: |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1797 | return ret; |
| 1798 | } |
| 1799 | |
Thomas Graf | 716b31a | 2012-06-13 02:54:59 +0000 | [diff] [blame] | 1800 | static struct dcb_app_type *dcb_app_lookup(const struct dcb_app *app, |
| 1801 | int ifindex, int prio) |
| 1802 | { |
| 1803 | struct dcb_app_type *itr; |
| 1804 | |
| 1805 | list_for_each_entry(itr, &dcb_app_list, list) { |
| 1806 | if (itr->app.selector == app->selector && |
| 1807 | itr->app.protocol == app->protocol && |
| 1808 | itr->ifindex == ifindex && |
Petr Machata | 08193d1 | 2018-07-27 15:26:55 +0300 | [diff] [blame] | 1809 | ((prio == -1) || itr->app.priority == prio)) |
Thomas Graf | 716b31a | 2012-06-13 02:54:59 +0000 | [diff] [blame] | 1810 | return itr; |
| 1811 | } |
| 1812 | |
| 1813 | return NULL; |
| 1814 | } |
| 1815 | |
Thomas Graf | 4e4f2f6 | 2012-06-13 02:55:00 +0000 | [diff] [blame] | 1816 | static int dcb_app_add(const struct dcb_app *app, int ifindex) |
| 1817 | { |
| 1818 | struct dcb_app_type *entry; |
| 1819 | |
| 1820 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
| 1821 | if (!entry) |
| 1822 | return -ENOMEM; |
| 1823 | |
| 1824 | memcpy(&entry->app, app, sizeof(*app)); |
| 1825 | entry->ifindex = ifindex; |
| 1826 | list_add(&entry->list, &dcb_app_list); |
| 1827 | |
| 1828 | return 0; |
| 1829 | } |
| 1830 | |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1831 | /** |
| 1832 | * dcb_getapp - retrieve the DCBX application user priority |
| 1833 | * |
| 1834 | * On success returns a non-zero 802.1p user priority bitmap |
| 1835 | * otherwise returns 0 as the invalid user priority bitmap to |
| 1836 | * indicate an error. |
| 1837 | */ |
| 1838 | u8 dcb_getapp(struct net_device *dev, struct dcb_app *app) |
| 1839 | { |
| 1840 | struct dcb_app_type *itr; |
| 1841 | u8 prio = 0; |
| 1842 | |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1843 | spin_lock_bh(&dcb_lock); |
Petr Machata | 08193d1 | 2018-07-27 15:26:55 +0300 | [diff] [blame] | 1844 | itr = dcb_app_lookup(app, dev->ifindex, -1); |
| 1845 | if (itr) |
Thomas Graf | 716b31a | 2012-06-13 02:54:59 +0000 | [diff] [blame] | 1846 | prio = itr->app.priority; |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1847 | spin_unlock_bh(&dcb_lock); |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1848 | |
| 1849 | return prio; |
| 1850 | } |
| 1851 | EXPORT_SYMBOL(dcb_getapp); |
| 1852 | |
| 1853 | /** |
John Fastabend | b6db217 | 2011-06-21 07:34:42 +0000 | [diff] [blame] | 1854 | * dcb_setapp - add CEE dcb application data to app list |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1855 | * |
John Fastabend | b6db217 | 2011-06-21 07:34:42 +0000 | [diff] [blame] | 1856 | * Priority 0 is an invalid priority in CEE spec. This routine |
| 1857 | * removes applications from the app list if the priority is |
Anish Bhatt | 16eecd9 | 2014-07-28 20:57:07 -0700 | [diff] [blame] | 1858 | * set to zero. Priority is expected to be 8-bit 802.1p user priority bitmap |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1859 | */ |
John Fastabend | ab6baf9 | 2011-06-21 07:34:58 +0000 | [diff] [blame] | 1860 | int dcb_setapp(struct net_device *dev, struct dcb_app *new) |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1861 | { |
| 1862 | struct dcb_app_type *itr; |
John Fastabend | 7ec7927 | 2011-01-31 12:00:59 +0000 | [diff] [blame] | 1863 | struct dcb_app_type event; |
Thomas Graf | 4e4f2f6 | 2012-06-13 02:55:00 +0000 | [diff] [blame] | 1864 | int err = 0; |
John Fastabend | 7ec7927 | 2011-01-31 12:00:59 +0000 | [diff] [blame] | 1865 | |
Mark Rustad | e290ed8 | 2011-10-06 08:52:33 +0000 | [diff] [blame] | 1866 | event.ifindex = dev->ifindex; |
John Fastabend | 7ec7927 | 2011-01-31 12:00:59 +0000 | [diff] [blame] | 1867 | memcpy(&event.app, new, sizeof(event.app)); |
John Fastabend | 6bd0e1c | 2011-10-06 08:52:38 +0000 | [diff] [blame] | 1868 | if (dev->dcbnl_ops->getdcbx) |
| 1869 | event.dcbx = dev->dcbnl_ops->getdcbx(dev); |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1870 | |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1871 | spin_lock_bh(&dcb_lock); |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1872 | /* Search for existing match and replace */ |
Petr Machata | 08193d1 | 2018-07-27 15:26:55 +0300 | [diff] [blame] | 1873 | itr = dcb_app_lookup(new, dev->ifindex, -1); |
| 1874 | if (itr) { |
Thomas Graf | 716b31a | 2012-06-13 02:54:59 +0000 | [diff] [blame] | 1875 | if (new->priority) |
| 1876 | itr->app.priority = new->priority; |
| 1877 | else { |
| 1878 | list_del(&itr->list); |
| 1879 | kfree(itr); |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1880 | } |
Thomas Graf | 716b31a | 2012-06-13 02:54:59 +0000 | [diff] [blame] | 1881 | goto out; |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1882 | } |
| 1883 | /* App type does not exist add new application type */ |
Thomas Graf | 4e4f2f6 | 2012-06-13 02:55:00 +0000 | [diff] [blame] | 1884 | if (new->priority) |
| 1885 | err = dcb_app_add(new, dev->ifindex); |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1886 | out: |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1887 | spin_unlock_bh(&dcb_lock); |
Thomas Graf | 4e4f2f6 | 2012-06-13 02:55:00 +0000 | [diff] [blame] | 1888 | if (!err) |
| 1889 | call_dcbevent_notifiers(DCB_APP_EVENT, &event); |
| 1890 | return err; |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 1891 | } |
| 1892 | EXPORT_SYMBOL(dcb_setapp); |
| 1893 | |
John Fastabend | b6db217 | 2011-06-21 07:34:42 +0000 | [diff] [blame] | 1894 | /** |
John Fastabend | a364c8c | 2011-06-21 07:34:53 +0000 | [diff] [blame] | 1895 | * dcb_ieee_getapp_mask - retrieve the IEEE DCB application priority |
| 1896 | * |
| 1897 | * Helper routine which on success returns a non-zero 802.1Qaz user |
| 1898 | * priority bitmap otherwise returns 0 to indicate the dcb_app was |
| 1899 | * not found in APP list. |
| 1900 | */ |
| 1901 | u8 dcb_ieee_getapp_mask(struct net_device *dev, struct dcb_app *app) |
| 1902 | { |
| 1903 | struct dcb_app_type *itr; |
| 1904 | u8 prio = 0; |
| 1905 | |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1906 | spin_lock_bh(&dcb_lock); |
Petr Machata | 08193d1 | 2018-07-27 15:26:55 +0300 | [diff] [blame] | 1907 | itr = dcb_app_lookup(app, dev->ifindex, -1); |
| 1908 | if (itr) |
Thomas Graf | 716b31a | 2012-06-13 02:54:59 +0000 | [diff] [blame] | 1909 | prio |= 1 << itr->app.priority; |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1910 | spin_unlock_bh(&dcb_lock); |
John Fastabend | a364c8c | 2011-06-21 07:34:53 +0000 | [diff] [blame] | 1911 | |
| 1912 | return prio; |
| 1913 | } |
| 1914 | EXPORT_SYMBOL(dcb_ieee_getapp_mask); |
| 1915 | |
| 1916 | /** |
John Fastabend | b6db217 | 2011-06-21 07:34:42 +0000 | [diff] [blame] | 1917 | * dcb_ieee_setapp - add IEEE dcb application data to app list |
| 1918 | * |
| 1919 | * This adds Application data to the list. Multiple application |
| 1920 | * entries may exists for the same selector and protocol as long |
Anish Bhatt | 16eecd9 | 2014-07-28 20:57:07 -0700 | [diff] [blame] | 1921 | * as the priorities are different. Priority is expected to be a |
| 1922 | * 3-bit unsigned integer |
John Fastabend | b6db217 | 2011-06-21 07:34:42 +0000 | [diff] [blame] | 1923 | */ |
| 1924 | int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new) |
| 1925 | { |
John Fastabend | b6db217 | 2011-06-21 07:34:42 +0000 | [diff] [blame] | 1926 | struct dcb_app_type event; |
| 1927 | int err = 0; |
| 1928 | |
Mark Rustad | e290ed8 | 2011-10-06 08:52:33 +0000 | [diff] [blame] | 1929 | event.ifindex = dev->ifindex; |
John Fastabend | b6db217 | 2011-06-21 07:34:42 +0000 | [diff] [blame] | 1930 | memcpy(&event.app, new, sizeof(event.app)); |
John Fastabend | 6bd0e1c | 2011-10-06 08:52:38 +0000 | [diff] [blame] | 1931 | if (dev->dcbnl_ops->getdcbx) |
| 1932 | event.dcbx = dev->dcbnl_ops->getdcbx(dev); |
John Fastabend | b6db217 | 2011-06-21 07:34:42 +0000 | [diff] [blame] | 1933 | |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1934 | spin_lock_bh(&dcb_lock); |
John Fastabend | b6db217 | 2011-06-21 07:34:42 +0000 | [diff] [blame] | 1935 | /* Search for existing match and abort if found */ |
Thomas Graf | 716b31a | 2012-06-13 02:54:59 +0000 | [diff] [blame] | 1936 | if (dcb_app_lookup(new, dev->ifindex, new->priority)) { |
| 1937 | err = -EEXIST; |
| 1938 | goto out; |
John Fastabend | b6db217 | 2011-06-21 07:34:42 +0000 | [diff] [blame] | 1939 | } |
| 1940 | |
Thomas Graf | 4e4f2f6 | 2012-06-13 02:55:00 +0000 | [diff] [blame] | 1941 | err = dcb_app_add(new, dev->ifindex); |
John Fastabend | b6db217 | 2011-06-21 07:34:42 +0000 | [diff] [blame] | 1942 | out: |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1943 | spin_unlock_bh(&dcb_lock); |
John Fastabend | b6db217 | 2011-06-21 07:34:42 +0000 | [diff] [blame] | 1944 | if (!err) |
| 1945 | call_dcbevent_notifiers(DCB_APP_EVENT, &event); |
| 1946 | return err; |
| 1947 | } |
| 1948 | EXPORT_SYMBOL(dcb_ieee_setapp); |
| 1949 | |
John Fastabend | f9ae7e4 | 2011-06-21 07:34:48 +0000 | [diff] [blame] | 1950 | /** |
| 1951 | * dcb_ieee_delapp - delete IEEE dcb application data from list |
| 1952 | * |
| 1953 | * This removes a matching APP data from the APP list |
| 1954 | */ |
| 1955 | int dcb_ieee_delapp(struct net_device *dev, struct dcb_app *del) |
| 1956 | { |
| 1957 | struct dcb_app_type *itr; |
| 1958 | struct dcb_app_type event; |
| 1959 | int err = -ENOENT; |
| 1960 | |
Mark Rustad | e290ed8 | 2011-10-06 08:52:33 +0000 | [diff] [blame] | 1961 | event.ifindex = dev->ifindex; |
John Fastabend | f9ae7e4 | 2011-06-21 07:34:48 +0000 | [diff] [blame] | 1962 | memcpy(&event.app, del, sizeof(event.app)); |
John Fastabend | 6bd0e1c | 2011-10-06 08:52:38 +0000 | [diff] [blame] | 1963 | if (dev->dcbnl_ops->getdcbx) |
| 1964 | event.dcbx = dev->dcbnl_ops->getdcbx(dev); |
John Fastabend | f9ae7e4 | 2011-06-21 07:34:48 +0000 | [diff] [blame] | 1965 | |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1966 | spin_lock_bh(&dcb_lock); |
John Fastabend | f9ae7e4 | 2011-06-21 07:34:48 +0000 | [diff] [blame] | 1967 | /* Search for existing match and remove it. */ |
Thomas Graf | 716b31a | 2012-06-13 02:54:59 +0000 | [diff] [blame] | 1968 | if ((itr = dcb_app_lookup(del, dev->ifindex, del->priority))) { |
| 1969 | list_del(&itr->list); |
| 1970 | kfree(itr); |
| 1971 | err = 0; |
John Fastabend | f9ae7e4 | 2011-06-21 07:34:48 +0000 | [diff] [blame] | 1972 | } |
| 1973 | |
Anish Bhatt | 52cff74 | 2014-11-14 16:38:31 -0800 | [diff] [blame] | 1974 | spin_unlock_bh(&dcb_lock); |
John Fastabend | f9ae7e4 | 2011-06-21 07:34:48 +0000 | [diff] [blame] | 1975 | if (!err) |
| 1976 | call_dcbevent_notifiers(DCB_APP_EVENT, &event); |
| 1977 | return err; |
| 1978 | } |
| 1979 | EXPORT_SYMBOL(dcb_ieee_delapp); |
| 1980 | |
Petr Machata | b67c540 | 2018-07-27 15:26:56 +0300 | [diff] [blame] | 1981 | /** |
| 1982 | * dcb_ieee_getapp_prio_dscp_mask_map - For a given device, find mapping from |
| 1983 | * priorities to the DSCP values assigned to that priority. Initialize p_map |
| 1984 | * such that each map element holds a bit mask of DSCP values configured for |
| 1985 | * that priority by APP entries. |
| 1986 | */ |
| 1987 | void dcb_ieee_getapp_prio_dscp_mask_map(const struct net_device *dev, |
| 1988 | struct dcb_ieee_app_prio_map *p_map) |
| 1989 | { |
| 1990 | int ifindex = dev->ifindex; |
| 1991 | struct dcb_app_type *itr; |
| 1992 | u8 prio; |
| 1993 | |
| 1994 | memset(p_map->map, 0, sizeof(p_map->map)); |
| 1995 | |
| 1996 | spin_lock_bh(&dcb_lock); |
| 1997 | list_for_each_entry(itr, &dcb_app_list, list) { |
| 1998 | if (itr->ifindex == ifindex && |
| 1999 | itr->app.selector == IEEE_8021QAZ_APP_SEL_DSCP && |
| 2000 | itr->app.protocol < 64 && |
| 2001 | itr->app.priority < IEEE_8021QAZ_MAX_TCS) { |
| 2002 | prio = itr->app.priority; |
| 2003 | p_map->map[prio] |= 1ULL << itr->app.protocol; |
| 2004 | } |
| 2005 | } |
| 2006 | spin_unlock_bh(&dcb_lock); |
| 2007 | } |
| 2008 | EXPORT_SYMBOL(dcb_ieee_getapp_prio_dscp_mask_map); |
| 2009 | |
| 2010 | /** |
| 2011 | * dcb_ieee_getapp_dscp_prio_mask_map - For a given device, find mapping from |
| 2012 | * DSCP values to the priorities assigned to that DSCP value. Initialize p_map |
| 2013 | * such that each map element holds a bit mask of priorities configured for a |
| 2014 | * given DSCP value by APP entries. |
| 2015 | */ |
| 2016 | void |
| 2017 | dcb_ieee_getapp_dscp_prio_mask_map(const struct net_device *dev, |
| 2018 | struct dcb_ieee_app_dscp_map *p_map) |
| 2019 | { |
| 2020 | int ifindex = dev->ifindex; |
| 2021 | struct dcb_app_type *itr; |
| 2022 | |
| 2023 | memset(p_map->map, 0, sizeof(p_map->map)); |
| 2024 | |
| 2025 | spin_lock_bh(&dcb_lock); |
| 2026 | list_for_each_entry(itr, &dcb_app_list, list) { |
| 2027 | if (itr->ifindex == ifindex && |
| 2028 | itr->app.selector == IEEE_8021QAZ_APP_SEL_DSCP && |
| 2029 | itr->app.protocol < 64 && |
| 2030 | itr->app.priority < IEEE_8021QAZ_MAX_TCS) |
| 2031 | p_map->map[itr->app.protocol] |= 1 << itr->app.priority; |
| 2032 | } |
| 2033 | spin_unlock_bh(&dcb_lock); |
| 2034 | } |
| 2035 | EXPORT_SYMBOL(dcb_ieee_getapp_dscp_prio_mask_map); |
| 2036 | |
| 2037 | /** |
| 2038 | * Per 802.1Q-2014, the selector value of 1 is used for matching on Ethernet |
| 2039 | * type, with valid PID values >= 1536. A special meaning is then assigned to |
| 2040 | * protocol value of 0: "default priority. For use when priority is not |
| 2041 | * otherwise specified". |
| 2042 | * |
| 2043 | * dcb_ieee_getapp_default_prio_mask - For a given device, find all APP entries |
| 2044 | * of the form {$PRIO, ETHERTYPE, 0} and construct a bit mask of all default |
| 2045 | * priorities set by these entries. |
| 2046 | */ |
| 2047 | u8 dcb_ieee_getapp_default_prio_mask(const struct net_device *dev) |
| 2048 | { |
| 2049 | int ifindex = dev->ifindex; |
| 2050 | struct dcb_app_type *itr; |
| 2051 | u8 mask = 0; |
| 2052 | |
| 2053 | spin_lock_bh(&dcb_lock); |
| 2054 | list_for_each_entry(itr, &dcb_app_list, list) { |
| 2055 | if (itr->ifindex == ifindex && |
| 2056 | itr->app.selector == IEEE_8021QAZ_APP_SEL_ETHERTYPE && |
| 2057 | itr->app.protocol == 0 && |
| 2058 | itr->app.priority < IEEE_8021QAZ_MAX_TCS) |
| 2059 | mask |= 1 << itr->app.priority; |
| 2060 | } |
| 2061 | spin_unlock_bh(&dcb_lock); |
| 2062 | |
| 2063 | return mask; |
| 2064 | } |
| 2065 | EXPORT_SYMBOL(dcb_ieee_getapp_default_prio_mask); |
| 2066 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2067 | static int __init dcbnl_init(void) |
| 2068 | { |
John Fastabend | 9ab933a | 2010-12-30 09:26:31 +0000 | [diff] [blame] | 2069 | INIT_LIST_HEAD(&dcb_app_list); |
| 2070 | |
Florian Westphal | b97bac6 | 2017-08-09 20:41:48 +0200 | [diff] [blame] | 2071 | rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL, 0); |
| 2072 | rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL, 0); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2073 | |
| 2074 | return 0; |
| 2075 | } |
Paul Gortmaker | 36b9ad80 | 2015-10-07 17:27:44 -0400 | [diff] [blame] | 2076 | device_initcall(dcbnl_init); |