add a new platform Lenovo ne2572

This commit is contained in:
cfeng111
2019-01-28 11:54:40 +08:00
parent fd26e64966
commit 601ccd7956
47 changed files with 6398 additions and 58 deletions

View File

@@ -61,9 +61,9 @@
#define FAN1_EEPROM_BUS 21
#define FAN_EEPROM_ADDR 0x57
#define FAN_MODEL_OFFSET 0x67
#define FAN_MODEL_LENGTH 12
#define FAN_SERIAL_OFFSET 0x77
#define FAN_SERIAL_LENGTH 8
#define FAN_MODEL_LENGTH 13
#define FAN_SERIAL_OFFSET 0x76
#define FAN_SERIAL_LENGTH 9
#define FAN_MAX_RPM 21000
@@ -256,6 +256,12 @@ _onlp_fani_info_get_fan(int local_id, onlp_fan_info_t *info)
else
info->status |= ONLP_FAN_STATUS_FAILED;
/* Check Speed Error*/
if (fan_status_reg.bit.fan0_rps_err == 1 || fan_status_reg.bit.fan1_rps_err == 1)
{
info->status |= ONLP_FAN_STATUS_FAILED;
}
/* Get the CPLD address offset for fan speed */
speed0_addr_offset = _onlp_fani_get_fan_speed_addr_offset(local_id);
speed1_addr_offset = speed0_addr_offset + 1;
@@ -299,7 +305,27 @@ _onlp_fani_info_get_fan(int local_id, onlp_fan_info_t *info)
/* Get fan duty cycle */
info->percentage = round(((unsigned char)data * 100) / 255);
#if 1
uint8_t rdata[256] = { 0 };
i2c_read_i2c_block_dump(FAN1_EEPROM_BUS + local_id - 1, FAN_EEPROM_ADDR, (uint8_t *)rdata);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
#if 0 // debug
int i;
for(i=0;i<256;i++)
{
printf("%02X ",rdata[i]);
}
printf("\n");
#endif
eeprom_tlv_read(rdata, TLV_CODE_PRODUCT_NAME, (char *)info->model);
eeprom_tlv_read(rdata, TLV_CODE_SERIAL_NUMBER, (char *)info->serial);
#else
ret = i2c_read(FAN1_EEPROM_BUS + local_id - 1, FAN_EEPROM_ADDR, FAN_MODEL_OFFSET, FAN_MODEL_LENGTH, (char *)info->model);
if (ret < 0)
{
@@ -313,7 +339,7 @@ _onlp_fani_info_get_fan(int local_id, onlp_fan_info_t *info)
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
#endif
return ONLP_STATUS_OK;
}

View File

