staging: brcm80211: improved checks on incompatible firmware
[firefly-linux-kernel-4.4.55.git] / drivers / staging / brcm80211 / brcmsmac / wl_ucode_loader.c
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #include <linux/types.h>
18 #include <bcmdefs.h>
19 #include <d11ucode_ext.h>
20 #include <wl_ucode.h>
21
22
23
24 d11init_t *d11lcn0bsinitvals24;
25 d11init_t *d11lcn0initvals24;
26 d11init_t *d11lcn1bsinitvals24;
27 d11init_t *d11lcn1initvals24;
28 d11init_t *d11lcn2bsinitvals24;
29 d11init_t *d11lcn2initvals24;
30 d11init_t *d11n0absinitvals16;
31 d11init_t *d11n0bsinitvals16;
32 d11init_t *d11n0initvals16;
33 u32 *bcm43xx_16_mimo;
34 u32 bcm43xx_16_mimosz;
35 u32 *bcm43xx_24_lcn;
36 u32 bcm43xx_24_lcnsz;
37 u32 *bcm43xx_bommajor;
38 u32 *bcm43xx_bomminor;
39
40 int wl_ucode_data_init(struct wl_info *wl)
41 {
42         int rc;
43         rc = wl_check_firmwares(wl);
44
45         rc = rc < 0 ? rc : wl_ucode_init_buf(wl, (void **)&d11lcn0bsinitvals24,
46                                              D11LCN0BSINITVALS24);
47         rc = rc < 0 ? rc : wl_ucode_init_buf(wl, (void **)&d11lcn0initvals24,
48                                              D11LCN0INITVALS24);
49         rc = rc < 0 ? rc : wl_ucode_init_buf(wl, (void **)&d11lcn1bsinitvals24,
50                                              D11LCN1BSINITVALS24);
51         rc = rc < 0 ? rc : wl_ucode_init_buf(wl, (void **)&d11lcn1initvals24,
52                                              D11LCN1INITVALS24);
53         rc = rc < 0 ? rc : wl_ucode_init_buf(wl, (void **)&d11lcn2bsinitvals24,
54                                              D11LCN2BSINITVALS24);
55         rc = rc < 0 ? rc : wl_ucode_init_buf(wl, (void **)&d11lcn2initvals24,
56                                              D11LCN2INITVALS24);
57         rc = rc < 0 ? rc : wl_ucode_init_buf(wl, (void **)&d11n0absinitvals16,
58                                              D11N0ABSINITVALS16);
59         rc = rc < 0 ? rc : wl_ucode_init_buf(wl, (void **)&d11n0bsinitvals16,
60                                              D11N0BSINITVALS16);
61         rc = rc < 0 ? rc : wl_ucode_init_buf(wl, (void **)&d11n0initvals16,
62                                              D11N0INITVALS16);
63         rc = rc < 0 ? rc : wl_ucode_init_buf(wl, (void **)&bcm43xx_16_mimo,
64                                              D11UCODE_OVERSIGHT16_MIMO);
65         rc = rc < 0 ? rc : wl_ucode_init_uint(wl, &bcm43xx_16_mimosz,
66                                               D11UCODE_OVERSIGHT16_MIMOSZ);
67         rc = rc < 0 ? rc : wl_ucode_init_buf(wl, (void **)&bcm43xx_24_lcn,
68                                              D11UCODE_OVERSIGHT24_LCN);
69         rc = rc < 0 ? rc : wl_ucode_init_uint(wl, &bcm43xx_24_lcnsz,
70                                               D11UCODE_OVERSIGHT24_LCNSZ);
71         rc = rc < 0 ? rc : wl_ucode_init_buf(wl, (void **)&bcm43xx_bommajor,
72                                              D11UCODE_OVERSIGHT_BOMMAJOR);
73         rc = rc < 0 ? rc : wl_ucode_init_buf(wl, (void **)&bcm43xx_bomminor,
74                                              D11UCODE_OVERSIGHT_BOMMINOR);
75         return rc;
76 }
77
78 void wl_ucode_data_free(void)
79 {
80         wl_ucode_free_buf((void *)d11lcn0bsinitvals24);
81         wl_ucode_free_buf((void *)d11lcn0initvals24);
82         wl_ucode_free_buf((void *)d11lcn1bsinitvals24);
83         wl_ucode_free_buf((void *)d11lcn1initvals24);
84         wl_ucode_free_buf((void *)d11lcn2bsinitvals24);
85         wl_ucode_free_buf((void *)d11lcn2initvals24);
86         wl_ucode_free_buf((void *)d11n0absinitvals16);
87         wl_ucode_free_buf((void *)d11n0bsinitvals16);
88         wl_ucode_free_buf((void *)d11n0initvals16);
89         wl_ucode_free_buf((void *)bcm43xx_16_mimo);
90         wl_ucode_free_buf((void *)bcm43xx_24_lcn);
91         wl_ucode_free_buf((void *)bcm43xx_bommajor);
92         wl_ucode_free_buf((void *)bcm43xx_bomminor);
93
94         return;
95 }