kni_dev.h revision 9365d6cf
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 "compat.h"
34
35#include <linux/if.h>
36#include <linux/wait.h>
37#ifdef HAVE_SIGNAL_FUNCTIONS_OWN_HEADER
38#include <linux/sched/signal.h>
39#else
40#include <linux/sched.h>
41#endif
42#include <linux/netdevice.h>
43#include <linux/spinlock.h>
44#include <linux/list.h>
45
46#ifdef RTE_KNI_VHOST
47#include <net/sock.h>
48#endif
49
50#include <exec-env/rte_kni_common.h>
51#define KNI_KTHREAD_RESCHEDULE_INTERVAL 5 /* us */
52
53#define MBUF_BURST_SZ 32
54
55/**
56 * A structure describing the private information for a kni device.
57 */
58struct kni_dev {
59	/* kni list */
60	struct list_head list;
61
62	struct net_device_stats stats;
63	int status;
64	uint16_t group_id;           /* Group ID of a group of KNI devices */
65	uint32_t core_id;            /* Core ID to bind */
66	char name[RTE_KNI_NAMESIZE]; /* Network device name */
67	struct task_struct *pthread;
68
69	/* wait queue for req/resp */
70	wait_queue_head_t wq;
71	struct mutex sync_lock;
72
73	/* PCI device id */
74	uint16_t device_id;
75
76	/* kni device */
77	struct net_device *net_dev;
78	struct net_device *lad_dev;
79	struct pci_dev *pci_dev;
80
81	/* queue for packets to be sent out */
82	void *tx_q;
83
84	/* queue for the packets received */
85	void *rx_q;
86
87	/* queue for the allocated mbufs those can be used to save sk buffs */
88	void *alloc_q;
89
90	/* free queue for the mbufs to be freed */
91	void *free_q;
92
93	/* request queue */
94	void *req_q;
95
96	/* response queue */
97	void *resp_q;
98
99	void *sync_kva;
100	void *sync_va;
101
102	void *mbuf_kva;
103	void *mbuf_va;
104
105	/* mbuf size */
106	uint32_t mbuf_size;
107
108	/* synchro for request processing */
109	unsigned long synchro;
110
111#ifdef RTE_KNI_VHOST
112	struct kni_vhost_queue *vhost_queue;
113
114	volatile enum {
115		BE_STOP = 0x1,
116		BE_START = 0x2,
117		BE_FINISH = 0x4,
118	} vq_status;
119#endif
120	/* buffers */
121	void *pa[MBUF_BURST_SZ];
122	void *va[MBUF_BURST_SZ];
123	void *alloc_pa[MBUF_BURST_SZ];
124	void *alloc_va[MBUF_BURST_SZ];
125};
126
127#ifdef RTE_KNI_VHOST
128uint32_t
129kni_poll(struct file *file, struct socket *sock, poll_table * wait);
130int kni_chk_vhost_rx(struct kni_dev *kni);
131int kni_vhost_init(struct kni_dev *kni);
132int kni_vhost_backend_release(struct kni_dev *kni);
133
134struct kni_vhost_queue {
135	struct sock sk;
136	struct socket *sock;
137	int vnet_hdr_sz;
138	struct kni_dev *kni;
139	int sockfd;
140	uint32_t flags;
141	struct sk_buff *cache;
142	struct rte_kni_fifo *fifo;
143};
144
145#endif
146
147void kni_net_rx(struct kni_dev *kni);
148void kni_net_init(struct net_device *dev);
149void kni_net_config_lo_mode(char *lo_str);
150void kni_net_poll_resp(struct kni_dev *kni);
151void kni_set_ethtool_ops(struct net_device *netdev);
152
153int ixgbe_kni_probe(struct pci_dev *pdev, struct net_device **lad_dev);
154void ixgbe_kni_remove(struct pci_dev *pdev);
155int igb_kni_probe(struct pci_dev *pdev, struct net_device **lad_dev);
156void igb_kni_remove(struct pci_dev *pdev);
157
158#endif
159