162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci#ifndef _NET_CORE_DEV_H
362306a36Sopenharmony_ci#define _NET_CORE_DEV_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/types.h>
662306a36Sopenharmony_ci
762306a36Sopenharmony_cistruct net;
862306a36Sopenharmony_cistruct net_device;
962306a36Sopenharmony_cistruct netdev_bpf;
1062306a36Sopenharmony_cistruct netdev_phys_item_id;
1162306a36Sopenharmony_cistruct netlink_ext_ack;
1262306a36Sopenharmony_cistruct cpumask;
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci/* Random bits of netdevice that don't need to be exposed */
1562306a36Sopenharmony_ci#define FLOW_LIMIT_HISTORY	(1 << 7)  /* must be ^2 and !overflow buckets */
1662306a36Sopenharmony_cistruct sd_flow_limit {
1762306a36Sopenharmony_ci	u64			count;
1862306a36Sopenharmony_ci	unsigned int		num_buckets;
1962306a36Sopenharmony_ci	unsigned int		history_head;
2062306a36Sopenharmony_ci	u16			history[FLOW_LIMIT_HISTORY];
2162306a36Sopenharmony_ci	u8			buckets[];
2262306a36Sopenharmony_ci};
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ciextern int netdev_flow_limit_table_len;
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci#ifdef CONFIG_PROC_FS
2762306a36Sopenharmony_ciint __init dev_proc_init(void);
2862306a36Sopenharmony_ci#else
2962306a36Sopenharmony_ci#define dev_proc_init() 0
3062306a36Sopenharmony_ci#endif
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_civoid linkwatch_init_dev(struct net_device *dev);
3362306a36Sopenharmony_civoid linkwatch_forget_dev(struct net_device *dev);
3462306a36Sopenharmony_civoid linkwatch_run_queue(void);
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_civoid dev_addr_flush(struct net_device *dev);
3762306a36Sopenharmony_ciint dev_addr_init(struct net_device *dev);
3862306a36Sopenharmony_civoid dev_addr_check(struct net_device *dev);
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci/* sysctls not referred to from outside net/core/ */
4162306a36Sopenharmony_ciextern int		netdev_budget;
4262306a36Sopenharmony_ciextern unsigned int	netdev_budget_usecs;
4362306a36Sopenharmony_ciextern unsigned int	sysctl_skb_defer_max;
4462306a36Sopenharmony_ciextern int		netdev_tstamp_prequeue;
4562306a36Sopenharmony_ciextern int		netdev_unregister_timeout_secs;
4662306a36Sopenharmony_ciextern int		weight_p;
4762306a36Sopenharmony_ciextern int		dev_weight_rx_bias;
4862306a36Sopenharmony_ciextern int		dev_weight_tx_bias;
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci/* rtnl helpers */
5162306a36Sopenharmony_ciextern struct list_head net_todo_list;
5262306a36Sopenharmony_civoid netdev_run_todo(void);
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci/* netdev management, shared between various uAPI entry points */
5562306a36Sopenharmony_cistruct netdev_name_node {
5662306a36Sopenharmony_ci	struct hlist_node hlist;
5762306a36Sopenharmony_ci	struct list_head list;
5862306a36Sopenharmony_ci	struct net_device *dev;
5962306a36Sopenharmony_ci	const char *name;
6062306a36Sopenharmony_ci};
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ciint netdev_get_name(struct net *net, char *name, int ifindex);
6362306a36Sopenharmony_ciint dev_change_name(struct net_device *dev, const char *newname);
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define netdev_for_each_altname(dev, namenode)				\
6662306a36Sopenharmony_ci	list_for_each_entry((namenode), &(dev)->name_node->list, list)
6762306a36Sopenharmony_ci#define netdev_for_each_altname_safe(dev, namenode, next)		\
6862306a36Sopenharmony_ci	list_for_each_entry_safe((namenode), (next), &(dev)->name_node->list, \
6962306a36Sopenharmony_ci				 list)
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ciint netdev_name_node_alt_create(struct net_device *dev, const char *name);
7262306a36Sopenharmony_ciint netdev_name_node_alt_destroy(struct net_device *dev, const char *name);
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ciint dev_validate_mtu(struct net_device *dev, int mtu,
7562306a36Sopenharmony_ci		     struct netlink_ext_ack *extack);
7662306a36Sopenharmony_ciint dev_set_mtu_ext(struct net_device *dev, int mtu,
7762306a36Sopenharmony_ci		    struct netlink_ext_ack *extack);
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ciint dev_get_phys_port_id(struct net_device *dev,
8062306a36Sopenharmony_ci			 struct netdev_phys_item_id *ppid);
8162306a36Sopenharmony_ciint dev_get_phys_port_name(struct net_device *dev,
8262306a36Sopenharmony_ci			   char *name, size_t len);
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ciint dev_change_proto_down(struct net_device *dev, bool proto_down);
8562306a36Sopenharmony_civoid dev_change_proto_down_reason(struct net_device *dev, unsigned long mask,
8662306a36Sopenharmony_ci				  u32 value);
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_citypedef int (*bpf_op_t)(struct net_device *dev, struct netdev_bpf *bpf);
8962306a36Sopenharmony_ciint dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
9062306a36Sopenharmony_ci		      int fd, int expected_fd, u32 flags);
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ciint dev_change_tx_queue_len(struct net_device *dev, unsigned long new_len);
9362306a36Sopenharmony_civoid dev_set_group(struct net_device *dev, int new_group);
9462306a36Sopenharmony_ciint dev_change_carrier(struct net_device *dev, bool new_carrier);
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_civoid __dev_set_rx_mode(struct net_device *dev);
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_civoid __dev_notify_flags(struct net_device *dev, unsigned int old_flags,
9962306a36Sopenharmony_ci			unsigned int gchanges, u32 portid,
10062306a36Sopenharmony_ci			const struct nlmsghdr *nlh);
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_civoid unregister_netdevice_many_notify(struct list_head *head,
10362306a36Sopenharmony_ci				      u32 portid, const struct nlmsghdr *nlh);
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_cistatic inline void netif_set_gso_max_size(struct net_device *dev,
10662306a36Sopenharmony_ci					  unsigned int size)
10762306a36Sopenharmony_ci{
10862306a36Sopenharmony_ci	/* dev->gso_max_size is read locklessly from sk_setup_caps() */
10962306a36Sopenharmony_ci	WRITE_ONCE(dev->gso_max_size, size);
11062306a36Sopenharmony_ci	if (size <= GSO_LEGACY_MAX_SIZE)
11162306a36Sopenharmony_ci		WRITE_ONCE(dev->gso_ipv4_max_size, size);
11262306a36Sopenharmony_ci}
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_cistatic inline void netif_set_gso_max_segs(struct net_device *dev,
11562306a36Sopenharmony_ci					  unsigned int segs)
11662306a36Sopenharmony_ci{
11762306a36Sopenharmony_ci	/* dev->gso_max_segs is read locklessly from sk_setup_caps() */
11862306a36Sopenharmony_ci	WRITE_ONCE(dev->gso_max_segs, segs);
11962306a36Sopenharmony_ci}
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_cistatic inline void netif_set_gro_max_size(struct net_device *dev,
12262306a36Sopenharmony_ci					  unsigned int size)
12362306a36Sopenharmony_ci{
12462306a36Sopenharmony_ci	/* This pairs with the READ_ONCE() in skb_gro_receive() */
12562306a36Sopenharmony_ci	WRITE_ONCE(dev->gro_max_size, size);
12662306a36Sopenharmony_ci	if (size <= GRO_LEGACY_MAX_SIZE)
12762306a36Sopenharmony_ci		WRITE_ONCE(dev->gro_ipv4_max_size, size);
12862306a36Sopenharmony_ci}
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_cistatic inline void netif_set_gso_ipv4_max_size(struct net_device *dev,
13162306a36Sopenharmony_ci					       unsigned int size)
13262306a36Sopenharmony_ci{
13362306a36Sopenharmony_ci	/* dev->gso_ipv4_max_size is read locklessly from sk_setup_caps() */
13462306a36Sopenharmony_ci	WRITE_ONCE(dev->gso_ipv4_max_size, size);
13562306a36Sopenharmony_ci}
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_cistatic inline void netif_set_gro_ipv4_max_size(struct net_device *dev,
13862306a36Sopenharmony_ci					       unsigned int size)
13962306a36Sopenharmony_ci{
14062306a36Sopenharmony_ci	/* This pairs with the READ_ONCE() in skb_gro_receive() */
14162306a36Sopenharmony_ci	WRITE_ONCE(dev->gro_ipv4_max_size, size);
14262306a36Sopenharmony_ci}
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ciint rps_cpumask_housekeeping(struct cpumask *mask);
14562306a36Sopenharmony_ci#endif
146