Skip to content

Commit

Permalink
[Mellanox][Smartswitch] Add no_wait option for dpu reboot and add pla…
Browse files Browse the repository at this point in the history
…tform information parsing (#20943)

- Why I did it
Changes for dpuctlplat.py:
1. Added option to invoke systemctl rshim start/stop from the pmon container (Using dbus)
2. Added no_wait option for reboot (Since we do not need to wait for the dpu to be ready if NPU+DPU reboot is ongoing)
3. Added platform JSON parsing for rshim and pcie information

- How I did it
Changed dpuctlplat.py to support systemctl commands from pmon container using the dbus-send command
  • Loading branch information
gpunathilell authored Dec 4, 2024
1 parent 335f40a commit 3cc4c11
Show file tree
Hide file tree
Showing 5 changed files with 401 additions and 85 deletions.
37 changes: 29 additions & 8 deletions platform/mellanox/mlnx-platform-api/sonic_platform/device_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Copyright (c) 2020-2024 NVIDIA CORPORATION & AFFILIATES.
# Apache-2.0
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
# Copyright (c) 2020-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -19,12 +20,22 @@
import os
import time
import re
from enum import Enum

from . import utils
from sonic_py_common.general import check_output_pipe

DEFAULT_WD_PERIOD = 65535


class DpuInterfaceEnum(Enum):
MIDPLANE_INT = "midplane_interface"
RSHIM_INT = "rshim_info"
PCIE_INT = "bus_info"


dpu_interface_values = [item.value for item in DpuInterfaceEnum]

DEVICE_DATA = {
'x86_64-mlnx_msn2700-r0': {
'thermal': {
Expand Down Expand Up @@ -271,16 +282,26 @@ def get_linecard_max_port_count(cls):
@classmethod
@utils.read_only_cache()
def get_platform_dpus_data(cls):
json_data = cls.get_platform_json_data()
from sonic_py_common import device_info
platform_path = device_info.get_path_to_platform_dir()
platform_json_path = os.path.join(platform_path, 'platform.json')
json_data = utils.load_json_file(platform_json_path)
return json_data.get('DPUS', None)

@classmethod
def get_dpu_interface(cls, dpu, interface):
dpu_data = cls.get_platform_dpus_data()
if (not dpu_data) or (interface not in dpu_interface_values):
return None
return dpu_data.get(dpu, {}).get(interface)

@classmethod
@utils.read_only_cache()
def get_platform_json_data(cls):
from sonic_py_common import device_info
platform_path = device_info.get_path_to_platform_dir()
platform_json_path = os.path.join(platform_path, 'platform.json')
return utils.load_json_file(platform_json_path)
def get_dpu_count(cls):
dpu_data = cls.get_platform_dpus_data()
if not dpu_data:
return 0
return len(dpu_data)

@classmethod
def get_bios_component(cls):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from .vpd_parser import VpdParser


class DpuVpdParser(VpdParser):
"""DPU Specific VPD parser"""
def __init__(self, file_path, dpu_name):
super(DpuVpdParser, self).__init__(file_path=file_path)
self.dpu_name = dpu_name

def get_dpu_data(self, key=None):
"""Retrieves VPD Entry for DPU Specific Key"""
return self.get_entry_value(f"{self.dpu_name}_{key}")

def get_dpu_base_mac(self):
"""Retrieves VPD Entry for DPU Specific Mac Address"""
return self.get_dpu_data("BASE_MAC")

def get_dpu_serial(self):
"""Retrieves VPD Entry for DPU Specific Serial Number"""
return self.get_dpu_data("SN")

def get_dpu_revision(self):
"""Retrieves VPD Entry for DPU Specific Revision"""
return self.get_dpu_data("REV")

def get_dpu_model(self):
"""Retrieves VPD Entry for DPU Specific Model Number"""
return self.get_dpu_data("PN")
Loading

0 comments on commit 3cc4c11

Please sign in to comment.