[mellanox] unify the sfp and eeprom plugin for all the mellanox platform (#2174)

This commit is contained in:
Kebo Liu 2018-10-24 11:56:31 +08:00 committed by lguohan
parent 709cd5a9f5
commit 973f83de27
21 changed files with 47 additions and 1718 deletions

View File

@ -1,32 +0,0 @@
#!/usr/bin/env python
#############################################################################
# Mellanox
#
# Platform and model specific eeprom subclass, inherits from the base class,
# and provides the followings:
# - the eeprom format definition
# - specific encoder/decoder if there is special need
#############################################################################
try:
import exceptions
import binascii
import time
import optparse
import warnings
import os
import sys
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/bsp/eeprom/vpd_info"
super(board, self).__init__(self.eeprom_path, 0, '', True)

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/eeprom.py

View File

@ -1,43 +0,0 @@
#!/usr/bin/env python
import sys, errno
import os
from python_sdk_api.sxd_api import *
from python_sdk_api.sx_api import *
# Check if SFP port number is provided
if len(sys.argv) < 2:
print "SFP module number is missed."
print "Usage: sfplpmget.py <SFP module>"
sys.exit(errno.EINVAL)
# Init SDK API
rc, handle = sx_api_open(None)
if (rc != SX_STATUS_SUCCESS):
print "Failed to open api handle.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
pid = os.getpid()
rc = sxd_access_reg_init(pid, None, 0)
if (rc != 0):
print "Failed to initializing register access.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
# Get SFP module number
sfp_module = int(sys.argv[1])
# Get MCION
mcion = ku_mcion_reg()
mcion.module = sfp_module
meta = sxd_reg_meta_t()
meta.dev_id = 1
meta.swid = 0
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_mcion(mcion, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_mcion failed, rc = %d" % rc
# Get low power mode status
lpm_mask = 1 << 8
lpm_status = (lpm_mask & mcion.module_status_bits) != 0
print "LPM ON" if lpm_status else "LPM OFF"

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py

View File

@ -1,107 +0,0 @@
#!/usr/bin/env python
import sys, errno
import time
import os
from python_sdk_api.sxd_api import *
from python_sdk_api.sx_api import *
def get_log_ports(handle, sfp_module):
port_attributes_list = new_sx_port_attributes_t_arr(64)
port_cnt_p = new_uint32_t_p()
uint32_t_p_assign(port_cnt_p, 64)
rc = sx_api_port_device_get(handle, 1 , 0, port_attributes_list, port_cnt_p)
assert rc == SX_STATUS_SUCCESS, "sx_api_port_device_get failed, rc = %d" % rc
port_cnt = uint32_t_p_value(port_cnt_p)
log_port_list = []
for i in range(0, port_cnt):
port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list, i)
if port_attributes.port_mapping.module_port == sfp_module:
log_port_list.append(port_attributes.log_port)
return log_port_list
def set_sfp_admin_status(handle, meta, sfp_module, sfp_log_port_list, admin_status):
# Get PMAOS
pmaos = ku_pmaos_reg()
pmaos.module = sfp_module
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
# Set admin status to PMAOS
pmaos.ase = 1
pmaos.ee = 1
pmaos.e = 2
pmaos.rst = 0
if admin_status == SX_PORT_ADMIN_STATUS_DOWN:
pmaos.admin_status = 2
else:
pmaos.admin_status = 1
meta.access_cmd = SXD_ACCESS_CMD_SET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
# Check if SFP port number is provided
if len(sys.argv) < 3:
print "SFP module number or LPM is missed."
print "Usage: sfplpmset.py <SFP module> <on|off>"
sys.exit(errno.EINVAL)
lpm_enable = None
if sys.argv[2] == 'on':
lpm_enable = True
elif sys.argv[2] == 'off':
lpm_enable = False
else:
print "Unrecognized LPM parameter. Please use <on> or <off> values"
sys.exit(errno.EINVAL)
# Init SDK API
rc, handle = sx_api_open(None)
if (rc != SX_STATUS_SUCCESS):
print "Failed to open api handle.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
pid = os.getpid()
rc = sxd_access_reg_init(pid, None, 0)
if (rc != 0):
print "Failed to initializing register access.\nPlease check that SDK is running."
sys.exit(errno.EACCES);
# Get SFP module and log ports number and LPM status
sfp_module = int(sys.argv[1])
log_port_list = get_log_ports(handle, sfp_module)
if not log_port_list:
print "Failed to get log ports"
sys.exit(errno.EACCES)
# Get PMMP
pmmp = ku_pmmp_reg()
pmmp.module = sfp_module
meta = sxd_reg_meta_t()
meta.dev_id = 1
meta.swid = 0
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_pmmp(pmmp, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmmp failed, rc = %d" % rc
# Disable admin status before LPM settings
set_sfp_admin_status(handle, meta, sfp_module, log_port_list, SX_PORT_ADMIN_STATUS_DOWN)
# Set low power mode status
lpm_mask = 1 << 8
if lpm_enable:
pmmp.eeprom_override = pmmp.eeprom_override | lpm_mask
else:
pmmp.eeprom_override = pmmp.eeprom_override & (~lpm_mask)
meta.access_cmd = SXD_ACCESS_CMD_SET
rc = sxd_access_reg_pmmp(pmmp, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmmp failed, rc = %d" % rc
# Enable admin status after LPM settings
set_sfp_admin_status(handle, meta, sfp_module, log_port_list, SX_PORT_ADMIN_STATUS_UP)

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py

View File

@ -1,45 +0,0 @@
#!/usr/bin/env python
import sys, errno
import os
from python_sdk_api.sxd_api import *
from python_sdk_api.sx_api import *
# Check if SFP port number is provided
if len(sys.argv) < 2:
print "SFP module number or LPM is missed."
print "Usage: sfpreset.py <SFP module>"
sys.exit(errno.EINVAL)
# Init SDK API
rc, handle = sx_api_open(None)
if (rc != SX_STATUS_SUCCESS):
print "Failed to open api handle.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
pid = os.getpid()
rc = sxd_access_reg_init(pid, None, 0)
if (rc != 0):
print "Failed to initializing register access.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
# Get SFP module number
sfp_module = int(sys.argv[1])
# Get PMAOS
pmaos = ku_pmaos_reg()
pmaos.module = sfp_module
meta = sxd_reg_meta_t()
meta.dev_id = 1
meta.swid = 0
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
# Reset SFP
pmaos.rst = 1
meta.access_cmd = SXD_ACCESS_CMD_SET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
print "Reset flag is set"

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfpreset.py

View File

@ -1,201 +0,0 @@
# sfputil.py
#
# Platform-specific SFP transceiver interface for SONiC
#
try:
import time
import subprocess
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
# parameters for DB connection
REDIS_HOSTNAME = "localhost"
REDIS_PORT = 6379
REDIS_TIMEOUT_USECS = 0
# parameters for SFP presence
SFP_STATUS_INSERTED = '1'
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
PORT_START = 0
PORT_END = 21
PORTS_IN_BLOCK = 22
QSFP_PORT_START = 18
EEPROM_OFFSET = 1
_port_to_eeprom_mapping = {}
db_sel = None
db_sel_timeout = None
db_sel_object = None
db_sel_tbl = None
state_db = None
sfpd_status_tbl = None
@property
def port_start(self):
return self.PORT_START
@property
def port_end(self):
return self.PORT_END
@property
def qsfp_ports(self):
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
@property
def port_to_eeprom_mapping(self):
return self._port_to_eeprom_mapping
def __init__(self):
eeprom_path = "/sys/devices/platform/i2c_mlxcpld.1/i2c-1/i2c-2/2-0048/qsfp{0}"
for x in range(0, self.port_end + 1):
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
SfpUtilBase.__init__(self)
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
try:
reg_file = open("/bsp/qsfp/qsfp%d_status" % (port_num+1))
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
content = reg_file.readline().rstrip()
# content is a string with the qsfp status
if content == SFP_STATUS_INSERTED:
return True
return False
def get_low_power_mode(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmget.py {}".format(port_num)
try:
output = subprocess.check_output(lpm_cmd, shell=True)
if 'LPM ON' in output:
return True
except subprocess.CalledProcessError as e:
print "Error! Unable to get LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False
return False
def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
curr_lpmode = self.get_low_power_mode(port_num)
if curr_lpmode == lpmode:
return True
lpm = 'on' if lpmode else 'off'
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmset.py {} {}".format(port_num, lpm)
sfp_port_names = self.physical_to_logical[port_num]
# Get port admin status
try:
enabled_ports = subprocess.check_output("ip link show up", shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to get ports status, err msg: {}".format(e.output)
return False
port_to_disable = []
for port in sfp_port_names:
if port in enabled_ports:
port_to_disable.append(port)
# Disable ports before LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} down".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to DOWN for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False
time.sleep(3)
# Set LPM
try:
subprocess.check_output(lpm_cmd, shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False
# Enable ports after LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} up".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to UP for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False
return True
def reset(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfpreset.py {}".format(port_num)
try:
subprocess.check_output(lpm_cmd, shell=True)
return True
except subprocess.CalledProcessError as e:
print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False
return False
def get_transceiver_change_event(self, timeout=0):
phy_port_dict = {}
status = True
if self.db_sel == None:
from swsscommon import swsscommon
self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
REDIS_HOSTNAME,
REDIS_PORT,
REDIS_TIMEOUT_USECS)
# Subscribe to state table for SFP change notifications
self.db_sel = swsscommon.Select()
self.db_sel_tbl = swsscommon.NotificationConsumer(self.state_db, 'TRANSCEIVER_NOTIFY')
self.db_sel.addSelectable(self.db_sel_tbl)
self.db_sel_timeout = swsscommon.Select.TIMEOUT
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
keys = self.sfpd_status_tbl.getKeys()
if 'LIVENESS' not in keys:
return False, phy_port_dict
(state, c) = self.db_sel.select(timeout)
if state == self.db_sel_timeout:
status = True
elif state != self.db_sel_object:
status = False
else:
(key, op, fvp) = self.db_sel_tbl.pop()
phy_port_dict[key] = op
return status, phy_port_dict

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfputil.py

View File

@ -1,32 +0,0 @@
#!/usr/bin/env python
#############################################################################
# Mellanox
#
# Platform and model specific eeprom subclass, inherits from the base class,
# and provides the followings:
# - the eeprom format definition
# - specific encoder/decoder if there is special need
#############################################################################
try:
import exceptions
import binascii
import time
import optparse
import warnings
import os
import sys
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/bsp/eeprom/vpd_info"
super(board, self).__init__(self.eeprom_path, 0, '', True)

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/eeprom.py

View File

@ -1,43 +0,0 @@
#!/usr/bin/env python
import sys, errno
import os
from python_sdk_api.sxd_api import *
from python_sdk_api.sx_api import *
# Check if SFP port number is provided
if len(sys.argv) < 2:
print "SFP module number is missed."
print "Usage: sfplpmget.py <SFP module>"
sys.exit(errno.EINVAL)
# Init SDK API
rc, handle = sx_api_open(None)
if (rc != SX_STATUS_SUCCESS):
print "Failed to open api handle.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
pid = os.getpid()
rc = sxd_access_reg_init(pid, None, 0)
if (rc != 0):
print "Failed to initializing register access.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
# Get SFP module number
sfp_module = int(sys.argv[1])
# Get MCION
mcion = ku_mcion_reg()
mcion.module = sfp_module
meta = sxd_reg_meta_t()
meta.dev_id = 1
meta.swid = 0
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_mcion(mcion, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_mcion failed, rc = %d" % rc
# Get low power mode status
lpm_mask = 1 << 8
lpm_status = (lpm_mask & mcion.module_status_bits) != 0
print "LPM ON" if lpm_status else "LPM OFF"

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py

View File

@ -1,107 +0,0 @@
#!/usr/bin/env python
import sys, errno
import time
import os
from python_sdk_api.sxd_api import *
from python_sdk_api.sx_api import *
def get_log_ports(handle, sfp_module):
port_attributes_list = new_sx_port_attributes_t_arr(64)
port_cnt_p = new_uint32_t_p()
uint32_t_p_assign(port_cnt_p, 64)
rc = sx_api_port_device_get(handle, 1 , 0, port_attributes_list, port_cnt_p)
assert rc == SX_STATUS_SUCCESS, "sx_api_port_device_get failed, rc = %d" % rc
port_cnt = uint32_t_p_value(port_cnt_p)
log_port_list = []
for i in range(0, port_cnt):
port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list, i)
if port_attributes.port_mapping.module_port == sfp_module:
log_port_list.append(port_attributes.log_port)
return log_port_list
def set_sfp_admin_status(handle, meta, sfp_module, sfp_log_port_list, admin_status):
# Get PMAOS
pmaos = ku_pmaos_reg()
pmaos.module = sfp_module
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
# Set admin status to PMAOS
pmaos.ase = 1
pmaos.ee = 1
pmaos.e = 2
pmaos.rst = 0
if admin_status == SX_PORT_ADMIN_STATUS_DOWN:
pmaos.admin_status = 2
else:
pmaos.admin_status = 1
meta.access_cmd = SXD_ACCESS_CMD_SET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
# Check if SFP port number is provided
if len(sys.argv) < 3:
print "SFP module number or LPM is missed."
print "Usage: sfplpmset.py <SFP module> <on|off>"
sys.exit(errno.EINVAL)
lpm_enable = None
if sys.argv[2] == 'on':
lpm_enable = True
elif sys.argv[2] == 'off':
lpm_enable = False
else:
print "Unrecognized LPM parameter. Please use <on> or <off> values"
sys.exit(errno.EINVAL)
# Init SDK API
rc, handle = sx_api_open(None)
if (rc != SX_STATUS_SUCCESS):
print "Failed to open api handle.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
pid = os.getpid()
rc = sxd_access_reg_init(pid, None, 0)
if (rc != 0):
print "Failed to initializing register access.\nPlease check that SDK is running."
sys.exit(errno.EACCES);
# Get SFP module and log ports number and LPM status
sfp_module = int(sys.argv[1])
log_port_list = get_log_ports(handle, sfp_module)
if not log_port_list:
print "Failed to get log ports"
sys.exit(errno.EACCES)
# Get PMMP
pmmp = ku_pmmp_reg()
pmmp.module = sfp_module
meta = sxd_reg_meta_t()
meta.dev_id = 1
meta.swid = 0
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_pmmp(pmmp, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmmp failed, rc = %d" % rc
# Disable admin status before LPM settings
set_sfp_admin_status(handle, meta, sfp_module, log_port_list, SX_PORT_ADMIN_STATUS_DOWN)
# Set low power mode status
lpm_mask = 1 << 8
if lpm_enable:
pmmp.eeprom_override = pmmp.eeprom_override | lpm_mask
else:
pmmp.eeprom_override = pmmp.eeprom_override & (~lpm_mask)
meta.access_cmd = SXD_ACCESS_CMD_SET
rc = sxd_access_reg_pmmp(pmmp, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmmp failed, rc = %d" % rc
# Enable admin status after LPM settings
set_sfp_admin_status(handle, meta, sfp_module, log_port_list, SX_PORT_ADMIN_STATUS_UP)

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py

View File

@ -1,45 +0,0 @@
#!/usr/bin/env python
import sys, errno
import os
from python_sdk_api.sxd_api import *
from python_sdk_api.sx_api import *
# Check if SFP port number is provided
if len(sys.argv) < 2:
print "SFP module number or LPM is missed."
print "Usage: sfpreset.py <SFP module>"
sys.exit(errno.EINVAL)
# Init SDK API
rc, handle = sx_api_open(None)
if (rc != SX_STATUS_SUCCESS):
print "Failed to open api handle.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
pid = os.getpid()
rc = sxd_access_reg_init(pid, None, 0)
if (rc != 0):
print "Failed to initializing register access.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
# Get SFP module number
sfp_module = int(sys.argv[1])
# Get PMAOS
pmaos = ku_pmaos_reg()
pmaos.module = sfp_module
meta = sxd_reg_meta_t()
meta.dev_id = 1
meta.swid = 0
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
# Reset SFP
pmaos.rst = 1
meta.access_cmd = SXD_ACCESS_CMD_SET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
print "Reset flag is set"

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfpreset.py

View File

@ -1,200 +0,0 @@
# sfputil.py
#
# Platform-specific SFP transceiver interface for SONiC
#
try:
import time
import subprocess
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
# parameters for DB connection
REDIS_HOSTNAME = "localhost"
REDIS_PORT = 6379
REDIS_TIMEOUT_USECS = 0
# parameters for SFP presence
SFP_STATUS_INSERTED = '1'
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
PORT_START = 0
PORT_END = 15
PORTS_IN_BLOCK = 16
EEPROM_OFFSET = 1
_port_to_eeprom_mapping = {}
db_sel = None
db_sel_timeout = None
db_sel_object = None
db_sel_tbl = None
state_db = None
sfpd_status_tbl = None
@property
def port_start(self):
return self.PORT_START
@property
def port_end(self):
return self.PORT_END
@property
def qsfp_ports(self):
return range(0, self.PORTS_IN_BLOCK + 1)
@property
def port_to_eeprom_mapping(self):
return self._port_to_eeprom_mapping
def __init__(self):
eeprom_path = "/sys/devices/platform/i2c_mlxcpld.1/i2c-1/i2c-2/2-0048/qsfp{0}"
for x in range(0, self.port_end + 1):
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
SfpUtilBase.__init__(self)
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
try:
reg_file = open("/bsp/qsfp/qsfp%d_status" % (port_num+1))
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
content = reg_file.readline().rstrip()
# content is a string with the qsfp status
if content == SFP_STATUS_INSERTED:
return True
return False
def get_low_power_mode(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmget.py {}".format(port_num)
try:
output = subprocess.check_output(lpm_cmd, shell=True)
if 'LPM ON' in output:
return True
except subprocess.CalledProcessError as e:
print "Error! Unable to get LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False
return False
def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
curr_lpmode = self.get_low_power_mode(port_num)
if curr_lpmode == lpmode:
return True
lpm = 'on' if lpmode else 'off'
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmset.py {} {}".format(port_num, lpm)
sfp_port_names = self.physical_to_logical[port_num]
# Get port admin status
try:
enabled_ports = subprocess.check_output("ip link show up", shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to get ports status, err msg: {}".format(e.output)
return False
port_to_disable = []
for port in sfp_port_names:
if port in enabled_ports:
port_to_disable.append(port)
# Disable ports before LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} down".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to DOWN for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False
time.sleep(3)
# Set LPM
try:
subprocess.check_output(lpm_cmd, shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False
# Enable ports after LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} up".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to UP for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False
return True
def reset(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfpreset.py {}".format(port_num)
try:
subprocess.check_output(lpm_cmd, shell=True)
return True
except subprocess.CalledProcessError as e:
print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False
return False
def get_transceiver_change_event(self, timeout=0):
phy_port_dict = {}
status = True
if self.db_sel == None:
from swsscommon import swsscommon
self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
REDIS_HOSTNAME,
REDIS_PORT,
REDIS_TIMEOUT_USECS)
# Subscribe to state table for SFP change notifications
self.db_sel = swsscommon.Select()
self.db_sel_tbl = swsscommon.NotificationConsumer(self.state_db, 'TRANSCEIVER_NOTIFY')
self.db_sel.addSelectable(self.db_sel_tbl)
self.db_sel_timeout = swsscommon.Select.TIMEOUT
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
keys = self.sfpd_status_tbl.getKeys()
if 'LIVENESS' not in keys:
return False, phy_port_dict
(state, c) = self.db_sel.select(timeout)
if state == self.db_sel_timeout:
status = True
elif state != self.db_sel_object:
status = False
else:
(key, op, fvp) = self.db_sel_tbl.pop()
phy_port_dict[key] = op
return status, phy_port_dict

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfputil.py

View File

@ -1,32 +0,0 @@
#!/usr/bin/env python
#############################################################################
# Mellanox
#
# Platform and model specific eeprom subclass, inherits from the base class,
# and provides the followings:
# - the eeprom format definition
# - specific encoder/decoder if there is special need
#############################################################################
try:
import exceptions
import binascii
import time
import optparse
import warnings
import os
import sys
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/bsp/eeprom/vpd_info"
super(board, self).__init__(self.eeprom_path, 0, '', True)

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/eeprom.py

View File

@ -1,43 +0,0 @@
#!/usr/bin/env python
import sys, errno
import os
from python_sdk_api.sxd_api import *
from python_sdk_api.sx_api import *
# Check if SFP port number is provided
if len(sys.argv) < 2:
print "SFP module number is missed."
print "Usage: sfplpmget.py <SFP module>"
sys.exit(errno.EINVAL)
# Init SDK API
rc, handle = sx_api_open(None)
if (rc != SX_STATUS_SUCCESS):
print "Failed to open api handle.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
pid = os.getpid()
rc = sxd_access_reg_init(pid, None, 0)
if (rc != 0):
print "Failed to initializing register access.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
# Get SFP module number
sfp_module = int(sys.argv[1])
# Get MCION
mcion = ku_mcion_reg()
mcion.module = sfp_module
meta = sxd_reg_meta_t()
meta.dev_id = 1
meta.swid = 0
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_mcion(mcion, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_mcion failed, rc = %d" % rc
# Get low power mode status
lpm_mask = 1 << 8
lpm_status = (lpm_mask & mcion.module_status_bits) != 0
print "LPM ON" if lpm_status else "LPM OFF"

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py

View File

@ -1,107 +0,0 @@
#!/usr/bin/env python
import sys, errno
import time
import os
from python_sdk_api.sxd_api import *
from python_sdk_api.sx_api import *
def get_log_ports(handle, sfp_module):
port_attributes_list = new_sx_port_attributes_t_arr(64)
port_cnt_p = new_uint32_t_p()
uint32_t_p_assign(port_cnt_p, 64)
rc = sx_api_port_device_get(handle, 1 , 0, port_attributes_list, port_cnt_p)
assert rc == SX_STATUS_SUCCESS, "sx_api_port_device_get failed, rc = %d" % rc
port_cnt = uint32_t_p_value(port_cnt_p)
log_port_list = []
for i in range(0, port_cnt):
port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list, i)
if port_attributes.port_mapping.module_port == sfp_module:
log_port_list.append(port_attributes.log_port)
return log_port_list
def set_sfp_admin_status(handle, meta, sfp_module, sfp_log_port_list, admin_status):
# Get PMAOS
pmaos = ku_pmaos_reg()
pmaos.module = sfp_module
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
# Set admin status to PMAOS
pmaos.ase = 1
pmaos.ee = 1
pmaos.e = 2
pmaos.rst = 0
if admin_status == SX_PORT_ADMIN_STATUS_DOWN:
pmaos.admin_status = 2
else:
pmaos.admin_status = 1
meta.access_cmd = SXD_ACCESS_CMD_SET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
# Check if SFP port number is provided
if len(sys.argv) < 3:
print "SFP module number or LPM is missed."
print "Usage: sfplpmset.py <SFP module> <on|off>"
sys.exit(errno.EINVAL)
lpm_enable = None
if sys.argv[2] == 'on':
lpm_enable = True
elif sys.argv[2] == 'off':
lpm_enable = False
else:
print "Unrecognized LPM parameter. Please use <on> or <off> values"
sys.exit(errno.EINVAL)
# Init SDK API
rc, handle = sx_api_open(None)
if (rc != SX_STATUS_SUCCESS):
print "Failed to open api handle.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
pid = os.getpid()
rc = sxd_access_reg_init(pid, None, 0)
if (rc != 0):
print "Failed to initializing register access.\nPlease check that SDK is running."
sys.exit(errno.EACCES);
# Get SFP module and log ports number and LPM status
sfp_module = int(sys.argv[1])
log_port_list = get_log_ports(handle, sfp_module)
if not log_port_list:
print "Failed to get log ports"
sys.exit(errno.EACCES)
# Get PMMP
pmmp = ku_pmmp_reg()
pmmp.module = sfp_module
meta = sxd_reg_meta_t()
meta.dev_id = 1
meta.swid = 0
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_pmmp(pmmp, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmmp failed, rc = %d" % rc
# Disable admin status before LPM settings
set_sfp_admin_status(handle, meta, sfp_module, log_port_list, SX_PORT_ADMIN_STATUS_DOWN)
# Set low power mode status
lpm_mask = 1 << 8
if lpm_enable:
pmmp.eeprom_override = pmmp.eeprom_override | lpm_mask
else:
pmmp.eeprom_override = pmmp.eeprom_override & (~lpm_mask)
meta.access_cmd = SXD_ACCESS_CMD_SET
rc = sxd_access_reg_pmmp(pmmp, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmmp failed, rc = %d" % rc
# Enable admin status after LPM settings
set_sfp_admin_status(handle, meta, sfp_module, log_port_list, SX_PORT_ADMIN_STATUS_UP)

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py

View File

@ -1,45 +0,0 @@
#!/usr/bin/env python
import sys, errno
import os
from python_sdk_api.sxd_api import *
from python_sdk_api.sx_api import *
# Check if SFP port number is provided
if len(sys.argv) < 2:
print "SFP module number or LPM is missed."
print "Usage: sfpreset.py <SFP module>"
sys.exit(errno.EINVAL)
# Init SDK API
rc, handle = sx_api_open(None)
if (rc != SX_STATUS_SUCCESS):
print "Failed to open api handle.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
pid = os.getpid()
rc = sxd_access_reg_init(pid, None, 0)
if (rc != 0):
print "Failed to initializing register access.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
# Get SFP module number
sfp_module = int(sys.argv[1])
# Get PMAOS
pmaos = ku_pmaos_reg()
pmaos.module = sfp_module
meta = sxd_reg_meta_t()
meta.dev_id = 1
meta.swid = 0
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
# Reset SFP
pmaos.rst = 1
meta.access_cmd = SXD_ACCESS_CMD_SET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
print "Reset flag is set"

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfpreset.py

View File

@ -1,201 +0,0 @@
# sfputil.py
#
# Platform-specific SFP transceiver interface for SONiC
#
try:
import time
import subprocess
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
# parameters for DB connection
REDIS_HOSTNAME = "localhost"
REDIS_PORT = 6379
REDIS_TIMEOUT_USECS = 0
# parameters for SFP presence
SFP_STATUS_INSERTED = '1'
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
PORT_START = 0
PORT_END = 55
PORTS_IN_BLOCK = 56
QSFP_PORT_START = 48
EEPROM_OFFSET = 1
_port_to_eeprom_mapping = {}
db_sel = None
db_sel_timeout = None
db_sel_object = None
db_sel_tbl = None
state_db = None
sfpd_status_tbl = None
@property
def port_start(self):
return self.PORT_START
@property
def port_end(self):
return self.PORT_END
@property
def qsfp_ports(self):
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
@property
def port_to_eeprom_mapping(self):
return self._port_to_eeprom_mapping
def __init__(self):
eeprom_path = "/sys/devices/platform/i2c_mlxcpld.1/i2c-1/i2c-2/2-0048/qsfp{0}"
for x in range(0, self.port_end + 1):
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
SfpUtilBase.__init__(self)
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
try:
reg_file = open("/bsp/qsfp/qsfp%d_status" % (port_num+1))
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
content = reg_file.readline().rstrip()
# content is a string with the qsfp status
if content == SFP_STATUS_INSERTED:
return True
return False
def get_low_power_mode(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmget.py {}".format(port_num)
try:
output = subprocess.check_output(lpm_cmd, shell=True)
if 'LPM ON' in output:
return True
except subprocess.CalledProcessError as e:
print "Error! Unable to get LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False
return False
def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
curr_lpmode = self.get_low_power_mode(port_num)
if curr_lpmode == lpmode:
return True
lpm = 'on' if lpmode else 'off'
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmset.py {} {}".format(port_num, lpm)
sfp_port_names = self.physical_to_logical[port_num]
# Get port admin status
try:
enabled_ports = subprocess.check_output("ip link show up", shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to get ports status, err msg: {}".format(e.output)
return False
port_to_disable = []
for port in sfp_port_names:
if port in enabled_ports:
port_to_disable.append(port)
# Disable ports before LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} down".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to DOWN for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False
time.sleep(3)
# Set LPM
try:
subprocess.check_output(lpm_cmd, shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False
# Enable ports after LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} up".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to UP for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False
return True
def reset(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfpreset.py {}".format(port_num)
try:
subprocess.check_output(lpm_cmd, shell=True)
return True
except subprocess.CalledProcessError as e:
print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False
return False
def get_transceiver_change_event(self, timeout=0):
phy_port_dict = {}
status = True
if self.db_sel == None:
from swsscommon import swsscommon
self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
REDIS_HOSTNAME,
REDIS_PORT,
REDIS_TIMEOUT_USECS)
# Subscribe to state table for SFP change notifications
self.db_sel = swsscommon.Select()
self.db_sel_tbl = swsscommon.NotificationConsumer(self.state_db, 'TRANSCEIVER_NOTIFY')
self.db_sel.addSelectable(self.db_sel_tbl)
self.db_sel_timeout = swsscommon.Select.TIMEOUT
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
keys = self.sfpd_status_tbl.getKeys()
if 'LIVENESS' not in keys:
return False, phy_port_dict
(state, c) = self.db_sel.select(timeout)
if state == self.db_sel_timeout:
status = True
elif state != self.db_sel_object:
status = False
else:
(key, op, fvp) = self.db_sel_tbl.pop()
phy_port_dict[key] = op
return status, phy_port_dict

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfputil.py

View File

@ -18,13 +18,20 @@ REDIS_TIMEOUT_USECS = 0
# parameters for SFP presence # parameters for SFP presence
SFP_STATUS_INSERTED = '1' SFP_STATUS_INSERTED = '1'
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, }
port_position_tuple_list = [(0, 0, 31, 32, 1), (0, 0, 15, 16, 1), (0, 48, 55, 56, 1),(0, 18, 21, 22, 1)]
class SfpUtil(SfpUtilBase): class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class""" """Platform-specific SfpUtil class"""
PORT_START = 0 PORT_START = 0
PORT_END = 31 QSFP_PORT_START = 0
PORTS_IN_BLOCK = 32 PORT_END = 0
PORTS_IN_BLOCK = 0
EEPROM_OFFSET = 1 EEPROM_OFFSET = 0
_port_to_eeprom_mapping = {} _port_to_eeprom_mapping = {}
@ -34,6 +41,7 @@ class SfpUtil(SfpUtilBase):
db_sel_tbl = None db_sel_tbl = None
state_db = None state_db = None
sfpd_status_tbl = None sfpd_status_tbl = None
qsfp_sysfs_path = "/sys/devices/platform/i2c_mlxcpld.1/i2c-1/i2c-2/2-0048/"
@property @property
def port_start(self): def port_start(self):
@ -45,17 +53,28 @@ class SfpUtil(SfpUtilBase):
@property @property
def qsfp_ports(self): def qsfp_ports(self):
return range(0, self.PORTS_IN_BLOCK + 1) return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
@property @property
def port_to_eeprom_mapping(self): def port_to_eeprom_mapping(self):
return self._port_to_eeprom_mapping return self._port_to_eeprom_mapping
def get_port_position_tuple_by_sku_name(self):
p = subprocess.Popen(GET_HWSKU_CMD, shell=True, stdout=subprocess.PIPE)
out, err = p.communicate()
position_tuple = port_position_tuple_list[hwsku_dict[out.rstrip('\n')]]
return position_tuple
def __init__(self): def __init__(self):
eeprom_path = "/sys/devices/platform/i2c_mlxcpld.1/i2c-1/i2c-2/2-0048/qsfp{0}" port_position_tuple = self.get_port_position_tuple_by_sku_name()
self.PORT_START = port_position_tuple[0]
self.QSFP_PORT_START = port_position_tuple[1]
self.PORT_END = port_position_tuple[2]
self.PORTS_IN_BLOCK = port_position_tuple[3]
self.EEPROM_OFFSET = port_position_tuple[4]
for x in range(0, self.port_end + 1): for x in range(0, self.port_end + 1):
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET) self._port_to_eeprom_mapping[x] = self.qsfp_sysfs_path + "qsfp{}".format(x + self.EEPROM_OFFSET)
SfpUtilBase.__init__(self) SfpUtilBase.__init__(self)
@ -65,7 +84,7 @@ class SfpUtil(SfpUtilBase):
return False return False
try: try:
reg_file = open("/bsp/qsfp/qsfp%d_status" % (port_num+1)) reg_file = open(self.qsfp_sysfs_path + "qsfp{}_status".format(port_num + 1))
except IOError as e: except IOError as e:
print "Error: unable to open file: %s" % str(e) print "Error: unable to open file: %s" % str(e)
return False return False

View File

@ -1,32 +0,0 @@
#!/usr/bin/env python
#############################################################################
# Mellanox
#
# Platform and model specific eeprom subclass, inherits from the base class,
# and provides the followings:
# - the eeprom format definition
# - specific encoder/decoder if there is special need
#############################################################################
try:
import exceptions
import binascii
import time
import optparse
import warnings
import os
import sys
from sonic_eeprom import eeprom_base
from sonic_eeprom import eeprom_tlvinfo
import subprocess
except ImportError, e:
raise ImportError (str(e) + "- required module not found")
class board(eeprom_tlvinfo.TlvInfoDecoder):
_TLV_INFO_MAX_LEN = 256
def __init__(self, name, path, cpld_root, ro):
self.eeprom_path = "/bsp/eeprom/vpd_info"
super(board, self).__init__(self.eeprom_path, 0, '', True)

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/eeprom.py

View File

@ -1,43 +0,0 @@
#!/usr/bin/env python
import sys, errno
import os
from python_sdk_api.sxd_api import *
from python_sdk_api.sx_api import *
# Check if SFP port number is provided
if len(sys.argv) < 2:
print "SFP module number is missed."
print "Usage: sfplpmget.py <SFP module>"
sys.exit(errno.EINVAL)
# Init SDK API
rc, handle = sx_api_open(None)
if (rc != SX_STATUS_SUCCESS):
print "Failed to open api handle.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
pid = os.getpid()
rc = sxd_access_reg_init(pid, None, 0)
if (rc != 0):
print "Failed to initializing register access.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
# Get SFP module number
sfp_module = int(sys.argv[1])
# Get MCION
mcion = ku_mcion_reg()
mcion.module = sfp_module
meta = sxd_reg_meta_t()
meta.dev_id = 1
meta.swid = 0
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_mcion(mcion, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_mcion failed, rc = %d" % rc
# Get low power mode status
lpm_mask = 1 << 8
lpm_status = (lpm_mask & mcion.module_status_bits) != 0
print "LPM ON" if lpm_status else "LPM OFF"

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfplpmget.py

View File

@ -1,107 +0,0 @@
#!/usr/bin/env python
import sys, errno
import time
import os
from python_sdk_api.sxd_api import *
from python_sdk_api.sx_api import *
def get_log_ports(handle, sfp_module):
port_attributes_list = new_sx_port_attributes_t_arr(64)
port_cnt_p = new_uint32_t_p()
uint32_t_p_assign(port_cnt_p, 64)
rc = sx_api_port_device_get(handle, 1 , 0, port_attributes_list, port_cnt_p)
assert rc == SX_STATUS_SUCCESS, "sx_api_port_device_get failed, rc = %d" % rc
port_cnt = uint32_t_p_value(port_cnt_p)
log_port_list = []
for i in range(0, port_cnt):
port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list, i)
if port_attributes.port_mapping.module_port == sfp_module:
log_port_list.append(port_attributes.log_port)
return log_port_list
def set_sfp_admin_status(handle, meta, sfp_module, sfp_log_port_list, admin_status):
# Get PMAOS
pmaos = ku_pmaos_reg()
pmaos.module = sfp_module
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
# Set admin status to PMAOS
pmaos.ase = 1
pmaos.ee = 1
pmaos.e = 2
pmaos.rst = 0
if admin_status == SX_PORT_ADMIN_STATUS_DOWN:
pmaos.admin_status = 2
else:
pmaos.admin_status = 1
meta.access_cmd = SXD_ACCESS_CMD_SET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
# Check if SFP port number is provided
if len(sys.argv) < 3:
print "SFP module number or LPM is missed."
print "Usage: sfplpmset.py <SFP module> <on|off>"
sys.exit(errno.EINVAL)
lpm_enable = None
if sys.argv[2] == 'on':
lpm_enable = True
elif sys.argv[2] == 'off':
lpm_enable = False
else:
print "Unrecognized LPM parameter. Please use <on> or <off> values"
sys.exit(errno.EINVAL)
# Init SDK API
rc, handle = sx_api_open(None)
if (rc != SX_STATUS_SUCCESS):
print "Failed to open api handle.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
pid = os.getpid()
rc = sxd_access_reg_init(pid, None, 0)
if (rc != 0):
print "Failed to initializing register access.\nPlease check that SDK is running."
sys.exit(errno.EACCES);
# Get SFP module and log ports number and LPM status
sfp_module = int(sys.argv[1])
log_port_list = get_log_ports(handle, sfp_module)
if not log_port_list:
print "Failed to get log ports"
sys.exit(errno.EACCES)
# Get PMMP
pmmp = ku_pmmp_reg()
pmmp.module = sfp_module
meta = sxd_reg_meta_t()
meta.dev_id = 1
meta.swid = 0
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_pmmp(pmmp, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmmp failed, rc = %d" % rc
# Disable admin status before LPM settings
set_sfp_admin_status(handle, meta, sfp_module, log_port_list, SX_PORT_ADMIN_STATUS_DOWN)
# Set low power mode status
lpm_mask = 1 << 8
if lpm_enable:
pmmp.eeprom_override = pmmp.eeprom_override | lpm_mask
else:
pmmp.eeprom_override = pmmp.eeprom_override & (~lpm_mask)
meta.access_cmd = SXD_ACCESS_CMD_SET
rc = sxd_access_reg_pmmp(pmmp, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmmp failed, rc = %d" % rc
# Enable admin status after LPM settings
set_sfp_admin_status(handle, meta, sfp_module, log_port_list, SX_PORT_ADMIN_STATUS_UP)

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfplpmset.py

View File

@ -1,45 +0,0 @@
#!/usr/bin/env python
import sys, errno
import os
from python_sdk_api.sxd_api import *
from python_sdk_api.sx_api import *
# Check if SFP port number is provided
if len(sys.argv) < 2:
print "SFP module number or LPM is missed."
print "Usage: sfpreset.py <SFP module>"
sys.exit(errno.EINVAL)
# Init SDK API
rc, handle = sx_api_open(None)
if (rc != SX_STATUS_SUCCESS):
print "Failed to open api handle.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
pid = os.getpid()
rc = sxd_access_reg_init(pid, None, 0)
if (rc != 0):
print "Failed to initializing register access.\nPlease check that SDK is running."
sys.exit(errno.EACCES)
# Get SFP module number
sfp_module = int(sys.argv[1])
# Get PMAOS
pmaos = ku_pmaos_reg()
pmaos.module = sfp_module
meta = sxd_reg_meta_t()
meta.dev_id = 1
meta.swid = 0
meta.access_cmd = SXD_ACCESS_CMD_GET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
# Reset SFP
pmaos.rst = 1
meta.access_cmd = SXD_ACCESS_CMD_SET
rc = sxd_access_reg_pmaos(pmaos, meta, 1, None, None)
assert rc == SXD_STATUS_SUCCESS, "sxd_access_reg_pmaos failed, rc = %d" % rc
print "Reset flag is set"

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfpreset.py

View File

@ -1,200 +0,0 @@
# sfputil.py
#
# Platform-specific SFP transceiver interface for SONiC
#
try:
import time
import subprocess
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
# parameters for DB connection
REDIS_HOSTNAME = "localhost"
REDIS_PORT = 6379
REDIS_TIMEOUT_USECS = 0
# parameters for SFP presence
SFP_STATUS_INSERTED = '1'
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
PORT_START = 0
PORT_END = 31
PORTS_IN_BLOCK = 32
EEPROM_OFFSET = 1
_port_to_eeprom_mapping = {}
db_sel = None
db_sel_timeout = None
db_sel_object = None
db_sel_tbl = None
state_db = None
sfpd_status_tbl = None
@property
def port_start(self):
return self.PORT_START
@property
def port_end(self):
return self.PORT_END
@property
def qsfp_ports(self):
return range(0, self.PORTS_IN_BLOCK + 1)
@property
def port_to_eeprom_mapping(self):
return self._port_to_eeprom_mapping
def __init__(self):
eeprom_path = "/sys/devices/platform/i2c_mlxcpld.1/i2c-1/i2c-2/2-0048/qsfp{0}"
for x in range(0, self.port_end + 1):
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
SfpUtilBase.__init__(self)
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
try:
reg_file = open("/bsp/qsfp/qsfp%d_status" % (port_num+1))
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
content = reg_file.readline().rstrip()
# content is a string with the qsfp status
if content == SFP_STATUS_INSERTED:
return True
return False
def get_low_power_mode(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmget.py {}".format(port_num)
try:
output = subprocess.check_output(lpm_cmd, shell=True)
if 'LPM ON' in output:
return True
except subprocess.CalledProcessError as e:
print "Error! Unable to get LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False
return False
def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
curr_lpmode = self.get_low_power_mode(port_num)
if curr_lpmode == lpmode:
return True
lpm = 'on' if lpmode else 'off'
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfplpmset.py {} {}".format(port_num, lpm)
sfp_port_names = self.physical_to_logical[port_num]
# Get port admin status
try:
enabled_ports = subprocess.check_output("ip link show up", shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to get ports status, err msg: {}".format(e.output)
return False
port_to_disable = []
for port in sfp_port_names:
if port in enabled_ports:
port_to_disable.append(port)
# Disable ports before LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} down".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to DOWN for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False
time.sleep(3)
# Set LPM
try:
subprocess.check_output(lpm_cmd, shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False
# Enable ports after LPM settings
for port in port_to_disable:
try:
subprocess.check_output("ifconfig {} up".format(port), shell=True)
except subprocess.CalledProcessError as e:
print "Error! Unable to set admin status to UP for {}, rc = {}, err msg: {}".format(port, e.returncode, e.output)
return False
return True
def reset(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
return False
lpm_cmd = "docker exec syncd python /usr/share/sonic/platform/plugins/sfpreset.py {}".format(port_num)
try:
subprocess.check_output(lpm_cmd, shell=True)
return True
except subprocess.CalledProcessError as e:
print "Error! Unable to set LPM for {}, rc = {}, err msg: {}".format(port_num, e.returncode, e.output)
return False
return False
def get_transceiver_change_event(self, timeout=0):
phy_port_dict = {}
status = True
if self.db_sel == None:
from swsscommon import swsscommon
self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
REDIS_HOSTNAME,
REDIS_PORT,
REDIS_TIMEOUT_USECS)
# Subscribe to state table for SFP change notifications
self.db_sel = swsscommon.Select()
self.db_sel_tbl = swsscommon.NotificationConsumer(self.state_db, 'TRANSCEIVER_NOTIFY')
self.db_sel.addSelectable(self.db_sel_tbl)
self.db_sel_timeout = swsscommon.Select.TIMEOUT
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
keys = self.sfpd_status_tbl.getKeys()
if 'LIVENESS' not in keys:
return False, phy_port_dict
(state, c) = self.db_sel.select(timeout)
if state == self.db_sel_timeout:
status = True
elif state != self.db_sel_object:
status = False
else:
(key, op, fvp) = self.db_sel_tbl.pop()
phy_port_dict[key] = op
return status, phy_port_dict

View File

@ -0,0 +1 @@
../../x86_64-mlnx_msn2700-r0/plugins/sfputil.py