Skip to content

Commit

Permalink
[201807][platform] Accton: As5712-54x. Fix sfputil and accton_util (#…
Browse files Browse the repository at this point in the history
…2002)

* [platform] accton as5712-54x, fixed
    1. Check i2c buses, they may get fliped on every bootup.
    2. QSFP's lp_mode and reset are out of port order.
    3. Change QSFP is reset with 1 second period.
Signed-off-by: roy_lee <[email protected]>

* [platform] accton as5712-54x. Fix util.py error about SFP/QSFP's tx_disable and present.
Signed-off-by: roy_lee <[email protected]>
  • Loading branch information
roylee123 authored and lguohan committed Aug 30, 2018
1 parent 5e48e6c commit f07181e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 14 deletions.
66 changes: 53 additions & 13 deletions device/accton/x86_64-accton_as5712_54x-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#
# Platform-specific SFP transceiver interface for SONiC
#

try:
import time
import os
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
Expand All @@ -21,8 +21,14 @@ class SfpUtil(SfpUtilBase):

BASE_VAL_PATH = "/sys/class/i2c-adapter/i2c-{0}/{1}-0050/"
BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/"
BASE_CPLD2_PATH = "/sys/bus/i2c/devices/0-0061/"
BASE_CPLD3_PATH = "/sys/bus/i2c/devices/0-0062/"
BASE_CPLD2_PATH = "/sys/bus/i2c/devices/{0}-0061/"
BASE_CPLD3_PATH = "/sys/bus/i2c/devices/{0}-0062/"
I2C_BUS_ORDER = -1

#The sidebands of QSFP is different.
#present is in-order.
#But lp_mode and reset are not.
qsfp_sb_map = [1, 3, 5, 2, 4, 6]

_port_to_is_present = {}
_port_to_lp_mode = {}
Expand Down Expand Up @@ -137,18 +143,30 @@ def __init__(self):

SfpUtilBase.__init__(self)

#Two i2c buses might get flipped order, check them both.
def update_i2c_order(self):
if self.I2C_BUS_ORDER < 0:
eeprom_path = "/sys/bus/i2c/devices/1-0057/eeprom"
if os.path.exists(eeprom_path):
self.I2C_BUS_ORDER = 0
eeprom_path = "/sys/bus/i2c/devices/0-0057/eeprom"
if os.path.exists(eeprom_path):
self.I2C_BUS_ORDER = 1
return self.I2C_BUS_ORDER

def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False

order = self.update_i2c_order()
if port_num < 24:
present_path = self.BASE_CPLD2_PATH + "module_present_" + str(self._port_to_i2c_mapping[port_num][0])
present_path = self.BASE_CPLD2_PATH.format(order)
else:
present_path = self.BASE_CPLD3_PATH + "module_present_" + str(self._port_to_i2c_mapping[port_num][0])
present_path = self.BASE_CPLD3_PATH.format(order)

present_path = present_path + "module_present_" + str(self._port_to_i2c_mapping[port_num][0])
self.__port_to_is_present = present_path


try:
val_file = open(self.__port_to_is_present)
Expand All @@ -165,11 +183,21 @@ def get_presence(self, port_num):

return False

def qsfp_sb_remap(self, port_num):
qsfp_start = self.qsfp_port_start
qsfp_index = self._port_to_i2c_mapping[port_num][0] - qsfp_start
qsfp_index = self.qsfp_sb_map[qsfp_index-1]
return qsfp_start+qsfp_index

