@@ -706,76 +706,16 @@ def is_timer_expired(self, expired_time, current_time=None):
706706
707707 return expired_time <= current_time
708708
709- def process_single_lport (self , lport , info , gearbox_lanes_dict ):
710- is_fast_reboot = common .is_fast_reboot_enabled ()
711-
709+ def process_cmis_state_machine (self , lport ):
710+ port_info = self .port_dict [lport ]
712711 state = common .get_cmis_state_from_state_db (lport , self .xcvr_table_helper .get_status_sw_tbl (self .get_asic_id (lport )))
713- if state in CMIS_TERMINAL_STATES or state == CMIS_STATE_UNKNOWN :
714- if state != CMIS_STATE_READY :
715- self .port_dict [lport ]['appl' ] = 0
716- self .port_dict [lport ]['host_lanes_mask' ] = 0
717- return
718-
719- # Handle the case when Xcvrd was NOT running when 'host_tx_ready' or 'admin_status'
720- # was updated or this is the first run so reconcile the above two attributes
721- if 'host_tx_ready' not in self .port_dict [lport ]:
722- self .port_dict [lport ]['host_tx_ready' ] = self .get_host_tx_status (lport )
723-
724- if 'admin_status' not in self .port_dict [lport ]:
725- self .port_dict [lport ]['admin_status' ] = self .get_port_admin_status (lport )
726-
727- pport = int (info .get ('index' , "-1" ))
728- speed = int (info .get ('speed' , "0" ))
729- lanes = info .get ('lanes' , "" ).strip ()
730- subport = info .get ('subport' , 0 )
731- if pport < 0 or speed == 0 or len (lanes ) < 1 or subport < 0 :
732- return
733-
734- # Desired port speed on the host side
735- host_speed = speed
736- host_lane_count = self .get_host_lane_count (lport , lanes , gearbox_lanes_dict )
737-
738- # double-check the HW presence before moving forward
739- sfp = self .platform_chassis .get_sfp (pport )
740- if not sfp .get_presence ():
741- self .update_port_transceiver_status_table_sw_cmis_state (lport , CMIS_STATE_REMOVED )
742- return
743-
744- try :
745- # Skip if XcvrApi is not supported
746- api = sfp .get_xcvr_api ()
747- if api is None :
748- self .log_error ("{}: skipping CMIS state machine since no xcvr api!!!" .format (lport ))
749- self .update_port_transceiver_status_table_sw_cmis_state (lport , CMIS_STATE_READY )
750- return
751-
752- # Skip if it's not a paged memory device
753- if api .is_flat_memory ():
754- self .log_notice ("{}: skipping CMIS state machine for flat memory xcvr" .format (lport ))
755- self .update_port_transceiver_status_table_sw_cmis_state (lport , CMIS_STATE_READY )
756- return
757-
758- # Skip if it's not a CMIS module
759- type = api .get_module_type_abbreviation ()
760- if (type is None ) or (type not in self .CMIS_MODULE_TYPES ):
761- self .log_notice ("{}: skipping CMIS state machine for non-CMIS module with type {}" .format (lport , type ))
762- self .update_port_transceiver_status_table_sw_cmis_state (lport , CMIS_STATE_READY )
763- return
764-
765- if api .is_coherent_module ():
766- if 'tx_power' not in self .port_dict [lport ]:
767- self .port_dict [lport ]['tx_power' ] = self .get_configured_tx_power_from_db (lport )
768- if 'laser_freq' not in self .port_dict [lport ]:
769- self .port_dict [lport ]['laser_freq' ] = self .get_configured_laser_freq_from_db (lport )
770- except AttributeError :
771- # Skip if these essential routines are not available
772- self .update_port_transceiver_status_table_sw_cmis_state (lport , CMIS_STATE_READY )
773- return
774- except Exception as e :
775- self .log_error ("{}: Exception in xcvr api: {}" .format (lport , e ))
776- common .log_exception_traceback ()
777- self .update_port_transceiver_status_table_sw_cmis_state (lport , CMIS_STATE_FAILED )
778- return
712+ speed = port_info .get ('speed' )
713+ api = port_info .get ('api' )
714+ host_lane_count = port_info .get ('host_lane_count' )
715+ subport = port_info .get ('subport' )
716+ pport = port_info .get ('pport' )
717+ sfp = port_info .get ('sfp' )
718+ is_fast_reboot = common .is_fast_reboot_enabled ()
779719
780720 # CMIS expiration and retries
781721 #
@@ -806,10 +746,10 @@ def process_single_lport(self, lport, info, gearbox_lanes_dict):
806746 try :
807747 # CMIS state transitions
808748 if state == CMIS_STATE_INSERTED :
809- self .port_dict [lport ]['appl' ] = common .get_cmis_application_desired (api , host_lane_count , host_speed )
749+ self .port_dict [lport ]['appl' ] = common .get_cmis_application_desired (api , host_lane_count , speed )
810750 if self .port_dict [lport ]['appl' ] is None :
811751 self .log_error ("{}: no suitable app for the port appl {} host_lane_count {} "
812- "host_speed {}" .format (lport , appl , host_lane_count , host_speed ))
752+ "host_speed {}" .format (lport , appl , host_lane_count , speed ))
813753 self .update_port_transceiver_status_table_sw_cmis_state (lport , CMIS_STATE_FAILED )
814754 return
815755 appl = self .port_dict [lport ]['appl' ]
@@ -1085,6 +1025,83 @@ def process_single_lport(self, lport, info, gearbox_lanes_dict):
10851025 common .log_exception_traceback ()
10861026 self .update_port_transceiver_status_table_sw_cmis_state (lport , CMIS_STATE_FAILED )
10871027
1028+ def process_single_lport (self , lport , info , gearbox_lanes_dict ):
1029+ state = common .get_cmis_state_from_state_db (lport , self .xcvr_table_helper .get_status_sw_tbl (self .get_asic_id (lport )))
1030+ if state in CMIS_TERMINAL_STATES or state == CMIS_STATE_UNKNOWN :
1031+ if state != CMIS_STATE_READY :
1032+ self .port_dict [lport ]['appl' ] = 0
1033+ self .port_dict [lport ]['host_lanes_mask' ] = 0
1034+ return
1035+
1036+ # Handle the case when Xcvrd was NOT running when 'host_tx_ready' or 'admin_status'
1037+ # was updated or this is the first run so reconcile the above two attributes
1038+ if 'host_tx_ready' not in self .port_dict [lport ]:
1039+ self .port_dict [lport ]['host_tx_ready' ] = self .get_host_tx_status (lport )
1040+
1041+ if 'admin_status' not in self .port_dict [lport ]:
1042+ self .port_dict [lport ]['admin_status' ] = self .get_port_admin_status (lport )
1043+
1044+ pport = int (info .get ('index' , "-1" ))
1045+ speed = int (info .get ('speed' , "0" ))
1046+ lanes = info .get ('lanes' , "" ).strip ()
1047+ subport = info .get ('subport' , 0 )
1048+ if pport < 0 or speed == 0 or len (lanes ) < 1 or subport < 0 :
1049+ return
1050+
1051+ host_lane_count = self .get_host_lane_count (lport , lanes , gearbox_lanes_dict )
1052+
1053+ # double-check the HW presence before moving forward
1054+ sfp = self .platform_chassis .get_sfp (pport )
1055+ if not sfp .get_presence ():
1056+ self .update_port_transceiver_status_table_sw_cmis_state (lport , CMIS_STATE_REMOVED )
1057+ return
1058+
1059+ try :
1060+ # Skip if XcvrApi is not supported
1061+ api = sfp .get_xcvr_api ()
1062+ if api is None :
1063+ self .log_error ("{}: skipping CMIS state machine since no xcvr api!!!" .format (lport ))
1064+ self .update_port_transceiver_status_table_sw_cmis_state (lport , CMIS_STATE_READY )
1065+ return
1066+
1067+ # Skip if it's not a paged memory device
1068+ if api .is_flat_memory ():
1069+ self .log_notice ("{}: skipping CMIS state machine for flat memory xcvr" .format (lport ))
1070+ self .update_port_transceiver_status_table_sw_cmis_state (lport , CMIS_STATE_READY )
1071+ return
1072+
1073+ # Skip if it's not a CMIS module
1074+ type = api .get_module_type_abbreviation ()
1075+ if (type is None ) or (type not in self .CMIS_MODULE_TYPES ):
1076+ self .log_notice ("{}: skipping CMIS state machine for non-CMIS module with type {}" .format (lport , type ))
1077+ self .update_port_transceiver_status_table_sw_cmis_state (lport , CMIS_STATE_READY )
1078+ return
1079+
1080+ if api .is_coherent_module ():
1081+ if 'tx_power' not in self .port_dict [lport ]:
1082+ self .port_dict [lport ]['tx_power' ] = self .get_configured_tx_power_from_db (lport )
1083+ if 'laser_freq' not in self .port_dict [lport ]:
1084+ self .port_dict [lport ]['laser_freq' ] = self .get_configured_laser_freq_from_db (lport )
1085+
1086+ # Store port information in port_dict for use by process_cmis_state_machine
1087+ self .port_dict [lport ]['pport' ] = pport
1088+ self .port_dict [lport ]['speed' ] = speed
1089+ self .port_dict [lport ]['subport' ] = subport
1090+ self .port_dict [lport ]['host_lane_count' ] = host_lane_count
1091+ self .port_dict [lport ]['api' ] = api
1092+ self .port_dict [lport ]['sfp' ] = sfp
1093+ except AttributeError :
1094+ # Skip if these essential routines are not available
1095+ self .update_port_transceiver_status_table_sw_cmis_state (lport , CMIS_STATE_READY )
1096+ return
1097+ except Exception as e :
1098+ self .log_error ("{}: Exception in xcvr api: {}" .format (lport , e ))
1099+ common .log_exception_traceback ()
1100+ self .update_port_transceiver_status_table_sw_cmis_state (lport , CMIS_STATE_FAILED )
1101+ return
1102+
1103+ self .process_cmis_state_machine (lport )
1104+
10881105 def task_worker (self ):
10891106 # APPL_DB for CONFIG updates, and STATE_DB for insertion/removal
10901107 port_change_observer = PortChangeObserver (self .namespaces , helper_logger ,
@@ -1109,7 +1126,6 @@ def task_worker(self):
11091126
11101127 self .log_notice ("Stopped" )
11111128
1112-
11131129 def run (self ):
11141130 if self .platform_chassis is None :
11151131 self .log_notice ("Platform chassis is not available, stopping..." )
0 commit comments