Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -1114,13 +1114,6 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in
sudo mkdir -p $FILESYSTEM_ROOT/etc/minicom/
sudo cp platform/mellanox/minirc.dfl $FILESYSTEM_ROOT/etc/minicom/

# Install rshim script
sudo install -m 755 platform/mellanox/rshim/files/rshim.sh $FILESYSTEM_ROOT/usr/bin/rshim.sh

# Install rshim services
sudo cp platform/mellanox/rshim/files/rshim@.service $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM/
sudo cp platform/mellanox/rshim/files/rshim-manager.service $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM/

# Install dpuctl script and config file
sudo install -m 755 platform/mellanox/smartswitch/dpuctl/dpuctl.sh $FILESYSTEM_ROOT/usr/bin/dpuctl.sh
sudo install -m 755 platform/mellanox/smartswitch/dpuctl/dpu.conf $FILESYSTEM_ROOT_ETC/mlnx/
Expand Down
11 changes: 0 additions & 11 deletions platform/mellanox/rshim/files/rshim-manager.service

This file was deleted.

44 changes: 0 additions & 44 deletions platform/mellanox/rshim/files/rshim.sh

This file was deleted.

13 changes: 0 additions & 13 deletions platform/mellanox/rshim/files/rshim@.service

This file was deleted.

61 changes: 49 additions & 12 deletions platform/mellanox/smartswitch/dpuctl/dpuctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,37 @@
DARK_MODE=true

bf3_pci_id="15b3:c2d5"
dpu2pcie[0]="08:00.0"
dpu2pcie[1]="07:00.0"
dpu2pcie[2]="01:00.0"
dpu2pcie[3]="02:00.0"

# Function to get PCI addresses dynamically from platform.json
get_dpu_pci_addresses() {
local dpu_list
local -A pci_to_dpu_map

# Get list of all DPUs from platform.json
dpu_list=$(dpumap.sh listdpus 2>/dev/null)
if [[ $? -ne 0 ]]; then
echo "Error: Failed to get DPU list from platform.json" >&2
return 1
fi

# Get PCI address for each DPU and build the mapping
while read -r dpu; do
if [[ -n "$dpu" ]]; then
rshim_bus_pci_addr=$(dpumap.sh dpu2rshim_bus_info "$dpu" 2>/dev/null)
if [[ $? -eq 0 && "$rshim_bus_pci_addr" != "null" ]]; then
pci_to_dpu_map["$rshim_bus_pci_addr"]="$dpu"
fi
# If DPU has older image, the bus_info pcie value should be considered
pci_addr=$(dpumap.sh dpu2pcie "$dpu" 2>/dev/null)
if [[ $? -eq 0 && "$pci_addr" != "null" ]]; then
pci_to_dpu_map["$pci_addr"]="$dpu"
fi
fi
done <<< "$dpu_list"

# Return the mapping as a string that can be eval'd
declare -p pci_to_dpu_map
}

if [[ -f /etc/mlnx/dpu.conf ]]; then
. /etc/mlnx/dpu.conf
Expand All @@ -33,18 +60,28 @@ do_start() {
if [[ $DARK_MODE == "true" ]]; then
# By default all the DPUs are on. Power off the DPUs when is dark mode is required.

for dpu_id in ${!dpu2pcie[@]}; do
pci_id=$(lspci -n | grep "${dpu2pcie[$dpu_id]}" | awk '{print $3}')
if [[ $pci_id == $bf3_pci_id ]]; then
dpuctl dpu-power-off dpu${dpu_id} &
# Get PCI addresses dynamically
eval $(get_dpu_pci_addresses)
if [[ ${#pci_to_dpu_map[@]} -eq 0 ]]; then
echo "Error: No PCI addresses found from platform.json" >&2
exit 1
fi

# Get all PCI addresses that match bf3_pci_id and extract their PCI IDs
pci_ids=$(lspci -Dn | grep "$bf3_pci_id" | awk '{print $1}')

# For each PCI ID, find the corresponding DPU from the mapping
while read -r pci_id; do
if [[ -n "$pci_id" ]]; then
dpu_name=${pci_to_dpu_map[$pci_id]}
if [[ -n "$dpu_name" ]]; then
dpuctl dpu-power-off "$dpu_name" &
fi
fi
done
done <<< "$pci_ids"

# Wait for all dpuctl processes to finish
wait
else
# Start RSHIM per each DPU to create interfaces
systemctl start rshim-manager.service
fi
}

Expand Down
102 changes: 102 additions & 0 deletions platform/mellanox/smartswitch/dpumap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash
#
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
# Copyright (c) 2025 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.
#

# read SONiC immutable variables
[ -f /etc/sonic/sonic-environment ] && . /etc/sonic/sonic-environment
PLATFORM=${PLATFORM:-`sonic-db-cli CONFIG_DB HGET 'DEVICE_METADATA|localhost' platform`}
# First Boot
PLATFORM=${PLATFORM:-`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`}

PLATFORM_JSON=/usr/share/sonic/device/$PLATFORM/platform.json

usage(){
echo "Usage: $0 {dpu2pcie|dpu2rshim|rshim2dpu|pcie2dpu|rshim2pcie|pcie2rshim|listdpus|listrshims} [name]"
}

validate_platform(){
if [[ ! -f $PLATFORM_JSON ]]; then
echo "platform.json file not found. Exiting script"
exit 1
fi
}


validate_platform
case $1 in
"dpu2rshim")
jq_query='.DPUS[$dpu].rshim_info'
var="dpu"
;;
"dpu2pcie")
jq_query='.DPUS[$dpu].bus_info'
var="dpu"
;;
"dpu2rshim_bus_info")
jq_query='.DPUS[$dpu].rshim_bus_info'
var="dpu"
;;
"pcie2dpu")
var="bus"
;;
"pcie2rshim")
jq_query='.DPUS | to_entries[] | select(.value.bus_info == $bus) | .value.rshim_info'
var="bus"
;;
"rshim2dpu")
jq_query='.DPUS | to_entries[] | select(.value.rshim_info == $rshim) | .key'
var="rshim"
;;
"rshim2pcie")
jq_query='.DPUS | to_entries[] | select(.value.rshim_info == $rshim) | .value.rshim_bus_info'
var="rshim"
;;
"listdpus")
jq_query='.DPUS | keys[]'
var=""
;;
"listrshims")
jq_query='.DPUS | to_entries[] | .value.rshim_info'
var=""
;;
*)
echo "Invalid usage of script!"
usage
exit 1
esac

if [[ -n "$2" ]]; then
IFS=',' read -r -a identifier_array <<< "$2"
else
identifier_array=("")
fi

for identifier in "${identifier_array[@]}"; do
if [[ -z "$var" ]]; then
op=$(jq -r "$jq_query" "$PLATFORM_JSON")
else
op=$(jq -r --arg "$var" "$identifier" "$jq_query" "$PLATFORM_JSON")
fi
if [[ "$op" != "null" ]]; then
echo "$op"
else
echo "Invald entry! $identifier"
exit 1
fi
done

Loading