xref: /OK3568_Linux_fs/kernel/include/linux/if_tap.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _LINUX_IF_TAP_H_
3*4882a593Smuzhiyun #define _LINUX_IF_TAP_H_
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_TAP)
6*4882a593Smuzhiyun struct socket *tap_get_socket(struct file *);
7*4882a593Smuzhiyun struct ptr_ring *tap_get_ptr_ring(struct file *file);
8*4882a593Smuzhiyun #else
9*4882a593Smuzhiyun #include <linux/err.h>
10*4882a593Smuzhiyun #include <linux/errno.h>
11*4882a593Smuzhiyun struct file;
12*4882a593Smuzhiyun struct socket;
tap_get_socket(struct file * f)13*4882a593Smuzhiyun static inline struct socket *tap_get_socket(struct file *f)
14*4882a593Smuzhiyun {
15*4882a593Smuzhiyun 	return ERR_PTR(-EINVAL);
16*4882a593Smuzhiyun }
tap_get_ptr_ring(struct file * f)17*4882a593Smuzhiyun static inline struct ptr_ring *tap_get_ptr_ring(struct file *f)
18*4882a593Smuzhiyun {
19*4882a593Smuzhiyun 	return ERR_PTR(-EINVAL);
20*4882a593Smuzhiyun }
21*4882a593Smuzhiyun #endif /* CONFIG_TAP */
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #include <net/sock.h>
24*4882a593Smuzhiyun #include <linux/skb_array.h>
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun /*
27*4882a593Smuzhiyun  * Maximum times a tap device can be opened. This can be used to
28*4882a593Smuzhiyun  * configure the number of receive queue, e.g. for multiqueue virtio.
29*4882a593Smuzhiyun  */
30*4882a593Smuzhiyun #define MAX_TAP_QUEUES 256
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun struct tap_queue;
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun struct tap_dev {
35*4882a593Smuzhiyun 	struct net_device	*dev;
36*4882a593Smuzhiyun 	u16			flags;
37*4882a593Smuzhiyun 	/* This array tracks active taps. */
38*4882a593Smuzhiyun 	struct tap_queue    __rcu *taps[MAX_TAP_QUEUES];
39*4882a593Smuzhiyun 	/* This list tracks all taps (both enabled and disabled) */
40*4882a593Smuzhiyun 	struct list_head	queue_list;
41*4882a593Smuzhiyun 	int			numvtaps;
42*4882a593Smuzhiyun 	int			numqueues;
43*4882a593Smuzhiyun 	netdev_features_t	tap_features;
44*4882a593Smuzhiyun 	int			minor;
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun 	void (*update_features)(struct tap_dev *tap, netdev_features_t features);
47*4882a593Smuzhiyun 	void (*count_tx_dropped)(struct tap_dev *tap);
48*4882a593Smuzhiyun 	void (*count_rx_dropped)(struct tap_dev *tap);
49*4882a593Smuzhiyun };
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun /*
52*4882a593Smuzhiyun  * A tap queue is the central object of tap module, it connects
53*4882a593Smuzhiyun  * an open character device to virtual interface. There can be
54*4882a593Smuzhiyun  * multiple queues on one interface, which map back to queues
55*4882a593Smuzhiyun  * implemented in hardware on the underlying device.
56*4882a593Smuzhiyun  *
57*4882a593Smuzhiyun  * tap_proto is used to allocate queues through the sock allocation
58*4882a593Smuzhiyun  * mechanism.
59*4882a593Smuzhiyun  *
60*4882a593Smuzhiyun  */
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun struct tap_queue {
63*4882a593Smuzhiyun 	struct sock sk;
64*4882a593Smuzhiyun 	struct socket sock;
65*4882a593Smuzhiyun 	int vnet_hdr_sz;
66*4882a593Smuzhiyun 	struct tap_dev __rcu *tap;
67*4882a593Smuzhiyun 	struct file *file;
68*4882a593Smuzhiyun 	unsigned int flags;
69*4882a593Smuzhiyun 	u16 queue_index;
70*4882a593Smuzhiyun 	bool enabled;
71*4882a593Smuzhiyun 	struct list_head next;
72*4882a593Smuzhiyun 	struct ptr_ring ring;
73*4882a593Smuzhiyun };
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun rx_handler_result_t tap_handle_frame(struct sk_buff **pskb);
76*4882a593Smuzhiyun void tap_del_queues(struct tap_dev *tap);
77*4882a593Smuzhiyun int tap_get_minor(dev_t major, struct tap_dev *tap);
78*4882a593Smuzhiyun void tap_free_minor(dev_t major, struct tap_dev *tap);
79*4882a593Smuzhiyun int tap_queue_resize(struct tap_dev *tap);
80*4882a593Smuzhiyun int tap_create_cdev(struct cdev *tap_cdev, dev_t *tap_major,
81*4882a593Smuzhiyun 		    const char *device_name, struct module *module);
82*4882a593Smuzhiyun void tap_destroy_cdev(dev_t major, struct cdev *tap_cdev);
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun #endif /*_LINUX_IF_TAP_H_*/
85