Skip to contentSkip to conversation

Bluetooth: Use NVM files based on SoC ID for WCN3991

PATCH Superseded Venkata Lakshmi Narayana Gubba 3 participants 5 messages Sep 15, 2020 – Nov 19, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bluetooth: Use NVM files based on SoC ID for WCN3991

This change will allow to use different NVM file based on WCN3991 BT SoC ID.Need to use different NVM file based on fab location for WCN3991 BT SoC.

---
 drivers/bluetooth/btqca.c   | 41 +++++++++++++++++++++++++----------------
 drivers/bluetooth/btqca.h   | 13 ++++++++-----
 drivers/bluetooth/hci_qca.c | 11 +++++------
 3 files changed, 38 insertions(+), 27 deletions(-)
drivers/bluetooth/btqca.c +25 -16
index ce9dcff..a7e72f1 100644
@@ -14,12 +14,11 @@
 
 #define VERSION "0.1"
 
-int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
+int qca_read_soc_version(struct hci_dev *hdev, struct qca_btsoc_version *ver,
 			 enum qca_btsoc_type soc_type)
 {
 	struct sk_buff *skb;
 	struct edl_event_hdr *edl;
-	struct qca_btsoc_version *ver;
 	char cmd;
 	int err = 0;
 	u8 event_type = HCI_EV_VENDOR;
@@ -70,9 +69,9 @@ int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
 	}
 
 	if (soc_type >= QCA_WCN3991)
-		memmove(&edl->data, &edl->data[1], sizeof(*ver));
-
-	ver = (struct qca_btsoc_version *)(edl->data);
+		memcpy(ver, &edl->data[1], sizeof(*ver));
+	else
+		memcpy(ver, &edl->data, sizeof(*ver));
 
 	bt_dev_info(hdev, "QCA Product ID   :0x%08x",
 		    le32_to_cpu(ver->product_id));
@@ -83,13 +82,7 @@ int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
 	bt_dev_info(hdev, "QCA Patch Version:0x%08x",
 		    le16_to_cpu(ver->patch_ver));
 
-	/* QCA chipset version can be decided by patch and SoC
-	 * version, combination with upper 2 bytes from SoC
-	 * and lower 2 bytes from patch will be used.
-	 */
-	*soc_version = (le32_to_cpu(ver->soc_id) << 16) |
-		       (le16_to_cpu(ver->rom_ver) & 0x0000ffff);
-	if (*soc_version == 0)
+	if (le32_to_cpu(ver->soc_id) == 0 || le16_to_cpu(ver->rom_ver) == 0)
 		err = -EILSEQ;
 
 out:
@@ -446,15 +439,25 @@ int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr)
 EXPORT_SYMBOL_GPL(qca_set_bdaddr_rome);
 
 int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
-		   enum qca_btsoc_type soc_type, u32 soc_ver,
+		   enum qca_btsoc_type soc_type, struct qca_btsoc_version ver,
 		   const char *firmware_name)
 {
 	struct qca_fw_config config;
 	int err;
 	u8 rom_ver = 0;
+	u32 soc_ver;
 
 	bt_dev_dbg(hdev, "QCA setup on UART");
 
+	/* QCA chipset version can be decided by patch and SoC
+	 * version, combination with upper 2 bytes from SoC
+	 * and lower 2 bytes from patch will be used.
+	 */
+	soc_ver = (le32_to_cpu(ver.soc_id) << 16) |
+		       (le16_to_cpu(ver.rom_ver) & 0x0000ffff);
+
+	bt_dev_info(hdev, "QCA controller version 0x%08x", soc_ver);
+
 	config.user_baud_rate = baudrate;
 
 	/* Download rampatch file */
@@ -491,9 +494,15 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
 	if (firmware_name)
 		snprintf(config.fwname, sizeof(config.fwname),
 			 "qca/%s", firmware_name);
-	else if (qca_is_wcn399x(soc_type))
-		snprintf(config.fwname, sizeof(config.fwname),
-			 "qca/crnv%02x.bin", rom_ver);
+	else if (qca_is_wcn399x(soc_type)) {
+		if (ver.soc_id == QCA_WCN3991_SOC_ID) {
+			snprintf(config.fwname, sizeof(config.fwname),
+				 "qca/crnv%02xu.bin", rom_ver);
+		} else {
+			snprintf(config.fwname, sizeof(config.fwname),
+				 "qca/crnv%02x.bin", rom_ver);
+		}
+	}
 	else if (soc_type == QCA_QCA6390)
 		snprintf(config.fwname, sizeof(config.fwname),
 			 "qca/htnv%02x.bin", rom_ver);
drivers/bluetooth/btqca.h +8 -5
index d81b74c..d01a9f5 100644
@@ -34,6 +34,8 @@
 #define QCA_HCI_CC_OPCODE		0xFC00
 #define QCA_HCI_CC_SUCCESS		0x00
 
+#define QCA_WCN3991_SOC_ID		(0x40014320)
+
 enum qca_baudrate {
 	QCA_BAUDRATE_115200 	= 0,
 	QCA_BAUDRATE_57600,
@@ -136,9 +138,9 @@ enum qca_btsoc_type {
 
 int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr);
 int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
-		   enum qca_btsoc_type soc_type, u32 soc_ver,
+		   enum qca_btsoc_type soc_type, struct qca_btsoc_version ver,
 		   const char *firmware_name);
-int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
+int qca_read_soc_version(struct hci_dev *hdev, struct qca_btsoc_version *ver,
 			 enum qca_btsoc_type);
 int qca_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr);
 int qca_send_pre_shutdown_cmd(struct hci_dev *hdev);
