X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=EmbeddedPkg%2FDrivers%2FLan9118Dxe%2FLan9118Dxe.c;h=bdc390f352480bdf751c586ce950d12dc62d69f7;hp=0503dbce1e5536a95dc6b3b2ab8eb81908cce711;hb=4f0624e87a89afce8408a87997482b383e7ba131;hpb=6382e5df4e320b8b7db40bccbeccbd89d368d52f diff --git a/EmbeddedPkg/Drivers/Lan9118Dxe/Lan9118Dxe.c b/EmbeddedPkg/Drivers/Lan9118Dxe/Lan9118Dxe.c index 0503dbce1e..bdc390f352 100644 --- a/EmbeddedPkg/Drivers/Lan9118Dxe/Lan9118Dxe.c +++ b/EmbeddedPkg/Drivers/Lan9118Dxe/Lan9118Dxe.c @@ -14,7 +14,6 @@ #include "Lan9118Dxe.h" - typedef struct { MAC_ADDR_DEVICE_PATH Lan9118; EFI_DEVICE_PATH_PROTOCOL End; @@ -143,7 +142,7 @@ Lan9118DxeEntry ( // Power up the device so we can find the MAC address Status = Lan9118Initialize (Snp); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "Lan9118: Error initialising hardware\n")); + DEBUG ((EFI_D_ERROR, "LAN9118: Error initialising hardware\n")); return EFI_DEVICE_ERROR; } @@ -298,7 +297,7 @@ SnpInitialize ( } // Read the PM register - PmConf = MmioRead32 (LAN9118_PMT_CTRL); + PmConf = Lan9118MmioRead32 (LAN9118_PMT_CTRL); // MPTCTRL_WOL_EN: Allow Wake-On-Lan to detect wake up frames or magic packets // MPTCTRL_ED_EN: Allow energy detection to allow lowest power consumption mode @@ -307,9 +306,7 @@ SnpInitialize ( PmConf |= (MPTCTRL_WOL_EN | MPTCTRL_ED_EN | MPTCTRL_PME_EN); // Write the current configuration to the register - MmioWrite32 (LAN9118_PMT_CTRL, PmConf); - gBS->Stall (LAN9118_STALL); - gBS->Stall (LAN9118_STALL); + Lan9118MmioWrite32 (LAN9118_PMT_CTRL, PmConf); // Configure GPIO and HW Status = ConfigureHardware (HW_CONF_USE_LEDS, Snp); @@ -344,7 +341,7 @@ SnpInitialize ( // Do auto-negotiation if supported Status = AutoNegotiate (AUTO_NEGOTIATE_ADVERTISE_ALL, Snp); if (EFI_ERROR(Status)) { - DEBUG ((EFI_D_WARN, "Lan9118: Auto Negociation not supported.\n")); + DEBUG ((EFI_D_WARN, "LAN9118: Auto Negotiation failed.\n")); } // Configure flow control depending on speed capabilities @@ -360,7 +357,7 @@ SnpInitialize ( } // Now acknowledge all interrupts - MmioWrite32 (LAN9118_INT_STS, ~0); + Lan9118MmioWrite32 (LAN9118_INT_STS, ~0); // Declare the driver as initialized Snp->Mode->State = EfiSimpleNetworkInitialized; @@ -423,7 +420,7 @@ SnpReset ( } // Read the PM register - PmConf = MmioRead32 (LAN9118_PMT_CTRL); + PmConf = Lan9118MmioRead32 (LAN9118_PMT_CTRL); // MPTCTRL_WOL_EN: Allow Wake-On-Lan to detect wake up frames or magic packets // MPTCTRL_ED_EN: Allow energy detection to allow lowest power consumption mode @@ -431,17 +428,21 @@ SnpReset ( PmConf |= (MPTCTRL_WOL_EN | MPTCTRL_ED_EN | MPTCTRL_PME_EN); // Write the current configuration to the register - MmioWrite32 (LAN9118_PMT_CTRL, PmConf); - gBS->Stall (LAN9118_STALL); + Lan9118MmioWrite32 (LAN9118_PMT_CTRL, PmConf); + + // Reactivate the LEDs + Status = ConfigureHardware (HW_CONF_USE_LEDS, Snp); + if (EFI_ERROR (Status)) { + return Status; + } // Check that a buffer size was specified in SnpInitialize if (gTxBuffer != 0) { - HwConf = MmioRead32 (LAN9118_HW_CFG); // Read the HW register + HwConf = Lan9118MmioRead32 (LAN9118_HW_CFG); // Read the HW register HwConf &= ~HW_CFG_TX_FIFO_SIZE_MASK; // Clear buffer bits first HwConf |= HW_CFG_TX_FIFO_SIZE(gTxBuffer); // assign size chosen in SnpInitialize - MmioWrite32 (LAN9118_HW_CFG, HwConf); // Write the conf - gBS->Stall (LAN9118_STALL); + Lan9118MmioWrite32 (LAN9118_HW_CFG, HwConf); // Write the conf } // Enable the receiver and transmitter and clear their contents @@ -449,7 +450,7 @@ SnpReset ( StartTx (START_TX_MAC | START_TX_CFG | START_TX_CLEAR, Snp); // Now acknowledge all interrupts - MmioWrite32 (LAN9118_INT_STS, ~0); + Lan9118MmioWrite32 (LAN9118_INT_STS, ~0); return EFI_SUCCESS; } @@ -696,7 +697,6 @@ SnpReceiveFilters ( // Write the options to the MAC_CSR // IndirectMACWrite32 (INDIRECT_MAC_INDEX_CR, MacCSRValue); - gBS->Stall (LAN9118_STALL); // // If we have to retrieve something, start packet reception. @@ -763,7 +763,7 @@ SnpStationAddress ( New = (EFI_MAC_ADDRESS *) PermAddr; Lan9118SetMacAddress ((EFI_MAC_ADDRESS *) PermAddr, Snp); } else { - DEBUG ((EFI_D_ERROR, "Lan9118: Warning: No valid MAC address in EEPROM, using fallback\n")); + DEBUG ((EFI_D_ERROR, "LAN9118: Warning: No valid MAC address in EEPROM, using fallback\n")); New = (EFI_MAC_ADDRESS*) (FixedPcdGet64 (PcdLan9118DefaultMacAddress)); } } else { @@ -991,12 +991,12 @@ SnpGetStatus ( // consumer of SNP does not call GetStatus.) // TODO will we lose TxStatuses if this happens? Maybe in SnpTransmit we // should check for it and dump the TX Status FIFO. - FifoInt = MmioRead32 (LAN9118_FIFO_INT); + FifoInt = Lan9118MmioRead32 (LAN9118_FIFO_INT); // Clear the TX Status FIFO Overflow if ((FifoInt & INSTS_TXSO) == 0) { FifoInt |= INSTS_TXSO; - MmioWrite32 (LAN9118_FIFO_INT, FifoInt); + Lan9118MmioWrite32 (LAN9118_FIFO_INT, FifoInt); } // Read interrupt status if IrqStat is not NULL @@ -1004,30 +1004,30 @@ SnpGetStatus ( *IrqStat = 0; // Check for receive interrupt - if (MmioRead32 (LAN9118_INT_STS) & INSTS_RSFL) { // Data moved from rx FIFO + if (Lan9118MmioRead32 (LAN9118_INT_STS) & INSTS_RSFL) { // Data moved from rx FIFO *IrqStat |= EFI_SIMPLE_NETWORK_RECEIVE_INTERRUPT; - MmioWrite32 (LAN9118_INT_STS,INSTS_RSFL); + Lan9118MmioWrite32 (LAN9118_INT_STS,INSTS_RSFL); } // Check for transmit interrupt - if (MmioRead32 (LAN9118_INT_STS) & INSTS_TSFL) { + if (Lan9118MmioRead32 (LAN9118_INT_STS) & INSTS_TSFL) { *IrqStat |= EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT; - MmioWrite32 (LAN9118_INT_STS,INSTS_TSFL); + Lan9118MmioWrite32 (LAN9118_INT_STS,INSTS_TSFL); } // Check for software interrupt - if (MmioRead32 (LAN9118_INT_STS) & INSTS_SW_INT) { + if (Lan9118MmioRead32 (LAN9118_INT_STS) & INSTS_SW_INT) { *IrqStat |= EFI_SIMPLE_NETWORK_SOFTWARE_INTERRUPT; - MmioWrite32 (LAN9118_INT_STS,INSTS_SW_INT); + Lan9118MmioWrite32 (LAN9118_INT_STS,INSTS_SW_INT); } } // Check Status of transmitted packets // (We ignore TXSTATUS_NO_CA has it might happen in Full Duplex) - NumTxStatusEntries = MmioRead32(LAN9118_TX_FIFO_INF) & TXFIFOINF_TXSUSED_MASK; + NumTxStatusEntries = Lan9118MmioRead32(LAN9118_TX_FIFO_INF) & TXFIFOINF_TXSUSED_MASK; if (NumTxStatusEntries > 0) { - TxStatus = MmioRead32 (LAN9118_TX_STATUS); + TxStatus = Lan9118MmioRead32 (LAN9118_TX_STATUS); PacketTag = TxStatus >> 16; TxStatus = TxStatus & 0xFFFF; if ((TxStatus & TXSTATUS_ES) && (TxStatus != (TXSTATUS_ES | TXSTATUS_NO_CA))) { @@ -1055,26 +1055,37 @@ SnpGetStatus ( LanDriver->Stats.TxTotalFrames += 1; *TxBuff = LanDriver->TxRing[PacketTag % LAN9118_TX_RING_NUM_ENTRIES]; } + } else if (TxBuff != NULL) { + *TxBuff = NULL; } // Check for a TX Error interrupt - Interrupts = MmioRead32 (LAN9118_INT_STS); + Interrupts = Lan9118MmioRead32 (LAN9118_INT_STS); if (Interrupts & INSTS_TXE) { DEBUG ((EFI_D_ERROR, "LAN9118: Transmitter error. Restarting...")); - // Initiate a software reset + // Software reset, the TXE interrupt is cleared by the reset. Status = SoftReset (0, Snp); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "\n\tSoft Reset Failed: Hardware Error\n")); return EFI_DEVICE_ERROR; } - // Acknowledge the TXE - MmioWrite32 (LAN9118_INT_STS, INSTS_TXE); - gBS->Stall (LAN9118_STALL); + // Reactivate the LEDs + Status = ConfigureHardware (HW_CONF_USE_LEDS, Snp); + if (EFI_ERROR (Status)) { + return Status; + } - // Restart the transmitter + // + // Restart the transmitter and if necessary the receiver. + // Do not ask for FIFO reset as it has already been done + // by SoftReset(). + // StartTx (START_TX_MAC | START_TX_CFG, Snp); + if (Snp->Mode->ReceiveFilterSetting != 0) { + StartRx (0, Snp); + } } // Update the media status @@ -1207,25 +1218,25 @@ SnpTransmit ( CommandB = TX_CMD_B_PACKET_TAG (PacketTag) | TX_CMD_B_PACKET_LENGTH (BuffSize); // Write the commands first - MmioWrite32 (LAN9118_TX_DATA, CommandA); - MmioWrite32 (LAN9118_TX_DATA, CommandB); + Lan9118MmioWrite32 (LAN9118_TX_DATA, CommandA); + Lan9118MmioWrite32 (LAN9118_TX_DATA, CommandB); // Write the destination address - MmioWrite32 (LAN9118_TX_DATA, + Lan9118MmioWrite32 (LAN9118_TX_DATA, (DstAddr->Addr[0]) | (DstAddr->Addr[1] << 8) | (DstAddr->Addr[2] << 16) | (DstAddr->Addr[3] << 24) ); - MmioWrite32 (LAN9118_TX_DATA, + Lan9118MmioWrite32 (LAN9118_TX_DATA, (DstAddr->Addr[4]) | (DstAddr->Addr[5] << 8) | (SrcAddr->Addr[0] << 16) | // Write the Source Address (SrcAddr->Addr[1] << 24) ); - MmioWrite32 (LAN9118_TX_DATA, + Lan9118MmioWrite32 (LAN9118_TX_DATA, (SrcAddr->Addr[2]) | (SrcAddr->Addr[3] << 8) | (SrcAddr->Addr[4] << 16) | @@ -1233,18 +1244,18 @@ SnpTransmit ( ); // Write the Protocol - MmioWrite32 (LAN9118_TX_DATA, (UINT32)(HTONS (LocalProtocol))); + Lan9118MmioWrite32 (LAN9118_TX_DATA, (UINT32)(HTONS (LocalProtocol))); // Next buffer is the payload CommandA = TX_CMD_A_LAST_SEGMENT | TX_CMD_A_BUFF_SIZE (BuffSize - HdrSize) | TX_CMD_A_COMPLETION_INT | TX_CMD_A_DATA_START_OFFSET (2); // 2 bytes beginning offset // Write the commands - MmioWrite32 (LAN9118_TX_DATA, CommandA); - MmioWrite32 (LAN9118_TX_DATA, CommandB); + Lan9118MmioWrite32 (LAN9118_TX_DATA, CommandA); + Lan9118MmioWrite32 (LAN9118_TX_DATA, CommandB); // Write the payload for (Count = 0; Count < ((BuffSize + 3) >> 2) - 3; Count++) { - MmioWrite32 (LAN9118_TX_DATA, LocalData[Count + 3]); + Lan9118MmioWrite32 (LAN9118_TX_DATA, LocalData[Count + 3]); } } else { // Format pointer @@ -1255,12 +1266,12 @@ SnpTransmit ( CommandB = TX_CMD_B_PACKET_TAG (PacketTag) | TX_CMD_B_PACKET_LENGTH (BuffSize); // Write the commands first - MmioWrite32 (LAN9118_TX_DATA, CommandA); - MmioWrite32 (LAN9118_TX_DATA, CommandB); + Lan9118MmioWrite32 (LAN9118_TX_DATA, CommandA); + Lan9118MmioWrite32 (LAN9118_TX_DATA, CommandB); // Write all the data for (Count = 0; Count < ((BuffSize + 3) >> 2); Count++) { - MmioWrite32 (LAN9118_TX_DATA, LocalData[Count]); + Lan9118MmioWrite32 (LAN9118_TX_DATA, LocalData[Count]); } } @@ -1297,6 +1308,7 @@ SnpReceive ( ) { LAN9118_DRIVER *LanDriver; + UINT32 IntSts; UINT32 RxFifoStatus; UINT32 NumPackets; UINT32 RxCfgValue; @@ -1331,8 +1343,29 @@ SnpReceive ( return EFI_NOT_STARTED; } + // + // If the receiver raised the RXE error bit, check if the receiver status + // FIFO is full and if not just acknowledge the error. The two other + // conditions to get a RXE error are : + // . the RX data FIFO is read whereas being empty. + // . the RX status FIFO is read whereas being empty. + // The RX data and status FIFO are read by this driver only in the following + // code of this function. After the readings, the RXE error bit is checked + // and if raised, the controller is reset. Thus, at this point, we consider + // that the only valid reason to get an RXE error is the receiver status + // FIFO being full. And if this is not the case, we consider that this is + // a spurious error and we just get rid of it. We experienced such 'spurious' + // errors when running the driver on an A57 on Juno. No valid reason to + // explain those errors has been found so far and everything seems to + // work perfectly when they are just ignored. + // + IntSts = Lan9118MmioRead32 (LAN9118_INT_STS); + if ((IntSts & INSTS_RXE) && (!(IntSts & INSTS_RSFF))) { + Lan9118MmioWrite32 (LAN9118_INT_STS, INSTS_RXE); + } + // Count dropped frames - DroppedFrames = MmioRead32 (LAN9118_RX_DROP); + DroppedFrames = Lan9118MmioRead32 (LAN9118_RX_DROP); LanDriver->Stats.RxDroppedFrames += DroppedFrames; NumPackets = RxStatusUsedSpace (0, Snp) / 4; @@ -1341,7 +1374,7 @@ SnpReceive ( } // Read Rx Status (only if not empty) - RxFifoStatus = MmioRead32 (LAN9118_RX_STATUS); + RxFifoStatus = Lan9118MmioRead32 (LAN9118_RX_STATUS); LanDriver->Stats.RxTotalFrames += 1; // First check for errors @@ -1397,12 +1430,6 @@ SnpReceive ( PLength = GET_RXSTATUS_PACKET_LENGTH(RxFifoStatus); LanDriver->Stats.RxTotalBytes += (PLength - 4); - // Check buffer size - if (*BuffSize < PLength) { - *BuffSize = PLength; - return EFI_BUFFER_TOO_SMALL; - } - // If padding is applied, read more DWORDs if (PLength % 4) { Padding = 4 - (PLength % 4); @@ -1412,15 +1439,21 @@ SnpReceive ( Padding = 0; } + // Check buffer size + if (*BuffSize < (PLength + Padding)) { + *BuffSize = PLength + Padding; + return EFI_BUFFER_TOO_SMALL; + } + // Set the amount of data to be transfered out of FIFO for THIS packet // This can be used to trigger an interrupt, and status can be checked - RxCfgValue = MmioRead32 (LAN9118_RX_CFG); + RxCfgValue = Lan9118MmioRead32 (LAN9118_RX_CFG); RxCfgValue &= ~(RXCFG_RX_DMA_CNT_MASK); RxCfgValue |= RXCFG_RX_DMA_CNT (ReadLimit); // Set end alignment to 4-bytes RxCfgValue &= ~(RXCFG_RX_END_ALIGN_MASK); - MmioWrite32 (LAN9118_RX_CFG, RxCfgValue); + Lan9118MmioWrite32 (LAN9118_RX_CFG, RxCfgValue); // Update buffer size *BuffSize = PLength; // -4 bytes may be needed: Received in buffer as @@ -1435,29 +1468,7 @@ SnpReceive ( // Read Rx Packet for (Count = 0; Count < ReadLimit; Count++) { - RawData[Count] = MmioRead32 (LAN9118_RX_DATA); - } - - // Check for Rx errors (worst possible error) - if (MmioRead32 (LAN9118_INT_STS) & INSTS_RXE) { - DEBUG ((EFI_D_WARN, "Warning: Receiver Error. Restarting...\n")); - - // Initiate a software reset - Status = SoftReset (0, Snp); - if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "Error: Soft Reset Failed: Hardware Error.\n")); - return EFI_DEVICE_ERROR; - } - - // Acknowledge the RXE - MmioWrite32 (LAN9118_INT_STS, INSTS_RXE); - gBS->Stall (LAN9118_STALL); - - // Restart the rx (and do not clear FIFO) - StartRx (0, Snp); - - // Say that command could not be sent - return EFI_DEVICE_ERROR; + RawData[Count] = Lan9118MmioRead32 (LAN9118_RX_DATA); } // Get the destination address @@ -1479,7 +1490,7 @@ SnpReceive ( Src.Addr[3] = (RawData[2] & 0xFF00) >> 8; Src.Addr[4] = (RawData[2] & 0xFF0000) >> 16; Src.Addr[5] = (RawData[2] & 0xFF000000) >> 24; - CopyMem (SrcAddr,&Src, NET_ETHER_ADDR_LEN); + CopyMem (SrcAddr, &Src, NET_ETHER_ADDR_LEN); } // Get the protocol @@ -1487,6 +1498,34 @@ SnpReceive ( *Protocol = NTOHS (RawData[3] & 0xFFFF); } + // Check for Rx errors (worst possible error) + if (Lan9118MmioRead32 (LAN9118_INT_STS) & INSTS_RXE) { + DEBUG ((EFI_D_WARN, "Warning: Receiver Error. Restarting...\n")); + + // Software reset, the RXE interrupt is cleared by the reset. + Status = SoftReset (0, Snp); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "Error: Soft Reset Failed: Hardware Error.\n")); + return EFI_DEVICE_ERROR; + } + + // Reactivate the LEDs + Status = ConfigureHardware (HW_CONF_USE_LEDS, Snp); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Restart the receiver and the transmitter without resetting the FIFOs + // as it has been done by SoftReset(). + // + StartRx (0, Snp); + StartTx (START_TX_MAC | START_TX_CFG, Snp); + + // Say that command could not be sent + return EFI_DEVICE_ERROR; + } + #if defined(EVAL_PERFORMANCE) UINT64 EndClock = GetPerformanceCounter (); DEBUG ((EFI_D_ERROR, "Receive Time processing: %d counts @ %d Hz\n", StartClock - EndClock,Perf));