61ace6f26d5d85e241af66ef83cd2a9697a08ac5
[dpdk.git] / lib / librte_eal / linuxapp / eal / include / exec-env / rte_kni_common.h
1 /* SPDX-License-Identifier: (BSD-3-Clause OR LGPL-2.1) */
2 /*
3  * Copyright(c) 2007-2014 Intel Corporation.
4  */
5
6 #ifndef _RTE_KNI_COMMON_H_
7 #define _RTE_KNI_COMMON_H_
8
9 #ifdef __KERNEL__
10 #include <linux/if.h>
11 #define RTE_STD_C11
12 #else
13 #include <rte_common.h>
14 #include <rte_config.h>
15 #endif
16
17 /**
18  * KNI name is part of memzone name.
19  */
20 #define RTE_KNI_NAMESIZE 32
21
22 #define RTE_CACHE_LINE_MIN_SIZE 64
23
24 /*
25  * Request id.
26  */
27 enum rte_kni_req_id {
28         RTE_KNI_REQ_UNKNOWN = 0,
29         RTE_KNI_REQ_CHANGE_MTU,
30         RTE_KNI_REQ_CFG_NETWORK_IF,
31         RTE_KNI_REQ_MAX,
32 };
33
34 /*
35  * Structure for KNI request.
36  */
37 struct rte_kni_request {
38         uint32_t req_id;             /**< Request id */
39         RTE_STD_C11
40         union {
41                 uint32_t new_mtu;    /**< New MTU */
42                 uint8_t if_up;       /**< 1: interface up, 0: interface down */
43         };
44         int32_t result;               /**< Result for processing request */
45 } __attribute__((__packed__));
46
47 /*
48  * Fifo struct mapped in a shared memory. It describes a circular buffer FIFO
49  * Write and read should wrap around. Fifo is empty when write == read
50  * Writing should never overwrite the read position
51  */
52 struct rte_kni_fifo {
53         volatile unsigned write;     /**< Next position to be written*/
54         volatile unsigned read;      /**< Next position to be read */
55         unsigned len;                /**< Circular buffer length */
56         unsigned elem_size;          /**< Pointer size - for 32/64 bit OS */
57         void *volatile buffer[];     /**< The buffer contains mbuf pointers */
58 };
59
60 /*
61  * The kernel image of the rte_mbuf struct, with only the relevant fields.
62  * Padding is necessary to assure the offsets of these fields
63  */
64 struct rte_kni_mbuf {
65         void *buf_addr __attribute__((__aligned__(RTE_CACHE_LINE_SIZE)));
66         uint64_t buf_physaddr;
67         uint16_t data_off;      /**< Start address of data in segment buffer. */
68         char pad1[2];
69         uint16_t nb_segs;       /**< Number of segments. */
70         char pad4[2];
71         uint64_t ol_flags;      /**< Offload features. */
72         char pad2[4];
73         uint32_t pkt_len;       /**< Total pkt len: sum of all segment data_len. */
74         uint16_t data_len;      /**< Amount of data in segment buffer. */
75
76         /* fields on second cache line */
77         char pad3[8] __attribute__((__aligned__(RTE_CACHE_LINE_MIN_SIZE)));
78         void *pool;
79         void *next;
80 };
81
82 /*
83  * Struct used to create a KNI device. Passed to the kernel in IOCTL call
84  */
85
86 struct rte_kni_device_info {
87         char name[RTE_KNI_NAMESIZE];  /**< Network device name for KNI */
88
89         phys_addr_t tx_phys;
90         phys_addr_t rx_phys;
91         phys_addr_t alloc_phys;
92         phys_addr_t free_phys;
93
94         /* Used by Ethtool */
95         phys_addr_t req_phys;
96         phys_addr_t resp_phys;
97         phys_addr_t sync_phys;
98         void * sync_va;
99
100         /* mbuf mempool */
101         void * mbuf_va;
102         phys_addr_t mbuf_phys;
103
104         /* PCI info */
105         uint16_t vendor_id;           /**< Vendor ID or PCI_ANY_ID. */
106         uint16_t device_id;           /**< Device ID or PCI_ANY_ID. */
107         uint8_t bus;                  /**< Device bus */
108         uint8_t devid;                /**< Device ID */
109         uint8_t function;             /**< Device function. */
110
111         uint16_t group_id;            /**< Group ID */
112         uint32_t core_id;             /**< core ID to bind for kernel thread */
113
114         __extension__
115         uint8_t force_bind : 1;       /**< Flag for kernel thread binding */
116
117         /* mbuf size */
118         unsigned mbuf_size;
119 };
120
121 #define KNI_DEVICE "kni"
122
123 #define RTE_KNI_IOCTL_TEST    _IOWR(0, 1, int)
124 #define RTE_KNI_IOCTL_CREATE  _IOWR(0, 2, struct rte_kni_device_info)
125 #define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info)
126
127 #endif /* _RTE_KNI_COMMON_H_ */