Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Conversation

@frickler24
Copy link
Collaborator

... and improve the behavior when modifying modes for RGB keyboards via the modes switch.

Replaces #64 which was based on master:

This pullrequest avoids the most important crashes of the daemon when the polling switches on the RGB keyboards are changed. Unfortunately, the cause of the error is the co-working of the keyboard firmware, the Linux USB driver and the ckb-daemon.

I have tried different test combinations with my K95RGB and M65RGB mouse. The result can be found here: Test.matrix.pdf.

In short, even without the ckb-daemon you can bring the USB driver or even the keyboard itself to crash by moving the state-switches. This is only supplemented by the daemon, so that the user is completely irritated and the cause of the error can no longer be identified.

What I found was a hint in the usb driver about the delays before sending a message: 5ms was the standard. Because I had a lot of trouble with the 8ms settings for my K95RGB, I tried to double this delay. It works a lot better, even not perfect. My suggestion is that we use that increased setting and observe whether we get a timing problem elsewhere.

If you are interested: I have several logfiles from the usb communication to show with wireshark or vusb-analyzer

The following info may be helpful for our users in the README.md file.
But first please check with your HW (K70xxx and others), if that change work for you.

The most reliable way to switch the mode is by following that order:

  • Unplug the keyboard first,
  • switch the mode,
  • wait a few seconds (about 10; this time is for your usb driver to detect the disconnect. This is done very fast normally, but these state transfers are all but normal...)
  • reconnect the keyboard
  • have a look at your system logs (or stdout/stderr, if you have called the ckb-daemon manually).
  • After maximum 15 seconds it should inform you about having started the communication with the KB.

If after 15 seconds the keyboard remains dark or simply not react, the daemon should be killed, the keyboard unplugged and after 15 seconds replugged. The times may vary depending on your system: It is needed for the usb driver to detect the reconnection of the usb device.

Please try killing the daemon gently first with "sudo pkill ckb-daemon", because with this it does some cleanup. Only if the process wont stop (there is a situation with a loop between kernel and daemon), kill it tough and then clean up manually. Example for Linux:
sudo pkill -9 ckb-daemon; sudo rm -rf /dev/input/ckb* # be careful with this statement!!!
If you do not clean up and have a lot of testing, you will have too many devices in the directory (max 10 allowed).

references #48

@hevanaa
Copy link
Contributor

hevanaa commented Feb 28, 2017

I tried this patch now. This is what happens when changing the switch from position "1" to BIOS mode:
switching_from_1_to_bios_mode.txt

And the keyboard is working again in 46 seconds. Keep in mind that this particular keyboard on this platform always has this initialization delay.

Switching back to "1" makes keyboard non-working. Only the following output is shown:
switching_back_to_1.txt

Now I have to unplug and plug it again to get it working:
unplug_to_get_working.txt

And it is working again in just under a minute.

@hevanaa
Copy link
Contributor

hevanaa commented Feb 28, 2017

This is now what I get during bootup (tried to filter all relevant).

bootup.txt

@ghost
Copy link

ghost commented Feb 28, 2017

@hevanaa please upload the logs as files.

@hevanaa
Copy link
Contributor

hevanaa commented Feb 28, 2017

Yes, sorry, fixed.

@frickler24
Copy link
Collaborator Author

@hevanaa soryy, your 3rd and 4th link are dead:
<Error><Code>InternalError</Code><Message>We encountered an internal error. Please try again.</Message><RequestId>BE3CC9572D350209</RequestId><HostId>QUl16ssBOITrFO60luM2Rj5AA5dqLe6ZCTuOHnvHTjdTdMvPHCBPA4D9wTi9D1GlaVd/6e/3erU=</HostId></Error>

@hevanaa
Copy link
Contributor

hevanaa commented Feb 28, 2017

Works over here. I guess it's the problems on Amazon S3.

@frickler24
Copy link
Collaborator Author

frickler24 commented Feb 28, 2017