@@ -426,58 +426,6 @@ int _i2c_read_word_data(int i2cbus, int addr, int offset)
return res;
}
int _i2c_read_block_data(int i2cbus, int addr, uint8_t offset, uint8_t *data, int data_length)
{
int file;
char filename[20];
/*open i2c device*/
snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cbus);
filename[sizeof(filename) - 1] = '\0';
file = open(filename, O_RDWR);
if (file < 0) {
sprintf(filename, "/dev/i2c-%d", i2cbus);
file = open(filename, O_RDWR);
}
if (file < 0)
{
AIM_LOG_INFO("Unable to open id:%d %s\r\n", i2cbus, filename);
return -1;
}
#if 0/*check funcs*/
unsigned long funcs;
if (ioctl(file, I2C_FUNCS, &funcs) < 0) {
AIM_LOG_INFO("Error: Could not get the adapter\r\n");
return -1;
}
//I2C_SMBUS_BLOCK_DATA
#endif
/*set slave address set_slave_addr(file, address, force))*/
//if (ioctl(file, I2C_SLAVE_FORCE, addr) < 0)
if (ioctl(file, I2C_SLAVE, addr) < 0)
{
AIM_LOG_INFO("Error: Could not set address to 0x%02x, %s \r\n", offset, strerror(errno));
close(file);
return -errno;
}
int res = 0;
res = i2c_smbus_read_i2c_block_data(file, offset, data_length, data);
if (res < 0 && DEBUG_FLAG)
{
AIM_LOG_INFO("Error: i2c_smbus_read_word_data status:%d\r\n", res);
//close(file);
//return res;
}
close(file);
return res;
}
int i2c_read_byte(int i2cbus, int addr, int offset, char* data)
{
int ret;
@@ -509,6 +457,57 @@ int i2c_read_word(int i2cbus, int addr, int offset)
return ret;
}
int _i2c_read_block_data(int i2cbus, int addr, uint8_t offset, uint8_t *data, int data_length)
{
int file;
char filename[20];
/*open i2c device*/
snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cbus);
filename[sizeof(filename) - 1] = '\0';
file = open(filename, O_RDWR);
if (file < 0) {
sprintf(filename, "/dev/i2c-%d", i2cbus);
file = open(filename, O_RDWR);
}
if (file < 0)
{
AIM_LOG_INFO("Unable to open id:%d %s\r\n", i2cbus, filename);
return -1;
}
#if 0/*check funcs*/
unsigned long funcs;
if (ioctl(file, I2C_FUNCS, &funcs) < 0) {
AIM_LOG_INFO("Error: Could not get the adapter\r\n");
return -1;
}
//I2C_SMBUS_BLOCK_DATA
#endif
/*set slave address set_slave_addr(file, address, force))*/
if (ioctl(file, I2C_SLAVE_FORCE, addr) < 0)
//if (ioctl(file, I2C_SLAVE, addr) < 0)
{
AIM_LOG_INFO("Error: Could not set address to 0x%02x, %s \r\n", addr, strerror(errno));
close(file);
return -errno;
}
int res = 0;
res = i2c_smbus_read_i2c_block_data(file, offset, data_length, data);
if (res < 0 && DEBUG_FLAG)
{
AIM_LOG_INFO("Error: i2c_smbus_read_word_data status:%d\r\n", res);
//close(file);
//return res;
}
close(file);
return res;
}
int i2c_read_block(int i2cbus, int addr, uint8_t offset, uint8_t *data, int length)
{
@@ -516,6 +515,90 @@ int i2c_read_block(int i2cbus, int addr, uint8_t offset, uint8_t *data, int leng
ret = _i2c_read_block_data(i2cbus, addr, offset, data, length);
if (ret < 0 && DEBUG_FLAG)
{
AIM_LOG_INFO("Error: Read failed %d\r\n", ret);
}
//AIM_LOG_INFO("i2c_read_block: bus:%d add:0x%x offset:%d ret:%d data:0x%x\r\n", i2cbus, addr, offset, ret, *data);
return ret;
}
int _i2c_read_i2c_block_data_dump(int i2cbus, int addr, uint8_t *data)
{
int file;
char filename[20];
int res = 0;
int i = 0;
unsigned char cblock[288];
/*open i2c device*/
snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cbus);
filename[sizeof(filename) - 1] = '\0';
file = open(filename, O_RDWR);
if (file < 0)
{
sprintf(filename, "/dev/i2c-%d", i2cbus);
file = open(filename, O_RDWR);
}
if (file < 0)
{
AIM_LOG_INFO("Unable to open id:%d %s\r\n", i2cbus, filename);
return -1;
}
#if 0/*check funcs*/
unsigned long funcs;
if (ioctl(file, I2C_FUNCS, &funcs) < 0)
{
AIM_LOG_INFO("Error: Could not get the adapter\r\n");
return -1;
}
//I2C_SMBUS_BLOCK_DATA
#endif
/*set slave address set_slave_addr(file, address, force))*/
if (ioctl(file, I2C_SLAVE_FORCE, addr) < 0)
//if (ioctl(file, I2C_SLAVE, addr) < 0)
{
AIM_LOG_INFO("Error: Could not set address to 0x%02x, %s \r\n", addr, strerror(errno));
close(file);
return -errno;
}
for (res = 0; res < 256; res += i)
{
i = i2c_smbus_read_i2c_block_data(file, res, 32, cblock + res);
if (i <= 0)
{
res = i;
break;
}
}
if (res < 0 && DEBUG_FLAG)
{
AIM_LOG_INFO("Error: i2c_smbus_read_word_data status:%d\r\n", res);
close(file);
return res;
}
if (res >= 256)
res = 256;
for (i = 0; i < res; i++) data[i] = cblock[i];
close(file);
return res;
}
int i2c_read_i2c_block_dump(int i2cbus, int addr, uint8_t *data)
{
int ret;
ret = _i2c_read_i2c_block_data_dump(i2cbus, addr, data);
if (ret < 0 && DEBUG_FLAG)
{
AIM_LOG_INFO("Error: Read failed %d\r\n",ret);
@@ -545,7 +628,8 @@ int i2c_write_byte(int i2cbus, int addr, int offset, char val)
filename[sizeof(filename) - 1] = '\0';
file = open(filename, O_RDWR);
if (file < 0) {
if (file < 0)
{
sprintf(filename, "/dev/i2c-%d", i2cbus);
file = open(filename, O_RDWR);
}
@@ -716,3 +800,32 @@ char diag_debug_pause_platform_manage_check(void)
return (flag == '1')?1:0;
}
#define ONIE_EEPROM_HEADER_LENGTH 11
int eeprom_tlv_read(uint8_t *rdata, char type, char *data)
{
uint8_t i, j, TLV_length;
int total_data_length = ((*(rdata + 9)) << 8) + (*(rdata + 10)) + ONIE_EEPROM_HEADER_LENGTH;
char TLV_type;
for (i = ONIE_EEPROM_HEADER_LENGTH; i < total_data_length;)
{
TLV_type = *(rdata + i);
TLV_length = *(rdata + i + 1);
//printf("Type:%d Len:%d\n", TLV_type,TLV_length);
if (TLV_type == type)
{
for (j = 0; j < TLV_length; j++)
{
data[j] = *(rdata + i + j + 2);
//printf("TLV match\n");
}
data[j] = '\0';
return 0;
}
i += (TLV_length + 2);
//printf("i:%d\n",i);
}
return 0;
}

View File

@@ -187,6 +187,27 @@ enum onlp_led_id
LED_REAR_FAN6,
};
/*
* TLV type code
*/
#define TLV_CODE_PRODUCT_NAME 0x21
#define TLV_CODE_PART_NUMBER 0x22
#define TLV_CODE_SERIAL_NUMBER 0x23
#define TLV_CODE_MAC_BASE 0x24
#define TLV_CODE_MANUF_DATE 0x25
#define TLV_CODE_DEVICE_VERSION 0x26
#define TLV_CODE_LABEL_REVISION 0x27
#define TLV_CODE_PLATFORM_NAME 0x28
#define TLV_CODE_ONIE_VERSION 0x29
#define TLV_CODE_MAC_SIZE 0x2A
#define TLV_CODE_MANUF_NAME 0x2B
#define TLV_CODE_MANUF_COUNTRY 0x2C
#define TLV_CODE_VENDOR_NAME 0x2D
#define TLV_CODE_DIAG_VERSION 0x2E
#define TLV_CODE_SERVICE_TAG 0x2F
#define TLV_CODE_VENDOR_EXT 0xFD
#define TLV_CODE_CRC_32 0xFE
/*
i2c APIs: access i2c device by ioctl
@@ -199,6 +220,7 @@ int i2c_sequential_read(int i2cbus, int addr, int offset, int length, char* data
int i2c_read_byte(int i2cbus, int addr, int offset, char* data);
int i2c_read_word(int i2cbus, int addr, int command);
int i2c_read_block(int i2cbus, int addr, uint8_t offset, uint8_t *data, int length);
int i2c_read_i2c_block_dump(int i2cbus, int addr, uint8_t *data);
int i2c_write_byte(int i2cbus, int addr, int offset, char val);
int i2c_write_bit(int i2cbus, int addr, int offset, int bit, char val);
int i2c_read_rps_status(int i2cbus, int addr, int offset);
@@ -215,6 +237,11 @@ char diag_debug_trace_check(void);
char diag_debug_pause_platform_manage_on(void);
char diag_debug_pause_platform_manage_off(void);
char diag_debug_pause_platform_manage_check(void);
/*
* TLV parsering for specific type code
*/
int eeprom_tlv_read(uint8_t *rdata, char type, char *data);
#define DIAG_TRACE(fmt,args...) if(diag_debug_trace_check()) printf("\n[TRACE]"fmt"\n", args)
#define DIAG_PRINT(fmt,args...) DIAG_TRACE(fmt,args);else if(diag_flag_get()) printf("[DIAG]"fmt"\n", args)

View File

@@ -630,7 +630,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int *value)
if (onlp_sfpi_is_present(port) == 0)
{
#if 1 //for display RX_LOS Bitmap in onlpdump
*value = 1;
*value = 0;
break;
#else
return ONLP_STATUS_E_MISSING;

View File

@@ -0,0 +1 @@
include $(ONL)/make/pkg.mk

View File

@@ -0,0 +1 @@
include $(ONL)/make/pkg.mk

View File

@@ -0,0 +1 @@
!include $ONL_TEMPLATES/no-platform-modules.yml ARCH=amd64 VENDOR=lenovo BASENAME=x86-64-lenovo-ne2572

View File

@@ -0,0 +1 @@
include $(ONL)/make/pkg.mk

View File

@@ -0,0 +1 @@
!include $ONL_TEMPLATES/onlp-platform-any.yml PLATFORM=x86-64-lenovo-ne2572 ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu

View File

@@ -0,0 +1,2 @@
FILTER=src
include $(ONL)/make/subdirs.mk

View File

@@ -0,0 +1,45 @@
############################################################
# <bsn.cl fy=2014 v=onl>
#
# Copyright 2014 BigSwitch Networks, Inc.
#
# Licensed under the Eclipse Public License, Version 1.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.eclipse.org/legal/epl-v10.html
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the
# License.
#
# </bsn.cl>
############################################################
#
#
############################################################
include $(ONL)/make/config.amd64.mk
MODULE := libonlp-x86-64-lenovo-ne2572
include $(BUILDER)/standardinit.mk
DEPENDMODULES := AIM IOF x86_64_lenovo_ne2572 onlplib
DEPENDMODULE_HEADERS := sff
include $(BUILDER)/dependmodules.mk
SHAREDLIB := libonlp-x86-64-lenovo-ne2572.so
$(SHAREDLIB)_TARGETS := $(ALL_TARGETS)
include $(BUILDER)/so.mk
.DEFAULT_GOAL := $(SHAREDLIB)
GLOBAL_CFLAGS += -I$(onlp_BASEDIR)/module/inc
GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1
GLOBAL_CFLAGS += -fPIC
GLOBAL_LINK_LIBS += -lpthread
include $(BUILDER)/targets.mk

View File

@@ -0,0 +1,46 @@
############################################################
# <bsn.cl fy=2014 v=onl>
#
# Copyright 2014 BigSwitch Networks, Inc.
#
# Licensed under the Eclipse Public License, Version 1.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.eclipse.org/legal/epl-v10.html
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the
# License.
#
# </bsn.cl>
############################################################
#
#
#
############################################################
include $(ONL)/make/config.amd64.mk
.DEFAULT_GOAL := onlpdump
MODULE := onlpdump
include $(BUILDER)/standardinit.mk
DEPENDMODULES := AIM IOF onlp x86_64_lenovo_ne2572 onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS
include $(BUILDER)/dependmodules.mk
BINARY := onlpdump
$(BINARY)_LIBRARIES := $(LIBRARY_TARGETS)
include $(BUILDER)/bin.mk
GLOBAL_CFLAGS += -DAIM_CONFIG_AIM_MAIN_FUNCTION=onlpdump_main
GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1
GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MAIN=1
GLOBAL_LINK_LIBS += -lpthread -lm
include $(BUILDER)/targets.mk

View File

@@ -0,0 +1 @@
name: x86_64_lenovo_ne2572

View File

@@ -0,0 +1,9 @@
###############################################################################
#
#
#
###############################################################################
include $(ONL)/make/config.mk
MODULE := x86_64_lenovo_ne2572
AUTOMODULE := x86_64_lenovo_ne2572
include $(BUILDER)/definemodule.mk

View File

@@ -0,0 +1,9 @@
###############################################################################
#
#
#
###############################################################################
include ../../init.mk
MODULE := x86_64_lenovo_ne2572
AUTOMODULE := x86_64_lenovo_ne2572
include $(BUILDER)/definemodule.mk

View File

@@ -0,0 +1,6 @@
###############################################################################
#
# x86_64_lenovo_ne2572 README
#
###############################################################################

View File

@@ -0,0 +1,9 @@
###############################################################################
#
# x86_64_lenovo_ne2572 Autogeneration
#
###############################################################################
x86_64_lenovo_ne2572_AUTO_DEFS := module/auto/x86_64_lenovo_ne2572.yml
x86_64_lenovo_ne2572_AUTO_DIRS := module/inc/x86_64_lenovo_ne2572 module/src
include $(BUILDER)/auto.mk

View File

@@ -0,0 +1,47 @@
###############################################################################
#
# x86_64_lenovo_ne2572 Autogeneration Definitions.
#
###############################################################################
cdefs: &cdefs
- X86_64_LENOVO_NE2572_CONFIG_INCLUDE_LOGGING:
doc: "Include or exclude logging."
default: 1
- X86_64_LENOVO_NE2572_CONFIG_LOG_OPTIONS_DEFAULT:
doc: "Default enabled log options."
default: AIM_LOG_OPTIONS_DEFAULT
- X86_64_LENOVO_NE2572_CONFIG_LOG_BITS_DEFAULT:
doc: "Default enabled log bits."
default: AIM_LOG_BITS_DEFAULT
- X86_64_LENOVO_NE2572_CONFIG_LOG_CUSTOM_BITS_DEFAULT:
doc: "Default enabled custom log bits."
default: 0
- X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB:
doc: "Default all porting macros to use the C standard libraries."
default: 1
- X86_64_LENOVO_NE2572_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS:
doc: "Include standard library headers for stdlib porting macros."
default: X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB
- X86_64_LENOVO_NE2572_CONFIG_INCLUDE_UCLI:
doc: "Include generic uCli support."
default: 0
definitions:
cdefs:
X86_64_LENOVO_NE2572_CONFIG_HEADER:
defs: *cdefs
basename: x86_64_lenovo_ne2572_config
portingmacro:
X86_64_LENOVO_NE2572:
macros:
- malloc
- free
- memset
- memcpy
- strncpy
- vsnprintf
- snprintf
- strlen

View File

@@ -0,0 +1,14 @@
/**************************************************************************//**
*
*
*
*****************************************************************************/
#include <x86_64_lenovo_ne2572/x86_64_lenovo_ne2572_config.h>
/* <--auto.start.xmacro(ALL).define> */
/* <auto.end.xmacro(ALL).define> */
/* <--auto.start.xenum(ALL).define> */
/* <auto.end.xenum(ALL).define> */

View File

@@ -0,0 +1,127 @@
/**************************************************************************//**
*
* @file
* @brief x86_64_lenovo_ne2572 Configuration Header
*
* @addtogroup x86_64_lenovo_ne2572-config
* @{
*
*****************************************************************************/
#ifndef __X86_64_LENOVO_NE2572_CONFIG_H__
#define __X86_64_LENOVO_NE2572_CONFIG_H__
#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG
#include <global_custom_config.h>
#endif
#ifdef X86_64_LENOVO_NE2572_INCLUDE_CUSTOM_CONFIG
#include <x86_64_lenovo_ne2572_custom_config.h>
#endif
/* <auto.start.cdefs(X86_64_LENOVO_NE2572_CONFIG_HEADER).header> */
#include <AIM/aim.h>
/**
* X86_64_LENOVO_NE2572_CONFIG_INCLUDE_LOGGING
*
* Include or exclude logging. */
#ifndef X86_64_LENOVO_NE2572_CONFIG_INCLUDE_LOGGING
#define X86_64_LENOVO_NE2572_CONFIG_INCLUDE_LOGGING 1
#endif
/**
* X86_64_LENOVO_NE2572_CONFIG_LOG_OPTIONS_DEFAULT
*
* Default enabled log options. */
#ifndef X86_64_LENOVO_NE2572_CONFIG_LOG_OPTIONS_DEFAULT
#define X86_64_LENOVO_NE2572_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT
#endif
/**
* X86_64_LENOVO_NE2572_CONFIG_LOG_BITS_DEFAULT
*
* Default enabled log bits. */
#ifndef X86_64_LENOVO_NE2572_CONFIG_LOG_BITS_DEFAULT
#define X86_64_LENOVO_NE2572_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT
#endif
/**
* X86_64_LENOVO_NE2572_CONFIG_LOG_CUSTOM_BITS_DEFAULT
*
* Default enabled custom log bits. */
#ifndef X86_64_LENOVO_NE2572_CONFIG_LOG_CUSTOM_BITS_DEFAULT
#define X86_64_LENOVO_NE2572_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0
#endif
/**
* X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB
*
* Default all porting macros to use the C standard libraries. */
#ifndef X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB
#define X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB 1
#endif
/**
* X86_64_LENOVO_NE2572_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS
*
* Include standard library headers for stdlib porting macros. */
#ifndef X86_64_LENOVO_NE2572_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS
#define X86_64_LENOVO_NE2572_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB
#endif
/**
* X86_64_LENOVO_NE2572_CONFIG_INCLUDE_UCLI
*
* Include generic uCli support. */
#ifndef X86_64_LENOVO_NE2572_CONFIG_INCLUDE_UCLI
#define X86_64_LENOVO_NE2572_CONFIG_INCLUDE_UCLI 0
#endif
/**
* All compile time options can be queried or displayed
*/
/** Configuration settings structure. */
typedef struct x86_64_lenovo_ne2572_config_settings_s {
/** name */
const char* name;
/** value */
const char* value;
} x86_64_lenovo_ne2572_config_settings_t;
/** Configuration settings table. */
/** x86_64_lenovo_ne2572_config_settings table. */
extern x86_64_lenovo_ne2572_config_settings_t x86_64_lenovo_ne2572_config_settings[];
/**
* @brief Lookup a configuration setting.
* @param setting The name of the configuration option to lookup.
*/
const char* x86_64_lenovo_ne2572_config_lookup(const char* setting);
/**
* @brief Show the compile-time configuration.
* @param pvs The output stream.
*/
int x86_64_lenovo_ne2572_config_show(struct aim_pvs_s* pvs);
/* <auto.end.cdefs(X86_64_LENOVO_NE2572_CONFIG_HEADER).header> */
#include "x86_64_lenovo_ne2572_porting.h"
#endif /* __X86_64_LENOVO_NE2572_CONFIG_H__ */
/* @} */

View File

@@ -0,0 +1,26 @@
/**************************************************************************//**
*
* x86_64_lenovo_ne2572 Doxygen Header
*
*****************************************************************************/
#ifndef __X86_64_LENOVO_NE2572_DOX_H__
#define __X86_64_LENOVO_NE2572_DOX_H__
/**
* @defgroup x86_64_lenovo_ne2572 x86_64_lenovo_ne2572 - x86_64_lenovo_ne2572 Description
*
The documentation overview for this module should go here.
*
* @{
*
* @defgroup x86_64_lenovo_ne2572-x86_64_lenovo_ne2572 Public Interface
* @defgroup x86_64_lenovo_ne2572-config Compile Time Configuration
* @defgroup x86_64_lenovo_ne2572-porting Porting Macros
*
* @}
*
*/
#endif /* __X86_64_LENOVO_NE2572_DOX_H__ */

View File

@@ -0,0 +1,107 @@
/**************************************************************************//**
*
* @file
* @brief x86_64_lenovo_ne2572 Porting Macros.
*
* @addtogroup x86_64_lenovo_ne2572-porting
* @{
*
*****************************************************************************/
#ifndef __X86_64_LENOVO_NE2572_PORTING_H__
#define __X86_64_LENOVO_NE2572_PORTING_H__
/* <auto.start.portingmacro(ALL).define> */
#if X86_64_LENOVO_NE2572_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <memory.h>
#endif
#ifndef X86_64_LENOVO_NE2572_MALLOC
#if defined(GLOBAL_MALLOC)
#define X86_64_LENOVO_NE2572_MALLOC GLOBAL_MALLOC
#elif X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB == 1
#define X86_64_LENOVO_NE2572_MALLOC malloc
#else
#error The macro X86_64_LENOVO_NE2572_MALLOC is required but cannot be defined.
#endif
#endif
#ifndef X86_64_LENOVO_NE2572_FREE
#if defined(GLOBAL_FREE)
#define X86_64_LENOVO_NE2572_FREE GLOBAL_FREE
#elif X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB == 1
#define X86_64_LENOVO_NE2572_FREE free
#else
#error The macro X86_64_LENOVO_NE2572_FREE is required but cannot be defined.
#endif
#endif
#ifndef X86_64_LENOVO_NE2572_MEMSET
#if defined(GLOBAL_MEMSET)
#define X86_64_LENOVO_NE2572_MEMSET GLOBAL_MEMSET
#elif X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB == 1
#define X86_64_LENOVO_NE2572_MEMSET memset
#else
#error The macro X86_64_LENOVO_NE2572_MEMSET is required but cannot be defined.
#endif
#endif
#ifndef X86_64_LENOVO_NE2572_MEMCPY
#if defined(GLOBAL_MEMCPY)
#define X86_64_LENOVO_NE2572_MEMCPY GLOBAL_MEMCPY
#elif X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB == 1
#define X86_64_LENOVO_NE2572_MEMCPY memcpy
#else
#error The macro X86_64_LENOVO_NE2572_MEMCPY is required but cannot be defined.
#endif
#endif
#ifndef X86_64_LENOVO_NE2572_STRNCPY
#if defined(GLOBAL_STRNCPY)
#define X86_64_LENOVO_NE2572_STRNCPY GLOBAL_STRNCPY
#elif X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB == 1
#define X86_64_LENOVO_NE2572_STRNCPY strncpy
#else
#error The macro X86_64_LENOVO_NE2572_STRNCPY is required but cannot be defined.
#endif
#endif
#ifndef X86_64_LENOVO_NE2572_VSNPRINTF
#if defined(GLOBAL_VSNPRINTF)
#define X86_64_LENOVO_NE2572_VSNPRINTF GLOBAL_VSNPRINTF
#elif X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB == 1
#define X86_64_LENOVO_NE2572_VSNPRINTF vsnprintf
#else
#error The macro X86_64_LENOVO_NE2572_VSNPRINTF is required but cannot be defined.
#endif
#endif
#ifndef X86_64_LENOVO_NE2572_SNPRINTF
#if defined(GLOBAL_SNPRINTF)
#define X86_64_LENOVO_NE2572_SNPRINTF GLOBAL_SNPRINTF
#elif X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB == 1
#define X86_64_LENOVO_NE2572_SNPRINTF snprintf
#else
#error The macro X86_64_LENOVO_NE2572_SNPRINTF is required but cannot be defined.
#endif
#endif
#ifndef X86_64_LENOVO_NE2572_STRLEN
#if defined(GLOBAL_STRLEN)
#define X86_64_LENOVO_NE2572_STRLEN GLOBAL_STRLEN
#elif X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB == 1
#define X86_64_LENOVO_NE2572_STRLEN strlen
#else
#error The macro X86_64_LENOVO_NE2572_STRLEN is required but cannot be defined.
#endif
#endif
/* <auto.end.portingmacro(ALL).define> */
#endif /* __X86_64_LENOVO_NE2572_PORTING_H__ */
/* @} */

View File

@@ -0,0 +1,10 @@
###############################################################################
#
#
#
###############################################################################
THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
x86_64_lenovo_ne2572_INCLUDES := -I $(THIS_DIR)inc
x86_64_lenovo_ne2572_INTERNAL_INCLUDES := -I $(THIS_DIR)src
x86_64_lenovo_ne2572_DEPENDMODULE_ENTRIES := init:x86_64_lenovo_ne2572 ucli:x86_64_lenovo_ne2572

View File

@@ -0,0 +1,9 @@
###############################################################################
#
# Local source generation targets.
#
###############################################################################
ucli:
@../../../../tools/uclihandlers.py x86_64_lenovo_ne2572_ucli.c

View File

@@ -0,0 +1,45 @@
#include "x86_64_lenovo_ne2572_int.h"
#if X86_64_LENOVO_NE2572_CONFIG_INCLUDE_DEBUG == 1
#include <unistd.h>
static char help__[] =
"Usage: debug [options]\n"
" -c CPLD Versions\n"
" -h Help\n"
;
int
x86_64_lenovo_ne2572_debug_main(int argc, char* argv[])
{
int c = 0;
int help = 0;
int rv = 0;
while( (c = getopt(argc, argv, "ch")) != -1) {
switch(c)
{
case 'c': c = 1; break;
case 'h': help = 1; rv = 0; break;
default: help = 1; rv = 1; break;
}
}
if(help || argc == 1) {
printf("%s", help__);
return rv;
}
if(c) {
printf("Not implemented.\n");
}
return 0;
}
#endif

View File

@@ -0,0 +1,597 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014 Big Switch Networks, Inc.
* Copyright 2018 Alpha Networks Incorporation.
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
************************************************************
*
* Fan Platform Implementation Defaults.
*
***********************************************************/
#include <onlp/platformi/fani.h>
#include <onlplib/mmap.h>
#include <fcntl.h>
#include <math.h>
#include "platform_lib.h"
#define DEBUG 0
#define CPLD_I2C_BUS_ID 0
#define CPLD_I2C_ADDR 0x5E /* Power CPLD Physical Address in the I2C */
#define CPLD_FAN6_STATUS_ADDR_OFFSET 0x10
#define CPLD_FAN5_STATUS_ADDR_OFFSET 0x11
#define CPLD_FAN4_STATUS_ADDR_OFFSET 0x12
#define CPLD_FAN3_STATUS_ADDR_OFFSET 0x13
#define CPLD_FAN2_STATUS_ADDR_OFFSET 0x14
#define CPLD_FAN1_STATUS_ADDR_OFFSET 0x15
#define CPLD_FAN6_0_SPEED_ADDR_OFFSET 0x16
#define CPLD_FAN6_1_SPEED_ADDR_OFFSET 0x17
#define CPLD_FAN5_0_SPEED_ADDR_OFFSET 0x18
#define CPLD_FAN5_1_SPEED_ADDR_OFFSET 0x19
#define CPLD_FAN4_0_SPEED_ADDR_OFFSET 0x1A
#define CPLD_FAN4_1_SPEED_ADDR_OFFSET 0x1B
#define CPLD_FAN3_0_SPEED_ADDR_OFFSET 0x1C
#define CPLD_FAN3_1_SPEED_ADDR_OFFSET 0x1D
#define CPLD_FAN2_0_SPEED_ADDR_OFFSET 0x1E
#define CPLD_FAN2_1_SPEED_ADDR_OFFSET 0x1F
#define CPLD_FAN1_0_SPEED_ADDR_OFFSET 0x20
#define CPLD_FAN1_1_SPEED_ADDR_OFFSET 0x21
#define CPLD_FAN_MIN_RPS_ADDR_OFFSET 0x22
#define CPLD_FAN_PWM_ADDR_OFFSET 0x23
#define CPLD_FAN_SEL_CONTROL_ADDR_OFFSET 0x24 /* 0: CPLD control, 1: BMC control */
#define FAN1_EEPROM_BUS 77
#define FAN_EEPROM_ADDR 0x57
#define FAN_MODEL_OFFSET 0x67
#define FAN_MODEL_LENGTH 12
#define FAN_SERIAL_OFFSET 0x77
#define FAN_SERIAL_LENGTH 8
#define FAN_MAX_RPM 21000
#if 1 //PSU FAN
#define PSU_PMBus_ADDR 0x59
#define READ_FAN_SPEED_REG 0x90
#define READ_FAN_STATUS_1_2_REG 0x81
#endif
#define FAN_DIR_FRONT_TO_BACK 0
#define FAN_DIR_BACK_TO_FRONT 1
/* Static fan information */
onlp_fan_info_t linfo[] = {
{ }, /* Not used */
{
{ ONLP_FAN_ID_CREATE(FAN_1), "Chassis Fan 1", 0 },
0x0,
ONLP_FAN_CAPS_GET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_SET_RPM,
0,
0,
ONLP_FAN_MODE_INVALID,
},
{
{ ONLP_FAN_ID_CREATE(FAN_2), "Chassis Fan 2", 0 },
0x0,
ONLP_FAN_CAPS_GET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_SET_RPM,
0,
0,
ONLP_FAN_MODE_INVALID,
},
{
{ ONLP_FAN_ID_CREATE(FAN_3), "Chassis Fan 3", 0 },
0x0,
ONLP_FAN_CAPS_GET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_SET_RPM,
0,
0,
ONLP_FAN_MODE_INVALID,
},
{
{ ONLP_FAN_ID_CREATE(FAN_4), "Chassis Fan 4", 0 },
0x0,
ONLP_FAN_CAPS_GET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_SET_RPM,
0,
0,
ONLP_FAN_MODE_INVALID,
},
{
{ ONLP_FAN_ID_CREATE(FAN_5), "Chassis Fan 5", 0 },
0x0,
ONLP_FAN_CAPS_GET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_SET_RPM,
0,
0,
ONLP_FAN_MODE_INVALID,
},
{
{ ONLP_FAN_ID_CREATE(FAN_6), "Chassis Fan 6", 0 },
0x0,
ONLP_FAN_CAPS_GET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_SET_RPM,
0,
0,
ONLP_FAN_MODE_INVALID,
},
{
{ ONLP_FAN_ID_CREATE(FAN_1_ON_PSU1), "Chassis PSU-1 Fan 1", 0 },
0x0,
ONLP_FAN_CAPS_GET_RPM,
0,
0,
ONLP_FAN_MODE_INVALID,
},
{
{ ONLP_FAN_ID_CREATE(FAN_1_ON_PSU2), "Chassis PSU-2 Fan 1", 0 },
0x0,
ONLP_FAN_CAPS_GET_RPM,
0,
0,
ONLP_FAN_MODE_INVALID,
},
};
#define VALIDATE(_id) \
do { \
if(!ONLP_OID_IS_FAN(_id)) { \
return ONLP_STATUS_E_INVALID; \
} \
} while(0)
typedef union
{
unsigned char val;
struct
{
unsigned char fan_direction :1;
unsigned char fan_present :1;
unsigned char fan0_rps_err :1;
unsigned char fan1_rps_err :1;
unsigned char :4; /* reserved */
}bit;
}_CPLD_FAN_STATUS_REG_T;
/* Get the CPLD address offset for fan status */
static char
_onlp_fani_get_fan_status_addr_offset(int local_id)
{
DIAG_PRINT("%s, local_id=%d", __FUNCTION__, local_id);
switch (local_id)
{
case FAN_1:
return CPLD_FAN1_STATUS_ADDR_OFFSET;
case FAN_2:
return CPLD_FAN2_STATUS_ADDR_OFFSET;
case FAN_3:
return CPLD_FAN3_STATUS_ADDR_OFFSET;
case FAN_4:
return CPLD_FAN4_STATUS_ADDR_OFFSET;
case FAN_5:
return CPLD_FAN5_STATUS_ADDR_OFFSET;
case FAN_6:
return CPLD_FAN6_STATUS_ADDR_OFFSET;
}
return 0;
}
/* Get the CPLD address offset for fan speed */
static char
_onlp_fani_get_fan_speed_addr_offset(int local_id)
{
DIAG_PRINT("%s, local_id=%d", __FUNCTION__, local_id);
switch (local_id)
{
case FAN_1:
return CPLD_FAN1_0_SPEED_ADDR_OFFSET;
case FAN_2:
return CPLD_FAN2_0_SPEED_ADDR_OFFSET;
case FAN_3:
return CPLD_FAN3_0_SPEED_ADDR_OFFSET;
case FAN_4:
return CPLD_FAN4_0_SPEED_ADDR_OFFSET;
case FAN_5:
return CPLD_FAN5_0_SPEED_ADDR_OFFSET;
case FAN_6:
return CPLD_FAN6_0_SPEED_ADDR_OFFSET;
}
return 0;
}
static int
_onlp_fani_info_get_fan(int local_id, onlp_fan_info_t *info)
{
DIAG_PRINT("%s, local_id=%d", __FUNCTION__, local_id);
_CPLD_FAN_STATUS_REG_T fan_status_reg;
char status_addr_offset = 0, speed0_addr_offset = 0, speed1_addr_offset = 0;
char data = 0;
unsigned char tach_speed0 = 0, tach_speed1 = 0;
int ret = 0;
/* Get the CPLD address offset for fan status */
status_addr_offset = _onlp_fani_get_fan_status_addr_offset(local_id);
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, status_addr_offset, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
if (DEBUG)
AIM_LOG_INFO("%s:%d id[%d],status_addr_offset[%02x],read_byte[%02x]\n",
__FUNCTION__, __LINE__, local_id, (unsigned char)status_addr_offset, (unsigned char)data);
fan_status_reg.val = data;
/* Get fan air flow direction */
if (fan_status_reg.bit.fan_direction == FAN_DIR_FRONT_TO_BACK)
info->status |= ONLP_FAN_STATUS_F2B;
else
info->status |= ONLP_FAN_STATUS_B2F;
/* Get fan present */
if (fan_status_reg.bit.fan_present == 1)
info->status |= ONLP_FAN_STATUS_PRESENT;
else
info->status |= ONLP_FAN_STATUS_FAILED;
/* Check Speed Error*/
if (fan_status_reg.bit.fan0_rps_err == 1 || fan_status_reg.bit.fan1_rps_err == 1)
{
info->status |= ONLP_FAN_STATUS_FAILED;
}
/* Get the CPLD address offset for fan speed */
speed0_addr_offset = _onlp_fani_get_fan_speed_addr_offset(local_id);
speed1_addr_offset = speed0_addr_offset + 1;
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, speed0_addr_offset, (char *)&tach_speed0);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
if (DEBUG)
AIM_LOG_INFO("%s:%d id[%d],speed0_addr_offset[%02x],read_byte[%02x]\n",
__FUNCTION__, __LINE__, local_id, (unsigned char)speed0_addr_offset, (unsigned char)tach_speed0);
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, speed1_addr_offset, (char *)&tach_speed1);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
if (DEBUG)
AIM_LOG_INFO("%s:%d id[%d],speed1_addr_offset[%02x],read_byte[%02x]\n",
__FUNCTION__, __LINE__, local_id, (unsigned char)speed1_addr_offset, (unsigned char)tach_speed1);
//DIAG_PRINT("%s, speed0=%d(0x%X), speed1=%d(0x%X)", __FUNCTION__, (int)tach_speed0, tach_speed0, (int)tach_speed1, tach_speed1);
/* Get fan rpm */
//info->rpm = (((int)tach_speed0 + (int)tach_speed1) / 2) * 150;
info->rpm = (int)tach_speed1 * 150;
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN_PWM_ADDR_OFFSET, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
if (DEBUG)
AIM_LOG_INFO("%s:%d id[%d],pwm_addr_offset[%02x],read_byte[%02x]\n",
__FUNCTION__, __LINE__, local_id, CPLD_FAN_PWM_ADDR_OFFSET, (unsigned char)data);
/* Get fan duty cycle */
info->percentage = round(((unsigned char)data * 100) / 255);
#if 1
uint8_t rdata[256] = { 0 };
i2c_read_i2c_block_dump(FAN1_EEPROM_BUS + local_id - 1, FAN_EEPROM_ADDR, (uint8_t *)rdata);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
#if 0 // debug
int i;
for(i=0;i<256;i++)
{
printf("%02X ",rdata[i]);
}
printf("\n");
#endif
eeprom_tlv_read(rdata, TLV_CODE_PRODUCT_NAME, (char *)info->model);
eeprom_tlv_read(rdata, TLV_CODE_SERIAL_NUMBER, (char *)info->serial);
#else
ret = i2c_read(FAN1_EEPROM_BUS + local_id - 1, FAN_EEPROM_ADDR, FAN_MODEL_OFFSET, FAN_MODEL_LENGTH, (char *)info->model);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
ret = i2c_read(FAN1_EEPROM_BUS + local_id - 1, FAN_EEPROM_ADDR, FAN_SERIAL_OFFSET, FAN_SERIAL_LENGTH, (char *)info->serial);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
#endif
return ONLP_STATUS_OK;
}
static int
_onlp_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t *info)
{
int ret = ONLP_STATUS_OK;
int exponent = 0, mantissa = 0;
uint16_t value = 0;
DIAG_PRINT("%s, local_id=%d", __FUNCTION__, local_id);
/* Get PSU fan speed */
switch (local_id)
{
case FAN_1_ON_PSU1:
ret = i2c_read_word(PSU1_BUS_ID, PSU_PMBus_ADDR, READ_FAN_SPEED_REG);
if (ret < 0 && DEBUG)
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
break;
case FAN_1_ON_PSU2:
ret = i2c_read_word(PSU2_BUS_ID, PSU_PMBus_ADDR, READ_FAN_SPEED_REG);
if (ret < 0 && DEBUG)
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
break;
}
//printf("[%s]local_id:%d i2c read ret:%d\n",__FUNCTION__, local_id, ret);
if (ret <= 0)
{
info->status |= ONLP_FAN_STATUS_FAILED;
}
else
{
info->status |= ONLP_FAN_STATUS_PRESENT;
value = ret;
//Linear Data Format
exponent = psu_two_complement_to_int(value >> 11, 5, 0x1f);
mantissa = psu_two_complement_to_int(value & 0x7ff, 11, 0x7ff);
info->rpm = (exponent >= 0) ? (mantissa << exponent) : (mantissa) / (1 << -exponent);
}
//check Fan Fault, bit 7
ret = i2c_read_word(PSU2_BUS_ID, PSU_PMBus_ADDR, READ_FAN_STATUS_1_2_REG);
if (ret < 0 && DEBUG)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
}
else if ((ret & 0x80) == 0x80)
{
info->status |= ONLP_FAN_STATUS_FAILED;
}
return ONLP_STATUS_OK;
}
/*
* This function will be called prior to all of onlp_fani_* functions.
*/
#define DEFAULT_FAN_SPEED 50
int
onlp_fani_init(void)
{
DIAG_PRINT("%s", __FUNCTION__);
#if 1 //By HW design, percentage is apply on all fans.
onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(FAN_1), DEFAULT_FAN_SPEED);
#else
int i = 0;
for (i = FAN_1;
i <= FAN_6;
i++)
{
onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(i), DEFAULT_FAN_SPEED);
}
#endif
return ONLP_STATUS_OK;
}
int
onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t *info)
{
DIAG_PRINT("%s, id=%d", __FUNCTION__, id);
int ret = ONLP_STATUS_OK;
int local_id;
VALIDATE(id);
local_id = ONLP_OID_ID_GET(id);
*info = linfo[local_id];
switch (local_id)
{
case FAN_1_ON_PSU1:
case FAN_1_ON_PSU2:
ret = _onlp_fani_info_get_fan_on_psu(local_id, info);
break;
default:
ret = _onlp_fani_info_get_fan(local_id, info);
break;
}
return ret;
}
int onlp_fani_status_get(onlp_oid_t id, uint32_t *rv)
{
DIAG_PRINT("%s, id=%d", __FUNCTION__, id);
onlp_fan_info_t info;
onlp_fan_status_t ret = 0;
onlp_fani_info_get(id, &info);
ret = info.status & (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_FAILED);
*rv = (uint32_t)ret;
return 0;
}
int _onlp_fani_rpm_to_percentage(int rpm)
{
int percentage = 0;
percentage = round(rpm * 100 / FAN_MAX_RPM);
if (percentage == 0 && rpm != 0)
{
percentage = 1;
}
DIAG_PRINT("%s, rpm=%d to percentage=%d", __FUNCTION__, rpm, percentage);
return percentage;
}
/*
* This function sets the speed of the given fan in RPM.
*
* This function will only be called if the fan supprots the RPM_SET
* capability.
*
* It is optional if you have no fans at all with this feature.
*/
/*
[Note]: By H/W design, fan speed is controlled using percentage.
RPM value will be translated to percentage and it may produce some deviation.
(the register size is 8-bit, so there is only 255 units to present the value.)
*/
int
onlp_fani_rpm_set(onlp_oid_t id, int rpm)
{
DIAG_PRINT("%s, id=%d, rpm=%d", __FUNCTION__, id, rpm);
if (rpm > FAN_MAX_RPM || rpm <= 0)
{
AIM_LOG_INFO("%s:%d rpm:%d is out of range. (1~%d)\n", __FUNCTION__, __LINE__, rpm, FAN_MAX_RPM);
return ONLP_STATUS_E_PARAM;
}
return onlp_fani_percentage_set(id, _onlp_fani_rpm_to_percentage(rpm));
}
/*
* This function sets the fan speed of the given OID as a percentage.
*
* This will only be called if the OID has the PERCENTAGE_SET
* capability.
*
* It is optional if you have no fans at all with this feature.
*/
int
onlp_fani_percentage_set(onlp_oid_t id, int p)
{
int ret = 0, local_id = 0;
float val = (float)p * 2.55;
char data = (char)round(val);
DIAG_PRINT("%s, id=%d, p=%d (0x%2X)", __FUNCTION__, id, p, (unsigned char)data);
VALIDATE(id);
local_id = ONLP_OID_ID_GET(id);
/* Not support to stop fan */
if (p == 0)
return ONLP_STATUS_E_INVALID;
else if (p == 100)
data = 0xff;
/* Cannot control PWM for each fan modules respectively.
* All fan modules PWM will be the same.
*/
ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN_PWM_ADDR_OFFSET, data);
if (ret < 0)
AIM_LOG_INFO("%s:%d data[%02x] fail[%d]\n", __FUNCTION__, __LINE__, data, ret);
if (DEBUG)
AIM_LOG_INFO("%s:%d id[%d],pwm_addr_offset[%02x],write_byte[%02x]\n",
__FUNCTION__, __LINE__, local_id, CPLD_FAN_PWM_ADDR_OFFSET, (unsigned char)data);
return ONLP_STATUS_OK;
}
/*
* This function sets the fan speed of the given OID as per
* the predefined ONLP fan speed modes: off, slow, normal, fast, max.
*
* Interpretation of these modes is up to the platform.
*
*/
int
onlp_fani_mode_set(onlp_oid_t id, onlp_fan_mode_t mode)
{
DIAG_PRINT("%s, ONLP_STATUS_E_UNSUPPORTED", __FUNCTION__);
return ONLP_STATUS_E_UNSUPPORTED;
}
/*
* This function sets the fan direction of the given OID.
*
* This function is only relevant if the fan OID supports both direction
* capabilities.
*
* This function is optional unless the functionality is available.
*/
int
onlp_fani_dir_set(onlp_oid_t id, onlp_fan_dir_t dir)
{
DIAG_PRINT("%s, ONLP_STATUS_E_UNSUPPORTED", __FUNCTION__);
return ONLP_STATUS_E_UNSUPPORTED;
}
/*
* Generic fan ioctl. Optional.
*/
int
onlp_fani_ioctl(onlp_oid_t id, va_list vargs)
{
DIAG_PRINT("%s, ONLP_STATUS_E_UNSUPPORTED", __FUNCTION__);
return ONLP_STATUS_E_UNSUPPORTED;
}

