Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp806771ybz; Fri, 17 Apr 2020 10:21:46 -0700 (PDT) X-Google-Smtp-Source: APiQypKRQciMxMIadoyK7pEUlOFpWuGXDsNn4fM0uaH2P+b/Xjl+NNq+UdhF+c3+J1yqD1bK+t5P X-Received: by 2002:a17:906:7045:: with SMTP id r5mr4127134ejj.29.1587144106193; Fri, 17 Apr 2020 10:21:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587144106; cv=none; d=google.com; s=arc-20160816; b=GxcjDgh1XIzqLxA5v9qRG4QNVsP6T+d4S+YeAkgwwWE/DbwedBvx1x/CQWjviXJXtY QLLahVcYumGKViSkwJd/pg+9lwVQIHX3+D1JAFef8B8FzcAx8PDRBt889X3QvXIqjpe4 v4KQCvJW+PNHddRDS6515Gi/XfnHftgCSOi81eBoSrChXKRGchasATtxteZCY1DK2qYV jsZSFsZbqntgSZqb93zpkA+zfg+A0LuzHvTIOLk5WV2tBMnEvWTwrOnB6gS/O3zMxOnk oSgdakKnXhSnunwTmBgs0XAuIJz1zUlYudAi1NS/nlwlv1E0ZomD8XBm1ZjbuTyHsXlE UFPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HwMhgNUQiCkIMdW07uPbS1uP55IP65k0HuUDpGRwChs=; b=P3xUsxkAXQ1J9KUZcpR3ZE8AX6aUvWajUk4BDnOm6bS7md+1l/5WTo0WQ2VlIO9Gs4 A4hkJpkasvxj2LDItI0HFtNfu6V0AjiiuZBvtuQBCJd3csOjLLWZ8+F5MHsm32fofWfW E8KSMijmNjnTM/qxlf1fHLrXuayfaGR5Qz2hcOfUCgL4U+F2/bdeOKfgtESDYc/eT8DA 1WyCE9lh5Mjid4CqaOVV41PMlg/zrpFd1ipviEbMtA8JbC/zqZXISexnl4BwAApv0OuU yFHi0xNqy4aexTsH05pcXgORvWPw8E53BmEJ8jG/N4FObi7/vHtPFMLKVQ6MmSkrozqf G8XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ccSwLOj6; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i15si14799930ejc.172.2020.04.17.10.21.22; Fri, 17 Apr 2020 10:21:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ccSwLOj6; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 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 S1728657AbgDQRQx (ORCPT + 99 others); Fri, 17 Apr 2020 13:16:53 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:45374 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729710AbgDQRQx (ORCPT ); Fri, 17 Apr 2020 13:16:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587143811; 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=HwMhgNUQiCkIMdW07uPbS1uP55IP65k0HuUDpGRwChs=; b=ccSwLOj6ILce5JffdWVWxvRoxoJIpUzjXvruQc53SUSLiMoIhm5BFpwM5WfJv4lts5H0sY WAEUMCFT5zQpRvw19XKZvftYRIza10q5krHPQE5ErQsl4EQOYwX7d/tVZrkp0mtS/adp8p g2jy8BGVxC28t5Gm88m8qFagc55DLj0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-482-gjRw5rbFPkGFghlByDoWDw-1; Fri, 17 Apr 2020 13:15:43 -0400 X-MC-Unique: gjRw5rbFPkGFghlByDoWDw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DCC3D104FB69; Fri, 17 Apr 2020 17:15:42 +0000 (UTC) Received: from x1.localdomain.com (ovpn-112-195.ams2.redhat.com [10.36.112.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id E078160BE0; Fri, 17 Apr 2020 17:15:41 +0000 (UTC) From: Hans de Goede To: Marcel Holtmann , Johan Hedberg Cc: Hans de Goede , linux-bluetooth@vger.kernel.org Subject: [PATCH 7/8] Bluetooth: btbcm: Try multiple Patch filenames when loading the Patch firmware Date: Fri, 17 Apr 2020 19:15:31 +0200 Message-Id: <20200417171532.448053-7-hdegoede@redhat.com> In-Reply-To: <20200417171532.448053-1-hdegoede@redhat.com> References: <20200417171532.448053-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Content-Transfer-Encoding: quoted-printable Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Currently the bcm_uart_subver_ and bcm_usb_subver_table-s lack entries for various newer chipsets. This makes the code use just "BCM" as prefix for the filename to pass to request-firmware, making it harder for users to figure out which firmware they need. This especially a problem with UART attached devices where this leads to the filename being "BCM.hcd". If we add new entries to the subver-tables now, then this will change what firmware file the kernel looks for, e.g. currently linux-firmware contains a brcm/BCM-0bb4-0306.hcd file. If we add the info for the BCM20703A1 to the subver table, then this will change to brcm/BCM20703A1-0bb4-0306.hcd. This will cause the file to no longer get loaded breaking Bluetooth for existing users, going against the no regressions policy. To avoid this regression make the btbcm code try multiple filenames, first try the fullname, e.g. BCM20703A1-0bb4-0306.hcd and if that is not found, then fallback to the name with just BCM as prefix. This commit also adds an info message which filename was used, this makes the output look like this for example: [ 57.387867] Bluetooth: hci0: BCM20703A1 [ 57.387870] Bluetooth: hci0: BCM20703A1 (001.001.005) build 0000 [ 57.389438] Bluetooth: hci0: BCM20703A1 'brcm/BCM20703A1-0a5c-6410.hcd= ' Patch [ 58.681769] Bluetooth: hci0: BCM20703A1 Generic USB 20Mhz fcbga_BU [ 58.681772] Bluetooth: hci0: BCM20703A1 (001.001.005) build 0481 Signed-off-by: Hans de Goede --- drivers/bluetooth/btbcm.c | 59 ++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c index 9fa153b35825..739ba1200f5d 100644 --- a/drivers/bluetooth/btbcm.c +++ b/drivers/bluetooth/btbcm.c @@ -28,6 +28,9 @@ #define BDADDR_BCM43341B (&(bdaddr_t) {{0xac, 0x1f, 0x00, 0x1b, 0x34, 0x= 43}}) =20 #define BCM_FW_NAME_LEN 64 +#define BCM_FW_NAME_COUNT_MAX 2 +/* For kmalloc-ing the fw-name array instead of putting it on the stack = */ +typedef char bcm_fw_name[BCM_FW_NAME_LEN]; =20 int btbcm_check_bdaddr(struct hci_dev *hdev) { @@ -420,11 +423,13 @@ static const struct bcm_subver_table bcm_usb_subver= _table[] =3D { int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done) { u16 subver, rev, pid, vid; - const char *hw_name =3D "BCM"; struct sk_buff *skb; struct hci_rp_read_local_version *ver; const struct bcm_subver_table *bcm_subver_table; - char fw_name[BCM_FW_NAME_LEN]; + const char *hw_name =3D NULL; + char postfix[16] =3D ""; + int fw_name_count =3D 0; + bcm_fw_name *fw_name; const struct firmware *fw; int i, err; =20 @@ -464,7 +469,7 @@ int btbcm_initialize(struct hci_dev *hdev, bool *fw_l= oad_done) } =20 bt_dev_info(hdev, "%s (%3.3u.%3.3u.%3.3u) build %4.4u", - hw_name, (subver & 0xe000) >> 13, + hw_name ? hw_name : "BCM", (subver & 0xe000) >> 13, (subver & 0x1f00) >> 8, (subver & 0x00ff), rev & 0x0fff); =20 if (*fw_load_done) @@ -480,24 +485,46 @@ int btbcm_initialize(struct hci_dev *hdev, bool *fw= _load_done) pid =3D get_unaligned_le16(skb->data + 3); kfree_skb(skb); =20 - snprintf(fw_name, BCM_FW_NAME_LEN, "brcm/%s-%4.4x-%4.4x.hcd", - hw_name, vid, pid); - } else { - snprintf(fw_name, BCM_FW_NAME_LEN, "brcm/%s.hcd", hw_name); + snprintf(postfix, sizeof(postfix), "-%4.4x-%4.4x", vid, pid); } =20 - err =3D request_firmware(&fw, fw_name, &hdev->dev); - if (err) { - bt_dev_info(hdev, "BCM: Patch %s not found", fw_name); - return 0; + fw_name =3D kmalloc(BCM_FW_NAME_COUNT_MAX * BCM_FW_NAME_LEN, GFP_KERNEL= ); + if (!fw_name) + return -ENOMEM; + + if (hw_name) { + snprintf(fw_name[fw_name_count], BCM_FW_NAME_LEN, + "brcm/%s%s.hcd", hw_name, postfix); + fw_name_count++; } =20 - err =3D btbcm_patchram(hdev, fw); - if (err) - bt_dev_info(hdev, "BCM: Patch failed (%d)", err); + snprintf(fw_name[fw_name_count], BCM_FW_NAME_LEN, + "brcm/BCM%s.hcd", postfix); + fw_name_count++; + + for (i =3D 0; i < fw_name_count; i++) { + err =3D firmware_request_nowarn(&fw, fw_name[i], &hdev->dev); + if (err =3D=3D 0) { + bt_dev_info(hdev, "%s '%s' Patch", + hw_name ? hw_name : "BCM", fw_name[i]); + *fw_load_done =3D true; + break; + } + } + + if (*fw_load_done) { + err =3D btbcm_patchram(hdev, fw); + if (err) + bt_dev_info(hdev, "BCM: Patch failed (%d)", err); + + release_firmware(fw); + } else { + bt_dev_err(hdev, "BCM: firmware Patch file not found, tried:"); + for (i =3D 0; i < fw_name_count; i++) + bt_dev_err(hdev, "BCM: '%s'", fw_name[i]); + } =20 - release_firmware(fw); - *fw_load_done =3D true; + kfree(fw_name); return 0; } EXPORT_SYMBOL_GPL(btbcm_initialize); --=20 2.26.0