@hevanaa To logfile 1:
This is a very similar behavior to my K95RGB.
After switching first the USB driver (kernel messages) has a problem to detect the device.
The kernel tries an enumeration (asking for config info) and gets an error -110 several times.
usb 3-6: can't read configurations, error -110
After some time either KB answers correctly or the bus does an internal reset and does not mention it (at 11:39:48).
Anyway, now the KB responds as a single-endpoint device and gets connected by the HID driver from the gdm-x-session process.
After this is done, ckb-daemon detects the new device also:
ckb-daemon[8197]: [I] Connecting Corsair Gaming K70 LUX Keyboard at /var/run/ckb1
ckb-daemon detects the device as single-endpoint: reading >> 1<<...
The current daemon cannot handle RGB devices which do not have 3 EPs, so it does a disconnect
(the last 2 lines in the file, beginning with [I] Disconnecting /var/run/ckb1.

Why the daemon does not tell the OS to claim the interfaces for its HID driver again - I don't know.
But the KB works after the initialization again. OK, 46 seconds is too long.

So far, so (relative) good.
@tatokis This is exact the behavior, we tried to change on weekend. The problem is, that the daemon cannot handle RGB-devices with 1 EP. We must change this, but this may become a hard job.

@frickler24
Copy link
Collaborator Author

@hevanaa the second logfile: Is there really no more lines after
kernel: usb usb3-port6: unable to enumerate USB device?
I ask because you find that line in file 1 also after some -110 timeouts:

feb 28 11:39:25 yggdrasil kernel: usb usb3-port6: unable to enumerate USB device
feb 28 11:39:25 yggdrasil gnome-shell[2122]: JS LOG: [FREON] Render all MenuItems
feb 28 11:39:40 yggdrasil gnome-shell[2122]: JS LOG: [FREON] Render all MenuItems
feb 28 11:39:42 yggdrasil kernel: usb 3-6: new full-speed USB device number 12 using xhci_hcd

OK, after 17 seconds - what ever the kernel has done in between...

If there is really no detection of the KB, I understand, why the KB is dead. But this is Corsair firmware + kernel function and has nothing to do with ckb.
The interesting question is: what should we do in handling the device so that switching does not confuse the firmware?

@frickler24
Copy link
Collaborator Author

@hevanaa ok, files 3 + 4 worked now.

@hevanaa
Copy link
Contributor

hevanaa commented Feb 28, 2017

Yes, this time there were no more lines. The log continues in the third file (I think I only removed a few lines from some Gnome plugin).

@tatokis
Copy link
Collaborator

tatokis commented Feb 28, 2017 via email

@hevanaa
Copy link
Contributor

hevanaa commented Feb 28, 2017

Yes, the power cable is plugged. I will try without and on USB3.

@frickler24
Copy link
Collaborator Author

@hevanaa File 3 starts with a normal init. Because it begins 2 minutes after the last file ends, I guess there is no message about unplugging usb 3-6.
Here again are some -110 timeouts, each waiting for 5 seconds.
Do you really have qirks configured?

What I can see when I debug the usb communication with wireshark, is 3 times the kernel tries a GET_CONFIG which is answered by the device, but the kernel detects the answer as invalid (must be on lowest protocol layer, because wireshark marks it as invalid itself).
Maybe the timeouts result from that. Maybe...

After these timeouts the normal startup process starts:
11:47:14 yggdrasil kernel: usb 3-6: new full-speed USB device number 22 using xhci_hcd
No idea what's going on here, but if X really wants to do this, ok:
11:47:14 yggdrasil /usr/libexec/gdm-x-session[1834]: (II) XINPUT: Adding extended input device "Corsair Corsair Gaming K70 LUX Keyboard " (type: MOUSE, id 11)

New to me is the last block:

feb 28 11:47:16 yggdrasil ckb-daemon[8197]: [E] loadrgb_kb (led_keyboard.c:224): Bad input header
feb 28 11:47:16 yggdrasil ckb-daemon[8197]: [E] loadrgb_kb (led_keyboard.c:228): color = 0, i = 1, mode = 0
feb 28 11:47:16 yggdrasil ckb-daemon[8197]: Input(Antwort): 0e ff 01 3c ff ff ff ff
feb 28 11:47:16 yggdrasil ckb-daemon[8197]: Output (Frage): 0e ff 01 3c
feb 28 11:47:22 yggdrasil ckb-daemon[8197]: [E] os_usbrecv (via led_keyboard.c:233): Connection timed out
feb 28 11:47:22 yggdrasil ckb-daemon[8197]: [W] _start_dev (device.c:45): Unable to load hardware profile
feb 28 11:47:22 yggdrasil kernel: usb 3-6: usbfs: USBDEVFS_CONTROL failed cmd ckb-daemon rqt 161 rq 1 len 64 ret -110
feb 28 11:47:22 yggdrasil ckb-daemon[8197]: [I] Setup finished for /var/run/ckb1

What does it mean? The daemon tries to read the LED profiles, stored to the KB. The protocol for this is fix, but changed on my KB between firmware v204 and 205. You have V204 in your KB. ist there a newer one you can upgrade?
If not, we must change the usb_led_fix to differentiate not only the version number, but the version specific to the hardware.

Even if the hardware could not be read, the KB runs afterwards.

@tatokis
Copy link
Collaborator

tatokis commented Feb 28, 2017 via email

@frickler24
Copy link
Collaborator Author

@tatokis Thank you for that info!

@tatokis
Copy link
Collaborator

tatokis commented Feb 28, 2017 via email

@hevanaa
Copy link
Contributor

hevanaa commented Feb 28, 2017

I feel stupid. I did mess around with different USB ports in the beginning, but apparently nothing worked well before I updated the firmware. Now it's booting fast with only data cable plugged in an USB3 port!

Thanks for that @tatokis!

Uploading same logs as above...

@frickler24
Copy link
Collaborator Author

@hevanaa last file (fresh boot):
Here I can see the timeouts again with 36 seconds time wasting.
Interesting is a sequence I've seen multiple times before:

feb 28 12:02:08 yggdrasil ckb-daemon[805]: [E] os_sendindicators (usb_linux.c:86): Connection timed out
feb 28 12:02:08 yggdrasil kernel: usb 3-6: usbfs: USBDEVFS_CONTROL failed cmd ckb-daemon rqt 33 rq 9 len 1 ret -110
...
feb 28 12:02:13 yggdrasil ckb-daemon[805]: [E] os_usbsend (via firmware.c:15): Connection timed out
feb 28 12:02:13 yggdrasil kernel: usb 3-6: usbfs: USBDEVFS_CONTROL failed cmd ckb-daemon rqt 33 rq 9 len 64 ret -110
feb 28 12:02:19 yggdrasil ckb-daemon[805]: [E] os_usbsend (via firmware.c:15): Connection timed out
feb 28 12:02:19 yggdrasil kernel: usb 3-6: usbfs: USBDEVFS_CONTROL failed cmd ckb-daemon rqt 33 rq 9 len 64 ret -110
feb 28 12:02:24 yggdrasil ckb-daemon[805]: [E] os_usbsend (via firmware.c:15): Connection timed out
feb 28 12:02:24 yggdrasil kernel: usb 3-6: usbfs: USBDEVFS_CONTROL failed cmd ckb-daemon rqt 33 rq 9 len 64 ret -110

This is a receive request to the device and the device does not send an answer or the kernel does not give the request to the device. Even if the -110 comes from the device and errno is set to timeout, there is no time delay!

@hevanaa
Copy link
Contributor

hevanaa commented Feb 28, 2017

Switching from 1 to bios mode:
1_to_bios_test2.txt

And back from bios to 1:
bios_to_1_test2.txt

Worked!

@hevanaa
Copy link
Contributor

hevanaa commented Feb 28, 2017

And a new boot log (filtered). Booting really fast now:
boot_test2.txt

@tatokis
Copy link
Collaborator

tatokis commented Feb 28, 2017 via email

@ghost
Copy link

ghost commented Feb 28, 2017

So, the issue lies somewhere around the second USB cable being connected? I know now that on Strafe RGB the second cable works just as a throughput (a throughput? don't know how it's called) for a USB device, the keyboard itself has a USB input on its surface (so that you can plug a flash drive directly in the keyboard). And I also remember having some problems almost a year ago with two cables being plugged at the same time. I should return to this at some point, actually.

@tatokis
Copy link
Collaborator

tatokis commented Feb 28, 2017 via email

@tatokis
Copy link
Collaborator

tatokis commented Feb 28, 2017 via email

@frickler24
Copy link
Collaborator Author

@tatokis I agree in your last point.
But I never used the second (power) usb cable and have the same problems as the others have.

So and because there are some infos in the 2. logfile sent by @hevanaa which is not correct, I prepared a PR just now.
The lines are:

feb 28 23:39:11 yggdrasil ckb-daemon[805]: [E] os_usbrecv (via firmware.c:15): Connection timed out
feb 28 23:39:11 yggdrasil ckb-daemon[805]: [W] _start_dev (device.c:24): Unable to load firmware version/poll rate
feb 28 23:39:11 yggdrasil kernel: usb 5-2: usbfs: USBDEVFS_CONTROL failed cmd ckb-daemon rqt 161 rq 1 len 64 ret -110
feb 28 23:39:11 yggdrasil ckb-daemon[805]: [I] Setup finished for /var/run/ckb1
feb 28 23:39:11 yggdrasil ckb-daemon[805]: [I] Disconnecting /var/run/ckb1

Let me have a look into the third file. Then we can decide what to do with the FW-hack.

@frickler24
Copy link
Collaborator Author

yes, there is still the firmware-bug (the 2.04 has the new functionality, not the old one!):

feb 28 23:46:38 yggdrasil ckb-daemon[768]: [I] Starting input thread for /var/run/ckb1
feb 28 23:46:39 yggdrasil ckb-daemon[768]: [E] loadrgb_kb (led_keyboard.c:224): Bad input header
feb 28 23:46:39 yggdrasil ckb-daemon[768]: [E] loadrgb_kb (led_keyboard.c:228): color = 0, i = 1, mode = 0
feb 28 23:46:39 yggdrasil ckb-daemon[768]: Input(Antwort): 0e ff 01 3c ff ff ff ff
feb 28 23:46:39 yggdrasil ckb-daemon[768]: Output (Frage): 0e ff 01 3c

Because I cannot revert my FW to 2.04, I cannot say if 2.04 on a K95RGB has the new function also.

So my recommendation is: let's merge the #96 into testing so @hevanaa can test it.

@hevanaa
Copy link
Contributor

hevanaa commented Mar 1, 2017

It works fine with the power cable plugged into an USB3 port, too. So the kernel timeout seems to be an issue with the USB2 port that I used before.

I also left out some rows from the last boot log above. Here is the correct one:
boot_test2_2.txt

@ghost
Copy link

ghost commented Mar 1, 2017

To be honest, I expected quite the contrary - USB3 would have been causing troubles (if there would be such at all). Shall this be a hardware issue? Excuse me if I didn't understand the problem fully.

@ghost
Copy link

ghost commented May 6, 2017

@frickler24
Quoting from #138 (comment):

I'm not sure why this was not merged into testing.

Can we explicitly clarify the status of this PR? If it's ready to be merged, let's merge it.

I am able to test (but haven't done this yet) that:

  • it compiles
  • the daemon detects STRAFE RGB in BIOS mode and deals with it according to some logic (I guess you would want to see the output of the journal and/or the daemon?)

The same clarification request is for the accompanying issue #48 - from what I see we need @tatokis to try? The same clarification request is for #96 and it's accompanying issue mentioned in your last comment here.

From what I see the reason why they are all fluxing (and other PRs as well) is that nobody wrote what else must be done to it or that it's working as expected. And because most of this thread was about solving a kernel timeout and not much about the PR.

Sorry, I'm a bit lost.

Regarding this particular issue, seems like I should put the kb into BIOS mode and tell whether the daemon crashes or not. If I'm mistaken, please correct me.

Also, just for your information:

  • STRAFE RGB doesn't have a mechanical switch to put it into the BIOS mode, one does this with a key combination (F1 + Windows Lock, I don't remember precisely), this might come in useful
  • the power for the kb is going only through one cable (the second one is used as a USB passthrough and I don't connect it)
  • we should explicitly discourage the usage of BIOS mode in the README in bold, yet be tolerant if a user doesn't care and operates in BIOS mode

@frickler24 frickler24 force-pushed the testing-48-Segfault-with-K70-RGB-in-BIOS-mode branch from 9e8bd5c to 0e84888 Compare May 6, 2017 18:24
@frickler24
Copy link
Collaborator Author

frickler24 commented May 6, 2017

@light2yellow Thanks for your comments.

I have had the effect today that my kernel has regularly issued errors. So I looked deeper at the fix again.

It has so far handled only the effect that a device either does not give proper information about its endpoints or the device is in BIOS mode.

In the case of various errors (also in the logs given in this issue by @hevanaa), other errors occur which are due to poor implementation of the communication between OS and firmware (the errors also occur when the daemon is not running).

Today I have expanded the fix in two situations, which appear frequently in the logfiles.
In these situations I call the function usb_tryreset() (several times as necessary). Since I had the error today, I could directly trace that resetting the device over the corresponding ioctl did really help.

Then I repeated some of the tests which I had already commented above. Especially switching between the poll rates leads again and again to exactly such "hangers" in the bus protocol.
Logfile with usb_tryreset implemented.txt

For me the Daemon at least runs better with the patch than without.
Since I know that the communication is a very sensitive part in the daemon,
I suggest that I use it for my own,
and we merge it into the testing branch as soon as 0.2.9 is on master.

To the testing possibilities you have:
Bring your device to BIOS mode. Daemon should mention it and give the control back to the OS.
If you switch back to normal mode, the OS should inform the daemon and he should connect again.
If you also succeed in disturbing the communication between host and device, the driver should react accordingly.
If you do not have such effects by yourself, we only may find other users who fight with it as I do.

I will rebase my branch with branch testing, if it changes.
Then we have it up-to-date if a user has strange connection problems once again.

@ghost
Copy link

ghost commented May 14, 2017

Installed, stopped the daemon, put the kb into BIOS mode and launched the daemon manually.

    ckb: Corsair RGB driver beta-v0.2.7
[I] Root controller ready at /dev/input/ckb0
[I] >>>vendor = 0x1b1c, product = 0x1b20, path = /dev/bus/usb/003/005, syspath = /sys/devices/pci0000:00/0000:00:14.0/usb3/3-4
[I] Connecting Corsair STRAFE RGB Gaming Keyboard at /dev/input/ckb1
[I] claiming interfaces. name=Corsair STRAFE RGB Gaming Keyboard, serial=0E024015AEAA1003550E6848F5001940, firmware=0205; Got >> 1<< as ep_str
[E] os_setupusb (usb_linux.c:318): Unable to read endpoint count from udev, assuming 1 and reading >> 1<< or device is in BIOS mode
[I] Attempting reset...
[I] claiming 1 endpoints
[E] os_usbrecv (via firmware.c:15): Connection timed out
[W] _start_dev (device.c:24): Unable to load firmware version/poll rate
[I] Reset success
[I] Connecting Corsair STRAFE RGB Gaming Keyboard at /dev/input/ckb1
[I] claiming interfaces. name=Corsair STRAFE RGB Gaming Keyboard, serial=0E024015AEAA1003550E6848F5001940, firmware=0205; Got >> 1<< as ep_str
[E] os_setupusb (usb_linux.c:318): Unable to read endpoint count from udev, assuming 1 and reading >> 1<< or device is in BIOS mode
[I] Attempting reset...
[I] claiming 1 endpoints
[I] Reset success
[I] Connecting Corsair STRAFE RGB Gaming Keyboard at /dev/input/ckb1
[I] claiming interfaces. name=Corsair STRAFE RGB Gaming Keyboard, serial=0E024015AEAA1003550E6848F5001940, firmware=0205; Got >> 1<< as ep_str
[E] os_setupusb (usb_linux.c:318): Unable to read endpoint count from udev, assuming 1 and reading >> 1<< or device is in BIOS mode
[I] Attempting reset...
[I] claiming 1 endpoints
[I] Reset success
[I] Connecting Corsair STRAFE RGB Gaming Keyboard at /dev/input/ckb1
[I] claiming interfaces. name=Corsair STRAFE RGB Gaming Keyboard, serial=0E024015AEAA1003550E6848F5001940, firmware=0205; Got >> 1<< as ep_str
[E] os_setupusb (usb_linux.c:318): Unable to read endpoint count from udev, assuming 1 and reading >> 1<< or device is in BIOS mode
[I] Attempting reset...
[I] claiming 1 endpoints
[I] Reset success
[I] Connecting Corsair STRAFE RGB Gaming Keyboard at /dev/input/ckb1
[I] claiming interfaces. name=Corsair STRAFE RGB Gaming Keyboard, serial=0E024015AEAA1003550E6848F5001940, firmware=0205; Got >> 1<< as ep_str
[E] os_setupusb (usb_linux.c:318): Unable to read endpoint count from udev, assuming 1 and reading >> 1<< or device is in BIOS mode
[I] Attempting reset...
[I] claiming 1 endpoints
[I] Reset success
[I] Connecting Corsair STRAFE RGB Gaming Keyboard at /dev/input/ckb1
[I] claiming interfaces. name=Corsair STRAFE RGB Gaming Keyboard, serial=0E024015AEAA1003550E6848F5001940, firmware=0205; Got >> 1<< as ep_str
[E] os_setupusb (usb_linux.c:318): Unable to read endpoint count from udev, assuming 1 and reading >> 1<< or device is in BIOS mode
[I] Attempting reset...
[I] claiming 1 endpoints
[I] Reset success
[I] Disconnecting /dev/input/ckb1
[I] Removed device path /dev/input/ckb1
^C
[I] Caught signal 2
[I] Closing root controller
[I] Removed device path /dev/input/ckb0

@ghost
Copy link

ghost commented May 14, 2017

Same as above, but after the disconnect of ckb1 I pressed the key combination (those ^[OP registered is F1 + Win Lock key) for 3-5 secs and daemon succeeded. I launched ckb in parallel and it registered the kb normally. Good job!

    ckb: Corsair RGB driver beta-v0.2.7
[I] Root controller ready at /dev/input/ckb0
[I] >>>vendor = 0x1b1c, product = 0x1b20, path = /dev/bus/usb/003/008, syspath = /sys/devices/pci0000:00/0000:00:14.0/usb3/3-4
[I] Connecting Corsair STRAFE RGB Gaming Keyboard at /dev/input/ckb1
[I] claiming interfaces. name=Corsair STRAFE RGB Gaming Keyboard, serial=0E024015AEAA1003550E6848F5001940, firmware=0205; Got >> 1<< as ep_str
[E] os_setupusb (usb_linux.c:318): Unable to read endpoint count from udev, assuming 1 and reading >> 1<< or device is in BIOS mode
[I] Attempting reset...
[I] claiming 1 endpoints
[E] os_usbrecv (via firmware.c:15): Connection timed out
[W] _start_dev (device.c:24): Unable to load firmware version/poll rate
[I] Reset success
[I] Connecting Corsair STRAFE RGB Gaming Keyboard at /dev/input/ckb1
[I] claiming interfaces. name=Corsair STRAFE RGB Gaming Keyboard, serial=0E024015AEAA1003550E6848F5001940, firmware=0205; Got >> 1<< as ep_str
[E] os_setupusb (usb_linux.c:318): Unable to read endpoint count from udev, assuming 1 and reading >> 1<< or device is in BIOS mode
[I] Attempting reset...
[I] claiming 1 endpoints
[I] Reset success
[I] Connecting Corsair STRAFE RGB Gaming Keyboard at /dev/input/ckb1
[I] claiming interfaces. name=Corsair STRAFE RGB Gaming Keyboard, serial=0E024015AEAA1003550E6848F5001940, firmware=0205; Got >> 1<< as ep_str
[E] os_setupusb (usb_linux.c:318): Unable to read endpoint count from udev, assuming 1 and reading >> 1<< or device is in BIOS mode
[I] Attempting reset...
[I] claiming 1 endpoints
[I] Reset success
[I] Connecting Corsair STRAFE RGB Gaming Keyboard at /dev/input/ckb1
[I] claiming interfaces. name=Corsair STRAFE RGB Gaming Keyboard, serial=0E024015AEAA1003550E6848F5001940, firmware=0205; Got >> 1<< as ep_str
[E] os_setupusb (usb_linux.c:318): Unable to read endpoint count from udev, assuming 1 and reading >> 1<< or device is in BIOS mode
[I] Attempting reset...
[I] claiming 1 endpoints
[I] Reset success
[I] Connecting Corsair STRAFE RGB Gaming Keyboard at /dev/input/ckb1
[I] claiming interfaces. name=Corsair STRAFE RGB Gaming Keyboard, serial=0E024015AEAA1003550E6848F5001940, firmware=0205; Got >> 1<< as ep_str
[E] os_setupusb (usb_linux.c:318): Unable to read endpoint count from udev, assuming 1 and reading >> 1<< or device is in BIOS mode
[I] Attempting reset...
[I] claiming 1 endpoints
[I] Reset success
[I] Connecting Corsair STRAFE RGB Gaming Keyboard at /dev/input/ckb1
[I] claiming interfaces. name=Corsair STRAFE RGB Gaming Keyboard, serial=0E024015AEAA1003550E6848F5001940, firmware=0205; Got >> 1<< as ep_str
[E] os_setupusb (usb_linux.c:318): Unable to read endpoint count from udev, assuming 1 and reading >> 1<< or device is in BIOS mode
[I] Attempting reset...
[I] claiming 1 endpoints
[I] Reset success
[I] Disconnecting /dev/input/ckb1
[I] Removed device path /dev/input/ckb1
^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP^[OP[I] >>>vendor = 0x1b1c, product = 0x1b20, path = /dev/bus/usb/003/009, syspath = /sys/devices/pci0000:00/0000:00:14.0/usb3/3-4
[I] Connecting Corsair STRAFE RGB Gaming Keyboard at /dev/input/ckb1
[I] claiming interfaces. name=Corsair STRAFE RGB Gaming Keyboard, serial=0E024015AEAA1003550E6848F5001940, firmware=0205; Got >> 3<< as ep_str
[I] claiming 3 endpoints
[I] Starting input thread for /dev/input/ckb1
[I] Setup finished for /dev/input/ckb1
^C
[I] Caught signal 2
[I] Disconnecting /dev/input/ckb1
[I] Removed device path /dev/input/ckb1
[I] Closing root controller
[I] Removed device path /dev/input/ckb0

@frickler24
Copy link
Collaborator Author

OK, but why did you get the endless loop in the first case?
I'll have a look later on this.

When switching K70RGB or K95RGB to BIOS mode, only one usb channel is provided
by the KB driver.
Because in usb_linux.c for all other modes the last channel is not used,
zero channels have to be initialized. this brings the daemon to a SIGSEGV.

While debugging this, sometimes the KB got informations which stopped the KB
completely from working. Only disconnecting + connecting worked,
no software-reset via the switch had been successful in this state.
When connecting a KB in this state to the daemon, 0 channels were detected.
These two special conditions (0 and 1 EP for an RGB device)
got special treatment in the code.
Changing the operating modes for the RGB keyboards that provide this feature
(such as the K70RGB or the K95RGB) will result in massive disruptions
to the daemon and the keyboard itself.

A test matrix is stored in the corresponding issue # 48.

The settings here refer to the timeout before sending a USB message.
The timeout was previously 10ms and has been doubled.

Minor corrections and the clipping of the debug output
in a #define DEBUG were also committed here.
In several cases we have seen error messages in the logfiles like

USBDEVFS_CONTROL failed cmd ckb-daemon rqt 33 rq 9 len 64 ret -110

[W] _start_dev (device.c:24): Unable to load firmware version/poll rate

[E] os_usbsend (via firmware.c:15): Connection timed out

or similar.

This happens if the device is in a status where the communication
between linux and device is corrupted. E.g. with an K95RGB one may
provoke the behavior by moving the poll-rate-switch, eg to BIOS mode.

This fix adds some USB-resets for the device if
either ioctls for getting infos give bad return values
or the device does not provide valuable information about endpoints,
version numbers etc.
@frickler24 frickler24 force-pushed the testing-48-Segfault-with-K70-RGB-in-BIOS-mode branch from 0e84888 to a2b6508 Compare May 14, 2017 20:38
@frickler24
Copy link
Collaborator Author

OK, both log outputs are correct. The first one terminates after 5 try_usbreset() and does a disconnect from ckb1. With this disconnect the OS HID driver manages the device again in BIOS mode.
The second does again 5 try_usbreset, disconnects first and reconnects then. This is the behavior I expected.
Branch conflicts are solved with the last push.
If you want, I'll merge this into testing tomorow.

@ghost
Copy link

ghost commented May 14, 2017

Yes, thank you.

@frickler24 frickler24 merged commit 0e3914f into mattanger:testing May 15, 2017
@frickler24 frickler24 deleted the testing-48-Segfault-with-K70-RGB-in-BIOS-mode branch May 15, 2017 19:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants