1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4source "../../../../net/forwarding/devlink_lib.sh" 5 6if [ "$DEVLINK_VIDDID" != "15b3:cb84" ]; then 7 echo "SKIP: test is tailored for Mellanox Spectrum" 8 exit 1 9fi 10 11# Needed for returning to default 12declare -A KVD_DEFAULTS 13 14KVD_CHILDREN="linear hash_single hash_double" 15KVDL_CHILDREN="singles chunks large_chunks" 16 17devlink_sp_resource_minimize() 18{ 19 local size 20 local i 21 22 for i in $KVD_CHILDREN; do 23 size=$(devlink_resource_get kvd "$i" | jq '.["size_min"]') 24 devlink_resource_size_set "$size" kvd "$i" 25 done 26 27 for i in $KVDL_CHILDREN; do 28 size=$(devlink_resource_get kvd linear "$i" | \ 29 jq '.["size_min"]') 30 devlink_resource_size_set "$size" kvd linear "$i" 31 done 32} 33 34devlink_sp_size_kvd_to_default() 35{ 36 local need_reload=0 37 local i 38 39 for i in $KVD_CHILDREN; do 40 local size=$(echo "${KVD_DEFAULTS[kvd_$i]}" | jq '.["size"]') 41 current_size=$(devlink_resource_size_get kvd "$i") 42 43 if [ "$size" -ne "$current_size" ]; then 44 devlink_resource_size_set "$size" kvd "$i" 45 need_reload=1 46 fi 47 done 48 49 for i in $KVDL_CHILDREN; do 50 local size=$(echo "${KVD_DEFAULTS[kvd_linear_$i]}" | \ 51 jq '.["size"]') 52 current_size=$(devlink_resource_size_get kvd linear "$i") 53 54 if [ "$size" -ne "$current_size" ]; then 55 devlink_resource_size_set "$size" kvd linear "$i" 56 need_reload=1 57 fi 58 done 59 60 if [ "$need_reload" -ne "0" ]; then 61 devlink_reload 62 fi 63} 64 65devlink_sp_read_kvd_defaults() 66{ 67 local key 68 local i 69 70 KVD_DEFAULTS[kvd]=$(devlink_resource_get "kvd") 71 for i in $KVD_CHILDREN; do 72 key=kvd_$i 73 KVD_DEFAULTS[$key]=$(devlink_resource_get kvd "$i") 74 done 75 76 for i in $KVDL_CHILDREN; do 77 key=kvd_linear_$i 78 KVD_DEFAULTS[$key]=$(devlink_resource_get kvd linear "$i") 79 done 80} 81 82KVD_PROFILES="default scale ipv4_max" 83 84devlink_sp_resource_kvd_profile_set() 85{ 86 local profile=$1 87 88 case "$profile" in 89 scale) 90 devlink_resource_size_set 64000 kvd linear 91 devlink_resource_size_set 15616 kvd linear singles 92 devlink_resource_size_set 32000 kvd linear chunks 93 devlink_resource_size_set 16384 kvd linear large_chunks 94 devlink_resource_size_set 128000 kvd hash_single 95 devlink_resource_size_set 48000 kvd hash_double 96 devlink_reload 97 ;; 98 ipv4_max) 99 devlink_resource_size_set 64000 kvd linear 100 devlink_resource_size_set 15616 kvd linear singles 101 devlink_resource_size_set 32000 kvd linear chunks 102 devlink_resource_size_set 16384 kvd linear large_chunks 103 devlink_resource_size_set 144000 kvd hash_single 104 devlink_resource_size_set 32768 kvd hash_double 105 devlink_reload 106 ;; 107 default) 108 devlink_resource_size_set 98304 kvd linear 109 devlink_resource_size_set 16384 kvd linear singles 110 devlink_resource_size_set 49152 kvd linear chunks 111 devlink_resource_size_set 32768 kvd linear large_chunks 112 devlink_resource_size_set 87040 kvd hash_single 113 devlink_resource_size_set 60416 kvd hash_double 114 devlink_reload 115 ;; 116 *) 117 check_err 1 "Unknown profile $profile" 118 esac 119} 120