2018-08-23 15:43:05 -05:00
|
|
|
try:
|
|
|
|
import time
|
|
|
|
import os
|
2019-04-18 04:30:50 -05:00
|
|
|
import select
|
2018-08-23 15:43:05 -05:00
|
|
|
from sonic_sfp.sfputilbase import SfpUtilBase
|
|
|
|
except ImportError as e:
|
|
|
|
raise ImportError("%s - required module not found" % str(e))
|
|
|
|
|
|
|
|
|
|
|
|
class SfpUtil(SfpUtilBase):
|
|
|
|
"""Platform-specific SfpUtil class"""
|
|
|
|
|
|
|
|
PORT_START = 1
|
2021-07-23 08:18:39 -05:00
|
|
|
PORT_END = 55
|
|
|
|
SFP_PORT_START = 49
|
|
|
|
SFP_PORT_END = 52
|
2018-08-23 15:43:05 -05:00
|
|
|
port_to_i2c_mapping = {
|
2018-08-29 10:50:29 -05:00
|
|
|
49: 15,
|
|
|
|
50: 14,
|
|
|
|
51: 17,
|
|
|
|
52: 16
|
2018-08-23 15:43:05 -05:00
|
|
|
}
|
|
|
|
_port_to_eeprom_mapping = {}
|
2021-07-23 08:18:39 -05:00
|
|
|
_sfp_port = list(range(SFP_PORT_START, SFP_PORT_END + 1))
|
2018-08-23 15:43:05 -05:00
|
|
|
|
|
|
|
@property
|
|
|
|
def port_start(self):
|
|
|
|
return self.PORT_START
|
|
|
|
|
|
|
|
@property
|
|
|
|
def port_end(self):
|
|
|
|
return self.PORT_END
|
|
|
|
|
|
|
|
@property
|
|
|
|
def qsfp_ports(self):
|
|
|
|
return []
|
|
|
|
|
|
|
|
@property
|
|
|
|
def port_to_eeprom_mapping(self):
|
|
|
|
return self._port_to_eeprom_mapping
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
# Override port_to_eeprom_mapping for class initialization
|
|
|
|
eeprom_path = '/sys/bus/i2c/devices/i2c-{0}/{0}-0050/eeprom'
|
|
|
|
for x in range(self.PORT_START, self.PORT_END + 1):
|
2021-07-23 08:18:39 -05:00
|
|
|
port_eeprom_path = eeprom_path.format(self.port_to_i2c_mapping[x]) if x in self._sfp_port else None
|
2018-08-23 15:43:05 -05:00
|
|
|
self.port_to_eeprom_mapping[x] = port_eeprom_path
|
|
|
|
SfpUtilBase.__init__(self)
|
|
|
|
|
|
|
|
def get_presence(self, port_num):
|
2018-08-29 10:50:29 -05:00
|
|
|
sfp_modabs_path = '/sys/devices/platform/e1031.smc/SFP/sfp_modabs'
|
2018-08-23 15:43:05 -05:00
|
|
|
|
|
|
|
if port_num not in self._sfp_port:
|
|
|
|
return False
|
2018-08-29 10:50:29 -05:00
|
|
|
|
2018-08-23 15:43:05 -05:00
|
|
|
status = 1
|
|
|
|
try:
|
2018-08-29 10:50:29 -05:00
|
|
|
with open(sfp_modabs_path, 'r') as port_status:
|
|
|
|
status = int(port_status.read(), 16)
|
2021-07-23 08:18:39 -05:00
|
|
|
status = (status >> (port_num - self.SFP_PORT_START)) & 1
|
2018-08-29 10:50:29 -05:00
|
|
|
except IOError:
|
2018-08-23 15:43:05 -05:00
|
|
|
return False
|
|
|
|
|
|
|
|
return status == 0
|
|
|
|
|
|
|
|
def get_low_power_mode(self, port_num):
|
2018-08-29 10:50:29 -05:00
|
|
|
raise NotImplementedError
|
2018-08-23 15:43:05 -05:00
|
|
|
|
|
|
|
def set_low_power_mode(self, port_num, lpmode):
|
2018-08-29 10:50:29 -05:00
|
|
|
raise NotImplementedError
|
2018-08-23 15:43:05 -05:00
|
|
|
|
|
|
|
def reset(self, port_num):
|
|
|
|
raise NotImplementedError
|
2018-08-29 10:50:29 -05:00
|
|
|
|
|
|
|
def get_transceiver_change_event(self, timeout=0):
|
2019-04-18 04:30:50 -05:00
|
|
|
epoll = select.epoll()
|
|
|
|
port_dict = {}
|
|
|
|
timeout_sec = timeout/1000
|
2018-08-29 10:50:29 -05:00
|
|
|
modabs_interrupt_path = '/sys/devices/platform/e1031.smc/SFP/modabs_int'
|
|
|
|
try:
|
2019-04-18 04:30:50 -05:00
|
|
|
# We get notified when there is an SCI interrupt from GPIO SUS7
|
|
|
|
fd = open("/sys/devices/platform/hlx-ich.0/sci_int_gpio_sus7", "r")
|
2020-11-25 12:28:36 -06:00
|
|
|
fd.read()
|
2019-04-18 04:30:50 -05:00
|
|
|
|
|
|
|
epoll.register(fd.fileno(), select.EPOLLIN & select.EPOLLET)
|
|
|
|
events = epoll.poll(timeout=timeout_sec if timeout != 0 else -1)
|
|
|
|
if events:
|
|
|
|
found_flag = 0
|
|
|
|
# Read the QSFP ABS interrupt & status registers
|
|
|
|
with open(modabs_interrupt_path, 'r') as port_changes:
|
|
|
|
changes = int(port_changes.read(), 16)
|
|
|
|
for port_num in self._sfp_port:
|
2020-11-25 12:28:36 -06:00
|
|
|
change = (changes >> (port_num - 49)) & 1
|
2019-04-18 04:30:50 -05:00
|
|
|
if change == 1:
|
2021-07-23 08:18:39 -05:00
|
|
|
port_dict[str(port_num)] = str(
|
|
|
|
int(self.get_presence(port_num)))
|
2019-04-18 04:30:50 -05:00
|
|
|
found_flag = 1
|
2020-11-25 12:28:36 -06:00
|
|
|
|
2019-04-18 04:30:50 -05:00
|
|
|
if not found_flag:
|
|
|
|
return False, {}
|
|
|
|
|
|
|
|
return True, port_dict
|
2020-11-25 12:28:36 -06:00
|
|
|
|
2019-04-18 04:30:50 -05:00
|
|
|
finally:
|
|
|
|
fd.close()
|
|
|
|
epoll.close()
|
|
|
|
|
2020-11-25 12:28:36 -06:00
|
|
|
return False, {}
|