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>
20 #include <linux/module.h>
21 #include <linux/pci.h>
30 #include <wlc_event.h>
31 #include <wlc_mac80211.h>
32 #include <wlc_alloc.h>
35 static struct wlc_pub *wlc_pub_malloc(struct osl_info *osh, uint unit,
36 uint *err, uint devid);
37 static void wlc_pub_mfree(struct osl_info *osh, struct wlc_pub *pub);
38 static void wlc_tunables_init(wlc_tunables_t *tunables, uint devid);
40 void *wlc_calloc(struct osl_info *osh, uint unit, uint size)
44 item = kzalloc(size, GFP_ATOMIC);
46 WL_ERROR("wl%d: %s: out of memory\n", unit, __func__);
50 void wlc_tunables_init(wlc_tunables_t *tunables, uint devid)
52 tunables->ntxd = NTXD;
53 tunables->nrxd = NRXD;
54 tunables->rxbufsz = RXBUFSZ;
55 tunables->nrxbufpost = NRXBUFPOST;
56 tunables->maxscb = MAXSCB;
57 tunables->ampdunummpdu = AMPDU_NUM_MPDU;
58 tunables->maxpktcb = MAXPKTCB;
59 tunables->maxucodebss = WLC_MAX_UCODE_BSS;
60 tunables->maxucodebss4 = WLC_MAX_UCODE_BSS4;
61 tunables->maxbss = MAXBSS;
62 tunables->datahiwat = WLC_DATAHIWAT;
63 tunables->ampdudatahiwat = WLC_AMPDUDATAHIWAT;
64 tunables->rxbnd = RXBND;
65 tunables->txsbnd = TXSBND;
68 static struct wlc_pub *wlc_pub_malloc(struct osl_info *osh, uint unit,
69 uint *err, uint devid)
73 pub = (struct wlc_pub *) wlc_calloc(osh, unit, sizeof(struct wlc_pub));
79 pub->tunables = (wlc_tunables_t *)wlc_calloc(osh, unit,
80 sizeof(wlc_tunables_t));
81 if (pub->tunables == NULL) {
86 /* need to init the tunables now */
87 wlc_tunables_init(pub->tunables, devid);
89 pub->multicast = (struct ether_addr *)wlc_calloc(osh, unit,
90 (sizeof(struct ether_addr) * MAXMULTILIST));
91 if (pub->multicast == NULL) {
99 wlc_pub_mfree(osh, pub);
103 static void wlc_pub_mfree(struct osl_info *osh, struct wlc_pub *pub)
109 kfree(pub->multicast);
111 kfree(pub->tunables);
112 pub->tunables = NULL;
118 wlc_bsscfg_t *wlc_bsscfg_malloc(struct osl_info *osh, uint unit)
122 cfg = (wlc_bsscfg_t *) wlc_calloc(osh, unit, sizeof(wlc_bsscfg_t));
126 cfg->current_bss = (wlc_bss_info_t *)wlc_calloc(osh, unit,
127 sizeof(wlc_bss_info_t));
128 if (cfg->current_bss == NULL)
134 wlc_bsscfg_mfree(osh, cfg);
138 void wlc_bsscfg_mfree(struct osl_info *osh, wlc_bsscfg_t *cfg)
148 if (cfg->current_bss != NULL) {
149 wlc_bss_info_t *current_bss = cfg->current_bss;
150 if (current_bss->bcn_prb != NULL)
151 kfree(current_bss->bcn_prb);
153 cfg->current_bss = NULL;
159 void wlc_bsscfg_ID_assign(struct wlc_info *wlc, wlc_bsscfg_t *bsscfg)
161 bsscfg->ID = wlc->next_bsscfg_ID;
162 wlc->next_bsscfg_ID++;
166 * The common driver entry routine. Error codes should be unique
168 struct wlc_info *wlc_attach_malloc(struct osl_info *osh, uint unit, uint *err,
171 struct wlc_info *wlc;
173 wlc = (struct wlc_info *) wlc_calloc(osh, unit,
174 sizeof(struct wlc_info));
180 wlc->hwrxoff = WL_HWRXOFF;
182 /* allocate struct wlc_pub state structure */
183 wlc->pub = wlc_pub_malloc(osh, unit, err, devid);
184 if (wlc->pub == NULL) {
190 /* allocate struct wlc_hw_info state structure */
192 wlc->hw = (struct wlc_hw_info *)wlc_calloc(osh, unit,
193 sizeof(struct wlc_hw_info));
194 if (wlc->hw == NULL) {
200 wlc->hw->bandstate[0] = (wlc_hwband_t *)wlc_calloc(osh, unit,
201 (sizeof(wlc_hwband_t) * MAXBANDS));
202 if (wlc->hw->bandstate[0] == NULL) {
208 for (i = 1; i < MAXBANDS; i++) {
209 wlc->hw->bandstate[i] = (wlc_hwband_t *)
210 ((unsigned long)wlc->hw->bandstate[0] +
211 (sizeof(wlc_hwband_t) * i));
215 wlc->modulecb = (modulecb_t *)wlc_calloc(osh, unit,
216 sizeof(modulecb_t) * WLC_MAXMODULES);
217 if (wlc->modulecb == NULL) {
222 wlc->default_bss = (wlc_bss_info_t *)wlc_calloc(osh, unit,
223 sizeof(wlc_bss_info_t));
224 if (wlc->default_bss == NULL) {
229 wlc->cfg = wlc_bsscfg_malloc(osh, unit);
230 if (wlc->cfg == NULL) {
234 wlc_bsscfg_ID_assign(wlc, wlc->cfg);
236 wlc->pkt_callback = (pkt_cb_t *)wlc_calloc(osh, unit,
237 (sizeof(pkt_cb_t) * (wlc->pub->tunables->maxpktcb + 1)));
238 if (wlc->pkt_callback == NULL) {
243 wlc->wsec_def_keys[0] = (wsec_key_t *)wlc_calloc(osh, unit,
244 (sizeof(wsec_key_t) * WLC_DEFAULT_KEYS));
245 if (wlc->wsec_def_keys[0] == NULL) {
250 for (i = 1; i < WLC_DEFAULT_KEYS; i++) {
251 wlc->wsec_def_keys[i] = (wsec_key_t *)
252 ((unsigned long)wlc->wsec_def_keys[0] +
253 (sizeof(wsec_key_t) * i));
257 wlc->protection = (wlc_protection_t *)wlc_calloc(osh, unit,
258 sizeof(wlc_protection_t));
259 if (wlc->protection == NULL) {
264 wlc->stf = (wlc_stf_t *)wlc_calloc(osh, unit, sizeof(wlc_stf_t));
265 if (wlc->stf == NULL) {
270 wlc->bandstate[0] = (struct wlcband *)wlc_calloc(osh, unit,
271 (sizeof(struct wlcband)*MAXBANDS));
272 if (wlc->bandstate[0] == NULL) {
278 for (i = 1; i < MAXBANDS; i++) {
280 (struct wlcband *) ((unsigned long)wlc->bandstate[0]
281 + (sizeof(struct wlcband)*i));
285 wlc->corestate = (struct wlccore *)wlc_calloc(osh, unit,
286 sizeof(struct wlccore));
287 if (wlc->corestate == NULL) {
292 wlc->corestate->macstat_snapshot =
293 (macstat_t *)wlc_calloc(osh, unit, sizeof(macstat_t));
294 if (wlc->corestate->macstat_snapshot == NULL) {
302 wlc_detach_mfree(wlc, osh);
306 void wlc_detach_mfree(struct wlc_info *wlc, struct osl_info *osh)
312 kfree(wlc->modulecb);
313 wlc->modulecb = NULL;
316 if (wlc->default_bss) {
317 kfree(wlc->default_bss);
318 wlc->default_bss = NULL;
321 wlc_bsscfg_mfree(osh, wlc->cfg);
325 if (wlc->pkt_callback && wlc->pub && wlc->pub->tunables) {
326 kfree(wlc->pkt_callback);
327 wlc->pkt_callback = NULL;
330 if (wlc->wsec_def_keys[0])
331 kfree(wlc->wsec_def_keys[0]);
332 if (wlc->protection) {
333 kfree(wlc->protection);
334 wlc->protection = NULL;
342 if (wlc->bandstate[0])
343 kfree(wlc->bandstate[0]);
345 if (wlc->corestate) {
346 if (wlc->corestate->macstat_snapshot) {
347 kfree(wlc->corestate->macstat_snapshot); wlc->corestate->macstat_snapshot = NULL;
349 kfree(wlc->corestate);
350 wlc->corestate = NULL;
354 /* free pub struct */
355 wlc_pub_mfree(osh, wlc->pub);
360 if (wlc->hw->bandstate[0]) {
361 kfree(wlc->hw->bandstate[0]);
362 wlc->hw->bandstate[0] = NULL;