View File

@@ -0,0 +1,744 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014, 2015 Big Switch Networks, Inc.
* Copyright 2018 Alpha Networks Incorporation.
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
************************************************************
*
* LED Management
*
***********************************************************/
#include <onlp/platformi/ledi.h>
#include <onlp/platformi/fani.h>
#include <sys/mman.h>
#include <stdio.h>
#include "platform_lib.h"
#include <onlplib/mmap.h>
//#include "onlpie_int.h"
#define CPLD_I2C_BUS_ID 8
#define CPLD_I2C_ADDR 0x5F /* System CPLD Physical Address in the I2C */
#define CPLD_POWER_I2C_ADDR 0x5E /* System CPLD Physical Address in the I2C */
#define CPLD_POWER_GREEN_OFFSET 0x0E
#define CPLD_SYS_LED_ADDRESS_OFFSET 0x08
#define CPLD_FAN1_LED_ADDRESS_OFFSET 0x09 //Fan LED Register 0
#define CPLD_FAN1_REAR_LED_ADDRESS_OFFSET 0x0E //Fan Rear LED Register 0
#define CPLD_FAN2_REAR_LED_ADDRESS_OFFSET 0x0E
#define CPLD_FAN3_REAR_LED_ADDRESS_OFFSET 0x0F //Fan Rear LED Register 1
#define CPLD_FAN4_REAR_LED_ADDRESS_OFFSET 0x0F
#define CPLD_FAN5_REAR_LED_ADDRESS_OFFSET 0x010 //Fan Rear LED Register 2
#define CPLD_FAN6_REAR_LED_ADDRESS_OFFSET 0x010
#define CPLD_SERVICE_LED_ADDRESS_OFFSET 0x11 //Service Blue LED Register
#define STACKING_LED_OFF 0x00
#define STACKING_LED_AMBER_SOLID 0x01
#define STACKING_LED_AMBER_BLINKING 0x03
#define STACKING_LED_GREEN_SOLID 0x05
#define STACKING_LED_GREEN_BLINKING 0x07
#define PWR_LED_OFF 0x00
#define PWR_LED_AMBER_SOLID 0x01
#define PWR_LED_AMBER_BLINKING 0x03
#define PWR_LED_GREEN_SOLID 0x05
#define PWR_LED_GREEN_BLINKING 0x07
#define SERVICE_LED_OFF 0x00
#define SERVICE_LED_BLUE_SOLID 0x01
#define SERVICE_LED_BLUE_BLINKING 0x03
#define SERVICE_LED_GREEN_SOLID 0x01
#define SERVICE_LED_GREEN_BLINKING 0x03
#define FAN_LED_OFF 0x00
#define FAN_LED_AMBER_SOLID 0x01
#define FAN_LED_AMBER_BLINKING 0x03
#define FAN_LED_GREEN_SOLID 0x05
#define FAN_LED_GREEN_BLINKING 0x07
#define REAR_FAN_LED_GREEN_SOLID 0x01
#define REAR_FAN_LED_GREEN_BLINKING 0x03
#define VALIDATE(_id) \
do { \
if(!ONLP_OID_IS_LED(_id)) { \
return ONLP_STATUS_E_INVALID; \
} \
} while(0)
struct led_id_mode
{
enum onlp_led_id led_id;
onlp_led_mode_t mode;
int hw_led_light_mode;
};
static struct led_id_mode led_id_mode_data[] = {
{ LED_SERVICE, ONLP_LED_MODE_OFF, SERVICE_LED_OFF },
{ LED_SERVICE, ONLP_LED_MODE_GREEN, SERVICE_LED_GREEN_SOLID },
{ LED_SERVICE, ONLP_LED_MODE_GREEN_BLINKING, SERVICE_LED_GREEN_BLINKING },
{ LED_SERVICE, ONLP_LED_MODE_BLUE, SERVICE_LED_BLUE_SOLID },
{ LED_SERVICE, ONLP_LED_MODE_BLUE_BLINKING, SERVICE_LED_BLUE_BLINKING },
{ LED_SERVICE, ONLP_LED_MODE_ON, SERVICE_LED_BLUE_SOLID },
{ LED_STACKING, ONLP_LED_MODE_OFF, STACKING_LED_OFF },
{ LED_STACKING, ONLP_LED_MODE_GREEN, STACKING_LED_GREEN_SOLID },
{ LED_STACKING, ONLP_LED_MODE_GREEN_BLINKING, STACKING_LED_GREEN_BLINKING },
{ LED_STACKING, ONLP_LED_MODE_ORANGE, STACKING_LED_AMBER_SOLID },
{ LED_STACKING, ONLP_LED_MODE_ORANGE_BLINKING, STACKING_LED_AMBER_BLINKING },
{ LED_STACKING, ONLP_LED_MODE_ON, STACKING_LED_GREEN_SOLID },
{ LED_PWR, ONLP_LED_MODE_OFF, PWR_LED_OFF },
{ LED_PWR, ONLP_LED_MODE_GREEN, PWR_LED_GREEN_SOLID },
{ LED_PWR, ONLP_LED_MODE_GREEN_BLINKING, PWR_LED_GREEN_BLINKING },
{ LED_PWR, ONLP_LED_MODE_ORANGE, PWR_LED_AMBER_SOLID },
{ LED_PWR, ONLP_LED_MODE_ORANGE_BLINKING, PWR_LED_AMBER_BLINKING },
{ LED_PWR, ONLP_LED_MODE_ON, PWR_LED_GREEN_SOLID },
{ LED_FAN, ONLP_LED_MODE_OFF, FAN_LED_OFF },
{ LED_FAN, ONLP_LED_MODE_GREEN, FAN_LED_GREEN_SOLID },
{ LED_FAN, ONLP_LED_MODE_GREEN_BLINKING, FAN_LED_GREEN_BLINKING },
{ LED_FAN, ONLP_LED_MODE_ORANGE, FAN_LED_AMBER_SOLID },
{ LED_FAN, ONLP_LED_MODE_ORANGE_BLINKING, FAN_LED_AMBER_BLINKING },
{ LED_FAN, ONLP_LED_MODE_ON, FAN_LED_GREEN_SOLID },
{ LED_REAR_FAN1, ONLP_LED_MODE_OFF, FAN_LED_OFF },
{ LED_REAR_FAN1, ONLP_LED_MODE_GREEN, REAR_FAN_LED_GREEN_SOLID },
{ LED_REAR_FAN1, ONLP_LED_MODE_GREEN_BLINKING, REAR_FAN_LED_GREEN_BLINKING },
{ LED_REAR_FAN1, ONLP_LED_MODE_ON, REAR_FAN_LED_GREEN_SOLID },
{ LED_REAR_FAN2, ONLP_LED_MODE_OFF, FAN_LED_OFF },
{ LED_REAR_FAN2, ONLP_LED_MODE_GREEN, REAR_FAN_LED_GREEN_SOLID },
{ LED_REAR_FAN2, ONLP_LED_MODE_GREEN_BLINKING, REAR_FAN_LED_GREEN_BLINKING },
{ LED_REAR_FAN2, ONLP_LED_MODE_ON, REAR_FAN_LED_GREEN_SOLID },
{ LED_REAR_FAN3, ONLP_LED_MODE_OFF, FAN_LED_OFF },
{ LED_REAR_FAN3, ONLP_LED_MODE_GREEN, REAR_FAN_LED_GREEN_SOLID },
{ LED_REAR_FAN3, ONLP_LED_MODE_GREEN_BLINKING, REAR_FAN_LED_GREEN_BLINKING },
{ LED_REAR_FAN3, ONLP_LED_MODE_ON, REAR_FAN_LED_GREEN_SOLID },
{ LED_REAR_FAN4, ONLP_LED_MODE_OFF, FAN_LED_OFF },
{ LED_REAR_FAN4, ONLP_LED_MODE_GREEN, REAR_FAN_LED_GREEN_SOLID },
{ LED_REAR_FAN4, ONLP_LED_MODE_GREEN_BLINKING, REAR_FAN_LED_GREEN_BLINKING },
{ LED_REAR_FAN4, ONLP_LED_MODE_ON, REAR_FAN_LED_GREEN_SOLID },
{ LED_REAR_FAN5, ONLP_LED_MODE_OFF, FAN_LED_OFF },
{ LED_REAR_FAN5, ONLP_LED_MODE_GREEN, REAR_FAN_LED_GREEN_SOLID },
{ LED_REAR_FAN5, ONLP_LED_MODE_GREEN_BLINKING, REAR_FAN_LED_GREEN_BLINKING },
{ LED_REAR_FAN5, ONLP_LED_MODE_ON, REAR_FAN_LED_GREEN_SOLID },
{ LED_REAR_FAN6, ONLP_LED_MODE_OFF, FAN_LED_OFF },
{ LED_REAR_FAN6, ONLP_LED_MODE_GREEN, REAR_FAN_LED_GREEN_SOLID },
{ LED_REAR_FAN6, ONLP_LED_MODE_GREEN_BLINKING, REAR_FAN_LED_GREEN_BLINKING },
{ LED_REAR_FAN6, ONLP_LED_MODE_ON, REAR_FAN_LED_GREEN_SOLID },
};
typedef union
{
unsigned char val;
struct
{
unsigned char power :3;
unsigned char :1; /* reserved */
unsigned char stacking :3;
unsigned char :1; /* reserved */
}bit;
}_CPLD_SYSTEM_LED_REG_T;
typedef union
{
unsigned char val;
struct
{
unsigned char locator :2;
unsigned char :6; /* reserved */
}bit;
}_CPLD_LOCATOR_LED_REG_T;
typedef union
{
unsigned char val;
struct
{
unsigned char fan_a :3; /* fan_a : FAN1/FAN3/FAN5, fan_b : FAN2/FAN4/FAN6 */
unsigned char :1; /* reserved */
unsigned char fan_b :3;
unsigned char :1; /* reserved */
}bit;
}_CPLD_FAN_LED_REG_T;
/*
* Get the information for the given LED OID.
*/
static onlp_led_info_t linfo[] =
{
{ }, /* Not used */
{
{ ONLP_LED_ID_CREATE(LED_SERVICE), "Chassis LED 1 (SERVICE LED)", 0 },
ONLP_LED_STATUS_PRESENT,
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_BLUE | ONLP_LED_CAPS_BLUE_BLINKING | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING,
},
{
{ ONLP_LED_ID_CREATE(LED_STACKING), "Chassis LED 2 (STACKING LED)", 0 },
ONLP_LED_STATUS_PRESENT,
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING,
},
{
{ ONLP_LED_ID_CREATE(LED_PWR), "Chassis LED 3 (POWER LED)", 0 },
ONLP_LED_STATUS_PRESENT,
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING,
},
{
{ ONLP_LED_ID_CREATE(LED_FAN), "Chassis LED 4 (FAN LED)", 0 },
ONLP_LED_STATUS_PRESENT,
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_ORANGE_BLINKING,
},
{
{ ONLP_LED_ID_CREATE(LED_REAR_FAN1), "FAN Rear LED 1", 0 },
ONLP_LED_STATUS_PRESENT,
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING,
},
{
{ ONLP_LED_ID_CREATE(LED_REAR_FAN2), "FAN Rear LED 2", 0 },
ONLP_LED_STATUS_PRESENT,
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING,
},
{
{ ONLP_LED_ID_CREATE(LED_REAR_FAN3), "FAN Rear LED 3", 0 },
ONLP_LED_STATUS_PRESENT,
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING,
},
{
{ ONLP_LED_ID_CREATE(LED_REAR_FAN4), "FAN Rear LED 4", 0 },
ONLP_LED_STATUS_PRESENT,
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING,
},
{
{ ONLP_LED_ID_CREATE(LED_REAR_FAN5), "FAN Rear LED 5", 0 },
ONLP_LED_STATUS_PRESENT,
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING,
},
{
{ ONLP_LED_ID_CREATE(LED_REAR_FAN6), "FAN Rear LED 6", 0 },
ONLP_LED_STATUS_PRESENT,
ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_GREEN_BLINKING,
},
};
static int convert_hw_led_light_mode_to_onlp(enum onlp_led_id id, int hw_mode)
{
int i, nsize = sizeof(led_id_mode_data) / sizeof(led_id_mode_data[0]);
for (i = 0; i < nsize; i++)
{
if ((led_id_mode_data[i].led_id == id) &&
(led_id_mode_data[i].hw_led_light_mode == hw_mode))
{
DIAG_PRINT("%s, id:%d, hw_mode:%d mode:%d", __FUNCTION__, id, hw_mode, led_id_mode_data[i].mode);
return (int)led_id_mode_data[i].mode;
}
}
return -1;
}
static int convert_onlp_led_light_mode_to_hw(enum onlp_led_id id, onlp_led_mode_t mode)
{
int i, nsize = sizeof(led_id_mode_data) / sizeof(led_id_mode_data[0]);
for (i = 0; i < nsize; i++)
{
if ((led_id_mode_data[i].led_id == id) &&
(led_id_mode_data[i].mode == mode))
{
DIAG_PRINT("%s, id:%d, mode:%d hw_mode:%d", __FUNCTION__, id, mode, led_id_mode_data[i].hw_led_light_mode);
return led_id_mode_data[i].hw_led_light_mode;
}
}
return -1;
}
/*
* This function will be called prior to any other onlp_ledi_* functions.
*/
int
onlp_ledi_init(void)
{
DIAG_PRINT("%s", __FUNCTION__);
#if 0
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_SERVICE), ONLP_LED_MODE_OFF);
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_STACKING), ONLP_LED_MODE_OFF);
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_PWR), ONLP_LED_MODE_OFF);
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN), ONLP_LED_MODE_OFF);
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN1), ONLP_LED_MODE_OFF);
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN2), ONLP_LED_MODE_OFF);
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN3), ONLP_LED_MODE_OFF);
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN4), ONLP_LED_MODE_OFF);
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN5), ONLP_LED_MODE_OFF);
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN6), ONLP_LED_MODE_OFF);
#endif
return ONLP_STATUS_OK;
}
int
onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t *info)
{
DIAG_PRINT("%s, id=%d", __FUNCTION__, id);
_CPLD_LOCATOR_LED_REG_T service_led_reg;
_CPLD_SYSTEM_LED_REG_T system_led_reg;
_CPLD_FAN_LED_REG_T fan_led_reg;
char data = 0;
int ret = 0, local_id = 0;
VALIDATE(id);
/* Set the onlp_oid_hdr_t and capabilities */
*info = linfo[ONLP_OID_ID_GET(id)];
local_id = ONLP_OID_ID_GET(id);
switch (local_id)
{
case LED_SERVICE:
//Read Blue LED
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_SERVICE_LED_ADDRESS_OFFSET, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
service_led_reg.val = data;
//Green LED on, Blue LED off
if(data == 0)
{
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_POWER_I2C_ADDR , CPLD_POWER_GREEN_OFFSET, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
service_led_reg.val = data;
if(service_led_reg.val == SERVICE_LED_GREEN_SOLID)
info->mode = ONLP_LED_MODE_GREEN;
else if(service_led_reg.val == SERVICE_LED_GREEN_BLINKING)
info->mode = ONLP_LED_MODE_GREEN_BLINKING;
}
//GREEN LED off, Blue LED on
else
{
if(service_led_reg.val == SERVICE_LED_BLUE_SOLID)
info->mode = ONLP_LED_MODE_BLUE;
else if(service_led_reg.val == SERVICE_LED_BLUE_BLINKING)
info->mode = ONLP_LED_MODE_BLUE_BLINKING;
}
//Check LED OFF or not
if(service_led_reg.val == SERVICE_LED_OFF)
info->mode = ONLP_LED_MODE_OFF;
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
break;
case LED_PWR:
case LED_STACKING:
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_SYS_LED_ADDRESS_OFFSET, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
system_led_reg.val = data;
break;
case LED_FAN:
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN1_LED_ADDRESS_OFFSET, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
fan_led_reg.val = data;
break;
case LED_REAR_FAN1:
case LED_REAR_FAN2:
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN1_REAR_LED_ADDRESS_OFFSET, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
fan_led_reg.val = data;
break;
case LED_REAR_FAN3:
case LED_REAR_FAN4:
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN3_REAR_LED_ADDRESS_OFFSET, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
fan_led_reg.val = data;
break;
case LED_REAR_FAN5:
case LED_REAR_FAN6:
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN5_REAR_LED_ADDRESS_OFFSET, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
fan_led_reg.val = data;
break;
default :
AIM_LOG_INFO("%s:%d %d is a wrong ID\n", __FUNCTION__, __LINE__, local_id);
return ONLP_STATUS_E_PARAM;
}
/* Get LED status */
switch (local_id)
{
case LED_SERVICE:
//info->mode = convert_hw_led_light_mode_to_onlp(local_id, service_led_reg.bit.locator);
break;
case LED_PWR:
info->mode = convert_hw_led_light_mode_to_onlp(local_id, system_led_reg.bit.power);
break;
case LED_STACKING:
info->mode = convert_hw_led_light_mode_to_onlp(local_id, system_led_reg.bit.stacking);
break;
case LED_FAN:
case LED_REAR_FAN1:
case LED_REAR_FAN3:
case LED_REAR_FAN5:
//debug
//printf("[%s] fan_led_reg.val:0x%x \n", __FUNCTION__, fan_led_reg.val);
info->mode = convert_hw_led_light_mode_to_onlp(local_id, fan_led_reg.bit.fan_a);
break;
case LED_REAR_FAN2:
case LED_REAR_FAN4:
case LED_REAR_FAN6:
//debug
//printf("[%s] fan_led_reg.val:0x%x \n", __FUNCTION__, fan_led_reg.val);
info->mode = convert_hw_led_light_mode_to_onlp(local_id, fan_led_reg.bit.fan_b);
break;
default:
AIM_LOG_INFO("%s:%d %d is a wrong ID\n", __FUNCTION__, __LINE__, local_id);
return ONLP_STATUS_E_PARAM;
}
/* Set the on/off status */
if (info->mode != ONLP_LED_MODE_OFF)
{
info->status |= ONLP_LED_STATUS_ON;
}
//debug
//printf("[%s] local_id:%d info->mode:%d info->status:%d\n", __FUNCTION__, local_id, info->mode, info->status);
return ONLP_STATUS_OK;
}
/*
* Turn an LED on or off.
*
* This function will only be called if the LED OID supports the ONOFF
* capability.
*
* What 'on' means in terms of colors or modes for multimode LEDs is
* up to the platform to decide. This is intended as baseline toggle mechanism.
*/
int
onlp_ledi_set(onlp_oid_t id, int on_or_off)
{
DIAG_PRINT("%s, id=%d, on_or_off=%d", __FUNCTION__, id, on_or_off);
VALIDATE(id);
if (!on_or_off)
{
return onlp_ledi_mode_set(id, ONLP_LED_MODE_OFF);
}
return onlp_ledi_mode_set(id, ONLP_LED_MODE_ON);
}
/*
* This function puts the LED into the given mode. It is a more functional
* interface for multimode LEDs.
*
* Only modes reported in the LED's capabilities will be attempted.
*/
int
onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode)
{
DIAG_PRINT("%s, id=%d, mode=%d", __FUNCTION__, id, mode);
_CPLD_LOCATOR_LED_REG_T service_led_reg;
_CPLD_SYSTEM_LED_REG_T system_led_reg;
_CPLD_FAN_LED_REG_T fan_led_reg;
char data = 0;
int ret = 0, local_id = 0, hw_led_mode = 0;
VALIDATE(id);
local_id = ONLP_OID_ID_GET(id);
switch (local_id)
{
case LED_SERVICE:
//Blue LED
if (mode == ONLP_LED_MODE_BLUE || mode == ONLP_LED_MODE_BLUE_BLINKING || mode == ONLP_LED_MODE_ON )
{
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_SERVICE_LED_ADDRESS_OFFSET, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
service_led_reg.val = data;
}
//Green LED
else if (mode == ONLP_LED_MODE_GREEN || mode == ONLP_LED_MODE_GREEN_BLINKING)
{
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_POWER_I2C_ADDR , CPLD_POWER_GREEN_OFFSET, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
service_led_reg.val = data;
}
break;
case LED_PWR:
case LED_STACKING:
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_SYS_LED_ADDRESS_OFFSET, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
system_led_reg.val = data;
break;
case LED_FAN:
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN1_LED_ADDRESS_OFFSET, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
fan_led_reg.val = data;
break;
case LED_REAR_FAN1:
case LED_REAR_FAN2:
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN1_REAR_LED_ADDRESS_OFFSET, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
fan_led_reg.val = data;
break;
case LED_REAR_FAN3:
case LED_REAR_FAN4:
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN3_REAR_LED_ADDRESS_OFFSET, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
fan_led_reg.val = data;
break;
case LED_REAR_FAN5:
case LED_REAR_FAN6:
ret = i2c_read_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN5_REAR_LED_ADDRESS_OFFSET, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
fan_led_reg.val = data;
break;
default :
AIM_LOG_INFO("%s:%d %d is a wrong ID\n", __FUNCTION__, __LINE__, local_id);
return ONLP_STATUS_E_PARAM;
}
hw_led_mode = convert_onlp_led_light_mode_to_hw(local_id, mode);
if (hw_led_mode < 0)
return ONLP_STATUS_E_PARAM;
/* Set LED light mode */
switch (local_id)
{
case LED_SERVICE:
service_led_reg.bit.locator = hw_led_mode;
break;
case LED_PWR:
system_led_reg.bit.power = hw_led_mode;
break;
case LED_STACKING:
system_led_reg.bit.stacking = hw_led_mode;
break;
case LED_FAN:
case LED_REAR_FAN1:
case LED_REAR_FAN3:
case LED_REAR_FAN5:
fan_led_reg.bit.fan_a = hw_led_mode;
break;
case LED_REAR_FAN2:
case LED_REAR_FAN4:
case LED_REAR_FAN6:
fan_led_reg.bit.fan_b = hw_led_mode;
break;
default:
AIM_LOG_INFO("%s:%d %d is a wrong ID\n", __FUNCTION__, __LINE__, local_id);
return ONLP_STATUS_E_PARAM;
}
switch (local_id)
{
case LED_SERVICE:
//printf("[debug]service_led_reg.val:0x%x\n", service_led_reg.val);
//BLUE LED on
if (mode == ONLP_LED_MODE_BLUE || mode == ONLP_LED_MODE_BLUE_BLINKING || mode == ONLP_LED_MODE_ON)
{
//turn on blue LED
ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_SERVICE_LED_ADDRESS_OFFSET, service_led_reg.val);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
//turn off green LED
service_led_reg.bit.locator = 0;
ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_POWER_I2C_ADDR, CPLD_POWER_GREEN_OFFSET, service_led_reg.val);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
}
//Green LED on
else if (mode == ONLP_LED_MODE_GREEN || mode == ONLP_LED_MODE_GREEN_BLINKING)
{
//turn on green led
ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_POWER_I2C_ADDR, CPLD_POWER_GREEN_OFFSET, service_led_reg.val);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
//turn off blue led
service_led_reg.bit.locator = 0;
ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_SERVICE_LED_ADDRESS_OFFSET, service_led_reg.val);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
}
// ONLP_LED_MODE_OFF
else
{
service_led_reg.bit.locator = 0;
//turn off blue led
ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_SERVICE_LED_ADDRESS_OFFSET, service_led_reg.val);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
//turn off green led
ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_POWER_I2C_ADDR, CPLD_POWER_GREEN_OFFSET, service_led_reg.val);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
}
break;
case LED_PWR:
case LED_STACKING:
ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_SYS_LED_ADDRESS_OFFSET, system_led_reg.val);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
break;
case LED_FAN:
ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN1_LED_ADDRESS_OFFSET, fan_led_reg.val);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
break;
case LED_REAR_FAN1:
case LED_REAR_FAN2:
ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN1_REAR_LED_ADDRESS_OFFSET, fan_led_reg.val);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
fan_led_reg.val = data;
break;
case LED_REAR_FAN3:
case LED_REAR_FAN4:
ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN3_REAR_LED_ADDRESS_OFFSET, fan_led_reg.val);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
fan_led_reg.val = data;
break;
case LED_REAR_FAN5:
case LED_REAR_FAN6:
ret = i2c_write_byte(CPLD_I2C_BUS_ID, CPLD_I2C_ADDR, CPLD_FAN5_REAR_LED_ADDRESS_OFFSET, fan_led_reg.val);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
fan_led_reg.val = data;
break;
default :
AIM_LOG_INFO("%s:%d %d is a wrong ID\n", __FUNCTION__, __LINE__, local_id);
return ONLP_STATUS_E_PARAM;
}
return ONLP_STATUS_OK;
}
/*
* Generic LED ioctl interface.
*/
int
onlp_ledi_ioctl(onlp_oid_t id, va_list vargs)
{
return ONLP_STATUS_E_UNSUPPORTED;
}

