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