Skip to content

Commit e7f1020

Browse files
authored
[Mellanox] Add common sai.profile per asic and asic_detect.sh script (#23676)
<!-- Please make sure you've read and understood our contributing guidelines: https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md failure_prs.log skip_prs.log Make sure all your commits include a signature generated with `git commit -s` ** If this is a bug fix, make sure your description includes "fixes #xxxx", or "closes #xxxx" or "resolves #xxxx" Please provide the following information: --> #### Why I did it This PR adds new script for Mellanox asic detection, as there are few places that use it. The script queries "lspci" command to find out what is the current device ID. If the script was successful, we write the value to asic_type so the script will be running only 1 time. Also, added sai-spcx.profile and sai-bf3.profile with relevant parameters. #### How I did it Added new script to detect asic type, and new files for per-asic sai.profile #### How to verify it Run on switch and make sure the parameters are applied to sai.profile inside syncd. <!-- If PR needs to be backported, then the PR must be tested against the base branch and the earliest backport release branch and provide tested image version on these two branches. For example, if the PR is requested for master, 202211 and 202012, then the requester needs to provide test results on master and 202012. --> #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 202205 - [ ] 202211 - [ ] 202305 - [ ] 202311 - [ ] 202405 - [ ] 202411 - [ ] 202505 #### Tested branch (Please provide the tested image version) <!-- - Please provide tested image version - e.g. - [x] 20201231.100 --> - [ ] <!-- image version 1 --> - [ ] <!-- image version 2 --> #### Description for the changelog <!-- Write a short (one line) summary that describes the changes in this pull request for inclusion in the changelog: --> <!-- Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU. --> #### Link to config_db schema for YANG module changes <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md --> #### A picture of a cute animal (not mandatory but encouraged)
1 parent 1cc7dbe commit e7f1020

16 files changed

Lines changed: 80 additions & 49 deletions

File tree

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
SAI_INIT_CONFIG_FILE=/usr/share/sonic/hwsku/sai_5640_448x100g_16x400g.xml
22
SAI_KEY_SPC5_LOSSY_SCHEDULING=1
3-
SAI_DEFAULT_SWITCHING_MODE_STORE_FORWARD=1
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
SAI_INIT_CONFIG_FILE=/usr/share/sonic/hwsku/sai_5640_512x100g.xml
22
SAI_KEY_SPC5_LOSSY_SCHEDULING=1
3-
SAI_DEFAULT_SWITCHING_MODE_STORE_FORWARD=1
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
SAI_INIT_CONFIG_FILE=/usr/share/sonic/hwsku/sai_5640.xml
22
SAI_KEY_SPC5_LOSSY_SCHEDULING=1
3-
SAI_DEFAULT_SWITCHING_MODE_STORE_FORWARD=1
4-

files/build_templates/docker_image_ctl.j2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ start() {
682682
-v /tmp/nv-syncd-shared/:/tmp \
683683
-v /dev/shm:/dev/shm:rw \
684684
-v /var/log/sai_failure_dump:/var/log/sai_failure_dump:rw \
685+
-v /usr/bin/asic_detect:/usr/bin/asic_detect:rw \
685686
-e SX_API_SOCKET_FILE=/var/run/sx_sdk/sx_api.sock \
686687
{%- elif docker_container_name == "pmon" %}
687688
-v /var/run/hw-management:/var/run/hw-management:rw \
@@ -697,6 +698,11 @@ start() {
697698
{%- endif %}
698699
{%- endif %}
699700
{%- endif %}
701+
{%- if sonic_asic_platform == "nvidia-bluefield" %}
702+
{%- if docker_container_name == "syncd" %}
703+
-v /usr/bin/asic_detect:/usr/bin/asic_detect:rw \
704+
{%- endif %}
705+
{%- endif %}
700706
{%- if sonic_asic_platform == "broadcom" %}
701707
{%- if docker_container_name == "syncd" %}
702708
--shm-size=${SYNCD_SHM_SIZE:-512m} \

files/build_templates/sonic_debian_extension.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,8 @@ sudo cp platform/mellanox/cmis_host_mgmt/cmis_host_mgmt.py $FILESYSTEM_ROOT/usr/
10951095
sudo chmod 755 $FILESYSTEM_ROOT/usr/bin/cmis_host_mgmt.py
10961096
j2 platform/mellanox/mlnx-fw-upgrade.j2 | sudo tee $FILESYSTEM_ROOT/usr/bin/mlnx-fw-upgrade.sh
10971097
sudo chmod 755 $FILESYSTEM_ROOT/usr/bin/mlnx-fw-upgrade.sh
1098+
sudo cp -r platform/mellanox/asic_detect $FILESYSTEM_ROOT/usr/bin/asic_detect
1099+
sudo chmod -R 777 $FILESYSTEM_ROOT/usr/bin/asic_detect/
10981100

10991101
# Install mlnx-sonic-platform Python 3 package
11001102
install_pip_package {{mlnx_platform_api_py3_wheel_path}}
@@ -1131,6 +1133,8 @@ done
11311133
sudo install -m 755 platform/nvidia-bluefield/byo/sonic-byo.py $FILESYSTEM_ROOT/usr/bin/sonic-byo.py
11321134
SONIC_PLATFORM={{sonic_asic_platform}} j2 platform/mellanox/mlnx-fw-upgrade.j2 | sudo tee $FILESYSTEM_ROOT/usr/bin/mlnx-fw-upgrade.sh
11331135
sudo chmod 755 $FILESYSTEM_ROOT/usr/bin/mlnx-fw-upgrade.sh
1136+
sudo cp -r platform/mellanox/asic_detect $FILESYSTEM_ROOT/usr/bin/asic_detect
1137+
sudo chmod -R 777 $FILESYSTEM_ROOT/usr/bin/asic_detect/
11341138

11351139
install_pip_package {{platform_api_py3_wheel_path}}
11361140

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
#
3+
# SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES
4+
# Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
SUCCESS_CODE=0
21+
RC=-1
22+
23+
if [[ -f "/usr/bin/asic_detect/asic_type" ]]; then
24+
cat /usr/bin/asic_detect/asic_type
25+
exit $SUCCESS_CODE
26+
fi
27+
28+
# make sure that DEVICE_DICT keys are the same as values in DEVICE_ORDER
29+
declare -A DEVICE_DICT=(
30+
["cb84"]="spc1"
31+
["cf6c"]="spc2"
32+
["cf70"]="spc3"
33+
["cf80"]="spc4"
34+
["cf82"]="spc5"
35+
["a2dc"]="bf3"
36+
)
37+
TYPE_UNKNOWN="unknown"
38+
VENDOR_ID="15b3"
39+
DEVICE_TYPE=$TYPE_UNKNOWN
40+
41+
# bf3 should be the last device in the list
42+
DEVICE_ORDER=("cb84" "cf6c" "cf70" "cf80" "cf82" "a2dc")
43+
44+
lspci_output=$(lspci -n 2>/dev/null)
45+
if [[ -n "$lspci_output" ]]; then
46+
for key in "${DEVICE_ORDER[@]}"; do
47+
if echo "$lspci_output" | grep "$VENDOR_ID:$key" &>/dev/null; then
48+
DEVICE_TYPE="${DEVICE_DICT[$key]}"
49+
RC=$SUCCESS_CODE
50+
break
51+
fi
52+
done
53+
if [[ -n "$DEVICE_TYPE" ]]; then
54+
echo "$DEVICE_TYPE" | tee >( [[ "$DEVICE_TYPE" != "$TYPE_UNKNOWN" ]] && cat > /usr/bin/asic_detect/asic_type )
55+
fi
56+
exit $RC
57+
fi

platform/mellanox/docker-syncd-mlnx/Dockerfile.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ COPY ["critical_processes", "/etc/supervisor/"]
7171
COPY ["platform_syncd_dump.sh", "/usr/bin/"]
7272

7373
RUN mkdir -p /etc/mlnx/
74-
COPY ["sai-common.profile", "/etc/mlnx/"]
74+
COPY sai-*.profile /etc/mlnx/
7575

7676
RUN mkdir -p /etc/supervisor/conf.d/
7777
RUN sonic-cfggen -a "{\"ENABLE_ASAN\":\"{{ENABLE_ASAN}}\"}" -t /usr/share/sonic/templates/supervisord.conf.j2 > /etc/supervisor/conf.d/supervisord.conf

platform/mellanox/docker-syncd-mlnx/sai-spc1.profile

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SAI_MIRROR_SESSION_HW_ID_RESERVATION=7
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SAI_MIRROR_SESSION_HW_ID_RESERVATION=7

0 commit comments

Comments
 (0)