Skip to content

Commit

Permalink
[device] accton update driver and sync as5712-54x from 201807. (#2110)
Browse files Browse the repository at this point in the history
* [platform_accton] Remove dependency on particular version of linux.
Signed-off-by: Polly Hsu <polly_hsu@edge-core.com>

* [platfrom] as5712-54x: update i2c_client for linux kernel 4.x.
Signed-off-by: Polly Hsu <polly_hsu@edge-core.com>

* [platform] Update lastest optoe.c from https://github.com/opencomputeproject/oom/blob/master/optoe/optoe.c.
Signed-off-by: roy_lee <roy_lee@accton.com>

* [platform] rm optoe driver here. For it's inside the kernel.
Signed-off-by: roy_lee <roy_lee@accton.com>

* [platform] as5712-54x, merge the change of #2002 which is on branch 201807.
Signed-off-by: roy_lee <roy_lee@accton.com>
  • Loading branch information
roylee123 authored and lguohan committed Oct 2, 2018
1 parent c8e6b15 commit 593bcb1
Show file tree
Hide file tree
Showing 5 changed files with 792 additions and 2,071 deletions.
67 changes: 53 additions & 14 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,25 +244,32 @@ 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

def get_transceiver_change_event(self):
"""
TODO: This function need to be implemented
when decide to support monitoring SFP(Xcvrd)
on this platform.
"""
raise NotImplementedError

Loading

0 comments on commit 593bcb1

Please sign in to comment.