linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arend van Spriel <arend@broadcom.com>
To: Kalle Valo <kvalo@codeaurora.org>
Cc: linux-wireless <linux-wireless@vger.kernel.org>,
	Hante Meuleman <meuleman@broadcom.com>,
	<linux-mips@linux-mips.org>,
	Arend van Spriel <arend@broadcom.com>
Subject: [PATCH 6/6] brcmfmac: Add support for host platform NVRAM loading.
Date: Wed, 20 May 2015 14:09:52 +0200	[thread overview]
Message-ID: <1432123792-4155-7-git-send-email-arend@broadcom.com> (raw)
In-Reply-To: <1432123792-4155-1-git-send-email-arend@broadcom.com>

From: Hante Meuleman <meuleman@broadcom.com>

Host platforms such as routers supported by OpenWRT can
support NVRAM reading directly from internal NVRAM store.
With this patch the nvram load routines will fall back to
this method when there is no nvram file and support is
available in the kernel.

Cc: linux-mips@linux-mips.org
Reviewed-by: Arend Van Spriel <arend@broadcom.com>
Reviewed-by: Franky (Zhenhui) Lin <frankyl@broadcom.com>
Reviewed-by: Pieter-Paul Giesberts <pieterpg@broadcom.com>
Reviewed-by: Daniel (Deognyoun) Kim <dekim@broadcom.com>
Signed-off-by: Hante Meuleman <meuleman@broadcom.com>
Signed-off-by: Arend van Spriel <arend@broadcom.com>
---
Hi Kalle,

This patch relies on a change which has been submitted to the
linux-mips maintainer [1]. However, the brcmfmac code that relies on
it is under CONFIG_BCM47XX flag. Still need to know whether that
patch will be accepted or not before applying this one.

Regards,
Arend

[1] http://mid.gmane.org/1432122655-3224-1-git-send-email-arend@broadcom.com
---
 drivers/net/wireless/brcm80211/brcmfmac/firmware.c | 107 ++++++++++++++-------
 1 file changed, 72 insertions(+), 35 deletions(-)

diff --git a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c
index 8ff31ff..bf8928d 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c
@@ -19,6 +19,9 @@
 #include <linux/device.h>
 #include <linux/firmware.h>
 #include <linux/module.h>
+#if IS_ENABLED(CONFIG_BCM47XX)
+#include <linux/bcm47xx_nvram.h>
+#endif
 
 #include "debug.h"
 #include "firmware.h"
