]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/VirtioNetDxe/VirtioNet.h
OvmfPkg/VirtioNetDxe: map VRINGs using VirtioRingMap()
[mirror_edk2.git] / OvmfPkg / VirtioNetDxe / VirtioNet.h
1 /** @file
2
3 Internal definitions for the virtio-net driver, which produces Simple Network
4 Protocol instances for virtio-net devices.
5
6 Copyright (C) 2013, Red Hat, Inc.
7
8 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
14 WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 **/
16
17 #ifndef _VIRTIO_NET_DXE_H_
18 #define _VIRTIO_NET_DXE_H_
19
20 #include <IndustryStandard/VirtioNet.h>
21 #include <Library/DebugLib.h>
22 #include <Library/VirtioLib.h>
23 #include <Protocol/ComponentName.h>
24 #include <Protocol/ComponentName2.h>
25 #include <Protocol/DevicePath.h>
26 #include <Protocol/DriverBinding.h>
27 #include <Protocol/SimpleNetwork.h>
28
29 #define VNET_SIG SIGNATURE_32 ('V', 'N', 'E', 'T')
30
31 //
32 // maximum number of pending packets, separately for each direction
33 //
34 #define VNET_MAX_PENDING 64
35
36 //
37 // State diagram:
38 //
39 // | ^
40 // | |
41 // BindingStart BindingStop
42 // +SnpPopulate |
43 // ++GetFeatures |
44 // | |
45 // v |
46 // +---------+ virtio-net device is reset, no resources are
47 // | stopped | allocated for traffic, but MAC address has
48 // +---------+ been retrieved
49 // | ^
50 // | |
51 // SNP.Start SNP.Stop
52 // | |
53 // v |
54 // +---------+
55 // | started | functionally identical to stopped
56 // +---------+
57 // | ^
58 // | |
59 // SNP.Initialize SNP.Shutdown
60 // | |
61 // v |
62 // +-------------+ Virtio-net setup complete, including DRIVER_OK
63 // | initialized | bit. The receive queue is populated with
64 // +-------------+ requests; McastIpToMac, GetStatus, Transmit,
65 // Receive are callable.
66 //
67
68 typedef struct {
69 //
70 // Parts of this structure are initialized / torn down in various functions
71 // at various call depths. The table to the right should make it easier to
72 // track them.
73 //
74 // field init function
75 // ------------------ ------------------------------
76 UINT32 Signature; // VirtioNetDriverBindingStart
77 VIRTIO_DEVICE_PROTOCOL *VirtIo; // VirtioNetDriverBindingStart
78 EFI_SIMPLE_NETWORK_PROTOCOL Snp; // VirtioNetSnpPopulate
79 EFI_SIMPLE_NETWORK_MODE Snm; // VirtioNetSnpPopulate
80 EFI_EVENT ExitBoot; // VirtioNetSnpPopulate
81 EFI_DEVICE_PATH_PROTOCOL *MacDevicePath; // VirtioNetDriverBindingStart
82 EFI_HANDLE MacHandle; // VirtioNetDriverBindingStart
83
84 VRING RxRing; // VirtioNetInitRing
85 VOID *RxRingMap; // VirtioRingMap and
86 // VirtioNetInitRing
87 UINT8 *RxBuf; // VirtioNetInitRx
88 UINT16 RxLastUsed; // VirtioNetInitRx
89
90 VRING TxRing; // VirtioNetInitRing
91 VOID *TxRingMap; // VirtioRingMap and
92 // VirtioNetInitRing
93 UINT16 TxMaxPending; // VirtioNetInitTx
94 UINT16 TxCurPending; // VirtioNetInitTx
95 UINT16 *TxFreeStack; // VirtioNetInitTx
96 VIRTIO_1_0_NET_REQ TxSharedReq; // VirtioNetInitTx
97 UINT16 TxLastUsed; // VirtioNetInitTx
98 } VNET_DEV;
99
100
101 //
102 // In order to avoid duplication of interface documentation, please find all
103 // leading comments near the respective function / variable definitions (not
104 // the declarations here), which is where your code editor of choice takes you
105 // anyway when jumping to a function.
106 //
107
108 //
109 // utility macros
110 //
111 #define VIRTIO_NET_FROM_SNP(SnpPointer) \
112 CR (SnpPointer, VNET_DEV, Snp, VNET_SIG)
113
114 #define VIRTIO_CFG_WRITE(Dev, Field, Value) ((Dev)->VirtIo->WriteDevice ( \
115 (Dev)->VirtIo, \
116 OFFSET_OF_VNET (Field), \
117 SIZE_OF_VNET (Field), \
118 (Value) \
119 ))
120
121 #define VIRTIO_CFG_READ(Dev, Field, Pointer) ((Dev)->VirtIo->ReadDevice ( \
122 (Dev)->VirtIo, \
123 OFFSET_OF_VNET (Field), \
124 SIZE_OF_VNET (Field), \
125 sizeof *(Pointer), \
126 (Pointer) \
127 ))
128
129 //
130 // component naming
131 //
132 extern EFI_COMPONENT_NAME_PROTOCOL gVirtioNetComponentName;
133 extern EFI_COMPONENT_NAME2_PROTOCOL gVirtioNetComponentName2;
134
135 //
136 // driver binding
137 //
138 extern EFI_DRIVER_BINDING_PROTOCOL gVirtioNetDriverBinding;
139
140 //
141 // member functions implementing the Simple Network Protocol
142 //
143 EFI_STATUS
144 EFIAPI
145 VirtioNetStart (
146 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
147 );
148
149 EFI_STATUS
150 EFIAPI
151 VirtioNetStop (
152 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
153 );
154
155 EFI_STATUS
156 EFIAPI
157 VirtioNetInitialize (
158 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
159 IN UINTN ExtraRxBufferSize OPTIONAL,
160 IN UINTN ExtraTxBufferSize OPTIONAL
161 );
162
163 EFI_STATUS
164 EFIAPI
165 VirtioNetReset (
166 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
167 IN BOOLEAN ExtendedVerification
168 );
169
170 EFI_STATUS
171 EFIAPI
172 VirtioNetShutdown (
173 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
174 );
175
176 EFI_STATUS
177 EFIAPI
178 VirtioNetReceiveFilters (
179 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
180 IN UINT32 Enable,
181 IN UINT32 Disable,
182 IN BOOLEAN ResetMCastFilter,
183 IN UINTN MCastFilterCnt OPTIONAL,
184 IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL
185 );
186
187 EFI_STATUS
188 EFIAPI
189 VirtioNetStationAddress (
190 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
191 IN BOOLEAN Reset,
192 IN EFI_MAC_ADDRESS *New OPTIONAL
193 );
194
195 EFI_STATUS
196 EFIAPI
197 VirtioNetStatistics (
198 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
199 IN BOOLEAN Reset,
200 IN OUT UINTN *StatisticsSize OPTIONAL,
201 OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL
202 );
203
204 EFI_STATUS
205 EFIAPI
206 VirtioNetMcastIpToMac (
207 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
208 IN BOOLEAN IPv6,
209 IN EFI_IP_ADDRESS *Ip,
210 OUT EFI_MAC_ADDRESS *Mac
211 );
212
213 EFI_STATUS
214 EFIAPI
215 VirtioNetNvData (
216 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
217 IN BOOLEAN ReadWrite,
218 IN UINTN Offset,
219 IN UINTN BufferSize,
220 IN OUT VOID *Buffer
221 );
222
223 EFI_STATUS
224 EFIAPI
225 VirtioNetGetStatus (
226 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
227 OUT UINT32 *InterruptStatus OPTIONAL,
228 OUT VOID **TxBuf OPTIONAL
229 );
230
231 EFI_STATUS
232 EFIAPI
233 VirtioNetTransmit (
234 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
235 IN UINTN HeaderSize,
236 IN UINTN BufferSize,
237 IN /* +OUT! */ VOID *Buffer,
238 IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
239 IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,
240 IN UINT16 *Protocol OPTIONAL
241 );
242
243 EFI_STATUS
244 EFIAPI
245 VirtioNetReceive (
246 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
247 OUT UINTN *HeaderSize OPTIONAL,
248 IN OUT UINTN *BufferSize,
249 OUT VOID *Buffer,
250 OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
251 OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL,
252 OUT UINT16 *Protocol OPTIONAL
253 );
254
255 //
256 // utility functions shared by various SNP member functions
257 //
258 VOID
259 EFIAPI
260 VirtioNetShutdownRx (
261 IN OUT VNET_DEV *Dev
262 );
263
264 VOID
265 EFIAPI
266 VirtioNetShutdownTx (
267 IN OUT VNET_DEV *Dev
268 );
269
270 VOID
271 EFIAPI
272 VirtioNetUninitRing (
273 IN OUT VNET_DEV *Dev,
274 IN OUT VRING *Ring,
275 IN VOID *RingMap
276 );
277
278 //
279 // event callbacks
280 //
281 VOID
282 EFIAPI
283 VirtioNetIsPacketAvailable (
284 IN EFI_EVENT Event,
285 IN VOID *Context
286 );
287
288 VOID
289 EFIAPI
290 VirtioNetExitBoot (
291 IN EFI_EVENT Event,
292 IN VOID *Context
293 );
294
295 #endif // _VIRTIO_NET_DXE_H_