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.
17 #include <brcmu_utils.h>
23 static struct brcms_c_bsscfg *wlc_bsscfg_malloc(uint unit);
24 static void wlc_bsscfg_mfree(struct brcms_c_bsscfg *cfg);
25 static struct wlc_pub *wlc_pub_malloc(uint unit,
26 uint *err, uint devid);
27 static void wlc_pub_mfree(struct wlc_pub *pub);
28 static void wlc_tunables_init(wlc_tunables_t *tunables, uint devid);
30 static void wlc_tunables_init(wlc_tunables_t *tunables, uint devid)
32 tunables->ntxd = NTXD;
33 tunables->nrxd = NRXD;
34 tunables->rxbufsz = RXBUFSZ;
35 tunables->nrxbufpost = NRXBUFPOST;
36 tunables->maxscb = MAXSCB;
37 tunables->ampdunummpdu = AMPDU_NUM_MPDU;
38 tunables->maxpktcb = MAXPKTCB;
39 tunables->maxucodebss = WLC_MAX_UCODE_BSS;
40 tunables->maxucodebss4 = WLC_MAX_UCODE_BSS4;
41 tunables->maxbss = MAXBSS;
42 tunables->datahiwat = WLC_DATAHIWAT;
43 tunables->ampdudatahiwat = WLC_AMPDUDATAHIWAT;
44 tunables->rxbnd = RXBND;
45 tunables->txsbnd = TXSBND;
48 static struct wlc_pub *wlc_pub_malloc(uint unit, uint *err, uint devid)
52 pub = kzalloc(sizeof(struct wlc_pub), GFP_ATOMIC);
58 pub->tunables = kzalloc(sizeof(wlc_tunables_t), GFP_ATOMIC);
59 if (pub->tunables == NULL) {
64 /* need to init the tunables now */
65 wlc_tunables_init(pub->tunables, devid);
67 pub->multicast = kzalloc(ETH_ALEN * MAXMULTILIST, GFP_ATOMIC);
68 if (pub->multicast == NULL) {
80 static void wlc_pub_mfree(struct wlc_pub *pub)
85 kfree(pub->multicast);
90 static struct brcms_c_bsscfg *wlc_bsscfg_malloc(uint unit)
92 struct brcms_c_bsscfg *cfg;
94 cfg = kzalloc(sizeof(struct brcms_c_bsscfg), GFP_ATOMIC);
98 cfg->current_bss = kzalloc(sizeof(wlc_bss_info_t), GFP_ATOMIC);
99 if (cfg->current_bss == NULL)
105 wlc_bsscfg_mfree(cfg);
109 static void wlc_bsscfg_mfree(struct brcms_c_bsscfg *cfg)
115 kfree(cfg->current_bss);
119 static void wlc_bsscfg_ID_assign(struct brcms_c_info *wlc,
120 struct brcms_c_bsscfg *bsscfg)
122 bsscfg->ID = wlc->next_bsscfg_ID;
123 wlc->next_bsscfg_ID++;
127 * The common driver entry routine. Error codes should be unique
129 struct brcms_c_info *brcms_c_attach_malloc(uint unit, uint *err, uint devid)
131 struct brcms_c_info *wlc;
133 wlc = kzalloc(sizeof(struct brcms_c_info), GFP_ATOMIC);
139 /* allocate struct brcms_c_pub state structure */
140 wlc->pub = wlc_pub_malloc(unit, err, devid);
141 if (wlc->pub == NULL) {
147 /* allocate struct brcms_c_hw_info state structure */
149 wlc->hw = kzalloc(sizeof(struct brcms_c_hw_info), GFP_ATOMIC);
150 if (wlc->hw == NULL) {
156 wlc->hw->bandstate[0] =
157 kzalloc(sizeof(struct brcms_c_hwband) * MAXBANDS, GFP_ATOMIC);
158 if (wlc->hw->bandstate[0] == NULL) {
164 for (i = 1; i < MAXBANDS; i++) {
165 wlc->hw->bandstate[i] = (struct brcms_c_hwband *)
166 ((unsigned long)wlc->hw->bandstate[0] +
167 (sizeof(struct brcms_c_hwband) * i));
172 kzalloc(sizeof(struct modulecb) * WLC_MAXMODULES, GFP_ATOMIC);
173 if (wlc->modulecb == NULL) {
178 wlc->default_bss = kzalloc(sizeof(wlc_bss_info_t), GFP_ATOMIC);
179 if (wlc->default_bss == NULL) {
184 wlc->cfg = wlc_bsscfg_malloc(unit);
185 if (wlc->cfg == NULL) {
189 wlc_bsscfg_ID_assign(wlc, wlc->cfg);
191 wlc->wsec_def_keys[0] =
192 kzalloc(sizeof(wsec_key_t) * WLC_DEFAULT_KEYS, GFP_ATOMIC);
193 if (wlc->wsec_def_keys[0] == NULL) {
198 for (i = 1; i < WLC_DEFAULT_KEYS; i++) {
199 wlc->wsec_def_keys[i] = (wsec_key_t *)
200 ((unsigned long)wlc->wsec_def_keys[0] +
201 (sizeof(wsec_key_t) * i));
205 wlc->protection = kzalloc(sizeof(struct brcms_c_protection),
207 if (wlc->protection == NULL) {
212 wlc->stf = kzalloc(sizeof(struct brcms_c_stf), GFP_ATOMIC);
213 if (wlc->stf == NULL) {
219 kzalloc(sizeof(struct brcms_c_band)*MAXBANDS, GFP_ATOMIC);
220 if (wlc->bandstate[0] == NULL) {
226 for (i = 1; i < MAXBANDS; i++) {
227 wlc->bandstate[i] = (struct brcms_c_band *)
228 ((unsigned long)wlc->bandstate[0]
229 + (sizeof(struct brcms_c_band)*i));
233 wlc->corestate = kzalloc(sizeof(struct brcms_c_core), GFP_ATOMIC);
234 if (wlc->corestate == NULL) {
239 wlc->corestate->macstat_snapshot =
240 kzalloc(sizeof(macstat_t), GFP_ATOMIC);
241 if (wlc->corestate->macstat_snapshot == NULL) {
249 brcms_c_detach_mfree(wlc);
253 void brcms_c_detach_mfree(struct brcms_c_info *wlc)
258 wlc_bsscfg_mfree(wlc->cfg);
259 wlc_pub_mfree(wlc->pub);
260 kfree(wlc->modulecb);
261 kfree(wlc->default_bss);
262 kfree(wlc->wsec_def_keys[0]);
263 kfree(wlc->protection);
265 kfree(wlc->bandstate[0]);
266 kfree(wlc->corestate->macstat_snapshot);
267 kfree(wlc->corestate);
268 kfree(wlc->hw->bandstate[0]);