Skip to content

Refactor CMIS memory map into pages#667

Open
aditya-nexthop wants to merge 10 commits into
sonic-net:masterfrom
nexthop-ai:aditya.cmis-mem-map-refactor
Open

Refactor CMIS memory map into pages#667
aditya-nexthop wants to merge 10 commits into
sonic-net:masterfrom
nexthop-ai:aditya.cmis-mem-map-refactor

Conversation

@aditya-nexthop
Copy link
Copy Markdown
Contributor

@aditya-nexthop aditya-nexthop commented May 18, 2026

Cherry pick commits from nexthop-ai#1 to public fork since it wasn't possible to move the original PR to sonic-net

This PR implements part 1 of 2 of the HLD described here.
It introduces the CmisPage class and refactors CMIS Mem Map into pages

Description

Refactor the CMIS memory map from a single monolithic class into per-page
classes that each own their own field definitions.

  • Introduces a new sonic_platform_base/sonic_xcvr/mem_maps/public/cmis_pages/
    package with one module per CMIS page:
    • pg_00_administrative_lower.py / pg_00_administrative_upper.py
    • pg_01_advertising.py
    • pg_02_thresholds.py
    • pg_10_lane_datapath_config.py
    • pg_11_lane_datapath_status.py
    • pg_12_tunable_laser_ctrl_status.py
    • pg_13_module_perf_diag_ctrl.py
    • pg_2f_vdm_advertising_ctrl.py
    • pg_9f_cdb_message.py
  • Adds a CmisPage base class (cmis_pages/base.py) that:
    • Stores its own page and bank numbers.
    • Implements getaddr(offset, page_size) so each page computes linear
      EEPROM offsets locally instead of relying on CmisFlatMemMap.getaddr.
    • Provides register_fields(memmap), which composes the page's fields
      onto the parent memory map and merges shared RegGroupFields (e.g.
      ADMIN_INFO_FIELD, ADVERTISING_FIELD) that span multiple pages,
      re-sorting members by offset to preserve the RegGroupField invariant.
  • Adds cmis_pages/cmis_page_consts.py with CMIS layout constants
    (CMIS_EEPROM_PAGE_SIZE, CMIS_ARCH_PAGES,
    CMIS_NUM_NON_BANKED_PAGES, and page-number constants).
  • Reworks cmis.py:
    • CmisFlatMemMap now exposes an add_pages(*pages) helper that appends
      to self.pages and calls register_fields on each page.
    • CmisFlatMemMap composes only the lower and upper halves of page 0x00.
    • CmisMemMap extends it by adding pages 0x01, 0x02, 0x10–0x13, 0x2F,
      and 0x9F.
    • getaddr now takes page as an explicit parameter and clamps bank
      to 0 for non-banked pages (00h–0Fh) and CDB pages (9Fh–AFh).
  • Registers the new cmis_pages package in setup.py.

Net diff: cmis.py shrinks from ~720 lines to ~120 lines, with the field
definitions redistributed across the per-page modules.

Motivation and Context

The previous CmisFlatMemMap / CmisMemMap implementation defined every
field for every CMIS page inside a single ~700-line class. This made it
hard to:

  • Locate the fields belonging to a given page.
  • Compose alternative memory maps (e.g. flat vs. paged, per-bank variants)
    without duplicating large blocks of field definitions.
  • Re-map an entire page (for vendor-specific layouts or future CMIS
    revisions) without editing the monolithic class.

Splitting the map into per-page classes makes each page self-contained
and addressable, lets CmisFlatMemMap and CmisMemMap declare their
contents by listing the pages they include, and allows shared field
groups that cross page boundaries (like ADMIN_INFO_FIELD spanning lower
and upper page 00h, or ADVERTISING_FIELD spanning pages 01h and 11h)
to be merged automatically by register_fields.

Exposing the page number as a constructor parameter on each page class
also enables entire pages to be remapped easily without duplicating field
declarations.

How Has This Been Tested?

This change introduces no new fields or changes in behavior.
All the existing unit tests pass.

Additional Information (Optional)

This change is intended to be behavior-preserving: the resulting
CmisMemMap exposes the same set of named fields at the same EEPROM
offsets as before the refactor. Only the internal organization of the
memory map definition changes.

abhi-nexthop and others added 5 commits May 18, 2026 17:05
Signed-off-by: Abhi Singh <abhi@nexthop.ai>
…on easier

Signed-off-by: Brian Gallagher <bgallagher@nexthop.ai>
Signed-off-by: Brian Gallagher <bgallagher@nexthop.ai>
Signed-off-by: Brian Gallagher <bgallagher@nexthop.ai>
Signed-off-by: Brian Gallagher <bgallagher@nexthop.ai>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@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: aditya-nexthop <aditya@nexthop.ai>
@aditya-nexthop aditya-nexthop force-pushed the aditya.cmis-mem-map-refactor branch from a9cfe9a to 1c4c917 Compare May 18, 2026 17:56
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

page model to handle bank calculation correctly.

Signed-off-by: aditya-nexthop <aditya@nexthop.ai>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown
Collaborator

@prgeor prgeor May 18, 2026

Choose a reason for hiding this comment

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

@aditya-nexthop may I suggest to have following dir style?

../public/cmis/pages/

page00.py
page01.py
page02.py
...
...
...
page2f.py
page9f.py

../public/cmis/cmis.py

The page file anywas has comment to indicate what this memmap corresponds to.

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.

updated

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.

I realized that this changes the location of cmis.py that holds theCmisFlatMemMap and CmisMemMap from sonic_platform_base/sonic_xcvr/mem_maps/public/cmis.py to sonic_platform_base/sonic_xcvr/mem_maps/public/cmis/cmis.py.

We now have a divergence where, cmis.py is inside the cmis directory while cdb.py and c_cmis.py is still in sonic_platform_base/sonic_xcvr/mem_maps/public/. I recommend all of them are at the same depth.

Where should we put them? Inside cmis or outside?

Comment thread sonic_platform_base/sonic_xcvr/mem_maps/public/cmis/pages/page.py
Copy link
Copy Markdown
Collaborator

@prgeor prgeor left a comment

Choose a reason for hiding this comment

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

@aditya-nexthop have we considered if any impact to link up time (fully loaded system), dom polling interval, link initialization when single optics insertion. A comparison will be good.

Comment thread sonic_platform_base/sonic_xcvr/mem_maps/public/cmis/pages/page9f.py
Signed-off-by: aditya-nexthop <aditya@nexthop.ai>
…e class

Signed-off-by: aditya-nexthop <aditya@nexthop.ai>
Signed-off-by: aditya-nexthop <aditya@nexthop.ai>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

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.

5 participants