Skip to content

Commit aa6e4ff

Browse files
gpunathilellVladimirKuk
authored andcommitted
[Mellanox][Smartswitch] Add no_wait option for dpu reboot and add platform information parsing (sonic-net#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
1 parent 2a2f96c commit aa6e4ff

5 files changed

Lines changed: 401 additions & 85 deletions

File tree

platform/mellanox/mlnx-platform-api/sonic_platform/device_data.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#
2-
# Copyright (c) 2020-2024 NVIDIA CORPORATION & AFFILIATES.
3-
# Apache-2.0
2+
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
3+
# Copyright (c) 2020-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
45
#
56
# Licensed under the Apache License, Version 2.0 (the "License");
67
# you may not use this file except in compliance with the License.
@@ -19,12 +20,22 @@
1920
import os
2021
import time
2122
import re
23+
from enum import Enum
2224

2325
from . import utils
2426
from sonic_py_common.general import check_output_pipe
2527

2628
DEFAULT_WD_PERIOD = 65535
2729

30+
31+
class DpuInterfaceEnum(Enum):
32+
MIDPLANE_INT = "midplane_interface"
33+
RSHIM_INT = "rshim_info"
34+
PCIE_INT = "bus_info"
35+
36+
37+
dpu_interface_values = [item.value for item in DpuInterfaceEnum]
38+
2839
DEVICE_DATA = {
2940
'x86_64-mlnx_msn2700-r0': {
3041
'thermal': {
@@ -271,16 +282,26 @@ def get_linecard_max_port_count(cls):
271282
@classmethod
272283
@utils.read_only_cache()
273284
def get_platform_dpus_data(cls):
274-
json_data = cls.get_platform_json_data()
285+
from sonic_py_common import device_info
286+
platform_path = device_info.get_path_to_platform_dir()
287+
platform_json_path = os.path.join(platform_path, 'platform.json')
288+
json_data = utils.load_json_file(platform_json_path)
275289
return json_data.get('DPUS', None)
276290

291+
@classmethod
292+
def get_dpu_interface(cls, dpu, interface):
293+
dpu_data = cls.get_platform_dpus_data()
294+
if (not dpu_data) or (interface not in dpu_interface_values):
295+
return None
296+
return dpu_data.get(dpu, {}).get(interface)
297+
277298
@classmethod
278299
@utils.read_only_cache()
279-
def get_platform_json_data(cls):
280-
from sonic_py_common import device_info
281-
platform_path = device_info.get_path_to_platform_dir()
282-
platform_json_path = os.path.join(platform_path, 'platform.json')
283-
return utils.load_json_file(platform_json_path)
300+
def get_dpu_count(cls):
301+
dpu_data = cls.get_platform_dpus_data()
302+
if not dpu_data:
303+
return 0
304+
return len(dpu_data)
284305

285306
@classmethod
286307
def get_bios_component(cls):
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#
2+
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
3+
# Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# Apache-2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
from .vpd_parser import VpdParser
20+
21+
22+
class DpuVpdParser(VpdParser):
23+
"""DPU Specific VPD parser"""
24+
def __init__(self, file_path, dpu_name):
25+
super(DpuVpdParser, self).__init__(file_path=file_path)
26+
self.dpu_name = dpu_name
27+
28+
def get_dpu_data(self, key=None):
29+
"""Retrieves VPD Entry for DPU Specific Key"""
30+
return self.get_entry_value(f"{self.dpu_name}_{key}")
31+
32+
def get_dpu_base_mac(self):
33+
"""Retrieves VPD Entry for DPU Specific Mac Address"""
34+
return self.get_dpu_data("BASE_MAC")
35+
36+
def get_dpu_serial(self):
37+
"""Retrieves VPD Entry for DPU Specific Serial Number"""
38+
return self.get_dpu_data("SN")
39+
40+
def get_dpu_revision(self):
41+
"""Retrieves VPD Entry for DPU Specific Revision"""
42+
return self.get_dpu_data("REV")
43+
44+
def get_dpu_model(self):
45+
"""Retrieves VPD Entry for DPU Specific Model Number"""
46+
return self.get_dpu_data("PN")

0 commit comments

Comments
 (0)