linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ath10k: Introduce download cal from mtd
@ 2020-09-18 16:29 Ansuel Smith
  2020-09-18 16:29 ` [PATCH 2/2] dt: bindings: ath10k: Document qcom,ath10k-pre-calibration-data-mtd Ansuel Smith
  0 siblings, 1 reply; 6+ messages in thread
From: Ansuel Smith @ 2020-09-18 16:29 UTC (permalink / raw)
  To: Kalle Valo
  Cc: Ansuel Smith, David S. Miller, Jakub Kicinski, Rob Herring,
	linux-wireless, netdev, devicetree, linux-kernel, ath10k

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

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
 drivers/net/wireless/ath/ath10k/core.c | 74 ++++++++++++++++++++++++++
 drivers/net/wireless/ath/ath10k/core.h |  3 ++
 2 files changed, 77 insertions(+)

diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
index 5f4e12196..eef00d657 100644
--- a/drivers/net/wireless/ath/ath10k/core.c
+++ b/drivers/net/wireless/ath/ath10k/core.c
@@ -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"
@@ -1701,6 +1702,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 +2111,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);
diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h
index 4cf5bd489..3ca158605 100644
--- a/drivers/net/wireless/ath/ath10k/core.h
+++ b/drivers/net/wireless/ath/ath10k/core.h
@@ -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:
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] dt: bindings: ath10k: Document qcom,ath10k-pre-calibration-data-mtd
  2020-09-18 16:29 [PATCH] ath10k: Introduce download cal from mtd Ansuel Smith
@ 2020-09-18 16:29 ` Ansuel Smith
  2020-09-18 16:53   ` [PATCH 2/2] dt: bindings: ath10k: Document qcom, ath10k-pre-calibration-data-mtd Christian Lamparter
  0 siblings, 1 reply; 6+ messages in thread
From: Ansuel Smith @ 2020-09-18 16:29 UTC (permalink / raw)
  To: Kalle Valo
  Cc: Ansuel Smith, David S. Miller, Jakub Kicinski, Rob Herring,
	linux-wireless, netdev, devicetree, linux-kernel, ath10k

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.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
---
 .../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
index b61c2d5a0..568364243 100644
--- a/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt
+++ b/Documentation/devicetree/bindings/net/wireless/qcom,ath10k.txt
@@ -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",
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] dt: bindings: ath10k: Document qcom, ath10k-pre-calibration-data-mtd
  2020-09-18 16:29 ` [PATCH 2/2] dt: bindings: ath10k: Document qcom,ath10k-pre-calibration-data-mtd Ansuel Smith
@ 2020-09-18 16:53   ` Christian Lamparter
  2020-09-18 18:08     ` R: " ansuelsmth
  2020-09-18 18:31     ` ansuelsmth
  0 siblings, 2 replies; 6+ messages in thread
From: Christian Lamparter @ 2020-09-18 16:53 UTC (permalink / raw)
  To: Ansuel Smith, Kalle Valo
  Cc: devicetree, netdev, linux-wireless, linux-kernel, ath10k,
	David S. Miller, Rob Herring, Jakub Kicinski, linux-mtd,
	Srinivas Kandagatla, Bartosz Golaszewski

On 2020-09-18 18:29, Ansuel Smith wrote:
> 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.
> 
> Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>

Q: Doesn't mtd now come with nvmem support from the get go? So
the MAC-Addresses and pre-caldata could be specified as a
nvmem-node in the devicetree? I remember seeing that this was
worked on or was this mtd->nvmem dropped?

Cheers,
Christian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* R: [PATCH 2/2] dt: bindings: ath10k: Document qcom, ath10k-pre-calibration-data-mtd
  2020-09-18 16:53   ` [PATCH 2/2] dt: bindings: ath10k: Document qcom, ath10k-pre-calibration-data-mtd Christian Lamparter
@ 2020-09-18 18:08     ` ansuelsmth
  2020-09-18 18:31     ` ansuelsmth
  1 sibling, 0 replies; 6+ messages in thread