def get_low_power_mode(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False

lp_mode_path = self.BASE_CPLD3_PATH + "module_lp_mode_" + str(self._port_to_i2c_mapping[port_num][0])
order = self.update_i2c_order()
lp_mode_path = self.BASE_CPLD3_PATH.format(order)
lp_mode_path = lp_mode_path + "module_lp_mode_"
q = self.qsfp_sb_remap(port_num)
lp_mode_path = lp_mode_path + str(q)

try:
val_file = open(lp_mode_path)
Expand All @@ -190,7 +218,11 @@ def set_low_power_mode(self, port_num, lpmode):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False

lp_mode_path = self.BASE_CPLD3_PATH + "module_lp_mode_" + str(self._port_to_i2c_mapping[port_num][0])
order = self.update_i2c_order()
lp_mode_path = self.BASE_CPLD3_PATH.format(order)
lp_mode_path = lp_mode_path + "module_lp_mode_"
q = self.qsfp_sb_remap(port_num)
lp_mode_path = lp_mode_path + str(q)

try:
reg_file = open(lp_mode_path, 'r+')
Expand All @@ -212,17 +244,25 @@ def reset(self, port_num):
if port_num < self.qsfp_port_start or port_num > self.qsfp_port_end:
return False

mod_rst_path = lp_mode_path = self.BASE_CPLD3_PATH + "module_reset_" + str(self._port_to_i2c_mapping[port_num][0])
order = self.update_i2c_order()
lp_mode_path = self.BASE_CPLD3_PATH.format(order)
mod_rst_path = lp_mode_path + "module_reset_"
q = self.qsfp_sb_remap(port_num)
mod_rst_path = mod_rst_path + str(q)

try:
reg_file = open(mod_rst_path, 'r+')
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False

reg_value = '1'

reg_file.write(reg_value)
#toggle reset
reg_file.seek(0)
reg_file.write('0')
time.sleep(1)
reg_file.seek(0)
reg_file.write('1')
reg_file.close()
return True

return True
return True
2 changes: 1 addition & 1 deletion platform/broadcom/sonic-platform-modules-accton
Submodule sonic-platform-modules-accton updated 81 files
+16 −0 as5712-54x/service/as5712-platform-monitor-fan.service
+16 −0 as5712-54x/service/as5712-platform-monitor-psu.service
+141 −0 as5712-54x/utils/accton_as5712_monitor_fan.py
+187 −0 as5712-54x/utils/accton_as5712_monitor_psu.py
+116 −32 as5712-54x/utils/accton_as5712_util.py
+0 −0 as6712-32x/classes/__init__.py
+253 −0 as6712-32x/classes/fanutil.py
+124 −0 as6712-32x/classes/thermalutil.py
+2 −0 as6712-32x/modules/Makefile
+946 −0 as6712-32x/modules/accton-as6712-32x-cpld.c
+463 −0 as6712-32x/modules/accton_as6712_32x_fan.c
+364 −0 as6712-32x/modules/accton_as6712_32x_psu.c
+1 −0 as6712-32x/modules/cpr_4011_4mxx.c
+612 −0 as6712-32x/modules/leds-accton_as6712_32x.c
+1 −0 as6712-32x/modules/ym2651y.c
+17 −0 as6712-32x/service/as6712-platform-init.service
+16 −0 as6712-32x/setup.py
+74 −0 as6712-32x/utils/README
+208 −0 as6712-32x/utils/accton_as6712_monitor.py
+627 −0 as6712-32x/utils/accton_as6712_util.py
+5 −6 as7326-56x/classes/fanutil.py
+173 −0 as7326-56x/classes/psu.py
+95 −37 as7326-56x/classes/thermalutil.py
+16 −0 as7326-56x/service/as7326-platform-handle_mac.service
+16 −0 as7326-56x/service/as7326-platform-monitor-fan.service
+16 −0 as7326-56x/service/as7326-platform-monitor-psu.service
+1 −1 as7326-56x/service/as7326-platform-monitor.service
+1 −1 as7326-56x/utils/README
+224 −106 as7326-56x/utils/accton_as7326_monitor.py
+200 −0 as7326-56x/utils/accton_as7326_monitor_fan.py
+190 −0 as7326-56x/utils/accton_as7326_monitor_psu.py
+148 −4 as7326-56x/utils/accton_as7326_util.py
+20 −0 as7326-56x/utils/accton_handle_mac.sh
+234 −0 as7326-56x/utils/mac_reset.sh
+0 −0 as7726-32x/classes/__init__.py
+251 −0 as7726-32x/classes/fanutil.py
+128 −0 as7726-32x/classes/thermalutil.py
+19 −0 as7726-32x/modules/Makefile
+934 −0 as7726-32x/modules/accton_as7726_32x_cpld.c
+766 −0 as7726-32x/modules/accton_as7726_32x_fan.c
+438 −0 as7726-32x/modules/accton_as7726_32x_leds.c
+276 −0 as7726-32x/modules/accton_as7726_32x_psu.c
+603 −0 as7726-32x/modules/ym2651y.c
+55 −0 as7726-32x/modules/ym2651y.mod.c
+16 −0 as7726-32x/service/as7726-32x-platform-handle_mac.service
+16 −0 as7726-32x/service/as7726-32x-platform-monitor-fan.service
+16 −0 as7726-32x/service/as7726-32x-platform-monitor-psu.service
+18 −0 as7726-32x/service/as7726-32x-platform-monitor.service
+16 −0 as7726-32x/setup.py
+117 −0 as7726-32x/utils/README
+206 −0 as7726-32x/utils/accton_as7726_32x_monitor.py
+200 −0 as7726-32x/utils/accton_as7726_32x_monitor_fan.py
+169 −0 as7726-32x/utils/accton_as7726_32x_monitor_psu.py
+560 −0 as7726-32x/utils/accton_as7726_32x_util.py
+20 −0 as7726-32x/utils/accton_handle_mac.sh
+241 −0 as7726-32x/utils/mac_reset.sh
+238 −0 as7816-64x/classes/fanutil.py
+123 −0 as7816-64x/classes/thermalutil.py
+9 −5 as7816-64x/service/as7816-platform-init.service
+153 −0 as7816-64x/utils/accton_as7816_monitor.py
+5 −1 as7816-64x/utils/accton_as7816_util.py
+0 −0 common/classes/__init__.py
+1 −0 common/modules/Makefile
+83 −46 common/modules/cpr_4011_4mxx.c
+1 −0 common/service/accton-platform-command.service
+16 −0 common/setup.py
+22 −1 debian/control
+2 −1 debian/rules
+0 −0 wedge100bf-32x/classes/__init__.py
+0 −0 wedge100bf-32x/modules/Makefile
+13 −0 wedge100bf-32x/service/wedge100bf-platform-init.service
+16 −0 wedge100bf-32x/setup.py
+28 −0 wedge100bf-32x/utils/README
+533 −0 wedge100bf-32x/utils/accton_wedge100bf_util.py
+0 −0 wedge100bf-65x/classes/__init__.py
+19 −0 wedge100bf-65x/modules/Makefile
+1,261 −0 wedge100bf-65x/modules/accton_wedge100bf_psensor.c
+13 −0 wedge100bf-65x/service/wedge100bf-platform-init.service
+16 −0 wedge100bf-65x/setup.py
+28 −0 wedge100bf-65x/utils/README
+624 −0 wedge100bf-65x/utils/accton_wedge100bf_util.py

0 comments on commit f07181e

Please sign in to comment.