Skip to contentSkip to conversation

ath10k: Introduce download cal from mtd

PATCH In review Ansuel Smith 2 participants 4 messages Sep 18, 2020 – Sep 23, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 ath10k: Introduce download cal from mtd

Most of routers that have the ath10k wifi chip integrated in the Soc have the pre-cal data stored in the art (or equivalent) mtd partition. Introduce a new function to directly extract and use it based on what is set in the dt if the system have mtd support.
Pre-cal file have still priority to everything else.

Tested-on: QCA9984 hw1.0 PCI 10.4

---
v2:
* Fix missing condition for cal_mode in transposing source to ath repo

 drivers/net/wireless/ath/ath10k/core.c | 80 +++++++++++++++++++++++++-
 drivers/net/wireless/ath/ath10k/core.h |  3 +
 2 files changed, 81 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath10k/core.c +78 -2
index 5f4e12196..d35abd16a 100644
@@ -13,6 +13,7 @@
 #include <linux/ctype.h>
 #include <linux/pm_qos.h>
 #include <asm/byteorder.h>
+#include <linux/mtd/mtd.h>
 
 #include "core.h"
 #include "mac.h"
@@ -918,7 +919,8 @@ static int ath10k_core_get_board_id_from_otp(struct ath10k *ar)
 	}
 
 	if (ar->cal_mode == ATH10K_PRE_CAL_MODE_DT ||
-	    ar->cal_mode == ATH10K_PRE_CAL_MODE_FILE)
+	    ar->cal_mode == ATH10K_PRE_CAL_MODE_FILE ||
+	    ar->cal_mode == ATH10K_PRE_CAL_MODE_MTD)
 		bmi_board_id_param = BMI_PARAM_GET_FLASH_BOARD_ID;
 	else
 		bmi_board_id_param = BMI_PARAM_GET_EEPROM_BOARD_ID;
@@ -1680,7 +1682,8 @@ static int ath10k_download_and_run_otp(struct ath10k *ar)
 
 	/* As of now pre-cal is valid for 10_4 variants */
 	if (ar->cal_mode == ATH10K_PRE_CAL_MODE_DT ||
-	    ar->cal_mode == ATH10K_PRE_CAL_MODE_FILE)
+	    ar->cal_mode == ATH10K_PRE_CAL_MODE_FILE ||
+	    ar->cal_mode == ATH10K_PRE_CAL_MODE_MTD)
 		bmi_otp_exe_param = BMI_PARAM_FLASH_SECTION_ALL;
 
 	ret = ath10k_bmi_execute(ar, address, bmi_otp_exe_param, &result);
@@ -1701,6 +1704,69 @@ static int ath10k_download_and_run_otp(struct ath10k *ar)
 	return 0;
 }
 
+static int ath10k_download_cal_mtd(struct ath10k *ar)
+{
+#ifdef CONFIG_MTD
+	struct device_node *node, *mtd_node = NULL;
+	struct mtd_info *mtd;
+	const __be32 *list;
+	u32 offset, size;
+	const char *part;
+	phandle phandle;
+	size_t retlen;
+	char *file;
+	int ret;
+
+	node = ar->dev->of_node;
+	if (!node)
+		return -ENOENT;
+
+	list = of_get_property(node, "qcom,ath10k-pre-calibration-data-mtd", &size);
+	if (!list || (size != (3 * sizeof(*list))))
+		return -EINVAL;
+
+	phandle = be32_to_cpup(list++);
+	if (phandle)
+		mtd_node = of_find_node_by_phandle(phandle);
+
+	if (!mtd_node)
+		return -ENODEV;
+
+	part = of_get_property(mtd_node, "label", NULL);
+	if (!part)
+		part = mtd_node->name;
+
+	mtd = get_mtd_device_nm(part);
+	if (IS_ERR(mtd))
+		return -ENODEV;
+
+	offset = be32_to_cpup(list++);
+	size = be32_to_cpup(list);
+
+	file = kzalloc(size, GFP_KERNEL);
+	if (!file)
+		return -ENOMEM;
+
+	ret = mtd_read(mtd, offset, size, &retlen, file);
+	put_mtd_device(mtd);
+
+	ret = ath10k_download_board_data(ar, file, size);
+	if (ret) {
+		ath10k_err(ar, "failed to download cal_file data: %d\n", ret);
+		goto err;
+	}
+
+	ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cal file downloaded\n");
+
+	return 0;
+
+err:
+	kfree(file);
+	return ret;
+#endif
+	return -EOPNOTSUPP;
+}
+
 static int ath10k_download_cal_file(struct ath10k *ar,
 				    const struct firmware *file)
 {
@@ -2047,6 +2113,16 @@ static int ath10k_core_pre_cal_download(struct ath10k *ar)
 		goto success;
 	}
 
