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>
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);
58 pub->tunables = kzalloc(sizeof(struct brcms_tunables), GFP_ATOMIC);
59 if (pub->tunables == NULL) {
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) {
76 brcms_c_pub_mfree(pub);
80 static void brcms_c_pub_mfree(struct brcms_pub *pub)
85 kfree(pub->multicast);
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);
98 cfg->current_bss = kzalloc(sizeof(struct brcms_bss_info), GFP_ATOMIC);
99 if (cfg->current_bss == NULL)
105 brcms_c_bsscfg_mfree(cfg);
109 static void brcms_c_bsscfg_mfree(struct brcms_bss_cfg *cfg)
115 kfree(cfg->current_bss);
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);
139 /* allocate struct brcms_c_pub state structure */
140 wlc->pub = brcms_c_pub_malloc(unit, err, devid);
141 if (wlc->pub == NULL) {
147 /* allocate struct brcms_hardware state structure */
149 wlc->hw = kzalloc(sizeof(struct brcms_hardware), GFP_ATOMIC);
150 if (wlc->hw == NULL) {
156 wlc->hw->bandstate[0] =
157 kzalloc(sizeof(struct brcms_hw_band) * MAXBANDS, GFP_ATOMIC);
158 if (wlc->hw->bandstate[0] == NULL) {
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));
172 kzalloc(sizeof(struct modulecb) * BRCMS_MAXMODULES, GFP_ATOMIC);
173 if (wlc->modulecb == NULL) {
178 wlc->default_bss = kzalloc(sizeof(struct brcms_bss_info), GFP_ATOMIC);
179 if (wlc->default_bss == NULL) {
184 wlc->cfg = brcms_c_bsscfg_malloc(unit);
185 if (wlc->cfg == NULL) {
189 brcms_c_bsscfg_ID_assign(wlc, wlc->cfg);
191 wlc->wsec_def_keys[0] =
192 kzalloc(sizeof(struct wsec_key) * BRCMS_DEFAULT_KEYS,
194 if (wlc->wsec_def_keys[0] == NULL) {
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),
208 if (wlc->protection == NULL) {
213 wlc->stf = kzalloc(sizeof(struct brcms_stf), GFP_ATOMIC);
214 if (wlc->stf == NULL) {
220 kzalloc(sizeof(struct brcms_band)*MAXBANDS, GFP_ATOMIC);
221 if (wlc->bandstate[0] == NULL) {
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) {
240 wlc->corestate->macstat_snapshot =
241 kzalloc(sizeof(struct macstat), GFP_ATOMIC);
242 if (wlc->corestate->macstat_snapshot == NULL) {
250 brcms_c_detach_mfree(wlc);
254 void brcms_c_detach_mfree(struct brcms_c_info *wlc)
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);
266 kfree(wlc->bandstate[0]);
267 kfree(wlc->corestate->macstat_snapshot);
268 kfree(wlc->corestate);
269 kfree(wlc->hw->bandstate[0]);