Commit 11f09d4b authored by Rafał Miłecki's avatar Rafał Miłecki Committed by Kalle Valo

brcmfmac: use direct data pointer in NVRAM parser struct

As we plan to add support for platform NVRAM we should store direct
data pointer without the extra struct firmware layer. This will allow
us to support other sources with the only requirement being u8 buffer.
Signed-off-by: default avatarRafał Miłecki <zajec5@gmail.com>
Acked-by: default avatarArend van Spriel <arend@broadcom.com>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent 2dea58f6
...@@ -43,7 +43,7 @@ enum nvram_parser_state { ...@@ -43,7 +43,7 @@ enum nvram_parser_state {
* struct nvram_parser - internal info for parser. * struct nvram_parser - internal info for parser.
* *
* @state: current parser state. * @state: current parser state.
* @fwnv: input buffer being parsed. * @data: input buffer being parsed.
* @nvram: output buffer with parse result. * @nvram: output buffer with parse result.
* @nvram_len: lenght of parse result. * @nvram_len: lenght of parse result.
* @line: current line. * @line: current line.
...@@ -55,7 +55,7 @@ enum nvram_parser_state { ...@@ -55,7 +55,7 @@ enum nvram_parser_state {
*/ */
struct nvram_parser { struct nvram_parser {
enum nvram_parser_state state; enum nvram_parser_state state;
const struct firmware *fwnv; const u8 *data;
u8 *nvram; u8 *nvram;
u32 nvram_len; u32 nvram_len;
u32 line; u32 line;
...@@ -91,7 +91,7 @@ static enum nvram_parser_state brcmf_nvram_handle_idle(struct nvram_parser *nvp) ...@@ -91,7 +91,7 @@ static enum nvram_parser_state brcmf_nvram_handle_idle(struct nvram_parser *nvp)
{ {
char c; char c;
c = nvp->fwnv->data[nvp->pos]; c = nvp->data[nvp->pos];
if (c == '\n') if (c == '\n')
return COMMENT; return COMMENT;
if (is_whitespace(c)) if (is_whitespace(c))
...@@ -115,16 +115,16 @@ static enum nvram_parser_state brcmf_nvram_handle_key(struct nvram_parser *nvp) ...@@ -115,16 +115,16 @@ static enum nvram_parser_state brcmf_nvram_handle_key(struct nvram_parser *nvp)
enum nvram_parser_state st = nvp->state; enum nvram_parser_state st = nvp->state;
char c; char c;
c = nvp->fwnv->data[nvp->pos]; c = nvp->data[nvp->pos];
if (c == '=') { if (c == '=') {
/* ignore RAW1 by treating as comment */ /* 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; st = COMMENT;
else else
st = VALUE; 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; 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; nvp->multi_dev_v2 = true;
} else if (!is_nvram_char(c) || c == ' ') { } else if (!is_nvram_char(c) || c == ' ') {
brcmf_dbg(INFO, "warning: ln=%d:col=%d: '=' expected, skip invalid key entry\n", brcmf_dbg(INFO, "warning: ln=%d:col=%d: '=' expected, skip invalid key entry\n",
...@@ -145,11 +145,11 @@ brcmf_nvram_handle_value(struct nvram_parser *nvp) ...@@ -145,11 +145,11 @@ brcmf_nvram_handle_value(struct nvram_parser *nvp)
char *ekv; char *ekv;
u32 cplen; u32 cplen;
c = nvp->fwnv->data[nvp->pos]; c = nvp->data[nvp->pos];
if (!is_nvram_char(c)) { if (!is_nvram_char(c)) {
/* key,value pair complete */ /* key,value pair complete */
ekv = (u8 *)&nvp->fwnv->data[nvp->pos]; ekv = (u8 *)&nvp->data[nvp->pos];
skv = (u8 *)&nvp->fwnv->data[nvp->entry]; skv = (u8 *)&nvp->data[nvp->entry];
cplen = ekv - skv; cplen = ekv - skv;
if (nvp->nvram_len + cplen + 1 >= BRCMF_FW_MAX_NVRAM_SIZE) if (nvp->nvram_len + cplen + 1 >= BRCMF_FW_MAX_NVRAM_SIZE)
return END; return END;
...@@ -170,7 +170,7 @@ brcmf_nvram_handle_comment(struct nvram_parser *nvp) ...@@ -170,7 +170,7 @@ brcmf_nvram_handle_comment(struct nvram_parser *nvp)
{ {
char *eoc, *sol; char *eoc, *sol;
sol = (char *)&nvp->fwnv->data[nvp->pos]; sol = (char *)&nvp->data[nvp->pos];
eoc = strchr(sol, '\n'); eoc = strchr(sol, '\n');
if (!eoc) { if (!eoc) {
eoc = strchr(sol, '\0'); eoc = strchr(sol, '\0');
...@@ -201,17 +201,17 @@ static enum nvram_parser_state ...@@ -201,17 +201,17 @@ static enum nvram_parser_state
}; };
static int brcmf_init_nvram_parser(struct nvram_parser *nvp, static int brcmf_init_nvram_parser(struct nvram_parser *nvp,
const struct firmware *nv) const u8 *data, size_t data_len)
{ {
size_t size; size_t size;
memset(nvp, 0, sizeof(*nvp)); memset(nvp, 0, sizeof(*nvp));
nvp->fwnv = nv; nvp->data = data;
/* Limit size to MAX_NVRAM_SIZE, some files contain lot of comment */ /* 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; size = BRCMF_FW_MAX_NVRAM_SIZE;
else else
size = nv->size; size = data_len;
/* Alloc for extra 0 byte + roundup by 4 + length field */ /* Alloc for extra 0 byte + roundup by 4 + length field */
size += 1 + 3 + sizeof(u32); size += 1 + 3 + sizeof(u32);
nvp->nvram = kzalloc(size, GFP_KERNEL); nvp->nvram = kzalloc(size, GFP_KERNEL);
...@@ -362,18 +362,18 @@ static void brcmf_fw_strip_multi_v2(struct nvram_parser *nvp, u16 domain_nr, ...@@ -362,18 +362,18 @@ static void brcmf_fw_strip_multi_v2(struct nvram_parser *nvp, u16 domain_nr,
* and converts newlines to NULs. Shortens buffer as needed and pads with NULs. * and converts newlines to NULs. Shortens buffer as needed and pads with NULs.
* End of buffer is completed with token identifying length of buffer. * 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(const u8 *data, size_t data_len,
u16 domain_nr, u16 bus_nr) u32 *new_length, u16 domain_nr, u16 bus_nr)
{ {
struct nvram_parser nvp; struct nvram_parser nvp;
u32 pad; u32 pad;
u32 token; u32 token;
__le32 token_le; __le32 token_le;
if (brcmf_init_nvram_parser(&nvp, nv) < 0) if (brcmf_init_nvram_parser(&nvp, data, data_len) < 0)
return NULL; return NULL;
while (nvp.pos < nv->size) { while (nvp.pos < data_len) {
nvp.state = nv_parser_states[nvp.state](&nvp); nvp.state = nv_parser_states[nvp.state](&nvp);
if (nvp.state == END) if (nvp.state == END)
break; break;
...@@ -432,7 +432,7 @@ static void brcmf_fw_request_nvram_done(const struct firmware *fw, void *ctx) ...@@ -432,7 +432,7 @@ static void brcmf_fw_request_nvram_done(const struct firmware *fw, void *ctx)
goto fail; goto fail;
if (fw) { if (fw) {
nvram = brcmf_fw_nvram_strip(fw, &nvram_length, nvram = brcmf_fw_nvram_strip(fw->data, fw->size, &nvram_length,
fwctx->domain_nr, fwctx->bus_nr); fwctx->domain_nr, fwctx->bus_nr);
release_firmware(fw); release_firmware(fw);
if (!nvram && !(fwctx->flags & BRCMF_FW_REQ_NV_OPTIONAL)) if (!nvram && !(fwctx->flags & BRCMF_FW_REQ_NV_OPTIONAL))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment