DPDK 22.11.4
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 __cplusplus
10extern "C" {
11#endif
12
13#ifdef __KERNEL__
14#include <linux/if.h>
15#include <asm/barrier.h>
16#define RTE_STD_C11
17#else
18#include <rte_common.h>
19#include <rte_config.h>
20#endif
21
22/*
23 * KNI name is part of memzone name. Must not exceed IFNAMSIZ.
24 */
25#define RTE_KNI_NAMESIZE 16
26
27#define RTE_CACHE_LINE_MIN_SIZE 64
28
29/*
30 * Request id.
31 */
32enum rte_kni_req_id {
33 RTE_KNI_REQ_UNKNOWN = 0,
34 RTE_KNI_REQ_CHANGE_MTU,
35 RTE_KNI_REQ_CFG_NETWORK_IF,
36 RTE_KNI_REQ_CHANGE_MAC_ADDR,
37 RTE_KNI_REQ_CHANGE_PROMISC,
38 RTE_KNI_REQ_CHANGE_ALLMULTI,
39 RTE_KNI_REQ_MAX,
40};
41
42/*
43 * Structure for KNI request.
44 */
45struct rte_kni_request {
46 uint32_t req_id;
48 union {
49 uint32_t new_mtu;
50 uint8_t if_up;
51 uint8_t mac_addr[6];
52 uint8_t promiscusity;
53 uint8_t allmulti;
54 };
55 int32_t async : 1;
56 int32_t result;
57} __attribute__((__packed__));
58
59/*
60 * Fifo struct mapped in a shared memory. It describes a circular buffer FIFO
61 * Write and read should wrap around. Fifo is empty when write == read
62 * Writing should never overwrite the read position
63 */
64struct rte_kni_fifo {
65#ifdef RTE_USE_C11_MEM_MODEL
66 unsigned write;
67 unsigned read;
68#else
69 volatile unsigned write;
70 volatile unsigned read;
71#endif
72 unsigned len;
73 unsigned elem_size;
74 void *volatile buffer[];
75};
76
77/*
78 * The kernel image of the rte_mbuf struct, with only the relevant fields.
79 * Padding is necessary to assure the offsets of these fields
80 */
81struct rte_kni_mbuf {
82 void *buf_addr __attribute__((__aligned__(RTE_CACHE_LINE_SIZE)));
83 uint64_t buf_iova;
84 uint16_t data_off;
85 char pad1[2];
86 uint16_t nb_segs;
87 char pad4[2];
88 uint64_t ol_flags;
89 char pad2[4];
90 uint32_t pkt_len;
91 uint16_t data_len;
92 char pad3[14];
93 void *pool;
94
95 /* fields on second cache line */
96 __attribute__((__aligned__(RTE_CACHE_LINE_MIN_SIZE)))
97 void *next;
98};
99
100/*
101 * Struct used to create a KNI device. Passed to the kernel in IOCTL call
102 */
103
104struct rte_kni_device_info {
105 char name[RTE_KNI_NAMESIZE];
107 phys_addr_t tx_phys;
108 phys_addr_t rx_phys;
109 phys_addr_t alloc_phys;
110 phys_addr_t free_phys;
111
112 /* Used by Ethtool */
113 phys_addr_t req_phys;
114 phys_addr_t resp_phys;
115 phys_addr_t sync_phys;
116 void * sync_va;
117
118 /* mbuf mempool */
119 void * mbuf_va;
120 phys_addr_t mbuf_phys;
121
122 uint16_t group_id;
123 uint32_t core_id;
125 __extension__
126 uint8_t force_bind : 1;
128 /* mbuf size */
129 unsigned mbuf_size;
130 unsigned int mtu;
131 unsigned int min_mtu;
132 unsigned int max_mtu;
133 uint8_t mac_addr[6];
134 uint8_t iova_mode;
135};
136
137#define KNI_DEVICE "kni"
138
139#define RTE_KNI_IOCTL_TEST _IOWR(0, 1, int)
140#define RTE_KNI_IOCTL_CREATE _IOWR(0, 2, struct rte_kni_device_info)
141#define RTE_KNI_IOCTL_RELEASE _IOWR(0, 3, struct rte_kni_device_info)
142
143#ifdef __cplusplus
144}
145#endif
146
147#endif /* _RTE_KNI_COMMON_H_ */
#define RTE_CACHE_LINE_MIN_SIZE
Definition: rte_common.h:437
uint64_t phys_addr_t
Definition: rte_common.h:448
#define RTE_STD_C11
Definition: rte_common.h:39