Skip to content

Commit

Permalink
[poed]Fix communication retry echo byte regenerate rule
Browse files Browse the repository at this point in the history
1. Fix communication retry echo byte regenerate.
2. Read 15 bytes when I2C bus initialized in all platform, avoid read mismatch package.
3. Suppress log message when exclusive lock success.
4. Skip powerlimit result checking in 802.3BT mode.

Signed-off-by: leon.chiang <[email protected]>
  • Loading branch information
leonchiang committed Dec 29, 2021
1 parent 3959c6c commit 82d1b74
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 18 deletions.
21 changes: 12 additions & 9 deletions dentos-poe-agent/opt/poeagent/bin/poed.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,22 @@ def init_platform(self,cfg_data=None):
try:
result = self.poe_plat.init_poe(cfg_data)
all_result = check_init_plat_ret_result(result)
if all_result[1]==0:
self.log.info("init_poe all_result: {0}".format(str(all_result[1])))
if all_result[1] == 0:
self.log.info(
"init_poe all_result: {0}".format(str(all_result[1])))
else:
self.log.info("init_poe all_result(some command failed): {0}".format(str(all_result)))
self.log.info(
"init_poe all_result(some command failed): {0}".format(str(all_result)))
return False


self.update_set_time()
return True
except Exception as e:
self.log.err(
"An exception when initializing poe chip: %s" % str(e))
self.log.info("init_poe all_result: {0}".format(str(all_result)))
"An exception when initializing poe chip: {0}".format(str(e)))
return False


def collect_general_info(self):
gen_info = OrderedDict()
gen_info[PLATFORM] = self.plat_name
Expand Down Expand Up @@ -341,9 +342,9 @@ def autosave_main(self):

@PoeAccessExclusiveLock
def flush_settings_to_chip(self, poe_cfg):
# Read all port enDis status
all_port_endis = self.poe_plat.get_all_ports_enDis()
try:
# Read all port enDis status
all_port_endis = self.poe_plat.get_all_ports_enDis()
ret_result = True
data = poe_cfg.load()
all_port_configs = data[PORT_CONFIGS]
Expand All @@ -353,7 +354,9 @@ def flush_settings_to_chip(self, poe_cfg):
poe_port = self.poe_plat.get_poe_port(port_id)
set_result = poe_port.set_all_params(
params, current_enDis=all_port_endis)
if set_result[ENDIS] != 0 or set_result[PRIORITY] != 0 or set_result[POWER_LIMIT] != 0:
if (set_result[ENDIS] != 0
or set_result[PRIORITY] != 0
or (self.poe_plat._4wire_bt == 0 and set_result[POWER_LIMIT] != 0)):
self.log.warn("Port[{0}] setting failed: {1}".format(
str(params.get(PORT_ID)), json.dumps(set_result)))
ret_result=False
Expand Down
11 changes: 10 additions & 1 deletion dentos-poe-agent/opt/poeagent/drivers/poe_driver_pd69200.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ def _check_rx_msg(self, rx_msg, tx_msg):
rx_msg[POE_PD69200_MSG_OFFSET_CSUM_L] != csum[1]):
raise RuntimeError("Invalid checksum in POE Rx message")


@PoeCommExclusiveLock()
def _communicate(self, tx_msg, delay):
retry = 0
ex="Unknown"
while retry < POE_PD69200_COMM_RETRY_TIMES:
try:
self._xmit(tx_msg, delay)
Expand All @@ -130,15 +132,20 @@ def _communicate(self, tx_msg, delay):
self._check_rx_msg(rx_msg, tx_msg)
return rx_msg
except Exception as e:
ex = e
print_stderr("_communicate error: {0}".format(str(e)))
print_stderr("Send: {0}".format(conv_byte_to_hex(tx_msg)))
print_stderr("Recv: {0}".format(conv_byte_to_hex(rx_msg)))
rx_msg = self._recv()
# Increment echo byte
command = tx_msg[0:POE_PD69200_MSG_OFFSET_DATA12]
command[POE_PD69200_MSG_OFFSET_ECHO] = self._calc_msg_echo()
tx_msg = self._build_tx_msg(command)
# Wait 0.5s to clear up I2C buffer
time.sleep(self._clear_bus_buffer_delay)
retry += 1
raise RuntimeError(
"Problems in running poe communication protocol - %s" % str(e))
"Problems in running poe communication protocol: {0}".format(str(ex)))

