linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/3] Bluetooth: btintel: Add firmware lock function
@ 2019-07-17  7:49 Kai-Heng Feng
  2019-07-17  7:49 ` [PATCH v2 2/3] Bluetooth: btusb: Load firmware exclusively for Intel BT Kai-Heng Feng
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Kai-Heng Feng @ 2019-07-17  7:49 UTC (permalink / raw)
  To: johannes.berg, emmanuel.grumbach, luciano.coelho, marcel, johan.hedberg
  Cc: linuxwifi, linux-wireless, netdev, linux-bluetooth, linux-kernel,
	Kai-Heng Feng

When Intel 8260 starts to load Bluetooth firmware and WiFi firmware, by
calling btintel_download_firmware() and iwl_pcie_load_given_ucode_8000()
respectively, the Bluetooth btintel_download_firmware() aborts half way:
[   11.950216] Bluetooth: hci0: Failed to send firmware data (-38)

Let btusb and iwlwifi load firmwares exclusively can avoid the issue, so
introduce a lock to use in btusb and iwlwifi.

This issue still occurs with latest WiFi and Bluetooth firmwares.

BugLink: https://bugs.launchpad.net/bugs/1832988

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v2:
 - Add bug report link.
 - Rebase on latest wireless-next.

 drivers/bluetooth/btintel.c   | 14 ++++++++++++++
 drivers/bluetooth/btintel.h   | 10 ++++++++++
 include/linux/intel-wifi-bt.h |  8 ++++++++
 3 files changed, 32 insertions(+)
 create mode 100644 include/linux/intel-wifi-bt.h

diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c
index bb99c8653aab..93ab18d6ddad 100644
--- a/drivers/bluetooth/btintel.c
+++ b/drivers/bluetooth/btintel.c
@@ -20,6 +20,8 @@
 
 #define BDADDR_INTEL (&(bdaddr_t) {{0x00, 0x8b, 0x9e, 0x19, 0x03, 0x00}})
 
+static DEFINE_MUTEX(firmware_lock);
+
 int btintel_check_bdaddr(struct hci_dev *hdev)
 {
 	struct hci_rp_read_bd_addr *bda;
@@ -709,6 +711,18 @@ int btintel_download_firmware(struct hci_dev *hdev, const struct firmware *fw,
 }
 EXPORT_SYMBOL_GPL(btintel_download_firmware);
 
+void btintel_firmware_lock(void)
+{
+	mutex_lock(&firmware_lock);
+}
+EXPORT_SYMBOL_GPL(btintel_firmware_lock);
+
+void btintel_firmware_unlock(void)
+{
+	mutex_unlock(&firmware_lock);
+}
+EXPORT_SYMBOL_GPL(btintel_firmware_unlock);
+
 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
 MODULE_DESCRIPTION("Bluetooth support for Intel devices ver " VERSION);
 MODULE_VERSION(VERSION);
diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h
index 3d846190f2bf..b3682d27d2ee 100644
--- a/drivers/bluetooth/btintel.h
+++ b/drivers/bluetooth/btintel.h
@@ -87,6 +87,8 @@ int btintel_read_boot_params(struct hci_dev *hdev,
 			     struct intel_boot_params *params);
 int btintel_download_firmware(struct hci_dev *dev, const struct firmware *fw,
 			      u32 *boot_param);
+void btintel_firmware_lock(void);
+void btintel_firmware_unlock(void);
 #else
 
 static inline int btintel_check_bdaddr(struct hci_dev *hdev)
@@ -181,4 +183,12 @@ static inline int btintel_download_firmware(struct hci_dev *dev,
 {
 	return -EOPNOTSUPP;
 }
+
+static inline void btintel_firmware_lock(void)
+{
+}
+
+static inline void btintel_firmware_unlock(void)
+{
+}
 #endif
diff --git a/include/linux/intel-wifi-bt.h b/include/linux/intel-wifi-bt.h
new file mode 100644
index 000000000000..260ed628d19b
--- /dev/null
+++ b/include/linux/intel-wifi-bt.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __INTEL_WIFI_BT_H__
+#define __INTEL_WIFI_BT_H__
+
+void btintel_firmware_lock(void);
+void btintel_firmware_unlock(void);
+
+#endif
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/3] Bluetooth: btusb: Load firmware exclusively for Intel BT
  2019-07-17  7:49 [PATCH v2 1/3] Bluetooth: btintel: Add firmware lock function Kai-Heng Feng
@ 2019-07-17  7:49 ` Kai-Heng Feng
  2019-07-17  7:49 ` [PATCH v2 3/3] iwlwifi: Load firmware exclusively for Intel WiFi Kai-Heng Feng
  2019-07-17 13:36 ` [PATCH v2 1/3] Bluetooth: btintel: Add firmware lock function Marcel Holtmann
  2 siblings, 0 replies; 6+ messages in thread
