Lines Matching defs:dev

30 #include "dev.h"
41 static inline int dev_isalive(const struct net_device *dev)
43 return READ_ONCE(dev->reg_state) <= NETREG_REGISTERED;
128 static ssize_t netdev_show(const struct device *dev,
132 struct net_device *ndev = to_net_dev(dev);
145 static ssize_t format_##field(const struct net_device *dev, char *buf) \
147 return sysfs_emit(buf, format_string, READ_ONCE(dev->field)); \
149 static ssize_t field##_show(struct device *dev, \
152 return netdev_show(dev, attr, buf, format_##field); \
164 static ssize_t netdev_store(struct device *dev, struct device_attribute *attr,
168 struct net_device *netdev = to_net_dev(dev);
180 ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev);
195 netdev_lock_store(struct device *dev, struct device_attribute *attr,
199 struct net_device *netdev = to_net_dev(dev);
231 static ssize_t iflink_show(struct device *dev, struct device_attribute *attr,
234 struct net_device *ndev = to_net_dev(dev);
240 static ssize_t format_name_assign_type(const struct net_device *dev, char *buf)
242 return sysfs_emit(buf, fmt_dec, READ_ONCE(dev->name_assign_type));
245 static ssize_t name_assign_type_show(struct device *dev,
249 struct net_device *ndev = to_net_dev(dev);
253 ret = netdev_show(dev, attr, buf, format_name_assign_type);
260 static ssize_t address_show(struct device *dev, struct device_attribute *attr,
263 struct net_device *ndev = to_net_dev(dev);
278 static ssize_t broadcast_show(struct device *dev,
281 struct net_device *ndev = to_net_dev(dev);
292 static int change_carrier(struct net_device *dev, unsigned long new_carrier)
294 if (!netif_running(dev))
296 return dev_change_carrier(dev, (bool)new_carrier);
299 static ssize_t carrier_store(struct device *dev, struct device_attribute *attr,
302 struct net_device *netdev = to_net_dev(dev);
310 return netdev_store(dev, attr, buf, len, change_carrier);
313 static ssize_t carrier_show(struct device *dev,
316 struct net_device *netdev = to_net_dev(dev);
319 ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev);
338 static ssize_t speed_show(struct device *dev,
341 struct net_device *netdev = to_net_dev(dev);
350 ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev);
366 static ssize_t duplex_show(struct device *dev,
369 struct net_device *netdev = to_net_dev(dev);
378 ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev);
408 static ssize_t testing_show(struct device *dev,
411 struct net_device *netdev = to_net_dev(dev);
420 static ssize_t dormant_show(struct device *dev,
423 struct net_device *netdev = to_net_dev(dev);
442 static ssize_t operstate_show(struct device *dev,
445 const struct net_device *netdev = to_net_dev(dev);
459 static ssize_t carrier_changes_show(struct device *dev,
463 struct net_device *netdev = to_net_dev(dev);
471 static ssize_t carrier_up_count_show(struct device *dev,
475 struct net_device *netdev = to_net_dev(dev);
481 static ssize_t carrier_down_count_show(struct device *dev,
485 struct net_device *netdev = to_net_dev(dev);
493 static int change_mtu(struct net_device *dev, unsigned long new_mtu)
495 return dev_set_mtu(dev, (int)new_mtu);
498 static ssize_t mtu_store(struct device *dev, struct device_attribute *attr,
501 return netdev_store(dev, attr, buf, len, change_mtu);
505 static int change_flags(struct net_device *dev, unsigned long new_flags)
507 return dev_change_flags(dev, (unsigned int)new_flags, NULL);
510 static ssize_t flags_store(struct device *dev, struct device_attribute *attr,
513 return netdev_store(dev, attr, buf, len, change_flags);
517 static ssize_t tx_queue_len_store(struct device *dev,
524 return netdev_store(dev, attr, buf, len, dev_change_tx_queue_len);
528 static int change_gro_flush_timeout(struct net_device *dev, unsigned long val)
530 netdev_set_gro_flush_timeout(dev, val);
534 static ssize_t gro_flush_timeout_store(struct device *dev,
541 return netdev_lock_store(dev, attr, buf, len, change_gro_flush_timeout);
545 static int change_napi_defer_hard_irqs(struct net_device *dev, unsigned long val)
550 netdev_set_defer_hard_irqs(dev, (u32)val);
554 static ssize_t napi_defer_hard_irqs_store(struct device *dev,
561 return netdev_lock_store(dev, attr, buf, len,
566 static ssize_t ifalias_store(struct device *dev, struct device_attribute *attr,
569 struct net_device *netdev = to_net_dev(dev);
581 ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev);
596 static ssize_t ifalias_show(struct device *dev,
599 const struct net_device *netdev = to_net_dev(dev);
610 static int change_group(struct net_device *dev, unsigned long new_group)
612 dev_set_group(dev, (int)new_group);
616 static ssize_t group_store(struct device *dev, struct device_attribute *attr,
619 return netdev_store(dev, attr, buf, len, change_group);
624 static int change_proto_down(struct net_device *dev, unsigned long proto_down)
626 return dev_change_proto_down(dev, (bool)proto_down);
629 static ssize_t proto_down_store(struct device *dev,
633 return netdev_store(dev, attr, buf, len, change_proto_down);
637 static ssize_t phys_port_id_show(struct device *dev,
640 struct net_device *netdev = to_net_dev(dev);
644 ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev);
658 static ssize_t phys_port_name_show(struct device *dev,
661 struct net_device *netdev = to_net_dev(dev);
665 ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev);
679 static ssize_t phys_switch_id_show(struct device *dev,
682 struct net_device *netdev = to_net_dev(dev);
686 ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev);
710 struct device *dev = kobj_to_dev(kobj);
711 struct net_device *netdev = to_net_dev(dev);
734 static ssize_t threaded_show(struct device *dev,
737 struct net_device *netdev = to_net_dev(dev);
750 static int modify_napi_threaded(struct net_device *dev, unsigned long val)
754 if (list_empty(&dev->napi_list))
760 ret = netif_set_threaded(dev, val);
765 static ssize_t threaded_store(struct device *dev,
769 return netdev_lock_store(dev, attr, buf, len, modify_napi_threaded);
812 struct net_device *dev = to_net_dev(d);
819 if (dev_isalive(dev)) {
821 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
1181 netdev_put(queue->dev, &queue->dev_tracker);
1187 struct device *dev = &queue->dev->dev;
1190 if (dev->class && dev->class->namespace)
1191 ns = dev->class->namespace(dev);
1211 static int rx_queue_default_mask(struct net_device *dev,
1220 rps_default_mask = dev_net(dev)->core.rps_default_mask;
1232 static int rx_queue_add_kobject(struct net_device *dev, int index)
1234 struct netdev_rx_queue *queue = dev->_rx + index;
1250 netdev_warn_once(dev, "Cannot re-add rx queues before their removal completed");
1255 * decreases dev refcount: Take that reference here
1257 netdev_hold(queue->dev, &queue->dev_tracker, GFP_KERNEL);
1259 kobj->kset = dev->queues_kset;
1270 if (dev->sysfs_rx_queue_group) {
1271 error = sysfs_create_group(kobj, dev->sysfs_rx_queue_group);
1276 error = rx_queue_default_mask(dev, queue);
1291 static int rx_queue_change_owner(struct net_device *dev, int index, kuid_t kuid,
1294 struct netdev_rx_queue *queue = dev->_rx + index;
1302 if (dev->sysfs_rx_queue_group)
1304 kobj, dev->sysfs_rx_queue_group, kuid, kgid);
1311 net_rx_queue_update_kobjects(struct net_device *dev, int old_num, int new_num)
1318 if (!dev->sysfs_rx_queue_group)
1322 error = rx_queue_add_kobject(dev, i);
1330 struct netdev_rx_queue *queue = &dev->_rx[i];
1333 if (!check_net(dev_net(dev)))
1335 if (dev->sysfs_rx_queue_group)
1336 sysfs_remove_group(kobj, dev->sysfs_rx_queue_group);
1347 static int net_rx_queue_change_owner(struct net_device *dev, int num,
1355 if (!dev->sysfs_rx_queue_group)
1359 error = rx_queue_change_owner(dev, i, kuid, kgid);
1429 struct net_device *dev = queue->dev;
1432 i = queue - dev->_tx;
1433 BUG_ON(i >= dev->num_tx_queues);
1441 struct net_device *dev = queue->dev;
1444 if (!netif_is_multiqueue(dev))
1447 ret = sysfs_rtnl_lock(kobj, attr, queue->dev);
1453 /* If queue belongs to subordinate dev use its TC mapping */
1454 dev = netdev_get_tx_queue(dev, index)->sb_dev ? : dev;
1456 num_tc = dev->num_tc;
1457 tc = netdev_txq_to_tc(dev, index);
1487 struct net_device *dev = queue->dev;
1496 if (!dev->netdev_ops->ndo_set_tx_maxrate)
1503 err = sysfs_rtnl_lock(kobj, attr, dev);
1508 netdev_lock_ops(dev);
1509 if (dev->netdev_ops->ndo_set_tx_maxrate)
1510 err = dev->netdev_ops->ndo_set_tx_maxrate(dev, index, rate);
1511 netdev_unlock_ops(dev);
1713 static ssize_t xps_queue_show(struct net_device *dev, unsigned int index,
1722 dev_maps = rcu_dereference(dev->xps_maps[type]);
1724 /* Default to nr_cpu_ids/dev->num_rx_queues and do not just return 0
1728 (type == XPS_CPUS ? nr_cpu_ids : dev->num_rx_queues);
1766 struct net_device *dev = queue->dev;
1770 if (!netif_is_multiqueue(dev))
1775 ret = sysfs_rtnl_lock(kobj, attr, queue->dev);
1779 /* If queue belongs to subordinate dev use its map */
1780 dev = netdev_get_tx_queue(dev, index)->sb_dev ? : dev;
1782 tc = netdev_txq_to_tc(dev, index);
1791 dev_hold(dev);
1794 len = xps_queue_show(dev, index, tc, buf, XPS_CPUS);
1796 dev_put(dev);
1804 struct net_device *dev = queue->dev;
1809 if (!netif_is_multiqueue(dev))
1826 err = sysfs_rtnl_lock(kobj, attr, dev);
1832 err = netif_set_xps_queue(dev, mask, index);
1846 struct net_device *dev = queue->dev;
1852 ret = sysfs_rtnl_lock(kobj, attr, dev);
1856 tc = netdev_txq_to_tc(dev, index);
1861 dev_hold(dev);
1864 ret = tc >= 0 ? xps_queue_show(dev, index, tc, buf, XPS_RXQS) : -EINVAL;
1865 dev_put(dev);
1873 struct net_device *dev = queue->dev;
1874 struct net *net = dev_net(dev);
1882 mask = bitmap_zalloc(dev->num_rx_queues, GFP_KERNEL);
1888 err = bitmap_parse(buf, len, mask, dev->num_rx_queues);
1894 err = sysfs_rtnl_lock(kobj, attr, dev);
1901 err = __netif_set_xps_queue(dev, mask, index, XPS_RXQS);
1931 netdev_put(queue->dev, &queue->dev_tracker);
1937 struct device *dev = &queue->dev->dev;
1940 if (dev->class && dev->class->namespace)
1941 ns = dev->class->namespace(dev);
1961 static bool netdev_uses_bql(const struct net_device *dev)
1963 if (dev->lltx || (dev->priv_flags & IFF_NO_QUEUE))
1969 static int netdev_queue_add_kobject(struct net_device *dev, int index)
1971 struct netdev_queue *queue = dev->_tx + index;
1987 netdev_warn_once(dev, "Cannot re-add tx queues before their removal completed");
1992 * which decreases dev refcount: Take that reference here
1994 netdev_hold(queue->dev, &queue->dev_tracker, GFP_KERNEL);
1996 kobj->kset = dev->queues_kset;
2007 if (netdev_uses_bql(dev)) {
2042 netdev_queue_update_kobjects(struct net_device *dev, int old_num, int new_num)
2052 WARN(dev->reg_state == NETREG_UNREGISTERING && new_num > old_num,
2056 error = netdev_queue_add_kobject(dev, i);
2064 struct netdev_queue *queue = dev->_tx + i;
2066 if (!check_net(dev_net(dev)))
2069 if (netdev_uses_bql(dev))
2082 static int net_tx_queue_change_owner(struct net_device *dev, int num,
2090 error = tx_queue_change_owner(dev, i, kuid, kgid);
2101 static int register_queue_kobjects(struct net_device *dev)
2106 dev->queues_kset = kset_create_and_add("queues",
2107 NULL, &dev->dev.kobj);
2108 if (!dev->queues_kset)
2110 real_rx = dev->real_num_rx_queues;
2112 real_tx = dev->real_num_tx_queues;
2114 error = net_rx_queue_update_kobjects(dev, 0, real_rx);
2119 error = netdev_queue_update_kobjects(dev, 0, real_tx);
2127 netdev_queue_update_kobjects(dev, txq, 0);
2128 net_rx_queue_update_kobjects(dev, rxq, 0);
2130 kset_unregister(dev->queues_kset);
2160 static void remove_queue_kobjects(struct net_device *dev)
2165 real_rx = dev->real_num_rx_queues;
2167 real_tx = dev->real_num_tx_queues;
2169 net_rx_queue_update_kobjects(dev, real_rx, 0);
2170 netdev_queue_update_kobjects(dev, real_tx, 0);
2172 netdev_lock_ops(dev);
2173 dev->real_num_rx_queues = 0;
2174 dev->real_num_tx_queues = 0;
2175 netdev_unlock_ops(dev);
2177 kset_unregister(dev->queues_kset);
2220 const struct net_device *dev = to_net_dev(d);
2224 retval = add_uevent_var(env, "INTERFACE=%s", dev->name);
2232 retval = add_uevent_var(env, "IFINDEX=%d", dev->ifindex);
2244 struct net_device *dev = to_net_dev(d);
2246 BUG_ON(dev->reg_state != NETREG_RELEASED);
2251 kfree(rcu_access_pointer(dev->ifalias));
2252 kvfree(dev);
2257 const struct net_device *dev = to_net_dev(d);
2259 return dev_net(dev);
2264 const struct net_device *dev = to_net_dev(d);
2265 const struct net *net = dev_net(dev);
2281 static int of_dev_node_match(struct device *dev, const void *data)
2283 for (; dev; dev = dev->parent) {
2284 if (dev->of_node == data)
2302 struct device *dev;
2304 dev = class_find_device(&net_class, NULL, np, of_dev_node_match);
2305 if (!dev)
2308 return to_net_dev(dev);
2318 struct device *dev = &ndev->dev;
2321 dev_set_uevent_suppress(dev, 1);
2323 kobject_get(&dev->kobj);
2327 pm_runtime_set_memalloc_noio(dev, false);
2329 device_del(dev);
2335 struct device *dev = &ndev->dev;
2339 device_initialize(dev);
2340 dev->class = &net_class;
2341 dev->platform_data = ndev;
2342 dev->groups = groups;
2344 dev_set_name(dev, "%s", ndev->name);
2358 error = device_add(dev);
2364 device_del(dev);
2368 pm_runtime_set_memalloc_noio(dev, true);
2381 struct device *dev = &ndev->dev;
2393 error = device_change_owner(dev, new_uid, new_gid);