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>
31 #include "phy/phy_hal.h"
35 static struct wlc_bsscfg *wlc_bsscfg_malloc(uint unit);
36 static void wlc_bsscfg_mfree(struct wlc_bsscfg *cfg);
37 static struct wlc_pub *wlc_pub_malloc(uint unit,
38 uint *err, uint devid);
39 static void wlc_pub_mfree(struct wlc_pub *pub);
40 static void wlc_tunables_init(wlc_tunables_t *tunables, uint devid);
42 static void wlc_tunables_init(wlc_tunables_t *tunables, uint devid)
44 tunables->ntxd = NTXD;
45 tunables->nrxd = NRXD;
46 tunables->rxbufsz = RXBUFSZ;
47 tunables->nrxbufpost = NRXBUFPOST;
48 tunables->maxscb = MAXSCB;
49 tunables->ampdunummpdu = AMPDU_NUM_MPDU;
50 tunables->maxpktcb = MAXPKTCB;
51 tunables->maxucodebss = WLC_MAX_UCODE_BSS;
52 tunables->maxucodebss4 = WLC_MAX_UCODE_BSS4;
53 tunables->maxbss = MAXBSS;
54 tunables->datahiwat = WLC_DATAHIWAT;
55 tunables->ampdudatahiwat = WLC_AMPDUDATAHIWAT;
56 tunables->rxbnd = RXBND;
57 tunables->txsbnd = TXSBND;
60 static struct wlc_pub *wlc_pub_malloc(uint unit, uint *err, uint devid)
64 pub = kzalloc(sizeof(struct wlc_pub), GFP_ATOMIC);
70 pub->tunables = kzalloc(sizeof(wlc_tunables_t), GFP_ATOMIC);
71 if (pub->tunables == NULL) {
76 /* need to init the tunables now */
77 wlc_tunables_init(pub->tunables, devid);
79 pub->multicast = kzalloc(ETH_ALEN * MAXMULTILIST, GFP_ATOMIC);
80 if (pub->multicast == NULL) {
92 static void wlc_pub_mfree(struct wlc_pub *pub)
97 kfree(pub->multicast);
102 static struct wlc_bsscfg *wlc_bsscfg_malloc(uint unit)
104 struct wlc_bsscfg *cfg;
106 cfg = kzalloc(sizeof(struct wlc_bsscfg), GFP_ATOMIC);
110 cfg->current_bss = kzalloc(sizeof(wlc_bss_info_t), GFP_ATOMIC);
111 if (cfg->current_bss == NULL)
117 wlc_bsscfg_mfree(cfg);
121 static void wlc_bsscfg_mfree(struct wlc_bsscfg *cfg)
127 kfree(cfg->current_bss);
131 static void wlc_bsscfg_ID_assign(struct wlc_info *wlc,
132 struct wlc_bsscfg *bsscfg)
134 bsscfg->ID = wlc->next_bsscfg_ID;
135 wlc->next_bsscfg_ID++;
139 * The common driver entry routine. Error codes should be unique
141 struct wlc_info *wlc_attach_malloc(uint unit, uint *err, uint devid)
143 struct wlc_info *wlc;
145 wlc = kzalloc(sizeof(struct wlc_info), GFP_ATOMIC);
151 /* allocate struct wlc_pub state structure */
152 wlc->pub = wlc_pub_malloc(unit, err, devid);
153 if (wlc->pub == NULL) {
159 /* allocate struct wlc_hw_info state structure */
161 wlc->hw = kzalloc(sizeof(struct wlc_hw_info), GFP_ATOMIC);
162 if (wlc->hw == NULL) {
168 wlc->hw->bandstate[0] =
169 kzalloc(sizeof(struct wlc_hwband) * MAXBANDS, GFP_ATOMIC);
170 if (wlc->hw->bandstate[0] == NULL) {
176 for (i = 1; i < MAXBANDS; i++) {
177 wlc->hw->bandstate[i] = (struct wlc_hwband *)
178 ((unsigned long)wlc->hw->bandstate[0] +
179 (sizeof(struct wlc_hwband) * i));
184 kzalloc(sizeof(struct modulecb) * WLC_MAXMODULES, GFP_ATOMIC);
185 if (wlc->modulecb == NULL) {
190 wlc->default_bss = kzalloc(sizeof(wlc_bss_info_t), GFP_ATOMIC);
191 if (wlc->default_bss == NULL) {
196 wlc->cfg = wlc_bsscfg_malloc(unit);
197 if (wlc->cfg == NULL) {
201 wlc_bsscfg_ID_assign(wlc, wlc->cfg);
203 wlc->wsec_def_keys[0] =
204 kzalloc(sizeof(wsec_key_t) * WLC_DEFAULT_KEYS, GFP_ATOMIC);
205 if (wlc->wsec_def_keys[0] == NULL) {
210 for (i = 1; i < WLC_DEFAULT_KEYS; i++) {
211 wlc->wsec_def_keys[i] = (wsec_key_t *)
212 ((unsigned long)wlc->wsec_def_keys[0] +
213 (sizeof(wsec_key_t) * i));
217 wlc->protection = kzalloc(sizeof(struct wlc_protection), GFP_ATOMIC);
218 if (wlc->protection == NULL) {
223 wlc->stf = kzalloc(sizeof(struct wlc_stf), GFP_ATOMIC);
224 if (wlc->stf == NULL) {
230 kzalloc(sizeof(struct wlcband)*MAXBANDS, GFP_ATOMIC);
231 if (wlc->bandstate[0] == NULL) {
237 for (i = 1; i < MAXBANDS; i++) {
239 (struct wlcband *) ((unsigned long)wlc->bandstate[0]
240 + (sizeof(struct wlcband)*i));
244 wlc->corestate = kzalloc(sizeof(struct wlccore), GFP_ATOMIC);
245 if (wlc->corestate == NULL) {
250 wlc->corestate->macstat_snapshot =
251 kzalloc(sizeof(macstat_t), GFP_ATOMIC);
252 if (wlc->corestate->macstat_snapshot == NULL) {
260 wlc_detach_mfree(wlc);
264 void wlc_detach_mfree(struct wlc_info *wlc)
269 wlc_bsscfg_mfree(wlc->cfg);
270 wlc_pub_mfree(wlc->pub);
271 kfree(wlc->modulecb);
272 kfree(wlc->default_bss);
273 kfree(wlc->wsec_def_keys[0]);
274 kfree(wlc->protection);
276 kfree(wlc->bandstate[0]);
277 kfree(wlc->corestate->macstat_snapshot);
278 kfree(wlc->corestate);
279 kfree(wlc->hw->bandstate[0]);