@@ -155,13 +157,14 @@ static inline int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdad
 }
 
 static inline int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
-				 enum qca_btsoc_type soc_type, u32 soc_ver,
-				 const char *firmware_name)
+		enum qca_btsoc_type soc_type, struct qca_btsoc_version ver,
+				const char *firmware_name)
 {
 	return -EOPNOTSUPP;
 }
 
-static inline int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
+static inline int qca_read_soc_version(struct hci_dev *hdev,
+				       struct qca_btsoc_version *ver,
 				       enum qca_btsoc_type)
 {
 	return -EOPNOTSUPP;
drivers/bluetooth/hci_qca.c +5 -6
index 244b8fe..4c32c60 100644
@@ -1649,7 +1649,7 @@ static int qca_setup(struct hci_uart *hu)
 	enum qca_btsoc_type soc_type = qca_soc_type(hu);
 	const char *firmware_name = qca_get_firmware_name(hu);
 	int ret;
-	int soc_ver = 0;
+	struct qca_btsoc_version ver;
 
 	ret = qca_check_speeds(hu);
 	if (ret)
@@ -1678,7 +1678,7 @@ static int qca_setup(struct hci_uart *hu)
 	if (qca_is_wcn399x(soc_type)) {
 		set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks);
 
-		ret = qca_read_soc_version(hdev, &soc_ver, soc_type);
+		ret = qca_read_soc_version(hdev, &ver, soc_type);
 		if (ret)
 			return ret;
 	} else {
@@ -1697,15 +1697,14 @@ static int qca_setup(struct hci_uart *hu)
 
 	if (!qca_is_wcn399x(soc_type)) {
 		/* Get QCA version information */
-		ret = qca_read_soc_version(hdev, &soc_ver, soc_type);
+		ret = qca_read_soc_version(hdev, &ver, soc_type);
 		if (ret)
 			return ret;
 	}
 
-	bt_dev_info(hdev, "QCA controller version 0x%08x", soc_ver);
 	/* Setup patch / NVM configurations */
-	ret = qca_uart_setup(hdev, qca_baudrate, soc_type, soc_ver,
-			firmware_name);
+	ret = qca_uart_setup(hdev, qca_baudrate, soc_type, ver,
+			     firmware_name);
 	if (!ret) {
 		set_bit(QCA_IBS_ENABLED, &qca->flags);
 		qca_debugfs_init(hdev);
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member 
of Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw

Hi Venkata,

I agree with Marcel that the version magic is confusing ...

Quoted 69 lines · Venkata Lakshmi Narayana Gubba

This change will allow to use different NVM file based on WCN3991 BT SoC ID.Need to use different NVM file based on fab location for WCN3991 BT SoC.

---
 drivers/bluetooth/btqca.c   | 41 +++++++++++++++++++++++++----------------
 drivers/bluetooth/btqca.h   | 13 ++++++++-----
 drivers/bluetooth/hci_qca.c | 11 +++++------
 3 files changed, 38 insertions(+), 27 deletions(-)
drivers/bluetooth/btqca.c +7 -13
index ce9dcff..a7e72f1 100644
@@ -14,12 +14,11 @@
 
 #define VERSION "0.1"
 
-int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
+int qca_read_soc_version(struct hci_dev *hdev, struct qca_btsoc_version *ver,
 			 enum qca_btsoc_type soc_type)
 {
 	struct sk_buff *skb;
 	struct edl_event_hdr *edl;
-	struct qca_btsoc_version *ver;
 	char cmd;
 	int err = 0;
 	u8 event_type = HCI_EV_VENDOR;
@@ -70,9 +69,9 @@ int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
 	}
 
 	if (soc_type >= QCA_WCN3991)
-		memmove(&edl->data, &edl->data[1], sizeof(*ver));
-
-	ver = (struct qca_btsoc_version *)(edl->data);
+		memcpy(ver, &edl->data[1], sizeof(*ver));
+	else
+		memcpy(ver, &edl->data, sizeof(*ver));
 
 	bt_dev_info(hdev, "QCA Product ID   :0x%08x",
 		    le32_to_cpu(ver->product_id));
@@ -83,13 +82,7 @@ int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
 	bt_dev_info(hdev, "QCA Patch Version:0x%08x",
 		    le16_to_cpu(ver->patch_ver));
 
-	/* QCA chipset version can be decided by patch and SoC
-	 * version, combination with upper 2 bytes from SoC
-	 * and lower 2 bytes from patch will be used.
-	 */
-	*soc_version = (le32_to_cpu(ver->soc_id) << 16) |
-		       (le16_to_cpu(ver->rom_ver) & 0x0000ffff);
-	if (*soc_version == 0)
+	if (le32_to_cpu(ver->soc_id) == 0 || le16_to_cpu(ver->rom_ver) == 0)
 		err = -EILSEQ;
 
 out:
@@ -446,15 +439,25 @@ int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr)
 EXPORT_SYMBOL_GPL(qca_set_bdaddr_rome);
 
 int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
-		   enum qca_btsoc_type soc_type, u32 soc_ver,
+		   enum qca_btsoc_type soc_type, struct qca_btsoc_version ver,
 		   const char *firmware_name)
 {
 	struct qca_fw_config config;
 	int err;
 	u8 rom_ver = 0;
+	u32 soc_ver;

drivers/bluetooth/btqca.c int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr) · line 458

