Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CMIS] Return the CDB status value for the caller to check the status… #485

Merged
merged 4 commits into from
Sep 9, 2024

Conversation

xinyulin
Copy link
Contributor

@xinyulin xinyulin commented Jul 19, 2024

Description

This PR unifies all CDB API calls to return CDB status, allowing the caller to check the command status returned from the module and perform corresponding actions.

Motivation and Context

Modified the following CDB APIs to return a dictionary with CDB status as the first element and RPL result as the second element.

  • query_cdb_status()
  • get_module_feature()
  • get_fw_management_features()
  • get_fw_info()

The caller can first check the CDB status to ensure the command was processed successfully, then retrieve the data from the reply payload (RPL).

How Has This Been Tested?

Tested with Cisco8111 and Credo C1 cable
image

@@ -1282,7 +1282,7 @@ def get_module_fw_info(self):
return {'status': False, 'info': "CDB Not supported", 'result': None}

# get fw info (CMD 0100h)
rpllen, rpl_chkcode, rpl = self.cdb.get_fw_info()
rpllen, rpl_chkcode, rpl = self.cdb.get_fw_info()['rpl']
Copy link
Contributor

Choose a reason for hiding this comment

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

@xinyulin Can we check for the value of self.cdb.get_fw_info()['status'] and take appropriate action?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mihirpat1 I have added the check and corresponding actions in the get_module_fw_mgmt_feature() and get_module_fw_info() functions. Could you please review them again? Thanks.

@xinyulin xinyulin force-pushed the cmis_cdb_status branch 8 times, most recently from 04560e3 to a66b757 Compare July 28, 2024 15:11
@@ -1281,7 +1284,7 @@ def get_module_fw_mgmt_feature(self, verbose = False):
elapsedtime = time.time()-starttime
logger.info('Get module FW upgrade features time: %.2f s\n' %elapsedtime)
logger.info(txt)
return {'status': True, 'info': txt, 'feature': (startLPLsize, maxblocksize, lplonly_flag, autopaging_flag, writelength)}
return {'status': True, 'info': txt, 'result': (startLPLsize, maxblocksize, lplonly_flag, autopaging_flag, writelength)}
Copy link
Contributor

Choose a reason for hiding this comment

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

change the field from feature to result will break the method caller!
e.g. https://github.com/sonic-net/sonic-utilities/blob/84cb00a4b2d7e8fb2bcab259367836fa11a17d0a/sfputil/main.py#L1528

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rqx110 thanks for your review and comment, I will change it back to feature.

@xinyulin xinyulin force-pushed the cmis_cdb_status branch 13 times, most recently from 2556588 to ef46a57 Compare July 30, 2024 15:40
@@ -1277,7 +1280,7 @@ def get_module_fw_mgmt_feature(self, verbose = False):

else:
txt += 'Reply payload check code error\n'
return {'status': False, 'info': txt, 'result': None}
return {'status': False, 'info': txt, 'feature': None}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mihirpat1 As suggested by rqx110, I should ensure that get_module_fw_mgmt_feature() returns a dictionary with the key 'feature' instead of 'result'; otherwise, other callers may not function properly. To ensure consistency in the output dictionary keys, I have also corrected the key to 'feature' for error cases.

Copy link
Contributor

@mihirpat1 mihirpat1 left a comment

Choose a reason for hiding this comment

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

@xinyulin Can you please test FW download + run + commit if not already tested with the changes?

