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