Quoted 10 lines
drivers/bluetooth/btqca.c +7 -0
 
 	bt_dev_dbg(hdev, "QCA setup on UART");
 
+	/* QCA chipset version can be decided by patch and SoC
+	 * version, combination with upper 2 bytes from SoC
+	 * and lower 2 bytes from patch will be used.
+	 */
+	soc_ver = (le32_to_cpu(ver.soc_id) << 16) |
+		       (le16_to_cpu(ver.rom_ver) & 0x0000ffff);
+

Can we at least do the leN_to_cpu conversions in qca_read_soc_version() as previously to make this less clunky?

And/or define a macro to extract 'soc_ver' to unclunkify this further.

Quoted 29 lines
drivers/bluetooth/btqca.c +11 -3
+	bt_dev_info(hdev, "QCA controller version 0x%08x", soc_ver);
+
 	config.user_baud_rate = baudrate;
 
 	/* Download rampatch file */
@@ -491,9 +494,15 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
 	if (firmware_name)
 		snprintf(config.fwname, sizeof(config.fwname),
 			 "qca/%s", firmware_name);
-	else if (qca_is_wcn399x(soc_type))
-		snprintf(config.fwname, sizeof(config.fwname),
-			 "qca/crnv%02x.bin", rom_ver);
+	else if (qca_is_wcn399x(soc_type)) {
+		if (ver.soc_id == QCA_WCN3991_SOC_ID) {
+			snprintf(config.fwname, sizeof(config.fwname),
+				 "qca/crnv%02xu.bin", rom_ver);
+		} else {
+			snprintf(config.fwname, sizeof(config.fwname),
+				 "qca/crnv%02x.bin", rom_ver);
+		}
+	}
 	else if (soc_type == QCA_QCA6390)
 		snprintf(config.fwname, sizeof(config.fwname),
 			 "qca/htnv%02x.bin", rom_ver);
drivers/bluetooth/btqca.h +0 -0
index d81b74c..d01a9f5 100644

drivers/bluetooth/btqca.h line 37

Quoted 4 lines
drivers/bluetooth/btqca.h +1 -0
@@ -34,6 +34,8 @@
 #define QCA_HCI_CC_OPCODE		0xFC00
 #define QCA_HCI_CC_SUCCESS		0x00
 
+#define QCA_WCN3991_SOC_ID		(0x40014320)

The QCA_ prefix seems a bit verbose, given that this is a QCA driver and WCN3991 uniquely identifies the chip. Having the prefix just needlessly clutters conditions, I suggest to just call it SOC_ID_WCN3991.

#2 lore raw

Hi Matthias,

Quoted 93 lines · Matthias Kaehlcke

Hi Venkata,

I agree with Marcel that the version magic is confusing ...

Quoted 74 lines · Venkata Lakshmi Narayana Gubba

This change will allow to use different NVM file based on WCN3991 BT SoC ID.Need to use different NVM file based on fab location for WCN3991 BT SoC.

---
 drivers/bluetooth/btqca.c   | 41 
+++++++++++++++++++++++++----------------
 drivers/bluetooth/btqca.h   | 13 ++++++++-----
 drivers/bluetooth/hci_qca.c | 11 +++++------
 3 files changed, 38 insertions(+), 27 deletions(-)
drivers/bluetooth/btqca.c +1 -2
index ce9dcff..a7e72f1 100644
@@ -14,12 +14,11 @@
 
 #define VERSION "0.1"
 
