123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- /** @file
- *
- * Copyright (c) 2015, Hisilicon Limited. All rights reserved.
- * Copyright (c) 2015, Linaro Limited. All rights reserved.
- *
- * This program and the accompanying materials
- * are licensed and made available under the terms and conditions of the BSD License
- * which accompanies this distribution. The full text of the license may be found at
- * http://opensource.org/licenses/bsd-license.php
- *
- * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
- *
- **/
- #include <Uefi.h>
- #include <Library/IoLib.h>
- #include <Library/DebugLib.h>
- #include <Library/TimerLib.h>
- #include <Library/UefiBootServicesTableLib.h>
- #include <Protocol/HisiBoardNicProtocol.h>
- #include <Library/I2CLib.h>
- #include <OemNicConfig.h>
- #define EEPROM_I2C_PORT 7
- EFI_STATUS
- EFIAPI OemGetMac (IN OUT EFI_MAC_ADDRESS *Mac, IN UINTN Port);
- EFI_STATUS
- EFIAPI OemSetMac (IN EFI_MAC_ADDRESS *Mac, IN UINTN Port);
- HISI_BOARD_NIC_PROTOCOL mOemNicProtocol = {
- .GetMac = OemGetMac,
- .SetMac = OemSetMac,
- };
- EFI_STATUS OemGetMacE2prom(IN UINT32 Port, OUT UINT8 *pucAddr)
- {
- I2C_DEVICE stI2cDev = {0};
- EFI_STATUS Status;
- UINT16 I2cOffset;
- Status = I2CInit(0, EEPROM_I2C_PORT, Normal);
- if (EFI_ERROR(Status))
- {
- DEBUG((EFI_D_ERROR, "[%a]:[%dL] Call I2CInit failed! p1=0x%x.\n", __FUNCTION__, __LINE__, Status));
- return Status;
- }
- I2cOffset = I2C_OFFSET_EEPROM_ETH0 + (Port * 6);
- stI2cDev.DeviceType = DEVICE_TYPE_E2PROM;
- stI2cDev.Port = EEPROM_I2C_PORT;
- stI2cDev.SlaveDeviceAddress = I2C_SLAVEADDR_EEPROM;
- stI2cDev.Socket = 0;
- Status = I2CRead(&stI2cDev, I2cOffset, 6, pucAddr);
- if (EFI_ERROR(Status))
- {
- DEBUG((EFI_D_ERROR, "[%a]:[%dL] Call I2cRead failed! p1=0x%x.\n", __FUNCTION__, __LINE__, Status));
- return Status;
- }
- return EFI_SUCCESS;
- }
- EFI_STATUS OemSetMacE2prom(IN UINT32 Port, IN UINT8 *pucAddr)
- {
- I2C_DEVICE stI2cDev = {0};
- EFI_STATUS Status;
- UINT16 I2cOffset;
- Status = I2CInit(0, EEPROM_I2C_PORT, Normal);
- if (EFI_ERROR(Status))
- {
- DEBUG((EFI_D_ERROR, "[%a]:[%dL] Call I2CInit failed! p1=0x%x.\n", __FUNCTION__, __LINE__, Status));
- return Status;
- }
- I2cOffset = I2C_OFFSET_EEPROM_ETH0 + (Port * 6);
- stI2cDev.DeviceType = DEVICE_TYPE_E2PROM;
- stI2cDev.Port = EEPROM_I2C_PORT;
- stI2cDev.SlaveDeviceAddress = I2C_SLAVEADDR_EEPROM;
- stI2cDev.Socket = 0;
- Status = I2CWrite(&stI2cDev, I2cOffset, 6, pucAddr);
- if (EFI_ERROR(Status))
- {
- DEBUG((EFI_D_ERROR, "[%a]:[%dL] Call I2cWrite failed! p1=0x%x.\n", __FUNCTION__, __LINE__, Status));
- return Status;
- }
- return EFI_SUCCESS;
- }
- EFI_STATUS
- EFIAPI OemGetMac (
- IN OUT EFI_MAC_ADDRESS *Mac,
- IN UINTN Port
- )
- {
- EFI_STATUS Status;
- if (NULL == Mac)
- {
- DEBUG((EFI_D_ERROR, "[%a]:[%dL] Mac buffer is null!\n", __FUNCTION__, __LINE__));
- return EFI_INVALID_PARAMETER;
- }
- //TODO: discard port number, only support one port
- // Only 6 bytes are used
- Status = OemGetMacE2prom(Port, Mac->Addr);
- if ((EFI_ERROR(Status)))
- {
- DEBUG((EFI_D_ERROR, "[%a]:[%dL] Get mac failed!\n", __FUNCTION__, __LINE__));
- return Status;
- }
- return EFI_SUCCESS;
- }
- EFI_STATUS
- EFIAPI OemSetMac (
- IN EFI_MAC_ADDRESS *Mac,
- IN UINTN Port
- )
- {
- EFI_STATUS Status;
- if (NULL == Mac)
- {
- DEBUG((EFI_D_ERROR, "[%a]:[%dL] Mac buffer is null!\n", __FUNCTION__, __LINE__));
- return EFI_INVALID_PARAMETER;
- }
- Status = OemSetMacE2prom(Port, Mac->Addr);
- if ((EFI_ERROR(Status)))
- {
- DEBUG((EFI_D_ERROR, "[%a]:[%dL] Set mac failed!\n", __FUNCTION__, __LINE__));
- return Status;
- }
- return EFI_SUCCESS;
- }
- EFI_STATUS
- EFIAPI
- OemNicConfigEntry (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
- {
- EFI_STATUS Status;
- Status = gBS->InstallProtocolInterface(
- &ImageHandle,
- &gHisiBoardNicProtocolGuid,
- EFI_NATIVE_INTERFACE,
- &mOemNicProtocol
- );
- if(EFI_ERROR(Status))
- {
- DEBUG((EFI_D_ERROR, "[%a]:[%dL] Install Protocol failed %r\n", __FUNCTION__, __LINE__, Status));
- return Status;
- }
- return EFI_SUCCESS;
- }
|