Skip to content

Commit

Permalink
implement CMIS set_laser_freq to support 100GHz grid space (#294)
Browse files Browse the repository at this point in the history
Signed-off-by: chiourung_huang <chiourung_huang@edge-core.com>

Signed-off-by: chiourung_huang <chiourung_huang@edge-core.com>
  • Loading branch information
chiourung committed Nov 18, 2022
1 parent d739102 commit 02dd597
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
26 changes: 17 additions & 9 deletions sonic_platform_base/sonic_xcvr/api/public/c_cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ def get_laser_tuning_summary(self):

def get_supported_freq_config(self):
'''
This function returns the supported freq grid, low and high supported channel in 75GHz grid,
This function returns the supported freq grid, low and high supported channel in 75/100GHz grid,
and low and high frequency supported in GHz.
allowed channel number bound in 75 GHz grid
allowed frequency bound in 75 GHz grid
allowed channel number bound in 75/100 GHz grid
allowed frequency bound in 75/100 GHz grid
'''
grid_supported = self.xcvr_eeprom.read(consts.SUPPORT_GRID)
low_ch_num = self.xcvr_eeprom.read(consts.LOW_CHANNEL)
Expand All @@ -106,20 +106,28 @@ def get_supported_freq_config(self):
high_freq_supported = 193100 + hi_ch_num * 25
return grid_supported, low_ch_num, hi_ch_num, low_freq_supported, high_freq_supported

def set_laser_freq(self, freq):
def set_laser_freq(self, freq, grid):
'''
This function sets the laser frequency. Unit in GHz
ZR application will not support fine tuning of the laser
SONiC will only support 75 GHz frequency grid
SONiC will only support 75 GHz and 100GHz frequency grids
Return True if the provision succeeds, False if it fails
'''
grid_supported, low_ch_num, hi_ch_num, _, _ = self.get_supported_freq_config()
grid_supported_75GHz = (grid_supported >> 7) & 0x1
assert grid_supported_75GHz
freq_grid = 0x70
grid_supported_100GHz = (grid_supported >> 5) & 0x1
if grid == 75:
assert grid_supported_75GHz
freq_grid = 0x70
channel_number = int(round((freq - 193100)/25))
assert channel_number % 3 == 0
elif grid == 100:
assert grid_supported_100GHz
freq_grid = 0x50
channel_number = int(round((freq - 193100)/100))
else:
return False
self.xcvr_eeprom.write(consts.GRID_SPACING, freq_grid)
channel_number = int(round((freq - 193100)/25))
assert channel_number % 3 == 0
if channel_number > hi_ch_num or channel_number < low_ch_num:
raise ValueError('Provisioned frequency out of range. Max Freq: 196100; Min Freq: 191300 GHz.')
status = self.xcvr_eeprom.write(consts.LASER_CONFIG_CHANNEL, channel_number)
Expand Down
6 changes: 3 additions & 3 deletions tests/sonic_xcvr/test_ccmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def test_get_supported_freq_config(self, mock_response, expected):
assert result == expected

@pytest.mark.parametrize("input_param, mock_response",[
(193100, (0xff, -72, 120, 191300, 196100)),
(195950, (0xff, -72, 120, 191300, 196100)),
((193100,75), (0xff, -72, 120, 191300, 196100)),
((195950,100), (0xff, -72, 120, 191300, 196100)),
])
def test_set_laser_freq(self, input_param, mock_response):
self.api.is_flat_memory = MagicMock()
Expand All @@ -103,7 +103,7 @@ def test_set_laser_freq(self, input_param, mock_response):
self.api.get_lpmode_support.return_value = False
self.api.get_supported_freq_config = MagicMock()
self.api.get_supported_freq_config.return_value = mock_response
self.api.set_laser_freq(input_param)
self.api.set_laser_freq(input_param[0], input_param[1])

@pytest.mark.parametrize("input_param, mock_response",[
(-10, (-14, -9)),
Expand Down

0 comments on commit 02dd597

Please sign in to comment.