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

View File

@ -80,7 +80,6 @@ i2c_nodes = {
'sfp': ['sfp_is_present ', 'sfp_tx_disable']} 'sfp': ['sfp_is_present ', 'sfp_tx_disable']}
QSFP_START = 48 QSFP_START = 48
I2C_BUS_ORDER = -1
sfp_map = [2, 3, 4, 5, 6, 7, 8, 9, 10, sfp_map = [2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
@ -241,7 +240,7 @@ def log_os_system(cmd, show):
return status, output return status, output
def driver_inserted(): 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) logging.info('mods:'+lsmod)
if len(lsmod) ==0: if len(lsmod) ==0:
return False return False
@ -293,34 +292,23 @@ def driver_uninstall():
def i2c_order_check(): def i2c_order_check():
# i2c bus 0 and 1 might be installed in different order. # i2c bus 0 and 1 might be installed in different order.
# Here check if 0x70 is exist @ i2c-0 # Here check if 0x70 is exist @ i2c-0
tmp = "echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device" tmp = "i2cget -y -f 0 0x70"
log_os_system(tmp, 0) ret = log_os_system(tmp, 0)
if not device_exist(): if not ret[0]:
order = 1 order = 1
else: else:
order = 0 order = 0
tmp = "echo 0x70 > /sys/bus/i2c/devices/i2c-1/delete_device" m = "[%s]Detected I2C_BUS_ORDER:%d" % (os.path.basename(__file__), order)
log_os_system(tmp, 0) my_log(m)
return order 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(): def get_i2c_order():
global I2C_BUS_ORDER return i2c_order_check()
if I2C_BUS_ORDER < 0:
update_i2c_order()
def device_install(): def device_install():
global FORCE global FORCE
global I2C_BUS_ORDER
update_i2c_order() order = get_i2c_order()
order = I2C_BUS_ORDER
# if 0x76 is not exist @i2c-0, use reversed bus order # if 0x76 is not exist @i2c-0, use reversed bus order
if order: if order:
for i in range(0,len(mknod2)): for i in range(0,len(mknod2)):
@ -344,7 +332,7 @@ def device_install():
print output print output
if FORCE == 0: if FORCE == 0:
return status return status
for i in range(0,len(sfp_map)): for i in range(0,len(sfp_map)):
if i < QSFP_START: 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)
@ -359,7 +347,7 @@ def device_install():
print output print output
if FORCE == 0: if FORCE == 0:
return status return status
return return
def device_uninstall(): def device_uninstall():
@ -372,8 +360,8 @@ def device_uninstall():
print output print output
if FORCE == 0: if FORCE == 0:
return status 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: if order == 0:
nodelist = mknod nodelist = mknod
else: else:
@ -526,19 +514,15 @@ def show_eeprom(index):
def get_cpld_path(index): def get_cpld_path(index):
global I2C_BUS_ORDER order = get_i2c_order()
if order !=0 :
if I2C_BUS_ORDER < 0:
get_i2c_order()
if I2C_BUS_ORDER !=0 :
return port_cpld_path[index].replace("0-", "1-") return port_cpld_path[index].replace("0-", "1-")
else: else:
return port_cpld_path[index] return port_cpld_path[index]
def cpld_path_of_port(port_index): def cpld_path_of_port(port_index):
if port_index < 1 and port_index > DEVICE_NO['sfp']: if port_index < 1 and port_index > DEVICE_NO['sfp']:
return None return None
if port_index < 25: if port_index < 25:
return get_cpld_path(0) return get_cpld_path(0)
else: else:
@ -550,7 +534,7 @@ def get_path_sfp_tx_dis(port_index):
return False, '' return False, ''
else: else:
dev = cpld_p+"module_tx_disable_"+str(port_index) dev = cpld_p+"module_tx_disable_"+str(port_index)
return True, dev return True, dev
def get_path_sfp_presence(port_index): def get_path_sfp_presence(port_index):
cpld_p = cpld_path_of_port(port_index) cpld_p = cpld_path_of_port(port_index)
@ -558,7 +542,7 @@ def get_path_sfp_presence(port_index):
return False, '' return False, ''
else: else:
dev = cpld_p+"module_present_"+str(port_index) dev = cpld_p+"module_present_"+str(port_index)
return True, dev return True, dev
def set_device(args): def set_device(args):
@ -635,7 +619,7 @@ def print_1_device_traversal(i, j, k):
return func+"="+log+" " return func+"="+log+" "
else: else:
return func+"="+"X"+" " return func+"="+"X"+" "
def device_traversal(): def device_traversal():
if system_ready()==False: if system_ready()==False:
print("System's not ready.") print("System's not ready.")
@ -659,18 +643,18 @@ def device_traversal():
if ret == False: if ret == False:
continue continue
log = print_1_device_traversal(i, j, k) log = print_1_device_traversal(i, j, k)
print log, print log,
if k.find('present')!= -1: if k.find('present')!= -1:
ret, k = get_path_sfp_presence(port_index) ret, k = get_path_sfp_presence(port_index)
if ret == False: if ret == False:
continue continue
log = print_1_device_traversal(i, j, k) log = print_1_device_traversal(i, j, k)
print log, print log,
else: else:
for k in (ALL_DEVICE[i][j]): for k in (ALL_DEVICE[i][j]):
log = print_1_device_traversal(i, j, k) log = print_1_device_traversal(i, j, k)
print log, print log,
print print
print("----------------------------------------------------------------") print("----------------------------------------------------------------")

View File

