Skip to content

Fix hardcoded lane masks when applying loopbacks#686

Open
abhi-nexthop wants to merge 1 commit into
sonic-net:masterfrom
nexthop-ai:abhi.hardcoded-lane-masks
Open

Fix hardcoded lane masks when applying loopbacks#686
abhi-nexthop wants to merge 1 commit into
sonic-net:masterfrom
nexthop-ai:abhi.hardcoded-lane-masks

Conversation

@abhi-nexthop

@abhi-nexthop abhi-nexthop commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Description

Certain transceivers expect exact lane masks for the active appsel when setting Media Side and Host side loopbacks respectively.
Currently, we have them hardcoded as 0xFF which works on certain transceivers but not others. On a 1 media lane transceiver, trying to disable loopback on it with 0xFF might fail depending on the device. We noticed this on several transceivers

Motivation and Context

How Has This Been Tested?

Tested on INPHI CORP IN-Q3JZ1-TC-M1 and Acacia DP04QSDD-E20-001

Acacia works with and without the fix
IN-Q3JZ1-TC-M1 fails to set any kind of media loopback without the fix

Additional Information (Optional)

Signed-off-by: Abhi Singh <abhi@nexthop.ai>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Comment on lines +1186 to +1238
def _get_active_appsel_descriptor(self):
'''
Returns the application-advertisement descriptor for the currently
active AppSel on host lane 1.

Raises RuntimeError if the active AppSel cannot be determined --
callers must not silently fall back to the default-application
descriptor, since that defeats the purpose of resolving the
runtime-configured application.
'''
if self.is_flat_memory():
raise RuntimeError(
'Cannot determine active AppSel descriptor: '
'module reports flat memory (page 11h unavailable)')

lane1_field = "%s%d" % (consts.ACTIVE_APSEL_HOSTLANE, 1)
active_apsel = self.xcvr_eeprom.read(lane1_field)
if not active_apsel:
raise RuntimeError(
'Cannot determine active AppSel descriptor: '
'read of %s returned %r' % (lane1_field, active_apsel))

appl_advt = self.get_application_advertisement()
descriptor = appl_advt.get(active_apsel)
if not descriptor:
raise RuntimeError(
'Cannot determine active AppSel descriptor: '
'AppSel %d has no entry in application advertisement %r'
% (active_apsel, appl_advt))

return active_apsel, descriptor

def get_active_appsel_host_lane_count(self):
'''
Returns the host lane count for the currently active application.

Reads the applied AppSel code from the DataPath Configuration
(Page 11h) and looks up the corresponding application descriptor.
Raises RuntimeError if the active AppSel cannot be determined or
the descriptor lacks a host_lane_count
'''
active_apsel, descriptor = self._get_active_appsel_descriptor()
if 'host_lane_count' not in descriptor:
raise RuntimeError(
'Cannot determine active AppSel host lane count: '
'AppSel %d descriptor %r has no host_lane_count'
% (active_apsel, descriptor))
return descriptor['host_lane_count']

def get_active_appsel_media_lane_count(self):
'''
Returns the media lane count for the currently active application.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhi-nexthop we don't have existing APIs for these? cc @mihirpat1

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the CMIS transceiver loopback implementation to avoid using a hardcoded 0xFF lane mask by deriving the “all lanes” mask from the currently active AppSel’s host/media lane counts, improving compatibility with 1-lane / smaller-lane-count modules.

Changes:

  • Add APIs to resolve the active AppSel descriptor and fetch active host/media lane counts from Page 11h + application advertisement.
  • Use the derived “all lanes” mask instead of 0xFF for loopback operations (notably when disabling all loopbacks via loopback_mode == 'none').
  • Extend unit tests to cover the new active-lane-count APIs and updated loopback behaviors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.

File Description
tests/sonic_xcvr/test_cmis.py Adds tests for active AppSel lane count helpers; updates loopback tests to account for derived masks.
sonic_platform_base/sonic_xcvr/api/public/cmis.py Introduces active AppSel lane-count helpers; replaces hardcoded lane masks in loopback paths; minor boolean conversion change for media loopback getters.

Comment on lines +1565 to 1568
all_lanes_mask = (1 << self.get_active_appsel_host_lane_count()) - 1
if loopback_capability['per_lane_host_loopback_supported'] is False and lane_mask != all_lanes_mask:
logger.error('Per-lane host input loopback is not supported, lane_mask:%#x', lane_mask)
return False
Comment on lines +1607 to 1610
all_lanes_mask = (1 << self.get_active_appsel_host_lane_count()) - 1
if loopback_capability['per_lane_host_loopback_supported'] is False and lane_mask != all_lanes_mask:
logger.error('Per-lane host output loopback is not supported, lane_mask:%#x', lane_mask)
return False
Comment on lines +1649 to 1652
all_lanes_mask = (1 << self.get_active_appsel_media_lane_count()) - 1
if loopback_capability['per_lane_media_loopback_supported'] is False and lane_mask != all_lanes_mask:
logger.error('Per-lane media input loopback is not supported, lane_mask:%#x', lane_mask)
return False
Comment on lines +1691 to 1694
all_lanes_mask = (1 << self.get_active_appsel_media_lane_count()) - 1
if loopback_capability['per_lane_media_loopback_supported'] is False and lane_mask != all_lanes_mask:
logger.error('Per-lane media output loopback is not supported, lane_mask:%#x', lane_mask)
return False
Comment on lines 1735 to 1743
if loopback_mode == 'none':
host_all_lanes_mask = (1 << self.get_active_appsel_host_lane_count()) - 1
media_all_lanes_mask = (1 << self.get_active_appsel_media_lane_count()) - 1
return all([
self.set_host_input_loopback(0xff, False),
self.set_host_output_loopback(0xff, False),
self.set_media_input_loopback(0xff, False),
self.set_media_output_loopback(0xff, False)
self.set_host_input_loopback(host_all_lanes_mask, False),
self.set_host_output_loopback(host_all_lanes_mask, False),
self.set_media_input_loopback(media_all_lanes_mask, False),
self.set_media_output_loopback(media_all_lanes_mask, False)
])
Comment on lines +1186 to +1250
def _get_active_appsel_descriptor(self):
'''
Returns the application-advertisement descriptor for the currently
active AppSel on host lane 1.

Raises RuntimeError if the active AppSel cannot be determined --
callers must not silently fall back to the default-application
descriptor, since that defeats the purpose of resolving the
runtime-configured application.
'''
if self.is_flat_memory():
raise RuntimeError(
'Cannot determine active AppSel descriptor: '
'module reports flat memory (page 11h unavailable)')

lane1_field = "%s%d" % (consts.ACTIVE_APSEL_HOSTLANE, 1)
active_apsel = self.xcvr_eeprom.read(lane1_field)
if not active_apsel:
raise RuntimeError(
'Cannot determine active AppSel descriptor: '
'read of %s returned %r' % (lane1_field, active_apsel))

appl_advt = self.get_application_advertisement()
descriptor = appl_advt.get(active_apsel)
if not descriptor:
raise RuntimeError(
'Cannot determine active AppSel descriptor: '
'AppSel %d has no entry in application advertisement %r'
% (active_apsel, appl_advt))

return active_apsel, descriptor

def get_active_appsel_host_lane_count(self):
'''
Returns the host lane count for the currently active application.

Reads the applied AppSel code from the DataPath Configuration
(Page 11h) and looks up the corresponding application descriptor.
Raises RuntimeError if the active AppSel cannot be determined or
the descriptor lacks a host_lane_count
'''
active_apsel, descriptor = self._get_active_appsel_descriptor()
if 'host_lane_count' not in descriptor:
raise RuntimeError(
'Cannot determine active AppSel host lane count: '
'AppSel %d descriptor %r has no host_lane_count'
% (active_apsel, descriptor))
return descriptor['host_lane_count']

def get_active_appsel_media_lane_count(self):
'''
Returns the media lane count for the currently active application.

Reads the applied AppSel code from the DataPath Configuration
(Page 11h) and looks up the corresponding application descriptor.
Raises RuntimeError if the active AppSel cannot be determined or
the descriptor lacks a media_lane_count
'''
active_apsel, descriptor = self._get_active_appsel_descriptor()
if 'media_lane_count' not in descriptor:
raise RuntimeError(
'Cannot determine active AppSel media lane count: '
'AppSel %d descriptor %r has no media_lane_count'
% (active_apsel, descriptor))
return descriptor['media_lane_count']
Comment on lines 1699 to 1704
self.api.set_media_output_loopback = MagicMock()
self.api.set_media_output_loopback.return_value = mock_response
self.api.get_active_appsel_host_lane_count = MagicMock(return_value=8)
self.api.get_active_appsel_media_lane_count = MagicMock(return_value=8)
result = self.api.set_loopback_mode(input_param[0], input_param[1])
assert result == expected
if loopback_capability['per_lane_host_loopback_supported'] is False and lane_mask != 0xff:
all_lanes_mask = (1 << self.get_active_appsel_host_lane_count()) - 1
if loopback_capability['per_lane_host_loopback_supported'] is False and lane_mask != all_lanes_mask:
logger.error('Per-lane host input loopback is not supported, lane_mask:%#x', lane_mask)
if loopback_capability['per_lane_host_loopback_supported'] is False and lane_mask != 0xff:
all_lanes_mask = (1 << self.get_active_appsel_host_lane_count()) - 1
if loopback_capability['per_lane_host_loopback_supported'] is False and lane_mask != all_lanes_mask:
logger.error('Per-lane host output loopback is not supported, lane_mask:%#x', lane_mask)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants