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.
16 #include <linux/kernel.h>
17 #include <linux/string.h>
27 #include <wlc_mac80211.h>
28 #include <wlc_alloc.h>
30 static wlc_pub_t *wlc_pub_malloc(osl_t *osh, uint unit, uint *err,
32 static void wlc_pub_mfree(osl_t *osh, wlc_pub_t *pub);
33 static void wlc_tunables_init(wlc_tunables_t *tunables, uint devid);
35 void *wlc_calloc(osl_t *osh, uint unit, uint size)
39 item = kzalloc(size, GFP_ATOMIC);
41 WL_ERROR(("wl%d: %s: out of memory\n", unit, __func__));
45 void wlc_tunables_init(wlc_tunables_t *tunables, uint devid)
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 #if defined(WLC_HIGH_ONLY) && defined(NTXD_USB_4319)
62 if (devid == BCM4319_CHIP_ID) {
63 tunables->ntxd = NTXD_USB_4319;
65 #endif /* WLC_HIGH_ONLY */
68 static wlc_pub_t *wlc_pub_malloc(osl_t *osh, uint unit, uint *err, uint devid)
72 pub = (wlc_pub_t *) wlc_calloc(osh, unit, sizeof(wlc_pub_t));
78 pub->tunables = (wlc_tunables_t *)wlc_calloc(osh, unit,
79 sizeof(wlc_tunables_t));
80 if (pub->tunables == NULL) {
85 /* need to init the tunables now */
86 wlc_tunables_init(pub->tunables, devid);
88 pub->multicast = (struct ether_addr *)wlc_calloc(osh, unit,
89 (sizeof(struct ether_addr) * MAXMULTILIST));
90 if (pub->multicast == NULL) {
98 wlc_pub_mfree(osh, pub);
102 static void wlc_pub_mfree(osl_t *osh, wlc_pub_t *pub)
108 kfree(pub->multicast);
110 kfree(pub->tunables);
111 pub->tunables = NULL;
117 wlc_bsscfg_t *wlc_bsscfg_malloc(osl_t *osh, uint unit)
121 cfg = (wlc_bsscfg_t *) wlc_calloc(osh, unit, sizeof(wlc_bsscfg_t));
125 cfg->current_bss = (wlc_bss_info_t *)wlc_calloc(osh, unit,
126 sizeof(wlc_bss_info_t));
127 if (cfg->current_bss == NULL)
133 wlc_bsscfg_mfree(osh, cfg);
137 void wlc_bsscfg_mfree(osl_t *osh, wlc_bsscfg_t *cfg)
147 if (cfg->current_bss != NULL) {
148 wlc_bss_info_t *current_bss = cfg->current_bss;
149 if (current_bss->bcn_prb != NULL)
150 kfree(current_bss->bcn_prb);
152 cfg->current_bss = NULL;
158 void wlc_bsscfg_ID_assign(wlc_info_t *wlc, wlc_bsscfg_t *bsscfg)
160 bsscfg->ID = wlc->next_bsscfg_ID;
161 wlc->next_bsscfg_ID++;
165 * The common driver entry routine. Error codes should be unique
167 wlc_info_t *wlc_attach_malloc(osl_t *osh, uint unit, uint *err, uint devid)
171 wlc = (wlc_info_t *) wlc_calloc(osh, unit, sizeof(wlc_info_t));
177 wlc->hwrxoff = WL_HWRXOFF;
179 /* allocate wlc_pub_t state structure */
180 wlc->pub = wlc_pub_malloc(osh, unit, err, devid);
181 if (wlc->pub == NULL) {
187 /* allocate wlc_hw_info_t state structure */
189 wlc->hw = (wlc_hw_info_t *)wlc_calloc(osh, unit,
190 sizeof(wlc_hw_info_t));
191 if (wlc->hw == NULL) {
198 wlc->hw->bandstate[0] = (wlc_hwband_t *)wlc_calloc(osh, unit,
199 (sizeof(wlc_hwband_t) * MAXBANDS));
200 if (wlc->hw->bandstate[0] == NULL) {
206 for (i = 1; i < MAXBANDS; i++) {
207 wlc->hw->bandstate[i] = (wlc_hwband_t *)
208 ((unsigned long)wlc->hw->bandstate[0] +
209 (sizeof(wlc_hwband_t) * i));
214 wlc->modulecb = (modulecb_t *)wlc_calloc(osh, unit,
215 sizeof(modulecb_t) * WLC_MAXMODULES);
216 if (wlc->modulecb == NULL) {
221 wlc->default_bss = (wlc_bss_info_t *)wlc_calloc(osh, unit,
222 sizeof(wlc_bss_info_t));
223 if (wlc->default_bss == NULL) {
228 wlc->cfg = wlc_bsscfg_malloc(osh, unit);
229 if (wlc->cfg == NULL) {
233 wlc_bsscfg_ID_assign(wlc, wlc->cfg);
235 wlc->pkt_callback = (pkt_cb_t *)wlc_calloc(osh, unit,
236 (sizeof(pkt_cb_t) * (wlc->pub->tunables->maxpktcb + 1)));
237 if (wlc->pkt_callback == NULL) {
242 wlc->wsec_def_keys[0] = (wsec_key_t *)wlc_calloc(osh, unit,
243 (sizeof(wsec_key_t) * WLC_DEFAULT_KEYS));
244 if (wlc->wsec_def_keys[0] == NULL) {
249 for (i = 1; i < WLC_DEFAULT_KEYS; i++) {
250 wlc->wsec_def_keys[i] = (wsec_key_t *)
251 ((unsigned long)wlc->wsec_def_keys[0] +
252 (sizeof(wsec_key_t) * i));
256 wlc->protection = (wlc_protection_t *)wlc_calloc(osh, unit,
257 sizeof(wlc_protection_t));
258 if (wlc->protection == NULL) {
263 wlc->stf = (wlc_stf_t *)wlc_calloc(osh, unit, sizeof(wlc_stf_t));
264 if (wlc->stf == NULL) {
269 wlc->bandstate[0] = (wlcband_t *)wlc_calloc(osh, unit,
270 (sizeof(wlcband_t) * MAXBANDS));
271 if (wlc->bandstate[0] == NULL) {
277 for (i = 1; i < MAXBANDS; i++) {
279 (wlcband_t *) ((unsigned long)wlc->bandstate[0] +
280 (sizeof(wlcband_t) * i));
284 wlc->corestate = (wlccore_t *)wlc_calloc(osh, unit, sizeof(wlccore_t));
285 if (wlc->corestate == NULL) {
290 wlc->corestate->macstat_snapshot =
291 (macstat_t *)wlc_calloc(osh, unit, sizeof(macstat_t));
292 if (wlc->corestate->macstat_snapshot == NULL) {
300 wlc_detach_mfree(wlc, osh);
304 void wlc_detach_mfree(wlc_info_t *wlc, osl_t *osh)
310 kfree(wlc->modulecb);
311 wlc->modulecb = NULL;
314 if (wlc->default_bss) {
315 kfree(wlc->default_bss);
316 wlc->default_bss = NULL;
319 wlc_bsscfg_mfree(osh, wlc->cfg);
323 if (wlc->pkt_callback && wlc->pub && wlc->pub->tunables) {
324 kfree(wlc->pkt_callback);
325 wlc->pkt_callback = NULL;
328 if (wlc->wsec_def_keys[0])
329 kfree(wlc->wsec_def_keys[0]);
330 if (wlc->protection) {
331 kfree(wlc->protection);
332 wlc->protection = NULL;
340 if (wlc->bandstate[0])
341 kfree(wlc->bandstate[0]);
343 if (wlc->corestate) {
344 if (wlc->corestate->macstat_snapshot) {
345 kfree(wlc->corestate->macstat_snapshot); wlc->corestate->macstat_snapshot = NULL;
347 kfree(wlc->corestate);
348 wlc->corestate = NULL;
352 /* free pub struct */
353 wlc_pub_mfree(osh, wlc->pub);
359 if (wlc->hw->bandstate[0]) {
360 kfree(wlc->hw->bandstate[0]);
361 wlc->hw->bandstate[0] = NULL;