From 22e351983a077ede1e634a99ce15fd8655f6994c Mon Sep 17 00:00:00 2001 From: "Oleksandr Shamray oleksandrs@mellanox.com" Date: Wed, 24 May 2017 10:36:27 +0000 Subject: [PATCH] Added onlp_sfp_dev_readb and onlp_sfp_dev_readw support to msn2100, msn2410 and msn2700 systems V2->v1 Comments pointed out by Vadim: - remove unnecessary braces; Signed-off-by: Oleksandr Shamray --- .../onlp/builds/src/module/src/sfpi.c | 51 +++++++++++++++++- .../onlp/builds/src/module/src/sfpi.c | 53 ++++++++++++++++++- .../onlp/builds/src/module/src/sfpi.c | 51 +++++++++++++++++- 3 files changed, 149 insertions(+), 6 deletions(-) diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sfpi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sfpi.c index 51fa0147..6b799584 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2100/onlp/builds/src/module/src/sfpi.c @@ -68,6 +68,13 @@ msn2100_sfp_get_port_path(int port, char *node_name) return sfp_node_path; } +static char* +msn2100_sfp_convert_i2c_path(int port, int devaddr) +{ + sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d", port); + return sfp_node_path; +} + /************************************************************ * * SFPI Entry Points @@ -150,7 +157,27 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) int onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) { - return ONLP_STATUS_E_UNSUPPORTED; + char* path = msn2100_sfp_convert_i2c_path(port, devaddr); + uint8_t data; + int fd; + int nrd; + + if (!path) + return ONLP_STATUS_E_MISSING; + + fd = open(path, O_RDONLY); + if (fd < 0) + return ONLP_STATUS_E_MISSING; + + lseek(fd, addr, SEEK_SET); + nrd = read(fd, &data, 1); + close(fd); + + if (nrd != 1) { + AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); + return ONLP_STATUS_E_INTERNAL; + } + return data; } int @@ -162,7 +189,27 @@ onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) int onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) { - return ONLP_STATUS_E_UNSUPPORTED; + char* path = msn2100_sfp_convert_i2c_path(port, devaddr); + uint16_t data; + int fd; + int nrd; + + if (!path) + return ONLP_STATUS_E_MISSING; + + fd = open(path, O_RDONLY); + if (fd < 0) + return ONLP_STATUS_E_MISSING; + + lseek(fd, addr, SEEK_SET); + nrd = read(fd, &data, 2); + close(fd); + + if (nrd != 2) { + AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); + return ONLP_STATUS_E_INTERNAL; + } + return data; } int diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sfpi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sfpi.c index 7ee8262a..bc65322a 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2410/onlp/builds/src/module/src/sfpi.c @@ -68,6 +68,13 @@ msn2410_sfp_get_port_path(int port, char *node_name) return sfp_node_path; } +static char* +sn2410_sfp_convert_i2c_path(int port, int devaddr) +{ + sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d", port); + return sfp_node_path; +} + /************************************************************ * * SFPI Entry Points @@ -153,7 +160,27 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) int onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) { - return ONLP_STATUS_E_UNSUPPORTED; + char* path = sn2410_sfp_convert_i2c_path(port, devaddr); + uint8_t data; + int fd; + int nrd; + + if (!path) + return ONLP_STATUS_E_MISSING; + + fd = open(path, O_RDONLY); + if (fd < 0) + return ONLP_STATUS_E_MISSING; + + lseek(fd, addr, SEEK_SET); + nrd = read(fd, &data, 1); + close(fd); + + if (nrd != 1) { + AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); + return ONLP_STATUS_E_INTERNAL; + } + return data; } int @@ -165,7 +192,29 @@ onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) int onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) { - return ONLP_STATUS_E_UNSUPPORTED; + char* path = sn2410_sfp_convert_i2c_path(port, devaddr); + uint16_t data; + int fd; + int nrd; + + if (!path){ + return ONLP_STATUS_E_MISSING; + } + + fd = open(path, O_RDONLY); + if (fd < 0) { + return ONLP_STATUS_E_MISSING; + } + + lseek(fd, addr, SEEK_SET); + nrd = read(fd, &data, 2); + close(fd); + + if (nrd != 2) { + AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); + return ONLP_STATUS_E_INTERNAL; + } + return data; } int diff --git a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sfpi.c b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sfpi.c index 4e9851f9..ad5b5fa7 100644 --- a/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/mellanox/x86-64/x86-64-mlnx-msn2700/onlp/builds/src/module/src/sfpi.c @@ -68,6 +68,13 @@ sn2700_sfp_get_port_path(int port, char *node_name) return sfp_node_path; } +static char* +sn2700_sfp_convert_i2c_path(int port, int devaddr) +{ + sprintf(sfp_node_path, "/bsp/qsfp/qsfp%d", port); + return sfp_node_path; +} + /************************************************************ * * SFPI Entry Points @@ -153,7 +160,27 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) int onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) { - return ONLP_STATUS_E_UNSUPPORTED; + char* path = sn2700_sfp_convert_i2c_path(port, devaddr); + uint8_t data; + int fd; + int nrd; + + if (!path) + return ONLP_STATUS_E_MISSING; + + fd = open(path, O_RDONLY); + if (fd < 0) + return ONLP_STATUS_E_MISSING; + + lseek(fd, addr, SEEK_SET); + nrd = read(fd, &data, 1); + close(fd); + + if (nrd != 1) { + AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); + return ONLP_STATUS_E_INTERNAL; + } + return data; } int @@ -165,7 +192,27 @@ onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) int onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) { - return ONLP_STATUS_E_UNSUPPORTED; + char* path = sn2700_sfp_convert_i2c_path(port, devaddr); + uint16_t data; + int fd; + int nrd; + + if (!path) + return ONLP_STATUS_E_MISSING; + + fd = open(path, O_RDONLY); + if (fd < 0) + return ONLP_STATUS_E_MISSING; + + lseek(fd, addr, SEEK_SET); + nrd = read(fd, &data, 2); + close(fd); + + if (nrd != 2) { + AIM_LOG_INTERNAL("Failed to read EEPROM file '%s'", path); + return ONLP_STATUS_E_INTERNAL; + } + return data; } int