3 Internal definitions for the virtio-net driver, which produces Simple Network
4 Protocol instances for virtio-net devices.
6 Copyright (C) 2013, Red Hat, Inc.
7 Copyright (c) 2017, AMD Inc, All rights reserved.<BR>
9 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #ifndef _VIRTIO_NET_DXE_H_
13 #define _VIRTIO_NET_DXE_H_
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>
25 #define VNET_SIG SIGNATURE_32 ('V', 'N', 'E', 'T')
28 // maximum number of pending packets, separately for each direction
30 #define VNET_MAX_PENDING 64
37 // BindingStart BindingStop
42 // +---------+ virtio-net device is reset, no resources are
43 // | stopped | allocated for traffic, but MAC address has
44 // +---------+ been retrieved
51 // | started | functionally identical to stopped
55 // SNP.Initialize SNP.Shutdown
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.
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
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
80 VRING RxRing
; // VirtioNetInitRing
81 VOID
*RxRingMap
; // VirtioRingMap and
83 UINT8
*RxBuf
; // VirtioNetInitRx
84 UINT16 RxLastUsed
; // VirtioNetInitRx
85 UINTN RxBufNrPages
; // VirtioNetInitRx
86 EFI_PHYSICAL_ADDRESS RxBufDeviceBase
; // VirtioNetInitRx
87 VOID
*RxBufMap
; // VirtioNetInitRx
89 VRING TxRing
; // VirtioNetInitRing
90 VOID
*TxRingMap
; // VirtioRingMap and
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
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.
112 #define VIRTIO_NET_FROM_SNP(SnpPointer) \
113 CR (SnpPointer, VNET_DEV, Snp, VNET_SIG)
115 #define VIRTIO_CFG_WRITE(Dev, Field, Value) ((Dev)->VirtIo->WriteDevice ( \
117 OFFSET_OF_VNET (Field), \
118 SIZE_OF_VNET (Field), \
122 #define VIRTIO_CFG_READ(Dev, Field, Pointer) ((Dev)->VirtIo->ReadDevice ( \
124 OFFSET_OF_VNET (Field), \
125 SIZE_OF_VNET (Field), \
133 extern EFI_COMPONENT_NAME_PROTOCOL gVirtioNetComponentName
;
134 extern EFI_COMPONENT_NAME2_PROTOCOL gVirtioNetComponentName2
;
139 extern EFI_DRIVER_BINDING_PROTOCOL gVirtioNetDriverBinding
;
142 // member functions implementing the Simple Network Protocol
147 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
153 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
158 VirtioNetInitialize (
159 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
160 IN UINTN ExtraRxBufferSize OPTIONAL
,
161 IN UINTN ExtraTxBufferSize OPTIONAL
167 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
168 IN BOOLEAN ExtendedVerification
174 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
179 VirtioNetReceiveFilters (
180 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
183 IN BOOLEAN ResetMCastFilter
,
184 IN UINTN MCastFilterCnt OPTIONAL
,
185 IN EFI_MAC_ADDRESS
*MCastFilter OPTIONAL
190 VirtioNetStationAddress (
191 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
193 IN EFI_MAC_ADDRESS
*New OPTIONAL
198 VirtioNetStatistics (
199 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
201 IN OUT UINTN
*StatisticsSize OPTIONAL
,
202 OUT EFI_NETWORK_STATISTICS
*StatisticsTable OPTIONAL
207 VirtioNetMcastIpToMac (
208 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
210 IN EFI_IP_ADDRESS
*Ip
,
211 OUT EFI_MAC_ADDRESS
*Mac
217 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
218 IN BOOLEAN ReadWrite
,
227 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
228 OUT UINT32
*InterruptStatus OPTIONAL
,
229 OUT VOID
**TxBuf OPTIONAL
235 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
238 IN
/* +OUT! */ VOID
*Buffer
,
239 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
240 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
241 IN UINT16
*Protocol OPTIONAL
247 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
248 OUT UINTN
*HeaderSize OPTIONAL
,
249 IN OUT UINTN
*BufferSize
,
251 OUT EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
252 OUT EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
253 OUT UINT16
*Protocol OPTIONAL
257 // utility functions shared by various SNP member functions
261 VirtioNetShutdownRx (
267 VirtioNetShutdownTx (
273 VirtioNetUninitRing (
274 IN OUT VNET_DEV
*Dev
,
280 // utility functions to map caller-supplied Tx buffer system physical address
281 // to a device address and vice versa
288 IN UINTN NumberOfBytes
,
289 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
294 VirtioNetUnmapTxBuf (
297 IN EFI_PHYSICAL_ADDRESS DeviceAddress
302 VirtioNetTxBufMapInfoCompare (
303 IN CONST VOID
*UserStruct1
,
304 IN CONST VOID
*UserStruct2
309 VirtioNetTxBufDeviceAddressCompare (
310 IN CONST VOID
*StandaloneKey
,
311 IN CONST VOID
*UserStruct
320 VirtioNetIsPacketAvailable (
332 #endif // _VIRTIO_NET_DXE_H_