Skip to content

Commit 4ec5f8e

Browse files
judyjosephqiluo-msft
authored andcommitted
Port the fix to get the PCI_id from asic.conf file from 201911 --> master branch (#7513)
Port the fix to get the pci_device ID from asic.conf file and update the "asic_id" field in DEVICE_METADATA with the pci_device_Id. Ref: #4705
1 parent 9a89c1b commit 4ec5f8e

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/sonic-config-engine/sonic-cfggen

+7-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ from functools import partial
4141
from minigraph import minigraph_encoder, parse_xml, parse_device_desc_xml, parse_asic_sub_role
4242
from portconfig import get_port_config, get_breakout_mode
4343
from redis_bcc import RedisBytecodeCache
44-
from sonic_py_common.multi_asic import get_asic_id_from_name
44+
from sonic_py_common.multi_asic import get_asic_id_from_name, get_asic_device_id
4545
from sonic_py_common import device_info
4646
from swsscommon.swsscommon import SonicV2Connector, ConfigDBConnector, SonicDBConfig, ConfigDBPipeConnector
4747

@@ -377,7 +377,12 @@ def main():
377377
}}}
378378
# The ID needs to be passed to the SAI to identify the asic.
379379
if asic_name is not None:
380-
hardware_data['DEVICE_METADATA']['localhost'].update(asic_id=asic_id)
380+
device_id = get_asic_device_id(asic_id)
381+
# if the device_id obtained is None, exit with error
382+
if device_id is None:
383+
print('Failed to get device ID for', asic_name, file=sys.stderr)
384+
sys.exit(1)
385+
hardware_data['DEVICE_METADATA']['localhost'].update(asic_id=device_id)
381386
deep_update(data, hardware_data)
382387

383388
paths = ['/', '/usr/share/sonic/templates']

src/sonic-py-common/sonic_py_common/multi_asic.py

+23
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,29 @@ def get_asic_id_from_name(asic_name):
137137
else:
138138
raise ValueError('Unknown asic namespace name {}'.format(asic_name))
139139

140+
def get_asic_device_id(asic_id):
141+
# Get asic.conf file
142+
asic_conf_file_path = get_asic_conf_file_path()
143+
144+
if asic_conf_file_path is None:
145+
return None
146+
147+
# In a multi-asic device we need to have the file "asic.conf" updated with the asic instance
148+
# and the corresponding device id which could be pci_id. Below is an eg: for a 2 ASIC platform/sku.
149+
# DEV_ID_ASIC_0=03:00.0
150+
# DEV_ID_ASIC_1=04:00.0
151+
device_str = "DEV_ID_ASIC_{}".format(asic_id)
152+
153+
with open(asic_conf_file_path) as asic_conf_file:
154+
for line in asic_conf_file:
155+
tokens = line.split('=')
156+
if len(tokens) < 2:
157+
continue
158+
if tokens[0] == device_str:
159+
device_id = tokens[1].strip()
160+
return device_id
161+
162+
return None
140163

141164
def get_current_namespace(pid=None):
142165
"""

0 commit comments

Comments
 (0)