xref: /freebsd/sys/net/netmap_virt.h (revision 844a6f0c)
1a82ab411SLuigi Rizzo /*
2a82ab411SLuigi Rizzo  * Copyright (C) 2013-2016 Luigi Rizzo
3a82ab411SLuigi Rizzo  * Copyright (C) 2013-2016 Giuseppe Lettieri
4a82ab411SLuigi Rizzo  * Copyright (C) 2013-2016 Vincenzo Maffione
5a82ab411SLuigi Rizzo  * Copyright (C) 2015 Stefano Garzarella
6a82ab411SLuigi Rizzo  * All rights reserved.
7a82ab411SLuigi Rizzo  *
8a82ab411SLuigi Rizzo  * Redistribution and use in source and binary forms, with or without
9a82ab411SLuigi Rizzo  * modification, are permitted provided that the following conditions
10a82ab411SLuigi Rizzo  * are met:
11a82ab411SLuigi Rizzo  *   1. Redistributions of source code must retain the above copyright
12a82ab411SLuigi Rizzo  *      notice, this list of conditions and the following disclaimer.
13a82ab411SLuigi Rizzo  *   2. Redistributions in binary form must reproduce the above copyright
14a82ab411SLuigi Rizzo  *      notice, this list of conditions and the following disclaimer in the
15a82ab411SLuigi Rizzo  *    documentation and/or other materials provided with the distribution.
16a82ab411SLuigi Rizzo  *
17a82ab411SLuigi Rizzo  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18a82ab411SLuigi Rizzo  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19a82ab411SLuigi Rizzo  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20a82ab411SLuigi Rizzo  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21a82ab411SLuigi Rizzo  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22a82ab411SLuigi Rizzo  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23a82ab411SLuigi Rizzo  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24a82ab411SLuigi Rizzo  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25a82ab411SLuigi Rizzo  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26a82ab411SLuigi Rizzo  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27a82ab411SLuigi Rizzo  * SUCH DAMAGE.
28a82ab411SLuigi Rizzo  *
29a82ab411SLuigi Rizzo  * $FreeBSD$
30a82ab411SLuigi Rizzo  */
31a82ab411SLuigi Rizzo 
32a82ab411SLuigi Rizzo #ifndef NETMAP_VIRT_H
33a82ab411SLuigi Rizzo #define NETMAP_VIRT_H
34a82ab411SLuigi Rizzo 
35a82ab411SLuigi Rizzo /*
36a82ab411SLuigi Rizzo  * ptnetmap_memdev: device used to expose memory into the guest VM
37a82ab411SLuigi Rizzo  *
38a82ab411SLuigi Rizzo  * These macros are used in the hypervisor frontend (QEMU, bhyve) and in the
39a82ab411SLuigi Rizzo  * guest device driver.
40a82ab411SLuigi Rizzo  */
41a82ab411SLuigi Rizzo 
42a82ab411SLuigi Rizzo /* PCI identifiers and PCI BARs for the ptnetmap memdev
43a82ab411SLuigi Rizzo  * and ptnetmap network interface. */
44a82ab411SLuigi Rizzo #define PTNETMAP_MEMDEV_NAME            "ptnetmap-memdev"
45844a6f0cSLuigi Rizzo #define PTNETMAP_PCI_VENDOR_ID          0x1b36  /* QEMU virtual devices */
46844a6f0cSLuigi Rizzo #define PTNETMAP_PCI_DEVICE_ID          0x000c  /* memory device */
47844a6f0cSLuigi Rizzo #define PTNETMAP_PCI_NETIF_ID           0x000d  /* ptnet network interface */
48a82ab411SLuigi Rizzo #define PTNETMAP_IO_PCI_BAR             0
49a82ab411SLuigi Rizzo #define PTNETMAP_MEM_PCI_BAR            1
50a82ab411SLuigi Rizzo #define PTNETMAP_MSIX_PCI_BAR           2
51a82ab411SLuigi Rizzo 
52a82ab411SLuigi Rizzo /* Registers for the ptnetmap memdev */
53844a6f0cSLuigi Rizzo #define PTNET_MDEV_IO_MEMSIZE_LO	0	/* netmap memory size (low) */
54844a6f0cSLuigi Rizzo #define PTNET_MDEV_IO_MEMSIZE_HI	4	/* netmap_memory_size (high) */
55844a6f0cSLuigi Rizzo #define PTNET_MDEV_IO_MEMID		8	/* memory allocator ID in the host */
56844a6f0cSLuigi Rizzo #define PTNET_MDEV_IO_IF_POOL_OFS	64
57844a6f0cSLuigi Rizzo #define PTNET_MDEV_IO_IF_POOL_OBJNUM	68
58844a6f0cSLuigi Rizzo #define PTNET_MDEV_IO_IF_POOL_OBJSZ	72
59844a6f0cSLuigi Rizzo #define PTNET_MDEV_IO_RING_POOL_OFS	76
60844a6f0cSLuigi Rizzo #define PTNET_MDEV_IO_RING_POOL_OBJNUM	80
61844a6f0cSLuigi Rizzo #define PTNET_MDEV_IO_RING_POOL_OBJSZ	84
62844a6f0cSLuigi Rizzo #define PTNET_MDEV_IO_BUF_POOL_OFS	88
63844a6f0cSLuigi Rizzo #define PTNET_MDEV_IO_BUF_POOL_OBJNUM	92
64844a6f0cSLuigi Rizzo #define PTNET_MDEV_IO_BUF_POOL_OBJSZ	96
65844a6f0cSLuigi Rizzo #define PTNET_MDEV_IO_END		100
66a82ab411SLuigi Rizzo 
67a82ab411SLuigi Rizzo /*
68a82ab411SLuigi Rizzo  * ptnetmap configuration
69a82ab411SLuigi Rizzo  *
70844a6f0cSLuigi Rizzo  * The ptnet kthreads (running in host kernel-space) need to be configured
71844a6f0cSLuigi Rizzo  * in order to know how to intercept guest kicks (I/O register writes) and
72844a6f0cSLuigi Rizzo  * how to inject MSI-X interrupts to the guest. The configuration may vary
73844a6f0cSLuigi Rizzo  * depending on the hypervisor. Currently, we support QEMU/KVM on Linux and
74844a6f0cSLuigi Rizzo  * and bhyve on FreeBSD.
75844a6f0cSLuigi Rizzo  * The configuration is passed by the hypervisor to the host netmap module
76844a6f0cSLuigi Rizzo  * by means of an ioctl() with nr_cmd=NETMAP_PT_HOST_CREATE, and it is
77844a6f0cSLuigi Rizzo  * specified by the ptnetmap_cfg struct. This struct contains an header
78844a6f0cSLuigi Rizzo  * with general informations and an array of entries whose size depends
79844a6f0cSLuigi Rizzo  * on the hypervisor. The NETMAP_PT_HOST_CREATE command is issued every
80844a6f0cSLuigi Rizzo  * time the kthreads are started.
81a82ab411SLuigi Rizzo  */
82a82ab411SLuigi Rizzo struct ptnetmap_cfg {
83844a6f0cSLuigi Rizzo #define PTNETMAP_CFGTYPE_QEMU		0x1
84844a6f0cSLuigi Rizzo #define PTNETMAP_CFGTYPE_BHYVE		0x2
85844a6f0cSLuigi Rizzo 	uint16_t cfgtype;	/* how to interpret the cfg entries */
86844a6f0cSLuigi Rizzo 	uint16_t entry_size;	/* size of a config entry */
87844a6f0cSLuigi Rizzo 	uint32_t num_rings;	/* number of config entries */
88a82ab411SLuigi Rizzo 	void *ptrings;		/* ptrings inside CSB */
89844a6f0cSLuigi Rizzo 	/* Configuration entries are allocated right after the struct. */
90844a6f0cSLuigi Rizzo };
91844a6f0cSLuigi Rizzo 
92844a6f0cSLuigi Rizzo /* Configuration of a ptnetmap ring for QEMU. */
93844a6f0cSLuigi Rizzo struct ptnetmap_cfgentry_qemu {
94844a6f0cSLuigi Rizzo 	uint32_t ioeventfd;	/* to intercept guest register access */
95844a6f0cSLuigi Rizzo 	uint32_t irqfd;		/* to inject guest interrupts */
96844a6f0cSLuigi Rizzo };
97844a6f0cSLuigi Rizzo 
98844a6f0cSLuigi Rizzo /* Configuration of a ptnetmap ring for bhyve. */
99844a6f0cSLuigi Rizzo struct ptnetmap_cfgentry_bhyve {
100844a6f0cSLuigi Rizzo 	uint64_t wchan;		/* tsleep() parameter, to wake up kthread */
101844a6f0cSLuigi Rizzo 	uint32_t ioctl_fd;	/* ioctl fd */
102844a6f0cSLuigi Rizzo 	/* ioctl parameters to send irq */
103844a6f0cSLuigi Rizzo 	uint32_t ioctl_cmd;
104844a6f0cSLuigi Rizzo 	/* vmm.ko MSIX parameters for IOCTL */
105844a6f0cSLuigi Rizzo 	struct {
106844a6f0cSLuigi Rizzo 		uint64_t        msg_data;
107844a6f0cSLuigi Rizzo 		uint64_t        addr;
108844a6f0cSLuigi Rizzo 	} ioctl_data;
109a82ab411SLuigi Rizzo };
110a82ab411SLuigi Rizzo 
111a82ab411SLuigi Rizzo /*
112844a6f0cSLuigi Rizzo  * Structure filled-in by the kernel when asked for allocator info
113844a6f0cSLuigi Rizzo  * through NETMAP_POOLS_INFO_GET. Used by hypervisors supporting
114844a6f0cSLuigi Rizzo  * ptnetmap.
115844a6f0cSLuigi Rizzo  */
116844a6f0cSLuigi Rizzo struct netmap_pools_info {
117844a6f0cSLuigi Rizzo 	uint64_t memsize;	/* same as nmr->nr_memsize */
118844a6f0cSLuigi Rizzo 	uint32_t memid;		/* same as nmr->nr_arg2 */
119844a6f0cSLuigi Rizzo 	uint32_t if_pool_offset;
120844a6f0cSLuigi Rizzo 	uint32_t if_pool_objtotal;
121844a6f0cSLuigi Rizzo 	uint32_t if_pool_objsize;
122844a6f0cSLuigi Rizzo 	uint32_t ring_pool_offset;
123844a6f0cSLuigi Rizzo 	uint32_t ring_pool_objtotal;
124844a6f0cSLuigi Rizzo 	uint32_t ring_pool_objsize;
125844a6f0cSLuigi Rizzo 	uint32_t buf_pool_offset;
126844a6f0cSLuigi Rizzo 	uint32_t buf_pool_objtotal;
127844a6f0cSLuigi Rizzo 	uint32_t buf_pool_objsize;
128844a6f0cSLuigi Rizzo };
129844a6f0cSLuigi Rizzo 
130844a6f0cSLuigi Rizzo /*
131844a6f0cSLuigi Rizzo  * Pass a pointer to a userspace buffer to be passed to kernelspace for write
132844a6f0cSLuigi Rizzo  * or read. Used by NETMAP_PT_HOST_CREATE and NETMAP_POOLS_INFO_GET.
133a82ab411SLuigi Rizzo  */
134a82ab411SLuigi Rizzo static inline void
135844a6f0cSLuigi Rizzo nmreq_pointer_put(struct nmreq *nmr, void *userptr)
136a82ab411SLuigi Rizzo {
137844a6f0cSLuigi Rizzo 	uintptr_t *pp = (uintptr_t *)&nmr->nr_arg1;
138844a6f0cSLuigi Rizzo 	*pp = (uintptr_t)userptr;
139a82ab411SLuigi Rizzo }
140a82ab411SLuigi Rizzo 
141844a6f0cSLuigi Rizzo /* ptnetmap features */
142844a6f0cSLuigi Rizzo #define PTNETMAP_F_VNET_HDR        1
143a82ab411SLuigi Rizzo 
144a82ab411SLuigi Rizzo /* I/O registers for the ptnet device. */
145a82ab411SLuigi Rizzo #define PTNET_IO_PTFEAT		0
146a82ab411SLuigi Rizzo #define PTNET_IO_PTCTL		4
147844a6f0cSLuigi Rizzo #define PTNET_IO_MAC_LO		8
148844a6f0cSLuigi Rizzo #define PTNET_IO_MAC_HI		12
149844a6f0cSLuigi Rizzo #define PTNET_IO_CSBBAH		16
150844a6f0cSLuigi Rizzo #define PTNET_IO_CSBBAL		20
151844a6f0cSLuigi Rizzo #define PTNET_IO_NIFP_OFS	24
152844a6f0cSLuigi Rizzo #define PTNET_IO_NUM_TX_RINGS	28
153844a6f0cSLuigi Rizzo #define PTNET_IO_NUM_RX_RINGS	32
154844a6f0cSLuigi Rizzo #define PTNET_IO_NUM_TX_SLOTS	36
155844a6f0cSLuigi Rizzo #define PTNET_IO_NUM_RX_SLOTS	40
156844a6f0cSLuigi Rizzo #define PTNET_IO_VNET_HDR_LEN	44
157844a6f0cSLuigi Rizzo #define PTNET_IO_HOSTMEMID	48
158a2a74091SLuigi Rizzo #define PTNET_IO_END		52
159a82ab411SLuigi Rizzo #define PTNET_IO_KICK_BASE	128
160a82ab411SLuigi Rizzo #define PTNET_IO_MASK		0xff
161a82ab411SLuigi Rizzo 
162844a6f0cSLuigi Rizzo /* ptnetmap control commands (values for PTCTL register) */
163844a6f0cSLuigi Rizzo #define PTNETMAP_PTCTL_CREATE		1
164844a6f0cSLuigi Rizzo #define PTNETMAP_PTCTL_DELETE		2
165844a6f0cSLuigi Rizzo 
166a82ab411SLuigi Rizzo /* If defined, CSB is allocated by the guest, not by the host. */
167a82ab411SLuigi Rizzo #define PTNET_CSB_ALLOC
168a82ab411SLuigi Rizzo 
169a82ab411SLuigi Rizzo /* ptnetmap ring fields shared between guest and host */
170a82ab411SLuigi Rizzo struct ptnet_ring {
171a82ab411SLuigi Rizzo 	/* XXX revise the layout to minimize cache bounces. */
172a82ab411SLuigi Rizzo 	uint32_t head;		  /* GW+ HR+ the head of the guest netmap_ring */
173a82ab411SLuigi Rizzo 	uint32_t cur;		  /* GW+ HR+ the cur of the guest netmap_ring */
174a82ab411SLuigi Rizzo 	uint32_t guest_need_kick; /* GW+ HR+ host-->guest notification enable */
175a2a74091SLuigi Rizzo 	uint32_t sync_flags;	  /* GW+ HR+ the flags of the guest [tx|rx]sync() */
176a82ab411SLuigi Rizzo 	uint32_t hwcur;		  /* GR+ HW+ the hwcur of the host netmap_kring */
177a82ab411SLuigi Rizzo 	uint32_t hwtail;	  /* GR+ HW+ the hwtail of the host netmap_kring */
178a82ab411SLuigi Rizzo 	uint32_t host_need_kick;  /* GR+ HW+ guest-->host notification enable */
179a2a74091SLuigi Rizzo 	char pad[4];
180a82ab411SLuigi Rizzo };
181a82ab411SLuigi Rizzo 
182a82ab411SLuigi Rizzo /* CSB for the ptnet device. */
183a82ab411SLuigi Rizzo struct ptnet_csb {
184844a6f0cSLuigi Rizzo #define NETMAP_VIRT_CSB_SIZE   4096
185a82ab411SLuigi Rizzo 	struct ptnet_ring rings[NETMAP_VIRT_CSB_SIZE/sizeof(struct ptnet_ring)];
186a82ab411SLuigi Rizzo };
187a82ab411SLuigi Rizzo 
188a2a74091SLuigi Rizzo #ifdef WITH_PTNETMAP_GUEST
189a2a74091SLuigi Rizzo 
190a2a74091SLuigi Rizzo /* ptnetmap_memdev routines used to talk with ptnetmap_memdev device driver */
191a2a74091SLuigi Rizzo struct ptnetmap_memdev;
192844a6f0cSLuigi Rizzo int nm_os_pt_memdev_iomap(struct ptnetmap_memdev *, vm_paddr_t *, void **,
193844a6f0cSLuigi Rizzo                           uint64_t *);
194a2a74091SLuigi Rizzo void nm_os_pt_memdev_iounmap(struct ptnetmap_memdev *);
195844a6f0cSLuigi Rizzo uint32_t nm_os_pt_memdev_ioread(struct ptnetmap_memdev *, unsigned int);
196a2a74091SLuigi Rizzo 
197a2a74091SLuigi Rizzo /* Guest driver: Write kring pointers (cur, head) to the CSB.
198a2a74091SLuigi Rizzo  * This routine is coupled with ptnetmap_host_read_kring_csb(). */
199a2a74091SLuigi Rizzo static inline void
200a2a74091SLuigi Rizzo ptnetmap_guest_write_kring_csb(struct ptnet_ring *ptr, uint32_t cur,
201a2a74091SLuigi Rizzo 			       uint32_t head)
202a2a74091SLuigi Rizzo {
203a2a74091SLuigi Rizzo     /*
204a2a74091SLuigi Rizzo      * We need to write cur and head to the CSB but we cannot do it atomically.
205a2a74091SLuigi Rizzo      * There is no way we can prevent the host from reading the updated value
206a2a74091SLuigi Rizzo      * of one of the two and the old value of the other. However, if we make
207a2a74091SLuigi Rizzo      * sure that the host never reads a value of head more recent than the
208a2a74091SLuigi Rizzo      * value of cur we are safe. We can allow the host to read a value of cur
209a2a74091SLuigi Rizzo      * more recent than the value of head, since in the netmap ring cur can be
210a2a74091SLuigi Rizzo      * ahead of head and cur cannot wrap around head because it must be behind
211a2a74091SLuigi Rizzo      * tail. Inverting the order of writes below could instead result into the
212a2a74091SLuigi Rizzo      * host to think head went ahead of cur, which would cause the sync
213a2a74091SLuigi Rizzo      * prologue to fail.
214a2a74091SLuigi Rizzo      *
215a2a74091SLuigi Rizzo      * The following memory barrier scheme is used to make this happen:
216a2a74091SLuigi Rizzo      *
217a2a74091SLuigi Rizzo      *          Guest              Host
218a2a74091SLuigi Rizzo      *
219a2a74091SLuigi Rizzo      *          STORE(cur)         LOAD(head)
220a2a74091SLuigi Rizzo      *          mb() <-----------> mb()
221a2a74091SLuigi Rizzo      *          STORE(head)        LOAD(cur)
222a2a74091SLuigi Rizzo      */
223a2a74091SLuigi Rizzo     ptr->cur = cur;
224a2a74091SLuigi Rizzo     mb();
225a2a74091SLuigi Rizzo     ptr->head = head;
226a2a74091SLuigi Rizzo }
227a2a74091SLuigi Rizzo 
228a2a74091SLuigi Rizzo /* Guest driver: Read kring pointers (hwcur, hwtail) from the CSB.
229a2a74091SLuigi Rizzo  * This routine is coupled with ptnetmap_host_write_kring_csb(). */
230a2a74091SLuigi Rizzo static inline void
231a2a74091SLuigi Rizzo ptnetmap_guest_read_kring_csb(struct ptnet_ring *ptr, struct netmap_kring *kring)
232a2a74091SLuigi Rizzo {
233a2a74091SLuigi Rizzo     /*
234a2a74091SLuigi Rizzo      * We place a memory barrier to make sure that the update of hwtail never
235a2a74091SLuigi Rizzo      * overtakes the update of hwcur.
236a2a74091SLuigi Rizzo      * (see explanation in ptnetmap_host_write_kring_csb).
237a2a74091SLuigi Rizzo      */
238a2a74091SLuigi Rizzo     kring->nr_hwtail = ptr->hwtail;
239a2a74091SLuigi Rizzo     mb();
240a2a74091SLuigi Rizzo     kring->nr_hwcur = ptr->hwcur;
241a2a74091SLuigi Rizzo }
242a2a74091SLuigi Rizzo 
243a2a74091SLuigi Rizzo #endif /* WITH_PTNETMAP_GUEST */
244a2a74091SLuigi Rizzo 
245a82ab411SLuigi Rizzo #ifdef WITH_PTNETMAP_HOST
246a82ab411SLuigi Rizzo /*
247a82ab411SLuigi Rizzo  * ptnetmap kernel thread routines
248a82ab411SLuigi Rizzo  * */
249a82ab411SLuigi Rizzo 
250a82ab411SLuigi Rizzo /* Functions to read and write CSB fields in the host */
251a82ab411SLuigi Rizzo #if defined (linux)
252a82ab411SLuigi Rizzo #define CSB_READ(csb, field, r) (get_user(r, &csb->field))
253a82ab411SLuigi Rizzo #define CSB_WRITE(csb, field, v) (put_user(v, &csb->field))
254a82ab411SLuigi Rizzo #else  /* ! linux */
255a82ab411SLuigi Rizzo #define CSB_READ(csb, field, r) (r = fuword32(&csb->field))
256a82ab411SLuigi Rizzo #define CSB_WRITE(csb, field, v) (suword32(&csb->field, v))
257a82ab411SLuigi Rizzo #endif /* ! linux */
258a82ab411SLuigi Rizzo 
259a2a74091SLuigi Rizzo /* Host netmap: Write kring pointers (hwcur, hwtail) to the CSB.
260a2a74091SLuigi Rizzo  * This routine is coupled with ptnetmap_guest_read_kring_csb(). */
261a82ab411SLuigi Rizzo static inline void
262a82ab411SLuigi Rizzo ptnetmap_host_write_kring_csb(struct ptnet_ring __user *ptr, uint32_t hwcur,
263a82ab411SLuigi Rizzo         uint32_t hwtail)
264a82ab411SLuigi Rizzo {
265a2a74091SLuigi Rizzo     /*
266a2a74091SLuigi Rizzo      * The same scheme used in ptnetmap_guest_write_kring_csb() applies here.
267a2a74091SLuigi Rizzo      * We allow the guest to read a value of hwcur more recent than the value
268a2a74091SLuigi Rizzo      * of hwtail, since this would anyway result in a consistent view of the
269a2a74091SLuigi Rizzo      * ring state (and hwcur can never wraparound hwtail, since hwcur must be
270a2a74091SLuigi Rizzo      * behind head).
271a2a74091SLuigi Rizzo      *
272a2a74091SLuigi Rizzo      * The following memory barrier scheme is used to make this happen:
273a2a74091SLuigi Rizzo      *
274a2a74091SLuigi Rizzo      *          Guest                Host
275a2a74091SLuigi Rizzo      *
276a2a74091SLuigi Rizzo      *          STORE(hwcur)         LOAD(hwtail)
277a2a74091SLuigi Rizzo      *          mb() <-------------> mb()
278a2a74091SLuigi Rizzo      *          STORE(hwtail)        LOAD(hwcur)
279a2a74091SLuigi Rizzo      */
280a82ab411SLuigi Rizzo     CSB_WRITE(ptr, hwcur, hwcur);
281a2a74091SLuigi Rizzo     mb();
282a2a74091SLuigi Rizzo     CSB_WRITE(ptr, hwtail, hwtail);
283a2a74091SLuigi Rizzo }
284a82ab411SLuigi Rizzo 
285a2a74091SLuigi Rizzo /* Host netmap: Read kring pointers (head, cur, sync_flags) from the CSB.
286a2a74091SLuigi Rizzo  * This routine is coupled with ptnetmap_guest_write_kring_csb(). */
287a2a74091SLuigi Rizzo static inline void
288a2a74091SLuigi Rizzo ptnetmap_host_read_kring_csb(struct ptnet_ring __user *ptr,
289a2a74091SLuigi Rizzo 			     struct netmap_ring *shadow_ring,
290a2a74091SLuigi Rizzo 			     uint32_t num_slots)
291a2a74091SLuigi Rizzo {
292a2a74091SLuigi Rizzo     /*
293a2a74091SLuigi Rizzo      * We place a memory barrier to make sure that the update of head never
294a2a74091SLuigi Rizzo      * overtakes the update of cur.
295a2a74091SLuigi Rizzo      * (see explanation in ptnetmap_guest_write_kring_csb).
296a2a74091SLuigi Rizzo      */
297a2a74091SLuigi Rizzo     CSB_READ(ptr, head, shadow_ring->head);
298a2a74091SLuigi Rizzo     mb();
299a2a74091SLuigi Rizzo     CSB_READ(ptr, cur, shadow_ring->cur);
300a2a74091SLuigi Rizzo     CSB_READ(ptr, sync_flags, shadow_ring->flags);
301a82ab411SLuigi Rizzo }
302a82ab411SLuigi Rizzo 
303a82ab411SLuigi Rizzo #endif /* WITH_PTNETMAP_HOST */
304a82ab411SLuigi Rizzo 
305a82ab411SLuigi Rizzo #endif /* NETMAP_VIRT_H */
306