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