3 # Copyright (c) 2021 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # CSIT SRIOV VF initialization and isolation.
20 SCRIPT_DIR="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))"
21 source "${SCRIPT_DIR}/csit-initialize-vfs-data.sh"
23 # Initilize whitelisted NICs with maximum number of VFs.
25 for pci_addr in ${PCI_WHITELIST[@]}; do
26 if ! [[ ${PCI_BLACKLIST[*]} =~ "${pci_addr}" ]]; then
27 pci_path="/sys/bus/pci/devices/${pci_addr}"
28 # SR-IOV initialization
31 if [ $(< "${pci_path}"/sriov_totalvfs) -gt 128 ]
35 sriov_totalvfs=$(< "${pci_path}"/sriov_totalvfs)
42 echo ${sriov_totalvfs} > "${pci_path}"/sriov_numvfs
43 # SR-IOV 802.1Q isolation
46 pf=$(basename "${pci_path}"/net/*)
47 for vf in $(seq "${sriov_totalvfs}"); do
48 # PCI address index in array (pairing siblings).
49 if [[ -n ${PF_INDICES[@]} ]]
51 vlan_pf_idx=${PF_INDICES[$pci_addr]}
53 vlan_pf_idx=$(( pci_idx % (${#PCI_WHITELIST[@]} / 2) ))
57 # 802.1Q PF PCI address offset.
58 vlan_pf_off=$(( vlan_pf_idx * 100 + vlan_bs_off ))
59 # 802.1Q VF PCI address offset.
60 vlan_vf_off=$(( vlan_pf_off + vf - 1 ))
62 vlan_str="vlan ${vlan_vf_off}"
64 mac5="$(printf '%x' ${pci_idx})"
65 mac6="$(printf '%x' $(( vf - 1 )))"
66 mac_str="mac ba:dc:0f:fe:${mac5}:${mac6}"
67 # Set 802.1Q VLAN id and MAC address
68 ip link set ${pf} vf $(( vf - 1 )) ${mac_str} ${vlan_str}
69 ip link set ${pf} vf $(( vf - 1 )) trust on
70 ip link set ${pf} vf $(( vf - 1 )) spoof off
73 pci_idx=$(( pci_idx + 1 ))