Skip to content

Commit 0f47c5b

Browse files
[202012] [Mellanox] Fix issue: cannot lable port for logical port is logical port number larger than 64 (#13709)
- 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 73c7ced commit 0f47c5b

File tree

1 file changed

+31
-18
lines changed
  • platform/mellanox/mlnx-platform-api/sonic_platform

1 file changed

+31
-18
lines changed

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

+31-18
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,9 @@ def on_pmpe(self, fd_p):
273273
pkt = new_uint8_t_arr(pkt_size)
274274
recv_info_p = new_sx_receive_info_t_p()
275275
pmpe_t = sx_event_pmpe_t()
276-
port_attributes_list = new_sx_port_attributes_t_arr(64)
277276
port_cnt_p = new_uint32_t_p()
278-
uint32_t_p_assign(port_cnt_p,64)
277+
uint32_t_p_assign(port_cnt_p, 0)
279278
label_port_list = []
280-
label_port = None
281279
module_state = 0
282280

283281
rc = sx_lib_host_ifc_recv(fd_p, pkt, pkt_size_p, recv_info_p)
@@ -296,29 +294,44 @@ def on_pmpe(self, fd_p):
296294
if module_state == SDK_SFP_STATE_ERR:
297295
logger.log_error("Receive PMPE error event on module {}: status {} error type {}".format(module_id, module_state, error_type))
298296
elif module_state == SDK_SFP_STATE_DIS:
299-
logger.log_info("Receive PMPE disable event on module {}: status {}".format(module_id, module_state))
297+
logger.log_notice("Receive PMPE disable event on module {}: status {}".format(module_id, module_state))
300298
elif module_state == SDK_SFP_STATE_IN or module_state == SDK_SFP_STATE_OUT:
301-
logger.log_info("Receive PMPE plug in/out event on module {}: status {}".format(module_id, module_state))
299+
logger.log_notice("Receive PMPE plug in/out event on module {}: status {}".format(module_id, module_state))
302300
else:
303301
logger.log_error("Receive PMPE unknown event on module {}: status {}".format(module_id, module_state))
304-
for i in range(port_list_size):
305-
logical_port = sx_port_log_id_t_arr_getitem(logical_port_list, i)
306-
rc = sx_api_port_device_get(self.handle, 1 , 0, port_attributes_list, port_cnt_p)
307-
port_cnt = uint32_t_p_value(port_cnt_p)
308-
309-
for i in range(port_cnt):
310-
port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list,i)
311-
if port_attributes.log_port == logical_port:
312-
label_port = port_attributes.port_mapping.module_port
313-
break
314302

315-
if label_port is not None:
316-
label_port_list.append(label_port)
303+
# Call sx_api_port_device_get with port_cnt_p=0, SDK will return the logical port number
304+
rc = sx_api_port_device_get(self.handle, 1, 0, None, port_cnt_p)
305+
if rc != SX_STATUS_SUCCESS:
306+
logger.log_error("Failed to get logical port number")
307+
status = False
308+
else:
309+
port_cnt = uint32_t_p_value(port_cnt_p)
310+
port_attributes_list = new_sx_port_attributes_t_arr(port_cnt)
311+
rc = sx_api_port_device_get(self.handle, 1, 0, port_attributes_list, port_cnt_p)
312+
if rc != SX_STATUS_SUCCESS:
313+
logger.log_error("Failed to get logical port attributes")
314+
status = False
315+
else:
316+
for i in range(port_list_size):
317+
label_port = None
318+
logical_port = sx_port_log_id_t_arr_getitem(logical_port_list, i)
319+
for j in range(port_cnt):
320+
port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list,j)
321+
if port_attributes.log_port == logical_port:
322+
label_port = port_attributes.port_mapping.module_port
323+
break
324+
325+
if label_port is not None:
326+
label_port_list.append(label_port)
327+
delete_sx_port_attributes_t_arr(port_attributes_list)
317328

318329
delete_uint32_t_p(pkt_size_p)
319330
delete_uint8_t_arr(pkt)
320331
delete_sx_receive_info_t_p(recv_info_p)
321-
delete_sx_port_attributes_t_arr(port_attributes_list)
322332
delete_uint32_t_p(port_cnt_p)
323333

334+
if not label_port_list:
335+
logger.log_error('Dropping PMPE event due to label port not found')
336+
324337
return status, label_port_list, module_state, error_type

0 commit comments

Comments
 (0)