View File

@@ -0,0 +1,9 @@
###############################################################################
#
#
#
###############################################################################
LIBRARY := x86_64_lenovo_ne2572
$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST)))
include $(BUILDER)/lib.mk

View File

@@ -0,0 +1,858 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014 Big Switch Networks, Inc.
* Copyright 2018 Alpha Networks Incorporation
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
************************************************************
*
*
*
***********************************************************/
#include <sys/mman.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <AIM/aim.h>
#include <onlp/platformi/sfpi.h>
#include "platform_lib.h"
#define DEBUG_FLAG 0
int deviceNodeWrite(char *filename, char *buffer, int buf_size, int data_len)
{
int fd;
int len;
if ((buffer == NULL) || (buf_size < 0))
{
return -1;
}
if ((fd = open(filename, O_WRONLY, S_IWUSR)) == -1)
{
return -1;
}
if ((len = write(fd, buffer, buf_size)) < 0)
{
close(fd);
return -1;
}
if ((close(fd) == -1))
{
return -1;
}
if ((len > buf_size) || (data_len != 0 && len != data_len))
{
return -1;
}
return 0;
}
int deviceNodeWriteInt(char *filename, int value, int data_len)
{
char buf[8] = { 0 };
sprintf(buf, "%d", value);
return deviceNodeWrite(filename, buf, sizeof(buf) - 1, data_len);
}
int deviceNodeReadBinary(char *filename, char *buffer, int buf_size, int data_len)
{
int fd;
int len;
if ((buffer == NULL) || (buf_size < 0))
{
return -1;
}
if ((fd = open(filename, O_RDONLY)) == -1)
{
return -1;
}
if ((len = read(fd, buffer, buf_size)) < 0)
{
close(fd);
return -1;
}
if ((close(fd) == -1))
{
return -1;
}
if ((len > buf_size) || (data_len != 0 && len != data_len))
{
return -1;
}
return 0;
}
int deviceNodeReadString(char *filename, char *buffer, int buf_size, int data_len)
{
int ret;
if (data_len >= buf_size || data_len < 0)
{
return -1;
}
ret = deviceNodeReadBinary(filename, buffer, buf_size - 1, data_len);
if (ret == 0)
{
if (data_len)
{
buffer[data_len] = '\0';
}
else
{
buffer[buf_size - 1] = '\0';
}
}
return ret;
}
int psu_two_complement_to_int(uint16_t data, uint8_t valid_bit, int mask)
{
uint16_t valid_data = data & mask;
bool is_negative = valid_data >> (valid_bit - 1);
return is_negative ? (-(((~valid_data) & mask) + 1)) : valid_data;
}
/*
i2c APIs: access i2c device by ioctl
static int i2c_read(int i2cbus, int addr, int offset, int length, char* data)
static int i2c_read_byte(int i2cbus, int addr, int offset, char* data)
static int i2c_read_word(int i2cbus, int addr, int command)
static int i2c_write_byte(int i2cbus, int addr, int offset, char val)
static int i2c_write_bit(int i2cbus, int addr, int offset, int bit, char val)
*/
int i2c_read(int i2cbus, int addr, int offset, int length, char *data)
{
int file;
int i;
char filename[20];
/*open i2c device*/
snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cbus);
filename[sizeof(filename) - 1] = '\0';
file = open(filename, O_RDWR);
if (file < 0)
{
sprintf(filename, "/dev/i2c-%d", i2cbus);
file = open(filename, O_RDWR);
}
if (file < 0)
{
AIM_LOG_INFO("Unable to open id:%d %s\r\n", i2cbus, filename);
return -1;
}
#if 0/*check funcs*/
unsigned long funcs;
if (ioctl(file, I2C_FUNCS, &funcs) < 0)
{
AIM_LOG_INFO("Error: Could not get the adapter\r\n");
return -1;
}
//I2C_SMBUS_BLOCK_DATA
#endif
/*set slave address set_slave_addr(file, address, force))*/
if (ioctl(file, I2C_SLAVE_FORCE, addr) < 0)
//if (ioctl(file, I2C_SLAVE, addr) < 0)
{
AIM_LOG_INFO("Error: Could not set address to 0x%02x, %s \r\n", addr, strerror(errno));
close(file);
return -errno;
}
#if 1
int res = 0;
for (i = 0; i < length; i++)
{
res = i2c_smbus_read_byte_data(file, offset + i);
if (res < 0 && DEBUG_FLAG)
{
AIM_LOG_INFO("Error: i2c_smbus_read_byte_data offset:%d\r\n", offset + i);
close(file);
return res;
}
data[i] = res;
}
#else
/*i2c_smbus_read_block_data(file, bank, cblock);*/
int res = 0;
unsigned char cblock[288];
res = i2c_smbus_read_block_data(file, 0, cblock);
i2c_smbus_read_byte_data(file, i+j)
if(res < 0)
{
AIM_LOG_INFO("Error: read failed res:%d\r\n", res);
return -1;
}
if((offset + length) > res)
{
AIM_LOG_INFO("Error: Size out of range offset:%d l:%d res:%d\r\n", offset, length, res);
return -1;
}
for (i = 0; i < length; i++)
{
data[i] = cblock[offset + i];
}
#endif
close(file);
return 0;
}
int i2c_sequential_read(int i2cbus, int addr, int offset, int length, char *data)
{
int file;
int i;
char filename[20];
int res = 0;
/*open i2c device*/
snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cbus);
filename[sizeof(filename) - 1] = '\0';
file = open(filename, O_RDWR);
if (file < 0)
{
sprintf(filename, "/dev/i2c-%d", i2cbus);
file = open(filename, O_RDWR);
}
if (file < 0)
{
AIM_LOG_INFO("Unable to open id:%d %s\r\n", i2cbus, filename);
return -1;
}
/*set slave address set_slave_addr(file, address, force))*/
if (ioctl(file, I2C_SLAVE_FORCE, addr) < 0)
{
AIM_LOG_INFO("Error: Could not set address to 0x%02x, %s \r\n", addr, strerror(errno));
close(file);
return -errno;
}
/*
Sequential Read for at24c128
use i2c_smbus_write_byte_data to write 24c128 address counter(two 8-bit data word addresses)
24c128:
+----------------------------------------------------+
| S | Device | Wr | A | 1st Word | A | 2nd Word | A |...
| | Address | | | Address | | Address | |
+----------------------------------------------------+
SMbus:
+----------------------------------------------------+
| S | Device | Wr | A | Command | A | Data | A |...
| | Address | | | | | | |
+----------------------------------------------------+
*/
res = i2c_smbus_write_byte_data(file, (uint8_t)offset >> 8, (uint8_t)offset);
if (res != 0)
{
AIM_LOG_INFO("Error: Write start address failed, return code %d\n", res);
return -1;
}
for (i = 0; i < length; i++)
{
res = i2c_smbus_read_byte(file);
if (res < 0 && DEBUG_FLAG)
{
AIM_LOG_INFO("Error: i2c_smbus_read_byte_data offset:%d\r\n", offset + i);
close(file);
return res;
}
data[i] = res;
}
close(file);
return 0;
}
int i2c_read_rps_status(int i2cbus, int addr, int offset)
{
int file;
//int i;
char filename[20];
/*open i2c device*/
snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cbus);
filename[sizeof(filename) - 1] = '\0';
file = open(filename, O_RDWR);
if (file < 0)
{
sprintf(filename, "/dev/i2c-%d", i2cbus);
file = open(filename, O_RDWR);
}
if (file < 0)
{
AIM_LOG_INFO("Unable to open id:%d %s\r\n", i2cbus, filename);
return -1;
}
#if 0/*check funcs*/
unsigned long funcs;
if (ioctl(file, I2C_FUNCS, &funcs) < 0)
{
AIM_LOG_INFO("Error: Could not get the adapter\r\n");
return -1;
}
//I2C_SMBUS_BLOCK_DATA
#endif
/*set slave address set_slave_addr(file, address, force))*/
//if (ioctl(file, I2C_SLAVE_FORCE, addr) < 0)
if (ioctl(file, I2C_SLAVE, addr) < 0)
{
AIM_LOG_INFO("Error: Could not set address to 0x%02x, %s \r\n", addr, strerror(errno));
close(file);
return -errno;
}
int res = 0;
res = i2c_smbus_read_byte_data(file, offset);
if (res < 0 && DEBUG_FLAG)
{
AIM_LOG_INFO("Error: i2c_smbus_read_byte_data offset:%d\r\n", offset);
close(file);
return res;
}
close(file);
return res;
}
int _i2c_read_word_data(int i2cbus, int addr, int offset)
{
int file;
//int i;
char filename[20];
/*open i2c device*/
snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cbus);
filename[sizeof(filename) - 1] = '\0';
file = open(filename, O_RDWR);
if (file < 0)
{
sprintf(filename, "/dev/i2c-%d", i2cbus);
file = open(filename, O_RDWR);
}
if (file < 0)
{
AIM_LOG_INFO("Unable to open id:%d %s\r\n", i2cbus, filename);
return -1;
}
#if 0/*check funcs*/
unsigned long funcs;
if (ioctl(file, I2C_FUNCS, &funcs) < 0)
{
AIM_LOG_INFO("Error: Could not get the adapter\r\n");
return -1;
}
//I2C_SMBUS_BLOCK_DATA
#endif
/*set slave address set_slave_addr(file, address, force))*/
//if (ioctl(file, I2C_SLAVE_FORCE, addr) < 0)
if (ioctl(file, I2C_SLAVE, addr) < 0)
{
AIM_LOG_INFO("Error: Could not set address to 0x%02x, %s \r\n", offset, strerror(errno));
close(file);
return -errno;
}
#if 1
int res = 0;
res = i2c_smbus_read_word_data(file, offset);
if (res < 0 && DEBUG_FLAG)
{
AIM_LOG_INFO("Error: i2c_smbus_read_word_data status:%d\r\n", res);
//close(file);
//return res;
}
#else
/*i2c_smbus_read_block_data(file, bank, cblock);*/
int res = 0;
unsigned char cblock[288];
res = i2c_smbus_read_block_data(file, 0, cblock);
i2c_smbus_read_byte_data(file, i+j)
if(res < 0)
{
AIM_LOG_INFO("Error: read failed res:%d\r\n", res);
return -1;
}
if((offset + length) > res)
{
AIM_LOG_INFO("Error: Size out of range offset:%d l:%d res:%d\r\n", offset, length, res);
return -1;
}
for (i = 0;
i < length;
i++)
{
data[i] = cblock[offset + i];
}
#endif
close(file);
return res;
}
int i2c_read_byte(int i2cbus, int addr, int offset, char *data)
{
int ret;
ret = i2c_read(i2cbus, addr, offset, 1, data);
if (ret < 0 && DEBUG_FLAG)
{
AIM_LOG_INFO("Error: Read failed %d\r\n", ret);
}
//AIM_LOG_INFO("i2c_read_byte: bus:%d add:0x%x offset:%d ret:%d data:0x%x\r\n", i2cbus, addr, offset, ret, *data);
return ret;
}
int i2c_read_word(int i2cbus, int addr, int offset)
{
int ret;
ret = _i2c_read_word_data(i2cbus, addr, offset);
if (ret < 0 && DEBUG_FLAG)
{
AIM_LOG_INFO("Error: Read failed %d\r\n", ret);
}
//AIM_LOG_INFO("i2c_read_word: bus:%d add:0x%x offset:%d ret:%d\r\n", i2cbus, addr, offset, ret);
return ret;
}
int _i2c_read_block_data(int i2cbus, int addr, uint8_t offset, uint8_t *data, int data_length)
{
int file;
char filename[20];
/*open i2c device*/
snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cbus);
filename[sizeof(filename) - 1] = '\0';
file = open(filename, O_RDWR);
if (file < 0)
{
sprintf(filename, "/dev/i2c-%d", i2cbus);
file = open(filename, O_RDWR);
}
if (file < 0)
{
AIM_LOG_INFO("Unable to open id:%d %s\r\n", i2cbus, filename);
return -1;
}
#if 0/*check funcs*/
unsigned long funcs;
if (ioctl(file, I2C_FUNCS, &funcs) < 0)
{
AIM_LOG_INFO("Error: Could not get the adapter\r\n");
return -1;
}
//I2C_SMBUS_BLOCK_DATA
#endif
/*set slave address set_slave_addr(file, address, force))*/
if (ioctl(file, I2C_SLAVE_FORCE, addr) < 0)
//if (ioctl(file, I2C_SLAVE, addr) < 0)
{
AIM_LOG_INFO("Error: Could not set address to 0x%02x, %s \r\n", addr, strerror(errno));
close(file);
return -errno;
}
int res = 0;
res = i2c_smbus_read_i2c_block_data(file, offset, data_length, data);
if (res < 0 && DEBUG_FLAG)
{
AIM_LOG_INFO("Error: i2c_smbus_read_word_data status:%d\r\n", res);
//close(file);
//return res;
}
close(file);
return res;
}
int i2c_read_block(int i2cbus, int addr, uint8_t offset, uint8_t *data, int length)
{
int ret;
ret = _i2c_read_block_data(i2cbus, addr, offset, data, length);
if (ret < 0 && DEBUG_FLAG)
{
AIM_LOG_INFO("Error: Read failed %d\r\n", ret);
}
//AIM_LOG_INFO("i2c_read_block: bus:%d add:0x%x offset:%d ret:%d data:0x%x\r\n", i2cbus, addr, offset, ret, *data);
return ret;
}
int _i2c_read_i2c_block_data_dump(int i2cbus, int addr, uint8_t *data)
{
int file;
char filename[20];
int res = 0;
int i = 0;
unsigned char cblock[288];
/*open i2c device*/
snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cbus);
filename[sizeof(filename) - 1] = '\0';
file = open(filename, O_RDWR);
if (file < 0)
{
sprintf(filename, "/dev/i2c-%d", i2cbus);
file = open(filename, O_RDWR);
}
if (file < 0)
{
AIM_LOG_INFO("Unable to open id:%d %s\r\n", i2cbus, filename);
return -1;
}
#if 0/*check funcs*/
unsigned long funcs;
if (ioctl(file, I2C_FUNCS, &funcs) < 0)
{
AIM_LOG_INFO("Error: Could not get the adapter\r\n");
return -1;
}
//I2C_SMBUS_BLOCK_DATA
#endif
/*set slave address set_slave_addr(file, address, force))*/
if (ioctl(file, I2C_SLAVE_FORCE, addr) < 0)
//if (ioctl(file, I2C_SLAVE, addr) < 0)
{
AIM_LOG_INFO("Error: Could not set address to 0x%02x, %s \r\n", addr, strerror(errno));
close(file);
return -errno;
}
for (res = 0; res < 256; res += i)
{
i = i2c_smbus_read_i2c_block_data(file, res, 32, cblock + res);
if (i <= 0)
{
res = i;
break;
}
}
if (res < 0 && DEBUG_FLAG)
{
AIM_LOG_INFO("Error: i2c_smbus_read_word_data status:%d\r\n", res);
close(file);
return res;
}
if (res >= 256)
res = 256;
for (i = 0; i < res; i++) data[i] = cblock[i];
close(file);
return res;
}
int i2c_read_i2c_block_dump(int i2cbus, int addr, uint8_t *data)
{
int ret;
ret = _i2c_read_i2c_block_data_dump(i2cbus, addr, data);
if (ret < 0 && DEBUG_FLAG)
{
AIM_LOG_INFO("Error: Read failed %d\r\n", ret);
}
//AIM_LOG_INFO("i2c_read_block: bus:%d add:0x%x offset:%d ret:%d data:0x%x\r\n", i2cbus, addr, offset, ret, *data);
return ret;
}
int i2c_write_byte(int i2cbus, int addr, int offset, char val)
{
int file;
char filename[20];
int res = 0;
#if 0/*get current value*/
char cur_val=0;
res = i2c_read_byte(i2cbus, addr, offset, &cur_val);
if (ret <0)
{
return res;
}
#endif
/*open i2c device*/
snprintf(filename, sizeof(filename), "/dev/i2c/%d", i2cbus);
filename[sizeof(filename) - 1] = '\0';
file = open(filename, O_RDWR);
if (file < 0)
{
sprintf(filename, "/dev/i2c-%d", i2cbus);
file = open(filename, O_RDWR);
}
if (file < 0)
{
AIM_LOG_INFO("Unable to open id:%d %s\r\n", i2cbus, filename);
return -1;
}
/*set slave address set_slave_addr(file, address, force))*/
//if (ioctl(file, I2C_SLAVE_FORCE, addr) < 0)
if (ioctl(file, I2C_SLAVE, addr) < 0)
{
AIM_LOG_INFO("Error: Could not set address to 0x%02x, %s \r\n", addr, strerror(errno));
close(file);
return -errno;
}
res = i2c_smbus_write_byte_data(file, offset, val);
if (res < 0)
{
AIM_LOG_INFO("Error: i2c_smbus_write_byte_data offset:%d val:0x%x r:%d\r\n", offset, val, res);
close(file);
return res;
}
close(file);
return 0;
}
int i2c_write_bit(int i2cbus, int addr, int offset, int bit, char val)
{
int res = 0;
char cur_val = 0;
char new_val = 0;
if (val != 0 && val != 1)
{
AIM_LOG_INFO("Error: i2c_write_bit error val:%d\r\n", val);
return -1;
}
if (bit < 0 && bit > 7)
{
AIM_LOG_INFO("Error: i2c_write_bit error bit:%d\r\n", bit);
return -1;
}
res = i2c_read_byte(i2cbus, addr, offset, &cur_val);
if (res < 0)
{
return res;
}
if (val == 1)
{
new_val = cur_val | (1 << bit);
}
else
{
new_val = cur_val & ~(1 << bit);
}
//AIM_LOG_INFO("i2c_write_bit %d-0x%x-%d cur:0x%x new:0x%x\r\n", i2cbus, addr, offset, cur_val, new_val);
if (new_val == cur_val)
{
return 0;
}
res = i2c_write_byte(i2cbus, addr, offset, new_val);
if (res < 0)
{
return res;
}
return 0;
}
static char diag_flag = 0;
char diag_flag_set(char d)
{
diag_flag = d;
return 0;
}
char diag_flag_get(void)
{
return diag_flag;
}
char diag_debug_trace_on(void)
{
system("echo 1 > /tmp/onlpi_dbg_trace");
return 0;
}
char diag_debug_trace_off(void)
{
system("echo 0 > /tmp/onlpi_dbg_trace");
return 0;
}
char diag_debug_trace_check(void)
{
char flag = 0;
FILE *file = fopen("/tmp/onlpi_dbg_trace", "r");
if (file == NULL)
{
return 0;
}
flag = fgetc(file);
fclose(file);
return (flag == '1') ? 1 : 0;
}
char* sfp_control_to_str(int value)
{
switch (value)
{
case ONLP_SFP_CONTROL_RESET:
return "RESET";
case ONLP_SFP_CONTROL_RESET_STATE:
return "RESET_STATE";
case ONLP_SFP_CONTROL_RX_LOS:
return "RX_LOS";
case ONLP_SFP_CONTROL_TX_FAULT:
return "TX_FAULT";
case ONLP_SFP_CONTROL_TX_DISABLE:
return "TX_DISABLE";
case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL:
return "TX_DISABLE_CHANNEL";
case ONLP_SFP_CONTROL_LP_MODE:
return "LP_MODE";
case ONLP_SFP_CONTROL_POWER_OVERRIDE:
return "POWER_OVERRIDE";
default:
return "UNKNOW";
}
return "";
}
char diag_debug_pause_platform_manage_on(void)
{
system("echo 1 > /tmp/onlpi_dbg_pause_pm");
return 0;
}
char diag_debug_pause_platform_manage_off(void)
{
system("echo 0 > /tmp/onlpi_dbg_pause_pm");
return 0;
}
char diag_debug_pause_platform_manage_check(void)
{
char flag = 0;
FILE *file = fopen("/tmp/onlpi_dbg_pause_pm", "r");
if (file == NULL)
{
return 0;
}
flag = fgetc(file);
fclose(file);
return (flag == '1') ? 1 : 0;
}
#define ONIE_EEPROM_HEADER_LENGTH 11
int eeprom_tlv_read(uint8_t *rdata, char type, char *data)
{
uint8_t i, j, TLV_length;
int total_data_length = ((*(rdata + 9)) << 8) + (*(rdata + 10)) + ONIE_EEPROM_HEADER_LENGTH;
char TLV_type;
for (i = ONIE_EEPROM_HEADER_LENGTH; i < total_data_length;)
{
TLV_type = *(rdata + i);
TLV_length = *(rdata + i + 1);
//printf("Type:%d Len:%d\n", TLV_type,TLV_length);
if (TLV_type == type)
{
for (j = 0; j < TLV_length; j++)
{
data[j] = *(rdata + i + j + 2);
//printf("TLV match\n");
}
data[j] = '\0';
return 0;
}
i += (TLV_length + 2);
//printf("i:%d\n",i);
}
return 0;
}

