Bug 254974 - Corsair K95 RGB PLATINUM gaming keyboard not working
Summary: Corsair K95 RGB PLATINUM gaming keyboard not working
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: usb (show other bugs)
Version: 12.2-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-usb (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-11 06:47 UTC by Loïc Bartoletti
Modified: 2021-04-22 23:46 UTC (History)
2 users (show)

See Also:


Attachments
usbconfig dump (581 bytes, text/plain)
2021-04-11 06:47 UTC, Loïc Bartoletti
no flags Details
webcamd log (1.84 KB, text/plain)
2021-04-11 06:48 UTC, Loïc Bartoletti
no flags Details
crash_pic (668.52 KB, image/jpeg)
2021-04-17 08:03 UTC, Loïc Bartoletti
no flags Details
usbhid-checks-for-uninitialized-xfers.patch (4.57 KB, patch)
2021-04-17 12:08 UTC, Vladimir Kondratyev
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Loïc Bartoletti freebsd_committer 2021-04-11 06:47:51 UTC
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
Comment 1 Loïc Bartoletti freebsd_committer 2021-04-11 06:48:15 UTC
Created attachment 224013 [details]
webcamd log
Comment 2 Hans Petter Selasky freebsd_committer 2021-04-11 18:12:58 UTC
Hi,

What is printed in dmesg when you plug this device?

What version of FreeBSD are you using?

--HPS
Comment 3 Hans Petter Selasky freebsd_committer 2021-04-11 18:28:37 UTC
To use webcamd with this device, you need to enable INPUT devices in the configuration before building webcamd.
Comment 4 Hans Petter Selasky freebsd_committer 2021-04-11 18:29:06 UTC
Adding wulf@ - maybe he has some ideas here.
Comment 5 Loïc Bartoletti freebsd_committer 2021-04-11 19:14:26 UTC
(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
Comment 6 Hans Petter Selasky freebsd_committer 2021-04-11 19:29:46 UTC
Is this 12-stable or 12.2-release?
Comment 7 Vladimir Kondratyev freebsd_committer 2021-04-11 20:10:28 UTC
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.
Comment 8 Loïc Bartoletti freebsd_committer 2021-04-12 19:19:00 UTC
(In reply to Hans Petter Selasky from comment #6)
12.2-RELEASE
Comment 9 Loïc Bartoletti freebsd_committer 2021-04-12 19:20:00 UTC
(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.
Comment 10 Hans Petter Selasky freebsd_committer 2021-04-12 19:45:47 UTC
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
Comment 11 Vladimir Kondratyev freebsd_committer 2021-04-12 19:58:52 UTC
(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)
Comment 12 Loïc Bartoletti freebsd_committer 2021-04-16 08:31:46 UTC
(In reply to Hans Petter Selasky from comment #10)
I tried on 12-stable and 13.0-RELEASE and it doesn't work
Comment 13 Loïc Bartoletti freebsd_committer 2021-04-16 08:36:46 UTC
(In reply to Vladimir Kondratyev from comment #11)
usb_quirk is already loaded
Comment 14 Hans Petter Selasky freebsd_committer 2021-04-16 08:44:00 UTC
Can you set:

sysctl hw.usb.ukbd.debug=17

Then attach the keyboard, and collect messages from dmesg?

--HPS
Comment 15 Vladimir Kondratyev freebsd_committer 2021-04-16 12:22:56 UTC
(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
Comment 16 Loïc Bartoletti freebsd_committer 2021-04-17 08:03:32 UTC
Created attachment 224180 [details]
crash_pic
Comment 17 Loïc Bartoletti freebsd_committer 2021-04-17 08:04:43 UTC
(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
Comment 18 Vladimir Kondratyev freebsd_committer 2021-04-17 09:41:05 UTC
(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)
Comment 19 Hans Petter Selasky freebsd_committer 2021-04-17 10:04:55 UTC
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
Comment 20 Vladimir Kondratyev freebsd_committer 2021-04-17 10:41:37 UTC
(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.
Comment 21 Vladimir Kondratyev freebsd_committer 2021-04-17 12:08:35 UTC
Created attachment 224186 [details]
usbhid-checks-for-uninitialized-xfers.patch

Could you test this patch. I hope it will fix the crash
Comment 22 Loïc Bartoletti freebsd_committer 2021-04-18 05:57:26 UTC
(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
Comment 23 Vladimir Kondratyev freebsd_committer 2021-04-22 23:46:07 UTC
(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.