summaryrefslogtreecommitdiff
path: root/OvmfPkg
diff options
context:
space:
mode:
authorLaszlo Ersek <lersek@redhat.com>2013-06-14 07:39:32 +0000
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>2013-06-14 07:39:32 +0000
commit201cac0d5aeb5a2e73cdba2c4ffcf146dd4f4b15 (patch)
tree21b8cd10d808d1b19756c4343ef1be9d61d45ea9 /OvmfPkg
parent50d4fa86dbbf8f3cde7e81505222dd4653875c70 (diff)
downloadedk2-platforms-201cac0d5aeb5a2e73cdba2c4ffcf146dd4f4b15.tar.xz
OvmfPkg: VirtioNetDxe: declarations and macro definitions
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Jordan Justen <jordan.l.justen@intel.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14405 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'OvmfPkg')
-rw-r--r--OvmfPkg/Include/IndustryStandard/VirtioNet.h99
-rw-r--r--OvmfPkg/VirtioNetDxe/VirtioNet.h285
2 files changed, 384 insertions, 0 deletions
diff --git a/OvmfPkg/Include/IndustryStandard/VirtioNet.h b/OvmfPkg/Include/IndustryStandard/VirtioNet.h
new file mode 100644
index 0000000000..9f5291a24c
--- /dev/null
+++ b/OvmfPkg/Include/IndustryStandard/VirtioNet.h
@@ -0,0 +1,99 @@
+/** @file
+
+ Virtio Network Device specific type and macro definitions corresponding to
+ the virtio-0.9.5 specification.
+
+ Copyright (C) 2013, Red Hat, Inc.
+
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _VIRTIO_NET_H_
+#define _VIRTIO_NET_H_
+
+#include <IndustryStandard/Virtio.h>
+
+//
+// virtio-0.9.5, Appendix C: Network Device
+//
+#pragma pack(1)
+typedef struct {
+ VIRTIO_HDR Generic;
+ UINT8 VhdrMac[6];
+ UINT16 VhdrLinkStatus;
+} VNET_HDR;
+#pragma pack()
+
+#define OFFSET_OF_VNET(Field) OFFSET_OF (VNET_HDR, Field)
+#define SIZE_OF_VNET(Field) (sizeof ((VNET_HDR *) 0)->Field)
+
+//
+// Queue Identifiers
+//
+#define VIRTIO_NET_Q_RX 0
+#define VIRTIO_NET_Q_TX 1
+
+//
+// Feature Bits
+//
+#define VIRTIO_NET_F_CSUM BIT0 // host to checksum outgoing packets
+#define VIRTIO_NET_F_GUEST_CSUM BIT1 // guest to checksum incoming packets
+#define VIRTIO_NET_F_MAC BIT5 // MAC available to guest
+#define VIRTIO_NET_F_GSO BIT6 // deprecated
+#define VIRTIO_NET_F_GUEST_TSO4 BIT7 // guest can receive TSOv4
+#define VIRTIO_NET_F_GUEST_TSO6 BIT8 // guest can receive TSOv6
+#define VIRTIO_NET_F_GUEST_ECN BIT9 // guest can receive TSO with ECN
+#define VIRTIO_NET_F_GUEST_UFO BIT10 // guest can receive UFO
+#define VIRTIO_NET_F_HOST_TSO4 BIT11 // host can receive TSOv4
+#define VIRTIO_NET_F_HOST_TSO6 BIT12 // host can receive TSOv6
+#define VIRTIO_NET_F_HOST_ECN BIT13 // host can receive TSO with ECN
+#define VIRTIO_NET_F_HOST_UFO BIT14 // host can receive UFO
+#define VIRTIO_NET_F_MRG_RXBUF BIT15 // guest can merge receive buffers
+#define VIRTIO_NET_F_STATUS BIT16 // link status available to guest
+#define VIRTIO_NET_F_CTRL_VQ BIT17 // control channel available
+#define VIRTIO_NET_F_CTRL_RX BIT18 // control channel RX mode support
+#define VIRTIO_NET_F_CTRL_VLAN BIT19 // control channel VLAN filtering
+#define VIRTIO_NET_F_GUEST_ANNOUNCE BIT21 // guest can send gratuitous pkts
+
+//
+// Packet Header
+//
+#pragma pack(1)
+typedef struct {
+ UINT8 Flags;
+ UINT8 GsoType;
+ UINT16 HdrLen;
+ UINT16 GsoSize;
+ UINT16 CsumStart;
+ UINT16 CsumOffset;
+} VIRTIO_NET_REQ;
+#pragma pack()
+
+//
+// Bits in VIRTIO_NET_REQ.Flags
+//
+#define VIRTIO_NET_HDR_F_NEEDS_CSUM BIT0
+
+//
+// Types/Bits for VIRTIO_NET_REQ.GsoType
+//
+#define VIRTIO_NET_HDR_GSO_NONE 0x00
+#define VIRTIO_NET_HDR_GSO_TCPV4 0x01
+#define VIRTIO_NET_HDR_GSO_UDP 0x03
+#define VIRTIO_NET_HDR_GSO_TCPV6 0x04
+#define VIRTIO_NET_HDR_GSO_ECN BIT7
+
+//
+// Link Status Bits in VNET_HDR.VhdrLinkStatus
+//
+#define VIRTIO_NET_S_LINK_UP BIT0
+#define VIRTIO_NET_S_ANNOUNCE BIT1
+
+#endif // _VIRTIO_NET_H_
diff --git a/OvmfPkg/VirtioNetDxe/VirtioNet.h b/OvmfPkg/VirtioNetDxe/VirtioNet.h
new file mode 100644
index 0000000000..8c21bcdfa2
--- /dev/null
+++ b/OvmfPkg/VirtioNetDxe/VirtioNet.h
@@ -0,0 +1,285 @@
+/** @file
+
+ Internal definitions for the virtio-net driver, which produces Simple Network
+ Protocol instances for virtio-net devices.
+
+ Copyright (C) 2013, Red Hat, Inc.
+
+ This program and the accompanying materials are licensed and made available
+ under the terms and conditions of the BSD License which accompanies this
+ distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+
+#ifndef _VIRTIO_NET_DXE_H_
+#define _VIRTIO_NET_DXE_H_
+
+#include <IndustryStandard/VirtioNet.h>
+#include <Library/DebugLib.h>
+#include <Library/VirtioLib.h>
+#include <Protocol/ComponentName.h>
+#include <Protocol/ComponentName2.h>
+#include <Protocol/DevicePath.h>
+#include <Protocol/DriverBinding.h>
+#include <Protocol/PciIo.h>
+#include <Protocol/SimpleNetwork.h>
+
+#define VNET_SIG SIGNATURE_32 ('V', 'N', 'E', 'T')
+
+//
+// maximum number of pending packets, separately for each direction
+//
+#define VNET_MAX_PENDING 64
+
+//
+// State diagram:
+//
+// | ^
+// | |
+// BindingStart BindingStop
+// +SnpPopulate |
+// ++GetFeatures |
+// | |
+// v |
+// +---------+ virtio-net device is reset, no resources are
+// | stopped | allocated for traffic, but MAC address has
+// +---------+ been retrieved
+// | ^
+// | |
+// SNP.Start SNP.Stop
+// | |
+// v |
+// +---------+
+// | started | functionally identical to stopped
+// +---------+
+// | ^
+// | |
+// SNP.Initialize SNP.Shutdown
+// | |
+// v |
+// +-------------+ Virtio-net setup complete, including DRIVER_OK
+// | initialized | bit. The receive queue is populated with
+// +-------------+ requests; McastIpToMac, GetStatus, Transmit,
+// Receive are callable.
+//
+
+typedef struct {
+ //
+ // Parts of this structure are initialized / torn down in various functions
+ // at various call depths. The table to the right should make it easier to
+ // track them.
+ //
+ // field init function
+ // ------------------ ------------------------------
+ UINT32 Signature; // VirtioNetDriverBindingStart
+ EFI_PCI_IO_PROTOCOL *PciIo; // VirtioNetDriverBindingStart
+ UINT64 OrigPciAttributes; // VirtioNetDriverBindingStart
+ EFI_SIMPLE_NETWORK_PROTOCOL Snp; // VirtioNetSnpPopulate
+ EFI_SIMPLE_NETWORK_MODE Snm; // VirtioNetSnpPopulate
+ EFI_EVENT ExitBoot; // VirtioNetSnpPopulate
+ EFI_DEVICE_PATH_PROTOCOL *MacDevicePath; // VirtioNetDriverBindingStart
+ EFI_HANDLE MacHandle; // VirtioNetDriverBindingStart
+
+ VRING RxRing; // VirtioNetInitRing
+ UINT8 *RxBuf; // VirtioNetInitRx
+ UINT16 RxLastUsed; // VirtioNetInitRx
+
+ VRING TxRing; // VirtioNetInitRing
+ UINT16 TxMaxPending; // VirtioNetInitTx
+ UINT16 TxCurPending; // VirtioNetInitTx
+ UINT16 *TxFreeStack; // VirtioNetInitTx
+ VIRTIO_NET_REQ TxSharedReq; // VirtioNetInitTx
+ UINT16 TxLastUsed; // VirtioNetInitTx
+} VNET_DEV;
+
+
+//
+// In order to avoid duplication of interface documentation, please find all
+// leading comments near the respective function / variable definitions (not
+// the declarations here), which is where your code editor of choice takes you
+// anyway when jumping to a function.
+//
+
+//
+// utility macros
+//
+#define VIRTIO_NET_FROM_SNP(SnpPointer) \
+ CR (SnpPointer, VNET_DEV, Snp, VNET_SIG)
+
+#define VIRTIO_CFG_WRITE(Dev, Field, Value) (VirtioWrite ( \
+ (Dev)->PciIo, \
+ OFFSET_OF_VNET (Field), \
+ SIZE_OF_VNET (Field), \
+ (Value) \
+ ))
+
+#define VIRTIO_CFG_READ(Dev, Field, Pointer) (VirtioRead ( \
+ (Dev)->PciIo, \
+ OFFSET_OF_VNET (Field), \
+ SIZE_OF_VNET (Field), \
+ sizeof *(Pointer), \
+ (Pointer) \
+ ))
+
+//
+// component naming
+//
+extern EFI_COMPONENT_NAME_PROTOCOL gVirtioNetComponentName;
+extern EFI_COMPONENT_NAME2_PROTOCOL gVirtioNetComponentName2;
+
+//
+// driver binding
+//
+extern EFI_DRIVER_BINDING_PROTOCOL gVirtioNetDriverBinding;
+
+//
+// member functions implementing the Simple Network Protocol
+//
+EFI_STATUS
+EFIAPI
+VirtioNetStart (
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioNetStop (
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioNetInitialize (
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
+ IN UINTN ExtraRxBufferSize OPTIONAL,
+ IN UINTN ExtraTxBufferSize OPTIONAL
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioNetReset (
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
+ IN BOOLEAN ExtendedVerification
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioNetShutdown (
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioNetReceiveFilters (
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
+ IN UINT32 Enable,
+ IN UINT32 Disable,
+ IN BOOLEAN ResetMCastFilter,
+ IN UINTN MCastFilterCnt OPTIONAL,
+ IN EFI_MAC_ADDRESS *MCastFilter OPTIONAL
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioNetStationAddress (
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
+ IN BOOLEAN Reset,
+ IN EFI_MAC_ADDRESS *New OPTIONAL
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioNetStatistics (
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
+ IN BOOLEAN Reset,
+ IN OUT UINTN *StatisticsSize OPTIONAL,
+ OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioNetMcastIpToMac (
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
+ IN BOOLEAN IPv6,
+ IN EFI_IP_ADDRESS *Ip,
+ OUT EFI_MAC_ADDRESS *Mac
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioNetNvData (
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
+ IN BOOLEAN ReadWrite,
+ IN UINTN Offset,
+ IN UINTN BufferSize,
+ IN OUT VOID *Buffer
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioNetGetStatus (
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
+ OUT UINT32 *InterruptStatus OPTIONAL,
+ OUT VOID **TxBuf OPTIONAL
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioNetTransmit (
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
+ IN UINTN HeaderSize,
+ IN UINTN BufferSize,
+ IN /* +OUT! */ VOID *Buffer,
+ IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
+ IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,
+ IN UINT16 *Protocol OPTIONAL
+ );
+
+EFI_STATUS
+EFIAPI
+VirtioNetReceive (
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
+ OUT UINTN *HeaderSize OPTIONAL,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer,
+ OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
+ OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL,
+ OUT UINT16 *Protocol OPTIONAL
+ );
+
+//
+// utility functions shared by various SNP member functions
+//
+VOID
+EFIAPI
+VirtioNetShutdownRx (
+ IN OUT VNET_DEV *Dev
+ );
+
+VOID
+EFIAPI
+VirtioNetShutdownTx (
+ IN OUT VNET_DEV *Dev
+ );
+
+//
+// event callbacks
+//
+VOID
+EFIAPI
+VirtioNetIsPacketAvailable (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ );
+
+VOID
+EFIAPI
+VirtioNetExitBoot (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ );
+
+#endif // _VIRTIO_NET_DXE_H_