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 <linux/kernel.h>
18 #include <linux/string.h>
19 #include <linux/netdevice.h>
20 #include <brcmu_wifi.h>
21 #include <brcmu_utils.h>
26 #include "fwil_types.h"
27 #include "tracepoint.h"
29 #define BRCMF_DEFAULT_BCN_TIMEOUT 3
30 #define BRCMF_DEFAULT_SCAN_CHANNEL_TIME 40
31 #define BRCMF_DEFAULT_SCAN_UNASSOC_TIME 40
33 /* boost value for RSSI_DELTA in preferred join selection */
34 #define BRCMF_JOIN_PREF_RSSI_BOOST 8
37 bool brcmf_c_prec_enq(struct device *dev, struct pktq *q,
38 struct sk_buff *pkt, int prec)
41 int eprec = -1; /* precedence to evict from */
43 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
44 struct brcmf_pub *drvr = bus_if->drvr;
46 /* Fast case, precedence queue is not full and we are also not
47 * exceeding total queue length
49 if (!pktq_pfull(q, prec) && !pktq_full(q)) {
50 brcmu_pktq_penq(q, prec, pkt);
54 /* Determine precedence from which to evict packet, if any */
55 if (pktq_pfull(q, prec))
57 else if (pktq_full(q)) {
58 p = brcmu_pktq_peek_tail(q, &eprec);
65 /* Detect queueing to unconfigured precedence */
66 discard_oldest = ac_bitmap_tst(drvr->wme_dp, eprec);
67 if (eprec == prec && !discard_oldest)
68 return false; /* refuse newer (incoming) packet */
69 /* Evict packet according to discard policy */
70 p = discard_oldest ? brcmu_pktq_pdeq(q, eprec) :
71 brcmu_pktq_pdeq_tail(q, eprec);
73 brcmf_err("brcmu_pktq_penq() failed, oldest %d\n",
76 brcmu_pkt_buf_free_skb(p);
80 p = brcmu_pktq_penq(q, prec, pkt);
82 brcmf_err("brcmu_pktq_penq() failed\n");
87 int brcmf_c_preinit_dcmds(struct brcmf_if *ifp)
89 s8 eventmask[BRCMF_EVENTING_MASK_LEN];
90 u8 buf[BRCMF_DCMD_SMLEN];
91 struct brcmf_join_pref_params join_pref_params[2];
95 /* retreive mac address */
96 err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr,
97 sizeof(ifp->mac_addr));
99 brcmf_err("Retreiving cur_etheraddr failed, %d\n",
103 memcpy(ifp->drvr->mac, ifp->mac_addr, sizeof(ifp->drvr->mac));
105 /* query for 'ver' to get version info from firmware */
106 memset(buf, 0, sizeof(buf));
108 err = brcmf_fil_iovar_data_get(ifp, "ver", buf, sizeof(buf));
110 brcmf_err("Retreiving version information failed, %d\n",
117 /* Print fw version info */
118 brcmf_err("Firmware version = %s\n", buf);
120 /* locate firmware version number for ethtool */
121 ptr = strrchr(buf, ' ') + 1;
122 strlcpy(ifp->drvr->fwver, ptr, sizeof(ifp->drvr->fwver));
125 err = brcmf_fil_iovar_int_set(ifp, "mpc", 1);
127 brcmf_err("failed setting mpc\n");
132 * Setup timeout if Beacons are lost and roam is off to report
135 err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout",
136 BRCMF_DEFAULT_BCN_TIMEOUT);
138 brcmf_err("bcn_timeout error (%d)\n", err);
142 /* Enable/Disable build-in roaming to allowed ext supplicant to take
145 err = brcmf_fil_iovar_int_set(ifp, "roam_off", 1);
147 brcmf_err("roam_off error (%d)\n", err);
151 /* Setup join_pref to select target by RSSI(with boost on 5GHz) */
152 join_pref_params[0].type = BRCMF_JOIN_PREF_RSSI_DELTA;
153 join_pref_params[0].len = 2;
154 join_pref_params[0].rssi_gain = BRCMF_JOIN_PREF_RSSI_BOOST;
155 join_pref_params[0].band = WLC_BAND_5G;
156 join_pref_params[1].type = BRCMF_JOIN_PREF_RSSI;
157 join_pref_params[1].len = 2;
158 join_pref_params[1].rssi_gain = 0;
159 join_pref_params[1].band = 0;
160 err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params,
161 sizeof(join_pref_params));
163 brcmf_err("Set join_pref error (%d)\n", err);
165 /* Setup event_msgs, enable E_IF */
166 err = brcmf_fil_iovar_data_get(ifp, "event_msgs", eventmask,
167 BRCMF_EVENTING_MASK_LEN);
169 brcmf_err("Get event_msgs error (%d)\n", err);
172 setbit(eventmask, BRCMF_E_IF);
173 err = brcmf_fil_iovar_data_set(ifp, "event_msgs", eventmask,
174 BRCMF_EVENTING_MASK_LEN);
176 brcmf_err("Set event_msgs error (%d)\n", err);
180 /* Setup default scan channel time */
181 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
182 BRCMF_DEFAULT_SCAN_CHANNEL_TIME);
184 brcmf_err("BRCMF_C_SET_SCAN_CHANNEL_TIME error (%d)\n",
189 /* Setup default scan unassoc time */
190 err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
191 BRCMF_DEFAULT_SCAN_UNASSOC_TIME);
193 brcmf_err("BRCMF_C_SET_SCAN_UNASSOC_TIME error (%d)\n",
198 /* do bus specific preinit here */
199 err = brcmf_bus_preinit(ifp->drvr->bus_if);
204 #if defined(CONFIG_BRCM_TRACING) || defined(CONFIG_BRCMDBG)
205 void __brcmf_dbg(u32 level, const char *func, const char *fmt, ...)
207 struct va_format vaf = {
214 if (brcmf_msg_level & level)
215 pr_debug("%s %pV", func, &vaf);
216 trace_brcmf_dbg(level, func, &vaf);