+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2006 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-Module name:\r
- decode.c\r
-\r
-Abstract:\r
-\r
-Revision history:\r
-\r
---*/\r
-\r
-// TODO: fix comment to add: Module Name: DECODE.C\r
-#include "Undi32.h"\r
-\r
-//\r
-// Global variables defined in this file\r
-//\r
-UNDI_CALL_TABLE api_table[PXE_OPCODE_LAST_VALID+1] = { \\r
- {PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,0, (UINT16)(ANY_STATE),UNDI_GetState },\\r
- {(UINT16)(DONT_CHECK),PXE_DBSIZE_NOT_USED,0,(UINT16)(ANY_STATE),UNDI_Start },\\r
- {PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,0,MUST_BE_STARTED,UNDI_Stop },\\r
- {PXE_CPBSIZE_NOT_USED,sizeof(PXE_DB_GET_INIT_INFO),0,MUST_BE_STARTED, UNDI_GetInitInfo },\\r
- {PXE_CPBSIZE_NOT_USED,sizeof(PXE_DB_GET_CONFIG_INFO),0,MUST_BE_STARTED, UNDI_GetConfigInfo },\\r
- {sizeof(PXE_CPB_INITIALIZE),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),MUST_BE_STARTED,UNDI_Initialize },\\r
- {PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED,UNDI_Reset },\\r
- {PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,0, MUST_BE_INITIALIZED,UNDI_Shutdown },\\r
- {PXE_CPBSIZE_NOT_USED,PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED,UNDI_Interrupt },\\r
- {(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_RecFilter },\\r
- {(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_StnAddr },\\r
- {PXE_CPBSIZE_NOT_USED, (UINT16)(DONT_CHECK), (UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_Statistics },\\r
- {sizeof(PXE_CPB_MCAST_IP_TO_MAC),sizeof(PXE_DB_MCAST_IP_TO_MAC), (UINT16)(DONT_CHECK),MUST_BE_INITIALIZED, UNDI_ip2mac },\\r
- {(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_NVData },\\r
- {PXE_CPBSIZE_NOT_USED,(UINT16)(DONT_CHECK),(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_Status },\\r
- {(UINT16)(DONT_CHECK),PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_FillHeader },\\r
- {(UINT16)(DONT_CHECK),PXE_DBSIZE_NOT_USED,(UINT16)(DONT_CHECK), MUST_BE_INITIALIZED, UNDI_Transmit },\\r
- {sizeof(PXE_CPB_RECEIVE),sizeof(PXE_DB_RECEIVE),0,MUST_BE_INITIALIZED, UNDI_Receive } \\r
-};\r
-\r
-//\r
-// end of global variables\r
-//\r
-\r
-VOID\r
-UNDI_GetState (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine determines the operational state of the UNDI. It updates the state flags in the\r
- Command Descriptor Block based on information derived from the AdapterInfo instance data.\r
-\r
- To ensure the command has completed successfully, CdbPtr->StatCode will contain the result of\r
- the command execution.\r
-\r
- The CdbPtr->StatFlags will contain a STOPPED, STARTED, or INITIALIZED state once the command\r
- has successfully completed.\r
-\r
- Keep in mind the AdapterInfo->State is the active state of the adapter (based on software\r
- interrogation), and the CdbPtr->StateFlags is the passed back information that is reflected\r
- to the caller of the UNDI API.\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- CdbPtr->StatFlags = (PXE_STATFLAGS) (CdbPtr->StatFlags | AdapterInfo->State);\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_Start (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine is used to change the operational state of the UNDI from stopped to started.\r
- It will do this as long as the adapter's state is PXE_STATFLAGS_GET_STATE_STOPPED, otherwise\r
- the CdbPtr->StatFlags will reflect a command failure, and the CdbPtr->StatCode will reflect the\r
- UNDI as having already been started.\r
-\r
- This routine is modified to reflect the undi 1.1 specification changes. The\r
- changes in the spec are mainly in the callback routines, the new spec adds\r
- 3 more callbacks and a unique id.\r
- Since this UNDI supports both old and new undi specifications,\r
- The NIC's data structure is filled in with the callback routines (depending\r
- on the version) pointed to in the caller's CpbPtr. This seeds the Delay,\r
- Virt2Phys, Block, and Mem_IO for old and new versions and Map_Mem, UnMap_Mem\r
- and Sync_Mem routines and a unique id variable for the new version.\r
- This is the function which an external entity (SNP, O/S, etc) would call\r
- to provide it's I/O abstraction to the UNDI.\r
-\r
- It's final action is to change the AdapterInfo->State to PXE_STATFLAGS_GET_STATE_STARTED.\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- PXE_CPB_START_30 *CpbPtr;\r
- PXE_CPB_START_31 *CpbPtr_31;\r
-\r
- //\r
- // check if it is already started.\r
- //\r
- if (AdapterInfo->State != PXE_STATFLAGS_GET_STATE_STOPPED) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_ALREADY_STARTED;\r
- return ;\r
- }\r
-\r
- if (CdbPtr->CPBsize != sizeof(PXE_CPB_START_30) &&\r
- CdbPtr->CPBsize != sizeof(PXE_CPB_START_31)) {\r
-\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
- return ;\r
- }\r
-\r
- CpbPtr = (PXE_CPB_START_30 *) (UINTN) (CdbPtr->CPBaddr);\r
- CpbPtr_31 = (PXE_CPB_START_31 *) (UINTN) (CdbPtr->CPBaddr);\r
-\r
- if (AdapterInfo->VersionFlag == 0x30) {\r
- AdapterInfo->Delay_30 = (bsptr_30) (UINTN) CpbPtr->Delay;\r
- AdapterInfo->Virt2Phys_30 = (virtphys_30) (UINTN) CpbPtr->Virt2Phys;\r
- AdapterInfo->Block_30 = (block_30) (UINTN) CpbPtr->Block;\r
- //\r
- // patch for old buggy 3.0 code:\r
- // In EFI1.0 undi used to provide the full (absolute) I/O address to the\r
- // i/o calls and SNP used to provide a callback that used GlobalIoFncs and\r
- // everything worked fine! In EFI 1.1, UNDI is not using the full\r
- // i/o or memory address to access the device, The base values for the i/o\r
- // and memory address is abstracted by the device specific PciIoFncs and\r
- // UNDI only uses the offset values. Since UNDI3.0 cannot provide any\r
- // identification to SNP, SNP cannot use nic specific PciIoFncs callback!\r
- //\r
- // To fix this and make undi3.0 work with SNP in EFI1.1 we\r
- // use a TmpMemIo function that is defined in init.c\r
- // This breaks the runtime driver feature of undi, but what to do\r
- // if we have to provide the 3.0 compatibility (including the 3.0 bugs)\r
- //\r
- // This TmpMemIo function also takes a UniqueId parameter\r
- // (as in undi3.1 design) and so initialize the UniqueId as well here\r
- // Note: AdapterInfo->Mem_Io_30 is just filled for consistency with other\r
- // parameters but never used, we only use Mem_Io field in the In/Out routines\r
- // inside e100b.c.\r
- //\r
- AdapterInfo->Mem_Io_30 = (mem_io_30) (UINTN) CpbPtr->Mem_IO;\r
- AdapterInfo->Mem_Io = (mem_io) (UINTN) TmpMemIo;\r
- AdapterInfo->Unique_ID = (UINT64) (UINTN) AdapterInfo;\r
-\r
- } else {\r
- AdapterInfo->Delay = (bsptr) (UINTN) CpbPtr_31->Delay;\r
- AdapterInfo->Virt2Phys = (virtphys) (UINTN) CpbPtr_31->Virt2Phys;\r
- AdapterInfo->Block = (block) (UINTN) CpbPtr_31->Block;\r
- AdapterInfo->Mem_Io = (mem_io) (UINTN) CpbPtr_31->Mem_IO;\r
-\r
- AdapterInfo->Map_Mem = (map_mem) (UINTN) CpbPtr_31->Map_Mem;\r
- AdapterInfo->UnMap_Mem = (unmap_mem) (UINTN) CpbPtr_31->UnMap_Mem;\r
- AdapterInfo->Sync_Mem = (sync_mem) (UINTN) CpbPtr_31->Sync_Mem;\r
- AdapterInfo->Unique_ID = CpbPtr_31->Unique_ID;\r
- }\r
-\r
- AdapterInfo->State = PXE_STATFLAGS_GET_STATE_STARTED;\r
-\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_Stop (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine is used to change the operational state of the UNDI from started to stopped.\r
- It will not do this if the adapter's state is PXE_STATFLAGS_GET_STATE_INITIALIZED, otherwise\r
- the CdbPtr->StatFlags will reflect a command failure, and the CdbPtr->StatCode will reflect the\r
- UNDI as having already not been shut down.\r
-\r
- The NIC's data structure will have the Delay, Virt2Phys, and Block, pointers zero'd out..\r
-\r
- It's final action is to change the AdapterInfo->State to PXE_STATFLAGS_GET_STATE_STOPPED.\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- if (AdapterInfo->State == PXE_STATFLAGS_GET_STATE_INITIALIZED) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_NOT_SHUTDOWN;\r
- return ;\r
- }\r
-\r
- AdapterInfo->Delay_30 = 0;\r
- AdapterInfo->Virt2Phys_30 = 0;\r
- AdapterInfo->Block_30 = 0;\r
-\r
- AdapterInfo->Delay = 0;\r
- AdapterInfo->Virt2Phys = 0;\r
- AdapterInfo->Block = 0;\r
-\r
- AdapterInfo->Map_Mem = 0;\r
- AdapterInfo->UnMap_Mem = 0;\r
- AdapterInfo->Sync_Mem = 0;\r
-\r
- AdapterInfo->State = PXE_STATFLAGS_GET_STATE_STOPPED;\r
-\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_GetInitInfo (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine is used to retrieve the initialization information that is needed by drivers and\r
- applications to initialize the UNDI. This will fill in data in the Data Block structure that is\r
- pointed to by the caller's CdbPtr->DBaddr. The fields filled in are as follows:\r
-\r
- MemoryRequired, FrameDataLen, LinkSpeeds[0-3], NvCount, NvWidth, MediaHeaderLen, HWaddrLen,\r
- MCastFilterCnt, TxBufCnt, TxBufSize, RxBufCnt, RxBufSize, IFtype, Duplex, and LoopBack.\r
-\r
- In addition, the CdbPtr->StatFlags ORs in that this NIC supports cable detection. (APRIORI knowledge)\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- PXE_DB_GET_INIT_INFO *DbPtr;\r
-\r
- DbPtr = (PXE_DB_GET_INIT_INFO *) (UINTN) (CdbPtr->DBaddr);\r
-\r
- DbPtr->MemoryRequired = MEMORY_NEEDED;\r
- DbPtr->FrameDataLen = PXE_MAX_TXRX_UNIT_ETHER;\r
- DbPtr->LinkSpeeds[0] = 10;\r
- DbPtr->LinkSpeeds[1] = 100;\r
- DbPtr->LinkSpeeds[2] = DbPtr->LinkSpeeds[3] = 0;\r
- DbPtr->NvCount = MAX_EEPROM_LEN;\r
- DbPtr->NvWidth = 4;\r
- DbPtr->MediaHeaderLen = PXE_MAC_HEADER_LEN_ETHER;\r
- DbPtr->HWaddrLen = PXE_HWADDR_LEN_ETHER;\r
- DbPtr->MCastFilterCnt = MAX_MCAST_ADDRESS_CNT;\r
-\r
- DbPtr->TxBufCnt = TX_BUFFER_COUNT;\r
- DbPtr->TxBufSize = sizeof (TxCB);\r
- DbPtr->RxBufCnt = RX_BUFFER_COUNT;\r
- DbPtr->RxBufSize = sizeof (RxFD);\r
-\r
- DbPtr->IFtype = PXE_IFTYPE_ETHERNET;\r
- DbPtr->SupportedDuplexModes = PXE_DUPLEX_ENABLE_FULL_SUPPORTED |\r
- PXE_DUPLEX_FORCE_FULL_SUPPORTED;\r
- DbPtr->SupportedLoopBackModes = PXE_LOOPBACK_INTERNAL_SUPPORTED |\r
- PXE_LOOPBACK_EXTERNAL_SUPPORTED;\r
-\r
- CdbPtr->StatFlags |= PXE_STATFLAGS_CABLE_DETECT_SUPPORTED;\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_GetConfigInfo (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine is used to retrieve the configuration information about the NIC being controlled by\r
- this driver. This will fill in data in the Data Block structure that is pointed to by the caller's CdbPtr->DBaddr.\r
- The fields filled in are as follows:\r
-\r
- DbPtr->pci.BusType, DbPtr->pci.Bus, DbPtr->pci.Device, and DbPtr->pci.\r
-\r
- In addition, the DbPtr->pci.Config.Dword[0-63] grabs a copy of this NIC's PCI configuration space.\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- UINT16 Index;\r
- PXE_DB_GET_CONFIG_INFO *DbPtr;\r
-\r
- DbPtr = (PXE_DB_GET_CONFIG_INFO *) (UINTN) (CdbPtr->DBaddr);\r
-\r
- DbPtr->pci.BusType = PXE_BUSTYPE_PCI;\r
- DbPtr->pci.Bus = AdapterInfo->Bus;\r
- DbPtr->pci.Device = AdapterInfo->Device;\r
- DbPtr->pci.Function = AdapterInfo->Function;\r
-\r
- for (Index = 0; Index < MAX_PCI_CONFIG_LEN; Index++) {\r
- DbPtr->pci.Config.Dword[Index] = AdapterInfo->Config[Index];\r
- }\r
-\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_Initialize (\r
- IN PXE_CDB *CdbPtr,\r
- NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine resets the network adapter and initializes the UNDI using the parameters supplied in\r
- the CPB. This command must be issued before the network adapter can be setup to transmit and\r
- receive packets.\r
-\r
- Once the memory requirements of the UNDI are obtained by using the GetInitInfo command, a block\r
- of non-swappable memory may need to be allocated. The address of this memory must be passed to\r
- UNDI during the Initialize in the CPB. This memory is used primarily for transmit and receive buffers.\r
-\r
- The fields CableDetect, LinkSpeed, Duplex, LoopBack, MemoryPtr, and MemoryLength are set with information\r
- that was passed in the CPB and the NIC is initialized.\r
-\r
- If the NIC initialization fails, the CdbPtr->StatFlags are updated with PXE_STATFLAGS_COMMAND_FAILED\r
- Otherwise, AdapterInfo->State is updated with PXE_STATFLAGS_GET_STATE_INITIALIZED showing the state of\r
- the UNDI is now initialized.\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- PXE_CPB_INITIALIZE *CpbPtr;\r
-\r
- if ((CdbPtr->OpFlags != PXE_OPFLAGS_INITIALIZE_DETECT_CABLE) &&\r
- (CdbPtr->OpFlags != PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE)) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
- return ;\r
- }\r
-\r
- //\r
- // check if it is already initialized\r
- //\r
- if (AdapterInfo->State == PXE_STATFLAGS_GET_STATE_INITIALIZED) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_ALREADY_INITIALIZED;\r
- return ;\r
- }\r
-\r
- CpbPtr = (PXE_CPB_INITIALIZE *) (UINTN) CdbPtr->CPBaddr;\r
-\r
- if (CpbPtr->MemoryLength < (UINT32) MEMORY_NEEDED) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CPB;\r
- return ;\r
- }\r
-\r
- //\r
- // default behaviour is to detect the cable, if the 3rd param is 1,\r
- // do not do that\r
- //\r
- AdapterInfo->CableDetect = (UINT8) ((CdbPtr->OpFlags == (UINT16) PXE_OPFLAGS_INITIALIZE_DO_NOT_DETECT_CABLE) ? (UINT8) 0 : (UINT8) 1);\r
- AdapterInfo->LinkSpeedReq = (UINT16) CpbPtr->LinkSpeed;\r
- AdapterInfo->DuplexReq = CpbPtr->DuplexMode;\r
- AdapterInfo->LoopBack = CpbPtr->LoopBackMode;\r
- AdapterInfo->MemoryPtr = CpbPtr->MemoryAddr;\r
- AdapterInfo->MemoryLength = CpbPtr->MemoryLength;\r
-\r
- CdbPtr->StatCode = (PXE_STATCODE) E100bInit (AdapterInfo);\r
-\r
- if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- } else {\r
- AdapterInfo->State = PXE_STATFLAGS_GET_STATE_INITIALIZED;\r
- }\r
-\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_Reset (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine resets the network adapter and initializes the UNDI using the parameters supplied in\r
- the CPB. The transmit and receive queues are emptied and any pending interrupts are cleared.\r
-\r
- If the NIC reset fails, the CdbPtr->StatFlags are updated with PXE_STATFLAGS_COMMAND_FAILED\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- if (CdbPtr->OpFlags != PXE_OPFLAGS_NOT_USED &&\r
- CdbPtr->OpFlags != PXE_OPFLAGS_RESET_DISABLE_INTERRUPTS &&\r
- CdbPtr->OpFlags != PXE_OPFLAGS_RESET_DISABLE_FILTERS ) {\r
-\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
- return ;\r
- }\r
-\r
- CdbPtr->StatCode = (UINT16) E100bReset (AdapterInfo, CdbPtr->OpFlags);\r
-\r
- if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- }\r
-}\r
-\r
-VOID\r
-UNDI_Shutdown (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine resets the network adapter and leaves it in a safe state for another driver to\r
- initialize. Any pending transmits or receives are lost. Receive filters and external\r
- interrupt enables are disabled. Once the UNDI has been shutdown, it can then be stopped\r
- or initialized again.\r
-\r
- If the NIC reset fails, the CdbPtr->StatFlags are updated with PXE_STATFLAGS_COMMAND_FAILED\r
-\r
- Otherwise, AdapterInfo->State is updated with PXE_STATFLAGS_GET_STATE_STARTED showing the state of\r
- the NIC as being started.\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- //\r
- // do the shutdown stuff here\r
- //\r
- CdbPtr->StatCode = (UINT16) E100bShutdown (AdapterInfo);\r
-\r
- if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- } else {\r
- AdapterInfo->State = PXE_STATFLAGS_GET_STATE_STARTED;\r
- }\r
-\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_Interrupt (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine can be used to read and/or change the current external interrupt enable\r
- settings. Disabling an external interrupt enable prevents and external (hardware)\r
- interrupt from being signaled by the network device. Internally the interrupt events\r
- can still be polled by using the UNDI_GetState command.\r
-\r
- The resulting information on the interrupt state will be passed back in the CdbPtr->StatFlags.\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- UINT8 IntMask;\r
-\r
- IntMask = (UINT8)(UINTN)(CdbPtr->OpFlags & (PXE_OPFLAGS_INTERRUPT_RECEIVE |\r
- PXE_OPFLAGS_INTERRUPT_TRANSMIT |\r
- PXE_OPFLAGS_INTERRUPT_COMMAND |\r
- PXE_OPFLAGS_INTERRUPT_SOFTWARE));\r
-\r
- switch (CdbPtr->OpFlags & PXE_OPFLAGS_INTERRUPT_OPMASK) {\r
- case PXE_OPFLAGS_INTERRUPT_READ:\r
- break;\r
-\r
- case PXE_OPFLAGS_INTERRUPT_ENABLE:\r
- if (IntMask == 0) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
- return ;\r
- }\r
-\r
- AdapterInfo->int_mask = IntMask;\r
- E100bSetInterruptState (AdapterInfo);\r
- break;\r
-\r
- case PXE_OPFLAGS_INTERRUPT_DISABLE:\r
- if (IntMask != 0) {\r
- AdapterInfo->int_mask = (UINT16) (AdapterInfo->int_mask & ~(IntMask));\r
- E100bSetInterruptState (AdapterInfo);\r
- break;\r
- }\r
-\r
- //\r
- // else fall thru.\r
- //\r
- default:\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
- return ;\r
- }\r
-\r
- if ((AdapterInfo->int_mask & PXE_OPFLAGS_INTERRUPT_RECEIVE) != 0) {\r
- CdbPtr->StatFlags |= PXE_STATFLAGS_INTERRUPT_RECEIVE;\r
-\r
- }\r
-\r
- if ((AdapterInfo->int_mask & PXE_OPFLAGS_INTERRUPT_TRANSMIT) != 0) {\r
- CdbPtr->StatFlags |= PXE_STATFLAGS_INTERRUPT_TRANSMIT;\r
-\r
- }\r
-\r
- if ((AdapterInfo->int_mask & PXE_OPFLAGS_INTERRUPT_COMMAND) != 0) {\r
- CdbPtr->StatFlags |= PXE_STATFLAGS_INTERRUPT_COMMAND;\r
-\r
- }\r
-\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_RecFilter (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine is used to read and change receive filters and, if supported, read\r
- and change multicast MAC address filter list.\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- UINT16 NewFilter;\r
- UINT16 OpFlags;\r
- PXE_DB_RECEIVE_FILTERS *DbPtr;\r
- UINT8 *MacAddr;\r
- UINTN MacCount;\r
- UINT16 Index;\r
- UINT16 copy_len;\r
- UINT8 *ptr1;\r
- UINT8 *ptr2;\r
- OpFlags = CdbPtr->OpFlags;\r
- NewFilter = (UINT16) (OpFlags & 0x1F);\r
-\r
- switch (OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_OPMASK) {\r
- case PXE_OPFLAGS_RECEIVE_FILTER_READ:\r
-\r
- //\r
- // not expecting a cpb, not expecting any filter bits\r
- //\r
- if ((NewFilter != 0) || (CdbPtr->CPBsize != 0)) {\r
- goto BadCdb;\r
-\r
- }\r
-\r
- if ((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) == 0) {\r
- goto JustRead;\r
-\r
- }\r
-\r
- NewFilter = (UINT16) (NewFilter | AdapterInfo->Rx_Filter);\r
- //\r
- // all other flags are ignored except mcast_reset\r
- //\r
- break;\r
-\r
- case PXE_OPFLAGS_RECEIVE_FILTER_ENABLE:\r
- //\r
- // there should be atleast one other filter bit set.\r
- //\r
- if (NewFilter == 0) {\r
- //\r
- // nothing to enable\r
- //\r
- goto BadCdb;\r
- }\r
-\r
- if (CdbPtr->CPBsize != 0) {\r
- //\r
- // this must be a multicast address list!\r
- // don't accept the list unless selective_mcast is set\r
- // don't accept confusing mcast settings with this\r
- //\r
- if (((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST) == 0) ||\r
- ((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) != 0) ||\r
- ((NewFilter & PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST) != 0) ||\r
- ((CdbPtr->CPBsize % sizeof (PXE_MAC_ADDR)) != 0) ) {\r
- goto BadCdb;\r
- }\r
-\r
- MacAddr = (UINT8 *) ((UINTN) (CdbPtr->CPBaddr));\r
- MacCount = CdbPtr->CPBsize / sizeof (PXE_MAC_ADDR);\r
-\r
- for (; MacCount-- != 0; MacAddr += sizeof (PXE_MAC_ADDR)) {\r
- if (MacAddr[0] != 0x01 || MacAddr[1] != 0x00 || MacAddr[2] != 0x5E || (MacAddr[3] & 0x80) != 0) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CPB;\r
- return ;\r
- }\r
- }\r
- }\r
-\r
- //\r
- // check selective mcast case enable case\r
- //\r
- if ((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST) != 0) {\r
- if (((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) != 0) ||\r
- ((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST) != 0) ) {\r
- goto BadCdb;\r
-\r
- }\r
- //\r
- // if no cpb, make sure we have an old list\r
- //\r
- if ((CdbPtr->CPBsize == 0) && (AdapterInfo->mcast_list.list_len == 0)) {\r
- goto BadCdb;\r
- }\r
- }\r
- //\r
- // if you want to enable anything, you got to have unicast\r
- // and you have what you already enabled!\r
- //\r
- NewFilter = (UINT16) (NewFilter | (PXE_OPFLAGS_RECEIVE_FILTER_UNICAST | AdapterInfo->Rx_Filter));\r
-\r
- break;\r
-\r
- case PXE_OPFLAGS_RECEIVE_FILTER_DISABLE:\r
-\r
- //\r
- // mcast list not expected, i.e. no cpb here!\r
- //\r
- if (CdbPtr->CPBsize != PXE_CPBSIZE_NOT_USED) {\r
- goto BadCdb;\r
- }\r
-\r
- NewFilter = (UINT16) ((~(CdbPtr->OpFlags & 0x1F)) & AdapterInfo->Rx_Filter);\r
-\r
- break;\r
-\r
- default:\r
- goto BadCdb;\r
- }\r
-\r
- if ((OpFlags & PXE_OPFLAGS_RECEIVE_FILTER_RESET_MCAST_LIST) != 0) {\r
- AdapterInfo->mcast_list.list_len = 0;\r
- NewFilter &= (~PXE_OPFLAGS_RECEIVE_FILTER_FILTERED_MULTICAST);\r
- }\r
-\r
- E100bSetfilter (AdapterInfo, NewFilter, CdbPtr->CPBaddr, CdbPtr->CPBsize);\r
-\r
-JustRead:\r
- //\r
- // give the current mcast list\r
- //\r
- if ((CdbPtr->DBsize != 0) && (AdapterInfo->mcast_list.list_len != 0)) {\r
- //\r
- // copy the mc list to db\r
- //\r
-\r
- DbPtr = (PXE_DB_RECEIVE_FILTERS *) (UINTN) CdbPtr->DBaddr;\r
- ptr1 = (UINT8 *) (&DbPtr->MCastList[0]);\r
-\r
- //\r
- // DbPtr->mc_count = AdapterInfo->mcast_list.list_len;\r
- //\r
- copy_len = (UINT16) (AdapterInfo->mcast_list.list_len * PXE_MAC_LENGTH);\r
-\r
- if (copy_len > CdbPtr->DBsize) {\r
- copy_len = CdbPtr->DBsize;\r
-\r
- }\r
-\r
- ptr2 = (UINT8 *) (&AdapterInfo->mcast_list.mc_list[0]);\r
- for (Index = 0; Index < copy_len; Index++) {\r
- ptr1[Index] = ptr2[Index];\r
- }\r
- }\r
- //\r
- // give the stat flags here\r
- //\r
- if (AdapterInfo->Receive_Started) {\r
- CdbPtr->StatFlags = (PXE_STATFLAGS) (CdbPtr->StatFlags | AdapterInfo->Rx_Filter);\r
-\r
- }\r
-\r
- return ;\r
-\r
-BadCdb:\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
-}\r
-\r
-VOID\r
-UNDI_StnAddr (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine is used to get the current station and broadcast MAC addresses, and to change the\r
- current station MAC address.\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- PXE_CPB_STATION_ADDRESS *CpbPtr;\r
- PXE_DB_STATION_ADDRESS *DbPtr;\r
- UINT16 Index;\r
-\r
- if (CdbPtr->OpFlags == PXE_OPFLAGS_STATION_ADDRESS_RESET) {\r
- //\r
- // configure the permanent address.\r
- // change the AdapterInfo->CurrentNodeAddress field.\r
- //\r
- if (CompareMem (\r
- &AdapterInfo->CurrentNodeAddress[0],\r
- &AdapterInfo->PermNodeAddress[0],\r
- PXE_MAC_LENGTH\r
- ) != 0) {\r
- for (Index = 0; Index < PXE_MAC_LENGTH; Index++) {\r
- AdapterInfo->CurrentNodeAddress[Index] = AdapterInfo->PermNodeAddress[Index];\r
- }\r
-\r
- E100bSetupIAAddr (AdapterInfo);\r
- }\r
- }\r
-\r
- if (CdbPtr->CPBaddr != (UINT64) 0) {\r
- CpbPtr = (PXE_CPB_STATION_ADDRESS *) (UINTN) (CdbPtr->CPBaddr);\r
- //\r
- // configure the new address\r
- //\r
- for (Index = 0; Index < PXE_MAC_LENGTH; Index++) {\r
- AdapterInfo->CurrentNodeAddress[Index] = CpbPtr->StationAddr[Index];\r
- }\r
-\r
- E100bSetupIAAddr (AdapterInfo);\r
- }\r
-\r
- if (CdbPtr->DBaddr != (UINT64) 0) {\r
- DbPtr = (PXE_DB_STATION_ADDRESS *) (UINTN) (CdbPtr->DBaddr);\r
- //\r
- // fill it with the new values\r
- //\r
- for (Index = 0; Index < PXE_MAC_LENGTH; Index++) {\r
- DbPtr->StationAddr[Index] = AdapterInfo->CurrentNodeAddress[Index];\r
- DbPtr->BroadcastAddr[Index] = AdapterInfo->BroadcastNodeAddress[Index];\r
- DbPtr->PermanentAddr[Index] = AdapterInfo->PermNodeAddress[Index];\r
- }\r
- }\r
-\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_Statistics (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine is used to read and clear the NIC traffic statistics. This command is supported only\r
- if the !PXE structure's Implementation flags say so.\r
-\r
- Results will be parsed out in the following manner:\r
- CdbPtr->DBaddr.Data[0] R Total Frames (Including frames with errors and dropped frames)\r
- CdbPtr->DBaddr.Data[1] R Good Frames (All frames copied into receive buffer)\r
- CdbPtr->DBaddr.Data[2] R Undersize Frames (Frames below minimum length for media <64 for ethernet)\r
- CdbPtr->DBaddr.Data[4] R Dropped Frames (Frames that were dropped because receive buffers were full)\r
- CdbPtr->DBaddr.Data[8] R CRC Error Frames (Frames with alignment or CRC errors)\r
- CdbPtr->DBaddr.Data[A] T Total Frames (Including frames with errors and dropped frames)\r
- CdbPtr->DBaddr.Data[B] T Good Frames (All frames copied into transmit buffer)\r
- CdbPtr->DBaddr.Data[C] T Undersize Frames (Frames below minimum length for media <64 for ethernet)\r
- CdbPtr->DBaddr.Data[E] T Dropped Frames (Frames that were dropped because of collisions)\r
- CdbPtr->DBaddr.Data[14] T Total Collision Frames (Total collisions on this subnet)\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- if ((CdbPtr->OpFlags &~(PXE_OPFLAGS_STATISTICS_RESET)) != 0) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
- return ;\r
- }\r
-\r
- if ((CdbPtr->OpFlags & PXE_OPFLAGS_STATISTICS_RESET) != 0) {\r
- //\r
- // Reset the statistics\r
- //\r
- CdbPtr->StatCode = (UINT16) E100bStatistics (AdapterInfo, 0, 0);\r
- } else {\r
- CdbPtr->StatCode = (UINT16) E100bStatistics (AdapterInfo, CdbPtr->DBaddr, CdbPtr->DBsize);\r
- }\r
-\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_ip2mac (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine is used to translate a multicast IP address to a multicast MAC address.\r
-\r
- This results in a MAC address composed of 25 bits of fixed data with the upper 23 bits of the IP\r
- address being appended to it. Results passed back in the equivalent of CdbPtr->DBaddr->MAC[0-5].\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- PXE_CPB_MCAST_IP_TO_MAC *CpbPtr;\r
- PXE_DB_MCAST_IP_TO_MAC *DbPtr;\r
- UINT8 *TmpPtr;\r
-\r
- CpbPtr = (PXE_CPB_MCAST_IP_TO_MAC *) (UINTN) CdbPtr->CPBaddr;\r
- DbPtr = (PXE_DB_MCAST_IP_TO_MAC *) (UINTN) CdbPtr->DBaddr;\r
-\r
- if ((CdbPtr->OpFlags & PXE_OPFLAGS_MCAST_IPV6_TO_MAC) != 0) {\r
- //\r
- // for now this is not supported\r
- //\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_UNSUPPORTED;\r
- return ;\r
- }\r
-\r
- TmpPtr = (UINT8 *) (&CpbPtr->IP.IPv4);\r
- //\r
- // check if the ip given is a mcast IP\r
- //\r
- if ((TmpPtr[0] & 0xF0) != 0xE0) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CPB;\r
- }\r
- //\r
- // take the last 23 bits in IP.\r
- // be very careful. accessing word on a non-word boundary will hang motherboard codenamed Big Sur\r
- // casting the mac array (in the middle) to a UINT32 pointer and accessing\r
- // the UINT32 content hung the system...\r
- //\r
- DbPtr->MAC[0] = 0x01;\r
- DbPtr->MAC[1] = 0x00;\r
- DbPtr->MAC[2] = 0x5e;\r
- DbPtr->MAC[3] = (UINT8) (TmpPtr[1] & 0x7f);\r
- DbPtr->MAC[4] = (UINT8) TmpPtr[2];\r
- DbPtr->MAC[5] = (UINT8) TmpPtr[3];\r
-\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_NVData (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine is used to read and write non-volatile storage on the NIC (if supported). The NVRAM\r
- could be EEPROM, FLASH, or battery backed RAM.\r
-\r
- This is an optional function according to the UNDI specification (or will be......)\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- PXE_DB_NVDATA *DbPtr;\r
- UINT16 Index;\r
-\r
- if ((CdbPtr->OpFlags == PXE_OPFLAGS_NVDATA_READ) != 0) {\r
-\r
- if ((CdbPtr->DBsize == PXE_DBSIZE_NOT_USED) != 0) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
- return ;\r
- }\r
-\r
- DbPtr = (PXE_DB_NVDATA *) (UINTN) CdbPtr->DBaddr;\r
-\r
- for (Index = 0; Index < MAX_PCI_CONFIG_LEN; Index++) {\r
- DbPtr->Data.Dword[Index] = AdapterInfo->NVData[Index];\r
-\r
- }\r
-\r
- } else {\r
- //\r
- // no write for now\r
- //\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_UNSUPPORTED;\r
- }\r
-\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_Status (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine returns the current interrupt status and/or the transmitted buffer addresses.\r
- If the current interrupt status is returned, pending interrupts will be acknowledged by this\r
- command. Transmitted buffer addresses that are written to the DB are removed from the transmit\r
- buffer queue.\r
-\r
- Normally, this command would be polled with interrupts disabled.\r
-\r
- The transmit buffers are returned in CdbPtr->DBaddr->TxBufer[0 - NumEntries].\r
- The interrupt status is returned in CdbPtr->StatFlags.\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- PXE_DB_GET_STATUS *DbPtr;\r
- PXE_DB_GET_STATUS TmpGetStatus;\r
- UINT16 Index;\r
- UINT16 Status;\r
- UINT16 NumEntries;\r
- RxFD *RxPtr;\r
-\r
- //\r
- // Fill in temporary GetStatus storage.\r
- //\r
- RxPtr = &AdapterInfo->rx_ring[AdapterInfo->cur_rx_ind];\r
-\r
- if ((RxPtr->cb_header.status & RX_COMPLETE) != 0) {\r
- TmpGetStatus.RxFrameLen = RxPtr->ActualCount & 0x3fff;\r
- } else {\r
- TmpGetStatus.RxFrameLen = 0;\r
- }\r
-\r
- TmpGetStatus.reserved = 0;\r
-\r
- //\r
- // Fill in size of next available receive packet and\r
- // reserved field in caller's DB storage.\r
- //\r
- DbPtr = (PXE_DB_GET_STATUS *) (UINTN) CdbPtr->DBaddr;\r
-\r
- if (CdbPtr->DBsize > 0 && CdbPtr->DBsize < sizeof (UINT32) * 2) {\r
- CopyMem (DbPtr, &TmpGetStatus, CdbPtr->DBsize);\r
- } else {\r
- CopyMem (DbPtr, &TmpGetStatus, sizeof (UINT32) * 2);\r
- }\r
-\r
- //\r
- //\r
- //\r
- if ((CdbPtr->OpFlags & PXE_OPFLAGS_GET_TRANSMITTED_BUFFERS) != 0) {\r
- //\r
- // DBsize of zero is invalid if Tx buffers are requested.\r
- //\r
- if (CdbPtr->DBsize == 0) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
- return ;\r
- }\r
-\r
- //\r
- // remember this b4 we overwrite\r
- //\r
- NumEntries = (UINT16) (CdbPtr->DBsize - sizeof (UINT64));\r
-\r
- //\r
- // We already filled in 2 UINT32s.\r
- //\r
- CdbPtr->DBsize = sizeof (UINT32) * 2;\r
-\r
- //\r
- // will claim any hanging free CBs\r
- //\r
- CheckCBList (AdapterInfo);\r
-\r
- if (AdapterInfo->xmit_done_head == AdapterInfo->xmit_done_tail) {\r
- CdbPtr->StatFlags |= PXE_STATFLAGS_GET_STATUS_TXBUF_QUEUE_EMPTY;\r
- } else {\r
- for (Index = 0; NumEntries >= sizeof (UINT64); Index++, NumEntries -= sizeof (UINT64)) {\r
- if (AdapterInfo->xmit_done_head != AdapterInfo->xmit_done_tail) {\r
- DbPtr->TxBuffer[Index] = AdapterInfo->xmit_done[AdapterInfo->xmit_done_head];\r
- AdapterInfo->xmit_done_head = next (AdapterInfo->xmit_done_head);\r
- CdbPtr->DBsize += sizeof (UINT64);\r
- } else {\r
- break;\r
- }\r
- }\r
- }\r
-\r
- if (AdapterInfo->xmit_done_head != AdapterInfo->xmit_done_tail) {\r
- CdbPtr->StatFlags |= PXE_STATFLAGS_DB_WRITE_TRUNCATED;\r
-\r
- }\r
- //\r
- // check for a receive buffer and give it's size in db\r
- //\r
- }\r
- //\r
- //\r
- //\r
- if ((CdbPtr->OpFlags & PXE_OPFLAGS_GET_INTERRUPT_STATUS) != 0) {\r
-\r
- Status = InWord (AdapterInfo, AdapterInfo->ioaddr + SCBStatus);\r
- AdapterInfo->Int_Status = (UINT16) (AdapterInfo->Int_Status | Status);\r
-\r
- //\r
- // acknoledge the interrupts\r
- //\r
- OutWord (AdapterInfo, (UINT16) (Status & 0xfc00), (UINT32) (AdapterInfo->ioaddr + SCBStatus));\r
-\r
- //\r
- // report all the outstanding interrupts\r
- //\r
- Status = AdapterInfo->Int_Status;\r
- if ((Status & SCB_STATUS_FR) != 0) {\r
- CdbPtr->StatFlags |= PXE_STATFLAGS_GET_STATUS_RECEIVE;\r
- }\r
-\r
- if ((Status & SCB_STATUS_SWI) != 0) {\r
- CdbPtr->StatFlags |= PXE_STATFLAGS_GET_STATUS_SOFTWARE;\r
- }\r
- }\r
-\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_FillHeader (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine is used to fill media header(s) in transmit packet(s).\r
- Copies the MAC address into the media header whether it is dealing\r
- with fragmented or non-fragmented packets.\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- PXE_CPB_FILL_HEADER *Cpb;\r
- PXE_CPB_FILL_HEADER_FRAGMENTED *Cpbf;\r
- EtherHeader *MacHeader;\r
- UINTN Index;\r
-\r
- if (CdbPtr->CPBsize == PXE_CPBSIZE_NOT_USED) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
- return ;\r
- }\r
-\r
- if ((CdbPtr->OpFlags & PXE_OPFLAGS_FILL_HEADER_FRAGMENTED) != 0) {\r
- Cpbf = (PXE_CPB_FILL_HEADER_FRAGMENTED *) (UINTN) CdbPtr->CPBaddr;\r
-\r
- //\r
- // assume 1st fragment is big enough for the mac header\r
- //\r
- if ((Cpbf->FragCnt == 0) || (Cpbf->FragDesc[0].FragLen < PXE_MAC_HEADER_LEN_ETHER)) {\r
- //\r
- // no buffers given\r
- //\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
- return ;\r
- }\r
-\r
- MacHeader = (EtherHeader *) (UINTN) Cpbf->FragDesc[0].FragAddr;\r
- //\r
- // we don't swap the protocol bytes\r
- //\r
- MacHeader->type = Cpbf->Protocol;\r
-\r
- for (Index = 0; Index < PXE_HWADDR_LEN_ETHER; Index++) {\r
- MacHeader->dest_addr[Index] = Cpbf->DestAddr[Index];\r
- MacHeader->src_addr[Index] = Cpbf->SrcAddr[Index];\r
- }\r
- } else {\r
- Cpb = (PXE_CPB_FILL_HEADER *) (UINTN) CdbPtr->CPBaddr;\r
-\r
- MacHeader = (EtherHeader *) (UINTN) Cpb->MediaHeader;\r
- //\r
- // we don't swap the protocol bytes\r
- //\r
- MacHeader->type = Cpb->Protocol;\r
-\r
- for (Index = 0; Index < PXE_HWADDR_LEN_ETHER; Index++) {\r
- MacHeader->dest_addr[Index] = Cpb->DestAddr[Index];\r
- MacHeader->src_addr[Index] = Cpb->SrcAddr[Index];\r
- }\r
- }\r
-\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_Transmit (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This routine is used to place a packet into the transmit queue. The data buffers given to\r
- this command are to be considered locked and the application or network driver loses\r
- ownership of these buffers and must not free or relocate them until the ownership returns.\r
-\r
- When the packets are transmitted, a transmit complete interrupt is generated (if interrupts\r
- are disabled, the transmit interrupt status is still set and can be checked using the UNDI_Status\r
- command.\r
-\r
- Some implementations and adapters support transmitting multiple packets with one transmit\r
- command. If this feature is supported, the transmit CPBs can be linked in one transmit\r
- command.\r
-\r
- All UNDIs support fragmented frames, now all network devices or protocols do. If a fragmented\r
- frame CPB is given to UNDI and the network device does not support fragmented frames\r
- (see !PXE.Implementation flag), the UNDI will have to copy the fragments into a local buffer\r
- before transmitting.\r
-\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
-\r
- if (CdbPtr->CPBsize == PXE_CPBSIZE_NOT_USED) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
- return ;\r
- }\r
-\r
- CdbPtr->StatCode = (PXE_STATCODE) E100bTransmit (AdapterInfo, CdbPtr->CPBaddr, CdbPtr->OpFlags);\r
-\r
- if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- }\r
-\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_Receive (\r
- IN PXE_CDB *CdbPtr,\r
- IN NIC_DATA_INSTANCE *AdapterInfo\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- When the network adapter has received a frame, this command is used to copy the frame\r
- into the driver/application storage location. Once a frame has been copied, it is\r
- removed from the receive queue.\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
-\r
- //\r
- // check if RU has started...\r
- //\r
- if (!AdapterInfo->Receive_Started) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_NOT_INITIALIZED;\r
- return ;\r
- }\r
-\r
-\r
- CdbPtr->StatCode = (UINT16) E100bReceive (AdapterInfo, CdbPtr->CPBaddr, CdbPtr->DBaddr);\r
- if (CdbPtr->StatCode != PXE_STATCODE_SUCCESS) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
-\r
- }\r
-\r
- return ;\r
-}\r
-\r
-VOID\r
-UNDI_APIEntry_old (\r
- IN UINT64 cdb\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This is the main SW UNDI API entry using the older nii protocol.\r
- The parameter passed in is a 64 bit flat model virtual\r
- address of the cdb. We then jump into the common routine for both old and\r
- new nii protocol entries.\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-// TODO: cdb - add argument and description to function comment\r
-{\r
- PXE_CDB *CdbPtr;\r
- NIC_DATA_INSTANCE *AdapterInfo;\r
-\r
- if (cdb == (UINT64) 0) {\r
- return ;\r
-\r
- }\r
-\r
- CdbPtr = (PXE_CDB *) (UINTN) cdb;\r
-\r
- if (CdbPtr->IFnum >= pxe->IFcnt) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
- return ;\r
- }\r
-\r
- AdapterInfo = &(UNDI32DeviceList[CdbPtr->IFnum]->NicInfo);\r
-\r
- //\r
- // entering from older entry point\r
- //\r
- AdapterInfo->VersionFlag = 0x30;\r
- UNDI_APIEntry_Common (cdb);\r
-}\r
-\r
-VOID\r
-UNDI_APIEntry_new (\r
- IN UINT64 cdb\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This is the main SW UNDI API entry using the newer nii protocol.\r
- The parameter passed in is a 64 bit flat model virtual\r
- address of the cdb. We then jump into the common routine for both old and\r
- new nii protocol entries.\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-// TODO: cdb - add argument and description to function comment\r
-{\r
- PXE_CDB *CdbPtr;\r
- NIC_DATA_INSTANCE *AdapterInfo;\r
-\r
- if (cdb == (UINT64) 0) {\r
- return ;\r
-\r
- }\r
-\r
- CdbPtr = (PXE_CDB *) (UINTN) cdb;\r
-\r
- if (CdbPtr->IFnum >= pxe_31->IFcnt) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
- return ;\r
- }\r
-\r
- AdapterInfo = &(UNDI32DeviceList[CdbPtr->IFnum]->NicInfo);\r
- //\r
- // entering from older entry point\r
- //\r
- AdapterInfo->VersionFlag = 0x31;\r
- UNDI_APIEntry_Common (cdb);\r
-}\r
-\r
-VOID\r
-UNDI_APIEntry_Common (\r
- IN UINT64 cdb\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This is the common routine for both old and new entry point procedures.\r
- The parameter passed in is a 64 bit flat model virtual\r
- address of the cdb. We then jump into the service routine pointed to by the\r
- Api_Table[OpCode].\r
-\r
-Arguments:\r
- CdbPtr - Pointer to the command descriptor block.\r
- AdapterInfo - Pointer to the NIC data structure information which the UNDI driver is layering on..\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-// TODO: cdb - add argument and description to function comment\r
-{\r
- PXE_CDB *CdbPtr;\r
- NIC_DATA_INSTANCE *AdapterInfo;\r
- UNDI_CALL_TABLE *tab_ptr;\r
-\r
- CdbPtr = (PXE_CDB *) (UINTN) cdb;\r
-\r
- //\r
- // check the OPCODE range\r
- //\r
- if ((CdbPtr->OpCode > PXE_OPCODE_LAST_VALID) ||\r
- (CdbPtr->StatCode != PXE_STATCODE_INITIALIZE) ||\r
- (CdbPtr->StatFlags != PXE_STATFLAGS_INITIALIZE) ||\r
- (CdbPtr->IFnum >= pxe_31->IFcnt) ) {\r
- goto badcdb;\r
-\r
- }\r
-\r
- if (CdbPtr->CPBsize == PXE_CPBSIZE_NOT_USED) {\r
- if (CdbPtr->CPBaddr != PXE_CPBADDR_NOT_USED) {\r
- goto badcdb;\r
- }\r
- } else if (CdbPtr->CPBaddr == PXE_CPBADDR_NOT_USED) {\r
- goto badcdb;\r
- }\r
-\r
- if (CdbPtr->DBsize == PXE_DBSIZE_NOT_USED) {\r
- if (CdbPtr->DBaddr != PXE_DBADDR_NOT_USED) {\r
- goto badcdb;\r
- }\r
- } else if (CdbPtr->DBaddr == PXE_DBADDR_NOT_USED) {\r
- goto badcdb;\r
- }\r
-\r
- //\r
- // check if cpbsize and dbsize are as needed\r
- // check if opflags are as expected\r
- //\r
- tab_ptr = &api_table[CdbPtr->OpCode];\r
-\r
- if (tab_ptr->cpbsize != (UINT16) (DONT_CHECK) && tab_ptr->cpbsize != CdbPtr->CPBsize) {\r
- goto badcdb;\r
- }\r
-\r
- if (tab_ptr->dbsize != (UINT16) (DONT_CHECK) && tab_ptr->dbsize != CdbPtr->DBsize) {\r
- goto badcdb;\r
- }\r
-\r
- if (tab_ptr->opflags != (UINT16) (DONT_CHECK) && tab_ptr->opflags != CdbPtr->OpFlags) {\r
- goto badcdb;\r
-\r
- }\r
-\r
- AdapterInfo = &(UNDI32DeviceList[CdbPtr->IFnum]->NicInfo);\r
-\r
- //\r
- // check if UNDI_State is valid for this call\r
- //\r
- if (tab_ptr->state != (UINT16) (-1)) {\r
- //\r
- // should atleast be started\r
- //\r
- if (AdapterInfo->State == PXE_STATFLAGS_GET_STATE_STOPPED) {\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_NOT_STARTED;\r
- return ;\r
- }\r
- //\r
- // check if it should be initialized\r
- //\r
- if (tab_ptr->state == 2) {\r
- if (AdapterInfo->State != PXE_STATFLAGS_GET_STATE_INITIALIZED) {\r
- CdbPtr->StatCode = PXE_STATCODE_NOT_INITIALIZED;\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- return ;\r
- }\r
- }\r
- }\r
- //\r
- // set the return variable for success case here\r
- //\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_COMPLETE;\r
- CdbPtr->StatCode = PXE_STATCODE_SUCCESS;\r
-\r
- tab_ptr->api_ptr (CdbPtr, AdapterInfo);\r
- return ;\r
- //\r
- // %% AVL - check for command linking\r
- //\r
-badcdb:\r
- CdbPtr->StatFlags = PXE_STATFLAGS_COMMAND_FAILED;\r
- CdbPtr->StatCode = PXE_STATCODE_INVALID_CDB;\r
- return ;\r
-}\r
-\r
-STATIC\r
-UINT8\r
-ChkSum (\r
- IN VOID *Buffer,\r
- IN UINT16 Len\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- This does an 8 bit check sum of the passed in buffer for Len bytes.\r
- This is primarily used to update the check sum in the SW UNDI header.\r
-\r
-Arguments:\r
- Buffer - Pointer to the passed in buffer to check sum\r
- Len - Length of buffer to be check summed in bytes.\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-{\r
- UINT8 Chksum;\r
- INT8 *Bp;\r
-\r
- Chksum = 0;\r
- if ((Bp = Buffer) != NULL) {\r
- while (Len--) {\r
- Chksum = (UINT8) (Chksum +*Bp++);\r
-\r
- }\r
-\r
- }\r
-\r
- return Chksum;\r
-}\r
-\r
-VOID\r
-PxeUpdate (\r
- IN NIC_DATA_INSTANCE *NicPtr,\r
- IN PXE_SW_UNDI *PxePtr\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- When called with a null NicPtr, this routine decrements the number of NICs\r
- this UNDI is supporting and removes the NIC_DATA_POINTER from the array.\r
- Otherwise, it increments the number of NICs this UNDI is supported and\r
- updates the pxe.Fudge to ensure a proper check sum results.\r
-\r
-Arguments:\r
- NicPtr - Pointer to the NIC data structure.\r
-\r
-Returns:\r
- None\r
-\r
---*/\r
-// TODO: PxePtr - add argument and description to function comment\r
-{\r
- if (NicPtr == NULL) {\r
- if (PxePtr->IFcnt > 0) {\r
- //\r
- // number of NICs this undi supports\r
- //\r
- PxePtr->IFcnt--;\r
- }\r
-\r
- PxePtr->Fudge = (UINT8) (PxePtr->Fudge - ChkSum ((VOID *) PxePtr, PxePtr->Len));\r
- return ;\r
- }\r
-\r
- //\r
- // number of NICs this undi supports\r
- //\r
- PxePtr->IFcnt++;\r
- PxePtr->Fudge = (UINT8) (PxePtr->Fudge - ChkSum ((VOID *) PxePtr, PxePtr->Len));\r
-\r
- return ;\r
-}\r
-\r
-VOID\r
-PxeStructInit (\r
- IN PXE_SW_UNDI *PxePtr,\r
- IN UINTN VersionFlag\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- Initialize the !PXE structure\r
-\r
-Arguments:\r
- RemainingDevicePath - Not used, always produce all possible children.\r
-\r
-Returns:\r
- EFI_SUCCESS - This driver is added to Controller.\r
- other - This driver does not support this device.\r
-\r
---*/\r
-// TODO: PxePtr - add argument and description to function comment\r
-// TODO: VersionFlag - add argument and description to function comment\r
-{\r
- //\r
- // Initialize the !PXE structure\r
- //\r
- PxePtr->Signature = PXE_ROMID_SIGNATURE;\r
- PxePtr->Len = sizeof (PXE_SW_UNDI);\r
- //\r
- // cksum\r
- //\r
- PxePtr->Fudge = 0;\r
- //\r
- // number of NICs this undi supports\r
- //\r
- PxePtr->IFcnt = 0;\r
- PxePtr->Rev = PXE_ROMID_REV;\r
- PxePtr->MajorVer = PXE_ROMID_MAJORVER;\r
- PxePtr->MinorVer = PXE_ROMID_MINORVER;\r
- PxePtr->reserved1 = 0;\r
-\r
- PxePtr->Implementation = PXE_ROMID_IMP_SW_VIRT_ADDR |\r
- PXE_ROMID_IMP_FRAG_SUPPORTED |\r
- PXE_ROMID_IMP_CMD_LINK_SUPPORTED |\r
- PXE_ROMID_IMP_NVDATA_READ_ONLY |\r
- PXE_ROMID_IMP_STATION_ADDR_SETTABLE |\r
- PXE_ROMID_IMP_PROMISCUOUS_MULTICAST_RX_SUPPORTED |\r
- PXE_ROMID_IMP_PROMISCUOUS_RX_SUPPORTED |\r
- PXE_ROMID_IMP_BROADCAST_RX_SUPPORTED |\r
- PXE_ROMID_IMP_FILTERED_MULTICAST_RX_SUPPORTED |\r
- PXE_ROMID_IMP_SOFTWARE_INT_SUPPORTED |\r
- PXE_ROMID_IMP_PACKET_RX_INT_SUPPORTED;\r
-\r
- if (VersionFlag == 0x30) {\r
- PxePtr->EntryPoint = (UINT64) UNDI_APIEntry_old;\r
- } else {\r
- PxePtr->EntryPoint = (UINT64) UNDI_APIEntry_new;\r
- PxePtr->MinorVer = PXE_ROMID_MINORVER_31;\r
- }\r
-\r
- PxePtr->reserved2[0] = 0;\r
- PxePtr->reserved2[1] = 0;\r
- PxePtr->reserved2[2] = 0;\r
- PxePtr->BusCnt = 1;\r
- PxePtr->BusType[0] = PXE_BUSTYPE_PCI;\r
-\r
- PxePtr->Fudge = (UINT8) (PxePtr->Fudge - ChkSum ((VOID *) PxePtr, PxePtr->Len));\r
-}\r
-\r