Skip to content

Commit

Permalink
[device/accton] AS****_54X, validate accton util to set sfp's tx_disa…
Browse files Browse the repository at this point in the history
…ble (sonic-net#5941)

bug fix: sonic-net#5914

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

Signed-off-by: roy_lee <[email protected]>
  • Loading branch information
roylee123 authored Dec 18, 2020
1 parent aa38022 commit 54681f1
Show file tree
Hide file tree
Showing 7 changed files with 690 additions and 748 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
'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,
Expand Down Expand Up @@ -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',
Expand All @@ -263,10 +261,10 @@ def driver_inserted():
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():
Expand All @@ -282,45 +280,34 @@ 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



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)):
Expand All @@ -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)
Expand All @@ -359,7 +346,7 @@ def device_install():
print output
if FORCE == 0:
return status

return

def device_uninstall():
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -550,15 +533,15 @@ 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)
if cpld_p is None:
return False, ''
else:
dev = cpld_p+"module_present_"+str(port_index)
return True, dev
return True, dev


def set_device(args):
Expand All @@ -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()
Expand Down Expand Up @@ -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.
Expand All @@ -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.")
Expand All @@ -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("----------------------------------------------------------------")

Expand All @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
'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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)):
Expand All @@ -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)
Expand All @@ -359,7 +347,7 @@ def device_install():
print output
if FORCE == 0:
return status

return

def device_uninstall():
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -550,15 +534,15 @@ 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)
if cpld_p is None:
return False, ''
else:
dev = cpld_p+"module_present_"+str(port_index)
return True, dev
return True, dev


def set_device(args):
Expand Down Expand Up @@ -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.")
Expand All @@ -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("----------------------------------------------------------------")

Expand Down
Loading

0 comments on commit 54681f1

Please sign in to comment.