-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathi915-sriov.plg
executable file
·250 lines (212 loc) · 8.53 KB
/
i915-sriov.plg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?xml version='1.0' standalone='yes'?>
<!DOCTYPE PLUGIN [
<!ENTITY name "i915-sriov">
<!ENTITY author "zhtengw">
<!ENTITY repo "unraid-i915-sriov">
<!ENTITY gitbranch "master">
<!ENTITY pluginver "2023.04.06">
<!ENTITY minosver "6.10.0">
<!ENTITY githuburl "https://raw.githubusercontent.com/&author;/&repo;/&gitbranch;">
<!ENTITY pluginurl "&githuburl;/&name;.plg">
<!ENTITY pkgurl "&githuburl;/packages">
<!ENTITY pluginpkg "unraid-&name;-&pluginver;.txz">
<!ENTITY supporturl "https://forums.unraid.net/topic/136621-unraid-kernel-with-igpu-sr-iov-support/">
<!-- Defines the persistent (USB) directory where downloaded packages are cached -->
<!ENTITY plugindir "/boot/config/plugins/&name;/">
<!ENTITY packages "&plugindir;/packages">
]>
<PLUGIN name="&name;"
author="&author;"
version="&pluginver;"
pluginURL="&pluginurl;"
support="&supporturl;"
min="&minosver;"
>
<CHANGES>
## i915-sriov
### 2023.04.06
- Make change VFs number work;
- Add option for saving to config file only;
- Add support for unRAID 6.10.x
### 2023.04.01
- Make tools.sh work with multiple Intel Graphic Cards;
- Restore libvirt.php when module download failed;
- Make slot of PCI address to 0 when machine type is q35
### 2023.03.30
- Add plugin page in Settings;
- Fix HW transcode not work for PF on linux-5.19
### 2023.03.28
- Change PCI address of VF to 0000:06:10.0
### 2023.03.21
- Initial unRAID V6.11 release.
</CHANGES>
<FILE Name="&plugindir;/&pluginpkg;" Run="upgradepkg --install-new">
<URL>&pkgurl;/&pluginpkg;</URL>
</FILE>
<!-- Generate the i915-sriov.conf -->
<FILE Run="/bin/bash" Method="install">
<INLINE>
MODCFGDIR="/boot/config/modprobe.d/"
if [ ! -f "${MODCFGDIR}/i915-sriov.conf" ]; then
mkdir -p &packages;
# install config to modprobe.d/i915-sriov.conf
mkdir -p ${MODCFGDIR}
echo "# disable autoload old i915 module on boot
blacklist i915
options i915 enable_guc=7" > ${MODCFGDIR}/i915-sriov.conf
fi
mkdir -p &plugindir;
#Create settings file if not found
if [ ! -f "&plugindir;/&name;.cfg" ]; then
echo 'vfnumber=2' > "&plugindir;/&name;.cfg"
fi
if [ ! -f /usr/local/emhttp/plugins/dynamix.vm.manager/include/libvirt.php.orig ]; then
cp /usr/local/emhttp/plugins/dynamix.vm.manager/include/libvirt.php /usr/local/emhttp/plugins/dynamix.vm.manager/include/libvirt.php.orig
else
cp /usr/local/emhttp/plugins/dynamix.vm.manager/include/libvirt.php.orig /usr/local/emhttp/plugins/dynamix.vm.manager/include/libvirt.php
fi
# Fix PCI address error when iGPU VF assigned to VM
cd / ; patch -p1 <<EOF
--- a/usr/local/emhttp/plugins/dynamix.vm.manager/include/libvirt.php
+++ b/usr/local/emhttp/plugins/dynamix.vm.manager/include/libvirt.php
@@ -780,7 +780,15 @@
\$strSpecialAddress = '';
if (\$gpu_bus == '00' && \$gpu_slot == '02') {
\$strXVGA = '';
- \$strSpecialAddress = "<address type='pci' domain='0x0000' bus='0x".\$gpu_bus."' slot='0x".\$gpu_slot."' function='0x".\$gpu_function."'/>";
+ if (\$gpu_function == '00') {
+ \$strSpecialAddress = "<address type='pci' domain='0x0000' bus='0x".\$gpu_bus."' slot='0x".\$gpu_slot."' function='0x".\$gpu_function."'/>";
+ } else {
+ if (\$machine_type == 'q35'){
+ \$strSpecialAddress = "<address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/>";
+ } else {
+ \$strSpecialAddress = "<address type='pci' domain='0x0000' bus='0x06' slot='0x10' function='0x0'/>";
+ }
+ }
}
\$strRomFile = '';
EOF
</INLINE>
</FILE>
<!-- Download, cache the i915-sriov module match the kernel version -->
<FILE Run="/bin/bash">
<INLINE>
KERNEL_V="$(uname -r)"
PKGNAME="&name;-${KERNEL_V}.txz"
removal() {
rm -rf &plugindir; /boot/config/modprobe.d/i915-sriov.conf
# Restore libvirt.php
if [ -f /usr/local/emhttp/plugins/dynamix.vm.manager/include/libvirt.php.orig ]; then
mv /usr/local/emhttp/plugins/dynamix.vm.manager/include/libvirt.php.orig /usr/local/emhttp/plugins/dynamix.vm.manager/include/libvirt.php
fi
}
#Download i915-sriov module Package
download() {
mkdir -p &packages;/${KERNEL_V%%-*}
if wget -q -nc --show-progress --progress=bar:force:noscroll -O "&packages;/${KERNEL_V%%-*}/${PKGNAME}" "&pkgurl;/${PKGNAME}" ; then
wget -q -nc --show-progress --progress=bar:force:noscroll -O "&packages;/${KERNEL_V%%-*}/${PKGNAME}.md5" "&pkgurl;/${PKGNAME}.md5"
if [ "$(md5sum &packages;/${KERNEL_V%%-*}/${PKGNAME} | awk '{print $1}')" != "$(cat &packages;/${KERNEL_V%%-*}/${PKGNAME}.md5 | awk '{print $1}')" ]; then
echo
echo "-----ERROR - ERROR - ERROR - ERROR - ERROR - ERROR - ERROR - ERROR - ERROR------"
echo "--------------------------------CHECKSUM ERROR!---------------------------------"
removal
exit 1
fi
echo
echo "----Successfully downloaded i915-sriov module Package for kernel v${KERNEL_V%%-*}, please wait!----"
else
echo
echo "--------Can't download i915-sriov module Package for kernel v${KERNEL_V%%-*}-----------"
removal
exit 1
fi
}
#Check if driver is already downloaded
check() {
if ! ls -1 &packages;/${KERNEL_V%%-*}/ | grep -q "${PKGNAME}" ; then
echo
echo "+=============================================================================="
echo "| WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING"
echo "|"
echo "| Don't close this window with the red 'X' in the top right corner "
echo "| until the 'DONE' button is displayed!"
echo "|"
echo "| WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING"
echo "+=============================================================================="
echo
echo "----------Downloading i915-sriov module Package for kernel v${KERNEL_V%%-*}----------"
echo "---------This could take some time, please don't close this window!-----------"
download
else
wget -q -nc --show-progress --progress=bar:force:noscroll -O "&packages;/${KERNEL_V%%-*}/${PKGNAME}.md5" "&pkgurl;/${PKGNAME}.md5"
if [ "$(md5sum &packages;/${KERNEL_V%%-*}/${PKGNAME} | awk '{print $1}')" != "$(cat &packages;/${KERNEL_V%%-*}/${PKGNAME}.md5 | awk '{print $1}')" ]; then
download
fi
echo
echo "---------i915-sriov module Package for kernel v${KERNEL_V%%-*} found locally---------"
fi
}
# Installation
install() {
/sbin/upgradepkg --install-new "&packages;/${KERNEL_V%%-*}/${PKGNAME}"
}
enable_module() {
VF_NUM="$(cat &plugindir;/&name;.cfg | grep "vfnumber=" | cut -d '=' -f2 | sed "s/\"//g")"
modprobe i915 enable_guc=7
sleep 2
if [ -f "/sys/devices/pci0000:00/0000:00:02.0/sriov_numvfs" ]; then
echo ${VF_NUM} > /sys/devices/pci0000:00/0000:00:02.0/sriov_numvfs
/usr/local/sbin/vfio-pci
fi
}
# Script main
check
install
enable_module
echo ""
echo "+=============================================================================="
echo "| Installation of i915-sriov module Package for kernel v${KERNEL_V%%-*} successful, reboot to take effect."
echo "+=============================================================================="
echo ""
exit 0
</INLINE>
</FILE>
<!-- The 'remove' script -->
<FILE Run="/bin/bash" Method="remove">
<INLINE>
set -e
echo ""
echo "+=============================================================================="
echo "| Uninstalling packages, removing directories and files"
echo "+=============================================================================="
echo ""
removepkg &pluginpkg;
# Restore libvirt.php
if [ -f /usr/local/emhttp/plugins/dynamix.vm.manager/include/libvirt.php.orig ]; then
mv /usr/local/emhttp/plugins/dynamix.vm.manager/include/libvirt.php.orig /usr/local/emhttp/plugins/dynamix.vm.manager/include/libvirt.php
fi
# Define directories and files to remove in a multi-line string
dirs_files_to_remove="
&plugindir;
/boot/config/modprobe.d/i915-sriov.conf
"
echo "Starting directory and file removal\n"
# Read through package removal lines, uninstalling each
while IFS= read -r line
do
# If line is empty, skip to the next iteration
[ -z "$line" ] && continue
echo "Deleting $line"
# rm -rf "/path/to/prefix*" * expansion fails due to quotes, wrap in bash exec
bash -c "rm -rf $line"
done < <(printf '%s\n' "$dirs_files_to_remove")
printf "\nDirectory and file removal done"
echo ""
echo "+=============================================================================="
echo "| &name; has been uninstalled, please reboot your server."
echo "+=============================================================================="
echo ""
exit 0
</INLINE>
</FILE>
</PLUGIN>