Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[device/alibaba]: Add reset_all function to sfputil #134

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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