diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/spdk/scripts/common.sh | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/spdk/scripts/common.sh')
-rw-r--r-- | src/spdk/scripts/common.sh | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/spdk/scripts/common.sh b/src/spdk/scripts/common.sh new file mode 100644 index 00000000..d85fdb8b --- /dev/null +++ b/src/spdk/scripts/common.sh @@ -0,0 +1,44 @@ +# Common shell utility functions + +function iter_pci_class_code() { + local class="$(printf %02x $((0x$1)))" + local subclass="$(printf %02x $((0x$2)))" + local progif="$(printf %02x $((0x$3)))" + + if hash lspci &>/dev/null; then + if [ "$progif" != "00" ]; then + lspci -mm -n -D | \ + grep -i -- "-p${progif}" | \ + awk -v cc="\"${class}${subclass}\"" -F " " \ + '{if (cc ~ $2) print $1}' | tr -d '"' + else + lspci -mm -n -D | \ + awk -v cc="\"${class}${subclass}\"" -F " " \ + '{if (cc ~ $2) print $1}' | tr -d '"' + fi + elif hash pciconf &>/dev/null; then + addr=($(pciconf -l | grep -i "class=0x${class}${subclass}${progif}" | \ + cut -d$'\t' -f1 | sed -e 's/^[a-zA-Z0-9_]*@pci//g' | tr ':' ' ')) + printf "%04x:%02x:%02x:%x\n" ${addr[0]} ${addr[1]} ${addr[2]} ${addr[3]} + else + echo "Missing PCI enumeration utility" + exit 1 + fi +} + +function iter_pci_dev_id() { + local ven_id="$(printf %04x $((0x$1)))" + local dev_id="$(printf %04x $((0x$2)))" + + if hash lspci &>/dev/null; then + lspci -mm -n -D | awk -v ven="\"$ven_id\"" -v dev="\"${dev_id}\"" -F " " \ + '{if (ven ~ $3 && dev ~ $4) print $1}' | tr -d '"' + elif hash pciconf &>/dev/null; then + addr=($(pciconf -l | grep -i "chip=0x${dev_id}${ven_id}" | \ + cut -d$'\t' -f1 | sed -e 's/^[a-zA-Z0-9_]*@pci//g' | tr ':' ' ')) + printf "%04x:%02x:%02x:%x\n" ${addr[0]} ${addr[1]} ${addr[2]} ${addr[3]} + else + echo "Missing PCI enumeration utility" + exit 1 + fi +} |