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/types.h>
27 #include "wlc_types.h"
32 #include "wlc_alloc.h"
35 #include "wlc_bsscfg.h"
36 #include "phy/wlc_phy_hal.h"
37 #include "wlc_channel.h"
38 #include "wlc_mac80211.h"
40 static struct wlc_bsscfg *wlc_bsscfg_malloc(struct osl_info *osh, uint unit);
41 static void wlc_bsscfg_mfree(struct osl_info *osh, struct wlc_bsscfg *cfg);
42 static struct wlc_pub *wlc_pub_malloc(struct osl_info *osh, uint unit,
43 uint *err, uint devid);
44 static void wlc_pub_mfree(struct osl_info *osh, struct wlc_pub *pub);
45 static void wlc_tunables_init(wlc_tunables_t *tunables, uint devid);
47 void *wlc_calloc(struct osl_info *osh, uint unit, uint size)
51 item = kzalloc(size, GFP_ATOMIC);
53 WL_ERROR("wl%d: %s: out of memory\n", unit, __func__);
57 void wlc_tunables_init(wlc_tunables_t *tunables, uint devid)
59 tunables->ntxd = NTXD;
60 tunables->nrxd = NRXD;
61 tunables->rxbufsz = RXBUFSZ;
62 tunables->nrxbufpost = NRXBUFPOST;
63 tunables->maxscb = MAXSCB;
64 tunables->ampdunummpdu = AMPDU_NUM_MPDU;
65 tunables->maxpktcb = MAXPKTCB;
66 tunables->maxucodebss = WLC_MAX_UCODE_BSS;
67 tunables->maxucodebss4 = WLC_MAX_UCODE_BSS4;
68 tunables->maxbss = MAXBSS;
69 tunables->datahiwat = WLC_DATAHIWAT;
70 tunables->ampdudatahiwat = WLC_AMPDUDATAHIWAT;
71 tunables->rxbnd = RXBND;
72 tunables->txsbnd = TXSBND;
75 static struct wlc_pub *wlc_pub_malloc(struct osl_info *osh, uint unit,
76 uint *err, uint devid)
80 pub = wlc_calloc(osh, unit, sizeof(struct wlc_pub));
86 pub->tunables = wlc_calloc(osh, unit,
87 sizeof(wlc_tunables_t));
88 if (pub->tunables == NULL) {
93 /* need to init the tunables now */
94 wlc_tunables_init(pub->tunables, devid);
96 pub->_cnt = wlc_calloc(osh, unit, sizeof(struct wl_cnt));
97 if (pub->_cnt == NULL)
100 pub->multicast = (u8 *)wlc_calloc(osh, unit,
101 (ETH_ALEN * MAXMULTILIST));
102 if (pub->multicast == NULL) {
110 wlc_pub_mfree(osh, pub);
114 static void wlc_pub_mfree(struct osl_info *osh, struct wlc_pub *pub)
119 kfree(pub->multicast);
121 kfree(pub->tunables);
125 static wlc_bsscfg_t *wlc_bsscfg_malloc(struct osl_info *osh, uint unit)
129 cfg = (wlc_bsscfg_t *) wlc_calloc(osh, unit, sizeof(wlc_bsscfg_t));
133 cfg->current_bss = (wlc_bss_info_t *)wlc_calloc(osh, unit,
134 sizeof(wlc_bss_info_t));
135 if (cfg->current_bss == NULL)
141 wlc_bsscfg_mfree(osh, cfg);
145 static void wlc_bsscfg_mfree(struct osl_info *osh, wlc_bsscfg_t *cfg)
155 if (cfg->current_bss != NULL) {
156 wlc_bss_info_t *current_bss = cfg->current_bss;
158 cfg->current_bss = NULL;
164 void wlc_bsscfg_ID_assign(struct wlc_info *wlc, wlc_bsscfg_t *bsscfg)
166 bsscfg->ID = wlc->next_bsscfg_ID;
167 wlc->next_bsscfg_ID++;
171 * The common driver entry routine. Error codes should be unique
173 struct wlc_info *wlc_attach_malloc(struct osl_info *osh, uint unit, uint *err,
176 struct wlc_info *wlc;
178 wlc = (struct wlc_info *) wlc_calloc(osh, unit,
179 sizeof(struct wlc_info));
185 wlc->hwrxoff = WL_HWRXOFF;
187 /* allocate struct wlc_pub state structure */
188 wlc->pub = wlc_pub_malloc(osh, unit, err, devid);
189 if (wlc->pub == NULL) {
195 /* allocate struct wlc_hw_info state structure */
197 wlc->hw = (struct wlc_hw_info *)wlc_calloc(osh, unit,
198 sizeof(struct wlc_hw_info));
199 if (wlc->hw == NULL) {
205 wlc->hw->bandstate[0] = wlc_calloc(osh, unit,
206 (sizeof(struct wlc_hwband) * MAXBANDS));
207 if (wlc->hw->bandstate[0] == NULL) {
213 for (i = 1; i < MAXBANDS; i++) {
214 wlc->hw->bandstate[i] = (struct wlc_hwband *)
215 ((unsigned long)wlc->hw->bandstate[0] +
216 (sizeof(struct wlc_hwband) * i));
220 wlc->modulecb = wlc_calloc(osh, unit,
221 sizeof(struct modulecb) * WLC_MAXMODULES);
222 if (wlc->modulecb == NULL) {
227 wlc->default_bss = (wlc_bss_info_t *)wlc_calloc(osh, unit,
228 sizeof(wlc_bss_info_t));
229 if (wlc->default_bss == NULL) {
234 wlc->cfg = wlc_bsscfg_malloc(osh, unit);
235 if (wlc->cfg == NULL) {
239 wlc_bsscfg_ID_assign(wlc, wlc->cfg);
241 wlc->pkt_callback = wlc_calloc(osh, unit,
242 (sizeof(struct pkt_cb) * (wlc->pub->tunables->maxpktcb + 1)));
243 if (wlc->pkt_callback == NULL) {
248 wlc->wsec_def_keys[0] = (wsec_key_t *)wlc_calloc(osh, unit,
249 (sizeof(wsec_key_t) * WLC_DEFAULT_KEYS));
250 if (wlc->wsec_def_keys[0] == NULL) {
255 for (i = 1; i < WLC_DEFAULT_KEYS; i++) {
256 wlc->wsec_def_keys[i] = (wsec_key_t *)
257 ((unsigned long)wlc->wsec_def_keys[0] +
258 (sizeof(wsec_key_t) * i));
262 wlc->protection = wlc_calloc(osh, unit,
263 sizeof(struct wlc_protection));
264 if (wlc->protection == NULL) {
269 wlc->stf = wlc_calloc(osh, unit, sizeof(struct wlc_stf));
270 if (wlc->stf == NULL) {
275 wlc->bandstate[0] = (struct wlcband *)wlc_calloc(osh, unit,
276 (sizeof(struct wlcband)*MAXBANDS));
277 if (wlc->bandstate[0] == NULL) {
283 for (i = 1; i < MAXBANDS; i++) {
285 (struct wlcband *) ((unsigned long)wlc->bandstate[0]
286 + (sizeof(struct wlcband)*i));
290 wlc->corestate = (struct wlccore *)wlc_calloc(osh, unit,
291 sizeof(struct wlccore));
292 if (wlc->corestate == NULL) {
297 wlc->corestate->macstat_snapshot =
298 (macstat_t *)wlc_calloc(osh, unit, sizeof(macstat_t));
299 if (wlc->corestate->macstat_snapshot == NULL) {
307 wlc_detach_mfree(wlc, osh);
311 void wlc_detach_mfree(struct wlc_info *wlc, struct osl_info *osh)
317 kfree(wlc->modulecb);
318 wlc->modulecb = NULL;
321 if (wlc->default_bss) {
322 kfree(wlc->default_bss);
323 wlc->default_bss = NULL;
326 wlc_bsscfg_mfree(osh, wlc->cfg);
330 if (wlc->pkt_callback && wlc->pub && wlc->pub->tunables) {
331 kfree(wlc->pkt_callback);
332 wlc->pkt_callback = NULL;
335 if (wlc->wsec_def_keys[0])
336 kfree(wlc->wsec_def_keys[0]);
337 if (wlc->protection) {
338 kfree(wlc->protection);
339 wlc->protection = NULL;
347 if (wlc->bandstate[0])
348 kfree(wlc->bandstate[0]);
350 if (wlc->corestate) {
351 if (wlc->corestate->macstat_snapshot) {
352 kfree(wlc->corestate->macstat_snapshot); wlc->corestate->macstat_snapshot = NULL;
354 kfree(wlc->corestate);
355 wlc->corestate = NULL;
359 /* free pub struct */
360 wlc_pub_mfree(osh, wlc->pub);
365 if (wlc->hw->bandstate[0]) {
366 kfree(wlc->hw->bandstate[0]);
367 wlc->hw->bandstate[0] = NULL;