View File

@@ -0,0 +1,249 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014 Big Switch Networks, Inc.
* Copyright 2018 Alpha Networks Incorporation.
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
************************************************************
*
*
*
***********************************************************/
#ifndef __PLATFORM_LIB_H__
#define __PLATFORM_LIB_H__
#include "x86_64_lenovo_ne2572_log.h"
//for ne2572
#define IDPROM_PATH "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/0-0056/eeprom"
//#define IDPROM_PATH "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-6/i2c-10/10-0051/eeprom"
#define PSU1_ID 1
#define PSU2_ID 2
#define PSU1_BUS_ID 11
#define PSU2_BUS_ID 10
#define CHASSIS_THERMAL_COUNT 2
#define CHASSIS_FAN_COUNT 6
#define PSU1_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/57-003c/"
#define PSU2_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/58-003f/"
#define PSU1_AC_HWMON_PREFIX "/sys/bus/i2c/devices/2-0050/"
#define PSU1_DC_HWMON_PREFIX "/sys/bus/i2c/devices/57-0050/"
#define PSU2_AC_HWMON_PREFIX "/sys/bus/i2c/devices/3-0050/"
#define PSU2_DC_HWMON_PREFIX "/sys/bus/i2c/devices/58-0053/"
#define PSU1_AC_HWMON_NODE(node) PSU1_AC_HWMON_PREFIX#node
#define PSU1_DC_HWMON_NODE(node) PSU1_DC_HWMON_PREFIX#node
#define PSU2_AC_HWMON_NODE(node) PSU2_AC_HWMON_PREFIX#node
#define PSU2_DC_HWMON_NODE(node) PSU2_DC_HWMON_PREFIX#node
#define NUM_OF_SFP_PORT 54
#define QSFP_START_INDEX 48
#define QSFP28_EEPROM_I2C_ADDR 0x50 /* QSFP28 EEPROM Physical Address in the I2C */
#define SFP_DOM_EEPROM_I2C_ADDR 0x51
#define QSFP28_EEPROM_TXRX_LOS_OFFSET 3
#define QSFP28_EEPROM_TX_FAULT_OFFSET 4
#define QSFP28_EEPROM_TX_DISABLE_OFFSET 86
#define QSFP28_EEPROM_POWERSET_OFFSET 93
#define QSFP28_EEPROM_PAGE_SELECT_OFFSET 127
typedef long long I64_T; /* 64-bit signed */
typedef unsigned long long UI64_T; /* 64-bit unsigned */
typedef long I32_T; /* 32-bit signed */
typedef unsigned long UI32_T; /* 32-bit unsigned */
typedef short int I16_T; /* 16-bit signed */
typedef unsigned short int UI16_T; /* 16-bit unsigned */
typedef char I8_T; /* 8-bit signed */
typedef unsigned char UI8_T; /* 8-bit unsigned */
/*----------------------------------------------------------*/
/* BIT operation */
/*----------------------------------------------------------*/
#define UTL_TEST_BITS(__type__,__var__,__pos__) \
(__type__)((((__type__)(__var__)>>(__type__)(__pos__))&(__type__)1)?(__type__)1:(__type__)0)
#define UTL_LEFT_SHIFT_BITS(__type__,__range__,__var__,__sft_bits__) \
(((__type__)(__sft_bits__)>=(__range__))?0:((__type__)(__var__)<<(__type__)(__sft_bits__)))
#define UTL_RIGHT_SHIFT_BITS(__type__,__range__,__var__,__sft_bits__) \
(((__type__)__sft_bits__>=(__range__))?(__type__)(__var__):((__type__)(__var__)>>(__type__)(__sft_bits__)))
#define UTL_SET_BITS(__type__,__range__,__var__,__pos__) \
((__type__)(__var__)|UTL_LEFT_SHIFT_BITS(__type__,__range__,(__type__)1U,(__type__)(__pos__)))
#define UTL_RESET_BITS(__type__,__range__,__var__,__pos__) \
((__type__)(__var__)&~UTL_LEFT_SHIFT_BITS(__type__,__range__,(__type__)1U,(__type__)(__pos__)))
/*----------------------------------------------------------*/
/* 64 BIT operation */
/*----------------------------------------------------------*/
#define UTL_TEST_BITS64(__var__,__pos__) UTL_TEST_BITS(UI64_T,__var__,__pos__)
#define UTL_SET_BITS64(__var__,__pos__) (__var__) = UTL_SET_BITS(UI64_T,64,__var__,__pos__)
#define UTL_RESET_BITS64(__var__,__pos__) (__var__) = UTL_RESET_BITS(UI64_T,64,__var__,__pos__)
/*----------------------------------------------------------*/
/* 32 BIT operation */
/*----------------------------------------------------------*/
/* Usage: if( UTL_TEST_BITS32(val,2) )*/
/* pos = 0~7, 0~15, 0~31 */
/* 0x1234 = 0001 0010 0011 0100 */
/* UTL_TEST_BITS32( 0x1234, 2 ) ==> 1 */
/* UTL_TEST_BITS32( 0x1234, 1 ) ==> 0 */
#define UTL_TEST_BITS32(__var__,__pos__) UTL_TEST_BITS(UI32_T,__var__,__pos__)
/* Usage: UTL_SET_BITS32( val, 6 ) */
/* pos = 0~7, 0~15, 0~31 */
/* val = 0x0100 = 0000 0001 0000 0000 */
/* UTL_SET_BITS32( val,6 )==> 0000 0001 0100 0000 */
/* UTL_RESET_BITS32( val,8 )=> 0000 0000 0000 0000 */
#define UTL_SET_BITS32(__var__,__pos__) (__var__) = UTL_SET_BITS(UI32_T,32,__var__,__pos__)
#define UTL_RESET_BITS32(__var__,__pos__) (__var__) = UTL_RESET_BITS(UI32_T,32,__var__,__pos__)
/*----------------------------------------------------------*/
/* 16 BIT operation */
/*----------------------------------------------------------*/
#define UTL_TEST_BITS16(__var__,__pos__) UTL_TEST_BITS(UI16_T,__var__,__pos__)
#define UTL_SET_BITS16(__var__,__pos__) (__var__) = UTL_SET_BITS(UI16_T,16,__var__,__pos__)
#define UTL_RESET_BITS16(__var__,__pos__) (__var__) = UTL_RESET_BITS(UI16_T,16,__var__,__pos__)
/*----------------------------------------------------------*/
/* 8 BIT operation */
/*----------------------------------------------------------*/
#define UTL_TEST_BITS8(__var__,__pos__) UTL_TEST_BITS(UI8_T,__var__,__pos__)
#define UTL_SET_BITS8(__var__,__pos__) (__var__) = UTL_SET_BITS(UI8_T,8,__var__,__pos__)
#define UTL_RESET_BITS8(__var__,__pos__) (__var__) = UTL_RESET_BITS(UI8_T,16,__var__,__pos__)
int deviceNodeWriteInt(char *filename, int value, int data_len);
int deviceNodeReadBinary(char *filename, char *buffer, int buf_size, int data_len);
int deviceNodeReadString(char *filename, char *buffer, int buf_size, int data_len);
typedef enum psu_type {
PSU_TYPE_UNKNOWN,
PSU_TYPE_AC_F2B,
PSU_TYPE_AC_B2F,
PSU_TYPE_DC_48V_F2B,
PSU_TYPE_DC_48V_B2F
} psu_type_t;
//psu_type_t get_psu_type(int id, char* modelname, int modelname_len);
int psu_two_complement_to_int(uint16_t data, uint8_t valid_bit, int mask);
/* FAN related data
*/
enum onlp_fan_id
{
FAN_RESERVED = 0,
FAN_1,
FAN_2,
FAN_3,
FAN_4,
FAN_5,
FAN_6,
FAN_1_ON_PSU1,
FAN_1_ON_PSU2,
};
/*
* LED ID (need to sync with "enum onlp_led_id" defined in ledi.c)
*/
enum onlp_led_id
{
LED_RESERVED = 0,
LED_SERVICE,
LED_STACKING,
LED_PWR,
LED_FAN,
LED_REAR_FAN1,
LED_REAR_FAN2,
LED_REAR_FAN3,
LED_REAR_FAN4,
LED_REAR_FAN5,
LED_REAR_FAN6,
};
/*
* TLV type code
*/
#define TLV_CODE_PRODUCT_NAME 0x21
#define TLV_CODE_PART_NUMBER 0x22
#define TLV_CODE_SERIAL_NUMBER 0x23
#define TLV_CODE_MAC_BASE 0x24
#define TLV_CODE_MANUF_DATE 0x25
#define TLV_CODE_DEVICE_VERSION 0x26
#define TLV_CODE_LABEL_REVISION 0x27
#define TLV_CODE_PLATFORM_NAME 0x28
#define TLV_CODE_ONIE_VERSION 0x29
#define TLV_CODE_MAC_SIZE 0x2A
#define TLV_CODE_MANUF_NAME 0x2B
#define TLV_CODE_MANUF_COUNTRY 0x2C
#define TLV_CODE_VENDOR_NAME 0x2D
#define TLV_CODE_DIAG_VERSION 0x2E
#define TLV_CODE_SERVICE_TAG 0x2F
#define TLV_CODE_VENDOR_EXT 0xFD
#define TLV_CODE_CRC_32 0xFE
/*
i2c APIs: access i2c device by ioctl
*/
#include <errno.h>
#include <linux/i2c-dev.h>
int i2c_read(int i2cbus, int addr, int offset, int length, char* data);
int i2c_sequential_read(int i2cbus, int addr, int offset, int length, char* data);
int i2c_read_byte(int i2cbus, int addr, int offset, char* data);
int i2c_read_word(int i2cbus, int addr, int command);
int i2c_read_block(int i2cbus, int addr, uint8_t offset, uint8_t *data, int length);
int i2c_read_i2c_block_dump(int i2cbus, int addr, uint8_t *data);
int i2c_write_byte(int i2cbus, int addr, int offset, char val);
int i2c_write_bit(int i2cbus, int addr, int offset, int bit, char val);
int i2c_read_rps_status(int i2cbus, int addr, int offset);
#define DIAG_FLAG_ON 1
#define DIAG_FLAG_OFF 0
char diag_flag_set(char d);
char diag_flag_get(void);
char diag_debug_trace_on(void);
char diag_debug_trace_off(void);
char diag_debug_trace_check(void);
char diag_debug_pause_platform_manage_on(void);
char diag_debug_pause_platform_manage_off(void);
char diag_debug_pause_platform_manage_check(void);
/*
* TLV parsering for specific type code
*/
int eeprom_tlv_read(uint8_t *rdata, char type, char *data);
#define DIAG_TRACE(fmt,args...) if(diag_debug_trace_check()) printf("\n[TRACE]"fmt"\n", args)
#define DIAG_PRINT(fmt,args...) DIAG_TRACE(fmt,args);else if(diag_flag_get()) printf("[DIAG]"fmt"\n", args)
char* sfp_control_to_str(int value);
#endif /* __PLATFORM_LIB_H__ */