@@ -43,7 +46,8 @@ enum nvram_parser_state {
  * struct nvram_parser - internal info for parser.
  *
  * @state: current parser state.
- * @fwnv: input buffer being parsed.
+ * @data: input buffer data pointer.
+ * @data_len : len of input buffer.
  * @nvram: output buffer with parse result.
  * @nvram_len: lenght of parse result.
  * @line: current line.
@@ -55,7 +59,8 @@ enum nvram_parser_state {
  */
 struct nvram_parser {
 	enum nvram_parser_state state;
-	const struct firmware *fwnv;
+	u8 *data;
+	u32 data_len;
 	u8 *nvram;
 	u32 nvram_len;
 	u32 line;
@@ -66,6 +71,27 @@ struct nvram_parser {
 	bool multi_dev_v2;
 };
 
+#if IS_ENABLED(CONFIG_BCM47XX)
+static char *brcmf_nvram_get_contents(size_t *nvram_size)
+{
+	return bcm47xx_nvram_get_contents(nvram_size);
+}
+
+static void brcmf_nvram_release_contents(char *nvram)
+{
+	bcm47xx_nvram_release_contents(nvram);
+}
+#else
+static char *brcmf_nvram_get_contents(size_t *nvram_size)
+{
+	return NULL;
+}
+
+static void brcmf_nvram_release_contents(char *nvram)
+{
+}
+#endif
+
 static bool is_nvram_char(char c)
 {
 	/* comment marker excluded */
@@ -85,7 +111,7 @@ static enum nvram_parser_state brcmf_nvram_handle_idle(struct nvram_parser *nvp)
 {
 	char c;
 
-	c = nvp->fwnv->data[nvp->pos];
+	c = nvp->data[nvp->pos];
 	if (c == '\n')
 		return COMMENT;
 	if (is_whitespace(c))
@@ -109,16 +135,16 @@ static enum nvram_parser_state brcmf_nvram_handle_key(struct nvram_parser *nvp)
 	enum nvram_parser_state st = nvp->state;
 	char c;
 
-	c = nvp->fwnv->data[nvp->pos];
+	c = nvp->data[nvp->pos];
 	if (c == '=') {
 		/* ignore RAW1 by treating as comment */
-		if (strncmp(&nvp->fwnv->data[nvp->entry], "RAW1", 4) == 0)
+		if (strncmp(&nvp->data[nvp->entry], "RAW1", 4) == 0)
 			st = COMMENT;
 		else
 			st = VALUE;
-		if (strncmp(&nvp->fwnv->data[nvp->entry], "devpath", 7) == 0)
+		if (strncmp(&nvp->data[nvp->entry], "devpath", 7) == 0)
 			nvp->multi_dev_v1 = true;
-		if (strncmp(&nvp->fwnv->data[nvp->entry], "pcie/", 5) == 0)
+		if (strncmp(&nvp->data[nvp->entry], "pcie/", 5) == 0)
 			nvp->multi_dev_v2 = true;
 	} else if (!is_nvram_char(c)) {
 		brcmf_dbg(INFO, "warning: ln=%d:col=%d: '=' expected, skip invalid key entry\n",
@@ -139,11 +165,11 @@ brcmf_nvram_handle_value(struct nvram_parser *nvp)
 	char *ekv;
 	u32 cplen;
 
-	c = nvp->fwnv->data[nvp->pos];
-	if (!is_nvram_char(c)) {
+	c = nvp->data[nvp->pos];
+	if (!is_nvram_char(c) && (c != ' ')) {
 		/* key,value pair complete */
-		ekv = (u8 *)&nvp->fwnv->data[nvp->pos];
-		skv = (u8 *)&nvp->fwnv->data[nvp->entry];
+		ekv = (u8 *)&nvp->data[nvp->pos];
+		skv = (u8 *)&nvp->data[nvp->entry];
 		cplen = ekv - skv;
 		if (nvp->nvram_len + cplen + 1 >= BRCMF_FW_MAX_NVRAM_SIZE)
 			return END;
@@ -164,7 +190,7 @@ brcmf_nvram_handle_comment(struct nvram_parser *nvp)
 {
 	char *eol, *sol;
 
-	sol = (char *)&nvp->fwnv->data[nvp->pos];
+	sol = (char *)&nvp->data[nvp->pos];
 	eol = strchr(sol, '\n');
 	if (eol == NULL)
 		return END;
@@ -191,18 +217,20 @@ static enum nvram_parser_state
 	brcmf_nvram_handle_end
 };
 
-static int brcmf_init_nvram_parser(struct nvram_parser *nvp,
-				   const struct firmware *nv)
+static int brcmf_init_nvram_parser(struct nvram_parser *nvp, u8 *data,
+				   u32 data_len)
 {
 	size_t size;
 
 	memset(nvp, 0, sizeof(*nvp));
-	nvp->fwnv = nv;
+	nvp->data = data;
+	nvp->data_len = data_len;
+
 	/* Limit size to MAX_NVRAM_SIZE, some files contain lot of comment */
-	if (nv->size > BRCMF_FW_MAX_NVRAM_SIZE)
+	if (data_len > BRCMF_FW_MAX_NVRAM_SIZE)
 		size = BRCMF_FW_MAX_NVRAM_SIZE;
 	else
-		size = nv->size;
+		size = data_len;
 	/* Alloc for extra 0 byte + roundup by 4 + length field */
 	size += 1 + 3 + sizeof(u32);
 	nvp->nvram = kzalloc(size, GFP_KERNEL);
@@ -342,7 +370,7 @@ fail:
  * and converts newlines to NULs. Shortens buffer as needed and pads with NULs.
  * End of buffer is completed with token identifying length of buffer.
  */
-static void *brcmf_fw_nvram_strip(const struct firmware *nv, u32 *new_length,
+static void *brcmf_fw_nvram_strip(u8 *data, u32 data_len, u32 *new_length,
 				  u16 domain_nr, u16 bus_nr)
 {
 	struct nvram_parser nvp;
@@ -350,10 +378,10 @@ static void *brcmf_fw_nvram_strip(const struct firmware *nv, u32 *new_length,
 	u32 token;
 	__le32 token_le;
 
-	if (brcmf_init_nvram_parser(&nvp, nv) < 0)
+	if (brcmf_init_nvram_parser(&nvp, data, data_len) < 0)
 		return NULL;
 
-	while (nvp.pos < nv->size) {
+	while (nvp.pos < data_len) {
 		nvp.state = nv_parser_states[nvp.state](&nvp);
 		if (nvp.state == END)
 			break;
@@ -406,19 +434,34 @@ static void brcmf_fw_request_nvram_done(const struct firmware *fw, void *ctx)
 	struct brcmf_fw *fwctx = ctx;
 	u32 nvram_length = 0;
 	void *nvram = NULL;
+	u8 *data = NULL;
+	size_t data_len;
+	bool raw_nvram;
 
 	brcmf_dbg(TRACE, "enter: dev=%s\n", dev_name(fwctx->dev));
-	if (!fw && !(fwctx->flags & BRCMF_FW_REQ_NV_OPTIONAL))
-		goto fail;
+	if ((fw) && (fw->data)) {
+		data = (u8 *)fw->data;
+		data_len = fw->size;
+		raw_nvram = false;
+	} else {
+		data = brcmf_nvram_get_contents(&data_len);
+		if (!data && !(fwctx->flags & BRCMF_FW_REQ_NV_OPTIONAL))
+			goto fail;
+		raw_nvram = true;
+	}
 
-	if (fw) {
-		nvram = brcmf_fw_nvram_strip(fw, &nvram_length,
+	if (data) {
+		nvram = brcmf_fw_nvram_strip(data, (u32)data_len, &nvram_length,
 					     fwctx->domain_nr, fwctx->bus_nr);
-		release_firmware(fw);
-		if (!nvram && !(fwctx->flags & BRCMF_FW_REQ_NV_OPTIONAL))
-			goto fail;
+		if (raw_nvram)
+			brcmf_nvram_release_contents(data);
 	}
 
+	if (fw)
+		release_firmware(fw);
+	if (!nvram && !(fwctx->flags & BRCMF_FW_REQ_NV_OPTIONAL))
+		goto fail;
+
 	fwctx->done(fwctx->dev, fwctx->code, nvram, nvram_length);
 	kfree(fwctx);
 	return;
@@ -453,15 +496,9 @@ static void brcmf_fw_request_code_done(const struct firmware *fw, void *ctx)
 	if (!ret)
 		return;
 
-	/* when nvram is optional call .done() callback here */
-	if (fwctx->flags & BRCMF_FW_REQ_NV_OPTIONAL) {
-		fwctx->done(fwctx->dev, fw, NULL, 0);
-		kfree(fwctx);
-		return;
-	}
+	brcmf_fw_request_nvram_done(NULL, fwctx);
+	return;
 
-	/* failed nvram request */
-	release_firmware(fw);
 fail:
 	brcmf_dbg(TRACE, "failed: dev=%s\n", dev_name(fwctx->dev));
 	device_release_driver(fwctx->dev);
-- 
1.9.1


  parent reply	other threads:[~2015-05-20 12:09 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-20 12:09 [PATCH 0/6] brcmfmac: PCIe changes and NVRAM support Arend van Spriel
2015-05-20 12:09 ` [PATCH 1/6] brcmfmac: allow device tree node without 'interrupts' property Arend van Spriel
2015-05-26 11:10   ` [1/6] " Kalle Valo
2015-05-20 12:09 ` [PATCH 2/6] brcmfmac: Improve throughput by scheduling msbug flow worker Arend van Spriel
2015-05-20 12:09 ` [PATCH 3/6] brcmfmac: remove pci shared structure rev4 support Arend van Spriel
2015-05-20 12:09 ` [PATCH 4/6] brcmfmac: remove dummy cache flush/invalidate function Arend van Spriel
2015-05-20 12:09 ` [PATCH 5/6] brcmfmac: add support for dma indices feature Arend van Spriel
2015-05-20 12:09 ` Arend van Spriel [this message]
2015-05-20 14:33   ` [PATCH 6/6] brcmfmac: Add support for host platform NVRAM loading Rafał Miłecki
2015-05-21  8:28     ` Rafał Miłecki
2015-05-21  9:28       ` Arend van Spriel
2015-05-21  9:30         ` Arend van Spriel
2015-05-21  9:32         ` Rafał Miłecki
2015-05-21 10:16         ` Kalle Valo
2015-05-21 10:30           ` Arend van Spriel
2015-05-21 14:08             ` Kalle Valo
2015-05-20 15:02   ` Rafał Miłecki
2015-05-22  8:31     ` Arend van Spriel
2015-05-22  9:05       ` Rafał Miłecki
2015-05-22  9:20         ` Arend van Spriel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1432123792-4155-7-git-send-email-arend@broadcom.com \
    --to=arend@broadcom.com \
    --cc=kvalo@codeaurora.org \
    --cc=linux-mips@linux-mips.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=meuleman@broadcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).