-int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
+int qca_read_soc_version(struct hci_dev *hdev, struct 
 qca_btsoc_version *ver,
 			 enum qca_btsoc_type soc_type)
 {
 	struct sk_buff *skb;
 	struct edl_event_hdr *edl;
-	struct qca_btsoc_version *ver;
 	char cmd;
 	int err = 0;
drivers/bluetooth/btqca.c +3 -3
 	u8 event_type = HCI_EV_VENDOR;
@@ -70,9 +69,9 @@ int qca_read_soc_version(struct hci_dev *hdev, u32 
 *soc_version,
 	}
 
 	if (soc_type >= QCA_WCN3991)
-		memmove(&edl->data, &edl->data[1], sizeof(*ver));
-
-	ver = (struct qca_btsoc_version *)(edl->data);
+		memcpy(ver, &edl->data[1], sizeof(*ver));
+	else
+		memcpy(ver, &edl->data, sizeof(*ver));
 
 	bt_dev_info(hdev, "QCA Product ID   :0x%08x",
drivers/bluetooth/btqca.c +1 -7
 		    le32_to_cpu(ver->product_id));
@@ -83,13 +82,7 @@ int qca_read_soc_version(struct hci_dev *hdev, u32 
 *soc_version,
 	bt_dev_info(hdev, "QCA Patch Version:0x%08x",
 		    le16_to_cpu(ver->patch_ver));
 
-	/* QCA chipset version can be decided by patch and SoC
-	 * version, combination with upper 2 bytes from SoC
-	 * and lower 2 bytes from patch will be used.
-	 */
-	*soc_version = (le32_to_cpu(ver->soc_id) << 16) |
-		       (le16_to_cpu(ver->rom_ver) & 0x0000ffff);
-	if (*soc_version == 0)
+	if (le32_to_cpu(ver->soc_id) == 0 || le16_to_cpu(ver->rom_ver) == 0)
 		err = -EILSEQ;
 

out:

drivers/bluetooth/btqca.c +2 -1
@@ -446,15 +439,25 @@ int qca_set_bdaddr_rome(struct hci_dev *hdev, 
 const bdaddr_t *bdaddr)
 EXPORT_SYMBOL_GPL(qca_set_bdaddr_rome);
 
 int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
-		   enum qca_btsoc_type soc_type, u32 soc_ver,
+		   enum qca_btsoc_type soc_type, struct qca_btsoc_version ver,
 		   const char *firmware_name)
 {
 	struct qca_fw_config config;
 	int err;
 	u8 rom_ver = 0;
+	u32 soc_ver;

drivers/bluetooth/btqca.c int qca_set_bdaddr_rome(struct hci_dev *hdev, · line 459

Quoted 10 lines
drivers/bluetooth/btqca.c +7 -0
 
 	bt_dev_dbg(hdev, "QCA setup on UART");
 
+	/* QCA chipset version can be decided by patch and SoC
+	 * version, combination with upper 2 bytes from SoC
+	 * and lower 2 bytes from patch will be used.
+	 */
+	soc_ver = (le32_to_cpu(ver.soc_id) << 16) |
+		       (le16_to_cpu(ver.rom_ver) & 0x0000ffff);
+

Can we at least do the leN_to_cpu conversions in qca_read_soc_version() as previously to make this less clunky?

Quoted 2 lines

And/or define a macro to extract 'soc_ver' to unclunkify this further.

[Venkata]:
I will define a macro to extract soc_ver and will update in next patchset.

Quoted 38 lines
Quoted 30 lines
drivers/bluetooth/btqca.c +2 -0
+	bt_dev_info(hdev, "QCA controller version 0x%08x", soc_ver);
+
 	config.user_baud_rate = baudrate;
 
drivers/bluetooth/btqca.c +9 -3
 	/* Download rampatch file */
@@ -491,9 +494,15 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t 
 baudrate,
 	if (firmware_name)
 		snprintf(config.fwname, sizeof(config.fwname),
 			 "qca/%s", firmware_name);
-	else if (qca_is_wcn399x(soc_type))
-		snprintf(config.fwname, sizeof(config.fwname),
-			 "qca/crnv%02x.bin", rom_ver);
+	else if (qca_is_wcn399x(soc_type)) {
+		if (ver.soc_id == QCA_WCN3991_SOC_ID) {
+			snprintf(config.fwname, sizeof(config.fwname),
+				 "qca/crnv%02xu.bin", rom_ver);
+		} else {
+			snprintf(config.fwname, sizeof(config.fwname),
+				 "qca/crnv%02x.bin", rom_ver);
+		}
+	}
 	else if (soc_type == QCA_QCA6390)
 		snprintf(config.fwname, sizeof(config.fwname),
drivers/bluetooth/btqca.c +0 -0
 			 "qca/htnv%02x.bin", rom_ver);
drivers/bluetooth/btqca.h +0 -0
index d81b74c..d01a9f5 100644

drivers/bluetooth/btqca.h line 37

Quoted 4 lines
drivers/bluetooth/btqca.h +1 -0
@@ -34,6 +34,8 @@
 #define QCA_HCI_CC_OPCODE		0xFC00
 #define QCA_HCI_CC_SUCCESS		0x00
 
+#define QCA_WCN3991_SOC_ID		(0x40014320)

The QCA_ prefix seems a bit verbose, given that this is a QCA driver and WCN3991 uniquely identifies the chip. Having the prefix just needlessly clutters conditions, I suggest to just call it SOC_ID_WCN3991.

maintainer
#3 lore raw
In reply to Venkata Lakshmi Narayana Gubba

Hi Venkata,

Quoted 30 lines

This change will allow to use different NVM file based on WCN3991 BT SoC ID.Need to use different NVM file based on fab location for WCN3991 BT SoC.

---

drivers/bluetooth/btqca.c   | 41 +++++++++++++++++++++++++----------------
drivers/bluetooth/btqca.h   | 13 ++++++++-----
drivers/bluetooth/hci_qca.c | 11 +++++------
3 files changed, 38 insertions(+), 27 deletions(-)
drivers/bluetooth/btqca.c +1 -2
index ce9dcff..a7e72f1 100644
@@ -14,12 +14,11 @@
 
 #define VERSION "0.1"
 
-int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
+int qca_read_soc_version(struct hci_dev *hdev, struct qca_btsoc_version *ver,
 			 enum qca_btsoc_type soc_type)
 {
 	struct sk_buff *skb;
 	struct edl_event_hdr *edl;
-	struct qca_btsoc_version *ver;
 	char cmd;
 	int err = 0;
 	u8 event_type = HCI_EV_VENDOR;

drivers/bluetooth/btqca.c int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version, · line 72

Quoted 7 lines
drivers/bluetooth/btqca.c +1 -3
@@ -70,9 +69,9 @@ int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
 	}
 
 	if (soc_type >= QCA_WCN3991)
-		memmove(&edl->data, &edl->data[1], sizeof(*ver));
-
-	ver = (struct qca_btsoc_version *)(edl->data);
+		memcpy(ver, &edl->data[1], sizeof(*ver));

any reason to use &edl->data[1] and not just edl->data + 1?

Quoted 31 lines
drivers/bluetooth/btqca.c +3 -7
+	else
+		memcpy(ver, &edl->data, sizeof(*ver));
 
 	bt_dev_info(hdev, "QCA Product ID   :0x%08x",
 		    le32_to_cpu(ver->product_id));
@@ -83,13 +82,7 @@ int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
 	bt_dev_info(hdev, "QCA Patch Version:0x%08x",
 		    le16_to_cpu(ver->patch_ver));
 
-	/* QCA chipset version can be decided by patch and SoC
-	 * version, combination with upper 2 bytes from SoC
-	 * and lower 2 bytes from patch will be used.
-	 */
-	*soc_version = (le32_to_cpu(ver->soc_id) << 16) |
-		       (le16_to_cpu(ver->rom_ver) & 0x0000ffff);
-	if (*soc_version == 0)
+	if (le32_to_cpu(ver->soc_id) == 0 || le16_to_cpu(ver->rom_ver) == 0)
 		err = -EILSEQ;
 

out:

drivers/bluetooth/btqca.c +1 -1
@@ -446,15 +439,25 @@ int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr)
 EXPORT_SYMBOL_GPL(qca_set_bdaddr_rome);
 
 int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
-		   enum qca_btsoc_type soc_type, u32 soc_ver,
+		   enum qca_btsoc_type soc_type, struct qca_btsoc_version ver,
 		   const char *firmware_name)
 {
 	struct qca_fw_config config;
 	int err;
 	u8 rom_ver = 0;

drivers/bluetooth/btqca.c int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr) · line 457

Quoted 10 lines
drivers/bluetooth/btqca.c +7 -0
+	u32 soc_ver;
 
 	bt_dev_dbg(hdev, "QCA setup on UART");
 
+	/* QCA chipset version can be decided by patch and SoC
+	 * version, combination with upper 2 bytes from SoC
+	 * and lower 2 bytes from patch will be used.
+	 */
+	soc_ver = (le32_to_cpu(ver.soc_id) << 16) |
+		       (le16_to_cpu(ver.rom_ver) & 0x0000ffff);

Please indent this properly.

I am also confused about the 0x0000ffff since it is just 16-bit value in the first place. Also where do you want to shift the 32-bit value to.

Frankly, I find all this version magic kinda questionable.

Quoted 51 lines
drivers/bluetooth/btqca.c +12 -3
+
+	bt_dev_info(hdev, "QCA controller version 0x%08x", soc_ver);
+
 	config.user_baud_rate = baudrate;
 
 	/* Download rampatch file */
@@ -491,9 +494,15 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
 	if (firmware_name)
 		snprintf(config.fwname, sizeof(config.fwname),
 			 "qca/%s", firmware_name);
-	else if (qca_is_wcn399x(soc_type))
-		snprintf(config.fwname, sizeof(config.fwname),
-			 "qca/crnv%02x.bin", rom_ver);
+	else if (qca_is_wcn399x(soc_type)) {
+		if (ver.soc_id == QCA_WCN3991_SOC_ID) {
+			snprintf(config.fwname, sizeof(config.fwname),
+				 "qca/crnv%02xu.bin", rom_ver);
+		} else {
+			snprintf(config.fwname, sizeof(config.fwname),
+				 "qca/crnv%02x.bin", rom_ver);
+		}
+	}
 	else if (soc_type == QCA_QCA6390)
 		snprintf(config.fwname, sizeof(config.fwname),
 			 "qca/htnv%02x.bin", rom_ver);
drivers/bluetooth/btqca.h +4 -2
index d81b74c..d01a9f5 100644
@@ -34,6 +34,8 @@
 #define QCA_HCI_CC_OPCODE		0xFC00
 #define QCA_HCI_CC_SUCCESS		0x00
 
+#define QCA_WCN3991_SOC_ID		(0x40014320)
+
 enum qca_baudrate {
 	QCA_BAUDRATE_115200 	= 0,
 	QCA_BAUDRATE_57600,
@@ -136,9 +138,9 @@ enum qca_btsoc_type {
 
 int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr);
 int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
-		   enum qca_btsoc_type soc_type, u32 soc_ver,
+		   enum qca_btsoc_type soc_type, struct qca_btsoc_version ver,
 		   const char *firmware_name);
-int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
+int qca_read_soc_version(struct hci_dev *hdev, struct qca_btsoc_version *ver,
 			 enum qca_btsoc_type);
 int qca_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr);
 int qca_send_pre_shutdown_cmd(struct hci_dev *hdev);

