Skip to content

[device] as4630-54pe: update sfputil for get_transceiver_change_event. #3315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 17, 2019
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
# name lanes alias index
Ethernet0 26 thousandE1 0
Ethernet1 25 thousandE2 1
Ethernet2 28 thousandE3 2
Ethernet3 27 thousandE4 3
Ethernet4 30 thousandE5 4
Ethernet5 29 thousandE6 5
Ethernet6 32 thousandE7 6
Ethernet7 31 thousandE8 7
Ethernet8 38 thousandE9 8
Ethernet9 37 thousandE10 9
Ethernet10 40 thousandE11 10
Ethernet11 39 thousandE12 11
Ethernet12 34 thousandE13 12
Ethernet13 33 thousandE14 13
Ethernet14 36 thousandE15 14
Ethernet15 35 thousandE16 15
Ethernet16 46 thousandE17 16
Ethernet17 45 thousandE18 17
Ethernet18 48 thousandE19 18
Ethernet19 47 thousandE20 19
Ethernet20 42 thousandE21 20
Ethernet21 41 thousandE22 21
Ethernet22 44 thousandE23 22
Ethernet23 43 thousandE24 23
Ethernet24 2 thousandE25 24
Ethernet25 1 thousandE26 25
Ethernet26 4 thousandE27 26
Ethernet27 3 thousandE28 27
Ethernet28 6 thousandE29 28
Ethernet29 5 thousandE30 29
Ethernet30 8 thousandE31 30
Ethernet31 7 thousandE32 31
Ethernet32 10 thousandE33 32
Ethernet33 9 thousandE34 33
Ethernet34 12 thousandE35 34
Ethernet35 11 thousandE36 35
Ethernet36 14 thousandE37 36
Ethernet37 13 thousandE38 37
Ethernet38 16 thousandE39 38
Ethernet39 15 thousandE40 39
Ethernet40 18 thousandE41 40
Ethernet41 17 thousandE42 41
Ethernet42 20 thousandE43 42
Ethernet43 19 thousandE44 43
Ethernet44 22 thousandE45 44
Ethernet45 21 thousandE46 45
Ethernet46 24 thousandE47 46
Ethernet47 23 thousandE48 47
Ethernet48 67 twentyfiveGigE49 48
Ethernet49 66 twentyfiveGigE50 49
Ethernet50 65 twentyfiveGigE51 50
Ethernet51 68 twentyfiveGigE52 51
Ethernet52 73,74,75,76 hundredGigE53 52
Ethernet56 69,70,71,72 hundredGigE54 56
# name lanes alias index speed
Ethernet0 26 thousandE1 1 1000
Ethernet1 25 thousandE2 2 1000
Ethernet2 28 thousandE3 3 1000
Ethernet3 27 thousandE4 4 1000
Ethernet4 30 thousandE5 5 1000
Ethernet5 29 thousandE6 6 1000
Ethernet6 32 thousandE7 7 1000
Ethernet7 31 thousandE8 8 1000
Ethernet8 38 thousandE9 9 1000
Ethernet9 37 thousandE10 10 1000
Ethernet10 40 thousandE11 11 1000
Ethernet11 39 thousandE12 12 1000
Ethernet12 34 thousandE13 13 1000
Ethernet13 33 thousandE14 14 1000
Ethernet14 36 thousandE15 15 1000
Ethernet15 35 thousandE16 16 1000
Ethernet16 46 thousandE17 17 1000
Ethernet17 45 thousandE18 18 1000
Ethernet18 48 thousandE19 19 1000
Ethernet19 47 thousandE20 20 1000
Ethernet20 42 thousandE21 21 1000
Ethernet21 41 thousandE22 22 1000
Ethernet22 44 thousandE23 23 1000
Ethernet23 43 thousandE24 24 1000
Ethernet24 2 thousandE25 25 1000
Ethernet25 1 thousandE26 26 1000
Ethernet26 4 thousandE27 27 1000
Ethernet27 3 thousandE28 28 1000
Ethernet28 6 thousandE29 29 1000
Ethernet29 5 thousandE30 30 1000
Ethernet30 8 thousandE31 31 1000
Ethernet31 7 thousandE32 32 1000
Ethernet32 10 thousandE33 33 1000
Ethernet33 9 thousandE34 34 1000
Ethernet34 12 thousandE35 35 1000
Ethernet35 11 thousandE36 36 1000
Ethernet36 14 thousandE37 37 1000
Ethernet37 13 thousandE38 38 1000
Ethernet38 16 thousandE39 39 1000
Ethernet39 15 thousandE40 40 1000
Ethernet40 18 thousandE41 41 1000
Ethernet41 17 thousandE42 42 1000
Ethernet42 20 thousandE43 43 1000
Ethernet43 19 thousandE44 44 1000
Ethernet44 22 thousandE45 45 1000
Ethernet45 21 thousandE46 46 1000
Ethernet46 24 thousandE47 47 1000
Ethernet47 23 thousandE48 48 1000
Ethernet48 67 twentyfiveGigE49 49 25000
Ethernet49 66 twentyfiveGigE50 50 25000
Ethernet50 65 twentyfiveGigE51 51 25000
Ethernet51 68 twentyfiveGigE52 52 25000
Ethernet52 73,74,75,76 hundredGigE53 53 100000
Ethernet56 69,70,71,72 hundredGigE54 54 100000
163 changes: 128 additions & 35 deletions device/accton/x86_64-accton_as4630_54pe-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,39 @@
#

