Skip to content

[cmis] Fix enter_password to include standard password entry method - #724

Open
Junchao-Mellanox wants to merge 4 commits into
sonic-net:masterfrom
Junchao-Mellanox:public/pr-19
Open

[cmis] Fix enter_password to include standard password entry method#724
Junchao-Mellanox wants to merge 4 commits into
sonic-net:masterfrom
Junchao-Mellanox:public/pr-19

Conversation

@Junchao-Mellanox

Copy link
Copy Markdown
Contributor

Why I did it

CdbCmdHandler.enter_password() previously delivered the CMIS host password only via CDB command 0001h. This is not the standard mechanism defined by the CMIS spec and is not honored by all modules — the standard, universally-supported way to unlock password-protected CDB/EEPROM access is to write the 4-byte host password (MSB first) to the Password Entry Area at page 00h bytes 122-125. As a result, password entry would fail on modules that only unlock via the Password Entry Area, blocking protected CDB/EEPROM operations (e.g. firmware/SED-protected access) on those modules.

How I did it

  • cdb.py — Reworked enter_password() to first write the password to the Password Entry Area (page 00h bytes 122-125, MSB first) using write_raw, which is the standard method honored by all CMIS modules. If that write fails, it falls back to the original CDB command 0001h path for modules that rely on it. Input validation (integer in range 0..0xFFFFFFFF) is preserved, and struct is used to pack the 32-bit password big-endian.
  • cdb_consts.py — Added CDB_HOST_PASSWORD_ENTRY_OFFSET = 122 and CDB_HOST_PASSWORD_ENTRY_SIZE = 4 with documentation describing the Password Entry Area register layout.
  • test_cdb.py — Updated existing tests to assert the password is now written MSB-first to the Password Entry Area (and that no CDB command is sent when the register write succeeds), and added test_enter_password_fallback_to_cdb_command to cover the fallback path when the register write fails.

How to verify it

Ran the updated unit tests in tests/sonic_xcvr/test_cdb.py, covering:

  • test_enter_password_valid — password written MSB-first to the Password Entry Area, no CDB command issued.
  • test_enter_password_default — default password (0x00001011) written to the Password Entry Area.
  • test_enter_password_fallback_to_cdb_command — CDB command 0001h used as fallback when the register write returns False.

#### Why I did it
`CdbCmdHandler.enter_password()` previously delivered the CMIS host password only via CDB command `0001h`. This is not the standard mechanism defined by the CMIS spec and is not honored by all modules — the standard, universally-supported way to unlock password-protected CDB/EEPROM access is to write the 4-byte host password (MSB first) to the Password Entry Area at page 00h bytes 122-125. As a result, password entry would fail on modules that only unlock via the Password Entry Area, blocking protected CDB/EEPROM operations (e.g. firmware/SED-protected access) on those modules.

#### How I did it
- `cdb.py` — Reworked `enter_password()` to first write the password to the Password Entry Area (page 00h bytes 122-125, MSB first) using `write_raw`, which is the standard method honored by all CMIS modules. If that write fails, it falls back to the original CDB command `0001h` path for modules that rely on it. Input validation (integer in range `0..0xFFFFFFFF`) is preserved, and `struct` is used to pack the 32-bit password big-endian.
- `cdb_consts.py` — Added `CDB_HOST_PASSWORD_ENTRY_OFFSET = 122` and `CDB_HOST_PASSWORD_ENTRY_SIZE = 4` with documentation describing the Password Entry Area register layout.
- `test_cdb.py` — Updated existing tests to assert the password is now written MSB-first to the Password Entry Area (and that no CDB command is sent when the register write succeeds), and added `test_enter_password_fallback_to_cdb_command` to cover the fallback path when the register write fails.

#### How to verify it
Ran the updated unit tests in `tests/sonic_xcvr/test_cdb.py`, covering:
- `test_enter_password_valid` — password written MSB-first to the Password Entry Area, no CDB command issued.
- `test_enter_password_default` — default password (`0x00001011`) written to the Password Entry Area.
- `test_enter_password_fallback_to_cdb_command` — CDB command `0001h` used as fallback when the register write returns `False`.

Signed-off-by: Junchao Chen <junchao@mellanox.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@Junchao-Mellanox

Copy link
Copy Markdown
Contributor Author

Hi @prgeor , @mihirpat1 , could you please help review this? Thanks!

stephenxs
stephenxs previously approved these changes Jul 21, 2026
Comment thread sonic_platform_base/sonic_xcvr/cdb/cdb.py Outdated
Comment thread sonic_platform_base/sonic_xcvr/cdb/cdb.py Outdated
Signed-off-by: Junchao Chen <junchao@mellanox.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@bgallagher-nexthop bgallagher-nexthop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍

Comment thread sonic_platform_base/sonic_xcvr/fields/cdb_consts.py Outdated
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Reduced the polling interval for password result checks.

Signed-off-by: Junchao Chen <junchao@mellanox.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

keboliu
keboliu previously approved these changes Jul 28, 2026
Comment thread sonic_platform_base/sonic_xcvr/cdb/cdb.py Outdated
Comment thread sonic_platform_base/sonic_xcvr/cdb/cdb.py Outdated
Comment thread sonic_platform_base/sonic_xcvr/cdb/cdb.py Outdated
Comment thread sonic_platform_base/sonic_xcvr/cdb/cdb.py Outdated
Comment thread sonic_platform_base/sonic_xcvr/cdb/cdb.py Outdated
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Signed-off-by: Junchao Chen <junchao@mellanox.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@Junchao-Mellanox
Junchao-Mellanox requested a review from prgeor July 30, 2026 03:13
class CdbFwHandler(CdbCmdHandler):
def __init__(self, reader, writer, mem_map):
super(CdbFwHandler, self).__init__(reader, writer, mem_map)
def __init__(self, reader, writer, mem_map, cmis_api):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Junchao-Mellanox please avoid polluting the namespace by introducing cmis_api into the CdbFwHandler. The handler is a service provider....the API is the user lets not inter-twine both of them.

@Junchao-Mellanox Junchao-Mellanox Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @prgeor , we cannot achieve following 2 items together:

  1. Not putting cmis_api to CdbFwHandler (Your current review comment)
  2. Put all memory password related logic to CmisAPI, cmis memory map, cmis consts. (Your previous review comment)

If we choose 1, we will need to put all memory password related logic to Cdb scope, including some duplicate logic such as implementing cdb.get_cmis_rev ; otherwise, we will need to put cmis_api to CdbFwHandler. I don't see other option. Please decide what to do.

@Junchao-Mellanox
Junchao-Mellanox requested a review from prgeor August 2, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants