Skip to content

Commit f3601c0

Browse files
Junchao-Mellanoxmssonicbld
authored andcommitted
[Mellanox] Fix issue: cannot find label port for logical port when logical port number is larger than 64 (sonic-net#13710)
- Why I did it sfp_event.py gets a PMPE message when a cable event is available. In PMPE message, there is no label port available. Current sfp_event.py is using sx_api_port_device_get to get 64 logical ports attributes, and find the label port from those 64 attributes. However, if there are more than 64 ports, sfp_event.py might not be able to find the label port and drop the PMPE message. - How I did it Don't use hardcoded 64, get logical port number instead. - How to verify it Manual test
1 parent 6a12ca9 commit f3601c0

1 file changed

Lines changed: 31 additions & 18 deletions

File tree

  • platform/mellanox/mlnx-platform-api/sonic_platform

platform/mellanox/mlnx-platform-api/sonic_platform/sfp_event.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,9 @@ def on_pmpe(self, fd_p):
332332
pkt = new_uint8_t_arr(pkt_size)
333333
recv_info_p = new_sx_receive_info_t_p()
334334
pmpe_t = sx_event_pmpe_t()
335-
port_attributes_list = new_sx_port_attributes_t_arr(64)
336335
port_cnt_p = new_uint32_t_p()
337-
uint32_t_p_assign(port_cnt_p,64)
336+
uint32_t_p_assign(port_cnt_p, 0)
338337
label_port_list = []
339-
label_port = None
340338
module_state = 0
341339

342340
rc = sx_lib_host_ifc_recv(fd_p, pkt, pkt_size_p, recv_info_p)
@@ -352,31 +350,44 @@ def on_pmpe(self, fd_p):
352350
module_state = pmpe_t.module_state
353351
error_type = pmpe_t.error_type
354352
module_id = pmpe_t.module_id
355-
slot_id = pmpe_t.slot_id # For non-modular chassis, it should return 0
353+
slot_id = pmpe_t.slot_id # For non-modular chassis, it should return 0
356354

357355
if module_state == SDK_SFP_STATE_ERR:
358356
logger.log_error("Receive PMPE error event on module {}: status {} error type {}".format(module_id, module_state, error_type))
359357
elif module_state == SDK_SFP_STATE_DIS:
360-
logger.log_info("Receive PMPE disable event on module {}: status {}".format(module_id, module_state))
358+
logger.log_notice("Receive PMPE disable event on module {}: status {}".format(module_id, module_state))
361359
elif module_state == SDK_SFP_STATE_IN or module_state == SDK_SFP_STATE_OUT:
362-
logger.log_info("Receive PMPE plug in/out event on module {}: status {}".format(module_id, module_state))
360+
logger.log_notice("Receive PMPE plug in/out event on module {}: status {}".format(module_id, module_state))
363361
elif module_state == SDK_SFP_STATE_UNKNOWN:
364362
unknown = True
365363
else:
366364
logger.log_error("Receive PMPE unknown event on module {}: status {}".format(module_id, module_state))
367365

368-
for i in range(port_list_size):
369-
logical_port = sx_port_log_id_t_arr_getitem(logical_port_list, i)
370-
rc = sx_api_port_device_get(self.handle, 1 , 0, port_attributes_list, port_cnt_p)
366+
# Call sx_api_port_device_get with port_cnt_p=0, SDK will return the logical port number
367+
rc = sx_api_port_device_get(self.handle, 1, 0, None, port_cnt_p)
368+
if rc != SX_STATUS_SUCCESS:
369+
logger.log_error("Failed to get logical port number")
370+
status = False
371+
else:
371372
port_cnt = uint32_t_p_value(port_cnt_p)
372-
for i in range(port_cnt):
373-
port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list,i)
374-
if port_attributes.log_port == logical_port:
375-
label_port = slot_id * DeviceDataManager.get_linecard_max_port_count() + port_attributes.port_mapping.module_port
376-
break
377-
378-
if label_port is not None:
379-
label_port_list.append(label_port)
373+
port_attributes_list = new_sx_port_attributes_t_arr(port_cnt)
374+
rc = sx_api_port_device_get(self.handle, 1, 0, port_attributes_list, port_cnt_p)
375+
if rc != SX_STATUS_SUCCESS:
376+
logger.log_error("Failed to get logical port attributes")
377+
status = False
378+
else:
379+
for i in range(port_list_size):
380+
label_port = None
381+
logical_port = sx_port_log_id_t_arr_getitem(logical_port_list, i)
382+
for j in range(port_cnt):
383+
port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list,j)
384+
if port_attributes.log_port == logical_port:
385+
label_port = slot_id * DeviceDataManager.get_linecard_max_port_count() + port_attributes.port_mapping.module_port
386+
break
387+
388+
if label_port is not None:
389+
label_port_list.append(label_port)
390+
delete_sx_port_attributes_t_arr(port_attributes_list)
380391

381392
if unknown:
382393
SFP_ports_with_unknown_event = set(label_port_list) - self.RJ45_port_set
@@ -389,7 +400,9 @@ def on_pmpe(self, fd_p):
389400
delete_uint32_t_p(pkt_size_p)
390401
delete_uint8_t_arr(pkt)
391402
delete_sx_receive_info_t_p(recv_info_p)
392-
delete_sx_port_attributes_t_arr(port_attributes_list)
393403
delete_uint32_t_p(port_cnt_p)
394404

405+
if not label_port_list:
406+
logger.log_error('Dropping PMPE event due to label port not found')
407+
395408
return status, label_port_list, module_state, error_type

0 commit comments

Comments
 (0)