try:
import sys
import time
import string
from ctypes import create_string_buffer
from sonic_sfp.sfputilbase import SfpUtilBase
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))

SFP_STATUS_INSERTED = '1'
SFP_STATUS_REMOVED = '0'

class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""


PORT_START = 48
PORT_END = 53
PORT_START = 49
PORT_END = 54
PORTS_IN_BLOCK = 54

QSFP_START = 53

BASE_OOM_PATH = "/sys/bus/i2c/devices/{0}-0050/"
BASE_CPLD_PATH = "/sys/bus/i2c/devices/3-0060/"

_port_to_is_present = {}
_port_to_lp_mode = {}

_port_to_eeprom_mapping = {}
_port_to_i2c_mapping = {
48: [18],
49: [19],
50: [20],
51: [21],
52: [22],
53: [23],
49: [18],
50: [19],
51: [20],
52: [21],
53: [22],
54: [23],
}

@property
Expand All @@ -41,7 +46,7 @@ def port_start(self):
@property
def port_end(self):
return self.PORT_END

@property
def qsfp_ports(self):
return range(self.PORT_START, self.PORTS_IN_BLOCK + 1)
Expand All @@ -52,28 +57,23 @@ def port_to_eeprom_mapping(self):

def __init__(self):
eeprom_path = self.BASE_OOM_PATH + "eeprom"

for x in range(0, self.port_end+1):
if x < 48:
self.port_to_eeprom_mapping[x] = eeprom_path.format(0)
else:
self.port_to_eeprom_mapping[x] = eeprom_path.format(
self._port_to_i2c_mapping[x][0])

for x in range(self.port_start, self.port_end+1):
self.port_to_eeprom_mapping[x] = eeprom_path.format(
self._port_to_i2c_mapping[x][0])
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
present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num+1)

present_path = self.BASE_CPLD_PATH + "module_present_" + str(port_num)
self.__port_to_is_present = present_path

try:
val_file = open(self.__port_to_is_present)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
print "Error: unable to open file: %s" % str(e)
return False

content = val_file.readline().rstrip()
Expand All @@ -84,20 +84,113 @@ def get_presence(self, port_num):
return True

return False

def get_low_power_mode(self, port_num):
raise NotImplementedError

def set_low_power_mode(self, port_num, lpmode):
raise NotImplementedError
def get_low_power_mode(self, port_num):
# Check for invalid port_num
if port_num < self.QSFP_START or port_num > self.port_end:
return False

try:
eeprom = None
if not self.get_presence(port_num):
return False
eeprom = open(self.port_to_eeprom_mapping[port_num], "rb")
eeprom.seek(93)
lpmode = ord(eeprom.read(1))

# if "Power override" bit is 1 and "Power set" bit is 1
if ((lpmode & 0x3) == 0x3):
return True

# High Power Mode if one of the following conditions is matched:
# 1. "Power override" bit is 0
# 2. "Power override" bit is 1 and "Power set" bit is 0
else:
return False

except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)

def set_low_power_mode(self, port_num, lpmode):
# Check for invalid port_num
if port_num < self.QSFP_START or port_num > self.port_end:
return False

