#!/bin/bash
#
# Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
#
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES.
# SPDX-License-Identifier: LicenseRef-NVIDIA-Proprietary
#
# Real: devlink E-Switch capability query
# Checks specific devlink param by name — requires 'name' argument
source "$(dirname "$0")/_lib.sh"
trace "$@"

OP="$1"; shift
TARGET="$1"; shift
BDF=$(bdf_from_target "$TARGET")

[[ "$OP" != "GET" ]] && { echo "Error: caps are read-only" >&2; exit 1; }

for PARAM in "$@"; do
    case "$PARAM" in
        esw_multiport_supported|multiport-supported)
            if devlink dev param show pci/"$BDF" name esw_multiport 2>/dev/null | grep -q "esw_multiport"; then
                echo "multiport-supported=true"
            else
                echo "multiport-supported=false"
            fi ;;
        flow_steering_mode_supported|flow-steering-mode-supported)
            if devlink dev param show pci/"$BDF" name flow_steering_mode 2>/dev/null | grep -q "flow_steering_mode"; then
                echo "flow-steering-mode-supported=true"
            else
                echo "flow-steering-mode-supported=false"
            fi ;;
        *)
            echo "${PARAM}=false" ;;
    esac
done