From: ansuelsmth @ 2020-09-18 18:08 UTC (permalink / raw)
  To: 'Christian Lamparter', 'Kalle Valo'
  Cc: devicetree, netdev, linux-wireless, linux-kernel, ath10k,
	'David S. Miller', 'Rob Herring',
	'Jakub Kicinski',
	linux-mtd, 'Srinivas Kandagatla',
	'Bartosz Golaszewski'



> -----Messaggio originale-----
> Da: Christian Lamparter <chunkeey@gmail.com>
> Inviato: venerdì 18 settembre 2020 18:54
> A: Ansuel Smith <ansuelsmth@gmail.com>; Kalle Valo
> <kvalo@codeaurora.org>
> Cc: devicetree@vger.kernel.org; netdev@vger.kernel.org; linux-
> wireless@vger.kernel.org; linux-kernel@vger.kernel.org;
> ath10k@lists.infradead.org; David S. Miller <davem@davemloft.net>; Rob
> Herring <robh+dt@kernel.org>; Jakub Kicinski <kuba@kernel.org>; linux-
> mtd@lists.infradead.org; Srinivas Kandagatla
> <srinivas.kandagatla@linaro.org>; Bartosz Golaszewski
> <bgolaszewski@baylibre.com>
> Oggetto: Re: [PATCH 2/2] dt: bindings: ath10k: Document qcom, ath10k-
> pre-calibration-data-mtd
> 
> On 2020-09-18 18:29, Ansuel Smith wrote:
> > 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.
> >
> > Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
> 
> Q: Doesn't mtd now come with nvmem support from the get go? So
> the MAC-Addresses and pre-caldata could be specified as a
> nvmem-node in the devicetree? I remember seeing that this was
> worked on or was this mtd->nvmem dropped?
> 
> Cheers,
> Christian

Can you give me some example where this is used? I can't find any reference.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* R: [PATCH 2/2] dt: bindings: ath10k: Document qcom, ath10k-pre-calibration-data-mtd
  2020-09-18 16:53   ` [PATCH 2/2] dt: bindings: ath10k: Document qcom, ath10k-pre-calibration-data-mtd Christian Lamparter
  2020-09-18 18:08     ` R: " ansuelsmth
@ 2020-09-18 18:31     ` ansuelsmth
  2020-09-18 18:55       ` Christian Lamparter
  1 sibling, 1 reply; 6+ messages in thread
From: ansuelsmth @ 2020-09-18 18:31 UTC (permalink / raw)
  To: 'Christian Lamparter', 'Kalle Valo'
  Cc: devicetree, netdev, linux-wireless, linux-kernel, ath10k,
	'David S. Miller', 'Rob Herring',
	'Jakub Kicinski',
	linux-mtd, 'Srinivas Kandagatla',
	'Bartosz Golaszewski'



> -----Messaggio originale-----
> Da: Christian Lamparter <chunkeey@gmail.com>
> Inviato: venerdì 18 settembre 2020 18:54
> A: Ansuel Smith <ansuelsmth@gmail.com>; Kalle Valo
> <kvalo@codeaurora.org>
> Cc: devicetree@vger.kernel.org; netdev@vger.kernel.org; linux-
> wireless@vger.kernel.org; linux-kernel@vger.kernel.org;
> ath10k@lists.infradead.org; David S. Miller <davem@davemloft.net>; Rob
> Herring <robh+dt@kernel.org>; Jakub Kicinski <kuba@kernel.org>; linux-
> mtd@lists.infradead.org; Srinivas Kandagatla
> <srinivas.kandagatla@linaro.org>; Bartosz Golaszewski
> <bgolaszewski@baylibre.com>
> Oggetto: Re: [PATCH 2/2] dt: bindings: ath10k: Document qcom, ath10k-
> pre-calibration-data-mtd
> 
> On 2020-09-18 18:29, Ansuel Smith wrote:
> > 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.
> >
> > Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
> 
> Q: Doesn't mtd now come with nvmem support from the get go? So
> the MAC-Addresses and pre-caldata could be specified as a
> nvmem-node in the devicetree? I remember seeing that this was
> worked on or was this mtd->nvmem dropped?
> 
> Cheers,
> Christian

