Using (pci) device id to identify the ASIC on sai_switch_create (#4705)
* Update to sonic_cfggen and utilities to populate the (pci) device id in the "asic_id" field in the DEVICE_METADATA. This Id is parsed from the file "asic.conf" file in the device/<platform> dir. The format of entries are eg: for a 2 ASIC platform. DEV_ID_ASIC_0=03:00.0 DEV_ID_ASIC_1=04:00.0 Going forward will use this device id as the asic instance ID passed to syncd/sai while doing create_switch. Current support is limited, supports only one TD2 platform.
This commit is contained in:
parent
7b18d9c15c
commit
a6877ad1b5
@ -43,6 +43,7 @@ from sonic_device_util import get_machine_info
|
||||
from sonic_device_util import get_platform_info
|
||||
from sonic_device_util import get_system_mac
|
||||
from sonic_device_util import get_npu_id_from_name
|
||||
from sonic_device_util import get_npu_device_id
|
||||
from config_samples import generate_sample_config
|
||||
from config_samples import get_available_config
|
||||
from swsssdk import SonicV2Connector, ConfigDBConnector, SonicDBConfig
|
||||
@ -304,7 +305,12 @@ def main():
|
||||
}}}
|
||||
# The ID needs to be passed to the SAI to identify the asic.
|
||||
if asic_name is not None:
|
||||
hardware_data['DEVICE_METADATA']['localhost'].update(asic_id=asic_id)
|
||||
device_id = get_npu_device_id(asic_id)
|
||||
# if the device_id obtained is None, exit with error
|
||||
if device_id is None:
|
||||
print('Failed to get device ID for', asic_name, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
hardware_data['DEVICE_METADATA']['localhost'].update(asic_id=device_id)
|
||||
deep_update(data, hardware_data)
|
||||
|
||||
if args.template is not None:
|
||||
|
@ -44,6 +44,32 @@ def get_npu_id_from_name(npu_name):
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_npu_device_id(npu_id):
|
||||
platform = get_platform_info(get_machine_info())
|
||||
if not platform:
|
||||
return None
|
||||
|
||||
asic_conf_file_path = os.path.join(SONIC_DEVICE_PATH, platform, ASIC_CONF_FILENAME)
|
||||
if not os.path.isfile(asic_conf_file_path):
|
||||
return None
|
||||
|
||||
# In a multi-npu device we need to have the file "asic.conf" updated with the asic instance
|
||||
# and the corresponding device id which could be pci_id. Below is an eg: for a 2 ASIC platform/sku.
|
||||
# DEV_ID_ASIC_0=03:00.0
|
||||
# DEV_ID_ASIC_1=04:00.0
|
||||
device_str = "DEV_ID_ASIC_{}".format(npu_id)
|
||||
|
||||
with open(asic_conf_file_path) as asic_conf_file:
|
||||
for line in asic_conf_file:
|
||||
tokens = line.split('=')
|
||||
if len(tokens) < 2:
|
||||
continue
|
||||
if tokens[0] == device_str:
|
||||
device_id = tokens[1].strip()
|
||||
return device_id
|
||||
|
||||
return None
|
||||
|
||||
def get_num_npus():
|
||||
platform = get_platform_info(get_machine_info())
|
||||
if not platform:
|
||||
|
Reference in New Issue
Block a user