Message ID | 20240115144538.12018-3-max@enpas.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-26148-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1753027dyc; Mon, 15 Jan 2024 06:58:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IEps0kgiohTVIT2WcK53QzHbQ3yV/XX1usrvmKmSSL32+Y36zvJfNHLjQ/BnUFjoKs6+qTz X-Received: by 2002:a05:6a00:2d15:b0:6d9:93cd:ed07 with SMTP id fa21-20020a056a002d1500b006d993cded07mr8488129pfb.24.1705330704216; Mon, 15 Jan 2024 06:58:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705330704; cv=none; d=google.com; s=arc-20160816; b=wfmlJcNxus+eX9hJVcYE5kEzoq/8jwB3p4qvjYuFAbjH1nLl62DslQ6Mq+vrOGE813 Bm/MAHbJnpzlMZJLiCGebZ18sWDw/DcBN4syuTaK053bT8U/WpXGVeptrcz7uAIh4dT5 IBYiiyfsrYNnslSbDzyNP78fNdM0x75Yo3lBO8pF2uYVwD2vtgEKPECzh54jcsTpxgVq YWYQZmvG54xUfKDWeUM3kh6eGpMT+0wUyBVRRl9axqseJpM4D8ygh0/FVED0blDfNKQk gnpEPRAis+9tG/GNoC6NDEWf9sWMw90/7vGOUyBnt91YRiLu0EVsss2gFNzQ2IjDYz4b hIdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=r4qaaG4IzmgUAqzp5BVDGbgAyK8rJWxpNKdkgUFkw7w=; fh=3M1PHg4byxu2MygWip944LqLZSq0Urk5Qa4iYXrexb8=; b=U+7aKhgoy5tlJ+IlTjJqRhQYl0sr5yLa8zr434UdbwhpzgpvQsIdoPDBmwA8uZfywE qHD8vygvH8+d/pHW0yhGLB07RYplTGF02b2naSfxDKMmWpe/aUNe7qYyjwjYmKkHL7kS JjB4M4n71R49qMJ1OC60fojN9tHNk74CoBirl/g4s0Kg2okh89ztp5Qrf3aqrP4NG5iK Zz8c/iZcetd/nTakY+gnFvuj9JicUYe9W/DhS3i1s5WjI21XcSvmgANf9Epi2dNP4n5q mjn5oa9kUzia5A5U/KIhtl0BawegychNiJRCiPJieWZ99nG8BL3ZEiYBG+GIlaR8QgWL Bo6A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26148-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26148-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id n8-20020a62e508000000b006d9aab1bbd4si8587726pff.77.2024.01.15.06.58.24 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 06:58:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26148-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26148-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26148-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0697A282845 for <ouuuleilei@gmail.com>; Mon, 15 Jan 2024 14:58:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CBE7717748; Mon, 15 Jan 2024 14:58:09 +0000 (UTC) Received: from mail.enpas.org (zhong.enpas.org [46.38.239.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DAB4617586; Mon, 15 Jan 2024 14:58:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=enpas.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=enpas.org Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail.enpas.org (Postfix) with ESMTPSA id 41FB5101643; Mon, 15 Jan 2024 14:48:47 +0000 (UTC) From: Max Staudt <max@enpas.org> To: Roderick Colenbrander <roderick.colenbrander@sony.com>, Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <benjamin.tissoires@redhat.com> Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, max@enpas.org Subject: [PATCH v1 2/7] HID: playstation: DS4: Don't fail on MAC address request Date: Mon, 15 Jan 2024 23:45:33 +0900 Message-Id: <20240115144538.12018-3-max@enpas.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240115144538.12018-1-max@enpas.org> References: <20240115144538.12018-1-max@enpas.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788168848195020257 X-GMAIL-MSGID: 1788168848195020257 |
Series |
HID: playstation: DS4: LED bugfix, third-party gamepad support
|
|
Commit Message
Max Staudt
Jan. 15, 2024, 2:45 p.m. UTC
Some third-party controllers can't report their MAC address.
Since a unique ID is needed for ps_devices_list_add() and
ps_device_register_battery(), let's use hdev->id for this when we don't
have a MAC address.
Signed-off-by: Max Staudt <max@enpas.org>
---
drivers/hid/hid-playstation.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
Comments
On Mon, Jan 15, 2024 at 6:58 AM Max Staudt <max@enpas.org> wrote: > > Some third-party controllers can't report their MAC address. > > Since a unique ID is needed for ps_devices_list_add() and > ps_device_register_battery(), let's use hdev->id for this when we don't > have a MAC address. > > Signed-off-by: Max Staudt <max@enpas.org> > --- > drivers/hid/hid-playstation.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c > index 7f50e13601f0..0a3c442af305 100644 > --- a/drivers/hid/hid-playstation.c > +++ b/drivers/hid/hid-playstation.c > @@ -1966,7 +1966,10 @@ static int dualshock4_get_mac_address(struct dualshock4 *ds4) > DS4_FEATURE_REPORT_PAIRING_INFO_SIZE, false); > if (ret) { > hid_err(hdev, "Failed to retrieve DualShock4 pairing info: %d\n", ret); > - goto err_free; > + hid_err(hdev, "Generating fake MAC address for this device.\n"); > + buf[1] = (hdev->id >> 0) & 0xff; > + buf[2] = (hdev->id >> 8) & 0xff; > + buf[3] = (hdev->id >> 16) & 0xff; > } > > memcpy(ds4->base.mac_address, &buf[1], sizeof(ds4->base.mac_address)); > @@ -1986,7 +1989,6 @@ static int dualshock4_get_mac_address(struct dualshock4 *ds4) > return 0; > } > > -err_free: > kfree(buf); > return ret; > } > @@ -2552,7 +2554,7 @@ static struct ps_device *dualshock4_create(struct hid_device *hdev) > ret = dualshock4_get_mac_address(ds4); > if (ret) { > hid_err(hdev, "Failed to get MAC address from DualShock4\n"); > - return ERR_PTR(ret); > + hid_err(hdev, "Can't detect simultaneous USB/BT connections from this device.\n"); > } > snprintf(hdev->uniq, sizeof(hdev->uniq), "%pMR", ds4->base.mac_address); > > -- > 2.39.2 > > Hi Max, For what type of devices is this not working? This one example of this request which is very foundational for a controller working on even the game console. Are this perhaps USB-only devices? If the case maybe some kind of error is only needed for USB connections. Thanks, Roderick
On 1/25/24 09:39, Roderick Colenbrander wrote: > On Mon, Jan 15, 2024 at 6:58 AM Max Staudt <max@enpas.org> wrote: >> >> Some third-party controllers can't report their MAC address. >> > For what type of devices is this not working? This one example of this > request which is very foundational for a controller working on even > the game console. Are this perhaps USB-only devices? If the case maybe > some kind of error is only needed for USB connections. IIRC I've only seen this quirk with the oddball VID/PID 7545:0104 that my patch 7/7 adds. It is indeed a USB-only controller. I have not tried this device (or any, really) with an actual console, my focus is just on Linux. Admittedly, I'd also like to know what happens on a real PS4 :) My intention was to keep the error message and the solution as universal as possible, in case a controller comes along that has both this quirk *and* Bluetooth. It's a bit of an ugly workaround though - if you (or anyone else) have an idea for a nicer solution, I'd be really glad. Max
On Sat, Jan 27, 2024 at 12:51 AM Max Staudt <max@enpas.org> wrote: > > On 1/25/24 09:39, Roderick Colenbrander wrote: > > On Mon, Jan 15, 2024 at 6:58 AM Max Staudt <max@enpas.org> wrote: > >> > >> Some third-party controllers can't report their MAC address. > >> > > For what type of devices is this not working? This one example of this > > request which is very foundational for a controller working on even > > the game console. Are this perhaps USB-only devices? If the case maybe > > some kind of error is only needed for USB connections. > > IIRC I've only seen this quirk with the oddball VID/PID 7545:0104 that my patch 7/7 adds. It is indeed a USB-only controller. I have not tried this device (or any, really) with an actual console, my focus is just on Linux. Admittedly, I'd also like to know what happens on a real PS4 :) > > My intention was to keep the error message and the solution as universal as possible, in case a controller comes along that has both this quirk *and* Bluetooth. It's a bit of an ugly workaround though - if you (or anyone else) have an idea for a nicer solution, I'd be really glad. > > > Max > I remember on the console side that we support a number of controllers including our official model and some licensed controllers. I recall them taking some different codepaths and HID reports differently. It has been a while, so I don't recall the details. If I remember it could be that all of the licensed ones were USB-only (of course there are some Bluetooth capable clones). For this reason I think not all DS4-compatible devices have a MAC address or handle this request. (We made some fixes in hid-playstation relative to hid-sony, where hid-sony used another less known HID report for the MAC address. Now we use the more commonly known one and that helped other clone devices). I'm not sure about the best way to handle this. I have kind of been leaning towards doing a vid/pid like check for this case even though I really hate it. It could be within dualshock4_get_mac_address as we do some other special handling there too (although having the caller of dualshock4_get_mac_address do it is an option too, but I think within get_mac_address is slightly nicer for now). Thanks, Roderick
On 1/31/24 05:59, Roderick Colenbrander wrote: > I remember on the console side that we support a number of controllers > including our official model and some licensed controllers. I recall > them taking some different codepaths and HID reports differently. It > has been a while, so I don't recall the details. If I remember it > could be that all of the licensed ones were USB-only (of course there > are some Bluetooth capable clones). Now that is an interesting tidbit... if you learn more, I'd be curious to hear about it if possible! > I'm not sure about the best way to handle this. I have kind of been > leaning towards doing a vid/pid like check for this case even though I > really hate it. It could be within dualshock4_get_mac_address as we do > some other special handling there too (although having the caller of > dualshock4_get_mac_address do it is an option too, but I think within > get_mac_address is slightly nicer for now). As suggested in the 7545:0104 patch, how about dropping this patch as well, until we encounter a device we really want to add and that does not provide a MAC address? If it's okay for you, I'd send a v2 of everything after hearing your comment on the patch to make controllers work that don't provide gyro calibration data. Max
diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index 7f50e13601f0..0a3c442af305 100644 --- a/drivers/hid/hid-playstation.c +++ b/drivers/hid/hid-playstation.c @@ -1966,7 +1966,10 @@ static int dualshock4_get_mac_address(struct dualshock4 *ds4) DS4_FEATURE_REPORT_PAIRING_INFO_SIZE, false); if (ret) { hid_err(hdev, "Failed to retrieve DualShock4 pairing info: %d\n", ret); - goto err_free; + hid_err(hdev, "Generating fake MAC address for this device.\n"); + buf[1] = (hdev->id >> 0) & 0xff; + buf[2] = (hdev->id >> 8) & 0xff; + buf[3] = (hdev->id >> 16) & 0xff; } memcpy(ds4->base.mac_address, &buf[1], sizeof(ds4->base.mac_address)); @@ -1986,7 +1989,6 @@ static int dualshock4_get_mac_address(struct dualshock4 *ds4) return 0; } -err_free: kfree(buf); return ret; } @@ -2552,7 +2554,7 @@ static struct ps_device *dualshock4_create(struct hid_device *hdev) ret = dualshock4_get_mac_address(ds4); if (ret) { hid_err(hdev, "Failed to get MAC address from DualShock4\n"); - return ERR_PTR(ret); + hid_err(hdev, "Can't detect simultaneous USB/BT connections from this device.\n"); } snprintf(hdev->uniq, sizeof(hdev->uniq), "%pMR", ds4->base.mac_address);