View File

@@ -0,0 +1,418 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014 Big Switch Networks, Inc.
* Copyright 2018 Alpha Networks Incorporation.
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
************************************************************
*
*
*
***********************************************************/
#include <onlp/platformi/psui.h>
#include <onlplib/mmap.h>
#include <stdio.h>
#include <string.h>
#include "platform_lib.h"
#define PSUI_DEBUG_FLAG 0
#define PSU_STATUS_INTERRUPT 3
#define PSU_STATUS_PRESENT 2
#define PSU_STATUS_POWER_OK 1
#define PSU_STATUS_POWER_ON 0
#define PSU_NODE_MAX_INT_LEN 8
#define PSU_NODE_MAX_PATH_LEN 64
#define PSUI_CPLD_BUS_ID 0
#define PSUI_POWER_CPLD_ADDR 0x5E
#define RPS_PSU_EEPROM_ADDR 0x51
#define RPS_PSU_MICRO_P_ADDR 0x59
#define PSUI_MANUFACTURER_NAME_REG 0x0C
#define PSUI_PRODUCT_NAME_REG 0x12
#define PSUI_MODEL_NO_REG 0x1D
#define PSUI_PRODUCT_VER_NO_REG 0x1F
#define PSUI_PRODUCT_SER_NO_REG_F2B 0x23
#define PSUI_PRODUCT_SER_NO_REG_B2F 0x25
#define PSUI_PRODUCT_SER_NO_REG PSUI_PRODUCT_SER_NO_REG_B2F
#define PSUI_RPS_STATUS_REG0 0x04 /* PSU Status Register for PSU#1 */
#define PSUI_RPS_STATUS_REG1 0x03 /* PSU Status Register for PSU#2 */
#define PSUI_PRODUCT_SER_NO_SIZE 14
#define PSUI_PRODUCT_SER_NO_LEN (PSUI_PRODUCT_SER_NO_SIZE + 1)
#define PSUI_PRODUCT_NAME_SIZE 13
#define PSUI_PRODUCT_NAME_SIZE_F2B 11
#define PSUI_PRODUCT_NAME_SIZE_B2F 13
struct psui_reg_data_word
{
uint8_t reg;
uint16_t value;
};
struct psui_reg_data_word regs_word[] = { {0x88, 0}, /* READ_Vin */
{0x8b, 0}, /* READ_Vout */
{0x89, 0}, /* READ_Iin */
{0x8c, 0}, /* READ_Iout */
{0x96, 0}, /* READ_Pout */
{0x97, 0} /* READ_Pin */
};
#define GET_RPS_STATUS_BIT(x,n) (((x) >> (n)) & 1)
#define VALIDATE(_id) \
do { \
if(!ONLP_OID_IS_PSU(_id)) { \
return ONLP_STATUS_E_INVALID; \
} \
} while(0)
int
psu_ne2572_linear_format(int exponent, int mantissa)
{
int multiplier = 1000;/* Units are "milli-" */
return (exponent >= 0) ? (mantissa << exponent) * multiplier :
(mantissa * multiplier) / (1 << -exponent);
}
int
onlp_psui_init(void)
{
DIAG_PRINT("%s", __FUNCTION__);
return ONLP_STATUS_OK;
}
static int
psu_info_get_product_name(int id, UI8_T *data)
{
DIAG_PRINT("%s, id:%d", __FUNCTION__, id);
int ret = 0;
ret = i2c_read_block(id, RPS_PSU_EEPROM_ADDR, PSUI_PRODUCT_NAME_REG, data, PSUI_PRODUCT_NAME_SIZE);
if (ret < 0 && PSUI_DEBUG_FLAG)
printf("I2C command 0x%X Read Fail, id=%d\n", PSUI_PRODUCT_NAME_REG,id);
return ret;
}
static int
psu_info_get_product_ser(psu_type_t psu_type, int id, UI8_T *data)
{
int ret = 0;
int addr = 0 ;
DIAG_PRINT("%s, id:%d", __FUNCTION__, id);
if (psu_type == PSU_TYPE_AC_F2B)
{
addr = PSUI_PRODUCT_SER_NO_REG_F2B;
}
else
{
addr = PSUI_PRODUCT_SER_NO_REG_B2F;
}
ret = i2c_read_block(id, RPS_PSU_EEPROM_ADDR, addr, data, PSUI_PRODUCT_SER_NO_SIZE);
if (ret < 0)
printf("I2C command 0x%X Read Fail, id=%d\n", addr,id);
return ret;
}
static int
psu_info_get_status(int id, char *data)
{
DIAG_PRINT("%s, id:%d", __FUNCTION__, id);
int ret = 0;
if (id == PSU1_ID)
{
ret = i2c_read_rps_status(PSUI_CPLD_BUS_ID, PSUI_POWER_CPLD_ADDR, PSUI_RPS_STATUS_REG0);
if (ret < 0)
printf("I2C command 0x%X Read Fail, id=%d\n", PSUI_RPS_STATUS_REG0, PSUI_CPLD_BUS_ID);
}
else if (id == PSU2_ID)
{
ret = i2c_read_rps_status(PSUI_CPLD_BUS_ID, PSUI_POWER_CPLD_ADDR, PSUI_RPS_STATUS_REG1);
if (ret < 0)
printf("I2C command 0x%X Read Fail, id=%d\n", PSUI_RPS_STATUS_REG1, PSUI_CPLD_BUS_ID);
}
sprintf (data, "%d\n", ret);
return ret;
}
static int
psu_ne2572_info_get(int id, onlp_psu_info_t* info)
{
DIAG_PRINT("%s, id:%d", __FUNCTION__, id);
//int val = 0;
//int index = ONLP_OID_ID_GET(info->hdr.id);
/* Set capability
*/
info->caps = ONLP_PSU_CAPS_AC;
if (info->status & ONLP_PSU_STATUS_FAILED)
{
return ONLP_STATUS_OK;
}
/* Set the associated oid_table */
//info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT);
//info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT);
#if 1
int i = 0;
int status;
int exponent, mantissa;
for (i = 0; i < 6; i++)
{
//printf("I2C register 0x%X \n", regs_word[i].reg);
status = i2c_read_word(id, RPS_PSU_MICRO_P_ADDR, regs_word[i].reg);
if (status < 0)
printf("I2C command 0x%X Read Fail\n", regs_word[i].reg);
else
{
//printf("I2C command 0x%X Read Success: 0x%02x\n", regs_word[i].reg, status);
regs_word[i].value = status;
}
}
info->caps |= ONLP_PSU_CAPS_VOUT;
info->caps |= ONLP_PSU_CAPS_VIN;
info->caps |= ONLP_PSU_CAPS_IOUT;
info->caps |= ONLP_PSU_CAPS_IIN;
info->caps |= ONLP_PSU_CAPS_POUT;
info->caps |= ONLP_PSU_CAPS_PIN;
/* Linear_5s_11s */
exponent = psu_two_complement_to_int(regs_word[0].value >> 11, 5, 0x1f);
mantissa = psu_two_complement_to_int(regs_word[0].value & 0x7ff, 11, 0x7ff);
info->mvin = psu_ne2572_linear_format(exponent, mantissa);
/* Linear_16u */
exponent = -12;
mantissa = regs_word[1].value;
info->mvout = psu_ne2572_linear_format(exponent, mantissa);
exponent = psu_two_complement_to_int(regs_word[2].value >> 11, 5, 0x1f);
mantissa = psu_two_complement_to_int(regs_word[2].value & 0x7ff, 11, 0x7ff);
info->miin = psu_ne2572_linear_format(exponent, mantissa);
exponent = psu_two_complement_to_int(regs_word[3].value >> 11, 5, 0x1f);
mantissa = psu_two_complement_to_int(regs_word[3].value & 0x7ff, 11, 0x7ff);
info->miout = psu_ne2572_linear_format(exponent, mantissa);
exponent = psu_two_complement_to_int(regs_word[4].value >> 11, 5, 0x1f);
mantissa = psu_two_complement_to_int(regs_word[4].value & 0x7ff, 11, 0x7ff);
info->mpout = psu_ne2572_linear_format(exponent, mantissa);
exponent = psu_two_complement_to_int(regs_word[5].value >> 11, 5, 0x1f);
mantissa = psu_two_complement_to_int(regs_word[5].value & 0x7ff, 11, 0x7ff);
info->mpin = psu_ne2572_linear_format(exponent, mantissa);
#endif
return ONLP_STATUS_OK;
}
int
psu_um400d_info_get(onlp_psu_info_t* info)
{
DIAG_PRINT("%s", __FUNCTION__);
int index = ONLP_OID_ID_GET(info->hdr.id);
/* Set capability
*/
info->caps = ONLP_PSU_CAPS_DC48;
if (info->status & ONLP_PSU_STATUS_FAILED)
{
return ONLP_STATUS_OK;
}
/* Set the associated oid_table */
info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT);
return ONLP_STATUS_OK;
}
/*
* Get all information about the given PSU oid.
*/
static onlp_psu_info_t pinfo[] =
{
{ }, /* Not used */
{ /* PSU-1 is on i2c channel 10 for ne2572*/
{ ONLP_PSU_ID_CREATE(PSU1_ID), "PSU-1", 0 },
},
{ /* PSU-2 is on i2c channel 11 for ne2572*/
{ ONLP_PSU_ID_CREATE(PSU2_ID), "PSU-2", 0 },
}
};
psu_type_t get_psu_type(int id, char* product_name, int productname_len)
{
DIAG_PRINT("%s, id:%d", __FUNCTION__, id);
UI8_T p_name[PSUI_PRODUCT_NAME_SIZE + 1] = {0};
/* Check AC model name */
if (psu_info_get_product_name(id, p_name) >= 0)
{
//printf("[psu_info_get_product_name] %s\n", p_name);
if (strncmp((char*)p_name, "DPS-770GB E", strlen("DPS-770GB E")) == 0)
{
if (product_name)
memcpy(product_name, p_name, PSUI_PRODUCT_NAME_SIZE_F2B);
return PSU_TYPE_AC_F2B;
}
else if (strncmp((char*)p_name, "DPS-770GB-1 A", strlen("DPS-770GB-1 A")) == 0)
{
if (product_name)
memcpy(product_name, p_name, PSUI_PRODUCT_NAME_SIZE_B2F);
return PSU_TYPE_AC_B2F;
}
#if 0
else if (strncmp((char*)p_name, "DPS-770GB", strlen("DPS-770GB")) == 0)
{
if (product_name)
memcpy(product_name, p_name, productname_len-1);
return PSU_TYPE_AC_B2F;
}
#endif
}
return PSU_TYPE_UNKNOWN;
}
int
onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info)
{
char name[ONLP_CONFIG_INFO_STR_MAX];
char status;
int ret = ONLP_STATUS_OK;
int index = ONLP_OID_ID_GET(id);
psu_type_t psu_type;
UI8_T product_ser[PSUI_PRODUCT_SER_NO_LEN];
UI8_T rps_status = 0, power_ok = 0, power_on = 0, power_present = 0;
VALIDATE(id);
memset(info, 0, sizeof(onlp_psu_info_t));
memset(name, 0, sizeof(name));
*info = pinfo[index]; /* Set the onlp_oid_hdr_t */
/* Get PSU type and product name, bus ID=index+10*/
if( index == 1)
psu_type = get_psu_type(PSU1_BUS_ID, info->model, sizeof(info->model));
else if( index == 2)
psu_type = get_psu_type(PSU2_BUS_ID, info->model, sizeof(info->model));
//debug
DIAG_PRINT("%s, id:%d, index:%d, psu_type:%d\n",__FUNCTION__,id,index,psu_type);
switch (psu_type)
{
case PSU_TYPE_AC_F2B:
case PSU_TYPE_AC_B2F:
if( index == 1)
ret = psu_ne2572_info_get(PSU1_BUS_ID, info);/* Get PSU electric info from PMBus */
else if (index == 2)
ret = psu_ne2572_info_get(PSU2_BUS_ID, info);/* Get PSU electric info from PMBus */
break;
case PSU_TYPE_DC_48V_F2B:
case PSU_TYPE_DC_48V_B2F:
ret = psu_um400d_info_get(info);
break;
default:
ret = ONLP_STATUS_E_UNSUPPORTED;
return ret;
}
/* Get the product serial number, bus ID=index+10 */
if(index == 1)
{
if (psu_info_get_product_ser(psu_type, PSU1_BUS_ID, product_ser) < 0)
{
printf("Unable to read PSU(%d) item(serial number)\r\n", index);
}
else
{
memcpy(info->serial, product_ser, sizeof(product_ser));
}
}
else if( index == 2)
{
if (psu_info_get_product_ser(psu_type, PSU2_BUS_ID, product_ser) < 0)
{
printf("Unable to read PSU(%d) item(serial number)\r\n", index);
}
else
{
memcpy(info->serial, product_ser, sizeof(product_ser));
}
}
/* Get psu status from CPLD */
if (psu_info_get_status(index, &status) < 0)
{
printf("Unable to read PSU(%d) item(psu status)\r\n", index);
}
else
{
rps_status = (UI8_T)atoi(&status);
power_present = GET_RPS_STATUS_BIT(rps_status, PSU_STATUS_PRESENT);
power_ok = GET_RPS_STATUS_BIT(rps_status, PSU_STATUS_POWER_OK);
power_on = GET_RPS_STATUS_BIT(rps_status, PSU_STATUS_POWER_ON);
/* Empty */
if (!power_present)
{
info->status |= ONLP_PSU_STATUS_UNPLUGGED;
}
if (!power_ok)
{
info->status |= ONLP_PSU_STATUS_FAILED;
}
if (power_on)
{
info->status |= ONLP_PSU_STATUS_PRESENT;
}
DIAG_PRINT("rps_status:0x%x ,info->status:0x%x\n", rps_status, info->status);
DIAG_PRINT("present:%d, ok:%d, on:%d\n", power_present, power_ok, power_on);
}
return ret;
}
int
onlp_psui_ioctl(onlp_oid_t pid, va_list vargs)
{
DIAG_PRINT("%s, pid=%d", __FUNCTION__, pid);
return ONLP_STATUS_E_UNSUPPORTED;
}

View File