def _run_communication_protocol(self, command, delay, msg_type=None):
tx_msg = self._build_tx_msg(command)
Expand Down Expand Up @@ -244,8 +251,10 @@ def support_4wire_bt(self, min_major_ver=3):
poe_ver = self.get_poe_versions()
major_ver = int(poe_ver.split('.')[1])
if major_ver >= min_major_ver:
self._4wire_bt = 1
return 1
else:
self._4wire_bt = 0
return 0

def set_temp_matrix(self, logic_port, phy_port_a, phy_port_b=0xFF):
Expand Down
12 changes: 8 additions & 4 deletions dentos-poe-agent/opt/poeagent/inc/poe_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,11 @@ def wrap_cmd(*args, **kwargs):
while retry > 0:
try:
fcntl.flock(fd, fcntl.LOCK_EX)
print_stderr("[{0}]Locked, retry: {1}".format(
func.__name__, str(retry)))


if retry < EXLOCK_RETRY:
print_stderr("[{0}]Locked, retry: {1}".format(
func.__name__, str(retry)))
LOCKED = True
break
except Exception as e:
Expand All @@ -174,8 +177,9 @@ def wrap_cmd(*args, **kwargs):
return res
if LOCKED:
try:
print_stderr("[{0}]Locked execution code".format(
func.__name__))
if retry < EXLOCK_RETRY:
print_stderr("[{0}]Locked execution code".format(
func.__name__))
res = func(*args, **kwargs)
except Exception as e:
error_class = e.__class__.__name__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ def __init__(self):
self._i2c_addr = 0x3C
self._poe_bus = SMBus(self._i2c_bus)

# Add read 15byte first to cleanup buffer
self.plat_poe_read()

# item in matrix: (logic port, phy port)
self._default_matrix = [
# locgic port
( 0, 7), ( 1, 4), ( 2, 5), ( 3, 6), ( 4, 0), ( 5, 1), ( 6, 2), ( 7, 3),
( 8, 12), ( 9, 13), (10, 14), (11, 15), (12, 9), (13, 10), (14, 11), (15, 8),
( 8, 12), ( 9, 13), (10, 14), (11, 15), (12, 9), (13, 10), (14, 11), (15, 8),
(16, 20), (17, 21), (18, 22), (19, 23), (20, 17), (21, 18), (22, 19), (23, 16),
(24, 28), (25, 29), (26, 30), (27, 31), (28, 27), (29, 26), (30, 25), (31, 24),
(32, 39), (33, 36), (34, 37), (35, 38), (36, 32), (37, 33), (38, 34), (39, 35),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def __init__(self):
self._i2c_bus = 1
self._i2c_addr = 0x3C
self._poe_bus = SMBus(self._i2c_bus)
# Add read 15byte first to cleanup buffer
self.plat_poe_read()
self._4wire_bt = self.support_4wire_bt(3)
# item in matrix: (logic port, phy port a, phy port b)
self._default_matrix = [
Expand All @@ -43,9 +45,6 @@ def __init__(self):
self._guard_band = 0x0A
self._default_power_banks = [(1, 520)]

#add read 15byte first as init chip
self._i2c_read(self._bus())

def total_poe_port(self):
return self._total_poe_port

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def __init__(self):
self._i2c_bus = 1
self._i2c_addr = 0x3C
self._poe_bus = SMBus(self._i2c_bus)

# Add read 15byte first to cleanup buffer
self.plat_poe_read()

# Time between commands (from hw spec): 30ms
self._msg_delay = 0.03
# Wait time after saving system setting: 50ms
Expand Down

0 comments on commit 82d1b74

Please sign in to comment.