]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/staging/brcm80211/brcmsmac/alloc.c
staging: brcm80211: removed keys.h
[mv-sheeva.git] / drivers / staging / brcm80211 / brcmsmac / alloc.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 #include <linux/kernel.h>
17 #include <linux/types.h>
18
19 #include <defs.h>
20 #include <brcmu_utils.h>
21 #include <aiutils.h>
22 #include "dma.h"
23
24 #include "d11.h"
25 #include "types.h"
26 #include "scb.h"
27 #include "pub.h"
28 #include "alloc.h"
29 #include "rate.h"
30 #include "phy/phy_hal.h"
31 #include "channel.h"
32 #include "main.h"
33
34 static struct wlc_bsscfg *wlc_bsscfg_malloc(uint unit);
35 static void wlc_bsscfg_mfree(struct wlc_bsscfg *cfg);
36 static struct wlc_pub *wlc_pub_malloc(uint unit,
37                                       uint *err, uint devid);
38 static void wlc_pub_mfree(struct wlc_pub *pub);
39 static void wlc_tunables_init(wlc_tunables_t *tunables, uint devid);
40
41 static void wlc_tunables_init(wlc_tunables_t *tunables, uint devid)
42 {
43         tunables->ntxd = NTXD;
44         tunables->nrxd = NRXD;
45         tunables->rxbufsz = RXBUFSZ;
46         tunables->nrxbufpost = NRXBUFPOST;
47         tunables->maxscb = MAXSCB;
48         tunables->ampdunummpdu = AMPDU_NUM_MPDU;
49         tunables->maxpktcb = MAXPKTCB;
50         tunables->maxucodebss = WLC_MAX_UCODE_BSS;
51         tunables->maxucodebss4 = WLC_MAX_UCODE_BSS4;
52         tunables->maxbss = MAXBSS;
53         tunables->datahiwat = WLC_DATAHIWAT;
54         tunables->ampdudatahiwat = WLC_AMPDUDATAHIWAT;
55         tunables->rxbnd = RXBND;
56         tunables->txsbnd = TXSBND;
57 }
58
59 static struct wlc_pub *wlc_pub_malloc(uint unit, uint *err, uint devid)
60 {
61         struct wlc_pub *pub;
62
63         pub = kzalloc(sizeof(struct wlc_pub), GFP_ATOMIC);
64         if (pub == NULL) {
65                 *err = 1001;
66                 goto fail;
67         }
68
69         pub->tunables = kzalloc(sizeof(wlc_tunables_t), GFP_ATOMIC);
70         if (pub->tunables == NULL) {
71                 *err = 1028;
72                 goto fail;
73         }
74
75         /* need to init the tunables now */
76         wlc_tunables_init(pub->tunables, devid);
77
78         pub->multicast = kzalloc(ETH_ALEN * MAXMULTILIST, GFP_ATOMIC);
79         if (pub->multicast == NULL) {
80                 *err = 1003;
81                 goto fail;
82         }
83
84         return pub;
85
86  fail:
87         wlc_pub_mfree(pub);
88         return NULL;
89 }
90
91 static void wlc_pub_mfree(struct wlc_pub *pub)
92 {
93         if (pub == NULL)
94                 return;
95
96         kfree(pub->multicast);
97         kfree(pub->tunables);
98         kfree(pub);
99 }
100
101 static struct wlc_bsscfg *wlc_bsscfg_malloc(uint unit)
102 {
103         struct wlc_bsscfg *cfg;
104
105         cfg = kzalloc(sizeof(struct wlc_bsscfg), GFP_ATOMIC);
106         if (cfg == NULL)
107                 goto fail;
108
109         cfg->current_bss = kzalloc(sizeof(wlc_bss_info_t), GFP_ATOMIC);
110         if (cfg->current_bss == NULL)
111                 goto fail;
112
113         return cfg;
114
115  fail:
116         wlc_bsscfg_mfree(cfg);
117         return NULL;
118 }
119
120 static void wlc_bsscfg_mfree(struct wlc_bsscfg *cfg)
121 {
122         if (cfg == NULL)
123                 return;
124
125         kfree(cfg->maclist);
126         kfree(cfg->current_bss);
127         kfree(cfg);
128 }
129
130 static void wlc_bsscfg_ID_assign(struct wlc_info *wlc,
131                                  struct wlc_bsscfg *bsscfg)
132 {
133         bsscfg->ID = wlc->next_bsscfg_ID;
134         wlc->next_bsscfg_ID++;
135 }
136
137 /*
138  * The common driver entry routine. Error codes should be unique
139  */
140 struct wlc_info *wlc_attach_malloc(uint unit, uint *err, uint devid)
141 {
142         struct wlc_info *wlc;
143
144         wlc = kzalloc(sizeof(struct wlc_info), GFP_ATOMIC);
145         if (wlc == NULL) {
146                 *err = 1002;
147                 goto fail;
148         }
149
150         /* allocate struct wlc_pub state structure */
151         wlc->pub = wlc_pub_malloc(unit, err, devid);
152         if (wlc->pub == NULL) {
153                 *err = 1003;
154                 goto fail;
155         }
156         wlc->pub->wlc = wlc;
157
158         /* allocate struct wlc_hw_info state structure */
159
160         wlc->hw = kzalloc(sizeof(struct wlc_hw_info), GFP_ATOMIC);
161         if (wlc->hw == NULL) {
162                 *err = 1005;
163                 goto fail;
164         }
165         wlc->hw->wlc = wlc;
166
167         wlc->hw->bandstate[0] =
168                 kzalloc(sizeof(struct wlc_hwband) * MAXBANDS, GFP_ATOMIC);
169         if (wlc->hw->bandstate[0] == NULL) {
170                 *err = 1006;
171                 goto fail;
172         } else {
173                 int i;
174
175                 for (i = 1; i < MAXBANDS; i++) {
176                         wlc->hw->bandstate[i] = (struct wlc_hwband *)
177                             ((unsigned long)wlc->hw->bandstate[0] +
178                              (sizeof(struct wlc_hwband) * i));
179                 }
180         }
181
182         wlc->modulecb =
183                 kzalloc(sizeof(struct modulecb) * WLC_MAXMODULES, GFP_ATOMIC);
184         if (wlc->modulecb == NULL) {
185                 *err = 1009;
186                 goto fail;
187         }
188
189         wlc->default_bss = kzalloc(sizeof(wlc_bss_info_t), GFP_ATOMIC);
190         if (wlc->default_bss == NULL) {
191                 *err = 1010;
192                 goto fail;
193         }
194
195         wlc->cfg = wlc_bsscfg_malloc(unit);
196         if (wlc->cfg == NULL) {
197                 *err = 1011;
198                 goto fail;
199         }
200         wlc_bsscfg_ID_assign(wlc, wlc->cfg);
201
202         wlc->wsec_def_keys[0] =
203                 kzalloc(sizeof(wsec_key_t) * WLC_DEFAULT_KEYS, GFP_ATOMIC);
204         if (wlc->wsec_def_keys[0] == NULL) {
205                 *err = 1015;
206                 goto fail;
207         } else {
208                 int i;
209                 for (i = 1; i < WLC_DEFAULT_KEYS; i++) {
210                         wlc->wsec_def_keys[i] = (wsec_key_t *)
211                             ((unsigned long)wlc->wsec_def_keys[0] +
212                              (sizeof(wsec_key_t) * i));
213                 }
214         }
215
216         wlc->protection = kzalloc(sizeof(struct wlc_protection), GFP_ATOMIC);
217         if (wlc->protection == NULL) {
218                 *err = 1016;
219                 goto fail;
220         }
221
222         wlc->stf = kzalloc(sizeof(struct wlc_stf), GFP_ATOMIC);
223         if (wlc->stf == NULL) {
224                 *err = 1017;
225                 goto fail;
226         }
227
228         wlc->bandstate[0] =
229                 kzalloc(sizeof(struct wlcband)*MAXBANDS, GFP_ATOMIC);
230         if (wlc->bandstate[0] == NULL) {
231                 *err = 1025;
232                 goto fail;
233         } else {
234                 int i;
235
236                 for (i = 1; i < MAXBANDS; i++) {
237                         wlc->bandstate[i] =
238                             (struct wlcband *) ((unsigned long)wlc->bandstate[0]
239                             + (sizeof(struct wlcband)*i));
240                 }
241         }
242
243         wlc->corestate = kzalloc(sizeof(struct wlccore), GFP_ATOMIC);
244         if (wlc->corestate == NULL) {
245                 *err = 1026;
246                 goto fail;
247         }
248
249         wlc->corestate->macstat_snapshot =
250                 kzalloc(sizeof(macstat_t), GFP_ATOMIC);
251         if (wlc->corestate->macstat_snapshot == NULL) {
252                 *err = 1027;
253                 goto fail;
254         }
255
256         return wlc;
257
258  fail:
259         wlc_detach_mfree(wlc);
260         return NULL;
261 }
262
263 void wlc_detach_mfree(struct wlc_info *wlc)
264 {
265         if (wlc == NULL)
266                 return;
267
268         wlc_bsscfg_mfree(wlc->cfg);
269         wlc_pub_mfree(wlc->pub);
270         kfree(wlc->modulecb);
271         kfree(wlc->default_bss);
272         kfree(wlc->wsec_def_keys[0]);
273         kfree(wlc->protection);
274         kfree(wlc->stf);
275         kfree(wlc->bandstate[0]);
276         kfree(wlc->corestate->macstat_snapshot);
277         kfree(wlc->corestate);
278         kfree(wlc->hw->bandstate[0]);
279         kfree(wlc->hw);
280
281         /* free the wlc */
282         kfree(wlc);
283         wlc = NULL;
284 }