Received: by 10.223.185.116 with SMTP id b49csp777016wrg; Wed, 14 Feb 2018 06:53:16 -0800 (PST) X-Google-Smtp-Source: AH8x225vWJejXXED+Jzw4rHHcKB61BYcn2i2qLVZzD1uQmaZsY1lYuXFz9uEfn/FvP047LuP0edo X-Received: by 2002:a17:902:6bca:: with SMTP id m10-v6mr4676833plt.351.1518619996318; Wed, 14 Feb 2018 06:53:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518619996; cv=none; d=google.com; s=arc-20160816; b=dmkY/SL+045FYxIXqs8pT/Kr0xKXrWI5dl3L8owKrO0pvdIx5I9P5H9XcUtyD7+l5i 7fYPR+pjlpGvUEq9Q5X01dBj/EqbkIMOALoZl5VXGeycxkWs69Ble9x8AgbQK1UIpt/T x9MyBI59MUhvsxuN5OGw2aSxCVyhJF1x+x7QRNrzSyvrThc99vjQStMa2djYYuGQ3u3V 46JguPnb4XfzrZr73jqIJnnpb/3BatC1WS+ymF3TEQ7EAroRuE9REmWxux/bEXHK9lx6 waPxlwUFvooZNxsWh7jPfVn2dIZelgA79a0xuFPvBvIyoWk9RnOUtmo1M4lg5VRRugx0 +mDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:arc-authentication-results; bh=vUw1RkqCK5dOu3iEGMF3xx1P7/H+oVDrJnCRH6hN/JQ=; b=TnmFFnDrezLI3LIcUsYbrTzzQQuYjDcEuYTUwUAHh5nkhENdpsL9xO8WI/AsMjlWn1 PuS5xnZkD/IicOFixiJEvXd6RCT2uz+md33hV2biGIscki/Y+WB1jYZnBWFXE+yBUqV7 HAug8DSmZrOXripGkP/jWqLRHjX/XetS3H73VAIPcYEjD2J4xcNn3HyN3WmMWppT6P2R cXtuxkkdqey+2vyEW7dDoFd29AaWIf7Zn3u+YWdGAVwPFxWJ9hvYLuXaULUuDahN5mCv hpnBWNYv6y0mflXiu4qQHbcGr+JDTWDsPicSrNrO9OmnGWckeWkYfqWElybD5opqrm/V t4nQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y72-v6si574175plh.556.2018.02.14.06.53.01; Wed, 14 Feb 2018 06:53:16 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031116AbeBNOve (ORCPT + 99 others); Wed, 14 Feb 2018 09:51:34 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:46269 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030650AbeBNOvc (ORCPT ); Wed, 14 Feb 2018 09:51:32 -0500 Received: by mail-qt0-f195.google.com with SMTP id u6so7964299qtg.13 for ; Wed, 14 Feb 2018 06:51:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=vUw1RkqCK5dOu3iEGMF3xx1P7/H+oVDrJnCRH6hN/JQ=; b=EuffLJl2UXLaH/WM3xeoA+w5eFIIMDkUFGFLevqzXOu4E0tODMMtQGbg6/NXiUl4SI I3GmaUD0qLuquCEDivceS6YCA9G7DY+hwQUV1/vQS5V7trqwGheVknzd7Gpe1kozBpXw Mc6KLpazyNstPVUTXGlsxDTYAkH28bNEyuYTRaNz7DlyqTx0YK/Y1LQV862MIcycVNLv FuO621J0IfuSNBt1lpK6BZ+rIYJC+hBEcMa9+tZkDXDUp6by2eDjjNRznTUIeIXajn2B xiaXh9u6gDDlYbEq0PG3QITqXt8CbUshw3kzsUqz7Igzgtx4AXL/JrBACnI4Nj6yjIxg c3vg== X-Gm-Message-State: APf1xPAzaB3eKefbli1TFVSOObt2fucmofDCKdtCbxcKSY7Toq6xlEQZ 2s2meXYs0sVOhlJWzouRTBat1zMGVlDOo6OjIbG9YA== X-Received: by 10.200.35.3 with SMTP id a3mr8423872qta.311.1518619891754; Wed, 14 Feb 2018 06:51:31 -0800 (PST) MIME-Version: 1.0 Received: by 10.200.82.24 with HTTP; Wed, 14 Feb 2018 06:51:31 -0800 (PST) In-Reply-To: <20180213120308.23879-2-rodrigorivascosta@gmail.com> References: <20180213120308.23879-1-rodrigorivascosta@gmail.com> <20180213120308.23879-2-rodrigorivascosta@gmail.com> From: Benjamin Tissoires Date: Wed, 14 Feb 2018 15:51:31 +0100 Message-ID: Subject: Re: [PATCH 2/3] HID: steam: add serial number information. To: Rodrigo Rivas Costa Cc: Jiri Kosina , lkml , linux-input@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 13, 2018 at 1:03 PM, Rodrigo Rivas Costa wrote: > This device has a feature report to send and receive commands. > Use it to get the serial number and set the device's uniq value. > > Signed-off-by: Rodrigo Rivas Costa > --- > drivers/hid/hid-steam.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 86 insertions(+), 3 deletions(-) > > diff --git a/drivers/hid/hid-steam.c b/drivers/hid/hid-steam.c > index 03f912ab5484..f269a986e2be 100644 > --- a/drivers/hid/hid-steam.c > +++ b/drivers/hid/hid-steam.c > @@ -34,12 +34,17 @@ struct steam_device { > unsigned long quirks; > struct work_struct work_connect; > bool connected; > + char serial_no[11]; > }; > > static int steam_register(struct steam_device *steam); > static void steam_unregister(struct steam_device *steam); > static void steam_do_connect_event(struct steam_device *steam, bool connected); > static void steam_do_input_event(struct steam_device *steam, u8 *data); > +static int steam_send_report(struct steam_device *steam, > + u8 *cmd, int size); > +static int steam_recv_report(struct steam_device *steam, > + u8 *data, int size); > > static int steam_input_open(struct input_dev *dev) > { > @@ -55,6 +60,78 @@ static void steam_input_close(struct input_dev *dev) > hid_hw_close(steam->hid_dev); > } > > +#define STEAM_FEATURE_REPORT_SIZE 65 > + > +static int steam_send_report(struct steam_device *steam, > + u8 *cmd, int size) > +{ > + int retry; > + int ret; > + u8 *buf = kzalloc(STEAM_FEATURE_REPORT_SIZE, GFP_KERNEL); Please use hid_alloc_report_buf() as sometimes we need to allocate a slightly bigger report. > + > + if (!buf) > + return -ENOMEM; > + > + /* The report ID is always 0 */ > + memcpy(buf + 1, cmd, size); > + > + /* Sometimes the wireless controller fails with EPIPE > + * when sending a feature report. > + * Doing a HID_REQ_GET_REPORT and waiting for a while > + * seems to fix that. > + */ > + for (retry = 0; retry < 10; ++retry) { > + ret = hid_hw_raw_request(steam->hid_dev, 0, > + buf, size + 1, > + HID_FEATURE_REPORT, HID_REQ_SET_REPORT); > + if (ret != -EPIPE) > + break; > + dbg_hid("%s: failed, retrying (%d times)\n", __func__, retry+1); > + steam_recv_report(steam, NULL, 0); > + msleep(50); > + } > + kfree(buf); > + return ret; > +} > + > +static int steam_recv_report(struct steam_device *steam, > + u8 *data, int size) > +{ > + int ret; > + u8 *buf = kzalloc(STEAM_FEATURE_REPORT_SIZE, GFP_KERNEL); same her hid_alloc_report_buf should be used > + > + if (!buf) > + return -ENOMEM; > + > + /* The report ID is always 0 */ > + ret = hid_hw_raw_request(steam->hid_dev, 0x00, > + buf, STEAM_FEATURE_REPORT_SIZE, > + HID_FEATURE_REPORT, HID_REQ_GET_REPORT); > + memcpy(data, buf + 1, size); > + kfree(buf); > + return ret; > +} > + > +static int steam_get_serial(struct steam_device *steam) > +{ > + /* Send: 0xae 0x15 0x01 > + * Recv: 0xae 0x15 0x01 serialnumber (10 chars) > + */ > + int ret; > + u8 cmd[] = {0xae, 0x15, 0x01}; > + u8 reply[14]; > + > + ret = steam_send_report(steam, cmd, sizeof(cmd)); > + if (ret < 0) > + return ret; > + ret = steam_recv_report(steam, reply, sizeof(reply)); > + if (ret < 0) > + return ret; > + reply[13] = 0; > + strcpy(steam->serial_no, reply + 3); > + return 0; > +} > + > static void steam_work_connect_cb(struct work_struct *work) > { > struct steam_device *steam = container_of(work, struct steam_device, > @@ -385,7 +462,12 @@ static int steam_register(struct steam_device *steam) > > dbg_hid("%s\n", __func__); > > - hid_info(hdev, "Steam Controller connected"); > + ret = steam_get_serial(steam); > + if (ret) > + return ret; > + > + hid_info(hdev, "Steam Controller SN: '%s' connected", > + steam->serial_no); > > input = input_allocate_device(); > if (!input) > @@ -398,7 +480,7 @@ static int steam_register(struct steam_device *steam) > > input->name = "Steam Controller"; > input->phys = hdev->phys; > - input->uniq = hdev->uniq; > + input->uniq = steam->serial_no; > input->id.bustype = hdev->bus; > input->id.vendor = hdev->vendor; > input->id.product = hdev->product; > @@ -447,7 +529,8 @@ static void steam_unregister(struct steam_device *steam) > dbg_hid("%s\n", __func__); > > if (steam->input_dev) { > - hid_info(steam->hid_dev, "Steam Controller disconnected"); > + hid_info(steam->hid_dev, "Steam Controller SN: '%s' disconnected", > + steam->serial_no); > input_unregister_device(steam->input_dev); > steam->input_dev = NULL; > } > -- > 2.16.1 > Rest is OK (minus the multi lines comments as pointed in 1/3) Cheers, Benjamin