drivers/bluetooth/btqca.h static inline int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdad · line 161

Quoted 7 lines
drivers/bluetooth/btqca.h +2 -2
@@ -155,13 +157,14 @@ static inline int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdad
 }
 
 static inline int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
-				 enum qca_btsoc_type soc_type, u32 soc_ver,
-				 const char *firmware_name)
+		enum qca_btsoc_type soc_type, struct qca_btsoc_version ver,
+				const char *firmware_name)

Please use proper indentation.

Quoted 41 lines
drivers/bluetooth/btqca.h +2 -1
 {
 	return -EOPNOTSUPP;
 }
 
-static inline int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
+static inline int qca_read_soc_version(struct hci_dev *hdev,
+				       struct qca_btsoc_version *ver,
 				       enum qca_btsoc_type)
 {
 	return -EOPNOTSUPP;
drivers/bluetooth/hci_qca.c +3 -3
index 244b8fe..4c32c60 100644
@@ -1649,7 +1649,7 @@ static int qca_setup(struct hci_uart *hu)
 	enum qca_btsoc_type soc_type = qca_soc_type(hu);
 	const char *firmware_name = qca_get_firmware_name(hu);
 	int ret;
-	int soc_ver = 0;
+	struct qca_btsoc_version ver;
 
 	ret = qca_check_speeds(hu);
 	if (ret)
@@ -1678,7 +1678,7 @@ static int qca_setup(struct hci_uart *hu)
 	if (qca_is_wcn399x(soc_type)) {
 		set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks);
 
-		ret = qca_read_soc_version(hdev, &soc_ver, soc_type);
+		ret = qca_read_soc_version(hdev, &ver, soc_type);
 		if (ret)
 			return ret;
 	} else {
@@ -1697,15 +1697,14 @@ static int qca_setup(struct hci_uart *hu)
 
 	if (!qca_is_wcn399x(soc_type)) {
 		/* Get QCA version information */
-		ret = qca_read_soc_version(hdev, &soc_ver, soc_type);
+		ret = qca_read_soc_version(hdev, &ver, soc_type);
 		if (ret)
 			return ret;
 	}

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1710

Quoted 10 lines
drivers/bluetooth/hci_qca.c +2 -3
 
-	bt_dev_info(hdev, "QCA controller version 0x%08x", soc_ver);
 	/* Setup patch / NVM configurations */
-	ret = qca_uart_setup(hdev, qca_baudrate, soc_type, soc_ver,
-			firmware_name);
+	ret = qca_uart_setup(hdev, qca_baudrate, soc_type, ver,
+			     firmware_name);
 	if (!ret) {
 		set_bit(QCA_IBS_ENABLED, &qca->flags);
 		qca_debugfs_init(hdev);

Regards

Marcel

#4 lore raw

Hi Marcel,

Quoted 37 lines · Marcel Holtmann

Hi Venkata,

Quoted 35 lines

This change will allow to use different NVM file based on WCN3991 BT SoC ID.Need to use different NVM file based on fab location for WCN3991 BT SoC.

---
drivers/bluetooth/btqca.c | 41
+++++++++++++++++++++++++----------------
drivers/bluetooth/btqca.h | 13 ++++++++-----
drivers/bluetooth/hci_qca.c | 11 +++++------

3 files changed, 38 insertions(+), 27 deletions(-)
drivers/bluetooth/btqca.c +1 -2
index ce9dcff..a7e72f1 100644
@@ -14,12 +14,11 @@
 
 #define VERSION "0.1"
 
-int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
+int qca_read_soc_version(struct hci_dev *hdev, struct 
 qca_btsoc_version *ver,
 			 enum qca_btsoc_type soc_type)
 {
 	struct sk_buff *skb;
 	struct edl_event_hdr *edl;
-	struct qca_btsoc_version *ver;
 	char cmd;
 	int err = 0;
	u8 event_type = HCI_EV_VENDOR;
drivers/bluetooth/btqca.c +0 -0
@@ -70,9 +69,9 @@ int qca_read_soc_version(struct hci_dev *hdev, u32 
 *soc_version,
 	}
 
Quoted 7 lines

drivers/bluetooth/btqca.c int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version, · line 72

Quoted 5 lines
drivers/bluetooth/btqca.c +1 -3
 	if (soc_type >= QCA_WCN3991)
-		memmove(&edl->data, &edl->data[1], sizeof(*ver));
-
-	ver = (struct qca_btsoc_version *)(edl->data);
+		memcpy(ver, &edl->data[1], sizeof(*ver));

any reason to use &edl->data[1] and not just edl->data + 1?

[Venkata]:
I will use edl->data + 1 and will update in next patchset.

Quoted 38 lines
Quoted 38 lines
drivers/bluetooth/btqca.c +2 -0
+	else
+		memcpy(ver, &edl->data, sizeof(*ver));
 
 	bt_dev_info(hdev, "QCA Product ID   :0x%08x",
		    le32_to_cpu(ver->product_id));
drivers/bluetooth/btqca.c +1 -7
@@ -83,13 +82,7 @@ int qca_read_soc_version(struct hci_dev *hdev, u32 
 *soc_version,
 	bt_dev_info(hdev, "QCA Patch Version:0x%08x",
 		    le16_to_cpu(ver->patch_ver));
 
-	/* QCA chipset version can be decided by patch and SoC
-	 * version, combination with upper 2 bytes from SoC
-	 * and lower 2 bytes from patch will be used.
-	 */
-	*soc_version = (le32_to_cpu(ver->soc_id) << 16) |
-		       (le16_to_cpu(ver->rom_ver) & 0x0000ffff);
-	if (*soc_version == 0)
+	if (le32_to_cpu(ver->soc_id) == 0 || le16_to_cpu(ver->rom_ver) == 0)
 		err = -EILSEQ;
 

out:

drivers/bluetooth/btqca.c +2 -1
@@ -446,15 +439,25 @@ int qca_set_bdaddr_rome(struct hci_dev *hdev, 
 const bdaddr_t *bdaddr)
 EXPORT_SYMBOL_GPL(qca_set_bdaddr_rome);
 
 int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
-		   enum qca_btsoc_type soc_type, u32 soc_ver,
+		   enum qca_btsoc_type soc_type, struct qca_btsoc_version ver,
 		   const char *firmware_name)
 {
 	struct qca_fw_config config;
 	int err;
 	u8 rom_ver = 0;
+	u32 soc_ver;
 
 	bt_dev_dbg(hdev, "QCA setup on UART");
 
Quoted 9 lines

drivers/bluetooth/btqca.c int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr) · line 457

Quoted 6 lines
drivers/bluetooth/btqca.c +6 -0
+	/* QCA chipset version can be decided by patch and SoC
+	 * version, combination with upper 2 bytes from SoC
+	 * and lower 2 bytes from patch will be used.
+	 */
+	soc_ver = (le32_to_cpu(ver.soc_id) << 16) |
+		       (le16_to_cpu(ver.rom_ver) & 0x0000ffff);

Please indent this properly.

[Venkat]:
Sure.I will update in next patchset.

Quoted 62 lines

I am also confused about the 0x0000ffff since it is just 16-bit value in the first place. Also where do you want to shift the 32-bit value to.

Frankly, I find all this version magic kinda questionable.

Quoted 56 lines
drivers/bluetooth/btqca.c +3 -0
+
+	bt_dev_info(hdev, "QCA controller version 0x%08x", soc_ver);
+
 	config.user_baud_rate = baudrate;
 
	/* Download rampatch file */
drivers/bluetooth/btqca.c +9 -3
@@ -491,9 +494,15 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t 
 baudrate,
 	if (firmware_name)
 		snprintf(config.fwname, sizeof(config.fwname),
 			 "qca/%s", firmware_name);
-	else if (qca_is_wcn399x(soc_type))
-		snprintf(config.fwname, sizeof(config.fwname),
-			 "qca/crnv%02x.bin", rom_ver);
+	else if (qca_is_wcn399x(soc_type)) {
+		if (ver.soc_id == QCA_WCN3991_SOC_ID) {
+			snprintf(config.fwname, sizeof(config.fwname),
+				 "qca/crnv%02xu.bin", rom_ver);
+		} else {
+			snprintf(config.fwname, sizeof(config.fwname),
+				 "qca/crnv%02x.bin", rom_ver);
+		}
+	}
 	else if (soc_type == QCA_QCA6390)
 		snprintf(config.fwname, sizeof(config.fwname),
			 "qca/htnv%02x.bin", rom_ver);
drivers/bluetooth/btqca.h +4 -2
index d81b74c..d01a9f5 100644
@@ -34,6 +34,8 @@
 #define QCA_HCI_CC_OPCODE		0xFC00
 #define QCA_HCI_CC_SUCCESS		0x00
 
+#define QCA_WCN3991_SOC_ID		(0x40014320)
+
 enum qca_baudrate {
 	QCA_BAUDRATE_115200 	= 0,
 	QCA_BAUDRATE_57600,
@@ -136,9 +138,9 @@ enum qca_btsoc_type {
 
 int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr);
 int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,
-		   enum qca_btsoc_type soc_type, u32 soc_ver,
+		   enum qca_btsoc_type soc_type, struct qca_btsoc_version ver,
 		   const char *firmware_name);
-int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,
+int qca_read_soc_version(struct hci_dev *hdev, struct 
 qca_btsoc_version *ver,
 			 enum qca_btsoc_type);
 int qca_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr);

int qca_send_pre_shutdown_cmd(struct hci_dev *hdev);

drivers/bluetooth/btqca.h +0 -0
@@ -155,13 +157,14 @@ static inline int qca_set_bdaddr_rome(struct 

hci_dev *hdev, const bdaddr_t *bdad
}

Quoted 8 lines

drivers/bluetooth/btqca.h static inline int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdad · line 161

Quoted 5 lines

static inline int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate,

drivers/bluetooth/btqca.h +2 -2
-				 enum qca_btsoc_type soc_type, u32 soc_ver,
-				 const char *firmware_name)
+		enum qca_btsoc_type soc_type, struct qca_btsoc_version ver,
+				const char *firmware_name)

