sysfs: Remove support for tagged directories with untagged members (again)
[linux-btrfs-devel.git] / drivers / staging / brcm80211 / brcmsmac / alloc.c
blob7f8dd7b396bf8286bd78ce8b9dfbfabe42ae972a
1 /*
2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
17 #include <brcmu_utils.h>
18 #include "types.h"
19 #include "pub.h"
20 #include "main.h"
21 #include "alloc.h"
23 static struct brcms_bss_cfg *brcms_c_bsscfg_malloc(uint unit);
24 static void brcms_c_bsscfg_mfree(struct brcms_bss_cfg *cfg);
25 static struct brcms_pub *brcms_c_pub_malloc(uint unit,
26 uint *err, uint devid);
27 static void brcms_c_pub_mfree(struct brcms_pub *pub);
28 static void brcms_c_tunables_init(struct brcms_tunables *tunables, uint devid);
30 static void brcms_c_tunables_init(struct brcms_tunables *tunables, uint devid)
32 tunables->ntxd = NTXD;
33 tunables->nrxd = NRXD;
34 tunables->rxbufsz = RXBUFSZ;
35 tunables->nrxbufpost = NRXBUFPOST;
36 tunables->maxscb = MAXSCB;
37 tunables->ampdunummpdu = AMPDU_NUM_MPDU;
38 tunables->maxpktcb = MAXPKTCB;
39 tunables->maxucodebss = BRCMS_MAX_UCODE_BSS;
40 tunables->maxucodebss4 = BRCMS_MAX_UCODE_BSS4;
41 tunables->maxbss = MAXBSS;
42 tunables->datahiwat = BRCMS_DATAHIWAT;
43 tunables->ampdudatahiwat = BRCMS_AMPDUDATAHIWAT;
44 tunables->rxbnd = RXBND;
45 tunables->txsbnd = TXSBND;
48 static struct brcms_pub *brcms_c_pub_malloc(uint unit, uint *err, uint devid)
50 struct brcms_pub *pub;
52 pub = kzalloc(sizeof(struct brcms_pub), GFP_ATOMIC);
53 if (pub == NULL) {
54 *err = 1001;
55 goto fail;
58 pub->tunables = kzalloc(sizeof(struct brcms_tunables), GFP_ATOMIC);
59 if (pub->tunables == NULL) {
60 *err = 1028;
61 goto fail;
64 /* need to init the tunables now */
65 brcms_c_tunables_init(pub->tunables, devid);
67 pub->multicast = kzalloc(ETH_ALEN * MAXMULTILIST, GFP_ATOMIC);
68 if (pub->multicast == NULL) {
69 *err = 1003;
70 goto fail;
73 return pub;
75 fail:
76 brcms_c_pub_mfree(pub);
77 return NULL;
80 static void brcms_c_pub_mfree(struct brcms_pub *pub)
82 if (pub == NULL)
83 return;
85 kfree(pub->multicast);
86 kfree(pub->tunables);
87 kfree(pub);
90 static struct brcms_bss_cfg *brcms_c_bsscfg_malloc(uint unit)
92 struct brcms_bss_cfg *cfg;
94 cfg = kzalloc(sizeof(struct brcms_bss_cfg), GFP_ATOMIC);
95 if (cfg == NULL)
96 goto fail;
98 cfg->current_bss = kzalloc(sizeof(struct brcms_bss_info), GFP_ATOMIC);
99 if (cfg->current_bss == NULL)
100 goto fail;
102 return cfg;
104 fail:
105 brcms_c_bsscfg_mfree(cfg);
106 return NULL;
109 static void brcms_c_bsscfg_mfree(struct brcms_bss_cfg *cfg)
111 if (cfg == NULL)
112 return;
114 kfree(cfg->maclist);
115 kfree(cfg->current_bss);
116 kfree(cfg);
119 static void brcms_c_bsscfg_ID_assign(struct brcms_c_info *wlc,
120 struct brcms_bss_cfg *bsscfg)
122 bsscfg->ID = wlc->next_bsscfg_ID;
123 wlc->next_bsscfg_ID++;
127 * The common driver entry routine. Error codes should be unique
129 struct brcms_c_info *brcms_c_attach_malloc(uint unit, uint *err, uint devid)
131 struct brcms_c_info *wlc;
133 wlc = kzalloc(sizeof(struct brcms_c_info), GFP_ATOMIC);
134 if (wlc == NULL) {
135 *err = 1002;
136 goto fail;
139 /* allocate struct brcms_c_pub state structure */
140 wlc->pub = brcms_c_pub_malloc(unit, err, devid);
141 if (wlc->pub == NULL) {
142 *err = 1003;
143 goto fail;
145 wlc->pub->wlc = wlc;
147 /* allocate struct brcms_hardware state structure */
149 wlc->hw = kzalloc(sizeof(struct brcms_hardware), GFP_ATOMIC);
150 if (wlc->hw == NULL) {
151 *err = 1005;
152 goto fail;
154 wlc->hw->wlc = wlc;
156 wlc->hw->bandstate[0] =
157 kzalloc(sizeof(struct brcms_hw_band) * MAXBANDS, GFP_ATOMIC);
158 if (wlc->hw->bandstate[0] == NULL) {
159 *err = 1006;
160 goto fail;
161 } else {
162 int i;
164 for (i = 1; i < MAXBANDS; i++) {
165 wlc->hw->bandstate[i] = (struct brcms_hw_band *)
166 ((unsigned long)wlc->hw->bandstate[0] +
167 (sizeof(struct brcms_hw_band) * i));
171 wlc->modulecb =
172 kzalloc(sizeof(struct modulecb) * BRCMS_MAXMODULES, GFP_ATOMIC);
173 if (wlc->modulecb == NULL) {
174 *err = 1009;
175 goto fail;
178 wlc->default_bss = kzalloc(sizeof(struct brcms_bss_info), GFP_ATOMIC);
179 if (wlc->default_bss == NULL) {
180 *err = 1010;
181 goto fail;
184 wlc->cfg = brcms_c_bsscfg_malloc(unit);
185 if (wlc->cfg == NULL) {
186 *err = 1011;
187 goto fail;
189 brcms_c_bsscfg_ID_assign(wlc, wlc->cfg);
191 wlc->wsec_def_keys[0] =
192 kzalloc(sizeof(struct wsec_key) * BRCMS_DEFAULT_KEYS,
193 GFP_ATOMIC);
194 if (wlc->wsec_def_keys[0] == NULL) {
195 *err = 1015;
196 goto fail;
197 } else {
198 int i;
199 for (i = 1; i < BRCMS_DEFAULT_KEYS; i++) {
200 wlc->wsec_def_keys[i] = (struct wsec_key *)
201 ((unsigned long)wlc->wsec_def_keys[0] +
202 (sizeof(struct wsec_key) * i));
206 wlc->protection = kzalloc(sizeof(struct brcms_protection),
207 GFP_ATOMIC);
208 if (wlc->protection == NULL) {
209 *err = 1016;
210 goto fail;
213 wlc->stf = kzalloc(sizeof(struct brcms_stf), GFP_ATOMIC);
214 if (wlc->stf == NULL) {
215 *err = 1017;
216 goto fail;
219 wlc->bandstate[0] =
220 kzalloc(sizeof(struct brcms_band)*MAXBANDS, GFP_ATOMIC);
221 if (wlc->bandstate[0] == NULL) {
222 *err = 1025;
223 goto fail;
224 } else {
225 int i;
227 for (i = 1; i < MAXBANDS; i++) {
228 wlc->bandstate[i] = (struct brcms_band *)
229 ((unsigned long)wlc->bandstate[0]
230 + (sizeof(struct brcms_band)*i));
234 wlc->corestate = kzalloc(sizeof(struct brcms_core), GFP_ATOMIC);
235 if (wlc->corestate == NULL) {
236 *err = 1026;
237 goto fail;
240 wlc->corestate->macstat_snapshot =
241 kzalloc(sizeof(struct macstat), GFP_ATOMIC);
242 if (wlc->corestate->macstat_snapshot == NULL) {
243 *err = 1027;
244 goto fail;
247 return wlc;
249 fail:
250 brcms_c_detach_mfree(wlc);
251 return NULL;
254 void brcms_c_detach_mfree(struct brcms_c_info *wlc)
256 if (wlc == NULL)
257 return;
259 brcms_c_bsscfg_mfree(wlc->cfg);
260 brcms_c_pub_mfree(wlc->pub);
261 kfree(wlc->modulecb);
262 kfree(wlc->default_bss);
263 kfree(wlc->wsec_def_keys[0]);
264 kfree(wlc->protection);
265 kfree(wlc->stf);
266 kfree(wlc->bandstate[0]);
267 kfree(wlc->corestate->macstat_snapshot);
268 kfree(wlc->corestate);
269 kfree(wlc->hw->bandstate[0]);
270 kfree(wlc->hw);
272 /* free the wlc */
273 kfree(wlc);
274 wlc = NULL;