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