TianoCore EDK2 master
Loading...
Searching...
No Matches
VirtioNet.h
Go to the documentation of this file.
1
12#ifndef _VIRTIO_NET_DXE_H_
13#define _VIRTIO_NET_DXE_H_
14
16#include <Library/DebugLib.h>
17#include <Library/VirtioLib.h>
20#include <Protocol/DevicePath.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// 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//
132extern EFI_COMPONENT_NAME_PROTOCOL gVirtioNetComponentName;
133extern EFI_COMPONENT_NAME2_PROTOCOL gVirtioNetComponentName2;
134
135//
136// driver binding
137//
138extern EFI_DRIVER_BINDING_PROTOCOL gVirtioNetDriverBinding;
139
140//
141// member functions implementing the Simple Network Protocol
142//
144EFIAPI
147 );
148
150EFIAPI
153 );
154
156EFIAPI
159 IN UINTN ExtraRxBufferSize OPTIONAL,
160 IN UINTN ExtraTxBufferSize OPTIONAL
161 );
162
164EFIAPI
167 IN BOOLEAN ExtendedVerification
168 );
169
171EFIAPI
174 );
175
177EFIAPI
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
188EFIAPI
191 IN BOOLEAN Reset,
192 IN EFI_MAC_ADDRESS *New OPTIONAL
193 );
194
196EFIAPI
199 IN BOOLEAN Reset,
200 IN OUT UINTN *StatisticsSize OPTIONAL,
201 OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL
202 );
203
205EFIAPI
208 IN BOOLEAN IPv6,
209 IN EFI_IP_ADDRESS *Ip,
211 );
212
214EFIAPI
217 IN BOOLEAN ReadWrite,
218 IN UINTN Offset,
219 IN UINTN BufferSize,
220 IN OUT VOID *Buffer
221 );
222
224EFIAPI
227 OUT UINT32 *InterruptStatus OPTIONAL,
228 OUT VOID **TxBuf OPTIONAL
229 );
230
232EFIAPI
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
244EFIAPI
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//
258VOID
259EFIAPI
261 IN OUT VNET_DEV *Dev
262 );
263
264VOID
265EFIAPI
266VirtioNetShutdownTx (
267 IN OUT VNET_DEV *Dev
268 );
269
270VOID
271EFIAPI
273 IN OUT VNET_DEV *Dev,
274 IN OUT VRING *Ring,
275 IN VOID *RingMap
276 );
277
278//
279// utility functions to map caller-supplied Tx buffer system physical address
280// to a device address and vice versa
281//
283EFIAPI
285 IN VNET_DEV *Dev,
286 IN VOID *Buffer,
287 IN UINTN NumberOfBytes,
288 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress
289 );
290
292EFIAPI
294 IN VNET_DEV *Dev,
295 OUT VOID **Buffer,
296 IN EFI_PHYSICAL_ADDRESS DeviceAddress
297 );
298
299INTN
300EFIAPI
302 IN CONST VOID *UserStruct1,
303 IN CONST VOID *UserStruct2
304 );
305
306INTN
307EFIAPI
309 IN CONST VOID *StandaloneKey,
310 IN CONST VOID *UserStruct
311 );
312
313//
314// event callbacks
315//
316VOID
317EFIAPI
319 IN EFI_EVENT Event,
320 IN VOID *Context
321 );
322
323VOID
324EFIAPI
325VirtioNetExitBoot (
326 IN EFI_EVENT Event,
327 IN VOID *Context
328 );
329
330#endif // _VIRTIO_NET_DXE_H_
UINT64 UINTN
INT64 INTN
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_STATUS EFIAPI VirtioNetStationAddress(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN Reset, IN EFI_MAC_ADDRESS *New OPTIONAL)
EFI_STATUS EFIAPI VirtioNetMapTxBuf(IN VNET_DEV *Dev, IN VOID *Buffer, IN UINTN NumberOfBytes, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress)
EFI_STATUS EFIAPI VirtioNetInitialize(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN UINTN ExtraRxBufferSize OPTIONAL, IN UINTN ExtraTxBufferSize OPTIONAL)
INTN EFIAPI VirtioNetTxBufMapInfoCompare(IN CONST VOID *UserStruct1, IN CONST VOID *UserStruct2)
EFI_STATUS EFIAPI VirtioNetReceiveFilters(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN UINT32 Enable, IN UINT32 Disable, IN BOOLEAN ResetMCastFilter, IN UINTN MCastFilterCnt OPTIONAL, IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL)
EFI_STATUS EFIAPI VirtioNetReceive(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, OUT UINTN *HeaderSize OPTIONAL, IN OUT UINTN *BufferSize, OUT VOID *Buffer, OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL, OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL, OUT UINT16 *Protocol OPTIONAL)
Definition: SnpReceive.c:57
EFI_STATUS EFIAPI VirtioNetStatistics(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN Reset, IN OUT UINTN *StatisticsSize OPTIONAL, OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL)
EFI_STATUS EFIAPI VirtioNetTransmit(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN UINTN HeaderSize, IN UINTN BufferSize, IN VOID *Buffer, IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL, IN EFI_MAC_ADDRESS *DestAddr OPTIONAL, IN UINT16 *Protocol OPTIONAL)
Definition: SnpTransmit.c:59
EFI_STATUS EFIAPI VirtioNetStop(IN EFI_SIMPLE_NETWORK_PROTOCOL *This)
Definition: SnpStop.c:34
VOID EFIAPI VirtioNetIsPacketAvailable(IN EFI_EVENT Event, IN VOID *Context)
Definition: Events.c:31
EFI_STATUS EFIAPI VirtioNetStart(IN EFI_SIMPLE_NETWORK_PROTOCOL *This)
Definition: SnpStart.c:33
VOID EFIAPI VirtioNetShutdownRx(IN OUT VNET_DEV *Dev)
EFI_STATUS EFIAPI VirtioNetNvData(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN ReadWrite, IN UINTN Offset, IN UINTN BufferSize, IN OUT VOID *Buffer)
EFI_STATUS EFIAPI VirtioNetMcastIpToMac(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN IPv6, IN EFI_IP_ADDRESS *Ip, OUT EFI_MAC_ADDRESS *Mac)
EFI_STATUS EFIAPI VirtioNetUnmapTxBuf(IN VNET_DEV *Dev, OUT VOID **Buffer, IN EFI_PHYSICAL_ADDRESS DeviceAddress)
INTN EFIAPI VirtioNetTxBufDeviceAddressCompare(IN CONST VOID *StandaloneKey, IN CONST VOID *UserStruct)
VOID EFIAPI VirtioNetUninitRing(IN OUT VNET_DEV *Dev, IN OUT VRING *Ring, IN VOID *RingMap)
EFI_STATUS EFIAPI VirtioNetShutdown(IN EFI_SIMPLE_NETWORK_PROTOCOL *This)
Definition: SnpShutdown.c:35
EFI_STATUS EFIAPI VirtioNetReset(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
EFI_STATUS EFIAPI VirtioNetGetStatus(IN EFI_SIMPLE_NETWORK_PROTOCOL *This, OUT UINT32 *InterruptStatus OPTIONAL, OUT VOID **TxBuf OPTIONAL)
Definition: SnpGetStatus.c:51