@ -21,13 +21,13 @@ Usage: %(scriptName)s [options] command object
options: options:
-h | --help : this help message -h | --help : this help message
-d | --debug : run with debug mode -d | --debug : run with debug mode
-f | --force : ignore error during installation or clean -f | --force : ignore error during installation or clean
command: command:
install : install drivers and generate related sysfs nodes install : install drivers and generate related sysfs nodes
clean : uninstall drivers and remove related sysfs nodes clean : uninstall drivers and remove related sysfs nodes
show : show all systen status show : show all systen status
sff : dump SFP eeprom sff : dump SFP eeprom
set : change board setting with fan|led|sfp set : change board setting with fan|led|sfp
""" """
import commands import commands
@ -45,7 +45,7 @@ version = '0.1.0'
verbose = False verbose = False
DEBUG = False DEBUG = False
args = [] args = []
ALL_DEVICE = {} ALL_DEVICE = {}
DEVICE_NO = {'led':5, 'fan':5,'thermal':4, 'psu':2, 'sfp':54} DEVICE_NO = {'led':5, 'fan':5,'thermal':4, 'psu':2, 'sfp':54}
FORCE = 0 FORCE = 0
#logging.basicConfig(filename= PROJECT_NAME+'.log', filemode='w',level=logging.DEBUG) #logging.basicConfig(filename= PROJECT_NAME+'.log', filemode='w',level=logging.DEBUG)
@ -54,37 +54,37 @@ FORCE = 0
if DEBUG == True: if DEBUG == True:
print sys.argv[0] print sys.argv[0]
print 'ARGV :', sys.argv[1:] print 'ARGV :', sys.argv[1:]
def main(): def main():
global DEBUG global DEBUG
global args global args
global FORCE global FORCE
if len(sys.argv)<2: if len(sys.argv)<2:
show_help() show_help()
options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help', options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help',
'debug', 'debug',
'force', 'force',
]) ])
if DEBUG == True: if DEBUG == True:
print options print options
print args print args
print len(sys.argv) print len(sys.argv)
for opt, arg in options: for opt, arg in options:
if opt in ('-h', '--help'): if opt in ('-h', '--help'):
show_help() show_help()
elif opt in ('-d', '--debug'): elif opt in ('-d', '--debug'):
DEBUG = True DEBUG = True
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
elif opt in ('-f', '--force'): elif opt in ('-f', '--force'):
FORCE = 1 FORCE = 1
else: else:
logging.info('no option') logging.info('no option')
for arg in args: for arg in args:
if arg == 'install': if arg == 'install':
do_install() do_install()
elif arg == 'clean': elif arg == 'clean':
@ -94,23 +94,23 @@ def main():
elif arg == 'sff': elif arg == 'sff':
if len(args)!=2: if len(args)!=2:
show_eeprom_help() 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() show_eeprom_help()
else: else:
show_eeprom(args[1]) show_eeprom(args[1])
return return
elif arg == 'set': elif arg == 'set':
if len(args)<3: if len(args)<3:
show_set_help() show_set_help()
else: else:
set_device(args[1:]) set_device(args[1:])
return return
else: else:
show_help() show_help()
return 0 return 0
def show_help(): def show_help():
print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]} print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]}
sys.exit(0) sys.exit(0)
@ -119,36 +119,36 @@ def show_set_help():
cmd = sys.argv[0].split("/")[-1]+ " " + args[0] cmd = sys.argv[0].split("/")[-1]+ " " + args[0]
print cmd +" [led|sfp|fan]" print cmd +" [led|sfp|fan]"
print " use \""+ cmd + " led 0-4 \" to set led color" print " use \""+ cmd + " led 0-4 \" to set led color"
print " use \""+ cmd + " fan 0-100\" to set fan duty percetage" 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) sys.exit(0)
def show_eeprom_help(): def show_eeprom_help():
cmd = sys.argv[0].split("/")[-1]+ " " + args[0] cmd = sys.argv[0].split("/")[-1]+ " " + args[0]
print " use \""+ cmd + " 1-54 \" to dump sfp# eeprom" print " use \""+ cmd + " 1-54 \" to dump sfp# eeprom"
sys.exit(0) sys.exit(0)
def my_log(txt): def my_log(txt):
if DEBUG == True: if DEBUG == True:
print "[Debug]"+txt print "[Debug]"+txt
return return
def log_os_system(cmd, show): def log_os_system(cmd, show):
logging.info('Run :'+cmd) logging.info('Run :'+cmd)
status, output = commands.getstatusoutput(cmd) status, output = commands.getstatusoutput(cmd)
my_log (cmd +"with result:" + str(status)) my_log (cmd +"with result:" + str(status))
my_log (" output:"+output) my_log (" output:"+output)
if status: if status:
logging.info('Failed :'+cmd) logging.info('Failed :'+cmd)
if show: if show:
print('Failed :'+cmd) print('Failed :'+cmd)
return status, output return status, output
def driver_check(): 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) logging.info('mods:'+lsmod)
if len(lsmod) ==0: if len(lsmod) ==0:
return False return False
return True return True
@ -165,30 +165,30 @@ kos = [
def driver_install(): def driver_install():
global FORCE global FORCE
status, output = log_os_system("depmod", 1) log_os_system("depmod", 1)
for i in range(0,len(kos)): for i in range(0,len(kos)):
status, output = log_os_system(kos[i], 1) ret = log_os_system(kos[i], 1)
if status: if ret[0]:
if FORCE == 0: if FORCE == 0:
return status return ret[0]
return 0 return 0
def driver_uninstall(): def driver_uninstall():
global FORCE global FORCE
for i in range(0,len(kos)): for i in range(0,len(kos)):
rm = kos[-(i+1)].replace("modprobe", "modprobe -rq") rm = kos[-(i+1)].replace("modprobe", "modprobe -rq")
rm = rm.replace("insmod", "rmmod") rm = rm.replace("insmod", "rmmod")
lst = rm.split(" ") lst = rm.split(" ")
if len(lst) > 3: if len(lst) > 3:
del(lst[3]) del(lst[3])
rm = " ".join(lst) rm = " ".join(lst)
status, output = log_os_system(rm, 1) ret = log_os_system(rm, 1)
if status: if ret[0]:
if FORCE == 0: if FORCE == 0:
return status return ret[0]
return 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_types = {'led': ['diag','fan','loc','psu1','psu2']}
hwmon_nodes = {'led': ['brightness'] } hwmon_nodes = {'led': ['brightness'] }
hwmon_prefix ={'led': led_prefix} hwmon_prefix ={'led': led_prefix}
@ -196,13 +196,13 @@ hwmon_prefix ={'led': led_prefix}
i2c_prefix = '/sys/bus/i2c/devices/' i2c_prefix = '/sys/bus/i2c/devices/'
i2c_bus = {'fan': ['3-0063'] , i2c_bus = {'fan': ['3-0063'] ,
'thermal': ['18-004b','19-004c', '20-0049', '21-004a'] , 'thermal': ['18-004b','19-004c', '20-0049', '21-004a'] ,
'psu': ['11-0050','12-0053'], 'psu': ['11-0050','12-0053'],
'sfp': ['-0050']} 'sfp': ['-0050']}
i2c_nodes = {'fan': ['present', 'front_speed_rpm', 'rear_speed_rpm'] , i2c_nodes = {'fan': ['present', 'front_speed_rpm', 'rear_speed_rpm'] ,
'thermal': ['hwmon/hwmon*/temp1_input'] , 'thermal': ['hwmon/hwmon*/temp1_input'] ,
'psu': ['psu_present ', 'psu_power_good'] , 'psu': ['psu_present ', 'psu_power_good'] ,
'sfp': ['module_present_', 'module_tx_disable_']} 'sfp': ['module_present_', 'module_tx_disable_']}
sfp_map = [42,43,44,45,46,47,48,49,50,51, sfp_map = [42,43,44,45,46,47,48,49,50,51,
52,53,54,55,56,57,58,59,60,61, 52,53,54,55,56,57,58,59,60,61,
62,63,64,65,66,67,68,69,70,71, 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)), cpld_of_module = {'3-0061': list(range(0,38)),
'3-0062': list(range(38,54)) } '3-0062': list(range(38,54)) }
mknod =[ mknod =[
'echo pca9548 0x77 > /sys/bus/i2c/devices/i2c-1/new_device', 'echo pca9548 0x77 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-2/new_device' , 'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-2/new_device' ,
'echo pca9548 0x71 > /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_cpld2 0x61 > /sys/bus/i2c/devices/i2c-3/new_device',
'echo as5835_54x_cpld3 0x62 > /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 0x77 > /sys/bus/i2c/devices/i2c-0/new_device',
'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-2/new_device' , 'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-2/new_device' ,
'echo pca9548 0x71 > /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_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_cpld2 0x61 > /sys/bus/i2c/devices/i2c-3/new_device',
'echo as5835_54x_cpld3 0x62 > /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. # i2c bus 0 and 1 might be installed in different order.
# Here check if 0x77 is exist @ i2c-1 # Here check if 0x77 is exist @ i2c-1
tmp = "echo pca9548 0x77 > /sys/bus/i2c/devices/i2c-1/new_device" tmp = "i2cget -y -f 0 0x77"
status, output = log_os_system(tmp, 0) ret = log_os_system(tmp, 0)
if not device_exist(): if not ret[0]:
order = 1 order = 1
else: else:
order = 0 order = 0
tmp = "echo 0x77 > /sys/bus/i2c/devices/i2c-1/delete_device"
status, output = log_os_system(tmp, 0)
return order return order
def device_install(): def device_install():
global FORCE global FORCE
order = i2c_order_check() order = i2c_order_check()
# if 0x77 is not exist @i2c-1, use reversed bus order # if 0x77 is not exist @i2c-1, use reversed bus order
if order: if order:
for i in range(0,len(mknod2)): 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: if mknod2[i].find('pca954') != -1:
time.sleep(1) time.sleep(1)
status, output = log_os_system(mknod2[i], 1) status, output = log_os_system(mknod2[i], 1)
time.sleep(0.01) time.sleep(0.01)
if status: if status:
print output print output
if FORCE == 0: if FORCE == 0:
return status return status
else: else:
for i in range(0,len(mknod)): 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: if mknod[i].find('pca954') != -1:
time.sleep(1) time.sleep(1)
status, output = log_os_system(mknod[i], 1) status, output = log_os_system(mknod[i], 1)
if status: if status:
print output print output
if FORCE == 0: if FORCE == 0:
return status return status
for i in range(49, 55): #Set qsfp port to normal state 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)): for i in range(0,len(sfp_map)):
if i < qsfp_start: 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)
@ -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) status, output =log_os_system("echo optoe1 0x50 > /sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/new_device", 1)
if status: if status:
print output print output
if FORCE == 0: if FORCE == 0:
return status return status
return return
def device_uninstall(): def device_uninstall():
global FORCE 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)): for i in range(0,len(sfp_map)):
target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device" target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device"
status, output =log_os_system("echo 0x50 > "+ target, 1) status, output =log_os_system("echo 0x50 > "+ target, 1)
if status: if status:
print output print output
if FORCE == 0: if FORCE == 0:
return status return status
if I2C_ORDER==0: order = i2c_order_check()
nodelist = mknod if order:
else:
nodelist = mknod2 nodelist = mknod2
else:
nodelist = mknod
for i in range(len(nodelist)): for i in range(len(nodelist)):
target = nodelist[-(i+1)] target = nodelist[-(i+1)]
temp = target.split() temp = target.split()
@ -358,72 +351,72 @@ def device_uninstall():
status, output = log_os_system(" ".join(temp), 1) status, output = log_os_system(" ".join(temp), 1)
if status: if status:
print output print output
if FORCE == 0: if FORCE == 0:
return status return status
return return
def system_ready(): def system_ready():
if driver_check() == False: if driver_check() == False:
return False return False
if not device_exist(): if not device_exist():
return False return False
return True return True
def do_install(): def do_install():
print "Checking system...." print "Checking system...."
if driver_check() == False: if driver_check() == False:
print "No driver, installing...." print "No driver, installing...."
status = driver_install() status = driver_install()
if status: if status:
if FORCE == 0: if FORCE == 0:
return status return status
else: else:
print PROJECT_NAME.upper()+" drivers detected...." print PROJECT_NAME.upper()+" drivers detected...."
if not device_exist(): if not device_exist():
print "No device, installing...." print "No device, installing...."
status = device_install() status = device_install()
if status: if status:
if FORCE == 0: if FORCE == 0:
return status return status
else: else:
print PROJECT_NAME.upper()+" devices detected...." print PROJECT_NAME.upper()+" devices detected...."
return return
def do_uninstall(): def do_uninstall():
print "Checking system...." print "Checking system...."
if not device_exist(): if not device_exist():
print PROJECT_NAME.upper() +" has no device installed...." print PROJECT_NAME.upper() +" has no device installed...."
else: else:
print "Removing device...." print "Removing device...."
status = device_uninstall() status = device_uninstall()
if status: if status:
if FORCE == 0: if FORCE == 0:
return status return status
if driver_check()== False : if driver_check()== False :
print PROJECT_NAME.upper() +" has no driver installed...." print PROJECT_NAME.upper() +" has no driver installed...."
else: else:
print "Removing installed driver...." print "Removing installed driver...."
status = driver_uninstall() status = driver_uninstall()
if status: if status:
if FORCE == 0: if FORCE == 0:
return status return status
return return
def devices_info(): def devices_info():
global DEVICE_NO global DEVICE_NO
global ALL_DEVICE global ALL_DEVICE
global i2c_bus, hwmon_types global i2c_bus, hwmon_types
for key in DEVICE_NO: for key in DEVICE_NO:
ALL_DEVICE[key]= {} ALL_DEVICE[key]= {}
for i in range(0,DEVICE_NO[key]): for i in range(0,DEVICE_NO[key]):
ALL_DEVICE[key][key+str(i+1)] = [] ALL_DEVICE[key][key+str(i+1)] = []
for key in i2c_bus: for key in i2c_bus:
buses = i2c_bus[key] buses = i2c_bus[key]
nodes = i2c_nodes[key] nodes = i2c_nodes[key]
for i in range(0,len(buses)): for i in range(0,len(buses)):
for j in range(0,len(nodes)): for j in range(0,len(nodes)):
if 'fan' == key: if 'fan' == key:
@ -431,7 +424,7 @@ def devices_info():
node = key+str(k+1) node = key+str(k+1)
path = i2c_prefix+ buses[i]+"/fan"+str(k+1)+"_"+ nodes[j] path = i2c_prefix+ buses[i]+"/fan"+str(k+1)+"_"+ nodes[j]
my_log(node+": "+ path) my_log(node+": "+ path)
ALL_DEVICE[key][node].append(path) ALL_DEVICE[key][node].append(path)
elif 'sfp' == key: elif 'sfp' == key:
for k in range(0,DEVICE_NO[key]): for k in range(0,DEVICE_NO[key]):
for lk in cpld_of_module: for lk in cpld_of_module:
@ -442,160 +435,160 @@ def devices_info():
ALL_DEVICE[key][node].append(path) ALL_DEVICE[key][node].append(path)
else: else:
node = key+str(i+1) node = key+str(i+1)
path = i2c_prefix+ buses[i]+"/"+ nodes[j] path = i2c_prefix+ buses[i]+"/"+ nodes[j]
my_log(node+": "+ path) my_log(node+": "+ path)
ALL_DEVICE[key][node].append(path) ALL_DEVICE[key][node].append(path)
for key in hwmon_types: for key in hwmon_types:
itypes = hwmon_types[key] itypes = hwmon_types[key]
nodes = hwmon_nodes[key] nodes = hwmon_nodes[key]
for i in range(0,len(itypes)): 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] node = key+"_"+itypes[i]
path = hwmon_prefix[key]+ itypes[i]+"/"+ nodes[j] path = hwmon_prefix[key]+ itypes[i]+"/"+ nodes[j]
my_log(node+": "+ path) 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 #show dict all in the order
if DEBUG == True: if DEBUG == True:
for i in sorted(ALL_DEVICE.keys()): for i in sorted(ALL_DEVICE.keys()):
print(i+": ") print(i+": ")
for j in sorted(ALL_DEVICE[i].keys()): for j in sorted(ALL_DEVICE[i].keys()):
print(" "+j) print(" "+j)
for k in (ALL_DEVICE[i][j]): for k in (ALL_DEVICE[i][j]):
print(" "+" "+k) print(" "+" "+k)
return return
def show_eeprom(index): def show_eeprom(index):
if system_ready()==False: if system_ready()==False:
print("System's not ready.") print("System's not ready.")
print("Please install first!") print("Please install first!")
return return
if len(ALL_DEVICE)==0: if len(ALL_DEVICE)==0:
devices_info() devices_info()
node = ALL_DEVICE['sfp'] ['sfp'+str(index)][0] 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 # check if got hexdump command in current environment
ret, log = log_os_system("which hexdump", 0) ret, log = log_os_system("which hexdump", 0)
ret, log2 = log_os_system("which busybox hexdump", 0) ret, log2 = log_os_system("which busybox hexdump", 0)
if len(log): if log :
hex_cmd = 'hexdump' hex_cmd = 'hexdump'
elif len(log2): elif log2 :
hex_cmd = ' busybox hexdump' hex_cmd = ' busybox hexdump'
else: else:
log = 'Failed : no hexdump cmd!!' log = 'Failed : no hexdump cmd!!'
logging.info(log) logging.info(log)
print log print log
return 1 return 1
print node + ":" print node + ":"
ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1) ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1)
if ret==0: if ret==0:
print log print log
else: else:
print "**********device no found**********" print "**********device no found**********"
return return
def set_device(args): def set_device(args):
global DEVICE_NO global DEVICE_NO
global ALL_DEVICE global ALL_DEVICE
if system_ready()==False: if system_ready()==False:
print("System's not ready.") print("System's not ready.")
print("Please install first!") print("Please install first!")
return return
if len(ALL_DEVICE)==0: if len(ALL_DEVICE)==0:
devices_info() devices_info()
if args[0]=='led': if args[0]=='led':
if int(args[1])>4: if int(args[1])>4:
show_set_help() show_set_help()
return return
#print ALL_DEVICE['led'] #print ALL_DEVICE['led']
for i in range(0,len(ALL_DEVICE['led'])): for i in range(0,len(ALL_DEVICE['led'])):
for k in (ALL_DEVICE['led']['led'+str(i+1)]): for k in (ALL_DEVICE['led']['led'+str(i+1)]):
ret, log = log_os_system("echo "+args[1]+" >"+k, 1) ret = log_os_system("echo "+args[1]+" >"+k, 1)
if ret: if ret[0]:
return ret return ret[0]
elif args[0]=='fan': elif args[0]=='fan':
if int(args[1])>100: if int(args[1])>100:
show_set_help() show_set_help()
return return
#print ALL_DEVICE['fan'] #print ALL_DEVICE['fan']
#fan1~5 is all fine, all fan share same setting #fan1~5 is all fine, all fan share same setting
node = ALL_DEVICE['fan'] ['fan1'][0] node = ALL_DEVICE['fan'] ['fan1'][0]
node = node.replace(node.split("/")[-1], 'fan_duty_cycle_percentage') node = node.replace(node.split("/")[-1], 'fan_duty_cycle_percentage')
ret, log = log_os_system("cat "+ node, 1) ret = log_os_system("cat "+ node, 1)
if ret==0: if ret[0] == 0:
print ("Previous fan duty: " + log.strip() +"%") print ("Previous fan duty: " + log.strip() +"%")
ret, log = log_os_system("echo "+args[1]+" >"+node, 1) ret = log_os_system("echo "+args[1]+" >"+node, 1)
if ret==0: if ret[0] == 0:
print ("Current fan duty: " + args[1] +"%") print ("Current fan duty: " + args[1] +"%")
return ret return ret[0]
elif args[0]=='sfp': 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() show_set_help()
return return
if len(args)<2: if len(args)<2:
show_set_help() show_set_help()
return return
if int(args[2])>1: if int(args[2])>1:
show_set_help() show_set_help()
return return
#print ALL_DEVICE[args[0]] #print ALL_DEVICE[args[0]]
for i in range(0,len(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])]: for j in ALL_DEVICE[args[0]][args[0]+str(args[1])]:
if j.find('tx_disable')!= -1: if j.find('tx_disable')!= -1:
ret, log = log_os_system("echo "+args[2]+" >"+ j, 1) ret = log_os_system("echo "+args[2]+" >"+ j, 1)
if ret: if ret[0]:
return ret return ret[0]
return return
#get digits inside a string. #get digits inside a string.
#Ex: 31 for "sfp31" #Ex: 31 for "sfp31"
def get_value(input): def get_value(input):
digit = re.findall('\d+', input) digit = re.findall('\d+', input)
return int(digit[0]) return int(digit[0])
def device_traversal(): def device_traversal():
if system_ready()==False: if system_ready()==False:
print("System's not ready.") print("System's not ready.")
print("Please install first!") print("Please install first!")
return return
if len(ALL_DEVICE)==0: if len(ALL_DEVICE)==0:
devices_info() devices_info()
for i in sorted(ALL_DEVICE.keys()): for i in sorted(ALL_DEVICE.keys()):
print("============================================") print("============================================")
print(i.upper()+": ") print(i.upper()+": ")
print("============================================") 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+":", print " "+j+":",
for k in (ALL_DEVICE[i][j]): for k in (ALL_DEVICE[i][j]):
ret, log = log_os_system("cat "+k, 0) ret, log = log_os_system("cat "+k, 0)
func = k.split("/")[-1].strip() func = k.split("/")[-1].strip()
func = re.sub(j+'_','',func,1) func = re.sub(j+'_','',func,1)
func = re.sub(i.lower()+'_','',func,1) func = re.sub(i.lower()+'_','',func,1)
if ret==0: if ret==0:
print func+"="+log+" ", print func+"="+log+" ",
else: else:
print func+"="+"X"+" ", print func+"="+"X"+" ",
print print
print("----------------------------------------------------------------") print("----------------------------------------------------------------")
print print
return return
def device_exist(): def device_exist():
ret1, log = log_os_system("ls "+i2c_prefix+"*0077", 0) ret1 = log_os_system("ls "+i2c_prefix+"*0077", 0)
ret2, log = log_os_system("ls "+i2c_prefix+"i2c-2", 0) ret2 = log_os_system("ls "+i2c_prefix+"i2c-2", 0)
return not(ret1 or ret2) return not(ret1[0] or ret2[0])
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -100,26 +100,17 @@ class FanUtil(object):
return None return None
device_path = self.get_fan_to_device_path(fan_num, node_num) device_path = self.get_fan_to_device_path(fan_num, node_num)
try: 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: except IOError as e:
logging.error('GET. unable to open file: %s', str(e)) logging.error('GET. unable to read file: %s', str(e))
return None 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): 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: 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) device_path = self.get_fan_to_device_path(fan_num, node_num)
try: try:
val_file = open(device_path, 'w') with open(device_path, 'w') as val_file:
val_file.write(content)
except IOError as e: except IOError as e:
logging.error('GET. unable to open file: %s', str(e)) logging.error('GET. unable to open file: %s', str(e))
return None 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 return True
def __init__(self): def __init__(self):
@ -193,32 +176,20 @@ class FanUtil(object):
def get_fan_duty_cycle(self): def get_fan_duty_cycle(self):
#duty_path = self.FAN_DUTY_PATH #duty_path = self.FAN_DUTY_PATH
try: 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: except IOError as e:
print "Error: unable to open file: %s" % str(e) print "Error: unable to open file: %s" % str(e)
return False return False
content = val_file.readline().rstrip()
val_file.close()
return int(content) return int(content)
#self._get_fan_node_val(fan_num, self.FAN_NODE_DUTY_IDX_OF_MAP)
#static u32 reg_val_to_duty_cycle(u8 reg_val)
#{
# reg_val &= FAN_DUTY_CYCLE_REG_MASK;
# return ((u32)(reg_val+1) * 625 + 75)/ 100;
#}
#
def set_fan_duty_cycle(self, val): def set_fan_duty_cycle(self, val):
try: 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: except IOError as e:
print "Error: unable to open file: %s" % str(e) print "Error: unable to open file: %s" % str(e)
return False return False
#val = ((val + 1 ) * 625 +75 ) / 100
fan_file.write(str(val))
fan_file.close()
return True return True
#def get_fanr_fault(self, fan_num): #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) device_path = self.get_thermal_to_device_path(thermal_num)
for filename in glob.glob(device_path): for filename in glob.glob(device_path):
try: 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: except IOError as e:
logging.error('GET. unable to open file: %s', str(e)) logging.error('GET. unable to open file: %s', str(e))
return None
content = val_file.readline().rstrip() return None
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): def get_num_thermals(self):
return self.THERMAL_NUM_ON_MAIN_BROAD return self.THERMAL_NUM_ON_MAIN_BROAD

