[Accel-config] [PATCH v1 1/1] accel-config/test: disable enabled devices before unloading iaa_crypto

Tony Zhu <[email protected]> Mon, 11 Dec 2023 14:37:51 +0800
Newsgroups dev.linux.lists.accel-config
Message-ID <[email protected]>
When a idxd device is probed and iaa_crypto will allow the idxd device
to be configured with default values. This is kernel change from patch
"Add support for device/wq defaults". iaa_crypto could not be removed
because this module is used. Before remove it, all enabled dsa/wqs must
be disabled. For the reset of idxd driver, must disable all enabled devices.

Signed-off-by: Tony Zhu <[email protected]>
---
 test/common | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/test/common b/test/common
index 14e7c21..983de4d 100755
--- a/test/common
+++ b/test/common
@@ -117,10 +117,49 @@ check_prereq()
 	fi
 }
 
+# Disable all active devices dsa/iax and enabled wqs.
+# Use accel-config tool to disable the device and wq.
+disable_all() {
+  for device_type in 'dsa' 'iax'; do
+    # Kernel before 5.13 has dsa and iax bus. Because of ABI change, iax
+    # bus is removed. All devices are in /sys/bus/das/devices.
+    if [ -d /sys/bus/iax ] && [ $device_type == 'iax' ]; then
+      DSA_DEVICE_PATH="/sys/bus/iax/devices"
+    else
+      DSA_DEVICE_PATH="/sys/bus/dsa/devices"
+    fi
+	# Get available devices
+    for device_path in ${DSA_DEVICE_PATH}/${device_type}* ; do
+      [[ $(echo "$device_path" | grep -c '!') -eq 0 ]] && {
+		# Get wqs and disable it if the status is enabled
+        for wqp in ${device_path}/wq* ; do
+          [[ $( cat "${wqp}"/state ) == "enabled" ]] && {
+            wq=${wqp##${DSA_DEVICE_PATH}/}
+            accel-config disable-wq "${wq}"
+            echo "-1" > "${wqp}"/group_id
+          }
+          done
+		# Disable device
+        [[ $( cat "${device_path}"/state ) == "enabled" ]] && {
+          accel-config disable-device "${device_path##${DSA_DEVICE_PATH}/}"
+        }
+		# Remove group id of engine
+        for engine in ${device_path}/engine* ; do
+          echo -1 > "$engine"/group_id
+        done
+      }
+    done
+  done
+}
+
 # cleanup
 #
 _cleanup()
 {
+  # iaa_crypto will enable iax devices by default after kernel 6.6, 
+  # need to disable all enabled devices before unloading the module.
+	disable_all
+
 	lsmod | grep -wq idxd_vdev && {
 		rmmod idxd_vdev
 	}
-- 
2.40.1