Skip to content

Commit 691de92

Browse files
authored
[sonic_y_cable] add stub function for upgrade firmware of Y cable and split the get_part_number and get_vendor API's (sonic-net#171)
This PR adds a stub function definition with details as to how it should be implemented by a Y cable vendor. Description Added a stub function definition with a doc string describing how it should be implemented Cleaning up and split some API's for vendors Motivation and Context Firmware upgrade is a functionality that vendors need to implement, this PR adds the definition and a description of how the implementation of this firmware_upgrade API should be How Has This Been Tested? Will be tested once implemented for cleanup API's opened a python shell and executed API's for correctness Signed-off-by: vaibhav-dahiya <[email protected]>
1 parent c6b642b commit 691de92

File tree

1 file changed

+131
-13
lines changed

1 file changed

+131
-13
lines changed

sonic_y_cable/y_cable.py

+131-13
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
OFFSET_MAX_LANES = 2
4242
OFFSET_INITIATE_EYE_MEASUREMENT = 784
4343
OFFSET_LANE_1_EYE_RESULT = 785
44-
OFFSET_PN_NUMBER = 168
44+
OFFSET_PART_NUMBER = 168
4545
OFFSET_VENDOR_NAME = 148
4646
OFFSET_MANUAL_SWITCH_COUNT = 653
4747
OFFSET_AUTO_SWITCH_COUNT = 657
@@ -92,6 +92,10 @@
9292

9393
MAX_NUM_LANES = 4
9494

95+
# Valid return codes for upgrade_firmware() routine
96+
FIRMWARE_UPGRADE_SUCCESS = 0
97+
FIRMWARE_UPGRADE_FAILURE = 1
98+
9599
SYSLOG_IDENTIFIER = "sonic_y_cable"
96100

97101
# Global logger instance for helper functions and classes to log
@@ -977,33 +981,56 @@ def get_eye_info(physical_port, target):
977981
return eye_result
978982

979983

980-
def get_pn_number_and_vendor_name(physical_port):
984+
def get_part_number(physical_port):
981985
"""
982-
This API specifically returns the pn number and vendor name for a specfic port.
986+
This API specifically returns the part number of the Y cable for a specfic port.
983987
984988
Args:
985989
physical_port:
986990
an Integer, the actual physical port connected to a Y cable
987991
Returns:
988-
a tuple, with pn_number and vendor name
992+
a string, with part number
989993
"""
990994

991-
curr_offset = OFFSET_PN_NUMBER
995+
curr_offset = OFFSET_PART_NUMBER
992996

993997
if platform_chassis is not None:
994-
pn_result = platform_chassis.get_sfp(physical_port).read_eeprom(curr_offset, 15)
995-
if y_cable_validate_read_data(pn_result, 15, physical_port, "PN number") == EEPROM_READ_DATA_INVALID:
996-
return EEPROM_ERROR
997-
curr_offset = OFFSET_VENDOR_NAME
998-
vendor_name = platform_chassis.get_sfp(physical_port).read_eeprom(curr_offset, 15)
999-
if y_cable_validate_read_data(vendor_name, 15, physical_port, "vendor name") == EEPROM_READ_DATA_INVALID:
998+
part_result = platform_chassis.get_sfp(physical_port).read_eeprom(curr_offset, 15)
999+
if y_cable_validate_read_data(part_result, 15, physical_port, "Part number") == EEPROM_READ_DATA_INVALID:
10001000
return EEPROM_ERROR
1001+
else:
1002+
helper_logger.log_error("platform_chassis is not loaded, failed to get part number")
1003+
return -1
1004+
1005+
part_number = str(part_result.decode())
1006+
1007+
return part_number
1008+
1009+
1010+
def get_vendor(physical_port):
1011+
"""
1012+
This API specifically returns the vendor name of the Y cable for a specfic port.
1013+
1014+
Args:
1015+
physical_port:
1016+
an Integer, the actual physical port connected to a Y cable
1017+
Returns:
1018+
a string, with vendor name
1019+
"""
10011020

1021+
curr_offset = OFFSET_VENDOR_NAME
1022+
1023+
if platform_chassis is not None:
1024+
result = platform_chassis.get_sfp(physical_port).read_eeprom(curr_offset, 15)
1025+
if y_cable_validate_read_data(result, 15, physical_port, "Vendor name") == EEPROM_READ_DATA_INVALID:
1026+
return EEPROM_ERROR
10021027
else:
1003-
helper_logger.log_error("platform_chassis is not loaded, failed to get pin results")
1028+
helper_logger.log_error("platform_chassis is not loaded, failed to get Vendor name")
10041029
return -1
10051030

1006-
return pn_result, vendor_name
1031+
vendor_name = str(result.decode())
1032+
1033+
return vendor_name
10071034

10081035

10091036
def get_switch_count(physical_port, count_type):
@@ -1237,3 +1264,94 @@ def get_nic_voltage_temp(physical_port):
12371264
return -1
12381265

12391266
return temp, voltage
1267+
1268+
1269+
def get_local_temperature(physical_port):
1270+
1271+
curr_offset = OFFSET_INTERNAL_TEMPERATURE
1272+
if platform_chassis is not None:
1273+
result = platform_chassis.get_sfp(physical_port).read_eeprom(curr_offset, 1)
1274+
if y_cable_validate_read_data(result, 1, physical_port, "local temperature") == EEPROM_READ_DATA_INVALID:
1275+
return EEPROM_ERROR
1276+
temp = result[0]
1277+
else:
1278+
helper_logger.log_error("platform_chassis is not loaded, failed to get local temp")
1279+
return -1
1280+
1281+
return temp
1282+
1283+
1284+
def get_local_voltage(physical_port):
1285+
1286+
if platform_chassis is not None:
1287+
curr_offset = OFFSET_INTERNAL_VOLTAGE
1288+
msb_result = platform_chassis.get_sfp(physical_port).read_eeprom(curr_offset, 1)
1289+
if y_cable_validate_read_data(msb_result, 1, physical_port, "local voltage MSB") == EEPROM_READ_DATA_INVALID:
1290+
return EEPROM_ERROR
1291+
lsb_result = platform_chassis.get_sfp(physical_port).read_eeprom(curr_offset+1, 1)
1292+
if y_cable_validate_read_data(lsb_result, 1, physical_port, "local voltage LSB") == EEPROM_READ_DATA_INVALID:
1293+
return EEPROM_ERROR
1294+
1295+
voltage = (((msb_result[0] << 8) | lsb_result[0]) * 0.0001)
1296+
else:
1297+
helper_logger.log_error("platform_chassis is not loaded, failed to get local voltage")
1298+
return -1
1299+
1300+
return voltage
1301+
1302+
1303+
def get_nic_temperature(physical_port):
1304+
1305+
curr_offset = OFFSET_NIC_TEMPERATURE
1306+
if platform_chassis is not None:
1307+
result = platform_chassis.get_sfp(physical_port).read_eeprom(curr_offset, 1)
1308+
if y_cable_validate_read_data(result, 1, physical_port, "NIC temperature") == EEPROM_READ_DATA_INVALID:
1309+
return EEPROM_ERROR
1310+
temp = result[0]
1311+
else:
1312+
helper_logger.log_error("platform_chassis is not loaded, failed to get NIC temp")
1313+
return -1
1314+
1315+
return temp
1316+
1317+
1318+
def get_nic_voltage(physical_port):
1319+
1320+
curr_offset = OFFSET_NIC_VOLTAGE
1321+
if platform_chassis is not None:
1322+
msb_result = platform_chassis.get_sfp(physical_port).read_eeprom(curr_offset, 1)
1323+
if y_cable_validate_read_data(msb_result, 1, physical_port, "NIC voltage MSB") == EEPROM_READ_DATA_INVALID:
1324+
return EEPROM_ERROR
1325+
lsb_result = platform_chassis.get_sfp(physical_port).read_eeprom(curr_offset+1, 1)
1326+
if y_cable_validate_read_data(lsb_result, 1, physical_port, "NIC voltage LSB") == EEPROM_READ_DATA_INVALID:
1327+
return EEPROM_ERROR
1328+
1329+
voltage = (((msb_result[0] << 8) | lsb_result[0]) * 0.0001)
1330+
else:
1331+
helper_logger.log_error("platform_chassis is not loaded, failed to get NIC voltage")
1332+
return -1
1333+
1334+
return voltage
1335+
1336+
1337+
def upgrade_firmware(physical_port, fwfile):
1338+
""" This routine should facilitate complete firmware
1339+
upgrade of the Y cable on all the three ends of the
1340+
Y cable of the port specified.
1341+
All the components of the Y cable should be upgraded and committed
1342+
in their entirety by this single call subroutine.
1343+
This should return success code if firmware upgrade is successful
1344+
and an error code otherwise.
1345+
1346+
Args:
1347+
physical_port:
1348+
an Integer, the actual physical port connected to a Y cable
1349+
fwfile:
1350+
a string, a path to the binary file which contains the firmware image
1351+
Returns:
1352+
an Integer:
1353+
a predefined code stating whether the firmware upgrade was successful
1354+
or an error code as to what was the cause of firmware upgrade failure
1355+
"""
1356+
1357+
return FIRMWARE_UPGRADE_SUCCESS

0 commit comments

Comments
 (0)