xref: /freebsd/sys/net/netmap_virt.h (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
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 
30 #ifndef NETMAP_VIRT_H
31 #define NETMAP_VIRT_H
32 
33 /*
34  * Register offsets and other macros for the ptnetmap paravirtual devices:
35  *   ptnetmap-memdev: device used to expose memory into the guest
36  *   ptnet: paravirtualized NIC exposing a netmap port in the guest
37  *
38  * These macros are used in the hypervisor frontend (QEMU, bhyve) and in the
39  * guest device driver.
40  */
41 
42 /* PCI identifiers and PCI BARs for ptnetmap-memdev and ptnet. */
43 #define PTNETMAP_MEMDEV_NAME            "ptnetmap-memdev"
44 #define PTNETMAP_PCI_VENDOR_ID          0x1b36  /* QEMU virtual devices */
45 #define PTNETMAP_PCI_DEVICE_ID          0x000c  /* memory device */
46 #define PTNETMAP_PCI_NETIF_ID           0x000d  /* ptnet network interface */
47 #define PTNETMAP_IO_PCI_BAR             0
48 #define PTNETMAP_MEM_PCI_BAR            1
49 #define PTNETMAP_MSIX_PCI_BAR           2
50 
51 /* Device registers for ptnetmap-memdev */
52 #define PTNET_MDEV_IO_MEMSIZE_LO	0	/* netmap memory size (low) */
53 #define PTNET_MDEV_IO_MEMSIZE_HI	4	/* netmap_memory_size (high) */
54 #define PTNET_MDEV_IO_MEMID		8	/* memory allocator ID in the host */
55 #define PTNET_MDEV_IO_IF_POOL_OFS	64
56 #define PTNET_MDEV_IO_IF_POOL_OBJNUM	68
57 #define PTNET_MDEV_IO_IF_POOL_OBJSZ	72
58 #define PTNET_MDEV_IO_RING_POOL_OFS	76
59 #define PTNET_MDEV_IO_RING_POOL_OBJNUM	80
60 #define PTNET_MDEV_IO_RING_POOL_OBJSZ	84
61 #define PTNET_MDEV_IO_BUF_POOL_OFS	88
62 #define PTNET_MDEV_IO_BUF_POOL_OBJNUM	92
63 #define PTNET_MDEV_IO_BUF_POOL_OBJSZ	96
64 #define PTNET_MDEV_IO_END		100
65 
66 /* ptnetmap features */
67 #define PTNETMAP_F_VNET_HDR        1
68 
69 /* Device registers for the ptnet network device. */
70 #define PTNET_IO_PTFEAT		0
71 #define PTNET_IO_PTCTL		4
72 #define PTNET_IO_MAC_LO		8
73 #define PTNET_IO_MAC_HI		12
74 #define PTNET_IO_CSBBAH		16 /* deprecated */
75 #define PTNET_IO_CSBBAL		20 /* deprecated */
76 #define PTNET_IO_NIFP_OFS	24
77 #define PTNET_IO_NUM_TX_RINGS	28
78 #define PTNET_IO_NUM_RX_RINGS	32
79 #define PTNET_IO_NUM_TX_SLOTS	36
80 #define PTNET_IO_NUM_RX_SLOTS	40
81 #define PTNET_IO_VNET_HDR_LEN	44
82 #define PTNET_IO_HOSTMEMID	48
83 #define PTNET_IO_CSB_GH_BAH     52
84 #define PTNET_IO_CSB_GH_BAL     56
85 #define PTNET_IO_CSB_HG_BAH     60
86 #define PTNET_IO_CSB_HG_BAL     64
87 #define PTNET_IO_END		68
88 #define PTNET_IO_KICK_BASE	128
89 #define PTNET_IO_MASK		0xff
90 
91 /* ptnet control commands (values for PTCTL register):
92  *   - CREATE starts the host sync-kloop
93  *   - DELETE stops the host sync-kloop
94  */
95 #define PTNETMAP_PTCTL_CREATE		1
96 #define PTNETMAP_PTCTL_DELETE		2
97 
98 #endif /* NETMAP_VIRT_H */
99