1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright(c) 2010-2014 Intel Corporation.
12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14 #define KNI_VERSION "1.0"
19 #include <linux/wait.h>
20 #ifdef HAVE_SIGNAL_FUNCTIONS_OWN_HEADER
21 #include <linux/sched/signal.h>
23 #include <linux/sched.h>
25 #include <linux/netdevice.h>
26 #include <linux/spinlock.h>
27 #include <linux/list.h>
29 #include <rte_kni_common.h>
30 #define KNI_KTHREAD_RESCHEDULE_INTERVAL 5 /* us */
32 #define MBUF_BURST_SZ 32
34 /* Default carrier state for created KNI network interfaces */
35 extern uint32_t kni_dflt_carrier;
38 * A structure describing the private information for a kni device.
42 struct list_head list;
46 uint32_t core_id; /* Core ID to bind */
47 char name[RTE_KNI_NAMESIZE]; /* Network device name */
48 struct task_struct *pthread;
50 /* wait queue for req/resp */
52 struct mutex sync_lock;
55 struct net_device *net_dev;
57 /* queue for packets to be sent out */
58 struct rte_kni_fifo *tx_q;
60 /* queue for the packets received */
61 struct rte_kni_fifo *rx_q;
63 /* queue for the allocated mbufs those can be used to save sk buffs */
64 struct rte_kni_fifo *alloc_q;
66 /* free queue for the mbufs to be freed */
67 struct rte_kni_fifo *free_q;
70 struct rte_kni_fifo *req_q;
73 struct rte_kni_fifo *resp_q;
85 void *pa[MBUF_BURST_SZ];
86 void *va[MBUF_BURST_SZ];
87 void *alloc_pa[MBUF_BURST_SZ];
88 void *alloc_va[MBUF_BURST_SZ];
90 struct task_struct *usr_tsk;
93 #ifdef HAVE_IOVA_TO_KVA_MAPPING_SUPPORT
94 static inline phys_addr_t iova_to_phys(struct task_struct *tsk,
97 phys_addr_t offset, phys_addr;
98 struct page *page = NULL;
101 offset = iova & (PAGE_SIZE - 1);
103 /* Read one page struct info */
104 ret = get_user_pages_remote(tsk, tsk->mm, iova, 1,
105 FOLL_TOUCH, &page, NULL, NULL);
109 phys_addr = page_to_phys(page) | offset;
115 static inline void *iova_to_kva(struct task_struct *tsk, unsigned long iova)
117 return phys_to_virt(iova_to_phys(tsk, iova));
121 void kni_net_release_fifo_phy(struct kni_dev *kni);
122 void kni_net_rx(struct kni_dev *kni);
123 void kni_net_init(struct net_device *dev);
124 void kni_net_config_lo_mode(char *lo_str);
125 void kni_net_poll_resp(struct kni_dev *kni);