]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/VirtioNetDxe/VirtioNet.h
OvmfPkg/EnrollDefaultKeys: enroll PK/KEK1 from the Type 11 SMBIOS table
[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 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
64 typedef 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 //
133 extern EFI_COMPONENT_NAME_PROTOCOL gVirtioNetComponentName;
134 extern EFI_COMPONENT_NAME2_PROTOCOL gVirtioNetComponentName2;
135
136 //
137 // driver binding
138 //
139 extern EFI_DRIVER_BINDING_PROTOCOL gVirtioNetDriverBinding;
140
141 //
142 // member functions implementing the Simple Network Protocol
143 //
144 EFI_STATUS
145 EFIAPI
146 VirtioNetStart (
147 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
148 );
149
150 EFI_STATUS
151 EFIAPI
152 VirtioNetStop (
153 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
154 );
155
156 EFI_STATUS
157 EFIAPI
158 VirtioNetInitialize (
159 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
160 IN UINTN ExtraRxBufferSize OPTIONAL,
161 IN UINTN ExtraTxBufferSize OPTIONAL
162 );
163
164 EFI_STATUS
165 EFIAPI
166 VirtioNetReset (
167 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
168 IN BOOLEAN ExtendedVerification
169 );
170
171 EFI_STATUS
172 EFIAPI
173 VirtioNetShutdown (
174 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
175 );
176
177 EFI_STATUS
178 EFIAPI
179 VirtioNetReceiveFilters (
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
188 EFI_STATUS
189 EFIAPI
190 VirtioNetStationAddress (
191 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
192 IN BOOLEAN Reset,
193 IN EFI_MAC_ADDRESS *New OPTIONAL
194 );
195
196 EFI_STATUS
197 EFIAPI
198 VirtioNetStatistics (
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
205 EFI_STATUS
206 EFIAPI
207 VirtioNetMcastIpToMac (
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
214 EFI_STATUS
215 EFIAPI
216 VirtioNetNvData (
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
224 EFI_STATUS
225 EFIAPI
226 VirtioNetGetStatus (
227 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
228 OUT UINT32 *InterruptStatus OPTIONAL,
229 OUT VOID **TxBuf OPTIONAL
230 );
231
232 EFI_STATUS
233 EFIAPI
234 VirtioNetTransmit (
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
244 EFI_STATUS
245 EFIAPI
246 VirtioNetReceive (
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 //
259 VOID
260 EFIAPI
261 VirtioNetShutdownRx (
262 IN OUT VNET_DEV *Dev
263 );
264
265 VOID
266 EFIAPI
267 VirtioNetShutdownTx (
268 IN OUT VNET_DEV *Dev
269 );
270
271 VOID
272 EFIAPI
273 VirtioNetUninitRing (
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 //
283 EFI_STATUS
284 EFIAPI
285 VirtioNetMapTxBuf (
286 IN VNET_DEV *Dev,
287 IN VOID *Buffer,
288 IN UINTN NumberOfBytes,
289 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress
290 );
291
292 EFI_STATUS
293 EFIAPI
294 VirtioNetUnmapTxBuf (
295 IN VNET_DEV *Dev,
296 OUT VOID **Buffer,
297 IN EFI_PHYSICAL_ADDRESS DeviceAddress
298 );
299
300 INTN
301 EFIAPI
302 VirtioNetTxBufMapInfoCompare (
303 IN CONST VOID *UserStruct1,
304 IN CONST VOID *UserStruct2
305 );
306
307 INTN
308 EFIAPI
309 VirtioNetTxBufDeviceAddressCompare (
310 IN CONST VOID *StandaloneKey,
311 IN CONST VOID *UserStruct
312 );
313
314
315 //
316 // event callbacks
317 //
318 VOID
319 EFIAPI
320 VirtioNetIsPacketAvailable (
321 IN EFI_EVENT Event,
322 IN VOID *Context
323 );
324
325 VOID
326 EFIAPI
327 VirtioNetExitBoot (
328 IN EFI_EVENT Event,
329 IN VOID *Context
330 );
331
332 #endif // _VIRTIO_NET_DXE_H_