Please use proper indentation.

[Venkat]:
Sure.I will update in next patchset.

Quoted 56 lines
Quoted 42 lines
{
	return -EOPNOTSUPP;
}

-static inline int qca_read_soc_version(struct hci_dev *hdev, u32 *soc_version,

drivers/bluetooth/btqca.h +2 -0
+static inline int qca_read_soc_version(struct hci_dev *hdev,
+				       struct qca_btsoc_version *ver,

enum qca_btsoc_type)

{
	return -EOPNOTSUPP;
drivers/bluetooth/hci_qca.c +3 -3
index 244b8fe..4c32c60 100644
@@ -1649,7 +1649,7 @@ static int qca_setup(struct hci_uart *hu)
 	enum qca_btsoc_type soc_type = qca_soc_type(hu);
 	const char *firmware_name = qca_get_firmware_name(hu);
 	int ret;
-	int soc_ver = 0;
+	struct qca_btsoc_version ver;
 
 	ret = qca_check_speeds(hu);
 	if (ret)
@@ -1678,7 +1678,7 @@ static int qca_setup(struct hci_uart *hu)
 	if (qca_is_wcn399x(soc_type)) {
 		set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks);
 
-		ret = qca_read_soc_version(hdev, &soc_ver, soc_type);
+		ret = qca_read_soc_version(hdev, &ver, soc_type);
 		if (ret)
 			return ret;
 	} else {
@@ -1697,15 +1697,14 @@ static int qca_setup(struct hci_uart *hu)
 
 	if (!qca_is_wcn399x(soc_type)) {
 		/* Get QCA version information */
-		ret = qca_read_soc_version(hdev, &soc_ver, soc_type);
+		ret = qca_read_soc_version(hdev, &ver, soc_type);
 		if (ret)
 			return ret;
 	}

drivers/bluetooth/hci_qca.c static int qca_setup(struct hci_uart *hu) · line 1710

Quoted 10 lines
drivers/bluetooth/hci_qca.c +2 -3
 
-	bt_dev_info(hdev, "QCA controller version 0x%08x", soc_ver);
 	/* Setup patch / NVM configurations */
-	ret = qca_uart_setup(hdev, qca_baudrate, soc_type, soc_ver,
-			firmware_name);
+	ret = qca_uart_setup(hdev, qca_baudrate, soc_type, ver,
+			     firmware_name);
 	if (!ret) {
 		set_bit(QCA_IBS_ENABLED, &qca->flags);
 		qca_debugfs_init(hdev);

Regards

Marcel