+	ath10k_dbg(ar, ATH10K_DBG_BOOT,
+		   "boot did not find a pre calibration file, try MTD next: %d\n",
+		   ret);
+
+	ret = ath10k_download_cal_mtd(ar);
+	if (ret == 0) {
+		ar->cal_mode = ATH10K_PRE_CAL_MODE_MTD;
+		goto success;
+	}
+
 	ath10k_dbg(ar, ATH10K_DBG_BOOT,
 		   "boot did not find a pre calibration file, try DT next: %d\n",
 		   ret);
drivers/net/wireless/ath/ath10k/core.h +3 -0
index 4cf5bd489..3ca158605 100644
@@ -864,6 +864,7 @@ enum ath10k_cal_mode {
 	ATH10K_CAL_MODE_OTP,
 	ATH10K_CAL_MODE_DT,
 	ATH10K_PRE_CAL_MODE_FILE,
+	ATH10K_PRE_CAL_MODE_MTD,
 	ATH10K_PRE_CAL_MODE_DT,
 	ATH10K_CAL_MODE_EEPROM,
 };
@@ -886,6 +887,8 @@ static inline const char *ath10k_cal_mode_str(enum ath10k_cal_mode mode)
 		return "dt";
 	case ATH10K_PRE_CAL_MODE_FILE:
 		return "pre-cal-file";
+	case ATH10K_PRE_CAL_MODE_MTD:
+		return "pre-cal-mtd";
 	case ATH10K_PRE_CAL_MODE_DT:
 		return "pre-cal-dt";
 	case ATH10K_CAL_MODE_EEPROM:
Signature · 7 lines
2.27.0


_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
#1 lore raw

PATCH v2 2/2 dt: bindings: ath10k: Document qcom,ath10k-pre-calibration-data-mtd

Document use of qcom,ath10k-pre-calibration-data-mtd bindings used to define from where the driver will load the pre-cal data in the defined mtd partition.

---
 .../devicetree/bindings/net/wireless/qcom,ath10k.txt | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt +9 -3
index b61c2d5a0..568364243 100644
@@ -15,9 +15,9 @@ and also uses most of the properties defined in this doc (except
 "qcom,ath10k-calibration-data"). It uses "qcom,ath10k-pre-calibration-data"
 to carry pre calibration data.
 
-In general, entry "qcom,ath10k-pre-calibration-data" and
-"qcom,ath10k-calibration-data" conflict with each other and only one
-can be provided per device.
+In general, entry "qcom,ath10k-pre-calibration-data",
+"qcom,ath10k-calibration-data-mtd" and "qcom,ath10k-calibration-data" conflict with
+each other and only one can be provided per device.
 
 SNOC based devices (i.e. wcn3990) uses compatible string "qcom,wcn3990-wifi".
 
@@ -63,6 +63,12 @@ Optional properties:
 				 hw versions.
 - qcom,ath10k-pre-calibration-data : pre calibration data as an array,
 				     the length can vary between hw versions.
+- qcom,ath10k-pre-calibration-data-mtd :
+	Usage: optional
+	Value type: <phandle offset size>
+	Definition: pre calibration data read from mtd partition. Take 3 value, the
+		    mtd to read data from, the offset in the mtd partition and the
+		    size of data to read.
 - <supply-name>-supply: handle to the regulator device tree node
 			   optional "supply-name" are "vdd-0.8-cx-mx",
 			   "vdd-1.8-xo", "vdd-1.3-rfa", "vdd-3.3-ch0",
Signature · 7 lines
2.27.0


_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k
maintainer
#2 lore raw

Re: [PATCH v2 2/2] dt: bindings: ath10k: Document qcom,ath10k-pre-calibration-data-mtd

Quoted 27 lines · Ansuel Smith

Document use of qcom,ath10k-pre-calibration-data-mtd bindings used to define from where the driver will load the pre-cal data in the defined mtd partition.

---
 .../devicetree/bindings/net/wireless/qcom,ath10k.txt | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt +3 -3
index b61c2d5a0..568364243 100644
@@ -15,9 +15,9 @@ and also uses most of the properties defined in this doc (except
 "qcom,ath10k-calibration-data"). It uses "qcom,ath10k-pre-calibration-data"
 to carry pre calibration data.
 
-In general, entry "qcom,ath10k-pre-calibration-data" and
-"qcom,ath10k-calibration-data" conflict with each other and only one
-can be provided per device.
+In general, entry "qcom,ath10k-pre-calibration-data",
+"qcom,ath10k-calibration-data-mtd" and "qcom,ath10k-calibration-data" conflict with
+each other and only one can be provided per device.
 
 SNOC based devices (i.e. wcn3990) uses compatible string "qcom,wcn3990-wifi".
 

Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt Optional properties: · line 66

