From 0c7cc3b62e08f9b4e90ed4040ed1de61329e69f9 Mon Sep 17 00:00:00 2001 From: Jonathan Tsai Date: Wed, 22 Feb 2017 13:45:18 +0800 Subject: [PATCH] [LY6,LY8,LY9] Change all low-level function-call to onlp APIs --- .../module/inc/quanta_lib/gpio.h | 19 ---- .../module/inc/quanta_lib/i2c.h | 7 -- .../module/src/gpio.c | 82 ---------------- .../module/src/i2c.c | 51 ---------- .../module/src/psui.c | 5 +- .../module/src/sfpi.c | 16 +-- .../module/inc/quanta_lib/gpio.h | 19 ---- .../module/inc/quanta_lib/i2c.h | 7 -- .../module/src/gpio.c | 82 ---------------- .../module/src/i2c.c | 51 ---------- .../module/src/psui.c | 5 +- .../module/src/sfpi.c | 36 ++++--- .../module/inc/quanta_lib/gpio.h | 19 ---- .../module/inc/quanta_lib/i2c.h | 7 -- .../module/src/gpio.c | 82 ---------------- .../module/src/i2c.c | 97 ------------------- .../module/src/psui.c | 5 +- .../module/src/sfpi.c | 37 ++++--- 18 files changed, 61 insertions(+), 566 deletions(-) delete mode 100644 packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/inc/quanta_lib/gpio.h delete mode 100644 packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/inc/quanta_lib/i2c.h delete mode 100644 packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/gpio.c delete mode 100644 packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/i2c.c delete mode 100644 packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/inc/quanta_lib/gpio.h delete mode 100644 packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/inc/quanta_lib/i2c.h delete mode 100644 packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/gpio.c delete mode 100644 packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/i2c.c delete mode 100755 packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/inc/quanta_lib/gpio.h delete mode 100755 packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/inc/quanta_lib/i2c.h delete mode 100755 packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/gpio.c delete mode 100755 packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/i2c.c diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/inc/quanta_lib/gpio.h b/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/inc/quanta_lib/gpio.h deleted file mode 100644 index b3096ec8..00000000 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/inc/quanta_lib/gpio.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __QUANTA_LIB_GPIO_H__ -#define __QUANTA_LIB_GPIO_H__ - -#define GPIO_LOW 0 -#define GPIO_HIGH 1 - -#define GPIO_IN 0 -#define GPIO_OUT 1 - -#define GPIO_PATH "/sys/class/gpio" -#define GPIO_EXPORT GPIO_PATH "/export" -#define GPIO_UNEXPORT GPIO_PATH "/unexport" -#define GPIO_PREF GPIO_PATH "/gpio" - -int pca953x_gpio_value_get(int gpio, int *value); -int pca953x_gpio_direction_set(int gpio, int direction); -int pca953x_gpio_value_set(int gpio, int value); - -#endif /* __QUANTA_LIB_GPIO_H__ */ diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/inc/quanta_lib/i2c.h b/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/inc/quanta_lib/i2c.h deleted file mode 100644 index 6bf8397a..00000000 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/inc/quanta_lib/i2c.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __QUANTA_LIB_I2C_H__ -#define __QUANTA_LIB_I2C_H__ - -int i2c_block_read(int bus, uint8_t addr, uint8_t offset, int size, - uint8_t* rdata, uint32_t flags); - -#endif /* __QUANTA_LIB_I2C_H__ */ diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/gpio.c b/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/gpio.c deleted file mode 100644 index 4486989c..00000000 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/gpio.c +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include -#include -#include -#include - -static int file_exists(char *filename) { - struct stat st; - return (stat(filename, &st) == 0); -} - -static int try_export_gpio(int gpio) { - char filename[PATH_MAX]; - - memset(filename, 0, sizeof(filename)); - sprintf(filename, "%s%d/value", GPIO_PREF, gpio); - - if(!file_exists(filename)) { - onlp_file_write_int(gpio, GPIO_EXPORT); - } - - return ONLP_STATUS_OK; -} - -static int try_unexport_gpio(int gpio) { - char filename[PATH_MAX]; - - memset(filename, 0, sizeof(filename)); - sprintf(filename, "%s%d/value", GPIO_PREF, gpio); - - if(file_exists(filename)) { - onlp_file_write_int(gpio, GPIO_UNEXPORT); - } - - return ONLP_STATUS_OK; -} - -int pca953x_gpio_value_get(int gpio, int *value) { - int ret; - - try_export_gpio(gpio); - ret = onlp_file_read_int(value, "%s%d/value", GPIO_PREF, gpio); - try_unexport_gpio(gpio); - - return ret; -} - -int pca953x_gpio_direction_set(int gpio, int direction) { - int ret; - - try_export_gpio(gpio); - - switch(direction) { - case GPIO_IN: - ret = onlp_file_write_str("in", "%s%d/direction", GPIO_PREF, gpio); - break; - - case GPIO_OUT: - ret = onlp_file_write_str("out", "%s%d/direction", GPIO_PREF, gpio); - break; - - default: - ret = ONLP_STATUS_E_UNSUPPORTED; - break; - } - - try_unexport_gpio(gpio); - - return ret; -} - -int pca953x_gpio_value_set(int gpio, int value) { - int ret; - - pca953x_gpio_direction_set(gpio, GPIO_OUT); - - try_export_gpio(gpio); - ret = onlp_file_write_int(value, "%s%d/value", GPIO_PREF, gpio); - try_unexport_gpio(gpio); - - return ret; -} diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/i2c.c b/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/i2c.c deleted file mode 100644 index 169b2b02..00000000 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/i2c.c +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* first byte of rdata is length of result */ -int -i2c_block_read(int bus, uint8_t addr, uint8_t offset, int size, - uint8_t* rdata, uint32_t flags) -{ - int fd; - - fd = onlp_i2c_open(bus, addr, flags); - - if(fd < 0) { - return fd; - } - - int count = size; - uint8_t* p = rdata; - while(count > 0) { - int rsize = (count >= ONLPLIB_CONFIG_I2C_BLOCK_SIZE) ? ONLPLIB_CONFIG_I2C_BLOCK_SIZE : count; - int rv = i2c_smbus_read_i2c_block_data(fd, - offset, - rsize, - p); - - if(rv != rsize) { - printf("i2c-%d: reading address 0x%x, offset %d, size=%d failed", - bus, addr, offset, rsize); - goto error; - } - - p += rsize; - count -= rsize; - } - - close(fd); - return 0; - - error: - close(fd); - return -1; -} - diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/psui.c b/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/psui.c index e014a3f3..c5683712 100755 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/psui.c +++ b/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/psui.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include "x86_64_quanta_ly6_rangeley_int.h" #include "x86_64_quanta_ly6_rangeley_log.h" @@ -85,7 +84,7 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) info->status |= 1; memset(buffer, 0, sizeof(buffer)); - rv = i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_MODEL, PMBUS_MFR_MODEL_LEN, buffer, ONLP_I2C_F_FORCE); + rv = onlp_i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_MODEL, PMBUS_MFR_MODEL_LEN, buffer, ONLP_I2C_F_FORCE); if(rv >= 0){ aim_strlcpy(info->model, (char *) (buffer+1), (buffer[0] + 1)); } @@ -94,7 +93,7 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) } memset(buffer, 0, sizeof(buffer)); - rv = i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_SERIAL, PMBUS_MFR_SERIAL_LEN, buffer, ONLP_I2C_F_FORCE); + rv = onlp_i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_SERIAL, PMBUS_MFR_SERIAL_LEN, buffer, ONLP_I2C_F_FORCE); if(rv >= 0){ aim_strlcpy(info->serial, (char *) (buffer+1), (buffer[0] + 1)); } diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/sfpi.c b/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/sfpi.c index 97bec11f..b2aa9dff 100755 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/sfpi.c +++ b/packages/platforms/quanta/x86-64/x86-64-quanta-ly6-rangeley/onlp/builds/src/x86_64_quanta_ly6_rangeley/module/src/sfpi.c @@ -26,13 +26,12 @@ #include #include #include +#include #include "x86_64_quanta_ly6_rangeley_log.h" #include #include -#include - /** * This table maps the presence gpio, reset gpio, and eeprom file * for each SFP port. @@ -86,9 +85,12 @@ int onlp_sfpi_init(void) { int value = -1, ret; - ret = pca953x_gpio_value_get(QUANTA_LY6_QSFP_EN_GPIO_P3V3_PW_EN, &value); - if(ret == ONLP_STATUS_OK && value != GPIO_HIGH) { - ret = pca953x_gpio_value_set(QUANTA_LY6_QSFP_EN_GPIO_P3V3_PW_EN, GPIO_HIGH); + + onlp_gpio_export(QUANTA_LY6_QSFP_EN_GPIO_P3V3_PW_EN, ONLP_GPIO_DIRECTION_IN); + ret = onlp_gpio_get(QUANTA_LY6_QSFP_EN_GPIO_P3V3_PW_EN, &value); + if(ret == ONLP_STATUS_OK && value != 1) { + onlp_gpio_export(QUANTA_LY6_QSFP_EN_GPIO_P3V3_PW_EN, ONLP_GPIO_DIRECTION_OUT); + ret = onlp_gpio_set(QUANTA_LY6_QSFP_EN_GPIO_P3V3_PW_EN, 1); sleep(1); } @@ -115,8 +117,8 @@ onlp_sfpi_is_present(int port) int value = 0; sfpmap_t* sfp = SFP_GET(port); if(sfp->present_gpio > 0) { - if(pca953x_gpio_value_get(sfp->present_gpio, &value) == ONLP_STATUS_OK) - return (value == GPIO_LOW); + if(onlp_gpio_get(sfp->present_gpio, &value) == ONLP_STATUS_OK) + return (value == 0); else return ONLP_STATUS_E_MISSING; } diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/inc/quanta_lib/gpio.h b/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/inc/quanta_lib/gpio.h deleted file mode 100644 index b3096ec8..00000000 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/inc/quanta_lib/gpio.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __QUANTA_LIB_GPIO_H__ -#define __QUANTA_LIB_GPIO_H__ - -#define GPIO_LOW 0 -#define GPIO_HIGH 1 - -#define GPIO_IN 0 -#define GPIO_OUT 1 - -#define GPIO_PATH "/sys/class/gpio" -#define GPIO_EXPORT GPIO_PATH "/export" -#define GPIO_UNEXPORT GPIO_PATH "/unexport" -#define GPIO_PREF GPIO_PATH "/gpio" - -int pca953x_gpio_value_get(int gpio, int *value); -int pca953x_gpio_direction_set(int gpio, int direction); -int pca953x_gpio_value_set(int gpio, int value); - -#endif /* __QUANTA_LIB_GPIO_H__ */ diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/inc/quanta_lib/i2c.h b/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/inc/quanta_lib/i2c.h deleted file mode 100644 index 6bf8397a..00000000 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/inc/quanta_lib/i2c.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __QUANTA_LIB_I2C_H__ -#define __QUANTA_LIB_I2C_H__ - -int i2c_block_read(int bus, uint8_t addr, uint8_t offset, int size, - uint8_t* rdata, uint32_t flags); - -#endif /* __QUANTA_LIB_I2C_H__ */ diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/gpio.c b/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/gpio.c deleted file mode 100644 index cfbc1b83..00000000 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/gpio.c +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include -#include -#include -#include - -static int file_exists(char *filename) { - struct stat st; - return (stat(filename, &st) == 0); -} - -static int try_export_gpio(int gpio) { - char filename[PATH_MAX]; - - memset(filename, 0, sizeof(filename)); - sprintf(filename, "%s%d/value", GPIO_PREF, gpio); - - if(!file_exists(filename)) { - onlp_file_write_int(gpio, GPIO_EXPORT); - } - - return ONLP_STATUS_OK; -} - -static int try_unexport_gpio(int gpio) { - char filename[PATH_MAX]; - - memset(filename, 0, sizeof(filename)); - sprintf(filename, "%s%d/value", GPIO_PREF, gpio); - - if(file_exists(filename)) { - onlp_file_write_int(gpio, GPIO_UNEXPORT); - } - - return ONLP_STATUS_OK; -} - -int pca953x_gpio_value_get(int gpio, int *value) { - int ret; - - try_export_gpio(gpio); - ret = onlp_file_read_int(value, "%s%d/value", GPIO_PREF, gpio); - try_unexport_gpio(gpio); - - return ret; - } - -int pca953x_gpio_direction_set(int gpio, int direction) { - int ret; - - try_export_gpio(gpio); - - switch(direction) { - case GPIO_IN: - ret = onlp_file_write_str("in", "%s%d/direction", GPIO_PREF, gpio); - break; - - case GPIO_OUT: - ret = onlp_file_write_str("out", "%s%d/direction", GPIO_PREF, gpio); - break; - - default: - ret = ONLP_STATUS_E_UNSUPPORTED; - break; - } - - try_unexport_gpio(gpio); - - return ret; -} - -int pca953x_gpio_value_set(int gpio, int value) { - int ret; - - pca953x_gpio_direction_set(gpio, GPIO_OUT); - - try_export_gpio(gpio); - ret = onlp_file_write_int(value, "%s%d/value", GPIO_PREF, gpio); - try_unexport_gpio(gpio); - - return ret; -} diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/i2c.c b/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/i2c.c deleted file mode 100644 index 169b2b02..00000000 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/i2c.c +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* first byte of rdata is length of result */ -int -i2c_block_read(int bus, uint8_t addr, uint8_t offset, int size, - uint8_t* rdata, uint32_t flags) -{ - int fd; - - fd = onlp_i2c_open(bus, addr, flags); - - if(fd < 0) { - return fd; - } - - int count = size; - uint8_t* p = rdata; - while(count > 0) { - int rsize = (count >= ONLPLIB_CONFIG_I2C_BLOCK_SIZE) ? ONLPLIB_CONFIG_I2C_BLOCK_SIZE : count; - int rv = i2c_smbus_read_i2c_block_data(fd, - offset, - rsize, - p); - - if(rv != rsize) { - printf("i2c-%d: reading address 0x%x, offset %d, size=%d failed", - bus, addr, offset, rsize); - goto error; - } - - p += rsize; - count -= rsize; - } - - close(fd); - return 0; - - error: - close(fd); - return -1; -} - diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/psui.c b/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/psui.c index f773d5a0..aebdade5 100755 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/psui.c +++ b/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/psui.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include "x86_64_quanta_ly8_rangeley_int.h" #include "x86_64_quanta_ly8_rangeley_log.h" @@ -85,7 +84,7 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) info->status |= 1; memset(buffer, 0, sizeof(buffer)); - rv = i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_MODEL, PMBUS_MFR_MODEL_LEN, buffer, ONLP_I2C_F_FORCE); + rv = onlp_i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_MODEL, PMBUS_MFR_MODEL_LEN, buffer, ONLP_I2C_F_FORCE); if(rv >= 0) { aim_strlcpy(info->model, (char *) (buffer+1), (buffer[0]+1)); } @@ -94,7 +93,7 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) } memset(buffer, 0, sizeof(buffer)); - rv = i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_SERIAL, PMBUS_MFR_SERIAL_LEN, buffer, ONLP_I2C_F_FORCE); + rv = onlp_i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_SERIAL, PMBUS_MFR_SERIAL_LEN, buffer, ONLP_I2C_F_FORCE); if(rv >= 0) { aim_strlcpy(info->serial, (char *) (buffer+1), (buffer[0] + 1)); } else { diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/sfpi.c b/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/sfpi.c index 3ec12672..236f1f82 100755 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/sfpi.c +++ b/packages/platforms/quanta/x86-64/x86-64-quanta-ly8-rangeley/onlp/builds/src/x86_64_quanta_ly8_rangeley/module/src/sfpi.c @@ -26,13 +26,12 @@ #include #include #include +#include #include "x86_64_quanta_ly8_rangeley_log.h" #include #include -#include - /** * This table maps the presence gpio, reset gpio, and eeprom file * for each SFP port. @@ -103,22 +102,35 @@ static sfpmap_t sfpmap__[] = { 70, QUANTA_LY8_QSFP_QDB_GPIO_PRSNT_70_N /* 446 */, "/sys/class/gpio/gpio446/value", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-23/i2c-89/89-0050/eeprom", "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-23/i2c-89/89-0051/eeprom" }, }; +#define SFP_GET(_port) (sfpmap__ + _port) + int onlp_sfpi_init(void) { - int value = -1, ret; - ret = pca953x_gpio_value_get(QUANTA_LY8_QSFP_EN_GPIO_P3V3_PW_EN, &value); - if(ret == ONLP_STATUS_OK && value != GPIO_HIGH) { - ret = pca953x_gpio_value_set(QUANTA_LY8_QSFP_EN_GPIO_P3V3_PW_EN, GPIO_HIGH); + int value = -1, ret, i; + sfpmap_t* sfp; + + onlp_gpio_export(QUANTA_LY8_QSFP_EN_GPIO_P3V3_PW_EN, ONLP_GPIO_DIRECTION_IN); + ret = onlp_gpio_get(QUANTA_LY8_QSFP_EN_GPIO_P3V3_PW_EN, &value); + if(ret == ONLP_STATUS_OK && value != 1) { + onlp_gpio_export(QUANTA_LY8_QSFP_EN_GPIO_P3V3_PW_EN, ONLP_GPIO_DIRECTION_OUT); + ret = onlp_gpio_set(QUANTA_LY8_QSFP_EN_GPIO_P3V3_PW_EN, 1); } if(ret == ONLP_STATUS_OK) { - ret = pca953x_gpio_value_get(QUANTA_LY8_QSFP_QDB_GPIO_MOD_EN_N, &value); - if(ret == ONLP_STATUS_OK && value != GPIO_LOW) { - ret = pca953x_gpio_value_set(QUANTA_LY8_QSFP_QDB_GPIO_MOD_EN_N, GPIO_LOW); + onlp_gpio_export(QUANTA_LY8_QSFP_QDB_GPIO_MOD_EN_N, ONLP_GPIO_DIRECTION_IN); + ret = onlp_gpio_get(QUANTA_LY8_QSFP_QDB_GPIO_MOD_EN_N, &value); + if(ret == ONLP_STATUS_OK && value != 0) { + onlp_gpio_export(QUANTA_LY8_QSFP_QDB_GPIO_MOD_EN_N, ONLP_GPIO_DIRECTION_OUT); + ret = onlp_gpio_set(QUANTA_LY8_QSFP_QDB_GPIO_MOD_EN_N, 0); } } + for(i = 0; i < 54; i++) { + sfp = SFP_GET(i); + onlp_gpio_export(sfp->present_gpio, ONLP_GPIO_DIRECTION_IN); + } + return ret; } @@ -134,16 +146,14 @@ onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) return ONLP_STATUS_OK; } -#define SFP_GET(_port) (sfpmap__ + _port) - int onlp_sfpi_is_present(int port) { int value = 0; sfpmap_t* sfp = SFP_GET(port); if(sfp->present_gpio > 0) { - if(pca953x_gpio_value_get(sfp->present_gpio, &value) == ONLP_STATUS_OK) - return (value == GPIO_LOW); + if(onlp_gpio_get(sfp->present_gpio, &value) == ONLP_STATUS_OK) + return (value == 0); else return ONLP_STATUS_E_MISSING; } diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/inc/quanta_lib/gpio.h b/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/inc/quanta_lib/gpio.h deleted file mode 100755 index f2882476..00000000 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/inc/quanta_lib/gpio.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __QUANTA_LIB_GPIO_H__ -#define __QUANTA_LIB_GPIO_H__ - -#define GPIO_LOW 0 -#define GPIO_HIGH 1 - -#define GPIO_IN 0 -#define GPIO_OUT 1 - -#define GPIO_PATH "/sys/class/gpio" -#define GPIO_EXPORT GPIO_PATH "/export" -#define GPIO_UNEXPORT GPIO_PATH "/unexport" -#define GPIO_PREF GPIO_PATH "/gpio" - -int pca953x_gpio_value_get(int gpio, int *value); -int pca953x_gpio_direction_set(int gpio, int direction); -int pca953x_gpio_value_set(int gpio, int value); - -#endif /* __QUANTA_LIB_GPIO_H__ */ diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/inc/quanta_lib/i2c.h b/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/inc/quanta_lib/i2c.h deleted file mode 100755 index d93595fa..00000000 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/inc/quanta_lib/i2c.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __QUANTA_LIB_I2C_H__ -#define __QUANTA_LIB_I2C_H__ - -int i2c_block_read(int bus, uint8_t addr, uint8_t offset, int size, - unsigned char *rdata, uint32_t flags); - -#endif /* __QUANTA_LIB_I2C_H__ */ diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/gpio.c b/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/gpio.c deleted file mode 100755 index cfbc1b83..00000000 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/gpio.c +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include -#include -#include -#include - -static int file_exists(char *filename) { - struct stat st; - return (stat(filename, &st) == 0); -} - -static int try_export_gpio(int gpio) { - char filename[PATH_MAX]; - - memset(filename, 0, sizeof(filename)); - sprintf(filename, "%s%d/value", GPIO_PREF, gpio); - - if(!file_exists(filename)) { - onlp_file_write_int(gpio, GPIO_EXPORT); - } - - return ONLP_STATUS_OK; -} - -static int try_unexport_gpio(int gpio) { - char filename[PATH_MAX]; - - memset(filename, 0, sizeof(filename)); - sprintf(filename, "%s%d/value", GPIO_PREF, gpio); - - if(file_exists(filename)) { - onlp_file_write_int(gpio, GPIO_UNEXPORT); - } - - return ONLP_STATUS_OK; -} - -int pca953x_gpio_value_get(int gpio, int *value) { - int ret; - - try_export_gpio(gpio); - ret = onlp_file_read_int(value, "%s%d/value", GPIO_PREF, gpio); - try_unexport_gpio(gpio); - - return ret; - } - -int pca953x_gpio_direction_set(int gpio, int direction) { - int ret; - - try_export_gpio(gpio); - - switch(direction) { - case GPIO_IN: - ret = onlp_file_write_str("in", "%s%d/direction", GPIO_PREF, gpio); - break; - - case GPIO_OUT: - ret = onlp_file_write_str("out", "%s%d/direction", GPIO_PREF, gpio); - break; - - default: - ret = ONLP_STATUS_E_UNSUPPORTED; - break; - } - - try_unexport_gpio(gpio); - - return ret; -} - -int pca953x_gpio_value_set(int gpio, int value) { - int ret; - - pca953x_gpio_direction_set(gpio, GPIO_OUT); - - try_export_gpio(gpio); - ret = onlp_file_write_int(value, "%s%d/value", GPIO_PREF, gpio); - try_unexport_gpio(gpio); - - return ret; -} diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/i2c.c b/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/i2c.c deleted file mode 100755 index 8f72df0c..00000000 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/i2c.c +++ /dev/null @@ -1,97 +0,0 @@ -#include -#include -#include -#include -#include -#include -#if ONLPLIB_CONFIG_I2C_USE_CUSTOM_HEADER == 1 -#include -#else -#include -#endif -#include -#include -#include "x86_64_quanta_ly9_rangeley_log.h" -#include -#include - -int i2c_dev_smbus_access(int file, char read_write, __u8 command, - int size, union i2c_smbus_data *data) -{ - struct i2c_smbus_ioctl_data args; - - args.read_write = read_write; - args.command = command; - args.size = size; - args.data = data; - return ioctl(file, I2C_SMBUS, &args); -} - -int i2c_dev_read_block(int file, uint8_t command, unsigned char *buffer, int length) -{ - union i2c_smbus_data data; - int i; - - if (length > 32) - length = 32; - data.block[0] = length; - if (i2c_dev_smbus_access(file, I2C_SMBUS_READ, command, - length == 32 ? I2C_SMBUS_I2C_BLOCK_BROKEN : - I2C_SMBUS_I2C_BLOCK_DATA, &data)) - return -1; - else{ - for (i = 1; i <= data.block[0]; i++) - buffer[i - 1] = data.block[i]; - } - return 0; -} - -/* first byte of rdata is length of result */ -int -i2c_block_read(int bus, uint8_t addr, uint8_t offset, int size, - unsigned char *rdata, uint32_t flags) -{ - int fd; - int force = I2C_SLAVE, rv; - - fd = onlp_i2c_open(bus, addr, flags); - - if(fd < 0) { - return fd; - } - - fd = onlp_file_open(O_RDWR, 1, "/dev/i2c-%d", bus); - if(fd < 0) { - AIM_LOG_MSG("/dev/i2c-%d open Error!", bus); - return fd; - } - - /* Set SLAVE or SLAVE_FORCE address */ - rv = ioctl(fd, - force ? I2C_SLAVE_FORCE : I2C_SLAVE, - addr); - - if(rv == -1) { - AIM_LOG_ERROR("i2c-%d: %s slave address 0x%x failed: %{errno}", - bus, - (flags & ONLP_I2C_F_FORCE) ? "forcing" : "setting", - addr, - errno); - goto error; - } - - if ((i2c_dev_read_block(fd, offset, rdata, size)) < 0) - { - printf("/dev/i2c-%d read Error!\n", bus); - close (fd); - return -1; - } - - close(fd); - return 0; - - error: - close(fd); - return -1; -} - diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/psui.c b/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/psui.c index e9a35c99..3eab15b4 100755 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/psui.c +++ b/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/psui.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include "x86_64_quanta_ly9_rangeley_int.h" #include "x86_64_quanta_ly9_rangeley_log.h" @@ -85,7 +84,7 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) info->status |= 1; memset(buffer, 0, sizeof(buffer)); - rv = i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_MODEL, PMBUS_MFR_MODEL_LEN, buffer, ONLP_I2C_F_FORCE); + rv = onlp_i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_MODEL, PMBUS_MFR_MODEL_LEN, buffer, ONLP_I2C_F_FORCE); buffer[buffer[0] + 1] = 0x00; if(rv >= 0){ aim_strlcpy(info->model, (char *) (buffer+1), (buffer[0] + 1)); @@ -95,7 +94,7 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) } memset(buffer, 0, sizeof(buffer)); - rv = i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_SERIAL, PMBUS_MFR_SERIAL_LEN, buffer, ONLP_I2C_F_FORCE); + rv = onlp_i2c_block_read(psu_info[pid].busno, psu_info[pid].addr, PMBUS_MFR_SERIAL, PMBUS_MFR_SERIAL_LEN, buffer, ONLP_I2C_F_FORCE); buffer[buffer[0] + 1] = 0x00; if(rv >= 0){ aim_strlcpy(info->serial, (char *) (buffer+1), (buffer[0] + 1)); diff --git a/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/sfpi.c b/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/sfpi.c index 403c8516..c22748c1 100755 --- a/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/sfpi.c +++ b/packages/platforms/quanta/x86-64/x86-64-quanta-ly9-rangeley/onlp/builds/src/x86_64_quanta_ly9_rangeley/module/src/sfpi.c @@ -26,13 +26,12 @@ #include #include #include +#include #include "x86_64_quanta_ly9_rangeley_log.h" #include #include -#include - /** * This table maps the presence gpio, reset gpio, and eeprom file * for each SFP port. @@ -67,21 +66,34 @@ static qsfpmap_t qsfpmap__[] = { 54, QUANTA_LY9_QSFP_QDB_GPIO_PRSNT_54_N, NULL, "/sys/devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-23/i2c-49/49-0050/eeprom", NULL }, }; +#define SFP_GET(_port) (sfpmap__ + _port - 49) +#define QSFP_GET(_port) (qsfpmap__ + _port - 53) + int onlp_sfpi_init(void) { - int value = -1, ret; - ret = pca953x_gpio_value_get(QUANTA_LY9_QSFP_EN_GPIO_P3V3_PW_EN, &value); - if(ret == ONLP_STATUS_OK && value != GPIO_LOW) { - ret = pca953x_gpio_value_set(QUANTA_LY9_QSFP_EN_GPIO_P3V3_PW_EN, GPIO_LOW); + int value = -1, ret, i; + qsfpmap_t* qsfp; + + onlp_gpio_export(QUANTA_LY9_QSFP_EN_GPIO_P3V3_PW_EN, ONLP_GPIO_DIRECTION_IN); + ret = onlp_gpio_get(QUANTA_LY9_QSFP_EN_GPIO_P3V3_PW_EN, &value); + if(ret == ONLP_STATUS_OK && value != 0) { + onlp_gpio_export(QUANTA_LY9_QSFP_EN_GPIO_P3V3_PW_EN, ONLP_GPIO_DIRECTION_OUT); + ret = onlp_gpio_set(QUANTA_LY9_QSFP_EN_GPIO_P3V3_PW_EN, 0); } if(ret == ONLP_STATUS_OK) { - ret = pca953x_gpio_value_get(QUANTA_LY9_QSFP_QDB_GPIO_MOD_EN_N, &value); - if(ret == ONLP_STATUS_OK && value != GPIO_LOW) { - ret = pca953x_gpio_value_set(QUANTA_LY9_QSFP_QDB_GPIO_MOD_EN_N, GPIO_LOW); + onlp_gpio_export(QUANTA_LY9_QSFP_QDB_GPIO_MOD_EN_N, ONLP_GPIO_DIRECTION_IN); + ret = onlp_gpio_get(QUANTA_LY9_QSFP_QDB_GPIO_MOD_EN_N, &value); + if(ret == ONLP_STATUS_OK && value != 0) { + onlp_gpio_export(QUANTA_LY9_QSFP_QDB_GPIO_MOD_EN_N, ONLP_GPIO_DIRECTION_OUT); + ret = onlp_gpio_set(QUANTA_LY9_QSFP_QDB_GPIO_MOD_EN_N, 0); } } + for(i = 53; i < 55; i++) { + qsfp = QSFP_GET(i); + onlp_gpio_export(qsfp->present_gpio, ONLP_GPIO_DIRECTION_IN); + } return ret; } @@ -98,9 +110,6 @@ onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) return ONLP_STATUS_OK; } -#define SFP_GET(_port) (sfpmap__ + _port - 49) -#define QSFP_GET(_port) (qsfpmap__ + _port - 53) - int onlp_sfpi_is_present(int port) { @@ -110,8 +119,8 @@ onlp_sfpi_is_present(int port) qsfpmap_t* qsfp = QSFP_GET(port); if(qsfp->present_gpio > 0) { - if(pca953x_gpio_value_get(qsfp->present_gpio, &value) == ONLP_STATUS_OK) - return (value == GPIO_LOW); + if(onlp_gpio_get(qsfp->present_gpio, &value) == ONLP_STATUS_OK) + return (value == 0); else return ONLP_STATUS_E_MISSING; }