@@ -0,0 +1,827 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014 Big Switch Networks, Inc.
* Copyright 2018 Alpha Networks Incorporation.
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
************************************************************
*
*
*
***********************************************************/
#include <onlp/platformi/sfpi.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <onlplib/i2c.h>
#include "platform_lib.h"
#define DEBUG 0
#define SYSTEM_CPLD_I2C_BUS_ID 8
#define SYSTEM_CPLD_I2C_ADDR 0x5F /* System CPLD Physical Address in the I2C */
#define SYSTEM_CPLD_RESET1_ADDR_OFFSET 0x02
#define PORT_CPLD0_I2C_BUS_ID 13
#define PORT_CPLD1_I2C_BUS_ID 15
#define PORT_CPLD2_I2C_BUS_ID 17
//#define PORT_CPLD_I2C_ADDR 0x5F /* Port CPLD Physical Address in the I2C */
#define PORT_CPLD0_I2C_ADDR 0x5B
#define PORT_CPLD1_I2C_ADDR 0x5C
#define PORT_CPLD2_I2C_ADDR 0x5D
#define PORT_CPLD2_MODULE_SELECT_ADDR_OFFSET 0x0B
#define PORT_CPLD_PRESENT_ADDR_OFFSET 0x05
#define PORT_CPLD_RESET_ADDR_OFFSET 0x07
#define PORT_CPLD_LOWPWR_ADDR_OFFSET 0x09
#define PORT_CPLD_MOD_SEL_ADDR_OFFSET 0x0B /* Module Select of QSFP ports */
#define PORT_CPLD_SFP_PRESENT_ADDR_OFFSET 0x16
#define PORT_CPLD_SFP_RX_LOS_ADDR_OFFSET 0x13
#define PORT_CPLD_SFP_TX_FAULT_ADDR_OFFSET 0x10
#define PORT_CPLD_SFP_TX_DISABLE_ADDR_OFFSET 0x19
#define SFP_I2C_BUS_ID_BASE 21
static int
port_to_busid(int port)
{
int index = 0;
index = port + SFP_I2C_BUS_ID_BASE;
DIAG_PRINT("%s, port:%d, busid:%d ", __FUNCTION__, port, index);
return index;
}
static int
port_to_cpld_busid(int port)
{
int index = 0;
int ret = 0;
index = port / 24;
ret = (index * 2) + PORT_CPLD0_I2C_BUS_ID;
DIAG_PRINT("%s, port:%d, cpld_busid:%d ", __FUNCTION__, port, ret);
return ret;
}
static int
port_to_cpld_addr(int port)
{
int index = 0;
int ret = 0;
index = port / 24;
ret = index + PORT_CPLD0_I2C_ADDR;
DIAG_PRINT("%s, port:%d, cpld_busaddr:%d ", __FUNCTION__, port, ret);
return ret;
}
static int
port_to_cpld_sfp_offset(int port, int start_index)
{
int index = 0;
int ret = 0;
if (port < QSFP_START_INDEX)
{
index = (port / 8) % 3;
ret = index + start_index;
}
else
{
AIM_LOG_INFO("%s:%d invaild sfp port index(%d), start_index:%d\n", __FUNCTION__, __LINE__, port, start_index);
}
DIAG_PRINT("%s, port:%d, present_offset:0x%X, start_index:%d, index:%d", __FUNCTION__, port, ret, start_index, index);
return ret;
}
static int
port_to_cpld_present_offset(int port)
{
int ret = 0;
if (port < QSFP_START_INDEX)
{
ret = port_to_cpld_sfp_offset(port, PORT_CPLD_SFP_PRESENT_ADDR_OFFSET);
}
else
{
ret = PORT_CPLD_PRESENT_ADDR_OFFSET; // QSFP28 Transceiver Present Register
}
DIAG_PRINT("%s, port:%d, present_offset:%d ", __FUNCTION__, port, ret);
return ret;
}
static int
port_to_cpld_port_bit(int port)
{
int index = 0;
index = (port % 8);
DIAG_PRINT("%s, port:%d, present_bit:%d ", __FUNCTION__, port, index);
return index;
}
static int
_sfp_present(int port)
{
int ret = 0;
char data = 0;
DIAG_PRINT("%s, port:%d", __FUNCTION__, port);
int busid = port_to_cpld_busid(port);
int addr = port_to_cpld_addr(port);
int offset = port_to_cpld_present_offset(port);
ret = i2c_read_byte(busid, addr, offset, &data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
if (DEBUG)
AIM_LOG_INFO("%s:%d port[%d],busid[%d],addr[0x%2X],offset[0x%02X],read_byte[%02x]\n", __FUNCTION__, __LINE__,
port, busid, addr, offset, (unsigned char)data);
if (data & (1 << port_to_cpld_port_bit(port)))
{
return 1;
}
return 0;
}
/************************************************************
*
* SFPI Entry Points
*
***********************************************************/
int
onlp_sfpi_init(void)
{
DIAG_PRINT("%s", __FUNCTION__);
int ret = 0;
char data = 0;
/* pull low for Reset Register 1 of Port CPLD */
ret = i2c_write_byte(SYSTEM_CPLD_I2C_BUS_ID, SYSTEM_CPLD_I2C_ADDR, SYSTEM_CPLD_RESET1_ADDR_OFFSET, data);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
//Module select
ret = i2c_write_byte(PORT_CPLD2_I2C_BUS_ID, PORT_CPLD2_I2C_ADDR, PORT_CPLD2_MODULE_SELECT_ADDR_OFFSET, 0x3F); //bit 0~5
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
return ONLP_STATUS_OK;
}
int
onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t *bmap)
{
int p = 0;
AIM_BITMAP_CLR_ALL(bmap);
for (p = 0; p < NUM_OF_SFP_PORT; p++)
{
AIM_BITMAP_SET(bmap, p);
}
DIAG_PRINT("%s", __FUNCTION__);
return ONLP_STATUS_OK;
}
int
onlp_sfpi_is_present(int port)
{
/*
* Return 1 if present.
* Return 0 if not present.
* Return < 0 if error.
*/
int present = 0;
present = _sfp_present(port);
DIAG_PRINT("%s, port=%d, present:%d", __FUNCTION__, port, present);
return present;
}
int
onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t *dst)
{
DIAG_PRINT("%s", __FUNCTION__);
int i = 0;
AIM_BITMAP_CLR_ALL(dst);
for (i = 0; i < NUM_OF_SFP_PORT; i++)
{
if (onlp_sfpi_is_present(i))
{
AIM_BITMAP_SET(dst, i);
}
}
return ONLP_STATUS_OK;
}
int
onlp_sfpi_eeprom_read(int port, uint8_t data[256])
{
int busid = port_to_busid(port);
DIAG_PRINT("%s, port:%d, busid:%d", __FUNCTION__, port, busid);
/*
* Read the SFP eeprom into data[]
*/
memset(data, 0x0, 256);
if (i2c_read(busid, QSFP28_EEPROM_I2C_ADDR, 0x0, 256, (char *)data) != 0)
{
AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port);
return ONLP_STATUS_E_INTERNAL;
}
return ONLP_STATUS_OK;
}
int onlp_sfpi_dom_read(int port, uint8_t data[256])
{
int busid = port_to_busid(port);
int ret = 0;
memset(data, 0x0, 256);
DIAG_PRINT("%s, port:%d, busid:%d", __FUNCTION__, port, busid);
if (port < QSFP_START_INDEX)
{
if (i2c_read(busid, SFP_DOM_EEPROM_I2C_ADDR, 0x0, 256, (char *)data) != 0)
{
AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port);
return ONLP_STATUS_E_INTERNAL;
}
}
else
{
//Set page select to pahe 00h.
ret = onlp_sfpi_dev_writeb(port, QSFP28_EEPROM_I2C_ADDR, QSFP28_EEPROM_PAGE_SELECT_OFFSET, 0);
if (ret < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ret);
return ret;
}
if (i2c_read(busid, QSFP28_EEPROM_I2C_ADDR, 0x0, 256, (char *)data) != 0)
{
AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port);
return ONLP_STATUS_E_INTERNAL;
}
}
return ONLP_STATUS_OK;
}
int
onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr)
{
int ret = 0;
int bus = port_to_busid(port);
ret = onlp_i2c_readb(bus, devaddr, addr, ONLP_I2C_F_FORCE);
DIAG_PRINT("%s, port:%d, devaddr:%d, addr:%d, ret:%d(0x%02X)", __FUNCTION__, port, devaddr, addr, ret, ret);
return ret;
}
int
onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value)
{
int ret = 0;
int bus = port_to_busid(port);
ret = onlp_i2c_writeb(bus, devaddr, addr, value, ONLP_I2C_F_FORCE);
DIAG_PRINT("%s, port:%d, devaddr:%d, addr:%d, value:%d(0x%02X), ret:%d", __FUNCTION__, port, devaddr, addr, value, value, ret);
return ret;
}
int
onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr)
{
int ret = 0;
int bus = port_to_busid(port);
ret = onlp_i2c_readw(bus, devaddr, addr, ONLP_I2C_F_FORCE);
DIAG_PRINT("%s, port:%d, devaddr:%d, addr:%d, ret:%d(0x%04X)", __FUNCTION__, port, devaddr, addr, ret, ret);
return ret;
}
int
onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value)
{
int ret = 0;
int bus = port_to_busid(port);
ret = onlp_i2c_writew(bus, devaddr, addr, value, ONLP_I2C_F_FORCE);
DIAG_PRINT("%s, port:%d, devaddr:%d, addr:%d, value:%d(0x%04X), ret:%d", __FUNCTION__, port, devaddr, addr, value, value, ret);
return ret;
}
/*
Reset and LP mode can control by CPLD so the setting will be keep in CPLD.
For other options, control is get/set to QSFP28.
Control options set to QSFP28 will be lost when the QSFP28 is removed.
Upper layer software system should keep the configuration and set it again when detect a new sfp module insert.
[QSFP]
function R/W CPLD EEPROM
------------------------------------ --- ------------- -----------------
ONLP_SFP_CONTROL_RESET W 0x7
ONLP_SFP_CONTROL_RESET_STATE R/W 0x7
ONLP_SFP_CONTROL_RX_LOS R none byte 4
ONLP_SFP_CONTROL_TX_FAULT R none byte 3
ONLP_SFP_CONTROL_TX_DISABLE R/W none byte 86
ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL R/W none byte 86
ONLP_SFP_CONTROL_LP_MODE R/W 0x9
ONLP_SFP_CONTROL_POWER_OVERRIDE R/W none byte 93
[SFP]
function R/W CPLD
------------------------------------ --- ---------------
ONLP_SFP_CONTROL_RESET Not Support(There is no RESET pin in SFP module)
ONLP_SFP_CONTROL_RESET_STATE Not Support(There is no RESET pin in SFP module)
ONLP_SFP_CONTROL_RX_LOS R 0x13/0x14/0x15
ONLP_SFP_CONTROL_TX_FAULT R 0x10/0x11/0x12
ONLP_SFP_CONTROL_TX_DISABLE R/W 0x19/0x1A/0x1B
ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL Not Support(It is for QSFP)
ONLP_SFP_CONTROL_LP_MODE Not Support(It is for QSFP)
ONLP_SFP_CONTROL_POWER_OVERRIDE Not Support(It is for QSFP)
*/
int onlp_sfpi_control_supported(int port, onlp_sfp_control_t control, int *supported)
{
if (supported == NULL)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_PARAM);
return ONLP_STATUS_E_PARAM;
}
*supported = 0;
switch (control)
{
case ONLP_SFP_CONTROL_RX_LOS:
case ONLP_SFP_CONTROL_TX_FAULT:
case ONLP_SFP_CONTROL_TX_DISABLE:
*supported = 1;
break;
case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL:
case ONLP_SFP_CONTROL_RESET:
case ONLP_SFP_CONTROL_RESET_STATE:
case ONLP_SFP_CONTROL_LP_MODE:
case ONLP_SFP_CONTROL_POWER_OVERRIDE:
if (port < QSFP_START_INDEX) //SFP port, those options are designed for QSFP.
*supported = 0;
else
*supported = 1;
break;
default:
*supported = 0;
break;
}
DIAG_PRINT("%s, port:%d, control:%d(%s), supported:%d", __FUNCTION__, port, control, sfp_control_to_str(control), *supported);
return ONLP_STATUS_OK;
}
int
onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value)
{
int rv = ONLP_STATUS_OK;
int bus = port_to_busid(port);
int cpld_bus = port_to_cpld_busid(port);
int addr = port_to_cpld_addr(port);
int offset = 0;
int port_bit = port_to_cpld_port_bit(port);
int supported = 0;
char optval = 0;
if ((onlp_sfpi_control_supported(port, control, &supported) == ONLP_STATUS_OK) && (supported == 0))
return ONLP_STATUS_E_UNSUPPORTED;
DIAG_PRINT("%s, port:%d, control:%d(%s), value:0x%X", __FUNCTION__, port, control, sfp_control_to_str(control), value);
if (port < QSFP_START_INDEX) //SFP
{
switch (control)
{
case ONLP_SFP_CONTROL_TX_DISABLE:
offset = port_to_cpld_sfp_offset(port, PORT_CPLD_SFP_TX_DISABLE_ADDR_OFFSET);
break;
default:
return ONLP_STATUS_E_UNSUPPORTED;
break;
}
optval = onlp_i2c_readb(cpld_bus, addr, offset, ONLP_I2C_F_FORCE);
if (value != 0)
{
optval |= (1 << port_bit);
}
else
{
optval &= !(1 << port_bit);
}
rv = onlp_i2c_writeb(cpld_bus, addr, offset, optval, ONLP_I2C_F_FORCE);
if (rv < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, rv);
return rv;
}
}
else
{
switch (control)
{
case ONLP_SFP_CONTROL_RESET:
if (value == 0) //set ONLP_SFP_CONTROL_RESET_STATE to 0
{
rv = onlp_sfpi_control_set(port, ONLP_SFP_CONTROL_RESET_STATE, 0);
break;
}
rv = onlp_sfpi_control_set(port, ONLP_SFP_CONTROL_RESET_STATE, 1);
if (rv < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, rv);
return rv;
}
rv = onlp_sfpi_control_set(port, ONLP_SFP_CONTROL_RESET_STATE, 0);
if (rv < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, rv);
return rv;
}
break;
case ONLP_SFP_CONTROL_RESET_STATE:
offset = PORT_CPLD_RESET_ADDR_OFFSET;
optval = onlp_i2c_readb(cpld_bus, addr, offset, ONLP_I2C_F_FORCE);
if (value != 0)
{
optval |= (1 << port_bit);
}
else
{
optval &= !(1 << port_bit);
}
rv = onlp_i2c_writeb(cpld_bus, addr, offset, optval, ONLP_I2C_F_FORCE);
if (rv < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, rv);
return rv;
}
break;
case ONLP_SFP_CONTROL_TX_DISABLE:
if (onlp_sfpi_is_present(port) == 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_MISSING);
return ONLP_STATUS_E_MISSING;
}
offset = QSFP28_EEPROM_TX_DISABLE_OFFSET;
addr = QSFP28_EEPROM_I2C_ADDR;
optval = onlp_i2c_readb(bus, addr, offset, ONLP_I2C_F_FORCE);
if (value != 0)
{
optval |= 0x0f; //bit 0~3
}
else
{
optval &= !(0x0f);
}
rv = onlp_i2c_writeb(bus, addr, offset, optval, ONLP_I2C_F_FORCE);
if (rv < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, rv);
return rv;
}
break;
case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL:
if (onlp_sfpi_is_present(port) == 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_MISSING);
return ONLP_STATUS_E_MISSING;
}
if (value < 0 || value > 0x0f)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_PARAM);
return ONLP_STATUS_E_PARAM;
}
offset = QSFP28_EEPROM_TX_DISABLE_OFFSET;
addr = QSFP28_EEPROM_I2C_ADDR;
optval = value;
rv = onlp_i2c_writeb(bus, addr, offset, optval, ONLP_I2C_F_FORCE);
if (rv < 0)
return rv;
break;
case ONLP_SFP_CONTROL_POWER_OVERRIDE:
if (onlp_sfpi_is_present(port) == 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_MISSING);
return ONLP_STATUS_E_MISSING;
}
offset = QSFP28_EEPROM_POWERSET_OFFSET;
addr = QSFP28_EEPROM_I2C_ADDR;
optval = onlp_i2c_readb(bus, addr, offset, ONLP_I2C_F_FORCE);
if (value != 0)
{
optval |= 0x01;
}
else
{
optval &= !(0x01);
}
rv = onlp_i2c_writeb(bus, addr, offset, optval, ONLP_I2C_F_FORCE);
if (rv < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, rv);
return rv;
}
break;
case ONLP_SFP_CONTROL_LP_MODE:
offset = PORT_CPLD_LOWPWR_ADDR_OFFSET;
optval = onlp_i2c_readb(cpld_bus, addr, offset, ONLP_I2C_F_FORCE);
if (value != 0)
{
optval |= (1 << port_bit);
}
else
{
optval &= !(1 << port_bit);
}
rv = onlp_i2c_writeb(cpld_bus, addr, offset, optval, ONLP_I2C_F_FORCE);
if (rv < 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, rv);
return rv;
}
break;
//Read Only
case ONLP_SFP_CONTROL_RX_LOS:
case ONLP_SFP_CONTROL_TX_FAULT:
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_INVALID);
return ONLP_STATUS_E_INVALID;
break;
default:
break;
}
}
DIAG_PRINT("%s, port_bit:%d, bus:%d, cpld_bus:%d, addr:0x%X, offset:0x%X", __FUNCTION__, port_bit, bus, cpld_bus, addr, offset);
return rv;
}
int
onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int *value)
{
int rv = ONLP_STATUS_OK;
int bus = port_to_busid(port);
int cpld_bus = port_to_cpld_busid(port);
int addr = port_to_cpld_addr(port);
int offset = 0;
int port_bit = port_to_cpld_port_bit(port);
int supported = 0;
char optval = 0;
if (value == NULL)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_PARAM);
return ONLP_STATUS_E_PARAM;
}
if ((onlp_sfpi_control_supported(port, control, &supported) == ONLP_STATUS_OK) && (supported == 0))
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_UNSUPPORTED);
return ONLP_STATUS_E_UNSUPPORTED;
}
*value = 0;
if (port < QSFP_START_INDEX) //SFP
{
switch (control)
{
case ONLP_SFP_CONTROL_RX_LOS:
offset = port_to_cpld_sfp_offset(port, PORT_CPLD_SFP_RX_LOS_ADDR_OFFSET);
break;
case ONLP_SFP_CONTROL_TX_FAULT:
offset = port_to_cpld_sfp_offset(port, PORT_CPLD_SFP_TX_FAULT_ADDR_OFFSET);
break;
case ONLP_SFP_CONTROL_TX_DISABLE:
offset = port_to_cpld_sfp_offset(port, PORT_CPLD_SFP_TX_DISABLE_ADDR_OFFSET);
break;
default:
return ONLP_STATUS_E_UNSUPPORTED;
break;
}
optval = onlp_i2c_readb(cpld_bus, addr, offset, ONLP_I2C_F_FORCE);
if ((optval & (1 << port_bit)) != 0) //1
{
*value = 1;
}
else
{
*value = 0;
}
}
else //QSFP
{
switch (control)
{
case ONLP_SFP_CONTROL_RESET_STATE:
offset = PORT_CPLD_RESET_ADDR_OFFSET;
optval = onlp_i2c_readb(cpld_bus, addr, offset, ONLP_I2C_F_FORCE);
if ((optval & (1 << port_bit)) != 0) //1
{
*value = 1;
}
else
{
*value = 0;
}
break;
case ONLP_SFP_CONTROL_RX_LOS:
if (onlp_sfpi_is_present(port) == 0)
{
#if 1 //for display RX_LOS Bitmap in onlpdump
*value = 0;
break;
#else
return ONLP_STATUS_E_MISSING;
#endif
}
offset = QSFP28_EEPROM_TXRX_LOS_OFFSET;
addr = QSFP28_EEPROM_I2C_ADDR;
optval = onlp_i2c_readb(bus, addr, offset, ONLP_I2C_F_FORCE);
if ((optval & (0x0f)) != 0) //bit 0~3
{
*value = 1;
}
else
{
*value = 0;
}
break;
case ONLP_SFP_CONTROL_TX_FAULT:
if (onlp_sfpi_is_present(port) == 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_MISSING);
return ONLP_STATUS_E_MISSING;
}
offset = QSFP28_EEPROM_TX_FAULT_OFFSET;
addr = QSFP28_EEPROM_I2C_ADDR;
optval = onlp_i2c_readb(bus, addr, offset, ONLP_I2C_F_FORCE);
if ((optval & (0x0f)) != 0) //bit 0~3
{
*value = 1;
}
else
{
*value = 0;
}
break;
case ONLP_SFP_CONTROL_TX_DISABLE:
if (onlp_sfpi_is_present(port) == 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_MISSING);
return ONLP_STATUS_E_MISSING;
}
offset = QSFP28_EEPROM_TX_DISABLE_OFFSET;
addr = QSFP28_EEPROM_I2C_ADDR;
optval = onlp_i2c_readb(bus, addr, offset, ONLP_I2C_F_FORCE);
if ((optval & (0x0f)) != 0) //bit 0~3
{
*value = 1;
}
else
{
*value = 0;
}
break;
case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL:
if (onlp_sfpi_is_present(port) == 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_MISSING);
return ONLP_STATUS_E_MISSING;
}
offset = QSFP28_EEPROM_TX_DISABLE_OFFSET;
addr = QSFP28_EEPROM_I2C_ADDR;
optval = onlp_i2c_readb(bus, addr, offset, ONLP_I2C_F_FORCE);
*value = optval & (0x0f); //bit 0~3
break;
case ONLP_SFP_CONTROL_LP_MODE:
offset = PORT_CPLD_LOWPWR_ADDR_OFFSET;
optval = onlp_i2c_readb(cpld_bus, addr, offset, ONLP_I2C_F_FORCE);
if ((optval & (1 << port_bit)) != 0)
{
*value = 1;
}
else
{
*value = 0;
}
break;
case ONLP_SFP_CONTROL_POWER_OVERRIDE:
if (onlp_sfpi_is_present(port) == 0)
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_MISSING);
return ONLP_STATUS_E_MISSING;
}
offset = QSFP28_EEPROM_POWERSET_OFFSET;
addr = QSFP28_EEPROM_I2C_ADDR;
optval = onlp_i2c_readb(bus, addr, offset, ONLP_I2C_F_FORCE);
if ((optval & (0x01)) != 0) //bit 0
{
*value = 1;
}
else
{
*value = 0;
}
break;
//Set Only
case ONLP_SFP_CONTROL_RESET:
{
AIM_LOG_INFO("%s:%d fail[%d]\n", __FUNCTION__, __LINE__, ONLP_STATUS_E_INVALID);
return ONLP_STATUS_E_INVALID;
}
default:
return ONLP_STATUS_E_UNSUPPORTED;
break;
}
}
DIAG_PRINT("%s, port_bit:%d, bus:%d, cpld_bus:%d, addr:0x%X, offset:0x%X", __FUNCTION__, port_bit, bus, cpld_bus, addr, offset);
DIAG_PRINT("%s, port:%d, control:%d(%s), value:0x%X", __FUNCTION__, port, control, sfp_control_to_str(control), *value);
return rv;
}
int
onlp_sfpi_denit(void)
{
DIAG_PRINT("%s", __FUNCTION__);
return ONLP_STATUS_OK;
}

View File

