From 02dd59730a67ad81b4aa9d0d1264e77ab0148d3a Mon Sep 17 00:00:00 2001 From: ChiouRung Haung Date: Sat, 19 Nov 2022 07:18:37 +0800 Subject: [PATCH] implement CMIS set_laser_freq to support 100GHz grid space (#294) Signed-off-by: chiourung_huang Signed-off-by: chiourung_huang --- .../sonic_xcvr/api/public/c_cmis.py | 26 ++++++++++++------- tests/sonic_xcvr/test_ccmis.py | 6 ++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py b/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py index 65ac4c1f350b..b6885381d0f0 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/c_cmis.py @@ -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) @@ -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) diff --git a/tests/sonic_xcvr/test_ccmis.py b/tests/sonic_xcvr/test_ccmis.py index 99a67b62b7dc..a505252c5b38 100644 --- a/tests/sonic_xcvr/test_ccmis.py +++ b/tests/sonic_xcvr/test_ccmis.py @@ -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() @@ -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)),