Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net-sysfs.c - network device class and attributes |
| 3 | * |
| 4 | * Copyright (c) 2003 Stephen Hemminger <shemminger@osdl.org> |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 5 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 12 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/kernel.h> |
| 14 | #include <linux/netdevice.h> |
| 15 | #include <linux/if_arp.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Eric W. Biederman | 608b4b9 | 2010-05-04 17:36:45 -0700 | [diff] [blame] | 17 | #include <linux/nsproxy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <net/sock.h> |
Eric W. Biederman | 608b4b9 | 2010-05-04 17:36:45 -0700 | [diff] [blame] | 19 | #include <net/net_namespace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/rtnetlink.h> |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 21 | #include <linux/vmalloc.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 22 | #include <linux/export.h> |
Tom Herbert | 114cf58 | 2011-11-28 16:33:09 +0000 | [diff] [blame] | 23 | #include <linux/jiffies.h> |
Ming Lei | 9802c8e | 2013-02-22 16:34:16 -0800 | [diff] [blame] | 24 | #include <linux/pm_runtime.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Pavel Emelyanov | 342709e | 2007-10-23 21:14:45 -0700 | [diff] [blame] | 26 | #include "net-sysfs.h" |
| 27 | |
Eric W. Biederman | 8b41d18 | 2007-09-26 22:02:53 -0700 | [diff] [blame] | 28 | #ifdef CONFIG_SYSFS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | static const char fmt_hex[] = "%#x\n"; |
David S. Miller | d1102b5 | 2005-05-29 20:28:25 -0700 | [diff] [blame] | 30 | static const char fmt_long_hex[] = "%#lx\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | static const char fmt_dec[] = "%d\n"; |
David Decotigny | 8ae6dac | 2011-04-27 18:32:38 +0000 | [diff] [blame] | 32 | static const char fmt_udec[] = "%u\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | static const char fmt_ulong[] = "%lu\n"; |
Ben Hutchings | be1f3c2 | 2010-06-08 07:19:54 +0000 | [diff] [blame] | 34 | static const char fmt_u64[] = "%llu\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 36 | static inline int dev_isalive(const struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | { |
Stephen Hemminger | fe9925b | 2006-05-06 17:56:03 -0700 | [diff] [blame] | 38 | return dev->reg_state <= NETREG_REGISTERED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | /* use same locking rules as GIF* ioctl's */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 42 | static ssize_t netdev_show(const struct device *dev, |
| 43 | struct device_attribute *attr, char *buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | ssize_t (*format)(const struct net_device *, char *)) |
| 45 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 46 | struct net_device *net = to_net_dev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | ssize_t ret = -EINVAL; |
| 48 | |
| 49 | read_lock(&dev_base_lock); |
| 50 | if (dev_isalive(net)) |
| 51 | ret = (*format)(net, buf); |
| 52 | read_unlock(&dev_base_lock); |
| 53 | |
| 54 | return ret; |
| 55 | } |
| 56 | |
| 57 | /* generate a show function for simple field */ |
| 58 | #define NETDEVICE_SHOW(field, format_string) \ |
| 59 | static ssize_t format_##field(const struct net_device *net, char *buf) \ |
| 60 | { \ |
| 61 | return sprintf(buf, format_string, net->field); \ |
| 62 | } \ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 63 | static ssize_t show_##field(struct device *dev, \ |
| 64 | struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { \ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 66 | return netdev_show(dev, attr, buf, format_##field); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | |
| 70 | /* use same locking and permission rules as SIF* ioctl's */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 71 | static ssize_t netdev_store(struct device *dev, struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | const char *buf, size_t len, |
| 73 | int (*set)(struct net_device *, unsigned long)) |
| 74 | { |
Eric W. Biederman | 5e1fccc | 2012-11-16 03:03:04 +0000 | [diff] [blame] | 75 | struct net_device *netdev = to_net_dev(dev); |
| 76 | struct net *net = dev_net(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | unsigned long new; |
| 78 | int ret = -EINVAL; |
| 79 | |
Eric W. Biederman | 5e1fccc | 2012-11-16 03:03:04 +0000 | [diff] [blame] | 80 | if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | return -EPERM; |
| 82 | |
Shuah Khan | e1e420c | 2012-04-12 09:28:13 +0000 | [diff] [blame] | 83 | ret = kstrtoul(buf, 0, &new); |
| 84 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | goto err; |
| 86 | |
Stephen Hemminger | 5a5990d | 2009-02-26 06:49:24 +0000 | [diff] [blame] | 87 | if (!rtnl_trylock()) |
Eric W. Biederman | 336ca57 | 2009-05-13 16:57:25 +0000 | [diff] [blame] | 88 | return restart_syscall(); |
Stephen Hemminger | 5a5990d | 2009-02-26 06:49:24 +0000 | [diff] [blame] | 89 | |
Eric W. Biederman | 5e1fccc | 2012-11-16 03:03:04 +0000 | [diff] [blame] | 90 | if (dev_isalive(netdev)) { |
| 91 | if ((ret = (*set)(netdev, new)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | ret = len; |
| 93 | } |
| 94 | rtnl_unlock(); |
| 95 | err: |
| 96 | return ret; |
| 97 | } |
| 98 | |
David Woodhouse | 9d29672 | 2008-04-20 16:07:43 -0700 | [diff] [blame] | 99 | NETDEVICE_SHOW(dev_id, fmt_hex); |
Stefan Assmann | c1f7942 | 2010-07-22 02:50:21 +0000 | [diff] [blame] | 100 | NETDEVICE_SHOW(addr_assign_type, fmt_dec); |
Kay Sievers | fd586ba | 2005-12-19 01:42:56 +0100 | [diff] [blame] | 101 | NETDEVICE_SHOW(addr_len, fmt_dec); |
| 102 | NETDEVICE_SHOW(iflink, fmt_dec); |
| 103 | NETDEVICE_SHOW(ifindex, fmt_dec); |
Kay Sievers | fd586ba | 2005-12-19 01:42:56 +0100 | [diff] [blame] | 104 | NETDEVICE_SHOW(type, fmt_dec); |
Stefan Rompf | b00055a | 2006-03-20 17:09:11 -0800 | [diff] [blame] | 105 | NETDEVICE_SHOW(link_mode, fmt_dec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | /* use same locking rules as GIFHWADDR ioctl's */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 108 | static ssize_t show_address(struct device *dev, struct device_attribute *attr, |
| 109 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
| 111 | struct net_device *net = to_net_dev(dev); |
| 112 | ssize_t ret = -EINVAL; |
| 113 | |
| 114 | read_lock(&dev_base_lock); |
| 115 | if (dev_isalive(net)) |
Michael Chan | 7ffc49a | 2007-12-24 21:28:09 -0800 | [diff] [blame] | 116 | ret = sysfs_format_mac(buf, net->dev_addr, net->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | read_unlock(&dev_base_lock); |
| 118 | return ret; |
| 119 | } |
| 120 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 121 | static ssize_t show_broadcast(struct device *dev, |
| 122 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | struct net_device *net = to_net_dev(dev); |
| 125 | if (dev_isalive(net)) |
Michael Chan | 7ffc49a | 2007-12-24 21:28:09 -0800 | [diff] [blame] | 126 | return sysfs_format_mac(buf, net->broadcast, net->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | return -EINVAL; |
| 128 | } |
| 129 | |
Jiri Pirko | fdae0fd | 2012-12-27 23:49:38 +0000 | [diff] [blame] | 130 | static int change_carrier(struct net_device *net, unsigned long new_carrier) |
| 131 | { |
| 132 | if (!netif_running(net)) |
| 133 | return -EINVAL; |
| 134 | return dev_change_carrier(net, (bool) new_carrier); |
| 135 | } |
| 136 | |
| 137 | static ssize_t store_carrier(struct device *dev, struct device_attribute *attr, |
| 138 | const char *buf, size_t len) |
| 139 | { |
| 140 | return netdev_store(dev, attr, buf, len, change_carrier); |
| 141 | } |
| 142 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 143 | static ssize_t show_carrier(struct device *dev, |
| 144 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
| 146 | struct net_device *netdev = to_net_dev(dev); |
| 147 | if (netif_running(netdev)) { |
| 148 | return sprintf(buf, fmt_dec, !!netif_carrier_ok(netdev)); |
| 149 | } |
| 150 | return -EINVAL; |
| 151 | } |
| 152 | |
Andy Gospodarek | d519e17 | 2009-10-02 09:26:12 +0000 | [diff] [blame] | 153 | static ssize_t show_speed(struct device *dev, |
| 154 | struct device_attribute *attr, char *buf) |
| 155 | { |
| 156 | struct net_device *netdev = to_net_dev(dev); |
| 157 | int ret = -EINVAL; |
| 158 | |
| 159 | if (!rtnl_trylock()) |
| 160 | return restart_syscall(); |
| 161 | |
David Decotigny | 8ae6dac | 2011-04-27 18:32:38 +0000 | [diff] [blame] | 162 | if (netif_running(netdev)) { |
| 163 | struct ethtool_cmd cmd; |
Jiri Pirko | 4bc71cb | 2011-09-03 03:34:30 +0000 | [diff] [blame] | 164 | if (!__ethtool_get_settings(netdev, &cmd)) |
David Decotigny | 8ae6dac | 2011-04-27 18:32:38 +0000 | [diff] [blame] | 165 | ret = sprintf(buf, fmt_udec, ethtool_cmd_speed(&cmd)); |
Andy Gospodarek | d519e17 | 2009-10-02 09:26:12 +0000 | [diff] [blame] | 166 | } |
| 167 | rtnl_unlock(); |
| 168 | return ret; |
| 169 | } |
| 170 | |
| 171 | static ssize_t show_duplex(struct device *dev, |
| 172 | struct device_attribute *attr, char *buf) |
| 173 | { |
| 174 | struct net_device *netdev = to_net_dev(dev); |
| 175 | int ret = -EINVAL; |
| 176 | |
| 177 | if (!rtnl_trylock()) |
| 178 | return restart_syscall(); |
| 179 | |
David Decotigny | 8ae6dac | 2011-04-27 18:32:38 +0000 | [diff] [blame] | 180 | if (netif_running(netdev)) { |
| 181 | struct ethtool_cmd cmd; |
Nikolay Aleksandrov | c6c1396 | 2012-09-05 04:11:28 +0000 | [diff] [blame] | 182 | if (!__ethtool_get_settings(netdev, &cmd)) { |
| 183 | const char *duplex; |
| 184 | switch (cmd.duplex) { |
| 185 | case DUPLEX_HALF: |
| 186 | duplex = "half"; |
| 187 | break; |
| 188 | case DUPLEX_FULL: |
| 189 | duplex = "full"; |
| 190 | break; |
| 191 | default: |
| 192 | duplex = "unknown"; |
| 193 | break; |
| 194 | } |
| 195 | ret = sprintf(buf, "%s\n", duplex); |
| 196 | } |
Andy Gospodarek | d519e17 | 2009-10-02 09:26:12 +0000 | [diff] [blame] | 197 | } |
| 198 | rtnl_unlock(); |
| 199 | return ret; |
| 200 | } |
| 201 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 202 | static ssize_t show_dormant(struct device *dev, |
| 203 | struct device_attribute *attr, char *buf) |
Stefan Rompf | b00055a | 2006-03-20 17:09:11 -0800 | [diff] [blame] | 204 | { |
| 205 | struct net_device *netdev = to_net_dev(dev); |
| 206 | |
| 207 | if (netif_running(netdev)) |
| 208 | return sprintf(buf, fmt_dec, !!netif_dormant(netdev)); |
| 209 | |
| 210 | return -EINVAL; |
| 211 | } |
| 212 | |
Jan Engelhardt | 36cbd3d | 2009-08-05 10:42:58 -0700 | [diff] [blame] | 213 | static const char *const operstates[] = { |
Stefan Rompf | b00055a | 2006-03-20 17:09:11 -0800 | [diff] [blame] | 214 | "unknown", |
| 215 | "notpresent", /* currently unused */ |
| 216 | "down", |
| 217 | "lowerlayerdown", |
| 218 | "testing", /* currently unused */ |
| 219 | "dormant", |
| 220 | "up" |
| 221 | }; |
| 222 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 223 | static ssize_t show_operstate(struct device *dev, |
| 224 | struct device_attribute *attr, char *buf) |
Stefan Rompf | b00055a | 2006-03-20 17:09:11 -0800 | [diff] [blame] | 225 | { |
| 226 | const struct net_device *netdev = to_net_dev(dev); |
| 227 | unsigned char operstate; |
| 228 | |
| 229 | read_lock(&dev_base_lock); |
| 230 | operstate = netdev->operstate; |
| 231 | if (!netif_running(netdev)) |
| 232 | operstate = IF_OPER_DOWN; |
| 233 | read_unlock(&dev_base_lock); |
| 234 | |
Adrian Bunk | e3a5cd9 | 2006-04-05 22:19:47 -0700 | [diff] [blame] | 235 | if (operstate >= ARRAY_SIZE(operstates)) |
Stefan Rompf | b00055a | 2006-03-20 17:09:11 -0800 | [diff] [blame] | 236 | return -EINVAL; /* should not happen */ |
| 237 | |
| 238 | return sprintf(buf, "%s\n", operstates[operstate]); |
| 239 | } |
| 240 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | /* read-write attributes */ |
| 242 | NETDEVICE_SHOW(mtu, fmt_dec); |
| 243 | |
| 244 | static int change_mtu(struct net_device *net, unsigned long new_mtu) |
| 245 | { |
| 246 | return dev_set_mtu(net, (int) new_mtu); |
| 247 | } |
| 248 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 249 | static ssize_t store_mtu(struct device *dev, struct device_attribute *attr, |
| 250 | const char *buf, size_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 252 | return netdev_store(dev, attr, buf, len, change_mtu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | NETDEVICE_SHOW(flags, fmt_hex); |
| 256 | |
| 257 | static int change_flags(struct net_device *net, unsigned long new_flags) |
| 258 | { |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 259 | return dev_change_flags(net, (unsigned int) new_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 262 | static ssize_t store_flags(struct device *dev, struct device_attribute *attr, |
| 263 | const char *buf, size_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 265 | return netdev_store(dev, attr, buf, len, change_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | NETDEVICE_SHOW(tx_queue_len, fmt_ulong); |
| 269 | |
| 270 | static int change_tx_queue_len(struct net_device *net, unsigned long new_len) |
| 271 | { |
| 272 | net->tx_queue_len = new_len; |
| 273 | return 0; |
| 274 | } |
| 275 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 276 | static ssize_t store_tx_queue_len(struct device *dev, |
| 277 | struct device_attribute *attr, |
| 278 | const char *buf, size_t len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | { |
Eric W. Biederman | 5e1fccc | 2012-11-16 03:03:04 +0000 | [diff] [blame] | 280 | if (!capable(CAP_NET_ADMIN)) |
| 281 | return -EPERM; |
| 282 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 283 | return netdev_store(dev, attr, buf, len, change_tx_queue_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Stephen Hemminger | 0b815a1 | 2008-09-22 21:28:11 -0700 | [diff] [blame] | 286 | static ssize_t store_ifalias(struct device *dev, struct device_attribute *attr, |
| 287 | const char *buf, size_t len) |
| 288 | { |
| 289 | struct net_device *netdev = to_net_dev(dev); |
Eric W. Biederman | 5e1fccc | 2012-11-16 03:03:04 +0000 | [diff] [blame] | 290 | struct net *net = dev_net(netdev); |
Stephen Hemminger | 0b815a1 | 2008-09-22 21:28:11 -0700 | [diff] [blame] | 291 | size_t count = len; |
| 292 | ssize_t ret; |
| 293 | |
Eric W. Biederman | 5e1fccc | 2012-11-16 03:03:04 +0000 | [diff] [blame] | 294 | if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) |
Stephen Hemminger | 0b815a1 | 2008-09-22 21:28:11 -0700 | [diff] [blame] | 295 | return -EPERM; |
| 296 | |
| 297 | /* ignore trailing newline */ |
| 298 | if (len > 0 && buf[len - 1] == '\n') |
| 299 | --count; |
| 300 | |
Eric W. Biederman | 336ca57 | 2009-05-13 16:57:25 +0000 | [diff] [blame] | 301 | if (!rtnl_trylock()) |
| 302 | return restart_syscall(); |
Stephen Hemminger | 0b815a1 | 2008-09-22 21:28:11 -0700 | [diff] [blame] | 303 | ret = dev_set_alias(netdev, buf, count); |
| 304 | rtnl_unlock(); |
| 305 | |
| 306 | return ret < 0 ? ret : len; |
| 307 | } |
| 308 | |
| 309 | static ssize_t show_ifalias(struct device *dev, |
| 310 | struct device_attribute *attr, char *buf) |
| 311 | { |
| 312 | const struct net_device *netdev = to_net_dev(dev); |
| 313 | ssize_t ret = 0; |
| 314 | |
Eric W. Biederman | 336ca57 | 2009-05-13 16:57:25 +0000 | [diff] [blame] | 315 | if (!rtnl_trylock()) |
| 316 | return restart_syscall(); |
Stephen Hemminger | 0b815a1 | 2008-09-22 21:28:11 -0700 | [diff] [blame] | 317 | if (netdev->ifalias) |
| 318 | ret = sprintf(buf, "%s\n", netdev->ifalias); |
| 319 | rtnl_unlock(); |
| 320 | return ret; |
| 321 | } |
| 322 | |
Vlad Dogaru | a512b92 | 2011-01-24 03:37:29 +0000 | [diff] [blame] | 323 | NETDEVICE_SHOW(group, fmt_dec); |
| 324 | |
| 325 | static int change_group(struct net_device *net, unsigned long new_group) |
| 326 | { |
| 327 | dev_set_group(net, (int) new_group); |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static ssize_t store_group(struct device *dev, struct device_attribute *attr, |
| 332 | const char *buf, size_t len) |
| 333 | { |
| 334 | return netdev_store(dev, attr, buf, len, change_group); |
| 335 | } |
| 336 | |
Jiri Pirko | ff80e51 | 2013-07-29 18:16:51 +0200 | [diff] [blame^] | 337 | static ssize_t show_phys_port_id(struct device *dev, |
| 338 | struct device_attribute *attr, char *buf) |
| 339 | { |
| 340 | struct net_device *netdev = to_net_dev(dev); |
| 341 | ssize_t ret = -EINVAL; |
| 342 | |
| 343 | if (!rtnl_trylock()) |
| 344 | return restart_syscall(); |
| 345 | |
| 346 | if (dev_isalive(netdev)) { |
| 347 | struct netdev_phys_port_id ppid; |
| 348 | |
| 349 | ret = dev_get_phys_port_id(netdev, &ppid); |
| 350 | if (!ret) |
| 351 | ret = sprintf(buf, "%*phN\n", ppid.id_len, ppid.id); |
| 352 | } |
| 353 | rtnl_unlock(); |
| 354 | |
| 355 | return ret; |
| 356 | } |
| 357 | |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 358 | static struct device_attribute net_class_attributes[] = { |
Stefan Assmann | c1f7942 | 2010-07-22 02:50:21 +0000 | [diff] [blame] | 359 | __ATTR(addr_assign_type, S_IRUGO, show_addr_assign_type, NULL), |
Kay Sievers | fd586ba | 2005-12-19 01:42:56 +0100 | [diff] [blame] | 360 | __ATTR(addr_len, S_IRUGO, show_addr_len, NULL), |
David Woodhouse | 9d29672 | 2008-04-20 16:07:43 -0700 | [diff] [blame] | 361 | __ATTR(dev_id, S_IRUGO, show_dev_id, NULL), |
Stephen Hemminger | 0b815a1 | 2008-09-22 21:28:11 -0700 | [diff] [blame] | 362 | __ATTR(ifalias, S_IRUGO | S_IWUSR, show_ifalias, store_ifalias), |
Kay Sievers | fd586ba | 2005-12-19 01:42:56 +0100 | [diff] [blame] | 363 | __ATTR(iflink, S_IRUGO, show_iflink, NULL), |
| 364 | __ATTR(ifindex, S_IRUGO, show_ifindex, NULL), |
Kay Sievers | fd586ba | 2005-12-19 01:42:56 +0100 | [diff] [blame] | 365 | __ATTR(type, S_IRUGO, show_type, NULL), |
Stefan Rompf | b00055a | 2006-03-20 17:09:11 -0800 | [diff] [blame] | 366 | __ATTR(link_mode, S_IRUGO, show_link_mode, NULL), |
Kay Sievers | fd586ba | 2005-12-19 01:42:56 +0100 | [diff] [blame] | 367 | __ATTR(address, S_IRUGO, show_address, NULL), |
| 368 | __ATTR(broadcast, S_IRUGO, show_broadcast, NULL), |
Jiri Pirko | fdae0fd | 2012-12-27 23:49:38 +0000 | [diff] [blame] | 369 | __ATTR(carrier, S_IRUGO | S_IWUSR, show_carrier, store_carrier), |
Andy Gospodarek | d519e17 | 2009-10-02 09:26:12 +0000 | [diff] [blame] | 370 | __ATTR(speed, S_IRUGO, show_speed, NULL), |
| 371 | __ATTR(duplex, S_IRUGO, show_duplex, NULL), |
Stefan Rompf | b00055a | 2006-03-20 17:09:11 -0800 | [diff] [blame] | 372 | __ATTR(dormant, S_IRUGO, show_dormant, NULL), |
| 373 | __ATTR(operstate, S_IRUGO, show_operstate, NULL), |
Kay Sievers | fd586ba | 2005-12-19 01:42:56 +0100 | [diff] [blame] | 374 | __ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu), |
| 375 | __ATTR(flags, S_IRUGO | S_IWUSR, show_flags, store_flags), |
| 376 | __ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len, |
| 377 | store_tx_queue_len), |
Xiaotian Feng | b6644cb | 2011-02-09 19:16:15 -0800 | [diff] [blame] | 378 | __ATTR(netdev_group, S_IRUGO | S_IWUSR, show_group, store_group), |
Jiri Pirko | ff80e51 | 2013-07-29 18:16:51 +0200 | [diff] [blame^] | 379 | __ATTR(phys_port_id, S_IRUGO, show_phys_port_id, NULL), |
Kay Sievers | fd586ba | 2005-12-19 01:42:56 +0100 | [diff] [blame] | 380 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | }; |
| 382 | |
| 383 | /* Show a given an attribute in the statistics group */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 384 | static ssize_t netstat_show(const struct device *d, |
| 385 | struct device_attribute *attr, char *buf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | unsigned long offset) |
| 387 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 388 | struct net_device *dev = to_net_dev(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | ssize_t ret = -EINVAL; |
| 390 | |
Ben Hutchings | be1f3c2 | 2010-06-08 07:19:54 +0000 | [diff] [blame] | 391 | WARN_ON(offset > sizeof(struct rtnl_link_stats64) || |
| 392 | offset % sizeof(u64) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
| 394 | read_lock(&dev_base_lock); |
Pavel Emelyanov | 96e7408 | 2008-05-21 14:12:46 -0700 | [diff] [blame] | 395 | if (dev_isalive(dev)) { |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 396 | struct rtnl_link_stats64 temp; |
| 397 | const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp); |
| 398 | |
Ben Hutchings | be1f3c2 | 2010-06-08 07:19:54 +0000 | [diff] [blame] | 399 | ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *) stats) + offset)); |
Pavel Emelyanov | 96e7408 | 2008-05-21 14:12:46 -0700 | [diff] [blame] | 400 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | read_unlock(&dev_base_lock); |
| 402 | return ret; |
| 403 | } |
| 404 | |
| 405 | /* generate a read-only statistics attribute */ |
| 406 | #define NETSTAT_ENTRY(name) \ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 407 | static ssize_t show_##name(struct device *d, \ |
| 408 | struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | { \ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 410 | return netstat_show(d, attr, buf, \ |
Ben Hutchings | be1f3c2 | 2010-06-08 07:19:54 +0000 | [diff] [blame] | 411 | offsetof(struct rtnl_link_stats64, name)); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } \ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 413 | static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
| 415 | NETSTAT_ENTRY(rx_packets); |
| 416 | NETSTAT_ENTRY(tx_packets); |
| 417 | NETSTAT_ENTRY(rx_bytes); |
| 418 | NETSTAT_ENTRY(tx_bytes); |
| 419 | NETSTAT_ENTRY(rx_errors); |
| 420 | NETSTAT_ENTRY(tx_errors); |
| 421 | NETSTAT_ENTRY(rx_dropped); |
| 422 | NETSTAT_ENTRY(tx_dropped); |
| 423 | NETSTAT_ENTRY(multicast); |
| 424 | NETSTAT_ENTRY(collisions); |
| 425 | NETSTAT_ENTRY(rx_length_errors); |
| 426 | NETSTAT_ENTRY(rx_over_errors); |
| 427 | NETSTAT_ENTRY(rx_crc_errors); |
| 428 | NETSTAT_ENTRY(rx_frame_errors); |
| 429 | NETSTAT_ENTRY(rx_fifo_errors); |
| 430 | NETSTAT_ENTRY(rx_missed_errors); |
| 431 | NETSTAT_ENTRY(tx_aborted_errors); |
| 432 | NETSTAT_ENTRY(tx_carrier_errors); |
| 433 | NETSTAT_ENTRY(tx_fifo_errors); |
| 434 | NETSTAT_ENTRY(tx_heartbeat_errors); |
| 435 | NETSTAT_ENTRY(tx_window_errors); |
| 436 | NETSTAT_ENTRY(rx_compressed); |
| 437 | NETSTAT_ENTRY(tx_compressed); |
| 438 | |
| 439 | static struct attribute *netstat_attrs[] = { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 440 | &dev_attr_rx_packets.attr, |
| 441 | &dev_attr_tx_packets.attr, |
| 442 | &dev_attr_rx_bytes.attr, |
| 443 | &dev_attr_tx_bytes.attr, |
| 444 | &dev_attr_rx_errors.attr, |
| 445 | &dev_attr_tx_errors.attr, |
| 446 | &dev_attr_rx_dropped.attr, |
| 447 | &dev_attr_tx_dropped.attr, |
| 448 | &dev_attr_multicast.attr, |
| 449 | &dev_attr_collisions.attr, |
| 450 | &dev_attr_rx_length_errors.attr, |
| 451 | &dev_attr_rx_over_errors.attr, |
| 452 | &dev_attr_rx_crc_errors.attr, |
| 453 | &dev_attr_rx_frame_errors.attr, |
| 454 | &dev_attr_rx_fifo_errors.attr, |
| 455 | &dev_attr_rx_missed_errors.attr, |
| 456 | &dev_attr_tx_aborted_errors.attr, |
| 457 | &dev_attr_tx_carrier_errors.attr, |
| 458 | &dev_attr_tx_fifo_errors.attr, |
| 459 | &dev_attr_tx_heartbeat_errors.attr, |
| 460 | &dev_attr_tx_window_errors.attr, |
| 461 | &dev_attr_rx_compressed.attr, |
| 462 | &dev_attr_tx_compressed.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | NULL |
| 464 | }; |
| 465 | |
| 466 | |
| 467 | static struct attribute_group netstat_group = { |
| 468 | .name = "statistics", |
| 469 | .attrs = netstat_attrs, |
| 470 | }; |
Johannes Berg | 38c1a01 | 2012-11-16 20:46:19 +0100 | [diff] [blame] | 471 | |
| 472 | #if IS_ENABLED(CONFIG_WIRELESS_EXT) || IS_ENABLED(CONFIG_CFG80211) |
| 473 | static struct attribute *wireless_attrs[] = { |
| 474 | NULL |
| 475 | }; |
| 476 | |
| 477 | static struct attribute_group wireless_group = { |
| 478 | .name = "wireless", |
| 479 | .attrs = wireless_attrs, |
| 480 | }; |
| 481 | #endif |
Eric W. Biederman | d6523dd | 2010-05-16 21:59:45 -0700 | [diff] [blame] | 482 | #endif /* CONFIG_SYSFS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
Stephen Rothwell | 30bde1f | 2010-03-29 01:00:44 -0700 | [diff] [blame] | 484 | #ifdef CONFIG_RPS |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 485 | /* |
| 486 | * RX queue sysfs structures and functions. |
| 487 | */ |
| 488 | struct rx_queue_attribute { |
| 489 | struct attribute attr; |
| 490 | ssize_t (*show)(struct netdev_rx_queue *queue, |
| 491 | struct rx_queue_attribute *attr, char *buf); |
| 492 | ssize_t (*store)(struct netdev_rx_queue *queue, |
| 493 | struct rx_queue_attribute *attr, const char *buf, size_t len); |
| 494 | }; |
| 495 | #define to_rx_queue_attr(_attr) container_of(_attr, \ |
| 496 | struct rx_queue_attribute, attr) |
| 497 | |
| 498 | #define to_rx_queue(obj) container_of(obj, struct netdev_rx_queue, kobj) |
| 499 | |
| 500 | static ssize_t rx_queue_attr_show(struct kobject *kobj, struct attribute *attr, |
| 501 | char *buf) |
| 502 | { |
| 503 | struct rx_queue_attribute *attribute = to_rx_queue_attr(attr); |
| 504 | struct netdev_rx_queue *queue = to_rx_queue(kobj); |
| 505 | |
| 506 | if (!attribute->show) |
| 507 | return -EIO; |
| 508 | |
| 509 | return attribute->show(queue, attribute, buf); |
| 510 | } |
| 511 | |
| 512 | static ssize_t rx_queue_attr_store(struct kobject *kobj, struct attribute *attr, |
| 513 | const char *buf, size_t count) |
| 514 | { |
| 515 | struct rx_queue_attribute *attribute = to_rx_queue_attr(attr); |
| 516 | struct netdev_rx_queue *queue = to_rx_queue(kobj); |
| 517 | |
| 518 | if (!attribute->store) |
| 519 | return -EIO; |
| 520 | |
| 521 | return attribute->store(queue, attribute, buf, count); |
| 522 | } |
| 523 | |
stephen hemminger | fa50d64 | 2010-08-31 12:14:13 +0000 | [diff] [blame] | 524 | static const struct sysfs_ops rx_queue_sysfs_ops = { |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 525 | .show = rx_queue_attr_show, |
| 526 | .store = rx_queue_attr_store, |
| 527 | }; |
| 528 | |
| 529 | static ssize_t show_rps_map(struct netdev_rx_queue *queue, |
| 530 | struct rx_queue_attribute *attribute, char *buf) |
| 531 | { |
| 532 | struct rps_map *map; |
| 533 | cpumask_var_t mask; |
| 534 | size_t len = 0; |
| 535 | int i; |
| 536 | |
| 537 | if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) |
| 538 | return -ENOMEM; |
| 539 | |
| 540 | rcu_read_lock(); |
| 541 | map = rcu_dereference(queue->rps_map); |
| 542 | if (map) |
| 543 | for (i = 0; i < map->len; i++) |
| 544 | cpumask_set_cpu(map->cpus[i], mask); |
| 545 | |
| 546 | len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask); |
| 547 | if (PAGE_SIZE - len < 3) { |
| 548 | rcu_read_unlock(); |
| 549 | free_cpumask_var(mask); |
| 550 | return -EINVAL; |
| 551 | } |
| 552 | rcu_read_unlock(); |
| 553 | |
| 554 | free_cpumask_var(mask); |
| 555 | len += sprintf(buf + len, "\n"); |
| 556 | return len; |
| 557 | } |
| 558 | |
Eric Dumazet | f5acb90 | 2010-04-19 14:40:57 -0700 | [diff] [blame] | 559 | static ssize_t store_rps_map(struct netdev_rx_queue *queue, |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 560 | struct rx_queue_attribute *attribute, |
| 561 | const char *buf, size_t len) |
| 562 | { |
| 563 | struct rps_map *old_map, *map; |
| 564 | cpumask_var_t mask; |
| 565 | int err, cpu, i; |
| 566 | static DEFINE_SPINLOCK(rps_map_lock); |
| 567 | |
| 568 | if (!capable(CAP_NET_ADMIN)) |
| 569 | return -EPERM; |
| 570 | |
| 571 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) |
| 572 | return -ENOMEM; |
| 573 | |
| 574 | err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits); |
| 575 | if (err) { |
| 576 | free_cpumask_var(mask); |
| 577 | return err; |
| 578 | } |
| 579 | |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 580 | map = kzalloc(max_t(unsigned int, |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 581 | RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES), |
| 582 | GFP_KERNEL); |
| 583 | if (!map) { |
| 584 | free_cpumask_var(mask); |
| 585 | return -ENOMEM; |
| 586 | } |
| 587 | |
| 588 | i = 0; |
| 589 | for_each_cpu_and(cpu, mask, cpu_online_mask) |
| 590 | map->cpus[i++] = cpu; |
| 591 | |
| 592 | if (i) |
| 593 | map->len = i; |
| 594 | else { |
| 595 | kfree(map); |
| 596 | map = NULL; |
| 597 | } |
| 598 | |
| 599 | spin_lock(&rps_map_lock); |
Eric Dumazet | 6e3f7fa | 2010-10-25 03:02:02 +0000 | [diff] [blame] | 600 | old_map = rcu_dereference_protected(queue->rps_map, |
| 601 | lockdep_is_held(&rps_map_lock)); |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 602 | rcu_assign_pointer(queue->rps_map, map); |
| 603 | spin_unlock(&rps_map_lock); |
| 604 | |
Eric Dumazet | adc9300 | 2011-11-17 03:13:26 +0000 | [diff] [blame] | 605 | if (map) |
Ingo Molnar | c5905af | 2012-02-24 08:31:31 +0100 | [diff] [blame] | 606 | static_key_slow_inc(&rps_needed); |
Eric Dumazet | adc9300 | 2011-11-17 03:13:26 +0000 | [diff] [blame] | 607 | if (old_map) { |
Lai Jiangshan | f6f8023 | 2011-03-18 12:01:31 +0800 | [diff] [blame] | 608 | kfree_rcu(old_map, rcu); |
Ingo Molnar | c5905af | 2012-02-24 08:31:31 +0100 | [diff] [blame] | 609 | static_key_slow_dec(&rps_needed); |
Eric Dumazet | adc9300 | 2011-11-17 03:13:26 +0000 | [diff] [blame] | 610 | } |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 611 | free_cpumask_var(mask); |
| 612 | return len; |
| 613 | } |
| 614 | |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 615 | static ssize_t show_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue, |
| 616 | struct rx_queue_attribute *attr, |
| 617 | char *buf) |
| 618 | { |
| 619 | struct rps_dev_flow_table *flow_table; |
Eric Dumazet | 60b778c | 2011-12-24 06:56:49 +0000 | [diff] [blame] | 620 | unsigned long val = 0; |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 621 | |
| 622 | rcu_read_lock(); |
| 623 | flow_table = rcu_dereference(queue->rps_flow_table); |
| 624 | if (flow_table) |
Eric Dumazet | 60b778c | 2011-12-24 06:56:49 +0000 | [diff] [blame] | 625 | val = (unsigned long)flow_table->mask + 1; |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 626 | rcu_read_unlock(); |
| 627 | |
Eric Dumazet | 60b778c | 2011-12-24 06:56:49 +0000 | [diff] [blame] | 628 | return sprintf(buf, "%lu\n", val); |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 631 | static void rps_dev_flow_table_release(struct rcu_head *rcu) |
| 632 | { |
| 633 | struct rps_dev_flow_table *table = container_of(rcu, |
| 634 | struct rps_dev_flow_table, rcu); |
Al Viro | 243198d | 2013-05-05 16:05:55 +0000 | [diff] [blame] | 635 | vfree(table); |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Eric Dumazet | f5acb90 | 2010-04-19 14:40:57 -0700 | [diff] [blame] | 638 | static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue, |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 639 | struct rx_queue_attribute *attr, |
| 640 | const char *buf, size_t len) |
| 641 | { |
Eric Dumazet | 60b778c | 2011-12-24 06:56:49 +0000 | [diff] [blame] | 642 | unsigned long mask, count; |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 643 | struct rps_dev_flow_table *table, *old_table; |
| 644 | static DEFINE_SPINLOCK(rps_dev_flow_lock); |
Eric Dumazet | 60b778c | 2011-12-24 06:56:49 +0000 | [diff] [blame] | 645 | int rc; |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 646 | |
| 647 | if (!capable(CAP_NET_ADMIN)) |
| 648 | return -EPERM; |
| 649 | |
Eric Dumazet | 60b778c | 2011-12-24 06:56:49 +0000 | [diff] [blame] | 650 | rc = kstrtoul(buf, 0, &count); |
| 651 | if (rc < 0) |
| 652 | return rc; |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 653 | |
| 654 | if (count) { |
Eric Dumazet | 60b778c | 2011-12-24 06:56:49 +0000 | [diff] [blame] | 655 | mask = count - 1; |
| 656 | /* mask = roundup_pow_of_two(count) - 1; |
| 657 | * without overflows... |
| 658 | */ |
| 659 | while ((mask | (mask >> 1)) != mask) |
| 660 | mask |= (mask >> 1); |
| 661 | /* On 64 bit arches, must check mask fits in table->mask (u32), |
| 662 | * and on 32bit arches, must check RPS_DEV_FLOW_TABLE_SIZE(mask + 1) |
| 663 | * doesnt overflow. |
| 664 | */ |
| 665 | #if BITS_PER_LONG > 32 |
| 666 | if (mask > (unsigned long)(u32)mask) |
Xi Wang | a0a129f | 2011-12-22 13:35:22 +0000 | [diff] [blame] | 667 | return -EINVAL; |
Eric Dumazet | 60b778c | 2011-12-24 06:56:49 +0000 | [diff] [blame] | 668 | #else |
| 669 | if (mask > (ULONG_MAX - RPS_DEV_FLOW_TABLE_SIZE(1)) |
Xi Wang | a0a129f | 2011-12-22 13:35:22 +0000 | [diff] [blame] | 670 | / sizeof(struct rps_dev_flow)) { |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 671 | /* Enforce a limit to prevent overflow */ |
| 672 | return -EINVAL; |
| 673 | } |
Eric Dumazet | 60b778c | 2011-12-24 06:56:49 +0000 | [diff] [blame] | 674 | #endif |
| 675 | table = vmalloc(RPS_DEV_FLOW_TABLE_SIZE(mask + 1)); |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 676 | if (!table) |
| 677 | return -ENOMEM; |
| 678 | |
Eric Dumazet | 60b778c | 2011-12-24 06:56:49 +0000 | [diff] [blame] | 679 | table->mask = mask; |
| 680 | for (count = 0; count <= mask; count++) |
| 681 | table->flows[count].cpu = RPS_NO_CPU; |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 682 | } else |
| 683 | table = NULL; |
| 684 | |
| 685 | spin_lock(&rps_dev_flow_lock); |
Eric Dumazet | 6e3f7fa | 2010-10-25 03:02:02 +0000 | [diff] [blame] | 686 | old_table = rcu_dereference_protected(queue->rps_flow_table, |
| 687 | lockdep_is_held(&rps_dev_flow_lock)); |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 688 | rcu_assign_pointer(queue->rps_flow_table, table); |
| 689 | spin_unlock(&rps_dev_flow_lock); |
| 690 | |
| 691 | if (old_table) |
| 692 | call_rcu(&old_table->rcu, rps_dev_flow_table_release); |
| 693 | |
| 694 | return len; |
| 695 | } |
| 696 | |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 697 | static struct rx_queue_attribute rps_cpus_attribute = |
| 698 | __ATTR(rps_cpus, S_IRUGO | S_IWUSR, show_rps_map, store_rps_map); |
| 699 | |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 700 | |
| 701 | static struct rx_queue_attribute rps_dev_flow_table_cnt_attribute = |
| 702 | __ATTR(rps_flow_cnt, S_IRUGO | S_IWUSR, |
| 703 | show_rps_dev_flow_table_cnt, store_rps_dev_flow_table_cnt); |
| 704 | |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 705 | static struct attribute *rx_queue_default_attrs[] = { |
| 706 | &rps_cpus_attribute.attr, |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 707 | &rps_dev_flow_table_cnt_attribute.attr, |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 708 | NULL |
| 709 | }; |
| 710 | |
| 711 | static void rx_queue_release(struct kobject *kobj) |
| 712 | { |
| 713 | struct netdev_rx_queue *queue = to_rx_queue(kobj); |
Eric Dumazet | 6e3f7fa | 2010-10-25 03:02:02 +0000 | [diff] [blame] | 714 | struct rps_map *map; |
| 715 | struct rps_dev_flow_table *flow_table; |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 716 | |
Tom Herbert | fec5e65 | 2010-04-16 16:01:27 -0700 | [diff] [blame] | 717 | |
Eric Dumazet | 33d480c | 2011-08-11 19:30:52 +0000 | [diff] [blame] | 718 | map = rcu_dereference_protected(queue->rps_map, 1); |
John Fastabend | 9ea1948 | 2010-11-16 06:31:39 +0000 | [diff] [blame] | 719 | if (map) { |
| 720 | RCU_INIT_POINTER(queue->rps_map, NULL); |
Lai Jiangshan | f6f8023 | 2011-03-18 12:01:31 +0800 | [diff] [blame] | 721 | kfree_rcu(map, rcu); |
John Fastabend | 9ea1948 | 2010-11-16 06:31:39 +0000 | [diff] [blame] | 722 | } |
Eric Dumazet | 6e3f7fa | 2010-10-25 03:02:02 +0000 | [diff] [blame] | 723 | |
Eric Dumazet | 33d480c | 2011-08-11 19:30:52 +0000 | [diff] [blame] | 724 | flow_table = rcu_dereference_protected(queue->rps_flow_table, 1); |
John Fastabend | 9ea1948 | 2010-11-16 06:31:39 +0000 | [diff] [blame] | 725 | if (flow_table) { |
| 726 | RCU_INIT_POINTER(queue->rps_flow_table, NULL); |
Eric Dumazet | 6e3f7fa | 2010-10-25 03:02:02 +0000 | [diff] [blame] | 727 | call_rcu(&flow_table->rcu, rps_dev_flow_table_release); |
John Fastabend | 9ea1948 | 2010-11-16 06:31:39 +0000 | [diff] [blame] | 728 | } |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 729 | |
John Fastabend | 9ea1948 | 2010-11-16 06:31:39 +0000 | [diff] [blame] | 730 | memset(kobj, 0, sizeof(*kobj)); |
Tom Herbert | fe82224 | 2010-11-09 10:47:38 +0000 | [diff] [blame] | 731 | dev_put(queue->dev); |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | static struct kobj_type rx_queue_ktype = { |
| 735 | .sysfs_ops = &rx_queue_sysfs_ops, |
| 736 | .release = rx_queue_release, |
| 737 | .default_attrs = rx_queue_default_attrs, |
| 738 | }; |
| 739 | |
| 740 | static int rx_queue_add_kobject(struct net_device *net, int index) |
| 741 | { |
| 742 | struct netdev_rx_queue *queue = net->_rx + index; |
| 743 | struct kobject *kobj = &queue->kobj; |
| 744 | int error = 0; |
| 745 | |
| 746 | kobj->kset = net->queues_kset; |
| 747 | error = kobject_init_and_add(kobj, &rx_queue_ktype, NULL, |
| 748 | "rx-%u", index); |
| 749 | if (error) { |
| 750 | kobject_put(kobj); |
| 751 | return error; |
| 752 | } |
| 753 | |
| 754 | kobject_uevent(kobj, KOBJ_ADD); |
Tom Herbert | fe82224 | 2010-11-09 10:47:38 +0000 | [diff] [blame] | 755 | dev_hold(queue->dev); |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 756 | |
| 757 | return error; |
| 758 | } |
Tom Herbert | bf26414 | 2010-11-26 08:36:09 +0000 | [diff] [blame] | 759 | #endif /* CONFIG_RPS */ |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 760 | |
Ben Hutchings | 62fe0b4 | 2010-09-27 08:24:33 +0000 | [diff] [blame] | 761 | int |
| 762 | net_rx_queue_update_kobjects(struct net_device *net, int old_num, int new_num) |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 763 | { |
Tom Herbert | bf26414 | 2010-11-26 08:36:09 +0000 | [diff] [blame] | 764 | #ifdef CONFIG_RPS |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 765 | int i; |
| 766 | int error = 0; |
| 767 | |
Ben Hutchings | 62fe0b4 | 2010-09-27 08:24:33 +0000 | [diff] [blame] | 768 | for (i = old_num; i < new_num; i++) { |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 769 | error = rx_queue_add_kobject(net, i); |
Ben Hutchings | 62fe0b4 | 2010-09-27 08:24:33 +0000 | [diff] [blame] | 770 | if (error) { |
| 771 | new_num = old_num; |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 772 | break; |
Ben Hutchings | 62fe0b4 | 2010-09-27 08:24:33 +0000 | [diff] [blame] | 773 | } |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 774 | } |
| 775 | |
Ben Hutchings | 62fe0b4 | 2010-09-27 08:24:33 +0000 | [diff] [blame] | 776 | while (--i >= new_num) |
| 777 | kobject_put(&net->_rx[i].kobj); |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 778 | |
| 779 | return error; |
Tom Herbert | bf26414 | 2010-11-26 08:36:09 +0000 | [diff] [blame] | 780 | #else |
| 781 | return 0; |
| 782 | #endif |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 783 | } |
| 784 | |
david decotigny | ccf5ff6 | 2011-11-16 12:15:10 +0000 | [diff] [blame] | 785 | #ifdef CONFIG_SYSFS |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 786 | /* |
| 787 | * netdev_queue sysfs structures and functions. |
| 788 | */ |
| 789 | struct netdev_queue_attribute { |
| 790 | struct attribute attr; |
| 791 | ssize_t (*show)(struct netdev_queue *queue, |
| 792 | struct netdev_queue_attribute *attr, char *buf); |
| 793 | ssize_t (*store)(struct netdev_queue *queue, |
| 794 | struct netdev_queue_attribute *attr, const char *buf, size_t len); |
| 795 | }; |
| 796 | #define to_netdev_queue_attr(_attr) container_of(_attr, \ |
| 797 | struct netdev_queue_attribute, attr) |
| 798 | |
| 799 | #define to_netdev_queue(obj) container_of(obj, struct netdev_queue, kobj) |
| 800 | |
| 801 | static ssize_t netdev_queue_attr_show(struct kobject *kobj, |
| 802 | struct attribute *attr, char *buf) |
Ben Hutchings | 62fe0b4 | 2010-09-27 08:24:33 +0000 | [diff] [blame] | 803 | { |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 804 | struct netdev_queue_attribute *attribute = to_netdev_queue_attr(attr); |
| 805 | struct netdev_queue *queue = to_netdev_queue(kobj); |
| 806 | |
| 807 | if (!attribute->show) |
| 808 | return -EIO; |
| 809 | |
| 810 | return attribute->show(queue, attribute, buf); |
| 811 | } |
| 812 | |
| 813 | static ssize_t netdev_queue_attr_store(struct kobject *kobj, |
| 814 | struct attribute *attr, |
| 815 | const char *buf, size_t count) |
| 816 | { |
| 817 | struct netdev_queue_attribute *attribute = to_netdev_queue_attr(attr); |
| 818 | struct netdev_queue *queue = to_netdev_queue(kobj); |
| 819 | |
| 820 | if (!attribute->store) |
| 821 | return -EIO; |
| 822 | |
| 823 | return attribute->store(queue, attribute, buf, count); |
| 824 | } |
| 825 | |
| 826 | static const struct sysfs_ops netdev_queue_sysfs_ops = { |
| 827 | .show = netdev_queue_attr_show, |
| 828 | .store = netdev_queue_attr_store, |
| 829 | }; |
| 830 | |
david decotigny | ccf5ff6 | 2011-11-16 12:15:10 +0000 | [diff] [blame] | 831 | static ssize_t show_trans_timeout(struct netdev_queue *queue, |
| 832 | struct netdev_queue_attribute *attribute, |
| 833 | char *buf) |
| 834 | { |
| 835 | unsigned long trans_timeout; |
| 836 | |
| 837 | spin_lock_irq(&queue->_xmit_lock); |
| 838 | trans_timeout = queue->trans_timeout; |
| 839 | spin_unlock_irq(&queue->_xmit_lock); |
| 840 | |
| 841 | return sprintf(buf, "%lu", trans_timeout); |
| 842 | } |
| 843 | |
| 844 | static struct netdev_queue_attribute queue_trans_timeout = |
| 845 | __ATTR(tx_timeout, S_IRUGO, show_trans_timeout, NULL); |
| 846 | |
Tom Herbert | 114cf58 | 2011-11-28 16:33:09 +0000 | [diff] [blame] | 847 | #ifdef CONFIG_BQL |
| 848 | /* |
| 849 | * Byte queue limits sysfs structures and functions. |
| 850 | */ |
| 851 | static ssize_t bql_show(char *buf, unsigned int value) |
| 852 | { |
| 853 | return sprintf(buf, "%u\n", value); |
| 854 | } |
| 855 | |
| 856 | static ssize_t bql_set(const char *buf, const size_t count, |
| 857 | unsigned int *pvalue) |
| 858 | { |
| 859 | unsigned int value; |
| 860 | int err; |
| 861 | |
| 862 | if (!strcmp(buf, "max") || !strcmp(buf, "max\n")) |
| 863 | value = DQL_MAX_LIMIT; |
| 864 | else { |
| 865 | err = kstrtouint(buf, 10, &value); |
| 866 | if (err < 0) |
| 867 | return err; |
| 868 | if (value > DQL_MAX_LIMIT) |
| 869 | return -EINVAL; |
| 870 | } |
| 871 | |
| 872 | *pvalue = value; |
| 873 | |
| 874 | return count; |
| 875 | } |
| 876 | |
| 877 | static ssize_t bql_show_hold_time(struct netdev_queue *queue, |
| 878 | struct netdev_queue_attribute *attr, |
| 879 | char *buf) |
| 880 | { |
| 881 | struct dql *dql = &queue->dql; |
| 882 | |
| 883 | return sprintf(buf, "%u\n", jiffies_to_msecs(dql->slack_hold_time)); |
| 884 | } |
| 885 | |
| 886 | static ssize_t bql_set_hold_time(struct netdev_queue *queue, |
| 887 | struct netdev_queue_attribute *attribute, |
| 888 | const char *buf, size_t len) |
| 889 | { |
| 890 | struct dql *dql = &queue->dql; |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 891 | unsigned int value; |
Tom Herbert | 114cf58 | 2011-11-28 16:33:09 +0000 | [diff] [blame] | 892 | int err; |
| 893 | |
| 894 | err = kstrtouint(buf, 10, &value); |
| 895 | if (err < 0) |
| 896 | return err; |
| 897 | |
| 898 | dql->slack_hold_time = msecs_to_jiffies(value); |
| 899 | |
| 900 | return len; |
| 901 | } |
| 902 | |
| 903 | static struct netdev_queue_attribute bql_hold_time_attribute = |
| 904 | __ATTR(hold_time, S_IRUGO | S_IWUSR, bql_show_hold_time, |
| 905 | bql_set_hold_time); |
| 906 | |
| 907 | static ssize_t bql_show_inflight(struct netdev_queue *queue, |
| 908 | struct netdev_queue_attribute *attr, |
| 909 | char *buf) |
| 910 | { |
| 911 | struct dql *dql = &queue->dql; |
| 912 | |
| 913 | return sprintf(buf, "%u\n", dql->num_queued - dql->num_completed); |
| 914 | } |
| 915 | |
| 916 | static struct netdev_queue_attribute bql_inflight_attribute = |
Hiroaki SHIMODA | 795d9a2 | 2012-01-14 07:10:21 +0000 | [diff] [blame] | 917 | __ATTR(inflight, S_IRUGO, bql_show_inflight, NULL); |
Tom Herbert | 114cf58 | 2011-11-28 16:33:09 +0000 | [diff] [blame] | 918 | |
| 919 | #define BQL_ATTR(NAME, FIELD) \ |
| 920 | static ssize_t bql_show_ ## NAME(struct netdev_queue *queue, \ |
| 921 | struct netdev_queue_attribute *attr, \ |
| 922 | char *buf) \ |
| 923 | { \ |
| 924 | return bql_show(buf, queue->dql.FIELD); \ |
| 925 | } \ |
| 926 | \ |
| 927 | static ssize_t bql_set_ ## NAME(struct netdev_queue *queue, \ |
| 928 | struct netdev_queue_attribute *attr, \ |
| 929 | const char *buf, size_t len) \ |
| 930 | { \ |
| 931 | return bql_set(buf, len, &queue->dql.FIELD); \ |
| 932 | } \ |
| 933 | \ |
| 934 | static struct netdev_queue_attribute bql_ ## NAME ## _attribute = \ |
| 935 | __ATTR(NAME, S_IRUGO | S_IWUSR, bql_show_ ## NAME, \ |
| 936 | bql_set_ ## NAME); |
| 937 | |
| 938 | BQL_ATTR(limit, limit) |
| 939 | BQL_ATTR(limit_max, max_limit) |
| 940 | BQL_ATTR(limit_min, min_limit) |
| 941 | |
| 942 | static struct attribute *dql_attrs[] = { |
| 943 | &bql_limit_attribute.attr, |
| 944 | &bql_limit_max_attribute.attr, |
| 945 | &bql_limit_min_attribute.attr, |
| 946 | &bql_hold_time_attribute.attr, |
| 947 | &bql_inflight_attribute.attr, |
| 948 | NULL |
| 949 | }; |
| 950 | |
| 951 | static struct attribute_group dql_group = { |
| 952 | .name = "byte_queue_limits", |
| 953 | .attrs = dql_attrs, |
| 954 | }; |
| 955 | #endif /* CONFIG_BQL */ |
| 956 | |
david decotigny | ccf5ff6 | 2011-11-16 12:15:10 +0000 | [diff] [blame] | 957 | #ifdef CONFIG_XPS |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 958 | static inline unsigned int get_netdev_queue_index(struct netdev_queue *queue) |
| 959 | { |
| 960 | struct net_device *dev = queue->dev; |
| 961 | int i; |
| 962 | |
| 963 | for (i = 0; i < dev->num_tx_queues; i++) |
| 964 | if (queue == &dev->_tx[i]) |
| 965 | break; |
| 966 | |
| 967 | BUG_ON(i >= dev->num_tx_queues); |
| 968 | |
| 969 | return i; |
| 970 | } |
| 971 | |
| 972 | |
| 973 | static ssize_t show_xps_map(struct netdev_queue *queue, |
| 974 | struct netdev_queue_attribute *attribute, char *buf) |
| 975 | { |
| 976 | struct net_device *dev = queue->dev; |
| 977 | struct xps_dev_maps *dev_maps; |
| 978 | cpumask_var_t mask; |
| 979 | unsigned long index; |
| 980 | size_t len = 0; |
| 981 | int i; |
| 982 | |
| 983 | if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) |
| 984 | return -ENOMEM; |
| 985 | |
| 986 | index = get_netdev_queue_index(queue); |
| 987 | |
| 988 | rcu_read_lock(); |
| 989 | dev_maps = rcu_dereference(dev->xps_maps); |
| 990 | if (dev_maps) { |
| 991 | for_each_possible_cpu(i) { |
| 992 | struct xps_map *map = |
| 993 | rcu_dereference(dev_maps->cpu_map[i]); |
| 994 | if (map) { |
| 995 | int j; |
| 996 | for (j = 0; j < map->len; j++) { |
| 997 | if (map->queues[j] == index) { |
| 998 | cpumask_set_cpu(i, mask); |
| 999 | break; |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | } |
| 1005 | rcu_read_unlock(); |
| 1006 | |
| 1007 | len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask); |
| 1008 | if (PAGE_SIZE - len < 3) { |
| 1009 | free_cpumask_var(mask); |
| 1010 | return -EINVAL; |
| 1011 | } |
| 1012 | |
| 1013 | free_cpumask_var(mask); |
| 1014 | len += sprintf(buf + len, "\n"); |
| 1015 | return len; |
| 1016 | } |
| 1017 | |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1018 | static ssize_t store_xps_map(struct netdev_queue *queue, |
| 1019 | struct netdev_queue_attribute *attribute, |
| 1020 | const char *buf, size_t len) |
| 1021 | { |
| 1022 | struct net_device *dev = queue->dev; |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1023 | unsigned long index; |
Alexander Duyck | 537c00d | 2013-01-10 08:57:02 +0000 | [diff] [blame] | 1024 | cpumask_var_t mask; |
| 1025 | int err; |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1026 | |
| 1027 | if (!capable(CAP_NET_ADMIN)) |
| 1028 | return -EPERM; |
| 1029 | |
| 1030 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) |
| 1031 | return -ENOMEM; |
| 1032 | |
| 1033 | index = get_netdev_queue_index(queue); |
| 1034 | |
| 1035 | err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits); |
| 1036 | if (err) { |
| 1037 | free_cpumask_var(mask); |
| 1038 | return err; |
| 1039 | } |
| 1040 | |
Alexander Duyck | 537c00d | 2013-01-10 08:57:02 +0000 | [diff] [blame] | 1041 | err = netif_set_xps_queue(dev, mask, index); |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1042 | |
| 1043 | free_cpumask_var(mask); |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1044 | |
Alexander Duyck | 537c00d | 2013-01-10 08:57:02 +0000 | [diff] [blame] | 1045 | return err ? : len; |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | static struct netdev_queue_attribute xps_cpus_attribute = |
| 1049 | __ATTR(xps_cpus, S_IRUGO | S_IWUSR, show_xps_map, store_xps_map); |
david decotigny | ccf5ff6 | 2011-11-16 12:15:10 +0000 | [diff] [blame] | 1050 | #endif /* CONFIG_XPS */ |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1051 | |
| 1052 | static struct attribute *netdev_queue_default_attrs[] = { |
david decotigny | ccf5ff6 | 2011-11-16 12:15:10 +0000 | [diff] [blame] | 1053 | &queue_trans_timeout.attr, |
| 1054 | #ifdef CONFIG_XPS |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1055 | &xps_cpus_attribute.attr, |
david decotigny | ccf5ff6 | 2011-11-16 12:15:10 +0000 | [diff] [blame] | 1056 | #endif |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1057 | NULL |
| 1058 | }; |
| 1059 | |
| 1060 | static void netdev_queue_release(struct kobject *kobj) |
| 1061 | { |
| 1062 | struct netdev_queue *queue = to_netdev_queue(kobj); |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1063 | |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1064 | memset(kobj, 0, sizeof(*kobj)); |
| 1065 | dev_put(queue->dev); |
| 1066 | } |
| 1067 | |
| 1068 | static struct kobj_type netdev_queue_ktype = { |
| 1069 | .sysfs_ops = &netdev_queue_sysfs_ops, |
| 1070 | .release = netdev_queue_release, |
| 1071 | .default_attrs = netdev_queue_default_attrs, |
| 1072 | }; |
| 1073 | |
| 1074 | static int netdev_queue_add_kobject(struct net_device *net, int index) |
| 1075 | { |
| 1076 | struct netdev_queue *queue = net->_tx + index; |
| 1077 | struct kobject *kobj = &queue->kobj; |
| 1078 | int error = 0; |
| 1079 | |
| 1080 | kobj->kset = net->queues_kset; |
| 1081 | error = kobject_init_and_add(kobj, &netdev_queue_ktype, NULL, |
| 1082 | "tx-%u", index); |
Tom Herbert | 114cf58 | 2011-11-28 16:33:09 +0000 | [diff] [blame] | 1083 | if (error) |
| 1084 | goto exit; |
| 1085 | |
| 1086 | #ifdef CONFIG_BQL |
| 1087 | error = sysfs_create_group(kobj, &dql_group); |
| 1088 | if (error) |
| 1089 | goto exit; |
| 1090 | #endif |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1091 | |
| 1092 | kobject_uevent(kobj, KOBJ_ADD); |
| 1093 | dev_hold(queue->dev); |
| 1094 | |
Tom Herbert | 114cf58 | 2011-11-28 16:33:09 +0000 | [diff] [blame] | 1095 | return 0; |
| 1096 | exit: |
| 1097 | kobject_put(kobj); |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1098 | return error; |
| 1099 | } |
david decotigny | ccf5ff6 | 2011-11-16 12:15:10 +0000 | [diff] [blame] | 1100 | #endif /* CONFIG_SYSFS */ |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1101 | |
| 1102 | int |
| 1103 | netdev_queue_update_kobjects(struct net_device *net, int old_num, int new_num) |
| 1104 | { |
david decotigny | ccf5ff6 | 2011-11-16 12:15:10 +0000 | [diff] [blame] | 1105 | #ifdef CONFIG_SYSFS |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1106 | int i; |
| 1107 | int error = 0; |
| 1108 | |
| 1109 | for (i = old_num; i < new_num; i++) { |
| 1110 | error = netdev_queue_add_kobject(net, i); |
| 1111 | if (error) { |
| 1112 | new_num = old_num; |
| 1113 | break; |
| 1114 | } |
| 1115 | } |
| 1116 | |
Tom Herbert | 114cf58 | 2011-11-28 16:33:09 +0000 | [diff] [blame] | 1117 | while (--i >= new_num) { |
| 1118 | struct netdev_queue *queue = net->_tx + i; |
| 1119 | |
| 1120 | #ifdef CONFIG_BQL |
| 1121 | sysfs_remove_group(&queue->kobj, &dql_group); |
| 1122 | #endif |
| 1123 | kobject_put(&queue->kobj); |
| 1124 | } |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1125 | |
| 1126 | return error; |
Tom Herbert | bf26414 | 2010-11-26 08:36:09 +0000 | [diff] [blame] | 1127 | #else |
| 1128 | return 0; |
david decotigny | ccf5ff6 | 2011-11-16 12:15:10 +0000 | [diff] [blame] | 1129 | #endif /* CONFIG_SYSFS */ |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | static int register_queue_kobjects(struct net_device *net) |
| 1133 | { |
Tom Herbert | bf26414 | 2010-11-26 08:36:09 +0000 | [diff] [blame] | 1134 | int error = 0, txq = 0, rxq = 0, real_rx = 0, real_tx = 0; |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1135 | |
david decotigny | ccf5ff6 | 2011-11-16 12:15:10 +0000 | [diff] [blame] | 1136 | #ifdef CONFIG_SYSFS |
Ben Hutchings | 62fe0b4 | 2010-09-27 08:24:33 +0000 | [diff] [blame] | 1137 | net->queues_kset = kset_create_and_add("queues", |
| 1138 | NULL, &net->dev.kobj); |
| 1139 | if (!net->queues_kset) |
| 1140 | return -ENOMEM; |
Tom Herbert | bf26414 | 2010-11-26 08:36:09 +0000 | [diff] [blame] | 1141 | #endif |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1142 | |
Tom Herbert | bf26414 | 2010-11-26 08:36:09 +0000 | [diff] [blame] | 1143 | #ifdef CONFIG_RPS |
| 1144 | real_rx = net->real_num_rx_queues; |
| 1145 | #endif |
| 1146 | real_tx = net->real_num_tx_queues; |
| 1147 | |
| 1148 | error = net_rx_queue_update_kobjects(net, 0, real_rx); |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1149 | if (error) |
| 1150 | goto error; |
Tom Herbert | bf26414 | 2010-11-26 08:36:09 +0000 | [diff] [blame] | 1151 | rxq = real_rx; |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1152 | |
Tom Herbert | bf26414 | 2010-11-26 08:36:09 +0000 | [diff] [blame] | 1153 | error = netdev_queue_update_kobjects(net, 0, real_tx); |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1154 | if (error) |
| 1155 | goto error; |
Tom Herbert | bf26414 | 2010-11-26 08:36:09 +0000 | [diff] [blame] | 1156 | txq = real_tx; |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1157 | |
| 1158 | return 0; |
| 1159 | |
| 1160 | error: |
| 1161 | netdev_queue_update_kobjects(net, txq, 0); |
| 1162 | net_rx_queue_update_kobjects(net, rxq, 0); |
| 1163 | return error; |
Ben Hutchings | 62fe0b4 | 2010-09-27 08:24:33 +0000 | [diff] [blame] | 1164 | } |
| 1165 | |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1166 | static void remove_queue_kobjects(struct net_device *net) |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 1167 | { |
Tom Herbert | bf26414 | 2010-11-26 08:36:09 +0000 | [diff] [blame] | 1168 | int real_rx = 0, real_tx = 0; |
| 1169 | |
| 1170 | #ifdef CONFIG_RPS |
| 1171 | real_rx = net->real_num_rx_queues; |
| 1172 | #endif |
| 1173 | real_tx = net->real_num_tx_queues; |
| 1174 | |
| 1175 | net_rx_queue_update_kobjects(net, real_rx, 0); |
| 1176 | netdev_queue_update_kobjects(net, real_tx, 0); |
david decotigny | ccf5ff6 | 2011-11-16 12:15:10 +0000 | [diff] [blame] | 1177 | #ifdef CONFIG_SYSFS |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 1178 | kset_unregister(net->queues_kset); |
Tom Herbert | bf26414 | 2010-11-26 08:36:09 +0000 | [diff] [blame] | 1179 | #endif |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 1180 | } |
Eric W. Biederman | 608b4b9 | 2010-05-04 17:36:45 -0700 | [diff] [blame] | 1181 | |
Al Viro | a685e08 | 2011-06-08 21:13:01 -0400 | [diff] [blame] | 1182 | static void *net_grab_current_ns(void) |
Eric W. Biederman | 608b4b9 | 2010-05-04 17:36:45 -0700 | [diff] [blame] | 1183 | { |
Al Viro | a685e08 | 2011-06-08 21:13:01 -0400 | [diff] [blame] | 1184 | struct net *ns = current->nsproxy->net_ns; |
| 1185 | #ifdef CONFIG_NET_NS |
| 1186 | if (ns) |
| 1187 | atomic_inc(&ns->passive); |
| 1188 | #endif |
| 1189 | return ns; |
Eric W. Biederman | 608b4b9 | 2010-05-04 17:36:45 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | static const void *net_initial_ns(void) |
| 1193 | { |
| 1194 | return &init_net; |
| 1195 | } |
| 1196 | |
| 1197 | static const void *net_netlink_ns(struct sock *sk) |
| 1198 | { |
| 1199 | return sock_net(sk); |
| 1200 | } |
| 1201 | |
Johannes Berg | 0460079 | 2010-08-05 17:45:15 +0200 | [diff] [blame] | 1202 | struct kobj_ns_type_operations net_ns_type_operations = { |
Eric W. Biederman | 608b4b9 | 2010-05-04 17:36:45 -0700 | [diff] [blame] | 1203 | .type = KOBJ_NS_TYPE_NET, |
Al Viro | a685e08 | 2011-06-08 21:13:01 -0400 | [diff] [blame] | 1204 | .grab_current_ns = net_grab_current_ns, |
Eric W. Biederman | 608b4b9 | 2010-05-04 17:36:45 -0700 | [diff] [blame] | 1205 | .netlink_ns = net_netlink_ns, |
| 1206 | .initial_ns = net_initial_ns, |
Al Viro | a685e08 | 2011-06-08 21:13:01 -0400 | [diff] [blame] | 1207 | .drop_ns = net_drop_ns, |
Eric W. Biederman | 608b4b9 | 2010-05-04 17:36:45 -0700 | [diff] [blame] | 1208 | }; |
Johannes Berg | 0460079 | 2010-08-05 17:45:15 +0200 | [diff] [blame] | 1209 | EXPORT_SYMBOL_GPL(net_ns_type_operations); |
Eric W. Biederman | 608b4b9 | 2010-05-04 17:36:45 -0700 | [diff] [blame] | 1210 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1211 | static int netdev_uevent(struct device *d, struct kobj_uevent_env *env) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1213 | struct net_device *dev = to_net_dev(d); |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1214 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 1216 | /* pass interface to uevent. */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1217 | retval = add_uevent_var(env, "INTERFACE=%s", dev->name); |
Eric Rannaud | bf62456 | 2007-03-30 22:23:12 -0700 | [diff] [blame] | 1218 | if (retval) |
| 1219 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | |
Jean Tourrilhes | ca2f37d | 2007-03-07 10:49:30 -0800 | [diff] [blame] | 1221 | /* pass ifindex to uevent. |
| 1222 | * ifindex is useful as it won't change (interface name may change) |
| 1223 | * and is what RtNetlink uses natively. */ |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 1224 | retval = add_uevent_var(env, "IFINDEX=%d", dev->ifindex); |
Jean Tourrilhes | ca2f37d | 2007-03-07 10:49:30 -0800 | [diff] [blame] | 1225 | |
Eric Rannaud | bf62456 | 2007-03-30 22:23:12 -0700 | [diff] [blame] | 1226 | exit: |
Eric Rannaud | bf62456 | 2007-03-30 22:23:12 -0700 | [diff] [blame] | 1227 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | |
| 1230 | /* |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 1231 | * netdev_release -- destroy and free a dead device. |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1232 | * Called when last reference to device kobject is gone. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1234 | static void netdev_release(struct device *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1236 | struct net_device *dev = to_net_dev(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | |
| 1238 | BUG_ON(dev->reg_state != NETREG_RELEASED); |
| 1239 | |
Stephen Hemminger | 0b815a1 | 2008-09-22 21:28:11 -0700 | [diff] [blame] | 1240 | kfree(dev->ifalias); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | kfree((char *)dev - dev->padded); |
| 1242 | } |
| 1243 | |
Eric W. Biederman | 608b4b9 | 2010-05-04 17:36:45 -0700 | [diff] [blame] | 1244 | static const void *net_namespace(struct device *d) |
| 1245 | { |
| 1246 | struct net_device *dev; |
| 1247 | dev = container_of(d, struct net_device, dev); |
| 1248 | return dev_net(dev); |
| 1249 | } |
| 1250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | static struct class net_class = { |
| 1252 | .name = "net", |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1253 | .dev_release = netdev_release, |
Eric W. Biederman | 8b41d18 | 2007-09-26 22:02:53 -0700 | [diff] [blame] | 1254 | #ifdef CONFIG_SYSFS |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1255 | .dev_attrs = net_class_attributes, |
Eric W. Biederman | 8b41d18 | 2007-09-26 22:02:53 -0700 | [diff] [blame] | 1256 | #endif /* CONFIG_SYSFS */ |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1257 | .dev_uevent = netdev_uevent, |
Eric W. Biederman | 608b4b9 | 2010-05-04 17:36:45 -0700 | [diff] [blame] | 1258 | .ns_type = &net_ns_type_operations, |
| 1259 | .namespace = net_namespace, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | }; |
| 1261 | |
Stephen Hemminger | 9093bbb | 2007-05-19 15:39:25 -0700 | [diff] [blame] | 1262 | /* Delete sysfs entries but hold kobject reference until after all |
| 1263 | * netdev references are gone. |
| 1264 | */ |
Eric W. Biederman | 8b41d18 | 2007-09-26 22:02:53 -0700 | [diff] [blame] | 1265 | void netdev_unregister_kobject(struct net_device * net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | { |
Stephen Hemminger | 9093bbb | 2007-05-19 15:39:25 -0700 | [diff] [blame] | 1267 | struct device *dev = &(net->dev); |
| 1268 | |
| 1269 | kobject_get(&dev->kobj); |
Eric W. Biederman | 3891845 | 2008-10-27 17:51:47 -0700 | [diff] [blame] | 1270 | |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1271 | remove_queue_kobjects(net); |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 1272 | |
Ming Lei | 9802c8e | 2013-02-22 16:34:16 -0800 | [diff] [blame] | 1273 | pm_runtime_set_memalloc_noio(dev, false); |
| 1274 | |
Stephen Hemminger | 9093bbb | 2007-05-19 15:39:25 -0700 | [diff] [blame] | 1275 | device_del(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | /* Create sysfs entries for network device. */ |
Eric W. Biederman | 8b41d18 | 2007-09-26 22:02:53 -0700 | [diff] [blame] | 1279 | int netdev_register_kobject(struct net_device *net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | { |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1281 | struct device *dev = &(net->dev); |
David Brownell | a4dbd67 | 2009-06-24 10:06:31 -0700 | [diff] [blame] | 1282 | const struct attribute_group **groups = net->sysfs_groups; |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 1283 | int error = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | |
Eric W. Biederman | a1b3f59 | 2010-05-04 17:36:49 -0700 | [diff] [blame] | 1285 | device_initialize(dev); |
Greg Kroah-Hartman | 43cb76d | 2002-04-09 12:14:34 -0700 | [diff] [blame] | 1286 | dev->class = &net_class; |
| 1287 | dev->platform_data = net; |
| 1288 | dev->groups = groups; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | |
Stephen Hemminger | a220547 | 2009-03-09 13:51:55 +0000 | [diff] [blame] | 1290 | dev_set_name(dev, "%s", net->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | |
Eric W. Biederman | 8b41d18 | 2007-09-26 22:02:53 -0700 | [diff] [blame] | 1292 | #ifdef CONFIG_SYSFS |
Eric W. Biederman | 0c509a6 | 2009-10-29 14:18:21 +0000 | [diff] [blame] | 1293 | /* Allow for a device specific group */ |
| 1294 | if (*groups) |
| 1295 | groups++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | |
Eric W. Biederman | 0c509a6 | 2009-10-29 14:18:21 +0000 | [diff] [blame] | 1297 | *groups++ = &netstat_group; |
Johannes Berg | 38c1a01 | 2012-11-16 20:46:19 +0100 | [diff] [blame] | 1298 | |
| 1299 | #if IS_ENABLED(CONFIG_WIRELESS_EXT) || IS_ENABLED(CONFIG_CFG80211) |
| 1300 | if (net->ieee80211_ptr) |
| 1301 | *groups++ = &wireless_group; |
| 1302 | #if IS_ENABLED(CONFIG_WIRELESS_EXT) |
| 1303 | else if (net->wireless_handlers) |
| 1304 | *groups++ = &wireless_group; |
| 1305 | #endif |
| 1306 | #endif |
Eric W. Biederman | 8b41d18 | 2007-09-26 22:02:53 -0700 | [diff] [blame] | 1307 | #endif /* CONFIG_SYSFS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 1309 | error = device_add(dev); |
| 1310 | if (error) |
| 1311 | return error; |
| 1312 | |
Tom Herbert | 1d24eb4 | 2010-11-21 13:17:27 +0000 | [diff] [blame] | 1313 | error = register_queue_kobjects(net); |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 1314 | if (error) { |
| 1315 | device_del(dev); |
| 1316 | return error; |
| 1317 | } |
| 1318 | |
Ming Lei | 9802c8e | 2013-02-22 16:34:16 -0800 | [diff] [blame] | 1319 | pm_runtime_set_memalloc_noio(dev, true); |
| 1320 | |
Tom Herbert | 0a9627f | 2010-03-16 08:03:29 +0000 | [diff] [blame] | 1321 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
Jay Vosburgh | b8a9787 | 2008-06-13 18:12:04 -0700 | [diff] [blame] | 1324 | int netdev_class_create_file(struct class_attribute *class_attr) |
| 1325 | { |
| 1326 | return class_create_file(&net_class, class_attr); |
| 1327 | } |
Eric Dumazet | 9e34a5b | 2010-07-09 21:22:04 +0000 | [diff] [blame] | 1328 | EXPORT_SYMBOL(netdev_class_create_file); |
Jay Vosburgh | b8a9787 | 2008-06-13 18:12:04 -0700 | [diff] [blame] | 1329 | |
| 1330 | void netdev_class_remove_file(struct class_attribute *class_attr) |
| 1331 | { |
| 1332 | class_remove_file(&net_class, class_attr); |
| 1333 | } |
Jay Vosburgh | b8a9787 | 2008-06-13 18:12:04 -0700 | [diff] [blame] | 1334 | EXPORT_SYMBOL(netdev_class_remove_file); |
| 1335 | |
Eric W. Biederman | 8b41d18 | 2007-09-26 22:02:53 -0700 | [diff] [blame] | 1336 | int netdev_kobject_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | { |
Eric W. Biederman | 608b4b9 | 2010-05-04 17:36:45 -0700 | [diff] [blame] | 1338 | kobj_ns_type_register(&net_ns_type_operations); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | return class_register(&net_class); |
| 1340 | } |