Bluetooth: btintel: Add helper function to download firmware
PATCH v2 1/2 Bluetooth: btintel: Add helper function to download firmware
1) add a helper function to download firmware for new generation Intel controllers
2) add a function to construct firmware / ddc file name for new generation Intel controllers
---
Changes in v2:
- Fix typo in commit message
drivers/bluetooth/btintel.h | 6 ++ drivers/bluetooth/btusb.c | 183 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+)
drivers/bluetooth/btintel.h +6 -0
@@ -132,6 +132,12 @@ struct intel_debug_features {__u8 page1[16 ]; } __packed; +#define INTEL_HW_PLATFORM (cnvx_bt) ((u8)(((cnvx_bt) & 0x0000ff00) >> 8)) +#define INTEL_HW_VARIANT (cnvx_bt) ((u8)(((cnvx_bt) & 0x003f0000) >> 16)) +#define INTEL_CNVX_TOP_TYPE (cnvx_top) ((cnvx_top) & 0x00000fff) +#define INTEL_CNVX_TOP_STEP (cnvx_top) (((cnvx_top) & 0x0f000000) >> 24) +#define INTEL_CNVX_TOP_PACK_SWAB (t, s) __swab16(((__u16)(((t) << 4) | (s)))) +#if IS_ENABLED (CONFIG_BT_INTEL )int btintel_check_bdaddr (struct hci_dev *hdev);
drivers/bluetooth/btusb.c +183 -0
189 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 2/2 Bluetooth: btintel: Add *setup* function for new generation Intel controllers
1) add a flag to identify new geneeration Intel controllers
2) define *setup* and hook it up for new genertion Intel controllers
3) map Typhoon Peak controller (PID:0x0032) to new generation controller
---
Changes in v2:
- None
drivers/bluetooth/btusb.c | 145 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 3 deletions(-)
drivers/bluetooth/btusb.c +142 -3
@@ -59,6 +59,7 @@ static struct usb_driver btusb_driver;#define BTUSB_MEDIATEK 0x200000#define BTUSB_WIDEBAND_SPEECH 0x400000#define BTUSB_VALID_LE_STATES 0x800000 +#define BTUSB_INTEL_NEWGEN 0x1000000static const struct usb_device_id btusb_table[] = {/* Generic Bluetooth USB device */
@@ -360,7 +361,7 @@ static const struct usb_device_id blacklist_table[] = { BTUSB_WIDEBAND_SPEECH }, { USB_DEVICE(0x8087, 0x0029), .driver_info = BTUSB_INTEL_NEW | BTUSB_WIDEBAND_SPEECH }, - { USB_DEVICE(0x8087, 0x0032), .driver_info = BTUSB_INTEL_NEW | + { USB_DEVICE(0x8087, 0x0032), .driver_info = BTUSB_INTEL_NEWGEN | BTUSB_WIDEBAND_SPEECH}, { USB_DEVICE(0x8087, 0x07da), .driver_info = BTUSB_CSR }, { USB_DEVICE(0x8087, 0x07dc), .driver_info = BTUSB_INTEL },
@@ -2871,6 +2872,138 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)return 0 ; } +static int btusb_setup_intel_newgen (struct hci_dev *hdev) +{ +struct btusb_data *data =hci_get_drvdata (hdev); +u32 boot_param; +char ddcname[64 ]; +ktime_t calltime, delta, rettime; +unsigned long long duration; +int err; +struct intel_debug_features features; +struct intel_version_tlv version; + +BT_DBG ("%s" , hdev->name); + +/* Set the default boot parameter to 0x0 and it is updated to +* SKU specific boot parameter after reading Intel_Write_Boot_Params +* command while downloading the firmware. +*/ + boot_param =0x00000000 ; + + calltime =ktime_get (); + +/* Read the Intel version information to determine if the device +* is in bootloader mode or if it already has operational firmware +* loaded. +*/ + err =btintel_read_version_tlv (hdev, &version); +if (err) { +bt_dev_err (hdev,"Intel Read version failed (%d)" , err); +btintel_reset_to_bootloader (hdev); +return err; + } + +btintel_version_info_tlv (hdev, &version); + + err =btusb_intel_download_firmware_newgen (hdev, &version, &boot_param); +if (err) +return err; + +/* check if controller is already having an operational firmware */ +if (version.img_type ==0x03 ) + goto finish; + + rettime =ktime_get (); + delta =ktime_sub (rettime, calltime); + duration = (unsigned long long )ktime_to_ns (delta) >>10 ; + +bt_dev_info (hdev,"Firmware loaded in %llu usecs" , duration); + + calltime =ktime_get (); + +set_bit (BTUSB_BOOTING , &data->flags); + + err =btintel_send_intel_reset (hdev, boot_param); +if (err) { +bt_dev_err (hdev,"Intel Soft Reset failed (%d)" , err); +btintel_reset_to_bootloader (hdev); +return err; + } + +/* The bootloader will not indicate when the device is ready. This +* is done by the operational firmware sending bootup notification. +* +* Booting into operational firmware should not take longer than +* 1 second. However if that happens, then just fail the setup +* since something went wrong. +*/ +bt_dev_info (hdev,"Waiting for device to boot" ); + + err =wait_on_bit_timeout (&data->flags,BTUSB_BOOTING , +TASK_INTERRUPTIBLE , +msecs_to_jiffies (1000 )); + +if (err == -EINTR ) { +bt_dev_err (hdev,"Device boot interrupted" ); +return -EINTR ; + } + +if (err) { +bt_dev_err (hdev,"Device boot timeout" ); +btintel_reset_to_bootloader (hdev); +return -ETIMEDOUT ; + } + + rettime =ktime_get (); + delta =ktime_sub (rettime, calltime); + duration = (unsigned long long )ktime_to_ns (delta) >>10 ; + +bt_dev_info (hdev,"Device booted in %llu usecs" , duration); + +clear_bit (BTUSB_BOOTLOADER , &data->flags); + + err =btusb_setup_intel_newgen_get_fw_name (&version, ddcname, +sizeof (ddcname),"ddc" ); +if (!err) { +bt_dev_err (hdev,"Unsupported Intel firmware naming" ); + }else { +/* Once the device is running in operational mode, it needs to +* apply the device configuration (DDC) parameters. +* +* The device can work without DDC parameters, so even if it +* fails to load the file, no need to fail the setup. +*/ +btintel_load_ddc_config (hdev, ddcname); + } + +/* Read the Intel supported features and if new exception formats +* supported, need to load the additional DDC config to enable. +*/ +btintel_read_debug_features (hdev, &features); + +/* Set DDC mask for available debug features */ +btintel_set_debug_features (hdev, &features); + +/* Read the Intel version information after loading the FW */ + err =btintel_read_version_tlv (hdev, &version); +if (err) +return err; + +btintel_version_info_tlv (hdev, &version); + +finish: +/* Set the event mask for Intel specific vendor events. This enables +* a few extra events that are useful during general operation. It +* does not enable any debugging related events. +* +* The device will function correctly without these events enabled +* and thus no need to fail the setup. +*/ +btintel_set_event_mask (hdev, false); + +return 0 ; +}static int btusb_shutdown_intel (struct hci_dev *hdev) {struct sk_buff *skb;
@@ -4119,7 +4252,8 @@ static int btusb_probe(struct usb_interface *intf,init_usb_anchor (&data->ctrl_anchor);spin_lock_init (&data->rxlock); -if (id->driver_info &BTUSB_INTEL_NEW ) { +if ((id->driver_info &BTUSB_INTEL_NEW ) || + (id->driver_info &BTUSB_INTEL_NEWGEN )) { data->recv_event = btusb_recv_event_intel; data->recv_bulk = btusb_recv_bulk_intel;set_bit (BTUSB_BOOTLOADER , &data->flags);
@@ -4214,7 +4348,8 @@ static int btusb_probe(struct usb_interface *intf,set_bit (HCI_QUIRK_NON_PERSISTENT_DIAG , &hdev->quirks); } -if (id->driver_info &BTUSB_INTEL_NEW ) { +if ((id->driver_info &BTUSB_INTEL_NEW ) || + (id->driver_info &BTUSB_INTEL_NEWGEN )) { hdev->manufacturer =2 ; hdev->send = btusb_send_frame_intel; hdev->setup = btusb_setup_intel_new;
@@ -4228,6 +4363,10 @@ static int btusb_probe(struct usb_interface *intf,set_bit (HCI_QUIRK_NON_PERSISTENT_DIAG , &hdev->quirks); } +/* Overload only setup function for new generation Intel controllers */ +if (id->driver_info &BTUSB_INTEL_NEWGEN ) + hdev->setup = btusb_setup_intel_newgen; +if (id->driver_info &BTUSB_MARVELL ) hdev->set_bdaddr = btusb_set_bdaddr_marvell;
Signature · 1 line
2.7.4
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Kiran,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on bluetooth-next/master]
[also build test WARNING on v5.9-rc6 next-20200925]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Kiran-K/Bluetooth-btintel-Add-helper-function-to-download-firmware/20200926-135059 base: https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master config: alpha-randconfig-r034-20200925 (attached as .config) compiler: alpha-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/5bb97dc4287da6a927e38203604b1199021bb572
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Kiran-K/Bluetooth-btintel-Add-helper-function-to-download-firmware/20200926-135059 git checkout 5bb97dc4287da6a927e38203604b1199021bb572
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=alpha
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/bluetooth/btusb.c:2374:5: warning: no previous prototype for 'btusb_intel_download_firmware_newgen' [-Wmissing-prototypes]
2374 | int btusb_intel_download_firmware_newgen(struct hci_dev *hdev,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/btusb_intel_download_firmware_newgen +2374 drivers/bluetooth/btusb.c
2373
> 2374 int btusb_intel_download_firmware_newgen(struct hci_dev *hdev,
2375 struct intel_version_tlv *ver,
2376 u32 *boot_param)
2377 {
2378 const struct firmware *fw;
2379 char fwname[64];
2380 int err;
2381 struct btusb_data *data = hci_get_drvdata(hdev);
2382
2383 if (!ver || !boot_param)
2384 return -EINVAL;
2385
2386 /* The hardware platform number has a fixed value of 0x37 and
2387 * for now only accept this single value.
2388 */
2389 if (INTEL_HW_PLATFORM(ver->cnvi_bt) != 0x37) {
2390 bt_dev_err(hdev, "Unsupported Intel hardware platform (0x%2x)",
2391 INTEL_HW_PLATFORM(ver->cnvi_bt));
2392 return -EINVAL;
2393 }
2394
2395 /* The firmware variant determines if the device is in bootloader
2396 * mode or is running operational firmware. The value 0x03 identifies
2397 * the bootloader and the value 0x23 identifies the operational
2398 * firmware.
2399 *
2400 * When the operational firmware is already present, then only
2401 * the check for valid Bluetooth device address is needed. This
2402 * determines if the device will be added as configured or
2403 * unconfigured controller.
2404 *
2405 * It is not possible to use the Secure Boot Parameters in this
2406 * case since that command is only available in bootloader mode.
2407 */
2408 if (ver->img_type == 0x03) {
2409 clear_bit(BTUSB_BOOTLOADER, &data->flags);
2410 btintel_check_bdaddr(hdev);
2411 return 0;
2412 }
2413
2414 /* Check for supported iBT hardware variants of this firmware
2415 * loading method.
2416 *
2417 * This check has been put in place to ensure correct forward
2418 * compatibility options when newer hardware variants come along.
2419 */
2420 switch (INTEL_HW_VARIANT(ver->cnvi_bt)) {
2421 case 0x17: /* TyP */
2422 case 0x18: /* Slr */
2423 case 0x19: /* Slr-F */
2424 break;
2425 default:
2426 bt_dev_err(hdev, "Unsupported Intel hardware variant (0x%x)",
2427 INTEL_HW_VARIANT(ver->cnvi_bt));
2428 return -EINVAL;
2429 }
2430
2431 /* If the device is not in bootloader mode, then the only possible
2432 * choice is to return an error and abort the device initialization.
2433 */
2434 if (ver->img_type != 0x01) {
2435 bt_dev_err(hdev, "Unsupported Intel firmware variant (0x%x)",
2436 ver->img_type);
2437 return -ENODEV;
2438 }
2439
2440 /* It is required that every single firmware fragment is acknowledged
2441 * with a command complete event. If the boot parameters indicate
2442 * that this bootloader does not send them, then abort the setup.
2443 */
2444 if (ver->limited_cce != 0x00) {
2445 bt_dev_err(hdev, "Unsupported Intel firmware loading method (0x%x)",
2446 ver->limited_cce);
2447 return -EINVAL;
2448 }
2449
2450 /* Secure boot engine type should be either 1 (ECDSA) or 0 (RSA) */
2451 if (ver->sbe_type > 0x01) {
2452 bt_dev_err(hdev, "Unsupported Intel secure boot engine type (0x%x)",
2453 ver->sbe_type);
2454 return -EINVAL;
2455 }
2456
2457 /* If the OTP has no valid Bluetooth device address, then there will
2458 * also be no valid address for the operational firmware.
2459 */
2460 if (!bacmp(&ver->otp_bd_addr, BDADDR_ANY)) {
2461 bt_dev_info(hdev, "No device address configured");
2462 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
2463 }
2464
2465 err = btusb_setup_intel_newgen_get_fw_name(ver, fwname, sizeof(fwname),
2466 "sfi");
2467 if (!err) {
2468 bt_dev_err(hdev, "Unsupported Intel firmware naming");
2469 return -EINVAL;
2470 }
2471
2472 err = request_firmware(&fw, fwname, &hdev->dev);
2473 if (err < 0) {
2474 bt_dev_err(hdev, "Failed to load Intel firmware file (%d)", err);
2475 return err;
2476 }
2477
2478 bt_dev_info(hdev, "Found device firmware: %s", fwname);
2479
2480 if (fw->size < 644) {
2481 bt_dev_err(hdev, "Invalid size of firmware file (%zu)",
2482 fw->size);
2483 err = -EBADF;
2484 goto done;
2485 }
2486
2487 set_bit(BTUSB_DOWNLOADING, &data->flags);
2488
2489 /* Start firmware downloading and get boot parameter */
2490 err = btintel_download_firmware_newgen(hdev, fw, boot_param,
2491 INTEL_HW_VARIANT(ver->cnvi_bt),
2492 ver->sbe_type);
2493 if (err < 0) {
2494 /* When FW download fails, send Intel Reset to retry
2495 * FW download.
2496 */
2497 btintel_reset_to_bootloader(hdev);
2498 goto done;
2499 }
2500 set_bit(BTUSB_FIRMWARE_LOADED, &data->flags);
2501
2502 bt_dev_info(hdev, "Waiting for firmware download to complete");
2503
2504 /* Before switching the device into operational mode and with that
2505 * booting the loaded firmware, wait for the bootloader notification
2506 * that all fragments have been successfully received.
2507 *
2508 * When the event processing receives the notification, then the
2509 * BTUSB_DOWNLOADING flag will be cleared.
2510 *
2511 * The firmware loading should not take longer than 5 seconds
2512 * and thus just timeout if that happens and fail the setup
2513 * of this device.
2514 */
2515 err = wait_on_bit_timeout(&data->flags, BTUSB_DOWNLOADING,
2516 TASK_INTERRUPTIBLE,
2517 msecs_to_jiffies(5000));
2518 if (err == -EINTR) {
2519 bt_dev_err(hdev, "Firmware loading interrupted");
2520 goto done;
2521 }
2522
2523 if (err) {
2524 bt_dev_err(hdev, "Firmware loading timeout");
2525 err = -ETIMEDOUT;
2526 btintel_reset_to_bootloader(hdev);
2527 goto done;
2528 }
2529
2530 if (test_bit(BTUSB_FIRMWARE_FAILED, &data->flags)) {
2531 bt_dev_err(hdev, "Firmware loading failed");
2532 err = -ENOEXEC;
2533 goto done;
2534 }
2535
2536 done:
2537 release_firmware(fw);
2538 return err;
2539 }
2540 static int btusb_intel_download_firmware(struct hci_dev *hdev,
2541 struct intel_version *ver,
2542 struct intel_boot_params *params,
2543 u32 *boot_param)
2544 {
2545 const struct firmware *fw;
2546 char fwname[64];
2547 int err;
2548 struct btusb_data *data = hci_get_drvdata(hdev);
2549
2550 if (!ver || !params)
2551 return -EINVAL;
2552
2553 /* The hardware platform number has a fixed value of 0x37 and
2554 * for now only accept this single value.
2555 */
2556 if (ver->hw_platform != 0x37) {
2557 bt_dev_err(hdev, "Unsupported Intel hardware platform (%u)",
2558 ver->hw_platform);
2559 return -EINVAL;
2560 }
2561
2562 /* Check for supported iBT hardware variants of this firmware
2563 * loading method.
2564 *
2565 * This check has been put in place to ensure correct forward
2566 * compatibility options when newer hardware variants come along.
2567 */
2568 switch (ver->hw_variant) {
2569 case 0x0b: /* SfP */
2570 case 0x0c: /* WsP */
2571 case 0x11: /* JfP */
2572 case 0x12: /* ThP */
2573 case 0x13: /* HrP */
2574 case 0x14: /* CcP */
2575 break;
2576 default:
2577 bt_dev_err(hdev, "Unsupported Intel hardware variant (%u)",
2578 ver->hw_variant);
2579 return -EINVAL;
2580 }
2581
2582 btintel_version_info(hdev, ver);
2583
2584 /* The firmware variant determines if the device is in bootloader
2585 * mode or is running operational firmware. The value 0x06 identifies
2586 * the bootloader and the value 0x23 identifies the operational
2587 * firmware.
2588 *
2589 * When the operational firmware is already present, then only
2590 * the check for valid Bluetooth device address is needed. This
2591 * determines if the device will be added as configured or
2592 * unconfigured controller.
2593 *
2594 * It is not possible to use the Secure Boot Parameters in this
2595 * case since that command is only available in bootloader mode.
2596 */
2597 if (ver->fw_variant == 0x23) {
2598 clear_bit(BTUSB_BOOTLOADER, &data->flags);
2599 btintel_check_bdaddr(hdev);
2600 return 0;
2601 }
2602
2603 /* If the device is not in bootloader mode, then the only possible
2604 * choice is to return an error and abort the device initialization.
2605 */
2606 if (ver->fw_variant != 0x06) {
2607 bt_dev_err(hdev, "Unsupported Intel firmware variant (%u)",
2608 ver->fw_variant);
2609 return -ENODEV;
2610 }
2611
2612 /* Read the secure boot parameters to identify the operating
2613 * details of the bootloader.
2614 */
2615 err = btintel_read_boot_params(hdev, params);
2616 if (err)
2617 return err;
2618
2619 /* It is required that every single firmware fragment is acknowledged
2620 * with a command complete event. If the boot parameters indicate
2621 * that this bootloader does not send them, then abort the setup.
2622 */
2623 if (params->limited_cce != 0x00) {
2624 bt_dev_err(hdev, "Unsupported Intel firmware loading method (%u)",
2625 params->limited_cce);
2626 return -EINVAL;
2627 }
2628
2629 /* If the OTP has no valid Bluetooth device address, then there will
2630 * also be no valid address for the operational firmware.
2631 */
2632 if (!bacmp(¶ms->otp_bdaddr, BDADDR_ANY)) {
2633 bt_dev_info(hdev, "No device address configured");
2634 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
2635 }
2636
2637 /* With this Intel bootloader only the hardware variant and device
2638 * revision information are used to select the right firmware for SfP
2639 * and WsP.
2640 *
2641 * The firmware filename is ibt-<hw_variant>-<dev_revid>.sfi.
2642 *
2643 * Currently the supported hardware variants are:
2644 * 11 (0x0b) for iBT3.0 (LnP/SfP)
2645 * 12 (0x0c) for iBT3.5 (WsP)
2646 *
2647 * For ThP/JfP and for future SKU's, the FW name varies based on HW
2648 * variant, HW revision and FW revision, as these are dependent on CNVi
2649 * and RF Combination.
2650 *
2651 * 17 (0x11) for iBT3.5 (JfP)
2652 * 18 (0x12) for iBT3.5 (ThP)
2653 *
2654 * The firmware file name for these will be
2655 * ibt-<hw_variant>-<hw_revision>-<fw_revision>.sfi.
2656 *
2657 */
2658 err = btusb_setup_intel_new_get_fw_name(ver, params, fwname,
2659 sizeof(fwname), "sfi");
2660 if (!err) {
2661 bt_dev_err(hdev, "Unsupported Intel firmware naming");
2662 return -EINVAL;
2663 }
2664
2665 err = request_firmware(&fw, fwname, &hdev->dev);
2666 if (err < 0) {
2667 bt_dev_err(hdev, "Failed to load Intel firmware file (%d)", err);
2668 return err;
2669 }
2670
2671 bt_dev_info(hdev, "Found device firmware: %s", fwname);
2672
2673 if (fw->size < 644) {
2674 bt_dev_err(hdev, "Invalid size of firmware file (%zu)",
2675 fw->size);
2676 err = -EBADF;
2677 goto done;
2678 }
2679
2680 set_bit(BTUSB_DOWNLOADING, &data->flags);
2681
2682 /* Start firmware downloading and get boot parameter */
2683 err = btintel_download_firmware(hdev, fw, boot_param);
2684 if (err < 0) {
2685 /* When FW download fails, send Intel Reset to retry
2686 * FW download.
2687 */
2688 btintel_reset_to_bootloader(hdev);
2689 goto done;
2690 }
2691 set_bit(BTUSB_FIRMWARE_LOADED, &data->flags);
2692
2693 bt_dev_info(hdev, "Waiting for firmware download to complete");
2694
2695 /* Before switching the device into operational mode and with that
2696 * booting the loaded firmware, wait for the bootloader notification
2697 * that all fragments have been successfully received.
2698 *
2699 * When the event processing receives the notification, then the
2700 * BTUSB_DOWNLOADING flag will be cleared.
2701 *
2702 * The firmware loading should not take longer than 5 seconds
2703 * and thus just timeout if that happens and fail the setup
2704 * of this device.
2705 */
2706 err = wait_on_bit_timeout(&data->flags, BTUSB_DOWNLOADING,
2707 TASK_INTERRUPTIBLE,
2708 msecs_to_jiffies(5000));
2709 if (err == -EINTR) {
2710 bt_dev_err(hdev, "Firmware loading interrupted");
2711 goto done;
2712 }
2713
2714 if (err) {
2715 bt_dev_err(hdev, "Firmware loading timeout");
2716 err = -ETIMEDOUT;
2717 btintel_reset_to_bootloader(hdev);
2718 goto done;
2719 }
2720
2721 if (test_bit(BTUSB_FIRMWARE_FAILED, &data->flags)) {
2722 bt_dev_err(hdev, "Firmware loading failed");
2723 err = -ENOEXEC;
2724 goto done;
2725 }
2726
2727 done:
2728 release_firmware(fw);
2729 return err;
2730 }
2731
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org