Imported Upstream version 16.11
[deb_dpdk.git] / lib / librte_eal / linuxapp / kni / kni_dev.h
1 /*-
2  * GPL LICENSE SUMMARY
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of version 2 of the GNU General Public License as
8  *   published by the Free Software Foundation.
9  *
10  *   This program is distributed in the hope that it will be useful, but
11  *   WITHOUT ANY WARRANTY; without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *   General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program; if not, write to the Free Software
17  *   Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18  *   The full GNU General Public License is included in this distribution
19  *   in the file called LICENSE.GPL.
20  *
21  *   Contact Information:
22  *   Intel Corporation
23  */
24
25 #ifndef _KNI_DEV_H_
26 #define _KNI_DEV_H_
27
28 #ifdef pr_fmt
29 #undef pr_fmt
30 #endif
31 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32
33 #include <linux/if.h>
34 #include <linux/wait.h>
35 #include <linux/sched.h>
36 #include <linux/netdevice.h>
37 #include <linux/spinlock.h>
38 #include <linux/list.h>
39
40 #ifdef RTE_KNI_VHOST
41 #include <net/sock.h>
42 #endif
43
44 #include <exec-env/rte_kni_common.h>
45 #define KNI_KTHREAD_RESCHEDULE_INTERVAL 5 /* us */
46
47 #define MBUF_BURST_SZ 32
48
49 /**
50  * A structure describing the private information for a kni device.
51  */
52 struct kni_dev {
53         /* kni list */
54         struct list_head list;
55
56         struct net_device_stats stats;
57         int status;
58         uint16_t group_id;           /* Group ID of a group of KNI devices */
59         uint32_t core_id;            /* Core ID to bind */
60         char name[RTE_KNI_NAMESIZE]; /* Network device name */
61         struct task_struct *pthread;
62
63         /* wait queue for req/resp */
64         wait_queue_head_t wq;
65         struct mutex sync_lock;
66
67         /* PCI device id */
68         uint16_t device_id;
69
70         /* kni device */
71         struct net_device *net_dev;
72         struct net_device *lad_dev;
73         struct pci_dev *pci_dev;
74
75         /* queue for packets to be sent out */
76         void *tx_q;
77
78         /* queue for the packets received */
79         void *rx_q;
80
81         /* queue for the allocated mbufs those can be used to save sk buffs */
82         void *alloc_q;
83
84         /* free queue for the mbufs to be freed */
85         void *free_q;
86
87         /* request queue */
88         void *req_q;
89
90         /* response queue */
91         void *resp_q;
92
93         void *sync_kva;
94         void *sync_va;
95
96         void *mbuf_kva;
97         void *mbuf_va;
98
99         /* mbuf size */
100         uint32_t mbuf_size;
101
102         /* synchro for request processing */
103         unsigned long synchro;
104
105 #ifdef RTE_KNI_VHOST
106         struct kni_vhost_queue *vhost_queue;
107
108         volatile enum {
109                 BE_STOP = 0x1,
110                 BE_START = 0x2,
111                 BE_FINISH = 0x4,
112         } vq_status;
113 #endif
114         /* buffers */
115         void *pa[MBUF_BURST_SZ];
116         void *va[MBUF_BURST_SZ];
117         void *alloc_pa[MBUF_BURST_SZ];
118         void *alloc_va[MBUF_BURST_SZ];
119 };
120
121 #ifdef RTE_KNI_VHOST
122 uint32_t
123 kni_poll(struct file *file, struct socket *sock, poll_table * wait);
124 int kni_chk_vhost_rx(struct kni_dev *kni);
125 int kni_vhost_init(struct kni_dev *kni);
126 int kni_vhost_backend_release(struct kni_dev *kni);
127
128 struct kni_vhost_queue {
129         struct sock sk;
130         struct socket *sock;
131         int vnet_hdr_sz;
132         struct kni_dev *kni;
133         int sockfd;
134         uint32_t flags;
135         struct sk_buff *cache;
136         struct rte_kni_fifo *fifo;
137 };
138
139 #endif
140
141 void kni_net_rx(struct kni_dev *kni);
142 void kni_net_init(struct net_device *dev);
143 void kni_net_config_lo_mode(char *lo_str);
144 void kni_net_poll_resp(struct kni_dev *kni);
145 void kni_set_ethtool_ops(struct net_device *netdev);
146
147 int ixgbe_kni_probe(struct pci_dev *pdev, struct net_device **lad_dev);
148 void ixgbe_kni_remove(struct pci_dev *pdev);
149 int igb_kni_probe(struct pci_dev *pdev, struct net_device **lad_dev);
150 void igb_kni_remove(struct pci_dev *pdev);
151
152 #endif