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>
20 #include <brcmu_utils.h>
30 #include "phy/phy_hal.h"
34 static struct wlc_bsscfg *wlc_bsscfg_malloc(uint unit);
35 static void wlc_bsscfg_mfree(struct wlc_bsscfg *cfg);
36 static struct wlc_pub *wlc_pub_malloc(uint unit,
37 uint *err, uint devid);
38 static void wlc_pub_mfree(struct wlc_pub *pub);
39 static void wlc_tunables_init(wlc_tunables_t *tunables, uint devid);
41 static void wlc_tunables_init(wlc_tunables_t *tunables, uint devid)
43 tunables->ntxd = NTXD;
44 tunables->nrxd = NRXD;
45 tunables->rxbufsz = RXBUFSZ;
46 tunables->nrxbufpost = NRXBUFPOST;
47 tunables->maxscb = MAXSCB;
48 tunables->ampdunummpdu = AMPDU_NUM_MPDU;
49 tunables->maxpktcb = MAXPKTCB;
50 tunables->maxucodebss = WLC_MAX_UCODE_BSS;
51 tunables->maxucodebss4 = WLC_MAX_UCODE_BSS4;
52 tunables->maxbss = MAXBSS;
53 tunables->datahiwat = WLC_DATAHIWAT;
54 tunables->ampdudatahiwat = WLC_AMPDUDATAHIWAT;
55 tunables->rxbnd = RXBND;
56 tunables->txsbnd = TXSBND;
59 static struct wlc_pub *wlc_pub_malloc(uint unit, uint *err, uint devid)
63 pub = kzalloc(sizeof(struct wlc_pub), GFP_ATOMIC);
69 pub->tunables = kzalloc(sizeof(wlc_tunables_t), GFP_ATOMIC);
70 if (pub->tunables == NULL) {
75 /* need to init the tunables now */
76 wlc_tunables_init(pub->tunables, devid);
78 pub->multicast = kzalloc(ETH_ALEN * MAXMULTILIST, GFP_ATOMIC);
79 if (pub->multicast == NULL) {
91 static void wlc_pub_mfree(struct wlc_pub *pub)
96 kfree(pub->multicast);
101 static struct wlc_bsscfg *wlc_bsscfg_malloc(uint unit)
103 struct wlc_bsscfg *cfg;
105 cfg = kzalloc(sizeof(struct wlc_bsscfg), GFP_ATOMIC);
109 cfg->current_bss = kzalloc(sizeof(wlc_bss_info_t), GFP_ATOMIC);
110 if (cfg->current_bss == NULL)
116 wlc_bsscfg_mfree(cfg);
120 static void wlc_bsscfg_mfree(struct wlc_bsscfg *cfg)
126 kfree(cfg->current_bss);
130 static void wlc_bsscfg_ID_assign(struct wlc_info *wlc,
131 struct wlc_bsscfg *bsscfg)
133 bsscfg->ID = wlc->next_bsscfg_ID;
134 wlc->next_bsscfg_ID++;
138 * The common driver entry routine. Error codes should be unique
140 struct wlc_info *wlc_attach_malloc(uint unit, uint *err, uint devid)
142 struct wlc_info *wlc;
144 wlc = kzalloc(sizeof(struct wlc_info), GFP_ATOMIC);
150 /* allocate struct wlc_pub state structure */
151 wlc->pub = wlc_pub_malloc(unit, err, devid);
152 if (wlc->pub == NULL) {
158 /* allocate struct wlc_hw_info state structure */
160 wlc->hw = kzalloc(sizeof(struct wlc_hw_info), GFP_ATOMIC);
161 if (wlc->hw == NULL) {
167 wlc->hw->bandstate[0] =
168 kzalloc(sizeof(struct wlc_hwband) * MAXBANDS, GFP_ATOMIC);
169 if (wlc->hw->bandstate[0] == NULL) {
175 for (i = 1; i < MAXBANDS; i++) {
176 wlc->hw->bandstate[i] = (struct wlc_hwband *)
177 ((unsigned long)wlc->hw->bandstate[0] +
178 (sizeof(struct wlc_hwband) * i));
183 kzalloc(sizeof(struct modulecb) * WLC_MAXMODULES, GFP_ATOMIC);
184 if (wlc->modulecb == NULL) {
189 wlc->default_bss = kzalloc(sizeof(wlc_bss_info_t), GFP_ATOMIC);
190 if (wlc->default_bss == NULL) {
195 wlc->cfg = wlc_bsscfg_malloc(unit);
196 if (wlc->cfg == NULL) {
200 wlc_bsscfg_ID_assign(wlc, wlc->cfg);
202 wlc->wsec_def_keys[0] =
203 kzalloc(sizeof(wsec_key_t) * WLC_DEFAULT_KEYS, GFP_ATOMIC);
204 if (wlc->wsec_def_keys[0] == NULL) {
209 for (i = 1; i < WLC_DEFAULT_KEYS; i++) {
210 wlc->wsec_def_keys[i] = (wsec_key_t *)
211 ((unsigned long)wlc->wsec_def_keys[0] +
212 (sizeof(wsec_key_t) * i));
216 wlc->protection = kzalloc(sizeof(struct wlc_protection), GFP_ATOMIC);
217 if (wlc->protection == NULL) {
222 wlc->stf = kzalloc(sizeof(struct wlc_stf), GFP_ATOMIC);
223 if (wlc->stf == NULL) {
229 kzalloc(sizeof(struct wlcband)*MAXBANDS, GFP_ATOMIC);
230 if (wlc->bandstate[0] == NULL) {
236 for (i = 1; i < MAXBANDS; i++) {
238 (struct wlcband *) ((unsigned long)wlc->bandstate[0]
239 + (sizeof(struct wlcband)*i));
243 wlc->corestate = kzalloc(sizeof(struct wlccore), GFP_ATOMIC);
244 if (wlc->corestate == NULL) {
249 wlc->corestate->macstat_snapshot =
250 kzalloc(sizeof(macstat_t), GFP_ATOMIC);
251 if (wlc->corestate->macstat_snapshot == NULL) {
259 wlc_detach_mfree(wlc);
263 void wlc_detach_mfree(struct wlc_info *wlc)
268 wlc_bsscfg_mfree(wlc->cfg);
269 wlc_pub_mfree(wlc->pub);
270 kfree(wlc->modulecb);
271 kfree(wlc->default_bss);
272 kfree(wlc->wsec_def_keys[0]);
273 kfree(wlc->protection);
275 kfree(wlc->bandstate[0]);
276 kfree(wlc->corestate->macstat_snapshot);
277 kfree(wlc->corestate);
278 kfree(wlc->hw->bandstate[0]);