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