]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/VirtioNetDxe/VirtioNet.h
8c21bcdfa2a823c29b2a1f91a38552630b3faf18
[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/PciIo.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 EFI_PCI_IO_PROTOCOL *PciIo; // VirtioNetDriverBindingStart
79 UINT64 OrigPciAttributes; // VirtioNetDriverBindingStart
80 EFI_SIMPLE_NETWORK_PROTOCOL Snp; // VirtioNetSnpPopulate
81 EFI_SIMPLE_NETWORK_MODE Snm; // VirtioNetSnpPopulate
82 EFI_EVENT ExitBoot; // VirtioNetSnpPopulate
83 EFI_DEVICE_PATH_PROTOCOL *MacDevicePath; // VirtioNetDriverBindingStart
84 EFI_HANDLE MacHandle; // VirtioNetDriverBindingStart
85
86 VRING RxRing; // VirtioNetInitRing
87 UINT8 *RxBuf; // VirtioNetInitRx
88 UINT16 RxLastUsed; // VirtioNetInitRx
89
90 VRING TxRing; // VirtioNetInitRing
91 UINT16 TxMaxPending; // VirtioNetInitTx
92 UINT16 TxCurPending; // VirtioNetInitTx
93 UINT16 *TxFreeStack; // VirtioNetInitTx
94 VIRTIO_NET_REQ TxSharedReq; // VirtioNetInitTx
95 UINT16 TxLastUsed; // VirtioNetInitTx
96 } VNET_DEV;
97
98
99 //
100 // In order to avoid duplication of interface documentation, please find all
101 // leading comments near the respective function / variable definitions (not
102 // the declarations here), which is where your code editor of choice takes you
103 // anyway when jumping to a function.
104 //
105
106 //
107 // utility macros
108 //
109 #define VIRTIO_NET_FROM_SNP(SnpPointer) \
110 CR (SnpPointer, VNET_DEV, Snp, VNET_SIG)
111
112 #define VIRTIO_CFG_WRITE(Dev, Field, Value) (VirtioWrite ( \
113 (Dev)->PciIo, \
114 OFFSET_OF_VNET (Field), \
115 SIZE_OF_VNET (Field), \
116 (Value) \
117 ))
118
119 #define VIRTIO_CFG_READ(Dev, Field, Pointer) (VirtioRead ( \
120 (Dev)->PciIo, \
121 OFFSET_OF_VNET (Field), \
122 SIZE_OF_VNET (Field), \
123 sizeof *(Pointer), \
124 (Pointer) \
125 ))
126
127 //
128 // component naming
129 //
130 extern EFI_COMPONENT_NAME_PROTOCOL gVirtioNetComponentName;
131 extern EFI_COMPONENT_NAME2_PROTOCOL gVirtioNetComponentName2;
132
133 //
134 // driver binding
135 //
136 extern EFI_DRIVER_BINDING_PROTOCOL gVirtioNetDriverBinding;
137
138 //
139 // member functions implementing the Simple Network Protocol
140 //
141 EFI_STATUS
142 EFIAPI
143 VirtioNetStart (
144 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
145 );
146
147 EFI_STATUS
148 EFIAPI
149 VirtioNetStop (
150 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
151 );
152
153 EFI_STATUS
154 EFIAPI
155 VirtioNetInitialize (
156 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
157 IN UINTN ExtraRxBufferSize OPTIONAL,
158 IN UINTN ExtraTxBufferSize OPTIONAL
159 );
160
161 EFI_STATUS
162 EFIAPI
163 VirtioNetReset (
164 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
165 IN BOOLEAN ExtendedVerification
166 );
167
168 EFI_STATUS
169 EFIAPI
170 VirtioNetShutdown (
171 IN EFI_SIMPLE_NETWORK_PROTOCOL *This
172 );
173
174 EFI_STATUS
175 EFIAPI
176 VirtioNetReceiveFilters (
177 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
178 IN UINT32 Enable,
179 IN UINT32 Disable,
180 IN BOOLEAN ResetMCastFilter,
181 IN UINTN MCastFilterCnt OPTIONAL,
182 IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL
183 );
184
185 EFI_STATUS
186 EFIAPI
187 VirtioNetStationAddress (
188 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
189 IN BOOLEAN Reset,
190 IN EFI_MAC_ADDRESS *New OPTIONAL
191 );
192
193 EFI_STATUS
194 EFIAPI
195 VirtioNetStatistics (
196 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
197 IN BOOLEAN Reset,
198 IN OUT UINTN *StatisticsSize OPTIONAL,
199 OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL
200 );
201
202 EFI_STATUS
203 EFIAPI
204 VirtioNetMcastIpToMac (
205 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
206 IN BOOLEAN IPv6,
207 IN EFI_IP_ADDRESS *Ip,
208 OUT EFI_MAC_ADDRESS *Mac
209 );
210
211 EFI_STATUS
212 EFIAPI
213 VirtioNetNvData (
214 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
215 IN BOOLEAN ReadWrite,
216 IN UINTN Offset,
217 IN UINTN BufferSize,
218 IN OUT VOID *Buffer
219 );
220
221 EFI_STATUS
222 EFIAPI
223 VirtioNetGetStatus (
224 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
225 OUT UINT32 *InterruptStatus OPTIONAL,
226 OUT VOID **TxBuf OPTIONAL
227 );
228
229 EFI_STATUS
230 EFIAPI
231 VirtioNetTransmit (
232 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
233 IN UINTN HeaderSize,
234 IN UINTN BufferSize,
235 IN /* +OUT! */ VOID *Buffer,
236 IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
237 IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,
238 IN UINT16 *Protocol OPTIONAL
239 );
240
241 EFI_STATUS
242 EFIAPI
243 VirtioNetReceive (
244 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
245 OUT UINTN *HeaderSize OPTIONAL,
246 IN OUT UINTN *BufferSize,
247 OUT VOID *Buffer,
248 OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
249 OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL,
250 OUT UINT16 *Protocol OPTIONAL
251 );
252
253 //
254 // utility functions shared by various SNP member functions
255 //
256 VOID
257 EFIAPI
258 VirtioNetShutdownRx (
259 IN OUT VNET_DEV *Dev
260 );
261
262 VOID
263 EFIAPI
264 VirtioNetShutdownTx (
265 IN OUT VNET_DEV *Dev
266 );
267
268 //
269 // event callbacks
270 //
271 VOID
272 EFIAPI
273 VirtioNetIsPacketAvailable (
274 IN EFI_EVENT Event,
275 IN VOID *Context
276 );
277
278 VOID
279 EFIAPI
280 VirtioNetExitBoot (
281 IN EFI_EVENT Event,
282 IN VOID *Context
283 );
284
285 #endif // _VIRTIO_NET_DXE_H_