Created attachment 224012 [details] usbconfig dump Hello, I have a Corsair K95 RGB PLATINUM gaming keyboard but it doesn't work on FreeBSD (tried on a laptop and a workstation). I see comments from #233884 for others corsair keyboard, but unfortunately added the quirk doesn't work or else, I'm doing things wrong. What I did: - webcamd -l - usbconfig -u 6 -a 2 dump_device_desc (see attachment dump_corsair_k95) - webcamd -d ugen6.2 (see attachment) - add hw.usb.quirk.0="0x1b1c 0x1b2d 0 0xffff UQ_KBD_BOOTPROTO" in /boot/loader.conf reboot, etc. I also patched sys/dev/usb/quirk/usb_quirk.c and sys/dev/usb/usbdevs without success. Let me know, how I can help to add the support of this keyboard. Thanks. For information, there are at least three K95 keyboard with different id: P_K95 0x1b11 P_K95_LEGACY 0x1b08 P_K95_PLATINUM 0x1b2d (mine) other id taken from https://github.com/ckb-next/ckb-next/blob/50ee67dde605f49efa50c3cb7a52ad62de689656/src/daemon/usb.h
Created attachment 224013 [details] webcamd log
Hi, What is printed in dmesg when you plug this device? What version of FreeBSD are you using? --HPS
To use webcamd with this device, you need to enable INPUT devices in the configuration before building webcamd.
Adding wulf@ - maybe he has some ideas here.
(In reply to Hans Petter Selasky from comment #2) ugen6.2: <Corsair Corsair Gaming K95 RGB PLATINUM Keyboard> at usbus6 ukbd2 on uhub1 ukbd2: <Corsair Corsair Gaming K95 RGB PLATINUM Keyboard, class 0/0, rev 2.00/1. 07, addr 2> on usbus6 kbd4 at ukbd2 ums2 on uhub1 ums2: <Corsair Corsair Gaming K95 RGB PLATINUM Keyboard, class 0/0, rev 2.00/1.0 7, addr 2> on usbus6 ums2: 31 buttons and [XYZ] coordinates ID=5 uhid2 on uhub1 uhid2: <Corsair Corsair Gaming K95 RGB PLATINUM Keyboard, class 0/0, rev 2.00/1. 07, addr 2> on usbus6 device_attach: uhid2 attach returned 12
Is this 12-stable or 12.2-release?
Does it work with generic HID driver in Linux or Windows? I see mention of firmware files in the root of Linux driver, so it may require to download them into hardware before start operating.
(In reply to Hans Petter Selasky from comment #6) 12.2-RELEASE
(In reply to Vladimir Kondratyev from comment #7) It works fine on linux, windows (even in install setup) and macos. I'll try to apply the firmware update.
Try to see if you have this commit in /usr/src . Else you need to build a 12-stable kernel to get this working. --HPS commit d4028678f27c762603661745f86896cb2870109c Author: Hans Petter Selasky <hselasky@FreeBSD.org> Date: Thu Feb 13 16:03:12 2020 +0000 Improve USB gaming keyboard support. Add support for decoding pressed keys as a bitmap. The keys in the bitmap are described in the interface specific HID descriptor. Some keyboards even have multiple input interfaces, only using the bitmap method when the event array is full. That typically means when more than seven keys are pressed simultaneously. The internals of the USB keyboard driver have been slightly reworked to keep track of all keys in a single bitmap having 256 bits. This bitmap is then divided into blocks of 64-bits as an optimisation. Simplify automatic key repeat logic, because only the last key pressed can be repeated. PR: 224592 PR: 233884 Tested by: Alex V. Petrov <alexvpetrov@gmail.com> MFC after: 1 week Sponsored by: Mellanox Technologies Notes: svn path=/head/; revision=357861
(In reply to Loïc Bartoletti from comment #9) > It works fine on linux, windows (even in install setup) and macos. Did you have usb_quirk module compiled in or kldloaded in to your kernel when you tried to apply UQ_KBD_BOOTPROTO quirk? It is required.(In reply to Loïc Bartoletti from comment #9)
(In reply to Hans Petter Selasky from comment #10) I tried on 12-stable and 13.0-RELEASE and it doesn't work
(In reply to Vladimir Kondratyev from comment #11) usb_quirk is already loaded
Can you set: sysctl hw.usb.ukbd.debug=17 Then attach the keyboard, and collect messages from dmesg? --HPS
(In reply to Loïc Bartoletti from comment #13) Could you under 13-RELEASE Insert in to /boot/loader.conf hw.usb.usbhid.enable=1 usbhid_load="YES" hidraw_load="YES" Reboot and place here output of: sudo usbhidctl -f /dev/hidraw# -r And then run sudo usbhidctl -f /dev/hidraw# -la than press/release several keys and collect output. /dev/hidraw# should reference your keyboard
Created attachment 224180 [details] crash_pic
(In reply to Vladimir Kondratyev from comment #15) >Could you under 13-RELEASE > >Insert in to /boot/loader.conf > >hw.usb.usbhid.enable=1 >usbhid_load="YES" >hidraw_load="YES" I get a crash when I attach my keyboard: https://bz-attachments.freebsd.org/attachment.cgi?id=224180
(In reply to Loïc Bartoletti from comment #17) Do you have crash dump available? If no than we can try to boot with crashed /boot/loader.conf but with "hw.usb.usbhid.enable=1" line commented out. Than collect output of following commands # kgdb /boot/kernel/kernel /dev/mem (kgdb) info line *0xffffffff821134d8 Also, install sysutils/usbhid-dump and run usbhid-dump utility (it will detach all usb devices, so you need pipe output to file or replug usb kbd or ssh or ps/2 keyboard)
wulf@: # kgdb101 /boot/kernel/usbhid.ko Reading symbols from /boot/kernel/usbhid.ko... Reading symbols from /usr/lib/debug//boot/kernel/usbhid.ko.debug... (kgdb) info line *(usbhid_intr_setup+0x168) Line 349 of "/usr/src/sys/dev/usb/input/usbhid.c" starts at address 0x4e5 <usbhid_intr_setup+357> and ends at 0x4e9 <usbhid_intr_setup+361>. */ for (n = 0; n != USBHID_N_TRANSFER; n++) { if (nowrite && n == USBHID_INTR_OUT_DT) continue; error = usbd_transfer_setup(sc->sc_udev, &sc->sc_iface_index, sc->sc_xfer + n, sc->sc_config + n, 1, (void *)(sc->sc_xfer_ctx + n), &sc->sc_mtx); if (error) break; } if (error) DPRINTF("error=%s\n", usbd_errstr(error)); Missing NULL pointer check for sc_xfer[] if usbd_transfer_setup() fails! rdesc->rdsize = usbd_xfer_max_len(sc->sc_xfer[USBHID_INTR_IN_DT]); rdesc->grsize = usbd_xfer_max_len(sc->sc_xfer[USBHID_CTRL_DT]); rdesc->srsize = rdesc->grsize; rdesc->wrsize = nowrite ? rdesc->srsize : usbd_xfer_max_len(sc->sc_xfer[USBHID_INTR_OUT_DT]); sc->sc_intr_buf = malloc(rdesc->rdsize, M_USBDEV, M_ZERO | M_WAITOK); --HPS
(In reply to Hans Petter Selasky from comment #19) > Missing NULL pointer check for sc_xfer[] if usbd_transfer_setup() fails! Really, usbd_xfer_max_len() is simple getter and unlike more complex usbd_* functions it does not perform NULL-pointer checks. Somehow I missed that.
Created attachment 224186 [details] usbhid-checks-for-uninitialized-xfers.patch Could you test this patch. I hope it will fix the crash
(In reply to Vladimir Kondratyev from comment #21) It fixes the crash and the keyboard works [1][2] but not during the boot. Thanks. [1] with /boot/loader.conf containing usbhid_load and hidraw_load [2] I haven't tested the multimedia keys
(In reply to Loïc Bartoletti from comment #22) > It fixes the crash Great! It would be good to find out why ukbd.ko does not work for you. Can you post USB endpoint and report descriptors from the keyboard? First one can be obtained with `usbconfig -d ugenX.X dump_all_desc` command while the second one with e.g. `hid-recorder /dev/hidrawX` command from sysutils/hid-tools port.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=e889a462d878675551b227a382764c3879e6c2b3 commit e889a462d878675551b227a382764c3879e6c2b3 Author: Vladimir Kondratyev <wulf@FreeBSD.org> AuthorDate: 2021-05-28 20:13:44 +0000 Commit: Vladimir Kondratyev <wulf@FreeBSD.org> CommitDate: 2021-05-28 20:29:42 +0000 usbhid(4): Fix NULL pointer dereference in usbd_xfer_max_len() Which happens when USB transfer setup is failed. MFC after: 1 week PR: 254974 Reviewed by: hselasky Differential revision: https://reviews.freebsd.org/D30485 sys/dev/usb/input/usbhid.c | 64 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 15 deletions(-)
Created attachment 225562 [details] hidraw0 log
Created attachment 225563 [details] hidraw1 log
Created attachment 225564 [details] usbconfig dump_all_desc
(In reply to Vladimir Kondratyev from comment #23) Sorry for the late response. I've just attached hidraw0 and hidraw1 log and the "dump_all_desc" from usbconfig.
Created attachment 225595 [details] ukbd_multipacket_frames.patch Test attached patch.
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=4458105f064740da227ad608ccb5c58805cfac3e commit 4458105f064740da227ad608ccb5c58805cfac3e Author: Vladimir Kondratyev <wulf@FreeBSD.org> AuthorDate: 2021-05-28 20:13:44 +0000 Commit: Vladimir Kondratyev <wulf@FreeBSD.org> CommitDate: 2021-06-13 21:57:31 +0000 usbhid(4): Fix NULL pointer dereference in usbd_xfer_max_len() Which happens when USB transfer setup is failed. PR: 254974 Reviewed by: hselasky Differential revision: https://reviews.freebsd.org/D30485 (cherry picked from commit e889a462d878675551b227a382764c3879e6c2b3) sys/dev/usb/input/usbhid.c | 64 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 15 deletions(-)
(In reply to Vladimir Kondratyev from comment #29) I get the backtrace attached "usb_bus_explorer"
Created attachment 225919 [details] usb_bus_explorer crash picture
(In reply to Loïc Bartoletti from comment #32) This is usbhid crash and it looks exactly like "crash_pic". Did you keep first patch applied? Also could you test last patch with disabled usbhid?
I'm so Sorry, I thought I had answered .... I just tested on FreeBSD 15.0 and the keyboard doesn't work.
I have just looked through hidraw0 log again and concluded that this keyboard can not work with ukbd driver regardless of if ukbd patch has been applied or not. The device shares USB interface between keyboard and mouse and only one of them can attach to it. The winner is hardcoded to ums(4) driver. This is limitation of old USB HID support. usbhid has no this limitation so if if works for you this PR can be closed again.
(In reply to Vladimir Kondratyev from comment #35) Thanks, So I try to (kld)load and unload ums and the keyboard doesn't work either. I also have a trackball (https://www.logitech.com/en-us/products/mice/mx-ergo-wireless-trackball-mouse.html) with an usb dongle. If I insert the dongle in the usb keybord port, FreeBSD crashes : https://ibb.co/0mqRxqN