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

Signed-off-by: roy_lee <roy_lee@accton.com>
This commit is contained in:
Roy Lee 2019-10-17 09:01:38 +08:00 committed by Joe LeVeque
parent ee4ca2c0c5
commit 4d8a01c26c
6 changed files with 200 additions and 192 deletions

View File

@ -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

View File

@ -4,19 +4,24 @@
#
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/"
@ -26,12 +31,12 @@ class SfpUtil(SfpUtilBase):
_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
@ -52,14 +57,9 @@ class SfpUtil(SfpUtilBase):
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:
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):
@ -67,7 +67,7 @@ class SfpUtil(SfpUtilBase):
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:
@ -86,18 +86,111 @@ class SfpUtil(SfpUtilBase):
return False
def get_low_power_mode(self, port_num):
raise NotImplementedError
# 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):
raise NotImplementedError
# 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, {}

View File

@ -180,8 +180,6 @@ class FanUtil(object):
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)
@ -196,17 +194,9 @@ class FanUtil(object):
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):
def set_fan_duty_cycle(self, val):
try:
fan_file = open(self.FAN_DUTY_PATH, 'r+')
except IOError as e:
@ -217,9 +207,6 @@ class FanUtil(object):
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)
@ -232,20 +219,5 @@ class FanUtil(object):
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()

View File

@ -45,7 +45,6 @@ class ThermalUtil(object):
""" Dictionary where
key1 = thermal id index (integer) starting from 1
value = path to fan device file (string) """
#_thermal_to_device_path_mapping = {}
_thermal_to_device_node_mapping = {
THERMAL_NUM_1_IDX: ['55', '48'],
@ -121,11 +120,6 @@ def main():
print "termal3=%d" %thermal._get_thermal_val(3)
print "termal4=%d" %thermal._get_thermal_val(4)
print "termal5=%d" %thermal._get_thermal_val(5)
#
# print 'get_size_node_map : %d' % thermal.get_size_node_map()
# print 'get_size_path_map : %d' % thermal.get_size_path_map()
# for x in range(thermal.get_idx_thermal_start(), thermal.get_num_thermals()+1):
# print thermal.get_thermal_to_device_path(x)
#
if __name__ == '__main__':
main()

View File

@ -9,7 +9,6 @@ ExecStartPre=/usr/local/bin/accton_as4630_54pe_util.py install
ExecStart=/usr/local/bin/accton_as4630_54pe_monitor.py
KillSignal=SIGKILL
SuccessExitStatus=SIGKILL
#StandardOutput=tty
# Resource Limitations
LimitCORE=infinity

View File

@ -1,4 +1,4 @@
Copyright (C) 2016 Accton Networks, Inc.
Copyright (C) 2019 Accton Networks, Inc.
This program is free software: you can redistribute it and/or modify
It under the terms of the GNU General Public License as published by
@ -13,79 +13,29 @@ See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Contents of this package:
patch - files under patch/ is for kernel and ONIE installer
for the kernel:
config-accton-as5712_54x.patch
for kernel configuration.
driver-i2c-muxes-pca954x-always-deselect.patch
for i2c_mux deselects after transaction.
driver-patches-for-accton-as5712-fan-psu-cpld.patch
for as5712's fan/psu/cpld/led/sfp drivers.
for ONIE:
onie_installer-accton-AS5712-54X.patch
for console port setting and copy util script o rootfs.
module - Contains source code of as5712 kernel driver modules.
The late Sonic building scripts, pushed @Dec 5 2016, will automatically
create a docker container and run building process under it.
User is not necessary to handle docker environment creation.
1. Download sonic-buildimage environment.
- Run "git clone https://github.com/Azure/sonic-buildimage".
- cd to sonic-buildimage and run "git submodule update --init --recursive".
2. Build kernel
- cd ./src/sonic-linux-kernel
- Copy patches and series from patch/kernel of this release to
sonic-linux-kernel/patch.
- Build kernel by "make".
- The built kernel package, linux-image-3.16.0-5-amd64_3.16.51-3+deb8u1_amd64.deb
, is generated.
3. Build installer
- Change directory back to sonic-buildimage/.
- Get onie_installer-accton-AS5712-54X.patch" from patch/installer.
- Change setting for AS5712-54X by patching build_image.sh.
"patch -p1 < onie_installer-accton-AS5712-54X.patch"
!!NOTICE, patching onie_installer-accton-AS5712-54X.patch comments out the
"git status" checking at build_image.sh.
- The account and password of installed OS can be given at rules/config.
The default user and password are "admin" & "YourPaSsWoRd" respectively.
- Run "make configure PLATFORM=broadcom"
- Copy the built kernel debian package to target/debs/.
The file is linux-image-3.16.0-5-amd64_*_amd64.deb under directory
src/sonic-linux-kernel/.
- Run "make target/sonic-generic.bin"
- Get the installer, target/sonic-generic.bin, to target machine and install.
All Linux kernel code is licensed under the GPLv1. All other code is
licensed under the GPLv3. Please see the LICENSE file for copies of
both licenses.
The code for integacting with Accton AS5712-54X has 2 parts,
The code for integacting with Accton AS4630-54pe has 2 parts,
kernel drivers and operational script.
The kernel drivers of peripherals are under module/ directory.
1. These drivers are patched into kernel by
driver-patches-for-accton-as5712-fan-psu-cpld.patch
Or you can build the driver under module/ by setting environment variable,
KERNEL_SRC, to proper linux built directory and run make.
It may be sonic-linux-kernel/linux-3.*/debian/build/build_amd64_none_amd64/.
2. A operational script, accton_as5712_util.py, for device initializatian and
1. These drivers are at module dir.
2. A operational script, accton_as4630_util.py, for device initializatian and
peripheral accessing should be installed at /usr/bin.
This script is generated by onie_installer-accton-AS5712-54X.patch.
It's done by patching onie_installer-accton-AS5712-54X.patch at build-image.
Run "accton_as5712_util.py install" to install drivers.
Run "accton_as4630_util.py install" to install drivers.
To initialize the system, run "accton_as5712_util.py install".
To clean up the drivers & devices, run "accton_as5712_util.py clean".
To dump information of sensors, run "accton_as5712_util.py show".
To dump SFP EEPROM, run "accton_as5712_util.py sff".
To set fan speed, run "accton_as5712_util.py set fan".
To enable/disable SFP emission, run "accton_as5712_util.py set sfp".
To set system LEDs' color, run "accton_as5712_util.py set led"
For more information, run "accton_as5712_util.py --help".
To initialize the system, run "accton_as4630_util.py install".
To clean up the drivers & devices, run "accton_as4630_util.py clean".
To dump information of sensors, run "accton_as4630_util.py show".
To dump SFP EEPROM, run "accton_as4630_util.py sff".
To set fan speed, run "accton_as4630_util.py set fan".
To enable/disable SFP emission, run "accton_as4630_util.py set sfp".
To set system LEDs' color, run "accton_as4630_util.py set led"
For more information, run "accton_as4630_util.py --help".
====================================================================
Besides applying accton_as5712_util.py to access peripherals, you can
Besides applying accton_as4630_util.py to access peripherals, you can
access peripherals by sysfs nodes directly after the installation is run.
System LED: