7b21d0d8b798ec0f3a8dc0c20e17e11e4933cb90
[dpdk.git] / drivers / net / tap / rte_eth_tap.h
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 <rte_ethdev_driver.h>
17 #include <rte_ether.h>
18 #include "tap_log.h"
19
20 #ifdef IFF_MULTI_QUEUE
21 #define RTE_PMD_TAP_MAX_QUEUES  TAP_MAX_QUEUES
22 #else
23 #define RTE_PMD_TAP_MAX_QUEUES  1
24 #endif
25
26 enum rte_tuntap_type {
27         ETH_TUNTAP_TYPE_UNKNOWN,
28         ETH_TUNTAP_TYPE_TUN,
29         ETH_TUNTAP_TYPE_TAP,
30         ETH_TUNTAP_TYPE_MAX,
31 };
32
33 struct pkt_stats {
34         uint64_t opackets;              /* Number of output packets */
35         uint64_t ipackets;              /* Number of input packets */
36         uint64_t obytes;                /* Number of bytes on output */
37         uint64_t ibytes;                /* Number of bytes on input */
38         uint64_t errs;                  /* Number of TX error packets */
39         uint64_t ierrors;               /* Number of RX error packets */
40         uint64_t rx_nombuf;             /* Nb of RX mbuf alloc failures */
41 };
42
43 struct rx_queue {
44         struct rte_mempool *mp;         /* Mempool for RX packets */
45         uint32_t trigger_seen;          /* Last seen Rx trigger value */
46         uint16_t in_port;               /* Port ID */
47         int fd;
48         struct pkt_stats stats;         /* Stats for this RX queue */
49         uint16_t nb_rx_desc;            /* max number of mbufs available */
50         struct rte_eth_rxmode *rxmode;  /* RX features */
51         struct rte_mbuf *pool;          /* mbufs pool for this queue */
52         struct iovec (*iovecs)[];       /* descriptors for this queue */
53         struct tun_pi pi;               /* packet info for iovecs */
54 };
55
56 struct tx_queue {
57         int fd;
58         int type;                       /* Type field - TUN|TAP */
59         uint16_t *mtu;                  /* Pointer to MTU from dev_data */
60         uint16_t csum:1;                /* Enable checksum offloading */
61         struct pkt_stats stats;         /* Stats for this TX queue */
62 };
63
64 struct pmd_internals {
65         struct rte_eth_dev *dev;          /* Ethernet device. */
66         char remote_iface[RTE_ETH_NAME_MAX_LEN]; /* Remote netdevice name */
67         char name[RTE_ETH_NAME_MAX_LEN];  /* Internal Tap device name */
68         int type;                         /* Type field - TUN|TAP */
69         struct ether_addr eth_addr;       /* Mac address of the device port */
70         struct ifreq remote_initial_flags;   /* Remote netdevice flags on init */
71         int remote_if_index;              /* remote netdevice IF_INDEX */
72         int if_index;                     /* IF_INDEX for the port */
73         int ioctl_sock;                   /* socket for ioctl calls */
74         int nlsk_fd;                      /* Netlink socket fd */
75         int flow_isolate;                 /* 1 if flow isolation is enabled */
76         int flower_support;               /* 1 if kernel supports, else 0 */
77         int flower_vlan_support;          /* 1 if kernel supports, else 0 */
78         int rss_enabled;                  /* 1 if RSS is enabled, else 0 */
79         /* implicit rules set when RSS is enabled */
80         int map_fd;                       /* BPF RSS map fd */
81         int bpf_fd[RTE_PMD_TAP_MAX_QUEUES];/* List of bpf fds per queue */
82         LIST_HEAD(tap_rss_flows, rte_flow) rss_flows;
83         LIST_HEAD(tap_flows, rte_flow) flows;        /* rte_flow rules */
84         /* implicit rte_flow rules set when a remote device is active */
85         LIST_HEAD(tap_implicit_flows, rte_flow) implicit_flows;
86         struct rx_queue rxq[RTE_PMD_TAP_MAX_QUEUES]; /* List of RX queues */
87         struct tx_queue txq[RTE_PMD_TAP_MAX_QUEUES]; /* List of TX queues */
88         struct rte_intr_handle intr_handle;          /* LSC interrupt handle. */
89         int ka_fd;                        /* keep-alive file descriptor */
90 };
91
92 /* tap_intr.c */
93
94 int tap_rx_intr_vec_set(struct rte_eth_dev *dev, int set);
95
96 #endif /* _RTE_ETH_TAP_H_ */