1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _NET_CORE_DEV_H
3 #define _NET_CORE_DEV_H
5 #include <linux/types.h>
10 struct netdev_phys_item_id;
11 struct netlink_ext_ack;
14 /* Random bits of netdevice that don't need to be exposed */
15 #define FLOW_LIMIT_HISTORY (1 << 7) /* must be ^2 and !overflow buckets */
16 struct sd_flow_limit {
18 unsigned int num_buckets;
19 unsigned int history_head;
20 u16 history[FLOW_LIMIT_HISTORY];
24 extern int netdev_flow_limit_table_len;
27 int __init dev_proc_init(void);
29 #define dev_proc_init() 0
32 void linkwatch_init_dev(struct net_device *dev);
33 void linkwatch_forget_dev(struct net_device *dev);
34 void linkwatch_run_queue(void);
36 void dev_addr_flush(struct net_device *dev);
37 int dev_addr_init(struct net_device *dev);
38 void dev_addr_check(struct net_device *dev);
40 /* sysctls not referred to from outside net/core/ */
41 extern int netdev_budget;
42 extern unsigned int netdev_budget_usecs;
43 extern unsigned int sysctl_skb_defer_max;
44 extern int netdev_tstamp_prequeue;
45 extern int netdev_unregister_timeout_secs;
47 extern int dev_weight_rx_bias;
48 extern int dev_weight_tx_bias;
51 extern struct list_head net_todo_list;
52 void netdev_run_todo(void);
54 /* netdev management, shared between various uAPI entry points */
55 struct netdev_name_node {
56 struct hlist_node hlist;
57 struct list_head list;
58 struct net_device *dev;
62 int netdev_get_name(struct net *net, char *name, int ifindex);
63 int dev_change_name(struct net_device *dev, const char *newname);
65 #define netdev_for_each_altname(dev, namenode) \
66 list_for_each_entry((namenode), &(dev)->name_node->list, list)
67 #define netdev_for_each_altname_safe(dev, namenode, next) \
68 list_for_each_entry_safe((namenode), (next), &(dev)->name_node->list, \
71 int netdev_name_node_alt_create(struct net_device *dev, const char *name);
72 int netdev_name_node_alt_destroy(struct net_device *dev, const char *name);
74 int dev_validate_mtu(struct net_device *dev, int mtu,
75 struct netlink_ext_ack *extack);
76 int dev_set_mtu_ext(struct net_device *dev, int mtu,
77 struct netlink_ext_ack *extack);
79 int dev_get_phys_port_id(struct net_device *dev,
80 struct netdev_phys_item_id *ppid);
81 int dev_get_phys_port_name(struct net_device *dev,
82 char *name, size_t len);
84 int dev_change_proto_down(struct net_device *dev, bool proto_down);
85 void dev_change_proto_down_reason(struct net_device *dev, unsigned long mask,
88 typedef int (*bpf_op_t)(struct net_device *dev, struct netdev_bpf *bpf);
89 int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
90 int fd, int expected_fd, u32 flags);
92 int dev_change_tx_queue_len(struct net_device *dev, unsigned long new_len);
93 void dev_set_group(struct net_device *dev, int new_group);
94 int dev_change_carrier(struct net_device *dev, bool new_carrier);
96 void __dev_set_rx_mode(struct net_device *dev);
98 void __dev_notify_flags(struct net_device *dev, unsigned int old_flags,
99 unsigned int gchanges, u32 portid,
100 const struct nlmsghdr *nlh);
102 void unregister_netdevice_many_notify(struct list_head *head,
103 u32 portid, const struct nlmsghdr *nlh);
105 static inline void netif_set_gso_max_size(struct net_device *dev,
108 /* dev->gso_max_size is read locklessly from sk_setup_caps() */
109 WRITE_ONCE(dev->gso_max_size, size);
110 if (size <= GSO_LEGACY_MAX_SIZE)
111 WRITE_ONCE(dev->gso_ipv4_max_size, size);
114 static inline void netif_set_gso_max_segs(struct net_device *dev,
117 /* dev->gso_max_segs is read locklessly from sk_setup_caps() */
118 WRITE_ONCE(dev->gso_max_segs, segs);
121 static inline void netif_set_gro_max_size(struct net_device *dev,
124 /* This pairs with the READ_ONCE() in skb_gro_receive() */
125 WRITE_ONCE(dev->gro_max_size, size);
126 if (size <= GRO_LEGACY_MAX_SIZE)
127 WRITE_ONCE(dev->gro_ipv4_max_size, size);
130 static inline void netif_set_gso_ipv4_max_size(struct net_device *dev,
133 /* dev->gso_ipv4_max_size is read locklessly from sk_setup_caps() */
134 WRITE_ONCE(dev->gso_ipv4_max_size, size);
137 static inline void netif_set_gro_ipv4_max_size(struct net_device *dev,
140 /* This pairs with the READ_ONCE() in skb_gro_receive() */
141 WRITE_ONCE(dev->gro_ipv4_max_size, size);
144 int rps_cpumask_housekeeping(struct cpumask *mask);