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>
30 #define VNET_SIG SIGNATURE_32 ('V', 'N', 'E', 'T')
33 // maximum number of pending packets, separately for each direction
35 #define VNET_MAX_PENDING 64
42 // BindingStart BindingStop
47 // +---------+ virtio-net device is reset, no resources are
48 // | stopped | allocated for traffic, but MAC address has
49 // +---------+ been retrieved
56 // | started | functionally identical to stopped
60 // SNP.Initialize SNP.Shutdown
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.
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
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
85 VRING RxRing
; // VirtioNetInitRing
86 VOID
*RxRingMap
; // VirtioRingMap and
88 UINT8
*RxBuf
; // VirtioNetInitRx
89 UINT16 RxLastUsed
; // VirtioNetInitRx
90 UINTN RxBufNrPages
; // VirtioNetInitRx
91 EFI_PHYSICAL_ADDRESS RxBufDeviceBase
; // VirtioNetInitRx
92 VOID
*RxBufMap
; // VirtioNetInitRx
94 VRING TxRing
; // VirtioNetInitRing
95 VOID
*TxRingMap
; // VirtioRingMap and
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
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.
116 #define VIRTIO_NET_FROM_SNP(SnpPointer) \
117 CR (SnpPointer, VNET_DEV, Snp, VNET_SIG)
119 #define VIRTIO_CFG_WRITE(Dev, Field, Value) ((Dev)->VirtIo->WriteDevice ( \
121 OFFSET_OF_VNET (Field), \
122 SIZE_OF_VNET (Field), \
126 #define VIRTIO_CFG_READ(Dev, Field, Pointer) ((Dev)->VirtIo->ReadDevice ( \
128 OFFSET_OF_VNET (Field), \
129 SIZE_OF_VNET (Field), \
137 extern EFI_COMPONENT_NAME_PROTOCOL gVirtioNetComponentName
;
138 extern EFI_COMPONENT_NAME2_PROTOCOL gVirtioNetComponentName2
;
143 extern EFI_DRIVER_BINDING_PROTOCOL gVirtioNetDriverBinding
;
146 // member functions implementing the Simple Network Protocol
151 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
157 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
162 VirtioNetInitialize (
163 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
164 IN UINTN ExtraRxBufferSize OPTIONAL
,
165 IN UINTN ExtraTxBufferSize OPTIONAL
171 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
172 IN BOOLEAN ExtendedVerification
178 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
183 VirtioNetReceiveFilters (
184 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
187 IN BOOLEAN ResetMCastFilter
,
188 IN UINTN MCastFilterCnt OPTIONAL
,
189 IN EFI_MAC_ADDRESS
*MCastFilter OPTIONAL
194 VirtioNetStationAddress (
195 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
197 IN EFI_MAC_ADDRESS
*New OPTIONAL
202 VirtioNetStatistics (
203 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
205 IN OUT UINTN
*StatisticsSize OPTIONAL
,
206 OUT EFI_NETWORK_STATISTICS
*StatisticsTable OPTIONAL
211 VirtioNetMcastIpToMac (
212 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
214 IN EFI_IP_ADDRESS
*Ip
,
215 OUT EFI_MAC_ADDRESS
*Mac
221 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
222 IN BOOLEAN ReadWrite
,
231 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
232 OUT UINT32
*InterruptStatus OPTIONAL
,
233 OUT VOID
**TxBuf OPTIONAL
239 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
242 IN
/* +OUT! */ VOID
*Buffer
,
243 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
244 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
245 IN UINT16
*Protocol OPTIONAL
251 IN EFI_SIMPLE_NETWORK_PROTOCOL
*This
,
252 OUT UINTN
*HeaderSize OPTIONAL
,
253 IN OUT UINTN
*BufferSize
,
255 OUT EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
256 OUT EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
257 OUT UINT16
*Protocol OPTIONAL
261 // utility functions shared by various SNP member functions
265 VirtioNetShutdownRx (
271 VirtioNetShutdownTx (
277 VirtioNetUninitRing (
278 IN OUT VNET_DEV
*Dev
,
288 VirtioNetIsPacketAvailable (
300 #endif // _VIRTIO_NET_DXE_H_