| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2010 Broadcom Corporation | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Permission to use, copy, modify, and/or distribute this software for any | 
					
						
							|  |  |  |  * purpose with or without fee is hereby granted, provided that the above | 
					
						
							|  |  |  |  * copyright notice and this permission notice appear in all copies. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 
					
						
							|  |  |  |  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 
					
						
							|  |  |  |  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | 
					
						
							|  |  |  |  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 
					
						
							|  |  |  |  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | 
					
						
							|  |  |  |  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | 
					
						
							|  |  |  |  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-01-15 00:38:44 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | #include <linux/kernel.h>
 | 
					
						
							|  |  |  | #include <linux/string.h>
 | 
					
						
							|  |  |  | #include <linux/netdevice.h>
 | 
					
						
							|  |  |  | #include <brcmu_wifi.h>
 | 
					
						
							|  |  |  | #include <brcmu_utils.h>
 | 
					
						
							| 
									
										
										
										
											2014-10-28 14:56:18 +01:00
										 |  |  | #include "core.h"
 | 
					
						
							| 
									
										
										
										
											2014-10-28 14:56:14 +01:00
										 |  |  | #include "bus.h"
 | 
					
						
							| 
									
										
										
										
											2014-10-28 14:56:13 +01:00
										 |  |  | #include "debug.h"
 | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | #include "fwil.h"
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:19 +01:00
										 |  |  | #include "fwil_types.h"
 | 
					
						
							| 
									
										
										
										
											2013-03-03 12:45:21 +01:00
										 |  |  | #include "tracepoint.h"
 | 
					
						
							| 
									
										
										
										
											2014-12-21 12:43:52 +01:00
										 |  |  | #include "common.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const u8 ALLFFMAC[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | #define BRCMF_DEFAULT_BCN_TIMEOUT	3
 | 
					
						
							|  |  |  | #define BRCMF_DEFAULT_SCAN_CHANNEL_TIME	40
 | 
					
						
							|  |  |  | #define BRCMF_DEFAULT_SCAN_UNASSOC_TIME	40
 | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-12 10:47:26 +02:00
										 |  |  | /* boost value for RSSI_DELTA in preferred join selection */ | 
					
						
							|  |  |  | #define BRCMF_JOIN_PREF_RSSI_BOOST	8
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | int brcmf_c_preinit_dcmds(struct brcmf_if *ifp) | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 	s8 eventmask[BRCMF_EVENTING_MASK_LEN]; | 
					
						
							|  |  |  | 	u8 buf[BRCMF_DCMD_SMLEN]; | 
					
						
							| 
									
										
										
										
											2014-05-12 10:47:26 +02:00
										 |  |  | 	struct brcmf_join_pref_params join_pref_params[2]; | 
					
						
							| 
									
										
										
										
											2015-01-25 20:31:40 +01:00
										 |  |  | 	struct brcmf_rev_info_le revinfo; | 
					
						
							|  |  |  | 	struct brcmf_rev_info *ri; | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 	char *ptr; | 
					
						
							|  |  |  | 	s32 err; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 	/* retreive mac address */ | 
					
						
							|  |  |  | 	err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr, | 
					
						
							|  |  |  | 				       sizeof(ifp->mac_addr)); | 
					
						
							|  |  |  | 	if (err < 0) { | 
					
						
							| 
									
										
										
										
											2015-01-25 20:31:40 +01:00
										 |  |  | 		brcmf_err("Retreiving cur_etheraddr failed, %d\n", err); | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 		goto done; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 	memcpy(ifp->drvr->mac, ifp->mac_addr, sizeof(ifp->drvr->mac)); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-25 20:31:40 +01:00
										 |  |  | 	err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_REVINFO, | 
					
						
							|  |  |  | 				     &revinfo, sizeof(revinfo)); | 
					
						
							| 
									
										
										
										
											2015-01-25 20:31:42 +01:00
										 |  |  | 	ri = &ifp->drvr->revinfo; | 
					
						
							| 
									
										
										
										
											2015-01-25 20:31:40 +01:00
										 |  |  | 	if (err < 0) { | 
					
						
							|  |  |  | 		brcmf_err("retrieving revision info failed, %d\n", err); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		ri->vendorid = le32_to_cpu(revinfo.vendorid); | 
					
						
							|  |  |  | 		ri->deviceid = le32_to_cpu(revinfo.deviceid); | 
					
						
							|  |  |  | 		ri->radiorev = le32_to_cpu(revinfo.radiorev); | 
					
						
							|  |  |  | 		ri->chiprev = le32_to_cpu(revinfo.chiprev); | 
					
						
							|  |  |  | 		ri->corerev = le32_to_cpu(revinfo.corerev); | 
					
						
							|  |  |  | 		ri->boardid = le32_to_cpu(revinfo.boardid); | 
					
						
							|  |  |  | 		ri->boardvendor = le32_to_cpu(revinfo.boardvendor); | 
					
						
							|  |  |  | 		ri->boardrev = le32_to_cpu(revinfo.boardrev); | 
					
						
							|  |  |  | 		ri->driverrev = le32_to_cpu(revinfo.driverrev); | 
					
						
							|  |  |  | 		ri->ucoderev = le32_to_cpu(revinfo.ucoderev); | 
					
						
							|  |  |  | 		ri->bus = le32_to_cpu(revinfo.bus); | 
					
						
							|  |  |  | 		ri->chipnum = le32_to_cpu(revinfo.chipnum); | 
					
						
							|  |  |  | 		ri->phytype = le32_to_cpu(revinfo.phytype); | 
					
						
							|  |  |  | 		ri->phyrev = le32_to_cpu(revinfo.phyrev); | 
					
						
							|  |  |  | 		ri->anarev = le32_to_cpu(revinfo.anarev); | 
					
						
							|  |  |  | 		ri->chippkg = le32_to_cpu(revinfo.chippkg); | 
					
						
							|  |  |  | 		ri->nvramrev = le32_to_cpu(revinfo.nvramrev); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-01-25 20:31:42 +01:00
										 |  |  | 	ri->result = err; | 
					
						
							| 
									
										
										
										
											2015-01-25 20:31:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	/* query for 'ver' to get version info from firmware */ | 
					
						
							|  |  |  | 	memset(buf, 0, sizeof(buf)); | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 	strcpy(buf, "ver"); | 
					
						
							|  |  |  | 	err = brcmf_fil_iovar_data_get(ifp, "ver", buf, sizeof(buf)); | 
					
						
							|  |  |  | 	if (err < 0) { | 
					
						
							| 
									
										
										
										
											2012-12-07 10:49:57 +01:00
										 |  |  | 		brcmf_err("Retreiving version information failed, %d\n", | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 			  err); | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ptr = (char *)buf; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	strsep(&ptr, "\n"); | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 	/* Print fw version info */ | 
					
						
							| 
									
										
										
										
											2012-12-07 10:49:57 +01:00
										 |  |  | 	brcmf_err("Firmware version = %s\n", buf); | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 12:25:17 +01:00
										 |  |  | 	/* locate firmware version number for ethtool */ | 
					
						
							|  |  |  | 	ptr = strrchr(buf, ' ') + 1; | 
					
						
							|  |  |  | 	strlcpy(ifp->drvr->fwver, ptr, sizeof(ifp->drvr->fwver)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-21 12:11:18 +02:00
										 |  |  | 	/* set mpc */ | 
					
						
							|  |  |  | 	err = brcmf_fil_iovar_int_set(ifp, "mpc", 1); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							|  |  |  | 		brcmf_err("failed setting mpc\n"); | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Setup timeout if Beacons are lost and roam is off to report | 
					
						
							|  |  |  | 	 * link down | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", | 
					
						
							|  |  |  | 				      BRCMF_DEFAULT_BCN_TIMEOUT); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							| 
									
										
										
										
											2012-12-07 10:49:57 +01:00
										 |  |  | 		brcmf_err("bcn_timeout error (%d)\n", err); | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Enable/Disable build-in roaming to allowed ext supplicant to take
 | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 	 * of romaing | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	err = brcmf_fil_iovar_int_set(ifp, "roam_off", 1); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							| 
									
										
										
										
											2012-12-07 10:49:57 +01:00
										 |  |  | 		brcmf_err("roam_off error (%d)\n", err); | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-12 10:47:26 +02:00
										 |  |  | 	/* Setup join_pref to select target by RSSI(with boost on 5GHz) */ | 
					
						
							|  |  |  | 	join_pref_params[0].type = BRCMF_JOIN_PREF_RSSI_DELTA; | 
					
						
							|  |  |  | 	join_pref_params[0].len = 2; | 
					
						
							|  |  |  | 	join_pref_params[0].rssi_gain = BRCMF_JOIN_PREF_RSSI_BOOST; | 
					
						
							|  |  |  | 	join_pref_params[0].band = WLC_BAND_5G; | 
					
						
							|  |  |  | 	join_pref_params[1].type = BRCMF_JOIN_PREF_RSSI; | 
					
						
							|  |  |  | 	join_pref_params[1].len = 2; | 
					
						
							|  |  |  | 	join_pref_params[1].rssi_gain = 0; | 
					
						
							|  |  |  | 	join_pref_params[1].band = 0; | 
					
						
							|  |  |  | 	err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params, | 
					
						
							|  |  |  | 				       sizeof(join_pref_params)); | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		brcmf_err("Set join_pref error (%d)\n", err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 	/* Setup event_msgs, enable E_IF */ | 
					
						
							|  |  |  | 	err = brcmf_fil_iovar_data_get(ifp, "event_msgs", eventmask, | 
					
						
							|  |  |  | 				       BRCMF_EVENTING_MASK_LEN); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							| 
									
										
										
										
											2012-12-07 10:49:57 +01:00
										 |  |  | 		brcmf_err("Get event_msgs error (%d)\n", err); | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	setbit(eventmask, BRCMF_E_IF); | 
					
						
							|  |  |  | 	err = brcmf_fil_iovar_data_set(ifp, "event_msgs", eventmask, | 
					
						
							|  |  |  | 				       BRCMF_EVENTING_MASK_LEN); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							| 
									
										
										
										
											2012-12-07 10:49:57 +01:00
										 |  |  | 		brcmf_err("Set event_msgs error (%d)\n", err); | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Setup default scan channel time */ | 
					
						
							|  |  |  | 	err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME, | 
					
						
							|  |  |  | 				    BRCMF_DEFAULT_SCAN_CHANNEL_TIME); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							| 
									
										
										
										
											2012-12-07 10:49:57 +01:00
										 |  |  | 		brcmf_err("BRCMF_C_SET_SCAN_CHANNEL_TIME error (%d)\n", | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 			  err); | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Setup default scan unassoc time */ | 
					
						
							|  |  |  | 	err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME, | 
					
						
							|  |  |  | 				    BRCMF_DEFAULT_SCAN_UNASSOC_TIME); | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							| 
									
										
										
										
											2012-12-07 10:49:57 +01:00
										 |  |  | 		brcmf_err("BRCMF_C_SET_SCAN_UNASSOC_TIME error (%d)\n", | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | 			  err); | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-29 11:48:15 +01:00
										 |  |  | 	/* do bus specific preinit here */ | 
					
						
							|  |  |  | 	err = brcmf_bus_preinit(ifp->drvr->bus_if); | 
					
						
							| 
									
										
										
										
											2012-10-22 10:36:25 -07:00
										 |  |  | done: | 
					
						
							|  |  |  | 	return err; | 
					
						
							| 
									
										
										
										
											2011-10-05 13:19:03 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-03-03 12:45:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if defined(CONFIG_BRCM_TRACING) || defined(CONFIG_BRCMDBG)
 | 
					
						
							|  |  |  | void __brcmf_dbg(u32 level, const char *func, const char *fmt, ...) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct va_format vaf = { | 
					
						
							|  |  |  | 		.fmt = fmt, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	va_list args; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	va_start(args, fmt); | 
					
						
							|  |  |  | 	vaf.va = &args; | 
					
						
							|  |  |  | 	if (brcmf_msg_level & level) | 
					
						
							|  |  |  | 		pr_debug("%s %pV", func, &vaf); | 
					
						
							|  |  |  | 	trace_brcmf_dbg(level, func, &vaf); | 
					
						
							|  |  |  | 	va_end(args); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 |