Received: by 10.213.65.68 with SMTP id h4csp1784025imn; Mon, 19 Mar 2018 13:10:21 -0700 (PDT) X-Google-Smtp-Source: AG47ELv0e2Q2u8nhCeRkl+BwlzBQGxuVPoFsBVWgiJnSlAy1c3Ew3AOZmsq3gG0841MFAFC6klGn X-Received: by 10.98.75.129 with SMTP id d1mr11310764pfj.19.1521490220929; Mon, 19 Mar 2018 13:10:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521490220; cv=none; d=google.com; s=arc-20160816; b=Z8JDsIgftF6IELSSVNHuK2bmwZXRvXwhMukpPRADRes4OD/1a5gb3uc2DrqDNCTQqf 258ZJzUDkYISd1GHtzNK7mrgV66bE3olKSwf+deUcgh1dLKZqe8zNHGFO/igT+nYwh5d O4mpvh5OatH5bpmsrNoLAbhFTD/ZTRxOxNdCoPt+8WRcp/UbV6fBfmosCBOQyAyKToAn 6EiugUzqTUfLV3OZiL0WoyutHFM20tccc6gJzFiuV453NY4bHa3kC06UlRNLxtIiP5vW ZVA+NXt5O9tTG9UCvx3jZYGNmEbrNcdOIv3IhBROVFwV1skak0wCCgE8YrbofFGiZQVS N8WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=8JTOQdAeRzg20kbEwmnAnLdmRZZNLlnjnY7N0EqP1MI=; b=LH8F+Bxu65I++CTWHFj6I43FzMVmvCNS8vJvrmwrSR5kXDz87Go9aRWD5RxpsufhiS zY6dGOJdvIDw/78VFGFEKZtYUz33RHx6pzklumSd4fp+3W7llglZgVvfg/jm8WNvyVID qduX3le9OiyypsgGtZqxcEj/nRXzYF06tjUVBTQH0LTplbYCmyQHnBgcxRgW2nd/fzXs hAep0j/PGzPqOV+hw3Jv2GdhpdcxrYBbVXcK+MbSHJJtjUahqAAQpS33u7osLgl0+gQR zDFVMls8MdFlcawZzi3DbnyU1Vizej7pVWfL2t0p5TZRvt/WbKoRjPrGR2oVoLi9BvHX VM7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZzGXpRk/; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8-v6si15445plz.31.2018.03.19.13.10.06; Mon, 19 Mar 2018 13:10:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZzGXpRk/; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S969356AbeCSUIg (ORCPT + 99 others); Mon, 19 Mar 2018 16:08:36 -0400 Received: from mail-wr0-f180.google.com ([209.85.128.180]:34666 "EHLO mail-wr0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031435AbeCSUIT (ORCPT ); Mon, 19 Mar 2018 16:08:19 -0400 Received: by mail-wr0-f180.google.com with SMTP id o8so19959168wra.1; Mon, 19 Mar 2018 13:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=8JTOQdAeRzg20kbEwmnAnLdmRZZNLlnjnY7N0EqP1MI=; b=ZzGXpRk/+QkccRKEiR6xF41kQc1qlkUyTdCUa67dSrifP59/yfUbv5+CPyE4KWvTqR Tu73Z3lrPHuBv2hPSUZnfyHuP/AKMBY6nJmq9VkRVJLIP0eFQOud2Bdl2VjX+n0F/6Rh fpqOBGhQ+5FVNLZ3rK/MAWMHXMoNI41ZqQwB1IHrF+VKMmkDhd9BAtHu1R5gWVuGdftT wvmSOLHgYkF+EBvcmn/nFueX/byL50o5qQX4eu43mSRc5geaJGYx22weXnUf9H4Ep+Wt G7T+Pnv80ZrYOkkCKAT4d883e7z0hEeS610CsNmrkEGJiyegSSKBM4AHZrT1Ylzyc9Bs u6Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=8JTOQdAeRzg20kbEwmnAnLdmRZZNLlnjnY7N0EqP1MI=; b=jkO6yJZGOBiMYfg8Zq8HpdAbtL1eZTsZvNzrAF1YNIx3RnTwhMWo1GaVLFic8RxQyX ETL9bCR+RtslEqCiXqXgD3u7KhdF4XmZOozbq6jqCbYOPIu5YwthRiajsylmI8uhZqbN bpNRXKyFkWUzzI2JNbiVmH+J3fd5AkDOEaqwQo/a6q2jvb6Vt4xrjAJMgGoJGQtBnlPu ryQOzFJ1m4hPJ8zvU8R9ClM4asuK5eaueXHAeWnOocQgawX4NFcn7Gme5tJ4ZlfNk7ha 971WUVf9Ub29j15TKSNwwHKRNxpVEG2omgmdUkowB7RVPwde2ABZvomAU3AxXhb/dK79 TyRQ== X-Gm-Message-State: AElRT7HxJMyQIM1v6vrkzKvs5G4FNrT9mOLf9g95eDHAAdcytjVN5082 UMgTdzmEtRemUyRtMp4Bn2U= X-Received: by 10.223.139.68 with SMTP id v4mr11058737wra.23.1521490097019; Mon, 19 Mar 2018 13:08:17 -0700 (PDT) Received: from casa ([2a01:c50e:5126:7a00:455b:d5a9:582c:4e95]) by smtp.gmail.com with ESMTPSA id r6sm1397wrg.63.2018.03.19.13.08.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Mar 2018 13:08:15 -0700 (PDT) Date: Mon, 19 Mar 2018 21:08:13 +0100 From: Rodrigo Rivas Costa To: "Pierre-Loup A. Griffais" Cc: Benjamin Tissoires , =?iso-8859-1?Q?Cl=E9ment?= VUCHENER , Jiri Kosina , Cameron Gutman , lkml , linux-input Subject: Re: [PATCH v5 0/4] new driver for Valve Steam Controller Message-ID: <20180319200813.GA18746@casa> References: <20180311195842.5551-1-rodrigorivascosta@gmail.com> <20180312205158.GB21621@casa> <20180315210659.GA16037@casa> <1c75c511-eada-585e-297f-e90feb17ac8c@valvesoftware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1c75c511-eada-585e-297f-e90feb17ac8c@valvesoftware.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Mar 17, 2018 at 02:54:07PM -0700, Pierre-Loup A. Griffais wrote: > > > On 03/15/2018 02:06 PM, Rodrigo Rivas Costa wrote: > > On Wed, Mar 14, 2018 at 05:39:25PM +0100, Benjamin Tissoires wrote: > > > On Mon, Mar 12, 2018 at 9:51 PM, Rodrigo Rivas Costa > > > wrote: > > > > On Mon, Mar 12, 2018 at 03:30:43PM +0100, Cl?ment VUCHENER wrote: > > > > > 2018-03-11 20:58 GMT+01:00 Rodrigo Rivas Costa : > > > > > > This patchset implements a driver for Valve Steam Controller, based on a > > > > > > reverse analysis by myself. > > > > > > > > > > > > Sorry, I've been out of town for a few weeks and couldn't keep up with this... > > > > > > > > > > > > @Pierre-Loup and @Cl?ment, could you please have another look at this and > > > > > > check if it is worthy? Benjamin will not commit it without an express ACK from > > > > > > Valve. Of course he is right to be cautious, but I checked this driver with > > > > > > the Steam Client and all seems to go just fine. I think that there is a lot of > > > > > > Linux out of the desktop that could use this driver and cannot use the Steam > > > > > > Client. Worst case scenario, this driver can now be blacklisted, but I hope > > > > > > that will not be needed. > > > > > > > > > > I tested the driver with my 4.15 fedora kernel (I only built the > > > > > module not the whole kernel) and I got double inputs (your driver > > > > > input device + steam uinput device) when testing Shovel Knight with > > > > > Steam Big Picture. It seems to work fine when the inputs are the same, > > > > > but after changing the controller configuration in Steam, the issue > > > > > became apparent. > > > > > > > > I assumed that when several joysticks are available, games would listen > > > > to one one of them. It looks like I'm wrong, and some (many?) games will > > > > listen to all available joysticks at the same time. Thus having two > > > > logical joysticks that represent the same physical one is not good. > > > > > > Yeah, the general rule of thumb is "think of the worst thing that can > > > happen, someone will do something worst". > > > > > > > > > > > An easy solution would be that Steam Client grabs this driver > > > > (ioctl(EVIOCGRAB)) when creating the uinput device. Another solution > > > > would be that Steam Client blacklists this driver, of course. > > > > > > This is 2 solutions that rely on a userspace change, and this is not > > > acceptable in its current form. What if people do not upgrade Steam > > > client but upgrade their kernel? Well, Steam might be able to force > > > people to always run the latest shiny available version, but for other > > > games, you can't expect people to have a compatible version of the > > > userspace stack. > > > > Well, if you don't have Steam then you don't have the double input in > > the first place. Unless you are using a different user-mode driver, of > > course. > > > > > > Also, "blacklisting the driver" from Steam client is something the OS > > > can do, but not the client when you run on a different distribution. > > > You need root for that, and I don't want to give root permissions to > > > Steam (or to any user space client that shouldn't have root privileges > > > for what it matters). > > > > Actually Steam needs a system installation that adds udev rules to grant > > uaccess to /dev/uinput and the USB raw device for the controller. > > Adding a /etc/modprobe.d/steam.conf should be possible, too. It would be > > a bit inconvenient because you'll need a distro update of the steam > > package, not just the usual user-mode-only auto-update. > > It's definitely a bit tricky; we've rolled out an update to our reference > package whenever we've added support for new devices (the final Steam > Controller, direct PS4 gamepad led/gyro access through HID, HTC Vive and its > myriad of onboard devices, bootloaders of all these things for firmware > updates, etc). Whenever we have to do that, the rollout never is as smooth > as desired: many users aren't using our own package; even on the > distributions we support directly. Then downstream distributions adopt these > udev changes with various delays (sometimes never), and port them to their > own mechanism of doing things, since everyone has their own idea of a robust > security model. I wish local sessions always had proper access to HID > devices connected to the physical computer the user is sitting at, but I > realize that the basic gaming desktop is just one of many usecases distros > out there have to support and it'd be unreasonable to expect them to focus > exclusively on it. I was afraid of something like that. Let's forget about that option for the moment. > > > > > And without Steam and your external tool, you get double inputs too. I > > > > > tried RetroArch and it was unusable because of the keyboard inputs > > > > > from the lizard mode (e.g. pressing B also presses Esc and quits > > > > > RetroArch). Having to download and compile an external tool to make > > > > > the driver work properly may be too difficult for the user. Your goal > > > > > was to provide an alternative to user space drivers but now you > > > > > actually depend on (a very simple) one. > > > > > > > > Yes, I noticed that. TBH, this driver without Steam Client or the > > > > user-space tool is not very nice, precisely because you'll get constant > > > > Escape and Enter presses, and most games react to those. > > > > > > > > Frankly speaking, I'm not sure how to proceed. I can think of the > > > > following options: > > > > 1.Steam Client installation could add a file to blacklist > > > > hid-steam, just as it adds a few udev rules. > > > > > > But what about RetroArch? And what if you install Steam but want to > > > play SDL games that could benefit from your driver? > > > > That is an issue of solution 1. I actually have the module blacklisted > > in my PC, and run `sudo modprobe hid-steam` to use SDL. > > > > > > 2.The default CONFIG_HID_STEAM can be changed to "n". Maybe only > > > > on the architectures for which there is a Steam Client available. > > > > This way DIY projects will still be able to use it. > > > > > > But this will make the decision to include or not the driver in > > > distributions harder. And if no distribution uses it, you won't have > > > free tests, and you will be alone to maintain it. So that's not ideal > > > either > > > > Could we set the default to 'y' in non-PC systems. It would be enabled > > in my Raspbian, for example... better than nothing. > > > > > > > 3.This driver could be abandoned :-(. Just use Steam Client if possible or > > > > any of the user-mode drivers available. > > > > > > This would be a waste for everybody as it's always better when we share. > > > > Indeed! > > > > I tried a new option: > > 4. The driver detects whether the DEVUSB/HIDRAW device is in use, and > > if that is the case it will disable itself. If the DEVUSB/HIDRAW is > > not in use, then the driver will work normally. A bit hackish maybe > > but it should work. > > > > I tried doing this option 4, but I'm unable to do it properly. I don't > > even know if it is possible... > > > > > > > > > > If we decide for 1 or 2, then the lizard mode could be disabled without > > > > ill effects. We could even enable the gyro and all the other gadgets > > > > without worring about current compatibility. > > > > > > To me, 1 is out of the question. The kernel can't expect a user space > > > change especially if you are knowingly introducing a bug for the end > > > user. > > > > > > 2 is still on the table IMO, and 3 would be a shame. > > > > > > I know we already discussed about sysfs and module parameters, but if > > > the driver will conflict with a userspace stack, the only way would be > > > to have a (dynamic) parameter "enhanced_mode" or > > > "kernel_awesome_support" or whatever which would be a boolean, that > > > defaults to false that Steam can eventually lookup if they want so in > > > the future we can default it to true. When this parameter is set, the > > > driver will create the inputs and toggle the various modes, while when > > > it's toggled off, it'll clean up itself and keep the device as if it > > > were connected to hid-generic. Bonus point, this removes the need for > > > the simple user space tool that enables the mode. > > > > That is doable, but that sysfs/parameter can be changed by a non-root > > user? I looked for a udev rule to grant access to those but found > > nothing. > > > > IIUC, when this parameter is false the driver will do nothing, right? > > The user will just need to change it to true to be able to use it, but > > that will have to be done by root. > > > > I'll try doing this, but I'd appreciate your advice about what approach > > would be better: sysfs? a module parameter? a cdev? or even a EV_MSC? > > > > > > At the end of the day, I think that it is up to Valve what to do. > > > > > > Again, Valve is a big player here, but do not underestimate other > > > projects (like RetroArch mentioned above) because if you break their > > > workflow, they will have the right to request a revert of the commit > > > because it breaks some random user playing games in the far end of > > > Antarctica (yes, penguins do love to play games :-P ) > > > > And everybody loves penguins! If we take away Steam (say a RaspberryPi > > as a canonical example) and disable the lizard mode, then this driver is > > just a regular gamepad. RetroArch should be happy with that. Unless they > > already have an user mode driver for the steam-controller, of course... > > Both of these things seem reasonable to me, with a few caveats: > > - If there's an opt-in mechanism available, it would be good to ensure we > have a way to reliably query its state without requiring extra permissions. > This way, if we know it's likely to affect Steam client functionality, we'll > have the right mechanism to properly message the situation to users. > > - If you find a way for the client to be able to program an opt out when > it's running that is not automatic (eg. by detecting the hidraw device being > opened), we'd be happy to participate with that scheme assuming it doesn't > require extra permissions. As soon as the API is figured out, we can include > it in the client, just send me a heads-up. The one thing that I'd be > cautious of is robust behavior against abnormal client termination. If it's > a sysfs entry we have to poke, I'm worried that if the client crashes we > might not always be able to opt the driver back out. It'd be nice if it was > based on opening an fd instead, this way the kernel would robustly clean up > after us and your driver would kick back in. Ok, I've written the following scheme: * I've added a member to struct steam_device: int hid_usage_count. * Whenver I call hid_hw_open(), hid_usage_count is incremented. * Whenver I call hid_hw_close(), hid_usage_count is decremented. Now, with this little function: static bool steam_is_only_client(struct steam_device *steam) { unsigned int count = steam->hdev->ll_open_count; return count == steam->hid_usage_count; } I can check if the hidraw device is opened from user-space. It is nice because it works not only for SteamClient, but any other user-space hid driver. And it is resistent to crashes, too. It is a bit hacky because I don't think ll_open_count is intended for that, and it is usually protected by a mutex... The proper way, IMO, would be to have a callback for when the hidraw is first opened/last closed, but that does not exist, AFAICT. But hey, it works. The mutexless access is not a big deal, because I call this function on every input report, so I will get the right value eventually. Then if I am the only user, I can disable/enable the lizard mode when opening/closing the input device. Moreover if hidraw is opened, then I bypass the input events, and this gamepad goes idle, preventing the double input problem. It's a bit tricky in the details, but I think I got it right. If you don't think this solution is too hacky, I'll post a reroll with this code, in a few days. I still have to do a few more tests. Now, what I would really want is a review by Valve of my set-lizard function: static void steam_set_lizard_mode(struct steam_device *steam, bool enabled) { if (enabled) { steam_send_report_byte(steam, 0x8e); //enable mouse steam_send_report_byte(steam, 0x85); //enable esc, enter and cursor keys } else { steam_send_report_byte(steam, 0x81); //disable esc, enter and cursor keys steam_write_register(steam, 0x08, 0x07); //disable mouse (cmd: 0x87) } } While it works, I find its asymmetry quite uncanny. I'm afraid that some of these are there for a side effect, this is not their real purpose. Could you give me a hint about this? > Note that there's a general desire on our side to create a reference > userspace implementation that would more or less have the current > functionality of the Steam client, but would be easily usable from other > platforms where the client doesn't currentl run. Unfortunately it's quite a > bit of work, so it's unclear what the timeframe would be, if it ever does > happen. Do you mean the piece of Steam Client that does input-mapping, but as a portable program without the full client? That would be awesome! And if open-sourced, even awesomer!! Thank you all. Rodrigo > Thanks, > - Pierre-Loup > > > > > Best regards. > > Rodrigo > > > > > Cheers, > > > Benjamin > > > > > > > Best Regards. > > > > Rodrigo. > > > > > > > > > Also the button and axis codes do not match the gamepad API doc > > > > > (https://www.kernel.org/doc/Documentation/input/gamepad.txt). > > > > > > > > > > > > > > > > > For full reference, I'm adding a full changelog of this patchset. > > > > > > > > > > > > Changes in v5: > > > > > > * Fix license SPDX to GPL-2.0+. > > > > > > * Minor stylistic changes (BIT(3) instead 0x08 and so on). > > > > > > > > > > > > Changes in v4: > > > > > > * Add command to check the wireless connection status on probe, without > > > > > > waiting for a message (thanks to Cl?ment Vuchener for the tip). > > > > > > * Removed the error code on redundant connection/disconnection messages. That > > > > > > was harmless but polluted dmesg. > > > > > > * Added buttons for touching the left-pad and right-pad. > > > > > > * Fixed a misplaced #include from 2/4 to 1/4. > > > > > > > > > > > > Changes in v3: > > > > > > * Use RCU to do the dynamic connec/disconnect of wireless devices. > > > > > > * Remove entries in hid-quirks.c as they are no longer needed. This allows > > > > > > this module to be blacklisted without side effects. > > > > > > * Do not bypass the virtual keyboard/mouse HID devices to avoid breaking > > > > > > existing use cases (lizard mode). A user-space tool to do that is > > > > > > linked. > > > > > > * Fully separated axes for joystick and left-pad. As it happens. > > > > > > * Add fuzz values for left/right pad axes, they are a little wiggly. > > > > > > > > > > > > Changes in v2: > > > > > > * Remove references to USB. Now the interesting interfaces are selected by > > > > > > looking for the ones with feature reports. > > > > > > * Feature reports buffers are allocated with hid_alloc_report_buf(). > > > > > > * Feature report length is checked, to avoid overflows in case of > > > > > > corrupt/malicius USB devices. > > > > > > * Resolution added to the ABS axes. > > > > > > * A lot of minor cleanups. > > > > > > > > > > > > Rodrigo Rivas Costa (4): > > > > > > HID: add driver for Valve Steam Controller > > > > > > HID: steam: add serial number information. > > > > > > HID: steam: command to check wireless connection > > > > > > HID: steam: add battery device. > > > > > > > > > > > > drivers/hid/Kconfig | 8 + > > > > > > drivers/hid/Makefile | 1 + > > > > > > drivers/hid/hid-ids.h | 4 + > > > > > > drivers/hid/hid-steam.c | 794 ++++++++++++++++++++++++++++++++++++++++++++++++ > > > > > > 4 files changed, 807 insertions(+) > > > > > > create mode 100644 drivers/hid/hid-steam.c > > > > > > > > > > > > -- > > > > > > 2.16.2 > > > > > > > > >