Re: [edk2] [PATCH edk2-platforms v4 19/31] Platform/Hisilicon/D06: Add OemNicLib
On Fri, Aug 24, 2018 at 12:07:31AM +0800, Ming Huang wrote: > OemNicLib provide nic related api like GetMac,SetMac. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ming Huang > --- > Platform/Hisilicon/D06/D06.dsc | 1 + > Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.inf | 35 ++ > Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.c | 570 > > 3 files changed, 606 insertions(+) > > diff --git a/Platform/Hisilicon/D06/D06.dsc b/Platform/Hisilicon/D06/D06.dsc > index 06249d8a5b..e18badf3b3 100644 > --- a/Platform/Hisilicon/D06/D06.dsc > +++ b/Platform/Hisilicon/D06/D06.dsc > @@ -90,6 +90,7 @@ > >LpcLib|Silicon/Hisilicon/Hi1620/Library/LpcLibHi1620/LpcLib.inf > > SerialPortLib|ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.inf > + OemNicLib|Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.inf > !if $(SECURE_BOOT_ENABLE) == TRUE >FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf > !endif > diff --git a/Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.inf > b/Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.inf > new file mode 100644 > index 00..3b0bd2d60c > --- /dev/null > +++ b/Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.inf > @@ -0,0 +1,35 @@ > +#/** @file > +# > +#Copyright (c) 2018, Hisilicon Limited. All rights reserved. > +#Copyright (c) 2017, 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. > +# > +#**/ > + > +[Defines] > + INF_VERSION= 0x0001001A > + BASE_NAME = OemNicLib > + FILE_GUID = 520F872C-FFCF-4EF3-AC01-85BDB0816DCE > + MODULE_TYPE= BASE > + VERSION_STRING = 1.0 > + LIBRARY_CLASS = OemNicLib > + > +[Sources.common] > + OemNicLib.c > + > +[Packages] > + ArmPkg/ArmPkg.dec > + MdeModulePkg/MdeModulePkg.dec > + MdePkg/MdePkg.dec > + Silicon/Hisilicon/HisiPkg.dec > + > +[LibraryClasses] > + CpldIoLib > + I2CLib > diff --git a/Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.c > b/Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.c > new file mode 100644 > index 00..6ecf9c8f0a > --- /dev/null > +++ b/Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.c > @@ -0,0 +1,570 @@ > +/** @file > +* > +* Copyright (c) 2018, Hisilicon Limited. All rights reserved. > +* Copyright (c) 2017, 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 > +#include > +#include > +#include > +#include > +#include > + > +#define CPU2_SFP2_100G_CARD_OFFSET 0x25 > +#define CPU1_SFP1_LOCATE_OFFSET 0x16 > +#define CPU1_SFP0_LOCATE_OFFSET 0x12 > +#define CPU2_SFP1_LOCATE_OFFSET 0x21 > +#define CPU2_SFP0_LOCATE_OFFSET 0x19 > +#define CPU2_SFP2_10G_GE_CARD_OFFSET 0x25 > + > +#define SFP_10G_SPEED 10 > +#define SFP_25G_SPEED 25 > +#define SFP_100G_SPEED 100 > +#define SFP_GE_SPEED1 > + > +#define SFP_GE_SPEED_VAL_VENDOR_FINISAR 0x0C > +#define SFP_GE_SPEED_VAL0x0D > +#define SFP_10G_SPEED_VAL 0x67 > +#define SFP_25G_SPEED_VAL 0xFF > + > +#define CARD_PRESENT_100G (BIT7) > +#define CARD_PRESENT_10G(BIT0) > +#define SELECT_SFP_BY_INDEX(index) (1 << (index - 1)) > +#define SPF_SPEED_OFFSET12 > + > +#define SFP_DEVICE_ADDRESS 0x50 > +#define CPU1_9545_I2C_ADDR 0x70 > +#define CPU2_9545_I2C_ADDR 0x71 > + > +#define FIBER_PRESENT 0 > +#define CARD_PRESENT 1 > +#define I2C_PORT_SFP 4 > +#define CPU2_I2C_PORT_SFP 5 > + > +#define SOCKET_0 0 > +#define SOCKET_1 1 > +#define EEPROM_I2C_PORT 4 > +#define EEPROM_PAGE_SIZE 0x40 > +#define MAC_ADDR_LEN 6 > +#define I2C_OFFSET_EEPROM_ETH0 (0xc00) > +#define I2C_SLAVEADDR_EEPROM (0x52) > + > +#pragma pack(1) > +typedef struct { > + UINT16 Crc16; > + UINT16 MacLen; > + UINT8 Mac[MAC_ADDR_LEN]; > +} NIC_MAC_ADDRESS; > +#pragma pack() > + > +ETH_PRODUCT_DESC
[edk2] [PATCH edk2-platforms v4 19/31] Platform/Hisilicon/D06: Add OemNicLib
OemNicLib provide nic related api like GetMac,SetMac. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ming Huang --- Platform/Hisilicon/D06/D06.dsc | 1 + Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.inf | 35 ++ Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.c | 570 3 files changed, 606 insertions(+) diff --git a/Platform/Hisilicon/D06/D06.dsc b/Platform/Hisilicon/D06/D06.dsc index 06249d8a5b..e18badf3b3 100644 --- a/Platform/Hisilicon/D06/D06.dsc +++ b/Platform/Hisilicon/D06/D06.dsc @@ -90,6 +90,7 @@ LpcLib|Silicon/Hisilicon/Hi1620/Library/LpcLibHi1620/LpcLib.inf SerialPortLib|ArmPlatformPkg/Library/PL011SerialPortLib/PL011SerialPortLib.inf + OemNicLib|Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.inf !if $(SECURE_BOOT_ENABLE) == TRUE FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf !endif diff --git a/Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.inf b/Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.inf new file mode 100644 index 00..3b0bd2d60c --- /dev/null +++ b/Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.inf @@ -0,0 +1,35 @@ +#/** @file +# +#Copyright (c) 2018, Hisilicon Limited. All rights reserved. +#Copyright (c) 2017, 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. +# +#**/ + +[Defines] + INF_VERSION= 0x0001001A + BASE_NAME = OemNicLib + FILE_GUID = 520F872C-FFCF-4EF3-AC01-85BDB0816DCE + MODULE_TYPE= BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = OemNicLib + +[Sources.common] + OemNicLib.c + +[Packages] + ArmPkg/ArmPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + Silicon/Hisilicon/HisiPkg.dec + +[LibraryClasses] + CpldIoLib + I2CLib diff --git a/Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.c b/Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.c new file mode 100644 index 00..6ecf9c8f0a --- /dev/null +++ b/Platform/Hisilicon/D06/Library/OemNicLib/OemNicLib.c @@ -0,0 +1,570 @@ +/** @file +* +* Copyright (c) 2018, Hisilicon Limited. All rights reserved. +* Copyright (c) 2017, 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 +#include +#include +#include +#include +#include + +#define CPU2_SFP2_100G_CARD_OFFSET 0x25 +#define CPU1_SFP1_LOCATE_OFFSET 0x16 +#define CPU1_SFP0_LOCATE_OFFSET 0x12 +#define CPU2_SFP1_LOCATE_OFFSET 0x21 +#define CPU2_SFP0_LOCATE_OFFSET 0x19 +#define CPU2_SFP2_10G_GE_CARD_OFFSET 0x25 + +#define SFP_10G_SPEED 10 +#define SFP_25G_SPEED 25 +#define SFP_100G_SPEED 100 +#define SFP_GE_SPEED1 + +#define SFP_GE_SPEED_VAL_VENDOR_FINISAR 0x0C +#define SFP_GE_SPEED_VAL0x0D +#define SFP_10G_SPEED_VAL 0x67 +#define SFP_25G_SPEED_VAL 0xFF + +#define CARD_PRESENT_100G (BIT7) +#define CARD_PRESENT_10G(BIT0) +#define SELECT_SFP_BY_INDEX(index) (1 << (index - 1)) +#define SPF_SPEED_OFFSET12 + +#define SFP_DEVICE_ADDRESS 0x50 +#define CPU1_9545_I2C_ADDR 0x70 +#define CPU2_9545_I2C_ADDR 0x71 + +#define FIBER_PRESENT 0 +#define CARD_PRESENT 1 +#define I2C_PORT_SFP 4 +#define CPU2_I2C_PORT_SFP 5 + +#define SOCKET_0 0 +#define SOCKET_1 1 +#define EEPROM_I2C_PORT 4 +#define EEPROM_PAGE_SIZE 0x40 +#define MAC_ADDR_LEN 6 +#define I2C_OFFSET_EEPROM_ETH0 (0xc00) +#define I2C_SLAVEADDR_EEPROM (0x52) + +#pragma pack(1) +typedef struct { + UINT16 Crc16; + UINT16 MacLen; + UINT8 Mac[MAC_ADDR_LEN]; +} NIC_MAC_ADDRESS; +#pragma pack() + +ETH_PRODUCT_DESC gEthPdtDesc[ETH_MAX_PORT] = +{ +{TRUE, ETH_SPEED_10KM, ETH_FULL_DUPLEX, ETH_INVALID, ETH_INVALID}, +{TRUE, ETH_SPEED_10KM, ETH_FULL_DUPLEX, ETH_INVALID, ETH_INVALID}, +{FALSE, ETH_INVALID, ETH_INVALID, ETH_INVALID, ETH_INVALID}, +{FALSE, ETH_INVALID, ETH_INVALID, ETH_INVALID, ETH_INVALID}, +{TRUE, ETH_SPEED_1000M,