'''
cmd = bytearray(b'\x00\x00\x00\x00\x02\x00\x00\x00\x00\x10')
cmd[133-INIT_OFFSET] = self.cdb_chkcode(cmd)
self.write_cdb(cmd)
status = self.cdb1_chkstatus()
if (status != 0x1):
Copy link
Contributor

Choose a reason for hiding this comment

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

@xinyulin Can you please revert this unrelated change to avoid increasing line history (agreed that the version without parenthesis is more pythonic though). Please do the same for similar changes in the diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I have reverted it.

@@ -1277,7 +1280,7 @@ def get_module_fw_mgmt_feature(self, verbose = False):

else:
txt += 'Reply payload check code error\n'
return {'status': False, 'info': txt, 'result': None}
return {'status': False, 'info': txt, 'feature': None}
Copy link
Contributor

Choose a reason for hiding this comment

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

@xinyulin Can we log an error with the value of status here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This error will be logged with the following format in the latest commit

        else:
            txt += 'Status or reply payload check code error\n'
            logger.info(txt)
            logger.info('Fail to get fw mgnt feature, cdb status: 0x{}\n'.format(status))
            return {'status': False, 'info': txt, 'feature': None}

The new commit has been tested with firmware download, run, and commit flows without any errors. Could you please review it to see if anything is missing.

Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion, there is no need to log here. The method caller will make the judgment and log the result.
for example:
https://github.com/sonic-net/sonic-utilities/blob/f50587a1ff65bb489231bfe45cec805fb32dbf00/sfputil/main.py#L1526-L1531

Copy link
Contributor

Choose a reason for hiding this comment

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

@rqx110 I think capturing the status and rpl_chkcode as part of logs will help in providing more datapoints to debug in case of an error.

return {'status': False, 'info': txt, 'result': None}
txt += 'Status or reply payload check code error\n'
logger.info(txt)
logger.info('Fail to get fw mgnt feature, cdb status: 0x{}\n'.format(status))
Copy link
Contributor

@rqx110 rqx110 Aug 5, 2024

Choose a reason for hiding this comment

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

Suggested change
logger.info('Fail to get fw mgnt feature, cdb status: 0x{}\n'.format(status))
logger.info('Fail to get fw mgmt feature, cdb status: {:#x}\n'.format(status))

Copy link
Contributor

Choose a reason for hiding this comment

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

@xinyulin Can you please log the value of rpl_chkcode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. both rpl_chkcode and check result are recorded in the new commit.

return {'status': False, 'info': txt, 'result': None}
txt += 'Status or reply payload check code error\n'
logger.info(txt)
logger.info('Fail to get fw mgnt feature, cdb status: {:#x} rpl_chkcode: {:#x}, {:#x}\n'.format(status, self.cdb.cdb_chkcode(rpl), rpl_chkcode))
Copy link
Contributor

Choose a reason for hiding this comment

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

First, mgnt should mgmt
Second, missing ',' after cdb status: {:#x}
Third, the message rpl_chkcode: {:#x}, {:#x} is not very clear. When leaving the code, do you know what the first and second values ​​represent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rqx110 Thank you for the review. I have added more details and corrected the incorrect abbreviation.

return {'status': False, 'info': txt, 'result': None}
txt += 'Status or reply payload check code error\n'
logger.info(txt)
logger.info('Fail to get fw mgmt feature, cdb status: {:#x}, cdb_chkcode: {:#x}, rpl_chkcode: {:#x}\n'.format(status, self.cdb.cdb_chkcode(rpl), rpl_chkcode))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.info('Fail to get fw mgmt feature, cdb status: {:#x}, cdb_chkcode: {:#x}, rpl_chkcode: {:#x}\n'.format(status, self.cdb.cdb_chkcode(rpl), rpl_chkcode))
logger.error('Fail to get fw mgmt feature, cdb status: {:#x}, cdb_chkcode: {:#x}, rpl_chkcode: {:#x}\n'.format(status, self.cdb.cdb_chkcode(rpl), rpl_chkcode))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mihirpat1 Thanks for the suggestion, I have modified it accordingly.

@prgeor prgeor merged commit 174bbd4 into sonic-net:master Sep 9, 2024
5 checks passed
@prgeor
Copy link
Collaborator

prgeor commented Sep 9, 2024

@bingwang-ms could you take this to 202405. This is for improved debugging.

@mihirpat1
Copy link
Contributor

@bingwang-ms MSFT ADO - 26804772

mssonicbld pushed a commit to mssonicbld/sonic-platform-common that referenced this pull request Sep 9, 2024
sonic-net#485)

* [CMIS] Return the CDB status value for the caller to check the status and perform the corresponding actions

Signed-off-by: xinyu <[email protected]>

* [CMIS] Log an error when failing to retrieve the CDB firmware management feature command

Signed-off-by: xinyu <[email protected]>

* [CMIS] Log get fw mgmt feature RPL check code result to provide clearer data when an error occurs

Signed-off-by: xinyu <[email protected]>

* [CMIS] Chagne log level from info to error for fail to get fw mgmt feature

Signed-off-by: xinyu <[email protected]>

---------

Signed-off-by: xinyu <[email protected]>
@mssonicbld
Copy link
Collaborator

Cherry-pick PR to 202405: #496

mssonicbld pushed a commit that referenced this pull request Sep 9, 2024
#485)

* [CMIS] Return the CDB status value for the caller to check the status and perform the corresponding actions

Signed-off-by: xinyu <[email protected]>

* [CMIS] Log an error when failing to retrieve the CDB firmware management feature command

Signed-off-by: xinyu <[email protected]>

* [CMIS] Log get fw mgmt feature RPL check code result to provide clearer data when an error occurs

Signed-off-by: xinyu <[email protected]>

* [CMIS] Chagne log level from info to error for fail to get fw mgmt feature

Signed-off-by: xinyu <[email protected]>

---------

Signed-off-by: xinyu <[email protected]>
@xinyulin xinyulin deleted the cmis_cdb_status branch September 12, 2024 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants