Skip to content

Commit 145d6cc

Browse files
committed
resolve comments, add more functions in sfp_optoe_base for use in xcvrd and sonic-utilities repo
1 parent 80ee2c2 commit 145d6cc

File tree

3 files changed

+72
-16
lines changed

3 files changed

+72
-16
lines changed

sonic_platform_base/sonic_xcvr/api/public/cmis.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def get_transceiver_threshold_info(self):
224224
if thresh is None:
225225
return None
226226
tx_bias_scale_raw = self.xcvr_eeprom.read(consts.TX_BIAS_SCALE)
227-
tx_bias_scale = 2**tx_bias_scale_raw
227+
tx_bias_scale = 2**tx_bias_scale_raw if tx_bias_scale_raw < 3 else 1
228228
threshold_info_dict = {
229229
"temphighalarm": float("{:.3f}".format(thresh[consts.TEMP_HIGH_ALARM_FIELD])),
230230
"templowalarm": float("{:.3f}".format(thresh[consts.TEMP_LOW_ALARM_FIELD])),
@@ -587,9 +587,6 @@ def set_power_override(self, power_override, power_set):
587587
def get_transceiver_thresholds_support(self):
588588
return not self.is_flat_memory()
589589

590-
def get_transceiver_loopback_support(self):
591-
return not self.is_flat_memory()
592-
593590
def get_lpmode_support(self):
594591
power_class = self.xcvr_eeprom.read(consts.POWER_CLASS_FIELD)
595592
if power_class is None:
@@ -879,6 +876,9 @@ def set_loopback_mode(self, loopback_mode):
879876
The function will look at 13h:128 to check advertized loopback capabilities.
880877
Return True if the provision succeeds, False if it fails
881878
'''
879+
loopback_support = not self.is_flat_memory()
880+
if loopback_support is None:
881+
return None
882882
loopback_capability = self.get_loopback_capability()
883883
if loopback_capability is None:
884884
return None
@@ -1658,13 +1658,20 @@ def get_transceiver_loopback(self):
16581658
host_input_loopback_lane8 = BOOLEAN ; host side input loopback enable lane8
16591659
========================================================================
16601660
"""
1661-
loopback_support = self.get_transceiver_loopback_support()
1661+
loopback_support = not self.is_flat_memory()
16621662
if loopback_support is None:
16631663
return None
16641664
loopback_capability = self.get_loopback_capability()
16651665
if loopback_capability is None:
16661666
return None
16671667
trans_loopback = dict()
1668+
trans_loopback['simultaneous_host_media_loopback_supported'] = loopback_capability['simultaneous_host_media_loopback_supported']
1669+
trans_loopback['per_lane_media_loopback_supported'] = loopback_capability['per_lane_media_loopback_supported']
1670+
trans_loopback['per_lane_host_loopback_supported'] = loopback_capability['per_lane_host_loopback_supported']
1671+
trans_loopback['host_side_input_loopback_supported'] = loopback_capability['host_side_input_loopback_supported']
1672+
trans_loopback['host_side_output_loopback_supported'] = loopback_capability['host_side_output_loopback_supported']
1673+
trans_loopback['media_side_input_loopback_supported'] = loopback_capability['media_side_input_loopback_supported']
1674+
trans_loopback['media_side_output_loopback_supported'] = loopback_capability['media_side_output_loopback_supported']
16681675
if loopback_capability['media_side_output_loopback_supported']:
16691676
trans_loopback['media_output_loopback'] = self.get_media_output_loopback()
16701677
else:

sonic_platform_base/sonic_xcvr/sfp_optoe_base.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,50 @@ def get_transceiver_threshold_info(self):
3131
api = self.get_xcvr_api()
3232
return api.get_transceiver_threshold_info() if api is not None else None
3333

34+
def get_transceiver_status(self):
35+
api = self.get_xcvr_api()
36+
return api.get_transceiver_status() if api is not None else None
37+
38+
def get_transceiver_loopback(self):
39+
api = self.get_xcvr_api()
40+
return api.get_transceiver_loopback() if api is not None else None
41+
42+
def is_coherent_module(self):
43+
api = self.get_xcvr_api()
44+
return api.is_coherent_module() if api is not None else None
45+
46+
def get_transceiver_pm(self):
47+
api = self.get_xcvr_api()
48+
return api.get_transceiver_pm() if api is not None else None
49+
50+
def get_module_fw_upgrade_feature(self):
51+
api = self.get_xcvr_api()
52+
return api.get_module_fw_upgrade_feature() if api is not None else None
53+
54+
def get_module_fw_info(self):
55+
api = self.get_xcvr_api()
56+
return api.get_module_fw_info() if api is not None else None
57+
58+
def module_fw_run(self):
59+
api = self.get_xcvr_api()
60+
return api.module_fw_run() if api is not None else None
61+
62+
def module_fw_commit(self):
63+
api = self.get_xcvr_api()
64+
return api.module_fw_commit() if api is not None else None
65+
66+
def module_fw_download(self):
67+
api = self.get_xcvr_api()
68+
return api.module_fw_download() if api is not None else None
69+
70+
def module_fw_upgrade(self):
71+
api = self.get_xcvr_api()
72+
return api.module_fw_upgrade() if api is not None else None
73+
74+
def module_fw_switch(self):
75+
api = self.get_xcvr_api()
76+
return api.module_fw_switch() if api is not None else None
77+
3478
def get_rx_los(self):
3579
api = self.get_xcvr_api()
3680
if api is not None:

tests/sonic_xcvr/test_cmis.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -532,15 +532,6 @@ def test_get_transceiver_thresholds_support(self, mock_response, expected):
532532
result = self.api.get_transceiver_thresholds_support()
533533
assert result == expected
534534

535-
@pytest.mark.parametrize("mock_response, expected", [
536-
(False, True)
537-
])
538-
def test_get_transceiver_loopback_support(self, mock_response, expected):
539-
self.api.is_flat_memory = MagicMock()
540-
self.api.is_flat_memory.return_value = mock_response
541-
result = self.api.get_transceiver_loopback_support()
542-
assert result == expected
543-
544535
@pytest.mark.parametrize("mock_response, expected", [
545536
(None, False),
546537
('Power Class 1', False),
@@ -1669,6 +1660,13 @@ def test_get_transceiver_status(self, mock_response, expected):
16691660
[False, False, False, False, False, False, False, False]
16701661
],
16711662
{
1663+
'simultaneous_host_media_loopback_supported': True,
1664+
'per_lane_media_loopback_supported': True,
1665+
'per_lane_host_loopback_supported': True,
1666+
'host_side_input_loopback_supported': True,
1667+
'host_side_output_loopback_supported': True,
1668+
'media_side_input_loopback_supported': True,
1669+
'media_side_output_loopback_supported': True,
16721670
'media_output_loopback': False,
16731671
'media_input_loopback': False,
16741672
'host_output_loopback_lane1': False,
@@ -1711,6 +1709,13 @@ def test_get_transceiver_status(self, mock_response, expected):
17111709
[False, False, False, False, False, False, False, False]
17121710
],
17131711
{
1712+
'simultaneous_host_media_loopback_supported': False,
1713+
'per_lane_media_loopback_supported': False,
1714+
'per_lane_host_loopback_supported': False,
1715+
'host_side_input_loopback_supported': False,
1716+
'host_side_output_loopback_supported': False,
1717+
'media_side_input_loopback_supported': False,
1718+
'media_side_output_loopback_supported': False,
17141719
'media_output_loopback': 'N/A',
17151720
'media_input_loopback': 'N/A',
17161721
'host_output_loopback_lane1': 'N/A',
@@ -1733,8 +1738,8 @@ def test_get_transceiver_status(self, mock_response, expected):
17331738
)
17341739
])
17351740
def test_get_transceiver_loopback(self, mock_response, expected):
1736-
self.api.get_transceiver_loopback_support = MagicMock()
1737-
self.api.get_transceiver_loopback_support.return_value = mock_response[0]
1741+
self.api.is_flat_memory = MagicMock()
1742+
self.api.is_flat_memory.return_value = mock_response[0]
17381743
self.api.get_loopback_capability = MagicMock()
17391744
self.api.get_loopback_capability.return_value = mock_response[1]
17401745
self.api.get_media_output_loopback = MagicMock()

0 commit comments

Comments
 (0)