Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1638506rwl; Fri, 31 Mar 2023 14:23:23 -0700 (PDT) X-Google-Smtp-Source: AKy350aFTZUlNXhjRGpuQn277eCEp3x3NwmcEwryezRJsgtcl3ZP+SRrtVBWvWaNel701GZ3NJD7 X-Received: by 2002:a17:906:33d2:b0:92c:6fbf:4d with SMTP id w18-20020a17090633d200b0092c6fbf004dmr27587727eja.40.1680297803355; Fri, 31 Mar 2023 14:23:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680297803; cv=none; d=google.com; s=arc-20160816; b=DEEkqCROBVhXLv6yfX11Cp/vZwri4/OkOpTlaiCY5hTmcuaXXAtiJpZCNEx9Q83sUS 3rihZfjGMaoND+Eig7MiJxCtniyVIGmhDEV2N1TT8f05twLChnARAVs91SXFqY26Wftv 7+wxHe56dqDe7CTs8HmsqGfQdkbgl1M1EM/FhR4YFBJOT+N65ZO+Zwwdosy+3NFs1jjG ifKIjTEeUsoTCEpmLiVgUs52dUZvO8k1Ex+qZuxPPXMOnk71DdtnOXqZ0FbS3bAuzp2q ITtME7ZQWODkrkfQBWBTBReFo4bY56RfWGiRkSxde+17Bl/I9y9nBqzkfBTtftzYxUFo aFFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8jjTu0gEBp3IgjYSiFsToObIbCc9F06ihqOobiqQVF8=; b=0Bmlz7+ahckOwyLZUTXjXtH7vsGtfKAFNY81unUqQWypv9JAha42aXrLHD8A7Cvsgk jmvvUKXOC5UISXNNVA0wJAfd1A58nriRDvhhXCvBEQn0FWNN53pDnyWyHZngNFGFXm8/ jiYy1N+CK246fOmWU3g73lKOzcVH091gaJVWOtboU/YCOaSImx+X6RC6ndKlLmWYpGw+ v9aPt2clxD94IDWj0K4j6y5whcEIwZdteuSTajbq0uZFUOGArwZvIV2Q+U+Y62FewbGz r+bYRNkIhqbLqxPNmHMXQ+rMaOvyibPPUNEM5HWJyD4RMUYwn8iT8xpnk7mWrjDZlYIZ HYZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="E/7WD2LW"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f24-20020a170906739800b008e828688d69si3301637ejl.798.2023.03.31.14.22.58; Fri, 31 Mar 2023 14:23:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="E/7WD2LW"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233011AbjCaVM0 (ORCPT + 99 others); Fri, 31 Mar 2023 17:12:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230092AbjCaVMZ (ORCPT ); Fri, 31 Mar 2023 17:12:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48C421D2C9 for ; Fri, 31 Mar 2023 14:11:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680297098; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8jjTu0gEBp3IgjYSiFsToObIbCc9F06ihqOobiqQVF8=; b=E/7WD2LW9BqzZiGpciugJiGR0KlBu+P22zY+nvKZyJz85WgjLxtvU/k1FrUcPqFFmy914j xStd0zEnl5uYpwmWzSmyqgDTGWUbFpWWYc2JLF1wZPi1ZcE99fPuPfx4yzU9olM7I9A4WF ByPahJls4Ok44xX9AbFCzcsiMLWUV4A= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-475-1ItpC1QkODWy55DDFlLgjQ-1; Fri, 31 Mar 2023 17:11:35 -0400 X-MC-Unique: 1ItpC1QkODWy55DDFlLgjQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CA2CA1C05AF0; Fri, 31 Mar 2023 21:11:34 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.192.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14BC4492B00; Fri, 31 Mar 2023 21:11:33 +0000 (UTC) From: Hans de Goede To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz Cc: Hans de Goede , linux-bluetooth@vger.kernel.org Subject: [PATCH 1/4] Bluetooth: hci_bcm: Fall back to getting bdaddr from EFI if not set Date: Fri, 31 Mar 2023 23:11:21 +0200 Message-Id: <20230331211124.463003-2-hdegoede@redhat.com> In-Reply-To: <20230331211124.463003-1-hdegoede@redhat.com> References: <20230331211124.463003-1-hdegoede@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org On some devices the BCM Bluetooth adapter does not have a valid bdaddr set. btbcm.c currently sets HCI_QUIRK_INVALID_BDADDR to indicate when this is the case. But this requires users to manual setup a btaddr, by doing e.g.: btmgmt -i hci0 public-addr 'B0:F1:EC:82:1D:B3' Which means that Bluetooth will not work out of the box on such devices. To avoid this (where possible) hci_bcm sets: HCI_QUIRK_USE_BDADDR_PROPERTY which tries to get the bdaddr from devicetree. But this only works on devicetree platforms. On UEFI based platforms there is a special Broadcom UEFI variable which when present contains the devices bdaddr, just like how there is another UEFI variable which contains wifi nvram contents including the wifi MAC address. Add support for getting the bdaddr from this Broadcom UEFI variable, so that Bluetooth will work OOTB for users on devices where this UEFI variable is present. This fixes Bluetooth not working on for example Asus T100HA 2-in-1s. Signed-off-by: Hans de Goede --- drivers/bluetooth/btbcm.c | 47 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c index 3006e2a0f37e..cf5b26b8850a 100644 --- a/drivers/bluetooth/btbcm.c +++ b/drivers/bluetooth/btbcm.c @@ -6,6 +6,7 @@ * Copyright (C) 2015 Intel Corporation */ +#include #include #include #include @@ -34,6 +35,43 @@ /* For kmalloc-ing the fw-name array instead of putting it on the stack */ typedef char bcm_fw_name[BCM_FW_NAME_LEN]; +#ifdef CONFIG_EFI +static int btbcm_set_bdaddr_from_efi(struct hci_dev *hdev) +{ + efi_guid_t guid = EFI_GUID(0x74b00bd9, 0x805a, 0x4d61, 0xb5, 0x1f, + 0x43, 0x26, 0x81, 0x23, 0xd1, 0x13); + bdaddr_t efi_bdaddr, bdaddr; + efi_status_t status; + unsigned long len; + int ret; + + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) + return -EOPNOTSUPP; + + len = sizeof(efi_bdaddr); + status = efi.get_variable(L"BDADDR", &guid, NULL, &len, &efi_bdaddr); + if (status != EFI_SUCCESS) + return -ENXIO; + + if (len != sizeof(efi_bdaddr)) + return -EIO; + + baswap(&bdaddr, &efi_bdaddr); + + ret = btbcm_set_bdaddr(hdev, &bdaddr); + if (ret) + return ret; + + bt_dev_info(hdev, "BCM: Using EFI device address (%pMR)", &bdaddr); + return 0; +} +#else +static int btbcm_set_bdaddr_from_efi(struct hci_dev *hdev) +{ + return -EOPNOTSUPP; +} +#endif + int btbcm_check_bdaddr(struct hci_dev *hdev) { struct hci_rp_read_bd_addr *bda; @@ -87,9 +125,12 @@ int btbcm_check_bdaddr(struct hci_dev *hdev) !bacmp(&bda->bdaddr, BDADDR_BCM4345C5) || !bacmp(&bda->bdaddr, BDADDR_BCM43430A0) || !bacmp(&bda->bdaddr, BDADDR_BCM43341B)) { - bt_dev_info(hdev, "BCM: Using default device address (%pMR)", - &bda->bdaddr); - set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); + /* Try falling back to BDADDR EFI variable */ + if (btbcm_set_bdaddr_from_efi(hdev) != 0) { + bt_dev_info(hdev, "BCM: Using default device address (%pMR)", + &bda->bdaddr); + set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); + } } kfree_skb(skb); -- 2.39.1