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