2019-06-25 11:12:58 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/*
|
|
|
|
* Copyright(c) 2010-2014 Intel Corporation.
|
2017-04-21 10:43:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _KNI_DEV_H_
|
|
|
|
#define _KNI_DEV_H_
|
|
|
|
|
2018-05-15 09:49:22 +00:00
|
|
|
#ifdef pr_fmt
|
|
|
|
#undef pr_fmt
|
|
|
|
#endif
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2020-06-18 16:55:50 +00:00
|
|
|
#define KNI_VERSION "1.0"
|
|
|
|
|
2018-01-05 05:50:59 +00:00
|
|
|
#include "compat.h"
|
|
|
|
|
2017-04-21 10:43:26 +00:00
|
|
|
#include <linux/if.h>
|
|
|
|
#include <linux/wait.h>
|
2018-01-05 05:50:59 +00:00
|
|
|
#ifdef HAVE_SIGNAL_FUNCTIONS_OWN_HEADER
|
|
|
|
#include <linux/sched/signal.h>
|
|
|
|
#else
|
2017-04-21 10:43:26 +00:00
|
|
|
#include <linux/sched.h>
|
2018-01-05 05:50:59 +00:00
|
|
|
#endif
|
2017-04-21 10:43:26 +00:00
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
|
2020-06-18 16:55:50 +00:00
|
|
|
#include <rte_kni_common.h>
|
2017-04-21 10:43:26 +00:00
|
|
|
#define KNI_KTHREAD_RESCHEDULE_INTERVAL 5 /* us */
|
|
|
|
|
2018-05-15 09:49:22 +00:00
|
|
|
#define MBUF_BURST_SZ 32
|
|
|
|
|
2019-06-25 11:12:58 +00:00
|
|
|
/* Default carrier state for created KNI network interfaces */
|
2020-06-18 16:55:50 +00:00
|
|
|
extern uint32_t kni_dflt_carrier;
|
2019-06-25 11:12:58 +00:00
|
|
|
|
2017-04-21 10:43:26 +00:00
|
|
|
/**
|
|
|
|
* A structure describing the private information for a kni device.
|
|
|
|
*/
|
|
|
|
struct kni_dev {
|
|
|
|
/* kni list */
|
|
|
|
struct list_head list;
|
|
|
|
|
2020-06-18 16:55:50 +00:00
|
|
|
uint8_t iova_mode;
|
|
|
|
|
2018-05-15 09:49:22 +00:00
|
|
|
uint32_t core_id; /* Core ID to bind */
|
2017-04-21 10:43:26 +00:00
|
|
|
char name[RTE_KNI_NAMESIZE]; /* Network device name */
|
|
|
|
struct task_struct *pthread;
|
|
|
|
|
|
|
|
/* wait queue for req/resp */
|
|
|
|
wait_queue_head_t wq;
|
|
|
|
struct mutex sync_lock;
|
|
|
|
|
|
|
|
/* kni device */
|
|
|
|
struct net_device *net_dev;
|
|
|
|
|
|
|
|
/* queue for packets to be sent out */
|
2020-06-18 16:55:50 +00:00
|
|
|
struct rte_kni_fifo *tx_q;
|
2017-04-21 10:43:26 +00:00
|
|
|
|
|
|
|
/* queue for the packets received */
|
2020-06-18 16:55:50 +00:00
|
|
|
struct rte_kni_fifo *rx_q;
|
2017-04-21 10:43:26 +00:00
|
|
|
|
|
|
|
/* queue for the allocated mbufs those can be used to save sk buffs */
|
2020-06-18 16:55:50 +00:00
|
|
|
struct rte_kni_fifo *alloc_q;
|
2017-04-21 10:43:26 +00:00
|
|
|
|
|
|
|
/* free queue for the mbufs to be freed */
|
2020-06-18 16:55:50 +00:00
|
|
|
struct rte_kni_fifo *free_q;
|
2017-04-21 10:43:26 +00:00
|
|
|
|
|
|
|
/* request queue */
|
2020-06-18 16:55:50 +00:00
|
|
|
struct rte_kni_fifo *req_q;
|
2017-04-21 10:43:26 +00:00
|
|
|
|
|
|
|
/* response queue */
|
2020-06-18 16:55:50 +00:00
|
|
|
struct rte_kni_fifo *resp_q;
|
2017-04-21 10:43:26 +00:00
|
|
|
|
2018-05-15 09:49:22 +00:00
|
|
|
void *sync_kva;
|
2017-04-21 10:43:26 +00:00
|
|
|
void *sync_va;
|
|
|
|
|
|
|
|
void *mbuf_kva;
|
|
|
|
void *mbuf_va;
|
|
|
|
|
|
|
|
/* mbuf size */
|
2018-05-15 09:49:22 +00:00
|
|
|
uint32_t mbuf_size;
|
2017-04-21 10:43:26 +00:00
|
|
|
|
2018-05-15 09:49:22 +00:00
|
|
|
/* buffers */
|
|
|
|
void *pa[MBUF_BURST_SZ];
|
|
|
|
void *va[MBUF_BURST_SZ];
|
|
|
|
void *alloc_pa[MBUF_BURST_SZ];
|
|
|
|
void *alloc_va[MBUF_BURST_SZ];
|
2020-06-18 16:55:50 +00:00
|
|
|
|
|
|
|
struct task_struct *usr_tsk;
|
2017-04-21 10:43:26 +00:00
|
|
|
};
|
|
|
|
|
2020-06-18 16:55:50 +00:00
|
|
|
#ifdef HAVE_IOVA_TO_KVA_MAPPING_SUPPORT
|
|
|
|
static inline phys_addr_t iova_to_phys(struct task_struct *tsk,
|
|
|
|
unsigned long iova)
|
|
|
|
{
|
|
|
|
phys_addr_t offset, phys_addr;
|
|
|
|
struct page *page = NULL;
|
|
|
|
long ret;
|
|
|
|
|
|
|
|
offset = iova & (PAGE_SIZE - 1);
|
|
|
|
|
|
|
|
/* Read one page struct info */
|
2021-01-28 17:08:59 +00:00
|
|
|
#ifdef HAVE_TSK_IN_GUP
|
2020-06-18 16:55:50 +00:00
|
|
|
ret = get_user_pages_remote(tsk, tsk->mm, iova, 1,
|
|
|
|
FOLL_TOUCH, &page, NULL, NULL);
|
2021-01-28 17:08:59 +00:00
|
|
|
#else
|
|
|
|
ret = get_user_pages_remote(tsk->mm, iova, 1,
|
|
|
|
FOLL_TOUCH, &page, NULL, NULL);
|
|
|
|
#endif
|
2020-06-18 16:55:50 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
phys_addr = page_to_phys(page) | offset;
|
|
|
|
put_page(page);
|
|
|
|
|
|
|
|
return phys_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *iova_to_kva(struct task_struct *tsk, unsigned long iova)
|
|
|
|
{
|
|
|
|
return phys_to_virt(iova_to_phys(tsk, iova));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-06-25 11:12:58 +00:00
|
|
|
void kni_net_release_fifo_phy(struct kni_dev *kni);
|
2018-05-15 09:49:22 +00:00
|
|
|
void kni_net_rx(struct kni_dev *kni);
|
|
|
|
void kni_net_init(struct net_device *dev);
|
|
|
|
void kni_net_config_lo_mode(char *lo_str);
|
|
|
|
void kni_net_poll_resp(struct kni_dev *kni);
|
2017-04-21 10:43:26 +00:00
|
|
|
|
|
|
|
#endif
|