diff mbox series

Bluetooth: btusb: Fallback to 16 bit ROM version lookup

Message ID 20210209114024.2910-2-falbrechtskirchinger@gmail.com (mailing list archive)
State New, archived
Headers show
Series Bluetooth: btusb: Fallback to 16 bit ROM version lookup | expand

Commit Message

Florian Albrechtskirchinger Feb. 9, 2021, 11:40 a.m. UTC
Commit b40f58b97386 ("Bluetooth: btusb: Add Qualcomm Bluetooth SoC WCN6855
support") changes ROM version lookup from 16 bit to 32 bit. Previously, the
upper 16 bit of the version number were ignored. This breaks setups, where the
upper 16 bits are non-zero, but are now assumed to be zero.

An example of such a device would be
0cf3:3008 Qualcomm Atheros Communications Bluetooth (AR3011)
with ROM version 0x1020200 and this corresponding entry in the device table:
{ 0x00000200, 28, 4, 16 }, /* Rome 2.0 */

This patch adds a potential second round of lookups that mimics the old
behavior, should no version have been matched by comparing the full 32 bits.
During this second round only the lower 16 bits are compared, but only where
the upper 16 bits are defined zero in the lookup table.

Fixes: b40f58b97386 ("Bluetooth: btusb: Add Qualcomm Bluetooth SoC WCN6855
support")

Signed-off-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
---
 drivers/bluetooth/btusb.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

Comments

Marcel Holtmann Feb. 9, 2021, 1:42 p.m. UTC | #1
Hi Florian,

> Commit b40f58b97386 ("Bluetooth: btusb: Add Qualcomm Bluetooth SoC WCN6855
> support") changes ROM version lookup from 16 bit to 32 bit. Previously, the
> upper 16 bit of the version number were ignored. This breaks setups, where the
> upper 16 bits are non-zero, but are now assumed to be zero.
> 
> An example of such a device would be
> 0cf3:3008 Qualcomm Atheros Communications Bluetooth (AR3011)
> with ROM version 0x1020200 and this corresponding entry in the device table:
> { 0x00000200, 28, 4, 16 }, /* Rome 2.0 */
> 
> This patch adds a potential second round of lookups that mimics the old
> behavior, should no version have been matched by comparing the full 32 bits.
> During this second round only the lower 16 bits are compared, but only where
> the upper 16 bits are defined zero in the lookup table.
> 
> Fixes: b40f58b97386 ("Bluetooth: btusb: Add Qualcomm Bluetooth SoC WCN6855
> support")
> 
> Signed-off-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
> ---
> drivers/bluetooth/btusb.c | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> index 03b83aa91277..d8c4c6474f14 100644
> --- a/drivers/bluetooth/btusb.c
> +++ b/drivers/bluetooth/btusb.c
> @@ -4054,6 +4054,7 @@ static int btusb_setup_qca(struct hci_dev *hdev)
> 	const struct qca_device_info *info = NULL;
> 	struct qca_version ver;
> 	u32 ver_rom;
> +	u16 ver_rom_low;
> 	u8 status;
> 	int i, err;
> 
> @@ -4065,8 +4066,22 @@ static int btusb_setup_qca(struct hci_dev *hdev)
> 	ver_rom = le32_to_cpu(ver.rom_version);
> 
> 	for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) {
> -		if (ver_rom == qca_devices_table[i].rom_version)
> +		if (ver_rom == qca_devices_table[i].rom_version) {
> 			info = &qca_devices_table[i];
> +			break;
> +		}
> +	}
> +	if (!info) {
> +		// If we don't find an exact version match, try with
> +		// the lower half, but only where the upper half is 0

please use correct comment style.

> +		ver_rom_low = ver_rom & 0xffff;
> +		for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) {
> +			if (!(qca_devices_table[i].rom_version & 0xffff0000) &&
> +			    ver_rom_low == qca_devices_table[i].rom_version) {
> +				info = &qca_devices_table[i];
> +				break;
> +			}
> +		}
> 	}
> 	if (!info) {
> 		bt_dev_err(hdev, "don't support firmware rome 0x%x", ver_rom);

Regards

Marcel
Florian Albrechtskirchinger Feb. 10, 2021, 10:37 a.m. UTC | #2
On Tue, Feb 9, 2021 at 2:42 PM Marcel Holtmann <marcel@holtmann.org> wrote:
>
> Hi Florian,
>
> > Commit b40f58b97386 ("Bluetooth: btusb: Add Qualcomm Bluetooth SoC WCN6855
> > support") changes ROM version lookup from 16 bit to 32 bit. Previously, the
> > upper 16 bit of the version number were ignored. This breaks setups, where the
> > upper 16 bits are non-zero, but are now assumed to be zero.
> >
> > An example of such a device would be
> > 0cf3:3008 Qualcomm Atheros Communications Bluetooth (AR3011)
> > with ROM version 0x1020200 and this corresponding entry in the device table:
> > { 0x00000200, 28, 4, 16 }, /* Rome 2.0 */
> >
> > This patch adds a potential second round of lookups that mimics the old
> > behavior, should no version have been matched by comparing the full 32 bits.
> > During this second round only the lower 16 bits are compared, but only where
> > the upper 16 bits are defined zero in the lookup table.
> >
> > Fixes: b40f58b97386 ("Bluetooth: btusb: Add Qualcomm Bluetooth SoC WCN6855
> > support")
> >
> > Signed-off-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
> > ---
> > drivers/bluetooth/btusb.c | 17 ++++++++++++++++-
> > 1 file changed, 16 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> > index 03b83aa91277..d8c4c6474f14 100644
> > --- a/drivers/bluetooth/btusb.c
> > +++ b/drivers/bluetooth/btusb.c
> > @@ -4054,6 +4054,7 @@ static int btusb_setup_qca(struct hci_dev *hdev)
> >       const struct qca_device_info *info = NULL;
> >       struct qca_version ver;
> >       u32 ver_rom;
> > +     u16 ver_rom_low;
> >       u8 status;
> >       int i, err;
> >
> > @@ -4065,8 +4066,22 @@ static int btusb_setup_qca(struct hci_dev *hdev)
> >       ver_rom = le32_to_cpu(ver.rom_version);
> >
> >       for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) {
> > -             if (ver_rom == qca_devices_table[i].rom_version)
> > +             if (ver_rom == qca_devices_table[i].rom_version) {
> >                       info = &qca_devices_table[i];
> > +                     break;
> > +             }
> > +     }
> > +     if (!info) {
> > +             // If we don't find an exact version match, try with
> > +             // the lower half, but only where the upper half is 0
>
> please use correct comment style.
Noted for next time. I would've expected checkpatch.pl to catch issues
like that?
A proper fix by Hui Wang has already been committed to bluetooth-next.

> > +             ver_rom_low = ver_rom & 0xffff;
> > +             for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) {
> > +                     if (!(qca_devices_table[i].rom_version & 0xffff0000) &&
> > +                         ver_rom_low == qca_devices_table[i].rom_version) {
> > +                             info = &qca_devices_table[i];
> > +                             break;
> > +                     }
> > +             }
> >       }
> >       if (!info) {
> >               bt_dev_err(hdev, "don't support firmware rome 0x%x", ver_rom);
>
> Regards
>
> Marcel

- Florian
diff mbox series

Patch

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index 03b83aa91277..d8c4c6474f14 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -4054,6 +4054,7 @@  static int btusb_setup_qca(struct hci_dev *hdev)
 	const struct qca_device_info *info = NULL;
 	struct qca_version ver;
 	u32 ver_rom;
+	u16 ver_rom_low;
 	u8 status;
 	int i, err;
 
@@ -4065,8 +4066,22 @@  static int btusb_setup_qca(struct hci_dev *hdev)
 	ver_rom = le32_to_cpu(ver.rom_version);
 
 	for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) {
-		if (ver_rom == qca_devices_table[i].rom_version)
+		if (ver_rom == qca_devices_table[i].rom_version) {
 			info = &qca_devices_table[i];
+			break;
+		}
+	}
+	if (!info) {
+		// If we don't find an exact version match, try with
+		// the lower half, but only where the upper half is 0
+		ver_rom_low = ver_rom & 0xffff;
+		for (i = 0; i < ARRAY_SIZE(qca_devices_table); i++) {
+			if (!(qca_devices_table[i].rom_version & 0xffff0000) &&
+			    ver_rom_low == qca_devices_table[i].rom_version) {
+				info = &qca_devices_table[i];
+				break;
+			}
+		}
 	}
 	if (!info) {
 		bt_dev_err(hdev, "don't support firmware rome 0x%x", ver_rom);