+++ /dev/null
-/** @file\r
- Implementation of reading the current interrupt status and recycled transmit\r
- buffer status from a network interface.\r
-\r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
-SPDX-License-Identifier: BSD-2-Clause-Patent\r
-\r
-**/\r
-\r
-#include "Snp.h"\r
-\r
-/**\r
- Call undi to get the status of the interrupts, get the list of recycled transmit\r
- buffers that completed transmitting. The recycled transmit buffer address will\r
- be saved into Snp->RecycledTxBuf. This function will also update the MediaPresent\r
- field of EFI_SIMPLE_NETWORK_MODE if UNDI support it.\r
-\r
- @param[in] Snp Pointer to snp driver structure.\r
- @param[out] InterruptStatusPtr A non null pointer to contain the interrupt\r
- status.\r
- @param[in] GetTransmittedBuf Set to TRUE to retrieve the recycled transmit\r
- buffer address.\r
-\r
- @retval EFI_SUCCESS The status of the network interface was retrieved.\r
- @retval EFI_DEVICE_ERROR The command could not be sent to the network\r
- interface.\r
-\r
-**/\r
-EFI_STATUS\r
-PxeGetStatus (\r
- IN SNP_DRIVER *Snp,\r
- OUT UINT32 *InterruptStatusPtr,\r
- IN BOOLEAN GetTransmittedBuf\r
- )\r
-{\r
- PXE_DB_GET_STATUS *Db;\r
- UINT16 InterruptFlags;\r
- UINT32 Index;\r
- UINT64 *Tmp;\r
-\r
- Tmp = NULL;\r
- Db = Snp->Db;\r
- Snp->Cdb.OpCode = PXE_OPCODE_GET_STATUS;\r
-\r
- Snp->Cdb.OpFlags = 0;\r
-\r
- if (GetTransmittedBuf) {\r
- Snp->Cdb.OpFlags |= PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS;\r
- ZeroMem (Db->TxBuffer, sizeof (Db->TxBuffer));\r
- }\r
-\r
- if (InterruptStatusPtr != NULL) {\r
- Snp->Cdb.OpFlags |= PXE_OPFLAGS_GET_INTERRUPT_STATUS;\r
- }\r
-\r
- if (Snp->MediaStatusSupported) {\r
- Snp->Cdb.OpFlags |= PXE_OPFLAGS_GET_MEDIA_STATUS;\r
- }\r
-\r
- Snp->Cdb.CPBsize = PXE_CPBSIZE_NOT_USED;\r
- Snp->Cdb.CPBaddr = PXE_CPBADDR_NOT_USED;\r
-\r
- Snp->Cdb.DBsize = (UINT16) sizeof (PXE_DB_GET_STATUS);\r
- Snp->Cdb.DBaddr = (UINT64)(UINTN) Db;\r
-\r
- Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
- Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
- Snp->Cdb.IFnum = Snp->IfNum;\r
- Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
-\r
- //\r
- // Issue UNDI command and check result.\r
- //\r
- DEBUG ((EFI_D_NET, "\nSnp->undi.get_status() "));\r
-\r
- (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);\r
-\r
- if (Snp->Cdb.StatCode != PXE_STATCODE_SUCCESS) {\r
- DEBUG (\r
- (EFI_D_NET,\r
- "\nSnp->undi.get_status() %xh:%xh\n",\r
- Snp->Cdb.StatFlags,\r
- Snp->Cdb.StatCode)\r
- );\r
-\r
- return EFI_DEVICE_ERROR;\r
- }\r
- //\r
- // report the values back..\r
- //\r
- if (InterruptStatusPtr != NULL) {\r
- InterruptFlags = (UINT16) (Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_INTERRUPT_MASK);\r
-\r
- *InterruptStatusPtr = 0;\r
-\r
- if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_RECEIVE) == PXE_STATFLAGS_GET_STATUS_RECEIVE) {\r
- *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT;\r
- }\r
-\r
- if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_TRANSMIT) == PXE_STATFLAGS_GET_STATUS_TRANSMIT) {\r
- *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;\r
- }\r
-\r
- if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_COMMAND) == PXE_STATFLAGS_GET_STATUS_COMMAND) {\r
- *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT;\r
- }\r
-\r
- if ((InterruptFlags & PXE_STATFLAGS_GET_STATUS_SOFTWARE) == PXE_STATFLAGS_GET_STATUS_SOFTWARE) {\r
- *InterruptStatusPtr |= EFI_SIMPLE_NETWORK_COMMAND_INTERRUPT;\r
- }\r
-\r
- }\r
-\r
- if (GetTransmittedBuf) {\r
- if ((Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_NO_TXBUFS_WRITTEN) == 0) {\r
- //\r
- // UNDI has written some transmitted buffer addresses into the DB. Store them into Snp->RecycledTxBuf.\r
- //\r
- for (Index = 0; Index < MAX_XMIT_BUFFERS; Index++) {\r
- if (Db->TxBuffer[Index] != 0) {\r
- if (Snp->RecycledTxBufCount == Snp->MaxRecycledTxBuf) {\r
- //\r
- // Snp->RecycledTxBuf is full, reallocate a new one.\r
- //\r
- if ((Snp->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT) >= SNP_MAX_TX_BUFFER_NUM) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
- Tmp = AllocatePool (sizeof (UINT64) * (Snp->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT));\r
- if (Tmp == NULL) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
- CopyMem (Tmp, Snp->RecycledTxBuf, sizeof (UINT64) * Snp->RecycledTxBufCount);\r
- FreePool (Snp->RecycledTxBuf);\r
- Snp->RecycledTxBuf = Tmp;\r
- Snp->MaxRecycledTxBuf += SNP_TX_BUFFER_INCREASEMENT;\r
- }\r
- Snp->RecycledTxBuf[Snp->RecycledTxBufCount] = Db->TxBuffer[Index];\r
- Snp->RecycledTxBufCount++;\r
- }\r
- }\r
- }\r
- }\r
-\r
- //\r
- // Update MediaPresent field of EFI_SIMPLE_NETWORK_MODE if the UNDI support\r
- // returning media status from GET_STATUS command\r
- //\r
- if (Snp->MediaStatusSupported) {\r
- Snp->Snp.Mode->MediaPresent =\r
- (BOOLEAN) (((Snp->Cdb.StatFlags & PXE_STATFLAGS_GET_STATUS_NO_MEDIA) != 0) ? FALSE : TRUE);\r
- }\r
-\r
- return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
- Reads the current interrupt status and recycled transmit buffer status from a\r
- network interface.\r
-\r
- This function gets the current interrupt and recycled transmit buffer status\r
- from the network interface. The interrupt status is returned as a bit mask in\r
- InterruptStatus. If InterruptStatus is NULL, the interrupt status will not be\r
- read. If TxBuf is not NULL, a recycled transmit buffer address will be retrieved.\r
- If a recycled transmit buffer address is returned in TxBuf, then the buffer has\r
- been successfully transmitted, and the status for that buffer is cleared. If\r
- the status of the network interface is successfully collected, EFI_SUCCESS\r
- will be returned. If the driver has not been initialized, EFI_DEVICE_ERROR will\r
- be returned.\r
-\r
- @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.\r
- @param InterruptStatus A pointer to the bit mask of the currently active\r
- interrupts (see "Related Definitions"). If this is NULL,\r
- the interrupt status will not be read from the device.\r
- If this is not NULL, the interrupt status will be read\r
- from the device. When the interrupt status is read, it\r
- will also be cleared. Clearing the transmit interrupt does\r
- not empty the recycled transmit buffer array.\r
- @param TxBuf Recycled transmit buffer address. The network interface\r
- will not transmit if its internal recycled transmit\r
- buffer array is full. Reading the transmit buffer does\r
- not clear the transmit interrupt. If this is NULL, then\r
- the transmit buffer status will not be read. If there\r
- are no transmit buffers to recycle and TxBuf is not NULL,\r
- TxBuf will be set to NULL.\r
-\r
- @retval EFI_SUCCESS The status of the network interface was retrieved.\r
- @retval EFI_NOT_STARTED The network interface has not been started.\r
- @retval EFI_INVALID_PARAMETER This parameter was NULL or did not point to a valid\r
- EFI_SIMPLE_NETWORK_PROTOCOL structure.\r
- @retval EFI_DEVICE_ERROR The command could not be sent to the network\r
- interface.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-SnpUndi32GetStatus (\r
- IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
- OUT UINT32 *InterruptStatus, OPTIONAL\r
- OUT VOID **TxBuf OPTIONAL\r
- )\r
-{\r
- SNP_DRIVER *Snp;\r
- EFI_TPL OldTpl;\r
- EFI_STATUS Status;\r
-\r
- if (This == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- if (InterruptStatus == NULL && TxBuf == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);\r
-\r
- OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
-\r
- if (Snp == NULL) {\r
- return EFI_DEVICE_ERROR;\r
- }\r
-\r
- switch (Snp->Mode.State) {\r
- case EfiSimpleNetworkInitialized:\r
- break;\r
-\r
- case EfiSimpleNetworkStopped:\r
- Status = EFI_NOT_STARTED;\r
- goto ON_EXIT;\r
-\r
- default:\r
- Status = EFI_DEVICE_ERROR;\r
- goto ON_EXIT;\r
- }\r
-\r
- if (Snp->RecycledTxBufCount == 0 && TxBuf != NULL) {\r
- Status = PxeGetStatus (Snp, InterruptStatus, TRUE);\r
- } else {\r
- Status = PxeGetStatus (Snp, InterruptStatus, FALSE);\r
- }\r
-\r
- if (TxBuf != NULL) {\r
- //\r
- // Get a recycled buf from Snp->RecycledTxBuf\r
- //\r
- if (Snp->RecycledTxBufCount == 0) {\r
- *TxBuf = NULL;\r
- } else {\r
- Snp->RecycledTxBufCount--;\r
- *TxBuf = (VOID *) (UINTN) Snp->RecycledTxBuf[Snp->RecycledTxBufCount];\r
- }\r
- }\r
-\r
-ON_EXIT:\r
- gBS->RestoreTPL (OldTpl);\r
-\r
- return Status;\r
-}\r