Sorry a lot for the double email... I think I found what you are talking about.
It looks like the code was merged but not the documentation.
Will do some test and check if this works.

This should be the related patch.
https://patchwork.ozlabs.org/project/linux-mtd/patch/1521933899-362-4-git-send-email-albeu@free.fr/



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: R: [PATCH 2/2] dt: bindings: ath10k: Document qcom, ath10k-pre-calibration-data-mtd
  2020-09-18 18:31     ` ansuelsmth
@ 2020-09-18 18:55       ` Christian Lamparter
  0 siblings, 0 replies; 6+ messages in thread
From: Christian Lamparter @ 2020-09-18 18:55 UTC (permalink / raw)
  To: ansuelsmth, 'Kalle Valo'
  Cc: devicetree, netdev, linux-wireless, linux-kernel, ath10k,
	'David S. Miller', 'Rob Herring',
	'Jakub Kicinski',
	linux-mtd, 'Srinivas Kandagatla',
	'Bartosz Golaszewski'

On 2020-09-18 20:31, ansuelsmth@gmail.com wrote:
> 
> 
>> -----Messaggio originale-----
>> Da: Christian Lamparter <chunkeey@gmail.com>
>> Inviato: venerdì 18 settembre 2020 18:54
>> A: Ansuel Smith <ansuelsmth@gmail.com>; Kalle Valo
>> <kvalo@codeaurora.org>
>> Cc: devicetree@vger.kernel.org; netdev@vger.kernel.org; linux-
>> wireless@vger.kernel.org; linux-kernel@vger.kernel.org;
>> ath10k@lists.infradead.org; David S. Miller <davem@davemloft.net>; Rob
>> Herring <robh+dt@kernel.org>; Jakub Kicinski <kuba@kernel.org>; linux-
>> mtd@lists.infradead.org; Srinivas Kandagatla
>> <srinivas.kandagatla@linaro.org>; Bartosz Golaszewski
>> <bgolaszewski@baylibre.com>
>> Oggetto: Re: [PATCH 2/2] dt: bindings: ath10k: Document qcom, ath10k-
>> pre-calibration-data-mtd
>>
>> On 2020-09-18 18:29, Ansuel Smith wrote:
>>> 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.
>>>
>>> Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
>>
>> Q: Doesn't mtd now come with nvmem support from the get go? So
>> the MAC-Addresses and pre-caldata could be specified as a
>> nvmem-node in the devicetree? I remember seeing that this was
>> worked on or was this mtd->nvmem dropped?
>>
>> Cheers,
>> Christian
> 
> Sorry a lot for the double email... I think I found what you are talking about.
> It looks like the code was merged but not the documentation.
> Will do some test and check if this works.
> 
> This should be the related patch.
> https://patchwork.ozlabs.org/project/linux-mtd/patch/1521933899-362-4-git-send-email-albeu@free.fr/
> 

Well, I guess the version that was merged:

|commit c4dfa25ab307a277eafa7067cd927fbe4d9be4ba
|Author: Alban Bedel <albeu@free.fr>
|Date:   Tue Nov 13 15:01:10 2018 +0100
|
|    mtd: add support for reading MTD devices via the nvmem API
|
|    Allow drivers that use the nvmem API to read data stored on MTD devices.
|    For this the mtd devices are registered as read-only NVMEM providers.
|
| >>>We don't support device tree systems for now.<<<

answers this. Sorry for the noise. Yee, this likely isn't going to work
as it is still disabled on purpose.

Regards,
Christian

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-09-18 18:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-18 16:29 [PATCH] ath10k: Introduce download cal from mtd Ansuel Smith
2020-09-18 16:29 ` [PATCH 2/2] dt: bindings: ath10k: Document qcom,ath10k-pre-calibration-data-mtd Ansuel Smith
2020-09-18 16:53   ` [PATCH 2/2] dt: bindings: ath10k: Document qcom, ath10k-pre-calibration-data-mtd Christian Lamparter
2020-09-18 18:08     ` R: " ansuelsmth
2020-09-18 18:31     ` ansuelsmth
2020-09-18 18:55       ` Christian Lamparter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).