summaryrefslogtreecommitdiff
path: root/OvmfPkg/VirtioNetDxe/DriverBinding.c
diff options
context:
space:
mode:
Diffstat (limited to 'OvmfPkg/VirtioNetDxe/DriverBinding.c')
-rw-r--r--OvmfPkg/VirtioNetDxe/DriverBinding.c121
1 files changed, 59 insertions, 62 deletions
diff --git a/OvmfPkg/VirtioNetDxe/DriverBinding.c b/OvmfPkg/VirtioNetDxe/DriverBinding.c
index f92a447f0..93995c635 100644
--- a/OvmfPkg/VirtioNetDxe/DriverBinding.c
+++ b/OvmfPkg/VirtioNetDxe/DriverBinding.c
@@ -49,8 +49,7 @@
unused.
@retval EFI_UNSUPPORTED The host doesn't supply a MAC address.
- @return Status codes from Dev->VirtIo->Io.Read(),
- VIRTIO_CFG_READ() and VIRTIO_CFG_WRITE().
+ @return Status codes from VirtIo protocol members.
@retval EFI_SUCCESS Configuration values retrieved.
*/
STATIC
@@ -66,6 +65,7 @@ VirtioNetGetFeatures (
EFI_STATUS Status;
UINT8 NextDevStat;
UINT32 Features;
+ UINTN MacIdx;
UINT16 LinkStatus;
//
@@ -73,19 +73,19 @@ VirtioNetGetFeatures (
// Initialization Sequence), but don't complete setting it up.
//
NextDevStat = 0; // step 1 -- reset device
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
if (EFI_ERROR (Status)) {
return Status;
}
NextDevStat |= VSTAT_ACK; // step 2 -- acknowledge device presence
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
if (EFI_ERROR (Status)) {
goto YieldDevice;
}
NextDevStat |= VSTAT_DRIVER; // step 3 -- we know how to drive it
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);
if (EFI_ERROR (Status)) {
goto YieldDevice;
}
@@ -93,7 +93,7 @@ VirtioNetGetFeatures (
//
// step 4a -- retrieve and validate features
//
- Status = Dev->VirtIo->GetDeviceFeatures (Dev->VirtIo, &Features);
+ Status = Dev->VirtIo->GetDeviceFeatures (Dev->VirtIo, &Features);
if (EFI_ERROR (Status)) {
goto YieldDevice;
}
@@ -105,15 +105,16 @@ VirtioNetGetFeatures (
Status = EFI_UNSUPPORTED;
goto YieldDevice;
}
- Status = Dev->VirtIo->ReadDevice (Dev->VirtIo,
- OFFSET_OF_VNET (Mac), // Offset
- sizeof(UINT8), // FieldSize
- SIZE_OF_VNET (Mac), // BufferSize
- MacAddress // Buffer
- );
-
- if (EFI_ERROR (Status)) {
- goto YieldDevice;
+ for (MacIdx = 0; MacIdx < SIZE_OF_VNET (Mac); ++MacIdx) {
+ Status = Dev->VirtIo->ReadDevice (Dev->VirtIo,
+ OFFSET_OF_VNET (Mac) + MacIdx, // Offset
+ 1, // FieldSize
+ 1, // BufferSize
+ &MacAddress->Addr[MacIdx] // Buffer
+ );
+ if (EFI_ERROR (Status)) {
+ goto YieldDevice;
+ }
}
//
@@ -124,7 +125,7 @@ VirtioNetGetFeatures (
}
else {
*MediaPresentSupported = TRUE;
- Status = VIRTIO_CFG_READ (Dev, LinkStatus, &LinkStatus);
+ Status = VIRTIO_CFG_READ (Dev, LinkStatus, &LinkStatus);
if (EFI_ERROR (Status)) {
goto YieldDevice;
}
@@ -132,7 +133,7 @@ VirtioNetGetFeatures (
}
YieldDevice:
- Dev->VirtIo->SetDeviceStatus (Dev->VirtIo,
+ Dev->VirtIo->SetDeviceStatus (Dev->VirtIo,
EFI_ERROR (Status) ? VSTAT_FAILED : 0);
return Status;
@@ -205,9 +206,9 @@ VirtioNetSnpPopulate (
Dev->Snp.Mode = &Dev->Snm;
Dev->Snm.State = EfiSimpleNetworkStopped;
- Dev->Snm.HwAddressSize = SIZE_OF_VNET (Mac);
- Dev->Snm.MediaHeaderSize = SIZE_OF_VNET (Mac) + // dst MAC
- SIZE_OF_VNET (Mac) + // src MAC
+ Dev->Snm.HwAddressSize = SIZE_OF_VNET (Mac);
+ Dev->Snm.MediaHeaderSize = SIZE_OF_VNET (Mac) + // dst MAC
+ SIZE_OF_VNET (Mac) + // src MAC
2; // Ethertype
Dev->Snm.MaxPacketSize = 1500;
Dev->Snm.NvRamSize = 0;
@@ -220,7 +221,7 @@ VirtioNetSnpPopulate (
Dev->Snm.MacAddressChangeable = FALSE;
Dev->Snm.MultipleTxSupported = TRUE;
- ASSERT (SIZE_OF_VNET (Mac) <= sizeof (EFI_MAC_ADDRESS));
+ ASSERT (SIZE_OF_VNET (Mac) <= sizeof (EFI_MAC_ADDRESS));
Status = VirtioNetGetFeatures (Dev, &Dev->Snm.CurrentAddress,
&Dev->Snm.MediaPresentSupported, &Dev->Snm.MediaPresent);
@@ -228,8 +229,8 @@ VirtioNetSnpPopulate (
goto CloseWaitForPacket;
}
CopyMem (&Dev->Snm.PermanentAddress, &Dev->Snm.CurrentAddress,
- SIZE_OF_VNET (Mac));
- SetMem (&Dev->Snm.BroadcastAddress, SIZE_OF_VNET (Mac), 0xFF);
+ SIZE_OF_VNET (Mac));
+ SetMem (&Dev->Snm.BroadcastAddress, SIZE_OF_VNET (Mac), 0xFF);
//
// VirtioNetExitBoot() is queued by ExitBootServices(); its purpose is to
@@ -346,36 +347,36 @@ VirtioNetDriverBindingSupported (
)
{
EFI_STATUS Status;
- VIRTIO_DEVICE_PROTOCOL *VirtIo;
-
- //
- // Attempt to open the device with the VirtIo set of interfaces. On success,
- // the protocol is "instantiated" for the VirtIo device. Covers duplicate open
- // attempts (EFI_ALREADY_STARTED).
- //
- Status = gBS->OpenProtocol (
- DeviceHandle, // candidate device
- &gVirtioDeviceProtocolGuid, // for generic VirtIo access
- (VOID **)&VirtIo, // handle to instantiate
- This->DriverBindingHandle, // requestor driver identity
- DeviceHandle, // ControllerHandle, according to
- // the UEFI Driver Model
- EFI_OPEN_PROTOCOL_BY_DRIVER // get exclusive VirtIo access to
- // the device; to be released
- );
+ VIRTIO_DEVICE_PROTOCOL *VirtIo;
+
+ //
+ // Attempt to open the device with the VirtIo set of interfaces. On success,
+ // the protocol is "instantiated" for the VirtIo device. Covers duplicate open
+ // attempts (EFI_ALREADY_STARTED).
+ //
+ Status = gBS->OpenProtocol (
+ DeviceHandle, // candidate device
+ &gVirtioDeviceProtocolGuid, // for generic VirtIo access
+ (VOID **)&VirtIo, // handle to instantiate
+ This->DriverBindingHandle, // requestor driver identity
+ DeviceHandle, // ControllerHandle, according to
+ // the UEFI Driver Model
+ EFI_OPEN_PROTOCOL_BY_DRIVER // get exclusive VirtIo access to
+ // the device; to be released
+ );
if (EFI_ERROR (Status)) {
return Status;
}
- if (VirtIo->SubSystemDeviceId != VIRTIO_SUBSYSTEM_NETWORK_CARD) {
- Status = EFI_UNSUPPORTED;
- }
+ if (VirtIo->SubSystemDeviceId != VIRTIO_SUBSYSTEM_NETWORK_CARD) {
+ Status = EFI_UNSUPPORTED;
+ }
//
- // We needed VirtIo access only transitorily, to see whether we support the
- // device or not.
+ // We needed VirtIo access only transitorily, to see whether we support the
+ // device or not.
//
- gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
This->DriverBindingHandle, DeviceHandle);
return Status;
}
@@ -441,7 +442,7 @@ VirtioNetDriverBindingStart (
VNET_DEV *Dev;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
MAC_ADDR_DEVICE_PATH MacNode;
- VOID *ChildVirtIo;
+ VOID *ChildVirtIo;
//
// allocate space for the driver instance
@@ -452,28 +453,24 @@ VirtioNetDriverBindingStart (
}
Dev->Signature = VNET_SIG;
- Status = gBS->OpenProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
- (VOID **)&Dev->VirtIo, This->DriverBindingHandle,
+ Status = gBS->OpenProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ (VOID **)&Dev->VirtIo, This->DriverBindingHandle,
DeviceHandle, EFI_OPEN_PROTOCOL_BY_DRIVER);
if (EFI_ERROR (Status)) {
goto FreeVirtioNet;
}
- if (Dev->VirtIo->SubSystemDeviceId != VIRTIO_SUBSYSTEM_NETWORK_CARD) {
- return EFI_UNSUPPORTED;
- }
-
//
// now we can run a basic one-shot virtio-net initialization required to
// retrieve the MAC address
//
Status = VirtioNetSnpPopulate (Dev);
if (EFI_ERROR (Status)) {
- goto CloseVirtIo;
+ goto CloseVirtIo;
}
//
- // get the device path of the virtio-net device -- one-shot open
+ // get the device path of the virtio-net device -- one-shot open
//
Status = gBS->OpenProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid,
(VOID **)&DevicePath, This->DriverBindingHandle,
@@ -511,11 +508,11 @@ VirtioNetDriverBindingStart (
}
//
- // make a note that we keep this device open with VirtIo for the sake of this
+ // make a note that we keep this device open with VirtIo for the sake of this
// child
//
- Status = gBS->OpenProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
- &ChildVirtIo, This->DriverBindingHandle,
+ Status = gBS->OpenProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ &ChildVirtIo, This->DriverBindingHandle,
Dev->MacHandle, EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER);
if (EFI_ERROR (Status)) {
goto UninstallMultiple;
@@ -535,8 +532,8 @@ FreeMacDevicePath:
Evacuate:
VirtioNetSnpEvacuate (Dev);
-CloseVirtIo:
- gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+CloseVirtIo:
+ gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
This->DriverBindingHandle, DeviceHandle);
FreeVirtioNet:
@@ -621,7 +618,7 @@ VirtioNetDriverBindingStop (
Status = EFI_DEVICE_ERROR;
}
else {
- gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
This->DriverBindingHandle, Dev->MacHandle);
gBS->UninstallMultipleProtocolInterfaces (Dev->MacHandle,
&gEfiDevicePathProtocolGuid, Dev->MacDevicePath,
@@ -639,7 +636,7 @@ VirtioNetDriverBindingStop (
//
// release remaining resources, tied directly to the parent handle
//
- gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
+ gBS->CloseProtocol (DeviceHandle, &gVirtioDeviceProtocolGuid,
This->DriverBindingHandle, DeviceHandle);
return EFI_SUCCESS;