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