@@ -511,7 +511,6 @@ struct btusb_data {
511
511
unsigned cmd_timeout_cnt ;
512
512
};
513
513
514
-
515
514
static void btusb_intel_cmd_timeout (struct hci_dev * hdev )
516
515
{
517
516
struct btusb_data * data = hci_get_drvdata (hdev );
@@ -2278,46 +2277,25 @@ static bool btusb_setup_intel_new_get_fw_name(struct intel_version *ver,
2278
2277
return true;
2279
2278
}
2280
2279
2281
- static int btusb_setup_intel_new (struct hci_dev * hdev )
2280
+ static int btusb_intel_download_firmware (struct hci_dev * hdev ,
2281
+ struct intel_version * ver ,
2282
+ struct intel_boot_params * params )
2282
2283
{
2283
- struct btusb_data * data = hci_get_drvdata (hdev );
2284
- struct intel_version ver ;
2285
- struct intel_boot_params params ;
2286
- struct intel_debug_features features ;
2287
2284
const struct firmware * fw ;
2288
2285
u32 boot_param ;
2289
2286
char fwname [64 ];
2290
- ktime_t calltime , delta , rettime ;
2291
- unsigned long long duration ;
2292
2287
int err ;
2288
+ struct btusb_data * data = hci_get_drvdata (hdev );
2293
2289
2294
- BT_DBG ("%s" , hdev -> name );
2295
-
2296
- /* Set the default boot parameter to 0x0 and it is updated to
2297
- * SKU specific boot parameter after reading Intel_Write_Boot_Params
2298
- * command while downloading the firmware.
2299
- */
2300
- boot_param = 0x00000000 ;
2301
-
2302
- calltime = ktime_get ();
2303
-
2304
- /* Read the Intel version information to determine if the device
2305
- * is in bootloader mode or if it already has operational firmware
2306
- * loaded.
2307
- */
2308
- err = btintel_read_version (hdev , & ver );
2309
- if (err ) {
2310
- bt_dev_err (hdev , "Intel Read version failed (%d)" , err );
2311
- btintel_reset_to_bootloader (hdev );
2312
- return err ;
2313
- }
2290
+ if (!ver || !params )
2291
+ return - EINVAL ;
2314
2292
2315
2293
/* The hardware platform number has a fixed value of 0x37 and
2316
2294
* for now only accept this single value.
2317
2295
*/
2318
- if (ver . hw_platform != 0x37 ) {
2296
+ if (ver -> hw_platform != 0x37 ) {
2319
2297
bt_dev_err (hdev , "Unsupported Intel hardware platform (%u)" ,
2320
- ver . hw_platform );
2298
+ ver -> hw_platform );
2321
2299
return - EINVAL ;
2322
2300
}
2323
2301
@@ -2327,7 +2305,7 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
2327
2305
* This check has been put in place to ensure correct forward
2328
2306
* compatibility options when newer hardware variants come along.
2329
2307
*/
2330
- switch (ver . hw_variant ) {
2308
+ switch (ver -> hw_variant ) {
2331
2309
case 0x0b : /* SfP */
2332
2310
case 0x0c : /* WsP */
2333
2311
case 0x11 : /* JfP */
@@ -2337,11 +2315,11 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
2337
2315
break ;
2338
2316
default :
2339
2317
bt_dev_err (hdev , "Unsupported Intel hardware variant (%u)" ,
2340
- ver . hw_variant );
2318
+ ver -> hw_variant );
2341
2319
return - EINVAL ;
2342
2320
}
2343
2321
2344
- btintel_version_info (hdev , & ver );
2322
+ btintel_version_info (hdev , ver );
2345
2323
2346
2324
/* The firmware variant determines if the device is in bootloader
2347
2325
* mode or is running operational firmware. The value 0x06 identifies
@@ -2356,42 +2334,42 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
2356
2334
* It is not possible to use the Secure Boot Parameters in this
2357
2335
* case since that command is only available in bootloader mode.
2358
2336
*/
2359
- if (ver . fw_variant == 0x23 ) {
2337
+ if (ver -> fw_variant == 0x23 ) {
2360
2338
clear_bit (BTUSB_BOOTLOADER , & data -> flags );
2361
2339
btintel_check_bdaddr (hdev );
2362
- goto finish ;
2340
+ return 0 ;
2363
2341
}
2364
2342
2365
2343
/* If the device is not in bootloader mode, then the only possible
2366
2344
* choice is to return an error and abort the device initialization.
2367
2345
*/
2368
- if (ver . fw_variant != 0x06 ) {
2346
+ if (ver -> fw_variant != 0x06 ) {
2369
2347
bt_dev_err (hdev , "Unsupported Intel firmware variant (%u)" ,
2370
- ver . fw_variant );
2348
+ ver -> fw_variant );
2371
2349
return - ENODEV ;
2372
2350
}
2373
2351
2374
2352
/* Read the secure boot parameters to identify the operating
2375
2353
* details of the bootloader.
2376
2354
*/
2377
- err = btintel_read_boot_params (hdev , & params );
2355
+ err = btintel_read_boot_params (hdev , params );
2378
2356
if (err )
2379
2357
return err ;
2380
2358
2381
2359
/* It is required that every single firmware fragment is acknowledged
2382
2360
* with a command complete event. If the boot parameters indicate
2383
2361
* that this bootloader does not send them, then abort the setup.
2384
2362
*/
2385
- if (params . limited_cce != 0x00 ) {
2363
+ if (params -> limited_cce != 0x00 ) {
2386
2364
bt_dev_err (hdev , "Unsupported Intel firmware loading method (%u)" ,
2387
- params . limited_cce );
2365
+ params -> limited_cce );
2388
2366
return - EINVAL ;
2389
2367
}
2390
2368
2391
2369
/* If the OTP has no valid Bluetooth device address, then there will
2392
2370
* also be no valid address for the operational firmware.
2393
2371
*/
2394
- if (!bacmp (& params . otp_bdaddr , BDADDR_ANY )) {
2372
+ if (!bacmp (& params -> otp_bdaddr , BDADDR_ANY )) {
2395
2373
bt_dev_info (hdev , "No device address configured" );
2396
2374
set_bit (HCI_QUIRK_INVALID_BDADDR , & hdev -> quirks );
2397
2375
}
@@ -2417,7 +2395,7 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
2417
2395
* ibt-<hw_variant>-<hw_revision>-<fw_revision>.sfi.
2418
2396
*
2419
2397
*/
2420
- err = btusb_setup_intel_new_get_fw_name (& ver , & params , fwname ,
2398
+ err = btusb_setup_intel_new_get_fw_name (ver , params , fwname ,
2421
2399
sizeof (fwname ), "sfi" );
2422
2400
if (!err ) {
2423
2401
bt_dev_err (hdev , "Unsupported Intel firmware naming" );
@@ -2432,16 +2410,6 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
2432
2410
2433
2411
bt_dev_info (hdev , "Found device firmware: %s" , fwname );
2434
2412
2435
- /* Save the DDC file name for later use to apply once the firmware
2436
- * downloading is done.
2437
- */
2438
- err = btusb_setup_intel_new_get_fw_name (& ver , & params , fwname ,
2439
- sizeof (fwname ), "ddc" );
2440
- if (!err ) {
2441
- bt_dev_err (hdev , "Unsupported Intel firmware naming" );
2442
- return - EINVAL ;
2443
- }
2444
-
2445
2413
if (fw -> size < 644 ) {
2446
2414
bt_dev_err (hdev , "Invalid size of firmware file (%zu)" ,
2447
2415
fw -> size );
@@ -2496,18 +2464,58 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
2496
2464
goto done ;
2497
2465
}
2498
2466
2467
+ done :
2468
+ release_firmware (fw );
2469
+ return err ;
2470
+ }
2471
+
2472
+ static int btusb_setup_intel_new (struct hci_dev * hdev )
2473
+ {
2474
+ struct btusb_data * data = hci_get_drvdata (hdev );
2475
+ struct intel_version ver ;
2476
+ struct intel_boot_params params ;
2477
+ u32 boot_param ;
2478
+ char ddcname [64 ];
2479
+ ktime_t calltime , delta , rettime ;
2480
+ unsigned long long duration ;
2481
+ int err ;
2482
+ struct intel_debug_features features ;
2483
+
2484
+ BT_DBG ("%s" , hdev -> name );
2485
+
2486
+ /* Set the default boot parameter to 0x0 and it is updated to
2487
+ * SKU specific boot parameter after reading Intel_Write_Boot_Params
2488
+ * command while downloading the firmware.
2489
+ */
2490
+ boot_param = 0x00000000 ;
2491
+
2492
+ calltime = ktime_get ();
2493
+
2494
+ /* Read the Intel version information to determine if the device
2495
+ * is in bootloader mode or if it already has operational firmware
2496
+ * loaded.
2497
+ */
2498
+ err = btintel_read_version (hdev , & ver );
2499
+ if (err ) {
2500
+ bt_dev_err (hdev , "Intel Read version failed (%d)" , err );
2501
+ btintel_reset_to_bootloader (hdev );
2502
+ return err ;
2503
+ }
2504
+
2505
+ err = btusb_intel_download_firmware (hdev , & ver , & params );
2506
+ if (err )
2507
+ return err ;
2508
+
2509
+ /* controller is already having an operational firmware */
2510
+ if (ver .fw_variant == 0x23 )
2511
+ goto finish ;
2512
+
2499
2513
rettime = ktime_get ();
2500
2514
delta = ktime_sub (rettime , calltime );
2501
2515
duration = (unsigned long long ) ktime_to_ns (delta ) >> 10 ;
2502
2516
2503
2517
bt_dev_info (hdev , "Firmware loaded in %llu usecs" , duration );
2504
2518
2505
- done :
2506
- release_firmware (fw );
2507
-
2508
- if (err < 0 )
2509
- return err ;
2510
-
2511
2519
calltime = ktime_get ();
2512
2520
2513
2521
set_bit (BTUSB_BOOTING , & data -> flags );
@@ -2551,13 +2559,20 @@ static int btusb_setup_intel_new(struct hci_dev *hdev)
2551
2559
2552
2560
clear_bit (BTUSB_BOOTLOADER , & data -> flags );
2553
2561
2554
- /* Once the device is running in operational mode, it needs to apply
2555
- * the device configuration (DDC) parameters.
2556
- *
2557
- * The device can work without DDC parameters, so even if it fails
2558
- * to load the file, no need to fail the setup.
2559
- */
2560
- btintel_load_ddc_config (hdev , fwname );
2562
+ err = btusb_setup_intel_new_get_fw_name (& ver , & params , ddcname ,
2563
+ sizeof (ddcname ), "ddc" );
2564
+
2565
+ if (!err ) {
2566
+ bt_dev_err (hdev , "Unsupported Intel firmware naming" );
2567
+ } else {
2568
+ /* Once the device is running in operational mode, it needs to
2569
+ * apply the device configuration (DDC) parameters.
2570
+ *
2571
+ * The device can work without DDC parameters, so even if it
2572
+ * fails to load the file, no need to fail the setup.
2573
+ */
2574
+ btintel_load_ddc_config (hdev , ddcname );
2575
+ }
2561
2576
2562
2577
/* Read the Intel supported features and if new exception formats
2563
2578
* supported, need to load the additional DDC config to enable.
0 commit comments