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.
19 #include <linux/kernel.h>
20 #include <linux/string.h>
28 #include <wlc_mac80211.h>
29 #include <wlc_alloc.h>
31 static wlc_pub_t *wlc_pub_malloc(osl_t *osh, uint unit, uint *err,
33 static void wlc_pub_mfree(osl_t *osh, wlc_pub_t *pub);
34 static void wlc_tunables_init(wlc_tunables_t *tunables, uint devid);
36 void *wlc_calloc(osl_t *osh, uint unit, uint size)
40 item = MALLOC(osh, size);
42 WL_ERROR(("wl%d: %s: out of memory, malloced %d bytes\n",
43 unit, __func__, MALLOCED(osh)));
45 bzero((char *)item, size);
49 void wlc_tunables_init(wlc_tunables_t *tunables, uint devid)
51 tunables->ntxd = NTXD;
52 tunables->nrxd = NRXD;
53 tunables->rxbufsz = RXBUFSZ;
54 tunables->nrxbufpost = NRXBUFPOST;
55 tunables->maxscb = MAXSCB;
56 tunables->ampdunummpdu = AMPDU_NUM_MPDU;
57 tunables->maxpktcb = MAXPKTCB;
58 tunables->maxucodebss = WLC_MAX_UCODE_BSS;
59 tunables->maxucodebss4 = WLC_MAX_UCODE_BSS4;
60 tunables->maxbss = MAXBSS;
61 tunables->datahiwat = WLC_DATAHIWAT;
62 tunables->ampdudatahiwat = WLC_AMPDUDATAHIWAT;
63 tunables->rxbnd = RXBND;
64 tunables->txsbnd = TXSBND;
65 #if defined(WLC_HIGH_ONLY) && defined(NTXD_USB_4319)
66 if (devid == BCM4319_CHIP_ID) {
67 tunables->ntxd = NTXD_USB_4319;
69 #endif /* WLC_HIGH_ONLY */
72 static wlc_pub_t *wlc_pub_malloc(osl_t *osh, uint unit, uint *err, uint devid)
76 pub = (wlc_pub_t *) wlc_calloc(osh, unit, sizeof(wlc_pub_t));
82 pub->tunables = (wlc_tunables_t *)wlc_calloc(osh, unit,
83 sizeof(wlc_tunables_t));
84 if (pub->tunables == NULL) {
89 /* need to init the tunables now */
90 wlc_tunables_init(pub->tunables, devid);
92 pub->multicast = (struct ether_addr *)wlc_calloc(osh, unit,
93 (sizeof(struct ether_addr) * MAXMULTILIST));
94 if (pub->multicast == NULL) {
102 wlc_pub_mfree(osh, pub);
106 static void wlc_pub_mfree(osl_t *osh, wlc_pub_t *pub)
112 MFREE(osh, pub->multicast,
113 (sizeof(struct ether_addr) * MAXMULTILIST));
116 MFREE(osh, pub->tunables, sizeof(wlc_tunables_t));
117 pub->tunables = NULL;
120 MFREE(osh, pub, sizeof(wlc_pub_t));
123 wlc_bsscfg_t *wlc_bsscfg_malloc(osl_t *osh, uint unit)
127 cfg = (wlc_bsscfg_t *) wlc_calloc(osh, unit, sizeof(wlc_bsscfg_t));
131 cfg->current_bss = (wlc_bss_info_t *)wlc_calloc(osh, unit,
132 sizeof(wlc_bss_info_t));
133 if (cfg->current_bss == NULL)
139 wlc_bsscfg_mfree(osh, cfg);
143 void wlc_bsscfg_mfree(osl_t *osh, wlc_bsscfg_t *cfg)
149 MFREE(osh, cfg->maclist,
150 (int)(offsetof(struct maclist, ea) +
151 cfg->nmac * ETHER_ADDR_LEN));
155 if (cfg->current_bss != NULL) {
156 wlc_bss_info_t *current_bss = cfg->current_bss;
157 if (current_bss->bcn_prb != NULL)
158 MFREE(osh, current_bss->bcn_prb,
159 current_bss->bcn_prb_len);
160 MFREE(osh, current_bss, sizeof(wlc_bss_info_t));
161 cfg->current_bss = NULL;
164 MFREE(osh, cfg, sizeof(wlc_bsscfg_t));
167 void wlc_bsscfg_ID_assign(wlc_info_t *wlc, wlc_bsscfg_t *bsscfg)
169 bsscfg->ID = wlc->next_bsscfg_ID;
170 wlc->next_bsscfg_ID++;
174 * The common driver entry routine. Error codes should be unique
176 wlc_info_t *wlc_attach_malloc(osl_t *osh, uint unit, uint *err, uint devid)
180 wlc = (wlc_info_t *) wlc_calloc(osh, unit, sizeof(wlc_info_t));
186 wlc->hwrxoff = WL_HWRXOFF;
188 /* allocate wlc_pub_t state structure */
189 wlc->pub = wlc_pub_malloc(osh, unit, err, devid);
190 if (wlc->pub == NULL) {
196 /* allocate wlc_hw_info_t state structure */
198 wlc->hw = (wlc_hw_info_t *)wlc_calloc(osh, unit,
199 sizeof(wlc_hw_info_t));
200 if (wlc->hw == NULL) {
207 wlc->hw->bandstate[0] = (wlc_hwband_t *)wlc_calloc(osh, unit,
208 (sizeof(wlc_hwband_t) * MAXBANDS));
209 if (wlc->hw->bandstate[0] == NULL) {
215 for (i = 1; i < MAXBANDS; i++) {
216 wlc->hw->bandstate[i] = (wlc_hwband_t *)
217 ((uintptr) wlc->hw->bandstate[0] +
218 (sizeof(wlc_hwband_t) * i));
223 wlc->modulecb = (modulecb_t *)wlc_calloc(osh, unit,
224 sizeof(modulecb_t) * WLC_MAXMODULES);
225 if (wlc->modulecb == NULL) {
230 wlc->default_bss = (wlc_bss_info_t *)wlc_calloc(osh, unit,
231 sizeof(wlc_bss_info_t));
232 if (wlc->default_bss == NULL) {
237 wlc->cfg = wlc_bsscfg_malloc(osh, unit);
238 if (wlc->cfg == NULL) {
242 wlc_bsscfg_ID_assign(wlc, wlc->cfg);
244 wlc->pkt_callback = (pkt_cb_t *)wlc_calloc(osh, unit,
245 (sizeof(pkt_cb_t) * (wlc->pub->tunables->maxpktcb + 1)));
246 if (wlc->pkt_callback == NULL) {
251 wlc->wsec_def_keys[0] = (wsec_key_t *)wlc_calloc(osh, unit,
252 (sizeof(wsec_key_t) * WLC_DEFAULT_KEYS));
253 if (wlc->wsec_def_keys[0] == NULL) {
258 for (i = 1; i < WLC_DEFAULT_KEYS; i++) {
259 wlc->wsec_def_keys[i] = (wsec_key_t *)
260 ((uintptr) wlc->wsec_def_keys[0] +
261 (sizeof(wsec_key_t) * i));
265 wlc->protection = (wlc_protection_t *)wlc_calloc(osh, unit,
266 sizeof(wlc_protection_t));
267 if (wlc->protection == NULL) {
272 wlc->stf = (wlc_stf_t *)wlc_calloc(osh, unit, sizeof(wlc_stf_t));
273 if (wlc->stf == NULL) {
278 wlc->bandstate[0] = (wlcband_t *)wlc_calloc(osh, unit,
279 (sizeof(wlcband_t) * MAXBANDS));
280 if (wlc->bandstate[0] == NULL) {
286 for (i = 1; i < MAXBANDS; i++) {
288 (wlcband_t *) ((uintptr) wlc->bandstate[0] +
289 (sizeof(wlcband_t) * i));
293 wlc->corestate = (wlccore_t *)wlc_calloc(osh, unit, sizeof(wlccore_t));
294 if (wlc->corestate == NULL) {
299 wlc->corestate->macstat_snapshot =
300 (macstat_t *)wlc_calloc(osh, unit, sizeof(macstat_t));
301 if (wlc->corestate->macstat_snapshot == NULL) {
309 wlc_detach_mfree(wlc, osh);
313 void wlc_detach_mfree(wlc_info_t *wlc, osl_t *osh)
319 MFREE(osh, wlc->modulecb, sizeof(modulecb_t) * WLC_MAXMODULES);
320 wlc->modulecb = NULL;
323 if (wlc->default_bss) {
324 MFREE(osh, wlc->default_bss, sizeof(wlc_bss_info_t));
325 wlc->default_bss = NULL;
328 wlc_bsscfg_mfree(osh, wlc->cfg);
332 if (wlc->pkt_callback && wlc->pub && wlc->pub->tunables) {
335 sizeof(pkt_cb_t) * (wlc->pub->tunables->maxpktcb + 1));
336 wlc->pkt_callback = NULL;
339 if (wlc->wsec_def_keys[0])
340 MFREE(osh, wlc->wsec_def_keys[0],
341 (sizeof(wsec_key_t) * WLC_DEFAULT_KEYS));
343 if (wlc->protection) {
344 MFREE(osh, wlc->protection, sizeof(wlc_protection_t));
345 wlc->protection = NULL;
349 MFREE(osh, wlc->stf, sizeof(wlc_stf_t));
353 if (wlc->bandstate[0])
354 MFREE(osh, wlc->bandstate[0], (sizeof(wlcband_t) * MAXBANDS));
356 if (wlc->corestate) {
357 if (wlc->corestate->macstat_snapshot) {
358 MFREE(osh, wlc->corestate->macstat_snapshot,
360 wlc->corestate->macstat_snapshot = NULL;
362 MFREE(osh, wlc->corestate, sizeof(wlccore_t));
363 wlc->corestate = NULL;
367 /* free pub struct */
368 wlc_pub_mfree(osh, wlc->pub);
374 if (wlc->hw->bandstate[0]) {
375 MFREE(osh, wlc->hw->bandstate[0],
376 (sizeof(wlc_hwband_t) * MAXBANDS));
377 wlc->hw->bandstate[0] = NULL;
382 MFREE(osh, wlc->hw, sizeof(wlc_hw_info_t));
387 MFREE(osh, wlc, sizeof(wlc_info_t));