[device/accton] AS****_54X, validate accton util to set sfp's tx_disable (#5941)

bug fix: #5914

Validated for tx_disable function of SFP+ on AS7312-54X, AS5812-54X, AS5712-54x, and AS5812-54x.

Signed-off-by: roy_lee <roy_lee@edge-core.com>
This commit is contained in:
Roy Lee 2020-12-18 14:35:59 +08:00 committed by GitHub
parent aa38022ca6
commit 54681f169f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 693 additions and 751 deletions

View File

@ -80,7 +80,6 @@ i2c_nodes = {
'sfp': ['sfp_is_present ', 'sfp_tx_disable']}
QSFP_START = 48
I2C_BUS_ORDER = -1
sfp_map = [2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
@ -241,13 +240,12 @@ def log_os_system(cmd, show):
return status, output
def driver_inserted():
ret, lsmod = log_os_system("lsmod| grep accton", 0)
ret, lsmod = log_os_system("ls /sys/module/ | grep accton", 0)
logging.info('mods:'+lsmod)
if len(lsmod) ==0:
if not lsmod:
return False
kos = [
'depmod -ae',
'modprobe i2c_dev',
@ -263,10 +261,10 @@ kos = [
def driver_install():
global FORCE
for i in range(0,len(kos)):
status, output = log_os_system(kos[i], 1)
if status:
ret = log_os_system(kos[i], 1)
if ret[0]:
if FORCE == 0:
return status
return ret[0]
return 0
def driver_uninstall():
@ -282,10 +280,10 @@ def driver_uninstall():
#Change to removing commands
rm = rm.replace("modprobe", "modprobe -rq")
rm = rm.replace("insmod", "rmmod")
status, output = log_os_system(rm, 1)
if status:
ret = log_os_system(rm, 1)
if ret[0]:
if FORCE == 0:
return status
return ret[0]
return 0
@ -293,34 +291,23 @@ def driver_uninstall():
def i2c_order_check():
# i2c bus 0 and 1 might be installed in different order.
# Here check if 0x70 is exist @ i2c-0
tmp = "echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device"
log_os_system(tmp, 0)
if not device_exist():
tmp = "i2cget -y -f 0 0x70"
ret = log_os_system(tmp, 0)
if not ret[0]:
order = 1
else:
order = 0
tmp = "echo 0x70 > /sys/bus/i2c/devices/i2c-1/delete_device"
log_os_system(tmp, 0)
m = "[%s]Detected I2C_BUS_ORDER:%d" % (os.path.basename(__file__), order)
my_log(m)
return order
def update_i2c_order():
global I2C_BUS_ORDER
order = i2c_order_check()
I2C_BUS_ORDER = order
print "[%s]Detected I2C_BUS_ORDER:%d" % (os.path.basename(__file__), I2C_BUS_ORDER)
def get_i2c_order():
global I2C_BUS_ORDER
if I2C_BUS_ORDER < 0:
update_i2c_order()
return i2c_order_check()
def device_install():
global FORCE
global I2C_BUS_ORDER
update_i2c_order()
order = I2C_BUS_ORDER
order = get_i2c_order()
# if 0x76 is not exist @i2c-0, use reversed bus order
if order:
for i in range(0,len(mknod2)):
@ -372,8 +359,8 @@ def device_uninstall():
print output
if FORCE == 0:
return status
status, output = log_os_system("ls /sys/bus/i2c/devices/1-0070", 0)
order = 0 if (status == 0) else 1
order = get_i2c_order()
if order == 0:
nodelist = mknod
else:
@ -526,12 +513,8 @@ def show_eeprom(index):
def get_cpld_path(index):
global I2C_BUS_ORDER
if I2C_BUS_ORDER < 0:
get_i2c_order()
if I2C_BUS_ORDER !=0 :
order = get_i2c_order()
if order !=0 :
return port_cpld_path[index].replace("0-", "1-")
else:
return port_cpld_path[index]
@ -579,9 +562,9 @@ def set_device(args):
#print ALL_DEVICE['led']
for i in range(0,len(ALL_DEVICE['led'])):
for k in (ALL_DEVICE['led']['led'+str(i+1)]):
ret, log = log_os_system("echo "+args[1]+" >"+k, 1)
if ret:
return ret
ret[0] = log_os_system("echo "+args[1]+" >"+k, 1)
if ret[0]:
return ret[0]
elif args[0]=='fan':
if int(args[1])>100:
show_set_help()
@ -616,8 +599,8 @@ def set_device(args):
if ret == False:
return False
else:
ret, log = log_os_system("echo "+args[2]+" >"+ dev, 1)
return ret
ret = log_os_system("echo "+args[2]+" >"+ dev, 1)
return ret[0]
return
#get digits inside a string.
@ -679,9 +662,9 @@ def device_traversal():
return
def device_exist():
ret1, log = log_os_system("ls "+i2c_prefix+"*0070", 0)
ret2, log = log_os_system("ls "+i2c_prefix+"i2c-2", 0)
return not(ret1 or ret2)
ret1 = log_os_system("ls "+i2c_prefix+"*0070", 0)
ret2 = log_os_system("ls "+i2c_prefix+"i2c-2", 0)
return not(ret1[0] or ret2[0])
if __name__ == "__main__":
main()

View File

@ -80,7 +80,6 @@ i2c_nodes = {
'sfp': ['sfp_is_present ', 'sfp_tx_disable']}
QSFP_START = 48
I2C_BUS_ORDER = -1
sfp_map = [2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
@ -241,7 +240,7 @@ def log_os_system(cmd, show):
return status, output
def driver_inserted():
ret, lsmod = log_os_system("lsmod| grep accton", 0)
ret, lsmod = log_os_system("ls /sys/module | grep accton", 0)
logging.info('mods:'+lsmod)
if len(lsmod) ==0:
return False
@ -293,34 +292,23 @@ def driver_uninstall():
def i2c_order_check():
# i2c bus 0 and 1 might be installed in different order.
# Here check if 0x70 is exist @ i2c-0
tmp = "echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device"
log_os_system(tmp, 0)
if not device_exist():
tmp = "i2cget -y -f 0 0x70"
ret = log_os_system(tmp, 0)
if not ret[0]:
order = 1
else:
order = 0
tmp = "echo 0x70 > /sys/bus/i2c/devices/i2c-1/delete_device"
log_os_system(tmp, 0)
m = "[%s]Detected I2C_BUS_ORDER:%d" % (os.path.basename(__file__), order)
my_log(m)
return order
def update_i2c_order():
global I2C_BUS_ORDER
order = i2c_order_check()
I2C_BUS_ORDER = order
print "[%s]Detected I2C_BUS_ORDER:%d" % (os.path.basename(__file__), I2C_BUS_ORDER)
def get_i2c_order():
global I2C_BUS_ORDER
if I2C_BUS_ORDER < 0:
update_i2c_order()
return i2c_order_check()
def device_install():
global FORCE
global I2C_BUS_ORDER
update_i2c_order()
order = I2C_BUS_ORDER
order = get_i2c_order()
# if 0x76 is not exist @i2c-0, use reversed bus order
if order:
for i in range(0,len(mknod2)):
@ -372,8 +360,8 @@ def device_uninstall():
print output
if FORCE == 0:
return status
status, output = log_os_system("ls /sys/bus/i2c/devices/1-0070", 0)
order = 0 if (status == 0) else 1
order = get_i2c_order()
if order == 0:
nodelist = mknod
else:
@ -526,12 +514,8 @@ def show_eeprom(index):
def get_cpld_path(index):
global I2C_BUS_ORDER
if I2C_BUS_ORDER < 0:
get_i2c_order()
if I2C_BUS_ORDER !=0 :
order = get_i2c_order()
if order !=0 :
return port_cpld_path[index].replace("0-", "1-")
else:
return port_cpld_path[index]

View File

@ -120,7 +120,7 @@ def show_set_help():
print cmd +" [led|sfp|fan]"
print " use \""+ cmd + " led 0-4 \" to set led color"
print " use \""+ cmd + " fan 0-100\" to set fan duty percetage"
print " use \""+ cmd + " sfp 1-54 {0|1}\" to set sfp# tx_disable"
print " use \""+ cmd + " sfp 1-48 {0|1}\" to set sfp# tx_disable"
sys.exit(0)
def show_eeprom_help():
@ -145,7 +145,7 @@ def log_os_system(cmd, show):
return status, output
def driver_check():
ret, lsmod = log_os_system("lsmod| grep accton", 0)
ret, lsmod = log_os_system("ls /sys/module/ | grep accton", 0)
logging.info('mods:'+lsmod)
if len(lsmod) ==0:
return False
@ -165,12 +165,12 @@ kos = [
def driver_install():
global FORCE
status, output = log_os_system("depmod", 1)
log_os_system("depmod", 1)
for i in range(0,len(kos)):
status, output = log_os_system(kos[i], 1)
if status:
ret = log_os_system(kos[i], 1)
if ret[0]:
if FORCE == 0:
return status
return ret[0]
return 0
def driver_uninstall():
@ -182,13 +182,13 @@ def driver_uninstall():
if len(lst) > 3:
del(lst[3])
rm = " ".join(lst)
status, output = log_os_system(rm, 1)
if status:
ret = log_os_system(rm, 1)
if ret[0]:
if FORCE == 0:
return status
return ret[0]
return 0
led_prefix ='/sys/class/leds/accton_'+PROJECT_NAME+'_led::'
led_prefix ='/sys/class/leds/'+PROJECT_NAME+'_led::'
hwmon_types = {'led': ['diag','fan','loc','psu1','psu2']}
hwmon_nodes = {'led': ['brightness'] }
hwmon_prefix ={'led': led_prefix}
@ -274,14 +274,12 @@ mknod2 =[
def i2c_order_check():
# i2c bus 0 and 1 might be installed in different order.
# Here check if 0x77 is exist @ i2c-1
tmp = "echo pca9548 0x77 > /sys/bus/i2c/devices/i2c-1/new_device"
status, output = log_os_system(tmp, 0)
if not device_exist():
tmp = "i2cget -y -f 0 0x77"
ret = log_os_system(tmp, 0)
if not ret[0]:
order = 1
else:
order = 0
tmp = "echo 0x77 > /sys/bus/i2c/devices/i2c-1/delete_device"
status, output = log_os_system(tmp, 0)
return order
def device_install():
@ -331,12 +329,6 @@ def device_install():
def device_uninstall():
global FORCE
status, output =log_os_system("ls /sys/bus/i2c/devices/0-0077", 0)
if status==0:
I2C_ORDER=1
else:
I2C_ORDER=0
for i in range(0,len(sfp_map)):
target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device"
status, output =log_os_system("echo 0x50 > "+ target, 1)
@ -345,10 +337,11 @@ def device_uninstall():
if FORCE == 0:
return status
if I2C_ORDER==0:
nodelist = mknod
else:
order = i2c_order_check()
if order:
nodelist = mknod2
else:
nodelist = mknod
for i in range(len(nodelist)):
target = nodelist[-(i+1)]
@ -479,9 +472,9 @@ def show_eeprom(index):
# check if got hexdump command in current environment
ret, log = log_os_system("which hexdump", 0)
ret, log2 = log_os_system("which busybox hexdump", 0)
if len(log):
if log :
hex_cmd = 'hexdump'
elif len(log2):
elif log2 :
hex_cmd = ' busybox hexdump'
else:
log = 'Failed : no hexdump cmd!!'
@ -515,9 +508,9 @@ def set_device(args):
#print ALL_DEVICE['led']
for i in range(0,len(ALL_DEVICE['led'])):
for k in (ALL_DEVICE['led']['led'+str(i+1)]):
ret, log = log_os_system("echo "+args[1]+" >"+k, 1)
if ret:
return ret
ret = log_os_system("echo "+args[1]+" >"+k, 1)
if ret[0]:
return ret[0]
elif args[0]=='fan':
if int(args[1])>100:
show_set_help()
@ -526,15 +519,15 @@ def set_device(args):
#fan1~5 is all fine, all fan share same setting
node = ALL_DEVICE['fan'] ['fan1'][0]
node = node.replace(node.split("/")[-1], 'fan_duty_cycle_percentage')
ret, log = log_os_system("cat "+ node, 1)
if ret==0:
ret = log_os_system("cat "+ node, 1)
if ret[0] == 0:
print ("Previous fan duty: " + log.strip() +"%")
ret, log = log_os_system("echo "+args[1]+" >"+node, 1)
if ret==0:
ret = log_os_system("echo "+args[1]+" >"+node, 1)
if ret[0] == 0:
print ("Current fan duty: " + args[1] +"%")
return ret
return ret[0]
elif args[0]=='sfp':
if int(args[1])> DEVICE_NO[args[0]] or int(args[1])==0:
if int(args[1])> qsfp_start or int(args[1])==0:
show_set_help()
return
if len(args)<2:
@ -549,9 +542,9 @@ def set_device(args):
for i in range(0,len(ALL_DEVICE[args[0]])):
for j in ALL_DEVICE[args[0]][args[0]+str(args[1])]:
if j.find('tx_disable')!= -1:
ret, log = log_os_system("echo "+args[2]+" >"+ j, 1)
if ret:
return ret
ret = log_os_system("echo "+args[2]+" >"+ j, 1)
if ret[0]:
return ret[0]
return
@ -593,9 +586,9 @@ def device_traversal():
return
def device_exist():
ret1, log = log_os_system("ls "+i2c_prefix+"*0077", 0)
ret2, log = log_os_system("ls "+i2c_prefix+"i2c-2", 0)
return not(ret1 or ret2)
ret1 = log_os_system("ls "+i2c_prefix+"*0077", 0)
ret2 = log_os_system("ls "+i2c_prefix+"i2c-2", 0)
return not(ret1[0] or ret2[0])
if __name__ == "__main__":
main()

View File

@ -100,27 +100,18 @@ class FanUtil(object):
return None
device_path = self.get_fan_to_device_path(fan_num, node_num)
try:
val_file = open(device_path, 'r')
except IOError as e:
logging.error('GET. unable to open file: %s', str(e))
return None
with open(device_path, 'r') as val_file:
content = val_file.readline().rstrip()
if content == '':
logging.debug('GET. content is NULL. device_path:%s', device_path)
if not content:
logging.debug('GET. content is NULL, path:%s', device_path)
return None
try:
val_file.close()
except:
logging.debug('GET. unable to close file. device_path:%s', device_path)
return None
except IOError as e:
logging.error('GET. unable to read file: %s', str(e))
else:
return int(content)
def _set_fan_node_val(self, fan_num, node_num, val):
if fan_num < self.FAN_NUM_1_IDX or fan_num > self.FAN_NUM_ON_MAIN_BROAD:
logging.debug('GET. Parameter error. fan_num:%d', fan_num)
@ -137,19 +128,11 @@ class FanUtil(object):
device_path = self.get_fan_to_device_path(fan_num, node_num)
try:
val_file = open(device_path, 'w')
with open(device_path, 'w') as val_file:
val_file.write(content)
except IOError as e:
logging.error('GET. unable to open file: %s', str(e))
return None
val_file.write(content)
try:
val_file.close()
except:
logging.debug('GET. unable to close file. device_path:%s', device_path)
return None
return True
def __init__(self):
@ -193,32 +176,20 @@ class FanUtil(object):
def get_fan_duty_cycle(self):
#duty_path = self.FAN_DUTY_PATH
try:
val_file = open(self.FAN_DUTY_PATH)
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
with open(self.FAN_DUTY_PATH) as val_file:
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:
print "Error: unable to open file: %s" % str(e)
return False
#val = ((val + 1 ) * 625 +75 ) / 100
fan_file.write(str(val))
fan_file.close()
return int(content)
def set_fan_duty_cycle(self, val):
try:
with open(self.FAN_DUTY_PATH, 'r+') as val_file:
val_file.write(str(val))
except IOError as e:
print "Error: unable to open file: %s" % str(e)
return False
return True
#def get_fanr_fault(self, fan_num):

View File

@ -69,26 +69,19 @@ class ThermalUtil(object):
device_path = self.get_thermal_to_device_path(thermal_num)
for filename in glob.glob(device_path):
try:
with open(filename, 'r') as val_file:
val_file = open(filename, 'r')
content = val_file.readline().rstrip()
if not content :
logging.debug('File is NULL. path:%s', device_path)
return None
else:
return int(content)
except IOError as e:
logging.error('GET. unable to open file: %s', str(e))
return None
content = val_file.readline().rstrip()
if content == '':
logging.debug('GET. content is NULL. device_path:%s', device_path)
return None
try:
val_file.close()
except:
logging.debug('GET. unable to close file. device_path:%s', device_path)
return None
return int(content)
def get_num_thermals(self):
return self.THERMAL_NUM_ON_MAIN_BROAD

View File

@ -72,6 +72,7 @@ class accton_as7312_monitor(object):
_new_perc = 0
_ori_perc = 0
def __init__(self, log_file, log_level):
"""Needs a logger and a logger level."""
# set up logging to file
@ -93,6 +94,9 @@ class accton_as7312_monitor(object):
logging.debug('SET. logfile:%s / loglevel:%d', log_file, log_level)
self.thermal = ThermalUtil()
self.fan = FanUtil()
def manage_fans(self):
max_duty = DUTY_MAX
fan_policy_f2b = {
@ -113,8 +117,8 @@ class accton_as7312_monitor(object):
2: 50000,
}
thermal = ThermalUtil()
fan = FanUtil()
thermal = self.thermal
fan = self.fan
for x in range(fan.get_idx_fan_start(), fan.get_num_fans()+1):
fan_status = fan.get_fan_status(x)
if fan_status is None:

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python
#
# Copyright (C) 2016 Accton Networks, Inc.
#
# This program is free software: you can redistribute it and/or modify
@ -38,20 +37,24 @@ import re
import time
PROJECT_NAME = 'as7312_54x'
version = '0.1.0'
verbose = False
DEBUG = False
args = []
ARGS = []
ALL_DEVICE = {}
DEVICE_NO = {'led':5, 'fan':6,'thermal':4, 'psu':2, 'sfp':54}
DEVICE_NO = {
'led': 5,
'fan': 6,
'thermal': 4,
'psu': 2,
'sfp': 54,
}
FORCE = 0
# logging.basicConfig(filename= PROJECT_NAME+'.log', filemode='w',level=logging.DEBUG)
# logging.basicConfig(level=logging.INFO)
if DEBUG == True:
print sys.argv[0]
print 'ARGV :', sys.argv[1:]
@ -59,22 +62,20 @@ if DEBUG == True:
def main():
global DEBUG
global args
global ARGS
global FORCE
if len(sys.argv) < 2:
show_help()
options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help',
'debug',
'force',
])
(options, ARGS) = getopt.getopt(sys.argv[1:], 'hdf',
['help','debug', 'force'])
if DEBUG == True:
print options
print args
print ARGS
print len(sys.argv)
for opt, arg in options:
for (opt, arg) in options:
if opt in ('-h', '--help'):
show_help()
elif opt in ('-d', '--debug'):
@ -84,7 +85,7 @@ def main():
FORCE = 1
else:
logging.info('no option')
for arg in args:
for arg in ARGS:
if arg == 'install':
do_install()
elif arg == 'clean':
@ -92,67 +93,70 @@ def main():
elif arg == 'show':
device_traversal()
elif arg == 'sff':
if len(args)!=2:
if len(ARGS) != 2:
show_eeprom_help()
elif int(args[1]) ==0 or int(args[1]) > DEVICE_NO['sfp']:
elif int(ARGS[1]) == 0 or int(ARGS[1]) > DEVICE_NO['sfp']:
show_eeprom_help()
else:
show_eeprom(args[1])
show_eeprom(ARGS[1])
return
elif arg == 'set':
if len(args)<3:
if len(ARGS) < 3:
show_set_help()
else:
set_device(args[1:])
set_device(ARGS[1:])
return
else:
show_help()
return 0
def show_help():
print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]}
print __doc__ % {'scriptName': sys.argv[0].split('/')[-1]}
sys.exit(0)
def show_set_help():
cmd = sys.argv[0].split("/")[-1]+ " " + args[0]
print cmd +" [led|sfp|fan]"
print " use \""+ cmd + " led 0-4 \" to set led color"
print " use \""+ cmd + " fan 0-100\" to set fan duty percetage"
print " use \""+ cmd + " sfp 1-54 {0|1}\" to set sfp# tx_disable"
cmd = sys.argv[0].split('/')[-1] + ' ' + ARGS[0]
print cmd + ' [led|sfp|fan]'
print ' use "' + cmd + ' led 0-4 " to set led color'
print ' use "' + cmd + ' fan 0-100" to set fan duty percetage'
print ' use "' + cmd + ' sfp 1-48 {0|1}" to set sfp# tx_disable'
sys.exit(0)
def show_eeprom_help():
cmd = sys.argv[0].split("/")[-1]+ " " + args[0]
print " use \""+ cmd + " 1-54 \" to dump sfp# eeprom"
cmd = sys.argv[0].split('/')[-1] + ' ' + ARGS[0]
print ' use "' + cmd + ' 1-54 " to dump sfp# eeprom'
sys.exit(0)
def my_log(txt):
if DEBUG == True:
print "[ROY]"+txt
print '[DBG]' + txt
return
def log_os_system(cmd, show):
logging.info('Run :' + cmd)
status, output = commands.getstatusoutput(cmd)
my_log (cmd +"with result:" + str(status))
my_log (" output:"+output)
(status, output) = commands.getstatusoutput(cmd)
my_log(cmd + 'with result:' + str(status))
my_log(' output:' + output)
if status:
logging.info('Failed :' + cmd)
if show:
print('Failed :'+cmd)
return status, output
print 'Failed :' + cmd
return (status, output)
def driver_check():
ret, lsmod = log_os_system("lsmod| grep accton", 0)
(ret, lsmod) = log_os_system('ls /sys/module/ | grep accton', 0)
logging.info('mods:' + lsmod)
if len(lsmod) ==0:
if not lsmod:
return False
return True
kos = [
'modprobe i2c_dev',
'modprobe i2c_mux_pca954x force_deselect_on_exit=1',
@ -161,47 +165,53 @@ kos = [
'modprobe accton_as7312_54x_fan',
'modprobe optoe',
'modprobe accton_as7312_54x_leds',
'modprobe accton_as7312_54x_psu' ]
'modprobe accton_as7312_54x_psu',
]
def driver_install():
global FORCE
status, output = log_os_system("depmod", 1)
log_os_system('depmod', 1)
for i in range(0, len(kos)):
status, output = log_os_system(kos[i], 1)
if status:
if FORCE == 0:
ret = log_os_system(kos[i], 1)
if ret[0] and FORCE == 0:
return status
return 0
def driver_uninstall():
global FORCE
for i in range(0, len(kos)):
rm = kos[-(i+1)].replace("modprobe", "modprobe -rq")
rm = rm.replace("insmod", "rmmod")
lst = rm.split(" ")
rm = kos[-(i + 1)].replace('modprobe', 'modprobe -rq')
rm = rm.replace('insmod', 'rmmod')
lst = rm.split(' ')
if len(lst) > 3:
del(lst[3])
rm = " ".join(lst)
status, output = log_os_system(rm, 1)
if status:
if FORCE == 0:
return status
del lst[3]
rm = ' '.join(lst)
ret = log_os_system(rm, 1)
if ret[0] and FORCE == 0:
return ret[0]
return 0
led_prefix = '/sys/class/leds/accton_' + PROJECT_NAME + '_led::'
hwmon_types = {'led': ['diag', 'fan', 'loc', 'psu1', 'psu2']}
hwmon_nodes = {'led': ['brightness']}
hwmon_prefix = {'led': led_prefix}
i2c_prefix = '/sys/bus/i2c/devices/'
i2c_bus = {'fan': ['2-0066'] ,
i2c_bus = {
'fan': ['2-0066'],
'thermal': ['3-0048', '3-0049', '3-004a', '3-004b'],
'psu': ['10-0051','11-0053'],
'sfp': ['-0050']}
i2c_nodes = {'fan': ['present', 'front_speed_rpm', 'rear_speed_rpm'] ,
'psu': ['10-0050', '11-0053'],
'sfp': ['-0050'],
}
i2c_nodes = {
'fan': ['present', 'front_speed_rpm', 'rear_speed_rpm'],
'thermal': ['hwmon/hwmon*/temp1_input'],
'psu': ['psu_present ', 'psu_power_good'],
'sfp': ['sfp_is_present', 'sfp_tx_disable']}
'sfp': ['module_present', 'module_tx_disable'],
}
sfp_map = [18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
@ -212,6 +222,20 @@ sfp_map = [18,19,20,21,22,23,24,25,26,27,
qsfp_start = 48
mknod_common = [
'echo as7312_54x_fan 0x66 > /sys/bus/i2c/devices/i2c-2/new_device ',
'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-3/new_device',
'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-3/new_device',
'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-3/new_device',
'echo lm75 0x4b > /sys/bus/i2c/devices/i2c-3/new_device',
'echo as7312_54x_psu1 0x53 > /sys/bus/i2c/devices/i2c-11/new_device',
'echo ym2651 0x5b > /sys/bus/i2c/devices/i2c-11/new_device',
'echo as7312_54x_psu2 0x50 > /sys/bus/i2c/devices/i2c-10/new_device',
'echo ym2651 0x58 > /sys/bus/i2c/devices/i2c-10/new_device',
'echo as7312_54x_cpld1 0x60 > /sys/bus/i2c/devices/i2c-4/new_device',
'echo as7312_54x_cpld2 0x62 > /sys/bus/i2c/devices/i2c-5/new_device',
'echo as7312_54x_cpld3 0x64 > /sys/bus/i2c/devices/i2c-6/new_device']
mknod = [
'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-0/new_device',
'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-0/new_device',
@ -222,20 +246,8 @@ mknod =[
'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo as7312_54x_fan 0x66 > /sys/bus/i2c/devices/i2c-2/new_device ',
'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-3/new_device',
'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-3/new_device',
'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-3/new_device',
'echo lm75 0x4b > /sys/bus/i2c/devices/i2c-3/new_device',
'echo as7312_54x_psu1 0x53 > /sys/bus/i2c/devices/i2c-11/new_device',
'echo ym2651 0x5b > /sys/bus/i2c/devices/i2c-11/new_device',
'echo as7312_54x_psu2 0x50 > /sys/bus/i2c/devices/i2c-10/new_device',
'echo ym2651 0x58 > /sys/bus/i2c/devices/i2c-10/new_device',
'echo as7312_54x_cpld1 0x60 > /sys/bus/i2c/devices/i2c-4/new_device',
'echo as7312_54x_cpld2 0x62 > /sys/bus/i2c/devices/i2c-5/new_device',
'echo as7312_54x_cpld3 0x64 > /sys/bus/i2c/devices/i2c-6/new_device']
'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-1/new_device',]
mknod = mknod + mknod_common
mknod2 = [
'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-1/new_device',
@ -247,41 +259,27 @@ mknod2 =[
'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-0/new_device',
'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-0/new_device',
'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-0/new_device',
'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-0/new_device',
'echo as7312_54x_fan 0x66 > /sys/bus/i2c/devices/i2c-2/new_device ',
'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-3/new_device',
'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-3/new_device',
'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-3/new_device',
'echo lm75 0x4b > /sys/bus/i2c/devices/i2c-3/new_device',
'echo as7312_54x_psu1 0x53 > /sys/bus/i2c/devices/i2c-11/new_device',
'echo ym2651 0x5b > /sys/bus/i2c/devices/i2c-11/new_device',
'echo as7312_54x_psu2 0x50 > /sys/bus/i2c/devices/i2c-10/new_device',
'echo ym2651 0x58 > /sys/bus/i2c/devices/i2c-10/new_device',
'echo as7312_54x_cpld1 0x60 > /sys/bus/i2c/devices/i2c-4/new_device',
'echo as7312_54x_cpld2 0x62 > /sys/bus/i2c/devices/i2c-5/new_device',
'echo as7312_54x_cpld3 0x64 > /sys/bus/i2c/devices/i2c-6/new_device']
'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-0/new_device',]
mknod2 = mknod2 + mknod_common
def i2c_order_check():
# i2c bus 0 and 1 might be installed in different order.
# Here check if 0x70 is exist @ i2c-1
tmp = "echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device"
status, output = log_os_system(tmp, 0)
if not device_exist():
tmp = "i2cget -y -f 0 0x70"
ret = log_os_system(tmp, 0)
if not ret[0]:
order = 1
else:
order = 0
tmp = "echo 0x70 > /sys/bus/i2c/devices/i2c-1/delete_device"
status, output = log_os_system(tmp, 0)
return order
def device_install():
global FORCE
order = i2c_order_check()
# if 0x70 is not exist @i2c-1, use reversed bus order
if order:
for i in range(0, len(mknod2)):
@ -289,7 +287,7 @@ def device_install():
if mknod2[i].find('pca954') != -1:
time.sleep(1)
status, output = log_os_system(mknod2[i], 1)
(status, output) = log_os_system(mknod2[i], 1)
if status:
print output
if FORCE == 0:
@ -300,16 +298,20 @@ def device_install():
if mknod[i].find('pca954') != -1:
time.sleep(1)
status, output = log_os_system(mknod[i], 1)
(status, output) = log_os_system(mknod[i], 1)
if status:
print output
if FORCE == 0:
return status
for i in range(0, len(sfp_map)):
if i < qsfp_start:
status, output =log_os_system("echo optoe2 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device", 1)
(status, output) = \
log_os_system('echo optoe2 0x50 > /sys/bus/i2c/devices/i2c-'
+ str(sfp_map[i]) + '/new_device', 1)
else:
status, output =log_os_system("echo optoe1 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device", 1)
(status, output) = \
log_os_system('echo optoe1 0x50 > /sys/bus/i2c/devices/i2c-'
+ str(sfp_map[i]) + '/new_device', 1)
if status:
print output
if FORCE == 0:
@ -319,31 +321,27 @@ def device_install():
def device_uninstall():
global FORCE
status, output =log_os_system("ls /sys/bus/i2c/devices/1-0076", 0)
if status==0:
I2C_ORDER=1
else:
I2C_ORDER=0
for i in range(0, len(sfp_map)):
target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device"
status, output =log_os_system("echo 0x50 > "+ target, 1)
target = '/sys/bus/i2c/devices/i2c-' + str(sfp_map[i]) \
+ '/delete_device'
(status, output) = log_os_system('echo 0x50 > ' + target, 1)
if status:
print output
if FORCE == 0:
return status
if I2C_ORDER==0:
nodelist = mknod
else:
order = i2c_order_check()
if order :
nodelist = mknod2
else:
nodelist = mknod
for i in range(len(nodelist)):
target = nodelist[-(i + 1)]
temp = target.split()
del temp[1]
temp[-1] = temp[-1].replace('new_device', 'delete_device')
status, output = log_os_system(" ".join(temp), 1)
(status, output) = log_os_system(' '.join(temp), 1)
if status:
print output
if FORCE == 0:
@ -351,54 +349,55 @@ def device_uninstall():
return
def system_ready():
if driver_check() == False:
if driver_check() is False:
return False
if not device_exist():
return False
return True
def do_install():
print "Checking system...."
if driver_check() == False:
print "No driver, installing...."
print 'Checking system....'
if driver_check() is False:
print 'No driver, installing....'
status = driver_install()
if status:
if FORCE == 0:
return status
else:
print PROJECT_NAME.upper()+" drivers detected...."
print PROJECT_NAME.upper() + ' drivers detected....'
if not device_exist():
print "No device, installing...."
print 'No device, installing....'
status = device_install()
if status:
if FORCE == 0:
return status
else:
print PROJECT_NAME.upper()+" devices detected...."
print PROJECT_NAME.upper() + ' devices detected....'
return
def do_uninstall():
print "Checking system...."
print 'Checking system....'
if not device_exist():
print PROJECT_NAME.upper() +" has no device installed...."
print PROJECT_NAME.upper() + ' has no device installed....'
else:
print "Removing device...."
print 'Removing device....'
status = device_uninstall()
if status:
if FORCE == 0:
if status and FORCE == 0:
return status
if driver_check()== False :
print PROJECT_NAME.upper() +" has no driver installed...."
if driver_check() is False:
print PROJECT_NAME.upper() + ' has no driver installed....'
else:
print "Removing installed driver...."
print 'Removing installed driver....'
status = driver_uninstall()
if status:
if FORCE == 0:
if status and FORCE == 0:
return status
return None
return
def devices_info():
global DEVICE_NO
@ -417,19 +416,24 @@ def devices_info():
if 'fan' == key:
for k in range(0, DEVICE_NO[key]):
node = key + str(k + 1)
path = i2c_prefix+ buses[i]+"/fan"+str(k+1)+"_"+ nodes[j]
my_log(node+": "+ path)
path = i2c_prefix + buses[i] + '/fan' + str(k
+ 1) + '_' + nodes[j]
my_log(node + ': ' + path)
ALL_DEVICE[key][node].append(path)
elif 'sfp' == key:
for k in range(0, DEVICE_NO[key]):
if k in range(24) or k in range(48, 52):
fmt = i2c_prefix + '5-0062/{0}_{1}'
else:
fmt = i2c_prefix + '6-0064/{0}_{1}'
node = key + str(k + 1)
path = i2c_prefix+ str(sfp_map[k])+ buses[i]+"/"+ nodes[j]
my_log(node+": "+ path)
path = fmt.format(nodes[j], k + 1)
my_log(node + ': ' + path)
ALL_DEVICE[key][node].append(path)
else:
node = key + str(i + 1)
path = i2c_prefix+ buses[i]+"/"+ nodes[j]
my_log(node+": "+ path)
path = i2c_prefix + buses[i] + '/' + nodes[j]
my_log(node + ': ' + path)
ALL_DEVICE[key][node].append(path)
for key in hwmon_types:
@ -437,37 +441,39 @@ def devices_info():
nodes = hwmon_nodes[key]
for i in range(0, len(itypes)):
for j in range(0, len(nodes)):
node = key+"_"+itypes[i]
path = hwmon_prefix[key]+ itypes[i]+"/"+ nodes[j]
my_log(node+": "+ path)
node = key + '_' + itypes[i]
path = hwmon_prefix[key] + itypes[i] + '/' + nodes[j]
my_log(node + ': ' + path)
ALL_DEVICE[key][key + str(i + 1)].append(path)
# show dict all in the order
if DEBUG == True:
for i in sorted(ALL_DEVICE.keys()):
print(i+": ")
print i + ': '
for j in sorted(ALL_DEVICE[i].keys()):
print(" "+j)
for k in (ALL_DEVICE[i][j]):
print(" "+" "+k)
print ' ' + j
for k in ALL_DEVICE[i][j]:
print ' ' + ' ' + k
return
def show_eeprom(index):
if system_ready()==False:
print("System's not ready.")
print("Please install first!")
if system_ready() is False:
print "System's not ready."
print 'Please install first!'
return
if len(ALL_DEVICE) == 0:
devices_info()
node = ALL_DEVICE['sfp']['sfp' + str(index)][0]
node = node.replace(node.split("/")[-1], 'sfp_eeprom')
node = node.replace(node.split('/')[-1], 'sfp_eeprom')
# check if got hexdump command in current environment
ret, log = log_os_system("which hexdump", 0)
ret, log2 = log_os_system("which busybox hexdump", 0)
if len(log):
(ret, log) = log_os_system('which hexdump', 0)
(ret, log2) = log_os_system('which busybox hexdump', 0)
if log:
hex_cmd = 'hexdump'
elif len(log2):
elif log2:
hex_cmd = ' busybox hexdump'
else:
log = 'Failed : no hexdump cmd!!'
@ -475,52 +481,58 @@ def show_eeprom(index):
print log
return 1
print node + ":"
ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1)
print node + ':'
(ret, log) = log_os_system('cat ' + node + '| ' + hex_cmd + ' -C',
1)
if ret == 0:
print log
else:
print "**********device no found**********"
print '**********device no found**********'
return
def set_device(args):
global DEVICE_NO
global ALL_DEVICE
if system_ready()==False:
print("System's not ready.")
print("Please install first!")
if system_ready() is False:
print "System's not ready."
print 'Please install first!'
return
if len(ALL_DEVICE)==0:
if not ALL_DEVICE:
devices_info()
if args[0] == 'led':
if int(args[1]) > 4:
show_set_help()
return
# print ALL_DEVICE['led']
for i in range(0, len(ALL_DEVICE['led'])):
for k in (ALL_DEVICE['led']['led'+str(i+1)]):
ret, log = log_os_system("echo "+args[1]+" >"+k, 1)
if ret:
return ret
for k in ALL_DEVICE['led']['led' + str(i + 1)]:
ret = log_os_system('echo ' + args[1] + ' >' + k, 1)
if ret[0]:
return ret[0]
elif args[0] == 'fan':
if int(args[1]) > 100:
show_set_help()
return
# print ALL_DEVICE['fan']
# fan1~6 is all fine, all fan share same setting
node = ALL_DEVICE['fan']['fan1'][0]
node = node.replace(node.split("/")[-1], 'fan_duty_cycle_percentage')
ret, log = log_os_system("cat "+ node, 1)
node = node.replace(node.split('/')[-1],
'fan_duty_cycle_percentage')
(ret, log) = log_os_system('cat ' + node, 1)
if ret == 0:
print ("Previous fan duty: " + log.strip() +"%")
ret, log = log_os_system("echo "+args[1]+" >"+node, 1)
if ret==0:
print ("Current fan duty: " + args[1] +"%")
print 'Previous fan duty: ' + log.strip() + '%'
ret = log_os_system('echo ' + args[1] + ' >' + node, 1)
if ret[0] == 0:
print 'Current fan duty: ' + args[1] + '%'
return ret
elif args[0] == 'sfp':
if int(args[1])> DEVICE_NO[args[0]] or int(args[1])==0:
if int(args[1]) > qsfp_start or int(args[1]) == 0:
show_set_help()
return
if len(args) < 2:
@ -532,56 +544,58 @@ def set_device(args):
return
# print ALL_DEVICE[args[0]]
for i in range(0,len(ALL_DEVICE[args[0]])):
for i in range(len(ALL_DEVICE[args[0]])):
for j in ALL_DEVICE[args[0]][args[0] + str(args[1])]:
if j.find('tx_disable') != -1:
ret, log = log_os_system("echo "+args[2]+" >"+ j, 1)
if ret:
return ret
ret = log_os_system('echo ' + args[2] + ' >' + j, 1)
if ret[0]:
return ret[0]
return
# get digits inside a string.
#Ex: 31 for "sfp31"
def get_value(input):
digit = re.findall('\d+', input)
# Ex: get 31 from "sfp31"
def get_value(i):
digit = re.findall('\d+', i)
return int(digit[0])
def device_traversal():
if system_ready()==False:
print("System's not ready.")
print("Please install first!")
if system_ready() is False:
print "System's not ready."
print 'Please install first!'
return
if len(ALL_DEVICE)==0:
if not ALL_DEVICE:
devices_info()
for i in sorted(ALL_DEVICE.keys()):
print("============================================")
print(i.upper()+": ")
print("============================================")
print '============================================'
print i.upper() + ': '
print '============================================'
for j in sorted(ALL_DEVICE[i].keys(), key=get_value):
print " "+j+":",
for k in (ALL_DEVICE[i][j]):
ret, log = log_os_system("cat "+k, 0)
func = k.split("/")[-1].strip()
print ' ' + j + ':',
for k in ALL_DEVICE[i][j]:
(ret, log) = log_os_system('cat ' + k, 0)
func = k.split('/')[-1].strip()
func = re.sub(j + '_', '', func, 1)
func = re.sub(i.lower() + '_', '', func, 1)
if ret == 0:
print func+"="+log+" ",
print func + '=' + log + ' ',
else:
print func+"="+"X"+" ",
print func + '=' + 'X' + ' ',
print
print("----------------------------------------------------------------")
print '----------------------------------------------------------------'
print
return
def device_exist():
ret1, log = log_os_system("ls "+i2c_prefix+"*0070", 0)
ret2, log = log_os_system("ls "+i2c_prefix+"i2c-2", 0)
return not(ret1 or ret2)
if __name__ == "__main__":
def device_exist():
ret1 = log_os_system('ls ' + i2c_prefix + '*0070', 0)
ret2 = log_os_system('ls ' + i2c_prefix + 'i2c-2', 0)
return not (ret1[0] or ret2[0])
if __name__ == '__main__':
main()