Merge commit 'c1e140bf79d817d4a7aa9932eb98b0359c87af33' from mac80211-next
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / brcm80211 / brcmfmac / common.c
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
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.
7  *
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.
15  */
16
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>
22 #include "core.h"
23 #include "bus.h"
24 #include "debug.h"
25 #include "fwil.h"
26 #include "fwil_types.h"
27 #include "tracepoint.h"
28 #include "common.h"
29
30 const u8 ALLFFMAC[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
31
32 #define BRCMF_DEFAULT_BCN_TIMEOUT       3
33 #define BRCMF_DEFAULT_SCAN_CHANNEL_TIME 40
34 #define BRCMF_DEFAULT_SCAN_UNASSOC_TIME 40
35
36 /* boost value for RSSI_DELTA in preferred join selection */
37 #define BRCMF_JOIN_PREF_RSSI_BOOST      8
38
39 int brcmf_c_preinit_dcmds(struct brcmf_if *ifp)
40 {
41         s8 eventmask[BRCMF_EVENTING_MASK_LEN];
42         u8 buf[BRCMF_DCMD_SMLEN];
43         struct brcmf_join_pref_params join_pref_params[2];
44         char *ptr;
45         s32 err;
46
47         /* retreive mac address */
48         err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr,
49                                        sizeof(ifp->mac_addr));
50         if (err < 0) {
51                 brcmf_err("Retreiving cur_etheraddr failed, %d\n",
52                           err);
53                 goto done;
54         }
55         memcpy(ifp->drvr->mac, ifp->mac_addr, sizeof(ifp->drvr->mac));
56
57         /* query for 'ver' to get version info from firmware */
58         memset(buf, 0, sizeof(buf));
59         strcpy(buf, "ver");
60         err = brcmf_fil_iovar_data_get(ifp, "ver", buf, sizeof(buf));
61         if (err < 0) {
62                 brcmf_err("Retreiving version information failed, %d\n",
63                           err);
64                 goto done;
65         }
66         ptr = (char *)buf;
67         strsep(&ptr, "\n");
68
69         /* Print fw version info */
70         brcmf_err("Firmware version = %s\n", buf);
71
72         /* locate firmware version number for ethtool */
73         ptr = strrchr(buf, ' ') + 1;
74         strlcpy(ifp->drvr->fwver, ptr, sizeof(ifp->drvr->fwver));
75
76         /* set mpc */
77         err = brcmf_fil_iovar_int_set(ifp, "mpc", 1);
78         if (err) {
79                 brcmf_err("failed setting mpc\n");
80                 goto done;
81         }
82
83         /*
84          * Setup timeout if Beacons are lost and roam is off to report
85          * link down
86          */
87         err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout",
88                                       BRCMF_DEFAULT_BCN_TIMEOUT);
89         if (err) {
90                 brcmf_err("bcn_timeout error (%d)\n", err);
91                 goto done;
92         }
93
94         /* Enable/Disable build-in roaming to allowed ext supplicant to take
95          * of romaing
96          */
97         err = brcmf_fil_iovar_int_set(ifp, "roam_off", 1);
98         if (err) {
99                 brcmf_err("roam_off error (%d)\n", err);
100                 goto done;
101         }
102
103         /* Setup join_pref to select target by RSSI(with boost on 5GHz) */
104         join_pref_params[0].type = BRCMF_JOIN_PREF_RSSI_DELTA;
105         join_pref_params[0].len = 2;
106         join_pref_params[0].rssi_gain = BRCMF_JOIN_PREF_RSSI_BOOST;
107         join_pref_params[0].band = WLC_BAND_5G;
108         join_pref_params[1].type = BRCMF_JOIN_PREF_RSSI;
109         join_pref_params[1].len = 2;
110         join_pref_params[1].rssi_gain = 0;
111         join_pref_params[1].band = 0;
112         err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params,
113                                        sizeof(join_pref_params));
114         if (err)
115                 brcmf_err("Set join_pref error (%d)\n", err);
116
117         /* Setup event_msgs, enable E_IF */
118         err = brcmf_fil_iovar_data_get(ifp, "event_msgs", eventmask,
119                                        BRCMF_EVENTING_MASK_LEN);
120         if (err) {
121                 brcmf_err("Get event_msgs error (%d)\n", err);
122                 goto done;
123         }
124         setbit(eventmask, BRCMF_E_IF);
125         err = brcmf_fil_iovar_data_set(ifp, "event_msgs", eventmask,
126                                        BRCMF_EVENTING_MASK_LEN);
127         if (err) {
128                 brcmf_err("Set event_msgs error (%d)\n", err);
129                 goto done;
130         }
131
132         /* Setup default scan channel time */
133         err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
134                                     BRCMF_DEFAULT_SCAN_CHANNEL_TIME);
135         if (err) {
136                 brcmf_err("BRCMF_C_SET_SCAN_CHANNEL_TIME error (%d)\n",
137                           err);
138                 goto done;
139         }
140
141         /* Setup default scan unassoc time */
142         err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
143                                     BRCMF_DEFAULT_SCAN_UNASSOC_TIME);
144         if (err) {
145                 brcmf_err("BRCMF_C_SET_SCAN_UNASSOC_TIME error (%d)\n",
146                           err);
147                 goto done;
148         }
149
150         /* do bus specific preinit here */
151         err = brcmf_bus_preinit(ifp->drvr->bus_if);
152 done:
153         return err;
154 }
155
156 #if defined(CONFIG_BRCM_TRACING) || defined(CONFIG_BRCMDBG)
157 void __brcmf_dbg(u32 level, const char *func, const char *fmt, ...)
158 {
159         struct va_format vaf = {
160                 .fmt = fmt,
161         };
162         va_list args;
163
164         va_start(args, fmt);
165         vaf.va = &args;
166         if (brcmf_msg_level & level)
167                 pr_debug("%s %pV", func, &vaf);
168         trace_brcmf_dbg(level, func, &vaf);
169         va_end(args);
170 }
171 #endif