VirtioRingMap().\r
@retval EFI_SUCCESS Ring initialized.\r
*/\r
-\r
STATIC\r
EFI_STATUS\r
EFIAPI\r
VirtioNetInitRing (\r
- IN OUT VNET_DEV *Dev,\r
- IN UINT16 Selector,\r
- OUT VRING *Ring,\r
- OUT VOID **Mapping\r
+ IN OUT VNET_DEV *Dev,\r
+ IN UINT16 Selector,\r
+ OUT VRING *Ring,\r
+ OUT VOID **Mapping\r
)\r
{\r
- EFI_STATUS Status;\r
- UINT16 QueueSize;\r
- UINT64 RingBaseShift;\r
- VOID *MapInfo;\r
+ EFI_STATUS Status;\r
+ UINT16 QueueSize;\r
+ UINT64 RingBaseShift;\r
+ VOID *MapInfo;\r
\r
//\r
// step 4b -- allocate selected queue\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
+\r
Status = Dev->VirtIo->GetQueueNumMax (Dev->VirtIo, &QueueSize);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
if (QueueSize < 2) {\r
return EFI_UNSUPPORTED;\r
}\r
+\r
Status = VirtioRingInit (Dev->VirtIo, QueueSize, Ring);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
return Status;\r
}\r
\r
-\r
/**\r
Set up static scaffolding for the VirtioNetTransmit() and\r
VirtioNetGetStatus() SNP methods.\r
VirtioMapAllBytesInSharedBuffer()\r
@retval EFI_SUCCESS TX setup successful.\r
*/\r
-\r
STATIC\r
EFI_STATUS\r
EFIAPI\r
VirtioNetInitTx (\r
- IN OUT VNET_DEV *Dev\r
+ IN OUT VNET_DEV *Dev\r
)\r
{\r
UINTN TxSharedReqSize;\r
EFI_PHYSICAL_ADDRESS DeviceAddress;\r
VOID *TxSharedReqBuffer;\r
\r
- Dev->TxMaxPending = (UINT16) MIN (Dev->TxRing.QueueSize / 2,\r
- VNET_MAX_PENDING);\r
+ Dev->TxMaxPending = (UINT16)MIN (\r
+ Dev->TxRing.QueueSize / 2,\r
+ VNET_MAX_PENDING\r
+ );\r
Dev->TxCurPending = 0;\r
- Dev->TxFreeStack = AllocatePool (Dev->TxMaxPending *\r
- sizeof *Dev->TxFreeStack);\r
+ Dev->TxFreeStack = AllocatePool (\r
+ Dev->TxMaxPending *\r
+ sizeof *Dev->TxFreeStack\r
+ );\r
if (Dev->TxFreeStack == NULL) {\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
Dev->TxSharedReq = TxSharedReqBuffer;\r
\r
-\r
//\r
// In VirtIo 1.0, the NumBuffers field is mandatory. In 0.9.5, it depends on\r
// VIRTIO_NET_F_MRG_RXBUF, which we never negotiate.\r
sizeof *Dev->TxSharedReq;\r
\r
for (PktIdx = 0; PktIdx < Dev->TxMaxPending; ++PktIdx) {\r
- UINT16 DescIdx;\r
+ UINT16 DescIdx;\r
\r
- DescIdx = (UINT16) (2 * PktIdx);\r
+ DescIdx = (UINT16)(2 * PktIdx);\r
Dev->TxFreeStack[PktIdx] = DescIdx;\r
\r
//\r
// (unmodified by the host) virtio-net request header.\r
//\r
Dev->TxRing.Desc[DescIdx].Addr = DeviceAddress;\r
- Dev->TxRing.Desc[DescIdx].Len = (UINT32) TxSharedReqSize;\r
+ Dev->TxRing.Desc[DescIdx].Len = (UINT32)TxSharedReqSize;\r
Dev->TxRing.Desc[DescIdx].Flags = VRING_DESC_F_NEXT;\r
- Dev->TxRing.Desc[DescIdx].Next = (UINT16) (DescIdx + 1);\r
+ Dev->TxRing.Desc[DescIdx].Next = (UINT16)(DescIdx + 1);\r
\r
//\r
// The second descriptor of each pending TX packet is updated on the fly,\r
//\r
// want no interrupt when a transmit completes\r
//\r
- *Dev->TxRing.Avail.Flags = (UINT16) VRING_AVAIL_F_NO_INTERRUPT;\r
+ *Dev->TxRing.Avail.Flags = (UINT16)VRING_AVAIL_F_NO_INTERRUPT;\r
\r
return EFI_SUCCESS;\r
\r
return Status;\r
}\r
\r
-\r
/**\r
Set up static scaffolding for the VirtioNetReceive() SNP method and enable\r
live device operation.\r
@retval EFI_SUCCESS RX setup successful. The device is live and may\r
already be writing to the receive area.\r
*/\r
-\r
STATIC\r
EFI_STATUS\r
EFIAPI\r
VirtioNetInitRx (\r
- IN OUT VNET_DEV *Dev\r
+ IN OUT VNET_DEV *Dev\r
)\r
{\r
EFI_STATUS Status;\r
// Limit the number of pending RX packets if the queue is big. The division\r
// by two is due to the above "two descriptors per packet" trait.\r
//\r
- RxAlwaysPending = (UINT16) MIN (Dev->RxRing.QueueSize / 2, VNET_MAX_PENDING);\r
+ RxAlwaysPending = (UINT16)MIN (Dev->RxRing.QueueSize / 2, VNET_MAX_PENDING);\r
\r
//\r
// The RxBuf is shared between guest and hypervisor, use\r
// BusMasterCommonBuffer so that it can be accessed by both guest and\r
// hypervisor.\r
//\r
- NumBytes = RxAlwaysPending * RxBufSize;\r
+ NumBytes = RxAlwaysPending * RxBufSize;\r
Dev->RxBufNrPages = EFI_SIZE_TO_PAGES (NumBytes);\r
- Status = Dev->VirtIo->AllocateSharedPages (\r
- Dev->VirtIo,\r
- Dev->RxBufNrPages,\r
- &RxBuffer\r
- );\r
+ Status = Dev->VirtIo->AllocateSharedPages (\r
+ Dev->VirtIo,\r
+ Dev->RxBufNrPages,\r
+ &RxBuffer\r
+ );\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
// the host should not send interrupts, we'll poll in VirtioNetReceive()\r
// and VirtioNetIsPacketAvailable().\r
//\r
- *Dev->RxRing.Avail.Flags = (UINT16) VRING_AVAIL_F_NO_INTERRUPT;\r
+ *Dev->RxRing.Avail.Flags = (UINT16)VRING_AVAIL_F_NO_INTERRUPT;\r
\r
//\r
// now set up a separate, two-part descriptor chain for each RX packet, and\r
// link each chain into (from) the available ring as well\r
//\r
- DescIdx = 0;\r
+ DescIdx = 0;\r
RxBufDeviceAddress = Dev->RxBufDeviceBase;\r
for (PktIdx = 0; PktIdx < RxAlwaysPending; ++PktIdx) {\r
//\r
// virtio-0.9.5, 2.4.1.1 Placing Buffers into the Descriptor Table\r
//\r
Dev->RxRing.Desc[DescIdx].Addr = RxBufDeviceAddress;\r
- Dev->RxRing.Desc[DescIdx].Len = (UINT32) VirtioNetReqSize;\r
+ Dev->RxRing.Desc[DescIdx].Len = (UINT32)VirtioNetReqSize;\r
Dev->RxRing.Desc[DescIdx].Flags = VRING_DESC_F_WRITE | VRING_DESC_F_NEXT;\r
- Dev->RxRing.Desc[DescIdx].Next = (UINT16) (DescIdx + 1);\r
- RxBufDeviceAddress += Dev->RxRing.Desc[DescIdx++].Len;\r
+ Dev->RxRing.Desc[DescIdx].Next = (UINT16)(DescIdx + 1);\r
+ RxBufDeviceAddress += Dev->RxRing.Desc[DescIdx++].Len;\r
\r
Dev->RxRing.Desc[DescIdx].Addr = RxBufDeviceAddress;\r
- Dev->RxRing.Desc[DescIdx].Len = (UINT32) (RxBufSize - VirtioNetReqSize);\r
+ Dev->RxRing.Desc[DescIdx].Len = (UINT32)(RxBufSize - VirtioNetReqSize);\r
Dev->RxRing.Desc[DescIdx].Flags = VRING_DESC_F_WRITE;\r
- RxBufDeviceAddress += Dev->RxRing.Desc[DescIdx++].Len;\r
+ RxBufDeviceAddress += Dev->RxRing.Desc[DescIdx++].Len;\r
}\r
\r
//\r
return Status;\r
}\r
\r
-\r
/**\r
Resets a network adapter and allocates the transmit and receive buffers\r
required by the network interface; optionally, also requests allocation of\r
interface.\r
\r
**/\r
-\r
EFI_STATUS\r
EFIAPI\r
VirtioNetInitialize (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- IN UINTN ExtraRxBufferSize OPTIONAL,\r
- IN UINTN ExtraTxBufferSize OPTIONAL\r
+ IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
+ IN UINTN ExtraRxBufferSize OPTIONAL,\r
+ IN UINTN ExtraTxBufferSize OPTIONAL\r
)\r
{\r
- VNET_DEV *Dev;\r
- EFI_TPL OldTpl;\r
- EFI_STATUS Status;\r
- UINT8 NextDevStat;\r
- UINT64 Features;\r
+ VNET_DEV *Dev;\r
+ EFI_TPL OldTpl;\r
+ EFI_STATUS Status;\r
+ UINT8 NextDevStat;\r
+ UINT64 Features;\r
\r
if (This == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
- if (ExtraRxBufferSize > 0 || ExtraTxBufferSize > 0) {\r
+\r
+ if ((ExtraRxBufferSize > 0) || (ExtraTxBufferSize > 0)) {\r
return EFI_UNSUPPORTED;\r
}\r
\r
- Dev = VIRTIO_NET_FROM_SNP (This);\r
+ Dev = VIRTIO_NET_FROM_SNP (This);\r
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
if (Dev->Snm.State != EfiSimpleNetworkStarted) {\r
Status = EFI_NOT_STARTED;\r
// virtio-0.9.5 spec, 2.2.1 Device Initialization Sequence.\r
//\r
NextDevStat = VSTAT_ACK; // step 2 -- acknowledge device presence\r
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);\r
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);\r
if (EFI_ERROR (Status)) {\r
goto InitFailed;\r
}\r
\r
NextDevStat |= VSTAT_DRIVER; // step 3 -- we know how to drive it\r
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);\r
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);\r
if (EFI_ERROR (Status)) {\r
goto DeviceFailed;\r
}\r
}\r
\r
ASSERT (Features & VIRTIO_NET_F_MAC);\r
- ASSERT (Dev->Snm.MediaPresentSupported ==\r
- !!(Features & VIRTIO_NET_F_STATUS));\r
+ ASSERT (\r
+ Dev->Snm.MediaPresentSupported ==\r
+ !!(Features & VIRTIO_NET_F_STATUS)\r
+ );\r
\r
Features &= VIRTIO_NET_F_MAC | VIRTIO_NET_F_STATUS | VIRTIO_F_VERSION_1 |\r
VIRTIO_F_IOMMU_PLATFORM;\r
//\r
if (Dev->VirtIo->Revision < VIRTIO_SPEC_REVISION (1, 0, 0)) {\r
Features &= ~(UINT64)(VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM);\r
- Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features);\r
+ Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features);\r
if (EFI_ERROR (Status)) {\r
goto ReleaseTxRing;\r
}\r
// step 6 -- virtio-net initialization complete\r
//\r
NextDevStat |= VSTAT_DRIVER_OK;\r
- Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);\r
+ Status = Dev->VirtIo->SetDeviceStatus (Dev->VirtIo, NextDevStat);\r
if (EFI_ERROR (Status)) {\r
goto ReleaseTxRing;\r
}\r