Bluetooth: Set the firmware file extension based on firmware type
RFC v2 2/4 Bluetooth: Set the firmware file extension based on firmware type
From: Tedd Ho-Jeong An <[email protected]>
This patch sets the extension of Intel Bluetooth firmware file based on firmware type.
--- drivers/bluetooth/btusb.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-)
drivers/bluetooth/btusb.c +29 -14
@@ -1334,12 +1334,18 @@ struct intel_version {u8 fw_patch_num; } __packed; -static const struct firmware *btusb_setup_intel_get_fw (struct hci_dev *hdev) +enum { +INTEL_FW_MODE_OP , +}; + +static const struct firmware *btusb_setup_intel_get_fw (struct hci_dev *hdev, +int fw_mode) {const struct firmware *fw;struct sk_buff *skb;struct intel_version *ver;char fwname[64 ]; +char ext[6 ] = {0 };int ret;BT_DBG ("%s" , hdev->name);
@@ -1377,23 +1383,32 @@ static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev) ver->fw_build_num, ver->fw_build_ww, ver->fw_build_yy, ver->fw_patch_num); -/* fw_patch_num indicates the version of patch the device currently -* have. If there is no patch data in the device, it is always 0x00. -* So, if it is other than 0x00, no need to patch the device again. -*/ -if (ver->fw_patch_num) { -BT_INFO ("%s: Intel device is already patched. patch num: %02x" , - hdev->name, ver->fw_patch_num); -btusb_check_bdaddr_intel (hdev); +/* set the extension of firmware file based on firmware type */ +if (fw_mode ==INTEL_FW_MODE_OP ) { +/* fw_patch_num indicates the version of patch the device +* currently have. If there is no patch data in the device, +* it is always 0x00. So, if it is other than 0x00, no need +* to patch the device again. +*/ +if (ver->fw_patch_num) { +BT_INFO ("%s: Intel device is already patched" , + hdev->name); +btusb_check_bdaddr_intel (hdev); +return NULL ; + } +strncpy (ext,"bseq" ,4 ); + }else { +BT_ERR ("%s: Invalid Intel firmware type: %d" , + hdev->name, fw_mode);return NULL ; }/* Open the firwmare file if it exists */ snprintf (fwname,sizeof (fwname), -"intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.bseq" , +"intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.%s" , ver->hw_platform, ver->hw_variant, ver->hw_revision, ver->fw_variant, ver->fw_revision, ver->fw_build_num, - ver->fw_build_ww, ver->fw_build_yy); + ver->fw_build_ww, ver->fw_build_yy, ext); ret =request_firmware (&fw, fwname, &hdev->dev);if (ret <0 ) {
@@ -1409,8 +1424,8 @@ static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev)/* If the correct firmware patch file is not found, use the * default firmware patch file instead */ -snprintf (fwname,sizeof (fwname),"intel/ibt-hw-%x.%x.bseq" , - ver->hw_platform, ver->hw_variant); +snprintf (fwname,sizeof (fwname),"intel/ibt-hw-%x.%x.%s" , + ver->hw_platform, ver->hw_variant, ext);if (request_firmware (&fw, fwname, &hdev->dev) <0 ) {BT_ERR ("%s failed to open default Intel fw file: %s" , hdev->name, fwname);
@@ -1574,7 +1589,7 @@ static int btusb_setup_intel(struct hci_dev *hdev)* If no patch file is found, allow the device to operate without * a patch. */ - fw =btusb_setup_intel_get_fw (hdev); + fw =btusb_setup_intel_get_fw (hdev,INTEL_FW_MODE_OP );if (!fw) {btusb_check_bdaddr_intel (hdev);return 0 ;
Signature · 1 line
1.9.1
Marcel Holtmann
maintainerHi Tedd,
Quoted 13 lines
This patch sets the extension of Intel Bluetooth firmware file based on firmware type.
Signed-off-by Tedd Ho-Jeong An <[email protected]>---
drivers/bluetooth/btusb.c| 43 +++++++++++++++++++++++++++++--------------1 file changed, 29 insertions(+), 14 deletions(-)drivers/bluetooth/btusb.c +0
-0
drivers/bluetooth/btusb.c struct intel_version { · line 1339
Quoted 7 lines
drivers/bluetooth/btusb.c +3
-1@@ -1334,12 +1334,18 @@ struct intel_version {u8 fw_patch_num; } __packed; -static const struct firmware *btusb_setup_intel_get_fw (struct hci_dev *hdev) +enum { +INTEL_FW_MODE_OP , +};
lets name this enum.
drivers/bluetooth/btusb.c struct intel_version { · line 1342
Quoted 3 lines
drivers/bluetooth/btusb.c +3
-0+ +static const struct firmware *btusb_setup_intel_get_fw (struct hci_dev *hdev, +int fw_mode)
And then use the enum here instead of just int.
drivers/bluetooth/btusb.c struct intel_version { · line 1348
Quoted 6 lines
drivers/bluetooth/btusb.c +1
-0{const struct firmware *fw;struct sk_buff *skb;struct intel_version *ver;char fwname[64 ]; +char ext[6 ] = {0 };
Do not initialize this one. And actually make it const char *ext. Actually naming it file_ext might make the code a lot easier to read and get what this is for.
Quoted 16 lines
drivers/bluetooth/btusb.c +1
-8int ret;BT_DBG ("%s" , hdev->name);@@ -1377,23 +1383,32 @@ static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev) ver->fw_build_num, ver->fw_build_ww, ver->fw_build_yy, ver->fw_patch_num); -/* fw_patch_num indicates the version of patch the device currently -* have. If there is no patch data in the device, it is always 0x00. -* So, if it is other than 0x00, no need to patch the device again. -*/ -if (ver->fw_patch_num) { -BT_INFO ("%s: Intel device is already patched. patch num: %02x" , - hdev->name, ver->fw_patch_num); -btusb_check_bdaddr_intel (hdev); +/* set the extension of firmware file based on firmware type */
drivers/bluetooth/btusb.c static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev) · line 1396
Quoted 10 lines
drivers/bluetooth/btusb.c +10
-0+if (fw_mode ==INTEL_FW_MODE_OP ) { +/* fw_patch_num indicates the version of patch the device +* currently have. If there is no patch data in the device, +* it is always 0x00. So, if it is other than 0x00, no need +* to patch the device again. +*/ +if (ver->fw_patch_num) { +BT_INFO ("%s: Intel device is already patched" , + hdev->name); +btusb_check_bdaddr_intel (hdev);
As in the previous patch, this btusb_check_bdaddr_intel is not needed. It would cause double execution actually.
drivers/bluetooth/btusb.c static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev) · line 1399
Quoted 3 lines
drivers/bluetooth/btusb.c +3
-0+return NULL ; + } +strncpy (ext,"bseq" ,4 );
Using ext = "bseq"; works just fine if this is a const pointer. It is all in the same function and thus does not need extra variable space to copy things into.
drivers/bluetooth/btusb.c static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev) · line 1404
Quoted 5 lines
drivers/bluetooth/btusb.c +3
-0+ }else { +BT_ERR ("%s: Invalid Intel firmware type: %d" , + hdev->name, fw_mode);return NULL ; }
Since we know that it will be an enum, lets use a switch statement here.
Quoted 24 lines
drivers/bluetooth/btusb.c +4
-4/* Open the firwmare file if it exists */ snprintf (fwname,sizeof (fwname), -"intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.bseq" , +"intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.%s" , ver->hw_platform, ver->hw_variant, ver->hw_revision, ver->fw_variant, ver->fw_revision, ver->fw_build_num, - ver->fw_build_ww, ver->fw_build_yy); + ver->fw_build_ww, ver->fw_build_yy, ext); ret =request_firmware (&fw, fwname, &hdev->dev);if (ret <0 ) {@@ -1409,8 +1424,8 @@ static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev)/* If the correct firmware patch file is not found, use the * default firmware patch file instead */ -snprintf (fwname,sizeof (fwname),"intel/ibt-hw-%x.%x.bseq" , - ver->hw_platform, ver->hw_variant); +snprintf (fwname,sizeof (fwname),"intel/ibt-hw-%x.%x.%s" , + ver->hw_platform, ver->hw_variant, ext);if (request_firmware (&fw, fwname, &hdev->dev) <0 ) {BT_ERR ("%s failed to open default Intel fw file: %s" , hdev->name, fwname);
drivers/bluetooth/btusb.c static int btusb_setup_intel(struct hci_dev *hdev) · line 1595
Quoted 8 lines
drivers/bluetooth/btusb.c +1
-1@@ -1574,7 +1589,7 @@ static int btusb_setup_intel(struct hci_dev *hdev)* If no patch file is found, allow the device to operate without * a patch. */ - fw =btusb_setup_intel_get_fw (hdev); + fw =btusb_setup_intel_get_fw (hdev,INTEL_FW_MODE_OP );if (!fw) {btusb_check_bdaddr_intel (hdev);return 0 ;
Regards
Marcel
Hi Marcel,
Quoted 76 lines · Marcel Holtmann
Hi Tedd,
Quoted 19 lines
This patch sets the extension of Intel Bluetooth firmware file based on firmware type.
=20Signed-off-by Tedd Ho-Jeong An <[email protected]>---
drivers/bluetooth/btusb.c| 43
+++++++++++++++++++++++++++++--------------1 file changed, 29 insertions(+), 14 deletions(-)=20
drivers/bluetooth/btusb.c +0
-0@@ -1334,12 +1334,18 @@ struct intel_version {u8 fw_patch_num; } __packed;=20
-static const struct firmware *btusb_setup_intel_get_fw(structhci_dev*hdev)drivers/bluetooth/btusb.c struct intel_version { · line 1339
Quoted 3 lines
drivers/bluetooth/btusb.c +3
-0+enum { +INTEL_FW_MODE_OP , +};lets name this enum.
drivers/bluetooth/btusb.c struct intel_version { · line 1342
Quoted 4 lines
drivers/bluetooth/btusb.c +2
-0+ +static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev*hdev,
drivers/bluetooth/btusb.c +1
-0+ int fw_mode)And then use the enum here instead of just int.
drivers/bluetooth/btusb.c
Quoted 6 lines
{ const struct firmware *fw; struct sk_buff *skb; struct intel_version *ver; char fwname[64];drivers/bluetooth/btusb.c +1
-0+ char ext[6] =3D {0};Do not initialize this one. And actually make it const char *ext. Actually naming it
file_extmight make the code a lot easier to read and get what this is for.Quoted 17 lines
int ret; =20 BT_DBG("%s", hdev->name);drivers/bluetooth/btusb.c +0
-0@@ -1377,23 +1383,32 @@ static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev) ver->fw_build_num, ver->fw_build_ww, ver->fw_build_yy, ver->fw_patch_num);=20
drivers/bluetooth/btusb.c +1
-8-/* fw_patch_num indicates the version of patch the device currently -* have. If there is no patch data in the device, it is always 0x00. -* So, if it is other than 0x00, no need to patch the device again. -*/ -if (ver->fw_patch_num) { -BT_INFO ("%s: Intel device is already patched. patch num: %02x" , - hdev->name, ver->fw_patch_num); -btusb_check_bdaddr_intel (hdev); +/* set the extension of firmware file based on firmware type */ drivers/bluetooth/btusb.c static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev) · line 1396
Quoted 10 lines
drivers/bluetooth/btusb.c +10
-0+ if (fw_mode =3D=3D INTEL_FW_MODE_OP) { +/* fw_patch_num indicates the version of patch the device +* currently have. If there is no patch data in the device, +* it is always 0x00. So, if it is other than 0x00, no need +* to patch the device again. +*/ +if (ver->fw_patch_num) { +BT_INFO ("%s: Intel device is already patched" , + hdev->name); +btusb_check_bdaddr_intel (hdev);As in the previous patch, this
btusb_check_bdaddr_intelis not needed. It would cause double execution actually.
Quoted 5 lines
drivers/bluetooth/btusb.c static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev) · line 1399
Quoted 3 lines
drivers/bluetooth/btusb.c +3
-0+return NULL ; + } +strncpy (ext,"bseq" ,4 );Using ext =3D "bseq"; works just fine if this is a const pointer. It is al=
l
Quoted 47 lines
in the same function and thus does not need extra variable space to copy things into.
Quoted 5 lines
drivers/bluetooth/btusb.c +3
-0+ }else { +BT_ERR ("%s: Invalid Intel firmware type: %d" , + hdev->name, fw_mode);return NULL; }Since we know that it will be an enum, lets use a switch statement here.
Quoted 25 lines
=20
/* Open the firwmare file if it exists */ snprintf(fwname, sizeof(fwname),drivers/bluetooth/btusb.c +1
-1- "intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.bseq", + "intel/ibt-hw-%x.%x.%x-fw-%x.%x.%x.%x.%x.%s",ver->hw_platform, ver->hw_variant, ver->hw_revision, ver->fw_variant, ver->fw_revision, ver->fw_build_num,drivers/bluetooth/btusb.c +1
-1- ver->fw_build_ww, ver->fw_build_yy); + ver->fw_build_ww, ver->fw_build_yy, ext);=20
ret =3D request_firmware(&fw, fwname, &hdev->dev); if (ret < 0) {drivers/bluetooth/btusb.c +2
-2@@ -1409,8 +1424,8 @@ static const struct firmware *btusb_setup_intel_get_fw(struct hci_dev *hdev)/* If the correct firmware patch file is not found, use the * default firmware patch file instead */ -snprintf (fwname,sizeof (fwname),"intel/ibt-hw-%x.%x.bseq" , - ver->hw_platform, ver->hw_variant); +snprintf (fwname,sizeof (fwname),"intel/ibt-hw-%x.%x.%s" , + ver->hw_platform, ver->hw_variant, ext);if (request_firmware (&fw, fwname, &hdev->dev) <0 ) { BT_ERR("%s failed to open default Intel fw file: %s",hdev->name, fwname);drivers/bluetooth/btusb.c static int btusb_setup_intel(struct hci_dev *hdev) · line 1595
Quoted 8 lines
drivers/bluetooth/btusb.c +1
-1@@ -1574,7 +1589,7 @@ static int btusb_setup_intel(struct hci_dev *hdev)* If no patch file is found, allow the device to operate without * a patch. */ - fw =3D btusb_setup_intel_get_fw(hdev); + fw =3D btusb_setup_intel_get_fw(hdev, INTEL_FW_MODE_OP);if (!fw) {btusb_check_bdaddr_intel (hdev);return 0 ;Regards
Quoted 2 lines
Marcel
I updated my patch and will send out v3.
Regards,
Tedd