f4b7a1def63b80c0253c58c58b82e29cdb556ba6
[kuberef.git] / sw_config / bmra / patched_vfio.yml
1 # SPDX-FileCopyrightText: 2021 Intel Corporation.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 ---
6 # check if the selected driver module is available on host
7 - name: Check that selected driver module is available
8   # if modinfo fails, lookup loaded modules as modinfo might return error
9   # for igb_uio and potentially other modules not included with the kernel
10   shell: "modinfo {{ vf_driver.value }} || grep {{ vf_driver.value }} /proc/modules || grep {{ vf_driver.value }} /lib/modules/$(uname -r)/modules.builtin"
11   register: shell_result
12   ignore_errors: yes
13   failed_when: no
14   changed_when: no
15   with_dict: "{{ item.sriov_vfs | default({}) | combine({'default': item.default_vf_driver}) }}"
16   loop_control:
17     loop_var: vf_driver
18
19 - name: pre-create empty dict for VFs
20   set_fact:
21     vfs_acc: {}
22
23 - name: populate VFs dict with values
24   set_fact:
25     vfs_acc: "{{ vfs_acc | combine({idx : item.default_vf_driver}) }}"
26   loop: "{{ range(item.sriov_numvfs | default(0) | int) | list }}"
27   loop_control:
28     index_var: idx
29     loop_var: vf_default
30
31 - name: update VFs dict with default drivers
32   set_fact:
33     vfs_acc: "{{ vfs_acc | combine({vf.key | regex_replace('.*_(\\d*)', '\\1') | int : vf.value}) }}"
34   loop: "{{ item.sriov_vfs | default({}) | dict2items | sort(attribute='key') }}"
35   loop_control:
36     loop_var: vf
37     extended: yes
38   when:  ansible_loop.index < (item.sriov_numvfs | default(0) | int )
39
40 # get a list of VFs PCI addresses and save the configuration
41 - name: attach VFs driver
42   block:
43     - name: fetch VFs pci addresses for a PF
44       shell: "for vf in /sys/class/net/{{ item.name }}/device/virtfn*;do basename $(readlink -f $vf);done | sort"
45       register: vf_pciids
46       args:
47         executable: /bin/bash
48       changed_when: false
49
50     - name: save VF driver binding
51       lineinfile:
52         path: "{{ sriov_config_path }}/bmra_interfaces"
53         line: "{{ this_item[0] }} {{ this_item[1].value }}"
54         regexp: "^{{ this_item[0] }}"
55         create: yes
56         owner: root
57         group: root
58         mode: '0600'
59       loop: "{{ vf_pciids.stdout_lines | zip(vfs_acc | dict2items) | list }}"
60       loop_control:
61         loop_var: this_item
62       when:
63         - vf_pciids.stderr|length == 0
64         - vf_pciids.stdout_lines|length > 0
65   when: shell_result.results | sum(attribute='rc') == 0