Skip to content

Commit

Permalink
Add custom media setting for CMIS
Browse files Browse the repository at this point in the history
Signed-off-by: Dante Su <dante.su@broadcom.com>
  • Loading branch information
ds952811 committed Nov 18, 2021
1 parent 6dd3608 commit 11b6850
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions sonic-xcvrd/xcvrd/xcvrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,20 @@ def get_media_settings_key(physical_port, transceiver_dict):

return [vendor_key, media_key]

def get_media_settings_cmis(transceiver_dict):
CMIS_MEDIA_SETTINGS_KEY = 'CMIS_MEDIA_SETTINGS'

if CMIS_MEDIA_SETTINGS_KEY not in g_dict:
return {}

vendor_name_str = transceiver_dict['manufacturer']
vendor_pn_str = transceiver_dict['model']
vendor_key = (vendor_name_str.strip() + '#' + vendor_pn_str.strip()).upper()

for k, v in g_dict[CMIS_MEDIA_SETTINGS_KEY].items():
if k.upper() == vendor_key:
return v
return {}

def get_media_val_str_from_dict(media_dict):
LANE_STR = 'lane'
Expand Down Expand Up @@ -861,7 +875,7 @@ def __init__(self, port_mapping):
self.port_mapping = copy.deepcopy(port_mapping)

def log_notice(self, message):
helper_logger.log_notice("CMIS (pid {0}): {1}".format(os.getpid(), message))
helper_logger.log_notice("CMIS: {}".format(message))

def on_port_config_change(self, port_change_event):
if port_change_event.event_type != port_change_event.PORT_SET:
Expand Down Expand Up @@ -894,7 +908,7 @@ def on_port_config_change(self, port_change_event):
time.sleep(0.001)

def task_worker(self, commander):
self.log_notice("Starting...{}".format(commander))
self.log_notice("Starting...")

if commander:
sel, asic_context = port_mapping.subscribe_port_config_change()
Expand Down Expand Up @@ -922,10 +936,39 @@ def task_worker(self, commander):
continue

try:
ret = sfp.set_cmis_application(speed, len(lanes))
# Skip if the port/cage type is not QSFP-DD
if sfp.SFP_PORT_TYPE_QSFPDD != sfp.get_port_type():
continue
# Skip if the xcvr type is not QSFP-DD
info = sfp.get_transceiver_info()
if info.get('type_abbrv_name', None) not in ['QSFP-DD', 'QSFP_DD']:
continue
# Skip if the memory type is flat
if info.get('memory_type', 'flat') in ['flat', 'FLAT']:
continue

# Fetch the custom CMIS media setting from media_settings.json
conf = get_media_settings_cmis(info)
if conf is None:
conf = {}
# Enable application selection by default
if conf.get('application_selection', True):
self.log_notice("{}: application update for {}G, {}-lanes".format(
lport, int(speed/1000), len(lanes)))
ret = sfp.set_cmis_application(speed, len(lanes))
else:
ret = None
except (NotImplementedError, AttributeError):
ret = False
self.log_notice("{0}: {1}".format(lport, "succeeded" if ret else "failed"))
ret = None

if ret is None:
state = "skipped"
elif not ret:
state = "failed"
else:
state = "ok"

self.log_notice("{}: application update ... {}".format(lport, state))

self.log_notice("Stopped")

Expand Down

0 comments on commit 11b6850

Please sign in to comment.