From: Kai-Heng Feng @ 2019-07-17  7:49 UTC (permalink / raw)
  To: johannes.berg, emmanuel.grumbach, luciano.coelho, marcel, johan.hedberg
  Cc: linuxwifi, linux-wireless, netdev, linux-bluetooth, linux-kernel,
	Kai-Heng Feng

To avoid the firmware loading race between Bluetooth and WiFi on Intel
8260, load firmware exclusively when IWLWIFI is enabled.

BugLink: https://bugs.launchpad.net/bugs/1832988

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v2:
 - Add bug report link.
 - Rebase on latest wireless-next.

 drivers/bluetooth/btusb.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 50aed5259c2b..ca7a5757a2ba 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -2272,8 +2272,16 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
 
 	set_bit(BTUSB_DOWNLOADING, &data->flags);
 
+#if IS_ENABLED(CONFIG_IWLWIFI)
+	btintel_firmware_lock();
+#endif
+
 	/* Start firmware downloading and get boot parameter */
 	err = btintel_download_firmware(hdev, fw, &boot_param);
+
+#if IS_ENABLED(CONFIG_IWLWIFI)
+	btintel_firmware_unlock();
+#endif
 	if (err < 0)
 		goto done;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/3] iwlwifi: Load firmware exclusively for Intel WiFi
  2019-07-17  7:49 [PATCH v2 1/3] Bluetooth: btintel: Add firmware lock function Kai-Heng Feng
  2019-07-17  7:49 ` [PATCH v2 2/3] Bluetooth: btusb: Load firmware exclusively for Intel BT Kai-Heng Feng
@ 2019-07-17  7:49 ` Kai-Heng Feng
  2019-07-17 13:36 ` [PATCH v2 1/3] Bluetooth: btintel: Add firmware lock function Marcel Holtmann
  2 siblings, 0 replies; 6+ messages in thread
From: Kai-Heng Feng @ 2019-07-17  7:49 UTC (permalink / raw)
  To: johannes.berg, emmanuel.grumbach, luciano.coelho, marcel, johan.hedberg
  Cc: linuxwifi, linux-wireless, netdev, linux-bluetooth, linux-kernel,
	Kai-Heng Feng

To avoid the firmware loading race between Bluetooth and WiFi on Intel
8260, load firmware exclusively when BT_INTEL is enabled.

BugLink: https://bugs.launchpad.net/bugs/1832988

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v2:
 - Add bug report link.
 - Rebase on latest wireless-next.

 .../net/wireless/intel/iwlwifi/pcie/trans.c   | 37 ++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c
index 602c31b3992a..e10ff847b216 100644
--- a/drivers/net/wireless/intel/iwlwifi/pcie/trans.c
+++ b/drivers/net/wireless/intel/iwlwifi/pcie/trans.c
@@ -72,6 +72,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/module.h>
 #include <linux/wait.h>
+#include <linux/intel-wifi-bt.h>
 
 #include "iwl-drv.h"
 #include "iwl-trans.h"
@@ -1335,6 +1336,10 @@ static int iwl_trans_pcie_start_fw(struct iwl_trans *trans,
 	bool hw_rfkill;
 	int ret;
 
+#if IS_ENABLED(CONFIG_BT_INTEL)
+	void (*firmware_lock_func)(void);
+	void (*firmware_unlock_func)(void);
+#endif
 	/* This may fail if AMT took ownership of the device */
 	if (iwl_pcie_prepare_card_hw(trans)) {
 		IWL_WARN(trans, "Exit HW not ready\n");
@@ -1394,6 +1399,7 @@ static int iwl_trans_pcie_start_fw(struct iwl_trans *trans,
 	 * RF-Kill switch is toggled, we will find out after having loaded
 	 * the firmware and return the proper value to the caller.
 	 */
+
 	iwl_enable_fw_load_int(trans);
 
 	/* really make sure rfkill handshake bits are cleared */
@@ -1401,8 +1407,37 @@ static int iwl_trans_pcie_start_fw(struct iwl_trans *trans,
 	iwl_write32(trans, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
 
 	/* Load the given image to the HW */
-	if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000)
+	if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000) {
+#if IS_ENABLED(CONFIG_BT_INTEL)
+		firmware_lock_func = symbol_request(btintel_firmware_lock);
+		firmware_unlock_func = symbol_request(btintel_firmware_unlock);
+		if (!firmware_lock_func || !firmware_unlock_func) {
+			if (firmware_lock_func) {
+				symbol_put(btintel_firmware_lock);
+				firmware_lock_func = NULL;
+			}
+
+			if (firmware_unlock_func) {
+				symbol_put(btintel_firmware_unlock);
+				firmware_unlock_func = NULL;
+			}
+		}
+
+		if (firmware_lock_func)
+			firmware_lock_func();
+#endif
 		ret = iwl_pcie_load_given_ucode_8000(trans, fw);
+
+#if IS_ENABLED(CONFIG_BT_INTEL)
+		if (firmware_unlock_func) {
+			firmware_unlock_func();
+			symbol_put(btintel_firmware_lock);
+			firmware_lock_func = NULL;
+			symbol_put(btintel_firmware_unlock);
+			firmware_unlock_func = NULL;
+		}
+#endif
+	}
 	else
 		ret = iwl_pcie_load_given_ucode(trans, fw);
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/3] Bluetooth: btintel: Add firmware lock function
  2019-07-17  7:49 [PATCH v2 1/3] Bluetooth: btintel: Add firmware lock function Kai-Heng Feng
  2019-07-17  7:49 ` [PATCH v2 2/3] Bluetooth: btusb: Load firmware exclusively for Intel BT Kai-Heng Feng
  2019-07-17  7:49 ` [PATCH v2 3/3] iwlwifi: Load firmware exclusively for Intel WiFi Kai-Heng Feng
@ 2019-07-17 13:36 ` Marcel Holtmann
  2019-07-17 14:08   ` Kai-Heng Feng
  2 siblings, 1 reply; 6+ messages in thread
From: Marcel Holtmann @ 2019-07-17 13:36 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: Johannes Berg, emmanuel.grumbach, luciano.coelho, Johan Hedberg,
	linuxwifi, linux-wireless, netdev, linux-bluetooth, linux-kernel

Hi Kai-Heng,

> When Intel 8260 starts to load Bluetooth firmware and WiFi firmware, by
> calling btintel_download_firmware() and iwl_pcie_load_given_ucode_8000()
> respectively, the Bluetooth btintel_download_firmware() aborts half way:
> [   11.950216] Bluetooth: hci0: Failed to send firmware data (-38)
> 
> Let btusb and iwlwifi load firmwares exclusively can avoid the issue, so
> introduce a lock to use in btusb and iwlwifi.
> 
> This issue still occurs with latest WiFi and Bluetooth firmwares.
> 
> BugLink: https://bugs.launchpad.net/bugs/1832988
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> ---
> v2:
> - Add bug report link.
> - Rebase on latest wireless-next.
> 
> drivers/bluetooth/btintel.c   | 14 ++++++++++++++
> drivers/bluetooth/btintel.h   | 10 ++++++++++
> include/linux/intel-wifi-bt.h |  8 ++++++++
> 3 files changed, 32 insertions(+)
> create mode 100644 include/linux/intel-wifi-bt.h
> 
> diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c
> index bb99c8653aab..93ab18d6ddad 100644
> --- a/drivers/bluetooth/btintel.c
> +++ b/drivers/bluetooth/btintel.c
> @@ -20,6 +20,8 @@
> 
> #define BDADDR_INTEL (&(bdaddr_t) {{0x00, 0x8b, 0x9e, 0x19, 0x03, 0x00}})
> 
> +static DEFINE_MUTEX(firmware_lock);
> +
> int btintel_check_bdaddr(struct hci_dev *hdev)
> {
> 	struct hci_rp_read_bd_addr *bda;
> @@ -709,6 +711,18 @@ int btintel_download_firmware(struct hci_dev *hdev, const struct firmware *fw,
> }
> EXPORT_SYMBOL_GPL(btintel_download_firmware);
> 
> +void btintel_firmware_lock(void)
> +{
> +	mutex_lock(&firmware_lock);
> +}
> +EXPORT_SYMBOL_GPL(btintel_firmware_lock);
> +
> +void btintel_firmware_unlock(void)
> +{
> +	mutex_unlock(&firmware_lock);
> +}
> +EXPORT_SYMBOL_GPL(btintel_firmware_unlock);
> +

so I am not in favor of this solution. The hardware guys should start looking into fixing the firmware loading and provide proper firmware that can be loaded at the same time.

I am also not for sure penalizing all Intel Bluetooth/WiFi combos only because one of them has a bug during simultaneous loading of WiFi and Bluetooth firmware.

Frankly it would be better to detect a failed load and try a second time instead of trying to lock each other out. The cross-contamination of WiFi and Bluetooth drivers is just not clean.

Regards

Marcel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/3] Bluetooth: btintel: Add firmware lock function
  2019-07-17 13:36 ` [PATCH v2 1/3] Bluetooth: btintel: Add firmware lock function Marcel Holtmann