Quoted 4 lines
Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt +1 -0
@@ -63,6 +63,12 @@ Optional properties:
 				 hw versions.
 - qcom,ath10k-pre-calibration-data : pre calibration data as an array,
 				     the length can vary between hw versions.
+- qcom,ath10k-pre-calibration-data-mtd :

mtd is a Linuxism.

Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt Optional properties: · line 70

Quoted 4 lines
Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt +4 -0
+	Usage: optional
+	Value type: <phandle offset size>
+	Definition: pre calibration data read from mtd partition. Take 3 value, the
+		    mtd to read data from, the offset in the mtd partition and the

The phandle is the mtd or partition?

Maybe you should be using nvmem binding here.

Quoted 7 lines
Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt +1 -0
+		    size of data to read.
 - <supply-name>-supply: handle to the regulator device tree node
 			   optional "supply-name" are "vdd-0.8-cx-mx",
 			   "vdd-1.8-xo", "vdd-1.3-rfa", "vdd-3.3-ch0",
Signature · 1 line
2.27.0

_______________________________________________
ath10k mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/ath10k

#3 lore raw

RE: [PATCH v2 2/2] dt: bindings: ath10k: Document qcom,ath10k-pre-calibration-data-mtd

Quoted 44 lines

-----Original Message-----
From: Rob Herring <[email protected]>
Sent: Wednesday, September 23, 2020 10:58 PM
To: Ansuel Smith <[email protected]>
Cc: Kalle Valo <[email protected]>; David S. Miller <[email protected]>; Jakub Kicinski <[email protected]>; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 2/2] dt: bindings: ath10k: Document qcom,ath10k- pre-calibration-data-mtd

Quoted 10 lines · Ansuel Smith

Document use of qcom,ath10k-pre-calibration-data-mtd bindings used to define from where the driver will load the pre-cal data in the defined mtd partition.

---
 .../devicetree/bindings/net/wireless/qcom,ath10k.txt | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git

a/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt b/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt

Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt and also uses most of the properties defined in this

Quoted 4 lines

index b61c2d5a0..568364243 100644

Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt +0 -0
@@ -15,9 +15,9 @@ and also uses most of the properties defined in this

doc (except

Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt and also uses most of the properties defined in this · line 15

Quoted 1 line
Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt +0 -0
 "qcom,ath10k-calibration-data"). It uses "qcom,ath10k-pre-calibration-

data"

Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt and also uses most of the properties defined in this doc (except

Quoted 7 lines
Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt +2 -3
 to carry pre calibration data.
 
-In general, entry "qcom,ath10k-pre-calibration-data" and
-"qcom,ath10k-calibration-data" conflict with each other and only one
-can be provided per device.
+In general, entry "qcom,ath10k-pre-calibration-data",
+"qcom,ath10k-calibration-data-mtd" and "qcom,ath10k-calibration-

data" conflict with

Quoted 2 lines
Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt +1 -0
+each other and only one can be provided per device.
 
Quoted 7 lines

Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt and also uses most of the properties defined in this · line 22

Quoted 1 line
Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt +0 -0
 SNOC based devices (i.e. wcn3990) uses compatible string

"qcom,wcn3990-wifi".

Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt Optional properties: · line 65

Quoted 5 lines
Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt +0 -0
@@ -63,6 +63,12 @@ Optional properties:
 				 hw versions.
 - qcom,ath10k-pre-calibration-data : pre calibration data as an array,
 				     the length can vary between hw

versions.

Quoted 9 lines

Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt Optional properties: · line 66

Quoted 1 line
Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt +1 -0
+- qcom,ath10k-pre-calibration-data-mtd :

mtd is a Linuxism.

Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt Optional properties:

Quoted 3 lines
Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt +3 -0
+	Usage: optional
+	Value type: <phandle offset size>
+	Definition: pre calibration data read from mtd partition. Take 3

value, the

Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt Optional properties: · line 70

Quoted 1 line
Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt +1 -0
+		    mtd to read data from, the offset in the mtd partition

and

Quoted 6 lines

the

The phandle is the mtd or partition?

Maybe you should be using nvmem binding here.

The phandle is to the mtd.
You are right about nvmem... Problem is that nvmem for mtd is still not supported. I already sent a patch to fix this in the mtd mailing list but I'm waiting for review...
If that will be accepted, I can convert this patch to use nvmem api.

Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt +1 -1
+		    size of data to read.
 - <supply-name>-supply: handle to the regulator device tree node
 			   optional "supply-name" are "vdd-0.8-cx-mx",
 			   "vdd-1.8-xo", "vdd-1.3-rfa", "vdd-3.3-ch0",
--

2.27.0