Skip to content

Commit

Permalink
[CMIS] Add API to get module power up duration (sonic-net#354)
Browse files Browse the repository at this point in the history
* [CMIS] Add API to get module power up duration

Add API to get moulde power up and power down duration

Signed-off-by: chiourung_huang <chiourung_huang@edge-core.com>

* modify function name after code review

* modify function name after code review for test case

---------

Signed-off-by: chiourung_huang <chiourung_huang@edge-core.com>
  • Loading branch information
chiourung authored Mar 22, 2023
1 parent d3f9b2f commit 6e24d32
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
18 changes: 18 additions & 0 deletions sonic_platform_base/sonic_xcvr/api/public/cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,24 @@ def get_datapath_deinit_duration(self):
duration = self.xcvr_eeprom.read(consts.DP_PATH_DEINIT_DURATION)
return float(duration) if duration is not None else 0

def get_module_pwr_up_duration(self):
'''
This function returns the duration of module power up
'''
if self.is_flat_memory():
return 0
duration = self.xcvr_eeprom.read(consts.MODULE_PWRUP_DURATION)
return float(duration) if duration is not None else 0

def get_module_pwr_down_duration(self):
'''
This function returns the duration of module power down
'''
if self.is_flat_memory():
return 0
duration = self.xcvr_eeprom.read(consts.MODULE_PWRDN_DURATION)
return float(duration) if duration is not None else 0

def get_host_lane_count(self):
'''
This function returns number of host lanes for default application
Expand Down
2 changes: 2 additions & 0 deletions sonic_platform_base/sonic_xcvr/fields/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@
INACTIVE_FW_MINOR_REV = "ModuleInactiveFirmwareMinorRevision"
DP_PATH_INIT_DURATION = "DPInitDuration"
DP_PATH_DEINIT_DURATION = "DPDeinitDuration"
MODULE_PWRUP_DURATION = "ModulePowerUpDuration"
MODULE_PWRDN_DURATION = "ModulePowerDownDuration"

# DOM
TRANS_DOM_FIELD = "TransceiverDom"
Expand Down
6 changes: 6 additions & 0 deletions sonic_platform_base/sonic_xcvr/mem_maps/public/cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ def __init__(self, codes):
CodeRegField(consts.DP_PATH_DEINIT_DURATION, self.getaddr(0x1, 144), self.codes.DP_PATH_TIMINGS,
*(RegBitField("Bit%d" % (bit), bit) for bit in range (4, 8))
),
CodeRegField(consts.MODULE_PWRUP_DURATION, self.getaddr(0x1, 167), self.codes.DP_PATH_TIMINGS,
*(RegBitField("Bit%d" % (bit), bit) for bit in range (0, 4))
),
CodeRegField(consts.MODULE_PWRDN_DURATION, self.getaddr(0x1, 167), self.codes.DP_PATH_TIMINGS,
*(RegBitField("Bit%d" % (bit), bit) for bit in range (4, 8))
),
NumberRegField(consts.MEDIA_LANE_ASSIGNMENT_OPTION, self.getaddr(0x1, 176), format="B", size=1),

RegGroupField(consts.ACTIVE_APSEL_CODE,
Expand Down
28 changes: 28 additions & 0 deletions tests/sonic_xcvr/test_cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,34 @@ def test_get_datapath_deinit_duration(self, mock_response1, mock_response2, expe
result = self.api.get_datapath_deinit_duration()
assert result == expected

@pytest.mark.parametrize("mock_response1, mock_response2, expected", [
(True, '10', 0 ),
(False, None, 0),
(False, '8', 8.0),
(False, '5000000', 5000000.0),
])
def test_get_module_pwr_up_duration(self, mock_response1, mock_response2, expected):
self.api.is_flat_memory = MagicMock()
self.api.is_flat_memory.return_value = mock_response1
self.api.xcvr_eeprom.read = MagicMock()
self.api.xcvr_eeprom.read.return_value = mock_response2
result = self.api.get_module_pwr_up_duration()
assert result == expected

@pytest.mark.parametrize("mock_response1, mock_response2, expected", [
(True, '1', 0 ),
(False, None, 0),
(False, '6', 6.0),
(False, '80000', 80000.0),
])
def test_get_module_pwr_down_duration(self, mock_response1, mock_response2, expected):
self.api.is_flat_memory = MagicMock()
self.api.is_flat_memory.return_value = mock_response1
self.api.xcvr_eeprom.read = MagicMock()
self.api.xcvr_eeprom.read.return_value = mock_response2
result = self.api.get_module_pwr_down_duration()
assert result == expected

@pytest.mark.parametrize("mock_response, expected", [
(8, 8)
])
Expand Down

0 comments on commit 6e24d32

Please sign in to comment.