727dcbe85a82c2e997e9e65304913b7d97d343ed
[openwrt/staging/stintel.git] /
1 From eae8e50669e15002b195177212a6e25afbe7cf4d Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Wed, 10 Oct 2018 13:01:00 +0200
4 Subject: [PATCH] brcmfmac: Add support for first trying to get a board
5 specific nvram file
6
7 The nvram files which some brcmfmac chips need are board-specific. To be
8 able to distribute these as part of linux-firmware, so that devices with
9 such a wifi chip will work OOTB, multiple (one per board) versions must
10 co-exist under /lib/firmware.
11
12 This commit adds support for callers of the brcmfmac/firmware.c code to
13 pass in a board_type parameter through the request structure.
14
15 If that parameter is set then the code will first try to load
16 chipmodel.board_type.txt before falling back to the old chipmodel.txt name.
17
18 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
19 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
20 ---
21 .../broadcom/brcm80211/brcmfmac/firmware.c | 27 +++++++++++++++++++++-
22 .../broadcom/brcm80211/brcmfmac/firmware.h | 1 +
23 2 files changed, 27 insertions(+), 1 deletion(-)
24
25 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
26 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
27 @@ -532,6 +532,31 @@ static int brcmf_fw_complete_request(con
28 return (cur->flags & BRCMF_FW_REQF_OPTIONAL) ? 0 : ret;
29 }
30
31 +static int brcmf_fw_request_firmware(const struct firmware **fw,
32 + struct brcmf_fw *fwctx)
33 +{
34 + struct brcmf_fw_item *cur = &fwctx->req->items[fwctx->curpos];
35 + int ret;
36 +
37 + /* nvram files are board-specific, first try a board-specific path */
38 + if (cur->type == BRCMF_FW_TYPE_NVRAM && fwctx->req->board_type) {
39 + char alt_path[BRCMF_FW_NAME_LEN];
40 +
41 + strlcpy(alt_path, cur->path, BRCMF_FW_NAME_LEN);
42 + /* strip .txt at the end */
43 + alt_path[strlen(alt_path) - 4] = 0;
44 + strlcat(alt_path, ".", BRCMF_FW_NAME_LEN);
45 + strlcat(alt_path, fwctx->req->board_type, BRCMF_FW_NAME_LEN);
46 + strlcat(alt_path, ".txt", BRCMF_FW_NAME_LEN);
47 +
48 + ret = request_firmware(fw, alt_path, fwctx->dev);
49 + if (ret == 0)
50 + return ret;
51 + }
52 +
53 + return request_firmware(fw, cur->path, fwctx->dev);
54 +}
55 +
56 static void brcmf_fw_request_done(const struct firmware *fw, void *ctx)
57 {
58 struct brcmf_fw *fwctx = ctx;
59 @@ -544,7 +569,7 @@ static void brcmf_fw_request_done(const
60
61 while (ret == 0 && ++fwctx->curpos < fwctx->req->n_items) {
62 cur = &fwctx->req->items[fwctx->curpos];
63 - request_firmware(&fw, cur->path, fwctx->dev);
64 + brcmf_fw_request_firmware(&fw, fwctx);
65 ret = brcmf_fw_complete_request(fw, ctx);
66 }
67
68 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.h
69 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.h
70 @@ -70,6 +70,7 @@ struct brcmf_fw_request {
71 u16 domain_nr;
72 u16 bus_nr;
73 u32 n_items;
74 + const char *board_type;
75 struct brcmf_fw_item items[0];
76 };
77