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>
25 #include "wlc_types.h"
30 #include "wlc_alloc.h"
33 #include "wlc_bsscfg.h"
34 #include "phy/wlc_phy_hal.h"
35 #include "wlc_channel.h"
38 static struct wlc_bsscfg *wlc_bsscfg_malloc(uint unit);
39 static void wlc_bsscfg_mfree(struct wlc_bsscfg *cfg);
40 static struct wlc_pub *wlc_pub_malloc(uint unit,
41 uint *err, uint devid);
42 static void wlc_pub_mfree(struct wlc_pub *pub);
43 static void wlc_tunables_init(wlc_tunables_t *tunables, uint devid);
45 static 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;
63 static struct wlc_pub *wlc_pub_malloc(uint unit, uint *err, uint devid)
67 pub = kzalloc(sizeof(struct wlc_pub), GFP_ATOMIC);
73 pub->tunables = kzalloc(sizeof(wlc_tunables_t), GFP_ATOMIC);
74 if (pub->tunables == NULL) {
79 /* need to init the tunables now */
80 wlc_tunables_init(pub->tunables, devid);
82 pub->multicast = kzalloc(ETH_ALEN * MAXMULTILIST, GFP_ATOMIC);
83 if (pub->multicast == NULL) {
95 static void wlc_pub_mfree(struct wlc_pub *pub)
100 kfree(pub->multicast);
101 kfree(pub->tunables);
105 static struct wlc_bsscfg *wlc_bsscfg_malloc(uint unit)
107 struct wlc_bsscfg *cfg;
109 cfg = kzalloc(sizeof(struct wlc_bsscfg), GFP_ATOMIC);
113 cfg->current_bss = kzalloc(sizeof(wlc_bss_info_t), GFP_ATOMIC);
114 if (cfg->current_bss == NULL)
120 wlc_bsscfg_mfree(cfg);
124 static void wlc_bsscfg_mfree(struct wlc_bsscfg *cfg)
130 kfree(cfg->current_bss);
134 static void wlc_bsscfg_ID_assign(struct wlc_info *wlc,
135 struct wlc_bsscfg *bsscfg)
137 bsscfg->ID = wlc->next_bsscfg_ID;
138 wlc->next_bsscfg_ID++;
142 * The common driver entry routine. Error codes should be unique
144 struct wlc_info *wlc_attach_malloc(uint unit, uint *err, uint devid)
146 struct wlc_info *wlc;
148 wlc = kzalloc(sizeof(struct wlc_info), GFP_ATOMIC);
154 /* allocate struct wlc_pub state structure */
155 wlc->pub = wlc_pub_malloc(unit, err, devid);
156 if (wlc->pub == NULL) {
162 /* allocate struct wlc_hw_info state structure */
164 wlc->hw = kzalloc(sizeof(struct wlc_hw_info), GFP_ATOMIC);
165 if (wlc->hw == NULL) {
171 wlc->hw->bandstate[0] =
172 kzalloc(sizeof(struct wlc_hwband) * MAXBANDS, GFP_ATOMIC);
173 if (wlc->hw->bandstate[0] == NULL) {
179 for (i = 1; i < MAXBANDS; i++) {
180 wlc->hw->bandstate[i] = (struct wlc_hwband *)
181 ((unsigned long)wlc->hw->bandstate[0] +
182 (sizeof(struct wlc_hwband) * i));
187 kzalloc(sizeof(struct modulecb) * WLC_MAXMODULES, GFP_ATOMIC);
188 if (wlc->modulecb == NULL) {
193 wlc->default_bss = kzalloc(sizeof(wlc_bss_info_t), GFP_ATOMIC);
194 if (wlc->default_bss == NULL) {
199 wlc->cfg = wlc_bsscfg_malloc(unit);
200 if (wlc->cfg == NULL) {
204 wlc_bsscfg_ID_assign(wlc, wlc->cfg);
206 wlc->wsec_def_keys[0] =
207 kzalloc(sizeof(wsec_key_t) * WLC_DEFAULT_KEYS, GFP_ATOMIC);
208 if (wlc->wsec_def_keys[0] == NULL) {
213 for (i = 1; i < WLC_DEFAULT_KEYS; i++) {
214 wlc->wsec_def_keys[i] = (wsec_key_t *)
215 ((unsigned long)wlc->wsec_def_keys[0] +
216 (sizeof(wsec_key_t) * i));
220 wlc->protection = kzalloc(sizeof(struct wlc_protection), GFP_ATOMIC);
221 if (wlc->protection == NULL) {
226 wlc->stf = kzalloc(sizeof(struct wlc_stf), GFP_ATOMIC);
227 if (wlc->stf == NULL) {
233 kzalloc(sizeof(struct wlcband)*MAXBANDS, GFP_ATOMIC);
234 if (wlc->bandstate[0] == NULL) {
240 for (i = 1; i < MAXBANDS; i++) {
242 (struct wlcband *) ((unsigned long)wlc->bandstate[0]
243 + (sizeof(struct wlcband)*i));
247 wlc->corestate = kzalloc(sizeof(struct wlccore), GFP_ATOMIC);
248 if (wlc->corestate == NULL) {
253 wlc->corestate->macstat_snapshot =
254 kzalloc(sizeof(macstat_t), GFP_ATOMIC);
255 if (wlc->corestate->macstat_snapshot == NULL) {
263 wlc_detach_mfree(wlc);
267 void wlc_detach_mfree(struct wlc_info *wlc)
272 wlc_bsscfg_mfree(wlc->cfg);
273 wlc_pub_mfree(wlc->pub);
274 kfree(wlc->modulecb);
275 kfree(wlc->default_bss);
276 kfree(wlc->wsec_def_keys[0]);
277 kfree(wlc->protection);
279 kfree(wlc->bandstate[0]);
280 kfree(wlc->corestate->macstat_snapshot);
281 kfree(wlc->corestate);
282 kfree(wlc->hw->bandstate[0]);