HID: lenovo: cptkbd probe blocks ~20 s per device when feature reports time out (behind KVM switch)
Hi,
with the ThinkPad Compact USB Keyboard with TrackPoint (17ef:6047) connected through a USB KVM switch (ASIX AX68002, 0b95:6802), probing the mouse interface in hid-lenovo blocks for about 20 seconds per keyboard. With two KVM ports this delays usable keyboard/mouse input until ~46 s after boot; GDM/gnome-shell is already up at ~9 s.
Kernel: 6.18.63 (Gentoo distribution kernel, Fedora-based config, CONFIG_HID_LENOVO=m). I checked current mainline hid-lenovo.c and the relevant code is unchanged.
The KVM switch emulates the keyboard and does not pass the vendor feature reports (report 0x13, SET_REPORT) through, so every lenovo_send_cmd_cptkbd() call ends in a 5 s USB control timeout:
[ 10.026746] lenovo 0003:17EF:6047.0003: Failed to switch F7/9/11 mode: -110
[ 15.146706] lenovo 0003:17EF:6047.0003: Failed to switch middle button: -110
[ 20.266709] lenovo 0003:17EF:6047.0003: Fn-lock setting failed: -110
[ 25.386681] lenovo 0003:17EF:6047.0003: Sensitivity setting failed: -110
[ 25.387037] input: Lenovo ThinkPad Compact USB Keyboard with TrackPoint as .../2-14.4.1:1.0/...
[ 30.720038] lenovo 0003:17EF:6047.0008: Failed to switch F7/9/11 mode: -110
[ 35.840036] lenovo 0003:17EF:6047.0008: Failed to switch middle button: -110
[ 40.960040] lenovo 0003:17EF:6047.0008: Fn-lock setting failed: -110
[ 46.080009] lenovo 0003:17EF:6047.0008: Sensitivity setting failed: -110
[ 46.258842] systemd-logind: Watching system buttons on /dev/input/event22 (Lenovo ThinkPad Compact USB Keyboard with TrackPoint)
USB topology (lsusb -t, abbreviated):
Port 014: Hub 1a40:0101
Port 003: Hub 0b95:6802 (ASIX AX68002 KVM Switch SoC) Port 001: 17ef:6047 ThinkPad Compact Keyboard with TrackPoint Port 002: 1532:0098 Razer DeathAdder Essential Port 004: Hub 0b95:6802 (second KVM port, same devices)
lenovo_features_set_cptkbd() sends four commands synchronously from probe and continues after each failure, so a device that never answers costs 4 x 5 s. While the probe runs, the udev events for the other devices behind the same hub are not processed either, so the keyboard is unusable for the whole time.
Possible improvements (I'm not familiar enough with the driver to say which is preferred):
1. Stop sending the remaining feature reports after the first one fails with -ETIMEDOUT (and maybe skip creating the sysfs attributes that cannot work).
2. Send the initial settings from a workqueue instead of blocking probe.
A second, related issue: simply blacklisting hid_lenovo does not fall back to hid-generic. 17ef:6047 is listed in hid_have_special_driver, so HID_QUIRK_HAVE_SPECIAL_DRIVER is set whenever CONFIG_HID_LENOVO is enabled, and hid-generic refuses the device even if hid-lenovo is not loaded. The keyboard then has no driver at all. With the kernel built without CONFIG_HID_LENOVO everything worked through hid-generic.
Workaround (tested): booting with usbhid.quirks=0x17ef:0x6047:0x0 (the dynamic quirk replaces the static ones, including HAVE_SPECIAL_DRIVER) plus "blacklist hid_lenovo" makes hid-generic bind all four interfaces at ~4.3 s; keyboard and TrackPoint are usable as soon as GDM is up and no timeouts are logged.
Happy to test patches.
Thanks,
Phobos