xref: /freebsd/sys/net/netmap_virt.h (revision c66ec88fed842fbaad62c30d510644ceb7bd2d71)
1 /*
2  * Copyright (C) 2013-2016 Luigi Rizzo
3  * Copyright (C) 2013-2016 Giuseppe Lettieri
4  * Copyright (C) 2013-2018 Vincenzo Maffione
5  * Copyright (C) 2015 Stefano Garzarella
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *   1. Redistributions of source code must retain the above copyright
12  *      notice, this list of conditions and the following disclaimer.
13  *   2. Redistributions in binary form must reproduce the above copyright
14  *      notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31 
32 #ifndef NETMAP_VIRT_H
33 #define NETMAP_VIRT_H
34 
35 /*
36  * Register offsets and other macros for the ptnetmap paravirtual devices:
37  *   ptnetmap-memdev: device used to expose memory into the guest
38  *   ptnet: paravirtualized NIC exposing a netmap port in the guest
39  *
40  * These macros are used in the hypervisor frontend (QEMU, bhyve) and in the
41  * guest device driver.
42  */
43 
44 /* PCI identifiers and PCI BARs for ptnetmap-memdev and ptnet. */
45 #define PTNETMAP_MEMDEV_NAME            "ptnetmap-memdev"
46 #define PTNETMAP_PCI_VENDOR_ID          0x1b36  /* QEMU virtual devices */
47 #define PTNETMAP_PCI_DEVICE_ID          0xcccc  /* memory device */
48 #define PTNETMAP_PCI_NETIF_ID           0xcccd  /* ptnet network interface */
49 #define PTNETMAP_IO_PCI_BAR             0
50 #define PTNETMAP_MEM_PCI_BAR            1
51 #define PTNETMAP_MSIX_PCI_BAR           2
52 
53 /* Device registers for ptnetmap-memdev */
54 #define PTNET_MDEV_IO_MEMSIZE_LO	0	/* netmap memory size (low) */
55 #define PTNET_MDEV_IO_MEMSIZE_HI	4	/* netmap_memory_size (high) */
56 #define PTNET_MDEV_IO_MEMID		8	/* memory allocator ID in the host */
57 #define PTNET_MDEV_IO_IF_POOL_OFS	64
58 #define PTNET_MDEV_IO_IF_POOL_OBJNUM	68
59 #define PTNET_MDEV_IO_IF_POOL_OBJSZ	72
60 #define PTNET_MDEV_IO_RING_POOL_OFS	76
61 #define PTNET_MDEV_IO_RING_POOL_OBJNUM	80
62 #define PTNET_MDEV_IO_RING_POOL_OBJSZ	84
63 #define PTNET_MDEV_IO_BUF_POOL_OFS	88
64 #define PTNET_MDEV_IO_BUF_POOL_OBJNUM	92
65 #define PTNET_MDEV_IO_BUF_POOL_OBJSZ	96
66 #define PTNET_MDEV_IO_END		100
67 
68 /* ptnetmap features */
69 #define PTNETMAP_F_VNET_HDR        1
70 
71 /* Device registers for the ptnet network device. */
72 #define PTNET_IO_PTFEAT		0
73 #define PTNET_IO_PTCTL		4
74 #define PTNET_IO_MAC_LO		8
75 #define PTNET_IO_MAC_HI		12
76 #define PTNET_IO_CSBBAH		16 /* deprecated */
77 #define PTNET_IO_CSBBAL		20 /* deprecated */
78 #define PTNET_IO_NIFP_OFS	24
79 #define PTNET_IO_NUM_TX_RINGS	28
80 #define PTNET_IO_NUM_RX_RINGS	32
81 #define PTNET_IO_NUM_TX_SLOTS	36
82 #define PTNET_IO_NUM_RX_SLOTS	40
83 #define PTNET_IO_VNET_HDR_LEN	44
84 #define PTNET_IO_HOSTMEMID	48
85 #define PTNET_IO_CSB_GH_BAH     52
86 #define PTNET_IO_CSB_GH_BAL     56
87 #define PTNET_IO_CSB_HG_BAH     60
88 #define PTNET_IO_CSB_HG_BAL     64
89 #define PTNET_IO_END		68
90 #define PTNET_IO_KICK_BASE	128
91 #define PTNET_IO_MASK		0xff
92 
93 /* ptnet control commands (values for PTCTL register):
94  *   - CREATE starts the host sync-kloop
95  *   - DELETE stops the host sync-kloop
96  */
97 #define PTNETMAP_PTCTL_CREATE		1
98 #define PTNETMAP_PTCTL_DELETE		2
99 
100 #endif /* NETMAP_VIRT_H */
101