Skip to content

Commit

Permalink
[device/alibaba]: add reset_all function to sfputil
Browse files Browse the repository at this point in the history
  • Loading branch information
Wirut Getbamrung authored and tiantianlv committed Feb 13, 2020
1 parent 06eee13 commit 68f06df
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
41 changes: 41 additions & 0 deletions device/alibaba/x86_64-alibaba_as13-32h-cl-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def __init__(self):
x + self.EEPROM_OFFSET)
SfpUtilBase.__init__(self)

def _do_write_file(self, file_handle, offset, value):
file_handle.seek(offset)
file_handle.write(hex(value))
file_handle.close()

def get_presence(self, port_num):

# Check for invalid port_num
Expand Down Expand Up @@ -203,3 +208,39 @@ def tx_disable(self, port_num, disable):
return False

return True

def reset_all(self):
result = True
port_sysfs_path = []
for port in range(self.port_start, self.port_end+1):
if port not in self.qsfp_ports:
continue

presence = self.get_presence(port)
if not presence:
continue

try:
port_name = self.get_port_name(port)
sysfs_path = "/".join([self.PORT_INFO_PATH,
port_name, "qsfp_reset"])
reg_file = open(sysfs_path, "w")
port_sysfs_path.append(sysfs_path)
except IOError as e:
result = False
continue

self._do_write_file(reg_file, 0, 0)

time.sleep(1)

for sysfs_path in port_sysfs_path:
try:
reg_file = open(sysfs_path, "w")
except IOError as e:
result = False
continue

self._do_write_file(reg_file, 0, 1)

return result
41 changes: 41 additions & 0 deletions device/alibaba/x86_64-alibaba_as13-48f8h-cl-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def __init__(self):
x + self.EEPROM_OFFSET)
SfpUtilBase.__init__(self)

def _do_write_file(self, file_handle, offset, value):
file_handle.seek(offset)
file_handle.write(hex(value))
file_handle.close()

def get_presence(self, port_num):

# Check for invalid port_num
Expand Down Expand Up @@ -203,3 +208,39 @@ def tx_disable(self, port_num, disable):
return False

return True

def reset_all(self):
result = True
port_sysfs_path = []
for port in range(self.port_start, self.port_end+1):
if port not in self.qsfp_ports:
continue

presence = self.get_presence(port)
if not presence:
continue

try:
port_name = self.get_port_name(port)
sysfs_path = "/".join([self.PORT_INFO_PATH,
port_name, "qsfp_reset"])
reg_file = open(sysfs_path, "w")
port_sysfs_path.append(sysfs_path)
except IOError as e:
result = False
continue

self._do_write_file(reg_file, 0, 0)

time.sleep(1)

for sysfs_path in port_sysfs_path:
try:
reg_file = open(sysfs_path, "w")
except IOError as e:
result = False
continue

self._do_write_file(reg_file, 0, 1)

return result
42 changes: 42 additions & 0 deletions device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def __init__(self):
x + self.EEPROM_OFFSET)
SfpUtilBase.__init__(self)

def _do_write_file(self, file_handle, offset, value):
file_handle.seek(offset)
file_handle.write(hex(value))
file_handle.close()

def get_presence(self, port_num):

# Check for invalid port_num
Expand Down Expand Up @@ -203,3 +208,40 @@ def tx_disable(self, port_num, disable):
return False

return True

def reset_all(self):
result = True
port_sysfs_path = []
for port in range(self.port_start, self.port_end+1):
if port not in self.qsfp_ports:
continue

presence = self.get_presence(port)
if not presence:
continue

try:
port_name = self.get_port_name(port)
sysfs_path = "/".join([self.PORT_INFO_PATH,
port_name, "qsfp_reset"])
print(sysfs_path)
reg_file = open(sysfs_path, "w")
port_sysfs_path.append(sysfs_path)
except IOError as e:
result = False
continue

self._do_write_file(reg_file, 0, 0)

time.sleep(1)

for sysfs_path in port_sysfs_path:
try:
reg_file = open(sysfs_path, "w")
except IOError as e:
result = False
continue

self._do_write_file(reg_file, 0, 1)

return result

0 comments on commit 68f06df

Please sign in to comment.