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 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
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.
18 #ifndef _VIRTIO_NET_DXE_H_
19 #define _VIRTIO_NET_DXE_H_
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 #include <Library/OrderedCollectionLib.h>
31 #define VNET_SIG SIGNATURE_32 ('V', 'N', 'E', 'T')
34 // maximum number of pending packets, separately for each direction
36 #define VNET_MAX_PENDING 64
43 // BindingStart BindingStop
48 // +---------+ virtio-net device is reset, no resources are
49 // | stopped | allocated for traffic, but MAC address has
50 // +---------+ been retrieved
57 // | started | functionally identical to stopped
61 // SNP.Initialize SNP.Shutdown
64 // +-------------+ Virtio-net setup complete, including DRIVER_OK
65 // | initialized | bit. The receive queue is populated with
66 // +-------------+ requests; McastIpToMac, GetStatus, Transmit,
67 // Receive are callable.
72 // Parts of this structure are initialized / torn down in various functions
73 // at various call depths. The table to the right should make it easier to
76 // field init function
77 // ------------------ ------------------------------
78 UINT32 Signature
; // VirtioNetDriverBindingStart
79 VIRTIO_DEVICE_PROTOCOL
*VirtIo
; // 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
86 VRING RxRing
; // VirtioNetInitRing
87 VOID
*RxRingMap
; // VirtioRingMap and
89 UINT8
*RxBuf
; // VirtioNetInitRx
90 UINT16 RxLastUsed
; // VirtioNetInitRx
91 UINTN RxBufNrPages
; // VirtioNetInitRx
92 EFI_PHYSICAL_ADDRESS RxBufDeviceBase
; // VirtioNetInitRx
93 VOID
*RxBufMap
; // VirtioNetInitRx
95 VRING TxRing
; // VirtioNetInitRing
96 VOID
*TxRingMap
; // VirtioRingMap and
98 UINT16 TxMaxPending
; // VirtioNetInitTx
99 UINT16 TxCurPending
; // VirtioNetInitTx
100 UINT16
*TxFreeStack
; // VirtioNetInitTx
101 VIRTIO_1_0_NET_REQ
*TxSharedReq
; // VirtioNetInitTx
102 VOID
*TxSharedReqMap
; // VirtioNetInitTx
103 UINT16 TxLastUsed
; // VirtioNetInitTx
104 ORDERED_COLLECTION
*TxBufCollection
; // VirtioNetInitTx
109 // In order to avoid duplication of interface documentation, please find all
110 // leading comments near the respective function / variable definitions (not
111 // the declarations here), which is where your code editor of choice takes you
112 // anyway when jumping to a function.
118 #define VIRTIO_NET_FROM_SNP(SnpPointer) \
119 CR (SnpPointer, VNET_DEV, Snp, VNET_SIG)
121 #define VIRTIO_CFG_WRITE(Dev, Field, Value) ((Dev)->VirtIo->WriteDevice ( \
123 OFFSET_OF_VNET (Field), \
124 SIZE_OF_VNET (Field), \
128 #define VIRTIO_CFG_READ(Dev, Field, Pointer) ((Dev)->VirtIo->ReadDevice ( \
130 OFFSET_OF_VNET (Field), \
131 SIZE_OF_VNET (Field), \
139 extern EFI_COMPONENT_NAME_PROTOCOL gVirtioNetComponentName
;
140 extern EFI_COMPONENT_NAME2_PROTOCOL gVirtioNetComponentName2
;
145 extern EFI_DRIVER_BINDING_PROTOCOL gVirtioNetDriverBinding
;
148 // member functions implementing the Simple Network Protocol
153 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
159 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
164 VirtioNetInitialize (
165 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
166 IN UINTN ExtraRxBufferSize OPTIONAL
,
167 IN UINTN ExtraTxBufferSize OPTIONAL
173 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
174 IN BOOLEAN ExtendedVerification
180 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
185 VirtioNetReceiveFilters (
186 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
189 IN BOOLEAN ResetMCastFilter
,
190 IN UINTN MCastFilterCnt OPTIONAL
,
191 IN EFI_MAC_ADDRESS
*MCastFilter OPTIONAL
196 VirtioNetStationAddress (
197 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
199 IN EFI_MAC_ADDRESS
*New OPTIONAL
204 VirtioNetStatistics (
205 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
207 IN OUT UINTN
*StatisticsSize OPTIONAL
,
208 OUT EFI_NETWORK_STATISTICS
*StatisticsTable OPTIONAL
213 VirtioNetMcastIpToMac (
214 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
216 IN EFI_IP_ADDRESS
*Ip
,
217 OUT EFI_MAC_ADDRESS
*Mac
223 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
224 IN BOOLEAN ReadWrite
,
233 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
234 OUT UINT32
*InterruptStatus OPTIONAL
,
235 OUT VOID
**TxBuf OPTIONAL
241 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
244 IN
/* +OUT! */ VOID
*Buffer
,
245 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
246 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
247 IN UINT16
*Protocol OPTIONAL
253 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
254 OUT UINTN
*HeaderSize OPTIONAL
,
255 IN OUT UINTN
*BufferSize
,
257 OUT EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
258 OUT EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
259 OUT UINT16
*Protocol OPTIONAL
263 // utility functions shared by various SNP member functions
267 VirtioNetShutdownRx (
273 VirtioNetShutdownTx (
279 VirtioNetUninitRing (
280 IN OUT VNET_DEV
*Dev
,
286 // utility functions to map caller-supplied Tx buffer system physical address
287 // to a device address and vice versa
294 IN UINTN NumberOfBytes
,
295 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
300 VirtioNetUnmapTxBuf (
303 IN EFI_PHYSICAL_ADDRESS DeviceAddress
308 VirtioNetTxBufMapInfoCompare (
309 IN CONST VOID
*UserStruct1
,
310 IN CONST VOID
*UserStruct2
315 VirtioNetTxBufDeviceAddressCompare (
316 IN CONST VOID
*StandaloneKey
,
317 IN CONST VOID
*UserStruct
326 VirtioNetIsPacketAvailable (
338 #endif // _VIRTIO_NET_DXE_H_