3030#include "x86_64_accton_as7515_24x_log.h"
3131#include "platform_lib.h"
3232
33+ #define VALIDATE (_port ) \
34+ do { \
35+ if (_port < 0 || _port > 23) { \
36+ return ONLP_STATUS_E_INVALID; \
37+ } \
38+ } while(0)
39+
3340#define VALIDATE_SFP (_port ) \
3441 do { \
3542 if (_port < 4 || _port > 23) \
5158#define MODULE_LPMODE_FORMAT "/sys/devices/platform/as7515_24x_sfp/module_lpmode_%d"
5259#define MODULE_PRESENT_ALL_ATTR "/sys/devices/platform/as7515_24x_sfp/module_present_all"
5360#define MODULE_RXLOS_ALL_ATTR "/sys/devices/platform/as7515_24x_sfp/module_rx_los_all"
61+ /* QSFP device address of eeprom */
62+ #define PORT_EEPROM_DEVADDR 0x50
63+ /* QSFP tx disable offset */
64+ #define QSFP_EEPROM_OFFSET_TXDIS 0x56
5465
5566#define NUM_OF_SFP_PORT 24
5667static const int port_bus_index [NUM_OF_SFP_PORT ] = {
@@ -96,6 +107,7 @@ onlp_sfpi_is_present(int port)
96107 * Return < 0 if error.
97108 */
98109 int present ;
110+ VALIDATE (port );
99111
100112 if (onlp_file_read_int (& present , MODULE_PRESENT_FORMAT , port + 1 ) < 0 ) {
101113 AIM_LOG_ERROR ("Unable to read present status from port(%d)\r\n" , port + 1 );
@@ -181,7 +193,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)
181193 /* Read rx los status of each port */
182194 fp = fopen (MODULE_RXLOS_ALL_ATTR , "r" );
183195 if (fp == NULL ) {
184- AIM_LOG_ERROR ("Unable to open the module_present_all device file of CPLD." );
196+ AIM_LOG_ERROR ("Unable to open the module_rx_los_all device file of CPLD." );
185197 return ONLP_STATUS_E_INTERNAL ;
186198 }
187199
@@ -190,7 +202,7 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst)
190202
191203 if (count != 3 ) {
192204 /* Likely a CPLD read timeout. */
193- AIM_LOG_ERROR ("Unable to read all fields the module_present_all device file of CPLD." );
205+ AIM_LOG_ERROR ("Unable to read all fields the module_rx_los_all device file of CPLD." );
194206 return ONLP_STATUS_E_INTERNAL ;
195207 }
196208
@@ -223,6 +235,8 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256])
223235 * Return OK if eeprom is read
224236 */
225237 int size = 0 ;
238+
239+ VALIDATE (port );
226240 memset (data , 0 , 256 );
227241
228242 if (onlp_file_read (data , 256 , & size , MODULE_EEPROM_FORMAT , PORT_BUS_INDEX (port )) != ONLP_STATUS_OK ) {
@@ -270,44 +284,60 @@ onlp_sfpi_dom_read(int port, uint8_t data[256])
270284int
271285onlp_sfpi_dev_readb (int port , uint8_t devaddr , uint8_t addr )
272286{
273- int bus = PORT_BUS_INDEX (port );
274- return onlp_i2c_readb (bus , devaddr , addr , ONLP_I2C_F_FORCE );
287+ VALIDATE (port );
288+ return onlp_i2c_readb (PORT_BUS_INDEX ( port ) , devaddr , addr , ONLP_I2C_F_FORCE );
275289}
276290
277291int
278292onlp_sfpi_dev_writeb (int port , uint8_t devaddr , uint8_t addr , uint8_t value )
279293{
280- int bus = PORT_BUS_INDEX (port );
281- return onlp_i2c_writeb (bus , devaddr , addr , value , ONLP_I2C_F_FORCE );
294+ VALIDATE (port );
295+ return onlp_i2c_writeb (PORT_BUS_INDEX ( port ) , devaddr , addr , value , ONLP_I2C_F_FORCE );
282296}
283297
284298int
285299onlp_sfpi_dev_readw (int port , uint8_t devaddr , uint8_t addr )
286300{
287- int bus = PORT_BUS_INDEX (port );
288- return onlp_i2c_readw (bus , devaddr , addr , ONLP_I2C_F_FORCE );
301+ VALIDATE (port );
302+ return onlp_i2c_readw (PORT_BUS_INDEX ( port ) , devaddr , addr , ONLP_I2C_F_FORCE );
289303}
290304
291305int
292306onlp_sfpi_dev_writew (int port , uint8_t devaddr , uint8_t addr , uint16_t value )
293307{
294- int bus = PORT_BUS_INDEX (port );
295- return onlp_i2c_writew (bus , devaddr , addr , value , ONLP_I2C_F_FORCE );
308+ VALIDATE (port );
309+ return onlp_i2c_writew (PORT_BUS_INDEX ( port ) , devaddr , addr , value , ONLP_I2C_F_FORCE );
296310}
297311
298312int
299313onlp_sfpi_control_set (int port , onlp_sfp_control_t control , int value )
300314{
301- switch (control ) {
302- case ONLP_SFP_CONTROL_TX_DISABLE : {
303- VALIDATE_SFP (port );
315+ int present = 0 ;
304316
305- if (onlp_file_write_int (value , MODULE_TXDISABLE_FORMAT , port + 1 ) < 0 ) {
306- AIM_LOG_ERROR ("Unable to set tx_disable status to port(%d)\r\n" , port );
317+ switch (control ) {
318+ case ONLP_SFP_CONTROL_TX_DISABLE :
319+ case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL : {
320+ VALIDATE (port );
321+ present = onlp_sfpi_is_present (port );
322+ if (present == 1 ) {
323+ if (port >= 0 && port < 4 ) {
324+ /* txdis valid bit(bit0-bit3), xxxx 1111 */
325+ value = value & 0xf ;
326+
327+ onlp_sfpi_dev_writeb (port , PORT_EEPROM_DEVADDR , QSFP_EEPROM_OFFSET_TXDIS , value );
328+
329+ return ONLP_STATUS_OK ;
330+ } else {
331+ if (onlp_file_write_int (value , MODULE_TXDISABLE_FORMAT , port + 1 ) < 0 ) {
332+ AIM_LOG_ERROR ("Unable to set tx_disable status to port(%d)\r\n" , port );
333+ return ONLP_STATUS_E_INTERNAL ;
334+ }
335+ return ONLP_STATUS_OK ;
336+ }
337+ } else {
338+ AIM_LOG_ERROR ("No transceiver is present in port(%d)\r\n" , port );
307339 return ONLP_STATUS_E_INTERNAL ;
308340 }
309-
310- return ONLP_STATUS_OK ;
311341 }
312342 case ONLP_SFP_CONTROL_RESET_STATE : {
313343 VALIDATE_QSFP (port );
@@ -323,7 +353,7 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value)
323353 VALIDATE_QSFP (port );
324354
325355 if (onlp_file_write_int (value , MODULE_LPMODE_FORMAT , port + 1 ) < 0 ) {
326- AIM_LOG_ERROR ("Unable to write reset status to port(%d)\r\n" , port );
356+ AIM_LOG_ERROR ("Unable to write lpmode status to port(%d)\r\n" , port );
327357 return ONLP_STATUS_E_INTERNAL ;
328358 }
329359
@@ -339,6 +369,9 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value)
339369int
340370onlp_sfpi_control_get (int port , onlp_sfp_control_t control , int * value )
341371{
372+ int present = 0 ;
373+ int tx_dis = 0 ;
374+
342375 * value = 0 ;
343376
344377 switch (control ) {
@@ -364,15 +397,28 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
364397 return ONLP_STATUS_OK ;
365398 }
366399
367- case ONLP_SFP_CONTROL_TX_DISABLE : {
368- VALIDATE_SFP (port );
369-
370- if (onlp_file_read_int (value , MODULE_TXDISABLE_FORMAT , port + 1 ) < 0 ) {
371- AIM_LOG_ERROR ("Unable to read tx_disabled status from port(%d)\r\n" , port );
400+ case ONLP_SFP_CONTROL_TX_DISABLE :
401+ case ONLP_SFP_CONTROL_TX_DISABLE_CHANNEL : {
402+ VALIDATE (port );
403+ present = onlp_sfpi_is_present (port );
404+ if (present == 1 ) {
405+ if (port >= 0 && port < 4 ) {
406+ tx_dis = onlp_sfpi_dev_readb (port , PORT_EEPROM_DEVADDR , QSFP_EEPROM_OFFSET_TXDIS );
407+
408+ * value = tx_dis ;
409+
410+ return ONLP_STATUS_OK ;
411+ } else {
412+ if (onlp_file_read_int (value , MODULE_TXDISABLE_FORMAT , port + 1 ) < 0 ) {
413+ AIM_LOG_ERROR ("Unable to read tx_disabled status from port(%d)\r\n" , port );
414+ return ONLP_STATUS_E_INTERNAL ;
415+ }
416+ return ONLP_STATUS_OK ;
417+ }
418+ } else {
419+ AIM_LOG_ERROR ("No transceiver is present in port(%d)\r\n" , port );
372420 return ONLP_STATUS_E_INTERNAL ;
373421 }
374-
375- return ONLP_STATUS_OK ;
376422 }
377423 case ONLP_SFP_CONTROL_RESET_STATE : {
378424 VALIDATE_QSFP (port );
0 commit comments