Skip to content

Commit

Permalink
[mellanox] extend cpld logic for x86_64-nvidia_sn4280-r0 (sonic-net#345)
Browse files Browse the repository at this point in the history
* add DPU FPGA support
* add SN4280 CPLD support
  • Loading branch information
Yakiv-Huryk authored and vivekrnv committed May 31, 2024
1 parent 7e8fdf3 commit cc07d86
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"CPLD1": { },
"CPLD2": { },
"CPLD3": { },
"CPLD4": { }
"DPU1_FPGA": { },
"DPU2_FPGA": { },
"DPU3_FPGA": { },
"DPU4_FPGA": { }
}
}
}
Expand Down
43 changes: 42 additions & 1 deletion platform/mellanox/mlnx-platform-api/sonic_platform/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ class ComponentCPLD(Component):

MST_DEVICE_PATH = '/dev/mst'
MST_DEVICE_PATTERN = 'mt[0-9]*_pci_cr0'
FW_VERSION_FORMAT = 'CPLD{}_REV{}{}'

CPLD_NUMBER_FILE = '/var/run/hw-management/config/cpld_num'
CPLD_PART_NUMBER_FILE = '/var/run/hw-management/system/cpld{}_pn'
Expand Down Expand Up @@ -833,7 +834,7 @@ def get_firmware_version(self):
version = version.rstrip('\n').zfill(self.CPLD_VERSION_MAX_LENGTH)
version_minor = version_minor.rstrip('\n').zfill(self.CPLD_VERSION_MINOR_MAX_LENGTH)

return "CPLD{}_REV{}{}".format(part_number, version, version_minor)
return self.FW_VERSION_FORMAT.format(part_number, version, version_minor)

def get_available_firmware_version(self, image_path):
with MPFAManager(image_path) as mpfa:
Expand Down Expand Up @@ -906,3 +907,43 @@ def _install_firmware(self, image_path):
return False

return True

class ComponentCPLDSN4280(ComponentCPLD):
CPLD_FIRMWARE_UPDATE_COMMAND = ['cpldupdate', '--gpio', '--print-progress', '']

def _install_firmware(self, image_path):
self.CPLD_FIRMWARE_UPDATE_COMMAND[3] = image_path

try:
print("INFO: Installing {} firmware update: path={}".format(self.name, image_path))
subprocess.check_call(self.CPLD_FIRMWARE_UPDATE_COMMAND, universal_newlines=True)
except subprocess.CalledProcessError as e:
print("ERROR: Failed to update {} firmware: {}".format(self.name, str(e)))
return False

return True

class ComponenetFPGADPU(ComponentCPLD):
CPLD_NUMBER_FILE = '/var/run/hw-management/config/dpu_num'

COMPONENT_NAME = 'DPU{}_FPGA'
COMPONENT_DESCRIPTION = 'FPGA - Field-Programmable Gate Array'
FW_VERSION_FORMAT = 'FPGA{}_REV{}{}'

CPLD_PART_NUMBER_FILE = '/var/run/hw-management/dpu{}/system/fpga1_pn'
CPLD_VERSION_FILE = '/var/run/hw-management/dpu{}/system/fpga1_version'
CPLD_VERSION_MINOR_FILE = '/var/run/hw-management/dpu{}/system/fpga1_version_min'

CPLD_FIRMWARE_UPDATE_COMMAND = ['cpldupdate', '--cpld_chain 2', '--gpio', '--print-progress', '']

def _install_firmware(self, image_path):
self.CPLD_FIRMWARE_UPDATE_COMMAND[4] = image_path

try:
print("INFO: Installing {} firmware update: path={}".format(self.name, image_path))
subprocess.check_call(self.CPLD_FIRMWARE_UPDATE_COMMAND, universal_newlines=True)
except subprocess.CalledProcessError as e:
print("ERROR: Failed to update {} firmware: {}".format(self.name, str(e)))
return False

return True
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,13 @@ def get_bios_component(cls):

@classmethod
def get_cpld_component_list(cls):
from .component import ComponentCPLD, ComponentCPLDSN2201
from .component import ComponentCPLD, ComponentCPLDSN2201, ComponentCPLDSN4280, ComponenetFPGADPU
if cls.get_platform_name() in ['x86_64-nvidia_sn2201-r0']:
# For SN2201, special chass is required for handle BIOS
# Currently, only fetching BIOS version is supported
return ComponentCPLDSN2201.get_component_list()
if cls.get_platform_name() in ['x86_64-nvidia_sn4280-r0']:
return ComponentCPLDSN4280.get_component_list() + ComponenetFPGADPU.get_component_list()
return ComponentCPLD.get_component_list()

@classmethod
Expand Down
23 changes: 23 additions & 0 deletions platform/mellanox/mlnx-platform-api/tests/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
ComponentBIOSSN2201, \
ComponentCPLD, \
ComponentCPLDSN2201, \
ComponentCPLDSN4280, \
ComponenetFPGADPU, \
MPFAManager, \
ONIEUpdater, \
Component
Expand Down Expand Up @@ -284,6 +286,13 @@ def test_cpld_get_component_list(self):
for index, item in enumerate(component_list):
assert item.name == 'CPLD{}'.format(index + 1)

@mock.patch('sonic_platform.component.ComponenetFPGADPU._read_generic_file', mock.MagicMock(return_value='4'))
def test_cpld_get_component_list_dpu(self):
component_list = ComponenetFPGADPU.get_component_list()
assert len(component_list) == 4
for index, item in enumerate(component_list):
assert item.name == 'DPU{}_FPGA'.format(index + 1)

def test_cpld_get_mst_device(self):
ComponentCPLD.MST_DEVICE_PATH = '/tmp/mst'
os.system('rm -rf /tmp/mst')
Expand All @@ -302,6 +311,20 @@ def test_cpld_2201_component(self, mock_check_call):
mock_check_call.side_effect = subprocess.CalledProcessError(1, None)
assert not c._install_firmware('')

@mock.patch('sonic_platform.component.subprocess.check_call')
def test_cpld_4280_component(self, mock_check_call):
c = ComponentCPLDSN4280(1)
assert c._install_firmware('')
mock_check_call.side_effect = subprocess.CalledProcessError(1, None)
assert not c._install_firmware('')

@mock.patch('sonic_platform.component.subprocess.check_call')
def test_cpld_dpu_component(self, mock_check_call):
c = ComponenetFPGADPU(1)
assert c._install_firmware('')
mock_check_call.side_effect = subprocess.CalledProcessError(1, None)
assert not c._install_firmware('')

@mock.patch('sonic_platform.component.MPFAManager.cleanup')
@mock.patch('sonic_platform.component.MPFAManager.extract')
def test_mpfa_manager_context(self, mock_extract, mock_cleanup):
Expand Down

0 comments on commit cc07d86

Please sign in to comment.