[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:
parent
aa38022ca6
commit
54681f169f
@ -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)):
|
||||
@ -344,7 +331,7 @@ def device_install():
|
||||
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)
|
||||
@ -359,7 +346,7 @@ def device_install():
|
||||
print output
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
|
||||
return
|
||||
|
||||
def device_uninstall():
|
||||
@ -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,19 +513,15 @@ 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]
|
||||
|
||||
def cpld_path_of_port(port_index):
|
||||
if port_index < 1 and port_index > DEVICE_NO['sfp']:
|
||||
return None
|
||||
return None
|
||||
if port_index < 25:
|
||||
return get_cpld_path(0)
|
||||
else:
|
||||
@ -550,7 +533,7 @@ def get_path_sfp_tx_dis(port_index):
|
||||
return False, ''
|
||||
else:
|
||||
dev = cpld_p+"module_tx_disable_"+str(port_index)
|
||||
return True, dev
|
||||
return True, dev
|
||||
|
||||
def get_path_sfp_presence(port_index):
|
||||
cpld_p = cpld_path_of_port(port_index)
|
||||
@ -558,7 +541,7 @@ def get_path_sfp_presence(port_index):
|
||||
return False, ''
|
||||
else:
|
||||
dev = cpld_p+"module_present_"+str(port_index)
|
||||
return True, dev
|
||||
return True, dev
|
||||
|
||||
|
||||
def set_device(args):
|
||||
@ -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.
|
||||
@ -635,7 +618,7 @@ def print_1_device_traversal(i, j, k):
|
||||
return func+"="+log+" "
|
||||
else:
|
||||
return func+"="+"X"+" "
|
||||
|
||||
|
||||
def device_traversal():
|
||||
if system_ready()==False:
|
||||
print("System's not ready.")
|
||||
@ -659,18 +642,18 @@ def device_traversal():
|
||||
if ret == False:
|
||||
continue
|
||||
log = print_1_device_traversal(i, j, k)
|
||||
print log,
|
||||
print log,
|
||||
if k.find('present')!= -1:
|
||||
ret, k = get_path_sfp_presence(port_index)
|
||||
if ret == False:
|
||||
continue
|
||||
log = print_1_device_traversal(i, j, k)
|
||||
print log,
|
||||
|
||||
print log,
|
||||
|
||||
else:
|
||||
for k in (ALL_DEVICE[i][j]):
|
||||
log = print_1_device_traversal(i, j, k)
|
||||
print log,
|
||||
print log,
|
||||
print
|
||||
print("----------------------------------------------------------------")
|
||||
|
||||
@ -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()
|
||||
|
@ -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)):
|
||||
@ -344,7 +332,7 @@ def device_install():
|
||||
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)
|
||||
@ -359,7 +347,7 @@ def device_install():
|
||||
print output
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
|
||||
return
|
||||
|
||||
def device_uninstall():
|
||||
@ -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,19 +514,15 @@ 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]
|
||||
|
||||
def cpld_path_of_port(port_index):
|
||||
if port_index < 1 and port_index > DEVICE_NO['sfp']:
|
||||
return None
|
||||
return None
|
||||
if port_index < 25:
|
||||
return get_cpld_path(0)
|
||||
else:
|
||||
@ -550,7 +534,7 @@ def get_path_sfp_tx_dis(port_index):
|
||||
return False, ''
|
||||
else:
|
||||
dev = cpld_p+"module_tx_disable_"+str(port_index)
|
||||
return True, dev
|
||||
return True, dev
|
||||
|
||||
def get_path_sfp_presence(port_index):
|
||||
cpld_p = cpld_path_of_port(port_index)
|
||||
@ -558,7 +542,7 @@ def get_path_sfp_presence(port_index):
|
||||
return False, ''
|
||||
else:
|
||||
dev = cpld_p+"module_present_"+str(port_index)
|
||||
return True, dev
|
||||
return True, dev
|
||||
|
||||
|
||||
def set_device(args):
|
||||
@ -635,7 +619,7 @@ def print_1_device_traversal(i, j, k):
|
||||
return func+"="+log+" "
|
||||
else:
|
||||
return func+"="+"X"+" "
|
||||
|
||||
|
||||
def device_traversal():
|
||||
if system_ready()==False:
|
||||
print("System's not ready.")
|
||||
@ -659,18 +643,18 @@ def device_traversal():
|
||||
if ret == False:
|
||||
continue
|
||||
log = print_1_device_traversal(i, j, k)
|
||||
print log,
|
||||
print log,
|
||||
if k.find('present')!= -1:
|
||||
ret, k = get_path_sfp_presence(port_index)
|
||||
if ret == False:
|
||||
continue
|
||||
log = print_1_device_traversal(i, j, k)
|
||||
print log,
|
||||
|
||||
print log,
|
||||
|
||||
else:
|
||||
for k in (ALL_DEVICE[i][j]):
|
||||
log = print_1_device_traversal(i, j, k)
|
||||
print log,
|
||||
print log,
|
||||
print
|
||||
print("----------------------------------------------------------------")
|
||||
|
||||
|
@ -21,13 +21,13 @@ Usage: %(scriptName)s [options] command object
|
||||
options:
|
||||
-h | --help : this help message
|
||||
-d | --debug : run with debug mode
|
||||
-f | --force : ignore error during installation or clean
|
||||
-f | --force : ignore error during installation or clean
|
||||
command:
|
||||
install : install drivers and generate related sysfs nodes
|
||||
clean : uninstall drivers and remove related sysfs nodes
|
||||
show : show all systen status
|
||||
sff : dump SFP eeprom
|
||||
set : change board setting with fan|led|sfp
|
||||
set : change board setting with fan|led|sfp
|
||||
"""
|
||||
|
||||
import commands
|
||||
@ -45,7 +45,7 @@ version = '0.1.0'
|
||||
verbose = False
|
||||
DEBUG = False
|
||||
args = []
|
||||
ALL_DEVICE = {}
|
||||
ALL_DEVICE = {}
|
||||
DEVICE_NO = {'led':5, 'fan':5,'thermal':4, 'psu':2, 'sfp':54}
|
||||
FORCE = 0
|
||||
#logging.basicConfig(filename= PROJECT_NAME+'.log', filemode='w',level=logging.DEBUG)
|
||||
@ -54,37 +54,37 @@ FORCE = 0
|
||||
|
||||
if DEBUG == True:
|
||||
print sys.argv[0]
|
||||
print 'ARGV :', sys.argv[1:]
|
||||
print 'ARGV :', sys.argv[1:]
|
||||
|
||||
|
||||
def main():
|
||||
global DEBUG
|
||||
global args
|
||||
global FORCE
|
||||
|
||||
|
||||
if len(sys.argv)<2:
|
||||
show_help()
|
||||
|
||||
|
||||
options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help',
|
||||
'debug',
|
||||
'force',
|
||||
])
|
||||
if DEBUG == True:
|
||||
if DEBUG == True:
|
||||
print options
|
||||
print args
|
||||
print len(sys.argv)
|
||||
|
||||
|
||||
for opt, arg in options:
|
||||
if opt in ('-h', '--help'):
|
||||
show_help()
|
||||
elif opt in ('-d', '--debug'):
|
||||
elif opt in ('-d', '--debug'):
|
||||
DEBUG = True
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
elif opt in ('-f', '--force'):
|
||||
elif opt in ('-f', '--force'):
|
||||
FORCE = 1
|
||||
else:
|
||||
logging.info('no option')
|
||||
for arg in args:
|
||||
logging.info('no option')
|
||||
for arg in args:
|
||||
if arg == 'install':
|
||||
do_install()
|
||||
elif arg == 'clean':
|
||||
@ -94,23 +94,23 @@ def main():
|
||||
elif arg == 'sff':
|
||||
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])
|
||||
return
|
||||
show_eeprom(args[1])
|
||||
return
|
||||
elif arg == 'set':
|
||||
if len(args)<3:
|
||||
show_set_help()
|
||||
else:
|
||||
set_device(args[1:])
|
||||
return
|
||||
set_device(args[1:])
|
||||
return
|
||||
else:
|
||||
show_help()
|
||||
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
return 0
|
||||
|
||||
def show_help():
|
||||
print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]}
|
||||
sys.exit(0)
|
||||
@ -119,36 +119,36 @@ 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"
|
||||
sys.exit(0)
|
||||
|
||||
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"
|
||||
sys.exit(0)
|
||||
|
||||
print " use \""+ cmd + " 1-54 \" to dump sfp# eeprom"
|
||||
sys.exit(0)
|
||||
|
||||
def my_log(txt):
|
||||
if DEBUG == True:
|
||||
print "[Debug]"+txt
|
||||
print "[Debug]"+txt
|
||||
return
|
||||
|
||||
|
||||
def log_os_system(cmd, show):
|
||||
logging.info('Run :'+cmd)
|
||||
status, output = commands.getstatusoutput(cmd)
|
||||
logging.info('Run :'+cmd)
|
||||
status, output = commands.getstatusoutput(cmd)
|
||||
my_log (cmd +"with result:" + str(status))
|
||||
my_log (" output:"+output)
|
||||
my_log (" output:"+output)
|
||||
if status:
|
||||
logging.info('Failed :'+cmd)
|
||||
if show:
|
||||
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:
|
||||
return False
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
@ -165,30 +165,30 @@ 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:
|
||||
if FORCE == 0:
|
||||
return status
|
||||
ret = log_os_system(kos[i], 1)
|
||||
if ret[0]:
|
||||
if FORCE == 0:
|
||||
return ret[0]
|
||||
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")
|
||||
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
|
||||
rm = " ".join(lst)
|
||||
ret = log_os_system(rm, 1)
|
||||
if ret[0]:
|
||||
if FORCE == 0:
|
||||
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}
|
||||
@ -196,13 +196,13 @@ hwmon_prefix ={'led': led_prefix}
|
||||
i2c_prefix = '/sys/bus/i2c/devices/'
|
||||
i2c_bus = {'fan': ['3-0063'] ,
|
||||
'thermal': ['18-004b','19-004c', '20-0049', '21-004a'] ,
|
||||
'psu': ['11-0050','12-0053'],
|
||||
'psu': ['11-0050','12-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': ['module_present_', 'module_tx_disable_']}
|
||||
|
||||
|
||||
sfp_map = [42,43,44,45,46,47,48,49,50,51,
|
||||
52,53,54,55,56,57,58,59,60,61,
|
||||
62,63,64,65,66,67,68,69,70,71,
|
||||
@ -216,7 +216,7 @@ qsfp_start = 48
|
||||
cpld_of_module = {'3-0061': list(range(0,38)),
|
||||
'3-0062': list(range(38,54)) }
|
||||
|
||||
mknod =[
|
||||
mknod =[
|
||||
'echo pca9548 0x77 > /sys/bus/i2c/devices/i2c-1/new_device',
|
||||
'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-2/new_device' ,
|
||||
'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-2/new_device' ,
|
||||
@ -243,7 +243,7 @@ mknod =[
|
||||
'echo as5835_54x_cpld2 0x61 > /sys/bus/i2c/devices/i2c-3/new_device',
|
||||
'echo as5835_54x_cpld3 0x62 > /sys/bus/i2c/devices/i2c-3/new_device']
|
||||
|
||||
mknod2 =[
|
||||
mknod2 =[
|
||||
'echo pca9548 0x77 > /sys/bus/i2c/devices/i2c-0/new_device',
|
||||
'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-2/new_device' ,
|
||||
'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-2/new_device' ,
|
||||
@ -269,54 +269,52 @@ mknod2 =[
|
||||
'echo as5835_54x_cpld1 0x60 > /sys/bus/i2c/devices/i2c-3/new_device',
|
||||
'echo as5835_54x_cpld2 0x61 > /sys/bus/i2c/devices/i2c-3/new_device',
|
||||
'echo as5835_54x_cpld3 0x62 > /sys/bus/i2c/devices/i2c-3/new_device']
|
||||
|
||||
|
||||
def i2c_order_check():
|
||||
|
||||
|
||||
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():
|
||||
global FORCE
|
||||
|
||||
|
||||
order = i2c_order_check()
|
||||
|
||||
# if 0x77 is not exist @i2c-1, use reversed bus order
|
||||
if order:
|
||||
|
||||
# if 0x77 is not exist @i2c-1, use reversed bus order
|
||||
if order:
|
||||
for i in range(0,len(mknod2)):
|
||||
#for pca954x need times to built new i2c buses
|
||||
#for pca954x need times to built new i2c buses
|
||||
if mknod2[i].find('pca954') != -1:
|
||||
time.sleep(1)
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
status, output = log_os_system(mknod2[i], 1)
|
||||
time.sleep(0.01)
|
||||
if status:
|
||||
print output
|
||||
if FORCE == 0:
|
||||
return status
|
||||
return status
|
||||
else:
|
||||
for i in range(0,len(mknod)):
|
||||
#for pca954x need times to built new i2c buses
|
||||
#for pca954x need times to built new i2c buses
|
||||
if mknod[i].find('pca954') != -1:
|
||||
time.sleep(1)
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
status, output = log_os_system(mknod[i], 1)
|
||||
if status:
|
||||
print output
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
for i in range(49, 55): #Set qsfp port to normal state
|
||||
log_os_system("echo 0 > /sys/bus/i2c/devices/3-0062/module_reset_" + str(i), 1)
|
||||
|
||||
log_os_system("echo 0 > /sys/bus/i2c/devices/3-0062/module_reset_" + str(i), 1)
|
||||
|
||||
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)
|
||||
@ -324,32 +322,27 @@ def device_install():
|
||||
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:
|
||||
return status
|
||||
return
|
||||
|
||||
if FORCE == 0:
|
||||
return status
|
||||
return
|
||||
|
||||
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)
|
||||
if status:
|
||||
print output
|
||||
if FORCE == 0:
|
||||
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()
|
||||
@ -358,72 +351,72 @@ def device_uninstall():
|
||||
status, output = log_os_system(" ".join(temp), 1)
|
||||
if status:
|
||||
print output
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
return
|
||||
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
return
|
||||
|
||||
def system_ready():
|
||||
if driver_check() == False:
|
||||
return False
|
||||
if not device_exist():
|
||||
if not device_exist():
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def do_install():
|
||||
print "Checking system...."
|
||||
if driver_check() == False:
|
||||
print "No driver, installing...."
|
||||
print "No driver, installing...."
|
||||
status = driver_install()
|
||||
if status:
|
||||
if FORCE == 0:
|
||||
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...."
|
||||
status = device_install()
|
||||
print "No device, installing...."
|
||||
status = device_install()
|
||||
if status:
|
||||
if FORCE == 0:
|
||||
return 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...."
|
||||
if not device_exist():
|
||||
print PROJECT_NAME.upper() +" has no device installed...."
|
||||
print PROJECT_NAME.upper() +" has no device installed...."
|
||||
else:
|
||||
print "Removing device...."
|
||||
status = device_uninstall()
|
||||
print "Removing device...."
|
||||
status = device_uninstall()
|
||||
if status:
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
if driver_check()== False :
|
||||
print PROJECT_NAME.upper() +" has no driver installed...."
|
||||
else:
|
||||
print "Removing installed driver...."
|
||||
status = driver_uninstall()
|
||||
if status:
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
return
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
return
|
||||
|
||||
def devices_info():
|
||||
global DEVICE_NO
|
||||
global ALL_DEVICE
|
||||
global i2c_bus, hwmon_types
|
||||
for key in DEVICE_NO:
|
||||
ALL_DEVICE[key]= {}
|
||||
for key in DEVICE_NO:
|
||||
ALL_DEVICE[key]= {}
|
||||
for i in range(0,DEVICE_NO[key]):
|
||||
ALL_DEVICE[key][key+str(i+1)] = []
|
||||
|
||||
|
||||
for key in i2c_bus:
|
||||
buses = i2c_bus[key]
|
||||
nodes = i2c_nodes[key]
|
||||
nodes = i2c_nodes[key]
|
||||
for i in range(0,len(buses)):
|
||||
for j in range(0,len(nodes)):
|
||||
if 'fan' == key:
|
||||
@ -431,7 +424,7 @@ def devices_info():
|
||||
node = key+str(k+1)
|
||||
path = i2c_prefix+ buses[i]+"/fan"+str(k+1)+"_"+ nodes[j]
|
||||
my_log(node+": "+ path)
|
||||
ALL_DEVICE[key][node].append(path)
|
||||
ALL_DEVICE[key][node].append(path)
|
||||
elif 'sfp' == key:
|
||||
for k in range(0,DEVICE_NO[key]):
|
||||
for lk in cpld_of_module:
|
||||
@ -442,160 +435,160 @@ def devices_info():
|
||||
ALL_DEVICE[key][node].append(path)
|
||||
else:
|
||||
node = key+str(i+1)
|
||||
path = i2c_prefix+ buses[i]+"/"+ nodes[j]
|
||||
path = i2c_prefix+ buses[i]+"/"+ nodes[j]
|
||||
my_log(node+": "+ path)
|
||||
ALL_DEVICE[key][node].append(path)
|
||||
|
||||
ALL_DEVICE[key][node].append(path)
|
||||
|
||||
for key in hwmon_types:
|
||||
itypes = hwmon_types[key]
|
||||
nodes = hwmon_nodes[key]
|
||||
nodes = hwmon_nodes[key]
|
||||
for i in range(0,len(itypes)):
|
||||
for j in range(0,len(nodes)):
|
||||
for j in range(0,len(nodes)):
|
||||
node = key+"_"+itypes[i]
|
||||
path = hwmon_prefix[key]+ itypes[i]+"/"+ nodes[j]
|
||||
path = hwmon_prefix[key]+ itypes[i]+"/"+ nodes[j]
|
||||
my_log(node+": "+ path)
|
||||
ALL_DEVICE[key][ key+str(i+1)].append(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+": ")
|
||||
for j in sorted(ALL_DEVICE[i].keys()):
|
||||
for j in sorted(ALL_DEVICE[i].keys()):
|
||||
print(" "+j)
|
||||
for k in (ALL_DEVICE[i][j]):
|
||||
for k in (ALL_DEVICE[i][j]):
|
||||
print(" "+" "+k)
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
def show_eeprom(index):
|
||||
if system_ready()==False:
|
||||
print("System's not ready.")
|
||||
print("System's not ready.")
|
||||
print("Please install first!")
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
if len(ALL_DEVICE)==0:
|
||||
devices_info()
|
||||
devices_info()
|
||||
node = ALL_DEVICE['sfp'] ['sfp'+str(index)][0]
|
||||
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, 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!!'
|
||||
logging.info(log)
|
||||
print log
|
||||
return 1
|
||||
|
||||
return 1
|
||||
|
||||
print node + ":"
|
||||
ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1)
|
||||
if ret==0:
|
||||
print log
|
||||
if ret==0:
|
||||
print log
|
||||
else:
|
||||
print "**********device no found**********"
|
||||
return
|
||||
|
||||
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("System's not ready.")
|
||||
print("Please install first!")
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
if len(ALL_DEVICE)==0:
|
||||
devices_info()
|
||||
|
||||
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 i in range(0,len(ALL_DEVICE['led'])):
|
||||
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~5 is all fine, all fan share same setting
|
||||
node = ALL_DEVICE['fan'] ['fan1'][0]
|
||||
#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:
|
||||
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] +"%")
|
||||
return ret
|
||||
ret = log_os_system("cat "+ node, 1)
|
||||
if ret[0] == 0:
|
||||
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[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
|
||||
return
|
||||
if len(args)<2:
|
||||
show_set_help()
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
if int(args[2])>1:
|
||||
show_set_help()
|
||||
return
|
||||
|
||||
#print ALL_DEVICE[args[0]]
|
||||
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
|
||||
|
||||
|
||||
#print ALL_DEVICE[args[0]]
|
||||
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_os_system("echo "+args[2]+" >"+ j, 1)
|
||||
if ret[0]:
|
||||
return ret[0]
|
||||
|
||||
return
|
||||
|
||||
#get digits inside a string.
|
||||
#Ex: 31 for "sfp31"
|
||||
|
||||
#get digits inside a string.
|
||||
#Ex: 31 for "sfp31"
|
||||
def get_value(input):
|
||||
digit = re.findall('\d+', input)
|
||||
return int(digit[0])
|
||||
|
||||
|
||||
def device_traversal():
|
||||
if system_ready()==False:
|
||||
print("System's not ready.")
|
||||
print("System's not ready.")
|
||||
print("Please install first!")
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
if len(ALL_DEVICE)==0:
|
||||
devices_info()
|
||||
for i in sorted(ALL_DEVICE.keys()):
|
||||
print("============================================")
|
||||
print("============================================")
|
||||
print(i.upper()+": ")
|
||||
print("============================================")
|
||||
|
||||
for j in sorted(ALL_DEVICE[i].keys(), key=get_value):
|
||||
|
||||
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()
|
||||
func = re.sub(j+'_','',func,1)
|
||||
func = re.sub(i.lower()+'_','',func,1)
|
||||
func = re.sub(i.lower()+'_','',func,1)
|
||||
if ret==0:
|
||||
print func+"="+log+" ",
|
||||
print func+"="+log+" ",
|
||||
else:
|
||||
print func+"="+"X"+" ",
|
||||
print
|
||||
print
|
||||
print("----------------------------------------------------------------")
|
||||
|
||||
|
||||
|
||||
|
||||
print
|
||||
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()
|
||||
|
@ -100,26 +100,17 @@ class FanUtil(object):
|
||||
return None
|
||||
|
||||
device_path = self.get_fan_to_device_path(fan_num, node_num)
|
||||
|
||||
try:
|
||||
val_file = open(device_path, 'r')
|
||||
with open(device_path, 'r') as val_file:
|
||||
content = val_file.readline().rstrip()
|
||||
if not content:
|
||||
logging.debug('GET. content is NULL, path:%s', device_path)
|
||||
return None
|
||||
except IOError as e:
|
||||
logging.error('GET. unable to open file: %s', str(e))
|
||||
return None
|
||||
logging.error('GET. unable to read file: %s', str(e))
|
||||
else:
|
||||
return int(content)
|
||||
|
||||
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 _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:
|
||||
@ -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)
|
||||
with open(self.FAN_DUTY_PATH) as val_file:
|
||||
content = val_file.readline().rstrip()
|
||||
except IOError as e:
|
||||
print "Error: unable to open file: %s" % str(e)
|
||||
return False
|
||||
|
||||
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+')
|
||||
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
|
||||
#val = ((val + 1 ) * 625 +75 ) / 100
|
||||
fan_file.write(str(val))
|
||||
fan_file.close()
|
||||
return True
|
||||
|
||||
#def get_fanr_fault(self, fan_num):
|
||||
|
@ -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:
|
||||
val_file = open(filename, 'r')
|
||||
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 None
|
||||
|
||||
return int(content)
|
||||
|
||||
|
||||
def get_num_thermals(self):
|
||||
return self.THERMAL_NUM_ON_MAIN_BROAD
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
@ -21,13 +20,13 @@ Usage: %(scriptName)s [options] command object
|
||||
options:
|
||||
-h | --help : this help message
|
||||
-d | --debug : run with debug mode
|
||||
-f | --force : ignore error during installation or clean
|
||||
-f | --force : ignore error during installation or clean
|
||||
command:
|
||||
install : install drivers and generate related sysfs nodes
|
||||
clean : uninstall drivers and remove related sysfs nodes
|
||||
show : show all systen status
|
||||
sff : dump SFP eeprom
|
||||
set : change board setting with fan|led|sfp
|
||||
set : change board setting with fan|led|sfp
|
||||
"""
|
||||
|
||||
import commands
|
||||
@ -38,550 +37,565 @@ import re
|
||||
import time
|
||||
|
||||
|
||||
|
||||
|
||||
PROJECT_NAME = 'as7312_54x'
|
||||
version = '0.1.0'
|
||||
verbose = False
|
||||
DEBUG = False
|
||||
args = []
|
||||
ALL_DEVICE = {}
|
||||
DEVICE_NO = {'led':5, 'fan':6,'thermal':4, 'psu':2, 'sfp':54}
|
||||
ARGS = []
|
||||
ALL_DEVICE = {}
|
||||
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)
|
||||
|
||||
# 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:]
|
||||
print 'ARGV :', sys.argv[1:]
|
||||
|
||||
|
||||
def main():
|
||||
global DEBUG
|
||||
global args
|
||||
global ARGS
|
||||
global FORCE
|
||||
|
||||
if len(sys.argv)<2:
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
show_help()
|
||||
|
||||
options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help',
|
||||
'debug',
|
||||
'force',
|
||||
])
|
||||
if DEBUG == True:
|
||||
|
||||
(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'):
|
||||
elif opt in ('-d', '--debug'):
|
||||
DEBUG = True
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
elif opt in ('-f', '--force'):
|
||||
elif opt in ('-f', '--force'):
|
||||
FORCE = 1
|
||||
else:
|
||||
logging.info('no option')
|
||||
for arg in args:
|
||||
logging.info('no option')
|
||||
for arg in ARGS:
|
||||
if arg == 'install':
|
||||
do_install()
|
||||
do_install()
|
||||
elif arg == 'clean':
|
||||
do_uninstall()
|
||||
do_uninstall()
|
||||
elif arg == 'show':
|
||||
device_traversal()
|
||||
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])
|
||||
return
|
||||
show_eeprom(ARGS[1])
|
||||
return
|
||||
elif arg == 'set':
|
||||
if len(args)<3:
|
||||
if len(ARGS) < 3:
|
||||
show_set_help()
|
||||
else:
|
||||
set_device(args[1:])
|
||||
return
|
||||
set_device(ARGS[1:])
|
||||
return
|
||||
else:
|
||||
show_help()
|
||||
|
||||
|
||||
return 0
|
||||
|
||||
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"
|
||||
sys.exit(0)
|
||||
|
||||
def show_eeprom_help():
|
||||
cmd = sys.argv[0].split("/")[-1]+ " " + args[0]
|
||||
print " use \""+ cmd + " 1-54 \" to dump sfp# eeprom"
|
||||
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-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'
|
||||
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)
|
||||
if status:
|
||||
logging.info('Failed :'+cmd)
|
||||
if show:
|
||||
print('Failed :'+cmd)
|
||||
return status, output
|
||||
|
||||
def driver_check():
|
||||
ret, lsmod = log_os_system("lsmod| grep accton", 0)
|
||||
logging.info('mods:'+lsmod)
|
||||
if len(lsmod) ==0:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
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)
|
||||
if status:
|
||||
logging.info('Failed :' + cmd)
|
||||
if show:
|
||||
print 'Failed :' + cmd
|
||||
return (status, output)
|
||||
|
||||
|
||||
def driver_check():
|
||||
(ret, lsmod) = log_os_system('ls /sys/module/ | grep accton', 0)
|
||||
logging.info('mods:' + lsmod)
|
||||
if not lsmod:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
kos = [
|
||||
'modprobe i2c_dev',
|
||||
'modprobe i2c_mux_pca954x force_deselect_on_exit=1',
|
||||
'modprobe accton_i2c_cpld' ,
|
||||
'modprobe ym2651y' ,
|
||||
'modprobe accton_as7312_54x_fan' ,
|
||||
'modprobe optoe' ,
|
||||
'modprobe accton_as7312_54x_leds' ,
|
||||
'modprobe accton_as7312_54x_psu' ]
|
||||
'modprobe i2c_dev',
|
||||
'modprobe i2c_mux_pca954x force_deselect_on_exit=1',
|
||||
'modprobe accton_i2c_cpld',
|
||||
'modprobe ym2651y',
|
||||
'modprobe accton_as7312_54x_fan',
|
||||
'modprobe optoe',
|
||||
'modprobe accton_as7312_54x_leds',
|
||||
'modprobe accton_as7312_54x_psu',
|
||||
]
|
||||
|
||||
|
||||
def driver_install():
|
||||
global FORCE
|
||||
status, output = 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:
|
||||
return status
|
||||
log_os_system('depmod', 1)
|
||||
for i in range(0, len(kos)):
|
||||
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(" ")
|
||||
for i in range(0, len(kos)):
|
||||
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}
|
||||
|
||||
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'] ,
|
||||
'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'] ,
|
||||
'thermal': ['hwmon/hwmon*/temp1_input'] ,
|
||||
'psu': ['psu_present ', 'psu_power_good'] ,
|
||||
'sfp': ['sfp_is_present', 'sfp_tx_disable']}
|
||||
|
||||
sfp_map = [18,19,20,21,22,23,24,25,26,27,
|
||||
28,29,30,31,32,33,34,35,36,37,
|
||||
38,39,40,41,42,43,44,45,46,47,
|
||||
48,49,50,51,52,53,54,55,56,57,
|
||||
58,59,60,61,62,63,64,65,66,67,
|
||||
68,69,70,71]
|
||||
i2c_bus = {
|
||||
'fan': ['2-0066'],
|
||||
'thermal': ['3-0048', '3-0049', '3-004a', '3-004b'],
|
||||
'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': ['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,
|
||||
38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
||||
48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
|
||||
58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
|
||||
68, 69, 70, 71]
|
||||
|
||||
qsfp_start = 48
|
||||
|
||||
mknod =[
|
||||
'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-0/new_device',
|
||||
'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-0/new_device' ,
|
||||
'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-1/new_device' ,
|
||||
'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-1/new_device' ,
|
||||
'echo pca9548 0x74 > /sys/bus/i2c/devices/i2c-1/new_device',
|
||||
'echo pca9548 0x75 > /sys/bus/i2c/devices/i2c-1/new_device',
|
||||
'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',
|
||||
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']
|
||||
|
||||
'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',
|
||||
'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-1/new_device',
|
||||
'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-1/new_device',
|
||||
'echo pca9548 0x74 > /sys/bus/i2c/devices/i2c-1/new_device',
|
||||
'echo pca9548 0x75 > /sys/bus/i2c/devices/i2c-1/new_device',
|
||||
'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',]
|
||||
mknod = mknod + mknod_common
|
||||
|
||||
mknod2 =[
|
||||
'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-1/new_device',
|
||||
'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-1/new_device' ,
|
||||
'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-0/new_device' ,
|
||||
'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-0/new_device' ,
|
||||
'echo pca9548 0x74 > /sys/bus/i2c/devices/i2c-0/new_device',
|
||||
'echo pca9548 0x75 > /sys/bus/i2c/devices/i2c-0/new_device',
|
||||
'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',
|
||||
mknod2 = [
|
||||
'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-1/new_device',
|
||||
'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-1/new_device',
|
||||
'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-0/new_device',
|
||||
'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-0/new_device',
|
||||
'echo pca9548 0x74 > /sys/bus/i2c/devices/i2c-0/new_device',
|
||||
'echo pca9548 0x75 > /sys/bus/i2c/devices/i2c-0/new_device',
|
||||
'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']
|
||||
mknod2 = mknod2 + mknod_common
|
||||
|
||||
|
||||
|
||||
def i2c_order_check():
|
||||
|
||||
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)):
|
||||
#for pca954x need times to built new i2c buses
|
||||
# if 0x70 is not exist @i2c-1, use reversed bus order
|
||||
if order:
|
||||
for i in range(0, len(mknod2)):
|
||||
# for pca954x need times to built new i2c buses
|
||||
if mknod2[i].find('pca954') != -1:
|
||||
time.sleep(1)
|
||||
|
||||
status, output = log_os_system(mknod2[i], 1)
|
||||
time.sleep(1)
|
||||
|
||||
(status, output) = log_os_system(mknod2[i], 1)
|
||||
if status:
|
||||
print output
|
||||
if FORCE == 0:
|
||||
return status
|
||||
return status
|
||||
else:
|
||||
for i in range(0,len(mknod)):
|
||||
#for pca954x need times to built new i2c buses
|
||||
for i in range(0, len(mknod)):
|
||||
# for pca954x need times to built new i2c buses
|
||||
if mknod[i].find('pca954') != -1:
|
||||
time.sleep(1)
|
||||
|
||||
status, output = log_os_system(mknod[i], 1)
|
||||
time.sleep(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 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:
|
||||
return status
|
||||
return
|
||||
|
||||
if FORCE == 0:
|
||||
return status
|
||||
return
|
||||
|
||||
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)
|
||||
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)
|
||||
if status:
|
||||
print output
|
||||
if FORCE == 0:
|
||||
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)]
|
||||
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:
|
||||
return status
|
||||
|
||||
return
|
||||
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
return
|
||||
|
||||
|
||||
def system_ready():
|
||||
if driver_check() == False:
|
||||
if driver_check() is False:
|
||||
return False
|
||||
if not device_exist():
|
||||
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
|
||||
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...."
|
||||
status = device_install()
|
||||
print 'No device, installing....'
|
||||
status = device_install()
|
||||
if status:
|
||||
if FORCE == 0:
|
||||
return 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...."
|
||||
status = device_uninstall()
|
||||
if status:
|
||||
if FORCE == 0:
|
||||
return status
|
||||
|
||||
if driver_check()== False :
|
||||
print PROJECT_NAME.upper() +" has no driver installed...."
|
||||
print 'Removing device....'
|
||||
status = device_uninstall()
|
||||
if status and FORCE == 0:
|
||||
return status
|
||||
|
||||
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:
|
||||
return status
|
||||
|
||||
return
|
||||
if status and FORCE == 0:
|
||||
return status
|
||||
return None
|
||||
|
||||
|
||||
def devices_info():
|
||||
global DEVICE_NO
|
||||
global ALL_DEVICE
|
||||
global i2c_bus, hwmon_types
|
||||
for key in DEVICE_NO:
|
||||
ALL_DEVICE[key]= {}
|
||||
for i in range(0,DEVICE_NO[key]):
|
||||
ALL_DEVICE[key][key+str(i+1)] = []
|
||||
|
||||
for key in DEVICE_NO:
|
||||
ALL_DEVICE[key] = {}
|
||||
for i in range(0, DEVICE_NO[key]):
|
||||
ALL_DEVICE[key][key + str(i + 1)] = []
|
||||
|
||||
for key in i2c_bus:
|
||||
buses = i2c_bus[key]
|
||||
nodes = i2c_nodes[key]
|
||||
for i in range(0,len(buses)):
|
||||
for j in range(0,len(nodes)):
|
||||
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)
|
||||
ALL_DEVICE[key][node].append(path)
|
||||
elif 'sfp' == key:
|
||||
for k in range(0,DEVICE_NO[key]):
|
||||
node = key+str(k+1)
|
||||
path = i2c_prefix+ str(sfp_map[k])+ buses[i]+"/"+ nodes[j]
|
||||
my_log(node+": "+ path)
|
||||
ALL_DEVICE[key][node].append(path)
|
||||
nodes = i2c_nodes[key]
|
||||
for i in range(0, len(buses)):
|
||||
for j in range(0, len(nodes)):
|
||||
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)
|
||||
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 = 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)
|
||||
ALL_DEVICE[key][node].append(path)
|
||||
|
||||
node = key + str(i + 1)
|
||||
path = i2c_prefix + buses[i] + '/' + nodes[j]
|
||||
my_log(node + ': ' + path)
|
||||
ALL_DEVICE[key][node].append(path)
|
||||
|
||||
for key in hwmon_types:
|
||||
itypes = hwmon_types[key]
|
||||
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)
|
||||
ALL_DEVICE[key][ key+str(i+1)].append(path)
|
||||
|
||||
#show dict all in the order
|
||||
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)
|
||||
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+": ")
|
||||
for j in sorted(ALL_DEVICE[i].keys()):
|
||||
print(" "+j)
|
||||
for k in (ALL_DEVICE[i][j]):
|
||||
print(" "+" "+k)
|
||||
return
|
||||
|
||||
print i + ': '
|
||||
for j in sorted(ALL_DEVICE[i].keys()):
|
||||
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!")
|
||||
return
|
||||
|
||||
if len(ALL_DEVICE)==0:
|
||||
devices_info()
|
||||
node = ALL_DEVICE['sfp'] ['sfp'+str(index)][0]
|
||||
node = node.replace(node.split("/")[-1], 'sfp_eeprom')
|
||||
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')
|
||||
|
||||
# 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!!'
|
||||
logging.info(log)
|
||||
print log
|
||||
return 1
|
||||
|
||||
print node + ":"
|
||||
ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1)
|
||||
if ret==0:
|
||||
print log
|
||||
return 1
|
||||
|
||||
print node + ':'
|
||||
(ret, log) = log_os_system('cat ' + node + '| ' + hex_cmd + ' -C',
|
||||
1)
|
||||
if ret == 0:
|
||||
print log
|
||||
else:
|
||||
print "**********device no found**********"
|
||||
return
|
||||
|
||||
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!")
|
||||
return
|
||||
|
||||
if len(ALL_DEVICE)==0:
|
||||
devices_info()
|
||||
|
||||
if args[0]=='led':
|
||||
if int(args[1])>4:
|
||||
if system_ready() is False:
|
||||
print "System's not ready."
|
||||
print 'Please install first!'
|
||||
return
|
||||
|
||||
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
|
||||
elif args[0]=='fan':
|
||||
if int(args[1])>100:
|
||||
|
||||
# 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_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)
|
||||
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 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)
|
||||
if ret == 0:
|
||||
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:
|
||||
show_set_help()
|
||||
return
|
||||
if len(args)<2:
|
||||
show_set_help()
|
||||
return
|
||||
|
||||
if int(args[2])>1:
|
||||
elif args[0] == 'sfp':
|
||||
if int(args[1]) > qsfp_start or int(args[1]) == 0:
|
||||
show_set_help()
|
||||
return
|
||||
|
||||
#print ALL_DEVICE[args[0]]
|
||||
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
|
||||
|
||||
if len(args) < 2:
|
||||
show_set_help()
|
||||
return
|
||||
|
||||
if int(args[2]) > 1:
|
||||
show_set_help()
|
||||
return
|
||||
|
||||
# print 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_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)
|
||||
|
||||
|
||||
# get digits inside a string.
|
||||
# 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!")
|
||||
return
|
||||
|
||||
if len(ALL_DEVICE)==0:
|
||||
if system_ready() is False:
|
||||
print "System's not ready."
|
||||
print 'Please install first!'
|
||||
return
|
||||
|
||||
if not ALL_DEVICE:
|
||||
devices_info()
|
||||
for i in sorted(ALL_DEVICE.keys()):
|
||||
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()
|
||||
func = re.sub(j+'_','',func,1)
|
||||
func = re.sub(i.lower()+'_','',func,1)
|
||||
if ret==0:
|
||||
print func+"="+log+" ",
|
||||
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()
|
||||
func = re.sub(j + '_', '', func, 1)
|
||||
func = re.sub(i.lower() + '_', '', func, 1)
|
||||
if ret == 0:
|
||||
print func + '=' + log + ' ',
|
||||
else:
|
||||
print func+"="+"X"+" ",
|
||||
print
|
||||
print("----------------------------------------------------------------")
|
||||
|
||||
|
||||
print func + '=' + 'X' + ' ',
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user