@@ -0,0 +1,148 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014, 2015 Big Switch Networks, Inc.
* Copyright 2018 Alpha Networks Incorporation
*
* Licensed under the Eclipse Public License, Version 1.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.eclipse.org/legal/epl-v10.html
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*
* </bsn.cl>
************************************************************
*
* Thermal Sensor Platform Implementation.
*
***********************************************************/
#include <unistd.h>
#include <onlplib/mmap.h>
#include <onlplib/file.h>
#include <onlp/platformi/thermali.h>
#include <fcntl.h>
#include "platform_lib.h"
#define LOCAL_DEBUG 0
#define THERMALI_LM75_HOT_SPOT_ADDR 0x4d /* NE2572 thermal addr */
#define THERMALI_LM75_AMBIENT_ADDR 0x4c /* NE2572 thermal addr */
#define THERMALI_HOTSPOT_BUS_ID 3
#define THERMALI_AMBIENT_BUS_ID 4
#define THERMALI_BUS_ID_OFFSET 2
#define VALIDATE(_id) \
do { \
if(!ONLP_OID_IS_THERMAL(_id)) { \
return ONLP_STATUS_E_INVALID; \
} \
} while(0)
enum onlp_thermal_id
{
THERMAL_RESERVED = 0,
THERMAL_1_ON_MAIN_BROAD_HOT_SPOT, /* The LM75 on Main Board for hot spot */
THERMAL_2_ON_MAIN_BROAD_AMBIENT /* The LM75 on Main Board for ambient */
};
static int thermali_current_temp_get(int id, char *data)
{
int ret = 0;
if (id == THERMALI_HOTSPOT_BUS_ID)
{
ret = i2c_read_byte(id, THERMALI_LM75_HOT_SPOT_ADDR, 0x0, data);
if (ret < 0)
printf("I2C command 0x%X Read Fail, id=%d\n", THERMALI_LM75_HOT_SPOT_ADDR, id);
}
else if (id == THERMALI_AMBIENT_BUS_ID)
{
ret = i2c_read_byte(id, THERMALI_LM75_AMBIENT_ADDR, 0x0, data);
if (ret < 0)
printf("I2C command 0x%X Read Fail, id=%d\n", THERMALI_LM75_AMBIENT_ADDR, id);
}
return ret;
}
/* Static values */
static onlp_thermal_info_t linfo[] = {
{ }, /* Not used */
{ { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_MAIN_BROAD_HOT_SPOT), "Chassis Thermal Sensor 1 (HOT SPOT)", 0},
ONLP_THERMAL_STATUS_PRESENT,
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
},
{ { ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD_AMBIENT), "Chassis Thermal Sensor 2 (AMBIENT)", 0},
ONLP_THERMAL_STATUS_PRESENT,
ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS
}
};
/*
* This will be called to intiialize the thermali subsystem.
*/
int
onlp_thermali_init(void)
{
DIAG_PRINT("%s", __FUNCTION__);
return ONLP_STATUS_OK;
}
/*
* Retrieve the information structure for the given thermal OID.
*
* If the OID is invalid, return ONLP_E_STATUS_INVALID.
* If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL.
* Otherwise, return ONLP_STATUS_OK with the OID's information.
*
* Note -- it is expected that you fill out the information
* structure even if the sensor described by the OID is not present.
*/
int
onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info)
{
DIAG_PRINT("%s, id=%d", __FUNCTION__, id);
int local_id, milli_unit = 1000;
char r_data[10] = {0};
VALIDATE(id);
local_id = ONLP_OID_ID_GET(id);
if (LOCAL_DEBUG)
printf("\n[Debug][%s][%d][local_id: %d]", __FUNCTION__, __LINE__, local_id);
/* Set the onlp_oid_hdr_t and capabilities */
*info = linfo[local_id];
#if 0
if(local_id == THERMAL_CPU_CORE) {
int rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files);
return rv;
}
#endif
if(thermali_current_temp_get(local_id + THERMALI_BUS_ID_OFFSET, r_data) < 0)
printf("[thermali]get current temperature fail!\n");
info->mcelsius = (*r_data) * milli_unit;
if (LOCAL_DEBUG)
printf("\n[Debug][%s][%d][save data: %d]\n", __FUNCTION__, __LINE__, info->mcelsius);
return ONLP_STATUS_OK;
}

View File

@@ -0,0 +1,76 @@
/**************************************************************************//**
*
*
*
*****************************************************************************/
#include <x86_64_lenovo_ne2572/x86_64_lenovo_ne2572_config.h>
/* <auto.start.cdefs(X86_64_LENOVO_NE2572_CONFIG_HEADER).source> */
#define __x86_64_lenovo_ne2572_config_STRINGIFY_NAME(_x) #_x
#define __x86_64_lenovo_ne2572_config_STRINGIFY_VALUE(_x) __x86_64_lenovo_ne2572_config_STRINGIFY_NAME(_x)
x86_64_lenovo_ne2572_config_settings_t x86_64_lenovo_ne2572_config_settings[] =
{
#ifdef X86_64_LENOVO_NE2572_CONFIG_INCLUDE_LOGGING
{ __x86_64_lenovo_ne2572_config_STRINGIFY_NAME(X86_64_LENOVO_NE2572_CONFIG_INCLUDE_LOGGING), __x86_64_lenovo_ne2572_config_STRINGIFY_VALUE(X86_64_LENOVO_NE2572_CONFIG_INCLUDE_LOGGING) },
#else
{ X86_64_LENOVO_NE2572_CONFIG_INCLUDE_LOGGING(__x86_64_lenovo_ne2572_config_STRINGIFY_NAME), "__undefined__" },
#endif
#ifdef X86_64_LENOVO_NE2572_CONFIG_LOG_OPTIONS_DEFAULT
{ __x86_64_lenovo_ne2572_config_STRINGIFY_NAME(X86_64_LENOVO_NE2572_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_lenovo_ne2572_config_STRINGIFY_VALUE(X86_64_LENOVO_NE2572_CONFIG_LOG_OPTIONS_DEFAULT) },
#else
{ X86_64_LENOVO_NE2572_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_lenovo_ne2572_config_STRINGIFY_NAME), "__undefined__" },
#endif
#ifdef X86_64_LENOVO_NE2572_CONFIG_LOG_BITS_DEFAULT
{ __x86_64_lenovo_ne2572_config_STRINGIFY_NAME(X86_64_LENOVO_NE2572_CONFIG_LOG_BITS_DEFAULT), __x86_64_lenovo_ne2572_config_STRINGIFY_VALUE(X86_64_LENOVO_NE2572_CONFIG_LOG_BITS_DEFAULT) },
#else
{ X86_64_LENOVO_NE2572_CONFIG_LOG_BITS_DEFAULT(__x86_64_lenovo_ne2572_config_STRINGIFY_NAME), "__undefined__" },
#endif
#ifdef X86_64_LENOVO_NE2572_CONFIG_LOG_CUSTOM_BITS_DEFAULT
{ __x86_64_lenovo_ne2572_config_STRINGIFY_NAME(X86_64_LENOVO_NE2572_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_lenovo_ne2572_config_STRINGIFY_VALUE(X86_64_LENOVO_NE2572_CONFIG_LOG_CUSTOM_BITS_DEFAULT) },
#else
{ X86_64_LENOVO_NE2572_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_lenovo_ne2572_config_STRINGIFY_NAME), "__undefined__" },
#endif
#ifdef X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB
{ __x86_64_lenovo_ne2572_config_STRINGIFY_NAME(X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB), __x86_64_lenovo_ne2572_config_STRINGIFY_VALUE(X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB) },
#else
{ X86_64_LENOVO_NE2572_CONFIG_PORTING_STDLIB(__x86_64_lenovo_ne2572_config_STRINGIFY_NAME), "__undefined__" },
#endif
#ifdef X86_64_LENOVO_NE2572_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS
{ __x86_64_lenovo_ne2572_config_STRINGIFY_NAME(X86_64_LENOVO_NE2572_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_lenovo_ne2572_config_STRINGIFY_VALUE(X86_64_LENOVO_NE2572_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) },
#else
{ X86_64_LENOVO_NE2572_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_lenovo_ne2572_config_STRINGIFY_NAME), "__undefined__" },
#endif
#ifdef X86_64_LENOVO_NE2572_CONFIG_INCLUDE_UCLI
{ __x86_64_lenovo_ne2572_config_STRINGIFY_NAME(X86_64_LENOVO_NE2572_CONFIG_INCLUDE_UCLI), __x86_64_lenovo_ne2572_config_STRINGIFY_VALUE(X86_64_LENOVO_NE2572_CONFIG_INCLUDE_UCLI) },
#else
{ X86_64_LENOVO_NE2572_CONFIG_INCLUDE_UCLI(__x86_64_lenovo_ne2572_config_STRINGIFY_NAME), "__undefined__" },
#endif
{ NULL, NULL }
};
#undef __x86_64_lenovo_ne2572_config_STRINGIFY_VALUE
#undef __x86_64_lenovo_ne2572_config_STRINGIFY_NAME
const char*
x86_64_lenovo_ne2572_config_lookup(const char* setting)
{
int i;
for(i = 0; x86_64_lenovo_ne2572_config_settings[i].name; i++) {
if(strcmp(x86_64_lenovo_ne2572_config_settings[i].name, setting)) {
return x86_64_lenovo_ne2572_config_settings[i].value;
}
}
return NULL;
}
int
x86_64_lenovo_ne2572_config_show(struct aim_pvs_s* pvs)
{
int i;
for(i = 0; x86_64_lenovo_ne2572_config_settings[i].name; i++) {
aim_printf(pvs, "%s = %s\n", x86_64_lenovo_ne2572_config_settings[i].name, x86_64_lenovo_ne2572_config_settings[i].value);
}
return i;
}
/* <auto.end.cdefs(X86_64_LENOVO_NE2572_CONFIG_HEADER).source> */

View File

@@ -0,0 +1,10 @@
/**************************************************************************//**
*
*
*
*****************************************************************************/
#include <x86_64_lenovo_ne2572/x86_64_lenovo_ne2572_config.h>
/* <--auto.start.enum(ALL).source> */
/* <auto.end.enum(ALL).source> */

View File

@@ -0,0 +1,12 @@
/**************************************************************************//**
*
* x86_64_lenovo_ne2572 Internal Header
*
*****************************************************************************/
#ifndef __X86_64_LENOVO_NE2572_INT_H__
#define __X86_64_LENOVO_NE2572_INT_H__
#include <x86_64_lenovo_ne2572/x86_64_lenovo_ne2572_config.h>
#endif /* __X86_64_LENOVO_NE2572_INT_H__ */

View File

@@ -0,0 +1,18 @@
/**************************************************************************//**
*
*
*
*****************************************************************************/
#include <x86_64_lenovo_ne2572/x86_64_lenovo_ne2572_config.h>
#include "x86_64_lenovo_ne2572_log.h"
/*
* x86_64_lenovo_ne2572 log struct.
*/
AIM_LOG_STRUCT_DEFINE(
X86_64_LENOVO_NE2572_CONFIG_LOG_OPTIONS_DEFAULT,
X86_64_LENOVO_NE2572_CONFIG_LOG_BITS_DEFAULT,
NULL, /* Custom log map */
X86_64_LENOVO_NE2572_CONFIG_LOG_CUSTOM_BITS_DEFAULT
);

View File

@@ -0,0 +1,12 @@
/**************************************************************************//**
*
*
*
*****************************************************************************/
#ifndef __X86_64_LENOVO_NE2572_LOG_H__
#define __X86_64_LENOVO_NE2572_LOG_H__
#define AIM_LOG_MODULE_NAME x86_64_lenovo_ne2572
#include <AIM/aim_log.h>
#endif /* __X86_64_LENOVO_NE2572_LOG_H__ */

View File

@@ -0,0 +1,24 @@
/**************************************************************************//**
*
*
*
*****************************************************************************/
#include <x86_64_lenovo_ne2572/x86_64_lenovo_ne2572_config.h>
#include "x86_64_lenovo_ne2572_log.h"
static int
datatypes_init__(void)
{
#define X86_64_LENOVO_NE2572_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL);
#include <x86_64_lenovo_ne2572/x86_64_lenovo_ne2572.x>
return 0;
}
void __x86_64_lenovo_ne2572_module_init__(void)
{
AIM_LOG_STRUCT_REGISTER();
datatypes_init__();
}
int __onlp_platform_version__ = 1;

View File

@@ -0,0 +1,50 @@
/**************************************************************************//**
*
*
*
*****************************************************************************/
#include <x86_64_lenovo_ne2572/x86_64_lenovo_ne2572_config.h>
#if X86_64_LENOVO_NE2572_CONFIG_INCLUDE_UCLI == 1
#include <uCli/ucli.h>
#include <uCli/ucli_argparse.h>
#include <uCli/ucli_handler_macros.h>
static ucli_status_t
x86_64_lenovo_ne2572_ucli_ucli__config__(ucli_context_t* uc)
{
UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_lenovo_ne2572)
}
/* <auto.ucli.handlers.start> */
/* <auto.ucli.handlers.end> */
static ucli_module_t
x86_64_lenovo_ne2572_ucli_module__ =
{
"x86_64_lenovo_ne2572_ucli",
NULL,
x86_64_lenovo_ne2572_ucli_ucli_handlers__,
NULL,
NULL,
};
ucli_node_t*
x86_64_lenovo_ne2572_ucli_node_create(void)
{
ucli_node_t* n;
ucli_module_init(&x86_64_lenovo_ne2572_ucli_module__);
n = ucli_node_create("x86_64_lenovo_ne2572", NULL, &x86_64_lenovo_ne2572_ucli_module__);
ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_lenovo_ne2572"));
return n;
}
#else
void*
x86_64_lenovo_ne2572_ucli_node_create(void)
{
return NULL;
}
#endif

View File

@@ -0,0 +1 @@
include $(ONL)/make/pkg.mk

View File

@@ -0,0 +1 @@
include $(ONL)/make/pkg.mk

View File

@@ -0,0 +1 @@
!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=lenovo BASENAME=x86-64-lenovo-ne2572 REVISION=r0

View File

@@ -0,0 +1,32 @@
---
######################################################################
#
# platform-config for NE2572
#
######################################################################
x86-64-lenovo-ne2572-r0:
grub:
serial: >-
--port=0x2f8
--speed=115200
--word=8
--parity=no
--stop=1
kernel:
<<: *kernel-3-16
args: >-
nopat
i2c-ismt.enable=0
console=ttyS1,115200n8
##network
## interfaces:
## ma1:
## name: ~
## syspath: pci0000:00/0000:00:14.0

View File

@@ -0,0 +1,31 @@
---
######################################################################
#
# platform-config for NE2572
#
######################################################################
x86-64-lenovo-ne2572-r0:
grub:
serial: >-
--port=0x2f8
--speed=115200
--word=8
--parity=no
--stop=1
kernel:
<<: *kernel-3-18
args: >-
nopat
console=ttyS1,115200n8
##network
## interfaces:
## ma1:
## name: ~
## syspath: pci0000:00/0000:00:14.0

View File

@@ -0,0 +1,223 @@
from onl.platform.base import *
from onl.platform.lenovo import *
class OnlPlatform_x86_64_lenovo_ne2572_r0(OnlPlatformLenovo,
OnlPlatformPortConfig_32x100):
PLATFORM='x86-64-lenovo-ne2572-r0'
MODEL="NE2572"
SYS_OBJECT_ID=".6010.32"
def baseconfig(self):
########### initialize I2C bus 0 ###########
self.new_i2c_devices([
# ONIE EEPROM @MB
('24c128', 0x56, 0),
# PowerCPLD @MB
('cpld', 0x5E, 0),
# initialize multiplexer (PCA9548 #0)
('pca9548', 0x70, 0),
# FRU EEROM @MB
('24c512', 0x51, 1),
# CFG EEROM @MB
('24c02', 0x51, 2),
# TMP75#1 (Hot Spot) #use lm75 will cause device busy, use other name
('thermal1', 0x4D, 3),
# TMP75#0 (Ambient) #use lm75 will cause device busy, use other name
('thermal2', 0x4C, 4),
# initialize multiplexer (PCA9545 #0)
('pca9545', 0x71, 5),
# IDT 5P49V5923A (Clock generator)
(' ', 0x6A, 6),
# initialize multiplexer (PCA9548 #1)
('pca9548', 0x72, 7),
# SystemCPLD @MB
('cpld', 0x5F, 8),
])
########### initialize I2C bus PCA9545 #0 ###########
self.new_i2c_devices([
# MGMT EEROM
('24c02', 0x51, 9),
# PSU #0
('psu', 0x51, 10),
('psu', 0x59, 10),
# PSU #1
('psu', 0x51, 11),
('psu', 0x59, 11),
# reserved
])
########### initialize I2C bus PCA9548 #1 ###########
self.new_i2c_devices([
# initialize multiplexer (PCA9548 #3)
('pca9548', 0x74, 14),
# initialize multiplexer (PCA9548 #4)
('pca9548', 0x75, 14),
# initialize multiplexer (PCA9548 #5)
('pca9548', 0x76, 14),
# initialize multiplexer (PCA9548 #6)
('pca9548', 0x74, 16),
# initialize multiplexer (PCA9548 #7)
('pca9548', 0x75, 16),
# initialize multiplexer (PCA9548 #8)
('pca9548', 0x76, 16),
# initialize multiplexer (PCA9548 #9)
('pca9548', 0x74, 18),
# IR3595
('ir3595', 0x09, 19),
# initialize multiplexer (PCA9548 #2)
('pca9548', 0x73, 20),
])
########### initialize I2C bus PCA9548 #3 @Fan Expander ###########
self.new_i2c_devices([
('SFP', 0x50, 21),
('SFP', 0x50, 22),
('SFP', 0x50, 23),
('SFP', 0x50, 24),
('SFP', 0x50, 25),
('SFP', 0x50, 26),
('SFP', 0x50, 27),
('SFP', 0x50, 28),
])
########### initialize I2C bus PCA9548 #4 @Fan Expander ###########
self.new_i2c_devices([
('SFP', 0x50, 29),
('SFP', 0x50, 30),
('SFP', 0x50, 31),
('SFP', 0x50, 32),
('SFP', 0x50, 33),
('SFP', 0x50, 34),
('SFP', 0x50, 35),
('SFP', 0x50, 36),
])
########### initialize I2C bus PCA9548 #5 @Fan Expander ###########
self.new_i2c_devices([
('SFP', 0x50, 37),
('SFP', 0x50, 38),
('SFP', 0x50, 39),
('SFP', 0x50, 40),
('SFP', 0x50, 41),
('SFP', 0x50, 42),
('SFP', 0x50, 43),
('SFP', 0x50, 44),
])
########### initialize I2C bus PCA9548 #6 @Fan Expander ###########
self.new_i2c_devices([
('SFP', 0x50, 45),
('SFP', 0x50, 46),
('SFP', 0x50, 47),
('SFP', 0x50, 48),
('SFP', 0x50, 49),
('SFP', 0x50, 50),
('SFP', 0x50, 51),
('SFP', 0x50, 52),
])
########### initialize I2C bus PCA9548 #7 @Fan Expander ###########
self.new_i2c_devices([
('SFP', 0x50, 53),
('SFP', 0x50, 54),
('SFP', 0x50, 55),
('SFP', 0x50, 56),
('SFP', 0x50, 57),
('SFP', 0x50, 58),
('SFP', 0x50, 59),
('SFP', 0x50, 60),
])
########### initialize I2C bus PCA9548 #8 @Fan Expander ###########
self.new_i2c_devices([
('SFP', 0x50, 61),
('SFP', 0x50, 62),
('SFP', 0x50, 63),
('SFP', 0x50, 64),
('SFP', 0x50, 65),
('SFP', 0x50, 66),
('SFP', 0x50, 67),
('SFP', 0x50, 68),
])
########### initialize I2C bus PCA9548 #9 @Fan Expander ###########
self.new_i2c_devices([
('QSFP', 0x50, 69),
('QSFP', 0x50, 70),
('QSFP', 0x50, 71),
('QSFP', 0x50, 72),
('QSFP', 0x50, 73),
('QSFP', 0x50, 74),
])
########### initialize I2C bus PCA9548 #2 @Fan Expander ###########
self.new_i2c_devices([
# Fan EEROM
('24c02', 0x57, 77),
# Fan EEROM
('24c02', 0x57, 78),
# Fan EEROM
('24c02', 0x57, 79),
# Fan EEROM
('24c02', 0x57, 80),
# Fan EEROM
('24c02', 0x57, 81),
# Fan EEROM
('24c02', 0x57, 82),
])
self.new_i2c_devices([
(' ', 0x68, 69),
(' ', 0x68, 70),
(' ', 0x68, 71),
(' ', 0x68, 72),
(' ', 0x68, 73),
(' ', 0x68, 74),
# Port CPLD0~2
('cpld', 0x5B, 13),
('cpld', 0x5C, 15),
('cpld', 0x5D, 17),
])
return True