Initial commit
[ta/infra-ansible.git] / roles / sriov_nodes / files / configure_vf_count.sh
1 #!/bin/bash
2 set -e
3
4 # Copyright 2019 Nokia
5
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 set_max_vf_count()
19 {
20     local iface vf_count device
21     iface=$1
22     vf_count=$2
23
24     echo "Setting interface $iface max vf count to $vf_count"
25     device=$(/bin/mst status -v | grep -E "net-${iface}[[:space:]]+" | awk '{print $2}')
26     /bin/mlxconfig --yes --dev $device set NUM_OF_VFS=$vf_count
27 }
28
29 main()
30 {
31     local -r CONF_FILE="/etc/sriov/sriov.conf"
32     local res=0
33     local mst_started=0
34     local item iface vf_count
35
36     [[ -r $CONF_FILE ]] && source $CONF_FILE
37
38     if [[ -n "$SRIOV_VF_COUNTS" ]]
39     then
40         for item in $SRIOV_VF_COUNTS
41         do
42             iface=${item%:*}
43             vf_count=${item##*:}
44             if /sbin/ethtool -i $iface | grep -qE '^driver:[[:space:]]+mlx5_core$'
45             then
46                 old_count=$(</sys/class/net/$iface/device/sriov_totalvfs)
47                 [[ $old_count -eq $vf_count ]] && continue
48                 [[ $mst_started -eq 0 ]] && /bin/mst start
49                 mst_started=1
50                 set_max_vf_count $iface $vf_count
51                 res=2
52             fi
53         done
54     fi
55
56     return $res
57 }
58
59 main "$@"