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"
30 const u8 ALLFFMAC
[ETH_ALEN
] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
32 #define BRCMF_DEFAULT_SCAN_CHANNEL_TIME 40
33 #define BRCMF_DEFAULT_SCAN_UNASSOC_TIME 40
35 /* boost value for RSSI_DELTA in preferred join selection */
36 #define BRCMF_JOIN_PREF_RSSI_BOOST 8
38 #define BRCMF_DEFAULT_TXGLOM_SIZE 32 /* max tx frames in glom chain */
40 static int brcmf_sdiod_txglomsz
= BRCMF_DEFAULT_TXGLOM_SIZE
;
41 module_param_named(txglomsz
, brcmf_sdiod_txglomsz
, int, 0);
42 MODULE_PARM_DESC(txglomsz
, "Maximum tx packet chain size [SDIO]");
44 /* Debug level configuration. See debug.h for bits, sysfs modifiable */
46 module_param_named(debug
, brcmf_msg_level
, int, S_IRUSR
| S_IWUSR
);
47 MODULE_PARM_DESC(debug
, "Level of debug output");
49 static int brcmf_p2p_enable
;
50 module_param_named(p2pon
, brcmf_p2p_enable
, int, 0);
51 MODULE_PARM_DESC(p2pon
, "Enable legacy p2p management functionality");
53 static int brcmf_feature_disable
;
54 module_param_named(feature_disable
, brcmf_feature_disable
, int, 0);
55 MODULE_PARM_DESC(feature_disable
, "Disable features");
57 static char brcmf_firmware_path
[BRCMF_FW_ALTPATH_LEN
];
58 module_param_string(alternative_fw_path
, brcmf_firmware_path
,
59 BRCMF_FW_ALTPATH_LEN
, S_IRUSR
);
60 MODULE_PARM_DESC(alternative_fw_path
, "Alternative firmware path");
62 static int brcmf_fcmode
;
63 module_param_named(fcmode
, brcmf_fcmode
, int, 0);
64 MODULE_PARM_DESC(fcmode
, "Mode of firmware signalled flow control");
66 static int brcmf_roamoff
;
67 module_param_named(roamoff
, brcmf_roamoff
, int, S_IRUSR
);
68 MODULE_PARM_DESC(roamoff
, "Do not use internal roaming engine");
71 /* always succeed brcmf_bus_start() */
72 static int brcmf_ignore_probe_fail
;
73 module_param_named(ignore_probe_fail
, brcmf_ignore_probe_fail
, int, 0);
74 MODULE_PARM_DESC(ignore_probe_fail
, "always succeed probe for debugging");
77 struct brcmf_mp_global_t brcmf_mp_global
;
79 int brcmf_c_preinit_dcmds(struct brcmf_if
*ifp
)
81 s8 eventmask
[BRCMF_EVENTING_MASK_LEN
];
82 u8 buf
[BRCMF_DCMD_SMLEN
];
83 struct brcmf_join_pref_params join_pref_params
[2];
84 struct brcmf_rev_info_le revinfo
;
85 struct brcmf_rev_info
*ri
;
89 /* retreive mac address */
90 err
= brcmf_fil_iovar_data_get(ifp
, "cur_etheraddr", ifp
->mac_addr
,
91 sizeof(ifp
->mac_addr
));
93 brcmf_err("Retreiving cur_etheraddr failed, %d\n", err
);
96 memcpy(ifp
->drvr
->mac
, ifp
->mac_addr
, sizeof(ifp
->drvr
->mac
));
98 err
= brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_REVINFO
,
99 &revinfo
, sizeof(revinfo
));
100 ri
= &ifp
->drvr
->revinfo
;
102 brcmf_err("retrieving revision info failed, %d\n", err
);
104 ri
->vendorid
= le32_to_cpu(revinfo
.vendorid
);
105 ri
->deviceid
= le32_to_cpu(revinfo
.deviceid
);
106 ri
->radiorev
= le32_to_cpu(revinfo
.radiorev
);
107 ri
->chiprev
= le32_to_cpu(revinfo
.chiprev
);
108 ri
->corerev
= le32_to_cpu(revinfo
.corerev
);
109 ri
->boardid
= le32_to_cpu(revinfo
.boardid
);
110 ri
->boardvendor
= le32_to_cpu(revinfo
.boardvendor
);
111 ri
->boardrev
= le32_to_cpu(revinfo
.boardrev
);
112 ri
->driverrev
= le32_to_cpu(revinfo
.driverrev
);
113 ri
->ucoderev
= le32_to_cpu(revinfo
.ucoderev
);
114 ri
->bus
= le32_to_cpu(revinfo
.bus
);
115 ri
->chipnum
= le32_to_cpu(revinfo
.chipnum
);
116 ri
->phytype
= le32_to_cpu(revinfo
.phytype
);
117 ri
->phyrev
= le32_to_cpu(revinfo
.phyrev
);
118 ri
->anarev
= le32_to_cpu(revinfo
.anarev
);
119 ri
->chippkg
= le32_to_cpu(revinfo
.chippkg
);
120 ri
->nvramrev
= le32_to_cpu(revinfo
.nvramrev
);
124 /* query for 'ver' to get version info from firmware */
125 memset(buf
, 0, sizeof(buf
));
127 err
= brcmf_fil_iovar_data_get(ifp
, "ver", buf
, sizeof(buf
));
129 brcmf_err("Retreiving version information failed, %d\n",
136 /* Print fw version info */
137 brcmf_err("Firmware version = %s\n", buf
);
139 /* locate firmware version number for ethtool */
140 ptr
= strrchr(buf
, ' ') + 1;
141 strlcpy(ifp
->drvr
->fwver
, ptr
, sizeof(ifp
->drvr
->fwver
));
144 err
= brcmf_fil_iovar_int_set(ifp
, "mpc", 1);
146 brcmf_err("failed setting mpc\n");
150 /* Setup join_pref to select target by RSSI(with boost on 5GHz) */
151 join_pref_params
[0].type
= BRCMF_JOIN_PREF_RSSI_DELTA
;
152 join_pref_params
[0].len
= 2;
153 join_pref_params
[0].rssi_gain
= BRCMF_JOIN_PREF_RSSI_BOOST
;
154 join_pref_params
[0].band
= WLC_BAND_5G
;
155 join_pref_params
[1].type
= BRCMF_JOIN_PREF_RSSI
;
156 join_pref_params
[1].len
= 2;
157 join_pref_params
[1].rssi_gain
= 0;
158 join_pref_params
[1].band
= 0;
159 err
= brcmf_fil_iovar_data_set(ifp
, "join_pref", join_pref_params
,
160 sizeof(join_pref_params
));
162 brcmf_err("Set join_pref error (%d)\n", err
);
164 /* Setup event_msgs, enable E_IF */
165 err
= brcmf_fil_iovar_data_get(ifp
, "event_msgs", eventmask
,
166 BRCMF_EVENTING_MASK_LEN
);
168 brcmf_err("Get event_msgs error (%d)\n", err
);
171 setbit(eventmask
, BRCMF_E_IF
);
172 err
= brcmf_fil_iovar_data_set(ifp
, "event_msgs", eventmask
,
173 BRCMF_EVENTING_MASK_LEN
);
175 brcmf_err("Set event_msgs error (%d)\n", err
);
179 /* Setup default scan channel time */
180 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCAN_CHANNEL_TIME
,
181 BRCMF_DEFAULT_SCAN_CHANNEL_TIME
);
183 brcmf_err("BRCMF_C_SET_SCAN_CHANNEL_TIME error (%d)\n",
188 /* Setup default scan unassoc time */
189 err
= brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCAN_UNASSOC_TIME
,
190 BRCMF_DEFAULT_SCAN_UNASSOC_TIME
);
192 brcmf_err("BRCMF_C_SET_SCAN_UNASSOC_TIME error (%d)\n",
197 /* Enable tx beamforming, errors can be ignored (not supported) */
198 (void)brcmf_fil_iovar_int_set(ifp
, "txbf", 1);
200 /* do bus specific preinit here */
201 err
= brcmf_bus_preinit(ifp
->drvr
->bus_if
);
206 #if defined(CONFIG_BRCM_TRACING) || defined(CONFIG_BRCMDBG)
207 void __brcmf_dbg(u32 level
, const char *func
, const char *fmt
, ...)
209 struct va_format vaf
= {
216 if (brcmf_msg_level
& level
)
217 pr_debug("%s %pV", func
, &vaf
);
218 trace_brcmf_dbg(level
, func
, &vaf
);
223 void brcmf_mp_attach(void)
225 strlcpy(brcmf_mp_global
.firmware_path
, brcmf_firmware_path
,
226 BRCMF_FW_ALTPATH_LEN
);
229 int brcmf_mp_device_attach(struct brcmf_pub
*drvr
)
231 drvr
->settings
= kzalloc(sizeof(*drvr
->settings
), GFP_ATOMIC
);
232 if (!drvr
->settings
) {
233 brcmf_err("Failed to alloca storage space for settings\n");
237 drvr
->settings
->sdiod_txglomsz
= brcmf_sdiod_txglomsz
;
238 drvr
->settings
->p2p_enable
= !!brcmf_p2p_enable
;
239 drvr
->settings
->feature_disable
= brcmf_feature_disable
;
240 drvr
->settings
->fcmode
= brcmf_fcmode
;
241 drvr
->settings
->roamoff
= !!brcmf_roamoff
;
243 drvr
->settings
->ignore_probe_fail
= !!brcmf_ignore_probe_fail
;
248 void brcmf_mp_device_detach(struct brcmf_pub
*drvr
)
250 kfree(drvr
->settings
);