Skip to content

Commit 92d5cde

Browse files
committed
[Accton][as5835-54x][as5835-54t] Add set/get sfp module_reset functionality
Signed-off-by: Eric Yang <eric_yang@accton.com>
1 parent 28f52e6 commit 92d5cde

2 files changed

Lines changed: 98 additions & 12 deletions

File tree

  • packages/platforms/accton/x86-64
    • as5835-54t/onlp/builds/x86_64_accton_as5835_54t/module/src
    • as5835-54x/onlp/builds/x86_64_accton_as5835_54x/module/src

packages/platforms/accton/x86-64/as5835-54t/onlp/builds/x86_64_accton_as5835_54t/module/src/sfpi.c

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@
3131

3232
int sfp_map[] = {28,29,26,30,31,27};
3333

34+
#define VALIDATE_QSFP(_port) \
35+
do { \
36+
if (_port < 48 || _port > 53 ) \
37+
return ONLP_STATUS_E_UNSUPPORTED; \
38+
} while(0)
39+
3440
#define PORT_BUS_INDEX(port) (sfp_map[port-48])
3541

3642
#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom"
3743
#define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/3-0062/module_present_%d"
3844
#define MODULE_PRESENT_ALL_ATTR "/sys/bus/i2c/devices/3-0062/module_present_all"
45+
#define MODULE_RESET_FORMAT "/sys/bus/i2c/devices/3-0062/module_reset_%d"
3946

