xref: /dpdk/drivers/net/tap/rte_eth_tap.h (revision 2bb2f755b78d50687e0dd414a5f296bce6824c84)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2017 6WIND S.A.
3  * Copyright 2017 Mellanox Technologies, Ltd
4  */
5 
6 #ifndef _RTE_ETH_TAP_H_
7 #define _RTE_ETH_TAP_H_
8 
9 #include <sys/queue.h>
10 #include <sys/uio.h>
11 #include <inttypes.h>
12 #include <net/if.h>
13 
14 #include <linux/if_tun.h>
15 
16 #include <ethdev_driver.h>
17 #include <rte_ether.h>
18 #include <rte_gso.h>
19 
20 #include "tap_log.h"
21 
22 #ifdef IFF_MULTI_QUEUE
23 #define RTE_PMD_TAP_MAX_QUEUES	TAP_MAX_QUEUES
24 #else
25 #define RTE_PMD_TAP_MAX_QUEUES	1
26 #endif
27 #define MAX_GSO_MBUFS 64
28 
29 enum rte_tuntap_type {
30 	ETH_TUNTAP_TYPE_UNKNOWN,
31 	ETH_TUNTAP_TYPE_TUN,
32 	ETH_TUNTAP_TYPE_TAP,
33 	ETH_TUNTAP_TYPE_MAX,
34 };
35 
36 struct pkt_stats {
37 	uint64_t opackets;              /* Number of output packets */
38 	uint64_t ipackets;              /* Number of input packets */
39 	uint64_t obytes;                /* Number of bytes on output */
40 	uint64_t ibytes;                /* Number of bytes on input */
41 	uint64_t errs;                  /* Number of TX error packets */
42 	uint64_t ierrors;               /* Number of RX error packets */
43 	uint64_t rx_nombuf;             /* Nb of RX mbuf alloc failures */
44 };
45 
46 struct rx_queue {
47 	struct rte_mempool *mp;         /* Mempool for RX packets */
48 	uint32_t trigger_seen;          /* Last seen Rx trigger value */
49 	uint16_t in_port;               /* Port ID */
50 	uint16_t queue_id;		/* queue ID*/
51 	struct pkt_stats stats;         /* Stats for this RX queue */
52 	uint16_t nb_rx_desc;            /* max number of mbufs available */
53 	struct rte_eth_rxmode *rxmode;  /* RX features */
54 	struct rte_mbuf *pool;          /* mbufs pool for this queue */
55 	struct iovec (*iovecs)[];       /* descriptors for this queue */
56 	struct tun_pi pi;               /* packet info for iovecs */
57 };
58 
59 struct tx_queue {
60 	int type;                       /* Type field - TUN|TAP */
61 	uint16_t *mtu;                  /* Pointer to MTU from dev_data */
62 	uint16_t csum:1;                /* Enable checksum offloading */
63 	struct pkt_stats stats;         /* Stats for this TX queue */
64 	struct rte_gso_ctx gso_ctx;     /* GSO context */
65 	uint16_t out_port;              /* Port ID */
66 	uint16_t queue_id;		/* queue ID*/
67 };
68 
69 struct pmd_internals {
70 	struct rte_eth_dev *dev;          /* Ethernet device. */
71 	char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
72 	char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
73 	int type;                         /* Type field - TUN|TAP */
74 	int persist;			  /* 1 if keep link up, else 0 */
75 	struct rte_ether_addr eth_addr;   /* Mac address of the device port */
76 	struct ifreq remote_initial_flags;/* Remote netdevice flags on init */
77 	int remote_if_index;              /* remote netdevice IF_INDEX */
78 	int if_index;                     /* IF_INDEX for the port */
79 	int ioctl_sock;                   /* socket for ioctl calls */
80 
81 #ifdef HAVE_TCA_FLOWER
82 	int nlsk_fd;                      /* Netlink socket fd */
83 	int flow_isolate;                 /* 1 if flow isolation is enabled */
84 
85 	struct tap_rss *rss;		  /* BPF program */
86 
87 	LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
88 	/* implicit rte_flow rules set when a remote device is active */
89 	LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
90 #endif
91 
92 	struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
93 	struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
94 	struct rte_intr_handle *intr_handle;         /* LSC interrupt handle. */
95 	int ka_fd;                        /* keep-alive file descriptor */
96 	struct rte_mempool *gso_ctx_mp;     /* Mempool for GSO packets */
97 };
98 
99 struct pmd_process_private {
100 	int fds[RTE_PMD_TAP_MAX_QUEUES];
101 };
102 
103 /* tap_intr.c */
104 
105 int tap_rx_intr_vec_set(struct rte_eth_dev *dev, int set);
106 
107 #endif /* _RTE_ETH_TAP_H_ */
108