Skip to content

Commit b9a2562

Browse files
Amitbagholtmann
authored andcommitted
Bluetooth: btusb: Trigger Intel FW download error recovery
Sometimes during FW data download stage, in case of an error is encountered the controller device could not be recovered. To recover from such failures send Intel hard Reset to re-trigger FW download in following error scenarios: 1. Intel Read version command error 2. Firmware download timeout 3. Failure in Intel Soft Reset for switching to operational FW 4. Boot timeout for switching to operaional FW Signed-off-by: Raghuram Hegde <raghuram.hegde@intel.com> Signed-off-by: Chethan T N <chethan.tumkur.narayan@intel.com> Signed-off-by: Amit K Bag <amit.k.bag@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent eb8c101 commit b9a2562

3 files changed

Lines changed: 67 additions & 4 deletions

File tree

‎drivers/bluetooth/btintel.c‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,51 @@ int btintel_download_firmware(struct hci_dev *hdev, const struct firmware *fw,
709709
}
710710
EXPORT_SYMBOL_GPL(btintel_download_firmware);
711711

712+
void btintel_reset_to_bootloader(struct hci_dev *hdev)
713+
{
714+
struct intel_reset params;
715+
struct sk_buff *skb;
716+
717+
/* Send Intel Reset command. This will result in
718+
* re-enumeration of BT controller.
719+
*
720+
* Intel Reset parameter description:
721+
* reset_type : 0x00 (Soft reset),
722+
* 0x01 (Hard reset)
723+
* patch_enable : 0x00 (Do not enable),
724+
* 0x01 (Enable)
725+
* ddc_reload : 0x00 (Do not reload),
726+
* 0x01 (Reload)
727+
* boot_option: 0x00 (Current image),
728+
* 0x01 (Specified boot address)
729+
* boot_param: Boot address
730+
*
731+
*/
732+
params.reset_type = 0x01;
733+
params.patch_enable = 0x01;
734+
params.ddc_reload = 0x01;
735+
params.boot_option = 0x00;
736+
params.boot_param = cpu_to_le32(0x00000000);
737+
738+
skb = __hci_cmd_sync(hdev, 0xfc01, sizeof(params),
739+
&params, HCI_INIT_TIMEOUT);
740+
if (IS_ERR(skb)) {
741+
bt_dev_err(hdev, "FW download error recovery failed (%ld)",
742+
PTR_ERR(skb));
743+
return;
744+
}
745+
bt_dev_info(hdev, "Intel reset sent to retry FW download");
746+
kfree_skb(skb);
747+
748+
/* Current Intel BT controllers(ThP/JfP) hold the USB reset
749+
* lines for 2ms when it receives Intel Reset in bootloader mode.
750+
* Whereas, the upcoming Intel BT controllers will hold USB reset
751+
* for 150ms. To keep the delay generic, 150ms is chosen here.
752+
*/
753+
msleep(150);
754+
}
755+
EXPORT_SYMBOL_GPL(btintel_reset_to_bootloader);
756+
712757
MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
713758
MODULE_DESCRIPTION("Bluetooth support for Intel devices ver " VERSION);
714759
MODULE_VERSION(VERSION);

‎drivers/bluetooth/btintel.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ int btintel_read_boot_params(struct hci_dev *hdev,
8787
struct intel_boot_params *params);
8888
int btintel_download_firmware(struct hci_dev *dev, const struct firmware *fw,
8989
u32 *boot_param);
90+
void btintel_reset_to_bootloader(struct hci_dev *hdev);
9091
#else
9192

9293
static inline int btintel_check_bdaddr(struct hci_dev *hdev)
@@ -181,4 +182,9 @@ static inline int btintel_download_firmware(struct hci_dev *dev,
181182
{
182183
return -EOPNOTSUPP;
183184
}
185+
186+
static inline void btintel_reset_to_bootloader(struct hci_dev *hdev)
187+
{
188+
return -EOPNOTSUPP;
189+
}
184190
#endif

‎drivers/bluetooth/btusb.c‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,8 +2182,11 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
21822182
* loaded.
21832183
*/
21842184
err = btintel_read_version(hdev, &ver);
2185-
if (err)
2185+
if (err) {
2186+
bt_dev_err(hdev, "Intel Read version failed (%d)", err);
2187+
btintel_reset_to_bootloader(hdev);
21862188
return err;
2189+
}
21872190

21882191
/* The hardware platform number has a fixed value of 0x37 and
21892192
* for now only accept this single value.
@@ -2326,9 +2329,13 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
23262329

23272330
/* Start firmware downloading and get boot parameter */
23282331
err = btintel_download_firmware(hdev, fw, &boot_param);
2329-
if (err < 0)
2332+
if (err < 0) {
2333+
/* When FW download fails, send Intel Reset to retry
2334+
* FW download.
2335+
*/
2336+
btintel_reset_to_bootloader(hdev);
23302337
goto done;
2331-
2338+
}
23322339
set_bit(BTUSB_FIRMWARE_LOADED, &data->flags);
23332340

23342341
bt_dev_info(hdev, "Waiting for firmware download to complete");
@@ -2355,6 +2362,7 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
23552362
if (err) {
23562363
bt_dev_err(hdev, "Firmware loading timeout");
23572364
err = -ETIMEDOUT;
2365+
btintel_reset_to_bootloader(hdev);
23582366
goto done;
23592367
}
23602368

@@ -2381,8 +2389,11 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
23812389
set_bit(BTUSB_BOOTING, &data->flags);
23822390

23832391
err = btintel_send_intel_reset(hdev, boot_param);
2384-
if (err)
2392+
if (err) {
2393+
bt_dev_err(hdev, "Intel Soft Reset failed (%d)", err);
2394+
btintel_reset_to_bootloader(hdev);
23852395
return err;
2396+
}
23862397

23872398
/* The bootloader will not indicate when the device is ready. This
23882399
* is done by the operational firmware sending bootup notification.
@@ -2404,6 +2415,7 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
24042415

24052416
if (err) {
24062417
bt_dev_err(hdev, "Device boot timeout");
2418+
btintel_reset_to_bootloader(hdev);
24072419
return -ETIMEDOUT;
24082420
}
24092421

0 commit comments

Comments
 (0)