4047
/************************************************************
4148
*
@@ -214,13 +221,56 @@ onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value)
214221
int
215222
onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value)
216223
{
217-
return ONLP_STATUS_E_UNSUPPORTED;
224+
int rv;
225+
226+
switch(control)
227+
{
228+
case ONLP_SFP_CONTROL_RESET:
229+
{
230+
VALIDATE_QSFP(port);
231+
if (onlp_file_write_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) {
232+
AIM_LOG_ERROR("Unable to write reset status to port(%d)\r\n", port);
233+
rv = ONLP_STATUS_E_INTERNAL;
234+
}
235+
else {
236+
rv = ONLP_STATUS_OK;
237+
}
238+
break;
239+
}
240+
241+
default:
242+
rv = ONLP_STATUS_E_UNSUPPORTED;
243+
break;
244+
}
245+
246+
return rv;
218247
}
219248

220249
int
221250
onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
222251
{
223-
return ONLP_STATUS_E_UNSUPPORTED;
252+
int rv;
253+
254+
switch(control)
255+
{
256+
case ONLP_SFP_CONTROL_RESET:
257+
{
258+
VALIDATE_QSFP(port);
259+
if (onlp_file_read_int(value, MODULE_RESET_FORMAT, (port+1)) < 0) {
260+
AIM_LOG_ERROR("Unable to read reset status from port(%d)\r\n", port);
261+
rv = ONLP_STATUS_E_INTERNAL;
262+
}
263+
else {
264+
rv = ONLP_STATUS_OK;
265+
}
266+
break;
267+
}
268+
269+
default:
270+
rv = ONLP_STATUS_E_UNSUPPORTED;
271+
}
272+
273+
return rv;
224274
}
225275

226276
int

packages/platforms/accton/x86-64/as5835-54x/onlp/builds/x86_64_accton_as5835_54x/module/src/sfpi.c

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,26 @@ int sfp_map[] = {
3838
26,30,31,27
3939
};
4040

41+
#define VALIDATE_SFP(_port) \
42+
do { \
43+
if (_port < 0 || _port > 47) \
44+
return ONLP_STATUS_E_UNSUPPORTED; \
45+
} while(0)
46+
47+
#define VALIDATE_QSFP(_port) \
48+
do { \
49+
if (_port < 48 || _port > 53 ) \
50+
return ONLP_STATUS_E_UNSUPPORTED; \
51+
} while(0)
52+
4153
#define PORT_BUS_INDEX(port) (sfp_map[port])
4254

4355
#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom"
4456
#define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_present_%d"
4557
#define MODULE_RXLOS_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_rx_los_%d"
4658
#define MODULE_TXFAULT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_fault_%d"
4759
#define MODULE_TXDISABLE_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_disable_%d"
60+
#define MODULE_RESET_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_reset_%d"
4861
#define MODULE_PRESENT_ALL_ATTR "/sys/bus/i2c/devices/%d-00%d/module_present_all"
4962
#define MODULE_RXLOS_ALL_ATTR_CPLD2 "/sys/bus/i2c/devices/3-0061/module_rx_los_all"
5063
#define MODULE_RXLOS_ALL_ATTR_CPLD3 "/sys/bus/i2c/devices/3-0062/module_rx_los_all"
@@ -324,16 +337,14 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value)
324337
{
325338
int rv;
326339

327-
if (port < 0 || port >= 48) {
328-
return ONLP_STATUS_E_UNSUPPORTED;
329-
}
330340

331341
int addr = (port < 38) ? 61 : 62;
332342

333343
switch(control)
334344
{
335345
case ONLP_SFP_CONTROL_TX_DISABLE:
336346
{
347+
VALIDATE_SFP(port);
337348
if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, 3, addr, (port+1)) < 0) {
338349
AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n", port);
339350
rv = ONLP_STATUS_E_INTERNAL;
@@ -344,6 +355,19 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value)
344355
break;
345356
}
346357

358+
case ONLP_SFP_CONTROL_RESET:
359+
{
360+
VALIDATE_QSFP(port);
361+
if (onlp_file_write_int(value, MODULE_RESET_FORMAT, 3, addr, (port+1)) < 0) {
362+
AIM_LOG_ERROR("Unable to write reset status to port(%d)\r\n", port);
363+
rv = ONLP_STATUS_E_INTERNAL;
364+
}
365+
else {
366+
rv = ONLP_STATUS_OK;
367+
}
368+
break;
369+
}
370+
347371
default:
348372
rv = ONLP_STATUS_E_UNSUPPORTED;
349373
break;
@@ -357,17 +381,14 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
357381
{
358382
int rv;
359383

360-
if (port < 0 || port >= 48) {
361-
return ONLP_STATUS_E_UNSUPPORTED;
362-
}
363-
364384
int addr = (port < 38) ? 61 : 62;
365385

366386
switch(control)
367387
{
368388
case ONLP_SFP_CONTROL_RX_LOS:
369389
{
370-
if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, 3, addr, (port+1)) < 0) {
390+
VALIDATE_SFP(port);
391+
if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, 3, addr, (port+1)) < 0) {
371392
AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", port);
372393
rv = ONLP_STATUS_E_INTERNAL;
373394
}
@@ -379,7 +400,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
379400

380401
case ONLP_SFP_CONTROL_TX_FAULT:
381402
{
382-
if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, 3, addr, (port+1)) < 0) {
403+
VALIDATE_SFP(port);
404+
if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, 3, addr, (port+1)) < 0) {
383405
AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port);
384406
rv = ONLP_STATUS_E_INTERNAL;
385407
}
@@ -391,7 +413,8 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
391413

392414
case ONLP_SFP_CONTROL_TX_DISABLE:
393415
{
394-
if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, 3, addr, (port+1)) < 0) {
416+
VALIDATE_SFP(port);
417+
if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, 3, addr, (port+1)) < 0) {
395418
AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", port);
396419
rv = ONLP_STATUS_E_INTERNAL;
397420
}
@@ -401,6 +424,19 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value)
401424
break;
402425
}
403426

427+
case ONLP_SFP_CONTROL_RESET:
428+
{
429+
VALIDATE_QSFP(port);
430+
if (onlp_file_read_int(value, MODULE_RESET_FORMAT, 3, addr, (port+1)) < 0) {
431+
AIM_LOG_ERROR("Unable to read reset status from port(%d)\r\n", port);
432+
rv = ONLP_STATUS_E_INTERNAL;
433+
}
434+
else {
435+
rv = ONLP_STATUS_OK;
436+
}
437+
break;
438+
}
439+
404440
default:
405441
rv = ONLP_STATUS_E_UNSUPPORTED;
406442
}

0 commit comments

Comments
 (0)