1acaa9ee9SHemant Agrawal /* SPDX-License-Identifier: GPL-2.0 */
2acaa9ee9SHemant Agrawal /*
3acaa9ee9SHemant Agrawal * Copyright(c) 2010-2014 Intel Corporation.
4acaa9ee9SHemant Agrawal */
5acaa9ee9SHemant Agrawal
6acaa9ee9SHemant Agrawal #ifndef _KNI_DEV_H_
7acaa9ee9SHemant Agrawal #define _KNI_DEV_H_
8acaa9ee9SHemant Agrawal
9acaa9ee9SHemant Agrawal #ifdef pr_fmt
10acaa9ee9SHemant Agrawal #undef pr_fmt
11acaa9ee9SHemant Agrawal #endif
12acaa9ee9SHemant Agrawal #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13acaa9ee9SHemant Agrawal
14398d6f94SStephen Hemminger #define KNI_VERSION "1.0"
15398d6f94SStephen Hemminger
16acaa9ee9SHemant Agrawal #include "compat.h"
17acaa9ee9SHemant Agrawal
18acaa9ee9SHemant Agrawal #include <linux/if.h>
19acaa9ee9SHemant Agrawal #include <linux/wait.h>
20acaa9ee9SHemant Agrawal #ifdef HAVE_SIGNAL_FUNCTIONS_OWN_HEADER
21acaa9ee9SHemant Agrawal #include <linux/sched/signal.h>
22acaa9ee9SHemant Agrawal #else
23acaa9ee9SHemant Agrawal #include <linux/sched.h>
24acaa9ee9SHemant Agrawal #endif
25acaa9ee9SHemant Agrawal #include <linux/netdevice.h>
26acaa9ee9SHemant Agrawal #include <linux/spinlock.h>
27acaa9ee9SHemant Agrawal #include <linux/list.h>
28acaa9ee9SHemant Agrawal
293c458891SThomas Monjalon #include <rte_kni_common.h>
30*5569dd7dSTudor Cornea #define KNI_KTHREAD_MAX_RESCHEDULE_INTERVAL 1000000 /* us */
31acaa9ee9SHemant Agrawal
32acaa9ee9SHemant Agrawal #define MBUF_BURST_SZ 32
33acaa9ee9SHemant Agrawal
3489397a01SDan Gora /* Default carrier state for created KNI network interfaces */
35c793dce9SStephen Hemminger extern uint32_t kni_dflt_carrier;
3689397a01SDan Gora
37a1b2558cSFerruh Yigit /* Request processing support for bifurcated drivers. */
38a1b2558cSFerruh Yigit extern uint32_t bifurcated_support;
39a1b2558cSFerruh Yigit
40acaa9ee9SHemant Agrawal /**
41acaa9ee9SHemant Agrawal * A structure describing the private information for a kni device.
42acaa9ee9SHemant Agrawal */
43acaa9ee9SHemant Agrawal struct kni_dev {
44acaa9ee9SHemant Agrawal /* kni list */
45acaa9ee9SHemant Agrawal struct list_head list;
46acaa9ee9SHemant Agrawal
47e73831dcSVamsi Attunuru uint8_t iova_mode;
48e73831dcSVamsi Attunuru
49acaa9ee9SHemant Agrawal uint32_t core_id; /* Core ID to bind */
50acaa9ee9SHemant Agrawal char name[RTE_KNI_NAMESIZE]; /* Network device name */
51acaa9ee9SHemant Agrawal struct task_struct *pthread;
52acaa9ee9SHemant Agrawal
53acaa9ee9SHemant Agrawal /* wait queue for req/resp */
54acaa9ee9SHemant Agrawal wait_queue_head_t wq;
55acaa9ee9SHemant Agrawal struct mutex sync_lock;
56acaa9ee9SHemant Agrawal
57acaa9ee9SHemant Agrawal /* kni device */
58acaa9ee9SHemant Agrawal struct net_device *net_dev;
59acaa9ee9SHemant Agrawal
60acaa9ee9SHemant Agrawal /* queue for packets to be sent out */
615cb4510cSStephen Hemminger struct rte_kni_fifo *tx_q;
62acaa9ee9SHemant Agrawal
63acaa9ee9SHemant Agrawal /* queue for the packets received */
645cb4510cSStephen Hemminger struct rte_kni_fifo *rx_q;
65acaa9ee9SHemant Agrawal
66acaa9ee9SHemant Agrawal /* queue for the allocated mbufs those can be used to save sk buffs */
675cb4510cSStephen Hemminger struct rte_kni_fifo *alloc_q;
68acaa9ee9SHemant Agrawal
69acaa9ee9SHemant Agrawal /* free queue for the mbufs to be freed */
705cb4510cSStephen Hemminger struct rte_kni_fifo *free_q;
71acaa9ee9SHemant Agrawal
72acaa9ee9SHemant Agrawal /* request queue */
735cb4510cSStephen Hemminger struct rte_kni_fifo *req_q;
74acaa9ee9SHemant Agrawal
75acaa9ee9SHemant Agrawal /* response queue */
765cb4510cSStephen Hemminger struct rte_kni_fifo *resp_q;
77acaa9ee9SHemant Agrawal
78acaa9ee9SHemant Agrawal void *sync_kva;
79acaa9ee9SHemant Agrawal void *sync_va;
80acaa9ee9SHemant Agrawal
81acaa9ee9SHemant Agrawal void *mbuf_kva;
82acaa9ee9SHemant Agrawal void *mbuf_va;
83acaa9ee9SHemant Agrawal
84acaa9ee9SHemant Agrawal /* mbuf size */
85acaa9ee9SHemant Agrawal uint32_t mbuf_size;
86acaa9ee9SHemant Agrawal
87acaa9ee9SHemant Agrawal /* buffers */
88acaa9ee9SHemant Agrawal void *pa[MBUF_BURST_SZ];
89acaa9ee9SHemant Agrawal void *va[MBUF_BURST_SZ];
90acaa9ee9SHemant Agrawal void *alloc_pa[MBUF_BURST_SZ];
91acaa9ee9SHemant Agrawal void *alloc_va[MBUF_BURST_SZ];
92e73831dcSVamsi Attunuru
93e73831dcSVamsi Attunuru struct task_struct *usr_tsk;
94acaa9ee9SHemant Agrawal };
95acaa9ee9SHemant Agrawal
96e73831dcSVamsi Attunuru #ifdef HAVE_IOVA_TO_KVA_MAPPING_SUPPORT
iova_to_phys(struct task_struct * tsk,unsigned long iova)97e73831dcSVamsi Attunuru static inline phys_addr_t iova_to_phys(struct task_struct *tsk,
98e73831dcSVamsi Attunuru unsigned long iova)
99e73831dcSVamsi Attunuru {
100e73831dcSVamsi Attunuru phys_addr_t offset, phys_addr;
101e73831dcSVamsi Attunuru struct page *page = NULL;
102e73831dcSVamsi Attunuru long ret;
103e73831dcSVamsi Attunuru
104e73831dcSVamsi Attunuru offset = iova & (PAGE_SIZE - 1);
105e73831dcSVamsi Attunuru
106e73831dcSVamsi Attunuru /* Read one page struct info */
10787efaea6SFerruh Yigit #ifdef HAVE_TSK_IN_GUP
108e73831dcSVamsi Attunuru ret = get_user_pages_remote(tsk, tsk->mm, iova, 1,
109e73831dcSVamsi Attunuru FOLL_TOUCH, &page, NULL, NULL);
11087efaea6SFerruh Yigit #else
11187efaea6SFerruh Yigit ret = get_user_pages_remote(tsk->mm, iova, 1,
11287efaea6SFerruh Yigit FOLL_TOUCH, &page, NULL, NULL);
11387efaea6SFerruh Yigit #endif
114e73831dcSVamsi Attunuru if (ret < 0)
115e73831dcSVamsi Attunuru return 0;
116e73831dcSVamsi Attunuru
117e73831dcSVamsi Attunuru phys_addr = page_to_phys(page) | offset;
118e73831dcSVamsi Attunuru put_page(page);
119e73831dcSVamsi Attunuru
120e73831dcSVamsi Attunuru return phys_addr;
121e73831dcSVamsi Attunuru }
122e73831dcSVamsi Attunuru
iova_to_kva(struct task_struct * tsk,unsigned long iova)123e73831dcSVamsi Attunuru static inline void *iova_to_kva(struct task_struct *tsk, unsigned long iova)
124e73831dcSVamsi Attunuru {
125e73831dcSVamsi Attunuru return phys_to_virt(iova_to_phys(tsk, iova));
126e73831dcSVamsi Attunuru }
127e73831dcSVamsi Attunuru #endif
128e73831dcSVamsi Attunuru
129e77fec69SYangchao Zhou void kni_net_release_fifo_phy(struct kni_dev *kni);
130acaa9ee9SHemant Agrawal void kni_net_rx(struct kni_dev *kni);
131acaa9ee9SHemant Agrawal void kni_net_init(struct net_device *dev);
132acaa9ee9SHemant Agrawal void kni_net_config_lo_mode(char *lo_str);
133acaa9ee9SHemant Agrawal void kni_net_poll_resp(struct kni_dev *kni);
134acaa9ee9SHemant Agrawal
135acaa9ee9SHemant Agrawal #endif
136