#! /bin/bash
#
# Copyright © 2021 NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED.
#
# This software product is a proprietary product of Nvidia Corporation and its affiliates
# (the "Company") and all right, title, and interest in and to the software
# product, including all associated intellectual property rights, are and
# shall remain exclusively with the Company.
#
# This software product is governed by the End User License Agreement
# provided with the software product.
#
# Record mlxlink output; used by cl-support
#

[ -x /usr/bin/mlxlink ] && {
    d=$(mst status | grep pciconf | awk '{print $1}' )
    #echo $d
    for p in $(ls -v1 /sys/class/net); do
        [ -d $p/bridge -o -d $p/bonding ] && continue;
        p=${p##*/}
        [[ $p =~ ^(sw[0-9]*p[0-9]+(s[0-7])?$) ]] && {
            p=${p#"swp"}
                p=${p%"s0"}
                p=${p/s1/\/2}
                p=${p/s2/\/3}
                p=${p/s3/\/4}
                p=${p/s4/\/5}
                p=${p/s5/\/6}
                p=${p/s6/\/7}
                p=${p/s7/\/8}
                echo "launching mlxlink -d ${d} -c -m --show_fec -p ${p}"
                mlxlink -d ${d} -c -m --show_fec -p ${p}| sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g'
        }
        done
        wait
}
