Skip to content

Commit 10dc16f

Browse files
authored
[y_cable] add support for enable/disable autoswitch feature on Y cable (sonic-net#176)
This PR adds functions definition with details for enabling/disabling Y cable auto-switch feature Description Added functions for enabling/disabling auto-switch on Y cable def set_switching_mode(physical_port, mode) def get_switching_mode(physical_port) Motivation and Context We need to have this feature within host cli so that a user can enable/disable the autoswitch on Y cable How Has This Been Tested? opened a python shell and executed API's for correctness Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
1 parent c6c81a8 commit 10dc16f

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

sonic_y_cable/y_cable.py

+91
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
OFFSET_INTERNAL_VOLTAGE = 26
5353
OFFSET_NIC_TEMPERATURE = 727
5454
OFFSET_NIC_VOLTAGE = 729
55+
OFFSET_ENABLE_AUTO_SWITCH = 651
5556

5657
# definitions of targets for getting the cursor
5758
# equalization parameters from the register spec
@@ -91,6 +92,10 @@
9192

9293
MAX_NUM_LANES = 4
9394

95+
# switching modes inside muxcable
96+
SWITCHING_MODE_MANUAL = 0
97+
SWITCHING_MODE_AUTO = 1
98+
9499
# Valid return codes for upgrade firmware routine steps
95100
FIRMWARE_DOWNLOAD_SUCCESS = 0
96101
FIRMWARE_DOWNLOAD_FAILURE = 1
@@ -1365,6 +1370,7 @@ def download_firmware(physical_port, fwfile):
13651370

13661371
return FIRMWARE_DOWNLOAD_SUCCESS
13671372

1373+
13681374
def activate_firmware(physical_port):
13691375
""" This routine should activate the downloaded firmware on all the
13701376
components of the Y cable of the port specified.
@@ -1385,6 +1391,7 @@ def activate_firmware(physical_port):
13851391

13861392
return FIRMWARE_ACTIVATE_SUCCESS
13871393

1394+
13881395
def rollback_firmware(physical_port):
13891396
""" This routine should rollback the firmware to the previous version
13901397
which was being used by the cable. This API is intended to be called when the
@@ -1401,3 +1408,87 @@ def rollback_firmware(physical_port):
14011408
"""
14021409

14031410
return FIRMWARE_ROLLBACK_SUCCESS
1411+
1412+
1413+
def set_switching_mode(physical_port, mode):
1414+
"""
1415+
This API specifically enables the auto switching or manual switching feature on the muxcable,
1416+
depending upon the mode entered by the user.
1417+
Autoswitch feature if enabled actually does an automatic toggle of the mux in case the active
1418+
side link goes down and basically points the mux to the other side.
1419+
1420+
Register Specification at offset 139 is documented below
1421+
1422+
Byte offset bits Name Description
1423+
139 0 Switch Target "0x01 - enable auto switchover; if both TOR#1 and TOR#2 are linked and the active link fails,
1424+
the cable will automatically switchover to the inactive link.
1425+
0x00 - disable auto switchover. Default is disabled."
1426+
1427+
1428+
Args:
1429+
physical_port:
1430+
an Integer, the actual physical port connected to Y end of a Y cable which can toggle the MUX
1431+
mode:
1432+
an Integer, specifies which type of switching mode we set the muxcable to
1433+
either SWITCHING_MODE_AUTO or SWITCHING_MODE_MANUAL
1434+
1435+
Returns:
1436+
a Boolean, true if the switch succeeded and false if it did not succeed.
1437+
"""
1438+
1439+
if mode == SWITCHING_MODE_AUTO:
1440+
buffer = bytearray([1])
1441+
elif mode == SWITCHING_MODE_MANUAL:
1442+
buffer = bytearray([0])
1443+
else:
1444+
helper_logger.log_error(
1445+
"ERR: invalid mode provided for autoswitch feature, failed to do a switch")
1446+
return False
1447+
1448+
curr_offset = OFFSET_ENABLE_AUTO_SWITCH
1449+
1450+
if platform_chassis is not None:
1451+
result = platform_chassis.get_sfp(
1452+
physical_port).write_eeprom(curr_offset, 1, buffer)
1453+
else:
1454+
helper_logger.log_error("platform_chassis is not loaded, failed to do a switch target")
1455+
return False
1456+
1457+
return result
1458+
1459+
def get_switching_mode(physical_port):
1460+
"""
1461+
This API specifically returns which type of switching mode the cable is set to auto/manual
1462+
1463+
Register Specification at offset 139 is documented below
1464+
1465+
Byte offset bits Name Description
1466+
139 0 Switch Target "0x01 - enable auto switchover; if both TOR#1 and TOR#2 are linked and the active link fails,
1467+
the cable will automatically switchover to the inactive link.
1468+
0x00 - disable auto switchover. Default is disabled."
1469+
1470+
1471+
Args:
1472+
physical_port:
1473+
an Integer, the actual physical port connected to Y end of a Y cable which can toggle the MUX
1474+
1475+
Returns:
1476+
an Integer, SWITCHING_MODE_AUTO if auto switch is enabled.
1477+
SWITCHING_MODE_MANUAL if manual switch is enabled.
1478+
"""
1479+
1480+
curr_offset = OFFSET_ENABLE_AUTO_SWITCH
1481+
1482+
if platform_chassis is not None:
1483+
result = platform_chassis.get_sfp(
1484+
physical_port).read_eeprom(curr_offset, 1)
1485+
if y_cable_validate_read_data(result, 1, physical_port, "check if autoswitch is enabled") == EEPROM_READ_DATA_INVALID:
1486+
return EEPROM_ERROR
1487+
else:
1488+
helper_logger.log_error("platform_chassis is not loaded, failed to get the switch mode")
1489+
return -1
1490+
1491+
if result[0] == 1:
1492+
return SWITCHING_MODE_AUTO
1493+
else:
1494+
return SWITCHING_MODE_MANUAL

0 commit comments

Comments
 (0)