@ 2019-07-17 14:08   ` Kai-Heng Feng
  2019-07-26  7:01     ` Johannes Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Kai-Heng Feng @ 2019-07-17 14:08 UTC (permalink / raw)
  To: Marcel Holtmann
  Cc: Johannes Berg, Grumbach, Emmanuel, Luciano Coelho, Johan Hedberg,
	linuxwifi, linux-wireless, netdev, linux-bluetooth, linux-kernel

at 21:36, Marcel Holtmann <marcel@holtmann.org> wrote:

> Hi Kai-Heng,
>
>> When Intel 8260 starts to load Bluetooth firmware and WiFi firmware, by
>> calling btintel_download_firmware() and iwl_pcie_load_given_ucode_8000()
>> respectively, the Bluetooth btintel_download_firmware() aborts half way:
>> [   11.950216] Bluetooth: hci0: Failed to send firmware data (-38)
>>
>> Let btusb and iwlwifi load firmwares exclusively can avoid the issue, so
>> introduce a lock to use in btusb and iwlwifi.
>>
>> This issue still occurs with latest WiFi and Bluetooth firmwares.
>>
>> BugLink: https://bugs.launchpad.net/bugs/1832988
>>
>> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
>> ---
>> v2:
>> - Add bug report link.
>> - Rebase on latest wireless-next.
>>
>> drivers/bluetooth/btintel.c   | 14 ++++++++++++++
>> drivers/bluetooth/btintel.h   | 10 ++++++++++
>> include/linux/intel-wifi-bt.h |  8 ++++++++
>> 3 files changed, 32 insertions(+)
>> create mode 100644 include/linux/intel-wifi-bt.h
>>
>> diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c
>> index bb99c8653aab..93ab18d6ddad 100644
>> --- a/drivers/bluetooth/btintel.c
>> +++ b/drivers/bluetooth/btintel.c
>> @@ -20,6 +20,8 @@
>>
>> #define BDADDR_INTEL (&(bdaddr_t) {{0x00, 0x8b, 0x9e, 0x19, 0x03, 0x00}})
>>
>> +static DEFINE_MUTEX(firmware_lock);
>> +
>> int btintel_check_bdaddr(struct hci_dev *hdev)
>> {
>> 	struct hci_rp_read_bd_addr *bda;
>> @@ -709,6 +711,18 @@ int btintel_download_firmware(struct hci_dev *hdev,  
>> const struct firmware *fw,
>> }
>> EXPORT_SYMBOL_GPL(btintel_download_firmware);
>>
>> +void btintel_firmware_lock(void)
>> +{
>> +	mutex_lock(&firmware_lock);
>> +}
>> +EXPORT_SYMBOL_GPL(btintel_firmware_lock);
>> +
>> +void btintel_firmware_unlock(void)
>> +{
>> +	mutex_unlock(&firmware_lock);
>> +}
>> +EXPORT_SYMBOL_GPL(btintel_firmware_unlock);
>> +
>
> so I am not in favor of this solution. The hardware guys should start  
> looking into fixing the firmware loading and provide proper firmware that  
> can be loaded at the same time.

Of course it’s much better to fix from hardware side.

>
> I am also not for sure penalizing all Intel Bluetooth/WiFi combos only  
> because one of them has a bug during simultaneous loading of WiFi and  
> Bluetooth firmware.

Yes, it’s not ideal.

>
> Frankly it would be better to detect a failed load and try a second time  
> instead of trying to lock each other out. The cross-contamination of WiFi  
> and Bluetooth drivers is just not clean.

Ok. Where do you think is better to handle it, Bluetooth core or USB core?

Kai-Heng

>
> Regards
>
> Marcel



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/3] Bluetooth: btintel: Add firmware lock function
  2019-07-17 14:08   ` Kai-Heng Feng
@ 2019-07-26  7:01     ` Johannes Berg
  0 siblings, 0 replies; 6+ messages in thread
