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;
37 /* Request processing support for bifurcated drivers. */
38 extern uint32_t bifurcated_support;
41 * A structure describing the private information for a kni device.
45 struct list_head list;
49 uint32_t core_id; /* Core ID to bind */
50 char name[RTE_KNI_NAMESIZE]; /* Network device name */
51 struct task_struct *pthread;
53 /* wait queue for req/resp */
55 struct mutex sync_lock;
58 struct net_device *net_dev;
60 /* queue for packets to be sent out */
61 struct rte_kni_fifo *tx_q;
63 /* queue for the packets received */
64 struct rte_kni_fifo *rx_q;
66 /* queue for the allocated mbufs those can be used to save sk buffs */
67 struct rte_kni_fifo *alloc_q;
69 /* free queue for the mbufs to be freed */
70 struct rte_kni_fifo *free_q;
73 struct rte_kni_fifo *req_q;
76 struct rte_kni_fifo *resp_q;
88 void *pa[MBUF_BURST_SZ];
89 void *va[MBUF_BURST_SZ];
90 void *alloc_pa[MBUF_BURST_SZ];
91 void *alloc_va[MBUF_BURST_SZ];
93 struct task_struct *usr_tsk;
96 #ifdef HAVE_IOVA_TO_KVA_MAPPING_SUPPORT
97 static inline phys_addr_t iova_to_phys(struct task_struct *tsk,
100 phys_addr_t offset, phys_addr;
101 struct page *page = NULL;
104 offset = iova & (PAGE_SIZE - 1);
106 /* Read one page struct info */
107 #ifdef HAVE_TSK_IN_GUP
108 ret = get_user_pages_remote(tsk, tsk->mm, iova, 1,
109 FOLL_TOUCH, &page, NULL, NULL);
111 ret = get_user_pages_remote(tsk->mm, iova, 1,
112 FOLL_TOUCH, &page, NULL, NULL);
117 phys_addr = page_to_phys(page) | offset;
123 static inline void *iova_to_kva(struct task_struct *tsk, unsigned long iova)
125 return phys_to_virt(iova_to_phys(tsk, iova));
129 void kni_net_release_fifo_phy(struct kni_dev *kni);
130 void kni_net_rx(struct kni_dev *kni);
131 void kni_net_init(struct net_device *dev);
132 void kni_net_config_lo_mode(char *lo_str);
133 void kni_net_poll_resp(struct kni_dev *kni);