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