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) 2021-2024, Oracle and/or its affiliates.
|
---|
7 | Copyright (c) 2017, AMD Inc, All rights reserved.
|
---|
8 | Copyright (C) 2013, Red Hat, Inc.<BR>
|
---|
9 |
|
---|
10 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
11 | **/
|
---|
12 |
|
---|
13 | #ifndef _E1K_NET_DXE_H_
|
---|
14 | #define _E1K_NET_DXE_H_
|
---|
15 |
|
---|
16 | #include <Library/DebugLib.h>
|
---|
17 | #include <Protocol/PciIo.h>
|
---|
18 | #include <Protocol/PciRootBridgeIo.h>
|
---|
19 | #include <Protocol/ComponentName.h>
|
---|
20 | #include <Protocol/ComponentName2.h>
|
---|
21 | #include <Protocol/DevicePath.h>
|
---|
22 | #include <Protocol/DriverBinding.h>
|
---|
23 | #include <Protocol/SimpleNetwork.h>
|
---|
24 | #include <Library/OrderedCollectionLib.h>
|
---|
25 |
|
---|
26 | #include "E1kNetHw.h"
|
---|
27 |
|
---|
28 | #define E1K_NET_DEV_SIGNATURE SIGNATURE_32 ('E','1','K','N')
|
---|
29 |
|
---|
30 | //
|
---|
31 | // maximum number of pending packets, separately for each direction
|
---|
32 | //
|
---|
33 | #define E1K_NET_MAX_PENDING 64
|
---|
34 |
|
---|
35 | //
|
---|
36 | // State diagram:
|
---|
37 | //
|
---|
38 | // | ^
|
---|
39 | // | |
|
---|
40 | // BindingStart BindingStop
|
---|
41 | // +SnpPopulate |
|
---|
42 | // ++GetFeatures |
|
---|
43 | // | |
|
---|
44 | // v |
|
---|
45 | // +---------+ virtio-net device is reset, no resources are
|
---|
46 | // | stopped | allocated for traffic, but MAC address has
|
---|
47 | // +---------+ been retrieved
|
---|
48 | // | ^
|
---|
49 | // | |
|
---|
50 | // SNP.Start SNP.Stop
|
---|
51 | // | |
|
---|
52 | // v |
|
---|
53 | // +---------+
|
---|
54 | // | started | functionally identical to stopped
|
---|
55 | // +---------+
|
---|
56 | // | ^
|
---|
57 | // | |
|
---|
58 | // SNP.Initialize SNP.Shutdown
|
---|
59 | // | |
|
---|
60 | // v |
|
---|
61 | // +-------------+ Virtio-net setup complete, including DRIVER_OK
|
---|
62 | // | initialized | bit. The receive queue is populated with
|
---|
63 | // +-------------+ requests; McastIpToMac, GetStatus, Transmit,
|
---|
64 | // Receive are callable.
|
---|
65 | //
|
---|
66 |
|
---|
67 | typedef struct {
|
---|
68 | //
|
---|
69 | // Parts of this structure are initialized / torn down in various functions
|
---|
70 | // at various call depths. The table to the right should make it easier to
|
---|
71 | // track them.
|
---|
72 | //
|
---|
73 | // field init function
|
---|
74 | // ------------------ ------------------------------
|
---|
75 | UINT32 Signature; // VirtioNetDriverBindingStart
|
---|
76 | EFI_PCI_IO_PROTOCOL *PciIo; // VirtioNetDriverBindingStart
|
---|
77 | UINT64 OriginalPciAttributes; // VirtioNetDriverBindingStart
|
---|
78 | EFI_SIMPLE_NETWORK_PROTOCOL Snp; // VirtioNetSnpPopulate
|
---|
79 | EFI_SIMPLE_NETWORK_MODE Snm; // VirtioNetSnpPopulate
|
---|
80 | EFI_EVENT ExitBoot; // VirtioNetSnpPopulate
|
---|
81 | EFI_DEVICE_PATH_PROTOCOL *MacDevicePath; // VirtioNetDriverBindingStart
|
---|
82 | EFI_HANDLE MacHandle; // VirtioNetDriverBindingStart
|
---|
83 |
|
---|
84 | E1K_RX_DESC *RxRing; // VirtioNetInitRing
|
---|
85 | UINT8 *RxBuf; // E1kNetInitRx
|
---|
86 | UINT32 RdhLastSeen; // E1kNetInitRx
|
---|
87 | UINTN RxBufNrPages; // E1kNetInitRx
|
---|
88 | EFI_PHYSICAL_ADDRESS RxBufDeviceBase; // E1kNetInitRx
|
---|
89 | EFI_PHYSICAL_ADDRESS RxDeviceBase; // E1kNetInitRx
|
---|
90 | VOID *RxMap; // E1kNetInitRx
|
---|
91 |
|
---|
92 | UINT16 TxMaxPending; // E1kNetInitTx
|
---|
93 | UINT16 TxCurPending; // E1kNetInitTx
|
---|
94 | E1K_TX_DESC *TxRing; // E1kNetInitTx
|
---|
95 | VOID *TxRingMap; // E1kNetInitTx
|
---|
96 | UINT16 TxLastUsed; // E1kNetInitTx
|
---|
97 | UINT32 TdhLastSeen; // E1kNetInitTx
|
---|
98 | ORDERED_COLLECTION *TxBufCollection; // E1kNetInitTx
|
---|
99 | } E1K_NET_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 E1K_NET_FROM_SNP(SnpPointer) \
|
---|
113 | CR (SnpPointer, E1K_NET_DEV, Snp, E1K_NET_DEV_SIGNATURE)
|
---|
114 |
|
---|
115 | //
|
---|
116 | // component naming
|
---|
117 | //
|
---|
118 | extern EFI_COMPONENT_NAME_PROTOCOL gE1kNetComponentName;
|
---|
119 | extern EFI_COMPONENT_NAME2_PROTOCOL gE1kNetComponentName2;
|
---|
120 |
|
---|
121 | //
|
---|
122 | // driver binding
|
---|
123 | //
|
---|
124 | extern EFI_DRIVER_BINDING_PROTOCOL gE1kNetDriverBinding;
|
---|
125 |
|
---|
126 | //
|
---|
127 | // member functions implementing the Simple Network Protocol
|
---|
128 | //
|
---|
129 | EFI_STATUS
|
---|
130 | EFIAPI
|
---|
131 | E1kNetStart (
|
---|
132 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This
|
---|
133 | );
|
---|
134 |
|
---|
135 | EFI_STATUS
|
---|
136 | EFIAPI
|
---|
137 | E1kNetStop (
|
---|
138 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This
|
---|
139 | );
|
---|
140 |
|
---|
141 | EFI_STATUS
|
---|
142 | EFIAPI
|
---|
143 | E1kNetInitialize (
|
---|
144 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
---|
145 | IN UINTN ExtraRxBufferSize OPTIONAL,
|
---|
146 | IN UINTN ExtraTxBufferSize OPTIONAL
|
---|
147 | );
|
---|
148 |
|
---|
149 | EFI_STATUS
|
---|
150 | EFIAPI
|
---|
151 | E1kNetReset (
|
---|
152 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
---|
153 | IN BOOLEAN ExtendedVerification
|
---|
154 | );
|
---|
155 |
|
---|
156 | EFI_STATUS
|
---|
157 | EFIAPI
|
---|
158 | E1kNetShutdown (
|
---|
159 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This
|
---|
160 | );
|
---|
161 |
|
---|
162 | EFI_STATUS
|
---|
163 | EFIAPI
|
---|
164 | E1kNetReceiveFilters (
|
---|
165 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
---|
166 | IN UINT32 Enable,
|
---|
167 | IN UINT32 Disable,
|
---|
168 | IN BOOLEAN ResetMCastFilter,
|
---|
169 | IN UINTN MCastFilterCnt OPTIONAL,
|
---|
170 | IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL
|
---|
171 | );
|
---|
172 |
|
---|
173 | EFI_STATUS
|
---|
174 | EFIAPI
|
---|
175 | E1kNetStationAddress (
|
---|
176 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
---|
177 | IN BOOLEAN Reset,
|
---|
178 | IN EFI_MAC_ADDRESS *New OPTIONAL
|
---|
179 | );
|
---|
180 |
|
---|
181 | EFI_STATUS
|
---|
182 | EFIAPI
|
---|
183 | E1kNetStatistics (
|
---|
184 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
---|
185 | IN BOOLEAN Reset,
|
---|
186 | IN OUT UINTN *StatisticsSize OPTIONAL,
|
---|
187 | OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL
|
---|
188 | );
|
---|
189 |
|
---|
190 | EFI_STATUS
|
---|
191 | EFIAPI
|
---|
192 | E1kNetMcastIpToMac (
|
---|
193 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
---|
194 | IN BOOLEAN IPv6,
|
---|
195 | IN EFI_IP_ADDRESS *Ip,
|
---|
196 | OUT EFI_MAC_ADDRESS *Mac
|
---|
197 | );
|
---|
198 |
|
---|
199 | EFI_STATUS
|
---|
200 | EFIAPI
|
---|
201 | E1kNetNvData (
|
---|
202 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
---|
203 | IN BOOLEAN ReadWrite,
|
---|
204 | IN UINTN Offset,
|
---|
205 | IN UINTN BufferSize,
|
---|
206 | IN OUT VOID *Buffer
|
---|
207 | );
|
---|
208 |
|
---|
209 | EFI_STATUS
|
---|
210 | EFIAPI
|
---|
211 | E1kNetGetStatus (
|
---|
212 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
---|
213 | OUT UINT32 *InterruptStatus OPTIONAL,
|
---|
214 | OUT VOID **TxBuf OPTIONAL
|
---|
215 | );
|
---|
216 |
|
---|
217 | EFI_STATUS
|
---|
218 | EFIAPI
|
---|
219 | E1kNetTransmit (
|
---|
220 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
---|
221 | IN UINTN HeaderSize,
|
---|
222 | IN UINTN BufferSize,
|
---|
223 | IN /* +OUT! */ VOID *Buffer,
|
---|
224 | IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
|
---|
225 | IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,
|
---|
226 | IN UINT16 *Protocol OPTIONAL
|
---|
227 | );
|
---|
228 |
|
---|
229 | EFI_STATUS
|
---|
230 | EFIAPI
|
---|
231 | E1kNetReceive (
|
---|
232 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
---|
233 | OUT UINTN *HeaderSize OPTIONAL,
|
---|
234 | IN OUT UINTN *BufferSize,
|
---|
235 | OUT VOID *Buffer,
|
---|
236 | OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
|
---|
237 | OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL,
|
---|
238 | OUT UINT16 *Protocol OPTIONAL
|
---|
239 | );
|
---|
240 |
|
---|
241 | //
|
---|
242 | // utility functions shared by various SNP member functions
|
---|
243 | //
|
---|
244 | VOID
|
---|
245 | EFIAPI
|
---|
246 | E1kNetShutdownRx (
|
---|
247 | IN OUT E1K_NET_DEV *Dev
|
---|
248 | );
|
---|
249 |
|
---|
250 | VOID
|
---|
251 | EFIAPI
|
---|
252 | E1kNetShutdownTx (
|
---|
253 | IN OUT E1K_NET_DEV *Dev
|
---|
254 | );
|
---|
255 |
|
---|
256 | //
|
---|
257 | // utility functions to map caller-supplied Tx buffer system physical address
|
---|
258 | // to a device address and vice versa
|
---|
259 | //
|
---|
260 | EFI_STATUS
|
---|
261 | EFIAPI
|
---|
262 | E1kNetMapTxBuf (
|
---|
263 | IN E1K_NET_DEV *Dev,
|
---|
264 | IN VOID *Buffer,
|
---|
265 | IN UINTN NumberOfBytes,
|
---|
266 | OUT EFI_PHYSICAL_ADDRESS *DeviceAddress
|
---|
267 | );
|
---|
268 |
|
---|
269 | EFI_STATUS
|
---|
270 | EFIAPI
|
---|
271 | E1kNetUnmapTxBuf (
|
---|
272 | IN E1K_NET_DEV *Dev,
|
---|
273 | OUT VOID **Buffer,
|
---|
274 | IN EFI_PHYSICAL_ADDRESS DeviceAddress
|
---|
275 | );
|
---|
276 |
|
---|
277 | INTN
|
---|
278 | EFIAPI
|
---|
279 | E1kNetTxBufMapInfoCompare (
|
---|
280 | IN CONST VOID *UserStruct1,
|
---|
281 | IN CONST VOID *UserStruct2
|
---|
282 | );
|
---|
283 |
|
---|
284 | INTN
|
---|
285 | EFIAPI
|
---|
286 | E1kNetTxBufDeviceAddressCompare (
|
---|
287 | IN CONST VOID *StandaloneKey,
|
---|
288 | IN CONST VOID *UserStruct
|
---|
289 | );
|
---|
290 |
|
---|
291 |
|
---|
292 | //
|
---|
293 | // event callbacks
|
---|
294 | //
|
---|
295 | VOID
|
---|
296 | EFIAPI
|
---|
297 | E1kNetIsPacketAvailable (
|
---|
298 | IN EFI_EVENT Event,
|
---|
299 | IN VOID *Context
|
---|
300 | );
|
---|
301 |
|
---|
302 | VOID
|
---|
303 | EFIAPI
|
---|
304 | E1kNetExitBoot (
|
---|
305 | IN EFI_EVENT Event,
|
---|
306 | IN VOID *Context
|
---|
307 | );
|
---|
308 |
|
---|
309 | //
|
---|
310 | // Hardware I/O functions.
|
---|
311 | //
|
---|
312 | EFI_STATUS
|
---|
313 | EFIAPI
|
---|
314 | E1kNetRegWrite32 (
|
---|
315 | IN E1K_NET_DEV *Dev,
|
---|
316 | IN UINT32 Addr,
|
---|
317 | IN UINT32 Data
|
---|
318 | );
|
---|
319 |
|
---|
320 | EFI_STATUS
|
---|
321 | EFIAPI
|
---|
322 | E1kNetRegRead32 (
|
---|
323 | IN E1K_NET_DEV *Dev,
|
---|
324 | IN UINT32 Addr,
|
---|
325 | OUT UINT32 *Data
|
---|
326 | );
|
---|
327 |
|
---|
328 | EFI_STATUS
|
---|
329 | EFIAPI
|
---|
330 | E1kNetRegSet32 (
|
---|
331 | IN E1K_NET_DEV *Dev,
|
---|
332 | IN UINT32 Addr,
|
---|
333 | IN UINT32 Set
|
---|
334 | );
|
---|
335 |
|
---|
336 | EFI_STATUS
|
---|
337 | EFIAPI
|
---|
338 | E1kNetRegClear32 (
|
---|
339 | IN E1K_NET_DEV *Dev,
|
---|
340 | IN UINT32 Addr,
|
---|
341 | IN UINT32 Clear
|
---|
342 | );
|
---|
343 |
|
---|
344 | EFI_STATUS
|
---|
345 | EFIAPI
|
---|
346 | E1kNetDevReset (
|
---|
347 | IN E1K_NET_DEV *Dev
|
---|
348 | );
|
---|
349 |
|
---|
350 | #endif // _E1K_NET_DXE_H_
|
---|