Skip to content

Commit

Permalink
[Mellanox sfputil] update get_transceiver_change_event to support mor…
Browse files Browse the repository at this point in the history
…e event (#3261)
  • Loading branch information
keboliu authored and yxieca committed Aug 8, 2019
1 parent ba3d85e commit c29e2e2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
38 changes: 35 additions & 3 deletions device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
try:
import time
import subprocess
from sonic_sfp.sfputilbase import SfpUtilBase
from sonic_sfp.sfputilbase import *
import syslog
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))

Expand All @@ -18,13 +19,29 @@
# parameters for SFP presence
SFP_STATUS_INSERTED = '1'

# system level event/error
EVENT_ON_ALL_SFP = '-1'
SYSTEM_NOT_READY = 'system_not_ready'
SYSTEM_READY = 'system_become_ready'
SYSTEM_FAIL = 'system_fail'

GET_HWSKU_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.hwsku"

# magic code defnition for port number, qsfp port position of each hwsku
# port_position_tuple = (PORT_START, QSFP_PORT_START, PORT_END, PORT_IN_BLOCK, EEPROM_OFFSET)
hwsku_dict = {'ACS-MSN2700': 0, "LS-SN2700":0, 'ACS-MSN2740': 0, 'ACS-MSN2100': 1, 'ACS-MSN2410': 2, 'ACS-MSN2010': 3, 'ACS-MSN3700': 0, 'ACS-MSN3700C': 0, 'Mellanox-SN2700': 0, 'Mellanox-SN2700-D48C8': 0}
port_position_tuple_list = [(0, 0, 31, 32, 1), (0, 0, 15, 16, 1), (0, 48, 55, 56, 1),(0, 18, 21, 22, 1)]

def log_info(msg, also_print_to_console=False):
syslog.openlog("sfputil")
syslog.syslog(syslog.LOG_INFO, msg)
syslog.closelog()

def log_err(msg, also_print_to_console=False):
syslog.openlog("sfputil")
syslog.syslog(syslog.LOG_ERR, msg)
syslog.closelog()

class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
PORT_START = 0
Expand Down Expand Up @@ -72,6 +89,7 @@ def __init__(self):
self.PORT_END = port_position_tuple[2]
self.PORTS_IN_BLOCK = port_position_tuple[3]
self.EEPROM_OFFSET = port_position_tuple[4]
self.mlnx_sfpd_started = False

for x in range(0, self.port_end + 1):
self._port_to_eeprom_mapping[x] = self.qsfp_sysfs_path + "qsfp{}".format(x + self.EEPROM_OFFSET)
Expand Down Expand Up @@ -171,10 +189,24 @@ def get_transceiver_change_event(self, timeout=0):
self.db_sel_object = swsscommon.Select.OBJECT
self.sfpd_status_tbl = swsscommon.Table(self.state_db, 'MLNX_SFPD_TASK')

# Check the liveness of mlnx-sfpd, if it failed, return false
# Check the liveness of mlnx-sfpd, if it failed, return system_fail event
# If mlnx-sfpd not started, return system_not_ready event
keys = self.sfpd_status_tbl.getKeys()
if 'LIVENESS' not in keys:
return False, phy_port_dict
if self.mlnx_sfpd_started:
log_err("mlnx-sfpd exited, return false to notify xcvrd.")
phy_port_dict[EVENT_ON_ALL_SFP] = SYSTEM_FAIL
return False, phy_port_dict
else:
log_info("mlnx-sfpd not ready, return false to notify xcvrd.")
phy_port_dict[EVENT_ON_ALL_SFP] = SYSTEM_NOT_READY
return False, phy_port_dict
else:
if not self.mlnx_sfpd_started:
self.mlnx_sfpd_started = True
log_info("mlnx-sfpd is running")
phy_port_dict[EVENT_ON_ALL_SFP] = SYSTEM_READY
return False, phy_port_dict

if timeout:
(state, c) = self.db_sel.select(timeout)
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-platform-common

0 comments on commit c29e2e2

Please sign in to comment.