View File

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

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python
#
# Copyright (C) 2016 Accton Networks, Inc. # Copyright (C) 2016 Accton Networks, Inc.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
@ -21,13 +20,13 @@ Usage: %(scriptName)s [options] command object
options: options:
-h | --help : this help message -h | --help : this help message
-d | --debug : run with debug mode -d | --debug : run with debug mode
-f | --force : ignore error during installation or clean -f | --force : ignore error during installation or clean
command: command:
install : install drivers and generate related sysfs nodes install : install drivers and generate related sysfs nodes
clean : uninstall drivers and remove related sysfs nodes clean : uninstall drivers and remove related sysfs nodes
show : show all systen status show : show all systen status
sff : dump SFP eeprom sff : dump SFP eeprom
set : change board setting with fan|led|sfp set : change board setting with fan|led|sfp
""" """
import commands import commands
@ -38,550 +37,565 @@ import re
import time import time
PROJECT_NAME = 'as7312_54x' PROJECT_NAME = 'as7312_54x'
version = '0.1.0' version = '0.1.0'
verbose = False verbose = False
DEBUG = False DEBUG = False
args = [] ARGS = []
ALL_DEVICE = {} 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 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: if DEBUG == True:
print sys.argv[0] print sys.argv[0]
print 'ARGV :', sys.argv[1:] print 'ARGV :', sys.argv[1:]
def main(): def main():
global DEBUG global DEBUG
global args global ARGS
global FORCE global FORCE
if len(sys.argv)<2: if len(sys.argv) < 2:
show_help() show_help()
options, args = getopt.getopt(sys.argv[1:], 'hdf', ['help', (options, ARGS) = getopt.getopt(sys.argv[1:], 'hdf',
'debug', ['help','debug', 'force'])
'force', if DEBUG == True:
])
if DEBUG == True:
print options print options
print args print ARGS
print len(sys.argv) print len(sys.argv)
for opt, arg in options: for (opt, arg) in options:
if opt in ('-h', '--help'): if opt in ('-h', '--help'):
show_help() show_help()
elif opt in ('-d', '--debug'): elif opt in ('-d', '--debug'):
DEBUG = True DEBUG = True
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
elif opt in ('-f', '--force'): elif opt in ('-f', '--force'):
FORCE = 1 FORCE = 1
else: else:
logging.info('no option') logging.info('no option')
for arg in args: for arg in ARGS:
if arg == 'install': if arg == 'install':
do_install() do_install()
elif arg == 'clean': elif arg == 'clean':
do_uninstall() do_uninstall()
elif arg == 'show': elif arg == 'show':
device_traversal() device_traversal()
elif arg == 'sff': elif arg == 'sff':
if len(args)!=2: if len(ARGS) != 2:
show_eeprom_help() 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() show_eeprom_help()
else: else:
show_eeprom(args[1]) show_eeprom(ARGS[1])
return return
elif arg == 'set': elif arg == 'set':
if len(args)<3: if len(ARGS) < 3:
show_set_help() show_set_help()
else: else:
set_device(args[1:]) set_device(ARGS[1:])
return return
else: else:
show_help() show_help()
return 0
return 0
def show_help(): def show_help():
print __doc__ % {'scriptName' : sys.argv[0].split("/")[-1]} print __doc__ % {'scriptName': sys.argv[0].split('/')[-1]}
sys.exit(0) sys.exit(0)
def show_set_help():
cmd = sys.argv[0].split("/")[-1]+ " " + args[0] def show_set_help():
print cmd +" [led|sfp|fan]" cmd = sys.argv[0].split('/')[-1] + ' ' + ARGS[0]
print " use \""+ cmd + " led 0-4 \" to set led color" print cmd + ' [led|sfp|fan]'
print " use \""+ cmd + " fan 0-100\" to set fan duty percetage" print ' use "' + cmd + ' led 0-4 " to set led color'
print " use \""+ cmd + " sfp 1-54 {0|1}\" to set sfp# tx_disable" print ' use "' + cmd + ' fan 0-100" to set fan duty percetage'
sys.exit(0) 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" def show_eeprom_help():
sys.exit(0) cmd = sys.argv[0].split('/')[-1] + ' ' + ARGS[0]
print ' use "' + cmd + ' 1-54 " to dump sfp# eeprom'
sys.exit(0)
def my_log(txt): def my_log(txt):
if DEBUG == True: if DEBUG == True:
print "[ROY]"+txt print '[DBG]' + txt
return 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 = [ kos = [
'modprobe i2c_dev', 'modprobe i2c_dev',
'modprobe i2c_mux_pca954x force_deselect_on_exit=1', 'modprobe i2c_mux_pca954x force_deselect_on_exit=1',
'modprobe accton_i2c_cpld' , 'modprobe accton_i2c_cpld',
'modprobe ym2651y' , 'modprobe ym2651y',
'modprobe accton_as7312_54x_fan' , 'modprobe accton_as7312_54x_fan',
'modprobe optoe' , 'modprobe optoe',
'modprobe accton_as7312_54x_leds' , 'modprobe accton_as7312_54x_leds',
'modprobe accton_as7312_54x_psu' ] 'modprobe accton_as7312_54x_psu',
]
def driver_install(): def driver_install():
global FORCE global FORCE
status, output = log_os_system("depmod", 1) log_os_system('depmod', 1)
for i in range(0,len(kos)): for i in range(0, len(kos)):
status, output = log_os_system(kos[i], 1) ret = log_os_system(kos[i], 1)
if status: if ret[0] and FORCE == 0:
if FORCE == 0: return status
return status
return 0 return 0
def driver_uninstall(): def driver_uninstall():
global FORCE global FORCE
for i in range(0,len(kos)): for i in range(0, len(kos)):
rm = kos[-(i+1)].replace("modprobe", "modprobe -rq") rm = kos[-(i + 1)].replace('modprobe', 'modprobe -rq')
rm = rm.replace("insmod", "rmmod") rm = rm.replace('insmod', 'rmmod')
lst = rm.split(" ") lst = rm.split(' ')
if len(lst) > 3: if len(lst) > 3:
del(lst[3]) del lst[3]
rm = " ".join(lst) rm = ' '.join(lst)
status, output = log_os_system(rm, 1) ret = log_os_system(rm, 1)
if status: if ret[0] and FORCE == 0:
if FORCE == 0: return ret[0]
return status
return 0 return 0
led_prefix ='/sys/class/leds/accton_'+PROJECT_NAME+'_led::'
hwmon_types = {'led': ['diag','fan','loc','psu1','psu2']} led_prefix = '/sys/class/leds/accton_' + PROJECT_NAME + '_led::'
hwmon_nodes = {'led': ['brightness'] } hwmon_types = {'led': ['diag', 'fan', 'loc', 'psu1', 'psu2']}
hwmon_prefix ={'led': led_prefix} hwmon_nodes = {'led': ['brightness']}
hwmon_prefix = {'led': led_prefix}
i2c_prefix = '/sys/bus/i2c/devices/' i2c_prefix = '/sys/bus/i2c/devices/'
i2c_bus = {'fan': ['2-0066'] , i2c_bus = {
'thermal': ['3-0048','3-0049', '3-004a', '3-004b'] , 'fan': ['2-0066'],
'psu': ['10-0051','11-0053'], 'thermal': ['3-0048', '3-0049', '3-004a', '3-004b'],
'sfp': ['-0050']} 'psu': ['10-0050', '11-0053'],
i2c_nodes = {'fan': ['present', 'front_speed_rpm', 'rear_speed_rpm'] , 'sfp': ['-0050'],
'thermal': ['hwmon/hwmon*/temp1_input'] , }
'psu': ['psu_present ', 'psu_power_good'] , i2c_nodes = {
'sfp': ['sfp_is_present', 'sfp_tx_disable']} 'fan': ['present', 'front_speed_rpm', 'rear_speed_rpm'],
'thermal': ['hwmon/hwmon*/temp1_input'],
sfp_map = [18,19,20,21,22,23,24,25,26,27, 'psu': ['psu_present ', 'psu_power_good'],
28,29,30,31,32,33,34,35,36,37, 'sfp': ['module_present', 'module_tx_disable'],
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, sfp_map = [18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
68,69,70,71] 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 qsfp_start = 48
mknod =[ mknod_common = [
'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-0/new_device', 'echo as7312_54x_fan 0x66 > /sys/bus/i2c/devices/i2c-2/new_device ',
'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-0/new_device' , 'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-3/new_device',
'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-1/new_device' , 'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-3/new_device',
'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-1/new_device' , 'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-3/new_device',
'echo pca9548 0x74 > /sys/bus/i2c/devices/i2c-1/new_device', 'echo lm75 0x4b > /sys/bus/i2c/devices/i2c-3/new_device',
'echo pca9548 0x75 > /sys/bus/i2c/devices/i2c-1/new_device', 'echo as7312_54x_psu1 0x53 > /sys/bus/i2c/devices/i2c-11/new_device',
'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-1/new_device', 'echo ym2651 0x5b > /sys/bus/i2c/devices/i2c-11/new_device',
'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-1/new_device', 'echo as7312_54x_psu2 0x50 > /sys/bus/i2c/devices/i2c-10/new_device',
'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device', 'echo ym2651 0x58 > /sys/bus/i2c/devices/i2c-10/new_device',
'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-1/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 ', mknod = [
'echo lm75 0x48 > /sys/bus/i2c/devices/i2c-3/new_device', 'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-0/new_device',
'echo lm75 0x49 > /sys/bus/i2c/devices/i2c-3/new_device', 'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-0/new_device',
'echo lm75 0x4a > /sys/bus/i2c/devices/i2c-3/new_device', 'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo lm75 0x4b > /sys/bus/i2c/devices/i2c-3/new_device', 'echo pca9548 0x73 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo as7312_54x_psu1 0x53 > /sys/bus/i2c/devices/i2c-11/new_device', 'echo pca9548 0x74 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo ym2651 0x5b > /sys/bus/i2c/devices/i2c-11/new_device', 'echo pca9548 0x75 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo as7312_54x_psu2 0x50 > /sys/bus/i2c/devices/i2c-10/new_device', 'echo pca9548 0x76 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo ym2651 0x58 > /sys/bus/i2c/devices/i2c-10/new_device', 'echo pca9548 0x71 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo as7312_54x_cpld1 0x60 > /sys/bus/i2c/devices/i2c-4/new_device', 'echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo as7312_54x_cpld2 0x62 > /sys/bus/i2c/devices/i2c-5/new_device', 'echo 24c02 0x57 > /sys/bus/i2c/devices/i2c-1/new_device',]
'echo as7312_54x_cpld3 0x64 > /sys/bus/i2c/devices/i2c-6/new_device'] mknod = mknod + mknod_common
mknod2 =[ mknod2 = [
'echo pca9548 0x76 > /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 0x71 > /sys/bus/i2c/devices/i2c-1/new_device',
'echo pca9548 0x72 > /sys/bus/i2c/devices/i2c-0/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 0x73 > /sys/bus/i2c/devices/i2c-0/new_device',
'echo pca9548 0x74 > /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 0x75 > /sys/bus/i2c/devices/i2c-0/new_device',
'echo pca9548 0x76 > /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 0x71 > /sys/bus/i2c/devices/i2c-0/new_device',
'echo pca9548 0x70 > /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 24c02 0x57 > /sys/bus/i2c/devices/i2c-0/new_device',]
'echo as7312_54x_fan 0x66 > /sys/bus/i2c/devices/i2c-2/new_device ', mknod2 = mknod2 + mknod_common
'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']
def i2c_order_check():
def i2c_order_check():
# i2c bus 0 and 1 might be installed in different order. # i2c bus 0 and 1 might be installed in different order.
# Here check if 0x70 is exist @ i2c-1 # Here check if 0x70 is exist @ i2c-1
tmp = "echo pca9548 0x70 > /sys/bus/i2c/devices/i2c-1/new_device" tmp = "i2cget -y -f 0 0x70"
status, output = log_os_system(tmp, 0) ret = log_os_system(tmp, 0)
if not device_exist(): if not ret[0]:
order = 1 order = 1
else: else:
order = 0 order = 0
tmp = "echo 0x70 > /sys/bus/i2c/devices/i2c-1/delete_device"
status, output = log_os_system(tmp, 0)
return order return order
def device_install(): def device_install():
global FORCE global FORCE
order = i2c_order_check() order = i2c_order_check()
# if 0x70 is not exist @i2c-1, use reversed bus order
# if 0x70 is not exist @i2c-1, use reversed bus order if order:
if order: for i in range(0, len(mknod2)):
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: if mknod2[i].find('pca954') != -1:
time.sleep(1) time.sleep(1)
status, output = log_os_system(mknod2[i], 1) (status, output) = log_os_system(mknod2[i], 1)
if status: if status:
print output print output
if FORCE == 0: if FORCE == 0:
return status return status
else: else:
for i in range(0,len(mknod)): 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: if mknod[i].find('pca954') != -1:
time.sleep(1) time.sleep(1)
status, output = log_os_system(mknod[i], 1) (status, output) = log_os_system(mknod[i], 1)
if status: if status:
print output print output
if FORCE == 0: if FORCE == 0:
return status return status
for i in range(0,len(sfp_map)): for i in range(0, len(sfp_map)):
if i < qsfp_start: 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: 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: if status:
print output print output
if FORCE == 0: if FORCE == 0:
return status return status
return return
def device_uninstall(): def device_uninstall():
global FORCE 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)): for i in range(0, len(sfp_map)):
target = "/sys/bus/i2c/devices/i2c-"+str(sfp_map[i])+"/delete_device" target = '/sys/bus/i2c/devices/i2c-' + str(sfp_map[i]) \
status, output =log_os_system("echo 0x50 > "+ target, 1) + '/delete_device'
(status, output) = log_os_system('echo 0x50 > ' + target, 1)
if status: if status:
print output print output
if FORCE == 0: if FORCE == 0:
return status return status
if I2C_ORDER==0: order = i2c_order_check()
nodelist = mknod if order :
else:
nodelist = mknod2 nodelist = mknod2
else:
nodelist = mknod
for i in range(len(nodelist)): for i in range(len(nodelist)):
target = nodelist[-(i+1)] target = nodelist[-(i + 1)]
temp = target.split() temp = target.split()
del temp[1] del temp[1]
temp[-1] = temp[-1].replace('new_device', 'delete_device') 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: if status:
print output print output
if FORCE == 0: if FORCE == 0:
return status return status
return return
def system_ready(): def system_ready():
if driver_check() == False: if driver_check() is False:
return False return False
if not device_exist(): if not device_exist():
return False return False
return True return True
def do_install(): def do_install():
print "Checking system...." print 'Checking system....'
if driver_check() == False: if driver_check() is False:
print "No driver, installing...." print 'No driver, installing....'
status = driver_install() status = driver_install()
if status: if status:
if FORCE == 0: if FORCE == 0:
return status return status
else: else:
print PROJECT_NAME.upper()+" drivers detected...." print PROJECT_NAME.upper() + ' drivers detected....'
if not device_exist(): if not device_exist():
print "No device, installing...." print 'No device, installing....'
status = device_install() status = device_install()
if status: if status:
if FORCE == 0: if FORCE == 0:
return status return status
else: else:
print PROJECT_NAME.upper()+" devices detected...." print PROJECT_NAME.upper() + ' devices detected....'
return return
def do_uninstall(): def do_uninstall():
print "Checking system...." print 'Checking system....'
if not device_exist(): if not device_exist():
print PROJECT_NAME.upper() +" has no device installed...." print PROJECT_NAME.upper() + ' has no device installed....'
else: else:
print "Removing device...." print 'Removing device....'
status = device_uninstall() status = device_uninstall()
if status: if status and FORCE == 0:
if FORCE == 0: return status
return status
if driver_check() is False:
if driver_check()== False : print PROJECT_NAME.upper() + ' has no driver installed....'
print PROJECT_NAME.upper() +" has no driver installed...."
else: else:
print "Removing installed driver...." print 'Removing installed driver....'
status = driver_uninstall() status = driver_uninstall()
if status: if status and FORCE == 0:
if FORCE == 0: return status
return status return None
return
def devices_info(): def devices_info():
global DEVICE_NO global DEVICE_NO
global ALL_DEVICE global ALL_DEVICE
global i2c_bus, hwmon_types global i2c_bus, hwmon_types
for key in DEVICE_NO: for key in DEVICE_NO:
ALL_DEVICE[key]= {} ALL_DEVICE[key] = {}
for i in range(0,DEVICE_NO[key]): for i in range(0, DEVICE_NO[key]):
ALL_DEVICE[key][key+str(i+1)] = [] ALL_DEVICE[key][key + str(i + 1)] = []
for key in i2c_bus: for key in i2c_bus:
buses = i2c_bus[key] buses = i2c_bus[key]
nodes = i2c_nodes[key] nodes = i2c_nodes[key]
for i in range(0,len(buses)): for i in range(0, len(buses)):
for j in range(0,len(nodes)): for j in range(0, len(nodes)):
if 'fan' == key: if 'fan' == key:
for k in range(0,DEVICE_NO[key]): for k in range(0, DEVICE_NO[key]):
node = key+str(k+1) node = key + str(k + 1)
path = i2c_prefix+ buses[i]+"/fan"+str(k+1)+"_"+ nodes[j] path = i2c_prefix + buses[i] + '/fan' + str(k
my_log(node+": "+ path) + 1) + '_' + nodes[j]
ALL_DEVICE[key][node].append(path) my_log(node + ': ' + path)
elif 'sfp' == key: ALL_DEVICE[key][node].append(path)
for k in range(0,DEVICE_NO[key]): elif 'sfp' == key:
node = key+str(k+1) for k in range(0, DEVICE_NO[key]):
path = i2c_prefix+ str(sfp_map[k])+ buses[i]+"/"+ nodes[j] if k in range(24) or k in range(48, 52):
my_log(node+": "+ path) fmt = i2c_prefix + '5-0062/{0}_{1}'
ALL_DEVICE[key][node].append(path) 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: else:
node = key+str(i+1) node = key + str(i + 1)
path = i2c_prefix+ buses[i]+"/"+ nodes[j] path = i2c_prefix + buses[i] + '/' + nodes[j]
my_log(node+": "+ path) my_log(node + ': ' + path)
ALL_DEVICE[key][node].append(path) ALL_DEVICE[key][node].append(path)
for key in hwmon_types: for key in hwmon_types:
itypes = hwmon_types[key] itypes = hwmon_types[key]
nodes = hwmon_nodes[key] nodes = hwmon_nodes[key]
for i in range(0,len(itypes)): 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] node = key + '_' + itypes[i]
path = hwmon_prefix[key]+ itypes[i]+"/"+ nodes[j] path = hwmon_prefix[key] + itypes[i] + '/' + nodes[j]
my_log(node+": "+ path) 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 # show dict all in the order
if DEBUG == True: if DEBUG == True:
for i in sorted(ALL_DEVICE.keys()): for i in sorted(ALL_DEVICE.keys()):
print(i+": ") print i + ': '
for j in sorted(ALL_DEVICE[i].keys()): for j in sorted(ALL_DEVICE[i].keys()):
print(" "+j) print ' ' + j
for k in (ALL_DEVICE[i][j]): for k in ALL_DEVICE[i][j]:
print(" "+" "+k) print ' ' + ' ' + k
return return
def show_eeprom(index): def show_eeprom(index):
if system_ready()==False: if system_ready() is False:
print("System's not ready.") print "System's not ready."
print("Please install first!") print 'Please install first!'
return return
if len(ALL_DEVICE)==0: if len(ALL_DEVICE) == 0:
devices_info() devices_info()
node = ALL_DEVICE['sfp'] ['sfp'+str(index)][0] 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 # check if got hexdump command in current environment
ret, log = log_os_system("which hexdump", 0) (ret, log) = log_os_system('which hexdump', 0)
ret, log2 = log_os_system("which busybox hexdump", 0) (ret, log2) = log_os_system('which busybox hexdump', 0)
if len(log): if log:
hex_cmd = 'hexdump' hex_cmd = 'hexdump'
elif len(log2): elif log2:
hex_cmd = ' busybox hexdump' hex_cmd = ' busybox hexdump'
else: else:
log = 'Failed : no hexdump cmd!!' log = 'Failed : no hexdump cmd!!'
logging.info(log) logging.info(log)
print log print log
return 1 return 1
print node + ":" print node + ':'
ret, log = log_os_system("cat "+node+"| "+hex_cmd+" -C", 1) (ret, log) = log_os_system('cat ' + node + '| ' + hex_cmd + ' -C',
if ret==0: 1)
print log if ret == 0:
print log
else: else:
print "**********device no found**********" print '**********device no found**********'
return return
def set_device(args): def set_device(args):
global DEVICE_NO global DEVICE_NO
global ALL_DEVICE global ALL_DEVICE
if system_ready()==False: if system_ready() is False:
print("System's not ready.") print "System's not ready."
print("Please install first!") print 'Please install first!'
return return
if len(ALL_DEVICE)==0: if not ALL_DEVICE:
devices_info() devices_info()
if args[0]=='led': if args[0] == 'led':
if int(args[1])>4: if int(args[1]) > 4:
show_set_help() show_set_help()
return return
#print ALL_DEVICE['led']
for i in range(0,len(ALL_DEVICE['led'])): # print ALL_DEVICE['led']
for k in (ALL_DEVICE['led']['led'+str(i+1)]): for i in range(0, len(ALL_DEVICE['led'])):
ret, log = log_os_system("echo "+args[1]+" >"+k, 1) for k in ALL_DEVICE['led']['led' + str(i + 1)]:
if ret: ret = log_os_system('echo ' + args[1] + ' >' + k, 1)
return ret if ret[0]:
elif args[0]=='fan': return ret[0]
if int(args[1])>100: elif args[0] == 'fan':
if int(args[1]) > 100:
show_set_help() show_set_help()
return return
#print ALL_DEVICE['fan']
#fan1~6 is all fine, all fan share same setting # print ALL_DEVICE['fan']
node = ALL_DEVICE['fan'] ['fan1'][0] # fan1~6 is all fine, all fan share same setting
node = node.replace(node.split("/")[-1], 'fan_duty_cycle_percentage')
ret, log = log_os_system("cat "+ node, 1) node = ALL_DEVICE['fan']['fan1'][0]
if ret==0: node = node.replace(node.split('/')[-1],
print ("Previous fan duty: " + log.strip() +"%") 'fan_duty_cycle_percentage')
ret, log = log_os_system("echo "+args[1]+" >"+node, 1) (ret, log) = log_os_system('cat ' + node, 1)
if ret==0: 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 return ret
elif args[0]=='sfp': 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:
show_set_help()
return
if int(args[2])>1:
show_set_help() show_set_help()
return return
if len(args) < 2:
#print ALL_DEVICE[args[0]] show_set_help()
for i in range(0,len(ALL_DEVICE[args[0]])): return
for j in ALL_DEVICE[args[0]][args[0]+str(args[1])]:
if j.find('tx_disable')!= -1: if int(args[2]) > 1:
ret, log = log_os_system("echo "+args[2]+" >"+ j, 1) show_set_help()
if ret: return
return ret
# 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 return
#get digits inside a string.
#Ex: 31 for "sfp31" # get digits inside a string.
def get_value(input): # Ex: get 31 from "sfp31"
digit = re.findall('\d+', input) def get_value(i):
digit = re.findall('\d+', i)
return int(digit[0]) return int(digit[0])
def device_traversal(): def device_traversal():
if system_ready()==False: if system_ready() is False:
print("System's not ready.") print "System's not ready."
print("Please install first!") print 'Please install first!'
return return
if len(ALL_DEVICE)==0: if not ALL_DEVICE:
devices_info() devices_info()
for i in sorted(ALL_DEVICE.keys()): for i in sorted(ALL_DEVICE.keys()):
print("============================================") print '============================================'
print(i.upper()+": ") print i.upper() + ': '
print("============================================") 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 + ':',
print " "+j+":", for k in ALL_DEVICE[i][j]:
for k in (ALL_DEVICE[i][j]): (ret, log) = log_os_system('cat ' + k, 0)
ret, log = log_os_system("cat "+k, 0) func = k.split('/')[-1].strip()
func = k.split("/")[-1].strip() func = re.sub(j + '_', '', func, 1)
func = re.sub(j+'_','',func,1) func = re.sub(i.lower() + '_', '', func, 1)
func = re.sub(i.lower()+'_','',func,1) if ret == 0:
if ret==0: print func + '=' + log + ' ',
print func+"="+log+" ",
else: else:
print func+"="+"X"+" ", print func + '=' + 'X' + ' ',
print print
print("----------------------------------------------------------------") print '----------------------------------------------------------------'
print print
return 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() main()