try:
eeprom = None
if not self.get_presence(port_num):
return False # Port is not present, unable to set the eeprom

# Fill in write buffer
# 0x3:Low Power Mode, 0x1:High Power Mode
regval = 0x3 if lpmode else 0x1

buffer = create_string_buffer(1)
buffer[0] = chr(regval)

# Write to eeprom
eeprom = open(self.port_to_eeprom_mapping[port_num], "r+b")
eeprom.seek(93)
eeprom.write(buffer[0])
return True
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
finally:
if eeprom is not None:
eeprom.close()
time.sleep(0.01)

def reset(self, port_num):
raise NotImplementedError

def get_transceiver_change_event(self):
"""
TODO: This function need to be implemented
when decide to support monitoring SFP(Xcvrd)
on this platform.
"""
raise NotImplementedError
@property
def _get_presence_bitmap(self):

bits = []
for x in range(self.port_start, self.port_end+1):
bits.append(str(int(self.get_presence(x))))

rev = "".join(bits[::-1])
return int(rev,2)

data = {'present':0}
def get_transceiver_change_event(self, timeout=0):
port_dict = {}

if timeout == 0:
cd_ms = sys.maxint
else:
cd_ms = timeout

#poll per second
while cd_ms > 0:
reg_value = self._get_presence_bitmap
changed_ports = self.data['present'] ^ reg_value
if changed_ports != 0:
break
time.sleep(1)
cd_ms = cd_ms - 1000

if changed_ports != 0:
for port in range (self.port_start, self.port_end+1):
# Mask off the bit corresponding to our port
mask = (1 << (port - self.port_start))
if changed_ports & mask:
if (reg_value & mask) == 0:
port_dict[port] = SFP_STATUS_REMOVED
else:
port_dict[port] = SFP_STATUS_INSERTED

# Update cache
self.data['present'] = reg_value
return True, port_dict
else:
return True, {}
return False, {}

Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ def get_fan_to_device_path(self, fan_num, node_num):
def get_fan_fault(self, fan_num):
return self._get_fan_node_val(fan_num, self.FAN_NODE_FAULT_IDX_OF_MAP)

#def get_fan_speed(self, fan_num):
# return self._get_fan_node_val(fan_num, self.FAN_NODE_SPEED_IDX_OF_MAP)

def get_fan_dir(self, fan_num):
return self._get_fan_node_val(fan_num, self.FAN_NODE_DIR_IDX_OF_MAP)
Expand All @@ -196,17 +194,9 @@ def get_fan_duty_cycle(self):

content = val_file.readline().rstrip()
val_file.close()

return int(content)
#self._get_fan_node_val(fan_num, self.FAN_NODE_DUTY_IDX_OF_MAP)
#static u32 reg_val_to_duty_cycle(u8 reg_val)
#{
# reg_val &= FAN_DUTY_CYCLE_REG_MASK;
# return ((u32)(reg_val+1) * 625 + 75)/ 100;
#}
#

def set_fan_duty_cycle(self, val):

try:
fan_file = open(self.FAN_DUTY_PATH, 'r+')
except IOError as e:
Expand All @@ -217,9 +207,6 @@ def set_fan_duty_cycle(self, val):
fan_file.close()
return True

#def get_fanr_fault(self, fan_num):
# return self._get_fan_node_val(fan_num, self.FANR_NODE_FAULT_IDX_OF_MAP)

def get_fanr_speed(self, fan_num):
return self._get_fan_node_val(fan_num, self.FANR_NODE_SPEED_IDX_OF_MAP)

Expand All @@ -232,20 +219,5 @@ def get_fan_status(self, fan_num):
logging.debug('GET. FAN fault. fan_num, %d', fan_num)
return False

#if self.get_fanr_fault(fan_num) is not None and self.get_fanr_fault(fan_num) > 0:
# logging.debug('GET. FANR fault. fan_num, %d', fan_num)
# return False

return True

#def main():
# fan = FanUtil()
#
# print 'get_size_node_map : %d' % fan.get_size_node_map()
# print 'get_size_path_map : %d' % fan.get_size_path_map()
# for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1):
# for y in range(fan.get_idx_node_start(), fan.get_num_nodes()+1):
# print fan.get_fan_to_device_path(x, y)
#
#if __name__ == '__main__':
# main()
Loading