Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mellanox][Smartswitch] Add no_wait option for dpu reboot and add platform information parsing #20943

Merged
merged 9 commits into from
Dec 4, 2024
Merged
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
Loading