Re: [PATCH v2 1/2] Bluetooth: btintel: Add helper function to download firmware

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
Reported-by: kernel test robot <lkp@xxxxxxxxx>

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(&params->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@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux