Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4b85757
temp commit for independent modules code
dbarashinvd Aug 17, 2023
90aa94e
update modules mgmt to have new state db table
dbarashinvd Sep 20, 2023
c19187d
Fix issues and separate to static module detection
dbarashinvd Sep 26, 2023
b71e69e
fix issues and change waiting list to Set
dbarashinvd Oct 1, 2023
f105501
added fixes and retries to power on and hw reset
dbarashinvd Oct 8, 2023
87fe6e8
added mci max freq. write commmented out due to bug in SDK
dbarashinvd Oct 11, 2023
e222cf0
change all logger from warning to info
dbarashinvd Oct 11, 2023
0b2bea5
fix comments of internal CR part 1
dbarashinvd Oct 11, 2023
97f9f47
fix CR comments part 2
dbarashinvd Oct 12, 2023
9fbcbe3
remove workaround using hw_reset for xcvr_api returned None
dbarashinvd Oct 16, 2023
fa65a6a
fix CR comments part 3 and add critical fixes
dbarashinvd Oct 17, 2023
c29d578
fix test_change_event test and align code to it
Junchao-Mellanox Oct 19, 2023
fc3912a
Add copyright header and try except for fds poller
dbarashinvd Oct 25, 2023
6824551
fix DPB bug of port not exists
dbarashinvd Oct 26, 2023
21586c2
fix get_sfp returns None
dbarashinvd Oct 29, 2023
f966b80
Junchao: Fix issues found in module detection flow
Junchao-Mellanox Nov 2, 2023
ca7d986
Junchao: Fix issue: wrong FD is used for dynamic detection
Junchao-Mellanox Nov 3, 2023
e555c06
Junchao: Fix issue: dummy read flow should use poll
Junchao-Mellanox Nov 6, 2023
f1ce61a
Junchao: fix typo in modules_mgmt
Junchao-Mellanox Nov 7, 2023
100fd69
Junchao: workaround for dummy read issue
Junchao-Mellanox Nov 7, 2023
875e73e
fix log typo and dynamic issue, remove old dummy
dbarashinvd Nov 13, 2023
d43b683
add hw_present fd registration to poll for shutdown port
dbarashinvd Nov 15, 2023
a52f918
fix plug out-in not detected when independent mode disabled
dbarashinvd Nov 22, 2023
b926a3f
fix dynamic detection not resetting states upon cable plug out
dbarashinvd Nov 26, 2023
40a3c68
Merge branch 'master' of github.com:Azure/sonic-buildimage into dbara…
dbarashinvd Nov 27, 2023
ccec845
fix dynamic detection cable plug in flow
dbarashinvd Nov 27, 2023
4210b1b
Update modules_mgmt thread to be a daemon and deleted the use of the …
dbarashinvd Dec 4, 2023
95eefa9
Merge branch 'sonic-net:master' into dbarashi_indep_mode_temp
dbarashinvd Dec 5, 2023
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
59 changes: 35 additions & 24 deletions platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
from . import utils
from .device_data import DeviceDataManager
import re
import queue
import threading
import time
from sonic_platform import modules_mgmt
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

Expand Down Expand Up @@ -124,6 +127,10 @@ def __init__(self):
self._RJ45_port_inited = False
self._RJ45_port_list = None

self.modules_mgmt_thread = threading.Thread()
self.modules_changes_queue = queue.Queue()
self.modules_mgmt_task_stopping_event = threading.Event()

logger.log_info("Chassis loaded successfully")

def __del__(self):
Expand Down Expand Up @@ -371,7 +378,7 @@ def get_change_event(self, timeout=0):

Returns:
(bool, dict):
- True if call successful, False if not;
- True if call successful, False if not; - Deprecated, will always return True
- A nested dictionary where key is a device type,
value is a dictionary with key:value pairs in the format of
{'device_id':'device_event'},
Expand All @@ -383,38 +390,42 @@ def get_change_event(self, timeout=0):
indicates that fan 0 has been removed, fan 2
has been inserted and sfp 11 has been removed.
"""
if not self.modules_mgmt_thread.is_alive():
# open new SFP change events thread
self.modules_mgmt_thread = modules_mgmt.ModulesMgmtTask(q=self.modules_changes_queue
, main_thread_stop_event = self.modules_mgmt_task_stopping_event)
# Set the thread as daemon so when pmon/xcvrd are shutting down, modules_mgmt will shut down immedietly.
self.modules_mgmt_thread.daemon = True
self.modules_mgmt_thread.start()
self.initialize_sfp()
# Initialize SFP event first
if not self.sfp_event:
from .sfp_event import sfp_event
self.sfp_event = sfp_event(self.RJ45_port_list)
self.sfp_event.initialize()

wait_for_ever = (timeout == 0)
# select timeout should be no more than 1000ms to ensure fast shutdown flow
select_timeout = 1000.0 if timeout >= 1000 else float(timeout)
# poll timeout should be no more than 1000ms to ensure fast shutdown flow
timeout = 1000.0 if timeout >= 1000 else float(timeout)
port_dict = {}
error_dict = {}
begin = time.time()
i = 0
while True:
status = self.sfp_event.check_sfp_status(port_dict, error_dict, select_timeout)
if bool(port_dict):
break

if not wait_for_ever:
elapse = time.time() - begin
if elapse * 1000 > timeout:
break
try:
logger.log_info(f'get_change_event() trying to get changes from queue on iteration {i}')
port_dict = self.modules_changes_queue.get(timeout=timeout / 1000)
logger.log_info(f'get_change_event() iteration {i} port_dict: {port_dict}')
except queue.Empty:
logger.log_info(f"failed to get item from modules changes queue on itertaion {i}")

if status:
if port_dict:
self.reinit_sfps(port_dict)
result_dict = {'sfp': port_dict}
if error_dict:
result_dict = {'sfp': port_dict}
result_dict['sfp_error'] = error_dict
return True, result_dict
else:
return True, {'sfp': {}}
return True, result_dict
else:
if not wait_for_ever:
elapse = time.time() - begin
logger.log_info(f"get_change_event: wait_for_ever {wait_for_ever} elapse {elapse} iteartion {i}")
if elapse * 1000 >= timeout:
logger.log_info(f"elapse {elapse} > timeout {timeout} iteartion {i} returning empty dict")
return True, {'sfp': {}}
i += 1

def reinit_sfps(self, port_dict):
"""
Expand All @@ -426,7 +437,7 @@ def reinit_sfps(self, port_dict):
for index, status in port_dict.items():
if status == sfp.SFP_STATUS_INSERTED:
try:
self._sfp_list[index - 1].reinit()
self._sfp_list[int(index) - 1].reinit()
except Exception as e:
logger.log_error("Fail to re-initialize SFP {} - {}".format(index, repr(e)))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ def is_psu_hotswapable(cls):
@classmethod
@utils.read_only_cache()
def get_sfp_count(cls):
return utils.read_int_from_file('/run/hw-management/config/module_counter')
sfp_count = utils.read_int_from_file('/run/hw-management/config/sfp_counter')
return sfp_count if sfp_count > 0 else len(glob.glob('/sys/module/sx_core/asic0/module*'))

@classmethod
def get_linecard_sfp_count(cls, lc_index):
Expand Down
Loading