From patchwork Fri Apr 17 17:15:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 11495779 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0686F912 for ; Fri, 17 Apr 2020 17:16:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D85B42078E for ; Fri, 17 Apr 2020 17:16:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fYLpWUXl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729684AbgDQRQo (ORCPT ); Fri, 17 Apr 2020 13:16:44 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:36585 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729658AbgDQRQo (ORCPT ); Fri, 17 Apr 2020 13:16:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587143803; 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; bh=WjAevoRtNnA5eQLgcRAeqiJLeblt9WTjZ1CS+lxMnjI=; b=fYLpWUXlq66k1CtpYD9h8mvlqMNFE/fSSpMb7YlQvyMqPX1Dxw7XwxmPD6FLg+Nbdn958S PmGt3rLm4HlJ5BpMLEsfzG3qK3WuK55ToCIrZT13nyaMXDUJSA8KFvnx0yOyBS3dUJHzBH nsyU7e3HdoIMiGNY0NU5hAZkrvykLic= 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-488-nKmmyVq8MCK42vuE7DHaTQ-1; Fri, 17 Apr 2020 13:15:36 -0400 X-MC-Unique: nKmmyVq8MCK42vuE7DHaTQ-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 0D0B9801E70; Fri, 17 Apr 2020 17:15:35 +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 0E21560BF7; Fri, 17 Apr 2020 17:15:33 +0000 (UTC) From: Hans de Goede To: Marcel Holtmann , Johan Hedberg Cc: Hans de Goede , linux-bluetooth@vger.kernel.org Subject: [PATCH 1/8] Bluetooth: btbcm: Drop upper nibble version check from btbcm_initialize() Date: Fri, 17 Apr 2020 19:15:25 +0200 Message-Id: <20200417171532.448053-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org btbcm_initialize() must either return an error; or fill the passed in fw_name, otherwise we end up passing uninitialized stack memory to request_firmware(). Since we have a fallback hw_name of "BCM" not having a known version in the subver field does not matter, drop the check so that we always fill the passed in fw_name. Signed-off-by: Hans de Goede --- drivers/bluetooth/btbcm.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c index 1f498f358f60..b9e1fe052148 100644 --- a/drivers/bluetooth/btbcm.c +++ b/drivers/bluetooth/btbcm.c @@ -440,10 +440,6 @@ int btbcm_initialize(struct hci_dev *hdev, char *fw_name, size_t len, return err; } - /* Upper nibble of rev should be between 0 and 3? */ - if (((rev & 0xf000) >> 12) > 3) - return 0; - bcm_subver_table = (hdev->bus == HCI_USB) ? bcm_usb_subver_table : bcm_uart_subver_table; From patchwork Fri Apr 17 17:15:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 11495781 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F79C92C for ; Fri, 17 Apr 2020 17:16:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0BB792078E for ; Fri, 17 Apr 2020 17:16:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="i1bPjIW9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729686AbgDQRQp (ORCPT ); Fri, 17 Apr 2020 13:16:45 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:36900 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728088AbgDQRQo (ORCPT ); Fri, 17 Apr 2020 13:16:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587143803; 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=g9L+Xx6ldbz31YrRmH5WHkiQ+j02vucVgaDmAo2y/sE=; b=i1bPjIW9gdN/wcPAfb1TL1Zny5IdQraoia3GUBLU5fMTCZaXWCVsNevUGuJz5FivVKgSsj rc2ge00pueAooRsPceE4OWL/tc7GPXNJkCHf/N4DEJ6aCaElBqLOvmvb117OnHRzMO2hUt uuIn6fBqTvzUGkLI/wPnMXRZpMHcFoY= 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-399--s47qxWNOuOKtZIbgdPZxg-1; Fri, 17 Apr 2020 13:15:37 -0400 X-MC-Unique: -s47qxWNOuOKtZIbgdPZxg-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 4E03310444C1; Fri, 17 Apr 2020 17:15:36 +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 555BD60C05; Fri, 17 Apr 2020 17:15:35 +0000 (UTC) From: Hans de Goede To: Marcel Holtmann , Johan Hedberg Cc: Hans de Goede , linux-bluetooth@vger.kernel.org Subject: [PATCH 2/8] Bluetooth: btbcm: Move setting of USE_BDADDR_PROPERTY quirk to hci_bcm.c Date: Fri, 17 Apr 2020 19:15:26 +0200 Message-Id: <20200417171532.448053-2-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 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org btbcm_finalize() is currently only used by UART attached BCM devices. Move the setting of the USE_BDADDR_PROPERTY quirk, which we only want for UART attached devices to hci_bcm in preparation for using btbcm_finalize() for USB attached devices too. Signed-off-by: Hans de Goede --- drivers/bluetooth/btbcm.c | 6 ------ drivers/bluetooth/hci_bcm.c | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c index b9e1fe052148..8052a0e8dbfb 100644 --- a/drivers/bluetooth/btbcm.c +++ b/drivers/bluetooth/btbcm.c @@ -488,12 +488,6 @@ int btbcm_finalize(struct hci_dev *hdev) set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); - /* Some devices ship with the controller default address. - * Allow the bootloader to set a valid address through the - * device tree. - */ - set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks); - return 0; } EXPORT_SYMBOL_GPL(btbcm_finalize); diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c index b236cb11c0dc..dcd2bdf2b4b9 100644 --- a/drivers/bluetooth/hci_bcm.c +++ b/drivers/bluetooth/hci_bcm.c @@ -620,6 +620,12 @@ static int bcm_setup(struct hci_uart *hu) if (err) return err; + /* Some devices ship with the controller default address. + * Allow the bootloader to set a valid address through the + * device tree. + */ + set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hu->hdev->quirks); + if (!bcm_request_irq(bcm)) err = bcm_setup_sleep(hu); From patchwork Fri Apr 17 17:15:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 11495793 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C3BFC912 for ; Fri, 17 Apr 2020 17:17:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A1D83208E4 for ; Fri, 17 Apr 2020 17:17:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dVfzv17i" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729323AbgDQRRG (ORCPT ); Fri, 17 Apr 2020 13:17:06 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:53203 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729748AbgDQRRC (ORCPT ); Fri, 17 Apr 2020 13:17:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587143821; 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=e7fJIHksWMy5Gy3b3361nPibQbHTAIx6woqFPpXkpBU=; b=dVfzv17iALQj/ARgLOAmTyWw1S21CjS6LGZH8e4lgGQBLyzDsRi6ILsyfqR9770pl2/U5S yM/YPrlgoa+O1eRQxxVUDP0j6fJTVkoGYGKIZv+A/+OXVWV8cvtZ4y89/Z5KH8GCx4ccDW Q1btdHdEOugsnzgSGLxFYexUAmIoYPM= 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-466-2R0baf0WNtm_loW1I3L3Kg-1; Fri, 17 Apr 2020 13:15:38 -0400 X-MC-Unique: 2R0baf0WNtm_loW1I3L3Kg-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 C12FA18CA247; Fri, 17 Apr 2020 17:15:37 +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 C353F60BFB; Fri, 17 Apr 2020 17:15:36 +0000 (UTC) From: Hans de Goede To: Marcel Holtmann , Johan Hedberg Cc: Hans de Goede , linux-bluetooth@vger.kernel.org Subject: [PATCH 3/8] Bluetooth: btbcm: Fold Patch loading + applying into btbcm_initialize() Date: Fri, 17 Apr 2020 19:15:27 +0200 Message-Id: <20200417171532.448053-3-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 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Instead of having btbcm_initialize() fill a passed in fw_name buffer and then have its callers use that to request the firmware + load it into the HCI, make btbcm_initialize() do this itself the first time it is called (its get called a second time to reset the HCI after the firmware has been loaded). This removes some code duplication and makes it easier for further patches in this series to try more then 1 firmware filename. Signed-off-by: Hans de Goede --- drivers/bluetooth/btbcm.c | 50 ++++++++++++++++++++++--------------- drivers/bluetooth/btbcm.h | 6 ++--- drivers/bluetooth/hci_bcm.c | 19 +++----------- 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c index 8052a0e8dbfb..c22e90a5e288 100644 --- a/drivers/bluetooth/btbcm.c +++ b/drivers/bluetooth/btbcm.c @@ -27,6 +27,8 @@ #define BDADDR_BCM4345C5 (&(bdaddr_t) {{0xac, 0x1f, 0x00, 0xc5, 0x45, 0x43}}) #define BDADDR_BCM43341B (&(bdaddr_t) {{0xac, 0x1f, 0x00, 0x1b, 0x34, 0x43}}) +#define BCM_FW_NAME_LEN 64 + int btbcm_check_bdaddr(struct hci_dev *hdev) { struct hci_rp_read_bd_addr *bda; @@ -408,14 +410,15 @@ static const struct bcm_subver_table bcm_usb_subver_table[] = { { } }; -int btbcm_initialize(struct hci_dev *hdev, char *fw_name, size_t len, - bool reinit) +int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done) { u16 subver, rev, pid, vid; const char *hw_name = "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 struct firmware *fw; int i, err; /* Reset */ @@ -434,7 +437,7 @@ int btbcm_initialize(struct hci_dev *hdev, char *fw_name, size_t len, kfree_skb(skb); /* Read controller information */ - if (!reinit) { + if (!(*fw_load_done)) { err = btbcm_read_info(hdev); if (err) return err; @@ -460,27 +463,42 @@ int btbcm_initialize(struct hci_dev *hdev, char *fw_name, size_t len, pid = get_unaligned_le16(skb->data + 3); kfree_skb(skb); - snprintf(fw_name, len, "brcm/%s-%4.4x-%4.4x.hcd", + snprintf(fw_name, BCM_FW_NAME_LEN, "brcm/%s-%4.4x-%4.4x.hcd", hw_name, vid, pid); } else { - snprintf(fw_name, len, "brcm/%s.hcd", hw_name); + snprintf(fw_name, BCM_FW_NAME_LEN, "brcm/%s.hcd", hw_name); } bt_dev_info(hdev, "%s (%3.3u.%3.3u.%3.3u) build %4.4u", hw_name, (subver & 0xe000) >> 13, (subver & 0x1f00) >> 8, (subver & 0x00ff), rev & 0x0fff); + if (*fw_load_done) + return 0; + + err = request_firmware(&fw, fw_name, &hdev->dev); + if (err) { + bt_dev_info(hdev, "BCM: Patch %s not found", fw_name); + return 0; + } + + err = btbcm_patchram(hdev, fw); + if (err) + bt_dev_info(hdev, "BCM: Patch failed (%d)", err); + + release_firmware(fw); + *fw_load_done = true; return 0; } EXPORT_SYMBOL_GPL(btbcm_initialize); int btbcm_finalize(struct hci_dev *hdev) { - char fw_name[64]; + bool fw_load_done = true; int err; /* Re-initialize */ - err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), true); + err = btbcm_initialize(hdev, &fw_load_done); if (err) return err; @@ -494,28 +512,20 @@ EXPORT_SYMBOL_GPL(btbcm_finalize); int btbcm_setup_patchram(struct hci_dev *hdev) { - char fw_name[64]; - const struct firmware *fw; + bool fw_load_done = false; struct sk_buff *skb; int err; /* Initialize */ - err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), false); + err = btbcm_initialize(hdev, &fw_load_done); if (err) return err; - err = request_firmware(&fw, fw_name, &hdev->dev); - if (err < 0) { - bt_dev_info(hdev, "BCM: Patch %s not found", fw_name); + if (!fw_load_done) goto done; - } - btbcm_patchram(hdev, fw); - - release_firmware(fw); - - /* Re-initialize */ - err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), true); + /* Re-initialize after loading Patch */ + err = btbcm_initialize(hdev, &fw_load_done); if (err) return err; diff --git a/drivers/bluetooth/btbcm.h b/drivers/bluetooth/btbcm.h index 014ef847a486..8437caba421d 100644 --- a/drivers/bluetooth/btbcm.h +++ b/drivers/bluetooth/btbcm.h @@ -62,8 +62,7 @@ int btbcm_write_pcm_int_params(struct hci_dev *hdev, int btbcm_setup_patchram(struct hci_dev *hdev); int btbcm_setup_apple(struct hci_dev *hdev); -int btbcm_initialize(struct hci_dev *hdev, char *fw_name, size_t len, - bool reinit); +int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done); int btbcm_finalize(struct hci_dev *hdev); #else @@ -105,8 +104,7 @@ static inline int btbcm_setup_apple(struct hci_dev *hdev) return 0; } -static inline int btbcm_initialize(struct hci_dev *hdev, char *fw_name, - size_t len, bool reinit) +static inline int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done) { return 0; } diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c index dcd2bdf2b4b9..6f0c3f2599c0 100644 --- a/drivers/bluetooth/hci_bcm.c +++ b/drivers/bluetooth/hci_bcm.c @@ -550,8 +550,7 @@ static int bcm_flush(struct hci_uart *hu) static int bcm_setup(struct hci_uart *hu) { struct bcm_data *bcm = hu->priv; - char fw_name[64]; - const struct firmware *fw; + bool fw_load_done = false; unsigned int speed; int err; @@ -560,21 +559,12 @@ static int bcm_setup(struct hci_uart *hu) hu->hdev->set_diag = bcm_set_diag; hu->hdev->set_bdaddr = btbcm_set_bdaddr; - err = btbcm_initialize(hu->hdev, fw_name, sizeof(fw_name), false); + err = btbcm_initialize(hu->hdev, &fw_load_done); if (err) return err; - err = request_firmware(&fw, fw_name, &hu->hdev->dev); - if (err < 0) { - bt_dev_info(hu->hdev, "BCM: Patch %s not found", fw_name); + if (!fw_load_done) return 0; - } - - err = btbcm_patchram(hu->hdev, fw); - if (err) { - bt_dev_info(hu->hdev, "BCM: Patch failed (%d)", err); - goto finalize; - } /* Init speed if any */ if (hu->init_speed) @@ -613,9 +603,6 @@ static int bcm_setup(struct hci_uart *hu) btbcm_write_pcm_int_params(hu->hdev, ¶ms); } -finalize: - release_firmware(fw); - err = btbcm_finalize(hu->hdev); if (err) return err; From patchwork Fri Apr 17 17:15:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 11495783 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D5C91668 for ; Fri, 17 Apr 2020 17:16:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 354EE208E4 for ; Fri, 17 Apr 2020 17:16:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CuGLKFoM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729691AbgDQRQr (ORCPT ); Fri, 17 Apr 2020 13:16:47 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:29304 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728088AbgDQRQr (ORCPT ); Fri, 17 Apr 2020 13:16:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587143806; 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=qHwkqC/4pocBCW8rE1cuZp145riqd8MlnpYqgaiib/M=; b=CuGLKFoM+ix2OsfVexCWsqoWHAEGzbp/xEPOuj4v+Uy3A8fqDbaSXiodW4nJMnfOjtiI82 6YF4s4+MDMXcCY/NCrs0e9ZdYR4NBJBQZSIE0rAtDnMWkZhSl9GNU2Ey9Ugd87RQ2S2oj4 H/IedxrBmi/D2/3atWvvxwty9TgntOI= 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-471-NaZsJRmYOY2NTQU6y4SyuQ-1; Fri, 17 Apr 2020 13:15:40 -0400 X-MC-Unique: NaZsJRmYOY2NTQU6y4SyuQ-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 11BD3104FB63; Fri, 17 Apr 2020 17:15:39 +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 149D760BF7; Fri, 17 Apr 2020 17:15:37 +0000 (UTC) From: Hans de Goede To: Marcel Holtmann , Johan Hedberg Cc: Hans de Goede , linux-bluetooth@vger.kernel.org Subject: [PATCH 4/8] Bluetooth: btbcm: Make btbcm_initialize() print local-name on re-init too Date: Fri, 17 Apr 2020 19:15:28 +0200 Message-Id: <20200417171532.448053-4-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 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Make btbcm_initialize() get and print the device's local-name on re-init too, this will make us also print the local-name after loading the Patch on UART attached devices making things more consistent. This also removes some code duplication from btbcm_setup_patchram() and allows more code duplication removal there in a follow-up patch. Signed-off-by: Hans de Goede --- drivers/bluetooth/btbcm.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c index c22e90a5e288..3404021b10bd 100644 --- a/drivers/bluetooth/btbcm.c +++ b/drivers/bluetooth/btbcm.c @@ -360,6 +360,13 @@ static int btbcm_read_info(struct hci_dev *hdev) bt_dev_info(hdev, "BCM: features 0x%2.2x", skb->data[1]); kfree_skb(skb); + return 0; +} + +static int btbcm_print_local_name(struct hci_dev *hdev) +{ + struct sk_buff *skb; + /* Read Local Name */ skb = btbcm_read_local_name(hdev); if (IS_ERR(skb)) @@ -442,6 +449,9 @@ int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done) if (err) return err; } + err = btbcm_print_local_name(hdev); + if (err) + return err; bcm_subver_table = (hdev->bus == HCI_USB) ? bcm_usb_subver_table : bcm_uart_subver_table; @@ -513,7 +523,6 @@ EXPORT_SYMBOL_GPL(btbcm_finalize); int btbcm_setup_patchram(struct hci_dev *hdev) { bool fw_load_done = false; - struct sk_buff *skb; int err; /* Initialize */ @@ -529,14 +538,6 @@ int btbcm_setup_patchram(struct hci_dev *hdev) if (err) return err; - /* Read Local Name */ - skb = btbcm_read_local_name(hdev); - if (IS_ERR(skb)) - return PTR_ERR(skb); - - bt_dev_info(hdev, "%s", (char *)(skb->data + 1)); - kfree_skb(skb); - done: btbcm_check_bdaddr(hdev); From patchwork Fri Apr 17 17:15:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 11495795 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A3E3792C for ; Fri, 17 Apr 2020 17:17:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 834D022209 for ; Fri, 17 Apr 2020 17:17:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OE08oA6o" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729761AbgDQRRI (ORCPT ); Fri, 17 Apr 2020 13:17:08 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:24953 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729089AbgDQRRD (ORCPT ); Fri, 17 Apr 2020 13:17:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587143822; 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=Z6l/zWDZCEaXbXc/ePUQ9stSahTa93C4eKw2IG5XIZw=; b=OE08oA6oG4D+GMWtVbgEj5qSX7fsnebApflgwAmuozxpZ5zzBzNQBwBRMRgw70chJM04s4 YfAEftlm9v0k/ORryUhgjb0w5KXdz0h8JTTzqioTE76SwqquRJEG7PuH0CMxk+VOaNypy4 iYLQhjGg357qN+tFvb3R8dukR+4U9gw= 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-142-gJl3UALLMs2u7MqkWeqrdw-1; Fri, 17 Apr 2020 13:15:41 -0400 X-MC-Unique: gJl3UALLMs2u7MqkWeqrdw-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 527A21088382; Fri, 17 Apr 2020 17:15:40 +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 5667760BE0; Fri, 17 Apr 2020 17:15:39 +0000 (UTC) From: Hans de Goede To: Marcel Holtmann , Johan Hedberg Cc: Hans de Goede , linux-bluetooth@vger.kernel.org Subject: [PATCH 5/8] Bluetooth: btbcm: Make btbcm_setup_patchram use btbcm_finalize Date: Fri, 17 Apr 2020 19:15:29 +0200 Message-Id: <20200417171532.448053-5-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 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org On UART attached devices we do: 1. btbcm_initialize() 2. Setup UART baudrate, etc. 3. btbcm_finalize() After our previous changes we can now also use btbcm_finalize() from the btbcm_setup_patchram() function used on USB devices without any functional changes. This completes unifying the USB and UART paths as much as possible. Signed-off-by: Hans de Goede --- drivers/bluetooth/btbcm.c | 27 ++++++++------------------- drivers/bluetooth/btbcm.h | 4 ++-- drivers/bluetooth/hci_bcm.c | 2 +- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c index 3404021b10bd..cc3628cace35 100644 --- a/drivers/bluetooth/btbcm.c +++ b/drivers/bluetooth/btbcm.c @@ -502,15 +502,16 @@ int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done) } EXPORT_SYMBOL_GPL(btbcm_initialize); -int btbcm_finalize(struct hci_dev *hdev) +int btbcm_finalize(struct hci_dev *hdev, bool *fw_load_done) { - bool fw_load_done = true; int err; - /* Re-initialize */ - err = btbcm_initialize(hdev, &fw_load_done); - if (err) - return err; + /* Re-initialize if necessary */ + if (*fw_load_done) { + err = btbcm_initialize(hdev, fw_load_done); + if (err) + return err; + } btbcm_check_bdaddr(hdev); @@ -530,20 +531,8 @@ int btbcm_setup_patchram(struct hci_dev *hdev) if (err) return err; - if (!fw_load_done) - goto done; - /* Re-initialize after loading Patch */ - err = btbcm_initialize(hdev, &fw_load_done); - if (err) - return err; - -done: - btbcm_check_bdaddr(hdev); - - set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks); - - return 0; + return btbcm_finalize(hdev, &fw_load_done); } EXPORT_SYMBOL_GPL(btbcm_setup_patchram); diff --git a/drivers/bluetooth/btbcm.h b/drivers/bluetooth/btbcm.h index 8437caba421d..8bf01565fdfc 100644 --- a/drivers/bluetooth/btbcm.h +++ b/drivers/bluetooth/btbcm.h @@ -63,7 +63,7 @@ int btbcm_setup_patchram(struct hci_dev *hdev); int btbcm_setup_apple(struct hci_dev *hdev); int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done); -int btbcm_finalize(struct hci_dev *hdev); +int btbcm_finalize(struct hci_dev *hdev, bool *fw_load_done); #else @@ -109,7 +109,7 @@ static inline int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done) return 0; } -static inline int btbcm_finalize(struct hci_dev *hdev) +static inline int btbcm_finalize(struct hci_dev *hdev, bool *fw_load_done) { return 0; } diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c index 6f0c3f2599c0..0c34b6c57f7d 100644 --- a/drivers/bluetooth/hci_bcm.c +++ b/drivers/bluetooth/hci_bcm.c @@ -603,7 +603,7 @@ static int bcm_setup(struct hci_uart *hu) btbcm_write_pcm_int_params(hu->hdev, ¶ms); } - err = btbcm_finalize(hu->hdev); + err = btbcm_finalize(hu->hdev, &fw_load_done); if (err) return err; From patchwork Fri Apr 17 17:15:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 11495785 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 716381893 for ; Fri, 17 Apr 2020 17:16:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 54CFB2078E for ; Fri, 17 Apr 2020 17:16:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BhauOamf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728454AbgDQRQr (ORCPT ); Fri, 17 Apr 2020 13:16:47 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:34266 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729687AbgDQRQr (ORCPT ); Fri, 17 Apr 2020 13:16:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587143806; 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=vWBTUfX4h0qFQMftuBWZYnImAcC3+Kc3kLWX3ba0HJ4=; b=BhauOamf+6/7NF4XPbg7Y814puQ/aOxv5H/+KTyEJNy5rd4f5Th9syUPYAC9t13ceqXEg6 WHz7I4JT4EKcfc7pSct+9bUuKdP2Dx+9Qidf0/+WiVxwJr1pH1soruhHZNqzzoxqBT7tXN dkHlnNZZBrDzg7Dy+/M8UtlmQpNhVUc= 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-458-yA5XRcAzPsGHfwUnrUXu8Q-1; Fri, 17 Apr 2020 13:15:42 -0400 X-MC-Unique: yA5XRcAzPsGHfwUnrUXu8Q-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 9B944DB62; Fri, 17 Apr 2020 17:15:41 +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 9A5CC60BE0; Fri, 17 Apr 2020 17:15:40 +0000 (UTC) From: Hans de Goede To: Marcel Holtmann , Johan Hedberg Cc: Hans de Goede , linux-bluetooth@vger.kernel.org Subject: [PATCH 6/8] Bluetooth: btbcm: Bail sooner from btbcm_initialize() when not loading fw Date: Fri, 17 Apr 2020 19:15:30 +0200 Message-Id: <20200417171532.448053-6-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 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org If we have already loaded the firmware/patchram and btbcm_initialize() is called to re-init the HCI after this then there is no need to get the USB device-ids and build a firmware-filename out of these. Signed-off-by: Hans de Goede --- drivers/bluetooth/btbcm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c index cc3628cace35..9fa153b35825 100644 --- a/drivers/bluetooth/btbcm.c +++ b/drivers/bluetooth/btbcm.c @@ -463,6 +463,13 @@ int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done) } } + bt_dev_info(hdev, "%s (%3.3u.%3.3u.%3.3u) build %4.4u", + hw_name, (subver & 0xe000) >> 13, + (subver & 0x1f00) >> 8, (subver & 0x00ff), rev & 0x0fff); + + if (*fw_load_done) + return 0; + if (hdev->bus == HCI_USB) { /* Read USB Product Info */ skb = btbcm_read_usb_product(hdev); @@ -479,13 +486,6 @@ int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done) snprintf(fw_name, BCM_FW_NAME_LEN, "brcm/%s.hcd", hw_name); } - bt_dev_info(hdev, "%s (%3.3u.%3.3u.%3.3u) build %4.4u", - hw_name, (subver & 0xe000) >> 13, - (subver & 0x1f00) >> 8, (subver & 0x00ff), rev & 0x0fff); - - if (*fw_load_done) - return 0; - err = request_firmware(&fw, fw_name, &hdev->dev); if (err) { bt_dev_info(hdev, "BCM: Patch %s not found", fw_name); From patchwork Fri Apr 17 17:15:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 11495789 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BB31B1983 for ; Fri, 17 Apr 2020 17:16:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F149208E4 for ; Fri, 17 Apr 2020 17:16:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ccSwLOj6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729206AbgDQRQx (ORCPT ); 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 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, 0x43}}) #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]; int btbcm_check_bdaddr(struct hci_dev *hdev) { @@ -420,11 +423,13 @@ static const struct bcm_subver_table bcm_usb_subver_table[] = { int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done) { u16 subver, rev, pid, vid; - const char *hw_name = "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 = NULL; + char postfix[16] = ""; + int fw_name_count = 0; + bcm_fw_name *fw_name; const struct firmware *fw; int i, err; @@ -464,7 +469,7 @@ int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done) } 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); if (*fw_load_done) @@ -480,24 +485,46 @@ int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done) pid = get_unaligned_le16(skb->data + 3); kfree_skb(skb); - 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); } - err = request_firmware(&fw, fw_name, &hdev->dev); - if (err) { - bt_dev_info(hdev, "BCM: Patch %s not found", fw_name); - return 0; + fw_name = 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++; } - err = 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 = 0; i < fw_name_count; i++) { + err = firmware_request_nowarn(&fw, fw_name[i], &hdev->dev); + if (err == 0) { + bt_dev_info(hdev, "%s '%s' Patch", + hw_name ? hw_name : "BCM", fw_name[i]); + *fw_load_done = true; + break; + } + } + + if (*fw_load_done) { + err = 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 = 0; i < fw_name_count; i++) + bt_dev_err(hdev, "BCM: '%s'", fw_name[i]); + } - release_firmware(fw); - *fw_load_done = true; + kfree(fw_name); return 0; } EXPORT_SYMBOL_GPL(btbcm_initialize); From patchwork Fri Apr 17 17:15:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 11495787 X-Patchwork-Delegate: marcel@holtmann.org Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 952EE186E for ; Fri, 17 Apr 2020 17:16:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 793A22078E for ; Fri, 17 Apr 2020 17:16:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VVhpBpp8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729707AbgDQRQu (ORCPT ); Fri, 17 Apr 2020 13:16:50 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:30118 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729687AbgDQRQu (ORCPT ); Fri, 17 Apr 2020 13:16:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587143808; 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=CGv2fgPNnWkB6F6rrs/oOKVeGJrIM+/McUrhS/YxLMo=; b=VVhpBpp8cJuAs12CVTYPZttmS/4ElHYAsEqw3FIVR2td552hQxL8GsEYTn1b90y8jycfyM 297phkZpSv8xvVOdlxVwUPOc5rOHogUinCOMvfwkiEsY2bCpJoLTvDYm3FEtTNofIxmWPL KUCE6ta4pcbDDUIJB9ymT6XNQaUxbAs= 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-10-jYFzj31_MdiSZ7idJWqFKg-1; Fri, 17 Apr 2020 13:15:45 -0400 X-MC-Unique: jYFzj31_MdiSZ7idJWqFKg-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 2781518CA242; Fri, 17 Apr 2020 17:15:44 +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 2FB0760BE0; Fri, 17 Apr 2020 17:15:43 +0000 (UTC) From: Hans de Goede To: Marcel Holtmann , Johan Hedberg Cc: Hans de Goede , linux-bluetooth@vger.kernel.org Subject: [PATCH 8/8] Bluetooth: btbcm: Add 2 missing models to subver tables Date: Fri, 17 Apr 2020 19:15:32 +0200 Message-Id: <20200417171532.448053-8-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 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 the BCM4324B5 and BCM20703A1 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 is problematic with the UART attached BCM4324B5 where this leads to the filename being just "BCM.hcd". Add the 2 missing devices to subver tables. This has been tested on: 1. A Dell XPS15 9550 where this makes btbcm.c try to load "BCM20703A1-0a5c-6410.hcd" before it tries to load "BCM-0a5c-6410.hcd". 2. A Thinkpad 8 where this makes btbcm.c try to load "BCM4324B5.hcd" before it tries to load "BCM.hcd" Signed-off-by: Hans de Goede --- drivers/bluetooth/btbcm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c index 739ba1200f5d..df7a8a22e53c 100644 --- a/drivers/bluetooth/btbcm.c +++ b/drivers/bluetooth/btbcm.c @@ -392,6 +392,7 @@ static const struct bcm_subver_table bcm_uart_subver_table[] = { { 0x410e, "BCM43341B0" }, /* 002.001.014 */ { 0x4204, "BCM2076B1" }, /* 002.002.004 */ { 0x4406, "BCM4324B3" }, /* 002.004.006 */ + { 0x4606, "BCM4324B5" }, /* 002.006.006 */ { 0x6109, "BCM4335C0" }, /* 003.001.009 */ { 0x610c, "BCM4354" }, /* 003.001.012 */ { 0x2122, "BCM4343A0" }, /* 001.001.034 */ @@ -407,6 +408,7 @@ static const struct bcm_subver_table bcm_uart_subver_table[] = { }; static const struct bcm_subver_table bcm_usb_subver_table[] = { + { 0x2105, "BCM20703A1" }, /* 001.001.005 */ { 0x210b, "BCM43142A0" }, /* 001.001.011 */ { 0x2112, "BCM4314A0" }, /* 001.001.018 */ { 0x2118, "BCM20702A0" }, /* 001.001.024 */