VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/VirtioNetDxe/VirtioNet.h@ 99396

Last change on this file since 99396 was 80721, checked in by vboxsync, 5 years ago

Devices/EFI/FirmwareNew: Start upgrade process to edk2-stable201908 (compiles on Windows and works to some extent), bugref:4643

  • Property svn:eol-style set to native
File size: 9.5 KB
Line 
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 Copyright (c) 2017, AMD Inc, All rights reserved.<BR>
8
9 SPDX-License-Identifier: BSD-2-Clause-Patent
10**/
11
12#ifndef _VIRTIO_NET_DXE_H_
13#define _VIRTIO_NET_DXE_H_
14
15#include <IndustryStandard/VirtioNet.h>
16#include <Library/DebugLib.h>
17#include <Library/VirtioLib.h>
18#include <Protocol/ComponentName.h>
19#include <Protocol/ComponentName2.h>
20#include <Protocol/DevicePath.h>
21#include <Protocol/DriverBinding.h>
22#include <Protocol/SimpleNetwork.h>
23#include <Library/OrderedCollectionLib.h>
24
25#define VNET_SIG SIGNATURE_32 ('V', 'N', 'E', 'T')
26
27//
28// maximum number of pending packets, separately for each direction
29//
30#define VNET_MAX_PENDING 64
31
32//
33// State diagram:
34//
35// | ^
36// | |
37// BindingStart BindingStop
38// +SnpPopulate |
39// ++GetFeatures |
40// | |
41// v |
42// +---------+ virtio-net device is reset, no resources are
43// | stopped | allocated for traffic, but MAC address has
44// +---------+ been retrieved
45// | ^
46// | |
47// SNP.Start SNP.Stop
48// | |
49// v |
50// +---------+
51// | started | functionally identical to stopped
52// +---------+
53// | ^
54// | |
55// SNP.Initialize SNP.Shutdown
56// | |
57// v |
58// +-------------+ Virtio-net setup complete, including DRIVER_OK
59// | initialized | bit. The receive queue is populated with
60// +-------------+ requests; McastIpToMac, GetStatus, Transmit,
61// Receive are callable.
62//
63
64typedef struct {
65 //
66 // Parts of this structure are initialized / torn down in various functions
67 // at various call depths. The table to the right should make it easier to
68 // track them.
69 //
70 // field init function
71 // ------------------ ------------------------------
72 UINT32 Signature; // VirtioNetDriverBindingStart
73 VIRTIO_DEVICE_PROTOCOL *VirtIo; // VirtioNetDriverBindingStart
74 EFI_SIMPLE_NETWORK_PROTOCOL Snp; // VirtioNetSnpPopulate
75 EFI_SIMPLE_NETWORK_MODE Snm; // VirtioNetSnpPopulate
76 EFI_EVENT ExitBoot; // VirtioNetSnpPopulate
77 EFI_DEVICE_PATH_PROTOCOL *MacDevicePath; // VirtioNetDriverBindingStart
78 EFI_HANDLE MacHandle; // VirtioNetDriverBindingStart
79
80 VRING RxRing; // VirtioNetInitRing
81 VOID *RxRingMap; // VirtioRingMap and
82 // VirtioNetInitRing
83 UINT8 *RxBuf; // VirtioNetInitRx
84 UINT16 RxLastUsed; // VirtioNetInitRx
85 UINTN RxBufNrPages; // VirtioNetInitRx
86 EFI_PHYSICAL_ADDRESS RxBufDeviceBase; // VirtioNetInitRx
87 VOID *RxBufMap; // VirtioNetInitRx
88
89 VRING TxRing; // VirtioNetInitRing
90 VOID *TxRingMap; // VirtioRingMap and
91 // VirtioNetInitRing
92 UINT16 TxMaxPending; // VirtioNetInitTx
93 UINT16 TxCurPending; // VirtioNetInitTx
94 UINT16 *TxFreeStack; // VirtioNetInitTx
95 VIRTIO_1_0_NET_REQ *TxSharedReq; // VirtioNetInitTx
96 VOID *TxSharedReqMap; // VirtioNetInitTx
97 UINT16 TxLastUsed; // VirtioNetInitTx
98 ORDERED_COLLECTION *TxBufCollection; // VirtioNetInitTx
99} VNET_DEV;
100
101
102//
103// In order to avoid duplication of interface documentation, please find all
104// leading comments near the respective function / variable definitions (not
105// the declarations here), which is where your code editor of choice takes you
106// anyway when jumping to a function.
107//
108
109//
110// utility macros
111//
112#define VIRTIO_NET_FROM_SNP(SnpPointer) \
113 CR (SnpPointer, VNET_DEV, Snp, VNET_SIG)
114
115#define VIRTIO_CFG_WRITE(Dev, Field, Value) ((Dev)->VirtIo->WriteDevice ( \
116 (Dev)->VirtIo, \
117 OFFSET_OF_VNET (Field), \
118 SIZE_OF_VNET (Field), \
119 (Value) \
120 ))
121
122#define VIRTIO_CFG_READ(Dev, Field, Pointer) ((Dev)->VirtIo->ReadDevice ( \
123 (Dev)->VirtIo, \
124 OFFSET_OF_VNET (Field), \
125 SIZE_OF_VNET (Field), \
126 sizeof *(Pointer), \
127 (Pointer) \
128 ))
129
130//
131// component naming
132//
133extern EFI_COMPONENT_NAME_PROTOCOL gVirtioNetComponentName;
134extern EFI_COMPONENT_NAME2_PROTOCOL gVirtioNetComponentName2;
135
136//
137// driver binding
138//
139extern EFI_DRIVER_BINDING_PROTOCOL gVirtioNetDriverBinding;
140
141//
142// member functions implementing the Simple Network Protocol
143//
144EFI_STATUS
145EFIAPI
146VirtioNetStart (
147 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
148 );
149
150EFI_STATUS
151EFIAPI
152VirtioNetStop (
153 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
154 );
155
156EFI_STATUS
157EFIAPI
158VirtioNetInitialize (
159 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
160 IN UINTN ExtraRxBufferSize OPTIONAL,
161 IN UINTN ExtraTxBufferSize OPTIONAL
162 );
163
164EFI_STATUS
165EFIAPI
166VirtioNetReset (
167 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
168 IN BOOLEAN ExtendedVerification
169 );
170
171EFI_STATUS
172EFIAPI
173VirtioNetShutdown (
174 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
175 );
176
177EFI_STATUS
178EFIAPI
179VirtioNetReceiveFilters (
180 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
181 IN UINT32 Enable,
182 IN UINT32 Disable,
183 IN BOOLEAN ResetMCastFilter,
184 IN UINTN MCastFilterCnt OPTIONAL,
185 IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL
186 );
187
188EFI_STATUS
189EFIAPI
190VirtioNetStationAddress (
191 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
192 IN BOOLEAN Reset,
193 IN EFI_MAC_ADDRESS *New OPTIONAL
194 );
195
196EFI_STATUS
197EFIAPI
198VirtioNetStatistics (
199 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
200 IN BOOLEAN Reset,
201 IN OUT UINTN *StatisticsSize OPTIONAL,
202 OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL
203 );
204
205EFI_STATUS
206EFIAPI
207VirtioNetMcastIpToMac (
208 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
209 IN BOOLEAN IPv6,
210 IN EFI_IP_ADDRESS *Ip,
211 OUT EFI_MAC_ADDRESS *Mac
212 );
213
214EFI_STATUS
215EFIAPI
216VirtioNetNvData (
217 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
218 IN BOOLEAN ReadWrite,
219 IN UINTN Offset,
220 IN UINTN BufferSize,
221 IN OUT VOID *Buffer
222 );
223
224EFI_STATUS
225EFIAPI
226VirtioNetGetStatus (
227 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
228 OUT UINT32 *InterruptStatus OPTIONAL,
229 OUT VOID **TxBuf OPTIONAL
230 );
231
232EFI_STATUS
233EFIAPI
234VirtioNetTransmit (
235 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
236 IN UINTN HeaderSize,
237 IN UINTN BufferSize,
238 IN /* +OUT! */ VOID *Buffer,
239 IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
240 IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,
241 IN UINT16 *Protocol OPTIONAL
242 );
243
244EFI_STATUS
245EFIAPI
246VirtioNetReceive (
247 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
248 OUT UINTN *HeaderSize OPTIONAL,
249 IN OUT UINTN *BufferSize,
250 OUT VOID *Buffer,
251 OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
252 OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL,
253 OUT UINT16 *Protocol OPTIONAL
254 );
255
256//
257// utility functions shared by various SNP member functions
258//
259VOID
260EFIAPI
261VirtioNetShutdownRx (
262 IN OUT VNET_DEV *Dev
263 );
264
265VOID
266EFIAPI
267VirtioNetShutdownTx (
268 IN OUT VNET_DEV *Dev
269 );
270
271VOID
272EFIAPI
273VirtioNetUninitRing (
274 IN OUT VNET_DEV *Dev,
275 IN OUT VRING *Ring,
276 IN VOID *RingMap
277 );
278
279//
280// utility functions to map caller-supplied Tx buffer system physical address
281// to a device address and vice versa
282//
283EFI_STATUS
284EFIAPI
285VirtioNetMapTxBuf (
286 IN VNET_DEV *Dev,
287 IN VOID *Buffer,
288 IN UINTN NumberOfBytes,
289 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress
290 );
291
292EFI_STATUS
293EFIAPI
294VirtioNetUnmapTxBuf (
295 IN VNET_DEV *Dev,
296 OUT VOID **Buffer,
297 IN EFI_PHYSICAL_ADDRESS DeviceAddress
298 );
299
300INTN
301EFIAPI
302VirtioNetTxBufMapInfoCompare (
303 IN CONST VOID *UserStruct1,
304 IN CONST VOID *UserStruct2
305 );
306
307INTN
308EFIAPI
309VirtioNetTxBufDeviceAddressCompare (
310 IN CONST VOID *StandaloneKey,
311 IN CONST VOID *UserStruct
312 );
313
314
315//
316// event callbacks
317//
318VOID
319EFIAPI
320VirtioNetIsPacketAvailable (
321 IN EFI_EVENT Event,
322 IN VOID *Context
323 );
324
325VOID
326EFIAPI
327VirtioNetExitBoot (
328 IN EFI_EVENT Event,
329 IN VOID *Context
330 );
331
332#endif // _VIRTIO_NET_DXE_H_
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette