Skip to content

Commit

Permalink
Changes for R0C HW
Browse files Browse the repository at this point in the history
* Support lpmode control by CPLD.
* PSU status add led status.

Signed-off-by: Sean Wu <sean_wu@edge-core.com>
  • Loading branch information
seanwu-ec committed Nov 3, 2021
1 parent d80c699 commit fa571f6
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 85 deletions.
74 changes: 29 additions & 45 deletions device/accton/x86_64-accton_as9726_32d-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,61 +125,45 @@ def get_presence(self, port_num):
def get_low_power_mode(self, port_num):
if port_num > self.QSFP_PORT_END: #sfp not support lpmode
return False
try:
eeprom = None

if not self.get_presence(port_num):
return False

eeprom = open(self.port_to_eeprom_mapping[port_num], "rb")
eeprom.seek(93)
lpmode = ord(eeprom.read(1))

if ((lpmode & 0x3) == 0x3):
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
else:
# High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
return False
if port_num <= 16:
lpmode_path = self.BASE_CPLD2_PATH + "module_lpmode_" + str(port_num)
else:
lpmode_path = self.BASE_CPLD3_PATH + "module_lpmode_" + str(port_num)
try:
val_file = open(lpmode_path)
content = val_file.readline().rstrip()
val_file.close()
except IOError as e:
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
if content == "0":
return True

return False


def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num > self.QSFP_PORT_END: #sfp not support lpmode:
return False
if not self.get_presence(port_num):
return False # Port is not present, unable to set lpmode

if port_num <= 16:
lpmode_path = self.BASE_CPLD2_PATH + "module_lpmode_" + str(port_num)
else:
lpmode_path = self.BASE_CPLD3_PATH + "module_lpmode_" + str(port_num)

self.__port_to_mod_lpmode = lpmode_path

if lpmode is True:
ret = self.__write_txt_file(self.__port_to_mod_lpmode, 0) #sysfs 1: enable lpmode
else:
ret = self.__write_txt_file(self.__port_to_mod_lpmode, 1) #sysfs 1: disable lpmode

return ret

try:
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom

# Fill in write buffer
# 0x3:Low Power Mode. "Power override" bit is 1 and "Power set" bit is 1
# 0x9:High Power Mode. "Power override" bit is 1 ,"Power set" bit is 0 and "High Power Class Enable" bit is 1
regval = 0x3 if lpmode else 0x9

buffer = create_string_buffer(1)
buffer[0] = regval

# Write to eeprom
eeprom = open(self.port_to_eeprom_mapping[port_num], "r+b")
eeprom.seek(93)
eeprom.write(buffer[0])
return True
except IOError as e:
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)

def reset(self, port_num):
if port_num > self.QSFP_PORT_END: #sfp not support lpmode:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,15 @@ def get_status_led(self):
Returns:
A string, one of the predefined STATUS_LED_COLOR_* strings above
"""
status=self.get_status()
if status is None:
status_ps=self.get_presence() #present
status=self.get_status() #power good

if status is None or status_ps is False:
return self.STATUS_LED_COLOR_OFF

return {
1: self.STATUS_LED_COLOR_GREEN,
0: self.STATUS_LED_COLOR_RED
0: self.STATUS_LED_COLOR_AMBER
}.get(status, self.STATUS_LED_COLOR_OFF)

def get_temperature(self):
Expand Down
52 changes: 20 additions & 32 deletions device/accton/x86_64-accton_as9726_32d-r0/sonic_platform/sfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1502,37 +1502,20 @@ def get_lpmode(self):
Returns:
A Boolean, True if lpmode is enabled, False if disabled
"""
if self._port_num > 32:
if self._port_num > 32:
# SFP doesn't support this feature
return False

if self._port_num <= 16:
lpmode_path = "{}{}{}".format(CPLD2_I2C_PATH, '/module_lpmode_', self._port_num)
else:
try:
eeprom = None

if not self.get_presence():
return False
# Write to eeprom
port_to_i2c_mapping = SFP_I2C_START + self._index
port_eeprom_path = I2C_EEPROM_PATH.format(port_to_i2c_mapping)

eeprom = open(port_eeprom_path, "rb")
eeprom.seek(QSFP_POWEROVERRIDE_OFFSET)
lpmode = ord(eeprom.read(1))

if ((lpmode & 0x3) == 0x3):
return True # Low Power Mode if "Power override" bit is 1 and "Power set" bit is 1
else:
# High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
return False
except IOError as e:
print("Error: unable to open file: %s" % str(e))
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)
lpmode_path = "{}{}{}".format(CPLD3_I2C_PATH, '/module_lpmode_', self._port_num)

val=self._api_helper.read_txt_file(lpmode_path)
if val is not None:
return int(val, 10)==0
else:
return False

def get_power_set(self):

Expand Down Expand Up @@ -2095,12 +2078,17 @@ def set_lpmode(self, lpmode):
if not self.get_presence():
return False

if lpmode is True:
self.set_power_override(True, True)
if self._port_num <= self.CPLD2_PORT_END:
lpmode_path = "{}{}{}".format(CPLD2_I2C_PATH, 'module_lpmode_', self._port_num)
else:
self.set_power_override(True, False)
lpmode_path = "{}{}{}".format(CPLD3_I2C_PATH, 'module_lpmode_', self._port_num)

return True
if lpmode is True:
ret = self.__write_txt_file(lpmode_path, 0) #enable lpmode
else:
ret = self.__write_txt_file(lpmode_path, 1) #disable lpmode

return ret

def set_power_override(self, power_override, power_set):
"""
Expand Down
Loading

0 comments on commit fa571f6

Please sign in to comment.