From: Johannes Berg @ 2019-07-26  7:01 UTC (permalink / raw)
  To: Kai-Heng Feng, Marcel Holtmann
  Cc: Luciano Coelho, Johan Hedberg, linuxwifi, linux-wireless,
	linux-bluetooth

[trimming CCs a bit]

> > so I am not in favor of this solution. The hardware guys should start  
> > looking into fixing the firmware loading and provide proper firmware that  
> > can be loaded at the same time.
> 
> Of course it’s much better to fix from hardware side.

I tried to ask around a bit, and am told that a firmware fix (to just
retry the relevant hardware block access) was made. I'll try to figure
out where/how it was (or wasn't?) released.

johannes


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-07-26  7:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-17  7:49 [PATCH v2 1/3] Bluetooth: btintel: Add firmware lock function Kai-Heng Feng
2019-07-17  7:49 ` [PATCH v2 2/3] Bluetooth: btusb: Load firmware exclusively for Intel BT Kai-Heng Feng
2019-07-17  7:49 ` [PATCH v2 3/3] iwlwifi: Load firmware exclusively for Intel WiFi Kai-Heng Feng
2019-07-17 13:36 ` [PATCH v2 1/3] Bluetooth: btintel: Add firmware lock function Marcel Holtmann
2019-07-17 14:08   ` Kai-Heng Feng
2019-07-26  7:01     ` Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).